7 #include "diagnostics/Location.h"
8 #include "utils/Utils.h"
14 class BlockStatement
final :
public Stmt {
16 BlockStatement(BumpAllocator& alloc, array_ref<Stmt*> stmts)
noexcept
18 utils::move_vector<Stmt*>(stmts, stmts_);
21 std::ostream& print(std::ostream& os,
int indentation = 0)
const override;
22 int printDotNode(DotPrinter& dp)
const override;
25 for(
auto stmt : stmts_)
co_yield stmt;
28 auto stmts()
const {
return std::views::all(stmts_); }
31 pmr_vector<Stmt*> stmts_;
34 class DeclStmt
final :
public Stmt {
36 DeclStmt(
VarDecl* decl) : decl_{decl} {}
38 std::ostream& print(std::ostream& os,
int indentation = 0)
const override;
39 int printDotNode(DotPrinter& dp)
const override;
41 auto decl()
const {
return decl_; }
51 class ExprStmt
final :
public Stmt {
53 ExprStmt(
Expr* expr) : expr_{expr} {}
55 std::ostream& print(std::ostream& os,
int indentation = 0)
const override;
56 int printDotNode(DotPrinter& dp)
const override;
58 auto expr()
const {
return expr_; }
65 class IfStmt
final :
public Stmt {
68 : condition_{condition}, thenStmt_{thenStmt}, elseStmt_{elseStmt} {}
70 std::ostream& print(std::ostream& os,
int indentation = 0)
const override;
71 int printDotNode(DotPrinter& dp)
const override;
73 auto condition()
const {
return condition_; }
74 auto thenStmt()
const {
return thenStmt_; }
75 auto elseStmt()
const {
return elseStmt_; }
79 if(elseStmt_)
co_yield elseStmt_;
88 class WhileStmt
final :
public Stmt {
90 WhileStmt(
Expr* condition,
Stmt* body) : condition_{condition}, body_{body} {}
91 std::ostream& print(std::ostream& os,
int indentation = 0)
const override;
92 int printDotNode(DotPrinter& dp)
const override;
93 auto condition()
const {
return condition_; }
94 auto body()
const {
return body_; }
105 class ForStmt
final :
public Stmt {
108 : init_{init}, condition_{condition}, update_{update}, body_{body} {}
110 std::ostream& print(std::ostream& os,
int indentation = 0)
const override;
111 int printDotNode(DotPrinter& dp)
const override;
113 auto init()
const {
return init_; }
114 auto condition()
const {
return condition_; }
115 auto update()
const {
return update_; }
116 auto body()
const {
return body_; }
131 class ReturnStmt
final :
public Stmt {
135 std::ostream& print(std::ostream& os,
int indentation = 0)
const override;
136 int printDotNode(DotPrinter& dp)
const override;
138 auto expr()
const {
return expr_; }
149 class NullStmt
final :
public Stmt {
151 std::ostream& print(std::ostream& os,
int indentation = 0)
const override;
152 int printDotNode(DotPrinter& dp)
const override;