TEAM-ADA Archives

Team Ada: Ada Programming Language Advocacy

TEAM-ADA@LISTSERV.ACM.ORG

Options: Use Forum View

Use Monospaced Font
Show Text Part by Default
Show All Mail Headers

Message: [<< First] [< Prev] [Next >] [Last >>]
Topic: [<< First] [< Prev] [Next >] [Last >>]
Author: [<< First] [< Prev] [Next >] [Last >>]

Print Reply
Subject:
From:
Tucker Taft <[log in to unmask]>
Reply To:
Date:
Tue, 25 May 1999 14:21:04 -0400
Content-Type:
text/plain
Parts/Attachments:
text/plain (101 lines)
Christoph & Ursula Grein wrote:
> ...
> Now I really do not see why I should not be able to add the renaming declaration
> (at the end of the code sample) (and Gnat 3.11p compiles and executes it without
> complaint).
> So I still do not see any difference between overriding visibly respectively in
> the private part (for tagged types).

There is very little difference.  One minor difference is that
you cannot change the parameter names or the default expressions for
callers from outside the package if you override in the private part.
But if you didn't intend to do that anyway, then there is no
difference, and you can override in either place with the same effect.
>
> (For untagged types, the difference is clear; perhaps not so obvious at first.)
>
> I would be very obliged if you please could further explain, perhaps by adding
> the relevant chapter and verse.

I don't know what you want to know.  The answer is that there
is very little difference for tagged types.  One rule specifically
designed to minimize the difference is given in RM95 8.5.4(8), which
says that a call on a renaming of a dispatching operation works the
same way whether the overriding happens in the visible part or the
private part, so long as the renaming happens "after" the overriding.
Renaming "before" the overriding is a way of "capturing" the unoverridden
(inherited) subprogram, perhaps for use in implementing the overriding one.

>
> >
> > Consider the following example:
> > ----------------
> > package Class is
> >
> >   type Root is tagged null record;
> >
> >   procedure Operation (R : in Root);
> >
> >   type Derived is new Root with null record;
> >
> >   -- procedure Operation (D : in Derived);  -- overrides
> >
> > private
> >
> >   procedure Operation (D : in Derived);  -- overrides
> >
> > end Class;
> > -----------------
> > with Ada.Text_Io;
> > use  Ada.Text_Io;
> >
> > package body Class is
> >
> >   procedure Operation (R : in Root) is
> >   begin
> >     Put_Line ("Root");
> >   end Operation;
> >
> >   procedure Operation (D : in Derived) is
> >   begin
> >     Put_Line ("Derived");
> >   end Operation;
> >
> > end Class;
> > -----------------
> > with Class;
> > use  Class;
> >
> > procedure Tester is
> >
> >   R : Root;
> >   D : Derived;
>
>   procedure Renamed_Operation (XYZ: in Derived) renames Class.Operation;
>   -- Operation is visible, because it's callable. So why should I not be
>   -- able to rename it?

You should be able to rename it.  Is there a compiler that refuses to allow
this renaming?  If so, then it has a bug.

> > begin
> >
> >   -- no dispatching calls
> >   Operation (R);  -- visible
> >   Operation (D);  -- derived, invisibly overridden
>
>     Renamed_Operation (D);
> >
> > end Tester;
>
> Christoph Grein
> Member of Ada Germany
>
> http://home.T-Online.de/home/Christ-Usch.Grein
> [log in to unmask]

--
-Tucker Taft   [log in to unmask]   http://www.averstar.com/~stt/
Technical Director, Distributed IT Solutions  (www.averstar.com/tools)
AverStar (formerly Intermetrics, Inc.)   Burlington, MA  USA

ATOM RSS1 RSS2