Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/AST/Stmt.hpp

    rc86b08d r94c98f0e  
    1010// Created On       : Wed May  8 13:00:00 2019
    1111// Last Modified By : Andrew Beach
    12 // Last Modified On : Wed Apr 20 14:34:00 2022
    13 // Update Count     : 36
     12// Last Modified On : Wed Apr  5 10:34:00 2023
     13// Update Count     : 37
    1414//
    1515
     
    205205};
    206206
     207// A while loop or a do-while loop:
     208enum WhileDoKind { While, DoWhile };
     209
    207210// While loop: while (...) ... else ... or do ... while (...) else ...;
    208211class WhileDoStmt final : public Stmt {
     
    212215        ptr<Stmt> else_;
    213216        std::vector<ptr<Stmt>> inits;
    214         bool isDoWhile;
     217        WhileDoKind isDoWhile;
    215218
    216219        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 = {} )
    218221                : Stmt(loc, std::move(labels)), cond(cond), body(body), else_(nullptr), inits(std::move(inits)), isDoWhile(isDoWhile) {}
    219222
    220223        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 = {} )
    222225                : Stmt(loc, std::move(labels)), cond(cond), body(body), else_(else_), inits(std::move(inits)), isDoWhile(isDoWhile) {}
    223226
     
    364367  public:
    365368        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) {}
    370373
    371374        const Stmt * accept( Visitor & v ) const override { return v.visit( this ); }
     
    375378};
    376379
    377 // Base class of WaitFor/WaitUntil statements
    378 // form: KEYWORD(...) ... timeout(...) ... else ...
    379 class WaitStmt : public Stmt {
    380   public:
    381     ptr<Expr> timeout_time;
     380// Waitfor statement: when (...) waitfor (... , ...) ... timeout(...) ... else ...
     381class WaitForStmt final : public Stmt {
     382  public:
     383        std::vector<ptr<WaitForClause>> clauses;
     384        ptr<Expr> timeout_time;
    382385        ptr<Stmt> timeout_stmt;
    383386        ptr<Expr> timeout_cond;
     
    385388        ptr<Expr> else_cond;
    386389
    387     WaitStmt( const CodeLocation & loc, const std::vector<Label> && labels = {} )
     390        WaitForStmt( const CodeLocation & loc, const std::vector<Label> && labels = {} )
    388391                : Stmt(loc, std::move(labels)) {}
    389392
    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 (..., ...) ...
     400class WaitForClause final : public StmtClause {
     401  public:
     402        ptr<Expr> target_func;
     403        std::vector<ptr<Expr>> target_args;
    400404        ptr<Stmt> stmt;
    401         ptr<Expr> when_cond;
    402 
    403         WhenClause( const CodeLocation & loc )
     405        ptr<Expr> cond;
     406
     407        WaitForClause( const CodeLocation & loc )
    404408                : StmtClause( loc ) {}
    405409
    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_FRIEND
    410 };
    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_FRIEND
    424 };
    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 
    433410        const WaitForClause * accept( Visitor & v ) const override { return v.visit( this ); }
    434411  private:
    435412        WaitForClause * clone() const override { return new WaitForClause{ *this }; }
    436         MUTATE_FRIEND
    437 };
    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 predicates
    443     //    and set initial status values for clauses
    444     // Used to create a tree corresponding to the structure of the clauses in a WaitUntil
    445     struct ClauseNode {
    446         enum Op { AND, OR, LEFT_OR, LEAF, ELSE, TIMEOUT } op; // operation/type tag
    447         // LEFT_OR used with TIMEOUT/ELSE to indicate that we ignore right hand side after parsing
    448 
    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() clauses
    454         bool whenState;     // used to track if when_cond is toggled on or off for generating init values
    455         bool childOfAnd;      // true on leaf nodes that are children of AND, false otherwise
    456 
    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 }; }
    482413        MUTATE_FRIEND
    483414};
     
    527458        MUTATE_FRIEND
    528459};
     460
    529461} // namespace ast
    530462
Note: See TracChangeset for help on using the changeset viewer.