1 ------------------------------------------------------------------------------
3 -- GNAT RUN-TIME COMPONENTS --
5 -- I N T E R F A C E S . C P P --
9 -- Copyright (C) 2000-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 -- 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
;
105 Position
: Positive) return System
.Address
107 pragma Warnings
(Off
, Vptr
);
108 pragma Warnings
(Off
, Position
);
111 -- + Storage_Offset (Vptr.Prims_Ptr (Position).Delta1);
112 -- why is above line commented out ???
115 -----------------------
116 -- CPP_CW_Membership --
117 -----------------------
119 function CPP_CW_Membership
120 (Obj_Tag
: Vtable_Ptr
;
121 Typ_Tag
: Vtable_Ptr
) return Boolean
123 Pos
: constant Integer := Obj_Tag
.TSD
.Idepth
- Typ_Tag
.TSD
.Idepth
;
125 return Pos
>= 0 and then Obj_Tag
.TSD
.Ancestor_Tags
(Pos
) = Typ_Tag
;
126 end CPP_CW_Membership
;
128 ---------------------------
129 -- CPP_Get_Expanded_Name --
130 ---------------------------
132 function CPP_Get_Expanded_Name
(T
: Vtable_Ptr
) return Address
is
134 return To_Address
(T
.TSD
.Expanded_Name
);
135 end CPP_Get_Expanded_Name
;
137 --------------------------
138 -- CPP_Get_External_Tag --
139 --------------------------
141 function CPP_Get_External_Tag
(T
: Vtable_Ptr
) return Address
is
143 return To_Address
(T
.TSD
.External_Tag
);
144 end CPP_Get_External_Tag
;
146 -------------------------------
147 -- CPP_Get_Inheritance_Depth --
148 -------------------------------
150 function CPP_Get_Inheritance_Depth
(T
: Vtable_Ptr
) return Natural is
153 end CPP_Get_Inheritance_Depth
;
155 -----------------------
156 -- CPP_Get_RC_Offset --
157 -----------------------
159 function CPP_Get_RC_Offset
(T
: Vtable_Ptr
) return SSE
.Storage_Offset
is
160 pragma Warnings
(Off
, T
);
163 end CPP_Get_RC_Offset
;
165 -----------------------------
166 -- CPP_Get_Prim_Op_Address --
167 -----------------------------
169 function CPP_Get_Prim_Op_Address
171 Position
: Positive) return Address
174 return T
.Prims_Ptr
(Position
).Pfn
;
175 end CPP_Get_Prim_Op_Address
;
177 -------------------------------
178 -- CPP_Get_Remotely_Callable --
179 -------------------------------
181 function CPP_Get_Remotely_Callable
(T
: Vtable_Ptr
) return Boolean is
182 pragma Warnings
(Off
, T
);
185 end CPP_Get_Remotely_Callable
;
191 function CPP_Get_TSD
(T
: Vtable_Ptr
) return Address
is
193 return To_Address
(T
.TSD
);
200 procedure CPP_Inherit_DT
203 Entry_Count
: Natural)
206 if Old_T
/= null then
207 New_T
.Prims_Ptr
(1 .. Entry_Count
) :=
208 Old_T
.Prims_Ptr
(1 .. Entry_Count
);
212 ---------------------
213 -- CPP_Inherit_TSD --
214 ---------------------
216 procedure CPP_Inherit_TSD
218 New_Tag
: Vtable_Ptr
)
220 TSD
: constant Type_Specific_Data_Ptr
:=
221 To_Type_Specific_Data_Ptr
(Old_TSD
);
223 New_TSD
: Type_Specific_Data
renames New_Tag
.TSD
.all;
227 New_TSD
.Idepth
:= TSD
.Idepth
+ 1;
228 New_TSD
.Ancestor_Tags
(1 .. New_TSD
.Idepth
)
229 := TSD
.Ancestor_Tags
(0 .. TSD
.Idepth
);
234 New_TSD
.Ancestor_Tags
(0) := New_Tag
;
237 ---------------------------
238 -- CPP_Set_Expanded_Name --
239 ---------------------------
241 procedure CPP_Set_Expanded_Name
(T
: Vtable_Ptr
; Value
: Address
) is
243 T
.TSD
.Expanded_Name
:= To_Cstring_Ptr
(Value
);
244 end CPP_Set_Expanded_Name
;
246 --------------------------
247 -- CPP_Set_External_Tag --
248 --------------------------
250 procedure CPP_Set_External_Tag
(T
: Vtable_Ptr
; Value
: Address
) is
252 T
.TSD
.External_Tag
:= To_Cstring_Ptr
(Value
);
253 end CPP_Set_External_Tag
;
255 -------------------------------
256 -- CPP_Set_Inheritance_Depth --
257 -------------------------------
259 procedure CPP_Set_Inheritance_Depth
264 T
.TSD
.Idepth
:= Value
;
265 end CPP_Set_Inheritance_Depth
;
267 -----------------------------
268 -- CPP_Set_Prim_Op_Address --
269 -----------------------------
271 procedure CPP_Set_Prim_Op_Address
277 T
.Prims_Ptr
(Position
).Pfn
:= Value
;
278 end CPP_Set_Prim_Op_Address
;
280 -----------------------
281 -- CPP_Set_RC_Offset --
282 -----------------------
284 procedure CPP_Set_RC_Offset
(T
: Vtable_Ptr
; Value
: SSE
.Storage_Offset
) is
285 pragma Warnings
(Off
, T
);
286 pragma Warnings
(Off
, Value
);
289 end CPP_Set_RC_Offset
;
291 -------------------------------
292 -- CPP_Set_Remotely_Callable --
293 -------------------------------
295 procedure CPP_Set_Remotely_Callable
(T
: Vtable_Ptr
; Value
: Boolean) is
296 pragma Warnings
(Off
, T
);
297 pragma Warnings
(Off
, Value
);
300 end CPP_Set_Remotely_Callable
;
306 procedure CPP_Set_TSD
(T
: Vtable_Ptr
; Value
: Address
) is
308 T
.TSD
:= To_Type_Specific_Data_Ptr
(Value
);
315 function Expanded_Name
(T
: Vtable_Ptr
) return String is
316 Result
: constant Cstring_Ptr
:= T
.TSD
.Expanded_Name
;
318 return Result
(1 .. Length
(Result
));
325 function External_Tag
(T
: Vtable_Ptr
) return String is
326 Result
: constant Cstring_Ptr
:= T
.TSD
.External_Tag
;
328 return Result
(1 .. Length
(Result
));
335 function Length
(Str
: Cstring_Ptr
) return Natural is
339 while Str
(Len
) /= ASCII
.Nul
loop