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) {
581 auto &Filter = MatcherFiltersMap[
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) {
638 if (Node.get<TranslationUnitDecl>() ==
639 ActiveASTContext->getTranslationUnitDecl())
643 if (!Builder->isComparable())
644 return matchesAncestorOfRecursively(Node, Matcher, Builder, MatchMode);
647 Key.MatcherID = Matcher.getID();
649 Key.BoundNodes = *Builder;
653 MemoizationMap::iterator I = ResultCache.find(Key);
654 if (I != ResultCache.end()) {
655 *Builder = I->second.Nodes;
656 return I->second.ResultOfMatch;
659 MemoizedMatchResult Result;
660 Result.Nodes = *Builder;
661 Result.ResultOfMatch =
662 matchesAncestorOfRecursively(Node, Matcher, &Result.Nodes, MatchMode);
664 MemoizedMatchResult &CachedResult = ResultCache[Key];
665 CachedResult = std::move(Result);
667 *Builder = CachedResult.Nodes;
668 return CachedResult.ResultOfMatch;
672 const DynTypedMatcher &Matcher,
673 BoundNodesTreeBuilder *Builder,
674 AncestorMatchMode MatchMode) {
675 const auto &Parents = ActiveASTContext->getParents(Node);
676 assert(!Parents.empty() &&
"Found node that is not in the parent map.");
677 if (Parents.size() == 1) {
680 BoundNodesTreeBuilder BuilderCopy = *Builder;
681 if (Matcher.matches(Parent,
this, &BuilderCopy)) {
682 *Builder = std::move(BuilderCopy);
685 if (MatchMode != ASTMatchFinder::AMM_ParentOnly) {
686 return memoizedMatchesAncestorOfRecursively(Parent, Matcher, Builder,
694 std::deque<ast_type_traits::DynTypedNode> Queue(Parents.begin(),
696 while (!Queue.empty()) {
697 BoundNodesTreeBuilder BuilderCopy = *Builder;
698 if (Matcher.matches(Queue.front(),
this, &BuilderCopy)) {
699 *Builder = std::move(BuilderCopy);
702 if (MatchMode != ASTMatchFinder::AMM_ParentOnly) {
704 ActiveASTContext->getParents(Queue.front())) {
708 if (Visited.insert(
Parent.getMemoizationData()).second)
720 class MatchVisitor :
public BoundNodesTreeBuilder::Visitor {
722 MatchVisitor(ASTContext* Context,
723 MatchFinder::MatchCallback* Callback)
725 Callback(Callback) {}
727 void visitMatch(
const BoundNodes& BoundNodesView)
override {
728 Callback->run(MatchFinder::MatchResult(BoundNodesView, Context));
733 MatchFinder::MatchCallback* Callback;
737 bool typeHasMatchingAlias(
const Type *TypeNode,
738 const Matcher<NamedDecl> &Matcher,
739 BoundNodesTreeBuilder *Builder) {
740 const Type *
const CanonicalType =
741 ActiveASTContext->getCanonicalType(TypeNode);
742 auto Aliases = TypeAliases.find(CanonicalType);
743 if (Aliases == TypeAliases.end())
745 for (
const TypedefNameDecl *Alias : Aliases->second) {
746 BoundNodesTreeBuilder Result(*Builder);
747 if (Matcher.matches(*Alias,
this, &Result)) {
748 *Builder = std::move(Result);
758 llvm::StringMap<llvm::TimeRecord> TimeByBucket;
760 const MatchFinder::MatchersByType *Matchers;
770 llvm::DenseMap<ast_type_traits::ASTNodeKind, std::vector<unsigned short>>
773 const MatchFinder::MatchFinderOptions &Options;
774 ASTContext *ActiveASTContext;
777 llvm::DenseMap<const Type*, std::set<const TypedefNameDecl*> > TypeAliases;
780 typedef std::map<MatchKey, MemoizedMatchResult> MemoizationMap;
781 MemoizationMap ResultCache;
784 static CXXRecordDecl *
785 getAsCXXRecordDeclOrPrimaryTemplate(
const Type *TypeNode) {
786 if (
auto *RD = TypeNode->getAsCXXRecordDecl())
790 auto *TemplateType = TypeNode->getAs<TemplateSpecializationType>();
791 while (TemplateType && TemplateType->isTypeAlias())
793 TemplateType->getAliasedType()->getAs<TemplateSpecializationType>();
798 if (
auto *ClassTemplate = dyn_cast_or_null<ClassTemplateDecl>(
799 TemplateType->getTemplateName().getAsTemplateDecl()))
800 return ClassTemplate->getTemplatedDecl();
808 bool MatchASTVisitor::classIsDerivedFrom(
const CXXRecordDecl *Declaration,
809 const Matcher<NamedDecl> &
Base,
810 BoundNodesTreeBuilder *Builder) {
811 if (!Declaration->hasDefinition())
813 for (
const auto &It : Declaration->bases()) {
814 const Type *TypeNode = It.getType().getTypePtr();
816 if (typeHasMatchingAlias(TypeNode, Base, Builder))
822 CXXRecordDecl *ClassDecl = getAsCXXRecordDeclOrPrimaryTemplate(TypeNode);
825 if (ClassDecl == Declaration) {
830 BoundNodesTreeBuilder Result(*Builder);
831 if (Base.matches(*ClassDecl,
this, &Result)) {
832 *Builder = std::move(Result);
835 if (classIsDerivedFrom(ClassDecl, Base, Builder))
841 bool MatchASTVisitor::TraverseDecl(Decl *DeclNode) {
849 bool MatchASTVisitor::TraverseStmt(Stmt *StmtNode, DataRecursionQueue *Queue) {
857 bool MatchASTVisitor::TraverseType(QualType TypeNode) {
862 bool MatchASTVisitor::TraverseTypeLoc(TypeLoc TypeLocNode) {
869 match(TypeLocNode.getType());
873 bool MatchASTVisitor::TraverseNestedNameSpecifier(NestedNameSpecifier *NNS) {
878 bool MatchASTVisitor::TraverseNestedNameSpecifierLoc(
879 NestedNameSpecifierLoc NNS) {
887 if (NNS.hasQualifier())
888 match(*NNS.getNestedNameSpecifier());
893 bool MatchASTVisitor::TraverseConstructorInitializer(
894 CXXCtorInitializer *CtorInit) {
904 class MatchASTConsumer :
public ASTConsumer {
906 MatchASTConsumer(MatchFinder *Finder,
907 MatchFinder::ParsingDoneTestCallback *ParsingDone)
908 : Finder(Finder), ParsingDone(ParsingDone) {}
911 void HandleTranslationUnit(ASTContext &Context)
override {
912 if (ParsingDone !=
nullptr) {
915 Finder->matchAST(Context);
919 MatchFinder::ParsingDoneTestCallback *ParsingDone;
927 : Nodes(Nodes), Context(Context),
934 : Options(
std::move(Options)), ParsingDone(nullptr) {}
940 Matchers.
DeclOrStmt.emplace_back(NodeMatch, Action);
946 Matchers.
Type.emplace_back(NodeMatch, Action);
952 Matchers.
DeclOrStmt.emplace_back(NodeMatch, Action);
970 Matchers.
TypeLoc.emplace_back(NodeMatch, Action);
976 Matchers.
CtorInit.emplace_back(NodeMatch, Action);
982 if (NodeMatch.canConvertTo<
Decl>()) {
985 }
else if (NodeMatch.canConvertTo<
QualType>()) {
988 }
else if (NodeMatch.canConvertTo<
Stmt>()) {
997 }
else if (NodeMatch.canConvertTo<
TypeLoc>()) {
1008 return llvm::make_unique<internal::MatchASTConsumer>(
this, ParsingDone);
1013 internal::MatchASTVisitor Visitor(&Matchers, Options);
1014 Visitor.set_active_ast_context(&Context);
1015 Visitor.match(Node);
1019 internal::MatchASTVisitor Visitor(&Matchers, Options);
1020 Visitor.set_active_ast_context(&Context);
1021 Visitor.onStartOfTranslationUnit();
1023 Visitor.onEndOfTranslationUnit();
1028 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
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.
TranslationUnitDecl * getTranslationUnitDecl() const
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.