Changes in / [01510fe:cb0bcf1]
- Location:
- src/ResolvExpr
- Files:
-
- 2 edited
-
ResolveTypeof.cc (modified) (4 diffs)
-
Resolver.cc (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/ResolvExpr/ResolveTypeof.cc
r01510fe rcb0bcf1 237 237 // The designator I want to replace 238 238 const ast::Expr * designator = des->designators.at(0); 239 // Stupid flag variable for development, to be removed 240 bool mutated = false; 239 241 240 if ( const ast::NameExpr * designatorName = dynamic_cast<const ast::NameExpr *>(designator) ) { 242 241 auto candidates = context.symtab.lookupId(designatorName->name); … … 245 244 if ( candidates.size() != 1 ) return mutDecl; 246 245 auto candidate = candidates.at(0); 247 if ( const ast::EnumInstType * enumInst = dynamic_cast<const ast::EnumInstType *>(candidate.id->get_type()) ) {246 if ( const ast::EnumInstType * enumInst = dynamic_cast<const ast::EnumInstType *>(candidate.id->get_type()) ) { 248 247 // determine that is an enumInst, swap it with its const value 249 248 assert( candidates.size() == 1 ); … … 251 250 // Need to iterate over all enum value to find the initializer to swap 252 251 for ( size_t m = 0; m < baseEnum->members.size(); ++m ) { 253 const ast::ObjectDecl * mem = baseEnum->members.at(m).as<const ast::ObjectDecl>();254 252 if ( baseEnum->members.at(m)->name == designatorName->name ) { 253 const ast::ObjectDecl * mem = baseEnum->members.at(m).as<const ast::ObjectDecl>(); 255 254 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; 261 } 262 break; 255 const ast::ConstantExpr * enumAsInit = ast::ConstantExpr::from_int(newDesination->location, m); 256 newDesination->designators.push_back( enumAsInit ); 263 257 } 258 } 259 if ( newDesination->designators.size() == 0 ) { 260 SemanticError(des->location, "Resolution Error: Resolving array designation as Enum Instance value, but cannot find a desgination value"); 264 261 } 265 262 } else { … … 269 266 newDesination->designators.push_back( des->designators.at(0) ); 270 267 } 271 if ( mutated ) { 272 mutListInit = ast::mutate_field_index(mutListInit, &ast::ListInit::designations, k, newDesination); 273 } 268 mutListInit = ast::mutate_field_index(mutListInit, &ast::ListInit::designations, k, newDesination); 274 269 } 275 270 } -
src/ResolvExpr/Resolver.cc
r01510fe rcb0bcf1 988 988 } 989 989 }; 990 991 struct ResolveDesignators_new final : public ast::WithShortCircuiting {992 ResolveContext& context;993 bool result = false;994 995 ResolveDesignators_new( ResolveContext& _context ): context{_context} {};996 997 void previsit( const ast::Node * ) {998 // short circuit if we already know there are designations999 if ( result ) visit_children = false;1000 }1001 1002 void previsit( const ast::Designation * des ) {1003 if ( result ) visit_children = false;1004 else if ( ! des->designators.empty() ) {1005 if ( (des->designators.size() == 1) ) {1006 const ast::Expr * designator = des->designators.at(0);1007 if ( const ast::NameExpr * designatorName = dynamic_cast<const ast::NameExpr *>(designator) ) {1008 auto candidates = context.symtab.lookupId(designatorName->name);1009 for ( auto candidate : candidates ) {1010 if ( dynamic_cast<const ast::EnumInstType *>(candidate.id->get_type()) ) {1011 result = true;1012 break;1013 }1014 }1015 }1016 }1017 visit_children = false;1018 }1019 }1020 };1021 990 } // anonymous namespace 1022 991 /// Check if this expression is or includes a deleted expression … … 1538 1507 if ( InitTweak::tryConstruct( mutDecl ) && ( managedTypes.isManaged( mutDecl ) || ((! isInFunction() || mutDecl->storage.is_static ) && ! InitTweak::isConstExpr( mutDecl->init ) ) ) ) { 1539 1508 // constructed objects cannot be designated 1509 // if ( InitTweak::isDesignated( mutDecl->init ) ) SemanticError( mutDecl, "Cannot include designations in the initializer for a managed Object. If this is really what you want, then initialize with @=.\n" ); 1540 1510 if ( InitTweak::isDesignated( mutDecl->init ) ) { 1541 ast::Pass<ResolveDesignators_new> res( context ); 1542 maybe_accept( mutDecl->init.get(), res ); 1543 if ( !res.core.result ) { 1544 SemanticError( mutDecl, "Cannot include designations in the initializer for a managed Object. If this is really what you want, then initialize with @=.\n" ); 1545 } 1511 SemanticError( mutDecl, "Cannot include designations in the initializer for a managed Object. If this is really what you want, then initialize with @=.\n" ); 1546 1512 } 1547 1513 // constructed objects should not have initializers nested too deeply
Note:
See TracChangeset
for help on using the changeset viewer.