- File:
-
- 1 edited
-
src/ResolvExpr/AlternativeFinder.cc (modified) (55 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/ResolvExpr/AlternativeFinder.cc
ra8706fc r8e18b8e 21 21 #include <list> // for _List_iterator, list, _List_const_... 22 22 #include <map> // for _Rb_tree_iterator, map, _Rb_tree_c... 23 #include <memory> // for allocator_traits<>::value_type , unique_ptr23 #include <memory> // for allocator_traits<>::value_type 24 24 #include <utility> // for pair 25 25 #include <vector> // for vector … … 35 35 #include "ResolveTypeof.h" // for resolveTypeof 36 36 #include "Resolver.h" // for resolveStmtExpr 37 #include "Common/GC.h" // for new_static_root 37 38 #include "SymTab/Indexer.h" // for Indexer 38 39 #include "SymTab/Mangler.h" // for Mangler … … 101 102 void addAnonConversions( const Alternative & alt ); 102 103 /// Adds alternatives for member expressions, given the aggregate, conversion cost for that aggregate, and name of the member 103 template< typename StructOrUnionType > void addAggMembers( StructOrUnionType *aggInst, Expression *expr, const Cost &newCost, const TypeEnvironment & env, Expression * member);104 template< typename StructOrUnionType > void addAggMembers( StructOrUnionType *aggInst, Expression *expr, const Cost &newCost, const TypeEnvironment & env, const std::string & name ); 104 105 /// Adds alternatives for member expressions where the left side has tuple type 105 106 void addTupleMembers( TupleType * tupleType, Expression *expr, const Cost &newCost, const TypeEnvironment & env, Expression * member ); … … 165 166 candidate->env.apply( newType ); 166 167 mangleName = SymTab::Mangler::mangle( newType ); 167 delete newType;168 168 } 169 169 std::map< std::string, PruneStruct >::iterator mapPlace = selected.find( mangleName ); … … 297 297 // adds anonymous member interpretations whenever an aggregate value type is seen. 298 298 // it's okay for the aggregate expression to have reference type -- cast it to the base type to treat the aggregate as the referenced value 299 std::unique_ptr<Expression> aggrExpr( alt.expr->clone());299 Expression* aggrExpr = alt.expr->clone(); 300 300 alt.env.apply( aggrExpr->get_result() ); 301 301 Type * aggrType = aggrExpr->get_result(); 302 302 if ( dynamic_cast< ReferenceType * >( aggrType ) ) { 303 303 aggrType = aggrType->stripReferences(); 304 aggrExpr .reset( new CastExpr( aggrExpr.release(), aggrType->clone() ) );304 aggrExpr = new CastExpr{ aggrExpr, aggrType->clone() }; 305 305 } 306 306 307 307 if ( StructInstType *structInst = dynamic_cast< StructInstType* >( aggrExpr->get_result() ) ) { 308 NameExpr nameExpr( "" ); 309 addAggMembers( structInst, aggrExpr.get(), alt.cost+Cost::safe, alt.env, &nameExpr ); 308 addAggMembers( structInst, aggrExpr, alt.cost+Cost::safe, alt.env, "" ); 310 309 } else if ( UnionInstType *unionInst = dynamic_cast< UnionInstType* >( aggrExpr->get_result() ) ) { 311 NameExpr nameExpr( "" ); 312 addAggMembers( unionInst, aggrExpr.get(), alt.cost+Cost::safe, alt.env, &nameExpr ); 310 addAggMembers( unionInst, aggrExpr, alt.cost+Cost::safe, alt.env, "" ); 313 311 } // if 314 312 } 315 313 316 314 template< typename StructOrUnionType > 317 void AlternativeFinder::Finder::addAggMembers( StructOrUnionType *aggInst, Expression *expr, const Cost &newCost, const TypeEnvironment & env, Expression * member ) { 318 // by this point, member must be a name expr 319 NameExpr * nameExpr = dynamic_cast< NameExpr * >( member ); 320 if ( ! nameExpr ) return; 321 const std::string & name = nameExpr->get_name(); 315 void AlternativeFinder::Finder::addAggMembers( StructOrUnionType *aggInst, Expression *expr, const Cost &newCost, const TypeEnvironment & env, const std::string & name ) { 322 316 std::list< Declaration* > members; 323 317 aggInst->lookup( name, members ); … … 344 338 if ( ss >> val && ! (ss >> tmp) ) { 345 339 if ( val >= 0 && (unsigned int)val < tupleType->size() ) { 346 alternatives.push_back( Alternative( new TupleIndexExpr( expr ->clone(), val ), env, newCost ) );340 alternatives.push_back( Alternative( new TupleIndexExpr( expr, val ), env, newCost ) ); 347 341 } // if 348 342 } // if … … 353 347 int val; 354 348 ss >> val; 355 alternatives.push_back( Alternative( new TupleIndexExpr( expr ->clone(), val ), env, newCost ) );349 alternatives.push_back( Alternative( new TupleIndexExpr( expr, val ), env, newCost ) ); 356 350 } 357 351 } // if … … 359 353 360 354 void AlternativeFinder::Finder::postvisit( ApplicationExpr *applicationExpr ) { 361 alternatives.push_back( Alternative( applicationExpr ->clone(), env, Cost::zero ) );355 alternatives.push_back( Alternative( applicationExpr, env, Cost::zero ) ); 362 356 } 363 357 … … 468 462 } 469 463 470 // /// Map of declaration uniqueIds (intended to be the assertions in an AssertionSet) to their parents and the number of times they've been included471 //typedef std::unordered_map< UniqueId, std::unordered_map< UniqueId, unsigned > > AssertionParentSet;472 473 464 static const int recursionLimit = /*10*/ 4; ///< Limit to depth of recursion satisfaction 474 //static const unsigned recursionParentLimit = 1; ///< Limit to the number of times an assertion can recursively use itself475 465 476 466 void addToIndexer( AssertionSet &assertSet, SymTab::Indexer &indexer ) { … … 483 473 484 474 template< typename ForwardIterator, typename OutputIterator > 485 void inferRecursive( ForwardIterator begin, ForwardIterator end, const Alternative &newAlt, OpenVarSet &openVars, const SymTab::Indexer &decls, const AssertionSet &newNeed, /*const AssertionParentSet &needParents,*/ 486 int level, const SymTab::Indexer &indexer, OutputIterator out ) { 475 void inferRecursive( ForwardIterator begin, ForwardIterator end, const Alternative &newAlt, OpenVarSet &openVars, const SymTab::Indexer &decls, const AssertionSet &newNeed, int level, const SymTab::Indexer &indexer, OutputIterator out ) { 487 476 if ( begin == end ) { 488 477 if ( newNeed.empty() ) { … … 502 491 printAssertionSet( newNeed, std::cerr, 8 ); 503 492 ) 504 inferRecursive( newNeed.begin(), newNeed.end(), newAlt, openVars, decls, newerNeed, /*needParents,*/level+1, indexer, out );493 inferRecursive( newNeed.begin(), newNeed.end(), newAlt, openVars, decls, newerNeed, level+1, indexer, out ); 505 494 return; 506 495 } … … 509 498 ForwardIterator cur = begin++; 510 499 if ( ! cur->second.isUsed ) { 511 inferRecursive( begin, end, newAlt, openVars, decls, newNeed, /*needParents,*/level, indexer, out );500 inferRecursive( begin, end, newAlt, openVars, decls, newNeed, level, indexer, out ); 512 501 return; // xxx - should this continue? previously this wasn't here, and it looks like it should be 513 502 } … … 562 551 } 563 552 564 //AssertionParentSet newNeedParents( needParents );565 // skip repeatingly-self-recursive assertion satisfaction566 // DOESN'T WORK: grandchild nodes conflict with their cousins567 //if ( newNeedParents[ curDecl->get_uniqueId() ][ candDecl->get_uniqueId() ]++ > recursionParentLimit ) continue;568 569 553 Expression *varExpr = data.combine( newerAlt.cvtCost ); 570 delete varExpr->get_result();571 554 varExpr->set_result( adjType->clone() ); 572 555 PRINT( … … 582 565 inferParameters = (*inferParameters)[ id ].inferParams.get(); 583 566 } 584 // XXX: this is a memory leak, but adjType can't be deleted because it might contain assertions 585 (*inferParameters)[ curDecl->get_uniqueId() ] = ParamEntry( candidate->get_uniqueId(), adjType->clone(), curDecl->get_type()->clone(), varExpr ); 586 inferRecursive( begin, end, newerAlt, newOpenVars, newDecls, newerNeed, /*newNeedParents,*/ level, indexer, out ); 587 } else { 588 delete adjType; 567 568 (*inferParameters)[ curDecl->get_uniqueId() ] = ParamEntry( candidate->get_uniqueId(), adjType, curDecl->get_type(), varExpr ); 569 inferRecursive( begin, end, newerAlt, newOpenVars, newDecls, newerNeed, level, indexer, out ); 589 570 } 590 571 } … … 606 587 addToIndexer( have, decls ); 607 588 AssertionSet newNeed; 608 //AssertionParentSet needParents;609 589 PRINT( 610 590 std::cerr << "env is: " << std::endl; … … 613 593 ) 614 594 615 inferRecursive( need.begin(), need.end(), newAlt, openVars, decls, newNeed, /*needParents,*/0, indexer, out );595 inferRecursive( need.begin(), need.end(), newAlt, openVars, decls, newNeed, 0, indexer, out ); 616 596 // PRINT( 617 597 // std::cerr << "declaration 14 is "; … … 634 614 struct ArgPack { 635 615 std::size_t parent; ///< Index of parent pack 636 std::unique_ptr<Expression> expr;///< The argument stored here616 Expression* expr; ///< The argument stored here 637 617 Cost cost; ///< The cost of this argument 638 618 TypeEnvironment env; ///< Environment for this pack … … 646 626 647 627 ArgPack() 648 : parent(0), expr( ), cost(Cost::zero), env(), need(), have(), openVars(), nextArg(0),649 tupleStart(0), nextExpl(0), explAlt(0) {}628 : parent(0), expr(nullptr), cost(Cost::zero), env(), need(), have(), openVars(), 629 nextArg(0), tupleStart(0), nextExpl(0), explAlt(0) {} 650 630 651 631 ArgPack(const TypeEnvironment& env, const AssertionSet& need, const AssertionSet& have, 652 632 const OpenVarSet& openVars) 653 : parent(0), expr( ), cost(Cost::zero), env(env), need(need), have(have),633 : parent(0), expr(nullptr), cost(Cost::zero), env(env), need(need), have(have), 654 634 openVars(openVars), nextArg(0), tupleStart(0), nextExpl(0), explAlt(0) {} 655 635 … … 658 638 unsigned tupleStart = 0, Cost cost = Cost::zero, unsigned nextExpl = 0, 659 639 unsigned explAlt = 0 ) 660 : parent(parent), expr(expr ->clone()), cost(cost), env(move(env)), need(move(need)),640 : parent(parent), expr(expr), cost(cost), env(move(env)), need(move(need)), 661 641 have(move(have)), openVars(move(openVars)), nextArg(nextArg), tupleStart(tupleStart), 662 642 nextExpl(nextExpl), explAlt(explAlt) {} … … 664 644 ArgPack(const ArgPack& o, TypeEnvironment&& env, AssertionSet&& need, AssertionSet&& have, 665 645 OpenVarSet&& openVars, unsigned nextArg, Cost added ) 666 : parent(o.parent), expr(o.expr ? o.expr->clone() : nullptr), cost(o.cost + added),667 env(move(env)), need(move(need)), have(move(have)), openVars(move(openVars)),668 nextArg(nextArg),tupleStart(o.tupleStart), nextExpl(0), explAlt(0) {}646 : parent(o.parent), expr(o.expr), cost(o.cost + added), env(move(env)), 647 need(move(need)), have(move(have)), openVars(move(openVars)), nextArg(nextArg), 648 tupleStart(o.tupleStart), nextExpl(0), explAlt(0) {} 669 649 670 650 /// true iff this pack is in the middle of an exploded argument … … 681 661 std::list<Expression*> exprs; 682 662 const ArgPack* pack = this; 683 if ( expr ) { exprs.push_front( expr .release()); }663 if ( expr ) { exprs.push_front( expr ); } 684 664 while ( pack->tupleStart == 0 ) { 685 665 pack = &packs[pack->parent]; 686 exprs.push_front( pack->expr ->clone());666 exprs.push_front( pack->expr ); 687 667 cost += pack->cost; 688 668 } 689 669 // reset pack to appropriate tuple 690 expr .reset( new TupleExpr( exprs ) );670 expr = new TupleExpr{ exprs }; 691 671 tupleStart = pack->tupleStart - 1; 692 672 parent = pack->parent; … … 741 721 742 722 results.emplace_back( 743 i, expl.exprs[results[i].nextExpl] .get(), copy(results[i].env),723 i, expl.exprs[results[i].nextExpl], copy(results[i].env), 744 724 copy(results[i].need), copy(results[i].have), 745 725 copy(results[i].openVars), nextArg, nTuples, Cost::zero, nextExpl, … … 762 742 newResult.parent = i; 763 743 std::list<Expression*> emptyList; 764 newResult.expr .reset( new TupleExpr( emptyList ) );744 newResult.expr = new TupleExpr{ emptyList }; 765 745 argType = newResult.expr->get_result(); 766 746 } else { … … 769 749 newResult.cost = results[i].cost; 770 750 newResult.tupleStart = results[i].tupleStart; 771 newResult.expr .reset( results[i].expr->clone() );751 newResult.expr = results[i].expr; 772 752 argType = newResult.expr->get_result(); 773 753 … … 819 799 // add new result 820 800 results.emplace_back( 821 i, expl.exprs.front() .get(), move(env), copy(results[i].need),801 i, expl.exprs.front(), move(env), copy(results[i].need), 822 802 copy(results[i].have), move(openVars), nextArg + 1, 823 803 nTuples, expl.cost, expl.exprs.size() == 1 ? 0 : 1, j ); … … 845 825 if ( results[i].hasExpl() ) { 846 826 const ExplodedActual& expl = results[i].getExpl( args ); 847 Expression* expr = expl.exprs[results[i].nextExpl] .get();827 Expression* expr = expl.exprs[results[i].nextExpl]; 848 828 849 829 TypeEnvironment env = results[i].env; … … 916 896 917 897 // consider only first exploded actual 918 Expression* expr = expl.exprs.front() .get();898 Expression* expr = expl.exprs.front(); 919 899 Type* actualType = expr->result->clone(); 920 900 … … 944 924 945 925 template<typename OutputIterator> 946 void AlternativeFinder::Finder::validateFunctionAlternative( const Alternative &func, ArgPack& result,947 const std::vector<ArgPack>& results, OutputIterator out ) {948 ApplicationExpr *appExpr = new ApplicationExpr( func.expr ->clone());926 void AlternativeFinder::Finder::validateFunctionAlternative( const Alternative &func, 927 ArgPack& result, const std::vector<ArgPack>& results, OutputIterator out ) { 928 ApplicationExpr *appExpr = new ApplicationExpr( func.expr ); 949 929 // sum cost and accumulate actuals 950 930 std::list<Expression*>& args = appExpr->args; … … 952 932 const ArgPack* pack = &result; 953 933 while ( pack->expr ) { 954 args.push_front( pack->expr ->clone());934 args.push_front( pack->expr ); 955 935 cost += pack->cost; 956 936 pack = &results[pack->parent]; … … 1019 999 1020 1000 results.emplace_back( 1021 i, expl.exprs[results[i].nextExpl] .get(), copy(results[i].env),1001 i, expl.exprs[results[i].nextExpl], copy(results[i].env), 1022 1002 copy(results[i].need), copy(results[i].have), 1023 1003 copy(results[i].openVars), nextArg, 0, Cost::zero, nextExpl, … … 1055 1035 // add new result 1056 1036 results.emplace_back( 1057 i, expl.exprs.front() .get(), move(env), copy(results[i].need),1037 i, expl.exprs.front(), move(env), copy(results[i].need), 1058 1038 copy(results[i].have), move(openVars), nextArg + 1, 0, 1059 1039 expl.cost, expl.exprs.size() == 1 ? 0 : 1, j ); … … 1089 1069 1090 1070 // find function operators 1091 static NameExpr *opExpr = new NameExpr( "?()" );1071 static auto *opExpr = new_static_root<NameExpr>( "?()" ); 1092 1072 AlternativeFinder funcOpFinder( indexer, env ); 1093 1073 // it's ok if there aren't any defined function ops 1094 funcOpFinder.maybeFind( opExpr );1074 funcOpFinder.maybeFind( opExpr ); 1095 1075 PRINT( 1096 1076 std::cerr << "known function ops:" << std::endl; … … 1121 1101 ) 1122 1102 // check if the type is pointer to function 1123 if ( PointerType *pointer = dynamic_cast< PointerType* >( func->expr-> result->stripReferences() ) ) {1124 if ( FunctionType *function = dynamic_cast< FunctionType* >( pointer-> base) ) {1103 if ( PointerType *pointer = dynamic_cast< PointerType* >( func->expr->get_result()->stripReferences() ) ) { 1104 if ( FunctionType *function = dynamic_cast< FunctionType* >( pointer->get_base() ) ) { 1125 1105 Alternative newFunc( *func ); 1126 1106 referenceToRvalueConversion( newFunc.expr, newFunc.cost ); … … 1128 1108 std::back_inserter( candidates ) ); 1129 1109 } 1130 } else if ( TypeInstType *typeInst = dynamic_cast< TypeInstType* >( func->expr->result->stripReferences() ) ) { // handle ftype (e.g. *? on function pointer) 1131 EqvClass eqvClass; 1132 if ( func->env.lookup( typeInst->name, eqvClass ) && eqvClass.type ) { 1133 if ( FunctionType *function = dynamic_cast< FunctionType* >( eqvClass.type ) ) { 1110 } else if ( TypeInstType *typeInst = dynamic_cast< TypeInstType* >( func->expr->get_result()->stripReferences() ) ) { // handle ftype (e.g. *? on function pointer) 1111 if ( const EqvClass *eqvClass = func->env.lookup( typeInst->get_name() ) ) { 1112 if ( FunctionType *function = dynamic_cast< FunctionType* >( eqvClass->type ) ) { 1134 1113 Alternative newFunc( *func ); 1135 1114 referenceToRvalueConversion( newFunc.expr, newFunc.cost ); … … 1159 1138 // check if type is a pointer to function 1160 1139 if ( PointerType* pointer = dynamic_cast<PointerType*>( 1161 funcOp->expr-> result->stripReferences() ) ) {1140 funcOp->expr->get_result()->stripReferences() ) ) { 1162 1141 if ( FunctionType* function = 1163 dynamic_cast<FunctionType*>( pointer-> base) ) {1142 dynamic_cast<FunctionType*>( pointer->get_base() ) ) { 1164 1143 Alternative newFunc( *funcOp ); 1165 1144 referenceToRvalueConversion( newFunc.expr, newFunc.cost ); … … 1183 1162 PRINT( 1184 1163 ApplicationExpr *appExpr = strict_dynamic_cast< ApplicationExpr* >( withFunc.expr ); 1185 PointerType *pointer = strict_dynamic_cast< PointerType* >( appExpr-> function->result);1186 FunctionType *function = strict_dynamic_cast< FunctionType* >( pointer-> base);1187 std::cerr << "Case +++++++++++++ " << appExpr-> function<< std::endl;1164 PointerType *pointer = strict_dynamic_cast< PointerType* >( appExpr->get_function()->get_result() ); 1165 FunctionType *function = strict_dynamic_cast< FunctionType* >( pointer->get_base() ); 1166 std::cerr << "Case +++++++++++++ " << appExpr->get_function() << std::endl; 1188 1167 std::cerr << "formals are:" << std::endl; 1189 printAll( function-> parameters, std::cerr, 8 );1168 printAll( function->get_parameters(), std::cerr, 8 ); 1190 1169 std::cerr << "actuals are:" << std::endl; 1191 printAll( appExpr-> args, std::cerr, 8 );1170 printAll( appExpr->get_args(), std::cerr, 8 ); 1192 1171 std::cerr << "bindings are:" << std::endl; 1193 1172 withFunc.env.print( std::cerr, 8 ); … … 1230 1209 bool isLvalue( Expression *expr ) { 1231 1210 // xxx - recurse into tuples? 1232 return expr->result && ( expr-> result->get_lvalue() || dynamic_cast< ReferenceType * >( expr->result) );1211 return expr->result && ( expr->get_result()->get_lvalue() || dynamic_cast< ReferenceType * >( expr->get_result() ) ); 1233 1212 } 1234 1213 … … 1239 1218 if ( isLvalue( alt.expr ) ) { 1240 1219 alternatives.push_back( 1241 Alternative{ new AddressExpr( alt.expr ->clone()), alt.env, alt.cost } );1220 Alternative{ new AddressExpr( alt.expr ), alt.env, alt.cost } ); 1242 1221 } // if 1243 1222 } // for … … 1245 1224 1246 1225 void AlternativeFinder::Finder::postvisit( LabelAddressExpr * expr ) { 1247 alternatives.push_back( Alternative{ expr ->clone(), env, Cost::zero } );1226 alternatives.push_back( Alternative{ expr, env, Cost::zero } ); 1248 1227 } 1249 1228 … … 1265 1244 componentExprs.push_back( restructureCast( idx, toType->getComponent( i ), isGenerated ) ); 1266 1245 } 1267 delete argExpr;1268 1246 assert( componentExprs.size() > 0 ); 1269 1247 // produce the tuple of casts … … 1341 1319 for ( Alternative & alt : finder.alternatives ) { 1342 1320 alternatives.push_back( Alternative( 1343 new VirtualCastExpr( alt.expr ->clone(), castExpr->get_result()->clone() ),1321 new VirtualCastExpr( alt.expr, castExpr->get_result()->clone() ), 1344 1322 alt.env, alt.cost ) ); 1323 } 1324 } 1325 1326 namespace { 1327 /// Gets name from untyped member expression (member must be NameExpr) 1328 const std::string& get_member_name( UntypedMemberExpr *memberExpr ) { 1329 NameExpr * nameExpr = dynamic_cast< NameExpr * >( memberExpr->get_member() ); 1330 assert( nameExpr ); 1331 return nameExpr->get_name(); 1345 1332 } 1346 1333 } … … 1354 1341 Expression * aggrExpr = agg->expr->clone(); 1355 1342 referenceToRvalueConversion( aggrExpr, cost ); 1356 std::unique_ptr<Expression> guard( aggrExpr );1357 1343 1358 1344 // find member of the given type 1359 1345 if ( StructInstType *structInst = dynamic_cast< StructInstType* >( aggrExpr->get_result() ) ) { 1360 addAggMembers( structInst, aggrExpr, cost, agg->env, memberExpr->get_member() );1346 addAggMembers( structInst, aggrExpr, cost, agg->env, get_member_name(memberExpr) ); 1361 1347 } else if ( UnionInstType *unionInst = dynamic_cast< UnionInstType* >( aggrExpr->get_result() ) ) { 1362 addAggMembers( unionInst, aggrExpr, cost, agg->env, memberExpr->get_member() );1348 addAggMembers( unionInst, aggrExpr, cost, agg->env, get_member_name(memberExpr) ); 1363 1349 } else if ( TupleType * tupleType = dynamic_cast< TupleType * >( aggrExpr->get_result() ) ) { 1364 1350 addTupleMembers( tupleType, aggrExpr, cost, agg->env, memberExpr->get_member() ); … … 1368 1354 1369 1355 void AlternativeFinder::Finder::postvisit( MemberExpr *memberExpr ) { 1370 alternatives.push_back( Alternative( memberExpr ->clone(), env, Cost::zero ) );1356 alternatives.push_back( Alternative( memberExpr, env, Cost::zero ) ); 1371 1357 } 1372 1358 … … 1399 1385 1400 1386 void AlternativeFinder::Finder::postvisit( ConstantExpr *constantExpr ) { 1401 alternatives.push_back( Alternative( constantExpr ->clone(), env, Cost::zero ) );1387 alternatives.push_back( Alternative( constantExpr, env, Cost::zero ) ); 1402 1388 } 1403 1389 … … 1419 1405 Alternative &choice = winners.front(); 1420 1406 referenceToRvalueConversion( choice.expr, choice.cost ); 1421 alternatives.push_back( Alternative( new SizeofExpr( choice.expr ->clone()), choice.env, Cost::zero ) );1407 alternatives.push_back( Alternative( new SizeofExpr( choice.expr ), choice.env, Cost::zero ) ); 1422 1408 } // if 1423 1409 } … … 1440 1426 Alternative &choice = winners.front(); 1441 1427 referenceToRvalueConversion( choice.expr, choice.cost ); 1442 alternatives.push_back( Alternative( new AlignofExpr( choice.expr ->clone()), choice.env, Cost::zero ) );1428 alternatives.push_back( Alternative( new AlignofExpr( choice.expr ), choice.env, Cost::zero ) ); 1443 1429 } // if 1444 1430 } … … 1469 1455 1470 1456 void AlternativeFinder::Finder::postvisit( OffsetofExpr *offsetofExpr ) { 1471 alternatives.push_back( Alternative( offsetofExpr ->clone(), env, Cost::zero ) );1457 alternatives.push_back( Alternative( offsetofExpr, env, Cost::zero ) ); 1472 1458 } 1473 1459 1474 1460 void AlternativeFinder::Finder::postvisit( OffsetPackExpr *offsetPackExpr ) { 1475 alternatives.push_back( Alternative( offsetPackExpr ->clone(), env, Cost::zero ) );1461 alternatives.push_back( Alternative( offsetPackExpr, env, Cost::zero ) ); 1476 1462 } 1477 1463 … … 1551 1537 compositeEnv.simpleCombine( second.env ); 1552 1538 1553 LogicalExpr *newExpr = new LogicalExpr( first.expr ->clone(), second.expr->clone(), logicalExpr->get_isAnd() );1539 LogicalExpr *newExpr = new LogicalExpr( first.expr, second.expr, logicalExpr->get_isAnd() ); 1554 1540 alternatives.push_back( Alternative( newExpr, compositeEnv, first.cost + second.cost ) ); 1555 1541 } … … 1584 1570 Type* commonType = nullptr; 1585 1571 if ( unify( second.expr->result, third.expr->result, newAlt.env, needAssertions, haveAssertions, openVars, indexer, commonType ) ) { 1586 ConditionalExpr *newExpr = new ConditionalExpr( first.expr ->clone(), second.expr->clone(), third.expr->clone());1572 ConditionalExpr *newExpr = new ConditionalExpr( first.expr, second.expr, third.expr ); 1587 1573 newExpr->result = commonType ? commonType : second.expr->result->clone(); 1588 1574 // convert both options to the conditional result type … … 1603 1589 secondFinder.findWithAdjustment( commaExpr->get_arg2() ); 1604 1590 for ( const Alternative & alt : secondFinder.alternatives ) { 1605 alternatives.push_back( Alternative( new CommaExpr( newFirstArg ->clone(), alt.expr->clone()), alt.env, alt.cost ) );1591 alternatives.push_back( Alternative( new CommaExpr( newFirstArg, alt.expr ), alt.env, alt.cost ) ); 1606 1592 } // for 1607 delete newFirstArg;1608 1593 } 1609 1594 … … 1626 1611 Type* commonType = nullptr; 1627 1612 if ( unify( first.expr->result, second.expr->result, newAlt.env, needAssertions, haveAssertions, openVars, indexer, commonType ) ) { 1628 RangeExpr * newExpr = new RangeExpr( first.expr ->clone(), second.expr->clone());1613 RangeExpr * newExpr = new RangeExpr( first.expr, second.expr ); 1629 1614 newExpr->result = commonType ? commonType : first.expr->result->clone(); 1630 1615 newAlt.expr = newExpr; … … 1654 1639 1655 1640 void AlternativeFinder::Finder::postvisit( TupleExpr *tupleExpr ) { 1656 alternatives.push_back( Alternative( tupleExpr ->clone(), env, Cost::zero ) );1641 alternatives.push_back( Alternative( tupleExpr, env, Cost::zero ) ); 1657 1642 } 1658 1643 1659 1644 void AlternativeFinder::Finder::postvisit( ImplicitCopyCtorExpr * impCpCtorExpr ) { 1660 alternatives.push_back( Alternative( impCpCtorExpr ->clone(), env, Cost::zero ) );1645 alternatives.push_back( Alternative( impCpCtorExpr, env, Cost::zero ) ); 1661 1646 } 1662 1647 … … 1667 1652 finder.findWithoutPrune( ctorExpr->get_callExpr() ); 1668 1653 for ( Alternative & alt : finder.alternatives ) { 1669 alternatives.push_back( Alternative( new ConstructorExpr( alt.expr ->clone()), alt.env, alt.cost ) );1654 alternatives.push_back( Alternative( new ConstructorExpr( alt.expr ), alt.env, alt.cost ) ); 1670 1655 } 1671 1656 } 1672 1657 1673 1658 void AlternativeFinder::Finder::postvisit( TupleIndexExpr *tupleExpr ) { 1674 alternatives.push_back( Alternative( tupleExpr ->clone(), env, Cost::zero ) );1659 alternatives.push_back( Alternative( tupleExpr, env, Cost::zero ) ); 1675 1660 } 1676 1661 1677 1662 void AlternativeFinder::Finder::postvisit( TupleAssignExpr *tupleAssignExpr ) { 1678 alternatives.push_back( Alternative( tupleAssignExpr ->clone(), env, Cost::zero ) );1663 alternatives.push_back( Alternative( tupleAssignExpr, env, Cost::zero ) ); 1679 1664 } 1680 1665 … … 1684 1669 for ( Alternative & alt : finder.alternatives ) { 1685 1670 // ensure that the id is passed on to the UniqueExpr alternative so that the expressions are "linked" 1686 UniqueExpr * newUnqExpr = new UniqueExpr( alt.expr ->clone(), unqExpr->get_id() );1671 UniqueExpr * newUnqExpr = new UniqueExpr( alt.expr, unqExpr->get_id() ); 1687 1672 alternatives.push_back( Alternative( newUnqExpr, alt.env, alt.cost ) ); 1688 1673 } … … 1735 1720 // count one safe conversion for each value that is thrown away 1736 1721 thisCost.incSafe( discardedValues ); 1737 Alternative newAlt( new InitExpr( restructureCast( alt.expr ->clone(), toType, true ), initAlt.designation->clone()), newEnv, alt.cost, thisCost );1722 Alternative newAlt( new InitExpr( restructureCast( alt.expr, toType, true ), initAlt.designation ), newEnv, alt.cost, thisCost ); 1738 1723 inferParameters( needAssertions, haveAssertions, newAlt, openVars, back_inserter( candidates ) ); 1739 1724 }
Note:
See TracChangeset
for help on using the changeset viewer.