source: src/SynTree/Statement.h @ 7a69460

ADTaaron-thesisarm-ehast-experimentalcleanup-dtorsctordeferred_resndemanglerenumforall-pointer-decaygc_noraiijacob/cs343-translationjenkins-sandboxmemorynew-astnew-ast-unique-exprnew-envno_listpersistent-indexerpthread-emulationqualifiedEnumresolv-newwith_gc
Last change on this file since 7a69460 was 3be261a, checked in by Rob Schluntz <rschlunt@…>, 8 years ago

added copy constructors and destructors to many types that were missing them

  • Property mode set to 100644
File size: 14.5 KB
Line 
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//
7// Statement.h --
8//
9// Author           : Richard C. Bilson
10// Created On       : Mon May 18 07:44:20 2015
11// Last Modified By : Rob Schluntz
12// Last Modified On : Wed Dec 09 14:09:24 2015
13// Update Count     : 46
14//
15
16#ifndef STATEMENT_H
17#define STATEMENT_H
18
19#include "SynTree.h"
20#include "Visitor.h"
21#include "Mutator.h"
22#include "Common/SemanticError.h"
23
24class Statement {
25  public:
26        Statement( std::list<Label> labels );
27        virtual ~Statement();
28
29        std::list<Label> & get_labels() { return labels; }
30        const std::list<Label> & get_labels() const { return labels; }
31
32        virtual Statement *clone() const = 0;
33        virtual void accept( Visitor &v ) = 0;
34        virtual Statement *acceptMutator( Mutator &m ) = 0;
35        virtual void print( std::ostream &os, int indent = 0 ) const;
36  protected:
37        std::list<Label> labels;
38};
39
40class CompoundStmt : public Statement {
41  public:
42        CompoundStmt( std::list<Label> labels );
43        CompoundStmt( const CompoundStmt &other );
44        virtual ~CompoundStmt();
45
46        std::list<Statement*>& get_kids() { return kids; }
47
48        virtual CompoundStmt *clone() const { return new CompoundStmt( *this ); }
49        virtual void accept( Visitor &v ) { v.visit( this ); }
50        virtual CompoundStmt *acceptMutator( Mutator &m ) { return m.mutate( this ); }
51        virtual void print( std::ostream &os, int indent = 0 ) const;
52  private:
53        std::list<Statement*> kids;
54};
55
56class ExprStmt : public Statement {
57  public:
58        ExprStmt( std::list<Label> labels, Expression *expr );
59        ExprStmt( const ExprStmt &other );
60        virtual ~ExprStmt();
61
62        Expression *get_expr() { return expr; }
63        void set_expr( Expression *newValue ) { expr = newValue; }
64
65        virtual ExprStmt *clone() const { return new ExprStmt( *this ); }
66        virtual void accept( Visitor &v ) { v.visit( this ); }
67        virtual Statement *acceptMutator( Mutator &m ) { return m.mutate( this ); }
68        virtual void print( std::ostream &os, int indent = 0 ) const;
69  private:
70        Expression *expr;
71};
72
73class AsmStmt : public Statement {
74  public:
75        AsmStmt( std::list<Label> labels, bool voltile, ConstantExpr *instruction, std::list<Expression *> input, std::list<Expression *> output, std::list<ConstantExpr *> clobber, std::list<Label> gotolabels );
76        AsmStmt( const AsmStmt &other );
77        virtual ~AsmStmt();
78
79        bool get_voltile() { return voltile; }
80        void set_voltile( bool newValue ) { voltile = newValue; }
81        ConstantExpr *get_instruction() { return instruction; }
82        void set_instruction( ConstantExpr *newValue ) { instruction = newValue; }
83        std::list<Expression *> &get_output() { return output; }
84        void set_output( const std::list<Expression *> &newValue ) { output = newValue; }
85        std::list<Expression *> &get_input() { return input; }
86        void set_input( const std::list<Expression *> &newValue ) { input = newValue; }
87        std::list<ConstantExpr *> &get_clobber() { return clobber; }
88        void set_clobber( const std::list<ConstantExpr *> &newValue ) { clobber = newValue; }
89        std::list<Label> &get_gotolabels() { return gotolabels; }
90        void set_gotolabels( const std::list<Label> &newValue ) { gotolabels = newValue; }
91
92        virtual AsmStmt *clone() const { return new AsmStmt( *this ); }
93        virtual void accept( Visitor &v ) { v.visit( this ); }
94        virtual Statement *acceptMutator( Mutator &m ) { return m.mutate( this ); }
95        virtual void print( std::ostream &os, int indent = 0 ) const;
96  private:
97        bool voltile;
98        ConstantExpr *instruction;
99        std::list<Expression *> output, input;
100        std::list<ConstantExpr *> clobber;
101        std::list<Label> gotolabels;
102};
103
104class IfStmt : public Statement {
105  public:
106        IfStmt( std::list<Label> labels, Expression *condition, Statement *thenPart, Statement *elsePart );
107        IfStmt( const IfStmt &other );
108        virtual ~IfStmt();
109
110        Expression *get_condition() { return condition; }
111        void set_condition( Expression *newValue ) { condition = newValue; }
112        Statement *get_thenPart() { return thenPart; }
113        void set_thenPart( Statement *newValue ) { thenPart = newValue; }
114        Statement *get_elsePart() { return elsePart; }
115        void set_elsePart( Statement *newValue ) { elsePart = newValue; }
116
117        virtual IfStmt *clone() const { return new IfStmt( *this ); }
118        virtual void accept( Visitor &v ) { v.visit( this ); }
119        virtual Statement *acceptMutator( Mutator &m ) { return m.mutate( this ); }
120        virtual void print( std::ostream &os, int indent = 0 ) const;
121  private:
122        Expression *condition;
123        Statement *thenPart;
124        Statement *elsePart;
125};
126
127class SwitchStmt : public Statement {
128  public:
129        SwitchStmt( std::list<Label> labels, Expression *condition, std::list<Statement *> &branches );
130        SwitchStmt( const SwitchStmt &other );
131        virtual ~SwitchStmt();
132
133        Expression *get_condition() { return condition; }
134        void set_condition( Expression *newValue ) { condition = newValue; }
135
136        std::list<Statement *> & get_branches() { return branches; }
137        void add_case( CaseStmt * );
138
139        virtual void accept( Visitor &v ) { v.visit( this ); }
140        virtual Statement *acceptMutator( Mutator &m ) { return m.mutate( this ); }
141
142        virtual SwitchStmt *clone() const { return new SwitchStmt( *this ); }
143        virtual void print( std::ostream &os, int indent = 0 ) const;
144  private:
145        Expression * condition;
146        std::list<Statement *> branches; // should be list of CaseStmt
147};
148
149class ChooseStmt : public Statement {
150  public:
151        ChooseStmt( std::list<Label> labels, Expression *condition, std::list<Statement *> &branches );
152        ChooseStmt( const ChooseStmt &other );
153        virtual ~ChooseStmt();
154
155        Expression *get_condition() { return condition; }
156        void set_condition( Expression *newValue ) { condition = newValue; }
157
158        std::list<Statement *>& get_branches() { return branches; }
159        void add_case( CaseStmt * );
160
161        virtual void accept( Visitor &v ) { v.visit( this ); }
162        virtual Statement *acceptMutator( Mutator &m ) { return m.mutate( this ); }
163
164        virtual ChooseStmt *clone() const { return new ChooseStmt( *this ); }
165        virtual void print( std::ostream &os, int indent = 0 ) const;
166  private:
167        Expression *condition;
168        std::list<Statement *> branches; // should be list of CaseStmt
169};
170
171class FallthruStmt : public Statement {
172  public:
173        FallthruStmt( std::list<Label> labels ) : Statement( labels ) { }
174
175        virtual void accept( Visitor &v ) { v.visit( this ); }
176        virtual Statement *acceptMutator( Mutator &m ) { return m.mutate( this ); }
177
178        virtual FallthruStmt *clone() const { return new FallthruStmt( *this ); }
179        virtual void print( std::ostream &os, int indent = 0 ) const;
180};
181
182class CaseStmt : public Statement {
183  public:
184        CaseStmt( std::list<Label> labels, Expression *conditions,
185              std::list<Statement *> &stmts, bool isdef = false ) throw(SemanticError);
186        CaseStmt( const CaseStmt &other );
187        virtual ~CaseStmt();
188
189        static CaseStmt * makeDefault( std::list<Label> labels = std::list<Label>(),
190                std::list<Statement *> stmts = std::list<Statement *>() );
191
192        bool isDefault() const { return _isDefault; }
193        void set_default(bool b) { _isDefault = b; }
194
195        Expression * &get_condition() { return condition; }
196        void set_condition( Expression *newValue ) { condition = newValue; }
197
198        std::list<Statement *> &get_statements() { return stmts; }
199        void set_statements( std::list<Statement *> &newValue ) { stmts = newValue; }
200
201        virtual void accept( Visitor &v ) { v.visit( this ); }
202        virtual Statement *acceptMutator( Mutator &m ) { return m.mutate( this ); }
203
204        virtual CaseStmt *clone() const { return new CaseStmt( *this ); }
205        virtual void print( std::ostream &os, int indent = 0 ) const;
206  private:
207        Expression * condition;
208        std::list<Statement *> stmts;
209        bool _isDefault;
210};
211
212class WhileStmt : public Statement {
213  public:
214        WhileStmt( std::list<Label> labels, Expression *condition,
215               Statement *body, bool isDoWhile = false );
216        WhileStmt( const WhileStmt &other );
217        virtual ~WhileStmt();
218
219        Expression *get_condition() { return condition; }
220        void set_condition( Expression *newValue ) { condition = newValue; }
221        Statement *get_body() { return body; }
222        void set_body( Statement *newValue ) { body = newValue; }
223        bool get_isDoWhile() { return isDoWhile; }
224        void set_isDoWhile( bool newValue ) { isDoWhile = newValue; }
225
226        virtual WhileStmt *clone() const { return new WhileStmt( *this ); }
227        virtual void accept( Visitor &v ) { v.visit( this ); }
228        virtual Statement *acceptMutator( Mutator &m ) { return m.mutate( this ); }
229        virtual void print( std::ostream &os, int indent = 0 ) const;
230  private:
231        Expression *condition;
232        Statement *body;
233        bool isDoWhile;
234};
235
236class ForStmt : public Statement {
237  public:
238        ForStmt( std::list<Label> labels, std::list<Statement *> initialization,
239             Expression *condition = 0, Expression *increment = 0, Statement *body = 0 );
240        ForStmt( const ForStmt &other );
241        virtual ~ForStmt();
242
243        std::list<Statement *> &get_initialization() { return initialization; }
244        void set_initialization( std::list<Statement *> newValue ) { initialization = newValue; }
245        Expression *get_condition() { return condition; }
246        void set_condition( Expression *newValue ) { condition = newValue; }
247        Expression *get_increment() { return increment; }
248        void set_increment( Expression *newValue ) { increment = newValue; }
249        Statement *get_body() { return body; }
250        void set_body( Statement *newValue ) { body = newValue; }
251
252        virtual ForStmt *clone() const { return new ForStmt( *this ); }
253        virtual void accept( Visitor &v ) { v.visit( this ); }
254        virtual Statement *acceptMutator( Mutator &m ) { return m.mutate( this ); }
255        virtual void print( std::ostream &os, int indent = 0 ) const;
256  private:
257        std::list<Statement *> initialization;
258        Expression *condition;
259        Expression *increment;
260        Statement *body;
261};
262
263class BranchStmt : public Statement {
264  public:
265        enum Type { Goto = 0, Break, Continue };
266
267        BranchStmt( std::list<Label> labels, Label target, Type ) throw (SemanticError);
268        BranchStmt( std::list<Label> labels, Expression *computedTarget, Type ) throw (SemanticError);
269
270        Label get_originalTarget() { return originalTarget; }
271        Label get_target() { return target; }
272        void set_target( Label newValue ) { target = newValue; }
273
274        Expression *get_computedTarget() { return computedTarget; }
275        void set_target( Expression * newValue ) { computedTarget = newValue; }
276
277        Type get_type() { return type; }
278        const char *get_typename() { return brType[ type ]; }
279
280        virtual BranchStmt *clone() const { return new BranchStmt( *this ); }
281        virtual void accept( Visitor &v ) { v.visit( this ); }
282        virtual Statement *acceptMutator( Mutator &m ) { return m.mutate( this ); }
283        virtual void print( std::ostream &os, int indent = 0 ) const;
284  private:
285        static const char *brType[];
286        Label originalTarget;  // can give better error messages if we remember the label name that the user entered
287        Label target;
288        Expression *computedTarget;
289        Type type;
290};
291
292class ReturnStmt : public Statement {
293  public:
294        ReturnStmt( std::list<Label> labels, Expression *expr, bool throwP = false );
295        ReturnStmt( const ReturnStmt &other );
296        virtual ~ReturnStmt();
297
298        Expression *get_expr() { return expr; }
299        void set_expr( Expression *newValue ) { expr = newValue; }
300
301        virtual ReturnStmt *clone() const { return new ReturnStmt( *this ); }
302        virtual void accept( Visitor &v ) { v.visit( this ); }
303        virtual Statement *acceptMutator( Mutator &m ) { return m.mutate( this ); }
304        virtual void print( std::ostream &os, int indent = 0 ) const;
305  private:
306        Expression *expr;
307        bool isThrow;
308};
309
310
311class NullStmt : public CompoundStmt {
312  public:
313        NullStmt();
314        NullStmt( std::list<Label> labels );
315
316        virtual NullStmt *clone() const { return new NullStmt( *this ); }
317        virtual void accept( Visitor &v ) { v.visit( this ); }
318        virtual NullStmt *acceptMutator( Mutator &m ) { return m.mutate( this ); }
319        virtual void print( std::ostream &os, int indent = 0 ) const;
320
321  private:
322};
323
324class TryStmt : public Statement {
325  public:
326        TryStmt( std::list<Label> labels, CompoundStmt *tryBlock, std::list<Statement *> &handlers, FinallyStmt *finallyBlock = 0 );
327        TryStmt( const TryStmt &other );
328        virtual ~TryStmt();
329
330        CompoundStmt *get_block() const { return block; }
331        void set_block( CompoundStmt *newValue ) { block = newValue; }
332        std::list<Statement *>& get_catchers() { return handlers; }
333
334        FinallyStmt *get_finally() const { return finallyBlock; }
335        void set_finally( FinallyStmt *newValue ) { finallyBlock = newValue; }
336
337        virtual TryStmt *clone() const { return new TryStmt( *this ); }
338        virtual void accept( Visitor &v ) { v.visit( this ); }
339        virtual Statement *acceptMutator( Mutator &m ) { return m.mutate( this ); }
340        virtual void print( std::ostream &os, int indent = 0 ) const;
341
342  private:
343        CompoundStmt *block;
344        std::list<Statement *> handlers;
345        FinallyStmt *finallyBlock;
346};
347
348class CatchStmt : public Statement {
349  public:
350        CatchStmt( std::list<Label> labels, Declaration *decl, Statement *body, bool isCatchRest = false );
351        CatchStmt( const CatchStmt &other );
352        virtual ~CatchStmt();
353
354        Declaration *get_decl() { return decl; }
355        void set_decl( Declaration *newValue ) { decl = newValue; }
356
357        Statement *get_body() { return body; }
358        void set_body( Statement *newValue ) { body = newValue; }
359
360        virtual CatchStmt *clone() const { return new CatchStmt( *this ); }
361        virtual void accept( Visitor &v ) { v.visit( this ); }
362        virtual Statement *acceptMutator( Mutator &m ) { return m.mutate( this ); }
363        virtual void print( std::ostream &os, int indent = 0 ) const;
364
365  private:
366        Declaration *decl;
367        Statement *body;
368        bool catchRest;
369};
370
371class FinallyStmt : public Statement {
372  public:
373        FinallyStmt( std::list<Label> labels, CompoundStmt *block );
374        FinallyStmt( const FinallyStmt &other );
375        virtual ~FinallyStmt();
376
377        CompoundStmt *get_block() const { return block; }
378        void set_block( CompoundStmt *newValue ) { block = newValue; }
379
380        virtual FinallyStmt *clone() const { return new FinallyStmt( *this ); }
381        virtual void accept( Visitor &v ) { v.visit( this ); }
382        virtual Statement *acceptMutator( Mutator &m ) { return m.mutate( this ); }
383        virtual void print( std::ostream &os, int indent = 0 ) const;
384  private:
385        CompoundStmt *block;
386};
387
388
389// represents a declaration that occurs as part of a compound statement
390class DeclStmt : public Statement {
391  public:
392        DeclStmt( std::list<Label> labels, Declaration *decl );
393        DeclStmt( const DeclStmt &other );
394        virtual ~DeclStmt();
395
396        Declaration *get_decl() { return decl; }
397        void set_decl( Declaration *newValue ) { decl = newValue; }
398
399        virtual DeclStmt *clone() const { return new DeclStmt( *this ); }
400        virtual void accept( Visitor &v ) { v.visit( this ); }
401        virtual Statement *acceptMutator( Mutator &m ) { return m.mutate( this ); }
402        virtual void print( std::ostream &os, int indent = 0 ) const;
403  private:
404        Declaration *decl;
405};
406
407std::ostream & operator<<( std::ostream & out, Statement * statement );
408
409#endif // STATEMENT_H
410
411// Local Variables: //
412// tab-width: 4 //
413// mode: c++ //
414// compile-command: "make install" //
415// End: //
Note: See TracBrowser for help on using the repository browser.