10 #ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CLANGTIDY_H 11 #define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CLANGTIDY_H 15 #include "clang/ASTMatchers/ASTMatchFinder.h" 16 #include "clang/Basic/Diagnostic.h" 17 #include "clang/Basic/SourceManager.h" 18 #include "clang/Tooling/Refactoring.h" 19 #include "llvm/ADT/StringExtras.h" 20 #include "llvm/Support/raw_ostream.h" 22 #include <type_traits> 27 class CompilerInstance;
29 class CompilationDatabase;
50 std::string
get(StringRef LocalName, StringRef Default)
const;
58 std::string getLocalOrGlobal(StringRef LocalName, StringRef Default)
const;
67 typename std::enable_if<std::is_integral<T>::value, T>::type
68 get(StringRef LocalName, T Default)
const {
69 std::string Value =
get(LocalName,
"");
72 StringRef(Value).getAsInteger(10, Result);
84 typename std::enable_if<std::is_integral<T>::value, T>::type
86 std::string Value = getLocalOrGlobal(LocalName,
"");
89 StringRef(Value).getAsInteger(10, Result);
96 StringRef Value)
const;
101 int64_t Value)
const;
104 std::string NamePrefix;
135 : CheckName(CheckName), Context(Context),
136 Options(CheckName, Context->getOptions().CheckOptions) {
137 assert(Context !=
nullptr);
138 assert(!CheckName.empty());
163 virtual void check(
const ast_matchers::MatchFinder::MatchResult &Result) {}
166 DiagnosticBuilder diag(SourceLocation
Loc, StringRef Description,
167 DiagnosticIDs::Level Level = DiagnosticIDs::Warning);
177 void run(
const ast_matchers::MatchFinder::MatchResult &Result)
override;
178 StringRef getID()
const override {
return CheckName; }
179 std::string CheckName;
197 std::unique_ptr<clang::ASTConsumer>
198 CreateASTConsumer(clang::CompilerInstance &Compiler, StringRef
File);
208 std::unique_ptr<ClangTidyCheckFactories> CheckFactories;
228 const tooling::CompilationDatabase &Compilations,
229 ArrayRef<std::string> InputFiles,
239 unsigned &WarningsAsErrorsCount);
244 const std::vector<ClangTidyError> &Errors,
250 #endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CLANGTIDY_H SourceLocation Loc
'#' location in the include directive
virtual void registerMatchers(ast_matchers::MatchFinder *Finder)
Override this to register AST matchers with Finder.
LangOptions getLangOpts() const
Returns the language options from the context.
std::enable_if< std::is_integral< T >::value, T >::type getLocalOrGlobal(StringRef LocalName, T Default) const
Read a named option from the Context and parse it as an integral type T.
ClangTidyOptions::OptionMap getCheckOptions(const ClangTidyOptions &Options)
Returns the effective check-specific options.
Contains options for clang-tidy.
StringRef getCurrentMainFile() const
Returns the main file name of the current translation unit.
Base class for all clang-tidy checks.
void runClangTidy(clang::tidy::ClangTidyContext &Context, const tooling::CompilationDatabase &Compilations, ArrayRef< std::string > InputFiles, ProfileData *Profile=nullptr)
Run a set of clang-tidy checks on a set of files.
A collection of ClangTidyCheckFactory instances.
void exportReplacements(StringRef MainFilePath, const std::vector< ClangTidyError > &Errors, raw_ostream &OS)
Serializes replacements into YAML and writes them to the specified output stream. ...
virtual void registerPPCallbacks(CompilerInstance &Compiler)
Override this to register PPCallbacks with Compiler.
const LangOptions & getLangOpts() const
Gets the language options from the AST context.
StringRef getCurrentFile() const
Returns the main file name of the current translation unit.
std::map< std::string, std::string > OptionMap
std::vector< std::string > getCheckNames(const ClangTidyOptions &Options)
Fills the list of check names that are enabled when the provided filters are applied.
void handleErrors(ClangTidyContext &Context, bool Fix, unsigned &WarningsAsErrorsCount)
Displays the found Errors to the users.
ClangTidyCheck(StringRef CheckName, ClangTidyContext *Context)
Initializes the check with CheckName and Context.
Provides access to the ClangTidyCheck options via check-local names.
Every ClangTidyCheck reports errors through a DiagnosticsEngine provided by this context.
static cl::opt< bool > Fix("fix", cl::desc(R"(
Apply suggested fixes. Without -fix-errors
clang-tidy will bail out if any compilation
errors were found.
)"), cl::init(false), cl::cat(ClangTidyCategory))
virtual void check(const ast_matchers::MatchFinder::MatchResult &Result)
ClangTidyChecks that register ASTMatchers should do the actual work in here.
Container for clang-tidy profiling data.
virtual void storeOptions(ClangTidyOptions::OptionMap &Options)
Should store all options supported by this check with their current values or default values for opti...