[Syntax] Add iterators over children of syntax trees.
authorSam McCall <sam.mccall@gmail.com>
Fri, 23 Oct 2020 10:23:29 +0000 (12:23 +0200)
committerSam McCall <sam.mccall@gmail.com>
Wed, 28 Oct 2020 11:37:57 +0000 (12:37 +0100)
commitd4934eb5f876cdc97a9a8665bd654351fbbcb66b
tree5450cdc3a2ef9b1a18059e43e18ac6d679d52b0b
parentedfb2f8b235ff72f00375ae2424f7eb98da08234
[Syntax] Add iterators over children of syntax trees.

This gives us slightly nicer syntax (foreach) for idioms currently expressed
as a loop, and the option to use range algorithms where it makes sense
(e.g. llvm::all_of et al encapsulate the needed flow control in a useful way).

It's also a building block for iteration over filtered views (e.g. iterate over
all Stmt children, with the right type):
for (const Statement &S : filter<Statement>(N.children()))
  ...

I realize the recent direction has been mostly towards strongly-typed
node-specific facilities, but I think it's important we have convenient
generic facilities too.

Differential Revision: https://reviews.llvm.org/D90023
clang/include/clang/Tooling/Syntax/Tree.h
clang/lib/Tooling/Syntax/Tree.cpp
clang/unittests/Tooling/Syntax/TreeTest.cpp
clang/unittests/Tooling/Syntax/TreeTestBase.h