mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-03 22:02:51 +01:00
Unify Action and Scope stacks, and eliminate Frame (#880)
Co-authored-by: Jon Meow <46229924+jonmeow@users.noreply.github.com>
This commit is contained in:
committed by
GitHub
co-authored by
Jon Meow
parent
44154c8663
commit
3bec7f8dc0
@@ -17,6 +17,8 @@
|
||||
|
||||
namespace Carbon {
|
||||
|
||||
class FunctionDeclaration;
|
||||
|
||||
class Statement {
|
||||
public:
|
||||
enum class Kind {
|
||||
@@ -167,9 +169,24 @@ class Return : public Statement {
|
||||
auto expression() -> Expression& { return *expression_; }
|
||||
auto is_omitted_expression() const -> bool { return is_omitted_expression_; }
|
||||
|
||||
// The AST node representing the function body this statement returns from.
|
||||
// Can only be called after ResolveControlFlow has visited this node.
|
||||
//
|
||||
// Note that this function does not represent an edge in the tree
|
||||
// structure of the AST: the return value is not a child of this node,
|
||||
// but an ancestor.
|
||||
auto function() const -> const FunctionDeclaration& { return **function_; }
|
||||
|
||||
// Can only be called once, by ResolveControlFlow.
|
||||
void set_function(Nonnull<const FunctionDeclaration*> function) {
|
||||
CHECK(!function_.has_value());
|
||||
function_ = function;
|
||||
}
|
||||
|
||||
private:
|
||||
Nonnull<Expression*> expression_;
|
||||
bool is_omitted_expression_;
|
||||
std::optional<Nonnull<const FunctionDeclaration*>> function_;
|
||||
};
|
||||
|
||||
class Sequence : public Statement {
|
||||
@@ -244,6 +261,23 @@ class Break : public Statement {
|
||||
static auto classof(const Statement* stmt) -> bool {
|
||||
return stmt->kind() == Kind::Break;
|
||||
}
|
||||
|
||||
// The AST node representing the loop this statement breaks out of.
|
||||
// Can only be called after ResolveControlFlow has visited this node.
|
||||
//
|
||||
// Note that this function does not represent an edge in the tree
|
||||
// structure of the AST: the return value is not a child of this node,
|
||||
// but an ancestor.
|
||||
auto loop() const -> const Statement& { return **loop_; }
|
||||
|
||||
// Can only be called once, by ResolveControlFlow.
|
||||
void set_loop(Nonnull<const Statement*> loop) {
|
||||
CHECK(!loop_.has_value());
|
||||
loop_ = loop;
|
||||
}
|
||||
|
||||
private:
|
||||
std::optional<Nonnull<const Statement*>> loop_;
|
||||
};
|
||||
|
||||
class Continue : public Statement {
|
||||
@@ -254,6 +288,23 @@ class Continue : public Statement {
|
||||
static auto classof(const Statement* stmt) -> bool {
|
||||
return stmt->kind() == Kind::Continue;
|
||||
}
|
||||
|
||||
// The AST node representing the loop this statement continues.
|
||||
// Can only be called after ResolveControlFlow has visited this node.
|
||||
//
|
||||
// Note that this function does not represent an edge in the tree
|
||||
// structure of the AST: the return value is not a child of this node,
|
||||
// but an ancestor.
|
||||
auto loop() const -> const Statement& { return **loop_; }
|
||||
|
||||
// Can only be called once, by ResolveControlFlow.
|
||||
void set_loop(Nonnull<const Statement*> loop) {
|
||||
CHECK(!loop_.has_value());
|
||||
loop_ = loop;
|
||||
}
|
||||
|
||||
private:
|
||||
std::optional<Nonnull<const Statement*>> loop_;
|
||||
};
|
||||
|
||||
class Match : public Statement {
|
||||
|
||||
Reference in New Issue
Block a user