[cfe-commits] r101954 - in /cfe/trunk: test/Index/usrs.m tools/CIndex/CIndexUSRs.cpp tools/c-index-test/c-index-test.c
Ted Kremenek
kremenek at apple.com
Tue Apr 20 16:15:40 PDT 2010
Author: kremenek
Date: Tue Apr 20 18:15:40 2010
New Revision: 101954
URL: http://llvm.org/viewvc/llvm-project?rev=101954&view=rev
Log:
Fix USRs for 'extern' variables declaration in functions/method bodies.
Fix USRs for @synthesize.
Add more USR tests.
Added:
cfe/trunk/test/Index/usrs.m
Modified:
cfe/trunk/tools/CIndex/CIndexUSRs.cpp
cfe/trunk/tools/c-index-test/c-index-test.c
Added: cfe/trunk/test/Index/usrs.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Index/usrs.m?rev=101954&view=auto
==============================================================================
--- cfe/trunk/test/Index/usrs.m (added)
+++ cfe/trunk/test/Index/usrs.m Tue Apr 20 18:15:40 2010
@@ -0,0 +1,74 @@
+// RUN: c-index-test -test-load-source-usrs all %s | FileCheck %s
+
+enum {
+ ABA,
+ CADABA
+};
+
+enum {
+ FOO,
+ BAR
+};
+
+typedef struct {
+ int wa;
+ int moo;
+} MyStruct;
+
+enum Pizza {
+ CHEESE,
+ MUSHROOMS
+};
+
+ at interface Foo {
+ id x;
+ id y;
+}
+- (id) godzilla;
++ (id) kingkong;
+ at property int d1;
+ at end
+
+ at implementation Foo
+- (id) godzilla {
+ static int a = 0;
+ extern int z;
+ return 0;
+}
++ (id) kingkong {
+ return 0;
+}
+ at synthesize d1;
+ at end
+
+int z;
+
+// CHECK: usrs.m c:@Ea at usrs.m@3:1 Extent=[3:1 - 6:2]
+// CHECK: usrs.m c:@Ea at usrs.m@3:1 at ABA Extent=[4:3 - 4:6]
+// CHECK: usrs.m c:@Ea at usrs.m@3:1 at CADABA Extent=[5:3 - 5:9]
+// CHECK: usrs.m c:@Ea at usrs.m@8:1 Extent=[8:1 - 11:2]
+// CHECK: usrs.m c:@Ea at usrs.m@8:1 at FOO Extent=[9:3 - 9:6]
+// CHECK: usrs.m c:@Ea at usrs.m@8:1 at BAR Extent=[10:3 - 10:6]
+// CHECK: usrs.m c:@SA at MyStruct Extent=[13:9 - 16:2]
+// CHECK: usrs.m c:@SA at MyStruct@FI at wa Extent=[14:7 - 14:9]
+// CHECK: usrs.m c:@SA at MyStruct@FI at moo Extent=[15:7 - 15:10]
+// CHECK: usrs.m c:@T at usrs.m@16:3 at MyStruct Extent=[16:3 - 16:11]
+// CHECK: usrs.m c:@E at Pizza Extent=[18:1 - 21:2]
+// CHECK: usrs.m c:@E at Pizza@CHEESE Extent=[19:3 - 19:9]
+// CHECK: usrs.m c:@E at Pizza@MUSHROOMS Extent=[20:3 - 20:12]
+// CHECK: usrs.m c:objc(cs)Foo Extent=[23:1 - 30:5]
+// CHECK: usrs.m c:objc(cs)Foo at x Extent=[24:6 - 24:7]
+// CHECK: usrs.m c:objc(cs)Foo at y Extent=[25:6 - 25:7]
+// CHECK: usrs.m c:objc(cs)Foo(py)d1 Extent=[29:15 - 29:17]
+// CHECK: usrs.m c:objc(cs)Foo(im)godzilla Extent=[27:1 - 27:17]
+// CHECK: usrs.m c:objc(cs)Foo(cm)kingkong Extent=[28:1 - 28:17]
+// CHECK: usrs.m c:objc(cs)Foo(im)d1 Extent=[29:15 - 29:17]
+// CHECK: usrs.m c:objc(cs)Foo(im)setD1: Extent=[29:15 - 29:17]
+// CHECK: usrs.m c:objc(cs)Foo Extent=[32:1 - 42:2]
+// CHECK: usrs.m c:objc(cs)Foo(im)godzilla Extent=[33:1 - 37:2]
+// CHECK: usrs.m c:@z Extent=[35:10 - 35:15]
+// CHECK: usrs.m c:objc(cs)Foo(cm)kingkong Extent=[38:1 - 40:2]
+// CHECK: usrs.m c:objc(cs)Foo at d1 Extent=[41:13 - 41:15]
+// CHECK: usrs.m c:objc(cs)Foo(py)d1 Extent=[41:1 - 41:15]
+// CHECK: usrs.m c:@z Extent=[44:1 - 44:6]
+
Modified: cfe/trunk/tools/CIndex/CIndexUSRs.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/CIndex/CIndexUSRs.cpp?rev=101954&r1=101953&r2=101954&view=diff
==============================================================================
--- cfe/trunk/tools/CIndex/CIndexUSRs.cpp (original)
+++ cfe/trunk/tools/CIndex/CIndexUSRs.cpp Tue Apr 20 18:15:40 2010
@@ -46,11 +46,13 @@
void VisitNamespaceDecl(NamespaceDecl *D);
void VisitObjCClassDecl(ObjCClassDecl *CD);
void VisitObjCContainerDecl(ObjCContainerDecl *CD);
- void VisitObjCMethodDecl(ObjCMethodDecl *MD);
void VisitObjCForwardProtocolDecl(ObjCForwardProtocolDecl *P);
+ void VisitObjCMethodDecl(ObjCMethodDecl *MD);
void VisitObjCPropertyDecl(ObjCPropertyDecl *D);
+ void VisitObjCPropertyImplDecl(ObjCPropertyImplDecl *D);
void VisitTagDecl(TagDecl *D);
void VisitTypedefDecl(TypedefDecl *D);
+ void VisitVarDecl(VarDecl *D);
/// Generate the string component containing the location of the
/// declaration.
@@ -132,7 +134,7 @@
return;
}
VisitDeclContext(D->getDeclContext());
- Out << "@FI@" << s;
+ Out << (isa<ObjCIvarDecl>(D) ? "@" : "@FI@") << s;
}
void USRGenerator::VisitFunctionDecl(FunctionDecl *D) {
@@ -153,6 +155,24 @@
GenNamedDecl(s);
}
+void USRGenerator::VisitVarDecl(VarDecl *D) {
+ // VarDecls can be declared 'extern' within a function or method body,
+ // but their enclosing DeclContext is the function, not the TU. We need
+ // to check the storage class to correctly generate the USR.
+ if (!D->hasExternalStorage())
+ VisitDeclContext(D->getDeclContext());
+
+ const std::string &s = D->getNameAsString();
+ // The string can be empty if the declaration has no name; e.g., it is
+ // the ParmDecl with no name for declaration of a function pointer type, e.g.:
+ // void (*f)(void *);
+ // In this case, don't generate a USR.
+ if (s.empty())
+ IgnoreResults = true;
+ else
+ GenNamedDecl(s);
+}
+
void USRGenerator::VisitNamespaceDecl(NamespaceDecl *D) {
VisitDeclContext(D->getDeclContext());
Out << "@N@" << D;
@@ -223,6 +243,15 @@
GenObjCProperty(D->getName());
}
+void USRGenerator::VisitObjCPropertyImplDecl(ObjCPropertyImplDecl *D) {
+ if (ObjCPropertyDecl *PD = D->getPropertyDecl()) {
+ VisitObjCPropertyDecl(PD);
+ return;
+ }
+
+ IgnoreResults = true;
+}
+
void USRGenerator::VisitTagDecl(TagDecl *D) {
D = D->getCanonicalDecl();
VisitDeclContext(D->getDeclContext());
@@ -369,6 +398,9 @@
if (SUG->ignoreResults())
return createCXString("");
+ // For development testing.
+ // assert(SUG.str().size() > 2);
+
// Return a copy of the string that must be disposed by the caller.
return createCXString(SUG.str(), true);
}
Modified: cfe/trunk/tools/c-index-test/c-index-test.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/c-index-test/c-index-test.c?rev=101954&r1=101953&r2=101954&view=diff
==============================================================================
--- cfe/trunk/tools/c-index-test/c-index-test.c (original)
+++ cfe/trunk/tools/c-index-test/c-index-test.c Tue Apr 20 18:15:40 2010
@@ -372,12 +372,13 @@
VisitorData *Data = (VisitorData *)ClientData;
if (!Data->Filter || (C.kind == *(enum CXCursorKind *)Data->Filter)) {
CXString USR = clang_getCursorUSR(C);
- if (!clang_getCString(USR)) {
+ const char *cstr = clang_getCString(USR);
+ if (!cstr || cstr[0] == '\0') {
clang_disposeString(USR);
return CXChildVisit_Recurse;
}
- printf("// %s: %s %s", FileCheckPrefix, GetCursorSource(C),
- clang_getCString(USR));
+ printf("// %s: %s %s", FileCheckPrefix, GetCursorSource(C), cstr);
+
PrintCursorExtent(C);
printf("\n");
clang_disposeString(USR);
More information about the cfe-commits
mailing list