1 | #pragma once |
---|
2 | // IWYU pragma: private, include "PassVisitor.h" |
---|
3 | |
---|
4 | #define VISIT_START( node ) \ |
---|
5 | __attribute__((unused)) \ |
---|
6 | ChildrenGuard children_guard( get_visit_children_ptr() ); \ |
---|
7 | __attribute__((unused)) \ |
---|
8 | guard_value_impl guard( at_cleanup_impl(pass, 0) ); \ |
---|
9 | call_previsit( node ); \ |
---|
10 | |
---|
11 | #define VISIT_END( node ) \ |
---|
12 | call_postvisit( node ); \ |
---|
13 | |
---|
14 | #define MUTATE_START( node ) \ |
---|
15 | __attribute__((unused)) \ |
---|
16 | ChildrenGuard children_guard( get_visit_children_ptr() ); \ |
---|
17 | __attribute__((unused)) \ |
---|
18 | guard_value_impl guard( at_cleanup_impl(pass, 0) ); \ |
---|
19 | call_premutate( node ); \ |
---|
20 | |
---|
21 | #define MUTATE_END( type, node ) \ |
---|
22 | return call_postmutate< type * >( node ); \ |
---|
23 | |
---|
24 | |
---|
25 | #define VISIT_BODY( node ) \ |
---|
26 | VISIT_START( node ); \ |
---|
27 | if( children_guard ) { \ |
---|
28 | Visitor::visit( node ); \ |
---|
29 | } \ |
---|
30 | VISIT_END( node ); \ |
---|
31 | |
---|
32 | |
---|
33 | #define MUTATE_BODY( type, node ) \ |
---|
34 | MUTATE_START( node ); \ |
---|
35 | if( children_guard ) { \ |
---|
36 | Mutator::mutate( node ); \ |
---|
37 | } \ |
---|
38 | MUTATE_END( type, node ); \ |
---|
39 | |
---|
40 | |
---|
41 | |
---|
42 | template<typename T> |
---|
43 | static inline bool empty( T * ptr ) { |
---|
44 | return !ptr || ptr->empty(); |
---|
45 | } |
---|
46 | |
---|
47 | typedef std::list< Statement * > StmtList_t; |
---|
48 | typedef std::list< Declaration * > DeclList_t; |
---|
49 | |
---|
50 | template<typename iterator_t> |
---|
51 | static inline void splice( iterator_t it, DeclList_t * decls ) { |
---|
52 | std::transform( |
---|
53 | decls->begin(), |
---|
54 | decls->end(), |
---|
55 | it, |
---|
56 | [](Declaration * decl) -> auto { |
---|
57 | return new DeclStmt( decl ); |
---|
58 | } |
---|
59 | ); |
---|
60 | decls->clear(); |
---|
61 | } |
---|
62 | |
---|
63 | template< typename pass_type > |
---|
64 | inline void acceptAll( std::list< Declaration* > &decls, PassVisitor< pass_type >& visitor ) { |
---|
65 | DeclList_t* beforeDecls = visitor.get_beforeDecls(); |
---|
66 | DeclList_t* afterDecls = visitor.get_afterDecls(); |
---|
67 | SemanticError errors; |
---|
68 | |
---|
69 | for ( std::list< Declaration* >::iterator i = decls.begin(); ; ++i ) { |
---|
70 | // splice in new declarations after previous decl |
---|
71 | if ( !empty( afterDecls ) ) { decls.splice( i, *afterDecls ); } |
---|
72 | |
---|
73 | if ( i == decls.end() ) break; |
---|
74 | |
---|
75 | try { |
---|
76 | // run visitor on declaration |
---|
77 | maybeAccept_impl( *i, visitor ); |
---|
78 | } catch( SemanticError &e ) { |
---|
79 | e.set_location( (*i)->location ); |
---|
80 | errors.append( e ); |
---|
81 | } |
---|
82 | |
---|
83 | // splice in new declarations before current decl |
---|
84 | if ( !empty( beforeDecls ) ) { decls.splice( i, *beforeDecls ); } |
---|
85 | } |
---|
86 | if ( ! errors.isEmpty() ) { |
---|
87 | throw errors; |
---|
88 | } |
---|
89 | } |
---|
90 | |
---|
91 | template< typename pass_type > |
---|
92 | inline void mutateAll( std::list< Declaration* > &decls, PassVisitor< pass_type >& mutator ) { |
---|
93 | DeclList_t* beforeDecls = mutator.get_beforeDecls(); |
---|
94 | DeclList_t* afterDecls = mutator.get_afterDecls(); |
---|
95 | SemanticError errors; |
---|
96 | |
---|
97 | for ( std::list< Declaration* >::iterator i = decls.begin(); ; ++i ) { |
---|
98 | // splice in new declarations after previous decl |
---|
99 | if ( !empty( afterDecls ) ) { decls.splice( i, *afterDecls ); } |
---|
100 | |
---|
101 | if ( i == decls.end() ) break; |
---|
102 | try { |
---|
103 | // run mutator on declaration |
---|
104 | maybeMutate_impl( *i, mutator ); |
---|
105 | } catch( SemanticError &e ) { |
---|
106 | e.set_location( (*i)->location ); |
---|
107 | errors.append( e ); |
---|
108 | } |
---|
109 | |
---|
110 | // splice in new declarations before current decl |
---|
111 | if ( !empty( beforeDecls ) ) { decls.splice( i, *beforeDecls ); } |
---|
112 | } |
---|
113 | if ( ! errors.isEmpty() ) { |
---|
114 | throw errors; |
---|
115 | } |
---|
116 | } |
---|
117 | |
---|
118 | template< typename TreeType, typename pass_type > |
---|
119 | inline void maybeAccept_impl( TreeType * tree, PassVisitor< pass_type > & visitor ) { |
---|
120 | if ( ! visitor.get_visit_children() ) return; |
---|
121 | if ( tree ) { |
---|
122 | tree->accept( visitor ); |
---|
123 | } |
---|
124 | } |
---|
125 | |
---|
126 | template< typename Container, typename pass_type > |
---|
127 | inline void maybeAccept_impl( Container & container, PassVisitor< pass_type > & visitor ) { |
---|
128 | if ( ! visitor.get_visit_children() ) return; |
---|
129 | SemanticError errors; |
---|
130 | for ( typename Container::iterator i = container.begin(); i != container.end(); ++i ) { |
---|
131 | try { |
---|
132 | if ( *i ) { |
---|
133 | (*i)->accept( visitor ); |
---|
134 | } |
---|
135 | } catch( SemanticError &e ) { |
---|
136 | e.set_location( (*i)->location ); |
---|
137 | errors.append( e ); |
---|
138 | } |
---|
139 | } |
---|
140 | if ( ! errors.isEmpty() ) { |
---|
141 | throw errors; |
---|
142 | } |
---|
143 | } |
---|
144 | |
---|
145 | template< typename TreeType, typename pass_type > |
---|
146 | inline void maybeMutate_impl( TreeType *& tree, PassVisitor< pass_type > & mutator ) { |
---|
147 | if ( ! mutator.get_visit_children() ) return; |
---|
148 | |
---|
149 | if ( tree ) { |
---|
150 | tree = strict_dynamic_cast< TreeType * >( tree->acceptMutator( mutator ) ); |
---|
151 | } |
---|
152 | } |
---|
153 | |
---|
154 | template< typename Container, typename pass_type > |
---|
155 | inline void maybeMutate_impl( Container & container, PassVisitor< pass_type > & mutator ) { |
---|
156 | if ( ! mutator.get_visit_children() ) return; |
---|
157 | SemanticError errors; |
---|
158 | for ( typename Container::iterator i = container.begin(); i != container.end(); ++i ) { |
---|
159 | try { |
---|
160 | if ( *i ) { |
---|
161 | *i = dynamic_cast< typename Container::value_type >( (*i)->acceptMutator( mutator ) ); |
---|
162 | assert( *i ); |
---|
163 | } // if |
---|
164 | } catch( SemanticError &e ) { |
---|
165 | e.set_location( (*i)->location ); |
---|
166 | errors.append( e ); |
---|
167 | } // try |
---|
168 | } // for |
---|
169 | if ( ! errors.isEmpty() ) { |
---|
170 | throw errors; |
---|
171 | } // if |
---|
172 | } |
---|
173 | |
---|
174 | template< typename pass_type > |
---|
175 | template< typename func_t > |
---|
176 | void PassVisitor< pass_type >::handleStatementList( std::list< Statement * > & statements, func_t func ) { |
---|
177 | if ( ! get_visit_children() ) return; |
---|
178 | SemanticError errors; |
---|
179 | |
---|
180 | // don't want statements from outer CompoundStmts to be added to this CompoundStmt |
---|
181 | ValueGuardPtr< StmtList_t > oldBeforeStmts( get_beforeStmts() ); |
---|
182 | ValueGuardPtr< StmtList_t > oldAfterStmts ( get_afterStmts () ); |
---|
183 | ValueGuardPtr< DeclList_t > oldBeforeDecls( get_beforeDecls() ); |
---|
184 | ValueGuardPtr< DeclList_t > oldAfterDecls ( get_afterDecls () ); |
---|
185 | |
---|
186 | StmtList_t* beforeStmts = get_beforeStmts(); |
---|
187 | StmtList_t* afterStmts = get_afterStmts(); |
---|
188 | DeclList_t* beforeDecls = get_beforeDecls(); |
---|
189 | DeclList_t* afterDecls = get_afterDecls(); |
---|
190 | |
---|
191 | for ( std::list< Statement* >::iterator i = statements.begin(); i != statements.end(); ++i ) { |
---|
192 | |
---|
193 | if ( !empty( afterDecls ) ) { splice( std::inserter( statements, i ), afterDecls ); } |
---|
194 | if ( !empty( afterStmts ) ) { statements.splice( i, *afterStmts ); } |
---|
195 | |
---|
196 | try { |
---|
197 | func( *i ); |
---|
198 | assert(( empty( beforeStmts ) && empty( afterStmts )) |
---|
199 | || ( empty( beforeDecls ) && empty( afterDecls )) ); |
---|
200 | |
---|
201 | } catch ( SemanticError &e ) { |
---|
202 | e.set_location( (*i)->location ); |
---|
203 | errors.append( e ); |
---|
204 | } |
---|
205 | |
---|
206 | if ( !empty( beforeDecls ) ) { splice( std::inserter( statements, i ), beforeDecls ); } |
---|
207 | if ( !empty( beforeStmts ) ) { statements.splice( i, *beforeStmts ); } |
---|
208 | } |
---|
209 | |
---|
210 | if ( !empty( afterDecls ) ) { splice( std::back_inserter( statements ), afterDecls); } |
---|
211 | if ( !empty( afterStmts ) ) { statements.splice( statements.end(), *afterStmts ); } |
---|
212 | if ( !errors.isEmpty() ) { throw errors; } |
---|
213 | } |
---|
214 | |
---|
215 | template< typename pass_type > |
---|
216 | void PassVisitor< pass_type >::visitStatementList( std::list< Statement * > & statements ) { |
---|
217 | handleStatementList( statements, [this]( Statement * stmt) { |
---|
218 | maybeAccept_impl( stmt, *this ); |
---|
219 | }); |
---|
220 | } |
---|
221 | |
---|
222 | template< typename pass_type > |
---|
223 | void PassVisitor< pass_type >::mutateStatementList( std::list< Statement * > & statements ) { |
---|
224 | handleStatementList( statements, [this]( Statement *& stmt) { |
---|
225 | maybeMutate_impl( stmt, *this ); |
---|
226 | }); |
---|
227 | } |
---|
228 | |
---|
229 | |
---|
230 | template< typename pass_type > |
---|
231 | template< typename func_t > |
---|
232 | Statement * PassVisitor< pass_type >::handleStatement( Statement * stmt, func_t func ) { |
---|
233 | if ( ! get_visit_children() ) return stmt; |
---|
234 | |
---|
235 | // don't want statements from outer CompoundStmts to be added to this CompoundStmt |
---|
236 | ValueGuardPtr< TypeSubstitution * > oldEnv ( get_env_ptr () ); |
---|
237 | ValueGuardPtr< DeclList_t > oldBeforeDecls( get_beforeDecls() ); |
---|
238 | ValueGuardPtr< DeclList_t > oldAfterDecls ( get_afterDecls () ); |
---|
239 | ValueGuardPtr< StmtList_t > oldBeforeStmts( get_beforeStmts() ); |
---|
240 | ValueGuardPtr< StmtList_t > oldAfterStmts ( get_afterStmts () ); |
---|
241 | |
---|
242 | Statement *newStmt = func( stmt ); |
---|
243 | |
---|
244 | StmtList_t* beforeStmts = get_beforeStmts(); |
---|
245 | StmtList_t* afterStmts = get_afterStmts(); |
---|
246 | DeclList_t* beforeDecls = get_beforeDecls(); |
---|
247 | DeclList_t* afterDecls = get_afterDecls(); |
---|
248 | |
---|
249 | if( empty(beforeStmts) && empty(afterStmts) && empty(beforeDecls) && empty(afterDecls) ) { return newStmt; } |
---|
250 | assert(( empty( beforeStmts ) && empty( afterStmts )) |
---|
251 | || ( empty( beforeDecls ) && empty( afterDecls )) ); |
---|
252 | |
---|
253 | CompoundStmt *compound = new CompoundStmt(); |
---|
254 | if( !empty(beforeDecls) ) { splice( std::back_inserter( compound->get_kids() ), beforeDecls ); } |
---|
255 | if( !empty(beforeStmts) ) { compound->get_kids().splice( compound->get_kids().end(), *beforeStmts ); } |
---|
256 | compound->get_kids().push_back( newStmt ); |
---|
257 | if( !empty(afterDecls) ) { splice( std::back_inserter( compound->get_kids() ), afterDecls ); } |
---|
258 | if( !empty(afterStmts) ) { compound->get_kids().splice( compound->get_kids().end(), *afterStmts ); } |
---|
259 | return compound; |
---|
260 | } |
---|
261 | |
---|
262 | template< typename pass_type > |
---|
263 | Statement * PassVisitor< pass_type >::visitStatement( Statement * stmt ) { |
---|
264 | return handleStatement( stmt, [this]( Statement * stmt ) { |
---|
265 | maybeAccept_impl( stmt, *this ); |
---|
266 | return stmt; |
---|
267 | }); |
---|
268 | } |
---|
269 | |
---|
270 | template< typename pass_type > |
---|
271 | Statement * PassVisitor< pass_type >::mutateStatement( Statement * stmt ) { |
---|
272 | return handleStatement( stmt, [this]( Statement * stmt ) { |
---|
273 | maybeMutate_impl( stmt, *this ); |
---|
274 | return stmt; |
---|
275 | }); |
---|
276 | } |
---|
277 | |
---|
278 | template< typename pass_type > |
---|
279 | template< typename func_t > |
---|
280 | Expression * PassVisitor< pass_type >::handleExpression( Expression * expr, func_t func ) { |
---|
281 | if ( ! get_visit_children() ) return expr; |
---|
282 | if( !expr ) return nullptr; |
---|
283 | |
---|
284 | auto env_ptr = get_env_ptr(); |
---|
285 | if ( env_ptr && expr->get_env() ) { |
---|
286 | *env_ptr = expr->get_env(); |
---|
287 | } |
---|
288 | |
---|
289 | // should env be moved onto the result of the mutate? |
---|
290 | return func( expr ); |
---|
291 | } |
---|
292 | |
---|
293 | template< typename pass_type > |
---|
294 | Expression * PassVisitor< pass_type >::visitExpression( Expression * expr ) { |
---|
295 | return handleExpression(expr, [this]( Expression * expr ) { |
---|
296 | maybeAccept_impl( expr, *this ); |
---|
297 | return expr; |
---|
298 | }); |
---|
299 | } |
---|
300 | |
---|
301 | template< typename pass_type > |
---|
302 | Expression * PassVisitor< pass_type >::mutateExpression( Expression * expr ) { |
---|
303 | return handleExpression(expr, [this]( Expression * expr ) { |
---|
304 | maybeMutate_impl( expr, *this ); |
---|
305 | return expr; |
---|
306 | }); |
---|
307 | } |
---|
308 | |
---|
309 | template< typename TreeType, typename VisitorType > |
---|
310 | inline void indexerScopedAccept( TreeType * tree, VisitorType & visitor ) { |
---|
311 | if ( ! visitor.get_visit_children() ) return; |
---|
312 | auto guard = makeFuncGuard( |
---|
313 | [&visitor]() { visitor.indexerScopeEnter(); }, |
---|
314 | [&visitor]() { visitor.indexerScopeLeave(); } |
---|
315 | ); |
---|
316 | maybeAccept_impl( tree, visitor ); |
---|
317 | } |
---|
318 | |
---|
319 | template< typename TreeType, typename MutatorType > |
---|
320 | inline void indexerScopedMutate( TreeType *& tree, MutatorType & mutator ) { |
---|
321 | if ( ! mutator.get_visit_children() ) return; |
---|
322 | auto guard = makeFuncGuard( |
---|
323 | [&mutator]() { mutator.indexerScopeEnter(); }, |
---|
324 | [&mutator]() { mutator.indexerScopeLeave(); } |
---|
325 | ); |
---|
326 | maybeMutate_impl( tree, mutator ); |
---|
327 | } |
---|
328 | |
---|
329 | //------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
---|
330 | //======================================================================================================================================================================== |
---|
331 | //======================================================================================================================================================================== |
---|
332 | //======================================================================================================================================================================== |
---|
333 | //======================================================================================================================================================================== |
---|
334 | //======================================================================================================================================================================== |
---|
335 | //------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
---|
336 | |
---|
337 | // A NOTE ON THE ORDER OF TRAVERSAL |
---|
338 | // |
---|
339 | // Types and typedefs have their base types visited before they are added to the type table. This is ok, since there is |
---|
340 | // no such thing as a recursive type or typedef. |
---|
341 | // |
---|
342 | // typedef struct { T *x; } T; // never allowed |
---|
343 | // |
---|
344 | // for structs/unions, it is possible to have recursion, so the decl should be added as if it's incomplete to begin, the |
---|
345 | // members are traversed, and then the complete type should be added (assuming the type is completed by this particular |
---|
346 | // declaration). |
---|
347 | // |
---|
348 | // struct T { struct T *x; }; // allowed |
---|
349 | // |
---|
350 | // It is important to add the complete type to the symbol table *after* the members/base has been traversed, since that |
---|
351 | // traversal may modify the definition of the type and these modifications should be visible when the symbol table is |
---|
352 | // queried later in this pass. |
---|
353 | // |
---|
354 | // TODO: figure out whether recursive contexts are sensible/possible/reasonable. |
---|
355 | |
---|
356 | //-------------------------------------------------------------------------- |
---|
357 | // ObjectDecl |
---|
358 | template< typename pass_type > |
---|
359 | void PassVisitor< pass_type >::visit( ObjectDecl * node ) { |
---|
360 | VISIT_START( node ); |
---|
361 | |
---|
362 | indexerScopedAccept( node->type , *this ); |
---|
363 | maybeAccept_impl ( node->init , *this ); |
---|
364 | maybeAccept_impl ( node->bitfieldWidth, *this ); |
---|
365 | maybeAccept_impl ( node->attributes , *this ); |
---|
366 | |
---|
367 | indexerAddId( node ); |
---|
368 | |
---|
369 | VISIT_END( node ); |
---|
370 | } |
---|
371 | |
---|
372 | template< typename pass_type > |
---|
373 | DeclarationWithType * PassVisitor< pass_type >::mutate( ObjectDecl * node ) { |
---|
374 | MUTATE_START( node ); |
---|
375 | |
---|
376 | indexerScopedMutate( node->type , *this ); |
---|
377 | maybeMutate_impl ( node->init , *this ); |
---|
378 | maybeMutate_impl ( node->bitfieldWidth, *this ); |
---|
379 | maybeMutate_impl ( node->attributes , *this ); |
---|
380 | |
---|
381 | indexerAddId( node ); |
---|
382 | |
---|
383 | MUTATE_END( DeclarationWithType, node ); |
---|
384 | } |
---|
385 | |
---|
386 | //-------------------------------------------------------------------------- |
---|
387 | // FunctionDecl |
---|
388 | template< typename pass_type > |
---|
389 | void PassVisitor< pass_type >::visit( FunctionDecl * node ) { |
---|
390 | VISIT_START( node ); |
---|
391 | |
---|
392 | indexerAddId( node ); |
---|
393 | |
---|
394 | { |
---|
395 | // with clause introduces a level of scope (for the with expression members). |
---|
396 | // with clause exprs are added to the indexer before parameters so that parameters |
---|
397 | // shadow with exprs and not the other way around. |
---|
398 | auto guard = makeFuncGuard( [this]() { indexerScopeEnter(); }, [this]() { indexerScopeLeave(); } ); |
---|
399 | // implicit add __func__ identifier as specified in the C manual 6.4.2.2 |
---|
400 | static ObjectDecl func( |
---|
401 | "__func__", noStorageClasses, LinkageSpec::C, nullptr, |
---|
402 | new ArrayType( Type::Qualifiers(), new BasicType( Type::Qualifiers( Type::Const ), BasicType::Char ), nullptr, true, false ), |
---|
403 | nullptr |
---|
404 | ); |
---|
405 | indexerAddId( &func ); |
---|
406 | maybeAccept_impl( node->type, *this ); |
---|
407 | maybeAccept_impl( node->statements, *this ); |
---|
408 | maybeAccept_impl( node->attributes, *this ); |
---|
409 | } |
---|
410 | |
---|
411 | VISIT_END( node ); |
---|
412 | } |
---|
413 | |
---|
414 | template< typename pass_type > |
---|
415 | DeclarationWithType * PassVisitor< pass_type >::mutate( FunctionDecl * node ) { |
---|
416 | MUTATE_START( node ); |
---|
417 | |
---|
418 | indexerAddId( node ); |
---|
419 | |
---|
420 | { |
---|
421 | // with clause introduces a level of scope (for the with expression members). |
---|
422 | // with clause exprs are added to the indexer before parameters so that parameters |
---|
423 | // shadow with exprs and not the other way around. |
---|
424 | auto guard = makeFuncGuard( [this]() { indexerScopeEnter(); }, [this]() { indexerScopeLeave(); } ); |
---|
425 | // implicit add __func__ identifier as specified in the C manual 6.4.2.2 |
---|
426 | static ObjectDecl func( |
---|
427 | "__func__", noStorageClasses, LinkageSpec::C, nullptr, |
---|
428 | new ArrayType( Type::Qualifiers(), new BasicType( Type::Qualifiers( Type::Const ), BasicType::Char ), nullptr, true, false ), |
---|
429 | nullptr |
---|
430 | ); |
---|
431 | indexerAddId( &func ); |
---|
432 | maybeMutate_impl( node->type, *this ); |
---|
433 | maybeMutate_impl( node->statements, *this ); |
---|
434 | maybeMutate_impl( node->attributes, *this ); |
---|
435 | } |
---|
436 | |
---|
437 | MUTATE_END( DeclarationWithType, node ); |
---|
438 | } |
---|
439 | |
---|
440 | //-------------------------------------------------------------------------- |
---|
441 | // StructDecl |
---|
442 | template< typename pass_type > |
---|
443 | void PassVisitor< pass_type >::visit( StructDecl * node ) { |
---|
444 | VISIT_START( node ); |
---|
445 | |
---|
446 | // make up a forward declaration and add it before processing the members |
---|
447 | // needs to be on the heap because addStruct saves the pointer |
---|
448 | indexerAddStructFwd( node ); |
---|
449 | |
---|
450 | { |
---|
451 | auto guard = makeFuncGuard( [this]() { indexerScopeEnter(); }, [this]() { indexerScopeLeave(); } ); |
---|
452 | maybeAccept_impl( node->parameters, *this ); |
---|
453 | maybeAccept_impl( node->members , *this ); |
---|
454 | } |
---|
455 | |
---|
456 | // this addition replaces the forward declaration |
---|
457 | indexerAddStruct( node ); |
---|
458 | |
---|
459 | VISIT_END( node ); |
---|
460 | } |
---|
461 | |
---|
462 | template< typename pass_type > |
---|
463 | Declaration * PassVisitor< pass_type >::mutate( StructDecl * node ) { |
---|
464 | MUTATE_START( node ); |
---|
465 | |
---|
466 | // make up a forward declaration and add it before processing the members |
---|
467 | // needs to be on the heap because addStruct saves the pointer |
---|
468 | indexerAddStructFwd( node ); |
---|
469 | |
---|
470 | { |
---|
471 | auto guard = makeFuncGuard( [this]() { indexerScopeEnter(); }, [this]() { indexerScopeLeave(); } ); |
---|
472 | maybeMutate_impl( node->parameters, *this ); |
---|
473 | maybeMutate_impl( node->members , *this ); |
---|
474 | } |
---|
475 | |
---|
476 | // this addition replaces the forward declaration |
---|
477 | indexerAddStruct( node ); |
---|
478 | |
---|
479 | MUTATE_END( Declaration, node ); |
---|
480 | } |
---|
481 | |
---|
482 | //-------------------------------------------------------------------------- |
---|
483 | // UnionDecl |
---|
484 | template< typename pass_type > |
---|
485 | void PassVisitor< pass_type >::visit( UnionDecl * node ) { |
---|
486 | VISIT_START( node ); |
---|
487 | |
---|
488 | // make up a forward declaration and add it before processing the members |
---|
489 | indexerAddUnionFwd( node ); |
---|
490 | |
---|
491 | { |
---|
492 | auto guard = makeFuncGuard( [this]() { indexerScopeEnter(); }, [this]() { indexerScopeLeave(); } ); |
---|
493 | maybeAccept_impl( node->parameters, *this ); |
---|
494 | maybeAccept_impl( node->members , *this ); |
---|
495 | } |
---|
496 | |
---|
497 | indexerAddUnion( node ); |
---|
498 | |
---|
499 | VISIT_END( node ); |
---|
500 | } |
---|
501 | |
---|
502 | template< typename pass_type > |
---|
503 | Declaration * PassVisitor< pass_type >::mutate( UnionDecl * node ) { |
---|
504 | MUTATE_START( node ); |
---|
505 | |
---|
506 | // make up a forward declaration and add it before processing the members |
---|
507 | indexerAddUnionFwd( node ); |
---|
508 | |
---|
509 | { |
---|
510 | auto guard = makeFuncGuard( [this]() { indexerScopeEnter(); }, [this]() { indexerScopeLeave(); } ); |
---|
511 | maybeMutate_impl( node->parameters, *this ); |
---|
512 | maybeMutate_impl( node->members , *this ); |
---|
513 | } |
---|
514 | |
---|
515 | indexerAddUnion( node ); |
---|
516 | |
---|
517 | MUTATE_END( Declaration, node ); |
---|
518 | } |
---|
519 | |
---|
520 | //-------------------------------------------------------------------------- |
---|
521 | // EnumDecl |
---|
522 | template< typename pass_type > |
---|
523 | void PassVisitor< pass_type >::visit( EnumDecl * node ) { |
---|
524 | VISIT_START( node ); |
---|
525 | |
---|
526 | indexerAddEnum( node ); |
---|
527 | |
---|
528 | // unlike structs, traits, and unions, enums inject their members into the global scope |
---|
529 | maybeAccept_impl( node->parameters, *this ); |
---|
530 | maybeAccept_impl( node->members , *this ); |
---|
531 | |
---|
532 | VISIT_END( node ); |
---|
533 | } |
---|
534 | |
---|
535 | template< typename pass_type > |
---|
536 | Declaration * PassVisitor< pass_type >::mutate( EnumDecl * node ) { |
---|
537 | MUTATE_START( node ); |
---|
538 | |
---|
539 | indexerAddEnum( node ); |
---|
540 | |
---|
541 | // unlike structs, traits, and unions, enums inject their members into the global scope |
---|
542 | maybeMutate_impl( node->parameters, *this ); |
---|
543 | maybeMutate_impl( node->members , *this ); |
---|
544 | |
---|
545 | MUTATE_END( Declaration, node ); |
---|
546 | } |
---|
547 | |
---|
548 | //-------------------------------------------------------------------------- |
---|
549 | // TraitDecl |
---|
550 | template< typename pass_type > |
---|
551 | void PassVisitor< pass_type >::visit( TraitDecl * node ) { |
---|
552 | VISIT_START( node ); |
---|
553 | |
---|
554 | { |
---|
555 | auto guard = makeFuncGuard( [this]() { indexerScopeEnter(); }, [this]() { indexerScopeLeave(); } ); |
---|
556 | maybeAccept_impl( node->parameters, *this ); |
---|
557 | maybeAccept_impl( node->members , *this ); |
---|
558 | } |
---|
559 | |
---|
560 | indexerAddTrait( node ); |
---|
561 | |
---|
562 | VISIT_END( node ); |
---|
563 | } |
---|
564 | |
---|
565 | template< typename pass_type > |
---|
566 | Declaration * PassVisitor< pass_type >::mutate( TraitDecl * node ) { |
---|
567 | MUTATE_START( node ); |
---|
568 | |
---|
569 | { |
---|
570 | auto guard = makeFuncGuard( [this]() { indexerScopeEnter(); }, [this]() { indexerScopeLeave(); } ); |
---|
571 | maybeMutate_impl( node->parameters, *this ); |
---|
572 | maybeMutate_impl( node->members , *this ); |
---|
573 | } |
---|
574 | |
---|
575 | indexerAddTrait( node ); |
---|
576 | |
---|
577 | MUTATE_END( Declaration, node ); |
---|
578 | } |
---|
579 | |
---|
580 | //-------------------------------------------------------------------------- |
---|
581 | // TypeDecl |
---|
582 | template< typename pass_type > |
---|
583 | void PassVisitor< pass_type >::visit( TypeDecl * node ) { |
---|
584 | VISIT_START( node ); |
---|
585 | |
---|
586 | { |
---|
587 | auto guard = makeFuncGuard( [this]() { indexerScopeEnter(); }, [this]() { indexerScopeLeave(); } ); |
---|
588 | maybeAccept_impl( node->parameters, *this ); |
---|
589 | maybeAccept_impl( node->base , *this ); |
---|
590 | } |
---|
591 | |
---|
592 | // see A NOTE ON THE ORDER OF TRAVERSAL, above |
---|
593 | // note that assertions come after the type is added to the symtab, since they are not part of the type proper |
---|
594 | // and may depend on the type itself |
---|
595 | indexerAddType( node ); |
---|
596 | |
---|
597 | maybeAccept_impl( node->assertions, *this ); |
---|
598 | |
---|
599 | indexerScopedAccept( node->init, *this ); |
---|
600 | |
---|
601 | VISIT_END( node ); |
---|
602 | } |
---|
603 | |
---|
604 | template< typename pass_type > |
---|
605 | Declaration * PassVisitor< pass_type >::mutate( TypeDecl * node ) { |
---|
606 | MUTATE_START( node ); |
---|
607 | |
---|
608 | { |
---|
609 | auto guard = makeFuncGuard( [this]() { indexerScopeEnter(); }, [this]() { indexerScopeLeave(); } ); |
---|
610 | maybeMutate_impl( node->parameters, *this ); |
---|
611 | maybeMutate_impl( node->base , *this ); |
---|
612 | } |
---|
613 | |
---|
614 | // see A NOTE ON THE ORDER OF TRAVERSAL, above |
---|
615 | // note that assertions come after the type is added to the symtab, since they are not part of the type proper |
---|
616 | // and may depend on the type itself |
---|
617 | indexerAddType( node ); |
---|
618 | |
---|
619 | maybeMutate_impl( node->assertions, *this ); |
---|
620 | |
---|
621 | indexerScopedMutate( node->init, *this ); |
---|
622 | |
---|
623 | MUTATE_END( Declaration, node ); |
---|
624 | } |
---|
625 | |
---|
626 | //-------------------------------------------------------------------------- |
---|
627 | // TypedefDecl |
---|
628 | template< typename pass_type > |
---|
629 | void PassVisitor< pass_type >::visit( TypedefDecl * node ) { |
---|
630 | VISIT_START( node ); |
---|
631 | |
---|
632 | { |
---|
633 | auto guard = makeFuncGuard( [this]() { indexerScopeEnter(); }, [this]() { indexerScopeLeave(); } ); |
---|
634 | maybeAccept_impl( node->parameters, *this ); |
---|
635 | maybeAccept_impl( node->base , *this ); |
---|
636 | } |
---|
637 | |
---|
638 | indexerAddType( node ); |
---|
639 | |
---|
640 | maybeAccept_impl( node->assertions, *this ); |
---|
641 | |
---|
642 | VISIT_END( node ); |
---|
643 | } |
---|
644 | |
---|
645 | template< typename pass_type > |
---|
646 | Declaration * PassVisitor< pass_type >::mutate( TypedefDecl * node ) { |
---|
647 | MUTATE_START( node ); |
---|
648 | |
---|
649 | { |
---|
650 | auto guard = makeFuncGuard( [this]() { indexerScopeEnter(); }, [this]() { indexerScopeLeave(); } ); |
---|
651 | maybeMutate_impl( node->parameters, *this ); |
---|
652 | maybeMutate_impl( node->base , *this ); |
---|
653 | } |
---|
654 | |
---|
655 | indexerAddType( node ); |
---|
656 | |
---|
657 | maybeMutate_impl( node->assertions, *this ); |
---|
658 | |
---|
659 | MUTATE_END( Declaration, node ); |
---|
660 | } |
---|
661 | |
---|
662 | //-------------------------------------------------------------------------- |
---|
663 | // AsmDecl |
---|
664 | template< typename pass_type > |
---|
665 | void PassVisitor< pass_type >::visit( AsmDecl * node ) { |
---|
666 | VISIT_START( node ); |
---|
667 | |
---|
668 | maybeAccept_impl( node->stmt, *this ); |
---|
669 | |
---|
670 | VISIT_END( node ); |
---|
671 | } |
---|
672 | |
---|
673 | template< typename pass_type > |
---|
674 | AsmDecl * PassVisitor< pass_type >::mutate( AsmDecl * node ) { |
---|
675 | MUTATE_START( node ); |
---|
676 | |
---|
677 | maybeMutate_impl( node->stmt, *this ); |
---|
678 | |
---|
679 | MUTATE_END( AsmDecl, node ); |
---|
680 | } |
---|
681 | |
---|
682 | //-------------------------------------------------------------------------- |
---|
683 | // CompoundStmt |
---|
684 | template< typename pass_type > |
---|
685 | void PassVisitor< pass_type >::visit( CompoundStmt * node ) { |
---|
686 | VISIT_START( node ); |
---|
687 | { |
---|
688 | auto guard1 = makeFuncGuard( [this]() { indexerScopeEnter(); }, [this]() { indexerScopeLeave(); } ); |
---|
689 | auto guard2 = makeFuncGuard( [this]() { call_beginScope(); }, [this]() { call_endScope(); } ); |
---|
690 | visitStatementList( node->kids ); |
---|
691 | } |
---|
692 | VISIT_END( node ); |
---|
693 | } |
---|
694 | |
---|
695 | template< typename pass_type > |
---|
696 | CompoundStmt * PassVisitor< pass_type >::mutate( CompoundStmt * node ) { |
---|
697 | MUTATE_START( node ); |
---|
698 | { |
---|
699 | auto guard1 = makeFuncGuard( [this]() { indexerScopeEnter(); }, [this]() { indexerScopeLeave(); } ); |
---|
700 | auto guard2 = makeFuncGuard( [this]() { call_beginScope(); }, [this]() { call_endScope(); } ); |
---|
701 | mutateStatementList( node->kids ); |
---|
702 | } |
---|
703 | MUTATE_END( CompoundStmt, node ); |
---|
704 | } |
---|
705 | |
---|
706 | //-------------------------------------------------------------------------- |
---|
707 | // ExprStmt |
---|
708 | template< typename pass_type > |
---|
709 | void PassVisitor< pass_type >::visit( ExprStmt * node ) { |
---|
710 | VISIT_START( node ); |
---|
711 | |
---|
712 | visitExpression( node->expr ); |
---|
713 | |
---|
714 | VISIT_END( node ); |
---|
715 | } |
---|
716 | |
---|
717 | template< typename pass_type > |
---|
718 | Statement * PassVisitor< pass_type >::mutate( ExprStmt * node ) { |
---|
719 | MUTATE_START( node ); |
---|
720 | |
---|
721 | node->expr = mutateExpression( node->expr ); |
---|
722 | |
---|
723 | MUTATE_END( Statement, node ); |
---|
724 | } |
---|
725 | |
---|
726 | //-------------------------------------------------------------------------- |
---|
727 | // AsmStmt |
---|
728 | template< typename pass_type > |
---|
729 | void PassVisitor< pass_type >::visit( AsmStmt * node ) { |
---|
730 | VISIT_BODY( node ); |
---|
731 | } |
---|
732 | |
---|
733 | template< typename pass_type > |
---|
734 | Statement * PassVisitor< pass_type >::mutate( AsmStmt * node ) { |
---|
735 | MUTATE_BODY( Statement, node ); |
---|
736 | } |
---|
737 | |
---|
738 | //-------------------------------------------------------------------------- |
---|
739 | // IfStmt |
---|
740 | template< typename pass_type > |
---|
741 | void PassVisitor< pass_type >::visit( IfStmt * node ) { |
---|
742 | VISIT_START( node ); |
---|
743 | { |
---|
744 | // if statements introduce a level of scope (for the initialization) |
---|
745 | auto guard = makeFuncGuard( [this]() { indexerScopeEnter(); }, [this]() { indexerScopeLeave(); } ); |
---|
746 | maybeAccept_impl( node->get_initialization(), *this ); |
---|
747 | visitExpression ( node->condition ); |
---|
748 | node->thenPart = visitStatement( node->thenPart ); |
---|
749 | node->elsePart = visitStatement( node->elsePart ); |
---|
750 | } |
---|
751 | VISIT_END( node ); |
---|
752 | } |
---|
753 | |
---|
754 | template< typename pass_type > |
---|
755 | Statement * PassVisitor< pass_type >::mutate( IfStmt * node ) { |
---|
756 | MUTATE_START( node ); |
---|
757 | { |
---|
758 | // if statements introduce a level of scope (for the initialization) |
---|
759 | auto guard = makeFuncGuard( [this]() { indexerScopeEnter(); }, [this]() { indexerScopeLeave(); } ); |
---|
760 | maybeMutate_impl( node->get_initialization(), *this ); |
---|
761 | node->condition = mutateExpression( node->condition ); |
---|
762 | node->thenPart = mutateStatement ( node->thenPart ); |
---|
763 | node->elsePart = mutateStatement ( node->elsePart ); |
---|
764 | } |
---|
765 | MUTATE_END( Statement, node ); |
---|
766 | } |
---|
767 | |
---|
768 | //-------------------------------------------------------------------------- |
---|
769 | // WhileStmt |
---|
770 | template< typename pass_type > |
---|
771 | void PassVisitor< pass_type >::visit( WhileStmt * node ) { |
---|
772 | VISIT_START( node ); |
---|
773 | |
---|
774 | visitExpression( node->condition ); |
---|
775 | node->body = visitStatement( node->body ); |
---|
776 | |
---|
777 | VISIT_END( node ); |
---|
778 | } |
---|
779 | |
---|
780 | template< typename pass_type > |
---|
781 | Statement * PassVisitor< pass_type >::mutate( WhileStmt * node ) { |
---|
782 | MUTATE_START( node ); |
---|
783 | |
---|
784 | node->condition = mutateExpression( node->condition ); |
---|
785 | node->body = mutateStatement ( node->body ); |
---|
786 | |
---|
787 | MUTATE_END( Statement, node ); |
---|
788 | } |
---|
789 | |
---|
790 | //-------------------------------------------------------------------------- |
---|
791 | // ForStmt |
---|
792 | template< typename pass_type > |
---|
793 | void PassVisitor< pass_type >::visit( ForStmt * node ) { |
---|
794 | VISIT_START( node ); |
---|
795 | { |
---|
796 | // for statements introduce a level of scope (for the initialization) |
---|
797 | auto guard = makeFuncGuard( [this]() { indexerScopeEnter(); }, [this]() { indexerScopeLeave(); } ); |
---|
798 | maybeAccept_impl( node->initialization, *this ); |
---|
799 | visitExpression( node->condition ); |
---|
800 | visitExpression( node->increment ); |
---|
801 | node->body = visitStatement( node->body ); |
---|
802 | } |
---|
803 | VISIT_END( node ); |
---|
804 | } |
---|
805 | |
---|
806 | template< typename pass_type > |
---|
807 | Statement * PassVisitor< pass_type >::mutate( ForStmt * node ) { |
---|
808 | MUTATE_START( node ); |
---|
809 | { |
---|
810 | // for statements introduce a level of scope (for the initialization) |
---|
811 | auto guard = makeFuncGuard( [this]() { indexerScopeEnter(); }, [this]() { indexerScopeLeave(); } ); |
---|
812 | maybeMutate_impl( node->initialization, *this ); |
---|
813 | node->condition = mutateExpression( node->condition ); |
---|
814 | node->increment = mutateExpression( node->increment ); |
---|
815 | node->body = mutateStatement ( node->body ); |
---|
816 | } |
---|
817 | MUTATE_END( Statement, node ); |
---|
818 | } |
---|
819 | |
---|
820 | //-------------------------------------------------------------------------- |
---|
821 | // SwitchStmt |
---|
822 | template< typename pass_type > |
---|
823 | void PassVisitor< pass_type >::visit( SwitchStmt * node ) { |
---|
824 | VISIT_START( node ); |
---|
825 | |
---|
826 | visitExpression ( node->condition ); |
---|
827 | visitStatementList( node->statements ); |
---|
828 | |
---|
829 | VISIT_END( node ); |
---|
830 | } |
---|
831 | |
---|
832 | template< typename pass_type > |
---|
833 | Statement * PassVisitor< pass_type >::mutate( SwitchStmt * node ) { |
---|
834 | MUTATE_START( node ); |
---|
835 | |
---|
836 | node->condition = mutateExpression( node->condition ); |
---|
837 | mutateStatementList( node->statements ); |
---|
838 | |
---|
839 | MUTATE_END( Statement, node ); |
---|
840 | } |
---|
841 | |
---|
842 | //-------------------------------------------------------------------------- |
---|
843 | // CaseStmt |
---|
844 | template< typename pass_type > |
---|
845 | void PassVisitor< pass_type >::visit( CaseStmt * node ) { |
---|
846 | VISIT_START( node ); |
---|
847 | |
---|
848 | visitExpression ( node->condition ); |
---|
849 | visitStatementList( node->stmts ); |
---|
850 | |
---|
851 | VISIT_END( node ); |
---|
852 | } |
---|
853 | |
---|
854 | template< typename pass_type > |
---|
855 | Statement * PassVisitor< pass_type >::mutate( CaseStmt * node ) { |
---|
856 | MUTATE_START( node ); |
---|
857 | |
---|
858 | node->condition = mutateExpression( node->condition ); |
---|
859 | mutateStatementList( node->stmts ); |
---|
860 | |
---|
861 | MUTATE_END( Statement, node ); |
---|
862 | } |
---|
863 | |
---|
864 | //-------------------------------------------------------------------------- |
---|
865 | // BranchStmt |
---|
866 | template< typename pass_type > |
---|
867 | void PassVisitor< pass_type >::visit( BranchStmt * node ) { |
---|
868 | VISIT_BODY( node ); |
---|
869 | } |
---|
870 | |
---|
871 | template< typename pass_type > |
---|
872 | Statement * PassVisitor< pass_type >::mutate( BranchStmt * node ) { |
---|
873 | MUTATE_BODY( Statement, node ); |
---|
874 | } |
---|
875 | |
---|
876 | //-------------------------------------------------------------------------- |
---|
877 | // ReturnStmt |
---|
878 | template< typename pass_type > |
---|
879 | void PassVisitor< pass_type >::visit( ReturnStmt * node ) { |
---|
880 | VISIT_START( node ); |
---|
881 | |
---|
882 | visitExpression( node->expr ); |
---|
883 | |
---|
884 | VISIT_END( node ); |
---|
885 | } |
---|
886 | |
---|
887 | template< typename pass_type > |
---|
888 | Statement * PassVisitor< pass_type >::mutate( ReturnStmt * node ) { |
---|
889 | MUTATE_START( node ); |
---|
890 | |
---|
891 | node->expr = mutateExpression( node->expr ); |
---|
892 | |
---|
893 | MUTATE_END( Statement, node ); |
---|
894 | } |
---|
895 | |
---|
896 | //-------------------------------------------------------------------------- |
---|
897 | // ThrowStmt |
---|
898 | |
---|
899 | template< typename pass_type > |
---|
900 | void PassVisitor< pass_type >::visit( ThrowStmt * node ) { |
---|
901 | VISIT_BODY( node ); |
---|
902 | } |
---|
903 | |
---|
904 | template< typename pass_type > |
---|
905 | Statement * PassVisitor< pass_type >::mutate( ThrowStmt * node ) { |
---|
906 | MUTATE_BODY( Statement, node ); |
---|
907 | } |
---|
908 | |
---|
909 | //-------------------------------------------------------------------------- |
---|
910 | // TryStmt |
---|
911 | template< typename pass_type > |
---|
912 | void PassVisitor< pass_type >::visit( TryStmt * node ) { |
---|
913 | VISIT_START( node ); |
---|
914 | |
---|
915 | maybeAccept_impl( node->block , *this ); |
---|
916 | maybeAccept_impl( node->handlers , *this ); |
---|
917 | maybeAccept_impl( node->finallyBlock, *this ); |
---|
918 | |
---|
919 | VISIT_END( node ); |
---|
920 | } |
---|
921 | |
---|
922 | template< typename pass_type > |
---|
923 | Statement * PassVisitor< pass_type >::mutate( TryStmt * node ) { |
---|
924 | MUTATE_START( node ); |
---|
925 | |
---|
926 | maybeMutate_impl( node->block , *this ); |
---|
927 | maybeMutate_impl( node->handlers , *this ); |
---|
928 | maybeMutate_impl( node->finallyBlock, *this ); |
---|
929 | |
---|
930 | MUTATE_END( Statement, node ); |
---|
931 | } |
---|
932 | |
---|
933 | //-------------------------------------------------------------------------- |
---|
934 | // CatchStmt |
---|
935 | template< typename pass_type > |
---|
936 | void PassVisitor< pass_type >::visit( CatchStmt * node ) { |
---|
937 | VISIT_START( node ); |
---|
938 | { |
---|
939 | // catch statements introduce a level of scope (for the caught exception) |
---|
940 | auto guard = makeFuncGuard( [this]() { indexerScopeEnter(); }, [this]() { indexerScopeLeave(); } ); |
---|
941 | maybeAccept_impl( node->decl, *this ); |
---|
942 | node->cond = visitExpression( node->cond ); |
---|
943 | node->body = visitStatement ( node->body ); |
---|
944 | } |
---|
945 | VISIT_END( node ); |
---|
946 | } |
---|
947 | |
---|
948 | template< typename pass_type > |
---|
949 | Statement * PassVisitor< pass_type >::mutate( CatchStmt * node ) { |
---|
950 | MUTATE_START( node ); |
---|
951 | { |
---|
952 | // catch statements introduce a level of scope (for the caught exception) |
---|
953 | auto guard = makeFuncGuard( [this]() { indexerScopeEnter(); }, [this]() { indexerScopeLeave(); } ); |
---|
954 | maybeMutate_impl( node->decl, *this ); |
---|
955 | node->cond = mutateExpression( node->cond ); |
---|
956 | node->body = mutateStatement ( node->body ); |
---|
957 | } |
---|
958 | MUTATE_END( Statement, node ); |
---|
959 | } |
---|
960 | |
---|
961 | //-------------------------------------------------------------------------- |
---|
962 | // FinallyStmt |
---|
963 | template< typename pass_type > |
---|
964 | void PassVisitor< pass_type >::visit( FinallyStmt * node ) { |
---|
965 | VISIT_BODY( node ); |
---|
966 | } |
---|
967 | |
---|
968 | template< typename pass_type > |
---|
969 | Statement * PassVisitor< pass_type >::mutate( FinallyStmt * node ) { |
---|
970 | MUTATE_BODY( Statement, node ); |
---|
971 | } |
---|
972 | |
---|
973 | //-------------------------------------------------------------------------- |
---|
974 | // WaitForStmt |
---|
975 | template< typename pass_type > |
---|
976 | void PassVisitor< pass_type >::visit( WaitForStmt * node ) { |
---|
977 | VISIT_BODY( node ); |
---|
978 | } |
---|
979 | |
---|
980 | template< typename pass_type > |
---|
981 | Statement * PassVisitor< pass_type >::mutate( WaitForStmt * node ) { |
---|
982 | MUTATE_BODY( Statement, node ); |
---|
983 | } |
---|
984 | |
---|
985 | |
---|
986 | |
---|
987 | //-------------------------------------------------------------------------- |
---|
988 | // NullStmt |
---|
989 | template< typename pass_type > |
---|
990 | void PassVisitor< pass_type >::visit( WithStmt * node ) { |
---|
991 | VISIT_START( node ); |
---|
992 | maybeAccept_impl( node->exprs, *this ); |
---|
993 | { |
---|
994 | // catch statements introduce a level of scope (for the caught exception) |
---|
995 | auto guard = makeFuncGuard( [this]() { indexerScopeEnter(); }, [this]() { indexerScopeLeave(); } ); |
---|
996 | indexerAddWith( node ); |
---|
997 | maybeAccept_impl( node->stmt, *this ); |
---|
998 | } |
---|
999 | VISIT_END( node ); |
---|
1000 | } |
---|
1001 | |
---|
1002 | template< typename pass_type > |
---|
1003 | Statement * PassVisitor< pass_type >::mutate( WithStmt * node ) { |
---|
1004 | MUTATE_START( node ); |
---|
1005 | maybeMutate_impl( node->exprs, *this ); |
---|
1006 | { |
---|
1007 | // catch statements introduce a level of scope (for the caught exception) |
---|
1008 | auto guard = makeFuncGuard( [this]() { indexerScopeEnter(); }, [this]() { indexerScopeLeave(); } ); |
---|
1009 | indexerAddWith( node ); |
---|
1010 | maybeMutate_impl( node->stmt, *this ); |
---|
1011 | } |
---|
1012 | MUTATE_END( Statement, node ); |
---|
1013 | } |
---|
1014 | |
---|
1015 | //-------------------------------------------------------------------------- |
---|
1016 | // NullStmt |
---|
1017 | template< typename pass_type > |
---|
1018 | void PassVisitor< pass_type >::visit( NullStmt * node ) { |
---|
1019 | VISIT_BODY( node ); |
---|
1020 | } |
---|
1021 | |
---|
1022 | template< typename pass_type > |
---|
1023 | NullStmt * PassVisitor< pass_type >::mutate( NullStmt * node ) { |
---|
1024 | MUTATE_BODY( NullStmt, node ); |
---|
1025 | } |
---|
1026 | |
---|
1027 | //-------------------------------------------------------------------------- |
---|
1028 | // DeclStmt |
---|
1029 | template< typename pass_type > |
---|
1030 | void PassVisitor< pass_type >::visit( DeclStmt * node ) { |
---|
1031 | VISIT_BODY( node ); |
---|
1032 | } |
---|
1033 | |
---|
1034 | template< typename pass_type > |
---|
1035 | Statement * PassVisitor< pass_type >::mutate( DeclStmt * node ) { |
---|
1036 | MUTATE_BODY( Statement, node ); |
---|
1037 | } |
---|
1038 | |
---|
1039 | //-------------------------------------------------------------------------- |
---|
1040 | // ImplicitCtorDtorStmt |
---|
1041 | template< typename pass_type > |
---|
1042 | void PassVisitor< pass_type >::visit( ImplicitCtorDtorStmt * node ) { |
---|
1043 | VISIT_BODY( node ); |
---|
1044 | } |
---|
1045 | |
---|
1046 | template< typename pass_type > |
---|
1047 | Statement * PassVisitor< pass_type >::mutate( ImplicitCtorDtorStmt * node ) { |
---|
1048 | MUTATE_BODY( Statement, node ); |
---|
1049 | } |
---|
1050 | |
---|
1051 | //-------------------------------------------------------------------------- |
---|
1052 | // ApplicationExpr |
---|
1053 | template< typename pass_type > |
---|
1054 | void PassVisitor< pass_type >::visit( ApplicationExpr * node ) { |
---|
1055 | VISIT_START( node ); |
---|
1056 | |
---|
1057 | indexerScopedAccept( node->result , *this ); |
---|
1058 | maybeAccept_impl ( node->function, *this ); |
---|
1059 | maybeAccept_impl ( node->args , *this ); |
---|
1060 | |
---|
1061 | VISIT_END( node ); |
---|
1062 | } |
---|
1063 | |
---|
1064 | template< typename pass_type > |
---|
1065 | Expression * PassVisitor< pass_type >::mutate( ApplicationExpr * node ) { |
---|
1066 | MUTATE_START( node ); |
---|
1067 | |
---|
1068 | indexerScopedMutate( node->env , *this ); |
---|
1069 | indexerScopedMutate( node->result , *this ); |
---|
1070 | maybeMutate_impl ( node->function, *this ); |
---|
1071 | maybeMutate_impl ( node->args , *this ); |
---|
1072 | |
---|
1073 | MUTATE_END( Expression, node ); |
---|
1074 | } |
---|
1075 | |
---|
1076 | //-------------------------------------------------------------------------- |
---|
1077 | // UntypedExpr |
---|
1078 | template< typename pass_type > |
---|
1079 | void PassVisitor< pass_type >::visit( UntypedExpr * node ) { |
---|
1080 | VISIT_START( node ); |
---|
1081 | |
---|
1082 | // maybeAccept_impl( node->get_env(), *this ); |
---|
1083 | indexerScopedAccept( node->result, *this ); |
---|
1084 | |
---|
1085 | for ( auto expr : node->args ) { |
---|
1086 | visitExpression( expr ); |
---|
1087 | } |
---|
1088 | |
---|
1089 | VISIT_END( node ); |
---|
1090 | } |
---|
1091 | |
---|
1092 | template< typename pass_type > |
---|
1093 | Expression * PassVisitor< pass_type >::mutate( UntypedExpr * node ) { |
---|
1094 | MUTATE_START( node ); |
---|
1095 | |
---|
1096 | indexerScopedMutate( node->env , *this ); |
---|
1097 | indexerScopedMutate( node->result, *this ); |
---|
1098 | |
---|
1099 | for ( auto& expr : node->args ) { |
---|
1100 | expr = mutateExpression( expr ); |
---|
1101 | } |
---|
1102 | |
---|
1103 | MUTATE_END( Expression, node ); |
---|
1104 | } |
---|
1105 | |
---|
1106 | //-------------------------------------------------------------------------- |
---|
1107 | // NameExpr |
---|
1108 | template< typename pass_type > |
---|
1109 | void PassVisitor< pass_type >::visit( NameExpr * node ) { |
---|
1110 | VISIT_START( node ); |
---|
1111 | |
---|
1112 | indexerScopedAccept( node->result, *this ); |
---|
1113 | |
---|
1114 | VISIT_END( node ); |
---|
1115 | } |
---|
1116 | |
---|
1117 | template< typename pass_type > |
---|
1118 | Expression * PassVisitor< pass_type >::mutate( NameExpr * node ) { |
---|
1119 | MUTATE_START( node ); |
---|
1120 | |
---|
1121 | indexerScopedMutate( node->env , *this ); |
---|
1122 | indexerScopedMutate( node->result, *this ); |
---|
1123 | |
---|
1124 | MUTATE_END( Expression, node ); |
---|
1125 | } |
---|
1126 | |
---|
1127 | //-------------------------------------------------------------------------- |
---|
1128 | // CastExpr |
---|
1129 | template< typename pass_type > |
---|
1130 | void PassVisitor< pass_type >::visit( CastExpr * node ) { |
---|
1131 | VISIT_START( node ); |
---|
1132 | |
---|
1133 | indexerScopedAccept( node->result, *this ); |
---|
1134 | maybeAccept_impl ( node->arg , *this ); |
---|
1135 | |
---|
1136 | VISIT_END( node ); |
---|
1137 | } |
---|
1138 | |
---|
1139 | template< typename pass_type > |
---|
1140 | Expression * PassVisitor< pass_type >::mutate( CastExpr * node ) { |
---|
1141 | MUTATE_START( node ); |
---|
1142 | |
---|
1143 | indexerScopedMutate( node->env , *this ); |
---|
1144 | indexerScopedMutate( node->result, *this ); |
---|
1145 | maybeMutate_impl ( node->arg , *this ); |
---|
1146 | |
---|
1147 | MUTATE_END( Expression, node ); |
---|
1148 | } |
---|
1149 | |
---|
1150 | //-------------------------------------------------------------------------- |
---|
1151 | // VirtualCastExpr |
---|
1152 | template< typename pass_type > |
---|
1153 | void PassVisitor< pass_type >::visit( VirtualCastExpr * node ) { |
---|
1154 | VISIT_START( node ); |
---|
1155 | |
---|
1156 | indexerScopedAccept( node->result, *this ); |
---|
1157 | maybeAccept_impl( node->arg, *this ); |
---|
1158 | |
---|
1159 | VISIT_END( node ); |
---|
1160 | } |
---|
1161 | |
---|
1162 | template< typename pass_type > |
---|
1163 | Expression * PassVisitor< pass_type >::mutate( VirtualCastExpr * node ) { |
---|
1164 | MUTATE_START( node ); |
---|
1165 | |
---|
1166 | indexerScopedMutate( node->env , *this ); |
---|
1167 | indexerScopedMutate( node->result, *this ); |
---|
1168 | maybeMutate_impl ( node->arg , *this ); |
---|
1169 | |
---|
1170 | MUTATE_END( Expression, node ); |
---|
1171 | } |
---|
1172 | |
---|
1173 | //-------------------------------------------------------------------------- |
---|
1174 | // AddressExpr |
---|
1175 | template< typename pass_type > |
---|
1176 | void PassVisitor< pass_type >::visit( AddressExpr * node ) { |
---|
1177 | VISIT_START( node ); |
---|
1178 | |
---|
1179 | indexerScopedAccept( node->result, *this ); |
---|
1180 | maybeAccept_impl ( node->arg , *this ); |
---|
1181 | |
---|
1182 | VISIT_END( node ); |
---|
1183 | } |
---|
1184 | |
---|
1185 | template< typename pass_type > |
---|
1186 | Expression * PassVisitor< pass_type >::mutate( AddressExpr * node ) { |
---|
1187 | MUTATE_START( node ); |
---|
1188 | |
---|
1189 | indexerScopedMutate( node->env , *this ); |
---|
1190 | indexerScopedMutate( node->result, *this ); |
---|
1191 | maybeMutate_impl ( node->arg , *this ); |
---|
1192 | |
---|
1193 | MUTATE_END( Expression, node ); |
---|
1194 | } |
---|
1195 | |
---|
1196 | //-------------------------------------------------------------------------- |
---|
1197 | // LabelAddressExpr |
---|
1198 | template< typename pass_type > |
---|
1199 | void PassVisitor< pass_type >::visit( LabelAddressExpr * node ) { |
---|
1200 | VISIT_START( node ); |
---|
1201 | |
---|
1202 | indexerScopedAccept( node->result, *this ); |
---|
1203 | |
---|
1204 | VISIT_END( node ); |
---|
1205 | } |
---|
1206 | |
---|
1207 | template< typename pass_type > |
---|
1208 | Expression * PassVisitor< pass_type >::mutate( LabelAddressExpr * node ) { |
---|
1209 | MUTATE_START( node ); |
---|
1210 | |
---|
1211 | indexerScopedMutate( node->env , *this ); |
---|
1212 | indexerScopedMutate( node->result, *this ); |
---|
1213 | |
---|
1214 | MUTATE_END( Expression, node ); |
---|
1215 | } |
---|
1216 | |
---|
1217 | //-------------------------------------------------------------------------- |
---|
1218 | // UntypedMemberExpr |
---|
1219 | template< typename pass_type > |
---|
1220 | void PassVisitor< pass_type >::visit( UntypedMemberExpr * node ) { |
---|
1221 | VISIT_START( node ); |
---|
1222 | |
---|
1223 | indexerScopedAccept( node->result , *this ); |
---|
1224 | maybeAccept_impl ( node->aggregate, *this ); |
---|
1225 | maybeAccept_impl ( node->member , *this ); |
---|
1226 | |
---|
1227 | VISIT_END( node ); |
---|
1228 | } |
---|
1229 | |
---|
1230 | template< typename pass_type > |
---|
1231 | Expression * PassVisitor< pass_type >::mutate( UntypedMemberExpr * node ) { |
---|
1232 | MUTATE_START( node ); |
---|
1233 | |
---|
1234 | indexerScopedMutate( node->env , *this ); |
---|
1235 | indexerScopedMutate( node->result , *this ); |
---|
1236 | maybeMutate_impl ( node->aggregate, *this ); |
---|
1237 | maybeMutate_impl ( node->member , *this ); |
---|
1238 | |
---|
1239 | MUTATE_END( Expression, node ); |
---|
1240 | } |
---|
1241 | |
---|
1242 | //-------------------------------------------------------------------------- |
---|
1243 | // MemberExpr |
---|
1244 | template< typename pass_type > |
---|
1245 | void PassVisitor< pass_type >::visit( MemberExpr * node ) { |
---|
1246 | VISIT_START( node ); |
---|
1247 | |
---|
1248 | indexerScopedAccept( node->result , *this ); |
---|
1249 | maybeAccept_impl ( node->aggregate, *this ); |
---|
1250 | |
---|
1251 | VISIT_END( node ); |
---|
1252 | } |
---|
1253 | |
---|
1254 | template< typename pass_type > |
---|
1255 | Expression * PassVisitor< pass_type >::mutate( MemberExpr * node ) { |
---|
1256 | MUTATE_START( node ); |
---|
1257 | |
---|
1258 | indexerScopedMutate( node->env , *this ); |
---|
1259 | indexerScopedMutate( node->result , *this ); |
---|
1260 | maybeMutate_impl ( node->aggregate, *this ); |
---|
1261 | |
---|
1262 | MUTATE_END( Expression, node ); |
---|
1263 | } |
---|
1264 | |
---|
1265 | //-------------------------------------------------------------------------- |
---|
1266 | // VariableExpr |
---|
1267 | template< typename pass_type > |
---|
1268 | void PassVisitor< pass_type >::visit( VariableExpr * node ) { |
---|
1269 | VISIT_START( node ); |
---|
1270 | |
---|
1271 | indexerScopedAccept( node->result, *this ); |
---|
1272 | |
---|
1273 | VISIT_END( node ); |
---|
1274 | } |
---|
1275 | |
---|
1276 | template< typename pass_type > |
---|
1277 | Expression * PassVisitor< pass_type >::mutate( VariableExpr * node ) { |
---|
1278 | MUTATE_START( node ); |
---|
1279 | |
---|
1280 | indexerScopedMutate( node->env , *this ); |
---|
1281 | indexerScopedMutate( node->result, *this ); |
---|
1282 | |
---|
1283 | MUTATE_END( Expression, node ); |
---|
1284 | } |
---|
1285 | |
---|
1286 | //-------------------------------------------------------------------------- |
---|
1287 | // ConstantExpr |
---|
1288 | template< typename pass_type > |
---|
1289 | void PassVisitor< pass_type >::visit( ConstantExpr * node ) { |
---|
1290 | VISIT_START( node ); |
---|
1291 | |
---|
1292 | indexerScopedAccept( node->result , *this ); |
---|
1293 | maybeAccept_impl ( &node->constant, *this ); |
---|
1294 | |
---|
1295 | VISIT_END( node ); |
---|
1296 | } |
---|
1297 | |
---|
1298 | template< typename pass_type > |
---|
1299 | Expression * PassVisitor< pass_type >::mutate( ConstantExpr * node ) { |
---|
1300 | MUTATE_START( node ); |
---|
1301 | |
---|
1302 | indexerScopedMutate( node->env , *this ); |
---|
1303 | indexerScopedMutate( node->result, *this ); |
---|
1304 | Constant * ptr = &node->constant; |
---|
1305 | maybeMutate_impl( ptr, *this ); |
---|
1306 | node->constant = *ptr; |
---|
1307 | |
---|
1308 | MUTATE_END( Expression, node ); |
---|
1309 | } |
---|
1310 | |
---|
1311 | //-------------------------------------------------------------------------- |
---|
1312 | // SizeofExpr |
---|
1313 | template< typename pass_type > |
---|
1314 | void PassVisitor< pass_type >::visit( SizeofExpr * node ) { |
---|
1315 | VISIT_START( node ); |
---|
1316 | |
---|
1317 | indexerScopedAccept( node->result, *this ); |
---|
1318 | if ( node->get_isType() ) { |
---|
1319 | maybeAccept_impl( node->type, *this ); |
---|
1320 | } else { |
---|
1321 | maybeAccept_impl( node->expr, *this ); |
---|
1322 | } |
---|
1323 | |
---|
1324 | VISIT_END( node ); |
---|
1325 | } |
---|
1326 | |
---|
1327 | template< typename pass_type > |
---|
1328 | Expression * PassVisitor< pass_type >::mutate( SizeofExpr * node ) { |
---|
1329 | MUTATE_START( node ); |
---|
1330 | |
---|
1331 | indexerScopedMutate( node->env , *this ); |
---|
1332 | indexerScopedMutate( node->result, *this ); |
---|
1333 | if ( node->get_isType() ) { |
---|
1334 | maybeMutate_impl( node->type, *this ); |
---|
1335 | } else { |
---|
1336 | maybeMutate_impl( node->expr, *this ); |
---|
1337 | } |
---|
1338 | |
---|
1339 | MUTATE_END( Expression, node ); |
---|
1340 | } |
---|
1341 | |
---|
1342 | //-------------------------------------------------------------------------- |
---|
1343 | // AlignofExpr |
---|
1344 | template< typename pass_type > |
---|
1345 | void PassVisitor< pass_type >::visit( AlignofExpr * node ) { |
---|
1346 | VISIT_START( node ); |
---|
1347 | |
---|
1348 | indexerScopedAccept( node->result, *this ); |
---|
1349 | if ( node->get_isType() ) { |
---|
1350 | maybeAccept_impl( node->type, *this ); |
---|
1351 | } else { |
---|
1352 | maybeAccept_impl( node->expr, *this ); |
---|
1353 | } |
---|
1354 | |
---|
1355 | VISIT_END( node ); |
---|
1356 | } |
---|
1357 | |
---|
1358 | template< typename pass_type > |
---|
1359 | Expression * PassVisitor< pass_type >::mutate( AlignofExpr * node ) { |
---|
1360 | MUTATE_START( node ); |
---|
1361 | |
---|
1362 | indexerScopedMutate( node->env , *this ); |
---|
1363 | indexerScopedMutate( node->result, *this ); |
---|
1364 | if ( node->get_isType() ) { |
---|
1365 | maybeMutate_impl( node->type, *this ); |
---|
1366 | } else { |
---|
1367 | maybeMutate_impl( node->expr, *this ); |
---|
1368 | } |
---|
1369 | |
---|
1370 | MUTATE_END( Expression, node ); |
---|
1371 | } |
---|
1372 | |
---|
1373 | //-------------------------------------------------------------------------- |
---|
1374 | // UntypedOffsetofExpr |
---|
1375 | template< typename pass_type > |
---|
1376 | void PassVisitor< pass_type >::visit( UntypedOffsetofExpr * node ) { |
---|
1377 | VISIT_START( node ); |
---|
1378 | |
---|
1379 | indexerScopedAccept( node->result, *this ); |
---|
1380 | maybeAccept_impl ( node->type , *this ); |
---|
1381 | |
---|
1382 | VISIT_END( node ); |
---|
1383 | } |
---|
1384 | |
---|
1385 | template< typename pass_type > |
---|
1386 | Expression * PassVisitor< pass_type >::mutate( UntypedOffsetofExpr * node ) { |
---|
1387 | MUTATE_START( node ); |
---|
1388 | |
---|
1389 | indexerScopedMutate( node->env , *this ); |
---|
1390 | indexerScopedMutate( node->result, *this ); |
---|
1391 | maybeMutate_impl ( node->type , *this ); |
---|
1392 | |
---|
1393 | MUTATE_END( Expression, node ); |
---|
1394 | } |
---|
1395 | |
---|
1396 | //-------------------------------------------------------------------------- |
---|
1397 | // OffsetofExpr |
---|
1398 | template< typename pass_type > |
---|
1399 | void PassVisitor< pass_type >::visit( OffsetofExpr * node ) { |
---|
1400 | VISIT_START( node ); |
---|
1401 | |
---|
1402 | indexerScopedAccept( node->result, *this ); |
---|
1403 | maybeAccept_impl ( node->type , *this ); |
---|
1404 | maybeAccept_impl ( node->member, *this ); |
---|
1405 | |
---|
1406 | VISIT_END( node ); |
---|
1407 | } |
---|
1408 | |
---|
1409 | template< typename pass_type > |
---|
1410 | Expression * PassVisitor< pass_type >::mutate( OffsetofExpr * node ) { |
---|
1411 | MUTATE_START( node ); |
---|
1412 | |
---|
1413 | indexerScopedMutate( node->env , *this ); |
---|
1414 | indexerScopedMutate( node->result, *this ); |
---|
1415 | maybeMutate_impl ( node->type , *this ); |
---|
1416 | maybeMutate_impl ( node->member, *this ); |
---|
1417 | |
---|
1418 | MUTATE_END( Expression, node ); |
---|
1419 | } |
---|
1420 | |
---|
1421 | //-------------------------------------------------------------------------- |
---|
1422 | // OffsetPackExpr |
---|
1423 | template< typename pass_type > |
---|
1424 | void PassVisitor< pass_type >::visit( OffsetPackExpr * node ) { |
---|
1425 | VISIT_START( node ); |
---|
1426 | |
---|
1427 | indexerScopedAccept( node->result, *this ); |
---|
1428 | maybeAccept_impl ( node->type , *this ); |
---|
1429 | |
---|
1430 | VISIT_END( node ); |
---|
1431 | } |
---|
1432 | |
---|
1433 | template< typename pass_type > |
---|
1434 | Expression * PassVisitor< pass_type >::mutate( OffsetPackExpr * node ) { |
---|
1435 | MUTATE_START( node ); |
---|
1436 | |
---|
1437 | indexerScopedMutate( node->env , *this ); |
---|
1438 | indexerScopedMutate( node->result, *this ); |
---|
1439 | maybeMutate_impl ( node->type , *this ); |
---|
1440 | |
---|
1441 | MUTATE_END( Expression, node ); |
---|
1442 | } |
---|
1443 | |
---|
1444 | //-------------------------------------------------------------------------- |
---|
1445 | // AttrExpr |
---|
1446 | template< typename pass_type > |
---|
1447 | void PassVisitor< pass_type >::visit( AttrExpr * node ) { |
---|
1448 | VISIT_START( node ); |
---|
1449 | |
---|
1450 | indexerScopedAccept( node->result, *this ); |
---|
1451 | if ( node->get_isType() ) { |
---|
1452 | maybeAccept_impl( node->type, *this ); |
---|
1453 | } else { |
---|
1454 | maybeAccept_impl( node->expr, *this ); |
---|
1455 | } |
---|
1456 | |
---|
1457 | VISIT_END( node ); |
---|
1458 | } |
---|
1459 | |
---|
1460 | template< typename pass_type > |
---|
1461 | Expression * PassVisitor< pass_type >::mutate( AttrExpr * node ) { |
---|
1462 | MUTATE_START( node ); |
---|
1463 | |
---|
1464 | indexerScopedMutate( node->env , *this ); |
---|
1465 | indexerScopedMutate( node->result, *this ); |
---|
1466 | if ( node->get_isType() ) { |
---|
1467 | maybeMutate_impl( node->type, *this ); |
---|
1468 | } else { |
---|
1469 | maybeMutate_impl( node->expr, *this ); |
---|
1470 | } |
---|
1471 | |
---|
1472 | MUTATE_END( Expression, node ); |
---|
1473 | } |
---|
1474 | |
---|
1475 | //-------------------------------------------------------------------------- |
---|
1476 | // LogicalExpr |
---|
1477 | template< typename pass_type > |
---|
1478 | void PassVisitor< pass_type >::visit( LogicalExpr * node ) { |
---|
1479 | VISIT_START( node ); |
---|
1480 | |
---|
1481 | indexerScopedAccept( node->result, *this ); |
---|
1482 | maybeAccept_impl ( node->arg1 , *this ); |
---|
1483 | maybeAccept_impl ( node->arg2 , *this ); |
---|
1484 | |
---|
1485 | VISIT_END( node ); |
---|
1486 | } |
---|
1487 | |
---|
1488 | template< typename pass_type > |
---|
1489 | Expression * PassVisitor< pass_type >::mutate( LogicalExpr * node ) { |
---|
1490 | MUTATE_START( node ); |
---|
1491 | |
---|
1492 | indexerScopedMutate( node->env , *this ); |
---|
1493 | indexerScopedMutate( node->result, *this ); |
---|
1494 | maybeMutate_impl ( node->arg1 , *this ); |
---|
1495 | maybeMutate_impl ( node->arg2 , *this ); |
---|
1496 | |
---|
1497 | MUTATE_END( Expression, node ); |
---|
1498 | } |
---|
1499 | |
---|
1500 | //-------------------------------------------------------------------------- |
---|
1501 | // ConditionalExpr |
---|
1502 | template< typename pass_type > |
---|
1503 | void PassVisitor< pass_type >::visit( ConditionalExpr * node ) { |
---|
1504 | VISIT_START( node ); |
---|
1505 | |
---|
1506 | indexerScopedAccept( node->result, *this ); |
---|
1507 | maybeAccept_impl ( node->arg1 , *this ); |
---|
1508 | maybeAccept_impl ( node->arg2 , *this ); |
---|
1509 | maybeAccept_impl ( node->arg3 , *this ); |
---|
1510 | |
---|
1511 | VISIT_END( node ); |
---|
1512 | } |
---|
1513 | |
---|
1514 | template< typename pass_type > |
---|
1515 | Expression * PassVisitor< pass_type >::mutate( ConditionalExpr * node ) { |
---|
1516 | MUTATE_START( node ); |
---|
1517 | |
---|
1518 | indexerScopedMutate( node->env , *this ); |
---|
1519 | indexerScopedMutate( node->result, *this ); |
---|
1520 | maybeMutate_impl ( node->arg1 , *this ); |
---|
1521 | maybeMutate_impl ( node->arg2 , *this ); |
---|
1522 | maybeMutate_impl ( node->arg3 , *this ); |
---|
1523 | |
---|
1524 | MUTATE_END( Expression, node ); |
---|
1525 | } |
---|
1526 | |
---|
1527 | //-------------------------------------------------------------------------- |
---|
1528 | // CommaExpr |
---|
1529 | template< typename pass_type > |
---|
1530 | void PassVisitor< pass_type >::visit( CommaExpr * node ) { |
---|
1531 | VISIT_START( node ); |
---|
1532 | |
---|
1533 | indexerScopedAccept( node->result, *this ); |
---|
1534 | maybeAccept_impl ( node->arg1 , *this ); |
---|
1535 | maybeAccept_impl ( node->arg2 , *this ); |
---|
1536 | |
---|
1537 | VISIT_END( node ); |
---|
1538 | } |
---|
1539 | |
---|
1540 | template< typename pass_type > |
---|
1541 | Expression * PassVisitor< pass_type >::mutate( CommaExpr * node ) { |
---|
1542 | MUTATE_START( node ); |
---|
1543 | |
---|
1544 | indexerScopedMutate( node->env , *this ); |
---|
1545 | indexerScopedMutate( node->result, *this ); |
---|
1546 | maybeMutate_impl ( node->arg1 , *this ); |
---|
1547 | maybeMutate_impl ( node->arg2 , *this ); |
---|
1548 | |
---|
1549 | MUTATE_END( Expression, node ); |
---|
1550 | } |
---|
1551 | |
---|
1552 | //-------------------------------------------------------------------------- |
---|
1553 | // TypeExpr |
---|
1554 | template< typename pass_type > |
---|
1555 | void PassVisitor< pass_type >::visit( TypeExpr * node ) { |
---|
1556 | VISIT_START( node ); |
---|
1557 | |
---|
1558 | indexerScopedAccept( node->result, *this ); |
---|
1559 | maybeAccept_impl ( node->type, *this ); |
---|
1560 | |
---|
1561 | VISIT_END( node ); |
---|
1562 | } |
---|
1563 | |
---|
1564 | template< typename pass_type > |
---|
1565 | Expression * PassVisitor< pass_type >::mutate( TypeExpr * node ) { |
---|
1566 | MUTATE_START( node ); |
---|
1567 | |
---|
1568 | indexerScopedMutate( node->env , *this ); |
---|
1569 | indexerScopedMutate( node->result, *this ); |
---|
1570 | maybeMutate_impl ( node->type , *this ); |
---|
1571 | |
---|
1572 | MUTATE_END( Expression, node ); |
---|
1573 | } |
---|
1574 | |
---|
1575 | //-------------------------------------------------------------------------- |
---|
1576 | // AsmExpr |
---|
1577 | template< typename pass_type > |
---|
1578 | void PassVisitor< pass_type >::visit( AsmExpr * node ) { |
---|
1579 | VISIT_START( node ); |
---|
1580 | |
---|
1581 | indexerScopedAccept( node->result , *this ); |
---|
1582 | maybeAccept_impl ( node->inout , *this ); |
---|
1583 | maybeAccept_impl ( node->constraint, *this ); |
---|
1584 | maybeAccept_impl ( node->operand , *this ); |
---|
1585 | |
---|
1586 | VISIT_END( node ); |
---|
1587 | } |
---|
1588 | |
---|
1589 | template< typename pass_type > |
---|
1590 | Expression * PassVisitor< pass_type >::mutate( AsmExpr * node ) { |
---|
1591 | MUTATE_START( node ); |
---|
1592 | |
---|
1593 | indexerScopedMutate( node->env , *this ); |
---|
1594 | indexerScopedMutate( node->result , *this ); |
---|
1595 | maybeMutate_impl ( node->inout , *this ); |
---|
1596 | maybeMutate_impl ( node->constraint, *this ); |
---|
1597 | maybeMutate_impl ( node->operand , *this ); |
---|
1598 | |
---|
1599 | MUTATE_END( Expression, node ); |
---|
1600 | } |
---|
1601 | |
---|
1602 | //-------------------------------------------------------------------------- |
---|
1603 | // ImplicitCopyCtorExpr |
---|
1604 | template< typename pass_type > |
---|
1605 | void PassVisitor< pass_type >::visit( ImplicitCopyCtorExpr * node ) { |
---|
1606 | VISIT_START( node ); |
---|
1607 | |
---|
1608 | indexerScopedAccept( node->result , *this ); |
---|
1609 | maybeAccept_impl ( node->callExpr , *this ); |
---|
1610 | maybeAccept_impl ( node->tempDecls , *this ); |
---|
1611 | maybeAccept_impl ( node->returnDecls, *this ); |
---|
1612 | maybeAccept_impl ( node->dtors , *this ); |
---|
1613 | |
---|
1614 | VISIT_END( node ); |
---|
1615 | } |
---|
1616 | |
---|
1617 | template< typename pass_type > |
---|
1618 | Expression * PassVisitor< pass_type >::mutate( ImplicitCopyCtorExpr * node ) { |
---|
1619 | MUTATE_START( node ); |
---|
1620 | |
---|
1621 | indexerScopedMutate( node->env , *this ); |
---|
1622 | indexerScopedMutate( node->result , *this ); |
---|
1623 | maybeMutate_impl ( node->callExpr , *this ); |
---|
1624 | maybeMutate_impl ( node->tempDecls , *this ); |
---|
1625 | maybeMutate_impl ( node->returnDecls, *this ); |
---|
1626 | maybeMutate_impl ( node->dtors , *this ); |
---|
1627 | |
---|
1628 | MUTATE_END( Expression, node ); |
---|
1629 | } |
---|
1630 | |
---|
1631 | //-------------------------------------------------------------------------- |
---|
1632 | // ConstructorExpr |
---|
1633 | template< typename pass_type > |
---|
1634 | void PassVisitor< pass_type >::visit( ConstructorExpr * node ) { |
---|
1635 | VISIT_START( node ); |
---|
1636 | |
---|
1637 | indexerScopedAccept( node->result , *this ); |
---|
1638 | maybeAccept_impl ( node->callExpr, *this ); |
---|
1639 | |
---|
1640 | VISIT_END( node ); |
---|
1641 | } |
---|
1642 | |
---|
1643 | template< typename pass_type > |
---|
1644 | Expression * PassVisitor< pass_type >::mutate( ConstructorExpr * node ) { |
---|
1645 | MUTATE_START( node ); |
---|
1646 | |
---|
1647 | indexerScopedMutate( node->env , *this ); |
---|
1648 | indexerScopedMutate( node->result , *this ); |
---|
1649 | maybeMutate_impl ( node->callExpr, *this ); |
---|
1650 | |
---|
1651 | MUTATE_END( Expression, node ); |
---|
1652 | } |
---|
1653 | |
---|
1654 | //-------------------------------------------------------------------------- |
---|
1655 | // CompoundLiteralExpr |
---|
1656 | template< typename pass_type > |
---|
1657 | void PassVisitor< pass_type >::visit( CompoundLiteralExpr * node ) { |
---|
1658 | VISIT_START( node ); |
---|
1659 | |
---|
1660 | indexerScopedAccept( node->result , *this ); |
---|
1661 | maybeAccept_impl ( node->initializer, *this ); |
---|
1662 | |
---|
1663 | VISIT_END( node ); |
---|
1664 | } |
---|
1665 | |
---|
1666 | template< typename pass_type > |
---|
1667 | Expression * PassVisitor< pass_type >::mutate( CompoundLiteralExpr * node ) { |
---|
1668 | MUTATE_START( node ); |
---|
1669 | |
---|
1670 | indexerScopedMutate( node->env , *this ); |
---|
1671 | indexerScopedMutate( node->result , *this ); |
---|
1672 | maybeMutate_impl ( node->initializer, *this ); |
---|
1673 | |
---|
1674 | MUTATE_END( Expression, node ); |
---|
1675 | } |
---|
1676 | |
---|
1677 | //-------------------------------------------------------------------------- |
---|
1678 | // RangeExpr |
---|
1679 | template< typename pass_type > |
---|
1680 | void PassVisitor< pass_type >::visit( RangeExpr * node ) { |
---|
1681 | VISIT_START( node ); |
---|
1682 | |
---|
1683 | indexerScopedAccept( node->result, *this ); |
---|
1684 | maybeAccept_impl ( node->low , *this ); |
---|
1685 | maybeAccept_impl ( node->high , *this ); |
---|
1686 | |
---|
1687 | VISIT_END( node ); |
---|
1688 | } |
---|
1689 | |
---|
1690 | template< typename pass_type > |
---|
1691 | Expression * PassVisitor< pass_type >::mutate( RangeExpr * node ) { |
---|
1692 | MUTATE_START( node ); |
---|
1693 | |
---|
1694 | indexerScopedMutate( node->env , *this ); |
---|
1695 | indexerScopedMutate( node->result, *this ); |
---|
1696 | maybeMutate_impl ( node->low , *this ); |
---|
1697 | maybeMutate_impl ( node->high , *this ); |
---|
1698 | |
---|
1699 | MUTATE_END( Expression, node ); |
---|
1700 | } |
---|
1701 | |
---|
1702 | //-------------------------------------------------------------------------- |
---|
1703 | // UntypedTupleExpr |
---|
1704 | template< typename pass_type > |
---|
1705 | void PassVisitor< pass_type >::visit( UntypedTupleExpr * node ) { |
---|
1706 | VISIT_START( node ); |
---|
1707 | |
---|
1708 | indexerScopedAccept( node->result, *this ); |
---|
1709 | maybeAccept_impl ( node->exprs , *this ); |
---|
1710 | |
---|
1711 | VISIT_END( node ); |
---|
1712 | } |
---|
1713 | |
---|
1714 | template< typename pass_type > |
---|
1715 | Expression * PassVisitor< pass_type >::mutate( UntypedTupleExpr * node ) { |
---|
1716 | MUTATE_START( node ); |
---|
1717 | |
---|
1718 | indexerScopedMutate( node->env , *this ); |
---|
1719 | indexerScopedMutate( node->result, *this ); |
---|
1720 | maybeMutate_impl ( node->exprs , *this ); |
---|
1721 | |
---|
1722 | MUTATE_END( Expression, node ); |
---|
1723 | } |
---|
1724 | |
---|
1725 | //-------------------------------------------------------------------------- |
---|
1726 | // TupleExpr |
---|
1727 | template< typename pass_type > |
---|
1728 | void PassVisitor< pass_type >::visit( TupleExpr * node ) { |
---|
1729 | VISIT_START( node ); |
---|
1730 | |
---|
1731 | indexerScopedAccept( node->result, *this ); |
---|
1732 | maybeAccept_impl ( node->exprs , *this ); |
---|
1733 | |
---|
1734 | VISIT_END( node ); |
---|
1735 | } |
---|
1736 | |
---|
1737 | template< typename pass_type > |
---|
1738 | Expression * PassVisitor< pass_type >::mutate( TupleExpr * node ) { |
---|
1739 | MUTATE_START( node ); |
---|
1740 | |
---|
1741 | indexerScopedMutate( node->env , *this ); |
---|
1742 | indexerScopedMutate( node->result, *this ); |
---|
1743 | maybeMutate_impl ( node->exprs , *this ); |
---|
1744 | |
---|
1745 | MUTATE_END( Expression, node ); |
---|
1746 | } |
---|
1747 | |
---|
1748 | //-------------------------------------------------------------------------- |
---|
1749 | // TupleIndexExpr |
---|
1750 | template< typename pass_type > |
---|
1751 | void PassVisitor< pass_type >::visit( TupleIndexExpr * node ) { |
---|
1752 | VISIT_START( node ); |
---|
1753 | |
---|
1754 | indexerScopedAccept( node->result, *this ); |
---|
1755 | maybeAccept_impl ( node->tuple , *this ); |
---|
1756 | |
---|
1757 | VISIT_END( node ); |
---|
1758 | } |
---|
1759 | |
---|
1760 | template< typename pass_type > |
---|
1761 | Expression * PassVisitor< pass_type >::mutate( TupleIndexExpr * node ) { |
---|
1762 | MUTATE_START( node ); |
---|
1763 | |
---|
1764 | indexerScopedMutate( node->env , *this ); |
---|
1765 | indexerScopedMutate( node->result, *this ); |
---|
1766 | maybeMutate_impl ( node->tuple , *this ); |
---|
1767 | |
---|
1768 | MUTATE_END( Expression, node ); |
---|
1769 | } |
---|
1770 | |
---|
1771 | //-------------------------------------------------------------------------- |
---|
1772 | // TupleAssignExpr |
---|
1773 | template< typename pass_type > |
---|
1774 | void PassVisitor< pass_type >::visit( TupleAssignExpr * node ) { |
---|
1775 | VISIT_START( node ); |
---|
1776 | |
---|
1777 | indexerScopedAccept( node->result , *this ); |
---|
1778 | maybeAccept_impl ( node->stmtExpr, *this ); |
---|
1779 | |
---|
1780 | VISIT_END( node ); |
---|
1781 | } |
---|
1782 | |
---|
1783 | template< typename pass_type > |
---|
1784 | Expression * PassVisitor< pass_type >::mutate( TupleAssignExpr * node ) { |
---|
1785 | MUTATE_START( node ); |
---|
1786 | |
---|
1787 | indexerScopedMutate( node->env , *this ); |
---|
1788 | indexerScopedMutate( node->result , *this ); |
---|
1789 | maybeMutate_impl ( node->stmtExpr, *this ); |
---|
1790 | |
---|
1791 | MUTATE_END( Expression, node ); |
---|
1792 | } |
---|
1793 | |
---|
1794 | //-------------------------------------------------------------------------- |
---|
1795 | // StmtExpr |
---|
1796 | template< typename pass_type > |
---|
1797 | void PassVisitor< pass_type >::visit( StmtExpr * node ) { |
---|
1798 | VISIT_START( node ); |
---|
1799 | |
---|
1800 | // don't want statements from outer CompoundStmts to be added to this StmtExpr |
---|
1801 | ValueGuardPtr< TypeSubstitution * > oldEnv ( get_env_ptr() ); |
---|
1802 | ValueGuardPtr< std::list< Statement* > > oldBeforeStmts( get_beforeStmts() ); |
---|
1803 | ValueGuardPtr< std::list< Statement* > > oldAfterStmts ( get_afterStmts () ); |
---|
1804 | |
---|
1805 | indexerScopedAccept( node->result , *this ); |
---|
1806 | maybeAccept_impl ( node->statements , *this ); |
---|
1807 | maybeAccept_impl ( node->returnDecls, *this ); |
---|
1808 | maybeAccept_impl ( node->dtors , *this ); |
---|
1809 | |
---|
1810 | VISIT_END( node ); |
---|
1811 | } |
---|
1812 | |
---|
1813 | template< typename pass_type > |
---|
1814 | Expression * PassVisitor< pass_type >::mutate( StmtExpr * node ) { |
---|
1815 | MUTATE_START( node ); |
---|
1816 | |
---|
1817 | // don't want statements from outer CompoundStmts to be added to this StmtExpr |
---|
1818 | ValueGuardPtr< TypeSubstitution * > oldEnv ( get_env_ptr() ); |
---|
1819 | ValueGuardPtr< std::list< Statement* > > oldBeforeStmts( get_beforeStmts() ); |
---|
1820 | ValueGuardPtr< std::list< Statement* > > oldAfterStmts ( get_afterStmts () ); |
---|
1821 | |
---|
1822 | indexerScopedMutate( node->result , *this ); |
---|
1823 | maybeMutate_impl ( node->statements , *this ); |
---|
1824 | maybeMutate_impl ( node->returnDecls, *this ); |
---|
1825 | maybeMutate_impl ( node->dtors , *this ); |
---|
1826 | |
---|
1827 | MUTATE_END( Expression, node ); |
---|
1828 | } |
---|
1829 | |
---|
1830 | //-------------------------------------------------------------------------- |
---|
1831 | // UniqueExpr |
---|
1832 | template< typename pass_type > |
---|
1833 | void PassVisitor< pass_type >::visit( UniqueExpr * node ) { |
---|
1834 | VISIT_START( node ); |
---|
1835 | |
---|
1836 | indexerScopedAccept( node->result, *this ); |
---|
1837 | maybeAccept_impl ( node->expr , *this ); |
---|
1838 | |
---|
1839 | VISIT_END( node ); |
---|
1840 | } |
---|
1841 | |
---|
1842 | template< typename pass_type > |
---|
1843 | Expression * PassVisitor< pass_type >::mutate( UniqueExpr * node ) { |
---|
1844 | MUTATE_START( node ); |
---|
1845 | |
---|
1846 | indexerScopedMutate( node->env , *this ); |
---|
1847 | indexerScopedMutate( node->result, *this ); |
---|
1848 | maybeMutate_impl ( node->expr , *this ); |
---|
1849 | |
---|
1850 | MUTATE_END( Expression, node ); |
---|
1851 | } |
---|
1852 | |
---|
1853 | //-------------------------------------------------------------------------- |
---|
1854 | // UntypedInitExpr |
---|
1855 | template< typename pass_type > |
---|
1856 | void PassVisitor< pass_type >::visit( UntypedInitExpr * node ) { |
---|
1857 | VISIT_START( node ); |
---|
1858 | |
---|
1859 | indexerScopedAccept( node->result, *this ); |
---|
1860 | maybeAccept_impl ( node->expr , *this ); |
---|
1861 | // not currently visiting initAlts, but this doesn't matter since this node is only used in the resolver. |
---|
1862 | |
---|
1863 | VISIT_END( node ); |
---|
1864 | } |
---|
1865 | |
---|
1866 | template< typename pass_type > |
---|
1867 | Expression * PassVisitor< pass_type >::mutate( UntypedInitExpr * node ) { |
---|
1868 | MUTATE_START( node ); |
---|
1869 | |
---|
1870 | indexerScopedMutate( node->env , *this ); |
---|
1871 | indexerScopedMutate( node->result, *this ); |
---|
1872 | maybeMutate_impl ( node->expr , *this ); |
---|
1873 | // not currently visiting initAlts, but this doesn't matter since this node is only used in the resolver. |
---|
1874 | |
---|
1875 | MUTATE_END( Expression, node ); |
---|
1876 | } |
---|
1877 | |
---|
1878 | //-------------------------------------------------------------------------- |
---|
1879 | // InitExpr |
---|
1880 | template< typename pass_type > |
---|
1881 | void PassVisitor< pass_type >::visit( InitExpr * node ) { |
---|
1882 | VISIT_START( node ); |
---|
1883 | |
---|
1884 | indexerScopedAccept( node->result, *this ); |
---|
1885 | maybeAccept_impl ( node->expr , *this ); |
---|
1886 | maybeAccept_impl ( node->designation, *this ); |
---|
1887 | |
---|
1888 | VISIT_END( node ); |
---|
1889 | } |
---|
1890 | |
---|
1891 | template< typename pass_type > |
---|
1892 | Expression * PassVisitor< pass_type >::mutate( InitExpr * node ) { |
---|
1893 | MUTATE_START( node ); |
---|
1894 | |
---|
1895 | indexerScopedMutate( node->env , *this ); |
---|
1896 | indexerScopedMutate( node->result, *this ); |
---|
1897 | maybeMutate_impl ( node->expr , *this ); |
---|
1898 | maybeMutate_impl ( node->designation, *this ); |
---|
1899 | |
---|
1900 | MUTATE_END( Expression, node ); |
---|
1901 | } |
---|
1902 | |
---|
1903 | template< typename pass_type > |
---|
1904 | void PassVisitor< pass_type >::visit( VoidType * node ) { |
---|
1905 | VISIT_BODY( node ); |
---|
1906 | } |
---|
1907 | |
---|
1908 | template< typename pass_type > |
---|
1909 | void PassVisitor< pass_type >::visit( BasicType * node ) { |
---|
1910 | VISIT_BODY( node ); |
---|
1911 | } |
---|
1912 | |
---|
1913 | template< typename pass_type > |
---|
1914 | void PassVisitor< pass_type >::visit( PointerType * node ) { |
---|
1915 | VISIT_BODY( node ); |
---|
1916 | } |
---|
1917 | |
---|
1918 | template< typename pass_type > |
---|
1919 | void PassVisitor< pass_type >::visit( ArrayType * node ) { |
---|
1920 | VISIT_BODY( node ); |
---|
1921 | } |
---|
1922 | |
---|
1923 | template< typename pass_type > |
---|
1924 | void PassVisitor< pass_type >::visit( ReferenceType * node ) { |
---|
1925 | VISIT_BODY( node ); |
---|
1926 | } |
---|
1927 | |
---|
1928 | template< typename pass_type > |
---|
1929 | void PassVisitor< pass_type >::visit( FunctionType * node ) { |
---|
1930 | VISIT_BODY( node ); |
---|
1931 | } |
---|
1932 | |
---|
1933 | //-------------------------------------------------------------------------- |
---|
1934 | // StructInstType |
---|
1935 | template< typename pass_type > |
---|
1936 | void PassVisitor< pass_type >::visit( StructInstType * node ) { |
---|
1937 | VISIT_START( node ); |
---|
1938 | |
---|
1939 | indexerAddStruct( node->name ); |
---|
1940 | |
---|
1941 | { |
---|
1942 | auto guard = makeFuncGuard( [this]() { indexerScopeEnter(); }, [this]() { indexerScopeLeave(); } ); |
---|
1943 | maybeAccept_impl( node->forall , *this ); |
---|
1944 | maybeAccept_impl( node->parameters, *this ); |
---|
1945 | } |
---|
1946 | |
---|
1947 | VISIT_END( node ); |
---|
1948 | } |
---|
1949 | |
---|
1950 | template< typename pass_type > |
---|
1951 | Type * PassVisitor< pass_type >::mutate( StructInstType * node ) { |
---|
1952 | MUTATE_START( node ); |
---|
1953 | |
---|
1954 | indexerAddStruct( node->name ); |
---|
1955 | |
---|
1956 | { |
---|
1957 | auto guard = makeFuncGuard( [this]() { indexerScopeEnter(); }, [this]() { indexerScopeLeave(); } ); |
---|
1958 | maybeMutate_impl( node->forall , *this ); |
---|
1959 | maybeMutate_impl( node->parameters, *this ); |
---|
1960 | } |
---|
1961 | |
---|
1962 | MUTATE_END( Type, node ); |
---|
1963 | } |
---|
1964 | |
---|
1965 | //-------------------------------------------------------------------------- |
---|
1966 | // UnionInstType |
---|
1967 | template< typename pass_type > |
---|
1968 | void PassVisitor< pass_type >::visit( UnionInstType * node ) { |
---|
1969 | VISIT_START( node ); |
---|
1970 | |
---|
1971 | indexerAddStruct( node->name ); |
---|
1972 | |
---|
1973 | { |
---|
1974 | auto guard = makeFuncGuard( [this]() { indexerScopeEnter(); }, [this]() { indexerScopeLeave(); } ); |
---|
1975 | maybeAccept_impl( node->forall , *this ); |
---|
1976 | maybeAccept_impl( node->parameters, *this ); |
---|
1977 | } |
---|
1978 | |
---|
1979 | VISIT_END( node ); |
---|
1980 | } |
---|
1981 | |
---|
1982 | template< typename pass_type > |
---|
1983 | Type * PassVisitor< pass_type >::mutate( UnionInstType * node ) { |
---|
1984 | MUTATE_START( node ); |
---|
1985 | |
---|
1986 | indexerAddStruct( node->name ); |
---|
1987 | |
---|
1988 | { |
---|
1989 | auto guard = makeFuncGuard( [this]() { indexerScopeEnter(); }, [this]() { indexerScopeLeave(); } ); |
---|
1990 | maybeMutate_impl( node->forall , *this ); |
---|
1991 | maybeMutate_impl( node->parameters, *this ); |
---|
1992 | } |
---|
1993 | |
---|
1994 | MUTATE_END( Type, node ); |
---|
1995 | } |
---|
1996 | |
---|
1997 | //-------------------------------------------------------------------------- |
---|
1998 | // EnumInstType |
---|
1999 | template< typename pass_type > |
---|
2000 | void PassVisitor< pass_type >::visit( EnumInstType * node ) { |
---|
2001 | VISIT_BODY( node ); |
---|
2002 | } |
---|
2003 | |
---|
2004 | template< typename pass_type > |
---|
2005 | Type * PassVisitor< pass_type >::mutate( EnumInstType * node ) { |
---|
2006 | MUTATE_BODY( Type, node ); |
---|
2007 | } |
---|
2008 | |
---|
2009 | //-------------------------------------------------------------------------- |
---|
2010 | // TraitInstType |
---|
2011 | template< typename pass_type > |
---|
2012 | void PassVisitor< pass_type >::visit( TraitInstType * node ) { |
---|
2013 | VISIT_START( node ); |
---|
2014 | |
---|
2015 | maybeAccept_impl( node->forall , *this ); |
---|
2016 | maybeAccept_impl( node->parameters, *this ); |
---|
2017 | |
---|
2018 | VISIT_END( node ); |
---|
2019 | } |
---|
2020 | |
---|
2021 | template< typename pass_type > |
---|
2022 | Type * PassVisitor< pass_type >::mutate( TraitInstType * node ) { |
---|
2023 | MUTATE_START( node ); |
---|
2024 | |
---|
2025 | maybeMutate_impl( node->forall , *this ); |
---|
2026 | maybeMutate_impl( node->parameters, *this ); |
---|
2027 | |
---|
2028 | MUTATE_END( Type, node ); |
---|
2029 | } |
---|
2030 | |
---|
2031 | //-------------------------------------------------------------------------- |
---|
2032 | // TypeInstType |
---|
2033 | template< typename pass_type > |
---|
2034 | void PassVisitor< pass_type >::visit( TypeInstType * node ) { |
---|
2035 | VISIT_BODY( node ); |
---|
2036 | } |
---|
2037 | |
---|
2038 | template< typename pass_type > |
---|
2039 | void PassVisitor< pass_type >::visit( TupleType * node ) { |
---|
2040 | VISIT_BODY( node ); |
---|
2041 | } |
---|
2042 | |
---|
2043 | template< typename pass_type > |
---|
2044 | void PassVisitor< pass_type >::visit( TypeofType * node ) { |
---|
2045 | VISIT_BODY( node ); |
---|
2046 | } |
---|
2047 | |
---|
2048 | template< typename pass_type > |
---|
2049 | void PassVisitor< pass_type >::visit( AttrType * node ) { |
---|
2050 | VISIT_BODY( node ); |
---|
2051 | } |
---|
2052 | |
---|
2053 | template< typename pass_type > |
---|
2054 | void PassVisitor< pass_type >::visit( VarArgsType * node ) { |
---|
2055 | VISIT_BODY( node ); |
---|
2056 | } |
---|
2057 | |
---|
2058 | template< typename pass_type > |
---|
2059 | void PassVisitor< pass_type >::visit( ZeroType * node ) { |
---|
2060 | VISIT_BODY( node ); |
---|
2061 | } |
---|
2062 | |
---|
2063 | template< typename pass_type > |
---|
2064 | void PassVisitor< pass_type >::visit( OneType * node ) { |
---|
2065 | VISIT_BODY( node ); |
---|
2066 | } |
---|
2067 | |
---|
2068 | template< typename pass_type > |
---|
2069 | void PassVisitor< pass_type >::visit( Designation * node ) { |
---|
2070 | VISIT_START( node ); |
---|
2071 | |
---|
2072 | maybeAccept_impl( node->get_designators(), *this ); |
---|
2073 | |
---|
2074 | VISIT_END( node ); |
---|
2075 | } |
---|
2076 | |
---|
2077 | template< typename pass_type > |
---|
2078 | Designation * PassVisitor< pass_type >::mutate( Designation * node ) { |
---|
2079 | MUTATE_START( node ); |
---|
2080 | |
---|
2081 | maybeMutate_impl( node->get_designators(), *this ); |
---|
2082 | |
---|
2083 | MUTATE_END( Designation, node ); |
---|
2084 | } |
---|
2085 | |
---|
2086 | //-------------------------------------------------------------------------- |
---|
2087 | // SingleInit |
---|
2088 | template< typename pass_type > |
---|
2089 | void PassVisitor< pass_type >::visit( SingleInit * node ) { |
---|
2090 | VISIT_START( node ); |
---|
2091 | |
---|
2092 | visitExpression( node->get_value() ); |
---|
2093 | |
---|
2094 | VISIT_END( node ); |
---|
2095 | } |
---|
2096 | |
---|
2097 | template< typename pass_type > |
---|
2098 | Initializer * PassVisitor< pass_type >::mutate( SingleInit * node ) { |
---|
2099 | MUTATE_START( node ); |
---|
2100 | |
---|
2101 | node->set_value( mutateExpression( node->get_value() ) ); |
---|
2102 | |
---|
2103 | MUTATE_END( Initializer, node ); |
---|
2104 | } |
---|
2105 | |
---|
2106 | template< typename pass_type > |
---|
2107 | void PassVisitor< pass_type >::visit( ListInit * node ) { |
---|
2108 | VISIT_BODY( node ); |
---|
2109 | } |
---|
2110 | |
---|
2111 | template< typename pass_type > |
---|
2112 | void PassVisitor< pass_type >::visit( ConstructorInit * node ) { |
---|
2113 | VISIT_BODY( node ); |
---|
2114 | } |
---|
2115 | |
---|
2116 | template< typename pass_type > |
---|
2117 | void PassVisitor< pass_type >::visit( Subrange * node ) { |
---|
2118 | VISIT_BODY( node ); |
---|
2119 | } |
---|
2120 | |
---|
2121 | template< typename pass_type > |
---|
2122 | void PassVisitor< pass_type >::visit( Constant * node ) { |
---|
2123 | VISIT_BODY( node ); |
---|
2124 | } |
---|
2125 | |
---|
2126 | template< typename pass_type > |
---|
2127 | void PassVisitor< pass_type >::visit( Attribute * node ) { |
---|
2128 | VISIT_BODY( node ); |
---|
2129 | } |
---|
2130 | |
---|
2131 | //--------------------------------------------------------------------------------------------------------------- |
---|
2132 | template< typename pass_type > |
---|
2133 | Type * PassVisitor< pass_type >::mutate( VoidType * node ) { |
---|
2134 | MUTATE_BODY( Type, node ); |
---|
2135 | } |
---|
2136 | |
---|
2137 | template< typename pass_type > |
---|
2138 | Type * PassVisitor< pass_type >::mutate( BasicType * node ) { |
---|
2139 | MUTATE_BODY( Type, node ); |
---|
2140 | } |
---|
2141 | |
---|
2142 | template< typename pass_type > |
---|
2143 | Type * PassVisitor< pass_type >::mutate( PointerType * node ) { |
---|
2144 | MUTATE_BODY( Type, node ); |
---|
2145 | } |
---|
2146 | |
---|
2147 | template< typename pass_type > |
---|
2148 | Type * PassVisitor< pass_type >::mutate( ArrayType * node ) { |
---|
2149 | MUTATE_BODY( Type, node ); |
---|
2150 | } |
---|
2151 | |
---|
2152 | template< typename pass_type > |
---|
2153 | Type * PassVisitor< pass_type >::mutate( ReferenceType * node ) { |
---|
2154 | MUTATE_BODY( Type, node ); |
---|
2155 | } |
---|
2156 | |
---|
2157 | template< typename pass_type > |
---|
2158 | Type * PassVisitor< pass_type >::mutate( FunctionType * node ) { |
---|
2159 | MUTATE_BODY( Type, node ); |
---|
2160 | } |
---|
2161 | |
---|
2162 | template< typename pass_type > |
---|
2163 | Type * PassVisitor< pass_type >::mutate( TypeInstType * node ) { |
---|
2164 | MUTATE_BODY( Type, node ); |
---|
2165 | } |
---|
2166 | |
---|
2167 | template< typename pass_type > |
---|
2168 | Type * PassVisitor< pass_type >::mutate( TupleType * node ) { |
---|
2169 | MUTATE_BODY( Type, node ); |
---|
2170 | } |
---|
2171 | |
---|
2172 | template< typename pass_type > |
---|
2173 | Type * PassVisitor< pass_type >::mutate( TypeofType * node ) { |
---|
2174 | MUTATE_BODY( Type, node ); |
---|
2175 | } |
---|
2176 | |
---|
2177 | template< typename pass_type > |
---|
2178 | Type * PassVisitor< pass_type >::mutate( AttrType * node ) { |
---|
2179 | MUTATE_BODY( Type, node ); |
---|
2180 | } |
---|
2181 | |
---|
2182 | template< typename pass_type > |
---|
2183 | Type * PassVisitor< pass_type >::mutate( VarArgsType * node ) { |
---|
2184 | MUTATE_BODY( Type, node ); |
---|
2185 | } |
---|
2186 | |
---|
2187 | template< typename pass_type > |
---|
2188 | Type * PassVisitor< pass_type >::mutate( ZeroType * node ) { |
---|
2189 | MUTATE_BODY( Type, node ); |
---|
2190 | } |
---|
2191 | |
---|
2192 | template< typename pass_type > |
---|
2193 | Type * PassVisitor< pass_type >::mutate( OneType * node ) { |
---|
2194 | MUTATE_BODY( Type, node ); |
---|
2195 | } |
---|
2196 | |
---|
2197 | template< typename pass_type > |
---|
2198 | Initializer * PassVisitor< pass_type >::mutate( ListInit * node ) { |
---|
2199 | MUTATE_BODY( Initializer, node ); |
---|
2200 | } |
---|
2201 | |
---|
2202 | template< typename pass_type > |
---|
2203 | Initializer * PassVisitor< pass_type >::mutate( ConstructorInit * node ) { |
---|
2204 | MUTATE_BODY( Initializer, node ); |
---|
2205 | } |
---|
2206 | |
---|
2207 | template< typename pass_type > |
---|
2208 | Subrange * PassVisitor< pass_type >::mutate( Subrange * node ) { |
---|
2209 | MUTATE_BODY( Subrange, node ); |
---|
2210 | } |
---|
2211 | |
---|
2212 | template< typename pass_type > |
---|
2213 | Constant * PassVisitor< pass_type >::mutate( Constant * node ) { |
---|
2214 | MUTATE_BODY( Constant, node ); |
---|
2215 | } |
---|
2216 | |
---|
2217 | template< typename pass_type > |
---|
2218 | Attribute * PassVisitor< pass_type >::mutate( Attribute * node ) { |
---|
2219 | MUTATE_BODY( Attribute, node ); |
---|
2220 | } |
---|
2221 | |
---|
2222 | template< typename pass_type > |
---|
2223 | TypeSubstitution * PassVisitor< pass_type >::mutate( TypeSubstitution * node ) { |
---|
2224 | MUTATE_START( node ); |
---|
2225 | |
---|
2226 | for ( auto & p : node->typeEnv ) { |
---|
2227 | indexerScopedMutate( p.second, *this ); |
---|
2228 | } |
---|
2229 | for ( auto & p : node->varEnv ) { |
---|
2230 | indexerScopedMutate( p.second, *this ); |
---|
2231 | } |
---|
2232 | |
---|
2233 | MUTATE_END( TypeSubstitution, node ); |
---|
2234 | } |
---|