summaryrefslogtreecommitdiffstats
path: root/clang
diff options
context:
space:
mode:
authorDouglas Gregor <dgregor@apple.com>2010-01-19 22:07:56 +0000
committerDouglas Gregor <dgregor@apple.com>2010-01-19 22:07:56 +0000
commitaccb183371d347130ae51d207336aceefbcae2dc (patch)
tree4cc1b717a70f0cdca26bc8fc5946ac10c0d5b5ee /clang
parentdc50e5d128f98081e3fda1bb42a6e49150ba5ffc (diff)
downloadbcm5719-llvm-accb183371d347130ae51d207336aceefbcae2dc.tar.gz
bcm5719-llvm-accb183371d347130ae51d207336aceefbcae2dc.zip
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. llvm-svn: 93924
Diffstat (limited to 'clang')
-rw-r--r--clang/include/clang-c/Index.h34
-rw-r--r--clang/test/Index/TestClassDecl.m2
-rw-r--r--clang/test/Index/TestClassForwardDecl.m2
-rw-r--r--clang/tools/CIndex/CIndex.cpp8
-rw-r--r--clang/tools/CIndex/CXCursor.cpp7
5 files changed, 46 insertions, 7 deletions
diff --git a/clang/include/clang-c/Index.h b/clang/include/clang-c/Index.h
index 022d5bb4796..a417209d837 100644
--- a/clang/include/clang-c/Index.h
+++ b/clang/include/clang-c/Index.h
@@ -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 */
diff --git a/clang/test/Index/TestClassDecl.m b/clang/test/Index/TestClassDecl.m
index 8bbe949948a..884289de96f 100644
--- a/clang/test/Index/TestClassDecl.m
+++ b/clang/test/Index/TestClassDecl.m
@@ -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
diff --git a/clang/test/Index/TestClassForwardDecl.m b/clang/test/Index/TestClassForwardDecl.m
index 65b7c6f5159..12f67fff66c 100644
--- a/clang/test/Index/TestClassForwardDecl.m
+++ b/clang/test/Index/TestClassForwardDecl.m
@@ -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)
diff --git a/clang/tools/CIndex/CIndex.cpp b/clang/tools/CIndex/CIndex.cpp
index a7cbb8a4fc7..b4759a51275 100644
--- a/clang/tools/CIndex/CIndex.cpp
+++ b/clang/tools/CIndex/CIndex.cpp
@@ -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";
diff --git a/clang/tools/CIndex/CXCursor.cpp b/clang/tools/CIndex/CXCursor.cpp
index 00636f74d50..f284b248cdf 100644
--- a/clang/tools/CIndex/CXCursor.cpp
+++ b/clang/tools/CIndex/CXCursor.cpp
@@ -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:
OpenPOWER on IntegriCloud