eduucaldas created this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.
eduucaldas requested review of this revision.
We do that because:
- Big tests generated big tree dumps that could hardly serve as documentation.
- In most cases the tests didn't share setup, thus there was not much addition
in lines of code.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D85819
Files:
clang/unittests/Tooling/Syntax/TreeTest.cpp
Index: clang/unittests/Tooling/Syntax/TreeTest.cpp
===================================================================
--- clang/unittests/Tooling/Syntax/TreeTest.cpp
+++ clang/unittests/Tooling/Syntax/TreeTest.cpp
@@ -632,26 +632,48 @@
)txt"));
}
-TEST_P(SyntaxTreeTest, UnqualifiedId) {
+TEST_P(SyntaxTreeTest, UnqualifiedIdIdentifier) {
+ EXPECT_TRUE(treeDumpEqual(
+ R"cpp(
+void test(int a) {
+ a;
+}
+)cpp",
+ R"txt(
+*: TranslationUnit
+`-SimpleDeclaration
+ |-void
+ |-SimpleDeclarator
+ | |-test
+ | `-ParametersAndQualifiers
+ | |-(
+ | |-SimpleDeclaration
+ | | |-int
+ | | `-SimpleDeclarator
+ | | `-a
+ | `-)
+ `-CompoundStatement
+ |-{
+ |-ExpressionStatement
+ | |-IdExpression
+ | | `-UnqualifiedId
+ | | `-a
+ | `-;
+ `-}
+)txt"));
+}
+
+TEST_P(SyntaxTreeTest, UnqualifiedIdOperatorFunctionId) {
if (!GetParam().isCXX()) {
return;
}
EXPECT_TRUE(treeDumpEqual(
R"cpp(
struct X {
- // TODO: Expose `id-expression` from `Declarator`
friend X operator+(const X&, const X&);
- operator int();
};
-template<typename T>
-void f(T&);
void test(X x) {
- x; // identifier
- operator+(x, x); // operator-function-id
- f<X>(x); // template-id
- // TODO: Expose `id-expression` from `MemberExpr`
- x.operator int(); // conversion-funtion-id
- x.~X(); // ~type-name
+ operator+(x, x);
}
)cpp",
R"txt(
@@ -682,35 +704,8 @@
| | | | `-&
| | | `-)
| | `-;
-| |-SimpleDeclaration
-| | |-SimpleDeclarator
-| | | |-operator
-| | | |-int
-| | | `-ParametersAndQualifiers
-| | | |-(
-| | | `-)
-| | `-;
| |-}
| `-;
-|-TemplateDeclaration
-| |-template
-| |-<
-| |-UnknownDeclaration
-| | |-typename
-| | `-T
-| |->
-| `-SimpleDeclaration
-| |-void
-| |-SimpleDeclarator
-| | |-f
-| | `-ParametersAndQualifiers
-| | |-(
-| | |-SimpleDeclaration
-| | | |-T
-| | | `-SimpleDeclarator
-| | | `-&
-| | `-)
-| `-;
`-SimpleDeclaration
|-void
|-SimpleDeclarator
@@ -725,11 +720,6 @@
`-CompoundStatement
|-{
|-ExpressionStatement
- | |-IdExpression
- | | `-UnqualifiedId
- | | `-x
- | `-;
- |-ExpressionStatement
| |-UnknownExpression
| | |-IdExpression
| | | `-UnqualifiedId
@@ -745,20 +735,53 @@
| | | `-x
| | `-)
| `-;
- |-ExpressionStatement
- | |-UnknownExpression
- | | |-IdExpression
- | | | `-UnqualifiedId
- | | | |-f
- | | | |-<
- | | | |-X
- | | | `->
- | | |-(
- | | |-IdExpression
- | | | `-UnqualifiedId
- | | | `-x
- | | `-)
- | `-;
+ `-}
+)txt"));
+}
+
+TEST_P(SyntaxTreeTest, UnqualifiedIdConversionFunctionId) {
+ if (!GetParam().isCXX()) {
+ return;
+ }
+ EXPECT_TRUE(treeDumpEqual(
+ R"cpp(
+struct X {
+ operator int();
+};
+void test(X x) {
+ // TODO: Expose `id-expression` from `MemberExpr`
+ x.operator int();
+}
+)cpp",
+ R"txt(
+*: TranslationUnit
+|-SimpleDeclaration
+| |-struct
+| |-X
+| |-{
+| |-SimpleDeclaration
+| | |-SimpleDeclarator
+| | | |-operator
+| | | |-int
+| | | `-ParametersAndQualifiers
+| | | |-(
+| | | `-)
+| | `-;
+| |-}
+| `-;
+`-SimpleDeclaration
+ |-void
+ |-SimpleDeclarator
+ | |-test
+ | `-ParametersAndQualifiers
+ | |-(
+ | |-SimpleDeclaration
+ | | |-X
+ | | `-SimpleDeclarator
+ | | `-x
+ | `-)
+ `-CompoundStatement
+ |-{
|-ExpressionStatement
| |-UnknownExpression
| | |-UnknownExpression
@@ -771,6 +794,93 @@
| | |-(
| | `-)
| `-;
+ `-}
+)txt"));
+}
+
+TEST_P(SyntaxTreeTest, UnqualifiedIdLiteralOperatorId) {
+ if (!GetParam().isCXX11OrLater()) {
+ return;
+ }
+ EXPECT_TRUE(treeDumpEqual(
+ R"cpp(
+unsigned operator "" _w(char);
+void test() {
+ operator "" _w('1');
+}
+)cpp",
+ R"txt(
+*: TranslationUnit
+|-SimpleDeclaration
+| |-unsigned
+| |-SimpleDeclarator
+| | |-operator
+| | |-""
+| | |-_w
+| | `-ParametersAndQualifiers
+| | |-(
+| | |-SimpleDeclaration
+| | | `-char
+| | `-)
+| `-;
+`-SimpleDeclaration
+ |-void
+ |-SimpleDeclarator
+ | |-test
+ | `-ParametersAndQualifiers
+ | |-(
+ | `-)
+ `-CompoundStatement
+ |-{
+ |-ExpressionStatement
+ | |-UnknownExpression
+ | | |-IdExpression
+ | | | `-UnqualifiedId
+ | | | |-operator
+ | | | |-""
+ | | | `-_w
+ | | |-(
+ | | |-CharacterLiteralExpression
+ | | | `-'1'
+ | | `-)
+ | `-;
+ `-}
+)txt"));
+}
+
+TEST_P(SyntaxTreeTest, UnqualifiedIdDestructor) {
+ if (!GetParam().isCXX()) {
+ return;
+ }
+ EXPECT_TRUE(treeDumpEqual(
+ R"cpp(
+struct X { };
+void test(X x) {
+ // TODO: Expose `id-expression` from `MemberExpr`
+ x.~X();
+}
+)cpp",
+ R"txt(
+*: TranslationUnit
+|-SimpleDeclaration
+| |-struct
+| |-X
+| |-{
+| |-}
+| `-;
+`-SimpleDeclaration
+ |-void
+ |-SimpleDeclarator
+ | |-test
+ | `-ParametersAndQualifiers
+ | |-(
+ | |-SimpleDeclaration
+ | | |-X
+ | | `-SimpleDeclarator
+ | | `-x
+ | `-)
+ `-CompoundStatement
+ |-{
|-ExpressionStatement
| |-UnknownExpression
| | |-UnknownExpression
@@ -787,18 +897,16 @@
)txt"));
}
-TEST_P(SyntaxTreeTest, UnqualifiedIdCxx11OrLater) {
+TEST_P(SyntaxTreeTest, UnqualifiedIdDecltypeDestructor) {
if (!GetParam().isCXX11OrLater()) {
return;
}
EXPECT_TRUE(treeDumpEqual(
R"cpp(
struct X { };
-unsigned operator "" _w(long long unsigned);
void test(X x) {
- operator "" _w(1llu); // literal-operator-id
// TODO: Expose `id-expression` from `MemberExpr`
- x.~decltype(x)(); // ~decltype-specifier
+ x.~decltype(x)();
}
)cpp",
R"txt(
@@ -809,20 +917,6 @@
| |-{
| |-}
| `-;
-|-SimpleDeclaration
-| |-unsigned
-| |-SimpleDeclarator
-| | |-operator
-| | |-""
-| | |-_w
-| | `-ParametersAndQualifiers
-| | |-(
-| | |-SimpleDeclaration
-| | | |-long
-| | | |-long
-| | | `-unsigned
-| | `-)
-| `-;
`-SimpleDeclaration
|-void
|-SimpleDeclarator
@@ -838,18 +932,6 @@
|-{
|-ExpressionStatement
| |-UnknownExpression
- | | |-IdExpression
- | | | `-UnqualifiedId
- | | | |-operator
- | | | |-""
- | | | `-_w
- | | |-(
- | | |-IntegerLiteralExpression
- | | | `-1llu
- | | `-)
- | `-;
- |-ExpressionStatement
- | |-UnknownExpression
| | |-UnknownExpression
| | | |-IdExpression
| | | | `-UnqualifiedId
@@ -867,6 +949,59 @@
)txt"));
}
+TEST_P(SyntaxTreeTest, UnqualifiedIdTemplateId) {
+ if (!GetParam().isCXX()) {
+ return;
+ }
+ EXPECT_TRUE(treeDumpEqual(
+ 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
+ | | | `->
+ | | |-(
+ | | `-)
+ | `-;
+ `-}
+)txt"));
+}
+
TEST_P(SyntaxTreeTest, QualifiedId) {
if (!GetParam().isCXX()) {
return;
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits