Changes in / [011c29e:bc07190]
- Files:
-
- 3 edited
-
libcfa/src/enum.cfa (modified) (1 diff)
-
libcfa/src/enum.hfa (modified) (1 diff)
-
src/ControlStruct/TranslateEnumRange.cpp (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
libcfa/src/enum.cfa
r011c29e rbc07190 23 23 int ?>?(E l, E r) { return posn(l) > posn(r); } 24 24 int ?>=?(E l, E r) { return posn(l) >= posn(r); } 25 26 E ++?(E& l) {27 l = succ(l);28 return l;29 }30 31 E ?++(E& l) {32 E ret = l;33 l = succ(l);34 return ret;35 }36 37 E --?(E& l) {38 l = pred(l);39 return l;40 }41 42 E ?--(E& l) {43 E ret = l;44 l = pred(l);45 return ret;46 }47 25 } -
libcfa/src/enum.hfa
r011c29e rbc07190 49 49 int ?>?(E, E); 50 50 int ?>=?(E, E); 51 52 int ++?(E&);53 int ?++(E&);54 int --?(E&);55 int ?--(E&);56 51 } -
src/ControlStruct/TranslateEnumRange.cpp
r011c29e rbc07190 27 27 28 28 auto objInit = stmt->inits.front(); 29 29 30 auto initLocation = objInit->location; 30 31 auto rangeLocation = stmt->range_over->location; … … 60 61 if ( !objDecl->init ) { 61 62 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, 64 65 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 ) ); 66 67 auto objDeclWithInit = ast::mutate_field( objDecl, &ast::ObjectDecl::init, newInit ); 67 68 auto declWithInit = ast::mutate_field( declStmt, &ast::DeclStmt::decl, objDeclWithInit ); … … 84 85 auto enumInst = typeExpr->type.strict_as<ast::EnumInstType>(); 85 86 auto enumDecl = enumInst->base; 86 87 87 88 // Both inc and dec check if the current posn less than the number of enumerator 88 89 // for dec, it keeps call pred until it passes 0 (the first enumerator) and underflow, … … 92 93 {new ast::CastExpr(location, 93 94 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), 96 97 ast::ConstantExpr::from_ulong( location, enumDecl->members.size()-1 ) }); 98 97 99 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 101 103 auto assig = ast::UntypedExpr::createAssign( location, new ast::NameExpr( location, indexName ), increment ); 102 104 auto mut = ast::mutate_field( stmt, &ast::ForStmt::cond, condition );
Note:
See TracChangeset
for help on using the changeset viewer.