Changes in src/SynTree/Statement.h [65cdc1e:046e04a]
- File:
-
- 1 edited
-
src/SynTree/Statement.h (modified) (25 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/SynTree/Statement.h
r65cdc1e r046e04a 10 10 // Created On : Mon May 18 07:44:20 2015 11 11 // Last Modified By : Andrew Beach 12 // Last Modified On : Thr Aug 3 14:08:00 201713 // Update Count : 6 912 // Last Modified On : Mon Jun 12 13:35:00 2017 13 // Update Count : 67 14 14 // 15 15 16 #pragma once 16 #ifndef STATEMENT_H 17 #define STATEMENT_H 17 18 18 19 #include "BaseSyntaxNode.h" … … 26 27 class Statement : public BaseSyntaxNode { 27 28 public: 28 std::list<Label> labels;29 30 29 Statement( std::list<Label> labels ); 31 30 virtual ~Statement(); … … 38 37 virtual Statement *acceptMutator( Mutator &m ) = 0; 39 38 virtual void print( std::ostream &os, int indent = 0 ) const; 39 protected: 40 std::list<Label> labels; 40 41 }; 41 42 42 43 class CompoundStmt : public Statement { 43 44 public: 44 std::list<Statement*> kids;45 46 45 CompoundStmt( std::list<Label> labels ); 47 46 CompoundStmt( const CompoundStmt &other ); … … 56 55 virtual CompoundStmt *acceptMutator( Mutator &m ) { return m.mutate( this ); } 57 56 virtual void print( std::ostream &os, int indent = 0 ) const; 57 private: 58 std::list<Statement*> kids; 58 59 }; 59 60 … … 67 68 virtual NullStmt *acceptMutator( Mutator &m ) { return m.mutate( this ); } 68 69 virtual void print( std::ostream &os, int indent = 0 ) const; 70 71 private: 69 72 }; 70 73 71 74 class ExprStmt : public Statement { 72 75 public: 73 Expression *expr;74 75 76 ExprStmt( std::list<Label> labels, Expression *expr ); 76 77 ExprStmt( const ExprStmt &other ); … … 84 85 virtual Statement *acceptMutator( Mutator &m ) { return m.mutate( this ); } 85 86 virtual void print( std::ostream &os, int indent = 0 ) const; 87 private: 88 Expression *expr; 86 89 }; 87 90 88 91 class AsmStmt : public Statement { 89 92 public: 90 bool voltile;91 ConstantExpr *instruction;92 std::list<Expression *> output, input;93 std::list<ConstantExpr *> clobber;94 std::list<Label> gotolabels;95 96 93 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 ); 97 94 AsmStmt( const AsmStmt &other ); … … 115 112 virtual Statement *acceptMutator( Mutator &m ) { return m.mutate( this ); } 116 113 virtual void print( std::ostream &os, int indent = 0 ) const; 114 private: 115 bool voltile; 116 ConstantExpr *instruction; 117 std::list<Expression *> output, input; 118 std::list<ConstantExpr *> clobber; 119 std::list<Label> gotolabels; 117 120 }; 118 121 119 122 class IfStmt : public Statement { 120 123 public: 121 Expression *condition;122 Statement *thenPart;123 Statement *elsePart;124 125 124 IfStmt( std::list<Label> labels, Expression *condition, Statement *thenPart, Statement *elsePart ); 126 125 IfStmt( const IfStmt &other ); … … 138 137 virtual Statement *acceptMutator( Mutator &m ) { return m.mutate( this ); } 139 138 virtual void print( std::ostream &os, int indent = 0 ) const; 139 private: 140 Expression *condition; 141 Statement *thenPart; 142 Statement *elsePart; 140 143 }; 141 144 142 145 class SwitchStmt : public Statement { 143 146 public: 144 Expression * condition;145 146 147 SwitchStmt( std::list<Label> labels, Expression *condition, std::list<Statement *> &statements ); 147 148 SwitchStmt( const SwitchStmt &other ); … … 159 160 virtual void print( std::ostream &os, int indent = 0 ) const; 160 161 private: 162 Expression * condition; 161 163 std::list<Statement *> statements; 162 164 }; … … 164 166 class CaseStmt : public Statement { 165 167 public: 166 Expression * condition;167 std::list<Statement *> stmts;168 169 168 CaseStmt( std::list<Label> labels, Expression *conditions, std::list<Statement *> &stmts, bool isdef = false ) throw(SemanticError); 170 169 CaseStmt( const CaseStmt &other ); … … 188 187 virtual void print( std::ostream &os, int indent = 0 ) const; 189 188 private: 189 Expression * condition; 190 std::list<Statement *> stmts; 190 191 bool _isDefault; 191 192 }; … … 193 194 class WhileStmt : public Statement { 194 195 public: 195 Expression *condition;196 Statement *body;197 bool isDoWhile;198 199 196 WhileStmt( std::list<Label> labels, Expression *condition, 200 197 Statement *body, bool isDoWhile = false ); … … 213 210 virtual Statement *acceptMutator( Mutator &m ) { return m.mutate( this ); } 214 211 virtual void print( std::ostream &os, int indent = 0 ) const; 212 private: 213 Expression *condition; 214 Statement *body; 215 bool isDoWhile; 215 216 }; 216 217 217 218 class ForStmt : public Statement { 218 219 public: 219 std::list<Statement *> initialization;220 Expression *condition;221 Expression *increment;222 Statement *body;223 224 220 ForStmt( std::list<Label> labels, std::list<Statement *> initialization, 225 221 Expression *condition = 0, Expression *increment = 0, Statement *body = 0 ); … … 240 236 virtual Statement *acceptMutator( Mutator &m ) { return m.mutate( this ); } 241 237 virtual void print( std::ostream &os, int indent = 0 ) const; 238 private: 239 std::list<Statement *> initialization; 240 Expression *condition; 241 Expression *increment; 242 Statement *body; 242 243 }; 243 244 … … 246 247 enum Type { Goto = 0, Break, Continue }; 247 248 248 // originalTarget kept for error messages. 249 const Label originalTarget; 249 BranchStmt( std::list<Label> labels, Label target, Type ) throw (SemanticError); 250 BranchStmt( std::list<Label> labels, Expression *computedTarget, Type ) throw (SemanticError); 251 252 Label get_originalTarget() { return originalTarget; } 253 Label get_target() { return target; } 254 void set_target( Label newValue ) { target = newValue; } 255 256 Expression *get_computedTarget() { return computedTarget; } 257 void set_target( Expression * newValue ) { computedTarget = newValue; } 258 259 Type get_type() { return type; } 260 const char *get_typename() { return brType[ type ]; } 261 262 virtual BranchStmt *clone() const { return new BranchStmt( *this ); } 263 virtual void accept( Visitor &v ) { v.visit( this ); } 264 virtual Statement *acceptMutator( Mutator &m ) { return m.mutate( this ); } 265 virtual void print( std::ostream &os, int indent = 0 ) const; 266 private: 267 static const char *brType[]; 268 Label originalTarget; // can give better error messages if we remember the label name that the user entered 250 269 Label target; 251 270 Expression *computedTarget; 252 271 Type type; 253 254 BranchStmt( std::list<Label> labels, Label target, Type ) throw (SemanticError);255 BranchStmt( std::list<Label> labels, Expression *computedTarget, Type ) throw (SemanticError);256 257 Label get_originalTarget() { return originalTarget; }258 Label get_target() { return target; }259 void set_target( Label newValue ) { target = newValue; }260 261 Expression *get_computedTarget() { return computedTarget; }262 void set_target( Expression * newValue ) { computedTarget = newValue; }263 264 Type get_type() { return type; }265 const char *get_typename() { return brType[ type ]; }266 267 virtual BranchStmt *clone() const { return new BranchStmt( *this ); }268 virtual void accept( Visitor &v ) { v.visit( this ); }269 virtual Statement *acceptMutator( Mutator &m ) { return m.mutate( this ); }270 virtual void print( std::ostream &os, int indent = 0 ) const;271 private:272 static const char *brType[];273 272 }; 274 273 275 274 class ReturnStmt : public Statement { 276 275 public: 277 Expression *expr;278 279 276 ReturnStmt( std::list<Label> labels, Expression *expr ); 280 277 ReturnStmt( const ReturnStmt &other ); … … 288 285 virtual Statement *acceptMutator( Mutator &m ) { return m.mutate( this ); } 289 286 virtual void print( std::ostream &os, int indent = 0 ) const; 287 private: 288 Expression *expr; 290 289 }; 291 290 … … 293 292 public: 294 293 enum Kind { Terminate, Resume }; 295 296 const Kind kind;297 Expression * expr;298 Expression * target;299 294 300 295 ThrowStmt( std::list<Label> labels, Kind kind, Expression * expr, Expression * target = nullptr ); … … 312 307 virtual Statement *acceptMutator( Mutator &m ) { return m.mutate( this ); } 313 308 virtual void print( std::ostream &os, int indent = 0 ) const; 309 private: 310 Kind kind; 311 Expression * expr; 312 Expression * target; 314 313 }; 315 314 316 315 class TryStmt : public Statement { 317 316 public: 317 TryStmt( std::list<Label> labels, CompoundStmt *tryBlock, std::list<CatchStmt *> &handlers, FinallyStmt *finallyBlock = 0 ); 318 TryStmt( const TryStmt &other ); 319 virtual ~TryStmt(); 320 321 CompoundStmt *get_block() const { return block; } 322 void set_block( CompoundStmt *newValue ) { block = newValue; } 323 std::list<CatchStmt *>& get_catchers() { return handlers; } 324 325 FinallyStmt *get_finally() const { return finallyBlock; } 326 void set_finally( FinallyStmt *newValue ) { finallyBlock = newValue; } 327 328 virtual TryStmt *clone() const { return new TryStmt( *this ); } 329 virtual void accept( Visitor &v ) { v.visit( this ); } 330 virtual Statement *acceptMutator( Mutator &m ) { return m.mutate( this ); } 331 virtual void print( std::ostream &os, int indent = 0 ) const; 332 333 private: 318 334 CompoundStmt *block; 319 335 std::list<CatchStmt *> handlers; 320 336 FinallyStmt *finallyBlock; 321 322 TryStmt( std::list<Label> labels, CompoundStmt *tryBlock, std::list<CatchStmt *> &handlers, FinallyStmt *finallyBlock = 0 );323 TryStmt( const TryStmt &other );324 virtual ~TryStmt();325 326 CompoundStmt *get_block() const { return block; }327 void set_block( CompoundStmt *newValue ) { block = newValue; }328 std::list<CatchStmt *>& get_catchers() { return handlers; }329 330 FinallyStmt *get_finally() const { return finallyBlock; }331 void set_finally( FinallyStmt *newValue ) { finallyBlock = newValue; }332 333 virtual TryStmt *clone() const { return new TryStmt( *this ); }334 virtual void accept( Visitor &v ) { v.visit( this ); }335 virtual Statement *acceptMutator( Mutator &m ) { return m.mutate( this ); }336 virtual void print( std::ostream &os, int indent = 0 ) const;337 337 }; 338 338 … … 340 340 public: 341 341 enum Kind { Terminate, Resume }; 342 343 const Kind kind;344 Declaration *decl;345 Expression *cond;346 Statement *body;347 342 348 343 CatchStmt( std::list<Label> labels, Kind kind, Declaration *decl, … … 363 358 virtual Statement *acceptMutator( Mutator &m ) { return m.mutate( this ); } 364 359 virtual void print( std::ostream &os, int indent = 0 ) const; 360 361 private: 362 Kind kind; 363 Declaration *decl; 364 Expression *cond; 365 Statement *body; 365 366 }; 366 367 367 368 class FinallyStmt : public Statement { 368 369 public: 369 CompoundStmt *block;370 371 370 FinallyStmt( std::list<Label> labels, CompoundStmt *block ); 372 371 FinallyStmt( const FinallyStmt &other ); … … 380 379 virtual Statement *acceptMutator( Mutator &m ) { return m.mutate( this ); } 381 380 virtual void print( std::ostream &os, int indent = 0 ) const; 381 private: 382 CompoundStmt *block; 382 383 }; 383 384 … … 386 387 class DeclStmt : public Statement { 387 388 public: 388 Declaration *decl;389 390 389 DeclStmt( std::list<Label> labels, Declaration *decl ); 391 390 DeclStmt( const DeclStmt &other ); … … 399 398 virtual Statement *acceptMutator( Mutator &m ) { return m.mutate( this ); } 400 399 virtual void print( std::ostream &os, int indent = 0 ) const; 400 private: 401 Declaration *decl; 401 402 }; 402 403 … … 407 408 class ImplicitCtorDtorStmt : public Statement { 408 409 public: 409 // Non-owned pointer to the constructor/destructor statement410 Statement * callStmt;411 412 410 ImplicitCtorDtorStmt( Statement * callStmt ); 413 411 ImplicitCtorDtorStmt( const ImplicitCtorDtorStmt & other ); … … 421 419 virtual Statement *acceptMutator( Mutator &m ) { return m.mutate( this ); } 422 420 virtual void print( std::ostream &os, int indent = 0 ) const; 421 422 private: 423 // Non-owned pointer to the constructor/destructor statement 424 Statement * callStmt; 423 425 }; 424 426 425 427 426 428 std::ostream & operator<<( std::ostream & out, const Statement * statement ); 429 430 #endif // STATEMENT_H 427 431 428 432 // Local Variables: //
Note:
See TracChangeset
for help on using the changeset viewer.