[cfe-commits] r96571 - in /cfe/trunk: test/Index/c-index-api-loadTU-test.m tools/CIndex/CIndex.cpp

Ted Kremenek kremenek at apple.com
Wed Feb 17 21:46:35 PST 2010


Author: kremenek
Date: Wed Feb 17 23:46:33 2010
New Revision: 96571

URL: http://llvm.org/viewvc/llvm-project?rev=96571&view=rev
Log:
Add basic cursor traversal for attributes.  We currently don't have source
ranges for Attr objects, so lookup by cursor location currently doesn't work.

Modified:
    cfe/trunk/test/Index/c-index-api-loadTU-test.m
    cfe/trunk/tools/CIndex/CIndex.cpp

Modified: cfe/trunk/test/Index/c-index-api-loadTU-test.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Index/c-index-api-loadTU-test.m?rev=96571&r1=96570&r2=96571&view=diff

==============================================================================
--- cfe/trunk/test/Index/c-index-api-loadTU-test.m (original)
+++ cfe/trunk/test/Index/c-index-api-loadTU-test.m Wed Feb 17 23:46:33 2010
@@ -3,6 +3,7 @@
 
 @interface Foo 
 {
+  __attribute__((iboutlet)) id myoutlet;
 }
 
 - foo;
@@ -53,79 +54,67 @@
   main(someEnum, (const char **)bee);
 }
 
-// CHECK: <invalid loc>:0:0: TypedefDecl=__int128_t:0:0 (Definition)
-// CHECK: <invalid loc>:0:0: TypedefDecl=__uint128_t:0:0 (Definition)
-// CHECK: <invalid loc>:0:0: TypedefDecl=SEL:0:0 (Definition)
-// CHECK: <invalid loc>:0:0: TypeRef=SEL:0:0
-// CHECK: <invalid loc>:0:0: TypedefDecl=id:0:0 (Definition)
-// CHECK: <invalid loc>:0:0: TypedefDecl=Class:0:0 (Definition)
-// CHECK: <invalid loc>:87:16: StructDecl=__va_list_tag:87:16 (Definition)
-// CHECK: <invalid loc>:87:42: FieldDecl=gp_offset:87:42 (Definition)
-// CHECK: <invalid loc>:87:63: FieldDecl=fp_offset:87:63 (Definition)
-// CHECK: <invalid loc>:87:81: FieldDecl=overflow_arg_area:87:81 (Definition)
-// CHECK: <invalid loc>:87:107: FieldDecl=reg_save_area:87:107 (Definition)
-// CHECK: <invalid loc>:87:123: TypedefDecl=__va_list_tag:87:123 (Definition)
-// CHECK: <invalid loc>:87:16: TypeRef=struct __va_list_tag:87:16
-// CHECK: <invalid loc>:87:159: TypedefDecl=__builtin_va_list:87:159 (Definition)
-// CHECK: <invalid loc>:87:145: TypeRef=__va_list_tag:87:123
-// CHECK: <invalid loc>:87:177: UnexposedExpr=
-// CHECK: c-index-api-loadTU-test.m:4:12: ObjCInterfaceDecl=Foo:4:12 Extent=[4:1 - 11:5]
-// CHECK: c-index-api-loadTU-test.m:8:1: ObjCInstanceMethodDecl=foo:8:1 Extent=[8:1 - 8:7]
-// CHECK: c-index-api-loadTU-test.m:9:1: ObjCClassMethodDecl=fooC:9:1 Extent=[9:1 - 9:8]
-// CHECK: c-index-api-loadTU-test.m:13:12: ObjCInterfaceDecl=Bar:13:12 Extent=[13:1 - 17:5]
-// CHECK: c-index-api-loadTU-test.m:13:18: ObjCSuperClassRef=Foo:4:12 Extent=[13:18 - 13:21]
-// CHECK: c-index-api-loadTU-test.m:19:12: ObjCCategoryDecl=FooCat:19:12 Extent=[19:1 - 22:5]
-// CHECK: c-index-api-loadTU-test.m:19:12: ObjCClassRef=Foo:4:12 Extent=[19:12 - 19:15]
-// CHECK: c-index-api-loadTU-test.m:20:1: ObjCInstanceMethodDecl=catMethodWithFloat::20:1 Extent=[20:1 - 20:41]
-// CHECK: c-index-api-loadTU-test.m:20:36: ParmDecl=fArg:20:36 (Definition) Extent=[20:29 - 20:40]
-// CHECK: c-index-api-loadTU-test.m:21:1: ObjCInstanceMethodDecl=floatMethod:21:1 Extent=[21:1 - 21:23]
-// CHECK: c-index-api-loadTU-test.m:24:1: ObjCProtocolDecl=Proto:24:1 (Definition) Extent=[24:1 - 26:5]
-// CHECK: c-index-api-loadTU-test.m:25:1: ObjCInstanceMethodDecl=pMethod:25:1 Extent=[25:1 - 25:11]
-// CHECK: c-index-api-loadTU-test.m:28:1: ObjCProtocolDecl=SubP:28:1 (Definition) Extent=[28:1 - 30:5]
-// CHECK: c-index-api-loadTU-test.m:28:17: ObjCProtocolRef=Proto:24:1 Extent=[28:17 - 28:22]
-// CHECK: c-index-api-loadTU-test.m:29:1: ObjCInstanceMethodDecl=spMethod:29:1 Extent=[29:1 - 29:12]
-// CHECK: c-index-api-loadTU-test.m:32:12: ObjCInterfaceDecl=Baz:32:12 Extent=[32:1 - 39:5]
-// CHECK: c-index-api-loadTU-test.m:32:18: ObjCSuperClassRef=Bar:13:12 Extent=[32:18 - 32:21]
-// CHECK: c-index-api-loadTU-test.m:32:23: ObjCProtocolRef=SubP:28:1 Extent=[32:23 - 32:27]
-// CHECK: c-index-api-loadTU-test.m:34:9: ObjCIvarDecl=_anIVar:34:9 (Definition) Extent=[34:9 - 34:16]
-// CHECK: c-index-api-loadTU-test.m:37:1: ObjCInstanceMethodDecl=bazMethod:37:1 Extent=[37:1 - 37:21]
-// CHECK: c-index-api-loadTU-test.m:41:1: EnumDecl=:41:1 (Definition) Extent=[41:1 - 43:2]
-// CHECK: c-index-api-loadTU-test.m:42:3: EnumConstantDecl=someEnum:42:3 (Definition) Extent=[42:3 - 42:11]
-// CHECK: c-index-api-loadTU-test.m:45:5: FunctionDecl=main:45:5 (Definition) Extent=[45:5 - 54:2]
-// CHECK: c-index-api-loadTU-test.m:45:15: ParmDecl=argc:45:15 (Definition) Extent=[45:11 - 45:19]
-// CHECK: c-index-api-loadTU-test.m:45:34: ParmDecl=argv:45:34 (Definition) Extent=[45:27 - 45:38]
-// CHECK: c-index-api-loadTU-test.m:45:5: UnexposedStmt= Extent=[45:42 - 54:2]
-// CHECK: c-index-api-loadTU-test.m:45:5: UnexposedStmt= Extent=[46:2 - 46:12]
-// CHECK: c-index-api-loadTU-test.m:46:8: VarDecl=bee:46:8 (Definition) Extent=[46:2 - 46:11]
-// CHECK: c-index-api-loadTU-test.m:46:2: ObjCClassRef=Baz:32:12 Extent=[46:2 - 46:5]
-// CHECK: c-index-api-loadTU-test.m:46:8: UnexposedStmt= Extent=[47:2 - 47:19]
-// CHECK: c-index-api-loadTU-test.m:47:5: VarDecl=a:47:5 (Definition) Extent=[47:2 - 47:18]
-// CHECK: c-index-api-loadTU-test.m:47:2: TypeRef=id:0:0 Extent=[47:2 - 47:4]
-// CHECK: c-index-api-loadTU-test.m:47:9: ObjCMessageExpr=foo:8:1 Extent=[47:9 - 47:18]
-// CHECK: c-index-api-loadTU-test.m:47:10: DeclRefExpr=bee:46:8 Extent=[47:10 - 47:13]
-// CHECK: c-index-api-loadTU-test.m:47:5: UnexposedStmt= Extent=[48:2 - 48:27]
-// CHECK: c-index-api-loadTU-test.m:48:12: VarDecl=c:48:12 (Definition) Extent=[48:2 - 48:26]
+// CHECK: c-index-api-loadTU-test.m:4:12: ObjCInterfaceDecl=Foo:4:12 Extent=[4:1 - 12:5]
+// CHECK: c-index-api-loadTU-test.m:6:32: attribute(iboutlet)= Extent=[6:32 - 6:40]
+// CHECK: c-index-api-loadTU-test.m:6:32: ObjCIvarDecl=myoutlet:6:32 (Definition) Extent=[6:32 - 6:40]
+// CHECK: c-index-api-loadTU-test.m:6:29: TypeRef=id:0:0 Extent=[6:29 - 6:31]
+// CHECK: c-index-api-loadTU-test.m:9:1: ObjCInstanceMethodDecl=foo:9:1 Extent=[9:1 - 9:7]
+// CHECK: c-index-api-loadTU-test.m:10:1: ObjCClassMethodDecl=fooC:10:1 Extent=[10:1 - 10:8]
+// CHECK: c-index-api-loadTU-test.m:14:12: ObjCInterfaceDecl=Bar:14:12 Extent=[14:1 - 18:5]
+// CHECK: c-index-api-loadTU-test.m:14:18: ObjCSuperClassRef=Foo:4:12 Extent=[14:18 - 14:21]
+// CHECK: c-index-api-loadTU-test.m:20:12: ObjCCategoryDecl=FooCat:20:12 Extent=[20:1 - 23:5]
+// CHECK: c-index-api-loadTU-test.m:20:12: ObjCClassRef=Foo:4:12 Extent=[20:12 - 20:15]
+// CHECK: c-index-api-loadTU-test.m:21:1: ObjCInstanceMethodDecl=catMethodWithFloat::21:1 Extent=[21:1 - 21:41]
+// CHECK: c-index-api-loadTU-test.m:21:36: ParmDecl=fArg:21:36 (Definition) Extent=[21:29 - 21:40]
+// CHECK: c-index-api-loadTU-test.m:22:1: ObjCInstanceMethodDecl=floatMethod:22:1 Extent=[22:1 - 22:23]
+// CHECK: c-index-api-loadTU-test.m:25:1: ObjCProtocolDecl=Proto:25:1 (Definition) Extent=[25:1 - 27:5]
+// CHECK: c-index-api-loadTU-test.m:26:1: ObjCInstanceMethodDecl=pMethod:26:1 Extent=[26:1 - 26:11]
+// CHECK: c-index-api-loadTU-test.m:29:1: ObjCProtocolDecl=SubP:29:1 (Definition) Extent=[29:1 - 31:5]
+// CHECK: c-index-api-loadTU-test.m:29:17: ObjCProtocolRef=Proto:25:1 Extent=[29:17 - 29:22]
+// CHECK: c-index-api-loadTU-test.m:30:1: ObjCInstanceMethodDecl=spMethod:30:1 Extent=[30:1 - 30:12]
+// CHECK: c-index-api-loadTU-test.m:33:12: ObjCInterfaceDecl=Baz:33:12 Extent=[33:1 - 40:5]
+// CHECK: c-index-api-loadTU-test.m:33:18: ObjCSuperClassRef=Bar:14:12 Extent=[33:18 - 33:21]
+// CHECK: c-index-api-loadTU-test.m:33:23: ObjCProtocolRef=SubP:29:1 Extent=[33:23 - 33:27]
+// CHECK: c-index-api-loadTU-test.m:35:9: ObjCIvarDecl=_anIVar:35:9 (Definition) Extent=[35:9 - 35:16]
+// CHECK: c-index-api-loadTU-test.m:38:1: ObjCInstanceMethodDecl=bazMethod:38:1 Extent=[38:1 - 38:21]
+// CHECK: c-index-api-loadTU-test.m:42:1: EnumDecl=:42:1 (Definition) Extent=[42:1 - 44:2]
+// CHECK: c-index-api-loadTU-test.m:43:3: EnumConstantDecl=someEnum:43:3 (Definition) Extent=[43:3 - 43:11]
+// CHECK: c-index-api-loadTU-test.m:46:5: FunctionDecl=main:46:5 (Definition) Extent=[46:5 - 55:2]
+// CHECK: c-index-api-loadTU-test.m:46:15: ParmDecl=argc:46:15 (Definition) Extent=[46:11 - 46:19]
+// CHECK: c-index-api-loadTU-test.m:46:34: ParmDecl=argv:46:34 (Definition) Extent=[46:27 - 46:38]
+// CHECK: c-index-api-loadTU-test.m:46:5: UnexposedStmt= Extent=[46:42 - 55:2]
+// CHECK: c-index-api-loadTU-test.m:46:5: UnexposedStmt= Extent=[47:2 - 47:12]
+// CHECK: c-index-api-loadTU-test.m:47:8: VarDecl=bee:47:8 (Definition) Extent=[47:2 - 47:11]
+// CHECK: c-index-api-loadTU-test.m:47:2: ObjCClassRef=Baz:33:12 Extent=[47:2 - 47:5]
+// CHECK: c-index-api-loadTU-test.m:47:8: UnexposedStmt= Extent=[48:2 - 48:19]
+// CHECK: c-index-api-loadTU-test.m:48:5: VarDecl=a:48:5 (Definition) Extent=[48:2 - 48:18]
 // CHECK: c-index-api-loadTU-test.m:48:2: TypeRef=id:0:0 Extent=[48:2 - 48:4]
-// CHECK: c-index-api-loadTU-test.m:48:6: ObjCProtocolRef=SubP:28:1 Extent=[48:6 - 48:10]
-// CHECK: c-index-api-loadTU-test.m:48:16: UnexposedExpr=fooC:9:1 Extent=[48:16 - 48:26]
-// CHECK: c-index-api-loadTU-test.m:48:16: ObjCMessageExpr=fooC:9:1 Extent=[48:16 - 48:26]
-// CHECK: c-index-api-loadTU-test.m:48:12: UnexposedStmt= Extent=[49:2 - 49:15]
-// CHECK: c-index-api-loadTU-test.m:49:13: VarDecl=d:49:13 (Definition) Extent=[49:2 - 49:14]
+// CHECK: c-index-api-loadTU-test.m:48:9: ObjCMessageExpr=foo:9:1 Extent=[48:9 - 48:18]
+// CHECK: c-index-api-loadTU-test.m:48:10: DeclRefExpr=bee:47:8 Extent=[48:10 - 48:13]
+// CHECK: c-index-api-loadTU-test.m:48:5: UnexposedStmt= Extent=[49:2 - 49:27]
+// CHECK: c-index-api-loadTU-test.m:49:12: VarDecl=c:49:12 (Definition) Extent=[49:2 - 49:26]
 // CHECK: c-index-api-loadTU-test.m:49:2: TypeRef=id:0:0 Extent=[49:2 - 49:4]
-// CHECK: c-index-api-loadTU-test.m:49:6: ObjCProtocolRef=Proto:24:1 Extent=[49:6 - 49:11]
-// CHECK: c-index-api-loadTU-test.m:50:2: UnexposedExpr= Extent=[50:2 - 50:7]
-// CHECK: c-index-api-loadTU-test.m:50:2: DeclRefExpr=d:49:13 Extent=[50:2 - 50:3]
-// CHECK: c-index-api-loadTU-test.m:50:6: UnexposedExpr=c:48:12 Extent=[50:6 - 50:7]
-// CHECK: c-index-api-loadTU-test.m:50:6: DeclRefExpr=c:48:12 Extent=[50:6 - 50:7]
-// CHECK: c-index-api-loadTU-test.m:51:2: ObjCMessageExpr=pMethod:25:1 Extent=[51:2 - 51:13]
-// CHECK: c-index-api-loadTU-test.m:51:3: DeclRefExpr=d:49:13 Extent=[51:3 - 51:4]
-// CHECK: c-index-api-loadTU-test.m:52:2: ObjCMessageExpr=catMethodWithFloat::20:1 Extent=[52:2 - 52:44]
-// CHECK: c-index-api-loadTU-test.m:52:3: DeclRefExpr=bee:46:8 Extent=[52:3 - 52:6]
-// CHECK: c-index-api-loadTU-test.m:52:26: ObjCMessageExpr=floatMethod:21:1 Extent=[52:26 - 52:43]
-// CHECK: c-index-api-loadTU-test.m:52:27: DeclRefExpr=bee:46:8 Extent=[52:27 - 52:30]
-// CHECK: c-index-api-loadTU-test.m:53:3: CallExpr=main:45:5 Extent=[53:3 - 53:37]
-// CHECK: c-index-api-loadTU-test.m:53:3: UnexposedExpr=main:45:5 Extent=[53:3 - 53:7]
-// CHECK: c-index-api-loadTU-test.m:53:3: DeclRefExpr=main:45:5 Extent=[53:3 - 53:7]
-// CHECK: c-index-api-loadTU-test.m:53:8: DeclRefExpr=someEnum:42:3 Extent=[53:8 - 53:16]
-// CHECK: c-index-api-loadTU-test.m:53:18: UnexposedExpr=bee:46:8 Extent=[53:18 - 53:36]
-// CHECK: c-index-api-loadTU-test.m:53:33: DeclRefExpr=bee:46:8 Extent=[53:33 - 53:36]
+// CHECK: c-index-api-loadTU-test.m:49:6: ObjCProtocolRef=SubP:29:1 Extent=[49:6 - 49:10]
+// CHECK: c-index-api-loadTU-test.m:49:16: UnexposedExpr=fooC:10:1 Extent=[49:16 - 49:26]
+// CHECK: c-index-api-loadTU-test.m:49:16: ObjCMessageExpr=fooC:10:1 Extent=[49:16 - 49:26]
+// CHECK: c-index-api-loadTU-test.m:49:12: UnexposedStmt= Extent=[50:2 - 50:15]
+// CHECK: c-index-api-loadTU-test.m:50:13: VarDecl=d:50:13 (Definition) Extent=[50:2 - 50:14]
+// CHECK: c-index-api-loadTU-test.m:50:2: TypeRef=id:0:0 Extent=[50:2 - 50:4]
+// CHECK: c-index-api-loadTU-test.m:50:6: ObjCProtocolRef=Proto:25:1 Extent=[50:6 - 50:11]
+// CHECK: c-index-api-loadTU-test.m:51:2: UnexposedExpr= Extent=[51:2 - 51:7]
+// CHECK: c-index-api-loadTU-test.m:51:2: DeclRefExpr=d:50:13 Extent=[51:2 - 51:3]
+// CHECK: c-index-api-loadTU-test.m:51:6: UnexposedExpr=c:49:12 Extent=[51:6 - 51:7]
+// CHECK: c-index-api-loadTU-test.m:51:6: DeclRefExpr=c:49:12 Extent=[51:6 - 51:7]
+// CHECK: c-index-api-loadTU-test.m:52:2: ObjCMessageExpr=pMethod:26:1 Extent=[52:2 - 52:13]
+// CHECK: c-index-api-loadTU-test.m:52:3: DeclRefExpr=d:50:13 Extent=[52:3 - 52:4]
+// CHECK: c-index-api-loadTU-test.m:53:2: ObjCMessageExpr=catMethodWithFloat::21:1 Extent=[53:2 - 53:44]
+// CHECK: c-index-api-loadTU-test.m:53:3: DeclRefExpr=bee:47:8 Extent=[53:3 - 53:6]
+// CHECK: c-index-api-loadTU-test.m:53:26: ObjCMessageExpr=floatMethod:22:1 Extent=[53:26 - 53:43]
+// CHECK: c-index-api-loadTU-test.m:53:27: DeclRefExpr=bee:47:8 Extent=[53:27 - 53:30]
+// CHECK: c-index-api-loadTU-test.m:54:3: CallExpr=main:46:5 Extent=[54:3 - 54:37]
+// 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:33: DeclRefExpr=bee:47:8 Extent=[54:33 - 54:36]
+

Modified: cfe/trunk/tools/CIndex/CIndex.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/CIndex/CIndex.cpp?rev=96571&r1=96570&r2=96571&view=diff

==============================================================================
--- cfe/trunk/tools/CIndex/CIndex.cpp (original)
+++ cfe/trunk/tools/CIndex/CIndex.cpp Wed Feb 17 23:46:33 2010
@@ -254,6 +254,7 @@
   bool VisitChildren(CXCursor Parent);
 
   // Declaration visitors
+  bool VisitAttributes(Decl *D);
   bool VisitDeclContext(DeclContext *DC);
   bool VisitTranslationUnitDecl(TranslationUnitDecl *D);
   bool VisitTypedefDecl(TypedefDecl *D);
@@ -436,6 +437,13 @@
 bool CursorVisitor::VisitDeclContext(DeclContext *DC) {
   for (DeclContext::decl_iterator
        I = DC->decls_begin(), E = DC->decls_end(); I != E; ++I) {
+
+    // Attributes currently don't have source ranges.  We only report them
+    // when the client hasn't specified a region of interest.
+    if (!RegionOfInterest.isValid())
+      if (VisitAttributes(*I))
+        return true;
+
     CXCursor Cursor = MakeCXCursor(*I, TU);
 
     if (RegionOfInterest.isValid()) {
@@ -896,6 +904,14 @@
   return VisitExpr(E);
 }
 
+bool CursorVisitor::VisitAttributes(Decl *D) {
+  for (const Attr *A = D->getAttrs(); A; A = A->getNext())
+    if (Visit(MakeCXCursor(A, D, TU)))
+        return true;
+
+  return false;
+}
+
 extern "C" {
 CXIndex clang_createIndex(int excludeDeclarationsFromPCH) {
   CIndexer *CIdxr = new CIndexer();





More information about the cfe-commits mailing list