[cfe-commits] r140490 - /cfe/trunk/lib/Frontend/TextDiagnosticPrinter.cpp
Chandler Carruth
chandlerc at gmail.com
Sun Sep 25 17:44:09 PDT 2011
Author: chandlerc
Date: Sun Sep 25 19:44:09 2011
New Revision: 140490
URL: http://llvm.org/viewvc/llvm-project?rev=140490&view=rev
Log:
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.
Modified:
cfe/trunk/lib/Frontend/TextDiagnosticPrinter.cpp
Modified: cfe/trunk/lib/Frontend/TextDiagnosticPrinter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/TextDiagnosticPrinter.cpp?rev=140490&r1=140489&r2=140490&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/TextDiagnosticPrinter.cpp (original)
+++ cfe/trunk/lib/Frontend/TextDiagnosticPrinter.cpp Sun Sep 25 19:44:09 2011
@@ -1091,48 +1091,12 @@
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 @@
// 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) {
More information about the cfe-commits
mailing list