1 ------------------------------------------------------------------------------
3 -- GNAT RUN-TIME COMPONENTS --
5 -- I N T E R F A C E S . C P P --
11 -- Copyright (C) 1992-2001, Free Software Foundation, Inc. --
13 -- GNAT is free software; you can redistribute it and/or modify it under --
14 -- terms of the GNU General Public License as published by the Free Soft- --
15 -- ware Foundation; either version 2, or (at your option) any later ver- --
16 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
17 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
18 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
19 -- for more details. You should have received a copy of the GNU General --
20 -- Public License distributed with GNAT; see file COPYING. If not, write --
21 -- to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, --
22 -- MA 02111-1307, USA. --
24 -- As a special exception, if other files instantiate generics from this --
25 -- unit, or you link this unit with other files to produce an executable, --
26 -- this unit does not by itself cause the resulting executable to be --
27 -- covered by the GNU General Public License. This exception does not --
28 -- however invalidate any other reasons why the executable file might be --
29 -- covered by the GNU Public License. --
31 -- GNAT was originally developed by the GNAT team at New York University. --
32 -- It is now maintained by Ada Core Technologies Inc (http://www.gnat.com). --
34 ------------------------------------------------------------------------------
36 with Ada.Tags; use Ada.Tags;
37 with Interfaces.C; use Interfaces.C;
38 with System; use System;
39 with System.Storage_Elements; use System.Storage_Elements;
40 with Unchecked_Conversion;
42 package body Interfaces.CPP is
44 subtype Cstring is String (Positive);
45 type Cstring_Ptr is access all Cstring;
46 type Tag_Table is array (Natural range <>) of Vtable_Ptr;
47 pragma Suppress_Initialization (Tag_Table);
49 type Type_Specific_Data is record
51 Expanded_Name : Cstring_Ptr;
52 External_Tag : Cstring_Ptr;
54 Ancestor_Tags : Tag_Table (Natural);
57 type Vtable_Entry is record
61 type Type_Specific_Data_Ptr is access all Type_Specific_Data;
62 type Vtable_Entry_Array is array (Positive range <>) of Vtable_Entry;
67 TSD : Type_Specific_Data_Ptr;
68 Prims_Ptr : Vtable_Entry_Array (Positive);
71 --------------------------------------------------------
72 -- Unchecked Conversions for Tag, Vtable_Ptr, and TSD --
73 --------------------------------------------------------
75 function To_Type_Specific_Data_Ptr is
76 new Unchecked_Conversion (Address, Type_Specific_Data_Ptr);
78 function To_Address is new Unchecked_Conversion (Vtable_Ptr, Address);
79 function To_Address is
80 new Unchecked_Conversion (Type_Specific_Data_Ptr, Address);
82 function To_Vtable_Ptr is new Unchecked_Conversion (Tag, Vtable_Ptr);
83 function To_Tag is new Unchecked_Conversion (Vtable_Ptr, Tag);
85 ---------------------------------------------
86 -- Unchecked Conversions for String Fields --
87 ---------------------------------------------
89 function To_Cstring_Ptr is
90 new Unchecked_Conversion (Address, Cstring_Ptr);
92 function To_Address is
93 new Unchecked_Conversion (Cstring_Ptr, Address);
95 -----------------------
96 -- Local Subprograms --
97 -----------------------
99 function Length (Str : Cstring_Ptr) return Natural;
100 -- Length of string represented by the given pointer (treating the
101 -- string as a C-style string, which is Nul terminated).
103 -----------------------
104 -- CPP_CW_Membership --
105 -----------------------
107 function CPP_CW_Membership
108 (Obj_Tag : Vtable_Ptr;
109 Typ_Tag : Vtable_Ptr)
112 Pos : constant Integer := Obj_Tag.TSD.Idepth - Typ_Tag.TSD.Idepth;
114 return Pos >= 0 and then Obj_Tag.TSD.Ancestor_Tags (Pos) = Typ_Tag;
115 end CPP_CW_Membership;
117 ---------------------------
118 -- CPP_Get_Expanded_Name --
119 ---------------------------
121 function CPP_Get_Expanded_Name (T : Vtable_Ptr) return Address is
123 return To_Address (T.TSD.Expanded_Name);
124 end CPP_Get_Expanded_Name;
126 --------------------------
127 -- CPP_Get_External_Tag --
128 --------------------------
130 function CPP_Get_External_Tag (T : Vtable_Ptr) return Address is
132 return To_Address (T.TSD.External_Tag);
133 end CPP_Get_External_Tag;
135 -------------------------------
136 -- CPP_Get_Inheritance_Depth --
137 -------------------------------
139 function CPP_Get_Inheritance_Depth (T : Vtable_Ptr) return Natural is
142 end CPP_Get_Inheritance_Depth;
144 -------------------------
145 -- CPP_Get_Prim_Op_Address --
146 -------------------------
148 function CPP_Get_Prim_Op_Address
153 return T.Prims_Ptr (Position).Pfn;
154 end CPP_Get_Prim_Op_Address;
156 -----------------------
157 -- CPP_Get_RC_Offset --
158 -----------------------
160 function CPP_Get_RC_Offset (T : Vtable_Ptr) return SSE.Storage_Offset is
163 end CPP_Get_RC_Offset;
165 -------------------------------
166 -- CPP_Get_Remotely_Callable --
167 -------------------------------
169 function CPP_Get_Remotely_Callable (T : Vtable_Ptr) return Boolean is
172 end CPP_Get_Remotely_Callable;
178 function CPP_Get_TSD (T : Vtable_Ptr) return Address is
180 return To_Address (T.TSD);
187 procedure CPP_Inherit_DT
190 Entry_Count : Natural)
193 if Old_T /= null then
194 New_T.Prims_Ptr (1 .. Entry_Count)
195 := Old_T.Prims_Ptr (1 .. Entry_Count);
199 ---------------------
200 -- CPP_Inherit_TSD --
201 ---------------------
203 procedure CPP_Inherit_TSD
205 New_Tag : Vtable_Ptr)
207 TSD : constant Type_Specific_Data_Ptr
208 := To_Type_Specific_Data_Ptr (Old_TSD);
210 New_TSD : Type_Specific_Data renames New_Tag.TSD.all;
214 New_TSD.Idepth := TSD.Idepth + 1;
215 New_TSD.Ancestor_Tags (1 .. New_TSD.Idepth)
216 := TSD.Ancestor_Tags (0 .. TSD.Idepth);
221 New_TSD.Ancestor_Tags (0) := New_Tag;
224 ---------------------------
225 -- CPP_Set_Expanded_Name --
226 ---------------------------
228 procedure CPP_Set_Expanded_Name (T : Vtable_Ptr; Value : Address) is
230 T.TSD.Expanded_Name := To_Cstring_Ptr (Value);
231 end CPP_Set_Expanded_Name;
233 --------------------------
234 -- CPP_Set_External_Tag --
235 --------------------------
237 procedure CPP_Set_External_Tag (T : Vtable_Ptr; Value : Address) is
239 T.TSD.External_Tag := To_Cstring_Ptr (Value);
240 end CPP_Set_External_Tag;
242 -------------------------------
243 -- CPP_Set_Inheritance_Depth --
244 -------------------------------
246 procedure CPP_Set_Inheritance_Depth
251 T.TSD.Idepth := Value;
252 end CPP_Set_Inheritance_Depth;
254 -----------------------------
255 -- CPP_Set_Prim_Op_Address --
256 -----------------------------
258 procedure CPP_Set_Prim_Op_Address
264 T.Prims_Ptr (Position).Pfn := Value;
265 end CPP_Set_Prim_Op_Address;
267 -----------------------
268 -- CPP_Set_RC_Offset --
269 -----------------------
271 procedure CPP_Set_RC_Offset (T : Vtable_Ptr; Value : SSE.Storage_Offset) is
274 end CPP_Set_RC_Offset;
276 -------------------------------
277 -- CPP_Set_Remotely_Callable --
278 -------------------------------
280 procedure CPP_Set_Remotely_Callable (T : Vtable_Ptr; Value : Boolean) is
283 end CPP_Set_Remotely_Callable;
289 procedure CPP_Set_TSD (T : Vtable_Ptr; Value : Address) is
291 T.TSD := To_Type_Specific_Data_Ptr (Value);
298 function Displaced_This
299 (Current_This : System.Address;
302 return System.Address
307 -- why is the following here commented out ???
308 -- + Storage_Offset (Vptr.Prims_Ptr (Position).Delta1);
315 function Expanded_Name (T : Vtable_Ptr) return String is
316 Result : Cstring_Ptr := T.TSD.Expanded_Name;
319 return Result (1 .. Length (Result));
326 function External_Tag (T : Vtable_Ptr) return String is
327 Result : Cstring_Ptr := T.TSD.External_Tag;
330 return Result (1 .. Length (Result));
337 function Length (Str : Cstring_Ptr) return Natural is
341 while Str (Len) /= ASCII.Nul loop