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