mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-05 22:02:55 +01:00
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:
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user