comp.lang.ada
 help / color / mirror / Atom feed
From: stt@houdini.camb.inmet.com (Tucker Taft)
Subject: Re: Recursive tagged types
Date: 1997/11/10
Date: 1997-11-10T00:00:00+00:00	[thread overview]
Message-ID: <EJGDuu.8C8.0.-s@inmet.camb.inmet.com> (raw)
In-Reply-To: 34675FB1.7C8@gsfc.nasa.gov


Stephen Leake (Stephen.Leake@gsfc.nasa.gov) wrote:

: Adam Beneschan wrote:
: > 
: > GNAT outputs TRUE when I run this program.  Is this correct according
: > to the Ada rules?

: ObjectAda 7.1 on Windows 95 also reports TRUE.

Both are correct.  A tag identifies the "full_type_declaration" of the
type, per RM95 3.9(4) .  There is only one of these, even though there 
are conceptually multiple types, one per invocation of the recursive 
procedure.

: It seems to me that declaring a type in a subprogram should not declare
: a distinct type each time the subprogram is invoked. Consider the name
: of the type; Test1.Recursive_Procedure.Type1. This does not change with
: each invocation.

: On the other hand, the RM seems pretty clear that they should be
: distinct:

It is true that these are distinct *types* (which are run-time things)
but they are not distinct type *declarations* (which are compile-time 
constructs).  Note that distinct generic instantiations generally
do produce distinct type *declarations* in each instance,
and these are required to have distinct tags (at least for types
declared in the package spec).

Note that the language *allows* tags to be different on each
elaboration of the type declaration, but does not require it
(need to read the AARM 3.9(4.b) to see a discussion of this), because 
the identification goes only one way.  That is, the
tag identifies the declaration, but the declaration does not
necessarily uniquely determine the tag.

However, in essentially all implementations, one expects all elaborations
of a given type declaration to result in the same tag.  The one exception
might be for implementations that share code between generic instantiations.
These might generate a new tag for each elaboration if a generic 
instantiation occurs inside a subprogram.

In general, one expects the implementation of tags to be similar
to the implementation of exceptions, that is only one per declaration,
rather than one per elaboration of the declaration.

Another way of thinking about it is that if the full expanded names of
two types are the same, then their tags may be the same.

: RM 3.2.1(11)

: The elaboration of a full_type_declaration consists of the elaboration
: of the full type definition. Each elaboration of a full type definition
: creates a distinct type and its first subtype. 

Right, it creates a distinct *type* but not a distinct type declaration,
which is a compile-time thing.

: ...
: - Stephe

--
-Tucker Taft   stt@inmet.com   http://www.inmet.com/~stt/
Intermetrics, Inc.  Burlington, MA  USA




      reply	other threads:[~1997-11-10  0:00 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1997-11-07  0:00 Recursive tagged types Adam Beneschan
1997-11-10  0:00 ` Stephen Leake
1997-11-10  0:00   ` Tucker Taft [this message]
replies disabled

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