mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-05 22:02:55 +01:00
Provide the callee expression to the Call node. (#3291)
Track the callee expression in full, instead of only tracking the callee's FunctionId. This results in the `name_reference` denoting the function actually being used. Lowering now propagates a `llvm::Function*` as the value associated with expressions of type `<function>`. We were not creating `NameReference` node for names produced by member access into a namespace, such as the second name in `Namespace.Function`, which caused lowering of calls to such names to fail. This is now fixed, but the resulting `NameReference` node only refers to the name and the lookup result, not to the `Namespace.` qualifier. We'll need to decide how to fit a third operand into that node (perhaps we can stop storing the `name_id`, since it can be derived from the lookup result) but for now the qualifier is not tracked.
This commit is contained in:
@@ -14,16 +14,16 @@ auto HandleCallExpression(Context& context, Parse::Node parse_node) -> bool {
|
||||
context.ParamOrArgEndNoPop(Parse::NodeKind::CallExpressionStart);
|
||||
|
||||
// TODO: Convert to call expression.
|
||||
auto [call_expr_parse_node, name_id] =
|
||||
auto [call_expr_parse_node, callee_id] =
|
||||
context.node_stack()
|
||||
.PopWithParseNode<Parse::NodeKind::CallExpressionStart>();
|
||||
auto name_node =
|
||||
context.semantics_ir().GetNode(context.FollowNameReferences(name_id));
|
||||
auto function_name = name_node.TryAs<SemIR::FunctionDeclaration>();
|
||||
auto callee_node =
|
||||
context.semantics_ir().GetNode(context.FollowNameReferences(callee_id));
|
||||
auto function_name = callee_node.TryAs<SemIR::FunctionDeclaration>();
|
||||
if (!function_name) {
|
||||
// TODO: Work on error.
|
||||
context.TODO(parse_node, "Not a callable name");
|
||||
context.node_stack().Push(parse_node, name_id);
|
||||
context.node_stack().Push(parse_node, callee_id);
|
||||
context.ParamOrArgPop();
|
||||
return true;
|
||||
}
|
||||
@@ -50,14 +50,14 @@ auto HandleCallExpression(Context& context, Parse::Node parse_node) -> bool {
|
||||
// Convert the arguments to match the parameters.
|
||||
auto refs_id = context.ParamOrArgPop();
|
||||
if (!ConvertCallArgs(context, call_expr_parse_node, refs_id,
|
||||
name_node.parse_node(), callable.param_refs_id,
|
||||
callee_node.parse_node(), callable.param_refs_id,
|
||||
callable.return_slot_id.is_valid())) {
|
||||
context.node_stack().Push(parse_node, SemIR::NodeId::BuiltinError);
|
||||
return true;
|
||||
}
|
||||
|
||||
auto call_node_id = context.AddNode(
|
||||
SemIR::Call(call_expr_parse_node, type_id, refs_id, function_id));
|
||||
SemIR::Call(call_expr_parse_node, type_id, callee_id, refs_id));
|
||||
|
||||
context.node_stack().Push(parse_node, call_node_id);
|
||||
return true;
|
||||
|
||||
Reference in New Issue
Block a user