clang: include/clang/ASTMatchers/ASTMatchFinder.h Source File (original) (raw)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40#ifndef LLVM_CLANG_ASTMATCHERS_ASTMATCHFINDER_H
41#define LLVM_CLANG_ASTMATCHERS_ASTMATCHFINDER_H
42
44#include "llvm/ADT/SmallPtrSet.h"
45#include "llvm/ADT/StringMap.h"
46#include "llvm/Support/Timer.h"
47#include
48
50
51namespace ast_matchers {
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
70public:
71
72
73
74
77
78
79
80
82
83
84
87
88 };
89
90
91
93 public:
95
96
98
99
100
101
103
104
105
106
108
109
110
111
112
113 virtual StringRef getID() const;
114
115
116
117
118
120 };
121
122
124 public:
127 };
128
133
134
135 llvm::StringMapllvm::TimeRecord &Records;
136 };
137
138
139
140
142 };
143
146
147
148
149
150
151
152
153
154
172
173
174
175
176
177
178
179
180
181
182 bool addDynamicMatcher(const internal::DynTypedMatcher &NodeMatch,
184
185
186 std::unique_ptrclang::ASTConsumer newASTConsumer();
187
188
189
190
191
192
193
196 }
198
199
200
202
203
204
205
206
207
209
210
211
213 std::vector<std::pair<internal::DynTypedMatcher, MatchCallback *>>
215 std::vector<std::pair<TypeMatcher, MatchCallback *>> Type;
216 std::vector<std::pair<NestedNameSpecifierMatcher, MatchCallback *>>
218 std::vector<std::pair<NestedNameSpecifierLocMatcher, MatchCallback *>>
220 std::vector<std::pair<TypeLocMatcher, MatchCallback *>> TypeLoc;
221 std::vector<std::pair<CXXCtorInitializerMatcher, MatchCallback *>> CtorInit;
222 std::vector<std::pair<TemplateArgumentLocMatcher, MatchCallback *>>
224 std::vector<std::pair<AttrMatcher, MatchCallback *>> Attr;
225
227 };
228
229private:
231
233
234
236};
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252template <typename MatcherT, typename NodeT>
255
256template
259
260
261
262
263template
265
266
267
268
269
270
271
272
273
274
275
276template
277const NodeT *
279 for (const BoundNodes &N : Results) {
280 if (const NodeT *Node = N.getNodeAs(BoundTo))
282 }
283 return nullptr;
284}
285
286namespace internal {
288public:
291 }
292
294 return std::nullopt;
295 }
296
298};
299}
300
301template
306 Finder.addMatcher(Matcher, &Callback);
307 Finder.match(Node, Context);
308 return std::move(Callback.Nodes);
309}
310
311template <typename MatcherT, typename NodeT>
315}
316
317template
322 Finder.addMatcher(Matcher, &Callback);
323 Finder.matchAST(Context);
324 return std::move(Callback.Nodes);
325}
326
332 Finder.addDynamicMatcher(Matcher, &Callback);
333 Finder.match(Node, Context);
334 return std::move(Callback.Nodes);
335}
336
337template
339 const NodeT &Node,
342}
343
348 Finder.addDynamicMatcher(Matcher, &Callback);
349 Finder.matchAST(Context);
350 return std::move(Callback.Nodes);
351}
352
353}
354}
355
356#endif
llvm::MachO::Records Records
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
A dynamically typed AST node container.
static DynTypedNode create(const T &Node)
Creates a DynTypedNode from Node.
This class handles loading and caching of source files into memory.
Maps string IDs to AST nodes matched by parts of a matcher.
Called when the Match registered for it was successfully found in the AST.
virtual std::optional< TraversalKind > getCheckTraversalKind() const
TraversalKind to use while matching and processing the result nodes.
virtual StringRef getID() const
An id used to group the matchers.
virtual void onEndOfTranslationUnit()
Called at the end of each translation unit.
virtual void run(const MatchResult &Result)=0
Called on every match by the MatchFinder.
virtual void onStartOfTranslationUnit()
Called at the start of each translation unit.
Called when parsing is finished. Intended for testing only.
virtual ~ParsingDoneTestCallback()
A class to allow finding matches over the Clang AST.
bool addDynamicMatcher(const internal::DynTypedMatcher &NodeMatch, MatchCallback *Action)
Adds a matcher to execute when running over the AST.
void addMatcher(const DeclarationMatcher &NodeMatch, MatchCallback *Action)
Adds a matcher to execute when running over the AST.
void match(const T &Node, ASTContext &Context)
Calls the registered callbacks on all matches on the given Node.
void registerTestCallbackAfterParsing(ParsingDoneTestCallback *ParsingDone)
Registers a callback to notify the end of parsing.
std::unique_ptr< clang::ASTConsumer > newASTConsumer()
Creates a clang ASTConsumer that finds all matches.
void matchAST(ASTContext &Context)
Finds all matches in the given AST.
void run(const MatchFinder::MatchResult &Result) override
Called on every match by the MatchFinder.
SmallVector< BoundNodes, 1 > Nodes
std::optional< TraversalKind > getCheckTraversalKind() const override
TraversalKind to use while matching and processing the result nodes.
internal::Matcher< QualType > TypeMatcher
internal::Matcher< Decl > DeclarationMatcher
Types of matchers for the top-level classes in the AST class hierarchy.
internal::Matcher< NestedNameSpecifier > NestedNameSpecifierMatcher
SmallVector< BoundNodes, 1 > match(MatcherT Matcher, const NodeT &Node, ASTContext &Context)
Returns the results of matching Matcher on Node.
internal::Matcher< CXXCtorInitializer > CXXCtorInitializerMatcher
const NodeT * selectFirst(StringRef BoundTo, const SmallVectorImpl< BoundNodes > &Results)
Returns the first result of type NodeT bound to BoundTo.
internal::Matcher< Stmt > StatementMatcher
internal::Matcher< TypeLoc > TypeLocMatcher
internal::Matcher< TemplateArgumentLoc > TemplateArgumentLocMatcher
SmallVector< BoundNodes, 1 > matchDynamic(internal::DynTypedMatcher Matcher, const DynTypedNode &Node, ASTContext &Context)
internal::Matcher< Attr > AttrMatcher
internal::Matcher< NestedNameSpecifierLoc > NestedNameSpecifierLocMatcher
The JSON file list parser is used to communicate input to InstallAPI.
@ Result
The result type of a method or function.
const FunctionProtoType * T
Profiling(llvm::StringMap< llvm::TimeRecord > &Records)
llvm::StringMap< llvm::TimeRecord > & Records
Per bucket timing information.
std::optional< Profiling > CheckProfiling
Enables per-check timers.
Contains all information for a given match.
clang::SourceManager *const SourceManager
const BoundNodes Nodes
Contains the nodes bound on the current match.
clang::ASTContext *const Context
Utilities for interpreting the matched AST structures.
For each Matcher<> a MatchCallback that will be called when it matches.
std::vector< std::pair< CXXCtorInitializerMatcher, MatchCallback * > > CtorInit
std::vector< std::pair< TemplateArgumentLocMatcher, MatchCallback * > > TemplateArgumentLoc
std::vector< std::pair< internal::DynTypedMatcher, MatchCallback * > > DeclOrStmt
std::vector< std::pair< NestedNameSpecifierMatcher, MatchCallback * > > NestedNameSpecifier
std::vector< std::pair< TypeMatcher, MatchCallback * > > Type
std::vector< std::pair< NestedNameSpecifierLocMatcher, MatchCallback * > > NestedNameSpecifierLoc
llvm::SmallPtrSet< MatchCallback *, 16 > AllCallbacks
All the callbacks in one container to simplify iteration.
std::vector< std::pair< TypeLocMatcher, MatchCallback * > > TypeLoc
std::vector< std::pair< AttrMatcher, MatchCallback * > > Attr