Changes in / [ca20b07:7350330f]


Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/ResolvExpr/ResolveTypeof.cc

    rca20b07 r7350330f  
    232232            // Desination here
    233233            ast::Designation * newDesination = new ast::Designation(des->location);
    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;
     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;
    257261                            }
     262                            break;
    258263                        }
    259                     } else {
    260                         newDesignators.push_back( des->designators.at(0) );
    261264                    }
    262265                } else {
    263                     newDesignators.push_back( des->designators.at(0) );
     266                    newDesination->designators.push_back( des->designators.at(0) );
    264267                }
    265             }           
    266            
    267             newDesination->designators = newDesignators;
    268             mutListInit = ast::mutate_field_index(mutListInit, &ast::ListInit::designations, k, newDesination);
    269            
     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            }
    270274        }
    271275    }
Note: See TracChangeset for help on using the changeset viewer.