Debian Codegraph @

gcc/testsuite/ada/acats/tests/c3/c3a0010.a

raw
1 -- C3A0010.A
2 --
3 -- Grant of Unlimited Rights
4 --
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
14 -- to do so.
15 --
16 -- DISCLAIMER
17 --
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.
24 --*
25 --
26 -- OBJECTIVE:
27 -- Check that an access-to-subprogram type in a generic instance may be
28 -- used to declare access-to-subprogram objects which invoke subprograms
29 -- in the instance.
30 --
31 -- TEST DESCRIPTION:
32 -- Declare a numeric type in the visible part of a generic package.
33 -- Declare two different math procedures that can be referred to by
34 -- the access to procedure type.
35 --
36 -- In the main program, instantiate the generic. Declare an access
37 -- to procedure type. Call each procedure indirectly by dereferencing
38 -- the access value.
39 --
40 --
41 -- CHANGE HISTORY:
42 -- 06 Dec 94 SAIC ACVC 2.0
43 -- 05 APR 96 SAIC Header correction for 2.1
44 --
45 --!
46
47 generic
48 type Real_Num is digits <>;
49
50 package C3A0010_0 is
51
52 -- Type accesses to any math procedure
53 type Math_Procedure_Ptr is access procedure
54 (First_Num, Second_Num : in Real_Num;
55 Result_Num : out Real_Num);
56
57 procedure Add (First_Num, Second_Num : in Real_Num;
58 Result_Num : out Real_Num);
59
60 procedure Subtract (First_Num, Second_Num : in Real_Num;
61 Result_Num : out Real_Num);
62
63 end C3A0010_0;
64
65
66 -----------------------------------------------------------------------------
67
68
69 package body C3A0010_0 is
70
71 procedure Add (First_Num, Second_Num : in Real_Num;
72 Result_Num : out Real_Num) is
73 begin
74 Result_Num := First_Num + Second_Num;
75 end Add;
76
77
78 procedure Subtract (First_Num, Second_Num : in Real_Num;
79 Result_Num : out Real_Num) is
80 begin
81 Result_Num := First_Num - Second_Num;
82 end Subtract;
83
84 end C3A0010_0;
85
86 -----------------------------------------------------------------------------
87
88 with Report;
89 with C3A0010_0;
90
91 procedure C3A0010 is
92
93 type Real is digits 2;
94
95 subtype Math_Float is Real range -10.0 .. 10.0;
96
97 package Math_Pk is new C3A0010_0 (Real_Num => Math_Float);
98
99 Math_Access : Math_Pk.Math_Procedure_Ptr;
100
101 Total_Num : Math_Float := 0.0;
102 First_Num : Math_Float := 1.0;
103 Second_Num : Math_Float := 2.0;
104
105 procedure Max( A_Num, B_Num: in Math_Float; Result : out Math_Float ) is
106 begin
107 if A_Num > B_Num then
108 Result := A_Num;
109 else
110 Result := B_Num;
111 end if;
112 end Max;
113
114 procedure Due_Process( Process: Math_Pk.Math_Procedure_Ptr ) is
115 begin
116 Process(First_Num, Second_Num, Total_Num);
117 end Due_Process;
118
119 begin
120
121 Report.Test ("C3A0010", "Check that an access-to-subprogram type in a "
122 & "generic instance may be used to declare "
123 & "access-to-subprogram objects which invoke "
124 & "subprograms in the instance");
125
126 -- Check for correct defaulting
127 if Math_Pk."/="( Math_Access, null) then
128 Report.Failed("subprogram access type object not initialized to null");
129 end if;
130
131 Math_Access := Math_Pk.Add'Access;
132
133 -- Invoking Add procedure designated by access value
134 Due_Process( Math_Access );
135
136 If Total_Num /= 3.0 then
137 Report.Failed ("Incorrect Add result");
138 end if;
139
140 Math_Access := Math_Pk.Subtract'Access;
141
142 Due_Process( Math_Access );
143
144 If Total_Num /= -1.0 then
145 Report.Failed ("Incorrect Subtract result");
146 end if;
147
148 Math_Access := Max'Access;
149
150 Due_Process( Math_Access );
151
152 If Total_Num /= 2.0 then
153 Report.Failed ("Incorrect Max result");
154 end if;
155
156 Report.Result;
157
158 end C3A0010;