Changeset 923d25a for src/AST/Type.hpp


Ignore:
Timestamp:
Jul 23, 2020, 2:42:23 PM (4 years ago)
Author:
Andrew Beach <ajbeach@…>
Branches:
ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, master, new-ast, new-ast-unique-expr, pthread-emulation, qualifiedEnum
Children:
d1ee9ec
Parents:
a8ed717
Message:

SueInstType? is a template that replaces {Struct,Union,Enum}InstType?, with using declarations keeping the interface the same.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/AST/Type.hpp

    ra8ed717 r923d25a  
    99// Author           : Aaron B. Moss
    1010// Created On       : Thu May 9 10:00:00 2019
    11 // Last Modified By : Peter A. Buhr
    12 // Last Modified On : Wed Dec 11 21:56:46 2019
    13 // Update Count     : 5
     11// Last Modified By : Andrew Beach
     12// Last Modified On : Thu Jul 23 14:15:00 2020
     13// Update Count     : 6
    1414//
    1515
     
    354354};
    355355
    356 /// instance of struct type
    357 class StructInstType final : public ReferenceToType {
    358 public:
    359         readonly<StructDecl> base;
    360 
    361         StructInstType(
     356// Common implementation for the SUE instance types. Not to be used directly.
     357template<typename decl_t>
     358class SueInstType final : public ReferenceToType {
     359public:
     360        using base_type = decl_t;
     361        readonly<decl_t> base;
     362
     363        SueInstType(
    362364                const std::string& n, CV::Qualifiers q = {}, std::vector<ptr<Attribute>> && as = {} )
    363365        : ReferenceToType( n, q, std::move(as) ), base() {}
    364366
    365         StructInstType(
    366                 const StructDecl * b, CV::Qualifiers q = {}, std::vector<ptr<Attribute>> && as = {} );
     367        SueInstType(
     368                const decl_t * b, CV::Qualifiers q = {}, std::vector<ptr<Attribute>> && as = {} );
    367369
    368370        bool isComplete() const override;
    369371
    370         const StructDecl * aggr() const override { return base; }
    371 
    372         const Type * accept( Visitor & v ) const override { return v.visit( this ); }
    373 private:
    374         StructInstType * clone() const override { return new StructInstType{ *this }; }
    375         MUTATE_FRIEND
    376 };
    377 
    378 /// instance of union type
    379 class UnionInstType final : public ReferenceToType {
    380 public:
    381         readonly<UnionDecl> base;
    382 
    383         UnionInstType(
    384                 const std::string& n, CV::Qualifiers q = {}, std::vector<ptr<Attribute>> && as = {} )
    385         : ReferenceToType( n, q, std::move(as) ), base() {}
    386 
    387         UnionInstType(
    388                 const UnionDecl * b, CV::Qualifiers q = {}, std::vector<ptr<Attribute>> && as = {} );
    389 
    390         bool isComplete() const override;
    391 
    392         const UnionDecl * aggr() const override { return base; }
    393 
    394         const Type * accept( Visitor & v ) const override { return v.visit( this ); }
    395 private:
    396         UnionInstType * clone() const override { return new UnionInstType{ *this }; }
    397         MUTATE_FRIEND
    398 };
    399 
    400 /// instance of enum type
    401 class EnumInstType final : public ReferenceToType {
    402 public:
    403         readonly<EnumDecl> base;
    404 
    405         EnumInstType(
    406                 const std::string& n, CV::Qualifiers q = {}, std::vector<ptr<Attribute>> && as = {} )
    407         : ReferenceToType( n, q, std::move(as) ), base() {}
    408 
    409         EnumInstType(
    410                 const EnumDecl * b, CV::Qualifiers q = {}, std::vector<ptr<Attribute>> && as = {} );
    411 
    412         bool isComplete() const override;
    413 
    414         const EnumDecl * aggr() const override { return base; }
    415 
    416         const Type * accept( Visitor & v ) const override { return v.visit( this ); }
    417 private:
    418         EnumInstType * clone() const override { return new EnumInstType{ *this }; }
    419         MUTATE_FRIEND
    420 };
    421 
    422 /// instance of trait type
     372        const decl_t * aggr() const override { return base; }
     373
     374        const Type * accept( Visitor & v ) const override { return v.visit( this ); }
     375private:
     376        SueInstType<decl_t> * clone() const override { return new SueInstType<decl_t>{ *this }; }
     377        MUTATE_FRIEND
     378};
     379
     380/// An instance of a struct type.
     381using StructInstType = SueInstType<StructDecl>;
     382
     383/// An instance of a union type.
     384using UnionInstType = SueInstType<UnionDecl>;
     385
     386/// An instance of an enum type.
     387using EnumInstType = SueInstType<EnumDecl>;
     388
     389/// An instance of a trait type.
    423390class TraitInstType final : public ReferenceToType {
    424391public:
Note: See TracChangeset for help on using the changeset viewer.