Changes in / [8fd1b7c:fece3d9]


Ignore:
Location:
src/AST
Files:
2 edited

Legend:

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

    r8fd1b7c rfece3d9  
    2222#include "AST/TranslationUnit.hpp"
    2323#include "AST/TypeSubstitution.hpp"
     24#include "Common/Iterate.hpp"
    2425
    2526#define VISIT_START( node ) \
     
    126127        }
    127128
     129        template< typename node_t >
     130        template< typename object_t, typename super_t, typename field_t >
     131        void __pass::result1< node_t >::apply( object_t * object, field_t super_t::* field ) {
     132                object->*field = value;
     133        }
     134
    128135        template< typename core_t >
    129136        template< typename node_t >
     
    227234
    228235                return {true, compound};
     236        }
     237
     238        template< template <class...> class container_t >
     239        template< typename object_t, typename super_t, typename field_t >
     240        void __pass::resultNstmt<container_t>::apply(object_t * object, field_t super_t::* field) {
     241                auto & container = object->*field;
     242                __pedantic_pass_assert( container.size() <= values.size() );
     243
     244                auto cit = enumerate(container).begin();
     245
     246                container_t<ptr<Stmt>> nvals;
     247                for (delta & d : values) {
     248                        if ( d.is_old ) {
     249                                __pedantic_pass_assert( cit.idx <= d.old_idx );
     250                                std::advance( cit, d.old_idx - cit.idx );
     251                                nvals.push_back( std::move( (*cit).val) );
     252                        } else {
     253                                nvals.push_back( std::move(d.new_val) );
     254                        }
     255                }
     256
     257                container = std::move(nvals);
     258        }
     259
     260        template< template <class...> class container_t >
     261        template< template <class...> class incontainer_t >
     262        void __pass::resultNstmt< container_t >::take_all( incontainer_t<ptr<Stmt>> * stmts ) {
     263                if (!stmts || stmts->empty()) return;
     264
     265                std::transform(stmts->begin(), stmts->end(), std::back_inserter( values ),
     266                        [](ast::ptr<ast::Stmt>& stmt) -> delta {
     267                                return delta( stmt.release(), -1, false );
     268                        });
     269                stmts->clear();
     270                differs = true;
     271        }
     272
     273        template< template<class...> class container_t >
     274        template< template<class...> class incontainer_t >
     275        void __pass::resultNstmt< container_t >::take_all( incontainer_t<ptr<Decl>> * decls ) {
     276                if (!decls || decls->empty()) return;
     277
     278                std::transform(decls->begin(), decls->end(), std::back_inserter( values ),
     279                        [](ast::ptr<ast::Decl>& decl) -> delta {
     280                                auto loc = decl->location;
     281                                auto stmt = new DeclStmt( loc, decl.release() );
     282                                return delta( stmt, -1, false );
     283                        });
     284                decls->clear();
     285                differs = true;
    229286        }
    230287
     
    296353
    297354                return new_kids;
     355        }
     356
     357        template< template <class...> class container_t, typename node_t >
     358        template< typename object_t, typename super_t, typename field_t >
     359        void __pass::resultN<container_t, node_t>::apply(object_t * object, field_t super_t::* field) {
     360                auto & container = object->*field;
     361                __pedantic_pass_assert( container.size() == values.size() );
     362
     363                for(size_t i = 0; i < container.size(); i++) {
     364                        // Take all the elements that are different in 'values'
     365                        // and swap them into 'container'
     366                        if( values[i] != nullptr ) swap(container[i], values[i]);
     367                }
     368
     369                // Now the original containers should still have the unchanged values
     370                // but also contain the new values
    298371        }
    299372
     
    21632236}
    21642237
    2165 #undef __pedantic_pass_assertf
    2166 #undef __pedantic_pass_assert
    21672238#undef VISIT_START
    21682239#undef VISIT_END
  • src/AST/Pass.proto.hpp

    r8fd1b7c rfece3d9  
    1717// IWYU pragma: private, include "Pass.hpp"
    1818
    19 #include "Common/Iterate.hpp"
    2019#include "Common/Stats/Heap.h"
    2120namespace ast {
     
    2524        template<typename node_t> node_t * deepCopy( const node_t * );
    2625}
    27 
    28 #ifdef PEDANTIC_PASS_ASSERT
    29 #define __pedantic_pass_assert(...) assert (__VA_ARGS__)
    30 #define __pedantic_pass_assertf(...) assertf(__VA_ARGS__)
    31 #else
    32 #define __pedantic_pass_assert(...)
    33 #define __pedantic_pass_assertf(...)
    34 #endif
    3526
    3627namespace ast::__pass {
     
    139130
    140131        template< typename object_t, typename super_t, typename field_t >
    141         void apply( object_t * object, field_t super_t::* field ) {
    142                 object->*field = value;
    143         }
     132        void apply( object_t *, field_t super_t::* field );
    144133};
    145134
     
    161150
    162151        template< typename object_t, typename super_t, typename field_t >
    163         void apply( object_t * object, field_t super_t::* field ) {
    164                 field_t & container = object->*field;
    165                 __pedantic_pass_assert( container.size() <= values.size() );
    166 
    167                 auto cit = enumerate(container).begin();
    168 
    169                 container_t<ptr<Stmt>> nvals;
    170                 for ( delta & d : values ) {
    171                         if ( d.is_old ) {
    172                                 __pedantic_pass_assert( cit.idx <= d.old_idx );
    173                                 std::advance( cit, d.old_idx - cit.idx );
    174                                 nvals.push_back( std::move( (*cit).val ) );
    175                         } else {
    176                                 nvals.push_back( std::move( d.new_val ) );
    177                         }
    178                 }
    179 
    180                 container = std::move(nvals);
    181         }
     152        void apply( object_t *, field_t super_t::* field );
    182153
    183154        template< template<class...> class incontainer_t >
    184         void take_all( incontainer_t<ptr<Stmt>> * stmts ) {
    185                 if ( !stmts || stmts->empty() ) return;
    186 
    187                 std::transform( stmts->begin(), stmts->end(), std::back_inserter( values ),
    188                         [](ast::ptr<ast::Stmt>& stmt) -> delta {
    189                                 return delta( stmt.release(), -1, false );
    190                         });
    191                 stmts->clear();
    192                 differs = true;
    193         }
     155        void take_all( incontainer_t<ptr<Stmt>> * stmts );
    194156
    195157        template< template<class...> class incontainer_t >
    196         void take_all( incontainer_t<ptr<Decl>> * decls ) {
    197                 if ( !decls || decls->empty() ) return;
    198 
    199                 std::transform( decls->begin(), decls->end(), std::back_inserter( values ),
    200                         [](ast::ptr<ast::Decl>& decl) -> delta {
    201                                 ast::Decl const * d = decl.release();
    202                                 return delta( new DeclStmt( d->location, d ), -1, false );
    203                         });
    204                 decls->clear();
    205                 differs = true;
    206         }
     158        void take_all( incontainer_t<ptr<Decl>> * decls );
    207159};
    208160
     
    214166
    215167        template< typename object_t, typename super_t, typename field_t >
    216         void apply( object_t * object, field_t super_t::* field ) {
    217                 field_t & container = object->*field;
    218                 __pedantic_pass_assert( container.size() == values.size() );
    219 
    220                 for ( size_t i = 0; i < container.size(); ++i ) {
    221                         // Take all the elements that are different in 'values'
    222                         // and swap them into 'container'
    223                         if ( values[i] != nullptr ) swap(container[i], values[i]);
    224                 }
    225                 // Now the original containers should still have the unchanged values
    226                 // but also contain the new values.
    227         }
     168        void apply( object_t *, field_t super_t::* field );
    228169};
    229170
     
    576517
    577518} // namespace ast::__pass
    578 
    579 #undef __pedantic_pass_assertf
    580 #undef __pedantic_pass_assert
Note: See TracChangeset for help on using the changeset viewer.