source: src/SynTree/Statement.h @ 28f3a19

new-envwith_gc
Last change on this file since 28f3a19 was 28f3a19, checked in by Aaron Moss <a3moss@…>, 6 years ago

Merge branch 'master' into with_gc

  • Property mode set to 100644
File size: 17.4 KB
RevLine 
[0dd3a2f]1//
2// Cforall Version 1.0.0 Copyright (C) 2015 University of Waterloo
3//
4// The contents of this file are covered under the licence agreement in the
5// file "LICENCE" distributed with Cforall.
6//
[3be261a]7// Statement.h --
[0dd3a2f]8//
9// Author           : Richard C. Bilson
10// Created On       : Mon May 18 07:44:20 2015
[936e9f4]11// Last Modified By : Peter A. Buhr
[6a276a0]12// Last Modified On : Thu Mar  8 14:53:02 2018
13// Update Count     : 78
[0dd3a2f]14//
15
[6b0b624]16#pragma once
[51b7345]17
[ea6332d]18#include <iosfwd>                  // for ostream
19#include <list>                    // for list
20#include <memory>                  // for allocator
[135b431]21#include <vector>                        // for vector
[ea6332d]22
23#include "BaseSyntaxNode.h"        // for BaseSyntaxNode
24#include "Common/SemanticError.h"  // for SemanticError
25#include "Label.h"                 // for Label
26#include "Mutator.h"               // for Mutator
27#include "Visitor.h"               // for Visitor
28
29class CatchStmt;
30class ConstantExpr;
31class Declaration;
32class Expression;
33class FinallyStmt;
[51b7345]34
[294647b]35class Statement : public BaseSyntaxNode {
[0dd3a2f]36  public:
[65cdc1e]37        std::list<Label> labels;
38
[ba3706f]39        Statement( const std::list<Label> & labels = {} );
[51b7345]40
[0dd3a2f]41        std::list<Label> & get_labels() { return labels; }
[de62360d]42        const std::list<Label> & get_labels() const { return labels; }
[51b7345]43
[fa16264]44        virtual Statement *clone() const override = 0;
[e149f77]45        virtual void accept( Visitor &v ) override = 0;
[fa16264]46        virtual Statement *acceptMutator( Mutator &m ) override = 0;
[50377a4]47        virtual void print( std::ostream &os, Indenter indent = {} ) const override;
[51b7345]48};
49
[0dd3a2f]50class CompoundStmt : public Statement {
51  public:
[65cdc1e]52        std::list<Statement*> kids;
53
[ba3706f]54        CompoundStmt();
[a2dbad10]55        CompoundStmt( std::list<Statement *> stmts );
[0dd3a2f]56        CompoundStmt( const CompoundStmt &other );
[51b7345]57
[0dd3a2f]58        std::list<Statement*>& get_kids() { return kids; }
[c8dfcd3]59        void push_back( Statement * stmt ) { kids.push_back( stmt ); }
60        void push_front( Statement * stmt ) { kids.push_front( stmt ); }
[51b7345]61
[e149f77]62        virtual CompoundStmt *clone() const override { return new CompoundStmt( *this ); }
63        virtual void accept( Visitor &v ) override { v.visit( this ); }
64        virtual CompoundStmt *acceptMutator( Mutator &m )  override { return m.mutate( this ); }
[50377a4]65        virtual void print( std::ostream &os, Indenter indent = {} ) const override;
[51b7345]66};
67
[70d826cd]68class NullStmt : public Statement {
[daf1af8]69  public:
[ba3706f]70        NullStmt( const std::list<Label> & labels = {} );
[daf1af8]71
[e149f77]72        virtual NullStmt *clone() const override { return new NullStmt( *this ); }
73        virtual void accept( Visitor &v ) override { v.visit( this ); }
74        virtual NullStmt *acceptMutator( Mutator &m )  override { return m.mutate( this ); }
[50377a4]75        virtual void print( std::ostream &os, Indenter indent = {} ) const override;
[daf1af8]76};
77
[0dd3a2f]78class ExprStmt : public Statement {
79  public:
[65cdc1e]80        Expression *expr;
81
[ba3706f]82        ExprStmt( Expression *expr );
[3be261a]83        ExprStmt( const ExprStmt &other );
[51b7345]84
[0dd3a2f]85        Expression *get_expr() { return expr; }
86        void set_expr( Expression *newValue ) { expr = newValue; }
[51b7345]87
[e149f77]88        virtual ExprStmt *clone() const override { return new ExprStmt( *this ); }
89        virtual void accept( Visitor &v ) override { v.visit( this ); }
90        virtual Statement *acceptMutator( Mutator &m )  override { return m.mutate( this ); }
[50377a4]91        virtual void print( std::ostream &os, Indenter indent = {} ) const override;
[0dd3a2f]92};
[51b7345]93
[7f5566b]94class AsmStmt : public Statement {
95  public:
[65cdc1e]96        bool voltile;
[e612146c]97        Expression *instruction;
[65cdc1e]98        std::list<Expression *> output, input;
99        std::list<ConstantExpr *> clobber;
100        std::list<Label> gotolabels;
101
[ba3706f]102        AsmStmt( bool voltile, Expression *instruction, std::list<Expression *> output, std::list<Expression *> input, std::list<ConstantExpr *> clobber, std::list<Label> gotolabels );
[3be261a]103        AsmStmt( const AsmStmt &other );
[7f5566b]104
105        bool get_voltile() { return voltile; }
106        void set_voltile( bool newValue ) { voltile = newValue; }
[e612146c]107        Expression * get_instruction() { return instruction; }
108        void set_instruction( Expression * newValue ) { instruction = newValue; }
109        std::list<Expression *> & get_output() { return output; }
110        void set_output( const std::list<Expression *> & newValue ) { output = newValue; }
111        std::list<Expression *> & get_input() { return input; }
[7f5566b]112        void set_input( const std::list<Expression *> &newValue ) { input = newValue; }
[e612146c]113        std::list<ConstantExpr *> & get_clobber() { return clobber; }
[7f5566b]114        void set_clobber( const std::list<ConstantExpr *> &newValue ) { clobber = newValue; }
[e612146c]115        std::list<Label> & get_gotolabels() { return gotolabels; }
[7f5566b]116        void set_gotolabels( const std::list<Label> &newValue ) { gotolabels = newValue; }
117
[e612146c]118        virtual AsmStmt * clone() const { return new AsmStmt( *this ); }
119        virtual void accept( Visitor & v ) { v.visit( this ); }
120        virtual Statement * acceptMutator( Mutator & m ) { return m.mutate( this ); }
[50377a4]121        virtual void print( std::ostream & os, Indenter indent = {} ) const;
[7f5566b]122};
123
[cc32d83]124class DirectiveStmt : public Statement {
125        public:
126        std::string directive;
127
128        DirectiveStmt( const std::string & );
129        virtual ~DirectiveStmt(){}
130
131        virtual DirectiveStmt * clone() const { return new DirectiveStmt( *this ); }
132        virtual void accept( Visitor & v ) { v.visit( this ); }
133        virtual Statement * acceptMutator( Mutator & m ) { return m.mutate( this ); }
134        virtual void print( std::ostream & os, Indenter indent = {} ) const;
135};
136
[0dd3a2f]137class IfStmt : public Statement {
138  public:
[65cdc1e]139        Expression *condition;
140        Statement *thenPart;
141        Statement *elsePart;
[6d49ea3]142        std::list<Statement *> initialization;
[65cdc1e]143
[ba3706f]144        IfStmt( Expression *condition, Statement *thenPart, Statement *elsePart,
[6d49ea3]145                        std::list<Statement *> initialization = std::list<Statement *>() );
[3be261a]146        IfStmt( const IfStmt &other );
[0dd3a2f]147
[936e9f4]148        std::list<Statement *> &get_initialization() { return initialization; }
[0dd3a2f]149        Expression *get_condition() { return condition; }
150        void set_condition( Expression *newValue ) { condition = newValue; }
151        Statement *get_thenPart() { return thenPart; }
152        void set_thenPart( Statement *newValue ) { thenPart = newValue; }
153        Statement *get_elsePart() { return elsePart; }
154        void set_elsePart( Statement *newValue ) { elsePart = newValue; }
[3be261a]155
[e149f77]156        virtual IfStmt *clone() const override { return new IfStmt( *this ); }
157        virtual void accept( Visitor &v ) override { v.visit( this ); }
158        virtual Statement *acceptMutator( Mutator &m )  override { return m.mutate( this ); }
[50377a4]159        virtual void print( std::ostream &os, Indenter indent = {} ) const override;
[51b7345]160};
161
[0dd3a2f]162class SwitchStmt : public Statement {
163  public:
[65cdc1e]164        Expression * condition;
[871cdb4]165        std::list<Statement *> statements;
[65cdc1e]166
[ba3706f]167        SwitchStmt( Expression *condition, const std::list<Statement *> &statements );
[3be261a]168        SwitchStmt( const SwitchStmt &other );
[51b7345]169
[0dd3a2f]170        Expression *get_condition() { return condition; }
171        void set_condition( Expression *newValue ) { condition = newValue; }
[51b7345]172
[8688ce1]173        std::list<Statement *> & get_statements() { return statements; }
[51b7345]174
[e149f77]175        virtual void accept( Visitor &v ) override { v.visit( this ); }
176        virtual Statement *acceptMutator( Mutator &m )  override { return m.mutate( this ); }
[51b7345]177
[e149f77]178        virtual SwitchStmt *clone() const override { return new SwitchStmt( *this ); }
[50377a4]179        virtual void print( std::ostream &os, Indenter indent = {} ) const override;
[871cdb4]180
[51b7345]181};
182
[0dd3a2f]183class CaseStmt : public Statement {
184  public:
[65cdc1e]185        Expression * condition;
186        std::list<Statement *> stmts;
187
[a16764a6]188        CaseStmt( Expression *conditions, const std::list<Statement *> &stmts, bool isdef = false ) throw (SemanticErrorException);
[3be261a]189        CaseStmt( const CaseStmt &other );
[0dd3a2f]190
[ba3706f]191        static CaseStmt * makeDefault( const std::list<Label> & labels = {}, std::list<Statement *> stmts = std::list<Statement *>() );
[b2152e7a]192
[de62360d]193        bool isDefault() const { return _isDefault; }
[0dd3a2f]194        void set_default(bool b) { _isDefault = b; }
195
196        Expression * &get_condition() { return condition; }
197        void set_condition( Expression *newValue ) { condition = newValue; }
198
199        std::list<Statement *> &get_statements() { return stmts; }
200        void set_statements( std::list<Statement *> &newValue ) { stmts = newValue; }
[3be261a]201
[e149f77]202        virtual void accept( Visitor &v ) override { v.visit( this ); }
203        virtual Statement *acceptMutator( Mutator &m )  override { return m.mutate( this ); }
[0dd3a2f]204
[e149f77]205        virtual CaseStmt *clone() const override { return new CaseStmt( *this ); }
[50377a4]206        virtual void print( std::ostream &os, Indenter indent = {} ) const override;
[0dd3a2f]207  private:
208        bool _isDefault;
[51b7345]209};
210
[0dd3a2f]211class WhileStmt : public Statement {
212  public:
[65cdc1e]213        Expression *condition;
214        Statement *body;
[ee3c93d]215        std::list<Statement *> initialization;
[65cdc1e]216        bool isDoWhile;
217
[ba3706f]218        WhileStmt( Expression *condition,
[ee3c93d]219               Statement *body, std::list<Statement *> & initialization, bool isDoWhile = false );
[3be261a]220        WhileStmt( const WhileStmt &other );
[0dd3a2f]221
222        Expression *get_condition() { return condition; }
223        void set_condition( Expression *newValue ) { condition = newValue; }
224        Statement *get_body() { return body; }
225        void set_body( Statement *newValue ) { body = newValue; }
226        bool get_isDoWhile() { return isDoWhile; }
227        void set_isDoWhile( bool newValue ) { isDoWhile = newValue; }
[3be261a]228
[e149f77]229        virtual WhileStmt *clone() const override { return new WhileStmt( *this ); }
230        virtual void accept( Visitor &v ) override { v.visit( this ); }
231        virtual Statement *acceptMutator( Mutator &m )  override { return m.mutate( this ); }
[50377a4]232        virtual void print( std::ostream &os, Indenter indent = {} ) const override;
[51b7345]233};
234
[0dd3a2f]235class ForStmt : public Statement {
236  public:
[65cdc1e]237        std::list<Statement *> initialization;
238        Expression *condition;
239        Expression *increment;
240        Statement *body;
241
[ba3706f]242        ForStmt( std::list<Statement *> initialization,
[0dd3a2f]243             Expression *condition = 0, Expression *increment = 0, Statement *body = 0 );
[3be261a]244        ForStmt( const ForStmt &other );
[0dd3a2f]245
[145f1fc]246        std::list<Statement *> &get_initialization() { return initialization; }
[0dd3a2f]247        Expression *get_condition() { return condition; }
248        void set_condition( Expression *newValue ) { condition = newValue; }
249        Expression *get_increment() { return increment; }
250        void set_increment( Expression *newValue ) { increment = newValue; }
251        Statement *get_body() { return body; }
252        void set_body( Statement *newValue ) { body = newValue; }
[3be261a]253
[e149f77]254        virtual ForStmt *clone() const override { return new ForStmt( *this ); }
255        virtual void accept( Visitor &v ) override { v.visit( this ); }
256        virtual Statement *acceptMutator( Mutator &m )  override { return m.mutate( this ); }
[50377a4]257        virtual void print( std::ostream &os, Indenter indent = {} ) const override;
[51b7345]258};
259
[0dd3a2f]260class BranchStmt : public Statement {
261  public:
[6a276a0]262        enum Type { Goto = 0, Break, Continue, FallThrough, FallThroughDefault };
[0dd3a2f]263
[65cdc1e]264        // originalTarget kept for error messages.
265        const Label originalTarget;
266        Label target;
267        Expression *computedTarget;
268        Type type;
269
[a16764a6]270        BranchStmt( Label target, Type ) throw (SemanticErrorException);
271        BranchStmt( Expression *computedTarget, Type ) throw (SemanticErrorException);
[0dd3a2f]272
[be5aa1b]273        Label get_originalTarget() { return originalTarget; }
[0dd3a2f]274        Label get_target() { return target; }
275        void set_target( Label newValue ) { target = newValue; }
[3be261a]276
[0dd3a2f]277        Expression *get_computedTarget() { return computedTarget; }
278        void set_target( Expression * newValue ) { computedTarget = newValue; }
279
280        Type get_type() { return type; }
281        const char *get_typename() { return brType[ type ]; }
282
[e149f77]283        virtual BranchStmt *clone() const override { return new BranchStmt( *this ); }
284        virtual void accept( Visitor &v ) override { v.visit( this ); }
285        virtual Statement *acceptMutator( Mutator &m )  override { return m.mutate( this ); }
[50377a4]286        virtual void print( std::ostream &os, Indenter indent = {} ) const override;
[0dd3a2f]287  private:
288        static const char *brType[];
[51b7345]289};
290
[0dd3a2f]291class ReturnStmt : public Statement {
292  public:
[65cdc1e]293        Expression *expr;
294
[ba3706f]295        ReturnStmt( Expression *expr );
[3be261a]296        ReturnStmt( const ReturnStmt &other );
[0dd3a2f]297
298        Expression *get_expr() { return expr; }
299        void set_expr( Expression *newValue ) { expr = newValue; }
[3be261a]300
[e149f77]301        virtual ReturnStmt *clone() const override { return new ReturnStmt( *this ); }
302        virtual void accept( Visitor &v ) override { v.visit( this ); }
303        virtual Statement *acceptMutator( Mutator &m )  override { return m.mutate( this ); }
[50377a4]304        virtual void print( std::ostream &os, Indenter indent = {} ) const override;
[51b7345]305};
306
[daf1af8]307class ThrowStmt : public Statement {
[0dd3a2f]308  public:
[daf1af8]309        enum Kind { Terminate, Resume };
[51b7345]310
[65cdc1e]311        const Kind kind;
312        Expression * expr;
313        Expression * target;
314
[ba3706f]315        ThrowStmt( Kind kind, Expression * expr, Expression * target = nullptr );
[daf1af8]316        ThrowStmt( const ThrowStmt &other );
317
318        Kind get_kind() { return kind; }
319        Expression * get_expr() { return expr; }
320        void set_expr( Expression * newExpr ) { expr = newExpr; }
321        Expression * get_target() { return target; }
322        void set_target( Expression * newTarget ) { target = newTarget; }
323
[e149f77]324        virtual ThrowStmt *clone() const override { return new ThrowStmt( *this ); }
325        virtual void accept( Visitor &v ) override { v.visit( this ); }
326        virtual Statement *acceptMutator( Mutator &m )  override { return m.mutate( this ); }
[50377a4]327        virtual void print( std::ostream &os, Indenter indent = {} ) const override;
[51b7345]328};
329
[3be261a]330class TryStmt : public Statement {
[0dd3a2f]331  public:
[871cdb4]332        CompoundStmt * block;
[65cdc1e]333        std::list<CatchStmt *> handlers;
[871cdb4]334        FinallyStmt * finallyBlock;
[65cdc1e]335
[ba3706f]336        TryStmt( CompoundStmt *tryBlock, std::list<CatchStmt *> &handlers, FinallyStmt *finallyBlock = 0 );
[0dd3a2f]337        TryStmt( const TryStmt &other );
338
339        CompoundStmt *get_block() const { return block; }
340        void set_block( CompoundStmt *newValue ) { block = newValue; }
[046e04a]341        std::list<CatchStmt *>& get_catchers() { return handlers; }
[0dd3a2f]342
343        FinallyStmt *get_finally() const { return finallyBlock; }
344        void set_finally( FinallyStmt *newValue ) { finallyBlock = newValue; }
345
[e149f77]346        virtual TryStmt *clone() const override { return new TryStmt( *this ); }
347        virtual void accept( Visitor &v ) override { v.visit( this ); }
348        virtual Statement *acceptMutator( Mutator &m )  override { return m.mutate( this ); }
[50377a4]349        virtual void print( std::ostream &os, Indenter indent = {} ) const override;
[3be261a]350};
[51b7345]351
[0dd3a2f]352class CatchStmt : public Statement {
353  public:
[ca78437]354        enum Kind { Terminate, Resume };
355
[65cdc1e]356        const Kind kind;
357        Declaration *decl;
358        Expression *cond;
359        Statement *body;
360
[ba3706f]361        CatchStmt( Kind kind, Declaration *decl,
[ca78437]362                   Expression *cond, Statement *body );
[3be261a]363        CatchStmt( const CatchStmt &other );
[0dd3a2f]364
[ca78437]365        Kind get_kind() { return kind; }
[0dd3a2f]366        Declaration *get_decl() { return decl; }
367        void set_decl( Declaration *newValue ) { decl = newValue; }
[ca78437]368        Expression *get_cond() { return cond; }
369        void set_cond( Expression *newCond ) { cond = newCond; }
[0dd3a2f]370        Statement *get_body() { return body; }
371        void set_body( Statement *newValue ) { body = newValue; }
[3be261a]372
[e149f77]373        virtual CatchStmt *clone() const override { return new CatchStmt( *this ); }
374        virtual void accept( Visitor &v ) override { v.visit( this ); }
375        virtual Statement *acceptMutator( Mutator &m )  override { return m.mutate( this ); }
[50377a4]376        virtual void print( std::ostream &os, Indenter indent = {} ) const override;
[51b7345]377};
378
[3be261a]379class FinallyStmt : public Statement {
[0dd3a2f]380  public:
[65cdc1e]381        CompoundStmt *block;
382
[ba3706f]383        FinallyStmt( CompoundStmt *block );
[3be261a]384        FinallyStmt( const FinallyStmt &other );
[0dd3a2f]385
386        CompoundStmt *get_block() const { return block; }
387        void set_block( CompoundStmt *newValue ) { block = newValue; }
[3be261a]388
[e149f77]389        virtual FinallyStmt *clone() const override { return new FinallyStmt( *this ); }
390        virtual void accept( Visitor &v ) override { v.visit( this ); }
391        virtual Statement *acceptMutator( Mutator &m )  override { return m.mutate( this ); }
[50377a4]392        virtual void print( std::ostream &os, Indenter indent = {} ) const override;
[3be261a]393};
[51b7345]394
[135b431]395class WaitForStmt : public Statement {
396  public:
397
398        struct Target {
399                Expression * function;
400                std::list<Expression * > arguments;
401        };
402
403        struct Clause {
404                Target       target;
405                Statement  * statement;
406                Expression * condition;
407        };
408
[ba3706f]409        WaitForStmt();
[135b431]410        WaitForStmt( const WaitForStmt & );
411
412        std::vector<Clause> clauses;
413
414        struct {
415                Expression * time;
416                Statement  * statement;
417                Expression * condition;
418        } timeout;
419
420        struct {
421                Statement  * statement;
422                Expression * condition;
423        } orelse;
424
[e149f77]425        virtual WaitForStmt *clone() const override { return new WaitForStmt( *this ); }
426        virtual void accept( Visitor &v ) override { v.visit( this ); }
427        virtual Statement *acceptMutator( Mutator &m )  override { return m.mutate( this ); }
[50377a4]428        virtual void print( std::ostream &os, Indenter indent = {} ) const override;
[135b431]429
430};
431
[61255ad]432class WithStmt : public Statement {
433public:
434        std::list< Expression * > exprs;
435        Statement * stmt;
436
437        WithStmt( const std::list< Expression * > & exprs, Statement * stmt );
438        WithStmt( const WithStmt & other );
439
440        virtual WithStmt * clone() const override { return new WithStmt( *this ); }
441        virtual void accept( Visitor & v ) override { v.visit( this ); }
442        virtual Statement * acceptMutator( Mutator & m )  override { return m.mutate( this ); }
443        virtual void print( std::ostream & os, Indenter indent = {} ) const override;
444};
445
[51b7345]446
447// represents a declaration that occurs as part of a compound statement
[0dd3a2f]448class DeclStmt : public Statement {
449  public:
[65cdc1e]450        Declaration *decl;
451
[ba3706f]452        DeclStmt( Declaration *decl );
[0dd3a2f]453        DeclStmt( const DeclStmt &other );
454
[f1b1e4c]455        Declaration *get_decl() const { return decl; }
[0dd3a2f]456        void set_decl( Declaration *newValue ) { decl = newValue; }
457
[e149f77]458        virtual DeclStmt *clone() const override { return new DeclStmt( *this ); }
459        virtual void accept( Visitor &v ) override { v.visit( this ); }
460        virtual Statement *acceptMutator( Mutator &m )  override { return m.mutate( this ); }
[50377a4]461        virtual void print( std::ostream &os, Indenter indent = {} ) const override;
[51b7345]462};
463
[f1b1e4c]464
465/// represents an implicit application of a constructor or destructor. Qualifiers are replaced
466/// immediately before and after the call so that qualified objects can be constructed
467/// with the same functions as unqualified objects.
468class ImplicitCtorDtorStmt : public Statement {
469  public:
[65cdc1e]470        // Non-owned pointer to the constructor/destructor statement
471        Statement * callStmt;
472
[f1b1e4c]473        ImplicitCtorDtorStmt( Statement * callStmt );
474        ImplicitCtorDtorStmt( const ImplicitCtorDtorStmt & other );
475
476        Statement *get_callStmt() const { return callStmt; }
477        void set_callStmt( Statement * newValue ) { callStmt = newValue; }
478
[e149f77]479        virtual ImplicitCtorDtorStmt *clone() const override { return new ImplicitCtorDtorStmt( *this ); }
480        virtual void accept( Visitor &v ) override { v.visit( this ); }
481        virtual Statement *acceptMutator( Mutator &m )  override { return m.mutate( this ); }
[50377a4]482        virtual void print( std::ostream &os, Indenter indent = {} ) const override;
[f1b1e4c]483};
484
[0dd3a2f]485// Local Variables: //
486// tab-width: 4 //
487// mode: c++ //
488// compile-command: "make install" //
489// End: //
Note: See TracBrowser for help on using the repository browser.