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
|
-- C490003.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 a static expression is legal if its evaluation fails
-- no language-defined check other than Overflow_Check. Check that such
-- a static expression is legal if it is part of a larger static
-- expression, even if its value is outside the base range of the
-- expected type.
--
-- Check that if a static expression is part of the right operand of a
-- short circuit control form whose value is determined by its left
-- operand, it is not evaluated.
--
-- Check that a static expression in a non-static context is evaluated
-- exactly.
--
-- TEST DESCRIPTION:
-- The first part of the objective is tested by constructing static
-- expressions which involve predefined operations of integer, floating
-- point, and fixed point subtypes. Intermediate expressions within the
-- static expressions have values outside the base range of the expected
-- type. In one case, the extended-range intermediates are compared as
-- part of a boolean expression. In the remaining two cases, further
-- predefined operations on the intermediates bring the final result
-- within the base range. An implementation which compiles these static
-- expressions satisfies this portion of the objective. A check is
-- performed at run-time to ensure that the static expressions evaluate
-- to values within the base range of their respective expected types.
--
-- The second part of the objective is tested by constructing
-- short-circuit control forms whose left operands have the values
-- shown below:
--
-- (TRUE) or else (...)
-- (FALSE) and then (...)
--
-- In both cases the left operand determines the value of the condition.
-- In the test each right operand involves a division by zero, which will
-- raise Constraint_Error if evaluated. A check is made that no exception
-- is raised when each short-circuit control form is evaluated, and that
-- the value of the condition is that of the left operand.
--
-- The third part of the objective is tested by evaluating static
-- expressions involving many operations in contexts which do not
-- require a static expression, and verifying that the exact
-- mathematical results are calculated.
--
--
-- CHANGE HISTORY:
-- 15 Sep 95 SAIC Initial prerelease version for ACVC 2.1.
-- 20 Oct 96 SAIC Modified expressions in C490003_0 to avoid
-- the use of universal operands.
--
--!
with System;
package C490003_0 is
type My_Flt is digits System.Max_Digits;
Flt_Range_Diff : My_Flt := (My_Flt'Base'Last - My_Flt'Base'First) -
(My_Flt'Last - My_Flt'First); -- OK.
type My_Fix is delta 0.125 range -128.0 .. 128.0;
Symmetric : Boolean := (My_Fix'Base'Last - My_Fix'Base'First) =
(My_Fix'Base'Last + My_Fix'Base'Last); -- OK.
Center : constant Integer := Integer'Base'Last -
(Integer'Base'Last -
Integer'Base'First) / 2; -- OK.
end C490003_0;
--==================================================================--
with Ada.Numerics;
package C490003_1 is
Zero : constant := 0.0;
Pi : constant := Ada.Numerics.Pi;
Two_Pi : constant := 2.0 * Pi;
Half_Pi : constant := Pi/2.0;
Quarter : constant := 90.0;
Half : constant := 180.0;
Full : constant := 360.0;
Deg_To_Rad : constant := Half_Pi/90;
Rad_To_Deg : constant := 1.0/Deg_To_Rad;
end C490003_1;
--==================================================================--
with C490003_0;
with C490003_1;
with Report;
procedure C490003 is
begin
Report.Test ("C490003", "Check that static expressions failing " &
"Overflow_Check are legal if part of a larger static " &
"expression. Check that static expressions as right " &
"operands of short-circuit control forms are not " &
"evaluated if value of control form is determined by " &
"left operand. Check that static expressions in non-static " &
"contexts are evaluated exactly");
--
-- Static expressions within larger static expressions:
--
if C490003_0.Flt_Range_Diff not in C490003_0.My_Flt'Base'Range then
Report.Failed ("Error evaluating static expression: floating point");
end if;
if C490003_0.Symmetric not in Boolean'Range then
Report.Failed ("Error evaluating static expression: fixed point");
end if;
if C490003_0.Center not in Integer'Base'Range then
Report.Failed ("Error evaluating static expression: integer");
end if;
--
-- Short-circuit control forms:
--
declare
N : constant := 0.0;
begin
begin
if not ( (N = 0.0) or else (1.0/N > 0.5) ) then
Report.Failed ("Error evaluating OR ELSE");
end if;
exception
when Constraint_Error =>
Report.Failed ("Right side of OR ELSE was evaluated");
when others =>
Report.Failed ("OR ELSE: unexpected exception raised");
end;
begin
if (N /= 0.0) and then (1.0/N <= 0.5) then
Report.Failed ("Error evaluating AND THEN");
end if;
exception
when Constraint_Error =>
Report.Failed ("Right side of AND THEN was evaluated");
when others =>
Report.Failed ("AND THEN: unexpected exception raised");
end;
end;
--
-- Exact evaluation of static expressions:
--
declare
use C490003_1;
Left : constant := 6.0 + 0.3125*( (Full*0.375) + (Half/2.4) -
((Quarter + 36.0)/3.0) )/10.0; -- 11.25
Right : constant := (Pi/3.0) * 1.2 * (15.0/96.0); -- Pi/16
begin
if Deg_To_Rad*Left /= Right then
Report.Failed ("Static expressions not evaluated exactly: #1");
end if;
if ((Pi*Rad_To_Deg)*2.0 + 4.0*Quarter)/16.0 /= Rad_To_Deg*(Pi/4.0) then
Report.Failed ("Static expressions not evaluated exactly: #2");
end if;
end;
Report.Result;
end C490003;
|