* Recursive tagged types @ 1997-11-07 0:00 Adam Beneschan 1997-11-10 0:00 ` Stephen Leake 0 siblings, 1 reply; 3+ messages in thread From: Adam Beneschan @ 1997-11-07 0:00 UTC (permalink / raw) GNAT outputs TRUE when I run this program. Is this correct according to the Ada rules? -- thanks, Adam with Ada.Tags; with Text_IO; procedure Test1 is Tag1 : Ada.Tags.Tag; Tag2 : Ada.Tags.Tag; procedure Recursive_Procedure (N : in Integer) is type Type1 is tagged null record; type Type2 is new Type1 with record Some_Data : Integer; end record; begin if N = 1 then Tag1 := Type2'Tag; Recursive_Procedure (2); else Tag2 := Type2'Tag; end if; end Recursive_Procedure; begin Recursive_Procedure (1); Text_IO.Put_Line (Boolean'image (Ada.Tags."=" (Tag1, Tag2))); end Test1; -------------------==== Posted via Deja News ====----------------------- http://www.dejanews.com/ Search, Read, Post to Usenet ^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: Recursive tagged types 1997-11-07 0:00 Recursive tagged types Adam Beneschan @ 1997-11-10 0:00 ` Stephen Leake 1997-11-10 0:00 ` Tucker Taft 0 siblings, 1 reply; 3+ messages in thread From: Stephen Leake @ 1997-11-10 0:00 UTC (permalink / raw) 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. 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: 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. RM 6.3 (7): The execution of a subprogram_body is invoked by a subprogram call. For this execution the declarative_part is elaborated, and the handled_sequence_of_statements is then executed. > > -- thanks, Adam > > with Ada.Tags; > with Text_IO; > > procedure Test1 is > > Tag1 : Ada.Tags.Tag; > Tag2 : Ada.Tags.Tag; > > procedure Recursive_Procedure (N : in Integer) is > > type Type1 is tagged null record; > > type Type2 is new Type1 with record > Some_Data : Integer; > end record; > > begin > if N = 1 then > Tag1 := Type2'Tag; > Recursive_Procedure (2); > else > Tag2 := Type2'Tag; > end if; > end Recursive_Procedure; > > begin > Recursive_Procedure (1); > Text_IO.Put_Line (Boolean'image (Ada.Tags."=" (Tag1, Tag2))); > end Test1; > > -------------------==== Posted via Deja News ====----------------------- > http://www.dejanews.com/ Search, Read, Post to Usenet -- - Stephe ^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: Recursive tagged types 1997-11-10 0:00 ` Stephen Leake @ 1997-11-10 0:00 ` Tucker Taft 0 siblings, 0 replies; 3+ messages in thread From: Tucker Taft @ 1997-11-10 0:00 UTC (permalink / raw) 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 ^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~1997-11-10 0:00 UTC | newest] Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 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 is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox