source: src/AST/Stmt.hpp@ f5dbc8d

Last change on this file since f5dbc8d was d3aa55e9, checked in by JiadaL <j82liang@…>, 15 months ago
  1. Disallow implicit conversion from cfa enum to int during on the function call site; 2. implement the reverse enum loop
  • Property mode set to 100644
File size: 19.0 KB
RevLine 
[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
[3e94a23]12// Last Modified On : Wed Apr 5 10:34:00 2023
13// Update Count : 37
[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"
[c92bdcc]26#include "Common/CodeLocation.hpp"
[2bb4a01]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 \
[a1da039]30 template<typename node_t> friend node_t * mutate(const node_t * node); \
[99da267]31 template<typename node_t> friend node_t * shallowCopy(const node_t * node);
[f3cc5b6]32
[2bb4a01]33namespace ast {
34class Expr;
35
[89a5a1f]36// Base statement node
[2bb4a01]37class 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).
53class 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
[491bb81]60 StmtClause( const CodeLocation & loc )
[400b8be]61 : ParseNode(loc) {}
62
63 private:
64 StmtClause * clone() const override = 0;
65 MUTATE_FRIEND
66};
67
[89a5a1f]68// Compound statement: { ... }
[2bb4a01]69class 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]89class 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]101class 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]115class 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]138class 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]153class 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]173class 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]190class 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
[3e94a23]207// A while loop or a do-while loop:
208enum WhileDoKind { While, DoWhile };
209
[89a5a1f]210// While loop: while (...) ... else ... or do ... while (...) else ...;
[3b0bc16]211class WhileDoStmt final : public Stmt {
[89a5a1f]212 public:
[1e97287]213 ptr<Expr> cond;
214 ptr<Stmt> body;
[3b0bc16]215 ptr<Stmt> else_;
[1e97287]216 std::vector<ptr<Stmt>> inits;
[3e94a23]217 WhileDoKind isDoWhile;
[1e97287]218
[3b0bc16]219 WhileDoStmt( const CodeLocation & loc, const Expr * cond, const Stmt * body,
[3e94a23]220 const std::vector<ptr<Stmt>> && inits, WhileDoKind isDoWhile = While, const std::vector<Label> && labels = {} )
[3b0bc16]221 : Stmt(loc, std::move(labels)), cond(cond), body(body), else_(nullptr), inits(std::move(inits)), isDoWhile(isDoWhile) {}
222
223 WhileDoStmt( const CodeLocation & loc, const Expr * cond, const Stmt * body, const Stmt * else_,
[3e94a23]224 const std::vector<ptr<Stmt>> && inits, WhileDoKind isDoWhile = While, const std::vector<Label> && labels = {} )
[3b0bc16]225 : Stmt(loc, std::move(labels)), cond(cond), body(body), else_(else_), inits(std::move(inits)), isDoWhile(isDoWhile) {}
[1e97287]226
[f3cc5b6]227 const Stmt * accept( Visitor & v ) const override { return v.visit( this ); }
[89a5a1f]228 private:
[3b0bc16]229 WhileDoStmt * clone() const override { return new WhileDoStmt{ *this }; }
[f3cc5b6]230 MUTATE_FRIEND
[1e97287]231};
232
[89a5a1f]233// For loop: for (... ; ... ; ...) ... else ...
[1e97287]234class ForStmt final : public Stmt {
[89a5a1f]235 public:
[1e97287]236 std::vector<ptr<Stmt>> inits;
237 ptr<Expr> cond;
[8a5530c]238 ptr<Expr> inc;
[525f7ad]239 ptr<Expr> range_over;
[d3aa55e9]240 bool is_inc;
[1e97287]241 ptr<Stmt> body;
[3b0bc16]242 ptr<Stmt> else_;
243
[6180274]244 ForStmt( const CodeLocation & loc, const std::vector<ptr<Stmt>> && inits, const Expr * cond,
245 const Expr * inc, const Stmt * body, const std::vector<Label> && label = {} )
[525f7ad]246 : Stmt(loc, std::move(label)), inits(std::move(inits)), cond(cond), inc(inc),
247 range_over(nullptr), body(body), else_(nullptr) {}
[1e97287]248
[6180274]249 ForStmt( const CodeLocation & loc, const std::vector<ptr<Stmt>> && inits, const Expr * cond,
250 const Expr * inc, const Stmt * body, const Stmt * else_, const std::vector<Label> && labels = {} )
[525f7ad]251 : Stmt(loc, std::move(labels)), inits(std::move(inits)), cond(cond), inc(inc),
252 range_over(nullptr), body(body), else_(else_) {}
253
[d3aa55e9]254 ForStmt( const CodeLocation & loc, const std::vector<ptr<Stmt>> && inits, const Expr * range_over, bool is_inc,
[525f7ad]255 const Stmt * body, const Stmt * else_ )
[d3aa55e9]256 : Stmt(loc, std::move(labels)), inits(std::move(inits)), range_over(range_over), is_inc(is_inc),
257 body(body), else_(else_) {}
[1e97287]258
[f3cc5b6]259 const Stmt * accept( Visitor & v ) const override { return v.visit( this ); }
[89a5a1f]260 private:
[f3cc5b6]261 ForStmt * clone() const override { return new ForStmt{ *this }; }
262 MUTATE_FRIEND
[1e97287]263};
264
[89a5a1f]265// Branch control flow statement: goto ... or break or continue or fallthru
[1e97287]266class BranchStmt final : public Stmt {
[89a5a1f]267 public:
[1e97287]268 enum Kind { Goto, Break, Continue, FallThrough, FallThroughDefault };
269 static constexpr size_t kindEnd = 1 + (size_t)FallThroughDefault;
270
271 const Label originalTarget;
272 Label target;
273 ptr<Expr> computedTarget;
274 Kind kind;
275
[6180274]276 BranchStmt( const CodeLocation & loc, Kind kind, Label target, const std::vector<Label> && labels = {} );
277 BranchStmt( const CodeLocation & loc, const Expr * computedTarget, const std::vector<Label> && labels = {} )
278 : Stmt(loc, std::move(labels)), originalTarget(loc), target(loc), computedTarget(computedTarget), kind(Goto) {}
[1e97287]279
[94b1f718]280 const char * kindName() const { return kindNames[kind]; }
[1e97287]281
[f3cc5b6]282 const Stmt * accept( Visitor & v ) const override { return v.visit( this ); }
[89a5a1f]283 private:
[f3cc5b6]284 BranchStmt * clone() const override { return new BranchStmt{ *this }; }
285 MUTATE_FRIEND
[8a5530c]286
[1e97287]287 static const char * kindNames[kindEnd];
288};
289
[89a5a1f]290// Return statement: return ...
[1e97287]291class ReturnStmt final : public Stmt {
[89a5a1f]292 public:
[1e97287]293 ptr<Expr> expr;
294
[6180274]295 ReturnStmt( const CodeLocation & loc, const Expr * expr, const std::vector<Label> && labels = {} )
[89a5a1f]296 : Stmt(loc, std::move(labels)), expr(expr) {}
[1e97287]297
[f3cc5b6]298 const Stmt * accept( Visitor & v ) const override { return v.visit( this ); }
[89a5a1f]299 private:
[f3cc5b6]300 ReturnStmt * clone() const override { return new ReturnStmt{ *this }; }
301 MUTATE_FRIEND
[1e97287]302};
303
[89a5a1f]304// Kind of exception
[6f4b7f2]305enum ExceptionKind { Terminate, Resume };
306
[89a5a1f]307// Throw statement: throw ...
[1e97287]308class ThrowStmt final : public Stmt {
[89a5a1f]309 public:
[1e97287]310 ptr<Expr> expr;
311 ptr<Expr> target;
[6f4b7f2]312 ExceptionKind kind;
[1e97287]313
[6180274]314 ThrowStmt( const CodeLocation & loc, ExceptionKind kind, const Expr * expr,
315 const Expr * target, const std::vector<Label> && labels = {} )
[89a5a1f]316 : Stmt(loc, std::move(labels)), expr(expr), target(target), kind(kind) {}
[1e97287]317
[f3cc5b6]318 const Stmt * accept( Visitor & v ) const override { return v.visit( this ); }
[89a5a1f]319 private:
[f3cc5b6]320 ThrowStmt * clone() const override { return new ThrowStmt{ *this }; }
321 MUTATE_FRIEND
[1e97287]322};
323
[89a5a1f]324// Try statement: try { ... } ...
[1e97287]325class TryStmt final : public Stmt {
[89a5a1f]326 public:
[1e97287]327 ptr<CompoundStmt> body;
[400b8be]328 std::vector<ptr<CatchClause>> handlers;
329 ptr<FinallyClause> finally;
[1e97287]330
[6180274]331 TryStmt( const CodeLocation & loc, const CompoundStmt * body,
[400b8be]332 const std::vector<ptr<CatchClause>> && handlers, const FinallyClause * finally,
[6180274]333 const std::vector<Label> && labels = {} )
[89a5a1f]334 : Stmt(loc, std::move(labels)), body(body), handlers(std::move(handlers)), finally(finally) {}
[1e97287]335
[f3cc5b6]336 const Stmt * accept( Visitor & v ) const override { return v.visit( this ); }
[89a5a1f]337 private:
[f3cc5b6]338 TryStmt * clone() const override { return new TryStmt{ *this }; }
339 MUTATE_FRIEND
[1e97287]340};
341
[89a5a1f]342// Catch clause of try statement
[400b8be]343class CatchClause final : public StmtClause {
[89a5a1f]344 public:
[1e97287]345 ptr<Decl> decl;
346 ptr<Expr> cond;
347 ptr<Stmt> body;
[6f4b7f2]348 ExceptionKind kind;
[1e97287]349
[400b8be]350 CatchClause( const CodeLocation & loc, ExceptionKind kind, const Decl * decl, const Expr * cond,
[a1da039]351 const Stmt * body )
[400b8be]352 : StmtClause(loc), decl(decl), cond(cond), body(body), kind(kind) {}
[1e97287]353
[400b8be]354 const CatchClause * accept( Visitor & v ) const override { return v.visit( this ); }
[89a5a1f]355 private:
[400b8be]356 CatchClause * clone() const override { return new CatchClause{ *this }; }
[f3cc5b6]357 MUTATE_FRIEND
[1e97287]358};
359
[89a5a1f]360// Finally clause of try statement
[400b8be]361class FinallyClause final : public StmtClause {
[89a5a1f]362 public:
[1e97287]363 ptr<CompoundStmt> body;
364
[400b8be]365 FinallyClause( const CodeLocation & loc, const CompoundStmt * body )
366 : StmtClause(loc), body(body) {}
[1e97287]367
[400b8be]368 const FinallyClause * accept( Visitor & v ) const override { return v.visit( this ); }
[89a5a1f]369 private:
[400b8be]370 FinallyClause * clone() const override { return new FinallyClause{ *this }; }
[f3cc5b6]371 MUTATE_FRIEND
[1e97287]372};
[2bb4a01]373
[89a5a1f]374// Suspend statement
[37cdd97]375class SuspendStmt final : public Stmt {
[89a5a1f]376 public:
[37cdd97]377 ptr<CompoundStmt> then;
[835d6e8]378 enum Kind { None, Coroutine, Generator } kind = None;
[37cdd97]379
[835d6e8]380 SuspendStmt( const CodeLocation & loc, const CompoundStmt * then, Kind kind, const std::vector<Label> && labels = {} )
381 : Stmt(loc, std::move(labels)), then(then), kind(kind) {}
[37cdd97]382
383 const Stmt * accept( Visitor & v ) const override { return v.visit( this ); }
[89a5a1f]384 private:
[37cdd97]385 SuspendStmt * clone() const override { return new SuspendStmt{ *this }; }
386 MUTATE_FRIEND
387};
388
[c86b08d]389// Base class of WaitFor/WaitUntil statements
390// form: KEYWORD(...) ... timeout(...) ... else ...
[a1da039]391class WaitStmt : public Stmt {
[89a5a1f]392 public:
[a1da039]393 ptr<Expr> timeout_time;
[f6e6a55]394 ptr<Stmt> timeout_stmt;
395 ptr<Expr> timeout_cond;
396 ptr<Stmt> else_stmt;
397 ptr<Expr> else_cond;
[1e97287]398
[a1da039]399 WaitStmt( const CodeLocation & loc, const std::vector<Label> && labels = {} )
[89a5a1f]400 : Stmt(loc, std::move(labels)) {}
[1e97287]401
[c86b08d]402 private:
[a1da039]403 WaitStmt * clone() const override = 0;
[c86b08d]404 MUTATE_FRIEND
405};
406
407// Base class for WaitFor/WaitUntil clauses
408// form: when( when_cond ) KEYWORD( target ) stmt
409class WhenClause : public StmtClause {
410 public:
411 ptr<Expr> target;
412 ptr<Stmt> stmt;
413 ptr<Expr> when_cond;
414
415 WhenClause( const CodeLocation & loc )
416 : StmtClause( loc ) {}
417
418 const WhenClause * accept( Visitor & v ) const override { return v.visit( this ); }
419 private:
420 WhenClause * clone() const override { return new WhenClause{ *this }; }
421 MUTATE_FRIEND
422};
423
424// Waitfor statement: when (...) waitfor (... , ...) ... timeout(...) ... else ...
425class WaitForStmt final : public WaitStmt {
426 public:
427 std::vector<ptr<WaitForClause>> clauses;
428
429 WaitForStmt( const CodeLocation & loc, const std::vector<Label> && labels = {} )
430 : WaitStmt(loc, std::move(labels)) {}
431
[f3cc5b6]432 const Stmt * accept( Visitor & v ) const override { return v.visit( this ); }
[89a5a1f]433 private:
[f3cc5b6]434 WaitForStmt * clone() const override { return new WaitForStmt{ *this }; }
435 MUTATE_FRIEND
[1e97287]436};
437
[94c98f0e]438// Clause in a waitfor statement: waitfor (..., ...) ...
[c86b08d]439class WaitForClause final : public WhenClause {
[f6e6a55]440 public:
[491bb81]441 std::vector<ptr<Expr>> target_args;
[f6e6a55]442
[491bb81]443 WaitForClause( const CodeLocation & loc )
[c86b08d]444 : WhenClause( loc ) {}
[f6e6a55]445
446 const WaitForClause * accept( Visitor & v ) const override { return v.visit( this ); }
447 private:
[491bb81]448 WaitForClause * clone() const override { return new WaitForClause{ *this }; }
449 MUTATE_FRIEND
[f6e6a55]450};
451
[c86b08d]452// waituntil statement: when (...) waituntil (...) ... timeout(...) ... else ...
453class WaitUntilStmt final : public WaitStmt {
454 public:
[a1da039]455 // Non-ast node used during compilation to store data needed to generate predicates
456 // and set initial status values for clauses
457 // Used to create a tree corresponding to the structure of the clauses in a WaitUntil
458 struct ClauseNode {
459 enum Op { AND, OR, LEFT_OR, LEAF, ELSE, TIMEOUT } op; // operation/type tag
460 // LEFT_OR used with TIMEOUT/ELSE to indicate that we ignore right hand side after parsing
461
462 ClauseNode * left;
463 ClauseNode * right;
464 WhenClause * leaf; // only set if this node is a leaf (points into vector of clauses)
465
466 bool ambiguousWhen; // used to paint nodes of predicate tree based on when() clauses
467 bool whenState; // used to track if when_cond is toggled on or off for generating init values
468 bool childOfAnd; // true on leaf nodes that are children of AND, false otherwise
469
470 ClauseNode( Op op, ClauseNode * left, ClauseNode * right )
471 : op(op), left(left), right(right), leaf(nullptr),
472 ambiguousWhen(false), whenState(true), childOfAnd(false) {}
473 ClauseNode( Op op, WhenClause * leaf )
474 : op(op), left(nullptr), right(nullptr), leaf(leaf),
475 ambiguousWhen(false), whenState(true), childOfAnd(false) {}
476 ClauseNode( WhenClause * leaf ) : ClauseNode(LEAF, leaf) {}
477
478 ~ClauseNode() {
479 if ( left ) delete left;
480 if ( right ) delete right;
481 }
482 };
[c86b08d]483
484 std::vector<ptr<WhenClause>> clauses;
[a1da039]485 ClauseNode * predicateTree;
[c86b08d]486
487 WaitUntilStmt( const CodeLocation & loc, const std::vector<Label> && labels = {} )
488 : WaitStmt(loc, std::move(labels)) {}
489
[a1da039]490 ~WaitUntilStmt() { delete predicateTree; }
[c86b08d]491
492 const Stmt * accept( Visitor & v ) const override { return v.visit( this ); }
493 private:
494 WaitUntilStmt * clone() const override { return new WaitUntilStmt{ *this }; }
495 MUTATE_FRIEND
496};
497
[89a5a1f]498// Any declaration in a (compound) statement.
[1e97287]499class DeclStmt final : public Stmt {
[89a5a1f]500 public:
[1e97287]501 ptr<Decl> decl;
502
[6180274]503 DeclStmt( const CodeLocation & loc, const Decl * decl, const std::vector<Label> && labels = {} )
[89a5a1f]504 : Stmt(loc, std::move(labels)), decl(decl) {}
[1e97287]505
[f3cc5b6]506 const Stmt * accept( Visitor & v ) const override { return v.visit( this ); }
[89a5a1f]507 private:
[f3cc5b6]508 DeclStmt * clone() const override { return new DeclStmt{ *this }; }
509 MUTATE_FRIEND
[1e97287]510};
511
[89a5a1f]512// Represents an implicit application of a constructor or destructor.
[1e97287]513class ImplicitCtorDtorStmt final : public Stmt {
[89a5a1f]514 public:
[c570806]515 ptr<Stmt> callStmt;
[1e97287]516
[f3cc5b6]517 ImplicitCtorDtorStmt( const CodeLocation & loc, const Stmt * callStmt,
[89a5a1f]518 std::vector<Label> && labels = {} )
519 : Stmt(loc, std::move(labels)), callStmt(callStmt) {}
[1e97287]520
[f3cc5b6]521 const Stmt * accept( Visitor & v ) const override { return v.visit( this ); }
[89a5a1f]522 private:
[f3cc5b6]523 ImplicitCtorDtorStmt * clone() const override { return new ImplicitCtorDtorStmt{ *this }; }
524 MUTATE_FRIEND
[1e97287]525};
[2bb4a01]526
[89a5a1f]527// Mutex Statement
[6cebfef]528class MutexStmt final : public Stmt {
[89a5a1f]529 public:
[6cebfef]530 ptr<Stmt> stmt;
531 std::vector<ptr<Expr>> mutexObjs;
532
[a1da039]533 MutexStmt( const CodeLocation & loc, const Stmt * stmt,
[6180274]534 const std::vector<ptr<Expr>> && mutexes, const std::vector<Label> && labels = {} )
[89a5a1f]535 : Stmt(loc, std::move(labels)), stmt(stmt), mutexObjs(std::move(mutexes)) {}
[6cebfef]536
537 const Stmt * accept( Visitor & v ) const override { return v.visit( this ); }
[89a5a1f]538 private:
[6cebfef]539 MutexStmt * clone() const override { return new MutexStmt{ *this }; }
540 MUTATE_FRIEND
541};
[94c98f0e]542
[eb779d5]543// Corun Statement
544class CorunStmt final : public Stmt {
545 public:
546 ptr<Stmt> stmt;
547
548 CorunStmt( const CodeLocation & loc, const Stmt * stmt, const std::vector<Label> && labels = {} )
549 : Stmt(loc, std::move(labels)), stmt(stmt) {}
550
551 const Stmt * accept( Visitor & v ) const override { return v.visit( this ); }
552 private:
553 CorunStmt * clone() const override { return new CorunStmt{ *this }; }
554 MUTATE_FRIEND
555};
556
[3d9d017]557// Corun Statement
558class CoforStmt final : public Stmt {
559 public:
560 std::vector<ptr<Stmt>> inits;
561 ptr<Expr> cond;
562 ptr<Expr> inc;
563 ptr<Stmt> body;
564
565 CoforStmt( const CodeLocation & loc, const std::vector<ptr<Stmt>> && inits, const Expr * cond,
566 const Expr * inc, const Stmt * body, const std::vector<Label> && label = {} )
567 : Stmt(loc, std::move(label)), inits(std::move(inits)), cond(cond), inc(inc), body(body) {}
568
569 const Stmt * accept( Visitor & v ) const override { return v.visit( this ); }
570 private:
571 CoforStmt * clone() const override { return new CoforStmt{ *this }; }
572 MUTATE_FRIEND
573};
574
[89a5a1f]575} // namespace ast
[2bb4a01]576
[f3cc5b6]577#undef MUTATE_FRIEND
578
[2bb4a01]579// Local Variables: //
580// mode: c++ //
[1e97287]581// End: //
Note: See TracBrowser for help on using the repository browser.