[SyntaxTree] Add reverse links to syntax Nodes.
authorEduardo Caldas <ecaldas@google.com>
Tue, 27 Oct 2020 15:14:03 +0000 (15:14 +0000)
committerEduardo Caldas <ecaldas@google.com>
Thu, 5 Nov 2020 09:33:53 +0000 (09:33 +0000)
commit23657d9cc33282208bdac074abccd73bd4d4f8be
treeeee8b552048a918e74c7e3fec6569d9a06d8ddeb
parentb715fa330dfaa379885c5184340c410a63be5987
[SyntaxTree] Add reverse links to syntax Nodes.

Rationale:
Children of a syntax tree had forward links only, because there was no
need for reverse links.

This need appeared when we started mutating the syntax tree.
On a forward list, to remove a target node in O(1) we need a pointer to the node before the target. If we don't have this "before" pointer, we have to find it, and that requires O(n).
So in order to remove a syntax node from a tree, we would similarly need to find the node before to then remove. This is both not ergonomic nor does it have a good complexity.

Differential Revision: https://reviews.llvm.org/D90240
clang/include/clang/Tooling/Syntax/Tree.h
clang/lib/Tooling/Syntax/BuildTree.cpp
clang/lib/Tooling/Syntax/Mutations.cpp
clang/lib/Tooling/Syntax/Synthesis.cpp
clang/lib/Tooling/Syntax/Tree.cpp