Changeset 954c954 for src/ResolvExpr
- Timestamp:
- Sep 24, 2020, 3:56:16 PM (4 years ago)
- Branches:
- ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, master, new-ast-unique-expr, pthread-emulation, qualifiedEnum
- Children:
- 6cc913e
- Parents:
- eccb14d
- Location:
- src/ResolvExpr
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
src/ResolvExpr/CandidateFinder.cpp
reccb14d r954c954 188 188 189 189 // mark conversion cost and also specialization cost of param type 190 const ast::Type * paramType = (*param)->get_type();190 // const ast::Type * paramType = (*param)->get_type(); 191 191 cand->expr = ast::mutate_field_index( 192 192 appExpr, &ast::ApplicationExpr::args, i, 193 193 computeExpressionConversionCost( 194 args[i], paramType, symtab, cand->env, convCost ) );195 convCost.decSpec( specCost( paramType) );194 args[i], *param, symtab, cand->env, convCost ) ); 195 convCost.decSpec( specCost( *param ) ); 196 196 ++param; // can't be in for-loop update because of the continue 197 197 } … … 698 698 if ( targetType && ! targetType->isVoid() && ! funcType->returns.empty() ) { 699 699 // attempt to narrow based on expected target type 700 const ast::Type * returnType = funcType->returns.front() ->get_type();700 const ast::Type * returnType = funcType->returns.front(); 701 701 if ( ! unify( 702 702 returnType, targetType, funcEnv, funcNeed, funcHave, funcOpen, symtab ) … … 712 712 std::size_t genStart = 0; 713 713 714 for ( const ast::DeclWithType * param : funcType->params ) { 715 auto obj = strict_dynamic_cast< const ast::ObjectDecl * >( param ); 714 // xxx - how to handle default arg after change to ftype representation? 715 if (const ast::VariableExpr * varExpr = func->expr.as<ast::VariableExpr>()) { 716 if (const ast::FunctionDecl * funcDecl = varExpr->var.as<ast::FunctionDecl>()) { 717 // function may have default args only if directly calling by name 718 // must use types on candidate however, due to RenameVars substitution 719 auto nParams = funcType->params.size(); 720 721 for (size_t i=0; i<nParams; ++i) { 722 auto obj = funcDecl->params[i].strict_as<ast::ObjectDecl>(); 723 if (!instantiateArgument( 724 funcType->params[i], obj->init, args, results, genStart, symtab)) return; 725 } 726 goto endMatch; 727 } 728 } 729 for ( const auto & param : funcType->params ) { 716 730 // Try adding the arguments corresponding to the current parameter to the existing 717 731 // matches 732 // no default args for indirect calls 718 733 if ( ! instantiateArgument( 719 obj->type, obj->init, args, results, genStart, symtab ) ) return; 720 } 721 734 param, nullptr, args, results, genStart, symtab ) ) return; 735 } 736 737 endMatch: 722 738 if ( funcType->isVarArgs ) { 723 739 // append any unused arguments to vararg pack -
src/ResolvExpr/CurrentObject.cc
reccb14d r954c954 594 594 class SimpleIterator final : public MemberIterator { 595 595 CodeLocation location; 596 readonly< Type >type = nullptr;596 const Type * type = nullptr; 597 597 public: 598 598 SimpleIterator( const CodeLocation & loc, const Type * t ) : location( loc ), type( t ) {} … … 630 630 class ArrayIterator final : public MemberIterator { 631 631 CodeLocation location; 632 readonly< ArrayType >array = nullptr;633 readonly< Type >base = nullptr;632 const ArrayType * array = nullptr; 633 const Type * base = nullptr; 634 634 size_t index = 0; 635 635 size_t size = 0; -
src/ResolvExpr/Resolver.cc
reccb14d r954c954 1223 1223 template<typename Iter> 1224 1224 inline bool nextMutex( Iter & it, const Iter & end ) { 1225 while ( it != end && ! (*it)-> get_type()->is_mutex() ) { ++it; }1225 while ( it != end && ! (*it)->is_mutex() ) { ++it; } 1226 1226 return it != end; 1227 1227 } … … 1638 1638 // Check if the argument matches the parameter type in the current 1639 1639 // scope 1640 ast::ptr< ast::Type > paramType = (*param)->get_type();1640 // ast::ptr< ast::Type > paramType = (*param)->get_type(); 1641 1641 if ( 1642 1642 ! unify( 1643 arg->expr->result, paramType, resultEnv, need, have, open,1643 arg->expr->result, *param, resultEnv, need, have, open, 1644 1644 symtab ) 1645 1645 ) { … … 1648 1648 ss << "candidate function not viable: no known conversion " 1649 1649 "from '"; 1650 ast::print( ss, (*param)->get_type());1650 ast::print( ss, *param ); 1651 1651 ss << "' to '"; 1652 1652 ast::print( ss, arg->expr->result ); -
src/ResolvExpr/SatisfyAssertions.cpp
reccb14d r954c954 318 318 if ( ! func ) continue; 319 319 320 for ( const a st::DeclWithType *param : func->params ) {321 cost.decSpec( specCost( param ->get_type()) );320 for ( const auto & param : func->params ) { 321 cost.decSpec( specCost( param ) ); 322 322 } 323 323 -
src/ResolvExpr/SpecCost.cc
reccb14d r954c954 178 178 void previsit( const ast::FunctionType * fty ) { 179 179 int minCount = std::numeric_limits<int>::max(); 180 updateMinimumPresent( minCount, fty->params, decl_type);181 updateMinimumPresent( minCount, fty->returns, decl_type);180 updateMinimumPresent( minCount, fty->params, type_deref ); 181 updateMinimumPresent( minCount, fty->returns, type_deref ); 182 182 // Add another level to minCount if set. 183 183 count = toNoneOrInc( minCount ); -
src/ResolvExpr/Unify.cc
reccb14d r954c954 395 395 396 396 template< typename Iterator1, typename Iterator2 > 397 bool unify DeclList( Iterator1 list1Begin, Iterator1 list1End, Iterator2 list2Begin, Iterator2 list2End, TypeEnvironment &env, AssertionSet &needAssertions, AssertionSet &haveAssertions, const OpenVarSet &openVars, const SymTab::Indexer &indexer ) {397 bool unifyTypeList( Iterator1 list1Begin, Iterator1 list1End, Iterator2 list2Begin, Iterator2 list2End, TypeEnvironment &env, AssertionSet &needAssertions, AssertionSet &haveAssertions, const OpenVarSet &openVars, const SymTab::Indexer &indexer ) { 398 398 auto get_type = [](DeclarationWithType * dwt){ return dwt->get_type(); }; 399 399 for ( ; list1Begin != list1End && list2Begin != list2End; ++list1Begin, ++list2Begin ) { … … 489 489 || flatOther->isTtype() 490 490 ) { 491 if ( unify DeclList( flatFunc->parameters.begin(), flatFunc->parameters.end(), flatOther->parameters.begin(), flatOther->parameters.end(), env, needAssertions, haveAssertions, openVars, indexer ) ) {492 if ( unify DeclList( flatFunc->returnVals.begin(), flatFunc->returnVals.end(), flatOther->returnVals.begin(), flatOther->returnVals.end(), env, needAssertions, haveAssertions, openVars, indexer ) ) {491 if ( unifyTypeList( flatFunc->parameters.begin(), flatFunc->parameters.end(), flatOther->parameters.begin(), flatOther->parameters.end(), env, needAssertions, haveAssertions, openVars, indexer ) ) { 492 if ( unifyTypeList( flatFunc->returnVals.begin(), flatFunc->returnVals.end(), flatOther->returnVals.begin(), flatOther->returnVals.end(), env, needAssertions, haveAssertions, openVars, indexer ) ) { 493 493 494 494 // the original types must be used in mark assertions, since pointer comparisons are used … … 784 784 785 785 /// returns flattened version of `src` 786 static std::vector< ast::ptr< ast:: DeclWithType > > flattenList(787 const std::vector< ast::ptr< ast:: DeclWithType > > & src, ast::TypeEnvironment & env786 static std::vector< ast::ptr< ast::Type > > flattenList( 787 const std::vector< ast::ptr< ast::Type > > & src, ast::TypeEnvironment & env 788 788 ) { 789 std::vector< ast::ptr< ast:: DeclWithType > > dst;789 std::vector< ast::ptr< ast::Type > > dst; 790 790 dst.reserve( src.size() ); 791 for ( const a st::DeclWithType *d : src ) {791 for ( const auto & d : src ) { 792 792 ast::Pass<TtypeExpander_new> expander{ env }; 793 793 // TtypeExpander pass is impure (may mutate nodes in place) 794 794 // need to make nodes shared to prevent accidental mutation 795 ast::ptr<ast:: DeclWithType> dc = d->accept(expander);796 auto types = flatten( dc ->get_type());795 ast::ptr<ast::Type> dc = d->accept(expander); 796 auto types = flatten( dc ); 797 797 for ( ast::ptr< ast::Type > & t : types ) { 798 798 // outermost const, volatile, _Atomic qualifiers in parameters should not play … … 803 803 // requirements than a non-mutex function 804 804 remove_qualifiers( t, ast::CV::Const | ast::CV::Volatile | ast::CV::Atomic ); 805 dst.emplace_back( new ast::ObjectDecl{ dc->location, "", t });805 dst.emplace_back( t ); 806 806 } 807 807 } … … 811 811 /// Creates a tuple type based on a list of DeclWithType 812 812 template< typename Iter > 813 static ast::ptr< ast::Type > tupleFrom Decls( Iter crnt, Iter end ) {813 static ast::ptr< ast::Type > tupleFromTypes( Iter crnt, Iter end ) { 814 814 std::vector< ast::ptr< ast::Type > > types; 815 815 while ( crnt != end ) { 816 816 // it is guaranteed that a ttype variable will be bound to a flat tuple, so ensure 817 817 // that this results in a flat tuple 818 flatten( (*crnt)->get_type(), types );818 flatten( *crnt, types ); 819 819 820 820 ++crnt; … … 825 825 826 826 template< typename Iter > 827 static bool unify DeclList(827 static bool unifyTypeList( 828 828 Iter crnt1, Iter end1, Iter crnt2, Iter end2, ast::TypeEnvironment & env, 829 829 ast::AssertionSet & need, ast::AssertionSet & have, const ast::OpenVarSet & open, … … 831 831 ) { 832 832 while ( crnt1 != end1 && crnt2 != end2 ) { 833 const ast::Type * t1 = (*crnt1)->get_type();834 const ast::Type * t2 = (*crnt2)->get_type();833 const ast::Type * t1 = *crnt1; 834 const ast::Type * t2 = *crnt2; 835 835 bool isTuple1 = Tuples::isTtype( t1 ); 836 836 bool isTuple2 = Tuples::isTtype( t2 ); … … 840 840 // combine remainder of list2, then unify 841 841 return unifyExact( 842 t1, tupleFrom Decls( crnt2, end2 ), env, need, have, open,842 t1, tupleFromTypes( crnt2, end2 ), env, need, have, open, 843 843 noWiden(), symtab ); 844 844 } else if ( ! isTuple1 && isTuple2 ) { 845 845 // combine remainder of list1, then unify 846 846 return unifyExact( 847 tupleFrom Decls( crnt1, end1 ), t2, env, need, have, open,847 tupleFromTypes( crnt1, end1 ), t2, env, need, have, open, 848 848 noWiden(), symtab ); 849 849 } … … 860 860 if ( crnt1 != end1 ) { 861 861 // try unifying empty tuple with ttype 862 const ast::Type * t1 = (*crnt1)->get_type();862 const ast::Type * t1 = *crnt1; 863 863 if ( ! Tuples::isTtype( t1 ) ) return false; 864 864 return unifyExact( 865 t1, tupleFrom Decls( crnt2, end2 ), env, need, have, open,865 t1, tupleFromTypes( crnt2, end2 ), env, need, have, open, 866 866 noWiden(), symtab ); 867 867 } else if ( crnt2 != end2 ) { 868 868 // try unifying empty tuple with ttype 869 const ast::Type * t2 = (*crnt2)->get_type();869 const ast::Type * t2 = *crnt2; 870 870 if ( ! Tuples::isTtype( t2 ) ) return false; 871 871 return unifyExact( 872 tupleFrom Decls( crnt1, end1 ), t2, env, need, have, open,872 tupleFromTypes( crnt1, end1 ), t2, env, need, have, open, 873 873 noWiden(), symtab ); 874 874 } … … 877 877 } 878 878 879 static bool unify DeclList(880 const std::vector< ast::ptr< ast:: DeclWithType > > & list1,881 const std::vector< ast::ptr< ast:: DeclWithType > > & list2,879 static bool unifyTypeList( 880 const std::vector< ast::ptr< ast::Type > > & list1, 881 const std::vector< ast::ptr< ast::Type > > & list2, 882 882 ast::TypeEnvironment & env, ast::AssertionSet & need, ast::AssertionSet & have, 883 883 const ast::OpenVarSet & open, const ast::SymbolTable & symtab 884 884 ) { 885 return unify DeclList(885 return unifyTypeList( 886 886 list1.begin(), list1.end(), list2.begin(), list2.end(), env, need, have, open, 887 887 symtab ); … … 928 928 ) return; 929 929 930 if ( ! unify DeclList( params, params2, tenv, need, have, open, symtab ) ) return;931 if ( ! unify DeclList(930 if ( ! unifyTypeList( params, params2, tenv, need, have, open, symtab ) ) return; 931 if ( ! unifyTypeList( 932 932 func->returns, func2->returns, tenv, need, have, open, symtab ) ) return; 933 933 … … 1232 1232 ast::ptr<ast::Type> extractResultType( const ast::FunctionType * func ) { 1233 1233 if ( func->returns.empty() ) return new ast::VoidType{}; 1234 if ( func->returns.size() == 1 ) return func->returns[0] ->get_type();1234 if ( func->returns.size() == 1 ) return func->returns[0]; 1235 1235 1236 1236 std::vector<ast::ptr<ast::Type>> tys; 1237 for ( const a st::DeclWithType *decl : func->returns ) {1238 tys.emplace_back( decl ->get_type());1237 for ( const auto & decl : func->returns ) { 1238 tys.emplace_back( decl ); 1239 1239 } 1240 1240 return new ast::TupleType{ std::move(tys) };
Note: See TracChangeset
for help on using the changeset viewer.