Changeset 3c70d38


Ignore:
Timestamp:
Nov 20, 2014, 9:50:35 PM (8 years ago)
Author:
Peter A. Buhr <pabuhr@…>
Branches:
aaron-thesis, arm-eh, 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, resolv-new, string, with_gc
Children:
ea3eb06
Parents:
1db2c5be
Message:

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

Location:
translator
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • translator/SymTab/TypeTable.h

    r1db2c5be r3c70d38  
    1 /*
    2  * This file is part of the Cforall project
    3  *
    4  * $Id: TypeTable.h,v 1.2 2005/08/29 20:14:18 rcbilson Exp $
    5  *
    6  */
    7 
    81#ifndef SYMTAB_TYPETABLE_H
    92#define SYMTAB_TYPETABLE_H
     
    1912
    2013namespace SymTab {
     14    class TypeTableConflictFunction : public std::binary_function< NamedTypeDecl *, NamedTypeDecl *, NamedTypeDecl * > {
     15      public:
     16        NamedTypeDecl *operator()( NamedTypeDecl *existing, NamedTypeDecl *added ) {
     17            if ( existing->get_base() == 0 ) {
     18                return added;
     19            } else if( added->get_base() == 0 ) {
     20                return existing;
     21            } else {
     22                throw SemanticError( "redeclaration of ", added );
     23            }
     24            assert( false );
     25            return 0;
     26        }
     27    };
    2128
    22 class TypeTableConflictFunction : public std::binary_function< NamedTypeDecl*, NamedTypeDecl*, NamedTypeDecl* >
    23 {
    24 public:
    25   NamedTypeDecl *operator()( NamedTypeDecl *existing, NamedTypeDecl *added )
    26   {
    27     if( existing->get_base() == 0 ) {
    28       return added;
    29     } else if( added->get_base() == 0 ) {
    30       return existing;
    31     } else {
    32       throw SemanticError( "redeclaration of ", added );
    33     }
    34     assert( false );
    35     return 0;
    36   }
    37  
    38 };
     29    typedef StackTable< NamedTypeDecl, TypeTableConflictFunction > TypeTable;
     30} // SymTab
    3931
    40 typedef StackTable< NamedTypeDecl, TypeTableConflictFunction > TypeTable;
    41 
    42 } // namespace SymTab
    43 
    44 #endif /* #ifndef SYMTAB_TYPETABLE_H */
     32#endif // SYMTAB_TYPETABLE_H
  • 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 );
  • translator/SymTab/Validate.h

    r1db2c5be r3c70d38  
    1 /*
    2  * This file is part of the Cforall project
    3  *
    4  * This class is intended to perform pre-processing of declarations, validating their
    5  * correctness and computing some auxilliary data that is necessary for the indexer.
    6  *
    7  * $Id: Validate.h,v 1.7 2005/08/29 20:14:18 rcbilson Exp $
    8  *
    9  */
     1// This class is intended to perform pre-processing of declarations, validating their
     2// correctness and computing some auxilliary data that is necessary for the indexer.
    103
    114#ifndef SYMTAB_VALIDATE_H
     
    158
    169namespace SymTab {
     10    class Indexer;
    1711
    18 class Indexer;
     12    void validate( std::list< Declaration * > &translationUnit, bool doDebug = false, const Indexer *indexer = 0 );
     13    void validateType( Type *type, const Indexer *indexer );
     14} // SymTab
    1915
    20 void validate( std::list< Declaration* > &translationUnit, bool doDebug = false,
    21                const Indexer *indexer = 0 );
    22 
    23 void validateType( Type *type, const Indexer *indexer );
    24 
    25 } // namespace SymTab
    26 
    27 #endif /* #ifndef SYMTAB_VALIDATE_H */
     16#endif // SYMTAB_VALIDATE_H
Note: See TracChangeset for help on using the changeset viewer.