Changeset b1bead1 for src/ResolvExpr
- Timestamp:
- Aug 8, 2017, 8:36:48 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:
- 8499c707
- Parents:
- 83794e1
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/ResolvExpr/AlternativeFinder.cc
r83794e1 rb1bead1 144 144 expr->get_result()->accept( global_renamer ); 145 145 } 146 } 146 147 void referenceToRvalueConversion( Expression *& expr ) { 148 if ( dynamic_cast< ReferenceType * >( expr->get_result() ) ) { 149 // cast away reference from expr 150 expr = new CastExpr( expr, expr->get_result()->stripReferences()->clone() ); 151 } 152 } 153 } // namespace 147 154 148 155 template< typename InputIterator, typename OutputIterator > … … 300 307 if ( function->get_isVarArgs() ) { 301 308 convCost.incUnsafe(); 309 // convert reference-typed expressions to value-typed expressions 310 referenceToRvalueConversion( *actualExpr ); 302 311 continue; 303 312 } else { … … 693 702 AltList candidates; 694 703 SemanticError errors; 695 for ( AltList:: const_iterator func = funcFinder.alternatives.begin(); func != funcFinder.alternatives.end(); ++func ) {704 for ( AltList::iterator func = funcFinder.alternatives.begin(); func != funcFinder.alternatives.end(); ++func ) { 696 705 try { 697 706 PRINT( … … 700 709 ) 701 710 // check if the type is pointer to function 702 PointerType *pointer; 703 if ( ( pointer = dynamic_cast< PointerType* >( func->expr->get_result() ) ) ) { 711 if ( PointerType *pointer = dynamic_cast< PointerType* >( func->expr->get_result()->stripReferences() ) ) { 704 712 if ( FunctionType *function = dynamic_cast< FunctionType* >( pointer->get_base() ) ) { 713 referenceToRvalueConversion( func->expr ); 705 714 for ( std::list< AltList >::iterator actualAlt = possibilities.begin(); actualAlt != possibilities.end(); ++actualAlt ) { 706 715 // XXX … … 708 717 makeFunctionAlternatives( *func, function, *actualAlt, std::back_inserter( candidates ) ); 709 718 } 710 } else if ( TypeInstType *typeInst = dynamic_cast< TypeInstType* >( pointer->get_base() ) ) { 711 EqvClass eqvClass; 712 if ( func->env.lookup( typeInst->get_name(), eqvClass ) && eqvClass.type ) { 713 if ( FunctionType *function = dynamic_cast< FunctionType* >( eqvClass.type ) ) { 714 for ( std::list< AltList >::iterator actualAlt = possibilities.begin(); actualAlt != possibilities.end(); ++actualAlt ) { 715 makeFunctionAlternatives( *func, function, *actualAlt, std::back_inserter( candidates ) ); 716 } // for 717 } // if 719 } 720 } else if ( TypeInstType *typeInst = dynamic_cast< TypeInstType* >( func->expr->get_result()->stripReferences() ) ) { // handle ftype (e.g. *? on function pointer) 721 referenceToRvalueConversion( func->expr ); 722 EqvClass eqvClass; 723 if ( func->env.lookup( typeInst->get_name(), eqvClass ) && eqvClass.type ) { 724 if ( FunctionType *function = dynamic_cast< FunctionType* >( eqvClass.type ) ) { 725 for ( std::list< AltList >::iterator actualAlt = possibilities.begin(); actualAlt != possibilities.end(); ++actualAlt ) { 726 makeFunctionAlternatives( *func, function, *actualAlt, std::back_inserter( candidates ) ); 727 } // for 718 728 } // if 719 729 } // if … … 734 744 } 735 745 736 for ( AltList:: const_iterator funcOp = funcOpFinder.alternatives.begin(); funcOp != funcOpFinder.alternatives.end(); ++funcOp ) {746 for ( AltList::iterator funcOp = funcOpFinder.alternatives.begin(); funcOp != funcOpFinder.alternatives.end(); ++funcOp ) { 737 747 // check if the type is pointer to function 738 PointerType *pointer; 739 if ( ( pointer = dynamic_cast< PointerType* >( funcOp->expr->get_result() ) ) ) { 748 if ( PointerType *pointer = dynamic_cast< PointerType* >( funcOp->expr->get_result()->stripReferences() ) ) { 740 749 if ( FunctionType *function = dynamic_cast< FunctionType* >( pointer->get_base() ) ) { 750 referenceToRvalueConversion( funcOp->expr ); 741 751 for ( std::list< AltList >::iterator actualAlt = possibilities.begin(); actualAlt != possibilities.end(); ++actualAlt ) { 742 752 AltList currentAlt; … … 868 878 // that are cast directly. The candidate is invalid if it has fewer results than there are types to cast 869 879 // to. 870 int discardedValues = (*i).expr->get_result()->size() - castExpr->get_result()->size();880 int discardedValues = i->expr->get_result()->size() - castExpr->get_result()->size(); 871 881 if ( discardedValues < 0 ) continue; 872 882 // xxx - may need to go into tuple types and extract relevant types and use unifyList. Note that currently, this does not 873 883 // allow casting a tuple to an atomic type (e.g. (int)([1, 2, 3])) 874 884 // unification run for side-effects 875 unify( castExpr->get_result(), (*i).expr->get_result(), i->env, needAssertions, haveAssertions, openVars, indexer );876 Cost thisCost = castCost( (*i).expr->get_result(), castExpr->get_result(), indexer, i->env );885 unify( castExpr->get_result(), i->expr->get_result(), i->env, needAssertions, haveAssertions, openVars, indexer ); 886 Cost thisCost = castCost( i->expr->get_result(), castExpr->get_result(), indexer, i->env ); 877 887 if ( thisCost != Cost::infinity ) { 878 888 // count one safe conversion for each value that is thrown away
Note: See TracChangeset
for help on using the changeset viewer.