Changeset fc72845d


Ignore:
Timestamp:
Sep 25, 2017, 6:36:46 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:
201182a
Parents:
cf90b88
Message:

Convert Box Pass3 to PassVisitor?

Location:
src
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • src/GenPoly/Box.cc

    rcf90b88 rfc72845d  
    6161                FunctionType *makeAdapterType( FunctionType *adaptee, const TyVarMap &tyVars );
    6262
     63                class BoxPass {
     64                protected:
     65                        BoxPass() : scopeTyVars( TypeDecl::Data{} ) {}
     66                        TyVarMap scopeTyVars;
     67                };
     68
    6369                /// Adds layout-generation functions to polymorphic types
    6470                class LayoutFunctionBuilder final : public WithDeclsToAdd, public WithVisitorRef<LayoutFunctionBuilder>, public WithShortCircuiting {
     
    197203
    198204                /// Replaces initialization of polymorphic values with alloca, declaration of dtype/ftype with appropriate void expression, sizeof expressions of polymorphic types with the proper variable, and strips fields from generic struct declarations.
    199                 class Pass3 final : public PolyMutator {
    200                   public:
     205                struct Pass3 final : public BoxPass, public WithGuards {
    201206                        template< typename DeclClass >
    202                         DeclClass *handleDecl( DeclClass *decl, Type *type );
    203 
    204                         using PolyMutator::mutate;
    205                         virtual DeclarationWithType *mutate( FunctionDecl *functionDecl ) override;
    206                         virtual Declaration *mutate( StructDecl *structDecl ) override;
    207                         virtual Declaration *mutate( UnionDecl *unionDecl ) override;
    208                         virtual ObjectDecl *mutate( ObjectDecl *objectDecl ) override;
    209                         virtual TypedefDecl *mutate( TypedefDecl *objectDecl ) override;
    210                         virtual TypeDecl *mutate( TypeDecl *objectDecl ) override;
    211                         virtual Type *mutate( PointerType *pointerType ) override;
    212                         virtual Type *mutate( FunctionType *funcType ) override;
    213                   private:
     207                        void handleDecl( DeclClass * decl, Type * type );
     208
     209                        void premutate( ObjectDecl * objectDecl );
     210                        void premutate( FunctionDecl * functionDecl );
     211                        void premutate( TypedefDecl * typedefDecl );
     212                        void premutate( StructDecl * structDecl );
     213                        void premutate( UnionDecl * unionDecl );
     214                        void premutate( TypeDecl * typeDecl );
     215                        void premutate( PointerType * pointerType );
     216                        void premutate( FunctionType * funcType );
    214217                };
    215218        } // anonymous namespace
     
    247250                Pass2 pass2;
    248251                PassVisitor<PolyGenericCalculator> polyCalculator;
    249                 Pass3 pass3;
     252                PassVisitor<Pass3> pass3;
    250253
    251254                acceptAll( translationUnit, layoutBuilder );
     
    253256                mutateTranslationUnit/*All*/( translationUnit, pass2 );
    254257                mutateAll( translationUnit, polyCalculator );
    255                 mutateTranslationUnit/*All*/( translationUnit, pass3 );
     258                mutateAll( translationUnit, pass3 );
    256259        }
    257260
     
    18251828
    18261829                template< typename DeclClass >
    1827                 DeclClass * Pass3::handleDecl( DeclClass *decl, Type *type ) {
    1828                         scopeTyVars.beginScope();
     1830                void Pass3::handleDecl( DeclClass * decl, Type * type ) {
     1831                        GuardScope( scopeTyVars );
    18291832                        makeTyVarMap( type, scopeTyVars );
    1830 
    1831                         DeclClass *ret = static_cast< DeclClass *>( Mutator::mutate( decl ) );
    1832                         // ScrubTyVars::scrub( decl, scopeTyVars );
    18331833                        ScrubTyVars::scrubAll( decl );
    1834 
    1835                         scopeTyVars.endScope();
    1836                         return ret;
    1837                 }
    1838 
    1839                 ObjectDecl * Pass3::mutate( ObjectDecl *objectDecl ) {
    1840                         return handleDecl( objectDecl, objectDecl->get_type() );
    1841                 }
    1842 
    1843                 DeclarationWithType * Pass3::mutate( FunctionDecl *functionDecl ) {
    1844                         return handleDecl( functionDecl, functionDecl->get_functionType() );
    1845                 }
    1846 
    1847                 TypedefDecl * Pass3::mutate( TypedefDecl *typedefDecl ) {
    1848                         return handleDecl( typedefDecl, typedefDecl->get_base() );
     1834                }
     1835
     1836                void Pass3::premutate( ObjectDecl * objectDecl ) {
     1837                        handleDecl( objectDecl, objectDecl->type );
     1838                }
     1839
     1840                void Pass3::premutate( FunctionDecl * functionDecl ) {
     1841                        handleDecl( functionDecl, functionDecl->type );
     1842                }
     1843
     1844                void Pass3::premutate( TypedefDecl * typedefDecl ) {
     1845                        handleDecl( typedefDecl, typedefDecl->base );
    18491846                }
    18501847
    18511848                /// Strips the members from a generic aggregate
    1852                 void stripGenericMembers(AggregateDecl* decl) {
    1853                         if ( ! decl->get_parameters().empty() ) decl->get_members().clear();
    1854                 }
    1855 
    1856                 Declaration *Pass3::mutate( StructDecl *structDecl ) {
     1849                void stripGenericMembers(AggregateDecl * decl) {
     1850                        if ( ! decl->parameters.empty() ) decl->members.clear();
     1851                }
     1852
     1853                void Pass3::premutate( StructDecl * structDecl ) {
    18571854                        stripGenericMembers( structDecl );
    1858                         return structDecl;
    1859                 }
    1860 
    1861                 Declaration *Pass3::mutate( UnionDecl *unionDecl ) {
     1855                }
     1856
     1857                void Pass3::premutate( UnionDecl * unionDecl ) {
    18621858                        stripGenericMembers( unionDecl );
    1863                         return unionDecl;
    1864                 }
    1865 
    1866                 TypeDecl * Pass3::mutate( TypeDecl *typeDecl ) {
    1867 //   Initializer *init = 0;
    1868 //   std::list< Expression *> designators;
    1869 //   addToTyVarMap( typeDecl, scopeTyVars );
    1870 //   if ( typeDecl->get_base() ) {
    1871 //     init = new SimpleInit( new SizeofExpr( handleDecl( typeDecl, typeDecl->get_base() ) ), designators );
    1872 //   }
    1873 //   return new ObjectDecl( typeDecl->get_name(), Declaration::Extern, LinkageSpec::C, 0, new BasicType( Type::Qualifiers(), BasicType::UnsignedInt ), init );
    1874 
     1859                }
     1860
     1861                void Pass3::premutate( TypeDecl * typeDecl ) {
    18751862                        addToTyVarMap( typeDecl, scopeTyVars );
    1876                         return dynamic_cast<TypeDecl*>( Mutator::mutate( typeDecl ) );
    1877                 }
    1878 
    1879                 Type * Pass3::mutate( PointerType *pointerType ) {
    1880                         scopeTyVars.beginScope();
     1863                }
     1864
     1865                void Pass3::premutate( PointerType * pointerType ) {
     1866                        GuardScope( scopeTyVars );
    18811867                        makeTyVarMap( pointerType, scopeTyVars );
    1882 
    1883                         Type *ret = Mutator::mutate( pointerType );
    1884 
    1885                         scopeTyVars.endScope();
    1886                         return ret;
    1887                 }
    1888 
    1889                 Type * Pass3::mutate( FunctionType *functionType ) {
    1890                         scopeTyVars.beginScope();
     1868                }
     1869
     1870                void Pass3::premutate( FunctionType * functionType ) {
     1871                        GuardScope( scopeTyVars );
    18911872                        makeTyVarMap( functionType, scopeTyVars );
    1892 
    1893                         Type *ret = Mutator::mutate( functionType );
    1894 
    1895                         scopeTyVars.endScope();
    1896                         return ret;
    18971873                }
    18981874        } // anonymous namespace
  • src/GenPoly/Specialize.cc

    rcf90b88 rfc72845d  
    2929#include "InitTweak/InitTweak.h"         // for isIntrinsicCallExpr
    3030#include "Parser/LinkageSpec.h"          // for C
    31 #include "PolyMutator.h"                 // for PolyMutator
    3231#include "ResolvExpr/FindOpenVars.h"     // for findOpenVars
    3332#include "ResolvExpr/TypeEnvironment.h"  // for OpenVarSet, AssertionSet
  • src/InitTweak/FixInit.cc

    rcf90b88 rfc72845d  
    3737#include "GenInit.h"                   // for genCtorDtor
    3838#include "GenPoly/GenPoly.h"           // for getFunctionType
    39 #include "GenPoly/PolyMutator.h"       // for PolyMutator
    4039#include "InitTweak.h"                 // for getFunctionName, getCallArg
    4140#include "Parser/LinkageSpec.h"        // for C, Spec, Cforall, isBuiltin
Note: See TracChangeset for help on using the changeset viewer.