Support for returned var and return var. (#3374)

Implement toolchain support for `returned var` and `return var`.

- Modeled `returned` in the parse tree as a `ReturnedSpecifier`
appearing after the `VariableIntroducer`.
- Modeled `return var` in the parse tree as a `ReturnVarSpecifier`
appearing after the `ReturnStatementStart`.
- Factored out the implementation of `return` statement and `returned
var` handling in check into a new `return.{h,cpp}`. The parse nodes
themselves are still handled in `handle_*.cpp`. This allows easy code
reuse between `return` and `returned var`.
This commit is contained in:
Richard Smith
2023-11-10 19:52:30 +00:00
committed by GitHub
parent 5020fdb3be
commit afd6d85610
34 changed files with 1077 additions and 146 deletions
+2 -1
View File
@@ -100,6 +100,7 @@ static auto BuildFunctionDecl(Context& context, bool is_definition)
name_context.state == DeclNameStack::NameContext::State::Unresolved
? name_context.unresolved_name_id
: SemIR::NameId::Invalid,
.declaration_id = function_decl_id,
.implicit_param_refs_id = implicit_param_refs_id,
.param_refs_id = param_refs_id,
.return_type_id = return_type_id,
@@ -182,7 +183,7 @@ auto HandleFunctionDefinitionStart(Context& context, Parse::Node parse_node)
}
// Create the function scope and the entry block.
context.return_scope_stack().push_back(decl_id);
context.return_scope_stack().push_back({.decl_id = decl_id});
context.inst_block_stack().Push();
context.PushScope(decl_id);
context.AddCurrentCodeBlockToFunction();