Changeset a2f920f


Ignore:
Timestamp:
Aug 5, 2016, 11:39:05 AM (5 years ago)
Author:
Aaron Moss <a3moss@…>
Branches:
aaron-thesis, arm-eh, cleanup-dtors, ctor, deferred_resn, demangler, jacob/cs343-translation, jenkins-sandbox, master, memory, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, resolv-new, with_gc
Children:
71a3593, d1ef1b0
Parents:
c331406
Message:

Cleanup after dtype constructor fix

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/SymTab/Autogen.cc

    rc331406 ra2f920f  
    173173        }
    174174
    175         void makeStructMemberOp( ObjectDecl * dstParam, Expression * src, DeclarationWithType * field, FunctionDecl * func, TypeSubstitution & genericSubs, bool isGeneric, bool isDynamicLayout, 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
     
    206200
    207201        template<typename Iterator>
    208         void makeStructFunctionBody( Iterator member, Iterator end, FunctionDecl * func, TypeSubstitution & genericSubs, bool isGeneric, bool isDynamicLayout, 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, isDynamicLayout, 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, bool isDynamicLayout ) {
     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, isDynamicLayout );
     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, isDynamicLayout );
     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)
    293                 bool isDynamicLayout = false;  // NOTE see above re: kludge
     286                bool isDynamicLayout = false;  // NOTE this flag is an incredibly ugly kludge; we should fix the assignment signature instead (ditto for union)
    294287                std::list< TypeDecl* >& genericParams = aggregateDecl->get_parameters();
    295288                std::list< Expression* > structParams;  // List of matching parameters to put on types
    296289                TypeSubstitution genericSubs; // Substitutions to make to member types of struct
    297290                for ( std::list< TypeDecl* >::const_iterator param = genericParams.begin(); param != genericParams.end(); ++param ) {
    298                         isGeneric = true;
    299291                        if ( (*param)->get_kind() == TypeDecl::Any ) isDynamicLayout = true;
    300292                        TypeDecl *typeParam = cloneAndRename( *param, "_autoassign_" + aggregateDecl->get_name() + "_" + (*param)->get_name() );
     
    357349                        FunctionDecl * ctor = new FunctionDecl( "?{}", functionNesting > 0 ? DeclarationNode::NoStorageClass : DeclarationNode::Static, LinkageSpec::AutoGen, memCtorType->clone(), new CompoundStmt( noLabels ), true, false );
    358350                        ctor->fixUniqueId();
    359                         makeStructFieldCtorBody( aggregateDecl->get_members().begin(), aggregateDecl->get_members().end(), ctor, genericSubs, isGeneric, isDynamicLayout );
     351                        makeStructFieldCtorBody( aggregateDecl->get_members().begin(), aggregateDecl->get_members().end(), ctor, genericSubs, isDynamicLayout );
    360352                        memCtors.push_back( ctor );
    361353                }
     
    363355
    364356                // generate appropriate calls to member ctor, assignment
    365                 makeStructFunctionBody( aggregateDecl->get_members().begin(), aggregateDecl->get_members().end(), assignDecl, genericSubs, isGeneric, isDynamicLayout );
    366                 makeStructFunctionBody( aggregateDecl->get_members().begin(), aggregateDecl->get_members().end(), ctorDecl, genericSubs, isGeneric, isDynamicLayout );
    367                 makeStructFunctionBody( aggregateDecl->get_members().begin(), aggregateDecl->get_members().end(), copyCtorDecl, genericSubs, isGeneric, isDynamicLayout );
     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 );
    368360                // needs to do everything in reverse, so pass "forward" as false
    369                 makeStructFunctionBody( aggregateDecl->get_members().rbegin(), aggregateDecl->get_members().rend(), dtorDecl, genericSubs, isGeneric, isDynamicLayout, false );
    370 
    371                 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 ) ) );
    372364
    373365                declsToAdd.push_back( assignDecl );
Note: See TracChangeset for help on using the changeset viewer.