1 ------------------------------------------------------------------------------
3 -- GNAT RUN-TIME COMPONENTS --
5 -- I N T E R F A C E S . C P P --
9 -- Copyright (C) 1992-2004, Free Software Foundation, Inc. --
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. --
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. --
29 -- GNAT was originally developed by the GNAT team at New York University. --
30 -- Extensive contributions were provided by Ada Core Technologies Inc. --
32 ------------------------------------------------------------------------------
34 with Ada.Tags; use Ada.Tags;
35 with System; use System;
36 with System.Storage_Elements; use System.Storage_Elements;
37 with Unchecked_Conversion;
39 package body Interfaces.CPP is
41 subtype Cstring is String (Positive);
42 type Cstring_Ptr is access all Cstring;
43 type Tag_Table is array (Natural range <>) of Vtable_Ptr;
44 pragma Suppress_Initialization (Tag_Table);
46 type Type_Specific_Data is record
48 Expanded_Name : Cstring_Ptr;
49 External_Tag : Cstring_Ptr;
51 Ancestor_Tags : Tag_Table (Natural);
54 type Vtable_Entry is record
58 type Type_Specific_Data_Ptr is access all Type_Specific_Data;
59 type Vtable_Entry_Array is array (Positive range <>) of Vtable_Entry;
62 Prims_Ptr : Vtable_Entry_Array (Positive);
63 TSD : Type_Specific_Data_Ptr;
66 --------------------------------------------------------
67 -- Unchecked Conversions for Tag, Vtable_Ptr, and TSD --
68 --------------------------------------------------------
70 function To_Type_Specific_Data_Ptr is
71 new Unchecked_Conversion (Address, Type_Specific_Data_Ptr);
73 function To_Address is
74 new Unchecked_Conversion (Type_Specific_Data_Ptr, Address);
76 ---------------------------------------------
77 -- Unchecked Conversions for String Fields --
78 ---------------------------------------------
80 function To_Cstring_Ptr is
81 new Unchecked_Conversion (Address, Cstring_Ptr);
83 function To_Address is
84 new Unchecked_Conversion (Cstring_Ptr, Address);
86 -----------------------
87 -- Local Subprograms --
88 -----------------------
90 function Length (Str : Cstring_Ptr) return Natural;
91 -- Length of string represented by the given pointer (treating the
92 -- string as a C-style string, which is Nul terminated).
94 -----------------------
95 -- CPP_CW_Membership --
96 -----------------------
98 function CPP_CW_Membership
99 (Obj_Tag : Vtable_Ptr;
100 Typ_Tag : Vtable_Ptr)
103 Pos : constant Integer := Obj_Tag.TSD.Idepth - Typ_Tag.TSD.Idepth;
105 return Pos >= 0 and then Obj_Tag.TSD.Ancestor_Tags (Pos) = Typ_Tag;
106 end CPP_CW_Membership;
108 ---------------------------
109 -- CPP_Get_Expanded_Name --
110 ---------------------------
112 function CPP_Get_Expanded_Name (T : Vtable_Ptr) return Address is
114 return To_Address (T.TSD.Expanded_Name);
115 end CPP_Get_Expanded_Name;
117 --------------------------
118 -- CPP_Get_External_Tag --
119 --------------------------
121 function CPP_Get_External_Tag (T : Vtable_Ptr) return Address is
123 return To_Address (T.TSD.External_Tag);
124 end CPP_Get_External_Tag;
126 -------------------------------
127 -- CPP_Get_Inheritance_Depth --
128 -------------------------------
130 function CPP_Get_Inheritance_Depth (T : Vtable_Ptr) return Natural is
133 end CPP_Get_Inheritance_Depth;
135 -------------------------
136 -- CPP_Get_Prim_Op_Address --
137 -------------------------
139 function CPP_Get_Prim_Op_Address
144 return T.Prims_Ptr (Position).Pfn;
145 end CPP_Get_Prim_Op_Address;
147 -----------------------
148 -- CPP_Get_RC_Offset --
149 -----------------------
151 function CPP_Get_RC_Offset (T : Vtable_Ptr) return SSE.Storage_Offset is
152 pragma Warnings (Off, T);
156 end CPP_Get_RC_Offset;
158 -------------------------------
159 -- CPP_Get_Remotely_Callable --
160 -------------------------------
162 function CPP_Get_Remotely_Callable (T : Vtable_Ptr) return Boolean is
163 pragma Warnings (Off, T);
167 end CPP_Get_Remotely_Callable;
173 function CPP_Get_TSD (T : Vtable_Ptr) return Address is
175 return To_Address (T.TSD);
182 procedure CPP_Inherit_DT
185 Entry_Count : Natural)
188 if Old_T /= null then
189 New_T.Prims_Ptr (1 .. Entry_Count)
190 := Old_T.Prims_Ptr (1 .. Entry_Count);
194 ---------------------
195 -- CPP_Inherit_TSD --
196 ---------------------
198 procedure CPP_Inherit_TSD
200 New_Tag : Vtable_Ptr)
202 TSD : constant Type_Specific_Data_Ptr
203 := To_Type_Specific_Data_Ptr (Old_TSD);
205 New_TSD : Type_Specific_Data renames New_Tag.TSD.all;
209 New_TSD.Idepth := TSD.Idepth + 1;
210 New_TSD.Ancestor_Tags (1 .. New_TSD.Idepth)
211 := TSD.Ancestor_Tags (0 .. TSD.Idepth);
216 New_TSD.Ancestor_Tags (0) := New_Tag;
219 ---------------------------
220 -- CPP_Set_Expanded_Name --
221 ---------------------------
223 procedure CPP_Set_Expanded_Name (T : Vtable_Ptr; Value : Address) is
225 T.TSD.Expanded_Name := To_Cstring_Ptr (Value);
226 end CPP_Set_Expanded_Name;
228 --------------------------
229 -- CPP_Set_External_Tag --
230 --------------------------
232 procedure CPP_Set_External_Tag (T : Vtable_Ptr; Value : Address) is
234 T.TSD.External_Tag := To_Cstring_Ptr (Value);
235 end CPP_Set_External_Tag;
237 -------------------------------
238 -- CPP_Set_Inheritance_Depth --
239 -------------------------------
241 procedure CPP_Set_Inheritance_Depth
246 T.TSD.Idepth := Value;
247 end CPP_Set_Inheritance_Depth;
249 -----------------------------
250 -- CPP_Set_Prim_Op_Address --
251 -----------------------------
253 procedure CPP_Set_Prim_Op_Address
259 T.Prims_Ptr (Position).Pfn := Value;
260 end CPP_Set_Prim_Op_Address;
262 -----------------------
263 -- CPP_Set_RC_Offset --
264 -----------------------
266 procedure CPP_Set_RC_Offset (T : Vtable_Ptr; Value : SSE.Storage_Offset) is
267 pragma Warnings (Off, T);
268 pragma Warnings (Off, Value);
272 end CPP_Set_RC_Offset;
274 -------------------------------
275 -- CPP_Set_Remotely_Callable --
276 -------------------------------
278 procedure CPP_Set_Remotely_Callable (T : Vtable_Ptr; Value : Boolean) is
279 pragma Warnings (Off, T);
280 pragma Warnings (Off, Value);
284 end CPP_Set_Remotely_Callable;
290 procedure CPP_Set_TSD (T : Vtable_Ptr; Value : Address) is
292 T.TSD := To_Type_Specific_Data_Ptr (Value);
299 function Displaced_This
300 (Current_This : System.Address;
303 return System.Address
305 pragma Warnings (Off, Vptr);
306 pragma Warnings (Off, Position);
311 -- why is the following here commented out ???
312 -- + Storage_Offset (Vptr.Prims_Ptr (Position).Delta1);
319 function Expanded_Name (T : Vtable_Ptr) return String is
320 Result : constant Cstring_Ptr := T.TSD.Expanded_Name;
323 return Result (1 .. Length (Result));
330 function External_Tag (T : Vtable_Ptr) return String is
331 Result : constant Cstring_Ptr := T.TSD.External_Tag;
334 return Result (1 .. Length (Result));
341 function Length (Str : Cstring_Ptr) return Natural is
345 while Str (Len) /= ASCII.Nul loop