source: src/SynTree/Statement.h@ 3cd5fdd

ADT arm-eh ast-experimental enum forall-pointer-decay jacob/cs343-translation jenkins-sandbox new-ast new-ast-unique-expr pthread-emulation qualifiedEnum
Last change on this file since 3cd5fdd was 35a2d47, checked in by Peter A. Buhr <pabuhr@…>, 7 years ago

formatting

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