Ignore:
Timestamp:
Jun 26, 2017, 4:48:35 PM (7 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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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.