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
|
-- C851002.A
--
-- Grant of Unlimited Rights
--
-- The Ada Conformity Assessment Authority (ACAA) holds unlimited
-- rights in the software and documentation contained herein. Unlimited
-- rights are the same as those granted by the U.S. Government for older
-- parts of the Ada Conformity Assessment Test Suite, and are defined
-- in DFAR 252.227-7013(a)(19). By making this public release, the ACAA
-- intends to confer upon all recipients unlimited rights equal to those
-- held by the ACAA. 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 ACAA 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.
--
-- Notice
--
-- The ACAA has created and maintains the Ada Conformity Assessment Test
-- Suite for the purpose of conformity assessments conducted in accordance
-- with the International Standard ISO/IEC 18009 - Ada: Conformity
-- assessment of a language processor. This test suite should not be used
-- to make claims of conformance unless used in accordance with
-- ISO/IEC 18009 and any applicable ACAA procedures.
--*
-- OBJECTIVE:
-- For an object renaming with an anonymous access type, check that the
-- name is resolved if there is only one interpretation with a correct
-- anonymous access type, even if other interpretations exist.
--
-- TEST DESCRIPTION:
-- The test defines a number of record types with identically named
-- components and various overloaded accessor functions. This models
-- all of these record types being placed into containers in the
-- same package. We then try to rename various components, and
-- verify that that succeeds.
--
-- The rule tested by this test was confirmed by AI05-0105-1, in
-- particular the case represented by type Not_Right_3. Note
-- that since it is impossible to qualify an anonymous access type,
-- renames like these are an important way to disambiguate overloaded
-- calls.
--
-- CHANGE HISTORY:
-- 21 Jul 2008 RLB Created test.
--
package C851002_A is
Aux : aliased Integer := 99;
function Double (X : Float) return Float;
type Expected is record -- This is the type we expect to resolve to.
Comp1 : access Integer := Aux'Access;
Comp2 : access function (X : Float) return Float := Double'Access;
-- Other (differently named) components in a real type.
end record;
function Element1 (Cursor : Natural) return Expected;
function Element2 (Cursor : Natural) return Expected;
function Element3 (Cursor : Natural) return Expected;
type Not_Right_1 is record -- This is a type with components with completely
-- different types.
Comp1 : Float := 92.0;
Comp2 : String(1..5) := "12345";
-- Other (differently named) components in a real type.
end record;
function Element1 (Cursor : Natural) return Not_Right_1;
type Not_Right_2 is record -- This is a type with components with access
-- types with the wrong designated type/profile.
Comp1 : access Float;
Comp2 : access function return Natural;
-- Other (differently named) components in a real type.
end record;
function Element2 (Cursor : Natural) return Not_Right_2;
type Int_Ptr is access all Integer;
type Func_Ptr is access function (X : Float) return Float;
type Not_Right_3 is record -- This is a type with components with named
-- access types with the correct characteristics.
Comp1 : Int_Ptr := Aux'Access;
Comp2 : Func_Ptr := Double'Access;
-- Other (differently named) components in a real type.
end record;
function Element3 (Cursor : Natural) return Not_Right_3;
end C851002_A;
with Report;
package body C851002_A is
Auxf : aliased Float := 4.0;
function Double (X : Float) return Float is
begin
return X * 2.0;
end Double;
function Element1 (Cursor : Natural) return Expected is
begin
return (others => <>);
end Element1;
function Element2 (Cursor : Natural) return Expected is
begin
return (others => <>);
end Element2;
function Element3 (Cursor : Natural) return Expected is
begin
return (others => <>);
end Element3;
function Element1 (Cursor : Natural) return Not_Right_1 is
begin
Report.Failed ("Wrong Element1 routine called -" & Natural'Image(Cursor));
return (others => <>);
end Element1;
function Element2 (Cursor : Natural) return Not_Right_2 is
begin
Report.Failed ("Wrong Element2 routine called -" & Natural'Image(Cursor));
return (others => <>);
end Element2;
function Element3 (Cursor : Natural) return Not_Right_3 is
begin
Report.Failed ("Wrong Element3 routine called -" & Natural'Image(Cursor));
return (others => <>);
end Element3;
end C851002_A;
with Report;
with C851002_A; use C851002_A;
procedure C851002 is
procedure Use_It_1 (Obj : access Integer) is
-- Use Obj so that the compiler cannot remove the actual from
-- the program as a dead object.
begin
if Obj = null then
null;
elsif not Report.Equal (Obj.all, Obj.all) then
Report.Comment ("Don't optimize Obj");
end if;
end Use_It_1;
procedure Use_It_2 (Obj : access function (X : Float) return Float) is
-- Use Obj so that the compiler cannot remove the actual from
-- the program as a dead object.
begin
if Obj = null then
null;
elsif Report.Equal (Integer(Obj(2.0)), 0) then
Report.Comment ("Don't optimize Obj");
end if;
end Use_It_2;
begin
Report.Test ("C851002", "For an object renaming with an anonymous " &
"access type, check that the name is resolved " &
"if there is only one interpretation with a " &
"correct anonymous access type, even if other " &
"interpretations exist");
declare
Ren1 : access Integer renames Element1(1).Comp1;
begin
if Ren1.all /= C851002_A.Aux then
Report.Failed ("Wrong value (1)");
end if;
Use_It_1 (Ren1);
end;
declare
Ren2 : access function (X : Float) return Float renames Element1(2).Comp2;
begin
if Ren2.all(2.0) /= 4.0 then
Report.Failed ("Wrong value (2)");
end if;
Use_It_2 (Ren2);
end;
declare
Ren3 : access Integer renames Element2(3).Comp1;
begin
if Ren3.all /= C851002_A.Aux then
Report.Failed ("Wrong value (3)");
end if;
Use_It_1 (Ren3);
end;
declare
Ren4 : access function (X : Float) return Float renames Element2(4).Comp2;
begin
if Ren4.all(2.0) /= 4.0 then
Report.Failed ("Wrong value (4)");
end if;
Use_It_2 (Ren4);
end;
declare
Ren5 : access Integer renames Element3(5).Comp1;
begin
if Ren5.all /= C851002_A.Aux then
Report.Failed ("Wrong value (5)");
end if;
Use_It_1 (Ren5);
end;
declare
Ren6 : access function (X : Float) return Float renames Element3(6).Comp2;
begin
if Ren6.all(2.0) /= 4.0 then
Report.Failed ("Wrong value (6)");
end if;
Use_It_2 (Ren6);
end;
Report.Result;
end C851002;
|