Changes in / [f22b7aef:c04531fc]
- Location:
- src
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
src/ResolvExpr/AlternativeFinder.cc
rf22b7aef rc04531fc 286 286 } 287 287 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 ) { 338 289 ApplicationExpr *appExpr = safe_dynamic_cast< ApplicationExpr* >( alt.expr ); 339 290 PointerType *pointer = safe_dynamic_cast< PointerType* >( appExpr->get_function()->get_result() ); … … 353 304 actualType->print( std::cerr, 8 ); 354 305 ) 306 Cost actualCost = Cost::zero; 355 307 if ( formal == formals.end() ) { 356 308 if ( function->get_isVarArgs() ) { … … 373 325 std::cerr << std::endl; 374 326 ) 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 ) ); 376 343 ++formal; // can't be in for-loop update because of the continue 377 344 } … … 381 348 382 349 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 ) ); 384 365 } 385 366 … … 795 776 // compute conversionsion costs 796 777 for ( AltList::iterator withFunc = candidates.begin(); withFunc != candidates.end(); ++withFunc ) { 797 Cost cvtCost = compute ApplicationConversionCost( *withFunc, indexer );778 Cost cvtCost = computeConversionCost( *withFunc, indexer ); 798 779 799 780 PRINT( … … 914 895 // count one safe conversion for each value that is thrown away 915 896 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 ) ); 922 899 } // if 923 900 } // for … … 1162 1139 ConditionalExpr *newExpr = new ConditionalExpr( first->expr->clone(), second->expr->clone(), third->expr->clone() ); 1163 1140 newExpr->set_result( commonType ? commonType : second->expr->get_result()->clone() ); 1164 // convert both options to the conditional result type1165 newAlt.cost += computeExpressionConversionCost( newExpr->arg2, newExpr->result, indexer, newAlt.env );1166 newAlt.cost += computeExpressionConversionCost( newExpr->arg3, newExpr->result, indexer, newAlt.env );1167 1141 newAlt.expr = newExpr; 1168 1142 inferParameters( needAssertions, haveAssertions, newAlt, openVars, back_inserter( alternatives ) ); -
src/ResolvExpr/Cost.h
rf22b7aef rc04531fc 28 28 Cost & incSafe( int inc = 1 ); 29 29 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; }35 30 36 31 Cost operator+( const Cost &other ) const; -
src/libcfa/Makefile.am
rf22b7aef rc04531fc 36 36 ${AM_V_GEN}@BACKEND_CC@ @CFA_FLAGS@ -D__CFA_DEBUG__ -O0 -c -o $@ $< 37 37 38 EXTRA_FLAGS = -g -Wall -W error -Wno-unused-function -imacros libcfa-prelude.c @CFA_FLAGS@38 EXTRA_FLAGS = -g -Wall -Wno-unused-function -imacros libcfa-prelude.c @CFA_FLAGS@ 39 39 40 40 AM_CCASFLAGS = @CFA_FLAGS@ -
src/libcfa/Makefile.in
rf22b7aef rc04531fc 416 416 ARFLAGS = cr 417 417 lib_LIBRARIES = $(am__append_1) $(am__append_2) 418 EXTRA_FLAGS = -g -Wall -W error -Wno-unused-function -imacros libcfa-prelude.c @CFA_FLAGS@418 EXTRA_FLAGS = -g -Wall -Wno-unused-function -imacros libcfa-prelude.c @CFA_FLAGS@ 419 419 AM_CCASFLAGS = @CFA_FLAGS@ 420 420 headers = fstream iostream iterator limits rational stdlib \ -
src/libcfa/exception.h
rf22b7aef rc04531fc 29 29 struct __cfaehm__base_exception_t * other); 30 30 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); 32 32 }; 33 33 struct __cfaehm__base_exception_t {
Note: See TracChangeset
for help on using the changeset viewer.