aboutsummaryrefslogtreecommitdiff
path: root/clang/unittests/Tooling/Syntax/TreeTest.cpp
diff options
context:
space:
mode:
authorEduardo Caldas <ecaldas@google.com>2020-06-22 17:35:38 +0000
committerEduardo Caldas <ecaldas@google.com>2020-06-25 17:05:08 +0000
commit7b404b6d003181e990f53d27866ee98d5151c4f3 (patch)
treec3c336a0350cfb690f849d163831100d165902ab /clang/unittests/Tooling/Syntax/TreeTest.cpp
parent466e8b7ea6e162d48cac42ccda210bdeb11080e3 (diff)
downloadllvm-7b404b6d003181e990f53d27866ee98d5151c4f3.zip
llvm-7b404b6d003181e990f53d27866ee98d5151c4f3.tar.gz
llvm-7b404b6d003181e990f53d27866ee98d5151c4f3.tar.bz2
Add `FloatingLiteral` to SyntaxTree
Subscribers: cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D82318
Diffstat (limited to 'clang/unittests/Tooling/Syntax/TreeTest.cpp')
-rw-r--r--clang/unittests/Tooling/Syntax/TreeTest.cpp301
1 files changed, 192 insertions, 109 deletions
diff --git a/clang/unittests/Tooling/Syntax/TreeTest.cpp b/clang/unittests/Tooling/Syntax/TreeTest.cpp
index bc2a65b..5dd6cc7 100644
--- a/clang/unittests/Tooling/Syntax/TreeTest.cpp
+++ b/clang/unittests/Tooling/Syntax/TreeTest.cpp
@@ -53,6 +53,8 @@ struct TestClangConfig {
bool isC99OrLater() const { return Language == Lang_C99; }
+ bool isC() const { return Language == Lang_C89 || Language == Lang_C99; }
+
bool isCXX() const {
return Language == Lang_CXX03 || Language == Lang_CXX11 ||
Language == Lang_CXX14 || Language == Lang_CXX17 ||
@@ -69,10 +71,6 @@ struct TestClangConfig {
Language == Lang_CXX20;
}
- bool hasBoolType() const {
- return Language == Lang_C89 || Language == Lang_C99;
- }
-
bool isCXX17OrLater() const {
return Language == Lang_CXX17 || Language == Lang_CXX20;
}
@@ -1207,14 +1205,66 @@ void test(S s) {
)txt"));
}
-TEST_P(SyntaxTreeTest, CxxNullPtrLiteral) {
+TEST_P(SyntaxTreeTest, IntegerLiteral) {
+ EXPECT_TRUE(treeDumpEqual(
+ R"cpp(
+void test() {
+ 12;
+ 12u;
+ 12l;
+ 12ul;
+ 014;
+ 0XC;
+}
+)cpp",
+ R"txt(
+*: TranslationUnit
+`-SimpleDeclaration
+ |-void
+ |-SimpleDeclarator
+ | |-test
+ | `-ParametersAndQualifiers
+ | |-(
+ | `-)
+ `-CompoundStatement
+ |-{
+ |-ExpressionStatement
+ | |-IntegerLiteralExpression
+ | | `-12
+ | `-;
+ |-ExpressionStatement
+ | |-IntegerLiteralExpression
+ | | `-12u
+ | `-;
+ |-ExpressionStatement
+ | |-IntegerLiteralExpression
+ | | `-12l
+ | `-;
+ |-ExpressionStatement
+ | |-IntegerLiteralExpression
+ | | `-12ul
+ | `-;
+ |-ExpressionStatement
+ | |-IntegerLiteralExpression
+ | | `-014
+ | `-;
+ |-ExpressionStatement
+ | |-IntegerLiteralExpression
+ | | `-0XC
+ | `-;
+ `-}
+)txt"));
+}
+
+TEST_P(SyntaxTreeTest, IntegerLiteralLongLong) {
if (!GetParam().isCXX11OrLater()) {
return;
}
EXPECT_TRUE(treeDumpEqual(
R"cpp(
void test() {
- nullptr;
+ 12ll;
+ 12ull;
}
)cpp",
R"txt(
@@ -1229,8 +1279,70 @@ void test() {
`-CompoundStatement
|-{
|-ExpressionStatement
- | |-CxxNullPtrExpression
- | | `-nullptr
+ | |-IntegerLiteralExpression
+ | | `-12ll
+ | `-;
+ |-ExpressionStatement
+ | |-IntegerLiteralExpression
+ | | `-12ull
+ | `-;
+ `-}
+)txt"));
+}
+
+TEST_P(SyntaxTreeTest, IntegerLiteralBinary) {
+ if (!GetParam().isCXX14OrLater()) {
+ return;
+ }
+ EXPECT_TRUE(treeDumpEqual(
+ R"cpp(
+void test() {
+ 0b1100;
+}
+)cpp",
+ R"txt(
+*: TranslationUnit
+`-SimpleDeclaration
+ |-void
+ |-SimpleDeclarator
+ | |-test
+ | `-ParametersAndQualifiers
+ | |-(
+ | `-)
+ `-CompoundStatement
+ |-{
+ |-ExpressionStatement
+ | |-IntegerLiteralExpression
+ | | `-0b1100
+ | `-;
+ `-}
+)txt"));
+}
+
+TEST_P(SyntaxTreeTest, IntegerLiteralWithDigitSeparators) {
+ if (!GetParam().isCXX14OrLater()) {
+ return;
+ }
+ EXPECT_TRUE(treeDumpEqual(
+ R"cpp(
+void test() {
+ 1'2'0ull;
+}
+)cpp",
+ R"txt(
+*: TranslationUnit
+`-SimpleDeclaration
+ |-void
+ |-SimpleDeclarator
+ | |-test
+ | `-ParametersAndQualifiers
+ | |-(
+ | `-)
+ `-CompoundStatement
+ |-{
+ |-ExpressionStatement
+ | |-IntegerLiteralExpression
+ | | `-1'2'0ull
| `-;
`-}
)txt"));
@@ -1365,15 +1477,58 @@ void test() {
)txt"));
}
-TEST_P(SyntaxTreeTest, BoolLiteral) {
- if (GetParam().hasBoolType()) {
+TEST_P(SyntaxTreeTest, FloatingLiteral) {
+ EXPECT_TRUE(treeDumpEqual(
+ 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"));
+}
+
+TEST_P(SyntaxTreeTest, FloatingLiteralHexadecimal) {
+ if (!GetParam().isCXX17OrLater()) {
return;
}
EXPECT_TRUE(treeDumpEqual(
R"cpp(
void test() {
- true;
- false;
+ 0xfp1;
+ 0xf.p1;
+ 0x.fp1;
+ 0xf.fp1f;
}
)cpp",
R"txt(
@@ -1388,12 +1543,20 @@ void test() {
`-CompoundStatement
|-{
|-ExpressionStatement
- | |-BoolLiteralExpression
- | | `-true
+ | |-FloatingLiteralExpression
+ | | `-0xfp1
| `-;
|-ExpressionStatement
- | |-BoolLiteralExpression
- | | `-false
+ | |-FloatingLiteralExpression
+ | | `-0xf.p1
+ | `-;
+ |-ExpressionStatement
+ | |-FloatingLiteralExpression
+ | | `-0x.fp1
+ | `-;
+ |-ExpressionStatement
+ | |-FloatingLiteralExpression
+ | | `-0xf.fp1f
| `-;
`-}
)txt"));
@@ -1502,66 +1665,15 @@ void test() {
)txt"));
}
-TEST_P(SyntaxTreeTest, IntegerLiteral) {
- EXPECT_TRUE(treeDumpEqual(
- R"cpp(
-void test() {
- 12;
- 12u;
- 12l;
- 12ul;
- 014;
- 0XC;
-}
-)cpp",
- R"txt(
-*: TranslationUnit
-`-SimpleDeclaration
- |-void
- |-SimpleDeclarator
- | |-test
- | `-ParametersAndQualifiers
- | |-(
- | `-)
- `-CompoundStatement
- |-{
- |-ExpressionStatement
- | |-IntegerLiteralExpression
- | | `-12
- | `-;
- |-ExpressionStatement
- | |-IntegerLiteralExpression
- | | `-12u
- | `-;
- |-ExpressionStatement
- | |-IntegerLiteralExpression
- | | `-12l
- | `-;
- |-ExpressionStatement
- | |-IntegerLiteralExpression
- | | `-12ul
- | `-;
- |-ExpressionStatement
- | |-IntegerLiteralExpression
- | | `-014
- | `-;
- |-ExpressionStatement
- | |-IntegerLiteralExpression
- | | `-0XC
- | `-;
- `-}
-)txt"));
-}
-
-TEST_P(SyntaxTreeTest, IntegerLiteralLongLong) {
- if (!GetParam().isCXX11OrLater()) {
+TEST_P(SyntaxTreeTest, BoolLiteral) {
+ if (GetParam().isC()) {
return;
}
EXPECT_TRUE(treeDumpEqual(
R"cpp(
void test() {
- 12ll;
- 12ull;
+ true;
+ false;
}
)cpp",
R"txt(
@@ -1576,54 +1688,25 @@ void test() {
`-CompoundStatement
|-{
|-ExpressionStatement
- | |-IntegerLiteralExpression
- | | `-12ll
+ | |-BoolLiteralExpression
+ | | `-true
| `-;
|-ExpressionStatement
- | |-IntegerLiteralExpression
- | | `-12ull
- | `-;
- `-}
-)txt"));
-}
-
-TEST_P(SyntaxTreeTest, IntegerLiteralBinary) {
- if (!GetParam().isCXX14OrLater()) {
- return;
- }
- EXPECT_TRUE(treeDumpEqual(
- R"cpp(
-void test() {
- 0b1100;
-}
-)cpp",
- R"txt(
-*: TranslationUnit
-`-SimpleDeclaration
- |-void
- |-SimpleDeclarator
- | |-test
- | `-ParametersAndQualifiers
- | |-(
- | `-)
- `-CompoundStatement
- |-{
- |-ExpressionStatement
- | |-IntegerLiteralExpression
- | | `-0b1100
+ | |-BoolLiteralExpression
+ | | `-false
| `-;
`-}
)txt"));
}
-TEST_P(SyntaxTreeTest, IntegerLiteralWithDigitSeparators) {
- if (!GetParam().isCXX14OrLater()) {
+TEST_P(SyntaxTreeTest, CxxNullPtrLiteral) {
+ if (!GetParam().isCXX11OrLater()) {
return;
}
EXPECT_TRUE(treeDumpEqual(
R"cpp(
void test() {
- 1'2'0ull;
+ nullptr;
}
)cpp",
R"txt(
@@ -1638,8 +1721,8 @@ void test() {
`-CompoundStatement
|-{
|-ExpressionStatement
- | |-IntegerLiteralExpression
- | | `-1'2'0ull
+ | |-CxxNullPtrExpression
+ | | `-nullptr
| `-;
`-}
)txt"));