Changeset a32b204 for translator/Tuples
- Timestamp:
- May 17, 2015, 1:19:35 PM (11 years ago)
- Branches:
- ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, ctor, deferred_resn, demangler, enum, forall-pointer-decay, gc_noraii, jacob/cs343-translation, jenkins-sandbox, master, memory, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, string, stuck-waitfor-destruct, with_gc
- Children:
- 0dd3a2f
- Parents:
- b87a5ed
- Location:
- translator/Tuples
- Files:
-
- 7 edited
-
AssignExpand.cc (modified) (5 diffs)
-
FunctionChecker.cc (modified) (5 diffs)
-
FunctionFixer.cc (modified) (4 diffs)
-
MultRet.cc (modified) (6 diffs)
-
NameMatcher.cc (modified) (4 diffs)
-
TupleAssignment.cc (modified) (26 diffs)
-
TupleAssignment.h (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
translator/Tuples/AssignExpand.cc
rb87a5ed ra32b204 24 24 CompoundStmt *newSt = 0; 25 25 if (! extra.empty() ) { 26 if ( ! newSt )26 if ( ! newSt ) 27 27 newSt= new CompoundStmt(std::list<Label>()); 28 28 … … 31 31 32 32 if (! extra2.empty() ) { 33 if ( ! newSt )33 if ( ! newSt ) 34 34 newSt= new CompoundStmt(std::list<Label>()); 35 35 … … 38 38 39 39 if (! replace.empty() ) { 40 if ( ! newSt )40 if ( ! newSt ) 41 41 newSt= new CompoundStmt(std::list<Label>()); 42 42 … … 45 45 } 46 46 47 if ( newSt ) return newSt; else return exprStmt;47 if ( newSt ) return newSt; else return exprStmt; 48 48 } 49 49 … … 72 72 tupleExpr->get_type() == SolvedTupleExpr::MASS ) */ { 73 73 std::list<Expression *> &comps = tupleExpr->get_exprs(); 74 for ( std::list<Expression *>::iterator i = comps.begin(); i != comps.end(); ++i ) {74 for ( std::list<Expression *>::iterator i = comps.begin(); i != comps.end(); ++i ) { 75 75 std::list<Statement *> decls; 76 76 std::list<Statement *> temps; 77 77 std::list<Statement *> assigns; 78 if ( ApplicationExpr *app = dynamic_cast< ApplicationExpr * >(*i) ) {78 if ( ApplicationExpr *app = dynamic_cast< ApplicationExpr * >(*i) ) { 79 79 assert( app->get_args().size() == 2 ); 80 80 -
translator/Tuples/FunctionChecker.cc
rb87a5ed ra32b204 23 23 24 24 FunctionChecker::FunctionChecker( bool _topLevel, UniqueName *_nameGen ) : topLevel( _topLevel ), nameGen( _nameGen ) { 25 if ( topLevel) {26 assert( ! nameGen );25 if ( topLevel) { 26 assert( ! nameGen ); 27 27 nameGen = new UniqueName("_MVR_"); 28 28 } else … … 31 31 32 32 FunctionChecker::~FunctionChecker() { 33 if ( topLevel) {33 if ( topLevel) { 34 34 delete nameGen; 35 35 nameGen = 0; … … 39 39 Statement* FunctionChecker::mutate(ExprStmt *exprStmt) { 40 40 exprStmt->set_expr( maybeMutate( exprStmt->get_expr(), *this ) ); 41 if ( ! tempExpr.empty() ) {42 assert ( ! temporaries.empty() );41 if ( ! tempExpr.empty() ) { 42 assert ( ! temporaries.empty() ); 43 43 CompoundStmt *newBlock = new CompoundStmt( std::list< Label >() ); 44 44 // declarations 45 for ( std::list< ObjectDecl *>::iterator d = temporaries.begin(); d != temporaries.end(); ++d )45 for ( std::list< ObjectDecl *>::iterator d = temporaries.begin(); d != temporaries.end(); ++d ) 46 46 newBlock->get_kids().push_back( new DeclStmt( std::list<Label>(), *d ) ); 47 47 // new expression statements 48 for ( std::list< Expression *>::iterator e = tempExpr.begin(); e != tempExpr.end(); ++e )48 for ( std::list< Expression *>::iterator e = tempExpr.begin(); e != tempExpr.end(); ++e ) 49 49 newBlock->get_kids().push_back( new ExprStmt( std::list<Label>(), *e ) ); 50 50 … … 69 69 70 70 std::list< Expression * > newArgs; 71 for ( std::list< Expression *>::iterator e = applicationExpr->get_args().begin(); e != applicationExpr->get_args().end(); ++e ) {71 for ( std::list< Expression *>::iterator e = applicationExpr->get_args().begin(); e != applicationExpr->get_args().end(); ++e ) { 72 72 FunctionChecker rec( false, nameGen ); 73 73 (*e)->acceptMutator( rec ); 74 74 75 if ( ! rec.temporaries.empty() ) {75 if ( ! rec.temporaries.empty() ) { 76 76 TupleExpr *lhs = new TupleExpr; 77 77 std::list< Expression * > &tmem = lhs->get_exprs(); 78 for ( std::list<ObjectDecl *>::iterator d = rec.temporaries.begin(); d != rec.temporaries.end(); ++d ) {78 for ( std::list<ObjectDecl *>::iterator d = rec.temporaries.begin(); d != rec.temporaries.end(); ++d ) { 79 79 tmem.push_back( new VariableExpr( *d ) ); 80 80 newArgs.push_back( new VariableExpr( *d ) ); … … 100 100 101 101 Expression* TupleDistrib::mutate(UntypedExpr *expr) { 102 if ( NameExpr *assgnop = dynamic_cast< NameExpr * >(expr->get_function()) ) {103 if ( assgnop->get_name() == std::string("?=?") ) {102 if ( NameExpr *assgnop = dynamic_cast< NameExpr * >(expr->get_function()) ) { 103 if ( assgnop->get_name() == std::string("?=?") ) { 104 104 std::list<Expression *> &args = expr->get_args(); 105 105 assert(args.size() == 2); 106 106 //if args.front() points to a tuple and if args.back() is already resolved 107 if ( AddressExpr *addr = dynamic_cast<AddressExpr *>(args.front()) )108 if ( TupleExpr *lhs = dynamic_cast<TupleExpr *>(addr->get_arg()) )109 if ( ApplicationExpr *rhs = dynamic_cast<ApplicationExpr *>( args.back() ) ) {107 if ( AddressExpr *addr = dynamic_cast<AddressExpr *>(args.front()) ) 108 if ( TupleExpr *lhs = dynamic_cast<TupleExpr *>(addr->get_arg()) ) 109 if ( ApplicationExpr *rhs = dynamic_cast<ApplicationExpr *>( args.back() ) ) { 110 110 for ( std::list<Expression *>::iterator tc = lhs->get_exprs().begin(); tc != lhs->get_exprs().end(); ++tc ) 111 111 rhs->get_args().push_back( new AddressExpr( *tc ) ); -
translator/Tuples/FunctionFixer.cc
rb87a5ed ra32b204 40 40 Expression *rhs = 0; 41 41 // also check if returning multiple values 42 if ( CastExpr *cst = dynamic_cast<CastExpr *>( retStmt->get_expr() ) ) {43 if ( ApplicationExpr *app = dynamic_cast<ApplicationExpr *>( cst->get_arg() ) ) {44 if ( app->get_results().size() > 1 ) { // doesn't need to be ApplicationExpr42 if ( CastExpr *cst = dynamic_cast<CastExpr *>( retStmt->get_expr() ) ) { 43 if ( ApplicationExpr *app = dynamic_cast<ApplicationExpr *>( cst->get_arg() ) ) { 44 if ( app->get_results().size() > 1 ) { // doesn't need to be ApplicationExpr 45 45 tupleReturn = true; 46 46 rhs = app; 47 47 } 48 } else if ( TupleExpr *t = dynamic_cast<TupleExpr *>( cst->get_arg() ) ) {48 } else if ( TupleExpr *t = dynamic_cast<TupleExpr *>( cst->get_arg() ) ) { 49 49 tupleReturn = true; 50 50 assert( rets.size() == t->get_exprs().size() ); // stupid check, resolve expression … … 52 52 } 53 53 54 if ( tupleReturn ) {54 if ( tupleReturn ) { 55 55 assert ( rhs != 0 ); 56 56 std::list< Expression * > lhs; 57 for ( std::list< DeclarationWithType * >::iterator d = rets.begin(); d != rets.end(); ++d ) {57 for ( std::list< DeclarationWithType * >::iterator d = rets.begin(); d != rets.end(); ++d ) { 58 58 std::list<Expression *> largs; 59 59 largs.push_back(new VariableExpr( *d )); … … 81 81 if ( rets.empty() ) return variableExpr; 82 82 mutateAll( variableExpr->get_results(), *this ); 83 if ( std::find( rets.begin(), rets.end(), variableExpr->get_var() ) != rets.end() )83 if ( std::find( rets.begin(), rets.end(), variableExpr->get_var() ) != rets.end() ) 84 84 // if ( PointerType *ptr = dynamic_cast<PointerType *>(variableExpr->get_var()->get_type()) ) { 85 85 if ( dynamic_cast<PointerType *>(variableExpr->get_var()->get_type()) != 0 ) { … … 88 88 Expression *expr = ResolvExpr::resolveInVoidContext( /*new CastExpr(*/new UntypedExpr( new NameExpr( "*?" ), largs )/*, 89 89 ptr->get_base()),*/, index); 90 if ( ApplicationExpr *app = dynamic_cast< ApplicationExpr * >( expr ) ) {90 if ( ApplicationExpr *app = dynamic_cast< ApplicationExpr * >( expr ) ) { 91 91 assert( app->get_args().size() == 1 ); 92 92 app->get_args().pop_front(); -
translator/Tuples/MultRet.cc
rb87a5ed ra32b204 35 35 // copy variables 36 36 Statements &vars = toplevel.getVars()->get_kids(); 37 for ( Statements::iterator i = vars.begin(); i != vars.end(); i++ )37 for ( Statements::iterator i = vars.begin(); i != vars.end(); i++ ) 38 38 code->get_kids().push_back( *i ); 39 39 40 40 // copy statements 41 41 Statements &block = toplevel.getCode()->get_kids(); 42 for ( Statements::iterator i = block.begin(); i != block.end(); i++ )42 for ( Statements::iterator i = block.begin(); i != block.end(); i++ ) 43 43 code->get_kids().push_back( *i ); 44 44 … … 66 66 mulretp = true; 67 67 68 if ( newVars == 0 )68 if ( newVars == 0 ) 69 69 newVars = new CompoundStmt( std::list<Label>(0) ); 70 70 … … 81 81 Exprs &args = appExpr->get_args(); 82 82 std::list< Expression * > newArgs; 83 for ( Exprs::iterator i = args.begin(); i != args.end(); i++ ) {83 for ( Exprs::iterator i = args.begin(); i != args.end(); i++ ) { 84 84 MVRMutator next; 85 85 Expression *mutated = (*i)->acceptMutator( next ); … … 93 93 if (newVars == 0) 94 94 newVars = new CompoundStmt( std::list< Label >() ); 95 for ( Stmts::iterator i = vars.begin(); i != vars.end(); i++ ) // std::splice? -- need to append lists95 for ( Stmts::iterator i = vars.begin(); i != vars.end(); i++ ) // std::splice? -- need to append lists 96 96 newVars->get_kids().push_back( *i ); 97 97 98 98 if (newCode == 0) 99 99 newCode = new CompoundStmt( std::list< Label >() ); 100 for ( Stmts::iterator i = block.begin(); i != block.end(); i++ )100 for ( Stmts::iterator i = block.begin(); i != block.end(); i++ ) 101 101 newCode->get_kids().push_back( *i ); 102 102 … … 105 105 if ( next.hasResults() ) { 106 106 Exprs &res = next.get_results(); 107 for ( Exprs::iterator i = res.begin(); i != res.end(); i++ )107 for ( Exprs::iterator i = res.begin(); i != res.end(); i++ ) 108 108 newArgs.push_back( *i ); 109 109 } else … … 117 117 // add 'out' parameters 118 118 if ( ! argsToAdd.empty() ) 119 for (std::list< Expression *>::iterator i = argsToAdd.begin(); i != argsToAdd.end(); i++)119 for (std::list< Expression *>::iterator i = argsToAdd.begin(); i != argsToAdd.end(); i++) 120 120 (appExpr->get_args()).push_back( *i ); 121 121 // clear 'out' parameters ( so that the list can be reused -- substitute by auto_ptr later? ) -
translator/Tuples/NameMatcher.cc
rb87a5ed ra32b204 6 6 : current( 0 ) { 7 7 int cnt = 0; 8 for ( std::list< DeclarationWithType *>::const_iterator f = formals.begin(); f != formals.end(); ++f ) {8 for ( std::list< DeclarationWithType *>::const_iterator f = formals.begin(); f != formals.end(); ++f ) { 9 9 table.insert( std::pair< std::string, int >( (*f)->get_name(), cnt++ ) ); 10 10 index.push_back(*f); … … 16 16 17 17 void NameMatcher::match( ResolvExpr::AltList &alternatives ) throw (NoMatch) { 18 if ( alternatives.size() != index.size() )18 if ( alternatives.size() != index.size() ) 19 19 throw NoMatch("Length of actuals and formals differ"); 20 20 21 for ( ResolvExpr::AltList::const_iterator a = alternatives.begin(); a != alternatives.end(); ++a ) {22 if ( a->expr->get_argName() != 0 )21 for ( ResolvExpr::AltList::const_iterator a = alternatives.begin(); a != alternatives.end(); ++a ) { 22 if ( a->expr->get_argName() != 0 ) 23 23 if ( NameExpr *name = dynamic_cast<NameExpr *>( a->expr->get_argName() ) ) { 24 24 if ( table.find( name->get_name() ) != table.end() ) { … … 27 27 } else 28 28 throw NoMatch( name->get_name() + "no such designation" ); 29 } /*else if ( TupleExpr *tup = dynamic_cast<TupleExpr *>( a->expr->get_argName() ) )29 } /*else if ( TupleExpr *tup = dynamic_cast<TupleExpr *>( a->expr->get_argName() ) ) 30 30 std::cerr << "Designated expression" << std::endl; */ 31 31 exprs.push_back( &(*a) ); … … 41 41 42 42 ResolvExpr::Alternative &NameMatcher::get_next() throw (NoMoreElements) { 43 if ( current++ >= (int)(index.size()) )43 if ( current++ >= (int)(index.size()) ) 44 44 throw NoMoreElements(); 45 45 return *(new ResolvExpr::Alternative()); -
translator/Tuples/TupleAssignment.cc
rb87a5ed ra32b204 19 19 bool TupleAssignSpotter::pointsToTuple( Expression *expr ) { 20 20 // also check for function returning tuple of reference types 21 if (AddressExpr *addr = dynamic_cast<AddressExpr *>(expr) )22 if ( isTuple(addr->get_arg() ) )21 if (AddressExpr *addr = dynamic_cast<AddressExpr *>(expr) ) 22 if ( isTuple(addr->get_arg() ) ) 23 23 return true; 24 24 return false; … … 26 26 27 27 bool TupleAssignSpotter::isTupleVar( DeclarationWithType *decl ) { 28 if ( dynamic_cast<TupleType *>(decl->get_type()) )28 if ( dynamic_cast<TupleType *>(decl->get_type()) ) 29 29 return true; 30 30 return false; … … 33 33 bool TupleAssignSpotter::isTuple( Expression *expr, bool isRight ) { 34 34 // true if `expr' is an expression returning a tuple: tuple, tuple variable or MRV function 35 if ( ! expr ) return false;36 37 if ( dynamic_cast<TupleExpr *>(expr) )38 return true; 39 else if ( VariableExpr *var = dynamic_cast<VariableExpr *>(expr) ) {40 if ( isTupleVar(var->get_var()) )35 if ( ! expr ) return false; 36 37 if ( dynamic_cast<TupleExpr *>(expr) ) 38 return true; 39 else if ( VariableExpr *var = dynamic_cast<VariableExpr *>(expr) ) { 40 if ( isTupleVar(var->get_var()) ) 41 41 return true; 42 42 } … … 52 52 return false; 53 53 54 if ( new_assigns.empty() ) return false;54 if ( new_assigns.empty() ) return false; 55 55 /*return */matcher->solve( new_assigns ); 56 if ( dynamic_cast<TupleAssignSpotter::MultipleAssignMatcher *>( matcher ) ) {56 if ( dynamic_cast<TupleAssignSpotter::MultipleAssignMatcher *>( matcher ) ) { 57 57 // now resolve new assignments 58 58 std::list< Expression * > solved_assigns; … … 61 61 62 62 ResolvExpr::AltList current; 63 for ( std::list< Expression * >::iterator i = new_assigns.begin(); i != new_assigns.end(); ++i ) {63 for ( std::list< Expression * >::iterator i = new_assigns.begin(); i != new_assigns.end(); ++i ) { 64 64 //try { 65 65 ResolvExpr::AlternativeFinder finder( currentFinder->get_indexer(), currentFinder->get_environ() ); … … 80 80 return true; 81 81 } else { // mass assignment 82 //if ( new_assigns.empty() ) return false;82 //if ( new_assigns.empty() ) return false; 83 83 std::list< Expression * > solved_assigns; 84 84 ResolvExpr::AltList solved_alts; … … 87 87 ResolvExpr::AltList current; 88 88 if ( optMass.empty() ) { 89 for ( std::list< Expression * >::size_type i = 0; i != new_assigns.size(); ++i )89 for ( std::list< Expression * >::size_type i = 0; i != new_assigns.size(); ++i ) 90 90 optMass.push_back( ResolvExpr::AltList() ); 91 91 } 92 92 int cnt = 0; 93 for ( std::list< Expression * >::iterator i = new_assigns.begin(); i != new_assigns.end(); ++i, cnt++ ) {93 for ( std::list< Expression * >::iterator i = new_assigns.begin(); i != new_assigns.end(); ++i, cnt++ ) { 94 94 95 95 ResolvExpr::AlternativeFinder finder( currentFinder->get_indexer(), currentFinder->get_environ() ); … … 110 110 111 111 bool TupleAssignSpotter::isMVR( Expression *expr ) { 112 if ( expr->get_results().size() > 1 ) {112 if ( expr->get_results().size() > 1 ) { 113 113 // MVR processing 114 114 return true; … … 118 118 119 119 bool TupleAssignSpotter::isTupleAssignment( UntypedExpr * expr, std::list<ResolvExpr::AltList> &possibilities ) { 120 if ( NameExpr *assgnop = dynamic_cast< NameExpr * >(expr->get_function()) ) {121 122 if ( assgnop->get_name() == std::string("?=?") ) {123 124 for ( std::list<ResolvExpr::AltList>::iterator ali = possibilities.begin(); ali != possibilities.end(); ++ali ) {120 if ( NameExpr *assgnop = dynamic_cast< NameExpr * >(expr->get_function()) ) { 121 122 if ( assgnop->get_name() == std::string("?=?") ) { 123 124 for ( std::list<ResolvExpr::AltList>::iterator ali = possibilities.begin(); ali != possibilities.end(); ++ali ) { 125 125 assert( ali->size() == 2 ); 126 126 ResolvExpr::AltList::iterator opit = ali->begin(); 127 127 ResolvExpr::Alternative op1 = *opit, op2 = *(++opit); 128 128 129 if ( pointsToTuple(op1.expr) ) { // also handles tuple vars129 if ( pointsToTuple(op1.expr) ) { // also handles tuple vars 130 130 if ( isTuple( op2.expr, true ) ) 131 131 matcher = new MultipleAssignMatcher(op1.expr, op2.expr); 132 else if ( isMVR( op2.expr ) ) {132 else if ( isMVR( op2.expr ) ) { 133 133 // handle MVR differently 134 134 } else … … 137 137 138 138 std::list< ResolvExpr::AltList > options; 139 if ( match() )139 if ( match() ) 140 140 /* 141 if ( hasMatched ) {141 if ( hasMatched ) { 142 142 // throw SemanticError("Ambiguous tuple assignment"); 143 143 } else {*/ … … 150 150 } 151 151 152 if ( hasMatched ) {153 if ( dynamic_cast<TupleAssignSpotter::MultipleAssignMatcher *>( matcher ) ) {152 if ( hasMatched ) { 153 if ( dynamic_cast<TupleAssignSpotter::MultipleAssignMatcher *>( matcher ) ) { 154 154 //options.print( std::cerr ); 155 155 std::list< ResolvExpr::AltList >best = options.get_best(); 156 if ( best.size() == 1 ) {156 if ( best.size() == 1 ) { 157 157 std::list<Expression *> solved_assigns; 158 for ( ResolvExpr::AltList::iterator i = best.front().begin(); i != best.front().end(); ++i ){158 for ( ResolvExpr::AltList::iterator i = best.front().begin(); i != best.front().end(); ++i ){ 159 159 solved_assigns.push_back( i->expr ); 160 160 } … … 165 165 assert(! optMass.empty() ); 166 166 ResolvExpr::AltList winners; 167 for ( std::vector< ResolvExpr::AltList >::iterator i = optMass.begin(); i != optMass.end(); ++i )167 for ( std::vector< ResolvExpr::AltList >::iterator i = optMass.begin(); i != optMass.end(); ++i ) 168 168 findMinCostAlt( i->begin(), i->end(), back_inserter(winners) ); 169 169 170 170 std::list< Expression *> solved_assigns; 171 for ( ResolvExpr::AltList::iterator i = winners.begin(); i != winners.end(); ++i )171 for ( ResolvExpr::AltList::iterator i = winners.begin(); i != winners.end(); ++i ) 172 172 solved_assigns.push_back( i->expr ); 173 173 currentFinder->get_alternatives().push_front( ResolvExpr::Alternative(new SolvedTupleExpr(solved_assigns/*, SolvedTupleExpr::MASS*/), currentFinder->get_environ(), ResolvExpr::Cost() ) ); … … 181 181 void TupleAssignSpotter::Matcher::init( Expression *_lhs, Expression *_rhs ) { 182 182 lhs.clear(); 183 if (AddressExpr *addr = dynamic_cast<AddressExpr *>(_lhs) )184 if ( TupleExpr *tuple = dynamic_cast<TupleExpr *>(addr->get_arg()) )183 if (AddressExpr *addr = dynamic_cast<AddressExpr *>(_lhs) ) 184 if ( TupleExpr *tuple = dynamic_cast<TupleExpr *>(addr->get_arg()) ) 185 185 std::copy( tuple->get_exprs().begin(), tuple->get_exprs().end(), back_inserter(lhs) ); 186 186 … … 195 195 init(_lhs,_rhs); 196 196 197 if ( TupleExpr *tuple = dynamic_cast<TupleExpr *>(_rhs) )197 if ( TupleExpr *tuple = dynamic_cast<TupleExpr *>(_rhs) ) 198 198 std::copy( tuple->get_exprs().begin(), tuple->get_exprs().end(), back_inserter(rhs) ); 199 199 } … … 211 211 if ( lhs.empty() || (rhs.size() != 1) ) return false; 212 212 213 for ( std::list< Expression * >::iterator l = lhs.begin(); l != lhs.end(); l++ ) {213 for ( std::list< Expression * >::iterator l = lhs.begin(); l != lhs.end(); l++ ) { 214 214 std::list< Expression * > args; 215 215 args.push_back( new AddressExpr(*l) ); … … 229 229 ResolvExpr::AltList current; 230 230 if ( optMass.empty() ) { 231 for ( std::list< Expression * >::size_type i = 0; i != new_assigns.size(); ++i )231 for ( std::list< Expression * >::size_type i = 0; i != new_assigns.size(); ++i ) 232 232 optMass.push_back( ResolvExpr::AltList() ); 233 233 } 234 234 int cnt = 0; 235 for ( std::list< Expression * >::iterator i = new_assigns.begin(); i != new_assigns.end(); ++i, cnt++ ) {235 for ( std::list< Expression * >::iterator i = new_assigns.begin(); i != new_assigns.end(); ++i, cnt++ ) { 236 236 237 237 ResolvExpr::AlternativeFinder finder( currentFinder->get_indexer(), currentFinder->get_environ() ); … … 250 250 bool TupleAssignSpotter::MultipleAssignMatcher::match( std::list< Expression * > &out ) { 251 251 // need more complicated matching 252 if ( lhs.size() == rhs.size() ) {252 if ( lhs.size() == rhs.size() ) { 253 253 zipWith( lhs.begin(), lhs.end(), rhs.begin(), rhs.end(), back_inserter(out), TupleAssignSpotter::Matcher::createAssgn ); 254 254 return true; … … 265 265 266 266 ResolvExpr::AltList current; 267 for ( std::list< Expression * >::iterator i = new_assigns.begin(); i != new_assigns.end(); ++i ) {267 for ( std::list< Expression * >::iterator i = new_assigns.begin(); i != new_assigns.end(); ++i ) { 268 268 //try { 269 269 ResolvExpr::AlternativeFinder finder( currentFinder->get_indexer(), currentFinder->get_environ() ); … … 297 297 // transpose matrix 298 298 if ( costMatrix.empty() ) 299 for ( unsigned int i = 0; i< opt.size(); ++i)299 for ( unsigned int i = 0; i< opt.size(); ++i) 300 300 costMatrix.push_back( vector<ResolvExpr::Cost>() ); 301 301 302 302 int cnt = 0; 303 for ( ResolvExpr::AltList::iterator i = opt.begin(); i != opt.end(); ++i, cnt++ )303 for ( ResolvExpr::AltList::iterator i = opt.begin(); i != opt.end(); ++i, cnt++ ) 304 304 costMatrix[cnt].push_back( i->cost ); 305 305 … … 312 312 list< ResolvExpr::AltList > ret; 313 313 list< multiset<int> > solns; 314 for ( vector< vector<Cost> >::iterator i = costMatrix.begin(); i != costMatrix.end(); ++i ) {314 for ( vector< vector<Cost> >::iterator i = costMatrix.begin(); i != costMatrix.end(); ++i ) { 315 315 list<int> current; 316 316 findMinCost( i->begin(), i->end(), back_inserter(current) ); … … 320 320 multiset<int> result; 321 321 lift_intersection( solns.begin(), solns.end(), inserter( result, result.begin() ) ); 322 if ( result.size() != 1 )322 if ( result.size() != 1 ) 323 323 throw SemanticError("Ambiguous tuple expression"); 324 324 ret.push_back(get_option( *(result.begin() ))); … … 329 329 using namespace std; 330 330 331 for ( vector< vector < ResolvExpr::Cost > >::iterator i = costMatrix.begin(); i != costMatrix.end(); ++i ) {332 for ( vector < ResolvExpr::Cost >::iterator j = i->begin(); j != i->end(); ++j )331 for ( vector< vector < ResolvExpr::Cost > >::iterator i = costMatrix.begin(); i != costMatrix.end(); ++i ) { 332 for ( vector < ResolvExpr::Cost >::iterator j = i->begin(); j != i->end(); ++j ) 333 333 ostr << *j << " " ; 334 334 ostr << std::endl; … … 352 352 Cost minCost = Cost::infinity; 353 353 unsigned int index = 0; 354 for ( InputIterator i = begin; i != end; ++i, index++ ) {355 if ( *i < minCost ) {354 for ( InputIterator i = begin; i != end; ++i, index++ ) { 355 if ( *i < minCost ) { 356 356 minCost = *i; 357 357 alternatives.clear(); 358 358 alternatives.push_back( index ); 359 } else if ( *i == minCost ) {359 } else if ( *i == minCost ) { 360 360 alternatives.push_back( index ); 361 361 } … … 366 366 template< class InputIterator, class OutputIterator > 367 367 void TupleAssignSpotter::Options::lift_intersection( InputIterator begin, InputIterator end, OutputIterator out ){ 368 if ( begin == end ) return;368 if ( begin == end ) return; 369 369 InputIterator test = begin; 370 370 371 if (++test == end)371 if (++test == end) 372 372 { copy(begin->begin(), begin->end(), out); return; } 373 373 … … 376 376 copy( begin->begin(), begin->end(), inserter( cur, cur.begin() ) ); 377 377 378 while ( test != end ) {378 while ( test != end ) { 379 379 std::multiset<int> temp; 380 380 set_intersection( cur.begin(), cur.end(), test->begin(), test->end(), inserter(temp,temp.begin()) ); … … 390 390 391 391 ResolvExpr::AltList TupleAssignSpotter::Options::get_option( std::list< ResolvExpr::AltList >::size_type index ) { 392 if ( index >= options.size() )392 if ( index >= options.size() ) 393 393 throw 0; // XXX 394 394 std::list< ResolvExpr::AltList >::iterator it = options.begin(); 395 for ( std::list< ResolvExpr::AltList >::size_type i = 0; i < index; ++i, ++it );395 for ( std::list< ResolvExpr::AltList >::size_type i = 0; i < index; ++i, ++it ); 396 396 return *it; 397 397 } -
translator/Tuples/TupleAssignment.h
rb87a5ed ra32b204 102 102 // select the alternatives that have the minimum parameter cost 103 103 Cost minCost = Cost::infinity; 104 for ( AltList::iterator i = begin; i != end; ++i ) {105 if ( i->cost < minCost ) {104 for ( AltList::iterator i = begin; i != end; ++i ) { 105 if ( i->cost < minCost ) { 106 106 minCost = i->cost; 107 107 i->cost = i->cvtCost; 108 108 alternatives.clear(); 109 109 alternatives.push_back( *i ); 110 } else if ( i->cost == minCost ) {110 } else if ( i->cost == minCost ) { 111 111 i->cost = i->cvtCost; 112 112 alternatives.push_back( *i );
Note:
See TracChangeset
for help on using the changeset viewer.