Changeset 7bb6bd8


Ignore:
Timestamp:
May 8, 2019, 1:38:55 PM (3 years ago)
Author:
Peter A. Buhr <pabuhr@…>
Branches:
arm-eh, cleanup-dtors, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr
Children:
2ed1d50
Parents:
3c1fa71 (diff), b1d3ee1 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge branch 'master' of plg.uwaterloo.ca:software/cfa/cfa-cc

Location:
src
Files:
1 added
13 edited

Legend:

Unmodified
Added
Removed
  • src/Common/PassVisitor.h

    r3c1fa71 r7bb6bd8  
    44
    55#include <stack>
     6#include <type_traits>
    67
    78#include "Common/Stats.h"
     
    301302
    302303
    303         TypeSubstitution **             get_env_ptr    () { return env_impl             ( pass, 0); }
     304        auto                                    get_env_ptr    () -> decltype(env_impl( pass, 0)) { return env_impl( pass, 0); }
    304305        std::list< Statement* > *       get_beforeStmts() { return stmtsToAddBefore_impl( pass, 0); }
    305306        std::list< Statement* > *       get_afterStmts () { return stmtsToAddAfter_impl ( pass, 0); }
     
    348349};
    349350
     351class WithConstTypeSubstitution {
     352protected:
     353        WithConstTypeSubstitution() = default;
     354        ~WithConstTypeSubstitution() = default;
     355
     356public:
     357        const TypeSubstitution * env = nullptr;
     358};
     359
    350360class WithStmtsToAdd {
    351361protected:
  • src/Common/PassVisitor.impl.h

    r3c1fa71 r7bb6bd8  
    253253
    254254        // don't want statements from outer CompoundStmts to be added to this CompoundStmt
    255         ValueGuardPtr< TypeSubstitution * >  oldEnv        ( get_env_ptr    () );
     255        ValueGuardPtr< typename std::remove_pointer<decltype(get_env_ptr())>::type >  oldEnv( get_env_ptr() );
    256256        ValueGuardPtr< DeclList_t >          oldBeforeDecls( get_beforeDecls() );
    257257        ValueGuardPtr< DeclList_t >          oldAfterDecls ( get_afterDecls () );
     
    19951995
    19961996        // don't want statements from outer CompoundStmts to be added to this StmtExpr
    1997         ValueGuardPtr< TypeSubstitution * >      oldEnv        ( get_env_ptr() );
     1997        ValueGuardPtr< typename std::remove_pointer<decltype(get_env_ptr())>::type >  oldEnv( get_env_ptr() );
    19981998        ValueGuardPtr< std::list< Statement* > > oldBeforeStmts( get_beforeStmts() );
    19991999        ValueGuardPtr< std::list< Statement* > > oldAfterStmts ( get_afterStmts () );
     
    20122012
    20132013        // don't want statements from outer CompoundStmts to be added to this StmtExpr
    2014         ValueGuardPtr< TypeSubstitution * >      oldEnv        ( get_env_ptr() );
     2014        ValueGuardPtr< typename std::remove_pointer<decltype(get_env_ptr())>::type >  oldEnv( get_env_ptr() );
    20152015        ValueGuardPtr< std::list< Statement* > > oldBeforeStmts( get_beforeStmts() );
    20162016        ValueGuardPtr< std::list< Statement* > > oldAfterStmts ( get_afterStmts () );
  • src/Common/PassVisitor.proto.h

    r3c1fa71 r7bb6bd8  
    165165static inline type * name##_impl( __attribute__((unused)) pass_type& pass, __attribute__((unused)) long unused ) { return nullptr;}    \
    166166
    167 FIELD_PTR( TypeSubstitution *, env )
     167FIELD_PTR( const TypeSubstitution *, env )
    168168FIELD_PTR( std::list< Statement* >, stmtsToAddBefore )
    169169FIELD_PTR( std::list< Statement* >, stmtsToAddAfter  )
  • src/GenPoly/Box.cc

    r3c1fa71 r7bb6bd8  
    7676
    7777                /// Replaces polymorphic return types with out-parameters, replaces calls to polymorphic functions with adapter calls as needed, and adds appropriate type variables to the function call
    78                 class Pass1 final : public BoxPass, public WithTypeSubstitution, public WithStmtsToAdd, public WithGuards, public WithVisitorRef<Pass1>, public WithShortCircuiting {
     78                class Pass1 final : public BoxPass, public WithConstTypeSubstitution, public WithStmtsToAdd, public WithGuards, public WithVisitorRef<Pass1>, public WithShortCircuiting {
    7979                  public:
    8080                        Pass1();
     
    150150                /// * Calculates polymorphic offsetof expressions from offset array
    151151                /// * Inserts dynamic calculation of polymorphic type layouts where needed
    152                 class PolyGenericCalculator final : public BoxPass, public WithGuards, public WithVisitorRef<PolyGenericCalculator>, public WithStmtsToAdd, public WithDeclsToAdd, public WithTypeSubstitution {
     152                class PolyGenericCalculator final : public BoxPass, public WithGuards, public WithVisitorRef<PolyGenericCalculator>, public WithStmtsToAdd, public WithDeclsToAdd, public WithConstTypeSubstitution {
    153153                public:
    154154                        PolyGenericCalculator();
     
    17641764
    17651765                Expression *PolyGenericCalculator::postmutate( SizeofExpr *sizeofExpr ) {
    1766                         Type *ty = sizeofExpr->get_isType() ? 
     1766                        Type *ty = sizeofExpr->get_isType() ?
    17671767                                sizeofExpr->get_type() : sizeofExpr->get_expr()->get_result();
    1768                        
     1768
    17691769                        Expression * gen = genSizeof( ty );
    17701770                        if ( gen ) {
  • src/GenPoly/GenPoly.cc

    r3c1fa71 r7bb6bd8  
    440440        }
    441441
    442         bool needsBoxing( Type * param, Type * arg, const TyVarMap &exprTyVars, TypeSubstitution * env ) {
     442        bool needsBoxing( Type * param, Type * arg, const TyVarMap &exprTyVars, const TypeSubstitution * env ) {
    443443                // is parameter is not polymorphic, don't need to box
    444444                if ( ! isPolyType( param, exprTyVars ) ) return false;
     
    450450        }
    451451
    452         bool needsBoxing( Type * param, Type * arg, ApplicationExpr * appExpr, TypeSubstitution * env ) {
     452        bool needsBoxing( Type * param, Type * arg, ApplicationExpr * appExpr, const TypeSubstitution * env ) {
    453453                FunctionType * function = getFunctionType( appExpr->function->result );
    454454                assertf( function, "ApplicationExpr has non-function type: %s", toString( appExpr->function->result ).c_str() );
  • src/GenPoly/GenPoly.h

    r3c1fa71 r7bb6bd8  
    8181
    8282        /// true if arg requires boxing given exprTyVars
    83         bool needsBoxing( Type * param, Type * arg, const TyVarMap &exprTyVars, TypeSubstitution * env );
     83        bool needsBoxing( Type * param, Type * arg, const TyVarMap &exprTyVars, const TypeSubstitution * env );
    8484
    8585        /// true if arg requires boxing in the call to appExpr
    86         bool needsBoxing( Type * param, Type * arg, ApplicationExpr * appExpr, TypeSubstitution * env );
     86        bool needsBoxing( Type * param, Type * arg, ApplicationExpr * appExpr, const TypeSubstitution * env );
    8787
    8888        /// Adds the type variable `tyVar` to `tyVarMap`
  • src/GenPoly/InstantiateGeneric.cc

    r3c1fa71 r7bb6bd8  
    168168
    169169        /// Mutator pass that replaces concrete instantiations of generic types with actual struct declarations, scoped appropriately
    170         struct GenericInstantiator final : public WithTypeSubstitution, public WithDeclsToAdd, public WithVisitorRef<GenericInstantiator>, public WithGuards {
     170        struct GenericInstantiator final : public WithConstTypeSubstitution, public WithDeclsToAdd, public WithVisitorRef<GenericInstantiator>, public WithGuards {
    171171                /// Map of (generic type, parameter list) pairs to concrete type instantiations
    172172                InstantiationMap< AggregateDecl, AggregateDecl > instantiations;
  • src/GenPoly/Specialize.cc

    r3c1fa71 r7bb6bd8  
    4242
    4343namespace GenPoly {
    44         struct Specialize final : public WithTypeSubstitution, public WithStmtsToAdd, public WithVisitorRef<Specialize> {
     44        struct Specialize final : public WithConstTypeSubstitution, public WithStmtsToAdd, public WithVisitorRef<Specialize> {
    4545                Expression * postmutate( ApplicationExpr *applicationExpr );
    4646                Expression * postmutate( CastExpr *castExpr );
     
    5454
    5555        /// Looks up open variables in actual type, returning true if any of them are bound in the environment or formal type.
    56         bool needsPolySpecialization( Type *formalType, Type *actualType, TypeSubstitution *env ) {
     56        bool needsPolySpecialization( Type *formalType, Type *actualType, const TypeSubstitution *env ) {
    5757                if ( env ) {
    5858                        using namespace ResolvExpr;
     
    145145        }
    146146
    147         bool needsSpecialization( Type *formalType, Type *actualType, TypeSubstitution *env ) {
     147        bool needsSpecialization( Type *formalType, Type *actualType, const TypeSubstitution *env ) {
    148148                return needsPolySpecialization( formalType, actualType, env ) || needsTupleSpecialization( formalType, actualType );
    149149        }
  • src/InitTweak/FixInit.cc

    r3c1fa71 r7bb6bd8  
    7272                };
    7373
    74                 struct InsertImplicitCalls : public WithTypeSubstitution {
     74                struct InsertImplicitCalls : public WithConstTypeSubstitution {
    7575                        /// wrap function application expressions as ImplicitCopyCtorExpr nodes so that it is easy to identify which
    7676                        /// function calls need their parameters to be copy constructed
     
    187187                };
    188188
    189                 class FixCopyCtors final : public WithStmtsToAdd, public WithShortCircuiting, public WithVisitorRef<FixCopyCtors>, public WithTypeSubstitution {
     189                class FixCopyCtors final : public WithStmtsToAdd, public WithShortCircuiting, public WithVisitorRef<FixCopyCtors>, public WithConstTypeSubstitution {
    190190                  public:
    191191                        FixCopyCtors( UnqCount & unqCount ) : unqCount( unqCount ){}
  • src/SynTree/TypeSubstitution.cc

    r3c1fa71 r7bb6bd8  
    108108namespace {
    109109        struct EnvTrimmer {
    110                 TypeSubstitution * env, * newEnv;
    111                 EnvTrimmer( TypeSubstitution * env, TypeSubstitution * newEnv ) : env( env ), newEnv( newEnv ){}
     110                const TypeSubstitution * env;
     111                TypeSubstitution * newEnv;
     112                EnvTrimmer( const TypeSubstitution * env, TypeSubstitution * newEnv ) : env( env ), newEnv( newEnv ){}
    112113                void previsit( TypeDecl * tyDecl ) {
    113114                        // transfer known bindings for seen type variables
     
    120121
    121122/// reduce environment to just the parts that are referenced in a given expression
    122 TypeSubstitution * TypeSubstitution::newFromExpr( Expression * expr, TypeSubstitution * env ) {
     123TypeSubstitution * TypeSubstitution::newFromExpr( Expression * expr, const TypeSubstitution * env ) {
    123124        if ( env ) {
    124125                TypeSubstitution * newEnv = new TypeSubstitution();
  • src/SynTree/TypeSubstitution.h

    r3c1fa71 r7bb6bd8  
    3939        TypeSubstitution &operator=( const TypeSubstitution &other );
    4040
    41         template< typename SynTreeClass > int apply( SynTreeClass *&input );
    42         template< typename SynTreeClass > int applyFree( SynTreeClass *&input );
     41        template< typename SynTreeClass > int apply( SynTreeClass *&input ) const;
     42        template< typename SynTreeClass > int applyFree( SynTreeClass *&input ) const;
    4343
    4444        void add( std::string formalType, Type *actualType );
     
    5656
    5757        /// create a new TypeSubstitution using bindings from env containing all of the type variables in expr
    58         static TypeSubstitution * newFromExpr( Expression * expr, TypeSubstitution * env );
     58        static TypeSubstitution * newFromExpr( Expression * expr, const TypeSubstitution * env );
    5959
    6060        void normalize();
     
    130130// definitition must happen after PassVisitor is included so that WithGuards can be used
    131131struct TypeSubstitution::Substituter : public WithGuards, public WithVisitorRef<Substituter> {
    132                 Substituter( TypeSubstitution & sub, bool freeOnly ) : sub( sub ), freeOnly( freeOnly ) {}
     132                Substituter( const TypeSubstitution & sub, bool freeOnly ) : sub( sub ), freeOnly( freeOnly ) {}
    133133
    134134                Type * postmutate( TypeInstType * aggregateUseType );
     
    143143                void premutate( UnionInstType * aggregateUseType );
    144144
    145                 TypeSubstitution & sub;
     145                const TypeSubstitution & sub;
    146146                int subCount = 0;
    147147                bool freeOnly;
     
    151151
    152152template< typename SynTreeClass >
    153 int TypeSubstitution::apply( SynTreeClass *&input ) {
     153int TypeSubstitution::apply( SynTreeClass *&input ) const {
    154154        assert( input );
    155155        PassVisitor<Substituter> sub( *this, false );
     
    163163
    164164template< typename SynTreeClass >
    165 int TypeSubstitution::applyFree( SynTreeClass *&input ) {
     165int TypeSubstitution::applyFree( SynTreeClass *&input ) const {
    166166        assert( input );
    167167        PassVisitor<Substituter> sub( *this, true );
  • src/Tuples/TupleExpansion.cc

    r3c1fa71 r7bb6bd8  
    5858                };
    5959
    60                 struct TupleTypeReplacer : public WithDeclsToAdd, public WithGuards, public WithTypeSubstitution {
     60                struct TupleTypeReplacer : public WithDeclsToAdd, public WithGuards, public WithConstTypeSubstitution {
    6161                        Type * postmutate( TupleType * tupleType );
    6262
  • src/main.cc

    r3c1fa71 r7bb6bd8  
    446446}; // description
    447447
    448 static_assert( sizeof( long_opts ) / sizeof( long_opts[0] ) - 1 == sizeof( description ) / sizeof( description[0] ) );
     448static_assert( sizeof( long_opts ) / sizeof( long_opts[0] ) - 1 == sizeof( description ) / sizeof( description[0] ), "Long opts and description must match" );
    449449
    450450static struct Printopts {
Note: See TracChangeset for help on using the changeset viewer.