22 #include "llvm/ADT/DenseMap.h" 23 #include "llvm/ADT/StringMap.h" 24 #include "llvm/Support/Timer.h" 34 typedef MatchFinder::MatchCallback MatchCallback;
44 static const unsigned MaxMemoizationEntries = 10000;
63 bool operator<(
const MatchKey &Other)
const {
64 return std::tie(MatcherID, Node, BoundNodes) <
65 std::tie(Other.MatcherID, Other.Node, Other.BoundNodes);
70 struct MemoizedMatchResult {
77 class MatchChildASTVisitor
78 :
public RecursiveASTVisitor<MatchChildASTVisitor> {
80 typedef RecursiveASTVisitor<MatchChildASTVisitor> VisitorBase;
86 MatchChildASTVisitor(
const DynTypedMatcher *Matcher, ASTMatchFinder *Finder,
87 BoundNodesTreeBuilder *Builder,
int MaxDepth,
89 ASTMatchFinder::BindKind Bind)
90 : Matcher(Matcher), Finder(Finder), Builder(Builder), CurrentDepth(0),
91 MaxDepth(MaxDepth), Traversal(Traversal), Bind(Bind), Matches(
false) {}
106 if (
const Decl *D = DynNode.get<Decl>())
108 else if (
const Stmt *S = DynNode.get<Stmt>())
110 else if (
const NestedNameSpecifier *NNS =
111 DynNode.get<NestedNameSpecifier>())
113 else if (
const NestedNameSpecifierLoc *NNSLoc =
114 DynNode.get<NestedNameSpecifierLoc>())
116 else if (
const QualType *Q = DynNode.get<QualType>())
118 else if (
const TypeLoc *T = DynNode.get<TypeLoc>())
120 else if (
const auto *C = DynNode.get<CXXCtorInitializer>())
127 *Builder = ResultBindings;
135 bool TraverseDecl(Decl *DeclNode) {
136 ScopedIncrement ScopedDepth(&CurrentDepth);
137 return (DeclNode ==
nullptr) || traverse(*DeclNode);
139 bool TraverseStmt(Stmt *StmtNode, DataRecursionQueue *Queue =
nullptr) {
141 if (CurrentDepth == 0 || (CurrentDepth <= MaxDepth && MaxDepth <
INT_MAX))
144 ScopedIncrement ScopedDepth(&CurrentDepth);
145 Stmt *StmtToTraverse = StmtNode;
148 if (Expr *ExprNode = dyn_cast_or_null<Expr>(StmtNode))
149 StmtToTraverse = ExprNode->IgnoreParenImpCasts();
153 if (!
match(*StmtToTraverse))
155 return VisitorBase::TraverseStmt(StmtToTraverse, Queue);
159 bool TraverseType(QualType TypeNode) {
160 if (TypeNode.isNull())
162 ScopedIncrement ScopedDepth(&CurrentDepth);
164 if (!
match(*TypeNode))
167 return traverse(TypeNode);
171 bool TraverseTypeLoc(TypeLoc TypeLocNode) {
172 if (TypeLocNode.isNull())
174 ScopedIncrement ScopedDepth(&CurrentDepth);
176 if (!
match(*TypeLocNode.getType()))
179 if (!
match(TypeLocNode.getType()))
182 return traverse(TypeLocNode);
184 bool TraverseNestedNameSpecifier(NestedNameSpecifier *NNS) {
185 ScopedIncrement ScopedDepth(&CurrentDepth);
186 return (NNS ==
nullptr) || traverse(*NNS);
188 bool TraverseNestedNameSpecifierLoc(NestedNameSpecifierLoc NNS) {
191 ScopedIncrement ScopedDepth(&CurrentDepth);
192 if (!
match(*NNS.getNestedNameSpecifier()))
194 return traverse(NNS);
196 bool TraverseConstructorInitializer(CXXCtorInitializer *CtorInit) {
199 ScopedIncrement ScopedDepth(&CurrentDepth);
200 return traverse(*CtorInit);
203 bool shouldVisitTemplateInstantiations()
const {
return true; }
204 bool shouldVisitImplicitCode()
const {
return true; }
208 struct ScopedIncrement {
209 explicit ScopedIncrement(
int *
Depth) :
Depth(Depth) { ++(*Depth); }
210 ~ScopedIncrement() { --(*Depth); }
224 bool baseTraverse(
const Decl &DeclNode) {
225 return VisitorBase::TraverseDecl(const_cast<Decl*>(&DeclNode));
227 bool baseTraverse(
const Stmt &StmtNode) {
228 return VisitorBase::TraverseStmt(const_cast<Stmt*>(&StmtNode));
230 bool baseTraverse(QualType TypeNode) {
231 return VisitorBase::TraverseType(TypeNode);
233 bool baseTraverse(TypeLoc TypeLocNode) {
234 return VisitorBase::TraverseTypeLoc(TypeLocNode);
236 bool baseTraverse(
const NestedNameSpecifier &NNS) {
237 return VisitorBase::TraverseNestedNameSpecifier(
238 const_cast<NestedNameSpecifier*>(&NNS));
240 bool baseTraverse(NestedNameSpecifierLoc NNS) {
241 return VisitorBase::TraverseNestedNameSpecifierLoc(NNS);
243 bool baseTraverse(
const CXXCtorInitializer &CtorInit) {
244 return VisitorBase::TraverseConstructorInitializer(
245 const_cast<CXXCtorInitializer *>(&CtorInit));
253 template <
typename T>
255 if (CurrentDepth == 0 || CurrentDepth > MaxDepth) {
258 if (Bind != ASTMatchFinder::BK_All) {
259 BoundNodesTreeBuilder RecursiveBuilder(*Builder);
261 &RecursiveBuilder)) {
263 ResultBindings.addMatch(RecursiveBuilder);
267 BoundNodesTreeBuilder RecursiveBuilder(*Builder);
269 &RecursiveBuilder)) {
272 ResultBindings.addMatch(RecursiveBuilder);
280 template <
typename T>
281 bool traverse(
const T &Node) {
282 static_assert(IsBaseType<T>::value,
283 "traverse can only be instantiated with base type");
286 return baseTraverse(Node);
289 const DynTypedMatcher *
const Matcher;
290 ASTMatchFinder *
const Finder;
291 BoundNodesTreeBuilder *
const Builder;
292 BoundNodesTreeBuilder ResultBindings;
296 const ASTMatchFinder::BindKind Bind;
302 class MatchASTVisitor :
public RecursiveASTVisitor<MatchASTVisitor>,
303 public ASTMatchFinder {
305 MatchASTVisitor(
const MatchFinder::MatchersByType *Matchers,
306 const MatchFinder::MatchFinderOptions &Options)
307 : Matchers(Matchers), Options(Options), ActiveASTContext(
nullptr) {}
309 ~MatchASTVisitor()
override {
310 if (Options.CheckProfiling) {
311 Options.CheckProfiling->Records = std::move(TimeByBucket);
315 void onStartOfTranslationUnit() {
316 const bool EnableCheckProfiling = Options.CheckProfiling.hasValue();
317 TimeBucketRegion Timer;
318 for (MatchCallback *MC : Matchers->AllCallbacks) {
319 if (EnableCheckProfiling)
320 Timer.setBucket(&TimeByBucket[MC->getID()]);
321 MC->onStartOfTranslationUnit();
325 void onEndOfTranslationUnit() {
326 const bool EnableCheckProfiling = Options.CheckProfiling.hasValue();
327 TimeBucketRegion Timer;
328 for (MatchCallback *MC : Matchers->AllCallbacks) {
329 if (EnableCheckProfiling)
330 Timer.setBucket(&TimeByBucket[MC->getID()]);
331 MC->onEndOfTranslationUnit();
335 void set_active_ast_context(ASTContext *NewActiveASTContext) {
336 ActiveASTContext = NewActiveASTContext;
342 bool VisitTypedefNameDecl(TypedefNameDecl *DeclNode) {
370 const Type *TypeNode = DeclNode->getUnderlyingType().getTypePtr();
371 const Type *CanonicalType =
372 ActiveASTContext->getCanonicalType(TypeNode);
373 TypeAliases[CanonicalType].insert(DeclNode);
377 bool TraverseDecl(Decl *DeclNode);
378 bool TraverseStmt(Stmt *StmtNode, DataRecursionQueue *Queue =
nullptr);
379 bool TraverseType(QualType TypeNode);
380 bool TraverseTypeLoc(TypeLoc TypeNode);
381 bool TraverseNestedNameSpecifier(NestedNameSpecifier *NNS);
382 bool TraverseNestedNameSpecifierLoc(NestedNameSpecifierLoc NNS);
383 bool TraverseConstructorInitializer(CXXCtorInitializer *CtorInit);
387 const DynTypedMatcher &Matcher,
388 BoundNodesTreeBuilder *Builder,
int MaxDepth,
392 if (!Node.getMemoizationData() || !Builder->isComparable())
393 return matchesRecursively(Node, Matcher, Builder, MaxDepth, Traversal,
397 Key.MatcherID = Matcher.getID();
400 Key.BoundNodes = *Builder;
402 MemoizationMap::iterator I = ResultCache.find(Key);
403 if (I != ResultCache.end()) {
404 *Builder = I->second.Nodes;
405 return I->second.ResultOfMatch;
408 MemoizedMatchResult Result;
409 Result.Nodes = *Builder;
410 Result.ResultOfMatch = matchesRecursively(Node, Matcher, &Result.Nodes,
411 MaxDepth, Traversal, Bind);
413 MemoizedMatchResult &CachedResult = ResultCache[Key];
414 CachedResult = std::move(Result);
416 *Builder = CachedResult.Nodes;
417 return CachedResult.ResultOfMatch;
422 const DynTypedMatcher &Matcher,
423 BoundNodesTreeBuilder *Builder,
int MaxDepth,
426 MatchChildASTVisitor Visitor(
427 &Matcher,
this, Builder, MaxDepth, Traversal, Bind);
428 return Visitor.findMatch(Node);
431 bool classIsDerivedFrom(
const CXXRecordDecl *Declaration,
432 const Matcher<NamedDecl> &
Base,
433 BoundNodesTreeBuilder *Builder)
override;
437 const DynTypedMatcher &Matcher,
438 BoundNodesTreeBuilder *Builder,
440 BindKind Bind)
override {
441 if (ResultCache.size() > MaxMemoizationEntries)
443 return memoizedMatchesRecursively(Node, Matcher, Builder, 1, Traversal,
448 const DynTypedMatcher &Matcher,
449 BoundNodesTreeBuilder *Builder,
450 BindKind Bind)
override {
451 if (ResultCache.size() > MaxMemoizationEntries)
453 return memoizedMatchesRecursively(Node, Matcher, Builder,
INT_MAX,
459 const DynTypedMatcher &Matcher,
460 BoundNodesTreeBuilder *Builder,
461 AncestorMatchMode MatchMode)
override {
464 if (ResultCache.size() > MaxMemoizationEntries)
466 return memoizedMatchesAncestorOfRecursively(Node, Matcher, Builder,
474 if (
auto *N = Node.get<Decl>()) {
476 }
else if (
auto *N = Node.get<Stmt>()) {
478 }
else if (
auto *N = Node.get<
Type>()) {
480 }
else if (
auto *N = Node.get<QualType>()) {
482 }
else if (
auto *N = Node.get<NestedNameSpecifier>()) {
484 }
else if (
auto *N = Node.get<NestedNameSpecifierLoc>()) {
486 }
else if (
auto *N = Node.get<TypeLoc>()) {
488 }
else if (
auto *N = Node.get<CXXCtorInitializer>()) {
493 template <
typename T>
void match(
const T &Node) {
494 matchDispatch(&Node);
498 ASTContext &getASTContext()
const override {
return *ActiveASTContext; }
500 bool shouldVisitTemplateInstantiations()
const {
return true; }
501 bool shouldVisitImplicitCode()
const {
return true; }
504 class TimeBucketRegion {
506 TimeBucketRegion() : Bucket(
nullptr) {}
507 ~TimeBucketRegion() { setBucket(
nullptr); }
517 void setBucket(llvm::TimeRecord *NewBucket) {
518 if (Bucket != NewBucket) {
519 auto Now = llvm::TimeRecord::getCurrentTime(
true);
529 llvm::TimeRecord *Bucket;
535 template <
typename T,
typename MC>
536 void matchWithoutFilter(
const T &Node,
const MC &Matchers) {
537 const bool EnableCheckProfiling = Options.CheckProfiling.hasValue();
538 TimeBucketRegion Timer;
539 for (
const auto &MP : Matchers) {
540 if (EnableCheckProfiling)
541 Timer.setBucket(&TimeByBucket[MP.second->getID()]);
542 BoundNodesTreeBuilder Builder;
543 if (MP.first.matches(Node,
this, &Builder)) {
544 MatchVisitor Visitor(ActiveASTContext, MP.second);
545 Builder.visitMatches(&Visitor);
551 auto Kind = DynNode.getNodeKind();
552 auto it = MatcherFiltersMap.find(
Kind);
554 it != MatcherFiltersMap.end() ? it->second : getFilterForKind(
Kind);
559 const bool EnableCheckProfiling = Options.CheckProfiling.hasValue();
560 TimeBucketRegion Timer;
561 auto &Matchers = this->Matchers->DeclOrStmt;
562 for (
unsigned short I :
Filter) {
563 auto &MP = Matchers[I];
564 if (EnableCheckProfiling)
565 Timer.setBucket(&TimeByBucket[MP.second->getID()]);
566 BoundNodesTreeBuilder Builder;
567 if (MP.first.matchesNoKindCheck(DynNode,
this, &Builder)) {
568 MatchVisitor Visitor(ActiveASTContext, MP.second);
569 Builder.visitMatches(&Visitor);
574 const std::vector<unsigned short> &
575 getFilterForKind(ast_type_traits::ASTNodeKind
Kind) {
577 auto &Matchers = this->Matchers->DeclOrStmt;
578 assert((Matchers.size() <
USHRT_MAX) &&
"Too many matchers.");
579 for (
unsigned I = 0, E = Matchers.size(); I != E; ++I) {
580 if (Matchers[I].first.canMatchNodesOfKind(Kind)) {
589 void matchDispatch(
const Decl *Node) {
592 void matchDispatch(
const Stmt *Node) {
596 void matchDispatch(
const Type *Node) {
597 matchWithoutFilter(QualType(Node, 0), Matchers->Type);
599 void matchDispatch(
const TypeLoc *Node) {
600 matchWithoutFilter(*Node, Matchers->TypeLoc);
602 void matchDispatch(
const QualType *Node) {
603 matchWithoutFilter(*Node, Matchers->Type);
605 void matchDispatch(
const NestedNameSpecifier *Node) {
606 matchWithoutFilter(*Node, Matchers->NestedNameSpecifier);
608 void matchDispatch(
const NestedNameSpecifierLoc *Node) {
609 matchWithoutFilter(*Node, Matchers->NestedNameSpecifierLoc);
611 void matchDispatch(
const CXXCtorInitializer *Node) {
612 matchWithoutFilter(*Node, Matchers->CtorInit);
614 void matchDispatch(
const void *) { }
630 bool memoizedMatchesAncestorOfRecursively(
632 BoundNodesTreeBuilder *Builder, AncestorMatchMode MatchMode) {
634 if (!Builder->isComparable())
635 return matchesAncestorOfRecursively(Node, Matcher, Builder, MatchMode);
638 Key.MatcherID = Matcher.getID();
640 Key.BoundNodes = *Builder;
644 MemoizationMap::iterator I = ResultCache.find(Key);
645 if (I != ResultCache.end()) {
646 *Builder = I->second.Nodes;
647 return I->second.ResultOfMatch;
650 MemoizedMatchResult Result;
651 Result.Nodes = *Builder;
652 Result.ResultOfMatch =
653 matchesAncestorOfRecursively(Node, Matcher, &Result.Nodes, MatchMode);
655 MemoizedMatchResult &CachedResult = ResultCache[Key];
656 CachedResult = std::move(Result);
658 *Builder = CachedResult.Nodes;
659 return CachedResult.ResultOfMatch;
663 const DynTypedMatcher &Matcher,
664 BoundNodesTreeBuilder *Builder,
665 AncestorMatchMode MatchMode) {
666 const auto &Parents = ActiveASTContext->getParents(Node);
667 if (Parents.empty()) {
675 if (!Node.get<TranslationUnitDecl>() &&
677 llvm::any_of(ActiveASTContext->getTraversalScope(), [](Decl *D) {
678 return D->getKind() == Decl::TranslationUnit;
680 llvm::errs() <<
"Tried to match orphan node:\n";
681 Node.dump(llvm::errs(), ActiveASTContext->getSourceManager());
682 llvm_unreachable(
"Parent map should be complete!");
687 if (Parents.size() == 1) {
690 BoundNodesTreeBuilder BuilderCopy = *Builder;
691 if (Matcher.matches(Parent,
this, &BuilderCopy)) {
692 *Builder = std::move(BuilderCopy);
695 if (MatchMode != ASTMatchFinder::AMM_ParentOnly) {
696 return memoizedMatchesAncestorOfRecursively(Parent, Matcher, Builder,
704 std::deque<ast_type_traits::DynTypedNode> Queue(Parents.begin(),
706 while (!Queue.empty()) {
707 BoundNodesTreeBuilder BuilderCopy = *Builder;
708 if (Matcher.matches(Queue.front(),
this, &BuilderCopy)) {
709 *Builder = std::move(BuilderCopy);
712 if (MatchMode != ASTMatchFinder::AMM_ParentOnly) {
714 ActiveASTContext->getParents(Queue.front())) {
718 if (Visited.insert(
Parent.getMemoizationData()).second)
730 class MatchVisitor :
public BoundNodesTreeBuilder::Visitor {
732 MatchVisitor(ASTContext* Context,
733 MatchFinder::MatchCallback* Callback)
735 Callback(Callback) {}
737 void visitMatch(
const BoundNodes& BoundNodesView)
override {
743 MatchFinder::MatchCallback* Callback;
747 bool typeHasMatchingAlias(
const Type *TypeNode,
748 const Matcher<NamedDecl> &Matcher,
749 BoundNodesTreeBuilder *Builder) {
750 const Type *
const CanonicalType =
751 ActiveASTContext->getCanonicalType(TypeNode);
752 auto Aliases = TypeAliases.find(CanonicalType);
753 if (Aliases == TypeAliases.end())
755 for (
const TypedefNameDecl *Alias : Aliases->second) {
756 BoundNodesTreeBuilder Result(*Builder);
757 if (Matcher.matches(*Alias,
this, &Result)) {
758 *Builder = std::move(Result);
768 llvm::StringMap<llvm::TimeRecord> TimeByBucket;
770 const MatchFinder::MatchersByType *Matchers;
780 llvm::DenseMap<ast_type_traits::ASTNodeKind, std::vector<unsigned short>>
783 const MatchFinder::MatchFinderOptions &Options;
784 ASTContext *ActiveASTContext;
787 llvm::DenseMap<const Type*, std::set<const TypedefNameDecl*> > TypeAliases;
790 typedef std::map<MatchKey, MemoizedMatchResult> MemoizationMap;
791 MemoizationMap ResultCache;
794 static CXXRecordDecl *
795 getAsCXXRecordDeclOrPrimaryTemplate(
const Type *TypeNode) {
796 if (
auto *RD = TypeNode->getAsCXXRecordDecl())
800 auto *TemplateType = TypeNode->getAs<TemplateSpecializationType>();
801 while (TemplateType && TemplateType->isTypeAlias())
803 TemplateType->getAliasedType()->getAs<TemplateSpecializationType>();
808 if (
auto *ClassTemplate = dyn_cast_or_null<ClassTemplateDecl>(
809 TemplateType->getTemplateName().getAsTemplateDecl()))
810 return ClassTemplate->getTemplatedDecl();
818 bool MatchASTVisitor::classIsDerivedFrom(
const CXXRecordDecl *Declaration,
819 const Matcher<NamedDecl> &
Base,
820 BoundNodesTreeBuilder *Builder) {
821 if (!Declaration->hasDefinition())
823 for (
const auto &It : Declaration->bases()) {
824 const Type *TypeNode = It.getType().getTypePtr();
826 if (typeHasMatchingAlias(TypeNode, Base, Builder))
832 CXXRecordDecl *ClassDecl = getAsCXXRecordDeclOrPrimaryTemplate(TypeNode);
835 if (ClassDecl == Declaration) {
840 BoundNodesTreeBuilder Result(*Builder);
841 if (Base.matches(*ClassDecl,
this, &Result)) {
842 *Builder = std::move(Result);
845 if (classIsDerivedFrom(ClassDecl, Base, Builder))
851 bool MatchASTVisitor::TraverseDecl(Decl *DeclNode) {
859 bool MatchASTVisitor::TraverseStmt(Stmt *StmtNode, DataRecursionQueue *Queue) {
867 bool MatchASTVisitor::TraverseType(QualType TypeNode) {
872 bool MatchASTVisitor::TraverseTypeLoc(TypeLoc TypeLocNode) {
879 match(TypeLocNode.getType());
883 bool MatchASTVisitor::TraverseNestedNameSpecifier(NestedNameSpecifier *NNS) {
888 bool MatchASTVisitor::TraverseNestedNameSpecifierLoc(
889 NestedNameSpecifierLoc NNS) {
897 if (NNS.hasQualifier())
898 match(*NNS.getNestedNameSpecifier());
903 bool MatchASTVisitor::TraverseConstructorInitializer(
904 CXXCtorInitializer *CtorInit) {
914 class MatchASTConsumer :
public ASTConsumer {
916 MatchASTConsumer(MatchFinder *Finder,
917 MatchFinder::ParsingDoneTestCallback *ParsingDone)
918 : Finder(Finder), ParsingDone(ParsingDone) {}
921 void HandleTranslationUnit(ASTContext &Context)
override {
922 if (ParsingDone !=
nullptr) {
925 Finder->matchAST(Context);
929 MatchFinder::ParsingDoneTestCallback *ParsingDone;
937 : Nodes(Nodes), Context(Context),
944 : Options(
std::move(Options)), ParsingDone(nullptr) {}
950 Matchers.
DeclOrStmt.emplace_back(NodeMatch, Action);
956 Matchers.
Type.emplace_back(NodeMatch, Action);
962 Matchers.
DeclOrStmt.emplace_back(NodeMatch, Action);
980 Matchers.
TypeLoc.emplace_back(NodeMatch, Action);
986 Matchers.
CtorInit.emplace_back(NodeMatch, Action);
992 if (NodeMatch.canConvertTo<
Decl>()) {
995 }
else if (NodeMatch.canConvertTo<
QualType>()) {
998 }
else if (NodeMatch.canConvertTo<
Stmt>()) {
1007 }
else if (NodeMatch.canConvertTo<
TypeLoc>()) {
1018 return llvm::make_unique<internal::MatchASTConsumer>(
this, ParsingDone);
1023 internal::MatchASTVisitor Visitor(&Matchers, Options);
1024 Visitor.set_active_ast_context(&Context);
1025 Visitor.match(Node);
1029 internal::MatchASTVisitor Visitor(&Matchers, Options);
1030 Visitor.set_active_ast_context(&Context);
1031 Visitor.onStartOfTranslationUnit();
1032 Visitor.TraverseAST(Context);
1033 Visitor.onEndOfTranslationUnit();
1038 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.
MatchFinder::MatchResult MatchResult
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.
Will traverse all child nodes.
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.
Will not traverse implicit casts and parentheses.
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.
TraversalKind
Defines how we descend a level in the AST when we pass through expressions.
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.