- Timestamp:
- Sep 25, 2023, 2:52:21 AM (11 months ago)
- Branches:
- master
- Children:
- ca20b07, f033d01
- Parents:
- 62c6cfa
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/ResolvExpr/ResolveTypeof.cc
r62c6cfa rc7616dd 232 232 // Desination here 233 233 ast::Designation * newDesination = new ast::Designation(des->location); 234 235 if (des->designators.size() == 0) continue; 236 237 // The designator I want to replace 238 const ast::Expr * designator = des->designators.at(0); 239 // Stupid flag variable for development, to be removed 240 bool mutated = false; 241 if ( const ast::NameExpr * designatorName = dynamic_cast<const ast::NameExpr *>(designator) ) { 242 auto candidates = context.symtab.lookupId(designatorName->name); 243 // Does not work for the overloading case currently 244 // assert( candidates.size() == 1 ); 245 if ( candidates.size() != 1 ) return mutDecl; 246 auto candidate = candidates.at(0); 247 if ( const ast::EnumInstType * enumInst = dynamic_cast<const ast::EnumInstType *>(candidate.id->get_type())) { 248 // determine that is an enumInst, swap it with its const value 249 assert( candidates.size() == 1 ); 250 const ast::EnumDecl * baseEnum = enumInst->base; 251 // Need to iterate over all enum value to find the initializer to swap 252 for ( size_t m = 0; m < baseEnum->members.size(); ++m ) { 253 const ast::ObjectDecl * mem = baseEnum->members.at(m).as<const ast::ObjectDecl>(); 254 if ( baseEnum->members.at(m)->name == designatorName->name ) { 255 assert(mem); 256 if ( mem->init ) { 257 const ast::SingleInit * memInit = mem->init.as<const ast::SingleInit>(); 258 ast::Expr * initValue = shallowCopy( memInit->value.get() ); 259 newDesination->designators.push_back( initValue ); 260 mutated = true; 234 std::deque<ast::ptr<ast::Expr>> newDesignators; 235 236 for ( ast::ptr<ast::Expr> designator : des->designators ) { 237 // Stupid flag variable for development, to be removed 238 // bool mutated = false; 239 if ( const ast::NameExpr * designatorName = designator.as<ast::NameExpr>() ) { 240 auto candidates = context.symtab.lookupId(designatorName->name); 241 // Does not work for the overloading case currently 242 // assert( candidates.size() == 1 ); 243 if ( candidates.size() != 1 ) return mutDecl; 244 auto candidate = candidates.at(0); 245 if ( const ast::EnumInstType * enumInst = dynamic_cast<const ast::EnumInstType *>(candidate.id->get_type())) { 246 // determine that is an enumInst, swap it with its const value 247 assert( candidates.size() == 1 ); 248 const ast::EnumDecl * baseEnum = enumInst->base; 249 // Need to iterate over all enum value to find the initializer to swap 250 for ( size_t m = 0; m < baseEnum->members.size(); ++m ) { 251 const ast::ObjectDecl * mem = baseEnum->members.at(m).as<const ast::ObjectDecl>(); 252 if ( baseEnum->members.at(m)->name == designatorName->name ) { 253 assert(mem); 254 newDesignators.push_back( ast::ConstantExpr::from_int(designator->location, m) ); 255 // mutated = true; 256 break; 261 257 } 262 break;263 258 } 259 } else { 260 newDesignators.push_back( des->designators.at(0) ); 264 261 } 265 262 } else { 266 newDesi nation->designators.push_back( des->designators.at(0) );263 newDesignators.push_back( des->designators.at(0) ); 267 264 } 268 } else { 269 newDesination->designators.push_back( des->designators.at(0) ); 270 } 271 if ( mutated ) { 272 mutListInit = ast::mutate_field_index(mutListInit, &ast::ListInit::designations, k, newDesination); 273 } 265 } 266 267 newDesination->designators = newDesignators; 268 mutListInit = ast::mutate_field_index(mutListInit, &ast::ListInit::designations, k, newDesination); 269 274 270 } 275 271 }
Note: See TracChangeset
for help on using the changeset viewer.