1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252
|
-- C730A02.A
--
-- Grant of Unlimited Rights
--
-- Under contracts F33600-87-D-0337, F33600-84-D-0280, MDA903-79-C-0687,
-- F08630-91-C-0015, and DCA100-97-D-0025, the U.S. Government obtained
-- unlimited rights in the software and documentation contained herein.
-- Unlimited rights are defined in DFAR 252.227-7013(a)(19). By making
-- this public release, the Government intends to confer upon all
-- recipients unlimited rights equal to those held by the Government.
-- These rights include rights to use, duplicate, release or disclose the
-- released technical data and computer software in whole or in part, in
-- any manner and for any purpose whatsoever, and to have or permit others
-- to do so.
--
-- DISCLAIMER
--
-- ALL MATERIALS OR INFORMATION HEREIN RELEASED, MADE AVAILABLE OR
-- DISCLOSED ARE AS IS. THE GOVERNMENT MAKES NO EXPRESS OR IMPLIED
-- WARRANTY AS TO ANY MATTER WHATSOEVER, INCLUDING THE CONDITIONS OF THE
-- SOFTWARE, DOCUMENTATION OR OTHER INFORMATION RELEASED, MADE AVAILABLE
-- OR DISCLOSED, OR THE OWNERSHIP, MERCHANTABILITY, OR FITNESS FOR A
-- PARTICULAR PURPOSE OF SAID MATERIAL.
--*
--
-- OBJECTIVE:
-- Check that a private extension (declared in a package specification) of
-- a tagged type (declared in a different package specification) may be
-- passed as a generic formal (tagged) private type to a generic package
-- declaration. Check that the formal type may be further extended with a
-- private extension in the generic package.
--
-- Check that the (visible) components inherited by the "generic"
-- extension are visible outside the generic package.
--
-- Check that, in the instance, the private extension inherits the
-- user-defined primitive subprograms of the tagged actual, including
-- those inherited by the actual from its parent.
--
-- TEST DESCRIPTION:
-- Declare a tagged type and an associated primitive subprogram in a
-- package specification (foundation code). Declare a private extension
-- of the tagged type and an associated primitive subprogram in a second
-- package specification. Declare a generic package which takes a tagged
-- type as a formal parameter, and then extends it with a private
-- extension (foundation code).
--
-- Instantiate the generic package with the private extension from the
-- second package (the "generic" extension should now have inherited
-- the primitive subprograms of the private extension from the second
-- package).
--
-- In the main program, call the primitive subprograms inherited by the
-- "generic" extension. There are two: (1) Create_Book, declared for
-- the root tagged type in the first package (inherited by the private
-- extension of the second package, and then in turn by the "generic"
-- extension), and (2) Update_Pages, declared for the private extension
-- in the second package. Verify the correctness of the components.
--
-- TEST FILES:
-- The following files comprise this test:
--
-- F730A000.A
-- F730A001.A
-- => C730A02.A
--
--
-- CHANGE HISTORY:
-- 06 Dec 94 SAIC ACVC 2.0
--
--!
with F730A001; -- Book definitions.
package C730A02_0 is -- Extended book abstraction.
type Detailed_Book_Type is new F730A001.Book_Type -- Private ext.
with private; -- of root tagged
-- type.
-- Inherits Create_Book from Book_Type.
procedure Update_Pages (Book : in out Detailed_Book_Type; -- Primitive op.
Pages : in Natural); -- of extension.
-- The following function is needed to verify the value of the
-- extension's private component. It will be inherited by extensions
-- of Detailed_Book_Type.
function Get_Pages (Book : in Detailed_Book_Type) return Natural;
private
type Detailed_Book_Type is new F730A001.Book_Type with record
Pages : Natural;
end record;
end C730A02_0;
--==================================================================--
package body C730A02_0 is
procedure Update_Pages (Book : in out Detailed_Book_Type;
Pages : in Natural) is
begin
Book.Pages := Pages;
end Update_Pages;
function Get_Pages (Book : in Detailed_Book_Type) return Natural is
begin
return (Book.Pages);
end Get_Pages;
end C730A02_0;
--==================================================================--
with F730A001; -- Book definitions.
package C730A02_1 is -- Raw data to be used in creating book elements.
Book_Count : constant := 3;
subtype Number_Of_Books is Integer range 1 .. Book_Count;
type Data_List is array (Number_Of_Books) of F730A001.Text_Ptr;
type Page_Counts is array (Number_Of_Books) of Natural;
Title_List : Data_List := (new String'("Wuthering Heights"),
new String'("Heart of Darkness"),
new String'("Ulysses"));
Author_List : Data_List := (new String'("Bronte, Emily"),
new String'("Conrad, Joseph"),
new String'("Joyce, James"));
Page_List : Page_Counts := (237, 215, 456);
end C730A02_1;
-- No body for C730A02_1.
--==================================================================--
-- Library-level instantiation. Actual parameter is private extension.
with C730A02_0; -- Extended book abstraction.
with F730A000; -- Singly-linked list abstraction.
package C730A02_2 is new F730A000
(Parent_Type => C730A02_0.Detailed_Book_Type);
--==================================================================--
with Report;
with C730A02_0; -- Extended book abstraction.
with C730A02_1; -- Raw book data.
with C730A02_2; -- Instance.
use C730A02_0; -- Primitive operations of Detailed_Book_Type directly visible.
use C730A02_2; -- Operations inherited by Priv_Node_Type directly visible.
procedure C730A02 is
List_Of_Books : Priv_Node_Ptr := null; -- Head of linked list of books.
--========================================================--
procedure Create_List (Title, Author : in C730A02_1.Data_List;
Pages : in C730A02_1.Page_Counts;
Head : in out Priv_Node_Ptr) is
Book : Priv_Node_Type; -- Object of extended type.
Book_Ptr : Priv_Node_Ptr;
begin
for I in C730A02_1.Number_Of_Books loop
Create_Book (Title (I), Author (I), Book); -- Call twice-inherited
-- operation.
Update_Pages (Book, Pages (I)); -- Call inherited op.
Book_Ptr := new Priv_Node_Type'(Book);
Add (Book_Ptr, Head);
end loop;
end Create_List;
--========================================================--
function Bad_List_Contents return Boolean is
Book1_Ptr : Priv_Node_Ptr;
Book2_Ptr : Priv_Node_Ptr;
Book3_Ptr : Priv_Node_Ptr;
begin
Remove (List_Of_Books, Book1_Ptr);
Remove (List_Of_Books, Book2_Ptr);
Remove (List_Of_Books, Book3_Ptr);
return (Book1_Ptr.Title.all /= "Ulysses" or -- Inherited
Book1_Ptr.Author.all /= "Joyce, James" or -- components
Book2_Ptr.Title.all /= "Heart of Darkness" or -- should still
Book2_Ptr.Author.all /= "Conrad, Joseph" or -- be visible
Book3_Ptr.Title.all /= "Wuthering Heights" or -- in private
Book3_Ptr.Author.all /= "Bronte, Emily" or -- "generic"
-- extension.
-- Call inherited operations using dereferenced pointers.
Get_Pages (Book1_Ptr.all) /= 456 or
Get_Pages (Book2_Ptr.all) /= 215 or
Get_Pages (Book3_Ptr.all) /= 237);
end Bad_List_Contents;
--========================================================--
begin -- Main program.
Report.Test ("C730A02", "Inheritance of primitive operations: private " &
"extension of formal tagged private type; actual is " &
"a private extension");
-- Create linked list using inherited operation:
Create_List (C730A02_1.Title_List, C730A02_1.Author_List,
C730A02_1.Page_List, List_Of_Books);
-- Verify results:
if Bad_List_Contents then
Report.Failed ("Wrong values after call to inherited operations");
end if;
Report.Result;
end C730A02;
|