1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
5 -- I N T E R F A C E S . C --
9 -- This specification is derived from the Ada Reference Manual for use with --
10 -- GNAT. In accordance with the copyright of that document, you can freely --
11 -- copy and modify this specification, provided that if you redistribute a --
12 -- modified version, any changes that you have made are clearly indicated. --
14 ------------------------------------------------------------------------------
16 with System
.Parameters
;
18 package Interfaces
.C
is
21 -- Declaration's based on C's <limits.h>
23 CHAR_BIT
: constant := 8;
24 SCHAR_MIN
: constant := -128;
25 SCHAR_MAX
: constant := 127;
26 UCHAR_MAX
: constant := 255;
28 -- Signed and Unsigned Integers. Note that in GNAT, we have ensured that
29 -- the standard predefined Ada types correspond to the standard C types
31 -- Note: the Integer qualifications used in the declaration of type long
32 -- avoid ambiguities when compiling in the presence of s-auxdec.ads and
33 -- a non-private system.address type.
35 type int
is new Integer;
36 type short
is new Short_Integer;
37 type long
is range -(2 ** (System
.Parameters
.long_bits
- Integer'(1)))
38 .. +(2 ** (System.Parameters.long_bits - Integer'(1))) - 1;
40 type signed_char
is range SCHAR_MIN
.. SCHAR_MAX
;
41 for signed_char
'Size use CHAR_BIT
;
43 type unsigned
is mod 2 ** int
'Size;
44 type unsigned_short
is mod 2 ** short
'Size;
45 type unsigned_long
is mod 2 ** long
'Size;
47 type unsigned_char
is mod (UCHAR_MAX
+ 1);
48 for unsigned_char
'Size use CHAR_BIT
;
50 subtype plain_char
is unsigned_char
; -- ??? should be parameterized
52 -- Note: the Integer qualifications used in the declaration of ptrdiff_t
53 -- avoid ambiguities when compiling in the presence of s-auxdec.ads and
54 -- a non-private system.address type.
57 range -(2 ** (System
.Parameters
.ptr_bits
- Integer'(1))) ..
58 +(2 ** (System.Parameters.ptr_bits - Integer'(1)) - 1);
60 type size_t
is mod 2 ** System
.Parameters
.ptr_bits
;
64 type C_float
is new Float;
65 type double
is new Standard
.Long_Float;
66 type long_double
is new Standard
.Long_Long_Float;
68 ----------------------------
69 -- Characters and Strings --
70 ----------------------------
72 type char
is new Character;
74 nul
: constant char
:= char
'First;
76 function To_C
(Item
: Character) return char
;
77 function To_Ada
(Item
: char
) return Character;
79 type char_array
is array (size_t
range <>) of aliased char
;
80 for char_array
'Component_Size use CHAR_BIT
;
82 function Is_Nul_Terminated
(Item
: char_array
) return Boolean;
86 Append_Nul
: Boolean := True) return char_array
;
90 Trim_Nul
: Boolean := True) return String;
94 Target
: out char_array
;
96 Append_Nul
: Boolean := True);
102 Trim_Nul
: Boolean := True);
104 ------------------------------------
105 -- Wide Character and Wide String --
106 ------------------------------------
108 type wchar_t
is new Wide_Character;
109 for wchar_t
'Size use Standard
'Wchar_T_Size;
111 wide_nul
: constant wchar_t
:= wchar_t
'First;
113 function To_C
(Item
: Wide_Character) return wchar_t
;
114 function To_Ada
(Item
: wchar_t
) return Wide_Character;
116 type wchar_array
is array (size_t
range <>) of aliased wchar_t
;
118 function Is_Nul_Terminated
(Item
: wchar_array
) return Boolean;
122 Append_Nul
: Boolean := True) return wchar_array
;
126 Trim_Nul
: Boolean := True) return Wide_String;
130 Target
: out wchar_array
;
132 Append_Nul
: Boolean := True);
136 Target
: out Wide_String;
138 Trim_Nul
: Boolean := True);
140 Terminator_Error
: exception;
142 -- The remaining declarations are for Ada 2005 (AI-285)
144 -- ISO/IEC 10646:2003 compatible types defined by SC22/WG14 document N1010
146 type char16_t
is new Wide_Character;
147 pragma Ada_05
(char16_t
);
149 char16_nul
: constant char16_t
:= char16_t
'Val (0);
150 pragma Ada_05
(char16_nul
);
152 function To_C
(Item
: Wide_Character) return char16_t
;
153 pragma Ada_05
(To_C
);
155 function To_Ada
(Item
: char16_t
) return Wide_Character;
156 pragma Ada_05
(To_Ada
);
158 type char16_array
is array (size_t
range <>) of aliased char16_t
;
159 pragma Ada_05
(char16_array
);
161 function Is_Nul_Terminated
(Item
: char16_array
) return Boolean;
162 pragma Ada_05
(Is_Nul_Terminated
);
166 Append_Nul
: Boolean := True) return char16_array
;
167 pragma Ada_05
(To_C
);
170 (Item
: char16_array
;
171 Trim_Nul
: Boolean := True) return Wide_String;
172 pragma Ada_05
(To_Ada
);
176 Target
: out char16_array
;
178 Append_Nul
: Boolean := True);
179 pragma Ada_05
(To_C
);
182 (Item
: char16_array
;
183 Target
: out Wide_String;
185 Trim_Nul
: Boolean := True);
186 pragma Ada_05
(To_Ada
);
188 type char32_t
is new Wide_Wide_Character
;
189 pragma Ada_05
(char32_t
);
191 char32_nul
: constant char32_t
:= char32_t
'Val (0);
192 pragma Ada_05
(char32_nul
);
194 function To_C
(Item
: Wide_Wide_Character
) return char32_t
;
195 pragma Ada_05
(To_C
);
197 function To_Ada
(Item
: char32_t
) return Wide_Wide_Character
;
198 pragma Ada_05
(To_Ada
);
200 type char32_array
is array (size_t
range <>) of aliased char32_t
;
201 pragma Ada_05
(char32_array
);
203 function Is_Nul_Terminated
(Item
: char32_array
) return Boolean;
204 pragma Ada_05
(Is_Nul_Terminated
);
207 (Item
: Wide_Wide_String
;
208 Append_Nul
: Boolean := True) return char32_array
;
209 pragma Ada_05
(To_C
);
212 (Item
: char32_array
;
213 Trim_Nul
: Boolean := True) return Wide_Wide_String
;
214 pragma Ada_05
(To_Ada
);
217 (Item
: Wide_Wide_String
;
218 Target
: out char32_array
;
220 Append_Nul
: Boolean := True);
221 pragma Ada_05
(To_C
);
224 (Item
: char32_array
;
225 Target
: out Wide_Wide_String
;
227 Trim_Nul
: Boolean := True);
228 pragma Ada_05
(To_Ada
);