mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-04 10:11:06 +01:00
Be more explicit about AST types (#921)
This was born out of wanting FunctionDeclaration to explicitly have a Block for a body, and became a bit more of specifying types around. Note this forces exec_program to generate a Block for print()'s body, which is probably more correct as now we can expect a standard FunctionDeclaration AST structure, even for the built-ins. There is a syntactic change here: a continuation's body is now a Block, not just a Statement. I've added an example disallowed test case. I think this is more reasonable syntax. Other than that, note that optional_else now generates a valid Block. This has me thinking about whether we can eliminate Sequence, but that seemed well out of scope for this.
This commit is contained in:
@@ -90,7 +90,7 @@ class FunctionDeclaration : public Declaration {
|
||||
Nonnull<TuplePattern*> param_pattern,
|
||||
Nonnull<Pattern*> return_type,
|
||||
bool is_omitted_return_type,
|
||||
std::optional<Nonnull<Statement*>> body)
|
||||
std::optional<Nonnull<Block*>> body)
|
||||
: Declaration(Kind::FunctionDeclaration, source_loc),
|
||||
name_(std::move(name)),
|
||||
deduced_parameters_(std::move(deduced_params)),
|
||||
@@ -116,10 +116,8 @@ class FunctionDeclaration : public Declaration {
|
||||
auto is_omitted_return_type() const -> bool {
|
||||
return is_omitted_return_type_;
|
||||
}
|
||||
auto body() const -> std::optional<Nonnull<const Statement*>> {
|
||||
return body_;
|
||||
}
|
||||
auto body() -> std::optional<Nonnull<Statement*>> { return body_; }
|
||||
auto body() const -> std::optional<Nonnull<const Block*>> { return body_; }
|
||||
auto body() -> std::optional<Nonnull<Block*>> { return body_; }
|
||||
|
||||
private:
|
||||
std::string name_;
|
||||
@@ -127,7 +125,7 @@ class FunctionDeclaration : public Declaration {
|
||||
Nonnull<TuplePattern*> param_pattern_;
|
||||
Nonnull<Pattern*> return_type_;
|
||||
bool is_omitted_return_type_;
|
||||
std::optional<Nonnull<Statement*>> body_;
|
||||
std::optional<Nonnull<Block*>> body_;
|
||||
};
|
||||
|
||||
class ClassDeclaration : public Declaration {
|
||||
|
||||
Reference in New Issue
Block a user