Debian Codegraph @

gcc/ada/libgnat/s-imagei.ads

raw
1 ------------------------------------------------------------------------------
2 -- --
3 -- GNAT RUN-TIME COMPONENTS --
4 -- --
5 -- S Y S T E M . I M A G E _ I --
6 -- --
7 -- S p e c --
8 -- --
9 -- Copyright (C) 1992-2025, Free Software Foundation, Inc. --
10 -- --
11 -- GNAT is free software; you can redistribute it and/or modify it under --
12 -- terms of the GNU General Public License as published by the Free Soft- --
13 -- ware Foundation; either version 3, or (at your option) any later ver- --
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
16 -- or FITNESS FOR A PARTICULAR PURPOSE. --
17 -- --
18 -- As a special exception under Section 7 of GPL version 3, you are granted --
19 -- additional permissions described in the GCC Runtime Library Exception, --
20 -- version 3.1, as published by the Free Software Foundation. --
21 -- --
22 -- You should have received a copy of the GNU General Public License and --
23 -- a copy of the GCC Runtime Library Exception along with this program; --
24 -- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see --
25 -- <http://www.gnu.org/licenses/>. --
26 -- --
27 -- GNAT was originally developed by the GNAT team at New York University. --
28 -- Extensive contributions were provided by Ada Core Technologies Inc. --
29 -- --
30 ------------------------------------------------------------------------------
31
32 -- This package provides the subprograms supporting the ``Image`` attribute
33 -- and ``Ada.Text_IO.Integer_IO`` conversions routines for signed integer
34 -- types.
35
36 -- Preconditions in this unit are meant for analysis only, not for run-time
37 -- checking, so that the expected exceptions are raised. This is enforced by
38 -- setting the corresponding assertion policy to Ignore. Postconditions and
39 -- contract cases should not be executed at runtime as well, in order not to
40 -- slow down the execution of these functions.
41
42 pragma Assertion_Policy (Pre => Ignore,
43 Post => Ignore,
44 Contract_Cases => Ignore,
45 Ghost => Ignore,
46 Subprogram_Variant => Ignore);
47
48 with System.Value_I_Spec;
49 with System.Value_U_Spec;
50
51 generic
52 type Int is range <>;
53 type Uns is mod <>;
54
55 -- Additional parameters for ghost subprograms used inside contracts
56
57 with package U_Spec is new System.Value_U_Spec (Uns => Uns) with Ghost;
58 with package I_Spec is new System.Value_I_Spec
59 (Int => Int, Uns => Uns, U_Spec => U_Spec) with Ghost;
60
61 package System.Image_I is
62 package IP renames I_Spec;
63 package UP renames U_Spec;
64 use type UP.Uns_Option;
65
66 Unsigned_Width_Ghost : constant Natural := U_Spec.Max_Log10 + 2 with Ghost;
67
68 procedure Image_Integer
69 (V : Int;
70 S : in out String;
71 P : out Natural)
72 with
73 Pre => S'First = 1
74 and then S'Last < Integer'Last
75 and then S'Last >= Unsigned_Width_Ghost,
76 Post => P in S'Range
77 and then IP.Is_Value_Integer_Ghost (S (1 .. P), V);
78 -- Computes Int'Image (V) and stores the result in S (1 .. P)
79 -- setting the resulting value of P. The caller guarantees that S
80 -- is long enough to hold the result, and that S'First is 1.
81
82 procedure Set_Image_Integer
83 (V : Int;
84 S : in out String;
85 P : in out Natural)
86 with
87 Pre => P < Integer'Last
88 and then S'Last < Integer'Last
89 and then S'First <= P + 1
90 and then S'First <= S'Last
91 and then
92 (if V >= 0 then
93 P <= S'Last - Unsigned_Width_Ghost + 1
94 else
95 P <= S'Last - Unsigned_Width_Ghost),
96 Post => S (S'First .. P'Old) = S'Old (S'First .. P'Old)
97 and then
98 (declare
99 Minus : constant Boolean := S (P'Old + 1) = '-';
100 Offset : constant Positive := (if V >= 0 then 1 else 2);
101 Abs_V : constant Uns := IP.Abs_Uns_Of_Int (V);
102 begin
103 Minus = (V < 0)
104 and then P in P'Old + Offset .. S'Last
105 and then UP.Only_Decimal_Ghost
106 (S, From => P'Old + Offset, To => P)
107 and then UP.Scan_Based_Number_Ghost
108 (S, From => P'Old + Offset, To => P)
109 = UP.Wrap_Option (Abs_V));
110 -- Stores the image of V in S starting at S (P + 1), P is updated to point
111 -- to the last character stored. The value stored is identical to the value
112 -- of Int'Image (V) except that no leading space is stored when V is
113 -- non-negative. The caller guarantees that S is long enough to hold the
114 -- result. S need not have a lower bound of 1.
115
116 end System.Image_I;