Changeset 2e9b59b for src/CodeGen
- Timestamp:
- Apr 19, 2022, 3:00:04 PM (4 years ago)
- Branches:
- ADT, ast-experimental, master, pthread-emulation, qualifiedEnum, stuck-waitfor-destruct
- 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. - Location:
- src/CodeGen
- Files:
-
- 3 edited
-
CodeGenerator.cc (modified) (3 diffs)
-
FixMain.cc (modified) (2 diffs)
-
GenType.cc (modified) (1 diff)
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 -
src/CodeGen/FixMain.cc
rba897d21 r2e9b59b 91 91 } 92 92 93 ObjectDecl * charStarObj() {93 ObjectDecl * makeArgvObj() { 94 94 return new ObjectDecl( 95 95 "", Type::StorageClasses(), LinkageSpec::Cforall, 0, … … 117 117 main_type->get_returnVals().push_back( signedIntObj() ); 118 118 main_type->get_parameters().push_back( signedIntObj() ); 119 main_type->get_parameters().push_back( charStarObj() );119 main_type->get_parameters().push_back( makeArgvObj() ); 120 120 return create_mangled_main_function_name( main_type ); 121 121 } -
src/CodeGen/GenType.cc
rba897d21 r2e9b59b 253 253 254 254 void GenType::postvisit( EnumInstType * enumInst ) { 255 typeString = enumInst->name + " " + typeString; 256 if ( options.genC ) typeString = "enum " + typeString; 255 if ( enumInst->baseEnum->base ) { 256 typeString = genType(enumInst->baseEnum->base, "", options) + typeString; 257 } else { 258 typeString = enumInst->name + " " + typeString; 259 if ( options.genC ) { 260 typeString = "enum " + typeString; 261 } 262 } 257 263 handleQualifiers( enumInst ); 258 264 }
Note:
See TracChangeset
for help on using the changeset viewer.