[cfe-commits] r130919 - in /cfe/trunk: include/clang/Basic/Diagnostic.h lib/Basic/Diagnostic.cpp

Argyrios Kyrtzidis akyrtzi at gmail.com
Thu May 5 00:54:59 PDT 2011


Author: akirtzidis
Date: Thu May  5 02:54:59 2011
New Revision: 130919

URL: http://llvm.org/viewvc/llvm-project?rev=130919&view=rev
Log:
Introduce a Diagnostic::Report function that accepts and emits a StoredDiagnostic.

Modified:
    cfe/trunk/include/clang/Basic/Diagnostic.h
    cfe/trunk/lib/Basic/Diagnostic.cpp

Modified: cfe/trunk/include/clang/Basic/Diagnostic.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/Diagnostic.h?rev=130919&r1=130918&r2=130919&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/Diagnostic.h (original)
+++ cfe/trunk/include/clang/Basic/Diagnostic.h Thu May  5 02:54:59 2011
@@ -32,6 +32,7 @@
   class LangOptions;
   class Preprocessor;
   class DiagnosticErrorTrap;
+  class StoredDiagnostic;
 
 /// \brief Annotates a diagnostic with some code that should be
 /// inserted, removed, or replaced to fix the problem.
@@ -487,6 +488,8 @@
   inline DiagnosticBuilder Report(SourceLocation Pos, unsigned DiagID);
   inline DiagnosticBuilder Report(unsigned DiagID);
 
+  void Report(const StoredDiagnostic &storedDiag);
+
   /// \brief Determine whethere there is already a diagnostic in flight.
   bool isDiagnosticInFlight() const { return CurDiagID != ~0U; }
 
@@ -839,8 +842,11 @@
 /// about the currently in-flight diagnostic.
 class DiagnosticInfo {
   const Diagnostic *DiagObj;
+  llvm::StringRef StoredDiagMessage;
 public:
   explicit DiagnosticInfo(const Diagnostic *DO) : DiagObj(DO) {}
+  DiagnosticInfo(const Diagnostic *DO, llvm::StringRef storedDiagMessage)
+    : DiagObj(DO), StoredDiagMessage(storedDiagMessage) {}
 
   const Diagnostic *getDiags() const { return DiagObj; }
   unsigned getID() const { return DiagObj->CurDiagID; }

Modified: cfe/trunk/lib/Basic/Diagnostic.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/Diagnostic.cpp?rev=130919&r1=130918&r2=130919&view=diff
==============================================================================
--- cfe/trunk/lib/Basic/Diagnostic.cpp (original)
+++ cfe/trunk/lib/Basic/Diagnostic.cpp Thu May  5 02:54:59 2011
@@ -212,6 +212,42 @@
                                                FullSourceLoc(Loc, *SourceMgr)));
 }
 
+void Diagnostic::Report(const StoredDiagnostic &storedDiag) {
+  assert(CurDiagID == ~0U && "Multiple diagnostics in flight at once!");
+
+  CurDiagLoc = storedDiag.getLocation();
+  CurDiagID = storedDiag.getID();
+  NumDiagArgs = 0;
+
+  NumDiagRanges = storedDiag.range_size();
+  assert(NumDiagRanges < sizeof(DiagRanges)/sizeof(DiagRanges[0]) &&
+         "Too many arguments to diagnostic!");
+  unsigned i = 0;
+  for (StoredDiagnostic::range_iterator
+         RI = storedDiag.range_begin(),
+         RE = storedDiag.range_end(); RI != RE; ++RI)
+    DiagRanges[i++] = *RI;
+
+  NumFixItHints = storedDiag.fixit_size();
+  assert(NumFixItHints < Diagnostic::MaxFixItHints && "Too many fix-it hints!");
+  i = 0;
+  for (StoredDiagnostic::fixit_iterator
+         FI = storedDiag.fixit_begin(),
+         FE = storedDiag.fixit_end(); FI != FE; ++FI)
+    FixItHints[i++] = *FI;
+
+  assert(Client && "DiagnosticClient not set!");
+  Level DiagLevel = storedDiag.getLevel();
+  DiagnosticInfo Info(this, storedDiag.getMessage());
+  Client->HandleDiagnostic(DiagLevel, Info);
+  if (Client->IncludeInDiagnosticCounts()) {
+    if (DiagLevel == Diagnostic::Warning)
+      ++NumWarnings;
+  }
+
+  CurDiagID = ~0U;
+}
+
 void DiagnosticBuilder::FlushCounts() {
   DiagObj->NumDiagArgs = NumArgs;
   DiagObj->NumDiagRanges = NumRanges;
@@ -486,6 +522,11 @@
 /// array.
 void DiagnosticInfo::
 FormatDiagnostic(llvm::SmallVectorImpl<char> &OutStr) const {
+  if (!StoredDiagMessage.empty()) {
+    OutStr.append(StoredDiagMessage.begin(), StoredDiagMessage.end());
+    return;
+  }
+
   const char *DiagStr = getDiags()->getDiagnosticIDs()->getDescription(getID());
   const char *DiagEnd = DiagStr+strlen(DiagStr);
 





More information about the cfe-commits mailing list