with Ada.Tags; use Ada.Tags;
with System; use System;
with System.Storage_Elements; use System.Storage_Elements;
with Unchecked_Conversion;
package body Interfaces.CPP is
subtype Cstring is String (Positive);
type Cstring_Ptr is access all Cstring;
type Tag_Table is array (Natural range <>) of Vtable_Ptr;
pragma Suppress_Initialization (Tag_Table);
type Type_Specific_Data is record
Idepth : Natural;
Expanded_Name : Cstring_Ptr;
External_Tag : Cstring_Ptr;
HT_Link : Tag;
Ancestor_Tags : Tag_Table (Natural);
end record;
type Vtable_Entry is record
Pfn : System.Address;
end record;
type Type_Specific_Data_Ptr is access all Type_Specific_Data;
type Vtable_Entry_Array is array (Positive range <>) of Vtable_Entry;
type VTable is record
Prims_Ptr : Vtable_Entry_Array (Positive);
TSD : Type_Specific_Data_Ptr;
end record;
function To_Type_Specific_Data_Ptr is
new Unchecked_Conversion (Address, Type_Specific_Data_Ptr);
function To_Address is
new Unchecked_Conversion (Type_Specific_Data_Ptr, Address);
function To_Cstring_Ptr is
new Unchecked_Conversion (Address, Cstring_Ptr);
function To_Address is
new Unchecked_Conversion (Cstring_Ptr, Address);
function Length (Str : Cstring_Ptr) return Natural;
function Displaced_This
(Current_This : System.Address;
Vptr : Vtable_Ptr;
Position : Positive)
return System.Address
is
begin
return Current_This;
end Displaced_This;
function CPP_CW_Membership
(Obj_Tag : Vtable_Ptr;
Typ_Tag : Vtable_Ptr)
return Boolean
is
Pos : constant Integer := Obj_Tag.TSD.Idepth - Typ_Tag.TSD.Idepth;
begin
return Pos >= 0 and then Obj_Tag.TSD.Ancestor_Tags (Pos) = Typ_Tag;
end CPP_CW_Membership;
function CPP_Get_Expanded_Name (T : Vtable_Ptr) return Address is
begin
return To_Address (T.TSD.Expanded_Name);
end CPP_Get_Expanded_Name;
function CPP_Get_External_Tag (T : Vtable_Ptr) return Address is
begin
return To_Address (T.TSD.External_Tag);
end CPP_Get_External_Tag;
function CPP_Get_Inheritance_Depth (T : Vtable_Ptr) return Natural is
begin
return T.TSD.Idepth;
end CPP_Get_Inheritance_Depth;
function CPP_Get_Prim_Op_Address
(T : Vtable_Ptr;
Position : Positive)
return Address is
begin
return T.Prims_Ptr (Position).Pfn;
end CPP_Get_Prim_Op_Address;
function CPP_Get_Remotely_Callable (T : Vtable_Ptr) return Boolean is
begin
return True;
end CPP_Get_Remotely_Callable;
function CPP_Get_TSD (T : Vtable_Ptr) return Address is
begin
return To_Address (T.TSD);
end CPP_Get_TSD;
procedure CPP_Inherit_DT
(Old_T : Vtable_Ptr;
New_T : Vtable_Ptr;
Entry_Count : Natural)
is
begin
if Old_T /= null then
New_T.Prims_Ptr (1 .. Entry_Count)
:= Old_T.Prims_Ptr (1 .. Entry_Count);
end if;
end CPP_Inherit_DT;
procedure CPP_Inherit_TSD
(Old_TSD : Address;
New_Tag : Vtable_Ptr)
is
TSD : constant Type_Specific_Data_Ptr
:= To_Type_Specific_Data_Ptr (Old_TSD);
New_TSD : Type_Specific_Data renames New_Tag.TSD.all;
begin
if TSD /= null then
New_TSD.Idepth := TSD.Idepth + 1;
New_TSD.Ancestor_Tags (1 .. New_TSD.Idepth)
:= TSD.Ancestor_Tags (0 .. TSD.Idepth);
else
New_TSD.Idepth := 0;
end if;
New_TSD.Ancestor_Tags (0) := New_Tag;
end CPP_Inherit_TSD;
procedure CPP_Set_Expanded_Name (T : Vtable_Ptr; Value : Address) is
begin
T.TSD.Expanded_Name := To_Cstring_Ptr (Value);
end CPP_Set_Expanded_Name;
procedure CPP_Set_External_Tag (T : Vtable_Ptr; Value : Address) is
begin
T.TSD.External_Tag := To_Cstring_Ptr (Value);
end CPP_Set_External_Tag;
procedure CPP_Set_Inheritance_Depth
(T : Vtable_Ptr;
Value : Natural)
is
begin
T.TSD.Idepth := Value;
end CPP_Set_Inheritance_Depth;
procedure CPP_Set_Prim_Op_Address
(T : Vtable_Ptr;
Position : Positive;
Value : Address)
is
begin
T.Prims_Ptr (Position).Pfn := Value;
end CPP_Set_Prim_Op_Address;
procedure CPP_Set_Remotely_Callable (T : Vtable_Ptr; Value : Boolean) is
begin
null;
end CPP_Set_Remotely_Callable;
procedure CPP_Set_TSD (T : Vtable_Ptr; Value : Address) is
begin
T.TSD := To_Type_Specific_Data_Ptr (Value);
end CPP_Set_TSD;
function Expanded_Name (T : Vtable_Ptr) return String is
Result : Cstring_Ptr := T.TSD.Expanded_Name;
begin
return Result (1 .. Length (Result));
end Expanded_Name;
function External_Tag (T : Vtable_Ptr) return String is
Result : Cstring_Ptr := T.TSD.External_Tag;
begin
return Result (1 .. Length (Result));
end External_Tag;
function Length (Str : Cstring_Ptr) return Natural is
Len : Integer := 1;
begin
while Str (Len) /= ASCII.Nul loop
Len := Len + 1;
end loop;
return Len - 1;
end Length;
procedure CPP_Set_RC_Offset (T : Vtable_Ptr; Value : SSE.Storage_Offset) is
begin
null;
end CPP_Set_RC_Offset;
function CPP_Get_RC_Offset (T : Vtable_Ptr) return SSE.Storage_Offset is
begin
return 0;
end CPP_Get_RC_Offset;
end Interfaces.CPP;