33 PathDiagnosticConsumerOptions DiagOpts;
34 DiagnosticsEngine &DiagEng;
35 const LangOptions &LO;
36 bool ShouldDisplayPathNotes;
39 TextDiagnostics(PathDiagnosticConsumerOptions DiagOpts,
40 DiagnosticsEngine &DiagEng,
const LangOptions &LO,
41 bool ShouldDisplayPathNotes)
42 : DiagOpts(std::move(DiagOpts)), DiagEng(DiagEng), LO(LO),
43 ShouldDisplayPathNotes(ShouldDisplayPathNotes) {}
44 ~TextDiagnostics()
override {}
46 StringRef
getName()
const override {
return "TextDiagnostics"; }
48 bool supportsLogicalOpControlFlow()
const override {
return true; }
49 bool supportsCrossFileDiagnostics()
const override {
return true; }
51 PathGenerationScheme getGenerationScheme()
const override {
55 void FlushDiagnosticsImpl(std::vector<const PathDiagnostic *> &Diags,
56 FilesMade *filesMade)
override {
58 DiagOpts.ShouldDisplayWarningsAsErrors
62 SourceManager &
SM = DiagEng.getSourceManager();
65 auto reportPiece = [&](
unsigned ID, FullSourceLoc Loc, StringRef String,
66 ArrayRef<SourceRange> Ranges,
67 ArrayRef<FixItHint> Fixits) {
68 if (!DiagOpts.ShouldApplyFixIts) {
69 DiagEng.Report(Loc, ID) << String << Ranges << Fixits;
73 DiagEng.Report(Loc, ID) << String << Ranges;
74 for (
const FixItHint &Hint : Fixits) {
75 Replacement Repl(
SM, Hint.RemoveRange, Hint.CodeToInsert);
77 if (llvm::Error Err = Repls.
add(Repl)) {
78 llvm::errs() <<
"Error applying replacement " << Repl.toString()
79 <<
": " << llvm::toString(std::move(Err)) <<
"\n";
84 for (
const PathDiagnostic *PD : Diags) {
85 std::string WarningMsg = (DiagOpts.ShouldDisplayDiagnosticName
86 ?
" [" + PD->getCheckerName() +
"]"
89 reportPiece(WarnID, PD->getLocation().asLocation(),
90 (PD->getShortDescription() + WarningMsg).str(),
91 PD->path.back()->getRanges(), PD->path.back()->getFixits());
94 for (
const auto &Piece : PD->path) {
98 reportPiece(NoteID, Piece->getLocation().asLocation(),
99 Piece->getString(), Piece->getRanges(),
103 if (!ShouldDisplayPathNotes)
107 PathPieces FlatPath = PD->path.flatten(
true);
108 for (
const auto &Piece : FlatPath) {
112 reportPiece(NoteID, Piece->getLocation().asLocation(),
113 Piece->getString(), Piece->getRanges(),
123 llvm::errs() <<
"An error occurred during applying fix-it.\n";
126 Rewrite.overwriteChangedFiles();
131void ento::createTextPathDiagnosticConsumer(
136 C.emplace_back(
new TextDiagnostics(std::move(DiagOpts), PP.
getDiagnostics(),
141void ento::createTextMinimalPathDiagnosticConsumer(
146 C.emplace_back(
new TextDiagnostics(std::move(DiagOpts), PP.
getDiagnostics(),
Defines the clang::Preprocessor interface.
Defines the SourceManager interface.
MacroExpansionContext tracks the macro expansions processed by the Preprocessor.
Engages in a tight little dance with the lexer to efficiently preprocess tokens.
const LangOptions & getLangOpts() const
DiagnosticsEngine & getDiagnostics() const
This class is used for tools that requires cross translation unit capability.
std::vector< std::unique_ptr< PathDiagnosticConsumer > > PathDiagnosticConsumers
StringRef getName(const HeaderType T)
The JSON file list parser is used to communicate input to InstallAPI.
bool isa(CodeGen::Address addr)
@ Rewrite
We are substituting template parameters for (typically) other template parameters in order to rewrite...
@ None
The alignment was not explicit in code.
These options tweak the behavior of path diangostic consumers.