summaryrefslogtreecommitdiffstats
path: root/clang/test/Index
diff options
context:
space:
mode:
authorArgyrios Kyrtzidis <akyrtzi@gmail.com>2011-10-06 07:00:54 +0000
committerArgyrios Kyrtzidis <akyrtzi@gmail.com>2011-10-06 07:00:54 +0000
commitcddafd3969977630d9bbec724dd09b6cb97fd9fd (patch)
tree47505b09dfb01fe57cef3c6fd98fd4d3eb6ca073 /clang/test/Index
parent3b947f72da42a2ea3dc496e9edfb265edf29ad56 (diff)
downloadbcm5719-llvm-cddafd3969977630d9bbec724dd09b6cb97fd9fd.tar.gz
bcm5719-llvm-cddafd3969977630d9bbec724dd09b6cb97fd9fd.zip
[libclang] Introduce clang_findReferencesInFile which accepts a cursor, a file,
and a callback and finds all identifier references of the cursor in the file. rdar://7948304 llvm-svn: 141277
Diffstat (limited to 'clang/test/Index')
-rw-r--r--clang/test/Index/file-refs.c57
-rw-r--r--clang/test/Index/file-refs.cpp104
-rw-r--r--clang/test/Index/file-refs.m87
3 files changed, 248 insertions, 0 deletions
diff --git a/clang/test/Index/file-refs.c b/clang/test/Index/file-refs.c
new file mode 100644
index 00000000000..23042ea06f6
--- /dev/null
+++ b/clang/test/Index/file-refs.c
@@ -0,0 +1,57 @@
+enum {
+ VALUE = 3
+};
+
+extern int glob_x;
+
+int f(int x) {
+ return x+glob_x+VALUE;
+}
+
+typedef struct {
+ int x;
+ int y;
+} Vector;
+
+int vector_get_x(Vector v) {
+ int x = v.x;
+ return x;
+}
+
+int f(int);
+int f(int);
+
+// RUN: c-index-test \
+
+// RUN: -file-refs-at=%s:2:5 \
+// CHECK: EnumConstantDecl=VALUE:2:3 (Definition)
+// CHECK-NEXT: EnumConstantDecl=VALUE:2:3 (Definition) =[2:3 - 2:8]
+// CHECK-NEXT: DeclRefExpr=VALUE:2:3 =[8:19 - 8:24]
+
+// RUN: -file-refs-at=%s:8:15 \
+// CHECK-NEXT: DeclRefExpr=glob_x:5:12
+// CHECK-NEXT: VarDecl=glob_x:5:12 =[5:12 - 5:18]
+// CHECK-NEXT: DeclRefExpr=glob_x:5:12 =[8:12 - 8:18]
+
+// RUN: -file-refs-at=%s:8:10 \
+// CHECK-NEXT: DeclRefExpr=x:7:11
+// CHECK-NEXT: ParmDecl=x:7:11 (Definition) =[7:11 - 7:12]
+// CHECK-NEXT: DeclRefExpr=x:7:11 =[8:10 - 8:11]
+
+// RUN: -file-refs-at=%s:12:7 \
+// CHECK-NEXT: FieldDecl=x:12:7 (Definition)
+// CHECK-NEXT: FieldDecl=x:12:7 (Definition) =[12:7 - 12:8]
+// CHECK-NEXT: MemberRefExpr=x:12:7 {{.*}} =[17:13 - 17:14]
+
+// RUN: -file-refs-at=%s:16:21 \
+// CHECK-NEXT: TypeRef=Vector:14:3
+// CHECK-NEXT: TypedefDecl=Vector:14:3 (Definition) =[14:3 - 14:9]
+// CHECK-NEXT: TypeRef=Vector:14:3 =[16:18 - 16:24]
+
+// RUN: -file-refs-at=%s:21:5 \
+// CHECK-NEXT: FunctionDecl=f:21:5
+// CHECK-NEXT: FunctionDecl=f:7:5 (Definition) =[7:5 - 7:6]
+// CHECK-NEXT: FunctionDecl=f:21:5 =[21:5 - 21:6]
+// CHECK-NEXT: FunctionDecl=f:22:5 =[22:5 - 22:6]
+
+// RUN: %s | FileCheck %s
diff --git a/clang/test/Index/file-refs.cpp b/clang/test/Index/file-refs.cpp
new file mode 100644
index 00000000000..a96d27c6307
--- /dev/null
+++ b/clang/test/Index/file-refs.cpp
@@ -0,0 +1,104 @@
+namespace NS {
+ class C {
+ public:
+ C() { }
+ void m();
+ };
+}
+
+void NS::C::m() {
+ C c;
+ c.m();
+}
+
+void f() {
+ NS::C c1();
+ NS::C c2 = NS::C();
+}
+
+void over(int);
+void over(float);
+
+void test_over() {
+ over(0);
+ over(0.0f);
+}
+
+template <typename T>
+T tf(T t) {
+ return t;
+}
+
+namespace Test2 {
+
+struct S {
+ S(int x, int y);
+ S();
+};
+
+typedef S Cake;
+
+void f() {
+ Cake p;
+ p = Test2::S(0,2);
+ p = Test2::Cake(0,2);
+}
+
+}
+
+// RUN: c-index-test \
+
+// RUN: -file-refs-at=%s:9:7 \
+// CHECK: NamespaceRef=NS:1:11
+// CHECK-NEXT: Namespace=NS:1:11 (Definition) =[1:11 - 1:13]
+// CHECK-NEXT: NamespaceRef=NS:1:11 =[9:6 - 9:8]
+// CHECK-NEXT: NamespaceRef=NS:1:11 =[15:3 - 15:5]
+// CHECK-NEXT: NamespaceRef=NS:1:11 =[16:3 - 16:5]
+// CHECK-NEXT: NamespaceRef=NS:1:11 =[16:14 - 16:16]
+
+// RUN: -file-refs-at=%s:2:9 \
+// CHECK-NEXT: ClassDecl=C:2:9 (Definition)
+// CHECK-NEXT: ClassDecl=C:2:9 (Definition) =[2:9 - 2:10]
+// CHECK-NEXT: CXXConstructor=C:4:5 (Definition) =[4:5 - 4:6]
+// CHECK-NEXT: TypeRef=class NS::C:2:9 =[9:10 - 9:11]
+// CHECK-NEXT: TypeRef=class NS::C:2:9 =[10:3 - 10:4]
+// CHECK-NEXT: TypeRef=class NS::C:2:9 =[15:7 - 15:8]
+// CHECK-NEXT: TypeRef=class NS::C:2:9 =[16:7 - 16:8]
+// CHECK-NEXT: TypeRef=class NS::C:2:9 =[16:18 - 16:19]
+
+// RUN: -file-refs-at=%s:16:18 \
+// CHECK-NEXT: CallExpr=C:4:5
+// CHECK-NEXT: ClassDecl=C:2:9 (Definition) =[2:9 - 2:10]
+// CHECK-NEXT: CXXConstructor=C:4:5 (Definition) =[4:5 - 4:6]
+// CHECK-NEXT: TypeRef=class NS::C:2:9 =[9:10 - 9:11]
+// CHECK-NEXT: TypeRef=class NS::C:2:9 =[10:3 - 10:4]
+// CHECK-NEXT: TypeRef=class NS::C:2:9 =[15:7 - 15:8]
+// CHECK-NEXT: TypeRef=class NS::C:2:9 =[16:7 - 16:8]
+// CHECK-NEXT: TypeRef=class NS::C:2:9 =[16:18 - 16:19]
+
+// RUN: -file-refs-at=%s:20:8 \
+// CHECK-NEXT: FunctionDecl=over:20:6
+// CHECK-NEXT: FunctionDecl=over:20:6 =[20:6 - 20:10]
+// CHECK-NEXT: DeclRefExpr=over:20:6 =[24:3 - 24:7]
+
+// RUN: -file-refs-at=%s:28:1 \
+// CHECK-NEXT: TypeRef=T:27:20
+// FIXME: Missing TemplateTypeParameter=T:27:20 (Definition)
+// CHECK-NEXT: TypeRef=T:27:20 =[28:1 - 28:2]
+// CHECK-NEXT: TypeRef=T:27:20 =[28:6 - 28:7]
+
+// RUN: -file-refs-at=%s:43:14 \
+// CHECK-NEXT: CallExpr=S:35:3
+// CHECK-NEXT: StructDecl=S:34:8 (Definition) =[34:8 - 34:9]
+// CHECK-NEXT: CXXConstructor=S:35:3 =[35:3 - 35:4]
+// CHECK-NEXT: CXXConstructor=S:36:3 =[36:3 - 36:4]
+// CHECK-NEXT: TypeRef=struct Test2::S:34:8 =[39:9 - 39:10]
+// CHECK-NEXT: TypeRef=struct Test2::S:34:8 =[43:14 - 43:15]
+
+// RUN: -file-refs-at=%s:44:16 \
+// CHECK-NEXT: CallExpr=S:35:3
+// CHECK-NEXT: TypedefDecl=Cake:39:11 (Definition) =[39:11 - 39:15]
+// CHECK-NEXT: TypeRef=Cake:39:11 =[42:3 - 42:7]
+// CHECK-NEXT: TypeRef=Cake:39:11 =[44:14 - 44:18]
+
+// RUN: %s | FileCheck %s
diff --git a/clang/test/Index/file-refs.m b/clang/test/Index/file-refs.m
new file mode 100644
index 00000000000..2267259d58a
--- /dev/null
+++ b/clang/test/Index/file-refs.m
@@ -0,0 +1,87 @@
+@class Foo;
+
+@interface Foo
+-(id)setWithInt:(int)i andFloat:(float)f;
+@end
+
+@implementation Foo
+-(id)setWithInt:(int)i andFloat:(float)f {
+ return self;
+}
+@end
+
+void test(Foo *foo) {
+ [foo setWithInt:0 andFloat:0];
+ [foo setWithInt: 2 andFloat: 3];
+}
+
+@protocol Prot1
+-(void)protMeth;
+@end
+
+@protocol Prot2<Prot1>
+@end
+
+@interface Base<Prot2>
+@end
+
+@interface Sub : Base
+-(void)protMeth;
+@end
+
+@implementation Sub
+-(void)protMeth {}
+@end
+
+void test2(Sub *s, id<Prot1> p) {
+ [s protMeth];
+ [p protMeth];
+}
+
+
+// RUN: c-index-test \
+
+// RUN: -file-refs-at=%s:7:18 \
+// CHECK: ObjCImplementationDecl=Foo:7:17 (Definition)
+// CHECK-NEXT: ObjCClassRef=Foo:3:12 =[1:8 - 1:11]
+// CHECK-NEXT: ObjCInterfaceDecl=Foo:3:12 =[3:12 - 3:15]
+// CHECK-NEXT: ObjCImplementationDecl=Foo:7:17 (Definition) =[7:17 - 7:20]
+// CHECK-NEXT: ObjCClassRef=Foo:3:12 =[13:11 - 13:14]
+
+// RUN: -file-refs-at=%s:4:10 \
+// CHECK-NEXT: ObjCInstanceMethodDecl=setWithInt:andFloat::4:1
+// CHECK-NEXT: ObjCInstanceMethodDecl=setWithInt:andFloat::4:1 =[4:6 - 4:16]
+// CHECK-NEXT: ObjCInstanceMethodDecl=setWithInt:andFloat::8:1 (Definition) [Overrides @4:1] =[8:6 - 8:16]
+// CHECK-NEXT: ObjCMessageExpr=setWithInt:andFloat::4:1 =[14:8 - 14:18]
+// CHECK-NEXT: ObjCMessageExpr=setWithInt:andFloat::4:1 =[15:8 - 15:18]
+
+// RUN: -file-refs-at=%s:15:27 \
+// CHECK-NEXT: ObjCMessageExpr=setWithInt:andFloat::4:1
+// CHECK-NEXT: ObjCInstanceMethodDecl=setWithInt:andFloat::4:1 =[4:24 - 4:32]
+// CHECK-NEXT: ObjCInstanceMethodDecl=setWithInt:andFloat::8:1 (Definition) [Overrides @4:1] =[8:24 - 8:32]
+// CHECK-NEXT: ObjCMessageExpr=setWithInt:andFloat::4:1 =[14:21 - 14:29]
+// CHECK-NEXT: ObjCMessageExpr=setWithInt:andFloat::4:1 =[15:22 - 15:30]
+
+// RUN: -file-refs-at=%s:18:13 \
+// CHECK-NEXT: ObjCProtocolDecl=Prot1:18:11 (Definition)
+// CHECK-NEXT: ObjCProtocolDecl=Prot1:18:11 (Definition) =[18:11 - 18:16]
+// CHECK-NEXT: ObjCProtocolRef=Prot1:18:11 =[22:17 - 22:22]
+// CHECK-NEXT: ObjCProtocolRef=Prot1:18:11 =[36:23 - 36:28]
+
+// RUN: -file-refs-at=%s:38:10 \
+// CHECK-NEXT: ObjCMessageExpr=protMeth:19:1
+// CHECK-NEXT: ObjCInstanceMethodDecl=protMeth:19:1 =[19:8 - 19:16]
+// CHECK-NEXT: ObjCInstanceMethodDecl=protMeth:29:1 [Overrides @19:1] =[29:8 - 29:16]
+// CHECK-NEXT: ObjCInstanceMethodDecl=protMeth:33:1 (Definition) [Overrides @29:1] =[33:8 - 33:16]
+// CHECK-NEXT: ObjCMessageExpr=protMeth:29:1 =[37:6 - 37:14]
+// CHECK-NEXT: ObjCMessageExpr=protMeth:19:1 =[38:6 - 38:14]
+
+// RUN: -file-refs-at=%s:33:12 \
+// CHECK-NEXT: ObjCInstanceMethodDecl=protMeth:33:1 (Definition) [Overrides @29:1]
+// CHECK-NEXT: ObjCInstanceMethodDecl=protMeth:19:1 =[19:8 - 19:16]
+// CHECK-NEXT: ObjCInstanceMethodDecl=protMeth:29:1 [Overrides @19:1] =[29:8 - 29:16]
+// CHECK-NEXT: ObjCInstanceMethodDecl=protMeth:33:1 (Definition) [Overrides @29:1] =[33:8 - 33:16]
+// CHECK-NEXT: ObjCMessageExpr=protMeth:29:1 =[37:6 - 37:14]
+// CHECK-NEXT: ObjCMessageExpr=protMeth:19:1 =[38:6 - 38:14]
+
+// RUN: %s | FileCheck %s
OpenPOWER on IntegriCloud