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
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
[936e9f4]11// Last Modified By : Peter A. Buhr
12// Last Modified On : Wed Aug 16 16:28:55 2017
13// Update Count : 70
[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:
[936e9f4]129 std::list<Statement *> initialization;
[65cdc1e]130 Expression *condition;
131 Statement *thenPart;
132 Statement *elsePart;
133
[0dd3a2f]134 IfStmt( std::list<Label> labels, Expression *condition, Statement *thenPart, Statement *elsePart );
[3be261a]135 IfStmt( const IfStmt &other );
[0dd3a2f]136 virtual ~IfStmt();
137
[936e9f4]138 std::list<Statement *> &get_initialization() { return initialization; }
139 void set_initialization( std::list<Statement *> newValue ) { initialization = newValue; }
[0dd3a2f]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; }
[3be261a]146
[0dd3a2f]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 ); }
[de62360d]150 virtual void print( std::ostream &os, int indent = 0 ) const;
[51b73452]151};
152
[0dd3a2f]153class SwitchStmt : public Statement {
154 public:
[65cdc1e]155 Expression * condition;
156
[8688ce1]157 SwitchStmt( std::list<Label> labels, Expression *condition, std::list<Statement *> &statements );
[3be261a]158 SwitchStmt( const SwitchStmt &other );
[0dd3a2f]159 virtual ~SwitchStmt();
[51b73452]160
[0dd3a2f]161 Expression *get_condition() { return condition; }
162 void set_condition( Expression *newValue ) { condition = newValue; }
[51b73452]163
[8688ce1]164 std::list<Statement *> & get_statements() { return statements; }
[51b73452]165
[0dd3a2f]166 virtual void accept( Visitor &v ) { v.visit( this ); }
167 virtual Statement *acceptMutator( Mutator &m ) { return m.mutate( this ); }
[51b73452]168
[0dd3a2f]169 virtual SwitchStmt *clone() const { return new SwitchStmt( *this ); }
[de62360d]170 virtual void print( std::ostream &os, int indent = 0 ) const;
[0dd3a2f]171 private:
[8688ce1]172 std::list<Statement *> statements;
[51b73452]173};
174
[0dd3a2f]175class CaseStmt : public Statement {
176 public:
[65cdc1e]177 Expression * condition;
178 std::list<Statement *> stmts;
179
[8688ce1]180 CaseStmt( std::list<Label> labels, Expression *conditions, std::list<Statement *> &stmts, bool isdef = false ) throw(SemanticError);
[3be261a]181 CaseStmt( const CaseStmt &other );
[0dd3a2f]182 virtual ~CaseStmt();
183
[8688ce1]184 static CaseStmt * makeDefault( std::list<Label> labels = std::list<Label>(), std::list<Statement *> stmts = std::list<Statement *>() );
[b2152e7a]185
[de62360d]186 bool isDefault() const { return _isDefault; }
[0dd3a2f]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; }
[3be261a]194
[0dd3a2f]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 ); }
[de62360d]199 virtual void print( std::ostream &os, int indent = 0 ) const;
[0dd3a2f]200 private:
201 bool _isDefault;
[51b73452]202};
203
[0dd3a2f]204class WhileStmt : public Statement {
205 public:
[65cdc1e]206 Expression *condition;
207 Statement *body;
208 bool isDoWhile;
209
[0dd3a2f]210 WhileStmt( std::list<Label> labels, Expression *condition,
211 Statement *body, bool isDoWhile = false );
[3be261a]212 WhileStmt( const WhileStmt &other );
[0dd3a2f]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; }
[3be261a]221
[0dd3a2f]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 ); }
[de62360d]225 virtual void print( std::ostream &os, int indent = 0 ) const;
[51b73452]226};
227
[0dd3a2f]228class ForStmt : public Statement {
229 public:
[65cdc1e]230 std::list<Statement *> initialization;
231 Expression *condition;
232 Expression *increment;
233 Statement *body;
234
[145f1fc]235 ForStmt( std::list<Label> labels, std::list<Statement *> initialization,
[0dd3a2f]236 Expression *condition = 0, Expression *increment = 0, Statement *body = 0 );
[3be261a]237 ForStmt( const ForStmt &other );
[0dd3a2f]238 virtual ~ForStmt();
239
[145f1fc]240 std::list<Statement *> &get_initialization() { return initialization; }
241 void set_initialization( std::list<Statement *> newValue ) { initialization = newValue; }
[0dd3a2f]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; }
[3be261a]248
[0dd3a2f]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 ); }
[de62360d]252 virtual void print( std::ostream &os, int indent = 0 ) const;
[51b73452]253};
254
[0dd3a2f]255class BranchStmt : public Statement {
256 public:
[de62360d]257 enum Type { Goto = 0, Break, Continue };
[0dd3a2f]258
[65cdc1e]259 // originalTarget kept for error messages.
260 const Label originalTarget;
261 Label target;
262 Expression *computedTarget;
263 Type type;
264
[0dd3a2f]265 BranchStmt( std::list<Label> labels, Label target, Type ) throw (SemanticError);
266 BranchStmt( std::list<Label> labels, Expression *computedTarget, Type ) throw (SemanticError);
267
[be5aa1b]268 Label get_originalTarget() { return originalTarget; }
[0dd3a2f]269 Label get_target() { return target; }
270 void set_target( Label newValue ) { target = newValue; }
[3be261a]271
[0dd3a2f]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 ); }
[de62360d]281 virtual void print( std::ostream &os, int indent = 0 ) const;
[0dd3a2f]282 private:
283 static const char *brType[];
[51b73452]284};
285
[0dd3a2f]286class ReturnStmt : public Statement {
287 public:
[65cdc1e]288 Expression *expr;
289
[daf1af8]290 ReturnStmt( std::list<Label> labels, Expression *expr );
[3be261a]291 ReturnStmt( const ReturnStmt &other );
[0dd3a2f]292 virtual ~ReturnStmt();
293
294 Expression *get_expr() { return expr; }
295 void set_expr( Expression *newValue ) { expr = newValue; }
[3be261a]296
[0dd3a2f]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 ); }
[de62360d]300 virtual void print( std::ostream &os, int indent = 0 ) const;
[51b73452]301};
302
[daf1af8]303class ThrowStmt : public Statement {
[0dd3a2f]304 public:
[daf1af8]305 enum Kind { Terminate, Resume };
[51b73452]306
[65cdc1e]307 const Kind kind;
308 Expression * expr;
309 Expression * target;
310
[ca78437]311 ThrowStmt( std::list<Label> labels, Kind kind, Expression * expr, Expression * target = nullptr );
[daf1af8]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 ); }
[0dd3a2f]322 virtual void accept( Visitor &v ) { v.visit( this ); }
[daf1af8]323 virtual Statement *acceptMutator( Mutator &m ) { return m.mutate( this ); }
[de62360d]324 virtual void print( std::ostream &os, int indent = 0 ) const;
[51b73452]325};
326
[3be261a]327class TryStmt : public Statement {
[0dd3a2f]328 public:
[65cdc1e]329 CompoundStmt *block;
330 std::list<CatchStmt *> handlers;
331 FinallyStmt *finallyBlock;
332
[046e04a]333 TryStmt( std::list<Label> labels, CompoundStmt *tryBlock, std::list<CatchStmt *> &handlers, FinallyStmt *finallyBlock = 0 );
[0dd3a2f]334 TryStmt( const TryStmt &other );
335 virtual ~TryStmt();
336
337 CompoundStmt *get_block() const { return block; }
338 void set_block( CompoundStmt *newValue ) { block = newValue; }
[046e04a]339 std::list<CatchStmt *>& get_catchers() { return handlers; }
[0dd3a2f]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 ); }
[de62360d]347 virtual void print( std::ostream &os, int indent = 0 ) const;
[3be261a]348};
[51b73452]349
[0dd3a2f]350class CatchStmt : public Statement {
351 public:
[ca78437]352 enum Kind { Terminate, Resume };
353
[65cdc1e]354 const Kind kind;
355 Declaration *decl;
356 Expression *cond;
357 Statement *body;
358
[ca78437]359 CatchStmt( std::list<Label> labels, Kind kind, Declaration *decl,
360 Expression *cond, Statement *body );
[3be261a]361 CatchStmt( const CatchStmt &other );
[0dd3a2f]362 virtual ~CatchStmt();
363
[ca78437]364 Kind get_kind() { return kind; }
[0dd3a2f]365 Declaration *get_decl() { return decl; }
366 void set_decl( Declaration *newValue ) { decl = newValue; }
[ca78437]367 Expression *get_cond() { return cond; }
368 void set_cond( Expression *newCond ) { cond = newCond; }
[0dd3a2f]369 Statement *get_body() { return body; }
370 void set_body( Statement *newValue ) { body = newValue; }
[3be261a]371
[0dd3a2f]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 ); }
[de62360d]375 virtual void print( std::ostream &os, int indent = 0 ) const;
[51b73452]376};
377
[3be261a]378class FinallyStmt : public Statement {
[0dd3a2f]379 public:
[65cdc1e]380 CompoundStmt *block;
381
[0dd3a2f]382 FinallyStmt( std::list<Label> labels, CompoundStmt *block );
[3be261a]383 FinallyStmt( const FinallyStmt &other );
[0dd3a2f]384 virtual ~FinallyStmt();
385
386 CompoundStmt *get_block() const { return block; }
387 void set_block( CompoundStmt *newValue ) { block = newValue; }
[3be261a]388
[0dd3a2f]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 ); }
[de62360d]392 virtual void print( std::ostream &os, int indent = 0 ) const;
[3be261a]393};
[51b73452]394
395
396// represents a declaration that occurs as part of a compound statement
[0dd3a2f]397class DeclStmt : public Statement {
398 public:
[65cdc1e]399 Declaration *decl;
400
[0dd3a2f]401 DeclStmt( std::list<Label> labels, Declaration *decl );
402 DeclStmt( const DeclStmt &other );
403 virtual ~DeclStmt();
404
[f1b1e4c]405 Declaration *get_decl() const { return decl; }
[0dd3a2f]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 ); }
[de62360d]411 virtual void print( std::ostream &os, int indent = 0 ) const;
[51b73452]412};
413
[f1b1e4c]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:
[65cdc1e]420 // Non-owned pointer to the constructor/destructor statement
421 Statement * callStmt;
422
[f1b1e4c]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
[3906301]437std::ostream & operator<<( std::ostream & out, const Statement * statement );
[baf7fee]438
[0dd3a2f]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.