Implement clang_getDiagnosticCategoryText() to provide a way for a client of libclang to accurately
get the diagnostic category name from a serialized diagnostic when the version of libclang used
to read the diagnostic file is newer than the clang that emitted the diagnostic file.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@154567 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/tools/libclang/CIndexDiagnostic.cpp b/tools/libclang/CIndexDiagnostic.cpp
index d8a2b05..8fbe3d8 100644
--- a/tools/libclang/CIndexDiagnostic.cpp
+++ b/tools/libclang/CIndexDiagnostic.cpp
@@ -72,6 +72,8 @@
}
unsigned getCategory() const { return 0; }
+ CXString getCategoryText() const { return createCXString(""); }
+
unsigned getNumRanges() const { return 0; }
CXSourceRange getRange(unsigned Range) const { return clang_getNullRange(); }
unsigned getNumFixIts() const { return 0; }
@@ -324,7 +326,7 @@
}
if (Options & CXDiagnostic_DisplayCategoryName) {
- CXString CategoryName = clang_getDiagnosticCategoryName(CategoryID);
+ CXString CategoryName = clang_getDiagnosticCategoryText(Diagnostic);
if (NeedBracket)
Out << " [";
if (NeedComma)
@@ -385,9 +387,16 @@
}
CXString clang_getDiagnosticCategoryName(unsigned Category) {
+ // Kept for backwards compatibility.
return createCXString(DiagnosticIDs::getCategoryNameFromID(Category));
}
+CXString clang_getDiagnosticCategoryText(CXDiagnostic Diag) {
+ if (CXDiagnosticImpl *D = static_cast<CXDiagnosticImpl *>(Diag))
+ return D->getCategoryText();
+ return createCXString("");
+}
+
unsigned clang_getDiagnosticNumRanges(CXDiagnostic Diag) {
if (CXDiagnosticImpl *D = static_cast<CXDiagnosticImpl *>(Diag))
return D->getNumRanges();