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