source: src/SynTree/Statement.h@ 353d168

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 with_gc
Last change on this file since 353d168 was 7f5566b, checked in by Peter A. Buhr <pabuhr@…>, 10 years ago

asm statement, memory leaks

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