blob: 01a615f0e4cbe709d4cb0bc0f8ee03fc631836c3 [file] [log] [blame]
Douglas Gregor4ae8f292010-03-18 17:52:52 +00001#define NOTHING(X,Y)
2#define STILL_NOTHING NOTHING(honk,warble)
Douglas Gregor9f1e3ff2010-03-18 00:42:48 +00003#define BAR baz
Douglas Gregor48072312010-03-18 15:23:44 +00004#define WIBBLE(X, Y) X##Y
Douglas Gregor4ae8f292010-03-18 17:52:52 +00005NOTHING(more,junk) float WIBBLE(int, float);
6int BAR STILL_NOTHING;
Douglas Gregor9f1e3ff2010-03-18 00:42:48 +00007#include "foo.h"
Douglas Gregor4ae8f292010-03-18 17:52:52 +00008#undef BAR
Douglas Gregor9f1e3ff2010-03-18 00:42:48 +00009
Ted Kremenek3f404602010-08-14 01:14:06 +000010#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
Ted Kremenek23bc11f2010-08-14 02:50:46 +000021#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
Douglas Gregordd3e5542011-05-04 00:14:37 +000028#include "pragma-once.h"
29#include "guarded.h"
30
31// RUN: c-index-test -test-annotate-tokens=%s:2:1:30:1 -I%S/Inputs %s | FileCheck %s
Douglas Gregor9f1e3ff2010-03-18 00:42:48 +000032// CHECK: Punctuation: "#" [2:1 - 2:2] preprocessing directive=
33// CHECK: Identifier: "define" [2:2 - 2:8] preprocessing directive=
Douglas Gregor572feb22010-03-18 18:04:21 +000034// CHECK: Identifier: "STILL_NOTHING" [2:9 - 2:22] macro definition=STILL_NOTHING
Douglas Gregor4419b672010-10-21 06:10:04 +000035// CHECK: Identifier: "NOTHING" [2:23 - 2:30] macro definition=STILL_NOTHING
36// CHECK: Punctuation: "(" [2:30 - 2:31] macro definition=STILL_NOTHING
37// CHECK: Identifier: "honk" [2:31 - 2:35] macro definition=STILL_NOTHING
38// CHECK: Punctuation: "," [2:35 - 2:36] macro definition=STILL_NOTHING
39// CHECK: Identifier: "warble" [2:36 - 2:42] macro definition=STILL_NOTHING
40// CHECK: Punctuation: ")" [2:42 - 2:43] macro definition=STILL_NOTHING
Douglas Gregor4ae8f292010-03-18 17:52:52 +000041// CHECK: Punctuation: "#" [3:1 - 3:2] preprocessing directive=
42// CHECK: Identifier: "define" [3:2 - 3:8] preprocessing directive=
Douglas Gregor572feb22010-03-18 18:04:21 +000043// CHECK: Identifier: "BAR" [3:9 - 3:12] macro definition=BAR
Douglas Gregor4419b672010-10-21 06:10:04 +000044// CHECK: Identifier: "baz" [3:13 - 3:16] macro definition=BAR
Douglas Gregor4ae8f292010-03-18 17:52:52 +000045// CHECK: Punctuation: "#" [4:1 - 4:2] preprocessing directive=
46// CHECK: Identifier: "define" [4:2 - 4:8] preprocessing directive=
Douglas Gregor572feb22010-03-18 18:04:21 +000047// CHECK: Identifier: "WIBBLE" [4:9 - 4:15] macro definition=WIBBLE
Douglas Gregor4419b672010-10-21 06:10:04 +000048// CHECK: Punctuation: "(" [4:15 - 4:16] macro definition=WIBBLE
49// CHECK: Identifier: "X" [4:16 - 4:17] macro definition=WIBBLE
50// CHECK: Punctuation: "," [4:17 - 4:18] macro definition=WIBBLE
51// CHECK: Identifier: "Y" [4:19 - 4:20] macro definition=WIBBLE
52// CHECK: Punctuation: ")" [4:20 - 4:21] macro definition=WIBBLE
53// CHECK: Identifier: "X" [4:22 - 4:23] macro definition=WIBBLE
54// CHECK: Punctuation: "##" [4:23 - 4:25] macro definition=WIBBLE
55// CHECK: Identifier: "Y" [4:25 - 4:26] macro definition=WIBBLE
Douglas Gregorbf7efa22010-03-18 18:23:03 +000056// CHECK: Identifier: "NOTHING" [5:1 - 5:8] macro instantiation=NOTHING:1:9
Douglas Gregor4ae8f292010-03-18 17:52:52 +000057// CHECK: Punctuation: "(" [5:8 - 5:9]
58// CHECK: Identifier: "more" [5:9 - 5:13]
59// CHECK: Punctuation: "," [5:13 - 5:14]
60// CHECK: Identifier: "junk" [5:14 - 5:18]
61// CHECK: Punctuation: ")" [5:18 - 5:19]
62// CHECK: Keyword: "float" [5:20 - 5:25]
Douglas Gregorbf7efa22010-03-18 18:23:03 +000063// CHECK: Identifier: "WIBBLE" [5:26 - 5:32] macro instantiation=WIBBLE:4:9
Douglas Gregor4ae8f292010-03-18 17:52:52 +000064// CHECK: Punctuation: "(" [5:32 - 5:33]
65// CHECK: Keyword: "int" [5:33 - 5:36]
66// CHECK: Punctuation: "," [5:36 - 5:37]
67// CHECK: Keyword: "float" [5:38 - 5:43]
68// CHECK: Punctuation: ")" [5:43 - 5:44]
69// CHECK: Punctuation: ";" [5:44 - 5:45]
70// CHECK: Keyword: "int" [6:1 - 6:4]
Douglas Gregorbf7efa22010-03-18 18:23:03 +000071// CHECK: Identifier: "BAR" [6:5 - 6:8] macro instantiation=BAR:3:9
72// CHECK: Identifier: "STILL_NOTHING" [6:9 - 6:22] macro instantiation=STILL_NOTHING:2:9
Douglas Gregor4ae8f292010-03-18 17:52:52 +000073// CHECK: Punctuation: ";" [6:22 - 6:23]
Douglas Gregorecdcb882010-10-20 22:00:55 +000074// CHECK: Punctuation: "#" [7:1 - 7:2] inclusion directive=foo.h
Douglas Gregor4419b672010-10-21 06:10:04 +000075// CHECK: Identifier: "include" [7:2 - 7:9] inclusion directive=foo.h
76// CHECK: Literal: ""foo.h"" [7:10 - 7:17] inclusion directive=foo.h
Douglas Gregor4ae8f292010-03-18 17:52:52 +000077// CHECK: Punctuation: "#" [8:1 - 8:2] preprocessing directive=
78// CHECK: Identifier: "undef" [8:2 - 8:7] preprocessing directive=
79// CHECK: Identifier: "BAR" [8:8 - 8:11] preprocessing directive=
Ted Kremenek3f404602010-08-14 01:14:06 +000080// CHECK: Punctuation: "#" [10:1 - 10:2] preprocessing directive=
81// CHECK: Identifier: "define" [10:2 - 10:8] preprocessing directive=
82// CHECK: Identifier: "REVERSE_MACRO" [10:9 - 10:22] macro definition=REVERSE_MACRO
Douglas Gregor4419b672010-10-21 06:10:04 +000083// CHECK: Punctuation: "(" [10:22 - 10:23] macro definition=REVERSE_MACRO
84// CHECK: Identifier: "x" [10:23 - 10:24] macro definition=REVERSE_MACRO
85// CHECK: Punctuation: "," [10:24 - 10:25] macro definition=REVERSE_MACRO
86// CHECK: Identifier: "y" [10:25 - 10:26] macro definition=REVERSE_MACRO
87// CHECK: Punctuation: ")" [10:26 - 10:27] macro definition=REVERSE_MACRO
88// CHECK: Identifier: "y" [10:28 - 10:29] macro definition=REVERSE_MACRO
89// CHECK: Punctuation: "+" [10:30 - 10:31] macro definition=REVERSE_MACRO
90// CHECK: Identifier: "x" [10:32 - 10:33] macro definition=REVERSE_MACRO
Ted Kremenek3f404602010-08-14 01:14:06 +000091// CHECK: Punctuation: "#" [11:1 - 11:2] preprocessing directive=
92// CHECK: Identifier: "define" [11:2 - 11:8] preprocessing directive=
93// CHECK: Identifier: "TWICE_MACRO" [11:9 - 11:20] macro definition=TWICE_MACRO
Douglas Gregor4419b672010-10-21 06:10:04 +000094// CHECK: Punctuation: "(" [11:20 - 11:21] macro definition=TWICE_MACRO
95// CHECK: Identifier: "y" [11:21 - 11:22] macro definition=TWICE_MACRO
96// CHECK: Punctuation: ")" [11:22 - 11:23] macro definition=TWICE_MACRO
97// CHECK: Identifier: "y" [11:24 - 11:25] macro definition=TWICE_MACRO
98// CHECK: Punctuation: "+" [11:26 - 11:27] macro definition=TWICE_MACRO
99// CHECK: Identifier: "y" [11:28 - 11:29] macro definition=TWICE_MACRO
Ted Kremenek3f404602010-08-14 01:14:06 +0000100// CHECK: Keyword: "void" [13:1 - 13:5] FunctionDecl=test_macro_args:13:6 (Definition)
101// CHECK: Identifier: "test_macro_args" [13:6 - 13:21] FunctionDecl=test_macro_args:13:6 (Definition)
102// CHECK: Punctuation: "(" [13:21 - 13:22] FunctionDecl=test_macro_args:13:6 (Definition)
103// CHECK: Punctuation: ")" [13:22 - 13:23] FunctionDecl=test_macro_args:13:6 (Definition)
104// CHECK: Punctuation: "{" [13:24 - 13:25] UnexposedStmt=
105// CHECK: Keyword: "int" [14:3 - 14:6] VarDecl=z:14:7 (Definition)
106// CHECK: Identifier: "z" [14:7 - 14:8] VarDecl=z:14:7 (Definition)
107// CHECK: Punctuation: "=" [14:9 - 14:10] VarDecl=z:14:7 (Definition)
108// CHECK: Literal: "1" [14:11 - 14:12] UnexposedExpr=
109// CHECK: Punctuation: ";" [14:12 - 14:13] UnexposedStmt=
110// CHECK: Keyword: "int" [15:3 - 15:6] VarDecl=t:15:7 (Definition)
111// CHECK: Identifier: "t" [15:7 - 15:8] VarDecl=t:15:7 (Definition)
112// CHECK: Punctuation: "=" [15:9 - 15:10] VarDecl=t:15:7 (Definition)
113// CHECK: Literal: "2" [15:11 - 15:12] UnexposedExpr=
114// CHECK: Punctuation: ";" [15:12 - 15:13] UnexposedStmt=
115// CHECK: Keyword: "int" [16:3 - 16:6] VarDecl=k:16:7 (Definition)
116// CHECK: Identifier: "k" [16:7 - 16:8] VarDecl=k:16:7 (Definition)
117// CHECK: Punctuation: "=" [16:9 - 16:10] VarDecl=k:16:7 (Definition)
118// CHECK: Identifier: "REVERSE_MACRO" [16:11 - 16:24] macro instantiation=REVERSE_MACRO:10:9
119// CHECK: Punctuation: "(" [16:24 - 16:25] UnexposedStmt=
120// CHECK: Identifier: "t" [16:25 - 16:26] DeclRefExpr=t:15:7
121// CHECK: Punctuation: "," [16:26 - 16:27] UnexposedStmt=
122// CHECK: Identifier: "z" [16:27 - 16:28] DeclRefExpr=z:14:7
123// CHECK: Punctuation: ")" [16:28 - 16:29] UnexposedStmt=
124// CHECK: Punctuation: ";" [16:29 - 16:30] UnexposedStmt=
125// CHECK: Keyword: "int" [17:3 - 17:6] VarDecl=j:17:7 (Definition)
126// CHECK: Identifier: "j" [17:7 - 17:8] VarDecl=j:17:7 (Definition)
127// CHECK: Punctuation: "=" [17:9 - 17:10] VarDecl=j:17:7 (Definition)
128// CHECK: Identifier: "TWICE_MACRO" [17:11 - 17:22] macro instantiation=TWICE_MACRO:11:9
129// CHECK: Punctuation: "(" [17:22 - 17:23] UnexposedStmt=
130// CHECK: Identifier: "k" [17:23 - 17:24] DeclRefExpr=k:16:7
131// CHECK: Punctuation: "+" [17:25 - 17:26] UnexposedStmt=
132// CHECK: Identifier: "k" [17:27 - 17:28] DeclRefExpr=k:16:7
133// CHECK: Punctuation: ")" [17:28 - 17:29] UnexposedStmt=
134// CHECK: Punctuation: ";" [17:29 - 17:30] UnexposedStmt=
135// CHECK: Keyword: "int" [18:3 - 18:6] VarDecl=w:18:7 (Definition)
136// CHECK: Identifier: "w" [18:7 - 18:8] VarDecl=w:18:7 (Definition)
137// CHECK: Punctuation: "=" [18:9 - 18:10] VarDecl=w:18:7 (Definition)
138// CHECK: Identifier: "j" [18:11 - 18:12] DeclRefExpr=j:17:7
139// CHECK: Punctuation: "+" [18:13 - 18:14] UnexposedExpr=
140// CHECK: Identifier: "j" [18:15 - 18:16] DeclRefExpr=j:17:7
141// CHECK: Punctuation: ";" [18:16 - 18:17] UnexposedStmt=
142// CHECK: Punctuation: "}" [19:1 - 19:2] UnexposedStmt=
Ted Kremenek23bc11f2010-08-14 02:50:46 +0000143// CHECK: Punctuation: "#" [21:1 - 21:2] preprocessing directive=
144// CHECK: Identifier: "define" [21:2 - 21:8] preprocessing directive=
145// CHECK: Identifier: "fun_with_macro_bodies" [21:9 - 21:30] macro definition=fun_with_macro_bodies
Douglas Gregor4419b672010-10-21 06:10:04 +0000146// CHECK: Punctuation: "(" [21:30 - 21:31] macro definition=fun_with_macro_bodies
147// CHECK: Identifier: "x" [21:31 - 21:32] macro definition=fun_with_macro_bodies
148// CHECK: Punctuation: "," [21:32 - 21:33] macro definition=fun_with_macro_bodies
149// CHECK: Identifier: "y" [21:34 - 21:35] macro definition=fun_with_macro_bodies
150// CHECK: Punctuation: ")" [21:35 - 21:36] macro definition=fun_with_macro_bodies
151// CHECK: Keyword: "do" [21:37 - 21:39] macro definition=fun_with_macro_bodies
152// CHECK: Punctuation: "{" [21:40 - 21:41] macro definition=fun_with_macro_bodies
153// CHECK: Keyword: "if" [21:42 - 21:44] macro definition=fun_with_macro_bodies
154// CHECK: Punctuation: "(" [21:45 - 21:46] macro definition=fun_with_macro_bodies
155// CHECK: Identifier: "x" [21:46 - 21:47] macro definition=fun_with_macro_bodies
156// CHECK: Punctuation: ")" [21:47 - 21:48] macro definition=fun_with_macro_bodies
157// CHECK: Identifier: "y" [21:49 - 21:50] macro definition=fun_with_macro_bodies
158// CHECK: Punctuation: "}" [21:51 - 21:52] macro definition=fun_with_macro_bodies
159// CHECK: Keyword: "while" [21:53 - 21:58] macro definition=fun_with_macro_bodies
160// CHECK: Punctuation: "(" [21:59 - 21:60] macro definition=fun_with_macro_bodies
161// CHECK: Literal: "0" [21:60 - 21:61] macro definition=fun_with_macro_bodies
162// CHECK: Punctuation: ")" [21:61 - 21:62] macro definition=fun_with_macro_bodies
Ted Kremenek23bc11f2010-08-14 02:50:46 +0000163// CHECK: Keyword: "void" [23:1 - 23:5] FunctionDecl=test:23:6 (Definition)
164// CHECK: Identifier: "test" [23:6 - 23:10] FunctionDecl=test:23:6 (Definition)
165// CHECK: Punctuation: "(" [23:10 - 23:11] FunctionDecl=test:23:6 (Definition)
166// CHECK: Punctuation: ")" [23:11 - 23:12] FunctionDecl=test:23:6 (Definition)
167// CHECK: Punctuation: "{" [23:13 - 23:14] UnexposedStmt=
168// CHECK: Keyword: "int" [24:3 - 24:6] VarDecl=x:24:7 (Definition)
169// CHECK: Identifier: "x" [24:7 - 24:8] VarDecl=x:24:7 (Definition)
170// CHECK: Punctuation: "=" [24:9 - 24:10] VarDecl=x:24:7 (Definition)
171// CHECK: Literal: "10" [24:11 - 24:13] UnexposedExpr=
172// CHECK: Punctuation: ";" [24:13 - 24:14] UnexposedStmt=
173// CHECK: Identifier: "fun_with_macro_bodies" [25:3 - 25:24] macro instantiation=fun_with_macro_bodies:21:9
174// CHECK: Punctuation: "(" [25:24 - 25:25] UnexposedStmt=
175// CHECK: Identifier: "x" [25:25 - 25:26] DeclRefExpr=x:24:7
176// CHECK: Punctuation: "," [25:26 - 25:27] UnexposedStmt=
177// CHECK: Punctuation: "{" [25:28 - 25:29] UnexposedStmt=
178// CHECK: Keyword: "int" [25:30 - 25:33] UnexposedStmt=
Douglas Gregora9b06d42010-11-09 06:24:54 +0000179// CHECK: Identifier: "z" [25:34 - 25:35] VarDecl=z:25:34 (Definition)
Ted Kremenek23bc11f2010-08-14 02:50:46 +0000180// CHECK: Punctuation: "=" [25:36 - 25:37] UnexposedStmt=
181// CHECK: Identifier: "x" [25:38 - 25:39] DeclRefExpr=x:24:7
182// CHECK: Punctuation: ";" [25:39 - 25:40] UnexposedStmt=
183// CHECK: Punctuation: "++" [25:41 - 25:43] UnexposedExpr=
184// CHECK: Identifier: "z" [25:43 - 25:44] DeclRefExpr=z:25:3
185// CHECK: Punctuation: ";" [25:44 - 25:45] UnexposedStmt=
186// CHECK: Punctuation: "}" [25:46 - 25:47] UnexposedStmt=
187// CHECK: Punctuation: ")" [25:47 - 25:48] UnexposedStmt=
188// CHECK: Punctuation: ";" [25:48 - 25:49] UnexposedStmt=
189// CHECK: Punctuation: "}" [26:1 - 26:2] UnexposedStmt=
Douglas Gregordd3e5542011-05-04 00:14:37 +0000190// CHECK: {{28:1.*inclusion directive=pragma-once.h.*multi-include guarded}}
191// CHECK: {{29:1.*inclusion directive=guarded.h.*multi-include guarded}}