diff options
author | Chandler Carruth <chandlerc@gmail.com> | 2011-08-31 23:59:19 +0000 |
---|---|---|
committer | Chandler Carruth <chandlerc@gmail.com> | 2011-08-31 23:59:19 +0000 |
commit | 0d6b893c0d66813fad5d9b9193e7af1058e4742e (patch) | |
tree | f536581c0fb299a9e33ad14c5845dd326aa97670 /lib/Frontend/TextDiagnosticPrinter.cpp | |
parent | 71f11d6a393c185b8896d3f6a4089ef93d340d00 (diff) |
Sink all of the include stack printing logic into its member function.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@138920 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Frontend/TextDiagnosticPrinter.cpp')
-rw-r--r-- | lib/Frontend/TextDiagnosticPrinter.cpp | 57 |
1 files changed, 39 insertions, 18 deletions
diff --git a/lib/Frontend/TextDiagnosticPrinter.cpp b/lib/Frontend/TextDiagnosticPrinter.cpp index c531ddd846..ad466c4e49 100644 --- a/lib/Frontend/TextDiagnosticPrinter.cpp +++ b/lib/Frontend/TextDiagnosticPrinter.cpp @@ -53,27 +53,54 @@ TextDiagnosticPrinter::~TextDiagnosticPrinter() { delete &OS; } -void TextDiagnosticPrinter::PrintIncludeStack(Diagnostic::Level Level, - SourceLocation Loc, - const SourceManager &SM) { - if (!DiagOpts->ShowNoteIncludeStack && Level == Diagnostic::Note) return; - - if (Loc.isInvalid()) return; +/// \brief Helper to recursivly walk up the include stack and print each layer +/// on the way back down. +static void PrintIncludeStackRecursively(raw_ostream &OS, + const SourceManager &SM, + SourceLocation Loc, + bool ShowLocation) { + if (Loc.isInvalid()) + return; PresumedLoc PLoc = SM.getPresumedLoc(Loc); if (PLoc.isInvalid()) return; - + // Print out the other include frames first. - PrintIncludeStack(Level, PLoc.getIncludeLoc(), SM); + PrintIncludeStackRecursively(OS, SM, PLoc.getIncludeLoc(), ShowLocation); - if (DiagOpts->ShowLocation) + if (ShowLocation) OS << "In file included from " << PLoc.getFilename() << ':' << PLoc.getLine() << ":\n"; else OS << "In included file:\n"; } +/// \brief Prints an include stack when appropriate for a particular diagnostic +/// level and location. +/// +/// This routine handles all the logic of suppressing particular include stacks +/// (such as those for notes) and duplicate include stacks when repeated +/// warnings occur within the same file. It also handles the logic of +/// customizing the formatting and display of the include stack. +/// +/// \param Level The diagnostic level of the message this stack pertains to. +/// \param Loc The include location of the current file (not the diagnostic +/// location). +void TextDiagnosticPrinter::PrintIncludeStack(Diagnostic::Level Level, + SourceLocation Loc, + const SourceManager &SM) { + // Skip redundant include stacks altogether. + if (LastWarningLoc == Loc) + return; + LastWarningLoc = Loc; + + if (!DiagOpts->ShowNoteIncludeStack && Level == Diagnostic::Note) + return; + + PrintIncludeStackRecursively(OS, SM, Loc, DiagOpts->ShowLocation); +} + /// HighlightRange - Given a SourceRange and a line number, highlight (with ~'s) /// any characters in LineNo that intersect the SourceRange. void TextDiagnosticPrinter::HighlightRange(const CharSourceRange &R, @@ -398,10 +425,7 @@ void TextDiagnosticPrinter::EmitCaretDiagnostic(SourceLocation Loc, // If this diagnostic is not in the main file, print out the // "included from" lines. - if (LastWarningLoc != PLoc.getIncludeLoc()) { - LastWarningLoc = PLoc.getIncludeLoc(); - PrintIncludeStack(Diagnostic::Note, LastWarningLoc, SM); - } + PrintIncludeStack(Diagnostic::Note, PLoc.getIncludeLoc(), SM); if (DiagOpts->ShowLocation) { // Emit the file/line/column that this expansion came from. @@ -879,11 +903,8 @@ void TextDiagnosticPrinter::HandleDiagnostic(Diagnostic::Level Level, // First, if this diagnostic is not in the main file, print out the // "included from" lines. - if (LastWarningLoc != PLoc.getIncludeLoc()) { - LastWarningLoc = PLoc.getIncludeLoc(); - PrintIncludeStack(Level, LastWarningLoc, SM); - StartOfLocationInfo = OS.tell(); - } + PrintIncludeStack(Level, PLoc.getIncludeLoc(), SM); + StartOfLocationInfo = OS.tell(); // Compute the column number. if (DiagOpts->ShowLocation) { |