Changeset 923d25a for src


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.

Location:
src/AST
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • src/AST/Fwd.hpp

    ra8ed717 r923d25a  
    1010// Created On       : Wed May  8 16:05:00 2019
    1111// Last Modified By : Andrew Beach
    12 // Last Modified On : Mon Jun 24 09:48:00 2019
    13 // Update Count     : 1
     12// Last Modified On : Thr Jul 23 14:15:00 2020
     13// Update Count     : 2
    1414//
    1515
     
    108108class FunctionType;
    109109class ReferenceToType;
    110 class StructInstType;
    111 class UnionInstType;
    112 class EnumInstType;
     110template<typename decl_t> class SueInstType;
     111using StructInstType = SueInstType<StructDecl>;
     112using UnionInstType = SueInstType<UnionDecl>;
     113using EnumInstType = SueInstType<EnumDecl>;
    113114class TraitInstType;
    114115class TypeInstType;
  • src/AST/Type.cpp

    ra8ed717 r923d25a  
    99// Author           : Aaron B. Moss
    1010// Created On       : Mon May 13 15:00:00 2019
    11 // Last Modified By : Peter A. Buhr
    12 // Last Modified On : Sun Dec 15 16:56:28 2019
    13 // Update Count     : 4
     11// Last Modified By : Andrew Beach
     12// Last Modified On : Thu Jul 23 14:16:00 2020
     13// Update Count     : 5
    1414//
    1515
     
    148148}
    149149
    150 // --- StructInstType
    151 
    152 StructInstType::StructInstType(
    153         const StructDecl * b, CV::Qualifiers q, std::vector<ptr<Attribute>>&& as )
     150// --- SueInstType (StructInstType, UnionInstType, EnumInstType)
     151
     152template<typename decl_t>
     153SueInstType<decl_t>::SueInstType(
     154        const decl_t * b, CV::Qualifiers q, std::vector<ptr<Attribute>>&& as )
    154155: ReferenceToType( b->name, q, move(as) ), base( b ) {}
    155156
    156 bool StructInstType::isComplete() const { return base ? base->body : false; }
    157 
    158 // --- UnionInstType
    159 
    160 UnionInstType::UnionInstType(
    161         const UnionDecl * b, CV::Qualifiers q, std::vector<ptr<Attribute>>&& as )
    162 : ReferenceToType( b->name, q, move(as) ), base( b ) {}
    163 
    164 bool UnionInstType::isComplete() const { return base ? base->body : false; }
    165 
    166 // --- EnumInstType
    167 
    168 EnumInstType::EnumInstType(
    169         const EnumDecl * b, CV::Qualifiers q, std::vector<ptr<Attribute>>&& as )
    170 : ReferenceToType( b->name, q, move(as) ), base( b ) {}
    171 
    172 bool EnumInstType::isComplete() const { return base ? base->body : false; }
     157template<typename decl_t>
     158bool SueInstType<decl_t>::isComplete() const {
     159        return base ? base->body : false;
     160}
     161
     162template class SueInstType<StructDecl>;
     163template class SueInstType<UnionDecl>;
     164template class SueInstType<EnumDecl>;
    173165
    174166// --- TraitInstType
  • 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.