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;
2272 |-ExpressionStatement Statement
2273 | |-MemberExpression Expression
2274 | | |-IdExpression Object
2275 | | | `-UnqualifiedId UnqualifiedId
2277 | | |-'.' AccessToken
2278 | | `-IdExpression Member
2279 | | `-UnqualifiedId UnqualifiedId
2289 TEST_P(BuildSyntaxTreeTest
, MemberExpression_FunctionTemplate
) {
2290 if (!GetParam().isCXX()) {
2293 EXPECT_TRUE(treeDumpEqualOnAnnotations(
2296 template<typename T>
2304 CallExpression Expression
2305 |-MemberExpression Callee
2306 | |-IdExpression Object
2307 | | `-UnqualifiedId UnqualifiedId
2309 | |-'->' AccessToken
2310 | `-IdExpression Member
2311 | `-UnqualifiedId UnqualifiedId
2321 TEST_P(BuildSyntaxTreeTest
,
2322 MemberExpression_FunctionTemplateWithTemplateKeyword
) {
2323 if (!GetParam().isCXX()) {
2326 EXPECT_TRUE(treeDumpEqualOnAnnotations(
2329 template<typename T>
2333 [[s.template f<int>()]];
2337 CallExpression Expression
2338 |-MemberExpression Callee
2339 | |-IdExpression Object
2340 | | `-UnqualifiedId UnqualifiedId
2344 | `-IdExpression Member
2345 | `-UnqualifiedId UnqualifiedId
2355 TEST_P(BuildSyntaxTreeTest
, MemberExpression_WithQualifier
) {
2356 if (!GetParam().isCXX()) {
2359 EXPECT_TRUE(treeDumpEqualOnAnnotations(
2364 struct S : public Base {};
2371 CallExpression Expression
2372 |-MemberExpression Callee
2373 | |-IdExpression Object
2374 | | `-UnqualifiedId UnqualifiedId
2377 | `-IdExpression Member
2378 | |-NestedNameSpecifier Qualifier
2379 | | |-IdentifierNameSpecifier ListElement
2381 | | `-'::' ListDelimiter
2382 | `-UnqualifiedId UnqualifiedId
2388 CallExpression Expression
2389 |-MemberExpression Callee
2390 | |-IdExpression Object
2391 | | `-UnqualifiedId UnqualifiedId
2394 | `-IdExpression Member
2395 | |-NestedNameSpecifier Qualifier
2396 | | |-'::' ListDelimiter
2397 | | |-IdentifierNameSpecifier ListElement
2399 | | `-'::' ListDelimiter
2400 | `-UnqualifiedId UnqualifiedId
2408 TEST_P(BuildSyntaxTreeTest
, MemberExpression_Complex
) {
2409 if (!GetParam().isCXX()) {
2412 EXPECT_TRUE(treeDumpEqualOnAnnotations(
2414 template<typename T>
2416 template<typename U>
2423 // FIXME: The first 'template' keyword is a child of `NestedNameSpecifier`,
2424 // but it should be a child of `MemberExpression` according to the grammar.
2425 // However one might argue that the 'template' keyword fits better inside
2426 // `NestedNameSpecifier` because if we change `U<int>` to `UI` we would like
2427 // equally to change the `NameSpecifier` `template U<int>` to just `UI`.
2428 [[sp->getU().template U<int>::template f<int>()]];
2432 CallExpression Expression
2433 |-MemberExpression Callee
2434 | |-CallExpression Object
2435 | | |-MemberExpression Callee
2436 | | | |-IdExpression Object
2437 | | | | `-UnqualifiedId UnqualifiedId
2439 | | | |-'->' AccessToken
2440 | | | `-IdExpression Member
2441 | | | `-UnqualifiedId UnqualifiedId
2444 | | `-')' CloseParen
2446 | `-IdExpression Member
2447 | |-NestedNameSpecifier Qualifier
2448 | | |-SimpleTemplateNameSpecifier ListElement
2454 | | `-'::' ListDelimiter
2455 | |-'template' TemplateKeyword
2456 | `-UnqualifiedId UnqualifiedId
2466 TEST_P(BuildSyntaxTreeTest
, CallExpression_Callee_Member
) {
2467 if (!GetParam().isCXX()) {
2470 EXPECT_TRUE(treeDumpEqualOnAnnotations(
2480 CallExpression Expression
2481 |-MemberExpression Callee
2482 | |-IdExpression Object
2483 | | `-UnqualifiedId UnqualifiedId
2486 | `-IdExpression Member
2487 | `-UnqualifiedId UnqualifiedId
2494 TEST_P(BuildSyntaxTreeTest
, CallExpression_Callee_OperatorParens
) {
2495 if (!GetParam().isCXX()) {
2498 EXPECT_TRUE(treeDumpEqualOnAnnotations(
2508 CallExpression Expression
2509 |-IdExpression Callee
2510 | `-UnqualifiedId UnqualifiedId
2517 TEST_P(BuildSyntaxTreeTest
, CallExpression_Callee_OperatorParensChaining
) {
2518 if (!GetParam().isCXX()) {
2521 EXPECT_TRUE(treeDumpEqualOnAnnotations(
2531 CallExpression Expression
2532 |-CallExpression Callee
2533 | |-IdExpression Callee
2534 | | `-UnqualifiedId UnqualifiedId
2543 TEST_P(BuildSyntaxTreeTest
, CallExpression_Callee_MemberWithThis
) {
2544 if (!GetParam().isCXX()) {
2547 EXPECT_TRUE(treeDumpEqualOnAnnotations(
2552 struct S: public Base {
2557 [[this->Base::f()]];
2562 CallExpression Expression
2563 |-MemberExpression Callee
2564 | |-ThisExpression Object
2565 | | `-'this' IntroducerKeyword
2566 | |-'->' AccessToken
2567 | `-IdExpression Member
2568 | `-UnqualifiedId UnqualifiedId
2574 CallExpression Expression
2575 |-IdExpression Callee
2576 | `-UnqualifiedId UnqualifiedId
2582 CallExpression Expression
2583 |-MemberExpression Callee
2584 | |-ThisExpression Object
2585 | | `-'this' IntroducerKeyword
2586 | |-'->' AccessToken
2587 | `-IdExpression Member
2588 | |-NestedNameSpecifier Qualifier
2589 | | |-IdentifierNameSpecifier ListElement
2591 | | `-'::' ListDelimiter
2592 | `-UnqualifiedId UnqualifiedId
2599 TEST_P(BuildSyntaxTreeTest
, CallExpression_Callee_FunctionPointer
) {
2600 if (!GetParam().isCXX()) {
2603 EXPECT_TRUE(treeDumpEqualOnAnnotations(
2612 CallExpression Expression
2613 |-IdExpression Callee
2614 | `-UnqualifiedId UnqualifiedId
2620 CallExpression Expression
2621 |-ParenExpression Callee
2623 | |-PrefixUnaryOperatorExpression SubExpression
2624 | | |-'*' OperatorToken
2625 | | `-IdExpression Operand
2626 | | `-UnqualifiedId UnqualifiedId
2634 TEST_P(BuildSyntaxTreeTest
, CallExpression_Callee_MemberFunctionPointer
) {
2635 if (!GetParam().isCXX()) {
2638 EXPECT_TRUE(treeDumpEqualOnAnnotations(
2650 CallExpression Expression
2651 |-ParenExpression Callee
2653 | |-BinaryOperatorExpression SubExpression
2654 | | |-IdExpression LeftHandSide
2655 | | | `-UnqualifiedId UnqualifiedId
2657 | | |-'.*' OperatorToken
2658 | | `-IdExpression RightHandSide
2659 | | `-UnqualifiedId UnqualifiedId
2667 TEST_P(BuildSyntaxTreeTest
, CallExpression_Arguments_Zero
) {
2668 if (!GetParam().isCXX()) {
2671 EXPECT_TRUE(treeDumpEqualOnAnnotations(
2679 ExpressionStatement Statement
2680 |-CallExpression Expression
2681 | |-IdExpression Callee
2682 | | `-UnqualifiedId UnqualifiedId
2690 TEST_P(BuildSyntaxTreeTest
, CallExpression_Arguments_One
) {
2691 if (!GetParam().isCXX()) {
2694 EXPECT_TRUE(treeDumpEqualOnAnnotations(
2702 ExpressionStatement Statement
2703 |-CallExpression Expression
2704 | |-IdExpression Callee
2705 | | `-UnqualifiedId UnqualifiedId
2708 | |-CallArguments Arguments
2709 | | `-IntegerLiteralExpression ListElement
2710 | | `-'1' LiteralToken
2716 TEST_P(BuildSyntaxTreeTest
, CallExpression_Arguments_Multiple
) {
2717 if (!GetParam().isCXX()) {
2720 EXPECT_TRUE(treeDumpEqualOnAnnotations(
2722 void f(int, char, float);
2728 ExpressionStatement Statement
2729 |-CallExpression Expression
2730 | |-IdExpression Callee
2731 | | `-UnqualifiedId UnqualifiedId
2734 | |-CallArguments Arguments
2735 | | |-IntegerLiteralExpression ListElement
2736 | | | `-'1' LiteralToken
2737 | | |-',' ListDelimiter
2738 | | |-CharacterLiteralExpression ListElement
2739 | | | `-''2'' LiteralToken
2740 | | |-',' ListDelimiter
2741 | | `-FloatingLiteralExpression ListElement
2742 | | `-'3.' LiteralToken
2748 TEST_P(BuildSyntaxTreeTest
, CallExpression_Arguments_Assignment
) {
2749 if (!GetParam().isCXX()) {
2752 EXPECT_TRUE(treeDumpEqualOnAnnotations(
2760 ExpressionStatement Statement
2761 |-CallExpression Expression
2762 | |-IdExpression Callee
2763 | | `-UnqualifiedId UnqualifiedId
2766 | |-CallArguments Arguments
2767 | | `-BinaryOperatorExpression ListElement
2768 | | |-IdExpression LeftHandSide
2769 | | | `-UnqualifiedId UnqualifiedId
2771 | | |-'=' OperatorToken
2772 | | `-IntegerLiteralExpression RightHandSide
2773 | | `-'1' LiteralToken
2779 TEST_P(BuildSyntaxTreeTest
, CallExpression_Arguments_BracedInitList_Empty
) {
2780 if (!GetParam().isCXX11OrLater()) {
2783 EXPECT_TRUE(treeDumpEqualOnAnnotations(
2791 ExpressionStatement Statement
2792 |-CallExpression Expression
2793 | |-IdExpression Callee
2794 | | `-UnqualifiedId UnqualifiedId
2797 | |-CallArguments Arguments
2798 | | `-UnknownExpression ListElement
2799 | | `-UnknownExpression
2807 TEST_P(BuildSyntaxTreeTest
, CallExpression_Arguments_BracedInitList_Simple
) {
2808 if (!GetParam().isCXX11OrLater()) {
2811 EXPECT_TRUE(treeDumpEqualOnAnnotations(
2824 ExpressionStatement Statement
2825 |-CallExpression Expression
2826 | |-IdExpression Callee
2827 | | `-UnqualifiedId UnqualifiedId
2830 | |-CallArguments Arguments
2831 | | `-UnknownExpression ListElement
2832 | | `-UnknownExpression
2834 | | |-IntegerLiteralExpression
2835 | | | `-'1' LiteralToken
2837 | | |-UnknownExpression
2838 | | | `-UnknownExpression
2847 TEST_P(BuildSyntaxTreeTest
,
2848 CallExpression_Arguments_BracedInitList_Designated
) {
2849 if (!GetParam().isCXX11OrLater()) {
2852 EXPECT_TRUE(treeDumpEqualOnAnnotations(
2861 [[f({.a = 1, .b {}});]]
2865 ExpressionStatement Statement
2866 |-CallExpression Expression
2867 | |-IdExpression Callee
2868 | | `-UnqualifiedId UnqualifiedId
2871 | |-CallArguments Arguments
2872 | | `-UnknownExpression ListElement
2873 | | `-UnknownExpression
2875 | | |-UnknownExpression
2879 | | | `-IntegerLiteralExpression
2880 | | | `-'1' LiteralToken
2882 | | |-UnknownExpression
2885 | | | `-UnknownExpression
2886 | | | `-UnknownExpression
2895 TEST_P(BuildSyntaxTreeTest
, CallExpression_Arguments_ParameterPack
) {
2896 if (!GetParam().isCXX11OrLater() || GetParam().hasDelayedTemplateParsing()) {
2899 EXPECT_TRUE(treeDumpEqualOnAnnotations(
2901 template<typename T, typename... Args>
2902 void test(T t, Args... args) {
2907 CallExpression Expression
2908 |-UnknownExpression Callee
2911 |-CallArguments Arguments
2912 | `-UnknownExpression ListElement
2914 | | `-UnqualifiedId UnqualifiedId
2921 TEST_P(BuildSyntaxTreeTest
, CallExpression_DefaultArguments
) {
2922 if (!GetParam().isCXX11OrLater()) {
2925 EXPECT_TRUE(treeDumpEqualOnAnnotations(
2927 void f(int i = 1, char c = '2');
2935 CallExpression Expression
2936 |-IdExpression Callee
2937 | `-UnqualifiedId UnqualifiedId
2943 CallExpression Expression
2944 |-IdExpression Callee
2945 | `-UnqualifiedId UnqualifiedId
2948 |-CallArguments Arguments
2949 | `-IntegerLiteralExpression ListElement
2950 | `-'1' LiteralToken
2954 CallExpression Expression
2955 |-IdExpression Callee
2956 | `-UnqualifiedId UnqualifiedId
2959 |-CallArguments Arguments
2960 | |-IntegerLiteralExpression ListElement
2961 | | `-'1' LiteralToken
2962 | |-',' ListDelimiter
2963 | `-CharacterLiteralExpression ListElement
2964 | `-''2'' LiteralToken
2969 TEST_P(BuildSyntaxTreeTest
, MultipleDeclaratorsGrouping
) {
2970 EXPECT_TRUE(treeDumpEqual(
2976 TranslationUnit Detached
2979 | |-DeclaratorList Declarators
2980 | | |-SimpleDeclarator ListElement
2983 | | |-',' ListDelimiter
2984 | | `-SimpleDeclarator ListElement
2989 |-DeclaratorList Declarators
2990 | |-SimpleDeclarator ListElement
2993 | |-',' ListDelimiter
2994 | `-SimpleDeclarator ListElement
3000 TEST_P(BuildSyntaxTreeTest
, MultipleDeclaratorsGroupingTypedef
) {
3001 EXPECT_TRUE(treeDumpEqual(
3006 TranslationUnit Detached
3010 |-DeclaratorList Declarators
3011 | |-SimpleDeclarator ListElement
3014 | |-',' ListDelimiter
3015 | `-SimpleDeclarator ListElement
3021 TEST_P(BuildSyntaxTreeTest
, MultipleDeclaratorsInsideStatement
) {
3022 EXPECT_TRUE(treeDumpEqual(
3026 typedef int *ta, tb;
3030 TranslationUnit Detached
3033 |-DeclaratorList Declarators
3034 | `-SimpleDeclarator ListElement
3036 | `-ParametersAndQualifiers
3041 |-DeclarationStatement Statement
3042 | |-SimpleDeclaration
3044 | | `-DeclaratorList Declarators
3045 | | |-SimpleDeclarator ListElement
3048 | | |-',' ListDelimiter
3049 | | `-SimpleDeclarator ListElement
3052 |-DeclarationStatement Statement
3053 | |-SimpleDeclaration
3056 | | `-DeclaratorList Declarators
3057 | | |-SimpleDeclarator ListElement
3060 | | |-',' ListDelimiter
3061 | | `-SimpleDeclarator ListElement
3068 TEST_P(BuildSyntaxTreeTest
, SizeTTypedef
) {
3069 if (!GetParam().isCXX11OrLater()) {
3072 EXPECT_TRUE(treeDumpEqual(
3074 typedef decltype(sizeof(void *)) size_t;
3077 TranslationUnit Detached
3089 |-DeclaratorList Declarators
3090 | `-SimpleDeclarator ListElement
3096 TEST_P(BuildSyntaxTreeTest
, Namespace_Nested
) {
3097 if (!GetParam().isCXX()) {
3100 EXPECT_TRUE(treeDumpEqual(
3102 namespace a { namespace b {} }
3105 TranslationUnit Detached
3106 `-NamespaceDefinition
3110 |-NamespaceDefinition
3119 TEST_P(BuildSyntaxTreeTest
, Namespace_NestedDefinition
) {
3120 if (!GetParam().isCXX17OrLater()) {
3123 EXPECT_TRUE(treeDumpEqual(
3128 TranslationUnit Detached
3129 `-NamespaceDefinition
3139 TEST_P(BuildSyntaxTreeTest
, Namespace_Unnamed
) {
3140 if (!GetParam().isCXX()) {
3143 EXPECT_TRUE(treeDumpEqual(
3148 TranslationUnit Detached
3149 `-NamespaceDefinition
3156 TEST_P(BuildSyntaxTreeTest
, Namespace_Alias
) {
3157 if (!GetParam().isCXX()) {
3160 EXPECT_TRUE(treeDumpEqualOnAnnotations(
3163 [[namespace foo = a;]]
3166 NamespaceAliasDefinition
3175 TEST_P(BuildSyntaxTreeTest
, UsingDirective
) {
3176 if (!GetParam().isCXX()) {
3179 EXPECT_TRUE(treeDumpEqualOnAnnotations(
3182 [[using namespace ::ns;]]
3185 UsingNamespaceDirective
3188 |-NestedNameSpecifier
3189 | `-'::' ListDelimiter
3195 TEST_P(BuildSyntaxTreeTest
, UsingDeclaration_Namespace
) {
3196 if (!GetParam().isCXX()) {
3199 EXPECT_TRUE(treeDumpEqualOnAnnotations(
3201 namespace ns { int a; }
3207 |-NestedNameSpecifier
3208 | |-IdentifierNameSpecifier ListElement
3210 | `-'::' ListDelimiter
3216 TEST_P(BuildSyntaxTreeTest
, UsingDeclaration_ClassMember
) {
3217 if (!GetParam().isCXX()) {
3220 EXPECT_TRUE(treeDumpEqualOnAnnotations(
3222 template <class T> struct X {
3224 [[using typename T::bar;]]
3230 |-NestedNameSpecifier
3231 | |-IdentifierNameSpecifier ListElement
3233 | `-'::' ListDelimiter
3241 |-NestedNameSpecifier
3242 | |-IdentifierNameSpecifier ListElement
3244 | `-'::' ListDelimiter
3250 TEST_P(BuildSyntaxTreeTest
, UsingTypeAlias
) {
3251 if (!GetParam().isCXX11OrLater()) {
3254 EXPECT_TRUE(treeDumpEqual(
3259 TranslationUnit Detached
3260 `-TypeAliasDeclaration
3269 TEST_P(BuildSyntaxTreeTest
, FreeStandingClass_ForwardDeclaration
) {
3270 EXPECT_TRUE(treeDumpEqualOnAnnotations(
3285 |-DeclaratorList Declarators
3286 | `-SimpleDeclarator ListElement
3293 TEST_P(BuildSyntaxTreeTest
, FreeStandingClasses_Definition
) {
3294 EXPECT_TRUE(treeDumpEqualOnAnnotations(
3297 [[struct Y {} *y2;]]
3314 |-DeclaratorList Declarators
3315 | `-SimpleDeclarator ListElement
3325 |-DeclaratorList Declarators
3326 | `-SimpleDeclarator ListElement
3333 TEST_P(BuildSyntaxTreeTest
, StaticMemberFunction
) {
3334 if (!GetParam().isCXX11OrLater()) {
3337 EXPECT_TRUE(treeDumpEqualOnAnnotations(
3340 [[static void f(){}]]
3347 |-DeclaratorList Declarators
3348 | `-SimpleDeclarator ListElement
3350 | `-ParametersAndQualifiers
3359 TEST_P(BuildSyntaxTreeTest
, OutOfLineMemberFunctionDefinition
) {
3360 if (!GetParam().isCXX11OrLater()) {
3363 EXPECT_TRUE(treeDumpEqualOnAnnotations(
3373 |-DeclaratorList Declarators
3374 | `-SimpleDeclarator ListElement
3375 | |-NestedNameSpecifier
3376 | | |-IdentifierNameSpecifier ListElement
3378 | | `-'::' ListDelimiter
3380 | `-ParametersAndQualifiers
3389 TEST_P(BuildSyntaxTreeTest
, ConversionMemberFunction
) {
3390 if (!GetParam().isCXX()) {
3393 EXPECT_TRUE(treeDumpEqualOnAnnotations(
3401 |-DeclaratorList Declarators
3402 | `-SimpleDeclarator ListElement
3405 | `-ParametersAndQualifiers
3412 TEST_P(BuildSyntaxTreeTest
, LiteralOperatorDeclaration
) {
3413 if (!GetParam().isCXX11OrLater()) {
3416 EXPECT_TRUE(treeDumpEqual(
3418 unsigned operator "" _c(char);
3421 TranslationUnit Detached
3424 |-DeclaratorList Declarators
3425 | `-SimpleDeclarator ListElement
3429 | `-ParametersAndQualifiers
3431 | |-ParameterDeclarationList Parameters
3432 | | `-SimpleDeclaration ListElement
3439 TEST_P(BuildSyntaxTreeTest
, NumericLiteralOperatorTemplateDeclaration
) {
3440 if (!GetParam().isCXX11OrLater()) {
3443 EXPECT_TRUE(treeDumpEqual(
3446 unsigned operator "" _t();
3449 TranslationUnit Detached
3450 `-TemplateDeclaration Declaration
3451 |-'template' IntroducerKeyword
3459 |-DeclaratorList Declarators
3460 | `-SimpleDeclarator ListElement
3464 | `-ParametersAndQualifiers
3471 TEST_P(BuildSyntaxTreeTest
, OverloadedOperatorDeclaration
) {
3472 if (!GetParam().isCXX()) {
3475 EXPECT_TRUE(treeDumpEqualOnAnnotations(
3478 [[X& operator=(const X&);]]
3484 |-DeclaratorList Declarators
3485 | `-SimpleDeclarator ListElement
3489 | `-ParametersAndQualifiers
3491 | |-ParameterDeclarationList Parameters
3492 | | `-SimpleDeclaration ListElement
3495 | | `-DeclaratorList Declarators
3496 | | `-SimpleDeclarator ListElement
3503 TEST_P(BuildSyntaxTreeTest
, OverloadedOperatorFriendDeclaration
) {
3504 if (!GetParam().isCXX()) {
3507 EXPECT_TRUE(treeDumpEqualOnAnnotations(
3510 [[friend X operator+(X, const X&);]]
3518 |-DeclaratorList Declarators
3519 | `-SimpleDeclarator ListElement
3522 | `-ParametersAndQualifiers
3524 | |-ParameterDeclarationList Parameters
3525 | | |-SimpleDeclaration ListElement
3527 | | |-',' ListDelimiter
3528 | | `-SimpleDeclaration ListElement
3531 | | `-DeclaratorList Declarators
3532 | | `-SimpleDeclarator ListElement
3539 TEST_P(BuildSyntaxTreeTest
, ClassTemplateDeclaration
) {
3540 if (!GetParam().isCXX()) {
3543 EXPECT_TRUE(treeDumpEqual(
3545 template<typename T>
3549 TranslationUnit Detached
3550 `-TemplateDeclaration Declaration
3551 |-'template' IntroducerKeyword
3553 |-UnknownDeclaration
3566 TEST_P(BuildSyntaxTreeTest
, FunctionTemplateDeclaration
) {
3567 if (!GetParam().isCXX()) {
3570 EXPECT_TRUE(treeDumpEqual(
3572 template<typename T>
3576 TranslationUnit Detached
3577 `-TemplateDeclaration Declaration
3578 |-'template' IntroducerKeyword
3580 |-UnknownDeclaration
3586 |-DeclaratorList Declarators
3587 | `-SimpleDeclarator ListElement
3589 | `-ParametersAndQualifiers
3596 TEST_P(BuildSyntaxTreeTest
, VariableTemplateDeclaration
) {
3597 if (!GetParam().isCXX14OrLater()) {
3600 EXPECT_TRUE(treeDumpEqual(
3602 template <class T> T var = 10;
3605 TranslationUnit Detached
3606 `-TemplateDeclaration Declaration
3607 |-'template' IntroducerKeyword
3609 |-UnknownDeclaration
3615 |-DeclaratorList Declarators
3616 | `-SimpleDeclarator ListElement
3619 | `-IntegerLiteralExpression
3620 | `-'10' LiteralToken
3625 TEST_P(BuildSyntaxTreeTest
, StaticMemberFunctionTemplate
) {
3626 if (!GetParam().isCXX()) {
3629 EXPECT_TRUE(treeDumpEqualOnAnnotations(
3632 [[template<typename U>
3637 TemplateDeclaration Declaration
3638 |-'template' IntroducerKeyword
3640 |-UnknownDeclaration
3647 |-DeclaratorList Declarators
3648 | `-SimpleDeclarator ListElement
3650 | `-ParametersAndQualifiers
3657 TEST_P(BuildSyntaxTreeTest
, NestedTemplates
) {
3658 if (!GetParam().isCXX()) {
3661 EXPECT_TRUE(treeDumpEqual(
3670 TranslationUnit Detached
3671 `-TemplateDeclaration Declaration
3672 |-'template' IntroducerKeyword
3674 |-UnknownDeclaration
3682 |-TemplateDeclaration Declaration
3683 | |-'template' IntroducerKeyword
3685 | |-UnknownDeclaration
3689 | `-SimpleDeclaration
3691 | |-DeclaratorList Declarators
3692 | | `-SimpleDeclarator ListElement
3694 | | `-ParametersAndQualifiers
3696 | | `-')' CloseParen
3703 TEST_P(BuildSyntaxTreeTest
, NestedTemplatesInNamespace
) {
3704 if (!GetParam().isCXX()) {
3707 EXPECT_TRUE(treeDumpEqual(
3710 template<typename T>
3712 template<typename U>
3718 TranslationUnit Detached
3719 `-NamespaceDefinition
3723 |-TemplateDeclaration Declaration
3724 | |-'template' IntroducerKeyword
3726 | |-UnknownDeclaration
3730 | `-SimpleDeclaration
3734 | |-TemplateDeclaration Declaration
3735 | | |-'template' IntroducerKeyword
3737 | | |-UnknownDeclaration
3741 | | `-SimpleDeclaration
3744 | | |-DeclaratorList Declarators
3745 | | | `-SimpleDeclarator ListElement
3747 | | | `-ParametersAndQualifiers
3748 | | | |-'(' OpenParen
3749 | | | `-')' CloseParen
3757 TEST_P(BuildSyntaxTreeTest
, ClassTemplate_MemberClassDefinition
) {
3758 if (!GetParam().isCXX()) {
3761 EXPECT_TRUE(treeDumpEqualOnAnnotations(
3763 template <class T> struct X { struct Y; };
3764 [[template <class T> struct X<T>::Y {};]]
3767 TemplateDeclaration Declaration
3768 |-'template' IntroducerKeyword
3770 |-UnknownDeclaration
3776 |-NestedNameSpecifier
3777 | |-SimpleTemplateNameSpecifier ListElement
3782 | `-'::' ListDelimiter
3790 TEST_P(BuildSyntaxTreeTest
, ExplicitClassTemplateInstantiation_Definition
) {
3791 if (!GetParam().isCXX()) {
3794 EXPECT_TRUE(treeDumpEqualOnAnnotations(
3796 template <class T> struct X {};
3797 [[template struct X<double>;]]
3800 ExplicitTemplateInstantiation
3801 |-'template' IntroducerKeyword
3802 `-SimpleDeclaration Declaration
3812 TEST_P(BuildSyntaxTreeTest
, ExplicitClassTemplateInstantiation_Declaration
) {
3813 if (!GetParam().isCXX()) {
3816 EXPECT_TRUE(treeDumpEqualOnAnnotations(
3818 template <class T> struct X {};
3819 [[extern template struct X<float>;]]
3822 ExplicitTemplateInstantiation
3823 |-'extern' ExternKeyword
3824 |-'template' IntroducerKeyword
3825 `-SimpleDeclaration Declaration
3835 TEST_P(BuildSyntaxTreeTest
, ClassTemplateSpecialization_Partial
) {
3836 if (!GetParam().isCXX()) {
3839 EXPECT_TRUE(treeDumpEqualOnAnnotations(
3841 template <class T> struct X {};
3842 [[template <class T> struct X<T*> {};]]
3845 TemplateDeclaration Declaration
3846 |-'template' IntroducerKeyword
3848 |-UnknownDeclaration
3865 TEST_P(BuildSyntaxTreeTest
, ClassTemplateSpecialization_Full
) {
3866 if (!GetParam().isCXX()) {
3869 EXPECT_TRUE(treeDumpEqualOnAnnotations(
3871 template <class T> struct X {};
3872 [[template <> struct X<int> {};]]
3875 TemplateDeclaration Declaration
3876 |-'template' IntroducerKeyword
3891 TEST_P(BuildSyntaxTreeTest
, EmptyDeclaration
) {
3892 EXPECT_TRUE(treeDumpEqual(
3897 TranslationUnit Detached
3903 TEST_P(BuildSyntaxTreeTest
, StaticAssert
) {
3904 if (!GetParam().isCXX11OrLater()) {
3907 EXPECT_TRUE(treeDumpEqual(
3909 static_assert(true, "message
");
3912 TranslationUnit Detached
3913 `-StaticAssertDeclaration
3916 |-BoolLiteralExpression Condition
3917 | `-'true' LiteralToken
3919 |-StringLiteralExpression Message
3920 | `-'"message
"' LiteralToken
3926 TEST_P(BuildSyntaxTreeTest
, StaticAssert_WithoutMessage
) {
3927 if (!GetParam().isCXX17OrLater()) {
3930 EXPECT_TRUE(treeDumpEqual(
3932 static_assert(true);
3935 TranslationUnit Detached
3936 `-StaticAssertDeclaration
3939 |-BoolLiteralExpression Condition
3940 | `-'true' LiteralToken
3946 TEST_P(BuildSyntaxTreeTest
, ExternC
) {
3947 if (!GetParam().isCXX()) {
3950 EXPECT_TRUE(treeDumpEqual(
3953 extern "C
" { int b; int c; }
3956 TranslationUnit Detached
3957 |-LinkageSpecificationDeclaration
3960 | `-SimpleDeclaration
3962 | |-DeclaratorList Declarators
3963 | | `-SimpleDeclarator ListElement
3966 `-LinkageSpecificationDeclaration
3972 | |-DeclaratorList Declarators
3973 | | `-SimpleDeclarator ListElement
3978 | |-DeclaratorList Declarators
3979 | | `-SimpleDeclarator ListElement
3986 TEST_P(BuildSyntaxTreeTest
, Macro_ObjectLike_Leaf
) {
3987 // All nodes can be mutated.
3988 EXPECT_TRUE(treeDumpEqual(
4004 TranslationUnit Detached
4007 |-DeclaratorList Declarators
4008 | `-SimpleDeclarator ListElement
4010 | `-ParametersAndQualifiers
4015 |-CompoundStatement Statement
4017 | |-ExpressionStatement Statement
4018 | | |-IntegerLiteralExpression Expression
4019 | | | `-'1' LiteralToken
4022 |-CompoundStatement Statement
4024 | |-ExpressionStatement Statement
4025 | | |-IntegerLiteralExpression Expression
4026 | | | `-'2' LiteralToken
4033 TEST_P(BuildSyntaxTreeTest
, Macro_ObjectLike_MatchTree
) {
4034 // Some nodes are unmodifiable, they are marked with 'unmodifiable'.
4035 EXPECT_TRUE(treeDumpEqual(
4042 TranslationUnit Detached
4045 |-DeclaratorList Declarators
4046 | `-SimpleDeclarator ListElement
4048 | `-ParametersAndQualifiers
4052 |-'{' OpenParen unmodifiable
4053 `-'}' CloseParen unmodifiable
4057 TEST_P(BuildSyntaxTreeTest
, Macro_ObjectLike_MismatchTree
) {
4058 EXPECT_TRUE(treeDumpEqual(
4060 #define HALF_IF if (1+
4061 #define HALF_IF_2 1) {}
4063 HALF_IF HALF_IF_2 else {}
4066 TranslationUnit Detached
4069 |-DeclaratorList Declarators
4070 | `-SimpleDeclarator ListElement
4072 | `-ParametersAndQualifiers
4077 |-IfStatement Statement
4078 | |-'if' IntroducerKeyword unmodifiable
4079 | |-'(' unmodifiable
4080 | |-ExpressionStatement Condition unmodifiable
4081 | | `-BinaryOperatorExpression Expression unmodifiable
4082 | | |-IntegerLiteralExpression LeftHandSide unmodifiable
4083 | | | `-'1' LiteralToken unmodifiable
4084 | | |-'+' OperatorToken unmodifiable
4085 | | `-IntegerLiteralExpression RightHandSide unmodifiable
4086 | | `-'1' LiteralToken unmodifiable
4087 | |-')' unmodifiable
4088 | |-CompoundStatement ThenStatement unmodifiable
4089 | | |-'{' OpenParen unmodifiable
4090 | | `-'}' CloseParen unmodifiable
4091 | |-'else' ElseKeyword
4092 | `-CompoundStatement ElseStatement
4099 TEST_P(BuildSyntaxTreeTest
, Macro_FunctionLike_ModifiableArguments
) {
4100 // FIXME: Note that the substitutions for `X` and `Y` are marked modifiable.
4101 // However we cannot change `X` freely. Indeed if we change its substitution
4102 // in the condition we should also change it the then-branch.
4103 EXPECT_TRUE(treeDumpEqual(
4105 #define MIN(X,Y) X < Y ? X : Y
4112 TranslationUnit Detached
4115 |-DeclaratorList Declarators
4116 | `-SimpleDeclarator ListElement
4118 | `-ParametersAndQualifiers
4123 |-ExpressionStatement Statement
4124 | |-UnknownExpression Expression
4125 | | |-BinaryOperatorExpression unmodifiable
4126 | | | |-IntegerLiteralExpression LeftHandSide
4127 | | | | `-'1' LiteralToken
4128 | | | |-'<' OperatorToken unmodifiable
4129 | | | `-IntegerLiteralExpression RightHandSide
4130 | | | `-'2' LiteralToken
4131 | | |-'?' unmodifiable
4132 | | |-IntegerLiteralExpression
4133 | | | `-'1' LiteralToken
4134 | | |-':' unmodifiable
4135 | | `-IntegerLiteralExpression
4136 | | `-'2' LiteralToken
4142 TEST_P(BuildSyntaxTreeTest
, Macro_FunctionLike_MismatchTree
) {
4143 EXPECT_TRUE(treeDumpEqual(
4145 #define HALF_IF(X) if (X &&
4146 #define HALF_IF_2(Y) Y) {}
4148 HALF_IF(1) HALF_IF_2(0) else {}
4151 TranslationUnit Detached
4154 |-DeclaratorList Declarators
4155 | `-SimpleDeclarator ListElement
4157 | `-ParametersAndQualifiers
4162 |-IfStatement Statement
4163 | |-'if' IntroducerKeyword unmodifiable
4164 | |-'(' unmodifiable
4165 | |-ExpressionStatement Condition unmodifiable
4166 | | `-BinaryOperatorExpression Expression unmodifiable
4167 | | |-IntegerLiteralExpression LeftHandSide
4168 | | | `-'1' LiteralToken
4169 | | |-'&&' OperatorToken unmodifiable
4170 | | `-IntegerLiteralExpression RightHandSide
4171 | | `-'0' LiteralToken
4172 | |-')' unmodifiable
4173 | |-CompoundStatement ThenStatement unmodifiable
4174 | | |-'{' OpenParen unmodifiable
4175 | | `-'}' CloseParen unmodifiable
4176 | |-'else' ElseKeyword
4177 | `-CompoundStatement ElseStatement
4184 TEST_P(BuildSyntaxTreeTest
, Macro_FunctionLike_Variadic
) {
4185 EXPECT_TRUE(treeDumpEqualOnAnnotations(
4187 #define CALL(F_NAME, ...) F_NAME(__VA_ARGS__)
4199 |-ExpressionStatement Statement
4200 | |-CallExpression Expression
4201 | | |-IdExpression Callee
4202 | | | `-UnqualifiedId UnqualifiedId
4204 | | |-'(' OpenParen unmodifiable
4205 | | |-CallArguments Arguments
4206 | | | `-IntegerLiteralExpression ListElement
4207 | | | `-'0' LiteralToken
4208 | | `-')' CloseParen unmodifiable
4210 |-ExpressionStatement Statement
4211 | |-CallExpression Expression
4212 | | |-IdExpression Callee
4213 | | | `-UnqualifiedId UnqualifiedId
4215 | | |-'(' OpenParen unmodifiable
4216 | | |-CallArguments Arguments
4217 | | | |-IntegerLiteralExpression ListElement
4218 | | | | `-'0' LiteralToken
4219 | | | |-',' ListDelimiter
4220 | | | `-IntegerLiteralExpression ListElement
4221 | | | `-'1' LiteralToken
4222 | | `-')' CloseParen unmodifiable
4228 TEST_P(BuildSyntaxTreeTest
, InitDeclarator_Equal
) {
4229 if (!GetParam().isCXX()) {
4232 EXPECT_TRUE(treeDumpEqualOnAnnotations(
4234 struct S { S(int);};
4242 `-DeclaratorList Declarators
4243 `-SimpleDeclarator ListElement
4246 `-IntegerLiteralExpression
4251 TEST_P(BuildSyntaxTreeTest
, InitDeclarator_Brace
) {
4252 if (!GetParam().isCXX11OrLater()) {
4255 EXPECT_TRUE(treeDumpEqualOnAnnotations(
4263 // FIXME: 's...' is a declarator and '{...}' is initializer
4272 `-DeclaratorList Declarators
4273 `-SimpleDeclarator ListElement
4282 `-DeclaratorList Declarators
4283 `-SimpleDeclarator ListElement
4287 |-IntegerLiteralExpression
4288 | `-'1' LiteralToken
4294 `-DeclaratorList Declarators
4295 `-SimpleDeclarator ListElement
4299 |-IntegerLiteralExpression
4300 | `-'1' LiteralToken
4302 |-FloatingLiteralExpression
4303 | `-'2.' LiteralToken
4308 TEST_P(BuildSyntaxTreeTest
, InitDeclarator_EqualBrace
) {
4309 if (!GetParam().isCXX11OrLater()) {
4312 EXPECT_TRUE(treeDumpEqualOnAnnotations(
4320 // FIXME: '= {...}' is initializer
4329 `-DeclaratorList Declarators
4330 `-SimpleDeclarator ListElement
4340 `-DeclaratorList Declarators
4341 `-SimpleDeclarator ListElement
4346 |-IntegerLiteralExpression
4347 | `-'1' LiteralToken
4353 `-DeclaratorList Declarators
4354 `-SimpleDeclarator ListElement
4359 |-IntegerLiteralExpression
4360 | `-'1' LiteralToken
4362 |-FloatingLiteralExpression
4363 | `-'2.' LiteralToken
4368 TEST_P(BuildSyntaxTreeTest
, InitDeclarator_Paren
) {
4369 if (!GetParam().isCXX()) {
4372 EXPECT_TRUE(treeDumpEqualOnAnnotations(
4378 // FIXME: 's...' is a declarator and '(...)' is initializer
4385 |-DeclaratorList Declarators
4386 | `-SimpleDeclarator ListElement
4387 | `-UnknownExpression
4390 | |-IntegerLiteralExpression
4391 | | `-'1' LiteralToken
4398 |-DeclaratorList Declarators
4399 | `-SimpleDeclarator ListElement
4400 | `-UnknownExpression
4403 | |-IntegerLiteralExpression
4404 | | `-'1' LiteralToken
4406 | |-FloatingLiteralExpression
4407 | | `-'2.' LiteralToken
4413 TEST_P(BuildSyntaxTreeTest
, InitDeclarator_Paren_DefaultArguments
) {
4414 if (!GetParam().isCXX()) {
4417 EXPECT_TRUE(treeDumpEqualOnAnnotations(
4420 S(int i = 1, float = 2.);
4423 // FIXME: 's...' is a declarator and '(...)' is initializer
4430 |-DeclaratorList Declarators
4431 | `-SimpleDeclarator ListElement
4438 |-DeclaratorList Declarators
4439 | `-SimpleDeclarator ListElement
4440 | `-UnknownExpression
4443 | |-IntegerLiteralExpression
4444 | | `-'1' LiteralToken
4451 |-DeclaratorList Declarators
4452 | `-SimpleDeclarator ListElement
4453 | `-UnknownExpression
4456 | |-IntegerLiteralExpression
4457 | | `-'1' LiteralToken
4459 | |-FloatingLiteralExpression
4460 | | `-'2.' LiteralToken
4466 TEST_P(BuildSyntaxTreeTest
, ImplicitConversion_Argument
) {
4467 if (!GetParam().isCXX()) {
4470 EXPECT_TRUE(treeDumpEqualOnAnnotations(
4475 void TakeX(const X&);
4481 CallExpression Expression
4482 |-IdExpression Callee
4483 | `-UnqualifiedId UnqualifiedId
4486 |-CallArguments Arguments
4487 | `-IntegerLiteralExpression ListElement
4488 | `-'1' LiteralToken
4493 TEST_P(BuildSyntaxTreeTest
, ImplicitConversion_Return
) {
4494 if (!GetParam().isCXX()) {
4497 EXPECT_TRUE(treeDumpEqualOnAnnotations(
4507 ReturnStatement Statement
4508 |-'return' IntroducerKeyword
4509 |-IntegerLiteralExpression ReturnValue
4510 | `-'1' LiteralToken
4515 TEST_P(BuildSyntaxTreeTest
, ConstructorCall_ZeroArguments
) {
4516 if (!GetParam().isCXX()) {
4519 EXPECT_TRUE(treeDumpEqualOnAnnotations(
4529 ReturnStatement Statement
4530 |-'return' IntroducerKeyword
4531 |-UnknownExpression ReturnValue
4539 TEST_P(BuildSyntaxTreeTest
, ConstructorCall_OneArgument
) {
4540 if (!GetParam().isCXX()) {
4543 EXPECT_TRUE(treeDumpEqualOnAnnotations(
4553 ReturnStatement Statement
4554 |-'return' IntroducerKeyword
4555 |-UnknownExpression ReturnValue
4558 | |-IntegerLiteralExpression
4559 | | `-'1' LiteralToken
4565 TEST_P(BuildSyntaxTreeTest
, ConstructorCall_MultipleArguments
) {
4566 if (!GetParam().isCXX()) {
4569 EXPECT_TRUE(treeDumpEqualOnAnnotations(
4575 [[return X(1, '2');]]
4579 ReturnStatement Statement
4580 |-'return' IntroducerKeyword
4581 |-UnknownExpression ReturnValue
4584 | |-IntegerLiteralExpression
4585 | | `-'1' LiteralToken
4587 | |-CharacterLiteralExpression
4588 | | `-''2'' LiteralToken
4594 TEST_P(BuildSyntaxTreeTest
, ConstructorCall_DefaultArguments
) {
4595 if (!GetParam().isCXX()) {
4598 EXPECT_TRUE(treeDumpEqualOnAnnotations(
4601 X(int i = 1, char c = '2');
4606 auto x2 = [[X(1, '2')]];
4619 |-IntegerLiteralExpression
4620 | `-'1' LiteralToken
4627 |-IntegerLiteralExpression
4628 | `-'1' LiteralToken
4630 |-CharacterLiteralExpression
4631 | `-''2'' LiteralToken
4636 TEST_P(BuildSyntaxTreeTest
, TypeConversion_FunctionalNotation
) {
4637 if (!GetParam().isCXX()) {
4640 EXPECT_TRUE(treeDumpEqualOnAnnotations(
4643 [[return float(1);]]
4647 ReturnStatement Statement
4648 |-'return' IntroducerKeyword
4649 |-UnknownExpression ReturnValue
4652 | |-IntegerLiteralExpression
4653 | | `-'1' LiteralToken
4659 TEST_P(BuildSyntaxTreeTest
, ArrayDeclarator_Simple
) {
4660 EXPECT_TRUE(treeDumpEqual(
4665 TranslationUnit Detached
4668 |-DeclaratorList Declarators
4669 | `-SimpleDeclarator ListElement
4673 | |-IntegerLiteralExpression Size
4674 | | `-'10' LiteralToken
4680 TEST_P(BuildSyntaxTreeTest
, ArrayDeclarator_Multidimensional
) {
4681 EXPECT_TRUE(treeDumpEqual(
4686 TranslationUnit Detached
4689 |-DeclaratorList Declarators
4690 | `-SimpleDeclarator ListElement
4694 | | |-IntegerLiteralExpression Size
4695 | | | `-'1' LiteralToken
4696 | | `-']' CloseParen
4699 | | |-IntegerLiteralExpression Size
4700 | | | `-'2' LiteralToken
4701 | | `-']' CloseParen
4704 | |-IntegerLiteralExpression Size
4705 | | `-'3' LiteralToken
4711 TEST_P(BuildSyntaxTreeTest
, ArrayDeclarator_UnknownBound
) {
4712 EXPECT_TRUE(treeDumpEqual(
4717 TranslationUnit Detached
4720 |-DeclaratorList Declarators
4721 | `-SimpleDeclarator ListElement
4725 | | `-']' CloseParen
4727 | `-UnknownExpression
4728 | `-UnknownExpression
4730 | |-IntegerLiteralExpression
4731 | | `-'1' LiteralToken
4733 | |-IntegerLiteralExpression
4734 | | `-'2' LiteralToken
4736 | |-IntegerLiteralExpression
4737 | | `-'3' LiteralToken
4743 TEST_P(BuildSyntaxTreeTest
, ArrayDeclarator_Static
) {
4744 if (!GetParam().isC99OrLater()) {
4747 EXPECT_TRUE(treeDumpEqual(
4749 void f(int xs[static 10]);
4752 TranslationUnit Detached
4755 |-DeclaratorList Declarators
4756 | `-SimpleDeclarator ListElement
4758 | `-ParametersAndQualifiers
4760 | |-ParameterDeclarationList Parameters
4761 | | `-SimpleDeclaration ListElement
4763 | | `-DeclaratorList Declarators
4764 | | `-SimpleDeclarator ListElement
4766 | | `-ArraySubscript
4769 | | |-IntegerLiteralExpression Size
4770 | | | `-'10' LiteralToken
4771 | | `-']' CloseParen
4777 TEST_P(BuildSyntaxTreeTest
, ParametersAndQualifiers_InFreeFunctions_Empty
) {
4778 EXPECT_TRUE(treeDumpEqual(
4783 TranslationUnit Detached
4786 |-DeclaratorList Declarators
4787 | `-SimpleDeclarator ListElement
4789 | `-ParametersAndQualifiers
4796 TEST_P(BuildSyntaxTreeTest
, ParametersAndQualifiers_InFreeFunctions_Named
) {
4797 EXPECT_TRUE(treeDumpEqualOnAnnotations(
4799 int func1([[int a]]);
4800 int func2([[int *ap]]);
4801 int func3([[int a, float b]]);
4802 int func4([[undef a]]); // error-ok: no crash on invalid type
4805 ParameterDeclarationList Parameters
4806 `-SimpleDeclaration ListElement
4808 `-DeclaratorList Declarators
4809 `-SimpleDeclarator ListElement
4813 ParameterDeclarationList Parameters
4814 `-SimpleDeclaration ListElement
4816 `-DeclaratorList Declarators
4817 `-SimpleDeclarator ListElement
4822 ParameterDeclarationList Parameters
4823 |-SimpleDeclaration ListElement
4825 | `-DeclaratorList Declarators
4826 | `-SimpleDeclarator ListElement
4829 `-SimpleDeclaration ListElement
4831 `-DeclaratorList Declarators
4832 `-SimpleDeclarator ListElement
4836 ParameterDeclarationList Parameters
4837 `-SimpleDeclaration ListElement
4839 `-DeclaratorList Declarators
4840 `-SimpleDeclarator ListElement
4845 TEST_P(BuildSyntaxTreeTest
, ParametersAndQualifiers_InFreeFunctions_Unnamed
) {
4846 EXPECT_TRUE(treeDumpEqual(
4850 int func3(int, float);
4853 TranslationUnit Detached
4856 | |-DeclaratorList Declarators
4857 | | `-SimpleDeclarator ListElement
4859 | | `-ParametersAndQualifiers
4861 | | |-ParameterDeclarationList Parameters
4862 | | | `-SimpleDeclaration ListElement
4864 | | `-')' CloseParen
4868 | |-DeclaratorList Declarators
4869 | | `-SimpleDeclarator ListElement
4871 | | `-ParametersAndQualifiers
4873 | | |-ParameterDeclarationList Parameters
4874 | | | `-SimpleDeclaration ListElement
4876 | | | `-DeclaratorList Declarators
4877 | | | `-SimpleDeclarator ListElement
4879 | | `-')' CloseParen
4883 |-DeclaratorList Declarators
4884 | `-SimpleDeclarator ListElement
4886 | `-ParametersAndQualifiers
4888 | |-ParameterDeclarationList Parameters
4889 | | |-SimpleDeclaration ListElement
4891 | | |-',' ListDelimiter
4892 | | `-SimpleDeclaration ListElement
4899 TEST_P(BuildSyntaxTreeTest
,
4900 ParametersAndQualifiers_InFreeFunctions_Default_One
) {
4901 if (!GetParam().isCXX()) {
4904 EXPECT_TRUE(treeDumpEqualOnAnnotations(
4906 int func1([[int a = 1]]);
4909 ParameterDeclarationList Parameters
4910 `-SimpleDeclaration ListElement
4912 `-DeclaratorList Declarators
4913 `-SimpleDeclarator ListElement
4916 `-IntegerLiteralExpression
4921 TEST_P(BuildSyntaxTreeTest
,
4922 ParametersAndQualifiers_InFreeFunctions_Default_Multiple
) {
4923 if (!GetParam().isCXX()) {
4926 EXPECT_TRUE(treeDumpEqualOnAnnotations(
4928 int func2([[int *ap, int a = 1, char c = '2']]);
4931 ParameterDeclarationList Parameters
4932 |-SimpleDeclaration ListElement
4934 | `-DeclaratorList Declarators
4935 | `-SimpleDeclarator ListElement
4939 |-SimpleDeclaration ListElement
4941 | `-DeclaratorList Declarators
4942 | `-SimpleDeclarator ListElement
4945 | `-IntegerLiteralExpression
4946 | `-'1' LiteralToken
4948 `-SimpleDeclaration ListElement
4950 `-DeclaratorList Declarators
4951 `-SimpleDeclarator ListElement
4954 `-CharacterLiteralExpression
4955 `-''2'' LiteralToken
4959 TEST_P(BuildSyntaxTreeTest
,
4960 ParametersAndQualifiers_InVariadicFunctionTemplate_ParameterPack
) {
4961 if (!GetParam().isCXX11OrLater() || GetParam().hasDelayedTemplateParsing()) {
4964 EXPECT_TRUE(treeDumpEqualOnAnnotations(
4966 template<typename T, typename... Args>
4967 [[void test(T , Args... );]]
4972 |-DeclaratorList Declarators
4973 | `-SimpleDeclarator ListElement
4975 | `-ParametersAndQualifiers
4977 | |-ParameterDeclarationList Parameters
4978 | | |-SimpleDeclaration ListElement
4980 | | |-',' ListDelimiter
4981 | | `-SimpleDeclaration ListElement
4989 TEST_P(BuildSyntaxTreeTest
,
4990 ParametersAndQualifiers_InVariadicFunctionTemplate_NamedParameterPack
) {
4991 if (!GetParam().isCXX11OrLater() || GetParam().hasDelayedTemplateParsing()) {
4994 EXPECT_TRUE(treeDumpEqualOnAnnotations(
4996 template<typename T, typename... Args>
4997 [[void test(T t, Args... args);]]
5002 |-DeclaratorList Declarators
5003 | `-SimpleDeclarator ListElement
5005 | `-ParametersAndQualifiers
5007 | |-ParameterDeclarationList Parameters
5008 | | |-SimpleDeclaration ListElement
5010 | | | `-DeclaratorList Declarators
5011 | | | `-SimpleDeclarator ListElement
5013 | | |-',' ListDelimiter
5014 | | `-SimpleDeclaration ListElement
5017 | | `-DeclaratorList Declarators
5018 | | `-SimpleDeclarator ListElement
5025 TEST_P(BuildSyntaxTreeTest
,
5026 ParametersAndQualifiers_InFreeFunctions_VariadicArguments
) {
5027 if (!GetParam().isCXX11OrLater()) {
5030 EXPECT_TRUE(treeDumpEqual(
5032 void test(int , char ...);
5035 TranslationUnit Detached
5038 |-DeclaratorList Declarators
5039 | `-SimpleDeclarator ListElement
5041 | `-ParametersAndQualifiers
5043 | |-ParameterDeclarationList Parameters
5044 | | |-SimpleDeclaration ListElement
5046 | | |-',' ListDelimiter
5047 | | `-SimpleDeclaration ListElement
5055 TEST_P(BuildSyntaxTreeTest
,
5056 ParametersAndQualifiers_InFreeFunctions_Cxx_CvQualifiers
) {
5057 if (!GetParam().isCXX()) {
5060 EXPECT_TRUE(treeDumpEqual(
5062 int func(const int a, volatile int b, const volatile int c);
5065 TranslationUnit Detached
5068 |-DeclaratorList Declarators
5069 | `-SimpleDeclarator ListElement
5071 | `-ParametersAndQualifiers
5073 | |-ParameterDeclarationList Parameters
5074 | | |-SimpleDeclaration ListElement
5077 | | | `-DeclaratorList Declarators
5078 | | | `-SimpleDeclarator ListElement
5080 | | |-',' ListDelimiter
5081 | | |-SimpleDeclaration ListElement
5084 | | | `-DeclaratorList Declarators
5085 | | | `-SimpleDeclarator ListElement
5087 | | |-',' ListDelimiter
5088 | | `-SimpleDeclaration ListElement
5092 | | `-DeclaratorList Declarators
5093 | | `-SimpleDeclarator ListElement
5100 TEST_P(BuildSyntaxTreeTest
, ParametersAndQualifiers_InFreeFunctions_Cxx_Ref
) {
5101 if (!GetParam().isCXX()) {
5104 EXPECT_TRUE(treeDumpEqual(
5109 TranslationUnit Detached
5112 |-DeclaratorList Declarators
5113 | `-SimpleDeclarator ListElement
5115 | `-ParametersAndQualifiers
5117 | |-ParameterDeclarationList Parameters
5118 | | `-SimpleDeclaration ListElement
5120 | | `-DeclaratorList Declarators
5121 | | `-SimpleDeclarator ListElement
5129 TEST_P(BuildSyntaxTreeTest
,
5130 ParametersAndQualifiers_InFreeFunctions_Cxx11_RefRef
) {
5131 if (!GetParam().isCXX11OrLater()) {
5134 EXPECT_TRUE(treeDumpEqual(
5139 TranslationUnit Detached
5142 |-DeclaratorList Declarators
5143 | `-SimpleDeclarator ListElement
5145 | `-ParametersAndQualifiers
5147 | |-ParameterDeclarationList Parameters
5148 | | `-SimpleDeclaration ListElement
5150 | | `-DeclaratorList Declarators
5151 | | `-SimpleDeclarator ListElement
5159 TEST_P(BuildSyntaxTreeTest
, ParametersAndQualifiers_InMemberFunctions_Simple
) {
5160 if (!GetParam().isCXX()) {
5163 EXPECT_TRUE(treeDumpEqual(
5170 TranslationUnit Detached
5177 | |-DeclaratorList Declarators
5178 | | `-SimpleDeclarator ListElement
5180 | | `-ParametersAndQualifiers
5182 | | `-')' CloseParen
5189 TEST_P(BuildSyntaxTreeTest
,
5190 ParametersAndQualifiers_InMemberFunctions_CvQualifiers
) {
5191 if (!GetParam().isCXX()) {
5194 EXPECT_TRUE(treeDumpEqualOnAnnotations(
5198 [[int c() volatile;]]
5199 [[int d() const volatile;]]
5205 |-DeclaratorList Declarators
5206 | `-SimpleDeclarator ListElement
5208 | `-ParametersAndQualifiers
5217 |-DeclaratorList Declarators
5218 | `-SimpleDeclarator ListElement
5220 | `-ParametersAndQualifiers
5229 |-DeclaratorList Declarators
5230 | `-SimpleDeclarator ListElement
5232 | `-ParametersAndQualifiers
5241 TEST_P(BuildSyntaxTreeTest
, ParametersAndQualifiers_InMemberFunctions_Ref
) {
5242 if (!GetParam().isCXX11OrLater()) {
5245 EXPECT_TRUE(treeDumpEqualOnAnnotations(
5254 |-DeclaratorList Declarators
5255 | `-SimpleDeclarator ListElement
5257 | `-ParametersAndQualifiers
5265 TEST_P(BuildSyntaxTreeTest
, ParametersAndQualifiers_InMemberFunctions_RefRef
) {
5266 if (!GetParam().isCXX11OrLater()) {
5269 EXPECT_TRUE(treeDumpEqualOnAnnotations(
5278 |-DeclaratorList Declarators
5279 | `-SimpleDeclarator ListElement
5281 | `-ParametersAndQualifiers
5289 TEST_P(BuildSyntaxTreeTest
, TrailingReturn
) {
5290 if (!GetParam().isCXX11OrLater()) {
5293 EXPECT_TRUE(treeDumpEqual(
5298 TranslationUnit Detached
5301 |-DeclaratorList Declarators
5302 | `-SimpleDeclarator ListElement
5304 | `-ParametersAndQualifiers
5307 | `-TrailingReturnType TrailingReturn
5314 TEST_P(BuildSyntaxTreeTest
, DynamicExceptionSpecification
) {
5315 if (!GetParam().supportsCXXDynamicExceptionSpecification()) {
5318 EXPECT_TRUE(treeDumpEqualOnAnnotations(
5320 struct MyException1 {};
5321 struct MyException2 {};
5322 [[int a() throw();]]
5323 [[int b() throw(...);]]
5324 [[int c() throw(MyException1);]]
5325 [[int d() throw(MyException1, MyException2);]]
5330 |-DeclaratorList Declarators
5331 | `-SimpleDeclarator ListElement
5333 | `-ParametersAndQualifiers
5344 |-DeclaratorList Declarators
5345 | `-SimpleDeclarator ListElement
5347 | `-ParametersAndQualifiers
5359 |-DeclaratorList Declarators
5360 | `-SimpleDeclarator ListElement
5362 | `-ParametersAndQualifiers
5374 |-DeclaratorList Declarators
5375 | `-SimpleDeclarator ListElement
5377 | `-ParametersAndQualifiers
5390 TEST_P(BuildSyntaxTreeTest
, NoexceptExceptionSpecification
) {
5391 if (!GetParam().isCXX11OrLater()) {
5394 EXPECT_TRUE(treeDumpEqual(
5397 int b() noexcept(true);
5400 TranslationUnit Detached
5403 | |-DeclaratorList Declarators
5404 | | `-SimpleDeclarator ListElement
5406 | | `-ParametersAndQualifiers
5408 | | |-')' CloseParen
5413 |-DeclaratorList Declarators
5414 | `-SimpleDeclarator ListElement
5416 | `-ParametersAndQualifiers
5421 | |-BoolLiteralExpression
5422 | | `-'true' LiteralToken
5428 TEST_P(BuildSyntaxTreeTest
, DeclaratorsInParentheses
) {
5429 EXPECT_TRUE(treeDumpEqual(
5437 TranslationUnit Detached
5440 | |-DeclaratorList Declarators
5441 | | `-SimpleDeclarator ListElement
5442 | | `-ParenDeclarator
5445 | | `-')' CloseParen
5449 | |-DeclaratorList Declarators
5450 | | `-SimpleDeclarator ListElement
5452 | | `-ParenDeclarator
5455 | | `-')' CloseParen
5459 | |-DeclaratorList Declarators
5460 | | `-SimpleDeclarator ListElement
5461 | | |-ParenDeclarator
5462 | | | |-'(' OpenParen
5465 | | | `-')' CloseParen
5466 | | `-ParametersAndQualifiers
5468 | | |-ParameterDeclarationList Parameters
5469 | | | `-SimpleDeclaration ListElement
5471 | | `-')' CloseParen
5475 |-DeclaratorList Declarators
5476 | `-SimpleDeclarator ListElement
5481 | | `-')' CloseParen
5482 | `-ParametersAndQualifiers
5484 | |-ParameterDeclarationList Parameters
5485 | | `-SimpleDeclaration ListElement
5492 TEST_P(BuildSyntaxTreeTest
, Declaration_ConstVolatileQualifiers_SimpleConst
) {
5493 EXPECT_TRUE(treeDumpEqual(
5495 const int west = -1;
5499 TranslationUnit Detached
5503 | |-DeclaratorList Declarators
5504 | | `-SimpleDeclarator ListElement
5507 | | `-PrefixUnaryOperatorExpression
5508 | | |-'-' OperatorToken
5509 | | `-IntegerLiteralExpression Operand
5510 | | `-'1' LiteralToken
5515 |-DeclaratorList Declarators
5516 | `-SimpleDeclarator ListElement
5519 | `-IntegerLiteralExpression
5520 | `-'1' LiteralToken
5525 TEST_P(BuildSyntaxTreeTest
, Declaration_ConstVolatileQualifiers_MultipleConst
) {
5526 EXPECT_TRUE(treeDumpEqual(
5528 const int const universal = 0;
5531 TranslationUnit Detached
5536 |-DeclaratorList Declarators
5537 | `-SimpleDeclarator ListElement
5540 | `-IntegerLiteralExpression
5541 | `-'0' LiteralToken
5546 TEST_P(BuildSyntaxTreeTest
,
5547 Declaration_ConstVolatileQualifiers_ConstAndVolatile
) {
5548 EXPECT_TRUE(treeDumpEqual(
5550 const int const *const *volatile b;
5553 TranslationUnit Detached
5558 |-DeclaratorList Declarators
5559 | `-SimpleDeclarator ListElement
5569 TEST_P(BuildSyntaxTreeTest
, RangesOfDeclaratorsWithTrailingReturnTypes
) {
5570 if (!GetParam().isCXX11OrLater()) {
5573 EXPECT_TRUE(treeDumpEqual(
5575 auto foo() -> auto(*)(int) -> double*;
5578 TranslationUnit Detached
5581 |-DeclaratorList Declarators
5582 | `-SimpleDeclarator ListElement
5584 | `-ParametersAndQualifiers
5587 | `-TrailingReturnType TrailingReturn
5590 | `-SimpleDeclarator Declarator
5594 | | `-')' CloseParen
5595 | `-ParametersAndQualifiers
5597 | |-ParameterDeclarationList Parameters
5598 | | `-SimpleDeclaration ListElement
5601 | `-TrailingReturnType TrailingReturn
5604 | `-SimpleDeclarator Declarator
5610 TEST_P(BuildSyntaxTreeTest
, MemberPointers
) {
5611 if (!GetParam().isCXX()) {
5614 EXPECT_TRUE(treeDumpEqualOnAnnotations(
5618 [[const int X::* b;]]
5623 |-DeclaratorList Declarators
5624 | `-SimpleDeclarator ListElement
5636 |-DeclaratorList Declarators
5637 | `-SimpleDeclarator ListElement
5647 TEST_P(BuildSyntaxTreeTest
, MemberFunctionPointer
) {
5648 if (!GetParam().isCXX()) {
5651 EXPECT_TRUE(treeDumpEqualOnAnnotations(
5656 [[void (X::*xp)();]]
5657 [[void (X::**xpp)(const int*);]]
5658 // FIXME: Generate the right syntax tree for this type,
5659 // i.e. create a syntax node for the outer member pointer
5660 [[void (X::Y::*xyp)(const int*, char);]]
5665 |-DeclaratorList Declarators
5666 | `-SimpleDeclarator ListElement
5674 | | `-')' CloseParen
5675 | `-ParametersAndQualifiers
5683 |-DeclaratorList Declarators
5684 | `-SimpleDeclarator ListElement
5693 | | `-')' CloseParen
5694 | `-ParametersAndQualifiers
5696 | |-ParameterDeclarationList Parameters
5697 | | `-SimpleDeclaration ListElement
5700 | | `-DeclaratorList Declarators
5701 | | `-SimpleDeclarator ListElement
5709 |-DeclaratorList Declarators
5710 | `-SimpleDeclarator ListElement
5720 | | `-')' CloseParen
5721 | `-ParametersAndQualifiers
5723 | |-ParameterDeclarationList Parameters
5724 | | |-SimpleDeclaration ListElement
5727 | | | `-DeclaratorList Declarators
5728 | | | `-SimpleDeclarator ListElement
5730 | | |-',' ListDelimiter
5731 | | `-SimpleDeclaration ListElement
5738 TEST_P(BuildSyntaxTreeTest
, ComplexDeclarator
) {
5739 EXPECT_TRUE(treeDumpEqual(
5741 void x(char a, short (*b)(int));
5744 TranslationUnit Detached
5747 |-DeclaratorList Declarators
5748 | `-SimpleDeclarator ListElement
5750 | `-ParametersAndQualifiers
5752 | |-ParameterDeclarationList Parameters
5753 | | |-SimpleDeclaration ListElement
5755 | | | `-DeclaratorList Declarators
5756 | | | `-SimpleDeclarator ListElement
5758 | | |-',' ListDelimiter
5759 | | `-SimpleDeclaration ListElement
5761 | | `-DeclaratorList Declarators
5762 | | `-SimpleDeclarator ListElement
5763 | | |-ParenDeclarator
5764 | | | |-'(' OpenParen
5767 | | | `-')' CloseParen
5768 | | `-ParametersAndQualifiers
5770 | | |-ParameterDeclarationList Parameters
5771 | | | `-SimpleDeclaration ListElement
5773 | | `-')' CloseParen
5779 TEST_P(BuildSyntaxTreeTest
, ComplexDeclarator2
) {
5780 EXPECT_TRUE(treeDumpEqual(
5782 void x(char a, short (*b)(int), long (**c)(long long));
5785 TranslationUnit Detached
5788 |-DeclaratorList Declarators
5789 | `-SimpleDeclarator ListElement
5791 | `-ParametersAndQualifiers
5793 | |-ParameterDeclarationList Parameters
5794 | | |-SimpleDeclaration ListElement
5796 | | | `-DeclaratorList Declarators
5797 | | | `-SimpleDeclarator ListElement
5799 | | |-',' ListDelimiter
5800 | | |-SimpleDeclaration ListElement
5802 | | | `-DeclaratorList Declarators
5803 | | | `-SimpleDeclarator ListElement
5804 | | | |-ParenDeclarator
5805 | | | | |-'(' OpenParen
5808 | | | | `-')' CloseParen
5809 | | | `-ParametersAndQualifiers
5810 | | | |-'(' OpenParen
5811 | | | |-ParameterDeclarationList Parameters
5812 | | | | `-SimpleDeclaration ListElement
5814 | | | `-')' CloseParen
5815 | | |-',' ListDelimiter
5816 | | `-SimpleDeclaration ListElement
5818 | | `-DeclaratorList Declarators
5819 | | `-SimpleDeclarator ListElement
5820 | | |-ParenDeclarator
5821 | | | |-'(' OpenParen
5825 | | | `-')' CloseParen
5826 | | `-ParametersAndQualifiers
5828 | | |-ParameterDeclarationList Parameters
5829 | | | `-SimpleDeclaration ListElement
5832 | | `-')' CloseParen