Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/AST/Type.hpp

    rf3cc5b6 r87701b6  
    2929#include "Visitor.hpp"
    3030
    31 // Must be included in *all* AST classes; should be #undef'd at the end of the file
    32 #define MUTATE_FRIEND template<typename node_t> friend auto mutate(const node_t * node);
    33 
    3431namespace ast {
    3532
     
    3734public:
    3835        CV::Qualifiers qualifiers;
    39        
     36
    4037        Type( CV::Qualifiers q = {} ) : qualifiers(q) {}
    4138
     
    7370private:
    7471        virtual Type * clone() const override = 0;
    75         MUTATE_FRIEND
    7672};
    7773
     
    8076public:
    8177        VoidType( CV::Qualifiers q = {} ) : Type( q ) {}
    82        
     78
    8379        unsigned size() const override { return 0; }
    8480        bool isVoid() const override { return true; }
     
    8884private:
    8985        VoidType * clone() const override { return new VoidType{ *this }; }
    90         MUTATE_FRIEND
    9186};
    9287
     
    151146private:
    152147        BasicType * clone() const override { return new BasicType{ *this }; }
    153         MUTATE_FRIEND
    154148};
    155149
     
    171165
    172166        PointerType( const Type * b, CV::Qualifiers q = {} ) : Type(q), base(b), dimension() {}
    173         PointerType( const Type * b, const Expr * d, LengthFlag vl, DimensionFlag s, 
     167        PointerType( const Type * b, const Expr * d, LengthFlag vl, DimensionFlag s,
    174168                CV::Qualifiers q = {} ) : Type(q), base(b), dimension(d), isVarLen(vl), isStatic(s) {}
    175169
     
    182176private:
    183177        PointerType * clone() const override { return new PointerType{ *this }; }
    184         MUTATE_FRIEND
    185178};
    186179
     
    193186        DimensionFlag isStatic;
    194187
    195         ArrayType( const Type * b, const Expr * d, LengthFlag vl, DimensionFlag s, 
     188        ArrayType( const Type * b, const Expr * d, LengthFlag vl, DimensionFlag s,
    196189                CV::Qualifiers q = {} ) : Type(q), base(b), dimension(d), isVarLen(vl), isStatic(s) {}
    197190
     
    204197private:
    205198        ArrayType * clone() const override { return new ArrayType{ *this }; }
    206         MUTATE_FRIEND
    207199};
    208200
     
    224216private:
    225217        ReferenceType * clone() const override { return new ReferenceType{ *this }; }
    226         MUTATE_FRIEND
    227218};
    228219
     
    233224        ptr<Type> child;
    234225
    235         QualifiedType( const Type * p, const Type * c, CV::Qualifiers q = {} ) 
     226        QualifiedType( const Type * p, const Type * c, CV::Qualifiers q = {} )
    236227        : Type(q), parent(p), child(c) {}
    237228
     
    239230private:
    240231        QualifiedType * clone() const override { return new QualifiedType{ *this }; }
    241         MUTATE_FRIEND
    242232};
    243233
     
    249239        ForallList forall;
    250240
    251         ParameterizedType( ForallList&& fs = {}, CV::Qualifiers q = {} ) 
     241        ParameterizedType( ForallList&& fs = {}, CV::Qualifiers q = {} )
    252242        : Type(q), forall(std::move(fs)) {}
    253243        ParameterizedType( CV::Qualifiers q ) : Type(q), forall() {}
     
    255245private:
    256246        virtual ParameterizedType * clone() const override = 0;
    257         MUTATE_FRIEND
    258247};
    259248
     
    267256        std::vector<ptr<DeclWithType>> params;
    268257
    269         /// Does the function accept a variable number of arguments following the arguments specified 
     258        /// Does the function accept a variable number of arguments following the arguments specified
    270259        /// in the parameters list.
    271260        /// This could be because of
     
    285274private:
    286275        FunctionType * clone() const override { return new FunctionType{ *this }; }
    287         MUTATE_FRIEND
    288276};
    289277
     
    296284        bool hoistType = false;
    297285
    298         ReferenceToType( const std::string& n, CV::Qualifiers q = {}, 
     286        ReferenceToType( const std::string& n, CV::Qualifiers q = {},
    299287                std::vector<ptr<Attribute>> && as = {} )
    300288        : ParameterizedType(q), params(), attributes(std::move(as)), name(n) {}
     
    307295private:
    308296        virtual ReferenceToType * clone() const override = 0;
    309         MUTATE_FRIEND
    310297
    311298protected:
     
    319306        readonly<StructDecl> base;
    320307
    321         StructInstType( const std::string& n, CV::Qualifiers q = {}, 
     308        StructInstType( const std::string& n, CV::Qualifiers q = {},
    322309                std::vector<ptr<Attribute>> && as = {} )
    323310        : ReferenceToType( n, q, std::move(as) ), base() {}
    324         StructInstType( const StructDecl * b, CV::Qualifiers q = {}, 
     311        StructInstType( const StructDecl * b, CV::Qualifiers q = {},
    325312                std::vector<ptr<Attribute>> && as = {} );
    326        
     313
    327314        bool isComplete() const override;
    328315
     
    332319private:
    333320        StructInstType * clone() const override { return new StructInstType{ *this }; }
    334         MUTATE_FRIEND
    335321
    336322        std::string typeString() const override { return "struct"; }
     
    342328        readonly<UnionDecl> base;
    343329
    344         UnionInstType( const std::string& n, CV::Qualifiers q = {}, 
     330        UnionInstType( const std::string& n, CV::Qualifiers q = {},
    345331                std::vector<ptr<Attribute>> && as = {} )
    346332        : ReferenceToType( n, q, std::move(as) ), base() {}
    347         UnionInstType( const UnionDecl * b, CV::Qualifiers q = {}, 
     333        UnionInstType( const UnionDecl * b, CV::Qualifiers q = {},
    348334                std::vector<ptr<Attribute>> && as = {} );
    349        
     335
    350336        bool isComplete() const override;
    351337
     
    355341private:
    356342        UnionInstType * clone() const override { return new UnionInstType{ *this }; }
    357         MUTATE_FRIEND
    358343
    359344        std::string typeString() const override { return "union"; }
     
    365350        readonly<EnumDecl> base;
    366351
    367         EnumInstType( const std::string& n, CV::Qualifiers q = {}, 
     352        EnumInstType( const std::string& n, CV::Qualifiers q = {},
    368353                std::vector<ptr<Attribute>> && as = {} )
    369354        : ReferenceToType( n, q, std::move(as) ), base() {}
    370         EnumInstType( const EnumDecl * b, CV::Qualifiers q = {}, 
     355        EnumInstType( const EnumDecl * b, CV::Qualifiers q = {},
    371356                std::vector<ptr<Attribute>> && as = {} );
    372        
     357
    373358        bool isComplete() const override;
    374359
     
    378363private:
    379364        EnumInstType * clone() const override { return new EnumInstType{ *this }; }
    380         MUTATE_FRIEND
    381365
    382366        std::string typeString() const override { return "enum"; }
     
    388372        readonly<TraitDecl> base;
    389373
    390         TraitInstType( const std::string& n, CV::Qualifiers q = {}, 
     374        TraitInstType( const std::string& n, CV::Qualifiers q = {},
    391375                std::vector<ptr<Attribute>> && as = {} )
    392376        : ReferenceToType( n, q, std::move(as) ), base() {}
    393         TraitInstType( const TraitDecl * b, CV::Qualifiers q = {}, 
     377        TraitInstType( const TraitDecl * b, CV::Qualifiers q = {},
    394378                std::vector<ptr<Attribute>> && as = {} );
    395        
     379
    396380        // not meaningful for TraitInstType
    397381        bool isComplete() const override { assert(false); }
     
    402386private:
    403387        TraitInstType * clone() const override { return new TraitInstType{ *this }; }
    404         MUTATE_FRIEND
    405388
    406389        std::string typeString() const override { return "trait"; }
     
    413396        TypeVar::Kind kind;
    414397
    415         TypeInstType( const std::string& n, const TypeDecl * b, CV::Qualifiers q = {}, 
     398        TypeInstType( const std::string& n, const TypeDecl * b, CV::Qualifiers q = {},
    416399                std::vector<ptr<Attribute>> && as = {} )
    417400        : ReferenceToType( n, q, std::move(as) ), base( b ), kind( b->kind ) {}
    418         TypeInstType( const std::string& n, TypeVar::Kind k, CV::Qualifiers q = {}, 
     401        TypeInstType( const std::string& n, TypeVar::Kind k, CV::Qualifiers q = {},
    419402                std::vector<ptr<Attribute>> && as = {} )
    420403        : ReferenceToType( n, q, std::move(as) ), base(), kind( k ) {}
     
    431414private:
    432415        TypeInstType * clone() const override { return new TypeInstType{ *this }; }
    433         MUTATE_FRIEND
    434416
    435417        std::string typeString() const override { return "type"; }
     
    448430        iterator begin() const { return types.begin(); }
    449431        iterator end() const { return types.end(); }
    450        
     432
    451433        unsigned size() const override { return types.size(); }
    452434
    453435        const Type * getComponent( unsigned i ) override {
    454                 assertf( i < size(), "TupleType::getComponent: index %d must be less than size %d", 
     436                assertf( i < size(), "TupleType::getComponent: index %d must be less than size %d",
    455437                        i, size() );
    456438                return *(begin()+i);
     
    460442private:
    461443        TupleType * clone() const override { return new TupleType{ *this }; }
    462         MUTATE_FRIEND
    463444};
    464445
     
    469450        enum Kind { Typeof, Basetypeof } kind;
    470451
    471         TypeofType( const Expr * e, Kind k = Typeof, CV::Qualifiers q = {} ) 
     452        TypeofType( const Expr * e, Kind k = Typeof, CV::Qualifiers q = {} )
    472453        : Type(q), expr(e), kind(k) {}
    473454
     
    475456private:
    476457        TypeofType * clone() const override { return new TypeofType{ *this }; }
    477         MUTATE_FRIEND
    478458};
    479459
     
    482462public:
    483463        VarArgsType( CV::Qualifiers q = {} ) : Type( q ) {}
    484        
     464
    485465        const Type * accept( Visitor & v ) const override { return v.visit( this ); }
    486466private:
    487467        VarArgsType * clone() const override { return new VarArgsType{ *this }; }
    488         MUTATE_FRIEND
    489468};
    490469
     
    493472public:
    494473        ZeroType( CV::Qualifiers q = {} ) : Type( q ) {}
    495        
     474
    496475        const Type * accept( Visitor & v ) const override { return v.visit( this ); }
    497476private:
    498477        ZeroType * clone() const override { return new ZeroType{ *this }; }
    499         MUTATE_FRIEND
    500478};
    501479
     
    508486private:
    509487        OneType * clone() const override { return new OneType{ *this }; }
    510         MUTATE_FRIEND
    511488};
    512489
     
    519496private:
    520497        GlobalScopeType * clone() const override { return new GlobalScopeType{ *this }; }
    521         MUTATE_FRIEND
    522 };
    523 
    524 //=================================================================================================
    525 /// This disgusting and giant piece of boiler-plate is here to solve a cyclic dependency
    526 /// remove only if there is a better solution.
    527 /// The problem is that ast::ptr< ... > uses increment/decrement which won't work well with
    528 /// forward declarations
    529 inline void increment( const class Type * node, Node::ref_type ref ) { node->increment( ref ); }
    530 inline void decrement( const class Type * node, Node::ref_type ref ) { node->decrement( ref ); }
    531 inline void increment( const class VoidType * node, Node::ref_type ref ) { node->increment( ref ); }
    532 inline void decrement( const class VoidType * node, Node::ref_type ref ) { node->decrement( ref ); }
    533 inline void increment( const class BasicType * node, Node::ref_type ref ) { node->increment( ref ); }
    534 inline void decrement( const class BasicType * node, Node::ref_type ref ) { node->decrement( ref ); }
    535 inline void increment( const class PointerType * node, Node::ref_type ref ) { node->increment( ref ); }
    536 inline void decrement( const class PointerType * node, Node::ref_type ref ) { node->decrement( ref ); }
    537 inline void increment( const class ArrayType * node, Node::ref_type ref ) { node->increment( ref ); }
    538 inline void decrement( const class ArrayType * node, Node::ref_type ref ) { node->decrement( ref ); }
    539 inline void increment( const class ReferenceType * node, Node::ref_type ref ) { node->increment( ref ); }
    540 inline void decrement( const class ReferenceType * node, Node::ref_type ref ) { node->decrement( ref ); }
    541 inline void increment( const class QualifiedType * node, Node::ref_type ref ) { node->increment( ref ); }
    542 inline void decrement( const class QualifiedType * node, Node::ref_type ref ) { node->decrement( ref ); }
    543 inline void increment( const class FunctionType * node, Node::ref_type ref ) { node->increment( ref ); }
    544 inline void decrement( const class FunctionType * node, Node::ref_type ref ) { node->decrement( ref ); }
    545 inline void increment( const class ReferenceToType * node, Node::ref_type ref ) { node->increment( ref ); }
    546 inline void decrement( const class ReferenceToType * node, Node::ref_type ref ) { node->decrement( ref ); }
    547 inline void increment( const class StructInstType * node, Node::ref_type ref ) { node->increment( ref ); }
    548 inline void decrement( const class StructInstType * node, Node::ref_type ref ) { node->decrement( ref ); }
    549 inline void increment( const class UnionInstType * node, Node::ref_type ref ) { node->increment( ref ); }
    550 inline void decrement( const class UnionInstType * node, Node::ref_type ref ) { node->decrement( ref ); }
    551 inline void increment( const class EnumInstType * node, Node::ref_type ref ) { node->increment( ref ); }
    552 inline void decrement( const class EnumInstType * node, Node::ref_type ref ) { node->decrement( ref ); }
    553 inline void increment( const class TraitInstType * node, Node::ref_type ref ) { node->increment( ref ); }
    554 inline void decrement( const class TraitInstType * node, Node::ref_type ref ) { node->decrement( ref ); }
    555 inline void increment( const class TypeInstType * node, Node::ref_type ref ) { node->increment( ref ); }
    556 inline void decrement( const class TypeInstType * node, Node::ref_type ref ) { node->decrement( ref ); }
    557 inline void increment( const class TupleType * node, Node::ref_type ref ) { node->increment( ref ); }
    558 inline void decrement( const class TupleType * node, Node::ref_type ref ) { node->decrement( ref ); }
    559 inline void increment( const class TypeofType * node, Node::ref_type ref ) { node->increment( ref ); }
    560 inline void decrement( const class TypeofType * node, Node::ref_type ref ) { node->decrement( ref ); }
    561 inline void increment( const class VarArgsType * node, Node::ref_type ref ) { node->increment( ref ); }
    562 inline void decrement( const class VarArgsType * node, Node::ref_type ref ) { node->decrement( ref ); }
    563 inline void increment( const class ZeroType * node, Node::ref_type ref ) { node->increment( ref ); }
    564 inline void decrement( const class ZeroType * node, Node::ref_type ref ) { node->decrement( ref ); }
    565 inline void increment( const class OneType * node, Node::ref_type ref ) { node->increment( ref ); }
    566 inline void decrement( const class OneType * node, Node::ref_type ref ) { node->decrement( ref ); }
    567 inline void increment( const class GlobalScopeType * node, Node::ref_type ref ) { node->increment( ref ); }
    568 inline void decrement( const class GlobalScopeType * node, Node::ref_type ref ) { node->decrement( ref ); }
     498};
    569499
    570500}
    571 
    572 #undef MUTATE_FRIEND
    573501
    574502// Local Variables: //
Note: See TracChangeset for help on using the changeset viewer.