Changes in / [c04531fc:f22b7aef]


Ignore:
Location:
src
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • src/ResolvExpr/AlternativeFinder.cc

    rc04531fc rf22b7aef  
    286286        }
    287287
    288         Cost computeConversionCost( Alternative &alt, const SymTab::Indexer &indexer ) {
     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 ) {
    289338                ApplicationExpr *appExpr = safe_dynamic_cast< ApplicationExpr* >( alt.expr );
    290339                PointerType *pointer = safe_dynamic_cast< PointerType* >( appExpr->get_function()->get_result() );
     
    304353                                actualType->print( std::cerr, 8 );
    305354                        )
    306                         Cost actualCost = Cost::zero;
    307355                        if ( formal == formals.end() ) {
    308356                                if ( function->get_isVarArgs() ) {
     
    325373                                std::cerr << std::endl;
    326374                        )
    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 ) );
     375                        convCost += computeExpressionConversionCost( *actualExpr, formalType, indexer, alt.env );
    343376                        ++formal; // can't be in for-loop update because of the continue
    344377                }
     
    348381
    349382                for ( InferredParams::const_iterator assert = appExpr->get_inferParams().begin(); assert != appExpr->get_inferParams().end(); ++assert ) {
    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 ) );
     383                        convCost += computeConversionCost( assert->second.actualType, assert->second.formalType, indexer, alt.env );
    365384                }
    366385
     
    776795                // compute conversionsion costs
    777796                for ( AltList::iterator withFunc = candidates.begin(); withFunc != candidates.end(); ++withFunc ) {
    778                         Cost cvtCost = computeConversionCost( *withFunc, indexer );
     797                        Cost cvtCost = computeApplicationConversionCost( *withFunc, indexer );
    779798
    780799                        PRINT(
     
    895914                                // count one safe conversion for each value that is thrown away
    896915                                thisCost.incSafe( discardedValues );
    897 
    898                                 candidates.push_back( Alternative( restructureCast( i->expr->clone(), toType ), i->env, i->cost, thisCost ) );
     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 ) );
    899922                        } // if
    900923                } // for
     
    11391162                                                ConditionalExpr *newExpr = new ConditionalExpr( first->expr->clone(), second->expr->clone(), third->expr->clone() );
    11401163                                                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 );
    11411167                                                newAlt.expr = newExpr;
    11421168                                                inferParameters( needAssertions, haveAssertions, newAlt, openVars, back_inserter( alternatives ) );
  • src/ResolvExpr/Cost.h

    rc04531fc rf22b7aef  
    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; }
    3035
    3136                Cost operator+( const Cost &other ) const;
  • src/libcfa/Makefile.am

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

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

    rc04531fc rf22b7aef  
    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.