comp.lang.ada
 help / color / mirror / Atom feed
From: "Pat Rogers" <progers@acm.org>
Subject: statically compatible access discriminants in derivation
Date: 1998/01/13
Date: 1998-01-13T00:00:00+00:00	[thread overview]
Message-ID: <69gucb$l9k$1@uuneo.neosoft.com> (raw)


Given a tagged type with an access discriminant designating a
classwide type, and a child type derived from this parent type, is it
possible to declare an access discriminant in the child type that is
statically compatible with the parent's access discriminant, while having
the child's access discriminant designate a classwide type further down in
the parent's designated derivation class?  (It's easier to see in the code
below.)

I want to constrain an access discriminant to designate only certain kinds
of objects, i.e., those further down in the derivation class, so that I
can take advantage of the additional information provided by the more
specific view.  I could use the inherited access discriminant without
specifying one for the child type, and convert the inherited discriminant
to the intended classwide type, but that seems rather weak in comparison.

For example, consider the following declarations (ignore the names; I've
chosen them for example purposes only):

package device_if is -- device interface
  type object is abstract tagged null record;
end device_if;

with device_if;
package unit_if is -- unit interface
  type object( board : access device_if.object'class ) is abstract tagged
limited null record;
end unit_if;

Given a concrete instance of device_if.object, I want to use that
classwide type in the access discriminant for a concrete instance of
unit_if.object:

with device_if;
package device_instance is
  type object is new device_if.object with
    record
      x : integer;
    end record;
end device_instance;

with device_instance;
with unit_if;
package unit_instance is
  type object( board : access device_instance.object'class ) is
    new unit_if.object( board ) with null record;
  procedure foo( this : in out object );
end unit_instance;

That way I can directly reference X within foo:

package body unit_instance is
  procedure foo( this : in out object ) is
  begin
    this.board.x := 0;
  end foo;
end unit_instance;

As I read the RM, it seems that 3.7(15) requires them to statically match,
and 4.9.1 says that they can not.  Is there a way around this?

As I mentioned, I could just inherit the discriminant 'board' designating
device_if.object'class, and convert to device_instance.object'class, but
would rather have it checked when the objects are declared.

Any ideas?







             reply	other threads:[~1998-01-13  0:00 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1998-01-13  0:00 Pat Rogers [this message]
1998-01-16  0:00 ` statically compatible access discriminants in derivation Nick Roberts
1998-01-17  0:00 ` Tucker Taft
replies disabled

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