Changeset 4390fb6
- Timestamp:
- Mar 21, 2022, 3:21:06 PM (3 years ago)
- Branches:
- ADT, ast-experimental, enum, master, pthread-emulation, qualifiedEnum
- Children:
- 32fc0d6
- Parents:
- f238fcc2
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/CodeGen/CodeGenerator.cc
rf238fcc2 r4390fb6 197 197 if ( objectDecl->isDeleted && options.genC ) return; 198 198 199 // objectDecl->checkAssignedValue(); 200 /* Temporary add the enum check here; need a better location */ 201 // { 202 // EnumInstType * enumTypePtr = dynamic_cast< EnumInstType *>(objectDecl->get_type()); 203 // if (enumTypePtr) { 204 // EnumDecl * enumBase = enumTypePtr -> baseEnum; 205 // if ( enumTypePtr && enumBase->base ) { 206 // std::list< Declaration * > & enumMembers = enumBase->get_members(); 207 // auto in_enum = [&]( Declaration * enumMem ) -> bool { 208 // ObjectDecl * obj = dynamic_cast< ObjectDecl* >( enumMem ); 209 // if ( mangleName( obj ) == mangleName( objectDecl ) ) { 210 // return true; 211 // } 212 // return false; 213 // }; 214 // if ( std::find_if( enumMembers.begin(), enumMembers.end(), in_enum ) == enumMembers.end() ) { 215 // output<< "/* Cannot assign a Non-enum member value to a typed enum variable. */" ; 216 // } 217 218 // } 219 // } 220 221 // } 222 199 223 // gcc allows an empty declarator (no name) for bit-fields and C states: 6.7.2.1 Structure and union specifiers, 200 224 // point 4, page 113: If the (bit field) value is zero, the declaration shall have no declarator. For anything … … 230 254 objectDecl->get_bitfieldWidth()->accept( *visitor ); 231 255 } // if 256 output << "/* objectDecl */"; 232 257 } 233 258 … … 274 299 void CodeGenerator::postvisit( EnumDecl * enumDecl ) { 275 300 extension( enumDecl ); 276 output << "enum ";277 genAttributes( enumDecl->get_attributes() );278 279 output << enumDecl->get_name();280 281 301 std::list< Declaration* > &memb = enumDecl->get_members(); 282 283 if ( ! memb.empty() ) { 284 output << " {" << endl; 285 286 ++indent; 302 if (enumDecl->base && ! memb.empty() && 303 (dynamic_cast<BasicType *>(enumDecl->base) 304 && !dynamic_cast<BasicType *>(enumDecl->base)->kind == BasicType::Kind::SignedInt)) { 305 ObjectDecl * last = nullptr; 287 306 for ( std::list< Declaration* >::iterator i = memb.begin(); i != memb.end(); i++) { 288 307 ObjectDecl * obj = dynamic_cast< ObjectDecl* >( *i ); 289 308 assert( obj ); 290 output << indent << mangleName( obj ); 309 output << "static const "; 310 output << genType(enumDecl->base, "", options) << " "; 311 output << mangleName( obj ) << " "; 312 output << " = "; 313 output << "(" << genType(enumDecl->base, "", options) << ")";; 291 314 if ( obj->get_init() ) { 292 output << " = ";293 // In progress294 315 obj->get_init()->accept( *visitor ); 295 } // if 296 output << "," << endl; 316 } else { 317 if (last == nullptr) { 318 output << 0; 319 } else { 320 output << mangleName(last) << " + 1"; 321 } 322 } // if— 323 output << ";" << endl; 324 last = obj; 297 325 } // for 298 326 } else { 327 output << "enum "; 328 genAttributes( enumDecl->get_attributes() ); 329 330 output << enumDecl->get_name(); 331 332 if ( ! memb.empty() ) { 333 output << " {" << endl; 334 335 ++indent; 336 for ( std::list< Declaration* >::iterator i = memb.begin(); i != memb.end(); i++) { 337 ObjectDecl * obj = dynamic_cast< ObjectDecl* >( *i ); 338 assert( obj ); 339 output << indent << mangleName( obj ); 340 if ( obj->get_init() ) { 341 output << " = "; 342 obj->get_init()->accept( *visitor ); 343 } // if 344 output << "," << endl; 345 } // for 299 346 --indent; 300 301 347 output << indent << "}"; 348 } // if 302 349 } // if 303 350 } … … 354 401 } // if 355 402 } // for 356 output << " = ";403 output << " = /* Designation */"; 357 404 } 358 405 … … 662 709 output << opInfo->symbol; 663 710 } else { 664 if (dynamic_cast<EnumInstType *>(variableExpr->get_var()->get_type())665 && dynamic_cast<EnumInstType *>(variableExpr->get_var()->get_type())->baseEnum->base) {666 output << '(' <<genType(dynamic_cast<EnumInstType *>(variableExpr->get_var()->get_type())->baseEnum->base, "", options) << ')';667 }711 // if (dynamic_cast<EnumInstType *>(variableExpr->get_var()->get_type()) 712 // && dynamic_cast<EnumInstType *>(variableExpr->get_var()->get_type())->baseEnum->base) { 713 // output << '(' <<genType(dynamic_cast<EnumInstType *>(variableExpr->get_var()->get_type())->baseEnum->base, "", options) << ')'; 714 // } 668 715 output << mangleName( variableExpr->get_var() ); 669 716 } // if … … 913 960 } 914 961 exprStmt->get_expr()->accept( *visitor ); 915 output << "; ";962 output << "; /* ExprStmt */"; 916 963 } 917 964
Note: See TracChangeset
for help on using the changeset viewer.