[clang] d0da5d2 - Change default traversal in AST Matchers to ignore invisible nodes

Stephen Kelly via cfe-commits cfe-commits at lists.llvm.org
Sun May 24 16:19:10 PDT 2020


Author: Stephen Kelly
Date: 2020-05-25T00:18:54+01:00
New Revision: d0da5d2bbe8305d06dc01a98706fd73e11e24a9f

URL: https://github.com/llvm/llvm-project/commit/d0da5d2bbe8305d06dc01a98706fd73e11e24a9f
DIFF: https://github.com/llvm/llvm-project/commit/d0da5d2bbe8305d06dc01a98706fd73e11e24a9f.diff

LOG: Change default traversal in AST Matchers to ignore invisible nodes

This makes many scenarios simpler by not requiring the user to write
ignoringImplicit() all the time, nor to account for non-visible
cxxConstructExpr() and cxxMemberCalExpr() nodes. This is also, in part,
inclusive of the equivalent of adding a use of ignoringParenImpCasts()
between all expr()-related matchers in an expression.

The pre-existing traverse(TK_AsIs, ...) matcher can be used to explcitly
match on implicit/invisible nodes. See

  http://lists.llvm.org/pipermail/cfe-dev/2019-December/064143.html

for more

Reviewers: aaron.ballman

Subscribers: cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D72534

Added: 
    

Modified: 
    clang/docs/ReleaseNotes.rst
    clang/include/clang/AST/ParentMapContext.h

Removed: 
    


################################################################################
diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 16f5915856fd..c38ff0e36790 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -246,7 +246,14 @@ release of Clang. Users of the build system should adjust accordingly.
 AST Matchers
 ------------
 
-- ...
+- Traversal in AST Matchers was simplified to use the
+  ``TK_IgnoreUnlessSpelledInSource`` mode by default, instead of ``TK_AsIs``.
+  This means that many uses of the ``ignoringImplicit()`` and similar matchers
+  is no longer necessary.  Clients of AST Matchers which wish to match on
+  implicit AST nodes can wrap their matcher in ``traverse(TK_AsIs, ...)`` or
+  use ``TraversalKindScope`` if appropriate.  The ``clang-query`` tool also
+  uses ``IgnoreUnlessSpelledInSource`` by default.  The mode can be changed
+  using ``set traversal AsIs`` in the ``clang-query`` environment.
 
 clang-format
 ------------

diff  --git a/clang/include/clang/AST/ParentMapContext.h b/clang/include/clang/AST/ParentMapContext.h
index be4d75df7b99..5f9936b28e8f 100644
--- a/clang/include/clang/AST/ParentMapContext.h
+++ b/clang/include/clang/AST/ParentMapContext.h
@@ -67,7 +67,7 @@ class ParentMapContext {
 private:
   ASTContext &ASTCtx;
   class ParentMap;
-  TraversalKind Traversal = TK_AsIs;
+  TraversalKind Traversal = TK_IgnoreUnlessSpelledInSource;
   std::unique_ptr<ParentMap> Parents;
 };
 


        


More information about the cfe-commits mailing list