Skip to content

Commit

Permalink
Add utility for testing if we're matching nodes AsIs
Browse files Browse the repository at this point in the history
Differential Revision: https://reviews.llvm.org/D91144
  • Loading branch information
steveire committed Nov 10, 2020
1 parent 7d85f73 commit e73296d
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 9 deletions.
2 changes: 2 additions & 0 deletions clang/include/clang/ASTMatchers/ASTMatchersInternal.h
Expand Up @@ -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,
Expand Down
7 changes: 2 additions & 5 deletions clang/lib/ASTMatchers/ASTMatchFinder.cpp
Expand Up @@ -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 =
Expand Down Expand Up @@ -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;
Expand Down
10 changes: 6 additions & 4 deletions clang/lib/ASTMatchers/ASTMatchersInternal.cpp
Expand Up @@ -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,
Expand Down Expand Up @@ -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;

Expand All @@ -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;

Expand Down

0 comments on commit e73296d

Please sign in to comment.