[DotGNU]Strategy for dealing with C++ virtual functions in a managed binding.
James Michael DuPont
mdupont777 at yahoo.com
Tue Dec 3 07:15:30 GMT 2002
--- Adam Treat <manyoso at yahoo.com> wrote:
> On Tuesday 03 December 2002 01:24 am, James Michael DuPont wrote:
> > Here is the code for getting it from the dbxout.c
> > you will notice that this information is stored in the tree
> structre.
> >
> --------------------------------------------------------------------
> > /* This is the "mangled" name of the method.
> > It encodes the argument types. */
> > const char *debug_name;
> >
> > /* Skip methods that aren't FUNCTION_DECLs. (In C++, these
> > include TEMPLATE_DECLs.) The debugger doesn't know what
> > to do with such entities anyhow. */
> > if (TREE_CODE (fndecl) != FUNCTION_DECL)
> > continue;
> >
> > debug_name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (fndecl));
> >
> --------------------------------------------------------------------
>
> Is this from libiberty or something?
no, it is in the gcc itself, basically in abstract syntax trees created
out of the source code.
> > do you have a spec of the output, I could output this directly from
> the
> > gcc-introscptor
>
> Sure ... here is some output from qwidget.xml
>
> ************ snip **************
> <Constructor Name="QWidget" Access="Public" Id="0">
> <Parameter Name="parent" Type="QWidget" Mode="Pointer"
> Default="0" />
> <Parameter Name="name" Type="char" Const="True"
> Mode="Pointer"
> Default="0" />
> <Parameter Name="f" Type="WFlags" Default="0" />
> </Constructor>
> ******** snip **********
ok, this is very similar to the type of data we get from the gcc.
Later on you can use the introspector to directly get this out of the
gcc.
> We are using PInvoke for the binding so internal calls really aren't
> applicable.
Well, there has to be a way to do something similar with pinvoke,
i just have not read up on this yet.
> You can find our DTD for the XML representation in our cvs under
> /qtsharp/doc/dtd/api.dtd . I can attach this to another private
> email if you
> want ... You can look at qt-copy/include/qwidget.h for an example of
> the
> header file and some virtual functions ...
ok, I will cvs that code out. I guess this is the kde cvs?
maybe you can just Make CFLAGS=-save-temps and send me an .i file that
has everything fully expanded. that way i can just work with that.
> > You want to overwrite the c++ vtable so that you can call C# from
> c++,
> > via the method table?
>
> Yes, this is precisely what we need to do. We need to be able to
> override C++
> virtual functions in C# and then have the C++ native functions call
> the C#
> overrides where appropriate. This is the only way to have full
> functionality
> in the binding.
Ok, I dont think this is *directly* possible in a complier independant
way, not without modifing the code or generating a set of classes.
You can generate a set of derived classes for each type of class, and
in the body of the class, call the pinvoke. The gcc compiler could be
extended to allow for intercepting and re-routing of the method calls,
the function, make_thunk could be extended for that purpose.
For compilier independence, You will need to generate a set of classes
that talk to delegates, derived from the orignal classes.
But QT uses the signal/slot system anyway, is that not enough to be
able to
>
> > ok, this will require setting the function pointer of an existing
> > method. Or involve a second interface.
> >
> > I would say that i need an exact example,
> > assuming you could modify the make_thunk function from the gcc,
> > then you call the c# code.
> > the makethunk is used on the client side
> > fn = make_thunk (fn, delta, vcall_index);
> > this is called in the function cp/class.c/build_vtbl_initializer
> > int the gcc. There you could set the function pointers.
>
> Hmm, an exact example would be to override the layout virtual methods
> in
> QWidget such as:
Ok, the point is, to call a C# method by pinvoke would mean to
generate a virtual table for the user of a class (the caller) that
allows for overwriting the functions.
=====
James Michael DuPont
http://introspector.sourceforge.net/
__________________________________________________
Do you Yahoo!?
Yahoo! Mail Plus - Powerful. Affordable. Sign up now.
http://mailplus.yahoo.com
>> Visit http://mail.kde.org/mailman/listinfo/kde-devel#unsub to unsubscribe <<
More information about the kde-core-devel
mailing list