Changeset 41b24c8


Ignore:
Timestamp:
May 16, 2019, 4:23:47 PM (5 years ago)
Author:
Thierry Delisle <tdelisle@…>
Branches:
ADT, arm-eh, ast-experimental, cleanup-dtors, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, pthread-emulation, qualifiedEnum
Children:
acd80b4
Parents:
e61207e7 (diff), c671112 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge branch 'master' of plg.uwaterloo.ca:software/cfa/cfa-cc

Files:
2 added
8 edited

Legend:

Unmodified
Added
Removed
  • libcfa/src/concurrency/coroutine.hfa

    re61207e7 r41b24c8  
    4949
    5050forall(dtype T | is_coroutine(T))
    51 static inline void resume(T & cor);
     51static inline T & resume(T & cor);
    5252
    5353forall(dtype T | is_coroutine(T))
  • src/AST/Convert.cpp

    re61207e7 r41b24c8  
    135135                decl->parent = parent;
    136136                decl->body   = old->body;
    137                 decl->parameters = params;
     137                decl->params = params;
    138138                decl->members    = members;
    139139                decl->extension  = old->extension;
     
    592592
    593593        }
     594
     595        virtual void visit( AttrExpr * ) override final {
     596
     597                assert( 0 );
     598        }
    594599};
    595600
  • src/AST/Decl.hpp

    re61207e7 r41b24c8  
    3030#include "Parser/ParseNode.h"  // for DeclarationNode::Aggregate
    3131
     32// Must be included in *all* AST classes; should be #undef'd at the end of the file
     33#define MUTATE_FRIEND template<typename node_t> friend node_t * mutate(const node_t * node);
     34
    3235namespace ast {
    3336
     
    5558private:
    5659        Decl * clone() const override = 0;
     60        MUTATE_FRIEND
    5761};
    5862
     
    8791private:
    8892        DeclWithType * clone() const override = 0;
     93        MUTATE_FRIEND
    8994};
    9095
     
    108113private:
    109114        ObjectDecl * clone() const override { return new ObjectDecl{ *this }; }
    110 
    111         /// Must be copied in ALL derived classes
    112         template<typename node_t>
    113         friend node_t * mutate(const node_t * node);
     115        MUTATE_FRIEND
    114116};
    115117
     
    135137private:
    136138        FunctionDecl * clone() const override { return new FunctionDecl( *this ); }
    137 
    138         /// Must be copied in ALL derived classes
    139         template<typename node_t>
    140         friend node_t * mutate(const node_t * node);
     139        MUTATE_FRIEND
    141140};
    142141
     
    157156private:
    158157        NamedTypeDecl* clone() const override = 0;
     158        MUTATE_FRIEND
    159159};
    160160
     
    198198private:
    199199        TypeDecl * clone() const override { return new TypeDecl{ *this }; }
    200 
    201         /// Must be copied in ALL derived classes
    202         template<typename node_t>
    203         friend node_t * mutate(const node_t * node);
     200        MUTATE_FRIEND
    204201};
    205202
     
    216213private:
    217214        TypedefDecl * clone() const override { return new TypedefDecl{ *this }; }
    218 
    219         /// Must be copied in ALL derived classes
    220         template<typename node_t>
    221         friend node_t * mutate(const node_t * node);
     215        MUTATE_FRIEND
    222216};
    223217
     
    238232        AggregateDecl* set_body( bool b ) { body = b; return this; }
    239233
     234private:
     235        AggregateDecl * clone() const override = 0;
     236        MUTATE_FRIEND
     237
    240238protected:
    241239        /// Produces a name for the kind of aggregate
     
    260258private:
    261259        StructDecl * clone() const override { return new StructDecl{ *this }; }
    262 
    263         /// Must be copied in ALL derived classes
    264         template<typename node_t>
    265         friend node_t * mutate(const node_t * node);
     260        MUTATE_FRIEND
    266261
    267262        std::string typeString() const override { return "struct"; }
     
    278273private:
    279274        UnionDecl * clone() const override { return new UnionDecl{ *this }; }
    280 
    281         /// Must be copied in ALL derived classes
    282         template<typename node_t>
    283         friend node_t * mutate(const node_t * node);
     275        MUTATE_FRIEND
    284276
    285277        std::string typeString() const override { return "union"; }
     
    299291private:
    300292        EnumDecl * clone() const override { return new EnumDecl{ *this }; }
    301 
    302         /// Must be copied in ALL derived classes
    303         template<typename node_t>
    304         friend node_t * mutate(const node_t * node);
     293        MUTATE_FRIEND
    305294
    306295        std::string typeString() const override { return "enum"; }
     
    320309private:
    321310        TraitDecl * clone() const override { return new TraitDecl{ *this }; }
    322 
    323         /// Must be copied in ALL derived classes
    324         template<typename node_t>
    325         friend node_t * mutate(const node_t * node);
     311        MUTATE_FRIEND
    326312
    327313        std::string typeString() const override { return "trait"; }
     
    338324private:
    339325        AsmDecl *clone() const override { return new AsmDecl( *this ); }
    340 
    341         /// Must be copied in ALL derived classes
    342         template<typename node_t>
    343         friend node_t * mutate(const node_t * node);
     326        MUTATE_FRIEND
    344327};
    345328
     
    355338private:
    356339        StaticAssertDecl * clone() const override { return new StaticAssertDecl( *this ); }
    357 
    358         /// Must be copied in ALL derived classes
    359         template<typename node_t>
    360         friend node_t * mutate(const node_t * node);
     340        MUTATE_FRIEND
    361341};
    362342
    363343}
     344
     345#undef MUTATE_FRIEND
    364346
    365347// Local Variables: //
  • src/AST/Expr.hpp

    re61207e7 r41b24c8  
    2727#include "Visitor.hpp"
    2828
     29// Must be included in *all* AST classes; should be #undef'd at the end of the file
     30#define MUTATE_FRIEND template<typename node_t> friend auto mutate(const node_t * node);
     31
    2932namespace ast {
    3033
     
    127130private:
    128131        Expr * clone() const override = 0;
     132        MUTATE_FRIEND
    129133};
    130134
     
    141145private:
    142146        ApplicationExpr * clone() const override { return new ApplicationExpr{ *this }; }
     147        MUTATE_FRIEND
    143148};
    144149
     
    160165private:
    161166        UntypedExpr * clone() const override { return new UntypedExpr{ *this }; }
     167        MUTATE_FRIEND
    162168};
    163169
     
    173179private:
    174180        NameExpr * clone() const override { return new NameExpr{ *this }; }
     181        MUTATE_FRIEND
    175182};
    176183
     
    185192private:
    186193        AddressExpr * clone() const override { return new AddressExpr{ *this }; }
     194        MUTATE_FRIEND
    187195};
    188196
     
    198206private:
    199207        LabelAddressExpr * clone() const override { return new LabelAddressExpr{ *this }; }
     208        MUTATE_FRIEND
    200209};
    201210
     
    217226private:
    218227        CastExpr * clone() const override { return new CastExpr{ *this }; }
     228        MUTATE_FRIEND
    219229};
    220230
     
    234244private:
    235245        KeywordCastExpr * clone() const override { return new KeywordCastExpr{ *this }; }
     246        MUTATE_FRIEND
    236247};
    237248
     
    247258private:
    248259        VirtualCastExpr * clone() const override { return new VirtualCastExpr{ *this }; }
     260        MUTATE_FRIEND
    249261};
    250262
     
    261273private:
    262274        UntypedMemberExpr * clone() const override { return new UntypedMemberExpr{ *this }; }
     275        MUTATE_FRIEND
    263276};
    264277
     
    274287private:
    275288        MemberExpr * clone() const override { return new MemberExpr{ *this }; }
     289        MUTATE_FRIEND
    276290};
    277291
     
    289303private:
    290304        VariableExpr * clone() const override { return new VariableExpr{ *this }; }
     305        MUTATE_FRIEND
    291306};
    292307
     
    332347private:
    333348        ConstantExpr * clone() const override { return new ConstantExpr{ *this }; }
     349        MUTATE_FRIEND
    334350};
    335351
     
    347363private:
    348364        SizeofExpr * clone() const override { return new SizeofExpr{ *this }; }
     365        MUTATE_FRIEND
    349366};
    350367
     
    362379private:
    363380        AlignofExpr * clone() const override { return new AlignofExpr{ *this }; }
     381        MUTATE_FRIEND
    364382};
    365383
     
    376394private:
    377395        UntypedOffsetofExpr * clone() const override { return new UntypedOffsetofExpr{ *this }; }
     396        MUTATE_FRIEND
    378397};
    379398
     
    389408private:
    390409        OffsetofExpr * clone() const override { return new OffsetofExpr{ *this }; }
     410        MUTATE_FRIEND
    391411};
    392412
     
    401421private:
    402422        OffsetPackExpr * clone() const override { return new OffsetPackExpr{ *this }; }
     423        MUTATE_FRIEND
    403424};
    404425
     
    418439private:
    419440        LogicalExpr * clone() const override { return new LogicalExpr{ *this }; }
     441        MUTATE_FRIEND
    420442};
    421443
     
    433455private:
    434456        ConditionalExpr * clone() const override { return new ConditionalExpr{ *this }; }
     457        MUTATE_FRIEND
    435458};
    436459
     
    447470private:
    448471        CommaExpr * clone() const override { return new CommaExpr{ *this }; }
     472        MUTATE_FRIEND
    449473};
    450474
     
    459483private:
    460484        TypeExpr * clone() const override { return new TypeExpr{ *this }; }
     485        MUTATE_FRIEND
    461486};
    462487
     
    470495
    471496}
     497
     498#undef MUTATE_FRIEND
    472499
    473500// Local Variables: //
  • src/AST/Init.hpp

    re61207e7 r41b24c8  
    2323#include "Visitor.hpp"
    2424
     25// Must be included in *all* AST classes; should be #undef'd at the end of the file
     26#define MUTATE_FRIEND template<typename node_t> friend node_t * mutate(const node_t * node);
     27
    2528namespace ast {
    2629
     
    4043private:
    4144        Designation* clone() const override { return new Designation{ *this }; }
     45        MUTATE_FRIEND
    4246};
    4347
     
    5559private:
    5660        Init * clone() const override = 0;
     61        MUTATE_FRIEND
    5762};
    5863
     
    6974private:
    7075        SingleInit * clone() const override { return new SingleInit{ *this }; }
    71 
    72         /// Must be copied in ALL derived classes
    73         template<typename node_t>
    74         friend node_t * mutate(const node_t * node);
     76        MUTATE_FRIEND
    7577};
    7678
     
    9799private:
    98100        ListInit * clone() const override { return new ListInit{ *this }; }
    99 
    100         /// Must be copied in ALL derived classes
    101         template<typename node_t>
    102         friend node_t * mutate(const node_t * node);
     101        MUTATE_FRIEND
    103102};
    104103
     
    120119private:
    121120        ConstructorInit * clone() const override { return new ConstructorInit{ *this }; }
    122 
    123         /// Must be copied in ALL derived classes
    124         template<typename node_t>
    125         friend node_t * mutate(const node_t * node);
     121        MUTATE_FRIEND
    126122};
    127123
    128124}
     125
     126#undef MUTATE_FRIEND
    129127
    130128// Local Variables: //
  • src/AST/Pass.impl.hpp

    re61207e7 r41b24c8  
    1919#include <type_traits>
    2020#include <unordered_map>
     21
     22#include "AST/TypeSubstitution.hpp"
    2123
    2224#define VISIT_START( node ) \
  • src/AST/Stmt.hpp

    re61207e7 r41b24c8  
    2626#include "Common/CodeLocation.h"
    2727
     28// Must be included in *all* AST classes; should be #undef'd at the end of the file
     29#define MUTATE_FRIEND template<typename node_t> friend auto mutate(const node_t * node);
     30
    2831namespace ast {
    2932
     
    3538        std::vector<Label> labels;
    3639
    37         Stmt( const CodeLocation& loc, std::vector<Label>&& labels = {} )
     40        Stmt( const CodeLocation & loc, std::vector<Label> && labels = {} )
    3841        : ParseNode(loc), labels(std::move(labels)) {}
    3942
    4043        Stmt(const Stmt& o) : ParseNode(o), labels(o.labels) {}
    4144
    42         const Stmt* accept( Visitor& v ) const override = 0;
    43 private:
    44         Stmt* clone() const override = 0;
     45        const Stmt * accept( Visitor & v ) const override = 0;
     46private:
     47        Stmt * clone() const override = 0;
     48        MUTATE_FRIEND
    4549};
    4650
     
    5054        std::list<ptr<Stmt>> kids;
    5155
    52         CompoundStmt(const CodeLocation& loc, std::list<ptr<Stmt>>&& ks = {} )
     56        CompoundStmt(const CodeLocation & loc, std::list<ptr<Stmt>> && ks = {} )
    5357        : Stmt(loc), kids(std::move(ks)) {}
    5458
     
    5660        CompoundStmt( CompoundStmt&& o ) = default;
    5761
    58         void push_back( Stmt* s ) { kids.emplace_back( s ); }
    59         void push_front( Stmt* s ) { kids.emplace_front( s ); }
    60 
    61         const CompoundStmt* accept( Visitor& v ) const override { return v.visit( this ); }
    62 private:
    63         CompoundStmt* clone() const override { return new CompoundStmt{ *this }; }
    64 
    65         /// Must be copied in ALL derived classes
    66         template<typename node_t>
    67         friend node_t * mutate(const node_t * node);
     62        void push_back( Stmt * s ) { kids.emplace_back( s ); }
     63        void push_front( Stmt * s ) { kids.emplace_front( s ); }
     64
     65        const CompoundStmt * accept( Visitor & v ) const override { return v.visit( this ); }
     66private:
     67        CompoundStmt * clone() const override { return new CompoundStmt{ *this }; }
     68        MUTATE_FRIEND
    6869};
    6970
     
    7172class NullStmt final : public Stmt {
    7273public:
    73         NullStmt( const CodeLocation& loc, std::vector<Label>&& labels = {} )
     74        NullStmt( const CodeLocation & loc, std::vector<Label> && labels = {} )
    7475        : Stmt(loc, std::move(labels)) {}
    7576
    76         const NullStmt* accept( Visitor& v ) const override { return v.visit( this ); }
    77 private:
    78         NullStmt* clone() const override { return new NullStmt{ *this }; }
    79 
    80         /// Must be copied in ALL derived classes
    81         template<typename node_t>
    82         friend node_t * mutate(const node_t * node);
     77        const NullStmt * accept( Visitor & v ) const override { return v.visit( this ); }
     78private:
     79        NullStmt * clone() const override { return new NullStmt{ *this }; }
     80        MUTATE_FRIEND
    8381};
    8482
     
    9088        ExprStmt( const CodeLocation & loc, const Expr * e ) : Stmt(loc), expr(e) {}
    9189
    92         const Stmt * accept( Visitor& v ) const override { return v.visit( this ); }
     90        const Stmt * accept( Visitor & v ) const override { return v.visit( this ); }
    9391private:
    9492        ExprStmt * clone() const override { return new ExprStmt{ *this }; }
    95 
    96         /// Must be copied in ALL derived classes
    97         template<typename node_t>
    98         friend node_t * mutate(const node_t * node);
     93        MUTATE_FRIEND
    9994};
    10095
     
    107102        std::vector<Label> gotoLabels;
    108103
    109         AsmStmt( const CodeLocation& loc, bool isVolatile, const Expr * instruction,
    110                 std::vector<ptr<Expr>>&& output, std::vector<ptr<Expr>>&& input,
    111                 std::vector<ptr<ConstantExpr>>&& clobber, std::vector<Label>&& gotoLabels,
    112                 std::vector<Label>&& labels = {})
     104        AsmStmt( const CodeLocation & loc, bool isVolatile, const Expr * instruction,
     105                std::vector<ptr<Expr>> && output, std::vector<ptr<Expr>> && input,
     106                std::vector<ptr<ConstantExpr>> && clobber, std::vector<Label> && gotoLabels,
     107                std::vector<Label> && labels = {})
    113108        : Stmt(loc, std::move(labels)), isVolatile(isVolatile), instruction(instruction),
    114109          output(std::move(output)), input(std::move(input)), clobber(std::move(clobber)),
    115110          gotoLabels(std::move(gotoLabels)) {}
    116111
    117         const Stmt* accept( Visitor& v ) const override { return v.visit( this ); }
    118 private:
    119         AsmStmt* clone() const override { return new AsmStmt{ *this }; }
    120 
    121         /// Must be copied in ALL derived classes
    122         template<typename node_t>
    123         friend node_t * mutate(const node_t * node);
     112        const Stmt * accept( Visitor & v ) const override { return v.visit( this ); }
     113private:
     114        AsmStmt * clone() const override { return new AsmStmt{ *this }; }
     115        MUTATE_FRIEND
    124116};
    125117
     
    128120        std::string directive;
    129121
    130         DirectiveStmt( const CodeLocation& loc, const std::string & directive,
    131                 std::vector<Label>&& labels = {} )
     122        DirectiveStmt( const CodeLocation & loc, const std::string & directive,
     123                std::vector<Label> && labels = {} )
    132124        : Stmt(loc, std::move(labels)), directive(directive) {}
    133125
    134         const Stmt* accept( Visitor& v ) const override { return v.visit( this ); }
    135 private:
    136         DirectiveStmt* clone() const override { return new DirectiveStmt{ *this }; }
    137 
    138         /// Must be copied in ALL derived classes
    139         template<typename node_t>
    140         friend node_t * mutate(const node_t * node);
     126        const Stmt * accept( Visitor & v ) const override { return v.visit( this ); }
     127private:
     128        DirectiveStmt * clone() const override { return new DirectiveStmt{ *this }; }
     129        MUTATE_FRIEND
    141130};
    142131
     
    148137        std::vector<ptr<Stmt>> inits;
    149138
    150         IfStmt( const CodeLocation& loc, const Expr* cond, const Stmt* thenPart,
    151                 Stmt * const elsePart, std::vector<ptr<Stmt>>&& inits,
    152                 std::vector<Label>&& labels = {} )
     139        IfStmt( const CodeLocation & loc, const Expr * cond, const Stmt * thenPart,
     140                Stmt * const elsePart, std::vector<ptr<Stmt>> && inits,
     141                std::vector<Label> && labels = {} )
    153142        : Stmt(loc, std::move(labels)), cond(cond), thenPart(thenPart), elsePart(elsePart),
    154143          inits(std::move(inits)) {}
    155144
    156         const Stmt* accept( Visitor& v ) const override { return v.visit( this ); }
    157 private:
    158         IfStmt* clone() const override { return new IfStmt{ *this }; }
    159 
    160         /// Must be copied in ALL derived classes
    161         template<typename node_t>
    162         friend node_t * mutate(const node_t * node);
     145        const Stmt * accept( Visitor & v ) const override { return v.visit( this ); }
     146private:
     147        IfStmt * clone() const override { return new IfStmt{ *this }; }
     148        MUTATE_FRIEND
    163149};
    164150
     
    168154        std::vector<ptr<Stmt>> stmts;
    169155
    170         SwitchStmt( const CodeLocation& loc, const Expr* cond, std::vector<ptr<Stmt>>&& stmts,
    171                 std::vector<Label>&& labels = {} )
     156        SwitchStmt( const CodeLocation & loc, const Expr * cond, std::vector<ptr<Stmt>> && stmts,
     157                std::vector<Label> && labels = {} )
    172158        : Stmt(loc, std::move(labels)), cond(cond), stmts(std::move(stmts)) {}
    173159
    174         const Stmt* accept( Visitor& v ) const override { return v.visit( this ); }
    175 private:
    176         SwitchStmt* clone() const override { return new SwitchStmt{ *this }; }
    177 
    178         /// Must be copied in ALL derived classes
    179         template<typename node_t>
    180         friend node_t * mutate(const node_t * node);
     160        const Stmt * accept( Visitor & v ) const override { return v.visit( this ); }
     161private:
     162        SwitchStmt * clone() const override { return new SwitchStmt{ *this }; }
     163        MUTATE_FRIEND
    181164};
    182165
     
    186169        std::vector<ptr<Stmt>> stmts;
    187170
    188     CaseStmt( const CodeLocation& loc, const Expr* cond, std::vector<ptr<Stmt>>&& stmts,
    189         std::vector<Label>&& labels = {} )
    190     : Stmt(loc, std::move(labels)), cond(cond), stmts(std::move(stmts)) {}
     171        CaseStmt( const CodeLocation & loc, const Expr * cond, std::vector<ptr<Stmt>> && stmts,
     172                std::vector<Label> && labels = {} )
     173        : Stmt(loc, std::move(labels)), cond(cond), stmts(std::move(stmts)) {}
    191174
    192175        bool isDefault() { return !cond; }
    193176
    194         const Stmt* accept( Visitor& v ) const override { return v.visit( this ); }
    195 private:
    196         CaseStmt* clone() const override { return new CaseStmt{ *this }; }
    197 
    198         /// Must be copied in ALL derived classes
    199         template<typename node_t>
    200         friend node_t * mutate(const node_t * node);
     177        const Stmt * accept( Visitor & v ) const override { return v.visit( this ); }
     178private:
     179        CaseStmt * clone() const override { return new CaseStmt{ *this }; }
     180        MUTATE_FRIEND
    201181};
    202182
     
    208188        bool isDoWhile;
    209189
    210         WhileStmt( const CodeLocation& loc, const Expr* cond, const Stmt* body,
    211                 std::vector<ptr<Stmt>>&& inits, bool isDoWhile = false, std::vector<Label>&& labels = {} )
     190        WhileStmt( const CodeLocation & loc, const Expr * cond, const Stmt * body,
     191                std::vector<ptr<Stmt>> && inits, bool isDoWhile = false, std::vector<Label> && labels = {} )
    212192        : Stmt(loc, std::move(labels)), cond(cond), body(body), inits(std::move(inits)),
    213193          isDoWhile(isDoWhile) {}
    214194
    215         const Stmt* accept( Visitor& v ) const override { return v.visit( this ); }
    216 private:
    217         WhileStmt* clone() const override { return new WhileStmt{ *this }; }
    218 
    219         /// Must be copied in ALL derived classes
    220         template<typename node_t>
    221         friend node_t * mutate(const node_t * node);
     195        const Stmt * accept( Visitor & v ) const override { return v.visit( this ); }
     196private:
     197        WhileStmt * clone() const override { return new WhileStmt{ *this }; }
     198        MUTATE_FRIEND
    222199};
    223200
     
    229206        ptr<Stmt> body;
    230207
    231         ForStmt( const CodeLocation& loc, std::vector<ptr<Stmt>>&& inits, const Expr* cond,
    232                 const Expr* inc, const Stmt* body, std::vector<Label>&& labels = {} )
     208        ForStmt( const CodeLocation & loc, std::vector<ptr<Stmt>> && inits, const Expr * cond,
     209                const Expr * inc, const Stmt * body, std::vector<Label> && labels = {} )
    233210        : Stmt(loc, std::move(labels)), inits(std::move(inits)), cond(cond), inc(inc),
    234211          body(body) {}
    235212
    236         const Stmt* accept( Visitor& v ) const override { return v.visit( this ); }
    237 private:
    238         ForStmt* clone() const override { return new ForStmt{ *this }; }
    239 
    240         /// Must be copied in ALL derived classes
    241         template<typename node_t>
    242         friend node_t * mutate(const node_t * node);
     213        const Stmt * accept( Visitor & v ) const override { return v.visit( this ); }
     214private:
     215        ForStmt * clone() const override { return new ForStmt{ *this }; }
     216        MUTATE_FRIEND
    243217};
    244218
     
    253227        Kind kind;
    254228
    255         BranchStmt( const CodeLocation& loc, Kind kind, Label target,
    256                 std::vector<Label>&& labels = {} );
    257         BranchStmt( const CodeLocation& loc, const Expr* computedTarget,
    258                 std::vector<Label>&& labels = {} )
     229        BranchStmt( const CodeLocation & loc, Kind kind, Label target,
     230                std::vector<Label> && labels = {} );
     231        BranchStmt( const CodeLocation & loc, const Expr * computedTarget,
     232                std::vector<Label> && labels = {} )
    259233        : Stmt(loc, std::move(labels)), originalTarget(loc), target(loc),
    260234          computedTarget(computedTarget), kind(Goto) {}
     
    262236        const char * kindName() { return kindNames[kind]; }
    263237
    264         const Stmt* accept( Visitor& v ) const override { return v.visit( this ); }
    265 private:
    266         BranchStmt* clone() const override { return new BranchStmt{ *this }; }
    267 
    268         /// Must be copied in ALL derived classes
    269         template<typename node_t>
    270         friend node_t * mutate(const node_t * node);
     238        const Stmt * accept( Visitor & v ) const override { return v.visit( this ); }
     239private:
     240        BranchStmt * clone() const override { return new BranchStmt{ *this }; }
     241        MUTATE_FRIEND
    271242
    272243        static const char * kindNames[kindEnd];
     
    277248        ptr<Expr> expr;
    278249
    279         ReturnStmt( const CodeLocation& loc, const Expr* expr, std::vector<Label>&& labels = {} )
     250        ReturnStmt( const CodeLocation & loc, const Expr * expr, std::vector<Label> && labels = {} )
    280251        : Stmt(loc, std::move(labels)), expr(expr) {}
    281252
    282         const Stmt* accept( Visitor& v ) const override { return v.visit( this ); }
    283 private:
    284         ReturnStmt* clone() const override { return new ReturnStmt{ *this }; }
    285 
    286         /// Must be copied in ALL derived classes
    287         template<typename node_t>
    288         friend node_t * mutate(const node_t * node);
     253        const Stmt * accept( Visitor & v ) const override { return v.visit( this ); }
     254private:
     255        ReturnStmt * clone() const override { return new ReturnStmt{ *this }; }
     256        MUTATE_FRIEND
    289257};
    290258
     
    297265        Kind kind;
    298266
    299         ThrowStmt( const CodeLocation& loc, Kind kind, const Expr* expr, const Expr* target,
    300                 std::vector<Label>&& labels = {} )
     267        ThrowStmt( const CodeLocation & loc, Kind kind, const Expr * expr, const Expr * target,
     268                std::vector<Label> && labels = {} )
    301269        : Stmt(loc, std::move(labels)), expr(expr), target(target), kind(kind) {}
    302270
    303         const Stmt* accept( Visitor& v ) const override { return v.visit( this ); }
    304 private:
    305         ThrowStmt* clone() const override { return new ThrowStmt{ *this }; }
    306 
    307         /// Must be copied in ALL derived classes
    308         template<typename node_t>
    309         friend node_t * mutate(const node_t * node);
     271        const Stmt * accept( Visitor & v ) const override { return v.visit( this ); }
     272private:
     273        ThrowStmt * clone() const override { return new ThrowStmt{ *this }; }
     274        MUTATE_FRIEND
    310275};
    311276
     
    316281        ptr<FinallyStmt> finally;
    317282
    318         TryStmt( const CodeLocation& loc, const CompoundStmt* body,
    319                 std::vector<ptr<CatchStmt>>&& handlers, const FinallyStmt* finally,
    320                 std::vector<Label>&& labels = {} )
     283        TryStmt( const CodeLocation & loc, const CompoundStmt * body,
     284                std::vector<ptr<CatchStmt>> && handlers, const FinallyStmt * finally,
     285                std::vector<Label> && labels = {} )
    321286        : Stmt(loc, std::move(labels)), body(body), handlers(std::move(handlers)), finally(finally) {}
    322287
    323         const Stmt* accept( Visitor& v ) const override { return v.visit( this ); }
    324 private:
    325         TryStmt* clone() const override { return new TryStmt{ *this }; }
    326 
    327         /// Must be copied in ALL derived classes
    328         template<typename node_t>
    329         friend node_t * mutate(const node_t * node);
     288        const Stmt * accept( Visitor & v ) const override { return v.visit( this ); }
     289private:
     290        TryStmt * clone() const override { return new TryStmt{ *this }; }
     291        MUTATE_FRIEND
    330292};
    331293
     
    339301        Kind kind;
    340302
    341         CatchStmt( const CodeLocation& loc, Kind kind, const Decl* decl, const Expr* cond,
    342                 const Stmt* body, std::vector<Label>&& labels = {} )
     303        CatchStmt( const CodeLocation & loc, Kind kind, const Decl * decl, const Expr * cond,
     304                const Stmt * body, std::vector<Label> && labels = {} )
    343305        : Stmt(loc, std::move(labels)), decl(decl), cond(cond), body(body), kind(kind) {}
    344306
    345         const Stmt* accept( Visitor& v ) const override { return v.visit( this ); }
    346 private:
    347         CatchStmt* clone() const override { return new CatchStmt{ *this }; }
    348 
    349         /// Must be copied in ALL derived classes
    350         template<typename node_t>
    351         friend node_t * mutate(const node_t * node);
     307        const Stmt * accept( Visitor & v ) const override { return v.visit( this ); }
     308private:
     309        CatchStmt * clone() const override { return new CatchStmt{ *this }; }
     310        MUTATE_FRIEND
    352311};
    353312
     
    356315        ptr<CompoundStmt> body;
    357316
    358         FinallyStmt( const CodeLocation& loc, const CompoundStmt* body,
    359                 std::vector<Label>&& labels = {} )
     317        FinallyStmt( const CodeLocation & loc, const CompoundStmt * body,
     318                std::vector<Label> && labels = {} )
    360319        : Stmt(loc, std::move(labels)), body(body) {}
    361320
    362         const Stmt* accept( Visitor& v ) const override { return v.visit( this ); }
    363 private:
    364         FinallyStmt* clone() const override { return new FinallyStmt{ *this }; }
    365 
    366         /// Must be copied in ALL derived classes
    367         template<typename node_t>
    368         friend node_t * mutate(const node_t * node);
     321        const Stmt * accept( Visitor & v ) const override { return v.visit( this ); }
     322private:
     323        FinallyStmt * clone() const override { return new FinallyStmt{ *this }; }
     324        MUTATE_FRIEND
    369325};
    370326
     
    397353        OrElse orElse;
    398354
    399         WaitForStmt( const CodeLocation& loc, std::vector<Label>&& labels = {} )
     355        WaitForStmt( const CodeLocation & loc, std::vector<Label> && labels = {} )
    400356        : Stmt(loc, std::move(labels)) {}
    401357
    402         const Stmt* accept( Visitor& v ) const override { return v.visit( this ); }
    403 private:
    404         WaitForStmt* clone() const override { return new WaitForStmt{ *this }; }
    405 
    406         /// Must be copied in ALL derived classes
    407         template<typename node_t>
    408         friend node_t * mutate(const node_t * node);
     358        const Stmt * accept( Visitor & v ) const override { return v.visit( this ); }
     359private:
     360        WaitForStmt * clone() const override { return new WaitForStmt{ *this }; }
     361        MUTATE_FRIEND
    409362};
    410363
     
    414367        ptr<Stmt> stmt;
    415368
    416         WithStmt( const CodeLocation& loc, std::vector<ptr<Expr>>&& exprs, const Stmt* stmt,
    417                 std::vector<Label>&& labels = {} )
     369        WithStmt( const CodeLocation & loc, std::vector<ptr<Expr>> && exprs, const Stmt * stmt,
     370                std::vector<Label> && labels = {} )
    418371        : Stmt(loc, std::move(labels)), exprs(std::move(exprs)), stmt(stmt) {}
    419372
    420         const Stmt* accept( Visitor& v ) const override { return v.visit( this ); }
    421 private:
    422         WithStmt* clone() const override { return new WithStmt{ *this }; }
    423 
    424         /// Must be copied in ALL derived classes
    425         template<typename node_t>
    426         friend node_t * mutate(const node_t * node);
     373        const Stmt * accept( Visitor & v ) const override { return v.visit( this ); }
     374private:
     375        WithStmt * clone() const override { return new WithStmt{ *this }; }
     376        MUTATE_FRIEND
    427377};
    428378
     
    431381        ptr<Decl> decl;
    432382
    433         DeclStmt( const CodeLocation& loc, const Decl* decl, std::vector<Label>&& labels = {} )
     383        DeclStmt( const CodeLocation & loc, const Decl * decl, std::vector<Label> && labels = {} )
    434384        : Stmt(loc, std::move(labels)), decl(decl) {}
    435385
    436         const Stmt* accept( Visitor& v ) const override { return v.visit( this ); }
    437 private:
    438         DeclStmt* clone() const override { return new DeclStmt{ *this }; }
    439 
    440         /// Must be copied in ALL derived classes
    441         template<typename node_t>
    442         friend node_t * mutate(const node_t * node);
     386        const Stmt * accept( Visitor & v ) const override { return v.visit( this ); }
     387private:
     388        DeclStmt * clone() const override { return new DeclStmt{ *this }; }
     389        MUTATE_FRIEND
    443390};
    444391
     
    447394        readonly<Stmt> callStmt;
    448395
    449         ImplicitCtorDtorStmt( const CodeLocation& loc, const Stmt* callStmt,
    450                 std::vector<Label>&& labels = {} )
     396        ImplicitCtorDtorStmt( const CodeLocation & loc, const Stmt * callStmt,
     397                std::vector<Label> && labels = {} )
    451398        : Stmt(loc, std::move(labels)), callStmt(callStmt) {}
    452399
    453         const Stmt* accept( Visitor& v ) const override { return v.visit( this ); }
    454 private:
    455         ImplicitCtorDtorStmt* clone() const override { return new ImplicitCtorDtorStmt{ *this }; }
    456 
    457         /// Must be copied in ALL derived classes
    458         template<typename node_t>
    459         friend node_t * mutate(const node_t * node);
     400        const Stmt * accept( Visitor & v ) const override { return v.visit( this ); }
     401private:
     402        ImplicitCtorDtorStmt * clone() const override { return new ImplicitCtorDtorStmt{ *this }; }
     403        MUTATE_FRIEND
    460404};
    461405
    462406}
     407
     408#undef MUTATE_FRIEND
    463409
    464410// Local Variables: //
  • src/AST/Type.hpp

    re61207e7 r41b24c8  
    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
    3134namespace ast {
    3235
     
    7073private:
    7174        virtual Type * clone() const override = 0;
     75        MUTATE_FRIEND
    7276};
    7377
     
    8488private:
    8589        VoidType * clone() const override { return new VoidType{ *this }; }
     90        MUTATE_FRIEND
    8691};
    8792
     
    146151private:
    147152        BasicType * clone() const override { return new BasicType{ *this }; }
     153        MUTATE_FRIEND
    148154};
    149155
     
    176182private:
    177183        PointerType * clone() const override { return new PointerType{ *this }; }
     184        MUTATE_FRIEND
    178185};
    179186
     
    197204private:
    198205        ArrayType * clone() const override { return new ArrayType{ *this }; }
     206        MUTATE_FRIEND
    199207};
    200208
     
    216224private:
    217225        ReferenceType * clone() const override { return new ReferenceType{ *this }; }
     226        MUTATE_FRIEND
    218227};
    219228
     
    230239private:
    231240        QualifiedType * clone() const override { return new QualifiedType{ *this }; }
     241        MUTATE_FRIEND
    232242};
    233243
     
    245255private:
    246256        virtual ParameterizedType * clone() const override = 0;
     257        MUTATE_FRIEND
    247258};
    248259
     
    274285private:
    275286        FunctionType * clone() const override { return new FunctionType{ *this }; }
     287        MUTATE_FRIEND
    276288};
    277289
     
    295307private:
    296308        virtual ReferenceToType * clone() const override = 0;
     309        MUTATE_FRIEND
    297310
    298311protected:
     
    319332private:
    320333        StructInstType * clone() const override { return new StructInstType{ *this }; }
     334        MUTATE_FRIEND
    321335
    322336        std::string typeString() const override { return "struct"; }
     
    341355private:
    342356        UnionInstType * clone() const override { return new UnionInstType{ *this }; }
     357        MUTATE_FRIEND
    343358
    344359        std::string typeString() const override { return "union"; }
     
    363378private:
    364379        EnumInstType * clone() const override { return new EnumInstType{ *this }; }
     380        MUTATE_FRIEND
    365381
    366382        std::string typeString() const override { return "enum"; }
     
    386402private:
    387403        TraitInstType * clone() const override { return new TraitInstType{ *this }; }
     404        MUTATE_FRIEND
    388405
    389406        std::string typeString() const override { return "trait"; }
     
    414431private:
    415432        TypeInstType * clone() const override { return new TypeInstType{ *this }; }
     433        MUTATE_FRIEND
    416434
    417435        std::string typeString() const override { return "type"; }
     
    442460private:
    443461        TupleType * clone() const override { return new TupleType{ *this }; }
     462        MUTATE_FRIEND
    444463};
    445464
     
    456475private:
    457476        TypeofType * clone() const override { return new TypeofType{ *this }; }
     477        MUTATE_FRIEND
    458478};
    459479
     
    466486private:
    467487        VarArgsType * clone() const override { return new VarArgsType{ *this }; }
     488        MUTATE_FRIEND
    468489};
    469490
     
    476497private:
    477498        ZeroType * clone() const override { return new ZeroType{ *this }; }
     499        MUTATE_FRIEND
    478500};
    479501
     
    486508private:
    487509        OneType * clone() const override { return new OneType{ *this }; }
     510        MUTATE_FRIEND
    488511};
    489512
     
    496519private:
    497520        GlobalScopeType * clone() const override { return new GlobalScopeType{ *this }; }
     521        MUTATE_FRIEND
    498522};
    499523
    500524}
     525
     526#undef MUTATE_FRIEND
    501527
    502528// Local Variables: //
Note: See TracChangeset for help on using the changeset viewer.