Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/SymTab/Validate.cc

    r06edda0 raf397ef8  
    6666#include "ResolvExpr/typeops.h"
    6767
    68 #include "SynTree/Attribute.h"
    6968#include "SynTree/Expression.h"
    7069#include "SynTree/Mutator.h"
     
    115114
    116115        /// 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 );
     116        class EnumAndPointerDecayPass final : public Visitor {
     117                typedef Visitor Parent;
     118                virtual void visit( EnumDecl *aggregateDecl );
     119                virtual void visit( FunctionType *func );
    121120        };
    122121
     
    126125          public:
    127126                LinkReferenceToTypes( bool doDebug, const Indexer *indexer );
     127          private:
    128128                using Parent::visit;
    129129                void visit( EnumInstType *enumInst ) final;
     
    135135                void visit( UnionDecl *unionDecl ) final;
    136136                void visit( TypeInstType *typeInst ) final;
    137           private:
     137
    138138                const Indexer *indexer;
    139139
     
    146146        };
    147147
    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 {
     148        /// Replaces array and function types in forall lists by appropriate pointer type
     149        class Pass3 final : public Indexer {
    150150                typedef Indexer Parent;
    151151          public:
    152152                using Parent::visit;
    153                 ForallPointerDecay( const Indexer *indexer );
    154 
     153                Pass3( const Indexer *indexer );
     154          private:
    155155                virtual void visit( ObjectDecl *object ) override;
    156156                virtual void visit( FunctionDecl *func ) override;
     
    159159        };
    160160
    161         class ReturnChecker : public WithScopes {
     161        class ReturnChecker {
    162162          public:
    163163                /// Checks that return statements return nothing if their return type is void
     
    166166          private:
    167167                void previsit( FunctionDecl * functionDecl );
     168                void postvisit( FunctionDecl * functionDecl );
    168169                void previsit( ReturnStmt * returnStmt );
    169170
    170171                typedef std::list< DeclarationWithType * > ReturnVals;
    171172                ReturnVals returnVals;
     173                std::stack< ReturnVals > returnValsStack;
    172174        };
    173175
     
    245247
    246248        void validate( std::list< Declaration * > &translationUnit, bool doDebug ) {
    247                 PassVisitor<EnumAndPointerDecay> epc;
     249                EnumAndPointerDecayPass epc;
    248250                LinkReferenceToTypes lrt( doDebug, 0 );
    249                 ForallPointerDecay fpd( 0 );
     251                Pass3 pass3( 0 );
    250252                CompoundLiteral compoundliteral;
    251253                PassVisitor<ValidateGenericParameters> genericParams;
     
    259261                VerifyCtorDtorAssign::verify( translationUnit );  // must happen before autogen, because autogen examines existing ctor/dtors
    260262                Concurrency::applyKeywords( translationUnit );
    261                 autogenerateRoutines( translationUnit ); // moved up, used to be below compoundLiteral - currently needs EnumAndPointerDecay
     263                autogenerateRoutines( translationUnit ); // moved up, used to be below compoundLiteral - currently needs EnumAndPointerDecayPass
    262264                Concurrency::implementMutexFuncs( translationUnit );
    263265                Concurrency::implementThreadStarter( translationUnit );
    264266                ReturnChecker::checkFunctionReturns( translationUnit );
    265267                compoundliteral.mutateDeclarationList( translationUnit );
    266                 acceptAll( translationUnit, fpd );
     268                acceptAll( translationUnit, pass3 );
    267269                ArrayLength::computeLength( translationUnit );
    268270        }
    269271
    270272        void validateType( Type *type, const Indexer *indexer ) {
    271                 PassVisitor<EnumAndPointerDecay> epc;
     273                EnumAndPointerDecayPass epc;
    272274                LinkReferenceToTypes lrt( false, indexer );
    273                 ForallPointerDecay fpd( indexer );
     275                Pass3 pass3( indexer );
    274276                type->accept( epc );
    275277                type->accept( lrt );
    276                 type->accept( fpd );
     278                type->accept( pass3 );
    277279        }
    278280
     
    353355        }
    354356
    355         void EnumAndPointerDecay::previsit( EnumDecl *enumDecl ) {
     357        void EnumAndPointerDecayPass::visit( EnumDecl *enumDecl ) {
    356358                // Set the type of each member of the enumeration to be EnumConstant
    357359                for ( std::list< Declaration * >::iterator i = enumDecl->get_members().begin(); i != enumDecl->get_members().end(); ++i ) {
     
    360362                        obj->set_type( new EnumInstType( Type::Qualifiers( Type::Const ), enumDecl->get_name() ) );
    361363                } // for
     364                Parent::visit( enumDecl );
    362365        }
    363366
     
    366369                void fixFunctionList( DWTList & dwts, FunctionType * func ) {
    367370                        // 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
     371                        // entirely other fix ups are handled by the FixFunction class
    369372                        typedef typename DWTList::iterator DWTIterator;
    370373                        DWTIterator begin( dwts.begin() ), end( dwts.end() );
     
    385388                                for ( ; i != end; ++i ) {
    386389                                        FixFunction fixer;
    387                                         *i = (*i)->acceptMutator( fixer );
     390                                        *i = (*i )->acceptMutator( fixer );
    388391                                        if ( fixer.get_isVoid() ) {
    389392                                                throw SemanticError( "invalid type void in function type ", func );
     
    394397        }
    395398
    396         void EnumAndPointerDecay::previsit( FunctionType *func ) {
     399        void EnumAndPointerDecayPass::visit( FunctionType *func ) {
    397400                // Fix up parameters and return types
    398401                fixFunctionList( func->get_parameters(), func );
    399402                fixFunctionList( func->get_returnVals(), func );
     403                Visitor::visit( func );
    400404        }
    401405
     
    544548        }
    545549
    546         ForallPointerDecay::ForallPointerDecay( const Indexer *other_indexer ) :  Indexer( false ) {
     550        Pass3::Pass3( const Indexer *other_indexer ) :  Indexer( false ) {
    547551                if ( other_indexer ) {
    548552                        indexer = other_indexer;
     
    582586        }
    583587
    584         void ForallPointerDecay::visit( ObjectDecl *object ) {
     588        void Pass3::visit( ObjectDecl *object ) {
    585589                forallFixer( object->get_type() );
    586590                if ( PointerType *pointer = dynamic_cast< PointerType * >( object->get_type() ) ) {
     
    591595        }
    592596
    593         void ForallPointerDecay::visit( FunctionDecl *func ) {
     597        void Pass3::visit( FunctionDecl *func ) {
    594598                forallFixer( func->get_type() );
    595599                Parent::visit( func );
     
    603607
    604608        void ReturnChecker::previsit( FunctionDecl * functionDecl ) {
    605                 GuardValue( returnVals );
     609                returnValsStack.push( returnVals );
    606610                returnVals = functionDecl->get_functionType()->get_returnVals();
     611        }
     612        void ReturnChecker::postvisit( __attribute__((unused)) FunctionDecl * functionDecl ) {
     613                returnVals = returnValsStack.top();
     614                returnValsStack.pop();
    607615        }
    608616
     
    919927                                ret->set_name( toString( "_retval_", CodeGen::genName( functionDecl ) ) );
    920928                        }
    921                         ret->get_attributes().push_back( new Attribute( "unused" ) );
    922929                }
    923930        }
Note: See TracChangeset for help on using the changeset viewer.