source: src/SynTree/Statement.h@ 5af7306

new-env with_gc
Last change on this file since 5af7306 was 68f9c43, checked in by Aaron Moss <a3moss@…>, 8 years ago

First pass at delete removal

  • Property mode set to 100644
File size: 16.9 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 : Sun Sep 3 20:46:46 2017
13// Update Count : 77
14//
15
16#pragma once
17
18#include <iosfwd> // for ostream
19#include <list> // for list
20#include <memory> // for allocator
21#include <vector> // for vector
22
23#include "BaseSyntaxNode.h" // for BaseSyntaxNode
24#include "Common/SemanticError.h" // for SemanticError
25#include "Label.h" // for Label
26#include "Mutator.h" // for Mutator
27#include "Visitor.h" // for Visitor
28
29class CatchStmt;
30class ConstantExpr;
31class Declaration;
32class Expression;
33class FinallyStmt;
34
35class Statement : public BaseSyntaxNode {
36 public:
37 std::list<Label> labels;
38
39 Statement( const std::list<Label> & labels = {} );
40
41 std::list<Label> & get_labels() { return labels; }
42 const std::list<Label> & get_labels() const { return labels; }
43
44 virtual Statement *clone() const override = 0;
45 virtual void accept( Visitor &v ) override = 0;
46 virtual Statement *acceptMutator( Mutator &m ) override = 0;
47 virtual void print( std::ostream &os, Indenter indent = {} ) const override;
48};
49
50class CompoundStmt : public Statement {
51 public:
52 std::list<Statement*> kids;
53
54 CompoundStmt();
55 CompoundStmt( std::list<Statement *> stmts );
56 CompoundStmt( const CompoundStmt &other );
57
58 std::list<Statement*>& get_kids() { return kids; }
59 void push_back( Statement * stmt ) { kids.push_back( stmt ); }
60 void push_front( Statement * stmt ) { kids.push_front( stmt ); }
61
62 virtual CompoundStmt *clone() const override { return new CompoundStmt( *this ); }
63 virtual void accept( Visitor &v ) override { v.visit( this ); }
64 virtual CompoundStmt *acceptMutator( Mutator &m ) override { return m.mutate( this ); }
65 virtual void print( std::ostream &os, Indenter indent = {} ) const override;
66};
67
68class NullStmt : public Statement {
69 public:
70 NullStmt( const std::list<Label> & labels = {} );
71
72 virtual NullStmt *clone() const override { return new NullStmt( *this ); }
73 virtual void accept( Visitor &v ) override { v.visit( this ); }
74 virtual NullStmt *acceptMutator( Mutator &m ) override { return m.mutate( this ); }
75 virtual void print( std::ostream &os, Indenter indent = {} ) const override;
76};
77
78class ExprStmt : public Statement {
79 public:
80 Expression *expr;
81
82 ExprStmt( Expression *expr );
83 ExprStmt( const ExprStmt &other );
84
85 Expression *get_expr() { return expr; }
86 void set_expr( Expression *newValue ) { expr = newValue; }
87
88 virtual ExprStmt *clone() const override { return new ExprStmt( *this ); }
89 virtual void accept( Visitor &v ) override { v.visit( this ); }
90 virtual Statement *acceptMutator( Mutator &m ) override { return m.mutate( this ); }
91 virtual void print( std::ostream &os, Indenter indent = {} ) const override;
92};
93
94class AsmStmt : public Statement {
95 public:
96 bool voltile;
97 Expression *instruction;
98 std::list<Expression *> output, input;
99 std::list<ConstantExpr *> clobber;
100 std::list<Label> gotolabels;
101
102 AsmStmt( bool voltile, Expression *instruction, std::list<Expression *> output, std::list<Expression *> input, std::list<ConstantExpr *> clobber, std::list<Label> gotolabels );
103 AsmStmt( const AsmStmt &other );
104
105 bool get_voltile() { return voltile; }
106 void set_voltile( bool newValue ) { voltile = newValue; }
107 Expression * get_instruction() { return instruction; }
108 void set_instruction( Expression * newValue ) { instruction = newValue; }
109 std::list<Expression *> & get_output() { return output; }
110 void set_output( const std::list<Expression *> & newValue ) { output = newValue; }
111 std::list<Expression *> & get_input() { return input; }
112 void set_input( const std::list<Expression *> &newValue ) { input = newValue; }
113 std::list<ConstantExpr *> & get_clobber() { return clobber; }
114 void set_clobber( const std::list<ConstantExpr *> &newValue ) { clobber = newValue; }
115 std::list<Label> & get_gotolabels() { return gotolabels; }
116 void set_gotolabels( const std::list<Label> &newValue ) { gotolabels = newValue; }
117
118 virtual AsmStmt * clone() const { return new AsmStmt( *this ); }
119 virtual void accept( Visitor & v ) { v.visit( this ); }
120 virtual Statement * acceptMutator( Mutator & m ) { return m.mutate( this ); }
121 virtual void print( std::ostream & os, Indenter indent = {} ) const;
122};
123
124class IfStmt : public Statement {
125 public:
126 Expression *condition;
127 Statement *thenPart;
128 Statement *elsePart;
129 std::list<Statement *> initialization;
130
131 IfStmt( Expression *condition, Statement *thenPart, Statement *elsePart,
132 std::list<Statement *> initialization = std::list<Statement *>() );
133 IfStmt( const IfStmt &other );
134
135 std::list<Statement *> &get_initialization() { return initialization; }
136 Expression *get_condition() { return condition; }
137 void set_condition( Expression *newValue ) { condition = newValue; }
138 Statement *get_thenPart() { return thenPart; }
139 void set_thenPart( Statement *newValue ) { thenPart = newValue; }
140 Statement *get_elsePart() { return elsePart; }
141 void set_elsePart( Statement *newValue ) { elsePart = newValue; }
142
143 virtual IfStmt *clone() const override { return new IfStmt( *this ); }
144 virtual void accept( Visitor &v ) override { v.visit( this ); }
145 virtual Statement *acceptMutator( Mutator &m ) override { return m.mutate( this ); }
146 virtual void print( std::ostream &os, Indenter indent = {} ) const override;
147};
148
149class SwitchStmt : public Statement {
150 public:
151 Expression * condition;
152 std::list<Statement *> statements;
153
154 SwitchStmt( Expression *condition, const std::list<Statement *> &statements );
155 SwitchStmt( const SwitchStmt &other );
156
157 Expression *get_condition() { return condition; }
158 void set_condition( Expression *newValue ) { condition = newValue; }
159
160 std::list<Statement *> & get_statements() { return statements; }
161
162 virtual void accept( Visitor &v ) override { v.visit( this ); }
163 virtual Statement *acceptMutator( Mutator &m ) override { return m.mutate( this ); }
164
165 virtual SwitchStmt *clone() const override { return new SwitchStmt( *this ); }
166 virtual void print( std::ostream &os, Indenter indent = {} ) const override;
167
168};
169
170class CaseStmt : public Statement {
171 public:
172 Expression * condition;
173 std::list<Statement *> stmts;
174
175 CaseStmt( Expression *conditions, const std::list<Statement *> &stmts, bool isdef = false ) throw (SemanticErrorException);
176 CaseStmt( const CaseStmt &other );
177
178 static CaseStmt * makeDefault( const std::list<Label> & labels = {}, std::list<Statement *> stmts = std::list<Statement *>() );
179
180 bool isDefault() const { return _isDefault; }
181 void set_default(bool b) { _isDefault = b; }
182
183 Expression * &get_condition() { return condition; }
184 void set_condition( Expression *newValue ) { condition = newValue; }
185
186 std::list<Statement *> &get_statements() { return stmts; }
187 void set_statements( std::list<Statement *> &newValue ) { stmts = newValue; }
188
189 virtual void accept( Visitor &v ) override { v.visit( this ); }
190 virtual Statement *acceptMutator( Mutator &m ) override { return m.mutate( this ); }
191
192 virtual CaseStmt *clone() const override { return new CaseStmt( *this ); }
193 virtual void print( std::ostream &os, Indenter indent = {} ) const override;
194 private:
195 bool _isDefault;
196};
197
198class WhileStmt : public Statement {
199 public:
200 Expression *condition;
201 Statement *body;
202 bool isDoWhile;
203
204 WhileStmt( Expression *condition,
205 Statement *body, bool isDoWhile = false );
206 WhileStmt( const WhileStmt &other );
207
208 Expression *get_condition() { return condition; }
209 void set_condition( Expression *newValue ) { condition = newValue; }
210 Statement *get_body() { return body; }
211 void set_body( Statement *newValue ) { body = newValue; }
212 bool get_isDoWhile() { return isDoWhile; }
213 void set_isDoWhile( bool newValue ) { isDoWhile = newValue; }
214
215 virtual WhileStmt *clone() const override { return new WhileStmt( *this ); }
216 virtual void accept( Visitor &v ) override { v.visit( this ); }
217 virtual Statement *acceptMutator( Mutator &m ) override { return m.mutate( this ); }
218 virtual void print( std::ostream &os, Indenter indent = {} ) const override;
219};
220
221class ForStmt : public Statement {
222 public:
223 std::list<Statement *> initialization;
224 Expression *condition;
225 Expression *increment;
226 Statement *body;
227
228 ForStmt( std::list<Statement *> initialization,
229 Expression *condition = 0, Expression *increment = 0, Statement *body = 0 );
230 ForStmt( const ForStmt &other );
231
232 std::list<Statement *> &get_initialization() { return initialization; }
233 Expression *get_condition() { return condition; }
234 void set_condition( Expression *newValue ) { condition = newValue; }
235 Expression *get_increment() { return increment; }
236 void set_increment( Expression *newValue ) { increment = newValue; }
237 Statement *get_body() { return body; }
238 void set_body( Statement *newValue ) { body = newValue; }
239
240 virtual ForStmt *clone() const override { return new ForStmt( *this ); }
241 virtual void accept( Visitor &v ) override { v.visit( this ); }
242 virtual Statement *acceptMutator( Mutator &m ) override { return m.mutate( this ); }
243 virtual void print( std::ostream &os, Indenter indent = {} ) const override;
244};
245
246class BranchStmt : public Statement {
247 public:
248 enum Type { Goto = 0, Break, Continue };
249
250 // originalTarget kept for error messages.
251 const Label originalTarget;
252 Label target;
253 Expression *computedTarget;
254 Type type;
255
256 BranchStmt( Label target, Type ) throw (SemanticErrorException);
257 BranchStmt( Expression *computedTarget, Type ) throw (SemanticErrorException);
258
259 Label get_originalTarget() { return originalTarget; }
260 Label get_target() { return target; }
261 void set_target( Label newValue ) { target = newValue; }
262
263 Expression *get_computedTarget() { return computedTarget; }
264 void set_target( Expression * newValue ) { computedTarget = newValue; }
265
266 Type get_type() { return type; }
267 const char *get_typename() { return brType[ type ]; }
268
269 virtual BranchStmt *clone() const override { return new BranchStmt( *this ); }
270 virtual void accept( Visitor &v ) override { v.visit( this ); }
271 virtual Statement *acceptMutator( Mutator &m ) override { return m.mutate( this ); }
272 virtual void print( std::ostream &os, Indenter indent = {} ) const override;
273 private:
274 static const char *brType[];
275};
276
277class ReturnStmt : public Statement {
278 public:
279 Expression *expr;
280
281 ReturnStmt( Expression *expr );
282 ReturnStmt( const ReturnStmt &other );
283
284 Expression *get_expr() { return expr; }
285 void set_expr( Expression *newValue ) { expr = newValue; }
286
287 virtual ReturnStmt *clone() const override { return new ReturnStmt( *this ); }
288 virtual void accept( Visitor &v ) override { v.visit( this ); }
289 virtual Statement *acceptMutator( Mutator &m ) override { return m.mutate( this ); }
290 virtual void print( std::ostream &os, Indenter indent = {} ) const override;
291};
292
293class ThrowStmt : public Statement {
294 public:
295 enum Kind { Terminate, Resume };
296
297 const Kind kind;
298 Expression * expr;
299 Expression * target;
300
301 ThrowStmt( Kind kind, Expression * expr, Expression * target = nullptr );
302 ThrowStmt( const ThrowStmt &other );
303
304 Kind get_kind() { return kind; }
305 Expression * get_expr() { return expr; }
306 void set_expr( Expression * newExpr ) { expr = newExpr; }
307 Expression * get_target() { return target; }
308 void set_target( Expression * newTarget ) { target = newTarget; }
309
310 virtual ThrowStmt *clone() const override { return new ThrowStmt( *this ); }
311 virtual void accept( Visitor &v ) override { v.visit( this ); }
312 virtual Statement *acceptMutator( Mutator &m ) override { return m.mutate( this ); }
313 virtual void print( std::ostream &os, Indenter indent = {} ) const override;
314};
315
316class TryStmt : public Statement {
317 public:
318 CompoundStmt * block;
319 std::list<CatchStmt *> handlers;
320 FinallyStmt * finallyBlock;
321
322 TryStmt( CompoundStmt *tryBlock, std::list<CatchStmt *> &handlers, FinallyStmt *finallyBlock = 0 );
323 TryStmt( const TryStmt &other );
324
325 CompoundStmt *get_block() const { return block; }
326 void set_block( CompoundStmt *newValue ) { block = newValue; }
327 std::list<CatchStmt *>& get_catchers() { return handlers; }
328
329 FinallyStmt *get_finally() const { return finallyBlock; }
330 void set_finally( FinallyStmt *newValue ) { finallyBlock = newValue; }
331
332 virtual TryStmt *clone() const override { return new TryStmt( *this ); }
333 virtual void accept( Visitor &v ) override { v.visit( this ); }
334 virtual Statement *acceptMutator( Mutator &m ) override { return m.mutate( this ); }
335 virtual void print( std::ostream &os, Indenter indent = {} ) const override;
336};
337
338class CatchStmt : public Statement {
339 public:
340 enum Kind { Terminate, Resume };
341
342 const Kind kind;
343 Declaration *decl;
344 Expression *cond;
345 Statement *body;
346
347 CatchStmt( Kind kind, Declaration *decl,
348 Expression *cond, Statement *body );
349 CatchStmt( const CatchStmt &other );
350
351 Kind get_kind() { return kind; }
352 Declaration *get_decl() { return decl; }
353 void set_decl( Declaration *newValue ) { decl = newValue; }
354 Expression *get_cond() { return cond; }
355 void set_cond( Expression *newCond ) { cond = newCond; }
356 Statement *get_body() { return body; }
357 void set_body( Statement *newValue ) { body = newValue; }
358
359 virtual CatchStmt *clone() const override { return new CatchStmt( *this ); }
360 virtual void accept( Visitor &v ) override { v.visit( this ); }
361 virtual Statement *acceptMutator( Mutator &m ) override { return m.mutate( this ); }
362 virtual void print( std::ostream &os, Indenter indent = {} ) const override;
363};
364
365class FinallyStmt : public Statement {
366 public:
367 CompoundStmt *block;
368
369 FinallyStmt( CompoundStmt *block );
370 FinallyStmt( const FinallyStmt &other );
371
372 CompoundStmt *get_block() const { return block; }
373 void set_block( CompoundStmt *newValue ) { block = newValue; }
374
375 virtual FinallyStmt *clone() const override { return new FinallyStmt( *this ); }
376 virtual void accept( Visitor &v ) override { v.visit( this ); }
377 virtual Statement *acceptMutator( Mutator &m ) override { return m.mutate( this ); }
378 virtual void print( std::ostream &os, Indenter indent = {} ) const override;
379};
380
381class WaitForStmt : public Statement {
382 public:
383
384 struct Target {
385 Expression * function;
386 std::list<Expression * > arguments;
387 };
388
389 struct Clause {
390 Target target;
391 Statement * statement;
392 Expression * condition;
393 };
394
395 WaitForStmt();
396 WaitForStmt( const WaitForStmt & );
397
398 std::vector<Clause> clauses;
399
400 struct {
401 Expression * time;
402 Statement * statement;
403 Expression * condition;
404 } timeout;
405
406 struct {
407 Statement * statement;
408 Expression * condition;
409 } orelse;
410
411 virtual WaitForStmt *clone() const override { return new WaitForStmt( *this ); }
412 virtual void accept( Visitor &v ) override { v.visit( this ); }
413 virtual Statement *acceptMutator( Mutator &m ) override { return m.mutate( this ); }
414 virtual void print( std::ostream &os, Indenter indent = {} ) const override;
415
416};
417
418class WithStmt : public Statement {
419public:
420 std::list< Expression * > exprs;
421 Statement * stmt;
422
423 WithStmt( const std::list< Expression * > & exprs, Statement * stmt );
424 WithStmt( const WithStmt & other );
425
426 virtual WithStmt * clone() const override { return new WithStmt( *this ); }
427 virtual void accept( Visitor & v ) override { v.visit( this ); }
428 virtual Statement * acceptMutator( Mutator & m ) override { return m.mutate( this ); }
429 virtual void print( std::ostream & os, Indenter indent = {} ) const override;
430};
431
432
433// represents a declaration that occurs as part of a compound statement
434class DeclStmt : public Statement {
435 public:
436 Declaration *decl;
437
438 DeclStmt( Declaration *decl );
439 DeclStmt( const DeclStmt &other );
440
441 Declaration *get_decl() const { return decl; }
442 void set_decl( Declaration *newValue ) { decl = newValue; }
443
444 virtual DeclStmt *clone() const override { return new DeclStmt( *this ); }
445 virtual void accept( Visitor &v ) override { v.visit( this ); }
446 virtual Statement *acceptMutator( Mutator &m ) override { return m.mutate( this ); }
447 virtual void print( std::ostream &os, Indenter indent = {} ) const override;
448};
449
450
451/// represents an implicit application of a constructor or destructor. Qualifiers are replaced
452/// immediately before and after the call so that qualified objects can be constructed
453/// with the same functions as unqualified objects.
454class ImplicitCtorDtorStmt : public Statement {
455 public:
456 // Non-owned pointer to the constructor/destructor statement
457 Statement * callStmt;
458
459 ImplicitCtorDtorStmt( Statement * callStmt );
460 ImplicitCtorDtorStmt( const ImplicitCtorDtorStmt & other );
461
462 Statement *get_callStmt() const { return callStmt; }
463 void set_callStmt( Statement * newValue ) { callStmt = newValue; }
464
465 virtual ImplicitCtorDtorStmt *clone() const override { return new ImplicitCtorDtorStmt( *this ); }
466 virtual void accept( Visitor &v ) override { v.visit( this ); }
467 virtual Statement *acceptMutator( Mutator &m ) override { return m.mutate( this ); }
468 virtual void print( std::ostream &os, Indenter indent = {} ) const override;
469};
470
471// Local Variables: //
472// tab-width: 4 //
473// mode: c++ //
474// compile-command: "make install" //
475// End: //
Note: See TracBrowser for help on using the repository browser.