comp.lang.ada
 help / color / mirror / Atom feed
* Invoking abstract subprograms in Ada95
@ 2002-04-19 13:15 Mike
  2002-04-19 16:18 ` Stephen Leake
  0 siblings, 1 reply; 8+ messages in thread
From: Mike @ 2002-04-19 13:15 UTC (permalink / raw)


Hi

I have a situation whereby I have an abstract class that describes
some common behaviour but which demands that from within that common
behaviour, some abstract behaviour be completed by its children.

In Ada 95 terms I have a package X that contains abstract type Xt and
describes some abstract behaviour "procedure Z". I also have Ada95
Child Package X.Y that contains a non abstract type Yt that extends
and fully completes Xt.

Within package X I have a classwide procedure (actually an XWindows
Callback) that I want to be invoked by all types of child, *but* there
are some specific tasks that can only be completed by the concrete
child (Y in this case) that fully implements procedure Z.

Gnat Ada95 will not let me do this: "Cannot call abstract subprogram"

* Why can I not invoke procedure Z from with package X?

* Why is the tag of the the object passed to procedure Z not being
examined and the call dispatched accordingly?


Given that the object whose root type is Xt can only exist after the
instantiation of Yt (and therefore the provision of procedure Z by my
reckoning) I find this frustrating.

Please help

Mike



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

* Re: Invoking abstract subprograms in Ada95
  2002-04-19 13:15 Invoking abstract subprograms in Ada95 Mike
@ 2002-04-19 16:18 ` Stephen Leake
  0 siblings, 0 replies; 8+ messages in thread
From: Stephen Leake @ 2002-04-19 16:18 UTC (permalink / raw)


michael.jackson5@virgin.net (Mike) writes:

> In Ada 95 terms I have a package X that contains abstract type Xt and
> describes some abstract behaviour "procedure Z". I also have Ada95
> Child Package X.Y that contains a non abstract type Yt that extends
> and fully completes Xt.
> 
> Within package X I have a classwide procedure (actually an XWindows
> Callback) that I want to be invoked by all types of child, *but* there
> are some specific tasks that can only be completed by the concrete
> child (Y in this case) that fully implements procedure Z.
> 
> Gnat Ada95 will not let me do this: "Cannot call abstract subprogram"
> 
> * Why can I not invoke procedure Z from with package X?

Apparently you have coded a non-dispatching call. Please post the code.


-- 
-- Stephe



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

* Re: Invoking abstract subprograms in Ada95
@ 2002-04-22  4:28 Grein, Christoph
  2002-04-22 13:24 ` Mike
  0 siblings, 1 reply; 8+ messages in thread
From: Grein, Christoph @ 2002-04-22  4:28 UTC (permalink / raw)


The following compiles fine (with Rational Apex):


package Abstract_Class_Wide is

    type T is abstract tagged null record;

    procedure P (X : T) is abstract;

    procedure C (X : T'Class);

end Abstract_Class_Wide;



package body Abstract_Class_Wide is

    procedure C (X : T'Class) is
    begin
	P (X);
    end C;

end Abstract_Class_Wide;



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

* Re: Invoking abstract subprograms in Ada95
  2002-04-22  4:28 Grein, Christoph
@ 2002-04-22 13:24 ` Mike
  2002-04-22 14:24   ` Dmitry A. Kazakov
  0 siblings, 1 reply; 8+ messages in thread
From: Mike @ 2002-04-22 13:24 UTC (permalink / raw)


"Grein, Christoph" <christoph.grein@eurocopter.com> wrote in message news:<mailman.1019449992.18314.comp.lang.ada@ada.eu.org>...
> The following compiles fine (with Rational Apex):
> 
> 
> package Abstract_Class_Wide is
> 
>     type T is abstract tagged null record;
> 
>     procedure P (X : T) is abstract;
> 
>     procedure C (X : T'Class);
> 
> end Abstract_Class_Wide;
> 
> 
> 
> package body Abstract_Class_Wide is
> 
>     procedure C (X : T'Class) is
>     begin
> 	P (X);
>     end C;
> 
> end Abstract_Class_Wide;

Hmm - the only differences I can see here are that my abstract method
also takes a classwide type, and is implemented in a child package.
Here's the distilled problem:

--
package abstract_bit is

type A is abstract tagged null record;

procedure generalOperation( this : in out A'class );
procedure specificOperation( this : in out A'class ) is abstract;

end abstract_bit;

--
package body abstract_bit is

procedure generalOperation( this : in out A'class ) is
begin
    specificOperation( this => this );
end generalOperation;

end abstract_bit;

--
package abstract_bit.concrete_bit is

type C is new A with null record;

procedure specificOperation( this : in out C );

end abstract_bit.concrete_bit;


--
package body abstract_bit.concrete_bit is

procedure specificOperation( this : in out C ) is
begin
    null;
end specificOperation;

end abstract_bit.concrete_bit;

-- main program
with abstract_bit.concrete_bit;

procedure annoying is

thingy : abstract_bit.concrete_bit.C;

begin
    abstract_bit.generalOperation( thingy );
end annoying;


Mike



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

* Re: Invoking abstract subprograms in Ada95
@ 2002-04-22 13:44 Grein, Christoph
  2002-04-23  8:36 ` Mike
  0 siblings, 1 reply; 8+ messages in thread
From: Grein, Christoph @ 2002-04-22 13:44 UTC (permalink / raw)


> "Grein, Christoph" <christoph.grein@eurocopter.com> wrote in message 
news:<mailman.1019449992.18314.comp.lang.ada@ada.eu.org>...
> > The following compiles fine (with Rational Apex):
> > 
> > 
> > package Abstract_Class_Wide is
> > 
> >     type T is abstract tagged null record;
> > 
> >     procedure P (X : T) is abstract;
> > 
> >     procedure C (X : T'Class);
> > 
> > end Abstract_Class_Wide;
> > 
> > 
> > 
> > package body Abstract_Class_Wide is
> > 
> >     procedure C (X : T'Class) is
> >     begin
> > 	P (X);
> >     end C;
> > 
> > end Abstract_Class_Wide;
> 
> Hmm - the only differences I can see here are that my abstract method
> also takes a classwide type, and is implemented in a child package.
> Here's the distilled problem:
> 
> --
> package abstract_bit is
> 
> type A is abstract tagged null record;
> 
> procedure generalOperation( this : in out A'class );
> procedure specificOperation( this : in out A'class ) is abstract;


Class-wide operations cannot be abstract, they also cannot be overrridden.

OK, they can be abstract, this is why your code compiles, but abstractness here 
has a devastating meaning: There can never be such an operation!


> end abstract_bit;
> 
> --
> package body abstract_bit is
> 
> procedure generalOperation( this : in out A'class ) is
> begin
>     specificOperation( this => this );

You said it was abstract, so does not exist! Therefore you cannot call it here.


> end generalOperation;
> 
> end abstract_bit;
> 
> --
> package abstract_bit.concrete_bit is
> 
> type C is new A with null record;
> 
> procedure specificOperation( this : in out C );
> 
> end abstract_bit.concrete_bit;
> 
> 
> --
> package body abstract_bit.concrete_bit is
> 
> procedure specificOperation( this : in out C ) is
> begin
>     null;
> end specificOperation;
> 
> end abstract_bit.concrete_bit;
> 
> -- main program
> with abstract_bit.concrete_bit;
> 
> procedure annoying is
> 
> thingy : abstract_bit.concrete_bit.C;
> 
> begin
>     abstract_bit.generalOperation( thingy );
> end annoying;
> 
> 
> Mike
> _______________________________________________
> comp.lang.ada mailing list
> comp.lang.ada@ada.eu.org
> http://ada.eu.org/mailman/listinfo/comp.lang.ada



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

* Re: Invoking abstract subprograms in Ada95
  2002-04-22 13:24 ` Mike
@ 2002-04-22 14:24   ` Dmitry A. Kazakov
  0 siblings, 0 replies; 8+ messages in thread
From: Dmitry A. Kazakov @ 2002-04-22 14:24 UTC (permalink / raw)


On 22 Apr 2002 06:24:15 -0700, michael.jackson5@virgin.net (Mike)
wrote:

>"Grein, Christoph" <christoph.grein@eurocopter.com> wrote in message news:<mailman.1019449992.18314.comp.lang.ada@ada.eu.org>...
>> The following compiles fine (with Rational Apex):
>> 
>> 
>> package Abstract_Class_Wide is
>> 
>>     type T is abstract tagged null record;
>> 
>>     procedure P (X : T) is abstract;
>> 
>>     procedure C (X : T'Class);
>> 
>> end Abstract_Class_Wide;
>>  
>> package body Abstract_Class_Wide is
>> 
>>     procedure C (X : T'Class) is
>>     begin
>> 	P (X);
>>     end C;
>> 
>> end Abstract_Class_Wide;
>
>Hmm - the only differences I can see here are that my abstract method
>also takes a classwide type,

That's the point. It is not a method [in the meaning "overridable"],
when the formal parameter is class wide. It could be a method only
relatively to some specific formal parameter[s]. Class wide means "one
for all derived types", so it cannot be overridden [at least till an
introduction "class class wide types" (:-))]

> and is implemented in a child package.
>Here's the distilled problem:
>
>--
>package abstract_bit is
>
>type A is abstract tagged null record;
>
>procedure generalOperation( this : in out A'class );
>procedure specificOperation( this : in out A'class ) is abstract;

If your intention is to override specificOperation for derived types,
then it should be exactly as in Christoph's example:

procedure specificOperation( this : in out A ) is abstract;

>end abstract_bit;
>
>--
>package body abstract_bit is
>
>procedure generalOperation( this : in out A'class ) is
>begin
>    specificOperation( this => this );
>end generalOperation;
>
>end abstract_bit;
>
>--
>package abstract_bit.concrete_bit is
>
>type C is new A with null record;
>
>procedure specificOperation( this : in out C );
>
>end abstract_bit.concrete_bit;

---
Regards,
Dmitry Kazakov
www.dmitry-kazakov.de



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

* Re: Invoking abstract subprograms in Ada95
  2002-04-22 13:44 Grein, Christoph
@ 2002-04-23  8:36 ` Mike
  0 siblings, 0 replies; 8+ messages in thread
From: Mike @ 2002-04-23  8:36 UTC (permalink / raw)


"Grein, Christoph" <christoph.grein@eurocopter.com> wrote in message news:<mailman.1019483282.562.comp.lang.ada@ada.eu.org>...

> Class-wide operations cannot be abstract, they also cannot be overrridden.
> 
> OK, they can be abstract, this is why your code compiles, but abstractness here 
> has a devastating meaning: There can never be such an operation!


Aha. Now I see the error of my ways.

> 
> 
> > end abstract_bit;
> > 
> > --
> > package body abstract_bit is
> > 
> > procedure generalOperation( this : in out A'class ) is
> > begin
> >     specificOperation( this => this );
> 
> You said it was abstract, so does not exist! Therefore you cannot call it here.

Weeell in my mind, for generalOperation to be invoked, 'A' must have
been extended sufficiently to be non abstract, and therefore an
implementation of specificOperation *must* exist ;)

Thanks for the help!

Mike



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

* Re: Invoking abstract subprograms in Ada95
@ 2002-04-24  7:32 Grein, Christoph
  0 siblings, 0 replies; 8+ messages in thread
From: Grein, Christoph @ 2002-04-24  7:32 UTC (permalink / raw)


> "Grein, Christoph" <christoph.grein@eurocopter.com> wrote in message 
news:<mailman.1019483282.562.comp.lang.ada@ada.eu.org>...
> 
> > Class-wide operations cannot be abstract, they also cannot be overrridden.
> > 
> > OK, they can be abstract, this is why your code compiles, but abstractness 
here 
> > has a devastating meaning: There can never be such an operation!
> 
> 
> Aha. Now I see the error of my ways.
> 
> > 
> > 
> > > end abstract_bit;
> > > 
> > > --
> > > package body abstract_bit is
> > > 
> > > procedure generalOperation( this : in out A'class ) is
> > > begin
> > >     specificOperation( this => this );
> > 
> > You said it was abstract, so does not exist! Therefore you cannot call it 
here.
> 
> Weeell in my mind, for generalOperation to be invoked, 'A' must have
> been extended sufficiently to be non abstract, and therefore an
> implementation of specificOperation *must* exist ;)

No, it can't exist because you defined it class-wide and abstract. It can only 
exist if you defined it class-specific and abstract. This is what my previous  
code example showed.



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

end of thread, other threads:[~2002-04-24  7:32 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-04-19 13:15 Invoking abstract subprograms in Ada95 Mike
2002-04-19 16:18 ` Stephen Leake
  -- strict thread matches above, loose matches on Subject: below --
2002-04-22  4:28 Grein, Christoph
2002-04-22 13:24 ` Mike
2002-04-22 14:24   ` Dmitry A. Kazakov
2002-04-22 13:44 Grein, Christoph
2002-04-23  8:36 ` Mike
2002-04-24  7:32 Grein, Christoph

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