Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/ControlStruct/TranslateEnumRange.cpp

    rd3aa55e9 rd66a43b  
    2626        auto enumDecl = enumInst->base;
    2727
    28         auto objInit = stmt->inits.front();
     28        auto init = stmt->inits.front();
    2929
    30         auto initLocation = objInit->location;
    31         auto rangeLocation = stmt->range_over->location;
    32         assert( stmt->inits.size() == 1 );
    33 
    34         if (auto declStmt = objInit.as<ast::DeclStmt>()) {
     30        if (auto declStmt = init.as<ast::DeclStmt>()) {
    3531            auto decl = declStmt->decl;
    3632            if ( auto objDecl = decl.as<ast::ObjectDecl>()) {
     
    6157                if ( !objDecl->init ) {
    6258                    auto location = stmt->location;
    63                     ast::SingleInit * newInit;
    64                     newInit = new ast::SingleInit( location,
    65                         new ast::NameExpr( location,
    66                         stmt->is_inc? enumDecl->members.front()->name: enumDecl->members.back()->name ) );
     59                    auto newInit = new ast::SingleInit( location, new ast::NameExpr( location, enumDecl->members.front()->name ) );
    6760                    auto objDeclWithInit = ast::mutate_field( objDecl, &ast::ObjectDecl::init, newInit );
    6861                    auto declWithInit = ast::mutate_field( declStmt, &ast::DeclStmt::decl, objDeclWithInit );
     
    8578    auto enumInst = typeExpr->type.strict_as<ast::EnumInstType>();
    8679    auto enumDecl = enumInst->base;
    87    
    88     // Both inc and dec check if the current posn less than the number of enumerator
    89     // for dec, it keeps call pred until it passes 0 (the first enumerator) and underflow,
    90     // it wraps around and become unsigned max
    91     ast::UntypedExpr * condition = ast::UntypedExpr::createCall( location,
    92         "?<=?",
    93         {
    94             ast::UntypedExpr::createCall(location, "posn", { new ast::NameExpr( location, indexName ) } ),
    95             ast::ConstantExpr::from_ulong( location, enumDecl->members.size()-1 )
    96         });
    97     auto increment = ast::UntypedExpr::createCall( location,
    98         stmt->is_inc? "succ": "pred",
    99         { new ast::NameExpr( location, indexName ) });
     80
     81    auto condition = ast::UntypedExpr::createCall( location, "?<=?", {
     82        new ast::NameExpr( location, indexName ),
     83        // ast::ConstantExpr::from_ulong( location, enumDecl->members.size() )
     84        new ast::NameExpr( location, enumDecl->members.back()->name )
     85    });
     86    auto increment = ast::UntypedExpr::createCall( location, "succ", {
     87        new ast::NameExpr( location, indexName )
     88    });
    10089    auto assig = ast::UntypedExpr::createAssign( location, new ast::NameExpr( location, indexName ), increment );
    10190    auto mut = ast::mutate_field( stmt, &ast::ForStmt::cond, condition );
Note: See TracChangeset for help on using the changeset viewer.