Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/SymTab/Validate.cc

    rd24d4e1 r06edda0  
    106106
    107107        /// Fix return types so that every function returns exactly one value
    108         struct ReturnTypeFixer {
     108        class ReturnTypeFixer {
     109          public:
    109110                static void fix( std::list< Declaration * > &translationUnit );
    110111
     
    114115
    115116        /// Replaces enum types by int, and function or array types in function parameter and return lists by appropriate pointers.
    116         struct EnumAndPointerDecay {
     117        class EnumAndPointerDecay {
     118        public:
    117119                void previsit( EnumDecl *aggregateDecl );
    118120                void previsit( FunctionType *func );
     
    157159        };
    158160
    159         struct ReturnChecker : public WithGuards {
     161        class ReturnChecker : public WithScopes {
     162          public:
    160163                /// Checks that return statements return nothing if their return type is void
    161164                /// and return something if the return type is non-void.
    162165                static void checkFunctionReturns( std::list< Declaration * > & translationUnit );
    163 
     166          private:
    164167                void previsit( FunctionDecl * functionDecl );
    165168                void previsit( ReturnStmt * returnStmt );
     
    202205        };
    203206
    204         struct VerifyCtorDtorAssign {
     207        class VerifyCtorDtorAssign {
     208        public:
    205209                /// ensure that constructors, destructors, and assignment have at least one
    206210                /// parameter, the first of which must be a pointer, and that ctor/dtors have no
     
    212216
    213217        /// ensure that generic types have the correct number of type arguments
    214         struct ValidateGenericParameters {
     218        class ValidateGenericParameters {
     219        public:
    215220                void previsit( StructInstType * inst );
    216221                void previsit( UnionInstType * inst );
    217222        };
    218223
    219         struct ArrayLength {
     224        class ArrayLength {
     225        public:
    220226                /// for array types without an explicit length, compute the length and store it so that it
    221227                /// is known to the rest of the phases. For example,
     
    230236        };
    231237
    232         struct CompoundLiteral final : public WithDeclsToAdd, public WithVisitorRef<CompoundLiteral> {
     238        class CompoundLiteral final : public GenPoly::DeclMutator {
    233239                Type::StorageClasses storageClasses;
    234240
    235                 void premutate( ObjectDecl *objectDecl );
    236                 Expression * postmutate( CompoundLiteralExpr *compLitExpr );
     241                using GenPoly::DeclMutator::mutate;
     242                DeclarationWithType * mutate( ObjectDecl *objectDecl ) final;
     243                Expression *mutate( CompoundLiteralExpr *compLitExpr ) final;
    237244        };
    238245
     
    241248                LinkReferenceToTypes lrt( doDebug, 0 );
    242249                ForallPointerDecay fpd( 0 );
    243                 PassVisitor<CompoundLiteral> compoundliteral;
     250                CompoundLiteral compoundliteral;
    244251                PassVisitor<ValidateGenericParameters> genericParams;
    245252
     
    256263                Concurrency::implementThreadStarter( translationUnit );
    257264                ReturnChecker::checkFunctionReturns( translationUnit );
    258                 mutateAll( translationUnit, compoundliteral );
     265                compoundliteral.mutateDeclarationList( translationUnit );
    259266                acceptAll( translationUnit, fpd );
    260267                ArrayLength::computeLength( translationUnit );
     
    876883        }
    877884
    878         void CompoundLiteral::premutate( ObjectDecl *objectDecl ) {
     885        DeclarationWithType * CompoundLiteral::mutate( ObjectDecl *objectDecl ) {
    879886                storageClasses = objectDecl->get_storageClasses();
    880         }
    881 
    882         Expression *CompoundLiteral::postmutate( CompoundLiteralExpr *compLitExpr ) {
     887                DeclarationWithType * temp = Mutator::mutate( objectDecl );
     888                return temp;
     889        }
     890
     891        Expression *CompoundLiteral::mutate( CompoundLiteralExpr *compLitExpr ) {
    883892                // transform [storage_class] ... (struct S){ 3, ... };
    884893                // into [storage_class] struct S temp =  { 3, ... };
    885894                static UniqueName indexName( "_compLit" );
    886895
    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 );
     896                ObjectDecl *tempvar = new ObjectDecl( indexName.newName(), storageClasses, LinkageSpec::C, 0, compLitExpr->get_result(), compLitExpr->get_initializer() );
     897                compLitExpr->set_result( 0 );
     898                compLitExpr->set_initializer( 0 );
    890899                delete compLitExpr;
    891                 declsToAddBefore.push_back( tempvar );                                  // add modified temporary to current block
    892                 return new VariableExpr( tempvar );
     900                DeclarationWithType * newtempvar = mutate( tempvar );
     901                addDeclaration( newtempvar );                                   // add modified temporary to current block
     902                return new VariableExpr( newtempvar );
    893903        }
    894904
Note: See TracChangeset for help on using the changeset viewer.