[AST] Include the TranslationUnitDecl when traversing with TraversalScope
authorSam McCall <sam.mccall@gmail.com>
Thu, 10 Jun 2021 22:16:14 +0000 (00:16 +0200)
committerSam McCall <sam.mccall@gmail.com>
Fri, 11 Jun 2021 12:29:45 +0000 (14:29 +0200)
commit6aca6032c5b62b5d26999da5f55779a1b08ec6a2
treeb4a1025b09a3d4fae629ad6a533d53f7f2b5cc11
parent61cdaf66fe22be2b5942ddee4f46a998b4f3ee29
[AST] Include the TranslationUnitDecl when traversing with TraversalScope

Given `int foo, bar;`, TraverseAST reveals this tree:
  TranslationUnitDecl
   - foo
   - bar

Before this patch, with the TraversalScope set to {foo}, TraverseAST yields:
  foo

After this patch it yields:
  TranslationUnitDecl
  - foo

Also, TraverseDecl(TranslationUnitDecl) now respects the traversal scope.

---

The main effect of this today is that clang-tidy checks that match the
translationUnitDecl(), either in order to traverse it or check
parentage, should work.

Differential Revision: https://reviews.llvm.org/D104071
clang-tools-extra/clangd/DumpAST.cpp
clang-tools-extra/clangd/refactor/tweaks/AddUsing.cpp
clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp
clang-tools-extra/clangd/unittests/TestTU.cpp
clang/include/clang/AST/ASTContext.h
clang/include/clang/AST/RecursiveASTVisitor.h
clang/unittests/AST/ASTContextParentMapTest.cpp
clang/unittests/Tooling/RecursiveASTVisitorTests/TraversalScope.cpp