[docs] Add LICENSE.txt to the root of the mono-repo
[llvm-project.git] / clang / test / Index / annotate-tokens.c
blob08e7a9a02f8f2471faf6b0fa26a74ad9f7a2a0ea
1 typedef int T;
2 struct X { int a, b; };
3 void 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";
11 enum Color { Red, Green, Blue };
12 typedef int Int;
13 enum Color g(int i, ...) {
14 __builtin_va_list va;
15 (void)__builtin_va_arg(va, Int);
16 (void)__builtin_types_compatible_p(Int, Int);
18 struct X x = { 0, 0 };
19 do {
20 x.a++;
21 } while (x.a < 10);
23 enum Color c;
24 switch (c) {
25 case Red:
26 return Green;
28 case Green:
29 return Blue;
31 case Blue:
32 return Red;
36 __attribute__((unavailable)) Int __attribute__((unavailable)) test() __attribute__((unavailable));
38 #define HEADER() \
39 int x; \
40 int y; \
41 int z
43 #define TYPE_INST(name, ...) \
44 static const struct { \
45 HEADER(); \
46 } name = { \
47 __VA_ARGS__ \
50 void func1(void);
52 TYPE_INST(Foo,
53 .x = 0,
54 .y = 1,
55 .z = 2,
58 void func2(void);
60 typedef union {
61 struct {
62 int field : 16;
64 } r_t;
66 void test() {
67 r_t reg;
68 reg.field = 1;
71 // RUN: c-index-test -test-annotate-tokens=%s:4:1:37:1 %s | FileCheck %s
72 // CHECK: Identifier: "T" [4:3 - 4:4] TypeRef=T:1:13
73 // CHECK: Punctuation: "*" [4:4 - 4:5] VarDecl=t_ptr:4:6 (Definition)
74 // CHECK: Identifier: "t_ptr" [4:6 - 4:11] VarDecl=t_ptr:4:6 (Definition)
75 // CHECK: Punctuation: "=" [4:12 - 4:13] VarDecl=t_ptr:4:6 (Definition)
76 // CHECK: Punctuation: "(" [4:14 - 4:15] CStyleCastExpr=
77 // CHECK: Identifier: "T" [4:15 - 4:16] TypeRef=T:1:13
78 // CHECK: Identifier: "ptr" [4:19 - 4:22] DeclRefExpr=ptr:3:14
79 // CHECK: Punctuation: ";" [4:22 - 4:23] DeclStmt=
80 // CHECK: Punctuation: "(" [5:3 - 5:4] CStyleCastExpr=
81 // CHECK: Keyword: "void" [5:4 - 5:8] CStyleCastExpr=
82 // CHECK: Punctuation: ")" [5:8 - 5:9] CStyleCastExpr=
83 // CHECK: Keyword: "sizeof" [5:9 - 5:15] UnaryExpr=
84 // CHECK: Punctuation: "(" [5:15 - 5:16] UnaryExpr=
85 // CHECK: Identifier: "T" [5:16 - 5:17] TypeRef=T:1:13
86 // CHECK: Punctuation: ")" [5:17 - 5:18] UnaryExpr=
87 // CHECK: Punctuation: ";" [5:18 - 5:19] CompoundStmt=
88 // CHECK: Keyword: "struct" [7:3 - 7:9] VarDecl=x:7:12 (Definition)
89 // CHECK: Identifier: "X" [7:10 - 7:11] TypeRef=struct X:2:8
90 // CHECK: Identifier: "x" [7:12 - 7:13] VarDecl=x:7:12 (Definition)
91 // CHECK: Punctuation: "=" [7:14 - 7:15] VarDecl=x:7:12 (Definition)
92 // CHECK: Punctuation: "(" [7:16 - 7:17] CompoundLiteralExpr=
93 // CHECK: Keyword: "struct" [7:17 - 7:23] CompoundLiteralExpr=
94 // CHECK: Identifier: "X" [7:24 - 7:25] TypeRef=struct X:2:8
95 // CHECK: Punctuation: ")" [7:25 - 7:26] CompoundLiteralExpr=
96 // CHECK: Punctuation: "{" [7:26 - 7:27] InitListExpr=
97 // CHECK: Literal: "1" [7:27 - 7:28] IntegerLiteral=
98 // CHECK: Punctuation: "," [7:28 - 7:29] InitListExpr=
99 // CHECK: Literal: "2" [7:30 - 7:31] IntegerLiteral=
100 // CHECK: Punctuation: "}" [7:31 - 7:32] InitListExpr=
101 // CHECK: Punctuation: ";" [7:32 - 7:33] DeclStmt=
102 // CHECK: Keyword: "void" [8:3 - 8:7] VarDecl=xx:8:9 (Definition)
103 // CHECK: Punctuation: "*" [8:8 - 8:9] VarDecl=xx:8:9 (Definition)
104 // CHECK: Identifier: "xx" [8:9 - 8:11] VarDecl=xx:8:9 (Definition)
105 // CHECK: Punctuation: "=" [8:12 - 8:13] VarDecl=xx:8:9 (Definition)
106 // CHECK: Identifier: "ptr" [8:14 - 8:17] DeclRefExpr=ptr:3:14
107 // CHECK: Punctuation: "?" [8:18 - 8:19] UnexposedExpr=
108 // CHECK: Punctuation: ":" [8:20 - 8:21] UnexposedExpr=
109 // CHECK: Punctuation: "&" [8:22 - 8:23] UnaryOperator=
110 // CHECK: Identifier: "x" [8:23 - 8:24] DeclRefExpr=x:7:12
111 // CHECK: Punctuation: ";" [8:24 - 8:25] DeclStmt=
112 // CHECK: Keyword: "const" [9:3 - 9:8] VarDecl=hello:9:16 (Definition)
113 // CHECK: Keyword: "char" [9:9 - 9:13] VarDecl=hello:9:16 (Definition)
114 // CHECK: Punctuation: "*" [9:14 - 9:15] VarDecl=hello:9:16 (Definition)
115 // CHECK: Identifier: "hello" [9:16 - 9:21] VarDecl=hello:9:16 (Definition)
116 // CHECK: Punctuation: "=" [9:22 - 9:23] VarDecl=hello:9:16 (Definition)
117 // CHECK: Literal: ""Hello"" [9:24 - 9:31] StringLiteral=
118 // CHECK: Punctuation: ";" [9:31 - 9:32] DeclStmt=
119 // CHECK: Punctuation: "}" [10:1 - 10:2] CompoundStmt=
120 // CHECK: Keyword: "__builtin_va_arg" [15:9 - 15:25] UnexposedExpr=
121 // CHECK: Identifier: "Int" [15:30 - 15:33] TypeRef=Int:12:13
122 // CHECK: Keyword: "__builtin_types_compatible_p" [16:9 - 16:37] UnexposedExpr=
123 // CHECK: Identifier: "Int" [16:38 - 16:41] TypeRef=Int:12:13
124 // CHECK: Punctuation: "," [16:41 - 16:42] UnexposedExpr=
125 // CHECK: Identifier: "Int" [16:43 - 16:46] TypeRef=Int:12:13
126 // CHECK: Keyword: "struct" [18:3 - 18:9] VarDecl=x:18:12 (Definition)
127 // CHECK: Identifier: "X" [18:10 - 18:11] TypeRef=struct X:2:8
128 // CHECK: Identifier: "x" [18:12 - 18:13] VarDecl=x:18:12 (Definition)
129 // CHECK: Keyword: "do" [19:3 - 19:5] DoStmt=
130 // CHECK: Identifier: "x" [20:5 - 20:6] DeclRefExpr=x:18:12
131 // CHECK: Punctuation: "." [20:6 - 20:7] MemberRefExpr=a:2:16
132 // CHECK: Identifier: "a" [20:7 - 20:8] MemberRefExpr=a:2:16
133 // CHECK: Punctuation: "++" [20:8 - 20:10] UnaryOperator=
134 // CHECK: Punctuation: ";" [20:10 - 20:11] CompoundStmt=
135 // CHECK: Punctuation: "}" [21:3 - 21:4] CompoundStmt=
136 // CHECK: Keyword: "while" [21:5 - 21:10] DoStmt=
137 // CHECK: Punctuation: "(" [21:11 - 21:12] DoStmt=
138 // CHECK: Identifier: "x" [21:12 - 21:13] DeclRefExpr=x:18:12
139 // CHECK: Punctuation: "." [21:13 - 21:14] MemberRefExpr=a:2:16
140 // CHECK: Identifier: "a" [21:14 - 21:15] MemberRefExpr=a:2:16
142 // CHECK: Keyword: "enum" [23:3 - 23:7] VarDecl=c:23:14 (Definition)
143 // CHECK: Identifier: "Color" [23:8 - 23:13] TypeRef=enum Color:11:6
144 // CHECK: Identifier: "c" [23:14 - 23:15] VarDecl=c:23:14 (Definition)
145 // CHECK: Punctuation: ";" [23:15 - 23:16] DeclStmt=
146 // CHECK: Keyword: "switch" [24:3 - 24:9] SwitchStmt=
147 // CHECK: Punctuation: "(" [24:10 - 24:11] SwitchStmt=
148 // CHECK: Identifier: "c" [24:11 - 24:12] DeclRefExpr=c:23:14
149 // CHECK: Punctuation: ")" [24:12 - 24:13] SwitchStmt=
150 // CHECK: Punctuation: "{" [24:14 - 24:15] CompoundStmt=
151 // CHECK: Keyword: "case" [25:3 - 25:7] CaseStmt=
152 // CHECK: Identifier: "Red" [25:8 - 25:11] DeclRefExpr=Red:11:14
153 // CHECK: Punctuation: ":" [25:11 - 25:12] CaseStmt=
154 // CHECK: Keyword: "return" [26:5 - 26:11] ReturnStmt=
155 // CHECK: Identifier: "Green" [26:12 - 26:17] DeclRefExpr=Green:11:19
156 // CHECK: Punctuation: ";" [26:17 - 26:18] CompoundStmt=
157 // CHECK: Keyword: "case" [28:3 - 28:7] CaseStmt=
158 // CHECK: Identifier: "Green" [28:8 - 28:13] DeclRefExpr=Green:11:19
159 // CHECK: Punctuation: ":" [28:13 - 28:14] CaseStmt=
160 // CHECK: Keyword: "return" [29:5 - 29:11] ReturnStmt=
161 // CHECK: Identifier: "Blue" [29:12 - 29:16] DeclRefExpr=Blue:11:26
162 // CHECK: Punctuation: ";" [29:16 - 29:17] CompoundStmt=
163 // CHECK: Keyword: "case" [31:3 - 31:7] CaseStmt=
164 // CHECK: Identifier: "Blue" [31:8 - 31:12] DeclRefExpr=Blue:11:26
165 // CHECK: Punctuation: ":" [31:12 - 31:13] CaseStmt=
166 // CHECK: Keyword: "return" [32:5 - 32:11] ReturnStmt=
167 // CHECK: Identifier: "Red" [32:12 - 32:15] DeclRefExpr=Red:11:14
168 // CHECK: Punctuation: ";" [32:15 - 32:16] CompoundStmt=
170 // CHECK: Keyword: "__attribute__" [36:1 - 36:14] FunctionDecl=test:36:63 (unavailable) (always unavailable: "")
171 // CHECK: Punctuation: "(" [36:14 - 36:15] FunctionDecl=test:36:63 (unavailable) (always unavailable: "")
172 // CHECK: Punctuation: "(" [36:15 - 36:16] FunctionDecl=test:36:63 (unavailable) (always unavailable: "")
173 // CHECK: Identifier: "unavailable" [36:16 - 36:27] UnexposedAttr=
174 // CHECK: Punctuation: ")" [36:27 - 36:28] FunctionDecl=test:36:63 (unavailable) (always unavailable: "")
175 // CHECK: Punctuation: ")" [36:28 - 36:29] FunctionDecl=test:36:63 (unavailable) (always unavailable: "")
176 // CHECK: Identifier: "Int" [36:30 - 36:33] TypeRef=Int:12:13
177 // CHECK: Keyword: "__attribute__" [36:34 - 36:47] FunctionDecl=test:36:63 (unavailable) (always unavailable: "")
178 // CHECK: Punctuation: "(" [36:47 - 36:48] FunctionDecl=test:36:63 (unavailable) (always unavailable: "")
179 // CHECK: Punctuation: "(" [36:48 - 36:49] FunctionDecl=test:36:63 (unavailable) (always unavailable: "")
180 // CHECK: Identifier: "unavailable" [36:49 - 36:60] UnexposedAttr=
181 // CHECK: Punctuation: ")" [36:60 - 36:61] FunctionDecl=test:36:63 (unavailable) (always unavailable: "")
182 // CHECK: Punctuation: ")" [36:61 - 36:62] FunctionDecl=test:36:63 (unavailable) (always unavailable: "")
183 // CHECK: Identifier: "test" [36:63 - 36:67] FunctionDecl=test:36:63 (unavailable) (always unavailable: "")
184 // CHECK: Punctuation: "(" [36:67 - 36:68] FunctionDecl=test:36:63 (unavailable) (always unavailable: "")
185 // CHECK: Punctuation: ")" [36:68 - 36:69] FunctionDecl=test:36:63 (unavailable) (always unavailable: "")
186 // CHECK: Keyword: "__attribute__" [36:70 - 36:83] FunctionDecl=test:36:63 (unavailable) (always unavailable: "")
187 // CHECK: Punctuation: "(" [36:83 - 36:84] FunctionDecl=test:36:63 (unavailable) (always unavailable: "")
188 // CHECK: Punctuation: "(" [36:84 - 36:85] FunctionDecl=test:36:63 (unavailable) (always unavailable: "")
189 // CHECK: Identifier: "unavailable" [36:85 - 36:96] UnexposedAttr=
190 // CHECK: Punctuation: ")" [36:96 - 36:97] FunctionDecl=test:36:63 (unavailable) (always unavailable: "")
191 // CHECK: Punctuation: ")" [36:97 - 36:98] FunctionDecl=test:36:63 (unavailable) (always unavailable: "")
192 // CHECK: Punctuation: ";" [36:98 - 36:99]
194 // RUN: c-index-test -test-annotate-tokens=%s:4:1:165:32 %s | FileCheck %s
195 // RUN: c-index-test -test-annotate-tokens=%s:4:1:165:38 %s | FileCheck %s
197 // RUN: c-index-test -test-annotate-tokens=%s:50:1:55:1 %s | FileCheck %s -check-prefix=CHECK-RANGE1
198 // CHECK-RANGE1: Keyword: "void" [50:1 - 50:5] FunctionDecl=func1:50:6
199 // CHECK-RANGE1: Identifier: "func1" [50:6 - 50:11] FunctionDecl=func1:50:6
200 // CHECK-RANGE1: Punctuation: "(" [50:11 - 50:12] FunctionDecl=func1:50:6
201 // CHECK-RANGE1: Keyword: "void" [50:12 - 50:16] FunctionDecl=func1:50:6
202 // CHECK-RANGE1: Punctuation: ")" [50:16 - 50:17] FunctionDecl=func1:50:6
203 // CHECK-RANGE1: Punctuation: ";" [50:17 - 50:18]
204 // CHECK-RANGE1: Identifier: "TYPE_INST" [52:1 - 52:10] macro expansion=TYPE_INST:43:9
205 // CHECK-RANGE1: Punctuation: "(" [52:10 - 52:11]
206 // CHECK-RANGE1: Identifier: "Foo" [52:11 - 52:14] VarDecl=Foo:52:11 (Definition)
207 // CHECK-RANGE1: Punctuation: "," [52:14 - 52:15]
208 // CHECK-RANGE1: Punctuation: "." [53:5 - 53:6] UnexposedExpr=
209 // CHECK-RANGE1: Identifier: "x" [53:6 - 53:7] MemberRef=x:52:1
210 // CHECK-RANGE1: Punctuation: "=" [53:8 - 53:9] UnexposedExpr=
211 // CHECK-RANGE1: Literal: "0" [53:10 - 53:11] IntegerLiteral=
212 // CHECK-RANGE1: Punctuation: "," [53:11 - 53:12] InitListExpr=
213 // CHECK-RANGE1: Punctuation: "." [54:5 - 54:6] UnexposedExpr=
214 // CHECK-RANGE1: Identifier: "y" [54:6 - 54:7] MemberRef=y:52:1
215 // CHECK-RANGE1: Punctuation: "=" [54:8 - 54:9] UnexposedExpr=
216 // CHECK-RANGE1: Literal: "1" [54:10 - 54:11] IntegerLiteral=
217 // CHECK-RANGE1: Punctuation: "," [54:11 - 54:12] InitListExpr=
219 // RUN: c-index-test -test-annotate-tokens=%s:54:1:70:1 %s | FileCheck %s -check-prefix=CHECK-RANGE2
220 // CHECK-RANGE2: Punctuation: "." [54:5 - 54:6] UnexposedExpr=
221 // CHECK-RANGE2: Identifier: "y" [54:6 - 54:7] MemberRef=y:52:1
222 // CHECK-RANGE2: Punctuation: "=" [54:8 - 54:9] UnexposedExpr=
223 // CHECK-RANGE2: Literal: "1" [54:10 - 54:11] IntegerLiteral=
224 // CHECK-RANGE2: Punctuation: "," [54:11 - 54:12] InitListExpr=
225 // CHECK-RANGE2: Punctuation: "." [55:5 - 55:6] UnexposedExpr=
226 // CHECK-RANGE2: Identifier: "z" [55:6 - 55:7] MemberRef=z:52:1
227 // CHECK-RANGE2: Punctuation: "=" [55:8 - 55:9] UnexposedExpr=
228 // CHECK-RANGE2: Literal: "2" [55:10 - 55:11] IntegerLiteral=
229 // CHECK-RANGE2: Punctuation: "," [55:11 - 55:12] InitListExpr=
230 // CHECK-RANGE2: Punctuation: ")" [56:1 - 56:2]
231 // CHECK-RANGE2: Punctuation: ";" [56:2 - 56:3]
232 // CHECK-RANGE2: Keyword: "void" [58:1 - 58:5] FunctionDecl=func2:58:6
233 // CHECK-RANGE2: Identifier: "func2" [58:6 - 58:11] FunctionDecl=func2:58:6
234 // CHECK-RANGE2: Punctuation: "(" [58:11 - 58:12] FunctionDecl=func2:58:6
235 // CHECK-RANGE2: Keyword: "void" [58:12 - 58:16] FunctionDecl=func2:58:6
236 // CHECK-RANGE2: Punctuation: ")" [58:16 - 58:17] FunctionDecl=func2:58:6
237 // CHECK-RANGE2: Punctuation: ";" [58:17 - 58:18]
239 // CHECK-RANGE2: Identifier: "reg" [68:3 - 68:6] DeclRefExpr=reg:67:7
240 // CHECK-RANGE2: Punctuation: "." [68:6 - 68:7] MemberRefExpr=field:62:9
241 // CHECK-RANGE2: Identifier: "field" [68:7 - 68:12] MemberRefExpr=field:62:9
243 // RUN: c-index-test -test-annotate-tokens=%s:68:15:68:16 %s | FileCheck %s -check-prefix=CHECK-RANGE3
244 // CHECK-RANGE3: Literal: "1" [68:15 - 68:16] IntegerLiteral=
245 // CHECK-RANGE3-NOT: Punctuation: ";"