[libclang] For getDeclFromExpr in CIndex.cpp, associate the decl of

a DeclRefExpr, MemberExpr, etc. with a CastExpr if it is ImplicitCast,
since the implicit cast is the one that is invisible in source code.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@139547 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Argyrios Kyrtzidis 2011-09-12 22:17:26 +00:00
Родитель 544055fa46
Коммит c2954616fb
8 изменённых файлов: 28 добавлений и 23 удалений

Просмотреть файл

@ -38,10 +38,10 @@ enum Color g(int i, ...) {
// CHECK: Punctuation: "*" [4:4 - 4:5] VarDecl=t_ptr:4:6 (Definition)
// CHECK: Identifier: "t_ptr" [4:6 - 4:11] VarDecl=t_ptr:4:6 (Definition)
// CHECK: Punctuation: "=" [4:12 - 4:13] VarDecl=t_ptr:4:6 (Definition)
// CHECK: Punctuation: "(" [4:14 - 4:15] UnexposedExpr=ptr:3:14
// CHECK: Punctuation: "(" [4:14 - 4:15] UnexposedExpr=
// CHECK: Identifier: "T" [4:15 - 4:16] TypeRef=T:1:13
// CHECK: Punctuation: "*" [4:17 - 4:18] UnexposedExpr=ptr:3:14
// CHECK: Punctuation: ")" [4:18 - 4:19] UnexposedExpr=ptr:3:14
// CHECK: Punctuation: "*" [4:17 - 4:18] UnexposedExpr=
// CHECK: Punctuation: ")" [4:18 - 4:19] UnexposedExpr=
// CHECK: Identifier: "ptr" [4:19 - 4:22] DeclRefExpr=ptr:3:14
// CHECK: Punctuation: ";" [4:22 - 4:23] UnexposedStmt=
// CHECK: Punctuation: "(" [5:3 - 5:4] UnexposedExpr=

Просмотреть файл

@ -299,9 +299,9 @@ static Rdar8595462_A * Rdar8595462_staticVar;
// CHECK: Punctuation: ")" [43:18 - 43:19] ParmDecl=x:43:19 (Definition)
// CHECK: Identifier: "x" [43:19 - 43:20] ParmDecl=x:43:19 (Definition)
// CHECK: Punctuation: "{" [44:1 - 44:2] UnexposedStmt=
// CHECK: Punctuation: "(" [45:3 - 45:4] UnexposedExpr=x:43:19
// CHECK: Keyword: "void" [45:4 - 45:8] UnexposedExpr=x:43:19
// CHECK: Punctuation: ")" [45:8 - 45:9] UnexposedExpr=x:43:19
// CHECK: Punctuation: "(" [45:3 - 45:4] UnexposedExpr=
// CHECK: Keyword: "void" [45:4 - 45:8] UnexposedExpr=
// CHECK: Punctuation: ")" [45:8 - 45:9] UnexposedExpr=
// CHECK: Identifier: "x" [45:10 - 45:11] DeclRefExpr=x:43:19
// CHECK: Punctuation: ";" [45:11 - 45:12] UnexposedStmt=
// CHECK: Punctuation: "}" [46:1 - 46:2] UnexposedStmt=
@ -442,9 +442,9 @@ static Rdar8595462_A * Rdar8595462_staticVar;
// CHECK: Punctuation: "(" [87:7 - 87:8] FunctionDecl=f:87:6 (Definition)
// CHECK: Punctuation: ")" [87:8 - 87:9] FunctionDecl=f:87:6 (Definition)
// CHECK: Punctuation: "{" [87:10 - 87:11] UnexposedStmt=
// CHECK: Punctuation: "(" [88:3 - 88:4] UnexposedExpr=Proto:85:1
// CHECK: Keyword: "void" [88:4 - 88:8] UnexposedExpr=Proto:85:1
// CHECK: Punctuation: ")" [88:8 - 88:9] UnexposedExpr=Proto:85:1
// CHECK: Punctuation: "(" [88:3 - 88:4] UnexposedExpr=
// CHECK: Keyword: "void" [88:4 - 88:8] UnexposedExpr=
// CHECK: Punctuation: ")" [88:8 - 88:9] UnexposedExpr=
// CHECK: Punctuation: "@" [88:9 - 88:10] UnexposedExpr=Proto:85:1
// CHECK: Keyword: "protocol" [88:10 - 88:18] UnexposedExpr=Proto:85:1
// CHECK: Punctuation: "(" [88:18 - 88:19] UnexposedExpr=Proto:85:1

Просмотреть файл

@ -24,7 +24,7 @@ void test() {
// CHECK: blocks.c:9:28: UnexposedStmt= Extent=[9:28 - 9:58]
// CHECK: blocks.c:9:30: UnexposedStmt= Extent=[9:30 - 9:55]
// CHECK: blocks.c:9:37: UnexposedExpr= Extent=[9:37 - 9:55]
// CHECK: blocks.c:9:37: UnexposedExpr=x:4:19 Extent=[9:37 - 9:51]
// CHECK: blocks.c:9:37: UnexposedExpr= Extent=[9:37 - 9:51]
// CHECK: blocks.c:9:38: TypeRef=int_t:3:13 Extent=[9:38 - 9:43]
// CHECK: blocks.c:9:50: MemberRefExpr=x:4:19 SingleRefName=[9:50 - 9:51] RefName=[9:50 - 9:51] Extent=[9:45 - 9:51]
// CHECK: blocks.c:9:45: DeclRefExpr=foo:9:23 Extent=[9:45 - 9:48]

Просмотреть файл

@ -137,7 +137,7 @@ struct X0 {};
// CHECK: c-index-api-loadTU-test.m:54:3: UnexposedExpr=main:46:5 Extent=[54:3 - 54:7]
// CHECK: c-index-api-loadTU-test.m:54:3: DeclRefExpr=main:46:5 Extent=[54:3 - 54:7]
// CHECK: c-index-api-loadTU-test.m:54:8: DeclRefExpr=someEnum:43:3 Extent=[54:8 - 54:16]
// CHECK: c-index-api-loadTU-test.m:54:18: UnexposedExpr=bee:47:8 Extent=[54:18 - 54:36]
// CHECK: c-index-api-loadTU-test.m:54:18: UnexposedExpr= Extent=[54:18 - 54:36]
// CHECK: c-index-api-loadTU-test.m:54:33: DeclRefExpr=bee:47:8 Extent=[54:33 - 54:36]
// CHECK: c-index-api-loadTU-test.m:62:12: ObjCInterfaceDecl=TestAttributes:62:12 Extent=[62:1 - 67:5]
// CHECK: c-index-api-loadTU-test.m:63:19: ObjCIvarDecl=anOutlet:63:19 (Definition) Extent=[58:18 - 63:27]

Просмотреть файл

@ -158,7 +158,7 @@ void f() {
// CHECK: [52:7 - 52:8] CallExpr=main:44:5
// CHECK: [52:8 - 52:16] DeclRefExpr=someEnum:41:3
// CHECK: [52:16 - 52:18] CallExpr=main:44:5
// CHECK: [52:18 - 52:33] UnexposedExpr=bee:45:8
// CHECK: [52:18 - 52:33] UnexposedExpr=
// CHECK: [52:33 - 52:36] DeclRefExpr=bee:45:8
// CHECK: [52:36 - 52:37] CallExpr=main:44:5
// CHECK: [52:37 - 53:2] UnexposedStmt=

Просмотреть файл

@ -202,8 +202,9 @@ void casts(int *ip) {
// CHECK: load-stmts.cpp:80:21: DeclRefExpr=j:79:44 Extent=[80:21 - 80:22]
// CHECK: load-stmts.cpp:82:9: TypeRef=Integer:81:15 Extent=[82:9 - 82:16]
// CHECK: load-stmts.cpp:82:17: DeclRefExpr=i:79:37 Extent=[82:17 - 82:18]
// CHECK: load-stmts.cpp:83:3: UnexposedExpr=i:79:37 Extent=[83:3 - 83:13]
// CHECK: load-stmts.cpp:83:3: UnexposedExpr= Extent=[83:3 - 83:13]
// CHECK: load-stmts.cpp:83:4: TypeRef=Integer:81:15 Extent=[83:4 - 83:11]
// CHECK: load-stmts.cpp:83:12: UnexposedExpr=i:79:37 Extent=[83:12 - 83:13]
// CHECK: load-stmts.cpp:83:12: DeclRefExpr=i:79:37 Extent=[83:12 - 83:13]
// CHECK: load-stmts.cpp:84:3: UnexposedExpr= Extent=[84:3 - 84:12]
// CHECK: load-stmts.cpp:84:3: TypeRef=Integer:81:15 Extent=[84:3 - 84:10]
@ -225,5 +226,6 @@ void casts(int *ip) {
// CHECK: load-stmts.cpp:108:2: LabelStmt=start_over Extent=[108:2 - 109:28]
// CHECK: load-stmts.cpp:109:17: LabelRef=start_over:108:2 Extent=[109:17 - 109:27]
// CHECK: load-stmts.cpp:113:10: LabelRef=start_over:108:2 Extent=[113:10 - 113:20]
// CHECK: load-stmts.cpp:117:9: UnexposedExpr=ip:116:17 Extent=[117:9 - 117:38]
// CHECK: load-stmts.cpp:117:35: UnexposedExpr=ip:116:17 Extent=[117:35 - 117:37]
// CHECK: load-stmts.cpp:117:35: DeclRefExpr=ip:116:17 Extent=[117:35 - 117:37]

Просмотреть файл

@ -952,16 +952,16 @@ AttributeList::Kind AttributeList::getKind(const IdentifierInfo * Name) {
// CHECK-tokens: Keyword: "return" [105:3 - 105:9] UnexposedStmt=
// FIXME: Missing "llvm" namespace reference below
// CHECK-tokens: Identifier: "llvm" [105:10 - 105:14] NamespaceRef=llvm:82:11
// CHECK-tokens: Punctuation: "::" [105:14 - 105:16] UnexposedExpr=StringSwitch:87:12
// CHECK-tokens: Punctuation: "::" [105:14 - 105:16] UnexposedExpr=
// CHECK-tokens: Identifier: "StringSwitch" [105:16 - 105:28] TemplateRef=StringSwitch:83:47
// CHECK-tokens: Punctuation: "<" [105:29 - 105:30] UnexposedExpr=StringSwitch:87:12
// CHECK-tokens: Punctuation: "<" [105:29 - 105:30] UnexposedExpr=
// CHECK-tokens: Identifier: "AttributeList" [105:31 - 105:44] TypeRef=class clang::AttributeList:12:9
// CHECK-tokens: Punctuation: "::" [105:44 - 105:46] UnexposedExpr=StringSwitch:87:12
// CHECK-tokens: Punctuation: "::" [105:44 - 105:46] UnexposedExpr=
// CHECK-tokens: Identifier: "Kind" [105:46 - 105:50] TypeRef=enum clang::AttributeList::Kind:13:10
// CHECK-tokens: Punctuation: ">" [105:51 - 105:52] CallExpr=StringSwitch:87:12
// CHECK-tokens: Punctuation: "(" [105:53 - 105:54] CallExpr=StringSwitch:87:12
// CHECK-tokens: Identifier: "AttrName" [105:54 - 105:62] DeclRefExpr=AttrName:101:19
// CHECK-tokens: Punctuation: ")" [105:62 - 105:63] UnexposedExpr=StringSwitch:87:12
// CHECK-tokens: Punctuation: ")" [105:62 - 105:63] UnexposedExpr=
// CHECK-tokens: Punctuation: "." [106:5 - 106:6] MemberRefExpr=Case:88:42
// CHECK-tokens: Identifier: "Case" [106:6 - 106:10] MemberRefExpr=Case:88:42
// CHECK-tokens: Punctuation: "(" [106:10 - 106:11] CallExpr=Case:88:42
@ -1707,7 +1707,7 @@ AttributeList::Kind AttributeList::getKind(const IdentifierInfo * Name) {
// CHECK: 54:11: DeclRefExpr=memcmp:7:7 Extent=[54:11 - 54:17]
// CHECK: 54:18: UnexposedExpr=Data:43:15 Extent=[54:18 - 54:22]
// CHECK: 54:18: MemberRefExpr=Data:43:15 Extent=[54:18 - 54:22]
// CHECK: 54:24: UnexposedExpr=Data:43:15 Extent=[54:24 - 54:35]
// CHECK: 54:31: UnexposedExpr=Data:43:15 Extent=[54:24 - 54:35]
// CHECK: 54:31: MemberRefExpr=Data:43:15 SingleRefName=[54:31 - 54:35] RefName=[54:31 - 54:35] Extent=[54:24 - 54:35]
// CHECK: 54:24: DeclRefExpr=Prefix:52:29 Extent=[54:24 - 54:30]
// CHECK: 54:44: MemberRefExpr=Length:44:10 SingleRefName=[54:44 - 54:50] RefName=[54:44 - 54:50] Extent=[54:37 - 54:50]
@ -1734,7 +1734,7 @@ AttributeList::Kind AttributeList::getKind(const IdentifierInfo * Name) {
// CHECK: 58:14: MemberRefExpr=end:50:12 Extent=[58:14 - 58:17]
// CHECK: 58:29: MemberRefExpr=Length:44:10 SingleRefName=[58:29 - 58:35] RefName=[58:29 - 58:35] Extent=[58:22 - 58:35]
// CHECK: 58:22: DeclRefExpr=Suffix:56:27 Extent=[58:22 - 58:28]
// CHECK: 58:37: UnexposedExpr=Data:43:15 Extent=[58:37 - 58:48]
// CHECK: 58:44: UnexposedExpr=Data:43:15 Extent=[58:37 - 58:48]
// CHECK: 58:44: MemberRefExpr=Data:43:15 SingleRefName=[58:44 - 58:48] RefName=[58:44 - 58:48] Extent=[58:37 - 58:48]
// CHECK: 58:37: DeclRefExpr=Suffix:56:27 Extent=[58:37 - 58:43]
// CHECK: 58:57: MemberRefExpr=Length:44:10 SingleRefName=[58:57 - 58:63] RefName=[58:57 - 58:63] Extent=[58:50 - 58:63]
@ -1790,7 +1790,7 @@ AttributeList::Kind AttributeList::getKind(const IdentifierInfo * Name) {
// CHECK: 74:5: UnexposedStmt= Extent=[74:5 - 74:61]
// CHECK: 74:17: VarDecl=p:74:17 (Definition) Extent=[74:5 - 74:60]
// CHECK: 74:21: UnexposedExpr= Extent=[74:21 - 74:60]
// CHECK: 74:21: UnexposedExpr=second:4:55 Extent=[74:21 - 74:56]
// CHECK: 74:50: UnexposedExpr=second:4:55 Extent=[74:21 - 74:56]
// CHECK: 74:50: MemberRefExpr=second:4:55 SingleRefName=[74:50 - 74:56] RefName=[74:50 - 74:56] Extent=[74:21 - 74:56]
// CHECK: 74:21: UnexposedExpr= Extent=[74:21 - 74:48]
// CHECK: 74:22: UnexposedExpr= Extent=[74:22 - 74:47]
@ -2079,7 +2079,7 @@ AttributeList::Kind AttributeList::getKind(const IdentifierInfo * Name) {
// CHECK: 107:6: MemberRefExpr=Case:88:42 SingleRefName=[107:6 - 107:10] RefName=[107:6 - 107:10] Extent=[105:10 - 107:10]
// CHECK: 105:10: CallExpr=Case:88:42 Extent=[105:10 - 106:27]
// CHECK: 106:6: MemberRefExpr=Case:88:42 SingleRefName=[106:6 - 106:10] RefName=[106:6 - 106:10] Extent=[105:10 - 106:10]
// CHECK: 105:10: UnexposedExpr=StringSwitch:87:12 Extent=[105:10 - 105:63]
// CHECK: 105:10: UnexposedExpr= Extent=[105:10 - 105:63]
// CHECK: 105:16: TemplateRef=StringSwitch:83:47 Extent=[105:16 - 105:28]
// CHECK: 105:10: CallExpr=StringSwitch:87:12 Extent=[105:10 - 105:62]
// CHECK: 105:54: CallExpr=StringRef:38:7 Extent=[105:54 - 105:62]

Просмотреть файл

@ -2963,7 +2963,7 @@ unsigned clang_isFileMultipleIncludeGuarded(CXTranslationUnit tu, CXFile file) {
//===----------------------------------------------------------------------===//
static Decl *getDeclFromExpr(Stmt *E) {
if (CastExpr *CE = dyn_cast<CastExpr>(E))
if (ImplicitCastExpr *CE = dyn_cast<ImplicitCastExpr>(E))
return getDeclFromExpr(CE->getSubExpr());
if (DeclRefExpr *RefExpr = dyn_cast<DeclRefExpr>(E))
@ -2999,6 +2999,9 @@ static Decl *getDeclFromExpr(Stmt *E) {
}
static SourceLocation getLocationFromExpr(Expr *E) {
if (ImplicitCastExpr *CE = dyn_cast<ImplicitCastExpr>(E))
return getLocationFromExpr(CE->getSubExpr());
if (ObjCMessageExpr *Msg = dyn_cast<ObjCMessageExpr>(E))
return /*FIXME:*/Msg->getLeftLoc();
if (DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(E))