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