xref: /minix3/external/bsd/llvm/dist/clang/test/Index/annotate-tokens.cpp (revision f4a2713ac843a11c696ec80c0a5e3e5d80b4d338)
1*f4a2713aSLionel Sambuc struct bonk { };
2*f4a2713aSLionel Sambuc void test(bonk X) {
3*f4a2713aSLionel Sambuc     X = X;
4*f4a2713aSLionel Sambuc     __is_base_of(bonk, bonk);
5*f4a2713aSLionel Sambuc }
6*f4a2713aSLionel Sambuc 
7*f4a2713aSLionel Sambuc struct X {
8*f4a2713aSLionel Sambuc   X operator++();
9*f4a2713aSLionel Sambuc   X operator++(int);
10*f4a2713aSLionel Sambuc };
11*f4a2713aSLionel Sambuc void test2(X x) {
12*f4a2713aSLionel Sambuc   ++(x);
13*f4a2713aSLionel Sambuc   (x)++;
14*f4a2713aSLionel Sambuc }
15*f4a2713aSLionel Sambuc 
16*f4a2713aSLionel Sambuc struct S1 { void f(); };
17*f4a2713aSLionel Sambuc struct S2 { S1 *operator->(); };
18*f4a2713aSLionel Sambuc void test3(S2 s2) {
19*f4a2713aSLionel Sambuc   s2->f();
20*f4a2713aSLionel Sambuc   X foo;
21*f4a2713aSLionel Sambuc }
22*f4a2713aSLionel Sambuc 
23*f4a2713aSLionel Sambuc template <bool (*tfn)(X*)>
24*f4a2713aSLionel Sambuc struct TS {
25*f4a2713aSLionel Sambuc   void foo();
26*f4a2713aSLionel Sambuc };
27*f4a2713aSLionel Sambuc 
28*f4a2713aSLionel Sambuc template <bool (*tfn)(X*)>
29*f4a2713aSLionel Sambuc void TS<tfn>::foo() {}
30*f4a2713aSLionel Sambuc 
31*f4a2713aSLionel Sambuc // RUN: c-index-test -test-annotate-tokens=%s:1:1:30:1 %s -fno-delayed-template-parsing | FileCheck %s
32*f4a2713aSLionel Sambuc // CHECK: Keyword: "struct" [1:1 - 1:7] StructDecl=bonk:1:8 (Definition)
33*f4a2713aSLionel Sambuc // CHECK: Identifier: "bonk" [1:8 - 1:12] StructDecl=bonk:1:8 (Definition)
34*f4a2713aSLionel Sambuc // CHECK: Punctuation: "{" [1:13 - 1:14] StructDecl=bonk:1:8 (Definition)
35*f4a2713aSLionel Sambuc // CHECK: Punctuation: "}" [1:15 - 1:16] StructDecl=bonk:1:8 (Definition)
36*f4a2713aSLionel Sambuc // CHECK: Punctuation: ";" [1:16 - 1:17]
37*f4a2713aSLionel Sambuc // CHECK: Keyword: "void" [2:1 - 2:5] FunctionDecl=test:2:6 (Definition)
38*f4a2713aSLionel Sambuc // CHECK: Identifier: "test" [2:6 - 2:10] FunctionDecl=test:2:6 (Definition)
39*f4a2713aSLionel Sambuc // CHECK: Punctuation: "(" [2:10 - 2:11] FunctionDecl=test:2:6 (Definition)
40*f4a2713aSLionel Sambuc // CHECK: Identifier: "bonk" [2:11 - 2:15] TypeRef=struct bonk:1:8
41*f4a2713aSLionel Sambuc // CHECK: Identifier: "X" [2:16 - 2:17] ParmDecl=X:2:16 (Definition)
42*f4a2713aSLionel Sambuc // CHECK: Punctuation: ")" [2:17 - 2:18] FunctionDecl=test:2:6 (Definition)
43*f4a2713aSLionel Sambuc // CHECK: Punctuation: "{" [2:19 - 2:20] CompoundStmt=
44*f4a2713aSLionel Sambuc // CHECK: Identifier: "X" [3:5 - 3:6] DeclRefExpr=X:2:16
45*f4a2713aSLionel Sambuc // CHECK: Punctuation: "=" [3:7 - 3:8] DeclRefExpr=operator=:1:8
46*f4a2713aSLionel Sambuc // CHECK: Identifier: "X" [3:9 - 3:10] DeclRefExpr=X:2:16
47*f4a2713aSLionel Sambuc // CHECK: Punctuation: ";" [3:10 - 3:11] CompoundStmt=
48*f4a2713aSLionel Sambuc // CHECK: Keyword: "__is_base_of" [4:5 - 4:17] UnexposedExpr=
49*f4a2713aSLionel Sambuc // CHECK: Punctuation: "(" [4:17 - 4:18] UnexposedExpr=
50*f4a2713aSLionel Sambuc // CHECK: Identifier: "bonk" [4:18 - 4:22] TypeRef=struct bonk:1:8
51*f4a2713aSLionel Sambuc // CHECK: Punctuation: "," [4:22 - 4:23] UnexposedExpr=
52*f4a2713aSLionel Sambuc // CHECK: Identifier: "bonk" [4:24 - 4:28] TypeRef=struct bonk:1:8
53*f4a2713aSLionel Sambuc // CHECK: Punctuation: ")" [4:28 - 4:29] UnexposedExpr=
54*f4a2713aSLionel Sambuc // CHECK: Punctuation: ";" [4:29 - 4:30] CompoundStmt=
55*f4a2713aSLionel Sambuc // CHECK: Punctuation: "}" [5:1 - 5:2] CompoundStmt=
56*f4a2713aSLionel Sambuc // CHECK: Keyword: "struct" [7:1 - 7:7] StructDecl=X:7:8 (Definition)
57*f4a2713aSLionel Sambuc // CHECK: Identifier: "X" [7:8 - 7:9] StructDecl=X:7:8 (Definition)
58*f4a2713aSLionel Sambuc // CHECK: Punctuation: "{" [7:10 - 7:11] StructDecl=X:7:8 (Definition)
59*f4a2713aSLionel Sambuc // CHECK: Identifier: "X" [8:3 - 8:4] TypeRef=struct X:7:8
60*f4a2713aSLionel Sambuc // CHECK: Keyword: "operator" [8:5 - 8:13] CXXMethod=operator++:8:5
61*f4a2713aSLionel Sambuc // CHECK: Punctuation: "++" [8:13 - 8:15] CXXMethod=operator++:8:5
62*f4a2713aSLionel Sambuc // CHECK: Punctuation: "(" [8:15 - 8:16] CXXMethod=operator++:8:5
63*f4a2713aSLionel Sambuc // CHECK: Punctuation: ")" [8:16 - 8:17] CXXMethod=operator++:8:5
64*f4a2713aSLionel Sambuc // CHECK: Punctuation: ";" [8:17 - 8:18] StructDecl=X:7:8 (Definition)
65*f4a2713aSLionel Sambuc // CHECK: Identifier: "X" [9:3 - 9:4] TypeRef=struct X:7:8
66*f4a2713aSLionel Sambuc // CHECK: Keyword: "operator" [9:5 - 9:13] CXXMethod=operator++:9:5
67*f4a2713aSLionel Sambuc // CHECK: Punctuation: "++" [9:13 - 9:15] CXXMethod=operator++:9:5
68*f4a2713aSLionel Sambuc // CHECK: Punctuation: "(" [9:15 - 9:16] CXXMethod=operator++:9:5
69*f4a2713aSLionel Sambuc // CHECK: Keyword: "int" [9:16 - 9:19] ParmDecl=:9:19 (Definition)
70*f4a2713aSLionel Sambuc // CHECK: Punctuation: ")" [9:19 - 9:20] ParmDecl=:9:19 (Definition)
71*f4a2713aSLionel Sambuc // CHECK: Punctuation: ";" [9:20 - 9:21] StructDecl=X:7:8 (Definition)
72*f4a2713aSLionel Sambuc // CHECK: Punctuation: "}" [10:1 - 10:2] StructDecl=X:7:8 (Definition)
73*f4a2713aSLionel Sambuc // CHECK: Punctuation: ";" [10:2 - 10:3]
74*f4a2713aSLionel Sambuc // CHECK: Keyword: "void" [11:1 - 11:5] FunctionDecl=test2:11:6 (Definition)
75*f4a2713aSLionel Sambuc // CHECK: Identifier: "test2" [11:6 - 11:11] FunctionDecl=test2:11:6 (Definition)
76*f4a2713aSLionel Sambuc // CHECK: Punctuation: "(" [11:11 - 11:12] FunctionDecl=test2:11:6 (Definition)
77*f4a2713aSLionel Sambuc // CHECK: Identifier: "X" [11:12 - 11:13] TypeRef=struct X:7:8
78*f4a2713aSLionel Sambuc // CHECK: Identifier: "x" [11:14 - 11:15] ParmDecl=x:11:14 (Definition)
79*f4a2713aSLionel Sambuc // CHECK: Punctuation: ")" [11:15 - 11:16] FunctionDecl=test2:11:6 (Definition)
80*f4a2713aSLionel Sambuc // CHECK: Punctuation: "{" [11:17 - 11:18] CompoundStmt=
81*f4a2713aSLionel Sambuc // CHECK: Punctuation: "++" [12:3 - 12:5] CallExpr=operator++:8:5
82*f4a2713aSLionel Sambuc // CHECK: Punctuation: "(" [12:5 - 12:6] ParenExpr=
83*f4a2713aSLionel Sambuc // CHECK: Identifier: "x" [12:6 - 12:7] DeclRefExpr=x:11:14
84*f4a2713aSLionel Sambuc // CHECK: Punctuation: ")" [12:7 - 12:8] ParenExpr=
85*f4a2713aSLionel Sambuc // CHECK: Punctuation: ";" [12:8 - 12:9] CompoundStmt=
86*f4a2713aSLionel Sambuc // CHECK: Punctuation: "(" [13:3 - 13:4] ParenExpr=
87*f4a2713aSLionel Sambuc // CHECK: Identifier: "x" [13:4 - 13:5] DeclRefExpr=x:11:14
88*f4a2713aSLionel Sambuc // CHECK: Punctuation: ")" [13:5 - 13:6] ParenExpr=
89*f4a2713aSLionel Sambuc // CHECK: Punctuation: "++" [13:6 - 13:8] DeclRefExpr=operator++:9:5
90*f4a2713aSLionel Sambuc // CHECK: Punctuation: ";" [13:8 - 13:9] CompoundStmt=
91*f4a2713aSLionel Sambuc // CHECK: Punctuation: "}" [14:1 - 14:2] CompoundStmt=
92*f4a2713aSLionel Sambuc // CHECK: Keyword: "struct" [16:1 - 16:7] StructDecl=S1:16:8 (Definition)
93*f4a2713aSLionel Sambuc // CHECK: Identifier: "S1" [16:8 - 16:10] StructDecl=S1:16:8 (Definition)
94*f4a2713aSLionel Sambuc // CHECK: Punctuation: "{" [16:11 - 16:12] StructDecl=S1:16:8 (Definition)
95*f4a2713aSLionel Sambuc // CHECK: Keyword: "void" [16:13 - 16:17] CXXMethod=f:16:18
96*f4a2713aSLionel Sambuc // CHECK: Identifier: "f" [16:18 - 16:19] CXXMethod=f:16:18
97*f4a2713aSLionel Sambuc // CHECK: Punctuation: "(" [16:19 - 16:20] CXXMethod=f:16:18
98*f4a2713aSLionel Sambuc // CHECK: Punctuation: ")" [16:20 - 16:21] CXXMethod=f:16:18
99*f4a2713aSLionel Sambuc // CHECK: Punctuation: ";" [16:21 - 16:22] StructDecl=S1:16:8 (Definition)
100*f4a2713aSLionel Sambuc // CHECK: Punctuation: "}" [16:23 - 16:24] StructDecl=S1:16:8 (Definition)
101*f4a2713aSLionel Sambuc // CHECK: Punctuation: ";" [16:24 - 16:25]
102*f4a2713aSLionel Sambuc // CHECK: Keyword: "struct" [17:1 - 17:7] StructDecl=S2:17:8 (Definition)
103*f4a2713aSLionel Sambuc // CHECK: Identifier: "S2" [17:8 - 17:10] StructDecl=S2:17:8 (Definition)
104*f4a2713aSLionel Sambuc // CHECK: Punctuation: "{" [17:11 - 17:12] StructDecl=S2:17:8 (Definition)
105*f4a2713aSLionel Sambuc // CHECK: Identifier: "S1" [17:13 - 17:15] TypeRef=struct S1:16:8
106*f4a2713aSLionel Sambuc // CHECK: Punctuation: "*" [17:16 - 17:17] CXXMethod=operator->:17:17
107*f4a2713aSLionel Sambuc // CHECK: Keyword: "operator" [17:17 - 17:25] CXXMethod=operator->:17:17
108*f4a2713aSLionel Sambuc // CHECK: Punctuation: "->" [17:25 - 17:27] CXXMethod=operator->:17:17
109*f4a2713aSLionel Sambuc // CHECK: Punctuation: "(" [17:27 - 17:28] CXXMethod=operator->:17:17
110*f4a2713aSLionel Sambuc // CHECK: Punctuation: ")" [17:28 - 17:29] CXXMethod=operator->:17:17
111*f4a2713aSLionel Sambuc // CHECK: Punctuation: ";" [17:29 - 17:30] StructDecl=S2:17:8 (Definition)
112*f4a2713aSLionel Sambuc // CHECK: Punctuation: "}" [17:31 - 17:32] StructDecl=S2:17:8 (Definition)
113*f4a2713aSLionel Sambuc // CHECK: Punctuation: ";" [17:32 - 17:33]
114*f4a2713aSLionel Sambuc // CHECK: Keyword: "void" [18:1 - 18:5] FunctionDecl=test3:18:6 (Definition)
115*f4a2713aSLionel Sambuc // CHECK: Identifier: "test3" [18:6 - 18:11] FunctionDecl=test3:18:6 (Definition)
116*f4a2713aSLionel Sambuc // CHECK: Punctuation: "(" [18:11 - 18:12] FunctionDecl=test3:18:6 (Definition)
117*f4a2713aSLionel Sambuc // CHECK: Identifier: "S2" [18:12 - 18:14] TypeRef=struct S2:17:8
118*f4a2713aSLionel Sambuc // CHECK: Identifier: "s2" [18:15 - 18:17] ParmDecl=s2:18:15 (Definition)
119*f4a2713aSLionel Sambuc // CHECK: Punctuation: ")" [18:17 - 18:18] FunctionDecl=test3:18:6 (Definition)
120*f4a2713aSLionel Sambuc // CHECK: Punctuation: "{" [18:19 - 18:20] CompoundStmt=
121*f4a2713aSLionel Sambuc // CHECK: Identifier: "s2" [19:3 - 19:5] DeclRefExpr=s2:18:15
122*f4a2713aSLionel Sambuc // CHECK: Punctuation: "->" [19:5 - 19:7] DeclRefExpr=operator->:17:17
123*f4a2713aSLionel Sambuc // CHECK: Identifier: "f" [19:7 - 19:8] MemberRefExpr=f:16:18
124*f4a2713aSLionel Sambuc // CHECK: Punctuation: "(" [19:8 - 19:9] CallExpr=f:16:18
125*f4a2713aSLionel Sambuc // CHECK: Punctuation: ")" [19:9 - 19:10] CallExpr=f:16:18
126*f4a2713aSLionel Sambuc // CHECK: Punctuation: ";" [19:10 - 19:11] CompoundStmt=
127*f4a2713aSLionel Sambuc // CHECK: Identifier: "X" [20:3 - 20:4] TypeRef=struct X:7:8
128*f4a2713aSLionel Sambuc // CHECK: Identifier: "foo" [20:5 - 20:8] VarDecl=foo:20:5 (Definition)
129*f4a2713aSLionel Sambuc // CHECK: Punctuation: ";" [20:8 - 20:9] DeclStmt=
130*f4a2713aSLionel Sambuc // CHECK: Punctuation: "}" [21:1 - 21:2] CompoundStmt=
131*f4a2713aSLionel Sambuc // CHECK: Keyword: "template" [23:1 - 23:9] ClassTemplate=TS:24:8 (Definition)
132*f4a2713aSLionel Sambuc // CHECK: Punctuation: "<" [23:10 - 23:11] ClassTemplate=TS:24:8 (Definition)
133*f4a2713aSLionel Sambuc // CHECK: Keyword: "bool" [23:11 - 23:15] NonTypeTemplateParameter=tfn:23:18 (Definition)
134*f4a2713aSLionel Sambuc // CHECK: Punctuation: "(" [23:16 - 23:17] NonTypeTemplateParameter=tfn:23:18 (Definition)
135*f4a2713aSLionel Sambuc // CHECK: Punctuation: "*" [23:17 - 23:18] NonTypeTemplateParameter=tfn:23:18 (Definition)
136*f4a2713aSLionel Sambuc // CHECK: Identifier: "tfn" [23:18 - 23:21] NonTypeTemplateParameter=tfn:23:18 (Definition)
137*f4a2713aSLionel Sambuc // CHECK: Punctuation: ")" [23:21 - 23:22] NonTypeTemplateParameter=tfn:23:18 (Definition)
138*f4a2713aSLionel Sambuc // CHECK: Punctuation: "(" [23:22 - 23:23] NonTypeTemplateParameter=tfn:23:18 (Definition)
139*f4a2713aSLionel Sambuc // CHECK: Identifier: "X" [23:23 - 23:24] TypeRef=struct X:7:8
140*f4a2713aSLionel Sambuc // CHECK: Punctuation: "*" [23:24 - 23:25] ParmDecl=:23:25 (Definition)
141*f4a2713aSLionel Sambuc // CHECK: Punctuation: ")" [23:25 - 23:26] ParmDecl=:23:25 (Definition)
142*f4a2713aSLionel Sambuc // CHECK: Punctuation: ">" [23:26 - 23:27] ClassTemplate=TS:24:8 (Definition)
143*f4a2713aSLionel Sambuc // CHECK: Keyword: "struct" [24:1 - 24:7] ClassTemplate=TS:24:8 (Definition)
144*f4a2713aSLionel Sambuc // CHECK: Identifier: "TS" [24:8 - 24:10] ClassTemplate=TS:24:8 (Definition)
145*f4a2713aSLionel Sambuc // CHECK: Punctuation: "{" [24:11 - 24:12] ClassTemplate=TS:24:8 (Definition)
146*f4a2713aSLionel Sambuc // CHECK: Keyword: "void" [25:3 - 25:7] CXXMethod=foo:25:8
147*f4a2713aSLionel Sambuc // CHECK: Identifier: "foo" [25:8 - 25:11] CXXMethod=foo:25:8
148*f4a2713aSLionel Sambuc // CHECK: Punctuation: "(" [25:11 - 25:12] CXXMethod=foo:25:8
149*f4a2713aSLionel Sambuc // CHECK: Punctuation: ")" [25:12 - 25:13] CXXMethod=foo:25:8
150*f4a2713aSLionel Sambuc // CHECK: Punctuation: ";" [25:13 - 25:14] ClassTemplate=TS:24:8 (Definition)
151*f4a2713aSLionel Sambuc // CHECK: Punctuation: "}" [26:1 - 26:2] ClassTemplate=TS:24:8 (Definition)
152*f4a2713aSLionel Sambuc // CHECK: Punctuation: ";" [26:2 - 26:3]
153*f4a2713aSLionel Sambuc // CHECK: Keyword: "template" [28:1 - 28:9] CXXMethod=foo:29:15 (Definition)
154*f4a2713aSLionel Sambuc // CHECK: Punctuation: "<" [28:10 - 28:11] CXXMethod=foo:29:15 (Definition)
155*f4a2713aSLionel Sambuc // CHECK: Keyword: "bool" [28:11 - 28:15] NonTypeTemplateParameter=tfn:28:18 (Definition)
156*f4a2713aSLionel Sambuc // CHECK: Punctuation: "(" [28:16 - 28:17] NonTypeTemplateParameter=tfn:28:18 (Definition)
157*f4a2713aSLionel Sambuc // CHECK: Punctuation: "*" [28:17 - 28:18] NonTypeTemplateParameter=tfn:28:18 (Definition)
158*f4a2713aSLionel Sambuc // CHECK: Identifier: "tfn" [28:18 - 28:21] NonTypeTemplateParameter=tfn:28:18 (Definition)
159*f4a2713aSLionel Sambuc // CHECK: Punctuation: ")" [28:21 - 28:22] NonTypeTemplateParameter=tfn:28:18 (Definition)
160*f4a2713aSLionel Sambuc // CHECK: Punctuation: "(" [28:22 - 28:23] NonTypeTemplateParameter=tfn:28:18 (Definition)
161*f4a2713aSLionel Sambuc // CHECK: Identifier: "X" [28:23 - 28:24] TypeRef=struct X:7:8
162*f4a2713aSLionel Sambuc // CHECK: Punctuation: "*" [28:24 - 28:25] ParmDecl=:28:25 (Definition)
163*f4a2713aSLionel Sambuc // CHECK: Punctuation: ")" [28:25 - 28:26] ParmDecl=:28:25 (Definition)
164*f4a2713aSLionel Sambuc // CHECK: Punctuation: ">" [28:26 - 28:27] CXXMethod=foo:29:15 (Definition)
165*f4a2713aSLionel Sambuc // CHECK: Keyword: "void" [29:1 - 29:5] CXXMethod=foo:29:15 (Definition)
166*f4a2713aSLionel Sambuc // CHECK: Identifier: "TS" [29:6 - 29:8] TemplateRef=TS:24:8
167*f4a2713aSLionel Sambuc // CHECK: Punctuation: "<" [29:8 - 29:9] CXXMethod=foo:29:15 (Definition)
168*f4a2713aSLionel Sambuc // CHECK: Identifier: "tfn" [29:9 - 29:12] DeclRefExpr=tfn:28:18
169*f4a2713aSLionel Sambuc // CHECK: Punctuation: ">" [29:12 - 29:13] CXXMethod=foo:29:15 (Definition)
170*f4a2713aSLionel Sambuc // CHECK: Punctuation: "::" [29:13 - 29:15] CXXMethod=foo:29:15 (Definition)
171*f4a2713aSLionel Sambuc // CHECK: Identifier: "foo" [29:15 - 29:18] CXXMethod=foo:29:15 (Definition)
172*f4a2713aSLionel Sambuc // CHECK: Punctuation: "(" [29:18 - 29:19] CXXMethod=foo:29:15 (Definition)
173*f4a2713aSLionel Sambuc // CHECK: Punctuation: ")" [29:19 - 29:20] CXXMethod=foo:29:15 (Definition)
174*f4a2713aSLionel Sambuc // CHECK: Punctuation: "{" [29:21 - 29:22] CompoundStmt=
175*f4a2713aSLionel Sambuc // CHECK: Punctuation: "}" [29:22 - 29:23] CompoundStmt=
176