Changes in / [f22b7aef:c04531fc]


Ignore:
Location:
src
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • src/ResolvExpr/AlternativeFinder.cc

    rf22b7aef rc04531fc  
    286286        }
    287287
    288         Cost computeConversionCost( Type * actualType, Type * formalType, const SymTab::Indexer &indexer, const TypeEnvironment & env ) {
    289                 PRINT(
    290                         std::cerr << std::endl << "converting ";
    291                         actualType->print( std::cerr, 8 );
    292                         std::cerr << std::endl << " to ";
    293                         formalType->print( std::cerr, 8 );
    294                         std::cerr << std::endl << "environment is: ";
    295                         env.print( std::cerr, 8 );
    296                         std::cerr << std::endl;
    297                 )
    298                 Cost convCost = conversionCost( actualType, formalType, indexer, env );
    299                 PRINT(
    300                         std::cerr << std::endl << "cost is" << convCost << std::endl;
    301                 )
    302                 if ( convCost == Cost::infinity ) {
    303                         return convCost;
    304                 }
    305                 convCost.incPoly( polyCost( formalType, env, indexer ) + polyCost( actualType, env, indexer ) );
    306                 return convCost;
    307         }
    308 
    309         Cost computeExpressionConversionCost( Expression *& actualExpr, Type * formalType, const SymTab::Indexer &indexer, const TypeEnvironment & env ) {
    310                 Cost convCost = computeConversionCost( actualExpr->result, formalType, indexer, env );
    311                 // if ( convCost != Cost::zero ) {
    312 
    313                 // xxx - temporary -- ignore poly cost, since this causes some polymorphic functions to be cast, which causes the specialize
    314                 // pass to try to specialize them, which currently does not work. Once that is fixed, remove the next 3 lines and uncomment the
    315                 // previous line.
    316                 Cost tmpCost = convCost;
    317                 tmpCost.incPoly( -tmpCost.get_polyCost() );
    318                 if ( tmpCost != Cost::zero ) {
    319                         Type *newType = formalType->clone();
    320                         env.apply( newType );
    321                         actualExpr = new CastExpr( actualExpr, newType );
    322                         // xxx - SHOULD be able to resolve this cast, but at the moment pointers are not castable to zero_t, but are implicitly convertible. This is clearly
    323                         // inconsistent, once this is fixed it should be possible to resolve the cast.
    324                         // xxx - this isn't working, it appears because type1 (the formal type) is seen as widenable, but it shouldn't be, because this makes the conversion from DT* to DT* since commontype(zero_t, DT*) is DT*, rather than just nothing.
    325 
    326                         // AlternativeFinder finder( indexer, env );
    327                         // finder.findWithAdjustment( actualExpr );
    328                         // assertf( finder.get_alternatives().size() > 0, "Somehow castable expression failed to find alternatives." );
    329                         // assertf( finder.get_alternatives().size() == 1, "Somehow got multiple alternatives for known cast expression." );
    330                         // Alternative & alt = finder.get_alternatives().front();
    331                         // delete actualExpr;
    332                         // actualExpr = alt.expr->clone();
    333                 }
    334                 return convCost;
    335         }
    336 
    337         Cost computeApplicationConversionCost( Alternative &alt, const SymTab::Indexer &indexer ) {
     288        Cost computeConversionCost( Alternative &alt, const SymTab::Indexer &indexer ) {
    338289                ApplicationExpr *appExpr = safe_dynamic_cast< ApplicationExpr* >( alt.expr );
    339290                PointerType *pointer = safe_dynamic_cast< PointerType* >( appExpr->get_function()->get_result() );
     
    353304                                actualType->print( std::cerr, 8 );
    354305                        )
     306                        Cost actualCost = Cost::zero;
    355307                        if ( formal == formals.end() ) {
    356308                                if ( function->get_isVarArgs() ) {
     
    373325                                std::cerr << std::endl;
    374326                        )
    375                         convCost += computeExpressionConversionCost( *actualExpr, formalType, indexer, alt.env );
     327                        Cost newCost = conversionCost( actualType, formalType, indexer, alt.env );
     328                        PRINT(
     329                                std::cerr << std::endl << "cost is" << newCost << std::endl;
     330                        )
     331
     332                        if ( newCost == Cost::infinity ) {
     333                                return newCost;
     334                        }
     335                        convCost += newCost;
     336                        actualCost += newCost;
     337                        if ( actualCost != Cost::zero ) {
     338                                Type *newType = formalType->clone();
     339                                alt.env.apply( newType );
     340                                *actualExpr = new CastExpr( *actualExpr, newType );
     341                        }
     342                        convCost.incPoly( polyCost( formalType, alt.env, indexer ) + polyCost( actualType, alt.env, indexer ) );
    376343                        ++formal; // can't be in for-loop update because of the continue
    377344                }
     
    381348
    382349                for ( InferredParams::const_iterator assert = appExpr->get_inferParams().begin(); assert != appExpr->get_inferParams().end(); ++assert ) {
    383                         convCost += computeConversionCost( assert->second.actualType, assert->second.formalType, indexer, alt.env );
     350                        PRINT(
     351                                std::cerr << std::endl << "converting ";
     352                                assert->second.actualType->print( std::cerr, 8 );
     353                                std::cerr << std::endl << " to ";
     354                                assert->second.formalType->print( std::cerr, 8 );
     355                        )
     356                        Cost newCost = conversionCost( assert->second.actualType, assert->second.formalType, indexer, alt.env );
     357                        PRINT(
     358                                std::cerr << std::endl << "cost of conversion is " << newCost << std::endl;
     359                        )
     360                        if ( newCost == Cost::infinity ) {
     361                                return newCost;
     362                        }
     363                        convCost += newCost;
     364                        convCost.incPoly( polyCost( assert->second.formalType, alt.env, indexer ) + polyCost( assert->second.actualType, alt.env, indexer ) );
    384365                }
    385366
     
    795776                // compute conversionsion costs
    796777                for ( AltList::iterator withFunc = candidates.begin(); withFunc != candidates.end(); ++withFunc ) {
    797                         Cost cvtCost = computeApplicationConversionCost( *withFunc, indexer );
     778                        Cost cvtCost = computeConversionCost( *withFunc, indexer );
    798779
    799780                        PRINT(
     
    914895                                // count one safe conversion for each value that is thrown away
    915896                                thisCost.incSafe( discardedValues );
    916                                 Alternative newAlt( restructureCast( i->expr->clone(), toType ), i->env, i->cost, thisCost );
    917                                 // xxx - this doesn't work at the moment, since inferParameters requires an ApplicationExpr as the alternative.
    918                                 // Once this works, it should be possible to infer parameters on a cast expression and specialize any function.
    919 
    920                                 // inferParameters( needAssertions, haveAssertions, newAlt, openVars, back_inserter( candidates ) );
    921                                 candidates.emplace_back( std::move( newAlt ) );
     897
     898                                candidates.push_back( Alternative( restructureCast( i->expr->clone(), toType ), i->env, i->cost, thisCost ) );
    922899                        } // if
    923900                } // for
     
    11621139                                                ConditionalExpr *newExpr = new ConditionalExpr( first->expr->clone(), second->expr->clone(), third->expr->clone() );
    11631140                                                newExpr->set_result( commonType ? commonType : second->expr->get_result()->clone() );
    1164                                                 // convert both options to the conditional result type
    1165                                                 newAlt.cost += computeExpressionConversionCost( newExpr->arg2, newExpr->result, indexer, newAlt.env );
    1166                                                 newAlt.cost += computeExpressionConversionCost( newExpr->arg3, newExpr->result, indexer, newAlt.env );
    11671141                                                newAlt.expr = newExpr;
    11681142                                                inferParameters( needAssertions, haveAssertions, newAlt, openVars, back_inserter( alternatives ) );
  • src/ResolvExpr/Cost.h

    rf22b7aef rc04531fc  
    2828                Cost & incSafe( int inc = 1 );
    2929                Cost & incReference( int inc = 1 );
    30 
    31                 int get_unsafeCost() const { return unsafeCost; }
    32                 int get_polyCost() const { return polyCost; }
    33                 int get_safeCost() const { return safeCost; }
    34                 int get_referenceCost() const { return referenceCost; }
    3530
    3631                Cost operator+( const Cost &other ) const;
  • src/libcfa/Makefile.am

    rf22b7aef rc04531fc  
    3636         ${AM_V_GEN}@BACKEND_CC@ @CFA_FLAGS@ -D__CFA_DEBUG__ -O0 -c -o $@ $<
    3737
    38 EXTRA_FLAGS = -g -Wall -Werror -Wno-unused-function -imacros libcfa-prelude.c @CFA_FLAGS@
     38EXTRA_FLAGS = -g -Wall -Wno-unused-function -imacros libcfa-prelude.c @CFA_FLAGS@
    3939
    4040AM_CCASFLAGS = @CFA_FLAGS@
  • src/libcfa/Makefile.in

    rf22b7aef rc04531fc  
    416416ARFLAGS = cr
    417417lib_LIBRARIES = $(am__append_1) $(am__append_2)
    418 EXTRA_FLAGS = -g -Wall -Werror -Wno-unused-function -imacros libcfa-prelude.c @CFA_FLAGS@
     418EXTRA_FLAGS = -g -Wall -Wno-unused-function -imacros libcfa-prelude.c @CFA_FLAGS@
    419419AM_CCASFLAGS = @CFA_FLAGS@
    420420headers = fstream iostream iterator limits rational stdlib \
  • src/libcfa/exception.h

    rf22b7aef rc04531fc  
    2929                     struct __cfaehm__base_exception_t * other);
    3030        void (*free)(struct __cfaehm__base_exception_t *this);
    31         const char * (*msg)(struct __cfaehm__base_exception_t *this);
     31        const char (*msg)(struct __cfaehm__base_exception_t *this);
    3232};
    3333struct __cfaehm__base_exception_t {
Note: See TracChangeset for help on using the changeset viewer.