1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2012, Free Software Foundation, Inc. --
11 -- GNAT is free software; you can redistribute it and/or modify it under --
12 -- terms of the GNU General Public License as published by the Free Soft- --
13 -- ware Foundation; either version 3, or (at your option) any later ver- --
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
16 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
17 -- for more details. You should have received a copy of the GNU General --
18 -- Public License distributed with GNAT; see file COPYING3. If not, go to --
19 -- http://www.gnu.org/licenses for a complete copy of the license. --
21 -- GNAT was originally developed by the GNAT team at New York University. --
22 -- Extensive contributions were provided by Ada Core Technologies Inc. --
24 ------------------------------------------------------------------------------
26 with Atree
; use Atree
;
27 with Checks
; use Checks
;
28 with Debug
; use Debug
;
29 with Einfo
; use Einfo
;
30 with Elists
; use Elists
;
31 with Errout
; use Errout
;
32 with Exp_Atag
; use Exp_Atag
;
33 with Exp_Ch6
; use Exp_Ch6
;
34 with Exp_CG
; use Exp_CG
;
35 with Exp_Dbug
; use Exp_Dbug
;
36 with Exp_Tss
; use Exp_Tss
;
37 with Exp_Util
; use Exp_Util
;
38 with Freeze
; use Freeze
;
39 with Itypes
; use Itypes
;
40 with Layout
; use Layout
;
41 with Nlists
; use Nlists
;
42 with Nmake
; use Nmake
;
43 with Namet
; use Namet
;
45 with Output
; use Output
;
46 with Restrict
; use Restrict
;
47 with Rident
; use Rident
;
48 with Rtsfind
; use Rtsfind
;
50 with Sem_Aux
; use Sem_Aux
;
51 with Sem_Ch6
; use Sem_Ch6
;
52 with Sem_Ch7
; use Sem_Ch7
;
53 with Sem_Ch8
; use Sem_Ch8
;
54 with Sem_Disp
; use Sem_Disp
;
55 with Sem_Eval
; use Sem_Eval
;
56 with Sem_Res
; use Sem_Res
;
57 with Sem_Type
; use Sem_Type
;
58 with Sem_Util
; use Sem_Util
;
59 with Sinfo
; use Sinfo
;
60 with Snames
; use Snames
;
61 with Stand
; use Stand
;
62 with Stringt
; use Stringt
;
63 with SCIL_LL
; use SCIL_LL
;
64 with Targparm
; use Targparm
;
65 with Tbuild
; use Tbuild
;
66 with Uintp
; use Uintp
;
68 package body Exp_Disp
is
70 -----------------------
71 -- Local Subprograms --
72 -----------------------
74 function Default_Prim_Op_Position
(E
: Entity_Id
) return Uint
;
75 -- Ada 2005 (AI-251): Returns the fixed position in the dispatch table
76 -- of the default primitive operations.
78 function Find_Specific_Type
(CW
: Entity_Id
) return Entity_Id
;
79 -- Find specific type of a class-wide type, and handle the case of an
80 -- incomplete type coming either from a limited_with clause or from an
81 -- incomplete type declaration. Shouldn't this be in Sem_Util? It seems
82 -- like a general purpose semantic routine ???
84 function Has_DT
(Typ
: Entity_Id
) return Boolean;
85 pragma Inline
(Has_DT
);
86 -- Returns true if we generate a dispatch table for tagged type Typ
88 function Is_Predefined_Dispatching_Alias
(Prim
: Entity_Id
) return Boolean;
89 -- Returns true if Prim is not a predefined dispatching primitive but it is
90 -- an alias of a predefined dispatching primitive (i.e. through a renaming)
92 function New_Value
(From
: Node_Id
) return Node_Id
;
93 -- From is the original Expression. New_Value is equivalent to a call
94 -- to Duplicate_Subexpr with an explicit dereference when From is an
97 function Original_View_In_Visible_Part
(Typ
: Entity_Id
) return Boolean;
98 -- Check if the type has a private view or if the public view appears
99 -- in the visible part of a package spec.
101 function Prim_Op_Kind
103 Typ
: Entity_Id
) return Node_Id
;
104 -- Ada 2005 (AI-345): Determine the primitive operation kind of Prim
105 -- according to its type Typ. Return a reference to an RE_Prim_Op_Kind
106 -- enumeration value.
108 function Tagged_Kind
(T
: Entity_Id
) return Node_Id
;
109 -- Ada 2005 (AI-345): Determine the tagged kind of T and return a reference
110 -- to an RE_Tagged_Kind enumeration value.
112 ----------------------
113 -- Apply_Tag_Checks --
114 ----------------------
116 procedure Apply_Tag_Checks
(Call_Node
: Node_Id
) is
117 Loc
: constant Source_Ptr
:= Sloc
(Call_Node
);
118 Ctrl_Arg
: constant Node_Id
:= Controlling_Argument
(Call_Node
);
119 Ctrl_Typ
: constant Entity_Id
:= Base_Type
(Etype
(Ctrl_Arg
));
120 Param_List
: constant List_Id
:= Parameter_Associations
(Call_Node
);
126 Eq_Prim_Op
: Entity_Id
:= Empty
;
129 if No_Run_Time_Mode
then
130 Error_Msg_CRT
("tagged types", Call_Node
);
134 -- Apply_Tag_Checks is called directly from the semantics, so we need
135 -- a check to see whether expansion is active before proceeding. In
136 -- addition, there is no need to expand the call when compiling under
137 -- restriction No_Dispatching_Calls; the semantic analyzer has
138 -- previously notified the violation of this restriction.
140 if not Expander_Active
141 or else Restriction_Active
(No_Dispatching_Calls
)
146 -- Set subprogram. If this is an inherited operation that was
147 -- overridden, the body that is being called is its alias.
149 Subp
:= Entity
(Name
(Call_Node
));
151 if Present
(Alias
(Subp
))
152 and then Is_Inherited_Operation
(Subp
)
153 and then No
(DTC_Entity
(Subp
))
155 Subp
:= Alias
(Subp
);
158 -- Definition of the class-wide type and the tagged type
160 -- If the controlling argument is itself a tag rather than a tagged
161 -- object, then use the class-wide type associated with the subprogram's
162 -- controlling type. This case can occur when a call to an inherited
163 -- primitive has an actual that originated from a default parameter
164 -- given by a tag-indeterminate call and when there is no other
165 -- controlling argument providing the tag (AI-239 requires dispatching).
166 -- This capability of dispatching directly by tag is also needed by the
167 -- implementation of AI-260 (for the generic dispatching constructors).
169 if Ctrl_Typ
= RTE
(RE_Tag
)
170 or else (RTE_Available
(RE_Interface_Tag
)
171 and then Ctrl_Typ
= RTE
(RE_Interface_Tag
))
173 CW_Typ
:= Class_Wide_Type
(Find_Dispatching_Type
(Subp
));
175 -- Class_Wide_Type is applied to the expressions used to initialize
176 -- CW_Typ, to ensure that CW_Typ always denotes a class-wide type, since
177 -- there are cases where the controlling type is resolved to a specific
178 -- type (such as for designated types of arguments such as CW'Access).
180 elsif Is_Access_Type
(Ctrl_Typ
) then
181 CW_Typ
:= Class_Wide_Type
(Designated_Type
(Ctrl_Typ
));
184 CW_Typ
:= Class_Wide_Type
(Ctrl_Typ
);
187 Typ
:= Find_Specific_Type
(CW_Typ
);
189 if not Is_Limited_Type
(Typ
) then
190 Eq_Prim_Op
:= Find_Prim_Op
(Typ
, Name_Op_Eq
);
193 -- Dispatching call to C++ primitive
195 if Is_CPP_Class
(Typ
) then
198 -- Dispatching call to Ada primitive
200 elsif Present
(Param_List
) then
202 -- Generate the Tag checks when appropriate
204 Param
:= First_Actual
(Call_Node
);
205 while Present
(Param
) loop
207 -- No tag check with itself
209 if Param
= Ctrl_Arg
then
212 -- No tag check for parameter whose type is neither tagged nor
213 -- access to tagged (for access parameters)
215 elsif No
(Find_Controlling_Arg
(Param
)) then
218 -- No tag check for function dispatching on result if the
219 -- Tag given by the context is this one
221 elsif Find_Controlling_Arg
(Param
) = Ctrl_Arg
then
224 -- "=" is the only dispatching operation allowed to get
225 -- operands with incompatible tags (it just returns false).
226 -- We use Duplicate_Subexpr_Move_Checks instead of calling
227 -- Relocate_Node because the value will be duplicated to
230 elsif Subp
= Eq_Prim_Op
then
233 -- No check in presence of suppress flags
235 elsif Tag_Checks_Suppressed
(Etype
(Param
))
236 or else (Is_Access_Type
(Etype
(Param
))
237 and then Tag_Checks_Suppressed
238 (Designated_Type
(Etype
(Param
))))
242 -- Optimization: no tag checks if the parameters are identical
244 elsif Is_Entity_Name
(Param
)
245 and then Is_Entity_Name
(Ctrl_Arg
)
246 and then Entity
(Param
) = Entity
(Ctrl_Arg
)
250 -- Now we need to generate the Tag check
253 -- Generate code for tag equality check
254 -- Perhaps should have Checks.Apply_Tag_Equality_Check???
256 Insert_Action
(Ctrl_Arg
,
257 Make_Implicit_If_Statement
(Call_Node
,
261 Make_Selected_Component
(Loc
,
262 Prefix
=> New_Value
(Ctrl_Arg
),
265 (First_Tag_Component
(Typ
), Loc
)),
268 Make_Selected_Component
(Loc
,
270 Unchecked_Convert_To
(Typ
, New_Value
(Param
)),
273 (First_Tag_Component
(Typ
), Loc
))),
276 New_List
(New_Constraint_Error
(Loc
))));
282 end Apply_Tag_Checks
;
284 ------------------------
285 -- Building_Static_DT --
286 ------------------------
288 function Building_Static_DT
(Typ
: Entity_Id
) return Boolean is
289 Root_Typ
: Entity_Id
:= Root_Type
(Typ
);
292 -- Handle private types
294 if Present
(Full_View
(Root_Typ
)) then
295 Root_Typ
:= Full_View
(Root_Typ
);
298 return Static_Dispatch_Tables
299 and then Is_Library_Level_Tagged_Type
(Typ
)
300 and then VM_Target
= No_VM
302 -- If the type is derived from a CPP class we cannot statically
303 -- build the dispatch tables because we must inherit primitives
304 -- from the CPP side.
306 and then not Is_CPP_Class
(Root_Typ
);
307 end Building_Static_DT
;
309 ----------------------------------
310 -- Build_Static_Dispatch_Tables --
311 ----------------------------------
313 procedure Build_Static_Dispatch_Tables
(N
: Entity_Id
) is
314 Target_List
: List_Id
;
316 procedure Build_Dispatch_Tables
(List
: List_Id
);
317 -- Build the static dispatch table of tagged types found in the list of
318 -- declarations. The generated nodes are added at the end of Target_List
320 procedure Build_Package_Dispatch_Tables
(N
: Node_Id
);
321 -- Build static dispatch tables associated with package declaration N
323 ---------------------------
324 -- Build_Dispatch_Tables --
325 ---------------------------
327 procedure Build_Dispatch_Tables
(List
: List_Id
) is
332 while Present
(D
) loop
334 -- Handle nested packages and package bodies recursively. The
335 -- generated code is placed on the Target_List established for
336 -- the enclosing compilation unit.
338 if Nkind
(D
) = N_Package_Declaration
then
339 Build_Package_Dispatch_Tables
(D
);
341 elsif Nkind
(D
) = N_Package_Body
then
342 Build_Dispatch_Tables
(Declarations
(D
));
344 elsif Nkind
(D
) = N_Package_Body_Stub
345 and then Present
(Library_Unit
(D
))
347 Build_Dispatch_Tables
348 (Declarations
(Proper_Body
(Unit
(Library_Unit
(D
)))));
350 -- Handle full type declarations and derivations of library
351 -- level tagged types
353 elsif Nkind_In
(D
, N_Full_Type_Declaration
,
354 N_Derived_Type_Definition
)
355 and then Is_Library_Level_Tagged_Type
(Defining_Entity
(D
))
356 and then Ekind
(Defining_Entity
(D
)) /= E_Record_Subtype
357 and then not Is_Private_Type
(Defining_Entity
(D
))
359 -- We do not generate dispatch tables for the internal types
360 -- created for a type extension with unknown discriminants
361 -- The needed information is shared with the source type,
362 -- See Expand_N_Record_Extension.
364 if Is_Underlying_Record_View
(Defining_Entity
(D
))
366 (not Comes_From_Source
(Defining_Entity
(D
))
368 Has_Unknown_Discriminants
(Etype
(Defining_Entity
(D
)))
370 not Comes_From_Source
371 (First_Subtype
(Defining_Entity
(D
))))
375 Insert_List_After_And_Analyze
(Last
(Target_List
),
376 Make_DT
(Defining_Entity
(D
)));
379 -- Handle private types of library level tagged types. We must
380 -- exchange the private and full-view to ensure the correct
381 -- expansion. If the full view is a synchronized type ignore
382 -- the type because the table will be built for the corresponding
383 -- record type, that has its own declaration.
385 elsif (Nkind
(D
) = N_Private_Type_Declaration
386 or else Nkind
(D
) = N_Private_Extension_Declaration
)
387 and then Present
(Full_View
(Defining_Entity
(D
)))
390 E1
: constant Entity_Id
:= Defining_Entity
(D
);
391 E2
: constant Entity_Id
:= Full_View
(E1
);
394 if Is_Library_Level_Tagged_Type
(E2
)
395 and then Ekind
(E2
) /= E_Record_Subtype
396 and then not Is_Concurrent_Type
(E2
)
398 Exchange_Declarations
(E1
);
399 Insert_List_After_And_Analyze
(Last
(Target_List
),
401 Exchange_Declarations
(E2
);
408 end Build_Dispatch_Tables
;
410 -----------------------------------
411 -- Build_Package_Dispatch_Tables --
412 -----------------------------------
414 procedure Build_Package_Dispatch_Tables
(N
: Node_Id
) is
415 Spec
: constant Node_Id
:= Specification
(N
);
416 Id
: constant Entity_Id
:= Defining_Entity
(N
);
417 Vis_Decls
: constant List_Id
:= Visible_Declarations
(Spec
);
418 Priv_Decls
: constant List_Id
:= Private_Declarations
(Spec
);
423 if Present
(Priv_Decls
) then
424 Build_Dispatch_Tables
(Vis_Decls
);
425 Build_Dispatch_Tables
(Priv_Decls
);
427 elsif Present
(Vis_Decls
) then
428 Build_Dispatch_Tables
(Vis_Decls
);
432 end Build_Package_Dispatch_Tables
;
434 -- Start of processing for Build_Static_Dispatch_Tables
437 if not Expander_Active
438 or else not Tagged_Type_Expansion
443 if Nkind
(N
) = N_Package_Declaration
then
445 Spec
: constant Node_Id
:= Specification
(N
);
446 Vis_Decls
: constant List_Id
:= Visible_Declarations
(Spec
);
447 Priv_Decls
: constant List_Id
:= Private_Declarations
(Spec
);
450 if Present
(Priv_Decls
)
451 and then Is_Non_Empty_List
(Priv_Decls
)
453 Target_List
:= Priv_Decls
;
455 elsif not Present
(Vis_Decls
) then
456 Target_List
:= New_List
;
457 Set_Private_Declarations
(Spec
, Target_List
);
459 Target_List
:= Vis_Decls
;
462 Build_Package_Dispatch_Tables
(N
);
465 else pragma Assert
(Nkind
(N
) = N_Package_Body
);
466 Target_List
:= Declarations
(N
);
467 Build_Dispatch_Tables
(Target_List
);
469 end Build_Static_Dispatch_Tables
;
471 ------------------------------
472 -- Convert_Tag_To_Interface --
473 ------------------------------
475 function Convert_Tag_To_Interface
477 Expr
: Node_Id
) return Node_Id
479 Loc
: constant Source_Ptr
:= Sloc
(Expr
);
480 Anon_Type
: Entity_Id
;
484 pragma Assert
(Is_Class_Wide_Type
(Typ
)
485 and then Is_Interface
(Typ
)
487 ((Nkind
(Expr
) = N_Selected_Component
488 and then Is_Tag
(Entity
(Selector_Name
(Expr
))))
490 (Nkind
(Expr
) = N_Function_Call
491 and then RTE_Available
(RE_Displace
)
492 and then Entity
(Name
(Expr
)) = RTE
(RE_Displace
))));
494 Anon_Type
:= Create_Itype
(E_Anonymous_Access_Type
, Expr
);
495 Set_Directly_Designated_Type
(Anon_Type
, Typ
);
496 Set_Etype
(Anon_Type
, Anon_Type
);
497 Set_Can_Never_Be_Null
(Anon_Type
);
499 -- Decorate the size and alignment attributes of the anonymous access
500 -- type, as required by gigi.
502 Layout_Type
(Anon_Type
);
504 if Nkind
(Expr
) = N_Selected_Component
505 and then Is_Tag
(Entity
(Selector_Name
(Expr
)))
508 Make_Explicit_Dereference
(Loc
,
509 Unchecked_Convert_To
(Anon_Type
,
510 Make_Attribute_Reference
(Loc
,
512 Attribute_Name
=> Name_Address
)));
515 Make_Explicit_Dereference
(Loc
,
516 Unchecked_Convert_To
(Anon_Type
, Expr
));
520 end Convert_Tag_To_Interface
;
526 function CPP_Num_Prims
(Typ
: Entity_Id
) return Nat
is
528 Tag_Comp
: Entity_Id
;
531 if not Is_Tagged_Type
(Typ
)
532 or else not Is_CPP_Class
(Root_Type
(Typ
))
537 CPP_Typ
:= Enclosing_CPP_Parent
(Typ
);
538 Tag_Comp
:= First_Tag_Component
(CPP_Typ
);
540 -- If the number of primitives is already set in the tag component
543 if Present
(Tag_Comp
)
544 and then DT_Entry_Count
(Tag_Comp
) /= No_Uint
546 return UI_To_Int
(DT_Entry_Count
(Tag_Comp
));
548 -- Otherwise, count the primitives of the enclosing CPP type
556 Elmt
:= First_Elmt
(Primitive_Operations
(CPP_Typ
));
557 while Present
(Elmt
) loop
568 ------------------------------
569 -- Default_Prim_Op_Position --
570 ------------------------------
572 function Default_Prim_Op_Position
(E
: Entity_Id
) return Uint
is
573 TSS_Name
: TSS_Name_Type
;
576 Get_Name_String
(Chars
(E
));
579 (Name_Buffer
(Name_Len
- TSS_Name
'Length + 1 .. Name_Len
));
581 if Chars
(E
) = Name_uSize
then
584 elsif TSS_Name
= TSS_Stream_Read
then
587 elsif TSS_Name
= TSS_Stream_Write
then
590 elsif TSS_Name
= TSS_Stream_Input
then
593 elsif TSS_Name
= TSS_Stream_Output
then
596 elsif Chars
(E
) = Name_Op_Eq
then
599 elsif Chars
(E
) = Name_uAssign
then
602 elsif TSS_Name
= TSS_Deep_Adjust
then
605 elsif TSS_Name
= TSS_Deep_Finalize
then
608 -- In VM targets unconditionally allow obtaining the position associated
609 -- with predefined interface primitives since in these platforms any
610 -- tagged type has these primitives.
612 elsif Ada_Version
>= Ada_2005
or else not Tagged_Type_Expansion
then
613 if Chars
(E
) = Name_uDisp_Asynchronous_Select
then
616 elsif Chars
(E
) = Name_uDisp_Conditional_Select
then
619 elsif Chars
(E
) = Name_uDisp_Get_Prim_Op_Kind
then
622 elsif Chars
(E
) = Name_uDisp_Get_Task_Id
then
625 elsif Chars
(E
) = Name_uDisp_Requeue
then
628 elsif Chars
(E
) = Name_uDisp_Timed_Select
then
634 end Default_Prim_Op_Position
;
636 -----------------------------
637 -- Expand_Dispatching_Call --
638 -----------------------------
640 procedure Expand_Dispatching_Call
(Call_Node
: Node_Id
) is
641 Loc
: constant Source_Ptr
:= Sloc
(Call_Node
);
642 Call_Typ
: constant Entity_Id
:= Etype
(Call_Node
);
644 Ctrl_Arg
: constant Node_Id
:= Controlling_Argument
(Call_Node
);
645 Ctrl_Typ
: constant Entity_Id
:= Base_Type
(Etype
(Ctrl_Arg
));
646 Param_List
: constant List_Id
:= Parameter_Associations
(Call_Node
);
651 New_Call_Name
: Node_Id
;
652 New_Params
: List_Id
:= No_List
;
655 Subp_Ptr_Typ
: Entity_Id
;
656 Subp_Typ
: Entity_Id
;
658 Eq_Prim_Op
: Entity_Id
:= Empty
;
659 Controlling_Tag
: Node_Id
;
661 function New_Value
(From
: Node_Id
) return Node_Id
;
662 -- From is the original Expression. New_Value is equivalent to a call
663 -- to Duplicate_Subexpr with an explicit dereference when From is an
670 function New_Value
(From
: Node_Id
) return Node_Id
is
671 Res
: constant Node_Id
:= Duplicate_Subexpr
(From
);
673 if Is_Access_Type
(Etype
(From
)) then
675 Make_Explicit_Dereference
(Sloc
(From
),
686 SCIL_Related_Node
: Node_Id
:= Call_Node
;
688 -- Start of processing for Expand_Dispatching_Call
691 if No_Run_Time_Mode
then
692 Error_Msg_CRT
("tagged types", Call_Node
);
696 -- Expand_Dispatching_Call is called directly from the semantics,
697 -- so we only proceed if the expander is active.
699 if not Full_Expander_Active
701 -- And there is no need to expand the call if we are compiling under
702 -- restriction No_Dispatching_Calls; the semantic analyzer has
703 -- previously notified the violation of this restriction.
705 or else Restriction_Active
(No_Dispatching_Calls
)
710 -- Set subprogram. If this is an inherited operation that was
711 -- overridden, the body that is being called is its alias.
713 Subp
:= Entity
(Name
(Call_Node
));
715 if Present
(Alias
(Subp
))
716 and then Is_Inherited_Operation
(Subp
)
717 and then No
(DTC_Entity
(Subp
))
719 Subp
:= Alias
(Subp
);
722 -- Definition of the class-wide type and the tagged type
724 -- If the controlling argument is itself a tag rather than a tagged
725 -- object, then use the class-wide type associated with the subprogram's
726 -- controlling type. This case can occur when a call to an inherited
727 -- primitive has an actual that originated from a default parameter
728 -- given by a tag-indeterminate call and when there is no other
729 -- controlling argument providing the tag (AI-239 requires dispatching).
730 -- This capability of dispatching directly by tag is also needed by the
731 -- implementation of AI-260 (for the generic dispatching constructors).
733 if Ctrl_Typ
= RTE
(RE_Tag
)
734 or else (RTE_Available
(RE_Interface_Tag
)
735 and then Ctrl_Typ
= RTE
(RE_Interface_Tag
))
737 CW_Typ
:= Class_Wide_Type
(Find_Dispatching_Type
(Subp
));
739 -- Class_Wide_Type is applied to the expressions used to initialize
740 -- CW_Typ, to ensure that CW_Typ always denotes a class-wide type, since
741 -- there are cases where the controlling type is resolved to a specific
742 -- type (such as for designated types of arguments such as CW'Access).
744 elsif Is_Access_Type
(Ctrl_Typ
) then
745 CW_Typ
:= Class_Wide_Type
(Designated_Type
(Ctrl_Typ
));
748 CW_Typ
:= Class_Wide_Type
(Ctrl_Typ
);
751 Typ
:= Find_Specific_Type
(CW_Typ
);
753 if not Is_Limited_Type
(Typ
) then
754 Eq_Prim_Op
:= Find_Prim_Op
(Typ
, Name_Op_Eq
);
757 -- Dispatching call to C++ primitive. Create a new parameter list
758 -- with no tag checks.
760 New_Params
:= New_List
;
762 if Is_CPP_Class
(Typ
) then
763 Param
:= First_Actual
(Call_Node
);
764 while Present
(Param
) loop
765 Append_To
(New_Params
, Relocate_Node
(Param
));
769 -- Dispatching call to Ada primitive
771 elsif Present
(Param_List
) then
772 Apply_Tag_Checks
(Call_Node
);
774 Param
:= First_Actual
(Call_Node
);
775 while Present
(Param
) loop
776 -- Cases in which we may have generated runtime checks
779 or else Subp
= Eq_Prim_Op
781 Append_To
(New_Params
,
782 Duplicate_Subexpr_Move_Checks
(Param
));
784 elsif Nkind
(Parent
(Param
)) /= N_Parameter_Association
785 or else not Is_Accessibility_Actual
(Parent
(Param
))
787 Append_To
(New_Params
, Relocate_Node
(Param
));
794 -- Generate the appropriate subprogram pointer type
796 if Etype
(Subp
) = Typ
then
799 Res_Typ
:= Etype
(Subp
);
802 Subp_Typ
:= Create_Itype
(E_Subprogram_Type
, Call_Node
);
803 Subp_Ptr_Typ
:= Create_Itype
(E_Access_Subprogram_Type
, Call_Node
);
804 Set_Etype
(Subp_Typ
, Res_Typ
);
805 Set_Returns_By_Ref
(Subp_Typ
, Returns_By_Ref
(Subp
));
806 Set_Convention
(Subp_Typ
, Convention
(Subp
));
808 -- Notify gigi that the designated type is a dispatching primitive
810 Set_Is_Dispatch_Table_Entity
(Subp_Typ
);
812 -- Create a new list of parameters which is a copy of the old formal
813 -- list including the creation of a new set of matching entities.
816 Old_Formal
: Entity_Id
:= First_Formal
(Subp
);
817 New_Formal
: Entity_Id
;
818 Extra
: Entity_Id
:= Empty
;
821 if Present
(Old_Formal
) then
822 New_Formal
:= New_Copy
(Old_Formal
);
823 Set_First_Entity
(Subp_Typ
, New_Formal
);
824 Param
:= First_Actual
(Call_Node
);
827 Set_Scope
(New_Formal
, Subp_Typ
);
829 -- Change all the controlling argument types to be class-wide
830 -- to avoid a recursion in dispatching.
832 if Is_Controlling_Formal
(New_Formal
) then
833 Set_Etype
(New_Formal
, Etype
(Param
));
836 -- If the type of the formal is an itype, there was code here
837 -- introduced in 1998 in revision 1.46, to create a new itype
838 -- by copy. This seems useless, and in fact leads to semantic
839 -- errors when the itype is the completion of a type derived
840 -- from a private type.
843 Next_Formal
(Old_Formal
);
844 exit when No
(Old_Formal
);
846 Set_Next_Entity
(New_Formal
, New_Copy
(Old_Formal
));
847 Next_Entity
(New_Formal
);
851 Set_Next_Entity
(New_Formal
, Empty
);
852 Set_Last_Entity
(Subp_Typ
, Extra
);
855 -- Now that the explicit formals have been duplicated, any extra
856 -- formals needed by the subprogram must be created.
858 if Present
(Extra
) then
859 Set_Extra_Formal
(Extra
, Empty
);
862 Create_Extra_Formals
(Subp_Typ
);
865 -- Complete description of pointer type, including size information, as
866 -- must be done with itypes to prevent order-of-elaboration anomalies
869 Set_Etype
(Subp_Ptr_Typ
, Subp_Ptr_Typ
);
870 Set_Directly_Designated_Type
(Subp_Ptr_Typ
, Subp_Typ
);
871 Set_Convention
(Subp_Ptr_Typ
, Convention
(Subp_Typ
));
872 Layout_Type
(Subp_Ptr_Typ
);
874 -- If the controlling argument is a value of type Ada.Tag or an abstract
875 -- interface class-wide type then use it directly. Otherwise, the tag
876 -- must be extracted from the controlling object.
878 if Ctrl_Typ
= RTE
(RE_Tag
)
879 or else (RTE_Available
(RE_Interface_Tag
)
880 and then Ctrl_Typ
= RTE
(RE_Interface_Tag
))
882 Controlling_Tag
:= Duplicate_Subexpr
(Ctrl_Arg
);
884 -- Extract the tag from an unchecked type conversion. Done to avoid
885 -- the expansion of additional code just to obtain the value of such
886 -- tag because the current management of interface type conversions
887 -- generates in some cases this unchecked type conversion with the
888 -- tag of the object (see Expand_Interface_Conversion).
890 elsif Nkind
(Ctrl_Arg
) = N_Unchecked_Type_Conversion
892 (Etype
(Expression
(Ctrl_Arg
)) = RTE
(RE_Tag
)
894 (RTE_Available
(RE_Interface_Tag
)
896 Etype
(Expression
(Ctrl_Arg
)) = RTE
(RE_Interface_Tag
)))
898 Controlling_Tag
:= Duplicate_Subexpr
(Expression
(Ctrl_Arg
));
900 -- Ada 2005 (AI-251): Abstract interface class-wide type
902 elsif Is_Interface
(Ctrl_Typ
)
903 and then Is_Class_Wide_Type
(Ctrl_Typ
)
905 Controlling_Tag
:= Duplicate_Subexpr
(Ctrl_Arg
);
909 Make_Selected_Component
(Loc
,
910 Prefix
=> Duplicate_Subexpr_Move_Checks
(Ctrl_Arg
),
911 Selector_Name
=> New_Reference_To
(DTC_Entity
(Subp
), Loc
));
914 -- Handle dispatching calls to predefined primitives
916 if Is_Predefined_Dispatching_Operation
(Subp
)
917 or else Is_Predefined_Dispatching_Alias
(Subp
)
919 Build_Get_Predefined_Prim_Op_Address
(Loc
,
920 Tag_Node
=> Controlling_Tag
,
921 Position
=> DT_Position
(Subp
),
922 New_Node
=> New_Node
);
924 -- Handle dispatching calls to user-defined primitives
927 Build_Get_Prim_Op_Address
(Loc
,
928 Typ
=> Underlying_Type
(Find_Dispatching_Type
(Subp
)),
929 Tag_Node
=> Controlling_Tag
,
930 Position
=> DT_Position
(Subp
),
931 New_Node
=> New_Node
);
935 Unchecked_Convert_To
(Subp_Ptr_Typ
, New_Node
);
937 -- Generate the SCIL node for this dispatching call. Done now because
938 -- attribute SCIL_Controlling_Tag must be set after the new call name
939 -- is built to reference the nodes that will see the SCIL backend
940 -- (because Build_Get_Prim_Op_Address generates an unchecked type
941 -- conversion which relocates the controlling tag node).
943 if Generate_SCIL
then
944 SCIL_Node
:= Make_SCIL_Dispatching_Call
(Sloc
(Call_Node
));
945 Set_SCIL_Entity
(SCIL_Node
, Typ
);
946 Set_SCIL_Target_Prim
(SCIL_Node
, Subp
);
948 -- Common case: the controlling tag is the tag of an object
949 -- (for example, obj.tag)
951 if Nkind
(Controlling_Tag
) = N_Selected_Component
then
952 Set_SCIL_Controlling_Tag
(SCIL_Node
, Controlling_Tag
);
954 -- Handle renaming of selected component
956 elsif Nkind
(Controlling_Tag
) = N_Identifier
957 and then Nkind
(Parent
(Entity
(Controlling_Tag
))) =
958 N_Object_Renaming_Declaration
959 and then Nkind
(Name
(Parent
(Entity
(Controlling_Tag
)))) =
962 Set_SCIL_Controlling_Tag
(SCIL_Node
,
963 Name
(Parent
(Entity
(Controlling_Tag
))));
965 -- If the controlling tag is an identifier, the SCIL node references
966 -- the corresponding object or parameter declaration
968 elsif Nkind
(Controlling_Tag
) = N_Identifier
969 and then Nkind_In
(Parent
(Entity
(Controlling_Tag
)),
970 N_Object_Declaration
,
971 N_Parameter_Specification
)
973 Set_SCIL_Controlling_Tag
(SCIL_Node
,
974 Parent
(Entity
(Controlling_Tag
)));
976 -- If the controlling tag is a dereference, the SCIL node references
977 -- the corresponding object or parameter declaration
979 elsif Nkind
(Controlling_Tag
) = N_Explicit_Dereference
980 and then Nkind
(Prefix
(Controlling_Tag
)) = N_Identifier
981 and then Nkind_In
(Parent
(Entity
(Prefix
(Controlling_Tag
))),
982 N_Object_Declaration
,
983 N_Parameter_Specification
)
985 Set_SCIL_Controlling_Tag
(SCIL_Node
,
986 Parent
(Entity
(Prefix
(Controlling_Tag
))));
988 -- For a direct reference of the tag of the type the SCIL node
989 -- references the internal object declaration containing the tag
992 elsif Nkind
(Controlling_Tag
) = N_Attribute_Reference
993 and then Attribute_Name
(Controlling_Tag
) = Name_Tag
995 Set_SCIL_Controlling_Tag
(SCIL_Node
,
999 (Access_Disp_Table
(Entity
(Prefix
(Controlling_Tag
)))))));
1001 -- Interfaces are not supported. For now we leave the SCIL node
1002 -- decorated with the Controlling_Tag. More work needed here???
1004 elsif Is_Interface
(Etype
(Controlling_Tag
)) then
1005 Set_SCIL_Controlling_Tag
(SCIL_Node
, Controlling_Tag
);
1008 pragma Assert
(False);
1013 if Nkind
(Call_Node
) = N_Function_Call
then
1015 Make_Function_Call
(Loc
,
1016 Name
=> New_Call_Name
,
1017 Parameter_Associations
=> New_Params
);
1019 -- If this is a dispatching "=", we must first compare the tags so
1020 -- we generate: x.tag = y.tag and then x = y
1022 if Subp
= Eq_Prim_Op
then
1023 Param
:= First_Actual
(Call_Node
);
1029 Make_Selected_Component
(Loc
,
1030 Prefix
=> New_Value
(Param
),
1032 New_Reference_To
(First_Tag_Component
(Typ
),
1036 Make_Selected_Component
(Loc
,
1038 Unchecked_Convert_To
(Typ
,
1039 New_Value
(Next_Actual
(Param
))),
1042 (First_Tag_Component
(Typ
), Loc
))),
1043 Right_Opnd
=> New_Call
);
1045 SCIL_Related_Node
:= Right_Opnd
(New_Call
);
1050 Make_Procedure_Call_Statement
(Loc
,
1051 Name
=> New_Call_Name
,
1052 Parameter_Associations
=> New_Params
);
1055 -- Register the dispatching call in the call graph nodes table
1057 Register_CG_Node
(Call_Node
);
1059 Rewrite
(Call_Node
, New_Call
);
1061 -- Associate the SCIL node of this dispatching call
1063 if Generate_SCIL
then
1064 Set_SCIL_Node
(SCIL_Related_Node
, SCIL_Node
);
1067 -- Suppress all checks during the analysis of the expanded code
1068 -- to avoid the generation of spurious warnings under ZFP run-time.
1070 Analyze_And_Resolve
(Call_Node
, Call_Typ
, Suppress
=> All_Checks
);
1071 end Expand_Dispatching_Call
;
1073 ---------------------------------
1074 -- Expand_Interface_Conversion --
1075 ---------------------------------
1077 procedure Expand_Interface_Conversion
1079 Is_Static
: Boolean := True)
1081 Loc
: constant Source_Ptr
:= Sloc
(N
);
1082 Etyp
: constant Entity_Id
:= Etype
(N
);
1083 Operand
: constant Node_Id
:= Expression
(N
);
1084 Operand_Typ
: Entity_Id
:= Etype
(Operand
);
1086 Iface_Typ
: Entity_Id
:= Etype
(N
);
1087 Iface_Tag
: Entity_Id
;
1090 -- Ada 2005 (AI-345): Handle synchronized interface type derivations
1092 if Is_Concurrent_Type
(Operand_Typ
) then
1093 Operand_Typ
:= Base_Type
(Corresponding_Record_Type
(Operand_Typ
));
1096 -- Handle access to class-wide interface types
1098 if Is_Access_Type
(Iface_Typ
) then
1099 Iface_Typ
:= Etype
(Directly_Designated_Type
(Iface_Typ
));
1102 -- Handle class-wide interface types. This conversion can appear
1103 -- explicitly in the source code. Example: I'Class (Obj)
1105 if Is_Class_Wide_Type
(Iface_Typ
) then
1106 Iface_Typ
:= Root_Type
(Iface_Typ
);
1109 -- If the target type is a tagged synchronized type, the dispatch table
1110 -- info is in the corresponding record type.
1112 if Is_Concurrent_Type
(Iface_Typ
) then
1113 Iface_Typ
:= Corresponding_Record_Type
(Iface_Typ
);
1116 -- Handle private types
1118 Iface_Typ
:= Underlying_Type
(Iface_Typ
);
1120 -- Freeze the entity associated with the target interface to have
1121 -- available the attribute Access_Disp_Table.
1123 Freeze_Before
(N
, Iface_Typ
);
1125 pragma Assert
(not Is_Static
1126 or else (not Is_Class_Wide_Type
(Iface_Typ
)
1127 and then Is_Interface
(Iface_Typ
)));
1129 if not Tagged_Type_Expansion
then
1130 if VM_Target
/= No_VM
then
1131 if Is_Access_Type
(Operand_Typ
) then
1132 Operand_Typ
:= Designated_Type
(Operand_Typ
);
1135 if Is_Class_Wide_Type
(Operand_Typ
) then
1136 Operand_Typ
:= Root_Type
(Operand_Typ
);
1140 and then Operand_Typ
/= Iface_Typ
1143 Make_Procedure_Call_Statement
(Loc
,
1144 Name
=> New_Occurrence_Of
1145 (RTE
(RE_Check_Interface_Conversion
), Loc
),
1146 Parameter_Associations
=> New_List
(
1147 Make_Attribute_Reference
(Loc
,
1148 Prefix
=> Duplicate_Subexpr
(Expression
(N
)),
1149 Attribute_Name
=> Name_Tag
),
1150 Make_Attribute_Reference
(Loc
,
1151 Prefix
=> New_Reference_To
(Iface_Typ
, Loc
),
1152 Attribute_Name
=> Name_Tag
))));
1155 -- Just do a conversion ???
1157 Rewrite
(N
, Unchecked_Convert_To
(Etype
(N
), N
));
1164 if not Is_Static
then
1166 -- Give error if configurable run time and Displace not available
1168 if not RTE_Available
(RE_Displace
) then
1169 Error_Msg_CRT
("dynamic interface conversion", N
);
1173 -- Handle conversion of access-to-class-wide interface types. Target
1174 -- can be an access to an object or an access to another class-wide
1175 -- interface (see -1- and -2- in the following example):
1177 -- type Iface1_Ref is access all Iface1'Class;
1178 -- type Iface2_Ref is access all Iface1'Class;
1180 -- Acc1 : Iface1_Ref := new ...
1181 -- Obj : Obj_Ref := Obj_Ref (Acc); -- 1
1182 -- Acc2 : Iface2_Ref := Iface2_Ref (Acc); -- 2
1184 if Is_Access_Type
(Operand_Typ
) then
1186 Unchecked_Convert_To
(Etype
(N
),
1187 Make_Function_Call
(Loc
,
1188 Name
=> New_Reference_To
(RTE
(RE_Displace
), Loc
),
1189 Parameter_Associations
=> New_List
(
1191 Unchecked_Convert_To
(RTE
(RE_Address
),
1192 Relocate_Node
(Expression
(N
))),
1195 (Node
(First_Elmt
(Access_Disp_Table
(Iface_Typ
))),
1203 Make_Function_Call
(Loc
,
1204 Name
=> New_Reference_To
(RTE
(RE_Displace
), Loc
),
1205 Parameter_Associations
=> New_List
(
1206 Make_Attribute_Reference
(Loc
,
1207 Prefix
=> Relocate_Node
(Expression
(N
)),
1208 Attribute_Name
=> Name_Address
),
1211 (Node
(First_Elmt
(Access_Disp_Table
(Iface_Typ
))),
1216 -- If the target is a class-wide interface we change the type of the
1217 -- data returned by IW_Convert to indicate that this is a dispatching
1221 New_Itype
: Entity_Id
;
1224 New_Itype
:= Create_Itype
(E_Anonymous_Access_Type
, N
);
1225 Set_Etype
(New_Itype
, New_Itype
);
1226 Set_Directly_Designated_Type
(New_Itype
, Etyp
);
1229 Make_Explicit_Dereference
(Loc
,
1231 Unchecked_Convert_To
(New_Itype
, Relocate_Node
(N
))));
1233 Freeze_Itype
(New_Itype
, N
);
1239 Iface_Tag
:= Find_Interface_Tag
(Operand_Typ
, Iface_Typ
);
1240 pragma Assert
(Iface_Tag
/= Empty
);
1242 -- Keep separate access types to interfaces because one internal
1243 -- function is used to handle the null value (see following comments)
1245 if not Is_Access_Type
(Etype
(N
)) then
1247 -- Statically displace the pointer to the object to reference
1248 -- the component containing the secondary dispatch table.
1251 Convert_Tag_To_Interface
(Class_Wide_Type
(Iface_Typ
),
1252 Make_Selected_Component
(Loc
,
1253 Prefix
=> Relocate_Node
(Expression
(N
)),
1254 Selector_Name
=> New_Occurrence_Of
(Iface_Tag
, Loc
))));
1257 -- Build internal function to handle the case in which the
1258 -- actual is null. If the actual is null returns null because
1259 -- no displacement is required; otherwise performs a type
1260 -- conversion that will be expanded in the code that returns
1261 -- the value of the displaced actual. That is:
1263 -- function Func (O : Address) return Iface_Typ is
1264 -- type Op_Typ is access all Operand_Typ;
1265 -- Aux : Op_Typ := To_Op_Typ (O);
1267 -- if O = Null_Address then
1270 -- return Iface_Typ!(Aux.Iface_Tag'Address);
1275 Desig_Typ
: Entity_Id
;
1277 New_Typ_Decl
: Node_Id
;
1281 Desig_Typ
:= Etype
(Expression
(N
));
1283 if Is_Access_Type
(Desig_Typ
) then
1285 Available_View
(Directly_Designated_Type
(Desig_Typ
));
1288 if Is_Concurrent_Type
(Desig_Typ
) then
1289 Desig_Typ
:= Base_Type
(Corresponding_Record_Type
(Desig_Typ
));
1293 Make_Full_Type_Declaration
(Loc
,
1294 Defining_Identifier
=> Make_Temporary
(Loc
, 'T'),
1296 Make_Access_To_Object_Definition
(Loc
,
1297 All_Present
=> True,
1298 Null_Exclusion_Present
=> False,
1299 Constant_Present
=> False,
1300 Subtype_Indication
=>
1301 New_Reference_To
(Desig_Typ
, Loc
)));
1304 Make_Simple_Return_Statement
(Loc
,
1305 Unchecked_Convert_To
(Etype
(N
),
1306 Make_Attribute_Reference
(Loc
,
1308 Make_Selected_Component
(Loc
,
1310 Unchecked_Convert_To
1311 (Defining_Identifier
(New_Typ_Decl
),
1312 Make_Identifier
(Loc
, Name_uO
)),
1314 New_Occurrence_Of
(Iface_Tag
, Loc
)),
1315 Attribute_Name
=> Name_Address
))));
1317 -- If the type is null-excluding, no need for the null branch.
1318 -- Otherwise we need to check for it and return null.
1320 if not Can_Never_Be_Null
(Etype
(N
)) then
1322 Make_If_Statement
(Loc
,
1325 Left_Opnd
=> Make_Identifier
(Loc
, Name_uO
),
1326 Right_Opnd
=> New_Reference_To
1327 (RTE
(RE_Null_Address
), Loc
)),
1329 Then_Statements
=> New_List
(
1330 Make_Simple_Return_Statement
(Loc
,
1332 Else_Statements
=> Stats
));
1335 Fent
:= Make_Temporary
(Loc
, 'F');
1337 Make_Subprogram_Body
(Loc
,
1339 Make_Function_Specification
(Loc
,
1340 Defining_Unit_Name
=> Fent
,
1342 Parameter_Specifications
=> New_List
(
1343 Make_Parameter_Specification
(Loc
,
1344 Defining_Identifier
=>
1345 Make_Defining_Identifier
(Loc
, Name_uO
),
1347 New_Reference_To
(RTE
(RE_Address
), Loc
))),
1349 Result_Definition
=>
1350 New_Reference_To
(Etype
(N
), Loc
)),
1352 Declarations
=> New_List
(New_Typ_Decl
),
1354 Handled_Statement_Sequence
=>
1355 Make_Handled_Sequence_Of_Statements
(Loc
, Stats
));
1357 -- Place function body before the expression containing the
1358 -- conversion. We suppress all checks because the body of the
1359 -- internally generated function already takes care of the case
1360 -- in which the actual is null; therefore there is no need to
1361 -- double check that the pointer is not null when the program
1362 -- executes the alternative that performs the type conversion).
1364 Insert_Action
(N
, Func
, Suppress
=> All_Checks
);
1366 if Is_Access_Type
(Etype
(Expression
(N
))) then
1368 -- Generate: Func (Address!(Expression))
1371 Make_Function_Call
(Loc
,
1372 Name
=> New_Reference_To
(Fent
, Loc
),
1373 Parameter_Associations
=> New_List
(
1374 Unchecked_Convert_To
(RTE
(RE_Address
),
1375 Relocate_Node
(Expression
(N
))))));
1378 -- Generate: Func (Operand_Typ!(Expression)'Address)
1381 Make_Function_Call
(Loc
,
1382 Name
=> New_Reference_To
(Fent
, Loc
),
1383 Parameter_Associations
=> New_List
(
1384 Make_Attribute_Reference
(Loc
,
1385 Prefix
=> Unchecked_Convert_To
(Operand_Typ
,
1386 Relocate_Node
(Expression
(N
))),
1387 Attribute_Name
=> Name_Address
))));
1393 end Expand_Interface_Conversion
;
1395 ------------------------------
1396 -- Expand_Interface_Actuals --
1397 ------------------------------
1399 procedure Expand_Interface_Actuals
(Call_Node
: Node_Id
) is
1401 Actual_Dup
: Node_Id
;
1402 Actual_Typ
: Entity_Id
;
1404 Conversion
: Node_Id
;
1406 Formal_Typ
: Entity_Id
;
1408 Formal_DDT
: Entity_Id
;
1409 Actual_DDT
: Entity_Id
;
1412 -- This subprogram is called directly from the semantics, so we need a
1413 -- check to see whether expansion is active before proceeding.
1415 if not Expander_Active
then
1419 -- Call using access to subprogram with explicit dereference
1421 if Nkind
(Name
(Call_Node
)) = N_Explicit_Dereference
then
1422 Subp
:= Etype
(Name
(Call_Node
));
1424 -- Call using selected component
1426 elsif Nkind
(Name
(Call_Node
)) = N_Selected_Component
then
1427 Subp
:= Entity
(Selector_Name
(Name
(Call_Node
)));
1429 -- Call using direct name
1432 Subp
:= Entity
(Name
(Call_Node
));
1435 -- Ada 2005 (AI-251): Look for interface type formals to force "this"
1438 Formal
:= First_Formal
(Subp
);
1439 Actual
:= First_Actual
(Call_Node
);
1440 while Present
(Formal
) loop
1441 Formal_Typ
:= Etype
(Formal
);
1443 if Ekind
(Formal_Typ
) = E_Record_Type_With_Private
then
1444 Formal_Typ
:= Full_View
(Formal_Typ
);
1447 if Is_Access_Type
(Formal_Typ
) then
1448 Formal_DDT
:= Directly_Designated_Type
(Formal_Typ
);
1451 Actual_Typ
:= Etype
(Actual
);
1453 if Is_Access_Type
(Actual_Typ
) then
1454 Actual_DDT
:= Directly_Designated_Type
(Actual_Typ
);
1457 if Is_Interface
(Formal_Typ
)
1458 and then Is_Class_Wide_Type
(Formal_Typ
)
1460 -- No need to displace the pointer if the type of the actual
1461 -- coincides with the type of the formal.
1463 if Actual_Typ
= Formal_Typ
then
1466 -- No need to displace the pointer if the interface type is
1467 -- a parent of the type of the actual because in this case the
1468 -- interface primitives are located in the primary dispatch table.
1470 elsif Is_Ancestor
(Formal_Typ
, Actual_Typ
,
1471 Use_Full_View
=> True)
1475 -- Implicit conversion to the class-wide formal type to force
1476 -- the displacement of the pointer.
1479 -- Normally, expansion of actuals for calls to build-in-place
1480 -- functions happens as part of Expand_Actuals, but in this
1481 -- case the call will be wrapped in a conversion and soon after
1482 -- expanded further to handle the displacement for a class-wide
1483 -- interface conversion, so if this is a BIP call then we need
1484 -- to handle it now.
1486 if Ada_Version
>= Ada_2005
1487 and then Is_Build_In_Place_Function_Call
(Actual
)
1489 Make_Build_In_Place_Call_In_Anonymous_Context
(Actual
);
1492 Conversion
:= Convert_To
(Formal_Typ
, Relocate_Node
(Actual
));
1493 Rewrite
(Actual
, Conversion
);
1494 Analyze_And_Resolve
(Actual
, Formal_Typ
);
1497 -- Access to class-wide interface type
1499 elsif Is_Access_Type
(Formal_Typ
)
1500 and then Is_Interface
(Formal_DDT
)
1501 and then Is_Class_Wide_Type
(Formal_DDT
)
1502 and then Interface_Present_In_Ancestor
1504 Iface
=> Etype
(Formal_DDT
))
1506 -- Handle attributes 'Access and 'Unchecked_Access
1508 if Nkind
(Actual
) = N_Attribute_Reference
1510 (Attribute_Name
(Actual
) = Name_Access
1511 or else Attribute_Name
(Actual
) = Name_Unchecked_Access
)
1513 -- This case must have been handled by the analysis and
1514 -- expansion of 'Access. The only exception is when types
1515 -- match and no further expansion is required.
1517 pragma Assert
(Base_Type
(Etype
(Prefix
(Actual
)))
1518 = Base_Type
(Formal_DDT
));
1521 -- No need to displace the pointer if the type of the actual
1522 -- coincides with the type of the formal.
1524 elsif Actual_DDT
= Formal_DDT
then
1527 -- No need to displace the pointer if the interface type is
1528 -- a parent of the type of the actual because in this case the
1529 -- interface primitives are located in the primary dispatch table.
1531 elsif Is_Ancestor
(Formal_DDT
, Actual_DDT
,
1532 Use_Full_View
=> True)
1537 Actual_Dup
:= Relocate_Node
(Actual
);
1539 if From_With_Type
(Actual_Typ
) then
1541 -- If the type of the actual parameter comes from a limited
1542 -- with-clause and the non-limited view is already available
1543 -- we replace the anonymous access type by a duplicate
1544 -- declaration whose designated type is the non-limited view
1546 if Ekind
(Actual_DDT
) = E_Incomplete_Type
1547 and then Present
(Non_Limited_View
(Actual_DDT
))
1549 Anon
:= New_Copy
(Actual_Typ
);
1551 if Is_Itype
(Anon
) then
1552 Set_Scope
(Anon
, Current_Scope
);
1555 Set_Directly_Designated_Type
(Anon
,
1556 Non_Limited_View
(Actual_DDT
));
1557 Set_Etype
(Actual_Dup
, Anon
);
1559 elsif Is_Class_Wide_Type
(Actual_DDT
)
1560 and then Ekind
(Etype
(Actual_DDT
)) = E_Incomplete_Type
1561 and then Present
(Non_Limited_View
(Etype
(Actual_DDT
)))
1563 Anon
:= New_Copy
(Actual_Typ
);
1565 if Is_Itype
(Anon
) then
1566 Set_Scope
(Anon
, Current_Scope
);
1569 Set_Directly_Designated_Type
(Anon
,
1570 New_Copy
(Actual_DDT
));
1571 Set_Class_Wide_Type
(Directly_Designated_Type
(Anon
),
1572 New_Copy
(Class_Wide_Type
(Actual_DDT
)));
1573 Set_Etype
(Directly_Designated_Type
(Anon
),
1574 Non_Limited_View
(Etype
(Actual_DDT
)));
1576 Class_Wide_Type
(Directly_Designated_Type
(Anon
)),
1577 Non_Limited_View
(Etype
(Actual_DDT
)));
1578 Set_Etype
(Actual_Dup
, Anon
);
1582 Conversion
:= Convert_To
(Formal_Typ
, Actual_Dup
);
1583 Rewrite
(Actual
, Conversion
);
1584 Analyze_And_Resolve
(Actual
, Formal_Typ
);
1588 Next_Actual
(Actual
);
1589 Next_Formal
(Formal
);
1591 end Expand_Interface_Actuals
;
1593 ----------------------------
1594 -- Expand_Interface_Thunk --
1595 ----------------------------
1597 procedure Expand_Interface_Thunk
1599 Thunk_Id
: out Entity_Id
;
1600 Thunk_Code
: out Node_Id
)
1602 Loc
: constant Source_Ptr
:= Sloc
(Prim
);
1603 Actuals
: constant List_Id
:= New_List
;
1604 Decl
: constant List_Id
:= New_List
;
1605 Formals
: constant List_Id
:= New_List
;
1606 Target
: constant Entity_Id
:= Ultimate_Alias
(Prim
);
1608 Controlling_Typ
: Entity_Id
;
1614 Iface_Formal
: Node_Id
;
1616 Offset_To_Top
: Node_Id
;
1617 Target_Formal
: Entity_Id
;
1621 Thunk_Code
:= Empty
;
1623 -- No thunk needed if the primitive has been eliminated
1625 if Is_Eliminated
(Ultimate_Alias
(Prim
)) then
1628 -- In case of primitives that are functions without formals and a
1629 -- controlling result there is no need to build the thunk.
1631 elsif not Present
(First_Formal
(Target
)) then
1632 pragma Assert
(Ekind
(Target
) = E_Function
1633 and then Has_Controlling_Result
(Target
));
1637 -- Duplicate the formals of the Target primitive. In the thunk, the type
1638 -- of the controlling formal is the covered interface type (instead of
1639 -- the target tagged type). Done to avoid problems with discriminated
1640 -- tagged types because, if the controlling type has discriminants with
1641 -- default values, then the type conversions done inside the body of
1642 -- the thunk (after the displacement of the pointer to the base of the
1643 -- actual object) generate code that modify its contents.
1645 -- Note: This special management is not done for predefined primitives
1648 if not Is_Predefined_Dispatching_Operation
(Prim
) then
1649 Iface_Formal
:= First_Formal
(Interface_Alias
(Prim
));
1652 Formal
:= First_Formal
(Target
);
1653 while Present
(Formal
) loop
1654 Ftyp
:= Etype
(Formal
);
1656 -- Use the interface type as the type of the controlling formal (see
1659 if not Is_Controlling_Formal
(Formal
)
1660 or else Is_Predefined_Dispatching_Operation
(Prim
)
1662 Ftyp
:= Etype
(Formal
);
1663 Expr
:= New_Copy_Tree
(Expression
(Parent
(Formal
)));
1665 Ftyp
:= Etype
(Iface_Formal
);
1670 Make_Parameter_Specification
(Loc
,
1671 Defining_Identifier
=>
1672 Make_Defining_Identifier
(Sloc
(Formal
),
1673 Chars
=> Chars
(Formal
)),
1674 In_Present
=> In_Present
(Parent
(Formal
)),
1675 Out_Present
=> Out_Present
(Parent
(Formal
)),
1676 Parameter_Type
=> New_Reference_To
(Ftyp
, Loc
),
1677 Expression
=> Expr
));
1679 if not Is_Predefined_Dispatching_Operation
(Prim
) then
1680 Next_Formal
(Iface_Formal
);
1683 Next_Formal
(Formal
);
1686 Controlling_Typ
:= Find_Dispatching_Type
(Target
);
1688 Target_Formal
:= First_Formal
(Target
);
1689 Formal
:= First
(Formals
);
1690 while Present
(Formal
) loop
1692 -- If the parent is a constrained discriminated type, then the
1693 -- primitive operation will have been defined on a first subtype.
1694 -- For proper matching with controlling type, use base type.
1696 if Ekind
(Target_Formal
) = E_In_Parameter
1697 and then Ekind
(Etype
(Target_Formal
)) = E_Anonymous_Access_Type
1700 Base_Type
(Directly_Designated_Type
(Etype
(Target_Formal
)));
1702 Ftyp
:= Base_Type
(Etype
(Target_Formal
));
1705 -- For concurrent types, the relevant information is found in the
1706 -- Corresponding_Record_Type, rather than the type entity itself.
1708 if Is_Concurrent_Type
(Ftyp
) then
1709 Ftyp
:= Corresponding_Record_Type
(Ftyp
);
1712 if Ekind
(Target_Formal
) = E_In_Parameter
1713 and then Ekind
(Etype
(Target_Formal
)) = E_Anonymous_Access_Type
1714 and then Ftyp
= Controlling_Typ
1717 -- type T is access all <<type of the target formal>>
1718 -- S : Storage_Offset := Storage_Offset!(Formal)
1719 -- - Offset_To_Top (address!(Formal))
1722 Make_Full_Type_Declaration
(Loc
,
1723 Defining_Identifier
=> Make_Temporary
(Loc
, 'T'),
1725 Make_Access_To_Object_Definition
(Loc
,
1726 All_Present
=> True,
1727 Null_Exclusion_Present
=> False,
1728 Constant_Present
=> False,
1729 Subtype_Indication
=>
1730 New_Reference_To
(Ftyp
, Loc
)));
1733 Unchecked_Convert_To
(RTE
(RE_Address
),
1734 New_Reference_To
(Defining_Identifier
(Formal
), Loc
));
1736 if not RTE_Available
(RE_Offset_To_Top
) then
1738 Build_Offset_To_Top
(Loc
, New_Arg
);
1741 Make_Function_Call
(Loc
,
1742 Name
=> New_Reference_To
(RTE
(RE_Offset_To_Top
), Loc
),
1743 Parameter_Associations
=> New_List
(New_Arg
));
1747 Make_Object_Declaration
(Loc
,
1748 Defining_Identifier
=> Make_Temporary
(Loc
, 'S'),
1749 Constant_Present
=> True,
1750 Object_Definition
=>
1751 New_Reference_To
(RTE
(RE_Storage_Offset
), Loc
),
1753 Make_Op_Subtract
(Loc
,
1755 Unchecked_Convert_To
1756 (RTE
(RE_Storage_Offset
),
1757 New_Reference_To
(Defining_Identifier
(Formal
), Loc
)),
1761 Append_To
(Decl
, Decl_2
);
1762 Append_To
(Decl
, Decl_1
);
1764 -- Reference the new actual. Generate:
1768 Unchecked_Convert_To
1769 (Defining_Identifier
(Decl_2
),
1770 New_Reference_To
(Defining_Identifier
(Decl_1
), Loc
)));
1772 elsif Ftyp
= Controlling_Typ
then
1775 -- S1 : Storage_Offset := Storage_Offset!(Formal'Address)
1776 -- - Offset_To_Top (Formal'Address)
1777 -- S2 : Addr_Ptr := Addr_Ptr!(S1)
1780 Make_Attribute_Reference
(Loc
,
1782 New_Reference_To
(Defining_Identifier
(Formal
), Loc
),
1786 if not RTE_Available
(RE_Offset_To_Top
) then
1788 Build_Offset_To_Top
(Loc
, New_Arg
);
1791 Make_Function_Call
(Loc
,
1792 Name
=> New_Reference_To
(RTE
(RE_Offset_To_Top
), Loc
),
1793 Parameter_Associations
=> New_List
(New_Arg
));
1797 Make_Object_Declaration
(Loc
,
1798 Defining_Identifier
=> Make_Temporary
(Loc
, 'S'),
1799 Constant_Present
=> True,
1800 Object_Definition
=>
1801 New_Reference_To
(RTE
(RE_Storage_Offset
), Loc
),
1803 Make_Op_Subtract
(Loc
,
1805 Unchecked_Convert_To
1806 (RTE
(RE_Storage_Offset
),
1807 Make_Attribute_Reference
(Loc
,
1810 (Defining_Identifier
(Formal
), Loc
),
1811 Attribute_Name
=> Name_Address
)),
1816 Make_Object_Declaration
(Loc
,
1817 Defining_Identifier
=> Make_Temporary
(Loc
, 'S'),
1818 Constant_Present
=> True,
1819 Object_Definition
=>
1820 New_Reference_To
(RTE
(RE_Addr_Ptr
), Loc
),
1822 Unchecked_Convert_To
1824 New_Reference_To
(Defining_Identifier
(Decl_1
), Loc
)));
1826 Append_To
(Decl
, Decl_1
);
1827 Append_To
(Decl
, Decl_2
);
1829 -- Reference the new actual, generate:
1830 -- Target_Formal (S2.all)
1833 Unchecked_Convert_To
(Ftyp
,
1834 Make_Explicit_Dereference
(Loc
,
1835 New_Reference_To
(Defining_Identifier
(Decl_2
), Loc
))));
1837 -- Ensure proper matching of access types. Required to avoid
1838 -- reporting spurious errors.
1840 elsif Is_Access_Type
(Etype
(Target_Formal
)) then
1842 Unchecked_Convert_To
(Base_Type
(Etype
(Target_Formal
)),
1843 New_Reference_To
(Defining_Identifier
(Formal
), Loc
)));
1845 -- No special management required for this actual
1849 New_Reference_To
(Defining_Identifier
(Formal
), Loc
));
1852 Next_Formal
(Target_Formal
);
1856 Thunk_Id
:= Make_Temporary
(Loc
, 'T');
1857 Set_Is_Thunk
(Thunk_Id
);
1858 Set_Convention
(Thunk_Id
, Convention
(Prim
));
1862 if Ekind
(Target
) = E_Procedure
then
1864 Make_Subprogram_Body
(Loc
,
1866 Make_Procedure_Specification
(Loc
,
1867 Defining_Unit_Name
=> Thunk_Id
,
1868 Parameter_Specifications
=> Formals
),
1869 Declarations
=> Decl
,
1870 Handled_Statement_Sequence
=>
1871 Make_Handled_Sequence_Of_Statements
(Loc
,
1872 Statements
=> New_List
(
1873 Make_Procedure_Call_Statement
(Loc
,
1874 Name
=> New_Occurrence_Of
(Target
, Loc
),
1875 Parameter_Associations
=> Actuals
))));
1879 else pragma Assert
(Ekind
(Target
) = E_Function
);
1881 Make_Subprogram_Body
(Loc
,
1883 Make_Function_Specification
(Loc
,
1884 Defining_Unit_Name
=> Thunk_Id
,
1885 Parameter_Specifications
=> Formals
,
1886 Result_Definition
=>
1887 New_Copy
(Result_Definition
(Parent
(Target
)))),
1888 Declarations
=> Decl
,
1889 Handled_Statement_Sequence
=>
1890 Make_Handled_Sequence_Of_Statements
(Loc
,
1891 Statements
=> New_List
(
1892 Make_Simple_Return_Statement
(Loc
,
1893 Make_Function_Call
(Loc
,
1894 Name
=> New_Occurrence_Of
(Target
, Loc
),
1895 Parameter_Associations
=> Actuals
)))));
1897 end Expand_Interface_Thunk
;
1899 ------------------------
1900 -- Find_Specific_Type --
1901 ------------------------
1903 function Find_Specific_Type
(CW
: Entity_Id
) return Entity_Id
is
1904 Typ
: Entity_Id
:= Root_Type
(CW
);
1907 if Ekind
(Typ
) = E_Incomplete_Type
then
1908 if From_With_Type
(Typ
) then
1909 Typ
:= Non_Limited_View
(Typ
);
1911 Typ
:= Full_View
(Typ
);
1916 end Find_Specific_Type
;
1918 --------------------------
1919 -- Has_CPP_Constructors --
1920 --------------------------
1922 function Has_CPP_Constructors
(Typ
: Entity_Id
) return Boolean is
1926 -- Look for the constructor entities
1928 E
:= Next_Entity
(Typ
);
1929 while Present
(E
) loop
1930 if Ekind
(E
) = E_Function
1931 and then Is_Constructor
(E
)
1940 end Has_CPP_Constructors
;
1946 function Has_DT
(Typ
: Entity_Id
) return Boolean is
1948 return not Is_Interface
(Typ
)
1949 and then not Restriction_Active
(No_Dispatching_Calls
);
1952 -----------------------------------------
1953 -- Is_Predefined_Dispatching_Operation --
1954 -----------------------------------------
1956 function Is_Predefined_Dispatching_Operation
1957 (E
: Entity_Id
) return Boolean
1959 TSS_Name
: TSS_Name_Type
;
1962 if not Is_Dispatching_Operation
(E
) then
1966 Get_Name_String
(Chars
(E
));
1968 -- Most predefined primitives have internally generated names. Equality
1969 -- must be treated differently; the predefined operation is recognized
1970 -- as a homogeneous binary operator that returns Boolean.
1972 if Name_Len
> TSS_Name_Type
'Last then
1973 TSS_Name
:= TSS_Name_Type
(Name_Buffer
(Name_Len
- TSS_Name
'Length + 1
1975 if Chars
(E
) = Name_uSize
1976 or else TSS_Name
= TSS_Stream_Read
1977 or else TSS_Name
= TSS_Stream_Write
1978 or else TSS_Name
= TSS_Stream_Input
1979 or else TSS_Name
= TSS_Stream_Output
1981 (Chars
(E
) = Name_Op_Eq
1982 and then Etype
(First_Formal
(E
)) = Etype
(Last_Formal
(E
)))
1983 or else Chars
(E
) = Name_uAssign
1984 or else TSS_Name
= TSS_Deep_Adjust
1985 or else TSS_Name
= TSS_Deep_Finalize
1986 or else Is_Predefined_Interface_Primitive
(E
)
1993 end Is_Predefined_Dispatching_Operation
;
1995 ---------------------------------------
1996 -- Is_Predefined_Internal_Operation --
1997 ---------------------------------------
1999 function Is_Predefined_Internal_Operation
2000 (E
: Entity_Id
) return Boolean
2002 TSS_Name
: TSS_Name_Type
;
2005 if not Is_Dispatching_Operation
(E
) then
2009 Get_Name_String
(Chars
(E
));
2011 -- Most predefined primitives have internally generated names. Equality
2012 -- must be treated differently; the predefined operation is recognized
2013 -- as a homogeneous binary operator that returns Boolean.
2015 if Name_Len
> TSS_Name_Type
'Last then
2018 (Name_Buffer
(Name_Len
- TSS_Name
'Length + 1 .. Name_Len
));
2020 if Chars
(E
) = Name_uSize
2022 (Chars
(E
) = Name_Op_Eq
2023 and then Etype
(First_Formal
(E
)) = Etype
(Last_Formal
(E
)))
2024 or else Chars
(E
) = Name_uAssign
2025 or else TSS_Name
= TSS_Deep_Adjust
2026 or else TSS_Name
= TSS_Deep_Finalize
2027 or else Is_Predefined_Interface_Primitive
(E
)
2034 end Is_Predefined_Internal_Operation
;
2036 -------------------------------------
2037 -- Is_Predefined_Dispatching_Alias --
2038 -------------------------------------
2040 function Is_Predefined_Dispatching_Alias
(Prim
: Entity_Id
) return Boolean
2043 return not Is_Predefined_Dispatching_Operation
(Prim
)
2044 and then Present
(Alias
(Prim
))
2045 and then Is_Predefined_Dispatching_Operation
(Ultimate_Alias
(Prim
));
2046 end Is_Predefined_Dispatching_Alias
;
2048 ---------------------------------------
2049 -- Is_Predefined_Interface_Primitive --
2050 ---------------------------------------
2052 function Is_Predefined_Interface_Primitive
(E
: Entity_Id
) return Boolean is
2054 -- In VM targets we don't restrict the functionality of this test to
2055 -- compiling in Ada 2005 mode since in VM targets any tagged type has
2058 return (Ada_Version
>= Ada_2005
or else not Tagged_Type_Expansion
)
2059 and then (Chars
(E
) = Name_uDisp_Asynchronous_Select
or else
2060 Chars
(E
) = Name_uDisp_Conditional_Select
or else
2061 Chars
(E
) = Name_uDisp_Get_Prim_Op_Kind
or else
2062 Chars
(E
) = Name_uDisp_Get_Task_Id
or else
2063 Chars
(E
) = Name_uDisp_Requeue
or else
2064 Chars
(E
) = Name_uDisp_Timed_Select
);
2065 end Is_Predefined_Interface_Primitive
;
2067 ----------------------------------------
2068 -- Make_Disp_Asynchronous_Select_Body --
2069 ----------------------------------------
2071 -- For interface types, generate:
2073 -- procedure _Disp_Asynchronous_Select
2074 -- (T : in out <Typ>;
2076 -- P : System.Address;
2077 -- B : out System.Storage_Elements.Dummy_Communication_Block;
2082 -- C := Ada.Tags.POK_Function;
2083 -- end _Disp_Asynchronous_Select;
2085 -- For protected types, generate:
2087 -- procedure _Disp_Asynchronous_Select
2088 -- (T : in out <Typ>;
2090 -- P : System.Address;
2091 -- B : out System.Storage_Elements.Dummy_Communication_Block;
2095 -- Ada.Tags.Get_Entry_Index (Ada.Tags.Tag (<Typ>VP, S));
2096 -- Bnn : System.Tasking.Protected_Objects.Operations.
2097 -- Communication_Block;
2099 -- System.Tasking.Protected_Objects.Operations.Protected_Entry_Call
2100 -- (T._object'Access,
2101 -- System.Tasking.Protected_Objects.Protected_Entry_Index (I),
2103 -- System.Tasking.Asynchronous_Call,
2105 -- B := System.Storage_Elements.Dummy_Communication_Block (Bnn);
2106 -- end _Disp_Asynchronous_Select;
2108 -- For task types, generate:
2110 -- procedure _Disp_Asynchronous_Select
2111 -- (T : in out <Typ>;
2113 -- P : System.Address;
2114 -- B : out System.Storage_Elements.Dummy_Communication_Block;
2118 -- Ada.Tags.Get_Entry_Index (Ada.Tags.Tag (<Typ>VP, S));
2120 -- System.Tasking.Rendezvous.Task_Entry_Call
2122 -- System.Tasking.Task_Entry_Index (I),
2124 -- System.Tasking.Asynchronous_Call,
2126 -- end _Disp_Asynchronous_Select;
2128 function Make_Disp_Asynchronous_Select_Body
2129 (Typ
: Entity_Id
) return Node_Id
2131 Com_Block
: Entity_Id
;
2132 Conc_Typ
: Entity_Id
:= Empty
;
2133 Decls
: constant List_Id
:= New_List
;
2134 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
2136 Stmts
: constant List_Id
:= New_List
;
2140 pragma Assert
(not Restriction_Active
(No_Dispatching_Calls
));
2142 -- Null body is generated for interface types
2144 if Is_Interface
(Typ
) then
2146 Make_Subprogram_Body
(Loc
,
2147 Specification
=> Make_Disp_Asynchronous_Select_Spec
(Typ
),
2148 Declarations
=> New_List
,
2149 Handled_Statement_Sequence
=>
2150 Make_Handled_Sequence_Of_Statements
(Loc
,
2151 New_List
(Make_Assignment_Statement
(Loc
,
2152 Name
=> Make_Identifier
(Loc
, Name_uF
),
2153 Expression
=> New_Reference_To
(Standard_False
, Loc
)))));
2156 if Is_Concurrent_Record_Type
(Typ
) then
2157 Conc_Typ
:= Corresponding_Concurrent_Type
(Typ
);
2161 -- Ada.Tags.Get_Entry_Index (Ada.Tags.Tag! (<type>VP), S);
2163 -- where I will be used to capture the entry index of the primitive
2164 -- wrapper at position S.
2166 if Tagged_Type_Expansion
then
2168 Unchecked_Convert_To
(RTE
(RE_Tag
),
2170 (Node
(First_Elmt
(Access_Disp_Table
(Typ
))), Loc
));
2173 Make_Attribute_Reference
(Loc
,
2174 Prefix
=> New_Reference_To
(Typ
, Loc
),
2175 Attribute_Name
=> Name_Tag
);
2179 Make_Object_Declaration
(Loc
,
2180 Defining_Identifier
=>
2181 Make_Defining_Identifier
(Loc
, Name_uI
),
2182 Object_Definition
=>
2183 New_Reference_To
(Standard_Integer
, Loc
),
2185 Make_Function_Call
(Loc
,
2187 New_Reference_To
(RTE
(RE_Get_Entry_Index
), Loc
),
2188 Parameter_Associations
=>
2191 Make_Identifier
(Loc
, Name_uS
)))));
2193 if Ekind
(Conc_Typ
) = E_Protected_Type
then
2196 -- Bnn : Communication_Block;
2198 Com_Block
:= Make_Temporary
(Loc
, 'B');
2200 Make_Object_Declaration
(Loc
,
2201 Defining_Identifier
=>
2203 Object_Definition
=>
2204 New_Reference_To
(RTE
(RE_Communication_Block
), Loc
)));
2206 -- Build T._object'Access for calls below
2209 Make_Attribute_Reference
(Loc
,
2210 Attribute_Name
=> Name_Unchecked_Access
,
2212 Make_Selected_Component
(Loc
,
2213 Prefix
=> Make_Identifier
(Loc
, Name_uT
),
2214 Selector_Name
=> Make_Identifier
(Loc
, Name_uObject
)));
2216 case Corresponding_Runtime_Package
(Conc_Typ
) is
2217 when System_Tasking_Protected_Objects_Entries
=>
2220 -- Protected_Entry_Call
2221 -- (T._object'Access, -- Object
2222 -- Protected_Entry_Index! (I), -- E
2223 -- P, -- Uninterpreted_Data
2224 -- Asynchronous_Call, -- Mode
2225 -- Bnn); -- Communication_Block
2227 -- where T is the protected object, I is the entry index, P
2228 -- is the wrapped parameters and B is the name of the
2229 -- communication block.
2232 Make_Procedure_Call_Statement
(Loc
,
2234 New_Reference_To
(RTE
(RE_Protected_Entry_Call
), Loc
),
2235 Parameter_Associations
=>
2239 Make_Unchecked_Type_Conversion
(Loc
, -- entry index
2242 (RTE
(RE_Protected_Entry_Index
), Loc
),
2243 Expression
=> Make_Identifier
(Loc
, Name_uI
)),
2245 Make_Identifier
(Loc
, Name_uP
), -- parameter block
2246 New_Reference_To
-- Asynchronous_Call
2247 (RTE
(RE_Asynchronous_Call
), Loc
),
2249 New_Reference_To
(Com_Block
, Loc
)))); -- comm block
2251 when System_Tasking_Protected_Objects_Single_Entry
=>
2254 -- procedure Protected_Single_Entry_Call
2255 -- (Object : Protection_Entry_Access;
2256 -- Uninterpreted_Data : System.Address;
2257 -- Mode : Call_Modes);
2260 Make_Procedure_Call_Statement
(Loc
,
2263 (RTE
(RE_Protected_Single_Entry_Call
), Loc
),
2264 Parameter_Associations
=>
2268 Make_Attribute_Reference
(Loc
,
2269 Prefix
=> Make_Identifier
(Loc
, Name_uP
),
2270 Attribute_Name
=> Name_Address
),
2273 (RTE
(RE_Asynchronous_Call
), Loc
))));
2276 raise Program_Error
;
2280 -- B := Dummy_Communication_Block (Bnn);
2283 Make_Assignment_Statement
(Loc
,
2284 Name
=> Make_Identifier
(Loc
, Name_uB
),
2286 Make_Unchecked_Type_Conversion
(Loc
,
2289 RTE
(RE_Dummy_Communication_Block
), Loc
),
2291 New_Reference_To
(Com_Block
, Loc
))));
2297 Make_Assignment_Statement
(Loc
,
2298 Name
=> Make_Identifier
(Loc
, Name_uF
),
2299 Expression
=> New_Reference_To
(Standard_False
, Loc
)));
2302 pragma Assert
(Ekind
(Conc_Typ
) = E_Task_Type
);
2306 -- (T._task_id, -- Acceptor
2307 -- Task_Entry_Index! (I), -- E
2308 -- P, -- Uninterpreted_Data
2309 -- Asynchronous_Call, -- Mode
2310 -- F); -- Rendezvous_Successful
2312 -- where T is the task object, I is the entry index, P is the
2313 -- wrapped parameters and F is the status flag.
2316 Make_Procedure_Call_Statement
(Loc
,
2318 New_Reference_To
(RTE
(RE_Task_Entry_Call
), Loc
),
2319 Parameter_Associations
=>
2321 Make_Selected_Component
(Loc
, -- T._task_id
2322 Prefix
=> Make_Identifier
(Loc
, Name_uT
),
2323 Selector_Name
=> Make_Identifier
(Loc
, Name_uTask_Id
)),
2325 Make_Unchecked_Type_Conversion
(Loc
, -- entry index
2327 New_Reference_To
(RTE
(RE_Task_Entry_Index
), Loc
),
2328 Expression
=> Make_Identifier
(Loc
, Name_uI
)),
2330 Make_Identifier
(Loc
, Name_uP
), -- parameter block
2331 New_Reference_To
-- Asynchronous_Call
2332 (RTE
(RE_Asynchronous_Call
), Loc
),
2333 Make_Identifier
(Loc
, Name_uF
)))); -- status flag
2337 -- Ensure that the statements list is non-empty
2340 Make_Assignment_Statement
(Loc
,
2341 Name
=> Make_Identifier
(Loc
, Name_uF
),
2342 Expression
=> New_Reference_To
(Standard_False
, Loc
)));
2346 Make_Subprogram_Body
(Loc
,
2348 Make_Disp_Asynchronous_Select_Spec
(Typ
),
2349 Declarations
=> Decls
,
2350 Handled_Statement_Sequence
=>
2351 Make_Handled_Sequence_Of_Statements
(Loc
, Stmts
));
2352 end Make_Disp_Asynchronous_Select_Body
;
2354 ----------------------------------------
2355 -- Make_Disp_Asynchronous_Select_Spec --
2356 ----------------------------------------
2358 function Make_Disp_Asynchronous_Select_Spec
2359 (Typ
: Entity_Id
) return Node_Id
2361 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
2362 Def_Id
: constant Node_Id
:=
2363 Make_Defining_Identifier
(Loc
,
2364 Name_uDisp_Asynchronous_Select
);
2365 Params
: constant List_Id
:= New_List
;
2368 pragma Assert
(not Restriction_Active
(No_Dispatching_Calls
));
2370 -- T : in out Typ; -- Object parameter
2371 -- S : Integer; -- Primitive operation slot
2372 -- P : Address; -- Wrapped parameters
2373 -- B : out Dummy_Communication_Block; -- Communication block dummy
2374 -- F : out Boolean; -- Status flag
2376 Append_List_To
(Params
, New_List
(
2378 Make_Parameter_Specification
(Loc
,
2379 Defining_Identifier
=>
2380 Make_Defining_Identifier
(Loc
, Name_uT
),
2382 New_Reference_To
(Typ
, Loc
),
2384 Out_Present
=> True),
2386 Make_Parameter_Specification
(Loc
,
2387 Defining_Identifier
=>
2388 Make_Defining_Identifier
(Loc
, Name_uS
),
2390 New_Reference_To
(Standard_Integer
, Loc
)),
2392 Make_Parameter_Specification
(Loc
,
2393 Defining_Identifier
=>
2394 Make_Defining_Identifier
(Loc
, Name_uP
),
2396 New_Reference_To
(RTE
(RE_Address
), Loc
)),
2398 Make_Parameter_Specification
(Loc
,
2399 Defining_Identifier
=>
2400 Make_Defining_Identifier
(Loc
, Name_uB
),
2402 New_Reference_To
(RTE
(RE_Dummy_Communication_Block
), Loc
),
2403 Out_Present
=> True),
2405 Make_Parameter_Specification
(Loc
,
2406 Defining_Identifier
=>
2407 Make_Defining_Identifier
(Loc
, Name_uF
),
2409 New_Reference_To
(Standard_Boolean
, Loc
),
2410 Out_Present
=> True)));
2413 Make_Procedure_Specification
(Loc
,
2414 Defining_Unit_Name
=> Def_Id
,
2415 Parameter_Specifications
=> Params
);
2416 end Make_Disp_Asynchronous_Select_Spec
;
2418 ---------------------------------------
2419 -- Make_Disp_Conditional_Select_Body --
2420 ---------------------------------------
2422 -- For interface types, generate:
2424 -- procedure _Disp_Conditional_Select
2425 -- (T : in out <Typ>;
2427 -- P : System.Address;
2428 -- C : out Ada.Tags.Prim_Op_Kind;
2433 -- C := Ada.Tags.POK_Function;
2434 -- end _Disp_Conditional_Select;
2436 -- For protected types, generate:
2438 -- procedure _Disp_Conditional_Select
2439 -- (T : in out <Typ>;
2441 -- P : System.Address;
2442 -- C : out Ada.Tags.Prim_Op_Kind;
2446 -- Bnn : System.Tasking.Protected_Objects.Operations.
2447 -- Communication_Block;
2450 -- C := Ada.Tags.Get_Prim_Op_Kind (Ada.Tags.Tag (<Typ>VP, S));
2452 -- if C = Ada.Tags.POK_Procedure
2453 -- or else C = Ada.Tags.POK_Protected_Procedure
2454 -- or else C = Ada.Tags.POK_Task_Procedure
2460 -- I := Ada.Tags.Get_Entry_Index (Ada.Tags.Tag (<Typ>VP, S));
2461 -- System.Tasking.Protected_Objects.Operations.Protected_Entry_Call
2462 -- (T.object'Access,
2463 -- System.Tasking.Protected_Objects.Protected_Entry_Index (I),
2465 -- System.Tasking.Conditional_Call,
2467 -- F := not Cancelled (Bnn);
2468 -- end _Disp_Conditional_Select;
2470 -- For task types, generate:
2472 -- procedure _Disp_Conditional_Select
2473 -- (T : in out <Typ>;
2475 -- P : System.Address;
2476 -- C : out Ada.Tags.Prim_Op_Kind;
2482 -- I := Ada.Tags.Get_Entry_Index (Ada.Tags.Tag (<Typ>VP, S));
2483 -- System.Tasking.Rendezvous.Task_Entry_Call
2485 -- System.Tasking.Task_Entry_Index (I),
2487 -- System.Tasking.Conditional_Call,
2489 -- end _Disp_Conditional_Select;
2491 function Make_Disp_Conditional_Select_Body
2492 (Typ
: Entity_Id
) return Node_Id
2494 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
2495 Blk_Nam
: Entity_Id
;
2496 Conc_Typ
: Entity_Id
:= Empty
;
2497 Decls
: constant List_Id
:= New_List
;
2499 Stmts
: constant List_Id
:= New_List
;
2503 pragma Assert
(not Restriction_Active
(No_Dispatching_Calls
));
2505 -- Null body is generated for interface types
2507 if Is_Interface
(Typ
) then
2509 Make_Subprogram_Body
(Loc
,
2511 Make_Disp_Conditional_Select_Spec
(Typ
),
2514 Handled_Statement_Sequence
=>
2515 Make_Handled_Sequence_Of_Statements
(Loc
,
2516 New_List
(Make_Assignment_Statement
(Loc
,
2517 Name
=> Make_Identifier
(Loc
, Name_uF
),
2518 Expression
=> New_Reference_To
(Standard_False
, Loc
)))));
2521 if Is_Concurrent_Record_Type
(Typ
) then
2522 Conc_Typ
:= Corresponding_Concurrent_Type
(Typ
);
2527 -- where I will be used to capture the entry index of the primitive
2528 -- wrapper at position S.
2531 Make_Object_Declaration
(Loc
,
2532 Defining_Identifier
=>
2533 Make_Defining_Identifier
(Loc
, Name_uI
),
2534 Object_Definition
=>
2535 New_Reference_To
(Standard_Integer
, Loc
)));
2538 -- C := Ada.Tags.Get_Prim_Op_Kind (Ada.Tags.Tag! (<type>VP), S);
2540 -- if C = POK_Procedure
2541 -- or else C = POK_Protected_Procedure
2542 -- or else C = POK_Task_Procedure;
2548 Build_Common_Dispatching_Select_Statements
(Typ
, Stmts
);
2551 -- Bnn : Communication_Block;
2553 -- where Bnn is the name of the communication block used in the
2554 -- call to Protected_Entry_Call.
2556 Blk_Nam
:= Make_Temporary
(Loc
, 'B');
2558 Make_Object_Declaration
(Loc
,
2559 Defining_Identifier
=>
2561 Object_Definition
=>
2562 New_Reference_To
(RTE
(RE_Communication_Block
), Loc
)));
2565 -- I := Ada.Tags.Get_Entry_Index (Ada.Tags.Tag! (<type>VP), S);
2567 -- I is the entry index and S is the dispatch table slot
2569 if Tagged_Type_Expansion
then
2571 Unchecked_Convert_To
(RTE
(RE_Tag
),
2573 (Node
(First_Elmt
(Access_Disp_Table
(Typ
))), Loc
));
2577 Make_Attribute_Reference
(Loc
,
2578 Prefix
=> New_Reference_To
(Typ
, Loc
),
2579 Attribute_Name
=> Name_Tag
);
2583 Make_Assignment_Statement
(Loc
,
2584 Name
=> Make_Identifier
(Loc
, Name_uI
),
2586 Make_Function_Call
(Loc
,
2588 New_Reference_To
(RTE
(RE_Get_Entry_Index
), Loc
),
2589 Parameter_Associations
=>
2592 Make_Identifier
(Loc
, Name_uS
)))));
2594 if Ekind
(Conc_Typ
) = E_Protected_Type
then
2596 Obj_Ref
:= -- T._object'Access
2597 Make_Attribute_Reference
(Loc
,
2598 Attribute_Name
=> Name_Unchecked_Access
,
2600 Make_Selected_Component
(Loc
,
2601 Prefix
=> Make_Identifier
(Loc
, Name_uT
),
2602 Selector_Name
=> Make_Identifier
(Loc
, Name_uObject
)));
2604 case Corresponding_Runtime_Package
(Conc_Typ
) is
2605 when System_Tasking_Protected_Objects_Entries
=>
2608 -- Protected_Entry_Call
2609 -- (T._object'Access, -- Object
2610 -- Protected_Entry_Index! (I), -- E
2611 -- P, -- Uninterpreted_Data
2612 -- Conditional_Call, -- Mode
2615 -- where T is the protected object, I is the entry index, P
2616 -- are the wrapped parameters and Bnn is the name of the
2617 -- communication block.
2620 Make_Procedure_Call_Statement
(Loc
,
2622 New_Reference_To
(RTE
(RE_Protected_Entry_Call
), Loc
),
2623 Parameter_Associations
=>
2627 Make_Unchecked_Type_Conversion
(Loc
, -- entry index
2630 (RTE
(RE_Protected_Entry_Index
), Loc
),
2631 Expression
=> Make_Identifier
(Loc
, Name_uI
)),
2633 Make_Identifier
(Loc
, Name_uP
), -- parameter block
2635 New_Reference_To
( -- Conditional_Call
2636 RTE
(RE_Conditional_Call
), Loc
),
2637 New_Reference_To
( -- Bnn
2640 when System_Tasking_Protected_Objects_Single_Entry
=>
2642 -- If we are compiling for a restricted run-time, the call
2643 -- uses the simpler form.
2646 Make_Procedure_Call_Statement
(Loc
,
2649 (RTE
(RE_Protected_Single_Entry_Call
), Loc
),
2650 Parameter_Associations
=>
2654 Make_Attribute_Reference
(Loc
,
2655 Prefix
=> Make_Identifier
(Loc
, Name_uP
),
2656 Attribute_Name
=> Name_Address
),
2659 (RTE
(RE_Conditional_Call
), Loc
))));
2661 raise Program_Error
;
2665 -- F := not Cancelled (Bnn);
2667 -- where F is the success flag. The status of Cancelled is negated
2668 -- in order to match the behaviour of the version for task types.
2671 Make_Assignment_Statement
(Loc
,
2672 Name
=> Make_Identifier
(Loc
, Name_uF
),
2676 Make_Function_Call
(Loc
,
2678 New_Reference_To
(RTE
(RE_Cancelled
), Loc
),
2679 Parameter_Associations
=>
2681 New_Reference_To
(Blk_Nam
, Loc
))))));
2683 pragma Assert
(Ekind
(Conc_Typ
) = E_Task_Type
);
2687 -- (T._task_id, -- Acceptor
2688 -- Task_Entry_Index! (I), -- E
2689 -- P, -- Uninterpreted_Data
2690 -- Conditional_Call, -- Mode
2691 -- F); -- Rendezvous_Successful
2693 -- where T is the task object, I is the entry index, P are the
2694 -- wrapped parameters and F is the status flag.
2697 Make_Procedure_Call_Statement
(Loc
,
2699 New_Reference_To
(RTE
(RE_Task_Entry_Call
), Loc
),
2700 Parameter_Associations
=>
2703 Make_Selected_Component
(Loc
, -- T._task_id
2704 Prefix
=> Make_Identifier
(Loc
, Name_uT
),
2705 Selector_Name
=> Make_Identifier
(Loc
, Name_uTask_Id
)),
2707 Make_Unchecked_Type_Conversion
(Loc
, -- entry index
2709 New_Reference_To
(RTE
(RE_Task_Entry_Index
), Loc
),
2710 Expression
=> Make_Identifier
(Loc
, Name_uI
)),
2712 Make_Identifier
(Loc
, Name_uP
), -- parameter block
2713 New_Reference_To
-- Conditional_Call
2714 (RTE
(RE_Conditional_Call
), Loc
),
2715 Make_Identifier
(Loc
, Name_uF
)))); -- status flag
2719 -- Initialize out parameters
2722 Make_Assignment_Statement
(Loc
,
2723 Name
=> Make_Identifier
(Loc
, Name_uF
),
2724 Expression
=> New_Reference_To
(Standard_False
, Loc
)));
2726 Make_Assignment_Statement
(Loc
,
2727 Name
=> Make_Identifier
(Loc
, Name_uC
),
2728 Expression
=> New_Reference_To
(RTE
(RE_POK_Function
), Loc
)));
2732 Make_Subprogram_Body
(Loc
,
2734 Make_Disp_Conditional_Select_Spec
(Typ
),
2735 Declarations
=> Decls
,
2736 Handled_Statement_Sequence
=>
2737 Make_Handled_Sequence_Of_Statements
(Loc
, Stmts
));
2738 end Make_Disp_Conditional_Select_Body
;
2740 ---------------------------------------
2741 -- Make_Disp_Conditional_Select_Spec --
2742 ---------------------------------------
2744 function Make_Disp_Conditional_Select_Spec
2745 (Typ
: Entity_Id
) return Node_Id
2747 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
2748 Def_Id
: constant Node_Id
:=
2749 Make_Defining_Identifier
(Loc
,
2750 Name_uDisp_Conditional_Select
);
2751 Params
: constant List_Id
:= New_List
;
2754 pragma Assert
(not Restriction_Active
(No_Dispatching_Calls
));
2756 -- T : in out Typ; -- Object parameter
2757 -- S : Integer; -- Primitive operation slot
2758 -- P : Address; -- Wrapped parameters
2759 -- C : out Prim_Op_Kind; -- Call kind
2760 -- F : out Boolean; -- Status flag
2762 Append_List_To
(Params
, New_List
(
2764 Make_Parameter_Specification
(Loc
,
2765 Defining_Identifier
=>
2766 Make_Defining_Identifier
(Loc
, Name_uT
),
2768 New_Reference_To
(Typ
, Loc
),
2770 Out_Present
=> True),
2772 Make_Parameter_Specification
(Loc
,
2773 Defining_Identifier
=>
2774 Make_Defining_Identifier
(Loc
, Name_uS
),
2776 New_Reference_To
(Standard_Integer
, Loc
)),
2778 Make_Parameter_Specification
(Loc
,
2779 Defining_Identifier
=>
2780 Make_Defining_Identifier
(Loc
, Name_uP
),
2782 New_Reference_To
(RTE
(RE_Address
), Loc
)),
2784 Make_Parameter_Specification
(Loc
,
2785 Defining_Identifier
=>
2786 Make_Defining_Identifier
(Loc
, Name_uC
),
2788 New_Reference_To
(RTE
(RE_Prim_Op_Kind
), Loc
),
2789 Out_Present
=> True),
2791 Make_Parameter_Specification
(Loc
,
2792 Defining_Identifier
=>
2793 Make_Defining_Identifier
(Loc
, Name_uF
),
2795 New_Reference_To
(Standard_Boolean
, Loc
),
2796 Out_Present
=> True)));
2799 Make_Procedure_Specification
(Loc
,
2800 Defining_Unit_Name
=> Def_Id
,
2801 Parameter_Specifications
=> Params
);
2802 end Make_Disp_Conditional_Select_Spec
;
2804 -------------------------------------
2805 -- Make_Disp_Get_Prim_Op_Kind_Body --
2806 -------------------------------------
2808 function Make_Disp_Get_Prim_Op_Kind_Body
2809 (Typ
: Entity_Id
) return Node_Id
2811 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
2815 pragma Assert
(not Restriction_Active
(No_Dispatching_Calls
));
2817 if Is_Interface
(Typ
) then
2819 Make_Subprogram_Body
(Loc
,
2821 Make_Disp_Get_Prim_Op_Kind_Spec
(Typ
),
2824 Handled_Statement_Sequence
=>
2825 Make_Handled_Sequence_Of_Statements
(Loc
,
2826 New_List
(Make_Null_Statement
(Loc
))));
2830 -- C := get_prim_op_kind (tag! (<type>VP), S);
2832 -- where C is the out parameter capturing the call kind and S is the
2833 -- dispatch table slot number.
2835 if Tagged_Type_Expansion
then
2837 Unchecked_Convert_To
(RTE
(RE_Tag
),
2839 (Node
(First_Elmt
(Access_Disp_Table
(Typ
))), Loc
));
2843 Make_Attribute_Reference
(Loc
,
2844 Prefix
=> New_Reference_To
(Typ
, Loc
),
2845 Attribute_Name
=> Name_Tag
);
2849 Make_Subprogram_Body
(Loc
,
2851 Make_Disp_Get_Prim_Op_Kind_Spec
(Typ
),
2854 Handled_Statement_Sequence
=>
2855 Make_Handled_Sequence_Of_Statements
(Loc
,
2857 Make_Assignment_Statement
(Loc
,
2859 Make_Identifier
(Loc
, Name_uC
),
2861 Make_Function_Call
(Loc
,
2863 New_Reference_To
(RTE
(RE_Get_Prim_Op_Kind
), Loc
),
2864 Parameter_Associations
=> New_List
(
2866 Make_Identifier
(Loc
, Name_uS
)))))));
2867 end Make_Disp_Get_Prim_Op_Kind_Body
;
2869 -------------------------------------
2870 -- Make_Disp_Get_Prim_Op_Kind_Spec --
2871 -------------------------------------
2873 function Make_Disp_Get_Prim_Op_Kind_Spec
2874 (Typ
: Entity_Id
) return Node_Id
2876 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
2877 Def_Id
: constant Node_Id
:=
2878 Make_Defining_Identifier
(Loc
,
2879 Name_uDisp_Get_Prim_Op_Kind
);
2880 Params
: constant List_Id
:= New_List
;
2883 pragma Assert
(not Restriction_Active
(No_Dispatching_Calls
));
2885 -- T : in out Typ; -- Object parameter
2886 -- S : Integer; -- Primitive operation slot
2887 -- C : out Prim_Op_Kind; -- Call kind
2889 Append_List_To
(Params
, New_List
(
2891 Make_Parameter_Specification
(Loc
,
2892 Defining_Identifier
=>
2893 Make_Defining_Identifier
(Loc
, Name_uT
),
2895 New_Reference_To
(Typ
, Loc
),
2897 Out_Present
=> True),
2899 Make_Parameter_Specification
(Loc
,
2900 Defining_Identifier
=>
2901 Make_Defining_Identifier
(Loc
, Name_uS
),
2903 New_Reference_To
(Standard_Integer
, Loc
)),
2905 Make_Parameter_Specification
(Loc
,
2906 Defining_Identifier
=>
2907 Make_Defining_Identifier
(Loc
, Name_uC
),
2909 New_Reference_To
(RTE
(RE_Prim_Op_Kind
), Loc
),
2910 Out_Present
=> True)));
2913 Make_Procedure_Specification
(Loc
,
2914 Defining_Unit_Name
=> Def_Id
,
2915 Parameter_Specifications
=> Params
);
2916 end Make_Disp_Get_Prim_Op_Kind_Spec
;
2918 --------------------------------
2919 -- Make_Disp_Get_Task_Id_Body --
2920 --------------------------------
2922 function Make_Disp_Get_Task_Id_Body
2923 (Typ
: Entity_Id
) return Node_Id
2925 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
2929 pragma Assert
(not Restriction_Active
(No_Dispatching_Calls
));
2931 if Is_Concurrent_Record_Type
(Typ
)
2932 and then Ekind
(Corresponding_Concurrent_Type
(Typ
)) = E_Task_Type
2935 -- return To_Address (_T._task_id);
2938 Make_Simple_Return_Statement
(Loc
,
2940 Make_Unchecked_Type_Conversion
(Loc
,
2942 New_Reference_To
(RTE
(RE_Address
), Loc
),
2944 Make_Selected_Component
(Loc
,
2945 Prefix
=> Make_Identifier
(Loc
, Name_uT
),
2946 Selector_Name
=> Make_Identifier
(Loc
, Name_uTask_Id
))));
2948 -- A null body is constructed for non-task types
2952 -- return Null_Address;
2955 Make_Simple_Return_Statement
(Loc
,
2957 New_Reference_To
(RTE
(RE_Null_Address
), Loc
));
2961 Make_Subprogram_Body
(Loc
,
2963 Make_Disp_Get_Task_Id_Spec
(Typ
),
2966 Handled_Statement_Sequence
=>
2967 Make_Handled_Sequence_Of_Statements
(Loc
,
2969 end Make_Disp_Get_Task_Id_Body
;
2971 --------------------------------
2972 -- Make_Disp_Get_Task_Id_Spec --
2973 --------------------------------
2975 function Make_Disp_Get_Task_Id_Spec
2976 (Typ
: Entity_Id
) return Node_Id
2978 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
2981 pragma Assert
(not Restriction_Active
(No_Dispatching_Calls
));
2984 Make_Function_Specification
(Loc
,
2985 Defining_Unit_Name
=>
2986 Make_Defining_Identifier
(Loc
, Name_uDisp_Get_Task_Id
),
2987 Parameter_Specifications
=> New_List
(
2988 Make_Parameter_Specification
(Loc
,
2989 Defining_Identifier
=>
2990 Make_Defining_Identifier
(Loc
, Name_uT
),
2992 New_Reference_To
(Typ
, Loc
))),
2993 Result_Definition
=>
2994 New_Reference_To
(RTE
(RE_Address
), Loc
));
2995 end Make_Disp_Get_Task_Id_Spec
;
2997 ----------------------------
2998 -- Make_Disp_Requeue_Body --
2999 ----------------------------
3001 function Make_Disp_Requeue_Body
3002 (Typ
: Entity_Id
) return Node_Id
3004 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
3005 Conc_Typ
: Entity_Id
:= Empty
;
3006 Stmts
: constant List_Id
:= New_List
;
3009 pragma Assert
(not Restriction_Active
(No_Dispatching_Calls
));
3011 -- Null body is generated for interface types and non-concurrent
3014 if Is_Interface
(Typ
)
3015 or else not Is_Concurrent_Record_Type
(Typ
)
3018 Make_Subprogram_Body
(Loc
,
3020 Make_Disp_Requeue_Spec
(Typ
),
3023 Handled_Statement_Sequence
=>
3024 Make_Handled_Sequence_Of_Statements
(Loc
,
3025 New_List
(Make_Null_Statement
(Loc
))));
3028 Conc_Typ
:= Corresponding_Concurrent_Type
(Typ
);
3030 if Ekind
(Conc_Typ
) = E_Protected_Type
then
3032 -- Generate statements:
3034 -- System.Tasking.Protected_Objects.Operations.
3035 -- Requeue_Protected_Entry
3036 -- (Protection_Entries_Access (P),
3037 -- O._object'Unchecked_Access,
3038 -- Protected_Entry_Index (I),
3041 -- System.Tasking.Protected_Objects.Operations.
3042 -- Requeue_Task_To_Protected_Entry
3043 -- (O._object'Unchecked_Access,
3044 -- Protected_Entry_Index (I),
3048 if Restriction_Active
(No_Entry_Queue
) then
3049 Append_To
(Stmts
, Make_Null_Statement
(Loc
));
3052 Make_If_Statement
(Loc
,
3053 Condition
=> Make_Identifier
(Loc
, Name_uF
),
3058 -- Call to Requeue_Protected_Entry
3060 Make_Procedure_Call_Statement
(Loc
,
3063 RTE
(RE_Requeue_Protected_Entry
), Loc
),
3064 Parameter_Associations
=>
3067 Make_Unchecked_Type_Conversion
(Loc
, -- PEA (P)
3070 RTE
(RE_Protection_Entries_Access
), Loc
),
3072 Make_Identifier
(Loc
, Name_uP
)),
3074 Make_Attribute_Reference
(Loc
, -- O._object'Acc
3076 Name_Unchecked_Access
,
3078 Make_Selected_Component
(Loc
,
3080 Make_Identifier
(Loc
, Name_uO
),
3082 Make_Identifier
(Loc
, Name_uObject
))),
3084 Make_Unchecked_Type_Conversion
(Loc
, -- entry index
3087 RTE
(RE_Protected_Entry_Index
), Loc
),
3088 Expression
=> Make_Identifier
(Loc
, Name_uI
)),
3090 Make_Identifier
(Loc
, Name_uA
)))), -- abort status
3095 -- Call to Requeue_Task_To_Protected_Entry
3097 Make_Procedure_Call_Statement
(Loc
,
3100 RTE
(RE_Requeue_Task_To_Protected_Entry
), Loc
),
3101 Parameter_Associations
=>
3104 Make_Attribute_Reference
(Loc
, -- O._object'Acc
3106 Name_Unchecked_Access
,
3108 Make_Selected_Component
(Loc
,
3110 Make_Identifier
(Loc
, Name_uO
),
3112 Make_Identifier
(Loc
, Name_uObject
))),
3114 Make_Unchecked_Type_Conversion
(Loc
, -- entry index
3117 RTE
(RE_Protected_Entry_Index
), Loc
),
3119 Make_Identifier
(Loc
, Name_uI
)),
3121 Make_Identifier
(Loc
, Name_uA
)))))); -- abort status
3124 pragma Assert
(Is_Task_Type
(Conc_Typ
));
3128 -- System.Tasking.Rendezvous.Requeue_Protected_To_Task_Entry
3129 -- (Protection_Entries_Access (P),
3131 -- Task_Entry_Index (I),
3134 -- System.Tasking.Rendezvous.Requeue_Task_Entry
3136 -- Task_Entry_Index (I),
3141 Make_If_Statement
(Loc
,
3142 Condition
=> Make_Identifier
(Loc
, Name_uF
),
3144 Then_Statements
=> New_List
(
3146 -- Call to Requeue_Protected_To_Task_Entry
3148 Make_Procedure_Call_Statement
(Loc
,
3151 (RTE
(RE_Requeue_Protected_To_Task_Entry
), Loc
),
3153 Parameter_Associations
=> New_List
(
3155 Make_Unchecked_Type_Conversion
(Loc
, -- PEA (P)
3158 (RTE
(RE_Protection_Entries_Access
), Loc
),
3159 Expression
=> Make_Identifier
(Loc
, Name_uP
)),
3161 Make_Selected_Component
(Loc
, -- O._task_id
3162 Prefix
=> Make_Identifier
(Loc
, Name_uO
),
3163 Selector_Name
=> Make_Identifier
(Loc
, Name_uTask_Id
)),
3165 Make_Unchecked_Type_Conversion
(Loc
, -- entry index
3167 New_Reference_To
(RTE
(RE_Task_Entry_Index
), Loc
),
3168 Expression
=> Make_Identifier
(Loc
, Name_uI
)),
3170 Make_Identifier
(Loc
, Name_uA
)))), -- abort status
3172 Else_Statements
=> New_List
(
3174 -- Call to Requeue_Task_Entry
3176 Make_Procedure_Call_Statement
(Loc
,
3177 Name
=> New_Reference_To
(RTE
(RE_Requeue_Task_Entry
), Loc
),
3179 Parameter_Associations
=> New_List
(
3181 Make_Selected_Component
(Loc
, -- O._task_id
3182 Prefix
=> Make_Identifier
(Loc
, Name_uO
),
3183 Selector_Name
=> Make_Identifier
(Loc
, Name_uTask_Id
)),
3185 Make_Unchecked_Type_Conversion
(Loc
, -- entry index
3187 New_Reference_To
(RTE
(RE_Task_Entry_Index
), Loc
),
3188 Expression
=> Make_Identifier
(Loc
, Name_uI
)),
3190 Make_Identifier
(Loc
, Name_uA
)))))); -- abort status
3193 -- Even though no declarations are needed in both cases, we allocate
3194 -- a list for entities added by Freeze.
3197 Make_Subprogram_Body
(Loc
,
3199 Make_Disp_Requeue_Spec
(Typ
),
3202 Handled_Statement_Sequence
=>
3203 Make_Handled_Sequence_Of_Statements
(Loc
, Stmts
));
3204 end Make_Disp_Requeue_Body
;
3206 ----------------------------
3207 -- Make_Disp_Requeue_Spec --
3208 ----------------------------
3210 function Make_Disp_Requeue_Spec
3211 (Typ
: Entity_Id
) return Node_Id
3213 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
3216 pragma Assert
(not Restriction_Active
(No_Dispatching_Calls
));
3218 -- O : in out Typ; - Object parameter
3219 -- F : Boolean; - Protected (True) / task (False) flag
3220 -- P : Address; - Protection_Entries_Access value
3221 -- I : Entry_Index - Index of entry call
3222 -- A : Boolean - Abort flag
3224 -- Note that the Protection_Entries_Access value is represented as a
3225 -- System.Address in order to avoid dragging in the tasking runtime
3226 -- when compiling sources without tasking constructs.
3229 Make_Procedure_Specification
(Loc
,
3230 Defining_Unit_Name
=>
3231 Make_Defining_Identifier
(Loc
, Name_uDisp_Requeue
),
3233 Parameter_Specifications
=>
3236 Make_Parameter_Specification
(Loc
, -- O
3237 Defining_Identifier
=>
3238 Make_Defining_Identifier
(Loc
, Name_uO
),
3240 New_Reference_To
(Typ
, Loc
),
3242 Out_Present
=> True),
3244 Make_Parameter_Specification
(Loc
, -- F
3245 Defining_Identifier
=>
3246 Make_Defining_Identifier
(Loc
, Name_uF
),
3248 New_Reference_To
(Standard_Boolean
, Loc
)),
3250 Make_Parameter_Specification
(Loc
, -- P
3251 Defining_Identifier
=>
3252 Make_Defining_Identifier
(Loc
, Name_uP
),
3254 New_Reference_To
(RTE
(RE_Address
), Loc
)),
3256 Make_Parameter_Specification
(Loc
, -- I
3257 Defining_Identifier
=>
3258 Make_Defining_Identifier
(Loc
, Name_uI
),
3260 New_Reference_To
(Standard_Integer
, Loc
)),
3262 Make_Parameter_Specification
(Loc
, -- A
3263 Defining_Identifier
=>
3264 Make_Defining_Identifier
(Loc
, Name_uA
),
3266 New_Reference_To
(Standard_Boolean
, Loc
))));
3267 end Make_Disp_Requeue_Spec
;
3269 ---------------------------------
3270 -- Make_Disp_Timed_Select_Body --
3271 ---------------------------------
3273 -- For interface types, generate:
3275 -- procedure _Disp_Timed_Select
3276 -- (T : in out <Typ>;
3278 -- P : System.Address;
3281 -- C : out Ada.Tags.Prim_Op_Kind;
3286 -- C := Ada.Tags.POK_Function;
3287 -- end _Disp_Timed_Select;
3289 -- For protected types, generate:
3291 -- procedure _Disp_Timed_Select
3292 -- (T : in out <Typ>;
3294 -- P : System.Address;
3297 -- C : out Ada.Tags.Prim_Op_Kind;
3303 -- C := Ada.Tags.Get_Prim_Op_Kind (Ada.Tags.Tag (<Typ>VP), S);
3305 -- if C = Ada.Tags.POK_Procedure
3306 -- or else C = Ada.Tags.POK_Protected_Procedure
3307 -- or else C = Ada.Tags.POK_Task_Procedure
3313 -- I := Ada.Tags.Get_Entry_Index (Ada.Tags.Tag (<Typ>VP), S);
3314 -- System.Tasking.Protected_Objects.Operations.
3315 -- Timed_Protected_Entry_Call
3316 -- (T._object'Access,
3317 -- System.Tasking.Protected_Objects.Protected_Entry_Index (I),
3322 -- end _Disp_Timed_Select;
3324 -- For task types, generate:
3326 -- procedure _Disp_Timed_Select
3327 -- (T : in out <Typ>;
3329 -- P : System.Address;
3332 -- C : out Ada.Tags.Prim_Op_Kind;
3338 -- I := Ada.Tags.Get_Entry_Index (Ada.Tags.Tag (<Typ>VP), S);
3339 -- System.Tasking.Rendezvous.Timed_Task_Entry_Call
3341 -- System.Tasking.Task_Entry_Index (I),
3346 -- end _Disp_Time_Select;
3348 function Make_Disp_Timed_Select_Body
3349 (Typ
: Entity_Id
) return Node_Id
3351 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
3352 Conc_Typ
: Entity_Id
:= Empty
;
3353 Decls
: constant List_Id
:= New_List
;
3355 Stmts
: constant List_Id
:= New_List
;
3359 pragma Assert
(not Restriction_Active
(No_Dispatching_Calls
));
3361 -- Null body is generated for interface types
3363 if Is_Interface
(Typ
) then
3365 Make_Subprogram_Body
(Loc
,
3367 Make_Disp_Timed_Select_Spec
(Typ
),
3370 Handled_Statement_Sequence
=>
3371 Make_Handled_Sequence_Of_Statements
(Loc
,
3373 Make_Assignment_Statement
(Loc
,
3374 Name
=> Make_Identifier
(Loc
, Name_uF
),
3375 Expression
=> New_Reference_To
(Standard_False
, Loc
)))));
3378 if Is_Concurrent_Record_Type
(Typ
) then
3379 Conc_Typ
:= Corresponding_Concurrent_Type
(Typ
);
3384 -- where I will be used to capture the entry index of the primitive
3385 -- wrapper at position S.
3388 Make_Object_Declaration
(Loc
,
3389 Defining_Identifier
=> Make_Defining_Identifier
(Loc
, Name_uI
),
3390 Object_Definition
=> New_Reference_To
(Standard_Integer
, Loc
)));
3393 -- C := Get_Prim_Op_Kind (tag! (<type>VP), S);
3395 -- if C = POK_Procedure
3396 -- or else C = POK_Protected_Procedure
3397 -- or else C = POK_Task_Procedure;
3403 Build_Common_Dispatching_Select_Statements
(Typ
, Stmts
);
3406 -- I := Get_Entry_Index (tag! (<type>VP), S);
3408 -- I is the entry index and S is the dispatch table slot
3410 if Tagged_Type_Expansion
then
3412 Unchecked_Convert_To
(RTE
(RE_Tag
),
3414 (Node
(First_Elmt
(Access_Disp_Table
(Typ
))), Loc
));
3418 Make_Attribute_Reference
(Loc
,
3419 Prefix
=> New_Reference_To
(Typ
, Loc
),
3420 Attribute_Name
=> Name_Tag
);
3424 Make_Assignment_Statement
(Loc
,
3425 Name
=> Make_Identifier
(Loc
, Name_uI
),
3427 Make_Function_Call
(Loc
,
3428 Name
=> New_Reference_To
(RTE
(RE_Get_Entry_Index
), Loc
),
3429 Parameter_Associations
=>
3432 Make_Identifier
(Loc
, Name_uS
)))));
3436 if Ekind
(Conc_Typ
) = E_Protected_Type
then
3438 -- Build T._object'Access
3441 Make_Attribute_Reference
(Loc
,
3442 Attribute_Name
=> Name_Unchecked_Access
,
3444 Make_Selected_Component
(Loc
,
3445 Prefix
=> Make_Identifier
(Loc
, Name_uT
),
3446 Selector_Name
=> Make_Identifier
(Loc
, Name_uObject
)));
3448 -- Normal case, No_Entry_Queue restriction not active. In this
3449 -- case we generate:
3451 -- Timed_Protected_Entry_Call
3452 -- (T._object'access,
3453 -- Protected_Entry_Index! (I),
3456 -- where T is the protected object, I is the entry index, P are
3457 -- the wrapped parameters, D is the delay amount, M is the delay
3458 -- mode and F is the status flag.
3460 case Corresponding_Runtime_Package
(Conc_Typ
) is
3461 when System_Tasking_Protected_Objects_Entries
=>
3463 Make_Procedure_Call_Statement
(Loc
,
3466 (RTE
(RE_Timed_Protected_Entry_Call
), Loc
),
3467 Parameter_Associations
=>
3471 Make_Unchecked_Type_Conversion
(Loc
, -- entry index
3474 (RTE
(RE_Protected_Entry_Index
), Loc
),
3476 Make_Identifier
(Loc
, Name_uI
)),
3478 Make_Identifier
(Loc
, Name_uP
), -- parameter block
3479 Make_Identifier
(Loc
, Name_uD
), -- delay
3480 Make_Identifier
(Loc
, Name_uM
), -- delay mode
3481 Make_Identifier
(Loc
, Name_uF
)))); -- status flag
3483 when System_Tasking_Protected_Objects_Single_Entry
=>
3486 -- Timed_Protected_Single_Entry_Call
3487 -- (T._object'access, P, D, M, F);
3489 -- where T is the protected object, P is the wrapped
3490 -- parameters, D is the delay amount, M is the delay mode, F
3491 -- is the status flag.
3494 Make_Procedure_Call_Statement
(Loc
,
3497 (RTE
(RE_Timed_Protected_Single_Entry_Call
), Loc
),
3498 Parameter_Associations
=>
3501 Make_Identifier
(Loc
, Name_uP
), -- parameter block
3502 Make_Identifier
(Loc
, Name_uD
), -- delay
3503 Make_Identifier
(Loc
, Name_uM
), -- delay mode
3504 Make_Identifier
(Loc
, Name_uF
)))); -- status flag
3507 raise Program_Error
;
3513 pragma Assert
(Ekind
(Conc_Typ
) = E_Task_Type
);
3516 -- Timed_Task_Entry_Call (
3518 -- Task_Entry_Index! (I),
3524 -- where T is the task object, I is the entry index, P are the
3525 -- wrapped parameters, D is the delay amount, M is the delay
3526 -- mode and F is the status flag.
3529 Make_Procedure_Call_Statement
(Loc
,
3531 New_Reference_To
(RTE
(RE_Timed_Task_Entry_Call
), Loc
),
3532 Parameter_Associations
=>
3535 Make_Selected_Component
(Loc
, -- T._task_id
3536 Prefix
=> Make_Identifier
(Loc
, Name_uT
),
3537 Selector_Name
=> Make_Identifier
(Loc
, Name_uTask_Id
)),
3539 Make_Unchecked_Type_Conversion
(Loc
, -- entry index
3541 New_Reference_To
(RTE
(RE_Task_Entry_Index
), Loc
),
3542 Expression
=> Make_Identifier
(Loc
, Name_uI
)),
3544 Make_Identifier
(Loc
, Name_uP
), -- parameter block
3545 Make_Identifier
(Loc
, Name_uD
), -- delay
3546 Make_Identifier
(Loc
, Name_uM
), -- delay mode
3547 Make_Identifier
(Loc
, Name_uF
)))); -- status flag
3551 -- Initialize out parameters
3554 Make_Assignment_Statement
(Loc
,
3555 Name
=> Make_Identifier
(Loc
, Name_uF
),
3556 Expression
=> New_Reference_To
(Standard_False
, Loc
)));
3558 Make_Assignment_Statement
(Loc
,
3559 Name
=> Make_Identifier
(Loc
, Name_uC
),
3560 Expression
=> New_Reference_To
(RTE
(RE_POK_Function
), Loc
)));
3564 Make_Subprogram_Body
(Loc
,
3565 Specification
=> Make_Disp_Timed_Select_Spec
(Typ
),
3566 Declarations
=> Decls
,
3567 Handled_Statement_Sequence
=>
3568 Make_Handled_Sequence_Of_Statements
(Loc
, Stmts
));
3569 end Make_Disp_Timed_Select_Body
;
3571 ---------------------------------
3572 -- Make_Disp_Timed_Select_Spec --
3573 ---------------------------------
3575 function Make_Disp_Timed_Select_Spec
3576 (Typ
: Entity_Id
) return Node_Id
3578 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
3579 Def_Id
: constant Node_Id
:=
3580 Make_Defining_Identifier
(Loc
,
3581 Name_uDisp_Timed_Select
);
3582 Params
: constant List_Id
:= New_List
;
3585 pragma Assert
(not Restriction_Active
(No_Dispatching_Calls
));
3587 -- T : in out Typ; -- Object parameter
3588 -- S : Integer; -- Primitive operation slot
3589 -- P : Address; -- Wrapped parameters
3590 -- D : Duration; -- Delay
3591 -- M : Integer; -- Delay Mode
3592 -- C : out Prim_Op_Kind; -- Call kind
3593 -- F : out Boolean; -- Status flag
3595 Append_List_To
(Params
, New_List
(
3597 Make_Parameter_Specification
(Loc
,
3598 Defining_Identifier
=>
3599 Make_Defining_Identifier
(Loc
, Name_uT
),
3601 New_Reference_To
(Typ
, Loc
),
3603 Out_Present
=> True),
3605 Make_Parameter_Specification
(Loc
,
3606 Defining_Identifier
=>
3607 Make_Defining_Identifier
(Loc
, Name_uS
),
3609 New_Reference_To
(Standard_Integer
, Loc
)),
3611 Make_Parameter_Specification
(Loc
,
3612 Defining_Identifier
=>
3613 Make_Defining_Identifier
(Loc
, Name_uP
),
3615 New_Reference_To
(RTE
(RE_Address
), Loc
)),
3617 Make_Parameter_Specification
(Loc
,
3618 Defining_Identifier
=>
3619 Make_Defining_Identifier
(Loc
, Name_uD
),
3621 New_Reference_To
(Standard_Duration
, Loc
)),
3623 Make_Parameter_Specification
(Loc
,
3624 Defining_Identifier
=>
3625 Make_Defining_Identifier
(Loc
, Name_uM
),
3627 New_Reference_To
(Standard_Integer
, Loc
)),
3629 Make_Parameter_Specification
(Loc
,
3630 Defining_Identifier
=>
3631 Make_Defining_Identifier
(Loc
, Name_uC
),
3633 New_Reference_To
(RTE
(RE_Prim_Op_Kind
), Loc
),
3634 Out_Present
=> True)));
3637 Make_Parameter_Specification
(Loc
,
3638 Defining_Identifier
=>
3639 Make_Defining_Identifier
(Loc
, Name_uF
),
3641 New_Reference_To
(Standard_Boolean
, Loc
),
3642 Out_Present
=> True));
3645 Make_Procedure_Specification
(Loc
,
3646 Defining_Unit_Name
=> Def_Id
,
3647 Parameter_Specifications
=> Params
);
3648 end Make_Disp_Timed_Select_Spec
;
3654 -- The frontend supports two models for expanding dispatch tables
3655 -- associated with library-level defined tagged types: statically
3656 -- and non-statically allocated dispatch tables. In the former case
3657 -- the object containing the dispatch table is constant and it is
3658 -- initialized by means of a positional aggregate. In the latter case,
3659 -- the object containing the dispatch table is a variable which is
3660 -- initialized by means of assignments.
3662 -- In case of locally defined tagged types, the object containing the
3663 -- object containing the dispatch table is always a variable (instead
3664 -- of a constant). This is currently required to give support to late
3665 -- overriding of primitives. For example:
3667 -- procedure Example is
3669 -- type T1 is tagged null record;
3670 -- procedure Prim (O : T1);
3673 -- type T2 is new Pkg.T1 with null record;
3674 -- procedure Prim (X : T2) is -- late overriding
3680 function Make_DT
(Typ
: Entity_Id
; N
: Node_Id
:= Empty
) return List_Id
is
3681 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
3683 Max_Predef_Prims
: constant Int
:=
3687 (Parent
(RTE
(RE_Max_Predef_Prims
)))));
3689 DT_Decl
: constant Elist_Id
:= New_Elmt_List
;
3690 DT_Aggr
: constant Elist_Id
:= New_Elmt_List
;
3691 -- Entities marked with attribute Is_Dispatch_Table_Entity
3693 procedure Check_Premature_Freezing
3695 Tagged_Type
: Entity_Id
;
3697 -- Verify that all non-tagged types in the profile of a subprogram
3698 -- are frozen at the point the subprogram is frozen. This enforces
3699 -- the rule on RM 13.14 (14) as modified by AI05-019. At the point a
3700 -- subprogram is frozen, enough must be known about it to build the
3701 -- activation record for it, which requires at least that the size of
3702 -- all parameters be known. Controlling arguments are by-reference,
3703 -- and therefore the rule only applies to non-tagged types.
3704 -- Typical violation of the rule involves an object declaration that
3705 -- freezes a tagged type, when one of its primitive operations has a
3706 -- type in its profile whose full view has not been analyzed yet.
3707 -- More complex cases involve composite types that have one private
3708 -- unfrozen subcomponent.
3710 procedure Export_DT
(Typ
: Entity_Id
; DT
: Entity_Id
; Index
: Nat
:= 0);
3711 -- Export the dispatch table DT of tagged type Typ. Required to generate
3712 -- forward references and statically allocate the table. For primary
3713 -- dispatch tables Index is 0; for secondary dispatch tables the value
3714 -- of index must match the Suffix_Index value assigned to the table by
3715 -- Make_Tags when generating its unique external name, and it is used to
3716 -- retrieve from the Dispatch_Table_Wrappers list associated with Typ
3717 -- the external name generated by Import_DT.
3719 procedure Make_Secondary_DT
3723 Num_Iface_Prims
: Nat
;
3724 Iface_DT_Ptr
: Entity_Id
;
3725 Predef_Prims_Ptr
: Entity_Id
;
3726 Build_Thunks
: Boolean;
3728 -- Ada 2005 (AI-251): Expand the declarations for a Secondary Dispatch
3729 -- Table of Typ associated with Iface. Each abstract interface of Typ
3730 -- has two secondary dispatch tables: one containing pointers to thunks
3731 -- and another containing pointers to the primitives covering the
3732 -- interface primitives. The former secondary table is generated when
3733 -- Build_Thunks is True, and provides common support for dispatching
3734 -- calls through interface types; the latter secondary table is
3735 -- generated when Build_Thunks is False, and provides support for
3736 -- Generic Dispatching Constructors that dispatch calls through
3737 -- interface types. When constructing this latter table the value of
3738 -- Suffix_Index is -1 to indicate that there is no need to export such
3739 -- table when building statically allocated dispatch tables; a positive
3740 -- value of Suffix_Index must match the Suffix_Index value assigned to
3741 -- this secondary dispatch table by Make_Tags when its unique external
3742 -- name was generated.
3744 ------------------------------
3745 -- Check_Premature_Freezing --
3746 ------------------------------
3748 procedure Check_Premature_Freezing
3750 Tagged_Type
: Entity_Id
;
3755 function Is_Actual_For_Formal_Incomplete_Type
3756 (T
: Entity_Id
) return Boolean;
3757 -- In Ada 2012, if a nested generic has an incomplete formal type,
3758 -- the actual may be (and usually is) a private type whose completion
3759 -- appears later. It is safe to build the dispatch table in this
3760 -- case, gigi will have full views available.
3762 ------------------------------------------
3763 -- Is_Actual_For_Formal_Incomplete_Type --
3764 ------------------------------------------
3766 function Is_Actual_For_Formal_Incomplete_Type
3767 (T
: Entity_Id
) return Boolean
3769 Gen_Par
: Entity_Id
;
3773 if not Is_Generic_Instance
(Current_Scope
)
3774 or else not Used_As_Generic_Actual
(T
)
3779 Gen_Par
:= Generic_Parent
(Parent
(Current_Scope
));
3784 (Generic_Formal_Declarations
3785 (Unit_Declaration_Node
(Gen_Par
)));
3786 while Present
(F
) loop
3787 if Ekind
(Defining_Identifier
(F
)) = E_Incomplete_Type
then
3795 end Is_Actual_For_Formal_Incomplete_Type
;
3797 -- Start of processing for Check_Premature_Freezing
3800 -- Note that if the type is a (subtype of) a generic actual, the
3801 -- actual will have been frozen by the instantiation.
3804 and then Is_Private_Type
(Typ
)
3805 and then No
(Full_View
(Typ
))
3806 and then not Is_Generic_Type
(Typ
)
3807 and then not Is_Tagged_Type
(Typ
)
3808 and then not Is_Frozen
(Typ
)
3809 and then not Is_Generic_Actual_Type
(Typ
)
3811 Error_Msg_Sloc
:= Sloc
(Subp
);
3813 ("declaration must appear after completion of type &", N
, Typ
);
3815 ("\which is an untagged type in the profile of"
3816 & " primitive operation & declared#", N
, Subp
);
3819 Comp
:= Private_Component
(Typ
);
3821 if not Is_Tagged_Type
(Typ
)
3822 and then Present
(Comp
)
3823 and then not Is_Frozen
(Comp
)
3825 not Is_Actual_For_Formal_Incomplete_Type
(Comp
)
3827 Error_Msg_Sloc
:= Sloc
(Subp
);
3828 Error_Msg_Node_2
:= Subp
;
3829 Error_Msg_Name_1
:= Chars
(Tagged_Type
);
3831 ("declaration must appear after completion of type &",
3834 ("\which is a component of untagged type& in the profile of"
3835 & " primitive & of type % that is frozen by the declaration ",
3839 end Check_Premature_Freezing
;
3845 procedure Export_DT
(Typ
: Entity_Id
; DT
: Entity_Id
; Index
: Nat
:= 0)
3851 Set_Is_Statically_Allocated
(DT
);
3852 Set_Is_True_Constant
(DT
);
3853 Set_Is_Exported
(DT
);
3856 Elmt
:= First_Elmt
(Dispatch_Table_Wrappers
(Typ
));
3857 while Count
/= Index
loop
3862 pragma Assert
(Related_Type
(Node
(Elmt
)) = Typ
);
3865 (Entity
=> Node
(Elmt
),
3866 Has_Suffix
=> True);
3868 Set_Interface_Name
(DT
,
3869 Make_String_Literal
(Loc
,
3870 Strval
=> String_From_Name_Buffer
));
3872 -- Ensure proper Sprint output of this implicit importation
3874 Set_Is_Internal
(DT
);
3878 -----------------------
3879 -- Make_Secondary_DT --
3880 -----------------------
3882 procedure Make_Secondary_DT
3886 Num_Iface_Prims
: Nat
;
3887 Iface_DT_Ptr
: Entity_Id
;
3888 Predef_Prims_Ptr
: Entity_Id
;
3889 Build_Thunks
: Boolean;
3892 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
3893 Exporting_Table
: constant Boolean :=
3894 Building_Static_DT
(Typ
)
3895 and then Suffix_Index
> 0;
3896 Iface_DT
: constant Entity_Id
:= Make_Temporary
(Loc
, 'T');
3897 Predef_Prims
: constant Entity_Id
:= Make_Temporary
(Loc
, 'R');
3898 DT_Constr_List
: List_Id
;
3899 DT_Aggr_List
: List_Id
;
3900 Empty_DT
: Boolean := False;
3901 Nb_Predef_Prims
: Nat
:= 0;
3905 OSD_Aggr_List
: List_Id
;
3908 Prim_Elmt
: Elmt_Id
;
3909 Prim_Ops_Aggr_List
: List_Id
;
3912 -- Handle cases in which we do not generate statically allocated
3915 if not Building_Static_DT
(Typ
) then
3916 Set_Ekind
(Predef_Prims
, E_Variable
);
3917 Set_Ekind
(Iface_DT
, E_Variable
);
3919 -- Statically allocated dispatch tables and related entities are
3923 Set_Ekind
(Predef_Prims
, E_Constant
);
3924 Set_Is_Statically_Allocated
(Predef_Prims
);
3925 Set_Is_True_Constant
(Predef_Prims
);
3927 Set_Ekind
(Iface_DT
, E_Constant
);
3928 Set_Is_Statically_Allocated
(Iface_DT
);
3929 Set_Is_True_Constant
(Iface_DT
);
3932 -- Calculate the number of slots of the dispatch table. If the number
3933 -- of primitives of Typ is 0 we reserve a dummy single entry for its
3934 -- DT because at run time the pointer to this dummy entry will be
3937 if Num_Iface_Prims
= 0 then
3941 Nb_Prim
:= Num_Iface_Prims
;
3946 -- Predef_Prims : Address_Array (1 .. Default_Prim_Ops_Count) :=
3947 -- (predef-prim-op-thunk-1'address,
3948 -- predef-prim-op-thunk-2'address,
3950 -- predef-prim-op-thunk-n'address);
3951 -- for Predef_Prims'Alignment use Address'Alignment
3953 -- Stage 1: Calculate the number of predefined primitives
3955 if not Building_Static_DT
(Typ
) then
3956 Nb_Predef_Prims
:= Max_Predef_Prims
;
3958 Prim_Elmt
:= First_Elmt
(Primitive_Operations
(Typ
));
3959 while Present
(Prim_Elmt
) loop
3960 Prim
:= Node
(Prim_Elmt
);
3962 if Is_Predefined_Dispatching_Operation
(Prim
)
3963 and then not Is_Abstract_Subprogram
(Prim
)
3965 Pos
:= UI_To_Int
(DT_Position
(Prim
));
3967 if Pos
> Nb_Predef_Prims
then
3968 Nb_Predef_Prims
:= Pos
;
3972 Next_Elmt
(Prim_Elmt
);
3976 -- Stage 2: Create the thunks associated with the predefined
3977 -- primitives and save their entity to fill the aggregate.
3980 Prim_Table
: array (Nat
range 1 .. Nb_Predef_Prims
) of Entity_Id
;
3982 Thunk_Id
: Entity_Id
;
3983 Thunk_Code
: Node_Id
;
3986 Prim_Ops_Aggr_List
:= New_List
;
3987 Prim_Table
:= (others => Empty
);
3989 if Building_Static_DT
(Typ
) then
3990 Prim_Elmt
:= First_Elmt
(Primitive_Operations
(Typ
));
3991 while Present
(Prim_Elmt
) loop
3992 Prim
:= Node
(Prim_Elmt
);
3994 if Is_Predefined_Dispatching_Operation
(Prim
)
3995 and then not Is_Abstract_Subprogram
(Prim
)
3996 and then not Is_Eliminated
(Prim
)
3997 and then not Present
(Prim_Table
3998 (UI_To_Int
(DT_Position
(Prim
))))
4000 if not Build_Thunks
then
4001 Prim_Table
(UI_To_Int
(DT_Position
(Prim
))) :=
4005 Expand_Interface_Thunk
4006 (Ultimate_Alias
(Prim
), Thunk_Id
, Thunk_Code
);
4008 if Present
(Thunk_Id
) then
4009 Append_To
(Result
, Thunk_Code
);
4010 Prim_Table
(UI_To_Int
(DT_Position
(Prim
)))
4016 Next_Elmt
(Prim_Elmt
);
4020 for J
in Prim_Table
'Range loop
4021 if Present
(Prim_Table
(J
)) then
4023 Unchecked_Convert_To
(RTE
(RE_Prim_Ptr
),
4024 Make_Attribute_Reference
(Loc
,
4025 Prefix
=> New_Reference_To
(Prim_Table
(J
), Loc
),
4026 Attribute_Name
=> Name_Unrestricted_Access
));
4028 New_Node
:= Make_Null
(Loc
);
4031 Append_To
(Prim_Ops_Aggr_List
, New_Node
);
4035 Make_Aggregate
(Loc
,
4036 Expressions
=> Prim_Ops_Aggr_List
);
4038 -- Remember aggregates initializing dispatch tables
4040 Append_Elmt
(New_Node
, DT_Aggr
);
4043 Make_Subtype_Declaration
(Loc
,
4044 Defining_Identifier
=> Make_Temporary
(Loc
, 'S'),
4045 Subtype_Indication
=>
4046 New_Reference_To
(RTE
(RE_Address_Array
), Loc
));
4048 Append_To
(Result
, Decl
);
4051 Make_Object_Declaration
(Loc
,
4052 Defining_Identifier
=> Predef_Prims
,
4053 Constant_Present
=> Building_Static_DT
(Typ
),
4054 Aliased_Present
=> True,
4055 Object_Definition
=> New_Reference_To
4056 (Defining_Identifier
(Decl
), Loc
),
4057 Expression
=> New_Node
));
4060 Make_Attribute_Definition_Clause
(Loc
,
4061 Name
=> New_Reference_To
(Predef_Prims
, Loc
),
4062 Chars
=> Name_Alignment
,
4064 Make_Attribute_Reference
(Loc
,
4066 New_Reference_To
(RTE
(RE_Integer_Address
), Loc
),
4067 Attribute_Name
=> Name_Alignment
)));
4072 -- OSD : Ada.Tags.Object_Specific_Data (Nb_Prims) :=
4073 -- (OSD_Table => (1 => <value>,
4077 -- Iface_DT : Dispatch_Table (Nb_Prims) :=
4078 -- ([ Signature => <sig-value> ],
4079 -- Tag_Kind => <tag_kind-value>,
4080 -- Predef_Prims => Predef_Prims'Address,
4081 -- Offset_To_Top => 0,
4082 -- OSD => OSD'Address,
4083 -- Prims_Ptr => (prim-op-1'address,
4084 -- prim-op-2'address,
4086 -- prim-op-n'address));
4087 -- for Iface_DT'Alignment use Address'Alignment;
4089 -- Stage 3: Initialize the discriminant and the record components
4091 DT_Constr_List
:= New_List
;
4092 DT_Aggr_List
:= New_List
;
4094 -- Nb_Prim. If the tagged type has no primitives we add a dummy
4095 -- slot whose address will be the tag of this type.
4098 New_Node
:= Make_Integer_Literal
(Loc
, 1);
4100 New_Node
:= Make_Integer_Literal
(Loc
, Nb_Prim
);
4103 Append_To
(DT_Constr_List
, New_Node
);
4104 Append_To
(DT_Aggr_List
, New_Copy
(New_Node
));
4108 if RTE_Record_Component_Available
(RE_Signature
) then
4109 Append_To
(DT_Aggr_List
,
4110 New_Reference_To
(RTE
(RE_Secondary_DT
), Loc
));
4115 if RTE_Record_Component_Available
(RE_Tag_Kind
) then
4116 Append_To
(DT_Aggr_List
, Tagged_Kind
(Typ
));
4121 Append_To
(DT_Aggr_List
,
4122 Make_Attribute_Reference
(Loc
,
4123 Prefix
=> New_Reference_To
(Predef_Prims
, Loc
),
4124 Attribute_Name
=> Name_Address
));
4126 -- Note: The correct value of Offset_To_Top will be set by the init
4129 Append_To
(DT_Aggr_List
, Make_Integer_Literal
(Loc
, 0));
4131 -- Generate the Object Specific Data table required to dispatch calls
4132 -- through synchronized interfaces.
4135 or else Is_Abstract_Type
(Typ
)
4136 or else Is_Controlled
(Typ
)
4137 or else Restriction_Active
(No_Dispatching_Calls
)
4138 or else not Is_Limited_Type
(Typ
)
4139 or else not Has_Interfaces
(Typ
)
4140 or else not Build_Thunks
4141 or else not RTE_Record_Component_Available
(RE_OSD_Table
)
4143 -- No OSD table required
4145 Append_To
(DT_Aggr_List
,
4146 New_Reference_To
(RTE
(RE_Null_Address
), Loc
));
4149 OSD_Aggr_List
:= New_List
;
4152 Prim_Table
: array (Nat
range 1 .. Nb_Prim
) of Entity_Id
;
4154 Prim_Alias
: Entity_Id
;
4155 Prim_Elmt
: Elmt_Id
;
4161 Prim_Table
:= (others => Empty
);
4162 Prim_Alias
:= Empty
;
4164 Prim_Elmt
:= First_Elmt
(Primitive_Operations
(Typ
));
4165 while Present
(Prim_Elmt
) loop
4166 Prim
:= Node
(Prim_Elmt
);
4168 if Present
(Interface_Alias
(Prim
))
4169 and then Find_Dispatching_Type
4170 (Interface_Alias
(Prim
)) = Iface
4172 Prim_Alias
:= Interface_Alias
(Prim
);
4173 E
:= Ultimate_Alias
(Prim
);
4174 Pos
:= UI_To_Int
(DT_Position
(Prim_Alias
));
4176 if Present
(Prim_Table
(Pos
)) then
4177 pragma Assert
(Prim_Table
(Pos
) = E
);
4181 Prim_Table
(Pos
) := E
;
4183 Append_To
(OSD_Aggr_List
,
4184 Make_Component_Association
(Loc
,
4185 Choices
=> New_List
(
4186 Make_Integer_Literal
(Loc
,
4187 DT_Position
(Prim_Alias
))),
4189 Make_Integer_Literal
(Loc
,
4190 DT_Position
(Alias
(Prim
)))));
4196 Next_Elmt
(Prim_Elmt
);
4198 pragma Assert
(Count
= Nb_Prim
);
4201 OSD
:= Make_Temporary
(Loc
, 'I');
4204 Make_Object_Declaration
(Loc
,
4205 Defining_Identifier
=> OSD
,
4206 Object_Definition
=>
4207 Make_Subtype_Indication
(Loc
,
4209 New_Reference_To
(RTE
(RE_Object_Specific_Data
), Loc
),
4211 Make_Index_Or_Discriminant_Constraint
(Loc
,
4212 Constraints
=> New_List
(
4213 Make_Integer_Literal
(Loc
, Nb_Prim
)))),
4216 Make_Aggregate
(Loc
,
4217 Component_Associations
=> New_List
(
4218 Make_Component_Association
(Loc
,
4219 Choices
=> New_List
(
4221 (RTE_Record_Component
(RE_OSD_Num_Prims
), Loc
)),
4223 Make_Integer_Literal
(Loc
, Nb_Prim
)),
4225 Make_Component_Association
(Loc
,
4226 Choices
=> New_List
(
4228 (RTE_Record_Component
(RE_OSD_Table
), Loc
)),
4229 Expression
=> Make_Aggregate
(Loc
,
4230 Component_Associations
=> OSD_Aggr_List
))))));
4233 Make_Attribute_Definition_Clause
(Loc
,
4234 Name
=> New_Reference_To
(OSD
, Loc
),
4235 Chars
=> Name_Alignment
,
4237 Make_Attribute_Reference
(Loc
,
4239 New_Reference_To
(RTE
(RE_Integer_Address
), Loc
),
4240 Attribute_Name
=> Name_Alignment
)));
4242 -- In secondary dispatch tables the Typeinfo component contains
4243 -- the address of the Object Specific Data (see a-tags.ads)
4245 Append_To
(DT_Aggr_List
,
4246 Make_Attribute_Reference
(Loc
,
4247 Prefix
=> New_Reference_To
(OSD
, Loc
),
4248 Attribute_Name
=> Name_Address
));
4251 -- Initialize the table of primitive operations
4253 Prim_Ops_Aggr_List
:= New_List
;
4256 Append_To
(Prim_Ops_Aggr_List
, Make_Null
(Loc
));
4258 elsif Is_Abstract_Type
(Typ
)
4259 or else not Building_Static_DT
(Typ
)
4261 for J
in 1 .. Nb_Prim
loop
4262 Append_To
(Prim_Ops_Aggr_List
, Make_Null
(Loc
));
4267 CPP_Nb_Prims
: constant Nat
:= CPP_Num_Prims
(Typ
);
4270 Prim_Table
: array (Nat
range 1 .. Nb_Prim
) of Entity_Id
;
4271 Thunk_Code
: Node_Id
;
4272 Thunk_Id
: Entity_Id
;
4275 Prim_Table
:= (others => Empty
);
4277 Prim_Elmt
:= First_Elmt
(Primitive_Operations
(Typ
));
4278 while Present
(Prim_Elmt
) loop
4279 Prim
:= Node
(Prim_Elmt
);
4280 E
:= Ultimate_Alias
(Prim
);
4281 Prim_Pos
:= UI_To_Int
(DT_Position
(E
));
4283 -- Do not reference predefined primitives because they are
4284 -- located in a separate dispatch table; skip abstract and
4285 -- eliminated primitives; skip primitives located in the C++
4286 -- part of the dispatch table because their slot is set by
4289 if not Is_Predefined_Dispatching_Operation
(Prim
)
4290 and then Present
(Interface_Alias
(Prim
))
4291 and then not Is_Abstract_Subprogram
(Alias
(Prim
))
4292 and then not Is_Eliminated
(Alias
(Prim
))
4293 and then (not Is_CPP_Class
(Root_Type
(Typ
))
4294 or else Prim_Pos
> CPP_Nb_Prims
)
4295 and then Find_Dispatching_Type
4296 (Interface_Alias
(Prim
)) = Iface
4298 -- Generate the code of the thunk only if the abstract
4299 -- interface type is not an immediate ancestor of
4300 -- Tagged_Type. Otherwise the DT associated with the
4301 -- interface is the primary DT.
4303 and then not Is_Ancestor
(Iface
, Typ
,
4304 Use_Full_View
=> True)
4306 if not Build_Thunks
then
4308 UI_To_Int
(DT_Position
(Interface_Alias
(Prim
)));
4309 Prim_Table
(Prim_Pos
) := Alias
(Prim
);
4312 Expand_Interface_Thunk
(Prim
, Thunk_Id
, Thunk_Code
);
4314 if Present
(Thunk_Id
) then
4316 UI_To_Int
(DT_Position
(Interface_Alias
(Prim
)));
4318 Prim_Table
(Prim_Pos
) := Thunk_Id
;
4319 Append_To
(Result
, Thunk_Code
);
4324 Next_Elmt
(Prim_Elmt
);
4327 for J
in Prim_Table
'Range loop
4328 if Present
(Prim_Table
(J
)) then
4330 Unchecked_Convert_To
(RTE
(RE_Prim_Ptr
),
4331 Make_Attribute_Reference
(Loc
,
4332 Prefix
=> New_Reference_To
(Prim_Table
(J
), Loc
),
4333 Attribute_Name
=> Name_Unrestricted_Access
));
4336 New_Node
:= Make_Null
(Loc
);
4339 Append_To
(Prim_Ops_Aggr_List
, New_Node
);
4345 Make_Aggregate
(Loc
,
4346 Expressions
=> Prim_Ops_Aggr_List
);
4348 Append_To
(DT_Aggr_List
, New_Node
);
4350 -- Remember aggregates initializing dispatch tables
4352 Append_Elmt
(New_Node
, DT_Aggr
);
4354 -- Note: Secondary dispatch tables cannot be declared constant
4355 -- because the component Offset_To_Top is currently initialized
4356 -- by the IP routine.
4359 Make_Object_Declaration
(Loc
,
4360 Defining_Identifier
=> Iface_DT
,
4361 Aliased_Present
=> True,
4362 Constant_Present
=> False,
4364 Object_Definition
=>
4365 Make_Subtype_Indication
(Loc
,
4366 Subtype_Mark
=> New_Reference_To
4367 (RTE
(RE_Dispatch_Table_Wrapper
), Loc
),
4368 Constraint
=> Make_Index_Or_Discriminant_Constraint
(Loc
,
4369 Constraints
=> DT_Constr_List
)),
4372 Make_Aggregate
(Loc
,
4373 Expressions
=> DT_Aggr_List
)));
4376 Make_Attribute_Definition_Clause
(Loc
,
4377 Name
=> New_Reference_To
(Iface_DT
, Loc
),
4378 Chars
=> Name_Alignment
,
4381 Make_Attribute_Reference
(Loc
,
4383 New_Reference_To
(RTE
(RE_Integer_Address
), Loc
),
4384 Attribute_Name
=> Name_Alignment
)));
4386 if Exporting_Table
then
4387 Export_DT
(Typ
, Iface_DT
, Suffix_Index
);
4389 -- Generate code to create the pointer to the dispatch table
4391 -- Iface_DT_Ptr : Tag := Tag!(DT.Prims_Ptr'Address);
4393 -- Note: This declaration is not added here if the table is exported
4394 -- because in such case Make_Tags has already added this declaration.
4398 Make_Object_Declaration
(Loc
,
4399 Defining_Identifier
=> Iface_DT_Ptr
,
4400 Constant_Present
=> True,
4402 Object_Definition
=>
4403 New_Reference_To
(RTE
(RE_Interface_Tag
), Loc
),
4406 Unchecked_Convert_To
(RTE
(RE_Interface_Tag
),
4407 Make_Attribute_Reference
(Loc
,
4409 Make_Selected_Component
(Loc
,
4410 Prefix
=> New_Reference_To
(Iface_DT
, Loc
),
4413 (RTE_Record_Component
(RE_Prims_Ptr
), Loc
)),
4414 Attribute_Name
=> Name_Address
))));
4418 Make_Object_Declaration
(Loc
,
4419 Defining_Identifier
=> Predef_Prims_Ptr
,
4420 Constant_Present
=> True,
4422 Object_Definition
=>
4423 New_Reference_To
(RTE
(RE_Address
), Loc
),
4426 Make_Attribute_Reference
(Loc
,
4428 Make_Selected_Component
(Loc
,
4429 Prefix
=> New_Reference_To
(Iface_DT
, Loc
),
4432 (RTE_Record_Component
(RE_Predef_Prims
), Loc
)),
4433 Attribute_Name
=> Name_Address
)));
4435 -- Remember entities containing dispatch tables
4437 Append_Elmt
(Predef_Prims
, DT_Decl
);
4438 Append_Elmt
(Iface_DT
, DT_Decl
);
4439 end Make_Secondary_DT
;
4443 Elab_Code
: constant List_Id
:= New_List
;
4444 Result
: constant List_Id
:= New_List
;
4445 Tname
: constant Name_Id
:= Chars
(Typ
);
4447 AI_Tag_Elmt
: Elmt_Id
;
4448 AI_Tag_Comp
: Elmt_Id
;
4449 DT_Aggr_List
: List_Id
;
4450 DT_Constr_List
: List_Id
;
4454 Iface_Table_Node
: Node_Id
;
4455 Name_ITable
: Name_Id
;
4456 Nb_Predef_Prims
: Nat
:= 0;
4459 Num_Ifaces
: Nat
:= 0;
4460 Parent_Typ
: Entity_Id
;
4462 Prim_Elmt
: Elmt_Id
;
4463 Prim_Ops_Aggr_List
: List_Id
;
4465 Typ_Comps
: Elist_Id
;
4466 Typ_Ifaces
: Elist_Id
;
4467 TSD_Aggr_List
: List_Id
;
4468 TSD_Tags_List
: List_Id
;
4470 -- The following name entries are used by Make_DT to generate a number
4471 -- of entities related to a tagged type. These entities may be generated
4472 -- in a scope other than that of the tagged type declaration, and if
4473 -- the entities for two tagged types with the same name happen to be
4474 -- generated in the same scope, we have to take care to use different
4475 -- names. This is achieved by means of a unique serial number appended
4476 -- to each generated entity name.
4478 Name_DT
: constant Name_Id
:=
4479 New_External_Name
(Tname
, 'T', Suffix_Index
=> -1);
4480 Name_Exname
: constant Name_Id
:=
4481 New_External_Name
(Tname
, 'E', Suffix_Index
=> -1);
4482 Name_HT_Link
: constant Name_Id
:=
4483 New_External_Name
(Tname
, 'H', Suffix_Index
=> -1);
4484 Name_Predef_Prims
: constant Name_Id
:=
4485 New_External_Name
(Tname
, 'R', Suffix_Index
=> -1);
4486 Name_SSD
: constant Name_Id
:=
4487 New_External_Name
(Tname
, 'S', Suffix_Index
=> -1);
4488 Name_TSD
: constant Name_Id
:=
4489 New_External_Name
(Tname
, 'B', Suffix_Index
=> -1);
4491 -- Entities built with above names
4493 DT
: constant Entity_Id
:=
4494 Make_Defining_Identifier
(Loc
, Name_DT
);
4495 Exname
: constant Entity_Id
:=
4496 Make_Defining_Identifier
(Loc
, Name_Exname
);
4497 HT_Link
: constant Entity_Id
:=
4498 Make_Defining_Identifier
(Loc
, Name_HT_Link
);
4499 Predef_Prims
: constant Entity_Id
:=
4500 Make_Defining_Identifier
(Loc
, Name_Predef_Prims
);
4501 SSD
: constant Entity_Id
:=
4502 Make_Defining_Identifier
(Loc
, Name_SSD
);
4503 TSD
: constant Entity_Id
:=
4504 Make_Defining_Identifier
(Loc
, Name_TSD
);
4506 -- Start of processing for Make_DT
4509 pragma Assert
(Is_Frozen
(Typ
));
4511 -- Handle cases in which there is no need to build the dispatch table
4513 if Has_Dispatch_Table
(Typ
)
4514 or else No
(Access_Disp_Table
(Typ
))
4515 or else Is_CPP_Class
(Typ
)
4516 or else Convention
(Typ
) = Convention_CIL
4517 or else Convention
(Typ
) = Convention_Java
4521 elsif No_Run_Time_Mode
then
4522 Error_Msg_CRT
("tagged types", Typ
);
4525 elsif not RTE_Available
(RE_Tag
) then
4527 Make_Object_Declaration
(Loc
,
4528 Defining_Identifier
=> Node
(First_Elmt
4529 (Access_Disp_Table
(Typ
))),
4530 Object_Definition
=> New_Reference_To
(RTE
(RE_Tag
), Loc
),
4531 Constant_Present
=> True,
4533 Unchecked_Convert_To
(RTE
(RE_Tag
),
4534 New_Reference_To
(RTE
(RE_Null_Address
), Loc
))));
4536 Analyze_List
(Result
, Suppress
=> All_Checks
);
4537 Error_Msg_CRT
("tagged types", Typ
);
4541 -- Ensure that the value of Max_Predef_Prims defined in a-tags is
4542 -- correct. Valid values are 9 under configurable runtime or 15
4543 -- with full runtime.
4545 if RTE_Available
(RE_Interface_Data
) then
4546 if Max_Predef_Prims
/= 15 then
4547 Error_Msg_N
("run-time library configuration error", Typ
);
4551 if Max_Predef_Prims
/= 9 then
4552 Error_Msg_N
("run-time library configuration error", Typ
);
4553 Error_Msg_CRT
("tagged types", Typ
);
4558 -- Initialize Parent_Typ handling private types
4560 Parent_Typ
:= Etype
(Typ
);
4562 if Present
(Full_View
(Parent_Typ
)) then
4563 Parent_Typ
:= Full_View
(Parent_Typ
);
4566 -- Ensure that all the primitives are frozen. This is only required when
4567 -- building static dispatch tables --- the primitives must be frozen to
4568 -- be referenced (otherwise we have problems with the backend). It is
4569 -- not a requirement with nonstatic dispatch tables because in this case
4570 -- we generate now an empty dispatch table; the extra code required to
4571 -- register the primitives in the slots will be generated later --- when
4572 -- each primitive is frozen (see Freeze_Subprogram).
4574 if Building_Static_DT
(Typ
) then
4576 Save
: constant Boolean := Freezing_Library_Level_Tagged_Type
;
4578 Prim_Elmt
: Elmt_Id
;
4582 Freezing_Library_Level_Tagged_Type
:= True;
4584 Prim_Elmt
:= First_Elmt
(Primitive_Operations
(Typ
));
4585 while Present
(Prim_Elmt
) loop
4586 Prim
:= Node
(Prim_Elmt
);
4587 Frnodes
:= Freeze_Entity
(Prim
, Typ
);
4593 F
:= First_Formal
(Prim
);
4594 while Present
(F
) loop
4595 Check_Premature_Freezing
(Prim
, Typ
, Etype
(F
));
4599 Check_Premature_Freezing
(Prim
, Typ
, Etype
(Prim
));
4602 if Present
(Frnodes
) then
4603 Append_List_To
(Result
, Frnodes
);
4606 Next_Elmt
(Prim_Elmt
);
4609 Freezing_Library_Level_Tagged_Type
:= Save
;
4613 -- Ada 2005 (AI-251): Build the secondary dispatch tables
4615 if Has_Interfaces
(Typ
) then
4616 Collect_Interface_Components
(Typ
, Typ_Comps
);
4618 -- Each secondary dispatch table is assigned an unique positive
4619 -- suffix index; such value also corresponds with the location of
4620 -- its entity in the Dispatch_Table_Wrappers list (see Make_Tags).
4622 -- Note: This value must be kept sync with the Suffix_Index values
4623 -- generated by Make_Tags
4627 Next_Elmt
(Next_Elmt
(First_Elmt
(Access_Disp_Table
(Typ
))));
4629 AI_Tag_Comp
:= First_Elmt
(Typ_Comps
);
4630 while Present
(AI_Tag_Comp
) loop
4631 pragma Assert
(Has_Suffix
(Node
(AI_Tag_Elmt
), 'P'));
4633 -- Build the secondary table containing pointers to thunks
4637 Iface
=> Base_Type
(Related_Type
(Node
(AI_Tag_Comp
))),
4638 Suffix_Index
=> Suffix_Index
,
4639 Num_Iface_Prims
=> UI_To_Int
4640 (DT_Entry_Count
(Node
(AI_Tag_Comp
))),
4641 Iface_DT_Ptr
=> Node
(AI_Tag_Elmt
),
4642 Predef_Prims_Ptr
=> Node
(Next_Elmt
(AI_Tag_Elmt
)),
4643 Build_Thunks
=> True,
4646 -- Skip secondary dispatch table referencing thunks to predefined
4649 Next_Elmt
(AI_Tag_Elmt
);
4650 pragma Assert
(Has_Suffix
(Node
(AI_Tag_Elmt
), 'Y'));
4652 -- Secondary dispatch table referencing user-defined primitives
4653 -- covered by this interface.
4655 Next_Elmt
(AI_Tag_Elmt
);
4656 pragma Assert
(Has_Suffix
(Node
(AI_Tag_Elmt
), 'D'));
4658 -- Build the secondary table containing pointers to primitives
4659 -- (used to give support to Generic Dispatching Constructors).
4664 (Related_Type
(Node
(AI_Tag_Comp
))),
4666 Num_Iface_Prims
=> UI_To_Int
4667 (DT_Entry_Count
(Node
(AI_Tag_Comp
))),
4668 Iface_DT_Ptr
=> Node
(AI_Tag_Elmt
),
4669 Predef_Prims_Ptr
=> Node
(Next_Elmt
(AI_Tag_Elmt
)),
4670 Build_Thunks
=> False,
4673 -- Skip secondary dispatch table referencing predefined primitives
4675 Next_Elmt
(AI_Tag_Elmt
);
4676 pragma Assert
(Has_Suffix
(Node
(AI_Tag_Elmt
), 'Z'));
4678 Suffix_Index
:= Suffix_Index
+ 1;
4679 Next_Elmt
(AI_Tag_Elmt
);
4680 Next_Elmt
(AI_Tag_Comp
);
4684 -- Get the _tag entity and number of primitives of its dispatch table
4686 DT_Ptr
:= Node
(First_Elmt
(Access_Disp_Table
(Typ
)));
4687 Nb_Prim
:= UI_To_Int
(DT_Entry_Count
(First_Tag_Component
(Typ
)));
4689 Set_Is_Statically_Allocated
(DT
, Is_Library_Level_Tagged_Type
(Typ
));
4690 Set_Is_Statically_Allocated
(SSD
, Is_Library_Level_Tagged_Type
(Typ
));
4691 Set_Is_Statically_Allocated
(TSD
, Is_Library_Level_Tagged_Type
(Typ
));
4692 Set_Is_Statically_Allocated
(Predef_Prims
,
4693 Is_Library_Level_Tagged_Type
(Typ
));
4695 -- In case of locally defined tagged type we declare the object
4696 -- containing the dispatch table by means of a variable. Its
4697 -- initialization is done later by means of an assignment. This is
4698 -- required to generate its External_Tag.
4700 if not Building_Static_DT
(Typ
) then
4703 -- DT : No_Dispatch_Table_Wrapper;
4704 -- for DT'Alignment use Address'Alignment;
4705 -- DT_Ptr : Tag := !Tag (DT.NDT_Prims_Ptr'Address);
4707 if not Has_DT
(Typ
) then
4709 Make_Object_Declaration
(Loc
,
4710 Defining_Identifier
=> DT
,
4711 Aliased_Present
=> True,
4712 Constant_Present
=> False,
4713 Object_Definition
=>
4715 (RTE
(RE_No_Dispatch_Table_Wrapper
), Loc
)));
4718 Make_Attribute_Definition_Clause
(Loc
,
4719 Name
=> New_Reference_To
(DT
, Loc
),
4720 Chars
=> Name_Alignment
,
4722 Make_Attribute_Reference
(Loc
,
4724 New_Reference_To
(RTE
(RE_Integer_Address
), Loc
),
4725 Attribute_Name
=> Name_Alignment
)));
4728 Make_Object_Declaration
(Loc
,
4729 Defining_Identifier
=> DT_Ptr
,
4730 Object_Definition
=> New_Reference_To
(RTE
(RE_Tag
), Loc
),
4731 Constant_Present
=> True,
4733 Unchecked_Convert_To
(RTE
(RE_Tag
),
4734 Make_Attribute_Reference
(Loc
,
4736 Make_Selected_Component
(Loc
,
4737 Prefix
=> New_Reference_To
(DT
, Loc
),
4740 (RTE_Record_Component
(RE_NDT_Prims_Ptr
), Loc
)),
4741 Attribute_Name
=> Name_Address
))));
4743 Set_Is_Statically_Allocated
(DT_Ptr
,
4744 Is_Library_Level_Tagged_Type
(Typ
));
4746 -- Generate the SCIL node for the previous object declaration
4747 -- because it has a tag initialization.
4749 if Generate_SCIL
then
4751 Make_SCIL_Dispatch_Table_Tag_Init
(Sloc
(Last
(Result
)));
4752 Set_SCIL_Entity
(New_Node
, Typ
);
4753 Set_SCIL_Node
(Last
(Result
), New_Node
);
4757 -- DT : Dispatch_Table_Wrapper (Nb_Prim);
4758 -- for DT'Alignment use Address'Alignment;
4759 -- DT_Ptr : Tag := !Tag (DT.Prims_Ptr'Address);
4762 -- If the tagged type has no primitives we add a dummy slot
4763 -- whose address will be the tag of this type.
4767 New_List
(Make_Integer_Literal
(Loc
, 1));
4770 New_List
(Make_Integer_Literal
(Loc
, Nb_Prim
));
4774 Make_Object_Declaration
(Loc
,
4775 Defining_Identifier
=> DT
,
4776 Aliased_Present
=> True,
4777 Constant_Present
=> False,
4778 Object_Definition
=>
4779 Make_Subtype_Indication
(Loc
,
4781 New_Reference_To
(RTE
(RE_Dispatch_Table_Wrapper
), Loc
),
4782 Constraint
=> Make_Index_Or_Discriminant_Constraint
(Loc
,
4783 Constraints
=> DT_Constr_List
))));
4786 Make_Attribute_Definition_Clause
(Loc
,
4787 Name
=> New_Reference_To
(DT
, Loc
),
4788 Chars
=> Name_Alignment
,
4790 Make_Attribute_Reference
(Loc
,
4792 New_Reference_To
(RTE
(RE_Integer_Address
), Loc
),
4793 Attribute_Name
=> Name_Alignment
)));
4796 Make_Object_Declaration
(Loc
,
4797 Defining_Identifier
=> DT_Ptr
,
4798 Object_Definition
=> New_Reference_To
(RTE
(RE_Tag
), Loc
),
4799 Constant_Present
=> True,
4801 Unchecked_Convert_To
(RTE
(RE_Tag
),
4802 Make_Attribute_Reference
(Loc
,
4804 Make_Selected_Component
(Loc
,
4805 Prefix
=> New_Reference_To
(DT
, Loc
),
4808 (RTE_Record_Component
(RE_Prims_Ptr
), Loc
)),
4809 Attribute_Name
=> Name_Address
))));
4811 Set_Is_Statically_Allocated
(DT_Ptr
,
4812 Is_Library_Level_Tagged_Type
(Typ
));
4814 -- Generate the SCIL node for the previous object declaration
4815 -- because it has a tag initialization.
4817 if Generate_SCIL
then
4819 Make_SCIL_Dispatch_Table_Tag_Init
(Sloc
(Last
(Result
)));
4820 Set_SCIL_Entity
(New_Node
, Typ
);
4821 Set_SCIL_Node
(Last
(Result
), New_Node
);
4825 Make_Object_Declaration
(Loc
,
4826 Defining_Identifier
=>
4827 Node
(Next_Elmt
(First_Elmt
(Access_Disp_Table
(Typ
)))),
4828 Constant_Present
=> True,
4829 Object_Definition
=> New_Reference_To
4830 (RTE
(RE_Address
), Loc
),
4832 Make_Attribute_Reference
(Loc
,
4834 Make_Selected_Component
(Loc
,
4835 Prefix
=> New_Reference_To
(DT
, Loc
),
4838 (RTE_Record_Component
(RE_Predef_Prims
), Loc
)),
4839 Attribute_Name
=> Name_Address
)));
4843 -- Generate: Exname : constant String := full_qualified_name (typ);
4844 -- The type itself may be an anonymous parent type, so use the first
4845 -- subtype to have a user-recognizable name.
4848 Make_Object_Declaration
(Loc
,
4849 Defining_Identifier
=> Exname
,
4850 Constant_Present
=> True,
4851 Object_Definition
=> New_Reference_To
(Standard_String
, Loc
),
4853 Make_String_Literal
(Loc
,
4854 Fully_Qualified_Name_String
(First_Subtype
(Typ
)))));
4856 Set_Is_Statically_Allocated
(Exname
);
4857 Set_Is_True_Constant
(Exname
);
4859 -- Declare the object used by Ada.Tags.Register_Tag
4861 if RTE_Available
(RE_Register_Tag
) then
4863 Make_Object_Declaration
(Loc
,
4864 Defining_Identifier
=> HT_Link
,
4865 Object_Definition
=> New_Reference_To
(RTE
(RE_Tag
), Loc
)));
4868 -- Generate code to create the storage for the type specific data object
4869 -- with enough space to store the tags of the ancestors plus the tags
4870 -- of all the implemented interfaces (as described in a-tags.adb).
4872 -- TSD : Type_Specific_Data (I_Depth) :=
4873 -- (Idepth => I_Depth,
4874 -- Access_Level => Type_Access_Level (Typ),
4875 -- Alignment => Typ'Alignment,
4876 -- Expanded_Name => Cstring_Ptr!(Exname'Address))
4877 -- External_Tag => Cstring_Ptr!(Exname'Address))
4878 -- HT_Link => HT_Link'Address,
4879 -- Transportable => <<boolean-value>>,
4880 -- Type_Is_Abstract => <<boolean-value>>,
4881 -- Needs_Finalization => <<boolean-value>>,
4882 -- [ Size_Func => Size_Prim'Access, ]
4883 -- [ Interfaces_Table => <<access-value>>, ]
4884 -- [ SSD => SSD_Table'Address ]
4885 -- Tags_Table => (0 => null,
4888 -- for TSD'Alignment use Address'Alignment
4890 TSD_Aggr_List
:= New_List
;
4892 -- Idepth: Count ancestors to compute the inheritance depth. For private
4893 -- extensions, always go to the full view in order to compute the real
4894 -- inheritance depth.
4897 Current_Typ
: Entity_Id
;
4898 Parent_Typ
: Entity_Id
;
4904 Parent_Typ
:= Etype
(Current_Typ
);
4906 if Is_Private_Type
(Parent_Typ
) then
4907 Parent_Typ
:= Full_View
(Base_Type
(Parent_Typ
));
4910 exit when Parent_Typ
= Current_Typ
;
4912 I_Depth
:= I_Depth
+ 1;
4913 Current_Typ
:= Parent_Typ
;
4917 Append_To
(TSD_Aggr_List
,
4918 Make_Integer_Literal
(Loc
, I_Depth
));
4922 Append_To
(TSD_Aggr_List
,
4923 Make_Integer_Literal
(Loc
, Type_Access_Level
(Typ
)));
4927 -- For CPP types we cannot rely on the value of 'Alignment provided
4928 -- by the backend to initialize this TSD field.
4930 if Convention
(Typ
) = Convention_CPP
4931 or else Is_CPP_Class
(Root_Type
(Typ
))
4933 Append_To
(TSD_Aggr_List
,
4934 Make_Integer_Literal
(Loc
, 0));
4936 Append_To
(TSD_Aggr_List
,
4937 Make_Attribute_Reference
(Loc
,
4938 Prefix
=> New_Reference_To
(Typ
, Loc
),
4939 Attribute_Name
=> Name_Alignment
));
4944 Append_To
(TSD_Aggr_List
,
4945 Unchecked_Convert_To
(RTE
(RE_Cstring_Ptr
),
4946 Make_Attribute_Reference
(Loc
,
4947 Prefix
=> New_Reference_To
(Exname
, Loc
),
4948 Attribute_Name
=> Name_Address
)));
4950 -- External_Tag of a local tagged type
4952 -- <typ>A : constant String :=
4953 -- "Internal tag at 16#tag-addr#: <full-name-of-typ>";
4955 -- The reason we generate this strange name is that we do not want to
4956 -- enter local tagged types in the global hash table used to compute
4957 -- the Internal_Tag attribute for two reasons:
4959 -- 1. It is hard to avoid a tasking race condition for entering the
4960 -- entry into the hash table.
4962 -- 2. It would cause a storage leak, unless we rig up considerable
4963 -- mechanism to remove the entry from the hash table on exit.
4965 -- So what we do is to generate the above external tag name, where the
4966 -- hex address is the address of the local dispatch table (i.e. exactly
4967 -- the value we want if Internal_Tag is computed from this string).
4969 -- Of course this value will only be valid if the tagged type is still
4970 -- in scope, but it clearly must be erroneous to compute the internal
4971 -- tag of a tagged type that is out of scope!
4973 -- We don't do this processing if an explicit external tag has been
4974 -- specified. That's an odd case for which we have already issued a
4975 -- warning, where we will not be able to compute the internal tag.
4977 if not Is_Library_Level_Entity
(Typ
)
4978 and then not Has_External_Tag_Rep_Clause
(Typ
)
4981 Exname
: constant Entity_Id
:=
4982 Make_Defining_Identifier
(Loc
,
4983 New_External_Name
(Tname
, 'A'));
4985 Full_Name
: constant String_Id
:=
4986 Fully_Qualified_Name_String
(First_Subtype
(Typ
));
4987 Str1_Id
: String_Id
;
4988 Str2_Id
: String_Id
;
4992 -- Str1 = "Internal tag at 16#";
4995 Store_String_Chars
("Internal tag at 16#");
4996 Str1_Id
:= End_String
;
4999 -- Str2 = "#: <type-full-name>";
5002 Store_String_Chars
("#: ");
5003 Store_String_Chars
(Full_Name
);
5004 Str2_Id
:= End_String
;
5007 -- Exname : constant String :=
5008 -- Str1 & Address_Image (Tag) & Str2;
5010 if RTE_Available
(RE_Address_Image
) then
5012 Make_Object_Declaration
(Loc
,
5013 Defining_Identifier
=> Exname
,
5014 Constant_Present
=> True,
5015 Object_Definition
=> New_Reference_To
5016 (Standard_String
, Loc
),
5018 Make_Op_Concat
(Loc
,
5020 Make_String_Literal
(Loc
, Str1_Id
),
5022 Make_Op_Concat
(Loc
,
5024 Make_Function_Call
(Loc
,
5027 (RTE
(RE_Address_Image
), Loc
),
5028 Parameter_Associations
=> New_List
(
5029 Unchecked_Convert_To
(RTE
(RE_Address
),
5030 New_Reference_To
(DT_Ptr
, Loc
)))),
5032 Make_String_Literal
(Loc
, Str2_Id
)))));
5036 Make_Object_Declaration
(Loc
,
5037 Defining_Identifier
=> Exname
,
5038 Constant_Present
=> True,
5039 Object_Definition
=> New_Reference_To
5040 (Standard_String
, Loc
),
5042 Make_Op_Concat
(Loc
,
5044 Make_String_Literal
(Loc
, Str1_Id
),
5046 Make_String_Literal
(Loc
, Str2_Id
))));
5050 Unchecked_Convert_To
(RTE
(RE_Cstring_Ptr
),
5051 Make_Attribute_Reference
(Loc
,
5052 Prefix
=> New_Reference_To
(Exname
, Loc
),
5053 Attribute_Name
=> Name_Address
));
5056 -- External tag of a library-level tagged type: Check for a definition
5057 -- of External_Tag. The clause is considered only if it applies to this
5058 -- specific tagged type, as opposed to one of its ancestors.
5059 -- If the type is an unconstrained type extension, we are building the
5060 -- dispatch table of its anonymous base type, so the external tag, if
5061 -- any was specified, must be retrieved from the first subtype. Go to
5062 -- the full view in case the clause is in the private part.
5066 Def
: constant Node_Id
:= Get_Attribute_Definition_Clause
5067 (Underlying_Type
(First_Subtype
(Typ
)),
5068 Attribute_External_Tag
);
5070 Old_Val
: String_Id
;
5071 New_Val
: String_Id
;
5075 if not Present
(Def
)
5076 or else Entity
(Name
(Def
)) /= First_Subtype
(Typ
)
5079 Unchecked_Convert_To
(RTE
(RE_Cstring_Ptr
),
5080 Make_Attribute_Reference
(Loc
,
5081 Prefix
=> New_Reference_To
(Exname
, Loc
),
5082 Attribute_Name
=> Name_Address
));
5084 Old_Val
:= Strval
(Expr_Value_S
(Expression
(Def
)));
5086 -- For the rep clause "for <typ>'external_tag use y" generate:
5088 -- <typ>A : constant string := y;
5090 -- <typ>A'Address is used to set the External_Tag component
5093 -- Create a new nul terminated string if it is not already
5095 if String_Length
(Old_Val
) > 0
5097 Get_String_Char
(Old_Val
, String_Length
(Old_Val
)) = 0
5101 Start_String
(Old_Val
);
5102 Store_String_Char
(Get_Char_Code
(ASCII
.NUL
));
5103 New_Val
:= End_String
;
5106 E
:= Make_Defining_Identifier
(Loc
,
5107 New_External_Name
(Chars
(Typ
), 'A'));
5110 Make_Object_Declaration
(Loc
,
5111 Defining_Identifier
=> E
,
5112 Constant_Present
=> True,
5113 Object_Definition
=>
5114 New_Reference_To
(Standard_String
, Loc
),
5116 Make_String_Literal
(Loc
, New_Val
)));
5119 Unchecked_Convert_To
(RTE
(RE_Cstring_Ptr
),
5120 Make_Attribute_Reference
(Loc
,
5121 Prefix
=> New_Reference_To
(E
, Loc
),
5122 Attribute_Name
=> Name_Address
));
5127 Append_To
(TSD_Aggr_List
, New_Node
);
5131 if RTE_Available
(RE_Register_Tag
) then
5132 Append_To
(TSD_Aggr_List
,
5133 Unchecked_Convert_To
(RTE
(RE_Tag_Ptr
),
5134 Make_Attribute_Reference
(Loc
,
5135 Prefix
=> New_Reference_To
(HT_Link
, Loc
),
5136 Attribute_Name
=> Name_Address
)));
5138 Append_To
(TSD_Aggr_List
,
5139 Unchecked_Convert_To
(RTE
(RE_Tag_Ptr
),
5140 New_Reference_To
(RTE
(RE_Null_Address
), Loc
)));
5143 -- Transportable: Set for types that can be used in remote calls
5144 -- with respect to E.4(18) legality rules.
5147 Transportable
: Entity_Id
;
5153 or else Is_Shared_Passive
(Typ
)
5155 ((Is_Remote_Types
(Typ
)
5156 or else Is_Remote_Call_Interface
(Typ
))
5157 and then Original_View_In_Visible_Part
(Typ
))
5158 or else not Comes_From_Source
(Typ
));
5160 Append_To
(TSD_Aggr_List
,
5161 New_Occurrence_Of
(Transportable
, Loc
));
5164 -- Type_Is_Abstract (Ada 2012: AI05-0173). This functionality is
5165 -- not available in the HIE runtime.
5167 if RTE_Record_Component_Available
(RE_Type_Is_Abstract
) then
5169 Type_Is_Abstract
: Entity_Id
;
5173 Boolean_Literals
(Is_Abstract_Type
(Typ
));
5175 Append_To
(TSD_Aggr_List
,
5176 New_Occurrence_Of
(Type_Is_Abstract
, Loc
));
5180 -- Needs_Finalization: Set if the type is controlled or has controlled
5184 Needs_Fin
: Entity_Id
;
5187 Needs_Fin
:= Boolean_Literals
(Needs_Finalization
(Typ
));
5188 Append_To
(TSD_Aggr_List
, New_Occurrence_Of
(Needs_Fin
, Loc
));
5193 if RTE_Record_Component_Available
(RE_Size_Func
) then
5195 -- Initialize this field to Null_Address if we are not building
5196 -- static dispatch tables static or if the size function is not
5197 -- available. In the former case we cannot initialize this field
5198 -- until the function is frozen and registered in the dispatch
5199 -- table (see Register_Primitive).
5201 if not Building_Static_DT
(Typ
) or else not Has_DT
(Typ
) then
5202 Append_To
(TSD_Aggr_List
,
5203 Unchecked_Convert_To
(RTE
(RE_Size_Ptr
),
5204 New_Reference_To
(RTE
(RE_Null_Address
), Loc
)));
5208 Prim_Elmt
: Elmt_Id
;
5210 Size_Comp
: Node_Id
;
5213 Prim_Elmt
:= First_Elmt
(Primitive_Operations
(Typ
));
5214 while Present
(Prim_Elmt
) loop
5215 Prim
:= Node
(Prim_Elmt
);
5217 if Chars
(Prim
) = Name_uSize
then
5218 Prim
:= Ultimate_Alias
(Prim
);
5220 if Is_Abstract_Subprogram
(Prim
) then
5222 Unchecked_Convert_To
(RTE
(RE_Size_Ptr
),
5223 New_Reference_To
(RTE
(RE_Null_Address
), Loc
));
5226 Unchecked_Convert_To
(RTE
(RE_Size_Ptr
),
5227 Make_Attribute_Reference
(Loc
,
5228 Prefix
=> New_Reference_To
(Prim
, Loc
),
5229 Attribute_Name
=> Name_Unrestricted_Access
));
5235 Next_Elmt
(Prim_Elmt
);
5238 pragma Assert
(Present
(Size_Comp
));
5239 Append_To
(TSD_Aggr_List
, Size_Comp
);
5244 -- Interfaces_Table (required for AI-405)
5246 if RTE_Record_Component_Available
(RE_Interfaces_Table
) then
5248 -- Count the number of interface types implemented by Typ
5250 Collect_Interfaces
(Typ
, Typ_Ifaces
);
5252 AI
:= First_Elmt
(Typ_Ifaces
);
5253 while Present
(AI
) loop
5254 Num_Ifaces
:= Num_Ifaces
+ 1;
5258 if Num_Ifaces
= 0 then
5259 Iface_Table_Node
:= Make_Null
(Loc
);
5261 -- Generate the Interface_Table object
5265 TSD_Ifaces_List
: constant List_Id
:= New_List
;
5267 Sec_DT_Tag
: Node_Id
;
5270 AI
:= First_Elmt
(Typ_Ifaces
);
5271 while Present
(AI
) loop
5272 if Is_Ancestor
(Node
(AI
), Typ
, Use_Full_View
=> True) then
5274 New_Reference_To
(DT_Ptr
, Loc
);
5278 (Next_Elmt
(First_Elmt
(Access_Disp_Table
(Typ
))));
5279 pragma Assert
(Has_Thunks
(Node
(Elmt
)));
5281 while Is_Tag
(Node
(Elmt
))
5283 Is_Ancestor
(Node
(AI
), Related_Type
(Node
(Elmt
)),
5284 Use_Full_View
=> True)
5286 pragma Assert
(Has_Thunks
(Node
(Elmt
)));
5288 pragma Assert
(Has_Thunks
(Node
(Elmt
)));
5290 pragma Assert
(not Has_Thunks
(Node
(Elmt
)));
5292 pragma Assert
(not Has_Thunks
(Node
(Elmt
)));
5296 pragma Assert
(Ekind
(Node
(Elmt
)) = E_Constant
5298 Has_Thunks
(Node
(Next_Elmt
(Next_Elmt
(Elmt
)))));
5300 New_Reference_To
(Node
(Next_Elmt
(Next_Elmt
(Elmt
))),
5304 Append_To
(TSD_Ifaces_List
,
5305 Make_Aggregate
(Loc
,
5306 Expressions
=> New_List
(
5310 Unchecked_Convert_To
(RTE
(RE_Tag
),
5312 (Node
(First_Elmt
(Access_Disp_Table
(Node
(AI
)))),
5315 -- Static_Offset_To_Top
5317 New_Reference_To
(Standard_True
, Loc
),
5319 -- Offset_To_Top_Value
5321 Make_Integer_Literal
(Loc
, 0),
5323 -- Offset_To_Top_Func
5329 Unchecked_Convert_To
(RTE
(RE_Tag
), Sec_DT_Tag
)
5336 Name_ITable
:= New_External_Name
(Tname
, 'I');
5337 ITable
:= Make_Defining_Identifier
(Loc
, Name_ITable
);
5338 Set_Is_Statically_Allocated
(ITable
,
5339 Is_Library_Level_Tagged_Type
(Typ
));
5341 -- The table of interfaces is not constant; its slots are
5342 -- filled at run time by the IP routine using attribute
5343 -- 'Position to know the location of the tag components
5344 -- (and this attribute cannot be safely used before the
5345 -- object is initialized).
5348 Make_Object_Declaration
(Loc
,
5349 Defining_Identifier
=> ITable
,
5350 Aliased_Present
=> True,
5351 Constant_Present
=> False,
5352 Object_Definition
=>
5353 Make_Subtype_Indication
(Loc
,
5355 New_Reference_To
(RTE
(RE_Interface_Data
), Loc
),
5356 Constraint
=> Make_Index_Or_Discriminant_Constraint
5358 Constraints
=> New_List
(
5359 Make_Integer_Literal
(Loc
, Num_Ifaces
)))),
5361 Expression
=> Make_Aggregate
(Loc
,
5362 Expressions
=> New_List
(
5363 Make_Integer_Literal
(Loc
, Num_Ifaces
),
5364 Make_Aggregate
(Loc
,
5365 Expressions
=> TSD_Ifaces_List
)))));
5368 Make_Attribute_Definition_Clause
(Loc
,
5369 Name
=> New_Reference_To
(ITable
, Loc
),
5370 Chars
=> Name_Alignment
,
5372 Make_Attribute_Reference
(Loc
,
5374 New_Reference_To
(RTE
(RE_Integer_Address
), Loc
),
5375 Attribute_Name
=> Name_Alignment
)));
5378 Make_Attribute_Reference
(Loc
,
5379 Prefix
=> New_Reference_To
(ITable
, Loc
),
5380 Attribute_Name
=> Name_Unchecked_Access
);
5384 Append_To
(TSD_Aggr_List
, Iface_Table_Node
);
5387 -- Generate the Select Specific Data table for synchronized types that
5388 -- implement synchronized interfaces. The size of the table is
5389 -- constrained by the number of non-predefined primitive operations.
5391 if RTE_Record_Component_Available
(RE_SSD
) then
5392 if Ada_Version
>= Ada_2005
5393 and then Has_DT
(Typ
)
5394 and then Is_Concurrent_Record_Type
(Typ
)
5395 and then Has_Interfaces
(Typ
)
5396 and then Nb_Prim
> 0
5397 and then not Is_Abstract_Type
(Typ
)
5398 and then not Is_Controlled
(Typ
)
5399 and then not Restriction_Active
(No_Dispatching_Calls
)
5400 and then not Restriction_Active
(No_Select_Statements
)
5403 Make_Object_Declaration
(Loc
,
5404 Defining_Identifier
=> SSD
,
5405 Aliased_Present
=> True,
5406 Object_Definition
=>
5407 Make_Subtype_Indication
(Loc
,
5408 Subtype_Mark
=> New_Reference_To
(
5409 RTE
(RE_Select_Specific_Data
), Loc
),
5411 Make_Index_Or_Discriminant_Constraint
(Loc
,
5412 Constraints
=> New_List
(
5413 Make_Integer_Literal
(Loc
, Nb_Prim
))))));
5416 Make_Attribute_Definition_Clause
(Loc
,
5417 Name
=> New_Reference_To
(SSD
, Loc
),
5418 Chars
=> Name_Alignment
,
5420 Make_Attribute_Reference
(Loc
,
5422 New_Reference_To
(RTE
(RE_Integer_Address
), Loc
),
5423 Attribute_Name
=> Name_Alignment
)));
5425 -- This table is initialized by Make_Select_Specific_Data_Table,
5426 -- which calls Set_Entry_Index and Set_Prim_Op_Kind.
5428 Append_To
(TSD_Aggr_List
,
5429 Make_Attribute_Reference
(Loc
,
5430 Prefix
=> New_Reference_To
(SSD
, Loc
),
5431 Attribute_Name
=> Name_Unchecked_Access
));
5433 Append_To
(TSD_Aggr_List
, Make_Null
(Loc
));
5437 -- Initialize the table of ancestor tags. In case of interface types
5438 -- this table is not needed.
5440 TSD_Tags_List
:= New_List
;
5442 -- If we are not statically allocating the dispatch table then we must
5443 -- fill position 0 with null because we still have not generated the
5446 if not Building_Static_DT
(Typ
)
5447 or else Is_Interface
(Typ
)
5449 Append_To
(TSD_Tags_List
,
5450 Unchecked_Convert_To
(RTE
(RE_Tag
),
5451 New_Reference_To
(RTE
(RE_Null_Address
), Loc
)));
5453 -- Otherwise we can safely reference the tag
5456 Append_To
(TSD_Tags_List
,
5457 New_Reference_To
(DT_Ptr
, Loc
));
5460 -- Fill the rest of the table with the tags of the ancestors
5463 Current_Typ
: Entity_Id
;
5464 Parent_Typ
: Entity_Id
;
5472 Parent_Typ
:= Etype
(Current_Typ
);
5474 if Is_Private_Type
(Parent_Typ
) then
5475 Parent_Typ
:= Full_View
(Base_Type
(Parent_Typ
));
5478 exit when Parent_Typ
= Current_Typ
;
5480 if Is_CPP_Class
(Parent_Typ
) then
5482 -- The tags defined in the C++ side will be inherited when
5483 -- the object is constructed (Exp_Ch3.Build_Init_Procedure)
5485 Append_To
(TSD_Tags_List
,
5486 Unchecked_Convert_To
(RTE
(RE_Tag
),
5487 New_Reference_To
(RTE
(RE_Null_Address
), Loc
)));
5489 Append_To
(TSD_Tags_List
,
5491 (Node
(First_Elmt
(Access_Disp_Table
(Parent_Typ
))),
5496 Current_Typ
:= Parent_Typ
;
5499 pragma Assert
(Pos
= I_Depth
+ 1);
5502 Append_To
(TSD_Aggr_List
,
5503 Make_Aggregate
(Loc
,
5504 Expressions
=> TSD_Tags_List
));
5506 -- Build the TSD object
5509 Make_Object_Declaration
(Loc
,
5510 Defining_Identifier
=> TSD
,
5511 Aliased_Present
=> True,
5512 Constant_Present
=> Building_Static_DT
(Typ
),
5513 Object_Definition
=>
5514 Make_Subtype_Indication
(Loc
,
5515 Subtype_Mark
=> New_Reference_To
(
5516 RTE
(RE_Type_Specific_Data
), Loc
),
5518 Make_Index_Or_Discriminant_Constraint
(Loc
,
5519 Constraints
=> New_List
(
5520 Make_Integer_Literal
(Loc
, I_Depth
)))),
5522 Expression
=> Make_Aggregate
(Loc
,
5523 Expressions
=> TSD_Aggr_List
)));
5525 Set_Is_True_Constant
(TSD
, Building_Static_DT
(Typ
));
5528 Make_Attribute_Definition_Clause
(Loc
,
5529 Name
=> New_Reference_To
(TSD
, Loc
),
5530 Chars
=> Name_Alignment
,
5532 Make_Attribute_Reference
(Loc
,
5533 Prefix
=> New_Reference_To
(RTE
(RE_Integer_Address
), Loc
),
5534 Attribute_Name
=> Name_Alignment
)));
5536 -- Initialize or declare the dispatch table object
5538 if not Has_DT
(Typ
) then
5539 DT_Constr_List
:= New_List
;
5540 DT_Aggr_List
:= New_List
;
5545 Make_Attribute_Reference
(Loc
,
5546 Prefix
=> New_Reference_To
(TSD
, Loc
),
5547 Attribute_Name
=> Name_Address
);
5549 Append_To
(DT_Constr_List
, New_Node
);
5550 Append_To
(DT_Aggr_List
, New_Copy
(New_Node
));
5551 Append_To
(DT_Aggr_List
, Make_Integer_Literal
(Loc
, 0));
5553 -- In case of locally defined tagged types we have already declared
5554 -- and uninitialized object for the dispatch table, which is now
5555 -- initialized by means of the following assignment:
5557 -- DT := (TSD'Address, 0);
5559 if not Building_Static_DT
(Typ
) then
5561 Make_Assignment_Statement
(Loc
,
5562 Name
=> New_Reference_To
(DT
, Loc
),
5563 Expression
=> Make_Aggregate
(Loc
,
5564 Expressions
=> DT_Aggr_List
)));
5566 -- In case of library level tagged types we declare and export now
5567 -- the constant object containing the dummy dispatch table. There
5568 -- is no need to declare the tag here because it has been previously
5569 -- declared by Make_Tags
5571 -- DT : aliased constant No_Dispatch_Table :=
5572 -- (NDT_TSD => TSD'Address;
5573 -- NDT_Prims_Ptr => 0);
5574 -- for DT'Alignment use Address'Alignment;
5578 Make_Object_Declaration
(Loc
,
5579 Defining_Identifier
=> DT
,
5580 Aliased_Present
=> True,
5581 Constant_Present
=> True,
5582 Object_Definition
=>
5583 New_Reference_To
(RTE
(RE_No_Dispatch_Table_Wrapper
), Loc
),
5584 Expression
=> Make_Aggregate
(Loc
,
5585 Expressions
=> DT_Aggr_List
)));
5588 Make_Attribute_Definition_Clause
(Loc
,
5589 Name
=> New_Reference_To
(DT
, Loc
),
5590 Chars
=> Name_Alignment
,
5592 Make_Attribute_Reference
(Loc
,
5594 New_Reference_To
(RTE
(RE_Integer_Address
), Loc
),
5595 Attribute_Name
=> Name_Alignment
)));
5597 Export_DT
(Typ
, DT
);
5600 -- Common case: Typ has a dispatch table
5604 -- Predef_Prims : Address_Array (1 .. Default_Prim_Ops_Count) :=
5605 -- (predef-prim-op-1'address,
5606 -- predef-prim-op-2'address,
5608 -- predef-prim-op-n'address);
5609 -- for Predef_Prims'Alignment use Address'Alignment
5611 -- DT : Dispatch_Table (Nb_Prims) :=
5612 -- (Signature => <sig-value>,
5613 -- Tag_Kind => <tag_kind-value>,
5614 -- Predef_Prims => Predef_Prims'First'Address,
5615 -- Offset_To_Top => 0,
5616 -- TSD => TSD'Address;
5617 -- Prims_Ptr => (prim-op-1'address,
5618 -- prim-op-2'address,
5620 -- prim-op-n'address));
5621 -- for DT'Alignment use Address'Alignment
5628 if not Building_Static_DT
(Typ
) then
5629 Nb_Predef_Prims
:= Max_Predef_Prims
;
5632 Prim_Elmt
:= First_Elmt
(Primitive_Operations
(Typ
));
5633 while Present
(Prim_Elmt
) loop
5634 Prim
:= Node
(Prim_Elmt
);
5636 if Is_Predefined_Dispatching_Operation
(Prim
)
5637 and then not Is_Abstract_Subprogram
(Prim
)
5639 Pos
:= UI_To_Int
(DT_Position
(Prim
));
5641 if Pos
> Nb_Predef_Prims
then
5642 Nb_Predef_Prims
:= Pos
;
5646 Next_Elmt
(Prim_Elmt
);
5652 (Nat
range 1 .. Nb_Predef_Prims
) of Entity_Id
;
5657 Prim_Ops_Aggr_List
:= New_List
;
5659 Prim_Table
:= (others => Empty
);
5661 if Building_Static_DT
(Typ
) then
5662 Prim_Elmt
:= First_Elmt
(Primitive_Operations
(Typ
));
5663 while Present
(Prim_Elmt
) loop
5664 Prim
:= Node
(Prim_Elmt
);
5666 if Is_Predefined_Dispatching_Operation
(Prim
)
5667 and then not Is_Abstract_Subprogram
(Prim
)
5668 and then not Is_Eliminated
(Prim
)
5669 and then not Present
(Prim_Table
5670 (UI_To_Int
(DT_Position
(Prim
))))
5672 E
:= Ultimate_Alias
(Prim
);
5673 pragma Assert
(not Is_Abstract_Subprogram
(E
));
5674 Prim_Table
(UI_To_Int
(DT_Position
(Prim
))) := E
;
5677 Next_Elmt
(Prim_Elmt
);
5681 for J
in Prim_Table
'Range loop
5682 if Present
(Prim_Table
(J
)) then
5684 Unchecked_Convert_To
(RTE
(RE_Prim_Ptr
),
5685 Make_Attribute_Reference
(Loc
,
5686 Prefix
=> New_Reference_To
(Prim_Table
(J
), Loc
),
5687 Attribute_Name
=> Name_Unrestricted_Access
));
5689 New_Node
:= Make_Null
(Loc
);
5692 Append_To
(Prim_Ops_Aggr_List
, New_Node
);
5696 Make_Aggregate
(Loc
,
5697 Expressions
=> Prim_Ops_Aggr_List
);
5700 Make_Subtype_Declaration
(Loc
,
5701 Defining_Identifier
=> Make_Temporary
(Loc
, 'S'),
5702 Subtype_Indication
=>
5703 New_Reference_To
(RTE
(RE_Address_Array
), Loc
));
5705 Append_To
(Result
, Decl
);
5708 Make_Object_Declaration
(Loc
,
5709 Defining_Identifier
=> Predef_Prims
,
5710 Aliased_Present
=> True,
5711 Constant_Present
=> Building_Static_DT
(Typ
),
5712 Object_Definition
=> New_Reference_To
5713 (Defining_Identifier
(Decl
), Loc
),
5714 Expression
=> New_Node
));
5716 -- Remember aggregates initializing dispatch tables
5718 Append_Elmt
(New_Node
, DT_Aggr
);
5721 Make_Attribute_Definition_Clause
(Loc
,
5722 Name
=> New_Reference_To
(Predef_Prims
, Loc
),
5723 Chars
=> Name_Alignment
,
5725 Make_Attribute_Reference
(Loc
,
5727 New_Reference_To
(RTE
(RE_Integer_Address
), Loc
),
5728 Attribute_Name
=> Name_Alignment
)));
5732 -- Stage 1: Initialize the discriminant and the record components
5734 DT_Constr_List
:= New_List
;
5735 DT_Aggr_List
:= New_List
;
5737 -- Num_Prims. If the tagged type has no primitives we add a dummy
5738 -- slot whose address will be the tag of this type.
5741 New_Node
:= Make_Integer_Literal
(Loc
, 1);
5743 New_Node
:= Make_Integer_Literal
(Loc
, Nb_Prim
);
5746 Append_To
(DT_Constr_List
, New_Node
);
5747 Append_To
(DT_Aggr_List
, New_Copy
(New_Node
));
5751 if RTE_Record_Component_Available
(RE_Signature
) then
5752 Append_To
(DT_Aggr_List
,
5753 New_Reference_To
(RTE
(RE_Primary_DT
), Loc
));
5758 if RTE_Record_Component_Available
(RE_Tag_Kind
) then
5759 Append_To
(DT_Aggr_List
, Tagged_Kind
(Typ
));
5764 Append_To
(DT_Aggr_List
,
5765 Make_Attribute_Reference
(Loc
,
5766 Prefix
=> New_Reference_To
(Predef_Prims
, Loc
),
5767 Attribute_Name
=> Name_Address
));
5771 Append_To
(DT_Aggr_List
, Make_Integer_Literal
(Loc
, 0));
5775 Append_To
(DT_Aggr_List
,
5776 Make_Attribute_Reference
(Loc
,
5777 Prefix
=> New_Reference_To
(TSD
, Loc
),
5778 Attribute_Name
=> Name_Address
));
5780 -- Stage 2: Initialize the table of user-defined primitive operations
5782 Prim_Ops_Aggr_List
:= New_List
;
5785 Append_To
(Prim_Ops_Aggr_List
, Make_Null
(Loc
));
5787 elsif not Building_Static_DT
(Typ
) then
5788 for J
in 1 .. Nb_Prim
loop
5789 Append_To
(Prim_Ops_Aggr_List
, Make_Null
(Loc
));
5794 CPP_Nb_Prims
: constant Nat
:= CPP_Num_Prims
(Typ
);
5797 Prim_Elmt
: Elmt_Id
;
5799 Prim_Table
: array (Nat
range 1 .. Nb_Prim
) of Entity_Id
;
5802 Prim_Table
:= (others => Empty
);
5804 Prim_Elmt
:= First_Elmt
(Primitive_Operations
(Typ
));
5805 while Present
(Prim_Elmt
) loop
5806 Prim
:= Node
(Prim_Elmt
);
5808 -- Retrieve the ultimate alias of the primitive for proper
5809 -- handling of renamings and eliminated primitives.
5811 E
:= Ultimate_Alias
(Prim
);
5812 Prim_Pos
:= UI_To_Int
(DT_Position
(E
));
5814 -- Do not reference predefined primitives because they are
5815 -- located in a separate dispatch table; skip entities with
5816 -- attribute Interface_Alias because they are only required
5817 -- to build secondary dispatch tables; skip abstract and
5818 -- eliminated primitives; for derivations of CPP types skip
5819 -- primitives located in the C++ part of the dispatch table
5820 -- because their slot is initialized by the IC routine.
5822 if not Is_Predefined_Dispatching_Operation
(Prim
)
5823 and then not Is_Predefined_Dispatching_Operation
(E
)
5824 and then not Present
(Interface_Alias
(Prim
))
5825 and then not Is_Abstract_Subprogram
(E
)
5826 and then not Is_Eliminated
(E
)
5827 and then (not Is_CPP_Class
(Root_Type
(Typ
))
5828 or else Prim_Pos
> CPP_Nb_Prims
)
5831 (UI_To_Int
(DT_Position
(Prim
)) <= Nb_Prim
);
5833 Prim_Table
(UI_To_Int
(DT_Position
(Prim
))) := E
;
5836 Next_Elmt
(Prim_Elmt
);
5839 for J
in Prim_Table
'Range loop
5840 if Present
(Prim_Table
(J
)) then
5842 Unchecked_Convert_To
(RTE
(RE_Prim_Ptr
),
5843 Make_Attribute_Reference
(Loc
,
5844 Prefix
=> New_Reference_To
(Prim_Table
(J
), Loc
),
5845 Attribute_Name
=> Name_Unrestricted_Access
));
5847 New_Node
:= Make_Null
(Loc
);
5850 Append_To
(Prim_Ops_Aggr_List
, New_Node
);
5856 Make_Aggregate
(Loc
,
5857 Expressions
=> Prim_Ops_Aggr_List
);
5859 Append_To
(DT_Aggr_List
, New_Node
);
5861 -- Remember aggregates initializing dispatch tables
5863 Append_Elmt
(New_Node
, DT_Aggr
);
5865 -- In case of locally defined tagged types we have already declared
5866 -- and uninitialized object for the dispatch table, which is now
5867 -- initialized by means of an assignment.
5869 if not Building_Static_DT
(Typ
) then
5871 Make_Assignment_Statement
(Loc
,
5872 Name
=> New_Reference_To
(DT
, Loc
),
5873 Expression
=> Make_Aggregate
(Loc
,
5874 Expressions
=> DT_Aggr_List
)));
5876 -- In case of library level tagged types we declare now and export
5877 -- the constant object containing the dispatch table.
5881 Make_Object_Declaration
(Loc
,
5882 Defining_Identifier
=> DT
,
5883 Aliased_Present
=> True,
5884 Constant_Present
=> True,
5885 Object_Definition
=>
5886 Make_Subtype_Indication
(Loc
,
5887 Subtype_Mark
=> New_Reference_To
5888 (RTE
(RE_Dispatch_Table_Wrapper
), Loc
),
5889 Constraint
=> Make_Index_Or_Discriminant_Constraint
(Loc
,
5890 Constraints
=> DT_Constr_List
)),
5891 Expression
=> Make_Aggregate
(Loc
,
5892 Expressions
=> DT_Aggr_List
)));
5895 Make_Attribute_Definition_Clause
(Loc
,
5896 Name
=> New_Reference_To
(DT
, Loc
),
5897 Chars
=> Name_Alignment
,
5899 Make_Attribute_Reference
(Loc
,
5901 New_Reference_To
(RTE
(RE_Integer_Address
), Loc
),
5902 Attribute_Name
=> Name_Alignment
)));
5904 Export_DT
(Typ
, DT
);
5908 -- Initialize the table of ancestor tags if not building static
5911 if not Building_Static_DT
(Typ
)
5912 and then not Is_Interface
(Typ
)
5913 and then not Is_CPP_Class
(Typ
)
5916 Make_Assignment_Statement
(Loc
,
5918 Make_Indexed_Component
(Loc
,
5920 Make_Selected_Component
(Loc
,
5922 New_Reference_To
(TSD
, Loc
),
5925 (RTE_Record_Component
(RE_Tags_Table
), Loc
)),
5927 New_List
(Make_Integer_Literal
(Loc
, 0))),
5931 (Node
(First_Elmt
(Access_Disp_Table
(Typ
))), Loc
)));
5934 -- Inherit the dispatch tables of the parent. There is no need to
5935 -- inherit anything from the parent when building static dispatch tables
5936 -- because the whole dispatch table (including inherited primitives) has
5937 -- been already built.
5939 if Building_Static_DT
(Typ
) then
5942 -- If the ancestor is a CPP_Class type we inherit the dispatch tables
5943 -- in the init proc, and we don't need to fill them in here.
5945 elsif Is_CPP_Class
(Parent_Typ
) then
5948 -- Otherwise we fill in the dispatch tables here
5951 if Typ
/= Parent_Typ
5952 and then not Is_Interface
(Typ
)
5953 and then not Restriction_Active
(No_Dispatching_Calls
)
5955 -- Inherit the dispatch table
5957 if not Is_Interface
(Typ
)
5958 and then not Is_Interface
(Parent_Typ
)
5959 and then not Is_CPP_Class
(Parent_Typ
)
5962 Nb_Prims
: constant Int
:=
5963 UI_To_Int
(DT_Entry_Count
5964 (First_Tag_Component
(Parent_Typ
)));
5967 Append_To
(Elab_Code
,
5968 Build_Inherit_Predefined_Prims
(Loc
,
5974 (Access_Disp_Table
(Parent_Typ
)))), Loc
),
5980 (Access_Disp_Table
(Typ
)))), Loc
)));
5982 if Nb_Prims
/= 0 then
5983 Append_To
(Elab_Code
,
5984 Build_Inherit_Prims
(Loc
,
5990 (Access_Disp_Table
(Parent_Typ
))), Loc
),
5991 New_Tag_Node
=> New_Reference_To
(DT_Ptr
, Loc
),
5992 Num_Prims
=> Nb_Prims
));
5997 -- Inherit the secondary dispatch tables of the ancestor
5999 if not Is_CPP_Class
(Parent_Typ
) then
6001 Sec_DT_Ancestor
: Elmt_Id
:=
6005 (Access_Disp_Table
(Parent_Typ
))));
6006 Sec_DT_Typ
: Elmt_Id
:=
6010 (Access_Disp_Table
(Typ
))));
6012 procedure Copy_Secondary_DTs
(Typ
: Entity_Id
);
6013 -- Local procedure required to climb through the ancestors
6014 -- and copy the contents of all their secondary dispatch
6017 ------------------------
6018 -- Copy_Secondary_DTs --
6019 ------------------------
6021 procedure Copy_Secondary_DTs
(Typ
: Entity_Id
) is
6026 -- Climb to the ancestor (if any) handling private types
6028 if Present
(Full_View
(Etype
(Typ
))) then
6029 if Full_View
(Etype
(Typ
)) /= Typ
then
6030 Copy_Secondary_DTs
(Full_View
(Etype
(Typ
)));
6033 elsif Etype
(Typ
) /= Typ
then
6034 Copy_Secondary_DTs
(Etype
(Typ
));
6037 if Present
(Interfaces
(Typ
))
6038 and then not Is_Empty_Elmt_List
(Interfaces
(Typ
))
6040 Iface
:= First_Elmt
(Interfaces
(Typ
));
6041 E
:= First_Entity
(Typ
);
6043 and then Present
(Node
(Sec_DT_Ancestor
))
6044 and then Ekind
(Node
(Sec_DT_Ancestor
)) = E_Constant
6046 if Is_Tag
(E
) and then Chars
(E
) /= Name_uTag
then
6048 Num_Prims
: constant Int
:=
6049 UI_To_Int
(DT_Entry_Count
(E
));
6052 if not Is_Interface
(Etype
(Typ
)) then
6054 -- Inherit first secondary dispatch table
6056 Append_To
(Elab_Code
,
6057 Build_Inherit_Predefined_Prims
(Loc
,
6059 Unchecked_Convert_To
(RTE
(RE_Tag
),
6062 (Next_Elmt
(Sec_DT_Ancestor
)),
6065 Unchecked_Convert_To
(RTE
(RE_Tag
),
6067 (Node
(Next_Elmt
(Sec_DT_Typ
)),
6070 if Num_Prims
/= 0 then
6071 Append_To
(Elab_Code
,
6072 Build_Inherit_Prims
(Loc
,
6073 Typ
=> Node
(Iface
),
6075 Unchecked_Convert_To
6078 (Node
(Sec_DT_Ancestor
),
6081 Unchecked_Convert_To
6084 (Node
(Sec_DT_Typ
), Loc
)),
6085 Num_Prims
=> Num_Prims
));
6089 Next_Elmt
(Sec_DT_Ancestor
);
6090 Next_Elmt
(Sec_DT_Typ
);
6092 -- Skip the secondary dispatch table of
6093 -- predefined primitives
6095 Next_Elmt
(Sec_DT_Ancestor
);
6096 Next_Elmt
(Sec_DT_Typ
);
6098 if not Is_Interface
(Etype
(Typ
)) then
6100 -- Inherit second secondary dispatch table
6102 Append_To
(Elab_Code
,
6103 Build_Inherit_Predefined_Prims
(Loc
,
6105 Unchecked_Convert_To
(RTE
(RE_Tag
),
6108 (Next_Elmt
(Sec_DT_Ancestor
)),
6111 Unchecked_Convert_To
(RTE
(RE_Tag
),
6113 (Node
(Next_Elmt
(Sec_DT_Typ
)),
6116 if Num_Prims
/= 0 then
6117 Append_To
(Elab_Code
,
6118 Build_Inherit_Prims
(Loc
,
6119 Typ
=> Node
(Iface
),
6121 Unchecked_Convert_To
6124 (Node
(Sec_DT_Ancestor
),
6127 Unchecked_Convert_To
6130 (Node
(Sec_DT_Typ
), Loc
)),
6131 Num_Prims
=> Num_Prims
));
6136 Next_Elmt
(Sec_DT_Ancestor
);
6137 Next_Elmt
(Sec_DT_Typ
);
6139 -- Skip the secondary dispatch table of
6140 -- predefined primitives
6142 Next_Elmt
(Sec_DT_Ancestor
);
6143 Next_Elmt
(Sec_DT_Typ
);
6151 end Copy_Secondary_DTs
;
6154 if Present
(Node
(Sec_DT_Ancestor
))
6155 and then Ekind
(Node
(Sec_DT_Ancestor
)) = E_Constant
6157 -- Handle private types
6159 if Present
(Full_View
(Typ
)) then
6160 Copy_Secondary_DTs
(Full_View
(Typ
));
6162 Copy_Secondary_DTs
(Typ
);
6170 -- If the type has a representation clause which specifies its external
6171 -- tag then generate code to check if the external tag of this type is
6172 -- the same as the external tag of some other declaration.
6174 -- Check_TSD (TSD'Unrestricted_Access);
6176 -- This check is a consequence of AI05-0113-1/06, so it officially
6177 -- applies to Ada 2005 (and Ada 2012). It might be argued that it is
6178 -- a desirable check to add in Ada 95 mode, but we hesitate to make
6179 -- this change, as it would be incompatible, and could conceivably
6180 -- cause a problem in existing Aa 95 code.
6182 -- We check for No_Run_Time_Mode here, because we do not want to pick
6183 -- up the RE_Check_TSD entity and call it in No_Run_Time mode.
6185 if not No_Run_Time_Mode
6186 and then Ada_Version
>= Ada_2005
6187 and then Has_External_Tag_Rep_Clause
(Typ
)
6188 and then RTE_Available
(RE_Check_TSD
)
6189 and then not Debug_Flag_QQ
6191 Append_To
(Elab_Code
,
6192 Make_Procedure_Call_Statement
(Loc
,
6193 Name
=> New_Reference_To
(RTE
(RE_Check_TSD
), Loc
),
6194 Parameter_Associations
=> New_List
(
6195 Make_Attribute_Reference
(Loc
,
6196 Prefix
=> New_Reference_To
(TSD
, Loc
),
6197 Attribute_Name
=> Name_Unchecked_Access
))));
6200 -- Generate code to register the Tag in the External_Tag hash table for
6201 -- the pure Ada type only.
6203 -- Register_Tag (Dt_Ptr);
6205 -- Skip this action in the following cases:
6206 -- 1) if Register_Tag is not available.
6207 -- 2) in No_Run_Time mode.
6208 -- 3) if Typ is not defined at the library level (this is required
6209 -- to avoid adding concurrency control to the hash table used
6210 -- by the run-time to register the tags).
6212 if not No_Run_Time_Mode
6213 and then Is_Library_Level_Entity
(Typ
)
6214 and then RTE_Available
(RE_Register_Tag
)
6216 Append_To
(Elab_Code
,
6217 Make_Procedure_Call_Statement
(Loc
,
6218 Name
=> New_Reference_To
(RTE
(RE_Register_Tag
), Loc
),
6219 Parameter_Associations
=>
6220 New_List
(New_Reference_To
(DT_Ptr
, Loc
))));
6223 if not Is_Empty_List
(Elab_Code
) then
6224 Append_List_To
(Result
, Elab_Code
);
6227 -- Populate the two auxiliary tables used for dispatching asynchronous,
6228 -- conditional and timed selects for synchronized types that implement
6229 -- a limited interface. Skip this step in Ravenscar profile or when
6230 -- general dispatching is forbidden.
6232 if Ada_Version
>= Ada_2005
6233 and then Is_Concurrent_Record_Type
(Typ
)
6234 and then Has_Interfaces
(Typ
)
6235 and then not Restriction_Active
(No_Dispatching_Calls
)
6236 and then not Restriction_Active
(No_Select_Statements
)
6238 Append_List_To
(Result
,
6239 Make_Select_Specific_Data_Table
(Typ
));
6242 -- Remember entities containing dispatch tables
6244 Append_Elmt
(Predef_Prims
, DT_Decl
);
6245 Append_Elmt
(DT
, DT_Decl
);
6247 Analyze_List
(Result
, Suppress
=> All_Checks
);
6248 Set_Has_Dispatch_Table
(Typ
);
6250 -- Mark entities containing dispatch tables. Required by the backend to
6251 -- handle them properly.
6253 if Has_DT
(Typ
) then
6258 -- Object declarations
6260 Elmt
:= First_Elmt
(DT_Decl
);
6261 while Present
(Elmt
) loop
6262 Set_Is_Dispatch_Table_Entity
(Node
(Elmt
));
6263 pragma Assert
(Ekind
(Etype
(Node
(Elmt
))) = E_Array_Subtype
6264 or else Ekind
(Etype
(Node
(Elmt
))) = E_Record_Subtype
);
6265 Set_Is_Dispatch_Table_Entity
(Etype
(Node
(Elmt
)));
6269 -- Aggregates initializing dispatch tables
6271 Elmt
:= First_Elmt
(DT_Aggr
);
6272 while Present
(Elmt
) loop
6273 Set_Is_Dispatch_Table_Entity
(Etype
(Node
(Elmt
)));
6279 -- Register the tagged type in the call graph nodes table
6281 Register_CG_Node
(Typ
);
6290 function Make_VM_TSD
(Typ
: Entity_Id
) return List_Id
is
6291 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
6292 Result
: constant List_Id
:= New_List
;
6294 function Count_Primitives
(Typ
: Entity_Id
) return Nat
;
6295 -- Count the non-predefined primitive operations of Typ
6297 ----------------------
6298 -- Count_Primitives --
6299 ----------------------
6301 function Count_Primitives
(Typ
: Entity_Id
) return Nat
is
6303 Prim_Elmt
: Elmt_Id
;
6309 Prim_Elmt
:= First_Elmt
(Primitive_Operations
(Typ
));
6310 while Present
(Prim_Elmt
) loop
6311 Prim
:= Node
(Prim_Elmt
);
6313 if Is_Predefined_Dispatching_Operation
(Prim
)
6314 or else Is_Predefined_Dispatching_Alias
(Prim
)
6318 elsif Present
(Interface_Alias
(Prim
)) then
6322 Nb_Prim
:= Nb_Prim
+ 1;
6325 Next_Elmt
(Prim_Elmt
);
6329 end Count_Primitives
;
6335 function Make_OSD
(Iface
: Entity_Id
) return Node_Id
;
6336 -- Generate the Object Specific Data table required to dispatch calls
6337 -- through synchronized interfaces. Returns a node that references the
6338 -- generated OSD object.
6340 function Make_OSD
(Iface
: Entity_Id
) return Node_Id
is
6341 Nb_Prim
: constant Nat
:= Count_Primitives
(Iface
);
6343 OSD_Aggr_List
: List_Id
;
6347 -- OSD : Ada.Tags.Object_Specific_Data (Nb_Prims) :=
6348 -- (OSD_Table => (1 => <value>,
6353 or else Is_Abstract_Type
(Typ
)
6354 or else Is_Controlled
(Typ
)
6355 or else Restriction_Active
(No_Dispatching_Calls
)
6356 or else not Is_Limited_Type
(Typ
)
6357 or else not Has_Interfaces
(Typ
)
6358 or else not RTE_Record_Component_Available
(RE_OSD_Table
)
6360 -- No OSD table required
6362 return Make_Null
(Loc
);
6365 OSD_Aggr_List
:= New_List
;
6368 Prim_Table
: array (Nat
range 1 .. Nb_Prim
) of Entity_Id
;
6370 Prim_Alias
: Entity_Id
;
6371 Prim_Elmt
: Elmt_Id
;
6377 Prim_Table
:= (others => Empty
);
6378 Prim_Alias
:= Empty
;
6380 Prim_Elmt
:= First_Elmt
(Primitive_Operations
(Typ
));
6381 while Present
(Prim_Elmt
) loop
6382 Prim
:= Node
(Prim_Elmt
);
6384 if Present
(Interface_Alias
(Prim
))
6385 and then Find_Dispatching_Type
6386 (Interface_Alias
(Prim
)) = Iface
6388 Prim_Alias
:= Interface_Alias
(Prim
);
6389 E
:= Ultimate_Alias
(Prim
);
6390 Pos
:= UI_To_Int
(DT_Position
(Prim_Alias
));
6392 if Present
(Prim_Table
(Pos
)) then
6393 pragma Assert
(Prim_Table
(Pos
) = E
);
6397 Prim_Table
(Pos
) := E
;
6399 Append_To
(OSD_Aggr_List
,
6400 Make_Component_Association
(Loc
,
6401 Choices
=> New_List
(
6402 Make_Integer_Literal
(Loc
,
6403 DT_Position
(Prim_Alias
))),
6405 Make_Integer_Literal
(Loc
,
6406 DT_Position
(Alias
(Prim
)))));
6412 Next_Elmt
(Prim_Elmt
);
6414 pragma Assert
(Count
= Nb_Prim
);
6417 OSD
:= Make_Temporary
(Loc
, 'I');
6420 Make_Object_Declaration
(Loc
,
6421 Defining_Identifier
=> OSD
,
6422 Aliased_Present
=> True,
6423 Constant_Present
=> True,
6424 Object_Definition
=>
6425 Make_Subtype_Indication
(Loc
,
6427 New_Reference_To
(RTE
(RE_Object_Specific_Data
), Loc
),
6429 Make_Index_Or_Discriminant_Constraint
(Loc
,
6430 Constraints
=> New_List
(
6431 Make_Integer_Literal
(Loc
, Nb_Prim
)))),
6434 Make_Aggregate
(Loc
,
6435 Component_Associations
=> New_List
(
6436 Make_Component_Association
(Loc
,
6437 Choices
=> New_List
(
6439 (RTE_Record_Component
(RE_OSD_Num_Prims
), Loc
)),
6441 Make_Integer_Literal
(Loc
, Nb_Prim
)),
6443 Make_Component_Association
(Loc
,
6444 Choices
=> New_List
(
6446 (RTE_Record_Component
(RE_OSD_Table
), Loc
)),
6447 Expression
=> Make_Aggregate
(Loc
,
6448 Component_Associations
=> OSD_Aggr_List
))))));
6451 Make_Attribute_Reference
(Loc
,
6452 Prefix
=> New_Reference_To
(OSD
, Loc
),
6453 Attribute_Name
=> Name_Unchecked_Access
);
6459 Nb_Prim
: constant Nat
:= Count_Primitives
(Typ
);
6462 Iface_Table_Node
: Node_Id
;
6464 TSD_Aggr_List
: List_Id
;
6465 Typ_Ifaces
: Elist_Id
;
6466 TSD_Tags_List
: List_Id
;
6468 Tname
: constant Name_Id
:= Chars
(Typ
);
6469 Name_SSD
: constant Name_Id
:=
6470 New_External_Name
(Tname
, 'S', Suffix_Index
=> -1);
6471 Name_TSD
: constant Name_Id
:=
6472 New_External_Name
(Tname
, 'B', Suffix_Index
=> -1);
6473 SSD
: constant Entity_Id
:=
6474 Make_Defining_Identifier
(Loc
, Name_SSD
);
6475 TSD
: constant Entity_Id
:=
6476 Make_Defining_Identifier
(Loc
, Name_TSD
);
6478 -- Generate code to create the storage for the type specific data object
6479 -- with enough space to store the tags of the ancestors plus the tags
6480 -- of all the implemented interfaces (as described in a-tags.ads).
6482 -- TSD : Type_Specific_Data (I_Depth) :=
6483 -- (Idepth => I_Depth,
6484 -- Tag_Kind => <tag_kind-value>,
6485 -- Access_Level => Type_Access_Level (Typ),
6486 -- Alignment => Typ'Alignment,
6488 -- Type_Is_Abstract => <<boolean-value>>,
6489 -- Type_Is_Library_Level => <<boolean-value>>,
6490 -- Interfaces_Table => <<access-value>>
6491 -- SSD => SSD_Table'Address
6492 -- Tags_Table => (0 => Typ'Tag,
6496 TSD_Aggr_List
:= New_List
;
6498 -- Idepth: Count ancestors to compute the inheritance depth. For private
6499 -- extensions, always go to the full view in order to compute the real
6500 -- inheritance depth.
6503 Current_Typ
: Entity_Id
;
6504 Parent_Typ
: Entity_Id
;
6510 Parent_Typ
:= Etype
(Current_Typ
);
6512 if Is_Private_Type
(Parent_Typ
) then
6513 Parent_Typ
:= Full_View
(Base_Type
(Parent_Typ
));
6516 exit when Parent_Typ
= Current_Typ
;
6518 I_Depth
:= I_Depth
+ 1;
6519 Current_Typ
:= Parent_Typ
;
6525 Append_To
(TSD_Aggr_List
,
6526 Make_Integer_Literal
(Loc
, I_Depth
));
6530 Append_To
(TSD_Aggr_List
, Tagged_Kind
(Typ
));
6534 Append_To
(TSD_Aggr_List
,
6535 Make_Integer_Literal
(Loc
, Type_Access_Level
(Typ
)));
6539 -- For CPP types we cannot rely on the value of 'Alignment provided
6540 -- by the backend to initialize this TSD field. Why not???
6542 if Convention
(Typ
) = Convention_CPP
6543 or else Is_CPP_Class
(Root_Type
(Typ
))
6545 Append_To
(TSD_Aggr_List
,
6546 Make_Integer_Literal
(Loc
, 0));
6548 Append_To
(TSD_Aggr_List
,
6549 Make_Attribute_Reference
(Loc
,
6550 Prefix
=> New_Reference_To
(Typ
, Loc
),
6551 Attribute_Name
=> Name_Alignment
));
6556 Append_To
(TSD_Aggr_List
,
6559 -- Type_Is_Abstract (Ada 2012: AI05-0173)
6562 Type_Is_Abstract
: Entity_Id
;
6566 Boolean_Literals
(Is_Abstract_Type
(Typ
));
6568 Append_To
(TSD_Aggr_List
,
6569 New_Occurrence_Of
(Type_Is_Abstract
, Loc
));
6572 -- Type_Is_Library_Level
6575 Type_Is_Library_Level
: Entity_Id
;
6577 Type_Is_Library_Level
:=
6578 Boolean_Literals
(Is_Library_Level_Entity
(Typ
));
6579 Append_To
(TSD_Aggr_List
,
6580 New_Occurrence_Of
(Type_Is_Library_Level
, Loc
));
6583 -- Interfaces_Table (required for AI-405)
6585 if RTE_Record_Component_Available
(RE_Interfaces_Table
) then
6587 -- Count the number of interface types implemented by Typ
6589 Collect_Interfaces
(Typ
, Typ_Ifaces
);
6592 AI
:= First_Elmt
(Typ_Ifaces
);
6593 while Present
(AI
) loop
6594 Num_Ifaces
:= Num_Ifaces
+ 1;
6598 if Num_Ifaces
= 0 then
6599 Iface_Table_Node
:= Make_Null
(Loc
);
6601 -- Generate the Interface_Table object
6605 TSD_Ifaces_List
: constant List_Id
:= New_List
;
6610 AI
:= First_Elmt
(Typ_Ifaces
);
6611 while Present
(AI
) loop
6614 Append_To
(TSD_Ifaces_List
,
6615 Make_Aggregate
(Loc
,
6616 Expressions
=> New_List
(
6620 Make_Attribute_Reference
(Loc
,
6621 Prefix
=> New_Reference_To
(Iface
, Loc
),
6622 Attribute_Name
=> Name_Tag
),
6626 Make_OSD
(Iface
))));
6631 ITable
:= Make_Temporary
(Loc
, 'I');
6634 Make_Object_Declaration
(Loc
,
6635 Defining_Identifier
=> ITable
,
6636 Aliased_Present
=> True,
6637 Constant_Present
=> True,
6638 Object_Definition
=>
6639 Make_Subtype_Indication
(Loc
,
6641 New_Reference_To
(RTE
(RE_Interface_Data
), Loc
),
6642 Constraint
=> Make_Index_Or_Discriminant_Constraint
6644 Constraints
=> New_List
(
6645 Make_Integer_Literal
(Loc
, Num_Ifaces
)))),
6647 Expression
=> Make_Aggregate
(Loc
,
6648 Expressions
=> New_List
(
6649 Make_Integer_Literal
(Loc
, Num_Ifaces
),
6650 Make_Aggregate
(Loc
,
6651 Expressions
=> TSD_Ifaces_List
)))));
6654 Make_Attribute_Reference
(Loc
,
6655 Prefix
=> New_Reference_To
(ITable
, Loc
),
6656 Attribute_Name
=> Name_Unchecked_Access
);
6660 Append_To
(TSD_Aggr_List
, Iface_Table_Node
);
6663 -- Generate the Select Specific Data table for synchronized types that
6664 -- implement synchronized interfaces. The size of the table is
6665 -- constrained by the number of non-predefined primitive operations.
6667 if RTE_Record_Component_Available
(RE_SSD
) then
6668 if Ada_Version
>= Ada_2005
6669 and then Has_DT
(Typ
)
6670 and then Is_Concurrent_Record_Type
(Typ
)
6671 and then Has_Interfaces
(Typ
)
6672 and then Nb_Prim
> 0
6673 and then not Is_Abstract_Type
(Typ
)
6674 and then not Is_Controlled
(Typ
)
6675 and then not Restriction_Active
(No_Dispatching_Calls
)
6676 and then not Restriction_Active
(No_Select_Statements
)
6679 Make_Object_Declaration
(Loc
,
6680 Defining_Identifier
=> SSD
,
6681 Aliased_Present
=> True,
6682 Object_Definition
=>
6683 Make_Subtype_Indication
(Loc
,
6684 Subtype_Mark
=> New_Reference_To
(
6685 RTE
(RE_Select_Specific_Data
), Loc
),
6687 Make_Index_Or_Discriminant_Constraint
(Loc
,
6688 Constraints
=> New_List
(
6689 Make_Integer_Literal
(Loc
, Nb_Prim
))))));
6691 -- This table is initialized by Make_Select_Specific_Data_Table,
6692 -- which calls Set_Entry_Index and Set_Prim_Op_Kind.
6694 Append_To
(TSD_Aggr_List
,
6695 Make_Attribute_Reference
(Loc
,
6696 Prefix
=> New_Reference_To
(SSD
, Loc
),
6697 Attribute_Name
=> Name_Unchecked_Access
));
6699 Append_To
(TSD_Aggr_List
, Make_Null
(Loc
));
6703 -- Initialize the table of ancestor tags. In case of interface types
6704 -- this table is not needed.
6706 TSD_Tags_List
:= New_List
;
6708 -- Fill position 0 with Typ'Tag
6710 Append_To
(TSD_Tags_List
,
6711 Make_Attribute_Reference
(Loc
,
6712 Prefix
=> New_Reference_To
(Typ
, Loc
),
6713 Attribute_Name
=> Name_Tag
));
6715 -- Fill the rest of the table with the tags of the ancestors
6718 Current_Typ
: Entity_Id
;
6719 Parent_Typ
: Entity_Id
;
6727 Parent_Typ
:= Etype
(Current_Typ
);
6729 if Is_Private_Type
(Parent_Typ
) then
6730 Parent_Typ
:= Full_View
(Base_Type
(Parent_Typ
));
6733 exit when Parent_Typ
= Current_Typ
;
6735 Append_To
(TSD_Tags_List
,
6736 Make_Attribute_Reference
(Loc
,
6737 Prefix
=> New_Reference_To
(Parent_Typ
, Loc
),
6738 Attribute_Name
=> Name_Tag
));
6741 Current_Typ
:= Parent_Typ
;
6744 pragma Assert
(Pos
= I_Depth
+ 1);
6747 Append_To
(TSD_Aggr_List
,
6748 Make_Aggregate
(Loc
,
6749 Expressions
=> TSD_Tags_List
));
6751 -- Build the TSD object
6754 Make_Object_Declaration
(Loc
,
6755 Defining_Identifier
=> TSD
,
6756 Aliased_Present
=> True,
6757 Constant_Present
=> True,
6758 Object_Definition
=>
6759 Make_Subtype_Indication
(Loc
,
6760 Subtype_Mark
=> New_Reference_To
(
6761 RTE
(RE_Type_Specific_Data
), Loc
),
6763 Make_Index_Or_Discriminant_Constraint
(Loc
,
6764 Constraints
=> New_List
(
6765 Make_Integer_Literal
(Loc
, I_Depth
)))),
6767 Expression
=> Make_Aggregate
(Loc
,
6768 Expressions
=> TSD_Aggr_List
)));
6772 -- (TSD => TSD'Unrestricted_Access);
6774 if Ada_Version
>= Ada_2005
6775 and then Is_Library_Level_Entity
(Typ
)
6776 and then Has_External_Tag_Rep_Clause
(Typ
)
6777 and then RTE_Available
(RE_Check_TSD
)
6778 and then not Debug_Flag_QQ
6781 Make_Procedure_Call_Statement
(Loc
,
6782 Name
=> New_Reference_To
(RTE
(RE_Check_TSD
), Loc
),
6783 Parameter_Associations
=> New_List
(
6784 Make_Attribute_Reference
(Loc
,
6785 Prefix
=> New_Reference_To
(TSD
, Loc
),
6786 Attribute_Name
=> Name_Unrestricted_Access
))));
6790 -- Register_TSD (TSD'Unrestricted_Access);
6793 Make_Procedure_Call_Statement
(Loc
,
6794 Name
=> New_Reference_To
(RTE
(RE_Register_TSD
), Loc
),
6795 Parameter_Associations
=> New_List
(
6796 Make_Attribute_Reference
(Loc
,
6797 Prefix
=> New_Reference_To
(TSD
, Loc
),
6798 Attribute_Name
=> Name_Unrestricted_Access
))));
6800 -- Populate the two auxiliary tables used for dispatching asynchronous,
6801 -- conditional and timed selects for synchronized types that implement
6802 -- a limited interface. Skip this step in Ravenscar profile or when
6803 -- general dispatching is forbidden.
6805 if Ada_Version
>= Ada_2005
6806 and then Is_Concurrent_Record_Type
(Typ
)
6807 and then Has_Interfaces
(Typ
)
6808 and then not Restriction_Active
(No_Dispatching_Calls
)
6809 and then not Restriction_Active
(No_Select_Statements
)
6811 Append_List_To
(Result
,
6812 Make_Select_Specific_Data_Table
(Typ
));
6818 -------------------------------------
6819 -- Make_Select_Specific_Data_Table --
6820 -------------------------------------
6822 function Make_Select_Specific_Data_Table
6823 (Typ
: Entity_Id
) return List_Id
6825 Assignments
: constant List_Id
:= New_List
;
6826 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
6828 Conc_Typ
: Entity_Id
;
6831 Prim_Als
: Entity_Id
;
6832 Prim_Elmt
: Elmt_Id
;
6836 type Examined_Array
is array (Int
range <>) of Boolean;
6838 function Find_Entry_Index
(E
: Entity_Id
) return Uint
;
6839 -- Given an entry, find its index in the visible declarations of the
6840 -- corresponding concurrent type of Typ.
6842 ----------------------
6843 -- Find_Entry_Index --
6844 ----------------------
6846 function Find_Entry_Index
(E
: Entity_Id
) return Uint
is
6847 Index
: Uint
:= Uint_1
;
6848 Subp_Decl
: Entity_Id
;
6852 and then not Is_Empty_List
(Decls
)
6854 Subp_Decl
:= First
(Decls
);
6855 while Present
(Subp_Decl
) loop
6856 if Nkind
(Subp_Decl
) = N_Entry_Declaration
then
6857 if Defining_Identifier
(Subp_Decl
) = E
then
6869 end Find_Entry_Index
;
6875 -- Start of processing for Make_Select_Specific_Data_Table
6878 pragma Assert
(not Restriction_Active
(No_Dispatching_Calls
));
6880 if Present
(Corresponding_Concurrent_Type
(Typ
)) then
6881 Conc_Typ
:= Corresponding_Concurrent_Type
(Typ
);
6883 if Present
(Full_View
(Conc_Typ
)) then
6884 Conc_Typ
:= Full_View
(Conc_Typ
);
6887 if Ekind
(Conc_Typ
) = E_Protected_Type
then
6888 Decls
:= Visible_Declarations
(Protected_Definition
(
6889 Parent
(Conc_Typ
)));
6891 pragma Assert
(Ekind
(Conc_Typ
) = E_Task_Type
);
6892 Decls
:= Visible_Declarations
(Task_Definition
(
6893 Parent
(Conc_Typ
)));
6897 -- Count the non-predefined primitive operations
6899 Prim_Elmt
:= First_Elmt
(Primitive_Operations
(Typ
));
6900 while Present
(Prim_Elmt
) loop
6901 Prim
:= Node
(Prim_Elmt
);
6903 if not (Is_Predefined_Dispatching_Operation
(Prim
)
6904 or else Is_Predefined_Dispatching_Alias
(Prim
))
6906 Nb_Prim
:= Nb_Prim
+ 1;
6909 Next_Elmt
(Prim_Elmt
);
6913 Examined
: Examined_Array
(1 .. Nb_Prim
) := (others => False);
6916 Prim_Elmt
:= First_Elmt
(Primitive_Operations
(Typ
));
6917 while Present
(Prim_Elmt
) loop
6918 Prim
:= Node
(Prim_Elmt
);
6920 -- Look for primitive overriding an abstract interface subprogram
6922 if Present
(Interface_Alias
(Prim
))
6925 (Find_Dispatching_Type
(Interface_Alias
(Prim
)), Typ
,
6926 Use_Full_View
=> True)
6927 and then not Examined
(UI_To_Int
(DT_Position
(Alias
(Prim
))))
6929 Prim_Pos
:= DT_Position
(Alias
(Prim
));
6930 pragma Assert
(UI_To_Int
(Prim_Pos
) <= Nb_Prim
);
6931 Examined
(UI_To_Int
(Prim_Pos
)) := True;
6933 -- Set the primitive operation kind regardless of subprogram
6935 -- Ada.Tags.Set_Prim_Op_Kind (DT_Ptr, <position>, <kind>);
6937 if Tagged_Type_Expansion
then
6940 (Node
(First_Elmt
(Access_Disp_Table
(Typ
))), Loc
);
6944 Make_Attribute_Reference
(Loc
,
6945 Prefix
=> New_Reference_To
(Typ
, Loc
),
6946 Attribute_Name
=> Name_Tag
);
6949 Append_To
(Assignments
,
6950 Make_Procedure_Call_Statement
(Loc
,
6951 Name
=> New_Reference_To
(RTE
(RE_Set_Prim_Op_Kind
), Loc
),
6952 Parameter_Associations
=> New_List
(
6954 Make_Integer_Literal
(Loc
, Prim_Pos
),
6955 Prim_Op_Kind
(Alias
(Prim
), Typ
))));
6957 -- Retrieve the root of the alias chain
6959 Prim_Als
:= Ultimate_Alias
(Prim
);
6961 -- In the case of an entry wrapper, set the entry index
6963 if Ekind
(Prim
) = E_Procedure
6964 and then Is_Primitive_Wrapper
(Prim_Als
)
6965 and then Ekind
(Wrapped_Entity
(Prim_Als
)) = E_Entry
6968 -- Ada.Tags.Set_Entry_Index
6969 -- (DT_Ptr, <position>, <index>);
6971 if Tagged_Type_Expansion
then
6974 (Node
(First_Elmt
(Access_Disp_Table
(Typ
))), Loc
);
6977 Make_Attribute_Reference
(Loc
,
6978 Prefix
=> New_Reference_To
(Typ
, Loc
),
6979 Attribute_Name
=> Name_Tag
);
6982 Append_To
(Assignments
,
6983 Make_Procedure_Call_Statement
(Loc
,
6985 New_Reference_To
(RTE
(RE_Set_Entry_Index
), Loc
),
6986 Parameter_Associations
=> New_List
(
6988 Make_Integer_Literal
(Loc
, Prim_Pos
),
6989 Make_Integer_Literal
(Loc
,
6990 Find_Entry_Index
(Wrapped_Entity
(Prim_Als
))))));
6994 Next_Elmt
(Prim_Elmt
);
6999 end Make_Select_Specific_Data_Table
;
7005 function Make_Tags
(Typ
: Entity_Id
) return List_Id
is
7006 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
7007 Result
: constant List_Id
:= New_List
;
7010 (Tag_Typ
: Entity_Id
;
7012 Is_Secondary_DT
: Boolean);
7013 -- Import the dispatch table DT of tagged type Tag_Typ. Required to
7014 -- generate forward references and statically allocate the table. For
7015 -- primary dispatch tables that require no dispatch table generate:
7017 -- DT : static aliased constant Non_Dispatch_Table_Wrapper;
7018 -- pragma Import (Ada, DT);
7020 -- Otherwise generate:
7022 -- DT : static aliased constant Dispatch_Table_Wrapper (Nb_Prim);
7023 -- pragma Import (Ada, DT);
7030 (Tag_Typ
: Entity_Id
;
7032 Is_Secondary_DT
: Boolean)
7034 DT_Constr_List
: List_Id
;
7038 Set_Is_Imported
(DT
);
7039 Set_Ekind
(DT
, E_Constant
);
7040 Set_Related_Type
(DT
, Typ
);
7042 -- The scope must be set now to call Get_External_Name
7044 Set_Scope
(DT
, Current_Scope
);
7046 Get_External_Name
(DT
, True);
7047 Set_Interface_Name
(DT
,
7048 Make_String_Literal
(Loc
, Strval
=> String_From_Name_Buffer
));
7050 -- Ensure proper Sprint output of this implicit importation
7052 Set_Is_Internal
(DT
);
7054 -- Save this entity to allow Make_DT to generate its exportation
7056 Append_Elmt
(DT
, Dispatch_Table_Wrappers
(Typ
));
7058 -- No dispatch table required
7060 if not Is_Secondary_DT
and then not Has_DT
(Tag_Typ
) then
7062 Make_Object_Declaration
(Loc
,
7063 Defining_Identifier
=> DT
,
7064 Aliased_Present
=> True,
7065 Constant_Present
=> True,
7066 Object_Definition
=>
7067 New_Reference_To
(RTE
(RE_No_Dispatch_Table_Wrapper
), Loc
)));
7070 -- Calculate the number of primitives of the dispatch table and
7071 -- the size of the Type_Specific_Data record.
7074 UI_To_Int
(DT_Entry_Count
(First_Tag_Component
(Tag_Typ
)));
7076 -- If the tagged type has no primitives we add a dummy slot whose
7077 -- address will be the tag of this type.
7081 New_List
(Make_Integer_Literal
(Loc
, 1));
7084 New_List
(Make_Integer_Literal
(Loc
, Nb_Prim
));
7088 Make_Object_Declaration
(Loc
,
7089 Defining_Identifier
=> DT
,
7090 Aliased_Present
=> True,
7091 Constant_Present
=> True,
7092 Object_Definition
=>
7093 Make_Subtype_Indication
(Loc
,
7095 New_Reference_To
(RTE
(RE_Dispatch_Table_Wrapper
), Loc
),
7096 Constraint
=> Make_Index_Or_Discriminant_Constraint
(Loc
,
7097 Constraints
=> DT_Constr_List
))));
7103 Tname
: constant Name_Id
:= Chars
(Typ
);
7104 AI_Tag_Comp
: Elmt_Id
;
7105 DT
: Node_Id
:= Empty
;
7107 Predef_Prims_Ptr
: Node_Id
;
7108 Iface_DT
: Node_Id
:= Empty
;
7109 Iface_DT_Ptr
: Node_Id
;
7113 Typ_Comps
: Elist_Id
;
7115 -- Start of processing for Make_Tags
7118 pragma Assert
(No
(Access_Disp_Table
(Typ
)));
7119 Set_Access_Disp_Table
(Typ
, New_Elmt_List
);
7121 -- 1) Generate the primary tag entities
7123 -- Primary dispatch table containing user-defined primitives
7125 DT_Ptr
:= Make_Defining_Identifier
(Loc
, New_External_Name
(Tname
, 'P'));
7126 Set_Etype
(DT_Ptr
, RTE
(RE_Tag
));
7127 Append_Elmt
(DT_Ptr
, Access_Disp_Table
(Typ
));
7129 -- Minimum decoration
7131 Set_Ekind
(DT_Ptr
, E_Variable
);
7132 Set_Related_Type
(DT_Ptr
, Typ
);
7134 -- Ensure that entities Prim_Ptr and Predef_Prims_Table_Ptr have
7135 -- the decoration required by the backend.
7137 -- Odd comment, the back end cannot require anything not properly
7138 -- documented in einfo! ???
7140 Set_Is_Dispatch_Table_Entity
(RTE
(RE_Prim_Ptr
));
7141 Set_Is_Dispatch_Table_Entity
(RTE
(RE_Predef_Prims_Table_Ptr
));
7143 -- For CPP types there is no need to build the dispatch tables since
7144 -- they are imported from the C++ side. If the CPP type has an IP then
7145 -- we declare now the variable that will store the copy of the C++ tag.
7146 -- If the CPP type is an interface, we need the variable as well because
7147 -- it becomes the pointer to the corresponding secondary table.
7149 if Is_CPP_Class
(Typ
) then
7150 if Has_CPP_Constructors
(Typ
) or else Is_Interface
(Typ
) then
7152 Make_Object_Declaration
(Loc
,
7153 Defining_Identifier
=> DT_Ptr
,
7154 Object_Definition
=> New_Reference_To
(RTE
(RE_Tag
), Loc
),
7156 Unchecked_Convert_To
(RTE
(RE_Tag
),
7157 New_Reference_To
(RTE
(RE_Null_Address
), Loc
))));
7159 Set_Is_Statically_Allocated
(DT_Ptr
,
7160 Is_Library_Level_Tagged_Type
(Typ
));
7166 -- Primary dispatch table containing predefined primitives
7169 Make_Defining_Identifier
(Loc
,
7170 Chars
=> New_External_Name
(Tname
, 'Y'));
7171 Set_Etype
(Predef_Prims_Ptr
, RTE
(RE_Address
));
7172 Append_Elmt
(Predef_Prims_Ptr
, Access_Disp_Table
(Typ
));
7174 -- Import the forward declaration of the Dispatch Table wrapper
7175 -- record (Make_DT will take care of exporting it).
7177 if Building_Static_DT
(Typ
) then
7178 Set_Dispatch_Table_Wrappers
(Typ
, New_Elmt_List
);
7181 Make_Defining_Identifier
(Loc
,
7182 Chars
=> New_External_Name
(Tname
, 'T'));
7184 Import_DT
(Typ
, DT
, Is_Secondary_DT
=> False);
7186 if Has_DT
(Typ
) then
7188 Make_Object_Declaration
(Loc
,
7189 Defining_Identifier
=> DT_Ptr
,
7190 Constant_Present
=> True,
7191 Object_Definition
=> New_Reference_To
(RTE
(RE_Tag
), Loc
),
7193 Unchecked_Convert_To
(RTE
(RE_Tag
),
7194 Make_Attribute_Reference
(Loc
,
7196 Make_Selected_Component
(Loc
,
7197 Prefix
=> New_Reference_To
(DT
, Loc
),
7200 (RTE_Record_Component
(RE_Prims_Ptr
), Loc
)),
7201 Attribute_Name
=> Name_Address
))));
7203 -- Generate the SCIL node for the previous object declaration
7204 -- because it has a tag initialization.
7206 if Generate_SCIL
then
7208 Make_SCIL_Dispatch_Table_Tag_Init
(Sloc
(Last
(Result
)));
7209 Set_SCIL_Entity
(New_Node
, Typ
);
7210 Set_SCIL_Node
(Last
(Result
), New_Node
);
7214 Make_Object_Declaration
(Loc
,
7215 Defining_Identifier
=> Predef_Prims_Ptr
,
7216 Constant_Present
=> True,
7217 Object_Definition
=>
7218 New_Reference_To
(RTE
(RE_Address
), Loc
),
7220 Make_Attribute_Reference
(Loc
,
7222 Make_Selected_Component
(Loc
,
7223 Prefix
=> New_Reference_To
(DT
, Loc
),
7226 (RTE_Record_Component
(RE_Predef_Prims
), Loc
)),
7227 Attribute_Name
=> Name_Address
)));
7229 -- No dispatch table required
7233 Make_Object_Declaration
(Loc
,
7234 Defining_Identifier
=> DT_Ptr
,
7235 Constant_Present
=> True,
7236 Object_Definition
=> New_Reference_To
(RTE
(RE_Tag
), Loc
),
7238 Unchecked_Convert_To
(RTE
(RE_Tag
),
7239 Make_Attribute_Reference
(Loc
,
7241 Make_Selected_Component
(Loc
,
7242 Prefix
=> New_Reference_To
(DT
, Loc
),
7245 (RTE_Record_Component
(RE_NDT_Prims_Ptr
),
7247 Attribute_Name
=> Name_Address
))));
7250 Set_Is_True_Constant
(DT_Ptr
);
7251 Set_Is_Statically_Allocated
(DT_Ptr
);
7255 -- 2) Generate the secondary tag entities
7257 -- Collect the components associated with secondary dispatch tables
7259 if Has_Interfaces
(Typ
) then
7260 Collect_Interface_Components
(Typ
, Typ_Comps
);
7262 -- For each interface type we build a unique external name associated
7263 -- with its secondary dispatch table. This name is used to declare an
7264 -- object that references this secondary dispatch table, whose value
7265 -- will be used for the elaboration of Typ objects, and also for the
7266 -- elaboration of objects of types derived from Typ that do not
7267 -- override the primitives of this interface type.
7271 -- Note: The value of Suffix_Index must be in sync with the
7272 -- Suffix_Index values of secondary dispatch tables generated
7275 if Is_CPP_Class
(Typ
) then
7276 AI_Tag_Comp
:= First_Elmt
(Typ_Comps
);
7277 while Present
(AI_Tag_Comp
) loop
7278 Get_Secondary_DT_External_Name
7279 (Typ
, Related_Type
(Node
(AI_Tag_Comp
)), Suffix_Index
);
7280 Typ_Name
:= Name_Find
;
7282 -- Declare variables that will store the copy of the C++
7286 Make_Defining_Identifier
(Loc
,
7287 Chars
=> New_External_Name
(Typ_Name
, 'P'));
7288 Set_Etype
(Iface_DT_Ptr
, RTE
(RE_Interface_Tag
));
7289 Set_Ekind
(Iface_DT_Ptr
, E_Variable
);
7290 Set_Is_Tag
(Iface_DT_Ptr
);
7292 Set_Has_Thunks
(Iface_DT_Ptr
);
7294 (Iface_DT_Ptr
, Related_Type
(Node
(AI_Tag_Comp
)));
7295 Append_Elmt
(Iface_DT_Ptr
, Access_Disp_Table
(Typ
));
7298 Make_Object_Declaration
(Loc
,
7299 Defining_Identifier
=> Iface_DT_Ptr
,
7300 Object_Definition
=> New_Reference_To
7301 (RTE
(RE_Interface_Tag
), Loc
),
7303 Unchecked_Convert_To
(RTE
(RE_Interface_Tag
),
7304 New_Reference_To
(RTE
(RE_Null_Address
), Loc
))));
7306 Set_Is_Statically_Allocated
(Iface_DT_Ptr
,
7307 Is_Library_Level_Tagged_Type
(Typ
));
7309 Next_Elmt
(AI_Tag_Comp
);
7312 -- This is not a CPP_Class type
7315 AI_Tag_Comp
:= First_Elmt
(Typ_Comps
);
7316 while Present
(AI_Tag_Comp
) loop
7317 Get_Secondary_DT_External_Name
7318 (Typ
, Related_Type
(Node
(AI_Tag_Comp
)), Suffix_Index
);
7319 Typ_Name
:= Name_Find
;
7321 if Building_Static_DT
(Typ
) then
7323 Make_Defining_Identifier
(Loc
,
7324 Chars
=> New_External_Name
7325 (Typ_Name
, 'T', Suffix_Index
=> -1));
7327 (Tag_Typ
=> Related_Type
(Node
(AI_Tag_Comp
)),
7329 Is_Secondary_DT
=> True);
7332 -- Secondary dispatch table referencing thunks to user-defined
7333 -- primitives covered by this interface.
7336 Make_Defining_Identifier
(Loc
,
7337 Chars
=> New_External_Name
(Typ_Name
, 'P'));
7338 Set_Etype
(Iface_DT_Ptr
, RTE
(RE_Interface_Tag
));
7339 Set_Ekind
(Iface_DT_Ptr
, E_Constant
);
7340 Set_Is_Tag
(Iface_DT_Ptr
);
7341 Set_Has_Thunks
(Iface_DT_Ptr
);
7342 Set_Is_Statically_Allocated
(Iface_DT_Ptr
,
7343 Is_Library_Level_Tagged_Type
(Typ
));
7344 Set_Is_True_Constant
(Iface_DT_Ptr
);
7346 (Iface_DT_Ptr
, Related_Type
(Node
(AI_Tag_Comp
)));
7347 Append_Elmt
(Iface_DT_Ptr
, Access_Disp_Table
(Typ
));
7349 if Building_Static_DT
(Typ
) then
7351 Make_Object_Declaration
(Loc
,
7352 Defining_Identifier
=> Iface_DT_Ptr
,
7353 Constant_Present
=> True,
7354 Object_Definition
=> New_Reference_To
7355 (RTE
(RE_Interface_Tag
), Loc
),
7357 Unchecked_Convert_To
(RTE
(RE_Interface_Tag
),
7358 Make_Attribute_Reference
(Loc
,
7360 Make_Selected_Component
(Loc
,
7362 New_Reference_To
(Iface_DT
, Loc
),
7365 (RTE_Record_Component
(RE_Prims_Ptr
),
7367 Attribute_Name
=> Name_Address
))));
7370 -- Secondary dispatch table referencing thunks to predefined
7374 Make_Defining_Identifier
(Loc
,
7375 Chars
=> New_External_Name
(Typ_Name
, 'Y'));
7376 Set_Etype
(Iface_DT_Ptr
, RTE
(RE_Address
));
7377 Set_Ekind
(Iface_DT_Ptr
, E_Constant
);
7378 Set_Is_Tag
(Iface_DT_Ptr
);
7379 Set_Has_Thunks
(Iface_DT_Ptr
);
7380 Set_Is_Statically_Allocated
(Iface_DT_Ptr
,
7381 Is_Library_Level_Tagged_Type
(Typ
));
7382 Set_Is_True_Constant
(Iface_DT_Ptr
);
7384 (Iface_DT_Ptr
, Related_Type
(Node
(AI_Tag_Comp
)));
7385 Append_Elmt
(Iface_DT_Ptr
, Access_Disp_Table
(Typ
));
7387 -- Secondary dispatch table referencing user-defined primitives
7388 -- covered by this interface.
7391 Make_Defining_Identifier
(Loc
,
7392 Chars
=> New_External_Name
(Typ_Name
, 'D'));
7393 Set_Etype
(Iface_DT_Ptr
, RTE
(RE_Interface_Tag
));
7394 Set_Ekind
(Iface_DT_Ptr
, E_Constant
);
7395 Set_Is_Tag
(Iface_DT_Ptr
);
7396 Set_Is_Statically_Allocated
(Iface_DT_Ptr
,
7397 Is_Library_Level_Tagged_Type
(Typ
));
7398 Set_Is_True_Constant
(Iface_DT_Ptr
);
7400 (Iface_DT_Ptr
, Related_Type
(Node
(AI_Tag_Comp
)));
7401 Append_Elmt
(Iface_DT_Ptr
, Access_Disp_Table
(Typ
));
7403 -- Secondary dispatch table referencing predefined primitives
7406 Make_Defining_Identifier
(Loc
,
7407 Chars
=> New_External_Name
(Typ_Name
, 'Z'));
7408 Set_Etype
(Iface_DT_Ptr
, RTE
(RE_Address
));
7409 Set_Ekind
(Iface_DT_Ptr
, E_Constant
);
7410 Set_Is_Tag
(Iface_DT_Ptr
);
7411 Set_Is_Statically_Allocated
(Iface_DT_Ptr
,
7412 Is_Library_Level_Tagged_Type
(Typ
));
7413 Set_Is_True_Constant
(Iface_DT_Ptr
);
7415 (Iface_DT_Ptr
, Related_Type
(Node
(AI_Tag_Comp
)));
7416 Append_Elmt
(Iface_DT_Ptr
, Access_Disp_Table
(Typ
));
7418 Next_Elmt
(AI_Tag_Comp
);
7423 -- 3) At the end of Access_Disp_Table, if the type has user-defined
7424 -- primitives, we add the entity of an access type declaration that
7425 -- is used by Build_Get_Prim_Op_Address to expand dispatching calls
7426 -- through the primary dispatch table.
7428 if UI_To_Int
(DT_Entry_Count
(First_Tag_Component
(Typ
))) = 0 then
7429 Analyze_List
(Result
);
7432 -- type Typ_DT is array (1 .. Nb_Prims) of Prim_Ptr;
7433 -- type Typ_DT_Acc is access Typ_DT;
7437 Name_DT_Prims
: constant Name_Id
:=
7438 New_External_Name
(Tname
, 'G');
7439 Name_DT_Prims_Acc
: constant Name_Id
:=
7440 New_External_Name
(Tname
, 'H');
7441 DT_Prims
: constant Entity_Id
:=
7442 Make_Defining_Identifier
(Loc
,
7444 DT_Prims_Acc
: constant Entity_Id
:=
7445 Make_Defining_Identifier
(Loc
,
7449 Make_Full_Type_Declaration
(Loc
,
7450 Defining_Identifier
=> DT_Prims
,
7452 Make_Constrained_Array_Definition
(Loc
,
7453 Discrete_Subtype_Definitions
=> New_List
(
7455 Low_Bound
=> Make_Integer_Literal
(Loc
, 1),
7456 High_Bound
=> Make_Integer_Literal
(Loc
,
7458 (First_Tag_Component
(Typ
))))),
7459 Component_Definition
=>
7460 Make_Component_Definition
(Loc
,
7461 Subtype_Indication
=>
7462 New_Reference_To
(RTE
(RE_Prim_Ptr
), Loc
)))));
7465 Make_Full_Type_Declaration
(Loc
,
7466 Defining_Identifier
=> DT_Prims_Acc
,
7468 Make_Access_To_Object_Definition
(Loc
,
7469 Subtype_Indication
=>
7470 New_Occurrence_Of
(DT_Prims
, Loc
))));
7472 Append_Elmt
(DT_Prims_Acc
, Access_Disp_Table
(Typ
));
7474 -- Analyze the resulting list and suppress the generation of the
7475 -- Init_Proc associated with the above array declaration because
7476 -- this type is never used in object declarations. It is only used
7477 -- to simplify the expansion associated with dispatching calls.
7479 Analyze_List
(Result
);
7480 Set_Suppress_Initialization
(Base_Type
(DT_Prims
));
7482 -- Disable backend optimizations based on assumptions about the
7483 -- aliasing status of objects designated by the access to the
7484 -- dispatch table. Required to handle dispatch tables imported
7487 Set_No_Strict_Aliasing
(Base_Type
(DT_Prims_Acc
));
7489 -- Add the freezing nodes of these declarations; required to avoid
7490 -- generating these freezing nodes in wrong scopes (for example in
7491 -- the IC routine of a derivation of Typ).
7492 -- What is an "IC routine"? Is "init_proc" meant here???
7494 Append_List_To
(Result
, Freeze_Entity
(DT_Prims
, Typ
));
7495 Append_List_To
(Result
, Freeze_Entity
(DT_Prims_Acc
, Typ
));
7497 -- Mark entity of dispatch table. Required by the back end to
7498 -- handle them properly.
7500 Set_Is_Dispatch_Table_Entity
(DT_Prims
);
7504 -- Mark entities of dispatch table. Required by the back end to handle
7507 if Present
(DT
) then
7508 Set_Is_Dispatch_Table_Entity
(DT
);
7509 Set_Is_Dispatch_Table_Entity
(Etype
(DT
));
7512 if Present
(Iface_DT
) then
7513 Set_Is_Dispatch_Table_Entity
(Iface_DT
);
7514 Set_Is_Dispatch_Table_Entity
(Etype
(Iface_DT
));
7517 if Is_CPP_Class
(Root_Type
(Typ
)) then
7518 Set_Ekind
(DT_Ptr
, E_Variable
);
7520 Set_Ekind
(DT_Ptr
, E_Constant
);
7523 Set_Is_Tag
(DT_Ptr
);
7524 Set_Related_Type
(DT_Ptr
, Typ
);
7533 function New_Value
(From
: Node_Id
) return Node_Id
is
7534 Res
: constant Node_Id
:= Duplicate_Subexpr
(From
);
7536 if Is_Access_Type
(Etype
(From
)) then
7538 Make_Explicit_Dereference
(Sloc
(From
),
7545 -----------------------------------
7546 -- Original_View_In_Visible_Part --
7547 -----------------------------------
7549 function Original_View_In_Visible_Part
(Typ
: Entity_Id
) return Boolean is
7550 Scop
: constant Entity_Id
:= Scope
(Typ
);
7553 -- The scope must be a package
7555 if not Is_Package_Or_Generic_Package
(Scop
) then
7559 -- A type with a private declaration has a private view declared in
7560 -- the visible part.
7562 if Has_Private_Declaration
(Typ
) then
7566 return List_Containing
(Parent
(Typ
)) =
7567 Visible_Declarations
(Specification
(Unit_Declaration_Node
(Scop
)));
7568 end Original_View_In_Visible_Part
;
7574 function Prim_Op_Kind
7576 Typ
: Entity_Id
) return Node_Id
7578 Full_Typ
: Entity_Id
:= Typ
;
7579 Loc
: constant Source_Ptr
:= Sloc
(Prim
);
7580 Prim_Op
: Entity_Id
;
7583 -- Retrieve the original primitive operation
7585 Prim_Op
:= Ultimate_Alias
(Prim
);
7587 if Ekind
(Typ
) = E_Record_Type
7588 and then Present
(Corresponding_Concurrent_Type
(Typ
))
7590 Full_Typ
:= Corresponding_Concurrent_Type
(Typ
);
7593 -- When a private tagged type is completed by a concurrent type,
7594 -- retrieve the full view.
7596 if Is_Private_Type
(Full_Typ
) then
7597 Full_Typ
:= Full_View
(Full_Typ
);
7600 if Ekind
(Prim_Op
) = E_Function
then
7602 -- Protected function
7604 if Ekind
(Full_Typ
) = E_Protected_Type
then
7605 return New_Reference_To
(RTE
(RE_POK_Protected_Function
), Loc
);
7609 elsif Ekind
(Full_Typ
) = E_Task_Type
then
7610 return New_Reference_To
(RTE
(RE_POK_Task_Function
), Loc
);
7615 return New_Reference_To
(RTE
(RE_POK_Function
), Loc
);
7619 pragma Assert
(Ekind
(Prim_Op
) = E_Procedure
);
7621 if Ekind
(Full_Typ
) = E_Protected_Type
then
7625 if Is_Primitive_Wrapper
(Prim_Op
)
7626 and then Ekind
(Wrapped_Entity
(Prim_Op
)) = E_Entry
7628 return New_Reference_To
(RTE
(RE_POK_Protected_Entry
), Loc
);
7630 -- Protected procedure
7633 return New_Reference_To
(RTE
(RE_POK_Protected_Procedure
), Loc
);
7636 elsif Ekind
(Full_Typ
) = E_Task_Type
then
7640 if Is_Primitive_Wrapper
(Prim_Op
)
7641 and then Ekind
(Wrapped_Entity
(Prim_Op
)) = E_Entry
7643 return New_Reference_To
(RTE
(RE_POK_Task_Entry
), Loc
);
7645 -- Task "procedure". These are the internally Expander-generated
7646 -- procedures (task body for instance).
7649 return New_Reference_To
(RTE
(RE_POK_Task_Procedure
), Loc
);
7652 -- Regular procedure
7655 return New_Reference_To
(RTE
(RE_POK_Procedure
), Loc
);
7660 ------------------------
7661 -- Register_Primitive --
7662 ------------------------
7664 function Register_Primitive
7666 Prim
: Entity_Id
) return List_Id
7669 Iface_Prim
: Entity_Id
;
7670 Iface_Typ
: Entity_Id
;
7671 Iface_DT_Ptr
: Entity_Id
;
7672 Iface_DT_Elmt
: Elmt_Id
;
7673 L
: constant List_Id
:= New_List
;
7676 Tag_Typ
: Entity_Id
;
7677 Thunk_Id
: Entity_Id
;
7678 Thunk_Code
: Node_Id
;
7681 pragma Assert
(not Restriction_Active
(No_Dispatching_Calls
));
7682 pragma Assert
(VM_Target
= No_VM
);
7684 -- Do not register in the dispatch table eliminated primitives
7686 if not RTE_Available
(RE_Tag
)
7687 or else Is_Eliminated
(Ultimate_Alias
(Prim
))
7692 if not Present
(Interface_Alias
(Prim
)) then
7693 Tag_Typ
:= Scope
(DTC_Entity
(Prim
));
7694 Pos
:= DT_Position
(Prim
);
7695 Tag
:= First_Tag_Component
(Tag_Typ
);
7697 if Is_Predefined_Dispatching_Operation
(Prim
)
7698 or else Is_Predefined_Dispatching_Alias
(Prim
)
7701 Node
(Next_Elmt
(First_Elmt
(Access_Disp_Table
(Tag_Typ
))));
7704 Build_Set_Predefined_Prim_Op_Address
(Loc
,
7705 Tag_Node
=> New_Reference_To
(DT_Ptr
, Loc
),
7708 Unchecked_Convert_To
(RTE
(RE_Prim_Ptr
),
7709 Make_Attribute_Reference
(Loc
,
7710 Prefix
=> New_Reference_To
(Prim
, Loc
),
7711 Attribute_Name
=> Name_Unrestricted_Access
))));
7713 -- Register copy of the pointer to the 'size primitive in the TSD
7715 if Chars
(Prim
) = Name_uSize
7716 and then RTE_Record_Component_Available
(RE_Size_Func
)
7718 DT_Ptr
:= Node
(First_Elmt
(Access_Disp_Table
(Tag_Typ
)));
7720 Build_Set_Size_Function
(Loc
,
7721 Tag_Node
=> New_Reference_To
(DT_Ptr
, Loc
),
7722 Size_Func
=> Prim
));
7726 pragma Assert
(Pos
/= Uint_0
and then Pos
<= DT_Entry_Count
(Tag
));
7728 -- Skip registration of primitives located in the C++ part of the
7729 -- dispatch table. Their slot is set by the IC routine.
7731 if not Is_CPP_Class
(Root_Type
(Tag_Typ
))
7732 or else Pos
> CPP_Num_Prims
(Tag_Typ
)
7734 DT_Ptr
:= Node
(First_Elmt
(Access_Disp_Table
(Tag_Typ
)));
7736 Build_Set_Prim_Op_Address
(Loc
,
7738 Tag_Node
=> New_Reference_To
(DT_Ptr
, Loc
),
7741 Unchecked_Convert_To
(RTE
(RE_Prim_Ptr
),
7742 Make_Attribute_Reference
(Loc
,
7743 Prefix
=> New_Reference_To
(Prim
, Loc
),
7744 Attribute_Name
=> Name_Unrestricted_Access
))));
7748 -- Ada 2005 (AI-251): Primitive associated with an interface type
7749 -- Generate the code of the thunk only if the interface type is not an
7750 -- immediate ancestor of Typ; otherwise the dispatch table associated
7751 -- with the interface is the primary dispatch table and we have nothing
7755 Tag_Typ
:= Find_Dispatching_Type
(Alias
(Prim
));
7756 Iface_Typ
:= Find_Dispatching_Type
(Interface_Alias
(Prim
));
7758 pragma Assert
(Is_Interface
(Iface_Typ
));
7760 -- No action needed for interfaces that are ancestors of Typ because
7761 -- their primitives are located in the primary dispatch table.
7763 if Is_Ancestor
(Iface_Typ
, Tag_Typ
, Use_Full_View
=> True) then
7766 -- No action needed for primitives located in the C++ part of the
7767 -- dispatch table. Their slot is set by the IC routine.
7769 elsif Is_CPP_Class
(Root_Type
(Tag_Typ
))
7770 and then DT_Position
(Alias
(Prim
)) <= CPP_Num_Prims
(Tag_Typ
)
7771 and then not Is_Predefined_Dispatching_Operation
(Prim
)
7772 and then not Is_Predefined_Dispatching_Alias
(Prim
)
7777 Expand_Interface_Thunk
(Prim
, Thunk_Id
, Thunk_Code
);
7779 if not Is_Ancestor
(Iface_Typ
, Tag_Typ
, Use_Full_View
=> True)
7780 and then Present
(Thunk_Code
)
7782 -- Generate the code necessary to fill the appropriate entry of
7783 -- the secondary dispatch table of Prim's controlling type with
7784 -- Thunk_Id's address.
7786 Iface_DT_Elmt
:= Find_Interface_ADT
(Tag_Typ
, Iface_Typ
);
7787 Iface_DT_Ptr
:= Node
(Iface_DT_Elmt
);
7788 pragma Assert
(Has_Thunks
(Iface_DT_Ptr
));
7790 Iface_Prim
:= Interface_Alias
(Prim
);
7791 Pos
:= DT_Position
(Iface_Prim
);
7792 Tag
:= First_Tag_Component
(Iface_Typ
);
7794 Prepend_To
(L
, Thunk_Code
);
7796 if Is_Predefined_Dispatching_Operation
(Prim
)
7797 or else Is_Predefined_Dispatching_Alias
(Prim
)
7800 Build_Set_Predefined_Prim_Op_Address
(Loc
,
7802 New_Reference_To
(Node
(Next_Elmt
(Iface_DT_Elmt
)), Loc
),
7805 Unchecked_Convert_To
(RTE
(RE_Prim_Ptr
),
7806 Make_Attribute_Reference
(Loc
,
7807 Prefix
=> New_Reference_To
(Thunk_Id
, Loc
),
7808 Attribute_Name
=> Name_Unrestricted_Access
))));
7810 Next_Elmt
(Iface_DT_Elmt
);
7811 Next_Elmt
(Iface_DT_Elmt
);
7812 Iface_DT_Ptr
:= Node
(Iface_DT_Elmt
);
7813 pragma Assert
(not Has_Thunks
(Iface_DT_Ptr
));
7816 Build_Set_Predefined_Prim_Op_Address
(Loc
,
7818 New_Reference_To
(Node
(Next_Elmt
(Iface_DT_Elmt
)), Loc
),
7821 Unchecked_Convert_To
(RTE
(RE_Prim_Ptr
),
7822 Make_Attribute_Reference
(Loc
,
7824 New_Reference_To
(Alias
(Prim
), Loc
),
7825 Attribute_Name
=> Name_Unrestricted_Access
))));
7828 pragma Assert
(Pos
/= Uint_0
7829 and then Pos
<= DT_Entry_Count
(Tag
));
7832 Build_Set_Prim_Op_Address
(Loc
,
7834 Tag_Node
=> New_Reference_To
(Iface_DT_Ptr
, Loc
),
7837 Unchecked_Convert_To
(RTE
(RE_Prim_Ptr
),
7838 Make_Attribute_Reference
(Loc
,
7839 Prefix
=> New_Reference_To
(Thunk_Id
, Loc
),
7840 Attribute_Name
=> Name_Unrestricted_Access
))));
7842 Next_Elmt
(Iface_DT_Elmt
);
7843 Next_Elmt
(Iface_DT_Elmt
);
7844 Iface_DT_Ptr
:= Node
(Iface_DT_Elmt
);
7845 pragma Assert
(not Has_Thunks
(Iface_DT_Ptr
));
7848 Build_Set_Prim_Op_Address
(Loc
,
7850 Tag_Node
=> New_Reference_To
(Iface_DT_Ptr
, Loc
),
7853 Unchecked_Convert_To
(RTE
(RE_Prim_Ptr
),
7854 Make_Attribute_Reference
(Loc
,
7856 New_Reference_To
(Alias
(Prim
), Loc
),
7857 Attribute_Name
=> Name_Unrestricted_Access
))));
7864 end Register_Primitive
;
7866 -------------------------
7867 -- Set_All_DT_Position --
7868 -------------------------
7870 procedure Set_All_DT_Position
(Typ
: Entity_Id
) is
7872 function In_Predef_Prims_DT
(Prim
: Entity_Id
) return Boolean;
7873 -- Returns True if Prim is located in the dispatch table of
7874 -- predefined primitives
7876 procedure Validate_Position
(Prim
: Entity_Id
);
7877 -- Check that the position assigned to Prim is completely safe
7878 -- (it has not been assigned to a previously defined primitive
7879 -- operation of Typ)
7881 ------------------------
7882 -- In_Predef_Prims_DT --
7883 ------------------------
7885 function In_Predef_Prims_DT
(Prim
: Entity_Id
) return Boolean is
7889 -- Predefined primitives
7891 if Is_Predefined_Dispatching_Operation
(Prim
) then
7894 -- Renamings of predefined primitives
7896 elsif Present
(Alias
(Prim
))
7897 and then Is_Predefined_Dispatching_Operation
(Ultimate_Alias
(Prim
))
7899 if Chars
(Ultimate_Alias
(Prim
)) /= Name_Op_Eq
then
7902 -- User-defined renamings of predefined equality have their own
7903 -- slot in the primary dispatch table
7907 while Present
(Alias
(E
)) loop
7908 if Comes_From_Source
(E
) then
7915 return not Comes_From_Source
(E
);
7918 -- User-defined primitives
7923 end In_Predef_Prims_DT
;
7925 -----------------------
7926 -- Validate_Position --
7927 -----------------------
7929 procedure Validate_Position
(Prim
: Entity_Id
) is
7934 -- Aliased primitives are safe
7936 if Present
(Alias
(Prim
)) then
7940 Op_Elmt
:= First_Elmt
(Primitive_Operations
(Typ
));
7941 while Present
(Op_Elmt
) loop
7942 Op
:= Node
(Op_Elmt
);
7944 -- No need to check against itself
7949 -- Primitive operations covering abstract interfaces are
7952 elsif Present
(Interface_Alias
(Op
)) then
7955 -- Predefined dispatching operations are completely safe. They
7956 -- are allocated at fixed positions in a separate table.
7958 elsif Is_Predefined_Dispatching_Operation
(Op
)
7959 or else Is_Predefined_Dispatching_Alias
(Op
)
7963 -- Aliased subprograms are safe
7965 elsif Present
(Alias
(Op
)) then
7968 elsif DT_Position
(Op
) = DT_Position
(Prim
)
7969 and then not Is_Predefined_Dispatching_Operation
(Op
)
7970 and then not Is_Predefined_Dispatching_Operation
(Prim
)
7971 and then not Is_Predefined_Dispatching_Alias
(Op
)
7972 and then not Is_Predefined_Dispatching_Alias
(Prim
)
7975 -- Handle aliased subprograms
7984 if Present
(Overridden_Operation
(Op_1
)) then
7985 Op_1
:= Overridden_Operation
(Op_1
);
7986 elsif Present
(Alias
(Op_1
)) then
7987 Op_1
:= Alias
(Op_1
);
7995 if Present
(Overridden_Operation
(Op_2
)) then
7996 Op_2
:= Overridden_Operation
(Op_2
);
7997 elsif Present
(Alias
(Op_2
)) then
7998 Op_2
:= Alias
(Op_2
);
8004 if Op_1
/= Op_2
then
8005 raise Program_Error
;
8010 Next_Elmt
(Op_Elmt
);
8012 end Validate_Position
;
8016 Parent_Typ
: constant Entity_Id
:= Etype
(Typ
);
8017 First_Prim
: constant Elmt_Id
:= First_Elmt
(Primitive_Operations
(Typ
));
8018 The_Tag
: constant Entity_Id
:= First_Tag_Component
(Typ
);
8020 Adjusted
: Boolean := False;
8021 Finalized
: Boolean := False;
8027 Prim_Elmt
: Elmt_Id
;
8029 -- Start of processing for Set_All_DT_Position
8032 pragma Assert
(Present
(First_Tag_Component
(Typ
)));
8034 -- Set the DT_Position for each primitive operation. Perform some sanity
8035 -- checks to avoid building inconsistent dispatch tables.
8037 -- First stage: Set the DTC entity of all the primitive operations. This
8038 -- is required to properly read the DT_Position attribute in the latter
8041 Prim_Elmt
:= First_Prim
;
8043 while Present
(Prim_Elmt
) loop
8044 Prim
:= Node
(Prim_Elmt
);
8046 -- Predefined primitives have a separate dispatch table
8048 if not In_Predef_Prims_DT
(Prim
) then
8049 Count_Prim
:= Count_Prim
+ 1;
8052 Set_DTC_Entity_Value
(Typ
, Prim
);
8054 -- Clear any previous value of the DT_Position attribute. In this
8055 -- way we ensure that the final position of all the primitives is
8056 -- established by the following stages of this algorithm.
8058 Set_DT_Position
(Prim
, No_Uint
);
8060 Next_Elmt
(Prim_Elmt
);
8064 Fixed_Prim
: array (Int
range 0 .. Count_Prim
) of Boolean :=
8069 procedure Handle_Inherited_Private_Subprograms
(Typ
: Entity_Id
);
8070 -- Called if Typ is declared in a nested package or a public child
8071 -- package to handle inherited primitives that were inherited by Typ
8072 -- in the visible part, but whose declaration was deferred because
8073 -- the parent operation was private and not visible at that point.
8075 procedure Set_Fixed_Prim
(Pos
: Nat
);
8076 -- Sets to true an element of the Fixed_Prim table to indicate
8077 -- that this entry of the dispatch table of Typ is occupied.
8079 ------------------------------------------
8080 -- Handle_Inherited_Private_Subprograms --
8081 ------------------------------------------
8083 procedure Handle_Inherited_Private_Subprograms
(Typ
: Entity_Id
) is
8086 Op_Elmt_2
: Elmt_Id
;
8087 Prim_Op
: Entity_Id
;
8088 Parent_Subp
: Entity_Id
;
8091 Op_List
:= Primitive_Operations
(Typ
);
8093 Op_Elmt
:= First_Elmt
(Op_List
);
8094 while Present
(Op_Elmt
) loop
8095 Prim_Op
:= Node
(Op_Elmt
);
8097 -- Search primitives that are implicit operations with an
8098 -- internal name whose parent operation has a normal name.
8100 if Present
(Alias
(Prim_Op
))
8101 and then Find_Dispatching_Type
(Alias
(Prim_Op
)) /= Typ
8102 and then not Comes_From_Source
(Prim_Op
)
8103 and then Is_Internal_Name
(Chars
(Prim_Op
))
8104 and then not Is_Internal_Name
(Chars
(Alias
(Prim_Op
)))
8106 Parent_Subp
:= Alias
(Prim_Op
);
8108 -- Check if the type has an explicit overriding for this
8111 Op_Elmt_2
:= Next_Elmt
(Op_Elmt
);
8112 while Present
(Op_Elmt_2
) loop
8113 if Chars
(Node
(Op_Elmt_2
)) = Chars
(Parent_Subp
)
8114 and then Type_Conformant
(Prim_Op
, Node
(Op_Elmt_2
))
8116 Set_DT_Position
(Prim_Op
, DT_Position
(Parent_Subp
));
8117 Set_DT_Position
(Node
(Op_Elmt_2
),
8118 DT_Position
(Parent_Subp
));
8119 Set_Fixed_Prim
(UI_To_Int
(DT_Position
(Prim_Op
)));
8121 goto Next_Primitive
;
8124 Next_Elmt
(Op_Elmt_2
);
8129 Next_Elmt
(Op_Elmt
);
8131 end Handle_Inherited_Private_Subprograms
;
8133 --------------------
8134 -- Set_Fixed_Prim --
8135 --------------------
8137 procedure Set_Fixed_Prim
(Pos
: Nat
) is
8139 pragma Assert
(Pos
<= Count_Prim
);
8140 Fixed_Prim
(Pos
) := True;
8142 when Constraint_Error
=>
8143 raise Program_Error
;
8147 -- In case of nested packages and public child package it may be
8148 -- necessary a special management on inherited subprograms so that
8149 -- the dispatch table is properly filled.
8151 if Ekind
(Scope
(Scope
(Typ
))) = E_Package
8152 and then Scope
(Scope
(Typ
)) /= Standard_Standard
8153 and then ((Is_Derived_Type
(Typ
) and then not Is_Private_Type
(Typ
))
8155 (Nkind
(Parent
(Typ
)) = N_Private_Extension_Declaration
8156 and then Is_Generic_Type
(Typ
)))
8157 and then In_Open_Scopes
(Scope
(Etype
(Typ
)))
8158 and then Is_Base_Type
(Typ
)
8160 Handle_Inherited_Private_Subprograms
(Typ
);
8163 -- Second stage: Register fixed entries
8166 Prim_Elmt
:= First_Prim
;
8167 while Present
(Prim_Elmt
) loop
8168 Prim
:= Node
(Prim_Elmt
);
8170 -- Predefined primitives have a separate table and all its
8171 -- entries are at predefined fixed positions.
8173 if In_Predef_Prims_DT
(Prim
) then
8174 if Is_Predefined_Dispatching_Operation
(Prim
) then
8175 Set_DT_Position
(Prim
, Default_Prim_Op_Position
(Prim
));
8177 else pragma Assert
(Present
(Alias
(Prim
)));
8178 Set_DT_Position
(Prim
,
8179 Default_Prim_Op_Position
(Ultimate_Alias
(Prim
)));
8182 -- Overriding primitives of ancestor abstract interfaces
8184 elsif Present
(Interface_Alias
(Prim
))
8185 and then Is_Ancestor
8186 (Find_Dispatching_Type
(Interface_Alias
(Prim
)), Typ
,
8187 Use_Full_View
=> True)
8189 pragma Assert
(DT_Position
(Prim
) = No_Uint
8190 and then Present
(DTC_Entity
(Interface_Alias
(Prim
))));
8192 E
:= Interface_Alias
(Prim
);
8193 Set_DT_Position
(Prim
, DT_Position
(E
));
8196 (DT_Position
(Alias
(Prim
)) = No_Uint
8197 or else DT_Position
(Alias
(Prim
)) = DT_Position
(E
));
8198 Set_DT_Position
(Alias
(Prim
), DT_Position
(E
));
8199 Set_Fixed_Prim
(UI_To_Int
(DT_Position
(Prim
)));
8201 -- Overriding primitives must use the same entry as the
8202 -- overridden primitive.
8204 elsif not Present
(Interface_Alias
(Prim
))
8205 and then Present
(Alias
(Prim
))
8206 and then Chars
(Prim
) = Chars
(Alias
(Prim
))
8207 and then Find_Dispatching_Type
(Alias
(Prim
)) /= Typ
8208 and then Is_Ancestor
8209 (Find_Dispatching_Type
(Alias
(Prim
)), Typ
,
8210 Use_Full_View
=> True)
8211 and then Present
(DTC_Entity
(Alias
(Prim
)))
8214 Set_DT_Position
(Prim
, DT_Position
(E
));
8216 if not Is_Predefined_Dispatching_Alias
(E
) then
8217 Set_Fixed_Prim
(UI_To_Int
(DT_Position
(E
)));
8221 Next_Elmt
(Prim_Elmt
);
8224 -- Third stage: Fix the position of all the new primitives.
8225 -- Entries associated with primitives covering interfaces
8226 -- are handled in a latter round.
8228 Prim_Elmt
:= First_Prim
;
8229 while Present
(Prim_Elmt
) loop
8230 Prim
:= Node
(Prim_Elmt
);
8232 -- Skip primitives previously set entries
8234 if DT_Position
(Prim
) /= No_Uint
then
8237 -- Primitives covering interface primitives are handled later
8239 elsif Present
(Interface_Alias
(Prim
)) then
8243 -- Take the next available position in the DT
8246 Nb_Prim
:= Nb_Prim
+ 1;
8247 pragma Assert
(Nb_Prim
<= Count_Prim
);
8248 exit when not Fixed_Prim
(Nb_Prim
);
8251 Set_DT_Position
(Prim
, UI_From_Int
(Nb_Prim
));
8252 Set_Fixed_Prim
(Nb_Prim
);
8255 Next_Elmt
(Prim_Elmt
);
8259 -- Fourth stage: Complete the decoration of primitives covering
8260 -- interfaces (that is, propagate the DT_Position attribute
8261 -- from the aliased primitive)
8263 Prim_Elmt
:= First_Prim
;
8264 while Present
(Prim_Elmt
) loop
8265 Prim
:= Node
(Prim_Elmt
);
8267 if DT_Position
(Prim
) = No_Uint
8268 and then Present
(Interface_Alias
(Prim
))
8270 pragma Assert
(Present
(Alias
(Prim
))
8271 and then Find_Dispatching_Type
(Alias
(Prim
)) = Typ
);
8273 -- Check if this entry will be placed in the primary DT
8276 (Find_Dispatching_Type
(Interface_Alias
(Prim
)), Typ
,
8277 Use_Full_View
=> True)
8279 pragma Assert
(DT_Position
(Alias
(Prim
)) /= No_Uint
);
8280 Set_DT_Position
(Prim
, DT_Position
(Alias
(Prim
)));
8282 -- Otherwise it will be placed in the secondary DT
8286 (DT_Position
(Interface_Alias
(Prim
)) /= No_Uint
);
8287 Set_DT_Position
(Prim
,
8288 DT_Position
(Interface_Alias
(Prim
)));
8292 Next_Elmt
(Prim_Elmt
);
8295 -- Generate listing showing the contents of the dispatch tables.
8296 -- This action is done before some further static checks because
8297 -- in case of critical errors caused by a wrong dispatch table
8298 -- we need to see the contents of such table.
8300 if Debug_Flag_ZZ
then
8304 -- Final stage: Ensure that the table is correct plus some further
8305 -- verifications concerning the primitives.
8307 Prim_Elmt
:= First_Prim
;
8309 while Present
(Prim_Elmt
) loop
8310 Prim
:= Node
(Prim_Elmt
);
8312 -- At this point all the primitives MUST have a position
8313 -- in the dispatch table.
8315 if DT_Position
(Prim
) = No_Uint
then
8316 raise Program_Error
;
8319 -- Calculate real size of the dispatch table
8321 if not In_Predef_Prims_DT
(Prim
)
8322 and then UI_To_Int
(DT_Position
(Prim
)) > DT_Length
8324 DT_Length
:= UI_To_Int
(DT_Position
(Prim
));
8327 -- Ensure that the assigned position to non-predefined
8328 -- dispatching operations in the dispatch table is correct.
8330 if not Is_Predefined_Dispatching_Operation
(Prim
)
8331 and then not Is_Predefined_Dispatching_Alias
(Prim
)
8333 Validate_Position
(Prim
);
8336 if Chars
(Prim
) = Name_Finalize
then
8340 if Chars
(Prim
) = Name_Adjust
then
8344 -- An abstract operation cannot be declared in the private part for a
8345 -- visible abstract type, because it can't be overridden outside this
8346 -- package hierarchy. For explicit declarations this is checked at
8347 -- the point of declaration, but for inherited operations it must be
8348 -- done when building the dispatch table.
8350 -- Ada 2005 (AI-251): Primitives associated with interfaces are
8351 -- excluded from this check because interfaces must be visible in
8352 -- the public and private part (RM 7.3 (7.3/2))
8354 -- We disable this check in CodePeer mode, to accommodate legacy
8357 if not CodePeer_Mode
8358 and then Is_Abstract_Type
(Typ
)
8359 and then Is_Abstract_Subprogram
(Prim
)
8360 and then Present
(Alias
(Prim
))
8361 and then not Is_Interface
8362 (Find_Dispatching_Type
(Ultimate_Alias
(Prim
)))
8363 and then not Present
(Interface_Alias
(Prim
))
8364 and then Is_Derived_Type
(Typ
)
8365 and then In_Private_Part
(Current_Scope
)
8367 List_Containing
(Parent
(Prim
)) =
8368 Private_Declarations
8369 (Specification
(Unit_Declaration_Node
(Current_Scope
)))
8370 and then Original_View_In_Visible_Part
(Typ
)
8372 -- We exclude Input and Output stream operations because
8373 -- Limited_Controlled inherits useless Input and Output
8374 -- stream operations from Root_Controlled, which can
8375 -- never be overridden.
8377 if not Is_TSS
(Prim
, TSS_Stream_Input
)
8379 not Is_TSS
(Prim
, TSS_Stream_Output
)
8382 ("abstract inherited private operation&" &
8383 " must be overridden (RM 3.9.3(10))",
8384 Parent
(Typ
), Prim
);
8388 Next_Elmt
(Prim_Elmt
);
8393 if Is_Controlled
(Typ
) then
8394 if not Finalized
then
8396 ("controlled type has no explicit Finalize method?", Typ
);
8398 elsif not Adjusted
then
8400 ("controlled type has no explicit Adjust method?", Typ
);
8404 -- Set the final size of the Dispatch Table
8406 Set_DT_Entry_Count
(The_Tag
, UI_From_Int
(DT_Length
));
8408 -- The derived type must have at least as many components as its parent
8409 -- (for root types Etype points to itself and the test cannot fail).
8411 if DT_Entry_Count
(The_Tag
) <
8412 DT_Entry_Count
(First_Tag_Component
(Parent_Typ
))
8414 raise Program_Error
;
8416 end Set_All_DT_Position
;
8418 --------------------------
8419 -- Set_CPP_Constructors --
8420 --------------------------
8422 procedure Set_CPP_Constructors
(Typ
: Entity_Id
) is
8424 procedure Set_CPP_Constructors_Old
(Typ
: Entity_Id
);
8425 -- For backward compatibility this routine handles CPP constructors
8426 -- of non-tagged types.
8428 procedure Set_CPP_Constructors_Old
(Typ
: Entity_Id
) is
8432 Found
: Boolean := False;
8437 -- Look for the constructor entities
8439 E
:= Next_Entity
(Typ
);
8440 while Present
(E
) loop
8441 if Ekind
(E
) = E_Function
8442 and then Is_Constructor
(E
)
8444 -- Create the init procedure
8448 Init
:= Make_Defining_Identifier
(Loc
,
8449 Make_Init_Proc_Name
(Typ
));
8452 Make_Parameter_Specification
(Loc
,
8453 Defining_Identifier
=>
8454 Make_Defining_Identifier
(Loc
, Name_X
),
8456 New_Reference_To
(Typ
, Loc
)));
8458 if Present
(Parameter_Specifications
(Parent
(E
))) then
8459 P
:= First
(Parameter_Specifications
(Parent
(E
)));
8460 while Present
(P
) loop
8462 Make_Parameter_Specification
(Loc
,
8463 Defining_Identifier
=>
8464 Make_Defining_Identifier
(Loc
,
8465 Chars
(Defining_Identifier
(P
))),
8467 New_Copy_Tree
(Parameter_Type
(P
))));
8473 Make_Subprogram_Declaration
(Loc
,
8474 Make_Procedure_Specification
(Loc
,
8475 Defining_Unit_Name
=> Init
,
8476 Parameter_Specifications
=> Parms
)));
8478 Set_Init_Proc
(Typ
, Init
);
8479 Set_Is_Imported
(Init
);
8480 Set_Is_Constructor
(Init
);
8481 Set_Interface_Name
(Init
, Interface_Name
(E
));
8482 Set_Convention
(Init
, Convention_CPP
);
8483 Set_Is_Public
(Init
);
8484 Set_Has_Completion
(Init
);
8490 -- If there are no constructors, mark the type as abstract since we
8491 -- won't be able to declare objects of that type.
8494 Set_Is_Abstract_Type
(Typ
);
8496 end Set_CPP_Constructors_Old
;
8502 Found
: Boolean := False;
8506 Constructor_Decl_Node
: Node_Id
;
8507 Constructor_Id
: Entity_Id
;
8508 Wrapper_Id
: Entity_Id
;
8509 Wrapper_Body_Node
: Node_Id
;
8511 Body_Stmts
: List_Id
;
8512 Init_Tags_List
: List_Id
;
8515 pragma Assert
(Is_CPP_Class
(Typ
));
8517 -- For backward compatibility the compiler accepts C++ classes
8518 -- imported through non-tagged record types. In such case the
8519 -- wrapper of the C++ constructor is useless because the _tag
8520 -- component is not available.
8523 -- type Root is limited record ...
8524 -- pragma Import (CPP, Root);
8525 -- function New_Root return Root;
8526 -- pragma CPP_Constructor (New_Root, ... );
8528 if not Is_Tagged_Type
(Typ
) then
8529 Set_CPP_Constructors_Old
(Typ
);
8533 -- Look for the constructor entities
8535 E
:= Next_Entity
(Typ
);
8536 while Present
(E
) loop
8537 if Ekind
(E
) = E_Function
8538 and then Is_Constructor
(E
)
8543 -- Generate the declaration of the imported C++ constructor
8547 Make_Parameter_Specification
(Loc
,
8548 Defining_Identifier
=>
8549 Make_Defining_Identifier
(Loc
, Name_uInit
),
8551 New_Reference_To
(Typ
, Loc
)));
8553 if Present
(Parameter_Specifications
(Parent
(E
))) then
8554 P
:= First
(Parameter_Specifications
(Parent
(E
)));
8555 while Present
(P
) loop
8557 Make_Parameter_Specification
(Loc
,
8558 Defining_Identifier
=>
8559 Make_Defining_Identifier
(Loc
,
8560 Chars
(Defining_Identifier
(P
))),
8561 Parameter_Type
=> New_Copy_Tree
(Parameter_Type
(P
))));
8566 Constructor_Id
:= Make_Temporary
(Loc
, 'P');
8568 Constructor_Decl_Node
:=
8569 Make_Subprogram_Declaration
(Loc
,
8570 Make_Procedure_Specification
(Loc
,
8571 Defining_Unit_Name
=> Constructor_Id
,
8572 Parameter_Specifications
=> Parms
));
8574 Set_Is_Imported
(Constructor_Id
);
8575 Set_Is_Constructor
(Constructor_Id
);
8576 Set_Interface_Name
(Constructor_Id
, Interface_Name
(E
));
8577 Set_Convention
(Constructor_Id
, Convention_CPP
);
8578 Set_Is_Public
(Constructor_Id
);
8579 Set_Has_Completion
(Constructor_Id
);
8581 -- Build the wrapper of this constructor
8585 Make_Parameter_Specification
(Loc
,
8586 Defining_Identifier
=>
8587 Make_Defining_Identifier
(Loc
, Name_uInit
),
8589 New_Reference_To
(Typ
, Loc
)));
8591 if Present
(Parameter_Specifications
(Parent
(E
))) then
8592 P
:= First
(Parameter_Specifications
(Parent
(E
)));
8593 while Present
(P
) loop
8595 Make_Parameter_Specification
(Loc
,
8596 Defining_Identifier
=>
8597 Make_Defining_Identifier
(Loc
,
8598 Chars
(Defining_Identifier
(P
))),
8599 Parameter_Type
=> New_Copy_Tree
(Parameter_Type
(P
))));
8604 Body_Stmts
:= New_List
;
8606 -- Invoke the C++ constructor
8608 Actuals
:= New_List
;
8611 while Present
(P
) loop
8613 New_Reference_To
(Defining_Identifier
(P
), Loc
));
8617 Append_To
(Body_Stmts
,
8618 Make_Procedure_Call_Statement
(Loc
,
8619 Name
=> New_Reference_To
(Constructor_Id
, Loc
),
8620 Parameter_Associations
=> Actuals
));
8622 -- Initialize copies of C++ primary and secondary tags
8624 Init_Tags_List
:= New_List
;
8631 Tag_Elmt
:= First_Elmt
(Access_Disp_Table
(Typ
));
8632 Tag_Comp
:= First_Tag_Component
(Typ
);
8634 while Present
(Tag_Elmt
)
8635 and then Is_Tag
(Node
(Tag_Elmt
))
8637 -- Skip the following assertion with primary tags because
8638 -- Related_Type is not set on primary tag components
8640 pragma Assert
(Tag_Comp
= First_Tag_Component
(Typ
)
8641 or else Related_Type
(Node
(Tag_Elmt
))
8642 = Related_Type
(Tag_Comp
));
8644 Append_To
(Init_Tags_List
,
8645 Make_Assignment_Statement
(Loc
,
8647 New_Reference_To
(Node
(Tag_Elmt
), Loc
),
8649 Make_Selected_Component
(Loc
,
8651 Make_Identifier
(Loc
, Name_uInit
),
8653 New_Reference_To
(Tag_Comp
, Loc
))));
8655 Tag_Comp
:= Next_Tag_Component
(Tag_Comp
);
8656 Next_Elmt
(Tag_Elmt
);
8660 Append_To
(Body_Stmts
,
8661 Make_If_Statement
(Loc
,
8666 (Node
(First_Elmt
(Access_Disp_Table
(Typ
))),
8669 Unchecked_Convert_To
(RTE
(RE_Tag
),
8670 New_Reference_To
(RTE
(RE_Null_Address
), Loc
))),
8671 Then_Statements
=> Init_Tags_List
));
8673 Wrapper_Id
:= Make_Defining_Identifier
(Loc
,
8674 Make_Init_Proc_Name
(Typ
));
8676 Wrapper_Body_Node
:=
8677 Make_Subprogram_Body
(Loc
,
8679 Make_Procedure_Specification
(Loc
,
8680 Defining_Unit_Name
=> Wrapper_Id
,
8681 Parameter_Specifications
=> Parms
),
8682 Declarations
=> New_List
(Constructor_Decl_Node
),
8683 Handled_Statement_Sequence
=>
8684 Make_Handled_Sequence_Of_Statements
(Loc
,
8685 Statements
=> Body_Stmts
,
8686 Exception_Handlers
=> No_List
));
8688 Discard_Node
(Wrapper_Body_Node
);
8689 Set_Init_Proc
(Typ
, Wrapper_Id
);
8695 -- If there are no constructors, mark the type as abstract since we
8696 -- won't be able to declare objects of that type.
8699 Set_Is_Abstract_Type
(Typ
);
8702 -- If the CPP type has constructors then it must import also the default
8703 -- C++ constructor. It is required for default initialization of objects
8704 -- of the type. It is also required to elaborate objects of Ada types
8705 -- that are defined as derivations of this CPP type.
8707 if Has_CPP_Constructors
(Typ
)
8708 and then No
(Init_Proc
(Typ
))
8710 Error_Msg_N
("?default constructor must be imported from C++", Typ
);
8712 end Set_CPP_Constructors
;
8714 --------------------------
8715 -- Set_DTC_Entity_Value --
8716 --------------------------
8718 procedure Set_DTC_Entity_Value
8719 (Tagged_Type
: Entity_Id
;
8723 if Present
(Interface_Alias
(Prim
))
8724 and then Is_Interface
8725 (Find_Dispatching_Type
(Interface_Alias
(Prim
)))
8727 Set_DTC_Entity
(Prim
,
8730 Iface
=> Find_Dispatching_Type
(Interface_Alias
(Prim
))));
8732 Set_DTC_Entity
(Prim
,
8733 First_Tag_Component
(Tagged_Type
));
8735 end Set_DTC_Entity_Value
;
8741 function Tagged_Kind
(T
: Entity_Id
) return Node_Id
is
8742 Conc_Typ
: Entity_Id
;
8743 Loc
: constant Source_Ptr
:= Sloc
(T
);
8747 (Is_Tagged_Type
(T
) and then RTE_Available
(RE_Tagged_Kind
));
8751 if Is_Abstract_Type
(T
) then
8752 if Is_Limited_Record
(T
) then
8753 return New_Reference_To
(RTE
(RE_TK_Abstract_Limited_Tagged
), Loc
);
8755 return New_Reference_To
(RTE
(RE_TK_Abstract_Tagged
), Loc
);
8760 elsif Is_Concurrent_Record_Type
(T
) then
8761 Conc_Typ
:= Corresponding_Concurrent_Type
(T
);
8763 if Present
(Full_View
(Conc_Typ
)) then
8764 Conc_Typ
:= Full_View
(Conc_Typ
);
8767 if Ekind
(Conc_Typ
) = E_Protected_Type
then
8768 return New_Reference_To
(RTE
(RE_TK_Protected
), Loc
);
8770 pragma Assert
(Ekind
(Conc_Typ
) = E_Task_Type
);
8771 return New_Reference_To
(RTE
(RE_TK_Task
), Loc
);
8774 -- Regular tagged kinds
8777 if Is_Limited_Record
(T
) then
8778 return New_Reference_To
(RTE
(RE_TK_Limited_Tagged
), Loc
);
8780 return New_Reference_To
(RTE
(RE_TK_Tagged
), Loc
);
8789 procedure Write_DT
(Typ
: Entity_Id
) is
8794 -- Protect this procedure against wrong usage. Required because it will
8795 -- be used directly from GDB
8797 if not (Typ
<= Last_Node_Id
)
8798 or else not Is_Tagged_Type
(Typ
)
8800 Write_Str
("wrong usage: Write_DT must be used with tagged types");
8805 Write_Int
(Int
(Typ
));
8807 Write_Name
(Chars
(Typ
));
8809 if Is_Interface
(Typ
) then
8810 Write_Str
(" is interface");
8815 Elmt
:= First_Elmt
(Primitive_Operations
(Typ
));
8816 while Present
(Elmt
) loop
8817 Prim
:= Node
(Elmt
);
8820 -- Indicate if this primitive will be allocated in the primary
8821 -- dispatch table or in a secondary dispatch table associated
8822 -- with an abstract interface type
8824 if Present
(DTC_Entity
(Prim
)) then
8825 if Etype
(DTC_Entity
(Prim
)) = RTE
(RE_Tag
) then
8832 -- Output the node of this primitive operation and its name
8834 Write_Int
(Int
(Prim
));
8837 if Is_Predefined_Dispatching_Operation
(Prim
) then
8838 Write_Str
("(predefined) ");
8841 -- Prefix the name of the primitive with its corresponding tagged
8842 -- type to facilitate seeing inherited primitives.
8844 if Present
(Alias
(Prim
)) then
8846 (Chars
(Find_Dispatching_Type
(Ultimate_Alias
(Prim
))));
8848 Write_Name
(Chars
(Typ
));
8852 Write_Name
(Chars
(Prim
));
8854 -- Indicate if this primitive has an aliased primitive
8856 if Present
(Alias
(Prim
)) then
8857 Write_Str
(" (alias = ");
8858 Write_Int
(Int
(Alias
(Prim
)));
8860 -- If the DTC_Entity attribute is already set we can also output
8861 -- the name of the interface covered by this primitive (if any).
8863 if Ekind_In
(Alias
(Prim
), E_Function
, E_Procedure
)
8864 and then Present
(DTC_Entity
(Alias
(Prim
)))
8865 and then Is_Interface
(Scope
(DTC_Entity
(Alias
(Prim
))))
8867 Write_Str
(" from interface ");
8868 Write_Name
(Chars
(Scope
(DTC_Entity
(Alias
(Prim
)))));
8871 if Present
(Interface_Alias
(Prim
)) then
8872 Write_Str
(", AI_Alias of ");
8874 if Is_Null_Interface_Primitive
(Interface_Alias
(Prim
)) then
8875 Write_Str
("null primitive ");
8879 (Chars
(Find_Dispatching_Type
(Interface_Alias
(Prim
))));
8881 Write_Int
(Int
(Interface_Alias
(Prim
)));
8887 -- Display the final position of this primitive in its associated
8888 -- (primary or secondary) dispatch table
8890 if Present
(DTC_Entity
(Prim
))
8891 and then DT_Position
(Prim
) /= No_Uint
8893 Write_Str
(" at #");
8894 Write_Int
(UI_To_Int
(DT_Position
(Prim
)));
8897 if Is_Abstract_Subprogram
(Prim
) then
8898 Write_Str
(" is abstract;");
8900 -- Check if this is a null primitive
8902 elsif Comes_From_Source
(Prim
)
8903 and then Ekind
(Prim
) = E_Procedure
8904 and then Null_Present
(Parent
(Prim
))
8906 Write_Str
(" is null;");
8909 if Is_Eliminated
(Ultimate_Alias
(Prim
)) then
8910 Write_Str
(" (eliminated)");
8913 if Is_Imported
(Prim
)
8914 and then Convention
(Prim
) = Convention_CPP
8916 Write_Str
(" (C++)");