comp.lang.ada
 help / color / mirror / Atom feed
* GNAT/Interfacing C++/Dispatching
@ 2001-11-11 18:48 Volkert
  2001-11-13 19:21 ` Stephen Leake
  0 siblings, 1 reply; 4+ messages in thread
From: Volkert @ 2001-11-11 18:48 UTC (permalink / raw)


Hello c.l.a.

Is this true, that dispatching works not across 
languages boundaries when interfacing Ada 95 with C++ 
(using C++ Interface mechanisms of GNAT 3.13p.)?


Example:

C++

class A {

  void f() {
     g();   
  };  

  virtual void g() {
     // do something
  }
}


Ada:

  package A_Type is

    -- corresponds to C++ Class A
    type A is tagged 
      record 
        ...
        Vptr : Interfacing.CPP.Vtable_Ptr;
     end record;

    pragma CPP_Class ...
    pragma CPP_Vtable ...

    procedure f (Self : in A'Class);
    pragma Import(CPP, f, ...);

    procedure g (Self: in A);
    pragma CPP_Virtual (g);
    pragma Import(CPP, ...) 
 
  end A_Type;


  -- extends A
  package B_Type is

    type B is new A with ...

    procedure g (Self : in B); -- redefines g of A.

    ...
    
  end B_Type;

  

  with ...
  procedure Main is
     Object : aliased B;
  begin
                -- ERROR (?)
     f(Object); -- calls c++ method g, 
                -- not the primitive g of the tagged type B.
  end; 


Any hints?


With regards,
Volkert Barr



^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: GNAT/Interfacing C++/Dispatching
  2001-11-11 18:48 GNAT/Interfacing C++/Dispatching Volkert
@ 2001-11-13 19:21 ` Stephen Leake
  2001-11-13 22:09   ` Jerry van Dijk
  2001-11-14  7:47   ` Volkert Barr
  0 siblings, 2 replies; 4+ messages in thread
From: Stephen Leake @ 2001-11-13 19:21 UTC (permalink / raw)


Volkert.Barr@freenet.de (Volkert) writes:

> Hello c.l.a.
> 
> Is this true, that dispatching works not across 
> languages boundaries when interfacing Ada 95 with C++ 
> (using C++ Interface mechanisms of GNAT 3.13p.)?

I have not done it, and I did not read your code in detail, but
GNAT/g++ is supposed to allow full inter-operation between Ada tagged
types and C++ classes. So keep trying!

> <snip>

-- 
-- Stephe



^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: GNAT/Interfacing C++/Dispatching
  2001-11-13 19:21 ` Stephen Leake
@ 2001-11-13 22:09   ` Jerry van Dijk
  2001-11-14  7:47   ` Volkert Barr
  1 sibling, 0 replies; 4+ messages in thread
From: Jerry van Dijk @ 2001-11-13 22:09 UTC (permalink / raw)


Stephen Leake <stephen.a.leake.1@gsfc.nasa.gov> writes:

> Volkert.Barr@freenet.de (Volkert) writes:
> 
> > Hello c.l.a.
> > 
> > Is this true, that dispatching works not across 
> > languages boundaries when interfacing Ada 95 with C++ 
> > (using C++ Interface mechanisms of GNAT 3.13p.)?
> 
> I have not done it, and I did not read your code in detail, but
> GNAT/g++ is supposed to allow full inter-operation between Ada tagged
> types and C++ classes. So keep trying!

One idea is to have another look at the Cpp_Virtual pragma.

-- 
--  Jerry van Dijk   | email: jvandyk@attglobal.net
--  Leiden, Holland  | web:   home.trouwweb.nl/Jerry



^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: GNAT/Interfacing C++/Dispatching
  2001-11-13 19:21 ` Stephen Leake
  2001-11-13 22:09   ` Jerry van Dijk
@ 2001-11-14  7:47   ` Volkert Barr
  1 sibling, 0 replies; 4+ messages in thread
From: Volkert Barr @ 2001-11-14  7:47 UTC (permalink / raw)


Stephen Leake wrote:
> 
> Volkert.Barr@freenet.de (Volkert) writes:
> 
> > Hello c.l.a.
> >
> > Is this true, that dispatching works not across
> > languages boundaries when interfacing Ada 95 with C++
> > (using C++ Interface mechanisms of GNAT 3.13p.)?
> 
> I have not done it, and I did not read your code in detail, but
> GNAT/g++ is supposed to allow full inter-operation between Ada tagged
> types and C++ classes. So keep trying!
Yes! Simple interfacing to C++ Classes seems to work well. But when is
comes to polymophism i run into trouble. Polymophism on Ada side works.
But,
dispatching calls starting at the c++ side do not propagate into the Ada
work. 
I think, a C++ class does not know the dispatching table, which i have
to add to an 
Ada tagged type. The c++ work does not know about overriden features
from
the Ada side. 

Expample:

class A {

  void f() {
     this->g(); 
  };  

  virtual void g() {
     // do something
  }
}

 package A_Type is

    -- corresponds to C++ Class A
    type A is tagged 
      record 
        ...
        Vptr : Interfacing.CPP.Vtable_Ptr;
     end record;

    pragma CPP_Class ...
    pragma CPP_Vtable ...

    procedure f (Self : in A'Class);
    pragma Import(CPP, f, ...);

    procedure g (Self: in A);
    pragma CPP_Virtual (g);
    pragma Import(CPP, ...) 
 
  end A_Type;


  -- extends A
  package B_Type is

    type B is new A with ...

    procedure g (Self : in B); -- redefines g of A.

    ...
    
  end B_Type;

  

If i override g() on the Ada side (with a new tagged type B_Type) and
i call f() on an object of Type T_type in the Ada world, i would expect
the call of the overridden g() method (primitive operation of tagged
type B_Type)


BTW: For all C++ virtual declared mothods i follow the gnat convention
to add a prama CPP_Virtual.

With regards,
Volkert

> > <snip>
> 
> --
> -- Stephe

-- 
- - - - - - - - - - - - - - - - - - - - - - - - - - -
 Volkert Barr      Institut fuer Softwaretechnik und 
                             Theoretische Informatik
             Fachgruppe Softwaretechnik *  TU Berlin

 email: barr@cs.tu-berlin.de
 web: www.cs.tu-berlin.de/~barr
- - - - - - - - - - - - - - - - - - - - - - - - - - -
          * macrosolutions to megaproblems *



^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2001-11-14  7:47 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-11-11 18:48 GNAT/Interfacing C++/Dispatching Volkert
2001-11-13 19:21 ` Stephen Leake
2001-11-13 22:09   ` Jerry van Dijk
2001-11-14  7:47   ` Volkert Barr

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox