]> granicus.if.org Git - clang/commitdiff
CIndex: Fix diagnostic callback to not return SourceLocations with a reference to...
authorDaniel Dunbar <daniel@zuster.org>
Sat, 30 Jan 2010 23:31:49 +0000 (23:31 +0000)
committerDaniel Dunbar <daniel@zuster.org>
Sat, 30 Jan 2010 23:31:49 +0000 (23:31 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@94928 91177308-0d34-0410-b5e6-96231b3b80d8

tools/CIndex/CIndexDiagnostic.cpp
tools/CIndex/CIndexDiagnostic.h

index c48872cebcf24466ddfc7edaaf667adfe8fe685f..87b9f66a5c5ee8c8ae54011c92f07d1ac51255bd 100644 (file)
@@ -27,7 +27,7 @@ namespace {
   /// \brief The storage behind a CXDiagnostic
   struct CXStoredDiagnostic {
     /// \brief The translation unit this diagnostic came from.
-    const LangOptions &LangOpts;
+    const LangOptions *LangOptsPtr;
     
     /// \brief The severity level of this diagnostic.
     Diagnostic::Level Level;
@@ -44,15 +44,23 @@ CIndexDiagnosticClient::~CIndexDiagnosticClient() { }
 
 void CIndexDiagnosticClient::BeginSourceFile(const LangOptions &LangOpts,
                                              const Preprocessor *PP) {
-  this->LangOpts = LangOpts;
+  assert(!LangOptsPtr && "Invalid state!");
+  LangOptsPtr = &LangOpts;
+}
+
+void CIndexDiagnosticClient::EndSourceFile() {
+  assert(LangOptsPtr && "Invalid state!");
+  LangOptsPtr = 0;
 }
 
 void CIndexDiagnosticClient::HandleDiagnostic(Diagnostic::Level DiagLevel,
                                               const DiagnosticInfo &Info) {
   if (!Callback)
     return;
-  
-  CXStoredDiagnostic Stored = { this->LangOpts, DiagLevel, Info };
+
+  assert((LangOptsPtr || Info.getLocation().isInvalid()) &&
+         "Missing language options with located diagnostic!");
+  CXStoredDiagnostic Stored = { this->LangOptsPtr, DiagLevel, Info };
   Callback(&Stored, ClientData);
 }
 
@@ -84,7 +92,7 @@ CXSourceLocation clang_getDiagnosticLocation(CXDiagnostic Diag) {
     return clang_getNullLocation();
   
   return translateSourceLocation(StoredDiag->Info.getLocation().getManager(),
-                                 StoredDiag->LangOpts,
+                                 *StoredDiag->LangOptsPtr,
                                  StoredDiag->Info.getLocation());
 }
 
@@ -118,7 +126,7 @@ void clang_getDiagnosticRanges(CXDiagnostic Diag,
   for (unsigned I = 0; I != N; ++I)
     (*Ranges)[I] = translateSourceRange(
                                     StoredDiag->Info.getLocation().getManager(),
-                                        StoredDiag->LangOpts,
+                                        *StoredDiag->LangOptsPtr,
                                         StoredDiag->Info.getRange(I));
 }
 
@@ -167,7 +175,7 @@ CXString clang_getDiagnosticFixItInsertion(CXDiagnostic Diag,
   if (Location && StoredDiag->Info.getLocation().isValid())
     *Location = translateSourceLocation(
                                     StoredDiag->Info.getLocation().getManager(),
-                                        StoredDiag->LangOpts, 
+                                        *StoredDiag->LangOptsPtr,
                                         Hint.InsertionLoc);
   return CIndexer::createCXString(Hint.CodeToInsert);
 }
@@ -182,7 +190,7 @@ CXSourceRange clang_getDiagnosticFixItRemoval(CXDiagnostic Diag,
   const CodeModificationHint &Hint
     = StoredDiag->Info.getCodeModificationHint(FixIt);
   return translateSourceRange(StoredDiag->Info.getLocation().getManager(),
-                              StoredDiag->LangOpts,
+                              *StoredDiag->LangOptsPtr,
                               Hint.RemoveRange);
 }
 
@@ -205,7 +213,7 @@ CXString clang_getDiagnosticFixItReplacement(CXDiagnostic Diag,
     = StoredDiag->Info.getCodeModificationHint(FixIt);
   if (Range)
     *Range = translateSourceRange(StoredDiag->Info.getLocation().getManager(),
-                                  StoredDiag->LangOpts,
+                                  *StoredDiag->LangOptsPtr,
                                   Hint.RemoveRange);
   return CIndexer::createCXString(Hint.CodeToInsert);  
 }
index 5fef01e555ae3b1b054f1762cd969338b96005ea..9f7ae51a108307e119dd0e68fc03cf62bd248240 100644 (file)
@@ -34,18 +34,20 @@ class Preprocessor;
 class CIndexDiagnosticClient : public DiagnosticClient {
   CXDiagnosticCallback Callback;
   CXClientData ClientData;
-  LangOptions LangOpts;
+  const LangOptions *LangOptsPtr;
   
 public:
   CIndexDiagnosticClient(CXDiagnosticCallback Callback,
                          CXClientData ClientData)
-    : Callback(Callback), ClientData(ClientData), LangOpts() { }
+    : Callback(Callback), ClientData(ClientData), LangOptsPtr(0) { }
   
   virtual ~CIndexDiagnosticClient();
   
   virtual void BeginSourceFile(const LangOptions &LangOpts,
                                const Preprocessor *PP);
   
+  virtual void EndSourceFile();
+
   virtual void HandleDiagnostic(Diagnostic::Level DiagLevel,
                                 const DiagnosticInfo &Info);
 };