Changeset 1cdfa82 for src/ResolvExpr
- Timestamp:
- Apr 25, 2018, 4:55:53 PM (6 years ago)
- Branches:
- new-env, with_gc
- Children:
- 42107b4
- Parents:
- 2efe4b8 (diff), 9d5fb67 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - Location:
- src/ResolvExpr
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
src/ResolvExpr/AlternativeFinder.cc
r2efe4b8 r1cdfa82 1238 1238 } 1239 1239 1240 Expression * restructureCast( Expression * argExpr, Type * toType ) {1240 Expression * restructureCast( Expression * argExpr, Type * toType, bool isGenerated ) { 1241 1241 if ( argExpr->get_result()->size() > 1 && ! toType->isVoid() && ! dynamic_cast<ReferenceType *>( toType ) ) { 1242 1242 // Argument expression is a tuple and the target type is not void and not a reference type. … … 1253 1253 // cast each component 1254 1254 TupleIndexExpr * idx = new TupleIndexExpr( argExpr->clone(), i ); 1255 componentExprs.push_back( restructureCast( idx, toType->getComponent( i ) ) );1255 componentExprs.push_back( restructureCast( idx, toType->getComponent( i ), isGenerated ) ); 1256 1256 } 1257 1257 assert( componentExprs.size() > 0 ); … … 1260 1260 } else { 1261 1261 // handle normally 1262 return new CastExpr( argExpr, toType->clone() ); 1262 CastExpr * ret = new CastExpr( argExpr, toType->clone() ); 1263 ret->isGenerated = isGenerated; 1264 return ret; 1263 1265 } 1264 1266 } … … 1304 1306 // count one safe conversion for each value that is thrown away 1305 1307 thisCost.incSafe( discardedValues ); 1306 Alternative newAlt( restructureCast( alt.expr->clone(), toType ), alt.env,1308 Alternative newAlt( restructureCast( alt.expr->clone(), toType, castExpr->isGenerated ), alt.env, 1307 1309 alt.cost, thisCost ); 1308 1310 inferParameters( needAssertions, haveAssertions, newAlt, openVars, … … 1727 1729 // count one safe conversion for each value that is thrown away 1728 1730 thisCost.incSafe( discardedValues ); 1729 Alternative newAlt( new InitExpr( restructureCast( alt.expr->clone(), toType ), initAlt.designation->clone() ), newEnv, alt.cost, thisCost );1731 Alternative newAlt( new InitExpr( restructureCast( alt.expr->clone(), toType, true ), initAlt.designation->clone() ), newEnv, alt.cost, thisCost ); 1730 1732 inferParameters( needAssertions, haveAssertions, newAlt, openVars, back_inserter( candidates ) ); 1731 1733 } -
src/ResolvExpr/CommonType.cc
r2efe4b8 r1cdfa82 28 28 29 29 // #define DEBUG 30 #ifdef DEBUG 31 #define PRINT(x) x 32 #else 33 #define PRINT(x) 34 #endif 30 35 31 36 namespace ResolvExpr { … … 70 75 // need unify to bind type variables 71 76 if ( unify( t1, t2, env, have, need, newOpen, indexer, common ) ) { 72 // std::cerr << "unify success: " << widenFirst << " " << widenSecond << std::endl; 77 PRINT( 78 std::cerr << "unify success: " << widenFirst << " " << widenSecond << std::endl; 79 ) 73 80 if ( (widenFirst || t2->get_qualifiers() <= t1->get_qualifiers()) && (widenSecond || t1->get_qualifiers() <= t2->get_qualifiers()) ) { 74 // std::cerr << "widen okay" << std::endl; 81 PRINT( 82 std::cerr << "widen okay" << std::endl; 83 ) 75 84 common->get_qualifiers() |= t1->get_qualifiers(); 76 85 common->get_qualifiers() |= t2->get_qualifiers(); … … 78 87 } 79 88 } 80 // std::cerr << "exact unify failed: " << t1 << " " << t2 << std::endl; 89 PRINT( 90 std::cerr << "exact unify failed: " << t1 << " " << t2 << std::endl; 91 ) 81 92 return nullptr; 82 93 } … … 90 101 int diff = depth1-depth2; 91 102 // TODO: should it be possible for commonType to generate complicated conversions? I would argue no, only conversions that involve types of the same reference level or a difference of 1 should be allowed. 92 if ( diff > 1 || diff < -1 ) return nullptr;103 // if ( diff > 1 || diff < -1 ) return nullptr; 93 104 94 105 // special case where one type has a reference depth of 1 larger than the other 95 106 if ( diff > 0 || diff < 0 ) { 96 // std::cerr << "reference depth diff: " << diff << std::endl; 107 PRINT( 108 std::cerr << "reference depth diff: " << diff << std::endl; 109 ) 97 110 Type * result = nullptr; 98 111 ReferenceType * ref1 = dynamic_cast< ReferenceType * >( type1 ); … … 109 122 if ( result && ref1 ) { 110 123 // formal is reference, so result should be reference 111 // std::cerr << "formal is reference; result should be reference" << std::endl; 124 PRINT( 125 std::cerr << "formal is reference; result should be reference" << std::endl; 126 ) 112 127 result = new ReferenceType( ref1->get_qualifiers(), result ); 113 128 } 114 // std::cerr << "common type of reference [" << type1 << "] and [" << type2 << "] is [" << result << "]" << std::endl; 129 PRINT( 130 std::cerr << "common type of reference [" << type1 << "] and [" << type2 << "] is [" << result << "]" << std::endl; 131 ) 115 132 return result; 116 133 } -
src/ResolvExpr/ConversionCost.cc
r2efe4b8 r1cdfa82 276 276 // xxx - not positive this is correct, but appears to allow casting int => enum 277 277 cost = Cost::unsafe; 278 } else if ( dynamic_cast< ZeroType* >( dest ) != nullptr || dynamic_cast< OneType* >( dest ) != nullptr ) { 279 cost = Cost::unsafe; 280 } // if 278 } // if 279 // no cases for zero_t/one_t because it should not be possible to convert int, etc. to zero_t/one_t. 281 280 } 282 281 … … 310 309 // assignResult == 0 means Cost::Infinity 311 310 } // if 312 } else if ( dynamic_cast< ZeroType * >( dest ) ) { 313 cost = Cost::unsafe; 311 // case case for zero_t because it should not be possible to convert pointers to zero_t. 314 312 } // if 315 313 } -
src/ResolvExpr/Resolver.cc
r2efe4b8 r1cdfa82 60 60 void previsit( TypeDecl *typeDecl ); 61 61 void previsit( EnumDecl * enumDecl ); 62 void previsit( StaticAssertDecl * assertDecl ); 62 63 63 64 void previsit( ArrayType * at ); … … 365 366 } 366 367 368 void Resolver::previsit( StaticAssertDecl * assertDecl ) { 369 findIntegralExpression( assertDecl->condition, indexer ); 370 } 371 367 372 void Resolver::previsit( ExprStmt *exprStmt ) { 368 373 visit_children = false;
Note: See TracChangeset
for help on using the changeset viewer.