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