Author: Stephen Kelly
Date: 2020-07-03T21:19:46+01:00
New Revision: 551092bc3dfb86f1e11a55f3bee0c8ee1be6fdd6

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

LOG: Revert AST Matchers default to AsIs mode

Reviewers: aaron.ballman, klimek

Subscribers: cfe-commits

Tags: #clang

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

Added: 
    

Modified: 
    clang-tools-extra/clang-query/Query.cpp
    clang-tools-extra/clang-query/QuerySession.h
    clang/docs/ReleaseNotes.rst
    clang/include/clang/AST/ParentMapContext.h
    clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp

Removed: 
    


################################################################################
diff  --git a/clang-tools-extra/clang-query/Query.cpp 
b/clang-tools-extra/clang-query/Query.cpp
index 4fe7110daed3..ca2a285e9eb7 100644
--- a/clang-tools-extra/clang-query/Query.cpp
+++ b/clang-tools-extra/clang-query/Query.cpp
@@ -46,12 +46,12 @@ bool HelpQuery::run(llvm::raw_ostream &OS, QuerySession 
&QS) const {
         "  set traversal <kind>              "
         "Set traversal kind of clang-query session. Available kinds are:\n"
         "    AsIs                            "
-        "Print and match the AST as clang sees it.\n"
+        "Print and match the AST as clang sees it.  This mode is the "
+        "default.\n"
         "    IgnoreImplicitCastsAndParentheses  "
         "Omit implicit casts and parens in matching and dumping.\n"
         "    IgnoreUnlessSpelledInSource     "
-        "Omit AST nodes unless spelled in the source.  This mode is the "
-        "default.\n"
+        "Omit AST nodes unless spelled in the source.\n"
         "  set output <feature>              "
         "Set whether to output only <feature> content.\n"
         "  enable output <feature>           "

diff  --git a/clang-tools-extra/clang-query/QuerySession.h 
b/clang-tools-extra/clang-query/QuerySession.h
index 1660e4039f61..20c788b206a0 100644
--- a/clang-tools-extra/clang-query/QuerySession.h
+++ b/clang-tools-extra/clang-query/QuerySession.h
@@ -26,7 +26,7 @@ class QuerySession {
   QuerySession(llvm::ArrayRef<std::unique_ptr<ASTUnit>> ASTs)
       : ASTs(ASTs), PrintOutput(false), DiagOutput(true),
         DetailedASTOutput(false), BindRoot(true), PrintMatcher(false),
-        Terminate(false), TK(ast_type_traits::TK_IgnoreUnlessSpelledInSource) 
{}
+        Terminate(false), TK(ast_type_traits::TK_AsIs) {}
 
   llvm::ArrayRef<std::unique_ptr<ASTUnit>> ASTs;
 

diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index c24c289f94b4..4d271bfdcd31 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -258,44 +258,7 @@ 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.
-
-  As this change requires downstream tools which use AST Matchers to adapt
-  to the new default, a porting guide may be useful for downstream tools
-  needing to adapt.
-
-  Note that although there are many steps below, only the first is
-  non-optional. The steps are intentionally extemely granular to facilitate
-  understanding of the guide itself. It is reasonable to do some of the
-  steps at the same time if you understand the guide:
-
-  1. Use ``(your ASTContext 
instance).getParentMapContext().setTraversalKind(TK_AsIs)``
-     to restore the previous behavior for your tool.  All further steps in
-     this porting guide are optional.
-  2. Wrap your existing matcher expressions with ``traverse(TK_AsIs, ...)``
-     before passing them to ``ASTMatchFinder::addMatcher``.
-  3. Remove ``(your ASTContext 
instance).getParentMapContext().setTraversalKind(TK_AsIs)``
-     from your tool so that the default behavior of your tool matches the
-     default behavior of upstream clang. This is made possible by wrapping
-     your matchers in ``traverse(TK_AsIs, ...)`` from step (2).
-  4. Audit your matcher expressions and remove ``traverse(TK_AsIs, ...)``
-     where not needed.
-  5. Audit your matcher expressions and remove calls to ``ignoring*()``
-     matchers where not needed.
-  6. Audit your matcher expressions and consider whether the matcher is
-     better using the ``TK_AsIs`` mode or if it can be better expressed in
-     the default mode. For example, some matchers explicitly match
-     ``has(implicitCastExpr(has(...)))``. Such matchers are sometimes
-     written by author who were unaware of the existence of the
-     ``ignoring*()`` matchers.
-
+- ...
 
 clang-format
 ------------

diff  --git a/clang/include/clang/AST/ParentMapContext.h 
b/clang/include/clang/AST/ParentMapContext.h
index 5f9936b28e8f..be4d75df7b99 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_IgnoreUnlessSpelledInSource;
+  TraversalKind Traversal = TK_AsIs;
   std::unique_ptr<ParentMap> Parents;
 };
 

diff  --git a/clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp 
b/clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp
index 3e1e2beb866d..59e0f74b3910 100644
--- a/clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp
+++ b/clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp
@@ -1207,7 +1207,12 @@ TEST_P(ASTMatchersTest, 
CastExpression_MatchesImplicitCasts) {
 }
 
 TEST_P(ASTMatchersTest, CastExpr_DoesNotMatchNonCasts) {
-  EXPECT_TRUE(notMatches("char c = '0';", castExpr()));
+  if (GetParam().Language == Lang_C89 || GetParam().Language == Lang_C99) {
+    // This does have a cast in C
+    EXPECT_TRUE(matches("char c = '0';", implicitCastExpr()));
+  } else {
+    EXPECT_TRUE(notMatches("char c = '0';", castExpr()));
+  }
   EXPECT_TRUE(notMatches("int i = (0);", castExpr()));
   EXPECT_TRUE(notMatches("int i = 0;", castExpr()));
 }


        
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to