Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/ResolvExpr/CurrentObject.cc

    r2d11663 r60aaa51d  
    946946        }
    947947
    948         const Designation * CurrentObject::findNext( const Designation * designation ) {
    949                 using DesignatorChain = std::deque< ptr< Expr > >;
    950                 PRINT( std::cerr << "___findNext" << std::endl; )
    951                
    952                 // find all the d's
    953                 std::vector< DesignatorChain > desigAlts{ {} }, newDesigAlts;
    954                 std::deque< const Type * > curTypes{ objStack.back()->getType() }, newTypes;
    955                 for ( const Expr * expr : designation->designators ) {
    956                         PRINT( std::cerr << "____untyped: " << expr << std::endl; )
    957                         auto dit = desigAlts.begin();
    958                         if ( auto nexpr = dynamic_cast< const NameExpr * >( expr ) ) {
    959                                 for ( const Type * t : curTypes ) {
    960                                         assert( dit != desigAlts.end() );
    961 
    962                                         DesignatorChain & d = *dit;
    963                                         PRINT( std::cerr << "____actual: " << t << std::endl; )
    964                                         if ( auto refType = dynamic_cast< const ReferenceToType * >( t ) ) {
    965                                                 // concatenate identical field names
    966                                                 for ( const Decl * mem : refType->lookup( nexpr->name ) ) {
    967                                                         if ( auto field = dynamic_cast< const ObjectDecl * >( mem ) ) {
    968                                                                 PRINT( std::cerr << "____alt: " << field->type << std::endl; )
    969                                                                 DesignatorChain d2 = d;
    970                                                                 d2.emplace_back( new VariableExpr{ expr->location, field } );
    971                                                                 newDesigAlts.emplace_back( std::move( d2 ) );
    972                                                                 newTypes.emplace_back( field->type );
    973                                                         }
    974                                                 }
    975                                         }
    976 
    977                                         ++dit;
    978                                 }
    979                         } else {
    980                                 for ( const Type * t : curTypes ) {
    981                                         assert( dit != desigAlts.end() );
    982 
    983                                         DesignatorChain & d = *dit;
    984                                         if ( auto at = dynamic_cast< const ArrayType * >( t ) ) {
    985                                                 PRINT( std::cerr << "____alt: " << at->get_base() << std::endl; )
    986                                                 d.emplace_back( expr );
    987                                                 newDesigAlts.emplace_back( d );
    988                                                 newTypes.emplace_back( at->base );
    989                                         }
    990                                 }
    991                         }
    992 
    993                         // reset queue
    994                         desigAlts = std::move( newDesigAlts );
    995                         newDesigAlts.clear();
    996                         curTypes = std::move( newTypes );
    997                         newTypes.clear();
    998                         assertf( desigAlts.size() == curTypes.size(), "Designator alternatives (%zu) and current types (%zu) out of sync", desigAlts.size(), curTypes.size() );
    999                 }
    1000 
    1001                 if ( desigAlts.size() > 1 ) {
    1002                         SemanticError( designation, toString("Too many alternatives (", desigAlts.size(), ") for designation: ") );
    1003                 } else if ( desigAlts.empty() ) {
    1004                         SemanticError( designation, "No reasonable alternatives for designation: " );
    1005                 }
    1006 
    1007                 DesignatorChain & d = desigAlts.back();
    1008                 PRINT( for ( Expression * expr : d ) {
    1009                         std::cerr << "____desig: " << expr << std::endl;
    1010                 } ) // for
    1011                 assertf( ! curTypes.empty(), "empty designator chosen");
    1012 
    1013                 // set new designators
    1014                 assertf( ! objStack.empty(), "empty object stack when setting designation" );
    1015                 Designation * actualDesignation =
    1016                         new Designation{ designation->location, DesignatorChain{d} };
    1017                 objStack.back()->setPosition( d ); // destroys d
    1018                 return actualDesignation;
    1019         }
    1020 
    1021         void CurrentObject::setNext( const Designation * designation ) {
     948        void CurrentObject::setNext( const ast::Designation * designation ) {
    1022949                PRINT( std::cerr << "____setNext" << designation << std::endl; )
    1023950                assertf( ! objStack.empty(), "obj stack empty in setNext" );
Note: See TracChangeset for help on using the changeset viewer.