Extend the CIndex API with direct support for expressions and

statements, moving some of the more unnatural kinds of references
(VarRef, EnumConstantRef, etc.) over to the expressions. We can now
poke at arbitrary expressions and statements with, e.g.,
clang_getCursor() and get back useful information (e.g., source
ranges).

llvm-svn: 93946
This commit is contained in:
Douglas Gregor 2010-01-19 23:20:36 +00:00
parent 314825bc8a
commit 8f40bbee78
9 changed files with 436 additions and 210 deletions

View File

@ -125,7 +125,55 @@ enum CXCursorKind {
CXCursor_InvalidFile = 70,
CXCursor_NoDeclFound = 71,
CXCursor_NotImplemented = 72,
CXCursor_LastInvalid = 72
CXCursor_LastInvalid = 72,
/* Expressions */
CXCursor_FirstExpr = 100,
/**
* \brief An expression whose specific kind is not exposed via this
* interface.
*
* Unexposed expressions have the same operations as any other kind
* of expression; one can extract their location information,
* spelling, children, etc. However, the specific kind of the
* expression is not reported.
*/
CXCursor_UnexposedExpr = 100,
/**
* \brief An expression that refers to some value declaration, such
* as a function, varible, or enumerator.
*/
CXCursor_DeclRefExpr = 101,
/**
* \brief An expression that refers to a member of a struct, union,
* class, Objective-C class, etc.
*/
CXCursor_MemberRefExpr = 102,
/** \brief An expression that calls a function. */
CXCursor_CallExpr = 103,
/** \brief An expression that sends a message to an Objective-C
object or class. */
CXCursor_ObjCMessageExpr = 104,
CXCursor_LastExpr = 104,
/* Statements */
CXCursor_FirstStmt = 200,
/**
* \brief A statement whose specific kind is not exposed via this
* interface.
*
* Unexposed statements have the same operations as any other kind of
* statement; one can extract their location information, spelling,
* children, etc. However, the specific kind of the statement is not
* reported.
*/
CXCursor_UnexposedStmt = 200,
CXCursor_LastStmt = 200
};
/**
@ -446,6 +494,8 @@ CINDEX_LINKAGE CXString clang_getCursorUSR(CXCursor);
CINDEX_LINKAGE enum CXCursorKind clang_getCursorKind(CXCursor);
CINDEX_LINKAGE unsigned clang_isDeclaration(enum CXCursorKind);
CINDEX_LINKAGE unsigned clang_isReference(enum CXCursorKind);
CINDEX_LINKAGE unsigned clang_isExpression(enum CXCursorKind);
CINDEX_LINKAGE unsigned clang_isStatement(enum CXCursorKind);
CINDEX_LINKAGE unsigned clang_isInvalid(enum CXCursorKind);
CINDEX_LINKAGE unsigned clang_equalCursors(CXCursor, CXCursor);

View File

@ -29,7 +29,7 @@ void function(Foo * arg)
// CHECK-scan: {start_line=13 start_col=19 end_line=13 end_col=19} ParmDecl=arg:13:21
// CHECK-scan: {start_line=13 start_col=20 end_line=13 end_col=20} FunctionDecl=function:13:6 (Definition)
// CHECK-scan: {start_line=13 start_col=21 end_line=13 end_col=23} ParmDecl=arg:13:21
// CHECK-scan: {start_line=13 start_col=24 end_line=16 end_col=1} FunctionDecl=function:13:6 (Definition)
// CHECK-scan: {start_line=14 start_col=1 end_line=16 end_col=1} UnexposedStmt=function
// CHECK-scan: {start_line=16 start_col=2 end_line=38 end_col=1} Invalid Cursor => NoDeclFound
// CHECK-load: TestClassDecl.m:10:12: ObjCInterfaceDecl=Foo:10:12 [Extent=10:1:11:4]

View File

@ -24,7 +24,7 @@ void function(Foo * arg)
// CHECK-scan: {start_line=10 start_col=19 end_line=10 end_col=19} ParmDecl=arg:10:21
// CHECK-scan: {start_line=10 start_col=20 end_line=10 end_col=20} FunctionDecl=function:10:6 (Definition)
// CHECK-scan: {start_line=10 start_col=21 end_line=10 end_col=23} ParmDecl=arg:10:21
// CHECK-scan: {start_line=10 start_col=24 end_line=13 end_col=1} FunctionDecl=function:10:6 (Definition)
// CHECK-scan: {start_line=11 start_col=1 end_line=13 end_col=1} UnexposedStmt=function
// CHECK-scan: {start_line=13 start_col=2 end_line=46 end_col=1} Invalid Cursor => NoDeclFound

View File

@ -104,15 +104,15 @@ int main (int argc, const char * argv[]) {
// CHECK: c-index-api-fn-scan.m:85:6: VarDecl=a:85:5
// CHECK: c-index-api-fn-scan.m:85:7: VarDecl=a:85:5
// CHECK: c-index-api-fn-scan.m:85:8: VarDecl=a:85:5
// CHECK: c-index-api-fn-scan.m:85:9: ObjCSelectorRef=foo:24:1
// CHECK: c-index-api-fn-scan.m:85:10: VarRef=bee:84:8
// CHECK: c-index-api-fn-scan.m:85:11: VarRef=bee:84:8
// CHECK: c-index-api-fn-scan.m:85:12: VarRef=bee:84:8
// CHECK: c-index-api-fn-scan.m:85:13: ObjCSelectorRef=foo:24:1
// CHECK: c-index-api-fn-scan.m:85:14: ObjCSelectorRef=foo:24:1
// CHECK: c-index-api-fn-scan.m:85:15: ObjCSelectorRef=foo:24:1
// CHECK: c-index-api-fn-scan.m:85:16: ObjCSelectorRef=foo:24:1
// CHECK: c-index-api-fn-scan.m:85:17: ObjCSelectorRef=foo:24:1
// CHECK: c-index-api-fn-scan.m:85:9: ObjCMessageExpr=foo:24:1
// CHECK: c-index-api-fn-scan.m:85:10: DeclRefExpr=bee:84:8
// CHECK: c-index-api-fn-scan.m:85:11: DeclRefExpr=bee:84:8
// CHECK: c-index-api-fn-scan.m:85:12: DeclRefExpr=bee:84:8
// CHECK: c-index-api-fn-scan.m:85:13: ObjCMessageExpr=foo:24:1
// CHECK: c-index-api-fn-scan.m:85:14: ObjCMessageExpr=foo:24:1
// CHECK: c-index-api-fn-scan.m:85:15: ObjCMessageExpr=foo:24:1
// CHECK: c-index-api-fn-scan.m:85:16: ObjCMessageExpr=foo:24:1
// CHECK: c-index-api-fn-scan.m:85:17: ObjCMessageExpr=foo:24:1
// CHECK: <invalid loc>:86:2: TypedefDecl=id:0:0
// CHECK: <invalid loc>:86:3: TypedefDecl=id:0:0
// CHECK: c-index-api-fn-scan.m:86:5: VarDecl=c:86:12
@ -125,16 +125,16 @@ int main (int argc, const char * argv[]) {
// CHECK: c-index-api-fn-scan.m:86:13: VarDecl=c:86:12
// CHECK: c-index-api-fn-scan.m:86:14: VarDecl=c:86:12
// CHECK: c-index-api-fn-scan.m:86:15: VarDecl=c:86:12
// CHECK: c-index-api-fn-scan.m:86:16: ObjCSelectorRef=fooC:25:1
// CHECK: c-index-api-fn-scan.m:86:17: ObjCSelectorRef=fooC:25:1
// CHECK: c-index-api-fn-scan.m:86:18: ObjCSelectorRef=fooC:25:1
// CHECK: c-index-api-fn-scan.m:86:19: ObjCSelectorRef=fooC:25:1
// CHECK: c-index-api-fn-scan.m:86:20: ObjCSelectorRef=fooC:25:1
// CHECK: c-index-api-fn-scan.m:86:21: ObjCSelectorRef=fooC:25:1
// CHECK: c-index-api-fn-scan.m:86:22: ObjCSelectorRef=fooC:25:1
// CHECK: c-index-api-fn-scan.m:86:23: ObjCSelectorRef=fooC:25:1
// CHECK: c-index-api-fn-scan.m:86:24: ObjCSelectorRef=fooC:25:1
// CHECK: c-index-api-fn-scan.m:86:25: ObjCSelectorRef=fooC:25:1
// CHECK: c-index-api-fn-scan.m:86:16: ObjCMessageExpr=fooC:25:1
// CHECK: c-index-api-fn-scan.m:86:17: ObjCMessageExpr=fooC:25:1
// CHECK: c-index-api-fn-scan.m:86:18: ObjCMessageExpr=fooC:25:1
// CHECK: c-index-api-fn-scan.m:86:19: ObjCMessageExpr=fooC:25:1
// CHECK: c-index-api-fn-scan.m:86:20: ObjCMessageExpr=fooC:25:1
// CHECK: c-index-api-fn-scan.m:86:21: ObjCMessageExpr=fooC:25:1
// CHECK: c-index-api-fn-scan.m:86:22: ObjCMessageExpr=fooC:25:1
// CHECK: c-index-api-fn-scan.m:86:23: ObjCMessageExpr=fooC:25:1
// CHECK: c-index-api-fn-scan.m:86:24: ObjCMessageExpr=fooC:25:1
// CHECK: c-index-api-fn-scan.m:86:25: ObjCMessageExpr=fooC:25:1
// CHECK: <invalid loc>:87:2: TypedefDecl=id:0:0
// CHECK: <invalid loc>:87:3: TypedefDecl=id:0:0
// CHECK: c-index-api-fn-scan.m:87:5: VarDecl=d:87:13
@ -145,73 +145,73 @@ int main (int argc, const char * argv[]) {
// CHECK: c-index-api-fn-scan.m:87:10: ObjCProtocolRef=Proto:40:1
// CHECK: c-index-api-fn-scan.m:87:11: VarDecl=d:87:13
// CHECK: c-index-api-fn-scan.m:87:13: VarDecl=d:87:13
// CHECK: c-index-api-fn-scan.m:88:2: VarRef=d:87:13
// CHECK: c-index-api-fn-scan.m:88:6: VarRef=c:86:12
// CHECK: c-index-api-fn-scan.m:89:2: ObjCSelectorRef=pMethod:41:1
// CHECK: c-index-api-fn-scan.m:89:3: VarRef=d:87:13
// CHECK: c-index-api-fn-scan.m:89:4: ObjCSelectorRef=pMethod:41:1
// CHECK: c-index-api-fn-scan.m:89:5: ObjCSelectorRef=pMethod:41:1
// CHECK: c-index-api-fn-scan.m:89:6: ObjCSelectorRef=pMethod:41:1
// CHECK: c-index-api-fn-scan.m:89:7: ObjCSelectorRef=pMethod:41:1
// CHECK: c-index-api-fn-scan.m:89:8: ObjCSelectorRef=pMethod:41:1
// CHECK: c-index-api-fn-scan.m:89:9: ObjCSelectorRef=pMethod:41:1
// CHECK: c-index-api-fn-scan.m:89:10: ObjCSelectorRef=pMethod:41:1
// CHECK: c-index-api-fn-scan.m:89:11: ObjCSelectorRef=pMethod:41:1
// CHECK: c-index-api-fn-scan.m:89:12: ObjCSelectorRef=pMethod:41:1
// CHECK: c-index-api-fn-scan.m:90:2: ObjCSelectorRef=catMethodWithFloat::36:1
// CHECK: c-index-api-fn-scan.m:90:3: VarRef=bee:84:8
// CHECK: c-index-api-fn-scan.m:90:4: VarRef=bee:84:8
// CHECK: c-index-api-fn-scan.m:90:5: VarRef=bee:84:8
// CHECK: c-index-api-fn-scan.m:90:6: ObjCSelectorRef=catMethodWithFloat::36:1
// CHECK: c-index-api-fn-scan.m:90:7: ObjCSelectorRef=catMethodWithFloat::36:1
// CHECK: c-index-api-fn-scan.m:90:8: ObjCSelectorRef=catMethodWithFloat::36:1
// CHECK: c-index-api-fn-scan.m:90:9: ObjCSelectorRef=catMethodWithFloat::36:1
// CHECK: c-index-api-fn-scan.m:90:10: ObjCSelectorRef=catMethodWithFloat::36:1
// CHECK: c-index-api-fn-scan.m:90:11: ObjCSelectorRef=catMethodWithFloat::36:1
// CHECK: c-index-api-fn-scan.m:90:12: ObjCSelectorRef=catMethodWithFloat::36:1
// CHECK: c-index-api-fn-scan.m:90:13: ObjCSelectorRef=catMethodWithFloat::36:1
// CHECK: c-index-api-fn-scan.m:90:14: ObjCSelectorRef=catMethodWithFloat::36:1
// CHECK: c-index-api-fn-scan.m:90:15: ObjCSelectorRef=catMethodWithFloat::36:1
// CHECK: c-index-api-fn-scan.m:90:16: ObjCSelectorRef=catMethodWithFloat::36:1
// CHECK: c-index-api-fn-scan.m:90:17: ObjCSelectorRef=catMethodWithFloat::36:1
// CHECK: c-index-api-fn-scan.m:90:18: ObjCSelectorRef=catMethodWithFloat::36:1
// CHECK: c-index-api-fn-scan.m:90:19: ObjCSelectorRef=catMethodWithFloat::36:1
// CHECK: c-index-api-fn-scan.m:90:20: ObjCSelectorRef=catMethodWithFloat::36:1
// CHECK: c-index-api-fn-scan.m:90:21: ObjCSelectorRef=catMethodWithFloat::36:1
// CHECK: c-index-api-fn-scan.m:90:22: ObjCSelectorRef=catMethodWithFloat::36:1
// CHECK: c-index-api-fn-scan.m:90:23: ObjCSelectorRef=catMethodWithFloat::36:1
// CHECK: c-index-api-fn-scan.m:90:24: ObjCSelectorRef=catMethodWithFloat::36:1
// CHECK: c-index-api-fn-scan.m:90:25: ObjCSelectorRef=catMethodWithFloat::36:1
// CHECK: c-index-api-fn-scan.m:90:26: ObjCSelectorRef=floatMethod:37:1
// CHECK: c-index-api-fn-scan.m:90:27: VarRef=bee:84:8
// CHECK: c-index-api-fn-scan.m:90:28: VarRef=bee:84:8
// CHECK: c-index-api-fn-scan.m:90:29: VarRef=bee:84:8
// CHECK: c-index-api-fn-scan.m:90:30: ObjCSelectorRef=floatMethod:37:1
// CHECK: c-index-api-fn-scan.m:90:31: ObjCSelectorRef=floatMethod:37:1
// CHECK: c-index-api-fn-scan.m:90:32: ObjCSelectorRef=floatMethod:37:1
// CHECK: c-index-api-fn-scan.m:90:33: ObjCSelectorRef=floatMethod:37:1
// CHECK: c-index-api-fn-scan.m:90:34: ObjCSelectorRef=floatMethod:37:1
// CHECK: c-index-api-fn-scan.m:90:35: ObjCSelectorRef=floatMethod:37:1
// CHECK: c-index-api-fn-scan.m:90:36: ObjCSelectorRef=floatMethod:37:1
// CHECK: c-index-api-fn-scan.m:90:37: ObjCSelectorRef=floatMethod:37:1
// CHECK: c-index-api-fn-scan.m:90:38: ObjCSelectorRef=floatMethod:37:1
// CHECK: c-index-api-fn-scan.m:90:39: ObjCSelectorRef=floatMethod:37:1
// CHECK: c-index-api-fn-scan.m:90:40: ObjCSelectorRef=floatMethod:37:1
// CHECK: c-index-api-fn-scan.m:90:41: ObjCSelectorRef=floatMethod:37:1
// CHECK: c-index-api-fn-scan.m:90:42: ObjCSelectorRef=floatMethod:37:1
// CHECK: c-index-api-fn-scan.m:90:43: ObjCSelectorRef=catMethodWithFloat::36:1
// CHECK: c-index-api-fn-scan.m:91:3: FunctionRef=main:83:5
// CHECK: c-index-api-fn-scan.m:91:4: FunctionRef=main:83:5
// CHECK: c-index-api-fn-scan.m:91:5: FunctionRef=main:83:5
// CHECK: c-index-api-fn-scan.m:91:6: FunctionRef=main:83:5
// CHECK: c-index-api-fn-scan.m:91:8: EnumConstantRef=someEnum:58:3
// CHECK: c-index-api-fn-scan.m:91:9: EnumConstantRef=someEnum:58:3
// CHECK: c-index-api-fn-scan.m:91:10: EnumConstantRef=someEnum:58:3
// CHECK: c-index-api-fn-scan.m:91:11: EnumConstantRef=someEnum:58:3
// CHECK: c-index-api-fn-scan.m:91:12: EnumConstantRef=someEnum:58:3
// CHECK: c-index-api-fn-scan.m:91:13: EnumConstantRef=someEnum:58:3
// CHECK: c-index-api-fn-scan.m:91:14: EnumConstantRef=someEnum:58:3
// CHECK: c-index-api-fn-scan.m:91:15: EnumConstantRef=someEnum:58:3
// CHECK: c-index-api-fn-scan.m:91:33: VarRef=bee:84:8
// CHECK: c-index-api-fn-scan.m:91:34: VarRef=bee:84:8
// CHECK: c-index-api-fn-scan.m:91:35: VarRef=bee:84:8
// CHECK: c-index-api-fn-scan.m:88:2: DeclRefExpr=d:87:13
// CHECK: c-index-api-fn-scan.m:88:6: DeclRefExpr=c:86:12
// CHECK: c-index-api-fn-scan.m:89:2: ObjCMessageExpr=pMethod:41:1
// CHECK: c-index-api-fn-scan.m:89:3: DeclRefExpr=d:87:13
// CHECK: c-index-api-fn-scan.m:89:4: ObjCMessageExpr=pMethod:41:1
// CHECK: c-index-api-fn-scan.m:89:5: ObjCMessageExpr=pMethod:41:1
// CHECK: c-index-api-fn-scan.m:89:6: ObjCMessageExpr=pMethod:41:1
// CHECK: c-index-api-fn-scan.m:89:7: ObjCMessageExpr=pMethod:41:1
// CHECK: c-index-api-fn-scan.m:89:8: ObjCMessageExpr=pMethod:41:1
// CHECK: c-index-api-fn-scan.m:89:9: ObjCMessageExpr=pMethod:41:1
// CHECK: c-index-api-fn-scan.m:89:10: ObjCMessageExpr=pMethod:41:1
// CHECK: c-index-api-fn-scan.m:89:11: ObjCMessageExpr=pMethod:41:1
// CHECK: c-index-api-fn-scan.m:89:12: ObjCMessageExpr=pMethod:41:1
// CHECK: c-index-api-fn-scan.m:90:2: ObjCMessageExpr=catMethodWithFloat::36:1
// CHECK: c-index-api-fn-scan.m:90:3: DeclRefExpr=bee:84:8
// CHECK: c-index-api-fn-scan.m:90:4: DeclRefExpr=bee:84:8
// CHECK: c-index-api-fn-scan.m:90:5: DeclRefExpr=bee:84:8
// CHECK: c-index-api-fn-scan.m:90:6: ObjCMessageExpr=catMethodWithFloat::36:1
// CHECK: c-index-api-fn-scan.m:90:7: ObjCMessageExpr=catMethodWithFloat::36:1
// CHECK: c-index-api-fn-scan.m:90:8: ObjCMessageExpr=catMethodWithFloat::36:1
// CHECK: c-index-api-fn-scan.m:90:9: ObjCMessageExpr=catMethodWithFloat::36:1
// CHECK: c-index-api-fn-scan.m:90:10: ObjCMessageExpr=catMethodWithFloat::36:1
// CHECK: c-index-api-fn-scan.m:90:11: ObjCMessageExpr=catMethodWithFloat::36:1
// CHECK: c-index-api-fn-scan.m:90:12: ObjCMessageExpr=catMethodWithFloat::36:1
// CHECK: c-index-api-fn-scan.m:90:13: ObjCMessageExpr=catMethodWithFloat::36:1
// CHECK: c-index-api-fn-scan.m:90:14: ObjCMessageExpr=catMethodWithFloat::36:1
// CHECK: c-index-api-fn-scan.m:90:15: ObjCMessageExpr=catMethodWithFloat::36:1
// CHECK: c-index-api-fn-scan.m:90:16: ObjCMessageExpr=catMethodWithFloat::36:1
// CHECK: c-index-api-fn-scan.m:90:17: ObjCMessageExpr=catMethodWithFloat::36:1
// CHECK: c-index-api-fn-scan.m:90:18: ObjCMessageExpr=catMethodWithFloat::36:1
// CHECK: c-index-api-fn-scan.m:90:19: ObjCMessageExpr=catMethodWithFloat::36:1
// CHECK: c-index-api-fn-scan.m:90:20: ObjCMessageExpr=catMethodWithFloat::36:1
// CHECK: c-index-api-fn-scan.m:90:21: ObjCMessageExpr=catMethodWithFloat::36:1
// CHECK: c-index-api-fn-scan.m:90:22: ObjCMessageExpr=catMethodWithFloat::36:1
// CHECK: c-index-api-fn-scan.m:90:23: ObjCMessageExpr=catMethodWithFloat::36:1
// CHECK: c-index-api-fn-scan.m:90:24: ObjCMessageExpr=catMethodWithFloat::36:1
// CHECK: c-index-api-fn-scan.m:90:25: ObjCMessageExpr=catMethodWithFloat::36:1
// CHECK: c-index-api-fn-scan.m:90:26: ObjCMessageExpr=floatMethod:37:1
// CHECK: c-index-api-fn-scan.m:90:27: DeclRefExpr=bee:84:8
// CHECK: c-index-api-fn-scan.m:90:28: DeclRefExpr=bee:84:8
// CHECK: c-index-api-fn-scan.m:90:29: DeclRefExpr=bee:84:8
// CHECK: c-index-api-fn-scan.m:90:30: ObjCMessageExpr=floatMethod:37:1
// CHECK: c-index-api-fn-scan.m:90:31: ObjCMessageExpr=floatMethod:37:1
// CHECK: c-index-api-fn-scan.m:90:32: ObjCMessageExpr=floatMethod:37:1
// CHECK: c-index-api-fn-scan.m:90:33: ObjCMessageExpr=floatMethod:37:1
// CHECK: c-index-api-fn-scan.m:90:34: ObjCMessageExpr=floatMethod:37:1
// CHECK: c-index-api-fn-scan.m:90:35: ObjCMessageExpr=floatMethod:37:1
// CHECK: c-index-api-fn-scan.m:90:36: ObjCMessageExpr=floatMethod:37:1
// CHECK: c-index-api-fn-scan.m:90:37: ObjCMessageExpr=floatMethod:37:1
// CHECK: c-index-api-fn-scan.m:90:38: ObjCMessageExpr=floatMethod:37:1
// CHECK: c-index-api-fn-scan.m:90:39: ObjCMessageExpr=floatMethod:37:1
// CHECK: c-index-api-fn-scan.m:90:40: ObjCMessageExpr=floatMethod:37:1
// CHECK: c-index-api-fn-scan.m:90:41: ObjCMessageExpr=floatMethod:37:1
// CHECK: c-index-api-fn-scan.m:90:42: ObjCMessageExpr=floatMethod:37:1
// CHECK: c-index-api-fn-scan.m:90:43: ObjCMessageExpr=catMethodWithFloat::36:1
// CHECK: c-index-api-fn-scan.m:91:3: DeclRefExpr=main:83:5
// CHECK: c-index-api-fn-scan.m:91:4: DeclRefExpr=main:83:5
// CHECK: c-index-api-fn-scan.m:91:5: DeclRefExpr=main:83:5
// CHECK: c-index-api-fn-scan.m:91:6: DeclRefExpr=main:83:5
// CHECK: c-index-api-fn-scan.m:91:8: DeclRefExpr=someEnum:58:3
// CHECK: c-index-api-fn-scan.m:91:9: DeclRefExpr=someEnum:58:3
// CHECK: c-index-api-fn-scan.m:91:10: DeclRefExpr=someEnum:58:3
// CHECK: c-index-api-fn-scan.m:91:11: DeclRefExpr=someEnum:58:3
// CHECK: c-index-api-fn-scan.m:91:12: DeclRefExpr=someEnum:58:3
// CHECK: c-index-api-fn-scan.m:91:13: DeclRefExpr=someEnum:58:3
// CHECK: c-index-api-fn-scan.m:91:14: DeclRefExpr=someEnum:58:3
// CHECK: c-index-api-fn-scan.m:91:15: DeclRefExpr=someEnum:58:3
// CHECK: c-index-api-fn-scan.m:91:33: DeclRefExpr=bee:84:8
// CHECK: c-index-api-fn-scan.m:91:34: DeclRefExpr=bee:84:8
// CHECK: c-index-api-fn-scan.m:91:35: DeclRefExpr=bee:84:8

View File

@ -53,108 +53,114 @@ int main (int argc, const char * argv[]) {
}
// CHECK: {start_line=1 start_col=1 end_line=2 end_col=62} Invalid Cursor => NoDeclFound
// CHECK: {start_line=3 start_col=1 end_line=6 end_col=1} ObjCInterfaceDecl=Foo:3:1
// CHECK: {start_line=3 start_col=1 end_line=6 end_col=1} ObjCInterfaceDecl=Foo:3:12
// CHECK: {start_line=7 start_col=1 end_line=7 end_col=6} ObjCInstanceMethodDecl=foo:7:1
// CHECK: {start_line=7 start_col=7 end_line=7 end_col=7} ObjCInterfaceDecl=Foo:3:1
// CHECK: {start_line=7 start_col=7 end_line=7 end_col=7} ObjCInterfaceDecl=Foo:3:12
// CHECK: {start_line=8 start_col=1 end_line=8 end_col=7} ObjCClassMethodDecl=fooC:8:1
// CHECK: {start_line=8 start_col=8 end_line=10 end_col=4} ObjCInterfaceDecl=Foo:3:1
// CHECK: {start_line=8 start_col=8 end_line=10 end_col=4} ObjCInterfaceDecl=Foo:3:12
// CHECK: {start_line=10 start_col=5 end_line=11 end_col=1} Invalid Cursor => NoDeclFound
// CHECK: {start_line=12 start_col=1 end_line=16 end_col=4} ObjCInterfaceDecl=Bar:12:1
// CHECK: {start_line=12 start_col=1 end_line=16 end_col=4} ObjCInterfaceDecl=Bar:12:12
// CHECK: {start_line=16 start_col=5 end_line=17 end_col=1} Invalid Cursor => NoDeclFound
// CHECK: {start_line=18 start_col=1 end_line=18 end_col=24} ObjCCategoryDecl=FooCat:18:1
// CHECK: {start_line=18 start_col=1 end_line=18 end_col=24} ObjCCategoryDecl=FooCat:18:12
// CHECK: {start_line=19 start_col=1 end_line=19 end_col=28} ObjCInstanceMethodDecl=catMethodWithFloat::19:1
// CHECK: {start_line=19 start_col=29 end_line=19 end_col=33} ParmDecl=fArg:19:36
// CHECK: {start_line=19 start_col=29 end_line=19 end_col=33} ParmDecl=fArg:19:36 (Definition)
// CHECK: {start_line=19 start_col=34 end_line=19 end_col=35} ObjCInstanceMethodDecl=catMethodWithFloat::19:1
// CHECK: {start_line=19 start_col=36 end_line=19 end_col=39} ParmDecl=fArg:19:36
// CHECK: {start_line=19 start_col=36 end_line=19 end_col=39} ParmDecl=fArg:19:36 (Definition)
// CHECK: {start_line=19 start_col=40 end_line=19 end_col=40} ObjCInstanceMethodDecl=catMethodWithFloat::19:1
// CHECK: {start_line=19 start_col=41 end_line=19 end_col=41} ObjCCategoryDecl=FooCat:18:1
// CHECK: {start_line=19 start_col=41 end_line=19 end_col=41} ObjCCategoryDecl=FooCat:18:12
// CHECK: {start_line=20 start_col=1 end_line=20 end_col=22} ObjCInstanceMethodDecl=floatMethod:20:1
// CHECK: {start_line=20 start_col=23 end_line=21 end_col=4} ObjCCategoryDecl=FooCat:18:1
// CHECK: {start_line=20 start_col=23 end_line=21 end_col=4} ObjCCategoryDecl=FooCat:18:12
// CHECK: {start_line=21 start_col=5 end_line=22 end_col=1} Invalid Cursor => NoDeclFound
// CHECK: {start_line=23 start_col=1 end_line=23 end_col=16} ObjCProtocolDecl=Proto:23:1
// CHECK: {start_line=23 start_col=1 end_line=23 end_col=16} ObjCProtocolDecl=Proto:23:1 (Definition)
// CHECK: {start_line=24 start_col=1 end_line=24 end_col=10} ObjCInstanceMethodDecl=pMethod:24:1
// CHECK: {start_line=24 start_col=11 end_line=25 end_col=4} ObjCProtocolDecl=Proto:23:1
// CHECK: {start_line=24 start_col=11 end_line=25 end_col=4} ObjCProtocolDecl=Proto:23:1 (Definition)
// CHECK: {start_line=25 start_col=5 end_line=26 end_col=1} Invalid Cursor => NoDeclFound
// CHECK: {start_line=27 start_col=1 end_line=27 end_col=23} ObjCProtocolDecl=SubP:27:1
// CHECK: {start_line=27 start_col=1 end_line=27 end_col=23} ObjCProtocolDecl=SubP:27:1 (Definition)
// CHECK: {start_line=28 start_col=1 end_line=28 end_col=11} ObjCInstanceMethodDecl=spMethod:28:1
// CHECK: {start_line=28 start_col=12 end_line=29 end_col=4} ObjCProtocolDecl=SubP:27:1
// CHECK: {start_line=28 start_col=12 end_line=29 end_col=4} ObjCProtocolDecl=SubP:27:1 (Definition)
// CHECK: {start_line=29 start_col=5 end_line=30 end_col=1} Invalid Cursor => NoDeclFound
// CHECK: {start_line=31 start_col=1 end_line=33 end_col=4} ObjCInterfaceDecl=Baz:31:1
// CHECK: {start_line=33 start_col=5 end_line=33 end_col=7} ObjCIvarDecl=_anIVar:33:9
// CHECK: {start_line=33 start_col=8 end_line=33 end_col=8} ObjCInterfaceDecl=Baz:31:1
// CHECK: {start_line=33 start_col=9 end_line=33 end_col=15} ObjCIvarDecl=_anIVar:33:9
// CHECK: {start_line=33 start_col=16 end_line=35 end_col=1} ObjCInterfaceDecl=Baz:31:1
// CHECK: {start_line=31 start_col=1 end_line=33 end_col=4} ObjCInterfaceDecl=Baz:31:12
// CHECK: {start_line=33 start_col=5 end_line=33 end_col=7} ObjCIvarDecl=_anIVar:33:9 (Definition)
// CHECK: {start_line=33 start_col=8 end_line=33 end_col=8} ObjCInterfaceDecl=Baz:31:12
// CHECK: {start_line=33 start_col=9 end_line=33 end_col=15} ObjCIvarDecl=_anIVar:33:9 (Definition)
// CHECK: {start_line=33 start_col=16 end_line=35 end_col=1} ObjCInterfaceDecl=Baz:31:12
// CHECK: {start_line=36 start_col=1 end_line=36 end_col=20} ObjCInstanceMethodDecl=bazMethod:36:1
// CHECK: {start_line=36 start_col=21 end_line=38 end_col=4} ObjCInterfaceDecl=Baz:31:1
// CHECK: {start_line=36 start_col=21 end_line=38 end_col=4} ObjCInterfaceDecl=Baz:31:12
// CHECK: {start_line=38 start_col=5 end_line=39 end_col=1} Invalid Cursor => NoDeclFound
// CHECK: {start_line=40 start_col=1 end_line=41 end_col=2} EnumDecl=:40:1
// CHECK: {start_line=41 start_col=3 end_line=41 end_col=10} EnumConstantDecl=someEnum:41:3
// CHECK: {start_line=41 start_col=11 end_line=42 end_col=1} EnumDecl=:40:1
// CHECK: {start_line=40 start_col=1 end_line=41 end_col=2} EnumDecl=:40:1 (Definition)
// CHECK: {start_line=41 start_col=3 end_line=41 end_col=10} EnumConstantDecl=someEnum:41:3 (Definition)
// CHECK: {start_line=41 start_col=11 end_line=42 end_col=1} EnumDecl=:40:1 (Definition)
// CHECK: {start_line=42 start_col=2 end_line=43 end_col=1} Invalid Cursor => NoDeclFound
// CHECK: {start_line=44 start_col=1 end_line=44 end_col=3} FunctionDecl=main:44:5 (Definition)
// CHECK: {start_line=44 start_col=4 end_line=44 end_col=4} Invalid Cursor => NoDeclFound
// CHECK: {start_line=44 start_col=5 end_line=44 end_col=10} FunctionDecl=main:44:5 (Definition)
// CHECK: {start_line=44 start_col=11 end_line=44 end_col=13} ParmDecl=argc:44:15
// CHECK: {start_line=44 start_col=11 end_line=44 end_col=13} ParmDecl=argc:44:15 (Definition)
// CHECK: {start_line=44 start_col=14 end_line=44 end_col=14} FunctionDecl=main:44:5 (Definition)
// CHECK: {start_line=44 start_col=15 end_line=44 end_col=18} ParmDecl=argc:44:15
// CHECK: {start_line=44 start_col=15 end_line=44 end_col=18} ParmDecl=argc:44:15 (Definition)
// CHECK: {start_line=44 start_col=19 end_line=44 end_col=26} FunctionDecl=main:44:5 (Definition)
// CHECK: {start_line=44 start_col=27 end_line=44 end_col=30} ParmDecl=argv:44:34
// CHECK: {start_line=44 start_col=27 end_line=44 end_col=30} ParmDecl=argv:44:34 (Definition)
// CHECK: {start_line=44 start_col=31 end_line=44 end_col=31} FunctionDecl=main:44:5 (Definition)
// CHECK: {start_line=44 start_col=32 end_line=44 end_col=32} ParmDecl=argv:44:34
// CHECK: {start_line=44 start_col=32 end_line=44 end_col=32} ParmDecl=argv:44:34 (Definition)
// CHECK: {start_line=44 start_col=33 end_line=44 end_col=33} FunctionDecl=main:44:5 (Definition)
// CHECK: {start_line=44 start_col=34 end_line=44 end_col=39} ParmDecl=argv:44:34
// CHECK: {start_line=44 start_col=40 end_line=45 end_col=1} FunctionDecl=main:44:5 (Definition)
// CHECK: {start_line=45 start_col=2 end_line=45 end_col=4} ObjCClassRef=Baz:31:1
// CHECK: {start_line=45 start_col=5 end_line=45 end_col=5} FunctionDecl=main:44:5 (Definition)
// CHECK: {start_line=45 start_col=6 end_line=45 end_col=6} VarDecl=bee:45:8
// CHECK: {start_line=45 start_col=7 end_line=45 end_col=7} FunctionDecl=main:44:5 (Definition)
// CHECK: {start_line=45 start_col=8 end_line=45 end_col=10} VarDecl=bee:45:8
// CHECK: {start_line=45 start_col=11 end_line=46 end_col=1} FunctionDecl=main:44:5 (Definition)
// CHECK: {start_line=46 start_col=2 end_line=46 end_col=3} TypedefDecl=id:0:0
// CHECK: {start_line=46 start_col=4 end_line=46 end_col=4} FunctionDecl=main:44:5 (Definition)
// CHECK: {start_line=46 start_col=5 end_line=46 end_col=8} VarDecl=a:46:5
// CHECK: {start_line=46 start_col=9 end_line=46 end_col=9} ObjCSelectorRef=foo:7:1
// CHECK: {start_line=46 start_col=10 end_line=46 end_col=12} VarRef=bee:45:8
// CHECK: {start_line=46 start_col=13 end_line=46 end_col=17} ObjCSelectorRef=foo:7:1
// CHECK: {start_line=46 start_col=18 end_line=47 end_col=1} FunctionDecl=main:44:5 (Definition)
// CHECK: {start_line=47 start_col=2 end_line=47 end_col=3} TypedefDecl=id:0:0
// CHECK: {start_line=47 start_col=4 end_line=47 end_col=4} FunctionDecl=main:44:5 (Definition)
// CHECK: {start_line=47 start_col=5 end_line=47 end_col=5} VarDecl=c:47:12
// CHECK: {start_line=44 start_col=34 end_line=44 end_col=39} ParmDecl=argv:44:34 (Definition)
// CHECK: {start_line=44 start_col=40 end_line=44 end_col=41} FunctionDecl=main:44:5 (Definition)
// CHECK: {start_line=44 start_col=42 end_line=45 end_col=1} UnexposedStmt=main
// CHECK: {start_line=45 start_col=2 end_line=45 end_col=4} ObjCClassRef=Baz:31:12
// CHECK: {start_line=45 start_col=5 end_line=45 end_col=5} UnexposedStmt=main
// CHECK: {start_line=45 start_col=6 end_line=45 end_col=6} VarDecl=bee:45:8 (Definition)
// CHECK: {start_line=45 start_col=7 end_line=45 end_col=7} UnexposedStmt=main
// CHECK: {start_line=45 start_col=8 end_line=45 end_col=10} VarDecl=bee:45:8 (Definition)
// CHECK: {start_line=45 start_col=11 end_line=45 end_col=11} UnexposedStmt=main
// CHECK: {start_line=45 start_col=12 end_line=46 end_col=1} UnexposedStmt=main
// CHECK: {start_line=46 start_col=2 end_line=46 end_col=3} TypedefDecl=id:0:0 (Definition)
// CHECK: {start_line=46 start_col=4 end_line=46 end_col=4} UnexposedStmt=main
// CHECK: {start_line=46 start_col=5 end_line=46 end_col=8} VarDecl=a:46:5 (Definition)
// CHECK: {start_line=46 start_col=9 end_line=46 end_col=9} ObjCMessageExpr=foo:7:1
// CHECK: {start_line=46 start_col=10 end_line=46 end_col=12} DeclRefExpr=bee:45:8
// CHECK: {start_line=46 start_col=13 end_line=46 end_col=17} ObjCMessageExpr=foo:7:1
// CHECK: {start_line=46 start_col=18 end_line=46 end_col=18} UnexposedStmt=main
// CHECK: {start_line=46 start_col=19 end_line=47 end_col=1} UnexposedStmt=main
// CHECK: {start_line=47 start_col=2 end_line=47 end_col=3} TypedefDecl=id:0:0 (Definition)
// CHECK: {start_line=47 start_col=4 end_line=47 end_col=4} UnexposedStmt=main
// CHECK: {start_line=47 start_col=5 end_line=47 end_col=5} VarDecl=c:47:12 (Definition)
// CHECK: {start_line=47 start_col=6 end_line=47 end_col=9} ObjCProtocolRef=SubP:27:1
// CHECK: {start_line=47 start_col=10 end_line=47 end_col=10} VarDecl=c:47:12
// CHECK: {start_line=47 start_col=11 end_line=47 end_col=11} FunctionDecl=main:44:5 (Definition)
// CHECK: {start_line=47 start_col=12 end_line=47 end_col=15} VarDecl=c:47:12
// CHECK: {start_line=47 start_col=16 end_line=47 end_col=25} ObjCSelectorRef=fooC:8:1
// CHECK: {start_line=47 start_col=26 end_line=48 end_col=1} FunctionDecl=main:44:5 (Definition)
// CHECK: {start_line=48 start_col=2 end_line=48 end_col=3} TypedefDecl=id:0:0
// CHECK: {start_line=48 start_col=4 end_line=48 end_col=4} FunctionDecl=main:44:5 (Definition)
// CHECK: {start_line=48 start_col=5 end_line=48 end_col=5} VarDecl=d:48:13
// CHECK: {start_line=47 start_col=10 end_line=47 end_col=10} VarDecl=c:47:12 (Definition)
// CHECK: {start_line=47 start_col=11 end_line=47 end_col=11} UnexposedStmt=main
// CHECK: {start_line=47 start_col=12 end_line=47 end_col=15} VarDecl=c:47:12 (Definition)
// CHECK: {start_line=47 start_col=16 end_line=47 end_col=25} ObjCMessageExpr=fooC:8:1
// CHECK: {start_line=47 start_col=26 end_line=47 end_col=26} UnexposedStmt=main
// CHECK: {start_line=47 start_col=27 end_line=48 end_col=1} UnexposedStmt=main
// CHECK: {start_line=48 start_col=2 end_line=48 end_col=3} TypedefDecl=id:0:0 (Definition)
// CHECK: {start_line=48 start_col=4 end_line=48 end_col=4} UnexposedStmt=main
// CHECK: {start_line=48 start_col=5 end_line=48 end_col=5} VarDecl=d:48:13 (Definition)
// CHECK: {start_line=48 start_col=6 end_line=48 end_col=10} ObjCProtocolRef=Proto:23:1
// CHECK: {start_line=48 start_col=11 end_line=48 end_col=11} VarDecl=d:48:13
// CHECK: {start_line=48 start_col=12 end_line=48 end_col=12} FunctionDecl=main:44:5 (Definition)
// CHECK: {start_line=48 start_col=13 end_line=48 end_col=13} VarDecl=d:48:13
// CHECK: {start_line=48 start_col=14 end_line=49 end_col=1} FunctionDecl=main:44:5 (Definition)
// CHECK: {start_line=49 start_col=2 end_line=49 end_col=2} VarRef=d:48:13
// CHECK: {start_line=49 start_col=3 end_line=49 end_col=5} FunctionDecl=main:44:5 (Definition)
// CHECK: {start_line=49 start_col=6 end_line=49 end_col=6} VarRef=c:47:12
// CHECK: {start_line=49 start_col=7 end_line=50 end_col=1} FunctionDecl=main:44:5 (Definition)
// CHECK: {start_line=50 start_col=2 end_line=50 end_col=2} ObjCSelectorRef=pMethod:24:1
// CHECK: {start_line=50 start_col=3 end_line=50 end_col=3} VarRef=d:48:13
// CHECK: {start_line=50 start_col=4 end_line=50 end_col=12} ObjCSelectorRef=pMethod:24:1
// CHECK: {start_line=50 start_col=13 end_line=51 end_col=1} FunctionDecl=main:44:5 (Definition)
// CHECK: {start_line=51 start_col=2 end_line=51 end_col=2} ObjCSelectorRef=catMethodWithFloat::19:1
// CHECK: {start_line=51 start_col=3 end_line=51 end_col=5} VarRef=bee:45:8
// CHECK: {start_line=51 start_col=6 end_line=51 end_col=25} ObjCSelectorRef=catMethodWithFloat::19:1
// CHECK: {start_line=51 start_col=26 end_line=51 end_col=26} ObjCSelectorRef=floatMethod:20:1
// CHECK: {start_line=51 start_col=27 end_line=51 end_col=29} VarRef=bee:45:8
// CHECK: {start_line=51 start_col=30 end_line=51 end_col=42} ObjCSelectorRef=floatMethod:20:1
// CHECK: {start_line=51 start_col=43 end_line=51 end_col=43} ObjCSelectorRef=catMethodWithFloat::19:1
// CHECK: {start_line=51 start_col=44 end_line=52 end_col=2} FunctionDecl=main:44:5 (Definition)
// CHECK: {start_line=52 start_col=3 end_line=52 end_col=6} FunctionRef=main:44:5
// CHECK: {start_line=52 start_col=7 end_line=52 end_col=7} FunctionDecl=main:44:5 (Definition)
// CHECK: {start_line=52 start_col=8 end_line=52 end_col=15} EnumConstantRef=someEnum:41:3
// CHECK: {start_line=52 start_col=16 end_line=52 end_col=32} FunctionDecl=main:44:5 (Definition)
// CHECK: {start_line=52 start_col=33 end_line=52 end_col=35} VarRef=bee:45:8
// CHECK: {start_line=52 start_col=36 end_line=53 end_col=1} FunctionDecl=main:44:5 (Definition)
// CHECK: {start_line=53 start_col=2 end_line=160 end_col=1} Invalid Cursor => NoDeclFound
// CHECK: {start_line=48 start_col=11 end_line=48 end_col=11} VarDecl=d:48:13 (Definition)
// CHECK: {start_line=48 start_col=12 end_line=48 end_col=12} UnexposedStmt=main
// CHECK: {start_line=48 start_col=13 end_line=48 end_col=13} VarDecl=d:48:13 (Definition)
// CHECK: {start_line=48 start_col=14 end_line=48 end_col=14} UnexposedStmt=main
// CHECK: {start_line=48 start_col=15 end_line=49 end_col=1} UnexposedStmt=main
// CHECK: {start_line=49 start_col=2 end_line=49 end_col=2} DeclRefExpr=d:48:13
// CHECK: {start_line=49 start_col=3 end_line=49 end_col=5} UnexposedExpr=
// CHECK: {start_line=49 start_col=6 end_line=49 end_col=6} DeclRefExpr=c:47:12
// CHECK: {start_line=49 start_col=7 end_line=50 end_col=1} UnexposedStmt=main
// CHECK: {start_line=50 start_col=2 end_line=50 end_col=2} ObjCMessageExpr=pMethod:24:1
// CHECK: {start_line=50 start_col=3 end_line=50 end_col=3} DeclRefExpr=d:48:13
// CHECK: {start_line=50 start_col=4 end_line=50 end_col=12} ObjCMessageExpr=pMethod:24:1
// CHECK: {start_line=50 start_col=13 end_line=51 end_col=1} UnexposedStmt=main
// CHECK: {start_line=51 start_col=2 end_line=51 end_col=2} ObjCMessageExpr=catMethodWithFloat::19:1
// CHECK: {start_line=51 start_col=3 end_line=51 end_col=5} DeclRefExpr=bee:45:8
// CHECK: {start_line=51 start_col=6 end_line=51 end_col=25} ObjCMessageExpr=catMethodWithFloat::19:1
// CHECK: {start_line=51 start_col=26 end_line=51 end_col=26} ObjCMessageExpr=floatMethod:20:1
// CHECK: {start_line=51 start_col=27 end_line=51 end_col=29} DeclRefExpr=bee:45:8
// CHECK: {start_line=51 start_col=30 end_line=51 end_col=42} ObjCMessageExpr=floatMethod:20:1
// CHECK: {start_line=51 start_col=43 end_line=51 end_col=43} ObjCMessageExpr=catMethodWithFloat::19:1
// CHECK: {start_line=51 start_col=44 end_line=52 end_col=2} UnexposedStmt=main
// CHECK: {start_line=52 start_col=3 end_line=52 end_col=6} DeclRefExpr=main:44:5
// CHECK: {start_line=52 start_col=7 end_line=52 end_col=7} CallExpr=main:44:5
// CHECK: {start_line=52 start_col=8 end_line=52 end_col=15} DeclRefExpr=someEnum:41:3
// CHECK: {start_line=52 start_col=16 end_line=52 end_col=17} CallExpr=main:44:5
// CHECK: {start_line=52 start_col=18 end_line=52 end_col=32} UnexposedExpr=bee:45:8
// CHECK: {start_line=52 start_col=33 end_line=52 end_col=35} DeclRefExpr=bee:45:8
// CHECK: {start_line=52 start_col=36 end_line=52 end_col=36} CallExpr=main:44:5
// CHECK: {start_line=52 start_col=37 end_line=53 end_col=1} UnexposedStmt=main

View File

@ -199,20 +199,7 @@ static CXSourceRange translateSourceRange(ASTContext &Context, SourceRange R) {
//===----------------------------------------------------------------------===//
namespace {
static enum CXCursorKind TranslateDeclRefExpr(DeclRefExpr *DRE) {
NamedDecl *D = DRE->getDecl();
if (isa<VarDecl>(D))
return CXCursor_VarRef;
else if (isa<FunctionDecl>(D))
return CXCursor_FunctionRef;
else if (isa<EnumConstantDecl>(D))
return CXCursor_EnumConstantRef;
else
return CXCursor_UnexposedDecl;
}
// Translation Unit Visitor.
class TUVisitor : public DeclVisitor<TUVisitor> {
public:
typedef void (*Iterator)(void *, CXCursor, CXClientData);
@ -849,6 +836,14 @@ CXString clang_getCursorSpelling(CXCursor C) {
return CIndexer::createCXString("<not implemented>");
}
}
if (clang_isExpression(C.kind)) {
Decl *D = getDeclFromExpr(getCursorExpr(C));
if (D)
return clang_getDeclSpelling(D);
return CIndexer::createCXString("");
}
return clang_getDeclSpelling(getCursorDecl(C));
}
@ -878,11 +873,15 @@ const char *clang_getCursorKindSpelling(enum CXCursorKind Kind) {
case CXCursor_ObjCProtocolRef: return "ObjCProtocolRef";
case CXCursor_ObjCClassRef: return "ObjCClassRef";
case CXCursor_ObjCSelectorRef: return "ObjCSelectorRef";
case CXCursor_VarRef: return "VarRef";
case CXCursor_FunctionRef: return "FunctionRef";
case CXCursor_EnumConstantRef: return "EnumConstantRef";
case CXCursor_UnexposedExpr: return "UnexposedExpr";
case CXCursor_DeclRefExpr: return "DeclRefExpr";
case CXCursor_MemberRefExpr: return "MemberRefExpr";
case CXCursor_CallExpr: return "CallExpr";
case CXCursor_ObjCMessageExpr: return "ObjCMessageExpr";
case CXCursor_UnexposedStmt: return "UnexposedStmt";
case CXCursor_InvalidFile: return "InvalidFile";
case CXCursor_NoDeclFound: return "NoDeclFound";
case CXCursor_NotImplemented: return "NotImplemented";
@ -919,15 +918,9 @@ CXCursor clang_getCursor(CXTranslationUnit CTUnit, const char *source_name,
Dcl = ALoc.AsNamedRef().ND;
Stmt *Stm = ALoc.dyn_AsStmt();
if (Dcl) {
if (Stm) {
if (DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(Stm))
return MakeCXCursor(TranslateDeclRefExpr(DRE), Dcl, Stm,
CXXUnit->getASTContext());
else if (ObjCMessageExpr *MExp = dyn_cast<ObjCMessageExpr>(Stm))
return MakeCXCursor(CXCursor_ObjCSelectorRef, Dcl, MExp,
CXXUnit->getASTContext());
// Fall through...treat as a decl, not a ref.
}
if (Stm)
return MakeCXCursor(Stm, Dcl);
if (ALoc.isNamedRef()) {
if (ObjCInterfaceDecl *Class = dyn_cast<ObjCInterfaceDecl>(Dcl))
return MakeCursorObjCClassRef(Class, ALoc.AsNamedRef().Loc);
@ -964,6 +957,14 @@ 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;
}
unsigned clang_isStatement(enum CXCursorKind K) {
return K >= CXCursor_FirstStmt && K <= CXCursor_LastStmt;
}
CXCursorKind clang_getCursorKind(CXCursor C) {
return C.kind;
}
@ -978,9 +979,25 @@ CXDecl clang_getCursorDecl(CXCursor C) {
return getCursorDecl(C);
}
if (clang_isExpression(C.kind))
return getDeclFromExpr(getCursorStmt(C));
return 0;
}
static SourceLocation getLocationFromExpr(Expr *E) {
if (ObjCMessageExpr *Msg = dyn_cast<ObjCMessageExpr>(E))
return /*FIXME:*/Msg->getLeftLoc();
if (DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(E))
return DRE->getLocation();
if (MemberExpr *Member = dyn_cast<MemberExpr>(E))
return Member->getMemberLoc();
if (ObjCIvarRefExpr *Ivar = dyn_cast<ObjCIvarRefExpr>(E))
return Ivar->getLocation();
return E->getLocStart();
}
CXSourceLocation clang_getCursorLocation(CXCursor C) {
if (clang_isReference(C.kind)) {
switch (C.kind) {
@ -1005,26 +1022,20 @@ CXSourceLocation clang_getCursorLocation(CXCursor C) {
case CXCursor_ObjCSelectorRef:
case CXCursor_VarRef:
case CXCursor_FunctionRef:
case CXCursor_EnumConstantRef: {
Expr *E = getCursorExpr(C);
ASTContext &Context = getCursorContext(C);
if (ObjCMessageExpr *Msg = dyn_cast<ObjCMessageExpr>(E))
return translateSourceLocation(Context, /*FIXME:*/Msg->getLeftLoc());
if (DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(E))
return translateSourceLocation(Context, DRE->getLocation());
if (MemberExpr *Member = dyn_cast<MemberExpr>(E))
return translateSourceLocation(Context, Member->getMemberLoc());
if (ObjCIvarRefExpr *Ivar = dyn_cast<ObjCIvarRefExpr>(E))
return translateSourceLocation(Context, Ivar->getLocation());
return translateSourceLocation(Context, E->getLocStart());
}
case CXCursor_EnumConstantRef:
return translateSourceLocation(getCursorContext(C),
getLocationFromExpr(getCursorExpr(C)));
default:
// FIXME: Need a way to enumerate all non-reference cases.
llvm_unreachable("Missed a reference kind");
}
}
if (clang_isExpression(C.kind))
return translateSourceLocation(getCursorContext(C),
getLocationFromExpr(getCursorExpr(C)));
if (!getCursorDecl(C)) {
CXSourceLocation empty = { 0, 0 };
return empty;
@ -1071,6 +1082,10 @@ CXSourceRange clang_getCursorExtent(CXCursor C) {
llvm_unreachable("Missed a reference kind");
}
}
if (clang_isExpression(C.kind))
return translateSourceRange(getCursorContext(C),
getCursorExpr(C)->getSourceRange());
if (!getCursorDecl(C)) {
CXSourceRange empty = { 0, 0, 0 };
@ -1085,6 +1100,13 @@ CXCursor clang_getCursorReferenced(CXCursor C) {
if (clang_isDeclaration(C.kind))
return C;
if (clang_isExpression(C.kind)) {
Decl *D = getDeclFromExpr(getCursorExpr(C));
if (D)
return MakeCXCursor(D);
return clang_getNullCursor();
}
if (!clang_isReference(C.kind))
return clang_getNullCursor();
@ -1120,7 +1142,7 @@ CXCursor clang_getCursorReferenced(CXCursor C) {
CXCursor clang_getCursorDefinition(CXCursor C) {
bool WasReference = false;
if (clang_isReference(C.kind)) {
if (clang_isReference(C.kind) || clang_isExpression(C.kind)) {
C = clang_getCursorReferenced(C);
WasReference = true;
}

View File

@ -42,8 +42,10 @@ _clang_getRangeStart
_clang_getTranslationUnitSpelling
_clang_isCursorDefinition
_clang_isDeclaration
_clang_isExpression
_clang_isInvalid
_clang_isReference
_clang_isStatement
_clang_loadDeclaration
_clang_loadTranslationUnit
_clang_setUseExternalASTGeneration

View File

@ -80,6 +80,141 @@ CXCursor cxcursor::MakeCXCursor(Decl *D) {
return MakeCXCursor(GetCursorKind(D), D);
}
CXCursor cxcursor::MakeCXCursor(Stmt *S, Decl *Parent) {
CXCursorKind K = CXCursor_NotImplemented;
switch (S->getStmtClass()) {
case Stmt::NoStmtClass:
break;
case Stmt::NullStmtClass:
case Stmt::CompoundStmtClass:
case Stmt::CaseStmtClass:
case Stmt::DefaultStmtClass:
case Stmt::LabelStmtClass:
case Stmt::IfStmtClass:
case Stmt::SwitchStmtClass:
case Stmt::WhileStmtClass:
case Stmt::DoStmtClass:
case Stmt::ForStmtClass:
case Stmt::GotoStmtClass:
case Stmt::IndirectGotoStmtClass:
case Stmt::ContinueStmtClass:
case Stmt::BreakStmtClass:
case Stmt::ReturnStmtClass:
case Stmt::DeclStmtClass:
case Stmt::SwitchCaseClass:
case Stmt::AsmStmtClass:
case Stmt::ObjCAtTryStmtClass:
case Stmt::ObjCAtCatchStmtClass:
case Stmt::ObjCAtFinallyStmtClass:
case Stmt::ObjCAtThrowStmtClass:
case Stmt::ObjCAtSynchronizedStmtClass:
case Stmt::ObjCForCollectionStmtClass:
case Stmt::CXXCatchStmtClass:
case Stmt::CXXTryStmtClass:
K = CXCursor_UnexposedStmt;
break;
case Stmt::ExprClass:
case Stmt::PredefinedExprClass:
case Stmt::IntegerLiteralClass:
case Stmt::FloatingLiteralClass:
case Stmt::ImaginaryLiteralClass:
case Stmt::StringLiteralClass:
case Stmt::CharacterLiteralClass:
case Stmt::ParenExprClass:
case Stmt::UnaryOperatorClass:
case Stmt::SizeOfAlignOfExprClass:
case Stmt::ArraySubscriptExprClass:
case Stmt::CastExprClass:
case Stmt::BinaryOperatorClass:
case Stmt::CompoundAssignOperatorClass:
case Stmt::ConditionalOperatorClass:
case Stmt::ImplicitCastExprClass:
case Stmt::ExplicitCastExprClass:
case Stmt::CStyleCastExprClass:
case Stmt::CompoundLiteralExprClass:
case Stmt::ExtVectorElementExprClass:
case Stmt::InitListExprClass:
case Stmt::DesignatedInitExprClass:
case Stmt::ImplicitValueInitExprClass:
case Stmt::ParenListExprClass:
case Stmt::VAArgExprClass:
case Stmt::AddrLabelExprClass:
case Stmt::StmtExprClass:
case Stmt::TypesCompatibleExprClass:
case Stmt::ChooseExprClass:
case Stmt::GNUNullExprClass:
case Stmt::CXXNamedCastExprClass:
case Stmt::CXXStaticCastExprClass:
case Stmt::CXXDynamicCastExprClass:
case Stmt::CXXReinterpretCastExprClass:
case Stmt::CXXConstCastExprClass:
case Stmt::CXXFunctionalCastExprClass:
case Stmt::CXXTypeidExprClass:
case Stmt::CXXBoolLiteralExprClass:
case Stmt::CXXNullPtrLiteralExprClass:
case Stmt::CXXThisExprClass:
case Stmt::CXXThrowExprClass:
case Stmt::CXXDefaultArgExprClass:
case Stmt::CXXZeroInitValueExprClass:
case Stmt::CXXNewExprClass:
case Stmt::CXXDeleteExprClass:
case Stmt::CXXPseudoDestructorExprClass:
case Stmt::UnresolvedLookupExprClass:
case Stmt::UnaryTypeTraitExprClass:
case Stmt::DependentScopeDeclRefExprClass:
case Stmt::CXXBindTemporaryExprClass:
case Stmt::CXXExprWithTemporariesClass:
case Stmt::CXXUnresolvedConstructExprClass:
case Stmt::CXXDependentScopeMemberExprClass:
case Stmt::UnresolvedMemberExprClass:
case Stmt::ObjCStringLiteralClass:
case Stmt::ObjCEncodeExprClass:
case Stmt::ObjCSelectorExprClass:
case Stmt::ObjCProtocolExprClass:
case Stmt::ObjCImplicitSetterGetterRefExprClass:
case Stmt::ObjCSuperExprClass:
case Stmt::ObjCIsaExprClass:
case Stmt::ShuffleVectorExprClass:
case Stmt::BlockExprClass:
K = CXCursor_UnexposedExpr;
break;
case Stmt::DeclRefExprClass:
case Stmt::BlockDeclRefExprClass:
// FIXME: UnresolvedLookupExpr?
// FIXME: DependentScopeDeclRefExpr?
K = CXCursor_DeclRefExpr;
break;
case Stmt::MemberExprClass:
case Stmt::ObjCIvarRefExprClass:
case Stmt::ObjCPropertyRefExprClass:
// FIXME: UnresolvedMemberExpr?
// FIXME: CXXDependentScopeMemberExpr?
K = CXCursor_MemberRefExpr;
break;
case Stmt::CallExprClass:
case Stmt::CXXOperatorCallExprClass:
case Stmt::CXXMemberCallExprClass:
case Stmt::CXXConstructExprClass:
case Stmt::CXXTemporaryObjectExprClass:
// FIXME: CXXUnresolvedConstructExpr
// FIXME: ObjCImplicitSetterGetterRefExpr?
K = CXCursor_CallExpr;
break;
case Stmt::ObjCMessageExprClass:
K = CXCursor_ObjCMessageExpr;
break;
}
CXCursor C = { K, { Parent, S, 0 } };
return C;
}
CXCursor cxcursor::MakeCursorObjCSuperClassRef(ObjCInterfaceDecl *Super,
SourceLocation Loc) {
void *RawLoc = reinterpret_cast<void *>(Loc.getRawEncoding());
@ -181,6 +316,16 @@ ASTContext &cxcursor::getCursorContext(CXCursor Cursor) {
case CXCursor_NoDeclFound:
case CXCursor_NotImplemented:
llvm_unreachable("No context in an invalid cursor");
break;
case CXCursor_UnexposedExpr:
case CXCursor_DeclRefExpr:
case CXCursor_MemberRefExpr:
case CXCursor_CallExpr:
case CXCursor_ObjCMessageExpr:
case CXCursor_UnexposedStmt:
return static_cast<Decl *>(Cursor.data[0])->getASTContext();
}
llvm_unreachable("No context available");

View File

@ -33,6 +33,7 @@ namespace cxcursor {
CXCursor MakeCXCursor(CXCursorKind K, clang::Decl *D);
CXCursor MakeCXCursor(CXCursorKind K, clang::Decl *D, clang::Stmt *S,
ASTContext &Context);
CXCursor MakeCXCursor(clang::Stmt *S, clang::Decl *Parent);
CXCursor MakeCXCursor(clang::Decl *D);
/// \brief Create an Objective-C superclass reference at the given location.