This revision was automatically updated to reflect the committed changes.
Closed by commit rC321697: [libclang] Support querying whether a declaration is 
invalid (authored by yvvan, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D40072?vs=128491&id=128497#toc

Repository:
  rC Clang

https://reviews.llvm.org/D40072

Files:
  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: test/Index/print-type-size.cpp
===================================================================
--- test/Index/print-type-size.cpp
+++ test/Index/print-type-size.cpp
@@ -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]
+
+namespace basic {
+
+// CHECK64: VarDecl=v:[[@LINE+2]]:6 (Definition) (invalid) [type=void] [typekind=Void]
+// CHECK32: VarDecl=v:[[@LINE+1]]:6 (Definition) (invalid) [type=void] [typekind=Void]
+void v;
+
+// CHECK64: VarDecl=v1:[[@LINE+2]]:7 (Definition) [type=void *] [typekind=Pointer] [sizeof=8] [alignof=8]
 // CHECK32: VarDecl=v1:[[@LINE+1]]:7 (Definition) [type=void *] [typekind=Pointer] [sizeof=4] [alignof=4]
 void *v1;
 
Index: tools/libclang/CIndex.cpp
===================================================================
--- tools/libclang/CIndex.cpp
+++ tools/libclang/CIndex.cpp
@@ -5418,12 +5418,21 @@
 
 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);
+}
+
+unsigned clang_isInvalidDeclaration(CXCursor C) {
+  if (clang_isDeclaration(C.kind)) {
+    if (const Decl *D = getCursorDecl(C))
+      return D->isInvalidDecl();
+  }
+
+  return 0;
+}
+
+unsigned clang_isReference(enum CXCursorKind K) {
+  return K >= CXCursor_FirstRef && K <= CXCursor_LastRef;
+}
 
 unsigned clang_isExpression(enum CXCursorKind K) {
   return K >= CXCursor_FirstExpr && K <= CXCursor_LastExpr;
Index: tools/libclang/libclang.exports
===================================================================
--- tools/libclang/libclang.exports
+++ tools/libclang/libclang.exports
@@ -288,12 +288,13 @@
 clang_index_setClientContainer
 clang_index_setClientEntity
 clang_isAttribute
-clang_isConstQualifiedType
-clang_isCursorDefinition
-clang_isDeclaration
-clang_isExpression
-clang_isFileMultipleIncludeGuarded
-clang_isFunctionTypeVariadic
+clang_isConstQualifiedType
+clang_isCursorDefinition
+clang_isDeclaration
+clang_isInvalidDeclaration
+clang_isExpression
+clang_isFileMultipleIncludeGuarded
+clang_isFunctionTypeVariadic
 clang_isInvalid
 clang_isPODType
 clang_isPreprocessing
Index: tools/c-index-test/c-index-test.c
===================================================================
--- tools/c-index-test/c-index-test.c
+++ tools/c-index-test/c-index-test.c
@@ -809,12 +809,14 @@
     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)");
+    if (clang_Cursor_isObjCOptional(Cursor))
+      printf(" (@optional)");
+    if (clang_isInvalidDeclaration(Cursor))
+      printf(" (invalid)");
+
+    switch (clang_getCursorExceptionSpecificationType(Cursor))
+    {
       case CXCursor_ExceptionSpecificationKind_None:
         break;
 
Index: include/clang-c/Index.h
===================================================================
--- include/clang-c/Index.h
+++ include/clang-c/Index.h
@@ -29,13 +29,13 @@
  * 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.
+ */
+#define CINDEX_VERSION_MAJOR 0
+#define CINDEX_VERSION_MINOR 46
+
+#define CINDEX_VERSION_ENCODE(major, minor) ( \
+      ((major) * 10000)                       \
     + ((minor) *     1))
 
 #define CINDEX_VERSION CINDEX_VERSION_ENCODE( \
@@ -2638,12 +2638,22 @@
 
 /**
  * \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.
+ */
+CINDEX_LINKAGE unsigned clang_isDeclaration(enum CXCursorKind);
+
+/**
+ * \brief Determine whether the given declaration is invalid.
+ *
+ * A declaration is invalid if it could not be parsed successfully.
+ *
+ * \returns non-zero if the cursor represents a declaration and it is
+ * invalid, otherwise NULL.
+ */
+CINDEX_LINKAGE unsigned clang_isInvalidDeclaration(CXCursor);
+
+/**
+ * \brief Determine whether the given cursor kind represents a simple
+ * reference.
  *
  * Note that other kinds of cursors (such as expressions) can also refer to
  * other cursors. Use clang_getCursorReferenced() to determine whether a
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
  • [PATCH] D40072: [libclang... Nikolai Kosjar via Phabricator via cfe-commits
    • [PATCH] D40072: [lib... Ivan Donchevskii via Phabricator via cfe-commits

Reply via email to