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