Changes in src/AST/Stmt.hpp [c86b08d:94c98f0e]
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/AST/Stmt.hpp
rc86b08d r94c98f0e 10 10 // Created On : Wed May 8 13:00:00 2019 11 11 // Last Modified By : Andrew Beach 12 // Last Modified On : Wed Apr 20 14:34:00 202213 // Update Count : 3 612 // Last Modified On : Wed Apr 5 10:34:00 2023 13 // Update Count : 37 14 14 // 15 15 … … 205 205 }; 206 206 207 // A while loop or a do-while loop: 208 enum WhileDoKind { While, DoWhile }; 209 207 210 // While loop: while (...) ... else ... or do ... while (...) else ...; 208 211 class WhileDoStmt final : public Stmt { … … 212 215 ptr<Stmt> else_; 213 216 std::vector<ptr<Stmt>> inits; 214 boolisDoWhile;217 WhileDoKind isDoWhile; 215 218 216 219 WhileDoStmt( const CodeLocation & loc, const Expr * cond, const Stmt * body, 217 const std::vector<ptr<Stmt>> && inits, bool isDoWhile = false, const std::vector<Label> && labels = {} )220 const std::vector<ptr<Stmt>> && inits, WhileDoKind isDoWhile = While, const std::vector<Label> && labels = {} ) 218 221 : Stmt(loc, std::move(labels)), cond(cond), body(body), else_(nullptr), inits(std::move(inits)), isDoWhile(isDoWhile) {} 219 222 220 223 WhileDoStmt( const CodeLocation & loc, const Expr * cond, const Stmt * body, const Stmt * else_, 221 const std::vector<ptr<Stmt>> && inits, bool isDoWhile = false, const std::vector<Label> && labels = {} )224 const std::vector<ptr<Stmt>> && inits, WhileDoKind isDoWhile = While, const std::vector<Label> && labels = {} ) 222 225 : Stmt(loc, std::move(labels)), cond(cond), body(body), else_(else_), inits(std::move(inits)), isDoWhile(isDoWhile) {} 223 226 … … 364 367 public: 365 368 ptr<CompoundStmt> then; 366 enum Type { None, Coroutine, Generator } type= None;367 368 SuspendStmt( const CodeLocation & loc, const CompoundStmt * then, Type type, const std::vector<Label> && labels = {} )369 : Stmt(loc, std::move(labels)), then(then), type(type) {}369 enum Kind { None, Coroutine, Generator } kind = None; 370 371 SuspendStmt( const CodeLocation & loc, const CompoundStmt * then, Kind kind, const std::vector<Label> && labels = {} ) 372 : Stmt(loc, std::move(labels)), then(then), kind(kind) {} 370 373 371 374 const Stmt * accept( Visitor & v ) const override { return v.visit( this ); } … … 375 378 }; 376 379 377 // Base class of WaitFor/WaitUntil statements378 // form: KEYWORD(...) ... timeout(...) ... else ... 379 class WaitStmt : public Stmt { 380 public: 381 380 // Waitfor statement: when (...) waitfor (... , ...) ... timeout(...) ... else ... 381 class WaitForStmt final : public Stmt { 382 public: 383 std::vector<ptr<WaitForClause>> clauses; 384 ptr<Expr> timeout_time; 382 385 ptr<Stmt> timeout_stmt; 383 386 ptr<Expr> timeout_cond; … … 385 388 ptr<Expr> else_cond; 386 389 387 WaitStmt( const CodeLocation & loc, const std::vector<Label> && labels = {} )390 WaitForStmt( const CodeLocation & loc, const std::vector<Label> && labels = {} ) 388 391 : Stmt(loc, std::move(labels)) {} 389 392 390 private: 391 WaitStmt * clone() const override = 0; 392 MUTATE_FRIEND 393 }; 394 395 // Base class for WaitFor/WaitUntil clauses 396 // form: when( when_cond ) KEYWORD( target ) stmt 397 class WhenClause : public StmtClause { 398 public: 399 ptr<Expr> target; 393 const Stmt * accept( Visitor & v ) const override { return v.visit( this ); } 394 private: 395 WaitForStmt * clone() const override { return new WaitForStmt{ *this }; } 396 MUTATE_FRIEND 397 }; 398 399 // Clause in a waitfor statement: waitfor (..., ...) ... 400 class WaitForClause final : public StmtClause { 401 public: 402 ptr<Expr> target_func; 403 std::vector<ptr<Expr>> target_args; 400 404 ptr<Stmt> stmt; 401 ptr<Expr> when_cond;402 403 W henClause( const CodeLocation & loc )405 ptr<Expr> cond; 406 407 WaitForClause( const CodeLocation & loc ) 404 408 : StmtClause( loc ) {} 405 409 406 const WhenClause * accept( Visitor & v ) const override { return v.visit( this ); }407 private:408 WhenClause * clone() const override { return new WhenClause{ *this }; }409 MUTATE_FRIEND410 };411 412 // Waitfor statement: when (...) waitfor (... , ...) ... timeout(...) ... else ...413 class WaitForStmt final : public WaitStmt {414 public:415 std::vector<ptr<WaitForClause>> clauses;416 417 WaitForStmt( const CodeLocation & loc, const std::vector<Label> && labels = {} )418 : WaitStmt(loc, std::move(labels)) {}419 420 const Stmt * accept( Visitor & v ) const override { return v.visit( this ); }421 private:422 WaitForStmt * clone() const override { return new WaitForStmt{ *this }; }423 MUTATE_FRIEND424 };425 426 class WaitForClause final : public WhenClause {427 public:428 std::vector<ptr<Expr>> target_args;429 430 WaitForClause( const CodeLocation & loc )431 : WhenClause( loc ) {}432 433 410 const WaitForClause * accept( Visitor & v ) const override { return v.visit( this ); } 434 411 private: 435 412 WaitForClause * clone() const override { return new WaitForClause{ *this }; } 436 MUTATE_FRIEND437 };438 439 // waituntil statement: when (...) waituntil (...) ... timeout(...) ... else ...440 class WaitUntilStmt final : public WaitStmt {441 public:442 // Non-ast node used during compilation to store data needed to generate predicates443 // and set initial status values for clauses444 // Used to create a tree corresponding to the structure of the clauses in a WaitUntil445 struct ClauseNode {446 enum Op { AND, OR, LEFT_OR, LEAF, ELSE, TIMEOUT } op; // operation/type tag447 // LEFT_OR used with TIMEOUT/ELSE to indicate that we ignore right hand side after parsing448 449 ClauseNode * left;450 ClauseNode * right;451 WhenClause * leaf; // only set if this node is a leaf (points into vector of clauses)452 453 bool ambiguousWhen; // used to paint nodes of predicate tree based on when() clauses454 bool whenState; // used to track if when_cond is toggled on or off for generating init values455 bool childOfAnd; // true on leaf nodes that are children of AND, false otherwise456 457 ClauseNode( Op op, ClauseNode * left, ClauseNode * right )458 : op(op), left(left), right(right), leaf(nullptr),459 ambiguousWhen(false), whenState(true), childOfAnd(false) {}460 ClauseNode( Op op, WhenClause * leaf )461 : op(op), left(nullptr), right(nullptr), leaf(leaf),462 ambiguousWhen(false), whenState(true), childOfAnd(false) {}463 ClauseNode( WhenClause * leaf ) : ClauseNode(LEAF, leaf) {}464 465 ~ClauseNode() {466 if ( left ) delete left;467 if ( right ) delete right;468 }469 };470 471 std::vector<ptr<WhenClause>> clauses;472 ClauseNode * predicateTree;473 474 WaitUntilStmt( const CodeLocation & loc, const std::vector<Label> && labels = {} )475 : WaitStmt(loc, std::move(labels)) {}476 477 ~WaitUntilStmt() { delete predicateTree; }478 479 const Stmt * accept( Visitor & v ) const override { return v.visit( this ); }480 private:481 WaitUntilStmt * clone() const override { return new WaitUntilStmt{ *this }; }482 413 MUTATE_FRIEND 483 414 }; … … 527 458 MUTATE_FRIEND 528 459 }; 460 529 461 } // namespace ast 530 462
Note:
See TracChangeset
for help on using the changeset viewer.