[cfe-commits] r93924 - in /cfe/trunk: include/clang-c/Index.h test/Index/TestClassDecl.m test/Index/TestClassForwardDecl.m tools/CIndex/CIndex.cpp tools/CIndex/CXCursor.cpp

Douglas Gregor dgregor at apple.com
Tue Jan 19 14:07:56 PST 2010


Author: dgregor
Date: Tue Jan 19 16:07:56 2010
New Revision: 93924

URL: http://llvm.org/viewvc/llvm-project?rev=93924&view=rev
Log:
Introduce the notion of an "unexposed" declaration into the CIndex
API. This is a catch-all for any declaration known to Clang but not
specifically part of the CIndex API. We'll use the same approach with
expressions, statements, references, etc., as needed.

Modified:
    cfe/trunk/include/clang-c/Index.h
    cfe/trunk/test/Index/TestClassDecl.m
    cfe/trunk/test/Index/TestClassForwardDecl.m
    cfe/trunk/tools/CIndex/CIndex.cpp
    cfe/trunk/tools/CIndex/CXCursor.cpp

Modified: cfe/trunk/include/clang-c/Index.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang-c/Index.h?rev=93924&r1=93923&r2=93924&view=diff

==============================================================================
--- cfe/trunk/include/clang-c/Index.h (original)
+++ cfe/trunk/include/clang-c/Index.h Tue Jan 19 16:07:56 2010
@@ -55,26 +55,58 @@
 enum CXCursorKind {
  /* Declarations */
  CXCursor_FirstDecl                     = 1,
+ /** \brief A typedef */
  CXCursor_TypedefDecl                   = 1,
+ /** \brief A C or C++ struct. */
  CXCursor_StructDecl                    = 2, 
+ /** \brief A C or C++ union. */
  CXCursor_UnionDecl                     = 3,
+ /** \brief A C++ class. */
  CXCursor_ClassDecl                     = 4,
+ /** \brief An enumeration. */
  CXCursor_EnumDecl                      = 5,
+ /** 
+  * \brief A field (in C) or non-static data member (in C++) in a
+  * struct, union, or C++ class.
+  */
  CXCursor_FieldDecl                     = 6,
+ /** \brief An enumerator constant. */
  CXCursor_EnumConstantDecl              = 7,
+ /** \brief A function. */
  CXCursor_FunctionDecl                  = 8,
+ /** \brief A variable. */
  CXCursor_VarDecl                       = 9,
+ /** \brief A function or method parameter. */
  CXCursor_ParmDecl                      = 10,
+ /** \brief An Objective-C @interface. */
  CXCursor_ObjCInterfaceDecl             = 11,
+ /** \brief An Objective-C @interface for a category. */
  CXCursor_ObjCCategoryDecl              = 12,
+ /** \brief An Objective-C @protocol declaration. */
  CXCursor_ObjCProtocolDecl              = 13,
+ /** \brief An Objective-C @property declaration. */
  CXCursor_ObjCPropertyDecl              = 14,
+ /** \brief An Objective-C instance variable. */
  CXCursor_ObjCIvarDecl                  = 15,
+ /** \brief An Objective-C instance method. */
  CXCursor_ObjCInstanceMethodDecl        = 16,
+ /** \brief An Objective-C class method. */
  CXCursor_ObjCClassMethodDecl           = 17,
+ /** \brief An Objective-C @implementation. */
  CXCursor_ObjCImplementationDecl        = 18,
+ /** \brief An Objective-C @implementation for a category. */
  CXCursor_ObjCCategoryImplDecl          = 19,
- CXCursor_LastDecl                      = 19,
+ /** 
+  * \brief A declaration whose specific kind is not exposed via this
+  * interface. 
+  *
+  * Unexposed declarations have the same operations as any other kind
+  * of declaration; one can extract their location information,
+  * spelling, find their definitions, etc. However, the specific kind
+  * of the declaration is not reported.
+  */
+ CXCursor_UnexposedDecl                 = 20,
+ CXCursor_LastDecl                      = 20,
  
  /* References */
  CXCursor_FirstRef                      = 40, /* Decl references */

Modified: cfe/trunk/test/Index/TestClassDecl.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Index/TestClassDecl.m?rev=93924&r1=93923&r2=93924&view=diff

==============================================================================
--- cfe/trunk/test/Index/TestClassDecl.m (original)
+++ cfe/trunk/test/Index/TestClassDecl.m Tue Jan 19 16:07:56 2010
@@ -16,7 +16,7 @@
 }
 
 // CHECK-scan: {start_line=1 start_col=1 end_line=7 end_col=1} Invalid Cursor => NoDeclFound
-// CHECK-scan: {start_line=8 start_col=1 end_line=8 end_col=7} Invalid Cursor => NotImplemented
+// CHECK-scan: {start_line=8 start_col=1 end_line=8 end_col=7} UnexposedDecl=:8:1
 // CHECK-scan: {start_line=8 start_col=8 end_line=8 end_col=10} ObjCClassRef=Foo:10:1
 // CHECK-scan: {start_line=8 start_col=11 end_line=9 end_col=1} Invalid Cursor => NoDeclFound
 // CHECK-scan: {start_line=10 start_col=1 end_line=11 end_col=4} ObjCInterfaceDecl=Foo:10:1

Modified: cfe/trunk/test/Index/TestClassForwardDecl.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Index/TestClassForwardDecl.m?rev=93924&r1=93923&r2=93924&view=diff

==============================================================================
--- cfe/trunk/test/Index/TestClassForwardDecl.m (original)
+++ cfe/trunk/test/Index/TestClassForwardDecl.m Tue Jan 19 16:07:56 2010
@@ -13,7 +13,7 @@
 }
 
 // CHECK-scan: {start_line=1 start_col=1 end_line=7 end_col=1} Invalid Cursor => NoDeclFound
-// CHECK-scan: {start_line=8 start_col=1 end_line=8 end_col=7} Invalid Cursor => NotImplemented
+// CHECK-scan: {start_line=8 start_col=1 end_line=8 end_col=7} UnexposedDecl=:8:1
 // CHECK-scan: {start_line=8 start_col=8 end_line=8 end_col=10} ObjCClassRef=Foo:8:8
 // CHECK-scan: {start_line=8 start_col=11 end_line=9 end_col=1} Invalid Cursor => NoDeclFound
 // CHECK-scan: {start_line=10 start_col=1 end_line=10 end_col=4} FunctionDecl=function:10:6 (Definition)

Modified: cfe/trunk/tools/CIndex/CIndex.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/CIndex/CIndex.cpp?rev=93924&r1=93923&r2=93924&view=diff

==============================================================================
--- cfe/trunk/tools/CIndex/CIndex.cpp (original)
+++ cfe/trunk/tools/CIndex/CIndex.cpp Tue Jan 19 16:07:56 2010
@@ -208,7 +208,7 @@
   else if (isa<EnumConstantDecl>(D))
     return CXCursor_EnumConstantRef;
   else
-    return CXCursor_NotImplemented;
+    return CXCursor_UnexposedDecl;
 }
 
 // Translation Unit Visitor.
@@ -712,7 +712,10 @@
 extern "C" {
 CXString clang_getDeclSpelling(CXDecl AnonDecl) {
   assert(AnonDecl && "Passed null CXDecl");
-  NamedDecl *ND = static_cast<NamedDecl *>(AnonDecl);
+  Decl *D = static_cast<Decl *>(AnonDecl);
+  NamedDecl *ND = dyn_cast<NamedDecl>(D);
+  if (!ND)
+    return CIndexer::createCXString("");
 
   if (ObjCMethodDecl *OMD = dyn_cast<ObjCMethodDecl>(ND))
     return CIndexer::createCXString(OMD->getSelector().getAsString().c_str(),
@@ -871,6 +874,7 @@
   case CXCursor_ObjCClassMethodDecl: return "ObjCClassMethodDecl";
   case CXCursor_ObjCImplementationDecl: return "ObjCImplementationDecl";
   case CXCursor_ObjCCategoryImplDecl: return "ObjCCategoryImplDecl";
+  case CXCursor_UnexposedDecl: return "UnexposedDecl";
   case CXCursor_ObjCSuperClassRef: return "ObjCSuperClassRef";
   case CXCursor_ObjCProtocolRef: return "ObjCProtocolRef";
   case CXCursor_ObjCClassRef: return "ObjCClassRef";

Modified: cfe/trunk/tools/CIndex/CXCursor.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/CIndex/CXCursor.cpp?rev=93924&r1=93923&r2=93924&view=diff

==============================================================================
--- cfe/trunk/tools/CIndex/CXCursor.cpp (original)
+++ cfe/trunk/tools/CIndex/CXCursor.cpp Tue Jan 19 16:07:56 2010
@@ -44,10 +44,10 @@
     case Decl::ObjCCategoryImpl:   return CXCursor_ObjCCategoryImplDecl;
     case Decl::ObjCClass:
       // FIXME
-      return CXCursor_NotImplemented;
+      return CXCursor_UnexposedDecl;
     case Decl::ObjCForwardProtocol:
       // FIXME
-      return CXCursor_NotImplemented;      
+      return CXCursor_UnexposedDecl;      
     case Decl::ObjCImplementation: return CXCursor_ObjCImplementationDecl;
     case Decl::ObjCInterface:      return CXCursor_ObjCInterfaceDecl;
     case Decl::ObjCIvar:           return CXCursor_ObjCIvarDecl; 
@@ -68,6 +68,8 @@
           case TagDecl::TK_enum:   return CXCursor_EnumDecl;
         }
       }
+
+      return CXCursor_UnexposedDecl;
   }
   
   llvm_unreachable("Invalid Decl");
@@ -161,6 +163,7 @@
   case CXCursor_ObjCClassMethodDecl:
   case CXCursor_ObjCImplementationDecl:
   case CXCursor_ObjCCategoryImplDecl:
+  case CXCursor_UnexposedDecl:
     return static_cast<Decl *>(Cursor.data[0])->getASTContext();
 
   case CXCursor_ObjCSuperClassRef:





More information about the cfe-commits mailing list