Ignore:
Timestamp:
Nov 20, 2014, 9:50:35 PM (10 years ago)
Author:
Peter A. Buhr <pabuhr@…>
Branches:
ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, ctor, deferred_resn, demangler, enum, forall-pointer-decay, gc_noraii, jacob/cs343-translation, jenkins-sandbox, master, memory, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, string, with_gc
Children:
ea3eb06
Parents:
1db2c5be
Message:

make routine static qualifier conditional, remove and reorder hoisted aggregate, format adjustment

File:
1 edited

Legend:

Unmodified
Added
Removed
  • translator/SymTab/Validate.cc

    r1db2c5be r3c70d38  
    117117        virtual void visit( TypeDecl *typeDecl );
    118118        virtual void visit( ContextDecl *ctxDecl );
     119        virtual void visit( FunctionDecl *functionDecl );
    119120
    120121        virtual void visit( FunctionType *ftype );
     
    129130        virtual void visit( CaseStmt *caseStmt );
    130131        virtual void visit( CatchStmt *catchStmt );
     132
     133        AddStructAssignment() : functionNesting( 0 ) {}
    131134      private:
    132135        template< typename StmtClass > void visitStatement( StmtClass *stmt );
     
    134137        std::list< Declaration * > declsToAdd;
    135138        std::set< std::string > structsDone;
     139        unsigned int functionNesting;                   // current level of nested functions
    136140    };
    137141
     
    194198    }
    195199
    196     void filter( std::list< Declaration * > &declList, bool (*pred )( Declaration * ), bool doDelete ) {
     200    void filter( std::list< Declaration * > &declList, bool (*pred)( Declaration * ), bool doDelete ) {
    197201        std::list< Declaration * >::iterator i = declList.begin();
    198202        while ( i != declList.end() ) {
     
    216220    void HoistStruct::handleAggregate( AggDecl *aggregateDecl ) {
    217221        if ( inStruct ) {
    218             declsToAdd.push_back( aggregateDecl );
     222            // Add elements in stack order corresponding to nesting structure.
     223            declsToAdd.push_front( aggregateDecl );
    219224            Visitor::visit( aggregateDecl );
    220225        } else {
     
    222227            Visitor::visit( aggregateDecl );
    223228            inStruct = false;
    224             filter( aggregateDecl->get_members(), isStructOrUnion, false );
    225         }
     229        }
     230        // Always remove the hoisted aggregate from the inner structure.
     231        filter( aggregateDecl->get_members(), isStructOrUnion, false );
    226232    }
    227233
     
    523529    }
    524530
    525     Declaration *makeStructAssignment( StructDecl *aggregateDecl, StructInstType *refType ) {
     531    Declaration *makeStructAssignment( StructDecl *aggregateDecl, StructInstType *refType, unsigned int functionNesting ) {
    526532        FunctionType *assignType = new FunctionType( Type::Qualifiers(), false );
    527533 
     
    534540        ObjectDecl *srcParam = new ObjectDecl( "_src", Declaration::NoStorageClass, LinkageSpec::Cforall, 0, refType, 0 );
    535541        assignType->get_parameters().push_back( srcParam );
    536  
    537         FunctionDecl *assignDecl = new FunctionDecl( "?=?", Declaration::Static, LinkageSpec::AutoGen, assignType, new CompoundStmt( noLabels ), true );
     542
     543        // Routines at global scope marked "static" to prevent multiple definitions is separate translation units
     544        // because each unit generates copies of the default routines for each aggregate.
     545        FunctionDecl *assignDecl = new FunctionDecl( "?=?", functionNesting > 0 ? Declaration::NoStorageClass : Declaration::Static, LinkageSpec::AutoGen, assignType, new CompoundStmt( noLabels ), true );
    538546        assignDecl->fixUniqueId();
    539547 
     
    552560    }
    553561
    554     Declaration *makeUnionAssignment( UnionDecl *aggregateDecl, UnionInstType *refType ) {
     562    Declaration *makeUnionAssignment( UnionDecl *aggregateDecl, UnionInstType *refType, unsigned int functionNesting ) {
    555563        FunctionType *assignType = new FunctionType( Type::Qualifiers(), false );
    556564 
     
    564572        assignType->get_parameters().push_back( srcParam );
    565573 
    566         FunctionDecl *assignDecl = new FunctionDecl( "?=?", Declaration::Static, LinkageSpec::AutoGen, assignType, new CompoundStmt( noLabels ), true );
     574        // Routines at global scope marked "static" to prevent multiple definitions is separate translation units
     575        // because each unit generates copies of the default routines for each aggregate.
     576        FunctionDecl *assignDecl = new FunctionDecl( "?=?",  functionNesting > 0 ? Declaration::NoStorageClass : Declaration::Static, LinkageSpec::AutoGen, assignType, new CompoundStmt( noLabels ), true );
    567577        assignDecl->fixUniqueId();
    568578 
     
    582592            StructInstType *structInst = new StructInstType( Type::Qualifiers(), structDecl->get_name() );
    583593            structInst->set_baseStruct( structDecl );
    584             declsToAdd.push_back( makeStructAssignment( structDecl, structInst ) );
     594            declsToAdd.push_back( makeStructAssignment( structDecl, structInst, functionNesting ) );
    585595            structsDone.insert( structDecl->get_name() );
    586596        }
     
    591601            UnionInstType *unionInst = new UnionInstType( Type::Qualifiers(), unionDecl->get_name() );
    592602            unionInst->set_baseUnion( unionDecl );
    593             declsToAdd.push_back( makeUnionAssignment( unionDecl, unionInst ) );
     603            declsToAdd.push_back( makeUnionAssignment( unionDecl, unionInst, functionNesting ) );
    594604        }
    595605    }
     
    647657    }
    648658
     659    void AddStructAssignment::visit( FunctionDecl *functionDecl ) {
     660        maybeAccept( functionDecl->get_functionType(), *this );
     661        acceptAll( functionDecl->get_oldDecls(), *this );
     662        functionNesting += 1;
     663        maybeAccept( functionDecl->get_statements(), *this );
     664        functionNesting -= 1;
     665    }
     666
    649667    void AddStructAssignment::visit( CompoundStmt *compoundStmt ) {
    650668        visitStatement( compoundStmt );
Note: See TracChangeset for help on using the changeset viewer.