OSDN Git Service

* sysdep.c: Problem discovered during IA64 VMS port.
[pf3gnuchains/gcc-fork.git] / gcc / ada / 6vcpp.adb
1 ------------------------------------------------------------------------------
2 --                                                                          --
3 --                         GNAT RUN-TIME COMPONENTS                         --
4 --                                                                          --
5 --                       I N T E R F A C E S . C P P                        --
6 --                                                                          --
7 --                                 B o d y                                  --
8 --                                                                          --
9 --         Copyright (C) 2000-2002, 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,  59 Temple Place - Suite 330,  Boston, --
20 -- MA 02111-1307, 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 ------------------------------------------------------------------------------
33
34 --  This is the OpenVMS/Alpha DEC C++ (cxx) version of this package.
35
36 with Ada.Tags;                use Ada.Tags;
37 with System;                  use System;
38 with System.Storage_Elements; use System.Storage_Elements;
39 with Unchecked_Conversion;
40
41 package body Interfaces.CPP is
42
43    subtype Cstring is String (Positive);
44    type Cstring_Ptr is access all Cstring;
45    type Tag_Table is array (Natural range <>) of Vtable_Ptr;
46    pragma Suppress_Initialization (Tag_Table);
47
48    type Type_Specific_Data is record
49       Idepth        : Natural;
50       Expanded_Name : Cstring_Ptr;
51       External_Tag  : Cstring_Ptr;
52       HT_Link       : Tag;
53       Ancestor_Tags : Tag_Table (Natural);
54    end record;
55
56    type Vtable_Entry is record
57      Pfn    : System.Address;
58    end record;
59
60    type Type_Specific_Data_Ptr is access all Type_Specific_Data;
61    type Vtable_Entry_Array is array (Positive range <>) of Vtable_Entry;
62
63    type VTable is record
64       Prims_Ptr : Vtable_Entry_Array (Positive);
65       TSD       : Type_Specific_Data_Ptr;
66       --  Location of TSD is unknown so it got moved here to be out of the
67       --  way of Prims_Ptr. Find it later. ???
68    end record;
69
70    --------------------------------------------------------
71    -- Unchecked Conversions for Tag, Vtable_Ptr, and TSD --
72    --------------------------------------------------------
73
74    function To_Type_Specific_Data_Ptr is
75      new Unchecked_Conversion (Address, Type_Specific_Data_Ptr);
76
77    function To_Address is
78      new Unchecked_Conversion (Type_Specific_Data_Ptr, Address);
79
80    ---------------------------------------------
81    -- Unchecked Conversions for String Fields --
82    ---------------------------------------------
83
84    function To_Cstring_Ptr is
85      new Unchecked_Conversion (Address, Cstring_Ptr);
86
87    function To_Address is
88      new Unchecked_Conversion (Cstring_Ptr, Address);
89
90    -----------------------
91    -- Local Subprograms --
92    -----------------------
93
94    function Length (Str : Cstring_Ptr) return Natural;
95    --  Length of string represented by the given pointer (treating the
96    --  string as a C-style string, which is Nul terminated).
97
98    --------------------
99    -- Displaced_This --
100    --------------------
101
102    function Displaced_This
103     (Current_This : System.Address;
104      Vptr         : Vtable_Ptr;
105      Position     : Positive)
106      return         System.Address
107    is
108       pragma Warnings (Off, Vptr);
109       pragma Warnings (Off, Position);
110    begin
111       return Current_This;
112 --        + Storage_Offset (Vptr.Prims_Ptr (Position).Delta1);
113    end Displaced_This;
114
115    -----------------------
116    -- CPP_CW_Membership --
117    -----------------------
118
119    function CPP_CW_Membership
120      (Obj_Tag : Vtable_Ptr;
121       Typ_Tag : Vtable_Ptr)
122       return Boolean
123    is
124       Pos : constant Integer := Obj_Tag.TSD.Idepth - Typ_Tag.TSD.Idepth;
125    begin
126       return Pos >= 0 and then Obj_Tag.TSD.Ancestor_Tags (Pos) = Typ_Tag;
127    end CPP_CW_Membership;
128
129    ---------------------------
130    -- CPP_Get_Expanded_Name --
131    ---------------------------
132
133    function CPP_Get_Expanded_Name (T : Vtable_Ptr) return Address is
134    begin
135       return To_Address (T.TSD.Expanded_Name);
136    end CPP_Get_Expanded_Name;
137
138    --------------------------
139    -- CPP_Get_External_Tag --
140    --------------------------
141
142    function CPP_Get_External_Tag (T : Vtable_Ptr) return Address is
143    begin
144       return To_Address (T.TSD.External_Tag);
145    end CPP_Get_External_Tag;
146
147    -------------------------------
148    -- CPP_Get_Inheritance_Depth --
149    -------------------------------
150
151    function CPP_Get_Inheritance_Depth (T : Vtable_Ptr) return Natural is
152    begin
153       return T.TSD.Idepth;
154    end CPP_Get_Inheritance_Depth;
155
156    -------------------------
157    -- CPP_Get_Prim_Op_Address --
158    -------------------------
159
160    function CPP_Get_Prim_Op_Address
161      (T        : Vtable_Ptr;
162       Position : Positive)
163       return Address is
164    begin
165       return T.Prims_Ptr (Position).Pfn;
166    end CPP_Get_Prim_Op_Address;
167
168    -------------------------------
169    -- CPP_Get_Remotely_Callable --
170    -------------------------------
171
172    function CPP_Get_Remotely_Callable (T : Vtable_Ptr) return Boolean is
173       pragma Warnings (Off, T);
174    begin
175       return True;
176    end CPP_Get_Remotely_Callable;
177
178    -----------------
179    -- CPP_Get_TSD --
180    -----------------
181
182    function CPP_Get_TSD  (T : Vtable_Ptr) return Address is
183    begin
184       return To_Address (T.TSD);
185    end CPP_Get_TSD;
186
187    --------------------
188    -- CPP_Inherit_DT --
189    --------------------
190
191    procedure CPP_Inherit_DT
192     (Old_T   : Vtable_Ptr;
193      New_T   : Vtable_Ptr;
194      Entry_Count : Natural)
195    is
196    begin
197       if Old_T /= null then
198          New_T.Prims_Ptr (1 .. Entry_Count)
199            := Old_T.Prims_Ptr (1 .. Entry_Count);
200       end if;
201    end CPP_Inherit_DT;
202
203    ---------------------
204    -- CPP_Inherit_TSD --
205    ---------------------
206
207    procedure CPP_Inherit_TSD
208      (Old_TSD : Address;
209       New_Tag : Vtable_Ptr)
210    is
211       TSD : constant Type_Specific_Data_Ptr
212         := To_Type_Specific_Data_Ptr (Old_TSD);
213
214       New_TSD : Type_Specific_Data renames New_Tag.TSD.all;
215
216    begin
217       if TSD /= null then
218          New_TSD.Idepth := TSD.Idepth + 1;
219          New_TSD.Ancestor_Tags (1 .. New_TSD.Idepth)
220            := TSD.Ancestor_Tags (0 .. TSD.Idepth);
221       else
222          New_TSD.Idepth := 0;
223       end if;
224
225       New_TSD.Ancestor_Tags (0) := New_Tag;
226    end CPP_Inherit_TSD;
227
228    ---------------------------
229    -- CPP_Set_Expanded_Name --
230    ---------------------------
231
232    procedure CPP_Set_Expanded_Name (T : Vtable_Ptr; Value : Address) is
233    begin
234       T.TSD.Expanded_Name := To_Cstring_Ptr (Value);
235    end CPP_Set_Expanded_Name;
236
237    --------------------------
238    -- CPP_Set_External_Tag --
239    --------------------------
240
241    procedure CPP_Set_External_Tag (T : Vtable_Ptr; Value : Address) is
242    begin
243       T.TSD.External_Tag := To_Cstring_Ptr (Value);
244    end CPP_Set_External_Tag;
245
246    -------------------------------
247    -- CPP_Set_Inheritance_Depth --
248    -------------------------------
249
250    procedure CPP_Set_Inheritance_Depth
251      (T     : Vtable_Ptr;
252       Value : Natural)
253    is
254    begin
255       T.TSD.Idepth := Value;
256    end CPP_Set_Inheritance_Depth;
257
258    -----------------------------
259    -- CPP_Set_Prim_Op_Address --
260    -----------------------------
261
262    procedure CPP_Set_Prim_Op_Address
263      (T        : Vtable_Ptr;
264       Position : Positive;
265       Value    : Address)
266    is
267    begin
268       T.Prims_Ptr (Position).Pfn := Value;
269    end CPP_Set_Prim_Op_Address;
270
271    -------------------------------
272    -- CPP_Set_Remotely_Callable --
273    -------------------------------
274
275    procedure CPP_Set_Remotely_Callable (T : Vtable_Ptr; Value : Boolean) is
276       pragma Warnings (Off, T);
277       pragma Warnings (Off, Value);
278    begin
279       null;
280    end CPP_Set_Remotely_Callable;
281
282    -----------------
283    -- CPP_Set_TSD --
284    -----------------
285
286    procedure CPP_Set_TSD (T : Vtable_Ptr; Value : Address) is
287    begin
288       T.TSD := To_Type_Specific_Data_Ptr (Value);
289    end CPP_Set_TSD;
290
291    -------------------
292    -- Expanded_Name --
293    -------------------
294
295    function Expanded_Name (T : Vtable_Ptr) return String is
296       Result : Cstring_Ptr := T.TSD.Expanded_Name;
297
298    begin
299       return Result (1 .. Length (Result));
300    end Expanded_Name;
301
302    ------------------
303    -- External_Tag --
304    ------------------
305
306    function External_Tag (T : Vtable_Ptr) return String is
307       Result : Cstring_Ptr := T.TSD.External_Tag;
308
309    begin
310       return Result (1 .. Length (Result));
311    end External_Tag;
312
313    ------------
314    -- Length --
315    ------------
316
317    function Length (Str : Cstring_Ptr) return Natural is
318       Len : Integer := 1;
319
320    begin
321       while Str (Len) /= ASCII.Nul loop
322          Len := Len + 1;
323       end loop;
324
325       return Len - 1;
326    end Length;
327
328    procedure CPP_Set_RC_Offset (T : Vtable_Ptr; Value : SSE.Storage_Offset) is
329       pragma Warnings (Off, T);
330       pragma Warnings (Off, Value);
331    begin
332       null;
333    end CPP_Set_RC_Offset;
334
335    function CPP_Get_RC_Offset (T : Vtable_Ptr) return SSE.Storage_Offset is
336       pragma Warnings (Off, T);
337    begin
338       return 0;
339    end CPP_Get_RC_Offset;
340 end Interfaces.CPP;