1 ------------------------------------------------------------------------------
3 -- GNAT RUN-TIME COMPONENTS --
9 -- Copyright (C) 1992-2001 Free Software Foundation, Inc. --
11 -- This specification is derived from the Ada Reference Manual for use with --
12 -- GNAT. The copyright notice above, and the license provisions that follow --
13 -- apply solely to the contents of the part following the private keyword. --
15 -- GNAT is free software; you can redistribute it and/or modify it under --
16 -- terms of the GNU General Public License as published by the Free Soft- --
17 -- ware Foundation; either version 2, or (at your option) any later ver- --
18 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
19 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
20 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
21 -- for more details. You should have received a copy of the GNU General --
22 -- Public License distributed with GNAT; see file COPYING. If not, write --
23 -- to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, --
24 -- MA 02111-1307, USA. --
26 -- As a special exception, if other files instantiate generics from this --
27 -- unit, or you link this unit with other files to produce an executable, --
28 -- this unit does not by itself cause the resulting executable to be --
29 -- covered by the GNU General Public License. This exception does not --
30 -- however invalidate any other reasons why the executable file might be --
31 -- covered by the GNU Public License. --
33 -- GNAT was originally developed by the GNAT team at New York University. --
34 -- Extensive contributions were provided by Ada Core Technologies Inc. --
36 ------------------------------------------------------------------------------
39 with System
.Storage_Elements
;
43 pragma Elaborate_Body
;
47 function Expanded_Name
(T
: Tag
) return String;
49 function External_Tag
(T
: Tag
) return String;
51 function Internal_Tag
(External
: String) return Tag
;
53 Tag_Error
: exception;
57 ----------------------------------------------------------------
58 -- Abstract procedural interface for the GNAT dispatch table --
59 ----------------------------------------------------------------
61 -- GNAT's Dispatch Table format is customizable in order to match the
62 -- format used in another language. GNAT supports programs that use
63 -- two different dispatch table format at the same time: the native
64 -- format that supports Ada 95 tagged types and which is described in
65 -- Ada.Tags and a foreign format for types that are imported from some
66 -- other language (typically C++) which is described in interfaces.cpp.
67 -- The runtime information kept for each tagged type is separated into
68 -- two objects: the Dispatch Table and the Type Specific Data record.
69 -- These two objects are allocated statically using the constants:
71 -- DT Size = DT_Prologue_Size + Nb_Prim * DT_Entry_Size
72 -- TSD Size = TSD_Prologue_Size + (1 + Idepth) * TSD_Entry_Size
74 -- where Nb_prim is the number of primitive operations of the given
75 -- type and Idepth its inheritance depth.
77 -- The compiler generates calls to the following SET routines to
78 -- initialize those structures and uses the GET functions to
79 -- retreive the information when needed
81 package S
renames System
;
82 package SSE
renames System
.Storage_Elements
;
84 function CW_Membership
(Obj_Tag
: Tag
; Typ_Tag
: Tag
) return Boolean;
85 -- Given the tag of an object and the tag associated to a type, return
86 -- true if Obj is in Typ'Class.
88 function Get_Expanded_Name
(T
: Tag
) return S
.Address
;
89 -- Retrieve the address of a null terminated string containing
92 function Get_External_Tag
(T
: Tag
) return S
.Address
;
93 -- Retrieve the address of a null terminated string containing
96 function Get_Prim_Op_Address
100 -- Given a pointer to a dispatch Table (T) and a position in the DT
101 -- this function returns the address of the virtual function stored
102 -- in it (used for dispatching calls)
104 function Get_Inheritance_Depth
(T
: Tag
) return Natural;
105 -- Given a pointer to a dispatch Table, retrieves the value representing
106 -- the depth in the inheritance tree (used for membership).
108 function Get_RC_Offset
(T
: Tag
) return SSE
.Storage_Offset
;
109 -- Return the Offset of the implicit record controller when the object
110 -- has controlled components. O otherwise.
112 pragma Export
(Ada
, Get_RC_Offset
, "ada__tags__get_rc_offset");
113 -- This procedure is used in s-finimp to compute the deep routines
114 -- it is exported manually in order to avoid changing completely the
115 -- organization of the run time.
117 function Get_Remotely_Callable
(T
: Tag
) return Boolean;
118 -- Return the value previously set by Set_Remotely_Callable
120 function Get_TSD
(T
: Tag
) return S
.Address
;
121 -- Given a pointer T to a dispatch Table, retreives the address of the
122 -- record containing the Type Specific Data generated by GNAT
127 Entry_Count
: Natural);
128 -- Entry point used to initialize the DT of a type knowing the tag
129 -- of the direct ancestor and the number of primitive ops that are
130 -- inherited (Entry_Count).
132 procedure Inherit_TSD
(Old_TSD
: S
.Address
; New_Tag
: Tag
);
133 -- Entry point used to initialize the TSD of a type knowing the
134 -- TSD of the direct ancestor.
136 function Parent_Size
(Obj
: S
.Address
) return SSE
.Storage_Count
;
137 -- Computes the size of field _Parent of a tagged extension object
138 -- whose address is 'obj' by calling the indirectly _size function of
139 -- the parent. This function assumes that _size is always in slot 1 of
140 -- the dispatch table.
142 pragma Export
(Ada
, Parent_Size
, "ada__tags__parent_size");
143 -- This procedure is used in s-finimp and is thus exported manually
145 procedure Register_Tag
(T
: Tag
);
146 -- Insert the Tag and its associated external_tag in a table for the
147 -- sake of Internal_Tag
149 procedure Set_Inheritance_Depth
152 -- Given a pointer to a dispatch Table, stores the value representing
153 -- the depth in the inheritance tree (the second parameter). Used during
154 -- elaboration of the tagged type.
156 procedure Set_Prim_Op_Address
160 -- Given a pointer to a dispatch Table (T) and a position in the
161 -- dispatch Table put the address of the virtual function in it
162 -- (used for overriding)
164 procedure Set_TSD
(T
: Tag
; Value
: S
.Address
);
165 -- Given a pointer T to a dispatch Table, stores the address of the record
166 -- containing the Type Specific Data generated by GNAT
168 procedure Set_Expanded_Name
(T
: Tag
; Value
: S
.Address
);
169 -- Set the address of the string containing the expanded name
170 -- in the Dispatch table
172 procedure Set_External_Tag
(T
: Tag
; Value
: S
.Address
);
173 -- Set the address of the string containing the external tag
174 -- in the Dispatch table
176 procedure Set_RC_Offset
(T
: Tag
; Value
: SSE
.Storage_Offset
);
177 -- Sets the Offset of the implicit record controller when the object
178 -- has controlled components. Set to O otherwise.
180 procedure Set_Remotely_Callable
(T
: Tag
; Value
: Boolean);
181 -- Set to true if the type has been declared in a context described
184 DT_Prologue_Size
: constant SSE
.Storage_Count
:=
186 (Standard
'Address_Size / S
.Storage_Unit
);
187 -- Size of the first part of the dispatch table
189 DT_Entry_Size
: constant SSE
.Storage_Count
:=
191 (Standard
'Address_Size / S
.Storage_Unit
);
192 -- Size of each primitive operation entry in the Dispatch Table.
194 TSD_Prologue_Size
: constant SSE
.Storage_Count
:=
196 (6 * Standard
'Address_Size / S
.Storage_Unit
);
197 -- Size of the first part of the type specific data
199 TSD_Entry_Size
: constant SSE
.Storage_Count
:=
200 SSE
.Storage_Count
(Standard
'Address_Size / S
.Storage_Unit
);
201 -- Size of each ancestor tag entry in the TSD
203 type Address_Array
is array (Natural range <>) of S
.Address
;
206 type Tag
is access all Dispatch_Table
;
208 type Type_Specific_Data
;
209 type Type_Specific_Data_Ptr
is access all Type_Specific_Data
;
211 pragma Inline_Always
(CW_Membership
);
212 pragma Inline_Always
(Get_Expanded_Name
);
213 pragma Inline_Always
(Get_Inheritance_Depth
);
214 pragma Inline_Always
(Get_Prim_Op_Address
);
215 pragma Inline_Always
(Get_RC_Offset
);
216 pragma Inline_Always
(Get_Remotely_Callable
);
217 pragma Inline_Always
(Get_TSD
);
218 pragma Inline_Always
(Inherit_DT
);
219 pragma Inline_Always
(Inherit_TSD
);
220 pragma Inline_Always
(Register_Tag
);
221 pragma Inline_Always
(Set_Expanded_Name
);
222 pragma Inline_Always
(Set_External_Tag
);
223 pragma Inline_Always
(Set_Inheritance_Depth
);
224 pragma Inline_Always
(Set_Prim_Op_Address
);
225 pragma Inline_Always
(Set_RC_Offset
);
226 pragma Inline_Always
(Set_Remotely_Callable
);
227 pragma Inline_Always
(Set_TSD
);