[PATCH] D89314: [SyntaxTree] Bug fix in `MutationsImpl::addAfter`.
Eduardo Caldas via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Wed Oct 14 02:26:15 PDT 2020
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG72732acade77: [SyntaxTree] Bug fix in `MutationsImpl::addAfter`. (authored by eduucaldas).
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D89314/new/
https://reviews.llvm.org/D89314
Files:
clang/lib/Tooling/Syntax/Mutations.cpp
Index: clang/lib/Tooling/Syntax/Mutations.cpp
===================================================================
--- clang/lib/Tooling/Syntax/Mutations.cpp
+++ clang/lib/Tooling/Syntax/Mutations.cpp
@@ -23,6 +23,19 @@
using namespace clang;
+static syntax::Node *findPrevious(syntax::Node *N) {
+ assert(N);
+ assert(N->getParent());
+ if (N->getParent()->getFirstChild() == N)
+ return nullptr;
+ for (syntax::Node *C = N->getParent()->getFirstChild(); C != nullptr;
+ C = C->getNextSibling()) {
+ if (C->getNextSibling() == N)
+ return C;
+ }
+ llvm_unreachable("could not find a child node");
+}
+
// This class has access to the internals of tree nodes. Its sole purpose is to
// define helpers that allow implementing the high-level mutation operations.
class syntax::MutationsImpl {
@@ -30,14 +43,15 @@
/// Add a new node with a specified role.
static void addAfter(syntax::Node *Anchor, syntax::Node *New, NodeRole Role) {
assert(Anchor != nullptr);
+ assert(Anchor->Parent != nullptr);
assert(New->Parent == nullptr);
assert(New->NextSibling == nullptr);
- assert(!New->isDetached());
+ assert(New->isDetached());
assert(Role != NodeRole::Detached);
New->setRole(Role);
auto *P = Anchor->getParent();
- P->replaceChildRangeLowLevel(Anchor, Anchor, New);
+ P->replaceChildRangeLowLevel(Anchor, Anchor->getNextSibling(), New);
P->assertInvariants();
}
@@ -60,6 +74,10 @@
/// Completely remove the node from its parent.
static void remove(syntax::Node *N) {
+ assert(N != nullptr);
+ assert(N->Parent != nullptr);
+ assert(N->canModify());
+
auto *P = N->getParent();
P->replaceChildRangeLowLevel(findPrevious(N), N->getNextSibling(),
/*New=*/nullptr);
@@ -67,18 +85,6 @@
P->assertInvariants();
N->assertInvariants();
}
-
-private:
- static syntax::Node *findPrevious(syntax::Node *N) {
- if (N->getParent()->getFirstChild() == N)
- return nullptr;
- for (syntax::Node *C = N->getParent()->getFirstChild(); C != nullptr;
- C = C->getNextSibling()) {
- if (C->getNextSibling() == N)
- return C;
- }
- llvm_unreachable("could not find a child node");
- }
};
void syntax::removeStatement(syntax::Arena &A, syntax::Statement *S) {
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D89314.298084.patch
Type: text/x-patch
Size: 2344 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20201014/112d3c9e/attachment-0001.bin>
More information about the cfe-commits
mailing list