1 | #pragma once
|
---|
2 |
|
---|
3 | // IWYU pragma: private, include "Common/PassVisitor.h"
|
---|
4 |
|
---|
5 | #include <stack>
|
---|
6 |
|
---|
7 | #include "SynTree/Mutator.h"
|
---|
8 | #include "SynTree/Visitor.h"
|
---|
9 |
|
---|
10 | #include "SymTab/Indexer.h"
|
---|
11 |
|
---|
12 | #include "SynTree/Initializer.h"
|
---|
13 | #include "SynTree/Statement.h"
|
---|
14 | #include "SynTree/Type.h"
|
---|
15 | #include "SynTree/Declaration.h"
|
---|
16 | #include "SynTree/Expression.h"
|
---|
17 | #include "SynTree/Constant.h"
|
---|
18 | #include "SynTree/TypeSubstitution.h"
|
---|
19 |
|
---|
20 | #include "PassVisitor.proto.h"
|
---|
21 |
|
---|
22 | //-------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
---|
23 | // Templated visitor type
|
---|
24 | // To use declare a PassVisitor< YOUR VISITOR TYPE >
|
---|
25 | // The visitor type should specify the previsit/postvisit/premutate/postmutate for types that are desired.
|
---|
26 | // Note: previsit/postvisit/premutate/postmutate must be **public** members
|
---|
27 | //
|
---|
28 | // Several additional features are available through inheritance
|
---|
29 | // | WithTypeSubstitution - provides polymorphic TypeSubstitution * env for the current expression
|
---|
30 | // | WithStmtsToAdd - provides the ability to insert statements before or after the current statement by adding new statements into
|
---|
31 | // stmtsToAddBefore or stmtsToAddAfter respectively.
|
---|
32 | // | WithShortCircuiting - provides the ability to skip visiting child nodes; set visit_children to false in pre{visit,mutate} to skip visiting children
|
---|
33 | // | WithGuards - provides the ability to save/restore data like a LIFO stack; to save, call GuardValue with the variable to save, the variable
|
---|
34 | // will automatically be restored to its previous value after the corresponding postvisit/postmutate teminates.
|
---|
35 | //-------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
---|
36 | template< typename pass_type >
|
---|
37 | class PassVisitor final : public Visitor, public Mutator {
|
---|
38 | public:
|
---|
39 |
|
---|
40 | template< typename... Args >
|
---|
41 | PassVisitor(Args &&... args)
|
---|
42 | : pass( std::forward<Args>( args )... )
|
---|
43 | {
|
---|
44 | typedef PassVisitor<pass_type> this_t;
|
---|
45 | this_t * const * visitor = visitor_impl(pass, 0);
|
---|
46 | if(visitor) {
|
---|
47 | *const_cast<this_t **>( visitor ) = this;
|
---|
48 | }
|
---|
49 | }
|
---|
50 |
|
---|
51 | virtual ~PassVisitor() = default;
|
---|
52 |
|
---|
53 | pass_type pass;
|
---|
54 |
|
---|
55 | virtual void visit( ObjectDecl *objectDecl ) override final;
|
---|
56 | virtual void visit( FunctionDecl *functionDecl ) override final;
|
---|
57 | virtual void visit( StructDecl *aggregateDecl ) override final;
|
---|
58 | virtual void visit( UnionDecl *aggregateDecl ) override final;
|
---|
59 | virtual void visit( EnumDecl *aggregateDecl ) override final;
|
---|
60 | virtual void visit( TraitDecl *aggregateDecl ) override final;
|
---|
61 | virtual void visit( TypeDecl *typeDecl ) override final;
|
---|
62 | virtual void visit( TypedefDecl *typeDecl ) override final;
|
---|
63 | virtual void visit( AsmDecl *asmDecl ) override final;
|
---|
64 |
|
---|
65 | virtual void visit( CompoundStmt *compoundStmt ) override final;
|
---|
66 | virtual void visit( ExprStmt *exprStmt ) override final;
|
---|
67 | virtual void visit( AsmStmt *asmStmt ) override final;
|
---|
68 | virtual void visit( IfStmt *ifStmt ) override final;
|
---|
69 | virtual void visit( WhileStmt *whileStmt ) override final;
|
---|
70 | virtual void visit( ForStmt *forStmt ) override final;
|
---|
71 | virtual void visit( SwitchStmt *switchStmt ) override final;
|
---|
72 | virtual void visit( CaseStmt *caseStmt ) override final;
|
---|
73 | virtual void visit( BranchStmt *branchStmt ) override final;
|
---|
74 | virtual void visit( ReturnStmt *returnStmt ) override final;
|
---|
75 | virtual void visit( ThrowStmt *throwStmt ) override final;
|
---|
76 | virtual void visit( TryStmt *tryStmt ) override final;
|
---|
77 | virtual void visit( CatchStmt *catchStmt ) override final;
|
---|
78 | virtual void visit( FinallyStmt *finallyStmt ) override final;
|
---|
79 | virtual void visit( WaitForStmt *waitforStmt ) override final;
|
---|
80 | virtual void visit( NullStmt *nullStmt ) override final;
|
---|
81 | virtual void visit( DeclStmt *declStmt ) override final;
|
---|
82 | virtual void visit( ImplicitCtorDtorStmt *impCtorDtorStmt ) override final;
|
---|
83 |
|
---|
84 | virtual void visit( ApplicationExpr *applicationExpr ) override final;
|
---|
85 | virtual void visit( UntypedExpr *untypedExpr ) override final;
|
---|
86 | virtual void visit( NameExpr *nameExpr ) override final;
|
---|
87 | virtual void visit( CastExpr *castExpr ) override final;
|
---|
88 | virtual void visit( VirtualCastExpr *castExpr ) override final;
|
---|
89 | virtual void visit( AddressExpr *addressExpr ) override final;
|
---|
90 | virtual void visit( LabelAddressExpr *labAddressExpr ) override final;
|
---|
91 | virtual void visit( UntypedMemberExpr *memberExpr ) override final;
|
---|
92 | virtual void visit( MemberExpr *memberExpr ) override final;
|
---|
93 | virtual void visit( VariableExpr *variableExpr ) override final;
|
---|
94 | virtual void visit( ConstantExpr *constantExpr ) override final;
|
---|
95 | virtual void visit( SizeofExpr *sizeofExpr ) override final;
|
---|
96 | virtual void visit( AlignofExpr *alignofExpr ) override final;
|
---|
97 | virtual void visit( UntypedOffsetofExpr *offsetofExpr ) override final;
|
---|
98 | virtual void visit( OffsetofExpr *offsetofExpr ) override final;
|
---|
99 | virtual void visit( OffsetPackExpr *offsetPackExpr ) override final;
|
---|
100 | virtual void visit( AttrExpr *attrExpr ) override final;
|
---|
101 | virtual void visit( LogicalExpr *logicalExpr ) override final;
|
---|
102 | virtual void visit( ConditionalExpr *conditionalExpr ) override final;
|
---|
103 | virtual void visit( CommaExpr *commaExpr ) override final;
|
---|
104 | virtual void visit( TypeExpr *typeExpr ) override final;
|
---|
105 | virtual void visit( AsmExpr *asmExpr ) override final;
|
---|
106 | virtual void visit( ImplicitCopyCtorExpr *impCpCtorExpr ) override final;
|
---|
107 | virtual void visit( ConstructorExpr * ctorExpr ) override final;
|
---|
108 | virtual void visit( CompoundLiteralExpr *compLitExpr ) override final;
|
---|
109 | virtual void visit( RangeExpr *rangeExpr ) override final;
|
---|
110 | virtual void visit( UntypedTupleExpr *tupleExpr ) override final;
|
---|
111 | virtual void visit( TupleExpr *tupleExpr ) override final;
|
---|
112 | virtual void visit( TupleIndexExpr *tupleExpr ) override final;
|
---|
113 | virtual void visit( TupleAssignExpr *assignExpr ) override final;
|
---|
114 | virtual void visit( StmtExpr * stmtExpr ) override final;
|
---|
115 | virtual void visit( UniqueExpr * uniqueExpr ) override final;
|
---|
116 |
|
---|
117 | virtual void visit( VoidType *basicType ) override final;
|
---|
118 | virtual void visit( BasicType *basicType ) override final;
|
---|
119 | virtual void visit( PointerType *pointerType ) override final;
|
---|
120 | virtual void visit( ArrayType *arrayType ) override final;
|
---|
121 | virtual void visit( ReferenceType *referenceType ) override final;
|
---|
122 | virtual void visit( FunctionType *functionType ) override final;
|
---|
123 | virtual void visit( StructInstType *aggregateUseType ) override final;
|
---|
124 | virtual void visit( UnionInstType *aggregateUseType ) override final;
|
---|
125 | virtual void visit( EnumInstType *aggregateUseType ) override final;
|
---|
126 | virtual void visit( TraitInstType *aggregateUseType ) override final;
|
---|
127 | virtual void visit( TypeInstType *aggregateUseType ) override final;
|
---|
128 | virtual void visit( TupleType *tupleType ) override final;
|
---|
129 | virtual void visit( TypeofType *typeofType ) override final;
|
---|
130 | virtual void visit( AttrType *attrType ) override final;
|
---|
131 | virtual void visit( VarArgsType *varArgsType ) override final;
|
---|
132 | virtual void visit( ZeroType *zeroType ) override final;
|
---|
133 | virtual void visit( OneType *oneType ) override final;
|
---|
134 |
|
---|
135 | virtual void visit( Designation *designation ) override final;
|
---|
136 | virtual void visit( SingleInit *singleInit ) override final;
|
---|
137 | virtual void visit( ListInit *listInit ) override final;
|
---|
138 | virtual void visit( ConstructorInit *ctorInit ) override final;
|
---|
139 |
|
---|
140 | virtual void visit( Subrange *subrange ) override final;
|
---|
141 |
|
---|
142 | virtual void visit( Constant *constant ) override final;
|
---|
143 |
|
---|
144 | virtual DeclarationWithType* mutate( ObjectDecl *objectDecl ) override final;
|
---|
145 | virtual DeclarationWithType* mutate( FunctionDecl *functionDecl ) override final;
|
---|
146 | virtual Declaration* mutate( StructDecl *aggregateDecl ) override final;
|
---|
147 | virtual Declaration* mutate( UnionDecl *aggregateDecl ) override final;
|
---|
148 | virtual Declaration* mutate( EnumDecl *aggregateDecl ) override final;
|
---|
149 | virtual Declaration* mutate( TraitDecl *aggregateDecl ) override final;
|
---|
150 | virtual Declaration* mutate( TypeDecl *typeDecl ) override final;
|
---|
151 | virtual Declaration* mutate( TypedefDecl *typeDecl ) override final;
|
---|
152 | virtual AsmDecl* mutate( AsmDecl *asmDecl ) override final;
|
---|
153 |
|
---|
154 | virtual CompoundStmt* mutate( CompoundStmt *compoundStmt ) override final;
|
---|
155 | virtual Statement* mutate( ExprStmt *exprStmt ) override final;
|
---|
156 | virtual Statement* mutate( AsmStmt *asmStmt ) override final;
|
---|
157 | virtual Statement* mutate( IfStmt *ifStmt ) override final;
|
---|
158 | virtual Statement* mutate( WhileStmt *whileStmt ) override final;
|
---|
159 | virtual Statement* mutate( ForStmt *forStmt ) override final;
|
---|
160 | virtual Statement* mutate( SwitchStmt *switchStmt ) override final;
|
---|
161 | virtual Statement* mutate( CaseStmt *caseStmt ) override final;
|
---|
162 | virtual Statement* mutate( BranchStmt *branchStmt ) override final;
|
---|
163 | virtual Statement* mutate( ReturnStmt *returnStmt ) override final;
|
---|
164 | virtual Statement* mutate( ThrowStmt *throwStmt ) override final;
|
---|
165 | virtual Statement* mutate( TryStmt *tryStmt ) override final;
|
---|
166 | virtual Statement* mutate( CatchStmt *catchStmt ) override final;
|
---|
167 | virtual Statement* mutate( FinallyStmt *finallyStmt ) override final;
|
---|
168 | virtual Statement* mutate( WaitForStmt *waitforStmt ) override final;
|
---|
169 | virtual NullStmt* mutate( NullStmt *nullStmt ) override final;
|
---|
170 | virtual Statement* mutate( DeclStmt *declStmt ) override final;
|
---|
171 | virtual Statement* mutate( ImplicitCtorDtorStmt *impCtorDtorStmt ) override final;
|
---|
172 |
|
---|
173 | virtual Expression* mutate( ApplicationExpr *applicationExpr ) override final;
|
---|
174 | virtual Expression* mutate( UntypedExpr *untypedExpr ) override final;
|
---|
175 | virtual Expression* mutate( NameExpr *nameExpr ) override final;
|
---|
176 | virtual Expression* mutate( AddressExpr *castExpr ) override final;
|
---|
177 | virtual Expression* mutate( LabelAddressExpr *labAddressExpr ) override final;
|
---|
178 | virtual Expression* mutate( CastExpr *castExpr ) override final;
|
---|
179 | virtual Expression* mutate( VirtualCastExpr *castExpr ) override final;
|
---|
180 | virtual Expression* mutate( UntypedMemberExpr *memberExpr ) override final;
|
---|
181 | virtual Expression* mutate( MemberExpr *memberExpr ) override final;
|
---|
182 | virtual Expression* mutate( VariableExpr *variableExpr ) override final;
|
---|
183 | virtual Expression* mutate( ConstantExpr *constantExpr ) override final;
|
---|
184 | virtual Expression* mutate( SizeofExpr *sizeofExpr ) override final;
|
---|
185 | virtual Expression* mutate( AlignofExpr *alignofExpr ) override final;
|
---|
186 | virtual Expression* mutate( UntypedOffsetofExpr *offsetofExpr ) override final;
|
---|
187 | virtual Expression* mutate( OffsetofExpr *offsetofExpr ) override final;
|
---|
188 | virtual Expression* mutate( OffsetPackExpr *offsetPackExpr ) override final;
|
---|
189 | virtual Expression* mutate( AttrExpr *attrExpr ) override final;
|
---|
190 | virtual Expression* mutate( LogicalExpr *logicalExpr ) override final;
|
---|
191 | virtual Expression* mutate( ConditionalExpr *conditionalExpr ) override final;
|
---|
192 | virtual Expression* mutate( CommaExpr *commaExpr ) override final;
|
---|
193 | virtual Expression* mutate( TypeExpr *typeExpr ) override final;
|
---|
194 | virtual Expression* mutate( AsmExpr *asmExpr ) override final;
|
---|
195 | virtual Expression* mutate( ImplicitCopyCtorExpr *impCpCtorExpr ) override final;
|
---|
196 | virtual Expression* mutate( ConstructorExpr *ctorExpr ) override final;
|
---|
197 | virtual Expression* mutate( CompoundLiteralExpr *compLitExpr ) override final;
|
---|
198 | virtual Expression* mutate( RangeExpr *rangeExpr ) override final;
|
---|
199 | virtual Expression* mutate( UntypedTupleExpr *tupleExpr ) override final;
|
---|
200 | virtual Expression* mutate( TupleExpr *tupleExpr ) override final;
|
---|
201 | virtual Expression* mutate( TupleIndexExpr *tupleExpr ) override final;
|
---|
202 | virtual Expression* mutate( TupleAssignExpr *assignExpr ) override final;
|
---|
203 | virtual Expression* mutate( StmtExpr * stmtExpr ) override final;
|
---|
204 | virtual Expression* mutate( UniqueExpr * uniqueExpr ) override final;
|
---|
205 |
|
---|
206 | virtual Type* mutate( VoidType *basicType ) override final;
|
---|
207 | virtual Type* mutate( BasicType *basicType ) override final;
|
---|
208 | virtual Type* mutate( PointerType *pointerType ) override final;
|
---|
209 | virtual Type* mutate( ArrayType *arrayType ) override final;
|
---|
210 | virtual Type* mutate( ReferenceType *referenceType ) override final;
|
---|
211 | virtual Type* mutate( FunctionType *functionType ) override final;
|
---|
212 | virtual Type* mutate( StructInstType *aggregateUseType ) override final;
|
---|
213 | virtual Type* mutate( UnionInstType *aggregateUseType ) override final;
|
---|
214 | virtual Type* mutate( EnumInstType *aggregateUseType ) override final;
|
---|
215 | virtual Type* mutate( TraitInstType *aggregateUseType ) override final;
|
---|
216 | virtual Type* mutate( TypeInstType *aggregateUseType ) override final;
|
---|
217 | virtual Type* mutate( TupleType *tupleType ) override final;
|
---|
218 | virtual Type* mutate( TypeofType *typeofType ) override final;
|
---|
219 | virtual Type* mutate( AttrType *attrType ) override final;
|
---|
220 | virtual Type* mutate( VarArgsType *varArgsType ) override final;
|
---|
221 | virtual Type* mutate( ZeroType *zeroType ) override final;
|
---|
222 | virtual Type* mutate( OneType *oneType ) override final;
|
---|
223 |
|
---|
224 | virtual Designation* mutate( Designation *designation ) override final;
|
---|
225 | virtual Initializer* mutate( SingleInit *singleInit ) override final;
|
---|
226 | virtual Initializer* mutate( ListInit *listInit ) override final;
|
---|
227 | virtual Initializer* mutate( ConstructorInit *ctorInit ) override final;
|
---|
228 |
|
---|
229 | virtual Subrange *mutate( Subrange *subrange ) override final;
|
---|
230 |
|
---|
231 | virtual Constant *mutate( Constant *constant ) override final;
|
---|
232 |
|
---|
233 | private:
|
---|
234 | template<typename pass_t> friend void acceptAll( std::list< Declaration* > &decls, PassVisitor< pass_t >& visitor );
|
---|
235 | template<typename pass_t> friend void mutateAll( std::list< Declaration* > &decls, PassVisitor< pass_t >& visitor );
|
---|
236 |
|
---|
237 | template<typename node_type> void call_previsit ( node_type * node ) { previsit_impl ( pass, node, 0 ); }
|
---|
238 | template<typename node_type> void call_postvisit( node_type * node ) { postvisit_impl( pass, node, 0 ); }
|
---|
239 |
|
---|
240 | template<typename node_type> void call_premutate ( node_type * node ) { premutate_impl( pass, node, 0 ); }
|
---|
241 | template<typename return_type, typename node_type> return_type call_postmutate ( node_type * node ) { return postmutate_impl<return_type>( pass, node, 0 ); }
|
---|
242 |
|
---|
243 | void call_beginScope() { begin_scope_impl( pass, 0 ); }
|
---|
244 | void call_endScope () { end_scope_impl ( pass, 0 ); }
|
---|
245 |
|
---|
246 | void set_env( TypeSubstitution * env ) { set_env_impl( pass, env, 0); }
|
---|
247 |
|
---|
248 | template< typename func_t >
|
---|
249 | void handleStatementList( std::list< Statement * > & statements, func_t func );
|
---|
250 | void visitStatementList ( std::list< Statement* > &statements );
|
---|
251 | void mutateStatementList( std::list< Statement* > &statements );
|
---|
252 |
|
---|
253 | template< typename func_t >
|
---|
254 | Statement * handleStatement( Statement * stmt, func_t func );
|
---|
255 | Statement * visitStatement ( Statement * stmt );
|
---|
256 | Statement * mutateStatement( Statement * stmt );
|
---|
257 |
|
---|
258 | template< typename func_t >
|
---|
259 | Expression * handleExpression( Expression * expr, func_t func );
|
---|
260 | Expression * visitExpression ( Expression * expr );
|
---|
261 | Expression * mutateExpression( Expression * expr );
|
---|
262 |
|
---|
263 |
|
---|
264 | TypeSubstitution ** get_env_ptr () { return env_impl ( pass, 0); }
|
---|
265 | std::list< Statement* > * get_beforeStmts() { return stmtsToAddBefore_impl( pass, 0); }
|
---|
266 | std::list< Statement* > * get_afterStmts () { return stmtsToAddAfter_impl ( pass, 0); }
|
---|
267 | std::list< Declaration* > * get_beforeDecls() { return declsToAddBefore_impl( pass, 0); }
|
---|
268 | std::list< Declaration* > * get_afterDecls () { return declsToAddAfter_impl ( pass, 0); }
|
---|
269 |
|
---|
270 | void set_visit_children( bool& ref ) { bool_ref * ptr = visit_children_impl(pass, 0); if(ptr) ptr->set( ref ); }
|
---|
271 |
|
---|
272 | void indexerScopeEnter () { indexer_impl_enterScope ( pass, 0 ); }
|
---|
273 | void indexerScopeLeave () { indexer_impl_leaveScope ( pass, 0 ); }
|
---|
274 | void indexerAddId ( DeclarationWithType * node ) { indexer_impl_addId ( pass, 0, node ); }
|
---|
275 | void indexerAddType ( NamedTypeDecl * node ) { indexer_impl_addType ( pass, 0, node ); }
|
---|
276 | void indexerAddStruct ( const std::string & id ) { indexer_impl_addStruct ( pass, 0, id ); }
|
---|
277 | void indexerAddStruct ( StructDecl * node ) { indexer_impl_addStruct ( pass, 0, node ); }
|
---|
278 | void indexerAddStructFwd( StructDecl * node ) { indexer_impl_addStructFwd( pass, 0, node ); }
|
---|
279 | void indexerAddEnum ( EnumDecl * node ) { indexer_impl_addEnum ( pass, 0, node ); }
|
---|
280 | void indexerAddUnion ( const std::string & id ) { indexer_impl_addUnion ( pass, 0, id ); }
|
---|
281 | void indexerAddUnion ( UnionDecl * node ) { indexer_impl_addUnion ( pass, 0, node ); }
|
---|
282 | void indexerAddUnionFwd ( UnionDecl * node ) { indexer_impl_addUnionFwd ( pass, 0, node ); }
|
---|
283 | void indexerAddTrait ( TraitDecl * node ) { indexer_impl_addTrait ( pass, 0, node ); }
|
---|
284 |
|
---|
285 | template< typename TreeType, typename VisitorType >
|
---|
286 | friend inline void indexerScopedAccept( TreeType * tree, VisitorType &visitor );
|
---|
287 |
|
---|
288 | template< typename TreeType, typename VisitorType >
|
---|
289 | friend inline void indexerScopedMutate( TreeType *& tree, VisitorType &visitor );
|
---|
290 | };
|
---|
291 |
|
---|
292 | template<typename pass_type, typename T>
|
---|
293 | void GuardValue( pass_type * pass, T& val ) {
|
---|
294 | pass->at_cleanup( [ val ]( void * newVal ) {
|
---|
295 | * static_cast< T * >( newVal ) = val;
|
---|
296 | }, static_cast< void * >( & val ) );
|
---|
297 | }
|
---|
298 |
|
---|
299 | class WithTypeSubstitution {
|
---|
300 | protected:
|
---|
301 | WithTypeSubstitution() = default;
|
---|
302 | ~WithTypeSubstitution() = default;
|
---|
303 |
|
---|
304 | public:
|
---|
305 | TypeSubstitution * env = nullptr;
|
---|
306 | };
|
---|
307 |
|
---|
308 | class WithStmtsToAdd {
|
---|
309 | protected:
|
---|
310 | WithStmtsToAdd() = default;
|
---|
311 | ~WithStmtsToAdd() = default;
|
---|
312 |
|
---|
313 | public:
|
---|
314 | std::list< Statement* > stmtsToAddBefore;
|
---|
315 | std::list< Statement* > stmtsToAddAfter;
|
---|
316 | };
|
---|
317 |
|
---|
318 | class WithDeclsToAdd {
|
---|
319 | protected:
|
---|
320 | WithDeclsToAdd() = default;
|
---|
321 | ~WithDeclsToAdd() {
|
---|
322 | assert( declsToAddBefore.empty() );
|
---|
323 | }
|
---|
324 |
|
---|
325 | public:
|
---|
326 | std::list< Declaration* > declsToAddBefore;
|
---|
327 | std::list< Declaration* > declsToAddAfter;
|
---|
328 | };
|
---|
329 |
|
---|
330 | class WithShortCircuiting {
|
---|
331 | protected:
|
---|
332 | WithShortCircuiting() = default;
|
---|
333 | ~WithShortCircuiting() = default;
|
---|
334 |
|
---|
335 | public:
|
---|
336 | bool_ref visit_children;
|
---|
337 | };
|
---|
338 |
|
---|
339 | class WithGuards {
|
---|
340 | protected:
|
---|
341 | WithGuards() = default;
|
---|
342 | ~WithGuards() = default;
|
---|
343 |
|
---|
344 | public:
|
---|
345 | at_cleanup_t at_cleanup;
|
---|
346 |
|
---|
347 | template< typename T >
|
---|
348 | void GuardValue( T& val ) {
|
---|
349 | at_cleanup( [ val ]( void * newVal ) {
|
---|
350 | * static_cast< T * >( newVal ) = val;
|
---|
351 | }, static_cast< void * >( & val ) );
|
---|
352 | }
|
---|
353 |
|
---|
354 | template< typename T >
|
---|
355 | void GuardScope( T& val ) {
|
---|
356 | val.beginScope();
|
---|
357 | at_cleanup( []( void * val ) {
|
---|
358 | static_cast< T * >( val )->endScope();
|
---|
359 | }, static_cast< void * >( & val ) );
|
---|
360 | }
|
---|
361 |
|
---|
362 | template< typename Func >
|
---|
363 | void GuardAction( Func func ) {
|
---|
364 | at_cleanup( [func](__attribute__((unused)) void *) { func(); }, nullptr );
|
---|
365 | }
|
---|
366 | };
|
---|
367 |
|
---|
368 | template<typename pass_type>
|
---|
369 | class WithVisitorRef {
|
---|
370 | protected:
|
---|
371 | WithVisitorRef() {}
|
---|
372 | ~WithVisitorRef() {}
|
---|
373 |
|
---|
374 | public:
|
---|
375 | PassVisitor<pass_type> * const visitor = nullptr;
|
---|
376 | };
|
---|
377 |
|
---|
378 | class WithIndexer {
|
---|
379 | protected:
|
---|
380 | WithIndexer() {}
|
---|
381 | ~WithIndexer() {}
|
---|
382 |
|
---|
383 | public:
|
---|
384 | SymTab::Indexer indexer;
|
---|
385 | };
|
---|
386 |
|
---|
387 | #include "PassVisitor.impl.h"
|
---|