source: translator/SynTree/Statement.h@ 643a2e1

ADT aaron-thesis arm-eh ast-experimental cleanup-dtors ctor deferred_resn demangler enum forall-pointer-decay gc_noraii jacob/cs343-translation jenkins-sandbox memory new-ast new-ast-unique-expr new-env no_list persistent-indexer pthread-emulation qualifiedEnum resolv-new string with_gc
Last change on this file since 643a2e1 was 51b73452, checked in by Peter A. Buhr <pabuhr@…>, 11 years ago

initial commit

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