aboutsummaryrefslogtreecommitdiff
path: root/clang/unittests/Tooling/Syntax/TreeTest.cpp
diff options
context:
space:
mode:
authorEduardo Caldas <ecaldas@google.com>2020-05-27 15:27:59 +0200
committerDmitri Gribenko <gribozavr@gmail.com>2020-05-27 17:12:46 +0200
commit461af57de78155ee5d1dc1969b81dd019d228538 (patch)
tree4cac42b4e39dcd35e29ebdf7f5ddd99ec6a30c75 /clang/unittests/Tooling/Syntax/TreeTest.cpp
parentb5b00877221ec7817b9de9cd65571e1c05e80145 (diff)
downloadllvm-461af57de78155ee5d1dc1969b81dd019d228538.zip
llvm-461af57de78155ee5d1dc1969b81dd019d228538.tar.gz
llvm-461af57de78155ee5d1dc1969b81dd019d228538.tar.bz2
Add support for UnaryOperator in SyntaxTree
Reviewers: gribozavr2 Reviewed By: gribozavr2 Subscribers: cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D80624
Diffstat (limited to 'clang/unittests/Tooling/Syntax/TreeTest.cpp')
-rw-r--r--clang/unittests/Tooling/Syntax/TreeTest.cpp157
1 files changed, 156 insertions, 1 deletions
diff --git a/clang/unittests/Tooling/Syntax/TreeTest.cpp b/clang/unittests/Tooling/Syntax/TreeTest.cpp
index 634f99f..e81e3c2 100644
--- a/clang/unittests/Tooling/Syntax/TreeTest.cpp
+++ b/clang/unittests/Tooling/Syntax/TreeTest.cpp
@@ -594,6 +594,161 @@ void test() {
)txt");
}
+TEST_F(SyntaxTreeTest, PostfixUnaryOperator) {
+ expectTreeDumpEqual(
+ R"cpp(
+void test(int a) {
+ a++;
+ a--;
+}
+ )cpp",
+ R"txt(
+*: TranslationUnit
+`-SimpleDeclaration
+ |-void
+ |-SimpleDeclarator
+ | |-test
+ | `-ParametersAndQualifiers
+ | |-(
+ | |-SimpleDeclaration
+ | | |-int
+ | | `-SimpleDeclarator
+ | | `-a
+ | `-)
+ `-CompoundStatement
+ |-{
+ |-ExpressionStatement
+ | |-PostfixUnaryOperatorExpression
+ | | |-UnknownExpression
+ | | | `-a
+ | | `-++
+ | `-;
+ |-ExpressionStatement
+ | |-PostfixUnaryOperatorExpression
+ | | |-UnknownExpression
+ | | | `-a
+ | | `---
+ | `-;
+ `-}
+)txt");
+}
+
+TEST_F(SyntaxTreeTest, PrefixUnaryOperator) {
+ expectTreeDumpEqual(
+ R"cpp(
+void test(int a, int *ap, bool b) {
+ --a; ++a;
+ ~a; compl a;
+ -a;
+ +a;
+ &a;
+ *ap;
+ !b; not b;
+ __real a; __imag a;
+}
+ )cpp",
+ R"txt(
+*: TranslationUnit
+`-SimpleDeclaration
+ |-void
+ |-SimpleDeclarator
+ | |-test
+ | `-ParametersAndQualifiers
+ | |-(
+ | |-SimpleDeclaration
+ | | |-int
+ | | `-SimpleDeclarator
+ | | `-a
+ | |-,
+ | |-SimpleDeclaration
+ | | |-int
+ | | `-SimpleDeclarator
+ | | |-*
+ | | `-ap
+ | |-,
+ | |-SimpleDeclaration
+ | | |-bool
+ | | `-SimpleDeclarator
+ | | `-b
+ | `-)
+ `-CompoundStatement
+ |-{
+ |-ExpressionStatement
+ | |-PrefixUnaryOperatorExpression
+ | | |---
+ | | `-UnknownExpression
+ | | `-a
+ | `-;
+ |-ExpressionStatement
+ | |-PrefixUnaryOperatorExpression
+ | | |-++
+ | | `-UnknownExpression
+ | | `-a
+ | `-;
+ |-ExpressionStatement
+ | |-PrefixUnaryOperatorExpression
+ | | |-~
+ | | `-UnknownExpression
+ | | `-a
+ | `-;
+ |-ExpressionStatement
+ | |-PrefixUnaryOperatorExpression
+ | | |-compl
+ | | `-UnknownExpression
+ | | `-a
+ | `-;
+ |-ExpressionStatement
+ | |-PrefixUnaryOperatorExpression
+ | | |--
+ | | `-UnknownExpression
+ | | `-a
+ | `-;
+ |-ExpressionStatement
+ | |-PrefixUnaryOperatorExpression
+ | | |-+
+ | | `-UnknownExpression
+ | | `-a
+ | `-;
+ |-ExpressionStatement
+ | |-PrefixUnaryOperatorExpression
+ | | |-&
+ | | `-UnknownExpression
+ | | `-a
+ | `-;
+ |-ExpressionStatement
+ | |-PrefixUnaryOperatorExpression
+ | | |-*
+ | | `-UnknownExpression
+ | | `-ap
+ | `-;
+ |-ExpressionStatement
+ | |-PrefixUnaryOperatorExpression
+ | | |-!
+ | | `-UnknownExpression
+ | | `-b
+ | `-;
+ |-ExpressionStatement
+ | |-PrefixUnaryOperatorExpression
+ | | |-not
+ | | `-UnknownExpression
+ | | `-b
+ | `-;
+ |-ExpressionStatement
+ | |-PrefixUnaryOperatorExpression
+ | | |-__real
+ | | `-UnknownExpression
+ | | `-a
+ | `-;
+ |-ExpressionStatement
+ | |-PrefixUnaryOperatorExpression
+ | | |-__imag
+ | | `-UnknownExpression
+ | | `-a
+ | `-;
+ `-}
+)txt");
+}
+
TEST_F(SyntaxTreeTest, BinaryOperator) {
expectTreeDumpEqual(
R"cpp(
@@ -1866,7 +2021,7 @@ const int const *const *volatile b;
| |-SimpleDeclarator
| | |-west
| | |-=
-| | `-UnknownExpression
+| | `-PrefixUnaryOperatorExpression
| | |--
| | `-UnknownExpression
| | `-1