eduucaldas updated this revision to Diff 285613. eduucaldas added a comment.
Previous diff had only the last commit Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D85962/new/ https://reviews.llvm.org/D85962 Files: clang/unittests/Tooling/Syntax/BuildTreeTest.cpp clang/unittests/Tooling/Syntax/TreeTestBase.cpp clang/unittests/Tooling/Syntax/TreeTestBase.h
Index: clang/unittests/Tooling/Syntax/TreeTestBase.h =================================================================== --- clang/unittests/Tooling/Syntax/TreeTestBase.h +++ clang/unittests/Tooling/Syntax/TreeTestBase.h @@ -34,6 +34,9 @@ ::testing::AssertionResult treeDumpEqual(StringRef Code, StringRef Tree); + ::testing::AssertionResult + treeDumpEqualOnAnnotations(StringRef CodeWithAnnotations, + ArrayRef<StringRef> TreeDumps); /// Finds the deepest node in the tree that covers exactly \p R. /// FIXME: implement this efficiently and move to public syntax tree API. syntax::Node *nodeByRange(llvm::Annotations::Range R, syntax::Node *Root); Index: clang/unittests/Tooling/Syntax/TreeTestBase.cpp =================================================================== --- clang/unittests/Tooling/Syntax/TreeTestBase.cpp +++ clang/unittests/Tooling/Syntax/TreeTestBase.cpp @@ -180,6 +180,35 @@ return ::testing::AssertionSuccess(); } +::testing::AssertionResult +SyntaxTreeTest::treeDumpEqualOnAnnotations(StringRef CodeWithAnnotations, + ArrayRef<StringRef> TreeDumps) { + SCOPED_TRACE(llvm::join(GetParam().getCommandLineArgs(), " ")); + + auto AnnotatedCode = llvm::Annotations(CodeWithAnnotations); + auto *Root = buildTree(AnnotatedCode.code(), GetParam()); + + if (Diags->getClient()->getNumErrors() != 0) { + return ::testing::AssertionFailure() + << "Source file has syntax errors, they were printed to the test " + "log"; + } + + bool failed = false; + auto AnnotatedRanges = AnnotatedCode.ranges(); + assert(AnnotatedRanges.size() == TreeDumps.size()); + for (auto i = 0ul; i < AnnotatedRanges.size(); i++) { + auto *AnnotatedNode = nodeByRange(AnnotatedRanges[i], Root); + assert(AnnotatedNode); + auto AnnotatedNodeDump = + std::string(StringRef(AnnotatedNode->dump(*Arena)).trim()); + // EXPECT_EQ shows the diff between the two strings if they are different. + EXPECT_EQ(TreeDumps[i].trim().str(), AnnotatedNodeDump); + if (AnnotatedNodeDump != TreeDumps[i].trim().str()) + failed = true; + } + return failed ? ::testing::AssertionFailure() : ::testing::AssertionSuccess(); +} syntax::Node *SyntaxTreeTest::nodeByRange(llvm::Annotations::Range R, syntax::Node *Root) { ArrayRef<syntax::Token> Toks = tokens(Root); Index: clang/unittests/Tooling/Syntax/BuildTreeTest.cpp =================================================================== --- clang/unittests/Tooling/Syntax/BuildTreeTest.cpp +++ clang/unittests/Tooling/Syntax/BuildTreeTest.cpp @@ -437,34 +437,17 @@ } TEST_P(SyntaxTreeTest, UnqualifiedId_Identifier) { - EXPECT_TRUE(treeDumpEqual( + EXPECT_TRUE(treeDumpEqualOnAnnotations( R"cpp( void test(int a) { - a; + [[a]]; } )cpp", - R"txt( -*: TranslationUnit -`-SimpleDeclaration - |-void - |-SimpleDeclarator - | |-test - | `-ParametersAndQualifiers - | |-( - | |-SimpleDeclaration - | | |-int - | | `-SimpleDeclarator - | | `-a - | `-) - `-CompoundStatement - |-{ - |-ExpressionStatement - | |-IdExpression - | | `-UnqualifiedId - | | `-a - | `-; - `-} -)txt")); + {R"txt( +IdExpression +`-UnqualifiedId + `-a +)txt"})); } TEST_P(SyntaxTreeTest, UnqualifiedId_OperatorFunctionId) { @@ -656,104 +639,85 @@ if (!GetParam().isCXX()) { return; } - EXPECT_TRUE(treeDumpEqual( + EXPECT_TRUE(treeDumpEqualOnAnnotations( R"cpp( struct X { }; void test(X x) { // TODO: Expose `id-expression` from `MemberExpr` - x.~X(); + [[x.~X()]]; } )cpp", - R"txt( -*: TranslationUnit -|-SimpleDeclaration -| |-struct -| |-X -| |-{ -| |-} -| `-; -`-SimpleDeclaration - |-void - |-SimpleDeclarator - | |-test - | `-ParametersAndQualifiers - | |-( - | |-SimpleDeclaration - | | |-X - | | `-SimpleDeclarator - | | `-x - | `-) - `-CompoundStatement - |-{ - |-ExpressionStatement - | |-UnknownExpression - | | |-UnknownExpression - | | | |-IdExpression - | | | | `-UnqualifiedId - | | | | `-x - | | | |-. - | | | |-~ - | | | `-X - | | |-( - | | `-) - | `-; - `-} -)txt")); + {R"txt( +UnknownExpression +|-UnknownExpression +| |-IdExpression +| | `-UnqualifiedId +| | `-x +| |-. +| |-~ +| `-X +|-( +`-) +)txt"})); } TEST_P(SyntaxTreeTest, UnqualifiedId_DecltypeDestructor) { if (!GetParam().isCXX11OrLater()) { return; } - EXPECT_TRUE(treeDumpEqual( + EXPECT_TRUE(treeDumpEqualOnAnnotations( R"cpp( struct X { }; void test(X x) { // TODO: Expose `id-expression` from `MemberExpr` - x.~decltype(x)(); -} + [[x.~decltype(x)()]]; +} +)cpp", + {R"txt( +UnknownExpression +|-UnknownExpression +| |-IdExpression +| | `-UnqualifiedId +| | `-x +| |-. +| `-~ +|-decltype +|-( +|-x +|-) +|-( +`-) +)txt"})); +} + +TEST_P(SyntaxTreeTest, ClassTemplateDeclaration) { + if (!GetParam().isCXX()) { + return; + } + EXPECT_TRUE(treeDumpEqual( + R"cpp( +template<typename T> +struct ST {}; )cpp", R"txt( *: TranslationUnit -|-SimpleDeclaration -| |-struct -| |-X -| |-{ -| |-} -| `-; -`-SimpleDeclaration - |-void - |-SimpleDeclarator - | |-test - | `-ParametersAndQualifiers - | |-( - | |-SimpleDeclaration - | | |-X - | | `-SimpleDeclarator - | | `-x - | `-) - `-CompoundStatement +`-TemplateDeclaration + |-template + |-< + |-UnknownDeclaration + | |-typename + | `-T + |-> + `-SimpleDeclaration + |-struct + |-ST |-{ - |-ExpressionStatement - | |-UnknownExpression - | | |-UnknownExpression - | | | |-IdExpression - | | | | `-UnqualifiedId - | | | | `-x - | | | |-. - | | | `-~ - | | |-decltype - | | |-( - | | |-x - | | |-) - | | |-( - | | `-) - | `-; - `-} + |-} + `-; )txt")); } -TEST_P(SyntaxTreeTest, UnqualifiedId_TemplateId) { +TEST_P(SyntaxTreeTest, FunctionTemplateDeclaration) { if (!GetParam().isCXX()) { return; } @@ -761,51 +725,52 @@ R"cpp( template<typename T> T f(); -void test() { - f<int>(); -} )cpp", R"txt( *: TranslationUnit -|-TemplateDeclaration -| |-template -| |-< -| |-UnknownDeclaration -| | |-typename -| | `-T -| |-> -| `-SimpleDeclaration -| |-T -| |-SimpleDeclarator -| | |-f -| | `-ParametersAndQualifiers -| | |-( -| | `-) -| `-; -`-SimpleDeclaration - |-void - |-SimpleDeclarator - | |-test - | `-ParametersAndQualifiers - | |-( - | `-) - `-CompoundStatement - |-{ - |-ExpressionStatement - | |-UnknownExpression - | | |-IdExpression - | | | `-UnqualifiedId - | | | |-f - | | | |-< - | | | |-int - | | | `-> - | | |-( - | | `-) - | `-; - `-} +`-TemplateDeclaration + |-template + |-< + |-UnknownDeclaration + | |-typename + | `-T + |-> + `-SimpleDeclaration + |-T + |-SimpleDeclarator + | |-f + | `-ParametersAndQualifiers + | |-( + | `-) + `-; )txt")); } +TEST_P(SyntaxTreeTest, UnqualifiedId_TemplateId) { + if (!GetParam().isCXX()) { + return; + } + EXPECT_TRUE(treeDumpEqualOnAnnotations( + R"cpp( +template<typename T> +T f(); +void test() { + [[f<int>()]]; +} +)cpp", + {R"txt( +UnknownExpression +|-IdExpression +| `-UnqualifiedId +| |-f +| |-< +| |-int +| `-> +|-( +`-) +)txt"})); +} + TEST_P(SyntaxTreeTest, QualifiedId_NamespaceSpecifier) { if (!GetParam().isCXX()) { return; @@ -873,79 +838,79 @@ if (!GetParam().isCXX()) { return; } - EXPECT_TRUE(treeDumpEqual( + EXPECT_TRUE(treeDumpEqualOnAnnotations( R"cpp( template<typename T> struct ST { struct S { }; }; void test() { - ::template ST<int>::S s1; - ::ST<int>::S s2; + [[::template ST<int>::S s1]]; + [[::ST<int>::S s2]]; +} +)cpp", + {R"txt( +SimpleDeclaration +|-NestedNameSpecifier +| |-:: +| |-SimpleTemplateNameSpecifier +| | |-template +| | |-ST +| | |-< +| | |-int +| | `-> +| `-:: +|-S +`-SimpleDeclarator + `-UnknownExpression + `-s1 +)txt", + R"txt( +SimpleDeclaration +|-NestedNameSpecifier +| |-:: +| |-SimpleTemplateNameSpecifier +| | |-ST +| | |-< +| | |-int +| | `-> +| `-:: +|-S +`-SimpleDeclarator + `-UnknownExpression + `-s2 +)txt"})); } + +TEST_P(SyntaxTreeTest, StaticMemberFunction) { + if (!GetParam().isCXX11OrLater()) { + return; + } + EXPECT_TRUE(treeDumpEqual( + R"cpp( +struct S { + static void f(){} +}; )cpp", R"txt( *: TranslationUnit -|-TemplateDeclaration -| |-template -| |-< -| |-UnknownDeclaration -| | |-typename -| | `-T -| |-> -| `-SimpleDeclaration -| |-struct -| |-ST -| |-{ -| |-SimpleDeclaration -| | |-struct -| | |-S -| | |-{ -| | |-} -| | `-; -| |-} -| `-; `-SimpleDeclaration - |-void - |-SimpleDeclarator - | |-test - | `-ParametersAndQualifiers - | |-( - | `-) - `-CompoundStatement - |-{ - |-DeclarationStatement - | |-SimpleDeclaration - | | |-NestedNameSpecifier - | | | |-:: - | | | |-SimpleTemplateNameSpecifier - | | | | |-template - | | | | |-ST - | | | | |-< - | | | | |-int - | | | | `-> - | | | `-:: - | | |-S - | | `-SimpleDeclarator - | | `-UnknownExpression - | | `-s1 - | `-; - |-DeclarationStatement - | |-SimpleDeclaration - | | |-NestedNameSpecifier - | | | |-:: - | | | |-SimpleTemplateNameSpecifier - | | | | |-ST - | | | | |-< - | | | | |-int - | | | | `-> - | | | `-:: - | | |-S - | | `-SimpleDeclarator - | | `-UnknownExpression - | | `-s2 - | `-; - `-} + |-struct + |-S + |-{ + |-SimpleDeclaration + | |-static + | |-void + | |-SimpleDeclarator + | | |-f + | | `-ParametersAndQualifiers + | | |-( + | | `-) + | `-CompoundStatement + | |-{ + | `-} + |-} + `-; )txt")); } @@ -953,148 +918,169 @@ if (!GetParam().isCXX11OrLater()) { return; } - EXPECT_TRUE(treeDumpEqual( + EXPECT_TRUE(treeDumpEqualOnAnnotations( R"cpp( struct S { static void f(){} }; void test(S s) { - decltype(s)::f(); + [[decltype(s)::f()]]; +} +)cpp", + {R"txt( +UnknownExpression +|-IdExpression +| |-NestedNameSpecifier +| | |-DecltypeNameSpecifier +| | | |-decltype +| | | |-( +| | | |-IdExpression +| | | | `-UnqualifiedId +| | | | `-s +| | | `-) +| | `-:: +| `-UnqualifiedId +| `-f +|-( +`-) +)txt"})); } + +TEST_P(SyntaxTreeTest, StaticMemberFunctionTemplate) { + if (!GetParam().isCXX()) { + return; + } + EXPECT_TRUE(treeDumpEqual( + R"cpp( +struct S { + template<typename U> + static U f(); +}; )cpp", R"txt( *: TranslationUnit -|-SimpleDeclaration -| |-struct -| |-S -| |-{ -| |-SimpleDeclaration -| | |-static -| | |-void -| | |-SimpleDeclarator -| | | |-f -| | | `-ParametersAndQualifiers -| | | |-( -| | | `-) -| | `-CompoundStatement -| | |-{ -| | `-} -| |-} -| `-; `-SimpleDeclaration - |-void - |-SimpleDeclarator - | |-test - | `-ParametersAndQualifiers - | |-( - | |-SimpleDeclaration - | | |-S - | | `-SimpleDeclarator - | | `-s - | `-) - `-CompoundStatement - |-{ - |-ExpressionStatement - | |-UnknownExpression - | | |-IdExpression - | | | |-NestedNameSpecifier - | | | | |-DecltypeNameSpecifier - | | | | | |-decltype - | | | | | |-( - | | | | | |-IdExpression - | | | | | | `-UnqualifiedId - | | | | | | `-s - | | | | | `-) - | | | | `-:: - | | | `-UnqualifiedId - | | | `-f - | | |-( - | | `-) - | `-; - `-} + |-struct + |-S + |-{ + |-TemplateDeclaration + | |-template + | |-< + | |-UnknownDeclaration + | | |-typename + | | `-U + | |-> + | `-SimpleDeclaration + | |-static + | |-U + | |-SimpleDeclarator + | | |-f + | | `-ParametersAndQualifiers + | | |-( + | | `-) + | `-; + |-} + `-; )txt")); } - TEST_P(SyntaxTreeTest, QualifiedId_OptionalTemplateKw) { if (!GetParam().isCXX()) { return; } - EXPECT_TRUE(treeDumpEqual( + EXPECT_TRUE(treeDumpEqualOnAnnotations( R"cpp( struct S { template<typename U> static U f(); }; void test() { - S::f<int>(); - S::template f<int>(); + [[S::f<int>()]]; + [[S::template f<int>()]]; +} +)cpp", + {R"txt( +UnknownExpression +|-IdExpression +| |-NestedNameSpecifier +| | |-IdentifierNameSpecifier +| | | `-S +| | `-:: +| `-UnqualifiedId +| |-f +| |-< +| |-int +| `-> +|-( +`-) +)txt", + R"txt( +UnknownExpression +|-IdExpression +| |-NestedNameSpecifier +| | |-IdentifierNameSpecifier +| | | `-S +| | `-:: +| |-template +| `-UnqualifiedId +| |-f +| |-< +| |-int +| `-> +|-( +`-) +)txt"})); +} + +TEST_P(SyntaxTreeTest, QualifiedId_Complex_Declaration) { + if (!GetParam().isCXX()) { + return; + } + EXPECT_TRUE(treeDumpEqual( + R"cpp( +namespace n { + template<typename T> + struct ST { + template<typename U> + static U f(); + }; } )cpp", R"txt( *: TranslationUnit -|-SimpleDeclaration -| |-struct -| |-S -| |-{ -| |-TemplateDeclaration -| | |-template -| | |-< -| | |-UnknownDeclaration -| | | |-typename -| | | `-U -| | |-> -| | `-SimpleDeclaration -| | |-static -| | |-U -| | |-SimpleDeclarator -| | | |-f -| | | `-ParametersAndQualifiers -| | | |-( -| | | `-) -| | `-; -| |-} -| `-; -`-SimpleDeclaration - |-void - |-SimpleDeclarator - | |-test - | `-ParametersAndQualifiers - | |-( - | `-) - `-CompoundStatement - |-{ - |-ExpressionStatement - | |-UnknownExpression - | | |-IdExpression - | | | |-NestedNameSpecifier - | | | | |-IdentifierNameSpecifier - | | | | | `-S - | | | | `-:: - | | | `-UnqualifiedId - | | | |-f - | | | |-< - | | | |-int - | | | `-> - | | |-( - | | `-) - | `-; - |-ExpressionStatement - | |-UnknownExpression - | | |-IdExpression - | | | |-NestedNameSpecifier - | | | | |-IdentifierNameSpecifier - | | | | | `-S - | | | | `-:: - | | | |-template - | | | `-UnqualifiedId - | | | |-f - | | | |-< - | | | |-int - | | | `-> - | | |-( - | | `-) - | `-; - `-} +`-NamespaceDefinition + |-namespace + |-n + |-{ + |-TemplateDeclaration + | |-template + | |-< + | |-UnknownDeclaration + | | |-typename + | | `-T + | |-> + | `-SimpleDeclaration + | |-struct + | |-ST + | |-{ + | |-TemplateDeclaration + | | |-template + | | |-< + | | |-UnknownDeclaration + | | | |-typename + | | | `-U + | | |-> + | | `-SimpleDeclaration + | | |-static + | | |-U + | | |-SimpleDeclarator + | | | |-f + | | | `-ParametersAndQualifiers + | | | |-( + | | | `-) + | | `-; + | |-} + | `-; + `-} )txt")); } @@ -1102,7 +1088,7 @@ if (!GetParam().isCXX()) { return; } - EXPECT_TRUE(treeDumpEqual( + EXPECT_TRUE(treeDumpEqualOnAnnotations( R"cpp( namespace n { template<typename T> @@ -1112,80 +1098,33 @@ }; } void test() { - ::n::template ST<int>::template f<int>(); -} -)cpp", - R"txt( -*: TranslationUnit -|-NamespaceDefinition -| |-namespace -| |-n -| |-{ -| |-TemplateDeclaration -| | |-template -| | |-< -| | |-UnknownDeclaration -| | | |-typename -| | | `-T -| | |-> -| | `-SimpleDeclaration -| | |-struct -| | |-ST -| | |-{ -| | |-TemplateDeclaration -| | | |-template -| | | |-< -| | | |-UnknownDeclaration -| | | | |-typename -| | | | `-U -| | | |-> -| | | `-SimpleDeclaration -| | | |-static -| | | |-U -| | | |-SimpleDeclarator -| | | | |-f -| | | | `-ParametersAndQualifiers -| | | | |-( -| | | | `-) -| | | `-; -| | |-} -| | `-; -| `-} -`-SimpleDeclaration - |-void - |-SimpleDeclarator - | |-test - | `-ParametersAndQualifiers - | |-( - | `-) - `-CompoundStatement - |-{ - |-ExpressionStatement - | |-UnknownExpression - | | |-IdExpression - | | | |-NestedNameSpecifier - | | | | |-:: - | | | | |-IdentifierNameSpecifier - | | | | | `-n - | | | | |-:: - | | | | |-SimpleTemplateNameSpecifier - | | | | | |-template - | | | | | |-ST - | | | | | |-< - | | | | | |-int - | | | | | `-> - | | | | `-:: - | | | |-template - | | | `-UnqualifiedId - | | | |-f - | | | |-< - | | | |-int - | | | `-> - | | |-( - | | `-) - | `-; - `-} -)txt")); + [[::n::template ST<int>::template f<int>()]]; +} +)cpp", + {R"txt( +UnknownExpression +|-IdExpression +| |-NestedNameSpecifier +| | |-:: +| | |-IdentifierNameSpecifier +| | | `-n +| | |-:: +| | |-SimpleTemplateNameSpecifier +| | | |-template +| | | |-ST +| | | |-< +| | | |-int +| | | `-> +| | `-:: +| |-template +| `-UnqualifiedId +| |-f +| |-< +| |-int +| `-> +|-( +`-) +)txt"})); } TEST_P(SyntaxTreeTest, QualifiedId_DependentType) { @@ -1197,140 +1136,132 @@ // tree when `-fdelayed-template-parsing` is active. return; } - EXPECT_TRUE(treeDumpEqual( + EXPECT_TRUE(treeDumpEqualOnAnnotations( R"cpp( template <typename T> void test() { - T::template U<int>::f(); - T::U::f(); - T::template f<0>(); + [[T::template U<int>::f()]]; + [[T::U::f()]]; + [[T::template f<0>()]]; } )cpp", - R"txt( -*: TranslationUnit -`-TemplateDeclaration - |-template - |-< - |-UnknownDeclaration - | |-typename - | `-T - |-> - `-SimpleDeclaration - |-void - |-SimpleDeclarator - | |-test - | `-ParametersAndQualifiers - | |-( - | `-) - `-CompoundStatement - |-{ - |-ExpressionStatement - | |-UnknownExpression - | | |-IdExpression - | | | |-NestedNameSpecifier - | | | | |-IdentifierNameSpecifier - | | | | | `-T - | | | | |-:: - | | | | |-SimpleTemplateNameSpecifier - | | | | | |-template - | | | | | |-U - | | | | | |-< - | | | | | |-int - | | | | | `-> - | | | | `-:: - | | | `-UnqualifiedId - | | | `-f - | | |-( - | | `-) - | `-; - |-ExpressionStatement - | |-UnknownExpression - | | |-IdExpression - | | | |-NestedNameSpecifier - | | | | |-IdentifierNameSpecifier - | | | | | `-T - | | | | |-:: - | | | | |-IdentifierNameSpecifier - | | | | | `-U - | | | | `-:: - | | | `-UnqualifiedId - | | | `-f - | | |-( - | | `-) - | `-; - |-ExpressionStatement - | |-UnknownExpression - | | |-IdExpression - | | | |-NestedNameSpecifier - | | | | |-IdentifierNameSpecifier - | | | | | `-T - | | | | `-:: - | | | |-template - | | | `-UnqualifiedId - | | | |-f - | | | |-< - | | | |-IntegerLiteralExpression - | | | | `-0 - | | | `-> - | | |-( - | | `-) - | `-; - `-} -)txt")); + {R"txt( +UnknownExpression +|-IdExpression +| |-NestedNameSpecifier +| | |-IdentifierNameSpecifier +| | | `-T +| | |-:: +| | |-SimpleTemplateNameSpecifier +| | | |-template +| | | |-U +| | | |-< +| | | |-int +| | | `-> +| | `-:: +| `-UnqualifiedId +| `-f +|-( +`-) +)txt", + R"txt( +UnknownExpression +|-IdExpression +| |-NestedNameSpecifier +| | |-IdentifierNameSpecifier +| | | `-T +| | |-:: +| | |-IdentifierNameSpecifier +| | | `-U +| | `-:: +| `-UnqualifiedId +| `-f +|-( +`-) +)txt", + R"txt( +UnknownExpression +|-IdExpression +| |-NestedNameSpecifier +| | |-IdentifierNameSpecifier +| | | `-T +| | `-:: +| |-template +| `-UnqualifiedId +| |-f +| |-< +| |-IntegerLiteralExpression +| | `-0 +| `-> +|-( +`-) +)txt"})); } TEST_P(SyntaxTreeTest, ParenExpr) { - EXPECT_TRUE(treeDumpEqual( + EXPECT_TRUE(treeDumpEqualOnAnnotations( R"cpp( void test() { - (1); - ((1)); - (1 + (2)); -} -)cpp", + [[(1)]]; + [[((1))]]; + [[(1 + (2))]]; +} +)cpp", + {R"txt( +ParenExpression +|-( +|-IntegerLiteralExpression +| `-1 +`-) +)txt", + R"txt( +ParenExpression +|-( +|-ParenExpression +| |-( +| |-IntegerLiteralExpression +| | `-1 +| `-) +`-) +)txt", + R"txt( +ParenExpression +|-( +|-BinaryOperatorExpression +| |-IntegerLiteralExpression +| | `-1 +| |-+ +| `-ParenExpression +| |-( +| |-IntegerLiteralExpression +| | `-2 +| `-) +`-) +)txt"})); +} + +TEST_P(SyntaxTreeTest, UserDefinedLiteral_LiteralOperatorDeclaration) { + if (!GetParam().isCXX11OrLater()) { + return; + } + EXPECT_TRUE(treeDumpEqual( + R"cpp( +unsigned operator "" _c(char); + )cpp", R"txt( *: TranslationUnit `-SimpleDeclaration - |-void + |-unsigned |-SimpleDeclarator - | |-test + | |-operator + | |-"" + | |-_c | `-ParametersAndQualifiers | |-( + | |-SimpleDeclaration + | | `-char | `-) - `-CompoundStatement - |-{ - |-ExpressionStatement - | |-ParenExpression - | | |-( - | | |-IntegerLiteralExpression - | | | `-1 - | | `-) - | `-; - |-ExpressionStatement - | |-ParenExpression - | | |-( - | | |-ParenExpression - | | | |-( - | | | |-IntegerLiteralExpression - | | | | `-1 - | | | `-) - | | `-) - | `-; - |-ExpressionStatement - | |-ParenExpression - | | |-( - | | |-BinaryOperatorExpression - | | | |-IntegerLiteralExpression - | | | | `-1 - | | | |-+ - | | | `-ParenExpression - | | | |-( - | | | |-IntegerLiteralExpression - | | | | `-2 - | | | `-) - | | `-) - | `-; - `-} + `-; )txt")); } @@ -1338,41 +1269,43 @@ if (!GetParam().isCXX11OrLater()) { return; } - EXPECT_TRUE(treeDumpEqual( + EXPECT_TRUE(treeDumpEqualOnAnnotations( R"cpp( unsigned operator "" _c(char); void test() { - '2'_c; + [['2'_c]]; +} + )cpp", + {R"txt( +CharUserDefinedLiteralExpression +`-'2'_c +)txt"})); } + +TEST_P(SyntaxTreeTest, UserDefinedLiteral_Typedef) { + if (!GetParam().isCXX11OrLater()) { + return; + } + EXPECT_TRUE(treeDumpEqual( + R"cpp( +typedef decltype(sizeof(void *)) size_t; )cpp", R"txt( *: TranslationUnit -|-SimpleDeclaration -| |-unsigned -| |-SimpleDeclarator -| | |-operator -| | |-"" -| | |-_c -| | `-ParametersAndQualifiers -| | |-( -| | |-SimpleDeclaration -| | | `-char -| | `-) -| `-; `-SimpleDeclaration - |-void + |-typedef + |-decltype + |-( + |-UnknownExpression + | |-sizeof + | |-( + | |-void + | |-* + | `-) + |-) |-SimpleDeclarator - | |-test - | `-ParametersAndQualifiers - | |-( - | `-) - `-CompoundStatement - |-{ - |-ExpressionStatement - | |-CharUserDefinedLiteralExpression - | | `-'2'_c - | `-; - `-} + | `-size_t + `-; )txt")); } @@ -1380,64 +1313,51 @@ if (!GetParam().isCXX11OrLater()) { return; } - EXPECT_TRUE(treeDumpEqual( + EXPECT_TRUE(treeDumpEqualOnAnnotations( R"cpp( typedef decltype(sizeof(void *)) size_t; unsigned operator "" _s(const char*, size_t); void test() { - "12"_s; + [["12"_s]]; +} + )cpp", + {R"txt( +StringUserDefinedLiteralExpression +`-"12"_s +)txt"})); } + +TEST_P(SyntaxTreeTest, + UserDefinedLiteral_NumericLiteralOperatorTemplateDeclaration) { + if (!GetParam().isCXX11OrLater()) { + return; + } + EXPECT_TRUE(treeDumpEqual( + R"cpp( +template <char...> +unsigned operator "" _t(); )cpp", R"txt( *: TranslationUnit -|-SimpleDeclaration -| |-typedef -| |-decltype -| |-( -| |-UnknownExpression -| | |-sizeof -| | |-( -| | |-void -| | |-* -| | `-) -| |-) -| |-SimpleDeclarator -| | `-size_t -| `-; -|-SimpleDeclaration -| |-unsigned -| |-SimpleDeclarator -| | |-operator -| | |-"" -| | |-_s -| | `-ParametersAndQualifiers -| | |-( -| | |-SimpleDeclaration -| | | |-const -| | | |-char -| | | `-SimpleDeclarator -| | | `-* -| | |-, -| | |-SimpleDeclaration -| | | `-size_t -| | `-) -| `-; -`-SimpleDeclaration - |-void - |-SimpleDeclarator - | |-test - | `-ParametersAndQualifiers - | |-( - | `-) - `-CompoundStatement - |-{ - |-ExpressionStatement - | |-StringUserDefinedLiteralExpression - | | `-"12"_s - | `-; - `-} +`-TemplateDeclaration + |-template + |-< + |-SimpleDeclaration + | `-char + |-... + |-> + `-SimpleDeclaration + |-unsigned + |-SimpleDeclarator + | |-operator + | |-"" + | |-_t + | `-ParametersAndQualifiers + | |-( + | `-) + `-; )txt")); } @@ -1445,7 +1365,7 @@ if (!GetParam().isCXX11OrLater()) { return; } - EXPECT_TRUE(treeDumpEqual( + EXPECT_TRUE(treeDumpEqualOnAnnotations( R"cpp( unsigned operator "" _i(unsigned long long); unsigned operator "" _r(const char*); @@ -1453,89 +1373,30 @@ unsigned operator "" _t(); void test() { - 12_i; - 12_r; - 12_t; + [[12_i]]; + [[12_r]]; + [[12_t]]; } )cpp", - R"txt( -*: TranslationUnit -|-SimpleDeclaration -| |-unsigned -| |-SimpleDeclarator -| | |-operator -| | |-"" -| | |-_i -| | `-ParametersAndQualifiers -| | |-( -| | |-SimpleDeclaration -| | | |-unsigned -| | | |-long -| | | `-long -| | `-) -| `-; -|-SimpleDeclaration -| |-unsigned -| |-SimpleDeclarator -| | |-operator -| | |-"" -| | |-_r -| | `-ParametersAndQualifiers -| | |-( -| | |-SimpleDeclaration -| | | |-const -| | | |-char -| | | `-SimpleDeclarator -| | | `-* -| | `-) -| `-; -|-TemplateDeclaration -| |-template -| |-< -| |-SimpleDeclaration -| | `-char -| |-... -| |-> -| `-SimpleDeclaration -| |-unsigned -| |-SimpleDeclarator -| | |-operator -| | |-"" -| | |-_t -| | `-ParametersAndQualifiers -| | |-( -| | `-) -| `-; -`-SimpleDeclaration - |-void - |-SimpleDeclarator - | |-test - | `-ParametersAndQualifiers - | |-( - | `-) - `-CompoundStatement - |-{ - |-ExpressionStatement - | |-IntegerUserDefinedLiteralExpression - | | `-12_i - | `-; - |-ExpressionStatement - | |-IntegerUserDefinedLiteralExpression - | | `-12_r - | `-; - |-ExpressionStatement - | |-IntegerUserDefinedLiteralExpression - | | `-12_t - | `-; - `-} -)txt")); + {R"txt( +IntegerUserDefinedLiteralExpression +`-12_i +)txt", + R"txt( +IntegerUserDefinedLiteralExpression +`-12_r +)txt", + R"txt( +IntegerUserDefinedLiteralExpression +`-12_t +)txt"})); } TEST_P(SyntaxTreeTest, UserDefinedLiteral_Float) { if (!GetParam().isCXX11OrLater()) { return; } - EXPECT_TRUE(treeDumpEqual( + EXPECT_TRUE(treeDumpEqualOnAnnotations( R"cpp( unsigned operator "" _f(long double); unsigned operator "" _r(const char*); @@ -1543,457 +1404,269 @@ unsigned operator "" _t(); void test() { - 1.2_f; // call: operator "" _f(1.2L) | kind: float - 1.2_r; // call: operator "" _i("1.2") | kind: float - 1.2_t; // call: operator<'1', '2'> "" _x() | kind: float + [[1.2_f]]; + [[1.2_r]]; + [[1.2_t]]; } )cpp", - R"txt( -*: TranslationUnit -|-SimpleDeclaration -| |-unsigned -| |-SimpleDeclarator -| | |-operator -| | |-"" -| | |-_f -| | `-ParametersAndQualifiers -| | |-( -| | |-SimpleDeclaration -| | | |-long -| | | `-double -| | `-) -| `-; -|-SimpleDeclaration -| |-unsigned -| |-SimpleDeclarator -| | |-operator -| | |-"" -| | |-_r -| | `-ParametersAndQualifiers -| | |-( -| | |-SimpleDeclaration -| | | |-const -| | | |-char -| | | `-SimpleDeclarator -| | | `-* -| | `-) -| `-; -|-TemplateDeclaration -| |-template -| |-< -| |-SimpleDeclaration -| | `-char -| |-... -| |-> -| `-SimpleDeclaration -| |-unsigned -| |-SimpleDeclarator -| | |-operator -| | |-"" -| | |-_t -| | `-ParametersAndQualifiers -| | |-( -| | `-) -| `-; -`-SimpleDeclaration - |-void - |-SimpleDeclarator - | |-test - | `-ParametersAndQualifiers - | |-( - | `-) - `-CompoundStatement - |-{ - |-ExpressionStatement - | |-FloatUserDefinedLiteralExpression - | | `-1.2_f - | `-; - |-ExpressionStatement - | |-FloatUserDefinedLiteralExpression - | | `-1.2_r - | `-; - |-ExpressionStatement - | |-FloatUserDefinedLiteralExpression - | | `-1.2_t - | `-; - `-} -)txt")); + {R"txt( +FloatUserDefinedLiteralExpression +`-1.2_f +)txt", + R"txt( +FloatUserDefinedLiteralExpression +`-1.2_r +)txt", + R"txt( +FloatUserDefinedLiteralExpression +`-1.2_t +)txt"})); } TEST_P(SyntaxTreeTest, IntegerLiteral_LongLong) { if (!GetParam().isCXX11OrLater()) { return; } - EXPECT_TRUE(treeDumpEqual( + EXPECT_TRUE(treeDumpEqualOnAnnotations( R"cpp( void test() { - 12ll; - 12ull; + [[12ll]]; + [[12ull]]; } )cpp", - R"txt( -*: TranslationUnit -`-SimpleDeclaration - |-void - |-SimpleDeclarator - | |-test - | `-ParametersAndQualifiers - | |-( - | `-) - `-CompoundStatement - |-{ - |-ExpressionStatement - | |-IntegerLiteralExpression - | | `-12ll - | `-; - |-ExpressionStatement - | |-IntegerLiteralExpression - | | `-12ull - | `-; - `-} -)txt")); + {R"txt( +IntegerLiteralExpression +`-12ll +)txt", + R"txt( +IntegerLiteralExpression +`-12ull +)txt"})); } TEST_P(SyntaxTreeTest, IntegerLiteral_Binary) { if (!GetParam().isCXX14OrLater()) { return; } - EXPECT_TRUE(treeDumpEqual( + EXPECT_TRUE(treeDumpEqualOnAnnotations( R"cpp( void test() { - 0b1100; + [[0b1100]]; } )cpp", - R"txt( -*: TranslationUnit -`-SimpleDeclaration - |-void - |-SimpleDeclarator - | |-test - | `-ParametersAndQualifiers - | |-( - | `-) - `-CompoundStatement - |-{ - |-ExpressionStatement - | |-IntegerLiteralExpression - | | `-0b1100 - | `-; - `-} -)txt")); + {R"txt( +IntegerLiteralExpression +`-0b1100 +)txt"})); } TEST_P(SyntaxTreeTest, IntegerLiteral_WithDigitSeparators) { if (!GetParam().isCXX14OrLater()) { return; } - EXPECT_TRUE(treeDumpEqual( + EXPECT_TRUE(treeDumpEqualOnAnnotations( R"cpp( void test() { - 1'2'0ull; + [[1'2'0ull]]; } )cpp", - R"txt( -*: TranslationUnit -`-SimpleDeclaration - |-void - |-SimpleDeclarator - | |-test - | `-ParametersAndQualifiers - | |-( - | `-) - `-CompoundStatement - |-{ - |-ExpressionStatement - | |-IntegerLiteralExpression - | | `-1'2'0ull - | `-; - `-} -)txt")); + {R"txt( +IntegerLiteralExpression +`-1'2'0ull +)txt"})); } TEST_P(SyntaxTreeTest, CharacterLiteral) { - EXPECT_TRUE(treeDumpEqual( + EXPECT_TRUE(treeDumpEqualOnAnnotations( R"cpp( void test() { - 'a'; - '\n'; - '\x20'; - '\0'; - L'a'; - L'α'; -} -)cpp", - R"txt( -*: TranslationUnit -`-SimpleDeclaration - |-void - |-SimpleDeclarator - | |-test - | `-ParametersAndQualifiers - | |-( - | `-) - `-CompoundStatement - |-{ - |-ExpressionStatement - | |-CharacterLiteralExpression - | | `-'a' - | `-; - |-ExpressionStatement - | |-CharacterLiteralExpression - | | `-'\n' - | `-; - |-ExpressionStatement - | |-CharacterLiteralExpression - | | `-'\x20' - | `-; - |-ExpressionStatement - | |-CharacterLiteralExpression - | | `-'\0' - | `-; - |-ExpressionStatement - | |-CharacterLiteralExpression - | | `-L'a' - | `-; - |-ExpressionStatement - | |-CharacterLiteralExpression - | | `-L'α' - | `-; - `-} -)txt")); + [['a']]; + [['\n']]; + [['\x20']]; + [['\0']]; + [[L'a']]; + [[L'α']]; +} +)cpp", + {R"txt( +CharacterLiteralExpression +`-'a' +)txt", + R"txt( +CharacterLiteralExpression +`-'\n' +)txt", + R"txt( +CharacterLiteralExpression +`-'\x20' +)txt", + R"txt( +CharacterLiteralExpression +`-'\0' +)txt", + R"txt( +CharacterLiteralExpression +`-L'a' +)txt", + R"txt( +CharacterLiteralExpression +`-L'α' +)txt"})); } TEST_P(SyntaxTreeTest, CharacterLiteral_Utf) { if (!GetParam().isCXX11OrLater()) { return; } - EXPECT_TRUE(treeDumpEqual( + EXPECT_TRUE(treeDumpEqualOnAnnotations( R"cpp( void test() { - u'a'; - u'æ§'; - U'a'; - U'ð²'; -} -)cpp", - R"txt( -*: TranslationUnit -`-SimpleDeclaration - |-void - |-SimpleDeclarator - | |-test - | `-ParametersAndQualifiers - | |-( - | `-) - `-CompoundStatement - |-{ - |-ExpressionStatement - | |-CharacterLiteralExpression - | | `-u'a' - | `-; - |-ExpressionStatement - | |-CharacterLiteralExpression - | | `-u'æ§' - | `-; - |-ExpressionStatement - | |-CharacterLiteralExpression - | | `-U'a' - | `-; - |-ExpressionStatement - | |-CharacterLiteralExpression - | | `-U'ð²' - | `-; - `-} -)txt")); + [[u'a']]; + [[u'æ§']]; + [[U'a']]; + [[U'ð²']]; +} +)cpp", + {R"txt( +CharacterLiteralExpression +`-u'a' +)txt", + R"txt( +CharacterLiteralExpression +`-u'æ§' +)txt", + R"txt( +CharacterLiteralExpression +`-U'a' +)txt", + R"txt( +CharacterLiteralExpression +`-U'ð²' +)txt"})); } TEST_P(SyntaxTreeTest, CharacterLiteral_Utf8) { if (!GetParam().isCXX17OrLater()) { return; } - EXPECT_TRUE(treeDumpEqual( + EXPECT_TRUE(treeDumpEqualOnAnnotations( R"cpp( void test() { - u8'a'; - u8'\x7f'; + [[u8'a']]; + [[u8'\x7f']]; } )cpp", - R"txt( -*: TranslationUnit -`-SimpleDeclaration - |-void - |-SimpleDeclarator - | |-test - | `-ParametersAndQualifiers - | |-( - | `-) - `-CompoundStatement - |-{ - |-ExpressionStatement - | |-CharacterLiteralExpression - | | `-u8'a' - | `-; - |-ExpressionStatement - | |-CharacterLiteralExpression - | | `-u8'\x7f' - | `-; - `-} -)txt")); + {R"txt( +CharacterLiteralExpression +`-u8'a' +)txt", + R"txt( +CharacterLiteralExpression +`-u8'\x7f' +)txt"})); } TEST_P(SyntaxTreeTest, FloatingLiteral) { - EXPECT_TRUE(treeDumpEqual( + EXPECT_TRUE(treeDumpEqualOnAnnotations( R"cpp( void test() { - 1e-2; - 2.; - .2; - 2.f; -} -)cpp", - R"txt( -*: TranslationUnit -`-SimpleDeclaration - |-void - |-SimpleDeclarator - | |-test - | `-ParametersAndQualifiers - | |-( - | `-) - `-CompoundStatement - |-{ - |-ExpressionStatement - | |-FloatingLiteralExpression - | | `-1e-2 - | `-; - |-ExpressionStatement - | |-FloatingLiteralExpression - | | `-2. - | `-; - |-ExpressionStatement - | |-FloatingLiteralExpression - | | `-.2 - | `-; - |-ExpressionStatement - | |-FloatingLiteralExpression - | | `-2.f - | `-; - `-} -)txt")); + [[1e-2]]; + [[2.]]; + [[.2]]; + [[2.f]]; +} +)cpp", + {R"txt( +FloatingLiteralExpression +`-1e-2 +)txt", + R"txt( +FloatingLiteralExpression +`-2. +)txt", + R"txt( +FloatingLiteralExpression +`-.2 +)txt", + R"txt( +FloatingLiteralExpression +`-2.f +)txt"})); } TEST_P(SyntaxTreeTest, FloatingLiteral_Hexadecimal) { if (!GetParam().isCXX17OrLater()) { return; } - EXPECT_TRUE(treeDumpEqual( + EXPECT_TRUE(treeDumpEqualOnAnnotations( R"cpp( void test() { - 0xfp1; - 0xf.p1; - 0x.fp1; - 0xf.fp1f; -} -)cpp", - R"txt( -*: TranslationUnit -`-SimpleDeclaration - |-void - |-SimpleDeclarator - | |-test - | `-ParametersAndQualifiers - | |-( - | `-) - `-CompoundStatement - |-{ - |-ExpressionStatement - | |-FloatingLiteralExpression - | | `-0xfp1 - | `-; - |-ExpressionStatement - | |-FloatingLiteralExpression - | | `-0xf.p1 - | `-; - |-ExpressionStatement - | |-FloatingLiteralExpression - | | `-0x.fp1 - | `-; - |-ExpressionStatement - | |-FloatingLiteralExpression - | | `-0xf.fp1f - | `-; - `-} -)txt")); + [[0xfp1]]; + [[0xf.p1]]; + [[0x.fp1]]; + [[0xf.fp1f]]; +} +)cpp", + {R"txt( +FloatingLiteralExpression +`-0xfp1 +)txt", + R"txt( +FloatingLiteralExpression +`-0xf.p1 +)txt", + R"txt( +FloatingLiteralExpression +`-0x.fp1 +)txt", + R"txt( +FloatingLiteralExpression +`-0xf.fp1f +)txt"})); } TEST_P(SyntaxTreeTest, StringLiteral) { - EXPECT_TRUE(treeDumpEqual( + EXPECT_TRUE(treeDumpEqualOnAnnotations( R"cpp( void test() { - "a\n\0\x20"; - L"αβ"; + [["a\n\0\x20"]]; + [[L"αβ"]]; } )cpp", - R"txt( -*: TranslationUnit -`-SimpleDeclaration - |-void - |-SimpleDeclarator - | |-test - | `-ParametersAndQualifiers - | |-( - | `-) - `-CompoundStatement - |-{ - |-ExpressionStatement - | |-StringLiteralExpression - | | `-"a\n\0\x20" - | `-; - |-ExpressionStatement - | |-StringLiteralExpression - | | `-L"αβ" - | `-; - `-} -)txt")); + {R"txt( +StringLiteralExpression +`-"a\n\0\x20" +)txt", + R"txt( +StringLiteralExpression +`-L"αβ" +)txt"})); } TEST_P(SyntaxTreeTest, StringLiteral_Utf) { if (!GetParam().isCXX11OrLater()) { return; } - EXPECT_TRUE(treeDumpEqual( + EXPECT_TRUE(treeDumpEqualOnAnnotations( R"cpp( void test() { - u8"a\x1f\x05"; - u"C++æ½è±¡æ§ææ¨"; - U"ðð²\n"; + [[u8"a\x1f\x05"]]; + [[u"C++æ½è±¡æ§ææ¨"]]; + [[U"ðð²\n"]]; } )cpp", - R"txt( -*: TranslationUnit -`-SimpleDeclaration - |-void - |-SimpleDeclarator - | |-test - | `-ParametersAndQualifiers - | |-( - | `-) - `-CompoundStatement - |-{ - |-ExpressionStatement - | |-StringLiteralExpression - | | `-u8"a\x1f\x05" - | `-; - |-ExpressionStatement - | |-StringLiteralExpression - | | `-u"C++æ½è±¡æ§ææ¨" - | `-; - |-ExpressionStatement - | |-StringLiteralExpression - | | `-U"ðð²\n" - | `-; - `-} -)txt")); + {R"txt( +StringLiteralExpression +`-u8"a\x1f\x05" +)txt", + R"txt( +StringLiteralExpression +`-u"C++æ½è±¡æ§ææ¨" +)txt", + R"txt( +StringLiteralExpression +`-U"ðð²\n" +)txt"})); } TEST_P(SyntaxTreeTest, StringLiteral_Raw) { @@ -2033,576 +1706,442 @@ if (GetParam().isC()) { return; } - EXPECT_TRUE(treeDumpEqual( + EXPECT_TRUE(treeDumpEqualOnAnnotations( R"cpp( void test() { - true; - false; + [[true]]; + [[false]]; } )cpp", - R"txt( -*: TranslationUnit -`-SimpleDeclaration - |-void - |-SimpleDeclarator - | |-test - | `-ParametersAndQualifiers - | |-( - | `-) - `-CompoundStatement - |-{ - |-ExpressionStatement - | |-BoolLiteralExpression - | | `-true - | `-; - |-ExpressionStatement - | |-BoolLiteralExpression - | | `-false - | `-; - `-} -)txt")); + {R"txt( +BoolLiteralExpression +`-true +)txt", + R"txt( +BoolLiteralExpression +`-false +)txt"})); } TEST_P(SyntaxTreeTest, CxxNullPtrLiteral) { if (!GetParam().isCXX11OrLater()) { return; } - EXPECT_TRUE(treeDumpEqual( + EXPECT_TRUE(treeDumpEqualOnAnnotations( R"cpp( void test() { - nullptr; + [[nullptr]]; } )cpp", - R"txt( -*: TranslationUnit -`-SimpleDeclaration - |-void - |-SimpleDeclarator - | |-test - | `-ParametersAndQualifiers - | |-( - | `-) - `-CompoundStatement - |-{ - |-ExpressionStatement - | |-CxxNullPtrExpression - | | `-nullptr - | `-; - `-} -)txt")); + {R"txt( +CxxNullPtrExpression +`-nullptr +)txt"})); } TEST_P(SyntaxTreeTest, PostfixUnaryOperator) { - EXPECT_TRUE(treeDumpEqual( + EXPECT_TRUE(treeDumpEqualOnAnnotations( R"cpp( void test(int a) { - a++; - a--; -} -)cpp", - R"txt( -*: TranslationUnit -`-SimpleDeclaration - |-void - |-SimpleDeclarator - | |-test - | `-ParametersAndQualifiers - | |-( - | |-SimpleDeclaration - | | |-int - | | `-SimpleDeclarator - | | `-a - | `-) - `-CompoundStatement - |-{ - |-ExpressionStatement - | |-PostfixUnaryOperatorExpression - | | |-IdExpression - | | | `-UnqualifiedId - | | | `-a - | | `-++ - | `-; - |-ExpressionStatement - | |-PostfixUnaryOperatorExpression - | | |-IdExpression - | | | `-UnqualifiedId - | | | `-a - | | `--- - | `-; - `-} -)txt")); + [[a++]]; + [[a--]]; +} +)cpp", + {R"txt( +PostfixUnaryOperatorExpression +|-IdExpression +| `-UnqualifiedId +| `-a +`-++ +)txt", + R"txt( +PostfixUnaryOperatorExpression +|-IdExpression +| `-UnqualifiedId +| `-a +`--- +)txt"})); } TEST_P(SyntaxTreeTest, PrefixUnaryOperator) { - EXPECT_TRUE(treeDumpEqual( + EXPECT_TRUE(treeDumpEqualOnAnnotations( R"cpp( void test(int a, int *ap) { - --a; ++a; - ~a; - -a; - +a; - &a; - *ap; - !a; - __real a; __imag a; -} -)cpp", - R"txt( -*: TranslationUnit -`-SimpleDeclaration - |-void - |-SimpleDeclarator - | |-test - | `-ParametersAndQualifiers - | |-( - | |-SimpleDeclaration - | | |-int - | | `-SimpleDeclarator - | | `-a - | |-, - | |-SimpleDeclaration - | | |-int - | | `-SimpleDeclarator - | | |-* - | | `-ap - | `-) - `-CompoundStatement - |-{ - |-ExpressionStatement - | |-PrefixUnaryOperatorExpression - | | |--- - | | `-IdExpression - | | `-UnqualifiedId - | | `-a - | `-; - |-ExpressionStatement - | |-PrefixUnaryOperatorExpression - | | |-++ - | | `-IdExpression - | | `-UnqualifiedId - | | `-a - | `-; - |-ExpressionStatement - | |-PrefixUnaryOperatorExpression - | | |-~ - | | `-IdExpression - | | `-UnqualifiedId - | | `-a - | `-; - |-ExpressionStatement - | |-PrefixUnaryOperatorExpression - | | |-- - | | `-IdExpression - | | `-UnqualifiedId - | | `-a - | `-; - |-ExpressionStatement - | |-PrefixUnaryOperatorExpression - | | |-+ - | | `-IdExpression - | | `-UnqualifiedId - | | `-a - | `-; - |-ExpressionStatement - | |-PrefixUnaryOperatorExpression - | | |-& - | | `-IdExpression - | | `-UnqualifiedId - | | `-a - | `-; - |-ExpressionStatement - | |-PrefixUnaryOperatorExpression - | | |-* - | | `-IdExpression - | | `-UnqualifiedId - | | `-ap - | `-; - |-ExpressionStatement - | |-PrefixUnaryOperatorExpression - | | |-! - | | `-IdExpression - | | `-UnqualifiedId - | | `-a - | `-; - |-ExpressionStatement - | |-PrefixUnaryOperatorExpression - | | |-__real - | | `-IdExpression - | | `-UnqualifiedId - | | `-a - | `-; - |-ExpressionStatement - | |-PrefixUnaryOperatorExpression - | | |-__imag - | | `-IdExpression - | | `-UnqualifiedId - | | `-a - | `-; - `-} -)txt")); + [[--a]]; [[++a]]; + [[~a]]; + [[-a]]; + [[+a]]; + [[&a]]; + [[*ap]]; + [[!a]]; + [[__real a]]; [[__imag a]]; +} +)cpp", + {R"txt( +PrefixUnaryOperatorExpression +|--- +`-IdExpression + `-UnqualifiedId + `-a +)txt", + R"txt( +PrefixUnaryOperatorExpression +|-++ +`-IdExpression + `-UnqualifiedId + `-a +)txt", + R"txt( +PrefixUnaryOperatorExpression +|-~ +`-IdExpression + `-UnqualifiedId + `-a +)txt", + R"txt( +PrefixUnaryOperatorExpression +|-- +`-IdExpression + `-UnqualifiedId + `-a +)txt", + R"txt( +PrefixUnaryOperatorExpression +|-+ +`-IdExpression + `-UnqualifiedId + `-a +)txt", + R"txt( +PrefixUnaryOperatorExpression +|-& +`-IdExpression + `-UnqualifiedId + `-a +)txt", + R"txt( +PrefixUnaryOperatorExpression +|-* +`-IdExpression + `-UnqualifiedId + `-ap +)txt", + R"txt( +PrefixUnaryOperatorExpression +|-! +`-IdExpression + `-UnqualifiedId + `-a +)txt", + R"txt( +PrefixUnaryOperatorExpression +|-__real +`-IdExpression + `-UnqualifiedId + `-a +)txt", + R"txt( +PrefixUnaryOperatorExpression +|-__imag +`-IdExpression + `-UnqualifiedId + `-a +)txt"})); } TEST_P(SyntaxTreeTest, PrefixUnaryOperatorCxx) { if (!GetParam().isCXX()) { return; } - EXPECT_TRUE(treeDumpEqual( + EXPECT_TRUE(treeDumpEqualOnAnnotations( R"cpp( void test(int a, bool b) { - compl a; - not b; -} -)cpp", - R"txt( -*: TranslationUnit -`-SimpleDeclaration - |-void - |-SimpleDeclarator - | |-test - | `-ParametersAndQualifiers - | |-( - | |-SimpleDeclaration - | | |-int - | | `-SimpleDeclarator - | | `-a - | |-, - | |-SimpleDeclaration - | | |-bool - | | `-SimpleDeclarator - | | `-b - | `-) - `-CompoundStatement - |-{ - |-ExpressionStatement - | |-PrefixUnaryOperatorExpression - | | |-compl - | | `-IdExpression - | | `-UnqualifiedId - | | `-a - | `-; - |-ExpressionStatement - | |-PrefixUnaryOperatorExpression - | | |-not - | | `-IdExpression - | | `-UnqualifiedId - | | `-b - | `-; - `-} -)txt")); + [[compl a]]; + [[not b]]; +} +)cpp", + {R"txt( +PrefixUnaryOperatorExpression +|-compl +`-IdExpression + `-UnqualifiedId + `-a +)txt", + R"txt( +PrefixUnaryOperatorExpression +|-not +`-IdExpression + `-UnqualifiedId + `-b +)txt"})); } TEST_P(SyntaxTreeTest, BinaryOperator) { - EXPECT_TRUE(treeDumpEqual( + EXPECT_TRUE(treeDumpEqualOnAnnotations( + R"cpp( +void test(int a) { + [[1 - 2]]; + [[1 == 2]]; + [[a = 1]]; + [[a <<= 1]]; + [[1 || 0]]; + [[1 & 2]]; + [[a != 3]]; +} +)cpp", + {R"txt( +BinaryOperatorExpression +|-IntegerLiteralExpression +| `-1 +|-- +`-IntegerLiteralExpression + `-2 +)txt", + R"txt( +BinaryOperatorExpression +|-IntegerLiteralExpression +| `-1 +|-== +`-IntegerLiteralExpression + `-2 +)txt", + R"txt( +BinaryOperatorExpression +|-IdExpression +| `-UnqualifiedId +| `-a +|-= +`-IntegerLiteralExpression + `-1 +)txt", + R"txt( +BinaryOperatorExpression +|-IdExpression +| `-UnqualifiedId +| `-a +|-<<= +`-IntegerLiteralExpression + `-1 +)txt", + R"txt( +BinaryOperatorExpression +|-IntegerLiteralExpression +| `-1 +|-|| +`-IntegerLiteralExpression + `-0 +)txt", + R"txt( +BinaryOperatorExpression +|-IntegerLiteralExpression +| `-1 +|-& +`-IntegerLiteralExpression + `-2 +)txt", + R"txt( +BinaryOperatorExpression +|-IdExpression +| `-UnqualifiedId +| `-a +|-!= +`-IntegerLiteralExpression + `-3 +)txt"})); +} + +TEST_P(SyntaxTreeTest, BinaryOperatorCxx) { + if (!GetParam().isCXX()) { + return; + } + EXPECT_TRUE(treeDumpEqualOnAnnotations( R"cpp( void test(int a) { - 1 - 2; - 1 == 2; - a = 1; - a <<= 1; - 1 || 0; - 1 & 2; - a ^= 3; + [[true || false]]; + [[true or false]]; + [[1 bitand 2]]; + [[a xor_eq 3]]; +} +)cpp", + {R"txt( +BinaryOperatorExpression +|-BoolLiteralExpression +| `-true +|-|| +`-BoolLiteralExpression + `-false +)txt", + R"txt( +BinaryOperatorExpression +|-BoolLiteralExpression +| `-true +|-or +`-BoolLiteralExpression + `-false +)txt", + R"txt( +BinaryOperatorExpression +|-IntegerLiteralExpression +| `-1 +|-bitand +`-IntegerLiteralExpression + `-2 +)txt", + R"txt( +BinaryOperatorExpression +|-IdExpression +| `-UnqualifiedId +| `-a +|-xor_eq +`-IntegerLiteralExpression + `-3 +)txt"})); +} + +TEST_P(SyntaxTreeTest, BinaryOperator_NestedWithParenthesis) { + EXPECT_TRUE(treeDumpEqualOnAnnotations( + R"cpp( +void test() { + [[(1 + 2) * (4 / 2)]]; } +)cpp", + {R"txt( +BinaryOperatorExpression +|-ParenExpression +| |-( +| |-BinaryOperatorExpression +| | |-IntegerLiteralExpression +| | | `-1 +| | |-+ +| | `-IntegerLiteralExpression +| | `-2 +| `-) +|-* +`-ParenExpression + |-( + |-BinaryOperatorExpression + | |-IntegerLiteralExpression + | | `-4 + | |-/ + | `-IntegerLiteralExpression + | `-2 + `-) +)txt"})); +} + +TEST_P(SyntaxTreeTest, BinaryOperator_Associativity) { + EXPECT_TRUE(treeDumpEqualOnAnnotations( + R"cpp( +void test(int a, int b) { + [[a + b + 42]]; + [[a = b = 42]]; +} +)cpp", + {R"txt( +BinaryOperatorExpression +|-BinaryOperatorExpression +| |-IdExpression +| | `-UnqualifiedId +| | `-a +| |-+ +| `-IdExpression +| `-UnqualifiedId +| `-b +|-+ +`-IntegerLiteralExpression + `-42 +)txt", + R"txt( +BinaryOperatorExpression +|-IdExpression +| `-UnqualifiedId +| `-a +|-= +`-BinaryOperatorExpression + |-IdExpression + | `-UnqualifiedId + | `-b + |-= + `-IntegerLiteralExpression + `-42 +)txt"})); +} + +TEST_P(SyntaxTreeTest, BinaryOperator_Precedence) { + EXPECT_TRUE(treeDumpEqualOnAnnotations( + R"cpp( +void test() { + [[1 + 2 * 3 + 4]]; + [[1 % 2 + 3 * 4]]; +} +)cpp", + {R"txt( +BinaryOperatorExpression +|-BinaryOperatorExpression +| |-IntegerLiteralExpression +| | `-1 +| |-+ +| `-BinaryOperatorExpression +| |-IntegerLiteralExpression +| | `-2 +| |-* +| `-IntegerLiteralExpression +| `-3 +|-+ +`-IntegerLiteralExpression + `-4 +)txt", + R"txt( +BinaryOperatorExpression +|-BinaryOperatorExpression +| |-IntegerLiteralExpression +| | `-1 +| |-% +| `-IntegerLiteralExpression +| `-2 +|-+ +`-BinaryOperatorExpression + |-IntegerLiteralExpression + | `-3 + |-* + `-IntegerLiteralExpression + `-4 +)txt"})); +} + +TEST_P(SyntaxTreeTest, OverloadedOperator_MemberDeclaration) { + if (!GetParam().isCXX()) { + return; + } + EXPECT_TRUE(treeDumpEqual( + R"cpp( +struct X { + X& operator=(const X&); +}; )cpp", R"txt( *: TranslationUnit `-SimpleDeclaration - |-void - |-SimpleDeclarator - | |-test - | `-ParametersAndQualifiers - | |-( - | |-SimpleDeclaration - | | |-int - | | `-SimpleDeclarator - | | `-a - | `-) - `-CompoundStatement - |-{ - |-ExpressionStatement - | |-BinaryOperatorExpression - | | |-IntegerLiteralExpression - | | | `-1 - | | |-- - | | `-IntegerLiteralExpression - | | `-2 - | `-; - |-ExpressionStatement - | |-BinaryOperatorExpression - | | |-IntegerLiteralExpression - | | | `-1 - | | |-== - | | `-IntegerLiteralExpression - | | `-2 - | `-; - |-ExpressionStatement - | |-BinaryOperatorExpression - | | |-IdExpression - | | | `-UnqualifiedId - | | | `-a - | | |-= - | | `-IntegerLiteralExpression - | | `-1 - | `-; - |-ExpressionStatement - | |-BinaryOperatorExpression - | | |-IdExpression - | | | `-UnqualifiedId - | | | `-a - | | |-<<= - | | `-IntegerLiteralExpression - | | `-1 - | `-; - |-ExpressionStatement - | |-BinaryOperatorExpression - | | |-IntegerLiteralExpression - | | | `-1 - | | |-|| - | | `-IntegerLiteralExpression - | | `-0 - | `-; - |-ExpressionStatement - | |-BinaryOperatorExpression - | | |-IntegerLiteralExpression - | | | `-1 - | | |-& - | | `-IntegerLiteralExpression - | | `-2 - | `-; - |-ExpressionStatement - | |-BinaryOperatorExpression - | | |-IdExpression - | | | `-UnqualifiedId - | | | `-a - | | |-^= - | | `-IntegerLiteralExpression - | | `-3 - | `-; - `-} -)txt")); -} - -TEST_P(SyntaxTreeTest, BinaryOperatorCxx) { - if (!GetParam().isCXX()) { - return; - } - EXPECT_TRUE(treeDumpEqual( - R"cpp( -void test(int a) { - true || false; - true or false; - 1 bitand 2; - a xor_eq 3; -} -)cpp", - R"txt( -*: TranslationUnit -`-SimpleDeclaration - |-void - |-SimpleDeclarator - | |-test - | `-ParametersAndQualifiers - | |-( - | |-SimpleDeclaration - | | |-int - | | `-SimpleDeclarator - | | `-a - | `-) - `-CompoundStatement - |-{ - |-ExpressionStatement - | |-BinaryOperatorExpression - | | |-BoolLiteralExpression - | | | `-true - | | |-|| - | | `-BoolLiteralExpression - | | `-false - | `-; - |-ExpressionStatement - | |-BinaryOperatorExpression - | | |-BoolLiteralExpression - | | | `-true - | | |-or - | | `-BoolLiteralExpression - | | `-false - | `-; - |-ExpressionStatement - | |-BinaryOperatorExpression - | | |-IntegerLiteralExpression - | | | `-1 - | | |-bitand - | | `-IntegerLiteralExpression - | | `-2 - | `-; - |-ExpressionStatement - | |-BinaryOperatorExpression - | | |-IdExpression - | | | `-UnqualifiedId - | | | `-a - | | |-xor_eq - | | `-IntegerLiteralExpression - | | `-3 - | `-; - `-} -)txt")); -} - -TEST_P(SyntaxTreeTest, BinaryOperator_NestedWithParenthesis) { - EXPECT_TRUE(treeDumpEqual( - R"cpp( -void test() { - (1 + 2) * (4 / 2); -} -)cpp", - R"txt( -*: TranslationUnit -`-SimpleDeclaration - |-void - |-SimpleDeclarator - | |-test - | `-ParametersAndQualifiers - | |-( - | `-) - `-CompoundStatement - |-{ - |-ExpressionStatement - | |-BinaryOperatorExpression - | | |-ParenExpression - | | | |-( - | | | |-BinaryOperatorExpression - | | | | |-IntegerLiteralExpression - | | | | | `-1 - | | | | |-+ - | | | | `-IntegerLiteralExpression - | | | | `-2 - | | | `-) - | | |-* - | | `-ParenExpression - | | |-( - | | |-BinaryOperatorExpression - | | | |-IntegerLiteralExpression - | | | | `-4 - | | | |-/ - | | | `-IntegerLiteralExpression - | | | `-2 - | | `-) - | `-; - `-} -)txt")); -} - -TEST_P(SyntaxTreeTest, BinaryOperator_Associativity) { - EXPECT_TRUE(treeDumpEqual( - R"cpp( -void test(int a, int b) { - a + b + 42; - a = b = 42; -} -)cpp", - R"txt( -*: TranslationUnit -`-SimpleDeclaration - |-void - |-SimpleDeclarator - | |-test - | `-ParametersAndQualifiers - | |-( - | |-SimpleDeclaration - | | |-int - | | `-SimpleDeclarator - | | `-a - | |-, - | |-SimpleDeclaration - | | |-int - | | `-SimpleDeclarator - | | `-b - | `-) - `-CompoundStatement - |-{ - |-ExpressionStatement - | |-BinaryOperatorExpression - | | |-BinaryOperatorExpression - | | | |-IdExpression - | | | | `-UnqualifiedId - | | | | `-a - | | | |-+ - | | | `-IdExpression - | | | `-UnqualifiedId - | | | `-b - | | |-+ - | | `-IntegerLiteralExpression - | | `-42 - | `-; - |-ExpressionStatement - | |-BinaryOperatorExpression - | | |-IdExpression - | | | `-UnqualifiedId - | | | `-a - | | |-= - | | `-BinaryOperatorExpression - | | |-IdExpression - | | | `-UnqualifiedId - | | | `-b - | | |-= - | | `-IntegerLiteralExpression - | | `-42 - | `-; - `-} -)txt")); -} - -TEST_P(SyntaxTreeTest, BinaryOperator_Precedence) { - EXPECT_TRUE(treeDumpEqual( - R"cpp( -void test() { - 1 + 2 * 3 + 4; - 1 % 2 + 3 * 4; -} -)cpp", - R"txt( -*: TranslationUnit -`-SimpleDeclaration - |-void - |-SimpleDeclarator - | |-test - | `-ParametersAndQualifiers - | |-( - | `-) - `-CompoundStatement - |-{ - |-ExpressionStatement - | |-BinaryOperatorExpression - | | |-BinaryOperatorExpression - | | | |-IntegerLiteralExpression - | | | | `-1 - | | | |-+ - | | | `-BinaryOperatorExpression - | | | |-IntegerLiteralExpression - | | | | `-2 - | | | |-* - | | | `-IntegerLiteralExpression - | | | `-3 - | | |-+ - | | `-IntegerLiteralExpression - | | `-4 - | `-; - |-ExpressionStatement - | |-BinaryOperatorExpression - | | |-BinaryOperatorExpression - | | | |-IntegerLiteralExpression - | | | | `-1 - | | | |-% - | | | `-IntegerLiteralExpression - | | | `-2 - | | |-+ - | | `-BinaryOperatorExpression - | | |-IntegerLiteralExpression - | | | `-3 - | | |-* - | | `-IntegerLiteralExpression - | | `-4 - | `-; - `-} + |-struct + |-X + |-{ + |-SimpleDeclaration + | |-X + | |-SimpleDeclarator + | | |-& + | | |-operator + | | |-= + | | `-ParametersAndQualifiers + | | |-( + | | |-SimpleDeclaration + | | | |-const + | | | |-X + | | | `-SimpleDeclarator + | | | `-& + | | `-) + | `-; + |-} + `-; )txt")); } @@ -2610,71 +2149,28 @@ if (!GetParam().isCXX()) { return; } - EXPECT_TRUE(treeDumpEqual( + EXPECT_TRUE(treeDumpEqualOnAnnotations( R"cpp( struct X { X& operator=(const X&); }; void test(X x, X y) { - x = y; + [[x = y]]; } )cpp", - R"txt( -*: TranslationUnit -|-SimpleDeclaration -| |-struct -| |-X -| |-{ -| |-SimpleDeclaration -| | |-X -| | |-SimpleDeclarator -| | | |-& -| | | |-operator -| | | |-= -| | | `-ParametersAndQualifiers -| | | |-( -| | | |-SimpleDeclaration -| | | | |-const -| | | | |-X -| | | | `-SimpleDeclarator -| | | | `-& -| | | `-) -| | `-; -| |-} -| `-; -`-SimpleDeclaration - |-void - |-SimpleDeclarator - | |-test - | `-ParametersAndQualifiers - | |-( - | |-SimpleDeclaration - | | |-X - | | `-SimpleDeclarator - | | `-x - | |-, - | |-SimpleDeclaration - | | |-X - | | `-SimpleDeclarator - | | `-y - | `-) - `-CompoundStatement - |-{ - |-ExpressionStatement - | |-BinaryOperatorExpression - | | |-IdExpression - | | | `-UnqualifiedId - | | | `-x - | | |-= - | | `-IdExpression - | | `-UnqualifiedId - | | `-y - | `-; - `-} -)txt")); + {R"txt( +BinaryOperatorExpression +|-IdExpression +| `-UnqualifiedId +| `-x +|-= +`-IdExpression + `-UnqualifiedId + `-y +)txt"})); } -TEST_P(SyntaxTreeTest, OverloadedOperator_Plus) { +TEST_P(SyntaxTreeTest, OverloadedOperator_FriendDeclarataion) { if (!GetParam().isCXX()) { return; } @@ -2683,571 +2179,249 @@ struct X { friend X operator+(X, const X&); }; -void test(X x, X y) { - x + y; -} -)cpp", - R"txt( -*: TranslationUnit -|-SimpleDeclaration -| |-struct -| |-X -| |-{ -| |-UnknownDeclaration -| | `-SimpleDeclaration -| | |-friend -| | |-X -| | |-SimpleDeclarator -| | | |-operator -| | | |-+ -| | | `-ParametersAndQualifiers -| | | |-( -| | | |-SimpleDeclaration -| | | | `-X -| | | |-, -| | | |-SimpleDeclaration -| | | | |-const -| | | | |-X -| | | | `-SimpleDeclarator -| | | | `-& -| | | `-) -| | `-; -| |-} -| `-; -`-SimpleDeclaration - |-void - |-SimpleDeclarator - | |-test - | `-ParametersAndQualifiers - | |-( - | |-SimpleDeclaration - | | |-X - | | `-SimpleDeclarator - | | `-x - | |-, - | |-SimpleDeclaration - | | |-X - | | `-SimpleDeclarator - | | `-y - | `-) - `-CompoundStatement - |-{ - |-ExpressionStatement - | |-BinaryOperatorExpression - | | |-UnknownExpression - | | | `-IdExpression - | | | `-UnqualifiedId - | | | `-x - | | |-+ - | | `-IdExpression - | | `-UnqualifiedId - | | `-y - | `-; - `-} -)txt")); -} - -TEST_P(SyntaxTreeTest, OverloadedOperator_Less) { - if (!GetParam().isCXX()) { - return; - } - EXPECT_TRUE(treeDumpEqual( - R"cpp( -struct X { - friend bool operator<(const X&, const X&); -}; -void test(X x, X y) { - x < y; -} -)cpp", - R"txt( -*: TranslationUnit -|-SimpleDeclaration -| |-struct -| |-X -| |-{ -| |-UnknownDeclaration -| | `-SimpleDeclaration -| | |-friend -| | |-bool -| | |-SimpleDeclarator -| | | |-operator -| | | |-< -| | | `-ParametersAndQualifiers -| | | |-( -| | | |-SimpleDeclaration -| | | | |-const -| | | | |-X -| | | | `-SimpleDeclarator -| | | | `-& -| | | |-, -| | | |-SimpleDeclaration -| | | | |-const -| | | | |-X -| | | | `-SimpleDeclarator -| | | | `-& -| | | `-) -| | `-; -| |-} -| `-; -`-SimpleDeclaration - |-void - |-SimpleDeclarator - | |-test - | `-ParametersAndQualifiers - | |-( - | |-SimpleDeclaration - | | |-X - | | `-SimpleDeclarator - | | `-x - | |-, - | |-SimpleDeclaration - | | |-X - | | `-SimpleDeclarator - | | `-y - | `-) - `-CompoundStatement - |-{ - |-ExpressionStatement - | |-BinaryOperatorExpression - | | |-IdExpression - | | | `-UnqualifiedId - | | | `-x - | | |-< - | | `-IdExpression - | | `-UnqualifiedId - | | `-y - | `-; - `-} -)txt")); -} - -TEST_P(SyntaxTreeTest, OverloadedOperator_LeftShift) { - if (!GetParam().isCXX()) { - return; - } - EXPECT_TRUE(treeDumpEqual( - R"cpp( -struct X { - friend X operator<<(X&, const X&); -}; -void test(X x, X y) { - x << y; -} )cpp", R"txt( *: TranslationUnit -|-SimpleDeclaration -| |-struct -| |-X -| |-{ -| |-UnknownDeclaration -| | `-SimpleDeclaration -| | |-friend -| | |-X -| | |-SimpleDeclarator -| | | |-operator -| | | |-<< -| | | `-ParametersAndQualifiers -| | | |-( -| | | |-SimpleDeclaration -| | | | |-X -| | | | `-SimpleDeclarator -| | | | `-& -| | | |-, -| | | |-SimpleDeclaration -| | | | |-const -| | | | |-X -| | | | `-SimpleDeclarator -| | | | `-& -| | | `-) -| | `-; -| |-} -| `-; `-SimpleDeclaration - |-void - |-SimpleDeclarator - | |-test - | `-ParametersAndQualifiers - | |-( - | |-SimpleDeclaration - | | |-X - | | `-SimpleDeclarator - | | `-x - | |-, - | |-SimpleDeclaration - | | |-X - | | `-SimpleDeclarator - | | `-y - | `-) - `-CompoundStatement - |-{ - |-ExpressionStatement - | |-BinaryOperatorExpression - | | |-IdExpression - | | | `-UnqualifiedId - | | | `-x - | | |-<< - | | `-IdExpression - | | `-UnqualifiedId - | | `-y - | `-; - `-} + |-struct + |-X + |-{ + |-UnknownDeclaration + | `-SimpleDeclaration + | |-friend + | |-X + | |-SimpleDeclarator + | | |-operator + | | |-+ + | | `-ParametersAndQualifiers + | | |-( + | | |-SimpleDeclaration + | | | `-X + | | |-, + | | |-SimpleDeclaration + | | | |-const + | | | |-X + | | | `-SimpleDeclarator + | | | `-& + | | `-) + | `-; + |-} + `-; )txt")); } +TEST_P(SyntaxTreeTest, OverloadedOperator_Plus) { + if (!GetParam().isCXX()) { + return; + } + EXPECT_TRUE(treeDumpEqualOnAnnotations( + R"cpp( +struct X { + friend X operator+(X, const X&); +}; +void test(X x, X y) { + [[x + y]]; +} +)cpp", + {R"txt( +BinaryOperatorExpression +|-UnknownExpression +| `-IdExpression +| `-UnqualifiedId +| `-x +|-+ +`-IdExpression + `-UnqualifiedId + `-y +)txt"})); +} + +TEST_P(SyntaxTreeTest, OverloadedOperator_Less) { + if (!GetParam().isCXX()) { + return; + } + EXPECT_TRUE(treeDumpEqualOnAnnotations( + R"cpp( +struct X { + friend bool operator<(const X&, const X&); +}; +void test(X x, X y) { + [[x < y]]; +} +)cpp", + {R"txt( +BinaryOperatorExpression +|-IdExpression +| `-UnqualifiedId +| `-x +|-< +`-IdExpression + `-UnqualifiedId + `-y +)txt"})); +} + +TEST_P(SyntaxTreeTest, OverloadedOperator_LeftShift) { + if (!GetParam().isCXX()) { + return; + } + EXPECT_TRUE(treeDumpEqualOnAnnotations( + R"cpp( +struct X { + friend X operator<<(X&, const X&); +}; +void test(X x, X y) { + [[x << y]]; +} +)cpp", + {R"txt( +BinaryOperatorExpression +|-IdExpression +| `-UnqualifiedId +| `-x +|-<< +`-IdExpression + `-UnqualifiedId + `-y +)txt"})); +} + TEST_P(SyntaxTreeTest, OverloadedOperator_Comma) { if (!GetParam().isCXX()) { return; } - EXPECT_TRUE(treeDumpEqual( + EXPECT_TRUE(treeDumpEqualOnAnnotations( R"cpp( struct X { X operator,(X&); }; void test(X x, X y) { - x, y; + [[x, y]]; } )cpp", - R"txt( -*: TranslationUnit -|-SimpleDeclaration -| |-struct -| |-X -| |-{ -| |-SimpleDeclaration -| | |-X -| | |-SimpleDeclarator -| | | |-operator -| | | |-, -| | | `-ParametersAndQualifiers -| | | |-( -| | | |-SimpleDeclaration -| | | | |-X -| | | | `-SimpleDeclarator -| | | | `-& -| | | `-) -| | `-; -| |-} -| `-; -`-SimpleDeclaration - |-void - |-SimpleDeclarator - | |-test - | `-ParametersAndQualifiers - | |-( - | |-SimpleDeclaration - | | |-X - | | `-SimpleDeclarator - | | `-x - | |-, - | |-SimpleDeclaration - | | |-X - | | `-SimpleDeclarator - | | `-y - | `-) - `-CompoundStatement - |-{ - |-ExpressionStatement - | |-BinaryOperatorExpression - | | |-IdExpression - | | | `-UnqualifiedId - | | | `-x - | | |-, - | | `-IdExpression - | | `-UnqualifiedId - | | `-y - | `-; - `-} -)txt")); + {R"txt( +BinaryOperatorExpression +|-IdExpression +| `-UnqualifiedId +| `-x +|-, +`-IdExpression + `-UnqualifiedId + `-y +)txt"})); } TEST_P(SyntaxTreeTest, OverloadedOperator_PointerToMember) { if (!GetParam().isCXX()) { return; } - EXPECT_TRUE(treeDumpEqual( + EXPECT_TRUE(treeDumpEqualOnAnnotations( R"cpp( struct X { X operator->*(int); }; void test(X* xp, int X::* pmi) { - xp->*pmi; + [[xp->*pmi]]; } )cpp", - R"txt( -*: TranslationUnit -|-SimpleDeclaration -| |-struct -| |-X -| |-{ -| |-SimpleDeclaration -| | |-X -| | |-SimpleDeclarator -| | | |-operator -| | | |-->* -| | | `-ParametersAndQualifiers -| | | |-( -| | | |-SimpleDeclaration -| | | | `-int -| | | `-) -| | `-; -| |-} -| `-; -`-SimpleDeclaration - |-void - |-SimpleDeclarator - | |-test - | `-ParametersAndQualifiers - | |-( - | |-SimpleDeclaration - | | |-X - | | `-SimpleDeclarator - | | |-* - | | `-xp - | |-, - | |-SimpleDeclaration - | | |-int - | | `-SimpleDeclarator - | | |-MemberPointer - | | | |-X - | | | |-:: - | | | `-* - | | `-pmi - | `-) - `-CompoundStatement - |-{ - |-ExpressionStatement - | |-BinaryOperatorExpression - | | |-IdExpression - | | | `-UnqualifiedId - | | | `-xp - | | |-->* - | | `-IdExpression - | | `-UnqualifiedId - | | `-pmi - | `-; - `-} -)txt")); + {R"txt( +BinaryOperatorExpression +|-IdExpression +| `-UnqualifiedId +| `-xp +|-->* +`-IdExpression + `-UnqualifiedId + `-pmi +)txt"})); } TEST_P(SyntaxTreeTest, OverloadedOperator_Negation) { if (!GetParam().isCXX()) { return; } - EXPECT_TRUE(treeDumpEqual( + EXPECT_TRUE(treeDumpEqualOnAnnotations( R"cpp( struct X { bool operator!(); }; void test(X x) { - !x; + [[!x]]; } )cpp", - R"txt( -*: TranslationUnit -|-SimpleDeclaration -| |-struct -| |-X -| |-{ -| |-SimpleDeclaration -| | |-bool -| | |-SimpleDeclarator -| | | |-operator -| | | |-! -| | | `-ParametersAndQualifiers -| | | |-( -| | | `-) -| | `-; -| |-} -| `-; -`-SimpleDeclaration - |-void - |-SimpleDeclarator - | |-test - | `-ParametersAndQualifiers - | |-( - | |-SimpleDeclaration - | | |-X - | | `-SimpleDeclarator - | | `-x - | `-) - `-CompoundStatement - |-{ - |-ExpressionStatement - | |-PrefixUnaryOperatorExpression - | | |-! - | | `-IdExpression - | | `-UnqualifiedId - | | `-x - | `-; - `-} -)txt")); + {R"txt( +PrefixUnaryOperatorExpression +|-! +`-IdExpression + `-UnqualifiedId + `-x +)txt"})); } TEST_P(SyntaxTreeTest, OverloadedOperator_AddressOf) { if (!GetParam().isCXX()) { return; } - EXPECT_TRUE(treeDumpEqual( + EXPECT_TRUE(treeDumpEqualOnAnnotations( R"cpp( struct X { X* operator&(); }; void test(X x) { - &x; + [[&x]]; } )cpp", - R"txt( -*: TranslationUnit -|-SimpleDeclaration -| |-struct -| |-X -| |-{ -| |-SimpleDeclaration -| | |-X -| | |-SimpleDeclarator -| | | |-* -| | | |-operator -| | | |-& -| | | `-ParametersAndQualifiers -| | | |-( -| | | `-) -| | `-; -| |-} -| `-; -`-SimpleDeclaration - |-void - |-SimpleDeclarator - | |-test - | `-ParametersAndQualifiers - | |-( - | |-SimpleDeclaration - | | |-X - | | `-SimpleDeclarator - | | `-x - | `-) - `-CompoundStatement - |-{ - |-ExpressionStatement - | |-PrefixUnaryOperatorExpression - | | |-& - | | `-IdExpression - | | `-UnqualifiedId - | | `-x - | `-; - `-} -)txt")); + {R"txt( +PrefixUnaryOperatorExpression +|-& +`-IdExpression + `-UnqualifiedId + `-x +)txt"})); } TEST_P(SyntaxTreeTest, OverloadedOperator_PrefixIncrement) { if (!GetParam().isCXX()) { return; } - EXPECT_TRUE(treeDumpEqual( + EXPECT_TRUE(treeDumpEqualOnAnnotations( R"cpp( struct X { X operator++(); }; void test(X x) { - ++x; + [[++x]]; } )cpp", - R"txt( -*: TranslationUnit -|-SimpleDeclaration -| |-struct -| |-X -| |-{ -| |-SimpleDeclaration -| | |-X -| | |-SimpleDeclarator -| | | |-operator -| | | |-++ -| | | `-ParametersAndQualifiers -| | | |-( -| | | `-) -| | `-; -| |-} -| `-; -`-SimpleDeclaration - |-void - |-SimpleDeclarator - | |-test - | `-ParametersAndQualifiers - | |-( - | |-SimpleDeclaration - | | |-X - | | `-SimpleDeclarator - | | `-x - | `-) - `-CompoundStatement - |-{ - |-ExpressionStatement - | |-PrefixUnaryOperatorExpression - | | |-++ - | | `-IdExpression - | | `-UnqualifiedId - | | `-x - | `-; - `-} -)txt")); + {R"txt( +PrefixUnaryOperatorExpression +|-++ +`-IdExpression + `-UnqualifiedId + `-x +)txt"})); } TEST_P(SyntaxTreeTest, OverloadedOperator_PostfixIncrement) { if (!GetParam().isCXX()) { return; } - EXPECT_TRUE(treeDumpEqual( + EXPECT_TRUE(treeDumpEqualOnAnnotations( R"cpp( struct X { X operator++(int); }; void test(X x) { - x++; + [[x++]]; } )cpp", - R"txt( -*: TranslationUnit -|-SimpleDeclaration -| |-struct -| |-X -| |-{ -| |-SimpleDeclaration -| | |-X -| | |-SimpleDeclarator -| | | |-operator -| | | |-++ -| | | `-ParametersAndQualifiers -| | | |-( -| | | |-SimpleDeclaration -| | | | `-int -| | | `-) -| | `-; -| |-} -| `-; -`-SimpleDeclaration - |-void - |-SimpleDeclarator - | |-test - | `-ParametersAndQualifiers - | |-( - | |-SimpleDeclaration - | | |-X - | | `-SimpleDeclarator - | | `-x - | `-) - `-CompoundStatement - |-{ - |-ExpressionStatement - | |-PostfixUnaryOperatorExpression - | | |-IdExpression - | | | `-UnqualifiedId - | | | `-x - | | `-++ - | `-; - `-} -)txt")); + {R"txt( +PostfixUnaryOperatorExpression +|-IdExpression +| `-UnqualifiedId +| `-x +`-++ +)txt"})); } TEST_P(SyntaxTreeTest, MultipleDeclaratorsGrouping) {
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits