Changeset 204358b for src/AST/Stmt.hpp


Ignore:
Timestamp:
May 16, 2019, 2:57:41 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:
b336af9
Parents:
10248ae0 (diff), f3cc5b6 (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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/AST/Stmt.hpp

    r10248ae0 r204358b  
    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 auto 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 auto 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 auto 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 auto 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 auto 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 auto 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 auto 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 auto 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 auto 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 auto 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 auto 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 auto 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 auto 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 auto 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 auto 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 auto 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 auto 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 auto 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 auto 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 auto 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
     
    510454}
    511455
     456#undef MUTATE_FRIEND
     457
    512458// Local Variables: //
    513459// tab-width: 4 //
Note: See TracChangeset for help on using the changeset viewer.