- Timestamp:
- Nov 22, 2017, 5:55:13 PM (7 years ago)
- Branches:
- ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, deferred_resn, demangler, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, with_gc
- Children:
- 62194cb, 88ef2af
- Parents:
- c2c6177
- git-author:
- Aaron Moss <a3moss@…> (11/22/17 17:27:05)
- git-committer:
- Aaron Moss <a3moss@…> (11/22/17 17:55:13)
- Location:
- src
- Files:
-
- 2 added
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
src/Makefile.in
rc2c6177 ra8b27c6 210 210 ResolvExpr/driver_cfa_cpp-TypeEnvironment.$(OBJEXT) \ 211 211 ResolvExpr/driver_cfa_cpp-CurrentObject.$(OBJEXT) \ 212 ResolvExpr/driver_cfa_cpp-ExplodedActual.$(OBJEXT) \ 212 213 SymTab/driver_cfa_cpp-Indexer.$(OBJEXT) \ 213 214 SymTab/driver_cfa_cpp-Mangler.$(OBJEXT) \ … … 511 512 ResolvExpr/FindOpenVars.cc ResolvExpr/PolyCost.cc \ 512 513 ResolvExpr/Occurs.cc ResolvExpr/TypeEnvironment.cc \ 513 ResolvExpr/CurrentObject.cc SymTab/Indexer.cc \ 514 SymTab/Mangler.cc SymTab/Validate.cc SymTab/FixFunction.cc \ 515 SymTab/ImplementationType.cc SymTab/TypeEquality.cc \ 516 SymTab/Autogen.cc SynTree/Type.cc SynTree/VoidType.cc \ 517 SynTree/BasicType.cc SynTree/PointerType.cc \ 518 SynTree/ArrayType.cc SynTree/ReferenceType.cc \ 519 SynTree/FunctionType.cc SynTree/ReferenceToType.cc \ 520 SynTree/TupleType.cc SynTree/TypeofType.cc SynTree/AttrType.cc \ 514 ResolvExpr/CurrentObject.cc ResolvExpr/ExplodedActual.cc \ 515 SymTab/Indexer.cc SymTab/Mangler.cc SymTab/Validate.cc \ 516 SymTab/FixFunction.cc SymTab/ImplementationType.cc \ 517 SymTab/TypeEquality.cc SymTab/Autogen.cc SynTree/Type.cc \ 518 SynTree/VoidType.cc SynTree/BasicType.cc \ 519 SynTree/PointerType.cc SynTree/ArrayType.cc \ 520 SynTree/ReferenceType.cc SynTree/FunctionType.cc \ 521 SynTree/ReferenceToType.cc SynTree/TupleType.cc \ 522 SynTree/TypeofType.cc SynTree/AttrType.cc \ 521 523 SynTree/VarArgsType.cc SynTree/ZeroOneType.cc \ 522 524 SynTree/Constant.cc SynTree/Expression.cc SynTree/TupleExpr.cc \ … … 825 827 ResolvExpr/$(am__dirstamp) \ 826 828 ResolvExpr/$(DEPDIR)/$(am__dirstamp) 829 ResolvExpr/driver_cfa_cpp-ExplodedActual.$(OBJEXT): \ 830 ResolvExpr/$(am__dirstamp) \ 831 ResolvExpr/$(DEPDIR)/$(am__dirstamp) 827 832 SymTab/$(am__dirstamp): 828 833 @$(MKDIR_P) SymTab … … 1022 1027 @AMDEP_TRUE@@am__include@ @am__quote@ResolvExpr/$(DEPDIR)/driver_cfa_cpp-ConversionCost.Po@am__quote@ 1023 1028 @AMDEP_TRUE@@am__include@ @am__quote@ResolvExpr/$(DEPDIR)/driver_cfa_cpp-CurrentObject.Po@am__quote@ 1029 @AMDEP_TRUE@@am__include@ @am__quote@ResolvExpr/$(DEPDIR)/driver_cfa_cpp-ExplodedActual.Po@am__quote@ 1024 1030 @AMDEP_TRUE@@am__include@ @am__quote@ResolvExpr/$(DEPDIR)/driver_cfa_cpp-FindOpenVars.Po@am__quote@ 1025 1031 @AMDEP_TRUE@@am__include@ @am__quote@ResolvExpr/$(DEPDIR)/driver_cfa_cpp-Occurs.Po@am__quote@ … … 1964 1970 @am__fastdepCXX_FALSE@ $(AM_V_CXX@am__nodep@)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(driver_cfa_cpp_CXXFLAGS) $(CXXFLAGS) -c -o ResolvExpr/driver_cfa_cpp-CurrentObject.obj `if test -f 'ResolvExpr/CurrentObject.cc'; then $(CYGPATH_W) 'ResolvExpr/CurrentObject.cc'; else $(CYGPATH_W) '$(srcdir)/ResolvExpr/CurrentObject.cc'; fi` 1965 1971 1972 ResolvExpr/driver_cfa_cpp-ExplodedActual.o: ResolvExpr/ExplodedActual.cc 1973 @am__fastdepCXX_TRUE@ $(AM_V_CXX)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(driver_cfa_cpp_CXXFLAGS) $(CXXFLAGS) -MT ResolvExpr/driver_cfa_cpp-ExplodedActual.o -MD -MP -MF ResolvExpr/$(DEPDIR)/driver_cfa_cpp-ExplodedActual.Tpo -c -o ResolvExpr/driver_cfa_cpp-ExplodedActual.o `test -f 'ResolvExpr/ExplodedActual.cc' || echo '$(srcdir)/'`ResolvExpr/ExplodedActual.cc 1974 @am__fastdepCXX_TRUE@ $(AM_V_at)$(am__mv) ResolvExpr/$(DEPDIR)/driver_cfa_cpp-ExplodedActual.Tpo ResolvExpr/$(DEPDIR)/driver_cfa_cpp-ExplodedActual.Po 1975 @AMDEP_TRUE@@am__fastdepCXX_FALSE@ $(AM_V_CXX)source='ResolvExpr/ExplodedActual.cc' object='ResolvExpr/driver_cfa_cpp-ExplodedActual.o' libtool=no @AMDEPBACKSLASH@ 1976 @AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@ 1977 @am__fastdepCXX_FALSE@ $(AM_V_CXX@am__nodep@)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(driver_cfa_cpp_CXXFLAGS) $(CXXFLAGS) -c -o ResolvExpr/driver_cfa_cpp-ExplodedActual.o `test -f 'ResolvExpr/ExplodedActual.cc' || echo '$(srcdir)/'`ResolvExpr/ExplodedActual.cc 1978 1979 ResolvExpr/driver_cfa_cpp-ExplodedActual.obj: ResolvExpr/ExplodedActual.cc 1980 @am__fastdepCXX_TRUE@ $(AM_V_CXX)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(driver_cfa_cpp_CXXFLAGS) $(CXXFLAGS) -MT ResolvExpr/driver_cfa_cpp-ExplodedActual.obj -MD -MP -MF ResolvExpr/$(DEPDIR)/driver_cfa_cpp-ExplodedActual.Tpo -c -o ResolvExpr/driver_cfa_cpp-ExplodedActual.obj `if test -f 'ResolvExpr/ExplodedActual.cc'; then $(CYGPATH_W) 'ResolvExpr/ExplodedActual.cc'; else $(CYGPATH_W) '$(srcdir)/ResolvExpr/ExplodedActual.cc'; fi` 1981 @am__fastdepCXX_TRUE@ $(AM_V_at)$(am__mv) ResolvExpr/$(DEPDIR)/driver_cfa_cpp-ExplodedActual.Tpo ResolvExpr/$(DEPDIR)/driver_cfa_cpp-ExplodedActual.Po 1982 @AMDEP_TRUE@@am__fastdepCXX_FALSE@ $(AM_V_CXX)source='ResolvExpr/ExplodedActual.cc' object='ResolvExpr/driver_cfa_cpp-ExplodedActual.obj' libtool=no @AMDEPBACKSLASH@ 1983 @AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@ 1984 @am__fastdepCXX_FALSE@ $(AM_V_CXX@am__nodep@)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(driver_cfa_cpp_CXXFLAGS) $(CXXFLAGS) -c -o ResolvExpr/driver_cfa_cpp-ExplodedActual.obj `if test -f 'ResolvExpr/ExplodedActual.cc'; then $(CYGPATH_W) 'ResolvExpr/ExplodedActual.cc'; else $(CYGPATH_W) '$(srcdir)/ResolvExpr/ExplodedActual.cc'; fi` 1985 1966 1986 SymTab/driver_cfa_cpp-Indexer.o: SymTab/Indexer.cc 1967 1987 @am__fastdepCXX_TRUE@ $(AM_V_CXX)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(driver_cfa_cpp_CXXFLAGS) $(CXXFLAGS) -MT SymTab/driver_cfa_cpp-Indexer.o -MD -MP -MF SymTab/$(DEPDIR)/driver_cfa_cpp-Indexer.Tpo -c -o SymTab/driver_cfa_cpp-Indexer.o `test -f 'SymTab/Indexer.cc' || echo '$(srcdir)/'`SymTab/Indexer.cc -
src/ResolvExpr/AlternativeFinder.cc
rc2c6177 ra8b27c6 30 30 #include "Common/utility.h" // for deleteAll, printAll, CodeLocation 31 31 #include "Cost.h" // for Cost, Cost::zero, operator<<, Cost... 32 #include "ExplodedActual.h" // for ExplodedActual 32 33 #include "InitTweak/InitTweak.h" // for getFunctionName 33 34 #include "RenameVars.h" // for RenameVars, global_renamer … … 587 588 unsigned nextArg; ///< Index of next argument in arguments list 588 589 unsigned tupleStart; ///< Number of tuples that start at this index 589 // TODO fix this somehow590 std::vector<Alternative> expls; ///< Exploded actuals left over from last match591 590 unsigned nextExpl; ///< Index of next exploded element 591 unsigned explAlt; ///< Index of alternative for nextExpl > 0 592 592 593 ArgPack() 593 594 : parent(0), expr(), cost(Cost::zero), env(), need(), have(), openVars(), nextArg(0), 594 tupleStart(0), expls() {}595 tupleStart(0), nextExpl(0), explAlt(0) {} 595 596 596 597 ArgPack(const TypeEnvironment& env, const AssertionSet& need, const AssertionSet& have, 597 598 const OpenVarSet& openVars) 598 599 : parent(0), expr(), cost(Cost::zero), env(env), need(need), have(have), 599 openVars(openVars), nextArg(0), tupleStart(0), expls() {}600 openVars(openVars), nextArg(0), tupleStart(0), nextExpl(0), explAlt(0) {} 600 601 601 602 ArgPack(std::size_t parent, Expression* expr, TypeEnvironment&& env, AssertionSet&& need, 602 603 AssertionSet&& have, OpenVarSet&& openVars, unsigned nextArg, 603 unsigned tupleStart = 0, Cost cost = Cost::zero, 604 std::vector<Alternative>&& expls = std::vector<Alternative>{})604 unsigned tupleStart = 0, Cost cost = Cost::zero, unsigned nextExpl = 0, 605 unsigned explAlt = 0 ) 605 606 : parent(parent), expr(expr->clone()), cost(cost), env(move(env)), need(move(need)), 606 607 have(move(have)), openVars(move(openVars)), nextArg(nextArg), tupleStart(tupleStart), 607 expls(move(expls)) {}608 nextExpl(nextExpl), explAlt(explAlt) {} 608 609 609 610 ArgPack(const ArgPack& o, TypeEnvironment&& env, AssertionSet&& need, AssertionSet&& have, … … 611 612 : parent(o.parent), expr(o.expr ? o.expr->clone() : nullptr), cost(o.cost + added), 612 613 env(move(env)), need(move(need)), have(move(have)), openVars(move(openVars)), 613 nextArg(nextArg), tupleStart(o.tupleStart), expls() {} 614 nextArg(nextArg), tupleStart(o.tupleStart), nextExpl(0), explAlt(0) {} 615 616 /// true iff this pack is in the middle of an exploded argument 617 bool hasExpl() const { return nextExpl > 0; } 618 619 /// Gets the list of exploded alternatives for this pack 620 const ExplodedActual& getExpl( const ExplodedArgs& args ) const { 621 return args[nextArg-1][explAlt]; 622 } 614 623 615 616 // ArgPack(const ArgPack& o)617 // : parent(o.parent), expr(o.expr ? o.expr->clone() : nullptr), env(o.env),618 // need(o.need), have(o.have), openVars(o.openVars), nextArg(o.nextArg),619 // tupleStart(o.tupleStart), expls(o.expls) {}620 621 // ArgPack(ArgPack&&) = default;622 623 624 /// Ends a tuple expression, consolidating the appropriate actuals 624 625 void endTuple( const std::vector<ArgPack>& packs ) { … … 641 642 /// Instantiates an argument to match a formal, returns false if no results left 642 643 bool instantiateArgument( Type* formalType, Initializer* initializer, 643 const std::vector< AlternativeFinder >& args, std::vector<ArgPack>& results,644 std::size_t& genStart,const SymTab::Indexer& indexer, unsigned nTuples = 0 ) {644 const ExplodedArgs& args, std::vector<ArgPack>& results, std::size_t& genStart, 645 const SymTab::Indexer& indexer, unsigned nTuples = 0 ) { 645 646 if ( TupleType* tupleType = dynamic_cast<TupleType*>( formalType ) ) { 646 647 // formalType is a TupleType - group actuals into a TupleExpr … … 673 674 // add another argument to results 674 675 for ( std::size_t i = genStart; i < genEnd; ++i ) { 676 auto nextArg = results[i].nextArg; 677 675 678 // use remainder of exploded tuple if present 676 if ( ! results[i].expls.empty() ) { 677 const Alternative& actual = results[i].expls.front(); 679 if ( results[i].hasExpl() ) { 680 const ExplodedActual& expl = results[i].getExpl( args ); 681 const Alternative& actual = expl.alts[results[i].nextExpl]; 678 682 679 683 TypeEnvironment env = results[i].env; … … 682 686 env.addActual( actual.env, openVars ); 683 687 684 std::vector<Alternative> newExpls( 685 std::next( results[i].expls.begin() ), results[i].expls.end() ); 688 unsigned nextExpl = results[i].nextExpl + 1; 689 if ( nextExpl == expl.alts.size() ) { 690 nextExpl = 0; 691 } 692 686 693 results.emplace_back( 687 694 i, actual.expr, move(env), copy(results[i].need), 688 copy(results[i].have), move(openVars), results[i].nextArg, nTuples,689 Cost::zero, move(newExpls));695 copy(results[i].have), move(openVars), nextArg, nTuples, 696 Cost::zero, nextExpl, results[i].explAlt ); 690 697 691 698 continue; … … 693 700 694 701 // finish result when out of arguments 695 if ( results[i].nextArg >= args.size() ) {702 if ( nextArg >= args.size() ) { 696 703 ArgPack newResult{ 697 704 results[i].env, results[i].need, results[i].have, 698 705 results[i].openVars }; 699 newResult.nextArg = results[i].nextArg;706 newResult.nextArg = nextArg; 700 707 Type* argType; 701 708 … … 741 748 742 749 // add each possible next argument 743 auto j = results[i].nextArg; 744 for ( const Alternative& actual : args[j] ) { 750 for ( std::size_t j = 0; j < args[nextArg].size(); ++j ) { 751 const ExplodedActual& expl = args[nextArg][j]; 752 745 753 // fresh copies of parent parameters for this iteration 746 754 TypeEnvironment env = results[i].env; 747 755 OpenVarSet openVars = results[i].openVars; 748 756 749 env.addActual( actual.env, openVars ); 750 751 // explode argument 752 std::vector<Alternative> exploded; 753 Tuples::explode( actual, indexer, back_inserter( exploded ) ); 754 if ( exploded.empty() ) { 755 // skip empty tuple arguments by (near-)cloning parent into next gen 757 env.addActual( expl.env, openVars ); 758 759 // skip empty tuple arguments by (near-)cloning parent into next gen 760 if ( expl.alts.empty() ) { 756 761 results.emplace_back( 757 762 results[i], move(env), copy(results[i].need), 758 copy(results[i].have), move(openVars), j + 1, actual.cost );763 copy(results[i].have), move(openVars), nextArg + 1, expl.cost ); 759 764 760 765 continue; 761 766 } 762 767 763 // trim first element from exploded764 std::vector<Alternative> newExpls;765 newExpls.reserve( exploded.size() - 1 );766 for ( std::size_t i = 1; i < exploded.size(); ++i ) {767 newExpls.push_back( move(exploded[i]) );768 }769 768 // add new result 770 769 results.emplace_back( 771 i, expl oded.front().expr, move(env), copy(results[i].need),772 copy(results[i].have), move(openVars), results[i].nextArg + 1,773 nTuples, actual.cost, move(newExpls));770 i, expl.alts.front().expr, move(env), copy(results[i].need), 771 copy(results[i].have), move(openVars), nextArg + 1, 772 nTuples, expl.cost, expl.alts.size() == 1 ? 0 : 1, j ); 774 773 } 775 774 } … … 790 789 std::size_t genEnd = results.size(); 791 790 for ( std::size_t i = genStart; i < genEnd; ++i ) { 791 auto nextArg = results[i].nextArg; 792 792 793 // use remainder of exploded tuple if present 793 if ( ! results[i].expls.empty() ) { 794 const Alternative& actual = results[i].expls.front(); 794 if ( results[i].hasExpl() ) { 795 const ExplodedActual& expl = results[i].getExpl( args ); 796 const Alternative& actual = expl.alts[results[i].nextExpl]; 795 797 796 798 TypeEnvironment env = results[i].env; … … 810 812 811 813 if ( unify( formalType, actualType, env, need, have, openVars, indexer ) ) { 812 std::vector<Alternative> newExpls( 813 std::next( results[i].expls.begin() ), results[i].expls.end() ); 814 unsigned nextExpl = results[i].nextExpl + 1; 815 if ( nextExpl == expl.alts.size() ) { 816 nextExpl = 0; 817 } 818 814 819 results.emplace_back( 815 820 i, actual.expr, move(env), move(need), move(have), move(openVars), 816 results[i].nextArg, nTuples, Cost::zero, move(newExpls) );;821 nextArg, nTuples, Cost::zero, nextExpl, results[i].explAlt ); 817 822 } 818 823 … … 821 826 822 827 // use default initializers if out of arguments 823 if ( results[i].nextArg >= args.size() ) {828 if ( nextArg >= args.size() ) { 824 829 if ( ConstantExpr* cnstExpr = getDefaultValue( initializer ) ) { 825 830 if ( Constant* cnst = dynamic_cast<Constant*>( cnstExpr->get_constant() ) ) { … … 832 837 results.emplace_back( 833 838 i, cnstExpr, move(env), move(need), move(have), 834 move(openVars), results[i].nextArg, nTuples );839 move(openVars), nextArg, nTuples ); 835 840 } 836 841 } … … 841 846 842 847 // Check each possible next argument 843 auto j = results[i].nextArg; 844 for ( const Alternative& actual : args[j] ) { 848 for ( std::size_t j = 0; j < args[nextArg].size(); ++j ) { 849 const ExplodedActual& expl = args[nextArg][j]; 850 845 851 // fresh copies of parent parameters for this iteration 846 852 TypeEnvironment env = results[i].env; … … 848 854 OpenVarSet openVars = results[i].openVars; 849 855 850 env.addActual( actual.env, openVars );856 env.addActual( expl.env, openVars ); 851 857 852 // explode argument 853 std::vector<Alternative> exploded; 854 Tuples::explode( actual, indexer, back_inserter( exploded ) ); 855 if ( exploded.empty() ) { 856 // skip empty tuple arguments by (near-)cloning parent into next gen 858 // skip empty tuple arguments by (near-)cloning parent into next gen 859 if ( expl.alts.empty() ) { 857 860 results.emplace_back( 858 results[i], move(env), move(need), move(have), move(openVars), j + 1,859 actual.cost );861 results[i], move(env), move(need), move(have), move(openVars), 862 nextArg + 1, expl.cost ); 860 863 861 864 continue; … … 863 866 864 867 // consider only first exploded actual 865 const Alternative& a Actual = exploded.front();866 Type* actualType = a Actual.expr->get_result()->clone();868 const Alternative& actual = expl.alts.front(); 869 Type* actualType = actual.expr->get_result()->clone(); 867 870 868 871 PRINT( … … 876 879 // attempt to unify types 877 880 if ( unify( formalType, actualType, env, need, have, openVars, indexer ) ) { 878 // trim first element from exploded879 std::vector<Alternative> newExpls;880 newExpls.reserve( exploded.size() - 1 );881 for ( std::size_t i = 1; i < exploded.size(); ++i ) {882 newExpls.push_back( move(exploded[i]) );883 }884 881 // add new result 885 882 results.emplace_back( 886 i, a Actual.expr, move(env), move(need), move(have), move(openVars),887 j + 1, nTuples, actual.cost, move(newExpls));883 i, actual.expr, move(env), move(need), move(have), move(openVars), 884 nextArg + 1, nTuples, expl.cost, expl.alts.size() == 1 ? 0 : 1, j ); 888 885 } 889 886 } … … 921 918 template<typename OutputIterator> 922 919 void AlternativeFinder::makeFunctionAlternatives( const Alternative &func, 923 FunctionType *funcType, const std::vector< AlternativeFinder > &args, 924 OutputIterator out ) { 920 FunctionType *funcType, const ExplodedArgs &args, OutputIterator out ) { 925 921 OpenVarSet funcOpenVars; 926 922 AssertionSet funcNeed, funcHave; … … 961 957 // iterate results 962 958 for ( std::size_t i = genStart; i < genEnd; ++i ) { 959 auto nextArg = results[i].nextArg; 960 963 961 // use remainder of exploded tuple if present 964 if ( ! results[i].expls.empty() ) { 965 const Alternative& actual = results[i].expls.front(); 962 if ( results[i].hasExpl() ) { 963 const ExplodedActual& expl = results[i].getExpl( args ); 964 const Alternative& actual = expl.alts[results[i].nextExpl]; 966 965 967 966 TypeEnvironment env = results[i].env; … … 970 969 env.addActual( actual.env, openVars ); 971 970 972 std::vector<Alternative> newExpls( 973 std::next( results[i].expls.begin() ), results[i].expls.end() ); 971 unsigned nextExpl = results[i].nextExpl + 1; 972 if ( nextExpl == expl.alts.size() ) { 973 nextExpl = 0; 974 } 975 974 976 results.emplace_back( 975 977 i, actual.expr, move(env), copy(results[i].need), 976 copy(results[i].have), move(openVars), results[i].nextArg, 0,977 Cost::zero, move(newExpls));978 copy(results[i].have), move(openVars), nextArg, 0, 979 Cost::zero, nextExpl, results[i].explAlt ); 978 980 979 981 continue; … … 981 983 982 984 // finish result when out of arguments 983 if ( results[i].nextArg >= args.size() ) {985 if ( nextArg >= args.size() ) { 984 986 validateFunctionAlternative( func, results[i], results, out ); 985 987 … … 988 990 989 991 // add each possible next argument 990 auto j = results[i].nextArg; 991 for ( const Alternative& actual : args[j] ) { 992 for ( std::size_t j = 0; j < args[nextArg].size(); ++j ) { 993 const ExplodedActual& expl = args[nextArg][j]; 994 992 995 // fresh copies of parent parameters for this iteration 993 996 TypeEnvironment env = results[i].env; 994 997 OpenVarSet openVars = results[i].openVars; 995 998 996 env.addActual( actual.env, openVars ); 997 998 // explode argument 999 std::vector<Alternative> exploded; 1000 Tuples::explode( actual, indexer, back_inserter( exploded ) ); 1001 if ( exploded.empty() ) { 1002 // skip empty tuple arguments by (near-)cloning parent into next gen 999 env.addActual( expl.env, openVars ); 1000 1001 // skip empty tuple arguments by (near-)cloning parent into next gen 1002 if ( expl.alts.empty() ) { 1003 1003 results.emplace_back( 1004 1004 results[i], move(env), copy(results[i].need), 1005 copy(results[i].have), move(openVars), j + 1, actual.cost ); 1005 copy(results[i].have), move(openVars), nextArg + 1, expl.cost ); 1006 1006 1007 continue; 1007 1008 } 1008 1009 1009 // trim first element from exploded1010 std::vector<Alternative> newExpls;1011 newExpls.reserve( exploded.size() - 1 );1012 for ( std::size_t i = 1; i < exploded.size(); ++i ) {1013 newExpls.push_back( move(exploded[i]) );1014 }1015 1010 // add new result 1016 1011 results.emplace_back( 1017 i, expl oded.front().expr, move(env), copy(results[i].need),1018 copy(results[i].have), move(openVars), j+ 1, 0,1019 actual.cost, move(newExpls));1012 i, expl.alts.front().expr, move(env), copy(results[i].need), 1013 copy(results[i].have), move(openVars), nextArg + 1, 0, 1014 expl.cost, expl.alts.size() == 1 ? 0 : 1, j ); 1020 1015 } 1021 1016 } … … 1027 1022 for ( std::size_t i = genStart; i < results.size(); ++i ) { 1028 1023 ArgPack& result = results[i]; 1029 if ( result.expls.empty() && result.nextArg >= args.size() ) {1024 if ( ! result.hasExpl() && result.nextArg >= args.size() ) { 1030 1025 validateFunctionAlternative( func, result, results, out ); 1031 1026 } … … 1057 1052 printAlts( funcOpFinder.alternatives, std::cerr, 1 ); 1058 1053 ) 1054 1055 // pre-explode arguments 1056 ExplodedArgs argExpansions; 1057 argExpansions.reserve( argAlternatives.size() ); 1058 1059 for ( const AlternativeFinder& arg : argAlternatives ) { 1060 argExpansions.emplace_back(); 1061 auto& argE = argExpansions.back(); 1062 argE.reserve( arg.alternatives.size() ); 1063 1064 for ( const Alternative& actual : arg ) { 1065 argE.emplace_back( actual, indexer ); 1066 } 1067 } 1059 1068 1060 1069 AltList candidates; … … 1071 1080 Alternative newFunc( *func ); 1072 1081 referenceToRvalueConversion( newFunc.expr ); 1073 makeFunctionAlternatives( newFunc, function, arg Alternatives,1082 makeFunctionAlternatives( newFunc, function, argExpansions, 1074 1083 std::back_inserter( candidates ) ); 1075 1084 } … … 1080 1089 Alternative newFunc( *func ); 1081 1090 referenceToRvalueConversion( newFunc.expr ); 1082 makeFunctionAlternatives( newFunc, function, arg Alternatives,1091 makeFunctionAlternatives( newFunc, function, argExpansions, 1083 1092 std::back_inserter( candidates ) ); 1084 1093 } // if … … 1092 1101 // try each function operator ?() with each function alternative 1093 1102 if ( ! funcOpFinder.alternatives.empty() ) { 1094 // add function alternatives to front of argument list 1095 argAlternatives.insert( argAlternatives.begin(), move(funcFinder) ); 1103 // add exploded function alternatives to front of argument list 1104 std::vector<ExplodedActual> funcE; 1105 funcE.reserve( funcFinder.alternatives.size() ); 1106 for ( const Alternative& actual : funcFinder ) { 1107 funcE.emplace_back( actual, indexer ); 1108 } 1109 argExpansions.insert( argExpansions.begin(), move(funcE) ); 1096 1110 1097 1111 for ( AltList::iterator funcOp = funcOpFinder.alternatives.begin(); … … 1105 1119 Alternative newFunc( *funcOp ); 1106 1120 referenceToRvalueConversion( newFunc.expr ); 1107 makeFunctionAlternatives( newFunc, function, arg Alternatives,1121 makeFunctionAlternatives( newFunc, function, argExpansions, 1108 1122 std::back_inserter( candidates ) ); 1109 1123 } -
src/ResolvExpr/AlternativeFinder.h
rc2c6177 ra8b27c6 21 21 22 22 #include "Alternative.h" // for AltList, Alternative 23 #include "ExplodedActual.h" // for ExplodedActual 23 24 #include "ResolvExpr/Cost.h" // for Cost, Cost::infinity 24 25 #include "ResolvExpr/TypeEnvironment.h" // for AssertionSet, OpenVarSet … … 32 33 namespace ResolvExpr { 33 34 class ArgPack; 35 36 /// First index is which argument, second index is which alternative for that argument, 37 /// third index is which exploded element of that alternative 38 using ExplodedArgs = std::vector< std::vector< ExplodedActual > >; 34 39 35 40 class AlternativeFinder : public Visitor { … … 133 138 /// Finds matching alternatives for a function, given a set of arguments 134 139 template<typename OutputIterator> 135 void makeFunctionAlternatives( const Alternative &func, FunctionType *funcType, const std::vector< AlternativeFinder >& args, OutputIterator out );140 void makeFunctionAlternatives( const Alternative &func, FunctionType *funcType, const ExplodedArgs& args, OutputIterator out ); 136 141 /// Checks if assertion parameters match for a new alternative 137 142 template< typename OutputIterator > -
src/ResolvExpr/module.mk
rc2c6177 ra8b27c6 32 32 ResolvExpr/Occurs.cc \ 33 33 ResolvExpr/TypeEnvironment.cc \ 34 ResolvExpr/CurrentObject.cc 34 ResolvExpr/CurrentObject.cc \ 35 ResolvExpr/ExplodedActual.cc
Note: See TracChangeset
for help on using the changeset viewer.