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);
79 StringRef Value)
const;
87 std::string NamePrefix;
118 : CheckName(CheckName), Context(Context),
119 Options(CheckName, Context->getOptions().CheckOptions) {
120 assert(Context !=
nullptr);
121 assert(!CheckName.empty());
146 virtual void check(
const ast_matchers::MatchFinder::MatchResult &
Result) {}
149 DiagnosticBuilder
diag(SourceLocation
Loc, StringRef Description,
150 DiagnosticIDs::Level Level = DiagnosticIDs::Warning);
160 void run(
const ast_matchers::MatchFinder::MatchResult &
Result)
override;
161 StringRef getID()
const override {
return CheckName; }
162 std::string CheckName;
163 ClangTidyContext *Context;
173 class ClangTidyCheckFactories;
180 std::unique_ptr<clang::ASTConsumer>
190 typedef std::vector<std::pair<std::string, bool>> CheckersList;
191 CheckersList getCheckersControlList(
GlobList &Filter);
194 std::unique_ptr<ClangTidyCheckFactories> CheckFactories;
214 runClangTidy(std::unique_ptr<ClangTidyOptionsProvider> OptionsProvider,
215 const tooling::CompilationDatabase &Compilations,
216 ArrayRef<std::string> InputFiles,
217 std::vector<ClangTidyError> *Errors,
226 unsigned &WarningsAsErrorsCount);
236 #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.
Read-only set of strings represented as a list of positive and negative globs.
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.
Base class for all clang-tidy checks.
StringRef getCurrentFile() const
Returns the main file name of the current translation unit.
void exportReplacements(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.
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.
ClangTidyStats runClangTidy(std::unique_ptr< ClangTidyOptionsProvider > OptionsProvider, const tooling::CompilationDatabase &Compilations, ArrayRef< std::string > InputFiles, std::vector< ClangTidyError > *Errors, ProfileData *Profile)
Run a set of clang-tidy checks on a set of files.
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.
Contains displayed and ignored diagnostic counters for a ClangTidy run.
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.
void handleErrors(const std::vector< ClangTidyError > &Errors, bool Fix, unsigned &WarningsAsErrorsCount)
Displays the found Errors to the users.
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...