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