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