Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/ControlStruct/TranslateEnumRange.cpp

    r73d0e3f4 r5ccc733  
    2727
    2828        auto objInit = stmt->inits.front();
     29
    2930        auto initLocation = objInit->location;
    3031        auto rangeLocation = stmt->range_over->location;
     
    6061                if ( !objDecl->init ) {
    6162                    auto location = stmt->location;
    62                     // auto newInit = new ast::SingleInit( location, new ast::NameExpr( location, enumDecl->members.front()->name ) );
    63                     ast::SingleInit * newInit = new ast::SingleInit( location,
     63                    ast::SingleInit * newInit;
     64                    newInit = new ast::SingleInit( location,
    6465                        new ast::NameExpr( location,
    65                            stmt->is_inc? enumDecl->members.front()->name: enumDecl->members.back()->name ) );
     66                        stmt->is_inc? enumDecl->members.front()->name: enumDecl->members.back()->name ) );
    6667                    auto objDeclWithInit = ast::mutate_field( objDecl, &ast::ObjectDecl::init, newInit );
    6768                    auto declWithInit = ast::mutate_field( declStmt, &ast::DeclStmt::decl, objDeclWithInit );
     
    8485    auto enumInst = typeExpr->type.strict_as<ast::EnumInstType>();
    8586    auto enumDecl = enumInst->base;
    86 
     87   
    8788    // Both inc and dec check if the current posn less than the number of enumerator
    8889    // for dec, it keeps call pred until it passes 0 (the first enumerator) and underflow,
     
    9293        {new ast::CastExpr(location,
    9394            new ast::NameExpr( location, indexName ),
    94             new ast::BasicType( ast::BasicKind::UnsignedInt
    95         ),ast::GeneratedFlag::ExplicitCast),
     95            new ast::BasicType( ast::BasicKind::UnsignedInt ),
     96            ast::GeneratedFlag::ExplicitCast),
    9697        ast::ConstantExpr::from_ulong( location, enumDecl->members.size()-1 ) });
     98
    9799    auto increment = ast::UntypedExpr::createCall( location,
    98         stmt->is_inc? "succ": "pred",{
    99         new ast::NameExpr( location, indexName )
    100     });
     100        stmt->is_inc? "?++": "?--",
     101        { new ast::NameExpr( location, indexName ) });
     102   
    101103    auto assig = ast::UntypedExpr::createAssign( location, new ast::NameExpr( location, indexName ), increment );
    102104    auto mut = ast::mutate_field( stmt, &ast::ForStmt::cond, condition );
Note: See TracChangeset for help on using the changeset viewer.