Changeset cc077f4
- Timestamp:
- Aug 5, 2024, 9:31:08 AM (4 months ago)
- Branches:
- master
- Children:
- f6d2e9b
- Parents:
- c588acb (diff), 7db4fcd4 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
libcfa/src/enum.cfa
rc588acb rcc077f4 6 6 7 7 forall( E | Serial( E ) ) { 8 E fromInt( unsignedi ) {8 E fromInt( int i ) { 9 9 E upper = upperBound(); 10 10 E lower = lowerBound(); -
libcfa/src/enum.hfa
rc588acb rcc077f4 9 9 10 10 forall( E | Bounded( E ) ) trait Serial { 11 unsignedfromInstance( E e );12 E fromInt_unsafe( unsignedi );11 int fromInstance( E e ); 12 E fromInt_unsafe( int i ); 13 13 E succ_unsafe( E e ); 14 14 E pred_unsafe( E e ); … … 16 16 17 17 forall( E | Serial( E ) ) { 18 E fromInt( unsignedi );18 E fromInt( int i ); 19 19 E succ( E e ); 20 20 E pred( E e ); … … 36 36 forall( E ) trait CfaEnum { 37 37 const char * label( E e ); 38 unsignedint posn( E e );38 int posn( E e ); 39 39 }; 40 40 … … 63 63 64 64 E ++?( E & l ) { // increment operators 65 l = succ( l ); 65 int pos = posn(l); 66 l = fromInt_unsafe(pos+1); 67 return l; 68 } 69 70 E --?( E & l ) { 71 int pos = posn(l); 72 l = fromInt_unsafe(pos-1); 66 73 return l; 67 74 } 68 75 69 76 E ?+=? ( E & l, one_t ) { 70 l = succ(l); 77 int pos = posn(l); 78 l = fromInt_unsafe(pos+1); 71 79 return l; 72 80 } 73 81 74 82 E ?-=? ( E & l, one_t ) { 75 l = pred(l); 83 int pos = posn(l); 84 l = fromInt_unsafe(pos-1); 76 85 return l; 77 86 } 78 87 79 88 E ?+=? ( E & l, int i ) { 80 int pos = posn(l) + i; 81 return fromInt(pos); 89 int pos = posn(l); 90 l = fromInt_unsafe(pos+i); 91 return l; 82 92 } 83 93 84 94 E ?-=? ( E & l, int i ) { 85 int pos = posn(l) - i; 86 return fromInt(pos); 87 } 88 89 E ?++( E & l ) { 90 E ret = l; 91 l = succ( l ); 92 return ret; 93 } 94 95 E --?( E & l ) { 96 l = pred( l ); 95 int pos = posn(l); 96 l = fromInt_unsafe(pos-i); 97 97 return l; 98 98 } 99 99 100 E ?++( E & l ) { 101 int pos = posn(l); 102 l = fromInt_unsafe(pos+1); 103 return fromInt_unsafe(pos); 104 } 105 100 106 E ?--( E & l ) { 101 E ret = l;102 l = pred( l);103 return ret;107 int pos = posn(l); 108 l = fromInt_unsafe(pos-1); 109 return fromInt_unsafe(pos); 104 110 } 105 111 } -
src/ControlStruct/TranslateEnumRange.cpp
rc588acb rcc077f4 51 51 // it wraps around and become unsigned max 52 52 ast::UntypedExpr * condition = ast::UntypedExpr::createCall( location, 53 "?<=?",53 stmt->is_inc? "?<=?": "?>=?", 54 54 { new ast::NameExpr( location, indexName ), 55 ast::UntypedExpr::createCall( location, "upperBound", {} ) }); 55 stmt->is_inc? 56 ast::UntypedExpr::createCall( location, "upperBound", {} ): 57 ast::UntypedExpr::createCall( location, "lowerBound", {} ) 58 }); 56 59 auto increment = ast::UntypedExpr::createCall( location, 57 60 stmt->is_inc? "succ_unsafe": "pred_unsafe", -
src/Validate/ImplementEnumFunc.cpp
rc588acb rcc077f4 25 25 : decl(decl), 26 26 functionNesting{functionNesting}, 27 // quasi_void_decl(new ast::StructDecl(decl->location,28 // "quasi_void", ast::AggregateDecl::Struct,29 // {}, ast::Linkage::AutoGen)),30 27 proto_linkage{ast::Linkage::Cforall} {} 31 28 … … 194 191 {new ast::ObjectDecl(getLocation(), "_i", new ast::EnumInstType(decl))}, 195 192 {new ast::ObjectDecl(getLocation(), "_ret", 196 new ast::BasicType(ast::BasicKind:: UnsignedInt))});193 new ast::BasicType(ast::BasicKind::SignedInt))}); 197 194 } 198 195 … … 229 226 return genProto( 230 227 "fromInt_unsafe", 231 {new ast::ObjectDecl(getLocation(), "_i", new ast::BasicType(ast::BasicKind:: UnsignedInt))},228 {new ast::ObjectDecl(getLocation(), "_i", new ast::BasicType(ast::BasicKind::SignedInt))}, 232 229 {new ast::ObjectDecl(getLocation(), "_ret", new ast::EnumInstType(decl))} 233 230 ); … … 238 235 "fromInstance", 239 236 {new ast::ObjectDecl(getLocation(), "_i", new ast::EnumInstType(decl))}, 240 {new ast::ObjectDecl(getLocation(), "_ret", new ast::BasicType(ast::BasicKind:: UnsignedInt))}237 {new ast::ObjectDecl(getLocation(), "_ret", new ast::BasicType(ast::BasicKind::SignedInt))} 241 238 ); 242 239 } … … 285 282 func->location, 286 283 new ast::VariableExpr(func->location, param), 287 new ast::BasicType(ast::BasicKind:: UnsignedInt),284 new ast::BasicType(ast::BasicKind::SignedInt), 288 285 ast::GeneratedFlag::ExplicitCast 289 286 ); … … 383 380 func->location, 384 381 new ast::VariableExpr( func->location, func->params.front() ), 385 new ast::BasicType( ast::BasicKind:: UnsignedInt ),382 new ast::BasicType( ast::BasicKind::SignedInt ), 386 383 ast::GeneratedFlag::ExplicitCast 387 384 )}); … … 407 404 func->location, 408 405 new ast::VariableExpr(func->location, func->params.front()), 409 new ast::BasicType( ast::BasicKind:: UnsignedInt ),406 new ast::BasicType( ast::BasicKind::SignedInt ), 410 407 ast::GeneratedFlag::ExplicitCast); 411 408 func->stmts = new ast::CompoundStmt( -
tests/ctrl-flow/.expect/loopctrl.txt
rc588acb rcc077f4 119 119 0 -2 -4 -6 -8 120 120 0 1 2 3 4 5 6 7 8 9 121 A B C 122 A B C D 123 D B 121 124 A B C D 122 125 D C B A -
tests/ctrl-flow/loopctrl.cfa
rc588acb rcc077f4 83 83 84 84 enum(int) E { A, B, C, D }; 85 //for ( E e; A ~= C ) { sout | e; } sout | nl;86 //for ( e; A ~= D ) { sout | e; } sout | nl;87 //for ( e; A -~= D ~ 2 ) { sout | e; } sout | nl;85 for ( E e; A ~= C ) { sout | e; } sout | nl; 86 for ( e; A ~= D ) { sout | e; } sout | nl; 87 for ( e; A -~= D ~ 2 ) { sout | e; } sout | nl; 88 88 for ( e; E ) { sout | e; } sout | nl; 89 89 for ( e; -~= E ) { sout | e; } sout | nl;
Note: See TracChangeset
for help on using the changeset viewer.