Changeset dcbb03b for src/ResolvExpr
- Timestamp:
- Mar 1, 2018, 9:29:03 AM (8 years ago)
- Branches:
- ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, deferred_resn, demangler, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, with_gc
- Children:
- 1f37ed02
- Parents:
- b002261 (diff), 446ffa3 (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:
-
- 5 edited
-
AlternativeFinder.cc (modified) (17 diffs)
-
ConversionCost.cc (modified) (1 diff)
-
CurrentObject.cc (modified) (4 diffs)
-
Resolver.cc (modified) (12 diffs)
-
typeops.h (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
src/ResolvExpr/AlternativeFinder.cc
rb002261 rdcbb03b 204 204 } // namespace 205 205 206 void referenceToRvalueConversion( Expression *& expr ) {206 void referenceToRvalueConversion( Expression *& expr, Cost & cost ) { 207 207 if ( dynamic_cast< ReferenceType * >( expr->get_result() ) ) { 208 208 // cast away reference from expr 209 209 expr = new CastExpr( expr, expr->get_result()->stripReferences()->clone() ); 210 cost.incReference(); 210 211 } 211 212 } … … 239 240 std::cerr << "No reasonable alternatives for expression " << expr << std::endl; 240 241 ) 241 throwSemanticError( expr, "No reasonable alternatives for expression " );242 SemanticError( expr, "No reasonable alternatives for expression " ); 242 243 } 243 244 if ( prune ) { … … 257 258 stream << " Alternatives are:\n"; 258 259 printAlts( winners, stream, 1 ); 259 throwSemanticError( expr->location, stream.str() );260 SemanticError( expr->location, stream.str() ); 260 261 } 261 262 alternatives = move(pruned); … … 435 436 PRINT( std::cerr << "end of formals with varargs function: inc unsafe: " << convCost << std::endl; ; ) 436 437 // convert reference-typed expressions to value-typed expressions 437 referenceToRvalueConversion( *actualExpr );438 referenceToRvalueConversion( *actualExpr, convCost ); 438 439 continue; 439 440 } else { … … 494 495 return; 495 496 } else if ( level >= recursionLimit ) { 496 throwSemanticError( newAlt.expr->location, "Too many recursive assertions" );497 SemanticError( newAlt.expr->location, "Too many recursive assertions" ); 497 498 } else { 498 499 AssertionSet newerNeed; … … 565 566 // DOESN'T WORK: grandchild nodes conflict with their cousins 566 567 //if ( newNeedParents[ curDecl->get_uniqueId() ][ candDecl->get_uniqueId() ]++ > recursionParentLimit ) continue; 567 Expression *varExpr = data.combine(); 568 569 Expression *varExpr = data.combine( newerAlt.cvtCost ); 568 570 delete varExpr->get_result(); 569 571 varExpr->set_result( adjType->clone() ); … … 1110 1112 1111 1113 AltList candidates; 1112 SemanticError errors;1114 SemanticErrorException errors; 1113 1115 for ( AltList::iterator func = funcFinder.alternatives.begin(); func != funcFinder.alternatives.end(); ++func ) { 1114 1116 try { … … 1121 1123 if ( FunctionType *function = dynamic_cast< FunctionType* >( pointer->get_base() ) ) { 1122 1124 Alternative newFunc( *func ); 1123 referenceToRvalueConversion( newFunc.expr );1125 referenceToRvalueConversion( newFunc.expr, newFunc.cost ); 1124 1126 makeFunctionAlternatives( newFunc, function, argExpansions, 1125 1127 std::back_inserter( candidates ) ); … … 1130 1132 if ( FunctionType *function = dynamic_cast< FunctionType* >( eqvClass.type ) ) { 1131 1133 Alternative newFunc( *func ); 1132 referenceToRvalueConversion( newFunc.expr );1134 referenceToRvalueConversion( newFunc.expr, newFunc.cost ); 1133 1135 makeFunctionAlternatives( newFunc, function, argExpansions, 1134 1136 std::back_inserter( candidates ) ); … … 1136 1138 } // if 1137 1139 } 1138 } catch ( SemanticError &e ) {1140 } catch ( SemanticErrorException &e ) { 1139 1141 errors.append( e ); 1140 1142 } … … 1160 1162 dynamic_cast<FunctionType*>( pointer->get_base() ) ) { 1161 1163 Alternative newFunc( *funcOp ); 1162 referenceToRvalueConversion( newFunc.expr );1164 referenceToRvalueConversion( newFunc.expr, newFunc.cost ); 1163 1165 makeFunctionAlternatives( newFunc, function, argExpansions, 1164 1166 std::back_inserter( candidates ) ); 1165 1167 } 1166 1168 } 1167 } catch ( SemanticError &e ) {1169 } catch ( SemanticErrorException &e ) { 1168 1170 errors.append( e ); 1169 1171 } … … 1344 1346 for ( AltList::const_iterator agg = funcFinder.alternatives.begin(); agg != funcFinder.alternatives.end(); ++agg ) { 1345 1347 // it's okay for the aggregate expression to have reference type -- cast it to the base type to treat the aggregate as the referenced value 1346 std::unique_ptr<Expression> aggrExpr( agg->expr->clone() ); 1347 Type * aggrType = aggrExpr->get_result(); 1348 if ( dynamic_cast< ReferenceType * >( aggrType ) ) { 1349 aggrType = aggrType->stripReferences(); 1350 aggrExpr.reset( new CastExpr( aggrExpr.release(), aggrType->clone() ) ); 1351 } 1348 Cost cost = agg->cost; 1349 Expression * aggrExpr = agg->expr->clone(); 1350 referenceToRvalueConversion( aggrExpr, cost ); 1351 std::unique_ptr<Expression> guard( aggrExpr ); 1352 1352 1353 // find member of the given type 1353 1354 if ( StructInstType *structInst = dynamic_cast< StructInstType* >( aggrExpr->get_result() ) ) { 1354 addAggMembers( structInst, aggrExpr .get(), agg->cost, agg->env, memberExpr->get_member() );1355 addAggMembers( structInst, aggrExpr, cost, agg->env, memberExpr->get_member() ); 1355 1356 } else if ( UnionInstType *unionInst = dynamic_cast< UnionInstType* >( aggrExpr->get_result() ) ) { 1356 addAggMembers( unionInst, aggrExpr .get(), agg->cost, agg->env, memberExpr->get_member() );1357 addAggMembers( unionInst, aggrExpr, cost, agg->env, memberExpr->get_member() ); 1357 1358 } else if ( TupleType * tupleType = dynamic_cast< TupleType * >( aggrExpr->get_result() ) ) { 1358 addTupleMembers( tupleType, aggrExpr .get(), agg->cost, agg->env, memberExpr->get_member() );1359 addTupleMembers( tupleType, aggrExpr, cost, agg->env, memberExpr->get_member() ); 1359 1360 } // if 1360 1361 } // for … … 1370 1371 PRINT( std::cerr << "nameExpr is " << nameExpr->name << std::endl; ) 1371 1372 for ( auto & data : declList ) { 1372 Expression * newExpr = data.combine();1373 // xxx - add in extra cost for with-statement exprs?1374 alternatives.push_back( Alternative( newExpr, env, Cost::zero ) );1373 Cost cost = Cost::zero; 1374 Expression * newExpr = data.combine( cost ); 1375 alternatives.push_back( Alternative( newExpr, env, Cost::zero, cost ) ); 1375 1376 PRINT( 1376 1377 std::cerr << "decl is "; … … 1408 1409 findMinCost( finder.alternatives.begin(), finder.alternatives.end(), back_inserter( winners ) ); 1409 1410 if ( winners.size() != 1 ) { 1410 throwSemanticError( sizeofExpr->get_expr(), "Ambiguous expression in sizeof operand: " );1411 SemanticError( sizeofExpr->get_expr(), "Ambiguous expression in sizeof operand: " ); 1411 1412 } // if 1412 1413 // return the lowest cost alternative for the argument 1413 1414 Alternative &choice = winners.front(); 1414 referenceToRvalueConversion( choice.expr );1415 referenceToRvalueConversion( choice.expr, choice.cost ); 1415 1416 alternatives.push_back( Alternative( new SizeofExpr( choice.expr->clone() ), choice.env, Cost::zero ) ); 1416 1417 } // if … … 1429 1430 findMinCost( finder.alternatives.begin(), finder.alternatives.end(), back_inserter( winners ) ); 1430 1431 if ( winners.size() != 1 ) { 1431 throwSemanticError( alignofExpr->get_expr(), "Ambiguous expression in alignof operand: " );1432 SemanticError( alignofExpr->get_expr(), "Ambiguous expression in alignof operand: " ); 1432 1433 } // if 1433 1434 // return the lowest cost alternative for the argument 1434 1435 Alternative &choice = winners.front(); 1435 referenceToRvalueConversion( choice.expr );1436 referenceToRvalueConversion( choice.expr, choice.cost ); 1436 1437 alternatives.push_back( Alternative( new AlignofExpr( choice.expr->clone() ), choice.env, Cost::zero ) ); 1437 1438 } // if … … 1485 1486 AltList & alternatives = finder.get_alternatives(); 1486 1487 if ( typesCompatibleIgnoreQualifiers( argType, function->get_parameters().front()->get_type(), indexer, env ) ) { 1487 alternatives.push_back( Alternative( new AttrExpr( data.combine(), argType->clone() ), env, Cost::zero ) ); 1488 Cost cost = Cost::zero; 1489 Expression * newExpr = data.combine( cost ); 1490 alternatives.push_back( Alternative( new AttrExpr( newExpr, argType->clone() ), env, Cost::zero, cost ) ); 1488 1491 for ( DeclarationWithType * retVal : function->returnVals ) { 1489 1492 alternatives.back().expr->result = retVal->get_type()->clone(); … … 1522 1525 } else { 1523 1526 for ( auto & data : attrList ) { 1524 alternatives.push_back( Alternative( data.combine(), env, Cost::zero ) ); 1527 Cost cost = Cost::zero; 1528 Expression * newExpr = data.combine( cost ); 1529 alternatives.push_back( Alternative( newExpr, env, Cost::zero, cost ) ); 1525 1530 renameTypes( alternatives.back().expr ); 1526 1531 } // for -
src/ResolvExpr/ConversionCost.cc
rb002261 rdcbb03b 170 170 Cost convertToReferenceCost( Type * src, ReferenceType * dest, const SymTab::Indexer & indexer, const TypeEnvironment & env, PtrsFunction func ) { 171 171 int sdepth = src->referenceDepth(), ddepth = dest->referenceDepth(); 172 return convertToReferenceCost( src, dest, sdepth-ddepth, indexer, env, func ); 172 Cost cost = convertToReferenceCost( src, dest, sdepth-ddepth, indexer, env, func ); 173 PRINT( std::cerr << "convertToReferenceCost result: " << cost << std::endl; ) 174 return cost; 173 175 } 174 176 -
src/ResolvExpr/CurrentObject.cc
rb002261 rdcbb03b 141 141 base = at->get_base(); 142 142 memberIter = createMemberIterator( base ); 143 if ( at->isVarLen ) throwSemanticError( at, "VLA initialization does not support @=" );143 if ( at->isVarLen ) SemanticError( at, "VLA initialization does not support @=" ); 144 144 setSize( at->get_dimension() ); 145 145 } … … 155 155 size = constExpr->intValue(); 156 156 PRINT( std::cerr << "array type with size: " << size << std::endl; ) 157 } catch ( SemanticError & ) {158 throwSemanticError( expr, "Constant expression of non-integral type in array dimension: " );157 } catch ( SemanticErrorException & ) { 158 SemanticError( expr, "Constant expression of non-integral type in array dimension: " ); 159 159 } 160 160 } else if ( CastExpr * castExpr = dynamic_cast< CastExpr * >( expr ) ) { … … 178 178 try { 179 179 index = constExpr->intValue(); 180 } catch( SemanticError & ) {181 throwSemanticError( expr, "Constant expression of non-integral type in array designator: " );180 } catch( SemanticErrorException & ) { 181 SemanticError( expr, "Constant expression of non-integral type in array designator: " ); 182 182 } 183 183 } else if ( CastExpr * castExpr = dynamic_cast< CastExpr * >( expr ) ) { … … 532 532 } // for 533 533 if ( desigAlts.size() > 1 ) { 534 throwSemanticError( designation, toString("Too many alternatives (", desigAlts.size(), ") for designation: ") );534 SemanticError( designation, toString("Too many alternatives (", desigAlts.size(), ") for designation: ") ); 535 535 } else if ( desigAlts.size() == 0 ) { 536 throwSemanticError( designation, "No reasonable alternatives for designation: " );536 SemanticError( designation, "No reasonable alternatives for designation: " ); 537 537 } 538 538 DesignatorChain & d = desigAlts.back(); -
src/ResolvExpr/Resolver.cc
rb002261 rdcbb03b 174 174 findMinCost( candidates.begin(), candidates.end(), back_inserter( winners ) ); 175 175 if ( winners.size() == 0 ) { 176 throwSemanticError( untyped, toString( "No reasonable alternatives for ", kindStr, (kindStr != "" ? " " : ""), "expression: ") );176 SemanticError( untyped, toString( "No reasonable alternatives for ", kindStr, (kindStr != "" ? " " : ""), "expression: ") ); 177 177 } else if ( winners.size() != 1 ) { 178 178 std::ostringstream stream; … … 181 181 stream << " Alternatives are:\n"; 182 182 printAlts( winners, stream, 1 ); 183 throwSemanticError( untyped->location, stream.str() );183 SemanticError( untyped->location, stream.str() ); 184 184 } 185 185 … … 187 187 Alternative & choice = winners.front(); 188 188 if ( findDeletedExpr( choice.expr ) ) { 189 throwSemanticError( choice.expr, "Unique best alternative includes deleted identifier in " );189 SemanticError( choice.expr, "Unique best alternative includes deleted identifier in " ); 190 190 } 191 191 alt = std::move( choice ); … … 484 484 ss << strict_dynamic_cast<NameExpr*>( clause.target.function )->name; 485 485 ss << "' in call to waitfor"; 486 throwSemanticError( stmt->location, ss.str() );486 SemanticError( stmt->location, ss.str() ); 487 487 } 488 488 … … 501 501 // try matching the arguments to the parameters 502 502 // not the other way around because we have more arguments than parameters 503 SemanticError errors;503 SemanticErrorException errors; 504 504 for ( Alternative & func : funcFinder.get_alternatives() ) { 505 505 try { 506 506 PointerType * pointer = dynamic_cast< PointerType* >( func.expr->get_result()->stripReferences() ); 507 507 if( !pointer ) { 508 throwSemanticError( func.expr->get_result(), "candidate not viable: not a pointer type\n" );508 SemanticError( func.expr->get_result(), "candidate not viable: not a pointer type\n" ); 509 509 } 510 510 511 511 FunctionType * function = dynamic_cast< FunctionType* >( pointer->get_base() ); 512 512 if( !function ) { 513 throwSemanticError( pointer->get_base(), "candidate not viable: not a function type\n" );513 SemanticError( pointer->get_base(), "candidate not viable: not a function type\n" ); 514 514 } 515 515 … … 520 520 521 521 if( !advance_to_mutex( param, param_end ) ) { 522 throwSemanticError(function, "candidate function not viable: no mutex parameters\n");522 SemanticError(function, "candidate function not viable: no mutex parameters\n"); 523 523 } 524 524 } … … 526 526 Alternative newFunc( func ); 527 527 // Strip reference from function 528 referenceToRvalueConversion( newFunc.expr );528 referenceToRvalueConversion( newFunc.expr, newFunc.cost ); 529 529 530 530 // For all the set of arguments we have try to match it with the parameter of the current function alternative … … 559 559 // We ran out of parameters but still have arguments 560 560 // this function doesn't match 561 throwSemanticError( function, "candidate function not viable: too many mutex arguments\n" );561 SemanticError( function, "candidate function not viable: too many mutex arguments\n" ); 562 562 } 563 563 … … 571 571 (*param)->get_type()->print( ss ); 572 572 ss << "'\n"; 573 throwSemanticError( function, ss.str() );573 SemanticError( function, ss.str() ); 574 574 } 575 575 … … 583 583 // We ran out of arguments but still have parameters left 584 584 // this function doesn't match 585 throwSemanticError( function, "candidate function not viable: too few mutex arguments\n" );585 SemanticError( function, "candidate function not viable: too few mutex arguments\n" ); 586 586 } 587 587 … … 599 599 600 600 } 601 catch( SemanticError &e ) {601 catch( SemanticErrorException &e ) { 602 602 errors.append( e ); 603 603 } 604 604 } 605 605 } 606 catch( SemanticError &e ) {606 catch( SemanticErrorException &e ) { 607 607 errors.append( e ); 608 608 } … … 610 610 611 611 // Make sure we got the right number of arguments 612 if( func_candidates.empty() ) { SemanticError top( stmt->location, "No alternatives for function in call to waitfor" ); top.append( errors ); throw top; }613 if( args_candidates.empty() ) { SemanticError top( stmt->location, "No alternatives for arguments in call to waitfor" ); top.append( errors ); throw top; }614 if( func_candidates.size() > 1 ) { SemanticError top( stmt->location, "Ambiguous function in call to waitfor" ); top.append( errors ); throw top; }615 if( args_candidates.size() > 1 ) { SemanticError top( stmt->location, "Ambiguous arguments in call to waitfor" ); top.append( errors ); throw top; }612 if( func_candidates.empty() ) { SemanticErrorException top( stmt->location, "No alternatives for function in call to waitfor" ); top.append( errors ); throw top; } 613 if( args_candidates.empty() ) { SemanticErrorException top( stmt->location, "No alternatives for arguments in call to waitfor" ); top.append( errors ); throw top; } 614 if( func_candidates.size() > 1 ) { SemanticErrorException top( stmt->location, "Ambiguous function in call to waitfor" ); top.append( errors ); throw top; } 615 if( args_candidates.size() > 1 ) { SemanticErrorException top( stmt->location, "Ambiguous arguments in call to waitfor" ); top.append( errors ); throw top; } 616 616 // TODO: need to use findDeletedExpr to ensure no deleted identifiers are used. 617 617 -
src/ResolvExpr/typeops.h
rb002261 rdcbb03b 106 106 107 107 // in AlternativeFinder.cc 108 void referenceToRvalueConversion( Expression *& expr );108 void referenceToRvalueConversion( Expression *& expr, Cost & cost ); 109 109 110 110 // flatten tuple type into list of types
Note:
See TracChangeset
for help on using the changeset viewer.