23 #include "llvm/ADT/DenseMap.h" 24 #include "llvm/ADT/StringMap.h" 25 #include "llvm/Support/Timer.h" 35 typedef MatchFinder::MatchCallback MatchCallback;
45 static const unsigned MaxMemoizationEntries = 10000;
64 bool operator<(
const MatchKey &Other)
const {
65 return std::tie(MatcherID, Node, BoundNodes) <
66 std::tie(Other.MatcherID, Other.Node, Other.BoundNodes);
71 struct MemoizedMatchResult {
78 class MatchChildASTVisitor
79 :
public RecursiveASTVisitor<MatchChildASTVisitor> {
81 typedef RecursiveASTVisitor<MatchChildASTVisitor> VisitorBase;
87 MatchChildASTVisitor(
const DynTypedMatcher *Matcher,
88 ASTMatchFinder *Finder,
89 BoundNodesTreeBuilder *Builder,
91 ASTMatchFinder::TraversalKind Traversal,
92 ASTMatchFinder::BindKind Bind)
115 if (
const Decl *D = DynNode.get<Decl>())
117 else if (
const Stmt *S = DynNode.get<Stmt>())
119 else if (
const NestedNameSpecifier *NNS =
120 DynNode.get<NestedNameSpecifier>())
122 else if (
const NestedNameSpecifierLoc *NNSLoc =
123 DynNode.get<NestedNameSpecifierLoc>())
125 else if (
const QualType *Q = DynNode.get<QualType>())
127 else if (
const TypeLoc *T = DynNode.get<TypeLoc>())
129 else if (
const auto *C = DynNode.get<CXXCtorInitializer>())
136 *Builder = ResultBindings;
144 bool TraverseDecl(Decl *DeclNode) {
145 ScopedIncrement ScopedDepth(&CurrentDepth);
146 return (DeclNode ==
nullptr) || traverse(*DeclNode);
148 bool TraverseStmt(Stmt *StmtNode, DataRecursionQueue *Queue =
nullptr) {
150 if (CurrentDepth == 0 || (CurrentDepth <= MaxDepth && MaxDepth <
INT_MAX))
153 ScopedIncrement ScopedDepth(&CurrentDepth);
154 Stmt *StmtToTraverse = StmtNode;
155 if (Traversal == ASTMatchFinder::TK_IgnoreImplicitCastsAndParentheses) {
156 if (Expr *ExprNode = dyn_cast_or_null<Expr>(StmtNode))
157 StmtToTraverse = ExprNode->IgnoreParenImpCasts();
161 if (!
match(*StmtToTraverse))
163 return VisitorBase::TraverseStmt(StmtToTraverse, Queue);
167 bool TraverseType(QualType TypeNode) {
168 if (TypeNode.isNull())
170 ScopedIncrement ScopedDepth(&CurrentDepth);
172 if (!
match(*TypeNode))
175 return traverse(TypeNode);
179 bool TraverseTypeLoc(TypeLoc TypeLocNode) {
180 if (TypeLocNode.isNull())
182 ScopedIncrement ScopedDepth(&CurrentDepth);
184 if (!
match(*TypeLocNode.getType()))
187 if (!
match(TypeLocNode.getType()))
190 return traverse(TypeLocNode);
192 bool TraverseNestedNameSpecifier(NestedNameSpecifier *NNS) {
193 ScopedIncrement ScopedDepth(&CurrentDepth);
194 return (NNS ==
nullptr) || traverse(*NNS);
196 bool TraverseNestedNameSpecifierLoc(NestedNameSpecifierLoc NNS) {
199 ScopedIncrement ScopedDepth(&CurrentDepth);
200 if (!
match(*NNS.getNestedNameSpecifier()))
202 return traverse(NNS);
204 bool TraverseConstructorInitializer(CXXCtorInitializer *CtorInit) {
207 ScopedIncrement ScopedDepth(&CurrentDepth);
208 return traverse(*CtorInit);
211 bool shouldVisitTemplateInstantiations()
const {
return true; }
212 bool shouldVisitImplicitCode()
const {
return true; }
216 struct ScopedIncrement {
217 explicit ScopedIncrement(
int *
Depth) :
Depth(Depth) { ++(*Depth); }
218 ~ScopedIncrement() { --(*Depth); }
232 bool baseTraverse(
const Decl &DeclNode) {
233 return VisitorBase::TraverseDecl(const_cast<Decl*>(&DeclNode));
235 bool baseTraverse(
const Stmt &StmtNode) {
236 return VisitorBase::TraverseStmt(const_cast<Stmt*>(&StmtNode));
238 bool baseTraverse(QualType TypeNode) {
239 return VisitorBase::TraverseType(TypeNode);
241 bool baseTraverse(TypeLoc TypeLocNode) {
242 return VisitorBase::TraverseTypeLoc(TypeLocNode);
244 bool baseTraverse(
const NestedNameSpecifier &NNS) {
245 return VisitorBase::TraverseNestedNameSpecifier(
246 const_cast<NestedNameSpecifier*>(&NNS));
248 bool baseTraverse(NestedNameSpecifierLoc NNS) {
249 return VisitorBase::TraverseNestedNameSpecifierLoc(NNS);
251 bool baseTraverse(
const CXXCtorInitializer &CtorInit) {
252 return VisitorBase::TraverseConstructorInitializer(
253 const_cast<CXXCtorInitializer *>(&CtorInit));
261 template <
typename T>
263 if (CurrentDepth == 0 || CurrentDepth > MaxDepth) {
266 if (Bind != ASTMatchFinder::BK_All) {
267 BoundNodesTreeBuilder RecursiveBuilder(*Builder);
269 &RecursiveBuilder)) {
271 ResultBindings.addMatch(RecursiveBuilder);
275 BoundNodesTreeBuilder RecursiveBuilder(*Builder);
277 &RecursiveBuilder)) {
280 ResultBindings.addMatch(RecursiveBuilder);
288 template <
typename T>
289 bool traverse(
const T &Node) {
290 static_assert(IsBaseType<T>::value,
291 "traverse can only be instantiated with base type");
294 return baseTraverse(Node);
297 const DynTypedMatcher *
const Matcher;
298 ASTMatchFinder *
const Finder;
299 BoundNodesTreeBuilder *
const Builder;
300 BoundNodesTreeBuilder ResultBindings;
303 const ASTMatchFinder::TraversalKind Traversal;
304 const ASTMatchFinder::BindKind Bind;
310 class MatchASTVisitor :
public RecursiveASTVisitor<MatchASTVisitor>,
311 public ASTMatchFinder {
313 MatchASTVisitor(
const MatchFinder::MatchersByType *Matchers,
314 const MatchFinder::MatchFinderOptions &Options)
315 : Matchers(Matchers), Options(Options), ActiveASTContext(
nullptr) {}
317 ~MatchASTVisitor()
override {
318 if (Options.CheckProfiling) {
319 Options.CheckProfiling->Records = std::move(TimeByBucket);
323 void onStartOfTranslationUnit() {
324 const bool EnableCheckProfiling = Options.CheckProfiling.hasValue();
325 TimeBucketRegion Timer;
326 for (MatchCallback *MC : Matchers->AllCallbacks) {
327 if (EnableCheckProfiling)
328 Timer.setBucket(&TimeByBucket[MC->getID()]);
329 MC->onStartOfTranslationUnit();
333 void onEndOfTranslationUnit() {
334 const bool EnableCheckProfiling = Options.CheckProfiling.hasValue();
335 TimeBucketRegion Timer;
336 for (MatchCallback *MC : Matchers->AllCallbacks) {
337 if (EnableCheckProfiling)
338 Timer.setBucket(&TimeByBucket[MC->getID()]);
339 MC->onEndOfTranslationUnit();
343 void set_active_ast_context(ASTContext *NewActiveASTContext) {
344 ActiveASTContext = NewActiveASTContext;
350 bool VisitTypedefNameDecl(TypedefNameDecl *DeclNode) {
378 const Type *TypeNode = DeclNode->getUnderlyingType().getTypePtr();
379 const Type *CanonicalType =
380 ActiveASTContext->getCanonicalType(TypeNode);
381 TypeAliases[CanonicalType].insert(DeclNode);
385 bool TraverseDecl(Decl *DeclNode);
386 bool TraverseStmt(Stmt *StmtNode, DataRecursionQueue *Queue =
nullptr);
387 bool TraverseType(QualType TypeNode);
388 bool TraverseTypeLoc(TypeLoc TypeNode);
389 bool TraverseNestedNameSpecifier(NestedNameSpecifier *NNS);
390 bool TraverseNestedNameSpecifierLoc(NestedNameSpecifierLoc NNS);
391 bool TraverseConstructorInitializer(CXXCtorInitializer *CtorInit);
395 const DynTypedMatcher &Matcher,
396 BoundNodesTreeBuilder *Builder,
int MaxDepth,
397 TraversalKind Traversal, BindKind Bind) {
399 if (!Node.getMemoizationData() || !Builder->isComparable())
400 return matchesRecursively(Node, Matcher, Builder, MaxDepth, Traversal,
404 Key.MatcherID = Matcher.getID();
407 Key.BoundNodes = *Builder;
409 MemoizationMap::iterator I = ResultCache.find(Key);
410 if (I != ResultCache.end()) {
411 *Builder = I->second.Nodes;
412 return I->second.ResultOfMatch;
415 MemoizedMatchResult Result;
416 Result.Nodes = *Builder;
417 Result.ResultOfMatch = matchesRecursively(Node, Matcher, &Result.Nodes,
418 MaxDepth, Traversal, Bind);
420 MemoizedMatchResult &CachedResult = ResultCache[Key];
421 CachedResult = std::move(Result);
423 *Builder = CachedResult.Nodes;
424 return CachedResult.ResultOfMatch;
429 const DynTypedMatcher &Matcher,
430 BoundNodesTreeBuilder *Builder,
int MaxDepth,
431 TraversalKind Traversal, BindKind Bind) {
432 MatchChildASTVisitor Visitor(
433 &Matcher,
this, Builder, MaxDepth, Traversal, Bind);
434 return Visitor.findMatch(Node);
437 bool classIsDerivedFrom(
const CXXRecordDecl *Declaration,
438 const Matcher<NamedDecl> &
Base,
439 BoundNodesTreeBuilder *Builder)
override;
443 const DynTypedMatcher &Matcher,
444 BoundNodesTreeBuilder *Builder,
445 TraversalKind Traversal,
446 BindKind Bind)
override {
447 if (ResultCache.size() > MaxMemoizationEntries)
449 return memoizedMatchesRecursively(Node, Matcher, Builder, 1, Traversal,
454 const DynTypedMatcher &Matcher,
455 BoundNodesTreeBuilder *Builder,
456 BindKind Bind)
override {
457 if (ResultCache.size() > MaxMemoizationEntries)
459 return memoizedMatchesRecursively(Node, Matcher, Builder,
INT_MAX,
464 const DynTypedMatcher &Matcher,
465 BoundNodesTreeBuilder *Builder,
466 AncestorMatchMode MatchMode)
override {
469 if (ResultCache.size() > MaxMemoizationEntries)
471 return memoizedMatchesAncestorOfRecursively(Node, Matcher, Builder,
479 if (
auto *N = Node.get<Decl>()) {
481 }
else if (
auto *N = Node.get<Stmt>()) {
483 }
else if (
auto *N = Node.get<
Type>()) {
485 }
else if (
auto *N = Node.get<QualType>()) {
487 }
else if (
auto *N = Node.get<NestedNameSpecifier>()) {
489 }
else if (
auto *N = Node.get<NestedNameSpecifierLoc>()) {
491 }
else if (
auto *N = Node.get<TypeLoc>()) {
493 }
else if (
auto *N = Node.get<CXXCtorInitializer>()) {
498 template <
typename T>
void match(
const T &Node) {
499 matchDispatch(&Node);
503 ASTContext &getASTContext()
const override {
return *ActiveASTContext; }
505 bool shouldVisitTemplateInstantiations()
const {
return true; }
506 bool shouldVisitImplicitCode()
const {
return true; }
509 class TimeBucketRegion {
511 TimeBucketRegion() : Bucket(
nullptr) {}
512 ~TimeBucketRegion() { setBucket(
nullptr); }
522 void setBucket(llvm::TimeRecord *NewBucket) {
523 if (Bucket != NewBucket) {
524 auto Now = llvm::TimeRecord::getCurrentTime(
true);
534 llvm::TimeRecord *Bucket;
540 template <
typename T,
typename MC>
541 void matchWithoutFilter(
const T &Node,
const MC &Matchers) {
542 const bool EnableCheckProfiling = Options.CheckProfiling.hasValue();
543 TimeBucketRegion Timer;
544 for (
const auto &MP : Matchers) {
545 if (EnableCheckProfiling)
546 Timer.setBucket(&TimeByBucket[MP.second->getID()]);
547 BoundNodesTreeBuilder Builder;
548 if (MP.first.matches(Node,
this, &Builder)) {
549 MatchVisitor Visitor(ActiveASTContext, MP.second);
550 Builder.visitMatches(&Visitor);
556 auto Kind = DynNode.getNodeKind();
557 auto it = MatcherFiltersMap.find(
Kind);
559 it != MatcherFiltersMap.end() ? it->second : getFilterForKind(
Kind);
564 const bool EnableCheckProfiling = Options.CheckProfiling.hasValue();
565 TimeBucketRegion Timer;
566 auto &Matchers = this->Matchers->DeclOrStmt;
567 for (
unsigned short I :
Filter) {
568 auto &MP = Matchers[I];
569 if (EnableCheckProfiling)
570 Timer.setBucket(&TimeByBucket[MP.second->getID()]);
571 BoundNodesTreeBuilder Builder;
572 if (MP.first.matchesNoKindCheck(DynNode,
this, &Builder)) {
573 MatchVisitor Visitor(ActiveASTContext, MP.second);
574 Builder.visitMatches(&Visitor);
579 const std::vector<unsigned short> &
580 getFilterForKind(ast_type_traits::ASTNodeKind
Kind) {
582 auto &Matchers = this->Matchers->DeclOrStmt;
583 assert((Matchers.size() <
USHRT_MAX) &&
"Too many matchers.");
584 for (
unsigned I = 0, E = Matchers.size(); I != E; ++I) {
585 if (Matchers[I].first.canMatchNodesOfKind(Kind)) {
594 void matchDispatch(
const Decl *Node) {
597 void matchDispatch(
const Stmt *Node) {
601 void matchDispatch(
const Type *Node) {
602 matchWithoutFilter(QualType(Node, 0), Matchers->Type);
604 void matchDispatch(
const TypeLoc *Node) {
605 matchWithoutFilter(*Node, Matchers->TypeLoc);
607 void matchDispatch(
const QualType *Node) {
608 matchWithoutFilter(*Node, Matchers->Type);
610 void matchDispatch(
const NestedNameSpecifier *Node) {
611 matchWithoutFilter(*Node, Matchers->NestedNameSpecifier);
613 void matchDispatch(
const NestedNameSpecifierLoc *Node) {
614 matchWithoutFilter(*Node, Matchers->NestedNameSpecifierLoc);
616 void matchDispatch(
const CXXCtorInitializer *Node) {
617 matchWithoutFilter(*Node, Matchers->CtorInit);
619 void matchDispatch(
const void *) { }
635 bool memoizedMatchesAncestorOfRecursively(
637 BoundNodesTreeBuilder *Builder, AncestorMatchMode MatchMode) {
639 if (!Builder->isComparable())
640 return matchesAncestorOfRecursively(Node, Matcher, Builder, MatchMode);
643 Key.MatcherID = Matcher.getID();
645 Key.BoundNodes = *Builder;
649 MemoizationMap::iterator I = ResultCache.find(Key);
650 if (I != ResultCache.end()) {
651 *Builder = I->second.Nodes;
652 return I->second.ResultOfMatch;
655 MemoizedMatchResult Result;
656 Result.Nodes = *Builder;
657 Result.ResultOfMatch =
658 matchesAncestorOfRecursively(Node, Matcher, &Result.Nodes, MatchMode);
660 MemoizedMatchResult &CachedResult = ResultCache[Key];
661 CachedResult = std::move(Result);
663 *Builder = CachedResult.Nodes;
664 return CachedResult.ResultOfMatch;
668 const DynTypedMatcher &Matcher,
669 BoundNodesTreeBuilder *Builder,
670 AncestorMatchMode MatchMode) {
671 const auto &Parents = ActiveASTContext->getParents(Node);
672 if (Parents.empty()) {
680 if (!Node.get<TranslationUnitDecl>() &&
682 llvm::any_of(ActiveASTContext->getTraversalScope(), [](Decl *D) {
683 return D->getKind() == Decl::TranslationUnit;
685 llvm::errs() <<
"Tried to match orphan node:\n";
686 Node.dump(llvm::errs(), ActiveASTContext->getSourceManager());
687 llvm_unreachable(
"Parent map should be complete!");
692 if (Parents.size() == 1) {
695 BoundNodesTreeBuilder BuilderCopy = *Builder;
696 if (Matcher.matches(Parent,
this, &BuilderCopy)) {
697 *Builder = std::move(BuilderCopy);
700 if (MatchMode != ASTMatchFinder::AMM_ParentOnly) {
701 return memoizedMatchesAncestorOfRecursively(Parent, Matcher, Builder,
709 std::deque<ast_type_traits::DynTypedNode> Queue(Parents.begin(),
711 while (!Queue.empty()) {
712 BoundNodesTreeBuilder BuilderCopy = *Builder;
713 if (Matcher.matches(Queue.front(),
this, &BuilderCopy)) {
714 *Builder = std::move(BuilderCopy);
717 if (MatchMode != ASTMatchFinder::AMM_ParentOnly) {
719 ActiveASTContext->getParents(Queue.front())) {
723 if (Visited.insert(
Parent.getMemoizationData()).second)
735 class MatchVisitor :
public BoundNodesTreeBuilder::Visitor {
737 MatchVisitor(ASTContext* Context,
738 MatchFinder::MatchCallback* Callback)
740 Callback(Callback) {}
742 void visitMatch(
const BoundNodes& BoundNodesView)
override {
743 Callback->run(MatchFinder::MatchResult(BoundNodesView, Context));
748 MatchFinder::MatchCallback* Callback;
752 bool typeHasMatchingAlias(
const Type *TypeNode,
753 const Matcher<NamedDecl> &Matcher,
754 BoundNodesTreeBuilder *Builder) {
755 const Type *
const CanonicalType =
756 ActiveASTContext->getCanonicalType(TypeNode);
757 auto Aliases = TypeAliases.find(CanonicalType);
758 if (Aliases == TypeAliases.end())
760 for (
const TypedefNameDecl *Alias : Aliases->second) {
761 BoundNodesTreeBuilder Result(*Builder);
762 if (Matcher.matches(*Alias,
this, &Result)) {
763 *Builder = std::move(Result);
773 llvm::StringMap<llvm::TimeRecord> TimeByBucket;
775 const MatchFinder::MatchersByType *Matchers;
785 llvm::DenseMap<ast_type_traits::ASTNodeKind, std::vector<unsigned short>>
788 const MatchFinder::MatchFinderOptions &Options;
789 ASTContext *ActiveASTContext;
792 llvm::DenseMap<const Type*, std::set<const TypedefNameDecl*> > TypeAliases;
795 typedef std::map<MatchKey, MemoizedMatchResult> MemoizationMap;
796 MemoizationMap ResultCache;
799 static CXXRecordDecl *
800 getAsCXXRecordDeclOrPrimaryTemplate(
const Type *TypeNode) {
801 if (
auto *RD = TypeNode->getAsCXXRecordDecl())
805 auto *TemplateType = TypeNode->getAs<TemplateSpecializationType>();
806 while (TemplateType && TemplateType->isTypeAlias())
808 TemplateType->getAliasedType()->getAs<TemplateSpecializationType>();
813 if (
auto *ClassTemplate = dyn_cast_or_null<ClassTemplateDecl>(
814 TemplateType->getTemplateName().getAsTemplateDecl()))
815 return ClassTemplate->getTemplatedDecl();
823 bool MatchASTVisitor::classIsDerivedFrom(
const CXXRecordDecl *Declaration,
824 const Matcher<NamedDecl> &
Base,
825 BoundNodesTreeBuilder *Builder) {
826 if (!Declaration->hasDefinition())
828 for (
const auto &It : Declaration->bases()) {
829 const Type *TypeNode = It.getType().getTypePtr();
831 if (typeHasMatchingAlias(TypeNode, Base, Builder))
837 CXXRecordDecl *ClassDecl = getAsCXXRecordDeclOrPrimaryTemplate(TypeNode);
840 if (ClassDecl == Declaration) {
845 BoundNodesTreeBuilder Result(*Builder);
846 if (Base.matches(*ClassDecl,
this, &Result)) {
847 *Builder = std::move(Result);
850 if (classIsDerivedFrom(ClassDecl, Base, Builder))
856 bool MatchASTVisitor::TraverseDecl(Decl *DeclNode) {
864 bool MatchASTVisitor::TraverseStmt(Stmt *StmtNode, DataRecursionQueue *Queue) {
872 bool MatchASTVisitor::TraverseType(QualType TypeNode) {
877 bool MatchASTVisitor::TraverseTypeLoc(TypeLoc TypeLocNode) {
884 match(TypeLocNode.getType());
888 bool MatchASTVisitor::TraverseNestedNameSpecifier(NestedNameSpecifier *NNS) {
893 bool MatchASTVisitor::TraverseNestedNameSpecifierLoc(
894 NestedNameSpecifierLoc NNS) {
902 if (NNS.hasQualifier())
903 match(*NNS.getNestedNameSpecifier());
908 bool MatchASTVisitor::TraverseConstructorInitializer(
909 CXXCtorInitializer *CtorInit) {
919 class MatchASTConsumer :
public ASTConsumer {
921 MatchASTConsumer(MatchFinder *Finder,
922 MatchFinder::ParsingDoneTestCallback *ParsingDone)
923 : Finder(Finder), ParsingDone(ParsingDone) {}
926 void HandleTranslationUnit(ASTContext &Context)
override {
927 if (ParsingDone !=
nullptr) {
930 Finder->matchAST(Context);
934 MatchFinder::ParsingDoneTestCallback *ParsingDone;
942 : Nodes(Nodes), Context(Context),
949 : Options(
std::move(Options)), ParsingDone(nullptr) {}
955 Matchers.
DeclOrStmt.emplace_back(NodeMatch, Action);
961 Matchers.
Type.emplace_back(NodeMatch, Action);
967 Matchers.
DeclOrStmt.emplace_back(NodeMatch, Action);
985 Matchers.
TypeLoc.emplace_back(NodeMatch, Action);
991 Matchers.
CtorInit.emplace_back(NodeMatch, Action);
997 if (NodeMatch.canConvertTo<
Decl>()) {
1000 }
else if (NodeMatch.canConvertTo<
QualType>()) {
1003 }
else if (NodeMatch.canConvertTo<
Stmt>()) {
1012 }
else if (NodeMatch.canConvertTo<
TypeLoc>()) {
1023 return llvm::make_unique<internal::MatchASTConsumer>(
this, ParsingDone);
1028 internal::MatchASTVisitor Visitor(&Matchers, Options);
1029 Visitor.set_active_ast_context(&Context);
1030 Visitor.match(Node);
1034 internal::MatchASTVisitor Visitor(&Matchers, Options);
1035 Visitor.set_active_ast_context(&Context);
1036 Visitor.onStartOfTranslationUnit();
1037 Visitor.TraverseAST(Context);
1038 Visitor.onEndOfTranslationUnit();
1043 ParsingDone = NewParsingDone;
Defines the clang::ASTContext interface.
A (possibly-)qualified type.
internal::Matcher< NestedNameSpecifier > NestedNameSpecifierMatcher
Stmt - This represents one statement.
internal::Matcher< Stmt > StatementMatcher
Decl - This represents one declaration (or definition), e.g.
llvm::SmallPtrSet< MatchCallback *, 16 > AllCallbacks
All the callbacks in one container to simplify iteration.
Called when parsing is finished. Intended for testing only.
MatchFinder(MatchFinderOptions Options=MatchFinderOptions())
internal::Matcher< QualType > TypeMatcher
BoundNodesTreeBuilder Nodes
bool TraverseDecl(Decl *D)
Recursively visit a declaration, by dispatching to Traverse*Decl() based on the argument's dynamic ty...
Base wrapper for a particular "section" of type source info.
virtual ~ParsingDoneTestCallback()
void match(const T &Node, ASTContext &Context)
Calls the registered callbacks on all matches on the given Node.
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
A C++ nested-name-specifier augmented with source location information.
void addMatcher(const DeclarationMatcher &NodeMatch, MatchCallback *Action)
Adds a matcher to execute when running over the AST.
std::vector< std::pair< CXXCtorInitializerMatcher, MatchCallback * > > CtorInit
SmallVector< BoundNodes, 1 > match(MatcherT Matcher, const NodeT &Node, ASTContext &Context)
Returns the results of matching Matcher on Node.
DynTypedMatcher::MatcherIDType MatcherID
bool TraverseConstructorInitializer(CXXCtorInitializer *Init)
Recursively visit a constructor initializer.
void registerTestCallbackAfterParsing(ParsingDoneTestCallback *ParsingDone)
Registers a callback to notify the end of parsing.
MatchResult(const BoundNodes &Nodes, clang::ASTContext *Context)
std::unique_ptr< clang::ASTConsumer > newASTConsumer()
Creates a clang ASTConsumer that finds all matches.
Maps string IDs to AST nodes matched by parts of a matcher.
virtual StringRef getID() const
An id used to group the matchers.
bool TraverseTypeLoc(TypeLoc TL)
Recursively visit a type with location, by dispatching to Traverse*TypeLoc() based on the argument ty...
bool TraverseNestedNameSpecifierLoc(NestedNameSpecifierLoc NNS)
Recursively visit a C++ nested-name-specifier with location information.
Represents a C++ nested name specifier, such as "\::std::vector<int>::".
void matchAST(ASTContext &Context)
Finds all matches in the given AST.
std::vector< std::pair< NestedNameSpecifierLocMatcher, MatchCallback * > > NestedNameSpecifierLoc
bool TraverseStmt(Stmt *S, DataRecursionQueue *Queue=nullptr)
Recursively visit a statement or expression, by dispatching to Traverse*() based on the argument's dy...
std::vector< std::pair< internal::DynTypedMatcher, MatchCallback * > > DeclOrStmt
bool operator<(DeclarationName LHS, DeclarationName RHS)
Ordering on two declaration names.
bool TraverseType(QualType T)
Recursively visit a type, by dispatching to Traverse*Type() based on the argument's getTypeClass() pr...
static DynTypedNode create(const T &Node)
Creates a DynTypedNode from Node.
std::vector< std::pair< NestedNameSpecifierMatcher, MatchCallback * > > NestedNameSpecifier
std::vector< std::pair< TypeMatcher, MatchCallback * > > Type
BoundNodesTreeBuilder BoundNodes
ast_type_traits::DynTypedNode DynTypedNode
ast_type_traits::DynTypedNode Node
Optional< types::ID > Type
Dataflow Directional Tag Classes.
internal::Matcher< CXXCtorInitializer > CXXCtorInitializerMatcher
A dynamically typed AST node container.
std::vector< std::pair< TypeLocMatcher, MatchCallback * > > TypeLoc
Represents a C++ base or member initializer.
bool TraverseNestedNameSpecifier(NestedNameSpecifier *NNS)
Recursively visit a C++ nested-name-specifier.
internal::Matcher< NestedNameSpecifierLoc > NestedNameSpecifierLocMatcher
internal::Matcher< TypeLoc > TypeLocMatcher
Called when the Match registered for it was successfully found in the AST.
This class handles loading and caching of source files into memory.
internal::Matcher< Decl > DeclarationMatcher
Types of matchers for the top-level classes in the AST class hierarchy.
bool addDynamicMatcher(const internal::DynTypedMatcher &NodeMatch, MatchCallback *Action)
Adds a matcher to execute when running over the AST.