diff --git a/clang/unittests/Tooling/Syntax/TreeTest.cpp b/clang/unittests/Tooling/Syntax/TreeTest.cpp --- a/clang/unittests/Tooling/Syntax/TreeTest.cpp +++ b/clang/unittests/Tooling/Syntax/TreeTest.cpp @@ -692,6 +692,152 @@ )txt")); } +TEST_P(SyntaxTreeTest, UnqualifiedId) { + if (!GetParam().isCXX()) { + return; + } + EXPECT_TRUE(treeDumpEqual( + R"cpp( +void test(int b) { + int a; + a = b; +} +)cpp", + R"txt( +*: TranslationUnit +`-SimpleDeclaration + |-void + |-SimpleDeclarator + | |-test + | `-ParametersAndQualifiers + | |-( + | |-SimpleDeclaration + | | |-int + | | `-SimpleDeclarator + | | `-b + | `-) + `-CompoundStatement + |-{ + |-DeclarationStatement + | |-SimpleDeclaration + | | |-int + | | `-SimpleDeclarator + | | `-a + | `-; + |-ExpressionStatement + | |-BinaryOperatorExpression + | | |-IdExpression + | | | `-UnqualifiedId + | | | `-a + | | |-= + | | `-IdExpression + | | `-UnqualifiedId + | | `-b + | `-; + `-} +)txt")); +} + +TEST_P(SyntaxTreeTest, QualifiedId) { + if (!GetParam().isCXX()) { + return; + } + EXPECT_TRUE(treeDumpEqual( + R"cpp( +namespace a { + namespace b { + struct S { + int i; + static void f(){} + }; + } +} +void test(int b) { + ::a::b::S::f(); +} +)cpp", + R"txt( +*: TranslationUnit +|-NamespaceDefinition +| |-namespace +| |-a +| |-{ +| |-NamespaceDefinition +| | |-namespace +| | |-b +| | |-{ +| | |-SimpleDeclaration +| | | |-struct +| | | |-S +| | | |-{ +| | | |-SimpleDeclaration +| | | | |-int +| | | | |-SimpleDeclarator +| | | | | `-i +| | | | `-; +| | | |-SimpleDeclaration +| | | | |-static +| | | | |-void +| | | | |-SimpleDeclarator +| | | | | |-f +| | | | | `-ParametersAndQualifiers +| | | | | |-( +| | | | | `-) +| | | | `-CompoundStatement +| | | | |-{ +| | | | `-} +| | | |-} +| | | `-; +| | `-} +| `-} +`-SimpleDeclaration + |-void + |-SimpleDeclarator + | |-test + | `-ParametersAndQualifiers + | |-( + | |-SimpleDeclaration + | | |-int + | | `-SimpleDeclarator + | | `-b + | `-) + `-CompoundStatement + |-{ + |-DeclarationStatement + | |-SimpleDeclaration + | | |-a + | | |-:: + | | |-b + | | |-:: + | | |-S + | | `-SimpleDeclarator + | | `-UnknownExpression + | | `-s + | `-; + |-ExpressionStatement + | |-UnknownExpression + | | |-IdExpression + | | | |-NestedNameSpecifier + | | | | |-GlobalNamespaceSpecifier + | | | | | `:: + | | | | |-NamespaceNameSpecifier + | | | | | |-a + | | | | | `-:: + | | | | |-NamespaceNameSpecifier + | | | | | |-b + | | | | | `-:: + | | | | `-TypeNameSpecifier + | | | | |-S + | | | | `-:: + | | | `-UnqualifiedId + | | | `-f + | | |-( + | | `-) + | `-; + `-} +)txt")); +} + TEST_P(SyntaxTreeTest, CxxNullPtrLiteral) { if (!GetParam().isCXX11OrLater()) { return;