3 -- Grant of Unlimited Rights
5 -- Under contracts F33600-87-D-0337, F33600-84-D-0280, MDA903-79-C-0687,
6 -- F08630-91-C-0015, and DCA100-97-D-0025, the U.S. Government obtained
7 -- unlimited rights in the software and documentation contained herein.
8 -- Unlimited rights are defined in DFAR 252.227-7013(a)(19). By making
9 -- this public release, the Government intends to confer upon all
10 -- recipients unlimited rights equal to those held by the Government.
11 -- These rights include rights to use, duplicate, release or disclose the
12 -- released technical data and computer software in whole or in part, in
13 -- any manner and for any purpose whatsoever, and to have or permit others
18 -- ALL MATERIALS OR INFORMATION HEREIN RELEASED, MADE AVAILABLE OR
19 -- DISCLOSED ARE AS IS. THE GOVERNMENT MAKES NO EXPRESS OR IMPLIED
20 -- WARRANTY AS TO ANY MATTER WHATSOEVER, INCLUDING THE CONDITIONS OF THE
21 -- SOFTWARE, DOCUMENTATION OR OTHER INFORMATION RELEASED, MADE AVAILABLE
22 -- OR DISCLOSED, OR THE OWNERSHIP, MERCHANTABILITY, OR FITNESS FOR A
23 -- PARTICULAR PURPOSE OF SAID MATERIAL.
27 -- Check that tagged types declared within generic package declarations
28 -- generate distinct tags for each instance of the generic.
31 -- This test defines a very simple generic package (with the expectation
32 -- that it should be easily be shared), and a few instances of that
33 -- package. In true user-like fashion, two of the instances are identical
34 -- (to wit: IIO is new Integer_IO(Integer)). The tags generated for each
35 -- of them are placed into a list. The last action of the test is to
36 -- check that everything in the list is unique.
38 -- Almost as an aside, this test defines functions that return T'Base and
39 -- T'Class, and then exercises these functions.
41 -- (JPR) persistent objects really need a function like:
42 -- function Get_Object return T'class;
46 -- 20 OCT 95 SAIC Initial version
47 -- 23 APR 96 SAIC Commentary Corrections 2.1
51 ----------------------------------------------------------------- C390011_0
56 procedure Add_Tag_To_List
( T
: Ada
.Tags
.Tag
; X_Name
, X_Tag
: String );
58 procedure Check_List_For_Duplicates
;
62 -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
65 package body C390011_0
is
67 use type Ada
.Tags
.Tag
;
68 type SP
is access String;
71 type List_P
is access List_Item
;
72 type List_Item
is record
73 The_Tag
: Ada
.Tags
.Tag
;
81 procedure Add_Tag_To_List
( T
: Ada
.Tags
.Tag
; X_Name
, X_Tag
: String ) is
82 begin -- prepend the tag information to the list
83 The_List
:= new List_Item
'( The_Tag => T,
84 Exp_Name => new String'(X_Name
),
85 Ext_Tag
=> new String'(X_Tag),
89 procedure Check_List_For_Duplicates is
91 Thumb : List_P := The_List;
93 while Thumb /= null loop
95 while Finger /= null loop
96 -- Check that the tag is unique
97 if Finger.The_Tag = Thumb.The_Tag then
98 Report.Failed("Duplicate Tag");
101 -- Check that the Expanded name is unique
102 if Finger.Exp_Name.all = Thumb.Exp_Name.all then
103 Report.Failed("Tag name " & Finger.Exp_Name.all & " repeats");
106 -- Check that the External Tag is unique
108 if Finger.Ext_Tag.all = Thumb.Ext_Tag.all then
109 Report.Failed("External Tag " & Finger.Ext_Tag.all & " repeats");
111 Finger := Finger.Next;
115 end Check_List_For_Duplicates;
118 -- some things I just don't trust...
119 if The_List /= null then
120 Report.Failed("Implicit default for The_List not null");
124 ----------------------------------------------------------------- C390011_1
128 type Item is private;
131 type List is array(Index range <>) of Item;
132 type ListP is access all List;
134 type Table is tagged record
138 function Sort( T: in Table'Class ) return Table'Class;
140 function Stable_Table return Table'Class;
142 function Table_End( T: Table ) return Index'Base;
146 -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
148 package body C390011_1 is
150 -- In a user program this package would DO something
152 function Sort( T: in Table'Class ) return Table'Class is
157 Empty : Table'Class := Table'( Data
=> null );
159 function Stable_Table
return Table
'Class is
164 function Table_End
( T
: Table
) return Index
'Base is
166 return Index
'Base( T
.Data
.all'Last );
171 ----------------------------------------------------------------- C390011_2
174 package C390011_2
is new C390011_1
( Index
=> Character, Item
=> Float );
176 ----------------------------------------------------------------- C390011_3
179 package C390011_3
is new C390011_1
( Index
=> Character, Item
=> Float );
181 ----------------------------------------------------------------- C390011_4
184 package C390011_4
is new C390011_1
( Index
=> Integer, Item
=> Character );
186 ----------------------------------------------------------------- C390011_5
192 type Table_3
is new C390011_3
.Table
with record
193 Serial_Number
: Integer;
196 type Table_4
is new C390011_4
.Table
with record
197 Serial_Number
: Integer;
202 -- no package body C390011_5 required
204 ------------------------------------------------------------------- C390011
215 begin -- Main test procedure.
217 Report
.Test
("C390011", "Check that tagged types declared within " &
218 "generic package declarations generate distinct " &
219 "tags for each instance of the generic. " &
220 "Check that 'Base may be used as a subtype mark. " &
221 "Check that T'Base and T'Class are allowed as " &
222 "the subtype mark in a function result" );
224 -- build the tag information table
225 C390011_0
.Add_Tag_To_List
(T
=> C390011_2
.Table
'Tag,
226 X_Name
=> Ada
.Tags
.Expanded_Name
(C390011_2
.Table
'Tag),
227 X_Tag
=> Ada
.Tags
.External_Tag
(C390011_2
.Table
'Tag) );
229 C390011_0
.Add_Tag_To_List
(T
=> C390011_3
.Table
'Tag,
230 X_Name
=> Ada
.Tags
.Expanded_Name
(C390011_3
.Table
'Tag),
231 X_Tag
=> Ada
.Tags
.External_Tag
(C390011_3
.Table
'Tag) );
233 C390011_0
.Add_Tag_To_List
(T
=> C390011_4
.Table
'Tag,
234 X_Name
=> Ada
.Tags
.Expanded_Name
(C390011_4
.Table
'Tag),
235 X_Tag
=> Ada
.Tags
.External_Tag
(C390011_4
.Table
'Tag) );
237 C390011_0
.Add_Tag_To_List
(T
=> C390011_5
.Table_3
'Tag,
238 X_Name
=> Ada
.Tags
.Expanded_Name
(C390011_5
.Table_3
'Tag),
239 X_Tag
=> Ada
.Tags
.External_Tag
(C390011_5
.Table_3
'Tag) );
241 C390011_0
.Add_Tag_To_List
(T
=> C390011_5
.Table_4
'Tag,
242 X_Name
=> Ada
.Tags
.Expanded_Name
(C390011_5
.Table_4
'Tag),
243 X_Tag
=> Ada
.Tags
.External_Tag
(C390011_5
.Table_4
'Tag) );
245 -- preform the check for distinct tags
246 C390011_0
.Check_List_For_Duplicates
;