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 a public child can utilize its parent unit's visible
31 -- Declare a parent package that contains the following: type, object,
32 -- constant, exception, and subprograms. Declare a public child unit
33 -- that utilizes the components found in the visible part of its parent.
35 -- Demonstrate utilization of the following parent components in the
45 -- This abstraction simulates a portion of a simple operating system.
49 -- 06 Dec 94 SAIC ACVC 2.0
53 package CA11002_0
is -- Package OS.
55 type File_Descriptor
is new Integer;
56 type File_Mode
is (Read_Only
, Write_Only
, Read_Write
);
58 Null_File
: constant File_Descriptor
:= 0;
59 Default_Mode
: constant File_Mode
:= Read_Only
;
60 Active_Mode
: constant File_Mode
:= Read_Write
;
64 Descriptor
: File_Descriptor
:= Null_File
;
65 Mode
: File_Mode
:= Default_Mode
;
68 System_File
: File_Type
;
69 File_Mode_Error
: exception;
71 function Next_Available_File
return File_Descriptor
;
73 function Mode_Of_File
(File
: File_Type
) return File_Mode
;
75 end CA11002_0
; -- Package OS.
77 --=================================================================--
79 package body CA11002_0
is -- Package body OS.
81 File_Count
: Integer := 0;
83 function Next_Available_File
return File_Descriptor
is
85 File_Count
:= File_Count
+ 1;
86 return (File_Descriptor
(File_Count
)); -- Type conversion.
87 end Next_Available_File
;
88 --------------------------------------------------------------
89 function Mode_Of_File
(File
: File_Type
) return File_Mode
is
90 Mode
: File_Mode
:= File
.Mode
;
95 end CA11002_0
; -- Package body OS.
97 --=================================================================--
99 package CA11002_0
.CA11002_1
is -- Child package OS.Operations.
101 -- Dot qualification of types, objects, etc. from parent is not required
104 procedure Create_File
(Mode
: in File_Mode
:= Active_Mode
;
105 File
: out File_Type
);
107 end CA11002_0
.CA11002_1
; -- Child package OS.Operations.
109 --=================================================================--
112 package body CA11002_0
.CA11002_1
is -- Child package body OS.Operations.
114 function New_File_Validated
(File
: File_Type
) -- Ensure that a newly
115 return Boolean is -- created file has
116 Result
: Boolean := False; -- appropriate values.
118 if (File
.Descriptor
> System_File
.Descriptor
) and -- Parent object.
119 (File
.Mode
in File_Mode
) -- Parent type.
126 end New_File_Validated
;
127 --------------------------------------------------------------
128 procedure Create_File
129 (Mode
: in File_Mode
:= Active_Mode
; -- Parent constant.
130 File
: out File_Type
) is -- Parent type.
132 New_File
: File_Type
;
135 New_File
.Descriptor
:= Next_Available_File
; -- Parent subprogram.
136 New_File
.Mode
:= Mode
;
138 if New_File_Validated
(File
=> New_File
) then
144 end CA11002_0
.CA11002_1
; -- Child Package body OS.Operations.
146 --=================================================================--
148 -- Child library subprogram Convert_File_Mode specification.
149 procedure CA11002_0
.CA11002_2
(File
: in out File_Type
; -- Parent type.
150 New_Mode
: in File_Mode
); -- Parent type.
153 --=================================================================--
156 -- Child library subprogram Convert_File_Mode body.
157 procedure CA11002_0
.CA11002_2
(File
: in out File_Type
;
158 New_Mode
: in File_Mode
) is
160 if File
.Mode
= New_Mode
then
161 raise File_Mode_Error
; -- Parent exception.
162 Report
.Failed
("Exception not raised in child unit");
164 File
.Mode
:= New_Mode
;
166 end CA11002_0
.CA11002_2
;
168 --=================================================================--
171 with CA11002_0
.CA11002_1
; -- Child package OS.Operations.
172 with CA11002_0
.CA11002_2
; -- Child subprogram OS.Convert_File_Mode,
173 -- Implicitly with parent, OS.
174 use CA11002_0
; -- All user-defined operators directly
179 Report
.Test
("CA11002", "Check that a public child can utilize its " &
180 "parent unit's visible definitions");
182 File_Creation
: -- This processing block will demonstrate
183 -- use of child package subroutine that
184 -- takes advantage of components declared
185 -- in the parent package.
187 User_File
: File_Type
;
189 CA11002_0
.CA11002_1
.Create_File
(File
=> User_File
); -- Default mode
192 if (User_File
.Descriptor
= System_File
.Descriptor
) or
193 (User_File
.Mode
= Default_Mode
)
195 Report
.Failed
("Incorrect file creation");
200 --------------------------------------------------------------
201 File_Mode_Conversion
: -- This processing block will demonstrate
202 -- the occurrence of a (forced) exception
203 -- being raised in a child subprogram, and
204 -- propagated to the caller. The exception
205 -- is handled, and the child subprogram
206 -- is called again, this time to perform
209 procedure Convert_File_Mode
(File
: in out File_Type
;
210 New_Mode
: in File_Mode
) renames CA11002_0
.CA11002_2
;
211 New_File
: File_Type
;
212 begin -- Raise an exception with this
213 -- illegal conversion operation
214 -- (attempt to change to current mode).
216 Convert_File_Mode
(File
=> New_File
,
217 New_Mode
=> Default_Mode
);
218 Report
.Failed
("Exception should have been raised in child unit");
221 when File_Mode_Error
=> -- Perform the conversion again, this
222 -- time with a different file mode.
224 Convert_File_Mode
(File
=> New_File
,
225 New_Mode
=> CA11002_0
.Active_Mode
);
227 if New_File
.Mode
/= Read_Write
then
228 Report
.Failed
("Incorrect result from mode conversion operation");
232 Report
.Failed
("Unexpected exception raised in File_Mode_Conversion");
234 end File_Mode_Conversion
;