annotate-tokens-pp.c revision 9b2a0ac970a077bdc0bf08c6c682f80ad733c892
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#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 32// CHECK: Punctuation: "#" [2:1 - 2:2] preprocessing directive= 33// CHECK: Identifier: "define" [2:2 - 2:8] preprocessing directive= 34// CHECK: Identifier: "STILL_NOTHING" [2:9 - 2:22] macro definition=STILL_NOTHING 35// 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 41// CHECK: Punctuation: "#" [3:1 - 3:2] preprocessing directive= 42// CHECK: Identifier: "define" [3:2 - 3:8] preprocessing directive= 43// CHECK: Identifier: "BAR" [3:9 - 3:12] macro definition=BAR 44// CHECK: Identifier: "baz" [3:13 - 3:16] macro definition=BAR 45// CHECK: Punctuation: "#" [4:1 - 4:2] preprocessing directive= 46// CHECK: Identifier: "define" [4:2 - 4:8] preprocessing directive= 47// CHECK: Identifier: "WIBBLE" [4:9 - 4:15] macro definition=WIBBLE 48// 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 56// CHECK: Identifier: "NOTHING" [5:1 - 5:8] macro expansion=NOTHING:1:9 57// 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] 63// CHECK: Identifier: "WIBBLE" [5:26 - 5:32] macro expansion=WIBBLE:4:9 64// 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] 71// CHECK: Identifier: "BAR" [6:5 - 6:8] macro expansion=BAR:3:9 72// CHECK: Identifier: "STILL_NOTHING" [6:9 - 6:22] macro expansion=STILL_NOTHING:2:9 73// CHECK: Punctuation: ";" [6:22 - 6:23] 74// CHECK: Punctuation: "#" [7:1 - 7:2] inclusion directive=foo.h 75// CHECK: Identifier: "include" [7:2 - 7:9] inclusion directive=foo.h 76// CHECK: Literal: ""foo.h"" [7:10 - 7:17] inclusion directive=foo.h 77// 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= 80// 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 83// 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 91// 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 94// 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 100// 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 expansion=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 expansion=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= 143// 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 146// 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 163// 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 expansion=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= 179// CHECK: Identifier: "z" [25:34 - 25:35] VarDecl=z:25:34 (Definition) 180// 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= 190// CHECK: {{28:1.*inclusion directive=pragma-once.h.*multi-include guarded}} 191// CHECK: {{29:1.*inclusion directive=guarded.h.*multi-include guarded}} 192