Ignore:
Timestamp:
Jun 12, 2023, 2:45:32 PM (2 years ago)
Author:
Fangren Yu <f37yu@…>
Branches:
ast-experimental, master
Children:
62d62db
Parents:
34b4268 (diff), 251ce80 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge branch 'master' into ast-experimental

File:
1 edited

Legend:

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

    r34b4268 r24d6572  
    2020#include <unordered_map>
    2121
     22#include "AST/Copy.hpp"
    2223#include "AST/TranslationUnit.hpp"
    2324#include "AST/TypeSubstitution.hpp"
     
    4546
    4647#ifdef PEDANTIC_PASS_ASSERT
    47 #define __pedantic_pass_assert(...) assert (__VA_ARGS__)
     48#define __pedantic_pass_assert(...) assert(__VA_ARGS__)
    4849#define __pedantic_pass_assertf(...) assertf(__VA_ARGS__)
    4950#else
     
    124125                        return !new_val.empty();
    125126                }
    126         }
    127 
    128         template< typename node_t >
    129         template< typename object_t, typename super_t, typename field_t >
    130         void __pass::result1< node_t >::apply( object_t * object, field_t super_t::* field ) {
    131                 object->*field = value;
    132127        }
    133128
     
    233228
    234229                return {true, compound};
    235         }
    236 
    237         template< template <class...> class container_t >
    238         template< typename object_t, typename super_t, typename field_t >
    239         void __pass::resultNstmt<container_t>::apply(object_t * object, field_t super_t::* field) {
    240                 auto & container = object->*field;
    241                 __pedantic_pass_assert( container.size() <= values.size() );
    242 
    243                 auto cit = enumerate(container).begin();
    244 
    245                 container_t<ptr<Stmt>> nvals;
    246                 for (delta & d : values) {
    247                         if ( d.is_old ) {
    248                                 __pedantic_pass_assert( cit.idx <= d.old_idx );
    249                                 std::advance( cit, d.old_idx - cit.idx );
    250                                 nvals.push_back( std::move( (*cit).val) );
    251                         } else {
    252                                 nvals.push_back( std::move(d.new_val) );
    253                         }
    254                 }
    255 
    256                 container = std::move(nvals);
    257         }
    258 
    259         template< template <class...> class container_t >
    260         template< template <class...> class incontainer_t >
    261         void __pass::resultNstmt< container_t >::take_all( incontainer_t<ptr<Stmt>> * stmts ) {
    262                 if (!stmts || stmts->empty()) return;
    263 
    264                 std::transform(stmts->begin(), stmts->end(), std::back_inserter( values ),
    265                         [](ast::ptr<ast::Stmt>& stmt) -> delta {
    266                                 return delta( stmt.release(), -1, false );
    267                         });
    268                 stmts->clear();
    269                 differs = true;
    270         }
    271 
    272         template< template<class...> class container_t >
    273         template< template<class...> class incontainer_t >
    274         void __pass::resultNstmt< container_t >::take_all( incontainer_t<ptr<Decl>> * decls ) {
    275                 if (!decls || decls->empty()) return;
    276 
    277                 std::transform(decls->begin(), decls->end(), std::back_inserter( values ),
    278                         [](ast::ptr<ast::Decl>& decl) -> delta {
    279                                 auto loc = decl->location;
    280                                 auto stmt = new DeclStmt( loc, decl.release() );
    281                                 return delta( stmt, -1, false );
    282                         });
    283                 decls->clear();
    284                 differs = true;
    285230        }
    286231
     
    352297
    353298                return new_kids;
    354         }
    355 
    356         template< template <class...> class container_t, typename node_t >
    357         template< typename object_t, typename super_t, typename field_t >
    358         void __pass::resultN<container_t, node_t>::apply(object_t * object, field_t super_t::* field) {
    359                 auto & container = object->*field;
    360                 __pedantic_pass_assert( container.size() == values.size() );
    361 
    362                 for(size_t i = 0; i < container.size(); i++) {
    363                         // Take all the elements that are different in 'values'
    364                         // and swap them into 'container'
    365                         if( values[i] != nullptr ) swap(container[i], values[i]);
    366                 }
    367 
    368                 // Now the original containers should still have the unchanged values
    369                 // but also contain the new values
    370299        }
    371300
     
    836765                        if ( enterScope ) {
    837766                                __pass::symtab::enter(core, 0);
    838                                 __pass::scope::enter(core, 0);
    839767                        }
    840768                }, [this, leaveScope = !this->atFunctionTop]() {
    841769                        if ( leaveScope ) {
    842770                                __pass::symtab::leave(core, 0);
    843                                 __pass::scope::leave(core, 0);
    844771                        }
    845772                });
     
    1067994
    1068995//--------------------------------------------------------------------------
     996// WhenClause
     997template< typename core_t >
     998const ast::WhenClause * ast::Pass< core_t >::visit( const ast::WhenClause * node ) {
     999        VISIT_START( node );
     1000
     1001        if ( __visit_children() ) {
     1002                maybe_accept( node, &WhenClause::target );
     1003                maybe_accept( node, &WhenClause::stmt );
     1004                maybe_accept( node, &WhenClause::when_cond );
     1005        }
     1006
     1007        VISIT_END( WhenClause, node );
     1008}
     1009
     1010//--------------------------------------------------------------------------
    10691011// WaitForStmt
    10701012template< typename core_t >
     
    10911033
    10921034        if ( __visit_children() ) {
    1093                 maybe_accept( node, &WaitForClause::target_func );
     1035                maybe_accept( node, &WaitForClause::target );
    10941036                maybe_accept( node, &WaitForClause::target_args );
    10951037                maybe_accept( node, &WaitForClause::stmt );
    1096                 maybe_accept( node, &WaitForClause::cond );
     1038                maybe_accept( node, &WaitForClause::when_cond );
    10971039        }
    10981040
    10991041        VISIT_END( WaitForClause, node );
     1042}
     1043
     1044//--------------------------------------------------------------------------
     1045// WaitUntilStmt
     1046template< typename core_t >
     1047const ast::Stmt * ast::Pass< core_t >::visit( const ast::WaitUntilStmt * node ) {
     1048        VISIT_START( node );
     1049
     1050        if ( __visit_children() ) {
     1051                maybe_accept( node, &WaitUntilStmt::clauses );
     1052                maybe_accept( node, &WaitUntilStmt::timeout_time );
     1053                maybe_accept( node, &WaitUntilStmt::timeout_stmt );
     1054                maybe_accept( node, &WaitUntilStmt::timeout_cond );
     1055                maybe_accept( node, &WaitUntilStmt::else_stmt );
     1056                maybe_accept( node, &WaitUntilStmt::else_cond );
     1057        }
     1058
     1059        VISIT_END( Stmt, node );
    11001060}
    11011061
     
    20432003        if ( __visit_children() ) {
    20442004                maybe_accept( node, &TupleType::types );
    2045                 maybe_accept( node, &TupleType::members );
    20462005        }
    20472006
     
    22052164}
    22062165
     2166#undef __pedantic_pass_assertf
     2167#undef __pedantic_pass_assert
    22072168#undef VISIT_START
    22082169#undef VISIT_END
Note: See TracChangeset for help on using the changeset viewer.