Changeset 361bf01 for src/AST


Ignore:
Timestamp:
Dec 11, 2020, 11:20:45 PM (3 years ago)
Author:
Fangren Yu <f37yu@…>
Branches:
ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, master, new-ast-unique-expr, pthread-emulation, qualifiedEnum
Children:
5b9a0ae
Parents:
a6e0e4c
Message:

remove ParameterizedType? and put content into FunctionType?

Location:
src/AST
Files:
12 edited

Legend:

Unmodified
Added
Removed
  • src/AST/Convert.cpp

    ra6e0e4c r361bf01  
    12171217
    12181218        const ast::Type * postvisit( const ast::BaseInstType * old, ReferenceToType * ty ) {
    1219                 ty->forall = get<TypeDecl>().acceptL( old->forall );
    12201219                ty->parameters = get<Expression>().acceptL( old->params );
    12211220                ty->hoistType = old->hoistType;
     
    26162615
    26172616        void postvisit( const ReferenceToType * old, ast::BaseInstType * ty ) {
    2618                 ty->forall = GET_ACCEPT_V( forall, TypeDecl );
    26192617                ty->params = GET_ACCEPT_V( parameters, Expr );
    26202618                ty->hoistType = old->hoistType;
  • src/AST/ForallSubstitutor.hpp

    ra6e0e4c r361bf01  
    2929       
    3030        /// Make new forall-list clone
    31         ParameterizedType::ForallList operator() ( const ParameterizedType::ForallList & o ) {
     31        FunctionType::ForallList operator() ( const FunctionType::ForallList & o ) {
    3232                return subs.clone( o, *visitor );
    3333        }
  • src/AST/Pass.hpp

    ra6e0e4c r361bf01  
    287287        /// Internal RAII guard for forall substitutions
    288288        struct guard_forall_subs {
    289                 guard_forall_subs( Pass<core_t> & pass, const ParameterizedType * type )
     289                guard_forall_subs( Pass<core_t> & pass, const FunctionType * type )
    290290                : pass( pass ), type( type ) { __pass::forall::enter(pass.core, 0, type ); }
    291291                ~guard_forall_subs()         { __pass::forall::leave(pass.core, 0, type ); }
    292292                Pass<core_t> & pass;
    293                 const ParameterizedType * type;
     293                const FunctionType * type;
    294294        };
    295295
  • src/AST/Pass.impl.hpp

    ra6e0e4c r361bf01  
    17771777        VISIT({
    17781778                guard_symtab guard { *this };
    1779                 guard_forall_subs forall_guard { *this, node };
    1780                 mutate_forall( node );
    17811779                maybe_accept( node, &StructInstType::params );
    17821780        })
     
    17951793        VISIT({
    17961794                guard_symtab guard { *this };
    1797                 guard_forall_subs forall_guard { *this, node };
    1798                 mutate_forall( node );
    17991795                maybe_accept( node, &UnionInstType::params );
    18001796        })
     
    18101806
    18111807        VISIT({
    1812                 guard_forall_subs forall_guard { *this, node };
    1813                 mutate_forall( node );
    18141808                maybe_accept( node, &EnumInstType::params );
    18151809        })
     
    18251819
    18261820        VISIT({
    1827                 guard_forall_subs forall_guard { *this, node };
    1828                 mutate_forall( node );
    18291821                maybe_accept( node, &TraitInstType::params );
    18301822        })
     
    18411833        VISIT(
    18421834                {
    1843                         guard_forall_subs forall_guard { *this, node };
    1844                         mutate_forall( node );
    18451835                        maybe_accept( node, &TypeInstType::params );
    18461836                }
  • src/AST/Pass.proto.hpp

    ra6e0e4c r361bf01  
    396396                // Some simple scoping rules
    397397                template<typename core_t>
    398                 static inline auto enter( core_t & core, int, const ast::ParameterizedType * type )
     398                static inline auto enter( core_t & core, int, const ast::FunctionType * type )
    399399                -> decltype( core.subs, void() ) {
    400400                        if ( ! type->forall.empty() ) core.subs.beginScope();
     
    402402
    403403                template<typename core_t>
    404                 static inline auto enter( core_t &, long, const ast::ParameterizedType * ) {}
    405 
    406                 template<typename core_t>
    407                 static inline auto leave( core_t & core, int, const ast::ParameterizedType * type )
     404                static inline auto enter( core_t &, long, const ast::FunctionType * ) {}
     405
     406                template<typename core_t>
     407                static inline auto leave( core_t & core, int, const ast::FunctionType * type )
    408408                -> decltype( core.subs, void() ) {
    409409                        if ( ! type->forall.empty() ) { core.subs.endScope(); }
     
    411411
    412412                template<typename core_t>
    413                 static inline auto leave( core_t &, long, const ast::ParameterizedType * ) {}
     413                static inline auto leave( core_t &, long, const ast::FunctionType * ) {}
    414414
    415415                // Get the substitution table, if present
  • src/AST/Print.cpp

    ra6e0e4c r361bf01  
    146146        }
    147147
    148         void print( const ast::ParameterizedType::ForallList & forall ) {
     148        void print( const ast::FunctionType::ForallList & forall ) {
    149149                if ( forall.empty() ) return;
    150150                os << "forall" << endl;
     
    259259        }
    260260
    261         void preprint( const ast::ParameterizedType * node ) {
     261        void preprint( const ast::FunctionType * node ) {
    262262                print( node->forall );
    263263                print( node->qualifiers );
     
    265265
    266266        void preprint( const ast::BaseInstType * node ) {
    267                 print( node->forall );
    268267                print( node->attributes );
    269268                print( node->qualifiers );
  • src/AST/Type.cpp

    ra6e0e4c r361bf01  
    9494// --- ParameterizedType
    9595
    96 void ParameterizedType::initWithSub(
    97         const ParameterizedType & o, Pass< ForallSubstitutor > & sub
     96void FunctionType::initWithSub(
     97        const FunctionType & o, Pass< ForallSubstitutor > & sub
    9898) {
    9999        forall = sub.core( o.forall );
     
    104104
    105105FunctionType::FunctionType( const FunctionType & o )
    106 : ParameterizedType( o.qualifiers, copy( o.attributes ) ), returns(), params(),
     106: Type( o.qualifiers, copy( o.attributes ) ), returns(), params(),
    107107  isVarArgs( o.isVarArgs ) {
    108108        Pass< ForallSubstitutor > sub;
     
    125125}
    126126
    127 // --- BaseInstType
    128 
    129 void BaseInstType::initWithSub( const BaseInstType & o, Pass< ForallSubstitutor > & sub ) {
    130         ParameterizedType::initWithSub( o, sub ); // initialize substitution
    131         params = sub.core( o.params );            // apply to parameters
    132 }
    133 
    134 BaseInstType::BaseInstType( const BaseInstType & o )
    135 : ParameterizedType( o.qualifiers, copy( o.attributes ) ), params(), name( o.name ),
    136   hoistType( o.hoistType ) {
    137         Pass< ForallSubstitutor > sub;
    138         initWithSub( o, sub );
    139 }
    140 
    141127std::vector<readonly<Decl>> BaseInstType::lookup( const std::string& name ) const {
    142128        assertf( aggr(), "Must have aggregate to perform lookup" );
     
    176162        const TraitDecl * b, CV::Qualifiers q, std::vector<ptr<Attribute>>&& as )
    177163: BaseInstType( b->name, q, move(as) ), base( b ) {}
    178 
    179 // --- TypeInstType
    180 
    181 TypeInstType::TypeInstType( const TypeInstType & o )
    182 : BaseInstType( o.name, o.qualifiers, copy( o.attributes ) ), base(), kind( o.kind ) {
    183         Pass< ForallSubstitutor > sub;
    184         initWithSub( o, sub );      // initialize substitution
    185         base = sub.core( o.base );  // apply to base type
    186 }
    187164
    188165void TypeInstType::set_base( const TypeDecl * b ) {
  • src/AST/Type.hpp

    ra6e0e4c r361bf01  
    267267};
    268268
    269 /// Base type for potentially forall-qualified types
    270 class ParameterizedType : public Type {
    271 protected:
    272         /// initializes forall with substitutor
    273         void initWithSub( const ParameterizedType & o, Pass< ForallSubstitutor > & sub );
    274 public:
    275         using ForallList = std::vector<ptr<TypeDecl>>;
    276 
    277         ForallList forall;
    278 
    279         ParameterizedType( ForallList&& fs = {}, CV::Qualifiers q = {},
    280                 std::vector<ptr<Attribute>> && as = {} )
    281         : Type(q, std::move(as)), forall(std::move(fs)) {}
    282 
    283         ParameterizedType( CV::Qualifiers q, std::vector<ptr<Attribute>> && as = {} )
    284         : Type(q, std::move(as)), forall() {}
    285 
    286         // enforce use of ForallSubstitutor to copy parameterized type
    287         ParameterizedType( const ParameterizedType & ) = delete;
    288 
    289         ParameterizedType( ParameterizedType && ) = default;
    290 
    291         // no need to change destructor, and operator= deleted in Node
    292 
    293 private:
    294         virtual ParameterizedType * clone() const override = 0;
    295         MUTATE_FRIEND
    296 };
    297 
    298269/// Function variable arguments flag
    299270enum ArgumentFlag { FixedArgs, VariableArgs };
    300271
    301272/// Type of a function `[R1, R2](*)(P1, P2, P3)`
    302 class FunctionType final : public ParameterizedType {
    303 public:
     273class FunctionType final : public Type {
     274        protected:
     275        /// initializes forall with substitutor
     276        void initWithSub( const FunctionType & o, Pass< ForallSubstitutor > & sub );
     277public:
     278        using ForallList = std::vector<ptr<TypeDecl>>;
     279        ForallList forall;
     280
    304281        std::vector<ptr<Type>> returns;
    305282        std::vector<ptr<Type>> params;
     
    313290
    314291        FunctionType( ArgumentFlag va = FixedArgs, CV::Qualifiers q = {} )
    315         : ParameterizedType(q), returns(), params(), isVarArgs(va) {}
     292        : Type(q), returns(), params(), isVarArgs(va) {}
    316293
    317294        FunctionType( const FunctionType & o );
     
    329306
    330307/// base class for types that refer to types declared elsewhere (aggregates and typedefs)
    331 class BaseInstType : public ParameterizedType {
    332 protected:
    333         /// Initializes forall and parameters based on substitutor
    334         void initWithSub( const BaseInstType & o, Pass< ForallSubstitutor > & sub );
     308class BaseInstType : public Type {
    335309public:
    336310        std::vector<ptr<Expr>> params;
     
    340314        BaseInstType(
    341315                const std::string& n, CV::Qualifiers q = {}, std::vector<ptr<Attribute>> && as = {} )
    342         : ParameterizedType(q, std::move(as)), params(), name(n) {}
     316        : Type(q, std::move(as)), params(), name(n) {}
    343317
    344318        BaseInstType(
    345319                const std::string& n, std::vector<ptr<Expr>> && params,
    346320                CV::Qualifiers q = {}, std::vector<ptr<Attribute>> && as = {} )
    347         : ParameterizedType(q, std::move(as)), params(std::move(params)), name(n) {}
    348 
    349         BaseInstType( const BaseInstType & o );
     321        : Type(q, std::move(as)), params(std::move(params)), name(n) {}
     322
     323        BaseInstType( const BaseInstType & o ) = default;
    350324
    351325        /// Gets aggregate declaration this type refers to
     
    433407        : BaseInstType( n, q, std::move(as) ), base(), kind( k ) {}
    434408
    435         TypeInstType( const TypeInstType & o );
     409        TypeInstType( const TypeInstType & o ) = default;
    436410
    437411        /// sets `base`, updating `kind` correctly
  • src/AST/TypeEnvironment.cpp

    ra6e0e4c r361bf01  
    105105}
    106106
    107 void TypeEnvironment::add( const ParameterizedType::ForallList & tyDecls ) {
     107void TypeEnvironment::add( const FunctionType::ForallList & tyDecls ) {
    108108        for ( const TypeDecl * tyDecl : tyDecls ) {
    109109                env.emplace_back( tyDecl );
  • src/AST/TypeEnvironment.hpp

    ra6e0e4c r361bf01  
    134134
    135135        /// Add a new equivalence class for each type variable
    136         void add( const ParameterizedType::ForallList & tyDecls );
     136        void add( const FunctionType::ForallList & tyDecls );
    137137
    138138        /// Add a new equivalence class for each branch of the substitution, checking for conflicts
  • src/AST/TypeSubstitution.cpp

    ra6e0e4c r361bf01  
    166166}
    167167
    168 void TypeSubstitution::Substituter::previsit( const ParameterizedType * ptype ) {
     168void TypeSubstitution::Substituter::previsit( const FunctionType * ptype ) {
    169169        GuardValue( boundVars );
    170170        // bind type variables from forall-qualifiers
     
    180180        // bind type variables from forall-qualifiers
    181181        if ( freeOnly ) {
    182                 for ( const TypeDecl * tyvar : type->forall ) {
    183                         boundVars.insert( tyvar->name );
    184                 } // for
    185182                // bind type variables from generic type instantiations
    186183                if ( auto decl = type->aggr() ) {
  • src/AST/TypeSubstitution.hpp

    ra6e0e4c r361bf01  
    167167
    168168                /// Records type variable bindings from forall-statements
    169                 void previsit( const ParameterizedType * type );
     169                void previsit( const FunctionType * type );
    170170                /// Records type variable bindings from forall-statements and instantiations of generic types
    171171                void handleAggregateType( const BaseInstType * type );
Note: See TracChangeset for help on using the changeset viewer.