]> granicus.if.org Git - clang/commitdiff
Introduce the notion of an "unexposed" declaration into the CIndex
authorDouglas Gregor <dgregor@apple.com>
Tue, 19 Jan 2010 22:07:56 +0000 (22:07 +0000)
committerDouglas Gregor <dgregor@apple.com>
Tue, 19 Jan 2010 22:07:56 +0000 (22:07 +0000)
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.

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

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

index 022d5bb4796c6ca3d6aa93724282a12952d6c9be..a417209d837c69cd70537b2aff42f9f092d00d38 100644 (file)
@@ -55,26 +55,58 @@ typedef void *CXStmt;    /* A specific statement within a function/method */
 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 */
index 8bbe949948ac9e50955724aaa109faccff389191..884289de96f15bd09580fa9421a494b43cd251ee 100644 (file)
@@ -16,7 +16,7 @@ void function(Foo * arg)
 }
 
 // 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
index 65b7c6f5159d70e94a6317052441a83297424143..12f67fff66cab488e6e3ba5001591d8c9e518b38 100644 (file)
@@ -13,7 +13,7 @@ void function(Foo * arg)
 }
 
 // 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)
index a7cbb8a4fc789685f570fda815bfff32d219cddd..b4759a51275967426a8a1a08e4dc019956e1d002 100644 (file)
@@ -208,7 +208,7 @@ static enum CXCursorKind TranslateDeclRefExpr(DeclRefExpr *DRE) {
   else if (isa<EnumConstantDecl>(D))
     return CXCursor_EnumConstantRef;
   else
-    return CXCursor_NotImplemented;
+    return CXCursor_UnexposedDecl;
 }
 
 // Translation Unit Visitor.
@@ -712,7 +712,10 @@ static const FileEntry *getFileEntryFromSourceLocation(SourceManager &SMgr,
 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 @@ const char *clang_getCursorKindSpelling(enum CXCursorKind Kind) {
   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";
index 00636f74d50d543efd915d9a6639c2eb52b16f5d..f284b248cdf8b9724448d7297a8712ade1c65e1c 100644 (file)
@@ -44,10 +44,10 @@ static CXCursorKind GetCursorKind(Decl *D) {
     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 @@ static CXCursorKind GetCursorKind(Decl *D) {
           case TagDecl::TK_enum:   return CXCursor_EnumDecl;
         }
       }
+
+      return CXCursor_UnexposedDecl;
   }
   
   llvm_unreachable("Invalid Decl");
@@ -161,6 +163,7 @@ ASTContext &cxcursor::getCursorContext(CXCursor Cursor) {
   case CXCursor_ObjCClassMethodDecl:
   case CXCursor_ObjCImplementationDecl:
   case CXCursor_ObjCCategoryImplDecl:
+  case CXCursor_UnexposedDecl:
     return static_cast<Decl *>(Cursor.data[0])->getASTContext();
 
   case CXCursor_ObjCSuperClassRef: