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
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
|
------------------------------------------------------------------------------
-- --
-- GNAT COMPILER COMPONENTS --
-- --
-- S Y S T E M . V A L U E _ U --
-- --
-- B o d y --
-- --
-- Copyright (C) 1992-2022, Free Software Foundation, Inc. --
-- --
-- GNAT is free software; you can redistribute it and/or modify it under --
-- terms of the GNU General Public License as published by the Free Soft- --
-- ware Foundation; either version 3, or (at your option) any later ver- --
-- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
-- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
-- or FITNESS FOR A PARTICULAR PURPOSE. --
-- --
-- As a special exception under Section 7 of GPL version 3, you are granted --
-- additional permissions described in the GCC Runtime Library Exception, --
-- version 3.1, as published by the Free Software Foundation. --
-- --
-- You should have received a copy of the GNU General Public License and --
-- a copy of the GCC Runtime Library Exception along with this program; --
-- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see --
-- <http://www.gnu.org/licenses/>. --
-- --
-- GNAT was originally developed by the GNAT team at New York University. --
-- Extensive contributions were provided by Ada Core Technologies Inc. --
-- --
------------------------------------------------------------------------------
package body System.Value_U is
-- Ghost code, loop invariants and assertions in this unit are meant for
-- analysis only, not for run-time checking, as it would be too costly
-- otherwise. This is enforced by setting the assertion policy to Ignore.
pragma Assertion_Policy (Ghost => Ignore,
Loop_Invariant => Ignore,
Assert => Ignore,
Assert_And_Cut => Ignore,
Subprogram_Variant => Ignore);
-- Local lemmas
procedure Lemma_Digit_Is_Before_Last
(Str : String;
P : Integer;
From : Integer;
To : Integer)
with Ghost,
Pre => Str'Last /= Positive'Last
and then From in Str'Range
and then To in From .. Str'Last
and then Str (From) in '0' .. '9' | 'a' .. 'f' | 'A' .. 'F'
and then P in From .. To
and then Str (P) in '0' .. '9' | 'a' .. 'f' | 'A' .. 'F',
Post => P /= Last_Hexa_Ghost (Str (From .. To)) + 1;
-- If the character at position P is a digit, P cannot be the position of
-- of the first non-digit in Str.
procedure Lemma_End_Of_Scan
(Str : String;
From : Integer;
To : Integer;
Base : Uns;
Acc : Uns)
with Ghost,
Pre => Str'Last /= Positive'Last and then From > To,
Post => Scan_Based_Number_Ghost (Str, From, To, Base, Acc) =
(False, Acc);
-- Unfold the definition of Scan_Based_Number_Ghost on an empty string
procedure Lemma_Scan_Digit
(Str : String;
P : Integer;
Lst : Integer;
Digit : Uns;
Base : Uns;
Old_Acc : Uns;
Acc : Uns;
Scan_Val : Uns_Option;
Old_Overflow : Boolean;
Overflow : Boolean)
with Ghost,
Pre => Str'Last /= Positive'Last
and then Lst in Str'Range
and then P in Str'First .. Lst
and then Str (P) in '0' .. '9' | 'a' .. 'f' | 'A' .. 'F'
and then Digit = Hexa_To_Unsigned_Ghost (Str (P))
and then Only_Hexa_Ghost (Str, P, Lst)
and then Base in 2 .. 16
and then (if Digit < Base and then Old_Acc <= Uns'Last / Base
then Acc = Base * Old_Acc + Digit)
and then (if Digit >= Base
or else Old_Acc > Uns'Last / Base
or else (Old_Acc > (Uns'Last - Base + 1) / Base
and then Acc < Uns'Last / Base)
then Overflow
else Overflow = Old_Overflow)
and then
(if not Old_Overflow then
Scan_Val = Scan_Based_Number_Ghost
(Str, P, Lst, Base, Old_Acc)),
Post =>
(if not Overflow then
Scan_Val = Scan_Based_Number_Ghost
(Str, P + 1, Lst, Base, Acc))
and then
(if Overflow then Old_Overflow or else Scan_Val.Overflow);
-- Unfold the definition of Scan_Based_Number_Ghost when the string starts
-- with a digit.
procedure Lemma_Scan_Underscore
(Str : String;
P : Integer;
From : Integer;
To : Integer;
Lst : Integer;
Base : Uns;
Acc : Uns;
Scan_Val : Uns_Option;
Overflow : Boolean;
Ext : Boolean)
with Ghost,
Pre => Str'Last /= Positive'Last
and then From in Str'Range
and then To in From .. Str'Last
and then Lst <= To
and then P in From .. Lst + 1
and then P <= To
and then
(if Ext then
Is_Based_Format_Ghost (Str (From .. To))
and then Lst = Last_Hexa_Ghost (Str (From .. To))
else Is_Natural_Format_Ghost (Str (From .. To))
and then Lst = Last_Number_Ghost (Str (From .. To)))
and then Str (P) = '_'
and then
(if not Overflow then
Scan_Val = Scan_Based_Number_Ghost (Str, P, Lst, Base, Acc)),
Post => P + 1 <= Lst
and then
(if Ext then Str (P + 1) in '0' .. '9' | 'a' .. 'f' | 'A' .. 'F'
else Str (P + 1) in '0' .. '9')
and then
(if not Overflow then
Scan_Val = Scan_Based_Number_Ghost (Str, P + 1, Lst, Base, Acc));
-- Unfold the definition of Scan_Based_Number_Ghost when the string starts
-- with an underscore.
-----------------------------
-- Local lemma null bodies --
-----------------------------
procedure Lemma_Digit_Is_Before_Last
(Str : String;
P : Integer;
From : Integer;
To : Integer)
is null;
procedure Lemma_End_Of_Scan
(Str : String;
From : Integer;
To : Integer;
Base : Uns;
Acc : Uns)
is null;
procedure Lemma_Scan_Underscore
(Str : String;
P : Integer;
From : Integer;
To : Integer;
Lst : Integer;
Base : Uns;
Acc : Uns;
Scan_Val : Uns_Option;
Overflow : Boolean;
Ext : Boolean)
is null;
---------------------
-- Last_Hexa_Ghost --
---------------------
function Last_Hexa_Ghost (Str : String) return Positive is
begin
for J in Str'Range loop
if Str (J) not in '0' .. '9' | 'a' .. 'f' | 'A' .. 'F' | '_' then
return J - 1;
end if;
pragma Loop_Invariant
(for all K in Str'First .. J =>
Str (K) in '0' .. '9' | 'a' .. 'f' | 'A' .. 'F' | '_');
end loop;
return Str'Last;
end Last_Hexa_Ghost;
----------------------
-- Lemma_Scan_Digit --
----------------------
procedure Lemma_Scan_Digit
(Str : String;
P : Integer;
Lst : Integer;
Digit : Uns;
Base : Uns;
Old_Acc : Uns;
Acc : Uns;
Scan_Val : Uns_Option;
Old_Overflow : Boolean;
Overflow : Boolean)
is
pragma Unreferenced (Str, P, Lst, Scan_Val, Overflow, Old_Overflow);
begin
if Digit >= Base then
null;
elsif Old_Acc <= (Uns'Last - Base + 1) / Base then
pragma Assert (not Scan_Overflows_Ghost (Digit, Base, Old_Acc));
elsif Old_Acc > Uns'Last / Base then
null;
else
pragma Assert
((Acc < Uns'Last / Base) =
Scan_Overflows_Ghost (Digit, Base, Old_Acc));
end if;
end Lemma_Scan_Digit;
-----------------------
-- Scan_Raw_Unsigned --
-----------------------
procedure Scan_Raw_Unsigned
(Str : String;
Ptr : not null access Integer;
Max : Integer;
Res : out Uns)
is
P : Integer;
-- Local copy of the pointer
Uval : Uns;
-- Accumulated unsigned integer result
Expon : Integer;
-- Exponent value
Overflow : Boolean := False;
-- Set True if overflow is detected at any point
Base_Char : Character;
-- Base character (# or :) in based case
Base : Uns := 10;
-- Base value (reset in based case)
Digit : Uns;
-- Digit value
Ptr_Old : constant Integer := Ptr.all
with Ghost;
Last_Num_Init : constant Integer :=
Last_Number_Ghost (Str (Ptr.all .. Max))
with Ghost;
Init_Val : constant Uns_Option :=
Scan_Based_Number_Ghost (Str, Ptr.all, Last_Num_Init)
with Ghost;
Starts_As_Based : constant Boolean :=
Last_Num_Init < Max - 1
and then Str (Last_Num_Init + 1) in '#' | ':'
and then Str (Last_Num_Init + 2) in
'0' .. '9' | 'a' .. 'f' | 'A' .. 'F'
with Ghost;
Last_Num_Based : constant Integer :=
(if Starts_As_Based
then Last_Hexa_Ghost (Str (Last_Num_Init + 2 .. Max))
else Last_Num_Init)
with Ghost;
Is_Based : constant Boolean :=
Starts_As_Based
and then Last_Num_Based < Max
and then Str (Last_Num_Based + 1) = Str (Last_Num_Init + 1)
with Ghost;
Based_Val : constant Uns_Option :=
(if Starts_As_Based and then not Init_Val.Overflow
then Scan_Based_Number_Ghost
(Str, Last_Num_Init + 2, Last_Num_Based, Init_Val.Value)
else Init_Val)
with Ghost;
First_Exp : constant Integer :=
(if Is_Based then Last_Num_Based + 2 else Last_Num_Init + 1)
with Ghost;
begin
-- We do not tolerate strings with Str'Last = Positive'Last
if Str'Last = Positive'Last then
raise Program_Error with
"string upper bound is Positive'Last, not supported";
end if;
P := Ptr.all;
Uval := Character'Pos (Str (P)) - Character'Pos ('0');
P := P + 1;
-- Scan out digits of what is either the number or the base.
-- In either case, we are definitely scanning out in base 10.
declare
Umax : constant Uns := (Uns'Last - 9) / 10;
-- Max value which cannot overflow on accumulating next digit
Umax10 : constant Uns := Uns'Last / 10;
-- Numbers bigger than Umax10 overflow if multiplied by 10
Old_Uval : Uns with Ghost;
Old_Overflow : Boolean with Ghost;
begin
-- Loop through decimal digits
loop
pragma Loop_Invariant (P in P'Loop_Entry .. Last_Num_Init + 1);
pragma Loop_Invariant
(if Overflow then Init_Val.Overflow);
pragma Loop_Invariant
(if not Overflow
then Init_Val = Scan_Based_Number_Ghost
(Str, P, Last_Num_Init, Acc => Uval));
exit when P > Max;
Digit := Character'Pos (Str (P)) - Character'Pos ('0');
-- Non-digit encountered
if Digit > 9 then
if Str (P) = '_' then
Lemma_Scan_Underscore
(Str, P, Ptr_Old, Max, Last_Num_Init, 10, Uval,
Init_Val, Overflow, False);
Scan_Underscore (Str, P, Ptr, Max, False);
else
exit;
end if;
-- Accumulate result, checking for overflow
else
Old_Uval := Uval;
Old_Overflow := Overflow;
if Uval <= Umax then
Uval := 10 * Uval + Digit;
elsif Uval > Umax10 then
Overflow := True;
else
Uval := 10 * Uval + Digit;
if Uval < Umax10 then
Overflow := True;
end if;
end if;
Lemma_Scan_Digit
(Str, P, Last_Num_Init, Digit, 10, Old_Uval, Uval, Init_Val,
Old_Overflow, Overflow);
P := P + 1;
end if;
end loop;
pragma Assert (P = Last_Num_Init + 1);
pragma Assert (Init_Val.Overflow = Overflow);
end;
pragma Assert_And_Cut
(P = Last_Num_Init + 1
and then Overflow = Init_Val.Overflow
and then (if not Overflow then Init_Val.Value = Uval));
Ptr.all := P;
-- Deal with based case. We recognize either the standard '#' or the
-- allowed alternative replacement ':' (see RM J.2(3)).
if P < Max and then (Str (P) = '#' or else Str (P) = ':') then
Base_Char := Str (P);
P := P + 1;
Base := Uval;
Uval := 0;
-- Check base value. Overflow is set True if we find a bad base, or
-- a digit that is out of range of the base. That way, we scan out
-- the numeral that is still syntactically correct, though illegal.
-- We use a safe base of 16 for this scan, to avoid zero divide.
if Base not in 2 .. 16 then
Overflow := True;
Base := 16;
end if;
-- Scan out based integer
declare
Umax : constant Uns := (Uns'Last - Base + 1) / Base;
-- Max value which cannot overflow on accumulating next digit
UmaxB : constant Uns := Uns'Last / Base;
-- Numbers bigger than UmaxB overflow if multiplied by base
Old_Uval : Uns with Ghost;
Old_Overflow : Boolean with Ghost;
begin
pragma Assert
(if Str (P) in '0' .. '9' | 'A' .. 'F' | 'a' .. 'f'
then Is_Based_Format_Ghost (Str (P .. Max)));
-- Loop to scan out based integer value
loop
-- We require a digit at this stage
if Str (P) in '0' .. '9' then
Digit := Character'Pos (Str (P)) - Character'Pos ('0');
elsif Str (P) in 'A' .. 'F' then
Digit :=
Character'Pos (Str (P)) - (Character'Pos ('A') - 10);
elsif Str (P) in 'a' .. 'f' then
Digit :=
Character'Pos (Str (P)) - (Character'Pos ('a') - 10);
-- If we don't have a digit, then this is not a based number
-- after all, so we use the value we scanned out as the base
-- (now in Base), and the pointer to the base character was
-- already stored in Ptr.all.
else
Uval := Base;
Base := 10;
pragma Assert (Ptr.all = Last_Num_Init + 1);
pragma Assert (if not Overflow then Uval = Init_Val.Value);
exit;
end if;
Lemma_Digit_Is_Before_Last (Str, P, Last_Num_Init + 2, Max);
pragma Loop_Invariant (P in P'Loop_Entry .. Last_Num_Based);
pragma Loop_Invariant
(Str (P) in '0' .. '9' | 'a' .. 'f' | 'A' .. 'F'
and then Digit = Hexa_To_Unsigned_Ghost (Str (P)));
pragma Loop_Invariant
(if Overflow'Loop_Entry then Overflow);
pragma Loop_Invariant
(if Overflow then
Overflow'Loop_Entry or else Based_Val.Overflow);
pragma Loop_Invariant
(if not Overflow
then Based_Val = Scan_Based_Number_Ghost
(Str, P, Last_Num_Based, Base, Uval));
pragma Loop_Invariant (Ptr.all = Last_Num_Init + 1);
Old_Uval := Uval;
Old_Overflow := Overflow;
-- If digit is too large, just signal overflow and continue.
-- The idea here is to keep scanning as long as the input is
-- syntactically valid, even if we have detected overflow
if Digit >= Base then
Overflow := True;
-- Here we accumulate the value, checking overflow
elsif Uval <= Umax then
Uval := Base * Uval + Digit;
elsif Uval > UmaxB then
Overflow := True;
else
Uval := Base * Uval + Digit;
if Uval < UmaxB then
Overflow := True;
end if;
end if;
Lemma_Scan_Digit
(Str, P, Last_Num_Based, Digit, Base, Old_Uval, Uval,
Based_Val, Old_Overflow, Overflow);
-- If at end of string with no base char, not a based number
-- but we signal Constraint_Error and set the pointer past
-- the end of the field, since this is what the ACVC tests
-- seem to require, see CE3704N, line 204.
P := P + 1;
if P > Max then
Ptr.all := P;
Bad_Value (Str);
end if;
-- If terminating base character, we are done with loop
if Str (P) = Base_Char then
Ptr.all := P + 1;
pragma Assert (Ptr.all = Last_Num_Based + 2);
Lemma_End_Of_Scan (Str, P, Last_Num_Based, Base, Uval);
pragma Assert (if not Overflow then Uval = Based_Val.Value);
exit;
-- Deal with underscore
elsif Str (P) = '_' then
Lemma_Scan_Underscore
(Str, P, Last_Num_Init + 2, Max, Last_Num_Based, Base,
Uval, Based_Val, Overflow, True);
Scan_Underscore (Str, P, Ptr, Max, True);
pragma Assert
(if not Overflow
then Based_Val = Scan_Based_Number_Ghost
(Str, P, Last_Num_Based, Base, Uval));
end if;
end loop;
end;
pragma Assert
(if Starts_As_Based then P = Last_Num_Based + 1
else P = Last_Num_Init + 2);
pragma Assert
(Overflow =
(Init_Val.Overflow
or else Init_Val.Value not in 2 .. 16
or else (Starts_As_Based and then Based_Val.Overflow)));
end if;
pragma Assert_And_Cut
(Overflow =
(Init_Val.Overflow
or else
(Last_Num_Init < Max - 1
and then Str (Last_Num_Init + 1) in '#' | ':'
and then Init_Val.Value not in 2 .. 16)
or else (Starts_As_Based and then Based_Val.Overflow))
and then
(if not Overflow then
(if Is_Based then Uval = Based_Val.Value
else Uval = Init_Val.Value))
and then Ptr.all = First_Exp
and then Base in 2 .. 16
and then
(if not Overflow then
(if Is_Based then Base = Init_Val.Value else Base = 10)));
-- Come here with scanned unsigned value in Uval. The only remaining
-- required step is to deal with exponent if one is present.
Scan_Exponent (Str, Ptr, Max, Expon);
pragma Assert
(if Starts_As_Exponent_Format_Ghost (Str (First_Exp .. Max))
then Expon = Scan_Exponent_Ghost (Str (First_Exp .. Max)));
if Expon /= 0 and then Uval /= 0 then
-- For non-zero value, scale by exponent value. No need to do this
-- efficiently, since use of exponent in integer literals is rare,
-- and in any case the exponent cannot be very large.
declare
UmaxB : constant Uns := Uns'Last / Base;
-- Numbers bigger than UmaxB overflow if multiplied by base
Res_Val : constant Uns_Option :=
Exponent_Unsigned_Ghost (Uval, Expon, Base)
with Ghost;
begin
for J in 1 .. Expon loop
pragma Loop_Invariant
(if Overflow'Loop_Entry then Overflow);
pragma Loop_Invariant
(if Overflow
then Overflow'Loop_Entry or else Res_Val.Overflow);
pragma Loop_Invariant
(if not Overflow
then Res_Val = Exponent_Unsigned_Ghost
(Uval, Expon - J + 1, Base));
pragma Assert
((Uval > UmaxB) = Scan_Overflows_Ghost (0, Base, Uval));
if Uval > UmaxB then
Overflow := True;
exit;
end if;
Uval := Uval * Base;
end loop;
pragma Assert
(Overflow = (Init_Val.Overflow
or else
(Last_Num_Init < Max - 1
and then Str (Last_Num_Init + 1) in '#' | ':'
and then Init_Val.Value not in 2 .. 16)
or else (Starts_As_Based and then Based_Val.Overflow)
or else Res_Val.Overflow));
pragma Assert
(Overflow = Raw_Unsigned_Overflows_Ghost (Str, Ptr_Old, Max));
pragma Assert
(Exponent_Unsigned_Ghost (Uval, 0, Base) = (False, Uval));
pragma Assert
(if not Overflow then Uval = Res_Val.Value);
pragma Assert
(if not Overflow then
Uval = Scan_Raw_Unsigned_Ghost (Str, Ptr_Old, Max));
end;
end if;
pragma Assert
(if Expon = 0 or else Uval = 0 then
Exponent_Unsigned_Ghost (Uval, Expon, Base) = (False, Uval));
pragma Assert
(Overflow = Raw_Unsigned_Overflows_Ghost (Str, Ptr_Old, Max));
pragma Assert
(if not Overflow then
Uval = Scan_Raw_Unsigned_Ghost (Str, Ptr_Old, Max));
-- Return result, dealing with overflow
if Overflow then
Bad_Value (Str);
pragma Annotate
(GNATprove, Intentional,
"call to nonreturning subprogram might be executed",
"it is expected that Constraint_Error is raised in case of"
& " overflow");
else
Res := Uval;
end if;
end Scan_Raw_Unsigned;
-------------------
-- Scan_Unsigned --
-------------------
procedure Scan_Unsigned
(Str : String;
Ptr : not null access Integer;
Max : Integer;
Res : out Uns)
is
Start : Positive;
-- Save location of first non-blank character
begin
pragma Warnings
(Off,
"""Start"" is set by ""Scan_Plus_Sign"" but not used after the call");
Scan_Plus_Sign (Str, Ptr, Max, Start);
pragma Warnings
(On,
"""Start"" is set by ""Scan_Plus_Sign"" but not used after the call");
if Str (Ptr.all) not in '0' .. '9' then
Ptr.all := Start;
Bad_Value (Str);
end if;
Scan_Raw_Unsigned (Str, Ptr, Max, Res);
end Scan_Unsigned;
--------------------
-- Value_Unsigned --
--------------------
function Value_Unsigned (Str : String) return Uns is
begin
-- We have to special case Str'Last = Positive'Last because the normal
-- circuit ends up setting P to Str'Last + 1 which is out of bounds. We
-- deal with this by converting to a subtype which fixes the bounds.
if Str'Last = Positive'Last then
declare
subtype NT is String (1 .. Str'Length);
begin
return Value_Unsigned (NT (Str));
end;
-- Normal case where Str'Last < Positive'Last
else
declare
V : Uns;
P : aliased Integer := Str'First;
Non_Blank : constant Positive := First_Non_Space_Ghost
(Str, Str'First, Str'Last)
with Ghost;
Fst_Num : constant Positive :=
(if Str (Non_Blank) = '+' then Non_Blank + 1 else Non_Blank)
with Ghost;
begin
pragma Assert
(Is_Raw_Unsigned_Format_Ghost (Str (Fst_Num .. Str'Last)));
declare
P_Acc : constant not null access Integer := P'Access;
begin
Scan_Unsigned (Str, P_Acc, Str'Last, V);
end;
pragma Assert
(P = Raw_Unsigned_Last_Ghost (Str, Fst_Num, Str'Last));
pragma Assert
(V = Scan_Raw_Unsigned_Ghost (Str, Fst_Num, Str'Last));
Scan_Trailing_Blanks (Str, P);
pragma Assert
(Is_Value_Unsigned_Ghost (Slide_If_Necessary (Str), V));
return V;
end;
end if;
end Value_Unsigned;
end System.Value_U;
|