Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add clang-tidy -line-filter option to filter findings by line ranges.
Summary: This is going to be used for a clang-tidy-diff script to display warnings in changed lines only. The option uses JSON, as its value is not intended to be entered manually. Reviewers: klimek Reviewed By: klimek Subscribers: cfe-commits Differential Revision: http://reviews.llvm.org/D3873 llvm-svn: 209450
- Loading branch information
Showing
12 changed files
with
262 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
//===--- ClangTidyOptions.cpp - clang-tidy ----------------------*- C++ -*-===// | ||
// | ||
// The LLVM Compiler Infrastructure | ||
// | ||
// This file is distributed under the University of Illinois Open Source | ||
// License. See LICENSE.TXT for details. | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#include "ClangTidyOptions.h" | ||
#include "llvm/Support/YAMLTraits.h" | ||
|
||
using clang::tidy::FileFilter; | ||
|
||
LLVM_YAML_IS_FLOW_SEQUENCE_VECTOR(FileFilter) | ||
LLVM_YAML_IS_FLOW_SEQUENCE_VECTOR(FileFilter::LineRange) | ||
|
||
namespace llvm { | ||
namespace yaml { | ||
|
||
// Map std::pair<int, int> to a JSON array of size 2. | ||
template <> struct SequenceTraits<FileFilter::LineRange> { | ||
static size_t size(IO &IO, FileFilter::LineRange &Range) { | ||
return Range.first == 0 ? 0 : Range.second == 0 ? 1 : 2; | ||
} | ||
static unsigned &element(IO &IO, FileFilter::LineRange &Range, size_t Index) { | ||
if (Index > 1) | ||
IO.setError("Too many elements in line range."); | ||
return Index == 0 ? Range.first : Range.second; | ||
} | ||
}; | ||
|
||
template <> struct MappingTraits<FileFilter> { | ||
static void mapping(IO &IO, FileFilter &File) { | ||
IO.mapRequired("name", File.Name); | ||
IO.mapOptional("lines", File.LineRanges); | ||
} | ||
static StringRef validate(IO &io, FileFilter &File) { | ||
if (File.Name.empty()) | ||
return "No file name specified"; | ||
for (const FileFilter::LineRange &Range : File.LineRanges) { | ||
if (Range.first <= 0 || Range.second <= 0) | ||
return "Invalid line range"; | ||
} | ||
return StringRef(); | ||
} | ||
}; | ||
|
||
} // namespace yaml | ||
} // namespace llvm | ||
|
||
namespace clang { | ||
namespace tidy { | ||
|
||
/// \brief Parses -line-filter option and stores it to the \c Options. | ||
llvm::error_code parseLineFilter(const std::string &LineFilter, | ||
clang::tidy::ClangTidyOptions &Options) { | ||
llvm::yaml::Input Input(LineFilter); | ||
Input >> Options.LineFilter; | ||
return Input.error(); | ||
} | ||
|
||
} // namespace tidy | ||
} // namespace clang |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 3 additions & 0 deletions
3
clang-tools-extra/test/clang-tidy/Inputs/line-filter/header1.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
class A1 { A1(int); }; | ||
class B1 { B1(int); }; | ||
class C1 { C1(int); }; |
3 changes: 3 additions & 0 deletions
3
clang-tools-extra/test/clang-tidy/Inputs/line-filter/header2.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
class A2 { A2(int); }; | ||
class B2 { B2(int); }; | ||
class C2 { C2(int); }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
class A3 { A3(int); }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// RUN: clang-tidy -checks='-*,google-explicit-constructor' -line-filter='[{"name":"%s","lines":[[18,18],[22,22]]},{"name":"header1.h","lines":[[1,2]]},{"name":"header2.h"},{"name":"header3.h"}]' -header-filter='header[12]\.h$' %s -- -I %S/Inputs/line-filter 2>&1 | FileCheck %s | ||
|
||
#include "header1.h" | ||
// CHECK-NOT: header1.h:{{.*}} warning | ||
// CHECK: header1.h:1:12: warning: Single-argument constructors must be explicit [google-explicit-constructor] | ||
// CHECK: header1.h:2:12: warning: Single-argument constructors {{.*}} | ||
// CHECK-NOT: header1.h:{{.*}} warning | ||
|
||
#include "header2.h" | ||
// CHECK: header2.h:1:12: warning: Single-argument constructors {{.*}} | ||
// CHECK: header2.h:2:12: warning: Single-argument constructors {{.*}} | ||
// CHECK: header2.h:3:12: warning: Single-argument constructors {{.*}} | ||
// CHECK-NOT: header2.h:{{.*}} warning | ||
|
||
#include "header3.h" | ||
// CHECK-NOT: header3.h:{{.*}} warning | ||
|
||
class A { A(int); }; | ||
// CHECK: :[[@LINE-1]]:11: warning: Single-argument constructors {{.*}} | ||
class B { B(int); }; | ||
// CHECK-NOT: :[[@LINE-1]]:{{.*}} warning | ||
class C { C(int); }; | ||
// CHECK: :[[@LINE-1]]:11: warning: Single-argument constructors {{.*}} | ||
|
||
// CHECK-NOT: warning: | ||
|
||
// CHECK: Suppressed 3 warnings (1 in non-user code, 2 due to line filter) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.