[cfe-commits] r154567 - in /cfe/trunk: include/clang-c/Index.h test/Misc/serialized-diags-single-issue.c tools/c-index-test/c-index-test.c tools/libclang/CIndexDiagnostic.cpp tools/libclang/CIndexDiagnostic.h tools/libclang/CXLoadedDiagnostic.cpp tools/libclang/CXLoadedDiagnostic.h tools/libclang/CXStoredDiagnostic.cpp tools/libclang/libclang.exports
Ted Kremenek
kremenek at apple.com
Wed Apr 11 17:03:31 PDT 2012
Author: kremenek
Date: Wed Apr 11 19:03:31 2012
New Revision: 154567
URL: http://llvm.org/viewvc/llvm-project?rev=154567&view=rev
Log:
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.
Modified:
cfe/trunk/include/clang-c/Index.h
cfe/trunk/test/Misc/serialized-diags-single-issue.c
cfe/trunk/tools/c-index-test/c-index-test.c
cfe/trunk/tools/libclang/CIndexDiagnostic.cpp
cfe/trunk/tools/libclang/CIndexDiagnostic.h
cfe/trunk/tools/libclang/CXLoadedDiagnostic.cpp
cfe/trunk/tools/libclang/CXLoadedDiagnostic.h
cfe/trunk/tools/libclang/CXStoredDiagnostic.cpp
cfe/trunk/tools/libclang/libclang.exports
Modified: cfe/trunk/include/clang-c/Index.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang-c/Index.h?rev=154567&r1=154566&r2=154567&view=diff
==============================================================================
--- cfe/trunk/include/clang-c/Index.h (original)
+++ cfe/trunk/include/clang-c/Index.h Wed Apr 11 19:03:31 2012
@@ -35,6 +35,16 @@
#define CINDEX_LINKAGE
#endif
+#ifdef __GNUC__
+ #define CINDEX_DEPRECATED __attribute__((deprecated))
+#else
+ #ifdef _MSC_VER
+ #define CINDEX_DEPRECATED __declspec(deprecated)
+ #else
+ #define CINDEX_DEPRECATED
+ #endif
+#endif
+
/** \defgroup CINDEX libclang: C Interface to Clang
*
* The C Interface to Clang provides a relatively small API that exposes
@@ -830,14 +840,25 @@
CINDEX_LINKAGE unsigned clang_getDiagnosticCategory(CXDiagnostic);
/**
- * \brief Retrieve the name of a particular diagnostic category.
+ * \brief Retrieve the name of a particular diagnostic category. This
+ * is now deprecated. Use clang_getDiagnosticCategoryText()
+ * instead.
*
* \param Category A diagnostic category number, as returned by
* \c clang_getDiagnosticCategory().
*
* \returns The name of the given diagnostic category.
*/
-CINDEX_LINKAGE CXString clang_getDiagnosticCategoryName(unsigned Category);
+CINDEX_DEPRECATED CINDEX_LINKAGE
+CXString clang_getDiagnosticCategoryName(unsigned Category);
+
+/**
+ * \brief Retrieve the diagnostic category text for a given diagnostic.
+ *
+ *
+ * \returns The text of the given diagnostic category.
+ */
+CINDEX_LINKAGE CXString clang_getDiagnosticCategoryText(CXDiagnostic);
/**
* \brief Determine the number of source ranges associated with the given
Modified: cfe/trunk/test/Misc/serialized-diags-single-issue.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Misc/serialized-diags-single-issue.c?rev=154567&r1=154566&r2=154567&view=diff
==============================================================================
--- cfe/trunk/test/Misc/serialized-diags-single-issue.c (original)
+++ cfe/trunk/test/Misc/serialized-diags-single-issue.c Wed Apr 11 19:03:31 2012
@@ -10,7 +10,7 @@
// NOTE: it is important that this test case only contain a single issue. This test case checks
// if we can handle serialized diagnostics that contain only one diagnostic.
-// CHECK: {{.*}}serialized-diags-single-issue.c:3:12: warning: variable 'voodoo' is uninitialized when used here [-Wuninitialized]
+// CHECK: {{.*}}serialized-diags-single-issue.c:3:12: warning: variable 'voodoo' is uninitialized when used here [-Wuninitialized] [Semantic Issue]
// CHECK: Range: {{.*}}serialized-diags-single-issue.c:3:12 {{.*}}serialized-diags-single-issue.c:3:18
// CHECK: +-{{.*}}serialized-diags-single-issue.c:2:13: note: initialize the variable 'voodoo' to silence this warning []
// CHECK: +-Range: {{.*}}serialized-diags-single-issue.c:2:13 {{.*}}serialized-diags-single-issue.c:2:13
Modified: cfe/trunk/tools/c-index-test/c-index-test.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/c-index-test/c-index-test.c?rev=154567&r1=154566&r2=154567&view=diff
==============================================================================
--- cfe/trunk/tools/c-index-test/c-index-test.c (original)
+++ cfe/trunk/tools/c-index-test/c-index-test.c Wed Apr 11 19:03:31 2012
@@ -2586,9 +2586,9 @@
CXSourceLocation DiagLoc;
CXDiagnostic D;
CXFile File;
- CXString FileName, DiagSpelling, DiagOption;
+ CXString FileName, DiagSpelling, DiagOption, DiagCat;
unsigned line, column, offset;
- const char *DiagOptionStr = 0;
+ const char *DiagOptionStr = 0, *DiagCatStr = 0;
D = clang_getDiagnosticInSet(Diags, i);
DiagLoc = clang_getDiagnosticLocation(D);
@@ -2611,6 +2611,12 @@
fprintf(stderr, " [%s]", DiagOptionStr);
}
+ DiagCat = clang_getDiagnosticCategoryText(D);
+ DiagCatStr = clang_getCString(DiagCat);
+ if (DiagCatStr) {
+ fprintf(stderr, " [%s]", DiagCatStr);
+ }
+
fprintf(stderr, "\n");
printRanges(D, indent);
Modified: cfe/trunk/tools/libclang/CIndexDiagnostic.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/libclang/CIndexDiagnostic.cpp?rev=154567&r1=154566&r2=154567&view=diff
==============================================================================
--- cfe/trunk/tools/libclang/CIndexDiagnostic.cpp (original)
+++ cfe/trunk/tools/libclang/CIndexDiagnostic.cpp Wed Apr 11 19:03:31 2012
@@ -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();
Modified: cfe/trunk/tools/libclang/CIndexDiagnostic.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/libclang/CIndexDiagnostic.h?rev=154567&r1=154566&r2=154567&view=diff
==============================================================================
--- cfe/trunk/tools/libclang/CIndexDiagnostic.h (original)
+++ cfe/trunk/tools/libclang/CIndexDiagnostic.h Wed Apr 11 19:03:31 2012
@@ -73,7 +73,10 @@
/// \brief Return the category of the diagnostic.
virtual unsigned getCategory() const = 0;
-
+
+ /// \brief Return the category string of the diagnostic.
+ virtual CXString getCategoryText() const = 0;
+
/// \brief Return the number of source ranges for the diagnostic.
virtual unsigned getNumRanges() const = 0;
@@ -132,6 +135,9 @@
/// \brief Return the category of the diagnostic.
virtual unsigned getCategory() const;
+ /// \brief Return the category string of the diagnostic.
+ virtual CXString getCategoryText() const;
+
/// \brief Return the number of source ranges for the diagnostic.
virtual unsigned getNumRanges() const;
Modified: cfe/trunk/tools/libclang/CXLoadedDiagnostic.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/libclang/CXLoadedDiagnostic.cpp?rev=154567&r1=154566&r2=154567&view=diff
==============================================================================
--- cfe/trunk/tools/libclang/CXLoadedDiagnostic.cpp (original)
+++ cfe/trunk/tools/libclang/CXLoadedDiagnostic.cpp Wed Apr 11 19:03:31 2012
@@ -119,6 +119,10 @@
return category;
}
+CXString CXLoadedDiagnostic::getCategoryText() const {
+ return cxstring::createCXString(CategoryText);
+}
+
unsigned CXLoadedDiagnostic::getNumRanges() const {
return Ranges.size();
}
@@ -650,6 +654,7 @@
D->category = Record[offset++];
unsigned diagFlag = Record[offset++];
D->DiagOption = diagFlag ? TopDiags.WarningFlags[diagFlag] : "";
+ D->CategoryText = D->category ? TopDiags.Categories[D->category] : "";
D->Spelling = TopDiags.makeString(BlobStart, BlobLen);
continue;
}
Modified: cfe/trunk/tools/libclang/CXLoadedDiagnostic.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/libclang/CXLoadedDiagnostic.h?rev=154567&r1=154566&r2=154567&view=diff
==============================================================================
--- cfe/trunk/tools/libclang/CXLoadedDiagnostic.h (original)
+++ cfe/trunk/tools/libclang/CXLoadedDiagnostic.h Wed Apr 11 19:03:31 2012
@@ -43,6 +43,9 @@
/// \brief Return the category of the diagnostic.
virtual unsigned getCategory() const;
+ /// \brief Return the category string of the diagnostic.
+ virtual CXString getCategoryText() const;
+
/// \brief Return the number of source ranges for the diagnostic.
virtual unsigned getNumRanges() const;
@@ -82,6 +85,7 @@
std::vector<std::pair<CXSourceRange, CXString> > FixIts;
llvm::StringRef Spelling;
llvm::StringRef DiagOption;
+ llvm::StringRef CategoryText;
unsigned severity;
unsigned category;
};
Modified: cfe/trunk/tools/libclang/CXStoredDiagnostic.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/libclang/CXStoredDiagnostic.cpp?rev=154567&r1=154566&r2=154567&view=diff
==============================================================================
--- cfe/trunk/tools/libclang/CXStoredDiagnostic.cpp (original)
+++ cfe/trunk/tools/libclang/CXStoredDiagnostic.cpp Wed Apr 11 19:03:31 2012
@@ -79,6 +79,11 @@
return DiagnosticIDs::getCategoryNumberForDiag(Diag.getID());
}
+CXString CXStoredDiagnostic::getCategoryText() const {
+ unsigned catID = DiagnosticIDs::getCategoryNumberForDiag(Diag.getID());
+ return createCXString(DiagnosticIDs::getCategoryNameFromID(catID));
+}
+
unsigned CXStoredDiagnostic::getNumRanges() const {
if (Diag.getLocation().isInvalid())
return 0;
Modified: cfe/trunk/tools/libclang/libclang.exports
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/libclang/libclang.exports?rev=154567&r1=154566&r2=154567&view=diff
==============================================================================
--- cfe/trunk/tools/libclang/libclang.exports (original)
+++ cfe/trunk/tools/libclang/libclang.exports Wed Apr 11 19:03:31 2012
@@ -6,9 +6,9 @@
clang_CXXMethod_isVirtual
clang_Cursor_getArgument
clang_Cursor_getNumArguments
+clang_Cursor_getObjCSelectorIndex
clang_Cursor_getSpellingNameRange
clang_Cursor_getTranslationUnit
-clang_Cursor_getObjCSelectorIndex
clang_Cursor_isNull
clang_IndexAction_create
clang_IndexAction_dispose
@@ -97,6 +97,7 @@
clang_getDiagnostic
clang_getDiagnosticCategory
clang_getDiagnosticCategoryName
+clang_getDiagnosticCategoryText
clang_getDiagnosticFixIt
clang_getDiagnosticInSet
clang_getDiagnosticLocation
More information about the cfe-commits
mailing list