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;
224 bool AllowEnablingAnalyzerAlphaCheckers);
234 const tooling::CompilationDatabase &Compilations,
235 ArrayRef<std::string> InputFiles,
236 llvm::IntrusiveRefCntPtr<vfs::FileSystem> BaseFS,
247 unsigned &WarningsAsErrorsCount,
248 llvm::IntrusiveRefCntPtr<vfs::FileSystem> BaseFS);
253 const std::vector<ClangTidyError> &Errors,
259 #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.
static cl::opt< std::string > StoreCheckProfile("store-check-profile", cl::desc(R"(
By default reports are printed in tabulated
format to stderr. When this option is passed,
these per-TU profiles are instead stored as JSON.
)"), cl::value_desc("prefix"), cl::cat(ClangTidyCategory))
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.
ClangTidyOptions::OptionMap getCheckOptions(const ClangTidyOptions &Options, bool AllowEnablingAnalyzerAlphaCheckers)
Returns the effective check-specific options.
A collection of ClangTidyCheckFactory instances.
void handleErrors(ClangTidyContext &Context, bool Fix, unsigned &WarningsAsErrorsCount, llvm::IntrusiveRefCntPtr< vfs::FileSystem > BaseFS)
Displays the found Errors to the users.
void runClangTidy(clang::tidy::ClangTidyContext &Context, const tooling::CompilationDatabase &Compilations, ArrayRef< std::string > InputFiles, llvm::IntrusiveRefCntPtr< vfs::FileSystem > BaseFS, bool EnableCheckProfile=false, llvm::StringRef StoreCheckProfile=StringRef())
Run a set of clang-tidy checks on a set of files.
void exportReplacements(StringRef MainFilePath, const std::vector< ClangTidyError > &Errors, raw_ostream &OS)
Serializes replacements into YAML and writes them to the specified output stream. ...
static cl::opt< bool > AllowEnablingAnalyzerAlphaCheckers("allow-enabling-analyzer-alpha-checkers", cl::init(false), cl::Hidden, cl::cat(ClangTidyCategory))
This option allows enabling the experimental alpha checkers from the static analyzer.
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
static cl::opt< bool > EnableCheckProfile("enable-check-profile", cl::desc(R"(
Enable per-check timing profiles, and print a
report to stderr.
)"), cl::init(false), cl::cat(ClangTidyCategory))
ClangTidyCheck(StringRef CheckName, ClangTidyContext *Context)
Initializes the check with CheckName and Context.
Provides access to the ClangTidyCheck options via check-local names.
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//
std::vector< std::string > getCheckNames(const ClangTidyOptions &Options, bool AllowEnablingAnalyzerAlphaCheckers)
Fills the list of check names that are enabled when the provided filters are applied.
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.
virtual void storeOptions(ClangTidyOptions::OptionMap &Options)
Should store all options supported by this check with their current values or default values for opti...