source: src/SynTree/Statement.h@ 8b52686

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 8b52686 was f1b1e4c, checked in by Rob Schluntz <rschlunt@…>, 9 years ago

can construct global const objects, except with intrinsic constructors

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