source: src/SynTree/Statement.h@ c6c6f2ae

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 c6c6f2ae was ea6332d, checked in by Thierry Delisle <tdelisle@…>, 8 years ago

Big header cleaning pass - commit 3

  • Property mode set to 100644
File size: 15.5 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//
[3be261a]7// Statement.h --
[0dd3a2f]8//
9// Author : Richard C. Bilson
10// Created On : Mon May 18 07:44:20 2015
[65cdc1e]11// Last Modified By : Andrew Beach
12// Last Modified On : Thr Aug 3 14:08:00 2017
13// Update Count : 69
[0dd3a2f]14//
15
[6b0b624]16#pragma once
[51b73452]17
[ea6332d]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;
[51b73452]33
[294647b]34class Statement : public BaseSyntaxNode {
[0dd3a2f]35 public:
[65cdc1e]36 std::list<Label> labels;
37
[0dd3a2f]38 Statement( std::list<Label> labels );
39 virtual ~Statement();
[51b73452]40
[0dd3a2f]41 std::list<Label> & get_labels() { return labels; }
[de62360d]42 const std::list<Label> & get_labels() const { return labels; }
[51b73452]43
[0dd3a2f]44 virtual Statement *clone() const = 0;
45 virtual void accept( Visitor &v ) = 0;
46 virtual Statement *acceptMutator( Mutator &m ) = 0;
[de62360d]47 virtual void print( std::ostream &os, int indent = 0 ) const;
[51b73452]48};
49
[0dd3a2f]50class CompoundStmt : public Statement {
51 public:
[65cdc1e]52 std::list<Statement*> kids;
53
[0dd3a2f]54 CompoundStmt( std::list<Label> labels );
55 CompoundStmt( const CompoundStmt &other );
56 virtual ~CompoundStmt();
[51b73452]57
[0dd3a2f]58 std::list<Statement*>& get_kids() { return kids; }
[c8dfcd3]59 void push_back( Statement * stmt ) { kids.push_back( stmt ); }
60 void push_front( Statement * stmt ) { kids.push_front( stmt ); }
[51b73452]61
[0dd3a2f]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 ); }
[de62360d]65 virtual void print( std::ostream &os, int indent = 0 ) const;
[51b73452]66};
67
[daf1af8]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
[0dd3a2f]79class ExprStmt : public Statement {
80 public:
[65cdc1e]81 Expression *expr;
82
[0dd3a2f]83 ExprStmt( std::list<Label> labels, Expression *expr );
[3be261a]84 ExprStmt( const ExprStmt &other );
[0dd3a2f]85 virtual ~ExprStmt();
[51b73452]86
[0dd3a2f]87 Expression *get_expr() { return expr; }
88 void set_expr( Expression *newValue ) { expr = newValue; }
[51b73452]89
[0dd3a2f]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 ); }
[de62360d]93 virtual void print( std::ostream &os, int indent = 0 ) const;
[0dd3a2f]94};
[51b73452]95
[7f5566b]96class AsmStmt : public Statement {
97 public:
[65cdc1e]98 bool voltile;
99 ConstantExpr *instruction;
100 std::list<Expression *> output, input;
101 std::list<ConstantExpr *> clobber;
102 std::list<Label> gotolabels;
103
[7f5566b]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 );
[3be261a]105 AsmStmt( const AsmStmt &other );
[7f5566b]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
[0dd3a2f]127class IfStmt : public Statement {
128 public:
[65cdc1e]129 Expression *condition;
130 Statement *thenPart;
131 Statement *elsePart;
132
[0dd3a2f]133 IfStmt( std::list<Label> labels, Expression *condition, Statement *thenPart, Statement *elsePart );
[3be261a]134 IfStmt( const IfStmt &other );
[0dd3a2f]135 virtual ~IfStmt();
136
137 Expression *get_condition() { return condition; }
138 void set_condition( Expression *newValue ) { condition = newValue; }
139 Statement *get_thenPart() { return thenPart; }
140 void set_thenPart( Statement *newValue ) { thenPart = newValue; }
141 Statement *get_elsePart() { return elsePart; }
142 void set_elsePart( Statement *newValue ) { elsePart = newValue; }
[3be261a]143
[0dd3a2f]144 virtual IfStmt *clone() const { return new IfStmt( *this ); }
145 virtual void accept( Visitor &v ) { v.visit( this ); }
146 virtual Statement *acceptMutator( Mutator &m ) { return m.mutate( this ); }
[de62360d]147 virtual void print( std::ostream &os, int indent = 0 ) const;
[51b73452]148};
149
[0dd3a2f]150class SwitchStmt : public Statement {
151 public:
[65cdc1e]152 Expression * condition;
153
[8688ce1]154 SwitchStmt( std::list<Label> labels, Expression *condition, std::list<Statement *> &statements );
[3be261a]155 SwitchStmt( const SwitchStmt &other );
[0dd3a2f]156 virtual ~SwitchStmt();
[51b73452]157
[0dd3a2f]158 Expression *get_condition() { return condition; }
159 void set_condition( Expression *newValue ) { condition = newValue; }
[51b73452]160
[8688ce1]161 std::list<Statement *> & get_statements() { return statements; }
[51b73452]162
[0dd3a2f]163 virtual void accept( Visitor &v ) { v.visit( this ); }
164 virtual Statement *acceptMutator( Mutator &m ) { return m.mutate( this ); }
[51b73452]165
[0dd3a2f]166 virtual SwitchStmt *clone() const { return new SwitchStmt( *this ); }
[de62360d]167 virtual void print( std::ostream &os, int indent = 0 ) const;
[0dd3a2f]168 private:
[8688ce1]169 std::list<Statement *> statements;
[51b73452]170};
171
[0dd3a2f]172class CaseStmt : public Statement {
173 public:
[65cdc1e]174 Expression * condition;
175 std::list<Statement *> stmts;
176
[8688ce1]177 CaseStmt( std::list<Label> labels, Expression *conditions, std::list<Statement *> &stmts, bool isdef = false ) throw(SemanticError);
[3be261a]178 CaseStmt( const CaseStmt &other );
[0dd3a2f]179 virtual ~CaseStmt();
180
[8688ce1]181 static CaseStmt * makeDefault( std::list<Label> labels = std::list<Label>(), std::list<Statement *> stmts = std::list<Statement *>() );
[b2152e7a]182
[de62360d]183 bool isDefault() const { return _isDefault; }
[0dd3a2f]184 void set_default(bool b) { _isDefault = b; }
185
186 Expression * &get_condition() { return condition; }
187 void set_condition( Expression *newValue ) { condition = newValue; }
188
189 std::list<Statement *> &get_statements() { return stmts; }
190 void set_statements( std::list<Statement *> &newValue ) { stmts = newValue; }
[3be261a]191
[0dd3a2f]192 virtual void accept( Visitor &v ) { v.visit( this ); }
193 virtual Statement *acceptMutator( Mutator &m ) { return m.mutate( this ); }
194
195 virtual CaseStmt *clone() const { return new CaseStmt( *this ); }
[de62360d]196 virtual void print( std::ostream &os, int indent = 0 ) const;
[0dd3a2f]197 private:
198 bool _isDefault;
[51b73452]199};
200
[0dd3a2f]201class WhileStmt : public Statement {
202 public:
[65cdc1e]203 Expression *condition;
204 Statement *body;
205 bool isDoWhile;
206
[0dd3a2f]207 WhileStmt( std::list<Label> labels, Expression *condition,
208 Statement *body, bool isDoWhile = false );
[3be261a]209 WhileStmt( const WhileStmt &other );
[0dd3a2f]210 virtual ~WhileStmt();
211
212 Expression *get_condition() { return condition; }
213 void set_condition( Expression *newValue ) { condition = newValue; }
214 Statement *get_body() { return body; }
215 void set_body( Statement *newValue ) { body = newValue; }
216 bool get_isDoWhile() { return isDoWhile; }
217 void set_isDoWhile( bool newValue ) { isDoWhile = newValue; }
[3be261a]218
[0dd3a2f]219 virtual WhileStmt *clone() const { return new WhileStmt( *this ); }
220 virtual void accept( Visitor &v ) { v.visit( this ); }
221 virtual Statement *acceptMutator( Mutator &m ) { return m.mutate( this ); }
[de62360d]222 virtual void print( std::ostream &os, int indent = 0 ) const;
[51b73452]223};
224
[0dd3a2f]225class ForStmt : public Statement {
226 public:
[65cdc1e]227 std::list<Statement *> initialization;
228 Expression *condition;
229 Expression *increment;
230 Statement *body;
231
[145f1fc]232 ForStmt( std::list<Label> labels, std::list<Statement *> initialization,
[0dd3a2f]233 Expression *condition = 0, Expression *increment = 0, Statement *body = 0 );
[3be261a]234 ForStmt( const ForStmt &other );
[0dd3a2f]235 virtual ~ForStmt();
236
[145f1fc]237 std::list<Statement *> &get_initialization() { return initialization; }
238 void set_initialization( std::list<Statement *> newValue ) { initialization = newValue; }
[0dd3a2f]239 Expression *get_condition() { return condition; }
240 void set_condition( Expression *newValue ) { condition = newValue; }
241 Expression *get_increment() { return increment; }
242 void set_increment( Expression *newValue ) { increment = newValue; }
243 Statement *get_body() { return body; }
244 void set_body( Statement *newValue ) { body = newValue; }
[3be261a]245
[0dd3a2f]246 virtual ForStmt *clone() const { return new ForStmt( *this ); }
247 virtual void accept( Visitor &v ) { v.visit( this ); }
248 virtual Statement *acceptMutator( Mutator &m ) { return m.mutate( this ); }
[de62360d]249 virtual void print( std::ostream &os, int indent = 0 ) const;
[51b73452]250};
251
[0dd3a2f]252class BranchStmt : public Statement {
253 public:
[de62360d]254 enum Type { Goto = 0, Break, Continue };
[0dd3a2f]255
[65cdc1e]256 // originalTarget kept for error messages.
257 const Label originalTarget;
258 Label target;
259 Expression *computedTarget;
260 Type type;
261
[0dd3a2f]262 BranchStmt( std::list<Label> labels, Label target, Type ) throw (SemanticError);
263 BranchStmt( std::list<Label> labels, Expression *computedTarget, Type ) throw (SemanticError);
264
[be5aa1b]265 Label get_originalTarget() { return originalTarget; }
[0dd3a2f]266 Label get_target() { return target; }
267 void set_target( Label newValue ) { target = newValue; }
[3be261a]268
[0dd3a2f]269 Expression *get_computedTarget() { return computedTarget; }
270 void set_target( Expression * newValue ) { computedTarget = newValue; }
271
272 Type get_type() { return type; }
273 const char *get_typename() { return brType[ type ]; }
274
275 virtual BranchStmt *clone() const { return new BranchStmt( *this ); }
276 virtual void accept( Visitor &v ) { v.visit( this ); }
277 virtual Statement *acceptMutator( Mutator &m ) { return m.mutate( this ); }
[de62360d]278 virtual void print( std::ostream &os, int indent = 0 ) const;
[0dd3a2f]279 private:
280 static const char *brType[];
[51b73452]281};
282
[0dd3a2f]283class ReturnStmt : public Statement {
284 public:
[65cdc1e]285 Expression *expr;
286
[daf1af8]287 ReturnStmt( std::list<Label> labels, Expression *expr );
[3be261a]288 ReturnStmt( const ReturnStmt &other );
[0dd3a2f]289 virtual ~ReturnStmt();
290
291 Expression *get_expr() { return expr; }
292 void set_expr( Expression *newValue ) { expr = newValue; }
[3be261a]293
[0dd3a2f]294 virtual ReturnStmt *clone() const { return new ReturnStmt( *this ); }
295 virtual void accept( Visitor &v ) { v.visit( this ); }
296 virtual Statement *acceptMutator( Mutator &m ) { return m.mutate( this ); }
[de62360d]297 virtual void print( std::ostream &os, int indent = 0 ) const;
[51b73452]298};
299
[daf1af8]300class ThrowStmt : public Statement {
[0dd3a2f]301 public:
[daf1af8]302 enum Kind { Terminate, Resume };
[51b73452]303
[65cdc1e]304 const Kind kind;
305 Expression * expr;
306 Expression * target;
307
[ca78437]308 ThrowStmt( std::list<Label> labels, Kind kind, Expression * expr, Expression * target = nullptr );
[daf1af8]309 ThrowStmt( const ThrowStmt &other );
310 virtual ~ThrowStmt();
311
312 Kind get_kind() { return kind; }
313 Expression * get_expr() { return expr; }
314 void set_expr( Expression * newExpr ) { expr = newExpr; }
315 Expression * get_target() { return target; }
316 void set_target( Expression * newTarget ) { target = newTarget; }
317
318 virtual ThrowStmt *clone() const { return new ThrowStmt( *this ); }
[0dd3a2f]319 virtual void accept( Visitor &v ) { v.visit( this ); }
[daf1af8]320 virtual Statement *acceptMutator( Mutator &m ) { return m.mutate( this ); }
[de62360d]321 virtual void print( std::ostream &os, int indent = 0 ) const;
[51b73452]322};
323
[3be261a]324class TryStmt : public Statement {
[0dd3a2f]325 public:
[65cdc1e]326 CompoundStmt *block;
327 std::list<CatchStmt *> handlers;
328 FinallyStmt *finallyBlock;
329
[046e04a]330 TryStmt( std::list<Label> labels, CompoundStmt *tryBlock, std::list<CatchStmt *> &handlers, FinallyStmt *finallyBlock = 0 );
[0dd3a2f]331 TryStmt( const TryStmt &other );
332 virtual ~TryStmt();
333
334 CompoundStmt *get_block() const { return block; }
335 void set_block( CompoundStmt *newValue ) { block = newValue; }
[046e04a]336 std::list<CatchStmt *>& get_catchers() { return handlers; }
[0dd3a2f]337
338 FinallyStmt *get_finally() const { return finallyBlock; }
339 void set_finally( FinallyStmt *newValue ) { finallyBlock = newValue; }
340
341 virtual TryStmt *clone() const { return new TryStmt( *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;
[3be261a]345};
[51b73452]346
[0dd3a2f]347class CatchStmt : public Statement {
348 public:
[ca78437]349 enum Kind { Terminate, Resume };
350
[65cdc1e]351 const Kind kind;
352 Declaration *decl;
353 Expression *cond;
354 Statement *body;
355
[ca78437]356 CatchStmt( std::list<Label> labels, Kind kind, Declaration *decl,
357 Expression *cond, Statement *body );
[3be261a]358 CatchStmt( const CatchStmt &other );
[0dd3a2f]359 virtual ~CatchStmt();
360
[ca78437]361 Kind get_kind() { return kind; }
[0dd3a2f]362 Declaration *get_decl() { return decl; }
363 void set_decl( Declaration *newValue ) { decl = newValue; }
[ca78437]364 Expression *get_cond() { return cond; }
365 void set_cond( Expression *newCond ) { cond = newCond; }
[0dd3a2f]366 Statement *get_body() { return body; }
367 void set_body( Statement *newValue ) { body = newValue; }
[3be261a]368
[0dd3a2f]369 virtual CatchStmt *clone() const { return new CatchStmt( *this ); }
370 virtual void accept( Visitor &v ) { v.visit( this ); }
371 virtual Statement *acceptMutator( Mutator &m ) { return m.mutate( this ); }
[de62360d]372 virtual void print( std::ostream &os, int indent = 0 ) const;
[51b73452]373};
374
[3be261a]375class FinallyStmt : public Statement {
[0dd3a2f]376 public:
[65cdc1e]377 CompoundStmt *block;
378
[0dd3a2f]379 FinallyStmt( std::list<Label> labels, CompoundStmt *block );
[3be261a]380 FinallyStmt( const FinallyStmt &other );
[0dd3a2f]381 virtual ~FinallyStmt();
382
383 CompoundStmt *get_block() const { return block; }
384 void set_block( CompoundStmt *newValue ) { block = newValue; }
[3be261a]385
[0dd3a2f]386 virtual FinallyStmt *clone() const { return new FinallyStmt( *this ); }
387 virtual void accept( Visitor &v ) { v.visit( this ); }
388 virtual Statement *acceptMutator( Mutator &m ) { return m.mutate( this ); }
[de62360d]389 virtual void print( std::ostream &os, int indent = 0 ) const;
[3be261a]390};
[51b73452]391
392
393// represents a declaration that occurs as part of a compound statement
[0dd3a2f]394class DeclStmt : public Statement {
395 public:
[65cdc1e]396 Declaration *decl;
397
[0dd3a2f]398 DeclStmt( std::list<Label> labels, Declaration *decl );
399 DeclStmt( const DeclStmt &other );
400 virtual ~DeclStmt();
401
[f1b1e4c]402 Declaration *get_decl() const { return decl; }
[0dd3a2f]403 void set_decl( Declaration *newValue ) { decl = newValue; }
404
405 virtual DeclStmt *clone() const { return new DeclStmt( *this ); }
406 virtual void accept( Visitor &v ) { v.visit( this ); }
407 virtual Statement *acceptMutator( Mutator &m ) { return m.mutate( this ); }
[de62360d]408 virtual void print( std::ostream &os, int indent = 0 ) const;
[51b73452]409};
410
[f1b1e4c]411
412/// represents an implicit application of a constructor or destructor. Qualifiers are replaced
413/// immediately before and after the call so that qualified objects can be constructed
414/// with the same functions as unqualified objects.
415class ImplicitCtorDtorStmt : public Statement {
416 public:
[65cdc1e]417 // Non-owned pointer to the constructor/destructor statement
418 Statement * callStmt;
419
[f1b1e4c]420 ImplicitCtorDtorStmt( Statement * callStmt );
421 ImplicitCtorDtorStmt( const ImplicitCtorDtorStmt & other );
422 virtual ~ImplicitCtorDtorStmt();
423
424 Statement *get_callStmt() const { return callStmt; }
425 void set_callStmt( Statement * newValue ) { callStmt = newValue; }
426
427 virtual ImplicitCtorDtorStmt *clone() const { return new ImplicitCtorDtorStmt( *this ); }
428 virtual void accept( Visitor &v ) { v.visit( this ); }
429 virtual Statement *acceptMutator( Mutator &m ) { return m.mutate( this ); }
430 virtual void print( std::ostream &os, int indent = 0 ) const;
431};
432
433
[3906301]434std::ostream & operator<<( std::ostream & out, const Statement * statement );
[baf7fee]435
[0dd3a2f]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.