(extendsfdf2): Add pattern accidentally deleted when cirrus instructions were
[official-gcc.git] / gcc / ada / types.adb
blob04ec4e5dc2f8f924010782bcf7fc1afa6b59721a
1 ------------------------------------------------------------------------------
2 -- --
3 -- GNAT COMPILER COMPONENTS --
4 -- --
5 -- T Y P E S --
6 -- --
7 -- B o d y --
8 -- --
9 -- --
10 -- Copyright (C) 1992-2001 Free Software Foundation, Inc. --
11 -- --
12 -- GNAT is free software; you can redistribute it and/or modify it under --
13 -- terms of the GNU General Public License as published by the Free Soft- --
14 -- ware Foundation; either version 2, or (at your option) any later ver- --
15 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
16 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
17 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
18 -- for more details. You should have received a copy of the GNU General --
19 -- Public License distributed with GNAT; see file COPYING. If not, write --
20 -- to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, --
21 -- MA 02111-1307, USA. --
22 -- --
23 -- As a special exception, if other files instantiate generics from this --
24 -- unit, or you link this unit with other files to produce an executable, --
25 -- this unit does not by itself cause the resulting executable to be --
26 -- covered by the GNU General Public License. This exception does not --
27 -- however invalidate any other reasons why the executable file might be --
28 -- covered by the GNU Public License. --
29 -- --
30 -- GNAT was originally developed by the GNAT team at New York University. --
31 -- Extensive contributions were provided by Ada Core Technologies Inc. --
32 -- --
33 ------------------------------------------------------------------------------
35 package body Types is
37 -----------------------
38 -- Local Subprograms --
39 -----------------------
41 function V (T : Time_Stamp_Type; X : Time_Stamp_Index) return Nat;
42 -- Extract two decimal digit value from time stamp
44 ---------
45 -- "<" --
46 ---------
48 function "<" (Left, Right : Time_Stamp_Type) return Boolean is
49 begin
50 return not (Left = Right) and then String (Left) < String (Right);
51 end "<";
53 ----------
54 -- "<=" --
55 ----------
57 function "<=" (Left, Right : Time_Stamp_Type) return Boolean is
58 begin
59 return not (Left > Right);
60 end "<=";
62 ---------
63 -- "=" --
64 ---------
66 function "=" (Left, Right : Time_Stamp_Type) return Boolean is
67 Sleft : Nat;
68 Sright : Nat;
70 begin
71 if String (Left) = String (Right) then
72 return True;
74 elsif Left (1) = ' ' or else Right (1) = ' ' then
75 return False;
76 end if;
78 -- In the following code we check for a difference of 2 seconds or less
80 -- Recall that the time stamp format is:
82 -- Y Y Y Y M M D D H H M M S S
83 -- 01 02 03 04 05 06 07 08 09 10 11 12 13 14
85 -- Note that we do not bother to worry about shifts in the day.
86 -- It seems unlikely that such shifts could ever occur in practice
87 -- and even if they do we err on the safe side, ie we say that the time
88 -- stamps are different.
90 Sright := V (Right, 13) + 60 * (V (Right, 11) + 60 * V (Right, 09));
91 Sleft := V (Left, 13) + 60 * (V (Left, 11) + 60 * V (Left, 09));
93 -- So the check is: dates must be the same, times differ 2 sec at most
95 return abs (Sleft - Sright) <= 2
96 and then String (Left (1 .. 8)) = String (Right (1 .. 8));
97 end "=";
99 ---------
100 -- ">" --
101 ---------
103 function ">" (Left, Right : Time_Stamp_Type) return Boolean is
104 begin
105 return not (Left = Right) and then String (Left) > String (Right);
106 end ">";
108 ----------
109 -- ">=" --
110 ----------
112 function ">=" (Left, Right : Time_Stamp_Type) return Boolean is
113 begin
114 return not (Left < Right);
115 end ">=";
117 -------------------
118 -- Get_Char_Code --
119 -------------------
121 function Get_Char_Code (C : Character) return Char_Code is
122 begin
123 return Char_Code'Val (Character'Pos (C));
124 end Get_Char_Code;
126 -------------------
127 -- Get_Character --
128 -------------------
130 function Get_Character (C : Char_Code) return Character is
131 begin
132 pragma Assert (C <= 255);
133 return Character'Val (C);
134 end Get_Character;
136 --------------------
137 -- Get_Hex_String --
138 --------------------
140 subtype Wordh is Word range 0 .. 15;
141 Hex : constant array (Wordh) of Character := "0123456789abcdef";
143 function Get_Hex_String (W : Word) return Word_Hex_String is
144 X : Word := W;
145 WS : Word_Hex_String;
147 begin
148 for J in reverse 1 .. 8 loop
149 WS (J) := Hex (X mod 16);
150 X := X / 16;
151 end loop;
153 return WS;
154 end Get_Hex_String;
156 ------------------------
157 -- In_Character_Range --
158 ------------------------
160 function In_Character_Range (C : Char_Code) return Boolean is
161 begin
162 return (C <= 255);
163 end In_Character_Range;
165 ---------------------
166 -- Make_Time_Stamp --
167 ---------------------
169 procedure Make_Time_Stamp
170 (Year : Nat;
171 Month : Nat;
172 Day : Nat;
173 Hour : Nat;
174 Minutes : Nat;
175 Seconds : Nat;
176 TS : out Time_Stamp_Type)
178 Z : constant := Character'Pos ('0');
180 begin
181 TS (01) := Character'Val (Z + Year / 1000);
182 TS (02) := Character'Val (Z + (Year / 100) mod 10);
183 TS (03) := Character'Val (Z + (Year / 10) mod 10);
184 TS (04) := Character'Val (Z + Year mod 10);
185 TS (05) := Character'Val (Z + Month / 10);
186 TS (06) := Character'Val (Z + Month mod 10);
187 TS (07) := Character'Val (Z + Day / 10);
188 TS (08) := Character'Val (Z + Day mod 10);
189 TS (09) := Character'Val (Z + Hour / 10);
190 TS (10) := Character'Val (Z + Hour mod 10);
191 TS (11) := Character'Val (Z + Minutes / 10);
192 TS (12) := Character'Val (Z + Minutes mod 10);
193 TS (13) := Character'Val (Z + Seconds / 10);
194 TS (14) := Character'Val (Z + Seconds mod 10);
195 end Make_Time_Stamp;
197 ----------------------
198 -- Split_Time_Stamp --
199 ----------------------
201 procedure Split_Time_Stamp
202 (TS : Time_Stamp_Type;
203 Year : out Nat;
204 Month : out Nat;
205 Day : out Nat;
206 Hour : out Nat;
207 Minutes : out Nat;
208 Seconds : out Nat)
211 begin
212 -- Y Y Y Y M M D D H H M M S S
213 -- 01 02 03 04 05 06 07 08 09 10 11 12 13 14
215 Year := 100 * V (TS, 01) + V (TS, 03);
216 Month := V (TS, 05);
217 Day := V (TS, 07);
218 Hour := V (TS, 09);
219 Minutes := V (TS, 11);
220 Seconds := V (TS, 13);
221 end Split_Time_Stamp;
223 -------
224 -- V --
225 -------
227 function V (T : Time_Stamp_Type; X : Time_Stamp_Index) return Nat is
228 begin
229 return 10 * (Character'Pos (T (X)) - Character'Pos ('0')) +
230 Character'Pos (T (X + 1)) - Character'Pos ('0');
231 end V;
233 end Types;