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