[cfe-commits] r140526 - /cfe/trunk/lib/Frontend/TextDiagnosticPrinter.cpp

Chandler Carruth chandlerc at gmail.com
Mon Sep 26 04:38:46 PDT 2011


Author: chandlerc
Date: Mon Sep 26 06:38:46 2011
New Revision: 140526

URL: http://llvm.org/viewvc/llvm-project?rev=140526&view=rev
Log:
Hoist and beef up the asserts about the level of infrastructure expected
when working with a diagnostic attached to a source location. Also
comment more thoroughly why its important to handle non-location
diagnostic messages separately.

Finally, hoist the creation of the TextDiagnostic object up to the
beginning of the location-based diagnostics. This paves the way for
sinking more and more of the logic into this class. When everything
below this constructor is sunk into the TextDiagnostic class it should
be sufficiently "feature complete" to accomplish my two goals:
1) Have the printing of a macro expansion note use the exact same code
   as any other note.
2) Be able to implement clang_formatDiagnostic in terms of this class.

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=140526&r1=140525&r2=140526&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/TextDiagnosticPrinter.cpp (original)
+++ cfe/trunk/lib/Frontend/TextDiagnosticPrinter.cpp Mon Sep 26 06:38:46 2011
@@ -1189,6 +1189,9 @@
     OS << Prefix << ": ";
 
   // Use a dedicated, simpler path for diagnostics without a valid location.
+  // This is important as if the location is missing, we may be emitting
+  // diagnostics in a context that lacks language options, a source manager, or
+  // other infrastructure necessary when emitting more rich diagnostics.
   if (!Info.getLocation().isValid()) {
     printDiagnosticLevel(OS, Level, DiagOpts->ShowColors);
     printDiagnosticMessage(OS, Level, DiagMessageStream.str(),
@@ -1198,7 +1201,14 @@
     return;
   }
 
+  // Assert that the rest of our infrastructure is setup properly.
+  assert(LangOpts && "Unexpected diagnostic outside source file processing");
+  assert(DiagOpts && "Unexpected diagnostic without options set");
+  assert(Info.hasSourceManager() &&
+         "Unexpected diagnostic with no source manager");
   const SourceManager &SM = Info.getSourceManager();
+  TextDiagnostic TextDiag(*this, OS, SM, *LangOpts, *DiagOpts);
+
   PresumedLoc PLoc = getDiagnosticPresumedLoc(SM, Info.getLocation());
 
   // First, if this diagnostic is not in the main file, print out the
@@ -1243,11 +1253,6 @@
         Ranges.push_back(Hint.RemoveRange);
     }
 
-    assert(LangOpts && "Unexpected diagnostic outside source file processing");
-    assert(DiagOpts && "Unexpected diagnostic without options set");
-
-    TextDiagnostic TextDiag(*this, OS, Info.getSourceManager(),
-                            *LangOpts, *DiagOpts);
     unsigned MacroDepth = 0;
     TextDiag.Emit(LastLoc, Ranges, llvm::makeArrayRef(Info.getFixItHints(),
                                                       Info.getNumFixItHints()),





More information about the cfe-commits mailing list