Changeset 1dd1bd2
- Timestamp:
- Oct 3, 2018, 2:22:44 PM (6 years ago)
- Branches:
- ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, deferred_resn, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, no_list, persistent-indexer, pthread-emulation, qualifiedEnum
- Children:
- 588c2b0
- Parents:
- 04bdc26
- Location:
- src
- Files:
-
- 1 added
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
TabularUnified src/Makefile.am ¶
r04bdc26 r1dd1bd2 128 128 ResolvExpr/Resolver.cc \ 129 129 ResolvExpr/ResolveTypeof.cc \ 130 ResolvExpr/SpecCost.cc \ 130 131 ResolvExpr/TypeEnvironment.cc \ 131 132 ResolvExpr/Unify.cc \ -
TabularUnified src/Makefile.in ¶
r04bdc26 r1dd1bd2 205 205 ResolvExpr/RenameVars.$(OBJEXT) ResolvExpr/Resolver.$(OBJEXT) \ 206 206 ResolvExpr/ResolveTypeof.$(OBJEXT) \ 207 ResolvExpr/SpecCost.$(OBJEXT) \ 207 208 ResolvExpr/TypeEnvironment.$(OBJEXT) \ 208 209 ResolvExpr/Unify.$(OBJEXT) SymTab/Autogen.$(OBJEXT) \ … … 259 260 ResolvExpr/TypeEnvironment.$(OBJEXT) \ 260 261 ResolvExpr/CurrentObject.$(OBJEXT) \ 261 ResolvExpr/ExplodedActual.$(OBJEXT) SymTab/Indexer.$(OBJEXT) \ 262 ResolvExpr/ExplodedActual.$(OBJEXT) \ 263 ResolvExpr/SpecCost.$(OBJEXT) SymTab/Indexer.$(OBJEXT) \ 262 264 SymTab/Mangler.$(OBJEXT) SymTab/ManglerCommon.$(OBJEXT) \ 263 265 SymTab/Validate.$(OBJEXT) SymTab/FixFunction.$(OBJEXT) \ … … 547 549 ResolvExpr/Occurs.cc ResolvExpr/TypeEnvironment.cc \ 548 550 ResolvExpr/CurrentObject.cc ResolvExpr/ExplodedActual.cc \ 549 SymTab/Indexer.cc SymTab/Mangler.cc SymTab/ManglerCommon.cc \ 550 SymTab/Validate.cc SymTab/FixFunction.cc SymTab/Autogen.cc \ 551 SynTree/Type.cc SynTree/VoidType.cc SynTree/BasicType.cc \ 551 ResolvExpr/SpecCost.cc SymTab/Indexer.cc SymTab/Mangler.cc \ 552 SymTab/ManglerCommon.cc SymTab/Validate.cc \ 553 SymTab/FixFunction.cc SymTab/Autogen.cc SynTree/Type.cc \ 554 SynTree/VoidType.cc SynTree/BasicType.cc \ 552 555 SynTree/PointerType.cc SynTree/ArrayType.cc \ 553 556 SynTree/ReferenceType.cc SynTree/FunctionType.cc \ … … 656 659 ResolvExpr/Resolver.cc \ 657 660 ResolvExpr/ResolveTypeof.cc \ 661 ResolvExpr/SpecCost.cc \ 658 662 ResolvExpr/TypeEnvironment.cc \ 659 663 ResolvExpr/Unify.cc \ … … 908 912 ResolvExpr/ResolveTypeof.$(OBJEXT): ResolvExpr/$(am__dirstamp) \ 909 913 ResolvExpr/$(DEPDIR)/$(am__dirstamp) 914 ResolvExpr/SpecCost.$(OBJEXT): ResolvExpr/$(am__dirstamp) \ 915 ResolvExpr/$(DEPDIR)/$(am__dirstamp) 910 916 ResolvExpr/TypeEnvironment.$(OBJEXT): ResolvExpr/$(am__dirstamp) \ 911 917 ResolvExpr/$(DEPDIR)/$(am__dirstamp) … … 1160 1166 @AMDEP_TRUE@@am__include@ @am__quote@ResolvExpr/$(DEPDIR)/ResolveTypeof.Po@am__quote@ 1161 1167 @AMDEP_TRUE@@am__include@ @am__quote@ResolvExpr/$(DEPDIR)/Resolver.Po@am__quote@ 1168 @AMDEP_TRUE@@am__include@ @am__quote@ResolvExpr/$(DEPDIR)/SpecCost.Po@am__quote@ 1162 1169 @AMDEP_TRUE@@am__include@ @am__quote@ResolvExpr/$(DEPDIR)/TypeEnvironment.Po@am__quote@ 1163 1170 @AMDEP_TRUE@@am__include@ @am__quote@ResolvExpr/$(DEPDIR)/Unify.Po@am__quote@ -
TabularUnified src/ResolvExpr/AlternativeFinder.cc ¶
r04bdc26 r1dd1bd2 410 410 Cost computeApplicationConversionCost( Alternative &alt, const SymTab::Indexer &indexer ) { 411 411 ApplicationExpr *appExpr = strict_dynamic_cast< ApplicationExpr* >( alt.expr ); 412 PointerType *pointer = strict_dynamic_cast< PointerType* >( appExpr-> get_function()->get_result());413 FunctionType *function = strict_dynamic_cast< FunctionType* >( pointer-> get_base());412 PointerType *pointer = strict_dynamic_cast< PointerType* >( appExpr->function->result ); 413 FunctionType *function = strict_dynamic_cast< FunctionType* >( pointer->base ); 414 414 415 415 Cost convCost = Cost::zero; 416 std::list< DeclarationWithType* >& formals = function-> get_parameters();416 std::list< DeclarationWithType* >& formals = function->parameters; 417 417 std::list< DeclarationWithType* >::iterator formal = formals.begin(); 418 std::list< Expression* >& actuals = appExpr-> get_args();419 420 for ( std::list< Expression* >::iterator actualExpr = actuals.begin(); actualExpr != actuals.end(); ++actualExpr) {421 Type * actualType = (*actualExpr)->get_result();418 std::list< Expression* >& actuals = appExpr->args; 419 420 for ( Expression*& actualExpr : actuals ) { 421 Type * actualType = actualExpr->result; 422 422 PRINT( 423 423 std::cerr << "actual expression:" << std::endl; 424 (*actualExpr)->print( std::cerr, 8 );424 actualExpr->print( std::cerr, 8 ); 425 425 std::cerr << "--- results are" << std::endl; 426 426 actualType->print( std::cerr, 8 ); 427 427 ) 428 428 if ( formal == formals.end() ) { 429 if ( function-> get_isVarArgs()) {429 if ( function->isVarArgs ) { 430 430 convCost.incUnsafe(); 431 431 PRINT( std::cerr << "end of formals with varargs function: inc unsafe: " << convCost << std::endl; ; ) 432 432 // convert reference-typed expressions to value-typed expressions 433 referenceToRvalueConversion( *actualExpr, convCost );433 referenceToRvalueConversion( actualExpr, convCost ); 434 434 continue; 435 435 } else { … … 437 437 } 438 438 } 439 if ( DefaultArgExpr * def = dynamic_cast< DefaultArgExpr * >( *actualExpr ) ) {439 if ( DefaultArgExpr * def = dynamic_cast< DefaultArgExpr * >( actualExpr ) ) { 440 440 // default arguments should be free - don't include conversion cost. 441 441 // Unwrap them here because they are not relevant to the rest of the system. 442 *actualExpr = def->expr;442 actualExpr = def->expr; 443 443 ++formal; 444 444 continue; 445 445 } 446 // mark conversion cost to formal and also specialization cost of formal type 446 447 Type * formalType = (*formal)->get_type(); 447 convCost += computeExpressionConversionCost( *actualExpr, formalType, indexer, alt.env ); 448 convCost += computeExpressionConversionCost( actualExpr, formalType, indexer, alt.env ); 449 convCost.decSpec( specCost( formalType ) ); 448 450 ++formal; // can't be in for-loop update because of the continue 449 451 } … … 452 454 } 453 455 456 // mark specialization cost of return types 457 for ( DeclarationWithType* returnVal : function->returnVals ) { 458 convCost.decSpec( specCost( returnVal->get_type() ) ); 459 } 460 461 // mark type variable and specialization cost of forall clause 462 convCost.incVar( function->forall.size() ); 463 for ( TypeDecl* td : function->forall ) { 464 convCost.decSpec( td->assertions.size() ); 465 } 466 467 // xxx -- replace with new costs in resolver 454 468 for ( InferredParams::const_iterator assert = appExpr->get_inferParams().begin(); assert != appExpr->get_inferParams().end(); ++assert ) { 455 469 convCost += computeConversionCost( assert->second.actualType, assert->second.formalType, indexer, alt.env ); -
TabularUnified src/ResolvExpr/ConversionCost.cc ¶
r04bdc26 r1dd1bd2 28 28 29 29 namespace ResolvExpr { 30 const Cost Cost::zero = Cost( 0, 0, 0, 0 ); 31 const Cost Cost::infinity = Cost( -1, -1, -1, -1 ); 32 const Cost Cost::unsafe = Cost( 1, 0, 0, 0 ); 33 const Cost Cost::poly = Cost( 0, 1, 0, 0 ); 34 const Cost Cost::safe = Cost( 0, 0, 1, 0 ); 35 const Cost Cost::reference = Cost( 0, 0, 0, 1 ); 30 const Cost Cost::zero = Cost{ 0, 0, 0, 0, 0, 0 }; 31 const Cost Cost::infinity = Cost{ -1, -1, -1, 1, -1, -1 }; 32 const Cost Cost::unsafe = Cost{ 1, 0, 0, 0, 0, 0 }; 33 const Cost Cost::poly = Cost{ 0, 1, 0, 0, 0, 0 }; 34 const Cost Cost::var = Cost{ 0, 0, 1, 0, 0, 0 }; 35 const Cost Cost::spec = Cost{ 0, 0, 0, -1, 0, 0 }; 36 const Cost Cost::safe = Cost{ 0, 0, 0, 0, 1, 0 }; 37 const Cost Cost::reference = Cost{ 0, 0, 0, 0, 0, 1 }; 36 38 37 39 #if 0 -
TabularUnified src/ResolvExpr/Cost.h ¶
r04bdc26 r1dd1bd2 9 9 // Author : Richard C. Bilson 10 10 // Created On : Sun May 17 09:39:50 2015 11 // Last Modified By : Peter A. Buhr12 // Last Modified On : Sat Jul 22 09:35:55 201713 // Update Count : 511 // Last Modified By : Aaron B. Moss 12 // Last Modified On : Tue Oct 02 14:40:00 2018 13 // Update Count : 6 14 14 // 15 15 … … 21 21 class Cost { 22 22 private: 23 Cost( int unsafeCost, int polyCost, int safeCost, int referenceCost ); 23 Cost( int unsafeCost, int polyCost, int varCost, int specCost, int safeCost, 24 int referenceCost ); 24 25 25 26 public: 26 27 Cost & incUnsafe( int inc = 1 ); 27 28 Cost & incPoly( int inc = 1 ); 29 Cost & incVar( int inc = 1 ); 30 Cost & decSpec( int inc = 1 ); 28 31 Cost & incSafe( int inc = 1 ); 29 32 Cost & incReference( int inc = 1 ); … … 31 34 int get_unsafeCost() const { return unsafeCost; } 32 35 int get_polyCost() const { return polyCost; } 36 int get_varCost() const { return varCost; } 37 int get_specCost() const { return specCost; } 33 38 int get_safeCost() const { return safeCost; } 34 39 int get_referenceCost() const { return referenceCost; } … … 47 52 static const Cost unsafe; 48 53 static const Cost poly; 54 static const Cost var; 55 static const Cost spec; 49 56 static const Cost safe; 50 57 static const Cost reference; … … 52 59 int compare( const Cost &other ) const; 53 60 54 int unsafeCost; 55 int polyCost; 56 int safeCost; 57 int referenceCost; 61 int unsafeCost; ///< Unsafe (narrowing) conversions 62 int polyCost; ///< Count of parameters and return values bound to some poly type 63 int varCost; ///< Count of polymorphic type variables 64 int specCost; ///< Polymorphic type specializations (type assertions), negative cost 65 int safeCost; ///< Safe (widening) conversions 66 int referenceCost; ///< reference conversions 58 67 }; 59 68 60 inline Cost::Cost( int unsafeCost, int polyCost, int safeCost, int referenceCost ) : unsafeCost( unsafeCost ), polyCost( polyCost ), safeCost( safeCost ), referenceCost( referenceCost ) {} 69 inline Cost::Cost( int unsafeCost, int polyCost, int varCost, int specCost, int safeCost, 70 int referenceCost ) 71 : unsafeCost( unsafeCost ), polyCost( polyCost ), varCost( varCost ), specCost( specCost ), 72 safeCost( safeCost ), referenceCost( referenceCost ) {} 61 73 62 74 inline Cost & Cost::incUnsafe( int inc ) { … … 69 81 if ( *this == infinity ) return *this; 70 82 polyCost += inc; 83 return *this; 84 } 85 86 inline Cost & Cost::incVar( int inc ) { 87 if ( *this == infinity ) return *this; 88 varCost += inc; 89 return *this; 90 } 91 92 inline Cost& Cost::decSpec( int dec ) { 93 if ( *this == infinity ) return *this; 94 specCost -= dec; 71 95 return *this; 72 96 } … … 86 110 inline Cost Cost::operator+( const Cost &other ) const { 87 111 if ( *this == infinity || other == infinity ) return infinity; 88 return Cost( unsafeCost + other.unsafeCost, polyCost + other.polyCost, safeCost + other.safeCost, referenceCost + other.referenceCost ); 112 return Cost{ 113 unsafeCost + other.unsafeCost, polyCost + other.polyCost, 114 varCost + other.varCost, specCost + other.specCost, 115 safeCost + other.safeCost, referenceCost + other.referenceCost }; 89 116 } 90 117 91 118 inline Cost Cost::operator-( const Cost &other ) const { 92 119 if ( *this == infinity || other == infinity ) return infinity; 93 return Cost( unsafeCost - other.unsafeCost, polyCost - other.polyCost, safeCost - other.safeCost, referenceCost - other.referenceCost ); 120 return Cost{ 121 unsafeCost - other.unsafeCost, polyCost - other.polyCost, 122 varCost - other.varCost, specCost - other.specCost, 123 safeCost - other.safeCost, referenceCost - other.referenceCost }; 94 124 } 95 125 … … 102 132 unsafeCost += other.unsafeCost; 103 133 polyCost += other.polyCost; 134 varCost += other.varCost; 135 specCost += other.specCost; 104 136 safeCost += other.safeCost; 105 137 referenceCost += other.referenceCost; … … 119 151 } else if ( polyCost < other.polyCost ) { 120 152 return true; 153 } else if ( varCost > other.varCost ) { 154 return false; 155 } else if ( varCost < other.varCost ) { 156 return true; 157 } else if ( specCost > other.specCost ) { 158 return false; 159 } else if ( specCost > other.specCost ) { 160 return true; 121 161 } else if ( safeCost > other.safeCost ) { 122 162 return false; … … 135 175 return unsafeCost == other.unsafeCost 136 176 && polyCost == other.polyCost 177 && varCost == other.varCost 178 && specCost == other.specCost 137 179 && safeCost == other.safeCost 138 180 && referenceCost == other.referenceCost; … … 144 186 145 187 inline std::ostream &operator<<( std::ostream &os, const Cost &cost ) { 146 os << "( " << cost.unsafeCost << ", " << cost.polyCost << ", " << cost.safeCost << ", " << cost.referenceCost << " )"; 147 return os; 188 return os << "( " << cost.unsafeCost << ", " << cost.polyCost << ", " 189 << cost.varCost << ", " << cost.specCost << ", " 190 << cost.safeCost << ", " << cost.referenceCost << " )"; 148 191 } 149 192 } // namespace ResolvExpr -
TabularUnified src/ResolvExpr/module.mk ¶
r04bdc26 r1dd1bd2 33 33 ResolvExpr/TypeEnvironment.cc \ 34 34 ResolvExpr/CurrentObject.cc \ 35 ResolvExpr/ExplodedActual.cc 35 ResolvExpr/ExplodedActual.cc \ 36 ResolvExpr/SpecCost.cc -
TabularUnified src/ResolvExpr/typeops.h ¶
r04bdc26 r1dd1bd2 102 102 int polyCost( Type *type, const TypeEnvironment &env, const SymTab::Indexer &indexer ); 103 103 104 // in SpecCost.cc 105 int specCost( Type *type ); 106 104 107 // in Occurs.cc 105 108 bool occurs( Type *type, std::string varName, const TypeEnvironment &env );
Note: See TracChangeset
for help on using the changeset viewer.