comp.lang.ada
 help / color / mirror / Atom feed
From: Samuel Mize <smize@imagin.net>
Subject: Re: Ada OO Mechanism
Date: 1999/05/27
Date: 1999-05-27T00:00:00+00:00	[thread overview]
Message-ID: <7ik1e5$8bc@news1.newsguy.com> (raw)
In-Reply-To: t7675gswiv.fsf@calumny.jyacc.com

Hyman Rosen <hymie@prolifics.com> wrote:
> Samuel Mize <smize@imagin.net> writes:
>>   -- This dispatches on both parameters, so they have to match
>>   -- at run-time
>>   procedure Operation_4 (A: A_Type; B: B_Type);
> 
> (Do you mean B: A_Type ?)
> 
> Thanks, this is the kind of example I meant! This is something that
> C++ can't do by itself. When you say "match at runtime" do you mean
> that their dynamic types must be the same? Does the code raise an
> exception if they happen not to match?

Yep.

I said elsewhere I'd bone up on this and explain it.  Here goes.  I
haven't been actually using this for a couple of years (dang it), so
everybody else backstop me and catch any errors.

In a call on a potentially dispatching function or procedure, all the
tags of the controlling parameter values have to match, or you get a
constraint error at run-time.  And, they must be all statically tagged
or all dynamically tagged.

A value can be statically tagged, dynamically tagged, or tag
indeterminate.

- It's statically tagged if it is of a specific tagged type.

- It's dynamically tagged if it's of a class-wide type.

- It's tag indeterminate ONLY if it's a function call, AND its
  parameters (if any) don't determine its tag.  (Such a function call
  must be able to determine the tag to use for its result from the
  context of the call.)

Note that the tag of a function call depends on the tags of its
parameters.  It's statically or dynamically tagged, whichever the
parameters are.  If there are no statically or dynamically tagged
parameters, the call is tag indeterminate, and you have to be able to
tell from the context of the call what tag to use.

Here is a little example code.  Given the package:

    package T_Types is
      type T1 is tagged null record;

      procedure Op1 (P1: T1; P2: T1);

      type T1_Class_Access is access T1'Class;

      type T1_1 is new T1 with null record;
      -- implicit op1 declared here

      type T2 is tagged null record;

      procedure Op1 (P1: T1'class; P2: T2);

    end t_types;

And the following data items:

    V1: T1;
    V1_1: T1_1;
    V1_Class_Access: T1_Class_Access := new T1;

    V2: T2;

Then we can have the following calls, some of which are illegal
at compile time and one of which raises Constraint_Error at
run time:

    ---------
    -- DISPATCHING TO SUBTYPES OF T1
    ---------

    -- legal -- static call to T1.op1
    op1 (V1, V1);

    -- not legal, tags must match
    --op1 (V1, V1_1);

    -- not legal, must both be either static or dynamic tagged
    --op1 (V1, V1_Class_Access.all);

    -- legal -- dispatching call to op1 in some descendant of T1
    op1 (V1_Class_Access.all, V1_Class_Access.all);

    -- legal -- both are now dynamically tagged
    op1 (T1'Class (V1), V1_Class_Access.all);

    -- legal at compile time, but fails at run time because the
    -- tags don't match
    --op1 (T1'Class (V1_1), V1_Class_Access.all);

    ---------
    -- DISPATCHING TO SUBTYPES OF T2
    ---------

    -- all legal
    op1 (V1, V2);
    op1 (V1_1, V2);
    op1 (V1_Class_Access.all, V2);

I hope you find this of some interest.

Best,
Sam Mize

-- 
Samuel Mize -- smize@imagin.net (home email) -- Team Ada
Fight Spam: see http://www.cauce.org/ \\\ Smert Spamonam




  parent reply	other threads:[~1999-05-27  0:00 UTC|newest]

Thread overview: 116+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1999-05-20  0:00 Ada OO Mechanism Shawn M. Root
1999-05-20  0:00 ` Samuel Mize
1999-05-20  0:00   ` David Botton
1999-05-20  0:00     ` Samuel Mize
1999-05-20  0:00       ` David Botton
1999-05-24  0:00   ` Hyman Rosen
1999-05-24  0:00     ` Robert Dewar
1999-05-24  0:00       ` Hyman Rosen
1999-05-24  0:00         ` Mike
1999-05-25  0:00           ` Robert Dewar
1999-05-24  0:00         ` David Starner
1999-05-24  0:00           ` bob
1999-05-24  0:00             ` David Starner
1999-05-25  0:00               ` Ole-Hjalmar Kristensen
1999-05-25  0:00                 ` Mark A Biggar
1999-05-25  0:00                   ` Hyman Rosen
1999-05-25  0:00                     ` Richard D Riehle
1999-05-25  0:00                       ` David Botton
1999-05-26  0:00                         ` Tom Moran
1999-05-27  0:00                       ` Aidan Skinner
1999-05-25  0:00                     ` Samuel Mize
1999-05-25  0:00                       ` Hyman Rosen
1999-05-25  0:00                         ` Richard D Riehle
1999-05-25  0:00                           ` Hyman Rosen
1999-05-26  0:00                             ` Ray Blaak
1999-05-26  0:00                               ` Richard D Riehle
1999-05-26  0:00                                 ` Hyman Rosen
1999-05-27  0:00                                   ` Richard D Riehle
1999-06-05  0:00                                     ` Matthew Heaney
1999-06-07  0:00                                       ` Hyman Rosen
1999-05-28  0:00                                   ` Laurent Guerby
1999-06-05  0:00                                   ` Matthew Heaney
1999-06-07  0:00                                     ` Hyman Rosen
1999-06-08  0:00                                       ` Matthew Heaney
1999-06-08  0:00                                         ` Hyman Rosen
1999-06-08  0:00                                           ` Samuel Mize
1999-06-08  0:00                                             ` Hyman Rosen
1999-06-08  0:00                                       ` Robert Dewar
1999-06-08  0:00                                         ` Markus Kuhn
1999-06-08  0:00                                           ` Stanley R. Allen
1999-06-08  0:00                                         ` Stanley R. Allen
1999-05-26  0:00                               ` Hyman Rosen
     [not found]                           ` <t7zp2sr6yf.fsf@calumny.jyacc.c <t7emjmmx8w.fsf@calumny.jyacc.com>
1999-06-08  0:00                             ` Larry Kilgallen
1999-06-08  0:00                               ` Hyman Rosen
1999-06-08  0:00                                 ` Tucker Taft
1999-06-08  0:00                                   ` Brian Rogoff
     [not found]                                   ` < <375E92CB.27850620@averstar.com>
1999-06-09  0:00                                     ` Brian Rogoff
1999-06-14  0:00                                       ` Robert A Duff
1999-06-09  0:00                                   ` Robert Dewar
1999-06-09  0:00                                   ` Tucker Taft
1999-06-09  0:00                                 ` Matthew Heaney
1999-06-09  0:00                                 ` Samuel Mize
     [not found]                           ` <t7zp2sr6yf.fsf@calumny.jyacc.c <t7r9nmz8ou.fsf@calumny.jyacc.com>
1999-06-08  0:00                             ` Larry Kilgallen
1999-06-08  0:00                               ` Hyman Rosen
1999-06-14  0:00                                 ` Robert A Duff
     [not found]                           ` <t7zp2sr6yf.fsf@calumny.jyacc.c <375d9a3d.e1cccc63@averstar.com>
1999-06-09  0:00                             ` Larry Kilgallen
1999-06-09  0:00                               ` Tucker Taft
1999-05-25  0:00                         ` Brian Rogoff
1999-05-25  0:00                           ` Jim
1999-05-26  0:00                           ` Robert Dewar
1999-05-26  0:00                             ` Brian Rogoff
1999-05-25  0:00                         ` Samuel Mize
1999-05-25  0:00                           ` Chris
1999-05-25  0:00                             ` David Botton
1999-05-27  0:00                               ` Aidan Skinner
1999-05-27  0:00                                 ` Gautier
1999-05-27  0:00                             ` Samuel Mize
1999-05-27  0:00                         ` Samuel Mize
1999-05-27  0:00                           ` Jon S Anthony
1999-05-27  0:00                         ` Samuel Mize [this message]
1999-05-27  0:00                           ` Hyman Rosen
1999-05-28  0:00                             ` Laurent Guerby
1999-05-28  0:00                               ` Richard D Riehle
1999-05-28  0:00                                 ` Tom Moran
1999-05-28  0:00                             ` Samuel Mize
1999-05-28  0:00                     ` Robert I. Eachus
1999-05-28  0:00                       ` Brian Rogoff
1999-05-29  0:00                       ` Ehud Lamm
1999-05-30  0:00                         ` chris
1999-05-30  0:00                           ` Harry George
1999-05-30  0:00                             ` Vladimir Olensky
1999-05-31  0:00                               ` Robert Dewar
1999-05-30  0:00                           ` Robert Dewar
1999-05-31  0:00                           ` Vladimir Olensky
1999-06-03  0:00                             ` Dale Stanbrough
1999-06-02  0:00                               ` mike
1999-06-03  0:00                                 ` Robert Dewar
1999-06-06  0:00                                   ` David Botton
1999-06-07  0:00                                     ` Robert Dewar
1999-06-01  0:00                           ` Richard D Riehle
1999-06-03  0:00                         ` Matthew Heaney
1999-06-03  0:00                     ` Matthew Heaney
1999-05-25  0:00                 ` Florian Weimer
1999-05-25  0:00     ` Samuel Mize
1999-05-25  0:00       ` Hyman Rosen
1999-05-25  0:00         ` David Starner
1999-05-26  0:00         ` Ole-Hjalmar Kristensen
1999-05-26  0:00         ` Laurent Guerby
1999-05-26  0:00           ` Hyman Rosen
1999-05-28  0:00             ` Laurent Guerby
1999-06-01  0:00               ` Hyman Rosen
1999-06-03  0:00                 ` Fraser Wilson
1999-06-03  0:00     ` Matthew Heaney
1999-06-03  0:00       ` Hyman Rosen
1999-05-21  0:00 ` Dale Stanbrough
1999-05-20  0:00   ` bob
1999-05-21  0:00     ` Dale Stanbrough
1999-05-21  0:00   ` Richard D Riehle
1999-05-21  0:00     ` Shawn M. Root
1999-05-21  0:00       ` Richard D Riehle
1999-05-25  0:00         ` Shawn M. Root
1999-05-21  0:00     ` Marin David Condic
1999-05-21  0:00       ` Steve
1999-05-21  0:00       ` Dan Nagle
1999-05-24  0:00         ` Marin David Condic
1999-05-25  0:00   ` Don Overheu
replies disabled

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