comp.lang.ada
 help / color / mirror / Atom feed
From: "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de>
Subject: Re: Why does `Unchecked_Deallocation` need the access type?
Date: Tue, 28 Jul 2015 09:40:55 +0200
Date: 2015-07-28T09:40:55+02:00	[thread overview]
Message-ID: <170ajsv4tazu3.mgrs0or8en9w$.dlg@40tude.net> (raw)
In-Reply-To: mp63qm$a50$1@loke.gir.dk

On Mon, 27 Jul 2015 15:20:37 -0500, Randy Brukardt wrote:

> "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de> wrote in message 
> news:5d6faxxdsssv.15g7kj5hv86mk$.dlg@40tude.net...
>> On Sun, 26 Jul 2015 00:11:22 -0700 (PDT), EGarrulo wrote:
> ...
>> What is indeed redundant here is the Object_Type. It is necessary because
>> Ada does not have access type introspection. That is, you cannot get the
>> object type from an access type, though the compiler knows it anyway.
>> Surely there should have been an attribute to get that type, e.g.
>>
>>   Pointer_Type'Target
>>
>> But there is none.
> 
> (1) The term is "designated type", so the attribute would be 
> Pointer_Type'Designated.
> 
> (2) Ada 83 did not have any type-valued attributes; it was considered a 
> problem. ('Base was not an attribute in Ada 83; it could only be used as the 
> prefix of another attribute.) Ada 95 changed that (for 'Base and 'Class), 
> but there wasn't any consideration (that I know of) whether there would be 
> any others that could make sense.

From the top of my head:

1. Arrays

type A is array (Positive range <>) of T;

A'Index = Positive
A'Element = T

2. Records

type R is record
   I : Integer;
   F : Float;
end R;

R'Index = type ... is (I, F) -- Enumeration of members
R'Member (R'Index'Val (0)) = Integer
R'Aggregator =
    type ... is access function (I : Integer; F : Float) return R

3. Tagged hierarchies

type S is new T with private;

S'Parent (T'Class) = T (in a public context)

The argument indicates the hierarchy where to search for the ancestor (due
to MI).

4. Subroutines

function Foo (I : Integer; F : Float) return T;

Foo'Index = type ... is (I, F)
Foo'Argument (Foo'Index'Val (0)) = Integer
Foo'Result = T

5. Discriminants

type T (I : Integer; B : Boolean) is ...;

T'Discriminant_Index = type ... is (I, B);
T'Discriminant (T'Discriminant_Index'Val (0)) = Integer
T'Constraints =  type ... (I : Integer; B : Boolean) is null record;

6. Generics

Actuals of generics. The visibility of is a real mess now. E.g. presently I
must "rename" actuals of generics like this:

   generic
      type T is ...;
   package Bar is
      subtype My_T is T;

to be able to access T in some generic contexts.

+ Some comparison of anonymous types

A'Index'Subtype_Conformant (B'Index) -- yields Boolean
A'Index'Type_Conformant (Integer)

--------------------------
The use cases are clear. Generics, universal stream I/O, persistency
layers, constructing/destructing will hugely profit from introspection. #3
is essential for robust code, when calling parent operations, e.g. in
Finalize.

> (3) We recently had a proposal for 'Subtype that applies to an object.

That is different I suppose, because it involves subtypes and because it
acts on an object, things which are not so static as plain types. Allowing
the attributes above for objects will possibly have similar problems. But
they are worth each attempt to resolve, IMO.

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de

  reply	other threads:[~2015-07-28  7:40 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-07-26  7:11 Why does `Unchecked_Deallocation` need the access type? EGarrulo
2015-07-26  8:54 ` Dmitry A. Kazakov
2015-07-26 11:16   ` Niklas Holsti
2015-07-27 22:38     ` Jeremiah
2015-07-27 20:20   ` Randy Brukardt
2015-07-28  7:40     ` Dmitry A. Kazakov [this message]
2015-07-28 21:25       ` Randy Brukardt
2015-07-29  6:28         ` Dmitry A. Kazakov
2015-07-29 20:47           ` Randy Brukardt
2015-07-30  6:19             ` Dmitry A. Kazakov
replies disabled

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