You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
!WIP - this is just a scratchpad, not fully thought through yet.
This would require:
Tagging ClassDecls as being a base class after parsing, and tagging each non-pure, non-final method to be overriden
During writing, given a C++ base class Base, generating:
A C++ class, BaseEx that inherites from Base and provides overrides for each of the tagged methods, as well as any pure virtual ones. Each constructor of BaseEx should be modified to take a "subclass" pointer as its first argument, which will be stashed as a field.
A matching C ABI function for each overriden method in in BaseEx, taking a void* subclass as its first argument
C translations (using the normal mechanism) of each constructor of BaseEx
The implementation of BaseEx just forwards to the matching C versions of its methods
... then on the Rust side the void sublcass* is used to take a Box<Box<dyn BaseEx>>
// original c++classBase {
virtualvoiddo_thing(int a);
};
// generated c++externintfwd_BaseEx_do_thing(void* _subclass, int a); // defined in RustclassBaseEx {
void* _subclass;
public:BaseEx(void* subclass) : _subclass(subclass){}
voiddo_thing(int a) override { fwd_BaseEx_do_thing(_subclass, a); }
};
voidBaseEx_ctor(void* subclass, BaseEx** result) {
*result = newBaseEx(subclass);
}
#[no_mangle]extern"C"fnfwd_BaseEx_do_thing(subclass:*mutc_void,a:c_int){let base_ex = std::mem::transmute::<*mutc_void,Box<Box<dynBaseEx>>(subclass);
base_ex.do_thing(a);}traitBaseEx{fnget_subclass(&self) -> &Box<Box<dynBaseEx>>;}// todo: ownership on the Rust side for trait impls?
The text was updated successfully, but these errors were encountered:
!WIP - this is just a scratchpad, not fully thought through yet.
This would require:
Base
, generating:BaseEx
that inherites fromBase
and provides overrides for each of the tagged methods, as well as any pure virtual ones. Each constructor ofBaseEx
should be modified to take a "subclass" pointer as its first argument, which will be stashed as a field.BaseEx
, taking avoid* subclass
as its first argumentBaseEx
BaseEx
just forwards to the matching C versions of its methods... then on the Rust side the
void sublcass*
is used to take aBox<Box<dyn BaseEx>>
The text was updated successfully, but these errors were encountered: