Skip to content

Commit fb532e7

Browse files
committed
[Feat] Allow Finding across only parts of an AST.
This is relevant for clang modules, as they are imported into the AST, but are actually part of a different TU. It can result in hundreds of milliseconds of additional time to also traverse the AST of these modules, and often for no benefit, as they are frequently already traversed in their own TU.
1 parent dc79c66 commit fb532e7

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

clang/include/clang/ASTMatchers/ASTMatchFinder.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,13 @@ class MatchFinder {
139139
///
140140
/// It prints a report after match.
141141
std::optional<Profiling> CheckProfiling;
142+
143+
/// Whether to traverse a Decl. This is relevant for clang modules, as they
144+
/// are imported into the AST, but are actually part of a different TU.
145+
/// It can result in hundreds of milliseconds of additional time to also
146+
/// traverse the AST of these modules, and often for no benefit, as they
147+
/// are frequently already traversed in their own TU.
148+
std::optional<llvm::function_ref<bool(const Decl *)>> ShouldTraverseDecl;
142149
};
143150

144151
MatchFinder(MatchFinderOptions Options = MatchFinderOptions());

clang/lib/ASTMatchers/ASTMatchFinder.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1443,7 +1443,7 @@ bool MatchASTVisitor::objcClassIsDerivedFrom(
14431443
}
14441444

14451445
bool MatchASTVisitor::TraverseDecl(Decl *DeclNode) {
1446-
if (!DeclNode) {
1446+
if (!DeclNode || (Options.ShouldTraverseDecl && !(*Options.ShouldTraverseDecl)(DeclNode))) {
14471447
return true;
14481448
}
14491449

0 commit comments

Comments
 (0)