| 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
 | 
|---|
| 11 | // Last Modified By : Peter A. Buhr
 | 
|---|
| 12 | // Last Modified On : Fri Jan 10 14:13:24 2020
 | 
|---|
| 13 | // Update Count     : 85
 | 
|---|
| 14 | //
 | 
|---|
| 15 | 
 | 
|---|
| 16 | #pragma once
 | 
|---|
| 17 | 
 | 
|---|
| 18 | #include <iosfwd>                  // for ostream
 | 
|---|
| 19 | #include <list>                    // for list
 | 
|---|
| 20 | #include <memory>                  // for allocator
 | 
|---|
| 21 | #include <vector>                                  // for vector
 | 
|---|
| 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;
 | 
|---|
| 34 | 
 | 
|---|
| 35 | class Statement : public BaseSyntaxNode {
 | 
|---|
| 36 |   public:
 | 
|---|
| 37 |         std::list<Label> labels;
 | 
|---|
| 38 | 
 | 
|---|
| 39 |         Statement( const std::list<Label> & labels = {} );
 | 
|---|
| 40 |         virtual ~Statement();
 | 
|---|
| 41 | 
 | 
|---|
| 42 |         std::list<Label> & get_labels() { return labels; }
 | 
|---|
| 43 |         const std::list<Label> & get_labels() const { return labels; }
 | 
|---|
| 44 | 
 | 
|---|
| 45 |         virtual Statement * clone() const override = 0;
 | 
|---|
| 46 |         virtual void accept( Visitor & v ) override = 0;
 | 
|---|
| 47 |         virtual void accept( Visitor & v ) const override = 0;
 | 
|---|
| 48 |         virtual Statement * acceptMutator( Mutator & m ) override = 0;
 | 
|---|
| 49 |         virtual void print( std::ostream & os, Indenter indent = {} ) const override;
 | 
|---|
| 50 | };
 | 
|---|
| 51 | 
 | 
|---|
| 52 | class CompoundStmt : public Statement {
 | 
|---|
| 53 |   public:
 | 
|---|
| 54 |         std::list<Statement*> kids;
 | 
|---|
| 55 | 
 | 
|---|
| 56 |         CompoundStmt();
 | 
|---|
| 57 |         CompoundStmt( std::list<Statement *> stmts );
 | 
|---|
| 58 |         CompoundStmt( const CompoundStmt & other );
 | 
|---|
| 59 |         virtual ~CompoundStmt();
 | 
|---|
| 60 | 
 | 
|---|
| 61 |         std::list<Statement*>& get_kids() { return kids; }
 | 
|---|
| 62 |         void push_back( Statement * stmt ) { kids.push_back( stmt ); }
 | 
|---|
| 63 |         void push_front( Statement * stmt ) { kids.push_front( stmt ); }
 | 
|---|
| 64 | 
 | 
|---|
| 65 |         virtual CompoundStmt * clone() const override { return new CompoundStmt( *this ); }
 | 
|---|
| 66 |         virtual void accept( Visitor & v ) override { v.visit( this ); }
 | 
|---|
| 67 |         virtual void accept( Visitor & v ) const override { v.visit( this ); }
 | 
|---|
| 68 |         virtual CompoundStmt * acceptMutator( Mutator & m )  override { return m.mutate( this ); }
 | 
|---|
| 69 |         virtual void print( std::ostream & os, Indenter indent = {} ) const override;
 | 
|---|
| 70 | };
 | 
|---|
| 71 | 
 | 
|---|
| 72 | class NullStmt : public Statement {
 | 
|---|
| 73 |   public:
 | 
|---|
| 74 |         NullStmt( const std::list<Label> & labels = {} );
 | 
|---|
| 75 | 
 | 
|---|
| 76 |         virtual NullStmt * clone() const override { return new NullStmt( *this ); }
 | 
|---|
| 77 |         virtual void accept( Visitor & v ) override { v.visit( this ); }
 | 
|---|
| 78 |         virtual void accept( Visitor & v ) const override { v.visit( this ); }
 | 
|---|
| 79 |         virtual NullStmt * acceptMutator( Mutator & m )  override { return m.mutate( this ); }
 | 
|---|
| 80 |         virtual void print( std::ostream & os, Indenter indent = {} ) const override;
 | 
|---|
| 81 | };
 | 
|---|
| 82 | 
 | 
|---|
| 83 | class ExprStmt : public Statement {
 | 
|---|
| 84 |   public:
 | 
|---|
| 85 |         Expression * expr;
 | 
|---|
| 86 | 
 | 
|---|
| 87 |         ExprStmt( Expression * expr );
 | 
|---|
| 88 |         ExprStmt( const ExprStmt & other );
 | 
|---|
| 89 |         virtual ~ExprStmt();
 | 
|---|
| 90 | 
 | 
|---|
| 91 |         Expression * get_expr() { return expr; }
 | 
|---|
| 92 |         void set_expr( Expression * newValue ) { expr = newValue; }
 | 
|---|
| 93 | 
 | 
|---|
| 94 |         virtual ExprStmt * clone() const override { return new ExprStmt( *this ); }
 | 
|---|
| 95 |         virtual void accept( Visitor & v ) override { v.visit( this ); }
 | 
|---|
| 96 |         virtual void accept( Visitor & v ) const override { v.visit( this ); }
 | 
|---|
| 97 |         virtual Statement * acceptMutator( Mutator & m )  override { return m.mutate( this ); }
 | 
|---|
| 98 |         virtual void print( std::ostream & os, Indenter indent = {} ) const override;
 | 
|---|
| 99 | };
 | 
|---|
| 100 | 
 | 
|---|
| 101 | class AsmStmt : public Statement {
 | 
|---|
| 102 |   public:
 | 
|---|
| 103 |         bool voltile;
 | 
|---|
| 104 |         Expression * instruction;
 | 
|---|
| 105 |         std::list<Expression *> output, input;
 | 
|---|
| 106 |         std::list<ConstantExpr *> clobber;
 | 
|---|
| 107 |         std::list<Label> gotolabels;
 | 
|---|
| 108 | 
 | 
|---|
| 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 );
 | 
|---|
| 111 |         virtual ~AsmStmt();
 | 
|---|
| 112 | 
 | 
|---|
| 113 |         bool get_voltile() { return voltile; }
 | 
|---|
| 114 |         void set_voltile( bool newValue ) { voltile = newValue; }
 | 
|---|
| 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; }
 | 
|---|
| 120 |         void set_input( const std::list<Expression *> & newValue ) { input = newValue; }
 | 
|---|
| 121 |         std::list<ConstantExpr *> & get_clobber() { return clobber; }
 | 
|---|
| 122 |         void set_clobber( const std::list<ConstantExpr *> & newValue ) { clobber = newValue; }
 | 
|---|
| 123 |         std::list<Label> & get_gotolabels() { return gotolabels; }
 | 
|---|
| 124 |         void set_gotolabels( const std::list<Label> & newValue ) { gotolabels = newValue; }
 | 
|---|
| 125 | 
 | 
|---|
| 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;
 | 
|---|
| 131 | };
 | 
|---|
| 132 | 
 | 
|---|
| 133 | class DirectiveStmt : public Statement {
 | 
|---|
| 134 |         public:
 | 
|---|
| 135 |         std::string directive;
 | 
|---|
| 136 | 
 | 
|---|
| 137 |         DirectiveStmt( const std::string & );
 | 
|---|
| 138 |         virtual ~DirectiveStmt(){}
 | 
|---|
| 139 | 
 | 
|---|
| 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;
 | 
|---|
| 145 | };
 | 
|---|
| 146 | 
 | 
|---|
| 147 | class IfStmt : public Statement {
 | 
|---|
| 148 |   public:
 | 
|---|
| 149 |         Expression * condition;
 | 
|---|
| 150 |         Statement * thenPart;
 | 
|---|
| 151 |         Statement * elsePart;
 | 
|---|
| 152 |         std::list<Statement *> initialization;
 | 
|---|
| 153 | 
 | 
|---|
| 154 |         IfStmt( Expression * condition, Statement * thenPart, Statement * elsePart,
 | 
|---|
| 155 |                         std::list<Statement *> initialization = std::list<Statement *>() );
 | 
|---|
| 156 |         IfStmt( const IfStmt & other );
 | 
|---|
| 157 |         virtual ~IfStmt();
 | 
|---|
| 158 | 
 | 
|---|
| 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 ); }
 | 
|---|
| 169 |         virtual void accept( Visitor & v ) const override { v.visit( this ); }
 | 
|---|
| 170 |         virtual Statement * acceptMutator( Mutator & m )  override { return m.mutate( this ); }
 | 
|---|
| 171 |         virtual void print( std::ostream & os, Indenter indent = {} ) const override;
 | 
|---|
| 172 | };
 | 
|---|
| 173 | 
 | 
|---|
| 174 | class SwitchStmt : public Statement {
 | 
|---|
| 175 |   public:
 | 
|---|
| 176 |         Expression * condition;
 | 
|---|
| 177 |         std::list<Statement *> statements;
 | 
|---|
| 178 | 
 | 
|---|
| 179 |         SwitchStmt( Expression * condition, const std::list<Statement *> & statements );
 | 
|---|
| 180 |         SwitchStmt( const SwitchStmt & other );
 | 
|---|
| 181 |         virtual ~SwitchStmt();
 | 
|---|
| 182 | 
 | 
|---|
| 183 |         Expression * get_condition() { return condition; }
 | 
|---|
| 184 |         void set_condition( Expression * newValue ) { condition = newValue; }
 | 
|---|
| 185 | 
 | 
|---|
| 186 |         std::list<Statement *> & get_statements() { return statements; }
 | 
|---|
| 187 | 
 | 
|---|
| 188 |         virtual void accept( Visitor & v ) override { v.visit( this ); }
 | 
|---|
| 189 |         virtual void accept( Visitor & v ) const override { v.visit( this ); }
 | 
|---|
| 190 |         virtual Statement * acceptMutator( Mutator & m )  override { return m.mutate( this ); }
 | 
|---|
| 191 | 
 | 
|---|
| 192 |         virtual SwitchStmt * clone() const override { return new SwitchStmt( *this ); }
 | 
|---|
| 193 |         virtual void print( std::ostream & os, Indenter indent = {} ) const override;
 | 
|---|
| 194 | 
 | 
|---|
| 195 | };
 | 
|---|
| 196 | 
 | 
|---|
| 197 | class CaseStmt : public Statement {
 | 
|---|
| 198 |   public:
 | 
|---|
| 199 |         Expression * condition;
 | 
|---|
| 200 |         std::list<Statement *> stmts;
 | 
|---|
| 201 | 
 | 
|---|
| 202 |         CaseStmt( Expression * conditions, const std::list<Statement *> & stmts, bool isdef = false ) throw (SemanticErrorException);
 | 
|---|
| 203 |         CaseStmt( const CaseStmt & other );
 | 
|---|
| 204 |         virtual ~CaseStmt();
 | 
|---|
| 205 | 
 | 
|---|
| 206 |         static CaseStmt * makeDefault( const std::list<Label> & labels = {}, std::list<Statement *> stmts = std::list<Statement *>() );
 | 
|---|
| 207 | 
 | 
|---|
| 208 |         bool isDefault() const { return _isDefault; }
 | 
|---|
| 209 |         void set_default(bool b) { _isDefault = b; }
 | 
|---|
| 210 | 
 | 
|---|
| 211 |         Expression * & get_condition() { return condition; }
 | 
|---|
| 212 |         void set_condition( Expression * newValue ) { condition = newValue; }
 | 
|---|
| 213 | 
 | 
|---|
| 214 |         std::list<Statement *> & get_statements() { return stmts; }
 | 
|---|
| 215 |         void set_statements( std::list<Statement *> & newValue ) { stmts = newValue; }
 | 
|---|
| 216 | 
 | 
|---|
| 217 |         virtual void accept( Visitor & v ) override { v.visit( this ); }
 | 
|---|
| 218 |         virtual void accept( Visitor & v ) const override { v.visit( this ); }
 | 
|---|
| 219 |         virtual Statement * acceptMutator( Mutator & m )  override { return m.mutate( this ); }
 | 
|---|
| 220 | 
 | 
|---|
| 221 |         virtual CaseStmt * clone() const override { return new CaseStmt( *this ); }
 | 
|---|
| 222 |         virtual void print( std::ostream & os, Indenter indent = {} ) const override;
 | 
|---|
| 223 |   private:
 | 
|---|
| 224 |         bool _isDefault;
 | 
|---|
| 225 | };
 | 
|---|
| 226 | 
 | 
|---|
| 227 | class WhileStmt : public Statement {
 | 
|---|
| 228 |   public:
 | 
|---|
| 229 |         Expression * condition;
 | 
|---|
| 230 |         Statement * body;
 | 
|---|
| 231 |         std::list<Statement *> initialization;
 | 
|---|
| 232 |         bool isDoWhile;
 | 
|---|
| 233 | 
 | 
|---|
| 234 |         WhileStmt( Expression * condition, Statement * body, std::list<Statement *> & initialization, bool isDoWhile = false );
 | 
|---|
| 235 |         WhileStmt( const WhileStmt & other );
 | 
|---|
| 236 |         virtual ~WhileStmt();
 | 
|---|
| 237 | 
 | 
|---|
| 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; }
 | 
|---|
| 242 |         bool get_isDoWhile() { return isDoWhile; }
 | 
|---|
| 243 |         void set_isDoWhile( bool newValue ) { isDoWhile = newValue; }
 | 
|---|
| 244 | 
 | 
|---|
| 245 |         virtual WhileStmt * clone() const override { return new WhileStmt( *this ); }
 | 
|---|
| 246 |         virtual void accept( Visitor & v ) override { v.visit( this ); }
 | 
|---|
| 247 |         virtual void accept( Visitor & v ) const override { v.visit( this ); }
 | 
|---|
| 248 |         virtual Statement * acceptMutator( Mutator & m )  override { return m.mutate( this ); }
 | 
|---|
| 249 |         virtual void print( std::ostream & os, Indenter indent = {} ) const override;
 | 
|---|
| 250 | };
 | 
|---|
| 251 | 
 | 
|---|
| 252 | class ForStmt : public Statement {
 | 
|---|
| 253 |   public:
 | 
|---|
| 254 |         std::list<Statement *> initialization;
 | 
|---|
| 255 |         Expression * condition;
 | 
|---|
| 256 |         Expression * increment;
 | 
|---|
| 257 |         Statement * body;
 | 
|---|
| 258 | 
 | 
|---|
| 259 |         ForStmt( std::list<Statement *> initialization, Expression * condition = nullptr, Expression * increment = nullptr, Statement * body = nullptr );
 | 
|---|
| 260 |         ForStmt( const ForStmt & other );
 | 
|---|
| 261 |         virtual ~ForStmt();
 | 
|---|
| 262 | 
 | 
|---|
| 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 ); }
 | 
|---|
| 273 |         virtual void accept( Visitor & v ) const override { v.visit( this ); }
 | 
|---|
| 274 |         virtual Statement * acceptMutator( Mutator & m )  override { return m.mutate( this ); }
 | 
|---|
| 275 |         virtual void print( std::ostream & os, Indenter indent = {} ) const override;
 | 
|---|
| 276 | };
 | 
|---|
| 277 | 
 | 
|---|
| 278 | class BranchStmt : public Statement {
 | 
|---|
| 279 |   public:
 | 
|---|
| 280 |         enum Type { Goto = 0, Break, Continue, FallThrough, FallThroughDefault };
 | 
|---|
| 281 | 
 | 
|---|
| 282 |         // originalTarget kept for error messages.
 | 
|---|
| 283 |         const Label originalTarget;
 | 
|---|
| 284 |         Label target;
 | 
|---|
| 285 |         Expression * computedTarget;
 | 
|---|
| 286 |         Type type;
 | 
|---|
| 287 | 
 | 
|---|
| 288 |         BranchStmt( Label target, Type ) throw (SemanticErrorException);
 | 
|---|
| 289 |         BranchStmt( Expression * computedTarget, Type ) throw (SemanticErrorException);
 | 
|---|
| 290 | 
 | 
|---|
| 291 |         Label get_originalTarget() { return originalTarget; }
 | 
|---|
| 292 |         Label get_target() { return target; }
 | 
|---|
| 293 |         void set_target( Label newValue ) { target = newValue; }
 | 
|---|
| 294 | 
 | 
|---|
| 295 |         Expression * get_computedTarget() { return computedTarget; }
 | 
|---|
| 296 |         void set_target( Expression * newValue ) { computedTarget = newValue; }
 | 
|---|
| 297 | 
 | 
|---|
| 298 |         Type get_type() { return type; }
 | 
|---|
| 299 |         const char * get_typename() { return brType[ type ]; }
 | 
|---|
| 300 | 
 | 
|---|
| 301 |         virtual BranchStmt * clone() const override { return new BranchStmt( *this ); }
 | 
|---|
| 302 |         virtual void accept( Visitor & v ) override { v.visit( this ); }
 | 
|---|
| 303 |         virtual void accept( Visitor & v ) const override { v.visit( this ); }
 | 
|---|
| 304 |         virtual Statement * acceptMutator( Mutator & m )  override { return m.mutate( this ); }
 | 
|---|
| 305 |         virtual void print( std::ostream & os, Indenter indent = {} ) const override;
 | 
|---|
| 306 |   private:
 | 
|---|
| 307 |         static const char * brType[];
 | 
|---|
| 308 | };
 | 
|---|
| 309 | 
 | 
|---|
| 310 | class ReturnStmt : public Statement {
 | 
|---|
| 311 |   public:
 | 
|---|
| 312 |         Expression * expr;
 | 
|---|
| 313 | 
 | 
|---|
| 314 |         ReturnStmt( Expression * expr );
 | 
|---|
| 315 |         ReturnStmt( const ReturnStmt & other );
 | 
|---|
| 316 |         virtual ~ReturnStmt();
 | 
|---|
| 317 | 
 | 
|---|
| 318 |         Expression * get_expr() { return expr; }
 | 
|---|
| 319 |         void set_expr( Expression * newValue ) { expr = newValue; }
 | 
|---|
| 320 | 
 | 
|---|
| 321 |         virtual ReturnStmt * clone() const override { return new ReturnStmt( *this ); }
 | 
|---|
| 322 |         virtual void accept( Visitor & v ) override { v.visit( this ); }
 | 
|---|
| 323 |         virtual void accept( Visitor & v ) const override { v.visit( this ); }
 | 
|---|
| 324 |         virtual Statement * acceptMutator( Mutator & m )  override { return m.mutate( this ); }
 | 
|---|
| 325 |         virtual void print( std::ostream & os, Indenter indent = {} ) const override;
 | 
|---|
| 326 | };
 | 
|---|
| 327 | 
 | 
|---|
| 328 | class ThrowStmt : public Statement {
 | 
|---|
| 329 |   public:
 | 
|---|
| 330 |         enum Kind { Terminate, Resume };
 | 
|---|
| 331 | 
 | 
|---|
| 332 |         const Kind kind;
 | 
|---|
| 333 |         Expression * expr;
 | 
|---|
| 334 |         Expression * target;
 | 
|---|
| 335 | 
 | 
|---|
| 336 |         ThrowStmt( Kind kind, Expression * expr, Expression * target = nullptr );
 | 
|---|
| 337 |         ThrowStmt( const ThrowStmt & other );
 | 
|---|
| 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 | 
 | 
|---|
| 346 |         virtual ThrowStmt * clone() const override { return new ThrowStmt( *this ); }
 | 
|---|
| 347 |         virtual void accept( Visitor & v ) override { v.visit( this ); }
 | 
|---|
| 348 |         virtual void accept( Visitor & v ) const override { v.visit( this ); }
 | 
|---|
| 349 |         virtual Statement * acceptMutator( Mutator & m )  override { return m.mutate( this ); }
 | 
|---|
| 350 |         virtual void print( std::ostream & os, Indenter indent = {} ) const override;
 | 
|---|
| 351 | };
 | 
|---|
| 352 | 
 | 
|---|
| 353 | class TryStmt : public Statement {
 | 
|---|
| 354 |   public:
 | 
|---|
| 355 |         CompoundStmt * block;
 | 
|---|
| 356 |         std::list<CatchStmt *> handlers;
 | 
|---|
| 357 |         FinallyStmt * finallyBlock;
 | 
|---|
| 358 | 
 | 
|---|
| 359 |         TryStmt( CompoundStmt * tryBlock, std::list<CatchStmt *> & handlers, FinallyStmt * finallyBlock = nullptr );
 | 
|---|
| 360 |         TryStmt( const TryStmt & other );
 | 
|---|
| 361 |         virtual ~TryStmt();
 | 
|---|
| 362 | 
 | 
|---|
| 363 |         CompoundStmt * get_block() const { return block; }
 | 
|---|
| 364 |         void set_block( CompoundStmt * newValue ) { block = newValue; }
 | 
|---|
| 365 |         std::list<CatchStmt *>& get_catchers() { return handlers; }
 | 
|---|
| 366 | 
 | 
|---|
| 367 |         FinallyStmt * get_finally() const { return finallyBlock; }
 | 
|---|
| 368 |         void set_finally( FinallyStmt * newValue ) { finallyBlock = newValue; }
 | 
|---|
| 369 | 
 | 
|---|
| 370 |         virtual TryStmt * clone() const override { return new TryStmt( *this ); }
 | 
|---|
| 371 |         virtual void accept( Visitor & v ) override { v.visit( this ); }
 | 
|---|
| 372 |         virtual void accept( Visitor & v ) const override { v.visit( this ); }
 | 
|---|
| 373 |         virtual Statement * acceptMutator( Mutator & m )  override { return m.mutate( this ); }
 | 
|---|
| 374 |         virtual void print( std::ostream & os, Indenter indent = {} ) const override;
 | 
|---|
| 375 | };
 | 
|---|
| 376 | 
 | 
|---|
| 377 | class CatchStmt : public Statement {
 | 
|---|
| 378 |   public:
 | 
|---|
| 379 |         enum Kind { Terminate, Resume };
 | 
|---|
| 380 | 
 | 
|---|
| 381 |         const Kind kind;
 | 
|---|
| 382 |         Declaration * decl;
 | 
|---|
| 383 |         Expression * cond;
 | 
|---|
| 384 |         Statement * body;
 | 
|---|
| 385 | 
 | 
|---|
| 386 |         CatchStmt( Kind kind, Declaration * decl,
 | 
|---|
| 387 |                    Expression * cond, Statement * body );
 | 
|---|
| 388 |         CatchStmt( const CatchStmt & other );
 | 
|---|
| 389 |         virtual ~CatchStmt();
 | 
|---|
| 390 | 
 | 
|---|
| 391 |         Kind get_kind() { return kind; }
 | 
|---|
| 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 ); }
 | 
|---|
| 401 |         virtual void accept( Visitor & v ) const override { v.visit( this ); }
 | 
|---|
| 402 |         virtual Statement * acceptMutator( Mutator & m )  override { return m.mutate( this ); }
 | 
|---|
| 403 |         virtual void print( std::ostream & os, Indenter indent = {} ) const override;
 | 
|---|
| 404 | };
 | 
|---|
| 405 | 
 | 
|---|
| 406 | class FinallyStmt : public Statement {
 | 
|---|
| 407 |   public:
 | 
|---|
| 408 |         CompoundStmt * block;
 | 
|---|
| 409 | 
 | 
|---|
| 410 |         FinallyStmt( CompoundStmt * block );
 | 
|---|
| 411 |         FinallyStmt( const FinallyStmt & other );
 | 
|---|
| 412 |         virtual ~FinallyStmt();
 | 
|---|
| 413 | 
 | 
|---|
| 414 |         CompoundStmt * get_block() const { return block; }
 | 
|---|
| 415 |         void set_block( CompoundStmt * newValue ) { block = newValue; }
 | 
|---|
| 416 | 
 | 
|---|
| 417 |         virtual FinallyStmt * clone() const override { return new FinallyStmt( *this ); }
 | 
|---|
| 418 |         virtual void accept( Visitor & v ) override { v.visit( this ); }
 | 
|---|
| 419 |         virtual void accept( Visitor & v ) const override { v.visit( this ); }
 | 
|---|
| 420 |         virtual Statement * acceptMutator( Mutator & m )  override { return m.mutate( this ); }
 | 
|---|
| 421 |         virtual void print( std::ostream & os, Indenter indent = {} ) const override;
 | 
|---|
| 422 | };
 | 
|---|
| 423 | 
 | 
|---|
| 424 | class SuspendStmt : public Statement {
 | 
|---|
| 425 |   public:
 | 
|---|
| 426 |         CompoundStmt * then = nullptr;
 | 
|---|
| 427 |         enum Type { None, Coroutine, Generator } type = None;
 | 
|---|
| 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 | 
 | 
|---|
| 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 | 
 | 
|---|
| 454 |         WaitForStmt();
 | 
|---|
| 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 | 
 | 
|---|
| 471 |         virtual WaitForStmt * clone() const override { return new WaitForStmt( *this ); }
 | 
|---|
| 472 |         virtual void accept( Visitor & v ) override { v.visit( this ); }
 | 
|---|
| 473 |         virtual void accept( Visitor & v ) const override { v.visit( this ); }
 | 
|---|
| 474 |         virtual Statement * acceptMutator( Mutator & m )  override { return m.mutate( this ); }
 | 
|---|
| 475 |         virtual void print( std::ostream & os, Indenter indent = {} ) const override;
 | 
|---|
| 476 | 
 | 
|---|
| 477 | };
 | 
|---|
| 478 | 
 | 
|---|
| 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 | // };
 | 
|---|
| 494 | 
 | 
|---|
| 495 | 
 | 
|---|
| 496 | // represents a declaration that occurs as part of a compound statement
 | 
|---|
| 497 | class DeclStmt : public Statement {
 | 
|---|
| 498 |   public:
 | 
|---|
| 499 |         Declaration * decl;
 | 
|---|
| 500 | 
 | 
|---|
| 501 |         DeclStmt( Declaration * decl );
 | 
|---|
| 502 |         DeclStmt( const DeclStmt & other );
 | 
|---|
| 503 |         virtual ~DeclStmt();
 | 
|---|
| 504 | 
 | 
|---|
| 505 |         Declaration * get_decl() const { return decl; }
 | 
|---|
| 506 |         void set_decl( Declaration * newValue ) { decl = newValue; }
 | 
|---|
| 507 | 
 | 
|---|
| 508 |         virtual DeclStmt * clone() const override { return new DeclStmt( *this ); }
 | 
|---|
| 509 |         virtual void accept( Visitor & v ) override { v.visit( this ); }
 | 
|---|
| 510 |         virtual void accept( Visitor & v ) const override { v.visit( this ); }
 | 
|---|
| 511 |         virtual Statement * acceptMutator( Mutator & m )  override { return m.mutate( this ); }
 | 
|---|
| 512 |         virtual void print( std::ostream & os, Indenter indent = {} ) const override;
 | 
|---|
| 513 | };
 | 
|---|
| 514 | 
 | 
|---|
| 515 | 
 | 
|---|
| 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.
 | 
|---|
| 518 | class ImplicitCtorDtorStmt : public Statement {
 | 
|---|
| 519 |   public:
 | 
|---|
| 520 |         // the constructor/destructor call statement; owned here for a while, eventually transferred elsewhere
 | 
|---|
| 521 |         Statement * callStmt;
 | 
|---|
| 522 | 
 | 
|---|
| 523 |         ImplicitCtorDtorStmt( Statement * callStmt );
 | 
|---|
| 524 |         ImplicitCtorDtorStmt( const ImplicitCtorDtorStmt & other );
 | 
|---|
| 525 |         virtual ~ImplicitCtorDtorStmt();
 | 
|---|
| 526 | 
 | 
|---|
| 527 |         Statement * get_callStmt() const { return callStmt; }
 | 
|---|
| 528 |         void set_callStmt( Statement * newValue ) { callStmt = newValue; }
 | 
|---|
| 529 | 
 | 
|---|
| 530 |         virtual ImplicitCtorDtorStmt * clone() const override { return new ImplicitCtorDtorStmt( *this ); }
 | 
|---|
| 531 |         virtual void accept( Visitor & v ) override { v.visit( this ); }
 | 
|---|
| 532 |         virtual void accept( Visitor & v ) const override { v.visit( this ); }
 | 
|---|
| 533 |         virtual Statement * acceptMutator( Mutator & m )  override { return m.mutate( this ); }
 | 
|---|
| 534 |         virtual void print( std::ostream & os, Indenter indent = {} ) const override;
 | 
|---|
| 535 | };
 | 
|---|
| 536 | 
 | 
|---|
| 537 | class MutexStmt : public Statement {
 | 
|---|
| 538 |   public:
 | 
|---|
| 539 |         Statement * stmt;
 | 
|---|
| 540 |         std::list<Expression *> mutexObjs; // list of mutex objects to acquire
 | 
|---|
| 541 | 
 | 
|---|
| 542 |         MutexStmt( Statement * stmt, std::list<Expression *> mutexObjs );
 | 
|---|
| 543 |         MutexStmt( const MutexStmt & other );
 | 
|---|
| 544 |         virtual ~MutexStmt();
 | 
|---|
| 545 | 
 | 
|---|
| 546 |         virtual MutexStmt * clone() const override { return new MutexStmt( *this ); }
 | 
|---|
| 547 |         virtual void accept( Visitor & v ) override { v.visit( this ); }
 | 
|---|
| 548 |         virtual void accept( Visitor & v ) const override { v.visit( this ); }
 | 
|---|
| 549 |         virtual Statement * acceptMutator( Mutator & m )  override { return m.mutate( this ); }
 | 
|---|
| 550 |         virtual void print( std::ostream & os, Indenter indent = {} ) const override;
 | 
|---|
| 551 | };
 | 
|---|
| 552 | 
 | 
|---|
| 553 | // Local Variables: //
 | 
|---|
| 554 | // tab-width: 4 //
 | 
|---|
| 555 | // mode: c++ //
 | 
|---|
| 556 | // compile-command: "make install" //
 | 
|---|
| 557 | // End: //
 | 
|---|