annotate gcc/testsuite/ada/acats/tests/cc/cc54003.a @ 111:04ced10e8804

gcc 7
author kono
date Fri, 27 Oct 2017 22:46:09 +0900
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
111
kono
parents:
diff changeset
1 -- CC54003.A
kono
parents:
diff changeset
2 --
kono
parents:
diff changeset
3 -- Grant of Unlimited Rights
kono
parents:
diff changeset
4 --
kono
parents:
diff changeset
5 -- Under contracts F33600-87-D-0337, F33600-84-D-0280, MDA903-79-C-0687,
kono
parents:
diff changeset
6 -- F08630-91-C-0015, and DCA100-97-D-0025, the U.S. Government obtained
kono
parents:
diff changeset
7 -- unlimited rights in the software and documentation contained herein.
kono
parents:
diff changeset
8 -- Unlimited rights are defined in DFAR 252.227-7013(a)(19). By making
kono
parents:
diff changeset
9 -- this public release, the Government intends to confer upon all
kono
parents:
diff changeset
10 -- recipients unlimited rights equal to those held by the Government.
kono
parents:
diff changeset
11 -- These rights include rights to use, duplicate, release or disclose the
kono
parents:
diff changeset
12 -- released technical data and computer software in whole or in part, in
kono
parents:
diff changeset
13 -- any manner and for any purpose whatsoever, and to have or permit others
kono
parents:
diff changeset
14 -- to do so.
kono
parents:
diff changeset
15 --
kono
parents:
diff changeset
16 -- DISCLAIMER
kono
parents:
diff changeset
17 --
kono
parents:
diff changeset
18 -- ALL MATERIALS OR INFORMATION HEREIN RELEASED, MADE AVAILABLE OR
kono
parents:
diff changeset
19 -- DISCLOSED ARE AS IS. THE GOVERNMENT MAKES NO EXPRESS OR IMPLIED
kono
parents:
diff changeset
20 -- WARRANTY AS TO ANY MATTER WHATSOEVER, INCLUDING THE CONDITIONS OF THE
kono
parents:
diff changeset
21 -- SOFTWARE, DOCUMENTATION OR OTHER INFORMATION RELEASED, MADE AVAILABLE
kono
parents:
diff changeset
22 -- OR DISCLOSED, OR THE OWNERSHIP, MERCHANTABILITY, OR FITNESS FOR A
kono
parents:
diff changeset
23 -- PARTICULAR PURPOSE OF SAID MATERIAL.
kono
parents:
diff changeset
24 --*
kono
parents:
diff changeset
25 --
kono
parents:
diff changeset
26 -- OBJECTIVE:
kono
parents:
diff changeset
27 -- Check that a general access-to-subprogram type may be passed as an
kono
parents:
diff changeset
28 -- actual to a generic formal access-to-subprogram type. Check that
kono
parents:
diff changeset
29 -- designated subprograms may be called by dereferencing the access
kono
parents:
diff changeset
30 -- values.
kono
parents:
diff changeset
31 --
kono
parents:
diff changeset
32 -- TEST DESCRIPTION:
kono
parents:
diff changeset
33 -- The generic implements a stack of access-to-subprogram objects as an
kono
parents:
diff changeset
34 -- array. The profile of the access-to-subprogram formal corresponds to
kono
parents:
diff changeset
35 -- a function which accepts a parameter of some type and returns an
kono
parents:
diff changeset
36 -- object of the same type.
kono
parents:
diff changeset
37 --
kono
parents:
diff changeset
38 -- For this test, the functions for which access values will be pushed
kono
parents:
diff changeset
39 -- onto the stack accept a parameter of type access-to-string, lengthen
kono
parents:
diff changeset
40 -- the pointed-to string, then return an access object pointing to this
kono
parents:
diff changeset
41 -- lengthened string.
kono
parents:
diff changeset
42 --
kono
parents:
diff changeset
43 -- The instance declares a function Execute_Stack which executes each
kono
parents:
diff changeset
44 -- subprogram on the stack in sequence. This function accepts some initial
kono
parents:
diff changeset
45 -- access-to-string, then returns an access object pointing to the
kono
parents:
diff changeset
46 -- lengthened string resulting from the execution of the stacked
kono
parents:
diff changeset
47 -- subprograms. Access-to-string objects are used rather than strings
kono
parents:
diff changeset
48 -- themselves because the initial string "grows" during each iteration.
kono
parents:
diff changeset
49 --
kono
parents:
diff changeset
50 --
kono
parents:
diff changeset
51 -- CHANGE HISTORY:
kono
parents:
diff changeset
52 -- 06 Dec 94 SAIC ACVC 2.0
kono
parents:
diff changeset
53 -- 10 Apr 96 SAIC ACVC 2.1: Added pragma Elaborate to context clause
kono
parents:
diff changeset
54 -- preceding CC54003_2.
kono
parents:
diff changeset
55 --
kono
parents:
diff changeset
56 --!
kono
parents:
diff changeset
57
kono
parents:
diff changeset
58 generic
kono
parents:
diff changeset
59
kono
parents:
diff changeset
60 Size : in Positive;
kono
parents:
diff changeset
61
kono
parents:
diff changeset
62 type Item_Type (<>) is private;
kono
parents:
diff changeset
63 type Item_Ptr is access Item_Type;
kono
parents:
diff changeset
64
kono
parents:
diff changeset
65 type Function_Ptr is access function (Item : Item_Ptr)
kono
parents:
diff changeset
66 return Item_Ptr;
kono
parents:
diff changeset
67
kono
parents:
diff changeset
68 package CC54003_0 is -- Generic stack of pointers.
kono
parents:
diff changeset
69
kono
parents:
diff changeset
70 type Stack_Type is private;
kono
parents:
diff changeset
71
kono
parents:
diff changeset
72 procedure Push (Stack : in out Stack_Type;
kono
parents:
diff changeset
73 Func_Ptr : in Function_Ptr);
kono
parents:
diff changeset
74
kono
parents:
diff changeset
75 function Execute_Stack (Stack : Stack_Type;
kono
parents:
diff changeset
76 Initial_Input : Item_Ptr) return Item_Ptr;
kono
parents:
diff changeset
77
kono
parents:
diff changeset
78 -- ... Other operations.
kono
parents:
diff changeset
79
kono
parents:
diff changeset
80 private
kono
parents:
diff changeset
81
kono
parents:
diff changeset
82 subtype Index is Positive range 1 .. (Size + 1);
kono
parents:
diff changeset
83 type Stack_Type is array (Index) of Function_Ptr; -- Last slot unused.
kono
parents:
diff changeset
84
kono
parents:
diff changeset
85 Top : Index := 1; -- Top refers to the next available slot.
kono
parents:
diff changeset
86
kono
parents:
diff changeset
87 end CC54003_0;
kono
parents:
diff changeset
88
kono
parents:
diff changeset
89
kono
parents:
diff changeset
90 --===================================================================--
kono
parents:
diff changeset
91
kono
parents:
diff changeset
92
kono
parents:
diff changeset
93 package body CC54003_0 is
kono
parents:
diff changeset
94
kono
parents:
diff changeset
95 procedure Push (Stack : in out Stack_Type;
kono
parents:
diff changeset
96 Func_Ptr : in Function_Ptr) is
kono
parents:
diff changeset
97 begin
kono
parents:
diff changeset
98 Stack(Top) := Func_Ptr;
kono
parents:
diff changeset
99 Top := Top + 1; -- Artificial: no Constraint_Error protection.
kono
parents:
diff changeset
100 end Push;
kono
parents:
diff changeset
101
kono
parents:
diff changeset
102
kono
parents:
diff changeset
103 -- Call each subprogram on the stack in sequence. For the first call, pass
kono
parents:
diff changeset
104 -- Initial_Input. For succeeding calls, pass the result of the previous
kono
parents:
diff changeset
105 -- call.
kono
parents:
diff changeset
106
kono
parents:
diff changeset
107 function Execute_Stack (Stack : Stack_Type;
kono
parents:
diff changeset
108 Initial_Input : Item_Ptr) return Item_Ptr is
kono
parents:
diff changeset
109 Result : Item_Ptr := Initial_Input;
kono
parents:
diff changeset
110 begin
kono
parents:
diff changeset
111 for I in reverse Index'First .. (Top - 1) loop -- Artificial: no C_E
kono
parents:
diff changeset
112 Result := Stack(I)(Result); -- protection.
kono
parents:
diff changeset
113 end loop;
kono
parents:
diff changeset
114 return Result;
kono
parents:
diff changeset
115 end Execute_Stack;
kono
parents:
diff changeset
116
kono
parents:
diff changeset
117 end CC54003_0;
kono
parents:
diff changeset
118
kono
parents:
diff changeset
119
kono
parents:
diff changeset
120 --===================================================================--
kono
parents:
diff changeset
121
kono
parents:
diff changeset
122
kono
parents:
diff changeset
123 package CC54003_1 is
kono
parents:
diff changeset
124
kono
parents:
diff changeset
125 subtype Message is String;
kono
parents:
diff changeset
126 type Message_Ptr is access Message;
kono
parents:
diff changeset
127
kono
parents:
diff changeset
128 function Add_Prefix (Msg_Ptr : Message_Ptr) return Message_Ptr;
kono
parents:
diff changeset
129 function Add_Suffix (Msg_Ptr : Message_Ptr) return Message_Ptr;
kono
parents:
diff changeset
130
kono
parents:
diff changeset
131 -- ...Other operations.
kono
parents:
diff changeset
132
kono
parents:
diff changeset
133 end CC54003_1;
kono
parents:
diff changeset
134
kono
parents:
diff changeset
135
kono
parents:
diff changeset
136 --===================================================================--
kono
parents:
diff changeset
137
kono
parents:
diff changeset
138
kono
parents:
diff changeset
139 package body CC54003_1 is
kono
parents:
diff changeset
140
kono
parents:
diff changeset
141 function Add_Prefix (Msg_Ptr : Message_Ptr) return Message_Ptr is
kono
parents:
diff changeset
142 Sender : constant String := "Dummy: "; -- Artificial; in a real
kono
parents:
diff changeset
143 -- application Sender might
kono
parents:
diff changeset
144 New_Msg : Message := Sender & Msg_Ptr.all; -- be a call to a function.
kono
parents:
diff changeset
145 begin
kono
parents:
diff changeset
146 return new Message'(New_Msg);
kono
parents:
diff changeset
147 end Add_Prefix;
kono
parents:
diff changeset
148
kono
parents:
diff changeset
149
kono
parents:
diff changeset
150 function Add_Suffix (Msg_Ptr : Message_Ptr) return Message_Ptr is
kono
parents:
diff changeset
151 Time : constant String := " (12:03pm)"; -- Artificial; in a real
kono
parents:
diff changeset
152 -- application Time might be a
kono
parents:
diff changeset
153 New_Msg : Message := Msg_Ptr.all & Time; -- be a call to a function.
kono
parents:
diff changeset
154 begin
kono
parents:
diff changeset
155 return new Message'(New_Msg);
kono
parents:
diff changeset
156 end Add_Suffix;
kono
parents:
diff changeset
157
kono
parents:
diff changeset
158 end CC54003_1;
kono
parents:
diff changeset
159
kono
parents:
diff changeset
160
kono
parents:
diff changeset
161 --===================================================================--
kono
parents:
diff changeset
162
kono
parents:
diff changeset
163
kono
parents:
diff changeset
164 with CC54003_0; -- Generic stack of pointers.
kono
parents:
diff changeset
165 pragma Elaborate (CC54003_0);
kono
parents:
diff changeset
166
kono
parents:
diff changeset
167 with CC54003_1; -- Message abstraction.
kono
parents:
diff changeset
168
kono
parents:
diff changeset
169 package CC54003_2 is
kono
parents:
diff changeset
170
kono
parents:
diff changeset
171 type Operation_Ptr is access function (Msg_Ptr : CC54003_1.Message_Ptr)
kono
parents:
diff changeset
172 return CC54003_1.Message_Ptr;
kono
parents:
diff changeset
173
kono
parents:
diff changeset
174 Maximum_Ops : constant := 4; -- Arbitrary.
kono
parents:
diff changeset
175
kono
parents:
diff changeset
176 package Stack_of_Ops is new CC54003_0
kono
parents:
diff changeset
177 (Item_Type => CC54003_1.Message,
kono
parents:
diff changeset
178 Item_Ptr => CC54003_1.Message_Ptr,
kono
parents:
diff changeset
179 Function_Ptr => Operation_Ptr,
kono
parents:
diff changeset
180 Size => Maximum_Ops);
kono
parents:
diff changeset
181
kono
parents:
diff changeset
182 Operation_Stack : Stack_Of_Ops.Stack_Type;
kono
parents:
diff changeset
183
kono
parents:
diff changeset
184
kono
parents:
diff changeset
185 procedure Create_Operation_Stack;
kono
parents:
diff changeset
186
kono
parents:
diff changeset
187 end CC54003_2;
kono
parents:
diff changeset
188
kono
parents:
diff changeset
189 --===================================================================--
kono
parents:
diff changeset
190
kono
parents:
diff changeset
191
kono
parents:
diff changeset
192 package body CC54003_2 is
kono
parents:
diff changeset
193
kono
parents:
diff changeset
194 procedure Create_Operation_Stack is
kono
parents:
diff changeset
195 begin
kono
parents:
diff changeset
196 Stack_Of_Ops.Push (Operation_Stack, CC54003_1.Add_Prefix'Access);
kono
parents:
diff changeset
197 Stack_Of_Ops.Push (Operation_Stack, CC54003_1.Add_Suffix'Access);
kono
parents:
diff changeset
198 end Create_Operation_Stack;
kono
parents:
diff changeset
199
kono
parents:
diff changeset
200 end CC54003_2;
kono
parents:
diff changeset
201
kono
parents:
diff changeset
202
kono
parents:
diff changeset
203 --===================================================================--
kono
parents:
diff changeset
204
kono
parents:
diff changeset
205
kono
parents:
diff changeset
206 with CC54003_1; -- Message abstraction.
kono
parents:
diff changeset
207 with CC54003_2; -- Message-operation stack.
kono
parents:
diff changeset
208
kono
parents:
diff changeset
209 with Report;
kono
parents:
diff changeset
210 procedure CC54003 is
kono
parents:
diff changeset
211
kono
parents:
diff changeset
212 package Msg_Ops renames CC54003_2.Stack_Of_Ops;
kono
parents:
diff changeset
213
kono
parents:
diff changeset
214 Msg : CC54003_1.Message_Ptr := new CC54003_1.Message'("Hello there");
kono
parents:
diff changeset
215 Expected : CC54003_1.Message := "Dummy: Hello there (12:03pm)";
kono
parents:
diff changeset
216
kono
parents:
diff changeset
217 begin
kono
parents:
diff changeset
218 Report.Test ("CC54003", "Check that a general access-to-subprogram type " &
kono
parents:
diff changeset
219 "may be passed as an actual to a generic formal " &
kono
parents:
diff changeset
220 "access-to-subprogram type");
kono
parents:
diff changeset
221
kono
parents:
diff changeset
222 CC54003_2.Create_Operation_Stack;
kono
parents:
diff changeset
223
kono
parents:
diff changeset
224 declare
kono
parents:
diff changeset
225 Actual : CC54003_1.Message_Ptr :=
kono
parents:
diff changeset
226 Msg_Ops.Execute_Stack (CC54003_2.Operation_Stack, Msg);
kono
parents:
diff changeset
227 begin
kono
parents:
diff changeset
228 if Actual.all /= Expected then
kono
parents:
diff changeset
229 Report.Failed ("Wrong result from dereferenced subprogram execution");
kono
parents:
diff changeset
230 end if;
kono
parents:
diff changeset
231 end;
kono
parents:
diff changeset
232
kono
parents:
diff changeset
233 Report.Result;
kono
parents:
diff changeset
234 end CC54003;