annotate gcc/ada/libgnat/a-tags.ads @ 145:1830386684a0

gcc-9.2.0
author anatofuz
date Thu, 13 Feb 2020 11:34:05 +0900
parents 84e7813d76e9
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
111
kono
parents:
diff changeset
1 ------------------------------------------------------------------------------
kono
parents:
diff changeset
2 -- --
kono
parents:
diff changeset
3 -- GNAT RUN-TIME COMPONENTS --
kono
parents:
diff changeset
4 -- --
kono
parents:
diff changeset
5 -- A D A . T A G S --
kono
parents:
diff changeset
6 -- --
kono
parents:
diff changeset
7 -- S p e c --
kono
parents:
diff changeset
8 -- --
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
9 -- Copyright (C) 1992-2019, Free Software Foundation, Inc. --
111
kono
parents:
diff changeset
10 -- --
kono
parents:
diff changeset
11 -- This specification is derived from the Ada Reference Manual for use with --
kono
parents:
diff changeset
12 -- GNAT. The copyright notice above, and the license provisions that follow --
kono
parents:
diff changeset
13 -- apply solely to the contents of the part following the private keyword. --
kono
parents:
diff changeset
14 -- --
kono
parents:
diff changeset
15 -- GNAT is free software; you can redistribute it and/or modify it under --
kono
parents:
diff changeset
16 -- terms of the GNU General Public License as published by the Free Soft- --
kono
parents:
diff changeset
17 -- ware Foundation; either version 3, or (at your option) any later ver- --
kono
parents:
diff changeset
18 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
kono
parents:
diff changeset
19 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
kono
parents:
diff changeset
20 -- or FITNESS FOR A PARTICULAR PURPOSE. --
kono
parents:
diff changeset
21 -- --
kono
parents:
diff changeset
22 -- As a special exception under Section 7 of GPL version 3, you are granted --
kono
parents:
diff changeset
23 -- additional permissions described in the GCC Runtime Library Exception, --
kono
parents:
diff changeset
24 -- version 3.1, as published by the Free Software Foundation. --
kono
parents:
diff changeset
25 -- --
kono
parents:
diff changeset
26 -- You should have received a copy of the GNU General Public License and --
kono
parents:
diff changeset
27 -- a copy of the GCC Runtime Library Exception along with this program; --
kono
parents:
diff changeset
28 -- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see --
kono
parents:
diff changeset
29 -- <http://www.gnu.org/licenses/>. --
kono
parents:
diff changeset
30 -- --
kono
parents:
diff changeset
31 -- GNAT was originally developed by the GNAT team at New York University. --
kono
parents:
diff changeset
32 -- Extensive contributions were provided by Ada Core Technologies Inc. --
kono
parents:
diff changeset
33 -- --
kono
parents:
diff changeset
34 ------------------------------------------------------------------------------
kono
parents:
diff changeset
35
kono
parents:
diff changeset
36 -- For performance analysis, take into account that the operations in this
kono
parents:
diff changeset
37 -- package provide the guarantee that all dispatching calls on primitive
kono
parents:
diff changeset
38 -- operations of tagged types and interfaces take constant time (in terms
kono
parents:
diff changeset
39 -- of source lines executed), that is to say, the cost of these calls is
kono
parents:
diff changeset
40 -- independent of the number of primitives of the type or interface, and
kono
parents:
diff changeset
41 -- independent of the number of ancestors or interface progenitors that a
kono
parents:
diff changeset
42 -- tagged type may have.
kono
parents:
diff changeset
43
kono
parents:
diff changeset
44 -- The following subprograms of the public part of this package take constant
kono
parents:
diff changeset
45 -- time (in terms of source lines executed):
kono
parents:
diff changeset
46
kono
parents:
diff changeset
47 -- Expanded_Name, Wide_Expanded_Name, Wide_Wide_Expanded_Name, External_Tag,
kono
parents:
diff changeset
48 -- Is_Abstract, Is_Descendant_At_Same_Level, Parent_Tag,
kono
parents:
diff changeset
49 -- Descendant_Tag (when used with a library-level tagged type),
kono
parents:
diff changeset
50 -- Internal_Tag (when used with a library-level tagged type).
kono
parents:
diff changeset
51
kono
parents:
diff changeset
52 -- The following subprograms of the public part of this package execute in
kono
parents:
diff changeset
53 -- time that is not constant (in terms of sources line executed):
kono
parents:
diff changeset
54
kono
parents:
diff changeset
55 -- Internal_Tag (when used with a locally defined tagged type), because in
kono
parents:
diff changeset
56 -- such cases this routine processes the external tag, extracts from it an
kono
parents:
diff changeset
57 -- address available there, and converts it into the tag value returned by
kono
parents:
diff changeset
58 -- this function. The number of instructions executed is not constant since
kono
parents:
diff changeset
59 -- it depends on the length of the external tag string.
kono
parents:
diff changeset
60
kono
parents:
diff changeset
61 -- Descendant_Tag (when used with a locally defined tagged type), because
kono
parents:
diff changeset
62 -- it relies on the subprogram Internal_Tag() to provide its functionality.
kono
parents:
diff changeset
63
kono
parents:
diff changeset
64 -- Interface_Ancestor_Tags, because this function returns a table whose
kono
parents:
diff changeset
65 -- length depends on the number of interfaces covered by a tagged type.
kono
parents:
diff changeset
66
kono
parents:
diff changeset
67 with System.Storage_Elements;
kono
parents:
diff changeset
68
kono
parents:
diff changeset
69 package Ada.Tags is
kono
parents:
diff changeset
70 pragma Preelaborate;
kono
parents:
diff changeset
71 -- In accordance with Ada 2005 AI-362
kono
parents:
diff changeset
72
kono
parents:
diff changeset
73 type Tag is private;
kono
parents:
diff changeset
74 pragma Preelaborable_Initialization (Tag);
kono
parents:
diff changeset
75
kono
parents:
diff changeset
76 No_Tag : constant Tag;
kono
parents:
diff changeset
77
kono
parents:
diff changeset
78 function Expanded_Name (T : Tag) return String;
kono
parents:
diff changeset
79
kono
parents:
diff changeset
80 function Wide_Expanded_Name (T : Tag) return Wide_String;
kono
parents:
diff changeset
81 pragma Ada_05 (Wide_Expanded_Name);
kono
parents:
diff changeset
82
kono
parents:
diff changeset
83 function Wide_Wide_Expanded_Name (T : Tag) return Wide_Wide_String;
kono
parents:
diff changeset
84 pragma Ada_05 (Wide_Wide_Expanded_Name);
kono
parents:
diff changeset
85
kono
parents:
diff changeset
86 function External_Tag (T : Tag) return String;
kono
parents:
diff changeset
87
kono
parents:
diff changeset
88 function Internal_Tag (External : String) return Tag;
kono
parents:
diff changeset
89
kono
parents:
diff changeset
90 function Descendant_Tag
kono
parents:
diff changeset
91 (External : String;
kono
parents:
diff changeset
92 Ancestor : Tag) return Tag;
kono
parents:
diff changeset
93 pragma Ada_05 (Descendant_Tag);
kono
parents:
diff changeset
94
kono
parents:
diff changeset
95 function Is_Descendant_At_Same_Level
kono
parents:
diff changeset
96 (Descendant : Tag;
kono
parents:
diff changeset
97 Ancestor : Tag) return Boolean;
kono
parents:
diff changeset
98 pragma Ada_05 (Is_Descendant_At_Same_Level);
kono
parents:
diff changeset
99
kono
parents:
diff changeset
100 function Parent_Tag (T : Tag) return Tag;
kono
parents:
diff changeset
101 pragma Ada_05 (Parent_Tag);
kono
parents:
diff changeset
102
kono
parents:
diff changeset
103 type Tag_Array is array (Positive range <>) of Tag;
kono
parents:
diff changeset
104
kono
parents:
diff changeset
105 function Interface_Ancestor_Tags (T : Tag) return Tag_Array;
kono
parents:
diff changeset
106 pragma Ada_05 (Interface_Ancestor_Tags);
kono
parents:
diff changeset
107
kono
parents:
diff changeset
108 function Is_Abstract (T : Tag) return Boolean;
kono
parents:
diff changeset
109 pragma Ada_2012 (Is_Abstract);
kono
parents:
diff changeset
110
kono
parents:
diff changeset
111 Tag_Error : exception;
kono
parents:
diff changeset
112
kono
parents:
diff changeset
113 private
kono
parents:
diff changeset
114 -- Structure of the GNAT Primary Dispatch Table
kono
parents:
diff changeset
115
kono
parents:
diff changeset
116 -- +--------------------+
kono
parents:
diff changeset
117 -- | Signature |
kono
parents:
diff changeset
118 -- +--------------------+
kono
parents:
diff changeset
119 -- | Tagged_Kind |
kono
parents:
diff changeset
120 -- +--------------------+ Predef Prims
kono
parents:
diff changeset
121 -- | Predef_Prims -----------------------------> +------------+
kono
parents:
diff changeset
122 -- +--------------------+ | table of |
kono
parents:
diff changeset
123 -- | Offset_To_Top | | predefined |
kono
parents:
diff changeset
124 -- +--------------------+ | primitives |
kono
parents:
diff changeset
125 -- |Typeinfo_Ptr/TSD_Ptr---> Type Specific Data +------------+
kono
parents:
diff changeset
126 -- Tag ---> +--------------------+ +-------------------+
kono
parents:
diff changeset
127 -- | table of | | inheritance depth |
kono
parents:
diff changeset
128 -- : primitive ops : +-------------------+
kono
parents:
diff changeset
129 -- | pointers | | access level |
kono
parents:
diff changeset
130 -- +--------------------+ +-------------------+
kono
parents:
diff changeset
131 -- | alignment |
kono
parents:
diff changeset
132 -- +-------------------+
kono
parents:
diff changeset
133 -- | expanded name |
kono
parents:
diff changeset
134 -- +-------------------+
kono
parents:
diff changeset
135 -- | external tag |
kono
parents:
diff changeset
136 -- +-------------------+
kono
parents:
diff changeset
137 -- | hash table link |
kono
parents:
diff changeset
138 -- +-------------------+
kono
parents:
diff changeset
139 -- | transportable |
kono
parents:
diff changeset
140 -- +-------------------+
kono
parents:
diff changeset
141 -- | is_abstract |
kono
parents:
diff changeset
142 -- +-------------------+
kono
parents:
diff changeset
143 -- | needs finalization|
kono
parents:
diff changeset
144 -- +-------------------+
kono
parents:
diff changeset
145 -- | Ifaces_Table ---> Interface Data
kono
parents:
diff changeset
146 -- +-------------------+ +------------+
kono
parents:
diff changeset
147 -- Select Specific Data <---- SSD | | Nb_Ifaces |
kono
parents:
diff changeset
148 -- +------------------+ +-------------------+ +------------+
kono
parents:
diff changeset
149 -- |table of primitive| | table of | | table |
kono
parents:
diff changeset
150 -- : operation : : ancestor : : of :
kono
parents:
diff changeset
151 -- | kinds | | tags | | interfaces |
kono
parents:
diff changeset
152 -- +------------------+ +-------------------+ +------------+
kono
parents:
diff changeset
153 -- |table of |
kono
parents:
diff changeset
154 -- : entry :
kono
parents:
diff changeset
155 -- | indexes |
kono
parents:
diff changeset
156 -- +------------------+
kono
parents:
diff changeset
157
kono
parents:
diff changeset
158 -- Structure of the GNAT Secondary Dispatch Table
kono
parents:
diff changeset
159
kono
parents:
diff changeset
160 -- +--------------------+
kono
parents:
diff changeset
161 -- | Signature |
kono
parents:
diff changeset
162 -- +--------------------+
kono
parents:
diff changeset
163 -- | Tagged_Kind |
kono
parents:
diff changeset
164 -- +--------------------+ Predef Prims
kono
parents:
diff changeset
165 -- | Predef_Prims -----------------------------> +------------+
kono
parents:
diff changeset
166 -- +--------------------+ | table of |
kono
parents:
diff changeset
167 -- | Offset_To_Top | | predefined |
kono
parents:
diff changeset
168 -- +--------------------+ | primitives |
kono
parents:
diff changeset
169 -- | OSD_Ptr |---> Object Specific Data | thunks |
kono
parents:
diff changeset
170 -- Tag ---> +--------------------+ +---------------+ +------------+
kono
parents:
diff changeset
171 -- | table of | | num prim ops |
kono
parents:
diff changeset
172 -- : primitive op : +---------------+
kono
parents:
diff changeset
173 -- | thunk pointers | | table of |
kono
parents:
diff changeset
174 -- +--------------------+ + primitive |
kono
parents:
diff changeset
175 -- | op offsets |
kono
parents:
diff changeset
176 -- +---------------+
kono
parents:
diff changeset
177
kono
parents:
diff changeset
178 -- The runtime information kept for each tagged type is separated into two
kono
parents:
diff changeset
179 -- objects: the Dispatch Table and the Type Specific Data record.
kono
parents:
diff changeset
180
kono
parents:
diff changeset
181 package SSE renames System.Storage_Elements;
kono
parents:
diff changeset
182
kono
parents:
diff changeset
183 subtype Cstring is String (Positive);
kono
parents:
diff changeset
184 type Cstring_Ptr is access all Cstring;
kono
parents:
diff changeset
185 pragma No_Strict_Aliasing (Cstring_Ptr);
kono
parents:
diff changeset
186
kono
parents:
diff changeset
187 -- Declarations for the table of interfaces
kono
parents:
diff changeset
188
kono
parents:
diff changeset
189 type Offset_To_Top_Function_Ptr is
kono
parents:
diff changeset
190 access function (This : System.Address) return SSE.Storage_Offset;
kono
parents:
diff changeset
191 -- Type definition used to call the function that is generated by the
kono
parents:
diff changeset
192 -- expander in case of tagged types with discriminants that have secondary
kono
parents:
diff changeset
193 -- dispatch tables. This function provides the Offset_To_Top value in this
kono
parents:
diff changeset
194 -- specific case.
kono
parents:
diff changeset
195
kono
parents:
diff changeset
196 type Interface_Data_Element is record
kono
parents:
diff changeset
197 Iface_Tag : Tag;
kono
parents:
diff changeset
198 Static_Offset_To_Top : Boolean;
kono
parents:
diff changeset
199 Offset_To_Top_Value : SSE.Storage_Offset;
kono
parents:
diff changeset
200 Offset_To_Top_Func : Offset_To_Top_Function_Ptr;
kono
parents:
diff changeset
201 Secondary_DT : Tag;
kono
parents:
diff changeset
202 end record;
kono
parents:
diff changeset
203 -- If some ancestor of the tagged type has discriminants the field
kono
parents:
diff changeset
204 -- Static_Offset_To_Top is False and the field Offset_To_Top_Func
kono
parents:
diff changeset
205 -- is used to store the access to the function generated by the
kono
parents:
diff changeset
206 -- expander which provides this value; otherwise Static_Offset_To_Top
kono
parents:
diff changeset
207 -- is True and such value is stored in the Offset_To_Top_Value field.
kono
parents:
diff changeset
208 -- Secondary_DT references a secondary dispatch table whose contents
kono
parents:
diff changeset
209 -- are pointers to the primitives of the tagged type that cover the
kono
parents:
diff changeset
210 -- interface primitives. Secondary_DT gives support to dispatching
kono
parents:
diff changeset
211 -- calls through interface types associated with Generic Dispatching
kono
parents:
diff changeset
212 -- Constructors.
kono
parents:
diff changeset
213
kono
parents:
diff changeset
214 type Interfaces_Array is array (Natural range <>) of Interface_Data_Element;
kono
parents:
diff changeset
215
kono
parents:
diff changeset
216 type Interface_Data (Nb_Ifaces : Positive) is record
kono
parents:
diff changeset
217 Ifaces_Table : Interfaces_Array (1 .. Nb_Ifaces);
kono
parents:
diff changeset
218 end record;
kono
parents:
diff changeset
219
kono
parents:
diff changeset
220 type Interface_Data_Ptr is access all Interface_Data;
kono
parents:
diff changeset
221 -- Table of abstract interfaces used to give support to backward interface
kono
parents:
diff changeset
222 -- conversions and also to IW_Membership.
kono
parents:
diff changeset
223
kono
parents:
diff changeset
224 -- Primitive operation kinds. These values differentiate the kinds of
kono
parents:
diff changeset
225 -- callable entities stored in the dispatch table. Certain kinds may
kono
parents:
diff changeset
226 -- not be used, but are added for completeness.
kono
parents:
diff changeset
227
kono
parents:
diff changeset
228 type Prim_Op_Kind is
kono
parents:
diff changeset
229 (POK_Function,
kono
parents:
diff changeset
230 POK_Procedure,
kono
parents:
diff changeset
231 POK_Protected_Entry,
kono
parents:
diff changeset
232 POK_Protected_Function,
kono
parents:
diff changeset
233 POK_Protected_Procedure,
kono
parents:
diff changeset
234 POK_Task_Entry,
kono
parents:
diff changeset
235 POK_Task_Function,
kono
parents:
diff changeset
236 POK_Task_Procedure);
kono
parents:
diff changeset
237
kono
parents:
diff changeset
238 -- Select specific data types
kono
parents:
diff changeset
239
kono
parents:
diff changeset
240 type Select_Specific_Data_Element is record
kono
parents:
diff changeset
241 Index : Positive;
kono
parents:
diff changeset
242 Kind : Prim_Op_Kind;
kono
parents:
diff changeset
243 end record;
kono
parents:
diff changeset
244
kono
parents:
diff changeset
245 type Select_Specific_Data_Array is
kono
parents:
diff changeset
246 array (Positive range <>) of Select_Specific_Data_Element;
kono
parents:
diff changeset
247
kono
parents:
diff changeset
248 type Select_Specific_Data (Nb_Prim : Positive) is record
kono
parents:
diff changeset
249 SSD_Table : Select_Specific_Data_Array (1 .. Nb_Prim);
kono
parents:
diff changeset
250 -- NOTE: Nb_Prim is the number of non-predefined primitive operations
kono
parents:
diff changeset
251 end record;
kono
parents:
diff changeset
252
kono
parents:
diff changeset
253 type Select_Specific_Data_Ptr is access all Select_Specific_Data;
kono
parents:
diff changeset
254 -- A table used to store the primitive operation kind and entry index of
kono
parents:
diff changeset
255 -- primitive subprograms of a type that implements a limited interface.
kono
parents:
diff changeset
256 -- The Select Specific Data table resides in the Type Specific Data of a
kono
parents:
diff changeset
257 -- type. This construct is used in the handling of dispatching triggers
kono
parents:
diff changeset
258 -- in select statements.
kono
parents:
diff changeset
259
kono
parents:
diff changeset
260 type Prim_Ptr is access procedure;
kono
parents:
diff changeset
261 type Address_Array is array (Positive range <>) of Prim_Ptr;
kono
parents:
diff changeset
262
kono
parents:
diff changeset
263 subtype Dispatch_Table is Address_Array (1 .. 1);
kono
parents:
diff changeset
264 -- Used by GDB to identify the _tags and traverse the run-time structure
kono
parents:
diff changeset
265 -- associated with tagged types. For compatibility with older versions of
kono
parents:
diff changeset
266 -- gdb, its name must not be changed.
kono
parents:
diff changeset
267
kono
parents:
diff changeset
268 type Tag is access all Dispatch_Table;
kono
parents:
diff changeset
269 pragma No_Strict_Aliasing (Tag);
kono
parents:
diff changeset
270
kono
parents:
diff changeset
271 type Interface_Tag is access all Dispatch_Table;
kono
parents:
diff changeset
272
kono
parents:
diff changeset
273 No_Tag : constant Tag := null;
kono
parents:
diff changeset
274
kono
parents:
diff changeset
275 -- The expander ensures that Tag objects reference the Prims_Ptr component
kono
parents:
diff changeset
276 -- of the wrapper.
kono
parents:
diff changeset
277
kono
parents:
diff changeset
278 type Tag_Ptr is access all Tag;
kono
parents:
diff changeset
279 pragma No_Strict_Aliasing (Tag_Ptr);
kono
parents:
diff changeset
280
kono
parents:
diff changeset
281 type Offset_To_Top_Ptr is access all SSE.Storage_Offset;
kono
parents:
diff changeset
282 pragma No_Strict_Aliasing (Offset_To_Top_Ptr);
kono
parents:
diff changeset
283
kono
parents:
diff changeset
284 type Tag_Table is array (Natural range <>) of Tag;
kono
parents:
diff changeset
285
kono
parents:
diff changeset
286 type Size_Ptr is
kono
parents:
diff changeset
287 access function (A : System.Address) return Long_Long_Integer;
kono
parents:
diff changeset
288
kono
parents:
diff changeset
289 type Type_Specific_Data (Idepth : Natural) is record
kono
parents:
diff changeset
290 -- The discriminant Idepth is the Inheritance Depth Level: Used to
kono
parents:
diff changeset
291 -- implement the membership test associated with single inheritance of
kono
parents:
diff changeset
292 -- tagged types in constant-time. It also indicates the size of the
kono
parents:
diff changeset
293 -- Tags_Table component.
kono
parents:
diff changeset
294
kono
parents:
diff changeset
295 Access_Level : Natural;
kono
parents:
diff changeset
296 -- Accessibility level required to give support to Ada 2005 nested type
kono
parents:
diff changeset
297 -- extensions. This feature allows safe nested type extensions by
kono
parents:
diff changeset
298 -- shifting the accessibility checks to certain operations, rather than
kono
parents:
diff changeset
299 -- being enforced at the type declaration. In particular, by performing
kono
parents:
diff changeset
300 -- run-time accessibility checks on class-wide allocators, class-wide
kono
parents:
diff changeset
301 -- function return, and class-wide stream I/O, the danger of objects
kono
parents:
diff changeset
302 -- outliving their type declaration can be eliminated (Ada 2005: AI-344)
kono
parents:
diff changeset
303
kono
parents:
diff changeset
304 Alignment : Natural;
kono
parents:
diff changeset
305 Expanded_Name : Cstring_Ptr;
kono
parents:
diff changeset
306 External_Tag : Cstring_Ptr;
kono
parents:
diff changeset
307 HT_Link : Tag_Ptr;
kono
parents:
diff changeset
308 -- Components used to support to the Ada.Tags subprograms in RM 3.9
kono
parents:
diff changeset
309
kono
parents:
diff changeset
310 -- Note: Expanded_Name is referenced by GDB to determine the actual name
kono
parents:
diff changeset
311 -- of the tagged type. Its requirements are: 1) it must have this exact
kono
parents:
diff changeset
312 -- name, and 2) its contents must point to a C-style Nul terminated
kono
parents:
diff changeset
313 -- string containing its expanded name. GDB has no requirement on a
kono
parents:
diff changeset
314 -- given position inside the record.
kono
parents:
diff changeset
315
kono
parents:
diff changeset
316 Transportable : Boolean;
kono
parents:
diff changeset
317 -- Used to check RM E.4(18), set for types that satisfy the requirements
kono
parents:
diff changeset
318 -- for being used in remote calls as actuals for classwide formals or as
kono
parents:
diff changeset
319 -- return values for classwide functions.
kono
parents:
diff changeset
320
kono
parents:
diff changeset
321 Is_Abstract : Boolean;
kono
parents:
diff changeset
322 -- True if the type is abstract (Ada 2012: AI05-0173)
kono
parents:
diff changeset
323
kono
parents:
diff changeset
324 Needs_Finalization : Boolean;
kono
parents:
diff changeset
325 -- Used to dynamically check whether an object is controlled or not
kono
parents:
diff changeset
326
kono
parents:
diff changeset
327 Size_Func : Size_Ptr;
kono
parents:
diff changeset
328 -- Pointer to the subprogram computing the _size of the object. Used by
kono
parents:
diff changeset
329 -- the run-time whenever a call to the 'size primitive is required. We
kono
parents:
diff changeset
330 -- cannot assume that the contents of dispatch tables are addresses
kono
parents:
diff changeset
331 -- because in some architectures the ABI allows descriptors.
kono
parents:
diff changeset
332
kono
parents:
diff changeset
333 Interfaces_Table : Interface_Data_Ptr;
kono
parents:
diff changeset
334 -- Pointer to the table of interface tags. It is used to implement the
kono
parents:
diff changeset
335 -- membership test associated with interfaces and also for backward
kono
parents:
diff changeset
336 -- abstract interface type conversions (Ada 2005:AI-251)
kono
parents:
diff changeset
337
kono
parents:
diff changeset
338 SSD : Select_Specific_Data_Ptr;
kono
parents:
diff changeset
339 -- Pointer to a table of records used in dispatching selects. This field
kono
parents:
diff changeset
340 -- has a meaningful value for all tagged types that implement a limited,
kono
parents:
diff changeset
341 -- protected, synchronized or task interfaces and have non-predefined
kono
parents:
diff changeset
342 -- primitive operations.
kono
parents:
diff changeset
343
kono
parents:
diff changeset
344 Tags_Table : Tag_Table (0 .. Idepth);
kono
parents:
diff changeset
345 -- Table of ancestor tags. Its size actually depends on the inheritance
kono
parents:
diff changeset
346 -- depth level of the tagged type.
kono
parents:
diff changeset
347 end record;
kono
parents:
diff changeset
348
kono
parents:
diff changeset
349 type Type_Specific_Data_Ptr is access all Type_Specific_Data;
kono
parents:
diff changeset
350 pragma No_Strict_Aliasing (Type_Specific_Data_Ptr);
kono
parents:
diff changeset
351
kono
parents:
diff changeset
352 -- Declarations for the dispatch table record
kono
parents:
diff changeset
353
kono
parents:
diff changeset
354 type Signature_Kind is
kono
parents:
diff changeset
355 (Unknown,
kono
parents:
diff changeset
356 Primary_DT,
kono
parents:
diff changeset
357 Secondary_DT);
kono
parents:
diff changeset
358
kono
parents:
diff changeset
359 -- Tagged type kinds with respect to concurrency and limitedness
kono
parents:
diff changeset
360
kono
parents:
diff changeset
361 type Tagged_Kind is
kono
parents:
diff changeset
362 (TK_Abstract_Limited_Tagged,
kono
parents:
diff changeset
363 TK_Abstract_Tagged,
kono
parents:
diff changeset
364 TK_Limited_Tagged,
kono
parents:
diff changeset
365 TK_Protected,
kono
parents:
diff changeset
366 TK_Tagged,
kono
parents:
diff changeset
367 TK_Task);
kono
parents:
diff changeset
368
kono
parents:
diff changeset
369 type Dispatch_Table_Wrapper (Num_Prims : Natural) is record
kono
parents:
diff changeset
370 Signature : Signature_Kind;
kono
parents:
diff changeset
371 Tag_Kind : Tagged_Kind;
kono
parents:
diff changeset
372 Predef_Prims : System.Address;
kono
parents:
diff changeset
373 -- Pointer to the dispatch table of predefined Ada primitives
kono
parents:
diff changeset
374
kono
parents:
diff changeset
375 -- According to the C++ ABI the components Offset_To_Top and TSD are
kono
parents:
diff changeset
376 -- stored just "before" the dispatch table, and they are referenced with
kono
parents:
diff changeset
377 -- negative offsets referring to the base of the dispatch table. The
kono
parents:
diff changeset
378 -- _Tag (or the VTable_Ptr in C++ terminology) must point to the base
kono
parents:
diff changeset
379 -- of the virtual table, just after these components, to point to the
kono
parents:
diff changeset
380 -- Prims_Ptr table.
kono
parents:
diff changeset
381
kono
parents:
diff changeset
382 Offset_To_Top : SSE.Storage_Offset;
kono
parents:
diff changeset
383 -- Offset between the _Tag field and the field that contains the
kono
parents:
diff changeset
384 -- reference to this dispatch table. For primary dispatch tables it is
kono
parents:
diff changeset
385 -- zero. For secondary dispatch tables: if the parent record type (if
kono
parents:
diff changeset
386 -- any) has a compile-time-known size, then Offset_To_Top contains the
kono
parents:
diff changeset
387 -- expected value, otherwise it contains SSE.Storage_Offset'Last and the
kono
parents:
diff changeset
388 -- actual offset is to be found in the tagged record, right after the
kono
parents:
diff changeset
389 -- field that contains the reference to this dispatch table. See the
kono
parents:
diff changeset
390 -- implementation of Ada.Tags.Offset_To_Top for the corresponding logic.
kono
parents:
diff changeset
391
kono
parents:
diff changeset
392 TSD : System.Address;
kono
parents:
diff changeset
393
kono
parents:
diff changeset
394 Prims_Ptr : aliased Address_Array (1 .. Num_Prims);
kono
parents:
diff changeset
395 -- The size of the Prims_Ptr array actually depends on the tagged type
kono
parents:
diff changeset
396 -- to which it applies. For each tagged type, the expander computes the
kono
parents:
diff changeset
397 -- actual array size, allocating the Dispatch_Table record accordingly.
kono
parents:
diff changeset
398 end record;
kono
parents:
diff changeset
399
kono
parents:
diff changeset
400 type Dispatch_Table_Ptr is access all Dispatch_Table_Wrapper;
kono
parents:
diff changeset
401 pragma No_Strict_Aliasing (Dispatch_Table_Ptr);
kono
parents:
diff changeset
402
kono
parents:
diff changeset
403 -- The following type declaration is used by the compiler when the program
kono
parents:
diff changeset
404 -- is compiled with restriction No_Dispatching_Calls. It is also used with
kono
parents:
diff changeset
405 -- interface types to generate the tag and run-time information associated
kono
parents:
diff changeset
406 -- with them.
kono
parents:
diff changeset
407
kono
parents:
diff changeset
408 type No_Dispatch_Table_Wrapper is record
kono
parents:
diff changeset
409 NDT_TSD : System.Address;
kono
parents:
diff changeset
410 NDT_Prims_Ptr : Natural;
kono
parents:
diff changeset
411 end record;
kono
parents:
diff changeset
412
kono
parents:
diff changeset
413 DT_Predef_Prims_Size : constant SSE.Storage_Count :=
kono
parents:
diff changeset
414 SSE.Storage_Count
kono
parents:
diff changeset
415 (1 * (Standard'Address_Size /
kono
parents:
diff changeset
416 System.Storage_Unit));
kono
parents:
diff changeset
417 -- Size of the Predef_Prims field of the Dispatch_Table
kono
parents:
diff changeset
418
kono
parents:
diff changeset
419 DT_Offset_To_Top_Size : constant SSE.Storage_Count :=
kono
parents:
diff changeset
420 SSE.Storage_Count
kono
parents:
diff changeset
421 (1 * (Standard'Address_Size /
kono
parents:
diff changeset
422 System.Storage_Unit));
kono
parents:
diff changeset
423 -- Size of the Offset_To_Top field of the Dispatch Table
kono
parents:
diff changeset
424
kono
parents:
diff changeset
425 DT_Typeinfo_Ptr_Size : constant SSE.Storage_Count :=
kono
parents:
diff changeset
426 SSE.Storage_Count
kono
parents:
diff changeset
427 (1 * (Standard'Address_Size /
kono
parents:
diff changeset
428 System.Storage_Unit));
kono
parents:
diff changeset
429 -- Size of the Typeinfo_Ptr field of the Dispatch Table
kono
parents:
diff changeset
430
kono
parents:
diff changeset
431 use type System.Storage_Elements.Storage_Offset;
kono
parents:
diff changeset
432
kono
parents:
diff changeset
433 DT_Offset_To_Top_Offset : constant SSE.Storage_Count :=
kono
parents:
diff changeset
434 DT_Typeinfo_Ptr_Size
kono
parents:
diff changeset
435 + DT_Offset_To_Top_Size;
kono
parents:
diff changeset
436
kono
parents:
diff changeset
437 DT_Predef_Prims_Offset : constant SSE.Storage_Count :=
kono
parents:
diff changeset
438 DT_Typeinfo_Ptr_Size
kono
parents:
diff changeset
439 + DT_Offset_To_Top_Size
kono
parents:
diff changeset
440 + DT_Predef_Prims_Size;
kono
parents:
diff changeset
441 -- Offset from Prims_Ptr to Predef_Prims component
kono
parents:
diff changeset
442
kono
parents:
diff changeset
443 -- Object Specific Data record of secondary dispatch tables
kono
parents:
diff changeset
444
kono
parents:
diff changeset
445 type Object_Specific_Data_Array is array (Positive range <>) of Positive;
kono
parents:
diff changeset
446
kono
parents:
diff changeset
447 type Object_Specific_Data (OSD_Num_Prims : Positive) is record
kono
parents:
diff changeset
448 OSD_Table : Object_Specific_Data_Array (1 .. OSD_Num_Prims);
kono
parents:
diff changeset
449 -- Table used in secondary DT to reference their counterpart in the
kono
parents:
diff changeset
450 -- select specific data (in the TSD of the primary DT). This construct
kono
parents:
diff changeset
451 -- is used in the handling of dispatching triggers in select statements.
kono
parents:
diff changeset
452 -- Nb_Prim is the number of non-predefined primitive operations.
kono
parents:
diff changeset
453 end record;
kono
parents:
diff changeset
454
kono
parents:
diff changeset
455 type Object_Specific_Data_Ptr is access all Object_Specific_Data;
kono
parents:
diff changeset
456 pragma No_Strict_Aliasing (Object_Specific_Data_Ptr);
kono
parents:
diff changeset
457
kono
parents:
diff changeset
458 -- The following subprogram specifications are placed here instead of the
kono
parents:
diff changeset
459 -- package body to see them from the frontend through rtsfind.
kono
parents:
diff changeset
460
kono
parents:
diff changeset
461 function Base_Address (This : System.Address) return System.Address;
kono
parents:
diff changeset
462 -- Ada 2005 (AI-251): Displace "This" to point to the base address of the
kono
parents:
diff changeset
463 -- object (that is, the address of the primary tag of the object).
kono
parents:
diff changeset
464
kono
parents:
diff changeset
465 procedure Check_TSD (TSD : Type_Specific_Data_Ptr);
kono
parents:
diff changeset
466 -- Ada 2012 (AI-113): Raise Program_Error if the external tag of this TSD
kono
parents:
diff changeset
467 -- is the same as the external tag for some other tagged type declaration.
kono
parents:
diff changeset
468
kono
parents:
diff changeset
469 function Displace (This : System.Address; T : Tag) return System.Address;
kono
parents:
diff changeset
470 -- Ada 2005 (AI-251): Displace "This" to point to the secondary dispatch
kono
parents:
diff changeset
471 -- table of T.
kono
parents:
diff changeset
472
kono
parents:
diff changeset
473 function Secondary_Tag (T, Iface : Tag) return Tag;
kono
parents:
diff changeset
474 -- Ada 2005 (AI-251): Given a primary tag T associated with a tagged type
kono
parents:
diff changeset
475 -- Typ, search for the secondary tag of the interface type Iface covered
kono
parents:
diff changeset
476 -- by Typ.
kono
parents:
diff changeset
477
kono
parents:
diff changeset
478 function DT (T : Tag) return Dispatch_Table_Ptr;
kono
parents:
diff changeset
479 -- Return the pointer to the TSD record associated with T
kono
parents:
diff changeset
480
kono
parents:
diff changeset
481 function Get_Entry_Index (T : Tag; Position : Positive) return Positive;
kono
parents:
diff changeset
482 -- Ada 2005 (AI-251): Return a primitive operation's entry index (if entry)
kono
parents:
diff changeset
483 -- given a dispatch table T and a position of a primitive operation in T.
kono
parents:
diff changeset
484
kono
parents:
diff changeset
485 function Get_Offset_Index
kono
parents:
diff changeset
486 (T : Tag;
kono
parents:
diff changeset
487 Position : Positive) return Positive;
kono
parents:
diff changeset
488 -- Ada 2005 (AI-251): Given a pointer to a secondary dispatch table (T)
kono
parents:
diff changeset
489 -- and a position of an operation in the DT, retrieve the corresponding
kono
parents:
diff changeset
490 -- operation's position in the primary dispatch table from the Offset
kono
parents:
diff changeset
491 -- Specific Data table of T.
kono
parents:
diff changeset
492
kono
parents:
diff changeset
493 function Get_Prim_Op_Kind
kono
parents:
diff changeset
494 (T : Tag;
kono
parents:
diff changeset
495 Position : Positive) return Prim_Op_Kind;
kono
parents:
diff changeset
496 -- Ada 2005 (AI-251): Return a primitive operation's kind given a dispatch
kono
parents:
diff changeset
497 -- table T and a position of a primitive operation in T.
kono
parents:
diff changeset
498
kono
parents:
diff changeset
499 function Get_Tagged_Kind (T : Tag) return Tagged_Kind;
kono
parents:
diff changeset
500 -- Ada 2005 (AI-345): Given a pointer to either a primary or a secondary
kono
parents:
diff changeset
501 -- dispatch table, return the tagged kind of a type in the context of
kono
parents:
diff changeset
502 -- concurrency and limitedness.
kono
parents:
diff changeset
503
kono
parents:
diff changeset
504 function IW_Membership (This : System.Address; T : Tag) return Boolean;
kono
parents:
diff changeset
505 -- Ada 2005 (AI-251): General routine that checks if a given object
kono
parents:
diff changeset
506 -- implements a tagged type. Its common usage is to check if Obj is in
kono
parents:
diff changeset
507 -- Iface'Class, but it is also used to check if a class-wide interface
kono
parents:
diff changeset
508 -- implements a given type (Iface_CW_Typ in T'Class). For example:
kono
parents:
diff changeset
509 --
kono
parents:
diff changeset
510 -- type I is interface;
kono
parents:
diff changeset
511 -- type T is tagged ...
kono
parents:
diff changeset
512 --
kono
parents:
diff changeset
513 -- function Test (O : I'Class) is
kono
parents:
diff changeset
514 -- begin
kono
parents:
diff changeset
515 -- return O in T'Class.
kono
parents:
diff changeset
516 -- end Test;
kono
parents:
diff changeset
517
kono
parents:
diff changeset
518 function Offset_To_Top
kono
parents:
diff changeset
519 (This : System.Address) return SSE.Storage_Offset;
kono
parents:
diff changeset
520 -- Ada 2005 (AI-251): Returns the current value of the Offset_To_Top
kono
parents:
diff changeset
521 -- component available in the prologue of the dispatch table. If the parent
kono
parents:
diff changeset
522 -- of the tagged type has discriminants this value is stored in a record
kono
parents:
diff changeset
523 -- component just immediately after the tag component.
kono
parents:
diff changeset
524
kono
parents:
diff changeset
525 function Needs_Finalization (T : Tag) return Boolean;
kono
parents:
diff changeset
526 -- A helper routine used in conjunction with finalization collections which
kono
parents:
diff changeset
527 -- service class-wide types. The function dynamically determines whether an
kono
parents:
diff changeset
528 -- object is controlled or has controlled components.
kono
parents:
diff changeset
529
kono
parents:
diff changeset
530 function Parent_Size
kono
parents:
diff changeset
531 (Obj : System.Address;
kono
parents:
diff changeset
532 T : Tag) return SSE.Storage_Count;
kono
parents:
diff changeset
533 -- Computes the size the ancestor part of a tagged extension object whose
kono
parents:
diff changeset
534 -- address is 'obj' by calling indirectly the ancestor _size function. The
kono
parents:
diff changeset
535 -- ancestor is the parent of the type represented by tag T. This function
kono
parents:
diff changeset
536 -- assumes that _size is always in slot one of the dispatch table.
kono
parents:
diff changeset
537
kono
parents:
diff changeset
538 procedure Register_Interface_Offset
kono
parents:
diff changeset
539 (Prim_T : Tag;
kono
parents:
diff changeset
540 Interface_T : Tag;
kono
parents:
diff changeset
541 Is_Static : Boolean;
kono
parents:
diff changeset
542 Offset_Value : SSE.Storage_Offset;
kono
parents:
diff changeset
543 Offset_Func : Offset_To_Top_Function_Ptr);
kono
parents:
diff changeset
544 -- Register in the table of interfaces of the tagged type associated with
kono
parents:
diff changeset
545 -- Prim_T the offset of the record component associated with the progenitor
kono
parents:
diff changeset
546 -- Interface_T (that is, the distance from "This" to the object component
kono
parents:
diff changeset
547 -- containing the tag of the secondary dispatch table). In case of constant
kono
parents:
diff changeset
548 -- offset, Is_Static is true and Offset_Value has such value. In case of
kono
parents:
diff changeset
549 -- variable offset, Is_Static is false and Offset_Func is an access to
kono
parents:
diff changeset
550 -- function that must be called to evaluate the offset.
kono
parents:
diff changeset
551
kono
parents:
diff changeset
552 procedure Register_Tag (T : Tag);
kono
parents:
diff changeset
553 -- Insert the Tag and its associated external_tag in a table for the sake
kono
parents:
diff changeset
554 -- of Internal_Tag.
kono
parents:
diff changeset
555
kono
parents:
diff changeset
556 procedure Set_Dynamic_Offset_To_Top
kono
parents:
diff changeset
557 (This : System.Address;
kono
parents:
diff changeset
558 Prim_T : Tag;
kono
parents:
diff changeset
559 Interface_T : Tag;
kono
parents:
diff changeset
560 Offset_Value : SSE.Storage_Offset;
kono
parents:
diff changeset
561 Offset_Func : Offset_To_Top_Function_Ptr);
kono
parents:
diff changeset
562 -- Ada 2005 (AI-251): The compiler generates calls to this routine only
kono
parents:
diff changeset
563 -- when initializing the Offset_To_Top field of dispatch tables of tagged
kono
parents:
diff changeset
564 -- types that cover interface types whose parent type has variable size
kono
parents:
diff changeset
565 -- components.
kono
parents:
diff changeset
566 --
kono
parents:
diff changeset
567 -- "This" is the object whose dispatch table is being initialized. Prim_T
kono
parents:
diff changeset
568 -- is the primary tag of such object. Interface_T is the interface tag for
kono
parents:
diff changeset
569 -- which the secondary dispatch table is being initialized. Offset_Value
kono
parents:
diff changeset
570 -- is the distance from "This" to the object component containing the tag
kono
parents:
diff changeset
571 -- of the secondary dispatch table (a zero value means that this interface
kono
parents:
diff changeset
572 -- shares the primary dispatch table). Offset_Func references a function
kono
parents:
diff changeset
573 -- that must be called to evaluate the offset at run time. This routine
kono
parents:
diff changeset
574 -- also takes care of registering these values in the table of interfaces
kono
parents:
diff changeset
575 -- of the type.
kono
parents:
diff changeset
576
kono
parents:
diff changeset
577 procedure Set_Entry_Index (T : Tag; Position : Positive; Value : Positive);
kono
parents:
diff changeset
578 -- Ada 2005 (AI-345): Set the entry index of a primitive operation in T's
kono
parents:
diff changeset
579 -- TSD table indexed by Position.
kono
parents:
diff changeset
580
kono
parents:
diff changeset
581 procedure Set_Prim_Op_Kind
kono
parents:
diff changeset
582 (T : Tag;
kono
parents:
diff changeset
583 Position : Positive;
kono
parents:
diff changeset
584 Value : Prim_Op_Kind);
kono
parents:
diff changeset
585 -- Ada 2005 (AI-251): Set the kind of a primitive operation in T's TSD
kono
parents:
diff changeset
586 -- table indexed by Position.
kono
parents:
diff changeset
587
kono
parents:
diff changeset
588 procedure Unregister_Tag (T : Tag);
kono
parents:
diff changeset
589 -- Remove a particular tag from the external tag hash table
kono
parents:
diff changeset
590
kono
parents:
diff changeset
591 Max_Predef_Prims : constant Positive := 15;
kono
parents:
diff changeset
592 -- Number of reserved slots for the following predefined ada primitives:
kono
parents:
diff changeset
593 --
kono
parents:
diff changeset
594 -- 1. Size
kono
parents:
diff changeset
595 -- 2. Read
kono
parents:
diff changeset
596 -- 3. Write
kono
parents:
diff changeset
597 -- 4. Input
kono
parents:
diff changeset
598 -- 5. Output
kono
parents:
diff changeset
599 -- 6. "="
kono
parents:
diff changeset
600 -- 7. assignment
kono
parents:
diff changeset
601 -- 8. deep adjust
kono
parents:
diff changeset
602 -- 9. deep finalize
kono
parents:
diff changeset
603 -- 10. async select
kono
parents:
diff changeset
604 -- 11. conditional select
kono
parents:
diff changeset
605 -- 12. prim_op kind
kono
parents:
diff changeset
606 -- 13. task_id
kono
parents:
diff changeset
607 -- 14. dispatching requeue
kono
parents:
diff changeset
608 -- 15. timed select
kono
parents:
diff changeset
609 --
kono
parents:
diff changeset
610 -- The compiler checks that the value here is correct
kono
parents:
diff changeset
611
kono
parents:
diff changeset
612 subtype Predef_Prims_Table is Address_Array (1 .. Max_Predef_Prims);
kono
parents:
diff changeset
613 type Predef_Prims_Table_Ptr is access Predef_Prims_Table;
kono
parents:
diff changeset
614 pragma No_Strict_Aliasing (Predef_Prims_Table_Ptr);
kono
parents:
diff changeset
615
kono
parents:
diff changeset
616 type Addr_Ptr is access System.Address;
kono
parents:
diff changeset
617 pragma No_Strict_Aliasing (Addr_Ptr);
kono
parents:
diff changeset
618 -- This type is used by the frontend to generate the code that handles
kono
parents:
diff changeset
619 -- dispatch table slots of types declared at the local level.
kono
parents:
diff changeset
620
kono
parents:
diff changeset
621 end Ada.Tags;