1 ------------------------------------------------------------------------------
3 -- GNAT RUN-TIME COMPONENTS --
5 -- I N T E R F A C E S . C P P --
9 -- Copyright (C) 1992-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 with Ada
.Tags
; use Ada
.Tags
;
35 with Interfaces
.C
; use Interfaces
.C
;
36 with System
; use System
;
37 with System
.Storage_Elements
; use System
.Storage_Elements
;
38 with Unchecked_Conversion
;
40 package body Interfaces
.CPP
is
42 subtype Cstring
is String (Positive);
43 type Cstring_Ptr
is access all Cstring
;
44 type Tag_Table
is array (Natural range <>) of Vtable_Ptr
;
45 pragma Suppress_Initialization
(Tag_Table
);
47 type Type_Specific_Data
is record
49 Expanded_Name
: Cstring_Ptr
;
50 External_Tag
: Cstring_Ptr
;
52 Ancestor_Tags
: Tag_Table
(Natural);
55 type Vtable_Entry
is record
59 type Type_Specific_Data_Ptr
is access all Type_Specific_Data
;
60 type Vtable_Entry_Array
is array (Positive range <>) of Vtable_Entry
;
65 TSD
: Type_Specific_Data_Ptr
;
66 Prims_Ptr
: Vtable_Entry_Array
(Positive);
69 --------------------------------------------------------
70 -- Unchecked Conversions for Tag, Vtable_Ptr, and TSD --
71 --------------------------------------------------------
73 function To_Type_Specific_Data_Ptr
is
74 new Unchecked_Conversion
(Address
, Type_Specific_Data_Ptr
);
76 function To_Address
is
77 new Unchecked_Conversion
(Type_Specific_Data_Ptr
, Address
);
79 ---------------------------------------------
80 -- Unchecked Conversions for String Fields --
81 ---------------------------------------------
83 function To_Cstring_Ptr
is
84 new Unchecked_Conversion
(Address
, Cstring_Ptr
);
86 function To_Address
is
87 new Unchecked_Conversion
(Cstring_Ptr
, Address
);
89 -----------------------
90 -- Local Subprograms --
91 -----------------------
93 function Length
(Str
: Cstring_Ptr
) return Natural;
94 -- Length of string represented by the given pointer (treating the
95 -- string as a C-style string, which is Nul terminated).
97 -----------------------
98 -- CPP_CW_Membership --
99 -----------------------
101 function CPP_CW_Membership
102 (Obj_Tag
: Vtable_Ptr
;
103 Typ_Tag
: Vtable_Ptr
)
106 Pos
: constant Integer := Obj_Tag
.TSD
.Idepth
- Typ_Tag
.TSD
.Idepth
;
108 return Pos
>= 0 and then Obj_Tag
.TSD
.Ancestor_Tags
(Pos
) = Typ_Tag
;
109 end CPP_CW_Membership
;
111 ---------------------------
112 -- CPP_Get_Expanded_Name --
113 ---------------------------
115 function CPP_Get_Expanded_Name
(T
: Vtable_Ptr
) return Address
is
117 return To_Address
(T
.TSD
.Expanded_Name
);
118 end CPP_Get_Expanded_Name
;
120 --------------------------
121 -- CPP_Get_External_Tag --
122 --------------------------
124 function CPP_Get_External_Tag
(T
: Vtable_Ptr
) return Address
is
126 return To_Address
(T
.TSD
.External_Tag
);
127 end CPP_Get_External_Tag
;
129 -------------------------------
130 -- CPP_Get_Inheritance_Depth --
131 -------------------------------
133 function CPP_Get_Inheritance_Depth
(T
: Vtable_Ptr
) return Natural is
136 end CPP_Get_Inheritance_Depth
;
138 -------------------------
139 -- CPP_Get_Prim_Op_Address --
140 -------------------------
142 function CPP_Get_Prim_Op_Address
147 return T
.Prims_Ptr
(Position
).Pfn
;
148 end CPP_Get_Prim_Op_Address
;
150 -----------------------
151 -- CPP_Get_RC_Offset --
152 -----------------------
154 function CPP_Get_RC_Offset
(T
: Vtable_Ptr
) return SSE
.Storage_Offset
is
155 pragma Warnings
(Off
, T
);
159 end CPP_Get_RC_Offset
;
161 -------------------------------
162 -- CPP_Get_Remotely_Callable --
163 -------------------------------
165 function CPP_Get_Remotely_Callable
(T
: Vtable_Ptr
) return Boolean is
166 pragma Warnings
(Off
, T
);
170 end CPP_Get_Remotely_Callable
;
176 function CPP_Get_TSD
(T
: Vtable_Ptr
) return Address
is
178 return To_Address
(T
.TSD
);
185 procedure CPP_Inherit_DT
188 Entry_Count
: Natural)
191 if Old_T
/= null then
192 New_T
.Prims_Ptr
(1 .. Entry_Count
)
193 := Old_T
.Prims_Ptr
(1 .. Entry_Count
);
197 ---------------------
198 -- CPP_Inherit_TSD --
199 ---------------------
201 procedure CPP_Inherit_TSD
203 New_Tag
: Vtable_Ptr
)
205 TSD
: constant Type_Specific_Data_Ptr
206 := To_Type_Specific_Data_Ptr
(Old_TSD
);
208 New_TSD
: Type_Specific_Data
renames New_Tag
.TSD
.all;
212 New_TSD
.Idepth
:= TSD
.Idepth
+ 1;
213 New_TSD
.Ancestor_Tags
(1 .. New_TSD
.Idepth
)
214 := TSD
.Ancestor_Tags
(0 .. TSD
.Idepth
);
219 New_TSD
.Ancestor_Tags
(0) := New_Tag
;
222 ---------------------------
223 -- CPP_Set_Expanded_Name --
224 ---------------------------
226 procedure CPP_Set_Expanded_Name
(T
: Vtable_Ptr
; Value
: Address
) is
228 T
.TSD
.Expanded_Name
:= To_Cstring_Ptr
(Value
);
229 end CPP_Set_Expanded_Name
;
231 --------------------------
232 -- CPP_Set_External_Tag --
233 --------------------------
235 procedure CPP_Set_External_Tag
(T
: Vtable_Ptr
; Value
: Address
) is
237 T
.TSD
.External_Tag
:= To_Cstring_Ptr
(Value
);
238 end CPP_Set_External_Tag
;
240 -------------------------------
241 -- CPP_Set_Inheritance_Depth --
242 -------------------------------
244 procedure CPP_Set_Inheritance_Depth
249 T
.TSD
.Idepth
:= Value
;
250 end CPP_Set_Inheritance_Depth
;
252 -----------------------------
253 -- CPP_Set_Prim_Op_Address --
254 -----------------------------
256 procedure CPP_Set_Prim_Op_Address
262 T
.Prims_Ptr
(Position
).Pfn
:= Value
;
263 end CPP_Set_Prim_Op_Address
;
265 -----------------------
266 -- CPP_Set_RC_Offset --
267 -----------------------
269 procedure CPP_Set_RC_Offset
(T
: Vtable_Ptr
; Value
: SSE
.Storage_Offset
) is
270 pragma Warnings
(Off
, T
);
271 pragma Warnings
(Off
, Value
);
275 end CPP_Set_RC_Offset
;
277 -------------------------------
278 -- CPP_Set_Remotely_Callable --
279 -------------------------------
281 procedure CPP_Set_Remotely_Callable
(T
: Vtable_Ptr
; Value
: Boolean) is
282 pragma Warnings
(Off
, T
);
283 pragma Warnings
(Off
, Value
);
287 end CPP_Set_Remotely_Callable
;
293 procedure CPP_Set_TSD
(T
: Vtable_Ptr
; Value
: Address
) is
295 T
.TSD
:= To_Type_Specific_Data_Ptr
(Value
);
302 function Displaced_This
303 (Current_This
: System
.Address
;
306 return System
.Address
308 pragma Warnings
(Off
, Vptr
);
309 pragma Warnings
(Off
, Position
);
314 -- why is the following here commented out ???
315 -- + Storage_Offset (Vptr.Prims_Ptr (Position).Delta1);
322 function Expanded_Name
(T
: Vtable_Ptr
) return String is
323 Result
: Cstring_Ptr
:= T
.TSD
.Expanded_Name
;
326 return Result
(1 .. Length
(Result
));
333 function External_Tag
(T
: Vtable_Ptr
) return String is
334 Result
: Cstring_Ptr
:= T
.TSD
.External_Tag
;
337 return Result
(1 .. Length
(Result
));
344 function Length
(Str
: Cstring_Ptr
) return Natural is
348 while Str
(Len
) /= ASCII
.Nul
loop