aboutsummaryrefslogtreecommitdiff
path: root/clang/unittests/Tooling/Syntax/TreeTest.cpp
diff options
context:
space:
mode:
authorEduardo Caldas <ecaldas@google.com>2020-08-04 17:33:36 +0000
committerEduardo Caldas <ecaldas@google.com>2020-08-07 18:05:47 +0000
commit8abb5fb68f81b0e42d824bf080b1cef9a61559d6 (patch)
treef1e6e05d4bd4c318749e7e58e8738568b96dc4d2 /clang/unittests/Tooling/Syntax/TreeTest.cpp
parent25367dfefb7ba5cc35dc56bf5063562695f1dd04 (diff)
downloadllvm-8abb5fb68f81b0e42d824bf080b1cef9a61559d6.zip
llvm-8abb5fb68f81b0e42d824bf080b1cef9a61559d6.tar.gz
llvm-8abb5fb68f81b0e42d824bf080b1cef9a61559d6.tar.bz2
[SyntaxTree] Use simplified grammar rule for `NestedNameSpecifier` grammar nodes
This is our grammar rule for nested-name-specifiers: globalbal-specifier: /*empty*/ simple-template-specifier: template_opt simple-template-id name-specifier: global-specifier decltype-specifier identifier simple-template-specifier nested-name-specifier: list(name-specifier, ::, non-empty, terminated) It is a relaxed version of C++ [expr.prim.id] and quite simpler to map to our API. TODO: refine name specifiers, `simple-template-name-specifier` and decltype-name-specifier` are token soup for now.
Diffstat (limited to 'clang/unittests/Tooling/Syntax/TreeTest.cpp')
-rw-r--r--clang/unittests/Tooling/Syntax/TreeTest.cpp314
1 files changed, 209 insertions, 105 deletions
diff --git a/clang/unittests/Tooling/Syntax/TreeTest.cpp b/clang/unittests/Tooling/Syntax/TreeTest.cpp
index f818959..fa5da1f 100644
--- a/clang/unittests/Tooling/Syntax/TreeTest.cpp
+++ b/clang/unittests/Tooling/Syntax/TreeTest.cpp
@@ -873,24 +873,47 @@ TEST_P(SyntaxTreeTest, QualifiedId) {
}
EXPECT_TRUE(treeDumpEqual(
R"cpp(
-namespace a {
+namespace n {
struct S {
template<typename T>
- static T f(){}
+ struct ST {
+ static void f();
+ };
};
}
+template<typename T>
+struct ST {
+ struct S {
+ template<typename U>
+ static U f();
+ };
+};
void test() {
- :: // global-namespace-specifier
- a:: // namespace-specifier
- S:: // type-name-specifier
+ :: // global-namespace-specifier
+ n:: // namespace-specifier
+ S:: // type-name-specifier
+ template ST<int>:: // type-template-instantiation-specifier
+ f();
+
+ n:: // namespace-specifier
+ S:: // type-name-specifier
+ ST<int>:: // type-template-instantiation-specifier
+ f();
+
+ ST<int>:: // type-name-specifier
+ S:: // type-name-specifier
f<int>();
+
+ ST<int>:: // type-name-specifier
+ S:: // type-name-specifier
+ template f<int>();
}
)cpp",
R"txt(
*: TranslationUnit
|-NamespaceDefinition
| |-namespace
-| |-a
+| |-n
| |-{
| |-SimpleDeclaration
| | |-struct
@@ -904,19 +927,58 @@ void test() {
| | | | `-T
| | | |->
| | | `-SimpleDeclaration
-| | | |-static
-| | | |-T
-| | | |-SimpleDeclarator
-| | | | |-f
-| | | | `-ParametersAndQualifiers
-| | | | |-(
-| | | | `-)
-| | | `-CompoundStatement
-| | | |-{
-| | | `-}
+| | | |-struct
+| | | |-ST
+| | | |-{
+| | | |-SimpleDeclaration
+| | | | |-static
+| | | | |-void
+| | | | |-SimpleDeclarator
+| | | | | |-f
+| | | | | `-ParametersAndQualifiers
+| | | | | |-(
+| | | | | `-)
+| | | | `-;
+| | | |-}
+| | | `-;
| | |-}
| | `-;
| `-}
+|-TemplateDeclaration
+| |-template
+| |-<
+| |-UnknownDeclaration
+| | |-typename
+| | `-T
+| |->
+| `-SimpleDeclaration
+| |-struct
+| |-ST
+| |-{
+| |-SimpleDeclaration
+| | |-struct
+| | |-S
+| | |-{
+| | |-TemplateDeclaration
+| | | |-template
+| | | |-<
+| | | |-UnknownDeclaration
+| | | | |-typename
+| | | | `-U
+| | | |->
+| | | `-SimpleDeclaration
+| | | |-static
+| | | |-U
+| | | |-SimpleDeclarator
+| | | | |-f
+| | | | `-ParametersAndQualifiers
+| | | | |-(
+| | | | `-)
+| | | `-;
+| | |-}
+| | `-;
+| |-}
+| `-;
`-SimpleDeclaration
|-void
|-SimpleDeclarator
@@ -930,14 +992,81 @@ void test() {
| |-UnknownExpression
| | |-IdExpression
| | | |-NestedNameSpecifier
- | | | | |-NameSpecifier
- | | | | | `-::
- | | | | |-NameSpecifier
- | | | | | |-a
- | | | | | `-::
- | | | | `-NameSpecifier
- | | | | |-S
- | | | | `-::
+ | | | | |-::
+ | | | | |-IdentifierNameSpecifier
+ | | | | | `-n
+ | | | | |-::
+ | | | | |-IdentifierNameSpecifier
+ | | | | | `-S
+ | | | | |-::
+ | | | | |-SimpleTemplateNameSpecifier
+ | | | | | |-template
+ | | | | | |-ST
+ | | | | | |-<
+ | | | | | |-int
+ | | | | | `->
+ | | | | `-::
+ | | | `-UnqualifiedId
+ | | | `-f
+ | | |-(
+ | | `-)
+ | `-;
+ |-ExpressionStatement
+ | |-UnknownExpression
+ | | |-IdExpression
+ | | | |-NestedNameSpecifier
+ | | | | |-IdentifierNameSpecifier
+ | | | | | `-n
+ | | | | |-::
+ | | | | |-IdentifierNameSpecifier
+ | | | | | `-S
+ | | | | |-::
+ | | | | |-SimpleTemplateNameSpecifier
+ | | | | | |-ST
+ | | | | | |-<
+ | | | | | |-int
+ | | | | | `->
+ | | | | `-::
+ | | | `-UnqualifiedId
+ | | | `-f
+ | | |-(
+ | | `-)
+ | `-;
+ |-ExpressionStatement
+ | |-UnknownExpression
+ | | |-IdExpression
+ | | | |-NestedNameSpecifier
+ | | | | |-SimpleTemplateNameSpecifier
+ | | | | | |-ST
+ | | | | | |-<
+ | | | | | |-int
+ | | | | | `->
+ | | | | |-::
+ | | | | |-IdentifierNameSpecifier
+ | | | | | `-S
+ | | | | `-::
+ | | | `-UnqualifiedId
+ | | | |-f
+ | | | |-<
+ | | | |-int
+ | | | `->
+ | | |-(
+ | | `-)
+ | `-;
+ |-ExpressionStatement
+ | |-UnknownExpression
+ | | |-IdExpression
+ | | | |-NestedNameSpecifier
+ | | | | |-SimpleTemplateNameSpecifier
+ | | | | | |-ST
+ | | | | | |-<
+ | | | | | |-int
+ | | | | | `->
+ | | | | |-::
+ | | | | |-IdentifierNameSpecifier
+ | | | | | `-S
+ | | | | `-::
+ | | | |-template
| | | `-UnqualifiedId
| | | |-f
| | | |-<
@@ -950,7 +1079,7 @@ void test() {
)txt"));
}
-TEST_P(SyntaxTreeTest, QualifiedIdWithTemplateKeyword) {
+TEST_P(SyntaxTreeTest, QualifiedIdWithDependentType) {
if (!GetParam().isCXX()) {
return;
}
@@ -961,63 +1090,17 @@ TEST_P(SyntaxTreeTest, QualifiedIdWithTemplateKeyword) {
}
EXPECT_TRUE(treeDumpEqual(
R"cpp(
-struct X {
- template<int> static void f();
- template<int>
- struct Y {
- static void f();
- };
-};
-template<typename T> void test() {
- // TODO: Expose `id-expression` from `DependentScopeDeclRefExpr`
- T::template f<0>(); // nested-name-specifier template unqualified-id
- T::template Y<0>::f(); // nested-name-specifier template :: unqualified-id
+template <typename T>
+void test() {
+ T::template U<int>::f();
+
+ T::U::f();
+
+ T::template f<0>();
}
)cpp",
R"txt(
*: TranslationUnit
-|-SimpleDeclaration
-| |-struct
-| |-X
-| |-{
-| |-TemplateDeclaration
-| | |-template
-| | |-<
-| | |-SimpleDeclaration
-| | | `-int
-| | |->
-| | `-SimpleDeclaration
-| | |-static
-| | |-void
-| | |-SimpleDeclarator
-| | | |-f
-| | | `-ParametersAndQualifiers
-| | | |-(
-| | | `-)
-| | `-;
-| |-TemplateDeclaration
-| | |-template
-| | |-<
-| | |-SimpleDeclaration
-| | | `-int
-| | |->
-| | `-SimpleDeclaration
-| | |-struct
-| | |-Y
-| | |-{
-| | |-SimpleDeclaration
-| | | |-static
-| | | |-void
-| | | |-SimpleDeclarator
-| | | | |-f
-| | | | `-ParametersAndQualifiers
-| | | | |-(
-| | | | `-)
-| | | `-;
-| | |-}
-| | `-;
-| |-}
-| `-;
`-TemplateDeclaration
|-template
|-<
@@ -1036,31 +1119,52 @@ template<typename T> void test() {
|-{
|-ExpressionStatement
| |-UnknownExpression
- | | |-UnknownExpression
- | | | |-T
- | | | |-::
- | | | |-template
- | | | |-f
- | | | |-<
- | | | |-IntegerLiteralExpression
- | | | | `-0
- | | | `->
+ | | |-IdExpression
+ | | | |-NestedNameSpecifier
+ | | | | |-IdentifierNameSpecifier
+ | | | | | `-T
+ | | | | |-::
+ | | | | |-SimpleTemplateNameSpecifier
+ | | | | | |-template
+ | | | | | |-U
+ | | | | | |-<
+ | | | | | |-int
+ | | | | | `->
+ | | | | `-::
+ | | | `-UnqualifiedId
+ | | | `-f
+ | | |-(
+ | | `-)
+ | `-;
+ |-ExpressionStatement
+ | |-UnknownExpression
+ | | |-IdExpression
+ | | | |-NestedNameSpecifier
+ | | | | |-IdentifierNameSpecifier
+ | | | | | `-T
+ | | | | |-::
+ | | | | |-IdentifierNameSpecifier
+ | | | | | `-U
+ | | | | `-::
+ | | | `-UnqualifiedId
+ | | | `-f
| | |-(
| | `-)
| `-;
|-ExpressionStatement
| |-UnknownExpression
- | | |-UnknownExpression
- | | | |-T
- | | | |-::
+ | | |-IdExpression
+ | | | |-NestedNameSpecifier
+ | | | | |-IdentifierNameSpecifier
+ | | | | | `-T
+ | | | | `-::
| | | |-template
- | | | |-Y
- | | | |-<
- | | | |-IntegerLiteralExpression
- | | | | `-0
- | | | |->
- | | | |-::
- | | | `-f
+ | | | `-UnqualifiedId
+ | | | |-f
+ | | | |-<
+ | | | |-IntegerLiteralExpression
+ | | | | `-0
+ | | | `->
| | |-(
| | `-)
| `-;
@@ -1118,14 +1222,14 @@ void test(S s) {
| |-UnknownExpression
| | |-IdExpression
| | | |-NestedNameSpecifier
- | | | | `-NameSpecifier
- | | | | |-decltype
- | | | | |-(
- | | | | |-IdExpression
- | | | | | `-UnqualifiedId
- | | | | | `-s
- | | | | |-)
- | | | | `-::
+ | | | | |-DecltypeNameSpecifier
+ | | | | | |-decltype
+ | | | | | |-(
+ | | | | | |-IdExpression
+ | | | | | | `-UnqualifiedId
+ | | | | | | `-s
+ | | | | | `-)
+ | | | | `-::
| | | `-UnqualifiedId
| | | `-f
| | |-(