Nathanael Nerode <neroden@gcc.gnu.org> PR ada/5904
[gcc.git] / gcc / ada / i-c.ads
1 -----------------------------------------------------------------------------
2 -- --
3 -- GNAT COMPILER COMPONENTS --
4 -- --
5 -- I N T E R F A C E S . C --
6 -- --
7 -- S p e c --
8 -- --
9 -- --
10 -- This specification is adapted from the Ada Reference Manual for use with --
11 -- GNAT. In accordance with the copyright of that document, you can freely --
12 -- copy and modify this specification, provided that if you redistribute a --
13 -- modified version, any changes that you have made are clearly indicated. --
14 -- --
15 ------------------------------------------------------------------------------
16
17 with System.Parameters;
18
19 package Interfaces.C is
20 pragma Pure (C);
21
22 -- Declaration's based on C's <limits.h>
23
24 CHAR_BIT : constant := 8;
25 SCHAR_MIN : constant := -128;
26 SCHAR_MAX : constant := 127;
27 UCHAR_MAX : constant := 255;
28
29 -- Signed and Unsigned Integers. Note that in GNAT, we have ensured that
30 -- the standard predefined Ada types correspond to the standard C types
31
32 type int is new Integer;
33 type short is new Short_Integer;
34 type long is range -(2 ** (System.Parameters.long_bits - 1))
35 .. +(2 ** (System.Parameters.long_bits - 1)) - 1;
36
37 type signed_char is range SCHAR_MIN .. SCHAR_MAX;
38 for signed_char'Size use CHAR_BIT;
39
40 type unsigned is mod 2 ** int'Size;
41 type unsigned_short is mod 2 ** short'Size;
42 type unsigned_long is mod 2 ** long'Size;
43
44 type unsigned_char is mod (UCHAR_MAX + 1);
45 for unsigned_char'Size use CHAR_BIT;
46
47 subtype plain_char is unsigned_char; -- ??? should be parametrized
48
49 type ptrdiff_t is
50 range -(2 ** (Standard'Address_Size - 1)) ..
51 +(2 ** (Standard'Address_Size - 1) - 1);
52
53 type size_t is mod 2 ** Standard'Address_Size;
54
55 -- Floating-Point
56
57 type C_float is new Float;
58 type double is new Standard.Long_Float;
59 type long_double is new Standard.Long_Long_Float;
60
61 ----------------------------
62 -- Characters and Strings --
63 ----------------------------
64
65 type char is new Character;
66
67 nul : constant char := char'First;
68
69 function To_C (Item : Character) return char;
70 function To_Ada (Item : char) return Character;
71
72 type char_array is array (size_t range <>) of aliased char;
73 for char_array'Component_Size use CHAR_BIT;
74
75 function Is_Nul_Terminated (Item : in char_array) return Boolean;
76
77 function To_C
78 (Item : in String;
79 Append_Nul : in Boolean := True)
80 return char_array;
81
82 function To_Ada
83 (Item : in char_array;
84 Trim_Nul : in Boolean := True)
85 return String;
86
87 procedure To_C
88 (Item : in String;
89 Target : out char_array;
90 Count : out size_t;
91 Append_Nul : in Boolean := True);
92
93 procedure To_Ada
94 (Item : in char_array;
95 Target : out String;
96 Count : out Natural;
97 Trim_Nul : in Boolean := True);
98
99 ------------------------------------
100 -- Wide Character and Wide String --
101 ------------------------------------
102
103 type wchar_t is new Wide_Character;
104 for wchar_t'Size use Standard'Wchar_T_Size;
105
106 wide_nul : constant wchar_t := wchar_t'First;
107
108 function To_C (Item : in Wide_Character) return wchar_t;
109 function To_Ada (Item : in wchar_t) return Wide_Character;
110
111 type wchar_array is array (size_t range <>) of aliased wchar_t;
112
113 function Is_Nul_Terminated (Item : in wchar_array) return Boolean;
114
115 function To_C
116 (Item : in Wide_String;
117 Append_Nul : in Boolean := True)
118 return wchar_array;
119
120 function To_Ada
121 (Item : in wchar_array;
122 Trim_Nul : in Boolean := True)
123 return Wide_String;
124
125 procedure To_C
126 (Item : in Wide_String;
127 Target : out wchar_array;
128 Count : out size_t;
129 Append_Nul : in Boolean := True);
130
131 procedure To_Ada
132 (Item : in wchar_array;
133 Target : out Wide_String;
134 Count : out Natural;
135 Trim_Nul : in Boolean := True);
136
137 Terminator_Error : exception;
138
139 end Interfaces.C;