Changeset 06edda0


Ignore:
Timestamp:
Jun 21, 2017, 1:40:54 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:
e9a3b20b
Parents:
af5c204a
Message:

convert EnumAndPointerDecayPass? and ForallPointerDecay? to PassVisitor?

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/SymTab/Validate.cc

    raf5c204a r06edda0  
    115115
    116116        /// 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 );
     117        class EnumAndPointerDecay {
     118        public:
     119                void previsit( EnumDecl *aggregateDecl );
     120                void previsit( FunctionType *func );
    121121        };
    122122
     
    126126          public:
    127127                LinkReferenceToTypes( bool doDebug, const Indexer *indexer );
    128           private:
    129128                using Parent::visit;
    130129                void visit( EnumInstType *enumInst ) final;
     
    136135                void visit( UnionDecl *unionDecl ) final;
    137136                void visit( TypeInstType *typeInst ) final;
    138 
     137          private:
    139138                const Indexer *indexer;
    140139
     
    147146        };
    148147
    149         /// Replaces array and function types in forall lists by appropriate pointer type
    150         class Pass3 final : public Indexer {
     148        /// Replaces array and function types in forall lists by appropriate pointer type and assigns each Object and Function declaration a unique ID.
     149        class ForallPointerDecay final : public Indexer {
    151150                typedef Indexer Parent;
    152151          public:
    153152                using Parent::visit;
    154                 Pass3( const Indexer *indexer );
    155           private:
     153                ForallPointerDecay( const Indexer *indexer );
     154
    156155                virtual void visit( ObjectDecl *object ) override;
    157156                virtual void visit( FunctionDecl *func ) override;
     
    246245
    247246        void validate( std::list< Declaration * > &translationUnit, bool doDebug ) {
    248                 EnumAndPointerDecayPass epc;
     247                PassVisitor<EnumAndPointerDecay> epc;
    249248                LinkReferenceToTypes lrt( doDebug, 0 );
    250                 Pass3 pass3( 0 );
     249                ForallPointerDecay fpd( 0 );
    251250                CompoundLiteral compoundliteral;
    252251                PassVisitor<ValidateGenericParameters> genericParams;
     
    260259                VerifyCtorDtorAssign::verify( translationUnit );  // must happen before autogen, because autogen examines existing ctor/dtors
    261260                Concurrency::applyKeywords( translationUnit );
    262                 autogenerateRoutines( translationUnit ); // moved up, used to be below compoundLiteral - currently needs EnumAndPointerDecayPass
     261                autogenerateRoutines( translationUnit ); // moved up, used to be below compoundLiteral - currently needs EnumAndPointerDecay
    263262                Concurrency::implementMutexFuncs( translationUnit );
    264263                Concurrency::implementThreadStarter( translationUnit );
    265264                ReturnChecker::checkFunctionReturns( translationUnit );
    266265                compoundliteral.mutateDeclarationList( translationUnit );
    267                 acceptAll( translationUnit, pass3 );
     266                acceptAll( translationUnit, fpd );
    268267                ArrayLength::computeLength( translationUnit );
    269268        }
    270269
    271270        void validateType( Type *type, const Indexer *indexer ) {
    272                 EnumAndPointerDecayPass epc;
     271                PassVisitor<EnumAndPointerDecay> epc;
    273272                LinkReferenceToTypes lrt( false, indexer );
    274                 Pass3 pass3( indexer );
     273                ForallPointerDecay fpd( indexer );
    275274                type->accept( epc );
    276275                type->accept( lrt );
    277                 type->accept( pass3 );
     276                type->accept( fpd );
    278277        }
    279278
     
    354353        }
    355354
    356         void EnumAndPointerDecayPass::visit( EnumDecl *enumDecl ) {
     355        void EnumAndPointerDecay::previsit( EnumDecl *enumDecl ) {
    357356                // Set the type of each member of the enumeration to be EnumConstant
    358357                for ( std::list< Declaration * >::iterator i = enumDecl->get_members().begin(); i != enumDecl->get_members().end(); ++i ) {
     
    361360                        obj->set_type( new EnumInstType( Type::Qualifiers( Type::Const ), enumDecl->get_name() ) );
    362361                } // for
    363                 Parent::visit( enumDecl );
    364362        }
    365363
     
    368366                void fixFunctionList( DWTList & dwts, FunctionType * func ) {
    369367                        // the only case in which "void" is valid is where it is the only one in the list; then it should be removed
    370                         // entirely other fix ups are handled by the FixFunction class
     368                        // entirely. other fix ups are handled by the FixFunction class
    371369                        typedef typename DWTList::iterator DWTIterator;
    372370                        DWTIterator begin( dwts.begin() ), end( dwts.end() );
     
    387385                                for ( ; i != end; ++i ) {
    388386                                        FixFunction fixer;
    389                                         *i = (*i )->acceptMutator( fixer );
     387                                        *i = (*i)->acceptMutator( fixer );
    390388                                        if ( fixer.get_isVoid() ) {
    391389                                                throw SemanticError( "invalid type void in function type ", func );
     
    396394        }
    397395
    398         void EnumAndPointerDecayPass::visit( FunctionType *func ) {
     396        void EnumAndPointerDecay::previsit( FunctionType *func ) {
    399397                // Fix up parameters and return types
    400398                fixFunctionList( func->get_parameters(), func );
    401399                fixFunctionList( func->get_returnVals(), func );
    402                 Visitor::visit( func );
    403400        }
    404401
     
    547544        }
    548545
    549         Pass3::Pass3( const Indexer *other_indexer ) :  Indexer( false ) {
     546        ForallPointerDecay::ForallPointerDecay( const Indexer *other_indexer ) :  Indexer( false ) {
    550547                if ( other_indexer ) {
    551548                        indexer = other_indexer;
     
    585582        }
    586583
    587         void Pass3::visit( ObjectDecl *object ) {
     584        void ForallPointerDecay::visit( ObjectDecl *object ) {
    588585                forallFixer( object->get_type() );
    589586                if ( PointerType *pointer = dynamic_cast< PointerType * >( object->get_type() ) ) {
     
    594591        }
    595592
    596         void Pass3::visit( FunctionDecl *func ) {
     593        void ForallPointerDecay::visit( FunctionDecl *func ) {
    597594                forallFixer( func->get_type() );
    598595                Parent::visit( func );
Note: See TracChangeset for help on using the changeset viewer.