From: Argyrios Kyrtzidis Date: Wed, 22 Feb 2012 02:10:41 +0000 (+0000) Subject: [libclang] Index the field references of a designated initializer, rdar://10906206 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=e0d92a43073d9a8eec220042651ccad9b0f71cc5;p=clang [libclang] Index the field references of a designated initializer, rdar://10906206 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@151118 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/test/Index/index-refs.cpp b/test/Index/index-refs.cpp index 56afa08ec8..77e2af71f8 100644 --- a/test/Index/index-refs.cpp +++ b/test/Index/index-refs.cpp @@ -61,6 +61,14 @@ typedef int some_arr[array_size]; const int default_param = 3; void foo4(int p = default_param); +struct S2 { + int x,y; +}; + +void foo5() { + struct S2 s = { .y = 1, .x = 4}; +} + // RUN: c-index-test -index-file %s | FileCheck %s // CHECK: [indexDeclaration]: kind: namespace | name: NS // CHECK-NEXT: [indexDeclaration]: kind: variable | name: gx @@ -108,3 +116,6 @@ void foo4(int p = default_param); // CHECK: [indexEntityReference]: kind: variable | name: array_size | {{.*}} | loc: 59:22 // CHECK: [indexEntityReference]: kind: variable | name: default_param | {{.*}} | loc: 62:19 // CHECK-NOT: [indexEntityReference]: kind: variable | name: default_param | {{.*}} | loc: 62:19 + +// CHECK: [indexEntityReference]: kind: field | name: y | {{.*}} | loc: 69:20 +// CHECK-NEXT: [indexEntityReference]: kind: field | name: x | {{.*}} | loc: 69:28 diff --git a/tools/libclang/IndexBody.cpp b/tools/libclang/IndexBody.cpp index 9330194cee..cce0bf705a 100644 --- a/tools/libclang/IndexBody.cpp +++ b/tools/libclang/IndexBody.cpp @@ -51,6 +51,17 @@ public: return true; } + bool VisitDesignatedInitExpr(DesignatedInitExpr *E) { + for (DesignatedInitExpr::reverse_designators_iterator + D = E->designators_rbegin(), DEnd = E->designators_rend(); + D != DEnd; ++D) { + if (D->isFieldDesignator()) + IndexCtx.handleReference(D->getField(), D->getFieldLoc(), + Parent, ParentDC, E); + } + return true; + } + bool VisitObjCIvarRefExpr(ObjCIvarRefExpr *E) { IndexCtx.handleReference(E->getDecl(), E->getLocation(), Parent, ParentDC, E);