summaryrefslogtreecommitdiff
path: root/test/Index
diff options
context:
space:
mode:
authorRoman Divacky <rdivacky@FreeBSD.org>2009-10-14 18:03:49 +0000
committerRoman Divacky <rdivacky@FreeBSD.org>2009-10-14 18:03:49 +0000
commit4c8b24812ddcd1dedaca343a6d4e76f91f398981 (patch)
tree137ebebcae16fb0ce7ab4af456992bbd8d22fced /test/Index
parent5362a71c02e7d448a8ce98cf00c47e353fba5d04 (diff)
Notes
Diffstat (limited to 'test/Index')
-rw-r--r--test/Index/c-index-api-test.m224
-rw-r--r--test/Index/comments.c30
-rw-r--r--test/Index/cxx-operator-overload.cpp28
-rw-r--r--test/Index/find-decls.c25
-rw-r--r--test/Index/find-defs.c18
-rw-r--r--test/Index/find-refs.c47
-rw-r--r--test/Index/foo.h8
-rw-r--r--test/Index/multiple-redecls.c12
-rw-r--r--test/Index/objc-decls.m16
-rw-r--r--test/Index/objc-message.m38
-rw-r--r--test/Index/objc.h11
-rw-r--r--test/Index/resolve-loc.c39
-rw-r--r--test/Index/t1.c31
-rw-r--r--test/Index/t1.m23
-rw-r--r--test/Index/t2.c14
-rw-r--r--test/Index/t2.m16
16 files changed, 554 insertions, 26 deletions
diff --git a/test/Index/c-index-api-test.m b/test/Index/c-index-api-test.m
new file mode 100644
index 0000000000000..20d4d7b45afd5
--- /dev/null
+++ b/test/Index/c-index-api-test.m
@@ -0,0 +1,224 @@
+// RUN: clang-cc -triple x86_64-apple-darwin10 -emit-pch -x objective-c %s -o %t.ast &&
+// RUN: c-index-test %t.ast all | FileCheck %s
+
+// CHECK: <invalid loc>:0:0: TypedefDecl=__int128_t:0:0 [Context=c-index-api-test.m]
+// CHECK: <invalid loc>:0:0: TypedefDecl=__uint128_t:0:0 [Context=c-index-api-test.m]
+// CHECK: <invalid loc>:0:0: StructDecl=objc_selector:0:0 [Context=c-index-api-test.m]
+// CHECK: <invalid loc>:0:0: TypedefDecl=SEL:0:0 [Context=c-index-api-test.m]
+// CHECK: <invalid loc>:0:0: ObjCInterfaceDecl=Protocol:0:0 [Context=c-index-api-test.m]
+// CHECK: <invalid loc>:0:0: TypedefDecl=id:0:0 [Context=c-index-api-test.m]
+// CHECK: <invalid loc>:0:0: TypedefDecl=Class:0:0 [Context=c-index-api-test.m]
+// CHECK: <built-in>:79:16: StructDecl=__va_list_tag:79:16 [Context=c-index-api-test.m]
+// CHECK: <built-in>:79:42: FieldDecl=gp_offset:79:42 [Context=__va_list_tag]
+// CHECK: <built-in>:79:63: FieldDecl=fp_offset:79:63 [Context=__va_list_tag]
+// CHECK: <built-in>:79:81: FieldDecl=overflow_arg_area:79:81 [Context=__va_list_tag]
+// CHECK: <built-in>:79:107: FieldDecl=reg_save_area:79:107 [Context=__va_list_tag]
+// CHECK: <built-in>:79:123: TypedefDecl=__va_list_tag:79:123 [Context=c-index-api-test.m]
+// CHECK: <built-in>:79:159: TypedefDecl=__builtin_va_list:79:159 [Context=c-index-api-test.m]
+//
+
+@interface Foo
+{
+}
+
+- foo;
++ fooC;
+
+@end
+
+@interface Bar : Foo
+{
+}
+
+@end
+
+@interface Foo (FooCat)
+- (int) catMethodWithFloat:(float) fArg;
+- (float) floatMethod;
+@end
+
+@protocol Proto
+- pMethod;
+@end
+
+@protocol SubP <Proto>
+- spMethod;
+@end
+
+@interface Baz : Bar <SubP>
+{
+ int _anIVar;
+}
+
+- (Foo *) bazMethod;
+
+@end
+
+enum {
+ someEnum
+};
+
+// CHECK: c-index-api-test.m:20:12: ObjCInterfaceDecl=Foo:20:1 [Context=c-index-api-test.m]
+// CHECK: c-index-api-test.m:24:1: ObjCInstanceMethodDecl=foo:24:1 [Context=Foo]
+// CHECK: c-index-api-test.m:25:1: ObjCClassMethodDecl=fooC:25:1 [Context=Foo]
+// CHECK: c-index-api-test.m:29:12: ObjCInterfaceDecl=Bar:29:1 [Context=c-index-api-test.m]
+// CHECK: c-index-api-test.m:29:18: ObjCSuperClassRef=Foo:29:1 [Context=Bar]
+// CHECK: c-index-api-test.m:35:1: ObjCCategoryDecl=FooCat:35:1 [Context=c-index-api-test.m]
+// CHECK: c-index-api-test.m:20:1: ObjCClassRef=Foo:35:1 [Context=FooCat]
+// CHECK: c-index-api-test.m:36:1: ObjCInstanceMethodDecl=catMethodWithFloat::36:1 [Context=FooCat]
+// CHECK: c-index-api-test.m:37:1: ObjCInstanceMethodDecl=floatMethod:37:1 [Context=FooCat]
+// CHECK: c-index-api-test.m:40:1: ObjCProtocolDecl=Proto:40:1 [Context=c-index-api-test.m]
+// CHECK: c-index-api-test.m:41:1: ObjCInstanceMethodDecl=pMethod:41:1 [Context=Proto]
+// CHECK: c-index-api-test.m:44:1: ObjCProtocolDecl=SubP:44:1 [Context=c-index-api-test.m]
+// CHECK: c-index-api-test.m:40:1: ObjCProtocolRef=Proto:40:1 [Context=SubP]
+// CHECK: c-index-api-test.m:45:1: ObjCInstanceMethodDecl=spMethod:45:1 [Context=SubP]
+// CHECK: c-index-api-test.m:48:12: ObjCInterfaceDecl=Baz:48:1 [Context=c-index-api-test.m]
+// CHECK: c-index-api-test.m:48:18: ObjCSuperClassRef=Bar:48:1 [Context=Baz]
+// CHECK: c-index-api-test.m:44:1: ObjCProtocolRef=SubP:44:1 [Context=Baz]
+// CHECK: c-index-api-test.m:50:9: ObjCIvarDecl=_anIVar:50:9 [Context=Baz]
+// CHECK: c-index-api-test.m:53:1: ObjCInstanceMethodDecl=bazMethod:53:1 [Context=Baz]
+// CHECK: c-index-api-test.m:57:1: EnumDecl=:57:1 [Context=c-index-api-test.m]
+// CHECK: c-index-api-test.m:58:3: EnumConstantDecl=someEnum:58:3 [Context=]
+
+int main (int argc, const char * argv[]) {
+ Baz * bee;
+ id a = [bee foo];
+ id <SubP> c = [Foo fooC];
+ id <Proto> d;
+ d = c;
+ [d pMethod];
+ [bee catMethodWithFloat:[bee floatMethod]];
+ main(someEnum, (const char **)bee);
+}
+
+// CHECK: c-index-api-test.m:83:5: FunctionDefn=main [Context=c-index-api-test.m]
+// CHECK: c-index-api-test.m:83:15: ParmDecl=argc:83:15 [Context=main]
+// CHECK: c-index-api-test.m:83:34: ParmDecl=argv:83:34 [Context=main]
+// CHECK: c-index-api-test.m:84:8: VarDecl=bee:84:8 [Context=main]
+// CHECK: c-index-api-test.m:85:5: VarDecl=a:85:5 [Context=main]
+// CHECK: c-index-api-test.m:86:12: VarDecl=c:86:12 [Context=main]
+// CHECK: c-index-api-test.m:87:13: VarDecl=d:87:13 [Context=main]
+// CHECK: c-index-api-test.m:84:2: ObjCClassRef=Baz:84:8 [Context:Baz]
+// CHECK: c-index-api-test.m:84:3: ObjCClassRef=Baz:84:8 [Context:Baz]
+// CHECK: c-index-api-test.m:84:4: ObjCClassRef=Baz:84:8 [Context:Baz]
+// CHECK: c-index-api-test.m:84:6: VarDecl=bee:84:8 [Context:bee]
+// CHECK: c-index-api-test.m:84:8: VarDecl=bee:84:8 [Context:bee]
+// CHECK: c-index-api-test.m:84:9: VarDecl=bee:84:8 [Context:bee]
+// CHECK: c-index-api-test.m:84:10: VarDecl=bee:84:8 [Context:bee]
+// CHECK: <invalid loc>:85:2: TypedefDecl=id:0:0 [Context:id]
+// CHECK: <invalid loc>:85:3: TypedefDecl=id:0:0 [Context:id]
+// CHECK: c-index-api-test.m:85:5: VarDecl=a:85:5 [Context:a]
+// CHECK: c-index-api-test.m:85:6: VarDecl=a:85:5 [Context:a]
+// CHECK: c-index-api-test.m:85:7: VarDecl=a:85:5 [Context:a]
+// CHECK: c-index-api-test.m:85:8: VarDecl=a:85:5 [Context:a]
+// CHECK: c-index-api-test.m:85:9: ObjCSelectorRef=foo:24:1 [Context:a]
+// CHECK: c-index-api-test.m:85:10: VarRef=bee:84:8 [Context:a]
+// CHECK: c-index-api-test.m:85:11: VarRef=bee:84:8 [Context:a]
+// CHECK: c-index-api-test.m:85:12: VarRef=bee:84:8 [Context:a]
+// CHECK: c-index-api-test.m:85:13: ObjCSelectorRef=foo:24:1 [Context:a]
+// CHECK: c-index-api-test.m:85:14: ObjCSelectorRef=foo:24:1 [Context:a]
+// CHECK: c-index-api-test.m:85:15: ObjCSelectorRef=foo:24:1 [Context:a]
+// CHECK: c-index-api-test.m:85:16: ObjCSelectorRef=foo:24:1 [Context:a]
+// CHECK: c-index-api-test.m:85:17: ObjCSelectorRef=foo:24:1 [Context:a]
+// CHECK: <invalid loc>:86:2: TypedefDecl=id:0:0 [Context:id]
+// CHECK: <invalid loc>:86:3: TypedefDecl=id:0:0 [Context:id]
+// CHECK: c-index-api-test.m:86:5: VarDecl=c:86:12 [Context:c]
+// CHECK: c-index-api-test.m:86:6: ObjCProtocolRef=SubP:86:12 [Context:SubP]
+// CHECK: c-index-api-test.m:86:7: ObjCProtocolRef=SubP:86:12 [Context:SubP]
+// CHECK: c-index-api-test.m:86:8: ObjCProtocolRef=SubP:86:12 [Context:SubP]
+// CHECK: c-index-api-test.m:86:9: ObjCProtocolRef=SubP:86:12 [Context:SubP]
+// CHECK: c-index-api-test.m:86:10: VarDecl=c:86:12 [Context:c]
+// CHECK: c-index-api-test.m:86:12: VarDecl=c:86:12 [Context:c]
+// CHECK: c-index-api-test.m:86:13: VarDecl=c:86:12 [Context:c]
+// CHECK: c-index-api-test.m:86:14: VarDecl=c:86:12 [Context:c]
+// CHECK: c-index-api-test.m:86:15: VarDecl=c:86:12 [Context:c]
+// CHECK: c-index-api-test.m:86:16: ObjCSelectorRef=fooC:25:1 [Context:c]
+// CHECK: c-index-api-test.m:86:17: ObjCSelectorRef=fooC:25:1 [Context:c]
+// CHECK: c-index-api-test.m:86:18: ObjCSelectorRef=fooC:25:1 [Context:c]
+// CHECK: c-index-api-test.m:86:19: ObjCSelectorRef=fooC:25:1 [Context:c]
+// CHECK: c-index-api-test.m:86:20: ObjCSelectorRef=fooC:25:1 [Context:c]
+// CHECK: c-index-api-test.m:86:21: ObjCSelectorRef=fooC:25:1 [Context:c]
+// CHECK: c-index-api-test.m:86:22: ObjCSelectorRef=fooC:25:1 [Context:c]
+// CHECK: c-index-api-test.m:86:23: ObjCSelectorRef=fooC:25:1 [Context:c]
+// CHECK: c-index-api-test.m:86:24: ObjCSelectorRef=fooC:25:1 [Context:c]
+// CHECK: c-index-api-test.m:86:25: ObjCSelectorRef=fooC:25:1 [Context:c]
+// CHECK: <invalid loc>:87:2: TypedefDecl=id:0:0 [Context:id]
+// CHECK: <invalid loc>:87:3: TypedefDecl=id:0:0 [Context:id]
+// CHECK: c-index-api-test.m:87:5: VarDecl=d:87:13 [Context:d]
+// CHECK: c-index-api-test.m:87:6: ObjCProtocolRef=Proto:87:13 [Context:Proto]
+// CHECK: c-index-api-test.m:87:7: ObjCProtocolRef=Proto:87:13 [Context:Proto]
+// CHECK: c-index-api-test.m:87:8: ObjCProtocolRef=Proto:87:13 [Context:Proto]
+// CHECK: c-index-api-test.m:87:9: ObjCProtocolRef=Proto:87:13 [Context:Proto]
+// CHECK: c-index-api-test.m:87:10: ObjCProtocolRef=Proto:87:13 [Context:Proto]
+// CHECK: c-index-api-test.m:87:11: VarDecl=d:87:13 [Context:d]
+// CHECK: c-index-api-test.m:87:13: VarDecl=d:87:13 [Context:d]
+// CHECK: c-index-api-test.m:88:2: VarRef=d:87:13 [Context:main]
+// CHECK: c-index-api-test.m:88:6: VarRef=c:86:12 [Context:main]
+// CHECK: c-index-api-test.m:89:2: ObjCSelectorRef=pMethod:41:1 [Context:main]
+// CHECK: c-index-api-test.m:89:3: VarRef=d:87:13 [Context:main]
+// CHECK: c-index-api-test.m:89:4: ObjCSelectorRef=pMethod:41:1 [Context:main]
+// CHECK: c-index-api-test.m:89:5: ObjCSelectorRef=pMethod:41:1 [Context:main]
+// CHECK: c-index-api-test.m:89:6: ObjCSelectorRef=pMethod:41:1 [Context:main]
+// CHECK: c-index-api-test.m:89:7: ObjCSelectorRef=pMethod:41:1 [Context:main]
+// CHECK: c-index-api-test.m:89:8: ObjCSelectorRef=pMethod:41:1 [Context:main]
+// CHECK: c-index-api-test.m:89:9: ObjCSelectorRef=pMethod:41:1 [Context:main]
+// CHECK: c-index-api-test.m:89:10: ObjCSelectorRef=pMethod:41:1 [Context:main]
+// CHECK: c-index-api-test.m:89:11: ObjCSelectorRef=pMethod:41:1 [Context:main]
+// CHECK: c-index-api-test.m:89:12: ObjCSelectorRef=pMethod:41:1 [Context:main]
+// CHECK: c-index-api-test.m:90:2: ObjCSelectorRef=catMethodWithFloat::36:1 [Context:main]
+// CHECK: c-index-api-test.m:90:3: VarRef=bee:84:8 [Context:main]
+// CHECK: c-index-api-test.m:90:4: VarRef=bee:84:8 [Context:main]
+// CHECK: c-index-api-test.m:90:5: VarRef=bee:84:8 [Context:main]
+// CHECK: c-index-api-test.m:90:6: ObjCSelectorRef=catMethodWithFloat::36:1 [Context:main]
+// CHECK: c-index-api-test.m:90:7: ObjCSelectorRef=catMethodWithFloat::36:1 [Context:main]
+// CHECK: c-index-api-test.m:90:8: ObjCSelectorRef=catMethodWithFloat::36:1 [Context:main]
+// CHECK: c-index-api-test.m:90:9: ObjCSelectorRef=catMethodWithFloat::36:1 [Context:main]
+// CHECK: c-index-api-test.m:90:10: ObjCSelectorRef=catMethodWithFloat::36:1 [Context:main]
+// CHECK: c-index-api-test.m:90:11: ObjCSelectorRef=catMethodWithFloat::36:1 [Context:main]
+// CHECK: c-index-api-test.m:90:12: ObjCSelectorRef=catMethodWithFloat::36:1 [Context:main]
+// CHECK: c-index-api-test.m:90:13: ObjCSelectorRef=catMethodWithFloat::36:1 [Context:main]
+// CHECK: c-index-api-test.m:90:14: ObjCSelectorRef=catMethodWithFloat::36:1 [Context:main]
+// CHECK: c-index-api-test.m:90:15: ObjCSelectorRef=catMethodWithFloat::36:1 [Context:main]
+// CHECK: c-index-api-test.m:90:16: ObjCSelectorRef=catMethodWithFloat::36:1 [Context:main]
+// CHECK: c-index-api-test.m:90:17: ObjCSelectorRef=catMethodWithFloat::36:1 [Context:main]
+// CHECK: c-index-api-test.m:90:18: ObjCSelectorRef=catMethodWithFloat::36:1 [Context:main]
+// CHECK: c-index-api-test.m:90:19: ObjCSelectorRef=catMethodWithFloat::36:1 [Context:main]
+// CHECK: c-index-api-test.m:90:20: ObjCSelectorRef=catMethodWithFloat::36:1 [Context:main]
+// CHECK: c-index-api-test.m:90:21: ObjCSelectorRef=catMethodWithFloat::36:1 [Context:main]
+// CHECK: c-index-api-test.m:90:22: ObjCSelectorRef=catMethodWithFloat::36:1 [Context:main]
+// CHECK: c-index-api-test.m:90:23: ObjCSelectorRef=catMethodWithFloat::36:1 [Context:main]
+// CHECK: c-index-api-test.m:90:24: ObjCSelectorRef=catMethodWithFloat::36:1 [Context:main]
+// CHECK: c-index-api-test.m:90:25: ObjCSelectorRef=catMethodWithFloat::36:1 [Context:main]
+// CHECK: c-index-api-test.m:90:26: ObjCSelectorRef=floatMethod:37:1 [Context:main]
+// CHECK: c-index-api-test.m:90:27: VarRef=bee:84:8 [Context:main]
+// CHECK: c-index-api-test.m:90:28: VarRef=bee:84:8 [Context:main]
+// CHECK: c-index-api-test.m:90:29: VarRef=bee:84:8 [Context:main]
+// CHECK: c-index-api-test.m:90:30: ObjCSelectorRef=floatMethod:37:1 [Context:main]
+// CHECK: c-index-api-test.m:90:31: ObjCSelectorRef=floatMethod:37:1 [Context:main]
+// CHECK: c-index-api-test.m:90:32: ObjCSelectorRef=floatMethod:37:1 [Context:main]
+// CHECK: c-index-api-test.m:90:33: ObjCSelectorRef=floatMethod:37:1 [Context:main]
+// CHECK: c-index-api-test.m:90:34: ObjCSelectorRef=floatMethod:37:1 [Context:main]
+// CHECK: c-index-api-test.m:90:35: ObjCSelectorRef=floatMethod:37:1 [Context:main]
+// CHECK: c-index-api-test.m:90:36: ObjCSelectorRef=floatMethod:37:1 [Context:main]
+// CHECK: c-index-api-test.m:90:37: ObjCSelectorRef=floatMethod:37:1 [Context:main]
+// CHECK: c-index-api-test.m:90:38: ObjCSelectorRef=floatMethod:37:1 [Context:main]
+// CHECK: c-index-api-test.m:90:39: ObjCSelectorRef=floatMethod:37:1 [Context:main]
+// CHECK: c-index-api-test.m:90:40: ObjCSelectorRef=floatMethod:37:1 [Context:main]
+// CHECK: c-index-api-test.m:90:41: ObjCSelectorRef=floatMethod:37:1 [Context:main]
+// CHECK: c-index-api-test.m:90:42: ObjCSelectorRef=floatMethod:37:1 [Context:main]
+// CHECK: c-index-api-test.m:90:43: ObjCSelectorRef=catMethodWithFloat::36:1 [Context:main]
+// CHECK: c-index-api-test.m:91:3: FunctionRef=main:83:5 [Context:main]
+// CHECK: c-index-api-test.m:91:4: FunctionRef=main:83:5 [Context:main]
+// CHECK: c-index-api-test.m:91:5: FunctionRef=main:83:5 [Context:main]
+// CHECK: c-index-api-test.m:91:6: FunctionRef=main:83:5 [Context:main]
+// CHECK: c-index-api-test.m:91:8: EnumConstantRef=someEnum:58:3 [Context:main]
+// CHECK: c-index-api-test.m:91:9: EnumConstantRef=someEnum:58:3 [Context:main]
+// CHECK: c-index-api-test.m:91:10: EnumConstantRef=someEnum:58:3 [Context:main]
+// CHECK: c-index-api-test.m:91:11: EnumConstantRef=someEnum:58:3 [Context:main]
+// CHECK: c-index-api-test.m:91:12: EnumConstantRef=someEnum:58:3 [Context:main]
+// CHECK: c-index-api-test.m:91:13: EnumConstantRef=someEnum:58:3 [Context:main]
+// CHECK: c-index-api-test.m:91:14: EnumConstantRef=someEnum:58:3 [Context:main]
+// CHECK: c-index-api-test.m:91:15: EnumConstantRef=someEnum:58:3 [Context:main]
+// CHECK: c-index-api-test.m:91:33: VarRef=bee:84:8 [Context:main]
+// CHECK: c-index-api-test.m:91:34: VarRef=bee:84:8 [Context:main]
+// CHECK: c-index-api-test.m:91:35: VarRef=bee:84:8 [Context:main]
diff --git a/test/Index/comments.c b/test/Index/comments.c
index 7ad8fd7e1f495..689ce88e22138 100644
--- a/test/Index/comments.c
+++ b/test/Index/comments.c
@@ -1,15 +1,4 @@
-// RUN: clang-cc -emit-pch -o %t.ast %s &&
-// RUN: index-test %t.ast -point-at %s:22:6 | grep "starts here" &&
-// RUN: index-test %t.ast -point-at %s:22:6 | grep "block comment" &&
-// RUN: index-test %t.ast -point-at %s:28:6 | grep "BCPL" &&
-// RUN: index-test %t.ast -point-at %s:28:6 | grep "But" &&
-// RUN: index-test %t.ast -point-at %s:28:6 | grep "NOT" | count 0 &&
-// RUN: index-test %t.ast -point-at %s:30:6 | grep "member"
-
-
-
-
-
+// Run lines are sensitive to line numbers and come below the code.
//! It all starts here.
/*! It's a little odd to continue line this,
@@ -27,4 +16,19 @@ void f(int, int);
/** But there are other blocks that are part of the comment, too. */
void g(int);
-void h(int); ///< This is a member comment. \ No newline at end of file
+void h(int); ///< This is a member comment.
+
+
+// RUN: clang-cc -emit-pch -o %t.ast %s &&
+
+// RUN: index-test %t.ast -point-at %s:11:6 > %t &&
+// RUN: grep "starts here" %t &&
+// RUN: grep "block comment" %t &&
+
+// RUN: index-test %t.ast -point-at %s:17:6 > %t &&
+// RUN: grep "BCPL" %t &&
+// RUN: grep "But" %t &&
+
+// RUN: index-test %t.ast -point-at %s:19:6 > %t &&
+// RUN: grep "NOT" %t | count 0 &&
+// RUN: grep "member" %t
diff --git a/test/Index/cxx-operator-overload.cpp b/test/Index/cxx-operator-overload.cpp
new file mode 100644
index 0000000000000..9bda03ef8dc45
--- /dev/null
+++ b/test/Index/cxx-operator-overload.cpp
@@ -0,0 +1,28 @@
+// Run lines are sensitive to line numbers and come below the code.
+// FIXME: re-enable this when we can serialize more C++ ASTs
+class Cls {
+public:
+ Cls operator +(const Cls &RHS);
+};
+
+static void bar() {
+ Cls x1, x2, x3;
+ Cls x4 = x1 + x2 + x3;
+}
+
+Cls Cls::operator +(const Cls &RHS) { while (1) {} }
+
+// RUN: clang-cc -emit-pch %s -o %t.ast
+
+// RUNx: index-test %t.ast -point-at %s:10:17 -print-decls > %t &&
+// RUNx: cat %t | count 2 &&
+// RUNx: grep ':5:9,' %t &&
+// RUNx: grep ':13:10,' %t &&
+
+// Yep, we can show references of '+' plus signs that are overloaded, w00t!
+// RUNx: index-test %t.ast -point-at %s:5:15 -print-refs > %t &&
+// RUNx: cat %t | count 2 &&
+// RUNx: grep ':10:17,' %t &&
+// RUNx: grep ':10:22,' %t &&
+
+// RUNx: index-test %t.ast -point-at %s:10:14 | grep 'DeclRefExpr x1'
diff --git a/test/Index/find-decls.c b/test/Index/find-decls.c
new file mode 100644
index 0000000000000..50a233d75ba5d
--- /dev/null
+++ b/test/Index/find-decls.c
@@ -0,0 +1,25 @@
+// RUN: clang-cc -fblocks -emit-pch %S/t1.c -o %t1.ast &&
+// RUN: clang-cc -fblocks -emit-pch %S/t2.c -o %t2.ast &&
+
+// RUN: index-test %t1.ast %t2.ast -point-at %S/t1.c:8:7 -print-decls > %t &&
+// RUN: cat %t | count 3 &&
+// RUN: grep 'foo.h:4:6,' %t | count 2 &&
+// RUN: grep 't2.c:5:6,' %t &&
+
+// RUN: index-test %t1.ast %t2.ast -point-at %S/t1.c:5:47 -print-decls > %t &&
+// RUN: cat %t | count 1 &&
+// RUN: grep 't1.c:5:12,' %t &&
+
+// RUN: index-test %t1.ast %t2.ast -point-at %S/t1.c:6:20 -print-decls > %t &&
+// RUN: cat %t | count 1 &&
+// RUN: grep 't1.c:3:19,' %t &&
+
+// field test
+
+// RUN: index-test %t1.ast %t2.ast -point-at %S/t1.c:21:6 -print-decls > %t &&
+// RUN: cat %t | count 1 &&
+// RUN: grep 't1.c:12:7,' %t &&
+
+// RUN: index-test %t1.ast %t2.ast -point-at %S/t1.c:22:21 -print-decls > %t &&
+// RUN: cat %t | count 1 &&
+// RUN: grep 't1.c:16:7,' %t
diff --git a/test/Index/find-defs.c b/test/Index/find-defs.c
new file mode 100644
index 0000000000000..0e63ae7600479
--- /dev/null
+++ b/test/Index/find-defs.c
@@ -0,0 +1,18 @@
+// RUN: clang-cc -fblocks -emit-pch %S/t1.c -o %t1.ast &&
+// RUN: clang-cc -fblocks -emit-pch %S/t2.c -o %t2.ast &&
+
+// RUN: index-test %t1.ast %t2.ast -point-at %S/foo.h:1:14 -print-defs > %t &&
+// RUN: cat %t | count 1 &&
+// RUN: grep 't2.c:3:5,' %t &&
+
+// RUN: index-test %t1.ast %t2.ast -point-at %S/foo.h:3:9 -print-defs > %t &&
+// RUN: cat %t | count 1 &&
+// RUN: grep 't1.c:3:6,' %t &&
+
+// RUN: index-test %t1.ast %t2.ast -point-at %S/foo.h:4:9 -print-defs > %t &&
+// RUN: cat %t | count 1 &&
+// RUN: grep 't2.c:5:6,' %t &&
+
+// RUN: index-test %t1.ast %t2.ast -point-at %S/t1.c:8:7 -print-defs > %t &&
+// RUN: cat %t | count 1 &&
+// RUN: grep 't2.c:5:6,' %t
diff --git a/test/Index/find-refs.c b/test/Index/find-refs.c
new file mode 100644
index 0000000000000..1b58b37527730
--- /dev/null
+++ b/test/Index/find-refs.c
@@ -0,0 +1,47 @@
+// RUN: clang-cc -fblocks -emit-pch %S/t1.c -o %t1.ast &&
+// RUN: clang-cc -fblocks -emit-pch %S/t2.c -o %t2.ast &&
+
+// RUN: index-test %t1.ast %t2.ast -point-at %S/foo.h:1:14 -print-refs > %t &&
+// RUN: cat %t | count 4 &&
+// RUN: grep 't1.c:4:19,' %t &&
+// RUN: grep 't1.c:28:40,' %t &&
+// RUN: grep 't2.c:6:3,' %t &&
+// RUN: grep 't2.c:7:12,' %t &&
+
+// RUN: index-test %t1.ast %t2.ast -point-at %S/foo.h:3:9 -print-refs > %t &&
+// RUN: cat %t | count 1 &&
+// RUN: grep 't2.c:7:3,' %t &&
+
+// RUN: index-test %t1.ast %t2.ast -point-at %S/foo.h:4:9 -print-refs > %t &&
+// RUN: cat %t | count 1 &&
+// RUN: grep 't1.c:8:3,' %t &&
+
+// RUN: index-test %t1.ast %t2.ast -point-at %S/t1.c:3:22 -print-refs > %t &&
+// RUN: cat %t | count 1 &&
+// RUN: grep 't1.c:6:17,' %t &&
+
+// RUN: index-test %t1.ast %t2.ast -point-at %S/t1.c:4:11 -print-refs > %t &&
+// RUN: cat %t | count 1 &&
+// RUN: grep 't1.c:6:5,' %t &&
+
+// RUN: index-test %t1.ast %t2.ast -point-at %S/t1.c:5:30 -print-refs > %t &&
+// RUN: cat %t | count 3 &&
+// RUN: grep 't1.c:5:27,' %t &&
+// RUN: grep 't1.c:5:44,' %t &&
+// RUN: grep 't1.c:6:26,' %t &&
+
+// field test
+
+// FIXME: References point at the start of MemberExpr, make them point at the field instead.
+// RUN: index-test %t1.ast %t2.ast -point-at %S/t1.c:12:7 -print-refs > %t &&
+// RUN: cat %t | count 1 &&
+// RUN: grep 't1.c:21:3,' %t &&
+
+// RUN: index-test %t1.ast %t2.ast -point-at %S/t1.c:16:7 -print-refs > %t &&
+// RUN: cat %t | count 1 &&
+// RUN: grep 't1.c:22:3,' %t &&
+
+// RUN: index-test %t1.ast %t2.ast -point-at %S/foo.h:7:11 -print-refs > %t &&
+// RUN: cat %t | count 2 &&
+// RUN: grep 't1.c:25:3,' %t &&
+// RUN: grep 't2.c:10:3,' %t
diff --git a/test/Index/foo.h b/test/Index/foo.h
new file mode 100644
index 0000000000000..7670c00dfbfe9
--- /dev/null
+++ b/test/Index/foo.h
@@ -0,0 +1,8 @@
+extern int global_var;
+
+void foo_func(int param1);
+void bar_func(void);
+
+struct MyStruct {
+ int field_var;
+};
diff --git a/test/Index/multiple-redecls.c b/test/Index/multiple-redecls.c
new file mode 100644
index 0000000000000..6f1f75b02f39a
--- /dev/null
+++ b/test/Index/multiple-redecls.c
@@ -0,0 +1,12 @@
+// RUN: clang-cc -emit-pch %s -o %t.ast &&
+// RUN: index-test %t.ast -point-at %s:8:4 -print-decls | count 2 &&
+// RUN: index-test %t.ast -point-at %s:8:4 -print-defs | count 1
+
+static void foo(int x);
+
+static void bar(void) {
+ foo(10);
+}
+
+void foo(int x) {
+}
diff --git a/test/Index/objc-decls.m b/test/Index/objc-decls.m
new file mode 100644
index 0000000000000..1a8ab4b5577e7
--- /dev/null
+++ b/test/Index/objc-decls.m
@@ -0,0 +1,16 @@
+// RUN: clang-cc -emit-pch %S/t1.m -o %t1.m.ast &&
+// RUN: clang-cc -emit-pch %S/t2.m -o %t2.m.ast &&
+
+// RUN: index-test %t1.m.ast %t2.m.ast -point-at %S/t1.m:12:12 -print-decls > %t &&
+// RUN: cat %t | count 2 &&
+// RUN: grep 'objc.h:2:9,' %t | count 2 &&
+
+// RUN: index-test %t1.m.ast %t2.m.ast -point-at %S/objc.h:5:13 -print-decls > %t &&
+// RUN: cat %t | count 3 &&
+// RUN: grep 'objc.h:5:1,' %t | count 2 &&
+// RUN: grep 't1.m:15:1,' %t | count 1 &&
+
+// RUN: index-test %t1.m.ast %t2.m.ast -point-at %S/objc.h:10:13 -print-decls > %t &&
+// RUN: cat %t | count 3 &&
+// RUN: grep 'objc.h:10:1,' %t | count 2 &&
+// RUN: grep 't2.m:11:1,' %t | count 1
diff --git a/test/Index/objc-message.m b/test/Index/objc-message.m
new file mode 100644
index 0000000000000..45ce83876cfeb
--- /dev/null
+++ b/test/Index/objc-message.m
@@ -0,0 +1,38 @@
+// RUN: clang-cc -emit-pch %S/t1.m -o %t1.m.ast &&
+// RUN: clang-cc -emit-pch %S/t2.m -o %t2.m.ast &&
+
+// RUN: index-test %t1.m.ast %t2.m.ast -point-at %S/objc.h:5:13 -print-refs > %t &&
+// RUN: cat %t | count 1 &&
+// RUN: grep 't1.m:6:3,' %t &&
+
+// RUN: index-test %t1.m.ast %t2.m.ast -point-at %S/objc.h:6:13 -print-refs > %t &&
+// RUN: cat %t | count 2 &&
+// RUN: grep 't1.m:7:3,' %t &&
+// RUN: grep 't2.m:7:3,' %t &&
+
+// RUN: index-test %t1.m.ast %t2.m.ast -point-at %S/objc.h:10:13 -print-refs > %t &&
+// RUN: cat %t | count 2 &&
+// RUN: grep 't1.m:6:3,' %t &&
+// RUN: grep 't2.m:6:3,' %t &&
+
+// RUN: index-test %t1.m.ast %t2.m.ast -point-at %S/t1.m:6:15 -print-decls > %t &&
+// RUN: cat %t | count 6 &&
+// RUN: grep 'objc.h:5:1,' %t | count 2 &&
+// RUN: grep 'objc.h:10:1,' %t | count 2 &&
+// RUN: grep 't1.m:15:1,' %t &&
+// RUN: grep 't2.m:11:1,' %t &&
+
+// RUN: index-test %t1.m.ast %t2.m.ast -point-at %S/t1.m:7:15 -print-decls > %t &&
+// RUN: cat %t | count 3 &&
+// RUN: grep 'objc.h:6:1,' %t | count 2 &&
+// RUN: grep 't1.m:18:1,' %t &&
+
+// RUN: index-test %t2.m.ast %t1.m.ast -point-at %S/t2.m:6:15 -print-decls > %t &&
+// RUN: cat %t | count 3 &&
+// RUN: grep 'objc.h:10:1,' %t | count 2 &&
+// RUN: grep 't2.m:11:1,' %t &&
+
+// RUN: index-test %t2.m.ast %t1.m.ast -point-at %S/t2.m:7:15 -print-decls > %t &&
+// RUN: cat %t | count 3 &&
+// RUN: grep 'objc.h:6:1,' %t | count 2 &&
+// RUN: grep 't1.m:18:1,' %t
diff --git a/test/Index/objc.h b/test/Index/objc.h
new file mode 100644
index 0000000000000..c671addde59f0
--- /dev/null
+++ b/test/Index/objc.h
@@ -0,0 +1,11 @@
+@interface Base {
+ int my_var;
+}
+-(int) my_var;
+-(void) my_method: (int)param;
++(void) my_method: (int)param;
+@end
+
+@interface Sub : Base
+-(void) my_method: (int)param;
+@end
diff --git a/test/Index/resolve-loc.c b/test/Index/resolve-loc.c
index d04b79b024edd..cae86f38dd6d4 100644
--- a/test/Index/resolve-loc.c
+++ b/test/Index/resolve-loc.c
@@ -1,16 +1,4 @@
-// RUN: clang-cc -emit-pch %s -o %t.ast &&
-// RUN: index-test %t.ast -point-at %s:15:8 | grep top_var &&
-// RUN: index-test %t.ast -point-at %s:17:15 | grep top_func_decl &&
-// RUN: index-test %t.ast -point-at %s:17:25 | grep param1 &&
-// RUN: index-test %t.ast -point-at %s:19:17 | grep top_func_def &&
-// RUN: index-test %t.ast -point-at %s:19:23 | grep param2 &&
-// RUN: index-test %t.ast -point-at %s:20:10 | grep local_var1 &&
-// RUN: index-test %t.ast -point-at %s:21:15 | grep for_var &&
-// RUN: index-test %t.ast -point-at %s:21:43 | grep top_func_def &&
-// RUN: index-test %t.ast -point-at %s:21:43 | grep '++for_var' &&
-// RUN: index-test %t.ast -point-at %s:22:9 | grep local_var2 &&
-// RUN: index-test %t.ast -point-at %s:22:30 | grep local_var2 &&
-// RUN: index-test %t.ast -point-at %s:22:30 | grep 'for_var + 1'
+// Run lines are sensitive to line numbers and come below the code.
int top_var;
@@ -22,3 +10,28 @@ void top_func_def(int param2) {
int local_var2 = for_var + 1;
}
}
+
+struct S {
+ int field_var;
+};
+
+
+// RUN: clang-cc -emit-pch %s -o %t.ast &&
+// RUN: index-test %t.ast -point-at %s:3:8 | grep top_var &&
+// RUN: index-test %t.ast -point-at %s:5:15 | grep top_func_decl &&
+// RUN: index-test %t.ast -point-at %s:5:25 | grep param1 &&
+// RUN: index-test %t.ast -point-at %s:7:17 | grep top_func_def &&
+// RUN: index-test %t.ast -point-at %s:7:23 | grep param2 &&
+// RUN: index-test %t.ast -point-at %s:8:10 | grep local_var1 &&
+// RUN: index-test %t.ast -point-at %s:9:15 | grep for_var &&
+
+// RUN: index-test %t.ast -point-at %s:9:43 > %t &&
+// RUN: grep '++for_var' %t &&
+
+// RUN: index-test %t.ast -point-at %s:10:9 | grep local_var2 &&
+
+// RUN: index-test %t.ast -point-at %s:10:30 > %t &&
+// RUN: grep 'for_var + 1' %t &&
+
+// fields test.
+// RUN: index-test %t.ast -point-at %s:15:10 | grep field_var
diff --git a/test/Index/t1.c b/test/Index/t1.c
new file mode 100644
index 0000000000000..45e04881244db
--- /dev/null
+++ b/test/Index/t1.c
@@ -0,0 +1,31 @@
+#include "foo.h"
+
+void foo_func(int param1) {
+ int local_var = global_var;
+ for (int for_var = 100; for_var < 500; ++for_var) {
+ local_var = param1 + for_var;
+ }
+ bar_func();
+}
+
+struct S1 {
+ int x;
+};
+
+struct S2 {
+ int x;
+};
+
+void field_test(void) {
+ struct S1 s1;
+ s1.x = 0;
+ ((struct S2 *)0)->x = 0;
+
+ struct MyStruct ms;
+ ms.field_var = 10;
+}
+
+int (^CP)(int) = ^(int x) { return x * global_var; };
+
+// Suppress 'no run line' failure.
+// RUN: true
diff --git a/test/Index/t1.m b/test/Index/t1.m
new file mode 100644
index 0000000000000..b2a7a3726d206
--- /dev/null
+++ b/test/Index/t1.m
@@ -0,0 +1,23 @@
+#include "objc.h"
+
+static void foo() {
+ Base *base;
+ int x = [base my_var];
+ [base my_method:x];
+ [Base my_method:x];
+}
+
+@implementation Base
+-(int) my_var {
+ return my_var;
+}
+
+-(void) my_method: (int)param {
+}
+
++(void) my_method: (int)param {
+}
+@end
+
+// Suppress 'no run line' failure.
+// RUN: true
diff --git a/test/Index/t2.c b/test/Index/t2.c
new file mode 100644
index 0000000000000..bf52869ec8d92
--- /dev/null
+++ b/test/Index/t2.c
@@ -0,0 +1,14 @@
+#include "foo.h"
+
+int global_var = 10;
+
+void bar_func(void) {
+ global_var += 100;
+ foo_func(global_var);
+
+ struct MyStruct *ms;
+ ms->field_var = 10;
+}
+
+// Suppress 'no run line' failure.
+// RUN: true
diff --git a/test/Index/t2.m b/test/Index/t2.m
new file mode 100644
index 0000000000000..00d2f1d92b05c
--- /dev/null
+++ b/test/Index/t2.m
@@ -0,0 +1,16 @@
+#include "objc.h"
+
+static void foo() {
+ Sub *sub;
+ int x = [sub my_var];
+ [sub my_method:x];
+ [Sub my_method:x];
+}
+
+@implementation Sub
+-(void) my_method: (int)param {
+}
+@end
+
+// Suppress 'no run line' failure.
+// RUN: true