source: translator/SynTree/Statement.h @ 5c7fb6c

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 5c7fb6c was c11e31c, checked in by Peter A. Buhr <pabuhr@…>, 9 years ago

add inline and attribute qualifiers, cfa.y comment formatting, fix error message in isIntegralType

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