Changeset 5ccc733 for src/ControlStruct


Ignore:
Timestamp:
Jun 29, 2024, 5:02:06 AM (6 months ago)
Author:
JiadaL <j82liang@…>
Branches:
master
Children:
4117761
Parents:
7552fde
Message:

Fix the bug that C style enum cannot to use as an lvalue

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/ControlStruct/TranslateEnumRange.cpp

    r7552fde r5ccc733  
    9191    ast::UntypedExpr * condition = ast::UntypedExpr::createCall( location,
    9292        "?<=?",
    93         {
    94             ast::UntypedExpr::createCall(location, "posn", { new ast::NameExpr( location, indexName ) } ),
    95             ast::ConstantExpr::from_ulong( location, enumDecl->members.size()-1 )
    96         });
     93        {new ast::CastExpr(location,
     94            new ast::NameExpr( location, indexName ),
     95            new ast::BasicType( ast::BasicKind::UnsignedInt ),
     96            ast::GeneratedFlag::ExplicitCast),
     97        ast::ConstantExpr::from_ulong( location, enumDecl->members.size()-1 ) });
     98
    9799    auto increment = ast::UntypedExpr::createCall( location,
    98         stmt->is_inc? "succ": "pred",
     100        stmt->is_inc? "?++": "?--",
    99101        { new ast::NameExpr( location, indexName ) });
     102   
    100103    auto assig = ast::UntypedExpr::createAssign( location, new ast::NameExpr( location, indexName ), increment );
    101104    auto mut = ast::mutate_field( stmt, &ast::ForStmt::cond, condition );
Note: See TracChangeset for help on using the changeset viewer.