[PATCH] D91144: Add utility for testing if we're matching nodes AsIs
Stephen Kelly via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Tue Nov 10 01:47:38 PST 2020
steveire created this revision.
steveire added a reviewer: aaron.ballman.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.
steveire requested review of this revision.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D91144
Files:
clang/include/clang/ASTMatchers/ASTMatchersInternal.h
clang/lib/ASTMatchers/ASTMatchFinder.cpp
clang/lib/ASTMatchers/ASTMatchersInternal.cpp
Index: clang/lib/ASTMatchers/ASTMatchersInternal.cpp
===================================================================
--- clang/lib/ASTMatchers/ASTMatchersInternal.cpp
+++ clang/lib/ASTMatchers/ASTMatchersInternal.cpp
@@ -191,6 +191,10 @@
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 @@
TraversalKindScope RAII(Finder->getASTContext(),
Implementation->TraversalKind());
- if (Finder->getASTContext().getParentMapContext().getTraversalKind() ==
- TK_IgnoreUnlessSpelledInSource &&
+ if (!Finder->isTraversalAsIs() &&
Finder->IsMatchingInTemplateInstantiationNotSpelledInSource())
return false;
@@ -309,8 +312,7 @@
TraversalKindScope raii(Finder->getASTContext(),
Implementation->TraversalKind());
- if (Finder->getASTContext().getParentMapContext().getTraversalKind() ==
- TK_IgnoreUnlessSpelledInSource &&
+ if (!Finder->isTraversalAsIs() &&
Finder->IsMatchingInTemplateInstantiationNotSpelledInSource())
return false;
Index: clang/lib/ASTMatchers/ASTMatchFinder.cpp
===================================================================
--- clang/lib/ASTMatchers/ASTMatchFinder.cpp
+++ clang/lib/ASTMatchers/ASTMatchFinder.cpp
@@ -153,9 +153,7 @@
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 @@
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;
Index: clang/include/clang/ASTMatchers/ASTMatchersInternal.h
===================================================================
--- clang/include/clang/ASTMatchers/ASTMatchersInternal.h
+++ clang/include/clang/ASTMatchers/ASTMatchersInternal.h
@@ -1062,6 +1062,8 @@
virtual bool IsMatchingInTemplateInstantiationNotSpelledInSource() const = 0;
+ bool isTraversalAsIs() const;
+
protected:
virtual bool matchesChildOf(const DynTypedNode &Node, ASTContext &Ctx,
const DynTypedMatcher &Matcher,
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D91144.304102.patch
Type: text/x-patch
Size: 2915 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20201110/ad30387f/attachment.bin>
More information about the cfe-commits
mailing list