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