source: src/SynTree/Statement.h @ 843054c2

ADTaaron-thesisarm-ehast-experimentalcleanup-dtorsctordeferred_resndemanglerenumforall-pointer-decaygc_noraiijacob/cs343-translationjenkins-sandboxmemorynew-astnew-ast-unique-exprnew-envno_listpersistent-indexerpthread-emulationqualifiedEnumresolv-newstringwith_gc
Last change on this file since 843054c2 was 843054c2, checked in by Peter A. Buhr <pabuhr@…>, 9 years ago

licencing: seventh groups of files

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