[cfe-commits] r113560 - in /cfe/trunk: test/Index/load-exprs.c tools/libclang/CIndex.cpp
Douglas Gregor
dgregor at apple.com
Thu Sep 9 16:28:24 PDT 2010
Author: dgregor
Date: Thu Sep 9 18:28:23 2010
New Revision: 113560
URL: http://llvm.org/viewvc/llvm-project?rev=113560&view=rev
Log:
Add libclang visitation for C99 designated initializers.
Modified:
cfe/trunk/test/Index/load-exprs.c
cfe/trunk/tools/libclang/CIndex.cpp
Modified: cfe/trunk/test/Index/load-exprs.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Index/load-exprs.c?rev=113560&r1=113559&r2=113560&view=diff
==============================================================================
--- cfe/trunk/test/Index/load-exprs.c (original)
+++ cfe/trunk/test/Index/load-exprs.c Thu Sep 9 18:28:23 2010
@@ -64,6 +64,16 @@
// CHECK: load-exprs.c:17:10: DeclRefExpr= Extent=[17:10 - 17:11]
// CHECK: load-exprs.c:20:10: DeclRefExpr=y:11:15 Extent=[20:10 - 20:11]
// CHECK: load-exprs.c:29:6: FunctionDecl=test_members:29:6 (Definition)
+// CHECK: load-exprs.c:30:12: VarDecl=y0:30:12 (Definition) Extent=[30:10 - 30:77]
+// CHECK: load-exprs.c:30:10: TypeRef=struct Y:23:8 Extent=[30:10 - 30:11]
+// CHECK: load-exprs.c:30:20: MemberRef=array:24:12 Extent=[30:20 - 30:25]
+// CHECK: load-exprs.c:30:26: DeclRefExpr=StartIndex:27:8 Extent=[30:26 - 30:36]
+// CHECK: load-exprs.c:30:38: MemberRef=b:2:19 Extent=[30:38 - 30:39]
+// CHECK: load-exprs.c:30:42: DeclRefExpr=bval:29:33 Extent=[30:42 - 30:46]
+// CHECK: load-exprs.c:30:49: MemberRef=array:24:12 Extent=[30:49 - 30:54]
+// CHECK: load-exprs.c:30:55: DeclRefExpr=StartIndex:27:8 Extent=[30:55 - 30:65]
+// CHECK: load-exprs.c:30:67: MemberRef=a:2:16 Extent=[30:67 - 30:68]
+// CHECK: load-exprs.c:30:71: DeclRefExpr=aval:29:23 Extent=[30:71 - 30:75]
// CHECK: load-exprs.c:31:29: TypeRef=struct Y:23:8 Extent=[31:29 - 31:30]
// CHECK: load-exprs.c:31:32: MemberRef=array:24:12 Extent=[31:32 - 31:37]
// CHECK: load-exprs.c:31:38: DeclRefExpr=StartIndex:27:8 Extent=[31:38 - 31:48]
Modified: cfe/trunk/tools/libclang/CIndex.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/libclang/CIndex.cpp?rev=113560&r1=113559&r2=113560&view=diff
==============================================================================
--- cfe/trunk/tools/libclang/CIndex.cpp (original)
+++ cfe/trunk/tools/libclang/CIndex.cpp Thu Sep 9 18:28:23 2010
@@ -380,8 +380,8 @@
// FIXME: AddrLabelExpr (once we have cursors for labels)
bool VisitTypesCompatibleExpr(TypesCompatibleExpr *E);
bool VisitVAArgExpr(VAArgExpr *E);
- // FIXME: InitListExpr (for the designators)
- // FIXME: DesignatedInitExpr
+ bool VisitInitListExpr(InitListExpr *E);
+ bool VisitDesignatedInitExpr(DesignatedInitExpr *E);
bool VisitCXXTypeidExpr(CXXTypeidExpr *E);
bool VisitCXXUuidofExpr(CXXUuidofExpr *E);
bool VisitCXXDefaultArgExpr(CXXDefaultArgExpr *E) { return false; }
@@ -1652,6 +1652,42 @@
return Visit(MakeCXCursor(E->getSubExpr(), StmtParent, TU));
}
+bool CursorVisitor::VisitInitListExpr(InitListExpr *E) {
+ // We care about the syntactic form of the initializer list, only.
+ return VisitExpr(E->getSyntacticForm());
+}
+
+bool CursorVisitor::VisitDesignatedInitExpr(DesignatedInitExpr *E) {
+ // Visit the designators.
+ typedef DesignatedInitExpr::Designator Designator;
+ for (DesignatedInitExpr::designators_iterator D = E->designators_begin(),
+ DEnd = E->designators_end();
+ D != DEnd; ++D) {
+ if (D->isFieldDesignator()) {
+ if (FieldDecl *Field = D->getField())
+ if (Visit(MakeCursorMemberRef(Field, D->getFieldLoc(), TU)))
+ return true;
+
+ continue;
+ }
+
+ if (D->isArrayDesignator()) {
+ if (Visit(MakeCXCursor(E->getArrayIndex(*D), StmtParent, TU)))
+ return true;
+
+ continue;
+ }
+
+ assert(D->isArrayRangeDesignator() && "Unknown designator kind");
+ if (Visit(MakeCXCursor(E->getArrayRangeStart(*D), StmtParent, TU)) ||
+ Visit(MakeCXCursor(E->getArrayRangeEnd(*D), StmtParent, TU)))
+ return true;
+ }
+
+ // Visit the initializer value itself.
+ return Visit(MakeCXCursor(E->getInit(), StmtParent, TU));
+}
+
bool CursorVisitor::VisitCXXTypeidExpr(CXXTypeidExpr *E) {
if (E->isTypeOperand()) {
if (TypeSourceInfo *TSInfo = E->getTypeOperandSourceInfo())
More information about the cfe-commits
mailing list