]> granicus.if.org Git - clang/commitdiff
[libclang] Support querying whether a declaration is invalid
authorIvan Donchevskii <ivan.donchevskii@qt.io>
Wed, 3 Jan 2018 09:49:31 +0000 (09:49 +0000)
committerIvan Donchevskii <ivan.donchevskii@qt.io>
Wed, 3 Jan 2018 09:49:31 +0000 (09:49 +0000)
This is useful for e.g. highlighting purposes in an IDE.

Patch by Nikolai Kosjar.

Differential Revision: https://reviews.llvm.org/D40072

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@321697 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang-c/Index.h
test/Index/print-type-size.cpp
tools/c-index-test/c-index-test.c
tools/libclang/CIndex.cpp
tools/libclang/libclang.exports

index 587008a7210b1b95a5adfdc76fb689eaedddaa19..2ea801913f24b7048a5991543c91bfdffdd3ed6f 100644 (file)
  * CINDEX_VERSION_MAJOR is intended for "major" source/ABI breaking changes.
  *
  * The policy about the libclang API was always to keep it source and ABI
- * compatible, thus CINDEX_VERSION_MAJOR is expected to remain stable.
- */
-#define CINDEX_VERSION_MAJOR 0
-#define CINDEX_VERSION_MINOR 45
-
-#define CINDEX_VERSION_ENCODE(major, minor) ( \
-      ((major) * 10000)                       \
+ * compatible, thus CINDEX_VERSION_MAJOR is expected to remain stable.\r
+ */\r
+#define CINDEX_VERSION_MAJOR 0\r
+#define CINDEX_VERSION_MINOR 46\r
+\r
+#define CINDEX_VERSION_ENCODE(major, minor) ( \\r
+      ((major) * 10000)                       \\r
     + ((minor) *     1))
 
 #define CINDEX_VERSION CINDEX_VERSION_ENCODE( \
@@ -2638,12 +2638,22 @@ CINDEX_LINKAGE enum CXCursorKind clang_getCursorKind(CXCursor);
 
 /**
  * \brief Determine whether the given cursor kind represents a declaration.
- */
-CINDEX_LINKAGE unsigned clang_isDeclaration(enum CXCursorKind);
-
-/**
- * \brief Determine whether the given cursor kind represents a simple
- * reference.
+ */\r
+CINDEX_LINKAGE unsigned clang_isDeclaration(enum CXCursorKind);\r
+\r
+/**\r
+ * \brief Determine whether the given declaration is invalid.\r
+ *\r
+ * A declaration is invalid if it could not be parsed successfully.\r
+ *\r
+ * \returns non-zero if the cursor represents a declaration and it is\r
+ * invalid, otherwise NULL.\r
+ */\r
+CINDEX_LINKAGE unsigned clang_isInvalidDeclaration(CXCursor);\r
+\r
+/**\r
+ * \brief Determine whether the given cursor kind represents a simple\r
+ * reference.\r
  *
  * Note that other kinds of cursors (such as expressions) can also refer to
  * other cursors. Use clang_getCursorReferenced() to determine whether a
index 45de93f308244a9b36ee6eaec0920a6f2d4a365e..3aa172f99ae07693fbc3bc48bf5b802a9c368366 100644 (file)
@@ -1,14 +1,14 @@
 // from SemaCXX/class-layout.cpp
 // RUN: c-index-test -test-print-type-size %s -target x86_64-pc-linux-gnu | FileCheck -check-prefix=CHECK64 %s
 // RUN: c-index-test -test-print-type-size %s -target i386-apple-darwin9 | FileCheck -check-prefix=CHECK32 %s
-
-namespace basic {
-
-// CHECK64: VarDecl=v:[[@LINE+2]]:6 (Definition) [type=void] [typekind=Void]
-// CHECK32: VarDecl=v:[[@LINE+1]]:6 (Definition) [type=void] [typekind=Void]
-void v;
-
-// CHECK64: VarDecl=v1:[[@LINE+2]]:7 (Definition) [type=void *] [typekind=Pointer] [sizeof=8] [alignof=8]
+\r
+namespace basic {\r
+\r
+// CHECK64: VarDecl=v:[[@LINE+2]]:6 (Definition) (invalid) [type=void] [typekind=Void]\r
+// CHECK32: VarDecl=v:[[@LINE+1]]:6 (Definition) (invalid) [type=void] [typekind=Void]\r
+void v;\r
+\r
+// CHECK64: VarDecl=v1:[[@LINE+2]]:7 (Definition) [type=void *] [typekind=Pointer] [sizeof=8] [alignof=8]\r
 // CHECK32: VarDecl=v1:[[@LINE+1]]:7 (Definition) [type=void *] [typekind=Pointer] [sizeof=4] [alignof=4]
 void *v1;
 
index 99f05669b64c748fe88e0cca09ce73efb64db73b..7ff814b6d67ac6c696f88826dbcfd2873b593060 100644 (file)
@@ -809,12 +809,14 @@ static void PrintCursor(CXCursor Cursor, const char *CommentSchemaFile) {
     if (clang_EnumDecl_isScoped(Cursor))
       printf(" (scoped)");
     if (clang_Cursor_isVariadic(Cursor))
-      printf(" (variadic)");
-    if (clang_Cursor_isObjCOptional(Cursor))
-      printf(" (@optional)");
-
-    switch (clang_getCursorExceptionSpecificationType(Cursor))
-    {
+      printf(" (variadic)");\r
+    if (clang_Cursor_isObjCOptional(Cursor))\r
+      printf(" (@optional)");\r
+    if (clang_isInvalidDeclaration(Cursor))\r
+      printf(" (invalid)");\r
+\r
+    switch (clang_getCursorExceptionSpecificationType(Cursor))\r
+    {\r
       case CXCursor_ExceptionSpecificationKind_None:
         break;
 
index f4d347108c9ff92768ee44b465b50e1cba7ea1c7..70bccc7eeaf0bb1c28e5ec340719d336d73af549 100644 (file)
@@ -5418,12 +5418,21 @@ unsigned clang_isInvalid(enum CXCursorKind K) {
 
 unsigned clang_isDeclaration(enum CXCursorKind K) {
   return (K >= CXCursor_FirstDecl && K <= CXCursor_LastDecl) ||
-         (K >= CXCursor_FirstExtraDecl && K <= CXCursor_LastExtraDecl);
-}
-
-unsigned clang_isReference(enum CXCursorKind K) {
-  return K >= CXCursor_FirstRef && K <= CXCursor_LastRef;
-}
+         (K >= CXCursor_FirstExtraDecl && K <= CXCursor_LastExtraDecl);\r
+}\r
+\r
+unsigned clang_isInvalidDeclaration(CXCursor C) {\r
+  if (clang_isDeclaration(C.kind)) {\r
+    if (const Decl *D = getCursorDecl(C))\r
+      return D->isInvalidDecl();\r
+  }\r
+\r
+  return 0;\r
+}\r
+\r
+unsigned clang_isReference(enum CXCursorKind K) {\r
+  return K >= CXCursor_FirstRef && K <= CXCursor_LastRef;\r
+}\r
 
 unsigned clang_isExpression(enum CXCursorKind K) {
   return K >= CXCursor_FirstExpr && K <= CXCursor_LastExpr;
index bf95b97073feeedd7382483d7d3a1941191814c6..f5d2de5823032b7da4d9a45b26913ea1c5dda530 100644 (file)
@@ -288,12 +288,13 @@ clang_index_isEntityObjCContainerKind
 clang_index_setClientContainer
 clang_index_setClientEntity
 clang_isAttribute
-clang_isConstQualifiedType
-clang_isCursorDefinition
-clang_isDeclaration
-clang_isExpression
-clang_isFileMultipleIncludeGuarded
-clang_isFunctionTypeVariadic
+clang_isConstQualifiedType\r
+clang_isCursorDefinition\r
+clang_isDeclaration\r
+clang_isInvalidDeclaration\r
+clang_isExpression\r
+clang_isFileMultipleIncludeGuarded\r
+clang_isFunctionTypeVariadic\r
 clang_isInvalid
 clang_isPODType
 clang_isPreprocessing