Mark ChangeLog
[official-gcc.git] / gcc / ada / a-tags.ads
blob92715a85b14603687ea73e38ff09d2405af509cb
1 ------------------------------------------------------------------------------
2 -- --
3 -- GNAT RUN-TIME COMPONENTS --
4 -- --
5 -- A D A . T A G S --
6 -- --
7 -- S p e c --
8 -- --
9 -- Copyright (C) 1992-2005 Free Software Foundation, Inc. --
10 -- --
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. --
14 -- --
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. --
25 -- --
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. --
32 -- --
33 -- GNAT was originally developed by the GNAT team at New York University. --
34 -- Extensive contributions were provided by Ada Core Technologies Inc. --
35 -- --
36 ------------------------------------------------------------------------------
38 with System;
39 with System.Storage_Elements;
40 with Unchecked_Conversion;
42 package Ada.Tags is
44 pragma Elaborate_Body;
46 type Tag is private;
48 function Expanded_Name (T : Tag) return String;
50 function External_Tag (T : Tag) return String;
52 function Internal_Tag (External : String) return Tag;
54 Tag_Error : exception;
56 private
58 ---------------------------------------------------------------
59 -- Abstract Procedural Interface For The GNAT Dispatch Table --
60 ---------------------------------------------------------------
62 -- GNAT's Dispatch Table format is customizable in order to match the
63 -- format used in another language. GNAT supports programs that use
64 -- two different dispatch table formats at the same time: the native
65 -- format that supports Ada 95 tagged types and which is described in
66 -- Ada.Tags, and a foreign format for types that are imported from some
67 -- other language (typically C++) which is described in Interfaces.CPP.
68 -- The runtime information kept for each tagged type is separated into
69 -- two objects: the Dispatch Table and the Type Specific Data record.
70 -- These two objects are allocated statically using the constants:
72 -- DT Size = DT_Prologue_Size + Nb_Prim * DT_Entry_Size
73 -- TSD Size = TSD_Prologue_Size + (1 + Idepth) * TSD_Entry_Size
75 -- where Nb_prim is the number of primitive operations of the given
76 -- type and Idepth its inheritance depth.
78 -- The compiler generates calls to the following SET routines to
79 -- initialize those structures and uses the GET functions to
80 -- retreive the information when needed
82 type Dispatch_Table;
83 type Tag is access all Dispatch_Table;
85 type Type_Specific_Data;
86 type Type_Specific_Data_Ptr is access all Type_Specific_Data;
88 package SSE renames System.Storage_Elements;
90 function CW_Membership (Obj_Tag : Tag; Typ_Tag : Tag) return Boolean;
91 -- Given the tag of an object and the tag associated to a type, return
92 -- true if Obj is in Typ'Class.
94 function Get_Expanded_Name (T : Tag) return System.Address;
95 -- Retrieve the address of a null terminated string containing
96 -- the expanded name
98 function Get_External_Tag (T : Tag) return System.Address;
99 -- Retrieve the address of a null terminated string containing
100 -- the external name
102 function Get_Prim_Op_Address
103 (T : Tag;
104 Position : Positive) return System.Address;
105 -- Given a pointer to a dispatch Table (T) and a position in the DT
106 -- this function returns the address of the virtual function stored
107 -- in it (used for dispatching calls)
109 function Get_Inheritance_Depth (T : Tag) return Natural;
110 -- Given a pointer to a dispatch Table, retrieves the value representing
111 -- the depth in the inheritance tree (used for membership).
113 function Get_RC_Offset (T : Tag) return SSE.Storage_Offset;
114 -- Return the Offset of the implicit record controller when the object
115 -- has controlled components. O otherwise.
117 pragma Export (Ada, Get_RC_Offset, "ada__tags__get_rc_offset");
118 -- This procedure is used in s-finimp to compute the deep routines
119 -- it is exported manually in order to avoid changing completely the
120 -- organization of the run time.
122 function Get_Remotely_Callable (T : Tag) return Boolean;
123 -- Return the value previously set by Set_Remotely_Callable
125 function Get_TSD (T : Tag) return System.Address;
126 -- Given a pointer T to a dispatch Table, retreives the address of the
127 -- record containing the Type Specific Data generated by GNAT
129 procedure Inherit_DT
130 (Old_T : Tag;
131 New_T : Tag;
132 Entry_Count : Natural);
133 -- Entry point used to initialize the DT of a type knowing the tag
134 -- of the direct ancestor and the number of primitive ops that are
135 -- inherited (Entry_Count).
137 procedure Inherit_TSD (Old_TSD : System.Address; New_Tag : Tag);
138 -- Entry point used to initialize the TSD of a type knowing the
139 -- TSD of the direct ancestor.
141 function Parent_Size
142 (Obj : System.Address;
143 T : Tag) return SSE.Storage_Count;
144 -- Computes the size the ancestor part of a tagged extension object
145 -- whose address is 'obj' by calling the indirectly _size function of
146 -- the ancestor. The ancestor is the parent of the type represented by
147 -- tag T. This function assumes that _size is always in slot 1 of
148 -- the dispatch table.
150 pragma Export (Ada, Parent_Size, "ada__tags__parent_size");
151 -- This procedure is used in s-finimp and is thus exported manually
153 function Parent_Tag (T : Tag) return Tag;
154 -- Obj is the address of a tagged object. Parent_Tag fetch the tag of the
155 -- immediate ancestor (parent) of the type associated with Obj.
157 pragma Export (Ada, Parent_Tag, "ada__tags__parent_tag");
158 -- This procedure is used in s-finimp and is thus exported manually
160 procedure Register_Tag (T : Tag);
161 -- Insert the Tag and its associated external_tag in a table for the
162 -- sake of Internal_Tag
164 procedure Set_Inheritance_Depth
165 (T : Tag;
166 Value : Natural);
167 -- Given a pointer to a dispatch Table, stores the value representing
168 -- the depth in the inheritance tree (the second parameter). Used during
169 -- elaboration of the tagged type.
171 procedure Set_Prim_Op_Address
172 (T : Tag;
173 Position : Positive;
174 Value : System.Address);
175 -- Given a pointer to a dispatch Table (T) and a position in the
176 -- dispatch Table put the address of the virtual function in it
177 -- (used for overriding)
179 procedure Set_TSD (T : Tag; Value : System.Address);
180 -- Given a pointer T to a dispatch Table, stores the address of the record
181 -- containing the Type Specific Data generated by GNAT
183 procedure Set_Expanded_Name (T : Tag; Value : System.Address);
184 -- Set the address of the string containing the expanded name
185 -- in the Dispatch table
187 procedure Set_External_Tag (T : Tag; Value : System.Address);
188 -- Set the address of the string containing the external tag
189 -- in the Dispatch table
191 procedure Set_RC_Offset (T : Tag; Value : SSE.Storage_Offset);
192 -- Sets the Offset of the implicit record controller when the object
193 -- has controlled components. Set to O otherwise.
195 procedure Set_Remotely_Callable (T : Tag; Value : Boolean);
196 -- Set to true if the type has been declared in a context described
197 -- in E.4 (18).
199 function TSD (T : Tag) return Type_Specific_Data_Ptr;
200 -- This function is conceptually equivalent to Get_TSD, but
201 -- returning a Type_Specific_Data_Ptr type (rather than an Address)
202 -- simplifies the implementation of the other subprograms.
204 DT_Prologue_Size : constant SSE.Storage_Count :=
205 SSE.Storage_Count
206 (2 * (Standard'Address_Size / System.Storage_Unit));
207 -- Size of the first part of the dispatch table
209 DT_Typeinfo_Ptr_Size : constant SSE.Storage_Count :=
210 SSE.Storage_Count
211 (Standard'Address_Size / System.Storage_Unit);
212 -- Size of the Typeinfo_Ptr field of the Dispatch Table.
214 DT_Entry_Size : constant SSE.Storage_Count :=
215 SSE.Storage_Count
216 (1 * (Standard'Address_Size / System.Storage_Unit));
217 -- Size of each primitive operation entry in the Dispatch Table.
219 TSD_Prologue_Size : constant SSE.Storage_Count :=
220 SSE.Storage_Count
221 (6 * Standard'Address_Size / System.Storage_Unit);
222 -- Size of the first part of the type specific data
224 TSD_Entry_Size : constant SSE.Storage_Count :=
225 SSE.Storage_Count (1 * (Standard'Address_Size / System.Storage_Unit));
226 -- Size of each ancestor tag entry in the TSD
228 type Address_Array is array (Natural range <>) of System.Address;
229 pragma Suppress (Index_Check, On => Address_Array);
230 -- The reason we suppress index checks is that in the body, objects
231 -- of this type are declared with a dummy size of 1, the actual size
232 -- depending on the number of primitive operations.
234 function To_Type_Specific_Data_Ptr is
235 new Unchecked_Conversion (System.Address, Type_Specific_Data_Ptr);
237 function To_Address is
238 new Unchecked_Conversion (Type_Specific_Data_Ptr, System.Address);
240 function To_Address is
241 new Unchecked_Conversion (Tag, System.Address);
243 type Addr_Ptr is access System.Address;
245 function To_Addr_Ptr is
246 new Unchecked_Conversion (System.Address, Addr_Ptr);
248 -- Primitive dispatching operations are always inlined, to facilitate
249 -- use in a minimal/no run-time environment for high integrity use.
251 pragma Inline_Always (CW_Membership);
252 pragma Inline_Always (Get_Expanded_Name);
253 pragma Inline_Always (Get_Inheritance_Depth);
254 pragma Inline_Always (Get_Prim_Op_Address);
255 pragma Inline_Always (Get_RC_Offset);
256 pragma Inline_Always (Get_Remotely_Callable);
257 pragma Inline_Always (Get_TSD);
258 pragma Inline_Always (Inherit_DT);
259 pragma Inline_Always (Inherit_TSD);
260 pragma Inline_Always (Register_Tag);
261 pragma Inline_Always (Set_Expanded_Name);
262 pragma Inline_Always (Set_External_Tag);
263 pragma Inline_Always (Set_Inheritance_Depth);
264 pragma Inline_Always (Set_Prim_Op_Address);
265 pragma Inline_Always (Set_RC_Offset);
266 pragma Inline_Always (Set_Remotely_Callable);
267 pragma Inline_Always (Set_TSD);
268 pragma Inline_Always (TSD);
270 end Ada.Tags;