Debian Codegraph @

gcc/ada/libgnat/a-tags.ads

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