Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/SymTab/Validate.cc

    r06edda0 rc6d2e93  
    115115
    116116        /// Replaces enum types by int, and function or array types in function parameter and return lists by appropriate pointers.
    117         class EnumAndPointerDecay {
    118         public:
    119                 void previsit( EnumDecl *aggregateDecl );
    120                 void previsit( FunctionType *func );
     117        class EnumAndPointerDecayPass final : public Visitor {
     118                typedef Visitor Parent;
     119                virtual void visit( EnumDecl *aggregateDecl );
     120                virtual void visit( FunctionType *func );
    121121        };
    122122
     
    126126          public:
    127127                LinkReferenceToTypes( bool doDebug, const Indexer *indexer );
     128          private:
    128129                using Parent::visit;
    129130                void visit( EnumInstType *enumInst ) final;
     
    135136                void visit( UnionDecl *unionDecl ) final;
    136137                void visit( TypeInstType *typeInst ) final;
    137           private:
     138
    138139                const Indexer *indexer;
    139140
     
    146147        };
    147148
    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 {
     149        /// Replaces array and function types in forall lists by appropriate pointer type
     150        class Pass3 final : public Indexer {
    150151                typedef Indexer Parent;
    151152          public:
    152153                using Parent::visit;
    153                 ForallPointerDecay( const Indexer *indexer );
    154 
     154                Pass3( const Indexer *indexer );
     155          private:
    155156                virtual void visit( ObjectDecl *object ) override;
    156157                virtual void visit( FunctionDecl *func ) override;
     
    159160        };
    160161
    161         class ReturnChecker : public WithScopes {
     162        class ReturnChecker {
    162163          public:
    163164                /// Checks that return statements return nothing if their return type is void
     
    166167          private:
    167168                void previsit( FunctionDecl * functionDecl );
     169                void postvisit( FunctionDecl * functionDecl );
    168170                void previsit( ReturnStmt * returnStmt );
    169171
    170172                typedef std::list< DeclarationWithType * > ReturnVals;
    171173                ReturnVals returnVals;
     174                std::stack< ReturnVals > returnValsStack;
    172175        };
    173176
     
    245248
    246249        void validate( std::list< Declaration * > &translationUnit, bool doDebug ) {
    247                 PassVisitor<EnumAndPointerDecay> epc;
     250                EnumAndPointerDecayPass epc;
    248251                LinkReferenceToTypes lrt( doDebug, 0 );
    249                 ForallPointerDecay fpd( 0 );
     252                Pass3 pass3( 0 );
    250253                CompoundLiteral compoundliteral;
    251254                PassVisitor<ValidateGenericParameters> genericParams;
     
    259262                VerifyCtorDtorAssign::verify( translationUnit );  // must happen before autogen, because autogen examines existing ctor/dtors
    260263                Concurrency::applyKeywords( translationUnit );
    261                 autogenerateRoutines( translationUnit ); // moved up, used to be below compoundLiteral - currently needs EnumAndPointerDecay
     264                autogenerateRoutines( translationUnit ); // moved up, used to be below compoundLiteral - currently needs EnumAndPointerDecayPass
    262265                Concurrency::implementMutexFuncs( translationUnit );
    263266                Concurrency::implementThreadStarter( translationUnit );
    264267                ReturnChecker::checkFunctionReturns( translationUnit );
    265268                compoundliteral.mutateDeclarationList( translationUnit );
    266                 acceptAll( translationUnit, fpd );
     269                acceptAll( translationUnit, pass3 );
    267270                ArrayLength::computeLength( translationUnit );
    268271        }
    269272
    270273        void validateType( Type *type, const Indexer *indexer ) {
    271                 PassVisitor<EnumAndPointerDecay> epc;
     274                EnumAndPointerDecayPass epc;
    272275                LinkReferenceToTypes lrt( false, indexer );
    273                 ForallPointerDecay fpd( indexer );
     276                Pass3 pass3( indexer );
    274277                type->accept( epc );
    275278                type->accept( lrt );
    276                 type->accept( fpd );
     279                type->accept( pass3 );
    277280        }
    278281
     
    353356        }
    354357
    355         void EnumAndPointerDecay::previsit( EnumDecl *enumDecl ) {
     358        void EnumAndPointerDecayPass::visit( EnumDecl *enumDecl ) {
    356359                // Set the type of each member of the enumeration to be EnumConstant
    357360                for ( std::list< Declaration * >::iterator i = enumDecl->get_members().begin(); i != enumDecl->get_members().end(); ++i ) {
     
    360363                        obj->set_type( new EnumInstType( Type::Qualifiers( Type::Const ), enumDecl->get_name() ) );
    361364                } // for
     365                Parent::visit( enumDecl );
    362366        }
    363367
     
    366370                void fixFunctionList( DWTList & dwts, FunctionType * func ) {
    367371                        // the only case in which "void" is valid is where it is the only one in the list; then it should be removed
    368                         // entirely. other fix ups are handled by the FixFunction class
     372                        // entirely other fix ups are handled by the FixFunction class
    369373                        typedef typename DWTList::iterator DWTIterator;
    370374                        DWTIterator begin( dwts.begin() ), end( dwts.end() );
     
    385389                                for ( ; i != end; ++i ) {
    386390                                        FixFunction fixer;
    387                                         *i = (*i)->acceptMutator( fixer );
     391                                        *i = (*i )->acceptMutator( fixer );
    388392                                        if ( fixer.get_isVoid() ) {
    389393                                                throw SemanticError( "invalid type void in function type ", func );
     
    394398        }
    395399
    396         void EnumAndPointerDecay::previsit( FunctionType *func ) {
     400        void EnumAndPointerDecayPass::visit( FunctionType *func ) {
    397401                // Fix up parameters and return types
    398402                fixFunctionList( func->get_parameters(), func );
    399403                fixFunctionList( func->get_returnVals(), func );
     404                Visitor::visit( func );
    400405        }
    401406
     
    544549        }
    545550
    546         ForallPointerDecay::ForallPointerDecay( const Indexer *other_indexer ) :  Indexer( false ) {
     551        Pass3::Pass3( const Indexer *other_indexer ) :  Indexer( false ) {
    547552                if ( other_indexer ) {
    548553                        indexer = other_indexer;
     
    582587        }
    583588
    584         void ForallPointerDecay::visit( ObjectDecl *object ) {
     589        void Pass3::visit( ObjectDecl *object ) {
    585590                forallFixer( object->get_type() );
    586591                if ( PointerType *pointer = dynamic_cast< PointerType * >( object->get_type() ) ) {
     
    591596        }
    592597
    593         void ForallPointerDecay::visit( FunctionDecl *func ) {
     598        void Pass3::visit( FunctionDecl *func ) {
    594599                forallFixer( func->get_type() );
    595600                Parent::visit( func );
     
    603608
    604609        void ReturnChecker::previsit( FunctionDecl * functionDecl ) {
    605                 GuardValue( returnVals );
     610                returnValsStack.push( returnVals );
    606611                returnVals = functionDecl->get_functionType()->get_returnVals();
     612        }
     613        void ReturnChecker::postvisit( FunctionDecl * functionDecl ) {
     614                returnVals = returnValsStack.top();
     615                returnValsStack.pop();
    607616        }
    608617
Note: See TracChangeset for help on using the changeset viewer.