mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-06 09:14:42 +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
@@ -9,6 +9,7 @@
|
||||
#include <utility>
|
||||
#include <variant>
|
||||
|
||||
#include "clang/AST/Type.h"
|
||||
#include "common/concepts.h"
|
||||
#include "common/raw_string_ostream.h"
|
||||
#include "toolchain/base/kind_switch.h"
|
||||
@@ -654,6 +655,14 @@ class Stringifier {
|
||||
">");
|
||||
}
|
||||
|
||||
auto StringifyInst(InstId /*inst_id*/, CppFunctionPointerType inst) -> void {
|
||||
clang::QualType clang_type(sem_ir_->clang_function_pointer_types()
|
||||
.Get(inst.clang_type_id)
|
||||
.clang_type,
|
||||
0);
|
||||
*out_ << "<C++ type " << clang_type.getAsString() << ">";
|
||||
}
|
||||
|
||||
auto StringifyInst(InstId /*inst_id*/, FunctionType inst) -> void {
|
||||
const auto& fn = sem_ir_->functions().Get(inst.function_id);
|
||||
*out_ << "<type of ";
|
||||
|
||||
Reference in New Issue
Block a user