CShim Writer¶
The CShim writer (headerkit.writers.cshim) generates pure C-ABI wrapper functions (extern "C") around C++ classes, constructors, destructors, methods, and namespaced free functions using opaque pointer handles.
Features¶
- Opaque Handles: Wraps C++ class instances as
typedef void* ClassNameHandle;. - Constructors & Destructors: Emits
ClassName_create(...)andClassName_destroy(handle). - Methods: Emits
ClassName_methodName(handle, ...)forwarding calls to the underlying C++ instance. - Operators: Maps C++ overloaded operators (e.g.
operator[],operator+=,operator==) to named C shim functions (e.g.ClassName_subscript,ClassName_op_add_assign,ClassName_op_equal). - Namespaces: Flattens nested C++ namespaces into prefix conventions (
ns1_ns2_func()).
Usage¶
API Reference¶
CShimWriter
¶
Bases: BaseWriter
Writer that generates C-ABI wrapper shims around C++ headers.
Emits two parts (or combined header/source):
- extern "C" C API declarations
- C++ implementation wrapping member calls, constructors, and destructors.
write_cshim
¶
Convenience function to generate C-ABI shims from a Header IR.