When printing diagnostics in c-index-test, also print source ranges
and fix-it information, so we can see everything in one place. Along
the way, fix a few bugs with deserialization and query of diagnostics
in CIndex.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@94768 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/tools/CIndex/CIndexDiagnostic.cpp b/tools/CIndex/CIndexDiagnostic.cpp
index eb039df..52de8bb 100644
--- a/tools/CIndex/CIndexDiagnostic.cpp
+++ b/tools/CIndex/CIndexDiagnostic.cpp
@@ -154,12 +154,21 @@
CXString clang_getDiagnosticFixItInsertion(CXDiagnostic Diag,
unsigned FixIt,
CXSourceLocation *Location) {
+ if (Location)
+ *Location = clang_getNullLocation();
+
CXStoredDiagnostic *StoredDiag = static_cast<CXStoredDiagnostic *>(Diag);
if (!StoredDiag || FixIt >= StoredDiag->Info.getNumCodeModificationHints())
return CIndexer::createCXString("");
const CodeModificationHint &Hint
= StoredDiag->Info.getCodeModificationHint(FixIt);
+
+ if (Location && StoredDiag->Info.getLocation().isValid())
+ *Location = translateSourceLocation(
+ StoredDiag->Info.getLocation().getManager(),
+ StoredDiag->LangOpts,
+ Hint.InsertionLoc);
return CIndexer::createCXString(Hint.CodeToInsert);
}
@@ -180,6 +189,9 @@
CXString clang_getDiagnosticFixItReplacement(CXDiagnostic Diag,
unsigned FixIt,
CXSourceRange *Range) {
+ if (Range)
+ *Range = clang_getNullRange();
+
CXStoredDiagnostic *StoredDiag = static_cast<CXStoredDiagnostic *>(Diag);
if (!StoredDiag || FixIt >= StoredDiag->Info.getNumCodeModificationHints() ||
StoredDiag->Info.getLocation().isInvalid()) {