source: src/SynTree/Statement.h@ 6ac5223

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 6ac5223 was 936e9f4, checked in by Peter A. Buhr <pabuhr@…>, 8 years ago

first attempt, add declarations into "if" conditional

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