9 #ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CLANGTIDYDIAGNOSTICCONSUMER_H 10 #define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CLANGTIDYDIAGNOSTICCONSUMER_H 14 #include "clang/Basic/Diagnostic.h" 15 #include "clang/Basic/SourceManager.h" 16 #include "clang/Tooling/Core/Diagnostic.h" 17 #include "clang/Tooling/Refactoring.h" 18 #include "llvm/ADT/DenseMap.h" 19 #include "llvm/ADT/StringMap.h" 20 #include "llvm/Support/Regex.h" 21 #include "llvm/Support/Timer.h" 26 class CompilerInstance;
27 namespace ast_matchers {
31 class CompilationDatabase;
44 ClangTidyError(StringRef CheckName, Level DiagLevel, StringRef BuildDirectory,
45 bool IsWarningAsError);
64 bool contains(StringRef S,
bool Contains);
68 std::unique_ptr<GlobList> NextGlob;
75 : ErrorsDisplayed(0), ErrorsIgnoredCheckFilter(0), ErrorsIgnoredNOLINT(0),
76 ErrorsIgnoredNonUserCode(0), ErrorsIgnoredLineFilter(0) {}
85 return ErrorsIgnoredNOLINT + ErrorsIgnoredCheckFilter +
86 ErrorsIgnoredNonUserCode + ErrorsIgnoredLineFilter;
108 this->DiagEngine = DiagEngine;
118 DiagnosticBuilder diag(StringRef CheckName, SourceLocation
Loc,
120 DiagnosticIDs::Level Level = DiagnosticIDs::Warning);
125 void setSourceManager(SourceManager *SourceMgr);
128 void setCurrentFile(StringRef File);
134 void setASTContext(ASTContext *Context);
141 std::string getCheckName(
unsigned DiagnosticID)
const;
146 bool isCheckEnabled(StringRef CheckName)
const;
150 bool treatAsError(StringRef CheckName)
const;
169 void setEnableProfiling(
bool Profile);
173 void setProfileStoragePrefix(StringRef ProfilePrefix);
174 llvm::Optional<ClangTidyProfiling::StorageParams>
175 getProfileStorageParams()
const;
179 CurrentBuildDirectory = BuildDirectory;
184 return CurrentBuildDirectory;
195 SourceLocation Loc) {
197 static_cast<DiagnosticIDs::Level>(
198 DiagEngine->getDiagnosticLevel(DiagnosticID, Loc)),
199 DiagEngine->getDiagnosticIDs()->getDescription(DiagnosticID));
206 DiagnosticsEngine *DiagEngine;
207 std::unique_ptr<ClangTidyOptionsProvider> OptionsProvider;
209 std::string CurrentFile;
212 std::unique_ptr<CachedGlobList> CheckFilter;
213 std::unique_ptr<CachedGlobList> WarningAsErrorFilter;
215 LangOptions LangOpts;
219 std::string CurrentBuildDirectory;
221 llvm::DenseMap<unsigned, std::string> CheckNamesByDiagnosticID;
224 std::string ProfilePrefix;
244 bool CheckMacroExpansion =
true);
254 DiagnosticsEngine *ExternalDiagEngine =
nullptr,
255 bool RemoveIncompatibleErrors =
true);
260 void HandleDiagnostic(DiagnosticsEngine::Level DiagLevel,
261 const Diagnostic &
Info)
override;
264 std::vector<ClangTidyError> take();
267 void finalizeLastError();
268 void removeIncompatibleErrors();
272 llvm::Regex *getHeaderFilter();
276 void checkFilters(SourceLocation
Location,
const SourceManager &Sources);
277 bool passesLineFilter(StringRef
FileName,
unsigned LineNumber)
const;
279 void forwardDiagnostic(
const Diagnostic &Info);
282 DiagnosticsEngine *ExternalDiagEngine;
283 bool RemoveIncompatibleErrors;
284 std::vector<ClangTidyError> Errors;
286 bool LastErrorRelatesToUserCode;
287 bool LastErrorPassesLineFilter;
288 bool LastErrorWasIgnored;
294 #endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CLANGTIDYDIAGNOSTICCONSUMER_H
SourceLocation Loc
'#' location in the include directive
bool ShouldSuppressDiagnostic(DiagnosticsEngine::Level DiagLevel, const Diagnostic &Info, ClangTidyContext &Context, bool CheckMacroExpansion)
Check whether a given diagnostic should be suppressed due to the presence of a "NOLINT" suppression c...
bool canEnableAnalyzerAlphaCheckers() const
If the experimental alpha checkers from the static analyzer can be enabled.
DiagLevelAndFormatString getDiagLevelAndFormatString(unsigned DiagnosticID, SourceLocation Loc)
Read-only set of strings represented as a list of positive and negative globs.
bool contains(StringRef S)
Returns true if the pattern matches S.
bool getEnableProfiling() const
constexpr llvm::StringLiteral Message
Contains options for clang-tidy.
unsigned ErrorsIgnoredCheckFilter
unsigned ErrorsIgnoredNOLINT
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.
unsigned errorsIgnored() const
unsigned ErrorsIgnoredNonUserCode
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.
A diagnostic consumer that turns each Diagnostic into a SourceManager-independent ClangTidyError...
unsigned ErrorsIgnoredLineFilter
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//
void setDiagnosticsEngine(DiagnosticsEngine *DiagEngine)
Sets the DiagnosticsEngine that diag() will emit diagnostics to.
static cl::opt< std::string > HeaderFilter("header-filter", cl::desc(R"(
Regular expression matching the names of the
headers to output diagnostics from. Diagnostics
from the main file of each translation unit are
always displayed.
Can be used together with -line-filter.
This option overrides the 'HeaderFilterRegex'
option in .clang-tidy file, if any.
)"), cl::init(""), cl::cat(ClangTidyCategory))
A detected error complete with information to display diagnostic and automatic fix.
Contains displayed and ignored diagnostic counters for a ClangTidy run.
Every ClangTidyCheck reports errors through a DiagnosticsEngine provided by this context.
const ClangTidyStats & getStats() const
Returns ClangTidyStats containing issued and ignored diagnostic counters.
void setCurrentBuildDirectory(StringRef BuildDirectory)
Should be called when starting to process new translation unit.
const std::string & getCurrentBuildDirectory()
Returns build directory of the current translation unit.
std::pair< DiagnosticIDs::Level, std::string > DiagLevelAndFormatString