1 //===- BuildTreeTest.cpp --------------------------------------------------===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 // This file tests the syntax tree generation from the ClangAST.
11 //===----------------------------------------------------------------------===//
13 #include "TreeTestBase.h"
15 using namespace clang
;
16 using namespace clang::syntax
;
20 class BuildSyntaxTreeTest
: public SyntaxTreeTest
{
22 ::testing::AssertionResult
treeDumpEqual(StringRef Code
, StringRef Tree
) {
23 SCOPED_TRACE(llvm::join(GetParam().getCommandLineArgs(), " "));
25 auto *Root
= buildTree(Code
, GetParam());
26 auto ErrorOK
= errorOK(Code
);
29 auto Actual
= StringRef(Root
->dump(*TM
)).trim().str();
30 // EXPECT_EQ shows the diff between the two strings if they are different.
31 EXPECT_EQ(Tree
.trim().str(), Actual
);
32 if (Actual
!= Tree
.trim().str()) {
33 return ::testing::AssertionFailure();
35 return ::testing::AssertionSuccess();
38 ::testing::AssertionResult
39 treeDumpEqualOnAnnotations(StringRef CodeWithAnnotations
,
40 ArrayRef
<StringRef
> TreeDumps
) {
41 SCOPED_TRACE(llvm::join(GetParam().getCommandLineArgs(), " "));
43 auto AnnotatedCode
= llvm::Annotations(CodeWithAnnotations
);
44 auto *Root
= buildTree(AnnotatedCode
.code(), GetParam());
46 auto ErrorOK
= errorOK(AnnotatedCode
.code());
50 auto AnnotatedRanges
= AnnotatedCode
.ranges();
51 if (AnnotatedRanges
.size() != TreeDumps
.size()) {
52 return ::testing::AssertionFailure()
53 << "The number of annotated ranges in the source code is "
55 "to the number of their corresponding tree dumps.";
58 for (unsigned i
= 0; i
< AnnotatedRanges
.size(); i
++) {
59 auto *AnnotatedNode
= nodeByRange(AnnotatedRanges
[i
], Root
);
60 assert(AnnotatedNode
);
61 auto AnnotatedNodeDump
=
62 StringRef(AnnotatedNode
->dump(*TM
))
65 // EXPECT_EQ shows the diff between the two strings if they are different.
66 EXPECT_EQ(TreeDumps
[i
].trim().str(), AnnotatedNodeDump
)
67 << "Dumps diverged for the code:\n"
68 << AnnotatedCode
.code().slice(AnnotatedRanges
[i
].Begin
,
69 AnnotatedRanges
[i
].End
);
70 if (AnnotatedNodeDump
!= TreeDumps
[i
].trim().str())
73 return Failed
? ::testing::AssertionFailure()
74 : ::testing::AssertionSuccess();
78 ::testing::AssertionResult
errorOK(StringRef RawCode
) {
79 if (!RawCode
.contains("error-ok")) {
80 if (Diags
->getClient()->getNumErrors() != 0) {
81 return ::testing::AssertionFailure()
82 << "Source file has syntax errors (suppress with /*error-ok*/), "
83 "they were printed to the "
87 return ::testing::AssertionSuccess();
91 INSTANTIATE_TEST_SUITE_P(SyntaxTreeTests
, BuildSyntaxTreeTest
,
92 testing::ValuesIn(allTestClangConfigs()) );
94 TEST_P(BuildSyntaxTreeTest
, Simple
) {
95 EXPECT_TRUE(treeDumpEqual(
101 TranslationUnit Detached
104 | |-DeclaratorList Declarators
105 | | `-SimpleDeclarator ListElement
107 | | `-ParametersAndQualifiers
110 | `-CompoundStatement
115 |-DeclaratorList Declarators
116 | `-SimpleDeclarator ListElement
118 | `-ParametersAndQualifiers
127 TEST_P(BuildSyntaxTreeTest
, SimpleVariable
) {
128 EXPECT_TRUE(treeDumpEqual(
134 TranslationUnit Detached
137 | |-DeclaratorList Declarators
138 | | `-SimpleDeclarator ListElement
143 |-DeclaratorList Declarators
144 | `-SimpleDeclarator ListElement
147 | `-IntegerLiteralExpression
148 | `-'42' LiteralToken
153 TEST_P(BuildSyntaxTreeTest
, SimpleFunction
) {
154 EXPECT_TRUE(treeDumpEqual(
156 void foo(int a, int b) {}
159 TranslationUnit Detached
162 |-DeclaratorList Declarators
163 | `-SimpleDeclarator ListElement
165 | `-ParametersAndQualifiers
167 | |-ParameterDeclarationList Parameters
168 | | |-SimpleDeclaration ListElement
170 | | | `-DeclaratorList Declarators
171 | | | `-SimpleDeclarator ListElement
173 | | |-',' ListDelimiter
174 | | `-SimpleDeclaration ListElement
176 | | `-DeclaratorList Declarators
177 | | `-SimpleDeclarator ListElement
186 TEST_P(BuildSyntaxTreeTest
, Simple_BackslashInsideToken
) {
187 EXPECT_TRUE(treeDumpEqual(
193 TranslationUnit Detached
197 |-DeclaratorList Declarators
198 | `-SimpleDeclarator ListElement
204 TEST_P(BuildSyntaxTreeTest
, If
) {
205 EXPECT_TRUE(treeDumpEqualOnAnnotations(
209 [[if (1) {} else if (0) {}]]
213 IfStatement Statement
214 |-'if' IntroducerKeyword
216 |-ExpressionStatement Condition
217 | `-IntegerLiteralExpression Expression
220 `-CompoundStatement ThenStatement
225 IfStatement Statement
226 |-'if' IntroducerKeyword
228 |-ExpressionStatement Condition
229 | `-IntegerLiteralExpression Expression
232 |-CompoundStatement ThenStatement
236 `-IfStatement ElseStatement
237 |-'if' IntroducerKeyword
239 |-ExpressionStatement Condition
240 | `-IntegerLiteralExpression Expression
243 `-CompoundStatement ThenStatement
249 TEST_P(BuildSyntaxTreeTest
, IfDecl
) {
250 if (!GetParam().isCXX17OrLater()) {
253 EXPECT_TRUE(treeDumpEqualOnAnnotations(
256 [[if (int a = 5) {}]]
257 [[if (int a; a == 5) {}]]
261 IfStatement Statement
262 |-'if' IntroducerKeyword
264 |-DeclarationStatement Condition
265 | `-SimpleDeclaration
267 | `-DeclaratorList Declarators
268 | `-SimpleDeclarator ListElement
271 | `-IntegerLiteralExpression
274 `-CompoundStatement ThenStatement
279 IfStatement Statement
280 |-'if' IntroducerKeyword
282 |-DeclarationStatement
283 | |-SimpleDeclaration
285 | | `-DeclaratorList Declarators
286 | | `-SimpleDeclarator ListElement
289 |-ExpressionStatement Condition
290 | `-BinaryOperatorExpression Expression
291 | |-IdExpression LeftHandSide
292 | | `-UnqualifiedId UnqualifiedId
294 | |-'==' OperatorToken
295 | `-IntegerLiteralExpression RightHandSide
298 `-CompoundStatement ThenStatement
304 TEST_P(BuildSyntaxTreeTest
, For
) {
305 EXPECT_TRUE(treeDumpEqualOnAnnotations(
312 ForStatement Statement
313 |-'for' IntroducerKeyword
318 `-CompoundStatement BodyStatement
324 TEST_P(BuildSyntaxTreeTest
, RangeBasedFor
) {
325 if (!GetParam().isCXX11OrLater()) {
328 EXPECT_TRUE(treeDumpEqualOnAnnotations(
337 RangeBasedForStatement Statement
338 |-'for' IntroducerKeyword
342 | |-DeclaratorList Declarators
343 | | `-SimpleDeclarator ListElement
347 | `-UnqualifiedId UnqualifiedId
350 `-EmptyStatement BodyStatement
355 TEST_P(BuildSyntaxTreeTest
, DeclarationStatement
) {
356 EXPECT_TRUE(treeDumpEqualOnAnnotations(
363 DeclarationStatement Statement
366 | `-DeclaratorList Declarators
367 | `-SimpleDeclarator ListElement
370 | `-IntegerLiteralExpression
371 | `-'10' LiteralToken
376 TEST_P(BuildSyntaxTreeTest
, Switch
) {
377 EXPECT_TRUE(treeDumpEqualOnAnnotations(
387 SwitchStatement Statement
388 |-'switch' IntroducerKeyword
390 |-IntegerLiteralExpression
393 `-CompoundStatement BodyStatement
395 |-CaseStatement Statement
396 | |-'case' IntroducerKeyword
397 | |-IntegerLiteralExpression CaseValue
398 | | `-'0' LiteralToken
400 | `-DefaultStatement BodyStatement
401 | |-'default' IntroducerKeyword
403 | `-EmptyStatement BodyStatement
409 TEST_P(BuildSyntaxTreeTest
, While
) {
410 EXPECT_TRUE(treeDumpEqualOnAnnotations(
413 [[while (1) { continue; break; }]]
417 WhileStatement Statement
418 |-'while' IntroducerKeyword
420 |-IntegerLiteralExpression
423 `-CompoundStatement BodyStatement
425 |-ContinueStatement Statement
426 | |-'continue' IntroducerKeyword
428 |-BreakStatement Statement
429 | |-'break' IntroducerKeyword
435 TEST_P(BuildSyntaxTreeTest
, UnhandledStatement
) {
436 // Unhandled statements should end up as 'unknown statement'.
437 // This example uses a 'label statement', which does not yet have a syntax
439 EXPECT_TRUE(treeDumpEqualOnAnnotations(
446 UnknownStatement Statement
450 |-'return' IntroducerKeyword
451 |-IntegerLiteralExpression ReturnValue
452 | `-'100' LiteralToken
457 TEST_P(BuildSyntaxTreeTest
, Expressions
) {
458 // expressions should be wrapped in 'ExpressionStatement' when they appear
459 // in a statement position.
460 EXPECT_TRUE(treeDumpEqual(
464 if (1) test(); else test();
468 TranslationUnit Detached
471 |-DeclaratorList Declarators
472 | `-SimpleDeclarator ListElement
474 | `-ParametersAndQualifiers
479 |-ExpressionStatement Statement
480 | |-CallExpression Expression
481 | | |-IdExpression Callee
482 | | | `-UnqualifiedId UnqualifiedId
487 |-IfStatement Statement
488 | |-'if' IntroducerKeyword
490 | |-ExpressionStatement Condition
491 | | `-IntegerLiteralExpression Expression
492 | | `-'1' LiteralToken
494 | |-ExpressionStatement ThenStatement
495 | | |-CallExpression Expression
496 | | | |-IdExpression Callee
497 | | | | `-UnqualifiedId UnqualifiedId
499 | | | |-'(' OpenParen
500 | | | `-')' CloseParen
502 | |-'else' ElseKeyword
503 | `-ExpressionStatement ElseStatement
504 | |-CallExpression Expression
505 | | |-IdExpression Callee
506 | | | `-UnqualifiedId UnqualifiedId
515 TEST_P(BuildSyntaxTreeTest
, ConditionalOperator
) {
516 // FIXME: conditional expression is not modeled yet.
517 EXPECT_TRUE(treeDumpEqualOnAnnotations(
524 UnknownExpression Expression
525 |-IntegerLiteralExpression
529 `-IntegerLiteralExpression
534 TEST_P(BuildSyntaxTreeTest
, UnqualifiedId_Identifier
) {
535 EXPECT_TRUE(treeDumpEqualOnAnnotations(
542 IdExpression Expression
543 `-UnqualifiedId UnqualifiedId
548 TEST_P(BuildSyntaxTreeTest
, UnqualifiedId_OperatorFunctionId
) {
549 if (!GetParam().isCXX()) {
552 EXPECT_TRUE(treeDumpEqualOnAnnotations(
555 friend X operator+(const X&, const X&);
562 CallExpression Expression
563 |-IdExpression Callee
564 | `-UnqualifiedId UnqualifiedId
568 |-CallArguments Arguments
569 | |-IdExpression ListElement
570 | | `-UnqualifiedId UnqualifiedId
572 | |-',' ListDelimiter
573 | `-IdExpression ListElement
574 | `-UnqualifiedId UnqualifiedId
580 TEST_P(BuildSyntaxTreeTest
, UnqualifiedId_ConversionFunctionId
) {
581 if (!GetParam().isCXX()) {
584 EXPECT_TRUE(treeDumpEqualOnAnnotations(
590 [[x.operator int()]];
594 CallExpression Expression
595 |-MemberExpression Callee
596 | |-IdExpression Object
597 | | `-UnqualifiedId UnqualifiedId
600 | `-IdExpression Member
601 | `-UnqualifiedId UnqualifiedId
609 TEST_P(BuildSyntaxTreeTest
, UnqualifiedId_LiteralOperatorId
) {
610 if (!GetParam().isCXX11OrLater()) {
613 EXPECT_TRUE(treeDumpEqualOnAnnotations(
615 unsigned operator "" _w(char);
617 [[operator "" _w('1')]];
621 CallExpression Expression
622 |-IdExpression Callee
623 | `-UnqualifiedId UnqualifiedId
628 |-CallArguments Arguments
629 | `-CharacterLiteralExpression ListElement
630 | `-''1'' LiteralToken
635 TEST_P(BuildSyntaxTreeTest
, UnqualifiedId_Destructor
) {
636 if (!GetParam().isCXX()) {
639 EXPECT_TRUE(treeDumpEqualOnAnnotations(
647 CallExpression Expression
648 |-MemberExpression Callee
649 | |-IdExpression Object
650 | | `-UnqualifiedId UnqualifiedId
653 | `-IdExpression Member
654 | `-UnqualifiedId UnqualifiedId
662 TEST_P(BuildSyntaxTreeTest
, UnqualifiedId_DecltypeDestructor
) {
663 if (!GetParam().isCXX11OrLater()) {
666 EXPECT_TRUE(treeDumpEqualOnAnnotations(
670 // FIXME: Make `decltype(x)` a child of `MemberExpression`. It is currently
671 // not because `Expr::getSourceRange()` returns the range of `x.~` for the
672 // `MemberExpr` instead of the expected `x.~decltype(x)`, this is a bug in
674 [[x.~decltype(x)()]];
678 CallExpression Expression
679 |-MemberExpression Callee
680 | |-IdExpression Object
681 | | `-UnqualifiedId UnqualifiedId
684 | `-IdExpression Member
685 | `-UnqualifiedId UnqualifiedId
696 TEST_P(BuildSyntaxTreeTest
, UnqualifiedId_TemplateId
) {
697 if (!GetParam().isCXX()) {
700 EXPECT_TRUE(treeDumpEqualOnAnnotations(
709 CallExpression Expression
710 |-IdExpression Callee
711 | `-UnqualifiedId UnqualifiedId
721 TEST_P(BuildSyntaxTreeTest
, QualifiedId_NamespaceSpecifier
) {
722 if (!GetParam().isCXX()) {
725 EXPECT_TRUE(treeDumpEqualOnAnnotations(
737 |-NestedNameSpecifier
738 | |-'::' ListDelimiter
739 | |-IdentifierNameSpecifier ListElement
741 | `-'::' ListDelimiter
743 `-DeclaratorList Declarators
744 `-SimpleDeclarator ListElement
749 |-NestedNameSpecifier
750 | |-IdentifierNameSpecifier ListElement
752 | `-'::' ListDelimiter
754 `-DeclaratorList Declarators
755 `-SimpleDeclarator ListElement
760 TEST_P(BuildSyntaxTreeTest
, QualifiedId_TemplateSpecifier
) {
761 if (!GetParam().isCXX()) {
764 EXPECT_TRUE(treeDumpEqualOnAnnotations(
771 [[::template ST<int>::S s1]];
777 |-NestedNameSpecifier
778 | |-'::' ListDelimiter
779 | |-SimpleTemplateNameSpecifier ListElement
785 | `-'::' ListDelimiter
787 `-DeclaratorList Declarators
788 `-SimpleDeclarator ListElement
793 |-NestedNameSpecifier
794 | |-'::' ListDelimiter
795 | |-SimpleTemplateNameSpecifier ListElement
800 | `-'::' ListDelimiter
802 `-DeclaratorList Declarators
803 `-SimpleDeclarator ListElement
808 TEST_P(BuildSyntaxTreeTest
, QualifiedId_DecltypeSpecifier
) {
809 if (!GetParam().isCXX11OrLater()) {
812 EXPECT_TRUE(treeDumpEqualOnAnnotations(
818 [[decltype(s)::f()]];
822 CallExpression Expression
823 |-IdExpression Callee
824 | |-NestedNameSpecifier Qualifier
825 | | |-DecltypeNameSpecifier ListElement
829 | | | | `-UnqualifiedId UnqualifiedId
832 | | `-'::' ListDelimiter
833 | `-UnqualifiedId UnqualifiedId
840 TEST_P(BuildSyntaxTreeTest
, QualifiedId_OptionalTemplateKw
) {
841 if (!GetParam().isCXX()) {
844 EXPECT_TRUE(treeDumpEqualOnAnnotations(
852 [[S::template f<int>()]];
856 CallExpression Expression
857 |-IdExpression Callee
858 | |-NestedNameSpecifier Qualifier
859 | | |-IdentifierNameSpecifier ListElement
861 | | `-'::' ListDelimiter
862 | `-UnqualifiedId UnqualifiedId
871 CallExpression Expression
872 |-IdExpression Callee
873 | |-NestedNameSpecifier Qualifier
874 | | |-IdentifierNameSpecifier ListElement
876 | | `-'::' ListDelimiter
877 | |-'template' TemplateKeyword
878 | `-UnqualifiedId UnqualifiedId
888 TEST_P(BuildSyntaxTreeTest
, QualifiedId_Complex
) {
889 if (!GetParam().isCXX()) {
892 EXPECT_TRUE(treeDumpEqualOnAnnotations(
902 [[::n::template ST<int>::template f<int>()]];
906 CallExpression Expression
907 |-IdExpression Callee
908 | |-NestedNameSpecifier Qualifier
909 | | |-'::' ListDelimiter
910 | | |-IdentifierNameSpecifier ListElement
912 | | |-'::' ListDelimiter
913 | | |-SimpleTemplateNameSpecifier ListElement
919 | | `-'::' ListDelimiter
920 | |-'template' TemplateKeyword
921 | `-UnqualifiedId UnqualifiedId
931 TEST_P(BuildSyntaxTreeTest
, QualifiedId_DependentType
) {
932 if (!GetParam().isCXX()) {
935 if (GetParam().hasDelayedTemplateParsing()) {
936 // FIXME: Make this test work on Windows by generating the expected syntax
937 // tree when `-fdelayed-template-parsing` is active.
940 EXPECT_TRUE(treeDumpEqualOnAnnotations(
942 template <typename T>
944 [[T::template U<int>::f()]];
946 [[T::template f<0>()]];
950 CallExpression Expression
951 |-IdExpression Callee
952 | |-NestedNameSpecifier Qualifier
953 | | |-IdentifierNameSpecifier ListElement
955 | | |-'::' ListDelimiter
956 | | |-SimpleTemplateNameSpecifier ListElement
962 | | `-'::' ListDelimiter
963 | `-UnqualifiedId UnqualifiedId
969 CallExpression Expression
970 |-IdExpression Callee
971 | |-NestedNameSpecifier Qualifier
972 | | |-IdentifierNameSpecifier ListElement
974 | | |-'::' ListDelimiter
975 | | |-IdentifierNameSpecifier ListElement
977 | | `-'::' ListDelimiter
978 | `-UnqualifiedId UnqualifiedId
984 CallExpression Expression
985 |-IdExpression Callee
986 | |-NestedNameSpecifier Qualifier
987 | | |-IdentifierNameSpecifier ListElement
989 | | `-'::' ListDelimiter
990 | |-'template' TemplateKeyword
991 | `-UnqualifiedId UnqualifiedId
994 | |-IntegerLiteralExpression
995 | | `-'0' LiteralToken
1002 TEST_P(BuildSyntaxTreeTest
, This_Simple
) {
1003 if (!GetParam().isCXX()) {
1006 EXPECT_TRUE(treeDumpEqualOnAnnotations(
1015 ThisExpression ReturnValue
1016 `-'this' IntroducerKeyword
1020 TEST_P(BuildSyntaxTreeTest
, This_ExplicitMemberAccess
) {
1021 if (!GetParam().isCXX()) {
1024 EXPECT_TRUE(treeDumpEqualOnAnnotations(
1034 MemberExpression Expression
1035 |-ThisExpression Object
1036 | `-'this' IntroducerKeyword
1038 `-IdExpression Member
1039 `-UnqualifiedId UnqualifiedId
1044 TEST_P(BuildSyntaxTreeTest
, This_ImplicitMemberAccess
) {
1045 if (!GetParam().isCXX()) {
1048 EXPECT_TRUE(treeDumpEqualOnAnnotations(
1058 IdExpression Expression
1059 `-UnqualifiedId UnqualifiedId
1064 TEST_P(BuildSyntaxTreeTest
, ParenExpr
) {
1065 EXPECT_TRUE(treeDumpEqualOnAnnotations(
1074 ParenExpression Expression
1076 |-IntegerLiteralExpression SubExpression
1077 | `-'1' LiteralToken
1081 ParenExpression Expression
1083 |-ParenExpression SubExpression
1085 | |-IntegerLiteralExpression SubExpression
1086 | | `-'1' LiteralToken
1091 ParenExpression Expression
1093 |-BinaryOperatorExpression SubExpression
1094 | |-IntegerLiteralExpression LeftHandSide
1095 | | `-'1' LiteralToken
1096 | |-'+' OperatorToken
1097 | `-ParenExpression RightHandSide
1099 | |-IntegerLiteralExpression SubExpression
1100 | | `-'2' LiteralToken
1106 TEST_P(BuildSyntaxTreeTest
, UserDefinedLiteral_Char
) {
1107 if (!GetParam().isCXX11OrLater()) {
1110 EXPECT_TRUE(treeDumpEqualOnAnnotations(
1112 unsigned operator "" _c(char);
1118 CharUserDefinedLiteralExpression Expression
1119 `-''2'_c' LiteralToken
1123 TEST_P(BuildSyntaxTreeTest
, UserDefinedLiteral_String
) {
1124 if (!GetParam().isCXX11OrLater()) {
1127 EXPECT_TRUE(treeDumpEqualOnAnnotations(
1129 typedef decltype(sizeof(void *)) size_t;
1131 unsigned operator "" _s(const char*, size_t);
1138 StringUserDefinedLiteralExpression Expression
1139 `-'"12"_s' LiteralToken
1143 TEST_P(BuildSyntaxTreeTest
, UserDefinedLiteral_Integer
) {
1144 if (!GetParam().isCXX11OrLater()) {
1147 EXPECT_TRUE(treeDumpEqualOnAnnotations(
1149 unsigned operator "" _i(unsigned long long);
1150 unsigned operator "" _r(const char*);
1152 unsigned operator "" _t();
1161 IntegerUserDefinedLiteralExpression Expression
1162 `-'12_i' LiteralToken
1165 IntegerUserDefinedLiteralExpression Expression
1166 `-'12_r' LiteralToken
1169 IntegerUserDefinedLiteralExpression Expression
1170 `-'12_t' LiteralToken
1174 TEST_P(BuildSyntaxTreeTest
, UserDefinedLiteral_Float
) {
1175 if (!GetParam().isCXX11OrLater()) {
1178 EXPECT_TRUE(treeDumpEqualOnAnnotations(
1180 unsigned operator "" _f(long double);
1181 unsigned operator "" _r(const char*);
1183 unsigned operator "" _t();
1192 FloatUserDefinedLiteralExpression Expression
1193 `-'1.2_f' LiteralToken
1196 FloatUserDefinedLiteralExpression Expression
1197 `-'1.2_r' LiteralToken
1200 FloatUserDefinedLiteralExpression Expression
1201 `-'1.2_t' LiteralToken
1205 TEST_P(BuildSyntaxTreeTest
, IntegerLiteral_LongLong
) {
1206 if (!GetParam().isCXX11OrLater()) {
1209 EXPECT_TRUE(treeDumpEqualOnAnnotations(
1217 IntegerLiteralExpression Expression
1218 `-'12ll' LiteralToken
1221 IntegerLiteralExpression Expression
1222 `-'12ull' LiteralToken
1226 TEST_P(BuildSyntaxTreeTest
, IntegerLiteral_Binary
) {
1227 if (!GetParam().isCXX14OrLater()) {
1230 EXPECT_TRUE(treeDumpEqualOnAnnotations(
1237 IntegerLiteralExpression Expression
1238 `-'0b1100' LiteralToken
1242 TEST_P(BuildSyntaxTreeTest
, IntegerLiteral_WithDigitSeparators
) {
1243 if (!GetParam().isCXX14OrLater()) {
1246 EXPECT_TRUE(treeDumpEqualOnAnnotations(
1253 IntegerLiteralExpression Expression
1254 `-'1'2'0ull' LiteralToken
1258 TEST_P(BuildSyntaxTreeTest
, CharacterLiteral
) {
1259 EXPECT_TRUE(treeDumpEqualOnAnnotations(
1271 CharacterLiteralExpression Expression
1272 `-''a'' LiteralToken
1275 CharacterLiteralExpression Expression
1276 `-''\n'' LiteralToken
1279 CharacterLiteralExpression Expression
1280 `-''\x20'' LiteralToken
1283 CharacterLiteralExpression Expression
1284 `-''\0'' LiteralToken
1287 CharacterLiteralExpression Expression
1288 `-'L'a'' LiteralToken
1291 CharacterLiteralExpression Expression
1292 `-'L'α'' LiteralToken
1296 TEST_P(BuildSyntaxTreeTest
, CharacterLiteral_Utf
) {
1297 if (!GetParam().isCXX11OrLater()) {
1300 EXPECT_TRUE(treeDumpEqualOnAnnotations(
1310 CharacterLiteralExpression Expression
1311 `-'u'a'' LiteralToken
1314 CharacterLiteralExpression Expression
1315 `-'u'構'' LiteralToken
1318 CharacterLiteralExpression Expression
1319 `-'U'a'' LiteralToken
1322 CharacterLiteralExpression Expression
1323 `-'U'🌲'' LiteralToken
1327 TEST_P(BuildSyntaxTreeTest
, CharacterLiteral_Utf8
) {
1328 if (!GetParam().isCXX17OrLater()) {
1331 EXPECT_TRUE(treeDumpEqualOnAnnotations(
1339 CharacterLiteralExpression Expression
1340 `-'u8'a'' LiteralToken
1343 CharacterLiteralExpression Expression
1344 `-'u8'\x7f'' LiteralToken
1348 TEST_P(BuildSyntaxTreeTest
, FloatingLiteral
) {
1349 EXPECT_TRUE(treeDumpEqualOnAnnotations(
1359 FloatingLiteralExpression Expression
1360 `-'1e-2' LiteralToken
1363 FloatingLiteralExpression Expression
1367 FloatingLiteralExpression Expression
1371 FloatingLiteralExpression Expression
1372 `-'2.f' LiteralToken
1376 TEST_P(BuildSyntaxTreeTest
, FloatingLiteral_Hexadecimal
) {
1377 if (!GetParam().isCXX17OrLater()) {
1380 EXPECT_TRUE(treeDumpEqualOnAnnotations(
1390 FloatingLiteralExpression Expression
1391 `-'0xfp1' LiteralToken
1394 FloatingLiteralExpression Expression
1395 `-'0xf.p1' LiteralToken
1398 FloatingLiteralExpression Expression
1399 `-'0x.fp1' LiteralToken
1402 FloatingLiteralExpression Expression
1403 `-'0xf.fp1f' LiteralToken
1407 TEST_P(BuildSyntaxTreeTest
, StringLiteral
) {
1408 EXPECT_TRUE(treeDumpEqualOnAnnotations(
1416 StringLiteralExpression Expression
1417 `-'"a
\n\
0\x20"' LiteralToken
1420 StringLiteralExpression Expression
1421 `-'L"αβ
"' LiteralToken
1425 TEST_P(BuildSyntaxTreeTest
, StringLiteral_Utf
) {
1426 if (!GetParam().isCXX11OrLater()) {
1429 EXPECT_TRUE(treeDumpEqualOnAnnotations(
1433 [[u"C
++抽象構文木
"]];
1438 StringLiteralExpression Expression
1439 `-'u8"a
\x1f\x05"' LiteralToken
1442 StringLiteralExpression Expression
1443 `-'u"C
++抽象構文木
"' LiteralToken
1446 StringLiteralExpression Expression
1447 `-'U"📖🌲
\n"' LiteralToken
1451 TEST_P(BuildSyntaxTreeTest
, StringLiteral_Raw
) {
1452 if (!GetParam().isCXX11OrLater()) {
1455 // This test uses regular string literals instead of raw string literals to
1456 // hold source code and expected output because of a bug in MSVC up to MSVC
1458 // https://developercommunity.visualstudio.com/content/problem/67300/stringifying-raw-string-literal.html
1459 EXPECT_TRUE(treeDumpEqual( //
1462 " Hello \"Syntax\" \\\"\n"
1465 "TranslationUnit Detached\n"
1466 "`-SimpleDeclaration\n"
1468 " |-DeclaratorList Declarators\n"
1469 " | `-SimpleDeclarator ListElement\n"
1471 " | `-ParametersAndQualifiers\n"
1472 " | |-'(' OpenParen\n"
1473 " | `-')' CloseParen\n"
1474 " `-CompoundStatement\n"
1475 " |-'{' OpenParen\n"
1476 " |-ExpressionStatement Statement\n"
1477 " | |-StringLiteralExpression Expression\n"
1478 " | | `-'R\"SyntaxTree(\n"
1479 " Hello \"Syntax\" \\\"\n"
1480 " )SyntaxTree\"' LiteralToken\n"
1482 " `-'}' CloseParen\n"));
1485 TEST_P(BuildSyntaxTreeTest
, BoolLiteral
) {
1486 if (GetParam().isC()) {
1489 EXPECT_TRUE(treeDumpEqualOnAnnotations(
1497 BoolLiteralExpression Expression
1498 `-'true' LiteralToken
1501 BoolLiteralExpression Expression
1502 `-'false' LiteralToken
1506 TEST_P(BuildSyntaxTreeTest
, CxxNullPtrLiteral
) {
1507 if (!GetParam().isCXX11OrLater()) {
1510 EXPECT_TRUE(treeDumpEqualOnAnnotations(
1517 CxxNullPtrExpression Expression
1518 `-'nullptr' LiteralToken
1522 TEST_P(BuildSyntaxTreeTest
, PostfixUnaryOperator
) {
1523 EXPECT_TRUE(treeDumpEqualOnAnnotations(
1531 PostfixUnaryOperatorExpression Expression
1532 |-IdExpression Operand
1533 | `-UnqualifiedId UnqualifiedId
1535 `-'++' OperatorToken
1538 PostfixUnaryOperatorExpression Expression
1539 |-IdExpression Operand
1540 | `-UnqualifiedId UnqualifiedId
1542 `-'--' OperatorToken
1546 TEST_P(BuildSyntaxTreeTest
, PrefixUnaryOperator
) {
1547 EXPECT_TRUE(treeDumpEqualOnAnnotations(
1549 void test(int a, int *ap) {
1557 [[__real a]]; [[__imag a]];
1561 PrefixUnaryOperatorExpression Expression
1562 |-'--' OperatorToken
1563 `-IdExpression Operand
1564 `-UnqualifiedId UnqualifiedId
1568 PrefixUnaryOperatorExpression Expression
1569 |-'++' OperatorToken
1570 `-IdExpression Operand
1571 `-UnqualifiedId UnqualifiedId
1575 PrefixUnaryOperatorExpression Expression
1577 `-IdExpression Operand
1578 `-UnqualifiedId UnqualifiedId
1582 PrefixUnaryOperatorExpression Expression
1584 `-IdExpression Operand
1585 `-UnqualifiedId UnqualifiedId
1589 PrefixUnaryOperatorExpression Expression
1591 `-IdExpression Operand
1592 `-UnqualifiedId UnqualifiedId
1596 PrefixUnaryOperatorExpression Expression
1598 `-IdExpression Operand
1599 `-UnqualifiedId UnqualifiedId
1603 PrefixUnaryOperatorExpression Expression
1605 `-IdExpression Operand
1606 `-UnqualifiedId UnqualifiedId
1610 PrefixUnaryOperatorExpression Expression
1612 `-IdExpression Operand
1613 `-UnqualifiedId UnqualifiedId
1617 PrefixUnaryOperatorExpression Expression
1618 |-'__real' OperatorToken
1619 `-IdExpression Operand
1620 `-UnqualifiedId UnqualifiedId
1624 PrefixUnaryOperatorExpression Expression
1625 |-'__imag' OperatorToken
1626 `-IdExpression Operand
1627 `-UnqualifiedId UnqualifiedId
1632 TEST_P(BuildSyntaxTreeTest
, PrefixUnaryOperatorCxx
) {
1633 if (!GetParam().isCXX()) {
1636 EXPECT_TRUE(treeDumpEqualOnAnnotations(
1638 void test(int a, bool b) {
1644 PrefixUnaryOperatorExpression Expression
1645 |-'compl' OperatorToken
1646 `-IdExpression Operand
1647 `-UnqualifiedId UnqualifiedId
1651 PrefixUnaryOperatorExpression Expression
1652 |-'not' OperatorToken
1653 `-IdExpression Operand
1654 `-UnqualifiedId UnqualifiedId
1659 TEST_P(BuildSyntaxTreeTest
, BinaryOperator
) {
1660 EXPECT_TRUE(treeDumpEqualOnAnnotations(
1673 BinaryOperatorExpression Expression
1674 |-IntegerLiteralExpression LeftHandSide
1675 | `-'1' LiteralToken
1677 `-IntegerLiteralExpression RightHandSide
1681 BinaryOperatorExpression Expression
1682 |-IntegerLiteralExpression LeftHandSide
1683 | `-'1' LiteralToken
1684 |-'==' OperatorToken
1685 `-IntegerLiteralExpression RightHandSide
1689 BinaryOperatorExpression Expression
1690 |-IdExpression LeftHandSide
1691 | `-UnqualifiedId UnqualifiedId
1694 `-IntegerLiteralExpression RightHandSide
1698 BinaryOperatorExpression Expression
1699 |-IdExpression LeftHandSide
1700 | `-UnqualifiedId UnqualifiedId
1702 |-'<<=' OperatorToken
1703 `-IntegerLiteralExpression RightHandSide
1707 BinaryOperatorExpression Expression
1708 |-IntegerLiteralExpression LeftHandSide
1709 | `-'1' LiteralToken
1710 |-'||' OperatorToken
1711 `-IntegerLiteralExpression RightHandSide
1715 BinaryOperatorExpression Expression
1716 |-IntegerLiteralExpression LeftHandSide
1717 | `-'1' LiteralToken
1719 `-IntegerLiteralExpression RightHandSide
1723 BinaryOperatorExpression Expression
1724 |-IdExpression LeftHandSide
1725 | `-UnqualifiedId UnqualifiedId
1727 |-'!=' OperatorToken
1728 `-IntegerLiteralExpression RightHandSide
1733 TEST_P(BuildSyntaxTreeTest
, BinaryOperatorCxx
) {
1734 if (!GetParam().isCXX()) {
1737 EXPECT_TRUE(treeDumpEqualOnAnnotations(
1747 BinaryOperatorExpression Expression
1748 |-BoolLiteralExpression LeftHandSide
1749 | `-'true' LiteralToken
1750 |-'||' OperatorToken
1751 `-BoolLiteralExpression RightHandSide
1752 `-'false' LiteralToken
1755 BinaryOperatorExpression Expression
1756 |-BoolLiteralExpression LeftHandSide
1757 | `-'true' LiteralToken
1758 |-'or' OperatorToken
1759 `-BoolLiteralExpression RightHandSide
1760 `-'false' LiteralToken
1763 BinaryOperatorExpression Expression
1764 |-IntegerLiteralExpression LeftHandSide
1765 | `-'1' LiteralToken
1766 |-'bitand' OperatorToken
1767 `-IntegerLiteralExpression RightHandSide
1771 BinaryOperatorExpression Expression
1772 |-IdExpression LeftHandSide
1773 | `-UnqualifiedId UnqualifiedId
1775 |-'xor_eq' OperatorToken
1776 `-IntegerLiteralExpression RightHandSide
1781 TEST_P(BuildSyntaxTreeTest
, BinaryOperator_NestedWithParenthesis
) {
1782 EXPECT_TRUE(treeDumpEqualOnAnnotations(
1785 [[(1 + 2) * (4 / 2)]];
1789 BinaryOperatorExpression Expression
1790 |-ParenExpression LeftHandSide
1792 | |-BinaryOperatorExpression SubExpression
1793 | | |-IntegerLiteralExpression LeftHandSide
1794 | | | `-'1' LiteralToken
1795 | | |-'+' OperatorToken
1796 | | `-IntegerLiteralExpression RightHandSide
1797 | | `-'2' LiteralToken
1800 `-ParenExpression RightHandSide
1802 |-BinaryOperatorExpression SubExpression
1803 | |-IntegerLiteralExpression LeftHandSide
1804 | | `-'4' LiteralToken
1805 | |-'/' OperatorToken
1806 | `-IntegerLiteralExpression RightHandSide
1807 | `-'2' LiteralToken
1812 TEST_P(BuildSyntaxTreeTest
, BinaryOperator_Associativity
) {
1813 EXPECT_TRUE(treeDumpEqualOnAnnotations(
1815 void test(int a, int b) {
1821 BinaryOperatorExpression Expression
1822 |-BinaryOperatorExpression LeftHandSide
1823 | |-IdExpression LeftHandSide
1824 | | `-UnqualifiedId UnqualifiedId
1826 | |-'+' OperatorToken
1827 | `-IdExpression RightHandSide
1828 | `-UnqualifiedId UnqualifiedId
1831 `-IntegerLiteralExpression RightHandSide
1835 BinaryOperatorExpression Expression
1836 |-IdExpression LeftHandSide
1837 | `-UnqualifiedId UnqualifiedId
1840 `-BinaryOperatorExpression RightHandSide
1841 |-IdExpression LeftHandSide
1842 | `-UnqualifiedId UnqualifiedId
1845 `-IntegerLiteralExpression RightHandSide
1850 TEST_P(BuildSyntaxTreeTest
, BinaryOperator_Precedence
) {
1851 EXPECT_TRUE(treeDumpEqualOnAnnotations(
1859 BinaryOperatorExpression Expression
1860 |-BinaryOperatorExpression LeftHandSide
1861 | |-IntegerLiteralExpression LeftHandSide
1862 | | `-'1' LiteralToken
1863 | |-'+' OperatorToken
1864 | `-BinaryOperatorExpression RightHandSide
1865 | |-IntegerLiteralExpression LeftHandSide
1866 | | `-'2' LiteralToken
1867 | |-'*' OperatorToken
1868 | `-IntegerLiteralExpression RightHandSide
1869 | `-'3' LiteralToken
1871 `-IntegerLiteralExpression RightHandSide
1875 BinaryOperatorExpression Expression
1876 |-BinaryOperatorExpression LeftHandSide
1877 | |-IntegerLiteralExpression LeftHandSide
1878 | | `-'1' LiteralToken
1879 | |-'%' OperatorToken
1880 | `-IntegerLiteralExpression RightHandSide
1881 | `-'2' LiteralToken
1883 `-BinaryOperatorExpression RightHandSide
1884 |-IntegerLiteralExpression LeftHandSide
1885 | `-'3' LiteralToken
1887 `-IntegerLiteralExpression RightHandSide
1892 TEST_P(BuildSyntaxTreeTest
, OverloadedOperator_Assignment
) {
1893 if (!GetParam().isCXX()) {
1896 EXPECT_TRUE(treeDumpEqualOnAnnotations(
1899 X& operator=(const X&);
1901 void test(X x, X y) {
1906 BinaryOperatorExpression Expression
1907 |-IdExpression LeftHandSide
1908 | `-UnqualifiedId UnqualifiedId
1911 `-IdExpression RightHandSide
1912 `-UnqualifiedId UnqualifiedId
1917 TEST_P(BuildSyntaxTreeTest
, OverloadedOperator_Plus
) {
1918 if (!GetParam().isCXX()) {
1921 EXPECT_TRUE(treeDumpEqualOnAnnotations(
1924 friend X operator+(X, const X&);
1926 void test(X x, X y) {
1931 BinaryOperatorExpression Expression
1932 |-IdExpression LeftHandSide
1933 | `-UnqualifiedId UnqualifiedId
1936 `-IdExpression RightHandSide
1937 `-UnqualifiedId UnqualifiedId
1942 TEST_P(BuildSyntaxTreeTest
, OverloadedOperator_Less
) {
1943 if (!GetParam().isCXX()) {
1946 EXPECT_TRUE(treeDumpEqualOnAnnotations(
1949 friend bool operator<(const X&, const X&);
1951 void test(X x, X y) {
1956 BinaryOperatorExpression Expression
1957 |-IdExpression LeftHandSide
1958 | `-UnqualifiedId UnqualifiedId
1961 `-IdExpression RightHandSide
1962 `-UnqualifiedId UnqualifiedId
1967 TEST_P(BuildSyntaxTreeTest
, OverloadedOperator_LeftShift
) {
1968 if (!GetParam().isCXX()) {
1971 EXPECT_TRUE(treeDumpEqualOnAnnotations(
1974 friend X operator<<(X&, const X&);
1976 void test(X x, X y) {
1981 BinaryOperatorExpression Expression
1982 |-IdExpression LeftHandSide
1983 | `-UnqualifiedId UnqualifiedId
1985 |-'<<' OperatorToken
1986 `-IdExpression RightHandSide
1987 `-UnqualifiedId UnqualifiedId
1992 TEST_P(BuildSyntaxTreeTest
, OverloadedOperator_Comma
) {
1993 if (!GetParam().isCXX()) {
1996 EXPECT_TRUE(treeDumpEqualOnAnnotations(
2001 void test(X x, X y) {
2006 BinaryOperatorExpression Expression
2007 |-IdExpression LeftHandSide
2008 | `-UnqualifiedId UnqualifiedId
2011 `-IdExpression RightHandSide
2012 `-UnqualifiedId UnqualifiedId
2017 TEST_P(BuildSyntaxTreeTest
, OverloadedOperator_PointerToMember
) {
2018 if (!GetParam().isCXX()) {
2021 EXPECT_TRUE(treeDumpEqualOnAnnotations(
2026 void test(X* xp, int X::* pmi) {
2031 BinaryOperatorExpression Expression
2032 |-IdExpression LeftHandSide
2033 | `-UnqualifiedId UnqualifiedId
2035 |-'->*' OperatorToken
2036 `-IdExpression RightHandSide
2037 `-UnqualifiedId UnqualifiedId
2042 TEST_P(BuildSyntaxTreeTest
, OverloadedOperator_Negation
) {
2043 if (!GetParam().isCXX()) {
2046 EXPECT_TRUE(treeDumpEqualOnAnnotations(
2056 PrefixUnaryOperatorExpression Expression
2058 `-IdExpression Operand
2059 `-UnqualifiedId UnqualifiedId
2064 TEST_P(BuildSyntaxTreeTest
, OverloadedOperator_AddressOf
) {
2065 if (!GetParam().isCXX()) {
2068 EXPECT_TRUE(treeDumpEqualOnAnnotations(
2078 PrefixUnaryOperatorExpression Expression
2080 `-IdExpression Operand
2081 `-UnqualifiedId UnqualifiedId
2086 TEST_P(BuildSyntaxTreeTest
, OverloadedOperator_PrefixIncrement
) {
2087 if (!GetParam().isCXX()) {
2090 EXPECT_TRUE(treeDumpEqualOnAnnotations(
2100 PrefixUnaryOperatorExpression Expression
2101 |-'++' OperatorToken
2102 `-IdExpression Operand
2103 `-UnqualifiedId UnqualifiedId
2108 TEST_P(BuildSyntaxTreeTest
, OverloadedOperator_PostfixIncrement
) {
2109 if (!GetParam().isCXX()) {
2112 EXPECT_TRUE(treeDumpEqualOnAnnotations(
2122 PostfixUnaryOperatorExpression Expression
2123 |-IdExpression Operand
2124 | `-UnqualifiedId UnqualifiedId
2126 `-'++' OperatorToken
2130 TEST_P(BuildSyntaxTreeTest
, MemberExpression_SimpleWithDot
) {
2131 EXPECT_TRUE(treeDumpEqualOnAnnotations(
2136 void test(struct S s) {
2141 MemberExpression Expression
2142 |-IdExpression Object
2143 | `-UnqualifiedId UnqualifiedId
2146 `-IdExpression Member
2147 `-UnqualifiedId UnqualifiedId
2152 TEST_P(BuildSyntaxTreeTest
, MemberExpression_StaticDataMember
) {
2153 if (!GetParam().isCXX()) {
2156 EXPECT_TRUE(treeDumpEqualOnAnnotations(
2166 MemberExpression Expression
2167 |-IdExpression Object
2168 | `-UnqualifiedId UnqualifiedId
2171 `-IdExpression Member
2172 `-UnqualifiedId UnqualifiedId
2177 TEST_P(BuildSyntaxTreeTest
, MemberExpression_SimpleWithArrow
) {
2178 EXPECT_TRUE(treeDumpEqualOnAnnotations(
2183 void test(struct S* sp) {
2188 MemberExpression Expression
2189 |-IdExpression Object
2190 | `-UnqualifiedId UnqualifiedId
2193 `-IdExpression Member
2194 `-UnqualifiedId UnqualifiedId
2199 TEST_P(BuildSyntaxTreeTest
, MemberExpression_Chaining
) {
2200 EXPECT_TRUE(treeDumpEqualOnAnnotations(
2205 void test(struct S s){
2210 MemberExpression Expression
2211 |-MemberExpression Object
2212 | |-IdExpression Object
2213 | | `-UnqualifiedId UnqualifiedId
2216 | `-IdExpression Member
2217 | `-UnqualifiedId UnqualifiedId
2220 `-IdExpression Member
2221 `-UnqualifiedId UnqualifiedId
2226 TEST_P(BuildSyntaxTreeTest
, MemberExpression_OperatorFunction
) {
2227 if (!GetParam().isCXX()) {
2230 EXPECT_TRUE(treeDumpEqualOnAnnotations(
2240 CallExpression Expression
2241 |-MemberExpression Callee
2242 | |-IdExpression Object
2243 | | `-UnqualifiedId UnqualifiedId
2246 | `-IdExpression Member
2247 | `-UnqualifiedId UnqualifiedId
2255 TEST_P(BuildSyntaxTreeTest
, MemberExpression_VariableTemplate
) {
2256 if (!GetParam().isCXX14OrLater()) {
2259 EXPECT_TRUE(treeDumpEqualOnAnnotations(
2262 template<typename T>
2263 static constexpr T x = 42;
2265 // FIXME: `<int>` should be a child of `MemberExpression` and `;` of
2266 // `ExpressionStatement`. This is a bug in clang, in `getSourceRange` methods.
2274 |-ExpressionStatement Statement
2275 | `-MemberExpression Expression
2276 | |-IdExpression Object
2277 | | `-UnqualifiedId UnqualifiedId
2280 | `-IdExpression Member
2281 | `-UnqualifiedId UnqualifiedId
2291 TEST_P(BuildSyntaxTreeTest
, MemberExpression_FunctionTemplate
) {
2292 if (!GetParam().isCXX()) {
2295 EXPECT_TRUE(treeDumpEqualOnAnnotations(
2298 template<typename T>
2306 CallExpression Expression
2307 |-MemberExpression Callee
2308 | |-IdExpression Object
2309 | | `-UnqualifiedId UnqualifiedId
2311 | |-'->' AccessToken
2312 | `-IdExpression Member
2313 | `-UnqualifiedId UnqualifiedId
2323 TEST_P(BuildSyntaxTreeTest
,
2324 MemberExpression_FunctionTemplateWithTemplateKeyword
) {
2325 if (!GetParam().isCXX()) {
2328 EXPECT_TRUE(treeDumpEqualOnAnnotations(
2331 template<typename T>
2335 [[s.template f<int>()]];
2339 CallExpression Expression
2340 |-MemberExpression Callee
2341 | |-IdExpression Object
2342 | | `-UnqualifiedId UnqualifiedId
2346 | `-IdExpression Member
2347 | `-UnqualifiedId UnqualifiedId
2357 TEST_P(BuildSyntaxTreeTest
, MemberExpression_WithQualifier
) {
2358 if (!GetParam().isCXX()) {
2361 EXPECT_TRUE(treeDumpEqualOnAnnotations(
2366 struct S : public Base {};
2373 CallExpression Expression
2374 |-MemberExpression Callee
2375 | |-IdExpression Object
2376 | | `-UnqualifiedId UnqualifiedId
2379 | `-IdExpression Member
2380 | |-NestedNameSpecifier Qualifier
2381 | | |-IdentifierNameSpecifier ListElement
2383 | | `-'::' ListDelimiter
2384 | `-UnqualifiedId UnqualifiedId
2390 CallExpression Expression
2391 |-MemberExpression Callee
2392 | |-IdExpression Object
2393 | | `-UnqualifiedId UnqualifiedId
2396 | `-IdExpression Member
2397 | |-NestedNameSpecifier Qualifier
2398 | | |-'::' ListDelimiter
2399 | | |-IdentifierNameSpecifier ListElement
2401 | | `-'::' ListDelimiter
2402 | `-UnqualifiedId UnqualifiedId
2410 TEST_P(BuildSyntaxTreeTest
, MemberExpression_Complex
) {
2411 if (!GetParam().isCXX()) {
2414 EXPECT_TRUE(treeDumpEqualOnAnnotations(
2416 template<typename T>
2418 template<typename U>
2425 // FIXME: The first 'template' keyword is a child of `NestedNameSpecifier`,
2426 // but it should be a child of `MemberExpression` according to the grammar.
2427 // However one might argue that the 'template' keyword fits better inside
2428 // `NestedNameSpecifier` because if we change `U<int>` to `UI` we would like
2429 // equally to change the `NameSpecifier` `template U<int>` to just `UI`.
2430 [[sp->getU().template U<int>::template f<int>()]];
2434 CallExpression Expression
2435 |-MemberExpression Callee
2436 | |-CallExpression Object
2437 | | |-MemberExpression Callee
2438 | | | |-IdExpression Object
2439 | | | | `-UnqualifiedId UnqualifiedId
2441 | | | |-'->' AccessToken
2442 | | | `-IdExpression Member
2443 | | | `-UnqualifiedId UnqualifiedId
2446 | | `-')' CloseParen
2448 | `-IdExpression Member
2449 | |-NestedNameSpecifier Qualifier
2450 | | |-SimpleTemplateNameSpecifier ListElement
2456 | | `-'::' ListDelimiter
2457 | |-'template' TemplateKeyword
2458 | `-UnqualifiedId UnqualifiedId
2468 TEST_P(BuildSyntaxTreeTest
, CallExpression_Callee_Member
) {
2469 if (!GetParam().isCXX()) {
2472 EXPECT_TRUE(treeDumpEqualOnAnnotations(
2482 CallExpression Expression
2483 |-MemberExpression Callee
2484 | |-IdExpression Object
2485 | | `-UnqualifiedId UnqualifiedId
2488 | `-IdExpression Member
2489 | `-UnqualifiedId UnqualifiedId
2496 TEST_P(BuildSyntaxTreeTest
, CallExpression_Callee_OperatorParens
) {
2497 if (!GetParam().isCXX()) {
2500 EXPECT_TRUE(treeDumpEqualOnAnnotations(
2510 CallExpression Expression
2511 |-IdExpression Callee
2512 | `-UnqualifiedId UnqualifiedId
2519 TEST_P(BuildSyntaxTreeTest
, CallExpression_Callee_OperatorParensChaining
) {
2520 if (!GetParam().isCXX()) {
2523 EXPECT_TRUE(treeDumpEqualOnAnnotations(
2533 CallExpression Expression
2534 |-CallExpression Callee
2535 | |-IdExpression Callee
2536 | | `-UnqualifiedId UnqualifiedId
2545 TEST_P(BuildSyntaxTreeTest
, CallExpression_Callee_MemberWithThis
) {
2546 if (!GetParam().isCXX()) {
2549 EXPECT_TRUE(treeDumpEqualOnAnnotations(
2554 struct S: public Base {
2559 [[this->Base::f()]];
2564 CallExpression Expression
2565 |-MemberExpression Callee
2566 | |-ThisExpression Object
2567 | | `-'this' IntroducerKeyword
2568 | |-'->' AccessToken
2569 | `-IdExpression Member
2570 | `-UnqualifiedId UnqualifiedId
2576 CallExpression Expression
2577 |-IdExpression Callee
2578 | `-UnqualifiedId UnqualifiedId
2584 CallExpression Expression
2585 |-MemberExpression Callee
2586 | |-ThisExpression Object
2587 | | `-'this' IntroducerKeyword
2588 | |-'->' AccessToken
2589 | `-IdExpression Member
2590 | |-NestedNameSpecifier Qualifier
2591 | | |-IdentifierNameSpecifier ListElement
2593 | | `-'::' ListDelimiter
2594 | `-UnqualifiedId UnqualifiedId
2601 TEST_P(BuildSyntaxTreeTest
, CallExpression_Callee_FunctionPointer
) {
2602 if (!GetParam().isCXX()) {
2605 EXPECT_TRUE(treeDumpEqualOnAnnotations(
2614 CallExpression Expression
2615 |-IdExpression Callee
2616 | `-UnqualifiedId UnqualifiedId
2622 CallExpression Expression
2623 |-ParenExpression Callee
2625 | |-PrefixUnaryOperatorExpression SubExpression
2626 | | |-'*' OperatorToken
2627 | | `-IdExpression Operand
2628 | | `-UnqualifiedId UnqualifiedId
2636 TEST_P(BuildSyntaxTreeTest
, CallExpression_Callee_MemberFunctionPointer
) {
2637 if (!GetParam().isCXX()) {
2640 EXPECT_TRUE(treeDumpEqualOnAnnotations(
2652 CallExpression Expression
2653 |-ParenExpression Callee
2655 | |-BinaryOperatorExpression SubExpression
2656 | | |-IdExpression LeftHandSide
2657 | | | `-UnqualifiedId UnqualifiedId
2659 | | |-'.*' OperatorToken
2660 | | `-IdExpression RightHandSide
2661 | | `-UnqualifiedId UnqualifiedId
2669 TEST_P(BuildSyntaxTreeTest
, CallExpression_Arguments_Zero
) {
2670 if (!GetParam().isCXX()) {
2673 EXPECT_TRUE(treeDumpEqualOnAnnotations(
2681 ExpressionStatement Statement
2682 |-CallExpression Expression
2683 | |-IdExpression Callee
2684 | | `-UnqualifiedId UnqualifiedId
2692 TEST_P(BuildSyntaxTreeTest
, CallExpression_Arguments_One
) {
2693 if (!GetParam().isCXX()) {
2696 EXPECT_TRUE(treeDumpEqualOnAnnotations(
2704 ExpressionStatement Statement
2705 |-CallExpression Expression
2706 | |-IdExpression Callee
2707 | | `-UnqualifiedId UnqualifiedId
2710 | |-CallArguments Arguments
2711 | | `-IntegerLiteralExpression ListElement
2712 | | `-'1' LiteralToken
2718 TEST_P(BuildSyntaxTreeTest
, CallExpression_Arguments_Multiple
) {
2719 if (!GetParam().isCXX()) {
2722 EXPECT_TRUE(treeDumpEqualOnAnnotations(
2724 void f(int, char, float);
2730 ExpressionStatement Statement
2731 |-CallExpression Expression
2732 | |-IdExpression Callee
2733 | | `-UnqualifiedId UnqualifiedId
2736 | |-CallArguments Arguments
2737 | | |-IntegerLiteralExpression ListElement
2738 | | | `-'1' LiteralToken
2739 | | |-',' ListDelimiter
2740 | | |-CharacterLiteralExpression ListElement
2741 | | | `-''2'' LiteralToken
2742 | | |-',' ListDelimiter
2743 | | `-FloatingLiteralExpression ListElement
2744 | | `-'3.' LiteralToken
2750 TEST_P(BuildSyntaxTreeTest
, CallExpression_Arguments_Assignment
) {
2751 if (!GetParam().isCXX()) {
2754 EXPECT_TRUE(treeDumpEqualOnAnnotations(
2762 ExpressionStatement Statement
2763 |-CallExpression Expression
2764 | |-IdExpression Callee
2765 | | `-UnqualifiedId UnqualifiedId
2768 | |-CallArguments Arguments
2769 | | `-BinaryOperatorExpression ListElement
2770 | | |-IdExpression LeftHandSide
2771 | | | `-UnqualifiedId UnqualifiedId
2773 | | |-'=' OperatorToken
2774 | | `-IntegerLiteralExpression RightHandSide
2775 | | `-'1' LiteralToken
2781 TEST_P(BuildSyntaxTreeTest
, CallExpression_Arguments_BracedInitList_Empty
) {
2782 if (!GetParam().isCXX11OrLater()) {
2785 EXPECT_TRUE(treeDumpEqualOnAnnotations(
2793 ExpressionStatement Statement
2794 |-CallExpression Expression
2795 | |-IdExpression Callee
2796 | | `-UnqualifiedId UnqualifiedId
2799 | |-CallArguments Arguments
2800 | | `-UnknownExpression ListElement
2801 | | `-UnknownExpression
2809 TEST_P(BuildSyntaxTreeTest
, CallExpression_Arguments_BracedInitList_Simple
) {
2810 if (!GetParam().isCXX11OrLater()) {
2813 EXPECT_TRUE(treeDumpEqualOnAnnotations(
2826 ExpressionStatement Statement
2827 |-CallExpression Expression
2828 | |-IdExpression Callee
2829 | | `-UnqualifiedId UnqualifiedId
2832 | |-CallArguments Arguments
2833 | | `-UnknownExpression ListElement
2834 | | `-UnknownExpression
2836 | | |-IntegerLiteralExpression
2837 | | | `-'1' LiteralToken
2839 | | |-UnknownExpression
2840 | | | `-UnknownExpression
2849 TEST_P(BuildSyntaxTreeTest
,
2850 CallExpression_Arguments_BracedInitList_Designated
) {
2851 if (!GetParam().isCXX11OrLater()) {
2854 EXPECT_TRUE(treeDumpEqualOnAnnotations(
2863 [[f({.a = 1, .b {}});]]
2867 ExpressionStatement Statement
2868 |-CallExpression Expression
2869 | |-IdExpression Callee
2870 | | `-UnqualifiedId UnqualifiedId
2873 | |-CallArguments Arguments
2874 | | `-UnknownExpression ListElement
2875 | | `-UnknownExpression
2877 | | |-UnknownExpression
2881 | | | `-IntegerLiteralExpression
2882 | | | `-'1' LiteralToken
2884 | | |-UnknownExpression
2887 | | | `-UnknownExpression
2888 | | | `-UnknownExpression
2897 TEST_P(BuildSyntaxTreeTest
, CallExpression_Arguments_ParameterPack
) {
2898 if (!GetParam().isCXX11OrLater() || GetParam().hasDelayedTemplateParsing()) {
2901 EXPECT_TRUE(treeDumpEqualOnAnnotations(
2903 template<typename T, typename... Args>
2904 void test(T t, Args... args) {
2909 CallExpression Expression
2910 |-UnknownExpression Callee
2913 |-CallArguments Arguments
2914 | `-UnknownExpression ListElement
2916 | | `-UnqualifiedId UnqualifiedId
2923 TEST_P(BuildSyntaxTreeTest
, CallExpression_DefaultArguments
) {
2924 if (!GetParam().isCXX11OrLater()) {
2927 EXPECT_TRUE(treeDumpEqualOnAnnotations(
2929 void f(int i = 1, char c = '2');
2937 CallExpression Expression
2938 |-IdExpression Callee
2939 | `-UnqualifiedId UnqualifiedId
2945 CallExpression Expression
2946 |-IdExpression Callee
2947 | `-UnqualifiedId UnqualifiedId
2950 |-CallArguments Arguments
2951 | `-IntegerLiteralExpression ListElement
2952 | `-'1' LiteralToken
2956 CallExpression Expression
2957 |-IdExpression Callee
2958 | `-UnqualifiedId UnqualifiedId
2961 |-CallArguments Arguments
2962 | |-IntegerLiteralExpression ListElement
2963 | | `-'1' LiteralToken
2964 | |-',' ListDelimiter
2965 | `-CharacterLiteralExpression ListElement
2966 | `-''2'' LiteralToken
2971 TEST_P(BuildSyntaxTreeTest
, MultipleDeclaratorsGrouping
) {
2972 EXPECT_TRUE(treeDumpEqual(
2978 TranslationUnit Detached
2981 | |-DeclaratorList Declarators
2982 | | |-SimpleDeclarator ListElement
2985 | | |-',' ListDelimiter
2986 | | `-SimpleDeclarator ListElement
2991 |-DeclaratorList Declarators
2992 | |-SimpleDeclarator ListElement
2995 | |-',' ListDelimiter
2996 | `-SimpleDeclarator ListElement
3002 TEST_P(BuildSyntaxTreeTest
, MultipleDeclaratorsGroupingTypedef
) {
3003 EXPECT_TRUE(treeDumpEqual(
3008 TranslationUnit Detached
3012 |-DeclaratorList Declarators
3013 | |-SimpleDeclarator ListElement
3016 | |-',' ListDelimiter
3017 | `-SimpleDeclarator ListElement
3023 TEST_P(BuildSyntaxTreeTest
, MultipleDeclaratorsInsideStatement
) {
3024 EXPECT_TRUE(treeDumpEqual(
3028 typedef int *ta, tb;
3032 TranslationUnit Detached
3035 |-DeclaratorList Declarators
3036 | `-SimpleDeclarator ListElement
3038 | `-ParametersAndQualifiers
3043 |-DeclarationStatement Statement
3044 | |-SimpleDeclaration
3046 | | `-DeclaratorList Declarators
3047 | | |-SimpleDeclarator ListElement
3050 | | |-',' ListDelimiter
3051 | | `-SimpleDeclarator ListElement
3054 |-DeclarationStatement Statement
3055 | |-SimpleDeclaration
3058 | | `-DeclaratorList Declarators
3059 | | |-SimpleDeclarator ListElement
3062 | | |-',' ListDelimiter
3063 | | `-SimpleDeclarator ListElement
3070 TEST_P(BuildSyntaxTreeTest
, SizeTTypedef
) {
3071 if (!GetParam().isCXX11OrLater()) {
3074 EXPECT_TRUE(treeDumpEqual(
3076 typedef decltype(sizeof(void *)) size_t;
3079 TranslationUnit Detached
3091 |-DeclaratorList Declarators
3092 | `-SimpleDeclarator ListElement
3098 TEST_P(BuildSyntaxTreeTest
, Namespace_Nested
) {
3099 if (!GetParam().isCXX()) {
3102 EXPECT_TRUE(treeDumpEqual(
3104 namespace a { namespace b {} }
3107 TranslationUnit Detached
3108 `-NamespaceDefinition
3112 |-NamespaceDefinition
3121 TEST_P(BuildSyntaxTreeTest
, Namespace_NestedDefinition
) {
3122 if (!GetParam().isCXX17OrLater()) {
3125 EXPECT_TRUE(treeDumpEqual(
3130 TranslationUnit Detached
3131 `-NamespaceDefinition
3141 TEST_P(BuildSyntaxTreeTest
, Namespace_Unnamed
) {
3142 if (!GetParam().isCXX()) {
3145 EXPECT_TRUE(treeDumpEqual(
3150 TranslationUnit Detached
3151 `-NamespaceDefinition
3158 TEST_P(BuildSyntaxTreeTest
, Namespace_Alias
) {
3159 if (!GetParam().isCXX()) {
3162 EXPECT_TRUE(treeDumpEqualOnAnnotations(
3165 [[namespace foo = a;]]
3168 NamespaceAliasDefinition
3177 TEST_P(BuildSyntaxTreeTest
, UsingDirective
) {
3178 if (!GetParam().isCXX()) {
3181 EXPECT_TRUE(treeDumpEqualOnAnnotations(
3184 [[using namespace ::ns;]]
3187 UsingNamespaceDirective
3190 |-NestedNameSpecifier
3191 | `-'::' ListDelimiter
3197 TEST_P(BuildSyntaxTreeTest
, UsingDeclaration_Namespace
) {
3198 if (!GetParam().isCXX()) {
3201 EXPECT_TRUE(treeDumpEqualOnAnnotations(
3203 namespace ns { int a; }
3209 |-NestedNameSpecifier
3210 | |-IdentifierNameSpecifier ListElement
3212 | `-'::' ListDelimiter
3218 TEST_P(BuildSyntaxTreeTest
, UsingDeclaration_ClassMember
) {
3219 if (!GetParam().isCXX()) {
3222 EXPECT_TRUE(treeDumpEqualOnAnnotations(
3224 template <class T> struct X {
3226 [[using typename T::bar;]]
3232 |-NestedNameSpecifier
3233 | |-IdentifierNameSpecifier ListElement
3235 | `-'::' ListDelimiter
3243 |-NestedNameSpecifier
3244 | |-IdentifierNameSpecifier ListElement
3246 | `-'::' ListDelimiter
3252 TEST_P(BuildSyntaxTreeTest
, UsingTypeAlias
) {
3253 if (!GetParam().isCXX11OrLater()) {
3256 EXPECT_TRUE(treeDumpEqual(
3261 TranslationUnit Detached
3262 `-TypeAliasDeclaration
3271 TEST_P(BuildSyntaxTreeTest
, FreeStandingClass_ForwardDeclaration
) {
3272 EXPECT_TRUE(treeDumpEqualOnAnnotations(
3287 |-DeclaratorList Declarators
3288 | `-SimpleDeclarator ListElement
3295 TEST_P(BuildSyntaxTreeTest
, FreeStandingClasses_Definition
) {
3296 EXPECT_TRUE(treeDumpEqualOnAnnotations(
3299 [[struct Y {} *y2;]]
3316 |-DeclaratorList Declarators
3317 | `-SimpleDeclarator ListElement
3327 |-DeclaratorList Declarators
3328 | `-SimpleDeclarator ListElement
3335 TEST_P(BuildSyntaxTreeTest
, StaticMemberFunction
) {
3336 if (!GetParam().isCXX11OrLater()) {
3339 EXPECT_TRUE(treeDumpEqualOnAnnotations(
3342 [[static void f(){}]]
3349 |-DeclaratorList Declarators
3350 | `-SimpleDeclarator ListElement
3352 | `-ParametersAndQualifiers
3361 TEST_P(BuildSyntaxTreeTest
, OutOfLineMemberFunctionDefinition
) {
3362 if (!GetParam().isCXX11OrLater()) {
3365 EXPECT_TRUE(treeDumpEqualOnAnnotations(
3375 |-DeclaratorList Declarators
3376 | `-SimpleDeclarator ListElement
3377 | |-NestedNameSpecifier
3378 | | |-IdentifierNameSpecifier ListElement
3380 | | `-'::' ListDelimiter
3382 | `-ParametersAndQualifiers
3391 TEST_P(BuildSyntaxTreeTest
, ConversionMemberFunction
) {
3392 if (!GetParam().isCXX()) {
3395 EXPECT_TRUE(treeDumpEqualOnAnnotations(
3403 |-DeclaratorList Declarators
3404 | `-SimpleDeclarator ListElement
3407 | `-ParametersAndQualifiers
3414 TEST_P(BuildSyntaxTreeTest
, LiteralOperatorDeclaration
) {
3415 if (!GetParam().isCXX11OrLater()) {
3418 EXPECT_TRUE(treeDumpEqual(
3420 unsigned operator "" _c(char);
3423 TranslationUnit Detached
3426 |-DeclaratorList Declarators
3427 | `-SimpleDeclarator ListElement
3431 | `-ParametersAndQualifiers
3433 | |-ParameterDeclarationList Parameters
3434 | | `-SimpleDeclaration ListElement
3441 TEST_P(BuildSyntaxTreeTest
, NumericLiteralOperatorTemplateDeclaration
) {
3442 if (!GetParam().isCXX11OrLater()) {
3445 EXPECT_TRUE(treeDumpEqual(
3448 unsigned operator "" _t();
3451 TranslationUnit Detached
3452 `-TemplateDeclaration Declaration
3453 |-'template' IntroducerKeyword
3461 |-DeclaratorList Declarators
3462 | `-SimpleDeclarator ListElement
3466 | `-ParametersAndQualifiers
3473 TEST_P(BuildSyntaxTreeTest
, OverloadedOperatorDeclaration
) {
3474 if (!GetParam().isCXX()) {
3477 EXPECT_TRUE(treeDumpEqualOnAnnotations(
3480 [[X& operator=(const X&);]]
3486 |-DeclaratorList Declarators
3487 | `-SimpleDeclarator ListElement
3491 | `-ParametersAndQualifiers
3493 | |-ParameterDeclarationList Parameters
3494 | | `-SimpleDeclaration ListElement
3497 | | `-DeclaratorList Declarators
3498 | | `-SimpleDeclarator ListElement
3505 TEST_P(BuildSyntaxTreeTest
, OverloadedOperatorFriendDeclaration
) {
3506 if (!GetParam().isCXX()) {
3509 EXPECT_TRUE(treeDumpEqualOnAnnotations(
3512 [[friend X operator+(X, const X&);]]
3520 |-DeclaratorList Declarators
3521 | `-SimpleDeclarator ListElement
3524 | `-ParametersAndQualifiers
3526 | |-ParameterDeclarationList Parameters
3527 | | |-SimpleDeclaration ListElement
3529 | | |-',' ListDelimiter
3530 | | `-SimpleDeclaration ListElement
3533 | | `-DeclaratorList Declarators
3534 | | `-SimpleDeclarator ListElement
3541 TEST_P(BuildSyntaxTreeTest
, ClassTemplateDeclaration
) {
3542 if (!GetParam().isCXX()) {
3545 EXPECT_TRUE(treeDumpEqual(
3547 template<typename T>
3551 TranslationUnit Detached
3552 `-TemplateDeclaration Declaration
3553 |-'template' IntroducerKeyword
3555 |-UnknownDeclaration
3568 TEST_P(BuildSyntaxTreeTest
, FunctionTemplateDeclaration
) {
3569 if (!GetParam().isCXX()) {
3572 EXPECT_TRUE(treeDumpEqual(
3574 template<typename T>
3578 TranslationUnit Detached
3579 `-TemplateDeclaration Declaration
3580 |-'template' IntroducerKeyword
3582 |-UnknownDeclaration
3588 |-DeclaratorList Declarators
3589 | `-SimpleDeclarator ListElement
3591 | `-ParametersAndQualifiers
3598 TEST_P(BuildSyntaxTreeTest
, VariableTemplateDeclaration
) {
3599 if (!GetParam().isCXX14OrLater()) {
3602 EXPECT_TRUE(treeDumpEqual(
3604 template <class T> T var = 10;
3607 TranslationUnit Detached
3608 `-TemplateDeclaration Declaration
3609 |-'template' IntroducerKeyword
3611 |-UnknownDeclaration
3617 |-DeclaratorList Declarators
3618 | `-SimpleDeclarator ListElement
3621 | `-IntegerLiteralExpression
3622 | `-'10' LiteralToken
3627 TEST_P(BuildSyntaxTreeTest
, StaticMemberFunctionTemplate
) {
3628 if (!GetParam().isCXX()) {
3631 EXPECT_TRUE(treeDumpEqualOnAnnotations(
3634 [[template<typename U>
3639 TemplateDeclaration Declaration
3640 |-'template' IntroducerKeyword
3642 |-UnknownDeclaration
3649 |-DeclaratorList Declarators
3650 | `-SimpleDeclarator ListElement
3652 | `-ParametersAndQualifiers
3659 TEST_P(BuildSyntaxTreeTest
, NestedTemplates
) {
3660 if (!GetParam().isCXX()) {
3663 EXPECT_TRUE(treeDumpEqual(
3672 TranslationUnit Detached
3673 `-TemplateDeclaration Declaration
3674 |-'template' IntroducerKeyword
3676 |-UnknownDeclaration
3684 |-TemplateDeclaration Declaration
3685 | |-'template' IntroducerKeyword
3687 | |-UnknownDeclaration
3691 | `-SimpleDeclaration
3693 | |-DeclaratorList Declarators
3694 | | `-SimpleDeclarator ListElement
3696 | | `-ParametersAndQualifiers
3698 | | `-')' CloseParen
3705 TEST_P(BuildSyntaxTreeTest
, NestedTemplatesInNamespace
) {
3706 if (!GetParam().isCXX()) {
3709 EXPECT_TRUE(treeDumpEqual(
3712 template<typename T>
3714 template<typename U>
3720 TranslationUnit Detached
3721 `-NamespaceDefinition
3725 |-TemplateDeclaration Declaration
3726 | |-'template' IntroducerKeyword
3728 | |-UnknownDeclaration
3732 | `-SimpleDeclaration
3736 | |-TemplateDeclaration Declaration
3737 | | |-'template' IntroducerKeyword
3739 | | |-UnknownDeclaration
3743 | | `-SimpleDeclaration
3746 | | |-DeclaratorList Declarators
3747 | | | `-SimpleDeclarator ListElement
3749 | | | `-ParametersAndQualifiers
3750 | | | |-'(' OpenParen
3751 | | | `-')' CloseParen
3759 TEST_P(BuildSyntaxTreeTest
, ClassTemplate_MemberClassDefinition
) {
3760 if (!GetParam().isCXX()) {
3763 EXPECT_TRUE(treeDumpEqualOnAnnotations(
3765 template <class T> struct X { struct Y; };
3766 [[template <class T> struct X<T>::Y {};]]
3769 TemplateDeclaration Declaration
3770 |-'template' IntroducerKeyword
3772 |-UnknownDeclaration
3778 |-NestedNameSpecifier
3779 | |-SimpleTemplateNameSpecifier ListElement
3784 | `-'::' ListDelimiter
3792 TEST_P(BuildSyntaxTreeTest
, ExplicitClassTemplateInstantiation_Definition
) {
3793 if (!GetParam().isCXX()) {
3796 EXPECT_TRUE(treeDumpEqualOnAnnotations(
3798 template <class T> struct X {};
3799 [[template struct X<double>;]]
3802 ExplicitTemplateInstantiation
3803 |-'template' IntroducerKeyword
3804 `-SimpleDeclaration Declaration
3814 TEST_P(BuildSyntaxTreeTest
, ExplicitClassTemplateInstantiation_Declaration
) {
3815 if (!GetParam().isCXX()) {
3818 EXPECT_TRUE(treeDumpEqualOnAnnotations(
3820 template <class T> struct X {};
3821 [[extern template struct X<float>;]]
3824 ExplicitTemplateInstantiation
3825 |-'extern' ExternKeyword
3826 |-'template' IntroducerKeyword
3827 `-SimpleDeclaration Declaration
3837 TEST_P(BuildSyntaxTreeTest
, ClassTemplateSpecialization_Partial
) {
3838 if (!GetParam().isCXX()) {
3841 EXPECT_TRUE(treeDumpEqualOnAnnotations(
3843 template <class T> struct X {};
3844 [[template <class T> struct X<T*> {};]]
3847 TemplateDeclaration Declaration
3848 |-'template' IntroducerKeyword
3850 |-UnknownDeclaration
3867 TEST_P(BuildSyntaxTreeTest
, ClassTemplateSpecialization_Full
) {
3868 if (!GetParam().isCXX()) {
3871 EXPECT_TRUE(treeDumpEqualOnAnnotations(
3873 template <class T> struct X {};
3874 [[template <> struct X<int> {};]]
3877 TemplateDeclaration Declaration
3878 |-'template' IntroducerKeyword
3893 TEST_P(BuildSyntaxTreeTest
, EmptyDeclaration
) {
3894 EXPECT_TRUE(treeDumpEqual(
3899 TranslationUnit Detached
3905 TEST_P(BuildSyntaxTreeTest
, StaticAssert
) {
3906 if (!GetParam().isCXX11OrLater()) {
3909 EXPECT_TRUE(treeDumpEqual(
3911 static_assert(true, "message
");
3914 TranslationUnit Detached
3915 `-StaticAssertDeclaration
3918 |-BoolLiteralExpression Condition
3919 | `-'true' LiteralToken
3921 |-StringLiteralExpression Message
3922 | `-'"message
"' LiteralToken
3928 TEST_P(BuildSyntaxTreeTest
, StaticAssert_WithoutMessage
) {
3929 if (!GetParam().isCXX17OrLater()) {
3932 EXPECT_TRUE(treeDumpEqual(
3934 static_assert(true);
3937 TranslationUnit Detached
3938 `-StaticAssertDeclaration
3941 |-BoolLiteralExpression Condition
3942 | `-'true' LiteralToken
3948 TEST_P(BuildSyntaxTreeTest
, ExternC
) {
3949 if (!GetParam().isCXX()) {
3952 EXPECT_TRUE(treeDumpEqual(
3955 extern "C
" { int b; int c; }
3958 TranslationUnit Detached
3959 |-LinkageSpecificationDeclaration
3962 | `-SimpleDeclaration
3964 | |-DeclaratorList Declarators
3965 | | `-SimpleDeclarator ListElement
3968 `-LinkageSpecificationDeclaration
3974 | |-DeclaratorList Declarators
3975 | | `-SimpleDeclarator ListElement
3980 | |-DeclaratorList Declarators
3981 | | `-SimpleDeclarator ListElement
3988 TEST_P(BuildSyntaxTreeTest
, Macro_ObjectLike_Leaf
) {
3989 // All nodes can be mutated.
3990 EXPECT_TRUE(treeDumpEqual(
4006 TranslationUnit Detached
4009 |-DeclaratorList Declarators
4010 | `-SimpleDeclarator ListElement
4012 | `-ParametersAndQualifiers
4017 |-CompoundStatement Statement
4019 | |-ExpressionStatement Statement
4020 | | |-IntegerLiteralExpression Expression
4021 | | | `-'1' LiteralToken
4024 |-CompoundStatement Statement
4026 | |-ExpressionStatement Statement
4027 | | |-IntegerLiteralExpression Expression
4028 | | | `-'2' LiteralToken
4035 TEST_P(BuildSyntaxTreeTest
, Macro_ObjectLike_MatchTree
) {
4036 // Some nodes are unmodifiable, they are marked with 'unmodifiable'.
4037 EXPECT_TRUE(treeDumpEqual(
4044 TranslationUnit Detached
4047 |-DeclaratorList Declarators
4048 | `-SimpleDeclarator ListElement
4050 | `-ParametersAndQualifiers
4054 |-'{' OpenParen unmodifiable
4055 `-'}' CloseParen unmodifiable
4059 TEST_P(BuildSyntaxTreeTest
, Macro_ObjectLike_MismatchTree
) {
4060 EXPECT_TRUE(treeDumpEqual(
4062 #define HALF_IF if (1+
4063 #define HALF_IF_2 1) {}
4065 HALF_IF HALF_IF_2 else {}
4068 TranslationUnit Detached
4071 |-DeclaratorList Declarators
4072 | `-SimpleDeclarator ListElement
4074 | `-ParametersAndQualifiers
4079 |-IfStatement Statement
4080 | |-'if' IntroducerKeyword unmodifiable
4081 | |-'(' unmodifiable
4082 | |-ExpressionStatement Condition unmodifiable
4083 | | `-BinaryOperatorExpression Expression unmodifiable
4084 | | |-IntegerLiteralExpression LeftHandSide unmodifiable
4085 | | | `-'1' LiteralToken unmodifiable
4086 | | |-'+' OperatorToken unmodifiable
4087 | | `-IntegerLiteralExpression RightHandSide unmodifiable
4088 | | `-'1' LiteralToken unmodifiable
4089 | |-')' unmodifiable
4090 | |-CompoundStatement ThenStatement unmodifiable
4091 | | |-'{' OpenParen unmodifiable
4092 | | `-'}' CloseParen unmodifiable
4093 | |-'else' ElseKeyword
4094 | `-CompoundStatement ElseStatement
4101 TEST_P(BuildSyntaxTreeTest
, Macro_FunctionLike_ModifiableArguments
) {
4102 // FIXME: Note that the substitutions for `X` and `Y` are marked modifiable.
4103 // However we cannot change `X` freely. Indeed if we change its substitution
4104 // in the condition we should also change it the then-branch.
4105 EXPECT_TRUE(treeDumpEqual(
4107 #define MIN(X,Y) X < Y ? X : Y
4114 TranslationUnit Detached
4117 |-DeclaratorList Declarators
4118 | `-SimpleDeclarator ListElement
4120 | `-ParametersAndQualifiers
4125 |-ExpressionStatement Statement
4126 | |-UnknownExpression Expression
4127 | | |-BinaryOperatorExpression unmodifiable
4128 | | | |-IntegerLiteralExpression LeftHandSide
4129 | | | | `-'1' LiteralToken
4130 | | | |-'<' OperatorToken unmodifiable
4131 | | | `-IntegerLiteralExpression RightHandSide
4132 | | | `-'2' LiteralToken
4133 | | |-'?' unmodifiable
4134 | | |-IntegerLiteralExpression
4135 | | | `-'1' LiteralToken
4136 | | |-':' unmodifiable
4137 | | `-IntegerLiteralExpression
4138 | | `-'2' LiteralToken
4144 TEST_P(BuildSyntaxTreeTest
, Macro_FunctionLike_MismatchTree
) {
4145 EXPECT_TRUE(treeDumpEqual(
4147 #define HALF_IF(X) if (X &&
4148 #define HALF_IF_2(Y) Y) {}
4150 HALF_IF(1) HALF_IF_2(0) else {}
4153 TranslationUnit Detached
4156 |-DeclaratorList Declarators
4157 | `-SimpleDeclarator ListElement
4159 | `-ParametersAndQualifiers
4164 |-IfStatement Statement
4165 | |-'if' IntroducerKeyword unmodifiable
4166 | |-'(' unmodifiable
4167 | |-ExpressionStatement Condition unmodifiable
4168 | | `-BinaryOperatorExpression Expression unmodifiable
4169 | | |-IntegerLiteralExpression LeftHandSide
4170 | | | `-'1' LiteralToken
4171 | | |-'&&' OperatorToken unmodifiable
4172 | | `-IntegerLiteralExpression RightHandSide
4173 | | `-'0' LiteralToken
4174 | |-')' unmodifiable
4175 | |-CompoundStatement ThenStatement unmodifiable
4176 | | |-'{' OpenParen unmodifiable
4177 | | `-'}' CloseParen unmodifiable
4178 | |-'else' ElseKeyword
4179 | `-CompoundStatement ElseStatement
4186 TEST_P(BuildSyntaxTreeTest
, Macro_FunctionLike_Variadic
) {
4187 EXPECT_TRUE(treeDumpEqualOnAnnotations(
4189 #define CALL(F_NAME, ...) F_NAME(__VA_ARGS__)
4201 |-ExpressionStatement Statement
4202 | |-CallExpression Expression
4203 | | |-IdExpression Callee
4204 | | | `-UnqualifiedId UnqualifiedId
4206 | | |-'(' OpenParen unmodifiable
4207 | | |-CallArguments Arguments
4208 | | | `-IntegerLiteralExpression ListElement
4209 | | | `-'0' LiteralToken
4210 | | `-')' CloseParen unmodifiable
4212 |-ExpressionStatement Statement
4213 | |-CallExpression Expression
4214 | | |-IdExpression Callee
4215 | | | `-UnqualifiedId UnqualifiedId
4217 | | |-'(' OpenParen unmodifiable
4218 | | |-CallArguments Arguments
4219 | | | |-IntegerLiteralExpression ListElement
4220 | | | | `-'0' LiteralToken
4221 | | | |-',' ListDelimiter
4222 | | | `-IntegerLiteralExpression ListElement
4223 | | | `-'1' LiteralToken
4224 | | `-')' CloseParen unmodifiable
4230 TEST_P(BuildSyntaxTreeTest
, InitDeclarator_Equal
) {
4231 if (!GetParam().isCXX()) {
4234 EXPECT_TRUE(treeDumpEqualOnAnnotations(
4236 struct S { S(int);};
4244 `-DeclaratorList Declarators
4245 `-SimpleDeclarator ListElement
4248 `-IntegerLiteralExpression
4253 TEST_P(BuildSyntaxTreeTest
, InitDeclarator_Brace
) {
4254 if (!GetParam().isCXX11OrLater()) {
4257 EXPECT_TRUE(treeDumpEqualOnAnnotations(
4265 // FIXME: 's...' is a declarator and '{...}' is initializer
4274 `-DeclaratorList Declarators
4275 `-SimpleDeclarator ListElement
4284 `-DeclaratorList Declarators
4285 `-SimpleDeclarator ListElement
4289 |-IntegerLiteralExpression
4290 | `-'1' LiteralToken
4296 `-DeclaratorList Declarators
4297 `-SimpleDeclarator ListElement
4301 |-IntegerLiteralExpression
4302 | `-'1' LiteralToken
4304 |-FloatingLiteralExpression
4305 | `-'2.' LiteralToken
4310 TEST_P(BuildSyntaxTreeTest
, InitDeclarator_EqualBrace
) {
4311 if (!GetParam().isCXX11OrLater()) {
4314 EXPECT_TRUE(treeDumpEqualOnAnnotations(
4322 // FIXME: '= {...}' is initializer
4331 `-DeclaratorList Declarators
4332 `-SimpleDeclarator ListElement
4342 `-DeclaratorList Declarators
4343 `-SimpleDeclarator ListElement
4348 |-IntegerLiteralExpression
4349 | `-'1' LiteralToken
4355 `-DeclaratorList Declarators
4356 `-SimpleDeclarator ListElement
4361 |-IntegerLiteralExpression
4362 | `-'1' LiteralToken
4364 |-FloatingLiteralExpression
4365 | `-'2.' LiteralToken
4370 TEST_P(BuildSyntaxTreeTest
, InitDeclarator_Paren
) {
4371 if (!GetParam().isCXX()) {
4374 EXPECT_TRUE(treeDumpEqualOnAnnotations(
4380 // FIXME: 's...' is a declarator and '(...)' is initializer
4387 |-DeclaratorList Declarators
4388 | `-SimpleDeclarator ListElement
4389 | `-UnknownExpression
4392 | |-IntegerLiteralExpression
4393 | | `-'1' LiteralToken
4400 |-DeclaratorList Declarators
4401 | `-SimpleDeclarator ListElement
4402 | `-UnknownExpression
4405 | |-IntegerLiteralExpression
4406 | | `-'1' LiteralToken
4408 | |-FloatingLiteralExpression
4409 | | `-'2.' LiteralToken
4415 TEST_P(BuildSyntaxTreeTest
, InitDeclarator_Paren_DefaultArguments
) {
4416 if (!GetParam().isCXX()) {
4419 EXPECT_TRUE(treeDumpEqualOnAnnotations(
4422 S(int i = 1, float = 2.);
4425 // FIXME: 's...' is a declarator and '(...)' is initializer
4432 |-DeclaratorList Declarators
4433 | `-SimpleDeclarator ListElement
4440 |-DeclaratorList Declarators
4441 | `-SimpleDeclarator ListElement
4442 | `-UnknownExpression
4445 | |-IntegerLiteralExpression
4446 | | `-'1' LiteralToken
4453 |-DeclaratorList Declarators
4454 | `-SimpleDeclarator ListElement
4455 | `-UnknownExpression
4458 | |-IntegerLiteralExpression
4459 | | `-'1' LiteralToken
4461 | |-FloatingLiteralExpression
4462 | | `-'2.' LiteralToken
4468 TEST_P(BuildSyntaxTreeTest
, ImplicitConversion_Argument
) {
4469 if (!GetParam().isCXX()) {
4472 EXPECT_TRUE(treeDumpEqualOnAnnotations(
4477 void TakeX(const X&);
4483 CallExpression Expression
4484 |-IdExpression Callee
4485 | `-UnqualifiedId UnqualifiedId
4488 |-CallArguments Arguments
4489 | `-IntegerLiteralExpression ListElement
4490 | `-'1' LiteralToken
4495 TEST_P(BuildSyntaxTreeTest
, ImplicitConversion_Return
) {
4496 if (!GetParam().isCXX()) {
4499 EXPECT_TRUE(treeDumpEqualOnAnnotations(
4509 ReturnStatement Statement
4510 |-'return' IntroducerKeyword
4511 |-IntegerLiteralExpression ReturnValue
4512 | `-'1' LiteralToken
4517 TEST_P(BuildSyntaxTreeTest
, ConstructorCall_ZeroArguments
) {
4518 if (!GetParam().isCXX()) {
4521 EXPECT_TRUE(treeDumpEqualOnAnnotations(
4531 ReturnStatement Statement
4532 |-'return' IntroducerKeyword
4533 |-UnknownExpression ReturnValue
4541 TEST_P(BuildSyntaxTreeTest
, ConstructorCall_OneArgument
) {
4542 if (!GetParam().isCXX()) {
4545 EXPECT_TRUE(treeDumpEqualOnAnnotations(
4555 ReturnStatement Statement
4556 |-'return' IntroducerKeyword
4557 |-UnknownExpression ReturnValue
4560 | |-IntegerLiteralExpression
4561 | | `-'1' LiteralToken
4567 TEST_P(BuildSyntaxTreeTest
, ConstructorCall_MultipleArguments
) {
4568 if (!GetParam().isCXX()) {
4571 EXPECT_TRUE(treeDumpEqualOnAnnotations(
4577 [[return X(1, '2');]]
4581 ReturnStatement Statement
4582 |-'return' IntroducerKeyword
4583 |-UnknownExpression ReturnValue
4586 | |-IntegerLiteralExpression
4587 | | `-'1' LiteralToken
4589 | |-CharacterLiteralExpression
4590 | | `-''2'' LiteralToken
4596 TEST_P(BuildSyntaxTreeTest
, ConstructorCall_DefaultArguments
) {
4597 if (!GetParam().isCXX()) {
4600 EXPECT_TRUE(treeDumpEqualOnAnnotations(
4603 X(int i = 1, char c = '2');
4608 auto x2 = [[X(1, '2')]];
4621 |-IntegerLiteralExpression
4622 | `-'1' LiteralToken
4629 |-IntegerLiteralExpression
4630 | `-'1' LiteralToken
4632 |-CharacterLiteralExpression
4633 | `-''2'' LiteralToken
4638 TEST_P(BuildSyntaxTreeTest
, TypeConversion_FunctionalNotation
) {
4639 if (!GetParam().isCXX()) {
4642 EXPECT_TRUE(treeDumpEqualOnAnnotations(
4645 [[return float(1);]]
4649 ReturnStatement Statement
4650 |-'return' IntroducerKeyword
4651 |-UnknownExpression ReturnValue
4654 | |-IntegerLiteralExpression
4655 | | `-'1' LiteralToken
4661 TEST_P(BuildSyntaxTreeTest
, ArrayDeclarator_Simple
) {
4662 EXPECT_TRUE(treeDumpEqual(
4667 TranslationUnit Detached
4670 |-DeclaratorList Declarators
4671 | `-SimpleDeclarator ListElement
4675 | |-IntegerLiteralExpression Size
4676 | | `-'10' LiteralToken
4682 TEST_P(BuildSyntaxTreeTest
, ArrayDeclarator_Multidimensional
) {
4683 EXPECT_TRUE(treeDumpEqual(
4688 TranslationUnit Detached
4691 |-DeclaratorList Declarators
4692 | `-SimpleDeclarator ListElement
4696 | | |-IntegerLiteralExpression Size
4697 | | | `-'1' LiteralToken
4698 | | `-']' CloseParen
4701 | | |-IntegerLiteralExpression Size
4702 | | | `-'2' LiteralToken
4703 | | `-']' CloseParen
4706 | |-IntegerLiteralExpression Size
4707 | | `-'3' LiteralToken
4713 TEST_P(BuildSyntaxTreeTest
, ArrayDeclarator_UnknownBound
) {
4714 EXPECT_TRUE(treeDumpEqual(
4719 TranslationUnit Detached
4722 |-DeclaratorList Declarators
4723 | `-SimpleDeclarator ListElement
4727 | | `-']' CloseParen
4729 | `-UnknownExpression
4730 | `-UnknownExpression
4732 | |-IntegerLiteralExpression
4733 | | `-'1' LiteralToken
4735 | |-IntegerLiteralExpression
4736 | | `-'2' LiteralToken
4738 | |-IntegerLiteralExpression
4739 | | `-'3' LiteralToken
4745 TEST_P(BuildSyntaxTreeTest
, ArrayDeclarator_Static
) {
4746 if (!GetParam().isC99OrLater()) {
4749 EXPECT_TRUE(treeDumpEqual(
4751 void f(int xs[static 10]);
4754 TranslationUnit Detached
4757 |-DeclaratorList Declarators
4758 | `-SimpleDeclarator ListElement
4760 | `-ParametersAndQualifiers
4762 | |-ParameterDeclarationList Parameters
4763 | | `-SimpleDeclaration ListElement
4765 | | `-DeclaratorList Declarators
4766 | | `-SimpleDeclarator ListElement
4768 | | `-ArraySubscript
4771 | | |-IntegerLiteralExpression Size
4772 | | | `-'10' LiteralToken
4773 | | `-']' CloseParen
4779 TEST_P(BuildSyntaxTreeTest
, ParametersAndQualifiers_InFreeFunctions_Empty
) {
4780 EXPECT_TRUE(treeDumpEqual(
4785 TranslationUnit Detached
4788 |-DeclaratorList Declarators
4789 | `-SimpleDeclarator ListElement
4791 | `-ParametersAndQualifiers
4798 TEST_P(BuildSyntaxTreeTest
, ParametersAndQualifiers_InFreeFunctions_Named
) {
4799 EXPECT_TRUE(treeDumpEqualOnAnnotations(
4801 int func1([[int a]]);
4802 int func2([[int *ap]]);
4803 int func3([[int a, float b]]);
4804 int func4([[undef a]]); // error-ok: no crash on invalid type
4807 ParameterDeclarationList Parameters
4808 `-SimpleDeclaration ListElement
4810 `-DeclaratorList Declarators
4811 `-SimpleDeclarator ListElement
4815 ParameterDeclarationList Parameters
4816 `-SimpleDeclaration ListElement
4818 `-DeclaratorList Declarators
4819 `-SimpleDeclarator ListElement
4824 ParameterDeclarationList Parameters
4825 |-SimpleDeclaration ListElement
4827 | `-DeclaratorList Declarators
4828 | `-SimpleDeclarator ListElement
4831 `-SimpleDeclaration ListElement
4833 `-DeclaratorList Declarators
4834 `-SimpleDeclarator ListElement
4838 ParameterDeclarationList Parameters
4839 `-SimpleDeclaration ListElement
4841 `-DeclaratorList Declarators
4842 `-SimpleDeclarator ListElement
4847 TEST_P(BuildSyntaxTreeTest
, ParametersAndQualifiers_InFreeFunctions_Unnamed
) {
4848 EXPECT_TRUE(treeDumpEqual(
4852 int func3(int, float);
4855 TranslationUnit Detached
4858 | |-DeclaratorList Declarators
4859 | | `-SimpleDeclarator ListElement
4861 | | `-ParametersAndQualifiers
4863 | | |-ParameterDeclarationList Parameters
4864 | | | `-SimpleDeclaration ListElement
4866 | | `-')' CloseParen
4870 | |-DeclaratorList Declarators
4871 | | `-SimpleDeclarator ListElement
4873 | | `-ParametersAndQualifiers
4875 | | |-ParameterDeclarationList Parameters
4876 | | | `-SimpleDeclaration ListElement
4878 | | | `-DeclaratorList Declarators
4879 | | | `-SimpleDeclarator ListElement
4881 | | `-')' CloseParen
4885 |-DeclaratorList Declarators
4886 | `-SimpleDeclarator ListElement
4888 | `-ParametersAndQualifiers
4890 | |-ParameterDeclarationList Parameters
4891 | | |-SimpleDeclaration ListElement
4893 | | |-',' ListDelimiter
4894 | | `-SimpleDeclaration ListElement
4901 TEST_P(BuildSyntaxTreeTest
,
4902 ParametersAndQualifiers_InFreeFunctions_Default_One
) {
4903 if (!GetParam().isCXX()) {
4906 EXPECT_TRUE(treeDumpEqualOnAnnotations(
4908 int func1([[int a = 1]]);
4911 ParameterDeclarationList Parameters
4912 `-SimpleDeclaration ListElement
4914 `-DeclaratorList Declarators
4915 `-SimpleDeclarator ListElement
4918 `-IntegerLiteralExpression
4923 TEST_P(BuildSyntaxTreeTest
,
4924 ParametersAndQualifiers_InFreeFunctions_Default_Multiple
) {
4925 if (!GetParam().isCXX()) {
4928 EXPECT_TRUE(treeDumpEqualOnAnnotations(
4930 int func2([[int *ap, int a = 1, char c = '2']]);
4933 ParameterDeclarationList Parameters
4934 |-SimpleDeclaration ListElement
4936 | `-DeclaratorList Declarators
4937 | `-SimpleDeclarator ListElement
4941 |-SimpleDeclaration ListElement
4943 | `-DeclaratorList Declarators
4944 | `-SimpleDeclarator ListElement
4947 | `-IntegerLiteralExpression
4948 | `-'1' LiteralToken
4950 `-SimpleDeclaration ListElement
4952 `-DeclaratorList Declarators
4953 `-SimpleDeclarator ListElement
4956 `-CharacterLiteralExpression
4957 `-''2'' LiteralToken
4961 TEST_P(BuildSyntaxTreeTest
,
4962 ParametersAndQualifiers_InVariadicFunctionTemplate_ParameterPack
) {
4963 if (!GetParam().isCXX11OrLater() || GetParam().hasDelayedTemplateParsing()) {
4966 EXPECT_TRUE(treeDumpEqualOnAnnotations(
4968 template<typename T, typename... Args>
4969 [[void test(T , Args... );]]
4974 |-DeclaratorList Declarators
4975 | `-SimpleDeclarator ListElement
4977 | `-ParametersAndQualifiers
4979 | |-ParameterDeclarationList Parameters
4980 | | |-SimpleDeclaration ListElement
4982 | | |-',' ListDelimiter
4983 | | `-SimpleDeclaration ListElement
4991 TEST_P(BuildSyntaxTreeTest
,
4992 ParametersAndQualifiers_InVariadicFunctionTemplate_NamedParameterPack
) {
4993 if (!GetParam().isCXX11OrLater() || GetParam().hasDelayedTemplateParsing()) {
4996 EXPECT_TRUE(treeDumpEqualOnAnnotations(
4998 template<typename T, typename... Args>
4999 [[void test(T t, Args... args);]]
5004 |-DeclaratorList Declarators
5005 | `-SimpleDeclarator ListElement
5007 | `-ParametersAndQualifiers
5009 | |-ParameterDeclarationList Parameters
5010 | | |-SimpleDeclaration ListElement
5012 | | | `-DeclaratorList Declarators
5013 | | | `-SimpleDeclarator ListElement
5015 | | |-',' ListDelimiter
5016 | | `-SimpleDeclaration ListElement
5019 | | `-DeclaratorList Declarators
5020 | | `-SimpleDeclarator ListElement
5027 TEST_P(BuildSyntaxTreeTest
,
5028 ParametersAndQualifiers_InFreeFunctions_VariadicArguments
) {
5029 if (!GetParam().isCXX11OrLater()) {
5032 EXPECT_TRUE(treeDumpEqual(
5034 void test(int , char ...);
5037 TranslationUnit Detached
5040 |-DeclaratorList Declarators
5041 | `-SimpleDeclarator ListElement
5043 | `-ParametersAndQualifiers
5045 | |-ParameterDeclarationList Parameters
5046 | | |-SimpleDeclaration ListElement
5048 | | |-',' ListDelimiter
5049 | | `-SimpleDeclaration ListElement
5057 TEST_P(BuildSyntaxTreeTest
,
5058 ParametersAndQualifiers_InFreeFunctions_Cxx_CvQualifiers
) {
5059 if (!GetParam().isCXX()) {
5062 EXPECT_TRUE(treeDumpEqual(
5064 int func(const int a, volatile int b, const volatile int c);
5067 TranslationUnit Detached
5070 |-DeclaratorList Declarators
5071 | `-SimpleDeclarator ListElement
5073 | `-ParametersAndQualifiers
5075 | |-ParameterDeclarationList Parameters
5076 | | |-SimpleDeclaration ListElement
5079 | | | `-DeclaratorList Declarators
5080 | | | `-SimpleDeclarator ListElement
5082 | | |-',' ListDelimiter
5083 | | |-SimpleDeclaration ListElement
5086 | | | `-DeclaratorList Declarators
5087 | | | `-SimpleDeclarator ListElement
5089 | | |-',' ListDelimiter
5090 | | `-SimpleDeclaration ListElement
5094 | | `-DeclaratorList Declarators
5095 | | `-SimpleDeclarator ListElement
5102 TEST_P(BuildSyntaxTreeTest
, ParametersAndQualifiers_InFreeFunctions_Cxx_Ref
) {
5103 if (!GetParam().isCXX()) {
5106 EXPECT_TRUE(treeDumpEqual(
5111 TranslationUnit Detached
5114 |-DeclaratorList Declarators
5115 | `-SimpleDeclarator ListElement
5117 | `-ParametersAndQualifiers
5119 | |-ParameterDeclarationList Parameters
5120 | | `-SimpleDeclaration ListElement
5122 | | `-DeclaratorList Declarators
5123 | | `-SimpleDeclarator ListElement
5131 TEST_P(BuildSyntaxTreeTest
,
5132 ParametersAndQualifiers_InFreeFunctions_Cxx11_RefRef
) {
5133 if (!GetParam().isCXX11OrLater()) {
5136 EXPECT_TRUE(treeDumpEqual(
5141 TranslationUnit Detached
5144 |-DeclaratorList Declarators
5145 | `-SimpleDeclarator ListElement
5147 | `-ParametersAndQualifiers
5149 | |-ParameterDeclarationList Parameters
5150 | | `-SimpleDeclaration ListElement
5152 | | `-DeclaratorList Declarators
5153 | | `-SimpleDeclarator ListElement
5161 TEST_P(BuildSyntaxTreeTest
, ParametersAndQualifiers_InMemberFunctions_Simple
) {
5162 if (!GetParam().isCXX()) {
5165 EXPECT_TRUE(treeDumpEqual(
5172 TranslationUnit Detached
5179 | |-DeclaratorList Declarators
5180 | | `-SimpleDeclarator ListElement
5182 | | `-ParametersAndQualifiers
5184 | | `-')' CloseParen
5191 TEST_P(BuildSyntaxTreeTest
,
5192 ParametersAndQualifiers_InMemberFunctions_CvQualifiers
) {
5193 if (!GetParam().isCXX()) {
5196 EXPECT_TRUE(treeDumpEqualOnAnnotations(
5200 [[int c() volatile;]]
5201 [[int d() const volatile;]]
5207 |-DeclaratorList Declarators
5208 | `-SimpleDeclarator ListElement
5210 | `-ParametersAndQualifiers
5219 |-DeclaratorList Declarators
5220 | `-SimpleDeclarator ListElement
5222 | `-ParametersAndQualifiers
5231 |-DeclaratorList Declarators
5232 | `-SimpleDeclarator ListElement
5234 | `-ParametersAndQualifiers
5243 TEST_P(BuildSyntaxTreeTest
, ParametersAndQualifiers_InMemberFunctions_Ref
) {
5244 if (!GetParam().isCXX11OrLater()) {
5247 EXPECT_TRUE(treeDumpEqualOnAnnotations(
5256 |-DeclaratorList Declarators
5257 | `-SimpleDeclarator ListElement
5259 | `-ParametersAndQualifiers
5267 TEST_P(BuildSyntaxTreeTest
, ParametersAndQualifiers_InMemberFunctions_RefRef
) {
5268 if (!GetParam().isCXX11OrLater()) {
5271 EXPECT_TRUE(treeDumpEqualOnAnnotations(
5280 |-DeclaratorList Declarators
5281 | `-SimpleDeclarator ListElement
5283 | `-ParametersAndQualifiers
5291 TEST_P(BuildSyntaxTreeTest
, TrailingReturn
) {
5292 if (!GetParam().isCXX11OrLater()) {
5295 EXPECT_TRUE(treeDumpEqual(
5300 TranslationUnit Detached
5303 |-DeclaratorList Declarators
5304 | `-SimpleDeclarator ListElement
5306 | `-ParametersAndQualifiers
5309 | `-TrailingReturnType TrailingReturn
5316 TEST_P(BuildSyntaxTreeTest
, DynamicExceptionSpecification
) {
5317 if (!GetParam().supportsCXXDynamicExceptionSpecification()) {
5320 EXPECT_TRUE(treeDumpEqualOnAnnotations(
5322 struct MyException1 {};
5323 struct MyException2 {};
5324 [[int a() throw();]]
5325 [[int b() throw(...);]]
5326 [[int c() throw(MyException1);]]
5327 [[int d() throw(MyException1, MyException2);]]
5332 |-DeclaratorList Declarators
5333 | `-SimpleDeclarator ListElement
5335 | `-ParametersAndQualifiers
5346 |-DeclaratorList Declarators
5347 | `-SimpleDeclarator ListElement
5349 | `-ParametersAndQualifiers
5361 |-DeclaratorList Declarators
5362 | `-SimpleDeclarator ListElement
5364 | `-ParametersAndQualifiers
5376 |-DeclaratorList Declarators
5377 | `-SimpleDeclarator ListElement
5379 | `-ParametersAndQualifiers
5392 TEST_P(BuildSyntaxTreeTest
, NoexceptExceptionSpecification
) {
5393 if (!GetParam().isCXX11OrLater()) {
5396 EXPECT_TRUE(treeDumpEqual(
5399 int b() noexcept(true);
5402 TranslationUnit Detached
5405 | |-DeclaratorList Declarators
5406 | | `-SimpleDeclarator ListElement
5408 | | `-ParametersAndQualifiers
5410 | | |-')' CloseParen
5415 |-DeclaratorList Declarators
5416 | `-SimpleDeclarator ListElement
5418 | `-ParametersAndQualifiers
5423 | |-BoolLiteralExpression
5424 | | `-'true' LiteralToken
5430 TEST_P(BuildSyntaxTreeTest
, DeclaratorsInParentheses
) {
5431 EXPECT_TRUE(treeDumpEqual(
5439 TranslationUnit Detached
5442 | |-DeclaratorList Declarators
5443 | | `-SimpleDeclarator ListElement
5444 | | `-ParenDeclarator
5447 | | `-')' CloseParen
5451 | |-DeclaratorList Declarators
5452 | | `-SimpleDeclarator ListElement
5454 | | `-ParenDeclarator
5457 | | `-')' CloseParen
5461 | |-DeclaratorList Declarators
5462 | | `-SimpleDeclarator ListElement
5463 | | |-ParenDeclarator
5464 | | | |-'(' OpenParen
5467 | | | `-')' CloseParen
5468 | | `-ParametersAndQualifiers
5470 | | |-ParameterDeclarationList Parameters
5471 | | | `-SimpleDeclaration ListElement
5473 | | `-')' CloseParen
5477 |-DeclaratorList Declarators
5478 | `-SimpleDeclarator ListElement
5483 | | `-')' CloseParen
5484 | `-ParametersAndQualifiers
5486 | |-ParameterDeclarationList Parameters
5487 | | `-SimpleDeclaration ListElement
5494 TEST_P(BuildSyntaxTreeTest
, Declaration_ConstVolatileQualifiers_SimpleConst
) {
5495 EXPECT_TRUE(treeDumpEqual(
5497 const int west = -1;
5501 TranslationUnit Detached
5505 | |-DeclaratorList Declarators
5506 | | `-SimpleDeclarator ListElement
5509 | | `-PrefixUnaryOperatorExpression
5510 | | |-'-' OperatorToken
5511 | | `-IntegerLiteralExpression Operand
5512 | | `-'1' LiteralToken
5517 |-DeclaratorList Declarators
5518 | `-SimpleDeclarator ListElement
5521 | `-IntegerLiteralExpression
5522 | `-'1' LiteralToken
5527 TEST_P(BuildSyntaxTreeTest
, Declaration_ConstVolatileQualifiers_MultipleConst
) {
5528 EXPECT_TRUE(treeDumpEqual(
5530 const int const universal = 0;
5533 TranslationUnit Detached
5538 |-DeclaratorList Declarators
5539 | `-SimpleDeclarator ListElement
5542 | `-IntegerLiteralExpression
5543 | `-'0' LiteralToken
5548 TEST_P(BuildSyntaxTreeTest
,
5549 Declaration_ConstVolatileQualifiers_ConstAndVolatile
) {
5550 EXPECT_TRUE(treeDumpEqual(
5552 const int const *const *volatile b;
5555 TranslationUnit Detached
5560 |-DeclaratorList Declarators
5561 | `-SimpleDeclarator ListElement
5571 TEST_P(BuildSyntaxTreeTest
, RangesOfDeclaratorsWithTrailingReturnTypes
) {
5572 if (!GetParam().isCXX11OrLater()) {
5575 EXPECT_TRUE(treeDumpEqual(
5577 auto foo() -> auto(*)(int) -> double*;
5580 TranslationUnit Detached
5583 |-DeclaratorList Declarators
5584 | `-SimpleDeclarator ListElement
5586 | `-ParametersAndQualifiers
5589 | `-TrailingReturnType TrailingReturn
5592 | `-SimpleDeclarator Declarator
5596 | | `-')' CloseParen
5597 | `-ParametersAndQualifiers
5599 | |-ParameterDeclarationList Parameters
5600 | | `-SimpleDeclaration ListElement
5603 | `-TrailingReturnType TrailingReturn
5606 | `-SimpleDeclarator Declarator
5612 TEST_P(BuildSyntaxTreeTest
, MemberPointers
) {
5613 if (!GetParam().isCXX()) {
5616 EXPECT_TRUE(treeDumpEqualOnAnnotations(
5620 [[const int X::* b;]]
5625 |-DeclaratorList Declarators
5626 | `-SimpleDeclarator ListElement
5638 |-DeclaratorList Declarators
5639 | `-SimpleDeclarator ListElement
5649 TEST_P(BuildSyntaxTreeTest
, MemberFunctionPointer
) {
5650 if (!GetParam().isCXX()) {
5653 EXPECT_TRUE(treeDumpEqualOnAnnotations(
5658 [[void (X::*xp)();]]
5659 [[void (X::**xpp)(const int*);]]
5660 // FIXME: Generate the right syntax tree for this type,
5661 // i.e. create a syntax node for the outer member pointer
5662 [[void (X::Y::*xyp)(const int*, char);]]
5667 |-DeclaratorList Declarators
5668 | `-SimpleDeclarator ListElement
5676 | | `-')' CloseParen
5677 | `-ParametersAndQualifiers
5685 |-DeclaratorList Declarators
5686 | `-SimpleDeclarator ListElement
5695 | | `-')' CloseParen
5696 | `-ParametersAndQualifiers
5698 | |-ParameterDeclarationList Parameters
5699 | | `-SimpleDeclaration ListElement
5702 | | `-DeclaratorList Declarators
5703 | | `-SimpleDeclarator ListElement
5711 |-DeclaratorList Declarators
5712 | `-SimpleDeclarator ListElement
5722 | | `-')' CloseParen
5723 | `-ParametersAndQualifiers
5725 | |-ParameterDeclarationList Parameters
5726 | | |-SimpleDeclaration ListElement
5729 | | | `-DeclaratorList Declarators
5730 | | | `-SimpleDeclarator ListElement
5732 | | |-',' ListDelimiter
5733 | | `-SimpleDeclaration ListElement
5740 TEST_P(BuildSyntaxTreeTest
, ComplexDeclarator
) {
5741 EXPECT_TRUE(treeDumpEqual(
5743 void x(char a, short (*b)(int));
5746 TranslationUnit Detached
5749 |-DeclaratorList Declarators
5750 | `-SimpleDeclarator ListElement
5752 | `-ParametersAndQualifiers
5754 | |-ParameterDeclarationList Parameters
5755 | | |-SimpleDeclaration ListElement
5757 | | | `-DeclaratorList Declarators
5758 | | | `-SimpleDeclarator ListElement
5760 | | |-',' ListDelimiter
5761 | | `-SimpleDeclaration ListElement
5763 | | `-DeclaratorList Declarators
5764 | | `-SimpleDeclarator ListElement
5765 | | |-ParenDeclarator
5766 | | | |-'(' OpenParen
5769 | | | `-')' CloseParen
5770 | | `-ParametersAndQualifiers
5772 | | |-ParameterDeclarationList Parameters
5773 | | | `-SimpleDeclaration ListElement
5775 | | `-')' CloseParen
5781 TEST_P(BuildSyntaxTreeTest
, ComplexDeclarator2
) {
5782 EXPECT_TRUE(treeDumpEqual(
5784 void x(char a, short (*b)(int), long (**c)(long long));
5787 TranslationUnit Detached
5790 |-DeclaratorList Declarators
5791 | `-SimpleDeclarator ListElement
5793 | `-ParametersAndQualifiers
5795 | |-ParameterDeclarationList Parameters
5796 | | |-SimpleDeclaration ListElement
5798 | | | `-DeclaratorList Declarators
5799 | | | `-SimpleDeclarator ListElement
5801 | | |-',' ListDelimiter
5802 | | |-SimpleDeclaration ListElement
5804 | | | `-DeclaratorList Declarators
5805 | | | `-SimpleDeclarator ListElement
5806 | | | |-ParenDeclarator
5807 | | | | |-'(' OpenParen
5810 | | | | `-')' CloseParen
5811 | | | `-ParametersAndQualifiers
5812 | | | |-'(' OpenParen
5813 | | | |-ParameterDeclarationList Parameters
5814 | | | | `-SimpleDeclaration ListElement
5816 | | | `-')' CloseParen
5817 | | |-',' ListDelimiter
5818 | | `-SimpleDeclaration ListElement
5820 | | `-DeclaratorList Declarators
5821 | | `-SimpleDeclarator ListElement
5822 | | |-ParenDeclarator
5823 | | | |-'(' OpenParen
5827 | | | `-')' CloseParen
5828 | | `-ParametersAndQualifiers
5830 | | |-ParameterDeclarationList Parameters
5831 | | | `-SimpleDeclaration ListElement
5834 | | `-')' CloseParen