[cfe-commits] r142083 - in /cfe/trunk: include/clang/Frontend/TextDiagnosticPrinter.h lib/Frontend/TextDiagnosticPrinter.cpp
Chandler Carruth
chandlerc at gmail.com
Sat Oct 15 15:39:16 PDT 2011
Author: chandlerc
Date: Sat Oct 15 17:39:16 2011
New Revision: 142083
URL: http://llvm.org/viewvc/llvm-project?rev=142083&view=rev
Log:
Rationalize the last bit of "arbitrary" state that is carried between
diagnostics to control suppression of redundant information. It now
follows the same model as all the other state, and has a bit more clear
semantics.
This is making the duality of the state a bit annoying, and I've added
a FIXME to resolve it. The problem is that I need to lift the
TextDiagnostic up into an externally visible layer before that can
happen.
Modified:
cfe/trunk/include/clang/Frontend/TextDiagnosticPrinter.h
cfe/trunk/lib/Frontend/TextDiagnosticPrinter.cpp
Modified: cfe/trunk/include/clang/Frontend/TextDiagnosticPrinter.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Frontend/TextDiagnosticPrinter.h?rev=142083&r1=142082&r2=142083&view=diff
==============================================================================
--- cfe/trunk/include/clang/Frontend/TextDiagnosticPrinter.h (original)
+++ cfe/trunk/include/clang/Frontend/TextDiagnosticPrinter.h Sat Oct 15 17:39:16 2011
@@ -29,7 +29,7 @@
FullSourceLoc LastLoc;
FullSourceLoc LastIncludeLoc;
- unsigned LastCaretDiagnosticWasNote : 1;
+ DiagnosticsEngine::Level LastLevel;
unsigned OwnsOutputStream : 1;
/// A string to prefix to error messages.
Modified: cfe/trunk/lib/Frontend/TextDiagnosticPrinter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/TextDiagnosticPrinter.cpp?rev=142083&r1=142082&r2=142083&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/TextDiagnosticPrinter.cpp (original)
+++ cfe/trunk/lib/Frontend/TextDiagnosticPrinter.cpp Sat Oct 15 17:39:16 2011
@@ -43,8 +43,7 @@
TextDiagnosticPrinter::TextDiagnosticPrinter(raw_ostream &os,
const DiagnosticOptions &diags,
bool _OwnsOutputStream)
- : OS(os), LangOpts(0), DiagOpts(&diags),
- LastCaretDiagnosticWasNote(0),
+ : OS(os), LangOpts(0), DiagOpts(&diags), LastLevel(),
OwnsOutputStream(_OwnsOutputStream) {
}
@@ -498,15 +497,23 @@
/// root locations rather than diagnostic locations.
SourceLocation LastIncludeLoc;
+ /// \brief The level of the last diagnostic emitted.
+ ///
+ /// The level of the last diagnostic emitted. Used to detect level changes
+ /// which change the amount of information displayed.
+ DiagnosticsEngine::Level LastLevel;
+
public:
TextDiagnostic(raw_ostream &OS,
const SourceManager &SM,
const LangOptions &LangOpts,
const DiagnosticOptions &DiagOpts,
FullSourceLoc LastLoc = FullSourceLoc(),
- FullSourceLoc LastIncludeLoc = FullSourceLoc())
+ FullSourceLoc LastIncludeLoc = FullSourceLoc(),
+ DiagnosticsEngine::Level LastLevel
+ = DiagnosticsEngine::Level())
: OS(OS), SM(SM), LangOpts(LangOpts), DiagOpts(DiagOpts),
- LastLoc(LastLoc), LastIncludeLoc(LastIncludeLoc) {
+ LastLoc(LastLoc), LastIncludeLoc(LastIncludeLoc), LastLevel(LastLevel) {
if (LastLoc.isValid() && &SM != &LastLoc.getManager())
this->LastLoc = SourceLocation();
if (LastIncludeLoc.isValid() && &SM != &LastIncludeLoc.getManager())
@@ -519,6 +526,9 @@
/// \brief Get the last emitted include stack location.
SourceLocation getLastIncludeLoc() const { return LastIncludeLoc; }
+ /// \brief Get the last diagnostic level.
+ DiagnosticsEngine::Level getLastLevel() const { return LastLevel; }
+
void Emit(SourceLocation Loc, DiagnosticsEngine::Level Level,
StringRef Message, ArrayRef<CharSourceRange> Ranges,
ArrayRef<FixItHint> FixItHints,
@@ -550,7 +560,7 @@
// multiple times if one loc has multiple diagnostics.
if (DiagOpts.ShowCarets &&
(Loc != LastLoc || !Ranges.empty() || !FixItHints.empty() ||
- (LastCaretDiagnosticWasNote && Level != DiagnosticsEngine::Note))) {
+ (LastLevel == DiagnosticsEngine::Note && Level != LastLevel))) {
// Get the ranges into a local array we can hack on.
SmallVector<CharSourceRange, 20> MutableRanges(Ranges.begin(),
Ranges.end());
@@ -566,6 +576,7 @@
}
LastLoc = Loc;
+ LastLevel = Level;
}
/// \brief Emit the caret and underlining text.
@@ -1279,18 +1290,21 @@
"Unexpected diagnostic with no source manager");
const SourceManager &SM = Info.getSourceManager();
TextDiagnostic TextDiag(OS, SM, *LangOpts, *DiagOpts,
- LastLoc, LastIncludeLoc);
+ LastLoc, LastIncludeLoc, LastLevel);
TextDiag.Emit(Info.getLocation(), Level, DiagMessageStream.str(),
Info.getRanges(),
llvm::makeArrayRef(Info.getFixItHints(),
- Info.getNumFixItHints()),
- LastCaretDiagnosticWasNote);
+ 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);
- LastCaretDiagnosticWasNote = (Level == DiagnosticsEngine::Note);
+ LastLevel = TextDiag.getLastLevel();
OS.flush();
}
More information about the cfe-commits
mailing list