diff options
author | Chandler Carruth <chandlerc@gmail.com> | 2011-09-26 00:44:09 +0000 |
---|---|---|
committer | Chandler Carruth <chandlerc@gmail.com> | 2011-09-26 00:44:09 +0000 |
commit | 53a529ee614d6a854814273ac49587a03b71a46b (patch) | |
tree | a26f4269ee6d7f6eb184c2800cea338f0e539fea /lib/Frontend/TextDiagnosticPrinter.cpp | |
parent | 621bc69624599da62abd9bc9e5edd8a63ac99fe6 (diff) |
A direct extraction of the rest of the option printing into a helper.
This needs to be cleaned up to better use the ostream object, WIP.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@140490 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Frontend/TextDiagnosticPrinter.cpp')
-rw-r--r-- | lib/Frontend/TextDiagnosticPrinter.cpp | 108 |
1 files changed, 57 insertions, 51 deletions
diff --git a/lib/Frontend/TextDiagnosticPrinter.cpp b/lib/Frontend/TextDiagnosticPrinter.cpp index 7edc8fc1ab..e3578bc238 100644 --- a/lib/Frontend/TextDiagnosticPrinter.cpp +++ b/lib/Frontend/TextDiagnosticPrinter.cpp @@ -1091,48 +1091,12 @@ static void PrintDiagnosticName(raw_ostream &OS, const DiagnosticInfo &Info) { OS << " [" << DiagnosticIDs::getName(Info.getID()) << "]"; } -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; - Info.FormatDiagnostic(OutStr); - - llvm::raw_svector_ostream DiagMessageStream(OutStr); - if (DiagOpts->ShowNames) - PrintDiagnosticName(DiagMessageStream, Info); - DiagMessageStream.flush(); - +static void PrintDiagnosticOptions(raw_ostream &OS, + DiagnosticsEngine::Level Level, + const DiagnosticInfo &Info, + const DiagnosticOptions &DiagOpts) { std::string OptionName; - if (DiagOpts->ShowOptionNames) { + if (DiagOpts.ShowOptionNames) { // Was this a warning mapped to an error using -Werror or pragma? if (Level == DiagnosticsEngine::Error && DiagnosticIDs::isBuiltinWarningOrExtension(Info.getID())) { @@ -1164,33 +1128,75 @@ void TextDiagnosticPrinter::HandleDiagnostic(DiagnosticsEngine::Level Level, // If the user wants to see category information, include it too. unsigned DiagCategory = 0; - if (DiagOpts->ShowCategories) + if (DiagOpts.ShowCategories) DiagCategory = DiagnosticIDs::getCategoryNumberForDiag(Info.getID()); // If there is any categorization information, include it. if (!OptionName.empty() || DiagCategory != 0) { bool NeedsComma = false; - OutStr += " ["; + OS << " ["; if (!OptionName.empty()) { - OutStr += OptionName; + OS << OptionName; NeedsComma = true; } if (DiagCategory) { - if (NeedsComma) OutStr += ','; - if (DiagOpts->ShowCategories == 1) - OutStr += llvm::utostr(DiagCategory); + if (NeedsComma) OS << ','; + if (DiagOpts.ShowCategories == 1) + OS << llvm::utostr(DiagCategory); else { - assert(DiagOpts->ShowCategories == 2 && "Invalid ShowCategories value"); - OutStr += DiagnosticIDs::getCategoryNameFromID(DiagCategory); + assert(DiagOpts.ShowCategories == 2 && "Invalid ShowCategories value"); + OS << DiagnosticIDs::getCategoryNameFromID(DiagCategory); } } - OutStr += "]"; + OS << "]"; } +} + +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; + Info.FormatDiagnostic(OutStr); + + llvm::raw_svector_ostream DiagMessageStream(OutStr); + if (DiagOpts->ShowNames) + PrintDiagnosticName(DiagMessageStream, Info); + PrintDiagnosticOptions(DiagMessageStream, Level, Info, *DiagOpts); + DiagMessageStream.flush(); + - if (DiagOpts->ShowColors) { // Print warnings, errors and fatal errors in bold, no color switch (Level) { |