Changeset 76fe046


Ignore:
Timestamp:
Mar 6, 2024, 10:55:41 PM (4 months ago)
Author:
JiadaL <j82liang@…>
Branches:
master
Children:
06601401
Parents:
647d633
Message:

Remove conversion part of the EnumPosType?. It can be resolved by the current unifier

Location:
src
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • src/ResolvExpr/ConversionCost.cc

    r647d633 r76fe046  
    379379                // if ( cost < Cost::unsafe ) cost.incSafe();
    380380                cost = Cost::zero;
    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 {
     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 {
    387385                static ast::ptr<ast::BasicType> integer = { new ast::BasicType( ast::BasicType::SignedInt ) };
    388386                cost = costCalc( integer, dst, srcIsLvalue, symtab, env );
  • src/Validate/ReplacePseudoFunc.cpp

    r647d633 r76fe046  
    344344}
    345345
    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 
    410346struct ReplaceSuccAndPred final : public ast::WithSymbolTable,
    411347                                  public ast::WithConstTranslationUnit {
     
    416352            if (expr->args.size() != 1) return expr;
    417353
    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             // }
    450354            auto param = expr->args.front();
    451355            if (auto argAsVar = reduceCastExpr(param).as<ast::VariableExpr>()) {
     
    525429    ast::Pass<PseudoFuncGenerateRoutine>::run(translationUnit);
    526430    ast::Pass<ReplacePseudoFuncCore>::run(translationUnit);
    527     ast::Pass<ReplaceEnumInst>::run(translationUnit);
    528431
    529432    ast::Pass<ReplaceSuccAndPred>::run(translationUnit);
Note: See TracChangeset for help on using the changeset viewer.