Ignore:
File:
1 edited

Legend:

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

    rf6e6a55 r4ec9513  
    10101010const ast::Stmt * ast::Pass< core_t >::visit( const ast::WaitForStmt * node ) {
    10111011        VISIT_START( node );
    1012 
    1013         if ( __visit_children() ) {
    1014                 maybe_accept( node, &WaitForStmt::clauses );
    1015                 maybe_accept( node, &WaitForStmt::timeout_time );
    1016                 maybe_accept( node, &WaitForStmt::timeout_stmt );
    1017                 maybe_accept( node, &WaitForStmt::timeout_cond );
    1018                 maybe_accept( node, &WaitForStmt::else_stmt );
    1019                 maybe_accept( node, &WaitForStmt::else_cond );
    1020         }
     1012                // for( auto & clause : node->clauses ) {
     1013                //      maybeAccept_impl( clause.target.function, *this );
     1014                //      maybeAccept_impl( clause.target.arguments, *this );
     1015
     1016                //      maybeAccept_impl( clause.statement, *this );
     1017                //      maybeAccept_impl( clause.condition, *this );
     1018                // }
     1019
     1020        if ( __visit_children() ) {
     1021                std::vector<WaitForStmt::Clause> new_clauses;
     1022                new_clauses.reserve( node->clauses.size() );
     1023                bool mutated = false;
     1024                for( const auto & clause : node->clauses ) {
     1025
     1026                        const Expr * func = clause.target.func ? clause.target.func->accept(*this) : nullptr;
     1027                        if(func != clause.target.func) mutated = true;
     1028                        else func = nullptr;
     1029
     1030                        std::vector<ptr<Expr>> new_args;
     1031                        new_args.reserve(clause.target.args.size());
     1032                        for( const auto & arg : clause.target.args ) {
     1033                                auto a = arg->accept(*this);
     1034                                if( a != arg ) {
     1035                                        mutated = true;
     1036                                        new_args.push_back( a );
     1037                                } else
     1038                                        new_args.push_back( nullptr );
     1039                        }
     1040
     1041                        const Stmt * stmt = clause.stmt ? clause.stmt->accept(*this) : nullptr;
     1042                        if(stmt != clause.stmt) mutated = true;
     1043                        else stmt = nullptr;
     1044
     1045                        const Expr * cond = clause.cond ? clause.cond->accept(*this) : nullptr;
     1046                        if(cond != clause.cond) mutated = true;
     1047                        else cond = nullptr;
     1048
     1049                        new_clauses.push_back( WaitForStmt::Clause{ {func, std::move(new_args) }, stmt, cond } );
     1050                }
     1051
     1052                if(mutated) {
     1053                        auto n = __pass::mutate<core_t>(node);
     1054                        for(size_t i = 0; i < new_clauses.size(); i++) {
     1055                                if(new_clauses.at(i).target.func != nullptr) swap(n->clauses.at(i).target.func, new_clauses.at(i).target.func);
     1056
     1057                                for(size_t j = 0; j < new_clauses.at(i).target.args.size(); 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));
     1059                                }
     1060
     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);
     1063                        }
     1064                        node = n;
     1065                }
     1066        }
     1067
     1068        #define maybe_accept(field) \
     1069                if(node->field) { \
     1070                        auto nval = call_accept( node->field ); \
     1071                        if(nval.differs ) { \
     1072                                auto nparent = __pass::mutate<core_t>(node); \
     1073                                nparent->field = nval.value; \
     1074                                node = nparent; \
     1075                        } \
     1076                }
     1077
     1078        if ( __visit_children() ) {
     1079                maybe_accept( timeout.time );
     1080                maybe_accept( timeout.stmt );
     1081                maybe_accept( timeout.cond );
     1082                maybe_accept( orElse.stmt  );
     1083                maybe_accept( orElse.cond  );
     1084        }
     1085
     1086        #undef maybe_accept
    10211087
    10221088        VISIT_END( Stmt, node );
    1023 }
    1024 
    1025 //--------------------------------------------------------------------------
    1026 // WaitForClause
    1027 template< typename core_t >
    1028 const ast::WaitForClause * ast::Pass< core_t >::visit( const ast::WaitForClause * node ) {
    1029         VISIT_START( node );
    1030 
    1031         if ( __visit_children() ) {
    1032                 maybe_accept( node, &WaitForClause::target_func );
    1033                 maybe_accept( node, &WaitForClause::target_args );
    1034                 maybe_accept( node, &WaitForClause::stmt );
    1035                 maybe_accept( node, &WaitForClause::cond );
    1036         }
    1037 
    1038         VISIT_END( WaitForClause, node );
    10391089}
    10401090
Note: See TracChangeset for help on using the changeset viewer.