Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/AST/Pass.impl.hpp

    reb211bf rf8143a6  
    111111                }
    112112
     113
    113114                //------------------------------
    114115                /// Check if value was mutated, different for pointers and containers
     
    124125        }
    125126
     127
     128        template< typename core_t >
    126129        template< typename node_t >
    127130        template< typename object_t, typename super_t, typename field_t >
    128         void __pass::result1< node_t >::apply( object_t * object, field_t super_t::* field ) {
     131        void ast::Pass< core_t >::result1< node_t >::apply(object_t * object, field_t super_t::* field) {
    129132                object->*field = value;
    130133        }
     
    133136        template< typename node_t >
    134137        auto ast::Pass< core_t >::call_accept( const node_t * node )
    135                 -> typename ast::Pass< core_t >::template generic_call_accept_result<node_t>::type
     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
     141                        , ast::Pass< core_t >::result1<
     142                                typename std::remove_pointer< decltype( node->accept(*this) ) >::type
     143                        >
     144                >::type
    136145        {
    137146                __pedantic_pass_assert( __visit_children() );
     
    142151
    143152                auto nval = node->accept( *this );
    144                 __pass::result1<
     153                ast::Pass< core_t >::result1<
    145154                        typename std::remove_pointer< decltype( node->accept(*this) ) >::type
    146155                > res;
     
    151160
    152161        template< typename core_t >
    153         __pass::template result1<ast::Expr> ast::Pass< core_t >::call_accept( const ast::Expr * expr ) {
     162        ast::Pass< core_t >::result1<ast::Expr> ast::Pass< core_t >::call_accept( const ast::Expr * expr ) {
    154163                __pedantic_pass_assert( __visit_children() );
    155164                __pedantic_pass_assert( expr );
     
    165174
    166175        template< typename core_t >
    167         __pass::template result1<ast::Stmt> ast::Pass< core_t >::call_accept( const ast::Stmt * stmt ) {
     176        ast::Pass< core_t >::result1<ast::Stmt> ast::Pass< core_t >::call_accept( const ast::Stmt * stmt ) {
    168177                __pedantic_pass_assert( __visit_children() );
    169178                __pedantic_pass_assert( stmt );
     
    174183
    175184        template< typename core_t >
    176         __pass::template result1<ast::Stmt> ast::Pass< core_t >::call_accept_as_compound( const ast::Stmt * stmt ) {
     185        ast::Pass< core_t >::result1<ast::Stmt> ast::Pass< core_t >::call_accept_as_compound( const ast::Stmt * stmt ) {
    177186                __pedantic_pass_assert( __visit_children() );
    178187                __pedantic_pass_assert( stmt );
     
    224233        }
    225234
     235        template< typename core_t >
    226236        template< template <class...> class container_t >
    227237        template< typename object_t, typename super_t, typename field_t >
    228         void __pass::resultNstmt<container_t>::apply(object_t * object, field_t super_t::* field) {
     238        void ast::Pass< core_t >::resultNstmt<container_t>::apply(object_t * object, field_t super_t::* field) {
    229239                auto & container = object->*field;
    230240                __pedantic_pass_assert( container.size() <= values.size() );
     
    233243
    234244                container_t<ptr<Stmt>> nvals;
    235                 for (delta & d : values) {
    236                         if ( d.is_old ) {
     245                for(delta & d : values) {
     246                        if( d.is_old ) {
    237247                                __pedantic_pass_assert( cit.idx <= d.old_idx );
    238248                                std::advance( cit, d.old_idx - cit.idx );
    239249                                nvals.push_back( std::move( (*cit).val) );
    240250                        } else {
    241                                 nvals.push_back( std::move(d.new_val) );
     251                                nvals.push_back( std::move(d.nval) );
    242252                        }
    243253                }
    244254
    245                 container = std::move(nvals);
    246         }
    247 
    248         template< template <class...> class container_t >
    249         template< template <class...> class incontainer_t >
    250         void __pass::resultNstmt< container_t >::take_all( incontainer_t<ptr<Stmt>> * stmts ) {
    251                 if (!stmts || stmts->empty()) return;
    252 
    253                 std::transform(stmts->begin(), stmts->end(), std::back_inserter( values ),
    254                         [](ast::ptr<ast::Stmt>& stmt) -> delta {
    255                                 return delta( stmt.release(), -1, false );
    256                         });
    257                 stmts->clear();
    258                 differs = true;
    259         }
    260 
    261         template< template<class...> class container_t >
    262         template< template<class...> class incontainer_t >
    263         void __pass::resultNstmt< container_t >::take_all( incontainer_t<ptr<Decl>> * decls ) {
    264                 if (!decls || decls->empty()) return;
    265 
    266                 std::transform(decls->begin(), decls->end(), std::back_inserter( values ),
    267                         [](ast::ptr<ast::Decl>& decl) -> delta {
    268                                 auto loc = decl->location;
    269                                 auto stmt = new DeclStmt( loc, decl.release() );
    270                                 return delta( stmt, -1, false );
    271                         });
    272                 decls->clear();
    273                 differs = true;
     255                object->*field = std::move(nvals);
    274256        }
    275257
    276258        template< typename core_t >
    277259        template< template <class...> class container_t >
    278         __pass::template resultNstmt<container_t> ast::Pass< core_t >::call_accept( const container_t< ptr<Stmt> > & statements ) {
     260        ast::Pass< core_t >::resultNstmt<container_t> ast::Pass< core_t >::call_accept( const container_t< ptr<Stmt> > & statements ) {
    279261                __pedantic_pass_assert( __visit_children() );
    280262                if( statements.empty() ) return {};
     
    303285                pass_visitor_stats.avg->push(pass_visitor_stats.depth);
    304286
    305                 __pass::resultNstmt<container_t> new_kids;
     287                resultNstmt<container_t> new_kids;
    306288                for( auto value : enumerate( statements ) ) {
    307289                        try {
     
    345327        }
    346328
     329        template< typename core_t >
    347330        template< template <class...> class container_t, typename node_t >
    348331        template< typename object_t, typename super_t, typename field_t >
    349         void __pass::resultN<container_t, node_t>::apply(object_t * object, field_t super_t::* field) {
     332        void ast::Pass< core_t >::resultN<container_t, node_t>::apply(object_t * object, field_t super_t::* field) {
    350333                auto & container = object->*field;
    351334                __pedantic_pass_assert( container.size() == values.size() );
     
    363346        template< typename core_t >
    364347        template< template <class...> class container_t, typename node_t >
    365         __pass::template resultN<container_t, node_t> ast::Pass< core_t >::call_accept( const container_t< ast::ptr<node_t> > & container ) {
     348        ast::Pass< core_t >::resultN<container_t, node_t> ast::Pass< core_t >::call_accept( const container_t< ast::ptr<node_t> > & container ) {
    366349                __pedantic_pass_assert( __visit_children() );
    367350                if( container.empty() ) return {};
     
    395378                if ( ! errors.isEmpty() ) { throw errors; }
    396379
    397                 return ast::__pass::resultN<container_t, node_t>{ mutated, new_kids };
     380                return ast::Pass< core_t >::resultN<container_t, node_t>{ mutated, new_kids };
    398381        }
    399382
Note: See TracChangeset for help on using the changeset viewer.