1 ------------------------------------------------------------------------------
3 -- GNAT RUN-TIME COMPONENTS --
5 -- I N T E R F A C E S . C P P --
9 -- Copyright (C) 2000-2002, 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 -- This is the OpenVMS/Alpha DEC C++ (cxx) version of this package.
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;
41 package body Interfaces.CPP is
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);
48 type Type_Specific_Data is record
50 Expanded_Name : Cstring_Ptr;
51 External_Tag : Cstring_Ptr;
53 Ancestor_Tags : Tag_Table (Natural);
56 type Vtable_Entry is record
60 type Type_Specific_Data_Ptr is access all Type_Specific_Data;
61 type Vtable_Entry_Array is array (Positive range <>) of Vtable_Entry;
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. ???
70 --------------------------------------------------------
71 -- Unchecked Conversions for Tag, Vtable_Ptr, and TSD --
72 --------------------------------------------------------
74 function To_Type_Specific_Data_Ptr is
75 new Unchecked_Conversion (Address, Type_Specific_Data_Ptr);
77 function To_Address is
78 new Unchecked_Conversion (Type_Specific_Data_Ptr, Address);
80 ---------------------------------------------
81 -- Unchecked Conversions for String Fields --
82 ---------------------------------------------
84 function To_Cstring_Ptr is
85 new Unchecked_Conversion (Address, Cstring_Ptr);
87 function To_Address is
88 new Unchecked_Conversion (Cstring_Ptr, Address);
90 -----------------------
91 -- Local Subprograms --
92 -----------------------
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).
102 function Displaced_This
103 (Current_This : System.Address;
106 return System.Address
108 pragma Warnings (Off, Vptr);
109 pragma Warnings (Off, Position);
112 -- + Storage_Offset (Vptr.Prims_Ptr (Position).Delta1);
115 -----------------------
116 -- CPP_CW_Membership --
117 -----------------------
119 function CPP_CW_Membership
120 (Obj_Tag : Vtable_Ptr;
121 Typ_Tag : Vtable_Ptr)
124 Pos : constant Integer := Obj_Tag.TSD.Idepth - Typ_Tag.TSD.Idepth;
126 return Pos >= 0 and then Obj_Tag.TSD.Ancestor_Tags (Pos) = Typ_Tag;
127 end CPP_CW_Membership;
129 ---------------------------
130 -- CPP_Get_Expanded_Name --
131 ---------------------------
133 function CPP_Get_Expanded_Name (T : Vtable_Ptr) return Address is
135 return To_Address (T.TSD.Expanded_Name);
136 end CPP_Get_Expanded_Name;
138 --------------------------
139 -- CPP_Get_External_Tag --
140 --------------------------
142 function CPP_Get_External_Tag (T : Vtable_Ptr) return Address is
144 return To_Address (T.TSD.External_Tag);
145 end CPP_Get_External_Tag;
147 -------------------------------
148 -- CPP_Get_Inheritance_Depth --
149 -------------------------------
151 function CPP_Get_Inheritance_Depth (T : Vtable_Ptr) return Natural is
154 end CPP_Get_Inheritance_Depth;
156 -------------------------
157 -- CPP_Get_Prim_Op_Address --
158 -------------------------
160 function CPP_Get_Prim_Op_Address
165 return T.Prims_Ptr (Position).Pfn;
166 end CPP_Get_Prim_Op_Address;
168 -------------------------------
169 -- CPP_Get_Remotely_Callable --
170 -------------------------------
172 function CPP_Get_Remotely_Callable (T : Vtable_Ptr) return Boolean is
173 pragma Warnings (Off, T);
176 end CPP_Get_Remotely_Callable;
182 function CPP_Get_TSD (T : Vtable_Ptr) return Address is
184 return To_Address (T.TSD);
191 procedure CPP_Inherit_DT
194 Entry_Count : Natural)
197 if Old_T /= null then
198 New_T.Prims_Ptr (1 .. Entry_Count)
199 := Old_T.Prims_Ptr (1 .. Entry_Count);
203 ---------------------
204 -- CPP_Inherit_TSD --
205 ---------------------
207 procedure CPP_Inherit_TSD
209 New_Tag : Vtable_Ptr)
211 TSD : constant Type_Specific_Data_Ptr
212 := To_Type_Specific_Data_Ptr (Old_TSD);
214 New_TSD : Type_Specific_Data renames New_Tag.TSD.all;
218 New_TSD.Idepth := TSD.Idepth + 1;
219 New_TSD.Ancestor_Tags (1 .. New_TSD.Idepth)
220 := TSD.Ancestor_Tags (0 .. TSD.Idepth);
225 New_TSD.Ancestor_Tags (0) := New_Tag;
228 ---------------------------
229 -- CPP_Set_Expanded_Name --
230 ---------------------------
232 procedure CPP_Set_Expanded_Name (T : Vtable_Ptr; Value : Address) is
234 T.TSD.Expanded_Name := To_Cstring_Ptr (Value);
235 end CPP_Set_Expanded_Name;
237 --------------------------
238 -- CPP_Set_External_Tag --
239 --------------------------
241 procedure CPP_Set_External_Tag (T : Vtable_Ptr; Value : Address) is
243 T.TSD.External_Tag := To_Cstring_Ptr (Value);
244 end CPP_Set_External_Tag;
246 -------------------------------
247 -- CPP_Set_Inheritance_Depth --
248 -------------------------------
250 procedure CPP_Set_Inheritance_Depth
255 T.TSD.Idepth := Value;
256 end CPP_Set_Inheritance_Depth;
258 -----------------------------
259 -- CPP_Set_Prim_Op_Address --
260 -----------------------------
262 procedure CPP_Set_Prim_Op_Address
268 T.Prims_Ptr (Position).Pfn := Value;
269 end CPP_Set_Prim_Op_Address;
271 -------------------------------
272 -- CPP_Set_Remotely_Callable --
273 -------------------------------
275 procedure CPP_Set_Remotely_Callable (T : Vtable_Ptr; Value : Boolean) is
276 pragma Warnings (Off, T);
277 pragma Warnings (Off, Value);
280 end CPP_Set_Remotely_Callable;
286 procedure CPP_Set_TSD (T : Vtable_Ptr; Value : Address) is
288 T.TSD := To_Type_Specific_Data_Ptr (Value);
295 function Expanded_Name (T : Vtable_Ptr) return String is
296 Result : Cstring_Ptr := T.TSD.Expanded_Name;
299 return Result (1 .. Length (Result));
306 function External_Tag (T : Vtable_Ptr) return String is
307 Result : Cstring_Ptr := T.TSD.External_Tag;
310 return Result (1 .. Length (Result));
317 function Length (Str : Cstring_Ptr) return Natural is
321 while Str (Len) /= ASCII.Nul loop
328 procedure CPP_Set_RC_Offset (T : Vtable_Ptr; Value : SSE.Storage_Offset) is
329 pragma Warnings (Off, T);
330 pragma Warnings (Off, Value);
333 end CPP_Set_RC_Offset;
335 function CPP_Get_RC_Offset (T : Vtable_Ptr) return SSE.Storage_Offset is
336 pragma Warnings (Off, T);
339 end CPP_Get_RC_Offset;