summaryrefslogtreecommitdiff
path: root/gcc/testsuite/ada/acats/tests/cc/cc70003.a
blob: d2309fc3695099a14540a84644ed246279f29f6f (plain)
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
-- CC70003.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 the actual passed to a formal package may be a formal
--      access-to-subprogram type. Check that the visible part of the generic
--      formal package includes the first list of basic declarative items of
--      the package specification.
--
-- TEST DESCRIPTION:
--      Declare a list abstraction in a generic package which manages lists of
--      elements of any nonlimited type (foundation code). Declare a generic
--      package which supports the execution of lists of operations. Provide
--      the generic package with two formal parameters: (1) a formal access-
--      to-function type, and (2) a generic formal package with the list
--      abstraction package as template. Within a procedure declared in the
--      list-execution package, utilize information about the profile of
--      the functions in the list. Declare a package which declares functions
--      matching the profile of the formal access-to-subprogram type. In the
--      main program, create a list of pointers to the functions declared in
--      the package, instantiate the list abstraction and list-execution
--      packages, and use the list-execution procedure to call each of the
--      functions in the list in sequence.
--
--
-- CHANGE HISTORY:
--      06 Dec 94   SAIC    ACVC 2.0
--
--!

generic
   type Element_Type is private;
package CC70003_0 is  -- This package simulates a generic list abstraction.

   -- The definition of List_Type below is purely artificial; its validity
   -- in the context of the abstraction is irrelevant to the feature being
   -- tested.

   type Element_Ptr is access Element_Type;

   subtype List_Size is Natural range 1 .. 2;
   type List_Type is array (List_Size) of Element_Ptr;

   function  View_Element (I : List_Size; L : List_Type) return Element_Type;

   procedure Write_Element (I : in     List_Size;
                            L : in out List_Type;
                            E : in     Element_Type);

   -- ... Other list operations for Element_Type.

end CC70003_0;


     --==================================================================--


package body CC70003_0 is

   -- The implementations of the operations below are purely artificial; the
   -- validity of their implementations in the context of the abstraction is
   -- irrelevant to the feature being tested.

   function View_Element (I : List_Size; L : List_Type) return Element_Type is
   begin
      return L(I).all;
   end View_Element;


   procedure Write_Element (I : in     List_Size;
                            L : in out List_Type;
                            E : in     Element_Type) is
   begin
      L(I) := new Element_Type'(E);
   end Write_Element;

end CC70003_0;


     --==================================================================--


with CC70003_0;    -- Generic list abstraction.
generic
   type Elem_Type is access function (F : Float) return Float;
   with package List_Mgr is new CC70003_0 (Elem_Type);
package CC70003_1 is  -- This package simulates support for executing lists
                      -- of operations.

   procedure Execute_List (L : List_Mgr.List_Type; F : in out Float);

   -- ... Other operations.

end CC70003_1;


     --==================================================================--


package body CC70003_1 is

   procedure Execute_List (L : List_Mgr.List_Type; F : in out Float) is
   begin
      for I in L'Range loop
         F := List_Mgr.View_Element(I, L)(F);   -- Execute next operation in
      end loop;                                 -- list with current value of
   end Execute_List;                            -- F as operand.


end CC70003_1;


     --==================================================================--


package CC70003_2 is

   function Sine (F : Float) return Float;
   function Exp  (F : Float) return Float;

   -- ... Other math functions.

end CC70003_2;


     --==================================================================--


package body CC70003_2 is

   -- The implementations of the functions below are purely artificial; the
   -- validity of their implementations in the context of the abstraction is
   -- irrelevant to the feature being tested.

   function Sine (F : Float) return Float is
   begin
      return (-0.15);
   end Sine;

   function Exp (F : Float) return Float is
   begin
      if (F = 0.0) then
         return (-0.69);
      else
         return (2.0);  -- This branch should be taken.
      end if;
   end Exp;

end CC70003_2;


     --==================================================================--


with CC70003_0;    -- Generic list abstraction.
with CC70003_1;  -- Generic operation-list abstraction.
with CC70003_2;  -- Math library.

with Report;
procedure CC70003 is

   type Math_Op is access function (F : Float) return Float;

   package Math_Op_Lists        is new CC70003_0 (Math_Op);
   package Math_Op_List_Support is new CC70003_1 (Math_Op, Math_Op_Lists);

   Sin_Ptr : Math_Op := CC70003_2.Sine'Access;
   Exp_Ptr : Math_Op := CC70003_2.Exp'Access;

   Op_List : Math_Op_Lists.List_Type;

   Operand  : Float := 0.0;
   Expected : Float := 2.0;


begin
   Report.Test ("CC70003", "Check that the actual passed to a formal " &
                "package may be a formal access-to-subprogram type");

   Math_Op_Lists.Write_Element (1, Op_List, Sin_Ptr);
   Math_Op_Lists.Write_Element (2, Op_List, Exp_Ptr);

   Math_Op_List_Support.Execute_List (Op_List, Operand);

   if (Operand /= Expected) then
      Report.Failed ("Incorrect results from indirect function calls");
   end if;

   Report.Result;
end CC70003;