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