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/Timer.h" 25 class CompilerInstance;
26 namespace ast_matchers {
30 class CompilationDatabase;
43 ClangTidyError(StringRef CheckName, Level DiagLevel, StringRef BuildDirectory,
44 bool IsWarningAsError);
53 : ErrorsDisplayed(0), ErrorsIgnoredCheckFilter(0), ErrorsIgnoredNOLINT(0),
54 ErrorsIgnoredNonUserCode(0), ErrorsIgnoredLineFilter(0) {}
63 return ErrorsIgnoredNOLINT + ErrorsIgnoredCheckFilter +
64 ErrorsIgnoredNonUserCode + ErrorsIgnoredLineFilter;
86 this->DiagEngine = DiagEngine;
96 DiagnosticBuilder diag(StringRef CheckName, SourceLocation
Loc,
98 DiagnosticIDs::Level Level = DiagnosticIDs::Warning);
103 void setSourceManager(SourceManager *SourceMgr);
106 void setCurrentFile(StringRef File);
112 void setASTContext(ASTContext *Context);
119 std::string getCheckName(
unsigned DiagnosticID)
const;
124 bool isCheckEnabled(StringRef CheckName)
const;
128 bool treatAsError(StringRef CheckName)
const;
147 void setEnableProfiling(
bool Profile);
151 void setProfileStoragePrefix(StringRef ProfilePrefix);
152 llvm::Optional<ClangTidyProfiling::StorageParams>
153 getProfileStorageParams()
const;
157 CurrentBuildDirectory = BuildDirectory;
162 return CurrentBuildDirectory;
173 SourceLocation Loc) {
175 static_cast<DiagnosticIDs::Level>(
176 DiagEngine->getDiagnosticLevel(DiagnosticID, Loc)),
177 DiagEngine->getDiagnosticIDs()->getDescription(DiagnosticID));
184 DiagnosticsEngine *DiagEngine;
185 std::unique_ptr<ClangTidyOptionsProvider> OptionsProvider;
187 std::string CurrentFile;
190 std::unique_ptr<CachedGlobList> CheckFilter;
191 std::unique_ptr<CachedGlobList> WarningAsErrorFilter;
193 LangOptions LangOpts;
197 std::string CurrentBuildDirectory;
199 llvm::DenseMap<unsigned, std::string> CheckNamesByDiagnosticID;
202 std::string ProfilePrefix;
222 bool CheckMacroExpansion =
true);
232 DiagnosticsEngine *ExternalDiagEngine =
nullptr,
233 bool RemoveIncompatibleErrors =
true);
238 void HandleDiagnostic(DiagnosticsEngine::Level DiagLevel,
239 const Diagnostic &
Info)
override;
242 std::vector<ClangTidyError> take();
245 void finalizeLastError();
246 void removeIncompatibleErrors();
250 llvm::Regex *getHeaderFilter();
254 void checkFilters(SourceLocation
Location,
const SourceManager &Sources);
255 bool passesLineFilter(StringRef
FileName,
unsigned LineNumber)
const;
257 void forwardDiagnostic(
const Diagnostic &Info);
260 DiagnosticsEngine *ExternalDiagEngine;
261 bool RemoveIncompatibleErrors;
262 std::vector<ClangTidyError> Errors;
264 bool LastErrorRelatesToUserCode;
265 bool LastErrorPassesLineFilter;
266 bool LastErrorWasIgnored;
272 #endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CLANGTIDYDIAGNOSTICCONSUMER_H
SourceLocation Loc
'#' location in the include directive
bool canEnableAnalyzerAlphaCheckers() const
If the experimental alpha checkers from the static analyzer can be enabled.
DiagLevelAndFormatString getDiagLevelAndFormatString(unsigned DiagnosticID, SourceLocation Loc)
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.
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...
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