Changeset ca20b07


Ignore:
Timestamp:
Sep 27, 2023, 10:07:38 PM (7 months ago)
Author:
Peter A. Buhr <pabuhr@…>
Branches:
master
Children:
c2d728c
Parents:
7350330f (diff), c7616dd (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.
Message:

Merge branch 'master' of plg.uwaterloo.ca:software/cfa/cfa-cc

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/ResolvExpr/ResolveTypeof.cc

    r7350330f rca20b07  
    232232            // Desination here
    233233            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;
    261257                            }
    262                             break;
    263258                        }
     259                    } else {
     260                        newDesignators.push_back( des->designators.at(0) );
    264261                    }
    265262                } else {
    266                     newDesination->designators.push_back( des->designators.at(0) );
     263                    newDesignators.push_back( des->designators.at(0) );
    267264                }
    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           
    274270        }
    275271    }
Note: See TracChangeset for help on using the changeset viewer.