[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 | // |
---|
| 7 | // Statement.h -- |
---|
| 8 | // |
---|
| 9 | // Author : Richard C. Bilson |
---|
| 10 | // Created On : Mon May 18 07:44:20 2015 |
---|
[a61fea9a] | 11 | // Last Modified By : Peter A. Buhr |
---|
[9a8930f] | 12 | // Last Modified On : Thu Jun 4 14:03:31 2015 |
---|
| 13 | // Update Count : 14 |
---|
[0dd3a2f] | 14 | // |
---|
| 15 | |
---|
[51b7345] | 16 | #ifndef STATEMENT_H |
---|
| 17 | #define STATEMENT_H |
---|
| 18 | |
---|
| 19 | #include "SynTree.h" |
---|
| 20 | #include "Visitor.h" |
---|
| 21 | #include "Mutator.h" |
---|
| 22 | #include "Common/SemanticError.h" |
---|
| 23 | |
---|
[0dd3a2f] | 24 | class Statement { |
---|
| 25 | public: |
---|
| 26 | Statement( std::list<Label> labels ); |
---|
| 27 | virtual ~Statement(); |
---|
[51b7345] | 28 | |
---|
[0dd3a2f] | 29 | std::list<Label> & get_labels() { return labels; } |
---|
[51b7345] | 30 | |
---|
[0dd3a2f] | 31 | virtual Statement *clone() const = 0; |
---|
| 32 | virtual void accept( Visitor &v ) = 0; |
---|
| 33 | virtual Statement *acceptMutator( Mutator &m ) = 0; |
---|
| 34 | virtual void print( std::ostream &os, int indent = 0 ); |
---|
| 35 | protected: |
---|
| 36 | std::list<Label> labels; |
---|
[51b7345] | 37 | }; |
---|
| 38 | |
---|
[0dd3a2f] | 39 | class CompoundStmt : public Statement { |
---|
| 40 | public: |
---|
| 41 | CompoundStmt( std::list<Label> labels ); |
---|
| 42 | CompoundStmt( const CompoundStmt &other ); |
---|
| 43 | virtual ~CompoundStmt(); |
---|
[51b7345] | 44 | |
---|
[0dd3a2f] | 45 | std::list<Statement*>& get_kids() { return kids; } |
---|
[51b7345] | 46 | |
---|
[0dd3a2f] | 47 | virtual CompoundStmt *clone() const { return new CompoundStmt( *this ); } |
---|
| 48 | virtual void accept( Visitor &v ) { v.visit( this ); } |
---|
| 49 | virtual CompoundStmt *acceptMutator( Mutator &m ) { return m.mutate( this ); } |
---|
| 50 | virtual void print( std::ostream &os, int indent = 0 ); |
---|
| 51 | private: |
---|
| 52 | std::list<Statement*> kids; |
---|
[51b7345] | 53 | }; |
---|
| 54 | |
---|
[0dd3a2f] | 55 | class ExprStmt : public Statement { |
---|
| 56 | public: |
---|
| 57 | ExprStmt( std::list<Label> labels, Expression *expr ); |
---|
| 58 | virtual ~ExprStmt(); |
---|
[51b7345] | 59 | |
---|
[0dd3a2f] | 60 | Expression *get_expr() { return expr; } |
---|
| 61 | void set_expr( Expression *newValue ) { expr = newValue; } |
---|
[51b7345] | 62 | |
---|
[0dd3a2f] | 63 | virtual ExprStmt *clone() const { return new ExprStmt( *this ); } |
---|
| 64 | virtual void accept( Visitor &v ) { v.visit( this ); } |
---|
| 65 | virtual Statement *acceptMutator( Mutator &m ) { return m.mutate( this ); } |
---|
| 66 | virtual void print( std::ostream &os, int indent = 0 ); |
---|
| 67 | private: |
---|
| 68 | Expression *expr; |
---|
| 69 | }; |
---|
[51b7345] | 70 | |
---|
[0dd3a2f] | 71 | class IfStmt : public Statement { |
---|
| 72 | public: |
---|
| 73 | IfStmt( std::list<Label> labels, Expression *condition, Statement *thenPart, Statement *elsePart ); |
---|
| 74 | virtual ~IfStmt(); |
---|
| 75 | |
---|
| 76 | Expression *get_condition() { return condition; } |
---|
| 77 | void set_condition( Expression *newValue ) { condition = newValue; } |
---|
| 78 | Statement *get_thenPart() { return thenPart; } |
---|
| 79 | void set_thenPart( Statement *newValue ) { thenPart = newValue; } |
---|
| 80 | Statement *get_elsePart() { return elsePart; } |
---|
| 81 | void set_elsePart( Statement *newValue ) { elsePart = newValue; } |
---|
| 82 | |
---|
| 83 | virtual IfStmt *clone() const { return new IfStmt( *this ); } |
---|
| 84 | virtual void accept( Visitor &v ) { v.visit( this ); } |
---|
| 85 | virtual Statement *acceptMutator( Mutator &m ) { return m.mutate( this ); } |
---|
| 86 | virtual void print( std::ostream &os, int indent = 0 ); |
---|
| 87 | private: |
---|
| 88 | Expression *condition; |
---|
| 89 | Statement *thenPart; |
---|
| 90 | Statement *elsePart; |
---|
[51b7345] | 91 | }; |
---|
| 92 | |
---|
[0dd3a2f] | 93 | class SwitchStmt : public Statement { |
---|
| 94 | public: |
---|
| 95 | SwitchStmt( std::list<Label> labels, Expression *condition, std::list<Statement *> &branches ); |
---|
| 96 | virtual ~SwitchStmt(); |
---|
[51b7345] | 97 | |
---|
[0dd3a2f] | 98 | Expression *get_condition() { return condition; } |
---|
| 99 | void set_condition( Expression *newValue ) { condition = newValue; } |
---|
[51b7345] | 100 | |
---|
[0dd3a2f] | 101 | std::list<Statement *>& get_branches() { return branches; } |
---|
| 102 | void add_case( CaseStmt * ); |
---|
[51b7345] | 103 | |
---|
[0dd3a2f] | 104 | virtual void accept( Visitor &v ) { v.visit( this ); } |
---|
| 105 | virtual Statement *acceptMutator( Mutator &m ) { return m.mutate( this ); } |
---|
[51b7345] | 106 | |
---|
[0dd3a2f] | 107 | virtual SwitchStmt *clone() const { return new SwitchStmt( *this ); } |
---|
| 108 | virtual void print( std::ostream &os, int indent = 0 ); |
---|
| 109 | private: |
---|
| 110 | Expression * condition; |
---|
| 111 | std::list<Statement *> branches; // should be list of CaseStmt |
---|
[51b7345] | 112 | }; |
---|
| 113 | |
---|
[0dd3a2f] | 114 | class ChooseStmt : public Statement { |
---|
| 115 | public: |
---|
| 116 | ChooseStmt( std::list<Label> labels, Expression *condition, std::list<Statement *> &branches ); |
---|
| 117 | virtual ~ChooseStmt(); |
---|
[51b7345] | 118 | |
---|
[0dd3a2f] | 119 | Expression *get_condition() { return condition; } |
---|
| 120 | void set_condition( Expression *newValue ) { condition = newValue; } |
---|
[51b7345] | 121 | |
---|
[0dd3a2f] | 122 | std::list<Statement *>& get_branches() { return branches; } |
---|
| 123 | void add_case( CaseStmt * ); |
---|
[51b7345] | 124 | |
---|
[0dd3a2f] | 125 | virtual void accept( Visitor &v ) { v.visit( this ); } |
---|
| 126 | virtual Statement *acceptMutator( Mutator &m ) { return m.mutate( this ); } |
---|
[51b7345] | 127 | |
---|
[0dd3a2f] | 128 | virtual ChooseStmt *clone() const { return new ChooseStmt( *this ); } |
---|
| 129 | virtual void print( std::ostream &os, int indent = 0 ); |
---|
| 130 | private: |
---|
| 131 | Expression *condition; |
---|
| 132 | std::list<Statement *> branches; // should be list of CaseStmt |
---|
| 133 | }; |
---|
[51b7345] | 134 | |
---|
[0dd3a2f] | 135 | class FallthruStmt : public Statement { |
---|
| 136 | public: |
---|
| 137 | FallthruStmt( std::list<Label> labels ) : Statement( labels ) { } |
---|
[51b7345] | 138 | |
---|
[0dd3a2f] | 139 | virtual void accept( Visitor &v ) { v.visit( this ); } |
---|
| 140 | virtual Statement *acceptMutator( Mutator &m ) { return m.mutate( this ); } |
---|
[51b7345] | 141 | |
---|
[0dd3a2f] | 142 | virtual FallthruStmt *clone() const { return new FallthruStmt( *this ); } |
---|
| 143 | virtual void print( std::ostream &os, int indent = 0 ); |
---|
| 144 | }; |
---|
[51b7345] | 145 | |
---|
[0dd3a2f] | 146 | class CaseStmt : public Statement { |
---|
| 147 | public: |
---|
| 148 | CaseStmt( std::list<Label> labels, Expression *conditions, |
---|
| 149 | std::list<Statement *> &stmts, bool isdef = false ) throw(SemanticError); |
---|
| 150 | virtual ~CaseStmt(); |
---|
| 151 | |
---|
[b2152e7a] | 152 | static CaseStmt * makeDefault( std::list<Label> labels = std::list<Label>(), |
---|
| 153 | std::list<Statement *> stmts = std::list<Statement *>() ); |
---|
| 154 | |
---|
[0dd3a2f] | 155 | bool isDefault() { return _isDefault; } |
---|
| 156 | void set_default(bool b) { _isDefault = b; } |
---|
| 157 | |
---|
| 158 | Expression * &get_condition() { return condition; } |
---|
| 159 | void set_condition( Expression *newValue ) { condition = newValue; } |
---|
| 160 | |
---|
| 161 | std::list<Statement *> &get_statements() { return stmts; } |
---|
| 162 | void set_statements( std::list<Statement *> &newValue ) { stmts = newValue; } |
---|
| 163 | |
---|
| 164 | virtual void accept( Visitor &v ) { v.visit( this ); } |
---|
| 165 | virtual Statement *acceptMutator( Mutator &m ) { return m.mutate( this ); } |
---|
| 166 | |
---|
| 167 | virtual CaseStmt *clone() const { return new CaseStmt( *this ); } |
---|
| 168 | virtual void print( std::ostream &os, int indent = 0 ); |
---|
| 169 | private: |
---|
| 170 | Expression * condition; |
---|
| 171 | std::list<Statement *> stmts; |
---|
| 172 | bool _isDefault; |
---|
[51b7345] | 173 | }; |
---|
| 174 | |
---|
[0dd3a2f] | 175 | class WhileStmt : public Statement { |
---|
| 176 | public: |
---|
| 177 | WhileStmt( std::list<Label> labels, Expression *condition, |
---|
| 178 | Statement *body, bool isDoWhile = false ); |
---|
| 179 | virtual ~WhileStmt(); |
---|
| 180 | |
---|
| 181 | Expression *get_condition() { return condition; } |
---|
| 182 | void set_condition( Expression *newValue ) { condition = newValue; } |
---|
| 183 | Statement *get_body() { return body; } |
---|
| 184 | void set_body( Statement *newValue ) { body = newValue; } |
---|
| 185 | bool get_isDoWhile() { return isDoWhile; } |
---|
| 186 | void set_isDoWhile( bool newValue ) { isDoWhile = newValue; } |
---|
| 187 | |
---|
| 188 | virtual WhileStmt *clone() const { return new WhileStmt( *this ); } |
---|
| 189 | virtual void accept( Visitor &v ) { v.visit( this ); } |
---|
| 190 | virtual Statement *acceptMutator( Mutator &m ) { return m.mutate( this ); } |
---|
| 191 | virtual void print( std::ostream &os, int indent = 0 ); |
---|
| 192 | private: |
---|
| 193 | Expression *condition; |
---|
| 194 | Statement *body; |
---|
| 195 | bool isDoWhile; |
---|
[51b7345] | 196 | }; |
---|
| 197 | |
---|
[0dd3a2f] | 198 | class ForStmt : public Statement { |
---|
| 199 | public: |
---|
| 200 | ForStmt( std::list<Label> labels, Statement *initialization = 0, |
---|
| 201 | Expression *condition = 0, Expression *increment = 0, Statement *body = 0 ); |
---|
| 202 | virtual ~ForStmt(); |
---|
| 203 | |
---|
| 204 | Statement *get_initialization() { return initialization; } |
---|
| 205 | void set_initialization( Statement *newValue ) { initialization = newValue; } |
---|
| 206 | Expression *get_condition() { return condition; } |
---|
| 207 | void set_condition( Expression *newValue ) { condition = newValue; } |
---|
| 208 | Expression *get_increment() { return increment; } |
---|
| 209 | void set_increment( Expression *newValue ) { increment = newValue; } |
---|
| 210 | Statement *get_body() { return body; } |
---|
| 211 | void set_body( Statement *newValue ) { body = newValue; } |
---|
| 212 | |
---|
| 213 | virtual ForStmt *clone() const { return new ForStmt( *this ); } |
---|
| 214 | virtual void accept( Visitor &v ) { v.visit( this ); } |
---|
| 215 | virtual Statement *acceptMutator( Mutator &m ) { return m.mutate( this ); } |
---|
| 216 | virtual void print( std::ostream &os, int indent = 0 ); |
---|
| 217 | private: |
---|
| 218 | Statement *initialization; |
---|
| 219 | Expression *condition; |
---|
| 220 | Expression *increment; |
---|
| 221 | Statement *body; |
---|
[51b7345] | 222 | }; |
---|
| 223 | |
---|
[0dd3a2f] | 224 | class BranchStmt : public Statement { |
---|
| 225 | public: |
---|
| 226 | enum Type { Goto = 0 , Break, Continue }; |
---|
| 227 | |
---|
| 228 | BranchStmt( std::list<Label> labels, Label target, Type ) throw (SemanticError); |
---|
| 229 | BranchStmt( std::list<Label> labels, Expression *computedTarget, Type ) throw (SemanticError); |
---|
| 230 | virtual ~BranchStmt() {} |
---|
| 231 | |
---|
[be5aa1b] | 232 | Label get_originalTarget() { return originalTarget; } |
---|
[0dd3a2f] | 233 | Label get_target() { return target; } |
---|
| 234 | void set_target( Label newValue ) { target = newValue; } |
---|
| 235 | |
---|
| 236 | Expression *get_computedTarget() { return computedTarget; } |
---|
| 237 | void set_target( Expression * newValue ) { computedTarget = newValue; } |
---|
| 238 | |
---|
| 239 | Type get_type() { return type; } |
---|
| 240 | const char *get_typename() { return brType[ type ]; } |
---|
| 241 | |
---|
| 242 | virtual BranchStmt *clone() const { return new BranchStmt( *this ); } |
---|
| 243 | virtual void accept( Visitor &v ) { v.visit( this ); } |
---|
| 244 | virtual Statement *acceptMutator( Mutator &m ) { return m.mutate( this ); } |
---|
| 245 | virtual void print( std::ostream &os, int indent = 0 ); |
---|
| 246 | private: |
---|
| 247 | static const char *brType[]; |
---|
[be5aa1b] | 248 | Label originalTarget; // can give better error messages if we remember the label name that the user entered |
---|
[0dd3a2f] | 249 | Label target; |
---|
| 250 | Expression *computedTarget; |
---|
| 251 | Type type; |
---|
[51b7345] | 252 | }; |
---|
| 253 | |
---|
[0dd3a2f] | 254 | class ReturnStmt : public Statement { |
---|
| 255 | public: |
---|
| 256 | ReturnStmt( std::list<Label> labels, Expression *expr, bool throwP = false ); |
---|
| 257 | virtual ~ReturnStmt(); |
---|
| 258 | |
---|
| 259 | Expression *get_expr() { return expr; } |
---|
| 260 | void set_expr( Expression *newValue ) { expr = newValue; } |
---|
| 261 | |
---|
| 262 | virtual ReturnStmt *clone() const { return new ReturnStmt( *this ); } |
---|
| 263 | virtual void accept( Visitor &v ) { v.visit( this ); } |
---|
| 264 | virtual Statement *acceptMutator( Mutator &m ) { return m.mutate( this ); } |
---|
| 265 | virtual void print( std::ostream &os, int indent = 0 ); |
---|
| 266 | private: |
---|
| 267 | Expression *expr; |
---|
| 268 | bool isThrow; |
---|
[51b7345] | 269 | }; |
---|
| 270 | |
---|
| 271 | |
---|
[0dd3a2f] | 272 | class NullStmt : public CompoundStmt { |
---|
| 273 | public: |
---|
| 274 | NullStmt(); |
---|
| 275 | NullStmt( std::list<Label> labels ); |
---|
| 276 | virtual ~NullStmt(); |
---|
[51b7345] | 277 | |
---|
[0dd3a2f] | 278 | virtual NullStmt *clone() const { return new NullStmt( *this ); } |
---|
| 279 | virtual void accept( Visitor &v ) { v.visit( this ); } |
---|
| 280 | virtual NullStmt *acceptMutator( Mutator &m ) { return m.mutate( this ); } |
---|
| 281 | virtual void print( std::ostream &os, int indent = 0 ); |
---|
| 282 | |
---|
| 283 | private: |
---|
[51b7345] | 284 | }; |
---|
| 285 | |
---|
[0dd3a2f] | 286 | class TryStmt : public Statement { |
---|
| 287 | public: |
---|
| 288 | TryStmt( std::list<Label> labels, CompoundStmt *tryBlock, std::list<Statement *> &handlers, FinallyStmt *finallyBlock = 0 ); |
---|
| 289 | TryStmt( const TryStmt &other ); |
---|
| 290 | virtual ~TryStmt(); |
---|
| 291 | |
---|
| 292 | CompoundStmt *get_block() const { return block; } |
---|
| 293 | void set_block( CompoundStmt *newValue ) { block = newValue; } |
---|
| 294 | std::list<Statement *>& get_catchers() { return handlers; } |
---|
| 295 | |
---|
| 296 | FinallyStmt *get_finally() const { return finallyBlock; } |
---|
| 297 | void set_finally( FinallyStmt *newValue ) { finallyBlock = newValue; } |
---|
| 298 | |
---|
| 299 | virtual TryStmt *clone() const { return new TryStmt( *this ); } |
---|
| 300 | virtual void accept( Visitor &v ) { v.visit( this ); } |
---|
| 301 | virtual Statement *acceptMutator( Mutator &m ) { return m.mutate( this ); } |
---|
| 302 | virtual void print( std::ostream &os, int indent = 0 ); |
---|
| 303 | |
---|
| 304 | private: |
---|
| 305 | CompoundStmt *block; |
---|
| 306 | std::list<Statement *> handlers; |
---|
| 307 | FinallyStmt *finallyBlock; |
---|
[51b7345] | 308 | }; |
---|
| 309 | |
---|
[0dd3a2f] | 310 | class CatchStmt : public Statement { |
---|
| 311 | public: |
---|
| 312 | CatchStmt( std::list<Label> labels, Declaration *decl, Statement *body, bool isCatchRest = false ); |
---|
| 313 | virtual ~CatchStmt(); |
---|
| 314 | |
---|
| 315 | Declaration *get_decl() { return decl; } |
---|
| 316 | void set_decl( Declaration *newValue ) { decl = newValue; } |
---|
| 317 | |
---|
| 318 | Statement *get_body() { return body; } |
---|
| 319 | void set_body( Statement *newValue ) { body = newValue; } |
---|
| 320 | |
---|
| 321 | virtual CatchStmt *clone() const { return new CatchStmt( *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 ); |
---|
| 325 | |
---|
| 326 | private: |
---|
| 327 | Declaration *decl; |
---|
| 328 | Statement *body; |
---|
| 329 | bool catchRest; |
---|
[51b7345] | 330 | }; |
---|
| 331 | |
---|
[0dd3a2f] | 332 | class FinallyStmt : public Statement { |
---|
| 333 | public: |
---|
| 334 | FinallyStmt( std::list<Label> labels, CompoundStmt *block ); |
---|
| 335 | virtual ~FinallyStmt(); |
---|
| 336 | |
---|
| 337 | CompoundStmt *get_block() const { return block; } |
---|
| 338 | void set_block( CompoundStmt *newValue ) { block = newValue; } |
---|
| 339 | |
---|
| 340 | virtual FinallyStmt *clone() const { return new FinallyStmt( *this ); } |
---|
| 341 | virtual void accept( Visitor &v ) { v.visit( this ); } |
---|
| 342 | virtual Statement *acceptMutator( Mutator &m ) { return m.mutate( this ); } |
---|
| 343 | virtual void print( std::ostream &os, int indent = 0 ); |
---|
| 344 | private: |
---|
| 345 | CompoundStmt *block; |
---|
[51b7345] | 346 | }; |
---|
| 347 | |
---|
| 348 | |
---|
| 349 | // represents a declaration that occurs as part of a compound statement |
---|
[0dd3a2f] | 350 | class DeclStmt : public Statement { |
---|
| 351 | public: |
---|
| 352 | DeclStmt( std::list<Label> labels, Declaration *decl ); |
---|
| 353 | DeclStmt( const DeclStmt &other ); |
---|
| 354 | virtual ~DeclStmt(); |
---|
| 355 | |
---|
| 356 | Declaration *get_decl() { return decl; } |
---|
| 357 | void set_decl( Declaration *newValue ) { decl = newValue; } |
---|
| 358 | |
---|
| 359 | virtual DeclStmt *clone() const { return new DeclStmt( *this ); } |
---|
| 360 | virtual void accept( Visitor &v ) { v.visit( this ); } |
---|
| 361 | virtual Statement *acceptMutator( Mutator &m ) { return m.mutate( this ); } |
---|
| 362 | virtual void print( std::ostream &os, int indent = 0 ); |
---|
| 363 | private: |
---|
| 364 | Declaration *decl; |
---|
[51b7345] | 365 | }; |
---|
| 366 | |
---|
[0dd3a2f] | 367 | #endif // STATEMENT_H |
---|
[51b7345] | 368 | |
---|
[0dd3a2f] | 369 | // Local Variables: // |
---|
| 370 | // tab-width: 4 // |
---|
| 371 | // mode: c++ // |
---|
| 372 | // compile-command: "make install" // |
---|
| 373 | // End: // |
---|