Changes in / [a1a17a74:2c88368]
- Location:
- src
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
src/ResolvExpr/AlternativeFinder.cc
ra1a17a74 r2c88368 698 698 const ExplodedArgs& args, std::vector<ArgPack>& results, std::size_t& genStart, 699 699 const SymTab::Indexer& indexer, unsigned nTuples = 0 ) { 700 if ( TupleType * tupleType = dynamic_cast<TupleType*>( formalType ) ) {700 if ( TupleType * tupleType = dynamic_cast<TupleType*>( formalType ) ) { 701 701 // formalType is a TupleType - group actuals into a TupleExpr 702 702 ++nTuples; 703 703 for ( Type* type : *tupleType ) { 704 704 // xxx - dropping initializer changes behaviour from previous, but seems correct 705 // ^^^ need to handle the case where a tuple has a default argument 705 706 if ( ! instantiateArgument( 706 707 type, nullptr, args, results, genStart, indexer, nTuples ) ) … … 713 714 } 714 715 return true; 715 } else if ( TypeInstType * ttype = Tuples::isTtype( formalType ) ) {716 } else if ( TypeInstType * ttype = Tuples::isTtype( formalType ) ) { 716 717 // formalType is a ttype, consumes all remaining arguments 717 718 // xxx - mixing default arguments with variadic?? … … 916 917 // consider only first exploded actual 917 918 Expression* expr = expl.exprs.front().get(); 918 Type* actualType = expr-> get_result()->clone();919 Type* actualType = expr->result->clone(); 919 920 920 921 PRINT( … … 947 948 ApplicationExpr *appExpr = new ApplicationExpr( func.expr->clone() ); 948 949 // sum cost and accumulate actuals 949 std::list<Expression*>& args = appExpr-> get_args();950 std::list<Expression*>& args = appExpr->args; 950 951 Cost cost = func.cost; 951 952 const ArgPack* pack = &result; … … 974 975 // add all type variables as open variables now so that those not used in the parameter 975 976 // list are still considered open. 976 funcEnv.add( funcType-> get_forall());977 978 if ( targetType && ! targetType->isVoid() && ! funcType-> get_returnVals().empty() ) {977 funcEnv.add( funcType->forall ); 978 979 if ( targetType && ! targetType->isVoid() && ! funcType->returnVals.empty() ) { 979 980 // attempt to narrow based on expected target type 980 Type * returnType = funcType-> get_returnVals().front()->get_type();981 Type * returnType = funcType->returnVals.front()->get_type(); 981 982 if ( ! unify( returnType, targetType, funcEnv, funcNeed, funcHave, funcOpenVars, 982 983 indexer ) ) { … … 991 992 std::size_t genStart = 0; 992 993 993 for ( DeclarationWithType* formal : funcType-> get_parameters()) {994 for ( DeclarationWithType* formal : funcType->parameters ) { 994 995 ObjectDecl* obj = strict_dynamic_cast< ObjectDecl* >( formal ); 995 996 if ( ! instantiateArgument( 996 obj-> get_type(), obj->get_init(), args, results, genStart, indexer ) )997 obj->type, obj->init, args, results, genStart, indexer ) ) 997 998 return; 998 999 } … … 1075 1076 void AlternativeFinder::Finder::postvisit( UntypedExpr *untypedExpr ) { 1076 1077 AlternativeFinder funcFinder( indexer, env ); 1077 funcFinder.findWithAdjustment( untypedExpr-> get_function());1078 funcFinder.findWithAdjustment( untypedExpr->function ); 1078 1079 // if there are no function alternatives, then proceeding is a waste of time. 1079 1080 if ( funcFinder.alternatives.empty() ) return; … … 1120 1121 ) 1121 1122 // check if the type is pointer to function 1122 if ( PointerType *pointer = dynamic_cast< PointerType* >( func->expr-> get_result()->stripReferences() ) ) {1123 if ( FunctionType *function = dynamic_cast< FunctionType* >( pointer-> get_base()) ) {1123 if ( PointerType *pointer = dynamic_cast< PointerType* >( func->expr->result->stripReferences() ) ) { 1124 if ( FunctionType *function = dynamic_cast< FunctionType* >( pointer->base ) ) { 1124 1125 Alternative newFunc( *func ); 1125 1126 referenceToRvalueConversion( newFunc.expr, newFunc.cost ); … … 1127 1128 std::back_inserter( candidates ) ); 1128 1129 } 1129 } else if ( TypeInstType *typeInst = dynamic_cast< TypeInstType* >( func->expr-> get_result()->stripReferences() ) ) { // handle ftype (e.g. *? on function pointer)1130 } else if ( TypeInstType *typeInst = dynamic_cast< TypeInstType* >( func->expr->result->stripReferences() ) ) { // handle ftype (e.g. *? on function pointer) 1130 1131 EqvClass eqvClass; 1131 if ( func->env.lookup( typeInst-> get_name(), eqvClass ) && eqvClass.type ) {1132 if ( func->env.lookup( typeInst->name, eqvClass ) && eqvClass.type ) { 1132 1133 if ( FunctionType *function = dynamic_cast< FunctionType* >( eqvClass.type ) ) { 1133 1134 Alternative newFunc( *func ); … … 1158 1159 // check if type is a pointer to function 1159 1160 if ( PointerType* pointer = dynamic_cast<PointerType*>( 1160 funcOp->expr-> get_result()->stripReferences() ) ) {1161 funcOp->expr->result->stripReferences() ) ) { 1161 1162 if ( FunctionType* function = 1162 dynamic_cast<FunctionType*>( pointer-> get_base()) ) {1163 dynamic_cast<FunctionType*>( pointer->base ) ) { 1163 1164 Alternative newFunc( *funcOp ); 1164 1165 referenceToRvalueConversion( newFunc.expr, newFunc.cost ); … … 1182 1183 PRINT( 1183 1184 ApplicationExpr *appExpr = strict_dynamic_cast< ApplicationExpr* >( withFunc.expr ); 1184 PointerType *pointer = strict_dynamic_cast< PointerType* >( appExpr-> get_function()->get_result());1185 FunctionType *function = strict_dynamic_cast< FunctionType* >( pointer-> get_base());1186 std::cerr << "Case +++++++++++++ " << appExpr-> get_function()<< std::endl;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; 1187 1188 std::cerr << "formals are:" << std::endl; 1188 printAll( function-> get_parameters(), std::cerr, 8 );1189 printAll( function->parameters, std::cerr, 8 ); 1189 1190 std::cerr << "actuals are:" << std::endl; 1190 printAll( appExpr-> get_args(), std::cerr, 8 );1191 printAll( appExpr->args, std::cerr, 8 ); 1191 1192 std::cerr << "bindings are:" << std::endl; 1192 1193 withFunc.env.print( std::cerr, 8 ); … … 1229 1230 bool isLvalue( Expression *expr ) { 1230 1231 // xxx - recurse into tuples? 1231 return expr->result && ( expr-> get_result()->get_lvalue() || dynamic_cast< ReferenceType * >( expr->get_result()) );1232 return expr->result && ( expr->result->get_lvalue() || dynamic_cast< ReferenceType * >( expr->result ) ); 1232 1233 } 1233 1234 … … 1291 1292 AssertionSet needAssertions, haveAssertions; 1292 1293 OpenVarSet openVars; 1294 1295 alt.env.extractOpenVars( openVars ); 1293 1296 1294 1297 // It's possible that a cast can throw away some values in a multiply-valued expression. (An example is a … … 1709 1712 AlternativeFinder finder( indexer, env ); 1710 1713 finder.targetType = toType; 1711 finder.findWithAdjustment( initExpr-> get_expr());1714 finder.findWithAdjustment( initExpr->expr ); 1712 1715 for ( Alternative & alt : finder.get_alternatives() ) { 1713 1716 TypeEnvironment newEnv( alt.env ); … … 1716 1719 PRINT( 1717 1720 std::cerr << " @ " << toType << " " << initAlt.designation << std::endl; 1718 1721 ) 1719 1722 // It's possible that a cast can throw away some values in a multiply-valued expression. (An example is a 1720 1723 // cast-to-void, which casts from one value to zero.) Figure out the prefix of the subexpression results 1721 1724 // that are cast directly. The candidate is invalid if it has fewer results than there are types to cast 1722 1725 // to. 1723 int discardedValues = alt.expr-> get_result()->size() - toType->size();1726 int discardedValues = alt.expr->result->size() - toType->size(); 1724 1727 if ( discardedValues < 0 ) continue; 1725 1728 // xxx - may need to go into tuple types and extract relevant types and use unifyList. Note that currently, this does not … … 1728 1731 unify( toType, alt.expr->result, newEnv, needAssertions, haveAssertions, openVars, indexer ); // xxx - do some inspecting on this line... why isn't result bound to initAlt.type?? 1729 1732 1730 Cost thisCost = castCost( alt.expr-> get_result(), toType, indexer, newEnv );1733 Cost thisCost = castCost( alt.expr->result, toType, indexer, newEnv ); 1731 1734 if ( thisCost != Cost::infinity ) { 1732 1735 // count one safe conversion for each value that is thrown away -
src/Tuples/TupleAssignment.cc
ra1a17a74 r2c88368 231 231 232 232 ResolvExpr::AlternativeFinder finder{ currentFinder.get_indexer(), 233 currentFinder.get_environ() }; 233 matcher->compositeEnv }; 234 234 235 try { 235 236 finder.findWithAdjustment(*i); … … 349 350 ltmp.push_back( lobj ); 350 351 rtmp.push_back( robj ); 352 353 // resolve the cast expression so that rhsAlt return type is bound by the cast type as needed, and transfer the resulting environment 354 ResolvExpr::AlternativeFinder finder{ spotter.currentFinder.get_indexer(), compositeEnv }; 355 finder.findWithAdjustment( rhsAlt.expr ); 356 assert( finder.get_alternatives().size() == 1 ); 357 compositeEnv = std::move( finder.get_alternatives().front().env ); 351 358 } 352 359 tmpDecls.splice( tmpDecls.end(), ltmp );
Note: See TracChangeset
for help on using the changeset viewer.