annotate-tokens-pp.c revision ecdcb883cbc6bb4a2445dc6f02d58d9bdb54a0ed
1#define NOTHING(X,Y)
2#define STILL_NOTHING NOTHING(honk,warble)
3#define BAR baz
4#define WIBBLE(X, Y) X##Y
5NOTHING(more,junk) float WIBBLE(int, float);
6int BAR STILL_NOTHING;
7#include "foo.h"
8#undef BAR
9
10#define REVERSE_MACRO(x,y) y + x
11#define TWICE_MACRO(y) y + y
12
13void test_macro_args() {
14  int z = 1;
15  int t = 2;
16  int k = REVERSE_MACRO(t,z);
17  int j = TWICE_MACRO(k + k);
18  int w = j + j;
19}
20
21#define fun_with_macro_bodies(x, y) do { if (x) y } while (0)
22
23void test() {
24  int x = 10;
25  fun_with_macro_bodies(x, { int z = x; ++z; });
26}
27
28// RUN: c-index-test -test-annotate-tokens=%s:2:1:26:1 -I%S/Inputs %s | FileCheck %s
29// CHECK: Punctuation: "#" [2:1 - 2:2] preprocessing directive=
30// CHECK: Identifier: "define" [2:2 - 2:8] preprocessing directive=
31// CHECK: Identifier: "STILL_NOTHING" [2:9 - 2:22] macro definition=STILL_NOTHING
32// CHECK: Identifier: "NOTHING" [2:23 - 2:30] preprocessing directive=
33// CHECK: Punctuation: "(" [2:30 - 2:31] preprocessing directive=
34// CHECK: Identifier: "honk" [2:31 - 2:35] preprocessing directive=
35// CHECK: Punctuation: "," [2:35 - 2:36] preprocessing directive=
36// CHECK: Identifier: "warble" [2:36 - 2:42] preprocessing directive=
37// CHECK: Punctuation: ")" [2:42 - 2:43] preprocessing directive=
38// CHECK: Punctuation: "#" [3:1 - 3:2] preprocessing directive=
39// CHECK: Identifier: "define" [3:2 - 3:8] preprocessing directive=
40// CHECK: Identifier: "BAR" [3:9 - 3:12] macro definition=BAR
41// CHECK: Identifier: "baz" [3:13 - 3:16] preprocessing directive=
42// CHECK: Punctuation: "#" [4:1 - 4:2] preprocessing directive=
43// CHECK: Identifier: "define" [4:2 - 4:8] preprocessing directive=
44// CHECK: Identifier: "WIBBLE" [4:9 - 4:15] macro definition=WIBBLE
45// CHECK: Punctuation: "(" [4:15 - 4:16] preprocessing directive=
46// CHECK: Identifier: "X" [4:16 - 4:17] preprocessing directive=
47// CHECK: Punctuation: "," [4:17 - 4:18] preprocessing directive=
48// CHECK: Identifier: "Y" [4:19 - 4:20] preprocessing directive=
49// CHECK: Punctuation: ")" [4:20 - 4:21] preprocessing directive=
50// CHECK: Identifier: "X" [4:22 - 4:23] preprocessing directive=
51// CHECK: Punctuation: "##" [4:23 - 4:25] preprocessing directive=
52// CHECK: Identifier: "Y" [4:25 - 4:26] preprocessing directive=
53// CHECK: Identifier: "NOTHING" [5:1 - 5:8] macro instantiation=NOTHING:1:9
54// CHECK: Punctuation: "(" [5:8 - 5:9]
55// CHECK: Identifier: "more" [5:9 - 5:13]
56// CHECK: Punctuation: "," [5:13 - 5:14]
57// CHECK: Identifier: "junk" [5:14 - 5:18]
58// CHECK: Punctuation: ")" [5:18 - 5:19]
59// CHECK: Keyword: "float" [5:20 - 5:25]
60// CHECK: Identifier: "WIBBLE" [5:26 - 5:32] macro instantiation=WIBBLE:4:9
61// CHECK: Punctuation: "(" [5:32 - 5:33]
62// CHECK: Keyword: "int" [5:33 - 5:36]
63// CHECK: Punctuation: "," [5:36 - 5:37]
64// CHECK: Keyword: "float" [5:38 - 5:43]
65// CHECK: Punctuation: ")" [5:43 - 5:44]
66// CHECK: Punctuation: ";" [5:44 - 5:45]
67// CHECK: Keyword: "int" [6:1 - 6:4]
68// CHECK: Identifier: "BAR" [6:5 - 6:8] macro instantiation=BAR:3:9
69// CHECK: Identifier: "STILL_NOTHING" [6:9 - 6:22] macro instantiation=STILL_NOTHING:2:9
70// CHECK: Punctuation: ";" [6:22 - 6:23]
71// CHECK: Punctuation: "#" [7:1 - 7:2] inclusion directive=foo.h
72// CHECK: Identifier: "include" [7:2 - 7:9] preprocessing directive=
73// CHECK: Literal: ""foo.h"" [7:10 - 7:17] preprocessing directive=
74// CHECK: Punctuation: "#" [8:1 - 8:2] preprocessing directive=
75// CHECK: Identifier: "undef" [8:2 - 8:7] preprocessing directive=
76// CHECK: Identifier: "BAR" [8:8 - 8:11] preprocessing directive=
77// CHECK: Punctuation: "#" [10:1 - 10:2] preprocessing directive=
78// CHECK: Identifier: "define" [10:2 - 10:8] preprocessing directive=
79// CHECK: Identifier: "REVERSE_MACRO" [10:9 - 10:22] macro definition=REVERSE_MACRO
80// CHECK: Punctuation: "(" [10:22 - 10:23] preprocessing directive=
81// CHECK: Identifier: "x" [10:23 - 10:24] preprocessing directive=
82// CHECK: Punctuation: "," [10:24 - 10:25] preprocessing directive=
83// CHECK: Identifier: "y" [10:25 - 10:26] preprocessing directive=
84// CHECK: Punctuation: ")" [10:26 - 10:27] preprocessing directive=
85// CHECK: Identifier: "y" [10:28 - 10:29] preprocessing directive=
86// CHECK: Punctuation: "+" [10:30 - 10:31] preprocessing directive=
87// CHECK: Identifier: "x" [10:32 - 10:33] preprocessing directive=
88// CHECK: Punctuation: "#" [11:1 - 11:2] preprocessing directive=
89// CHECK: Identifier: "define" [11:2 - 11:8] preprocessing directive=
90// CHECK: Identifier: "TWICE_MACRO" [11:9 - 11:20] macro definition=TWICE_MACRO
91// CHECK: Punctuation: "(" [11:20 - 11:21] preprocessing directive=
92// CHECK: Identifier: "y" [11:21 - 11:22] preprocessing directive=
93// CHECK: Punctuation: ")" [11:22 - 11:23] preprocessing directive=
94// CHECK: Identifier: "y" [11:24 - 11:25] preprocessing directive=
95// CHECK: Punctuation: "+" [11:26 - 11:27] preprocessing directive=
96// CHECK: Identifier: "y" [11:28 - 11:29] preprocessing directive=
97// CHECK: Keyword: "void" [13:1 - 13:5] FunctionDecl=test_macro_args:13:6 (Definition)
98// CHECK: Identifier: "test_macro_args" [13:6 - 13:21] FunctionDecl=test_macro_args:13:6 (Definition)
99// CHECK: Punctuation: "(" [13:21 - 13:22] FunctionDecl=test_macro_args:13:6 (Definition)
100// CHECK: Punctuation: ")" [13:22 - 13:23] FunctionDecl=test_macro_args:13:6 (Definition)
101// CHECK: Punctuation: "{" [13:24 - 13:25] UnexposedStmt=
102// CHECK: Keyword: "int" [14:3 - 14:6] VarDecl=z:14:7 (Definition)
103// CHECK: Identifier: "z" [14:7 - 14:8] VarDecl=z:14:7 (Definition)
104// CHECK: Punctuation: "=" [14:9 - 14:10] VarDecl=z:14:7 (Definition)
105// CHECK: Literal: "1" [14:11 - 14:12] UnexposedExpr=
106// CHECK: Punctuation: ";" [14:12 - 14:13] UnexposedStmt=
107// CHECK: Keyword: "int" [15:3 - 15:6] VarDecl=t:15:7 (Definition)
108// CHECK: Identifier: "t" [15:7 - 15:8] VarDecl=t:15:7 (Definition)
109// CHECK: Punctuation: "=" [15:9 - 15:10] VarDecl=t:15:7 (Definition)
110// CHECK: Literal: "2" [15:11 - 15:12] UnexposedExpr=
111// CHECK: Punctuation: ";" [15:12 - 15:13] UnexposedStmt=
112// CHECK: Keyword: "int" [16:3 - 16:6] VarDecl=k:16:7 (Definition)
113// CHECK: Identifier: "k" [16:7 - 16:8] VarDecl=k:16:7 (Definition)
114// CHECK: Punctuation: "=" [16:9 - 16:10] VarDecl=k:16:7 (Definition)
115// CHECK: Identifier: "REVERSE_MACRO" [16:11 - 16:24] macro instantiation=REVERSE_MACRO:10:9
116// CHECK: Punctuation: "(" [16:24 - 16:25] UnexposedStmt=
117// CHECK: Identifier: "t" [16:25 - 16:26] DeclRefExpr=t:15:7
118// CHECK: Punctuation: "," [16:26 - 16:27] UnexposedStmt=
119// CHECK: Identifier: "z" [16:27 - 16:28] DeclRefExpr=z:14:7
120// CHECK: Punctuation: ")" [16:28 - 16:29] UnexposedStmt=
121// CHECK: Punctuation: ";" [16:29 - 16:30] UnexposedStmt=
122// CHECK: Keyword: "int" [17:3 - 17:6] VarDecl=j:17:7 (Definition)
123// CHECK: Identifier: "j" [17:7 - 17:8] VarDecl=j:17:7 (Definition)
124// CHECK: Punctuation: "=" [17:9 - 17:10] VarDecl=j:17:7 (Definition)
125// CHECK: Identifier: "TWICE_MACRO" [17:11 - 17:22] macro instantiation=TWICE_MACRO:11:9
126// CHECK: Punctuation: "(" [17:22 - 17:23] UnexposedStmt=
127// CHECK: Identifier: "k" [17:23 - 17:24] DeclRefExpr=k:16:7
128// CHECK: Punctuation: "+" [17:25 - 17:26] UnexposedStmt=
129// CHECK: Identifier: "k" [17:27 - 17:28] DeclRefExpr=k:16:7
130// CHECK: Punctuation: ")" [17:28 - 17:29] UnexposedStmt=
131// CHECK: Punctuation: ";" [17:29 - 17:30] UnexposedStmt=
132// CHECK: Keyword: "int" [18:3 - 18:6] VarDecl=w:18:7 (Definition)
133// CHECK: Identifier: "w" [18:7 - 18:8] VarDecl=w:18:7 (Definition)
134// CHECK: Punctuation: "=" [18:9 - 18:10] VarDecl=w:18:7 (Definition)
135// CHECK: Identifier: "j" [18:11 - 18:12] DeclRefExpr=j:17:7
136// CHECK: Punctuation: "+" [18:13 - 18:14] UnexposedExpr=
137// CHECK: Identifier: "j" [18:15 - 18:16] DeclRefExpr=j:17:7
138// CHECK: Punctuation: ";" [18:16 - 18:17] UnexposedStmt=
139// CHECK: Punctuation: "}" [19:1 - 19:2] UnexposedStmt=
140// CHECK: Punctuation: "#" [21:1 - 21:2] preprocessing directive=
141// CHECK: Identifier: "define" [21:2 - 21:8] preprocessing directive=
142// CHECK: Identifier: "fun_with_macro_bodies" [21:9 - 21:30] macro definition=fun_with_macro_bodies
143// CHECK: Punctuation: "(" [21:30 - 21:31] preprocessing directive=
144// CHECK: Identifier: "x" [21:31 - 21:32] preprocessing directive=
145// CHECK: Punctuation: "," [21:32 - 21:33] preprocessing directive=
146// CHECK: Identifier: "y" [21:34 - 21:35] preprocessing directive=
147// CHECK: Punctuation: ")" [21:35 - 21:36] preprocessing directive=
148// CHECK: Keyword: "do" [21:37 - 21:39] preprocessing directive=
149// CHECK: Punctuation: "{" [21:40 - 21:41] preprocessing directive=
150// CHECK: Keyword: "if" [21:42 - 21:44] preprocessing directive=
151// CHECK: Punctuation: "(" [21:45 - 21:46] preprocessing directive=
152// CHECK: Identifier: "x" [21:46 - 21:47] preprocessing directive=
153// CHECK: Punctuation: ")" [21:47 - 21:48] preprocessing directive=
154// CHECK: Identifier: "y" [21:49 - 21:50] preprocessing directive=
155// CHECK: Punctuation: "}" [21:51 - 21:52] preprocessing directive=
156// CHECK: Keyword: "while" [21:53 - 21:58] preprocessing directive=
157// CHECK: Punctuation: "(" [21:59 - 21:60] preprocessing directive=
158// CHECK: Literal: "0" [21:60 - 21:61] preprocessing directive=
159// CHECK: Punctuation: ")" [21:61 - 21:62] preprocessing directive=
160// CHECK: Keyword: "void" [23:1 - 23:5] FunctionDecl=test:23:6 (Definition)
161// CHECK: Identifier: "test" [23:6 - 23:10] FunctionDecl=test:23:6 (Definition)
162// CHECK: Punctuation: "(" [23:10 - 23:11] FunctionDecl=test:23:6 (Definition)
163// CHECK: Punctuation: ")" [23:11 - 23:12] FunctionDecl=test:23:6 (Definition)
164// CHECK: Punctuation: "{" [23:13 - 23:14] UnexposedStmt=
165// CHECK: Keyword: "int" [24:3 - 24:6] VarDecl=x:24:7 (Definition)
166// CHECK: Identifier: "x" [24:7 - 24:8] VarDecl=x:24:7 (Definition)
167// CHECK: Punctuation: "=" [24:9 - 24:10] VarDecl=x:24:7 (Definition)
168// CHECK: Literal: "10" [24:11 - 24:13] UnexposedExpr=
169// CHECK: Punctuation: ";" [24:13 - 24:14] UnexposedStmt=
170// CHECK: Identifier: "fun_with_macro_bodies" [25:3 - 25:24] macro instantiation=fun_with_macro_bodies:21:9
171// CHECK: Punctuation: "(" [25:24 - 25:25] UnexposedStmt=
172// CHECK: Identifier: "x" [25:25 - 25:26] DeclRefExpr=x:24:7
173// CHECK: Punctuation: "," [25:26 - 25:27] UnexposedStmt=
174// CHECK: Punctuation: "{" [25:28 - 25:29] UnexposedStmt=
175// CHECK: Keyword: "int" [25:30 - 25:33] UnexposedStmt=
176// CHECK: Identifier: "z" [25:34 - 25:35] VarDecl=z:25:3 (Definition)
177// CHECK: Punctuation: "=" [25:36 - 25:37] UnexposedStmt=
178// CHECK: Identifier: "x" [25:38 - 25:39] DeclRefExpr=x:24:7
179// CHECK: Punctuation: ";" [25:39 - 25:40] UnexposedStmt=
180// CHECK: Punctuation: "++" [25:41 - 25:43] UnexposedExpr=
181// CHECK: Identifier: "z" [25:43 - 25:44] DeclRefExpr=z:25:3
182// CHECK: Punctuation: ";" [25:44 - 25:45] UnexposedStmt=
183// CHECK: Punctuation: "}" [25:46 - 25:47] UnexposedStmt=
184// CHECK: Punctuation: ")" [25:47 - 25:48] UnexposedStmt=
185// CHECK: Punctuation: ";" [25:48 - 25:49] UnexposedStmt=
186// CHECK: Punctuation: "}" [26:1 - 26:2] UnexposedStmt=
187
188