Ignore:
Timestamp:
Jun 2, 2017, 6:30:18 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:
7985fa5
Parents:
f94ca7e
Message:

convert several passes to PassVisitor?

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/SymTab/Validate.cc

    rf94ca7e r0db6fc0  
    3838//   definition occurs later in the input.
    3939
     40#include <algorithm>
     41#include <iterator>
    4042#include <list>
    41 #include <iterator>
     43
     44#include "CodeGen/CodeGenerator.h"
     45
     46#include "Common/PassVisitor.h"
    4247#include "Common/ScopedMap.h"
     48#include "Common/UniqueName.h"
    4349#include "Common/utility.h"
    44 #include "Common/UniqueName.h"
     50
    4551#include "Concurrency/Keywords.h"
    46 #include "Validate.h"
    47 #include "SynTree/Visitor.h"
    48 #include "SynTree/Mutator.h"
    49 #include "SynTree/Type.h"
    50 #include "SynTree/Expression.h"
    51 #include "SynTree/Statement.h"
    52 #include "SynTree/TypeSubstitution.h"
    53 #include "Indexer.h"
     52
     53#include "GenPoly/DeclMutator.h"
     54
     55#include "InitTweak/InitTweak.h"
     56
     57#include "AddVisit.h"
     58#include "Autogen.h"
    5459#include "FixFunction.h"
    5560// #include "ImplementationType.h"
    56 #include "GenPoly/DeclMutator.h"
    57 #include "AddVisit.h"
     61#include "Indexer.h"
    5862#include "MakeLibCfa.h"
    5963#include "TypeEquality.h"
    60 #include "Autogen.h"
     64#include "Validate.h"
     65
    6166#include "ResolvExpr/typeops.h"
    62 #include <algorithm>
    63 #include "InitTweak/InitTweak.h"
    64 #include "CodeGen/CodeGenerator.h"
     67
     68#include "SynTree/Expression.h"
     69#include "SynTree/Mutator.h"
     70#include "SynTree/Statement.h"
     71#include "SynTree/Type.h"
     72#include "SynTree/TypeSubstitution.h"
     73#include "SynTree/Visitor.h"
    6574
    6675#define debugPrint( x ) if ( doDebug ) { std::cout << x; }
     
    96105
    97106        /// Fix return types so that every function returns exactly one value
    98         class ReturnTypeFixer final : public Visitor {
     107        class ReturnTypeFixer {
    99108          public:
    100                 typedef Visitor Parent;
    101                 using Parent::visit;
    102 
    103109                static void fix( std::list< Declaration * > &translationUnit );
    104110
    105                 virtual void visit( FunctionDecl * functionDecl );
    106                 virtual void visit( FunctionType * ftype );
     111                void postvisit( FunctionDecl * functionDecl );
     112                void postvisit( FunctionType * ftype );
    107113        };
    108114
     
    153159        };
    154160
    155         class ReturnChecker : public Visitor {
     161        class ReturnChecker {
    156162          public:
    157163                /// Checks that return statements return nothing if their return type is void
     
    159165                static void checkFunctionReturns( std::list< Declaration * > & translationUnit );
    160166          private:
    161                 virtual void visit( FunctionDecl * functionDecl );
    162                 virtual void visit( ReturnStmt * returnStmt );
    163 
    164                 std::list< DeclarationWithType * > returnVals;
     167                void previsit( FunctionDecl * functionDecl );
     168                void postvisit( FunctionDecl * functionDecl );
     169                void previsit( ReturnStmt * returnStmt );
     170
     171                typedef std::list< DeclarationWithType * > ReturnVals;
     172                ReturnVals returnVals;
     173                std::stack< ReturnVals > returnValsStack;
    165174        };
    166175
     
    198207        };
    199208
    200         class VerifyCtorDtorAssign : public Visitor {
     209        class VerifyCtorDtorAssign {
    201210        public:
    202211                /// ensure that constructors, destructors, and assignment have at least one
     
    205214                static void verify( std::list< Declaration * > &translationUnit );
    206215
    207                 virtual void visit( FunctionDecl *funcDecl );
     216                void previsit( FunctionDecl *funcDecl );
    208217        };
    209218
    210219        /// ensure that generic types have the correct number of type arguments
    211         class ValidateGenericParameters : public Visitor {
     220        class ValidateGenericParameters {
    212221        public:
    213                 typedef Visitor Parent;
    214                 virtual void visit( StructInstType * inst ) final override;
    215                 virtual void visit( UnionInstType * inst ) final override;
    216         };
    217 
    218         class ArrayLength : public Visitor {
     222                void previsit( StructInstType * inst );
     223                void previsit( UnionInstType * inst );
     224        };
     225
     226        class ArrayLength {
    219227        public:
    220228                /// for array types without an explicit length, compute the length and store it so that it
     
    227235                static void computeLength( std::list< Declaration * > & translationUnit );
    228236
    229                 virtual void visit( ObjectDecl * objDecl );
     237                void previsit( ObjectDecl * objDecl );
    230238        };
    231239
     
    243251                Pass3 pass3( 0 );
    244252                CompoundLiteral compoundliteral;
    245                 ValidateGenericParameters genericParams;
     253                PassVisitor<ValidateGenericParameters> genericParams;
    246254
    247255                EliminateTypedef::eliminateTypedef( translationUnit );
     
    594602
    595603        void ReturnChecker::checkFunctionReturns( std::list< Declaration * > & translationUnit ) {
    596                 ReturnChecker checker;
     604                PassVisitor<ReturnChecker> checker;
    597605                acceptAll( translationUnit, checker );
    598606        }
    599607
    600         void ReturnChecker::visit( FunctionDecl * functionDecl ) {
    601                 std::list< DeclarationWithType * > oldReturnVals = returnVals;
     608        void ReturnChecker::previsit( FunctionDecl * functionDecl ) {
     609                returnValsStack.push( returnVals );
    602610                returnVals = functionDecl->get_functionType()->get_returnVals();
    603                 Visitor::visit( functionDecl );
    604                 returnVals = oldReturnVals;
    605         }
    606 
    607         void ReturnChecker::visit( ReturnStmt * returnStmt ) {
     611        }
     612        void ReturnChecker::postvisit( FunctionDecl * functionDecl ) {
     613                returnVals = returnValsStack.top();
     614                returnValsStack.pop();
     615        }
     616
     617        void ReturnChecker::previsit( ReturnStmt * returnStmt ) {
    608618                // Previously this also checked for the existence of an expr paired with no return values on
    609619                // the  function return type. This is incorrect, since you can have an expression attached to
     
    815825
    816826        void VerifyCtorDtorAssign::verify( std::list< Declaration * > & translationUnit ) {
    817                 VerifyCtorDtorAssign verifier;
     827                PassVisitor<VerifyCtorDtorAssign> verifier;
    818828                acceptAll( translationUnit, verifier );
    819829        }
    820830
    821         void VerifyCtorDtorAssign::visit( FunctionDecl * funcDecl ) {
     831        void VerifyCtorDtorAssign::previsit( FunctionDecl * funcDecl ) {
    822832                FunctionType * funcType = funcDecl->get_functionType();
    823833                std::list< DeclarationWithType * > &returnVals = funcType->get_returnVals();
     
    836846                        }
    837847                }
    838 
    839                 Visitor::visit( funcDecl );
    840848        }
    841849
     
    875883        }
    876884
    877         void ValidateGenericParameters::visit( StructInstType * inst ) {
     885        void ValidateGenericParameters::previsit( StructInstType * inst ) {
    878886                validateGeneric( inst );
    879                 Parent::visit( inst );
    880         }
    881 
    882         void ValidateGenericParameters::visit( UnionInstType * inst ) {
     887        }
     888
     889        void ValidateGenericParameters::previsit( UnionInstType * inst ) {
    883890                validateGeneric( inst );
    884                 Parent::visit( inst );
    885891        }
    886892
     
    906912
    907913        void ReturnTypeFixer::fix( std::list< Declaration * > &translationUnit ) {
    908                 ReturnTypeFixer fixer;
     914                PassVisitor<ReturnTypeFixer> fixer;
    909915                acceptAll( translationUnit, fixer );
    910916        }
    911917
    912         void ReturnTypeFixer::visit( FunctionDecl * functionDecl ) {
    913                 Parent::visit( functionDecl );
     918        void ReturnTypeFixer::postvisit( FunctionDecl * functionDecl ) {
    914919                FunctionType * ftype = functionDecl->get_functionType();
    915920                std::list< DeclarationWithType * > & retVals = ftype->get_returnVals();
     
    925930        }
    926931
    927         void ReturnTypeFixer::visit( FunctionType * ftype ) {
     932        void ReturnTypeFixer::postvisit( FunctionType * ftype ) {
    928933                // xxx - need to handle named return values - this information needs to be saved somehow
    929934                // so that resolution has access to the names.
     
    943948
    944949        void ArrayLength::computeLength( std::list< Declaration * > & translationUnit ) {
    945                 ArrayLength len;
     950                PassVisitor<ArrayLength> len;
    946951                acceptAll( translationUnit, len );
    947952        }
    948953
    949         void ArrayLength::visit( ObjectDecl * objDecl ) {
     954        void ArrayLength::previsit( ObjectDecl * objDecl ) {
    950955                if ( ArrayType * at = dynamic_cast< ArrayType * >( objDecl->get_type() ) ) {
    951956                        if ( at->get_dimension() != nullptr ) return;
Note: See TracChangeset for help on using the changeset viewer.