[PATCH] D89147: [SyntaxTree] Improve the signature of `replaceChildRangeLowLevel`.

Eduardo Caldas via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Oct 9 10:09:29 PDT 2020


eduucaldas created this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.
eduucaldas requested review of this revision.

Previously `replaceChildRangeLowLevel` took the new child range as a
`Node* New`.  `New` was expected to have siblings attached already, and
thus it was interpreted as a range. Additionally, the role of `New` and
its siblings were expected to be set prior to calling the function.  As
a result the `New` argument broke the invariant `New->Parent == nullptr`
<=> `New->Role == Detached`, at call site.  We change the signature of
`replaceChildRangeLowLevel` to take instead an
`ArrayRef<std::pair<Node*, NodeRole>>`, and thus move the burden of
setting siblings and roles from the user to the member function.

Moreover, `replaceChildRangeLowLevel` returns now a vector of the
replaced range, following the "law of useful returns". Previously, in
order to reuse the replaced elements the user needed to get pointers to
those elements and before calling the function.

We also fixed some minor bugs in `addAfter`, and added more asserts to
the new `replaceChildRangeLowLevel`.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D89147

Files:
  clang/include/clang/Tooling/Syntax/Tree.h
  clang/lib/Tooling/Syntax/Mutations.cpp
  clang/lib/Tooling/Syntax/Tree.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D89147.297273.patch
Type: text/x-patch
Size: 7492 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20201009/8991fe09/attachment-0001.bin>


More information about the cfe-commits mailing list