OSDN Git Service

* Make-lang.in (gnat_ug_unx.info): Add dependency on stmp-docobjdir.
[pf3gnuchains/gcc-fork.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 -- This specification is adapted 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. --
13 --                                                                          --
14 ------------------------------------------------------------------------------
15
16 with System.Parameters;
17
18 package Interfaces.C is
19 pragma Pure (C);
20
21    --  Declaration's based on C's <limits.h>
22
23    CHAR_BIT  : constant := 8;
24    SCHAR_MIN : constant := -128;
25    SCHAR_MAX : constant := 127;
26    UCHAR_MAX : constant := 255;
27
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
30
31    type int   is new Integer;
32    type short is new Short_Integer;
33    type long  is range -(2 ** (System.Parameters.long_bits - 1))
34      .. +(2 ** (System.Parameters.long_bits - 1)) - 1;
35
36    type signed_char is range SCHAR_MIN .. SCHAR_MAX;
37    for signed_char'Size use CHAR_BIT;
38
39    type unsigned       is mod 2 ** int'Size;
40    type unsigned_short is mod 2 ** short'Size;
41    type unsigned_long  is mod 2 ** long'Size;
42
43    type unsigned_char is mod (UCHAR_MAX + 1);
44    for unsigned_char'Size use CHAR_BIT;
45
46    subtype plain_char is unsigned_char; -- ??? should be parametrized
47
48    type ptrdiff_t is
49      range -(2 ** (Standard'Address_Size - 1)) ..
50            +(2 ** (Standard'Address_Size - 1) - 1);
51
52    type size_t is mod 2 ** Standard'Address_Size;
53
54    --  Floating-Point
55
56    type C_float     is new Float;
57    type double      is new Standard.Long_Float;
58    type long_double is new Standard.Long_Long_Float;
59
60    ----------------------------
61    -- Characters and Strings --
62    ----------------------------
63
64    type char is new Character;
65
66    nul : constant char := char'First;
67
68    function To_C   (Item : Character) return char;
69    function To_Ada (Item : char)      return Character;
70
71    type char_array is array (size_t range <>) of aliased char;
72    for char_array'Component_Size use CHAR_BIT;
73
74    function Is_Nul_Terminated (Item : in char_array) return Boolean;
75
76    function To_C
77      (Item       : in String;
78       Append_Nul : in Boolean := True)
79       return       char_array;
80
81    function To_Ada
82      (Item     : in char_array;
83       Trim_Nul : in Boolean := True)
84       return     String;
85
86    procedure To_C
87      (Item       : in String;
88       Target     : out char_array;
89       Count      : out size_t;
90       Append_Nul : in Boolean := True);
91
92    procedure To_Ada
93      (Item     : in char_array;
94       Target   : out String;
95       Count    : out Natural;
96       Trim_Nul : in Boolean := True);
97
98    ------------------------------------
99    -- Wide Character and Wide String --
100    ------------------------------------
101
102    type wchar_t is new Wide_Character;
103    for wchar_t'Size use Standard'Wchar_T_Size;
104
105    wide_nul : constant wchar_t := wchar_t'First;
106
107    function To_C   (Item : in Wide_Character) return wchar_t;
108    function To_Ada (Item : in wchar_t)        return Wide_Character;
109
110    type wchar_array is array (size_t range <>) of aliased wchar_t;
111
112    function Is_Nul_Terminated (Item : in wchar_array) return Boolean;
113
114    function To_C
115      (Item       : in Wide_String;
116       Append_Nul : in Boolean := True)
117       return       wchar_array;
118
119    function To_Ada
120      (Item     : in wchar_array;
121       Trim_Nul : in Boolean := True)
122       return     Wide_String;
123
124    procedure To_C
125      (Item       : in Wide_String;
126       Target     : out wchar_array;
127       Count      : out size_t;
128       Append_Nul : in Boolean := True);
129
130    procedure To_Ada
131      (Item     : in wchar_array;
132       Target   : out Wide_String;
133       Count    : out Natural;
134       Trim_Nul : in Boolean := True);
135
136    Terminator_Error : exception;
137
138 end Interfaces.C;