source: src/SynTree/Statement.h@ b947fb2

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

change #ifndef to #pragma once

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