Changeset 2d11663 for src/ResolvExpr


Ignore:
Timestamp:
Jun 10, 2019, 1:48:19 PM (6 years ago)
Author:
Aaron Moss <a3moss@…>
Branches:
ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, pthread-emulation, qualifiedEnum
Children:
f9a7cf0
Parents:
05d55ff
Message:

resolver porting; finish top level of initialization

Location:
src/ResolvExpr
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • src/ResolvExpr/CurrentObject.cc

    r05d55ff r2d11663  
    946946        }
    947947
    948         void CurrentObject::setNext( const ast::Designation * designation ) {
     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 ) {
    9491022                PRINT( std::cerr << "____setNext" << designation << std::endl; )
    9501023                assertf( ! objStack.empty(), "obj stack empty in setNext" );
  • src/ResolvExpr/CurrentObject.h

    r05d55ff r2d11663  
    111111                CurrentObject( const CodeLocation & loc, const Type * type );
    112112
     113                /// resolves unresolved designation
     114                const Designation * findNext( const Designation * designation );
    113115                /// sets current position using the resolved designation
    114116                void setNext( const ast::Designation * designation );
  • src/ResolvExpr/Resolver.cc

    r05d55ff r2d11663  
    12271227                void previsit( const ast::WaitForStmt * );
    12281228
    1229                 const ast::SingleInit * previsit( const ast::SingleInit * );
    1230                 const ast::ListInit * previsit( const ast::ListInit * );
    1231                 void previsit( const ast::ConstructorInit * );
     1229                const ast::SingleInit *      previsit( const ast::SingleInit * );
     1230                const ast::ListInit *        previsit( const ast::ListInit * );
     1231                const ast::ConstructorInit * previsit( const ast::ConstructorInit * );
    12321232        };
    12331233
     
    15101510                        // iterate designations and initializers in pairs, moving the cursor to the current
    15111511                        // designated object and resolving the initializer against that object
    1512                         #warning unimplemented; Resolver port in progress
    1513                         assert(false);
    1514                 }
     1512                        listInit = ast::mutate_field_index(
     1513                                listInit, &ast::ListInit::designations, i,
     1514                                currentObject.findNext( listInit->designations[i] ) );
     1515                        listInit = ast::mutate_field_index(
     1516                                listInit, &ast::ListInit::initializers, i,
     1517                                listInit->initializers[i]->accept( *visitor ) );
     1518                }
     1519
     1520                // move cursor out of brace-enclosed initializer-list
     1521                currentObject.exitListInit();
    15151522
    15161523                visit_children = false;
     
    15181525        }
    15191526
    1520         void Resolver_new::previsit( const ast::ConstructorInit * ctorInit ) {
    1521                 #warning unimplemented; Resolver port in progress
    1522                 (void)ctorInit;
    1523                 assert(false);
     1527        const ast::ConstructorInit * Resolver_new::previsit( const ast::ConstructorInit * ctorInit ) {
     1528                visitor->maybe_accept( ctorInit, &ast::ConstructorInit::ctor );
     1529                visitor->maybe_accept( ctorInit, &ast::ConstructorInit::dtor );
     1530
     1531                // found a constructor - can get rid of C-style initializer
     1532                // xxx - Rob suggests this field is dead code
     1533                ctorInit = ast::mutate_field( ctorInit, &ast::ConstructorInit::init, nullptr );
     1534
     1535                // intrinsic single-parameter constructors and destructors do nothing. Since this was
     1536                // implicitly generated, there's no way for it to have side effects, so get rid of it to
     1537                // clean up generated code
     1538                if ( InitTweak::isIntrinsicSingleArgCallStmt( ctorInit->ctor ) ) {
     1539                        ctorInit = ast::mutate_field( ctorInit, &ast::ConstructorInit::ctor, nullptr );
     1540                }
     1541                if ( InitTweak::isIntrinsicSingleArgCallStmt( ctorInit->dtor ) ) {
     1542                        ctorInit = ast::mutate_field( ctorInit, &ast::ConstructorInit::dtor, nullptr );
     1543                }
     1544
     1545                return ctorInit;
    15241546        }
    15251547
Note: See TracChangeset for help on using the changeset viewer.