[PATCH] D104071: [AST] Include the TranslationUnitDecl when traversing with TraversalScope

Sam McCall via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Jun 10 16:07:22 PDT 2021


sammccall created this revision.
sammccall added reviewers: hokein, chh, srhines.
Herald added subscribers: usaxena95, kadircet, arphaman.
sammccall requested review of this revision.
Herald added projects: clang, clang-tools-extra.
Herald added a subscriber: cfe-commits.

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.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D104071

Files:
  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/Tooling/RecursiveASTVisitorTests/TraversalScope.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D104071.351289.patch
Type: text/x-patch
Size: 8284 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20210610/b42a0c10/attachment.bin>


More information about the cfe-commits mailing list