Ignore:
Timestamp:
Sep 6, 2016, 4:36:29 PM (9 years ago)
Author:
Rob Schluntz <rschlunt@…>
Branches:
ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, deferred_resn, demangler, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, with_gc
Children:
e76acbe
Parents:
0362d42 (diff), f04a8b81 (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' into tuples

File:
1 edited

Legend:

Unmodified
Added
Removed
  • TabularUnified src/InitTweak/FixInit.cc

    r0362d42 r1ced874  
    200200                        ObjectDecl * thisParam = 0;
    201201                        bool isCtor = false; // true if current function is a constructor
     202                        StructDecl * structDecl = 0;
    202203                };
    203204
     
    744745                        ValueGuard< ObjectDecl * > oldThisParam( thisParam );
    745746                        ValueGuard< bool > oldIsCtor( isCtor );
     747                        ValueGuard< StructDecl * > oldStructDecl( structDecl );
    746748
    747749                        // need to start with fresh sets
     
    758760                                StructInstType * structType = dynamic_cast< StructInstType * >( ptrType->get_base() );
    759761                                if ( structType ) {
    760                                         StructDecl * structDecl = structType->get_baseStruct();
     762                                        structDecl = structType->get_baseStruct();
    761763                                        for ( Declaration * member : structDecl->get_members() ) {
    762764                                                if ( ObjectDecl * field = dynamic_cast< ObjectDecl * >( member ) ) {
     
    775777                        std::set_difference( usedUninit.begin(), usedUninit.end(), unhandled.begin(), unhandled.end(), std::inserter( diff, diff.begin() ) );
    776778                        for ( DeclarationWithType * member : diff ) {
    777                                 emit( "in ", CodeGen::genType( function->get_functionType(), function->get_name(), false ), ", member ", member->get_name(), " used before being constructed" );
     779                                emit( "in ", CodeGen::genType( function->get_functionType(), function->get_name(), false ), ", field ", member->get_name(), " used before being constructed" );
    778780                        }
    779781
     
    781783                                // need to explicitly re-add function parameters in order to resolve copy constructors
    782784                                enterScope();
    783                                 // maybeAccept( function->get_functionType(), *this );
    784                                 for ( DeclarationWithType * member : unhandled ) {
    785                                         // insert and resolve default/copy constructor call for each member that's unhandled
     785                                maybeAccept( function->get_functionType(), *this );
     786
     787                                // need to iterate through members in reverse in order for
     788                                // ctor/dtor statements to come out in the right order
     789                                for ( Declaration * member : reverseIterate( structDecl->get_members() ) ) {
     790                                        DeclarationWithType * field = dynamic_cast< DeclarationWithType * >( member );
     791                                        // skip non-DWT members
     792                                        if ( ! field ) continue;
     793                                        // skip handled members
     794                                        if ( ! unhandled.count( field ) ) continue;
     795
     796                                        // insert and resolve default/copy constructor call for each field that's unhandled
    786797                                        std::list< Statement * > stmt;
    787798                                        UntypedExpr * deref = new UntypedExpr( new NameExpr( "*?" ) );
    788799                                        deref->get_args().push_back( new VariableExpr( thisParam ) );
    789                                         InitExpander srcParam( (Initializer *)NULL ); // xxx - if copy ctor, need to pass appropriate argument - second param of this function dot member
    790                                         SymTab::genImplicitCall( srcParam, new MemberExpr( member, deref ), function->get_name(), back_inserter( stmt ), member, isCtor );
     800
     801                                        Expression * arg2 = 0;
     802                                        if ( isCopyConstructor( function ) ) {
     803                                                // if copy ctor, need to pass second-param-of-this-function.field
     804                                                std::list< DeclarationWithType * > & params = function->get_functionType()->get_parameters();
     805                                                assert( params.size() == 2 );
     806                                                arg2 = new MemberExpr( field, new VariableExpr( params.back() ) );
     807                                        }
     808                                        InitExpander srcParam( arg2 );
     809                                        SymTab::genImplicitCall( srcParam, new MemberExpr( field, deref ), function->get_name(), back_inserter( stmt ), field, isCtor );
    791810
    792811                                        assert( stmt.size() <= 1 );
     
    796815                                                MutatingResolver resolver( *this );
    797816                                                try {
    798                                                         // xxx - these should be in field declaration order
    799817                                                        callStmt->acceptMutator( resolver );
    800818                                                        if ( isCtor ) {
     
    805823                                                        }
    806824                                                } catch ( SemanticError & error ) {
    807                                                         emit( "in ", CodeGen::genType( function->get_functionType(), function->get_name(), false ), ", member ", member->get_name(), " not explicitly ", isCtor ? "constructed" : "destructed",  " and no ", isCtor ? "default constructor" : "destructor", " found" );
     825                                                        emit( "in ", CodeGen::genType( function->get_functionType(), function->get_name(), false ), ", field ", field->get_name(), " not explicitly ", isCtor ? "constructed" : "destructed",  " and no ", isCtor ? "default constructor" : "destructor", " found" );
    808826                                                }
    809827                                        }
     
    832850                                        handleFirstParam( firstParam );
    833851                                }
    834                         } else if ( fname == "?=?" && isIntrinsicCallExpr( appExpr ) ) {
    835                                 // forgive use of intrinsic assignment to construct, since instrinsic constructors
    836                                 // codegen as assignment anyway.
    837                                 assert( appExpr->get_args().size() == 2 );
    838                                 handleFirstParam( appExpr->get_args().front() );
    839852                        }
    840853
Note: See TracChangeset for help on using the changeset viewer.