[clang] e73296d - Add utility for testing if we're matching nodes AsIs

Stephen Kelly via cfe-commits cfe-commits at lists.llvm.org
Tue Nov 10 11:28:28 PST 2020


Author: Stephen Kelly
Date: 2020-11-10T19:28:11Z
New Revision: e73296d3b92fc231f3f913815e477d55b66595bd

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

LOG: Add utility for testing if we're matching nodes AsIs

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

Added: 
    

Modified: 
    clang/include/clang/ASTMatchers/ASTMatchersInternal.h
    clang/lib/ASTMatchers/ASTMatchFinder.cpp
    clang/lib/ASTMatchers/ASTMatchersInternal.cpp

Removed: 
    


################################################################################
diff  --git a/clang/include/clang/ASTMatchers/ASTMatchersInternal.h b/clang/include/clang/ASTMatchers/ASTMatchersInternal.h
index f5563977cb7e..2c2e67ace157 100644
--- a/clang/include/clang/ASTMatchers/ASTMatchersInternal.h
+++ b/clang/include/clang/ASTMatchers/ASTMatchersInternal.h
@@ -1062,6 +1062,8 @@ class ASTMatchFinder {
 
   virtual bool IsMatchingInTemplateInstantiationNotSpelledInSource() const = 0;
 
+  bool isTraversalAsIs() const;
+
 protected:
   virtual bool matchesChildOf(const DynTypedNode &Node, ASTContext &Ctx,
                               const DynTypedMatcher &Matcher,

diff  --git a/clang/lib/ASTMatchers/ASTMatchFinder.cpp b/clang/lib/ASTMatchers/ASTMatchFinder.cpp
index 67de0e14d18c..f86e0648ecc6 100644
--- a/clang/lib/ASTMatchers/ASTMatchFinder.cpp
+++ b/clang/lib/ASTMatchers/ASTMatchFinder.cpp
@@ -153,9 +153,7 @@ class MatchChildASTVisitor
     Stmt *StmtToTraverse = StmtNode;
     if (auto *ExprNode = dyn_cast_or_null<Expr>(StmtNode)) {
       auto *LambdaNode = dyn_cast_or_null<LambdaExpr>(StmtNode);
-      if (LambdaNode &&
-          Finder->getASTContext().getParentMapContext().getTraversalKind() ==
-              TK_IgnoreUnlessSpelledInSource)
+      if (LambdaNode && !Finder->isTraversalAsIs())
         StmtToTraverse = LambdaNode;
       else
         StmtToTraverse =
@@ -232,8 +230,7 @@ class MatchChildASTVisitor
     return traverse(TAL);
   }
   bool TraverseLambdaExpr(LambdaExpr *Node) {
-    if (Finder->getASTContext().getParentMapContext().getTraversalKind() !=
-        TK_IgnoreUnlessSpelledInSource)
+    if (!Finder->isTraversalAsIs())
       return VisitorBase::TraverseLambdaExpr(Node);
     if (!Node)
       return true;

diff  --git a/clang/lib/ASTMatchers/ASTMatchersInternal.cpp b/clang/lib/ASTMatchers/ASTMatchersInternal.cpp
index 2e14ef28ecdb..0eea41bdc4e5 100644
--- a/clang/lib/ASTMatchers/ASTMatchersInternal.cpp
+++ b/clang/lib/ASTMatchers/ASTMatchersInternal.cpp
@@ -191,6 +191,10 @@ class DynTraversalMatcherImpl : public DynMatcherInterface {
 
 static llvm::ManagedStatic<TrueMatcherImpl> TrueMatcherInstance;
 
+bool ASTMatchFinder::isTraversalAsIs() const {
+  return getASTContext().getParentMapContext().getTraversalKind() == TK_AsIs;
+}
+
 DynTypedMatcher
 DynTypedMatcher::constructVariadic(DynTypedMatcher::VariadicOperator Op,
                                    ASTNodeKind SupportedKind,
@@ -284,8 +288,7 @@ bool DynTypedMatcher::matches(const DynTypedNode &DynNode,
   TraversalKindScope RAII(Finder->getASTContext(),
                           Implementation->TraversalKind());
 
-  if (Finder->getASTContext().getParentMapContext().getTraversalKind() ==
-          TK_IgnoreUnlessSpelledInSource &&
+  if (!Finder->isTraversalAsIs() &&
       Finder->IsMatchingInTemplateInstantiationNotSpelledInSource())
     return false;
 
@@ -309,8 +312,7 @@ bool DynTypedMatcher::matchesNoKindCheck(const DynTypedNode &DynNode,
   TraversalKindScope raii(Finder->getASTContext(),
                           Implementation->TraversalKind());
 
-  if (Finder->getASTContext().getParentMapContext().getTraversalKind() ==
-          TK_IgnoreUnlessSpelledInSource &&
+  if (!Finder->isTraversalAsIs() &&
       Finder->IsMatchingInTemplateInstantiationNotSpelledInSource())
     return false;
 


        


More information about the cfe-commits mailing list