1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2013, 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
)
707 -- No action needed if the dispatching call has been already expanded
709 or else Is_Expanded_Dispatching_Call
(Name
(Call_Node
))
714 -- Set subprogram. If this is an inherited operation that was
715 -- overridden, the body that is being called is its alias.
717 Subp
:= Entity
(Name
(Call_Node
));
719 if Present
(Alias
(Subp
))
720 and then Is_Inherited_Operation
(Subp
)
721 and then No
(DTC_Entity
(Subp
))
723 Subp
:= Alias
(Subp
);
726 -- Definition of the class-wide type and the tagged type
728 -- If the controlling argument is itself a tag rather than a tagged
729 -- object, then use the class-wide type associated with the subprogram's
730 -- controlling type. This case can occur when a call to an inherited
731 -- primitive has an actual that originated from a default parameter
732 -- given by a tag-indeterminate call and when there is no other
733 -- controlling argument providing the tag (AI-239 requires dispatching).
734 -- This capability of dispatching directly by tag is also needed by the
735 -- implementation of AI-260 (for the generic dispatching constructors).
737 if Ctrl_Typ
= RTE
(RE_Tag
)
738 or else (RTE_Available
(RE_Interface_Tag
)
739 and then Ctrl_Typ
= RTE
(RE_Interface_Tag
))
741 CW_Typ
:= Class_Wide_Type
(Find_Dispatching_Type
(Subp
));
743 -- Class_Wide_Type is applied to the expressions used to initialize
744 -- CW_Typ, to ensure that CW_Typ always denotes a class-wide type, since
745 -- there are cases where the controlling type is resolved to a specific
746 -- type (such as for designated types of arguments such as CW'Access).
748 elsif Is_Access_Type
(Ctrl_Typ
) then
749 CW_Typ
:= Class_Wide_Type
(Designated_Type
(Ctrl_Typ
));
752 CW_Typ
:= Class_Wide_Type
(Ctrl_Typ
);
755 Typ
:= Find_Specific_Type
(CW_Typ
);
757 if not Is_Limited_Type
(Typ
) then
758 Eq_Prim_Op
:= Find_Prim_Op
(Typ
, Name_Op_Eq
);
761 -- Dispatching call to C++ primitive. Create a new parameter list
762 -- with no tag checks.
764 New_Params
:= New_List
;
766 if Is_CPP_Class
(Typ
) then
767 Param
:= First_Actual
(Call_Node
);
768 while Present
(Param
) loop
769 Append_To
(New_Params
, Relocate_Node
(Param
));
773 -- Dispatching call to Ada primitive
775 elsif Present
(Param_List
) then
776 Apply_Tag_Checks
(Call_Node
);
778 Param
:= First_Actual
(Call_Node
);
779 while Present
(Param
) loop
780 -- Cases in which we may have generated runtime checks
783 or else Subp
= Eq_Prim_Op
785 Append_To
(New_Params
,
786 Duplicate_Subexpr_Move_Checks
(Param
));
788 elsif Nkind
(Parent
(Param
)) /= N_Parameter_Association
789 or else not Is_Accessibility_Actual
(Parent
(Param
))
791 Append_To
(New_Params
, Relocate_Node
(Param
));
798 -- Generate the appropriate subprogram pointer type
800 if Etype
(Subp
) = Typ
then
803 Res_Typ
:= Etype
(Subp
);
806 Subp_Typ
:= Create_Itype
(E_Subprogram_Type
, Call_Node
);
807 Subp_Ptr_Typ
:= Create_Itype
(E_Access_Subprogram_Type
, Call_Node
);
808 Set_Etype
(Subp_Typ
, Res_Typ
);
809 Set_Returns_By_Ref
(Subp_Typ
, Returns_By_Ref
(Subp
));
810 Set_Convention
(Subp_Typ
, Convention
(Subp
));
812 -- Notify gigi that the designated type is a dispatching primitive
814 Set_Is_Dispatch_Table_Entity
(Subp_Typ
);
816 -- Create a new list of parameters which is a copy of the old formal
817 -- list including the creation of a new set of matching entities.
820 Old_Formal
: Entity_Id
:= First_Formal
(Subp
);
821 New_Formal
: Entity_Id
;
822 Extra
: Entity_Id
:= Empty
;
825 if Present
(Old_Formal
) then
826 New_Formal
:= New_Copy
(Old_Formal
);
827 Set_First_Entity
(Subp_Typ
, New_Formal
);
828 Param
:= First_Actual
(Call_Node
);
831 Set_Scope
(New_Formal
, Subp_Typ
);
833 -- Change all the controlling argument types to be class-wide
834 -- to avoid a recursion in dispatching.
836 if Is_Controlling_Formal
(New_Formal
) then
837 Set_Etype
(New_Formal
, Etype
(Param
));
840 -- If the type of the formal is an itype, there was code here
841 -- introduced in 1998 in revision 1.46, to create a new itype
842 -- by copy. This seems useless, and in fact leads to semantic
843 -- errors when the itype is the completion of a type derived
844 -- from a private type.
847 Next_Formal
(Old_Formal
);
848 exit when No
(Old_Formal
);
850 Set_Next_Entity
(New_Formal
, New_Copy
(Old_Formal
));
851 Next_Entity
(New_Formal
);
855 Set_Next_Entity
(New_Formal
, Empty
);
856 Set_Last_Entity
(Subp_Typ
, Extra
);
859 -- Now that the explicit formals have been duplicated, any extra
860 -- formals needed by the subprogram must be created.
862 if Present
(Extra
) then
863 Set_Extra_Formal
(Extra
, Empty
);
866 Create_Extra_Formals
(Subp_Typ
);
869 -- Complete description of pointer type, including size information, as
870 -- must be done with itypes to prevent order-of-elaboration anomalies
873 Set_Etype
(Subp_Ptr_Typ
, Subp_Ptr_Typ
);
874 Set_Directly_Designated_Type
(Subp_Ptr_Typ
, Subp_Typ
);
875 Set_Convention
(Subp_Ptr_Typ
, Convention
(Subp_Typ
));
876 Layout_Type
(Subp_Ptr_Typ
);
878 -- If the controlling argument is a value of type Ada.Tag or an abstract
879 -- interface class-wide type then use it directly. Otherwise, the tag
880 -- must be extracted from the controlling object.
882 if Ctrl_Typ
= RTE
(RE_Tag
)
883 or else (RTE_Available
(RE_Interface_Tag
)
884 and then Ctrl_Typ
= RTE
(RE_Interface_Tag
))
886 Controlling_Tag
:= Duplicate_Subexpr
(Ctrl_Arg
);
888 -- Extract the tag from an unchecked type conversion. Done to avoid
889 -- the expansion of additional code just to obtain the value of such
890 -- tag because the current management of interface type conversions
891 -- generates in some cases this unchecked type conversion with the
892 -- tag of the object (see Expand_Interface_Conversion).
894 elsif Nkind
(Ctrl_Arg
) = N_Unchecked_Type_Conversion
896 (Etype
(Expression
(Ctrl_Arg
)) = RTE
(RE_Tag
)
898 (RTE_Available
(RE_Interface_Tag
)
900 Etype
(Expression
(Ctrl_Arg
)) = RTE
(RE_Interface_Tag
)))
902 Controlling_Tag
:= Duplicate_Subexpr
(Expression
(Ctrl_Arg
));
904 -- Ada 2005 (AI-251): Abstract interface class-wide type
906 elsif Is_Interface
(Ctrl_Typ
)
907 and then Is_Class_Wide_Type
(Ctrl_Typ
)
909 Controlling_Tag
:= Duplicate_Subexpr
(Ctrl_Arg
);
913 Make_Selected_Component
(Loc
,
914 Prefix
=> Duplicate_Subexpr_Move_Checks
(Ctrl_Arg
),
915 Selector_Name
=> New_Reference_To
(DTC_Entity
(Subp
), Loc
));
918 -- Handle dispatching calls to predefined primitives
920 if Is_Predefined_Dispatching_Operation
(Subp
)
921 or else Is_Predefined_Dispatching_Alias
(Subp
)
923 Build_Get_Predefined_Prim_Op_Address
(Loc
,
924 Tag_Node
=> Controlling_Tag
,
925 Position
=> DT_Position
(Subp
),
926 New_Node
=> New_Node
);
928 -- Handle dispatching calls to user-defined primitives
931 Build_Get_Prim_Op_Address
(Loc
,
932 Typ
=> Underlying_Type
(Find_Dispatching_Type
(Subp
)),
933 Tag_Node
=> Controlling_Tag
,
934 Position
=> DT_Position
(Subp
),
935 New_Node
=> New_Node
);
939 Unchecked_Convert_To
(Subp_Ptr_Typ
, New_Node
);
941 -- Generate the SCIL node for this dispatching call. Done now because
942 -- attribute SCIL_Controlling_Tag must be set after the new call name
943 -- is built to reference the nodes that will see the SCIL backend
944 -- (because Build_Get_Prim_Op_Address generates an unchecked type
945 -- conversion which relocates the controlling tag node).
947 if Generate_SCIL
then
948 SCIL_Node
:= Make_SCIL_Dispatching_Call
(Sloc
(Call_Node
));
949 Set_SCIL_Entity
(SCIL_Node
, Typ
);
950 Set_SCIL_Target_Prim
(SCIL_Node
, Subp
);
952 -- Common case: the controlling tag is the tag of an object
953 -- (for example, obj.tag)
955 if Nkind
(Controlling_Tag
) = N_Selected_Component
then
956 Set_SCIL_Controlling_Tag
(SCIL_Node
, Controlling_Tag
);
958 -- Handle renaming of selected component
960 elsif Nkind
(Controlling_Tag
) = N_Identifier
961 and then Nkind
(Parent
(Entity
(Controlling_Tag
))) =
962 N_Object_Renaming_Declaration
963 and then Nkind
(Name
(Parent
(Entity
(Controlling_Tag
)))) =
966 Set_SCIL_Controlling_Tag
(SCIL_Node
,
967 Name
(Parent
(Entity
(Controlling_Tag
))));
969 -- If the controlling tag is an identifier, the SCIL node references
970 -- the corresponding object or parameter declaration
972 elsif Nkind
(Controlling_Tag
) = N_Identifier
973 and then Nkind_In
(Parent
(Entity
(Controlling_Tag
)),
974 N_Object_Declaration
,
975 N_Parameter_Specification
)
977 Set_SCIL_Controlling_Tag
(SCIL_Node
,
978 Parent
(Entity
(Controlling_Tag
)));
980 -- If the controlling tag is a dereference, the SCIL node references
981 -- the corresponding object or parameter declaration
983 elsif Nkind
(Controlling_Tag
) = N_Explicit_Dereference
984 and then Nkind
(Prefix
(Controlling_Tag
)) = N_Identifier
985 and then Nkind_In
(Parent
(Entity
(Prefix
(Controlling_Tag
))),
986 N_Object_Declaration
,
987 N_Parameter_Specification
)
989 Set_SCIL_Controlling_Tag
(SCIL_Node
,
990 Parent
(Entity
(Prefix
(Controlling_Tag
))));
992 -- For a direct reference of the tag of the type the SCIL node
993 -- references the internal object declaration containing the tag
996 elsif Nkind
(Controlling_Tag
) = N_Attribute_Reference
997 and then Attribute_Name
(Controlling_Tag
) = Name_Tag
999 Set_SCIL_Controlling_Tag
(SCIL_Node
,
1003 (Access_Disp_Table
(Entity
(Prefix
(Controlling_Tag
)))))));
1005 -- Interfaces are not supported. For now we leave the SCIL node
1006 -- decorated with the Controlling_Tag. More work needed here???
1008 elsif Is_Interface
(Etype
(Controlling_Tag
)) then
1009 Set_SCIL_Controlling_Tag
(SCIL_Node
, Controlling_Tag
);
1012 pragma Assert
(False);
1017 if Nkind
(Call_Node
) = N_Function_Call
then
1019 Make_Function_Call
(Loc
,
1020 Name
=> New_Call_Name
,
1021 Parameter_Associations
=> New_Params
);
1023 -- If this is a dispatching "=", we must first compare the tags so
1024 -- we generate: x.tag = y.tag and then x = y
1026 if Subp
= Eq_Prim_Op
then
1027 Param
:= First_Actual
(Call_Node
);
1033 Make_Selected_Component
(Loc
,
1034 Prefix
=> New_Value
(Param
),
1036 New_Reference_To
(First_Tag_Component
(Typ
),
1040 Make_Selected_Component
(Loc
,
1042 Unchecked_Convert_To
(Typ
,
1043 New_Value
(Next_Actual
(Param
))),
1046 (First_Tag_Component
(Typ
), Loc
))),
1047 Right_Opnd
=> New_Call
);
1049 SCIL_Related_Node
:= Right_Opnd
(New_Call
);
1054 Make_Procedure_Call_Statement
(Loc
,
1055 Name
=> New_Call_Name
,
1056 Parameter_Associations
=> New_Params
);
1059 -- Register the dispatching call in the call graph nodes table
1061 Register_CG_Node
(Call_Node
);
1063 Rewrite
(Call_Node
, New_Call
);
1065 -- Associate the SCIL node of this dispatching call
1067 if Generate_SCIL
then
1068 Set_SCIL_Node
(SCIL_Related_Node
, SCIL_Node
);
1071 -- Suppress all checks during the analysis of the expanded code
1072 -- to avoid the generation of spurious warnings under ZFP run-time.
1074 Analyze_And_Resolve
(Call_Node
, Call_Typ
, Suppress
=> All_Checks
);
1075 end Expand_Dispatching_Call
;
1077 ---------------------------------
1078 -- Expand_Interface_Conversion --
1079 ---------------------------------
1081 procedure Expand_Interface_Conversion
(N
: Node_Id
) is
1082 function Underlying_Record_Type
(Typ
: Entity_Id
) return Entity_Id
;
1083 -- Return the underlying record type of Typ.
1085 ----------------------------
1086 -- Underlying_Record_Type --
1087 ----------------------------
1089 function Underlying_Record_Type
(Typ
: Entity_Id
) return Entity_Id
is
1090 E
: Entity_Id
:= Typ
;
1093 -- Handle access to class-wide interface types
1095 if Is_Access_Type
(E
) then
1096 E
:= Etype
(Directly_Designated_Type
(E
));
1099 -- Handle class-wide types. This conversion can appear explicitly in
1100 -- the source code. Example: I'Class (Obj)
1102 if Is_Class_Wide_Type
(E
) then
1106 -- If the target type is a tagged synchronized type, the dispatch
1107 -- table info is in the corresponding record type.
1109 if Is_Concurrent_Type
(E
) then
1110 E
:= Corresponding_Record_Type
(E
);
1113 -- Handle private types
1115 E
:= Underlying_Type
(E
);
1119 return Base_Type
(E
);
1120 end Underlying_Record_Type
;
1124 Loc
: constant Source_Ptr
:= Sloc
(N
);
1125 Etyp
: constant Entity_Id
:= Etype
(N
);
1126 Operand
: constant Node_Id
:= Expression
(N
);
1127 Operand_Typ
: Entity_Id
:= Etype
(Operand
);
1129 Iface_Typ
: constant Entity_Id
:= Underlying_Record_Type
(Etype
(N
));
1130 Iface_Tag
: Entity_Id
;
1131 Is_Static
: Boolean;
1133 -- Start of processing for Expand_Interface_Conversion
1136 -- Freeze the entity associated with the target interface to have
1137 -- available the attribute Access_Disp_Table.
1139 Freeze_Before
(N
, Iface_Typ
);
1141 -- Ada 2005 (AI-345): Handle synchronized interface type derivations
1143 if Is_Concurrent_Type
(Operand_Typ
) then
1144 Operand_Typ
:= Base_Type
(Corresponding_Record_Type
(Operand_Typ
));
1147 -- Evaluate if we can statically displace the pointer to the object
1150 Opnd_Typ
: constant Node_Id
:= Underlying_Record_Type
(Operand_Typ
);
1154 not Is_Interface
(Opnd_Typ
)
1155 and then Interface_Present_In_Ancestor
1158 and then (Etype
(Opnd_Typ
) = Opnd_Typ
1160 Is_Variable_Size_Record
(Etype
(Opnd_Typ
)));
1163 if not Tagged_Type_Expansion
then
1164 if VM_Target
/= No_VM
then
1165 if Is_Access_Type
(Operand_Typ
) then
1166 Operand_Typ
:= Designated_Type
(Operand_Typ
);
1169 if Is_Class_Wide_Type
(Operand_Typ
) then
1170 Operand_Typ
:= Root_Type
(Operand_Typ
);
1173 if not Is_Static
and then Operand_Typ
/= Iface_Typ
then
1175 Make_Procedure_Call_Statement
(Loc
,
1176 Name
=> New_Occurrence_Of
1177 (RTE
(RE_Check_Interface_Conversion
), Loc
),
1178 Parameter_Associations
=> New_List
(
1179 Make_Attribute_Reference
(Loc
,
1180 Prefix
=> Duplicate_Subexpr
(Expression
(N
)),
1181 Attribute_Name
=> Name_Tag
),
1182 Make_Attribute_Reference
(Loc
,
1183 Prefix
=> New_Reference_To
(Iface_Typ
, Loc
),
1184 Attribute_Name
=> Name_Tag
))));
1187 -- Just do a conversion ???
1189 Rewrite
(N
, Unchecked_Convert_To
(Etype
(N
), N
));
1196 if not Is_Static
then
1198 -- Give error if configurable run time and Displace not available
1200 if not RTE_Available
(RE_Displace
) then
1201 Error_Msg_CRT
("dynamic interface conversion", N
);
1205 -- Handle conversion of access-to-class-wide interface types. Target
1206 -- can be an access to an object or an access to another class-wide
1207 -- interface (see -1- and -2- in the following example):
1209 -- type Iface1_Ref is access all Iface1'Class;
1210 -- type Iface2_Ref is access all Iface1'Class;
1212 -- Acc1 : Iface1_Ref := new ...
1213 -- Obj : Obj_Ref := Obj_Ref (Acc); -- 1
1214 -- Acc2 : Iface2_Ref := Iface2_Ref (Acc); -- 2
1216 if Is_Access_Type
(Operand_Typ
) then
1218 Unchecked_Convert_To
(Etype
(N
),
1219 Make_Function_Call
(Loc
,
1220 Name
=> New_Reference_To
(RTE
(RE_Displace
), Loc
),
1221 Parameter_Associations
=> New_List
(
1223 Unchecked_Convert_To
(RTE
(RE_Address
),
1224 Relocate_Node
(Expression
(N
))),
1227 (Node
(First_Elmt
(Access_Disp_Table
(Iface_Typ
))),
1235 Make_Function_Call
(Loc
,
1236 Name
=> New_Reference_To
(RTE
(RE_Displace
), Loc
),
1237 Parameter_Associations
=> New_List
(
1238 Make_Attribute_Reference
(Loc
,
1239 Prefix
=> Relocate_Node
(Expression
(N
)),
1240 Attribute_Name
=> Name_Address
),
1243 (Node
(First_Elmt
(Access_Disp_Table
(Iface_Typ
))),
1248 -- If the target is a class-wide interface we change the type of the
1249 -- data returned by IW_Convert to indicate that this is a dispatching
1253 New_Itype
: Entity_Id
;
1256 New_Itype
:= Create_Itype
(E_Anonymous_Access_Type
, N
);
1257 Set_Etype
(New_Itype
, New_Itype
);
1258 Set_Directly_Designated_Type
(New_Itype
, Etyp
);
1261 Make_Explicit_Dereference
(Loc
,
1263 Unchecked_Convert_To
(New_Itype
, Relocate_Node
(N
))));
1265 Freeze_Itype
(New_Itype
, N
);
1271 Iface_Tag
:= Find_Interface_Tag
(Operand_Typ
, Iface_Typ
);
1272 pragma Assert
(Iface_Tag
/= Empty
);
1274 -- Keep separate access types to interfaces because one internal
1275 -- function is used to handle the null value (see following comments)
1277 if not Is_Access_Type
(Etype
(N
)) then
1279 -- Statically displace the pointer to the object to reference
1280 -- the component containing the secondary dispatch table.
1283 Convert_Tag_To_Interface
(Class_Wide_Type
(Iface_Typ
),
1284 Make_Selected_Component
(Loc
,
1285 Prefix
=> Relocate_Node
(Expression
(N
)),
1286 Selector_Name
=> New_Occurrence_Of
(Iface_Tag
, Loc
))));
1289 -- Build internal function to handle the case in which the
1290 -- actual is null. If the actual is null returns null because
1291 -- no displacement is required; otherwise performs a type
1292 -- conversion that will be expanded in the code that returns
1293 -- the value of the displaced actual. That is:
1295 -- function Func (O : Address) return Iface_Typ is
1296 -- type Op_Typ is access all Operand_Typ;
1297 -- Aux : Op_Typ := To_Op_Typ (O);
1299 -- if O = Null_Address then
1302 -- return Iface_Typ!(Aux.Iface_Tag'Address);
1307 Desig_Typ
: Entity_Id
;
1309 New_Typ_Decl
: Node_Id
;
1313 Desig_Typ
:= Etype
(Expression
(N
));
1315 if Is_Access_Type
(Desig_Typ
) then
1317 Available_View
(Directly_Designated_Type
(Desig_Typ
));
1320 if Is_Concurrent_Type
(Desig_Typ
) then
1321 Desig_Typ
:= Base_Type
(Corresponding_Record_Type
(Desig_Typ
));
1325 Make_Full_Type_Declaration
(Loc
,
1326 Defining_Identifier
=> Make_Temporary
(Loc
, 'T'),
1328 Make_Access_To_Object_Definition
(Loc
,
1329 All_Present
=> True,
1330 Null_Exclusion_Present
=> False,
1331 Constant_Present
=> False,
1332 Subtype_Indication
=>
1333 New_Reference_To
(Desig_Typ
, Loc
)));
1336 Make_Simple_Return_Statement
(Loc
,
1337 Unchecked_Convert_To
(Etype
(N
),
1338 Make_Attribute_Reference
(Loc
,
1340 Make_Selected_Component
(Loc
,
1342 Unchecked_Convert_To
1343 (Defining_Identifier
(New_Typ_Decl
),
1344 Make_Identifier
(Loc
, Name_uO
)),
1346 New_Occurrence_Of
(Iface_Tag
, Loc
)),
1347 Attribute_Name
=> Name_Address
))));
1349 -- If the type is null-excluding, no need for the null branch.
1350 -- Otherwise we need to check for it and return null.
1352 if not Can_Never_Be_Null
(Etype
(N
)) then
1354 Make_If_Statement
(Loc
,
1357 Left_Opnd
=> Make_Identifier
(Loc
, Name_uO
),
1358 Right_Opnd
=> New_Reference_To
1359 (RTE
(RE_Null_Address
), Loc
)),
1361 Then_Statements
=> New_List
(
1362 Make_Simple_Return_Statement
(Loc
,
1364 Else_Statements
=> Stats
));
1367 Fent
:= Make_Temporary
(Loc
, 'F');
1369 Make_Subprogram_Body
(Loc
,
1371 Make_Function_Specification
(Loc
,
1372 Defining_Unit_Name
=> Fent
,
1374 Parameter_Specifications
=> New_List
(
1375 Make_Parameter_Specification
(Loc
,
1376 Defining_Identifier
=>
1377 Make_Defining_Identifier
(Loc
, Name_uO
),
1379 New_Reference_To
(RTE
(RE_Address
), Loc
))),
1381 Result_Definition
=>
1382 New_Reference_To
(Etype
(N
), Loc
)),
1384 Declarations
=> New_List
(New_Typ_Decl
),
1386 Handled_Statement_Sequence
=>
1387 Make_Handled_Sequence_Of_Statements
(Loc
, Stats
));
1389 -- Place function body before the expression containing the
1390 -- conversion. We suppress all checks because the body of the
1391 -- internally generated function already takes care of the case
1392 -- in which the actual is null; therefore there is no need to
1393 -- double check that the pointer is not null when the program
1394 -- executes the alternative that performs the type conversion).
1396 Insert_Action
(N
, Func
, Suppress
=> All_Checks
);
1398 if Is_Access_Type
(Etype
(Expression
(N
))) then
1400 -- Generate: Func (Address!(Expression))
1403 Make_Function_Call
(Loc
,
1404 Name
=> New_Reference_To
(Fent
, Loc
),
1405 Parameter_Associations
=> New_List
(
1406 Unchecked_Convert_To
(RTE
(RE_Address
),
1407 Relocate_Node
(Expression
(N
))))));
1410 -- Generate: Func (Operand_Typ!(Expression)'Address)
1413 Make_Function_Call
(Loc
,
1414 Name
=> New_Reference_To
(Fent
, Loc
),
1415 Parameter_Associations
=> New_List
(
1416 Make_Attribute_Reference
(Loc
,
1417 Prefix
=> Unchecked_Convert_To
(Operand_Typ
,
1418 Relocate_Node
(Expression
(N
))),
1419 Attribute_Name
=> Name_Address
))));
1425 end Expand_Interface_Conversion
;
1427 ------------------------------
1428 -- Expand_Interface_Actuals --
1429 ------------------------------
1431 procedure Expand_Interface_Actuals
(Call_Node
: Node_Id
) is
1433 Actual_Dup
: Node_Id
;
1434 Actual_Typ
: Entity_Id
;
1436 Conversion
: Node_Id
;
1438 Formal_Typ
: Entity_Id
;
1440 Formal_DDT
: Entity_Id
;
1441 Actual_DDT
: Entity_Id
;
1444 -- This subprogram is called directly from the semantics, so we need a
1445 -- check to see whether expansion is active before proceeding.
1447 if not Expander_Active
then
1451 -- Call using access to subprogram with explicit dereference
1453 if Nkind
(Name
(Call_Node
)) = N_Explicit_Dereference
then
1454 Subp
:= Etype
(Name
(Call_Node
));
1456 -- Call using selected component
1458 elsif Nkind
(Name
(Call_Node
)) = N_Selected_Component
then
1459 Subp
:= Entity
(Selector_Name
(Name
(Call_Node
)));
1461 -- Call using direct name
1464 Subp
:= Entity
(Name
(Call_Node
));
1467 -- Ada 2005 (AI-251): Look for interface type formals to force "this"
1470 Formal
:= First_Formal
(Subp
);
1471 Actual
:= First_Actual
(Call_Node
);
1472 while Present
(Formal
) loop
1473 Formal_Typ
:= Etype
(Formal
);
1475 if Ekind
(Formal_Typ
) = E_Record_Type_With_Private
then
1476 Formal_Typ
:= Full_View
(Formal_Typ
);
1479 if Is_Access_Type
(Formal_Typ
) then
1480 Formal_DDT
:= Directly_Designated_Type
(Formal_Typ
);
1483 Actual_Typ
:= Etype
(Actual
);
1485 if Is_Access_Type
(Actual_Typ
) then
1486 Actual_DDT
:= Directly_Designated_Type
(Actual_Typ
);
1489 if Is_Interface
(Formal_Typ
)
1490 and then Is_Class_Wide_Type
(Formal_Typ
)
1492 -- No need to displace the pointer if the type of the actual
1493 -- coincides with the type of the formal.
1495 if Actual_Typ
= Formal_Typ
then
1498 -- No need to displace the pointer if the interface type is
1499 -- a parent of the type of the actual because in this case the
1500 -- interface primitives are located in the primary dispatch table.
1502 elsif Is_Ancestor
(Formal_Typ
, Actual_Typ
,
1503 Use_Full_View
=> True)
1507 -- Implicit conversion to the class-wide formal type to force
1508 -- the displacement of the pointer.
1511 -- Normally, expansion of actuals for calls to build-in-place
1512 -- functions happens as part of Expand_Actuals, but in this
1513 -- case the call will be wrapped in a conversion and soon after
1514 -- expanded further to handle the displacement for a class-wide
1515 -- interface conversion, so if this is a BIP call then we need
1516 -- to handle it now.
1518 if Ada_Version
>= Ada_2005
1519 and then Is_Build_In_Place_Function_Call
(Actual
)
1521 Make_Build_In_Place_Call_In_Anonymous_Context
(Actual
);
1524 Conversion
:= Convert_To
(Formal_Typ
, Relocate_Node
(Actual
));
1525 Rewrite
(Actual
, Conversion
);
1526 Analyze_And_Resolve
(Actual
, Formal_Typ
);
1529 -- Access to class-wide interface type
1531 elsif Is_Access_Type
(Formal_Typ
)
1532 and then Is_Interface
(Formal_DDT
)
1533 and then Is_Class_Wide_Type
(Formal_DDT
)
1534 and then Interface_Present_In_Ancestor
1536 Iface
=> Etype
(Formal_DDT
))
1538 -- Handle attributes 'Access and 'Unchecked_Access
1540 if Nkind
(Actual
) = N_Attribute_Reference
1542 (Attribute_Name
(Actual
) = Name_Access
1543 or else Attribute_Name
(Actual
) = Name_Unchecked_Access
)
1545 -- This case must have been handled by the analysis and
1546 -- expansion of 'Access. The only exception is when types
1547 -- match and no further expansion is required.
1549 pragma Assert
(Base_Type
(Etype
(Prefix
(Actual
)))
1550 = Base_Type
(Formal_DDT
));
1553 -- No need to displace the pointer if the type of the actual
1554 -- coincides with the type of the formal.
1556 elsif Actual_DDT
= Formal_DDT
then
1559 -- No need to displace the pointer if the interface type is
1560 -- a parent of the type of the actual because in this case the
1561 -- interface primitives are located in the primary dispatch table.
1563 elsif Is_Ancestor
(Formal_DDT
, Actual_DDT
,
1564 Use_Full_View
=> True)
1569 Actual_Dup
:= Relocate_Node
(Actual
);
1571 if From_Limited_With
(Actual_Typ
) then
1573 -- If the type of the actual parameter comes from a limited
1574 -- with-clause and the non-limited view is already available
1575 -- we replace the anonymous access type by a duplicate
1576 -- declaration whose designated type is the non-limited view
1578 if Ekind
(Actual_DDT
) = E_Incomplete_Type
1579 and then Present
(Non_Limited_View
(Actual_DDT
))
1581 Anon
:= New_Copy
(Actual_Typ
);
1583 if Is_Itype
(Anon
) then
1584 Set_Scope
(Anon
, Current_Scope
);
1587 Set_Directly_Designated_Type
(Anon
,
1588 Non_Limited_View
(Actual_DDT
));
1589 Set_Etype
(Actual_Dup
, Anon
);
1591 elsif Is_Class_Wide_Type
(Actual_DDT
)
1592 and then Ekind
(Etype
(Actual_DDT
)) = E_Incomplete_Type
1593 and then Present
(Non_Limited_View
(Etype
(Actual_DDT
)))
1595 Anon
:= New_Copy
(Actual_Typ
);
1597 if Is_Itype
(Anon
) then
1598 Set_Scope
(Anon
, Current_Scope
);
1601 Set_Directly_Designated_Type
(Anon
,
1602 New_Copy
(Actual_DDT
));
1603 Set_Class_Wide_Type
(Directly_Designated_Type
(Anon
),
1604 New_Copy
(Class_Wide_Type
(Actual_DDT
)));
1605 Set_Etype
(Directly_Designated_Type
(Anon
),
1606 Non_Limited_View
(Etype
(Actual_DDT
)));
1608 Class_Wide_Type
(Directly_Designated_Type
(Anon
)),
1609 Non_Limited_View
(Etype
(Actual_DDT
)));
1610 Set_Etype
(Actual_Dup
, Anon
);
1614 Conversion
:= Convert_To
(Formal_Typ
, Actual_Dup
);
1615 Rewrite
(Actual
, Conversion
);
1616 Analyze_And_Resolve
(Actual
, Formal_Typ
);
1620 Next_Actual
(Actual
);
1621 Next_Formal
(Formal
);
1623 end Expand_Interface_Actuals
;
1625 ----------------------------
1626 -- Expand_Interface_Thunk --
1627 ----------------------------
1629 procedure Expand_Interface_Thunk
1631 Thunk_Id
: out Entity_Id
;
1632 Thunk_Code
: out Node_Id
)
1634 Loc
: constant Source_Ptr
:= Sloc
(Prim
);
1635 Actuals
: constant List_Id
:= New_List
;
1636 Decl
: constant List_Id
:= New_List
;
1637 Formals
: constant List_Id
:= New_List
;
1638 Target
: constant Entity_Id
:= Ultimate_Alias
(Prim
);
1645 Iface_Formal
: Node_Id
;
1647 Offset_To_Top
: Node_Id
;
1648 Target_Formal
: Entity_Id
;
1652 Thunk_Code
:= Empty
;
1654 -- No thunk needed if the primitive has been eliminated
1656 if Is_Eliminated
(Ultimate_Alias
(Prim
)) then
1659 -- In case of primitives that are functions without formals and a
1660 -- controlling result there is no need to build the thunk.
1662 elsif not Present
(First_Formal
(Target
)) then
1663 pragma Assert
(Ekind
(Target
) = E_Function
1664 and then Has_Controlling_Result
(Target
));
1668 -- Duplicate the formals of the Target primitive. In the thunk, the type
1669 -- of the controlling formal is the covered interface type (instead of
1670 -- the target tagged type). Done to avoid problems with discriminated
1671 -- tagged types because, if the controlling type has discriminants with
1672 -- default values, then the type conversions done inside the body of
1673 -- the thunk (after the displacement of the pointer to the base of the
1674 -- actual object) generate code that modify its contents.
1676 -- Note: This special management is not done for predefined primitives
1679 if not Is_Predefined_Dispatching_Operation
(Prim
) then
1680 Iface_Formal
:= First_Formal
(Interface_Alias
(Prim
));
1683 Formal
:= First_Formal
(Target
);
1684 while Present
(Formal
) loop
1685 Ftyp
:= Etype
(Formal
);
1687 -- Use the interface type as the type of the controlling formal (see
1690 if not Is_Controlling_Formal
(Formal
)
1691 or else Is_Predefined_Dispatching_Operation
(Prim
)
1693 Ftyp
:= Etype
(Formal
);
1694 Expr
:= New_Copy_Tree
(Expression
(Parent
(Formal
)));
1696 Ftyp
:= Etype
(Iface_Formal
);
1701 Make_Parameter_Specification
(Loc
,
1702 Defining_Identifier
=>
1703 Make_Defining_Identifier
(Sloc
(Formal
),
1704 Chars
=> Chars
(Formal
)),
1705 In_Present
=> In_Present
(Parent
(Formal
)),
1706 Out_Present
=> Out_Present
(Parent
(Formal
)),
1707 Parameter_Type
=> New_Reference_To
(Ftyp
, Loc
),
1708 Expression
=> Expr
));
1710 if not Is_Predefined_Dispatching_Operation
(Prim
) then
1711 Next_Formal
(Iface_Formal
);
1714 Next_Formal
(Formal
);
1717 Target_Formal
:= First_Formal
(Target
);
1718 Formal
:= First
(Formals
);
1719 while Present
(Formal
) loop
1721 -- If the parent is a constrained discriminated type, then the
1722 -- primitive operation will have been defined on a first subtype.
1723 -- For proper matching with controlling type, use base type.
1725 if Ekind
(Target_Formal
) = E_In_Parameter
1726 and then Ekind
(Etype
(Target_Formal
)) = E_Anonymous_Access_Type
1729 Base_Type
(Directly_Designated_Type
(Etype
(Target_Formal
)));
1731 Ftyp
:= Base_Type
(Etype
(Target_Formal
));
1734 -- For concurrent types, the relevant information is found in the
1735 -- Corresponding_Record_Type, rather than the type entity itself.
1737 if Is_Concurrent_Type
(Ftyp
) then
1738 Ftyp
:= Corresponding_Record_Type
(Ftyp
);
1741 if Ekind
(Target_Formal
) = E_In_Parameter
1742 and then Ekind
(Etype
(Target_Formal
)) = E_Anonymous_Access_Type
1743 and then Is_Controlling_Formal
(Target_Formal
)
1746 -- type T is access all <<type of the target formal>>
1747 -- S : Storage_Offset := Storage_Offset!(Formal)
1748 -- - Offset_To_Top (address!(Formal))
1751 Make_Full_Type_Declaration
(Loc
,
1752 Defining_Identifier
=> Make_Temporary
(Loc
, 'T'),
1754 Make_Access_To_Object_Definition
(Loc
,
1755 All_Present
=> True,
1756 Null_Exclusion_Present
=> False,
1757 Constant_Present
=> False,
1758 Subtype_Indication
=>
1759 New_Reference_To
(Ftyp
, Loc
)));
1762 Unchecked_Convert_To
(RTE
(RE_Address
),
1763 New_Reference_To
(Defining_Identifier
(Formal
), Loc
));
1765 if not RTE_Available
(RE_Offset_To_Top
) then
1767 Build_Offset_To_Top
(Loc
, New_Arg
);
1770 Make_Function_Call
(Loc
,
1771 Name
=> New_Reference_To
(RTE
(RE_Offset_To_Top
), Loc
),
1772 Parameter_Associations
=> New_List
(New_Arg
));
1776 Make_Object_Declaration
(Loc
,
1777 Defining_Identifier
=> Make_Temporary
(Loc
, 'S'),
1778 Constant_Present
=> True,
1779 Object_Definition
=>
1780 New_Reference_To
(RTE
(RE_Storage_Offset
), Loc
),
1782 Make_Op_Subtract
(Loc
,
1784 Unchecked_Convert_To
1785 (RTE
(RE_Storage_Offset
),
1786 New_Reference_To
(Defining_Identifier
(Formal
), Loc
)),
1790 Append_To
(Decl
, Decl_2
);
1791 Append_To
(Decl
, Decl_1
);
1793 -- Reference the new actual. Generate:
1797 Unchecked_Convert_To
1798 (Defining_Identifier
(Decl_2
),
1799 New_Reference_To
(Defining_Identifier
(Decl_1
), Loc
)));
1801 elsif Is_Controlling_Formal
(Target_Formal
) then
1804 -- S1 : Storage_Offset := Storage_Offset!(Formal'Address)
1805 -- - Offset_To_Top (Formal'Address)
1806 -- S2 : Addr_Ptr := Addr_Ptr!(S1)
1809 Make_Attribute_Reference
(Loc
,
1811 New_Reference_To
(Defining_Identifier
(Formal
), Loc
),
1815 if not RTE_Available
(RE_Offset_To_Top
) then
1817 Build_Offset_To_Top
(Loc
, New_Arg
);
1820 Make_Function_Call
(Loc
,
1821 Name
=> New_Reference_To
(RTE
(RE_Offset_To_Top
), Loc
),
1822 Parameter_Associations
=> New_List
(New_Arg
));
1826 Make_Object_Declaration
(Loc
,
1827 Defining_Identifier
=> Make_Temporary
(Loc
, 'S'),
1828 Constant_Present
=> True,
1829 Object_Definition
=>
1830 New_Reference_To
(RTE
(RE_Storage_Offset
), Loc
),
1832 Make_Op_Subtract
(Loc
,
1834 Unchecked_Convert_To
1835 (RTE
(RE_Storage_Offset
),
1836 Make_Attribute_Reference
(Loc
,
1839 (Defining_Identifier
(Formal
), Loc
),
1840 Attribute_Name
=> Name_Address
)),
1845 Make_Object_Declaration
(Loc
,
1846 Defining_Identifier
=> Make_Temporary
(Loc
, 'S'),
1847 Constant_Present
=> True,
1848 Object_Definition
=>
1849 New_Reference_To
(RTE
(RE_Addr_Ptr
), Loc
),
1851 Unchecked_Convert_To
1853 New_Reference_To
(Defining_Identifier
(Decl_1
), Loc
)));
1855 Append_To
(Decl
, Decl_1
);
1856 Append_To
(Decl
, Decl_2
);
1858 -- Reference the new actual, generate:
1859 -- Target_Formal (S2.all)
1862 Unchecked_Convert_To
(Ftyp
,
1863 Make_Explicit_Dereference
(Loc
,
1864 New_Reference_To
(Defining_Identifier
(Decl_2
), Loc
))));
1866 -- Ensure proper matching of access types. Required to avoid
1867 -- reporting spurious errors.
1869 elsif Is_Access_Type
(Etype
(Target_Formal
)) then
1871 Unchecked_Convert_To
(Base_Type
(Etype
(Target_Formal
)),
1872 New_Reference_To
(Defining_Identifier
(Formal
), Loc
)));
1874 -- No special management required for this actual
1878 New_Reference_To
(Defining_Identifier
(Formal
), Loc
));
1881 Next_Formal
(Target_Formal
);
1885 Thunk_Id
:= Make_Temporary
(Loc
, 'T');
1886 Set_Ekind
(Thunk_Id
, Ekind
(Prim
));
1887 Set_Is_Thunk
(Thunk_Id
);
1888 Set_Convention
(Thunk_Id
, Convention
(Prim
));
1889 Set_Thunk_Entity
(Thunk_Id
, Target
);
1893 if Ekind
(Target
) = E_Procedure
then
1895 Make_Subprogram_Body
(Loc
,
1897 Make_Procedure_Specification
(Loc
,
1898 Defining_Unit_Name
=> Thunk_Id
,
1899 Parameter_Specifications
=> Formals
),
1900 Declarations
=> Decl
,
1901 Handled_Statement_Sequence
=>
1902 Make_Handled_Sequence_Of_Statements
(Loc
,
1903 Statements
=> New_List
(
1904 Make_Procedure_Call_Statement
(Loc
,
1905 Name
=> New_Occurrence_Of
(Target
, Loc
),
1906 Parameter_Associations
=> Actuals
))));
1910 else pragma Assert
(Ekind
(Target
) = E_Function
);
1912 Result_Def
: Node_Id
;
1913 Call_Node
: Node_Id
;
1917 Make_Function_Call
(Loc
,
1918 Name
=> New_Occurrence_Of
(Target
, Loc
),
1919 Parameter_Associations
=> Actuals
);
1921 if not Is_Interface
(Etype
(Prim
)) then
1922 Result_Def
:= New_Copy
(Result_Definition
(Parent
(Target
)));
1924 -- Thunk of function returning a class-wide interface object. No
1925 -- extra displacement needed since the displacement is generated
1926 -- in the return statement of Prim. Example:
1928 -- type Iface is interface ...
1929 -- function F (O : Iface) return Iface'Class;
1931 -- type T is new ... and Iface with ...
1932 -- function F (O : T) return Iface'Class;
1934 elsif Is_Class_Wide_Type
(Etype
(Prim
)) then
1935 Result_Def
:= New_Occurrence_Of
(Etype
(Prim
), Loc
);
1937 -- Thunk of function returning an interface object. Displacement
1940 -- type Iface is interface ...
1941 -- function F (O : Iface) return Iface;
1943 -- type T is new ... and Iface with ...
1944 -- function F (O : T) return T;
1948 New_Occurrence_Of
(Class_Wide_Type
(Etype
(Prim
)), Loc
);
1950 -- Adding implicit conversion to force the displacement of
1951 -- the pointer to the object to reference the corresponding
1952 -- secondary dispatch table.
1955 Make_Type_Conversion
(Loc
,
1957 New_Occurrence_Of
(Class_Wide_Type
(Etype
(Prim
)), Loc
),
1958 Expression
=> Relocate_Node
(Call_Node
));
1962 Make_Subprogram_Body
(Loc
,
1964 Make_Function_Specification
(Loc
,
1965 Defining_Unit_Name
=> Thunk_Id
,
1966 Parameter_Specifications
=> Formals
,
1967 Result_Definition
=> Result_Def
),
1968 Declarations
=> Decl
,
1969 Handled_Statement_Sequence
=>
1970 Make_Handled_Sequence_Of_Statements
(Loc
,
1971 Statements
=> New_List
(
1972 Make_Simple_Return_Statement
(Loc
, Call_Node
))));
1975 end Expand_Interface_Thunk
;
1977 ------------------------
1978 -- Find_Specific_Type --
1979 ------------------------
1981 function Find_Specific_Type
(CW
: Entity_Id
) return Entity_Id
is
1982 Typ
: Entity_Id
:= Root_Type
(CW
);
1985 if Ekind
(Typ
) = E_Incomplete_Type
then
1986 if From_Limited_With
(Typ
) then
1987 Typ
:= Non_Limited_View
(Typ
);
1989 Typ
:= Full_View
(Typ
);
1994 end Find_Specific_Type
;
1996 --------------------------
1997 -- Has_CPP_Constructors --
1998 --------------------------
2000 function Has_CPP_Constructors
(Typ
: Entity_Id
) return Boolean is
2004 -- Look for the constructor entities
2006 E
:= Next_Entity
(Typ
);
2007 while Present
(E
) loop
2008 if Ekind
(E
) = E_Function
2009 and then Is_Constructor
(E
)
2018 end Has_CPP_Constructors
;
2024 function Has_DT
(Typ
: Entity_Id
) return Boolean is
2026 return not Is_Interface
(Typ
)
2027 and then not Restriction_Active
(No_Dispatching_Calls
);
2030 ----------------------------------
2031 -- Is_Expanded_Dispatching_Call --
2032 ----------------------------------
2034 function Is_Expanded_Dispatching_Call
(N
: Node_Id
) return Boolean is
2036 return Nkind
(N
) in N_Subprogram_Call
2037 and then Nkind
(Name
(N
)) = N_Explicit_Dereference
2038 and then Is_Dispatch_Table_Entity
(Etype
(Name
(N
)));
2039 end Is_Expanded_Dispatching_Call
;
2041 -----------------------------------------
2042 -- Is_Predefined_Dispatching_Operation --
2043 -----------------------------------------
2045 function Is_Predefined_Dispatching_Operation
2046 (E
: Entity_Id
) return Boolean
2048 TSS_Name
: TSS_Name_Type
;
2051 if not Is_Dispatching_Operation
(E
) then
2055 Get_Name_String
(Chars
(E
));
2057 -- Most predefined primitives have internally generated names. Equality
2058 -- must be treated differently; the predefined operation is recognized
2059 -- as a homogeneous binary operator that returns Boolean.
2061 if Name_Len
> TSS_Name_Type
'Last then
2062 TSS_Name
:= TSS_Name_Type
(Name_Buffer
(Name_Len
- TSS_Name
'Length + 1
2064 if Chars
(E
) = Name_uSize
2065 or else TSS_Name
= TSS_Stream_Read
2066 or else TSS_Name
= TSS_Stream_Write
2067 or else TSS_Name
= TSS_Stream_Input
2068 or else TSS_Name
= TSS_Stream_Output
2070 (Chars
(E
) = Name_Op_Eq
2071 and then Etype
(First_Formal
(E
)) = Etype
(Last_Formal
(E
)))
2072 or else Chars
(E
) = Name_uAssign
2073 or else TSS_Name
= TSS_Deep_Adjust
2074 or else TSS_Name
= TSS_Deep_Finalize
2075 or else Is_Predefined_Interface_Primitive
(E
)
2082 end Is_Predefined_Dispatching_Operation
;
2084 ---------------------------------------
2085 -- Is_Predefined_Internal_Operation --
2086 ---------------------------------------
2088 function Is_Predefined_Internal_Operation
2089 (E
: Entity_Id
) return Boolean
2091 TSS_Name
: TSS_Name_Type
;
2094 if not Is_Dispatching_Operation
(E
) then
2098 Get_Name_String
(Chars
(E
));
2100 -- Most predefined primitives have internally generated names. Equality
2101 -- must be treated differently; the predefined operation is recognized
2102 -- as a homogeneous binary operator that returns Boolean.
2104 if Name_Len
> TSS_Name_Type
'Last then
2107 (Name_Buffer
(Name_Len
- TSS_Name
'Length + 1 .. Name_Len
));
2109 if Nam_In
(Chars
(E
), Name_uSize
, Name_uAssign
)
2111 (Chars
(E
) = Name_Op_Eq
2112 and then Etype
(First_Formal
(E
)) = Etype
(Last_Formal
(E
)))
2113 or else TSS_Name
= TSS_Deep_Adjust
2114 or else TSS_Name
= TSS_Deep_Finalize
2115 or else Is_Predefined_Interface_Primitive
(E
)
2122 end Is_Predefined_Internal_Operation
;
2124 -------------------------------------
2125 -- Is_Predefined_Dispatching_Alias --
2126 -------------------------------------
2128 function Is_Predefined_Dispatching_Alias
(Prim
: Entity_Id
) return Boolean
2131 return not Is_Predefined_Dispatching_Operation
(Prim
)
2132 and then Present
(Alias
(Prim
))
2133 and then Is_Predefined_Dispatching_Operation
(Ultimate_Alias
(Prim
));
2134 end Is_Predefined_Dispatching_Alias
;
2136 ---------------------------------------
2137 -- Is_Predefined_Interface_Primitive --
2138 ---------------------------------------
2140 function Is_Predefined_Interface_Primitive
(E
: Entity_Id
) return Boolean is
2142 -- In VM targets we don't restrict the functionality of this test to
2143 -- compiling in Ada 2005 mode since in VM targets any tagged type has
2146 return (Ada_Version
>= Ada_2005
or else not Tagged_Type_Expansion
)
2147 and then (Chars
(E
) = Name_uDisp_Asynchronous_Select
or else
2148 Chars
(E
) = Name_uDisp_Conditional_Select
or else
2149 Chars
(E
) = Name_uDisp_Get_Prim_Op_Kind
or else
2150 Chars
(E
) = Name_uDisp_Get_Task_Id
or else
2151 Chars
(E
) = Name_uDisp_Requeue
or else
2152 Chars
(E
) = Name_uDisp_Timed_Select
);
2153 end Is_Predefined_Interface_Primitive
;
2155 ----------------------------------------
2156 -- Make_Disp_Asynchronous_Select_Body --
2157 ----------------------------------------
2159 -- For interface types, generate:
2161 -- procedure _Disp_Asynchronous_Select
2162 -- (T : in out <Typ>;
2164 -- P : System.Address;
2165 -- B : out System.Storage_Elements.Dummy_Communication_Block;
2170 -- C := Ada.Tags.POK_Function;
2171 -- end _Disp_Asynchronous_Select;
2173 -- For protected types, generate:
2175 -- procedure _Disp_Asynchronous_Select
2176 -- (T : in out <Typ>;
2178 -- P : System.Address;
2179 -- B : out System.Storage_Elements.Dummy_Communication_Block;
2183 -- Ada.Tags.Get_Entry_Index (Ada.Tags.Tag (<Typ>VP, S));
2184 -- Bnn : System.Tasking.Protected_Objects.Operations.
2185 -- Communication_Block;
2187 -- System.Tasking.Protected_Objects.Operations.Protected_Entry_Call
2188 -- (T._object'Access,
2189 -- System.Tasking.Protected_Objects.Protected_Entry_Index (I),
2191 -- System.Tasking.Asynchronous_Call,
2193 -- B := System.Storage_Elements.Dummy_Communication_Block (Bnn);
2194 -- end _Disp_Asynchronous_Select;
2196 -- For task types, generate:
2198 -- procedure _Disp_Asynchronous_Select
2199 -- (T : in out <Typ>;
2201 -- P : System.Address;
2202 -- B : out System.Storage_Elements.Dummy_Communication_Block;
2206 -- Ada.Tags.Get_Entry_Index (Ada.Tags.Tag (<Typ>VP, S));
2208 -- System.Tasking.Rendezvous.Task_Entry_Call
2210 -- System.Tasking.Task_Entry_Index (I),
2212 -- System.Tasking.Asynchronous_Call,
2214 -- end _Disp_Asynchronous_Select;
2216 function Make_Disp_Asynchronous_Select_Body
2217 (Typ
: Entity_Id
) return Node_Id
2219 Com_Block
: Entity_Id
;
2220 Conc_Typ
: Entity_Id
:= Empty
;
2221 Decls
: constant List_Id
:= New_List
;
2222 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
2224 Stmts
: constant List_Id
:= New_List
;
2228 pragma Assert
(not Restriction_Active
(No_Dispatching_Calls
));
2230 -- Null body is generated for interface types
2232 if Is_Interface
(Typ
) then
2234 Make_Subprogram_Body
(Loc
,
2235 Specification
=> Make_Disp_Asynchronous_Select_Spec
(Typ
),
2236 Declarations
=> New_List
,
2237 Handled_Statement_Sequence
=>
2238 Make_Handled_Sequence_Of_Statements
(Loc
,
2239 New_List
(Make_Assignment_Statement
(Loc
,
2240 Name
=> Make_Identifier
(Loc
, Name_uF
),
2241 Expression
=> New_Reference_To
(Standard_False
, Loc
)))));
2244 if Is_Concurrent_Record_Type
(Typ
) then
2245 Conc_Typ
:= Corresponding_Concurrent_Type
(Typ
);
2249 -- Ada.Tags.Get_Entry_Index (Ada.Tags.Tag! (<type>VP), S);
2251 -- where I will be used to capture the entry index of the primitive
2252 -- wrapper at position S.
2254 if Tagged_Type_Expansion
then
2256 Unchecked_Convert_To
(RTE
(RE_Tag
),
2258 (Node
(First_Elmt
(Access_Disp_Table
(Typ
))), Loc
));
2261 Make_Attribute_Reference
(Loc
,
2262 Prefix
=> New_Reference_To
(Typ
, Loc
),
2263 Attribute_Name
=> Name_Tag
);
2267 Make_Object_Declaration
(Loc
,
2268 Defining_Identifier
=>
2269 Make_Defining_Identifier
(Loc
, Name_uI
),
2270 Object_Definition
=>
2271 New_Reference_To
(Standard_Integer
, Loc
),
2273 Make_Function_Call
(Loc
,
2275 New_Reference_To
(RTE
(RE_Get_Entry_Index
), Loc
),
2276 Parameter_Associations
=>
2279 Make_Identifier
(Loc
, Name_uS
)))));
2281 if Ekind
(Conc_Typ
) = E_Protected_Type
then
2284 -- Bnn : Communication_Block;
2286 Com_Block
:= Make_Temporary
(Loc
, 'B');
2288 Make_Object_Declaration
(Loc
,
2289 Defining_Identifier
=>
2291 Object_Definition
=>
2292 New_Reference_To
(RTE
(RE_Communication_Block
), Loc
)));
2294 -- Build T._object'Access for calls below
2297 Make_Attribute_Reference
(Loc
,
2298 Attribute_Name
=> Name_Unchecked_Access
,
2300 Make_Selected_Component
(Loc
,
2301 Prefix
=> Make_Identifier
(Loc
, Name_uT
),
2302 Selector_Name
=> Make_Identifier
(Loc
, Name_uObject
)));
2304 case Corresponding_Runtime_Package
(Conc_Typ
) is
2305 when System_Tasking_Protected_Objects_Entries
=>
2308 -- Protected_Entry_Call
2309 -- (T._object'Access, -- Object
2310 -- Protected_Entry_Index! (I), -- E
2311 -- P, -- Uninterpreted_Data
2312 -- Asynchronous_Call, -- Mode
2313 -- Bnn); -- Communication_Block
2315 -- where T is the protected object, I is the entry index, P
2316 -- is the wrapped parameters and B is the name of the
2317 -- communication block.
2320 Make_Procedure_Call_Statement
(Loc
,
2322 New_Reference_To
(RTE
(RE_Protected_Entry_Call
), Loc
),
2323 Parameter_Associations
=>
2327 Make_Unchecked_Type_Conversion
(Loc
, -- entry index
2330 (RTE
(RE_Protected_Entry_Index
), Loc
),
2331 Expression
=> Make_Identifier
(Loc
, Name_uI
)),
2333 Make_Identifier
(Loc
, Name_uP
), -- parameter block
2334 New_Reference_To
-- Asynchronous_Call
2335 (RTE
(RE_Asynchronous_Call
), Loc
),
2337 New_Reference_To
(Com_Block
, Loc
)))); -- comm block
2339 when System_Tasking_Protected_Objects_Single_Entry
=>
2342 -- procedure Protected_Single_Entry_Call
2343 -- (Object : Protection_Entry_Access;
2344 -- Uninterpreted_Data : System.Address;
2345 -- Mode : Call_Modes);
2348 Make_Procedure_Call_Statement
(Loc
,
2351 (RTE
(RE_Protected_Single_Entry_Call
), Loc
),
2352 Parameter_Associations
=>
2356 Make_Attribute_Reference
(Loc
,
2357 Prefix
=> Make_Identifier
(Loc
, Name_uP
),
2358 Attribute_Name
=> Name_Address
),
2361 (RTE
(RE_Asynchronous_Call
), Loc
))));
2364 raise Program_Error
;
2368 -- B := Dummy_Communication_Block (Bnn);
2371 Make_Assignment_Statement
(Loc
,
2372 Name
=> Make_Identifier
(Loc
, Name_uB
),
2374 Make_Unchecked_Type_Conversion
(Loc
,
2377 RTE
(RE_Dummy_Communication_Block
), Loc
),
2379 New_Reference_To
(Com_Block
, Loc
))));
2385 Make_Assignment_Statement
(Loc
,
2386 Name
=> Make_Identifier
(Loc
, Name_uF
),
2387 Expression
=> New_Reference_To
(Standard_False
, Loc
)));
2390 pragma Assert
(Ekind
(Conc_Typ
) = E_Task_Type
);
2394 -- (T._task_id, -- Acceptor
2395 -- Task_Entry_Index! (I), -- E
2396 -- P, -- Uninterpreted_Data
2397 -- Asynchronous_Call, -- Mode
2398 -- F); -- Rendezvous_Successful
2400 -- where T is the task object, I is the entry index, P is the
2401 -- wrapped parameters and F is the status flag.
2404 Make_Procedure_Call_Statement
(Loc
,
2406 New_Reference_To
(RTE
(RE_Task_Entry_Call
), Loc
),
2407 Parameter_Associations
=>
2409 Make_Selected_Component
(Loc
, -- T._task_id
2410 Prefix
=> Make_Identifier
(Loc
, Name_uT
),
2411 Selector_Name
=> Make_Identifier
(Loc
, Name_uTask_Id
)),
2413 Make_Unchecked_Type_Conversion
(Loc
, -- entry index
2415 New_Reference_To
(RTE
(RE_Task_Entry_Index
), Loc
),
2416 Expression
=> Make_Identifier
(Loc
, Name_uI
)),
2418 Make_Identifier
(Loc
, Name_uP
), -- parameter block
2419 New_Reference_To
-- Asynchronous_Call
2420 (RTE
(RE_Asynchronous_Call
), Loc
),
2421 Make_Identifier
(Loc
, Name_uF
)))); -- status flag
2425 -- Ensure that the statements list is non-empty
2428 Make_Assignment_Statement
(Loc
,
2429 Name
=> Make_Identifier
(Loc
, Name_uF
),
2430 Expression
=> New_Reference_To
(Standard_False
, Loc
)));
2434 Make_Subprogram_Body
(Loc
,
2436 Make_Disp_Asynchronous_Select_Spec
(Typ
),
2437 Declarations
=> Decls
,
2438 Handled_Statement_Sequence
=>
2439 Make_Handled_Sequence_Of_Statements
(Loc
, Stmts
));
2440 end Make_Disp_Asynchronous_Select_Body
;
2442 ----------------------------------------
2443 -- Make_Disp_Asynchronous_Select_Spec --
2444 ----------------------------------------
2446 function Make_Disp_Asynchronous_Select_Spec
2447 (Typ
: Entity_Id
) return Node_Id
2449 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
2450 Def_Id
: constant Node_Id
:=
2451 Make_Defining_Identifier
(Loc
,
2452 Name_uDisp_Asynchronous_Select
);
2453 Params
: constant List_Id
:= New_List
;
2456 pragma Assert
(not Restriction_Active
(No_Dispatching_Calls
));
2458 -- T : in out Typ; -- Object parameter
2459 -- S : Integer; -- Primitive operation slot
2460 -- P : Address; -- Wrapped parameters
2461 -- B : out Dummy_Communication_Block; -- Communication block dummy
2462 -- F : out Boolean; -- Status flag
2464 Append_List_To
(Params
, New_List
(
2466 Make_Parameter_Specification
(Loc
,
2467 Defining_Identifier
=>
2468 Make_Defining_Identifier
(Loc
, Name_uT
),
2470 New_Reference_To
(Typ
, Loc
),
2472 Out_Present
=> True),
2474 Make_Parameter_Specification
(Loc
,
2475 Defining_Identifier
=>
2476 Make_Defining_Identifier
(Loc
, Name_uS
),
2478 New_Reference_To
(Standard_Integer
, Loc
)),
2480 Make_Parameter_Specification
(Loc
,
2481 Defining_Identifier
=>
2482 Make_Defining_Identifier
(Loc
, Name_uP
),
2484 New_Reference_To
(RTE
(RE_Address
), Loc
)),
2486 Make_Parameter_Specification
(Loc
,
2487 Defining_Identifier
=>
2488 Make_Defining_Identifier
(Loc
, Name_uB
),
2490 New_Reference_To
(RTE
(RE_Dummy_Communication_Block
), Loc
),
2491 Out_Present
=> True),
2493 Make_Parameter_Specification
(Loc
,
2494 Defining_Identifier
=>
2495 Make_Defining_Identifier
(Loc
, Name_uF
),
2497 New_Reference_To
(Standard_Boolean
, Loc
),
2498 Out_Present
=> True)));
2501 Make_Procedure_Specification
(Loc
,
2502 Defining_Unit_Name
=> Def_Id
,
2503 Parameter_Specifications
=> Params
);
2504 end Make_Disp_Asynchronous_Select_Spec
;
2506 ---------------------------------------
2507 -- Make_Disp_Conditional_Select_Body --
2508 ---------------------------------------
2510 -- For interface types, generate:
2512 -- procedure _Disp_Conditional_Select
2513 -- (T : in out <Typ>;
2515 -- P : System.Address;
2516 -- C : out Ada.Tags.Prim_Op_Kind;
2521 -- C := Ada.Tags.POK_Function;
2522 -- end _Disp_Conditional_Select;
2524 -- For protected types, generate:
2526 -- procedure _Disp_Conditional_Select
2527 -- (T : in out <Typ>;
2529 -- P : System.Address;
2530 -- C : out Ada.Tags.Prim_Op_Kind;
2534 -- Bnn : System.Tasking.Protected_Objects.Operations.
2535 -- Communication_Block;
2538 -- C := Ada.Tags.Get_Prim_Op_Kind (Ada.Tags.Tag (<Typ>VP, S));
2540 -- if C = Ada.Tags.POK_Procedure
2541 -- or else C = Ada.Tags.POK_Protected_Procedure
2542 -- or else C = Ada.Tags.POK_Task_Procedure
2548 -- I := Ada.Tags.Get_Entry_Index (Ada.Tags.Tag (<Typ>VP, S));
2549 -- System.Tasking.Protected_Objects.Operations.Protected_Entry_Call
2550 -- (T.object'Access,
2551 -- System.Tasking.Protected_Objects.Protected_Entry_Index (I),
2553 -- System.Tasking.Conditional_Call,
2555 -- F := not Cancelled (Bnn);
2556 -- end _Disp_Conditional_Select;
2558 -- For task types, generate:
2560 -- procedure _Disp_Conditional_Select
2561 -- (T : in out <Typ>;
2563 -- P : System.Address;
2564 -- C : out Ada.Tags.Prim_Op_Kind;
2570 -- I := Ada.Tags.Get_Entry_Index (Ada.Tags.Tag (<Typ>VP, S));
2571 -- System.Tasking.Rendezvous.Task_Entry_Call
2573 -- System.Tasking.Task_Entry_Index (I),
2575 -- System.Tasking.Conditional_Call,
2577 -- end _Disp_Conditional_Select;
2579 function Make_Disp_Conditional_Select_Body
2580 (Typ
: Entity_Id
) return Node_Id
2582 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
2583 Blk_Nam
: Entity_Id
;
2584 Conc_Typ
: Entity_Id
:= Empty
;
2585 Decls
: constant List_Id
:= New_List
;
2587 Stmts
: constant List_Id
:= New_List
;
2591 pragma Assert
(not Restriction_Active
(No_Dispatching_Calls
));
2593 -- Null body is generated for interface types
2595 if Is_Interface
(Typ
) then
2597 Make_Subprogram_Body
(Loc
,
2599 Make_Disp_Conditional_Select_Spec
(Typ
),
2602 Handled_Statement_Sequence
=>
2603 Make_Handled_Sequence_Of_Statements
(Loc
,
2604 New_List
(Make_Assignment_Statement
(Loc
,
2605 Name
=> Make_Identifier
(Loc
, Name_uF
),
2606 Expression
=> New_Reference_To
(Standard_False
, Loc
)))));
2609 if Is_Concurrent_Record_Type
(Typ
) then
2610 Conc_Typ
:= Corresponding_Concurrent_Type
(Typ
);
2615 -- where I will be used to capture the entry index of the primitive
2616 -- wrapper at position S.
2619 Make_Object_Declaration
(Loc
,
2620 Defining_Identifier
=>
2621 Make_Defining_Identifier
(Loc
, Name_uI
),
2622 Object_Definition
=>
2623 New_Reference_To
(Standard_Integer
, Loc
)));
2626 -- C := Ada.Tags.Get_Prim_Op_Kind (Ada.Tags.Tag! (<type>VP), S);
2628 -- if C = POK_Procedure
2629 -- or else C = POK_Protected_Procedure
2630 -- or else C = POK_Task_Procedure;
2636 Build_Common_Dispatching_Select_Statements
(Typ
, Stmts
);
2639 -- Bnn : Communication_Block;
2641 -- where Bnn is the name of the communication block used in the
2642 -- call to Protected_Entry_Call.
2644 Blk_Nam
:= Make_Temporary
(Loc
, 'B');
2646 Make_Object_Declaration
(Loc
,
2647 Defining_Identifier
=>
2649 Object_Definition
=>
2650 New_Reference_To
(RTE
(RE_Communication_Block
), Loc
)));
2653 -- I := Ada.Tags.Get_Entry_Index (Ada.Tags.Tag! (<type>VP), S);
2655 -- I is the entry index and S is the dispatch table slot
2657 if Tagged_Type_Expansion
then
2659 Unchecked_Convert_To
(RTE
(RE_Tag
),
2661 (Node
(First_Elmt
(Access_Disp_Table
(Typ
))), Loc
));
2665 Make_Attribute_Reference
(Loc
,
2666 Prefix
=> New_Reference_To
(Typ
, Loc
),
2667 Attribute_Name
=> Name_Tag
);
2671 Make_Assignment_Statement
(Loc
,
2672 Name
=> Make_Identifier
(Loc
, Name_uI
),
2674 Make_Function_Call
(Loc
,
2676 New_Reference_To
(RTE
(RE_Get_Entry_Index
), Loc
),
2677 Parameter_Associations
=>
2680 Make_Identifier
(Loc
, Name_uS
)))));
2682 if Ekind
(Conc_Typ
) = E_Protected_Type
then
2684 Obj_Ref
:= -- T._object'Access
2685 Make_Attribute_Reference
(Loc
,
2686 Attribute_Name
=> Name_Unchecked_Access
,
2688 Make_Selected_Component
(Loc
,
2689 Prefix
=> Make_Identifier
(Loc
, Name_uT
),
2690 Selector_Name
=> Make_Identifier
(Loc
, Name_uObject
)));
2692 case Corresponding_Runtime_Package
(Conc_Typ
) is
2693 when System_Tasking_Protected_Objects_Entries
=>
2696 -- Protected_Entry_Call
2697 -- (T._object'Access, -- Object
2698 -- Protected_Entry_Index! (I), -- E
2699 -- P, -- Uninterpreted_Data
2700 -- Conditional_Call, -- Mode
2703 -- where T is the protected object, I is the entry index, P
2704 -- are the wrapped parameters and Bnn is the name of the
2705 -- communication block.
2708 Make_Procedure_Call_Statement
(Loc
,
2710 New_Reference_To
(RTE
(RE_Protected_Entry_Call
), Loc
),
2711 Parameter_Associations
=>
2715 Make_Unchecked_Type_Conversion
(Loc
, -- entry index
2718 (RTE
(RE_Protected_Entry_Index
), Loc
),
2719 Expression
=> Make_Identifier
(Loc
, Name_uI
)),
2721 Make_Identifier
(Loc
, Name_uP
), -- parameter block
2723 New_Reference_To
( -- Conditional_Call
2724 RTE
(RE_Conditional_Call
), Loc
),
2725 New_Reference_To
( -- Bnn
2728 when System_Tasking_Protected_Objects_Single_Entry
=>
2730 -- If we are compiling for a restricted run-time, the call
2731 -- uses the simpler form.
2734 Make_Procedure_Call_Statement
(Loc
,
2737 (RTE
(RE_Protected_Single_Entry_Call
), Loc
),
2738 Parameter_Associations
=>
2742 Make_Attribute_Reference
(Loc
,
2743 Prefix
=> Make_Identifier
(Loc
, Name_uP
),
2744 Attribute_Name
=> Name_Address
),
2747 (RTE
(RE_Conditional_Call
), Loc
))));
2749 raise Program_Error
;
2753 -- F := not Cancelled (Bnn);
2755 -- where F is the success flag. The status of Cancelled is negated
2756 -- in order to match the behaviour of the version for task types.
2759 Make_Assignment_Statement
(Loc
,
2760 Name
=> Make_Identifier
(Loc
, Name_uF
),
2764 Make_Function_Call
(Loc
,
2766 New_Reference_To
(RTE
(RE_Cancelled
), Loc
),
2767 Parameter_Associations
=>
2769 New_Reference_To
(Blk_Nam
, Loc
))))));
2771 pragma Assert
(Ekind
(Conc_Typ
) = E_Task_Type
);
2775 -- (T._task_id, -- Acceptor
2776 -- Task_Entry_Index! (I), -- E
2777 -- P, -- Uninterpreted_Data
2778 -- Conditional_Call, -- Mode
2779 -- F); -- Rendezvous_Successful
2781 -- where T is the task object, I is the entry index, P are the
2782 -- wrapped parameters and F is the status flag.
2785 Make_Procedure_Call_Statement
(Loc
,
2787 New_Reference_To
(RTE
(RE_Task_Entry_Call
), Loc
),
2788 Parameter_Associations
=>
2791 Make_Selected_Component
(Loc
, -- T._task_id
2792 Prefix
=> Make_Identifier
(Loc
, Name_uT
),
2793 Selector_Name
=> Make_Identifier
(Loc
, Name_uTask_Id
)),
2795 Make_Unchecked_Type_Conversion
(Loc
, -- entry index
2797 New_Reference_To
(RTE
(RE_Task_Entry_Index
), Loc
),
2798 Expression
=> Make_Identifier
(Loc
, Name_uI
)),
2800 Make_Identifier
(Loc
, Name_uP
), -- parameter block
2801 New_Reference_To
-- Conditional_Call
2802 (RTE
(RE_Conditional_Call
), Loc
),
2803 Make_Identifier
(Loc
, Name_uF
)))); -- status flag
2807 -- Initialize out parameters
2810 Make_Assignment_Statement
(Loc
,
2811 Name
=> Make_Identifier
(Loc
, Name_uF
),
2812 Expression
=> New_Reference_To
(Standard_False
, Loc
)));
2814 Make_Assignment_Statement
(Loc
,
2815 Name
=> Make_Identifier
(Loc
, Name_uC
),
2816 Expression
=> New_Reference_To
(RTE
(RE_POK_Function
), Loc
)));
2820 Make_Subprogram_Body
(Loc
,
2822 Make_Disp_Conditional_Select_Spec
(Typ
),
2823 Declarations
=> Decls
,
2824 Handled_Statement_Sequence
=>
2825 Make_Handled_Sequence_Of_Statements
(Loc
, Stmts
));
2826 end Make_Disp_Conditional_Select_Body
;
2828 ---------------------------------------
2829 -- Make_Disp_Conditional_Select_Spec --
2830 ---------------------------------------
2832 function Make_Disp_Conditional_Select_Spec
2833 (Typ
: Entity_Id
) return Node_Id
2835 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
2836 Def_Id
: constant Node_Id
:=
2837 Make_Defining_Identifier
(Loc
,
2838 Name_uDisp_Conditional_Select
);
2839 Params
: constant List_Id
:= New_List
;
2842 pragma Assert
(not Restriction_Active
(No_Dispatching_Calls
));
2844 -- T : in out Typ; -- Object parameter
2845 -- S : Integer; -- Primitive operation slot
2846 -- P : Address; -- Wrapped parameters
2847 -- C : out Prim_Op_Kind; -- Call kind
2848 -- F : out Boolean; -- Status flag
2850 Append_List_To
(Params
, New_List
(
2852 Make_Parameter_Specification
(Loc
,
2853 Defining_Identifier
=>
2854 Make_Defining_Identifier
(Loc
, Name_uT
),
2856 New_Reference_To
(Typ
, Loc
),
2858 Out_Present
=> True),
2860 Make_Parameter_Specification
(Loc
,
2861 Defining_Identifier
=>
2862 Make_Defining_Identifier
(Loc
, Name_uS
),
2864 New_Reference_To
(Standard_Integer
, Loc
)),
2866 Make_Parameter_Specification
(Loc
,
2867 Defining_Identifier
=>
2868 Make_Defining_Identifier
(Loc
, Name_uP
),
2870 New_Reference_To
(RTE
(RE_Address
), Loc
)),
2872 Make_Parameter_Specification
(Loc
,
2873 Defining_Identifier
=>
2874 Make_Defining_Identifier
(Loc
, Name_uC
),
2876 New_Reference_To
(RTE
(RE_Prim_Op_Kind
), Loc
),
2877 Out_Present
=> True),
2879 Make_Parameter_Specification
(Loc
,
2880 Defining_Identifier
=>
2881 Make_Defining_Identifier
(Loc
, Name_uF
),
2883 New_Reference_To
(Standard_Boolean
, Loc
),
2884 Out_Present
=> True)));
2887 Make_Procedure_Specification
(Loc
,
2888 Defining_Unit_Name
=> Def_Id
,
2889 Parameter_Specifications
=> Params
);
2890 end Make_Disp_Conditional_Select_Spec
;
2892 -------------------------------------
2893 -- Make_Disp_Get_Prim_Op_Kind_Body --
2894 -------------------------------------
2896 function Make_Disp_Get_Prim_Op_Kind_Body
2897 (Typ
: Entity_Id
) return Node_Id
2899 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
2903 pragma Assert
(not Restriction_Active
(No_Dispatching_Calls
));
2905 if Is_Interface
(Typ
) then
2907 Make_Subprogram_Body
(Loc
,
2909 Make_Disp_Get_Prim_Op_Kind_Spec
(Typ
),
2912 Handled_Statement_Sequence
=>
2913 Make_Handled_Sequence_Of_Statements
(Loc
,
2914 New_List
(Make_Null_Statement
(Loc
))));
2918 -- C := get_prim_op_kind (tag! (<type>VP), S);
2920 -- where C is the out parameter capturing the call kind and S is the
2921 -- dispatch table slot number.
2923 if Tagged_Type_Expansion
then
2925 Unchecked_Convert_To
(RTE
(RE_Tag
),
2927 (Node
(First_Elmt
(Access_Disp_Table
(Typ
))), Loc
));
2931 Make_Attribute_Reference
(Loc
,
2932 Prefix
=> New_Reference_To
(Typ
, Loc
),
2933 Attribute_Name
=> Name_Tag
);
2937 Make_Subprogram_Body
(Loc
,
2939 Make_Disp_Get_Prim_Op_Kind_Spec
(Typ
),
2942 Handled_Statement_Sequence
=>
2943 Make_Handled_Sequence_Of_Statements
(Loc
,
2945 Make_Assignment_Statement
(Loc
,
2947 Make_Identifier
(Loc
, Name_uC
),
2949 Make_Function_Call
(Loc
,
2951 New_Reference_To
(RTE
(RE_Get_Prim_Op_Kind
), Loc
),
2952 Parameter_Associations
=> New_List
(
2954 Make_Identifier
(Loc
, Name_uS
)))))));
2955 end Make_Disp_Get_Prim_Op_Kind_Body
;
2957 -------------------------------------
2958 -- Make_Disp_Get_Prim_Op_Kind_Spec --
2959 -------------------------------------
2961 function Make_Disp_Get_Prim_Op_Kind_Spec
2962 (Typ
: Entity_Id
) return Node_Id
2964 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
2965 Def_Id
: constant Node_Id
:=
2966 Make_Defining_Identifier
(Loc
,
2967 Name_uDisp_Get_Prim_Op_Kind
);
2968 Params
: constant List_Id
:= New_List
;
2971 pragma Assert
(not Restriction_Active
(No_Dispatching_Calls
));
2973 -- T : in out Typ; -- Object parameter
2974 -- S : Integer; -- Primitive operation slot
2975 -- C : out Prim_Op_Kind; -- Call kind
2977 Append_List_To
(Params
, New_List
(
2979 Make_Parameter_Specification
(Loc
,
2980 Defining_Identifier
=>
2981 Make_Defining_Identifier
(Loc
, Name_uT
),
2983 New_Reference_To
(Typ
, Loc
),
2985 Out_Present
=> True),
2987 Make_Parameter_Specification
(Loc
,
2988 Defining_Identifier
=>
2989 Make_Defining_Identifier
(Loc
, Name_uS
),
2991 New_Reference_To
(Standard_Integer
, Loc
)),
2993 Make_Parameter_Specification
(Loc
,
2994 Defining_Identifier
=>
2995 Make_Defining_Identifier
(Loc
, Name_uC
),
2997 New_Reference_To
(RTE
(RE_Prim_Op_Kind
), Loc
),
2998 Out_Present
=> True)));
3001 Make_Procedure_Specification
(Loc
,
3002 Defining_Unit_Name
=> Def_Id
,
3003 Parameter_Specifications
=> Params
);
3004 end Make_Disp_Get_Prim_Op_Kind_Spec
;
3006 --------------------------------
3007 -- Make_Disp_Get_Task_Id_Body --
3008 --------------------------------
3010 function Make_Disp_Get_Task_Id_Body
3011 (Typ
: Entity_Id
) return Node_Id
3013 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
3017 pragma Assert
(not Restriction_Active
(No_Dispatching_Calls
));
3019 if Is_Concurrent_Record_Type
(Typ
)
3020 and then Ekind
(Corresponding_Concurrent_Type
(Typ
)) = E_Task_Type
3023 -- return To_Address (_T._task_id);
3026 Make_Simple_Return_Statement
(Loc
,
3028 Make_Unchecked_Type_Conversion
(Loc
,
3030 New_Reference_To
(RTE
(RE_Address
), Loc
),
3032 Make_Selected_Component
(Loc
,
3033 Prefix
=> Make_Identifier
(Loc
, Name_uT
),
3034 Selector_Name
=> Make_Identifier
(Loc
, Name_uTask_Id
))));
3036 -- A null body is constructed for non-task types
3040 -- return Null_Address;
3043 Make_Simple_Return_Statement
(Loc
,
3045 New_Reference_To
(RTE
(RE_Null_Address
), Loc
));
3049 Make_Subprogram_Body
(Loc
,
3051 Make_Disp_Get_Task_Id_Spec
(Typ
),
3054 Handled_Statement_Sequence
=>
3055 Make_Handled_Sequence_Of_Statements
(Loc
,
3057 end Make_Disp_Get_Task_Id_Body
;
3059 --------------------------------
3060 -- Make_Disp_Get_Task_Id_Spec --
3061 --------------------------------
3063 function Make_Disp_Get_Task_Id_Spec
3064 (Typ
: Entity_Id
) return Node_Id
3066 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
3069 pragma Assert
(not Restriction_Active
(No_Dispatching_Calls
));
3072 Make_Function_Specification
(Loc
,
3073 Defining_Unit_Name
=>
3074 Make_Defining_Identifier
(Loc
, Name_uDisp_Get_Task_Id
),
3075 Parameter_Specifications
=> New_List
(
3076 Make_Parameter_Specification
(Loc
,
3077 Defining_Identifier
=>
3078 Make_Defining_Identifier
(Loc
, Name_uT
),
3080 New_Reference_To
(Typ
, Loc
))),
3081 Result_Definition
=>
3082 New_Reference_To
(RTE
(RE_Address
), Loc
));
3083 end Make_Disp_Get_Task_Id_Spec
;
3085 ----------------------------
3086 -- Make_Disp_Requeue_Body --
3087 ----------------------------
3089 function Make_Disp_Requeue_Body
3090 (Typ
: Entity_Id
) return Node_Id
3092 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
3093 Conc_Typ
: Entity_Id
:= Empty
;
3094 Stmts
: constant List_Id
:= New_List
;
3097 pragma Assert
(not Restriction_Active
(No_Dispatching_Calls
));
3099 -- Null body is generated for interface types and non-concurrent
3102 if Is_Interface
(Typ
)
3103 or else not Is_Concurrent_Record_Type
(Typ
)
3106 Make_Subprogram_Body
(Loc
,
3108 Make_Disp_Requeue_Spec
(Typ
),
3111 Handled_Statement_Sequence
=>
3112 Make_Handled_Sequence_Of_Statements
(Loc
,
3113 New_List
(Make_Null_Statement
(Loc
))));
3116 Conc_Typ
:= Corresponding_Concurrent_Type
(Typ
);
3118 if Ekind
(Conc_Typ
) = E_Protected_Type
then
3120 -- Generate statements:
3122 -- System.Tasking.Protected_Objects.Operations.
3123 -- Requeue_Protected_Entry
3124 -- (Protection_Entries_Access (P),
3125 -- O._object'Unchecked_Access,
3126 -- Protected_Entry_Index (I),
3129 -- System.Tasking.Protected_Objects.Operations.
3130 -- Requeue_Task_To_Protected_Entry
3131 -- (O._object'Unchecked_Access,
3132 -- Protected_Entry_Index (I),
3136 if Restriction_Active
(No_Entry_Queue
) then
3137 Append_To
(Stmts
, Make_Null_Statement
(Loc
));
3140 Make_If_Statement
(Loc
,
3141 Condition
=> Make_Identifier
(Loc
, Name_uF
),
3146 -- Call to Requeue_Protected_Entry
3148 Make_Procedure_Call_Statement
(Loc
,
3151 RTE
(RE_Requeue_Protected_Entry
), Loc
),
3152 Parameter_Associations
=>
3155 Make_Unchecked_Type_Conversion
(Loc
, -- PEA (P)
3158 RTE
(RE_Protection_Entries_Access
), Loc
),
3160 Make_Identifier
(Loc
, Name_uP
)),
3162 Make_Attribute_Reference
(Loc
, -- O._object'Acc
3164 Name_Unchecked_Access
,
3166 Make_Selected_Component
(Loc
,
3168 Make_Identifier
(Loc
, Name_uO
),
3170 Make_Identifier
(Loc
, Name_uObject
))),
3172 Make_Unchecked_Type_Conversion
(Loc
, -- entry index
3175 RTE
(RE_Protected_Entry_Index
), Loc
),
3176 Expression
=> Make_Identifier
(Loc
, Name_uI
)),
3178 Make_Identifier
(Loc
, Name_uA
)))), -- abort status
3183 -- Call to Requeue_Task_To_Protected_Entry
3185 Make_Procedure_Call_Statement
(Loc
,
3188 RTE
(RE_Requeue_Task_To_Protected_Entry
), Loc
),
3189 Parameter_Associations
=>
3192 Make_Attribute_Reference
(Loc
, -- O._object'Acc
3194 Name_Unchecked_Access
,
3196 Make_Selected_Component
(Loc
,
3198 Make_Identifier
(Loc
, Name_uO
),
3200 Make_Identifier
(Loc
, Name_uObject
))),
3202 Make_Unchecked_Type_Conversion
(Loc
, -- entry index
3205 RTE
(RE_Protected_Entry_Index
), Loc
),
3207 Make_Identifier
(Loc
, Name_uI
)),
3209 Make_Identifier
(Loc
, Name_uA
)))))); -- abort status
3212 pragma Assert
(Is_Task_Type
(Conc_Typ
));
3216 -- System.Tasking.Rendezvous.Requeue_Protected_To_Task_Entry
3217 -- (Protection_Entries_Access (P),
3219 -- Task_Entry_Index (I),
3222 -- System.Tasking.Rendezvous.Requeue_Task_Entry
3224 -- Task_Entry_Index (I),
3229 Make_If_Statement
(Loc
,
3230 Condition
=> Make_Identifier
(Loc
, Name_uF
),
3232 Then_Statements
=> New_List
(
3234 -- Call to Requeue_Protected_To_Task_Entry
3236 Make_Procedure_Call_Statement
(Loc
,
3239 (RTE
(RE_Requeue_Protected_To_Task_Entry
), Loc
),
3241 Parameter_Associations
=> New_List
(
3243 Make_Unchecked_Type_Conversion
(Loc
, -- PEA (P)
3246 (RTE
(RE_Protection_Entries_Access
), Loc
),
3247 Expression
=> Make_Identifier
(Loc
, Name_uP
)),
3249 Make_Selected_Component
(Loc
, -- O._task_id
3250 Prefix
=> Make_Identifier
(Loc
, Name_uO
),
3251 Selector_Name
=> Make_Identifier
(Loc
, Name_uTask_Id
)),
3253 Make_Unchecked_Type_Conversion
(Loc
, -- entry index
3255 New_Reference_To
(RTE
(RE_Task_Entry_Index
), Loc
),
3256 Expression
=> Make_Identifier
(Loc
, Name_uI
)),
3258 Make_Identifier
(Loc
, Name_uA
)))), -- abort status
3260 Else_Statements
=> New_List
(
3262 -- Call to Requeue_Task_Entry
3264 Make_Procedure_Call_Statement
(Loc
,
3265 Name
=> New_Reference_To
(RTE
(RE_Requeue_Task_Entry
), Loc
),
3267 Parameter_Associations
=> New_List
(
3269 Make_Selected_Component
(Loc
, -- O._task_id
3270 Prefix
=> Make_Identifier
(Loc
, Name_uO
),
3271 Selector_Name
=> Make_Identifier
(Loc
, Name_uTask_Id
)),
3273 Make_Unchecked_Type_Conversion
(Loc
, -- entry index
3275 New_Reference_To
(RTE
(RE_Task_Entry_Index
), Loc
),
3276 Expression
=> Make_Identifier
(Loc
, Name_uI
)),
3278 Make_Identifier
(Loc
, Name_uA
)))))); -- abort status
3281 -- Even though no declarations are needed in both cases, we allocate
3282 -- a list for entities added by Freeze.
3285 Make_Subprogram_Body
(Loc
,
3287 Make_Disp_Requeue_Spec
(Typ
),
3290 Handled_Statement_Sequence
=>
3291 Make_Handled_Sequence_Of_Statements
(Loc
, Stmts
));
3292 end Make_Disp_Requeue_Body
;
3294 ----------------------------
3295 -- Make_Disp_Requeue_Spec --
3296 ----------------------------
3298 function Make_Disp_Requeue_Spec
3299 (Typ
: Entity_Id
) return Node_Id
3301 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
3304 pragma Assert
(not Restriction_Active
(No_Dispatching_Calls
));
3306 -- O : in out Typ; - Object parameter
3307 -- F : Boolean; - Protected (True) / task (False) flag
3308 -- P : Address; - Protection_Entries_Access value
3309 -- I : Entry_Index - Index of entry call
3310 -- A : Boolean - Abort flag
3312 -- Note that the Protection_Entries_Access value is represented as a
3313 -- System.Address in order to avoid dragging in the tasking runtime
3314 -- when compiling sources without tasking constructs.
3317 Make_Procedure_Specification
(Loc
,
3318 Defining_Unit_Name
=>
3319 Make_Defining_Identifier
(Loc
, Name_uDisp_Requeue
),
3321 Parameter_Specifications
=>
3324 Make_Parameter_Specification
(Loc
, -- O
3325 Defining_Identifier
=>
3326 Make_Defining_Identifier
(Loc
, Name_uO
),
3328 New_Reference_To
(Typ
, Loc
),
3330 Out_Present
=> True),
3332 Make_Parameter_Specification
(Loc
, -- F
3333 Defining_Identifier
=>
3334 Make_Defining_Identifier
(Loc
, Name_uF
),
3336 New_Reference_To
(Standard_Boolean
, Loc
)),
3338 Make_Parameter_Specification
(Loc
, -- P
3339 Defining_Identifier
=>
3340 Make_Defining_Identifier
(Loc
, Name_uP
),
3342 New_Reference_To
(RTE
(RE_Address
), Loc
)),
3344 Make_Parameter_Specification
(Loc
, -- I
3345 Defining_Identifier
=>
3346 Make_Defining_Identifier
(Loc
, Name_uI
),
3348 New_Reference_To
(Standard_Integer
, Loc
)),
3350 Make_Parameter_Specification
(Loc
, -- A
3351 Defining_Identifier
=>
3352 Make_Defining_Identifier
(Loc
, Name_uA
),
3354 New_Reference_To
(Standard_Boolean
, Loc
))));
3355 end Make_Disp_Requeue_Spec
;
3357 ---------------------------------
3358 -- Make_Disp_Timed_Select_Body --
3359 ---------------------------------
3361 -- For interface types, generate:
3363 -- procedure _Disp_Timed_Select
3364 -- (T : in out <Typ>;
3366 -- P : System.Address;
3369 -- C : out Ada.Tags.Prim_Op_Kind;
3374 -- C := Ada.Tags.POK_Function;
3375 -- end _Disp_Timed_Select;
3377 -- For protected types, generate:
3379 -- procedure _Disp_Timed_Select
3380 -- (T : in out <Typ>;
3382 -- P : System.Address;
3385 -- C : out Ada.Tags.Prim_Op_Kind;
3391 -- C := Ada.Tags.Get_Prim_Op_Kind (Ada.Tags.Tag (<Typ>VP), S);
3393 -- if C = Ada.Tags.POK_Procedure
3394 -- or else C = Ada.Tags.POK_Protected_Procedure
3395 -- or else C = Ada.Tags.POK_Task_Procedure
3401 -- I := Ada.Tags.Get_Entry_Index (Ada.Tags.Tag (<Typ>VP), S);
3402 -- System.Tasking.Protected_Objects.Operations.
3403 -- Timed_Protected_Entry_Call
3404 -- (T._object'Access,
3405 -- System.Tasking.Protected_Objects.Protected_Entry_Index (I),
3410 -- end _Disp_Timed_Select;
3412 -- For task types, generate:
3414 -- procedure _Disp_Timed_Select
3415 -- (T : in out <Typ>;
3417 -- P : System.Address;
3420 -- C : out Ada.Tags.Prim_Op_Kind;
3426 -- I := Ada.Tags.Get_Entry_Index (Ada.Tags.Tag (<Typ>VP), S);
3427 -- System.Tasking.Rendezvous.Timed_Task_Entry_Call
3429 -- System.Tasking.Task_Entry_Index (I),
3434 -- end _Disp_Time_Select;
3436 function Make_Disp_Timed_Select_Body
3437 (Typ
: Entity_Id
) return Node_Id
3439 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
3440 Conc_Typ
: Entity_Id
:= Empty
;
3441 Decls
: constant List_Id
:= New_List
;
3443 Stmts
: constant List_Id
:= New_List
;
3447 pragma Assert
(not Restriction_Active
(No_Dispatching_Calls
));
3449 -- Null body is generated for interface types
3451 if Is_Interface
(Typ
) then
3453 Make_Subprogram_Body
(Loc
,
3455 Make_Disp_Timed_Select_Spec
(Typ
),
3458 Handled_Statement_Sequence
=>
3459 Make_Handled_Sequence_Of_Statements
(Loc
,
3461 Make_Assignment_Statement
(Loc
,
3462 Name
=> Make_Identifier
(Loc
, Name_uF
),
3463 Expression
=> New_Reference_To
(Standard_False
, Loc
)))));
3466 if Is_Concurrent_Record_Type
(Typ
) then
3467 Conc_Typ
:= Corresponding_Concurrent_Type
(Typ
);
3472 -- where I will be used to capture the entry index of the primitive
3473 -- wrapper at position S.
3476 Make_Object_Declaration
(Loc
,
3477 Defining_Identifier
=> Make_Defining_Identifier
(Loc
, Name_uI
),
3478 Object_Definition
=> New_Reference_To
(Standard_Integer
, Loc
)));
3481 -- C := Get_Prim_Op_Kind (tag! (<type>VP), S);
3483 -- if C = POK_Procedure
3484 -- or else C = POK_Protected_Procedure
3485 -- or else C = POK_Task_Procedure;
3491 Build_Common_Dispatching_Select_Statements
(Typ
, Stmts
);
3494 -- I := Get_Entry_Index (tag! (<type>VP), S);
3496 -- I is the entry index and S is the dispatch table slot
3498 if Tagged_Type_Expansion
then
3500 Unchecked_Convert_To
(RTE
(RE_Tag
),
3502 (Node
(First_Elmt
(Access_Disp_Table
(Typ
))), Loc
));
3506 Make_Attribute_Reference
(Loc
,
3507 Prefix
=> New_Reference_To
(Typ
, Loc
),
3508 Attribute_Name
=> Name_Tag
);
3512 Make_Assignment_Statement
(Loc
,
3513 Name
=> Make_Identifier
(Loc
, Name_uI
),
3515 Make_Function_Call
(Loc
,
3516 Name
=> New_Reference_To
(RTE
(RE_Get_Entry_Index
), Loc
),
3517 Parameter_Associations
=>
3520 Make_Identifier
(Loc
, Name_uS
)))));
3524 if Ekind
(Conc_Typ
) = E_Protected_Type
then
3526 -- Build T._object'Access
3529 Make_Attribute_Reference
(Loc
,
3530 Attribute_Name
=> Name_Unchecked_Access
,
3532 Make_Selected_Component
(Loc
,
3533 Prefix
=> Make_Identifier
(Loc
, Name_uT
),
3534 Selector_Name
=> Make_Identifier
(Loc
, Name_uObject
)));
3536 -- Normal case, No_Entry_Queue restriction not active. In this
3537 -- case we generate:
3539 -- Timed_Protected_Entry_Call
3540 -- (T._object'access,
3541 -- Protected_Entry_Index! (I),
3544 -- where T is the protected object, I is the entry index, P are
3545 -- the wrapped parameters, D is the delay amount, M is the delay
3546 -- mode and F is the status flag.
3548 case Corresponding_Runtime_Package
(Conc_Typ
) is
3549 when System_Tasking_Protected_Objects_Entries
=>
3551 Make_Procedure_Call_Statement
(Loc
,
3554 (RTE
(RE_Timed_Protected_Entry_Call
), Loc
),
3555 Parameter_Associations
=>
3559 Make_Unchecked_Type_Conversion
(Loc
, -- entry index
3562 (RTE
(RE_Protected_Entry_Index
), Loc
),
3564 Make_Identifier
(Loc
, Name_uI
)),
3566 Make_Identifier
(Loc
, Name_uP
), -- parameter block
3567 Make_Identifier
(Loc
, Name_uD
), -- delay
3568 Make_Identifier
(Loc
, Name_uM
), -- delay mode
3569 Make_Identifier
(Loc
, Name_uF
)))); -- status flag
3571 when System_Tasking_Protected_Objects_Single_Entry
=>
3574 -- Timed_Protected_Single_Entry_Call
3575 -- (T._object'access, P, D, M, F);
3577 -- where T is the protected object, P is the wrapped
3578 -- parameters, D is the delay amount, M is the delay mode, F
3579 -- is the status flag.
3582 Make_Procedure_Call_Statement
(Loc
,
3585 (RTE
(RE_Timed_Protected_Single_Entry_Call
), Loc
),
3586 Parameter_Associations
=>
3589 Make_Identifier
(Loc
, Name_uP
), -- parameter block
3590 Make_Identifier
(Loc
, Name_uD
), -- delay
3591 Make_Identifier
(Loc
, Name_uM
), -- delay mode
3592 Make_Identifier
(Loc
, Name_uF
)))); -- status flag
3595 raise Program_Error
;
3601 pragma Assert
(Ekind
(Conc_Typ
) = E_Task_Type
);
3604 -- Timed_Task_Entry_Call (
3606 -- Task_Entry_Index! (I),
3612 -- where T is the task object, I is the entry index, P are the
3613 -- wrapped parameters, D is the delay amount, M is the delay
3614 -- mode and F is the status flag.
3617 Make_Procedure_Call_Statement
(Loc
,
3619 New_Reference_To
(RTE
(RE_Timed_Task_Entry_Call
), Loc
),
3620 Parameter_Associations
=>
3623 Make_Selected_Component
(Loc
, -- T._task_id
3624 Prefix
=> Make_Identifier
(Loc
, Name_uT
),
3625 Selector_Name
=> Make_Identifier
(Loc
, Name_uTask_Id
)),
3627 Make_Unchecked_Type_Conversion
(Loc
, -- entry index
3629 New_Reference_To
(RTE
(RE_Task_Entry_Index
), Loc
),
3630 Expression
=> Make_Identifier
(Loc
, Name_uI
)),
3632 Make_Identifier
(Loc
, Name_uP
), -- parameter block
3633 Make_Identifier
(Loc
, Name_uD
), -- delay
3634 Make_Identifier
(Loc
, Name_uM
), -- delay mode
3635 Make_Identifier
(Loc
, Name_uF
)))); -- status flag
3639 -- Initialize out parameters
3642 Make_Assignment_Statement
(Loc
,
3643 Name
=> Make_Identifier
(Loc
, Name_uF
),
3644 Expression
=> New_Reference_To
(Standard_False
, Loc
)));
3646 Make_Assignment_Statement
(Loc
,
3647 Name
=> Make_Identifier
(Loc
, Name_uC
),
3648 Expression
=> New_Reference_To
(RTE
(RE_POK_Function
), Loc
)));
3652 Make_Subprogram_Body
(Loc
,
3653 Specification
=> Make_Disp_Timed_Select_Spec
(Typ
),
3654 Declarations
=> Decls
,
3655 Handled_Statement_Sequence
=>
3656 Make_Handled_Sequence_Of_Statements
(Loc
, Stmts
));
3657 end Make_Disp_Timed_Select_Body
;
3659 ---------------------------------
3660 -- Make_Disp_Timed_Select_Spec --
3661 ---------------------------------
3663 function Make_Disp_Timed_Select_Spec
3664 (Typ
: Entity_Id
) return Node_Id
3666 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
3667 Def_Id
: constant Node_Id
:=
3668 Make_Defining_Identifier
(Loc
,
3669 Name_uDisp_Timed_Select
);
3670 Params
: constant List_Id
:= New_List
;
3673 pragma Assert
(not Restriction_Active
(No_Dispatching_Calls
));
3675 -- T : in out Typ; -- Object parameter
3676 -- S : Integer; -- Primitive operation slot
3677 -- P : Address; -- Wrapped parameters
3678 -- D : Duration; -- Delay
3679 -- M : Integer; -- Delay Mode
3680 -- C : out Prim_Op_Kind; -- Call kind
3681 -- F : out Boolean; -- Status flag
3683 Append_List_To
(Params
, New_List
(
3685 Make_Parameter_Specification
(Loc
,
3686 Defining_Identifier
=>
3687 Make_Defining_Identifier
(Loc
, Name_uT
),
3689 New_Reference_To
(Typ
, Loc
),
3691 Out_Present
=> True),
3693 Make_Parameter_Specification
(Loc
,
3694 Defining_Identifier
=>
3695 Make_Defining_Identifier
(Loc
, Name_uS
),
3697 New_Reference_To
(Standard_Integer
, Loc
)),
3699 Make_Parameter_Specification
(Loc
,
3700 Defining_Identifier
=>
3701 Make_Defining_Identifier
(Loc
, Name_uP
),
3703 New_Reference_To
(RTE
(RE_Address
), Loc
)),
3705 Make_Parameter_Specification
(Loc
,
3706 Defining_Identifier
=>
3707 Make_Defining_Identifier
(Loc
, Name_uD
),
3709 New_Reference_To
(Standard_Duration
, Loc
)),
3711 Make_Parameter_Specification
(Loc
,
3712 Defining_Identifier
=>
3713 Make_Defining_Identifier
(Loc
, Name_uM
),
3715 New_Reference_To
(Standard_Integer
, Loc
)),
3717 Make_Parameter_Specification
(Loc
,
3718 Defining_Identifier
=>
3719 Make_Defining_Identifier
(Loc
, Name_uC
),
3721 New_Reference_To
(RTE
(RE_Prim_Op_Kind
), Loc
),
3722 Out_Present
=> True)));
3725 Make_Parameter_Specification
(Loc
,
3726 Defining_Identifier
=>
3727 Make_Defining_Identifier
(Loc
, Name_uF
),
3729 New_Reference_To
(Standard_Boolean
, Loc
),
3730 Out_Present
=> True));
3733 Make_Procedure_Specification
(Loc
,
3734 Defining_Unit_Name
=> Def_Id
,
3735 Parameter_Specifications
=> Params
);
3736 end Make_Disp_Timed_Select_Spec
;
3742 -- The frontend supports two models for expanding dispatch tables
3743 -- associated with library-level defined tagged types: statically
3744 -- and non-statically allocated dispatch tables. In the former case
3745 -- the object containing the dispatch table is constant and it is
3746 -- initialized by means of a positional aggregate. In the latter case,
3747 -- the object containing the dispatch table is a variable which is
3748 -- initialized by means of assignments.
3750 -- In case of locally defined tagged types, the object containing the
3751 -- object containing the dispatch table is always a variable (instead
3752 -- of a constant). This is currently required to give support to late
3753 -- overriding of primitives. For example:
3755 -- procedure Example is
3757 -- type T1 is tagged null record;
3758 -- procedure Prim (O : T1);
3761 -- type T2 is new Pkg.T1 with null record;
3762 -- procedure Prim (X : T2) is -- late overriding
3768 function Make_DT
(Typ
: Entity_Id
; N
: Node_Id
:= Empty
) return List_Id
is
3769 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
3771 Max_Predef_Prims
: constant Int
:=
3775 (Parent
(RTE
(RE_Max_Predef_Prims
)))));
3777 DT_Decl
: constant Elist_Id
:= New_Elmt_List
;
3778 DT_Aggr
: constant Elist_Id
:= New_Elmt_List
;
3779 -- Entities marked with attribute Is_Dispatch_Table_Entity
3781 procedure Check_Premature_Freezing
3783 Tagged_Type
: Entity_Id
;
3785 -- Verify that all non-tagged types in the profile of a subprogram
3786 -- are frozen at the point the subprogram is frozen. This enforces
3787 -- the rule on RM 13.14 (14) as modified by AI05-019. At the point a
3788 -- subprogram is frozen, enough must be known about it to build the
3789 -- activation record for it, which requires at least that the size of
3790 -- all parameters be known. Controlling arguments are by-reference,
3791 -- and therefore the rule only applies to non-tagged types.
3792 -- Typical violation of the rule involves an object declaration that
3793 -- freezes a tagged type, when one of its primitive operations has a
3794 -- type in its profile whose full view has not been analyzed yet.
3795 -- More complex cases involve composite types that have one private
3796 -- unfrozen subcomponent.
3798 procedure Export_DT
(Typ
: Entity_Id
; DT
: Entity_Id
; Index
: Nat
:= 0);
3799 -- Export the dispatch table DT of tagged type Typ. Required to generate
3800 -- forward references and statically allocate the table. For primary
3801 -- dispatch tables Index is 0; for secondary dispatch tables the value
3802 -- of index must match the Suffix_Index value assigned to the table by
3803 -- Make_Tags when generating its unique external name, and it is used to
3804 -- retrieve from the Dispatch_Table_Wrappers list associated with Typ
3805 -- the external name generated by Import_DT.
3807 procedure Make_Secondary_DT
3811 Num_Iface_Prims
: Nat
;
3812 Iface_DT_Ptr
: Entity_Id
;
3813 Predef_Prims_Ptr
: Entity_Id
;
3814 Build_Thunks
: Boolean;
3816 -- Ada 2005 (AI-251): Expand the declarations for a Secondary Dispatch
3817 -- Table of Typ associated with Iface. Each abstract interface of Typ
3818 -- has two secondary dispatch tables: one containing pointers to thunks
3819 -- and another containing pointers to the primitives covering the
3820 -- interface primitives. The former secondary table is generated when
3821 -- Build_Thunks is True, and provides common support for dispatching
3822 -- calls through interface types; the latter secondary table is
3823 -- generated when Build_Thunks is False, and provides support for
3824 -- Generic Dispatching Constructors that dispatch calls through
3825 -- interface types. When constructing this latter table the value of
3826 -- Suffix_Index is -1 to indicate that there is no need to export such
3827 -- table when building statically allocated dispatch tables; a positive
3828 -- value of Suffix_Index must match the Suffix_Index value assigned to
3829 -- this secondary dispatch table by Make_Tags when its unique external
3830 -- name was generated.
3832 ------------------------------
3833 -- Check_Premature_Freezing --
3834 ------------------------------
3836 procedure Check_Premature_Freezing
3838 Tagged_Type
: Entity_Id
;
3843 function Is_Actual_For_Formal_Incomplete_Type
3844 (T
: Entity_Id
) return Boolean;
3845 -- In Ada 2012, if a nested generic has an incomplete formal type,
3846 -- the actual may be (and usually is) a private type whose completion
3847 -- appears later. It is safe to build the dispatch table in this
3848 -- case, gigi will have full views available.
3850 ------------------------------------------
3851 -- Is_Actual_For_Formal_Incomplete_Type --
3852 ------------------------------------------
3854 function Is_Actual_For_Formal_Incomplete_Type
3855 (T
: Entity_Id
) return Boolean
3857 Gen_Par
: Entity_Id
;
3861 if not Is_Generic_Instance
(Current_Scope
)
3862 or else not Used_As_Generic_Actual
(T
)
3867 Gen_Par
:= Generic_Parent
(Parent
(Current_Scope
));
3872 (Generic_Formal_Declarations
3873 (Unit_Declaration_Node
(Gen_Par
)));
3874 while Present
(F
) loop
3875 if Ekind
(Defining_Identifier
(F
)) = E_Incomplete_Type
then
3883 end Is_Actual_For_Formal_Incomplete_Type
;
3885 -- Start of processing for Check_Premature_Freezing
3888 -- Note that if the type is a (subtype of) a generic actual, the
3889 -- actual will have been frozen by the instantiation.
3892 and then Is_Private_Type
(Typ
)
3893 and then No
(Full_View
(Typ
))
3894 and then not Is_Generic_Type
(Typ
)
3895 and then not Is_Tagged_Type
(Typ
)
3896 and then not Is_Frozen
(Typ
)
3897 and then not Is_Generic_Actual_Type
(Typ
)
3899 Error_Msg_Sloc
:= Sloc
(Subp
);
3901 ("declaration must appear after completion of type &", N
, Typ
);
3903 ("\which is an untagged type in the profile of"
3904 & " primitive operation & declared#", N
, Subp
);
3907 Comp
:= Private_Component
(Typ
);
3909 if not Is_Tagged_Type
(Typ
)
3910 and then Present
(Comp
)
3911 and then not Is_Frozen
(Comp
)
3913 not Is_Actual_For_Formal_Incomplete_Type
(Comp
)
3915 Error_Msg_Sloc
:= Sloc
(Subp
);
3916 Error_Msg_Node_2
:= Subp
;
3917 Error_Msg_Name_1
:= Chars
(Tagged_Type
);
3919 ("declaration must appear after completion of type &",
3922 ("\which is a component of untagged type& in the profile of"
3923 & " primitive & of type % that is frozen by the declaration ",
3927 end Check_Premature_Freezing
;
3933 procedure Export_DT
(Typ
: Entity_Id
; DT
: Entity_Id
; Index
: Nat
:= 0)
3939 Set_Is_Statically_Allocated
(DT
);
3940 Set_Is_True_Constant
(DT
);
3941 Set_Is_Exported
(DT
);
3944 Elmt
:= First_Elmt
(Dispatch_Table_Wrappers
(Typ
));
3945 while Count
/= Index
loop
3950 pragma Assert
(Related_Type
(Node
(Elmt
)) = Typ
);
3953 (Entity
=> Node
(Elmt
),
3954 Has_Suffix
=> True);
3956 Set_Interface_Name
(DT
,
3957 Make_String_Literal
(Loc
,
3958 Strval
=> String_From_Name_Buffer
));
3960 -- Ensure proper Sprint output of this implicit importation
3962 Set_Is_Internal
(DT
);
3966 -----------------------
3967 -- Make_Secondary_DT --
3968 -----------------------
3970 procedure Make_Secondary_DT
3974 Num_Iface_Prims
: Nat
;
3975 Iface_DT_Ptr
: Entity_Id
;
3976 Predef_Prims_Ptr
: Entity_Id
;
3977 Build_Thunks
: Boolean;
3980 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
3981 Exporting_Table
: constant Boolean :=
3982 Building_Static_DT
(Typ
)
3983 and then Suffix_Index
> 0;
3984 Iface_DT
: constant Entity_Id
:= Make_Temporary
(Loc
, 'T');
3985 Predef_Prims
: constant Entity_Id
:= Make_Temporary
(Loc
, 'R');
3986 DT_Constr_List
: List_Id
;
3987 DT_Aggr_List
: List_Id
;
3988 Empty_DT
: Boolean := False;
3989 Nb_Predef_Prims
: Nat
:= 0;
3993 OSD_Aggr_List
: List_Id
;
3996 Prim_Elmt
: Elmt_Id
;
3997 Prim_Ops_Aggr_List
: List_Id
;
4000 -- Handle cases in which we do not generate statically allocated
4003 if not Building_Static_DT
(Typ
) then
4004 Set_Ekind
(Predef_Prims
, E_Variable
);
4005 Set_Ekind
(Iface_DT
, E_Variable
);
4007 -- Statically allocated dispatch tables and related entities are
4011 Set_Ekind
(Predef_Prims
, E_Constant
);
4012 Set_Is_Statically_Allocated
(Predef_Prims
);
4013 Set_Is_True_Constant
(Predef_Prims
);
4015 Set_Ekind
(Iface_DT
, E_Constant
);
4016 Set_Is_Statically_Allocated
(Iface_DT
);
4017 Set_Is_True_Constant
(Iface_DT
);
4020 -- Calculate the number of slots of the dispatch table. If the number
4021 -- of primitives of Typ is 0 we reserve a dummy single entry for its
4022 -- DT because at run time the pointer to this dummy entry will be
4025 if Num_Iface_Prims
= 0 then
4029 Nb_Prim
:= Num_Iface_Prims
;
4034 -- Predef_Prims : Address_Array (1 .. Default_Prim_Ops_Count) :=
4035 -- (predef-prim-op-thunk-1'address,
4036 -- predef-prim-op-thunk-2'address,
4038 -- predef-prim-op-thunk-n'address);
4039 -- for Predef_Prims'Alignment use Address'Alignment
4041 -- Stage 1: Calculate the number of predefined primitives
4043 if not Building_Static_DT
(Typ
) then
4044 Nb_Predef_Prims
:= Max_Predef_Prims
;
4046 Prim_Elmt
:= First_Elmt
(Primitive_Operations
(Typ
));
4047 while Present
(Prim_Elmt
) loop
4048 Prim
:= Node
(Prim_Elmt
);
4050 if Is_Predefined_Dispatching_Operation
(Prim
)
4051 and then not Is_Abstract_Subprogram
(Prim
)
4053 Pos
:= UI_To_Int
(DT_Position
(Prim
));
4055 if Pos
> Nb_Predef_Prims
then
4056 Nb_Predef_Prims
:= Pos
;
4060 Next_Elmt
(Prim_Elmt
);
4064 -- Stage 2: Create the thunks associated with the predefined
4065 -- primitives and save their entity to fill the aggregate.
4068 Prim_Table
: array (Nat
range 1 .. Nb_Predef_Prims
) of Entity_Id
;
4070 Thunk_Id
: Entity_Id
;
4071 Thunk_Code
: Node_Id
;
4074 Prim_Ops_Aggr_List
:= New_List
;
4075 Prim_Table
:= (others => Empty
);
4077 if Building_Static_DT
(Typ
) then
4078 Prim_Elmt
:= First_Elmt
(Primitive_Operations
(Typ
));
4079 while Present
(Prim_Elmt
) loop
4080 Prim
:= Node
(Prim_Elmt
);
4082 if Is_Predefined_Dispatching_Operation
(Prim
)
4083 and then not Is_Abstract_Subprogram
(Prim
)
4084 and then not Is_Eliminated
(Prim
)
4085 and then not Present
(Prim_Table
4086 (UI_To_Int
(DT_Position
(Prim
))))
4088 if not Build_Thunks
then
4089 Prim_Table
(UI_To_Int
(DT_Position
(Prim
))) :=
4093 Expand_Interface_Thunk
4094 (Ultimate_Alias
(Prim
), Thunk_Id
, Thunk_Code
);
4096 if Present
(Thunk_Id
) then
4097 Append_To
(Result
, Thunk_Code
);
4098 Prim_Table
(UI_To_Int
(DT_Position
(Prim
)))
4104 Next_Elmt
(Prim_Elmt
);
4108 for J
in Prim_Table
'Range loop
4109 if Present
(Prim_Table
(J
)) then
4111 Unchecked_Convert_To
(RTE
(RE_Prim_Ptr
),
4112 Make_Attribute_Reference
(Loc
,
4113 Prefix
=> New_Reference_To
(Prim_Table
(J
), Loc
),
4114 Attribute_Name
=> Name_Unrestricted_Access
));
4116 New_Node
:= Make_Null
(Loc
);
4119 Append_To
(Prim_Ops_Aggr_List
, New_Node
);
4123 Make_Aggregate
(Loc
,
4124 Expressions
=> Prim_Ops_Aggr_List
);
4126 -- Remember aggregates initializing dispatch tables
4128 Append_Elmt
(New_Node
, DT_Aggr
);
4131 Make_Subtype_Declaration
(Loc
,
4132 Defining_Identifier
=> Make_Temporary
(Loc
, 'S'),
4133 Subtype_Indication
=>
4134 New_Reference_To
(RTE
(RE_Address_Array
), Loc
));
4136 Append_To
(Result
, Decl
);
4139 Make_Object_Declaration
(Loc
,
4140 Defining_Identifier
=> Predef_Prims
,
4141 Constant_Present
=> Building_Static_DT
(Typ
),
4142 Aliased_Present
=> True,
4143 Object_Definition
=> New_Reference_To
4144 (Defining_Identifier
(Decl
), Loc
),
4145 Expression
=> New_Node
));
4148 Make_Attribute_Definition_Clause
(Loc
,
4149 Name
=> New_Reference_To
(Predef_Prims
, Loc
),
4150 Chars
=> Name_Alignment
,
4152 Make_Attribute_Reference
(Loc
,
4154 New_Reference_To
(RTE
(RE_Integer_Address
), Loc
),
4155 Attribute_Name
=> Name_Alignment
)));
4160 -- OSD : Ada.Tags.Object_Specific_Data (Nb_Prims) :=
4161 -- (OSD_Table => (1 => <value>,
4165 -- Iface_DT : Dispatch_Table (Nb_Prims) :=
4166 -- ([ Signature => <sig-value> ],
4167 -- Tag_Kind => <tag_kind-value>,
4168 -- Predef_Prims => Predef_Prims'Address,
4169 -- Offset_To_Top => 0,
4170 -- OSD => OSD'Address,
4171 -- Prims_Ptr => (prim-op-1'address,
4172 -- prim-op-2'address,
4174 -- prim-op-n'address));
4175 -- for Iface_DT'Alignment use Address'Alignment;
4177 -- Stage 3: Initialize the discriminant and the record components
4179 DT_Constr_List
:= New_List
;
4180 DT_Aggr_List
:= New_List
;
4184 Append_To
(DT_Constr_List
, Make_Integer_Literal
(Loc
, Nb_Prim
));
4185 Append_To
(DT_Aggr_List
, Make_Integer_Literal
(Loc
, Nb_Prim
));
4189 if RTE_Record_Component_Available
(RE_Signature
) then
4190 Append_To
(DT_Aggr_List
,
4191 New_Reference_To
(RTE
(RE_Secondary_DT
), Loc
));
4196 if RTE_Record_Component_Available
(RE_Tag_Kind
) then
4197 Append_To
(DT_Aggr_List
, Tagged_Kind
(Typ
));
4202 Append_To
(DT_Aggr_List
,
4203 Make_Attribute_Reference
(Loc
,
4204 Prefix
=> New_Reference_To
(Predef_Prims
, Loc
),
4205 Attribute_Name
=> Name_Address
));
4207 -- Note: The correct value of Offset_To_Top will be set by the init
4210 Append_To
(DT_Aggr_List
, Make_Integer_Literal
(Loc
, 0));
4212 -- Generate the Object Specific Data table required to dispatch calls
4213 -- through synchronized interfaces.
4216 or else Is_Abstract_Type
(Typ
)
4217 or else Is_Controlled
(Typ
)
4218 or else Restriction_Active
(No_Dispatching_Calls
)
4219 or else not Is_Limited_Type
(Typ
)
4220 or else not Has_Interfaces
(Typ
)
4221 or else not Build_Thunks
4222 or else not RTE_Record_Component_Available
(RE_OSD_Table
)
4224 -- No OSD table required
4226 Append_To
(DT_Aggr_List
,
4227 New_Reference_To
(RTE
(RE_Null_Address
), Loc
));
4230 OSD_Aggr_List
:= New_List
;
4233 Prim_Table
: array (Nat
range 1 .. Nb_Prim
) of Entity_Id
;
4235 Prim_Alias
: Entity_Id
;
4236 Prim_Elmt
: Elmt_Id
;
4242 Prim_Table
:= (others => Empty
);
4243 Prim_Alias
:= Empty
;
4245 Prim_Elmt
:= First_Elmt
(Primitive_Operations
(Typ
));
4246 while Present
(Prim_Elmt
) loop
4247 Prim
:= Node
(Prim_Elmt
);
4249 if Present
(Interface_Alias
(Prim
))
4250 and then Find_Dispatching_Type
4251 (Interface_Alias
(Prim
)) = Iface
4253 Prim_Alias
:= Interface_Alias
(Prim
);
4254 E
:= Ultimate_Alias
(Prim
);
4255 Pos
:= UI_To_Int
(DT_Position
(Prim_Alias
));
4257 if Present
(Prim_Table
(Pos
)) then
4258 pragma Assert
(Prim_Table
(Pos
) = E
);
4262 Prim_Table
(Pos
) := E
;
4264 Append_To
(OSD_Aggr_List
,
4265 Make_Component_Association
(Loc
,
4266 Choices
=> New_List
(
4267 Make_Integer_Literal
(Loc
,
4268 DT_Position
(Prim_Alias
))),
4270 Make_Integer_Literal
(Loc
,
4271 DT_Position
(Alias
(Prim
)))));
4277 Next_Elmt
(Prim_Elmt
);
4279 pragma Assert
(Count
= Nb_Prim
);
4282 OSD
:= Make_Temporary
(Loc
, 'I');
4285 Make_Object_Declaration
(Loc
,
4286 Defining_Identifier
=> OSD
,
4287 Object_Definition
=>
4288 Make_Subtype_Indication
(Loc
,
4290 New_Reference_To
(RTE
(RE_Object_Specific_Data
), Loc
),
4292 Make_Index_Or_Discriminant_Constraint
(Loc
,
4293 Constraints
=> New_List
(
4294 Make_Integer_Literal
(Loc
, Nb_Prim
)))),
4297 Make_Aggregate
(Loc
,
4298 Component_Associations
=> New_List
(
4299 Make_Component_Association
(Loc
,
4300 Choices
=> New_List
(
4302 (RTE_Record_Component
(RE_OSD_Num_Prims
), Loc
)),
4304 Make_Integer_Literal
(Loc
, Nb_Prim
)),
4306 Make_Component_Association
(Loc
,
4307 Choices
=> New_List
(
4309 (RTE_Record_Component
(RE_OSD_Table
), Loc
)),
4310 Expression
=> Make_Aggregate
(Loc
,
4311 Component_Associations
=> OSD_Aggr_List
))))));
4314 Make_Attribute_Definition_Clause
(Loc
,
4315 Name
=> New_Reference_To
(OSD
, Loc
),
4316 Chars
=> Name_Alignment
,
4318 Make_Attribute_Reference
(Loc
,
4320 New_Reference_To
(RTE
(RE_Integer_Address
), Loc
),
4321 Attribute_Name
=> Name_Alignment
)));
4323 -- In secondary dispatch tables the Typeinfo component contains
4324 -- the address of the Object Specific Data (see a-tags.ads)
4326 Append_To
(DT_Aggr_List
,
4327 Make_Attribute_Reference
(Loc
,
4328 Prefix
=> New_Reference_To
(OSD
, Loc
),
4329 Attribute_Name
=> Name_Address
));
4332 -- Initialize the table of primitive operations
4334 Prim_Ops_Aggr_List
:= New_List
;
4337 Append_To
(Prim_Ops_Aggr_List
, Make_Null
(Loc
));
4339 elsif Is_Abstract_Type
(Typ
)
4340 or else not Building_Static_DT
(Typ
)
4342 for J
in 1 .. Nb_Prim
loop
4343 Append_To
(Prim_Ops_Aggr_List
, Make_Null
(Loc
));
4348 CPP_Nb_Prims
: constant Nat
:= CPP_Num_Prims
(Typ
);
4351 Prim_Table
: array (Nat
range 1 .. Nb_Prim
) of Entity_Id
;
4352 Thunk_Code
: Node_Id
;
4353 Thunk_Id
: Entity_Id
;
4356 Prim_Table
:= (others => Empty
);
4358 Prim_Elmt
:= First_Elmt
(Primitive_Operations
(Typ
));
4359 while Present
(Prim_Elmt
) loop
4360 Prim
:= Node
(Prim_Elmt
);
4361 E
:= Ultimate_Alias
(Prim
);
4362 Prim_Pos
:= UI_To_Int
(DT_Position
(E
));
4364 -- Do not reference predefined primitives because they are
4365 -- located in a separate dispatch table; skip abstract and
4366 -- eliminated primitives; skip primitives located in the C++
4367 -- part of the dispatch table because their slot is set by
4370 if not Is_Predefined_Dispatching_Operation
(Prim
)
4371 and then Present
(Interface_Alias
(Prim
))
4372 and then not Is_Abstract_Subprogram
(Alias
(Prim
))
4373 and then not Is_Eliminated
(Alias
(Prim
))
4374 and then (not Is_CPP_Class
(Root_Type
(Typ
))
4375 or else Prim_Pos
> CPP_Nb_Prims
)
4376 and then Find_Dispatching_Type
4377 (Interface_Alias
(Prim
)) = Iface
4379 -- Generate the code of the thunk only if the abstract
4380 -- interface type is not an immediate ancestor of
4381 -- Tagged_Type. Otherwise the DT associated with the
4382 -- interface is the primary DT.
4384 and then not Is_Ancestor
(Iface
, Typ
,
4385 Use_Full_View
=> True)
4387 if not Build_Thunks
then
4389 UI_To_Int
(DT_Position
(Interface_Alias
(Prim
)));
4390 Prim_Table
(Prim_Pos
) := Alias
(Prim
);
4393 Expand_Interface_Thunk
(Prim
, Thunk_Id
, Thunk_Code
);
4395 if Present
(Thunk_Id
) then
4397 UI_To_Int
(DT_Position
(Interface_Alias
(Prim
)));
4399 Prim_Table
(Prim_Pos
) := Thunk_Id
;
4400 Append_To
(Result
, Thunk_Code
);
4405 Next_Elmt
(Prim_Elmt
);
4408 for J
in Prim_Table
'Range loop
4409 if Present
(Prim_Table
(J
)) then
4411 Unchecked_Convert_To
(RTE
(RE_Prim_Ptr
),
4412 Make_Attribute_Reference
(Loc
,
4413 Prefix
=> New_Reference_To
(Prim_Table
(J
), Loc
),
4414 Attribute_Name
=> Name_Unrestricted_Access
));
4417 New_Node
:= Make_Null
(Loc
);
4420 Append_To
(Prim_Ops_Aggr_List
, New_Node
);
4426 Make_Aggregate
(Loc
,
4427 Expressions
=> Prim_Ops_Aggr_List
);
4429 Append_To
(DT_Aggr_List
, New_Node
);
4431 -- Remember aggregates initializing dispatch tables
4433 Append_Elmt
(New_Node
, DT_Aggr
);
4435 -- Note: Secondary dispatch tables cannot be declared constant
4436 -- because the component Offset_To_Top is currently initialized
4437 -- by the IP routine.
4440 Make_Object_Declaration
(Loc
,
4441 Defining_Identifier
=> Iface_DT
,
4442 Aliased_Present
=> True,
4443 Constant_Present
=> False,
4445 Object_Definition
=>
4446 Make_Subtype_Indication
(Loc
,
4447 Subtype_Mark
=> New_Reference_To
4448 (RTE
(RE_Dispatch_Table_Wrapper
), Loc
),
4449 Constraint
=> Make_Index_Or_Discriminant_Constraint
(Loc
,
4450 Constraints
=> DT_Constr_List
)),
4453 Make_Aggregate
(Loc
,
4454 Expressions
=> DT_Aggr_List
)));
4457 Make_Attribute_Definition_Clause
(Loc
,
4458 Name
=> New_Reference_To
(Iface_DT
, Loc
),
4459 Chars
=> Name_Alignment
,
4462 Make_Attribute_Reference
(Loc
,
4464 New_Reference_To
(RTE
(RE_Integer_Address
), Loc
),
4465 Attribute_Name
=> Name_Alignment
)));
4467 if Exporting_Table
then
4468 Export_DT
(Typ
, Iface_DT
, Suffix_Index
);
4470 -- Generate code to create the pointer to the dispatch table
4472 -- Iface_DT_Ptr : Tag := Tag!(DT.Prims_Ptr'Address);
4474 -- Note: This declaration is not added here if the table is exported
4475 -- because in such case Make_Tags has already added this declaration.
4479 Make_Object_Declaration
(Loc
,
4480 Defining_Identifier
=> Iface_DT_Ptr
,
4481 Constant_Present
=> True,
4483 Object_Definition
=>
4484 New_Reference_To
(RTE
(RE_Interface_Tag
), Loc
),
4487 Unchecked_Convert_To
(RTE
(RE_Interface_Tag
),
4488 Make_Attribute_Reference
(Loc
,
4490 Make_Selected_Component
(Loc
,
4491 Prefix
=> New_Reference_To
(Iface_DT
, Loc
),
4494 (RTE_Record_Component
(RE_Prims_Ptr
), Loc
)),
4495 Attribute_Name
=> Name_Address
))));
4499 Make_Object_Declaration
(Loc
,
4500 Defining_Identifier
=> Predef_Prims_Ptr
,
4501 Constant_Present
=> True,
4503 Object_Definition
=>
4504 New_Reference_To
(RTE
(RE_Address
), Loc
),
4507 Make_Attribute_Reference
(Loc
,
4509 Make_Selected_Component
(Loc
,
4510 Prefix
=> New_Reference_To
(Iface_DT
, Loc
),
4513 (RTE_Record_Component
(RE_Predef_Prims
), Loc
)),
4514 Attribute_Name
=> Name_Address
)));
4516 -- Remember entities containing dispatch tables
4518 Append_Elmt
(Predef_Prims
, DT_Decl
);
4519 Append_Elmt
(Iface_DT
, DT_Decl
);
4520 end Make_Secondary_DT
;
4524 Elab_Code
: constant List_Id
:= New_List
;
4525 Result
: constant List_Id
:= New_List
;
4526 Tname
: constant Name_Id
:= Chars
(Typ
);
4528 AI_Tag_Elmt
: Elmt_Id
;
4529 AI_Tag_Comp
: Elmt_Id
;
4530 DT_Aggr_List
: List_Id
;
4531 DT_Constr_List
: List_Id
;
4535 Iface_Table_Node
: Node_Id
;
4536 Name_ITable
: Name_Id
;
4537 Nb_Predef_Prims
: Nat
:= 0;
4540 Num_Ifaces
: Nat
:= 0;
4541 Parent_Typ
: Entity_Id
;
4543 Prim_Elmt
: Elmt_Id
;
4544 Prim_Ops_Aggr_List
: List_Id
;
4546 Typ_Comps
: Elist_Id
;
4547 Typ_Ifaces
: Elist_Id
;
4548 TSD_Aggr_List
: List_Id
;
4549 TSD_Tags_List
: List_Id
;
4551 -- The following name entries are used by Make_DT to generate a number
4552 -- of entities related to a tagged type. These entities may be generated
4553 -- in a scope other than that of the tagged type declaration, and if
4554 -- the entities for two tagged types with the same name happen to be
4555 -- generated in the same scope, we have to take care to use different
4556 -- names. This is achieved by means of a unique serial number appended
4557 -- to each generated entity name.
4559 Name_DT
: constant Name_Id
:=
4560 New_External_Name
(Tname
, 'T', Suffix_Index
=> -1);
4561 Name_Exname
: constant Name_Id
:=
4562 New_External_Name
(Tname
, 'E', Suffix_Index
=> -1);
4563 Name_HT_Link
: constant Name_Id
:=
4564 New_External_Name
(Tname
, 'H', Suffix_Index
=> -1);
4565 Name_Predef_Prims
: constant Name_Id
:=
4566 New_External_Name
(Tname
, 'R', Suffix_Index
=> -1);
4567 Name_SSD
: constant Name_Id
:=
4568 New_External_Name
(Tname
, 'S', Suffix_Index
=> -1);
4569 Name_TSD
: constant Name_Id
:=
4570 New_External_Name
(Tname
, 'B', Suffix_Index
=> -1);
4572 -- Entities built with above names
4574 DT
: constant Entity_Id
:=
4575 Make_Defining_Identifier
(Loc
, Name_DT
);
4576 Exname
: constant Entity_Id
:=
4577 Make_Defining_Identifier
(Loc
, Name_Exname
);
4578 HT_Link
: constant Entity_Id
:=
4579 Make_Defining_Identifier
(Loc
, Name_HT_Link
);
4580 Predef_Prims
: constant Entity_Id
:=
4581 Make_Defining_Identifier
(Loc
, Name_Predef_Prims
);
4582 SSD
: constant Entity_Id
:=
4583 Make_Defining_Identifier
(Loc
, Name_SSD
);
4584 TSD
: constant Entity_Id
:=
4585 Make_Defining_Identifier
(Loc
, Name_TSD
);
4587 -- Start of processing for Make_DT
4590 pragma Assert
(Is_Frozen
(Typ
));
4592 -- Handle cases in which there is no need to build the dispatch table
4594 if Has_Dispatch_Table
(Typ
)
4595 or else No
(Access_Disp_Table
(Typ
))
4596 or else Is_CPP_Class
(Typ
)
4597 or else Convention
(Typ
) = Convention_CIL
4598 or else Convention
(Typ
) = Convention_Java
4602 elsif No_Run_Time_Mode
then
4603 Error_Msg_CRT
("tagged types", Typ
);
4606 elsif not RTE_Available
(RE_Tag
) then
4608 Make_Object_Declaration
(Loc
,
4609 Defining_Identifier
=> Node
(First_Elmt
4610 (Access_Disp_Table
(Typ
))),
4611 Object_Definition
=> New_Reference_To
(RTE
(RE_Tag
), Loc
),
4612 Constant_Present
=> True,
4614 Unchecked_Convert_To
(RTE
(RE_Tag
),
4615 New_Reference_To
(RTE
(RE_Null_Address
), Loc
))));
4617 Analyze_List
(Result
, Suppress
=> All_Checks
);
4618 Error_Msg_CRT
("tagged types", Typ
);
4622 -- Ensure that the value of Max_Predef_Prims defined in a-tags is
4623 -- correct. Valid values are 9 under configurable runtime or 15
4624 -- with full runtime.
4626 if RTE_Available
(RE_Interface_Data
) then
4627 if Max_Predef_Prims
/= 15 then
4628 Error_Msg_N
("run-time library configuration error", Typ
);
4632 if Max_Predef_Prims
/= 9 then
4633 Error_Msg_N
("run-time library configuration error", Typ
);
4634 Error_Msg_CRT
("tagged types", Typ
);
4639 -- Initialize Parent_Typ handling private types
4641 Parent_Typ
:= Etype
(Typ
);
4643 if Present
(Full_View
(Parent_Typ
)) then
4644 Parent_Typ
:= Full_View
(Parent_Typ
);
4647 -- Ensure that all the primitives are frozen. This is only required when
4648 -- building static dispatch tables --- the primitives must be frozen to
4649 -- be referenced (otherwise we have problems with the backend). It is
4650 -- not a requirement with nonstatic dispatch tables because in this case
4651 -- we generate now an empty dispatch table; the extra code required to
4652 -- register the primitives in the slots will be generated later --- when
4653 -- each primitive is frozen (see Freeze_Subprogram).
4655 if Building_Static_DT
(Typ
) then
4657 Save
: constant Boolean := Freezing_Library_Level_Tagged_Type
;
4659 Prim_Elmt
: Elmt_Id
;
4663 Freezing_Library_Level_Tagged_Type
:= True;
4665 Prim_Elmt
:= First_Elmt
(Primitive_Operations
(Typ
));
4666 while Present
(Prim_Elmt
) loop
4667 Prim
:= Node
(Prim_Elmt
);
4668 Frnodes
:= Freeze_Entity
(Prim
, Typ
);
4674 F
:= First_Formal
(Prim
);
4675 while Present
(F
) loop
4676 Check_Premature_Freezing
(Prim
, Typ
, Etype
(F
));
4680 Check_Premature_Freezing
(Prim
, Typ
, Etype
(Prim
));
4683 if Present
(Frnodes
) then
4684 Append_List_To
(Result
, Frnodes
);
4687 Next_Elmt
(Prim_Elmt
);
4690 Freezing_Library_Level_Tagged_Type
:= Save
;
4694 -- Ada 2005 (AI-251): Build the secondary dispatch tables
4696 if Has_Interfaces
(Typ
) then
4697 Collect_Interface_Components
(Typ
, Typ_Comps
);
4699 -- Each secondary dispatch table is assigned an unique positive
4700 -- suffix index; such value also corresponds with the location of
4701 -- its entity in the Dispatch_Table_Wrappers list (see Make_Tags).
4703 -- Note: This value must be kept sync with the Suffix_Index values
4704 -- generated by Make_Tags
4708 Next_Elmt
(Next_Elmt
(First_Elmt
(Access_Disp_Table
(Typ
))));
4710 AI_Tag_Comp
:= First_Elmt
(Typ_Comps
);
4711 while Present
(AI_Tag_Comp
) loop
4712 pragma Assert
(Has_Suffix
(Node
(AI_Tag_Elmt
), 'P'));
4714 -- Build the secondary table containing pointers to thunks
4718 Iface
=> Base_Type
(Related_Type
(Node
(AI_Tag_Comp
))),
4719 Suffix_Index
=> Suffix_Index
,
4720 Num_Iface_Prims
=> UI_To_Int
4721 (DT_Entry_Count
(Node
(AI_Tag_Comp
))),
4722 Iface_DT_Ptr
=> Node
(AI_Tag_Elmt
),
4723 Predef_Prims_Ptr
=> Node
(Next_Elmt
(AI_Tag_Elmt
)),
4724 Build_Thunks
=> True,
4727 -- Skip secondary dispatch table referencing thunks to predefined
4730 Next_Elmt
(AI_Tag_Elmt
);
4731 pragma Assert
(Has_Suffix
(Node
(AI_Tag_Elmt
), 'Y'));
4733 -- Secondary dispatch table referencing user-defined primitives
4734 -- covered by this interface.
4736 Next_Elmt
(AI_Tag_Elmt
);
4737 pragma Assert
(Has_Suffix
(Node
(AI_Tag_Elmt
), 'D'));
4739 -- Build the secondary table containing pointers to primitives
4740 -- (used to give support to Generic Dispatching Constructors).
4745 (Related_Type
(Node
(AI_Tag_Comp
))),
4747 Num_Iface_Prims
=> UI_To_Int
4748 (DT_Entry_Count
(Node
(AI_Tag_Comp
))),
4749 Iface_DT_Ptr
=> Node
(AI_Tag_Elmt
),
4750 Predef_Prims_Ptr
=> Node
(Next_Elmt
(AI_Tag_Elmt
)),
4751 Build_Thunks
=> False,
4754 -- Skip secondary dispatch table referencing predefined primitives
4756 Next_Elmt
(AI_Tag_Elmt
);
4757 pragma Assert
(Has_Suffix
(Node
(AI_Tag_Elmt
), 'Z'));
4759 Suffix_Index
:= Suffix_Index
+ 1;
4760 Next_Elmt
(AI_Tag_Elmt
);
4761 Next_Elmt
(AI_Tag_Comp
);
4765 -- Get the _tag entity and number of primitives of its dispatch table
4767 DT_Ptr
:= Node
(First_Elmt
(Access_Disp_Table
(Typ
)));
4768 Nb_Prim
:= UI_To_Int
(DT_Entry_Count
(First_Tag_Component
(Typ
)));
4770 Set_Is_Statically_Allocated
(DT
, Is_Library_Level_Tagged_Type
(Typ
));
4771 Set_Is_Statically_Allocated
(SSD
, Is_Library_Level_Tagged_Type
(Typ
));
4772 Set_Is_Statically_Allocated
(TSD
, Is_Library_Level_Tagged_Type
(Typ
));
4773 Set_Is_Statically_Allocated
(Predef_Prims
,
4774 Is_Library_Level_Tagged_Type
(Typ
));
4776 -- In case of locally defined tagged type we declare the object
4777 -- containing the dispatch table by means of a variable. Its
4778 -- initialization is done later by means of an assignment. This is
4779 -- required to generate its External_Tag.
4781 if not Building_Static_DT
(Typ
) then
4784 -- DT : No_Dispatch_Table_Wrapper;
4785 -- for DT'Alignment use Address'Alignment;
4786 -- DT_Ptr : Tag := !Tag (DT.NDT_Prims_Ptr'Address);
4788 if not Has_DT
(Typ
) then
4790 Make_Object_Declaration
(Loc
,
4791 Defining_Identifier
=> DT
,
4792 Aliased_Present
=> True,
4793 Constant_Present
=> False,
4794 Object_Definition
=>
4796 (RTE
(RE_No_Dispatch_Table_Wrapper
), Loc
)));
4799 Make_Attribute_Definition_Clause
(Loc
,
4800 Name
=> New_Reference_To
(DT
, Loc
),
4801 Chars
=> Name_Alignment
,
4803 Make_Attribute_Reference
(Loc
,
4805 New_Reference_To
(RTE
(RE_Integer_Address
), Loc
),
4806 Attribute_Name
=> Name_Alignment
)));
4809 Make_Object_Declaration
(Loc
,
4810 Defining_Identifier
=> DT_Ptr
,
4811 Object_Definition
=> New_Reference_To
(RTE
(RE_Tag
), Loc
),
4812 Constant_Present
=> True,
4814 Unchecked_Convert_To
(RTE
(RE_Tag
),
4815 Make_Attribute_Reference
(Loc
,
4817 Make_Selected_Component
(Loc
,
4818 Prefix
=> New_Reference_To
(DT
, Loc
),
4821 (RTE_Record_Component
(RE_NDT_Prims_Ptr
), Loc
)),
4822 Attribute_Name
=> Name_Address
))));
4824 Set_Is_Statically_Allocated
(DT_Ptr
,
4825 Is_Library_Level_Tagged_Type
(Typ
));
4827 -- Generate the SCIL node for the previous object declaration
4828 -- because it has a tag initialization.
4830 if Generate_SCIL
then
4832 Make_SCIL_Dispatch_Table_Tag_Init
(Sloc
(Last
(Result
)));
4833 Set_SCIL_Entity
(New_Node
, Typ
);
4834 Set_SCIL_Node
(Last
(Result
), New_Node
);
4838 -- DT : Dispatch_Table_Wrapper (Nb_Prim);
4839 -- for DT'Alignment use Address'Alignment;
4840 -- DT_Ptr : Tag := !Tag (DT.Prims_Ptr'Address);
4843 -- If the tagged type has no primitives we add a dummy slot
4844 -- whose address will be the tag of this type.
4848 New_List
(Make_Integer_Literal
(Loc
, 1));
4851 New_List
(Make_Integer_Literal
(Loc
, Nb_Prim
));
4855 Make_Object_Declaration
(Loc
,
4856 Defining_Identifier
=> DT
,
4857 Aliased_Present
=> True,
4858 Constant_Present
=> False,
4859 Object_Definition
=>
4860 Make_Subtype_Indication
(Loc
,
4862 New_Reference_To
(RTE
(RE_Dispatch_Table_Wrapper
), Loc
),
4863 Constraint
=> Make_Index_Or_Discriminant_Constraint
(Loc
,
4864 Constraints
=> DT_Constr_List
))));
4867 Make_Attribute_Definition_Clause
(Loc
,
4868 Name
=> New_Reference_To
(DT
, Loc
),
4869 Chars
=> Name_Alignment
,
4871 Make_Attribute_Reference
(Loc
,
4873 New_Reference_To
(RTE
(RE_Integer_Address
), Loc
),
4874 Attribute_Name
=> Name_Alignment
)));
4877 Make_Object_Declaration
(Loc
,
4878 Defining_Identifier
=> DT_Ptr
,
4879 Object_Definition
=> New_Reference_To
(RTE
(RE_Tag
), Loc
),
4880 Constant_Present
=> True,
4882 Unchecked_Convert_To
(RTE
(RE_Tag
),
4883 Make_Attribute_Reference
(Loc
,
4885 Make_Selected_Component
(Loc
,
4886 Prefix
=> New_Reference_To
(DT
, Loc
),
4889 (RTE_Record_Component
(RE_Prims_Ptr
), Loc
)),
4890 Attribute_Name
=> Name_Address
))));
4892 Set_Is_Statically_Allocated
(DT_Ptr
,
4893 Is_Library_Level_Tagged_Type
(Typ
));
4895 -- Generate the SCIL node for the previous object declaration
4896 -- because it has a tag initialization.
4898 if Generate_SCIL
then
4900 Make_SCIL_Dispatch_Table_Tag_Init
(Sloc
(Last
(Result
)));
4901 Set_SCIL_Entity
(New_Node
, Typ
);
4902 Set_SCIL_Node
(Last
(Result
), New_Node
);
4906 Make_Object_Declaration
(Loc
,
4907 Defining_Identifier
=>
4908 Node
(Next_Elmt
(First_Elmt
(Access_Disp_Table
(Typ
)))),
4909 Constant_Present
=> True,
4910 Object_Definition
=> New_Reference_To
4911 (RTE
(RE_Address
), Loc
),
4913 Make_Attribute_Reference
(Loc
,
4915 Make_Selected_Component
(Loc
,
4916 Prefix
=> New_Reference_To
(DT
, Loc
),
4919 (RTE_Record_Component
(RE_Predef_Prims
), Loc
)),
4920 Attribute_Name
=> Name_Address
)));
4924 -- Generate: Exname : constant String := full_qualified_name (typ);
4925 -- The type itself may be an anonymous parent type, so use the first
4926 -- subtype to have a user-recognizable name.
4929 Make_Object_Declaration
(Loc
,
4930 Defining_Identifier
=> Exname
,
4931 Constant_Present
=> True,
4932 Object_Definition
=> New_Reference_To
(Standard_String
, Loc
),
4934 Make_String_Literal
(Loc
,
4935 Fully_Qualified_Name_String
(First_Subtype
(Typ
)))));
4937 Set_Is_Statically_Allocated
(Exname
);
4938 Set_Is_True_Constant
(Exname
);
4940 -- Declare the object used by Ada.Tags.Register_Tag
4942 if RTE_Available
(RE_Register_Tag
) then
4944 Make_Object_Declaration
(Loc
,
4945 Defining_Identifier
=> HT_Link
,
4946 Object_Definition
=> New_Reference_To
(RTE
(RE_Tag
), Loc
)));
4949 -- Generate code to create the storage for the type specific data object
4950 -- with enough space to store the tags of the ancestors plus the tags
4951 -- of all the implemented interfaces (as described in a-tags.adb).
4953 -- TSD : Type_Specific_Data (I_Depth) :=
4954 -- (Idepth => I_Depth,
4955 -- Access_Level => Type_Access_Level (Typ),
4956 -- Alignment => Typ'Alignment,
4957 -- Expanded_Name => Cstring_Ptr!(Exname'Address))
4958 -- External_Tag => Cstring_Ptr!(Exname'Address))
4959 -- HT_Link => HT_Link'Address,
4960 -- Transportable => <<boolean-value>>,
4961 -- Type_Is_Abstract => <<boolean-value>>,
4962 -- Needs_Finalization => <<boolean-value>>,
4963 -- [ Size_Func => Size_Prim'Access, ]
4964 -- [ Interfaces_Table => <<access-value>>, ]
4965 -- [ SSD => SSD_Table'Address ]
4966 -- Tags_Table => (0 => null,
4969 -- for TSD'Alignment use Address'Alignment
4971 TSD_Aggr_List
:= New_List
;
4973 -- Idepth: Count ancestors to compute the inheritance depth. For private
4974 -- extensions, always go to the full view in order to compute the real
4975 -- inheritance depth.
4978 Current_Typ
: Entity_Id
;
4979 Parent_Typ
: Entity_Id
;
4985 Parent_Typ
:= Etype
(Current_Typ
);
4987 if Is_Private_Type
(Parent_Typ
) then
4988 Parent_Typ
:= Full_View
(Base_Type
(Parent_Typ
));
4991 exit when Parent_Typ
= Current_Typ
;
4993 I_Depth
:= I_Depth
+ 1;
4994 Current_Typ
:= Parent_Typ
;
4998 Append_To
(TSD_Aggr_List
,
4999 Make_Integer_Literal
(Loc
, I_Depth
));
5003 Append_To
(TSD_Aggr_List
,
5004 Make_Integer_Literal
(Loc
, Type_Access_Level
(Typ
)));
5008 -- For CPP types we cannot rely on the value of 'Alignment provided
5009 -- by the backend to initialize this TSD field.
5011 if Convention
(Typ
) = Convention_CPP
5012 or else Is_CPP_Class
(Root_Type
(Typ
))
5014 Append_To
(TSD_Aggr_List
,
5015 Make_Integer_Literal
(Loc
, 0));
5017 Append_To
(TSD_Aggr_List
,
5018 Make_Attribute_Reference
(Loc
,
5019 Prefix
=> New_Reference_To
(Typ
, Loc
),
5020 Attribute_Name
=> Name_Alignment
));
5025 Append_To
(TSD_Aggr_List
,
5026 Unchecked_Convert_To
(RTE
(RE_Cstring_Ptr
),
5027 Make_Attribute_Reference
(Loc
,
5028 Prefix
=> New_Reference_To
(Exname
, Loc
),
5029 Attribute_Name
=> Name_Address
)));
5031 -- External_Tag of a local tagged type
5033 -- <typ>A : constant String :=
5034 -- "Internal tag at 16#tag-addr#: <full-name-of-typ>";
5036 -- The reason we generate this strange name is that we do not want to
5037 -- enter local tagged types in the global hash table used to compute
5038 -- the Internal_Tag attribute for two reasons:
5040 -- 1. It is hard to avoid a tasking race condition for entering the
5041 -- entry into the hash table.
5043 -- 2. It would cause a storage leak, unless we rig up considerable
5044 -- mechanism to remove the entry from the hash table on exit.
5046 -- So what we do is to generate the above external tag name, where the
5047 -- hex address is the address of the local dispatch table (i.e. exactly
5048 -- the value we want if Internal_Tag is computed from this string).
5050 -- Of course this value will only be valid if the tagged type is still
5051 -- in scope, but it clearly must be erroneous to compute the internal
5052 -- tag of a tagged type that is out of scope!
5054 -- We don't do this processing if an explicit external tag has been
5055 -- specified. That's an odd case for which we have already issued a
5056 -- warning, where we will not be able to compute the internal tag.
5058 if not Is_Library_Level_Entity
(Typ
)
5059 and then not Has_External_Tag_Rep_Clause
(Typ
)
5062 Exname
: constant Entity_Id
:=
5063 Make_Defining_Identifier
(Loc
,
5064 New_External_Name
(Tname
, 'A'));
5066 Full_Name
: constant String_Id
:=
5067 Fully_Qualified_Name_String
(First_Subtype
(Typ
));
5068 Str1_Id
: String_Id
;
5069 Str2_Id
: String_Id
;
5073 -- Str1 = "Internal tag at 16#";
5076 Store_String_Chars
("Internal tag at 16#");
5077 Str1_Id
:= End_String
;
5080 -- Str2 = "#: <type-full-name>";
5083 Store_String_Chars
("#: ");
5084 Store_String_Chars
(Full_Name
);
5085 Str2_Id
:= End_String
;
5088 -- Exname : constant String :=
5089 -- Str1 & Address_Image (Tag) & Str2;
5091 if RTE_Available
(RE_Address_Image
) then
5093 Make_Object_Declaration
(Loc
,
5094 Defining_Identifier
=> Exname
,
5095 Constant_Present
=> True,
5096 Object_Definition
=> New_Reference_To
5097 (Standard_String
, Loc
),
5099 Make_Op_Concat
(Loc
,
5101 Make_String_Literal
(Loc
, Str1_Id
),
5103 Make_Op_Concat
(Loc
,
5105 Make_Function_Call
(Loc
,
5108 (RTE
(RE_Address_Image
), Loc
),
5109 Parameter_Associations
=> New_List
(
5110 Unchecked_Convert_To
(RTE
(RE_Address
),
5111 New_Reference_To
(DT_Ptr
, Loc
)))),
5113 Make_String_Literal
(Loc
, Str2_Id
)))));
5117 Make_Object_Declaration
(Loc
,
5118 Defining_Identifier
=> Exname
,
5119 Constant_Present
=> True,
5120 Object_Definition
=> New_Reference_To
5121 (Standard_String
, Loc
),
5123 Make_Op_Concat
(Loc
,
5125 Make_String_Literal
(Loc
, Str1_Id
),
5127 Make_String_Literal
(Loc
, Str2_Id
))));
5131 Unchecked_Convert_To
(RTE
(RE_Cstring_Ptr
),
5132 Make_Attribute_Reference
(Loc
,
5133 Prefix
=> New_Reference_To
(Exname
, Loc
),
5134 Attribute_Name
=> Name_Address
));
5137 -- External tag of a library-level tagged type: Check for a definition
5138 -- of External_Tag. The clause is considered only if it applies to this
5139 -- specific tagged type, as opposed to one of its ancestors.
5140 -- If the type is an unconstrained type extension, we are building the
5141 -- dispatch table of its anonymous base type, so the external tag, if
5142 -- any was specified, must be retrieved from the first subtype. Go to
5143 -- the full view in case the clause is in the private part.
5147 Def
: constant Node_Id
:= Get_Attribute_Definition_Clause
5148 (Underlying_Type
(First_Subtype
(Typ
)),
5149 Attribute_External_Tag
);
5151 Old_Val
: String_Id
;
5152 New_Val
: String_Id
;
5156 if not Present
(Def
)
5157 or else Entity
(Name
(Def
)) /= First_Subtype
(Typ
)
5160 Unchecked_Convert_To
(RTE
(RE_Cstring_Ptr
),
5161 Make_Attribute_Reference
(Loc
,
5162 Prefix
=> New_Reference_To
(Exname
, Loc
),
5163 Attribute_Name
=> Name_Address
));
5165 Old_Val
:= Strval
(Expr_Value_S
(Expression
(Def
)));
5167 -- For the rep clause "for <typ>'external_tag use y" generate:
5169 -- <typ>A : constant string := y;
5171 -- <typ>A'Address is used to set the External_Tag component
5174 -- Create a new nul terminated string if it is not already
5176 if String_Length
(Old_Val
) > 0
5178 Get_String_Char
(Old_Val
, String_Length
(Old_Val
)) = 0
5182 Start_String
(Old_Val
);
5183 Store_String_Char
(Get_Char_Code
(ASCII
.NUL
));
5184 New_Val
:= End_String
;
5187 E
:= Make_Defining_Identifier
(Loc
,
5188 New_External_Name
(Chars
(Typ
), 'A'));
5191 Make_Object_Declaration
(Loc
,
5192 Defining_Identifier
=> E
,
5193 Constant_Present
=> True,
5194 Object_Definition
=>
5195 New_Reference_To
(Standard_String
, Loc
),
5197 Make_String_Literal
(Loc
, New_Val
)));
5200 Unchecked_Convert_To
(RTE
(RE_Cstring_Ptr
),
5201 Make_Attribute_Reference
(Loc
,
5202 Prefix
=> New_Reference_To
(E
, Loc
),
5203 Attribute_Name
=> Name_Address
));
5208 Append_To
(TSD_Aggr_List
, New_Node
);
5212 if RTE_Available
(RE_Register_Tag
) then
5213 Append_To
(TSD_Aggr_List
,
5214 Unchecked_Convert_To
(RTE
(RE_Tag_Ptr
),
5215 Make_Attribute_Reference
(Loc
,
5216 Prefix
=> New_Reference_To
(HT_Link
, Loc
),
5217 Attribute_Name
=> Name_Address
)));
5219 Append_To
(TSD_Aggr_List
,
5220 Unchecked_Convert_To
(RTE
(RE_Tag_Ptr
),
5221 New_Reference_To
(RTE
(RE_Null_Address
), Loc
)));
5224 -- Transportable: Set for types that can be used in remote calls
5225 -- with respect to E.4(18) legality rules.
5228 Transportable
: Entity_Id
;
5234 or else Is_Shared_Passive
(Typ
)
5236 ((Is_Remote_Types
(Typ
)
5237 or else Is_Remote_Call_Interface
(Typ
))
5238 and then Original_View_In_Visible_Part
(Typ
))
5239 or else not Comes_From_Source
(Typ
));
5241 Append_To
(TSD_Aggr_List
,
5242 New_Occurrence_Of
(Transportable
, Loc
));
5245 -- Type_Is_Abstract (Ada 2012: AI05-0173). This functionality is
5246 -- not available in the HIE runtime.
5248 if RTE_Record_Component_Available
(RE_Type_Is_Abstract
) then
5250 Type_Is_Abstract
: Entity_Id
;
5254 Boolean_Literals
(Is_Abstract_Type
(Typ
));
5256 Append_To
(TSD_Aggr_List
,
5257 New_Occurrence_Of
(Type_Is_Abstract
, Loc
));
5261 -- Needs_Finalization: Set if the type is controlled or has controlled
5265 Needs_Fin
: Entity_Id
;
5268 Needs_Fin
:= Boolean_Literals
(Needs_Finalization
(Typ
));
5269 Append_To
(TSD_Aggr_List
, New_Occurrence_Of
(Needs_Fin
, Loc
));
5274 if RTE_Record_Component_Available
(RE_Size_Func
) then
5276 -- Initialize this field to Null_Address if we are not building
5277 -- static dispatch tables static or if the size function is not
5278 -- available. In the former case we cannot initialize this field
5279 -- until the function is frozen and registered in the dispatch
5280 -- table (see Register_Primitive).
5282 if not Building_Static_DT
(Typ
) or else not Has_DT
(Typ
) then
5283 Append_To
(TSD_Aggr_List
,
5284 Unchecked_Convert_To
(RTE
(RE_Size_Ptr
),
5285 New_Reference_To
(RTE
(RE_Null_Address
), Loc
)));
5289 Prim_Elmt
: Elmt_Id
;
5291 Size_Comp
: Node_Id
;
5294 Prim_Elmt
:= First_Elmt
(Primitive_Operations
(Typ
));
5295 while Present
(Prim_Elmt
) loop
5296 Prim
:= Node
(Prim_Elmt
);
5298 if Chars
(Prim
) = Name_uSize
then
5299 Prim
:= Ultimate_Alias
(Prim
);
5301 if Is_Abstract_Subprogram
(Prim
) then
5303 Unchecked_Convert_To
(RTE
(RE_Size_Ptr
),
5304 New_Reference_To
(RTE
(RE_Null_Address
), Loc
));
5307 Unchecked_Convert_To
(RTE
(RE_Size_Ptr
),
5308 Make_Attribute_Reference
(Loc
,
5309 Prefix
=> New_Reference_To
(Prim
, Loc
),
5310 Attribute_Name
=> Name_Unrestricted_Access
));
5316 Next_Elmt
(Prim_Elmt
);
5319 pragma Assert
(Present
(Size_Comp
));
5320 Append_To
(TSD_Aggr_List
, Size_Comp
);
5325 -- Interfaces_Table (required for AI-405)
5327 if RTE_Record_Component_Available
(RE_Interfaces_Table
) then
5329 -- Count the number of interface types implemented by Typ
5331 Collect_Interfaces
(Typ
, Typ_Ifaces
);
5333 AI
:= First_Elmt
(Typ_Ifaces
);
5334 while Present
(AI
) loop
5335 Num_Ifaces
:= Num_Ifaces
+ 1;
5339 if Num_Ifaces
= 0 then
5340 Iface_Table_Node
:= Make_Null
(Loc
);
5342 -- Generate the Interface_Table object
5346 TSD_Ifaces_List
: constant List_Id
:= New_List
;
5348 Sec_DT_Tag
: Node_Id
;
5351 AI
:= First_Elmt
(Typ_Ifaces
);
5352 while Present
(AI
) loop
5353 if Is_Ancestor
(Node
(AI
), Typ
, Use_Full_View
=> True) then
5355 New_Reference_To
(DT_Ptr
, Loc
);
5359 (Next_Elmt
(First_Elmt
(Access_Disp_Table
(Typ
))));
5360 pragma Assert
(Has_Thunks
(Node
(Elmt
)));
5362 while Is_Tag
(Node
(Elmt
))
5364 Is_Ancestor
(Node
(AI
), Related_Type
(Node
(Elmt
)),
5365 Use_Full_View
=> True)
5367 pragma Assert
(Has_Thunks
(Node
(Elmt
)));
5369 pragma Assert
(Has_Thunks
(Node
(Elmt
)));
5371 pragma Assert
(not Has_Thunks
(Node
(Elmt
)));
5373 pragma Assert
(not Has_Thunks
(Node
(Elmt
)));
5377 pragma Assert
(Ekind
(Node
(Elmt
)) = E_Constant
5379 Has_Thunks
(Node
(Next_Elmt
(Next_Elmt
(Elmt
)))));
5381 New_Reference_To
(Node
(Next_Elmt
(Next_Elmt
(Elmt
))),
5385 Append_To
(TSD_Ifaces_List
,
5386 Make_Aggregate
(Loc
,
5387 Expressions
=> New_List
(
5391 Unchecked_Convert_To
(RTE
(RE_Tag
),
5393 (Node
(First_Elmt
(Access_Disp_Table
(Node
(AI
)))),
5396 -- Static_Offset_To_Top
5398 New_Reference_To
(Standard_True
, Loc
),
5400 -- Offset_To_Top_Value
5402 Make_Integer_Literal
(Loc
, 0),
5404 -- Offset_To_Top_Func
5410 Unchecked_Convert_To
(RTE
(RE_Tag
), Sec_DT_Tag
)
5417 Name_ITable
:= New_External_Name
(Tname
, 'I');
5418 ITable
:= Make_Defining_Identifier
(Loc
, Name_ITable
);
5419 Set_Is_Statically_Allocated
(ITable
,
5420 Is_Library_Level_Tagged_Type
(Typ
));
5422 -- The table of interfaces is not constant; its slots are
5423 -- filled at run time by the IP routine using attribute
5424 -- 'Position to know the location of the tag components
5425 -- (and this attribute cannot be safely used before the
5426 -- object is initialized).
5429 Make_Object_Declaration
(Loc
,
5430 Defining_Identifier
=> ITable
,
5431 Aliased_Present
=> True,
5432 Constant_Present
=> False,
5433 Object_Definition
=>
5434 Make_Subtype_Indication
(Loc
,
5436 New_Reference_To
(RTE
(RE_Interface_Data
), Loc
),
5437 Constraint
=> Make_Index_Or_Discriminant_Constraint
5439 Constraints
=> New_List
(
5440 Make_Integer_Literal
(Loc
, Num_Ifaces
)))),
5442 Expression
=> Make_Aggregate
(Loc
,
5443 Expressions
=> New_List
(
5444 Make_Integer_Literal
(Loc
, Num_Ifaces
),
5445 Make_Aggregate
(Loc
,
5446 Expressions
=> TSD_Ifaces_List
)))));
5449 Make_Attribute_Definition_Clause
(Loc
,
5450 Name
=> New_Reference_To
(ITable
, Loc
),
5451 Chars
=> Name_Alignment
,
5453 Make_Attribute_Reference
(Loc
,
5455 New_Reference_To
(RTE
(RE_Integer_Address
), Loc
),
5456 Attribute_Name
=> Name_Alignment
)));
5459 Make_Attribute_Reference
(Loc
,
5460 Prefix
=> New_Reference_To
(ITable
, Loc
),
5461 Attribute_Name
=> Name_Unchecked_Access
);
5465 Append_To
(TSD_Aggr_List
, Iface_Table_Node
);
5468 -- Generate the Select Specific Data table for synchronized types that
5469 -- implement synchronized interfaces. The size of the table is
5470 -- constrained by the number of non-predefined primitive operations.
5472 if RTE_Record_Component_Available
(RE_SSD
) then
5473 if Ada_Version
>= Ada_2005
5474 and then Has_DT
(Typ
)
5475 and then Is_Concurrent_Record_Type
(Typ
)
5476 and then Has_Interfaces
(Typ
)
5477 and then Nb_Prim
> 0
5478 and then not Is_Abstract_Type
(Typ
)
5479 and then not Is_Controlled
(Typ
)
5480 and then not Restriction_Active
(No_Dispatching_Calls
)
5481 and then not Restriction_Active
(No_Select_Statements
)
5484 Make_Object_Declaration
(Loc
,
5485 Defining_Identifier
=> SSD
,
5486 Aliased_Present
=> True,
5487 Object_Definition
=>
5488 Make_Subtype_Indication
(Loc
,
5489 Subtype_Mark
=> New_Reference_To
(
5490 RTE
(RE_Select_Specific_Data
), Loc
),
5492 Make_Index_Or_Discriminant_Constraint
(Loc
,
5493 Constraints
=> New_List
(
5494 Make_Integer_Literal
(Loc
, Nb_Prim
))))));
5497 Make_Attribute_Definition_Clause
(Loc
,
5498 Name
=> New_Reference_To
(SSD
, Loc
),
5499 Chars
=> Name_Alignment
,
5501 Make_Attribute_Reference
(Loc
,
5503 New_Reference_To
(RTE
(RE_Integer_Address
), Loc
),
5504 Attribute_Name
=> Name_Alignment
)));
5506 -- This table is initialized by Make_Select_Specific_Data_Table,
5507 -- which calls Set_Entry_Index and Set_Prim_Op_Kind.
5509 Append_To
(TSD_Aggr_List
,
5510 Make_Attribute_Reference
(Loc
,
5511 Prefix
=> New_Reference_To
(SSD
, Loc
),
5512 Attribute_Name
=> Name_Unchecked_Access
));
5514 Append_To
(TSD_Aggr_List
, Make_Null
(Loc
));
5518 -- Initialize the table of ancestor tags. In case of interface types
5519 -- this table is not needed.
5521 TSD_Tags_List
:= New_List
;
5523 -- If we are not statically allocating the dispatch table then we must
5524 -- fill position 0 with null because we still have not generated the
5527 if not Building_Static_DT
(Typ
)
5528 or else Is_Interface
(Typ
)
5530 Append_To
(TSD_Tags_List
,
5531 Unchecked_Convert_To
(RTE
(RE_Tag
),
5532 New_Reference_To
(RTE
(RE_Null_Address
), Loc
)));
5534 -- Otherwise we can safely reference the tag
5537 Append_To
(TSD_Tags_List
,
5538 New_Reference_To
(DT_Ptr
, Loc
));
5541 -- Fill the rest of the table with the tags of the ancestors
5544 Current_Typ
: Entity_Id
;
5545 Parent_Typ
: Entity_Id
;
5553 Parent_Typ
:= Etype
(Current_Typ
);
5555 if Is_Private_Type
(Parent_Typ
) then
5556 Parent_Typ
:= Full_View
(Base_Type
(Parent_Typ
));
5559 exit when Parent_Typ
= Current_Typ
;
5561 if Is_CPP_Class
(Parent_Typ
) then
5563 -- The tags defined in the C++ side will be inherited when
5564 -- the object is constructed (Exp_Ch3.Build_Init_Procedure)
5566 Append_To
(TSD_Tags_List
,
5567 Unchecked_Convert_To
(RTE
(RE_Tag
),
5568 New_Reference_To
(RTE
(RE_Null_Address
), Loc
)));
5570 Append_To
(TSD_Tags_List
,
5572 (Node
(First_Elmt
(Access_Disp_Table
(Parent_Typ
))),
5577 Current_Typ
:= Parent_Typ
;
5580 pragma Assert
(Pos
= I_Depth
+ 1);
5583 Append_To
(TSD_Aggr_List
,
5584 Make_Aggregate
(Loc
,
5585 Expressions
=> TSD_Tags_List
));
5587 -- Build the TSD object
5590 Make_Object_Declaration
(Loc
,
5591 Defining_Identifier
=> TSD
,
5592 Aliased_Present
=> True,
5593 Constant_Present
=> Building_Static_DT
(Typ
),
5594 Object_Definition
=>
5595 Make_Subtype_Indication
(Loc
,
5596 Subtype_Mark
=> New_Reference_To
(
5597 RTE
(RE_Type_Specific_Data
), Loc
),
5599 Make_Index_Or_Discriminant_Constraint
(Loc
,
5600 Constraints
=> New_List
(
5601 Make_Integer_Literal
(Loc
, I_Depth
)))),
5603 Expression
=> Make_Aggregate
(Loc
,
5604 Expressions
=> TSD_Aggr_List
)));
5606 Set_Is_True_Constant
(TSD
, Building_Static_DT
(Typ
));
5609 Make_Attribute_Definition_Clause
(Loc
,
5610 Name
=> New_Reference_To
(TSD
, Loc
),
5611 Chars
=> Name_Alignment
,
5613 Make_Attribute_Reference
(Loc
,
5614 Prefix
=> New_Reference_To
(RTE
(RE_Integer_Address
), Loc
),
5615 Attribute_Name
=> Name_Alignment
)));
5617 -- Initialize or declare the dispatch table object
5619 if not Has_DT
(Typ
) then
5620 DT_Constr_List
:= New_List
;
5621 DT_Aggr_List
:= New_List
;
5626 Make_Attribute_Reference
(Loc
,
5627 Prefix
=> New_Reference_To
(TSD
, Loc
),
5628 Attribute_Name
=> Name_Address
);
5630 Append_To
(DT_Constr_List
, New_Node
);
5631 Append_To
(DT_Aggr_List
, New_Copy
(New_Node
));
5632 Append_To
(DT_Aggr_List
, Make_Integer_Literal
(Loc
, 0));
5634 -- In case of locally defined tagged types we have already declared
5635 -- and uninitialized object for the dispatch table, which is now
5636 -- initialized by means of the following assignment:
5638 -- DT := (TSD'Address, 0);
5640 if not Building_Static_DT
(Typ
) then
5642 Make_Assignment_Statement
(Loc
,
5643 Name
=> New_Reference_To
(DT
, Loc
),
5644 Expression
=> Make_Aggregate
(Loc
,
5645 Expressions
=> DT_Aggr_List
)));
5647 -- In case of library level tagged types we declare and export now
5648 -- the constant object containing the dummy dispatch table. There
5649 -- is no need to declare the tag here because it has been previously
5650 -- declared by Make_Tags
5652 -- DT : aliased constant No_Dispatch_Table :=
5653 -- (NDT_TSD => TSD'Address;
5654 -- NDT_Prims_Ptr => 0);
5655 -- for DT'Alignment use Address'Alignment;
5659 Make_Object_Declaration
(Loc
,
5660 Defining_Identifier
=> DT
,
5661 Aliased_Present
=> True,
5662 Constant_Present
=> True,
5663 Object_Definition
=>
5664 New_Reference_To
(RTE
(RE_No_Dispatch_Table_Wrapper
), Loc
),
5665 Expression
=> Make_Aggregate
(Loc
,
5666 Expressions
=> DT_Aggr_List
)));
5669 Make_Attribute_Definition_Clause
(Loc
,
5670 Name
=> New_Reference_To
(DT
, Loc
),
5671 Chars
=> Name_Alignment
,
5673 Make_Attribute_Reference
(Loc
,
5675 New_Reference_To
(RTE
(RE_Integer_Address
), Loc
),
5676 Attribute_Name
=> Name_Alignment
)));
5678 Export_DT
(Typ
, DT
);
5681 -- Common case: Typ has a dispatch table
5685 -- Predef_Prims : Address_Array (1 .. Default_Prim_Ops_Count) :=
5686 -- (predef-prim-op-1'address,
5687 -- predef-prim-op-2'address,
5689 -- predef-prim-op-n'address);
5690 -- for Predef_Prims'Alignment use Address'Alignment
5692 -- DT : Dispatch_Table (Nb_Prims) :=
5693 -- (Signature => <sig-value>,
5694 -- Tag_Kind => <tag_kind-value>,
5695 -- Predef_Prims => Predef_Prims'First'Address,
5696 -- Offset_To_Top => 0,
5697 -- TSD => TSD'Address;
5698 -- Prims_Ptr => (prim-op-1'address,
5699 -- prim-op-2'address,
5701 -- prim-op-n'address));
5702 -- for DT'Alignment use Address'Alignment
5709 if not Building_Static_DT
(Typ
) then
5710 Nb_Predef_Prims
:= Max_Predef_Prims
;
5713 Prim_Elmt
:= First_Elmt
(Primitive_Operations
(Typ
));
5714 while Present
(Prim_Elmt
) loop
5715 Prim
:= Node
(Prim_Elmt
);
5717 if Is_Predefined_Dispatching_Operation
(Prim
)
5718 and then not Is_Abstract_Subprogram
(Prim
)
5720 Pos
:= UI_To_Int
(DT_Position
(Prim
));
5722 if Pos
> Nb_Predef_Prims
then
5723 Nb_Predef_Prims
:= Pos
;
5727 Next_Elmt
(Prim_Elmt
);
5733 (Nat
range 1 .. Nb_Predef_Prims
) of Entity_Id
;
5738 Prim_Ops_Aggr_List
:= New_List
;
5740 Prim_Table
:= (others => Empty
);
5742 if Building_Static_DT
(Typ
) then
5743 Prim_Elmt
:= First_Elmt
(Primitive_Operations
(Typ
));
5744 while Present
(Prim_Elmt
) loop
5745 Prim
:= Node
(Prim_Elmt
);
5747 if Is_Predefined_Dispatching_Operation
(Prim
)
5748 and then not Is_Abstract_Subprogram
(Prim
)
5749 and then not Is_Eliminated
(Prim
)
5750 and then not Present
(Prim_Table
5751 (UI_To_Int
(DT_Position
(Prim
))))
5753 E
:= Ultimate_Alias
(Prim
);
5754 pragma Assert
(not Is_Abstract_Subprogram
(E
));
5755 Prim_Table
(UI_To_Int
(DT_Position
(Prim
))) := E
;
5758 Next_Elmt
(Prim_Elmt
);
5762 for J
in Prim_Table
'Range loop
5763 if Present
(Prim_Table
(J
)) then
5765 Unchecked_Convert_To
(RTE
(RE_Prim_Ptr
),
5766 Make_Attribute_Reference
(Loc
,
5767 Prefix
=> New_Reference_To
(Prim_Table
(J
), Loc
),
5768 Attribute_Name
=> Name_Unrestricted_Access
));
5770 New_Node
:= Make_Null
(Loc
);
5773 Append_To
(Prim_Ops_Aggr_List
, New_Node
);
5777 Make_Aggregate
(Loc
,
5778 Expressions
=> Prim_Ops_Aggr_List
);
5781 Make_Subtype_Declaration
(Loc
,
5782 Defining_Identifier
=> Make_Temporary
(Loc
, 'S'),
5783 Subtype_Indication
=>
5784 New_Reference_To
(RTE
(RE_Address_Array
), Loc
));
5786 Append_To
(Result
, Decl
);
5789 Make_Object_Declaration
(Loc
,
5790 Defining_Identifier
=> Predef_Prims
,
5791 Aliased_Present
=> True,
5792 Constant_Present
=> Building_Static_DT
(Typ
),
5793 Object_Definition
=> New_Reference_To
5794 (Defining_Identifier
(Decl
), Loc
),
5795 Expression
=> New_Node
));
5797 -- Remember aggregates initializing dispatch tables
5799 Append_Elmt
(New_Node
, DT_Aggr
);
5802 Make_Attribute_Definition_Clause
(Loc
,
5803 Name
=> New_Reference_To
(Predef_Prims
, Loc
),
5804 Chars
=> Name_Alignment
,
5806 Make_Attribute_Reference
(Loc
,
5808 New_Reference_To
(RTE
(RE_Integer_Address
), Loc
),
5809 Attribute_Name
=> Name_Alignment
)));
5813 -- Stage 1: Initialize the discriminant and the record components
5815 DT_Constr_List
:= New_List
;
5816 DT_Aggr_List
:= New_List
;
5818 -- Num_Prims. If the tagged type has no primitives we add a dummy
5819 -- slot whose address will be the tag of this type.
5822 New_Node
:= Make_Integer_Literal
(Loc
, 1);
5824 New_Node
:= Make_Integer_Literal
(Loc
, Nb_Prim
);
5827 Append_To
(DT_Constr_List
, New_Node
);
5828 Append_To
(DT_Aggr_List
, New_Copy
(New_Node
));
5832 if RTE_Record_Component_Available
(RE_Signature
) then
5833 Append_To
(DT_Aggr_List
,
5834 New_Reference_To
(RTE
(RE_Primary_DT
), Loc
));
5839 if RTE_Record_Component_Available
(RE_Tag_Kind
) then
5840 Append_To
(DT_Aggr_List
, Tagged_Kind
(Typ
));
5845 Append_To
(DT_Aggr_List
,
5846 Make_Attribute_Reference
(Loc
,
5847 Prefix
=> New_Reference_To
(Predef_Prims
, Loc
),
5848 Attribute_Name
=> Name_Address
));
5852 Append_To
(DT_Aggr_List
, Make_Integer_Literal
(Loc
, 0));
5856 Append_To
(DT_Aggr_List
,
5857 Make_Attribute_Reference
(Loc
,
5858 Prefix
=> New_Reference_To
(TSD
, Loc
),
5859 Attribute_Name
=> Name_Address
));
5861 -- Stage 2: Initialize the table of user-defined primitive operations
5863 Prim_Ops_Aggr_List
:= New_List
;
5866 Append_To
(Prim_Ops_Aggr_List
, Make_Null
(Loc
));
5868 elsif not Building_Static_DT
(Typ
) then
5869 for J
in 1 .. Nb_Prim
loop
5870 Append_To
(Prim_Ops_Aggr_List
, Make_Null
(Loc
));
5875 CPP_Nb_Prims
: constant Nat
:= CPP_Num_Prims
(Typ
);
5878 Prim_Elmt
: Elmt_Id
;
5880 Prim_Table
: array (Nat
range 1 .. Nb_Prim
) of Entity_Id
;
5883 Prim_Table
:= (others => Empty
);
5885 Prim_Elmt
:= First_Elmt
(Primitive_Operations
(Typ
));
5886 while Present
(Prim_Elmt
) loop
5887 Prim
:= Node
(Prim_Elmt
);
5889 -- Retrieve the ultimate alias of the primitive for proper
5890 -- handling of renamings and eliminated primitives.
5892 E
:= Ultimate_Alias
(Prim
);
5893 Prim_Pos
:= UI_To_Int
(DT_Position
(E
));
5895 -- Do not reference predefined primitives because they are
5896 -- located in a separate dispatch table; skip entities with
5897 -- attribute Interface_Alias because they are only required
5898 -- to build secondary dispatch tables; skip abstract and
5899 -- eliminated primitives; for derivations of CPP types skip
5900 -- primitives located in the C++ part of the dispatch table
5901 -- because their slot is initialized by the IC routine.
5903 if not Is_Predefined_Dispatching_Operation
(Prim
)
5904 and then not Is_Predefined_Dispatching_Operation
(E
)
5905 and then not Present
(Interface_Alias
(Prim
))
5906 and then not Is_Abstract_Subprogram
(E
)
5907 and then not Is_Eliminated
(E
)
5908 and then (not Is_CPP_Class
(Root_Type
(Typ
))
5909 or else Prim_Pos
> CPP_Nb_Prims
)
5912 (UI_To_Int
(DT_Position
(Prim
)) <= Nb_Prim
);
5914 Prim_Table
(UI_To_Int
(DT_Position
(Prim
))) := E
;
5917 Next_Elmt
(Prim_Elmt
);
5920 for J
in Prim_Table
'Range loop
5921 if Present
(Prim_Table
(J
)) then
5923 Unchecked_Convert_To
(RTE
(RE_Prim_Ptr
),
5924 Make_Attribute_Reference
(Loc
,
5925 Prefix
=> New_Reference_To
(Prim_Table
(J
), Loc
),
5926 Attribute_Name
=> Name_Unrestricted_Access
));
5928 New_Node
:= Make_Null
(Loc
);
5931 Append_To
(Prim_Ops_Aggr_List
, New_Node
);
5937 Make_Aggregate
(Loc
,
5938 Expressions
=> Prim_Ops_Aggr_List
);
5940 Append_To
(DT_Aggr_List
, New_Node
);
5942 -- Remember aggregates initializing dispatch tables
5944 Append_Elmt
(New_Node
, DT_Aggr
);
5946 -- In case of locally defined tagged types we have already declared
5947 -- and uninitialized object for the dispatch table, which is now
5948 -- initialized by means of an assignment.
5950 if not Building_Static_DT
(Typ
) then
5952 Make_Assignment_Statement
(Loc
,
5953 Name
=> New_Reference_To
(DT
, Loc
),
5954 Expression
=> Make_Aggregate
(Loc
,
5955 Expressions
=> DT_Aggr_List
)));
5957 -- In case of library level tagged types we declare now and export
5958 -- the constant object containing the dispatch table.
5962 Make_Object_Declaration
(Loc
,
5963 Defining_Identifier
=> DT
,
5964 Aliased_Present
=> True,
5965 Constant_Present
=> True,
5966 Object_Definition
=>
5967 Make_Subtype_Indication
(Loc
,
5968 Subtype_Mark
=> New_Reference_To
5969 (RTE
(RE_Dispatch_Table_Wrapper
), Loc
),
5970 Constraint
=> Make_Index_Or_Discriminant_Constraint
(Loc
,
5971 Constraints
=> DT_Constr_List
)),
5972 Expression
=> Make_Aggregate
(Loc
,
5973 Expressions
=> DT_Aggr_List
)));
5976 Make_Attribute_Definition_Clause
(Loc
,
5977 Name
=> New_Reference_To
(DT
, Loc
),
5978 Chars
=> Name_Alignment
,
5980 Make_Attribute_Reference
(Loc
,
5982 New_Reference_To
(RTE
(RE_Integer_Address
), Loc
),
5983 Attribute_Name
=> Name_Alignment
)));
5985 Export_DT
(Typ
, DT
);
5989 -- Initialize the table of ancestor tags if not building static
5992 if not Building_Static_DT
(Typ
)
5993 and then not Is_Interface
(Typ
)
5994 and then not Is_CPP_Class
(Typ
)
5997 Make_Assignment_Statement
(Loc
,
5999 Make_Indexed_Component
(Loc
,
6001 Make_Selected_Component
(Loc
,
6003 New_Reference_To
(TSD
, Loc
),
6006 (RTE_Record_Component
(RE_Tags_Table
), Loc
)),
6008 New_List
(Make_Integer_Literal
(Loc
, 0))),
6012 (Node
(First_Elmt
(Access_Disp_Table
(Typ
))), Loc
)));
6015 -- Inherit the dispatch tables of the parent. There is no need to
6016 -- inherit anything from the parent when building static dispatch tables
6017 -- because the whole dispatch table (including inherited primitives) has
6018 -- been already built.
6020 if Building_Static_DT
(Typ
) then
6023 -- If the ancestor is a CPP_Class type we inherit the dispatch tables
6024 -- in the init proc, and we don't need to fill them in here.
6026 elsif Is_CPP_Class
(Parent_Typ
) then
6029 -- Otherwise we fill in the dispatch tables here
6032 if Typ
/= Parent_Typ
6033 and then not Is_Interface
(Typ
)
6034 and then not Restriction_Active
(No_Dispatching_Calls
)
6036 -- Inherit the dispatch table
6038 if not Is_Interface
(Typ
)
6039 and then not Is_Interface
(Parent_Typ
)
6040 and then not Is_CPP_Class
(Parent_Typ
)
6043 Nb_Prims
: constant Int
:=
6044 UI_To_Int
(DT_Entry_Count
6045 (First_Tag_Component
(Parent_Typ
)));
6048 Append_To
(Elab_Code
,
6049 Build_Inherit_Predefined_Prims
(Loc
,
6055 (Access_Disp_Table
(Parent_Typ
)))), Loc
),
6061 (Access_Disp_Table
(Typ
)))), Loc
)));
6063 if Nb_Prims
/= 0 then
6064 Append_To
(Elab_Code
,
6065 Build_Inherit_Prims
(Loc
,
6071 (Access_Disp_Table
(Parent_Typ
))), Loc
),
6072 New_Tag_Node
=> New_Reference_To
(DT_Ptr
, Loc
),
6073 Num_Prims
=> Nb_Prims
));
6078 -- Inherit the secondary dispatch tables of the ancestor
6080 if not Is_CPP_Class
(Parent_Typ
) then
6082 Sec_DT_Ancestor
: Elmt_Id
:=
6086 (Access_Disp_Table
(Parent_Typ
))));
6087 Sec_DT_Typ
: Elmt_Id
:=
6091 (Access_Disp_Table
(Typ
))));
6093 procedure Copy_Secondary_DTs
(Typ
: Entity_Id
);
6094 -- Local procedure required to climb through the ancestors
6095 -- and copy the contents of all their secondary dispatch
6098 ------------------------
6099 -- Copy_Secondary_DTs --
6100 ------------------------
6102 procedure Copy_Secondary_DTs
(Typ
: Entity_Id
) is
6107 -- Climb to the ancestor (if any) handling private types
6109 if Present
(Full_View
(Etype
(Typ
))) then
6110 if Full_View
(Etype
(Typ
)) /= Typ
then
6111 Copy_Secondary_DTs
(Full_View
(Etype
(Typ
)));
6114 elsif Etype
(Typ
) /= Typ
then
6115 Copy_Secondary_DTs
(Etype
(Typ
));
6118 if Present
(Interfaces
(Typ
))
6119 and then not Is_Empty_Elmt_List
(Interfaces
(Typ
))
6121 Iface
:= First_Elmt
(Interfaces
(Typ
));
6122 E
:= First_Entity
(Typ
);
6124 and then Present
(Node
(Sec_DT_Ancestor
))
6125 and then Ekind
(Node
(Sec_DT_Ancestor
)) = E_Constant
6127 if Is_Tag
(E
) and then Chars
(E
) /= Name_uTag
then
6129 Num_Prims
: constant Int
:=
6130 UI_To_Int
(DT_Entry_Count
(E
));
6133 if not Is_Interface
(Etype
(Typ
)) then
6135 -- Inherit first secondary dispatch table
6137 Append_To
(Elab_Code
,
6138 Build_Inherit_Predefined_Prims
(Loc
,
6140 Unchecked_Convert_To
(RTE
(RE_Tag
),
6143 (Next_Elmt
(Sec_DT_Ancestor
)),
6146 Unchecked_Convert_To
(RTE
(RE_Tag
),
6148 (Node
(Next_Elmt
(Sec_DT_Typ
)),
6151 if Num_Prims
/= 0 then
6152 Append_To
(Elab_Code
,
6153 Build_Inherit_Prims
(Loc
,
6154 Typ
=> Node
(Iface
),
6156 Unchecked_Convert_To
6159 (Node
(Sec_DT_Ancestor
),
6162 Unchecked_Convert_To
6165 (Node
(Sec_DT_Typ
), Loc
)),
6166 Num_Prims
=> Num_Prims
));
6170 Next_Elmt
(Sec_DT_Ancestor
);
6171 Next_Elmt
(Sec_DT_Typ
);
6173 -- Skip the secondary dispatch table of
6174 -- predefined primitives
6176 Next_Elmt
(Sec_DT_Ancestor
);
6177 Next_Elmt
(Sec_DT_Typ
);
6179 if not Is_Interface
(Etype
(Typ
)) then
6181 -- Inherit second secondary dispatch table
6183 Append_To
(Elab_Code
,
6184 Build_Inherit_Predefined_Prims
(Loc
,
6186 Unchecked_Convert_To
(RTE
(RE_Tag
),
6189 (Next_Elmt
(Sec_DT_Ancestor
)),
6192 Unchecked_Convert_To
(RTE
(RE_Tag
),
6194 (Node
(Next_Elmt
(Sec_DT_Typ
)),
6197 if Num_Prims
/= 0 then
6198 Append_To
(Elab_Code
,
6199 Build_Inherit_Prims
(Loc
,
6200 Typ
=> Node
(Iface
),
6202 Unchecked_Convert_To
6205 (Node
(Sec_DT_Ancestor
),
6208 Unchecked_Convert_To
6211 (Node
(Sec_DT_Typ
), Loc
)),
6212 Num_Prims
=> Num_Prims
));
6217 Next_Elmt
(Sec_DT_Ancestor
);
6218 Next_Elmt
(Sec_DT_Typ
);
6220 -- Skip the secondary dispatch table of
6221 -- predefined primitives
6223 Next_Elmt
(Sec_DT_Ancestor
);
6224 Next_Elmt
(Sec_DT_Typ
);
6232 end Copy_Secondary_DTs
;
6235 if Present
(Node
(Sec_DT_Ancestor
))
6236 and then Ekind
(Node
(Sec_DT_Ancestor
)) = E_Constant
6238 -- Handle private types
6240 if Present
(Full_View
(Typ
)) then
6241 Copy_Secondary_DTs
(Full_View
(Typ
));
6243 Copy_Secondary_DTs
(Typ
);
6251 -- If the type has a representation clause which specifies its external
6252 -- tag then generate code to check if the external tag of this type is
6253 -- the same as the external tag of some other declaration.
6255 -- Check_TSD (TSD'Unrestricted_Access);
6257 -- This check is a consequence of AI05-0113-1/06, so it officially
6258 -- applies to Ada 2005 (and Ada 2012). It might be argued that it is
6259 -- a desirable check to add in Ada 95 mode, but we hesitate to make
6260 -- this change, as it would be incompatible, and could conceivably
6261 -- cause a problem in existing Aa 95 code.
6263 -- We check for No_Run_Time_Mode here, because we do not want to pick
6264 -- up the RE_Check_TSD entity and call it in No_Run_Time mode.
6266 if not No_Run_Time_Mode
6267 and then Ada_Version
>= Ada_2005
6268 and then Has_External_Tag_Rep_Clause
(Typ
)
6269 and then RTE_Available
(RE_Check_TSD
)
6270 and then not Debug_Flag_QQ
6272 Append_To
(Elab_Code
,
6273 Make_Procedure_Call_Statement
(Loc
,
6274 Name
=> New_Reference_To
(RTE
(RE_Check_TSD
), Loc
),
6275 Parameter_Associations
=> New_List
(
6276 Make_Attribute_Reference
(Loc
,
6277 Prefix
=> New_Reference_To
(TSD
, Loc
),
6278 Attribute_Name
=> Name_Unchecked_Access
))));
6281 -- Generate code to register the Tag in the External_Tag hash table for
6282 -- the pure Ada type only.
6284 -- Register_Tag (Dt_Ptr);
6286 -- Skip this action in the following cases:
6287 -- 1) if Register_Tag is not available.
6288 -- 2) in No_Run_Time mode.
6289 -- 3) if Typ is not defined at the library level (this is required
6290 -- to avoid adding concurrency control to the hash table used
6291 -- by the run-time to register the tags).
6293 if not No_Run_Time_Mode
6294 and then Is_Library_Level_Entity
(Typ
)
6295 and then RTE_Available
(RE_Register_Tag
)
6297 Append_To
(Elab_Code
,
6298 Make_Procedure_Call_Statement
(Loc
,
6299 Name
=> New_Reference_To
(RTE
(RE_Register_Tag
), Loc
),
6300 Parameter_Associations
=>
6301 New_List
(New_Reference_To
(DT_Ptr
, Loc
))));
6304 if not Is_Empty_List
(Elab_Code
) then
6305 Append_List_To
(Result
, Elab_Code
);
6308 -- Populate the two auxiliary tables used for dispatching asynchronous,
6309 -- conditional and timed selects for synchronized types that implement
6310 -- a limited interface. Skip this step in Ravenscar profile or when
6311 -- general dispatching is forbidden.
6313 if Ada_Version
>= Ada_2005
6314 and then Is_Concurrent_Record_Type
(Typ
)
6315 and then Has_Interfaces
(Typ
)
6316 and then not Restriction_Active
(No_Dispatching_Calls
)
6317 and then not Restriction_Active
(No_Select_Statements
)
6319 Append_List_To
(Result
,
6320 Make_Select_Specific_Data_Table
(Typ
));
6323 -- Remember entities containing dispatch tables
6325 Append_Elmt
(Predef_Prims
, DT_Decl
);
6326 Append_Elmt
(DT
, DT_Decl
);
6328 Analyze_List
(Result
, Suppress
=> All_Checks
);
6329 Set_Has_Dispatch_Table
(Typ
);
6331 -- Mark entities containing dispatch tables. Required by the backend to
6332 -- handle them properly.
6334 if Has_DT
(Typ
) then
6339 -- Object declarations
6341 Elmt
:= First_Elmt
(DT_Decl
);
6342 while Present
(Elmt
) loop
6343 Set_Is_Dispatch_Table_Entity
(Node
(Elmt
));
6344 pragma Assert
(Ekind
(Etype
(Node
(Elmt
))) = E_Array_Subtype
6345 or else Ekind
(Etype
(Node
(Elmt
))) = E_Record_Subtype
);
6346 Set_Is_Dispatch_Table_Entity
(Etype
(Node
(Elmt
)));
6350 -- Aggregates initializing dispatch tables
6352 Elmt
:= First_Elmt
(DT_Aggr
);
6353 while Present
(Elmt
) loop
6354 Set_Is_Dispatch_Table_Entity
(Etype
(Node
(Elmt
)));
6360 -- Register the tagged type in the call graph nodes table
6362 Register_CG_Node
(Typ
);
6371 function Make_VM_TSD
(Typ
: Entity_Id
) return List_Id
is
6372 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
6373 Result
: constant List_Id
:= New_List
;
6375 function Count_Primitives
(Typ
: Entity_Id
) return Nat
;
6376 -- Count the non-predefined primitive operations of Typ
6378 ----------------------
6379 -- Count_Primitives --
6380 ----------------------
6382 function Count_Primitives
(Typ
: Entity_Id
) return Nat
is
6384 Prim_Elmt
: Elmt_Id
;
6390 Prim_Elmt
:= First_Elmt
(Primitive_Operations
(Typ
));
6391 while Present
(Prim_Elmt
) loop
6392 Prim
:= Node
(Prim_Elmt
);
6394 if Is_Predefined_Dispatching_Operation
(Prim
)
6395 or else Is_Predefined_Dispatching_Alias
(Prim
)
6399 elsif Present
(Interface_Alias
(Prim
)) then
6403 Nb_Prim
:= Nb_Prim
+ 1;
6406 Next_Elmt
(Prim_Elmt
);
6410 end Count_Primitives
;
6416 function Make_OSD
(Iface
: Entity_Id
) return Node_Id
;
6417 -- Generate the Object Specific Data table required to dispatch calls
6418 -- through synchronized interfaces. Returns a node that references the
6419 -- generated OSD object.
6421 function Make_OSD
(Iface
: Entity_Id
) return Node_Id
is
6422 Nb_Prim
: constant Nat
:= Count_Primitives
(Iface
);
6424 OSD_Aggr_List
: List_Id
;
6428 -- OSD : Ada.Tags.Object_Specific_Data (Nb_Prims) :=
6429 -- (OSD_Table => (1 => <value>,
6434 or else Is_Abstract_Type
(Typ
)
6435 or else Is_Controlled
(Typ
)
6436 or else Restriction_Active
(No_Dispatching_Calls
)
6437 or else not Is_Limited_Type
(Typ
)
6438 or else not Has_Interfaces
(Typ
)
6439 or else not RTE_Record_Component_Available
(RE_OSD_Table
)
6441 -- No OSD table required
6443 return Make_Null
(Loc
);
6446 OSD_Aggr_List
:= New_List
;
6449 Prim_Table
: array (Nat
range 1 .. Nb_Prim
) of Entity_Id
;
6451 Prim_Alias
: Entity_Id
;
6452 Prim_Elmt
: Elmt_Id
;
6458 Prim_Table
:= (others => Empty
);
6459 Prim_Alias
:= Empty
;
6461 Prim_Elmt
:= First_Elmt
(Primitive_Operations
(Typ
));
6462 while Present
(Prim_Elmt
) loop
6463 Prim
:= Node
(Prim_Elmt
);
6465 if Present
(Interface_Alias
(Prim
))
6466 and then Find_Dispatching_Type
6467 (Interface_Alias
(Prim
)) = Iface
6469 Prim_Alias
:= Interface_Alias
(Prim
);
6470 E
:= Ultimate_Alias
(Prim
);
6471 Pos
:= UI_To_Int
(DT_Position
(Prim_Alias
));
6473 if Present
(Prim_Table
(Pos
)) then
6474 pragma Assert
(Prim_Table
(Pos
) = E
);
6478 Prim_Table
(Pos
) := E
;
6480 Append_To
(OSD_Aggr_List
,
6481 Make_Component_Association
(Loc
,
6482 Choices
=> New_List
(
6483 Make_Integer_Literal
(Loc
,
6484 DT_Position
(Prim_Alias
))),
6486 Make_Integer_Literal
(Loc
,
6487 DT_Position
(Alias
(Prim
)))));
6493 Next_Elmt
(Prim_Elmt
);
6495 pragma Assert
(Count
= Nb_Prim
);
6498 OSD
:= Make_Temporary
(Loc
, 'I');
6501 Make_Object_Declaration
(Loc
,
6502 Defining_Identifier
=> OSD
,
6503 Aliased_Present
=> True,
6504 Constant_Present
=> True,
6505 Object_Definition
=>
6506 Make_Subtype_Indication
(Loc
,
6508 New_Reference_To
(RTE
(RE_Object_Specific_Data
), Loc
),
6510 Make_Index_Or_Discriminant_Constraint
(Loc
,
6511 Constraints
=> New_List
(
6512 Make_Integer_Literal
(Loc
, Nb_Prim
)))),
6515 Make_Aggregate
(Loc
,
6516 Component_Associations
=> New_List
(
6517 Make_Component_Association
(Loc
,
6518 Choices
=> New_List
(
6520 (RTE_Record_Component
(RE_OSD_Num_Prims
), Loc
)),
6522 Make_Integer_Literal
(Loc
, Nb_Prim
)),
6524 Make_Component_Association
(Loc
,
6525 Choices
=> New_List
(
6527 (RTE_Record_Component
(RE_OSD_Table
), Loc
)),
6528 Expression
=> Make_Aggregate
(Loc
,
6529 Component_Associations
=> OSD_Aggr_List
))))));
6532 Make_Attribute_Reference
(Loc
,
6533 Prefix
=> New_Reference_To
(OSD
, Loc
),
6534 Attribute_Name
=> Name_Unchecked_Access
);
6540 Nb_Prim
: constant Nat
:= Count_Primitives
(Typ
);
6543 Iface_Table_Node
: Node_Id
;
6545 TSD_Aggr_List
: List_Id
;
6546 Typ_Ifaces
: Elist_Id
;
6547 TSD_Tags_List
: List_Id
;
6549 Tname
: constant Name_Id
:= Chars
(Typ
);
6550 Name_SSD
: constant Name_Id
:=
6551 New_External_Name
(Tname
, 'S', Suffix_Index
=> -1);
6552 Name_TSD
: constant Name_Id
:=
6553 New_External_Name
(Tname
, 'B', Suffix_Index
=> -1);
6554 SSD
: constant Entity_Id
:=
6555 Make_Defining_Identifier
(Loc
, Name_SSD
);
6556 TSD
: constant Entity_Id
:=
6557 Make_Defining_Identifier
(Loc
, Name_TSD
);
6559 -- Generate code to create the storage for the type specific data object
6560 -- with enough space to store the tags of the ancestors plus the tags
6561 -- of all the implemented interfaces (as described in a-tags.ads).
6563 -- TSD : Type_Specific_Data (I_Depth) :=
6564 -- (Idepth => I_Depth,
6565 -- Tag_Kind => <tag_kind-value>,
6566 -- Access_Level => Type_Access_Level (Typ),
6567 -- Alignment => Typ'Alignment,
6569 -- Type_Is_Abstract => <<boolean-value>>,
6570 -- Type_Is_Library_Level => <<boolean-value>>,
6571 -- Interfaces_Table => <<access-value>>
6572 -- SSD => SSD_Table'Address
6573 -- Tags_Table => (0 => Typ'Tag,
6577 TSD_Aggr_List
:= New_List
;
6579 -- Idepth: Count ancestors to compute the inheritance depth. For private
6580 -- extensions, always go to the full view in order to compute the real
6581 -- inheritance depth.
6584 Current_Typ
: Entity_Id
;
6585 Parent_Typ
: Entity_Id
;
6591 Parent_Typ
:= Etype
(Current_Typ
);
6593 if Is_Private_Type
(Parent_Typ
) then
6594 Parent_Typ
:= Full_View
(Base_Type
(Parent_Typ
));
6597 exit when Parent_Typ
= Current_Typ
;
6599 I_Depth
:= I_Depth
+ 1;
6600 Current_Typ
:= Parent_Typ
;
6606 Append_To
(TSD_Aggr_List
,
6607 Make_Integer_Literal
(Loc
, I_Depth
));
6611 Append_To
(TSD_Aggr_List
, Tagged_Kind
(Typ
));
6615 Append_To
(TSD_Aggr_List
,
6616 Make_Integer_Literal
(Loc
, Type_Access_Level
(Typ
)));
6620 -- For CPP types we cannot rely on the value of 'Alignment provided
6621 -- by the backend to initialize this TSD field. Why not???
6623 if Convention
(Typ
) = Convention_CPP
6624 or else Is_CPP_Class
(Root_Type
(Typ
))
6626 Append_To
(TSD_Aggr_List
,
6627 Make_Integer_Literal
(Loc
, 0));
6629 Append_To
(TSD_Aggr_List
,
6630 Make_Attribute_Reference
(Loc
,
6631 Prefix
=> New_Reference_To
(Typ
, Loc
),
6632 Attribute_Name
=> Name_Alignment
));
6637 Append_To
(TSD_Aggr_List
,
6640 -- Type_Is_Abstract (Ada 2012: AI05-0173)
6643 Type_Is_Abstract
: Entity_Id
;
6647 Boolean_Literals
(Is_Abstract_Type
(Typ
));
6649 Append_To
(TSD_Aggr_List
,
6650 New_Occurrence_Of
(Type_Is_Abstract
, Loc
));
6653 -- Type_Is_Library_Level
6656 Type_Is_Library_Level
: Entity_Id
;
6658 Type_Is_Library_Level
:=
6659 Boolean_Literals
(Is_Library_Level_Entity
(Typ
));
6660 Append_To
(TSD_Aggr_List
,
6661 New_Occurrence_Of
(Type_Is_Library_Level
, Loc
));
6664 -- Interfaces_Table (required for AI-405)
6666 if RTE_Record_Component_Available
(RE_Interfaces_Table
) then
6668 -- Count the number of interface types implemented by Typ
6670 Collect_Interfaces
(Typ
, Typ_Ifaces
);
6673 AI
:= First_Elmt
(Typ_Ifaces
);
6674 while Present
(AI
) loop
6675 Num_Ifaces
:= Num_Ifaces
+ 1;
6679 if Num_Ifaces
= 0 then
6680 Iface_Table_Node
:= Make_Null
(Loc
);
6682 -- Generate the Interface_Table object
6686 TSD_Ifaces_List
: constant List_Id
:= New_List
;
6691 AI
:= First_Elmt
(Typ_Ifaces
);
6692 while Present
(AI
) loop
6695 Append_To
(TSD_Ifaces_List
,
6696 Make_Aggregate
(Loc
,
6697 Expressions
=> New_List
(
6701 Make_Attribute_Reference
(Loc
,
6702 Prefix
=> New_Reference_To
(Iface
, Loc
),
6703 Attribute_Name
=> Name_Tag
),
6707 Make_OSD
(Iface
))));
6712 ITable
:= Make_Temporary
(Loc
, 'I');
6715 Make_Object_Declaration
(Loc
,
6716 Defining_Identifier
=> ITable
,
6717 Aliased_Present
=> True,
6718 Constant_Present
=> True,
6719 Object_Definition
=>
6720 Make_Subtype_Indication
(Loc
,
6722 New_Reference_To
(RTE
(RE_Interface_Data
), Loc
),
6723 Constraint
=> Make_Index_Or_Discriminant_Constraint
6725 Constraints
=> New_List
(
6726 Make_Integer_Literal
(Loc
, Num_Ifaces
)))),
6728 Expression
=> Make_Aggregate
(Loc
,
6729 Expressions
=> New_List
(
6730 Make_Integer_Literal
(Loc
, Num_Ifaces
),
6731 Make_Aggregate
(Loc
,
6732 Expressions
=> TSD_Ifaces_List
)))));
6735 Make_Attribute_Reference
(Loc
,
6736 Prefix
=> New_Reference_To
(ITable
, Loc
),
6737 Attribute_Name
=> Name_Unchecked_Access
);
6741 Append_To
(TSD_Aggr_List
, Iface_Table_Node
);
6744 -- Generate the Select Specific Data table for synchronized types that
6745 -- implement synchronized interfaces. The size of the table is
6746 -- constrained by the number of non-predefined primitive operations.
6748 if RTE_Record_Component_Available
(RE_SSD
) then
6749 if Ada_Version
>= Ada_2005
6750 and then Has_DT
(Typ
)
6751 and then Is_Concurrent_Record_Type
(Typ
)
6752 and then Has_Interfaces
(Typ
)
6753 and then Nb_Prim
> 0
6754 and then not Is_Abstract_Type
(Typ
)
6755 and then not Is_Controlled
(Typ
)
6756 and then not Restriction_Active
(No_Dispatching_Calls
)
6757 and then not Restriction_Active
(No_Select_Statements
)
6760 Make_Object_Declaration
(Loc
,
6761 Defining_Identifier
=> SSD
,
6762 Aliased_Present
=> True,
6763 Object_Definition
=>
6764 Make_Subtype_Indication
(Loc
,
6765 Subtype_Mark
=> New_Reference_To
(
6766 RTE
(RE_Select_Specific_Data
), Loc
),
6768 Make_Index_Or_Discriminant_Constraint
(Loc
,
6769 Constraints
=> New_List
(
6770 Make_Integer_Literal
(Loc
, Nb_Prim
))))));
6772 -- This table is initialized by Make_Select_Specific_Data_Table,
6773 -- which calls Set_Entry_Index and Set_Prim_Op_Kind.
6775 Append_To
(TSD_Aggr_List
,
6776 Make_Attribute_Reference
(Loc
,
6777 Prefix
=> New_Reference_To
(SSD
, Loc
),
6778 Attribute_Name
=> Name_Unchecked_Access
));
6780 Append_To
(TSD_Aggr_List
, Make_Null
(Loc
));
6784 -- Initialize the table of ancestor tags. In case of interface types
6785 -- this table is not needed.
6787 TSD_Tags_List
:= New_List
;
6789 -- Fill position 0 with Typ'Tag
6791 Append_To
(TSD_Tags_List
,
6792 Make_Attribute_Reference
(Loc
,
6793 Prefix
=> New_Reference_To
(Typ
, Loc
),
6794 Attribute_Name
=> Name_Tag
));
6796 -- Fill the rest of the table with the tags of the ancestors
6799 Current_Typ
: Entity_Id
;
6800 Parent_Typ
: Entity_Id
;
6808 Parent_Typ
:= Etype
(Current_Typ
);
6810 if Is_Private_Type
(Parent_Typ
) then
6811 Parent_Typ
:= Full_View
(Base_Type
(Parent_Typ
));
6814 exit when Parent_Typ
= Current_Typ
;
6816 Append_To
(TSD_Tags_List
,
6817 Make_Attribute_Reference
(Loc
,
6818 Prefix
=> New_Reference_To
(Parent_Typ
, Loc
),
6819 Attribute_Name
=> Name_Tag
));
6822 Current_Typ
:= Parent_Typ
;
6825 pragma Assert
(Pos
= I_Depth
+ 1);
6828 Append_To
(TSD_Aggr_List
,
6829 Make_Aggregate
(Loc
,
6830 Expressions
=> TSD_Tags_List
));
6832 -- Build the TSD object
6835 Make_Object_Declaration
(Loc
,
6836 Defining_Identifier
=> TSD
,
6837 Aliased_Present
=> True,
6838 Constant_Present
=> True,
6839 Object_Definition
=>
6840 Make_Subtype_Indication
(Loc
,
6841 Subtype_Mark
=> New_Reference_To
(
6842 RTE
(RE_Type_Specific_Data
), Loc
),
6844 Make_Index_Or_Discriminant_Constraint
(Loc
,
6845 Constraints
=> New_List
(
6846 Make_Integer_Literal
(Loc
, I_Depth
)))),
6848 Expression
=> Make_Aggregate
(Loc
,
6849 Expressions
=> TSD_Aggr_List
)));
6853 -- (TSD => TSD'Unrestricted_Access);
6855 if Ada_Version
>= Ada_2005
6856 and then Is_Library_Level_Entity
(Typ
)
6857 and then Has_External_Tag_Rep_Clause
(Typ
)
6858 and then RTE_Available
(RE_Check_TSD
)
6859 and then not Debug_Flag_QQ
6862 Make_Procedure_Call_Statement
(Loc
,
6863 Name
=> New_Reference_To
(RTE
(RE_Check_TSD
), Loc
),
6864 Parameter_Associations
=> New_List
(
6865 Make_Attribute_Reference
(Loc
,
6866 Prefix
=> New_Reference_To
(TSD
, Loc
),
6867 Attribute_Name
=> Name_Unrestricted_Access
))));
6871 -- Register_TSD (TSD'Unrestricted_Access);
6874 Make_Procedure_Call_Statement
(Loc
,
6875 Name
=> New_Reference_To
(RTE
(RE_Register_TSD
), Loc
),
6876 Parameter_Associations
=> New_List
(
6877 Make_Attribute_Reference
(Loc
,
6878 Prefix
=> New_Reference_To
(TSD
, Loc
),
6879 Attribute_Name
=> Name_Unrestricted_Access
))));
6881 -- Populate the two auxiliary tables used for dispatching asynchronous,
6882 -- conditional and timed selects for synchronized types that implement
6883 -- a limited interface. Skip this step in Ravenscar profile or when
6884 -- general dispatching is forbidden.
6886 if Ada_Version
>= Ada_2005
6887 and then Is_Concurrent_Record_Type
(Typ
)
6888 and then Has_Interfaces
(Typ
)
6889 and then not Restriction_Active
(No_Dispatching_Calls
)
6890 and then not Restriction_Active
(No_Select_Statements
)
6892 Append_List_To
(Result
,
6893 Make_Select_Specific_Data_Table
(Typ
));
6899 -------------------------------------
6900 -- Make_Select_Specific_Data_Table --
6901 -------------------------------------
6903 function Make_Select_Specific_Data_Table
6904 (Typ
: Entity_Id
) return List_Id
6906 Assignments
: constant List_Id
:= New_List
;
6907 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
6909 Conc_Typ
: Entity_Id
;
6912 Prim_Als
: Entity_Id
;
6913 Prim_Elmt
: Elmt_Id
;
6917 type Examined_Array
is array (Int
range <>) of Boolean;
6919 function Find_Entry_Index
(E
: Entity_Id
) return Uint
;
6920 -- Given an entry, find its index in the visible declarations of the
6921 -- corresponding concurrent type of Typ.
6923 ----------------------
6924 -- Find_Entry_Index --
6925 ----------------------
6927 function Find_Entry_Index
(E
: Entity_Id
) return Uint
is
6928 Index
: Uint
:= Uint_1
;
6929 Subp_Decl
: Entity_Id
;
6933 and then not Is_Empty_List
(Decls
)
6935 Subp_Decl
:= First
(Decls
);
6936 while Present
(Subp_Decl
) loop
6937 if Nkind
(Subp_Decl
) = N_Entry_Declaration
then
6938 if Defining_Identifier
(Subp_Decl
) = E
then
6950 end Find_Entry_Index
;
6956 -- Start of processing for Make_Select_Specific_Data_Table
6959 pragma Assert
(not Restriction_Active
(No_Dispatching_Calls
));
6961 if Present
(Corresponding_Concurrent_Type
(Typ
)) then
6962 Conc_Typ
:= Corresponding_Concurrent_Type
(Typ
);
6964 if Present
(Full_View
(Conc_Typ
)) then
6965 Conc_Typ
:= Full_View
(Conc_Typ
);
6968 if Ekind
(Conc_Typ
) = E_Protected_Type
then
6969 Decls
:= Visible_Declarations
(Protected_Definition
(
6970 Parent
(Conc_Typ
)));
6972 pragma Assert
(Ekind
(Conc_Typ
) = E_Task_Type
);
6973 Decls
:= Visible_Declarations
(Task_Definition
(
6974 Parent
(Conc_Typ
)));
6978 -- Count the non-predefined primitive operations
6980 Prim_Elmt
:= First_Elmt
(Primitive_Operations
(Typ
));
6981 while Present
(Prim_Elmt
) loop
6982 Prim
:= Node
(Prim_Elmt
);
6984 if not (Is_Predefined_Dispatching_Operation
(Prim
)
6985 or else Is_Predefined_Dispatching_Alias
(Prim
))
6987 Nb_Prim
:= Nb_Prim
+ 1;
6990 Next_Elmt
(Prim_Elmt
);
6994 Examined
: Examined_Array
(1 .. Nb_Prim
) := (others => False);
6997 Prim_Elmt
:= First_Elmt
(Primitive_Operations
(Typ
));
6998 while Present
(Prim_Elmt
) loop
6999 Prim
:= Node
(Prim_Elmt
);
7001 -- Look for primitive overriding an abstract interface subprogram
7003 if Present
(Interface_Alias
(Prim
))
7006 (Find_Dispatching_Type
(Interface_Alias
(Prim
)), Typ
,
7007 Use_Full_View
=> True)
7008 and then not Examined
(UI_To_Int
(DT_Position
(Alias
(Prim
))))
7010 Prim_Pos
:= DT_Position
(Alias
(Prim
));
7011 pragma Assert
(UI_To_Int
(Prim_Pos
) <= Nb_Prim
);
7012 Examined
(UI_To_Int
(Prim_Pos
)) := True;
7014 -- Set the primitive operation kind regardless of subprogram
7016 -- Ada.Tags.Set_Prim_Op_Kind (DT_Ptr, <position>, <kind>);
7018 if Tagged_Type_Expansion
then
7021 (Node
(First_Elmt
(Access_Disp_Table
(Typ
))), Loc
);
7025 Make_Attribute_Reference
(Loc
,
7026 Prefix
=> New_Reference_To
(Typ
, Loc
),
7027 Attribute_Name
=> Name_Tag
);
7030 Append_To
(Assignments
,
7031 Make_Procedure_Call_Statement
(Loc
,
7032 Name
=> New_Reference_To
(RTE
(RE_Set_Prim_Op_Kind
), Loc
),
7033 Parameter_Associations
=> New_List
(
7035 Make_Integer_Literal
(Loc
, Prim_Pos
),
7036 Prim_Op_Kind
(Alias
(Prim
), Typ
))));
7038 -- Retrieve the root of the alias chain
7040 Prim_Als
:= Ultimate_Alias
(Prim
);
7042 -- In the case of an entry wrapper, set the entry index
7044 if Ekind
(Prim
) = E_Procedure
7045 and then Is_Primitive_Wrapper
(Prim_Als
)
7046 and then Ekind
(Wrapped_Entity
(Prim_Als
)) = E_Entry
7049 -- Ada.Tags.Set_Entry_Index
7050 -- (DT_Ptr, <position>, <index>);
7052 if Tagged_Type_Expansion
then
7055 (Node
(First_Elmt
(Access_Disp_Table
(Typ
))), Loc
);
7058 Make_Attribute_Reference
(Loc
,
7059 Prefix
=> New_Reference_To
(Typ
, Loc
),
7060 Attribute_Name
=> Name_Tag
);
7063 Append_To
(Assignments
,
7064 Make_Procedure_Call_Statement
(Loc
,
7066 New_Reference_To
(RTE
(RE_Set_Entry_Index
), Loc
),
7067 Parameter_Associations
=> New_List
(
7069 Make_Integer_Literal
(Loc
, Prim_Pos
),
7070 Make_Integer_Literal
(Loc
,
7071 Find_Entry_Index
(Wrapped_Entity
(Prim_Als
))))));
7075 Next_Elmt
(Prim_Elmt
);
7080 end Make_Select_Specific_Data_Table
;
7086 function Make_Tags
(Typ
: Entity_Id
) return List_Id
is
7087 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
7088 Result
: constant List_Id
:= New_List
;
7091 (Tag_Typ
: Entity_Id
;
7093 Is_Secondary_DT
: Boolean);
7094 -- Import the dispatch table DT of tagged type Tag_Typ. Required to
7095 -- generate forward references and statically allocate the table. For
7096 -- primary dispatch tables that require no dispatch table generate:
7098 -- DT : static aliased constant Non_Dispatch_Table_Wrapper;
7099 -- pragma Import (Ada, DT);
7101 -- Otherwise generate:
7103 -- DT : static aliased constant Dispatch_Table_Wrapper (Nb_Prim);
7104 -- pragma Import (Ada, DT);
7111 (Tag_Typ
: Entity_Id
;
7113 Is_Secondary_DT
: Boolean)
7115 DT_Constr_List
: List_Id
;
7119 Set_Is_Imported
(DT
);
7120 Set_Ekind
(DT
, E_Constant
);
7121 Set_Related_Type
(DT
, Typ
);
7123 -- The scope must be set now to call Get_External_Name
7125 Set_Scope
(DT
, Current_Scope
);
7127 Get_External_Name
(DT
, True);
7128 Set_Interface_Name
(DT
,
7129 Make_String_Literal
(Loc
, Strval
=> String_From_Name_Buffer
));
7131 -- Ensure proper Sprint output of this implicit importation
7133 Set_Is_Internal
(DT
);
7135 -- Save this entity to allow Make_DT to generate its exportation
7137 Append_Elmt
(DT
, Dispatch_Table_Wrappers
(Typ
));
7139 -- No dispatch table required
7141 if not Is_Secondary_DT
and then not Has_DT
(Tag_Typ
) then
7143 Make_Object_Declaration
(Loc
,
7144 Defining_Identifier
=> DT
,
7145 Aliased_Present
=> True,
7146 Constant_Present
=> True,
7147 Object_Definition
=>
7148 New_Reference_To
(RTE
(RE_No_Dispatch_Table_Wrapper
), Loc
)));
7151 -- Calculate the number of primitives of the dispatch table and
7152 -- the size of the Type_Specific_Data record.
7155 UI_To_Int
(DT_Entry_Count
(First_Tag_Component
(Tag_Typ
)));
7157 -- If the tagged type has no primitives we add a dummy slot whose
7158 -- address will be the tag of this type.
7162 New_List
(Make_Integer_Literal
(Loc
, 1));
7165 New_List
(Make_Integer_Literal
(Loc
, Nb_Prim
));
7169 Make_Object_Declaration
(Loc
,
7170 Defining_Identifier
=> DT
,
7171 Aliased_Present
=> True,
7172 Constant_Present
=> True,
7173 Object_Definition
=>
7174 Make_Subtype_Indication
(Loc
,
7176 New_Reference_To
(RTE
(RE_Dispatch_Table_Wrapper
), Loc
),
7177 Constraint
=> Make_Index_Or_Discriminant_Constraint
(Loc
,
7178 Constraints
=> DT_Constr_List
))));
7184 Tname
: constant Name_Id
:= Chars
(Typ
);
7185 AI_Tag_Comp
: Elmt_Id
;
7186 DT
: Node_Id
:= Empty
;
7188 Predef_Prims_Ptr
: Node_Id
;
7189 Iface_DT
: Node_Id
:= Empty
;
7190 Iface_DT_Ptr
: Node_Id
;
7194 Typ_Comps
: Elist_Id
;
7196 -- Start of processing for Make_Tags
7199 pragma Assert
(No
(Access_Disp_Table
(Typ
)));
7200 Set_Access_Disp_Table
(Typ
, New_Elmt_List
);
7202 -- 1) Generate the primary tag entities
7204 -- Primary dispatch table containing user-defined primitives
7206 DT_Ptr
:= Make_Defining_Identifier
(Loc
, New_External_Name
(Tname
, 'P'));
7207 Set_Etype
(DT_Ptr
, RTE
(RE_Tag
));
7208 Append_Elmt
(DT_Ptr
, Access_Disp_Table
(Typ
));
7210 -- Minimum decoration
7212 Set_Ekind
(DT_Ptr
, E_Variable
);
7213 Set_Related_Type
(DT_Ptr
, Typ
);
7215 -- Ensure that entities Prim_Ptr and Predef_Prims_Table_Ptr have
7216 -- the decoration required by the backend.
7218 -- Odd comment, the back end cannot require anything not properly
7219 -- documented in einfo! ???
7221 Set_Is_Dispatch_Table_Entity
(RTE
(RE_Prim_Ptr
));
7222 Set_Is_Dispatch_Table_Entity
(RTE
(RE_Predef_Prims_Table_Ptr
));
7224 -- For CPP types there is no need to build the dispatch tables since
7225 -- they are imported from the C++ side. If the CPP type has an IP then
7226 -- we declare now the variable that will store the copy of the C++ tag.
7227 -- If the CPP type is an interface, we need the variable as well because
7228 -- it becomes the pointer to the corresponding secondary table.
7230 if Is_CPP_Class
(Typ
) then
7231 if Has_CPP_Constructors
(Typ
) or else Is_Interface
(Typ
) then
7233 Make_Object_Declaration
(Loc
,
7234 Defining_Identifier
=> DT_Ptr
,
7235 Object_Definition
=> New_Reference_To
(RTE
(RE_Tag
), Loc
),
7237 Unchecked_Convert_To
(RTE
(RE_Tag
),
7238 New_Reference_To
(RTE
(RE_Null_Address
), Loc
))));
7240 Set_Is_Statically_Allocated
(DT_Ptr
,
7241 Is_Library_Level_Tagged_Type
(Typ
));
7247 -- Primary dispatch table containing predefined primitives
7250 Make_Defining_Identifier
(Loc
,
7251 Chars
=> New_External_Name
(Tname
, 'Y'));
7252 Set_Etype
(Predef_Prims_Ptr
, RTE
(RE_Address
));
7253 Append_Elmt
(Predef_Prims_Ptr
, Access_Disp_Table
(Typ
));
7255 -- Import the forward declaration of the Dispatch Table wrapper
7256 -- record (Make_DT will take care of exporting it).
7258 if Building_Static_DT
(Typ
) then
7259 Set_Dispatch_Table_Wrappers
(Typ
, New_Elmt_List
);
7262 Make_Defining_Identifier
(Loc
,
7263 Chars
=> New_External_Name
(Tname
, 'T'));
7265 Import_DT
(Typ
, DT
, Is_Secondary_DT
=> False);
7267 if Has_DT
(Typ
) then
7269 Make_Object_Declaration
(Loc
,
7270 Defining_Identifier
=> DT_Ptr
,
7271 Constant_Present
=> True,
7272 Object_Definition
=> New_Reference_To
(RTE
(RE_Tag
), Loc
),
7274 Unchecked_Convert_To
(RTE
(RE_Tag
),
7275 Make_Attribute_Reference
(Loc
,
7277 Make_Selected_Component
(Loc
,
7278 Prefix
=> New_Reference_To
(DT
, Loc
),
7281 (RTE_Record_Component
(RE_Prims_Ptr
), Loc
)),
7282 Attribute_Name
=> Name_Address
))));
7284 -- Generate the SCIL node for the previous object declaration
7285 -- because it has a tag initialization.
7287 if Generate_SCIL
then
7289 Make_SCIL_Dispatch_Table_Tag_Init
(Sloc
(Last
(Result
)));
7290 Set_SCIL_Entity
(New_Node
, Typ
);
7291 Set_SCIL_Node
(Last
(Result
), New_Node
);
7295 Make_Object_Declaration
(Loc
,
7296 Defining_Identifier
=> Predef_Prims_Ptr
,
7297 Constant_Present
=> True,
7298 Object_Definition
=>
7299 New_Reference_To
(RTE
(RE_Address
), Loc
),
7301 Make_Attribute_Reference
(Loc
,
7303 Make_Selected_Component
(Loc
,
7304 Prefix
=> New_Reference_To
(DT
, Loc
),
7307 (RTE_Record_Component
(RE_Predef_Prims
), Loc
)),
7308 Attribute_Name
=> Name_Address
)));
7310 -- No dispatch table required
7314 Make_Object_Declaration
(Loc
,
7315 Defining_Identifier
=> DT_Ptr
,
7316 Constant_Present
=> True,
7317 Object_Definition
=> New_Reference_To
(RTE
(RE_Tag
), Loc
),
7319 Unchecked_Convert_To
(RTE
(RE_Tag
),
7320 Make_Attribute_Reference
(Loc
,
7322 Make_Selected_Component
(Loc
,
7323 Prefix
=> New_Reference_To
(DT
, Loc
),
7326 (RTE_Record_Component
(RE_NDT_Prims_Ptr
),
7328 Attribute_Name
=> Name_Address
))));
7331 Set_Is_True_Constant
(DT_Ptr
);
7332 Set_Is_Statically_Allocated
(DT_Ptr
);
7336 -- 2) Generate the secondary tag entities
7338 -- Collect the components associated with secondary dispatch tables
7340 if Has_Interfaces
(Typ
) then
7341 Collect_Interface_Components
(Typ
, Typ_Comps
);
7343 -- For each interface type we build a unique external name associated
7344 -- with its secondary dispatch table. This name is used to declare an
7345 -- object that references this secondary dispatch table, whose value
7346 -- will be used for the elaboration of Typ objects, and also for the
7347 -- elaboration of objects of types derived from Typ that do not
7348 -- override the primitives of this interface type.
7352 -- Note: The value of Suffix_Index must be in sync with the
7353 -- Suffix_Index values of secondary dispatch tables generated
7356 if Is_CPP_Class
(Typ
) then
7357 AI_Tag_Comp
:= First_Elmt
(Typ_Comps
);
7358 while Present
(AI_Tag_Comp
) loop
7359 Get_Secondary_DT_External_Name
7360 (Typ
, Related_Type
(Node
(AI_Tag_Comp
)), Suffix_Index
);
7361 Typ_Name
:= Name_Find
;
7363 -- Declare variables that will store the copy of the C++
7367 Make_Defining_Identifier
(Loc
,
7368 Chars
=> New_External_Name
(Typ_Name
, 'P'));
7369 Set_Etype
(Iface_DT_Ptr
, RTE
(RE_Interface_Tag
));
7370 Set_Ekind
(Iface_DT_Ptr
, E_Variable
);
7371 Set_Is_Tag
(Iface_DT_Ptr
);
7373 Set_Has_Thunks
(Iface_DT_Ptr
);
7375 (Iface_DT_Ptr
, Related_Type
(Node
(AI_Tag_Comp
)));
7376 Append_Elmt
(Iface_DT_Ptr
, Access_Disp_Table
(Typ
));
7379 Make_Object_Declaration
(Loc
,
7380 Defining_Identifier
=> Iface_DT_Ptr
,
7381 Object_Definition
=> New_Reference_To
7382 (RTE
(RE_Interface_Tag
), Loc
),
7384 Unchecked_Convert_To
(RTE
(RE_Interface_Tag
),
7385 New_Reference_To
(RTE
(RE_Null_Address
), Loc
))));
7387 Set_Is_Statically_Allocated
(Iface_DT_Ptr
,
7388 Is_Library_Level_Tagged_Type
(Typ
));
7390 Next_Elmt
(AI_Tag_Comp
);
7393 -- This is not a CPP_Class type
7396 AI_Tag_Comp
:= First_Elmt
(Typ_Comps
);
7397 while Present
(AI_Tag_Comp
) loop
7398 Get_Secondary_DT_External_Name
7399 (Typ
, Related_Type
(Node
(AI_Tag_Comp
)), Suffix_Index
);
7400 Typ_Name
:= Name_Find
;
7402 if Building_Static_DT
(Typ
) then
7404 Make_Defining_Identifier
(Loc
,
7405 Chars
=> New_External_Name
7406 (Typ_Name
, 'T', Suffix_Index
=> -1));
7408 (Tag_Typ
=> Related_Type
(Node
(AI_Tag_Comp
)),
7410 Is_Secondary_DT
=> True);
7413 -- Secondary dispatch table referencing thunks to user-defined
7414 -- primitives covered by this interface.
7417 Make_Defining_Identifier
(Loc
,
7418 Chars
=> New_External_Name
(Typ_Name
, 'P'));
7419 Set_Etype
(Iface_DT_Ptr
, RTE
(RE_Interface_Tag
));
7420 Set_Ekind
(Iface_DT_Ptr
, E_Constant
);
7421 Set_Is_Tag
(Iface_DT_Ptr
);
7422 Set_Has_Thunks
(Iface_DT_Ptr
);
7423 Set_Is_Statically_Allocated
(Iface_DT_Ptr
,
7424 Is_Library_Level_Tagged_Type
(Typ
));
7425 Set_Is_True_Constant
(Iface_DT_Ptr
);
7427 (Iface_DT_Ptr
, Related_Type
(Node
(AI_Tag_Comp
)));
7428 Append_Elmt
(Iface_DT_Ptr
, Access_Disp_Table
(Typ
));
7430 if Building_Static_DT
(Typ
) then
7432 Make_Object_Declaration
(Loc
,
7433 Defining_Identifier
=> Iface_DT_Ptr
,
7434 Constant_Present
=> True,
7435 Object_Definition
=> New_Reference_To
7436 (RTE
(RE_Interface_Tag
), Loc
),
7438 Unchecked_Convert_To
(RTE
(RE_Interface_Tag
),
7439 Make_Attribute_Reference
(Loc
,
7441 Make_Selected_Component
(Loc
,
7443 New_Reference_To
(Iface_DT
, Loc
),
7446 (RTE_Record_Component
(RE_Prims_Ptr
),
7448 Attribute_Name
=> Name_Address
))));
7451 -- Secondary dispatch table referencing thunks to predefined
7455 Make_Defining_Identifier
(Loc
,
7456 Chars
=> New_External_Name
(Typ_Name
, 'Y'));
7457 Set_Etype
(Iface_DT_Ptr
, RTE
(RE_Address
));
7458 Set_Ekind
(Iface_DT_Ptr
, E_Constant
);
7459 Set_Is_Tag
(Iface_DT_Ptr
);
7460 Set_Has_Thunks
(Iface_DT_Ptr
);
7461 Set_Is_Statically_Allocated
(Iface_DT_Ptr
,
7462 Is_Library_Level_Tagged_Type
(Typ
));
7463 Set_Is_True_Constant
(Iface_DT_Ptr
);
7465 (Iface_DT_Ptr
, Related_Type
(Node
(AI_Tag_Comp
)));
7466 Append_Elmt
(Iface_DT_Ptr
, Access_Disp_Table
(Typ
));
7468 -- Secondary dispatch table referencing user-defined primitives
7469 -- covered by this interface.
7472 Make_Defining_Identifier
(Loc
,
7473 Chars
=> New_External_Name
(Typ_Name
, 'D'));
7474 Set_Etype
(Iface_DT_Ptr
, RTE
(RE_Interface_Tag
));
7475 Set_Ekind
(Iface_DT_Ptr
, E_Constant
);
7476 Set_Is_Tag
(Iface_DT_Ptr
);
7477 Set_Is_Statically_Allocated
(Iface_DT_Ptr
,
7478 Is_Library_Level_Tagged_Type
(Typ
));
7479 Set_Is_True_Constant
(Iface_DT_Ptr
);
7481 (Iface_DT_Ptr
, Related_Type
(Node
(AI_Tag_Comp
)));
7482 Append_Elmt
(Iface_DT_Ptr
, Access_Disp_Table
(Typ
));
7484 -- Secondary dispatch table referencing predefined primitives
7487 Make_Defining_Identifier
(Loc
,
7488 Chars
=> New_External_Name
(Typ_Name
, 'Z'));
7489 Set_Etype
(Iface_DT_Ptr
, RTE
(RE_Address
));
7490 Set_Ekind
(Iface_DT_Ptr
, E_Constant
);
7491 Set_Is_Tag
(Iface_DT_Ptr
);
7492 Set_Is_Statically_Allocated
(Iface_DT_Ptr
,
7493 Is_Library_Level_Tagged_Type
(Typ
));
7494 Set_Is_True_Constant
(Iface_DT_Ptr
);
7496 (Iface_DT_Ptr
, Related_Type
(Node
(AI_Tag_Comp
)));
7497 Append_Elmt
(Iface_DT_Ptr
, Access_Disp_Table
(Typ
));
7499 Next_Elmt
(AI_Tag_Comp
);
7504 -- 3) At the end of Access_Disp_Table, if the type has user-defined
7505 -- primitives, we add the entity of an access type declaration that
7506 -- is used by Build_Get_Prim_Op_Address to expand dispatching calls
7507 -- through the primary dispatch table.
7509 if UI_To_Int
(DT_Entry_Count
(First_Tag_Component
(Typ
))) = 0 then
7510 Analyze_List
(Result
);
7513 -- type Typ_DT is array (1 .. Nb_Prims) of Prim_Ptr;
7514 -- type Typ_DT_Acc is access Typ_DT;
7518 Name_DT_Prims
: constant Name_Id
:=
7519 New_External_Name
(Tname
, 'G');
7520 Name_DT_Prims_Acc
: constant Name_Id
:=
7521 New_External_Name
(Tname
, 'H');
7522 DT_Prims
: constant Entity_Id
:=
7523 Make_Defining_Identifier
(Loc
,
7525 DT_Prims_Acc
: constant Entity_Id
:=
7526 Make_Defining_Identifier
(Loc
,
7530 Make_Full_Type_Declaration
(Loc
,
7531 Defining_Identifier
=> DT_Prims
,
7533 Make_Constrained_Array_Definition
(Loc
,
7534 Discrete_Subtype_Definitions
=> New_List
(
7536 Low_Bound
=> Make_Integer_Literal
(Loc
, 1),
7537 High_Bound
=> Make_Integer_Literal
(Loc
,
7539 (First_Tag_Component
(Typ
))))),
7540 Component_Definition
=>
7541 Make_Component_Definition
(Loc
,
7542 Subtype_Indication
=>
7543 New_Reference_To
(RTE
(RE_Prim_Ptr
), Loc
)))));
7546 Make_Full_Type_Declaration
(Loc
,
7547 Defining_Identifier
=> DT_Prims_Acc
,
7549 Make_Access_To_Object_Definition
(Loc
,
7550 Subtype_Indication
=>
7551 New_Occurrence_Of
(DT_Prims
, Loc
))));
7553 Append_Elmt
(DT_Prims_Acc
, Access_Disp_Table
(Typ
));
7555 -- Analyze the resulting list and suppress the generation of the
7556 -- Init_Proc associated with the above array declaration because
7557 -- this type is never used in object declarations. It is only used
7558 -- to simplify the expansion associated with dispatching calls.
7560 Analyze_List
(Result
);
7561 Set_Suppress_Initialization
(Base_Type
(DT_Prims
));
7563 -- Disable backend optimizations based on assumptions about the
7564 -- aliasing status of objects designated by the access to the
7565 -- dispatch table. Required to handle dispatch tables imported
7568 Set_No_Strict_Aliasing
(Base_Type
(DT_Prims_Acc
));
7570 -- Add the freezing nodes of these declarations; required to avoid
7571 -- generating these freezing nodes in wrong scopes (for example in
7572 -- the IC routine of a derivation of Typ).
7573 -- What is an "IC routine"? Is "init_proc" meant here???
7575 Append_List_To
(Result
, Freeze_Entity
(DT_Prims
, Typ
));
7576 Append_List_To
(Result
, Freeze_Entity
(DT_Prims_Acc
, Typ
));
7578 -- Mark entity of dispatch table. Required by the back end to
7579 -- handle them properly.
7581 Set_Is_Dispatch_Table_Entity
(DT_Prims
);
7585 -- Mark entities of dispatch table. Required by the back end to handle
7588 if Present
(DT
) then
7589 Set_Is_Dispatch_Table_Entity
(DT
);
7590 Set_Is_Dispatch_Table_Entity
(Etype
(DT
));
7593 if Present
(Iface_DT
) then
7594 Set_Is_Dispatch_Table_Entity
(Iface_DT
);
7595 Set_Is_Dispatch_Table_Entity
(Etype
(Iface_DT
));
7598 if Is_CPP_Class
(Root_Type
(Typ
)) then
7599 Set_Ekind
(DT_Ptr
, E_Variable
);
7601 Set_Ekind
(DT_Ptr
, E_Constant
);
7604 Set_Is_Tag
(DT_Ptr
);
7605 Set_Related_Type
(DT_Ptr
, Typ
);
7614 function New_Value
(From
: Node_Id
) return Node_Id
is
7615 Res
: constant Node_Id
:= Duplicate_Subexpr
(From
);
7617 if Is_Access_Type
(Etype
(From
)) then
7619 Make_Explicit_Dereference
(Sloc
(From
),
7626 -----------------------------------
7627 -- Original_View_In_Visible_Part --
7628 -----------------------------------
7630 function Original_View_In_Visible_Part
(Typ
: Entity_Id
) return Boolean is
7631 Scop
: constant Entity_Id
:= Scope
(Typ
);
7634 -- The scope must be a package
7636 if not Is_Package_Or_Generic_Package
(Scop
) then
7640 -- A type with a private declaration has a private view declared in
7641 -- the visible part.
7643 if Has_Private_Declaration
(Typ
) then
7647 return List_Containing
(Parent
(Typ
)) =
7648 Visible_Declarations
(Package_Specification
(Scop
));
7649 end Original_View_In_Visible_Part
;
7655 function Prim_Op_Kind
7657 Typ
: Entity_Id
) return Node_Id
7659 Full_Typ
: Entity_Id
:= Typ
;
7660 Loc
: constant Source_Ptr
:= Sloc
(Prim
);
7661 Prim_Op
: Entity_Id
;
7664 -- Retrieve the original primitive operation
7666 Prim_Op
:= Ultimate_Alias
(Prim
);
7668 if Ekind
(Typ
) = E_Record_Type
7669 and then Present
(Corresponding_Concurrent_Type
(Typ
))
7671 Full_Typ
:= Corresponding_Concurrent_Type
(Typ
);
7674 -- When a private tagged type is completed by a concurrent type,
7675 -- retrieve the full view.
7677 if Is_Private_Type
(Full_Typ
) then
7678 Full_Typ
:= Full_View
(Full_Typ
);
7681 if Ekind
(Prim_Op
) = E_Function
then
7683 -- Protected function
7685 if Ekind
(Full_Typ
) = E_Protected_Type
then
7686 return New_Reference_To
(RTE
(RE_POK_Protected_Function
), Loc
);
7690 elsif Ekind
(Full_Typ
) = E_Task_Type
then
7691 return New_Reference_To
(RTE
(RE_POK_Task_Function
), Loc
);
7696 return New_Reference_To
(RTE
(RE_POK_Function
), Loc
);
7700 pragma Assert
(Ekind
(Prim_Op
) = E_Procedure
);
7702 if Ekind
(Full_Typ
) = E_Protected_Type
then
7706 if Is_Primitive_Wrapper
(Prim_Op
)
7707 and then Ekind
(Wrapped_Entity
(Prim_Op
)) = E_Entry
7709 return New_Reference_To
(RTE
(RE_POK_Protected_Entry
), Loc
);
7711 -- Protected procedure
7714 return New_Reference_To
(RTE
(RE_POK_Protected_Procedure
), Loc
);
7717 elsif Ekind
(Full_Typ
) = E_Task_Type
then
7721 if Is_Primitive_Wrapper
(Prim_Op
)
7722 and then Ekind
(Wrapped_Entity
(Prim_Op
)) = E_Entry
7724 return New_Reference_To
(RTE
(RE_POK_Task_Entry
), Loc
);
7726 -- Task "procedure". These are the internally Expander-generated
7727 -- procedures (task body for instance).
7730 return New_Reference_To
(RTE
(RE_POK_Task_Procedure
), Loc
);
7733 -- Regular procedure
7736 return New_Reference_To
(RTE
(RE_POK_Procedure
), Loc
);
7741 ------------------------
7742 -- Register_Primitive --
7743 ------------------------
7745 function Register_Primitive
7747 Prim
: Entity_Id
) return List_Id
7750 Iface_Prim
: Entity_Id
;
7751 Iface_Typ
: Entity_Id
;
7752 Iface_DT_Ptr
: Entity_Id
;
7753 Iface_DT_Elmt
: Elmt_Id
;
7754 L
: constant List_Id
:= New_List
;
7757 Tag_Typ
: Entity_Id
;
7758 Thunk_Id
: Entity_Id
;
7759 Thunk_Code
: Node_Id
;
7762 pragma Assert
(not Restriction_Active
(No_Dispatching_Calls
));
7763 pragma Assert
(VM_Target
= No_VM
);
7765 -- Do not register in the dispatch table eliminated primitives
7767 if not RTE_Available
(RE_Tag
)
7768 or else Is_Eliminated
(Ultimate_Alias
(Prim
))
7773 if not Present
(Interface_Alias
(Prim
)) then
7774 Tag_Typ
:= Scope
(DTC_Entity
(Prim
));
7775 Pos
:= DT_Position
(Prim
);
7776 Tag
:= First_Tag_Component
(Tag_Typ
);
7778 if Is_Predefined_Dispatching_Operation
(Prim
)
7779 or else Is_Predefined_Dispatching_Alias
(Prim
)
7782 Node
(Next_Elmt
(First_Elmt
(Access_Disp_Table
(Tag_Typ
))));
7785 Build_Set_Predefined_Prim_Op_Address
(Loc
,
7786 Tag_Node
=> New_Reference_To
(DT_Ptr
, Loc
),
7789 Unchecked_Convert_To
(RTE
(RE_Prim_Ptr
),
7790 Make_Attribute_Reference
(Loc
,
7791 Prefix
=> New_Reference_To
(Prim
, Loc
),
7792 Attribute_Name
=> Name_Unrestricted_Access
))));
7794 -- Register copy of the pointer to the 'size primitive in the TSD
7796 if Chars
(Prim
) = Name_uSize
7797 and then RTE_Record_Component_Available
(RE_Size_Func
)
7799 DT_Ptr
:= Node
(First_Elmt
(Access_Disp_Table
(Tag_Typ
)));
7801 Build_Set_Size_Function
(Loc
,
7802 Tag_Node
=> New_Reference_To
(DT_Ptr
, Loc
),
7803 Size_Func
=> Prim
));
7807 pragma Assert
(Pos
/= Uint_0
and then Pos
<= DT_Entry_Count
(Tag
));
7809 -- Skip registration of primitives located in the C++ part of the
7810 -- dispatch table. Their slot is set by the IC routine.
7812 if not Is_CPP_Class
(Root_Type
(Tag_Typ
))
7813 or else Pos
> CPP_Num_Prims
(Tag_Typ
)
7815 DT_Ptr
:= Node
(First_Elmt
(Access_Disp_Table
(Tag_Typ
)));
7817 Build_Set_Prim_Op_Address
(Loc
,
7819 Tag_Node
=> New_Reference_To
(DT_Ptr
, Loc
),
7822 Unchecked_Convert_To
(RTE
(RE_Prim_Ptr
),
7823 Make_Attribute_Reference
(Loc
,
7824 Prefix
=> New_Reference_To
(Prim
, Loc
),
7825 Attribute_Name
=> Name_Unrestricted_Access
))));
7829 -- Ada 2005 (AI-251): Primitive associated with an interface type
7830 -- Generate the code of the thunk only if the interface type is not an
7831 -- immediate ancestor of Typ; otherwise the dispatch table associated
7832 -- with the interface is the primary dispatch table and we have nothing
7836 Tag_Typ
:= Find_Dispatching_Type
(Alias
(Prim
));
7837 Iface_Typ
:= Find_Dispatching_Type
(Interface_Alias
(Prim
));
7839 pragma Assert
(Is_Interface
(Iface_Typ
));
7841 -- No action needed for interfaces that are ancestors of Typ because
7842 -- their primitives are located in the primary dispatch table.
7844 if Is_Ancestor
(Iface_Typ
, Tag_Typ
, Use_Full_View
=> True) then
7847 -- No action needed for primitives located in the C++ part of the
7848 -- dispatch table. Their slot is set by the IC routine.
7850 elsif Is_CPP_Class
(Root_Type
(Tag_Typ
))
7851 and then DT_Position
(Alias
(Prim
)) <= CPP_Num_Prims
(Tag_Typ
)
7852 and then not Is_Predefined_Dispatching_Operation
(Prim
)
7853 and then not Is_Predefined_Dispatching_Alias
(Prim
)
7858 Expand_Interface_Thunk
(Prim
, Thunk_Id
, Thunk_Code
);
7860 if not Is_Ancestor
(Iface_Typ
, Tag_Typ
, Use_Full_View
=> True)
7861 and then Present
(Thunk_Code
)
7863 -- Generate the code necessary to fill the appropriate entry of
7864 -- the secondary dispatch table of Prim's controlling type with
7865 -- Thunk_Id's address.
7867 Iface_DT_Elmt
:= Find_Interface_ADT
(Tag_Typ
, Iface_Typ
);
7868 Iface_DT_Ptr
:= Node
(Iface_DT_Elmt
);
7869 pragma Assert
(Has_Thunks
(Iface_DT_Ptr
));
7871 Iface_Prim
:= Interface_Alias
(Prim
);
7872 Pos
:= DT_Position
(Iface_Prim
);
7873 Tag
:= First_Tag_Component
(Iface_Typ
);
7875 Prepend_To
(L
, Thunk_Code
);
7877 if Is_Predefined_Dispatching_Operation
(Prim
)
7878 or else Is_Predefined_Dispatching_Alias
(Prim
)
7881 Build_Set_Predefined_Prim_Op_Address
(Loc
,
7883 New_Reference_To
(Node
(Next_Elmt
(Iface_DT_Elmt
)), Loc
),
7886 Unchecked_Convert_To
(RTE
(RE_Prim_Ptr
),
7887 Make_Attribute_Reference
(Loc
,
7888 Prefix
=> New_Reference_To
(Thunk_Id
, Loc
),
7889 Attribute_Name
=> Name_Unrestricted_Access
))));
7891 Next_Elmt
(Iface_DT_Elmt
);
7892 Next_Elmt
(Iface_DT_Elmt
);
7893 Iface_DT_Ptr
:= Node
(Iface_DT_Elmt
);
7894 pragma Assert
(not Has_Thunks
(Iface_DT_Ptr
));
7897 Build_Set_Predefined_Prim_Op_Address
(Loc
,
7899 New_Reference_To
(Node
(Next_Elmt
(Iface_DT_Elmt
)), Loc
),
7902 Unchecked_Convert_To
(RTE
(RE_Prim_Ptr
),
7903 Make_Attribute_Reference
(Loc
,
7905 New_Reference_To
(Alias
(Prim
), Loc
),
7906 Attribute_Name
=> Name_Unrestricted_Access
))));
7909 pragma Assert
(Pos
/= Uint_0
7910 and then Pos
<= DT_Entry_Count
(Tag
));
7913 Build_Set_Prim_Op_Address
(Loc
,
7915 Tag_Node
=> New_Reference_To
(Iface_DT_Ptr
, Loc
),
7918 Unchecked_Convert_To
(RTE
(RE_Prim_Ptr
),
7919 Make_Attribute_Reference
(Loc
,
7920 Prefix
=> New_Reference_To
(Thunk_Id
, Loc
),
7921 Attribute_Name
=> Name_Unrestricted_Access
))));
7923 Next_Elmt
(Iface_DT_Elmt
);
7924 Next_Elmt
(Iface_DT_Elmt
);
7925 Iface_DT_Ptr
:= Node
(Iface_DT_Elmt
);
7926 pragma Assert
(not Has_Thunks
(Iface_DT_Ptr
));
7929 Build_Set_Prim_Op_Address
(Loc
,
7931 Tag_Node
=> New_Reference_To
(Iface_DT_Ptr
, Loc
),
7934 Unchecked_Convert_To
(RTE
(RE_Prim_Ptr
),
7935 Make_Attribute_Reference
(Loc
,
7937 New_Reference_To
(Alias
(Prim
), Loc
),
7938 Attribute_Name
=> Name_Unrestricted_Access
))));
7945 end Register_Primitive
;
7947 -------------------------
7948 -- Set_All_DT_Position --
7949 -------------------------
7951 procedure Set_All_DT_Position
(Typ
: Entity_Id
) is
7953 function In_Predef_Prims_DT
(Prim
: Entity_Id
) return Boolean;
7954 -- Returns True if Prim is located in the dispatch table of
7955 -- predefined primitives
7957 procedure Validate_Position
(Prim
: Entity_Id
);
7958 -- Check that the position assigned to Prim is completely safe
7959 -- (it has not been assigned to a previously defined primitive
7960 -- operation of Typ)
7962 ------------------------
7963 -- In_Predef_Prims_DT --
7964 ------------------------
7966 function In_Predef_Prims_DT
(Prim
: Entity_Id
) return Boolean is
7970 -- Predefined primitives
7972 if Is_Predefined_Dispatching_Operation
(Prim
) then
7975 -- Renamings of predefined primitives
7977 elsif Present
(Alias
(Prim
))
7978 and then Is_Predefined_Dispatching_Operation
(Ultimate_Alias
(Prim
))
7980 if Chars
(Ultimate_Alias
(Prim
)) /= Name_Op_Eq
then
7983 -- User-defined renamings of predefined equality have their own
7984 -- slot in the primary dispatch table
7988 while Present
(Alias
(E
)) loop
7989 if Comes_From_Source
(E
) then
7996 return not Comes_From_Source
(E
);
7999 -- User-defined primitives
8004 end In_Predef_Prims_DT
;
8006 -----------------------
8007 -- Validate_Position --
8008 -----------------------
8010 procedure Validate_Position
(Prim
: Entity_Id
) is
8015 -- Aliased primitives are safe
8017 if Present
(Alias
(Prim
)) then
8021 Op_Elmt
:= First_Elmt
(Primitive_Operations
(Typ
));
8022 while Present
(Op_Elmt
) loop
8023 Op
:= Node
(Op_Elmt
);
8025 -- No need to check against itself
8030 -- Primitive operations covering abstract interfaces are
8033 elsif Present
(Interface_Alias
(Op
)) then
8036 -- Predefined dispatching operations are completely safe. They
8037 -- are allocated at fixed positions in a separate table.
8039 elsif Is_Predefined_Dispatching_Operation
(Op
)
8040 or else Is_Predefined_Dispatching_Alias
(Op
)
8044 -- Aliased subprograms are safe
8046 elsif Present
(Alias
(Op
)) then
8049 elsif DT_Position
(Op
) = DT_Position
(Prim
)
8050 and then not Is_Predefined_Dispatching_Operation
(Op
)
8051 and then not Is_Predefined_Dispatching_Operation
(Prim
)
8052 and then not Is_Predefined_Dispatching_Alias
(Op
)
8053 and then not Is_Predefined_Dispatching_Alias
(Prim
)
8056 -- Handle aliased subprograms
8065 if Present
(Overridden_Operation
(Op_1
)) then
8066 Op_1
:= Overridden_Operation
(Op_1
);
8067 elsif Present
(Alias
(Op_1
)) then
8068 Op_1
:= Alias
(Op_1
);
8076 if Present
(Overridden_Operation
(Op_2
)) then
8077 Op_2
:= Overridden_Operation
(Op_2
);
8078 elsif Present
(Alias
(Op_2
)) then
8079 Op_2
:= Alias
(Op_2
);
8085 if Op_1
/= Op_2
then
8086 raise Program_Error
;
8091 Next_Elmt
(Op_Elmt
);
8093 end Validate_Position
;
8097 Parent_Typ
: constant Entity_Id
:= Etype
(Typ
);
8098 First_Prim
: constant Elmt_Id
:= First_Elmt
(Primitive_Operations
(Typ
));
8099 The_Tag
: constant Entity_Id
:= First_Tag_Component
(Typ
);
8101 Adjusted
: Boolean := False;
8102 Finalized
: Boolean := False;
8108 Prim_Elmt
: Elmt_Id
;
8110 -- Start of processing for Set_All_DT_Position
8113 pragma Assert
(Present
(First_Tag_Component
(Typ
)));
8115 -- Set the DT_Position for each primitive operation. Perform some sanity
8116 -- checks to avoid building inconsistent dispatch tables.
8118 -- First stage: Set the DTC entity of all the primitive operations. This
8119 -- is required to properly read the DT_Position attribute in the latter
8122 Prim_Elmt
:= First_Prim
;
8124 while Present
(Prim_Elmt
) loop
8125 Prim
:= Node
(Prim_Elmt
);
8127 -- Predefined primitives have a separate dispatch table
8129 if not In_Predef_Prims_DT
(Prim
) then
8130 Count_Prim
:= Count_Prim
+ 1;
8133 Set_DTC_Entity_Value
(Typ
, Prim
);
8135 -- Clear any previous value of the DT_Position attribute. In this
8136 -- way we ensure that the final position of all the primitives is
8137 -- established by the following stages of this algorithm.
8139 Set_DT_Position
(Prim
, No_Uint
);
8141 Next_Elmt
(Prim_Elmt
);
8145 Fixed_Prim
: array (Int
range 0 .. Count_Prim
) of Boolean :=
8150 procedure Handle_Inherited_Private_Subprograms
(Typ
: Entity_Id
);
8151 -- Called if Typ is declared in a nested package or a public child
8152 -- package to handle inherited primitives that were inherited by Typ
8153 -- in the visible part, but whose declaration was deferred because
8154 -- the parent operation was private and not visible at that point.
8156 procedure Set_Fixed_Prim
(Pos
: Nat
);
8157 -- Sets to true an element of the Fixed_Prim table to indicate
8158 -- that this entry of the dispatch table of Typ is occupied.
8160 ------------------------------------------
8161 -- Handle_Inherited_Private_Subprograms --
8162 ------------------------------------------
8164 procedure Handle_Inherited_Private_Subprograms
(Typ
: Entity_Id
) is
8167 Op_Elmt_2
: Elmt_Id
;
8168 Prim_Op
: Entity_Id
;
8169 Parent_Subp
: Entity_Id
;
8172 Op_List
:= Primitive_Operations
(Typ
);
8174 Op_Elmt
:= First_Elmt
(Op_List
);
8175 while Present
(Op_Elmt
) loop
8176 Prim_Op
:= Node
(Op_Elmt
);
8178 -- Search primitives that are implicit operations with an
8179 -- internal name whose parent operation has a normal name.
8181 if Present
(Alias
(Prim_Op
))
8182 and then Find_Dispatching_Type
(Alias
(Prim_Op
)) /= Typ
8183 and then not Comes_From_Source
(Prim_Op
)
8184 and then Is_Internal_Name
(Chars
(Prim_Op
))
8185 and then not Is_Internal_Name
(Chars
(Alias
(Prim_Op
)))
8187 Parent_Subp
:= Alias
(Prim_Op
);
8189 -- Check if the type has an explicit overriding for this
8192 Op_Elmt_2
:= Next_Elmt
(Op_Elmt
);
8193 while Present
(Op_Elmt_2
) loop
8194 if Chars
(Node
(Op_Elmt_2
)) = Chars
(Parent_Subp
)
8195 and then Type_Conformant
(Prim_Op
, Node
(Op_Elmt_2
))
8197 Set_DT_Position
(Prim_Op
, DT_Position
(Parent_Subp
));
8198 Set_DT_Position
(Node
(Op_Elmt_2
),
8199 DT_Position
(Parent_Subp
));
8200 Set_Fixed_Prim
(UI_To_Int
(DT_Position
(Prim_Op
)));
8202 goto Next_Primitive
;
8205 Next_Elmt
(Op_Elmt_2
);
8210 Next_Elmt
(Op_Elmt
);
8212 end Handle_Inherited_Private_Subprograms
;
8214 --------------------
8215 -- Set_Fixed_Prim --
8216 --------------------
8218 procedure Set_Fixed_Prim
(Pos
: Nat
) is
8220 pragma Assert
(Pos
<= Count_Prim
);
8221 Fixed_Prim
(Pos
) := True;
8223 when Constraint_Error
=>
8224 raise Program_Error
;
8228 -- In case of nested packages and public child package it may be
8229 -- necessary a special management on inherited subprograms so that
8230 -- the dispatch table is properly filled.
8232 if Ekind
(Scope
(Scope
(Typ
))) = E_Package
8233 and then Scope
(Scope
(Typ
)) /= Standard_Standard
8234 and then ((Is_Derived_Type
(Typ
) and then not Is_Private_Type
(Typ
))
8236 (Nkind
(Parent
(Typ
)) = N_Private_Extension_Declaration
8237 and then Is_Generic_Type
(Typ
)))
8238 and then In_Open_Scopes
(Scope
(Etype
(Typ
)))
8239 and then Is_Base_Type
(Typ
)
8241 Handle_Inherited_Private_Subprograms
(Typ
);
8244 -- Second stage: Register fixed entries
8247 Prim_Elmt
:= First_Prim
;
8248 while Present
(Prim_Elmt
) loop
8249 Prim
:= Node
(Prim_Elmt
);
8251 -- Predefined primitives have a separate table and all its
8252 -- entries are at predefined fixed positions.
8254 if In_Predef_Prims_DT
(Prim
) then
8255 if Is_Predefined_Dispatching_Operation
(Prim
) then
8256 Set_DT_Position
(Prim
, Default_Prim_Op_Position
(Prim
));
8258 else pragma Assert
(Present
(Alias
(Prim
)));
8259 Set_DT_Position
(Prim
,
8260 Default_Prim_Op_Position
(Ultimate_Alias
(Prim
)));
8263 -- Overriding primitives of ancestor abstract interfaces
8265 elsif Present
(Interface_Alias
(Prim
))
8266 and then Is_Ancestor
8267 (Find_Dispatching_Type
(Interface_Alias
(Prim
)), Typ
,
8268 Use_Full_View
=> True)
8270 pragma Assert
(DT_Position
(Prim
) = No_Uint
8271 and then Present
(DTC_Entity
(Interface_Alias
(Prim
))));
8273 E
:= Interface_Alias
(Prim
);
8274 Set_DT_Position
(Prim
, DT_Position
(E
));
8277 (DT_Position
(Alias
(Prim
)) = No_Uint
8278 or else DT_Position
(Alias
(Prim
)) = DT_Position
(E
));
8279 Set_DT_Position
(Alias
(Prim
), DT_Position
(E
));
8280 Set_Fixed_Prim
(UI_To_Int
(DT_Position
(Prim
)));
8282 -- Overriding primitives must use the same entry as the
8283 -- overridden primitive.
8285 elsif not Present
(Interface_Alias
(Prim
))
8286 and then Present
(Alias
(Prim
))
8287 and then Chars
(Prim
) = Chars
(Alias
(Prim
))
8288 and then Find_Dispatching_Type
(Alias
(Prim
)) /= Typ
8289 and then Is_Ancestor
8290 (Find_Dispatching_Type
(Alias
(Prim
)), Typ
,
8291 Use_Full_View
=> True)
8292 and then Present
(DTC_Entity
(Alias
(Prim
)))
8295 Set_DT_Position
(Prim
, DT_Position
(E
));
8297 if not Is_Predefined_Dispatching_Alias
(E
) then
8298 Set_Fixed_Prim
(UI_To_Int
(DT_Position
(E
)));
8302 Next_Elmt
(Prim_Elmt
);
8305 -- Third stage: Fix the position of all the new primitives.
8306 -- Entries associated with primitives covering interfaces
8307 -- are handled in a latter round.
8309 Prim_Elmt
:= First_Prim
;
8310 while Present
(Prim_Elmt
) loop
8311 Prim
:= Node
(Prim_Elmt
);
8313 -- Skip primitives previously set entries
8315 if DT_Position
(Prim
) /= No_Uint
then
8318 -- Primitives covering interface primitives are handled later
8320 elsif Present
(Interface_Alias
(Prim
)) then
8324 -- Take the next available position in the DT
8327 Nb_Prim
:= Nb_Prim
+ 1;
8328 pragma Assert
(Nb_Prim
<= Count_Prim
);
8329 exit when not Fixed_Prim
(Nb_Prim
);
8332 Set_DT_Position
(Prim
, UI_From_Int
(Nb_Prim
));
8333 Set_Fixed_Prim
(Nb_Prim
);
8336 Next_Elmt
(Prim_Elmt
);
8340 -- Fourth stage: Complete the decoration of primitives covering
8341 -- interfaces (that is, propagate the DT_Position attribute
8342 -- from the aliased primitive)
8344 Prim_Elmt
:= First_Prim
;
8345 while Present
(Prim_Elmt
) loop
8346 Prim
:= Node
(Prim_Elmt
);
8348 if DT_Position
(Prim
) = No_Uint
8349 and then Present
(Interface_Alias
(Prim
))
8351 pragma Assert
(Present
(Alias
(Prim
))
8352 and then Find_Dispatching_Type
(Alias
(Prim
)) = Typ
);
8354 -- Check if this entry will be placed in the primary DT
8357 (Find_Dispatching_Type
(Interface_Alias
(Prim
)), Typ
,
8358 Use_Full_View
=> True)
8360 pragma Assert
(DT_Position
(Alias
(Prim
)) /= No_Uint
);
8361 Set_DT_Position
(Prim
, DT_Position
(Alias
(Prim
)));
8363 -- Otherwise it will be placed in the secondary DT
8367 (DT_Position
(Interface_Alias
(Prim
)) /= No_Uint
);
8368 Set_DT_Position
(Prim
,
8369 DT_Position
(Interface_Alias
(Prim
)));
8373 Next_Elmt
(Prim_Elmt
);
8376 -- Generate listing showing the contents of the dispatch tables.
8377 -- This action is done before some further static checks because
8378 -- in case of critical errors caused by a wrong dispatch table
8379 -- we need to see the contents of such table.
8381 if Debug_Flag_ZZ
then
8385 -- Final stage: Ensure that the table is correct plus some further
8386 -- verifications concerning the primitives.
8388 Prim_Elmt
:= First_Prim
;
8390 while Present
(Prim_Elmt
) loop
8391 Prim
:= Node
(Prim_Elmt
);
8393 -- At this point all the primitives MUST have a position
8394 -- in the dispatch table.
8396 if DT_Position
(Prim
) = No_Uint
then
8397 raise Program_Error
;
8400 -- Calculate real size of the dispatch table
8402 if not In_Predef_Prims_DT
(Prim
)
8403 and then UI_To_Int
(DT_Position
(Prim
)) > DT_Length
8405 DT_Length
:= UI_To_Int
(DT_Position
(Prim
));
8408 -- Ensure that the assigned position to non-predefined
8409 -- dispatching operations in the dispatch table is correct.
8411 if not Is_Predefined_Dispatching_Operation
(Prim
)
8412 and then not Is_Predefined_Dispatching_Alias
(Prim
)
8414 Validate_Position
(Prim
);
8417 if Chars
(Prim
) = Name_Finalize
then
8421 if Chars
(Prim
) = Name_Adjust
then
8425 -- An abstract operation cannot be declared in the private part for a
8426 -- visible abstract type, because it can't be overridden outside this
8427 -- package hierarchy. For explicit declarations this is checked at
8428 -- the point of declaration, but for inherited operations it must be
8429 -- done when building the dispatch table.
8431 -- Ada 2005 (AI-251): Primitives associated with interfaces are
8432 -- excluded from this check because interfaces must be visible in
8433 -- the public and private part (RM 7.3 (7.3/2))
8435 -- We disable this check in Relaxed_RM_Semantics mode, to
8436 -- accommodate legacy Ada code.
8438 if not Relaxed_RM_Semantics
8439 and then Is_Abstract_Type
(Typ
)
8440 and then Is_Abstract_Subprogram
(Prim
)
8441 and then Present
(Alias
(Prim
))
8442 and then not Is_Interface
8443 (Find_Dispatching_Type
(Ultimate_Alias
(Prim
)))
8444 and then not Present
(Interface_Alias
(Prim
))
8445 and then Is_Derived_Type
(Typ
)
8446 and then In_Private_Part
(Current_Scope
)
8448 List_Containing
(Parent
(Prim
)) =
8449 Private_Declarations
(Package_Specification
(Current_Scope
))
8450 and then Original_View_In_Visible_Part
(Typ
)
8452 -- We exclude Input and Output stream operations because
8453 -- Limited_Controlled inherits useless Input and Output
8454 -- stream operations from Root_Controlled, which can
8455 -- never be overridden.
8457 if not Is_TSS
(Prim
, TSS_Stream_Input
)
8459 not Is_TSS
(Prim
, TSS_Stream_Output
)
8462 ("abstract inherited private operation&" &
8463 " must be overridden (RM 3.9.3(10))",
8464 Parent
(Typ
), Prim
);
8468 Next_Elmt
(Prim_Elmt
);
8473 if Is_Controlled
(Typ
) then
8474 if not Finalized
then
8476 ("controlled type has no explicit Finalize method??", Typ
);
8478 elsif not Adjusted
then
8480 ("controlled type has no explicit Adjust method??", Typ
);
8484 -- Set the final size of the Dispatch Table
8486 Set_DT_Entry_Count
(The_Tag
, UI_From_Int
(DT_Length
));
8488 -- The derived type must have at least as many components as its parent
8489 -- (for root types Etype points to itself and the test cannot fail).
8491 if DT_Entry_Count
(The_Tag
) <
8492 DT_Entry_Count
(First_Tag_Component
(Parent_Typ
))
8494 raise Program_Error
;
8496 end Set_All_DT_Position
;
8498 --------------------------
8499 -- Set_CPP_Constructors --
8500 --------------------------
8502 procedure Set_CPP_Constructors
(Typ
: Entity_Id
) is
8504 function Gen_Parameters_Profile
(E
: Entity_Id
) return List_Id
;
8505 -- Duplicate the parameters profile of the imported C++ constructor
8506 -- adding an access to the object as an additional parameter.
8508 function Gen_Parameters_Profile
(E
: Entity_Id
) return List_Id
is
8509 Loc
: constant Source_Ptr
:= Sloc
(E
);
8516 Make_Parameter_Specification
(Loc
,
8517 Defining_Identifier
=>
8518 Make_Defining_Identifier
(Loc
, Name_uInit
),
8519 Parameter_Type
=> New_Reference_To
(Typ
, Loc
)));
8521 if Present
(Parameter_Specifications
(Parent
(E
))) then
8522 P
:= First
(Parameter_Specifications
(Parent
(E
)));
8523 while Present
(P
) loop
8525 Make_Parameter_Specification
(Loc
,
8526 Defining_Identifier
=>
8527 Make_Defining_Identifier
(Loc
,
8528 Chars
=> Chars
(Defining_Identifier
(P
))),
8529 Parameter_Type
=> New_Copy_Tree
(Parameter_Type
(P
)),
8530 Expression
=> New_Copy_Tree
(Expression
(P
))));
8536 end Gen_Parameters_Profile
;
8542 Found
: Boolean := False;
8548 Covers_Default_Constructor
: Entity_Id
:= Empty
;
8550 -- Start of processing for Set_CPP_Constructor
8553 pragma Assert
(Is_CPP_Class
(Typ
));
8555 -- Look for the constructor entities
8557 E
:= Next_Entity
(Typ
);
8558 while Present
(E
) loop
8559 if Ekind
(E
) = E_Function
8560 and then Is_Constructor
(E
)
8564 Parms
:= Gen_Parameters_Profile
(E
);
8566 Make_Defining_Identifier
(Loc
,
8567 Chars
=> Make_Init_Proc_Name
(Typ
));
8569 -- Case 1: Constructor of non-tagged type
8571 -- If the C++ class has no virtual methods then the matching Ada
8572 -- type is a non-tagged record type. In such case there is no need
8573 -- to generate a wrapper of the C++ constructor because the _tag
8574 -- component is not available.
8576 if not Is_Tagged_Type
(Typ
) then
8578 (Make_Subprogram_Declaration
(Loc
,
8580 Make_Procedure_Specification
(Loc
,
8581 Defining_Unit_Name
=> IP
,
8582 Parameter_Specifications
=> Parms
)));
8584 Set_Init_Proc
(Typ
, IP
);
8585 Set_Is_Imported
(IP
);
8586 Set_Is_Constructor
(IP
);
8587 Set_Interface_Name
(IP
, Interface_Name
(E
));
8588 Set_Convention
(IP
, Convention_CPP
);
8590 Set_Has_Completion
(IP
);
8592 -- Case 2: Constructor of a tagged type
8594 -- In this case we generate the IP as a wrapper of the the
8595 -- C++ constructor because IP must also save copy of the _tag
8596 -- generated in the C++ side. The copy of the _tag is used by
8597 -- Build_CPP_Init_Procedure to elaborate derivations of C++ types.
8600 -- procedure IP (_init : Typ; ...) is
8601 -- procedure ConstructorP (_init : Typ; ...);
8602 -- pragma Import (ConstructorP);
8604 -- ConstructorP (_init, ...);
8605 -- if Typ._tag = null then
8606 -- Typ._tag := _init._tag;
8612 Body_Stmts
: constant List_Id
:= New_List
;
8613 Constructor_Id
: Entity_Id
;
8614 Constructor_Decl_Node
: Node_Id
;
8615 Init_Tags_List
: List_Id
;
8618 Constructor_Id
:= Make_Temporary
(Loc
, 'P');
8620 Constructor_Decl_Node
:=
8621 Make_Subprogram_Declaration
(Loc
,
8622 Make_Procedure_Specification
(Loc
,
8623 Defining_Unit_Name
=> Constructor_Id
,
8624 Parameter_Specifications
=> Parms
));
8626 Set_Is_Imported
(Constructor_Id
);
8627 Set_Is_Constructor
(Constructor_Id
);
8628 Set_Interface_Name
(Constructor_Id
, Interface_Name
(E
));
8629 Set_Convention
(Constructor_Id
, Convention_CPP
);
8630 Set_Is_Public
(Constructor_Id
);
8631 Set_Has_Completion
(Constructor_Id
);
8633 -- Build the init procedure as a wrapper of this constructor
8635 Parms
:= Gen_Parameters_Profile
(E
);
8637 -- Invoke the C++ constructor
8640 Actuals
: constant List_Id
:= New_List
;
8644 while Present
(P
) loop
8646 New_Reference_To
(Defining_Identifier
(P
), Loc
));
8650 Append_To
(Body_Stmts
,
8651 Make_Procedure_Call_Statement
(Loc
,
8652 Name
=> New_Reference_To
(Constructor_Id
, Loc
),
8653 Parameter_Associations
=> Actuals
));
8656 -- Initialize copies of C++ primary and secondary tags
8658 Init_Tags_List
:= New_List
;
8665 Tag_Elmt
:= First_Elmt
(Access_Disp_Table
(Typ
));
8666 Tag_Comp
:= First_Tag_Component
(Typ
);
8668 while Present
(Tag_Elmt
)
8669 and then Is_Tag
(Node
(Tag_Elmt
))
8671 -- Skip the following assertion with primary tags
8672 -- because Related_Type is not set on primary tag
8676 (Tag_Comp
= First_Tag_Component
(Typ
)
8677 or else Related_Type
(Node
(Tag_Elmt
))
8678 = Related_Type
(Tag_Comp
));
8680 Append_To
(Init_Tags_List
,
8681 Make_Assignment_Statement
(Loc
,
8683 New_Reference_To
(Node
(Tag_Elmt
), Loc
),
8685 Make_Selected_Component
(Loc
,
8687 Make_Identifier
(Loc
, Name_uInit
),
8689 New_Reference_To
(Tag_Comp
, Loc
))));
8691 Tag_Comp
:= Next_Tag_Component
(Tag_Comp
);
8692 Next_Elmt
(Tag_Elmt
);
8696 Append_To
(Body_Stmts
,
8697 Make_If_Statement
(Loc
,
8702 (Node
(First_Elmt
(Access_Disp_Table
(Typ
))),
8705 Unchecked_Convert_To
(RTE
(RE_Tag
),
8706 New_Reference_To
(RTE
(RE_Null_Address
), Loc
))),
8707 Then_Statements
=> Init_Tags_List
));
8710 Make_Subprogram_Body
(Loc
,
8712 Make_Procedure_Specification
(Loc
,
8713 Defining_Unit_Name
=> IP
,
8714 Parameter_Specifications
=> Parms
),
8715 Declarations
=> New_List
(Constructor_Decl_Node
),
8716 Handled_Statement_Sequence
=>
8717 Make_Handled_Sequence_Of_Statements
(Loc
,
8718 Statements
=> Body_Stmts
,
8719 Exception_Handlers
=> No_List
));
8721 Discard_Node
(IP_Body
);
8722 Set_Init_Proc
(Typ
, IP
);
8726 -- If this constructor has parameters and all its parameters
8727 -- have defaults then it covers the default constructor. The
8728 -- semantic analyzer ensures that only one constructor with
8729 -- defaults covers the default constructor.
8731 if Present
(Parameter_Specifications
(Parent
(E
)))
8732 and then Needs_No_Actuals
(E
)
8734 Covers_Default_Constructor
:= IP
;
8741 -- If there are no constructors, mark the type as abstract since we
8742 -- won't be able to declare objects of that type.
8745 Set_Is_Abstract_Type
(Typ
);
8748 -- Handle constructor that has all its parameters with defaults and
8749 -- hence it covers the default constructor. We generate a wrapper IP
8750 -- which calls the covering constructor.
8752 if Present
(Covers_Default_Constructor
) then
8754 Body_Stmts
: List_Id
;
8757 Loc
:= Sloc
(Covers_Default_Constructor
);
8759 Body_Stmts
:= New_List
(
8760 Make_Procedure_Call_Statement
(Loc
,
8762 New_Reference_To
(Covers_Default_Constructor
, Loc
),
8763 Parameter_Associations
=> New_List
(
8764 Make_Identifier
(Loc
, Name_uInit
))));
8766 IP
:= Make_Defining_Identifier
(Loc
, Make_Init_Proc_Name
(Typ
));
8769 Make_Subprogram_Body
(Loc
,
8771 Make_Procedure_Specification
(Loc
,
8772 Defining_Unit_Name
=> IP
,
8773 Parameter_Specifications
=> New_List
(
8774 Make_Parameter_Specification
(Loc
,
8775 Defining_Identifier
=>
8776 Make_Defining_Identifier
(Loc
, Name_uInit
),
8777 Parameter_Type
=> New_Reference_To
(Typ
, Loc
)))),
8779 Declarations
=> No_List
,
8781 Handled_Statement_Sequence
=>
8782 Make_Handled_Sequence_Of_Statements
(Loc
,
8783 Statements
=> Body_Stmts
,
8784 Exception_Handlers
=> No_List
));
8786 Discard_Node
(IP_Body
);
8787 Set_Init_Proc
(Typ
, IP
);
8791 -- If the CPP type has constructors then it must import also the default
8792 -- C++ constructor. It is required for default initialization of objects
8793 -- of the type. It is also required to elaborate objects of Ada types
8794 -- that are defined as derivations of this CPP type.
8796 if Has_CPP_Constructors
(Typ
)
8797 and then No
(Init_Proc
(Typ
))
8799 Error_Msg_N
("??default constructor must be imported from C++", Typ
);
8801 end Set_CPP_Constructors
;
8803 --------------------------
8804 -- Set_DTC_Entity_Value --
8805 --------------------------
8807 procedure Set_DTC_Entity_Value
8808 (Tagged_Type
: Entity_Id
;
8812 if Present
(Interface_Alias
(Prim
))
8813 and then Is_Interface
8814 (Find_Dispatching_Type
(Interface_Alias
(Prim
)))
8816 Set_DTC_Entity
(Prim
,
8819 Iface
=> Find_Dispatching_Type
(Interface_Alias
(Prim
))));
8821 Set_DTC_Entity
(Prim
,
8822 First_Tag_Component
(Tagged_Type
));
8824 end Set_DTC_Entity_Value
;
8830 function Tagged_Kind
(T
: Entity_Id
) return Node_Id
is
8831 Conc_Typ
: Entity_Id
;
8832 Loc
: constant Source_Ptr
:= Sloc
(T
);
8836 (Is_Tagged_Type
(T
) and then RTE_Available
(RE_Tagged_Kind
));
8840 if Is_Abstract_Type
(T
) then
8841 if Is_Limited_Record
(T
) then
8842 return New_Reference_To
(RTE
(RE_TK_Abstract_Limited_Tagged
), Loc
);
8844 return New_Reference_To
(RTE
(RE_TK_Abstract_Tagged
), Loc
);
8849 elsif Is_Concurrent_Record_Type
(T
) then
8850 Conc_Typ
:= Corresponding_Concurrent_Type
(T
);
8852 if Present
(Full_View
(Conc_Typ
)) then
8853 Conc_Typ
:= Full_View
(Conc_Typ
);
8856 if Ekind
(Conc_Typ
) = E_Protected_Type
then
8857 return New_Reference_To
(RTE
(RE_TK_Protected
), Loc
);
8859 pragma Assert
(Ekind
(Conc_Typ
) = E_Task_Type
);
8860 return New_Reference_To
(RTE
(RE_TK_Task
), Loc
);
8863 -- Regular tagged kinds
8866 if Is_Limited_Record
(T
) then
8867 return New_Reference_To
(RTE
(RE_TK_Limited_Tagged
), Loc
);
8869 return New_Reference_To
(RTE
(RE_TK_Tagged
), Loc
);
8878 procedure Write_DT
(Typ
: Entity_Id
) is
8883 -- Protect this procedure against wrong usage. Required because it will
8884 -- be used directly from GDB
8886 if not (Typ
<= Last_Node_Id
)
8887 or else not Is_Tagged_Type
(Typ
)
8889 Write_Str
("wrong usage: Write_DT must be used with tagged types");
8894 Write_Int
(Int
(Typ
));
8896 Write_Name
(Chars
(Typ
));
8898 if Is_Interface
(Typ
) then
8899 Write_Str
(" is interface");
8904 Elmt
:= First_Elmt
(Primitive_Operations
(Typ
));
8905 while Present
(Elmt
) loop
8906 Prim
:= Node
(Elmt
);
8909 -- Indicate if this primitive will be allocated in the primary
8910 -- dispatch table or in a secondary dispatch table associated
8911 -- with an abstract interface type
8913 if Present
(DTC_Entity
(Prim
)) then
8914 if Etype
(DTC_Entity
(Prim
)) = RTE
(RE_Tag
) then
8921 -- Output the node of this primitive operation and its name
8923 Write_Int
(Int
(Prim
));
8926 if Is_Predefined_Dispatching_Operation
(Prim
) then
8927 Write_Str
("(predefined) ");
8930 -- Prefix the name of the primitive with its corresponding tagged
8931 -- type to facilitate seeing inherited primitives.
8933 if Present
(Alias
(Prim
)) then
8935 (Chars
(Find_Dispatching_Type
(Ultimate_Alias
(Prim
))));
8937 Write_Name
(Chars
(Typ
));
8941 Write_Name
(Chars
(Prim
));
8943 -- Indicate if this primitive has an aliased primitive
8945 if Present
(Alias
(Prim
)) then
8946 Write_Str
(" (alias = ");
8947 Write_Int
(Int
(Alias
(Prim
)));
8949 -- If the DTC_Entity attribute is already set we can also output
8950 -- the name of the interface covered by this primitive (if any).
8952 if Ekind_In
(Alias
(Prim
), E_Function
, E_Procedure
)
8953 and then Present
(DTC_Entity
(Alias
(Prim
)))
8954 and then Is_Interface
(Scope
(DTC_Entity
(Alias
(Prim
))))
8956 Write_Str
(" from interface ");
8957 Write_Name
(Chars
(Scope
(DTC_Entity
(Alias
(Prim
)))));
8960 if Present
(Interface_Alias
(Prim
)) then
8961 Write_Str
(", AI_Alias of ");
8963 if Is_Null_Interface_Primitive
(Interface_Alias
(Prim
)) then
8964 Write_Str
("null primitive ");
8968 (Chars
(Find_Dispatching_Type
(Interface_Alias
(Prim
))));
8970 Write_Int
(Int
(Interface_Alias
(Prim
)));
8976 -- Display the final position of this primitive in its associated
8977 -- (primary or secondary) dispatch table
8979 if Present
(DTC_Entity
(Prim
))
8980 and then DT_Position
(Prim
) /= No_Uint
8982 Write_Str
(" at #");
8983 Write_Int
(UI_To_Int
(DT_Position
(Prim
)));
8986 if Is_Abstract_Subprogram
(Prim
) then
8987 Write_Str
(" is abstract;");
8989 -- Check if this is a null primitive
8991 elsif Comes_From_Source
(Prim
)
8992 and then Ekind
(Prim
) = E_Procedure
8993 and then Null_Present
(Parent
(Prim
))
8995 Write_Str
(" is null;");
8998 if Is_Eliminated
(Ultimate_Alias
(Prim
)) then
8999 Write_Str
(" (eliminated)");
9002 if Is_Imported
(Prim
)
9003 and then Convention
(Prim
) = Convention_CPP
9005 Write_Str
(" (C++)");