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) {
149 ScopedIncrement ScopedDepth(&CurrentDepth);
150 const Stmt *StmtToTraverse = StmtNode;
152 ASTMatchFinder::TK_IgnoreImplicitCastsAndParentheses) {
153 const Expr *ExprNode = dyn_cast_or_null<Expr>(StmtNode);
155 StmtToTraverse = ExprNode->IgnoreParenImpCasts();
158 return (StmtToTraverse ==
nullptr) || traverse(*StmtToTraverse);
162 bool TraverseType(QualType TypeNode) {
163 if (TypeNode.isNull())
165 ScopedIncrement ScopedDepth(&CurrentDepth);
167 if (!
match(*TypeNode))
170 return traverse(TypeNode);
174 bool TraverseTypeLoc(TypeLoc TypeLocNode) {
175 if (TypeLocNode.isNull())
177 ScopedIncrement ScopedDepth(&CurrentDepth);
179 if (!
match(*TypeLocNode.getType()))
182 if (!
match(TypeLocNode.getType()))
185 return traverse(TypeLocNode);
187 bool TraverseNestedNameSpecifier(NestedNameSpecifier *NNS) {
188 ScopedIncrement ScopedDepth(&CurrentDepth);
189 return (NNS ==
nullptr) || traverse(*NNS);
191 bool TraverseNestedNameSpecifierLoc(NestedNameSpecifierLoc NNS) {
194 ScopedIncrement ScopedDepth(&CurrentDepth);
195 if (!
match(*NNS.getNestedNameSpecifier()))
197 return traverse(NNS);
199 bool TraverseConstructorInitializer(CXXCtorInitializer *CtorInit) {
202 ScopedIncrement ScopedDepth(&CurrentDepth);
203 return traverse(*CtorInit);
206 bool shouldVisitTemplateInstantiations()
const {
return true; }
207 bool shouldVisitImplicitCode()
const {
return true; }
211 struct ScopedIncrement {
212 explicit ScopedIncrement(
int *
Depth) :
Depth(Depth) { ++(*Depth); }
213 ~ScopedIncrement() { --(*Depth); }
227 bool baseTraverse(
const Decl &DeclNode) {
228 return VisitorBase::TraverseDecl(const_cast<Decl*>(&DeclNode));
230 bool baseTraverse(
const Stmt &StmtNode) {
231 return VisitorBase::TraverseStmt(const_cast<Stmt*>(&StmtNode));
233 bool baseTraverse(QualType TypeNode) {
234 return VisitorBase::TraverseType(TypeNode);
236 bool baseTraverse(TypeLoc TypeLocNode) {
237 return VisitorBase::TraverseTypeLoc(TypeLocNode);
239 bool baseTraverse(
const NestedNameSpecifier &NNS) {
240 return VisitorBase::TraverseNestedNameSpecifier(
241 const_cast<NestedNameSpecifier*>(&NNS));
243 bool baseTraverse(NestedNameSpecifierLoc NNS) {
244 return VisitorBase::TraverseNestedNameSpecifierLoc(NNS);
246 bool baseTraverse(
const CXXCtorInitializer &CtorInit) {
247 return VisitorBase::TraverseConstructorInitializer(
248 const_cast<CXXCtorInitializer *>(&CtorInit));
256 template <
typename T>
258 if (CurrentDepth == 0 || CurrentDepth > MaxDepth) {
261 if (Bind != ASTMatchFinder::BK_All) {
262 BoundNodesTreeBuilder RecursiveBuilder(*Builder);
264 &RecursiveBuilder)) {
266 ResultBindings.addMatch(RecursiveBuilder);
270 BoundNodesTreeBuilder RecursiveBuilder(*Builder);
272 &RecursiveBuilder)) {
275 ResultBindings.addMatch(RecursiveBuilder);
283 template <
typename T>
284 bool traverse(
const T &Node) {
285 static_assert(IsBaseType<T>::value,
286 "traverse can only be instantiated with base type");
289 return baseTraverse(Node);
292 const DynTypedMatcher *
const Matcher;
293 ASTMatchFinder *
const Finder;
294 BoundNodesTreeBuilder *
const Builder;
295 BoundNodesTreeBuilder ResultBindings;
298 const ASTMatchFinder::TraversalKind Traversal;
299 const ASTMatchFinder::BindKind Bind;
305 class MatchASTVisitor :
public RecursiveASTVisitor<MatchASTVisitor>,
306 public ASTMatchFinder {
308 MatchASTVisitor(
const MatchFinder::MatchersByType *Matchers,
309 const MatchFinder::MatchFinderOptions &Options)
310 : Matchers(Matchers), Options(Options), ActiveASTContext(
nullptr) {}
312 ~MatchASTVisitor()
override {
313 if (Options.CheckProfiling) {
314 Options.CheckProfiling->Records = std::move(TimeByBucket);
318 void onStartOfTranslationUnit() {
319 const bool EnableCheckProfiling = Options.CheckProfiling.hasValue();
320 TimeBucketRegion Timer;
321 for (MatchCallback *MC : Matchers->AllCallbacks) {
322 if (EnableCheckProfiling)
323 Timer.setBucket(&TimeByBucket[MC->getID()]);
324 MC->onStartOfTranslationUnit();
328 void onEndOfTranslationUnit() {
329 const bool EnableCheckProfiling = Options.CheckProfiling.hasValue();
330 TimeBucketRegion Timer;
331 for (MatchCallback *MC : Matchers->AllCallbacks) {
332 if (EnableCheckProfiling)
333 Timer.setBucket(&TimeByBucket[MC->getID()]);
334 MC->onEndOfTranslationUnit();
338 void set_active_ast_context(ASTContext *NewActiveASTContext) {
339 ActiveASTContext = NewActiveASTContext;
345 bool VisitTypedefNameDecl(TypedefNameDecl *DeclNode) {
373 const Type *TypeNode = DeclNode->getUnderlyingType().getTypePtr();
374 const Type *CanonicalType =
375 ActiveASTContext->getCanonicalType(TypeNode);
376 TypeAliases[CanonicalType].insert(DeclNode);
380 bool TraverseDecl(Decl *DeclNode);
381 bool TraverseStmt(Stmt *StmtNode);
382 bool TraverseType(QualType TypeNode);
383 bool TraverseTypeLoc(TypeLoc TypeNode);
384 bool TraverseNestedNameSpecifier(NestedNameSpecifier *NNS);
385 bool TraverseNestedNameSpecifierLoc(NestedNameSpecifierLoc NNS);
386 bool TraverseConstructorInitializer(CXXCtorInitializer *CtorInit);
390 const DynTypedMatcher &Matcher,
391 BoundNodesTreeBuilder *Builder,
int MaxDepth,
392 TraversalKind Traversal, BindKind Bind) {
394 if (!Node.getMemoizationData() || !Builder->isComparable())
395 return matchesRecursively(Node, Matcher, Builder, MaxDepth, Traversal,
399 Key.MatcherID = Matcher.getID();
402 Key.BoundNodes = *Builder;
404 MemoizationMap::iterator I = ResultCache.find(Key);
405 if (I != ResultCache.end()) {
406 *Builder = I->second.Nodes;
407 return I->second.ResultOfMatch;
410 MemoizedMatchResult Result;
411 Result.Nodes = *Builder;
412 Result.ResultOfMatch = matchesRecursively(Node, Matcher, &Result.Nodes,
413 MaxDepth, Traversal, Bind);
415 MemoizedMatchResult &CachedResult = ResultCache[Key];
416 CachedResult = std::move(Result);
418 *Builder = CachedResult.Nodes;
419 return CachedResult.ResultOfMatch;
424 const DynTypedMatcher &Matcher,
425 BoundNodesTreeBuilder *Builder,
int MaxDepth,
426 TraversalKind Traversal, BindKind Bind) {
427 MatchChildASTVisitor Visitor(
428 &Matcher,
this, Builder, MaxDepth, Traversal, Bind);
429 return Visitor.findMatch(Node);
432 bool classIsDerivedFrom(
const CXXRecordDecl *Declaration,
433 const Matcher<NamedDecl> &
Base,
434 BoundNodesTreeBuilder *Builder)
override;
438 const DynTypedMatcher &Matcher,
439 BoundNodesTreeBuilder *Builder,
440 TraversalKind Traversal,
441 BindKind Bind)
override {
442 if (ResultCache.size() > MaxMemoizationEntries)
444 return memoizedMatchesRecursively(Node, Matcher, Builder, 1, Traversal,
449 const DynTypedMatcher &Matcher,
450 BoundNodesTreeBuilder *Builder,
451 BindKind Bind)
override {
452 if (ResultCache.size() > MaxMemoizationEntries)
454 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) {
576 auto &Filter = MatcherFiltersMap[
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) {
633 if (Node.get<TranslationUnitDecl>() ==
634 ActiveASTContext->getTranslationUnitDecl())
638 if (!Builder->isComparable())
639 return matchesAncestorOfRecursively(Node, Matcher, Builder, MatchMode);
642 Key.MatcherID = Matcher.getID();
644 Key.BoundNodes = *Builder;
648 MemoizationMap::iterator I = ResultCache.find(Key);
649 if (I != ResultCache.end()) {
650 *Builder = I->second.Nodes;
651 return I->second.ResultOfMatch;
654 MemoizedMatchResult Result;
655 Result.Nodes = *Builder;
656 Result.ResultOfMatch =
657 matchesAncestorOfRecursively(Node, Matcher, &Result.Nodes, MatchMode);
659 MemoizedMatchResult &CachedResult = ResultCache[Key];
660 CachedResult = std::move(Result);
662 *Builder = CachedResult.Nodes;
663 return CachedResult.ResultOfMatch;
667 const DynTypedMatcher &Matcher,
668 BoundNodesTreeBuilder *Builder,
669 AncestorMatchMode MatchMode) {
670 const auto &Parents = ActiveASTContext->getParents(Node);
671 assert(!Parents.empty() &&
"Found node that is not in the parent map.");
672 if (Parents.size() == 1) {
675 BoundNodesTreeBuilder BuilderCopy = *Builder;
676 if (Matcher.matches(Parent,
this, &BuilderCopy)) {
677 *Builder = std::move(BuilderCopy);
680 if (MatchMode != ASTMatchFinder::AMM_ParentOnly) {
681 return memoizedMatchesAncestorOfRecursively(Parent, Matcher, Builder,
689 std::deque<ast_type_traits::DynTypedNode> Queue(Parents.begin(),
691 while (!Queue.empty()) {
692 BoundNodesTreeBuilder BuilderCopy = *Builder;
693 if (Matcher.matches(Queue.front(),
this, &BuilderCopy)) {
694 *Builder = std::move(BuilderCopy);
697 if (MatchMode != ASTMatchFinder::AMM_ParentOnly) {
699 ActiveASTContext->getParents(Queue.front())) {
703 if (Visited.insert(
Parent.getMemoizationData()).second)
715 class MatchVisitor :
public BoundNodesTreeBuilder::Visitor {
717 MatchVisitor(ASTContext* Context,
718 MatchFinder::MatchCallback* Callback)
720 Callback(Callback) {}
722 void visitMatch(
const BoundNodes& BoundNodesView)
override {
723 Callback->run(MatchFinder::MatchResult(BoundNodesView, Context));
728 MatchFinder::MatchCallback* Callback;
732 bool typeHasMatchingAlias(
const Type *TypeNode,
733 const Matcher<NamedDecl> &Matcher,
734 BoundNodesTreeBuilder *Builder) {
735 const Type *
const CanonicalType =
736 ActiveASTContext->getCanonicalType(TypeNode);
737 auto Aliases = TypeAliases.find(CanonicalType);
738 if (Aliases == TypeAliases.end())
740 for (
const TypedefNameDecl *Alias : Aliases->second) {
741 BoundNodesTreeBuilder Result(*Builder);
742 if (Matcher.matches(*Alias,
this, &Result)) {
743 *Builder = std::move(Result);
753 llvm::StringMap<llvm::TimeRecord> TimeByBucket;
755 const MatchFinder::MatchersByType *Matchers;
765 llvm::DenseMap<ast_type_traits::ASTNodeKind, std::vector<unsigned short>>
768 const MatchFinder::MatchFinderOptions &Options;
769 ASTContext *ActiveASTContext;
772 llvm::DenseMap<const Type*, std::set<const TypedefNameDecl*> > TypeAliases;
775 typedef std::map<MatchKey, MemoizedMatchResult> MemoizationMap;
776 MemoizationMap ResultCache;
779 static CXXRecordDecl *
780 getAsCXXRecordDeclOrPrimaryTemplate(
const Type *TypeNode) {
781 if (
auto *RD = TypeNode->getAsCXXRecordDecl())
785 auto *TemplateType = TypeNode->getAs<TemplateSpecializationType>();
786 while (TemplateType && TemplateType->isTypeAlias())
788 TemplateType->getAliasedType()->getAs<TemplateSpecializationType>();
793 if (
auto *ClassTemplate = dyn_cast_or_null<ClassTemplateDecl>(
794 TemplateType->getTemplateName().getAsTemplateDecl()))
795 return ClassTemplate->getTemplatedDecl();
803 bool MatchASTVisitor::classIsDerivedFrom(
const CXXRecordDecl *Declaration,
804 const Matcher<NamedDecl> &
Base,
805 BoundNodesTreeBuilder *Builder) {
806 if (!Declaration->hasDefinition())
808 for (
const auto &It : Declaration->bases()) {
809 const Type *TypeNode = It.getType().getTypePtr();
811 if (typeHasMatchingAlias(TypeNode, Base, Builder))
817 CXXRecordDecl *ClassDecl = getAsCXXRecordDeclOrPrimaryTemplate(TypeNode);
820 if (ClassDecl == Declaration) {
825 BoundNodesTreeBuilder Result(*Builder);
826 if (Base.matches(*ClassDecl,
this, &Result)) {
827 *Builder = std::move(Result);
830 if (classIsDerivedFrom(ClassDecl, Base, Builder))
836 bool MatchASTVisitor::TraverseDecl(Decl *DeclNode) {
844 bool MatchASTVisitor::TraverseStmt(Stmt *StmtNode) {
852 bool MatchASTVisitor::TraverseType(QualType TypeNode) {
857 bool MatchASTVisitor::TraverseTypeLoc(TypeLoc TypeLocNode) {
864 match(TypeLocNode.getType());
868 bool MatchASTVisitor::TraverseNestedNameSpecifier(NestedNameSpecifier *NNS) {
873 bool MatchASTVisitor::TraverseNestedNameSpecifierLoc(
874 NestedNameSpecifierLoc NNS) {
882 if (NNS.hasQualifier())
883 match(*NNS.getNestedNameSpecifier());
888 bool MatchASTVisitor::TraverseConstructorInitializer(
889 CXXCtorInitializer *CtorInit) {
899 class MatchASTConsumer :
public ASTConsumer {
901 MatchASTConsumer(MatchFinder *Finder,
902 MatchFinder::ParsingDoneTestCallback *ParsingDone)
903 : Finder(Finder), ParsingDone(ParsingDone) {}
906 void HandleTranslationUnit(ASTContext &Context)
override {
907 if (ParsingDone !=
nullptr) {
910 Finder->matchAST(Context);
914 MatchFinder::ParsingDoneTestCallback *ParsingDone;
922 : Nodes(Nodes), Context(Context),
929 : Options(
std::move(Options)), ParsingDone(nullptr) {}
935 Matchers.
DeclOrStmt.emplace_back(NodeMatch, Action);
941 Matchers.
Type.emplace_back(NodeMatch, Action);
947 Matchers.
DeclOrStmt.emplace_back(NodeMatch, Action);
965 Matchers.
TypeLoc.emplace_back(NodeMatch, Action);
971 Matchers.
CtorInit.emplace_back(NodeMatch, Action);
977 if (NodeMatch.canConvertTo<
Decl>()) {
980 }
else if (NodeMatch.canConvertTo<
QualType>()) {
983 }
else if (NodeMatch.canConvertTo<
Stmt>()) {
992 }
else if (NodeMatch.canConvertTo<
TypeLoc>()) {
1003 return llvm::make_unique<internal::MatchASTConsumer>(
this, ParsingDone);
1008 internal::MatchASTVisitor Visitor(&Matchers, Options);
1009 Visitor.set_active_ast_context(&Context);
1010 Visitor.match(Node);
1014 internal::MatchASTVisitor Visitor(&Matchers, Options);
1015 Visitor.set_active_ast_context(&Context);
1016 Visitor.onStartOfTranslationUnit();
1018 Visitor.onEndOfTranslationUnit();
1023 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.
const FunctionProtoType * T
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.