Changes in / [7a780ad:38093ae]
- Location:
- src
- Files:
-
- 4 edited
-
ResolvExpr/CandidateFinder.cpp (modified) (4 diffs)
-
ResolvExpr/ConversionCost.cc (modified) (2 diffs)
-
Validate/ImplementEnumFunc.cpp (modified) (3 diffs)
-
main.cc (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/ResolvExpr/CandidateFinder.cpp
r7a780ad r38093ae 513 513 // add new result 514 514 assert( common ); 515 // auto attrType = common.as<ast::EnumAttrType>();516 // if ( attrType && ( attrType->attr == ast::EnumAttribute::Value ) ) {517 // auto callExpr = new ast::UntypedExpr(518 // expr->location, new ast::NameExpr( expr->location, "valueE"), {expr} );519 // CandidateFinder finder( context, env );520 // finder.find( callExpr );521 // CandidateList winners = findMinCost( finder.candidates );522 // if (winners.size() != 1) {523 // SemanticError( callExpr, "Ambiguous expression in valueE" );524 // }525 // CandidateRef & choice = winners.front();526 // choice->expr = referenceToRvalueConversion( choice->expr, choice->cost );527 528 // results.emplace_back(529 // i, choice->expr,530 // std::move( env ), std::move( need ), std::move( have ), std::move( open ),531 // nextArg + 1, nTuples, expl.cost, expl.exprs.size() == 1 ? 0 : 1, j );532 // } else {533 515 results.emplace_back( 534 516 i, expr, std::move( env ), std::move( need ), std::move( have ), std::move( open ), … … 921 903 CandidateList winners = findMinCost( finder.candidates ); 922 904 if (winners.size() != 1) { 923 SemanticError( callExpr, "Ambiguous expression in valueE " );905 SemanticError( callExpr, "Ambiguous expression in valueE..." ); 924 906 } 925 907 CandidateRef & choice = winners.front(); 926 // choice->cost.incSafe();908 choice->cost.incVar(); 927 909 candidates.emplace_back( std::move(choice) ); 928 910 } … … 1800 1782 CandidateList winners = findMinCost( finder.candidates ); 1801 1783 if (winners.size() != 1) { 1802 SemanticError( callExpr, "Ambiguous expression in valueE " );1784 SemanticError( callExpr, "Ambiguous expression in valueE..." ); 1803 1785 } 1804 1786 CandidateRef & choice = winners.front(); … … 2150 2132 } 2151 2133 2152 const ast::Expr * getValueEnumCall( const ast::Expr * expr, 2153 const ResolveContext & context, const ast::TypeEnvironment & env ) { 2154 auto callExpr = new ast::UntypedExpr( 2155 expr->location, new ast::NameExpr( expr->location, "valueE"), {expr} ); 2156 CandidateFinder finder( context, env ); 2157 finder.find( callExpr ); 2158 CandidateList winners = findMinCost( finder.candidates ); 2159 if (winners.size() != 1) { 2160 SemanticError( callExpr, "Ambiguous expression in valueE" ); 2161 } 2162 CandidateRef & choice = winners.front(); 2163 return choice->expr; 2134 // get the valueE(...) ApplicationExpr that returns the enum value 2135 const ast::Expr * getValueEnumCall( 2136 const ast::Expr * expr, 2137 const ResolvExpr::ResolveContext & context, const ast::TypeEnvironment & env ) { 2138 auto callExpr = new ast::UntypedExpr( 2139 expr->location, new ast::NameExpr( expr->location, "valueE"), {expr} ); 2140 CandidateFinder finder( context, env ); 2141 finder.find( callExpr ); 2142 CandidateList winners = findMinCost( finder.candidates ); 2143 if (winners.size() != 1) { 2144 SemanticError( callExpr, "Ambiguous expression in valueE..." ); 2145 } 2146 CandidateRef & choice = winners.front(); 2147 return choice->expr; 2164 2148 } 2165 2149 -
src/ResolvExpr/ConversionCost.cc
r7a780ad r38093ae 362 362 363 363 void ConversionCost::postvisit( const ast::EnumInstType * inst ) { 364 if ( inst->base && inst->base->base ) { 365 if ( auto dstAsAttr = dynamic_cast<const ast::EnumAttrType *>( dst ) ) { 366 auto instAsAttr = ast::EnumAttrType( inst, dstAsAttr->attr ); 367 if ( instAsAttr.match(dstAsAttr) ) { 368 cost.incUnsafe(); 369 } 370 371 } else if ( auto dstAsInst = dynamic_cast<const ast::EnumInstType *>( dst ) ) { 372 if (inst->base && dstAsInst->base) { 373 if (inst->base == dstAsInst->base) { 374 cost.incUnsafe(); 375 } 376 } 377 } else { 378 auto instAsVal = ast::EnumAttrType( inst, ast::EnumAttribute::Value ); 379 cost = costCalc( &instAsVal, dst, srcIsLvalue, symtab, env ); 380 if ( cost < Cost::infinity ) { 381 cost.incUnsafe(); 364 if ( auto dstAsInst = dynamic_cast<const ast::EnumInstType *>( dst ) ) { 365 if (inst->base && dstAsInst->base) { 366 if (inst->base->name == dstAsInst->base->name) { 367 cost = Cost::zero; 368 return; 382 369 } 383 370 } … … 393 380 void ConversionCost::postvisit( const ast::EnumAttrType * src ) { 394 381 auto dstAsEnumAttrType = dynamic_cast<const ast::EnumAttrType *>(dst); 395 if ( src->attr == ast::EnumAttribute::Label ) { 396 if ( dstAsEnumAttrType && dstAsEnumAttrType->attr == ast::EnumAttribute::Label ) { 397 cost = costCalc( src->instance, dstAsEnumAttrType->instance, srcIsLvalue, symtab, env ); 398 } 399 // Add Conversion To String 400 } else if ( src->attr == ast::EnumAttribute::Value ) { 382 assert( src->attr != ast::EnumAttribute::Label ); 383 if ( src->attr == ast::EnumAttribute::Value ) { 401 384 if ( dstAsEnumAttrType && dstAsEnumAttrType->attr == ast::EnumAttribute::Value) { 402 385 cost = costCalc( src->instance, dstAsEnumAttrType->instance, srcIsLvalue, symtab, env ); -
src/Validate/ImplementEnumFunc.cpp
r7a780ad r38093ae 156 156 const ast::ObjectDecl* dstParam, 157 157 const ast::ObjectDecl* srcParam) { 158 // const CodeLocation& location = func->location;159 // auto& params = func->params;160 // assert(2 == params.size());161 // auto dstParam = params.front().strict_as<ast::ObjectDecl>();162 // auto srcParam = params.back().strict_as<ast::ObjectDecl>();163 158 return new ast::CompoundStmt( 164 159 location, … … 301 296 {new ast::ObjectDecl(getLocation(), "_i", new ast::EnumInstType(decl))}, 302 297 {new ast::ObjectDecl(getLocation(), "_ret", 303 new ast::EnumAttrType(new ast::EnumInstType(decl), 304 ast::EnumAttribute::Posn))}); 298 new ast::BasicType(ast::BasicType::UnsignedInt))}); 305 299 } 306 300 … … 440 434 441 435 auto addOneExpr = ast::UntypedExpr::createCall( location, 442 "?+?",436 succ? "?+?": "?-?", 443 437 {new ast::VariableExpr(location, param), 444 438 ast::ConstantExpr::from_int(location, 1)} -
src/main.cc
r7a780ad r38093ae 382 382 DUMP( exprp, std::move( transUnit ) ); 383 383 PASS( "Replace Pseudo Func", Validate::replacePseudoFunc, transUnit ); 384 DUMP( reppseu, std::move( transUnit ) );385 384 PASS( "Fix Init", InitTweak::fix, transUnit, buildingLibrary() ); // Here 386 385 PASS( "Erase With", ResolvExpr::eraseWith, transUnit ); … … 534 533 { "instgen", genericsp, true, "print AST after instantiate generics" }, 535 534 { "bbox", bboxp, true, "print AST before box pass" }, 536 { "bcodegen", bcodegenp, true, "print AST before code generation" }, 537 { "reppseu", reppseu, true, "print AST after replacing pseudo functions" } 535 { "bcodegen", bcodegenp, true, "print AST before code generation" } 538 536 }; 539 537 enum { printoptsSize = sizeof( printopts ) / sizeof( printopts[0] ) };
Note:
See TracChangeset
for help on using the changeset viewer.