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