mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-11-15 20:58:15 +00: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:
1 parent
dea277d8e1
commit
bbd4940e6d
11 files changed
+143
-122
No files matched your search
@@ -22,10 +22,15 @@ static void AddIntrinsics(Nonnull<Arena*> arena,
|
||||
source_loc, "format_str",
|
||||
arena->New<ExpressionPattern>(
|
||||
arena->New<StringTypeLiteral>(source_loc)))};
|
||||
auto print_return = arena->New<Return>(
|
||||
auto print_return = arena->New<Block>(
|
||||
source_loc,
|
||||
arena->New<IntrinsicExpression>(IntrinsicExpression::Intrinsic::Print),
|
||||
false);
|
||||
arena->New<Sequence>(
|
||||
source_loc,
|
||||
arena->New<Return>(source_loc,
|
||||
arena->New<IntrinsicExpression>(
|
||||
IntrinsicExpression::Intrinsic::Print),
|
||||
false),
|
||||
std::nullopt));
|
||||
auto print = arena->New<FunctionDeclaration>(
|
||||
source_loc, "Print", std::vector<GenericBinding>(),
|
||||
arena->New<TuplePattern>(source_loc, print_params),
|
||||
|
||||
Reference in new issue
Block a user