Changeset 561354f for src/AST/Decl.hpp


Ignore:
Timestamp:
May 17, 2023, 1:33:39 AM (2 years ago)
Author:
JiadaL <j82liang@…>
Branches:
ADT
Children:
d6c464d
Parents:
28f8f15
Message:

Save progress

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/AST/Decl.hpp

    r28f8f15 r561354f  
    248248class AggregateDecl : public Decl {
    249249public:
    250         enum Aggregate { Struct, Union, Enum, Exception, Trait, Generator, Coroutine, Monitor, Thread, NoAggregate, ADT };
     250        enum Aggregate { Struct, Union, Enum, Exception, Trait, Generator, Coroutine, Monitor, Thread, NoAggregate, Adt };
    251251        static const char * aggrString( Aggregate aggr );
    252252
     
    286286        bool is_monitor  () const { return kind == Monitor  ; }
    287287        bool is_thread   () const { return kind == Thread   ; }
    288         bool is_adt              () const { return kind == ADT          ; }
     288        bool is_adt              () const { return kind == Adt          ; }
    289289
    290290        const Decl * accept( Visitor & v ) const override { return v.visit( this ); }
     
    320320        ptr<Type> base; // if isTyped == true && base.get() == nullptr, it is a "void" type enum
    321321        enum class EnumHiding { Visible, Hide } hide;
    322 
    323         std::vector<ptr<StructDecl>> data_constructors;
    324         bool isData = false;
    325         ptr<UnionDecl> data_union;
    326         ptr<EnumDecl> tag;
    327         ptr<StructDecl> tag_union;
    328322
    329323        EnumDecl( const CodeLocation& loc, const std::string& name, bool isTyped = false,
     
    350344};
    351345
     346class AdtDecl final : public AggregateDecl {
     347public:
     348        std::vector<ptr<StructDecl>> data_constructors; // Todo: members?
     349        ptr<UnionDecl> data_union;
     350        ptr<EnumDecl> tag;
     351        ptr<StructDecl> tag_union;
     352
     353        AdtDecl( const CodeLocation& loc, const std::string& name,
     354                std::vector<ptr<Attribute>>&& attrs = {}, Linkage::Spec linkage = Linkage::Cforall )
     355        : AggregateDecl( loc, name, std::move(attrs), linkage ) {}
     356
     357        const Decl * accept( Visitor & v ) const override { return v.visit( this ); }
     358
     359        const char * typeString() const override { return aggrString( Adt ); }
     360
     361private:
     362        AdtDecl * clone() const override { return new AdtDecl{ *this }; }
     363        MUTATE_FRIEND
     364};
     365
    352366/// trait declaration `trait Foo( ... ) { ... };`
    353367class TraitDecl final : public AggregateDecl {
     
    358372
    359373        const Decl * accept( Visitor & v ) const override { return v.visit( this ); }
    360 
    361374        const char * typeString() const override { return "trait"; }
    362375
Note: See TracChangeset for help on using the changeset viewer.