Changeset 3982384 for src/AST/Stmt.hpp
- Timestamp:
- May 17, 2023, 1:35:09 AM (2 years ago)
- Branches:
- ADT, master
- Children:
- f11010e
- Parents:
- 6e4c44d (diff), 8db4708 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/AST/Stmt.hpp
r6e4c44d r3982384 378 378 }; 379 379 380 // Waitfor statement: when (...) waitfor (... , ...) ... timeout(...) ... else ...381 class WaitForStmt final : public Stmt { 382 public: 383 std::vector<ptr<WaitForClause>> clauses; 384 380 // Base class of WaitFor/WaitUntil statements 381 // form: KEYWORD(...) ... timeout(...) ... else ... 382 class WaitStmt : public Stmt { 383 public: 384 ptr<Expr> timeout_time; 385 385 ptr<Stmt> timeout_stmt; 386 386 ptr<Expr> timeout_cond; … … 388 388 ptr<Expr> else_cond; 389 389 390 WaitStmt( const CodeLocation & loc, const std::vector<Label> && labels = {} ) 391 : Stmt(loc, std::move(labels)) {} 392 393 private: 394 WaitStmt * clone() const override = 0; 395 MUTATE_FRIEND 396 }; 397 398 // Base class for WaitFor/WaitUntil clauses 399 // form: when( when_cond ) KEYWORD( target ) stmt 400 class WhenClause : public StmtClause { 401 public: 402 ptr<Expr> target; 403 ptr<Stmt> stmt; 404 ptr<Expr> when_cond; 405 406 WhenClause( const CodeLocation & loc ) 407 : StmtClause( loc ) {} 408 409 const WhenClause * accept( Visitor & v ) const override { return v.visit( this ); } 410 private: 411 WhenClause * clone() const override { return new WhenClause{ *this }; } 412 MUTATE_FRIEND 413 }; 414 415 // Waitfor statement: when (...) waitfor (... , ...) ... timeout(...) ... else ... 416 class WaitForStmt final : public WaitStmt { 417 public: 418 std::vector<ptr<WaitForClause>> clauses; 419 390 420 WaitForStmt( const CodeLocation & loc, const std::vector<Label> && labels = {} ) 391 : Stmt(loc, std::move(labels)) {}421 : WaitStmt(loc, std::move(labels)) {} 392 422 393 423 const Stmt * accept( Visitor & v ) const override { return v.visit( this ); } … … 398 428 399 429 // Clause in a waitfor statement: waitfor (..., ...) ... 400 class WaitForClause final : public StmtClause { 401 public: 402 ptr<Expr> target_func; 430 class WaitForClause final : public WhenClause { 431 public: 403 432 std::vector<ptr<Expr>> target_args; 404 ptr<Stmt> stmt;405 ptr<Expr> cond;406 433 407 434 WaitForClause( const CodeLocation & loc ) 408 : StmtClause( loc ) {}435 : WhenClause( loc ) {} 409 436 410 437 const WaitForClause * accept( Visitor & v ) const override { return v.visit( this ); } 411 438 private: 412 439 WaitForClause * clone() const override { return new WaitForClause{ *this }; } 440 MUTATE_FRIEND 441 }; 442 443 // waituntil statement: when (...) waituntil (...) ... timeout(...) ... else ... 444 class WaitUntilStmt final : public WaitStmt { 445 public: 446 // Non-ast node used during compilation to store data needed to generate predicates 447 // and set initial status values for clauses 448 // Used to create a tree corresponding to the structure of the clauses in a WaitUntil 449 struct ClauseNode { 450 enum Op { AND, OR, LEFT_OR, LEAF, ELSE, TIMEOUT } op; // operation/type tag 451 // LEFT_OR used with TIMEOUT/ELSE to indicate that we ignore right hand side after parsing 452 453 ClauseNode * left; 454 ClauseNode * right; 455 WhenClause * leaf; // only set if this node is a leaf (points into vector of clauses) 456 457 bool ambiguousWhen; // used to paint nodes of predicate tree based on when() clauses 458 bool whenState; // used to track if when_cond is toggled on or off for generating init values 459 bool childOfAnd; // true on leaf nodes that are children of AND, false otherwise 460 461 ClauseNode( Op op, ClauseNode * left, ClauseNode * right ) 462 : op(op), left(left), right(right), leaf(nullptr), 463 ambiguousWhen(false), whenState(true), childOfAnd(false) {} 464 ClauseNode( Op op, WhenClause * leaf ) 465 : op(op), left(nullptr), right(nullptr), leaf(leaf), 466 ambiguousWhen(false), whenState(true), childOfAnd(false) {} 467 ClauseNode( WhenClause * leaf ) : ClauseNode(LEAF, leaf) {} 468 469 ~ClauseNode() { 470 if ( left ) delete left; 471 if ( right ) delete right; 472 } 473 }; 474 475 std::vector<ptr<WhenClause>> clauses; 476 ClauseNode * predicateTree; 477 478 WaitUntilStmt( const CodeLocation & loc, const std::vector<Label> && labels = {} ) 479 : WaitStmt(loc, std::move(labels)) {} 480 481 ~WaitUntilStmt() { delete predicateTree; } 482 483 const Stmt * accept( Visitor & v ) const override { return v.visit( this ); } 484 private: 485 WaitUntilStmt * clone() const override { return new WaitUntilStmt{ *this }; } 413 486 MUTATE_FRIEND 414 487 };
Note:
See TracChangeset
for help on using the changeset viewer.