Debian Codegraph @

gcc/ada/libgnat/s-imaged.adb

raw
1 ------------------------------------------------------------------------------
2 -- --
3 -- GNAT RUN-TIME COMPONENTS --
4 -- --
5 -- S Y S T E M . I M A G E _ D --
6 -- --
7 -- B o d y --
8 -- --
9 -- Copyright (C) 2020-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 with System.Image_I;
33 with System.Img_Util; use System.Img_Util;
34 with System.Value_I_Spec;
35 with System.Value_U_Spec;
36
37 package body System.Image_D is
38
39 -- Contracts, ghost code, loop invariants and assertions in this unit are
40 -- meant for analysis only, not for run-time checking, as it would be too
41 -- costly otherwise. This is enforced by setting the assertion policy to
42 -- Ignore.
43
44 pragma Assertion_Policy (Assert => Ignore,
45 Assert_And_Cut => Ignore,
46 Contract_Cases => Ignore,
47 Ghost => Ignore,
48 Loop_Invariant => Ignore,
49 Pre => Ignore,
50 Post => Ignore,
51 Subprogram_Variant => Ignore);
52
53 package Uns_Spec is new System.Value_U_Spec (Uns);
54 package Int_Spec is new System.Value_I_Spec (Int, Uns, Uns_Spec);
55
56 package Image_I is new System.Image_I
57 (Int => Int,
58 Uns => Uns,
59 U_Spec => Uns_Spec,
60 I_Spec => Int_Spec);
61
62 procedure Set_Image_Integer
63 (V : Int;
64 S : in out String;
65 P : in out Natural)
66 renames Image_I.Set_Image_Integer;
67
68 -------------------
69 -- Image_Decimal --
70 -------------------
71
72 procedure Image_Decimal
73 (V : Int;
74 S : in out String;
75 P : out Natural;
76 Scale : Integer)
77 is
78 pragma Assert (S'First = 1);
79
80 begin
81 -- Add space at start for non-negative numbers
82
83 if V >= 0 then
84 S (1) := ' ';
85 P := 1;
86 else
87 P := 0;
88 end if;
89
90 Set_Image_Decimal (V, S, P, Scale, 1, Integer'Max (1, Scale), 0);
91 end Image_Decimal;
92
93 -----------------------
94 -- Set_Image_Decimal --
95 -----------------------
96
97 procedure Set_Image_Decimal
98 (V : Int;
99 S : in out String;
100 P : in out Natural;
101 Scale : Integer;
102 Fore : Natural;
103 Aft : Natural;
104 Exp : Natural)
105 is
106 Maxdigs : constant Natural := Int'Width;
107 -- Maximum length needed for Image of an Int
108
109 Digs : String (1 .. Maxdigs);
110 Ndigs : Natural;
111 -- Buffer for the image of the integer value
112
113 begin
114 -- Set the first character like Image
115
116 if V >= 0 then
117 Digs (1) := ' ';
118 Ndigs := 1;
119 else
120 Ndigs := 0;
121 end if;
122
123 Set_Image_Integer (V, Digs, Ndigs);
124
125 pragma Assert (1 <= Ndigs and then Ndigs <= Maxdigs);
126
127 Set_Decimal_Digits (Digs, Ndigs, S, P, Scale, Fore, Aft, Exp);
128 end Set_Image_Decimal;
129
130 end System.Image_D;