| [2bb4a01] | 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 | // Stmt.hpp --
 | 
|---|
 | 8 | //
 | 
|---|
 | 9 | // Author           : Aaron B. Moss
 | 
|---|
| [1e97287] | 10 | // Created On       : Wed May  8 13:00:00 2019
 | 
|---|
| [400b8be] | 11 | // Last Modified By : Andrew Beach
 | 
|---|
 | 12 | // Last Modified On : Mon Mar 28  9:50:00 2022
 | 
|---|
 | 13 | // Update Count     : 35
 | 
|---|
| [2bb4a01] | 14 | //
 | 
|---|
 | 15 | 
 | 
|---|
 | 16 | #pragma once
 | 
|---|
 | 17 | 
 | 
|---|
 | 18 | #include <list>
 | 
|---|
| [89a5a1f] | 19 | #include <utility>                                                                              // for move
 | 
|---|
| [2bb4a01] | 20 | #include <vector>
 | 
|---|
 | 21 | 
 | 
|---|
 | 22 | #include "Label.hpp"
 | 
|---|
| [89a5a1f] | 23 | #include "Node.hpp"                                                                             // for node, ptr
 | 
|---|
| [2bb4a01] | 24 | #include "ParseNode.hpp"
 | 
|---|
 | 25 | #include "Visitor.hpp"
 | 
|---|
 | 26 | #include "Common/CodeLocation.h"
 | 
|---|
 | 27 | 
 | 
|---|
| [f3cc5b6] | 28 | // Must be included in *all* AST classes; should be #undef'd at the end of the file
 | 
|---|
| [89a5a1f] | 29 | #define MUTATE_FRIEND                                                                                                   \
 | 
|---|
| [99da267] | 30 |     template<typename node_t> friend node_t * mutate(const node_t * node); \
 | 
|---|
 | 31 |         template<typename node_t> friend node_t * shallowCopy(const node_t * node);
 | 
|---|
| [f3cc5b6] | 32 | 
 | 
|---|
| [2bb4a01] | 33 | namespace ast {
 | 
|---|
 | 34 | class Expr;
 | 
|---|
 | 35 | 
 | 
|---|
| [89a5a1f] | 36 | // Base statement node
 | 
|---|
| [2bb4a01] | 37 | class Stmt : public ParseNode {
 | 
|---|
| [89a5a1f] | 38 |   public:
 | 
|---|
| [2bb4a01] | 39 |         std::vector<Label> labels;
 | 
|---|
 | 40 | 
 | 
|---|
| [6180274] | 41 |         Stmt( const CodeLocation & loc, const std::vector<Label> && labels = {} )
 | 
|---|
| [89a5a1f] | 42 |                 : ParseNode(loc), labels(std::move(labels)) {}
 | 
|---|
| [2bb4a01] | 43 | 
 | 
|---|
| [3b0bc16] | 44 |         Stmt(const Stmt & o) : ParseNode(o), labels(o.labels) {}
 | 
|---|
| [2bb4a01] | 45 | 
 | 
|---|
| [f3cc5b6] | 46 |         const Stmt * accept( Visitor & v ) const override = 0;
 | 
|---|
| [89a5a1f] | 47 |   private:
 | 
|---|
| [f3cc5b6] | 48 |         Stmt * clone() const override = 0;
 | 
|---|
 | 49 |         MUTATE_FRIEND
 | 
|---|
| [2bb4a01] | 50 | };
 | 
|---|
 | 51 | 
 | 
|---|
| [400b8be] | 52 | // Base statement component node (only serves to group them).
 | 
|---|
 | 53 | class StmtClause : public ParseNode {
 | 
|---|
 | 54 |   public:
 | 
|---|
 | 55 |         // This is for non-statements that still belong with the statements,
 | 
|---|
 | 56 |         // but are not statements, usually some sort of clause. Often these can
 | 
|---|
 | 57 |         // (and should) be folded into the approprate parent node, but if they
 | 
|---|
 | 58 |         // cannot be, they are sub-types of this type, for organization.
 | 
|---|
 | 59 | 
 | 
|---|
 | 60 |     StmtClause( const CodeLocation & loc )
 | 
|---|
 | 61 |                 : ParseNode(loc) {}
 | 
|---|
 | 62 | 
 | 
|---|
 | 63 |   private:
 | 
|---|
 | 64 |         StmtClause * clone() const override = 0;
 | 
|---|
 | 65 |         MUTATE_FRIEND
 | 
|---|
 | 66 | };
 | 
|---|
 | 67 | 
 | 
|---|
| [89a5a1f] | 68 | // Compound statement: { ... }
 | 
|---|
| [2bb4a01] | 69 | class CompoundStmt final : public Stmt {
 | 
|---|
| [89a5a1f] | 70 |   public:
 | 
|---|
| [2bb4a01] | 71 |         std::list<ptr<Stmt>> kids;
 | 
|---|
 | 72 | 
 | 
|---|
| [6180274] | 73 |         CompoundStmt(const CodeLocation & loc, const std::list<ptr<Stmt>> && ks = {}, const std::vector<Label> && labels = {} )
 | 
|---|
| [89a5a1f] | 74 |                 : Stmt(loc, std::move(labels)), kids(std::move(ks)) {}
 | 
|---|
| [2bb4a01] | 75 | 
 | 
|---|
| [3b0bc16] | 76 |         CompoundStmt( const CompoundStmt & o );
 | 
|---|
 | 77 |         CompoundStmt( CompoundStmt && o ) = default;
 | 
|---|
| [2bb4a01] | 78 | 
 | 
|---|
| [b8524ca] | 79 |         void push_back( const Stmt * s ) { kids.emplace_back( s ); }
 | 
|---|
 | 80 |         void push_front( const Stmt * s ) { kids.emplace_front( s ); }
 | 
|---|
| [2bb4a01] | 81 | 
 | 
|---|
| [f3cc5b6] | 82 |         const CompoundStmt * accept( Visitor & v ) const override { return v.visit( this ); }
 | 
|---|
| [89a5a1f] | 83 |   private:
 | 
|---|
| [f3cc5b6] | 84 |         CompoundStmt * clone() const override { return new CompoundStmt{ *this }; }
 | 
|---|
 | 85 |         MUTATE_FRIEND
 | 
|---|
| [2bb4a01] | 86 | };
 | 
|---|
 | 87 | 
 | 
|---|
| [89a5a1f] | 88 | // Empty statment: ;
 | 
|---|
| [2bb4a01] | 89 | class NullStmt final : public Stmt {
 | 
|---|
| [89a5a1f] | 90 |   public:
 | 
|---|
| [6180274] | 91 |         NullStmt( const CodeLocation & loc, const std::vector<Label> && labels = {} )
 | 
|---|
| [89a5a1f] | 92 |                 : Stmt(loc, std::move(labels)) {}
 | 
|---|
| [2bb4a01] | 93 | 
 | 
|---|
| [f3cc5b6] | 94 |         const NullStmt * accept( Visitor & v ) const override { return v.visit( this ); }
 | 
|---|
| [89a5a1f] | 95 |   private:
 | 
|---|
| [f3cc5b6] | 96 |         NullStmt * clone() const override { return new NullStmt{ *this }; }
 | 
|---|
 | 97 |         MUTATE_FRIEND
 | 
|---|
| [2bb4a01] | 98 | };
 | 
|---|
 | 99 | 
 | 
|---|
| [89a5a1f] | 100 | // Expression wrapped by statement
 | 
|---|
| [2bb4a01] | 101 | class ExprStmt final : public Stmt {
 | 
|---|
| [89a5a1f] | 102 |   public:
 | 
|---|
| [2bb4a01] | 103 |         ptr<Expr> expr;
 | 
|---|
 | 104 | 
 | 
|---|
| [6180274] | 105 |         ExprStmt( const CodeLocation & loc, const Expr* e, const std::vector<Label> && labels = {} )
 | 
|---|
| [89a5a1f] | 106 |                 : Stmt(loc, std::move(labels)), expr(e) {}
 | 
|---|
| [2bb4a01] | 107 | 
 | 
|---|
| [f3cc5b6] | 108 |         const Stmt * accept( Visitor & v ) const override { return v.visit( this ); }
 | 
|---|
| [89a5a1f] | 109 |   private:
 | 
|---|
| [23f99e1] | 110 |         ExprStmt * clone() const override { return new ExprStmt{ *this }; }
 | 
|---|
| [f3cc5b6] | 111 |         MUTATE_FRIEND
 | 
|---|
| [2bb4a01] | 112 | };
 | 
|---|
 | 113 | 
 | 
|---|
| [89a5a1f] | 114 | // Assembly statement: asm ... ( "..." : ... )
 | 
|---|
| [1e97287] | 115 | class AsmStmt final : public Stmt {
 | 
|---|
| [89a5a1f] | 116 |   public:
 | 
|---|
| [1e97287] | 117 |         bool isVolatile;
 | 
|---|
 | 118 |         ptr<Expr> instruction;
 | 
|---|
 | 119 |         std::vector<ptr<Expr>> output, input;
 | 
|---|
 | 120 |         std::vector<ptr<ConstantExpr>> clobber;
 | 
|---|
 | 121 |         std::vector<Label> gotoLabels;
 | 
|---|
 | 122 | 
 | 
|---|
| [f3cc5b6] | 123 |         AsmStmt( const CodeLocation & loc, bool isVolatile, const Expr * instruction,
 | 
|---|
| [6180274] | 124 |                          const std::vector<ptr<Expr>> && output, const std::vector<ptr<Expr>> && input,
 | 
|---|
 | 125 |                          const std::vector<ptr<ConstantExpr>> && clobber, const std::vector<Label> && gotoLabels,
 | 
|---|
 | 126 |                          const std::vector<Label> && labels = {})
 | 
|---|
| [89a5a1f] | 127 |                 : Stmt(loc, std::move(labels)), isVolatile(isVolatile), instruction(instruction),
 | 
|---|
 | 128 |                   output(std::move(output)), input(std::move(input)), clobber(std::move(clobber)),
 | 
|---|
 | 129 |                   gotoLabels(std::move(gotoLabels)) {}
 | 
|---|
| [1e97287] | 130 | 
 | 
|---|
| [f3cc5b6] | 131 |         const Stmt * accept( Visitor & v ) const override { return v.visit( this ); }
 | 
|---|
| [89a5a1f] | 132 |   private:
 | 
|---|
| [f3cc5b6] | 133 |         AsmStmt * clone() const override { return new AsmStmt{ *this }; }
 | 
|---|
 | 134 |         MUTATE_FRIEND
 | 
|---|
| [1e97287] | 135 | };
 | 
|---|
 | 136 | 
 | 
|---|
| [89a5a1f] | 137 | // C-preprocessor directive: #...
 | 
|---|
| [1e97287] | 138 | class DirectiveStmt final : public Stmt {
 | 
|---|
| [89a5a1f] | 139 |   public:
 | 
|---|
| [1e97287] | 140 |         std::string directive;
 | 
|---|
 | 141 | 
 | 
|---|
| [f3cc5b6] | 142 |         DirectiveStmt( const CodeLocation & loc, const std::string & directive,
 | 
|---|
| [89a5a1f] | 143 |                                    std::vector<Label> && labels = {} )
 | 
|---|
 | 144 |                 : Stmt(loc, std::move(labels)), directive(directive) {}
 | 
|---|
| [1e97287] | 145 | 
 | 
|---|
| [f3cc5b6] | 146 |         const Stmt * accept( Visitor & v ) const override { return v.visit( this ); }
 | 
|---|
| [89a5a1f] | 147 |   private:
 | 
|---|
| [f3cc5b6] | 148 |         DirectiveStmt * clone() const override { return new DirectiveStmt{ *this }; }
 | 
|---|
 | 149 |         MUTATE_FRIEND
 | 
|---|
| [1e97287] | 150 | };
 | 
|---|
 | 151 | 
 | 
|---|
| [89a5a1f] | 152 | // If statement: if (...) ... else ...
 | 
|---|
| [1e97287] | 153 | class IfStmt final : public Stmt {
 | 
|---|
| [89a5a1f] | 154 |   public:
 | 
|---|
| [1e97287] | 155 |         ptr<Expr> cond;
 | 
|---|
| [3b0bc16] | 156 |         ptr<Stmt> then;
 | 
|---|
 | 157 |         ptr<Stmt> else_;
 | 
|---|
| [1e97287] | 158 |         std::vector<ptr<Stmt>> inits;
 | 
|---|
 | 159 | 
 | 
|---|
| [3b0bc16] | 160 |         IfStmt( const CodeLocation & loc, const Expr * cond, const Stmt * then,
 | 
|---|
| [6180274] | 161 |                         const Stmt * else_ = nullptr, const std::vector<ptr<Stmt>> && inits = {},
 | 
|---|
 | 162 |                         const std::vector<Label> && labels = {} )
 | 
|---|
| [3b0bc16] | 163 |                 : Stmt(loc, std::move(labels)), cond(cond), then(then), else_(else_),
 | 
|---|
| [89a5a1f] | 164 |                   inits(std::move(inits)) {}
 | 
|---|
| [1e97287] | 165 | 
 | 
|---|
| [f3cc5b6] | 166 |         const Stmt * accept( Visitor & v ) const override { return v.visit( this ); }
 | 
|---|
| [89a5a1f] | 167 |   private:
 | 
|---|
| [f3cc5b6] | 168 |         IfStmt * clone() const override { return new IfStmt{ *this }; }
 | 
|---|
 | 169 |         MUTATE_FRIEND
 | 
|---|
| [1e97287] | 170 | };
 | 
|---|
 | 171 | 
 | 
|---|
| [89a5a1f] | 172 | // Switch or choose statement: switch (...) { ... }
 | 
|---|
| [1e97287] | 173 | class SwitchStmt final : public Stmt {
 | 
|---|
| [89a5a1f] | 174 |   public:
 | 
|---|
| [1e97287] | 175 |         ptr<Expr> cond;
 | 
|---|
| [400b8be] | 176 |         std::vector<ptr<CaseClause>> cases;
 | 
|---|
| [1e97287] | 177 | 
 | 
|---|
| [400b8be] | 178 |         SwitchStmt( const CodeLocation & loc, const Expr * cond,
 | 
|---|
 | 179 |                                 const std::vector<ptr<CaseClause>> && cases,
 | 
|---|
| [6180274] | 180 |                                 const std::vector<Label> && labels = {} )
 | 
|---|
| [400b8be] | 181 |                 : Stmt(loc, std::move(labels)), cond(cond), cases(std::move(cases)) {}
 | 
|---|
| [1e97287] | 182 | 
 | 
|---|
| [f3cc5b6] | 183 |         const Stmt * accept( Visitor & v ) const override { return v.visit( this ); }
 | 
|---|
| [89a5a1f] | 184 |   private:
 | 
|---|
| [f3cc5b6] | 185 |         SwitchStmt * clone() const override { return new SwitchStmt{ *this }; }
 | 
|---|
 | 186 |         MUTATE_FRIEND
 | 
|---|
| [1e97287] | 187 | };
 | 
|---|
 | 188 | 
 | 
|---|
| [89a5a1f] | 189 | // Case label: case ...: or default:
 | 
|---|
| [400b8be] | 190 | class CaseClause final : public StmtClause {
 | 
|---|
| [89a5a1f] | 191 |   public:
 | 
|---|
 | 192 |         // Null for the default label.
 | 
|---|
| [1e97287] | 193 |         ptr<Expr> cond;
 | 
|---|
 | 194 |         std::vector<ptr<Stmt>> stmts;
 | 
|---|
 | 195 | 
 | 
|---|
| [400b8be] | 196 |         CaseClause( const CodeLocation & loc, const Expr * cond, const std::vector<ptr<Stmt>> && stmts )
 | 
|---|
 | 197 |                 : StmtClause(loc), cond(cond), stmts(std::move(stmts)) {}
 | 
|---|
| [1e97287] | 198 | 
 | 
|---|
| [675d816] | 199 |         bool isDefault() const { return !cond; }
 | 
|---|
| [1e97287] | 200 | 
 | 
|---|
| [400b8be] | 201 |         const CaseClause * accept( Visitor & v ) const override { return v.visit( this ); }
 | 
|---|
| [89a5a1f] | 202 |   private:
 | 
|---|
| [400b8be] | 203 |         CaseClause * clone() const override { return new CaseClause{ *this }; }
 | 
|---|
| [f3cc5b6] | 204 |         MUTATE_FRIEND
 | 
|---|
| [1e97287] | 205 | };
 | 
|---|
 | 206 | 
 | 
|---|
| [89a5a1f] | 207 | // While loop: while (...) ... else ... or do ... while (...) else ...;
 | 
|---|
| [3b0bc16] | 208 | class WhileDoStmt final : public Stmt {
 | 
|---|
| [89a5a1f] | 209 |   public:
 | 
|---|
| [1e97287] | 210 |         ptr<Expr> cond;
 | 
|---|
 | 211 |         ptr<Stmt> body;
 | 
|---|
| [3b0bc16] | 212 |         ptr<Stmt> else_;
 | 
|---|
| [1e97287] | 213 |         std::vector<ptr<Stmt>> inits;
 | 
|---|
 | 214 |         bool isDoWhile;
 | 
|---|
 | 215 | 
 | 
|---|
| [3b0bc16] | 216 |         WhileDoStmt( const CodeLocation & loc, const Expr * cond, const Stmt * body,
 | 
|---|
| [6180274] | 217 |                                  const std::vector<ptr<Stmt>> && inits, bool isDoWhile = false, const std::vector<Label> && labels = {} )
 | 
|---|
| [3b0bc16] | 218 |                 : Stmt(loc, std::move(labels)), cond(cond), body(body), else_(nullptr), inits(std::move(inits)), isDoWhile(isDoWhile) {}
 | 
|---|
 | 219 | 
 | 
|---|
 | 220 |         WhileDoStmt( const CodeLocation & loc, const Expr * cond, const Stmt * body, const Stmt * else_,
 | 
|---|
| [6180274] | 221 |                                  const std::vector<ptr<Stmt>> && inits, bool isDoWhile = false, const std::vector<Label> && labels = {} )
 | 
|---|
| [3b0bc16] | 222 |                 : Stmt(loc, std::move(labels)), cond(cond), body(body), else_(else_), inits(std::move(inits)), isDoWhile(isDoWhile) {}
 | 
|---|
| [1e97287] | 223 | 
 | 
|---|
| [f3cc5b6] | 224 |         const Stmt * accept( Visitor & v ) const override { return v.visit( this ); }
 | 
|---|
| [89a5a1f] | 225 |   private:
 | 
|---|
| [3b0bc16] | 226 |         WhileDoStmt * clone() const override { return new WhileDoStmt{ *this }; }
 | 
|---|
| [f3cc5b6] | 227 |         MUTATE_FRIEND
 | 
|---|
| [1e97287] | 228 | };
 | 
|---|
 | 229 | 
 | 
|---|
| [89a5a1f] | 230 | // For loop: for (... ; ... ; ...) ... else ...
 | 
|---|
| [1e97287] | 231 | class ForStmt final : public Stmt {
 | 
|---|
| [89a5a1f] | 232 |   public:
 | 
|---|
| [1e97287] | 233 |         std::vector<ptr<Stmt>> inits;
 | 
|---|
 | 234 |         ptr<Expr> cond;
 | 
|---|
| [8a5530c] | 235 |         ptr<Expr> inc;
 | 
|---|
| [1e97287] | 236 |         ptr<Stmt> body;
 | 
|---|
| [3b0bc16] | 237 |         ptr<Stmt> else_;
 | 
|---|
 | 238 | 
 | 
|---|
| [6180274] | 239 |         ForStmt( const CodeLocation & loc, const std::vector<ptr<Stmt>> && inits, const Expr * cond,
 | 
|---|
 | 240 |                          const Expr * inc, const Stmt * body, const std::vector<Label> && label = {} )
 | 
|---|
| [3b0bc16] | 241 |                 : Stmt(loc, std::move(label)), inits(std::move(inits)), cond(cond), inc(inc), body(body), else_(nullptr) {}
 | 
|---|
| [1e97287] | 242 | 
 | 
|---|
| [6180274] | 243 |         ForStmt( const CodeLocation & loc, const std::vector<ptr<Stmt>> && inits, const Expr * cond,
 | 
|---|
 | 244 |                          const Expr * inc, const Stmt * body, const Stmt * else_, const std::vector<Label> && labels = {} )
 | 
|---|
| [3b0bc16] | 245 |                 : Stmt(loc, std::move(labels)), inits(std::move(inits)), cond(cond), inc(inc), body(body), else_(else_) {}
 | 
|---|
| [1e97287] | 246 | 
 | 
|---|
| [f3cc5b6] | 247 |         const Stmt * accept( Visitor & v ) const override { return v.visit( this ); }
 | 
|---|
| [89a5a1f] | 248 |   private:
 | 
|---|
| [f3cc5b6] | 249 |         ForStmt * clone() const override { return new ForStmt{ *this }; }
 | 
|---|
 | 250 |         MUTATE_FRIEND
 | 
|---|
| [1e97287] | 251 | };
 | 
|---|
 | 252 | 
 | 
|---|
| [89a5a1f] | 253 | // Branch control flow statement: goto ... or break or continue or fallthru
 | 
|---|
| [1e97287] | 254 | class BranchStmt final : public Stmt {
 | 
|---|
| [89a5a1f] | 255 |   public:
 | 
|---|
| [1e97287] | 256 |         enum Kind { Goto, Break, Continue, FallThrough, FallThroughDefault };
 | 
|---|
 | 257 |         static constexpr size_t kindEnd = 1 + (size_t)FallThroughDefault;
 | 
|---|
 | 258 | 
 | 
|---|
 | 259 |         const Label originalTarget;
 | 
|---|
 | 260 |         Label target;
 | 
|---|
 | 261 |         ptr<Expr> computedTarget;
 | 
|---|
 | 262 |         Kind kind;
 | 
|---|
 | 263 | 
 | 
|---|
| [6180274] | 264 |         BranchStmt( const CodeLocation & loc, Kind kind, Label target, const std::vector<Label> && labels = {} );
 | 
|---|
 | 265 |         BranchStmt( const CodeLocation & loc, const Expr * computedTarget, const std::vector<Label> && labels = {} )
 | 
|---|
 | 266 |                 : Stmt(loc, std::move(labels)), originalTarget(loc), target(loc), computedTarget(computedTarget), kind(Goto) {}
 | 
|---|
| [1e97287] | 267 | 
 | 
|---|
| [94b1f718] | 268 |         const char * kindName() const { return kindNames[kind]; }
 | 
|---|
| [1e97287] | 269 | 
 | 
|---|
| [f3cc5b6] | 270 |         const Stmt * accept( Visitor & v ) const override { return v.visit( this ); }
 | 
|---|
| [89a5a1f] | 271 |   private:
 | 
|---|
| [f3cc5b6] | 272 |         BranchStmt * clone() const override { return new BranchStmt{ *this }; }
 | 
|---|
 | 273 |         MUTATE_FRIEND
 | 
|---|
| [8a5530c] | 274 | 
 | 
|---|
| [1e97287] | 275 |         static const char * kindNames[kindEnd];
 | 
|---|
 | 276 | };
 | 
|---|
 | 277 | 
 | 
|---|
| [89a5a1f] | 278 | // Return statement: return ...
 | 
|---|
| [1e97287] | 279 | class ReturnStmt final : public Stmt {
 | 
|---|
| [89a5a1f] | 280 |   public:
 | 
|---|
| [1e97287] | 281 |         ptr<Expr> expr;
 | 
|---|
 | 282 | 
 | 
|---|
| [6180274] | 283 |         ReturnStmt( const CodeLocation & loc, const Expr * expr, const std::vector<Label> && labels = {} )
 | 
|---|
| [89a5a1f] | 284 |                 : Stmt(loc, std::move(labels)), expr(expr) {}
 | 
|---|
| [1e97287] | 285 | 
 | 
|---|
| [f3cc5b6] | 286 |         const Stmt * accept( Visitor & v ) const override { return v.visit( this ); }
 | 
|---|
| [89a5a1f] | 287 |   private:
 | 
|---|
| [f3cc5b6] | 288 |         ReturnStmt * clone() const override { return new ReturnStmt{ *this }; }
 | 
|---|
 | 289 |         MUTATE_FRIEND
 | 
|---|
| [1e97287] | 290 | };
 | 
|---|
 | 291 | 
 | 
|---|
| [89a5a1f] | 292 | // Kind of exception
 | 
|---|
| [6f4b7f2] | 293 | enum ExceptionKind { Terminate, Resume };
 | 
|---|
 | 294 | 
 | 
|---|
| [89a5a1f] | 295 | // Throw statement: throw ...
 | 
|---|
| [1e97287] | 296 | class ThrowStmt final : public Stmt {
 | 
|---|
| [89a5a1f] | 297 |   public:
 | 
|---|
| [1e97287] | 298 |         ptr<Expr> expr;
 | 
|---|
 | 299 |         ptr<Expr> target;
 | 
|---|
| [6f4b7f2] | 300 |         ExceptionKind kind;
 | 
|---|
| [1e97287] | 301 | 
 | 
|---|
| [6180274] | 302 |         ThrowStmt( const CodeLocation & loc, ExceptionKind kind, const Expr * expr,
 | 
|---|
 | 303 |                            const Expr * target, const std::vector<Label> && labels = {} )
 | 
|---|
| [89a5a1f] | 304 |                 : Stmt(loc, std::move(labels)), expr(expr), target(target), kind(kind) {}
 | 
|---|
| [1e97287] | 305 | 
 | 
|---|
| [f3cc5b6] | 306 |         const Stmt * accept( Visitor & v ) const override { return v.visit( this ); }
 | 
|---|
| [89a5a1f] | 307 |   private:
 | 
|---|
| [f3cc5b6] | 308 |         ThrowStmt * clone() const override { return new ThrowStmt{ *this }; }
 | 
|---|
 | 309 |         MUTATE_FRIEND
 | 
|---|
| [1e97287] | 310 | };
 | 
|---|
 | 311 | 
 | 
|---|
| [89a5a1f] | 312 | // Try statement: try { ... } ...
 | 
|---|
| [1e97287] | 313 | class TryStmt final : public Stmt {
 | 
|---|
| [89a5a1f] | 314 |   public:
 | 
|---|
| [1e97287] | 315 |         ptr<CompoundStmt> body;
 | 
|---|
| [400b8be] | 316 |         std::vector<ptr<CatchClause>> handlers;
 | 
|---|
 | 317 |         ptr<FinallyClause> finally;
 | 
|---|
| [1e97287] | 318 | 
 | 
|---|
| [6180274] | 319 |         TryStmt( const CodeLocation & loc, const CompoundStmt * body,
 | 
|---|
| [400b8be] | 320 |                          const std::vector<ptr<CatchClause>> && handlers, const FinallyClause * finally,
 | 
|---|
| [6180274] | 321 |                          const std::vector<Label> && labels = {} )
 | 
|---|
| [89a5a1f] | 322 |                 : Stmt(loc, std::move(labels)), body(body), handlers(std::move(handlers)), finally(finally) {}
 | 
|---|
| [1e97287] | 323 | 
 | 
|---|
| [f3cc5b6] | 324 |         const Stmt * accept( Visitor & v ) const override { return v.visit( this ); }
 | 
|---|
| [89a5a1f] | 325 |   private:
 | 
|---|
| [f3cc5b6] | 326 |         TryStmt * clone() const override { return new TryStmt{ *this }; }
 | 
|---|
 | 327 |         MUTATE_FRIEND
 | 
|---|
| [1e97287] | 328 | };
 | 
|---|
 | 329 | 
 | 
|---|
| [89a5a1f] | 330 | // Catch clause of try statement
 | 
|---|
| [400b8be] | 331 | class CatchClause final : public StmtClause {
 | 
|---|
| [89a5a1f] | 332 |   public:
 | 
|---|
| [1e97287] | 333 |         ptr<Decl> decl;
 | 
|---|
 | 334 |         ptr<Expr> cond;
 | 
|---|
 | 335 |         ptr<Stmt> body;
 | 
|---|
| [6f4b7f2] | 336 |         ExceptionKind kind;
 | 
|---|
| [1e97287] | 337 | 
 | 
|---|
| [400b8be] | 338 |         CatchClause( const CodeLocation & loc, ExceptionKind kind, const Decl * decl, const Expr * cond,
 | 
|---|
 | 339 |                            const Stmt * body )
 | 
|---|
 | 340 |                 : StmtClause(loc), decl(decl), cond(cond), body(body), kind(kind) {}
 | 
|---|
| [1e97287] | 341 | 
 | 
|---|
| [400b8be] | 342 |         const CatchClause * accept( Visitor & v ) const override { return v.visit( this ); }
 | 
|---|
| [89a5a1f] | 343 |   private:
 | 
|---|
| [400b8be] | 344 |         CatchClause * clone() const override { return new CatchClause{ *this }; }
 | 
|---|
| [f3cc5b6] | 345 |         MUTATE_FRIEND
 | 
|---|
| [1e97287] | 346 | };
 | 
|---|
 | 347 | 
 | 
|---|
| [89a5a1f] | 348 | // Finally clause of try statement
 | 
|---|
| [400b8be] | 349 | class FinallyClause final : public StmtClause {
 | 
|---|
| [89a5a1f] | 350 |   public:
 | 
|---|
| [1e97287] | 351 |         ptr<CompoundStmt> body;
 | 
|---|
 | 352 | 
 | 
|---|
| [400b8be] | 353 |         FinallyClause( const CodeLocation & loc, const CompoundStmt * body )
 | 
|---|
 | 354 |                 : StmtClause(loc), body(body) {}
 | 
|---|
| [1e97287] | 355 | 
 | 
|---|
| [400b8be] | 356 |         const FinallyClause * accept( Visitor & v ) const override { return v.visit( this ); }
 | 
|---|
| [89a5a1f] | 357 |   private:
 | 
|---|
| [400b8be] | 358 |         FinallyClause * clone() const override { return new FinallyClause{ *this }; }
 | 
|---|
| [f3cc5b6] | 359 |         MUTATE_FRIEND
 | 
|---|
| [1e97287] | 360 | };
 | 
|---|
| [2bb4a01] | 361 | 
 | 
|---|
| [89a5a1f] | 362 | // Suspend statement
 | 
|---|
| [37cdd97] | 363 | class SuspendStmt final : public Stmt {
 | 
|---|
| [89a5a1f] | 364 |   public:
 | 
|---|
| [37cdd97] | 365 |         ptr<CompoundStmt> then;
 | 
|---|
 | 366 |         enum Type { None, Coroutine, Generator } type = None;
 | 
|---|
 | 367 | 
 | 
|---|
| [6180274] | 368 |         SuspendStmt( const CodeLocation & loc, const CompoundStmt * then, Type type, const std::vector<Label> && labels = {} )
 | 
|---|
| [89a5a1f] | 369 |                 : Stmt(loc, std::move(labels)), then(then), type(type) {}
 | 
|---|
| [37cdd97] | 370 | 
 | 
|---|
 | 371 |         const Stmt * accept( Visitor & v ) const override { return v.visit( this ); }
 | 
|---|
| [89a5a1f] | 372 |   private:
 | 
|---|
| [37cdd97] | 373 |         SuspendStmt * clone() const override { return new SuspendStmt{ *this }; }
 | 
|---|
 | 374 |         MUTATE_FRIEND
 | 
|---|
 | 375 | };
 | 
|---|
 | 376 | 
 | 
|---|
| [89a5a1f] | 377 | // Waitfor statement: when (...) waitfor (... , ...) ... timeout(...) ... else ...
 | 
|---|
| [1e97287] | 378 | class WaitForStmt final : public Stmt {
 | 
|---|
| [89a5a1f] | 379 |   public:
 | 
|---|
| [1e97287] | 380 |         struct Target {
 | 
|---|
| [e0016a5] | 381 |                 ptr<Expr> func;
 | 
|---|
 | 382 |                 std::vector<ptr<Expr>> args;
 | 
|---|
| [1e97287] | 383 |         };
 | 
|---|
 | 384 | 
 | 
|---|
 | 385 |         struct Clause {
 | 
|---|
 | 386 |                 Target target;
 | 
|---|
 | 387 |                 ptr<Stmt> stmt;
 | 
|---|
 | 388 |                 ptr<Expr> cond;
 | 
|---|
 | 389 |         };
 | 
|---|
 | 390 | 
 | 
|---|
 | 391 |         struct Timeout {
 | 
|---|
 | 392 |                 ptr<Expr> time;
 | 
|---|
 | 393 |                 ptr<Stmt> stmt;
 | 
|---|
 | 394 |                 ptr<Expr> cond;
 | 
|---|
 | 395 |         };
 | 
|---|
 | 396 | 
 | 
|---|
 | 397 |         struct OrElse {
 | 
|---|
 | 398 |                 ptr<Stmt> stmt;
 | 
|---|
 | 399 |                 ptr<Expr> cond;
 | 
|---|
 | 400 |         };
 | 
|---|
 | 401 | 
 | 
|---|
 | 402 |         std::vector<Clause> clauses;
 | 
|---|
 | 403 |         Timeout timeout;
 | 
|---|
 | 404 |         OrElse orElse;
 | 
|---|
 | 405 | 
 | 
|---|
| [6180274] | 406 |         WaitForStmt( const CodeLocation & loc, const std::vector<Label> && labels = {} )
 | 
|---|
| [89a5a1f] | 407 |                 : Stmt(loc, std::move(labels)) {}
 | 
|---|
| [1e97287] | 408 | 
 | 
|---|
| [f3cc5b6] | 409 |         const Stmt * accept( Visitor & v ) const override { return v.visit( this ); }
 | 
|---|
| [89a5a1f] | 410 |   private:
 | 
|---|
| [f3cc5b6] | 411 |         WaitForStmt * clone() const override { return new WaitForStmt{ *this }; }
 | 
|---|
 | 412 |         MUTATE_FRIEND
 | 
|---|
| [1e97287] | 413 | };
 | 
|---|
 | 414 | 
 | 
|---|
| [89a5a1f] | 415 | // Any declaration in a (compound) statement.
 | 
|---|
| [1e97287] | 416 | class DeclStmt final : public Stmt {
 | 
|---|
| [89a5a1f] | 417 |   public:
 | 
|---|
| [1e97287] | 418 |         ptr<Decl> decl;
 | 
|---|
 | 419 | 
 | 
|---|
| [6180274] | 420 |         DeclStmt( const CodeLocation & loc, const Decl * decl, const std::vector<Label> && labels = {} )
 | 
|---|
| [89a5a1f] | 421 |                 : Stmt(loc, std::move(labels)), decl(decl) {}
 | 
|---|
| [1e97287] | 422 | 
 | 
|---|
| [f3cc5b6] | 423 |         const Stmt * accept( Visitor & v ) const override { return v.visit( this ); }
 | 
|---|
| [89a5a1f] | 424 |   private:
 | 
|---|
| [f3cc5b6] | 425 |         DeclStmt * clone() const override { return new DeclStmt{ *this }; }
 | 
|---|
 | 426 |         MUTATE_FRIEND
 | 
|---|
| [1e97287] | 427 | };
 | 
|---|
 | 428 | 
 | 
|---|
| [89a5a1f] | 429 | // Represents an implicit application of a constructor or destructor.
 | 
|---|
| [1e97287] | 430 | class ImplicitCtorDtorStmt final : public Stmt {
 | 
|---|
| [89a5a1f] | 431 |   public:
 | 
|---|
| [c570806] | 432 |         ptr<Stmt> callStmt;
 | 
|---|
| [1e97287] | 433 | 
 | 
|---|
| [f3cc5b6] | 434 |         ImplicitCtorDtorStmt( const CodeLocation & loc, const Stmt * callStmt,
 | 
|---|
| [89a5a1f] | 435 |                                                   std::vector<Label> && labels = {} )
 | 
|---|
 | 436 |                 : Stmt(loc, std::move(labels)), callStmt(callStmt) {}
 | 
|---|
| [1e97287] | 437 | 
 | 
|---|
| [f3cc5b6] | 438 |         const Stmt * accept( Visitor & v ) const override { return v.visit( this ); }
 | 
|---|
| [89a5a1f] | 439 |   private:
 | 
|---|
| [f3cc5b6] | 440 |         ImplicitCtorDtorStmt * clone() const override { return new ImplicitCtorDtorStmt{ *this }; }
 | 
|---|
 | 441 |         MUTATE_FRIEND
 | 
|---|
| [1e97287] | 442 | };
 | 
|---|
| [2bb4a01] | 443 | 
 | 
|---|
| [89a5a1f] | 444 | // Mutex Statement
 | 
|---|
| [6cebfef] | 445 | class MutexStmt final : public Stmt {
 | 
|---|
| [89a5a1f] | 446 |   public:
 | 
|---|
| [6cebfef] | 447 |         ptr<Stmt> stmt;
 | 
|---|
 | 448 |         std::vector<ptr<Expr>> mutexObjs;
 | 
|---|
 | 449 | 
 | 
|---|
 | 450 |         MutexStmt( const CodeLocation & loc, const Stmt * stmt, 
 | 
|---|
| [6180274] | 451 |                            const std::vector<ptr<Expr>> && mutexes, const std::vector<Label> && labels = {} )
 | 
|---|
| [89a5a1f] | 452 |                 : Stmt(loc, std::move(labels)), stmt(stmt), mutexObjs(std::move(mutexes)) {}
 | 
|---|
| [6cebfef] | 453 | 
 | 
|---|
 | 454 |         const Stmt * accept( Visitor & v ) const override { return v.visit( this ); }
 | 
|---|
| [89a5a1f] | 455 |   private:
 | 
|---|
| [6cebfef] | 456 |         MutexStmt * clone() const override { return new MutexStmt{ *this }; }
 | 
|---|
 | 457 |         MUTATE_FRIEND
 | 
|---|
 | 458 | };
 | 
|---|
| [89a5a1f] | 459 | } // namespace ast
 | 
|---|
| [2bb4a01] | 460 | 
 | 
|---|
| [f3cc5b6] | 461 | #undef MUTATE_FRIEND
 | 
|---|
 | 462 | 
 | 
|---|
| [2bb4a01] | 463 | // Local Variables: //
 | 
|---|
 | 464 | // mode: c++ //
 | 
|---|
| [1e97287] | 465 | // End: //
 | 
|---|