]> git.ipfire.org Git - thirdparty/gcc.git/blob - gcc/ada/a-tags.ads
2003-10-21 Arnaud Charlet <charlet@act-europe.fr>
[thirdparty/gcc.git] / gcc / ada / a-tags.ads
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-2003 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 ------------------------------------------------------------------------------
37
38 with System;
39 with System.Storage_Elements;
40
41 package Ada.Tags is
42
43 pragma Elaborate_Body;
44
45 type Tag is private;
46
47 function Expanded_Name (T : Tag) return String;
48
49 function External_Tag (T : Tag) return String;
50
51 function Internal_Tag (External : String) return Tag;
52
53 Tag_Error : exception;
54
55 private
56
57 ----------------------------------------------------------------
58 -- Abstract procedural interface for the GNAT dispatch table --
59 ----------------------------------------------------------------
60
61 -- GNAT's Dispatch Table format is customizable in order to match the
62 -- format used in another langauge. 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:
70
71 -- DT Size = DT_Prologue_Size + Nb_Prim * DT_Entry_Size
72 -- TSD Size = TSD_Prologue_Size + (1 + Idepth) * TSD_Entry_Size
73
74 -- where Nb_prim is the number of primitive operations of the given
75 -- type and Idepth its inheritance depth.
76
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
80
81 package S renames System;
82 package SSE renames System.Storage_Elements;
83
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.
87
88 function Get_Expanded_Name (T : Tag) return S.Address;
89 -- Retrieve the address of a null terminated string containing
90 -- the expanded name
91
92 function Get_External_Tag (T : Tag) return S.Address;
93 -- Retrieve the address of a null terminated string containing
94 -- the external name
95
96 function Get_Prim_Op_Address
97 (T : Tag;
98 Position : Positive)
99 return S.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)
103
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).
107
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.
111
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.
116
117 function Get_Remotely_Callable (T : Tag) return Boolean;
118 -- Return the value previously set by Set_Remotely_Callable
119
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
123
124 procedure Inherit_DT
125 (Old_T : Tag;
126 New_T : Tag;
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).
131
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.
135
136 function Parent_Size
137 (Obj : S.Address;
138 T : Tag)
139 return SSE.Storage_Count;
140 -- Computes the size the ancestor part of a tagged extension object
141 -- whose address is 'obj' by calling the indirectly _size function of
142 -- the ancestor. The ancestor is the parent of the type represented by
143 -- tag T. This function assumes that _size is always in slot 1 of
144 -- the dispatch table.
145
146 pragma Export (Ada, Parent_Size, "ada__tags__parent_size");
147 -- This procedure is used in s-finimp and is thus exported manually
148
149 function Parent_Tag (T : Tag) return Tag;
150 -- Obj is the address of a tagged object. Parent_Tag fetch the tag of the
151 -- immediate ancestor (parent) of the type associated with Obj.
152
153 pragma Export (Ada, Parent_Tag, "ada__tags__parent_tag");
154 -- This procedure is used in s-finimp and is thus exported manually
155
156 procedure Register_Tag (T : Tag);
157 -- Insert the Tag and its associated external_tag in a table for the
158 -- sake of Internal_Tag
159
160 procedure Set_Inheritance_Depth
161 (T : Tag;
162 Value : Natural);
163 -- Given a pointer to a dispatch Table, stores the value representing
164 -- the depth in the inheritance tree (the second parameter). Used during
165 -- elaboration of the tagged type.
166
167 procedure Set_Prim_Op_Address
168 (T : Tag;
169 Position : Positive;
170 Value : S.Address);
171 -- Given a pointer to a dispatch Table (T) and a position in the
172 -- dispatch Table put the address of the virtual function in it
173 -- (used for overriding)
174
175 procedure Set_TSD (T : Tag; Value : S.Address);
176 -- Given a pointer T to a dispatch Table, stores the address of the record
177 -- containing the Type Specific Data generated by GNAT
178
179 procedure Set_Expanded_Name (T : Tag; Value : S.Address);
180 -- Set the address of the string containing the expanded name
181 -- in the Dispatch table
182
183 procedure Set_External_Tag (T : Tag; Value : S.Address);
184 -- Set the address of the string containing the external tag
185 -- in the Dispatch table
186
187 procedure Set_RC_Offset (T : Tag; Value : SSE.Storage_Offset);
188 -- Sets the Offset of the implicit record controller when the object
189 -- has controlled components. Set to O otherwise.
190
191 procedure Set_Remotely_Callable (T : Tag; Value : Boolean);
192 -- Set to true if the type has been declared in a context described
193 -- in E.4 (18)
194
195 DT_Prologue_Size : constant SSE.Storage_Count :=
196 SSE.Storage_Count
197 (Standard'Address_Size / S.Storage_Unit);
198 -- Size of the first part of the dispatch table
199
200 DT_Entry_Size : constant SSE.Storage_Count :=
201 SSE.Storage_Count
202 (Standard'Address_Size / S.Storage_Unit);
203 -- Size of each primitive operation entry in the Dispatch Table.
204
205 TSD_Prologue_Size : constant SSE.Storage_Count :=
206 SSE.Storage_Count
207 (6 * Standard'Address_Size / S.Storage_Unit);
208 -- Size of the first part of the type specific data
209
210 TSD_Entry_Size : constant SSE.Storage_Count :=
211 SSE.Storage_Count (Standard'Address_Size / S.Storage_Unit);
212 -- Size of each ancestor tag entry in the TSD
213
214 type Address_Array is array (Natural range <>) of S.Address;
215
216 type Dispatch_Table;
217 type Tag is access all Dispatch_Table;
218
219 type Type_Specific_Data;
220 type Type_Specific_Data_Ptr is access all Type_Specific_Data;
221
222 pragma Inline_Always (CW_Membership);
223 pragma Inline_Always (Get_Expanded_Name);
224 pragma Inline_Always (Get_Inheritance_Depth);
225 pragma Inline_Always (Get_Prim_Op_Address);
226 pragma Inline_Always (Get_RC_Offset);
227 pragma Inline_Always (Get_Remotely_Callable);
228 pragma Inline_Always (Get_TSD);
229 pragma Inline_Always (Inherit_DT);
230 pragma Inline_Always (Inherit_TSD);
231 pragma Inline_Always (Register_Tag);
232 pragma Inline_Always (Set_Expanded_Name);
233 pragma Inline_Always (Set_External_Tag);
234 pragma Inline_Always (Set_Inheritance_Depth);
235 pragma Inline_Always (Set_Prim_Op_Address);
236 pragma Inline_Always (Set_RC_Offset);
237 pragma Inline_Always (Set_Remotely_Callable);
238 pragma Inline_Always (Set_TSD);
239
240 end Ada.Tags;