- File:
-
- 1 edited
-
src/ControlStruct/TranslateEnumRange.cpp (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/ControlStruct/TranslateEnumRange.cpp
rd3aa55e9 rd66a43b 26 26 auto enumDecl = enumInst->base; 27 27 28 auto objInit = stmt->inits.front();28 auto init = stmt->inits.front(); 29 29 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>()) { 35 31 auto decl = declStmt->decl; 36 32 if ( auto objDecl = decl.as<ast::ObjectDecl>()) { … … 61 57 if ( !objDecl->init ) { 62 58 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 ) ); 67 60 auto objDeclWithInit = ast::mutate_field( objDecl, &ast::ObjectDecl::init, newInit ); 68 61 auto declWithInit = ast::mutate_field( declStmt, &ast::DeclStmt::decl, objDeclWithInit ); … … 85 78 auto enumInst = typeExpr->type.strict_as<ast::EnumInstType>(); 86 79 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 }); 100 89 auto assig = ast::UntypedExpr::createAssign( location, new ast::NameExpr( location, indexName ), increment ); 101 90 auto mut = ast::mutate_field( stmt, &ast::ForStmt::cond, condition );
Note:
See TracChangeset
for help on using the changeset viewer.