annotate-tokens.cpp 11 KB

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