annotate-tokens.c revision c7b5ed6da7410849b51ba9a9ea04d2cc7b720f48
12d098408c757270ad1ae36475ab8300ecc1d3bc6Greg Claytontypedef int T;
22d098408c757270ad1ae36475ab8300ecc1d3bc6Greg Claytonstruct X { int a, b; };
39de4dec874148d30cc1d4c498d38cd048a8164caGreg Claytonvoid f(void *ptr) {
49de4dec874148d30cc1d4c498d38cd048a8164caGreg Clayton  T* t_ptr = (T *)ptr;
59de4dec874148d30cc1d4c498d38cd048a8164caGreg Clayton  (void)sizeof(T);
69de4dec874148d30cc1d4c498d38cd048a8164caGreg Clayton  /* A comment */
79de4dec874148d30cc1d4c498d38cd048a8164caGreg Clayton  struct X x = (struct X){1, 2};
89de4dec874148d30cc1d4c498d38cd048a8164caGreg Clayton  void *xx = ptr ? : &x;
92d098408c757270ad1ae36475ab8300ecc1d3bc6Greg Clayton  const char * hello = "Hello";
109de4dec874148d30cc1d4c498d38cd048a8164caGreg Clayton}
119de4dec874148d30cc1d4c498d38cd048a8164caGreg Clayton
129de4dec874148d30cc1d4c498d38cd048a8164caGreg Claytontypedef int Int;
139de4dec874148d30cc1d4c498d38cd048a8164caGreg Claytonvoid g(int i, ...) {
149de4dec874148d30cc1d4c498d38cd048a8164caGreg Clayton  __builtin_va_list va;
159de4dec874148d30cc1d4c498d38cd048a8164caGreg Clayton  (void)__builtin_va_arg(va, Int);
169de4dec874148d30cc1d4c498d38cd048a8164caGreg Clayton  (void)__builtin_types_compatible_p(Int, Int);
179de4dec874148d30cc1d4c498d38cd048a8164caGreg Clayton
189de4dec874148d30cc1d4c498d38cd048a8164caGreg Clayton  struct X x = { 0, 0 };
199de4dec874148d30cc1d4c498d38cd048a8164caGreg Clayton  do {
209de4dec874148d30cc1d4c498d38cd048a8164caGreg Clayton    x.a++;
219de4dec874148d30cc1d4c498d38cd048a8164caGreg Clayton  } while (x.a < 10);
22aa08062b169a51f3334a662f14f5ea2c626b7d13Greg Clayton}
23ec1799a439c74497f64206b30d3e3c0e4e775317Greg Clayton
24aa08062b169a51f3334a662f14f5ea2c626b7d13Greg Clayton// RUN: c-index-test -test-annotate-tokens=%s:4:1:22:1 %s | FileCheck %s
25aa08062b169a51f3334a662f14f5ea2c626b7d13Greg Clayton// CHECK: Identifier: "T" [4:3 - 4:4] TypeRef=T:1:13
26aa08062b169a51f3334a662f14f5ea2c626b7d13Greg Clayton// CHECK: Punctuation: "*" [4:4 - 4:5] VarDecl=t_ptr:4:6 (Definition)
27aa08062b169a51f3334a662f14f5ea2c626b7d13Greg Clayton// CHECK: Identifier: "t_ptr" [4:6 - 4:11] VarDecl=t_ptr:4:6 (Definition)
28ec1799a439c74497f64206b30d3e3c0e4e775317Greg Clayton// CHECK: Punctuation: "=" [4:12 - 4:13] VarDecl=t_ptr:4:6 (Definition)
29ec1799a439c74497f64206b30d3e3c0e4e775317Greg Clayton// CHECK: Punctuation: "(" [4:14 - 4:15] UnexposedExpr=ptr:3:14
309de4dec874148d30cc1d4c498d38cd048a8164caGreg Clayton// CHECK: Identifier: "T" [4:15 - 4:16] TypeRef=T:1:13
319de4dec874148d30cc1d4c498d38cd048a8164caGreg Clayton// CHECK: Punctuation: "*" [4:17 - 4:18] UnexposedExpr=ptr:3:14
329de4dec874148d30cc1d4c498d38cd048a8164caGreg Clayton// CHECK: Punctuation: ")" [4:18 - 4:19] UnexposedExpr=ptr:3:14
339de4dec874148d30cc1d4c498d38cd048a8164caGreg Clayton// CHECK: Identifier: "ptr" [4:19 - 4:22] DeclRefExpr=ptr:3:14
34// CHECK: Punctuation: ";" [4:22 - 4:23] UnexposedStmt=
35// CHECK: Punctuation: "(" [5:3 - 5:4] UnexposedExpr=
36// CHECK: Keyword: "void" [5:4 - 5:8] UnexposedExpr=
37// CHECK: Punctuation: ")" [5:8 - 5:9] UnexposedExpr=
38// CHECK: Keyword: "sizeof" [5:9 - 5:15] UnexposedExpr=
39// CHECK: Punctuation: "(" [5:15 - 5:16] UnexposedExpr=
40// CHECK: Identifier: "T" [5:16 - 5:17] TypeRef=T:1:13
41// CHECK: Punctuation: ")" [5:17 - 5:18] UnexposedExpr=
42// CHECK: Punctuation: ";" [5:18 - 5:19] UnexposedStmt=
43// CHECK: Comment: "/* A comment */" [6:3 - 6:18] UnexposedStmt=
44// CHECK: Keyword: "struct" [7:3 - 7:9] UnexposedStmt=
45// CHECK: Identifier: "X" [7:10 - 7:11] TypeRef=struct X:2:8
46// CHECK: Identifier: "x" [7:12 - 7:13] VarDecl=x:7:12 (Definition)
47// CHECK: Punctuation: "=" [7:14 - 7:15] VarDecl=x:7:12 (Definition)
48// CHECK: Punctuation: "(" [7:16 - 7:17] UnexposedExpr=
49// CHECK: Keyword: "struct" [7:17 - 7:23] UnexposedExpr=
50// CHECK: Identifier: "X" [7:24 - 7:25] TypeRef=struct X:2:8
51// CHECK: Punctuation: ")" [7:25 - 7:26] UnexposedExpr=
52// CHECK: Punctuation: "{" [7:26 - 7:27] UnexposedExpr=
53// CHECK: Literal: "1" [7:27 - 7:28] UnexposedExpr=
54// CHECK: Punctuation: "," [7:28 - 7:29] UnexposedExpr=
55// CHECK: Literal: "2" [7:30 - 7:31] UnexposedExpr=
56// CHECK: Punctuation: "}" [7:31 - 7:32] UnexposedExpr=
57// CHECK: Punctuation: ";" [7:32 - 7:33] UnexposedStmt=
58// CHECK: Keyword: "void" [8:3 - 8:7] VarDecl=xx:8:9 (Definition)
59// CHECK: Punctuation: "*" [8:8 - 8:9] VarDecl=xx:8:9 (Definition)
60// CHECK: Identifier: "xx" [8:9 - 8:11] VarDecl=xx:8:9 (Definition)
61// CHECK: Punctuation: "=" [8:12 - 8:13] VarDecl=xx:8:9 (Definition)
62// CHECK: Identifier: "ptr" [8:14 - 8:17] DeclRefExpr=ptr:3:14
63// CHECK: Punctuation: "?" [8:18 - 8:19] UnexposedExpr=
64// CHECK: Punctuation: ":" [8:20 - 8:21] UnexposedExpr=
65// CHECK: Punctuation: "&" [8:22 - 8:23] UnexposedExpr=
66// CHECK: Identifier: "x" [8:23 - 8:24] DeclRefExpr=x:7:12
67// CHECK: Punctuation: ";" [8:24 - 8:25] UnexposedStmt=
68// CHECK: Keyword: "const" [9:3 - 9:8] UnexposedStmt=
69// CHECK: Keyword: "char" [9:9 - 9:13] VarDecl=hello:9:16 (Definition)
70// CHECK: Punctuation: "*" [9:14 - 9:15] VarDecl=hello:9:16 (Definition)
71// CHECK: Identifier: "hello" [9:16 - 9:21] VarDecl=hello:9:16 (Definition)
72// CHECK: Punctuation: "=" [9:22 - 9:23] VarDecl=hello:9:16 (Definition)
73// CHECK: Literal: ""Hello"" [9:24 - 9:31] UnexposedExpr=
74// CHECK: Punctuation: ";" [9:31 - 9:32] UnexposedStmt=
75// CHECK: Punctuation: "}" [10:1 - 10:2] UnexposedStmt=
76// CHECK: Keyword: "__builtin_va_arg" [15:9 - 15:25] UnexposedExpr=
77// CHECK: Identifier: "Int" [15:30 - 15:33] TypeRef=Int:12:13
78// CHECK: Keyword: "__builtin_types_compatible_p" [16:9 - 16:37] UnexposedExpr=
79// CHECK: Identifier: "Int" [16:38 - 16:41] TypeRef=Int:12:13
80// CHECK: Punctuation: "," [16:41 - 16:42] UnexposedExpr=
81// CHECK: Identifier: "Int" [16:43 - 16:46] TypeRef=Int:12:13
82// CHECK: Keyword: "struct" [18:3 - 18:9] UnexposedStmt=
83// CHECK: Identifier: "X" [18:10 - 18:11] TypeRef=struct X:2:8
84// CHECK: Identifier: "x" [18:12 - 18:13] VarDecl=x:18:12 (Definition)
85// CHECK: Keyword: "do" [19:3 - 19:5] UnexposedStmt=
86// CHECK: Identifier: "x" [20:5 - 20:6] DeclRefExpr=x:18:12
87// CHECK: Punctuation: "." [20:6 - 20:7] MemberRefExpr=a:2:16
88// CHECK: Identifier: "a" [20:7 - 20:8] MemberRefExpr=a:2:16
89// CHECK: Punctuation: "++" [20:8 - 20:10] UnexposedExpr=
90// CHECK: Punctuation: ";" [20:10 - 20:11] UnexposedStmt=
91// CHECK: Punctuation: "}" [21:3 - 21:4] UnexposedStmt=
92// CHECK: Keyword: "while" [21:5 - 21:10] UnexposedStmt=
93// CHECK: Punctuation: "(" [21:11 - 21:12] UnexposedStmt=
94// CHECK: Identifier: "x" [21:12 - 21:13] DeclRefExpr=x:18:12
95// CHECK: Punctuation: "." [21:13 - 21:14] MemberRefExpr=a:2:16
96// CHECK: Identifier: "a" [21:14 - 21:15] MemberRefExpr=a:2:16
97
98// RUN: c-index-test -test-annotate-tokens=%s:4:1:165:32 %s | FileCheck %s
99// RUN: c-index-test -test-annotate-tokens=%s:4:1:165:38 %s | FileCheck %s
100