Changes in / [4ec9513:365c8dcb]
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
src/CodeGen/CodeGenerator.cc
r4ec9513 r365c8dcb 276 276 std::list< Declaration* > &memb = enumDecl->get_members(); 277 277 if (enumDecl->base && ! memb.empty()) { 278 ObjectDecl * last = nullptr;278 unsigned long long last_val = -1; 279 279 for ( std::list< Declaration* >::iterator i = memb.begin(); i != memb.end(); i++) { 280 280 ObjectDecl * obj = dynamic_cast< ObjectDecl* >( *i ); … … 284 284 output << mangleName( obj ) << " "; 285 285 output << " = "; 286 output << "(" << genType(enumDecl->base, "", options) << ")";; 287 if ( obj->get_init() ) { 288 obj->get_init()->accept( *visitor ); 286 output << "(" << genType(enumDecl->base, "", options) << ")"; 287 if ( (BasicType *)(enumDecl->base) && ((BasicType *)(enumDecl->base))->isWholeNumber() ) { 288 if ( obj->get_init() ) { 289 obj->get_init()->accept( *visitor ); 290 last_val = ((ConstantExpr *)(((SingleInit *)(obj->init))->value))->constant.get_ival(); 291 } else { 292 output << ++last_val; 293 } // if 289 294 } else { 290 if ( last == nullptr) {291 o utput << 0;295 if ( obj->get_init() ) { 296 obj->get_init()->accept( *visitor ); 292 297 } else { 293 output << mangleName(last) << " + 1";298 // Should not reach here! 294 299 } 295 } // if—300 } 296 301 output << ";" << endl; 297 last = obj;298 302 } // for 299 303 } else { -
tests/enum_tests/.expect/typedIntEnum.txt
r4ec9513 r365c8dcb 1 zero: 0, one: 1 1 0 2 1 3 1000 4 1001 5 2000 6 2001 7 2002 -
tests/enum_tests/typedIntEnum.cfa
r4ec9513 r365c8dcb 3 3 enum(int) IntEnum { 4 4 zero, 5 one 5 one, 6 thousand = 1000, 7 thousand_one, 8 two_thousand = 2000, 9 two_thousand_one, 10 two_thousand_two 6 11 }; 7 12 8 13 int main() { 9 printf("zero: %d, one: %d\n", zero, one); 14 printf("%d\n", zero); 15 printf("%d\n", one); 16 printf("%d\n", thousand); 17 printf("%d\n", thousand_one); 18 printf("%d\n", two_thousand); 19 printf("%d\n", two_thousand_one); 20 printf("%d\n", two_thousand_two); 10 21 return 0; 11 22 }
Note: See TracChangeset
for help on using the changeset viewer.