* gcc.dg/pr26570.c: Clean up coverage files.
[official-gcc.git] / gcc / ada / s-imgllw.adb
blob6e69e80f0c9b8541c4ca79af6ce487966d705795
1 ------------------------------------------------------------------------------
2 -- --
3 -- GNAT RUN-TIME COMPONENTS --
4 -- --
5 -- S Y S T E M . I M G _ L L W --
6 -- --
7 -- B o d y --
8 -- --
9 -- Copyright (C) 1992-2005 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 2, 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. See the GNU General Public License --
17 -- for more details. You should have received a copy of the GNU General --
18 -- Public License distributed with GNAT; see file COPYING. If not, write --
19 -- to the Free Software Foundation, 51 Franklin Street, Fifth Floor, --
20 -- Boston, MA 02110-1301, USA. --
21 -- --
22 -- As a special exception, if other files instantiate generics from this --
23 -- unit, or you link this unit with other files to produce an executable, --
24 -- this unit does not by itself cause the resulting executable to be --
25 -- covered by the GNU General Public License. This exception does not --
26 -- however invalidate any other reasons why the executable file might be --
27 -- covered by the GNU Public License. --
28 -- --
29 -- GNAT was originally developed by the GNAT team at New York University. --
30 -- Extensive contributions were provided by Ada Core Technologies Inc. --
31 -- --
32 ------------------------------------------------------------------------------
34 with System.Unsigned_Types; use System.Unsigned_Types;
36 package body System.Img_LLW is
38 ---------------------------------------
39 -- Set_Image_Width_Long_Long_Integer --
40 ---------------------------------------
42 procedure Set_Image_Width_Long_Long_Integer
43 (V : Long_Long_Integer;
44 W : Integer;
45 S : out String;
46 P : in out Natural)
48 Start : Natural;
50 begin
51 -- Positive case can just use the unsigned circuit directly
53 if V >= 0 then
54 Set_Image_Width_Long_Long_Unsigned
55 (Long_Long_Unsigned (V), W, S, P);
57 -- Negative case has to set a minus sign. Note also that we have to be
58 -- careful not to generate overflow with the largest negative number.
60 else
61 P := P + 1;
62 S (P) := ' ';
63 Start := P;
65 declare
66 pragma Suppress (Overflow_Check);
67 pragma Suppress (Range_Check);
68 begin
69 Set_Image_Width_Long_Long_Unsigned
70 (Long_Long_Unsigned (-V), W - 1, S, P);
71 end;
73 -- Set minus sign in last leading blank location. Because of the
74 -- code above, there must be at least one such location.
76 while S (Start + 1) = ' ' loop
77 Start := Start + 1;
78 end loop;
80 S (Start) := '-';
81 end if;
83 end Set_Image_Width_Long_Long_Integer;
85 ----------------------------------------
86 -- Set_Image_Width_Long_Long_Unsigned --
87 ----------------------------------------
89 procedure Set_Image_Width_Long_Long_Unsigned
90 (V : Long_Long_Unsigned;
91 W : Integer;
92 S : out String;
93 P : in out Natural)
95 Start : constant Natural := P;
96 F, T : Natural;
98 procedure Set_Digits (T : Long_Long_Unsigned);
99 -- Set digits of absolute value of T
101 procedure Set_Digits (T : Long_Long_Unsigned) is
102 begin
103 if T >= 10 then
104 Set_Digits (T / 10);
105 P := P + 1;
106 S (P) := Character'Val (T mod 10 + Character'Pos ('0'));
107 else
108 P := P + 1;
109 S (P) := Character'Val (T + Character'Pos ('0'));
110 end if;
111 end Set_Digits;
113 -- Start of processing for Set_Image_Width_Long_Long_Unsigned
115 begin
116 Set_Digits (V);
118 -- Add leading spaces if required by width parameter
120 if P - Start < W then
121 F := P;
122 P := P + (W - (P - Start));
123 T := P;
125 while F > Start loop
126 S (T) := S (F);
127 T := T - 1;
128 F := F - 1;
129 end loop;
131 for J in Start + 1 .. T loop
132 S (J) := ' ';
133 end loop;
134 end if;
136 end Set_Image_Width_Long_Long_Unsigned;
138 end System.Img_LLW;