From 89645bab0bd889b03339e69ea949f5edaa2f1081 Mon Sep 17 00:00:00 2001 From: Chandler Carruth Date: Mon, 26 Sep 2011 00:21:47 +0000 Subject: [PATCH] Extract the diagnostic message formatting into a helper routine. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@140484 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Frontend/TextDiagnosticPrinter.cpp | 73 ++++++++++++++------------ 1 file changed, 39 insertions(+), 34 deletions(-) diff --git a/lib/Frontend/TextDiagnosticPrinter.cpp b/lib/Frontend/TextDiagnosticPrinter.cpp index a947c0e80e..c6b1df9c77 100644 --- a/lib/Frontend/TextDiagnosticPrinter.cpp +++ b/lib/Frontend/TextDiagnosticPrinter.cpp @@ -1086,39 +1086,9 @@ static void PrintDiagnosticLevel(raw_ostream& OS, OS.resetColor(); } -void TextDiagnosticPrinter::HandleDiagnostic(DiagnosticsEngine::Level Level, - const DiagnosticInfo &Info) { - // Default implementation (Warnings/errors count). - DiagnosticConsumer::HandleDiagnostic(Level, Info); - - // Keeps track of the the starting position of the location - // information (e.g., "foo.c:10:4:") that precedes the error - // message. We use this information to determine how long the - // file+line+column number prefix is. - uint64_t StartOfLocationInfo = OS.tell(); - - if (!Prefix.empty()) - OS << Prefix << ": "; - - if (Info.getLocation().isValid()) { - const SourceManager &SM = Info.getSourceManager(); - PresumedLoc PLoc = getDiagnosticPresumedLoc(SM, Info.getLocation()); - - // First, if this diagnostic is not in the main file, print out the - // "included from" lines. - PrintIncludeStack(Level, PLoc.getIncludeLoc(), SM); - StartOfLocationInfo = OS.tell(); - - // Next emit the location of this particular diagnostic. - EmitDiagnosticLoc(Level, Info, SM, PLoc); - - if (DiagOpts->ShowColors) - OS.resetColor(); - } - - PrintDiagnosticLevel(OS, Level, DiagOpts->ShowColors); - - llvm::SmallString<100> OutStr; +static void FormatDiagnosticMessage(const Diagnostic &Info, + const DiagnosticOptions &DiagOpts, + SmallVectorImpl &OutStr) { Info.FormatDiagnostic(OutStr); if (DiagOpts->ShowNames && @@ -1186,8 +1156,43 @@ void TextDiagnosticPrinter::HandleDiagnostic(DiagnosticsEngine::Level Level, OutStr += "]"; } +} + +void TextDiagnosticPrinter::HandleDiagnostic(DiagnosticsEngine::Level Level, + const DiagnosticInfo &Info) { + // Default implementation (Warnings/errors count). + DiagnosticConsumer::HandleDiagnostic(Level, Info); + + // Keeps track of the the starting position of the location + // information (e.g., "foo.c:10:4:") that precedes the error + // message. We use this information to determine how long the + // file+line+column number prefix is. + uint64_t StartOfLocationInfo = OS.tell(); + + if (!Prefix.empty()) + OS << Prefix << ": "; + + if (Info.getLocation().isValid()) { + const SourceManager &SM = Info.getSourceManager(); + PresumedLoc PLoc = getDiagnosticPresumedLoc(SM, Info.getLocation()); + + // First, if this diagnostic is not in the main file, print out the + // "included from" lines. + PrintIncludeStack(Level, PLoc.getIncludeLoc(), SM); + StartOfLocationInfo = OS.tell(); + + // Next emit the location of this particular diagnostic. + EmitDiagnosticLoc(Level, Info, SM, PLoc); + + if (DiagOpts->ShowColors) + OS.resetColor(); + } + + PrintDiagnosticLevel(OS, Level, DiagOpts->ShowColors); + + llvm::SmallString<100> OutStr; + FormatDiagnosticMessage(Info, *Diagopts, OutStr); - if (DiagOpts->ShowColors) { // Print warnings, errors and fatal errors in bold, no color switch (Level) { -- 2.40.0