diff options
author | Chandler Carruth <chandlerc@gmail.com> | 2011-10-16 02:57:39 +0000 |
---|---|---|
committer | Chandler Carruth <chandlerc@gmail.com> | 2011-10-16 02:57:39 +0000 |
commit | 21a869aace45586125238fde88c477b330618a0b (patch) | |
tree | 0a0c93e7dc3a5253ebddab6658d95c18c1d91191 /lib/Frontend/TextDiagnosticPrinter.cpp | |
parent | 7531f571808201d44002fa38b67ee0a81e5ae936 (diff) |
Persist the TextDiagnostic object across multiple diagnostics as long as
the SourceManager doesn't change, and the source files don't change.
This greatly simplifies the interfaces and interactions. The lifetime of
the TextDiagnostic object forms the 'session' over which we attempt to
condense and deduplicate information in diagnostics.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@142104 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Frontend/TextDiagnosticPrinter.cpp')
-rw-r--r-- | lib/Frontend/TextDiagnosticPrinter.cpp | 41 |
1 files changed, 23 insertions, 18 deletions
diff --git a/lib/Frontend/TextDiagnosticPrinter.cpp b/lib/Frontend/TextDiagnosticPrinter.cpp index cf2826484f..b5d0bcb0cb 100644 --- a/lib/Frontend/TextDiagnosticPrinter.cpp +++ b/lib/Frontend/TextDiagnosticPrinter.cpp @@ -27,7 +27,7 @@ using namespace clang; TextDiagnosticPrinter::TextDiagnosticPrinter(raw_ostream &os, const DiagnosticOptions &diags, bool _OwnsOutputStream) - : OS(os), LangOpts(0), DiagOpts(&diags), LastLevel(), + : OS(os), LangOpts(0), DiagOpts(&diags), SM(0), OwnsOutputStream(_OwnsOutputStream) { } @@ -36,6 +36,16 @@ TextDiagnosticPrinter::~TextDiagnosticPrinter() { delete &OS; } +void TextDiagnosticPrinter::BeginSourceFile(const LangOptions &LO, + const Preprocessor *PP) { + LangOpts = &LO; +} + +void TextDiagnosticPrinter::EndSourceFile() { + LangOpts = 0; + TextDiag.reset(0); +} + /// \brief Print the diagnostic name to a raw_ostream. /// /// This prints the diagnostic name to a raw_ostream if it has one. It formats @@ -158,23 +168,18 @@ void TextDiagnosticPrinter::HandleDiagnostic(DiagnosticsEngine::Level Level, assert(DiagOpts && "Unexpected diagnostic without options set"); assert(Info.hasSourceManager() && "Unexpected diagnostic with no source manager"); - const SourceManager &SM = Info.getSourceManager(); - TextDiagnostic TextDiag(OS, SM, *LangOpts, *DiagOpts, - LastLoc, LastIncludeLoc, LastLevel); - - TextDiag.emitDiagnostic(Info.getLocation(), Level, DiagMessageStream.str(), - Info.getRanges(), - llvm::makeArrayRef(Info.getFixItHints(), - Info.getNumFixItHints())); - - // Cache the LastLoc from the TextDiagnostic printing. - // FIXME: Rather than this, we should persist a TextDiagnostic object across - // diagnostics until the SourceManager changes. That will allow the - // TextDiagnostic object to form a 'session' of output where we can - // reasonably collapse redundant information. - LastLoc = FullSourceLoc(TextDiag.getLastLoc(), SM); - LastIncludeLoc = FullSourceLoc(TextDiag.getLastIncludeLoc(), SM); - LastLevel = TextDiag.getLastLevel(); + + // Rebuild the TextDiagnostic utility if missing or the source manager has + // changed. + if (!TextDiag || SM != &Info.getSourceManager()) { + SM = &Info.getSourceManager(); + TextDiag.reset(new TextDiagnostic(OS, *SM, *LangOpts, *DiagOpts)); + } + + TextDiag->emitDiagnostic(Info.getLocation(), Level, DiagMessageStream.str(), + Info.getRanges(), + llvm::makeArrayRef(Info.getFixItHints(), + Info.getNumFixItHints())); OS.flush(); } |