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