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