Ignore:
Timestamp:
Apr 19, 2022, 3:00:04 PM (3 years ago)
Author:
m3zulfiq <m3zulfiq@…>
Branches:
ADT, ast-experimental, master, pthread-emulation, qualifiedEnum
Children:
5b84a321
Parents:
ba897d21 (diff), bb7c77d (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:

added benchmark and evaluations chapter to thesis

File:
1 edited

Legend:

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

    rba897d21 r2e9b59b  
    354354                        // Take all the elements that are different in 'values'
    355355                        // and swap them into 'container'
    356                         if( values[i] != nullptr ) std::swap(container[i], values[i]);
     356                        if( values[i] != nullptr ) swap(container[i], values[i]);
    357357                }
    358358
     
    399399
    400400        template< typename core_t >
    401         template<typename node_t, typename parent_t, typename child_t>
     401        template<typename node_t, typename super_t, typename field_t>
    402402        void ast::Pass< core_t >::maybe_accept(
    403403                const node_t * & parent,
    404                 child_t parent_t::*child
     404                field_t super_t::*field
    405405        ) {
    406                 static_assert( std::is_base_of<parent_t, node_t>::value, "Error deducing member object" );
    407 
    408                 if(__pass::skip(parent->*child)) return;
    409                 const auto & old_val = __pass::get(parent->*child, 0);
     406                static_assert( std::is_base_of<super_t, node_t>::value, "Error deducing member object" );
     407
     408                if(__pass::skip(parent->*field)) return;
     409                const auto & old_val = __pass::get(parent->*field, 0);
    410410
    411411                static_assert( !std::is_same<const ast::Node * &, decltype(old_val)>::value, "ERROR");
     
    417417                if( new_val.differs ) {
    418418                        auto new_parent = __pass::mutate<core_t>(parent);
    419                         new_val.apply(new_parent, child);
     419                        new_val.apply(new_parent, field);
    420420                        parent = new_parent;
    421421                }
     
    423423
    424424        template< typename core_t >
    425         template<typename node_t, typename parent_t, typename child_t>
     425        template<typename node_t, typename super_t, typename field_t>
    426426        void ast::Pass< core_t >::maybe_accept_as_compound(
    427427                const node_t * & parent,
    428                 child_t parent_t::*child
     428                field_t super_t::*child
    429429        ) {
    430                 static_assert( std::is_base_of<parent_t, node_t>::value, "Error deducing member object" );
     430                static_assert( std::is_base_of<super_t, node_t>::value, "Error deducing member object" );
    431431
    432432                if(__pass::skip(parent->*child)) return;
     
    575575                        __pass::symtab::addId( core, 0, func );
    576576                        if ( __visit_children() ) {
    577                                 // parameter declarations
     577                                maybe_accept( node, &FunctionDecl::type_params );
     578                                maybe_accept( node, &FunctionDecl::assertions );
    578579                                maybe_accept( node, &FunctionDecl::params );
    579580                                maybe_accept( node, &FunctionDecl::returns );
    580                                 // type params and assertions
    581                                 maybe_accept( node, &FunctionDecl::type_params );
    582                                 maybe_accept( node, &FunctionDecl::assertions );
     581                                maybe_accept( node, &FunctionDecl::type );
    583582                                // First remember that we are now within a function.
    584583                                ValueGuard< bool > oldInFunction( inFunction );
     
    893892        if ( __visit_children() ) {
    894893                maybe_accept( node, &SwitchStmt::cond  );
    895                 maybe_accept( node, &SwitchStmt::stmts );
     894                maybe_accept( node, &SwitchStmt::cases );
    896895        }
    897896
     
    900899
    901900//--------------------------------------------------------------------------
    902 // CaseStmt
    903 template< typename core_t >
    904 const ast::Stmt * ast::Pass< core_t >::visit( const ast::CaseStmt * node ) {
    905         VISIT_START( node );
    906 
    907         if ( __visit_children() ) {
    908                 maybe_accept( node, &CaseStmt::cond  );
    909                 maybe_accept( node, &CaseStmt::stmts );
    910         }
    911 
    912         VISIT_END( Stmt, node );
     901// CaseClause
     902template< typename core_t >
     903const ast::CaseClause * ast::Pass< core_t >::visit( const ast::CaseClause * node ) {
     904        VISIT_START( node );
     905
     906        if ( __visit_children() ) {
     907                maybe_accept( node, &CaseClause::cond  );
     908                maybe_accept( node, &CaseClause::stmts );
     909        }
     910
     911        VISIT_END( CaseClause, node );
    913912}
    914913
     
    964963
    965964//--------------------------------------------------------------------------
    966 // CatchStmt
    967 template< typename core_t >
    968 const ast::Stmt * ast::Pass< core_t >::visit( const ast::CatchStmt * node ) {
     965// CatchClause
     966template< typename core_t >
     967const ast::CatchClause * ast::Pass< core_t >::visit( const ast::CatchClause * node ) {
    969968        VISIT_START( node );
    970969
     
    972971                // catch statements introduce a level of scope (for the caught exception)
    973972                guard_symtab guard { *this };
    974                 maybe_accept( node, &CatchStmt::decl );
    975                 maybe_accept( node, &CatchStmt::cond );
    976                 maybe_accept_as_compound( node, &CatchStmt::body );
    977         }
    978 
    979         VISIT_END( Stmt, node );
    980 }
    981 
    982 //--------------------------------------------------------------------------
    983 // FinallyStmt
    984 template< typename core_t >
    985 const ast::Stmt * ast::Pass< core_t >::visit( const ast::FinallyStmt * node ) {
    986         VISIT_START( node );
    987 
    988         if ( __visit_children() ) {
    989                 maybe_accept( node, &FinallyStmt::body );
    990         }
    991 
    992         VISIT_END( Stmt, node );
     973                maybe_accept( node, &CatchClause::decl );
     974                maybe_accept( node, &CatchClause::cond );
     975                maybe_accept_as_compound( node, &CatchClause::body );
     976        }
     977
     978        VISIT_END( CatchClause, node );
     979}
     980
     981//--------------------------------------------------------------------------
     982// FinallyClause
     983template< typename core_t >
     984const ast::FinallyClause * ast::Pass< core_t >::visit( const ast::FinallyClause * node ) {
     985        VISIT_START( node );
     986
     987        if ( __visit_children() ) {
     988                maybe_accept( node, &FinallyClause::body );
     989        }
     990
     991        VISIT_END( FinallyClause, node );
    993992}
    994993
     
    10541053                        auto n = __pass::mutate<core_t>(node);
    10551054                        for(size_t i = 0; i < new_clauses.size(); i++) {
    1056                                 if(new_clauses.at(i).target.func != nullptr) std::swap(n->clauses.at(i).target.func, new_clauses.at(i).target.func);
     1055                                if(new_clauses.at(i).target.func != nullptr) swap(n->clauses.at(i).target.func, new_clauses.at(i).target.func);
    10571056
    10581057                                for(size_t j = 0; j < new_clauses.at(i).target.args.size(); j++) {
    1059                                         if(new_clauses.at(i).target.args.at(j) != nullptr) std::swap(n->clauses.at(i).target.args.at(j), new_clauses.at(i).target.args.at(j));
     1058                                        if(new_clauses.at(i).target.args.at(j) != nullptr) swap(n->clauses.at(i).target.args.at(j), new_clauses.at(i).target.args.at(j));
    10601059                                }
    10611060
    1062                                 if(new_clauses.at(i).stmt != nullptr) std::swap(n->clauses.at(i).stmt, new_clauses.at(i).stmt);
    1063                                 if(new_clauses.at(i).cond != nullptr) std::swap(n->clauses.at(i).cond, new_clauses.at(i).cond);
     1061                                if(new_clauses.at(i).stmt != nullptr) swap(n->clauses.at(i).stmt, new_clauses.at(i).stmt);
     1062                                if(new_clauses.at(i).cond != nullptr) swap(n->clauses.at(i).cond, new_clauses.at(i).cond);
    10641063                        }
    10651064                        node = n;
     
    15161515                }
    15171516                maybe_accept( node, &TypeExpr::type );
     1517        }
     1518
     1519        VISIT_END( Expr, node );
     1520}
     1521
     1522//--------------------------------------------------------------------------
     1523// DimensionExpr
     1524template< typename core_t >
     1525const ast::Expr * ast::Pass< core_t >::visit( const ast::DimensionExpr * node ) {
     1526        VISIT_START( node );
     1527
     1528        if ( __visit_children() ) {
     1529                guard_symtab guard { *this };
     1530                maybe_accept( node, &DimensionExpr::result );
    15181531        }
    15191532
     
    18591872
    18601873        if ( __visit_children() ) {
    1861                 // xxx - should PointerType visit/mutate dimension?
     1874                maybe_accept( node, &PointerType::dimension );
    18621875                maybe_accept( node, &PointerType::base );
    18631876        }
     
    21512164
    21522165        if ( __visit_children() ) {
    2153                 {
    2154                         bool mutated = false;
    2155                         std::unordered_map< ast::TypeInstType::TypeEnvKey, ast::ptr< ast::Type > > new_map;
    2156                         for ( const auto & p : node->typeEnv ) {
    2157                                 guard_symtab guard { *this };
    2158                                 auto new_node = p.second->accept( *this );
    2159                                 if (new_node != p.second) mutated = true;
    2160                                 new_map.insert({ p.first, new_node });
    2161                         }
    2162                         if (mutated) {
    2163                                 auto new_node = __pass::mutate<core_t>( node );
    2164                                 new_node->typeEnv.swap( new_map );
    2165                                 node = new_node;
    2166                         }
     2166                bool mutated = false;
     2167                std::unordered_map< ast::TypeInstType::TypeEnvKey, ast::ptr< ast::Type > > new_map;
     2168                for ( const auto & p : node->typeEnv ) {
     2169                        guard_symtab guard { *this };
     2170                        auto new_node = p.second->accept( *this );
     2171                        if (new_node != p.second) mutated = true;
     2172                        new_map.insert({ p.first, new_node });
     2173                }
     2174                if (mutated) {
     2175                        auto new_node = __pass::mutate<core_t>( node );
     2176                        new_node->typeEnv.swap( new_map );
     2177                        node = new_node;
    21672178                }
    21682179        }
Note: See TracChangeset for help on using the changeset viewer.