blob: 0b5f3d477366f4d8738cc48a811b42ee4cf36448 [file] [log] [blame]
Douglas Gregorfc8ea232010-01-26 17:06:03 +00001typedef int T;
2struct X { int a, b; };
3void f(void *ptr) {
4 T* t_ptr = (T *)ptr;
5 (void)sizeof(T);
6 /* A comment */
7 struct X x = (struct X){1, 2};
8 void *xx = ptr ? : &x;
9 const char * hello = "Hello";
10}
Douglas Gregor0a9beb52011-03-02 21:45:00 +000011enum Color { Red, Green, Blue };
Douglas Gregor648220e2010-08-10 15:02:34 +000012typedef int Int;
Douglas Gregor0a9beb52011-03-02 21:45:00 +000013enum Color g(int i, ...) {
Douglas Gregor648220e2010-08-10 15:02:34 +000014 __builtin_va_list va;
15 (void)__builtin_va_arg(va, Int);
16 (void)__builtin_types_compatible_p(Int, Int);
Douglas Gregorc7b5ed62010-12-17 16:18:04 +000017
18 struct X x = { 0, 0 };
19 do {
20 x.a++;
21 } while (x.a < 10);
Douglas Gregor0a9beb52011-03-02 21:45:00 +000022
23 enum Color c;
24 switch (c) {
25 case Red:
26 return Green;
27
28 case Green:
29 return Blue;
30
31 case Blue:
32 return Red;
33 }
Douglas Gregor648220e2010-08-10 15:02:34 +000034}
35
Douglas Gregor0a9beb52011-03-02 21:45:00 +000036// RUN: c-index-test -test-annotate-tokens=%s:4:1:34:1 %s | FileCheck %s
Daniel Dunbar8f0bf812010-02-14 08:32:51 +000037// CHECK: Identifier: "T" [4:3 - 4:4] TypeRef=T:1:13
Ted Kremenekfbd84ca2010-05-05 00:55:23 +000038// CHECK: Punctuation: "*" [4:4 - 4:5] VarDecl=t_ptr:4:6 (Definition)
Daniel Dunbar8f0bf812010-02-14 08:32:51 +000039// CHECK: Identifier: "t_ptr" [4:6 - 4:11] VarDecl=t_ptr:4:6 (Definition)
Ted Kremenekfbd84ca2010-05-05 00:55:23 +000040// CHECK: Punctuation: "=" [4:12 - 4:13] VarDecl=t_ptr:4:6 (Definition)
Douglas Gregor42b29842011-10-05 19:00:14 +000041// CHECK: Punctuation: "(" [4:14 - 4:15] CStyleCastExpr=
Daniel Dunbar8f0bf812010-02-14 08:32:51 +000042// CHECK: Identifier: "T" [4:15 - 4:16] TypeRef=T:1:13
Daniel Dunbar8f0bf812010-02-14 08:32:51 +000043// CHECK: Identifier: "ptr" [4:19 - 4:22] DeclRefExpr=ptr:3:14
Douglas Gregor42b29842011-10-05 19:00:14 +000044// CHECK: Punctuation: ";" [4:22 - 4:23] DeclStmt=
45// CHECK: Punctuation: "(" [5:3 - 5:4] CStyleCastExpr=
46// CHECK: Keyword: "void" [5:4 - 5:8] CStyleCastExpr=
47// CHECK: Punctuation: ")" [5:8 - 5:9] CStyleCastExpr=
Ted Kremenekfbd84ca2010-05-05 00:55:23 +000048// CHECK: Keyword: "sizeof" [5:9 - 5:15] UnexposedExpr=
49// CHECK: Punctuation: "(" [5:15 - 5:16] UnexposedExpr=
Daniel Dunbar8f0bf812010-02-14 08:32:51 +000050// CHECK: Identifier: "T" [5:16 - 5:17] TypeRef=T:1:13
Ted Kremenekfbd84ca2010-05-05 00:55:23 +000051// CHECK: Punctuation: ")" [5:17 - 5:18] UnexposedExpr=
Douglas Gregor42b29842011-10-05 19:00:14 +000052// CHECK: Punctuation: ";" [5:18 - 5:19] CompoundStmt=
Abramo Bagnara0daaf322011-03-16 20:16:18 +000053// CHECK: Keyword: "struct" [7:3 - 7:9] VarDecl=x:7:12 (Definition)
Daniel Dunbar8f0bf812010-02-14 08:32:51 +000054// CHECK: Identifier: "X" [7:10 - 7:11] TypeRef=struct X:2:8
55// CHECK: Identifier: "x" [7:12 - 7:13] VarDecl=x:7:12 (Definition)
Ted Kremenekfbd84ca2010-05-05 00:55:23 +000056// CHECK: Punctuation: "=" [7:14 - 7:15] VarDecl=x:7:12 (Definition)
Douglas Gregor42b29842011-10-05 19:00:14 +000057// CHECK: Punctuation: "(" [7:16 - 7:17] CompoundLiteralExpr=
58// CHECK: Keyword: "struct" [7:17 - 7:23] CompoundLiteralExpr=
Daniel Dunbar8f0bf812010-02-14 08:32:51 +000059// CHECK: Identifier: "X" [7:24 - 7:25] TypeRef=struct X:2:8
Douglas Gregor42b29842011-10-05 19:00:14 +000060// CHECK: Punctuation: ")" [7:25 - 7:26] CompoundLiteralExpr=
61// CHECK: Punctuation: "{" [7:26 - 7:27] InitListExpr=
62// CHECK: Literal: "1" [7:27 - 7:28] IntegerLiteral=
63// CHECK: Punctuation: "," [7:28 - 7:29] InitListExpr=
64// CHECK: Literal: "2" [7:30 - 7:31] IntegerLiteral=
65// CHECK: Punctuation: "}" [7:31 - 7:32] InitListExpr=
66// CHECK: Punctuation: ";" [7:32 - 7:33] DeclStmt=
Ted Kremenekfbd84ca2010-05-05 00:55:23 +000067// CHECK: Keyword: "void" [8:3 - 8:7] VarDecl=xx:8:9 (Definition)
68// CHECK: Punctuation: "*" [8:8 - 8:9] VarDecl=xx:8:9 (Definition)
Daniel Dunbar8f0bf812010-02-14 08:32:51 +000069// CHECK: Identifier: "xx" [8:9 - 8:11] VarDecl=xx:8:9 (Definition)
Ted Kremenekfbd84ca2010-05-05 00:55:23 +000070// CHECK: Punctuation: "=" [8:12 - 8:13] VarDecl=xx:8:9 (Definition)
Daniel Dunbar8f0bf812010-02-14 08:32:51 +000071// CHECK: Identifier: "ptr" [8:14 - 8:17] DeclRefExpr=ptr:3:14
Ted Kremenekfbd84ca2010-05-05 00:55:23 +000072// CHECK: Punctuation: "?" [8:18 - 8:19] UnexposedExpr=
73// CHECK: Punctuation: ":" [8:20 - 8:21] UnexposedExpr=
Douglas Gregor42b29842011-10-05 19:00:14 +000074// CHECK: Punctuation: "&" [8:22 - 8:23] UnaryOperator=
Daniel Dunbar8f0bf812010-02-14 08:32:51 +000075// CHECK: Identifier: "x" [8:23 - 8:24] DeclRefExpr=x:7:12
Douglas Gregor42b29842011-10-05 19:00:14 +000076// CHECK: Punctuation: ";" [8:24 - 8:25] DeclStmt=
77// CHECK: Keyword: "const" [9:3 - 9:8] DeclStmt=
Ted Kremenekfbd84ca2010-05-05 00:55:23 +000078// CHECK: Keyword: "char" [9:9 - 9:13] VarDecl=hello:9:16 (Definition)
79// CHECK: Punctuation: "*" [9:14 - 9:15] VarDecl=hello:9:16 (Definition)
Daniel Dunbar8f0bf812010-02-14 08:32:51 +000080// CHECK: Identifier: "hello" [9:16 - 9:21] VarDecl=hello:9:16 (Definition)
Ted Kremenekfbd84ca2010-05-05 00:55:23 +000081// CHECK: Punctuation: "=" [9:22 - 9:23] VarDecl=hello:9:16 (Definition)
Douglas Gregor42b29842011-10-05 19:00:14 +000082// CHECK: Literal: ""Hello"" [9:24 - 9:31] StringLiteral=
83// CHECK: Punctuation: ";" [9:31 - 9:32] DeclStmt=
84// CHECK: Punctuation: "}" [10:1 - 10:2] CompoundStmt=
Douglas Gregor648220e2010-08-10 15:02:34 +000085// CHECK: Keyword: "__builtin_va_arg" [15:9 - 15:25] UnexposedExpr=
86// CHECK: Identifier: "Int" [15:30 - 15:33] TypeRef=Int:12:13
87// CHECK: Keyword: "__builtin_types_compatible_p" [16:9 - 16:37] UnexposedExpr=
88// CHECK: Identifier: "Int" [16:38 - 16:41] TypeRef=Int:12:13
89// CHECK: Punctuation: "," [16:41 - 16:42] UnexposedExpr=
90// CHECK: Identifier: "Int" [16:43 - 16:46] TypeRef=Int:12:13
Abramo Bagnara0daaf322011-03-16 20:16:18 +000091// CHECK: Keyword: "struct" [18:3 - 18:9] VarDecl=x:18:12 (Definition)
Douglas Gregorc7b5ed62010-12-17 16:18:04 +000092// CHECK: Identifier: "X" [18:10 - 18:11] TypeRef=struct X:2:8
93// CHECK: Identifier: "x" [18:12 - 18:13] VarDecl=x:18:12 (Definition)
Douglas Gregor42b29842011-10-05 19:00:14 +000094// CHECK: Keyword: "do" [19:3 - 19:5] DoStmt=
Douglas Gregorc7b5ed62010-12-17 16:18:04 +000095// CHECK: Identifier: "x" [20:5 - 20:6] DeclRefExpr=x:18:12
96// CHECK: Punctuation: "." [20:6 - 20:7] MemberRefExpr=a:2:16
97// CHECK: Identifier: "a" [20:7 - 20:8] MemberRefExpr=a:2:16
Douglas Gregor42b29842011-10-05 19:00:14 +000098// CHECK: Punctuation: "++" [20:8 - 20:10] UnaryOperator=
99// CHECK: Punctuation: ";" [20:10 - 20:11] CompoundStmt=
100// CHECK: Punctuation: "}" [21:3 - 21:4] CompoundStmt=
101// CHECK: Keyword: "while" [21:5 - 21:10] DoStmt=
102// CHECK: Punctuation: "(" [21:11 - 21:12] DoStmt=
Douglas Gregorc7b5ed62010-12-17 16:18:04 +0000103// CHECK: Identifier: "x" [21:12 - 21:13] DeclRefExpr=x:18:12
104// CHECK: Punctuation: "." [21:13 - 21:14] MemberRefExpr=a:2:16
105// CHECK: Identifier: "a" [21:14 - 21:15] MemberRefExpr=a:2:16
106
Abramo Bagnara0daaf322011-03-16 20:16:18 +0000107// CHECK: Keyword: "enum" [23:3 - 23:7] VarDecl=c:23:14 (Definition)
Douglas Gregor0a9beb52011-03-02 21:45:00 +0000108// CHECK: Identifier: "Color" [23:8 - 23:13] TypeRef=enum Color:11:6
109// CHECK: Identifier: "c" [23:14 - 23:15] VarDecl=c:23:14 (Definition)
Douglas Gregor42b29842011-10-05 19:00:14 +0000110// CHECK: Punctuation: ";" [23:15 - 23:16] DeclStmt=
111// CHECK: Keyword: "switch" [24:3 - 24:9] SwitchStmt=
112// CHECK: Punctuation: "(" [24:10 - 24:11] SwitchStmt=
Douglas Gregor0a9beb52011-03-02 21:45:00 +0000113// CHECK: Identifier: "c" [24:11 - 24:12] DeclRefExpr=c:23:14
Douglas Gregor42b29842011-10-05 19:00:14 +0000114// CHECK: Punctuation: ")" [24:12 - 24:13] SwitchStmt=
115// CHECK: Punctuation: "{" [24:14 - 24:15] CompoundStmt=
116// CHECK: Keyword: "case" [25:3 - 25:7] CaseStmt=
Douglas Gregor0a9beb52011-03-02 21:45:00 +0000117// CHECK: Identifier: "Red" [25:8 - 25:11] DeclRefExpr=Red:11:14
Douglas Gregor42b29842011-10-05 19:00:14 +0000118// CHECK: Punctuation: ":" [25:11 - 25:12] CaseStmt=
119// CHECK: Keyword: "return" [26:5 - 26:11] ReturnStmt=
Douglas Gregor0a9beb52011-03-02 21:45:00 +0000120// CHECK: Identifier: "Green" [26:12 - 26:17] DeclRefExpr=Green:11:19
Douglas Gregor42b29842011-10-05 19:00:14 +0000121// CHECK: Punctuation: ";" [26:17 - 26:18] CompoundStmt=
122// CHECK: Keyword: "case" [28:3 - 28:7] CaseStmt=
Douglas Gregor0a9beb52011-03-02 21:45:00 +0000123// CHECK: Identifier: "Green" [28:8 - 28:13] DeclRefExpr=Green:11:19
Douglas Gregor42b29842011-10-05 19:00:14 +0000124// CHECK: Punctuation: ":" [28:13 - 28:14] CaseStmt=
125// CHECK: Keyword: "return" [29:5 - 29:11] ReturnStmt=
Douglas Gregor0a9beb52011-03-02 21:45:00 +0000126// CHECK: Identifier: "Blue" [29:12 - 29:16] DeclRefExpr=Blue:11:26
Douglas Gregor42b29842011-10-05 19:00:14 +0000127// CHECK: Punctuation: ";" [29:16 - 29:17] CompoundStmt=
128// CHECK: Keyword: "case" [31:3 - 31:7] CaseStmt=
Douglas Gregor0a9beb52011-03-02 21:45:00 +0000129// CHECK: Identifier: "Blue" [31:8 - 31:12] DeclRefExpr=Blue:11:26
Douglas Gregor42b29842011-10-05 19:00:14 +0000130// CHECK: Punctuation: ":" [31:12 - 31:13] CaseStmt=
131// CHECK: Keyword: "return" [32:5 - 32:11] ReturnStmt=
Douglas Gregor0a9beb52011-03-02 21:45:00 +0000132// CHECK: Identifier: "Red" [32:12 - 32:15] DeclRefExpr=Red:11:14
Douglas Gregor42b29842011-10-05 19:00:14 +0000133// CHECK: Punctuation: ";" [32:15 - 32:16] CompoundStmt=
Douglas Gregor0a9beb52011-03-02 21:45:00 +0000134
Douglas Gregord1eabfb2010-02-27 02:42:25 +0000135// RUN: c-index-test -test-annotate-tokens=%s:4:1:165:32 %s | FileCheck %s
136// RUN: c-index-test -test-annotate-tokens=%s:4:1:165:38 %s | FileCheck %s