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

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 5aa708c was 145f1fc, checked in by Rob Schluntz <rschlunt@…>, 10 years ago

modified ForStmt to have a list of statements for the initialization portion, and reverted to hoisting the initialization

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