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