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;
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
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;
180 ClangTidyContext *Context;
190 class ClangTidyCheckFactories;
197 std::unique_ptr<clang::ASTConsumer>
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.
std::vector< std::string > getCheckNames()
Get the list of enabled checks.
ClangTidyASTConsumerFactory(ClangTidyContext &Context)
LangOptions getLangOpts() const
Returns the language options from the context.
StringRef getCurrentMainFile() const
Returns the main file name of the current translation unit.
std::unique_ptr< ast_matchers::MatchFinder > Finder
ClangTidyOptions::OptionMap getCheckOptions()
Get the union of options from all checks.
ClangTidyOptions::OptionMap getCheckOptions(const ClangTidyOptions &Options)
Returns the effective check-specific options.
Contains options for clang-tidy.
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.
Base class for all clang-tidy checks.
void runClangTidy(clang::tidy::ClangTidyContext &Context, const CompilationDatabase &Compilations, ArrayRef< std::string > InputFiles, ProfileData *Profile)
StringRef getCurrentFile() const
Returns the main file name of the current translation unit.
virtual void registerPPCallbacks(CompilerInstance &Compiler)
Override this to register PPCallbacks with Compiler.
std::string getLocalOrGlobal(StringRef LocalName, StringRef Default) const
Read a named option from the Context.
void store(ClangTidyOptions::OptionMap &Options, StringRef LocalName, StringRef Value) const
Stores an option with the check-local name LocalName with string value Value to Options.
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.
const LangOptions & getLangOpts() const
Gets the language options from the AST context.
OptionsView(StringRef CheckName, const ClangTidyOptions::OptionMap &CheckOptions)
Initializes the instance using CheckName + "." as a prefix.
void exportReplacements(const llvm::StringRef MainFilePath, const std::vector< ClangTidyError > &Errors, raw_ostream &OS)
ClangTidyContext & Context
Every ClangTidyCheck reports errors through a DiagnosticsEngine provided by this context.
std::unique_ptr< clang::ASTConsumer > CreateASTConsumer(clang::CompilerInstance &Compiler, StringRef File)
Returns an ASTConsumer that runs the specified clang-tidy checks.
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.
DiagnosticBuilder diag(SourceLocation Loc, StringRef Description, DiagnosticIDs::Level Level=DiagnosticIDs::Warning)
Add a diagnostic with the check's name.
virtual void storeOptions(ClangTidyOptions::OptionMap &Options)
Should store all options supported by this check with their current values or default values for opti...