From: Stephen Kelly Date: Mon, 9 Nov 2020 19:56:48 +0000 (+0000) Subject: Add utility for testing if we're matching nodes AsIs X-Git-Tag: llvmorg-13-init~6493 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=872633b28538f87a2b7f61bcb91259cf7e09dfa1;p=platform%2Fupstream%2Fllvm.git Add utility for testing if we're matching nodes AsIs Differential Revision: https://reviews.llvm.org/D91144 --- diff --git a/clang/include/clang/ASTMatchers/ASTMatchersInternal.h b/clang/include/clang/ASTMatchers/ASTMatchersInternal.h index f556397..2c2e67a 100644 --- a/clang/include/clang/ASTMatchers/ASTMatchersInternal.h +++ b/clang/include/clang/ASTMatchers/ASTMatchersInternal.h @@ -1062,6 +1062,8 @@ public: 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 67de0e1..33dd45d4 100644 --- a/clang/lib/ASTMatchers/ASTMatchFinder.cpp +++ b/clang/lib/ASTMatchers/ASTMatchFinder.cpp @@ -153,9 +153,7 @@ public: Stmt *StmtToTraverse = StmtNode; if (auto *ExprNode = dyn_cast_or_null(StmtNode)) { auto *LambdaNode = dyn_cast_or_null(StmtNode); - if (LambdaNode && - Finder->getASTContext().getParentMapContext().getTraversalKind() == - TK_IgnoreUnlessSpelledInSource) + if (LambdaNode && !Finder->isTraversalAsIs()) StmtToTraverse = LambdaNode; else StmtToTraverse = @@ -232,8 +230,7 @@ public: 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 2e14ef2..0eea41b 100644 --- a/clang/lib/ASTMatchers/ASTMatchersInternal.cpp +++ b/clang/lib/ASTMatchers/ASTMatchersInternal.cpp @@ -191,6 +191,10 @@ private: static llvm::ManagedStatic 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;