Changeset e0e9a0b for src/AST/Type.hpp


Ignore:
Timestamp:
Jun 27, 2019, 5:16:54 PM (5 years ago)
Author:
Aaron Moss <a3moss@…>
Branches:
ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, master, new-ast, new-ast-unique-expr, pthread-emulation, qualifiedEnum
Children:
7d0881c
Parents:
6be3b7d6
Message:

Somewhat deeper clone for types with forall qualifiers.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/AST/Type.hpp

    r6be3b7d6 re0e9a0b  
    3333
    3434namespace ast {
     35
     36template< typename T > class Pass;
     37class ForallSubstitutor;
    3538
    3639class Type : public Node {
     
    266269/// Base type for potentially forall-qualified types
    267270class ParameterizedType : public Type {
     271protected:
     272        /// initializes forall with substitutor
     273        void initWithSub( const ParameterizedType & o, Pass< ForallSubstitutor > & sub );
    268274public:
    269275        using ForallList = std::vector<ptr<TypeDecl>>;
     
    278284        : Type(q, std::move(as)), forall() {}
    279285
    280         ParameterizedType( const ParameterizedType & o ) : Type( o ), forall() {
    281                 // one-level deep clone to avoid weak-reference errors
    282                 forall.reserve( o.forall.size() );
    283                 for ( const TypeDecl * d : o.forall ) { forall.emplace_back( d->clone() ); }
    284         }
     286        // enforce use of ForallSubstitutor to copy parameterized type
     287        ParameterizedType( const ParameterizedType & ) = delete;
    285288
    286289        ParameterizedType( ParameterizedType && ) = default;
     
    312315        : ParameterizedType(q), returns(), params(), isVarArgs(va) {}
    313316
     317        FunctionType( const FunctionType & o );
     318
    314319        /// true if either the parameters or return values contain a tttype
    315320        bool isTtype() const;
     
    325330/// base class for types that refer to types declared elsewhere (aggregates and typedefs)
    326331class ReferenceToType : public ParameterizedType {
     332protected:
     333        /// Initializes forall and parameters based on substitutor
     334        void initWithSub( const ReferenceToType & o, Pass< ForallSubstitutor > & sub );
    327335public:
    328336        std::vector<ptr<Expr>> params;
     
    330338        bool hoistType = false;
    331339
    332         ReferenceToType( const std::string& n, CV::Qualifiers q = {},
    333                 std::vector<ptr<Attribute>> && as = {} )
     340        ReferenceToType(
     341                const std::string& n, CV::Qualifiers q = {}, std::vector<ptr<Attribute>> && as = {} )
    334342        : ParameterizedType(q, std::move(as)), params(), name(n) {}
     343
     344        ReferenceToType( const ReferenceToType & o );
    335345
    336346        /// Gets aggregate declaration this type refers to
     
    349359        readonly<StructDecl> base;
    350360
    351         StructInstType( const std::string& n, CV::Qualifiers q = {},
    352                 std::vector<ptr<Attribute>> && as = {} )
     361        StructInstType(
     362                const std::string& n, CV::Qualifiers q = {}, std::vector<ptr<Attribute>> && as = {} )
    353363        : ReferenceToType( n, q, std::move(as) ), base() {}
    354         StructInstType( const StructDecl * b, CV::Qualifiers q = {},
    355                 std::vector<ptr<Attribute>> && as = {} );
     364
     365        StructInstType(
     366                const StructDecl * b, CV::Qualifiers q = {}, std::vector<ptr<Attribute>> && as = {} );
    356367
    357368        bool isComplete() const override;
     
    370381        readonly<UnionDecl> base;
    371382
    372         UnionInstType( const std::string& n, CV::Qualifiers q = {},
    373                 std::vector<ptr<Attribute>> && as = {} )
     383        UnionInstType(
     384                const std::string& n, CV::Qualifiers q = {}, std::vector<ptr<Attribute>> && as = {} )
    374385        : ReferenceToType( n, q, std::move(as) ), base() {}
    375         UnionInstType( const UnionDecl * b, CV::Qualifiers q = {},
    376                 std::vector<ptr<Attribute>> && as = {} );
     386
     387        UnionInstType(
     388                const UnionDecl * b, CV::Qualifiers q = {}, std::vector<ptr<Attribute>> && as = {} );
    377389
    378390        bool isComplete() const override;
     
    391403        readonly<EnumDecl> base;
    392404
    393         EnumInstType( const std::string& n, CV::Qualifiers q = {},
    394                 std::vector<ptr<Attribute>> && as = {} )
     405        EnumInstType(
     406                const std::string& n, CV::Qualifiers q = {}, std::vector<ptr<Attribute>> && as = {} )
    395407        : ReferenceToType( n, q, std::move(as) ), base() {}
    396         EnumInstType( const EnumDecl * b, CV::Qualifiers q = {},
    397                 std::vector<ptr<Attribute>> && as = {} );
     408
     409        EnumInstType(
     410                const EnumDecl * b, CV::Qualifiers q = {}, std::vector<ptr<Attribute>> && as = {} );
    398411
    399412        bool isComplete() const override;
     
    412425        readonly<TraitDecl> base;
    413426
    414         TraitInstType( const std::string& n, CV::Qualifiers q = {},
    415                 std::vector<ptr<Attribute>> && as = {} )
     427        TraitInstType(
     428                const std::string& n, CV::Qualifiers q = {}, std::vector<ptr<Attribute>> && as = {} )
    416429        : ReferenceToType( n, q, std::move(as) ), base() {}
    417         TraitInstType( const TraitDecl * b, CV::Qualifiers q = {},
    418                 std::vector<ptr<Attribute>> && as = {} );
     430       
     431        TraitInstType(
     432                const TraitDecl * b, CV::Qualifiers q = {}, std::vector<ptr<Attribute>> && as = {} );
    419433
    420434        // not meaningful for TraitInstType
     
    435449        TypeVar::Kind kind;
    436450
    437         TypeInstType( const std::string& n, const TypeDecl * b, CV::Qualifiers q = {},
     451        TypeInstType(
     452                const std::string& n, const TypeDecl * b, CV::Qualifiers q = {},
    438453                std::vector<ptr<Attribute>> && as = {} )
    439454        : ReferenceToType( n, q, std::move(as) ), base( b ), kind( b->kind ) {}
    440         TypeInstType( const std::string& n, TypeVar::Kind k, CV::Qualifiers q = {},
     455       
     456        TypeInstType(
     457                const std::string& n, TypeVar::Kind k, CV::Qualifiers q = {},
    441458                std::vector<ptr<Attribute>> && as = {} )
    442459        : ReferenceToType( n, q, std::move(as) ), base(), kind( k ) {}
     460
     461        TypeInstType( const TypeInstType & o );
    443462
    444463        /// sets `base`, updating `kind` correctly
Note: See TracChangeset for help on using the changeset viewer.