[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 |
---|
[0608e007] | 12 | // Last Modified On : Fri Jan 10 14:13:24 2020 |
---|
| 13 | // Update Count : 85 |
---|
[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 |
---|
[35a2d47] | 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 | |
---|
[35a2d47] | 45 | virtual Statement * clone() const override = 0; |
---|
| 46 | virtual void accept( Visitor & v ) override = 0; |
---|
[7870799] | 47 | virtual void accept( Visitor & v ) const override = 0; |
---|
[35a2d47] | 48 | virtual Statement * acceptMutator( Mutator & m ) override = 0; |
---|
| 49 | virtual void print( std::ostream & os, Indenter indent = {} ) const override; |
---|
[51b7345] | 50 | }; |
---|
| 51 | |
---|
[0dd3a2f] | 52 | class CompoundStmt : public Statement { |
---|
| 53 | public: |
---|
[65cdc1e] | 54 | std::list<Statement*> kids; |
---|
| 55 | |
---|
[ba3706f] | 56 | CompoundStmt(); |
---|
[a2dbad10] | 57 | CompoundStmt( std::list<Statement *> stmts ); |
---|
[35a2d47] | 58 | CompoundStmt( const CompoundStmt & other ); |
---|
[0dd3a2f] | 59 | virtual ~CompoundStmt(); |
---|
[51b7345] | 60 | |
---|
[0dd3a2f] | 61 | std::list<Statement*>& get_kids() { return kids; } |
---|
[c8dfcd3] | 62 | void push_back( Statement * stmt ) { kids.push_back( stmt ); } |
---|
| 63 | void push_front( Statement * stmt ) { kids.push_front( stmt ); } |
---|
[51b7345] | 64 | |
---|
[35a2d47] | 65 | virtual CompoundStmt * clone() const override { return new CompoundStmt( *this ); } |
---|
| 66 | virtual void accept( Visitor & v ) override { v.visit( this ); } |
---|
[7870799] | 67 | virtual void accept( Visitor & v ) const override { v.visit( this ); } |
---|
[35a2d47] | 68 | virtual CompoundStmt * acceptMutator( Mutator & m ) override { return m.mutate( this ); } |
---|
| 69 | virtual void print( std::ostream & os, Indenter indent = {} ) const override; |
---|
[51b7345] | 70 | }; |
---|
| 71 | |
---|
[70d826cd] | 72 | class NullStmt : public Statement { |
---|
[daf1af8] | 73 | public: |
---|
[ba3706f] | 74 | NullStmt( const std::list<Label> & labels = {} ); |
---|
[daf1af8] | 75 | |
---|
[35a2d47] | 76 | virtual NullStmt * clone() const override { return new NullStmt( *this ); } |
---|
| 77 | virtual void accept( Visitor & v ) override { v.visit( this ); } |
---|
[7870799] | 78 | virtual void accept( Visitor & v ) const override { v.visit( this ); } |
---|
[35a2d47] | 79 | virtual NullStmt * acceptMutator( Mutator & m ) override { return m.mutate( this ); } |
---|
| 80 | virtual void print( std::ostream & os, Indenter indent = {} ) const override; |
---|
[daf1af8] | 81 | }; |
---|
| 82 | |
---|
[0dd3a2f] | 83 | class ExprStmt : public Statement { |
---|
| 84 | public: |
---|
[35a2d47] | 85 | Expression * expr; |
---|
[65cdc1e] | 86 | |
---|
[35a2d47] | 87 | ExprStmt( Expression * expr ); |
---|
| 88 | ExprStmt( const ExprStmt & other ); |
---|
[0dd3a2f] | 89 | virtual ~ExprStmt(); |
---|
[51b7345] | 90 | |
---|
[35a2d47] | 91 | Expression * get_expr() { return expr; } |
---|
| 92 | void set_expr( Expression * newValue ) { expr = newValue; } |
---|
[51b7345] | 93 | |
---|
[35a2d47] | 94 | virtual ExprStmt * clone() const override { return new ExprStmt( *this ); } |
---|
| 95 | virtual void accept( Visitor & v ) override { v.visit( this ); } |
---|
[7870799] | 96 | virtual void accept( Visitor & v ) const override { v.visit( this ); } |
---|
[35a2d47] | 97 | virtual Statement * acceptMutator( Mutator & m ) override { return m.mutate( this ); } |
---|
| 98 | virtual void print( std::ostream & os, Indenter indent = {} ) const override; |
---|
[0dd3a2f] | 99 | }; |
---|
[51b7345] | 100 | |
---|
[7f5566b] | 101 | class AsmStmt : public Statement { |
---|
| 102 | public: |
---|
[65cdc1e] | 103 | bool voltile; |
---|
[35a2d47] | 104 | Expression * instruction; |
---|
[65cdc1e] | 105 | std::list<Expression *> output, input; |
---|
| 106 | std::list<ConstantExpr *> clobber; |
---|
| 107 | std::list<Label> gotolabels; |
---|
| 108 | |
---|
[35a2d47] | 109 | AsmStmt( bool voltile, Expression * instruction, std::list<Expression *> output, std::list<Expression *> input, std::list<ConstantExpr *> clobber, std::list<Label> gotolabels ); |
---|
| 110 | AsmStmt( const AsmStmt & other ); |
---|
[7f5566b] | 111 | virtual ~AsmStmt(); |
---|
| 112 | |
---|
| 113 | bool get_voltile() { return voltile; } |
---|
| 114 | void set_voltile( bool newValue ) { voltile = newValue; } |
---|
[e612146c] | 115 | Expression * get_instruction() { return instruction; } |
---|
| 116 | void set_instruction( Expression * newValue ) { instruction = newValue; } |
---|
| 117 | std::list<Expression *> & get_output() { return output; } |
---|
| 118 | void set_output( const std::list<Expression *> & newValue ) { output = newValue; } |
---|
| 119 | std::list<Expression *> & get_input() { return input; } |
---|
[35a2d47] | 120 | void set_input( const std::list<Expression *> & newValue ) { input = newValue; } |
---|
[e612146c] | 121 | std::list<ConstantExpr *> & get_clobber() { return clobber; } |
---|
[35a2d47] | 122 | void set_clobber( const std::list<ConstantExpr *> & newValue ) { clobber = newValue; } |
---|
[e612146c] | 123 | std::list<Label> & get_gotolabels() { return gotolabels; } |
---|
[35a2d47] | 124 | void set_gotolabels( const std::list<Label> & newValue ) { gotolabels = newValue; } |
---|
[7f5566b] | 125 | |
---|
[7870799] | 126 | virtual AsmStmt * clone() const override { return new AsmStmt( *this ); } |
---|
| 127 | virtual void accept( Visitor & v ) override { v.visit( this ); } |
---|
| 128 | virtual void accept( Visitor & v ) const override { v.visit( this ); } |
---|
| 129 | virtual Statement * acceptMutator( Mutator & m ) override { return m.mutate( this ); } |
---|
| 130 | virtual void print( std::ostream & os, Indenter indent = {} ) const override; |
---|
[7f5566b] | 131 | }; |
---|
| 132 | |
---|
[cc32d83] | 133 | class DirectiveStmt : public Statement { |
---|
| 134 | public: |
---|
| 135 | std::string directive; |
---|
| 136 | |
---|
| 137 | DirectiveStmt( const std::string & ); |
---|
| 138 | virtual ~DirectiveStmt(){} |
---|
| 139 | |
---|
[7870799] | 140 | virtual DirectiveStmt * clone() const override { return new DirectiveStmt( *this ); } |
---|
| 141 | virtual void accept( Visitor & v ) override { v.visit( this ); } |
---|
| 142 | virtual void accept( Visitor & v ) const override { v.visit( this ); } |
---|
| 143 | virtual Statement * acceptMutator( Mutator & m ) override { return m.mutate( this ); } |
---|
| 144 | virtual void print( std::ostream & os, Indenter indent = {} ) const override; |
---|
[cc32d83] | 145 | }; |
---|
| 146 | |
---|
[0dd3a2f] | 147 | class IfStmt : public Statement { |
---|
| 148 | public: |
---|
[35a2d47] | 149 | Expression * condition; |
---|
| 150 | Statement * thenPart; |
---|
| 151 | Statement * elsePart; |
---|
[6d49ea3] | 152 | std::list<Statement *> initialization; |
---|
[65cdc1e] | 153 | |
---|
[35a2d47] | 154 | IfStmt( Expression * condition, Statement * thenPart, Statement * elsePart, |
---|
[6d49ea3] | 155 | std::list<Statement *> initialization = std::list<Statement *>() ); |
---|
[35a2d47] | 156 | IfStmt( const IfStmt & other ); |
---|
[0dd3a2f] | 157 | virtual ~IfStmt(); |
---|
| 158 | |
---|
[35a2d47] | 159 | std::list<Statement *> & get_initialization() { return initialization; } |
---|
| 160 | Expression * get_condition() { return condition; } |
---|
| 161 | void set_condition( Expression * newValue ) { condition = newValue; } |
---|
| 162 | Statement * get_thenPart() { return thenPart; } |
---|
| 163 | void set_thenPart( Statement * newValue ) { thenPart = newValue; } |
---|
| 164 | Statement * get_elsePart() { return elsePart; } |
---|
| 165 | void set_elsePart( Statement * newValue ) { elsePart = newValue; } |
---|
| 166 | |
---|
| 167 | virtual IfStmt * clone() const override { return new IfStmt( *this ); } |
---|
| 168 | virtual void accept( Visitor & v ) override { v.visit( this ); } |
---|
[7870799] | 169 | virtual void accept( Visitor & v ) const override { v.visit( this ); } |
---|
[35a2d47] | 170 | virtual Statement * acceptMutator( Mutator & m ) override { return m.mutate( this ); } |
---|
| 171 | virtual void print( std::ostream & os, Indenter indent = {} ) const override; |
---|
[51b7345] | 172 | }; |
---|
| 173 | |
---|
[0dd3a2f] | 174 | class SwitchStmt : public Statement { |
---|
| 175 | public: |
---|
[65cdc1e] | 176 | Expression * condition; |
---|
[871cdb4] | 177 | std::list<Statement *> statements; |
---|
[65cdc1e] | 178 | |
---|
[35a2d47] | 179 | SwitchStmt( Expression * condition, const std::list<Statement *> & statements ); |
---|
| 180 | SwitchStmt( const SwitchStmt & other ); |
---|
[0dd3a2f] | 181 | virtual ~SwitchStmt(); |
---|
[51b7345] | 182 | |
---|
[35a2d47] | 183 | Expression * get_condition() { return condition; } |
---|
| 184 | void set_condition( Expression * newValue ) { condition = newValue; } |
---|
[51b7345] | 185 | |
---|
[8688ce1] | 186 | std::list<Statement *> & get_statements() { return statements; } |
---|
[51b7345] | 187 | |
---|
[35a2d47] | 188 | virtual void accept( Visitor & v ) override { v.visit( this ); } |
---|
[7870799] | 189 | virtual void accept( Visitor & v ) const override { v.visit( this ); } |
---|
[35a2d47] | 190 | virtual Statement * acceptMutator( Mutator & m ) override { return m.mutate( this ); } |
---|
[51b7345] | 191 | |
---|
[35a2d47] | 192 | virtual SwitchStmt * clone() const override { return new SwitchStmt( *this ); } |
---|
| 193 | virtual void print( std::ostream & os, Indenter indent = {} ) const override; |
---|
[871cdb4] | 194 | |
---|
[51b7345] | 195 | }; |
---|
| 196 | |
---|
[0dd3a2f] | 197 | class CaseStmt : public Statement { |
---|
| 198 | public: |
---|
[65cdc1e] | 199 | Expression * condition; |
---|
| 200 | std::list<Statement *> stmts; |
---|
| 201 | |
---|
[35a2d47] | 202 | CaseStmt( Expression * conditions, const std::list<Statement *> & stmts, bool isdef = false ) throw (SemanticErrorException); |
---|
| 203 | CaseStmt( const CaseStmt & other ); |
---|
[0dd3a2f] | 204 | virtual ~CaseStmt(); |
---|
| 205 | |
---|
[ba3706f] | 206 | static CaseStmt * makeDefault( const std::list<Label> & labels = {}, std::list<Statement *> stmts = std::list<Statement *>() ); |
---|
[b2152e7a] | 207 | |
---|
[de62360d] | 208 | bool isDefault() const { return _isDefault; } |
---|
[0dd3a2f] | 209 | void set_default(bool b) { _isDefault = b; } |
---|
| 210 | |
---|
[35a2d47] | 211 | Expression * & get_condition() { return condition; } |
---|
| 212 | void set_condition( Expression * newValue ) { condition = newValue; } |
---|
[0dd3a2f] | 213 | |
---|
[35a2d47] | 214 | std::list<Statement *> & get_statements() { return stmts; } |
---|
| 215 | void set_statements( std::list<Statement *> & newValue ) { stmts = newValue; } |
---|
[3be261a] | 216 | |
---|
[35a2d47] | 217 | virtual void accept( Visitor & v ) override { v.visit( this ); } |
---|
[7870799] | 218 | virtual void accept( Visitor & v ) const override { v.visit( this ); } |
---|
[35a2d47] | 219 | virtual Statement * acceptMutator( Mutator & m ) override { return m.mutate( this ); } |
---|
[0dd3a2f] | 220 | |
---|
[35a2d47] | 221 | virtual CaseStmt * clone() const override { return new CaseStmt( *this ); } |
---|
| 222 | virtual void print( std::ostream & os, Indenter indent = {} ) const override; |
---|
[0dd3a2f] | 223 | private: |
---|
| 224 | bool _isDefault; |
---|
[51b7345] | 225 | }; |
---|
| 226 | |
---|
[0dd3a2f] | 227 | class WhileStmt : public Statement { |
---|
| 228 | public: |
---|
[35a2d47] | 229 | Expression * condition; |
---|
| 230 | Statement * body; |
---|
[ee3c93d] | 231 | std::list<Statement *> initialization; |
---|
[65cdc1e] | 232 | bool isDoWhile; |
---|
| 233 | |
---|
[35a2d47] | 234 | WhileStmt( Expression * condition, Statement * body, std::list<Statement *> & initialization, bool isDoWhile = false ); |
---|
| 235 | WhileStmt( const WhileStmt & other ); |
---|
[0dd3a2f] | 236 | virtual ~WhileStmt(); |
---|
| 237 | |
---|
[35a2d47] | 238 | Expression * get_condition() { return condition; } |
---|
| 239 | void set_condition( Expression * newValue ) { condition = newValue; } |
---|
| 240 | Statement * get_body() { return body; } |
---|
| 241 | void set_body( Statement * newValue ) { body = newValue; } |
---|
[0dd3a2f] | 242 | bool get_isDoWhile() { return isDoWhile; } |
---|
| 243 | void set_isDoWhile( bool newValue ) { isDoWhile = newValue; } |
---|
[3be261a] | 244 | |
---|
[35a2d47] | 245 | virtual WhileStmt * clone() const override { return new WhileStmt( *this ); } |
---|
| 246 | virtual void accept( Visitor & v ) override { v.visit( this ); } |
---|
[7870799] | 247 | virtual void accept( Visitor & v ) const override { v.visit( this ); } |
---|
[35a2d47] | 248 | virtual Statement * acceptMutator( Mutator & m ) override { return m.mutate( this ); } |
---|
| 249 | virtual void print( std::ostream & os, Indenter indent = {} ) const override; |
---|
[51b7345] | 250 | }; |
---|
| 251 | |
---|
[0dd3a2f] | 252 | class ForStmt : public Statement { |
---|
| 253 | public: |
---|
[65cdc1e] | 254 | std::list<Statement *> initialization; |
---|
[35a2d47] | 255 | Expression * condition; |
---|
| 256 | Expression * increment; |
---|
| 257 | Statement * body; |
---|
[65cdc1e] | 258 | |
---|
[0608e007] | 259 | ForStmt( std::list<Statement *> initialization, Expression * condition = nullptr, Expression * increment = nullptr, Statement * body = nullptr ); |
---|
[35a2d47] | 260 | ForStmt( const ForStmt & other ); |
---|
[0dd3a2f] | 261 | virtual ~ForStmt(); |
---|
| 262 | |
---|
[35a2d47] | 263 | std::list<Statement *> & get_initialization() { return initialization; } |
---|
| 264 | Expression * get_condition() { return condition; } |
---|
| 265 | void set_condition( Expression * newValue ) { condition = newValue; } |
---|
| 266 | Expression * get_increment() { return increment; } |
---|
| 267 | void set_increment( Expression * newValue ) { increment = newValue; } |
---|
| 268 | Statement * get_body() { return body; } |
---|
| 269 | void set_body( Statement * newValue ) { body = newValue; } |
---|
| 270 | |
---|
| 271 | virtual ForStmt * clone() const override { return new ForStmt( *this ); } |
---|
| 272 | virtual void accept( Visitor & v ) override { v.visit( this ); } |
---|
[7870799] | 273 | virtual void accept( Visitor & v ) const override { v.visit( this ); } |
---|
[35a2d47] | 274 | virtual Statement * acceptMutator( Mutator & m ) override { return m.mutate( this ); } |
---|
| 275 | virtual void print( std::ostream & os, Indenter indent = {} ) const override; |
---|
[51b7345] | 276 | }; |
---|
| 277 | |
---|
[0dd3a2f] | 278 | class BranchStmt : public Statement { |
---|
| 279 | public: |
---|
[6a276a0] | 280 | enum Type { Goto = 0, Break, Continue, FallThrough, FallThroughDefault }; |
---|
[0dd3a2f] | 281 | |
---|
[65cdc1e] | 282 | // originalTarget kept for error messages. |
---|
| 283 | const Label originalTarget; |
---|
| 284 | Label target; |
---|
[35a2d47] | 285 | Expression * computedTarget; |
---|
[65cdc1e] | 286 | Type type; |
---|
| 287 | |
---|
[a16764a6] | 288 | BranchStmt( Label target, Type ) throw (SemanticErrorException); |
---|
[35a2d47] | 289 | BranchStmt( Expression * computedTarget, Type ) throw (SemanticErrorException); |
---|
[0dd3a2f] | 290 | |
---|
[be5aa1b] | 291 | Label get_originalTarget() { return originalTarget; } |
---|
[0dd3a2f] | 292 | Label get_target() { return target; } |
---|
| 293 | void set_target( Label newValue ) { target = newValue; } |
---|
[3be261a] | 294 | |
---|
[35a2d47] | 295 | Expression * get_computedTarget() { return computedTarget; } |
---|
[0dd3a2f] | 296 | void set_target( Expression * newValue ) { computedTarget = newValue; } |
---|
| 297 | |
---|
| 298 | Type get_type() { return type; } |
---|
[35a2d47] | 299 | const char * get_typename() { return brType[ type ]; } |
---|
[0dd3a2f] | 300 | |
---|
[35a2d47] | 301 | virtual BranchStmt * clone() const override { return new BranchStmt( *this ); } |
---|
| 302 | virtual void accept( Visitor & v ) override { v.visit( this ); } |
---|
[7870799] | 303 | virtual void accept( Visitor & v ) const override { v.visit( this ); } |
---|
[35a2d47] | 304 | virtual Statement * acceptMutator( Mutator & m ) override { return m.mutate( this ); } |
---|
| 305 | virtual void print( std::ostream & os, Indenter indent = {} ) const override; |
---|
[0dd3a2f] | 306 | private: |
---|
[35a2d47] | 307 | static const char * brType[]; |
---|
[51b7345] | 308 | }; |
---|
| 309 | |
---|
[0dd3a2f] | 310 | class ReturnStmt : public Statement { |
---|
| 311 | public: |
---|
[35a2d47] | 312 | Expression * expr; |
---|
[65cdc1e] | 313 | |
---|
[35a2d47] | 314 | ReturnStmt( Expression * expr ); |
---|
| 315 | ReturnStmt( const ReturnStmt & other ); |
---|
[0dd3a2f] | 316 | virtual ~ReturnStmt(); |
---|
| 317 | |
---|
[35a2d47] | 318 | Expression * get_expr() { return expr; } |
---|
| 319 | void set_expr( Expression * newValue ) { expr = newValue; } |
---|
[3be261a] | 320 | |
---|
[35a2d47] | 321 | virtual ReturnStmt * clone() const override { return new ReturnStmt( *this ); } |
---|
| 322 | virtual void accept( Visitor & v ) override { v.visit( this ); } |
---|
[7870799] | 323 | virtual void accept( Visitor & v ) const override { v.visit( this ); } |
---|
[35a2d47] | 324 | virtual Statement * acceptMutator( Mutator & m ) override { return m.mutate( this ); } |
---|
| 325 | virtual void print( std::ostream & os, Indenter indent = {} ) const override; |
---|
[51b7345] | 326 | }; |
---|
| 327 | |
---|
[daf1af8] | 328 | class ThrowStmt : public Statement { |
---|
[0dd3a2f] | 329 | public: |
---|
[daf1af8] | 330 | enum Kind { Terminate, Resume }; |
---|
[51b7345] | 331 | |
---|
[65cdc1e] | 332 | const Kind kind; |
---|
| 333 | Expression * expr; |
---|
| 334 | Expression * target; |
---|
| 335 | |
---|
[ba3706f] | 336 | ThrowStmt( Kind kind, Expression * expr, Expression * target = nullptr ); |
---|
[35a2d47] | 337 | ThrowStmt( const ThrowStmt & other ); |
---|
[daf1af8] | 338 | virtual ~ThrowStmt(); |
---|
| 339 | |
---|
| 340 | Kind get_kind() { return kind; } |
---|
| 341 | Expression * get_expr() { return expr; } |
---|
| 342 | void set_expr( Expression * newExpr ) { expr = newExpr; } |
---|
| 343 | Expression * get_target() { return target; } |
---|
| 344 | void set_target( Expression * newTarget ) { target = newTarget; } |
---|
| 345 | |
---|
[35a2d47] | 346 | virtual ThrowStmt * clone() const override { return new ThrowStmt( *this ); } |
---|
| 347 | virtual void accept( Visitor & v ) override { v.visit( this ); } |
---|
[7870799] | 348 | virtual void accept( Visitor & v ) const override { v.visit( this ); } |
---|
[35a2d47] | 349 | virtual Statement * acceptMutator( Mutator & m ) override { return m.mutate( this ); } |
---|
| 350 | virtual void print( std::ostream & os, Indenter indent = {} ) const override; |
---|
[51b7345] | 351 | }; |
---|
| 352 | |
---|
[3be261a] | 353 | class TryStmt : public Statement { |
---|
[0dd3a2f] | 354 | public: |
---|
[871cdb4] | 355 | CompoundStmt * block; |
---|
[65cdc1e] | 356 | std::list<CatchStmt *> handlers; |
---|
[871cdb4] | 357 | FinallyStmt * finallyBlock; |
---|
[65cdc1e] | 358 | |
---|
[0608e007] | 359 | TryStmt( CompoundStmt * tryBlock, std::list<CatchStmt *> & handlers, FinallyStmt * finallyBlock = nullptr ); |
---|
[35a2d47] | 360 | TryStmt( const TryStmt & other ); |
---|
[0dd3a2f] | 361 | virtual ~TryStmt(); |
---|
| 362 | |
---|
[35a2d47] | 363 | CompoundStmt * get_block() const { return block; } |
---|
| 364 | void set_block( CompoundStmt * newValue ) { block = newValue; } |
---|
[046e04a] | 365 | std::list<CatchStmt *>& get_catchers() { return handlers; } |
---|
[0dd3a2f] | 366 | |
---|
[35a2d47] | 367 | FinallyStmt * get_finally() const { return finallyBlock; } |
---|
| 368 | void set_finally( FinallyStmt * newValue ) { finallyBlock = newValue; } |
---|
[0dd3a2f] | 369 | |
---|
[35a2d47] | 370 | virtual TryStmt * clone() const override { return new TryStmt( *this ); } |
---|
| 371 | virtual void accept( Visitor & v ) override { v.visit( this ); } |
---|
[7870799] | 372 | virtual void accept( Visitor & v ) const override { v.visit( this ); } |
---|
[35a2d47] | 373 | virtual Statement * acceptMutator( Mutator & m ) override { return m.mutate( this ); } |
---|
| 374 | virtual void print( std::ostream & os, Indenter indent = {} ) const override; |
---|
[3be261a] | 375 | }; |
---|
[51b7345] | 376 | |
---|
[0dd3a2f] | 377 | class CatchStmt : public Statement { |
---|
| 378 | public: |
---|
[ca78437] | 379 | enum Kind { Terminate, Resume }; |
---|
| 380 | |
---|
[65cdc1e] | 381 | const Kind kind; |
---|
[35a2d47] | 382 | Declaration * decl; |
---|
| 383 | Expression * cond; |
---|
| 384 | Statement * body; |
---|
[65cdc1e] | 385 | |
---|
[35a2d47] | 386 | CatchStmt( Kind kind, Declaration * decl, |
---|
| 387 | Expression * cond, Statement * body ); |
---|
| 388 | CatchStmt( const CatchStmt & other ); |
---|
[0dd3a2f] | 389 | virtual ~CatchStmt(); |
---|
| 390 | |
---|
[ca78437] | 391 | Kind get_kind() { return kind; } |
---|
[35a2d47] | 392 | Declaration * get_decl() { return decl; } |
---|
| 393 | void set_decl( Declaration * newValue ) { decl = newValue; } |
---|
| 394 | Expression * get_cond() { return cond; } |
---|
| 395 | void set_cond( Expression * newCond ) { cond = newCond; } |
---|
| 396 | Statement * get_body() { return body; } |
---|
| 397 | void set_body( Statement * newValue ) { body = newValue; } |
---|
| 398 | |
---|
| 399 | virtual CatchStmt * clone() const override { return new CatchStmt( *this ); } |
---|
| 400 | virtual void accept( Visitor & v ) override { v.visit( this ); } |
---|
[7870799] | 401 | virtual void accept( Visitor & v ) const override { v.visit( this ); } |
---|
[35a2d47] | 402 | virtual Statement * acceptMutator( Mutator & m ) override { return m.mutate( this ); } |
---|
| 403 | virtual void print( std::ostream & os, Indenter indent = {} ) const override; |
---|
[51b7345] | 404 | }; |
---|
| 405 | |
---|
[3be261a] | 406 | class FinallyStmt : public Statement { |
---|
[0dd3a2f] | 407 | public: |
---|
[35a2d47] | 408 | CompoundStmt * block; |
---|
[65cdc1e] | 409 | |
---|
[35a2d47] | 410 | FinallyStmt( CompoundStmt * block ); |
---|
| 411 | FinallyStmt( const FinallyStmt & other ); |
---|
[0dd3a2f] | 412 | virtual ~FinallyStmt(); |
---|
| 413 | |
---|
[35a2d47] | 414 | CompoundStmt * get_block() const { return block; } |
---|
| 415 | void set_block( CompoundStmt * newValue ) { block = newValue; } |
---|
[3be261a] | 416 | |
---|
[35a2d47] | 417 | virtual FinallyStmt * clone() const override { return new FinallyStmt( *this ); } |
---|
| 418 | virtual void accept( Visitor & v ) override { v.visit( this ); } |
---|
[7870799] | 419 | virtual void accept( Visitor & v ) const override { v.visit( this ); } |
---|
[35a2d47] | 420 | virtual Statement * acceptMutator( Mutator & m ) override { return m.mutate( this ); } |
---|
| 421 | virtual void print( std::ostream & os, Indenter indent = {} ) const override; |
---|
[3be261a] | 422 | }; |
---|
[51b7345] | 423 | |
---|
[37cdd97] | 424 | class SuspendStmt : public Statement { |
---|
| 425 | public: |
---|
| 426 | CompoundStmt * then = nullptr; |
---|
[427854b] | 427 | enum Type { None, Coroutine, Generator } type = None; |
---|
[37cdd97] | 428 | |
---|
| 429 | SuspendStmt() = default; |
---|
| 430 | SuspendStmt( const SuspendStmt & ); |
---|
| 431 | virtual ~SuspendStmt(); |
---|
| 432 | |
---|
| 433 | virtual SuspendStmt * clone() const override { return new SuspendStmt( *this ); } |
---|
| 434 | virtual void accept( Visitor & v ) override { v.visit( this ); } |
---|
| 435 | virtual void accept( Visitor & v ) const override { v.visit( this ); } |
---|
| 436 | virtual Statement * acceptMutator( Mutator & m ) override { return m.mutate( this ); } |
---|
| 437 | virtual void print( std::ostream & os, Indenter indent = {} ) const override; |
---|
| 438 | }; |
---|
| 439 | |
---|
[135b431] | 440 | class WaitForStmt : public Statement { |
---|
| 441 | public: |
---|
| 442 | |
---|
| 443 | struct Target { |
---|
| 444 | Expression * function; |
---|
| 445 | std::list<Expression * > arguments; |
---|
| 446 | }; |
---|
| 447 | |
---|
| 448 | struct Clause { |
---|
| 449 | Target target; |
---|
| 450 | Statement * statement; |
---|
| 451 | Expression * condition; |
---|
| 452 | }; |
---|
| 453 | |
---|
[ba3706f] | 454 | WaitForStmt(); |
---|
[135b431] | 455 | WaitForStmt( const WaitForStmt & ); |
---|
| 456 | virtual ~WaitForStmt(); |
---|
| 457 | |
---|
| 458 | std::vector<Clause> clauses; |
---|
| 459 | |
---|
| 460 | struct { |
---|
| 461 | Expression * time; |
---|
| 462 | Statement * statement; |
---|
| 463 | Expression * condition; |
---|
| 464 | } timeout; |
---|
| 465 | |
---|
| 466 | struct { |
---|
| 467 | Statement * statement; |
---|
| 468 | Expression * condition; |
---|
| 469 | } orelse; |
---|
| 470 | |
---|
[35a2d47] | 471 | virtual WaitForStmt * clone() const override { return new WaitForStmt( *this ); } |
---|
| 472 | virtual void accept( Visitor & v ) override { v.visit( this ); } |
---|
[7870799] | 473 | virtual void accept( Visitor & v ) const override { v.visit( this ); } |
---|
[35a2d47] | 474 | virtual Statement * acceptMutator( Mutator & m ) override { return m.mutate( this ); } |
---|
| 475 | virtual void print( std::ostream & os, Indenter indent = {} ) const override; |
---|
[135b431] | 476 | |
---|
| 477 | }; |
---|
| 478 | |
---|
[e67991f] | 479 | // class WithStmt : public Statement { |
---|
| 480 | // public: |
---|
| 481 | // std::list< Expression * > exprs; |
---|
| 482 | // Statement * stmt; |
---|
| 483 | |
---|
| 484 | // WithStmt( const std::list< Expression * > & exprs, Statement * stmt ); |
---|
| 485 | // WithStmt( const WithStmt & other ); |
---|
| 486 | // virtual ~WithStmt(); |
---|
| 487 | |
---|
| 488 | // virtual WithStmt * clone() const override { return new WithStmt( *this ); } |
---|
| 489 | // virtual void accept( Visitor & v ) override { v.visit( this ); } |
---|
| 490 | // virtual void accept( Visitor & v ) const override { v.visit( this ); } |
---|
| 491 | // virtual Statement * acceptMutator( Mutator & m ) override { return m.mutate( this ); } |
---|
| 492 | // virtual void print( std::ostream & os, Indenter indent = {} ) const override; |
---|
| 493 | // }; |
---|
[61255ad] | 494 | |
---|
[51b7345] | 495 | |
---|
| 496 | // represents a declaration that occurs as part of a compound statement |
---|
[0dd3a2f] | 497 | class DeclStmt : public Statement { |
---|
| 498 | public: |
---|
[35a2d47] | 499 | Declaration * decl; |
---|
[65cdc1e] | 500 | |
---|
[35a2d47] | 501 | DeclStmt( Declaration * decl ); |
---|
| 502 | DeclStmt( const DeclStmt & other ); |
---|
[0dd3a2f] | 503 | virtual ~DeclStmt(); |
---|
| 504 | |
---|
[35a2d47] | 505 | Declaration * get_decl() const { return decl; } |
---|
| 506 | void set_decl( Declaration * newValue ) { decl = newValue; } |
---|
[0dd3a2f] | 507 | |
---|
[35a2d47] | 508 | virtual DeclStmt * clone() const override { return new DeclStmt( *this ); } |
---|
| 509 | virtual void accept( Visitor & v ) override { v.visit( this ); } |
---|
[7870799] | 510 | virtual void accept( Visitor & v ) const override { v.visit( this ); } |
---|
[35a2d47] | 511 | virtual Statement * acceptMutator( Mutator & m ) override { return m.mutate( this ); } |
---|
| 512 | virtual void print( std::ostream & os, Indenter indent = {} ) const override; |
---|
[51b7345] | 513 | }; |
---|
| 514 | |
---|
[f1b1e4c] | 515 | |
---|
[35a2d47] | 516 | /// represents an implicit application of a constructor or destructor. Qualifiers are replaced immediately before and |
---|
| 517 | /// after the call so that qualified objects can be constructed with the same functions as unqualified objects. |
---|
[f1b1e4c] | 518 | class ImplicitCtorDtorStmt : public Statement { |
---|
| 519 | public: |
---|
[c570806] | 520 | // the constructor/destructor call statement; owned here for a while, eventually transferred elsewhere |
---|
[65cdc1e] | 521 | Statement * callStmt; |
---|
| 522 | |
---|
[f1b1e4c] | 523 | ImplicitCtorDtorStmt( Statement * callStmt ); |
---|
| 524 | ImplicitCtorDtorStmt( const ImplicitCtorDtorStmt & other ); |
---|
| 525 | virtual ~ImplicitCtorDtorStmt(); |
---|
| 526 | |
---|
[35a2d47] | 527 | Statement * get_callStmt() const { return callStmt; } |
---|
[f1b1e4c] | 528 | void set_callStmt( Statement * newValue ) { callStmt = newValue; } |
---|
| 529 | |
---|
[35a2d47] | 530 | virtual ImplicitCtorDtorStmt * clone() const override { return new ImplicitCtorDtorStmt( *this ); } |
---|
| 531 | virtual void accept( Visitor & v ) override { v.visit( this ); } |
---|
[7870799] | 532 | virtual void accept( Visitor & v ) const override { v.visit( this ); } |
---|
[35a2d47] | 533 | virtual Statement * acceptMutator( Mutator & m ) override { return m.mutate( this ); } |
---|
| 534 | virtual void print( std::ostream & os, Indenter indent = {} ) const override; |
---|
[f1b1e4c] | 535 | }; |
---|
| 536 | |
---|
[0dd3a2f] | 537 | // Local Variables: // |
---|
| 538 | // tab-width: 4 // |
---|
| 539 | // mode: c++ // |
---|
| 540 | // compile-command: "make install" // |
---|
| 541 | // End: // |
---|