Changeset 579263a for src/SymTab


Ignore:
Timestamp:
Jun 26, 2017, 4:48:35 PM (8 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:
bb1cd95
Parents:
e4d829b (diff), 2a7b3ca (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 designations

Conflicts:

src/InitTweak/FixInit.cc
src/SymTab/Autogen.h
src/SynTree/Initializer.cc
src/SynTree/Initializer.h
src/Tuples/TupleExpansion.cc

Location:
src/SymTab
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • src/SymTab/Autogen.cc

    re4d829b r579263a  
    262262        // E ?=?(E volatile*, int),
    263263        //   ?=?(E _Atomic volatile*, int);
    264         void makeEnumFunctions( EnumDecl *enumDecl, EnumInstType *refType, unsigned int functionNesting, std::list< Declaration * > &declsToAdd ) {
     264        void makeEnumFunctions( EnumInstType *refType, unsigned int functionNesting, std::list< Declaration * > &declsToAdd ) {
    265265
    266266                // T ?=?(E *, E);
     
    486486
    487487        /// generates the body of a union assignment/copy constructor/field constructor
    488         void makeUnionAssignBody( FunctionDecl * funcDecl, bool isDynamicLayout ) {
     488        void makeUnionAssignBody( FunctionDecl * funcDecl ) {
    489489                FunctionType * ftype = funcDecl->get_functionType();
    490490                assert( ftype->get_parameters().size() == 2 );
     
    506506                // Make function polymorphic in same parameters as generic union, if applicable
    507507                const std::list< TypeDecl* > & typeParams = aggregateDecl->get_parameters(); // List of type variables to be placed on the generated functions
    508                 bool isDynamicLayout = hasDynamicLayout( aggregateDecl );  // NOTE this flag is an incredibly ugly kludge; we should fix the assignment signature instead (ditto for struct)
    509 
     508               
    510509                // default ctor/dtor need only first parameter
    511510                // void ?{}(T *); void ^?{}(T *);
     
    533532                FunctionDecl *dtorDecl = genFunc( "^?{}", dtorType, functionNesting );
    534533
    535                 makeUnionAssignBody( assignDecl, isDynamicLayout );
     534                makeUnionAssignBody( assignDecl );
    536535
    537536                // body of assignment and copy ctor is the same
    538                 makeUnionAssignBody( copyCtorDecl, isDynamicLayout );
     537                makeUnionAssignBody( copyCtorDecl );
    539538
    540539                // create a constructor which takes the first member type as a parameter.
     
    551550                                FunctionDecl * ctor = genFunc( "?{}", memCtorType, functionNesting );
    552551
    553                                 makeUnionAssignBody( ctor, isDynamicLayout );
     552                                makeUnionAssignBody( ctor );
    554553                                memCtors.push_back( ctor );
    555554                                // only generate a ctor for the first field
     
    578577                        EnumInstType *enumInst = new EnumInstType( Type::Qualifiers(), enumDecl->get_name() );
    579578                        // enumInst->set_baseEnum( enumDecl );
    580                         makeEnumFunctions( enumDecl, enumInst, functionNesting, declsToAddAfter );
     579                        makeEnumFunctions( enumInst, functionNesting, declsToAddAfter );
    581580                }
    582581        }
  • src/SymTab/Autogen.h

    re4d829b r579263a  
    1010// Created On       : Sun May 17 21:53:34 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Fri Mar 17 09:10:41 2017
    13 // Update Count     : 9
     12// Last Modified On : Wed Jun 21 17:25:26 2017
     13// Update Count     : 14
    1414//
    1515
     
    4343        template< typename OutputIterator >
    4444        Statement * genScalarCall( InitTweak::InitExpander & srcParam, Expression *dstParam, const std::string & fname, OutputIterator out, Type * type, bool addCast = false ) {
    45                 // want to be able to generate assignment, ctor, and dtor generically,
    46                 // so fname is either ?=?, ?{}, or ^?{}
    47                 UntypedExpr *fExpr = new UntypedExpr( new NameExpr( fname ) );
     45        // want to be able to generate assignment, ctor, and dtor generically,
     46        // so fname is either ?=?, ?{}, or ^?{}
     47        UntypedExpr *fExpr = new UntypedExpr( new NameExpr( fname ) );
    4848
    49                 // do something special for unnamed members
    50                 dstParam = new AddressExpr( dstParam );
    51                 if ( addCast ) {
    52                         // cast to T* with qualifiers removed, so that qualified objects can be constructed
    53                         // and destructed with the same functions as non-qualified objects.
    54                         // unfortunately, lvalue is considered a qualifier. For AddressExpr to resolve, its argument
    55                         // must have an lvalue qualified type, so remove all qualifiers except lvalue. If we ever
    56                         // remove lvalue as a qualifier, this can change to
    57                         //   type->get_qualifiers() = Type::Qualifiers();
    58                         assert( type );
    59                         Type * castType = type->clone();
    60 //                      castType->get_qualifiers() -= Type::Qualifiers(true, true, true, false, true, false);
    61                         castType->get_qualifiers() -= Type::Qualifiers( Type::Const | Type::Volatile | Type::Restrict | Type::Atomic );
    62                         castType->set_lvalue( true ); // xxx - might not need this
    63                         dstParam = new CastExpr( dstParam, new PointerType( Type::Qualifiers(), castType ) );
    64                 }
    65                 fExpr->get_args().push_back( dstParam );
     49        // do something special for unnamed members
     50        dstParam = new AddressExpr( dstParam );
     51        if ( addCast ) {
     52                // cast to T* with qualifiers removed, so that qualified objects can be constructed
     53                // and destructed with the same functions as non-qualified objects.
     54                // unfortunately, lvalue is considered a qualifier. For AddressExpr to resolve, its argument
     55                // must have an lvalue qualified type, so remove all qualifiers except lvalue. If we ever
     56                // remove lvalue as a qualifier, this can change to
     57                //   type->get_qualifiers() = Type::Qualifiers();
     58                assert( type );
     59                Type * castType = type->clone();
     60                castType->get_qualifiers() -= Type::Qualifiers( Type::Const | Type::Volatile | Type::Restrict | Type::Atomic );
     61                castType->set_lvalue( true ); // xxx - might not need this
     62                dstParam = new CastExpr( dstParam, new PointerType( Type::Qualifiers(), castType ) );
     63        }
     64        fExpr->get_args().push_back( dstParam );
    6665
    67                 Statement * listInit = srcParam.buildListInit( fExpr );
     66        Statement * listInit = srcParam.buildListInit( fExpr );
    6867
    69                 std::list< Expression * > args = *++srcParam;
    70                 fExpr->get_args().splice( fExpr->get_args().end(), args );
     68        std::list< Expression * > args = *++srcParam;
     69        fExpr->get_args().splice( fExpr->get_args().end(), args );
    7170
    72                 *out++ = new ExprStmt( noLabels, fExpr );
     71        *out++ = new ExprStmt( noLabels, fExpr );
    7372
    74                 srcParam.clearArrayIndices();
     73        srcParam.clearArrayIndices();
    7574
    76                 return listInit;
     75        return listInit;
    7776        }
    7877
     
    8887                Expression * begin, * end, * update, * cmp;
    8988                if ( forward ) {
    90                         // generate: for ( int i = 0; i < 0; ++i )
    91                         begin = new ConstantExpr( Constant( new ZeroType( emptyQualifiers ), "0" ) );
     89                        // generate: for ( int i = 0; i < N; ++i )
     90                        begin = new ConstantExpr( Constant::from_int( 0 ) );
    9291                        end = array->get_dimension()->clone();
    9392                        cmp = new NameExpr( "?<?" );
     
    9796                        begin = new UntypedExpr( new NameExpr( "?-?" ) );
    9897                        ((UntypedExpr*)begin)->get_args().push_back( array->get_dimension()->clone() );
    99                         ((UntypedExpr*)begin)->get_args().push_back( new ConstantExpr( Constant( new OneType( emptyQualifiers ), "1" ) ) );
    100                         end = new ConstantExpr( Constant( new ZeroType( emptyQualifiers ), "0" ) );
     98                        ((UntypedExpr*)begin)->get_args().push_back( new ConstantExpr( Constant::from_int( 1 ) ) );
     99                        end = new ConstantExpr( Constant::from_int( 0 ) );
    101100                        cmp = new NameExpr( "?>=?" );
    102101                        update = new NameExpr( "--?" );
  • src/SymTab/ImplementationType.cc

    re4d829b r579263a  
    7676        }
    7777
    78         void ImplementationType::visit(FunctionType *functionType) {
    79 ///   FunctionType *newType = functionType->clone();
    80 ///   for ( std::list< DeclarationWithType* >::iterator i = newType->get_parameters().begin(); i != newType->get_parameters().end(); ++i ) {
    81 ///     i->set_type( implementationType( i->get_type(), indexer ) );
    82 ///   }
    83 ///   for ( std::list< DeclarationWithType* >::iterator i = newType->get_parameters().begin(); i != newType->get_parameters().end(); ++i ) {
    84 ///     i->set_type( implementationType( i->get_type(), indexer ) );
    85 ///   }
    86         }
    87 
     78        void ImplementationType::visit( __attribute__((unused)) FunctionType *functionType ) {}
    8879        void ImplementationType::visit( __attribute__((unused)) StructInstType * aggregateUseType ) {}
    8980        void ImplementationType::visit( __attribute__((unused)) UnionInstType * aggregateUseType ) {}
  • src/SymTab/Indexer.cc

    re4d829b r579263a  
    495495        }
    496496
    497         void Indexer::visit( UntypedValofExpr *valofExpr ) {
    498                 acceptNewScope( valofExpr->get_result(), *this );
    499                 maybeAccept( valofExpr->get_body(), *this );
    500         }
    501 
    502497        void Indexer::visit( RangeExpr *rangeExpr ) {
    503498                maybeAccept( rangeExpr->get_low(), *this );
     
    518513                acceptNewScope( tupleExpr->get_result(), *this );
    519514                maybeAccept( tupleExpr->get_tuple(), *this );
    520         }
    521 
    522         void Indexer::visit( MemberTupleExpr *tupleExpr ) {
    523                 acceptNewScope( tupleExpr->get_result(), *this );
    524                 maybeAccept( tupleExpr->get_member(), *this );
    525                 maybeAccept( tupleExpr->get_aggregate(), *this );
    526515        }
    527516
  • src/SymTab/Indexer.h

    re4d829b r579263a  
    6969                virtual void visit( ConstructorExpr * ctorExpr );
    7070                virtual void visit( CompoundLiteralExpr *compLitExpr );
    71                 virtual void visit( UntypedValofExpr *valofExpr );
    7271                virtual void visit( RangeExpr *rangeExpr );
    7372                virtual void visit( UntypedTupleExpr *tupleExpr );
    7473                virtual void visit( TupleExpr *tupleExpr );
    7574                virtual void visit( TupleIndexExpr *tupleExpr );
    76                 virtual void visit( MemberTupleExpr *tupleExpr );
    7775                virtual void visit( TupleAssignExpr *tupleExpr );
    7876                virtual void visit( StmtExpr * stmtExpr );
  • src/SymTab/Mangler.cc

    re4d829b r579263a  
    236236        }
    237237
    238         void Mangler::visit( ZeroType *zeroType ) {
     238        void Mangler::visit( __attribute__((unused)) ZeroType *zeroType ) {
    239239                mangleName << "Z";
    240240        }
    241241
    242         void Mangler::visit( OneType *oneType ) {
     242        void Mangler::visit( __attribute__((unused)) OneType *oneType ) {
    243243                mangleName << "O";
    244244        }
  • src/SymTab/Validate.cc

    re4d829b r579263a  
    106106
    107107        /// Fix return types so that every function returns exactly one value
    108         class ReturnTypeFixer {
    109           public:
     108        struct ReturnTypeFixer {
    110109                static void fix( std::list< Declaration * > &translationUnit );
    111110
     
    115114
    116115        /// Replaces enum types by int, and function or array types in function parameter and return lists by appropriate pointers.
    117         class EnumAndPointerDecayPass final : public Visitor {
    118                 typedef Visitor Parent;
    119                 virtual void visit( EnumDecl *aggregateDecl );
    120                 virtual void visit( FunctionType *func );
     116        struct EnumAndPointerDecay {
     117                void previsit( EnumDecl *aggregateDecl );
     118                void previsit( FunctionType *func );
    121119        };
    122120
     
    126124          public:
    127125                LinkReferenceToTypes( bool doDebug, const Indexer *indexer );
    128           private:
    129126                using Parent::visit;
    130127                void visit( EnumInstType *enumInst ) final;
     
    136133                void visit( UnionDecl *unionDecl ) final;
    137134                void visit( TypeInstType *typeInst ) final;
    138 
     135          private:
    139136                const Indexer *indexer;
    140137
     
    147144        };
    148145
    149         /// Replaces array and function types in forall lists by appropriate pointer type
    150         class Pass3 final : public Indexer {
     146        /// Replaces array and function types in forall lists by appropriate pointer type and assigns each Object and Function declaration a unique ID.
     147        class ForallPointerDecay final : public Indexer {
    151148                typedef Indexer Parent;
    152149          public:
    153150                using Parent::visit;
    154                 Pass3( const Indexer *indexer );
    155           private:
     151                ForallPointerDecay( const Indexer *indexer );
     152
    156153                virtual void visit( ObjectDecl *object ) override;
    157154                virtual void visit( FunctionDecl *func ) override;
     
    160157        };
    161158
    162         class ReturnChecker {
    163           public:
     159        struct ReturnChecker : public WithGuards {
    164160                /// Checks that return statements return nothing if their return type is void
    165161                /// and return something if the return type is non-void.
    166162                static void checkFunctionReturns( std::list< Declaration * > & translationUnit );
    167           private:
     163
    168164                void previsit( FunctionDecl * functionDecl );
    169                 void postvisit( FunctionDecl * functionDecl );
    170165                void previsit( ReturnStmt * returnStmt );
    171166
    172167                typedef std::list< DeclarationWithType * > ReturnVals;
    173168                ReturnVals returnVals;
    174                 std::stack< ReturnVals > returnValsStack;
    175169        };
    176170
     
    208202        };
    209203
    210         class VerifyCtorDtorAssign {
    211         public:
     204        struct VerifyCtorDtorAssign {
    212205                /// ensure that constructors, destructors, and assignment have at least one
    213206                /// parameter, the first of which must be a pointer, and that ctor/dtors have no
     
    219212
    220213        /// ensure that generic types have the correct number of type arguments
    221         class ValidateGenericParameters {
    222         public:
     214        struct ValidateGenericParameters {
    223215                void previsit( StructInstType * inst );
    224216                void previsit( UnionInstType * inst );
    225217        };
    226218
    227         class ArrayLength {
    228         public:
     219        struct ArrayLength {
    229220                /// for array types without an explicit length, compute the length and store it so that it
    230221                /// is known to the rest of the phases. For example,
     
    239230        };
    240231
    241         class CompoundLiteral final : public GenPoly::DeclMutator {
     232        struct CompoundLiteral final : public WithDeclsToAdd, public WithVisitorRef<CompoundLiteral> {
    242233                Type::StorageClasses storageClasses;
    243234
    244                 using GenPoly::DeclMutator::mutate;
    245                 DeclarationWithType * mutate( ObjectDecl *objectDecl ) final;
    246                 Expression *mutate( CompoundLiteralExpr *compLitExpr ) final;
     235                void premutate( ObjectDecl *objectDecl );
     236                Expression * postmutate( CompoundLiteralExpr *compLitExpr );
    247237        };
    248238
    249239        void validate( std::list< Declaration * > &translationUnit, bool doDebug ) {
    250                 EnumAndPointerDecayPass epc;
     240                PassVisitor<EnumAndPointerDecay> epc;
    251241                LinkReferenceToTypes lrt( doDebug, 0 );
    252                 Pass3 pass3( 0 );
    253                 CompoundLiteral compoundliteral;
     242                ForallPointerDecay fpd( 0 );
     243                PassVisitor<CompoundLiteral> compoundliteral;
    254244                PassVisitor<ValidateGenericParameters> genericParams;
    255245
     
    262252                VerifyCtorDtorAssign::verify( translationUnit );  // must happen before autogen, because autogen examines existing ctor/dtors
    263253                Concurrency::applyKeywords( translationUnit );
    264                 autogenerateRoutines( translationUnit ); // moved up, used to be below compoundLiteral - currently needs EnumAndPointerDecayPass
     254                autogenerateRoutines( translationUnit ); // moved up, used to be below compoundLiteral - currently needs EnumAndPointerDecay
    265255                Concurrency::implementMutexFuncs( translationUnit );
    266256                Concurrency::implementThreadStarter( translationUnit );
    267257                ReturnChecker::checkFunctionReturns( translationUnit );
    268                 compoundliteral.mutateDeclarationList( translationUnit );
    269                 acceptAll( translationUnit, pass3 );
     258                mutateAll( translationUnit, compoundliteral );
     259                acceptAll( translationUnit, fpd );
    270260                ArrayLength::computeLength( translationUnit );
    271261        }
    272262
    273263        void validateType( Type *type, const Indexer *indexer ) {
    274                 EnumAndPointerDecayPass epc;
     264                PassVisitor<EnumAndPointerDecay> epc;
    275265                LinkReferenceToTypes lrt( false, indexer );
    276                 Pass3 pass3( indexer );
     266                ForallPointerDecay fpd( indexer );
    277267                type->accept( epc );
    278268                type->accept( lrt );
    279                 type->accept( pass3 );
     269                type->accept( fpd );
    280270        }
    281271
     
    356346        }
    357347
    358         void EnumAndPointerDecayPass::visit( EnumDecl *enumDecl ) {
     348        void EnumAndPointerDecay::previsit( EnumDecl *enumDecl ) {
    359349                // Set the type of each member of the enumeration to be EnumConstant
    360350                for ( std::list< Declaration * >::iterator i = enumDecl->get_members().begin(); i != enumDecl->get_members().end(); ++i ) {
     
    363353                        obj->set_type( new EnumInstType( Type::Qualifiers( Type::Const ), enumDecl->get_name() ) );
    364354                } // for
    365                 Parent::visit( enumDecl );
    366355        }
    367356
     
    370359                void fixFunctionList( DWTList & dwts, FunctionType * func ) {
    371360                        // the only case in which "void" is valid is where it is the only one in the list; then it should be removed
    372                         // entirely other fix ups are handled by the FixFunction class
     361                        // entirely. other fix ups are handled by the FixFunction class
    373362                        typedef typename DWTList::iterator DWTIterator;
    374363                        DWTIterator begin( dwts.begin() ), end( dwts.end() );
     
    389378                                for ( ; i != end; ++i ) {
    390379                                        FixFunction fixer;
    391                                         *i = (*i )->acceptMutator( fixer );
     380                                        *i = (*i)->acceptMutator( fixer );
    392381                                        if ( fixer.get_isVoid() ) {
    393382                                                throw SemanticError( "invalid type void in function type ", func );
     
    398387        }
    399388
    400         void EnumAndPointerDecayPass::visit( FunctionType *func ) {
     389        void EnumAndPointerDecay::previsit( FunctionType *func ) {
    401390                // Fix up parameters and return types
    402391                fixFunctionList( func->get_parameters(), func );
    403392                fixFunctionList( func->get_returnVals(), func );
    404                 Visitor::visit( func );
    405393        }
    406394
     
    549537        }
    550538
    551         Pass3::Pass3( const Indexer *other_indexer ) :  Indexer( false ) {
     539        ForallPointerDecay::ForallPointerDecay( const Indexer *other_indexer ) :  Indexer( false ) {
    552540                if ( other_indexer ) {
    553541                        indexer = other_indexer;
     
    587575        }
    588576
    589         void Pass3::visit( ObjectDecl *object ) {
     577        void ForallPointerDecay::visit( ObjectDecl *object ) {
    590578                forallFixer( object->get_type() );
    591579                if ( PointerType *pointer = dynamic_cast< PointerType * >( object->get_type() ) ) {
     
    596584        }
    597585
    598         void Pass3::visit( FunctionDecl *func ) {
     586        void ForallPointerDecay::visit( FunctionDecl *func ) {
    599587                forallFixer( func->get_type() );
    600588                Parent::visit( func );
     
    608596
    609597        void ReturnChecker::previsit( FunctionDecl * functionDecl ) {
    610                 returnValsStack.push( returnVals );
     598                GuardValue( returnVals );
    611599                returnVals = functionDecl->get_functionType()->get_returnVals();
    612         }
    613         void ReturnChecker::postvisit( FunctionDecl * functionDecl ) {
    614                 returnVals = returnValsStack.top();
    615                 returnValsStack.pop();
    616600        }
    617601
     
    892876        }
    893877
    894         DeclarationWithType * CompoundLiteral::mutate( ObjectDecl *objectDecl ) {
     878        void CompoundLiteral::premutate( ObjectDecl *objectDecl ) {
    895879                storageClasses = objectDecl->get_storageClasses();
    896                 DeclarationWithType * temp = Mutator::mutate( objectDecl );
    897                 return temp;
    898         }
    899 
    900         Expression *CompoundLiteral::mutate( CompoundLiteralExpr *compLitExpr ) {
     880        }
     881
     882        Expression *CompoundLiteral::postmutate( CompoundLiteralExpr *compLitExpr ) {
    901883                // transform [storage_class] ... (struct S){ 3, ... };
    902884                // into [storage_class] struct S temp =  { 3, ... };
    903885                static UniqueName indexName( "_compLit" );
    904886
    905                 ObjectDecl *tempvar = new ObjectDecl( indexName.newName(), storageClasses, LinkageSpec::C, 0, compLitExpr->get_result(), compLitExpr->get_initializer() );
    906                 compLitExpr->set_result( 0 );
    907                 compLitExpr->set_initializer( 0 );
     887                ObjectDecl *tempvar = new ObjectDecl( indexName.newName(), storageClasses, LinkageSpec::C, nullptr, compLitExpr->get_result(), compLitExpr->get_initializer() );
     888                compLitExpr->set_result( nullptr );
     889                compLitExpr->set_initializer( nullptr );
    908890                delete compLitExpr;
    909                 DeclarationWithType * newtempvar = mutate( tempvar );
    910                 addDeclaration( newtempvar );                                   // add modified temporary to current block
    911                 return new VariableExpr( newtempvar );
     891                declsToAddBefore.push_back( tempvar );                                  // add modified temporary to current block
     892                return new VariableExpr( tempvar );
    912893        }
    913894
Note: See TracChangeset for help on using the changeset viewer.