summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorIlya Biryukov <ibiryukov@google.com>2020-01-14 16:27:06 +0100
committerIlya Biryukov <ibiryukov@google.com>2020-01-14 16:41:09 +0100
commit07a41018e9d27f67f7b4295eb7e00e0345c0aacf (patch)
tree04639b8d6f393da8f548a908e8f56a7c22af5025
parent3b929fe7763570fc1d4a4691a53257a4a0b7760e (diff)
downloadbcm5719-llvm-07a41018e9d27f67f7b4295eb7e00e0345c0aacf.tar.gz
bcm5719-llvm-07a41018e9d27f67f7b4295eb7e00e0345c0aacf.zip
[Syntax] Mark synthesized nodes as modifiable
This was an oversight in the original patch. Also add corresponding tests.
-rw-r--r--clang/include/clang/Tooling/Syntax/Tree.h2
-rw-r--r--clang/lib/Tooling/Syntax/Synthesis.cpp4
-rw-r--r--clang/unittests/Tooling/Syntax/TreeTest.cpp18
3 files changed, 24 insertions, 0 deletions
diff --git a/clang/include/clang/Tooling/Syntax/Tree.h b/clang/include/clang/Tooling/Syntax/Tree.h
index 640697a25f3..8702fe60ce1 100644
--- a/clang/include/clang/Tooling/Syntax/Tree.h
+++ b/clang/include/clang/Tooling/Syntax/Tree.h
@@ -123,6 +123,8 @@ private:
friend class TreeBuilder;
// MutationsImpl sets roles and CanModify flag.
friend class MutationsImpl;
+ // FactoryImpl sets CanModify flag.
+ friend class FactoryImpl;
Tree *Parent;
Node *NextSibling;
diff --git a/clang/lib/Tooling/Syntax/Synthesis.cpp b/clang/lib/Tooling/Syntax/Synthesis.cpp
index cbd9579f4f0..aa01a34c761 100644
--- a/clang/lib/Tooling/Syntax/Synthesis.cpp
+++ b/clang/lib/Tooling/Syntax/Synthesis.cpp
@@ -13,6 +13,8 @@ using namespace clang;
/// Should not be used for anything else.
class syntax::FactoryImpl {
public:
+ static void setCanModify(syntax::Node *N) { N->CanModify = true; }
+
static void prependChildLowLevel(syntax::Tree *T, syntax::Node *Child,
syntax::NodeRole R) {
T->prependChildLowLevel(Child, R);
@@ -27,6 +29,7 @@ clang::syntax::Leaf *syntax::createPunctuation(clang::syntax::Arena &A,
assert(Tokens.size() == 1);
assert(Tokens.front().kind() == K);
auto *L = new (A.allocator()) clang::syntax::Leaf(Tokens.begin());
+ FactoryImpl::setCanModify(L);
L->assertInvariants();
return L;
}
@@ -34,6 +37,7 @@ clang::syntax::Leaf *syntax::createPunctuation(clang::syntax::Arena &A,
clang::syntax::EmptyStatement *
syntax::createEmptyStatement(clang::syntax::Arena &A) {
auto *S = new (A.allocator()) clang::syntax::EmptyStatement;
+ FactoryImpl::setCanModify(S);
FactoryImpl::prependChildLowLevel(S, createPunctuation(A, clang::tok::semi),
NodeRole::Unknown);
S->assertInvariants();
diff --git a/clang/unittests/Tooling/Syntax/TreeTest.cpp b/clang/unittests/Tooling/Syntax/TreeTest.cpp
index b54d06319e8..c457c788812 100644
--- a/clang/unittests/Tooling/Syntax/TreeTest.cpp
+++ b/clang/unittests/Tooling/Syntax/TreeTest.cpp
@@ -11,6 +11,7 @@
#include "clang/AST/Decl.h"
#include "clang/AST/Stmt.h"
#include "clang/Basic/LLVM.h"
+#include "clang/Basic/TokenKinds.h"
#include "clang/Frontend/CompilerInstance.h"
#include "clang/Frontend/CompilerInvocation.h"
#include "clang/Frontend/FrontendAction.h"
@@ -906,4 +907,21 @@ TEST_F(SyntaxTreeTest, Mutations) {
CheckTransformation(C.first, C.second, RemoveStatement);
}
+TEST_F(SyntaxTreeTest, SynthesizedNodes) {
+ buildTree("");
+
+ auto *C = syntax::createPunctuation(*Arena, tok::comma);
+ ASSERT_NE(C, nullptr);
+ EXPECT_EQ(C->token()->kind(), tok::comma);
+ EXPECT_TRUE(C->canModify());
+ EXPECT_FALSE(C->isOriginal());
+ EXPECT_TRUE(C->isDetached());
+
+ auto *S = syntax::createEmptyStatement(*Arena);
+ ASSERT_NE(S, nullptr);
+ EXPECT_TRUE(S->canModify());
+ EXPECT_FALSE(S->isOriginal());
+ EXPECT_TRUE(S->isDetached());
+}
+
} // namespace
OpenPOWER on IntegriCloud