Ignore:
Timestamp:
Aug 8, 2016, 5:29:03 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, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, with_gc
Children:
03da511
Parents:
0853178 (diff), 7bf7fb9 (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 ctor

Conflicts:

src/SymTab/Autogen.cc

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/SymTab/Autogen.cc

    r0853178 r04273e9  
    173173        }
    174174
    175         void makeStructMemberOp( ObjectDecl * dstParam, Expression * src, DeclarationWithType * field, FunctionDecl * func, TypeSubstitution & genericSubs, bool isGeneric, bool forward = true ) {
    176                 if ( isGeneric ) {
    177                         // rewrite member type in terms of the type variables on this operator
    178                         field = field->clone();
    179                         genericSubs.apply( field );
    180 
    181                         if ( src ) {
    182                                 genericSubs.apply( src );
    183                         }
     175        void makeStructMemberOp( ObjectDecl * dstParam, Expression * src, DeclarationWithType * field, FunctionDecl * func, TypeSubstitution & genericSubs, bool isDynamicLayout, bool forward = true ) {
     176                if ( isDynamicLayout && src ) {
     177                        genericSubs.apply( src );
    184178                }
    185179
     
    197191                genImplicitCall( srcParam, dstselect, func->get_name(), back_inserter( func->get_statements()->get_kids() ), field, forward );
    198192
    199                 if ( isGeneric && returnVal ) {
     193                if ( isDynamicLayout && returnVal ) {
    200194                        UntypedExpr *derefRet = new UntypedExpr( new NameExpr( "*?" ) );
    201195                        derefRet->get_args().push_back( new VariableExpr( returnVal ) );
     
    206200
    207201        template<typename Iterator>
    208         void makeStructFunctionBody( Iterator member, Iterator end, FunctionDecl * func, TypeSubstitution & genericSubs, bool isGeneric, bool forward = true ) {
     202        void makeStructFunctionBody( Iterator member, Iterator end, FunctionDecl * func, TypeSubstitution & genericSubs, bool isDynamicLayout, bool forward = true ) {
    209203                for ( ; member != end; ++member ) {
    210204                        if ( DeclarationWithType *field = dynamic_cast< DeclarationWithType * >( *member ) ) { // otherwise some form of type declaration, e.g. Aggregate
     
    242236
    243237                                Expression *srcselect = srcParam ? new MemberExpr( field, new VariableExpr( srcParam ) ) : NULL;
    244                                 makeStructMemberOp( dstParam, srcselect, field, func, genericSubs, isGeneric, forward );
     238                                makeStructMemberOp( dstParam, srcselect, field, func, genericSubs, isDynamicLayout, forward );
    245239                        } // if
    246240                } // for
     
    250244        /// void ?{}(A *, int) and void?{}(A *, int, int) for a struct A which has two int fields.
    251245        template<typename Iterator>
    252         void makeStructFieldCtorBody( Iterator member, Iterator end, FunctionDecl * func, TypeSubstitution & genericSubs, bool isGeneric ) {
     246        void makeStructFieldCtorBody( Iterator member, Iterator end, FunctionDecl * func, TypeSubstitution & genericSubs, bool isDynamicLayout ) {
    253247                FunctionType * ftype = func->get_functionType();
    254248                std::list<DeclarationWithType*> & params = ftype->get_parameters();
     
    276270                                        // matching parameter, initialize field with copy ctor
    277271                                        Expression *srcselect = new VariableExpr(*parameter);
    278                                         makeStructMemberOp( dstParam, srcselect, field, func, genericSubs, isGeneric );
     272                                        makeStructMemberOp( dstParam, srcselect, field, func, genericSubs, isDynamicLayout );
    279273                                        ++parameter;
    280274                                } else {
    281275                                        // no matching parameter, initialize field with default ctor
    282                                         makeStructMemberOp( dstParam, NULL, field, func, genericSubs, isGeneric );
     276                                        makeStructMemberOp( dstParam, NULL, field, func, genericSubs, isDynamicLayout );
    283277                                }
    284278                        }
     
    290284
    291285                // Make function polymorphic in same parameters as generic struct, if applicable
    292                 bool isGeneric = false;  // NOTE this flag is an incredibly ugly kludge; we should fix the assignment signature instead (ditto for union)
     286                bool isDynamicLayout = false;  // NOTE this flag is an incredibly ugly kludge; we should fix the assignment signature instead (ditto for union)
    293287                std::list< TypeDecl* >& genericParams = aggregateDecl->get_parameters();
    294288                std::list< Expression* > structParams;  // List of matching parameters to put on types
    295289                TypeSubstitution genericSubs; // Substitutions to make to member types of struct
    296290                for ( std::list< TypeDecl* >::const_iterator param = genericParams.begin(); param != genericParams.end(); ++param ) {
    297                         isGeneric = true;
     291                        if ( (*param)->get_kind() == TypeDecl::Any ) isDynamicLayout = true;
    298292                        TypeDecl *typeParam = cloneAndRename( *param, "_autoassign_" + aggregateDecl->get_name() + "_" + (*param)->get_name() );
    299293                        assignType->get_forall().push_back( typeParam );
     
    355349                        FunctionDecl * ctor = new FunctionDecl( "?{}", functionNesting > 0 ? DeclarationNode::NoStorageClass : DeclarationNode::Static, LinkageSpec::AutoGen, memCtorType->clone(), new CompoundStmt( noLabels ), true, false );
    356350                        ctor->fixUniqueId();
    357                         makeStructFieldCtorBody( aggregateDecl->get_members().begin(), aggregateDecl->get_members().end(), ctor, genericSubs, isGeneric );
     351                        makeStructFieldCtorBody( aggregateDecl->get_members().begin(), aggregateDecl->get_members().end(), ctor, genericSubs, isDynamicLayout );
    358352                        memCtors.push_back( ctor );
    359353                }
     
    361355
    362356                // generate appropriate calls to member ctor, assignment
    363                 makeStructFunctionBody( aggregateDecl->get_members().begin(), aggregateDecl->get_members().end(), assignDecl, genericSubs, isGeneric );
    364                 makeStructFunctionBody( aggregateDecl->get_members().begin(), aggregateDecl->get_members().end(), ctorDecl, genericSubs, isGeneric );
    365                 makeStructFunctionBody( aggregateDecl->get_members().begin(), aggregateDecl->get_members().end(), copyCtorDecl, genericSubs, isGeneric );
     357                makeStructFunctionBody( aggregateDecl->get_members().begin(), aggregateDecl->get_members().end(), assignDecl, genericSubs, isDynamicLayout );
     358                makeStructFunctionBody( aggregateDecl->get_members().begin(), aggregateDecl->get_members().end(), ctorDecl, genericSubs, isDynamicLayout );
     359                makeStructFunctionBody( aggregateDecl->get_members().begin(), aggregateDecl->get_members().end(), copyCtorDecl, genericSubs, isDynamicLayout );
    366360                // needs to do everything in reverse, so pass "forward" as false
    367                 makeStructFunctionBody( aggregateDecl->get_members().rbegin(), aggregateDecl->get_members().rend(), dtorDecl, genericSubs, isGeneric, false );
    368 
    369                 if ( ! isGeneric ) assignDecl->get_statements()->get_kids().push_back( new ReturnStmt( noLabels, new VariableExpr( srcParam ) ) );
     361                makeStructFunctionBody( aggregateDecl->get_members().rbegin(), aggregateDecl->get_members().rend(), dtorDecl, genericSubs, isDynamicLayout, false );
     362
     363                if ( ! isDynamicLayout ) assignDecl->get_statements()->get_kids().push_back( new ReturnStmt( noLabels, new VariableExpr( srcParam ) ) );
    370364
    371365                declsToAdd.push_back( assignDecl );
     
    380374
    381375                // Make function polymorphic in same parameters as generic union, if applicable
    382                 bool isGeneric = false; // NOTE this flag is an incredibly ugly kludge; we should fix the assignment signature instead (ditto for struct)
     376                bool isDynamicLayout = false; // NOTE this flag is an incredibly ugly kludge; we should fix the assignment signature instead (ditto for struct)
    383377                std::list< TypeDecl* >& genericParams = aggregateDecl->get_parameters();
    384378                std::list< Expression* > unionParams;  // List of matching parameters to put on types
    385379                for ( std::list< TypeDecl* >::const_iterator param = genericParams.begin(); param != genericParams.end(); ++param ) {
    386                         isGeneric = true;
     380                        if ( (*param)->get_kind() == TypeDecl::Any ) isDynamicLayout = true;
    387381                        TypeDecl *typeParam = cloneAndRename( *param, "_autoassign_" + aggregateDecl->get_name() + "_" + (*param)->get_name() );
    388382                        assignType->get_forall().push_back( typeParam );
     
    420414
    421415                makeUnionFieldsAssignment( srcParam, dstParam, cloneWithParams( refType, unionParams ), back_inserter( assignDecl->get_statements()->get_kids() ) );
    422                 if ( isGeneric ) makeUnionFieldsAssignment( srcParam, returnVal, cloneWithParams( refType, unionParams ), back_inserter( assignDecl->get_statements()->get_kids() ) );
     416                if ( isDynamicLayout ) makeUnionFieldsAssignment( srcParam, returnVal, cloneWithParams( refType, unionParams ), back_inserter( assignDecl->get_statements()->get_kids() ) );
    423417                else assignDecl->get_statements()->get_kids().push_back( new ReturnStmt( noLabels, new VariableExpr( srcParam ) ) );
    424418
Note: See TracChangeset for help on using the changeset viewer.