Ignore:
Timestamp:
Aug 2, 2016, 6:37:08 PM (8 years ago)
Author:
Rob Schluntz <rschlunt@…>
Branches:
ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, ctor, deferred_resn, demangler, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, memory, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, with_gc
Children:
8a443f4
Parents:
39f84a4
Message:

major reorganization of constructor generation from initializer list so that it now works with multi-dimensional arrays

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/ResolvExpr/Resolver.cc

    r39f84a4 r4d2434a  
    5454                virtual void visit( BranchStmt *branchStmt );
    5555                virtual void visit( ReturnStmt *returnStmt );
    56                 virtual void visit( ImplicitCtorDtorStmt * impCtorDtorStmt );
    5756
    5857                virtual void visit( SingleInit *singleInit );
     
    436435
    437436        void Resolver::visit( ListInit * listInit ) {
    438                 InitIterator iter = listInit->begin_initializers();
    439                 InitIterator end = listInit->end_initializers();
     437                InitIterator iter = listInit->begin();
     438                InitIterator end = listInit->end();
    440439
    441440                if ( ArrayType * at = dynamic_cast< ArrayType * >( initContext ) ) {
     
    539538                        ctorInit->set_ctor( NULL );
    540539                }
    541                 if ( InitTweak::isInstrinsicSingleArgCallStmt( ctorInit->get_ctor() ) ) {
     540                if ( InitTweak::isInstrinsicSingleArgCallStmt( ctorInit->get_dtor() ) ) {
    542541                        delete ctorInit->get_dtor();
    543542                        ctorInit->set_dtor( NULL );
    544543                }
    545         }
    546 
    547         void Resolver::visit( ImplicitCtorDtorStmt * impCtorDtorStmt ) {
    548                 // before resolving ctor/dtor, need to remove type qualifiers from the first argument (the object being constructed).
    549                 // Do this through a cast expression to greatly simplify the code.
    550                 Expression * callExpr = InitTweak::getCtorDtorCall( impCtorDtorStmt );
    551                 assert( callExpr );
    552                 Expression *& constructee = InitTweak::getCallArg( callExpr, 0 );
    553 
    554                 // the first argument will always be &<expr>
    555                 AddressExpr * addrExpr = dynamic_cast< AddressExpr * > ( constructee );
    556                 assert( addrExpr );
    557 
    558                 // need to find the type of the first argument. In the case of an array,
    559                 // need to remove one ArrayType layer from the type for each subscript expression.
    560                 Expression * addressee = addrExpr->get_arg();
    561                 int numLayers = 0;
    562                 while ( UntypedExpr * untypedExpr = dynamic_cast< UntypedExpr * >( addressee ) ) {
    563                         assert( InitTweak::getFunctionName( untypedExpr ) == "?[?]" );
    564                         addressee = InitTweak::getCallArg( untypedExpr, 0 );
    565                         numLayers++;
    566                 }
    567                 assert( addressee->get_results().size() == 1 );
    568                 Type * type = addressee->get_results().front();
    569                 for ( int i = 0; i < numLayers; i++ ) {
    570                         type = InitTweak::getPointerBase( type );
    571                         assert( type && "Expected pointer or array type. May have generated too many ?[?] calls." );
    572                 }
    573 
    574                 // cast to T* with qualifiers removed.
    575                 // unfortunately, lvalue is considered a qualifier. For AddressExpr to resolve, its argument
    576                 // must have an lvalue qualified type, so remove all qualifiers except lvalue. If we ever
    577                 // remove lvalue as a qualifier, this can change to
    578                 //   type->get_qualifiers() = Type::Qualifiers();
    579                 assert( type );
    580                 type = type->clone();
    581                 type->get_qualifiers() -= Type::Qualifiers(true, true, true, false, true, true);
    582                 type = new PointerType( Type::Qualifiers(), type );
    583                 constructee = new CastExpr( constructee, type );
    584 
    585                 // finally, resolve the ctor/dtor
    586                 impCtorDtorStmt->get_callStmt()->accept( *this );
    587544        }
    588545} // namespace ResolvExpr
Note: See TracChangeset for help on using the changeset viewer.