#include #include #include #include #include "MultRet.h" #include "SynTree/Statement.h" #include "SynTree/Expression.h" #include "SynTree/Declaration.h" #include "SynTree/Type.h" namespace Tuples { MVRMutator::MVRMutator() : newVars( 0 ), newCode( 0 ) { } MVRMutator::~MVRMutator() { } int MVRMutator::curVal = 0; Statement *MVRMutator::mutate( ExprStmt *exprStmt ){ MVRMutator toplevel; exprStmt->set_expr( maybeMutate( exprStmt->get_expr(), toplevel ) ); if ( toplevel.hasCode() ) { assert ( toplevel.getVars() != 0 ); typedef std::list Statements; CompoundStmt *code = new CompoundStmt( std::list< Label >() ); // copy variables Statements &vars = toplevel.getVars()->get_kids(); for( Statements::iterator i = vars.begin(); i != vars.end(); i++ ) code->get_kids().push_back( *i ); // copy statements Statements &block = toplevel.getCode()->get_kids(); for( Statements::iterator i = block.begin(); i != block.end(); i++ ) code->get_kids().push_back( *i ); return code; } else return exprStmt; } Expression *MVRMutator::mutate( ApplicationExpr *appExpr ) { // appExpr->set_function( maybeMutate( appExpr->get_function(), *this ) ); bool mulretp = false; VariableExpr *funname; if ( (funname = dynamic_cast(appExpr->get_function())) == 0 ) goto DoArgs; FunctionDecl *fundecl; if ((fundecl = dynamic_cast(funname->get_var())) == 0) goto DoArgs; { typedef std::list RetType; RetType &rets = fundecl->get_functionType()->get_returnVals(); if ( rets.size() <= 1 ) goto DoArgs; mulretp = true; if( newVars == 0 ) newVars = new CompoundStmt( std::list