diff options
Diffstat (limited to 'clang/lib/Tooling/Syntax/Mutations.cpp')
| -rw-r--r-- | clang/lib/Tooling/Syntax/Mutations.cpp | 24 |
1 files changed, 19 insertions, 5 deletions
diff --git a/clang/lib/Tooling/Syntax/Mutations.cpp b/clang/lib/Tooling/Syntax/Mutations.cpp index 7278aff5f18..72458528202 100644 --- a/clang/lib/Tooling/Syntax/Mutations.cpp +++ b/clang/lib/Tooling/Syntax/Mutations.cpp @@ -29,30 +29,43 @@ class syntax::MutationsImpl { public: /// Add a new node with a specified role. static void addAfter(syntax::Node *Anchor, syntax::Node *New, NodeRole Role) { + assert(Anchor != nullptr); assert(New->Parent == nullptr); assert(New->NextSibling == nullptr); assert(!New->isDetached()); assert(Role != NodeRole::Detached); New->Role = static_cast<unsigned>(Role); - Anchor->parent()->replaceChildRangeLowLevel(Anchor, Anchor, New); + auto *P = Anchor->parent(); + P->replaceChildRangeLowLevel(Anchor, Anchor, New); + + P->assertInvariants(); } /// Replace the node, keeping the role. static void replace(syntax::Node *Old, syntax::Node *New) { + assert(Old != nullptr); + assert(Old->Parent != nullptr); + assert(Old->canModify()); assert(New->Parent == nullptr); assert(New->NextSibling == nullptr); assert(New->isDetached()); New->Role = Old->Role; - Old->parent()->replaceChildRangeLowLevel(findPrevious(Old), - Old->nextSibling(), New); + auto *P = Old->parent(); + P->replaceChildRangeLowLevel(findPrevious(Old), Old->nextSibling(), New); + + P->assertInvariants(); } /// Completely remove the node from its parent. static void remove(syntax::Node *N) { - N->parent()->replaceChildRangeLowLevel(findPrevious(N), N->nextSibling(), - /*New=*/nullptr); + auto *P = N->parent(); + P->replaceChildRangeLowLevel(findPrevious(N), N->nextSibling(), + /*New=*/nullptr); + + P->assertInvariants(); + N->assertInvariants(); } private: @@ -69,6 +82,7 @@ private: }; void syntax::removeStatement(syntax::Arena &A, syntax::Statement *S) { + assert(S); assert(S->canModify()); if (isa<CompoundStatement>(S->parent())) { |

