mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-05 22:02:55 +01:00
Initial support for C++ function pointers (#7788)
This change introduces a new inst kind `CppFunctionPointerType`, which represents an imported C++ function pointer that can be invoked from Carbon (support for forming such a pointer from a Carbon function is in a follow-up PR). This is implemented by treating the operation of invoking a function pointer in C++ as if it were a call to an `__invoke` method on the function pointer type, and extending the existing function-import logic to support importing this fictitious method. --------- Co-authored-by: Nicholas Bishop <nbishop@nbishop.net>
This commit is contained in:
co-authored by
Nicholas Bishop
parent
f65572a1e6
commit
12e1afeb15
@@ -2888,10 +2888,24 @@ static auto TryEvalCall(EvalContext& outer_eval_context, SemIR::LocId loc_id,
|
||||
static auto GetReturnStorageParamIndexRange(EvalContext& eval_context,
|
||||
const SemIR::Callee& callee)
|
||||
-> std::pair<int, int> {
|
||||
if (const auto* callee_function =
|
||||
std::get_if<SemIR::CalleeFunction>(&callee)) {
|
||||
const auto& function =
|
||||
eval_context.functions().Get(callee_function->function_id);
|
||||
auto function_id = SemIR::FunctionId::None;
|
||||
CARBON_KIND_SWITCH(callee) {
|
||||
case CARBON_KIND(SemIR::CalleeFunction callee_function): {
|
||||
function_id = callee_function.function_id;
|
||||
break;
|
||||
}
|
||||
case CARBON_KIND(SemIR::CalleeCppFunctionPointer callee_function_ptr): {
|
||||
function_id = eval_context.context()
|
||||
.clang_function_pointer_types()
|
||||
.Get(callee_function_ptr.function_type_id)
|
||||
.function_id;
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
if (function_id.has_value()) {
|
||||
const auto& function = eval_context.functions().Get(function_id);
|
||||
return {function.call_param_ranges.return_begin().index,
|
||||
function.call_param_ranges.return_end().index};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user