mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-05 20:11:12 +01:00
Support for functions with a self parameter. (#3338)
So far, such functions can only be defined; calls are not supported yet.
This commit is contained in:
@@ -22,25 +22,24 @@ auto HandleVariableDeclaration(Context& context, Parse::Node parse_node)
|
||||
}
|
||||
|
||||
// Extract the name binding.
|
||||
SemIR::NodeId bind_name_id =
|
||||
context.node_stack().Pop<Parse::NodeKind::PatternBinding>();
|
||||
auto bind_name = context.nodes().GetAs<SemIR::BindName>(bind_name_id);
|
||||
|
||||
// Form a corresponding name in the current context, and bind the name to the
|
||||
// variable.
|
||||
context.declaration_name_stack().AddNameToLookup(
|
||||
context.declaration_name_stack().MakeUnqualifiedName(bind_name.parse_node,
|
||||
bind_name.name_id),
|
||||
bind_name_id);
|
||||
auto value_id = context.node_stack().Pop<Parse::NodeKind::PatternBinding>();
|
||||
if (auto bind_name = context.nodes().Get(value_id).TryAs<SemIR::BindName>()) {
|
||||
// Form a corresponding name in the current context, and bind the name to
|
||||
// the variable.
|
||||
context.declaration_name_stack().AddNameToLookup(
|
||||
context.declaration_name_stack().MakeUnqualifiedName(
|
||||
bind_name->parse_node, bind_name->name_id),
|
||||
value_id);
|
||||
value_id = bind_name->value_id;
|
||||
}
|
||||
|
||||
// If there was an initializer, assign it to the storage.
|
||||
if (has_init) {
|
||||
auto var_id = bind_name.value_id;
|
||||
if (context.nodes().Get(var_id).Is<SemIR::VarStorage>()) {
|
||||
init_id = Initialize(context, parse_node, var_id, init_id);
|
||||
if (context.nodes().Get(value_id).Is<SemIR::VarStorage>()) {
|
||||
init_id = Initialize(context, parse_node, value_id, init_id);
|
||||
// TODO: Consider using different node kinds for assignment versus
|
||||
// initialization.
|
||||
context.AddNode(SemIR::Assign{parse_node, var_id, init_id});
|
||||
context.AddNode(SemIR::Assign{parse_node, value_id, init_id});
|
||||
} else {
|
||||
// TODO: In a class scope, we should instead save the initializer
|
||||
// somewhere so that we can use it as a default.
|
||||
|
||||
Reference in New Issue
Block a user