[clang] 466e8b7 - Add StringLiteral to SyntaxTree
Yung, Douglas via cfe-commits
cfe-commits at lists.llvm.org
Thu Jun 25 18:23:37 PDT 2020
Hi Eduardo,
Your change is causing a build failure on PS4 Windows build bot, can you please take a look and fix it or revert the change if you cannot fix it soon so we can get the bot green again?
http://lab.llvm.org:8011/builders/llvm-clang-lld-x86_64-scei-ps4-windows10pro-fast/builds/33164
FAILED: tools/clang/unittests/Tooling/Syntax/CMakeFiles/SyntaxTests.dir/TreeTest.cpp.obj
C:\PROGRA~2\MIB055~1\2019\COMMUN~1\VC\Tools\MSVC\1425~1.286\bin\Hostx64\x64\cl.exe /nologo /TP -DBUILD_EXAMPLES -DGTEST_HAS_RTTI=0 -DGTEST_HAS_TR1_TUPLE=0 -DGTEST_LANG_CXX11=1 -DUNICODE -D_CRT_NONSTDC_NO_DEPRECATE -D_CRT_NONSTDC_NO_WARNINGS -D_CRT_SECURE_NO_DEPRECATE -D_CRT_SECURE_NO_WARNINGS -D_GNU_SOURCE -D_HAS_EXCEPTIONS=0 -D_SCL_SECURE_NO_DEPRECATE -D_SCL_SECURE_NO_WARNINGS -D_UNICODE -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -Itools\clang\unittests\Tooling\Syntax -IC:\ps4-buildslave2\llvm-clang-lld-x86_64-scei-ps4-windows10pro-fast\llvm-project\clang\unittests\Tooling\Syntax -IC:\ps4-buildslave2\llvm-clang-lld-x86_64-scei-ps4-windows10pro-fast\llvm-project\clang\include -Itools\clang\include -Iinclude -IC:\ps4-buildslave2\llvm-clang-lld-x86_64-scei-ps4-windows10pro-fast\llvm-project\llvm\include -IC:\ps4-buildslave2\llvm-clang-lld-x86_64-scei-ps4-windows10pro-fast\llvm-project\llvm\utils\unittest\googletest\include -IC:\ps4-buildslave2\llvm-clang-lld-x86_64-scei-ps4-windows10pro-fast\llvm-project\llvm\utils\unittest\googlemock\include /DWIN32 /D_WINDOWS /Zc:inline /Zc:strictStrings /Oi /Zc:rvalueCast /W4 -wd4141 -wd4146 -wd4244 -wd4267 -wd4291 -wd4351 -wd4456 -wd4457 -wd4458 -wd4459 -wd4503 -wd4624 -wd4722 -wd4100 -wd4127 -wd4512 -wd4505 -wd4610 -wd4510 -wd4702 -wd4245 -wd4706 -wd4310 -wd4701 -wd4703 -wd4389 -wd4611 -wd4805 -wd4204 -wd4577 -wd4091 -wd4592 -wd4319 -wd4709 -wd4324 -w14062 -we4238 /Gw /MD /O2 /Ob2 /EHs-c- /GR- -UNDEBUG -std:c++14 /showIncludes /Fotools\clang\unittests\Tooling\Syntax\CMakeFiles\SyntaxTests.dir\TreeTest.cpp.obj /Fdtools\clang\unittests\Tooling\Syntax\CMakeFiles\SyntaxTests.dir\ /FS -c C:\ps4-buildslave2\llvm-clang-lld-x86_64-scei-ps4-windows10pro-fast\llvm-project\clang\unittests\Tooling\Syntax\TreeTest.cpp
C:\ps4-buildslave2\llvm-clang-lld-x86_64-scei-ps4-windows10pro-fast\llvm-project\clang\unittests\Tooling\Syntax\TreeTest.cpp(1665): error C2017: illegal escape sequence
C:\ps4-buildslave2\llvm-clang-lld-x86_64-scei-ps4-windows10pro-fast\llvm-project\clang\unittests\Tooling\Syntax\TreeTest.cpp(1639): error C2146: syntax error: missing ')' before identifier 'n'
C:\ps4-buildslave2\llvm-clang-lld-x86_64-scei-ps4-windows10pro-fast\llvm-project\clang\unittests\Tooling\Syntax\TreeTest.cpp(1639): error C2660: 'testing::internal::GetBoolAssertionFailureMessage': function does not take 2 arguments
C:\ps4-buildslave2\llvm-clang-lld-x86_64-scei-ps4-windows10pro-fast\llvm-project\llvm\utils\unittest\googletest\include\gtest/internal/gtest-internal.h(226): note: see declaration of 'testing::internal::GetBoolAssertionFailureMessage'
C:\ps4-buildslave2\llvm-clang-lld-x86_64-scei-ps4-windows10pro-fast\llvm-project\clang\unittests\Tooling\Syntax\TreeTest.cpp(1639): error C2440: '<function-style-cast>': cannot convert from 'initializer list' to 'testing::internal::AssertHelper'
C:\ps4-buildslave2\llvm-clang-lld-x86_64-scei-ps4-windows10pro-fast\llvm-project\clang\unittests\Tooling\Syntax\TreeTest.cpp(1665): note: No constructor could take the source type, or constructor overload resolution was ambiguous
C:\ps4-buildslave2\llvm-clang-lld-x86_64-scei-ps4-windows10pro-fast\llvm-project\clang\unittests\Tooling\Syntax\TreeTest.cpp(1639): error C2064: term does not evaluate to a function taking 3 arguments
C:\ps4-buildslave2\llvm-clang-lld-x86_64-scei-ps4-windows10pro-fast\llvm-project\clang\unittests\Tooling\Syntax\TreeTest.cpp(1639): error C2146: syntax error: missing ';' before identifier 'n'
C:\ps4-buildslave2\llvm-clang-lld-x86_64-scei-ps4-windows10pro-fast\llvm-project\clang\unittests\Tooling\Syntax\TreeTest.cpp(1665): error C2059: syntax error: ')'
C:\ps4-buildslave2\llvm-clang-lld-x86_64-scei-ps4-windows10pro-fast\llvm-project\clang\unittests\Tooling\Syntax\TreeTest.cpp(1639): error C2065: 'n': undeclared identifier
C:\ps4-buildslave2\llvm-clang-lld-x86_64-scei-ps4-windows10pro-fast\llvm-project\clang\unittests\Tooling\Syntax\TreeTest.cpp(1639): error C2146: syntax error: missing ';' before identifier 'SyntaxTree'
C:\ps4-buildslave2\llvm-clang-lld-x86_64-scei-ps4-windows10pro-fast\llvm-project\clang\unittests\Tooling\Syntax\TreeTest.cpp(1639): error C2065: 'SyntaxTree': undeclared identifier
C:\ps4-buildslave2\llvm-clang-lld-x86_64-scei-ps4-windows10pro-fast\llvm-project\clang\unittests\Tooling\Syntax\TreeTest.cpp(1639): error C2143: syntax error: missing ';' before 'string'
Douglas Yung
-----Original Message-----
From: cfe-commits <cfe-commits-bounces at lists.llvm.org> On Behalf Of Eduardo Caldas via cfe-commits
Sent: Thursday, June 25, 2020 10:05
To: cfe-commits at lists.llvm.org
Subject: [clang] 466e8b7 - Add StringLiteral to SyntaxTree
Author: Eduardo Caldas
Date: 2020-06-25T17:05:08Z
New Revision: 466e8b7ea6e162d48cac42ccda210bdeb11080e3
URL: https://github.com/llvm/llvm-project/commit/466e8b7ea6e162d48cac42ccda210bdeb11080e3
DIFF: https://github.com/llvm/llvm-project/commit/466e8b7ea6e162d48cac42ccda210bdeb11080e3.diff
LOG: Add StringLiteral to SyntaxTree
Subscribers: cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D82360
Added:
Modified:
clang/include/clang/Tooling/Syntax/Nodes.h
clang/lib/Tooling/Syntax/BuildTree.cpp
clang/lib/Tooling/Syntax/Nodes.cpp
clang/unittests/Tooling/Syntax/TreeTest.cpp
Removed:
################################################################################
diff --git a/clang/include/clang/Tooling/Syntax/Nodes.h b/clang/include/clang/Tooling/Syntax/Nodes.h
index 4310bc5dc81c..e50e80ec1fc3 100644
--- a/clang/include/clang/Tooling/Syntax/Nodes.h
+++ b/clang/include/clang/Tooling/Syntax/Nodes.h
@@ -47,6 +47,7 @@ enum class NodeKind : uint16_t {
IntegerLiteralExpression,
BoolLiteralExpression,
CharacterLiteralExpression,
+ StringLiteralExpression,
IdExpression,
// Statements.
@@ -287,6 +288,16 @@ class BoolLiteralExpression final : public Expression {
syntax::Leaf *literalToken();
};
+/// Expression for string-literals. C++ [lex.string] class
+StringLiteralExpression final : public Expression {
+public:
+ StringLiteralExpression() :
+Expression(NodeKind::StringLiteralExpression) {}
+ static bool classof(const Node *N) {
+ return N->kind() == NodeKind::StringLiteralExpression;
+ }
+ syntax::Leaf *literalToken();
+};
+
/// An abstract class for prefix and postfix unary operators.
class UnaryOperatorExpression : public Expression {
public:
diff --git a/clang/lib/Tooling/Syntax/BuildTree.cpp b/clang/lib/Tooling/Syntax/BuildTree.cpp
index 5912a54d1bee..bd2f372e057b 100644
--- a/clang/lib/Tooling/Syntax/BuildTree.cpp
+++ b/clang/lib/Tooling/Syntax/BuildTree.cpp
@@ -667,6 +667,12 @@ class BuildTreeVisitor : public RecursiveASTVisitor<BuildTreeVisitor> {
new (allocator()) syntax::CharacterLiteralExpression, S);
return true;
}
+ bool WalkUpFromStringLiteral(StringLiteral *S) {
+ Builder.markChildToken(S->getBeginLoc(), syntax::NodeRole::LiteralToken);
+ Builder.foldNode(Builder.getExprRange(S),
+ new (allocator()) syntax::StringLiteralExpression, S);
+ return true;
+ }
bool WalkUpFromCXXNullPtrLiteralExpr(CXXNullPtrLiteralExpr *S) {
Builder.markChildToken(S->getLocation(), syntax::NodeRole::LiteralToken);
diff --git a/clang/lib/Tooling/Syntax/Nodes.cpp b/clang/lib/Tooling/Syntax/Nodes.cpp
index e6e280e9cb13..290b1e6bafa1 100644
--- a/clang/lib/Tooling/Syntax/Nodes.cpp
+++ b/clang/lib/Tooling/Syntax/Nodes.cpp
@@ -26,6 +26,8 @@ llvm::raw_ostream &syntax::operator<<(llvm::raw_ostream &OS, NodeKind K) {
return OS << "BoolLiteralExpression";
case NodeKind::CharacterLiteralExpression:
return OS << "CharacterLiteralExpression";
+ case NodeKind::StringLiteralExpression:
+ return OS << "StringLiteralExpression";
case NodeKind::PrefixUnaryOperatorExpression:
return OS << "PrefixUnaryOperatorExpression";
case NodeKind::PostfixUnaryOperatorExpression:
@@ -214,6 +216,11 @@ syntax::Leaf *syntax::CharacterLiteralExpression::literalToken() {
findChild(syntax::NodeRole::LiteralToken));
}
+syntax::Leaf *syntax::StringLiteralExpression::literalToken() {
+ return llvm::cast_or_null<syntax::Leaf>(
+ findChild(syntax::NodeRole::LiteralToken));
+}
+
syntax::Leaf *syntax::CxxNullPtrExpression::nullPtrKeyword() {
return llvm::cast_or_null<syntax::Leaf>(
findChild(syntax::NodeRole::LiteralToken));
diff --git a/clang/unittests/Tooling/Syntax/TreeTest.cpp b/clang/unittests/Tooling/Syntax/TreeTest.cpp
index 0a20950458d6..bc2a65b2dd07 100644
--- a/clang/unittests/Tooling/Syntax/TreeTest.cpp
+++ b/clang/unittests/Tooling/Syntax/TreeTest.cpp
@@ -1399,6 +1399,109 @@ void test() {
)txt"));
}
+TEST_P(SyntaxTreeTest, StringLiteral) {
+ EXPECT_TRUE(treeDumpEqual(
+ R"cpp(
+void test() {
+ "a\n\0\x20";
+ L"αβ";
+}
+)cpp",
+ R"txt(
+*: TranslationUnit
+`-SimpleDeclaration
+ |-void
+ |-SimpleDeclarator
+ | |-test
+ | `-ParametersAndQualifiers
+ | |-(
+ | `-)
+ `-CompoundStatement
+ |-{
+ |-ExpressionStatement
+ | |-StringLiteralExpression
+ | | `-"a\n\0\x20"
+ | `-;
+ |-ExpressionStatement
+ | |-StringLiteralExpression
+ | | `-L"αβ"
+ | `-;
+ `-}
+)txt"));
+}
+
+TEST_P(SyntaxTreeTest, StringLiteralUtf) {
+ if (!GetParam().isCXX11OrLater()) {
+ return;
+ }
+ EXPECT_TRUE(treeDumpEqual(
+ R"cpp(
+void test() {
+ u8"a\x1f\x05";
+ u"C++抽象構文木";
+ U"📖🌲\n";
+}
+)cpp",
+ R"txt(
+*: TranslationUnit
+`-SimpleDeclaration
+ |-void
+ |-SimpleDeclarator
+ | |-test
+ | `-ParametersAndQualifiers
+ | |-(
+ | `-)
+ `-CompoundStatement
+ |-{
+ |-ExpressionStatement
+ | |-StringLiteralExpression
+ | | `-u8"a\x1f\x05"
+ | `-;
+ |-ExpressionStatement
+ | |-StringLiteralExpression
+ | | `-u"C++抽象構文木"
+ | `-;
+ |-ExpressionStatement
+ | |-StringLiteralExpression
+ | | `-U"📖🌲\n"
+ | `-;
+ `-}
+)txt"));
+}
+
+TEST_P(SyntaxTreeTest, StringLiteralRaw) {
+ if (!GetParam().isCXX11OrLater()) {
+ return;
+ }
+ EXPECT_TRUE(treeDumpEqual(
+ R"cpp(
+void test() {
+ R"SyntaxTree(
+ Hello "Syntax" \"
+ )SyntaxTree";
+}
+)cpp",
+ R"txt(
+*: TranslationUnit
+`-SimpleDeclaration
+ |-void
+ |-SimpleDeclarator
+ | |-test
+ | `-ParametersAndQualifiers
+ | |-(
+ | `-)
+ `-CompoundStatement
+ |-{
+ |-ExpressionStatement
+ | |-StringLiteralExpression
+ | | `-R"SyntaxTree(
+ Hello "Syntax" \"
+ )SyntaxTree"
+ | `-;
+ `-}
+)txt"));
+}
+
TEST_P(SyntaxTreeTest, IntegerLiteral) {
EXPECT_TRUE(treeDumpEqual(
R"cpp(
@@ -2730,7 +2833,7 @@ static_assert(true); | |-BoolLiteralExpression | | `-true | |-,
-| |-UnknownExpression
+| |-StringLiteralExpression
| | `-"message"
| |-)
| `-;
_______________________________________________
cfe-commits mailing list
cfe-commits at lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
More information about the cfe-commits
mailing list