- Timestamp:
- Feb 21, 2018, 4:07:10 PM (7 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:
- 5a806be4
- Parents:
- 599fbb6
- git-author:
- Rob Schluntz <rschlunt@…> (02/21/18 15:52:43)
- git-committer:
- Rob Schluntz <rschlunt@…> (02/21/18 16:07:10)
- Location:
- src
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
src/ResolvExpr/AlternativeFinder.cc
r599fbb6 ra181494 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 } … … 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 { … … 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.cost ); 568 570 delete varExpr->get_result(); 569 571 varExpr->set_result( adjType->clone() ); … … 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 ) ); … … 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 ) ); … … 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 ) ); // xxx 1375 1376 PRINT( 1376 1377 std::cerr << "decl is "; … … 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 … … 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 ) ); 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 ) ); 1525 1530 renameTypes( alternatives.back().expr ); 1526 1531 } // for -
src/ResolvExpr/Resolver.cc
r599fbb6 ra181494 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 -
src/ResolvExpr/typeops.h
r599fbb6 ra181494 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 -
src/SymTab/Indexer.cc
r599fbb6 ra181494 603 603 if ( dynamic_cast< StructInstType * >( t ) || dynamic_cast< UnionInstType * >( t ) ) { 604 604 Expression * base = expr->clone(); 605 ResolvExpr::referenceToRvalueConversion( base ); 605 ResolvExpr::Cost cost = ResolvExpr::Cost::zero; // xxx - carry this cost into the indexer as a base cost? 606 ResolvExpr::referenceToRvalueConversion( base, cost ); 606 607 addMembers( t->getAggr(), new MemberExpr( dwt, base ), handleConflicts ); 607 608 } … … 705 706 } 706 707 707 Expression * Indexer::IdData::combine( ) const {708 Expression * Indexer::IdData::combine( ResolvExpr::Cost & cost ) const { 708 709 Expression * ret = nullptr; 709 710 if ( baseExpr ) { 710 711 Expression * base = baseExpr->clone(); 711 ResolvExpr::referenceToRvalueConversion( base );712 ResolvExpr::referenceToRvalueConversion( base, cost ); 712 713 ret = new MemberExpr( id, base ); 713 714 // xxx - this introduces hidden environments, for now remove them. -
src/SymTab/Indexer.h
r599fbb6 ra181494 23 23 #include "SynTree/Visitor.h" // for Visitor 24 24 #include "SynTree/SynTree.h" // for AST nodes 25 26 namespace ResolvExpr { 27 class Cost; 28 } 25 29 26 30 namespace SymTab { … … 51 55 IdData( DeclarationWithType * id, Expression * baseExpr, BaseSyntaxNode * deleteStmt ) : id( id ), baseExpr( baseExpr ), deleteStmt( deleteStmt ) {} 52 56 53 Expression * combine( ) const;57 Expression * combine( ResolvExpr::Cost & cost ) const; 54 58 }; 55 59
Note: See TracChangeset
for help on using the changeset viewer.