// // Cforall Version 1.0.0 Copyright (C) 2015 University of Waterloo // // The contents of this file are covered under the licence agreement in the // file "LICENCE" distributed with Cforall. // // MultRet.cc -- // // Author : Richard C. Bilson // Created On : Mon May 18 07:44:20 2015 // Last Modified By : Peter A. Buhr // Last Modified On : Mon May 18 12:37:57 2015 // Update Count : 1 // #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