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 body of the parent package may depend on one of its own
28 -- private generic children.
31 -- A scenario is created that demonstrates the potential of adding a
32 -- generic private child during code maintenance without distubing a
33 -- large subsystem. After child is added to the subsystem, a maintainer
34 -- decides to take advantage of the new functionality and rewrites
37 -- Declare a data collection abstraction in a package. Declare a private
38 -- generic child of this package which provides parameterized code that
39 -- have been written once and will be used three times to implement the
40 -- services of the parent package. In the parent body, instantiate the
43 -- In the main program, check that the operations in the parent,
44 -- and instance of the private child package perform as expected.
48 -- 06 Dec 94 SAIC ACVC 2.0
49 -- 17 Nov 95 SAIC Update and repair for ACVC 2.0.1
56 type Data_Record
is tagged private;
57 type Data_Collection
is private;
60 subtype Data_1
is integer range 0 .. 100;
61 procedure Add_1
(Data
: Data_1
; To
: in out Data_Collection
);
62 function Statistical_Op_1
(Data
: Data_Collection
) return Data_1
;
64 subtype Data_2
is integer range -100 .. 1000;
65 procedure Add_2
(Data
: Data_2
; To
: in out Data_Collection
);
66 function Statistical_Op_2
(Data
: Data_Collection
) return Data_2
;
68 subtype Data_3
is integer range -10_000
.. 10_000
;
69 procedure Add_3
(Data
: Data_3
; To
: in out Data_Collection
);
70 function Statistical_Op_3
(Data
: Data_Collection
) return Data_3
;
75 type Data_Ptr
is access Data_Record
'class;
76 subtype Sequence_Number
is positive range 1 .. 512;
78 type Data_Record
is tagged
80 Next
: Data_Ptr
:= null;
81 Seq
: Sequence_Number
;
84 type Data_Collection
is
86 First
: Data_Ptr
:= null;
87 Last
: Data_Ptr
:= null;
93 --=================================================================--
95 -- This generic package provides parameterized code that has been
96 -- written once and will be used three times to implement the services
97 -- of the parent package.
101 type Data_Type
is range <>;
103 package CA11019_0
.CA11019_1
is
106 type Data_Elem
is new Data_Record
with
111 Next_Avail_Seq_No
: Sequence_Number
:= 1;
113 procedure Sequence
(Ptr
: Data_Ptr
);
114 -- the child must be private for this procedure to know details of
115 -- the implementation of data collections
117 procedure Add
(Datum
: Data_Type
; To
: in out Data_Collection
);
119 function Op
(Data
: Data_Collection
) return Data_Type
;
120 -- op models a complicated operation that whose code can be
121 -- used for various data types
124 end CA11019_0
.CA11019_1
;
127 --=================================================================--
130 package body CA11019_0
.CA11019_1
is
133 procedure Sequence
(Ptr
: Data_Ptr
) is
135 Ptr
.Seq
:= Next_Avail_Seq_No
;
136 Next_Avail_Seq_No
:= Next_Avail_Seq_No
+ 1;
139 ---------------------------------------------------------
141 procedure Add
(Datum
: Data_Type
; To
: in out Data_Collection
) is
144 if To
.First
= null then
145 -- assign new record with data value to
147 To
.First
:= new Data_Elem
'(Next => null,
153 -- chase to end of list
155 while Ptr.Next /= null loop
158 -- and add element there
159 Ptr.Next := new Data_Elem'(Next
=> null,
168 ---------------------------------------------------------
170 function Op
(Data
: Data_Collection
) return Data_Type
is
171 -- for simplicity, just return the maximum of the data set
172 Max
: Data_Type
:= Data_Elem
( Data
.First
.all ).Value
;
173 -- assuming non-empty collection
174 Ptr
: Data_Ptr
:= Data
.First
;
178 while Ptr
.Next
/= null loop
179 if Data_Elem
( Ptr
.Next
.all ).Value
> Max
then
180 Max
:= Data_Elem
( Ptr
.Next
.all ).Value
;
187 end CA11019_0
.CA11019_1
;
190 --=================================================================--
192 -- parent body depends on private generic child
193 with CA11019_0
.CA11019_1
; -- Private generic child.
195 pragma Elaborate
(CA11019_0
.CA11019_1
);
196 package body CA11019_0
is
198 -- instantiate the generic child with data types needed by the
199 -- package interface services
200 package Data_1_Ops
is new CA11019_1
201 (Data_Type
=> Data_1
);
203 package Data_2_Ops
is new CA11019_1
204 (Data_Type
=> Data_2
);
206 package Data_3_Ops
is new CA11019_1
207 (Data_Type
=> Data_3
);
209 ---------------------------------------------------------
211 procedure Add_1
(Data
: Data_1
; To
: in out Data_Collection
) is
213 -- maybe do other stuff here
214 Data_1_Ops
.Add
(Data
, To
);
218 ---------------------------------------------------------
220 function Statistical_Op_1
(Data
: Data_Collection
) return Data_1
is
222 -- maybe use generic operation(s) in some complicated ways
223 -- (but simplified out, for the sake of testing)
224 return Data_1_Ops
.Op
(Data
);
227 ---------------------------------------------------------
229 procedure Add_2
(Data
: Data_2
; To
: in out Data_Collection
) is
231 Data_2_Ops
.Add
(Data
, To
);
234 ---------------------------------------------------------
236 function Statistical_Op_2
(Data
: Data_Collection
) return Data_2
is
238 return Data_2_Ops
.Op
(Data
);
241 ---------------------------------------------------------
243 procedure Add_3
(Data
: Data_3
; To
: in out Data_Collection
) is
245 Data_3_Ops
.Add
(Data
, To
);
248 ---------------------------------------------------------
250 function Statistical_Op_3
(Data
: Data_Collection
) return Data_3
is
252 return Data_3_Ops
.Op
(Data
);
258 --=================================================--
262 -- Main.Child is private
267 package Main
renames CA11019_0
;
271 Col_3
: Main
.Data_Collection
;
275 Report
.Test
("CA11019", "Check that body of a (non-generic) package " &
276 "may depend on its private generic child");
278 -- build a data collection
280 for I
in 1 .. 10 loop
281 Main
.Add_1
( Main
.Data_1
(I
), Col_1
);
284 if Main
.Statistical_Op_1
(Col_1
) /= 10 then
285 Report
.Failed
("Wrong data_1 value returned");
288 for I
in reverse 10 .. 20 loop
289 Main
.Add_2
( Main
.Data_2
(I
* 10), Col_2
);
292 if Main
.Statistical_Op_2
(Col_2
) /= 200 then
293 Report
.Failed
("Wrong data_2 value returned");
296 for I
in 0 .. 10 loop
297 Main
.Add_3
( Main
.Data_3
(I
+ 5), Col_3
);
300 if Main
.Statistical_Op_3
(Col_3
) /= 15 then
301 Report
.Failed
("Wrong data_3 value returned");