-- C390010.A
|
-- C390010.A
|
--
|
--
|
-- Grant of Unlimited Rights
|
-- Grant of Unlimited Rights
|
--
|
--
|
-- Under contracts F33600-87-D-0337, F33600-84-D-0280, MDA903-79-C-0687,
|
-- 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
|
-- 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 in the software and documentation contained herein.
|
-- Unlimited rights are defined in DFAR 252.227-7013(a)(19). By making
|
-- Unlimited rights are defined in DFAR 252.227-7013(a)(19). By making
|
-- this public release, the Government intends to confer upon all
|
-- this public release, the Government intends to confer upon all
|
-- recipients unlimited rights equal to those held by the Government.
|
-- recipients unlimited rights equal to those held by the Government.
|
-- These rights include rights to use, duplicate, release or disclose the
|
-- These rights include rights to use, duplicate, release or disclose the
|
-- released technical data and computer software in whole or in part, in
|
-- 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
|
-- any manner and for any purpose whatsoever, and to have or permit others
|
-- to do so.
|
-- to do so.
|
--
|
--
|
-- DISCLAIMER
|
-- DISCLAIMER
|
--
|
--
|
-- ALL MATERIALS OR INFORMATION HEREIN RELEASED, MADE AVAILABLE OR
|
-- ALL MATERIALS OR INFORMATION HEREIN RELEASED, MADE AVAILABLE OR
|
-- DISCLOSED ARE AS IS. THE GOVERNMENT MAKES NO EXPRESS OR IMPLIED
|
-- DISCLOSED ARE AS IS. THE GOVERNMENT MAKES NO EXPRESS OR IMPLIED
|
-- WARRANTY AS TO ANY MATTER WHATSOEVER, INCLUDING THE CONDITIONS OF THE
|
-- WARRANTY AS TO ANY MATTER WHATSOEVER, INCLUDING THE CONDITIONS OF THE
|
-- SOFTWARE, DOCUMENTATION OR OTHER INFORMATION RELEASED, MADE AVAILABLE
|
-- SOFTWARE, DOCUMENTATION OR OTHER INFORMATION RELEASED, MADE AVAILABLE
|
-- OR DISCLOSED, OR THE OWNERSHIP, MERCHANTABILITY, OR FITNESS FOR A
|
-- OR DISCLOSED, OR THE OWNERSHIP, MERCHANTABILITY, OR FITNESS FOR A
|
-- PARTICULAR PURPOSE OF SAID MATERIAL.
|
-- PARTICULAR PURPOSE OF SAID MATERIAL.
|
--*
|
--*
|
--
|
--
|
-- OBJECTIVE:
|
-- OBJECTIVE:
|
-- Check that if S is a subtype of a tagged type T, and if S is
|
-- Check that if S is a subtype of a tagged type T, and if S is
|
-- constrained, then the allowable values of S'Class are only those
|
-- constrained, then the allowable values of S'Class are only those
|
-- that, when converted to T, belong to S.
|
-- that, when converted to T, belong to S.
|
--
|
--
|
-- TEST DESCRIPTION:
|
-- TEST DESCRIPTION:
|
-- This test defines a small tagged hierarchy of discriminated tagged
|
-- This test defines a small tagged hierarchy of discriminated tagged
|
-- records, and constrained subtypes of those tagged record types.
|
-- records, and constrained subtypes of those tagged record types.
|
-- It then uses access to the classwide of the constrained subtype
|
-- It then uses access to the classwide of the constrained subtype
|
-- to check the objective.
|
-- to check the objective.
|
--
|
--
|
--
|
--
|
-- CHANGE HISTORY:
|
-- CHANGE HISTORY:
|
-- 09 APR 96 SAIC Initial version
|
-- 09 APR 96 SAIC Initial version
|
-- 03 NOV 96 SAIC Revised for 2.1 release
|
-- 03 NOV 96 SAIC Revised for 2.1 release
|
-- 31 DEC 97 EDS Restored use of intermediate access variable
|
-- 31 DEC 97 EDS Restored use of intermediate access variable
|
-- to eliminate raising of Program_Error
|
-- to eliminate raising of Program_Error
|
-- 13 SEP 99 RLB Repaired previous change to avoid premature
|
-- 13 SEP 99 RLB Repaired previous change to avoid premature
|
-- subtype check.
|
-- subtype check.
|
-- 28 JUN 02 RLB Added pragma Elaborate_All (Report);.
|
-- 28 JUN 02 RLB Added pragma Elaborate_All (Report);.
|
--!
|
--!
|
|
|
----------------------------------------------------------------- C390010_0
|
----------------------------------------------------------------- C390010_0
|
|
|
with Report; pragma Elaborate_All (Report);
|
with Report; pragma Elaborate_All (Report);
|
package C390010_0 is
|
package C390010_0 is
|
|
|
-- the defined subprograms will allow checking the placement of
|
-- the defined subprograms will allow checking the placement of
|
-- constraint_checks
|
-- constraint_checks
|
|
|
-- define a discriminated tagged type, and a constrained subtype of
|
-- define a discriminated tagged type, and a constrained subtype of
|
-- that type:
|
-- that type:
|
|
|
type Discr_Tag_Record( Disc: Boolean ) is tagged record
|
type Discr_Tag_Record( Disc: Boolean ) is tagged record
|
FieldA : Character := 'A';
|
FieldA : Character := 'A';
|
case Disc is
|
case Disc is
|
when True => FieldB : Character := 'B';
|
when True => FieldB : Character := 'B';
|
when False => FieldC : Character := 'C';
|
when False => FieldC : Character := 'C';
|
end case;
|
end case;
|
end record;
|
end record;
|
|
|
procedure Dispatching_Op( DTO : in out Discr_Tag_Record );
|
procedure Dispatching_Op( DTO : in out Discr_Tag_Record );
|
|
|
Authentic : Boolean := Report.Ident_Bool( True );
|
Authentic : Boolean := Report.Ident_Bool( True );
|
|
|
subtype True_Record is Discr_Tag_Record( Authentic );
|
subtype True_Record is Discr_Tag_Record( Authentic );
|
|
|
|
|
-- derive a type, "passing through" one discriminant, adding one
|
-- derive a type, "passing through" one discriminant, adding one
|
-- discriminant, and a constrained subtype of THAT type:
|
-- discriminant, and a constrained subtype of THAT type:
|
|
|
type Derived_Record( Disc1, Disc2: Boolean ) is
|
type Derived_Record( Disc1, Disc2: Boolean ) is
|
new Discr_Tag_Record( Disc1 ) with record
|
new Discr_Tag_Record( Disc1 ) with record
|
FieldD : Character := 'D';
|
FieldD : Character := 'D';
|
case Disc2 is
|
case Disc2 is
|
when True => FieldE : Character := 'E';
|
when True => FieldE : Character := 'E';
|
when False => FieldF : Character := 'F';
|
when False => FieldF : Character := 'F';
|
end case;
|
end case;
|
end record;
|
end record;
|
|
|
procedure Dispatching_Op( DR : in out Derived_Record );
|
procedure Dispatching_Op( DR : in out Derived_Record );
|
|
|
subtype True_True_Derived is Derived_Record( Authentic, Authentic );
|
subtype True_True_Derived is Derived_Record( Authentic, Authentic );
|
|
|
|
|
-- now, define an access to classwide type, using the classwide from the
|
-- now, define an access to classwide type, using the classwide from the
|
-- constrained subtype of the root (or parent) type:
|
-- constrained subtype of the root (or parent) type:
|
|
|
type Subtype_Parent_Class_Access is access all True_Record'Class;
|
type Subtype_Parent_Class_Access is access all True_Record'Class;
|
type Parent_Class_Access is access all Discr_Tag_Record'Class;
|
type Parent_Class_Access is access all Discr_Tag_Record'Class;
|
|
|
procedure PCW_Op( SPCA : in Subtype_Parent_Class_Access );
|
procedure PCW_Op( SPCA : in Subtype_Parent_Class_Access );
|
|
|
end C390010_0;
|
end C390010_0;
|
|
|
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- C390010_0
|
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- C390010_0
|
|
|
with Report;
|
with Report;
|
with TCTouch;
|
with TCTouch;
|
package body C390010_0 is
|
package body C390010_0 is
|
|
|
procedure Dispatching_Op( DTO : in out Discr_Tag_Record ) is
|
procedure Dispatching_Op( DTO : in out Discr_Tag_Record ) is
|
begin
|
begin
|
TCTouch.Touch('1'); --------------------------------------------------- 1
|
TCTouch.Touch('1'); --------------------------------------------------- 1
|
if DTO.Disc then
|
if DTO.Disc then
|
TCTouch.Touch(DTO.FieldB); ------------------------------------------ B
|
TCTouch.Touch(DTO.FieldB); ------------------------------------------ B
|
else
|
else
|
TCTouch.Touch(DTO.FieldC); ------------------------------------------ C
|
TCTouch.Touch(DTO.FieldC); ------------------------------------------ C
|
end if;
|
end if;
|
end Dispatching_Op;
|
end Dispatching_Op;
|
|
|
|
|
procedure Dispatching_Op( DR : in out Derived_Record ) is
|
procedure Dispatching_Op( DR : in out Derived_Record ) is
|
begin
|
begin
|
TCTouch.Touch('2'); --------------------------------------------------- 2
|
TCTouch.Touch('2'); --------------------------------------------------- 2
|
if DR.Disc1 then
|
if DR.Disc1 then
|
TCTouch.Touch(DR.FieldB); ------------------------------------------ B
|
TCTouch.Touch(DR.FieldB); ------------------------------------------ B
|
else
|
else
|
TCTouch.Touch(DR.FieldC); ------------------------------------------ C
|
TCTouch.Touch(DR.FieldC); ------------------------------------------ C
|
end if;
|
end if;
|
if DR.Disc2 then
|
if DR.Disc2 then
|
TCTouch.Touch(DR.FieldE); ------------------------------------------ E
|
TCTouch.Touch(DR.FieldE); ------------------------------------------ E
|
else
|
else
|
TCTouch.Touch(DR.FieldF); ------------------------------------------ F
|
TCTouch.Touch(DR.FieldF); ------------------------------------------ F
|
end if;
|
end if;
|
end Dispatching_Op;
|
end Dispatching_Op;
|
|
|
procedure PCW_Op( SPCA : in Subtype_Parent_Class_Access ) is
|
procedure PCW_Op( SPCA : in Subtype_Parent_Class_Access ) is
|
begin
|
begin
|
|
|
-- the following line is the "heart" of this test, objects of all types
|
-- the following line is the "heart" of this test, objects of all types
|
-- covered by the classwide type will be passed to this subprogram in
|
-- covered by the classwide type will be passed to this subprogram in
|
-- the execution of the test.
|
-- the execution of the test.
|
if SPCA.Disc then
|
if SPCA.Disc then
|
TCTouch.Touch(SPCA.FieldB); ------------------------------------------ B
|
TCTouch.Touch(SPCA.FieldB); ------------------------------------------ B
|
else
|
else
|
TCTouch.Touch(SPCA.FieldC); ------------------------------------------ C
|
TCTouch.Touch(SPCA.FieldC); ------------------------------------------ C
|
end if;
|
end if;
|
|
|
Dispatching_Op( SPCA.all ); -- check that this dispatches correctly,
|
Dispatching_Op( SPCA.all ); -- check that this dispatches correctly,
|
-- with discriminants correctly represented
|
-- with discriminants correctly represented
|
|
|
end PCW_Op;
|
end PCW_Op;
|
|
|
end C390010_0;
|
end C390010_0;
|
|
|
------------------------------------------------------------------- C390010
|
------------------------------------------------------------------- C390010
|
|
|
with Report;
|
with Report;
|
with TCTouch;
|
with TCTouch;
|
with C390010_0;
|
with C390010_0;
|
procedure C390010 is
|
procedure C390010 is
|
|
|
package CP renames C390010_0;
|
package CP renames C390010_0;
|
|
|
procedure Check_Element( Item : access CP.Discr_Tag_Record'Class ) is
|
procedure Check_Element( Item : access CP.Discr_Tag_Record'Class ) is
|
begin
|
begin
|
|
|
-- the implicit conversion from the general access parameter to the more
|
-- the implicit conversion from the general access parameter to the more
|
-- constrained subtype access type in the following call should cause
|
-- constrained subtype access type in the following call should cause
|
-- Constraint_Error in the cases where the object is not correctly
|
-- Constraint_Error in the cases where the object is not correctly
|
-- constrained
|
-- constrained
|
|
|
CP.PCW_Op( Item.all'Access );
|
CP.PCW_Op( Item.all'Access );
|
|
|
exception
|
exception
|
when Constraint_Error => TCTouch.Touch('X'); -------------------------- X
|
when Constraint_Error => TCTouch.Touch('X'); -------------------------- X
|
when others => Report.Failed("Unanticipated exception in Check_Element");
|
when others => Report.Failed("Unanticipated exception in Check_Element");
|
|
|
end Check_Element;
|
end Check_Element;
|
|
|
An_Item : CP.Parent_Class_Access;
|
An_Item : CP.Parent_Class_Access;
|
|
|
begin -- Main test procedure.
|
begin -- Main test procedure.
|
|
|
Report.Test ("C390010", "Check that if S is a subtype of a tagged type " &
|
Report.Test ("C390010", "Check that if S is a subtype of a tagged type " &
|
"T, and if S is constrained, then the allowable " &
|
"T, and if S is constrained, then the allowable " &
|
"values of S'Class are only those that, when " &
|
"values of S'Class are only those that, when " &
|
"converted to T, belong to S" );
|
"converted to T, belong to S" );
|
|
|
An_Item := new CP.Discr_Tag_Record(True);
|
An_Item := new CP.Discr_Tag_Record(True);
|
Check_Element( An_Item );
|
Check_Element( An_Item );
|
TCTouch.Validate("B1B","Case 1");
|
TCTouch.Validate("B1B","Case 1");
|
|
|
An_Item := new CP.Discr_Tag_Record(False);
|
An_Item := new CP.Discr_Tag_Record(False);
|
Check_Element( An_Item );
|
Check_Element( An_Item );
|
TCTouch.Validate("X","Case 2");
|
TCTouch.Validate("X","Case 2");
|
|
|
An_Item := new CP.True_Record;
|
An_Item := new CP.True_Record;
|
Check_Element( An_Item );
|
Check_Element( An_Item );
|
TCTouch.Validate("B1B","Case 3");
|
TCTouch.Validate("B1B","Case 3");
|
|
|
An_Item := new CP.Derived_Record(False, False);
|
An_Item := new CP.Derived_Record(False, False);
|
Check_Element( An_Item );
|
Check_Element( An_Item );
|
TCTouch.Validate("X","Case 4");
|
TCTouch.Validate("X","Case 4");
|
|
|
An_Item := new CP.Derived_Record(False, True);
|
An_Item := new CP.Derived_Record(False, True);
|
Check_Element( An_Item );
|
Check_Element( An_Item );
|
TCTouch.Validate("X","Case 5");
|
TCTouch.Validate("X","Case 5");
|
|
|
An_Item := new CP.Derived_Record(True, False);
|
An_Item := new CP.Derived_Record(True, False);
|
Check_Element( An_Item );
|
Check_Element( An_Item );
|
TCTouch.Validate("B2BF","Case 6");
|
TCTouch.Validate("B2BF","Case 6");
|
|
|
An_Item := new CP.True_True_Derived;
|
An_Item := new CP.True_True_Derived;
|
Check_Element( An_Item );
|
Check_Element( An_Item );
|
TCTouch.Validate("B2BE","Case 7");
|
TCTouch.Validate("B2BE","Case 7");
|
|
|
Report.Result;
|
Report.Result;
|
|
|
end C390010;
|
end C390010;
|
|
|