1 | // |
---|
2 | // Cforall Version 1.0.0 Copyright (C) 2019 University of Waterloo |
---|
3 | // |
---|
4 | // The contents of this file are covered under the licence agreement in the |
---|
5 | // file "LICENCE" distributed with Cforall. |
---|
6 | // |
---|
7 | // ast::Pass.impl.hpp -- |
---|
8 | // |
---|
9 | // Author : Thierry Delisle |
---|
10 | // Created On : Thu May 09 15::37::05 2019 |
---|
11 | // Last Modified By : |
---|
12 | // Last Modified On : |
---|
13 | // Update Count : |
---|
14 | // |
---|
15 | |
---|
16 | #pragma once |
---|
17 | // IWYU pragma: private, include "AST/Pass.hpp" |
---|
18 | |
---|
19 | #include <type_traits> |
---|
20 | #include <unordered_map> |
---|
21 | |
---|
22 | #include "AST/TranslationUnit.hpp" |
---|
23 | #include "AST/TypeSubstitution.hpp" |
---|
24 | |
---|
25 | #define VISIT_START( node ) \ |
---|
26 | using namespace ast; \ |
---|
27 | /* back-up the visit children */ \ |
---|
28 | __attribute__((unused)) ast::__pass::visit_children_guard guard1( ast::__pass::visit_children(core, 0) ); \ |
---|
29 | /* setup the scope for passes that want to run code at exit */ \ |
---|
30 | __attribute__((unused)) ast::__pass::guard_value guard2( ast::__pass::at_cleanup (core, 0) ); \ |
---|
31 | /* begin tracing memory allocation if requested by this pass */ \ |
---|
32 | __pass::beginTrace( core, 0 ); \ |
---|
33 | /* call the implementation of the previsit of this pass */ \ |
---|
34 | __pass::previsit( core, node, 0 ); |
---|
35 | |
---|
36 | #define VISIT( code... ) \ |
---|
37 | /* if this node should visit its children */ \ |
---|
38 | if ( __visit_children() ) { \ |
---|
39 | /* visit the children */ \ |
---|
40 | code \ |
---|
41 | } |
---|
42 | |
---|
43 | #define VISIT_END( type, node ) \ |
---|
44 | /* call the implementation of the postvisit of this pass */ \ |
---|
45 | auto __return = __pass::postvisit( core, node, 0 ); \ |
---|
46 | assertf(__return, "post visit should never return null"); \ |
---|
47 | /* end tracing memory allocation if requested by this pass */ \ |
---|
48 | __pass::endTrace( core, 0 ); \ |
---|
49 | return __return; |
---|
50 | |
---|
51 | #ifdef PEDANTIC_PASS_ASSERT |
---|
52 | #define __pedantic_pass_assert(...) assert (__VA_ARGS__) |
---|
53 | #define __pedantic_pass_assertf(...) assertf(__VA_ARGS__) |
---|
54 | #else |
---|
55 | #define __pedantic_pass_assert(...) |
---|
56 | #define __pedantic_pass_assertf(...) |
---|
57 | #endif |
---|
58 | |
---|
59 | namespace ast { |
---|
60 | template<typename node_t> |
---|
61 | node_t * shallowCopy( const node_t * node ); |
---|
62 | |
---|
63 | namespace __pass { |
---|
64 | // Check if this is either a null pointer or a pointer to an empty container |
---|
65 | template<typename T> |
---|
66 | static inline bool empty( T * ptr ) { |
---|
67 | return !ptr || ptr->empty(); |
---|
68 | } |
---|
69 | |
---|
70 | template< typename core_t, typename node_t > |
---|
71 | static inline node_t* mutate(const node_t *node) { |
---|
72 | return std::is_base_of<PureVisitor, core_t>::value ? ::ast::shallowCopy(node) : ::ast::mutate(node); |
---|
73 | } |
---|
74 | |
---|
75 | //------------------------------ |
---|
76 | template<typename it_t, template <class...> class container_t> |
---|
77 | static inline void take_all( it_t it, container_t<ast::ptr<ast::Decl>> * decls, bool * mutated = nullptr ) { |
---|
78 | if(empty(decls)) return; |
---|
79 | |
---|
80 | std::transform(decls->begin(), decls->end(), it, [](const ast::Decl * decl) -> auto { |
---|
81 | return new DeclStmt( decl->location, decl ); |
---|
82 | }); |
---|
83 | decls->clear(); |
---|
84 | if(mutated) *mutated = true; |
---|
85 | } |
---|
86 | |
---|
87 | template<typename it_t, template <class...> class container_t> |
---|
88 | static inline void take_all( it_t it, container_t<ast::ptr<ast::Stmt>> * decls, bool * mutated = nullptr ) { |
---|
89 | if(empty(decls)) return; |
---|
90 | |
---|
91 | std::move(decls->begin(), decls->end(), it); |
---|
92 | decls->clear(); |
---|
93 | if(mutated) *mutated = true; |
---|
94 | } |
---|
95 | |
---|
96 | //------------------------------ |
---|
97 | /// Check if should be skipped, different for pointers and containers |
---|
98 | template<typename node_t> |
---|
99 | bool skip( const ast::ptr<node_t> & val) { |
---|
100 | return !val; |
---|
101 | } |
---|
102 | |
---|
103 | template< template <class...> class container_t, typename node_t > |
---|
104 | bool skip( const container_t<ast::ptr< node_t >> & val ) { |
---|
105 | return val.empty(); |
---|
106 | } |
---|
107 | |
---|
108 | //------------------------------ |
---|
109 | /// Get the value to visit, different for pointers and containers |
---|
110 | template<typename node_t> |
---|
111 | auto get( const ast::ptr<node_t> & val, int ) -> decltype(val.get()) { |
---|
112 | return val.get(); |
---|
113 | } |
---|
114 | |
---|
115 | template<typename node_t> |
---|
116 | const node_t & get( const node_t & val, long) { |
---|
117 | return val; |
---|
118 | } |
---|
119 | |
---|
120 | |
---|
121 | //------------------------------ |
---|
122 | /// Check if value was mutated, different for pointers and containers |
---|
123 | template<typename lhs_t, typename rhs_t> |
---|
124 | bool differs( const lhs_t * old_val, const rhs_t * new_val ) { |
---|
125 | return old_val != new_val; |
---|
126 | } |
---|
127 | |
---|
128 | template< template <class...> class container_t, typename node_t > |
---|
129 | bool differs( const container_t<ast::ptr< node_t >> &, const container_t<ast::ptr< node_t >> & new_val ) { |
---|
130 | return !new_val.empty(); |
---|
131 | } |
---|
132 | } |
---|
133 | |
---|
134 | template< typename core_t > |
---|
135 | template< typename node_t > |
---|
136 | auto ast::Pass< core_t >::call_accept( const node_t * node ) |
---|
137 | -> typename std::enable_if< |
---|
138 | !std::is_base_of<ast::Expr, node_t>::value && |
---|
139 | !std::is_base_of<ast::Stmt, node_t>::value |
---|
140 | , decltype( node->accept(*this) ) |
---|
141 | >::type |
---|
142 | { |
---|
143 | __pedantic_pass_assert( __visit_children() ); |
---|
144 | __pedantic_pass_assert( node ); |
---|
145 | |
---|
146 | static_assert( !std::is_base_of<ast::Expr, node_t>::value, "ERROR"); |
---|
147 | static_assert( !std::is_base_of<ast::Stmt, node_t>::value, "ERROR"); |
---|
148 | |
---|
149 | return node->accept( *this ); |
---|
150 | } |
---|
151 | |
---|
152 | template< typename core_t > |
---|
153 | const ast::Expr * ast::Pass< core_t >::call_accept( const ast::Expr * expr ) { |
---|
154 | __pedantic_pass_assert( __visit_children() ); |
---|
155 | __pedantic_pass_assert( expr ); |
---|
156 | |
---|
157 | const ast::TypeSubstitution ** typeSubs_ptr = __pass::typeSubs( core, 0 ); |
---|
158 | if ( typeSubs_ptr && expr->env ) { |
---|
159 | *typeSubs_ptr = expr->env; |
---|
160 | } |
---|
161 | |
---|
162 | return expr->accept( *this ); |
---|
163 | } |
---|
164 | |
---|
165 | template< typename core_t > |
---|
166 | const ast::Stmt * ast::Pass< core_t >::call_accept( const ast::Stmt * stmt ) { |
---|
167 | __pedantic_pass_assert( __visit_children() ); |
---|
168 | __pedantic_pass_assert( stmt ); |
---|
169 | |
---|
170 | return stmt->accept( *this ); |
---|
171 | } |
---|
172 | |
---|
173 | template< typename core_t > |
---|
174 | const ast::Stmt * ast::Pass< core_t >::call_accept_as_compound( const ast::Stmt * stmt ) { |
---|
175 | __pedantic_pass_assert( __visit_children() ); |
---|
176 | __pedantic_pass_assert( stmt ); |
---|
177 | |
---|
178 | // add a few useful symbols to the scope |
---|
179 | using __pass::empty; |
---|
180 | |
---|
181 | // get the stmts/decls that will need to be spliced in |
---|
182 | auto stmts_before = __pass::stmtsToAddBefore( core, 0); |
---|
183 | auto stmts_after = __pass::stmtsToAddAfter ( core, 0); |
---|
184 | auto decls_before = __pass::declsToAddBefore( core, 0); |
---|
185 | auto decls_after = __pass::declsToAddAfter ( core, 0); |
---|
186 | |
---|
187 | // These may be modified by subnode but most be restored once we exit this statemnet. |
---|
188 | ValueGuardPtr< const ast::TypeSubstitution * > __old_env ( __pass::typeSubs( core, 0 ) ); |
---|
189 | ValueGuardPtr< typename std::remove_pointer< decltype(stmts_before) >::type > __old_decls_before( stmts_before ); |
---|
190 | ValueGuardPtr< typename std::remove_pointer< decltype(stmts_after ) >::type > __old_decls_after ( stmts_after ); |
---|
191 | ValueGuardPtr< typename std::remove_pointer< decltype(decls_before) >::type > __old_stmts_before( decls_before ); |
---|
192 | ValueGuardPtr< typename std::remove_pointer< decltype(decls_after ) >::type > __old_stmts_after ( decls_after ); |
---|
193 | |
---|
194 | // Now is the time to actually visit the node |
---|
195 | const ast::Stmt * nstmt = stmt->accept( *this ); |
---|
196 | |
---|
197 | // If the pass doesn't want to add anything then we are done |
---|
198 | if( empty(stmts_before) && empty(stmts_after) && empty(decls_before) && empty(decls_after) ) { |
---|
199 | return nstmt; |
---|
200 | } |
---|
201 | |
---|
202 | // Make sure that it is either adding statements or declartions but not both |
---|
203 | // this is because otherwise the order would be awkward to predict |
---|
204 | assert(( empty( stmts_before ) && empty( stmts_after )) |
---|
205 | || ( empty( decls_before ) && empty( decls_after )) ); |
---|
206 | |
---|
207 | // Create a new Compound Statement to hold the new decls/stmts |
---|
208 | ast::CompoundStmt * compound = new ast::CompoundStmt( stmt->location ); |
---|
209 | |
---|
210 | // Take all the declarations that go before |
---|
211 | __pass::take_all( std::back_inserter( compound->kids ), decls_before ); |
---|
212 | __pass::take_all( std::back_inserter( compound->kids ), stmts_before ); |
---|
213 | |
---|
214 | // Insert the original declaration |
---|
215 | compound->kids.emplace_back( nstmt ); |
---|
216 | |
---|
217 | // Insert all the declarations that go before |
---|
218 | __pass::take_all( std::back_inserter( compound->kids ), decls_after ); |
---|
219 | __pass::take_all( std::back_inserter( compound->kids ), stmts_after ); |
---|
220 | |
---|
221 | return compound; |
---|
222 | } |
---|
223 | |
---|
224 | template< typename core_t > |
---|
225 | template< template <class...> class container_t > |
---|
226 | container_t< ptr<Stmt> > ast::Pass< core_t >::call_accept( const container_t< ptr<Stmt> > & statements ) { |
---|
227 | __pedantic_pass_assert( __visit_children() ); |
---|
228 | if( statements.empty() ) return {}; |
---|
229 | |
---|
230 | // We are going to aggregate errors for all these statements |
---|
231 | SemanticErrorException errors; |
---|
232 | |
---|
233 | // add a few useful symbols to the scope |
---|
234 | using __pass::empty; |
---|
235 | |
---|
236 | // get the stmts/decls that will need to be spliced in |
---|
237 | auto stmts_before = __pass::stmtsToAddBefore( core, 0); |
---|
238 | auto stmts_after = __pass::stmtsToAddAfter ( core, 0); |
---|
239 | auto decls_before = __pass::declsToAddBefore( core, 0); |
---|
240 | auto decls_after = __pass::declsToAddAfter ( core, 0); |
---|
241 | |
---|
242 | // These may be modified by subnode but most be restored once we exit this statemnet. |
---|
243 | ValueGuardPtr< typename std::remove_pointer< decltype(stmts_before) >::type > __old_decls_before( stmts_before ); |
---|
244 | ValueGuardPtr< typename std::remove_pointer< decltype(stmts_after ) >::type > __old_decls_after ( stmts_after ); |
---|
245 | ValueGuardPtr< typename std::remove_pointer< decltype(decls_before) >::type > __old_stmts_before( decls_before ); |
---|
246 | ValueGuardPtr< typename std::remove_pointer< decltype(decls_after ) >::type > __old_stmts_after ( decls_after ); |
---|
247 | |
---|
248 | // update pass statitistics |
---|
249 | pass_visitor_stats.depth++; |
---|
250 | pass_visitor_stats.max->push(pass_visitor_stats.depth); |
---|
251 | pass_visitor_stats.avg->push(pass_visitor_stats.depth); |
---|
252 | |
---|
253 | bool mutated = false; |
---|
254 | container_t< ptr<Stmt> > new_kids; |
---|
255 | for( const Stmt * stmt : statements ) { |
---|
256 | try { |
---|
257 | __pedantic_pass_assert( stmt ); |
---|
258 | const ast::Stmt * new_stmt = stmt->accept( *this ); |
---|
259 | assert( new_stmt ); |
---|
260 | if(new_stmt != stmt ) mutated = true; |
---|
261 | |
---|
262 | // Make sure that it is either adding statements or declartions but not both |
---|
263 | // this is because otherwise the order would be awkward to predict |
---|
264 | assert(( empty( stmts_before ) && empty( stmts_after )) |
---|
265 | || ( empty( decls_before ) && empty( decls_after )) ); |
---|
266 | |
---|
267 | |
---|
268 | |
---|
269 | // Take all the statements which should have gone after, N/A for first iteration |
---|
270 | __pass::take_all( std::back_inserter( new_kids ), decls_before, &mutated ); |
---|
271 | __pass::take_all( std::back_inserter( new_kids ), stmts_before, &mutated ); |
---|
272 | |
---|
273 | // Now add the statement if there is one |
---|
274 | new_kids.emplace_back( new_stmt ); |
---|
275 | |
---|
276 | // Take all the declarations that go before |
---|
277 | __pass::take_all( std::back_inserter( new_kids ), decls_after, &mutated ); |
---|
278 | __pass::take_all( std::back_inserter( new_kids ), stmts_after, &mutated ); |
---|
279 | } |
---|
280 | catch ( SemanticErrorException &e ) { |
---|
281 | errors.append( e ); |
---|
282 | } |
---|
283 | } |
---|
284 | pass_visitor_stats.depth--; |
---|
285 | if ( !errors.isEmpty() ) { throw errors; } |
---|
286 | |
---|
287 | return mutated ? new_kids : container_t< ptr<Stmt> >(); |
---|
288 | } |
---|
289 | |
---|
290 | template< typename core_t > |
---|
291 | template< template <class...> class container_t, typename node_t > |
---|
292 | container_t< ast::ptr<node_t> > ast::Pass< core_t >::call_accept( const container_t< ast::ptr<node_t> > & container ) { |
---|
293 | __pedantic_pass_assert( __visit_children() ); |
---|
294 | if( container.empty() ) return {}; |
---|
295 | SemanticErrorException errors; |
---|
296 | |
---|
297 | pass_visitor_stats.depth++; |
---|
298 | pass_visitor_stats.max->push(pass_visitor_stats.depth); |
---|
299 | pass_visitor_stats.avg->push(pass_visitor_stats.depth); |
---|
300 | |
---|
301 | bool mutated = false; |
---|
302 | container_t< ast::ptr<node_t> > new_kids; |
---|
303 | for ( const node_t * node : container ) { |
---|
304 | try { |
---|
305 | __pedantic_pass_assert( node ); |
---|
306 | const node_t * new_stmt = strict_dynamic_cast< const node_t * >( node->accept( *this ) ); |
---|
307 | if(new_stmt != node ) mutated = true; |
---|
308 | |
---|
309 | new_kids.emplace_back( new_stmt ); |
---|
310 | } |
---|
311 | catch( SemanticErrorException &e ) { |
---|
312 | errors.append( e ); |
---|
313 | } |
---|
314 | } |
---|
315 | pass_visitor_stats.depth--; |
---|
316 | if ( ! errors.isEmpty() ) { throw errors; } |
---|
317 | |
---|
318 | return mutated ? new_kids : container_t< ast::ptr<node_t> >(); |
---|
319 | } |
---|
320 | |
---|
321 | template< typename core_t > |
---|
322 | template<typename node_t, typename parent_t, typename child_t> |
---|
323 | void ast::Pass< core_t >::maybe_accept( |
---|
324 | const node_t * & parent, |
---|
325 | child_t parent_t::*child |
---|
326 | ) { |
---|
327 | static_assert( std::is_base_of<parent_t, node_t>::value, "Error deducing member object" ); |
---|
328 | |
---|
329 | if(__pass::skip(parent->*child)) return; |
---|
330 | const auto & old_val = __pass::get(parent->*child, 0); |
---|
331 | |
---|
332 | static_assert( !std::is_same<const ast::Node * &, decltype(old_val)>::value, "ERROR"); |
---|
333 | |
---|
334 | auto new_val = call_accept( old_val ); |
---|
335 | |
---|
336 | static_assert( !std::is_same<const ast::Node *, decltype(new_val)>::value || std::is_same<int, decltype(old_val)>::value, "ERROR"); |
---|
337 | |
---|
338 | if( __pass::differs(old_val, new_val) ) { |
---|
339 | auto new_parent = __pass::mutate<core_t>(parent); |
---|
340 | new_parent->*child = new_val; |
---|
341 | parent = new_parent; |
---|
342 | } |
---|
343 | } |
---|
344 | |
---|
345 | template< typename core_t > |
---|
346 | template<typename node_t, typename parent_t, typename child_t> |
---|
347 | void ast::Pass< core_t >::maybe_accept_as_compound( |
---|
348 | const node_t * & parent, |
---|
349 | child_t parent_t::*child |
---|
350 | ) { |
---|
351 | static_assert( std::is_base_of<parent_t, node_t>::value, "Error deducing member object" ); |
---|
352 | |
---|
353 | if(__pass::skip(parent->*child)) return; |
---|
354 | const auto & old_val = __pass::get(parent->*child, 0); |
---|
355 | |
---|
356 | static_assert( !std::is_same<const ast::Node * &, decltype(old_val)>::value, "ERROR"); |
---|
357 | |
---|
358 | auto new_val = call_accept_as_compound( old_val ); |
---|
359 | |
---|
360 | static_assert( !std::is_same<const ast::Node *, decltype(new_val)>::value || std::is_same<int, decltype(old_val)>::value, "ERROR"); |
---|
361 | |
---|
362 | if( __pass::differs(old_val, new_val) ) { |
---|
363 | auto new_parent = __pass::mutate<core_t>(parent); |
---|
364 | new_parent->*child = new_val; |
---|
365 | parent = new_parent; |
---|
366 | } |
---|
367 | } |
---|
368 | |
---|
369 | } |
---|
370 | |
---|
371 | //------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
---|
372 | //======================================================================================================================================================================== |
---|
373 | //======================================================================================================================================================================== |
---|
374 | //======================================================================================================================================================================== |
---|
375 | //======================================================================================================================================================================== |
---|
376 | //======================================================================================================================================================================== |
---|
377 | //------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
---|
378 | |
---|
379 | template< typename core_t > |
---|
380 | inline void ast::accept_all( std::list< ast::ptr<ast::Decl> > & decls, ast::Pass< core_t > & visitor ) { |
---|
381 | // We are going to aggregate errors for all these statements |
---|
382 | SemanticErrorException errors; |
---|
383 | |
---|
384 | // add a few useful symbols to the scope |
---|
385 | using __pass::empty; |
---|
386 | |
---|
387 | // get the stmts/decls that will need to be spliced in |
---|
388 | auto decls_before = __pass::declsToAddBefore( visitor.core, 0); |
---|
389 | auto decls_after = __pass::declsToAddAfter ( visitor.core, 0); |
---|
390 | |
---|
391 | // update pass statitistics |
---|
392 | pass_visitor_stats.depth++; |
---|
393 | pass_visitor_stats.max->push(pass_visitor_stats.depth); |
---|
394 | pass_visitor_stats.avg->push(pass_visitor_stats.depth); |
---|
395 | |
---|
396 | for ( std::list< ast::ptr<ast::Decl> >::iterator i = decls.begin(); ; ++i ) { |
---|
397 | // splice in new declarations after previous decl |
---|
398 | if ( !empty( decls_after ) ) { decls.splice( i, *decls_after ); } |
---|
399 | |
---|
400 | if ( i == decls.end() ) break; |
---|
401 | |
---|
402 | try { |
---|
403 | // run visitor on declaration |
---|
404 | ast::ptr<ast::Decl> & node = *i; |
---|
405 | assert( node ); |
---|
406 | node = node->accept( visitor ); |
---|
407 | } |
---|
408 | catch( SemanticErrorException &e ) { |
---|
409 | if (__pass::on_error (visitor.core, *i, 0)) |
---|
410 | errors.append( e ); |
---|
411 | } |
---|
412 | |
---|
413 | // splice in new declarations before current decl |
---|
414 | if ( !empty( decls_before ) ) { decls.splice( i, *decls_before ); } |
---|
415 | } |
---|
416 | pass_visitor_stats.depth--; |
---|
417 | if ( !errors.isEmpty() ) { throw errors; } |
---|
418 | } |
---|
419 | |
---|
420 | template< typename core_t > |
---|
421 | inline void ast::accept_all( ast::TranslationUnit & unit, ast::Pass< core_t > & visitor ) { |
---|
422 | return ast::accept_all( unit.decls, visitor ); |
---|
423 | } |
---|
424 | |
---|
425 | // A NOTE ON THE ORDER OF TRAVERSAL |
---|
426 | // |
---|
427 | // Types and typedefs have their base types visited before they are added to the type table. This is ok, since there is |
---|
428 | // no such thing as a recursive type or typedef. |
---|
429 | // |
---|
430 | // typedef struct { T *x; } T; // never allowed |
---|
431 | // |
---|
432 | // for structs/unions, it is possible to have recursion, so the decl should be added as if it's incomplete to begin, the |
---|
433 | // members are traversed, and then the complete type should be added (assuming the type is completed by this particular |
---|
434 | // declaration). |
---|
435 | // |
---|
436 | // struct T { struct T *x; }; // allowed |
---|
437 | // |
---|
438 | // It is important to add the complete type to the symbol table *after* the members/base has been traversed, since that |
---|
439 | // traversal may modify the definition of the type and these modifications should be visible when the symbol table is |
---|
440 | // queried later in this pass. |
---|
441 | |
---|
442 | //-------------------------------------------------------------------------- |
---|
443 | // ObjectDecl |
---|
444 | template< typename core_t > |
---|
445 | const ast::DeclWithType * ast::Pass< core_t >::visit( const ast::ObjectDecl * node ) { |
---|
446 | VISIT_START( node ); |
---|
447 | |
---|
448 | VISIT( |
---|
449 | { |
---|
450 | guard_symtab guard { *this }; |
---|
451 | maybe_accept( node, &ObjectDecl::type ); |
---|
452 | } |
---|
453 | maybe_accept( node, &ObjectDecl::init ); |
---|
454 | maybe_accept( node, &ObjectDecl::bitfieldWidth ); |
---|
455 | maybe_accept( node, &ObjectDecl::attributes ); |
---|
456 | ) |
---|
457 | |
---|
458 | __pass::symtab::addId( core, 0, node ); |
---|
459 | |
---|
460 | VISIT_END( DeclWithType, node ); |
---|
461 | } |
---|
462 | |
---|
463 | //-------------------------------------------------------------------------- |
---|
464 | // FunctionDecl |
---|
465 | template< typename core_t > |
---|
466 | const ast::DeclWithType * ast::Pass< core_t >::visit( const ast::FunctionDecl * node ) { |
---|
467 | VISIT_START( node ); |
---|
468 | |
---|
469 | __pass::symtab::addId( core, 0, node ); |
---|
470 | |
---|
471 | VISIT(maybe_accept( node, &FunctionDecl::withExprs );) |
---|
472 | { |
---|
473 | // with clause introduces a level of scope (for the with expression members). |
---|
474 | // with clause exprs are added to the symbol table before parameters so that parameters |
---|
475 | // shadow with exprs and not the other way around. |
---|
476 | guard_symtab guard { *this }; |
---|
477 | __pass::symtab::addWith( core, 0, node->withExprs, node ); |
---|
478 | { |
---|
479 | guard_symtab guard { *this }; |
---|
480 | // implicit add __func__ identifier as specified in the C manual 6.4.2.2 |
---|
481 | static ast::ptr< ast::ObjectDecl > func{ new ast::ObjectDecl{ |
---|
482 | CodeLocation{}, "__func__", |
---|
483 | new ast::ArrayType{ |
---|
484 | new ast::BasicType{ ast::BasicType::Char, ast::CV::Const }, |
---|
485 | nullptr, VariableLen, DynamicDim |
---|
486 | } |
---|
487 | } }; |
---|
488 | __pass::symtab::addId( core, 0, func ); |
---|
489 | VISIT( |
---|
490 | // parameter declarations |
---|
491 | maybe_accept( node, &FunctionDecl::params ); |
---|
492 | maybe_accept( node, &FunctionDecl::returns ); |
---|
493 | // type params and assertions |
---|
494 | maybe_accept( node, &FunctionDecl::type_params ); |
---|
495 | maybe_accept( node, &FunctionDecl::assertions ); |
---|
496 | // First remember that we are now within a function. |
---|
497 | ValueGuard< bool > oldInFunction( inFunction ); |
---|
498 | inFunction = true; |
---|
499 | // The function body needs to have the same scope as parameters. |
---|
500 | // A CompoundStmt will not enter a new scope if atFunctionTop is true. |
---|
501 | ValueGuard< bool > oldAtFunctionTop( atFunctionTop ); |
---|
502 | atFunctionTop = true; |
---|
503 | maybe_accept( node, &FunctionDecl::stmts ); |
---|
504 | maybe_accept( node, &FunctionDecl::attributes ); |
---|
505 | ) |
---|
506 | } |
---|
507 | } |
---|
508 | |
---|
509 | VISIT_END( DeclWithType, node ); |
---|
510 | } |
---|
511 | |
---|
512 | //-------------------------------------------------------------------------- |
---|
513 | // StructDecl |
---|
514 | template< typename core_t > |
---|
515 | const ast::Decl * ast::Pass< core_t >::visit( const ast::StructDecl * node ) { |
---|
516 | VISIT_START( node ); |
---|
517 | |
---|
518 | // make up a forward declaration and add it before processing the members |
---|
519 | // needs to be on the heap because addStruct saves the pointer |
---|
520 | __pass::symtab::addStructFwd( core, 0, node ); |
---|
521 | |
---|
522 | VISIT({ |
---|
523 | guard_symtab guard { * this }; |
---|
524 | maybe_accept( node, &StructDecl::params ); |
---|
525 | maybe_accept( node, &StructDecl::members ); |
---|
526 | maybe_accept( node, &StructDecl::attributes ); |
---|
527 | }) |
---|
528 | |
---|
529 | // this addition replaces the forward declaration |
---|
530 | __pass::symtab::addStruct( core, 0, node ); |
---|
531 | |
---|
532 | VISIT_END( Decl, node ); |
---|
533 | } |
---|
534 | |
---|
535 | //-------------------------------------------------------------------------- |
---|
536 | // UnionDecl |
---|
537 | template< typename core_t > |
---|
538 | const ast::Decl * ast::Pass< core_t >::visit( const ast::UnionDecl * node ) { |
---|
539 | VISIT_START( node ); |
---|
540 | |
---|
541 | // make up a forward declaration and add it before processing the members |
---|
542 | __pass::symtab::addUnionFwd( core, 0, node ); |
---|
543 | |
---|
544 | VISIT({ |
---|
545 | guard_symtab guard { * this }; |
---|
546 | maybe_accept( node, &UnionDecl::params ); |
---|
547 | maybe_accept( node, &UnionDecl::members ); |
---|
548 | maybe_accept( node, &UnionDecl::attributes ); |
---|
549 | }) |
---|
550 | |
---|
551 | __pass::symtab::addUnion( core, 0, node ); |
---|
552 | |
---|
553 | VISIT_END( Decl, node ); |
---|
554 | } |
---|
555 | |
---|
556 | //-------------------------------------------------------------------------- |
---|
557 | // EnumDecl |
---|
558 | template< typename core_t > |
---|
559 | const ast::Decl * ast::Pass< core_t >::visit( const ast::EnumDecl * node ) { |
---|
560 | VISIT_START( node ); |
---|
561 | |
---|
562 | __pass::symtab::addEnum( core, 0, node ); |
---|
563 | |
---|
564 | VISIT( |
---|
565 | // unlike structs, traits, and unions, enums inject their members into the global scope |
---|
566 | maybe_accept( node, &EnumDecl::params ); |
---|
567 | maybe_accept( node, &EnumDecl::members ); |
---|
568 | maybe_accept( node, &EnumDecl::attributes ); |
---|
569 | ) |
---|
570 | |
---|
571 | VISIT_END( Decl, node ); |
---|
572 | } |
---|
573 | |
---|
574 | //-------------------------------------------------------------------------- |
---|
575 | // TraitDecl |
---|
576 | template< typename core_t > |
---|
577 | const ast::Decl * ast::Pass< core_t >::visit( const ast::TraitDecl * node ) { |
---|
578 | VISIT_START( node ); |
---|
579 | |
---|
580 | VISIT({ |
---|
581 | guard_symtab guard { *this }; |
---|
582 | maybe_accept( node, &TraitDecl::params ); |
---|
583 | maybe_accept( node, &TraitDecl::members ); |
---|
584 | maybe_accept( node, &TraitDecl::attributes ); |
---|
585 | }) |
---|
586 | |
---|
587 | __pass::symtab::addTrait( core, 0, node ); |
---|
588 | |
---|
589 | VISIT_END( Decl, node ); |
---|
590 | } |
---|
591 | |
---|
592 | //-------------------------------------------------------------------------- |
---|
593 | // TypeDecl |
---|
594 | template< typename core_t > |
---|
595 | const ast::Decl * ast::Pass< core_t >::visit( const ast::TypeDecl * node ) { |
---|
596 | VISIT_START( node ); |
---|
597 | |
---|
598 | VISIT({ |
---|
599 | guard_symtab guard { *this }; |
---|
600 | maybe_accept( node, &TypeDecl::base ); |
---|
601 | }) |
---|
602 | |
---|
603 | // see A NOTE ON THE ORDER OF TRAVERSAL, above |
---|
604 | // note that assertions come after the type is added to the symtab, since they are not part of the type proper |
---|
605 | // and may depend on the type itself |
---|
606 | __pass::symtab::addType( core, 0, node ); |
---|
607 | |
---|
608 | VISIT( |
---|
609 | maybe_accept( node, &TypeDecl::assertions ); |
---|
610 | |
---|
611 | { |
---|
612 | guard_symtab guard { *this }; |
---|
613 | maybe_accept( node, &TypeDecl::init ); |
---|
614 | } |
---|
615 | ) |
---|
616 | |
---|
617 | VISIT_END( Decl, node ); |
---|
618 | } |
---|
619 | |
---|
620 | //-------------------------------------------------------------------------- |
---|
621 | // TypedefDecl |
---|
622 | template< typename core_t > |
---|
623 | const ast::Decl * ast::Pass< core_t >::visit( const ast::TypedefDecl * node ) { |
---|
624 | VISIT_START( node ); |
---|
625 | |
---|
626 | VISIT({ |
---|
627 | guard_symtab guard { *this }; |
---|
628 | maybe_accept( node, &TypedefDecl::base ); |
---|
629 | }) |
---|
630 | |
---|
631 | __pass::symtab::addType( core, 0, node ); |
---|
632 | |
---|
633 | VISIT( maybe_accept( node, &TypedefDecl::assertions ); ) |
---|
634 | |
---|
635 | VISIT_END( Decl, node ); |
---|
636 | } |
---|
637 | |
---|
638 | //-------------------------------------------------------------------------- |
---|
639 | // AsmDecl |
---|
640 | template< typename core_t > |
---|
641 | const ast::AsmDecl * ast::Pass< core_t >::visit( const ast::AsmDecl * node ) { |
---|
642 | VISIT_START( node ); |
---|
643 | |
---|
644 | VISIT( |
---|
645 | maybe_accept( node, &AsmDecl::stmt ); |
---|
646 | ) |
---|
647 | |
---|
648 | VISIT_END( AsmDecl, node ); |
---|
649 | } |
---|
650 | |
---|
651 | //-------------------------------------------------------------------------- |
---|
652 | // DirectiveDecl |
---|
653 | template< typename core_t > |
---|
654 | const ast::DirectiveDecl * ast::Pass< core_t >::visit( const ast::DirectiveDecl * node ) { |
---|
655 | VISIT_START( node ); |
---|
656 | |
---|
657 | VISIT( |
---|
658 | maybe_accept( node, &DirectiveDecl::stmt ); |
---|
659 | ) |
---|
660 | |
---|
661 | VISIT_END( DirectiveDecl, node ); |
---|
662 | } |
---|
663 | |
---|
664 | //-------------------------------------------------------------------------- |
---|
665 | // StaticAssertDecl |
---|
666 | template< typename core_t > |
---|
667 | const ast::StaticAssertDecl * ast::Pass< core_t >::visit( const ast::StaticAssertDecl * node ) { |
---|
668 | VISIT_START( node ); |
---|
669 | |
---|
670 | VISIT( |
---|
671 | maybe_accept( node, &StaticAssertDecl::cond ); |
---|
672 | maybe_accept( node, &StaticAssertDecl::msg ); |
---|
673 | ) |
---|
674 | |
---|
675 | VISIT_END( StaticAssertDecl, node ); |
---|
676 | } |
---|
677 | |
---|
678 | //-------------------------------------------------------------------------- |
---|
679 | // CompoundStmt |
---|
680 | template< typename core_t > |
---|
681 | const ast::CompoundStmt * ast::Pass< core_t >::visit( const ast::CompoundStmt * node ) { |
---|
682 | VISIT_START( node ); |
---|
683 | VISIT( |
---|
684 | // Do not enter (or leave) a new scope if atFunctionTop. Remember to save the result. |
---|
685 | auto guard1 = makeFuncGuard( [this, enterScope = !this->atFunctionTop]() { |
---|
686 | if ( enterScope ) { |
---|
687 | __pass::symtab::enter(core, 0); |
---|
688 | __pass::scope::enter(core, 0); |
---|
689 | } |
---|
690 | }, [this, leaveScope = !this->atFunctionTop]() { |
---|
691 | if ( leaveScope ) { |
---|
692 | __pass::symtab::leave(core, 0); |
---|
693 | __pass::scope::leave(core, 0); |
---|
694 | } |
---|
695 | }); |
---|
696 | ValueGuard< bool > guard2( atFunctionTop ); |
---|
697 | atFunctionTop = false; |
---|
698 | guard_scope guard3 { *this }; |
---|
699 | maybe_accept( node, &CompoundStmt::kids ); |
---|
700 | ) |
---|
701 | VISIT_END( CompoundStmt, node ); |
---|
702 | } |
---|
703 | |
---|
704 | //-------------------------------------------------------------------------- |
---|
705 | // ExprStmt |
---|
706 | template< typename core_t > |
---|
707 | const ast::Stmt * ast::Pass< core_t >::visit( const ast::ExprStmt * node ) { |
---|
708 | VISIT_START( node ); |
---|
709 | |
---|
710 | VISIT( |
---|
711 | maybe_accept( node, &ExprStmt::expr ); |
---|
712 | ) |
---|
713 | |
---|
714 | VISIT_END( Stmt, node ); |
---|
715 | } |
---|
716 | |
---|
717 | //-------------------------------------------------------------------------- |
---|
718 | // AsmStmt |
---|
719 | template< typename core_t > |
---|
720 | const ast::Stmt * ast::Pass< core_t >::visit( const ast::AsmStmt * node ) { |
---|
721 | VISIT_START( node ) |
---|
722 | |
---|
723 | VISIT( |
---|
724 | maybe_accept( node, &AsmStmt::instruction ); |
---|
725 | maybe_accept( node, &AsmStmt::output ); |
---|
726 | maybe_accept( node, &AsmStmt::input ); |
---|
727 | maybe_accept( node, &AsmStmt::clobber ); |
---|
728 | ) |
---|
729 | |
---|
730 | VISIT_END( Stmt, node ); |
---|
731 | } |
---|
732 | |
---|
733 | //-------------------------------------------------------------------------- |
---|
734 | // DirectiveStmt |
---|
735 | template< typename core_t > |
---|
736 | const ast::Stmt * ast::Pass< core_t >::visit( const ast::DirectiveStmt * node ) { |
---|
737 | VISIT_START( node ) |
---|
738 | |
---|
739 | VISIT_END( Stmt, node ); |
---|
740 | } |
---|
741 | |
---|
742 | //-------------------------------------------------------------------------- |
---|
743 | // IfStmt |
---|
744 | template< typename core_t > |
---|
745 | const ast::Stmt * ast::Pass< core_t >::visit( const ast::IfStmt * node ) { |
---|
746 | VISIT_START( node ); |
---|
747 | |
---|
748 | VISIT({ |
---|
749 | // if statements introduce a level of scope (for the initialization) |
---|
750 | guard_symtab guard { *this }; |
---|
751 | maybe_accept( node, &IfStmt::inits ); |
---|
752 | maybe_accept( node, &IfStmt::cond ); |
---|
753 | maybe_accept_as_compound( node, &IfStmt::thenPart ); |
---|
754 | maybe_accept_as_compound( node, &IfStmt::elsePart ); |
---|
755 | }) |
---|
756 | |
---|
757 | VISIT_END( Stmt, node ); |
---|
758 | } |
---|
759 | |
---|
760 | //-------------------------------------------------------------------------- |
---|
761 | // WhileStmt |
---|
762 | template< typename core_t > |
---|
763 | const ast::Stmt * ast::Pass< core_t >::visit( const ast::WhileStmt * node ) { |
---|
764 | VISIT_START( node ); |
---|
765 | |
---|
766 | VISIT({ |
---|
767 | // while statements introduce a level of scope (for the initialization) |
---|
768 | guard_symtab guard { *this }; |
---|
769 | maybe_accept( node, &WhileStmt::inits ); |
---|
770 | maybe_accept( node, &WhileStmt::cond ); |
---|
771 | maybe_accept_as_compound( node, &WhileStmt::body ); |
---|
772 | }) |
---|
773 | |
---|
774 | VISIT_END( Stmt, node ); |
---|
775 | } |
---|
776 | |
---|
777 | //-------------------------------------------------------------------------- |
---|
778 | // ForStmt |
---|
779 | template< typename core_t > |
---|
780 | const ast::Stmt * ast::Pass< core_t >::visit( const ast::ForStmt * node ) { |
---|
781 | VISIT_START( node ); |
---|
782 | |
---|
783 | VISIT({ |
---|
784 | // for statements introduce a level of scope (for the initialization) |
---|
785 | guard_symtab guard { *this }; |
---|
786 | // xxx - old ast does not create WithStmtsToAdd scope for loop inits. should revisit this later. |
---|
787 | maybe_accept( node, &ForStmt::inits ); |
---|
788 | maybe_accept( node, &ForStmt::cond ); |
---|
789 | maybe_accept( node, &ForStmt::inc ); |
---|
790 | maybe_accept_as_compound( node, &ForStmt::body ); |
---|
791 | }) |
---|
792 | |
---|
793 | VISIT_END( Stmt, node ); |
---|
794 | } |
---|
795 | |
---|
796 | //-------------------------------------------------------------------------- |
---|
797 | // SwitchStmt |
---|
798 | template< typename core_t > |
---|
799 | const ast::Stmt * ast::Pass< core_t >::visit( const ast::SwitchStmt * node ) { |
---|
800 | VISIT_START( node ); |
---|
801 | |
---|
802 | VISIT( |
---|
803 | maybe_accept( node, &SwitchStmt::cond ); |
---|
804 | maybe_accept( node, &SwitchStmt::stmts ); |
---|
805 | ) |
---|
806 | |
---|
807 | VISIT_END( Stmt, node ); |
---|
808 | } |
---|
809 | |
---|
810 | //-------------------------------------------------------------------------- |
---|
811 | // CaseStmt |
---|
812 | template< typename core_t > |
---|
813 | const ast::Stmt * ast::Pass< core_t >::visit( const ast::CaseStmt * node ) { |
---|
814 | VISIT_START( node ); |
---|
815 | |
---|
816 | VISIT( |
---|
817 | maybe_accept( node, &CaseStmt::cond ); |
---|
818 | maybe_accept( node, &CaseStmt::stmts ); |
---|
819 | ) |
---|
820 | |
---|
821 | VISIT_END( Stmt, node ); |
---|
822 | } |
---|
823 | |
---|
824 | //-------------------------------------------------------------------------- |
---|
825 | // BranchStmt |
---|
826 | template< typename core_t > |
---|
827 | const ast::Stmt * ast::Pass< core_t >::visit( const ast::BranchStmt * node ) { |
---|
828 | VISIT_START( node ); |
---|
829 | VISIT_END( Stmt, node ); |
---|
830 | } |
---|
831 | |
---|
832 | //-------------------------------------------------------------------------- |
---|
833 | // ReturnStmt |
---|
834 | template< typename core_t > |
---|
835 | const ast::Stmt * ast::Pass< core_t >::visit( const ast::ReturnStmt * node ) { |
---|
836 | VISIT_START( node ); |
---|
837 | |
---|
838 | VISIT( |
---|
839 | maybe_accept( node, &ReturnStmt::expr ); |
---|
840 | ) |
---|
841 | |
---|
842 | VISIT_END( Stmt, node ); |
---|
843 | } |
---|
844 | |
---|
845 | //-------------------------------------------------------------------------- |
---|
846 | // ThrowStmt |
---|
847 | template< typename core_t > |
---|
848 | const ast::Stmt * ast::Pass< core_t >::visit( const ast::ThrowStmt * node ) { |
---|
849 | VISIT_START( node ); |
---|
850 | |
---|
851 | VISIT( |
---|
852 | maybe_accept( node, &ThrowStmt::expr ); |
---|
853 | maybe_accept( node, &ThrowStmt::target ); |
---|
854 | ) |
---|
855 | |
---|
856 | VISIT_END( Stmt, node ); |
---|
857 | } |
---|
858 | |
---|
859 | //-------------------------------------------------------------------------- |
---|
860 | // TryStmt |
---|
861 | template< typename core_t > |
---|
862 | const ast::Stmt * ast::Pass< core_t >::visit( const ast::TryStmt * node ) { |
---|
863 | VISIT_START( node ); |
---|
864 | |
---|
865 | VISIT( |
---|
866 | maybe_accept( node, &TryStmt::body ); |
---|
867 | maybe_accept( node, &TryStmt::handlers ); |
---|
868 | maybe_accept( node, &TryStmt::finally ); |
---|
869 | ) |
---|
870 | |
---|
871 | VISIT_END( Stmt, node ); |
---|
872 | } |
---|
873 | |
---|
874 | //-------------------------------------------------------------------------- |
---|
875 | // CatchStmt |
---|
876 | template< typename core_t > |
---|
877 | const ast::Stmt * ast::Pass< core_t >::visit( const ast::CatchStmt * node ) { |
---|
878 | VISIT_START( node ); |
---|
879 | |
---|
880 | VISIT({ |
---|
881 | // catch statements introduce a level of scope (for the caught exception) |
---|
882 | guard_symtab guard { *this }; |
---|
883 | maybe_accept( node, &CatchStmt::decl ); |
---|
884 | maybe_accept( node, &CatchStmt::cond ); |
---|
885 | maybe_accept_as_compound( node, &CatchStmt::body ); |
---|
886 | }) |
---|
887 | |
---|
888 | VISIT_END( Stmt, node ); |
---|
889 | } |
---|
890 | |
---|
891 | //-------------------------------------------------------------------------- |
---|
892 | // FinallyStmt |
---|
893 | template< typename core_t > |
---|
894 | const ast::Stmt * ast::Pass< core_t >::visit( const ast::FinallyStmt * node ) { |
---|
895 | VISIT_START( node ); |
---|
896 | |
---|
897 | VISIT( |
---|
898 | maybe_accept( node, &FinallyStmt::body ); |
---|
899 | ) |
---|
900 | |
---|
901 | VISIT_END( Stmt, node ); |
---|
902 | } |
---|
903 | |
---|
904 | //-------------------------------------------------------------------------- |
---|
905 | // FinallyStmt |
---|
906 | template< typename core_t > |
---|
907 | const ast::Stmt * ast::Pass< core_t >::visit( const ast::SuspendStmt * node ) { |
---|
908 | VISIT_START( node ); |
---|
909 | |
---|
910 | VISIT( |
---|
911 | maybe_accept( node, &SuspendStmt::then ); |
---|
912 | ) |
---|
913 | |
---|
914 | VISIT_END( Stmt, node ); |
---|
915 | } |
---|
916 | |
---|
917 | //-------------------------------------------------------------------------- |
---|
918 | // WaitForStmt |
---|
919 | template< typename core_t > |
---|
920 | const ast::Stmt * ast::Pass< core_t >::visit( const ast::WaitForStmt * node ) { |
---|
921 | VISIT_START( node ); |
---|
922 | // for( auto & clause : node->clauses ) { |
---|
923 | // maybeAccept_impl( clause.target.function, *this ); |
---|
924 | // maybeAccept_impl( clause.target.arguments, *this ); |
---|
925 | |
---|
926 | // maybeAccept_impl( clause.statement, *this ); |
---|
927 | // maybeAccept_impl( clause.condition, *this ); |
---|
928 | // } |
---|
929 | |
---|
930 | VISIT({ |
---|
931 | std::vector<WaitForStmt::Clause> new_clauses; |
---|
932 | new_clauses.reserve( node->clauses.size() ); |
---|
933 | bool mutated = false; |
---|
934 | for( const auto & clause : node->clauses ) { |
---|
935 | |
---|
936 | const Expr * func = clause.target.func ? clause.target.func->accept(*this) : nullptr; |
---|
937 | if(func != clause.target.func) mutated = true; |
---|
938 | |
---|
939 | std::vector<ptr<Expr>> new_args; |
---|
940 | new_args.reserve(clause.target.args.size()); |
---|
941 | for( const auto & arg : clause.target.args ) { |
---|
942 | auto a = arg->accept(*this); |
---|
943 | new_args.push_back( a ); |
---|
944 | if( a != arg ) mutated = true; |
---|
945 | } |
---|
946 | |
---|
947 | const Stmt * stmt = clause.stmt ? clause.stmt->accept(*this) : nullptr; |
---|
948 | if(stmt != clause.stmt) mutated = true; |
---|
949 | |
---|
950 | const Expr * cond = clause.cond ? clause.cond->accept(*this) : nullptr; |
---|
951 | if(cond != clause.cond) mutated = true; |
---|
952 | |
---|
953 | new_clauses.push_back( WaitForStmt::Clause{ {func, std::move(new_args) }, stmt, cond } ); |
---|
954 | } |
---|
955 | |
---|
956 | if(mutated) { |
---|
957 | auto n = __pass::mutate<core_t>(node); |
---|
958 | n->clauses = std::move( new_clauses ); |
---|
959 | node = n; |
---|
960 | } |
---|
961 | }) |
---|
962 | |
---|
963 | #define maybe_accept(field) \ |
---|
964 | if(node->field) { \ |
---|
965 | auto nval = call_accept( node->field ); \ |
---|
966 | if(nval != node->field ) { \ |
---|
967 | auto nparent = __pass::mutate<core_t>(node); \ |
---|
968 | nparent->field = nval; \ |
---|
969 | node = nparent; \ |
---|
970 | } \ |
---|
971 | } |
---|
972 | |
---|
973 | VISIT( |
---|
974 | maybe_accept( timeout.time ); |
---|
975 | maybe_accept( timeout.stmt ); |
---|
976 | maybe_accept( timeout.cond ); |
---|
977 | maybe_accept( orElse.stmt ); |
---|
978 | maybe_accept( orElse.cond ); |
---|
979 | ) |
---|
980 | |
---|
981 | #undef maybe_accept |
---|
982 | |
---|
983 | VISIT_END( Stmt, node ); |
---|
984 | } |
---|
985 | |
---|
986 | //-------------------------------------------------------------------------- |
---|
987 | // WithStmt |
---|
988 | template< typename core_t > |
---|
989 | const ast::Decl * ast::Pass< core_t >::visit( const ast::WithStmt * node ) { |
---|
990 | VISIT_START( node ); |
---|
991 | |
---|
992 | VISIT( |
---|
993 | maybe_accept( node, &WithStmt::exprs ); |
---|
994 | { |
---|
995 | // catch statements introduce a level of scope (for the caught exception) |
---|
996 | guard_symtab guard { *this }; |
---|
997 | __pass::symtab::addWith( core, 0, node->exprs, node ); |
---|
998 | maybe_accept( node, &WithStmt::stmt ); |
---|
999 | } |
---|
1000 | ) |
---|
1001 | VISIT_END( Stmt, node ); |
---|
1002 | } |
---|
1003 | |
---|
1004 | //-------------------------------------------------------------------------- |
---|
1005 | // NullStmt |
---|
1006 | template< typename core_t > |
---|
1007 | const ast::NullStmt * ast::Pass< core_t >::visit( const ast::NullStmt * node ) { |
---|
1008 | VISIT_START( node ); |
---|
1009 | VISIT_END( NullStmt, node ); |
---|
1010 | } |
---|
1011 | |
---|
1012 | //-------------------------------------------------------------------------- |
---|
1013 | // DeclStmt |
---|
1014 | template< typename core_t > |
---|
1015 | const ast::Stmt * ast::Pass< core_t >::visit( const ast::DeclStmt * node ) { |
---|
1016 | VISIT_START( node ); |
---|
1017 | |
---|
1018 | VISIT( |
---|
1019 | maybe_accept( node, &DeclStmt::decl ); |
---|
1020 | ) |
---|
1021 | |
---|
1022 | VISIT_END( Stmt, node ); |
---|
1023 | } |
---|
1024 | |
---|
1025 | //-------------------------------------------------------------------------- |
---|
1026 | // ImplicitCtorDtorStmt |
---|
1027 | template< typename core_t > |
---|
1028 | const ast::Stmt * ast::Pass< core_t >::visit( const ast::ImplicitCtorDtorStmt * node ) { |
---|
1029 | VISIT_START( node ); |
---|
1030 | |
---|
1031 | // For now this isn't visited, it is unclear if this causes problem |
---|
1032 | // if all tests are known to pass, remove this code |
---|
1033 | VISIT( |
---|
1034 | maybe_accept( node, &ImplicitCtorDtorStmt::callStmt ); |
---|
1035 | ) |
---|
1036 | |
---|
1037 | VISIT_END( Stmt, node ); |
---|
1038 | } |
---|
1039 | |
---|
1040 | //-------------------------------------------------------------------------- |
---|
1041 | // MutexStmt |
---|
1042 | template< typename core_t > |
---|
1043 | const ast::Stmt * ast::Pass< core_t >::visit( const ast::MutexStmt * node ) { |
---|
1044 | VISIT_START( node ); |
---|
1045 | |
---|
1046 | VISIT({ |
---|
1047 | // mutex statements introduce a level of scope (for the initialization) |
---|
1048 | guard_symtab guard { *this }; |
---|
1049 | maybe_accept( node, &MutexStmt::stmt ); |
---|
1050 | maybe_accept( node, &MutexStmt::mutexObjs ); |
---|
1051 | }) |
---|
1052 | |
---|
1053 | VISIT_END( Stmt, node ); |
---|
1054 | } |
---|
1055 | |
---|
1056 | //-------------------------------------------------------------------------- |
---|
1057 | // ApplicationExpr |
---|
1058 | template< typename core_t > |
---|
1059 | const ast::Expr * ast::Pass< core_t >::visit( const ast::ApplicationExpr * node ) { |
---|
1060 | VISIT_START( node ); |
---|
1061 | |
---|
1062 | VISIT( |
---|
1063 | { |
---|
1064 | guard_symtab guard { *this }; |
---|
1065 | maybe_accept( node, &ApplicationExpr::result ); |
---|
1066 | } |
---|
1067 | maybe_accept( node, &ApplicationExpr::func ); |
---|
1068 | maybe_accept( node, &ApplicationExpr::args ); |
---|
1069 | ) |
---|
1070 | |
---|
1071 | VISIT_END( Expr, node ); |
---|
1072 | } |
---|
1073 | |
---|
1074 | //-------------------------------------------------------------------------- |
---|
1075 | // UntypedExpr |
---|
1076 | template< typename core_t > |
---|
1077 | const ast::Expr * ast::Pass< core_t >::visit( const ast::UntypedExpr * node ) { |
---|
1078 | VISIT_START( node ); |
---|
1079 | |
---|
1080 | VISIT( |
---|
1081 | { |
---|
1082 | guard_symtab guard { *this }; |
---|
1083 | maybe_accept( node, &UntypedExpr::result ); |
---|
1084 | } |
---|
1085 | |
---|
1086 | maybe_accept( node, &UntypedExpr::args ); |
---|
1087 | ) |
---|
1088 | |
---|
1089 | VISIT_END( Expr, node ); |
---|
1090 | } |
---|
1091 | |
---|
1092 | //-------------------------------------------------------------------------- |
---|
1093 | // NameExpr |
---|
1094 | template< typename core_t > |
---|
1095 | const ast::Expr * ast::Pass< core_t >::visit( const ast::NameExpr * node ) { |
---|
1096 | VISIT_START( node ); |
---|
1097 | |
---|
1098 | VISIT({ |
---|
1099 | guard_symtab guard { *this }; |
---|
1100 | maybe_accept( node, &NameExpr::result ); |
---|
1101 | }) |
---|
1102 | |
---|
1103 | VISIT_END( Expr, node ); |
---|
1104 | } |
---|
1105 | |
---|
1106 | //-------------------------------------------------------------------------- |
---|
1107 | // CastExpr |
---|
1108 | template< typename core_t > |
---|
1109 | const ast::Expr * ast::Pass< core_t >::visit( const ast::CastExpr * node ) { |
---|
1110 | VISIT_START( node ); |
---|
1111 | |
---|
1112 | VISIT({ |
---|
1113 | guard_symtab guard { *this }; |
---|
1114 | maybe_accept( node, &CastExpr::result ); |
---|
1115 | } |
---|
1116 | maybe_accept( node, &CastExpr::arg ); |
---|
1117 | ) |
---|
1118 | |
---|
1119 | VISIT_END( Expr, node ); |
---|
1120 | } |
---|
1121 | |
---|
1122 | //-------------------------------------------------------------------------- |
---|
1123 | // KeywordCastExpr |
---|
1124 | template< typename core_t > |
---|
1125 | const ast::Expr * ast::Pass< core_t >::visit( const ast::KeywordCastExpr * node ) { |
---|
1126 | VISIT_START( node ); |
---|
1127 | |
---|
1128 | VISIT({ |
---|
1129 | guard_symtab guard { *this }; |
---|
1130 | maybe_accept( node, &KeywordCastExpr::result ); |
---|
1131 | } |
---|
1132 | maybe_accept( node, &KeywordCastExpr::arg ); |
---|
1133 | ) |
---|
1134 | |
---|
1135 | VISIT_END( Expr, node ); |
---|
1136 | } |
---|
1137 | |
---|
1138 | //-------------------------------------------------------------------------- |
---|
1139 | // VirtualCastExpr |
---|
1140 | template< typename core_t > |
---|
1141 | const ast::Expr * ast::Pass< core_t >::visit( const ast::VirtualCastExpr * node ) { |
---|
1142 | VISIT_START( node ); |
---|
1143 | |
---|
1144 | VISIT({ |
---|
1145 | guard_symtab guard { *this }; |
---|
1146 | maybe_accept( node, &VirtualCastExpr::result ); |
---|
1147 | } |
---|
1148 | maybe_accept( node, &VirtualCastExpr::arg ); |
---|
1149 | ) |
---|
1150 | |
---|
1151 | VISIT_END( Expr, node ); |
---|
1152 | } |
---|
1153 | |
---|
1154 | //-------------------------------------------------------------------------- |
---|
1155 | // AddressExpr |
---|
1156 | template< typename core_t > |
---|
1157 | const ast::Expr * ast::Pass< core_t >::visit( const ast::AddressExpr * node ) { |
---|
1158 | VISIT_START( node ); |
---|
1159 | |
---|
1160 | VISIT({ |
---|
1161 | guard_symtab guard { *this }; |
---|
1162 | maybe_accept( node, &AddressExpr::result ); |
---|
1163 | } |
---|
1164 | maybe_accept( node, &AddressExpr::arg ); |
---|
1165 | ) |
---|
1166 | |
---|
1167 | VISIT_END( Expr, node ); |
---|
1168 | } |
---|
1169 | |
---|
1170 | //-------------------------------------------------------------------------- |
---|
1171 | // LabelAddressExpr |
---|
1172 | template< typename core_t > |
---|
1173 | const ast::Expr * ast::Pass< core_t >::visit( const ast::LabelAddressExpr * node ) { |
---|
1174 | VISIT_START( node ); |
---|
1175 | |
---|
1176 | VISIT({ |
---|
1177 | guard_symtab guard { *this }; |
---|
1178 | maybe_accept( node, &LabelAddressExpr::result ); |
---|
1179 | }) |
---|
1180 | |
---|
1181 | VISIT_END( Expr, node ); |
---|
1182 | } |
---|
1183 | |
---|
1184 | //-------------------------------------------------------------------------- |
---|
1185 | // UntypedMemberExpr |
---|
1186 | template< typename core_t > |
---|
1187 | const ast::Expr * ast::Pass< core_t >::visit( const ast::UntypedMemberExpr * node ) { |
---|
1188 | VISIT_START( node ); |
---|
1189 | |
---|
1190 | VISIT({ |
---|
1191 | guard_symtab guard { *this }; |
---|
1192 | maybe_accept( node, &UntypedMemberExpr::result ); |
---|
1193 | } |
---|
1194 | maybe_accept( node, &UntypedMemberExpr::aggregate ); |
---|
1195 | maybe_accept( node, &UntypedMemberExpr::member ); |
---|
1196 | ) |
---|
1197 | |
---|
1198 | VISIT_END( Expr, node ); |
---|
1199 | } |
---|
1200 | |
---|
1201 | //-------------------------------------------------------------------------- |
---|
1202 | // MemberExpr |
---|
1203 | template< typename core_t > |
---|
1204 | const ast::Expr * ast::Pass< core_t >::visit( const ast::MemberExpr * node ) { |
---|
1205 | VISIT_START( node ); |
---|
1206 | |
---|
1207 | VISIT({ |
---|
1208 | guard_symtab guard { *this }; |
---|
1209 | maybe_accept( node, &MemberExpr::result ); |
---|
1210 | } |
---|
1211 | maybe_accept( node, &MemberExpr::aggregate ); |
---|
1212 | ) |
---|
1213 | |
---|
1214 | VISIT_END( Expr, node ); |
---|
1215 | } |
---|
1216 | |
---|
1217 | //-------------------------------------------------------------------------- |
---|
1218 | // VariableExpr |
---|
1219 | template< typename core_t > |
---|
1220 | const ast::Expr * ast::Pass< core_t >::visit( const ast::VariableExpr * node ) { |
---|
1221 | VISIT_START( node ); |
---|
1222 | |
---|
1223 | VISIT({ |
---|
1224 | guard_symtab guard { *this }; |
---|
1225 | maybe_accept( node, &VariableExpr::result ); |
---|
1226 | }) |
---|
1227 | |
---|
1228 | VISIT_END( Expr, node ); |
---|
1229 | } |
---|
1230 | |
---|
1231 | //-------------------------------------------------------------------------- |
---|
1232 | // ConstantExpr |
---|
1233 | template< typename core_t > |
---|
1234 | const ast::Expr * ast::Pass< core_t >::visit( const ast::ConstantExpr * node ) { |
---|
1235 | VISIT_START( node ); |
---|
1236 | |
---|
1237 | VISIT({ |
---|
1238 | guard_symtab guard { *this }; |
---|
1239 | maybe_accept( node, &ConstantExpr::result ); |
---|
1240 | }) |
---|
1241 | |
---|
1242 | VISIT_END( Expr, node ); |
---|
1243 | } |
---|
1244 | |
---|
1245 | //-------------------------------------------------------------------------- |
---|
1246 | // SizeofExpr |
---|
1247 | template< typename core_t > |
---|
1248 | const ast::Expr * ast::Pass< core_t >::visit( const ast::SizeofExpr * node ) { |
---|
1249 | VISIT_START( node ); |
---|
1250 | |
---|
1251 | VISIT({ |
---|
1252 | guard_symtab guard { *this }; |
---|
1253 | maybe_accept( node, &SizeofExpr::result ); |
---|
1254 | } |
---|
1255 | if ( node->type ) { |
---|
1256 | maybe_accept( node, &SizeofExpr::type ); |
---|
1257 | } else { |
---|
1258 | maybe_accept( node, &SizeofExpr::expr ); |
---|
1259 | } |
---|
1260 | ) |
---|
1261 | |
---|
1262 | VISIT_END( Expr, node ); |
---|
1263 | } |
---|
1264 | |
---|
1265 | //-------------------------------------------------------------------------- |
---|
1266 | // AlignofExpr |
---|
1267 | template< typename core_t > |
---|
1268 | const ast::Expr * ast::Pass< core_t >::visit( const ast::AlignofExpr * node ) { |
---|
1269 | VISIT_START( node ); |
---|
1270 | |
---|
1271 | VISIT({ |
---|
1272 | guard_symtab guard { *this }; |
---|
1273 | maybe_accept( node, &AlignofExpr::result ); |
---|
1274 | } |
---|
1275 | if ( node->type ) { |
---|
1276 | maybe_accept( node, &AlignofExpr::type ); |
---|
1277 | } else { |
---|
1278 | maybe_accept( node, &AlignofExpr::expr ); |
---|
1279 | } |
---|
1280 | ) |
---|
1281 | |
---|
1282 | VISIT_END( Expr, node ); |
---|
1283 | } |
---|
1284 | |
---|
1285 | //-------------------------------------------------------------------------- |
---|
1286 | // UntypedOffsetofExpr |
---|
1287 | template< typename core_t > |
---|
1288 | const ast::Expr * ast::Pass< core_t >::visit( const ast::UntypedOffsetofExpr * node ) { |
---|
1289 | VISIT_START( node ); |
---|
1290 | |
---|
1291 | VISIT({ |
---|
1292 | guard_symtab guard { *this }; |
---|
1293 | maybe_accept( node, &UntypedOffsetofExpr::result ); |
---|
1294 | } |
---|
1295 | maybe_accept( node, &UntypedOffsetofExpr::type ); |
---|
1296 | ) |
---|
1297 | |
---|
1298 | VISIT_END( Expr, node ); |
---|
1299 | } |
---|
1300 | |
---|
1301 | //-------------------------------------------------------------------------- |
---|
1302 | // OffsetofExpr |
---|
1303 | template< typename core_t > |
---|
1304 | const ast::Expr * ast::Pass< core_t >::visit( const ast::OffsetofExpr * node ) { |
---|
1305 | VISIT_START( node ); |
---|
1306 | |
---|
1307 | VISIT({ |
---|
1308 | guard_symtab guard { *this }; |
---|
1309 | maybe_accept( node, &OffsetofExpr::result ); |
---|
1310 | } |
---|
1311 | maybe_accept( node, &OffsetofExpr::type ); |
---|
1312 | ) |
---|
1313 | |
---|
1314 | VISIT_END( Expr, node ); |
---|
1315 | } |
---|
1316 | |
---|
1317 | //-------------------------------------------------------------------------- |
---|
1318 | // OffsetPackExpr |
---|
1319 | template< typename core_t > |
---|
1320 | const ast::Expr * ast::Pass< core_t >::visit( const ast::OffsetPackExpr * node ) { |
---|
1321 | VISIT_START( node ); |
---|
1322 | |
---|
1323 | VISIT({ |
---|
1324 | guard_symtab guard { *this }; |
---|
1325 | maybe_accept( node, &OffsetPackExpr::result ); |
---|
1326 | } |
---|
1327 | maybe_accept( node, &OffsetPackExpr::type ); |
---|
1328 | ) |
---|
1329 | |
---|
1330 | VISIT_END( Expr, node ); |
---|
1331 | } |
---|
1332 | |
---|
1333 | //-------------------------------------------------------------------------- |
---|
1334 | // LogicalExpr |
---|
1335 | template< typename core_t > |
---|
1336 | const ast::Expr * ast::Pass< core_t >::visit( const ast::LogicalExpr * node ) { |
---|
1337 | VISIT_START( node ); |
---|
1338 | |
---|
1339 | VISIT({ |
---|
1340 | guard_symtab guard { *this }; |
---|
1341 | maybe_accept( node, &LogicalExpr::result ); |
---|
1342 | } |
---|
1343 | maybe_accept( node, &LogicalExpr::arg1 ); |
---|
1344 | maybe_accept( node, &LogicalExpr::arg2 ); |
---|
1345 | ) |
---|
1346 | |
---|
1347 | VISIT_END( Expr, node ); |
---|
1348 | } |
---|
1349 | |
---|
1350 | //-------------------------------------------------------------------------- |
---|
1351 | // ConditionalExpr |
---|
1352 | template< typename core_t > |
---|
1353 | const ast::Expr * ast::Pass< core_t >::visit( const ast::ConditionalExpr * node ) { |
---|
1354 | VISIT_START( node ); |
---|
1355 | |
---|
1356 | VISIT({ |
---|
1357 | guard_symtab guard { *this }; |
---|
1358 | maybe_accept( node, &ConditionalExpr::result ); |
---|
1359 | } |
---|
1360 | maybe_accept( node, &ConditionalExpr::arg1 ); |
---|
1361 | maybe_accept( node, &ConditionalExpr::arg2 ); |
---|
1362 | maybe_accept( node, &ConditionalExpr::arg3 ); |
---|
1363 | ) |
---|
1364 | |
---|
1365 | VISIT_END( Expr, node ); |
---|
1366 | } |
---|
1367 | |
---|
1368 | //-------------------------------------------------------------------------- |
---|
1369 | // CommaExpr |
---|
1370 | template< typename core_t > |
---|
1371 | const ast::Expr * ast::Pass< core_t >::visit( const ast::CommaExpr * node ) { |
---|
1372 | VISIT_START( node ); |
---|
1373 | |
---|
1374 | VISIT({ |
---|
1375 | guard_symtab guard { *this }; |
---|
1376 | maybe_accept( node, &CommaExpr::result ); |
---|
1377 | } |
---|
1378 | maybe_accept( node, &CommaExpr::arg1 ); |
---|
1379 | maybe_accept( node, &CommaExpr::arg2 ); |
---|
1380 | ) |
---|
1381 | |
---|
1382 | VISIT_END( Expr, node ); |
---|
1383 | } |
---|
1384 | |
---|
1385 | //-------------------------------------------------------------------------- |
---|
1386 | // TypeExpr |
---|
1387 | template< typename core_t > |
---|
1388 | const ast::Expr * ast::Pass< core_t >::visit( const ast::TypeExpr * node ) { |
---|
1389 | VISIT_START( node ); |
---|
1390 | |
---|
1391 | VISIT({ |
---|
1392 | guard_symtab guard { *this }; |
---|
1393 | maybe_accept( node, &TypeExpr::result ); |
---|
1394 | } |
---|
1395 | maybe_accept( node, &TypeExpr::type ); |
---|
1396 | ) |
---|
1397 | |
---|
1398 | VISIT_END( Expr, node ); |
---|
1399 | } |
---|
1400 | |
---|
1401 | //-------------------------------------------------------------------------- |
---|
1402 | // AsmExpr |
---|
1403 | template< typename core_t > |
---|
1404 | const ast::Expr * ast::Pass< core_t >::visit( const ast::AsmExpr * node ) { |
---|
1405 | VISIT_START( node ); |
---|
1406 | |
---|
1407 | VISIT({ |
---|
1408 | guard_symtab guard { *this }; |
---|
1409 | maybe_accept( node, &AsmExpr::result ); |
---|
1410 | } |
---|
1411 | maybe_accept( node, &AsmExpr::constraint ); |
---|
1412 | maybe_accept( node, &AsmExpr::operand ); |
---|
1413 | ) |
---|
1414 | |
---|
1415 | VISIT_END( Expr, node ); |
---|
1416 | } |
---|
1417 | |
---|
1418 | //-------------------------------------------------------------------------- |
---|
1419 | // ImplicitCopyCtorExpr |
---|
1420 | template< typename core_t > |
---|
1421 | const ast::Expr * ast::Pass< core_t >::visit( const ast::ImplicitCopyCtorExpr * node ) { |
---|
1422 | VISIT_START( node ); |
---|
1423 | |
---|
1424 | VISIT({ |
---|
1425 | guard_symtab guard { *this }; |
---|
1426 | maybe_accept( node, &ImplicitCopyCtorExpr::result ); |
---|
1427 | } |
---|
1428 | maybe_accept( node, &ImplicitCopyCtorExpr::callExpr ); |
---|
1429 | ) |
---|
1430 | |
---|
1431 | VISIT_END( Expr, node ); |
---|
1432 | } |
---|
1433 | |
---|
1434 | //-------------------------------------------------------------------------- |
---|
1435 | // ConstructorExpr |
---|
1436 | template< typename core_t > |
---|
1437 | const ast::Expr * ast::Pass< core_t >::visit( const ast::ConstructorExpr * node ) { |
---|
1438 | VISIT_START( node ); |
---|
1439 | |
---|
1440 | VISIT({ |
---|
1441 | guard_symtab guard { *this }; |
---|
1442 | maybe_accept( node, &ConstructorExpr::result ); |
---|
1443 | } |
---|
1444 | maybe_accept( node, &ConstructorExpr::callExpr ); |
---|
1445 | ) |
---|
1446 | |
---|
1447 | VISIT_END( Expr, node ); |
---|
1448 | } |
---|
1449 | |
---|
1450 | //-------------------------------------------------------------------------- |
---|
1451 | // CompoundLiteralExpr |
---|
1452 | template< typename core_t > |
---|
1453 | const ast::Expr * ast::Pass< core_t >::visit( const ast::CompoundLiteralExpr * node ) { |
---|
1454 | VISIT_START( node ); |
---|
1455 | |
---|
1456 | VISIT({ |
---|
1457 | guard_symtab guard { *this }; |
---|
1458 | maybe_accept( node, &CompoundLiteralExpr::result ); |
---|
1459 | } |
---|
1460 | maybe_accept( node, &CompoundLiteralExpr::init ); |
---|
1461 | ) |
---|
1462 | |
---|
1463 | VISIT_END( Expr, node ); |
---|
1464 | } |
---|
1465 | |
---|
1466 | //-------------------------------------------------------------------------- |
---|
1467 | // RangeExpr |
---|
1468 | template< typename core_t > |
---|
1469 | const ast::Expr * ast::Pass< core_t >::visit( const ast::RangeExpr * node ) { |
---|
1470 | VISIT_START( node ); |
---|
1471 | |
---|
1472 | VISIT({ |
---|
1473 | guard_symtab guard { *this }; |
---|
1474 | maybe_accept( node, &RangeExpr::result ); |
---|
1475 | } |
---|
1476 | maybe_accept( node, &RangeExpr::low ); |
---|
1477 | maybe_accept( node, &RangeExpr::high ); |
---|
1478 | ) |
---|
1479 | |
---|
1480 | VISIT_END( Expr, node ); |
---|
1481 | } |
---|
1482 | |
---|
1483 | //-------------------------------------------------------------------------- |
---|
1484 | // UntypedTupleExpr |
---|
1485 | template< typename core_t > |
---|
1486 | const ast::Expr * ast::Pass< core_t >::visit( const ast::UntypedTupleExpr * node ) { |
---|
1487 | VISIT_START( node ); |
---|
1488 | |
---|
1489 | VISIT({ |
---|
1490 | guard_symtab guard { *this }; |
---|
1491 | maybe_accept( node, &UntypedTupleExpr::result ); |
---|
1492 | } |
---|
1493 | maybe_accept( node, &UntypedTupleExpr::exprs ); |
---|
1494 | ) |
---|
1495 | |
---|
1496 | VISIT_END( Expr, node ); |
---|
1497 | } |
---|
1498 | |
---|
1499 | //-------------------------------------------------------------------------- |
---|
1500 | // TupleExpr |
---|
1501 | template< typename core_t > |
---|
1502 | const ast::Expr * ast::Pass< core_t >::visit( const ast::TupleExpr * node ) { |
---|
1503 | VISIT_START( node ); |
---|
1504 | |
---|
1505 | VISIT({ |
---|
1506 | guard_symtab guard { *this }; |
---|
1507 | maybe_accept( node, &TupleExpr::result ); |
---|
1508 | } |
---|
1509 | maybe_accept( node, &TupleExpr::exprs ); |
---|
1510 | ) |
---|
1511 | |
---|
1512 | VISIT_END( Expr, node ); |
---|
1513 | } |
---|
1514 | |
---|
1515 | //-------------------------------------------------------------------------- |
---|
1516 | // TupleIndexExpr |
---|
1517 | template< typename core_t > |
---|
1518 | const ast::Expr * ast::Pass< core_t >::visit( const ast::TupleIndexExpr * node ) { |
---|
1519 | VISIT_START( node ); |
---|
1520 | |
---|
1521 | VISIT({ |
---|
1522 | guard_symtab guard { *this }; |
---|
1523 | maybe_accept( node, &TupleIndexExpr::result ); |
---|
1524 | } |
---|
1525 | maybe_accept( node, &TupleIndexExpr::tuple ); |
---|
1526 | ) |
---|
1527 | |
---|
1528 | VISIT_END( Expr, node ); |
---|
1529 | } |
---|
1530 | |
---|
1531 | //-------------------------------------------------------------------------- |
---|
1532 | // TupleAssignExpr |
---|
1533 | template< typename core_t > |
---|
1534 | const ast::Expr * ast::Pass< core_t >::visit( const ast::TupleAssignExpr * node ) { |
---|
1535 | VISIT_START( node ); |
---|
1536 | |
---|
1537 | VISIT({ |
---|
1538 | guard_symtab guard { *this }; |
---|
1539 | maybe_accept( node, &TupleAssignExpr::result ); |
---|
1540 | } |
---|
1541 | maybe_accept( node, &TupleAssignExpr::stmtExpr ); |
---|
1542 | ) |
---|
1543 | |
---|
1544 | VISIT_END( Expr, node ); |
---|
1545 | } |
---|
1546 | |
---|
1547 | //-------------------------------------------------------------------------- |
---|
1548 | // StmtExpr |
---|
1549 | template< typename core_t > |
---|
1550 | const ast::Expr * ast::Pass< core_t >::visit( const ast::StmtExpr * node ) { |
---|
1551 | VISIT_START( node ); |
---|
1552 | |
---|
1553 | VISIT(// don't want statements from outer CompoundStmts to be added to this StmtExpr |
---|
1554 | // get the stmts that will need to be spliced in |
---|
1555 | auto stmts_before = __pass::stmtsToAddBefore( core, 0); |
---|
1556 | auto stmts_after = __pass::stmtsToAddAfter ( core, 0); |
---|
1557 | |
---|
1558 | // These may be modified by subnode but most be restored once we exit this statemnet. |
---|
1559 | ValueGuardPtr< const ast::TypeSubstitution * > __old_env( __pass::typeSubs( core, 0 ) ); |
---|
1560 | ValueGuardPtr< typename std::remove_pointer< decltype(stmts_before) >::type > __old_decls_before( stmts_before ); |
---|
1561 | ValueGuardPtr< typename std::remove_pointer< decltype(stmts_after ) >::type > __old_decls_after ( stmts_after ); |
---|
1562 | |
---|
1563 | { |
---|
1564 | guard_symtab guard { *this }; |
---|
1565 | maybe_accept( node, &StmtExpr::result ); |
---|
1566 | } |
---|
1567 | maybe_accept( node, &StmtExpr::stmts ); |
---|
1568 | maybe_accept( node, &StmtExpr::returnDecls ); |
---|
1569 | maybe_accept( node, &StmtExpr::dtors ); |
---|
1570 | ) |
---|
1571 | |
---|
1572 | VISIT_END( Expr, node ); |
---|
1573 | } |
---|
1574 | |
---|
1575 | //-------------------------------------------------------------------------- |
---|
1576 | // UniqueExpr |
---|
1577 | template< typename core_t > |
---|
1578 | const ast::Expr * ast::Pass< core_t >::visit( const ast::UniqueExpr * node ) { |
---|
1579 | VISIT_START( node ); |
---|
1580 | |
---|
1581 | VISIT({ |
---|
1582 | guard_symtab guard { *this }; |
---|
1583 | maybe_accept( node, &UniqueExpr::result ); |
---|
1584 | } |
---|
1585 | maybe_accept( node, &UniqueExpr::expr ); |
---|
1586 | ) |
---|
1587 | |
---|
1588 | VISIT_END( Expr, node ); |
---|
1589 | } |
---|
1590 | |
---|
1591 | //-------------------------------------------------------------------------- |
---|
1592 | // UntypedInitExpr |
---|
1593 | template< typename core_t > |
---|
1594 | const ast::Expr * ast::Pass< core_t >::visit( const ast::UntypedInitExpr * node ) { |
---|
1595 | VISIT_START( node ); |
---|
1596 | |
---|
1597 | VISIT({ |
---|
1598 | guard_symtab guard { *this }; |
---|
1599 | maybe_accept( node, &UntypedInitExpr::result ); |
---|
1600 | } |
---|
1601 | maybe_accept( node, &UntypedInitExpr::expr ); |
---|
1602 | // not currently visiting initAlts, but this doesn't matter since this node is only used in the resolver. |
---|
1603 | ) |
---|
1604 | |
---|
1605 | VISIT_END( Expr, node ); |
---|
1606 | } |
---|
1607 | |
---|
1608 | //-------------------------------------------------------------------------- |
---|
1609 | // InitExpr |
---|
1610 | template< typename core_t > |
---|
1611 | const ast::Expr * ast::Pass< core_t >::visit( const ast::InitExpr * node ) { |
---|
1612 | VISIT_START( node ); |
---|
1613 | |
---|
1614 | VISIT({ |
---|
1615 | guard_symtab guard { *this }; |
---|
1616 | maybe_accept( node, &InitExpr::result ); |
---|
1617 | } |
---|
1618 | maybe_accept( node, &InitExpr::expr ); |
---|
1619 | maybe_accept( node, &InitExpr::designation ); |
---|
1620 | ) |
---|
1621 | |
---|
1622 | VISIT_END( Expr, node ); |
---|
1623 | } |
---|
1624 | |
---|
1625 | //-------------------------------------------------------------------------- |
---|
1626 | // DeletedExpr |
---|
1627 | template< typename core_t > |
---|
1628 | const ast::Expr * ast::Pass< core_t >::visit( const ast::DeletedExpr * node ) { |
---|
1629 | VISIT_START( node ); |
---|
1630 | |
---|
1631 | VISIT({ |
---|
1632 | guard_symtab guard { *this }; |
---|
1633 | maybe_accept( node, &DeletedExpr::result ); |
---|
1634 | } |
---|
1635 | maybe_accept( node, &DeletedExpr::expr ); |
---|
1636 | // don't visit deleteStmt, because it is a pointer to somewhere else in the tree. |
---|
1637 | ) |
---|
1638 | |
---|
1639 | VISIT_END( Expr, node ); |
---|
1640 | } |
---|
1641 | |
---|
1642 | //-------------------------------------------------------------------------- |
---|
1643 | // DefaultArgExpr |
---|
1644 | template< typename core_t > |
---|
1645 | const ast::Expr * ast::Pass< core_t >::visit( const ast::DefaultArgExpr * node ) { |
---|
1646 | VISIT_START( node ); |
---|
1647 | |
---|
1648 | VISIT({ |
---|
1649 | guard_symtab guard { *this }; |
---|
1650 | maybe_accept( node, &DefaultArgExpr::result ); |
---|
1651 | } |
---|
1652 | maybe_accept( node, &DefaultArgExpr::expr ); |
---|
1653 | ) |
---|
1654 | |
---|
1655 | VISIT_END( Expr, node ); |
---|
1656 | } |
---|
1657 | |
---|
1658 | //-------------------------------------------------------------------------- |
---|
1659 | // GenericExpr |
---|
1660 | template< typename core_t > |
---|
1661 | const ast::Expr * ast::Pass< core_t >::visit( const ast::GenericExpr * node ) { |
---|
1662 | VISIT_START( node ); |
---|
1663 | |
---|
1664 | VISIT({ |
---|
1665 | guard_symtab guard { *this }; |
---|
1666 | maybe_accept( node, &GenericExpr::result ); |
---|
1667 | } |
---|
1668 | maybe_accept( node, &GenericExpr::control ); |
---|
1669 | |
---|
1670 | std::vector<GenericExpr::Association> new_kids; |
---|
1671 | new_kids.reserve(node->associations.size()); |
---|
1672 | bool mutated = false; |
---|
1673 | for( const auto & assoc : node->associations ) { |
---|
1674 | const Type * type = nullptr; |
---|
1675 | if( assoc.type ) { |
---|
1676 | guard_symtab guard { *this }; |
---|
1677 | type = assoc.type->accept( *this ); |
---|
1678 | if( type != assoc.type ) mutated = true; |
---|
1679 | } |
---|
1680 | const Expr * expr = nullptr; |
---|
1681 | if( assoc.expr ) { |
---|
1682 | expr = assoc.expr->accept( *this ); |
---|
1683 | if( expr != assoc.expr ) mutated = true; |
---|
1684 | } |
---|
1685 | new_kids.emplace_back( type, expr ); |
---|
1686 | } |
---|
1687 | |
---|
1688 | if(mutated) { |
---|
1689 | auto n = __pass::mutate<core_t>(node); |
---|
1690 | n->associations = std::move( new_kids ); |
---|
1691 | node = n; |
---|
1692 | } |
---|
1693 | ) |
---|
1694 | |
---|
1695 | VISIT_END( Expr, node ); |
---|
1696 | } |
---|
1697 | |
---|
1698 | //-------------------------------------------------------------------------- |
---|
1699 | // VoidType |
---|
1700 | template< typename core_t > |
---|
1701 | const ast::Type * ast::Pass< core_t >::visit( const ast::VoidType * node ) { |
---|
1702 | VISIT_START( node ); |
---|
1703 | |
---|
1704 | VISIT_END( Type, node ); |
---|
1705 | } |
---|
1706 | |
---|
1707 | //-------------------------------------------------------------------------- |
---|
1708 | // BasicType |
---|
1709 | template< typename core_t > |
---|
1710 | const ast::Type * ast::Pass< core_t >::visit( const ast::BasicType * node ) { |
---|
1711 | VISIT_START( node ); |
---|
1712 | |
---|
1713 | VISIT_END( Type, node ); |
---|
1714 | } |
---|
1715 | |
---|
1716 | //-------------------------------------------------------------------------- |
---|
1717 | // PointerType |
---|
1718 | template< typename core_t > |
---|
1719 | const ast::Type * ast::Pass< core_t >::visit( const ast::PointerType * node ) { |
---|
1720 | VISIT_START( node ); |
---|
1721 | |
---|
1722 | VISIT( |
---|
1723 | // xxx - should PointerType visit/mutate dimension? |
---|
1724 | maybe_accept( node, &PointerType::base ); |
---|
1725 | ) |
---|
1726 | |
---|
1727 | VISIT_END( Type, node ); |
---|
1728 | } |
---|
1729 | |
---|
1730 | //-------------------------------------------------------------------------- |
---|
1731 | // ArrayType |
---|
1732 | template< typename core_t > |
---|
1733 | const ast::Type * ast::Pass< core_t >::visit( const ast::ArrayType * node ) { |
---|
1734 | VISIT_START( node ); |
---|
1735 | |
---|
1736 | VISIT( |
---|
1737 | maybe_accept( node, &ArrayType::dimension ); |
---|
1738 | maybe_accept( node, &ArrayType::base ); |
---|
1739 | ) |
---|
1740 | |
---|
1741 | VISIT_END( Type, node ); |
---|
1742 | } |
---|
1743 | |
---|
1744 | //-------------------------------------------------------------------------- |
---|
1745 | // ReferenceType |
---|
1746 | template< typename core_t > |
---|
1747 | const ast::Type * ast::Pass< core_t >::visit( const ast::ReferenceType * node ) { |
---|
1748 | VISIT_START( node ); |
---|
1749 | |
---|
1750 | VISIT( |
---|
1751 | maybe_accept( node, &ReferenceType::base ); |
---|
1752 | ) |
---|
1753 | |
---|
1754 | VISIT_END( Type, node ); |
---|
1755 | } |
---|
1756 | |
---|
1757 | //-------------------------------------------------------------------------- |
---|
1758 | // QualifiedType |
---|
1759 | template< typename core_t > |
---|
1760 | const ast::Type * ast::Pass< core_t >::visit( const ast::QualifiedType * node ) { |
---|
1761 | VISIT_START( node ); |
---|
1762 | |
---|
1763 | VISIT( |
---|
1764 | maybe_accept( node, &QualifiedType::parent ); |
---|
1765 | maybe_accept( node, &QualifiedType::child ); |
---|
1766 | ) |
---|
1767 | |
---|
1768 | VISIT_END( Type, node ); |
---|
1769 | } |
---|
1770 | |
---|
1771 | //-------------------------------------------------------------------------- |
---|
1772 | // FunctionType |
---|
1773 | template< typename core_t > |
---|
1774 | const ast::Type * ast::Pass< core_t >::visit( const ast::FunctionType * node ) { |
---|
1775 | VISIT_START( node ); |
---|
1776 | |
---|
1777 | VISIT({ |
---|
1778 | // guard_forall_subs forall_guard { *this, node }; |
---|
1779 | // mutate_forall( node ); |
---|
1780 | maybe_accept( node, &FunctionType::assertions ); |
---|
1781 | maybe_accept( node, &FunctionType::returns ); |
---|
1782 | maybe_accept( node, &FunctionType::params ); |
---|
1783 | }) |
---|
1784 | |
---|
1785 | VISIT_END( Type, node ); |
---|
1786 | } |
---|
1787 | |
---|
1788 | //-------------------------------------------------------------------------- |
---|
1789 | // StructInstType |
---|
1790 | template< typename core_t > |
---|
1791 | const ast::Type * ast::Pass< core_t >::visit( const ast::StructInstType * node ) { |
---|
1792 | VISIT_START( node ); |
---|
1793 | |
---|
1794 | __pass::symtab::addStruct( core, 0, node->name ); |
---|
1795 | |
---|
1796 | VISIT({ |
---|
1797 | guard_symtab guard { *this }; |
---|
1798 | maybe_accept( node, &StructInstType::params ); |
---|
1799 | }) |
---|
1800 | |
---|
1801 | VISIT_END( Type, node ); |
---|
1802 | } |
---|
1803 | |
---|
1804 | //-------------------------------------------------------------------------- |
---|
1805 | // UnionInstType |
---|
1806 | template< typename core_t > |
---|
1807 | const ast::Type * ast::Pass< core_t >::visit( const ast::UnionInstType * node ) { |
---|
1808 | VISIT_START( node ); |
---|
1809 | |
---|
1810 | __pass::symtab::addUnion( core, 0, node->name ); |
---|
1811 | |
---|
1812 | VISIT({ |
---|
1813 | guard_symtab guard { *this }; |
---|
1814 | maybe_accept( node, &UnionInstType::params ); |
---|
1815 | }) |
---|
1816 | |
---|
1817 | VISIT_END( Type, node ); |
---|
1818 | } |
---|
1819 | |
---|
1820 | //-------------------------------------------------------------------------- |
---|
1821 | // EnumInstType |
---|
1822 | template< typename core_t > |
---|
1823 | const ast::Type * ast::Pass< core_t >::visit( const ast::EnumInstType * node ) { |
---|
1824 | VISIT_START( node ); |
---|
1825 | |
---|
1826 | VISIT({ |
---|
1827 | maybe_accept( node, &EnumInstType::params ); |
---|
1828 | }) |
---|
1829 | |
---|
1830 | VISIT_END( Type, node ); |
---|
1831 | } |
---|
1832 | |
---|
1833 | //-------------------------------------------------------------------------- |
---|
1834 | // TraitInstType |
---|
1835 | template< typename core_t > |
---|
1836 | const ast::Type * ast::Pass< core_t >::visit( const ast::TraitInstType * node ) { |
---|
1837 | VISIT_START( node ); |
---|
1838 | |
---|
1839 | VISIT({ |
---|
1840 | maybe_accept( node, &TraitInstType::params ); |
---|
1841 | }) |
---|
1842 | |
---|
1843 | VISIT_END( Type, node ); |
---|
1844 | } |
---|
1845 | |
---|
1846 | //-------------------------------------------------------------------------- |
---|
1847 | // TypeInstType |
---|
1848 | template< typename core_t > |
---|
1849 | const ast::Type * ast::Pass< core_t >::visit( const ast::TypeInstType * node ) { |
---|
1850 | VISIT_START( node ); |
---|
1851 | |
---|
1852 | VISIT( |
---|
1853 | { |
---|
1854 | maybe_accept( node, &TypeInstType::params ); |
---|
1855 | } |
---|
1856 | // ensure that base re-bound if doing substitution |
---|
1857 | __pass::forall::replace( core, 0, node ); |
---|
1858 | ) |
---|
1859 | |
---|
1860 | VISIT_END( Type, node ); |
---|
1861 | } |
---|
1862 | |
---|
1863 | //-------------------------------------------------------------------------- |
---|
1864 | // TupleType |
---|
1865 | template< typename core_t > |
---|
1866 | const ast::Type * ast::Pass< core_t >::visit( const ast::TupleType * node ) { |
---|
1867 | VISIT_START( node ); |
---|
1868 | |
---|
1869 | VISIT( |
---|
1870 | maybe_accept( node, &TupleType::types ); |
---|
1871 | maybe_accept( node, &TupleType::members ); |
---|
1872 | ) |
---|
1873 | |
---|
1874 | VISIT_END( Type, node ); |
---|
1875 | } |
---|
1876 | |
---|
1877 | //-------------------------------------------------------------------------- |
---|
1878 | // TypeofType |
---|
1879 | template< typename core_t > |
---|
1880 | const ast::Type * ast::Pass< core_t >::visit( const ast::TypeofType * node ) { |
---|
1881 | VISIT_START( node ); |
---|
1882 | |
---|
1883 | VISIT( |
---|
1884 | maybe_accept( node, &TypeofType::expr ); |
---|
1885 | ) |
---|
1886 | |
---|
1887 | VISIT_END( Type, node ); |
---|
1888 | } |
---|
1889 | |
---|
1890 | //-------------------------------------------------------------------------- |
---|
1891 | // VTableType |
---|
1892 | template< typename core_t > |
---|
1893 | const ast::Type * ast::Pass< core_t >::visit( const ast::VTableType * node ) { |
---|
1894 | VISIT_START( node ); |
---|
1895 | |
---|
1896 | VISIT( |
---|
1897 | maybe_accept( node, &VTableType::base ); |
---|
1898 | ) |
---|
1899 | |
---|
1900 | VISIT_END( Type, node ); |
---|
1901 | } |
---|
1902 | |
---|
1903 | //-------------------------------------------------------------------------- |
---|
1904 | // VarArgsType |
---|
1905 | template< typename core_t > |
---|
1906 | const ast::Type * ast::Pass< core_t >::visit( const ast::VarArgsType * node ) { |
---|
1907 | VISIT_START( node ); |
---|
1908 | |
---|
1909 | VISIT_END( Type, node ); |
---|
1910 | } |
---|
1911 | |
---|
1912 | //-------------------------------------------------------------------------- |
---|
1913 | // ZeroType |
---|
1914 | template< typename core_t > |
---|
1915 | const ast::Type * ast::Pass< core_t >::visit( const ast::ZeroType * node ) { |
---|
1916 | VISIT_START( node ); |
---|
1917 | |
---|
1918 | VISIT_END( Type, node ); |
---|
1919 | } |
---|
1920 | |
---|
1921 | //-------------------------------------------------------------------------- |
---|
1922 | // OneType |
---|
1923 | template< typename core_t > |
---|
1924 | const ast::Type * ast::Pass< core_t >::visit( const ast::OneType * node ) { |
---|
1925 | VISIT_START( node ); |
---|
1926 | |
---|
1927 | VISIT_END( Type, node ); |
---|
1928 | } |
---|
1929 | |
---|
1930 | //-------------------------------------------------------------------------- |
---|
1931 | // GlobalScopeType |
---|
1932 | template< typename core_t > |
---|
1933 | const ast::Type * ast::Pass< core_t >::visit( const ast::GlobalScopeType * node ) { |
---|
1934 | VISIT_START( node ); |
---|
1935 | |
---|
1936 | VISIT_END( Type, node ); |
---|
1937 | } |
---|
1938 | |
---|
1939 | |
---|
1940 | //-------------------------------------------------------------------------- |
---|
1941 | // Designation |
---|
1942 | template< typename core_t > |
---|
1943 | const ast::Designation * ast::Pass< core_t >::visit( const ast::Designation * node ) { |
---|
1944 | VISIT_START( node ); |
---|
1945 | |
---|
1946 | VISIT( maybe_accept( node, &Designation::designators ); ) |
---|
1947 | |
---|
1948 | VISIT_END( Designation, node ); |
---|
1949 | } |
---|
1950 | |
---|
1951 | //-------------------------------------------------------------------------- |
---|
1952 | // SingleInit |
---|
1953 | template< typename core_t > |
---|
1954 | const ast::Init * ast::Pass< core_t >::visit( const ast::SingleInit * node ) { |
---|
1955 | VISIT_START( node ); |
---|
1956 | |
---|
1957 | VISIT( |
---|
1958 | maybe_accept( node, &SingleInit::value ); |
---|
1959 | ) |
---|
1960 | |
---|
1961 | VISIT_END( Init, node ); |
---|
1962 | } |
---|
1963 | |
---|
1964 | //-------------------------------------------------------------------------- |
---|
1965 | // ListInit |
---|
1966 | template< typename core_t > |
---|
1967 | const ast::Init * ast::Pass< core_t >::visit( const ast::ListInit * node ) { |
---|
1968 | VISIT_START( node ); |
---|
1969 | |
---|
1970 | VISIT( |
---|
1971 | maybe_accept( node, &ListInit::designations ); |
---|
1972 | maybe_accept( node, &ListInit::initializers ); |
---|
1973 | ) |
---|
1974 | |
---|
1975 | VISIT_END( Init, node ); |
---|
1976 | } |
---|
1977 | |
---|
1978 | //-------------------------------------------------------------------------- |
---|
1979 | // ConstructorInit |
---|
1980 | template< typename core_t > |
---|
1981 | const ast::Init * ast::Pass< core_t >::visit( const ast::ConstructorInit * node ) { |
---|
1982 | VISIT_START( node ); |
---|
1983 | |
---|
1984 | VISIT( |
---|
1985 | maybe_accept( node, &ConstructorInit::ctor ); |
---|
1986 | maybe_accept( node, &ConstructorInit::dtor ); |
---|
1987 | maybe_accept( node, &ConstructorInit::init ); |
---|
1988 | ) |
---|
1989 | |
---|
1990 | VISIT_END( Init, node ); |
---|
1991 | } |
---|
1992 | |
---|
1993 | //-------------------------------------------------------------------------- |
---|
1994 | // Attribute |
---|
1995 | template< typename core_t > |
---|
1996 | const ast::Attribute * ast::Pass< core_t >::visit( const ast::Attribute * node ) { |
---|
1997 | VISIT_START( node ); |
---|
1998 | |
---|
1999 | VISIT( |
---|
2000 | maybe_accept( node, &Attribute::params ); |
---|
2001 | ) |
---|
2002 | |
---|
2003 | VISIT_END( Attribute, node ); |
---|
2004 | } |
---|
2005 | |
---|
2006 | //-------------------------------------------------------------------------- |
---|
2007 | // TypeSubstitution |
---|
2008 | template< typename core_t > |
---|
2009 | const ast::TypeSubstitution * ast::Pass< core_t >::visit( const ast::TypeSubstitution * node ) { |
---|
2010 | VISIT_START( node ); |
---|
2011 | |
---|
2012 | VISIT( |
---|
2013 | { |
---|
2014 | bool mutated = false; |
---|
2015 | std::unordered_map< ast::TypeInstType::TypeEnvKey, ast::ptr< ast::Type > > new_map; |
---|
2016 | for ( const auto & p : node->typeEnv ) { |
---|
2017 | guard_symtab guard { *this }; |
---|
2018 | auto new_node = p.second->accept( *this ); |
---|
2019 | if (new_node != p.second) mutated = true; |
---|
2020 | new_map.insert({ p.first, new_node }); |
---|
2021 | } |
---|
2022 | if (mutated) { |
---|
2023 | auto new_node = __pass::mutate<core_t>( node ); |
---|
2024 | new_node->typeEnv.swap( new_map ); |
---|
2025 | node = new_node; |
---|
2026 | } |
---|
2027 | } |
---|
2028 | ) |
---|
2029 | |
---|
2030 | VISIT_END( TypeSubstitution, node ); |
---|
2031 | } |
---|
2032 | |
---|
2033 | #undef VISIT_START |
---|
2034 | #undef VISIT |
---|
2035 | #undef VISIT_END |
---|