Changeset 2e9b59b for src/CodeGen/CodeGenerator.cc
- Timestamp:
- Apr 19, 2022, 3:00:04 PM (3 years ago)
- Branches:
- ADT, ast-experimental, master, pthread-emulation, qualifiedEnum
- Children:
- 5b84a321
- Parents:
- ba897d21 (diff), bb7c77d (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. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/CodeGen/CodeGenerator.cc
rba897d21 r2e9b59b 274 274 void CodeGenerator::postvisit( EnumDecl * enumDecl ) { 275 275 extension( enumDecl ); 276 output << "enum ";277 genAttributes( enumDecl->get_attributes() );278 279 output << enumDecl->get_name();280 281 276 std::list< Declaration* > &memb = enumDecl->get_members(); 282 283 if ( ! memb.empty() ) { 284 output << " {" << endl; 285 286 ++indent; 277 if (enumDecl->base && ! memb.empty()) { 278 unsigned long long last_val = -1; 287 279 for ( std::list< Declaration* >::iterator i = memb.begin(); i != memb.end(); i++) { 288 280 ObjectDecl * obj = dynamic_cast< ObjectDecl* >( *i ); 289 281 assert( obj ); 290 output << indent << mangleName( obj ); 291 if ( obj->get_init() ) { 292 output << " = "; 293 obj->get_init()->accept( *visitor ); 294 } // if 295 output << "," << endl; 282 output << "static const "; 283 output << genType(enumDecl->base, "", options) << " "; 284 output << mangleName( obj ) << " "; 285 output << " = "; 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 294 } else { 295 if ( obj->get_init() ) { 296 obj->get_init()->accept( *visitor ); 297 } else { 298 // Should not reach here! 299 } 300 } 301 output << ";" << endl; 296 302 } // for 297 303 } else { 304 output << "enum "; 305 genAttributes( enumDecl->get_attributes() ); 306 307 output << enumDecl->get_name(); 308 309 if ( ! memb.empty() ) { 310 output << " {" << endl; 311 312 ++indent; 313 for ( std::list< Declaration* >::iterator i = memb.begin(); i != memb.end(); i++) { 314 ObjectDecl * obj = dynamic_cast< ObjectDecl* >( *i ); 315 assert( obj ); 316 output << indent << mangleName( obj ); 317 if ( obj->get_init() ) { 318 output << " = "; 319 obj->get_init()->accept( *visitor ); 320 } // if 321 output << "," << endl; 322 } // for 298 323 --indent; 299 300 324 output << indent << "}"; 325 } // if 301 326 } // if 302 327 } … … 347 372 des->accept( *visitor ); 348 373 } else { 349 // otherwise, it has to be a ConstantExpr or CastExpr, initializing array ele emnt374 // otherwise, it has to be a ConstantExpr or CastExpr, initializing array element 350 375 output << "["; 351 376 des->accept( *visitor ); … … 661 686 output << opInfo->symbol; 662 687 } else { 688 // if (dynamic_cast<EnumInstType *>(variableExpr->get_var()->get_type()) 689 // && dynamic_cast<EnumInstType *>(variableExpr->get_var()->get_type())->baseEnum->base) { 690 // output << '(' <<genType(dynamic_cast<EnumInstType *>(variableExpr->get_var()->get_type())->baseEnum->base, "", options) << ')'; 691 // } 663 692 output << mangleName( variableExpr->get_var() ); 664 693 } // if
Note:
See TracChangeset
for help on using the changeset viewer.