mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-05 22:02:55 +01:00
Collapse Sequence into Block. (#927)
This commit is contained in:
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user