Collapse Sequence into Block. (#927)

This commit is contained in:
Jon Meow
2021-11-01 14:59:39 -07:00
committed by GitHub
parent e69ec3f528
commit 904774fbb8
7 changed files with 60 additions and 131 deletions
+8 -31
View File
@@ -27,7 +27,6 @@ class Statement {
VariableDefinition,
If,
Return,
Sequence,
Block,
While,
Break,
@@ -60,46 +59,24 @@ class Statement {
SourceLocation source_loc_;
};
class Sequence : public Statement {
public:
Sequence(SourceLocation source_loc, Nonnull<Statement*> statement,
std::optional<Nonnull<Statement*>> next)
: Statement(Kind::Sequence, source_loc),
statement_(statement),
next_(next) {}
static auto classof(const Statement* stmt) -> bool {
return stmt->kind() == Kind::Sequence;
}
auto statement() const -> const Statement& { return *statement_; }
auto statement() -> Statement& { return *statement_; }
auto next() const -> std::optional<Nonnull<const Statement*>> {
return next_;
}
auto next() -> std::optional<Nonnull<Statement*>> { return next_; }
private:
Nonnull<Statement*> statement_;
std::optional<Nonnull<Statement*>> next_;
};
class Block : public Statement {
public:
Block(SourceLocation source_loc, std::optional<Nonnull<Sequence*>> sequence)
: Statement(Kind::Block, source_loc), sequence_(sequence) {}
Block(SourceLocation source_loc, std::vector<Nonnull<Statement*>> statements)
: Statement(Kind::Block, source_loc), statements_(statements) {}
static auto classof(const Statement* stmt) -> bool {
return stmt->kind() == Kind::Block;
}
auto sequence() const -> std::optional<Nonnull<const Sequence*>> {
return sequence_;
auto statements() const -> llvm::ArrayRef<Nonnull<const Statement*>> {
return statements_;
}
auto statements() -> llvm::MutableArrayRef<Nonnull<Statement*>> {
return statements_;
}
auto sequence() -> std::optional<Nonnull<Sequence*>> { return sequence_; }
private:
std::optional<Nonnull<Sequence*>> sequence_;
std::vector<Nonnull<Statement*>> statements_;
};
class ExpressionStatement : public Statement {