source: src/SynTree/Statement.h@ ac10576

ADT aaron-thesis arm-eh ast-experimental cleanup-dtors deferred_resn demangler enum forall-pointer-decay jacob/cs343-translation jenkins-sandbox 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 ac10576 was 046e04a, checked in by Andrew Beach <ajbeach@…>, 8 years ago

Now only CatchStmt can be a handler on a TryStmt.

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