Changeset 0db6fc0


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?

Location:
src
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • src/ControlStruct/ForExprMutator.cc

    rf94ca7e r0db6fc0  
    55// file "LICENCE" distributed with Cforall.
    66//
    7 // ForExprMutator.cc -- 
     7// ForExprMutator.cc --
    88//
    99// Author           : Rodolfo G. Esteves
     
    1919
    2020namespace ControlStruct {
    21         Statement *ForExprMutator::mutate( ForStmt *forStmt ) {
    22                 // recurse down all nest for loops to hoist any initializer declarations to make them C89 (rather than C99)
    23                 forStmt->set_body( forStmt->get_body()->acceptMutator( *this ) );
    24 
    25                 std::list<Statement *> &init = forStmt->get_initialization();
     21        Statement *ForExprMutator::postmutate( ForStmt *forStmt ) {
     22                // hoist any initializer declarations to make them C89 (rather than C99)
     23                std::list<Statement *> &init = forStmt->get_initialization();
    2624                if ( init.size() == 0 ) {
    2725                        return forStmt;
     
    3937                forStmt->set_initialization( std::list<Statement *>() );
    4038                return block;
    41 
    42                 return forStmt;
    4339        }
    4440} // namespace ControlStruct
  • src/ControlStruct/ForExprMutator.h

    rf94ca7e r0db6fc0  
    55// file "LICENCE" distributed with Cforall.
    66//
    7 // ForExprMutator.h -- 
     7// ForExprMutator.h --
    88//
    99// Author           : Rodolfo G. Esteves
     
    2121
    2222namespace ControlStruct {
    23         class ForExprMutator : public Mutator {
     23        class ForExprMutator {
    2424          public:
    25                 virtual Statement *mutate( ForStmt * );
     25                Statement *postmutate( ForStmt * );
    2626        };
    2727} // namespace ControlStruct
  • src/ControlStruct/Mutate.cc

    rf94ca7e r0db6fc0  
    2626
    2727#include "Common/utility.h"
     28#include "Common/PassVisitor.h"
    2829
    2930#include "SynTree/Visitor.h"
     
    3435        void mutate( std::list< Declaration * > translationUnit ) {
    3536                // hoist initialization out of for statements
    36                 ForExprMutator formut;
     37                PassVisitor<ForExprMutator> formut;
    3738
    3839                // normalizes label definitions and generates multi-level exit labels
  • src/InitTweak/GenInit.cc

    rf94ca7e r0db6fc0  
    4444                static void makeReturnTemp( std::list< Declaration * > &translationUnit );
    4545
    46                 ReturnFixer();
    47 
    4846                typedef GenPoly::PolyMutator Parent;
    4947                using Parent::mutate;
     
    134132                mutateAll( translationUnit, fixer );
    135133        }
    136 
    137         ReturnFixer::ReturnFixer() {}
    138134
    139135        Statement *ReturnFixer::mutate( ReturnStmt *returnStmt ) {
  • 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.