Changes in / [169496e1:03606ce]


Ignore:
Location:
src
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • src/ResolvExpr/CommonType.cc

    r169496e1 r03606ce  
    681681
    682682        void postvisit( const ast::EnumPosType * enumPos ) {
    683                 if ( dynamic_cast<const ast::EnumPosType *>(type2) ) {
     683                if ( auto type2AsPos = dynamic_cast<const ast::EnumPosType *>(type2) ) {
    684684                        // result = commonType( type2AsPos->instance, enumPos->instance, tenv, need, have, open, widen );
    685                         result = enumPos;
     685                        // result = enumPos;
     686                        if ( enumPos->instance->base->name == type2AsPos->instance->base->name ) {
     687                                result = type2;
     688                        }
    686689                } else if ( dynamic_cast<const ast::BasicType *>(type2) ) {
    687690                        result = type2;
  • src/ResolvExpr/ConversionCost.cc

    r169496e1 r03606ce  
    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/ResolvExpr/Unify.cc

    r169496e1 r03606ce  
    517517                }
    518518
    519                 void postvisit( const ast::EnumPosType * ) {
     519                void postvisit( const ast::EnumPosType * posType ) {
    520520                        // Lazy approach for now
    521521                        auto otherPos = dynamic_cast< const ast::EnumPosType *>(type2);
    522                         if (otherPos) this->result = otherPos;
     522                        if ( otherPos ) {
     523                                if ( otherPos->instance->base->name == posType->instance->base->name )
     524                                        result = otherPos;
     525                        }
    523526                }
    524527
  • src/Validate/ReplacePseudoFunc.cpp

    r169496e1 r03606ce  
    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.