[cfe-commits] r94928 - in /cfe/trunk/tools/CIndex: CIndexDiagnostic.cpp CIndexDiagnostic.h
Daniel Dunbar
daniel at zuster.org
Sat Jan 30 15:31:49 PST 2010
Author: ddunbar
Date: Sat Jan 30 17:31:49 2010
New Revision: 94928
URL: http://llvm.org/viewvc/llvm-project?rev=94928&view=rev
Log:
CIndex: Fix diagnostic callback to not return SourceLocations with a reference to a temporary LangOptions object.
Modified:
cfe/trunk/tools/CIndex/CIndexDiagnostic.cpp
cfe/trunk/tools/CIndex/CIndexDiagnostic.h
Modified: cfe/trunk/tools/CIndex/CIndexDiagnostic.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/CIndex/CIndexDiagnostic.cpp?rev=94928&r1=94927&r2=94928&view=diff
==============================================================================
--- cfe/trunk/tools/CIndex/CIndexDiagnostic.cpp (original)
+++ cfe/trunk/tools/CIndex/CIndexDiagnostic.cpp Sat Jan 30 17:31:49 2010
@@ -27,7 +27,7 @@
/// \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 @@
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 @@
return clang_getNullLocation();
return translateSourceLocation(StoredDiag->Info.getLocation().getManager(),
- StoredDiag->LangOpts,
+ *StoredDiag->LangOptsPtr,
StoredDiag->Info.getLocation());
}
@@ -118,7 +126,7 @@
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 @@
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 @@
const CodeModificationHint &Hint
= StoredDiag->Info.getCodeModificationHint(FixIt);
return translateSourceRange(StoredDiag->Info.getLocation().getManager(),
- StoredDiag->LangOpts,
+ *StoredDiag->LangOptsPtr,
Hint.RemoveRange);
}
@@ -205,7 +213,7 @@
= StoredDiag->Info.getCodeModificationHint(FixIt);
if (Range)
*Range = translateSourceRange(StoredDiag->Info.getLocation().getManager(),
- StoredDiag->LangOpts,
+ *StoredDiag->LangOptsPtr,
Hint.RemoveRange);
return CIndexer::createCXString(Hint.CodeToInsert);
}
Modified: cfe/trunk/tools/CIndex/CIndexDiagnostic.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/CIndex/CIndexDiagnostic.h?rev=94928&r1=94927&r2=94928&view=diff
==============================================================================
--- cfe/trunk/tools/CIndex/CIndexDiagnostic.h (original)
+++ cfe/trunk/tools/CIndex/CIndexDiagnostic.h Sat Jan 30 17:31:49 2010
@@ -34,18 +34,20 @@
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);
};
More information about the cfe-commits
mailing list