Changes in / [03606ce:169496e1]
- Location:
- src
- Files:
-
- 4 edited
-
ResolvExpr/CommonType.cc (modified) (1 diff)
-
ResolvExpr/ConversionCost.cc (modified) (1 diff)
-
ResolvExpr/Unify.cc (modified) (1 diff)
-
Validate/ReplacePseudoFunc.cpp (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/ResolvExpr/CommonType.cc
r03606ce r169496e1 681 681 682 682 void postvisit( const ast::EnumPosType * enumPos ) { 683 if ( auto type2AsPos =dynamic_cast<const ast::EnumPosType *>(type2) ) {683 if ( dynamic_cast<const ast::EnumPosType *>(type2) ) { 684 684 // result = commonType( type2AsPos->instance, enumPos->instance, tenv, need, have, open, widen ); 685 // result = enumPos; 686 if ( enumPos->instance->base->name == type2AsPos->instance->base->name ) { 687 result = type2; 688 } 685 result = enumPos; 689 686 } else if ( dynamic_cast<const ast::BasicType *>(type2) ) { 690 687 result = type2; -
src/ResolvExpr/ConversionCost.cc
r03606ce r169496e1 379 379 // if ( cost < Cost::unsafe ) cost.incSafe(); 380 380 cost = Cost::zero; 381 } else if ( auto dstBase = dynamic_cast<const ast::EnumInstType *>( dst ) ) { 382 cost = costCalc( src->instance, dstBase, srcIsLvalue, symtab, env ); 383 if ( cost < Cost::unsafe ) cost.incSafe(); 384 } else { 381 } 382 // if ( auto dstBase = dynamic_cast<const ast::EnumInstType *>( dst ) ) { 383 // cost = costCalc( src->instance, dstBase, srcIsLvalue, symtab, env ); 384 // if ( cost < Cost::unsafe ) cost.incSafe(); 385 // } 386 else { 385 387 static ast::ptr<ast::BasicType> integer = { new ast::BasicType( ast::BasicType::SignedInt ) }; 386 388 cost = costCalc( integer, dst, srcIsLvalue, symtab, env ); -
src/ResolvExpr/Unify.cc
r03606ce r169496e1 517 517 } 518 518 519 void postvisit( const ast::EnumPosType * posType) {519 void postvisit( const ast::EnumPosType * ) { 520 520 // Lazy approach for now 521 521 auto otherPos = dynamic_cast< const ast::EnumPosType *>(type2); 522 if ( otherPos ) { 523 if ( otherPos->instance->base->name == posType->instance->base->name ) 524 result = otherPos; 525 } 522 if (otherPos) this->result = otherPos; 526 523 } 527 524 -
src/Validate/ReplacePseudoFunc.cpp
r03606ce r169496e1 344 344 } 345 345 346 struct ReplaceEnumInst final { 347 const ast::Expr* postvisit(const ast::ApplicationExpr* expr) { 348 auto fname = ast::getFunctionName(expr); 349 if (fname == "?[?]") { 350 if (expr->args.size() != 2) return expr; 351 352 auto arg1AsVar = 353 reduceCastExpr(expr->args.front()).as<ast::VariableExpr>(); 354 auto arg2AsVar = 355 reduceCastExpr(expr->args.back()).as<ast::VariableExpr>(); 356 357 if (!arg1AsVar || !arg2AsVar) return expr; 358 359 auto arg1AsDecl = arg1AsVar->var.as<ast::ObjectDecl>(); 360 auto arg2AsDecl = arg2AsVar->var.as<ast::ObjectDecl>(); 361 362 if (!arg1AsDecl || !arg2AsDecl) return expr; 363 auto arrInst = arg1AsDecl->type.as<ast::ArrayType>(); 364 auto pointerInst = arg1AsDecl->type.as<ast::PointerType>(); 365 if (!arrInst && !pointerInst) { 366 return expr; 367 } 368 auto enumInst = arg2AsDecl->type.as<ast::EnumInstType>(); 369 if (!enumInst) return expr; 370 371 const std::string arrName = arg1AsDecl->name; 372 if (arrName != getValueArrayName(enumInst->base->name)) return expr; 373 ast::Pass<ReplaceEnumInstWithPos> replacer; 374 auto rep = arg2AsDecl->accept(replacer); 375 if (!rep) return expr; 376 auto mutObj = 377 ast::mutate_field(arg2AsVar, &ast::VariableExpr::var, rep); 378 mutObj = ast::mutate_field(mutObj, &ast::VariableExpr::result, 379 mutObj->var->get_type()); 380 auto mut = ast::mutate_field_index( 381 expr, &ast::ApplicationExpr::args, 1, mutObj); 382 return mut; 383 } 384 // else if (fname == "succ" || fname == "pred") { 385 // if (expr->args.size() != 1) return expr; 386 // auto argExpr = expr->args.front(); 387 // auto argAsVar = reduceCastExpr(argExpr).as<ast::VariableExpr>(); 388 389 // if (auto argAsDecl = argAsVar->var.as<ast::ObjectDecl>()) { 390 // if (auto enumInst = argAsDecl->type.as<ast::EnumInstType>()) 391 // { 392 // auto enumPos = new ast::EnumPosType(enumInst); 393 // auto castExpr = 394 // new ast::CastExpr(argExpr->location, argExpr, 395 // enumPos); 396 // auto mut = ast::mutate_field_index( 397 // expr, &ast::ApplicationExpr::args, 0, castExpr); 398 // return mut; 399 // } else if (auto enumPos = 400 // argAsDecl->type.as<ast::EnumPosType>()) { 401 // // std::cout << "pos" << std::endl; 402 // return expr; 403 // } 404 // } 405 // } 406 return expr; 407 } 408 }; 409 346 410 struct ReplaceSuccAndPred final : public ast::WithSymbolTable, 347 411 public ast::WithConstTranslationUnit { … … 352 416 if (expr->args.size() != 1) return expr; 353 417 418 // if (auto argAsVar = reduceCastExpr(expr->args.front()) 419 // .as<ast::VariableExpr>()) { 420 // if (auto argAsDecl = argAsVar->var.as<ast::ObjectDecl>()) { 421 // auto enumPos = argAsDecl->type.as<ast::EnumPosType>(); 422 // if (!enumPos) return expr; 423 // // ast::Pass<ReplaceEnumInstWithPos> replacer; 424 // // auto posObj = argAsDecl->accept(replacer); 425 // // if (!posObj) return expr; 426 427 // // auto newParam = new ast::VariableExpr( location, 428 // posObj 429 // // ); 430 431 // auto untyped = new ast::UntypedExpr( 432 // location, 433 // new ast::NameExpr(location, fname == "succ" 434 // ? "_successor_" 435 // : "_predessor_"), 436 // {argAsVar}); 437 438 // ResolvExpr::ResolveContext context{symtab, 439 // transUnit().global}; 440 441 // auto typedResult = 442 // ResolvExpr::findVoidExpression(untyped, context); 443 444 // ast::ptr<ast::ApplicationExpr> ret = 445 // typedResult.strict_as<ast::ApplicationExpr>(); 446 447 // return ast::deepCopy(ret); 448 // } 449 // } 354 450 auto param = expr->args.front(); 355 451 if (auto argAsVar = reduceCastExpr(param).as<ast::VariableExpr>()) { … … 429 525 ast::Pass<PseudoFuncGenerateRoutine>::run(translationUnit); 430 526 ast::Pass<ReplacePseudoFuncCore>::run(translationUnit); 527 ast::Pass<ReplaceEnumInst>::run(translationUnit); 431 528 432 529 ast::Pass<ReplaceSuccAndPred>::run(translationUnit);
Note:
See TracChangeset
for help on using the changeset viewer.