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
@@ -64,6 +64,12 @@ auto GetCallee(const File& sem_ir, InstId callee_id,
|
||||
"Invalid callee id in a specific context");
|
||||
}
|
||||
|
||||
if (auto fn_ptr_type = sem_ir.types().TryGetAs<CppFunctionPointerType>(
|
||||
sem_ir.insts().Get(callee_id).type_id())) {
|
||||
return CalleeCppFunctionPointer{.function_type_id =
|
||||
fn_ptr_type->clang_type_id};
|
||||
}
|
||||
|
||||
auto val_id = sem_ir.constant_values().GetConstantInstId(callee_id);
|
||||
if (!val_id.has_value()) {
|
||||
return CalleeNonFunction();
|
||||
|
||||
Reference in New Issue
Block a user