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 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
781 -- Cases in which we may have generated run-time checks. Note that
782 -- we strip any qualification from Param before comparing with the
783 -- already-stripped controlling argument.
785 if Unqualify
(Param
) = Ctrl_Arg
or else Subp
= Eq_Prim_Op
then
786 Append_To
(New_Params
,
787 Duplicate_Subexpr_Move_Checks
(Param
));
789 elsif Nkind
(Parent
(Param
)) /= N_Parameter_Association
790 or else not Is_Accessibility_Actual
(Parent
(Param
))
792 Append_To
(New_Params
, Relocate_Node
(Param
));
799 -- Generate the appropriate subprogram pointer type
801 if Etype
(Subp
) = Typ
then
804 Res_Typ
:= Etype
(Subp
);
807 Subp_Typ
:= Create_Itype
(E_Subprogram_Type
, Call_Node
);
808 Subp_Ptr_Typ
:= Create_Itype
(E_Access_Subprogram_Type
, Call_Node
);
809 Set_Etype
(Subp_Typ
, Res_Typ
);
810 Set_Returns_By_Ref
(Subp_Typ
, Returns_By_Ref
(Subp
));
811 Set_Convention
(Subp_Typ
, Convention
(Subp
));
813 -- Notify gigi that the designated type is a dispatching primitive
815 Set_Is_Dispatch_Table_Entity
(Subp_Typ
);
817 -- Create a new list of parameters which is a copy of the old formal
818 -- list including the creation of a new set of matching entities.
821 Old_Formal
: Entity_Id
:= First_Formal
(Subp
);
822 New_Formal
: Entity_Id
;
823 Extra
: Entity_Id
:= Empty
;
826 if Present
(Old_Formal
) then
827 New_Formal
:= New_Copy
(Old_Formal
);
828 Set_First_Entity
(Subp_Typ
, New_Formal
);
829 Param
:= First_Actual
(Call_Node
);
832 Set_Scope
(New_Formal
, Subp_Typ
);
834 -- Change all the controlling argument types to be class-wide
835 -- to avoid a recursion in dispatching.
837 if Is_Controlling_Formal
(New_Formal
) then
838 Set_Etype
(New_Formal
, Etype
(Param
));
841 -- If the type of the formal is an itype, there was code here
842 -- introduced in 1998 in revision 1.46, to create a new itype
843 -- by copy. This seems useless, and in fact leads to semantic
844 -- errors when the itype is the completion of a type derived
845 -- from a private type.
848 Next_Formal
(Old_Formal
);
849 exit when No
(Old_Formal
);
851 Set_Next_Entity
(New_Formal
, New_Copy
(Old_Formal
));
852 Next_Entity
(New_Formal
);
856 Set_Next_Entity
(New_Formal
, Empty
);
857 Set_Last_Entity
(Subp_Typ
, Extra
);
860 -- Now that the explicit formals have been duplicated, any extra
861 -- formals needed by the subprogram must be created.
863 if Present
(Extra
) then
864 Set_Extra_Formal
(Extra
, Empty
);
867 Create_Extra_Formals
(Subp_Typ
);
870 -- Complete description of pointer type, including size information, as
871 -- must be done with itypes to prevent order-of-elaboration anomalies
874 Set_Etype
(Subp_Ptr_Typ
, Subp_Ptr_Typ
);
875 Set_Directly_Designated_Type
(Subp_Ptr_Typ
, Subp_Typ
);
876 Set_Convention
(Subp_Ptr_Typ
, Convention
(Subp_Typ
));
877 Layout_Type
(Subp_Ptr_Typ
);
879 -- If the controlling argument is a value of type Ada.Tag or an abstract
880 -- interface class-wide type then use it directly. Otherwise, the tag
881 -- must be extracted from the controlling object.
883 if Ctrl_Typ
= RTE
(RE_Tag
)
884 or else (RTE_Available
(RE_Interface_Tag
)
885 and then Ctrl_Typ
= RTE
(RE_Interface_Tag
))
887 Controlling_Tag
:= Duplicate_Subexpr
(Ctrl_Arg
);
889 -- Extract the tag from an unchecked type conversion. Done to avoid
890 -- the expansion of additional code just to obtain the value of such
891 -- tag because the current management of interface type conversions
892 -- generates in some cases this unchecked type conversion with the
893 -- tag of the object (see Expand_Interface_Conversion).
895 elsif Nkind
(Ctrl_Arg
) = N_Unchecked_Type_Conversion
897 (Etype
(Expression
(Ctrl_Arg
)) = RTE
(RE_Tag
)
899 (RTE_Available
(RE_Interface_Tag
)
901 Etype
(Expression
(Ctrl_Arg
)) = RTE
(RE_Interface_Tag
)))
903 Controlling_Tag
:= Duplicate_Subexpr
(Expression
(Ctrl_Arg
));
905 -- Ada 2005 (AI-251): Abstract interface class-wide type
907 elsif Is_Interface
(Ctrl_Typ
)
908 and then Is_Class_Wide_Type
(Ctrl_Typ
)
910 Controlling_Tag
:= Duplicate_Subexpr
(Ctrl_Arg
);
914 Make_Selected_Component
(Loc
,
915 Prefix
=> Duplicate_Subexpr_Move_Checks
(Ctrl_Arg
),
916 Selector_Name
=> New_Occurrence_Of
(DTC_Entity
(Subp
), Loc
));
919 -- Handle dispatching calls to predefined primitives
921 if Is_Predefined_Dispatching_Operation
(Subp
)
922 or else Is_Predefined_Dispatching_Alias
(Subp
)
924 Build_Get_Predefined_Prim_Op_Address
(Loc
,
925 Tag_Node
=> Controlling_Tag
,
926 Position
=> DT_Position
(Subp
),
927 New_Node
=> New_Node
);
929 -- Handle dispatching calls to user-defined primitives
932 Build_Get_Prim_Op_Address
(Loc
,
933 Typ
=> Underlying_Type
(Find_Dispatching_Type
(Subp
)),
934 Tag_Node
=> Controlling_Tag
,
935 Position
=> DT_Position
(Subp
),
936 New_Node
=> New_Node
);
940 Unchecked_Convert_To
(Subp_Ptr_Typ
, New_Node
);
942 -- Generate the SCIL node for this dispatching call. Done now because
943 -- attribute SCIL_Controlling_Tag must be set after the new call name
944 -- is built to reference the nodes that will see the SCIL backend
945 -- (because Build_Get_Prim_Op_Address generates an unchecked type
946 -- conversion which relocates the controlling tag node).
948 if Generate_SCIL
then
949 SCIL_Node
:= Make_SCIL_Dispatching_Call
(Sloc
(Call_Node
));
950 Set_SCIL_Entity
(SCIL_Node
, Typ
);
951 Set_SCIL_Target_Prim
(SCIL_Node
, Subp
);
953 -- Common case: the controlling tag is the tag of an object
954 -- (for example, obj.tag)
956 if Nkind
(Controlling_Tag
) = N_Selected_Component
then
957 Set_SCIL_Controlling_Tag
(SCIL_Node
, Controlling_Tag
);
959 -- Handle renaming of selected component
961 elsif Nkind
(Controlling_Tag
) = N_Identifier
962 and then Nkind
(Parent
(Entity
(Controlling_Tag
))) =
963 N_Object_Renaming_Declaration
964 and then Nkind
(Name
(Parent
(Entity
(Controlling_Tag
)))) =
967 Set_SCIL_Controlling_Tag
(SCIL_Node
,
968 Name
(Parent
(Entity
(Controlling_Tag
))));
970 -- If the controlling tag is an identifier, the SCIL node references
971 -- the corresponding object or parameter declaration
973 elsif Nkind
(Controlling_Tag
) = N_Identifier
974 and then Nkind_In
(Parent
(Entity
(Controlling_Tag
)),
975 N_Object_Declaration
,
976 N_Parameter_Specification
)
978 Set_SCIL_Controlling_Tag
(SCIL_Node
,
979 Parent
(Entity
(Controlling_Tag
)));
981 -- If the controlling tag is a dereference, the SCIL node references
982 -- the corresponding object or parameter declaration
984 elsif Nkind
(Controlling_Tag
) = N_Explicit_Dereference
985 and then Nkind
(Prefix
(Controlling_Tag
)) = N_Identifier
986 and then Nkind_In
(Parent
(Entity
(Prefix
(Controlling_Tag
))),
987 N_Object_Declaration
,
988 N_Parameter_Specification
)
990 Set_SCIL_Controlling_Tag
(SCIL_Node
,
991 Parent
(Entity
(Prefix
(Controlling_Tag
))));
993 -- For a direct reference of the tag of the type the SCIL node
994 -- references the internal object declaration containing the tag
997 elsif Nkind
(Controlling_Tag
) = N_Attribute_Reference
998 and then Attribute_Name
(Controlling_Tag
) = Name_Tag
1000 Set_SCIL_Controlling_Tag
(SCIL_Node
,
1004 (Access_Disp_Table
(Entity
(Prefix
(Controlling_Tag
)))))));
1006 -- Interfaces are not supported. For now we leave the SCIL node
1007 -- decorated with the Controlling_Tag. More work needed here???
1009 elsif Is_Interface
(Etype
(Controlling_Tag
)) then
1010 Set_SCIL_Controlling_Tag
(SCIL_Node
, Controlling_Tag
);
1013 pragma Assert
(False);
1018 if Nkind
(Call_Node
) = N_Function_Call
then
1020 Make_Function_Call
(Loc
,
1021 Name
=> New_Call_Name
,
1022 Parameter_Associations
=> New_Params
);
1024 -- If this is a dispatching "=", we must first compare the tags so
1025 -- we generate: x.tag = y.tag and then x = y
1027 if Subp
= Eq_Prim_Op
then
1028 Param
:= First_Actual
(Call_Node
);
1034 Make_Selected_Component
(Loc
,
1035 Prefix
=> New_Value
(Param
),
1037 New_Occurrence_Of
(First_Tag_Component
(Typ
),
1041 Make_Selected_Component
(Loc
,
1043 Unchecked_Convert_To
(Typ
,
1044 New_Value
(Next_Actual
(Param
))),
1047 (First_Tag_Component
(Typ
), Loc
))),
1048 Right_Opnd
=> New_Call
);
1050 SCIL_Related_Node
:= Right_Opnd
(New_Call
);
1055 Make_Procedure_Call_Statement
(Loc
,
1056 Name
=> New_Call_Name
,
1057 Parameter_Associations
=> New_Params
);
1060 -- Register the dispatching call in the call graph nodes table
1062 Register_CG_Node
(Call_Node
);
1064 Rewrite
(Call_Node
, New_Call
);
1066 -- Associate the SCIL node of this dispatching call
1068 if Generate_SCIL
then
1069 Set_SCIL_Node
(SCIL_Related_Node
, SCIL_Node
);
1072 -- Suppress all checks during the analysis of the expanded code
1073 -- to avoid the generation of spurious warnings under ZFP run-time.
1075 Analyze_And_Resolve
(Call_Node
, Call_Typ
, Suppress
=> All_Checks
);
1076 end Expand_Dispatching_Call
;
1078 ---------------------------------
1079 -- Expand_Interface_Conversion --
1080 ---------------------------------
1082 procedure Expand_Interface_Conversion
(N
: Node_Id
) is
1083 function Underlying_Record_Type
(Typ
: Entity_Id
) return Entity_Id
;
1084 -- Return the underlying record type of Typ.
1086 ----------------------------
1087 -- Underlying_Record_Type --
1088 ----------------------------
1090 function Underlying_Record_Type
(Typ
: Entity_Id
) return Entity_Id
is
1091 E
: Entity_Id
:= Typ
;
1094 -- Handle access to class-wide interface types
1096 if Is_Access_Type
(E
) then
1097 E
:= Etype
(Directly_Designated_Type
(E
));
1100 -- Handle class-wide types. This conversion can appear explicitly in
1101 -- the source code. Example: I'Class (Obj)
1103 if Is_Class_Wide_Type
(E
) then
1107 -- If the target type is a tagged synchronized type, the dispatch
1108 -- table info is in the corresponding record type.
1110 if Is_Concurrent_Type
(E
) then
1111 E
:= Corresponding_Record_Type
(E
);
1114 -- Handle private types
1116 E
:= Underlying_Type
(E
);
1120 return Base_Type
(E
);
1121 end Underlying_Record_Type
;
1125 Loc
: constant Source_Ptr
:= Sloc
(N
);
1126 Etyp
: constant Entity_Id
:= Etype
(N
);
1127 Operand
: constant Node_Id
:= Expression
(N
);
1128 Operand_Typ
: Entity_Id
:= Etype
(Operand
);
1130 Iface_Typ
: constant Entity_Id
:= Underlying_Record_Type
(Etype
(N
));
1131 Iface_Tag
: Entity_Id
;
1132 Is_Static
: Boolean;
1134 -- Start of processing for Expand_Interface_Conversion
1137 -- Freeze the entity associated with the target interface to have
1138 -- available the attribute Access_Disp_Table.
1140 Freeze_Before
(N
, Iface_Typ
);
1142 -- Ada 2005 (AI-345): Handle synchronized interface type derivations
1144 if Is_Concurrent_Type
(Operand_Typ
) then
1145 Operand_Typ
:= Base_Type
(Corresponding_Record_Type
(Operand_Typ
));
1148 -- Evaluate if we can statically displace the pointer to the object
1151 Opnd_Typ
: constant Node_Id
:= Underlying_Record_Type
(Operand_Typ
);
1155 not Is_Interface
(Opnd_Typ
)
1156 and then Interface_Present_In_Ancestor
1159 and then (Etype
(Opnd_Typ
) = Opnd_Typ
1161 Is_Variable_Size_Record
(Etype
(Opnd_Typ
)));
1164 if not Tagged_Type_Expansion
then
1165 if VM_Target
/= No_VM
then
1166 if Is_Access_Type
(Operand_Typ
) then
1167 Operand_Typ
:= Designated_Type
(Operand_Typ
);
1170 if Is_Class_Wide_Type
(Operand_Typ
) then
1171 Operand_Typ
:= Root_Type
(Operand_Typ
);
1174 if not Is_Static
and then Operand_Typ
/= Iface_Typ
then
1176 Make_Procedure_Call_Statement
(Loc
,
1177 Name
=> New_Occurrence_Of
1178 (RTE
(RE_Check_Interface_Conversion
), Loc
),
1179 Parameter_Associations
=> New_List
(
1180 Make_Attribute_Reference
(Loc
,
1181 Prefix
=> Duplicate_Subexpr
(Expression
(N
)),
1182 Attribute_Name
=> Name_Tag
),
1183 Make_Attribute_Reference
(Loc
,
1184 Prefix
=> New_Occurrence_Of
(Iface_Typ
, Loc
),
1185 Attribute_Name
=> Name_Tag
))));
1188 -- Just do a conversion ???
1190 Rewrite
(N
, Unchecked_Convert_To
(Etype
(N
), N
));
1197 if not Is_Static
then
1199 -- Give error if configurable run time and Displace not available
1201 if not RTE_Available
(RE_Displace
) then
1202 Error_Msg_CRT
("dynamic interface conversion", N
);
1206 -- Handle conversion of access-to-class-wide interface types. Target
1207 -- can be an access to an object or an access to another class-wide
1208 -- interface (see -1- and -2- in the following example):
1210 -- type Iface1_Ref is access all Iface1'Class;
1211 -- type Iface2_Ref is access all Iface1'Class;
1213 -- Acc1 : Iface1_Ref := new ...
1214 -- Obj : Obj_Ref := Obj_Ref (Acc); -- 1
1215 -- Acc2 : Iface2_Ref := Iface2_Ref (Acc); -- 2
1217 if Is_Access_Type
(Operand_Typ
) then
1219 Unchecked_Convert_To
(Etype
(N
),
1220 Make_Function_Call
(Loc
,
1221 Name
=> New_Occurrence_Of
(RTE
(RE_Displace
), Loc
),
1222 Parameter_Associations
=> New_List
(
1224 Unchecked_Convert_To
(RTE
(RE_Address
),
1225 Relocate_Node
(Expression
(N
))),
1228 (Node
(First_Elmt
(Access_Disp_Table
(Iface_Typ
))),
1236 Make_Function_Call
(Loc
,
1237 Name
=> New_Occurrence_Of
(RTE
(RE_Displace
), Loc
),
1238 Parameter_Associations
=> New_List
(
1239 Make_Attribute_Reference
(Loc
,
1240 Prefix
=> Relocate_Node
(Expression
(N
)),
1241 Attribute_Name
=> Name_Address
),
1244 (Node
(First_Elmt
(Access_Disp_Table
(Iface_Typ
))),
1249 -- If the target is a class-wide interface we change the type of the
1250 -- data returned by IW_Convert to indicate that this is a dispatching
1254 New_Itype
: Entity_Id
;
1257 New_Itype
:= Create_Itype
(E_Anonymous_Access_Type
, N
);
1258 Set_Etype
(New_Itype
, New_Itype
);
1259 Set_Directly_Designated_Type
(New_Itype
, Etyp
);
1262 Make_Explicit_Dereference
(Loc
,
1264 Unchecked_Convert_To
(New_Itype
, Relocate_Node
(N
))));
1266 Freeze_Itype
(New_Itype
, N
);
1272 Iface_Tag
:= Find_Interface_Tag
(Operand_Typ
, Iface_Typ
);
1273 pragma Assert
(Iface_Tag
/= Empty
);
1275 -- Keep separate access types to interfaces because one internal
1276 -- function is used to handle the null value (see following comments)
1278 if not Is_Access_Type
(Etype
(N
)) then
1280 -- Statically displace the pointer to the object to reference
1281 -- the component containing the secondary dispatch table.
1284 Convert_Tag_To_Interface
(Class_Wide_Type
(Iface_Typ
),
1285 Make_Selected_Component
(Loc
,
1286 Prefix
=> Relocate_Node
(Expression
(N
)),
1287 Selector_Name
=> New_Occurrence_Of
(Iface_Tag
, Loc
))));
1290 -- Build internal function to handle the case in which the actual is
1291 -- null. If the actual is null returns null because no displacement
1292 -- is required; otherwise performs a type conversion that will be
1293 -- expanded in the code that returns the value of the displaced
1296 -- function Func (O : Address) return Iface_Typ is
1297 -- type Op_Typ is access all Operand_Typ;
1298 -- Aux : Op_Typ := To_Op_Typ (O);
1300 -- if O = Null_Address then
1303 -- return Iface_Typ!(Aux.Iface_Tag'Address);
1308 Desig_Typ
: Entity_Id
;
1310 New_Typ_Decl
: Node_Id
;
1314 Desig_Typ
:= Etype
(Expression
(N
));
1316 if Is_Access_Type
(Desig_Typ
) then
1318 Available_View
(Directly_Designated_Type
(Desig_Typ
));
1321 if Is_Concurrent_Type
(Desig_Typ
) then
1322 Desig_Typ
:= Base_Type
(Corresponding_Record_Type
(Desig_Typ
));
1326 Make_Full_Type_Declaration
(Loc
,
1327 Defining_Identifier
=> Make_Temporary
(Loc
, 'T'),
1329 Make_Access_To_Object_Definition
(Loc
,
1330 All_Present
=> True,
1331 Null_Exclusion_Present
=> False,
1332 Constant_Present
=> False,
1333 Subtype_Indication
=>
1334 New_Occurrence_Of
(Desig_Typ
, Loc
)));
1337 Make_Simple_Return_Statement
(Loc
,
1338 Unchecked_Convert_To
(Etype
(N
),
1339 Make_Attribute_Reference
(Loc
,
1341 Make_Selected_Component
(Loc
,
1343 Unchecked_Convert_To
1344 (Defining_Identifier
(New_Typ_Decl
),
1345 Make_Identifier
(Loc
, Name_uO
)),
1347 New_Occurrence_Of
(Iface_Tag
, Loc
)),
1348 Attribute_Name
=> Name_Address
))));
1350 -- If the type is null-excluding, no need for the null branch.
1351 -- Otherwise we need to check for it and return null.
1353 if not Can_Never_Be_Null
(Etype
(N
)) then
1355 Make_If_Statement
(Loc
,
1358 Left_Opnd
=> Make_Identifier
(Loc
, Name_uO
),
1359 Right_Opnd
=> New_Occurrence_Of
1360 (RTE
(RE_Null_Address
), Loc
)),
1362 Then_Statements
=> New_List
(
1363 Make_Simple_Return_Statement
(Loc
,
1365 Else_Statements
=> Stats
));
1368 Fent
:= Make_Temporary
(Loc
, 'F');
1370 Make_Subprogram_Body
(Loc
,
1372 Make_Function_Specification
(Loc
,
1373 Defining_Unit_Name
=> Fent
,
1375 Parameter_Specifications
=> New_List
(
1376 Make_Parameter_Specification
(Loc
,
1377 Defining_Identifier
=>
1378 Make_Defining_Identifier
(Loc
, Name_uO
),
1380 New_Occurrence_Of
(RTE
(RE_Address
), Loc
))),
1382 Result_Definition
=>
1383 New_Occurrence_Of
(Etype
(N
), Loc
)),
1385 Declarations
=> New_List
(New_Typ_Decl
),
1387 Handled_Statement_Sequence
=>
1388 Make_Handled_Sequence_Of_Statements
(Loc
, Stats
));
1390 -- Place function body before the expression containing the
1391 -- conversion. We suppress all checks because the body of the
1392 -- internally generated function already takes care of the case
1393 -- in which the actual is null; therefore there is no need to
1394 -- double check that the pointer is not null when the program
1395 -- executes the alternative that performs the type conversion).
1397 Insert_Action
(N
, Func
, Suppress
=> All_Checks
);
1399 if Is_Access_Type
(Etype
(Expression
(N
))) then
1401 -- Generate: Func (Address!(Expression))
1404 Make_Function_Call
(Loc
,
1405 Name
=> New_Occurrence_Of
(Fent
, Loc
),
1406 Parameter_Associations
=> New_List
(
1407 Unchecked_Convert_To
(RTE
(RE_Address
),
1408 Relocate_Node
(Expression
(N
))))));
1411 -- Generate: Func (Operand_Typ!(Expression)'Address)
1414 Make_Function_Call
(Loc
,
1415 Name
=> New_Occurrence_Of
(Fent
, Loc
),
1416 Parameter_Associations
=> New_List
(
1417 Make_Attribute_Reference
(Loc
,
1418 Prefix
=> Unchecked_Convert_To
(Operand_Typ
,
1419 Relocate_Node
(Expression
(N
))),
1420 Attribute_Name
=> Name_Address
))));
1426 end Expand_Interface_Conversion
;
1428 ------------------------------
1429 -- Expand_Interface_Actuals --
1430 ------------------------------
1432 procedure Expand_Interface_Actuals
(Call_Node
: Node_Id
) is
1434 Actual_Dup
: Node_Id
;
1435 Actual_Typ
: Entity_Id
;
1437 Conversion
: Node_Id
;
1439 Formal_Typ
: Entity_Id
;
1441 Formal_DDT
: Entity_Id
;
1442 Actual_DDT
: Entity_Id
;
1445 -- This subprogram is called directly from the semantics, so we need a
1446 -- check to see whether expansion is active before proceeding.
1448 if not Expander_Active
then
1452 -- Call using access to subprogram with explicit dereference
1454 if Nkind
(Name
(Call_Node
)) = N_Explicit_Dereference
then
1455 Subp
:= Etype
(Name
(Call_Node
));
1457 -- Call using selected component
1459 elsif Nkind
(Name
(Call_Node
)) = N_Selected_Component
then
1460 Subp
:= Entity
(Selector_Name
(Name
(Call_Node
)));
1462 -- Call using direct name
1465 Subp
:= Entity
(Name
(Call_Node
));
1468 -- Ada 2005 (AI-251): Look for interface type formals to force "this"
1471 Formal
:= First_Formal
(Subp
);
1472 Actual
:= First_Actual
(Call_Node
);
1473 while Present
(Formal
) loop
1474 Formal_Typ
:= Etype
(Formal
);
1476 if Ekind
(Formal_Typ
) = E_Record_Type_With_Private
then
1477 Formal_Typ
:= Full_View
(Formal_Typ
);
1480 if Is_Access_Type
(Formal_Typ
) then
1481 Formal_DDT
:= Directly_Designated_Type
(Formal_Typ
);
1484 Actual_Typ
:= Etype
(Actual
);
1486 if Is_Access_Type
(Actual_Typ
) then
1487 Actual_DDT
:= Directly_Designated_Type
(Actual_Typ
);
1490 if Is_Interface
(Formal_Typ
)
1491 and then Is_Class_Wide_Type
(Formal_Typ
)
1493 -- No need to displace the pointer if the type of the actual
1494 -- coincides with the type of the formal.
1496 if Actual_Typ
= Formal_Typ
then
1499 -- No need to displace the pointer if the interface type is
1500 -- a parent of the type of the actual because in this case the
1501 -- interface primitives are located in the primary dispatch table.
1503 elsif Is_Ancestor
(Formal_Typ
, Actual_Typ
,
1504 Use_Full_View
=> True)
1508 -- Implicit conversion to the class-wide formal type to force
1509 -- the displacement of the pointer.
1512 -- Normally, expansion of actuals for calls to build-in-place
1513 -- functions happens as part of Expand_Actuals, but in this
1514 -- case the call will be wrapped in a conversion and soon after
1515 -- expanded further to handle the displacement for a class-wide
1516 -- interface conversion, so if this is a BIP call then we need
1517 -- to handle it now.
1519 if Ada_Version
>= Ada_2005
1520 and then Is_Build_In_Place_Function_Call
(Actual
)
1522 Make_Build_In_Place_Call_In_Anonymous_Context
(Actual
);
1525 Conversion
:= Convert_To
(Formal_Typ
, Relocate_Node
(Actual
));
1526 Rewrite
(Actual
, Conversion
);
1527 Analyze_And_Resolve
(Actual
, Formal_Typ
);
1530 -- Access to class-wide interface type
1532 elsif Is_Access_Type
(Formal_Typ
)
1533 and then Is_Interface
(Formal_DDT
)
1534 and then Is_Class_Wide_Type
(Formal_DDT
)
1535 and then Interface_Present_In_Ancestor
1537 Iface
=> Etype
(Formal_DDT
))
1539 -- Handle attributes 'Access and 'Unchecked_Access
1541 if Nkind
(Actual
) = N_Attribute_Reference
1543 (Attribute_Name
(Actual
) = Name_Access
1544 or else Attribute_Name
(Actual
) = Name_Unchecked_Access
)
1546 -- This case must have been handled by the analysis and
1547 -- expansion of 'Access. The only exception is when types
1548 -- match and no further expansion is required.
1550 pragma Assert
(Base_Type
(Etype
(Prefix
(Actual
)))
1551 = Base_Type
(Formal_DDT
));
1554 -- No need to displace the pointer if the type of the actual
1555 -- coincides with the type of the formal.
1557 elsif Actual_DDT
= Formal_DDT
then
1560 -- No need to displace the pointer if the interface type is
1561 -- a parent of the type of the actual because in this case the
1562 -- interface primitives are located in the primary dispatch table.
1564 elsif Is_Ancestor
(Formal_DDT
, Actual_DDT
,
1565 Use_Full_View
=> True)
1570 Actual_Dup
:= Relocate_Node
(Actual
);
1572 if From_Limited_With
(Actual_Typ
) then
1574 -- If the type of the actual parameter comes from a limited
1575 -- with-clause and the non-limited view is already available
1576 -- we replace the anonymous access type by a duplicate
1577 -- declaration whose designated type is the non-limited view
1579 if Ekind
(Actual_DDT
) = E_Incomplete_Type
1580 and then Present
(Non_Limited_View
(Actual_DDT
))
1582 Anon
:= New_Copy
(Actual_Typ
);
1584 if Is_Itype
(Anon
) then
1585 Set_Scope
(Anon
, Current_Scope
);
1588 Set_Directly_Designated_Type
(Anon
,
1589 Non_Limited_View
(Actual_DDT
));
1590 Set_Etype
(Actual_Dup
, Anon
);
1592 elsif Is_Class_Wide_Type
(Actual_DDT
)
1593 and then Ekind
(Etype
(Actual_DDT
)) = E_Incomplete_Type
1594 and then Present
(Non_Limited_View
(Etype
(Actual_DDT
)))
1596 Anon
:= New_Copy
(Actual_Typ
);
1598 if Is_Itype
(Anon
) then
1599 Set_Scope
(Anon
, Current_Scope
);
1602 Set_Directly_Designated_Type
(Anon
,
1603 New_Copy
(Actual_DDT
));
1604 Set_Class_Wide_Type
(Directly_Designated_Type
(Anon
),
1605 New_Copy
(Class_Wide_Type
(Actual_DDT
)));
1606 Set_Etype
(Directly_Designated_Type
(Anon
),
1607 Non_Limited_View
(Etype
(Actual_DDT
)));
1609 Class_Wide_Type
(Directly_Designated_Type
(Anon
)),
1610 Non_Limited_View
(Etype
(Actual_DDT
)));
1611 Set_Etype
(Actual_Dup
, Anon
);
1615 Conversion
:= Convert_To
(Formal_Typ
, Actual_Dup
);
1616 Rewrite
(Actual
, Conversion
);
1617 Analyze_And_Resolve
(Actual
, Formal_Typ
);
1621 Next_Actual
(Actual
);
1622 Next_Formal
(Formal
);
1624 end Expand_Interface_Actuals
;
1626 ----------------------------
1627 -- Expand_Interface_Thunk --
1628 ----------------------------
1630 procedure Expand_Interface_Thunk
1632 Thunk_Id
: out Entity_Id
;
1633 Thunk_Code
: out Node_Id
)
1635 Loc
: constant Source_Ptr
:= Sloc
(Prim
);
1636 Actuals
: constant List_Id
:= New_List
;
1637 Decl
: constant List_Id
:= New_List
;
1638 Formals
: constant List_Id
:= New_List
;
1639 Target
: constant Entity_Id
:= Ultimate_Alias
(Prim
);
1646 Iface_Formal
: Node_Id
;
1648 Offset_To_Top
: Node_Id
;
1649 Target_Formal
: Entity_Id
;
1653 Thunk_Code
:= Empty
;
1655 -- No thunk needed if the primitive has been eliminated
1657 if Is_Eliminated
(Ultimate_Alias
(Prim
)) then
1660 -- In case of primitives that are functions without formals and a
1661 -- controlling result there is no need to build the thunk.
1663 elsif not Present
(First_Formal
(Target
)) then
1664 pragma Assert
(Ekind
(Target
) = E_Function
1665 and then Has_Controlling_Result
(Target
));
1669 -- Duplicate the formals of the Target primitive. In the thunk, the type
1670 -- of the controlling formal is the covered interface type (instead of
1671 -- the target tagged type). Done to avoid problems with discriminated
1672 -- tagged types because, if the controlling type has discriminants with
1673 -- default values, then the type conversions done inside the body of
1674 -- the thunk (after the displacement of the pointer to the base of the
1675 -- actual object) generate code that modify its contents.
1677 -- Note: This special management is not done for predefined primitives
1680 if not Is_Predefined_Dispatching_Operation
(Prim
) then
1681 Iface_Formal
:= First_Formal
(Interface_Alias
(Prim
));
1684 Formal
:= First_Formal
(Target
);
1685 while Present
(Formal
) loop
1686 Ftyp
:= Etype
(Formal
);
1688 -- Use the interface type as the type of the controlling formal (see
1691 if not Is_Controlling_Formal
(Formal
)
1692 or else Is_Predefined_Dispatching_Operation
(Prim
)
1694 Ftyp
:= Etype
(Formal
);
1695 Expr
:= New_Copy_Tree
(Expression
(Parent
(Formal
)));
1697 Ftyp
:= Etype
(Iface_Formal
);
1702 Make_Parameter_Specification
(Loc
,
1703 Defining_Identifier
=>
1704 Make_Defining_Identifier
(Sloc
(Formal
),
1705 Chars
=> Chars
(Formal
)),
1706 In_Present
=> In_Present
(Parent
(Formal
)),
1707 Out_Present
=> Out_Present
(Parent
(Formal
)),
1708 Parameter_Type
=> New_Occurrence_Of
(Ftyp
, Loc
),
1709 Expression
=> Expr
));
1711 if not Is_Predefined_Dispatching_Operation
(Prim
) then
1712 Next_Formal
(Iface_Formal
);
1715 Next_Formal
(Formal
);
1718 Target_Formal
:= First_Formal
(Target
);
1719 Formal
:= First
(Formals
);
1720 while Present
(Formal
) loop
1722 -- If the parent is a constrained discriminated type, then the
1723 -- primitive operation will have been defined on a first subtype.
1724 -- For proper matching with controlling type, use base type.
1726 if Ekind
(Target_Formal
) = E_In_Parameter
1727 and then Ekind
(Etype
(Target_Formal
)) = E_Anonymous_Access_Type
1730 Base_Type
(Directly_Designated_Type
(Etype
(Target_Formal
)));
1732 Ftyp
:= Base_Type
(Etype
(Target_Formal
));
1735 -- For concurrent types, the relevant information is found in the
1736 -- Corresponding_Record_Type, rather than the type entity itself.
1738 if Is_Concurrent_Type
(Ftyp
) then
1739 Ftyp
:= Corresponding_Record_Type
(Ftyp
);
1742 if Ekind
(Target_Formal
) = E_In_Parameter
1743 and then Ekind
(Etype
(Target_Formal
)) = E_Anonymous_Access_Type
1744 and then Is_Controlling_Formal
(Target_Formal
)
1747 -- type T is access all <<type of the target formal>>
1748 -- S : Storage_Offset := Storage_Offset!(Formal)
1749 -- - Offset_To_Top (address!(Formal))
1752 Make_Full_Type_Declaration
(Loc
,
1753 Defining_Identifier
=> Make_Temporary
(Loc
, 'T'),
1755 Make_Access_To_Object_Definition
(Loc
,
1756 All_Present
=> True,
1757 Null_Exclusion_Present
=> False,
1758 Constant_Present
=> False,
1759 Subtype_Indication
=>
1760 New_Occurrence_Of
(Ftyp
, Loc
)));
1763 Unchecked_Convert_To
(RTE
(RE_Address
),
1764 New_Occurrence_Of
(Defining_Identifier
(Formal
), Loc
));
1766 if not RTE_Available
(RE_Offset_To_Top
) then
1768 Build_Offset_To_Top
(Loc
, New_Arg
);
1771 Make_Function_Call
(Loc
,
1772 Name
=> New_Occurrence_Of
(RTE
(RE_Offset_To_Top
), Loc
),
1773 Parameter_Associations
=> New_List
(New_Arg
));
1777 Make_Object_Declaration
(Loc
,
1778 Defining_Identifier
=> Make_Temporary
(Loc
, 'S'),
1779 Constant_Present
=> True,
1780 Object_Definition
=>
1781 New_Occurrence_Of
(RTE
(RE_Storage_Offset
), Loc
),
1783 Make_Op_Subtract
(Loc
,
1785 Unchecked_Convert_To
1786 (RTE
(RE_Storage_Offset
),
1788 (Defining_Identifier
(Formal
), Loc
)),
1792 Append_To
(Decl
, Decl_2
);
1793 Append_To
(Decl
, Decl_1
);
1795 -- Reference the new actual. Generate:
1799 Unchecked_Convert_To
1800 (Defining_Identifier
(Decl_2
),
1801 New_Occurrence_Of
(Defining_Identifier
(Decl_1
), Loc
)));
1803 elsif Is_Controlling_Formal
(Target_Formal
) then
1806 -- S1 : Storage_Offset := Storage_Offset!(Formal'Address)
1807 -- - Offset_To_Top (Formal'Address)
1808 -- S2 : Addr_Ptr := Addr_Ptr!(S1)
1811 Make_Attribute_Reference
(Loc
,
1813 New_Occurrence_Of
(Defining_Identifier
(Formal
), Loc
),
1817 if not RTE_Available
(RE_Offset_To_Top
) then
1819 Build_Offset_To_Top
(Loc
, New_Arg
);
1822 Make_Function_Call
(Loc
,
1823 Name
=> New_Occurrence_Of
(RTE
(RE_Offset_To_Top
), Loc
),
1824 Parameter_Associations
=> New_List
(New_Arg
));
1828 Make_Object_Declaration
(Loc
,
1829 Defining_Identifier
=> Make_Temporary
(Loc
, 'S'),
1830 Constant_Present
=> True,
1831 Object_Definition
=>
1832 New_Occurrence_Of
(RTE
(RE_Storage_Offset
), Loc
),
1834 Make_Op_Subtract
(Loc
,
1836 Unchecked_Convert_To
1837 (RTE
(RE_Storage_Offset
),
1838 Make_Attribute_Reference
(Loc
,
1841 (Defining_Identifier
(Formal
), Loc
),
1842 Attribute_Name
=> Name_Address
)),
1847 Make_Object_Declaration
(Loc
,
1848 Defining_Identifier
=> Make_Temporary
(Loc
, 'S'),
1849 Constant_Present
=> True,
1850 Object_Definition
=>
1851 New_Occurrence_Of
(RTE
(RE_Addr_Ptr
), Loc
),
1853 Unchecked_Convert_To
1855 New_Occurrence_Of
(Defining_Identifier
(Decl_1
), Loc
)));
1857 Append_To
(Decl
, Decl_1
);
1858 Append_To
(Decl
, Decl_2
);
1860 -- Reference the new actual, generate:
1861 -- Target_Formal (S2.all)
1864 Unchecked_Convert_To
(Ftyp
,
1865 Make_Explicit_Dereference
(Loc
,
1866 New_Occurrence_Of
(Defining_Identifier
(Decl_2
), Loc
))));
1868 -- Ensure proper matching of access types. Required to avoid
1869 -- reporting spurious errors.
1871 elsif Is_Access_Type
(Etype
(Target_Formal
)) then
1873 Unchecked_Convert_To
(Base_Type
(Etype
(Target_Formal
)),
1874 New_Occurrence_Of
(Defining_Identifier
(Formal
), Loc
)));
1876 -- No special management required for this actual
1880 New_Occurrence_Of
(Defining_Identifier
(Formal
), Loc
));
1883 Next_Formal
(Target_Formal
);
1887 Thunk_Id
:= Make_Temporary
(Loc
, 'T');
1888 Set_Ekind
(Thunk_Id
, Ekind
(Prim
));
1889 Set_Is_Thunk
(Thunk_Id
);
1890 Set_Convention
(Thunk_Id
, Convention
(Prim
));
1891 Set_Thunk_Entity
(Thunk_Id
, Target
);
1895 if Ekind
(Target
) = E_Procedure
then
1897 Make_Subprogram_Body
(Loc
,
1899 Make_Procedure_Specification
(Loc
,
1900 Defining_Unit_Name
=> Thunk_Id
,
1901 Parameter_Specifications
=> Formals
),
1902 Declarations
=> Decl
,
1903 Handled_Statement_Sequence
=>
1904 Make_Handled_Sequence_Of_Statements
(Loc
,
1905 Statements
=> New_List
(
1906 Make_Procedure_Call_Statement
(Loc
,
1907 Name
=> New_Occurrence_Of
(Target
, Loc
),
1908 Parameter_Associations
=> Actuals
))));
1912 else pragma Assert
(Ekind
(Target
) = E_Function
);
1914 Result_Def
: Node_Id
;
1915 Call_Node
: Node_Id
;
1919 Make_Function_Call
(Loc
,
1920 Name
=> New_Occurrence_Of
(Target
, Loc
),
1921 Parameter_Associations
=> Actuals
);
1923 if not Is_Interface
(Etype
(Prim
)) then
1924 Result_Def
:= New_Copy
(Result_Definition
(Parent
(Target
)));
1926 -- Thunk of function returning a class-wide interface object. No
1927 -- extra displacement needed since the displacement is generated
1928 -- in the return statement of Prim. Example:
1930 -- type Iface is interface ...
1931 -- function F (O : Iface) return Iface'Class;
1933 -- type T is new ... and Iface with ...
1934 -- function F (O : T) return Iface'Class;
1936 elsif Is_Class_Wide_Type
(Etype
(Prim
)) then
1937 Result_Def
:= New_Occurrence_Of
(Etype
(Prim
), Loc
);
1939 -- Thunk of function returning an interface object. Displacement
1942 -- type Iface is interface ...
1943 -- function F (O : Iface) return Iface;
1945 -- type T is new ... and Iface with ...
1946 -- function F (O : T) return T;
1950 New_Occurrence_Of
(Class_Wide_Type
(Etype
(Prim
)), Loc
);
1952 -- Adding implicit conversion to force the displacement of
1953 -- the pointer to the object to reference the corresponding
1954 -- secondary dispatch table.
1957 Make_Type_Conversion
(Loc
,
1959 New_Occurrence_Of
(Class_Wide_Type
(Etype
(Prim
)), Loc
),
1960 Expression
=> Relocate_Node
(Call_Node
));
1964 Make_Subprogram_Body
(Loc
,
1966 Make_Function_Specification
(Loc
,
1967 Defining_Unit_Name
=> Thunk_Id
,
1968 Parameter_Specifications
=> Formals
,
1969 Result_Definition
=> Result_Def
),
1970 Declarations
=> Decl
,
1971 Handled_Statement_Sequence
=>
1972 Make_Handled_Sequence_Of_Statements
(Loc
,
1973 Statements
=> New_List
(
1974 Make_Simple_Return_Statement
(Loc
, Call_Node
))));
1977 end Expand_Interface_Thunk
;
1979 ------------------------
1980 -- Find_Specific_Type --
1981 ------------------------
1983 function Find_Specific_Type
(CW
: Entity_Id
) return Entity_Id
is
1984 Typ
: Entity_Id
:= Root_Type
(CW
);
1987 if Ekind
(Typ
) = E_Incomplete_Type
then
1988 if From_Limited_With
(Typ
) then
1989 Typ
:= Non_Limited_View
(Typ
);
1991 Typ
:= Full_View
(Typ
);
1996 end Find_Specific_Type
;
1998 --------------------------
1999 -- Has_CPP_Constructors --
2000 --------------------------
2002 function Has_CPP_Constructors
(Typ
: Entity_Id
) return Boolean is
2006 -- Look for the constructor entities
2008 E
:= Next_Entity
(Typ
);
2009 while Present
(E
) loop
2010 if Ekind
(E
) = E_Function
2011 and then Is_Constructor
(E
)
2020 end Has_CPP_Constructors
;
2026 function Has_DT
(Typ
: Entity_Id
) return Boolean is
2028 return not Is_Interface
(Typ
)
2029 and then not Restriction_Active
(No_Dispatching_Calls
);
2032 ----------------------------------
2033 -- Is_Expanded_Dispatching_Call --
2034 ----------------------------------
2036 function Is_Expanded_Dispatching_Call
(N
: Node_Id
) return Boolean is
2038 return Nkind
(N
) in N_Subprogram_Call
2039 and then Nkind
(Name
(N
)) = N_Explicit_Dereference
2040 and then Is_Dispatch_Table_Entity
(Etype
(Name
(N
)));
2041 end Is_Expanded_Dispatching_Call
;
2043 -----------------------------------------
2044 -- Is_Predefined_Dispatching_Operation --
2045 -----------------------------------------
2047 function Is_Predefined_Dispatching_Operation
2048 (E
: Entity_Id
) return Boolean
2050 TSS_Name
: TSS_Name_Type
;
2053 if not Is_Dispatching_Operation
(E
) then
2057 Get_Name_String
(Chars
(E
));
2059 -- Most predefined primitives have internally generated names. Equality
2060 -- must be treated differently; the predefined operation is recognized
2061 -- as a homogeneous binary operator that returns Boolean.
2063 if Name_Len
> TSS_Name_Type
'Last then
2064 TSS_Name
:= TSS_Name_Type
(Name_Buffer
(Name_Len
- TSS_Name
'Length + 1
2066 if Chars
(E
) = Name_uSize
2067 or else TSS_Name
= TSS_Stream_Read
2068 or else TSS_Name
= TSS_Stream_Write
2069 or else TSS_Name
= TSS_Stream_Input
2070 or else TSS_Name
= TSS_Stream_Output
2072 (Chars
(E
) = Name_Op_Eq
2073 and then Etype
(First_Formal
(E
)) = Etype
(Last_Formal
(E
)))
2074 or else Chars
(E
) = Name_uAssign
2075 or else TSS_Name
= TSS_Deep_Adjust
2076 or else TSS_Name
= TSS_Deep_Finalize
2077 or else Is_Predefined_Interface_Primitive
(E
)
2084 end Is_Predefined_Dispatching_Operation
;
2086 ---------------------------------------
2087 -- Is_Predefined_Internal_Operation --
2088 ---------------------------------------
2090 function Is_Predefined_Internal_Operation
2091 (E
: Entity_Id
) return Boolean
2093 TSS_Name
: TSS_Name_Type
;
2096 if not Is_Dispatching_Operation
(E
) then
2100 Get_Name_String
(Chars
(E
));
2102 -- Most predefined primitives have internally generated names. Equality
2103 -- must be treated differently; the predefined operation is recognized
2104 -- as a homogeneous binary operator that returns Boolean.
2106 if Name_Len
> TSS_Name_Type
'Last then
2109 (Name_Buffer
(Name_Len
- TSS_Name
'Length + 1 .. Name_Len
));
2111 if Nam_In
(Chars
(E
), Name_uSize
, Name_uAssign
)
2113 (Chars
(E
) = Name_Op_Eq
2114 and then Etype
(First_Formal
(E
)) = Etype
(Last_Formal
(E
)))
2115 or else TSS_Name
= TSS_Deep_Adjust
2116 or else TSS_Name
= TSS_Deep_Finalize
2117 or else Is_Predefined_Interface_Primitive
(E
)
2124 end Is_Predefined_Internal_Operation
;
2126 -------------------------------------
2127 -- Is_Predefined_Dispatching_Alias --
2128 -------------------------------------
2130 function Is_Predefined_Dispatching_Alias
(Prim
: Entity_Id
) return Boolean
2133 return not Is_Predefined_Dispatching_Operation
(Prim
)
2134 and then Present
(Alias
(Prim
))
2135 and then Is_Predefined_Dispatching_Operation
(Ultimate_Alias
(Prim
));
2136 end Is_Predefined_Dispatching_Alias
;
2138 ---------------------------------------
2139 -- Is_Predefined_Interface_Primitive --
2140 ---------------------------------------
2142 function Is_Predefined_Interface_Primitive
(E
: Entity_Id
) return Boolean is
2144 -- In VM targets we don't restrict the functionality of this test to
2145 -- compiling in Ada 2005 mode since in VM targets any tagged type has
2148 return (Ada_Version
>= Ada_2005
or else not Tagged_Type_Expansion
)
2149 and then (Chars
(E
) = Name_uDisp_Asynchronous_Select
or else
2150 Chars
(E
) = Name_uDisp_Conditional_Select
or else
2151 Chars
(E
) = Name_uDisp_Get_Prim_Op_Kind
or else
2152 Chars
(E
) = Name_uDisp_Get_Task_Id
or else
2153 Chars
(E
) = Name_uDisp_Requeue
or else
2154 Chars
(E
) = Name_uDisp_Timed_Select
);
2155 end Is_Predefined_Interface_Primitive
;
2157 ----------------------------------------
2158 -- Make_Disp_Asynchronous_Select_Body --
2159 ----------------------------------------
2161 -- For interface types, generate:
2163 -- procedure _Disp_Asynchronous_Select
2164 -- (T : in out <Typ>;
2166 -- P : System.Address;
2167 -- B : out System.Storage_Elements.Dummy_Communication_Block;
2172 -- C := Ada.Tags.POK_Function;
2173 -- end _Disp_Asynchronous_Select;
2175 -- For protected types, generate:
2177 -- procedure _Disp_Asynchronous_Select
2178 -- (T : in out <Typ>;
2180 -- P : System.Address;
2181 -- B : out System.Storage_Elements.Dummy_Communication_Block;
2185 -- Ada.Tags.Get_Entry_Index (Ada.Tags.Tag (<Typ>VP, S));
2186 -- Bnn : System.Tasking.Protected_Objects.Operations.
2187 -- Communication_Block;
2189 -- System.Tasking.Protected_Objects.Operations.Protected_Entry_Call
2190 -- (T._object'Access,
2191 -- System.Tasking.Protected_Objects.Protected_Entry_Index (I),
2193 -- System.Tasking.Asynchronous_Call,
2195 -- B := System.Storage_Elements.Dummy_Communication_Block (Bnn);
2196 -- end _Disp_Asynchronous_Select;
2198 -- For task types, generate:
2200 -- procedure _Disp_Asynchronous_Select
2201 -- (T : in out <Typ>;
2203 -- P : System.Address;
2204 -- B : out System.Storage_Elements.Dummy_Communication_Block;
2208 -- Ada.Tags.Get_Entry_Index (Ada.Tags.Tag (<Typ>VP, S));
2210 -- System.Tasking.Rendezvous.Task_Entry_Call
2212 -- System.Tasking.Task_Entry_Index (I),
2214 -- System.Tasking.Asynchronous_Call,
2216 -- end _Disp_Asynchronous_Select;
2218 function Make_Disp_Asynchronous_Select_Body
2219 (Typ
: Entity_Id
) return Node_Id
2221 Com_Block
: Entity_Id
;
2222 Conc_Typ
: Entity_Id
:= Empty
;
2223 Decls
: constant List_Id
:= New_List
;
2224 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
2226 Stmts
: constant List_Id
:= New_List
;
2230 pragma Assert
(not Restriction_Active
(No_Dispatching_Calls
));
2232 -- Null body is generated for interface types
2234 if Is_Interface
(Typ
) then
2236 Make_Subprogram_Body
(Loc
,
2237 Specification
=> Make_Disp_Asynchronous_Select_Spec
(Typ
),
2238 Declarations
=> New_List
,
2239 Handled_Statement_Sequence
=>
2240 Make_Handled_Sequence_Of_Statements
(Loc
,
2241 New_List
(Make_Assignment_Statement
(Loc
,
2242 Name
=> Make_Identifier
(Loc
, Name_uF
),
2243 Expression
=> New_Occurrence_Of
(Standard_False
, Loc
)))));
2246 if Is_Concurrent_Record_Type
(Typ
) then
2247 Conc_Typ
:= Corresponding_Concurrent_Type
(Typ
);
2251 -- Ada.Tags.Get_Entry_Index (Ada.Tags.Tag! (<type>VP), S);
2253 -- where I will be used to capture the entry index of the primitive
2254 -- wrapper at position S.
2256 if Tagged_Type_Expansion
then
2258 Unchecked_Convert_To
(RTE
(RE_Tag
),
2260 (Node
(First_Elmt
(Access_Disp_Table
(Typ
))), Loc
));
2263 Make_Attribute_Reference
(Loc
,
2264 Prefix
=> New_Occurrence_Of
(Typ
, Loc
),
2265 Attribute_Name
=> Name_Tag
);
2269 Make_Object_Declaration
(Loc
,
2270 Defining_Identifier
=>
2271 Make_Defining_Identifier
(Loc
, Name_uI
),
2272 Object_Definition
=>
2273 New_Occurrence_Of
(Standard_Integer
, Loc
),
2275 Make_Function_Call
(Loc
,
2277 New_Occurrence_Of
(RTE
(RE_Get_Entry_Index
), Loc
),
2278 Parameter_Associations
=>
2281 Make_Identifier
(Loc
, Name_uS
)))));
2283 if Ekind
(Conc_Typ
) = E_Protected_Type
then
2286 -- Bnn : Communication_Block;
2288 Com_Block
:= Make_Temporary
(Loc
, 'B');
2290 Make_Object_Declaration
(Loc
,
2291 Defining_Identifier
=>
2293 Object_Definition
=>
2294 New_Occurrence_Of
(RTE
(RE_Communication_Block
), Loc
)));
2296 -- Build T._object'Access for calls below
2299 Make_Attribute_Reference
(Loc
,
2300 Attribute_Name
=> Name_Unchecked_Access
,
2302 Make_Selected_Component
(Loc
,
2303 Prefix
=> Make_Identifier
(Loc
, Name_uT
),
2304 Selector_Name
=> Make_Identifier
(Loc
, Name_uObject
)));
2306 case Corresponding_Runtime_Package
(Conc_Typ
) is
2307 when System_Tasking_Protected_Objects_Entries
=>
2310 -- Protected_Entry_Call
2311 -- (T._object'Access, -- Object
2312 -- Protected_Entry_Index! (I), -- E
2313 -- P, -- Uninterpreted_Data
2314 -- Asynchronous_Call, -- Mode
2315 -- Bnn); -- Communication_Block
2317 -- where T is the protected object, I is the entry index, P
2318 -- is the wrapped parameters and B is the name of the
2319 -- communication block.
2322 Make_Procedure_Call_Statement
(Loc
,
2324 New_Occurrence_Of
(RTE
(RE_Protected_Entry_Call
), Loc
),
2325 Parameter_Associations
=>
2329 Make_Unchecked_Type_Conversion
(Loc
, -- entry index
2332 (RTE
(RE_Protected_Entry_Index
), Loc
),
2333 Expression
=> Make_Identifier
(Loc
, Name_uI
)),
2335 Make_Identifier
(Loc
, Name_uP
), -- parameter block
2336 New_Occurrence_Of
-- Asynchronous_Call
2337 (RTE
(RE_Asynchronous_Call
), Loc
),
2338 New_Occurrence_Of
-- comm block
2339 (Com_Block
, Loc
))));
2342 raise Program_Error
;
2346 -- B := Dummy_Communication_Block (Bnn);
2349 Make_Assignment_Statement
(Loc
,
2350 Name
=> Make_Identifier
(Loc
, Name_uB
),
2352 Make_Unchecked_Type_Conversion
(Loc
,
2355 RTE
(RE_Dummy_Communication_Block
), Loc
),
2357 New_Occurrence_Of
(Com_Block
, Loc
))));
2363 Make_Assignment_Statement
(Loc
,
2364 Name
=> Make_Identifier
(Loc
, Name_uF
),
2365 Expression
=> New_Occurrence_Of
(Standard_False
, Loc
)));
2368 pragma Assert
(Ekind
(Conc_Typ
) = E_Task_Type
);
2372 -- (T._task_id, -- Acceptor
2373 -- Task_Entry_Index! (I), -- E
2374 -- P, -- Uninterpreted_Data
2375 -- Asynchronous_Call, -- Mode
2376 -- F); -- Rendezvous_Successful
2378 -- where T is the task object, I is the entry index, P is the
2379 -- wrapped parameters and F is the status flag.
2382 Make_Procedure_Call_Statement
(Loc
,
2384 New_Occurrence_Of
(RTE
(RE_Task_Entry_Call
), Loc
),
2385 Parameter_Associations
=>
2387 Make_Selected_Component
(Loc
, -- T._task_id
2388 Prefix
=> Make_Identifier
(Loc
, Name_uT
),
2389 Selector_Name
=> Make_Identifier
(Loc
, Name_uTask_Id
)),
2391 Make_Unchecked_Type_Conversion
(Loc
, -- entry index
2393 New_Occurrence_Of
(RTE
(RE_Task_Entry_Index
), Loc
),
2394 Expression
=> Make_Identifier
(Loc
, Name_uI
)),
2396 Make_Identifier
(Loc
, Name_uP
), -- parameter block
2397 New_Occurrence_Of
-- Asynchronous_Call
2398 (RTE
(RE_Asynchronous_Call
), Loc
),
2399 Make_Identifier
(Loc
, Name_uF
)))); -- status flag
2403 -- Ensure that the statements list is non-empty
2406 Make_Assignment_Statement
(Loc
,
2407 Name
=> Make_Identifier
(Loc
, Name_uF
),
2408 Expression
=> New_Occurrence_Of
(Standard_False
, Loc
)));
2412 Make_Subprogram_Body
(Loc
,
2414 Make_Disp_Asynchronous_Select_Spec
(Typ
),
2415 Declarations
=> Decls
,
2416 Handled_Statement_Sequence
=>
2417 Make_Handled_Sequence_Of_Statements
(Loc
, Stmts
));
2418 end Make_Disp_Asynchronous_Select_Body
;
2420 ----------------------------------------
2421 -- Make_Disp_Asynchronous_Select_Spec --
2422 ----------------------------------------
2424 function Make_Disp_Asynchronous_Select_Spec
2425 (Typ
: Entity_Id
) return Node_Id
2427 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
2428 Def_Id
: constant Node_Id
:=
2429 Make_Defining_Identifier
(Loc
,
2430 Name_uDisp_Asynchronous_Select
);
2431 Params
: constant List_Id
:= New_List
;
2434 pragma Assert
(not Restriction_Active
(No_Dispatching_Calls
));
2436 -- T : in out Typ; -- Object parameter
2437 -- S : Integer; -- Primitive operation slot
2438 -- P : Address; -- Wrapped parameters
2439 -- B : out Dummy_Communication_Block; -- Communication block dummy
2440 -- F : out Boolean; -- Status flag
2442 Append_List_To
(Params
, New_List
(
2444 Make_Parameter_Specification
(Loc
,
2445 Defining_Identifier
=>
2446 Make_Defining_Identifier
(Loc
, Name_uT
),
2448 New_Occurrence_Of
(Typ
, Loc
),
2450 Out_Present
=> True),
2452 Make_Parameter_Specification
(Loc
,
2453 Defining_Identifier
=>
2454 Make_Defining_Identifier
(Loc
, Name_uS
),
2456 New_Occurrence_Of
(Standard_Integer
, Loc
)),
2458 Make_Parameter_Specification
(Loc
,
2459 Defining_Identifier
=>
2460 Make_Defining_Identifier
(Loc
, Name_uP
),
2462 New_Occurrence_Of
(RTE
(RE_Address
), Loc
)),
2464 Make_Parameter_Specification
(Loc
,
2465 Defining_Identifier
=>
2466 Make_Defining_Identifier
(Loc
, Name_uB
),
2468 New_Occurrence_Of
(RTE
(RE_Dummy_Communication_Block
), Loc
),
2469 Out_Present
=> True),
2471 Make_Parameter_Specification
(Loc
,
2472 Defining_Identifier
=>
2473 Make_Defining_Identifier
(Loc
, Name_uF
),
2475 New_Occurrence_Of
(Standard_Boolean
, Loc
),
2476 Out_Present
=> True)));
2479 Make_Procedure_Specification
(Loc
,
2480 Defining_Unit_Name
=> Def_Id
,
2481 Parameter_Specifications
=> Params
);
2482 end Make_Disp_Asynchronous_Select_Spec
;
2484 ---------------------------------------
2485 -- Make_Disp_Conditional_Select_Body --
2486 ---------------------------------------
2488 -- For interface types, generate:
2490 -- procedure _Disp_Conditional_Select
2491 -- (T : in out <Typ>;
2493 -- P : System.Address;
2494 -- C : out Ada.Tags.Prim_Op_Kind;
2499 -- C := Ada.Tags.POK_Function;
2500 -- end _Disp_Conditional_Select;
2502 -- For protected types, generate:
2504 -- procedure _Disp_Conditional_Select
2505 -- (T : in out <Typ>;
2507 -- P : System.Address;
2508 -- C : out Ada.Tags.Prim_Op_Kind;
2512 -- Bnn : System.Tasking.Protected_Objects.Operations.
2513 -- Communication_Block;
2516 -- C := Ada.Tags.Get_Prim_Op_Kind (Ada.Tags.Tag (<Typ>VP, S));
2518 -- if C = Ada.Tags.POK_Procedure
2519 -- or else C = Ada.Tags.POK_Protected_Procedure
2520 -- or else C = Ada.Tags.POK_Task_Procedure
2526 -- I := Ada.Tags.Get_Entry_Index (Ada.Tags.Tag (<Typ>VP, S));
2527 -- System.Tasking.Protected_Objects.Operations.Protected_Entry_Call
2528 -- (T.object'Access,
2529 -- System.Tasking.Protected_Objects.Protected_Entry_Index (I),
2531 -- System.Tasking.Conditional_Call,
2533 -- F := not Cancelled (Bnn);
2534 -- end _Disp_Conditional_Select;
2536 -- For task types, generate:
2538 -- procedure _Disp_Conditional_Select
2539 -- (T : in out <Typ>;
2541 -- P : System.Address;
2542 -- C : out Ada.Tags.Prim_Op_Kind;
2548 -- I := Ada.Tags.Get_Entry_Index (Ada.Tags.Tag (<Typ>VP, S));
2549 -- System.Tasking.Rendezvous.Task_Entry_Call
2551 -- System.Tasking.Task_Entry_Index (I),
2553 -- System.Tasking.Conditional_Call,
2555 -- end _Disp_Conditional_Select;
2557 function Make_Disp_Conditional_Select_Body
2558 (Typ
: Entity_Id
) return Node_Id
2560 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
2561 Blk_Nam
: Entity_Id
;
2562 Conc_Typ
: Entity_Id
:= Empty
;
2563 Decls
: constant List_Id
:= New_List
;
2565 Stmts
: constant List_Id
:= New_List
;
2569 pragma Assert
(not Restriction_Active
(No_Dispatching_Calls
));
2571 -- Null body is generated for interface types
2573 if Is_Interface
(Typ
) then
2575 Make_Subprogram_Body
(Loc
,
2577 Make_Disp_Conditional_Select_Spec
(Typ
),
2580 Handled_Statement_Sequence
=>
2581 Make_Handled_Sequence_Of_Statements
(Loc
,
2582 New_List
(Make_Assignment_Statement
(Loc
,
2583 Name
=> Make_Identifier
(Loc
, Name_uF
),
2584 Expression
=> New_Occurrence_Of
(Standard_False
, Loc
)))));
2587 if Is_Concurrent_Record_Type
(Typ
) then
2588 Conc_Typ
:= Corresponding_Concurrent_Type
(Typ
);
2593 -- where I will be used to capture the entry index of the primitive
2594 -- wrapper at position S.
2597 Make_Object_Declaration
(Loc
,
2598 Defining_Identifier
=>
2599 Make_Defining_Identifier
(Loc
, Name_uI
),
2600 Object_Definition
=>
2601 New_Occurrence_Of
(Standard_Integer
, Loc
)));
2604 -- C := Ada.Tags.Get_Prim_Op_Kind (Ada.Tags.Tag! (<type>VP), S);
2606 -- if C = POK_Procedure
2607 -- or else C = POK_Protected_Procedure
2608 -- or else C = POK_Task_Procedure;
2614 Build_Common_Dispatching_Select_Statements
(Typ
, Stmts
);
2617 -- Bnn : Communication_Block;
2619 -- where Bnn is the name of the communication block used in the
2620 -- call to Protected_Entry_Call.
2622 Blk_Nam
:= Make_Temporary
(Loc
, 'B');
2624 Make_Object_Declaration
(Loc
,
2625 Defining_Identifier
=>
2627 Object_Definition
=>
2628 New_Occurrence_Of
(RTE
(RE_Communication_Block
), Loc
)));
2631 -- I := Ada.Tags.Get_Entry_Index (Ada.Tags.Tag! (<type>VP), S);
2633 -- I is the entry index and S is the dispatch table slot
2635 if Tagged_Type_Expansion
then
2637 Unchecked_Convert_To
(RTE
(RE_Tag
),
2639 (Node
(First_Elmt
(Access_Disp_Table
(Typ
))), Loc
));
2643 Make_Attribute_Reference
(Loc
,
2644 Prefix
=> New_Occurrence_Of
(Typ
, Loc
),
2645 Attribute_Name
=> Name_Tag
);
2649 Make_Assignment_Statement
(Loc
,
2650 Name
=> Make_Identifier
(Loc
, Name_uI
),
2652 Make_Function_Call
(Loc
,
2654 New_Occurrence_Of
(RTE
(RE_Get_Entry_Index
), Loc
),
2655 Parameter_Associations
=>
2658 Make_Identifier
(Loc
, Name_uS
)))));
2660 if Ekind
(Conc_Typ
) = E_Protected_Type
then
2662 Obj_Ref
:= -- T._object'Access
2663 Make_Attribute_Reference
(Loc
,
2664 Attribute_Name
=> Name_Unchecked_Access
,
2666 Make_Selected_Component
(Loc
,
2667 Prefix
=> Make_Identifier
(Loc
, Name_uT
),
2668 Selector_Name
=> Make_Identifier
(Loc
, Name_uObject
)));
2670 case Corresponding_Runtime_Package
(Conc_Typ
) is
2671 when System_Tasking_Protected_Objects_Entries
=>
2674 -- Protected_Entry_Call
2675 -- (T._object'Access, -- Object
2676 -- Protected_Entry_Index! (I), -- E
2677 -- P, -- Uninterpreted_Data
2678 -- Conditional_Call, -- Mode
2681 -- where T is the protected object, I is the entry index, P
2682 -- are the wrapped parameters and Bnn is the name of the
2683 -- communication block.
2686 Make_Procedure_Call_Statement
(Loc
,
2688 New_Occurrence_Of
(RTE
(RE_Protected_Entry_Call
), Loc
),
2689 Parameter_Associations
=>
2693 Make_Unchecked_Type_Conversion
(Loc
, -- entry index
2696 (RTE
(RE_Protected_Entry_Index
), Loc
),
2697 Expression
=> Make_Identifier
(Loc
, Name_uI
)),
2699 Make_Identifier
(Loc
, Name_uP
), -- parameter block
2701 New_Occurrence_Of
-- Conditional_Call
2702 (RTE
(RE_Conditional_Call
), Loc
),
2703 New_Occurrence_Of
-- Bnn
2706 when System_Tasking_Protected_Objects_Single_Entry
=>
2708 -- If we are compiling for a restricted run-time, the call
2709 -- uses the simpler form.
2712 Make_Procedure_Call_Statement
(Loc
,
2715 (RTE
(RE_Protected_Single_Entry_Call
), Loc
),
2716 Parameter_Associations
=>
2720 Make_Attribute_Reference
(Loc
,
2721 Prefix
=> Make_Identifier
(Loc
, Name_uP
),
2722 Attribute_Name
=> Name_Address
),
2725 (RTE
(RE_Conditional_Call
), Loc
))));
2727 raise Program_Error
;
2731 -- F := not Cancelled (Bnn);
2733 -- where F is the success flag. The status of Cancelled is negated
2734 -- in order to match the behaviour of the version for task types.
2737 Make_Assignment_Statement
(Loc
,
2738 Name
=> Make_Identifier
(Loc
, Name_uF
),
2742 Make_Function_Call
(Loc
,
2744 New_Occurrence_Of
(RTE
(RE_Cancelled
), Loc
),
2745 Parameter_Associations
=>
2747 New_Occurrence_Of
(Blk_Nam
, Loc
))))));
2749 pragma Assert
(Ekind
(Conc_Typ
) = E_Task_Type
);
2753 -- (T._task_id, -- Acceptor
2754 -- Task_Entry_Index! (I), -- E
2755 -- P, -- Uninterpreted_Data
2756 -- Conditional_Call, -- Mode
2757 -- F); -- Rendezvous_Successful
2759 -- where T is the task object, I is the entry index, P are the
2760 -- wrapped parameters and F is the status flag.
2763 Make_Procedure_Call_Statement
(Loc
,
2765 New_Occurrence_Of
(RTE
(RE_Task_Entry_Call
), Loc
),
2766 Parameter_Associations
=>
2769 Make_Selected_Component
(Loc
, -- T._task_id
2770 Prefix
=> Make_Identifier
(Loc
, Name_uT
),
2771 Selector_Name
=> Make_Identifier
(Loc
, Name_uTask_Id
)),
2773 Make_Unchecked_Type_Conversion
(Loc
, -- entry index
2775 New_Occurrence_Of
(RTE
(RE_Task_Entry_Index
), Loc
),
2776 Expression
=> Make_Identifier
(Loc
, Name_uI
)),
2778 Make_Identifier
(Loc
, Name_uP
), -- parameter block
2779 New_Occurrence_Of
-- Conditional_Call
2780 (RTE
(RE_Conditional_Call
), Loc
),
2781 Make_Identifier
(Loc
, Name_uF
)))); -- status flag
2785 -- Initialize out parameters
2788 Make_Assignment_Statement
(Loc
,
2789 Name
=> Make_Identifier
(Loc
, Name_uF
),
2790 Expression
=> New_Occurrence_Of
(Standard_False
, Loc
)));
2792 Make_Assignment_Statement
(Loc
,
2793 Name
=> Make_Identifier
(Loc
, Name_uC
),
2794 Expression
=> New_Occurrence_Of
(RTE
(RE_POK_Function
), Loc
)));
2798 Make_Subprogram_Body
(Loc
,
2800 Make_Disp_Conditional_Select_Spec
(Typ
),
2801 Declarations
=> Decls
,
2802 Handled_Statement_Sequence
=>
2803 Make_Handled_Sequence_Of_Statements
(Loc
, Stmts
));
2804 end Make_Disp_Conditional_Select_Body
;
2806 ---------------------------------------
2807 -- Make_Disp_Conditional_Select_Spec --
2808 ---------------------------------------
2810 function Make_Disp_Conditional_Select_Spec
2811 (Typ
: Entity_Id
) return Node_Id
2813 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
2814 Def_Id
: constant Node_Id
:=
2815 Make_Defining_Identifier
(Loc
,
2816 Name_uDisp_Conditional_Select
);
2817 Params
: constant List_Id
:= New_List
;
2820 pragma Assert
(not Restriction_Active
(No_Dispatching_Calls
));
2822 -- T : in out Typ; -- Object parameter
2823 -- S : Integer; -- Primitive operation slot
2824 -- P : Address; -- Wrapped parameters
2825 -- C : out Prim_Op_Kind; -- Call kind
2826 -- F : out Boolean; -- Status flag
2828 Append_List_To
(Params
, New_List
(
2830 Make_Parameter_Specification
(Loc
,
2831 Defining_Identifier
=>
2832 Make_Defining_Identifier
(Loc
, Name_uT
),
2834 New_Occurrence_Of
(Typ
, Loc
),
2836 Out_Present
=> True),
2838 Make_Parameter_Specification
(Loc
,
2839 Defining_Identifier
=>
2840 Make_Defining_Identifier
(Loc
, Name_uS
),
2842 New_Occurrence_Of
(Standard_Integer
, Loc
)),
2844 Make_Parameter_Specification
(Loc
,
2845 Defining_Identifier
=>
2846 Make_Defining_Identifier
(Loc
, Name_uP
),
2848 New_Occurrence_Of
(RTE
(RE_Address
), Loc
)),
2850 Make_Parameter_Specification
(Loc
,
2851 Defining_Identifier
=>
2852 Make_Defining_Identifier
(Loc
, Name_uC
),
2854 New_Occurrence_Of
(RTE
(RE_Prim_Op_Kind
), Loc
),
2855 Out_Present
=> True),
2857 Make_Parameter_Specification
(Loc
,
2858 Defining_Identifier
=>
2859 Make_Defining_Identifier
(Loc
, Name_uF
),
2861 New_Occurrence_Of
(Standard_Boolean
, Loc
),
2862 Out_Present
=> True)));
2865 Make_Procedure_Specification
(Loc
,
2866 Defining_Unit_Name
=> Def_Id
,
2867 Parameter_Specifications
=> Params
);
2868 end Make_Disp_Conditional_Select_Spec
;
2870 -------------------------------------
2871 -- Make_Disp_Get_Prim_Op_Kind_Body --
2872 -------------------------------------
2874 function Make_Disp_Get_Prim_Op_Kind_Body
2875 (Typ
: Entity_Id
) return Node_Id
2877 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
2881 pragma Assert
(not Restriction_Active
(No_Dispatching_Calls
));
2883 if Is_Interface
(Typ
) then
2885 Make_Subprogram_Body
(Loc
,
2887 Make_Disp_Get_Prim_Op_Kind_Spec
(Typ
),
2890 Handled_Statement_Sequence
=>
2891 Make_Handled_Sequence_Of_Statements
(Loc
,
2892 New_List
(Make_Null_Statement
(Loc
))));
2896 -- C := get_prim_op_kind (tag! (<type>VP), S);
2898 -- where C is the out parameter capturing the call kind and S is the
2899 -- dispatch table slot number.
2901 if Tagged_Type_Expansion
then
2903 Unchecked_Convert_To
(RTE
(RE_Tag
),
2905 (Node
(First_Elmt
(Access_Disp_Table
(Typ
))), Loc
));
2909 Make_Attribute_Reference
(Loc
,
2910 Prefix
=> New_Occurrence_Of
(Typ
, Loc
),
2911 Attribute_Name
=> Name_Tag
);
2915 Make_Subprogram_Body
(Loc
,
2917 Make_Disp_Get_Prim_Op_Kind_Spec
(Typ
),
2920 Handled_Statement_Sequence
=>
2921 Make_Handled_Sequence_Of_Statements
(Loc
,
2923 Make_Assignment_Statement
(Loc
,
2925 Make_Identifier
(Loc
, Name_uC
),
2927 Make_Function_Call
(Loc
,
2929 New_Occurrence_Of
(RTE
(RE_Get_Prim_Op_Kind
), Loc
),
2930 Parameter_Associations
=> New_List
(
2932 Make_Identifier
(Loc
, Name_uS
)))))));
2933 end Make_Disp_Get_Prim_Op_Kind_Body
;
2935 -------------------------------------
2936 -- Make_Disp_Get_Prim_Op_Kind_Spec --
2937 -------------------------------------
2939 function Make_Disp_Get_Prim_Op_Kind_Spec
2940 (Typ
: Entity_Id
) return Node_Id
2942 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
2943 Def_Id
: constant Node_Id
:=
2944 Make_Defining_Identifier
(Loc
,
2945 Name_uDisp_Get_Prim_Op_Kind
);
2946 Params
: constant List_Id
:= New_List
;
2949 pragma Assert
(not Restriction_Active
(No_Dispatching_Calls
));
2951 -- T : in out Typ; -- Object parameter
2952 -- S : Integer; -- Primitive operation slot
2953 -- C : out Prim_Op_Kind; -- Call kind
2955 Append_List_To
(Params
, New_List
(
2957 Make_Parameter_Specification
(Loc
,
2958 Defining_Identifier
=>
2959 Make_Defining_Identifier
(Loc
, Name_uT
),
2961 New_Occurrence_Of
(Typ
, Loc
),
2963 Out_Present
=> True),
2965 Make_Parameter_Specification
(Loc
,
2966 Defining_Identifier
=>
2967 Make_Defining_Identifier
(Loc
, Name_uS
),
2969 New_Occurrence_Of
(Standard_Integer
, Loc
)),
2971 Make_Parameter_Specification
(Loc
,
2972 Defining_Identifier
=>
2973 Make_Defining_Identifier
(Loc
, Name_uC
),
2975 New_Occurrence_Of
(RTE
(RE_Prim_Op_Kind
), Loc
),
2976 Out_Present
=> True)));
2979 Make_Procedure_Specification
(Loc
,
2980 Defining_Unit_Name
=> Def_Id
,
2981 Parameter_Specifications
=> Params
);
2982 end Make_Disp_Get_Prim_Op_Kind_Spec
;
2984 --------------------------------
2985 -- Make_Disp_Get_Task_Id_Body --
2986 --------------------------------
2988 function Make_Disp_Get_Task_Id_Body
2989 (Typ
: Entity_Id
) return Node_Id
2991 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
2995 pragma Assert
(not Restriction_Active
(No_Dispatching_Calls
));
2997 if Is_Concurrent_Record_Type
(Typ
)
2998 and then Ekind
(Corresponding_Concurrent_Type
(Typ
)) = E_Task_Type
3001 -- return To_Address (_T._task_id);
3004 Make_Simple_Return_Statement
(Loc
,
3006 Make_Unchecked_Type_Conversion
(Loc
,
3008 New_Occurrence_Of
(RTE
(RE_Address
), Loc
),
3010 Make_Selected_Component
(Loc
,
3011 Prefix
=> Make_Identifier
(Loc
, Name_uT
),
3012 Selector_Name
=> Make_Identifier
(Loc
, Name_uTask_Id
))));
3014 -- A null body is constructed for non-task types
3018 -- return Null_Address;
3021 Make_Simple_Return_Statement
(Loc
,
3023 New_Occurrence_Of
(RTE
(RE_Null_Address
), Loc
));
3027 Make_Subprogram_Body
(Loc
,
3029 Make_Disp_Get_Task_Id_Spec
(Typ
),
3032 Handled_Statement_Sequence
=>
3033 Make_Handled_Sequence_Of_Statements
(Loc
,
3035 end Make_Disp_Get_Task_Id_Body
;
3037 --------------------------------
3038 -- Make_Disp_Get_Task_Id_Spec --
3039 --------------------------------
3041 function Make_Disp_Get_Task_Id_Spec
3042 (Typ
: Entity_Id
) return Node_Id
3044 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
3047 pragma Assert
(not Restriction_Active
(No_Dispatching_Calls
));
3050 Make_Function_Specification
(Loc
,
3051 Defining_Unit_Name
=>
3052 Make_Defining_Identifier
(Loc
, Name_uDisp_Get_Task_Id
),
3053 Parameter_Specifications
=> New_List
(
3054 Make_Parameter_Specification
(Loc
,
3055 Defining_Identifier
=>
3056 Make_Defining_Identifier
(Loc
, Name_uT
),
3058 New_Occurrence_Of
(Typ
, Loc
))),
3059 Result_Definition
=>
3060 New_Occurrence_Of
(RTE
(RE_Address
), Loc
));
3061 end Make_Disp_Get_Task_Id_Spec
;
3063 ----------------------------
3064 -- Make_Disp_Requeue_Body --
3065 ----------------------------
3067 function Make_Disp_Requeue_Body
3068 (Typ
: Entity_Id
) return Node_Id
3070 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
3071 Conc_Typ
: Entity_Id
:= Empty
;
3072 Stmts
: constant List_Id
:= New_List
;
3075 pragma Assert
(not Restriction_Active
(No_Dispatching_Calls
));
3077 -- Null body is generated for interface types and non-concurrent
3080 if Is_Interface
(Typ
)
3081 or else not Is_Concurrent_Record_Type
(Typ
)
3084 Make_Subprogram_Body
(Loc
,
3086 Make_Disp_Requeue_Spec
(Typ
),
3089 Handled_Statement_Sequence
=>
3090 Make_Handled_Sequence_Of_Statements
(Loc
,
3091 New_List
(Make_Null_Statement
(Loc
))));
3094 Conc_Typ
:= Corresponding_Concurrent_Type
(Typ
);
3096 if Ekind
(Conc_Typ
) = E_Protected_Type
then
3098 -- Generate statements:
3100 -- System.Tasking.Protected_Objects.Operations.
3101 -- Requeue_Protected_Entry
3102 -- (Protection_Entries_Access (P),
3103 -- O._object'Unchecked_Access,
3104 -- Protected_Entry_Index (I),
3107 -- System.Tasking.Protected_Objects.Operations.
3108 -- Requeue_Task_To_Protected_Entry
3109 -- (O._object'Unchecked_Access,
3110 -- Protected_Entry_Index (I),
3114 if Restriction_Active
(No_Entry_Queue
) then
3115 Append_To
(Stmts
, Make_Null_Statement
(Loc
));
3118 Make_If_Statement
(Loc
,
3119 Condition
=> Make_Identifier
(Loc
, Name_uF
),
3124 -- Call to Requeue_Protected_Entry
3126 Make_Procedure_Call_Statement
(Loc
,
3129 RTE
(RE_Requeue_Protected_Entry
), Loc
),
3130 Parameter_Associations
=>
3133 Make_Unchecked_Type_Conversion
(Loc
, -- PEA (P)
3136 RTE
(RE_Protection_Entries_Access
), Loc
),
3138 Make_Identifier
(Loc
, Name_uP
)),
3140 Make_Attribute_Reference
(Loc
, -- O._object'Acc
3142 Name_Unchecked_Access
,
3144 Make_Selected_Component
(Loc
,
3146 Make_Identifier
(Loc
, Name_uO
),
3148 Make_Identifier
(Loc
, Name_uObject
))),
3150 Make_Unchecked_Type_Conversion
(Loc
, -- entry index
3153 RTE
(RE_Protected_Entry_Index
), Loc
),
3154 Expression
=> Make_Identifier
(Loc
, Name_uI
)),
3156 Make_Identifier
(Loc
, Name_uA
)))), -- abort status
3161 -- Call to Requeue_Task_To_Protected_Entry
3163 Make_Procedure_Call_Statement
(Loc
,
3166 RTE
(RE_Requeue_Task_To_Protected_Entry
), Loc
),
3167 Parameter_Associations
=>
3170 Make_Attribute_Reference
(Loc
, -- O._object'Acc
3172 Name_Unchecked_Access
,
3174 Make_Selected_Component
(Loc
,
3176 Make_Identifier
(Loc
, Name_uO
),
3178 Make_Identifier
(Loc
, Name_uObject
))),
3180 Make_Unchecked_Type_Conversion
(Loc
, -- entry index
3183 RTE
(RE_Protected_Entry_Index
), Loc
),
3185 Make_Identifier
(Loc
, Name_uI
)),
3187 Make_Identifier
(Loc
, Name_uA
)))))); -- abort status
3190 pragma Assert
(Is_Task_Type
(Conc_Typ
));
3194 -- System.Tasking.Rendezvous.Requeue_Protected_To_Task_Entry
3195 -- (Protection_Entries_Access (P),
3197 -- Task_Entry_Index (I),
3200 -- System.Tasking.Rendezvous.Requeue_Task_Entry
3202 -- Task_Entry_Index (I),
3207 Make_If_Statement
(Loc
,
3208 Condition
=> Make_Identifier
(Loc
, Name_uF
),
3210 Then_Statements
=> New_List
(
3212 -- Call to Requeue_Protected_To_Task_Entry
3214 Make_Procedure_Call_Statement
(Loc
,
3217 (RTE
(RE_Requeue_Protected_To_Task_Entry
), Loc
),
3219 Parameter_Associations
=> New_List
(
3221 Make_Unchecked_Type_Conversion
(Loc
, -- PEA (P)
3224 (RTE
(RE_Protection_Entries_Access
), Loc
),
3225 Expression
=> Make_Identifier
(Loc
, Name_uP
)),
3227 Make_Selected_Component
(Loc
, -- O._task_id
3228 Prefix
=> Make_Identifier
(Loc
, Name_uO
),
3229 Selector_Name
=> Make_Identifier
(Loc
, Name_uTask_Id
)),
3231 Make_Unchecked_Type_Conversion
(Loc
, -- entry index
3233 New_Occurrence_Of
(RTE
(RE_Task_Entry_Index
), Loc
),
3234 Expression
=> Make_Identifier
(Loc
, Name_uI
)),
3236 Make_Identifier
(Loc
, Name_uA
)))), -- abort status
3238 Else_Statements
=> New_List
(
3240 -- Call to Requeue_Task_Entry
3242 Make_Procedure_Call_Statement
(Loc
,
3243 Name
=> New_Occurrence_Of
(RTE
(RE_Requeue_Task_Entry
), Loc
),
3245 Parameter_Associations
=> New_List
(
3247 Make_Selected_Component
(Loc
, -- O._task_id
3248 Prefix
=> Make_Identifier
(Loc
, Name_uO
),
3249 Selector_Name
=> Make_Identifier
(Loc
, Name_uTask_Id
)),
3251 Make_Unchecked_Type_Conversion
(Loc
, -- entry index
3253 New_Occurrence_Of
(RTE
(RE_Task_Entry_Index
), Loc
),
3254 Expression
=> Make_Identifier
(Loc
, Name_uI
)),
3256 Make_Identifier
(Loc
, Name_uA
)))))); -- abort status
3259 -- Even though no declarations are needed in both cases, we allocate
3260 -- a list for entities added by Freeze.
3263 Make_Subprogram_Body
(Loc
,
3265 Make_Disp_Requeue_Spec
(Typ
),
3268 Handled_Statement_Sequence
=>
3269 Make_Handled_Sequence_Of_Statements
(Loc
, Stmts
));
3270 end Make_Disp_Requeue_Body
;
3272 ----------------------------
3273 -- Make_Disp_Requeue_Spec --
3274 ----------------------------
3276 function Make_Disp_Requeue_Spec
3277 (Typ
: Entity_Id
) return Node_Id
3279 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
3282 pragma Assert
(not Restriction_Active
(No_Dispatching_Calls
));
3284 -- O : in out Typ; - Object parameter
3285 -- F : Boolean; - Protected (True) / task (False) flag
3286 -- P : Address; - Protection_Entries_Access value
3287 -- I : Entry_Index - Index of entry call
3288 -- A : Boolean - Abort flag
3290 -- Note that the Protection_Entries_Access value is represented as a
3291 -- System.Address in order to avoid dragging in the tasking runtime
3292 -- when compiling sources without tasking constructs.
3295 Make_Procedure_Specification
(Loc
,
3296 Defining_Unit_Name
=>
3297 Make_Defining_Identifier
(Loc
, Name_uDisp_Requeue
),
3299 Parameter_Specifications
=>
3302 Make_Parameter_Specification
(Loc
, -- O
3303 Defining_Identifier
=>
3304 Make_Defining_Identifier
(Loc
, Name_uO
),
3306 New_Occurrence_Of
(Typ
, Loc
),
3308 Out_Present
=> True),
3310 Make_Parameter_Specification
(Loc
, -- F
3311 Defining_Identifier
=>
3312 Make_Defining_Identifier
(Loc
, Name_uF
),
3314 New_Occurrence_Of
(Standard_Boolean
, Loc
)),
3316 Make_Parameter_Specification
(Loc
, -- P
3317 Defining_Identifier
=>
3318 Make_Defining_Identifier
(Loc
, Name_uP
),
3320 New_Occurrence_Of
(RTE
(RE_Address
), Loc
)),
3322 Make_Parameter_Specification
(Loc
, -- I
3323 Defining_Identifier
=>
3324 Make_Defining_Identifier
(Loc
, Name_uI
),
3326 New_Occurrence_Of
(Standard_Integer
, Loc
)),
3328 Make_Parameter_Specification
(Loc
, -- A
3329 Defining_Identifier
=>
3330 Make_Defining_Identifier
(Loc
, Name_uA
),
3332 New_Occurrence_Of
(Standard_Boolean
, Loc
))));
3333 end Make_Disp_Requeue_Spec
;
3335 ---------------------------------
3336 -- Make_Disp_Timed_Select_Body --
3337 ---------------------------------
3339 -- For interface types, generate:
3341 -- procedure _Disp_Timed_Select
3342 -- (T : in out <Typ>;
3344 -- P : System.Address;
3347 -- C : out Ada.Tags.Prim_Op_Kind;
3352 -- C := Ada.Tags.POK_Function;
3353 -- end _Disp_Timed_Select;
3355 -- For protected types, generate:
3357 -- procedure _Disp_Timed_Select
3358 -- (T : in out <Typ>;
3360 -- P : System.Address;
3363 -- C : out Ada.Tags.Prim_Op_Kind;
3369 -- C := Ada.Tags.Get_Prim_Op_Kind (Ada.Tags.Tag (<Typ>VP), S);
3371 -- if C = Ada.Tags.POK_Procedure
3372 -- or else C = Ada.Tags.POK_Protected_Procedure
3373 -- or else C = Ada.Tags.POK_Task_Procedure
3379 -- I := Ada.Tags.Get_Entry_Index (Ada.Tags.Tag (<Typ>VP), S);
3380 -- System.Tasking.Protected_Objects.Operations.
3381 -- Timed_Protected_Entry_Call
3382 -- (T._object'Access,
3383 -- System.Tasking.Protected_Objects.Protected_Entry_Index (I),
3388 -- end _Disp_Timed_Select;
3390 -- For task types, generate:
3392 -- procedure _Disp_Timed_Select
3393 -- (T : in out <Typ>;
3395 -- P : System.Address;
3398 -- C : out Ada.Tags.Prim_Op_Kind;
3404 -- I := Ada.Tags.Get_Entry_Index (Ada.Tags.Tag (<Typ>VP), S);
3405 -- System.Tasking.Rendezvous.Timed_Task_Entry_Call
3407 -- System.Tasking.Task_Entry_Index (I),
3412 -- end _Disp_Time_Select;
3414 function Make_Disp_Timed_Select_Body
3415 (Typ
: Entity_Id
) return Node_Id
3417 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
3418 Conc_Typ
: Entity_Id
:= Empty
;
3419 Decls
: constant List_Id
:= New_List
;
3421 Stmts
: constant List_Id
:= New_List
;
3425 pragma Assert
(not Restriction_Active
(No_Dispatching_Calls
));
3427 -- Null body is generated for interface types
3429 if Is_Interface
(Typ
) then
3431 Make_Subprogram_Body
(Loc
,
3433 Make_Disp_Timed_Select_Spec
(Typ
),
3436 Handled_Statement_Sequence
=>
3437 Make_Handled_Sequence_Of_Statements
(Loc
,
3439 Make_Assignment_Statement
(Loc
,
3440 Name
=> Make_Identifier
(Loc
, Name_uF
),
3441 Expression
=> New_Occurrence_Of
(Standard_False
, Loc
)))));
3444 if Is_Concurrent_Record_Type
(Typ
) then
3445 Conc_Typ
:= Corresponding_Concurrent_Type
(Typ
);
3450 -- where I will be used to capture the entry index of the primitive
3451 -- wrapper at position S.
3454 Make_Object_Declaration
(Loc
,
3455 Defining_Identifier
=> Make_Defining_Identifier
(Loc
, Name_uI
),
3456 Object_Definition
=>
3457 New_Occurrence_Of
(Standard_Integer
, Loc
)));
3460 -- C := Get_Prim_Op_Kind (tag! (<type>VP), S);
3462 -- if C = POK_Procedure
3463 -- or else C = POK_Protected_Procedure
3464 -- or else C = POK_Task_Procedure;
3470 Build_Common_Dispatching_Select_Statements
(Typ
, Stmts
);
3473 -- I := Get_Entry_Index (tag! (<type>VP), S);
3475 -- I is the entry index and S is the dispatch table slot
3477 if Tagged_Type_Expansion
then
3479 Unchecked_Convert_To
(RTE
(RE_Tag
),
3481 (Node
(First_Elmt
(Access_Disp_Table
(Typ
))), Loc
));
3485 Make_Attribute_Reference
(Loc
,
3486 Prefix
=> New_Occurrence_Of
(Typ
, Loc
),
3487 Attribute_Name
=> Name_Tag
);
3491 Make_Assignment_Statement
(Loc
,
3492 Name
=> Make_Identifier
(Loc
, Name_uI
),
3494 Make_Function_Call
(Loc
,
3495 Name
=> New_Occurrence_Of
(RTE
(RE_Get_Entry_Index
), Loc
),
3496 Parameter_Associations
=>
3499 Make_Identifier
(Loc
, Name_uS
)))));
3503 if Ekind
(Conc_Typ
) = E_Protected_Type
then
3505 -- Build T._object'Access
3508 Make_Attribute_Reference
(Loc
,
3509 Attribute_Name
=> Name_Unchecked_Access
,
3511 Make_Selected_Component
(Loc
,
3512 Prefix
=> Make_Identifier
(Loc
, Name_uT
),
3513 Selector_Name
=> Make_Identifier
(Loc
, Name_uObject
)));
3515 -- Normal case, No_Entry_Queue restriction not active. In this
3516 -- case we generate:
3518 -- Timed_Protected_Entry_Call
3519 -- (T._object'access,
3520 -- Protected_Entry_Index! (I),
3523 -- where T is the protected object, I is the entry index, P are
3524 -- the wrapped parameters, D is the delay amount, M is the delay
3525 -- mode and F is the status flag.
3527 -- Historically, there was also an implementation for single
3528 -- entry protected types (in s-tposen). However, it was removed
3529 -- by also testing for no No_Select_Statements restriction in
3530 -- Exp_Utils.Corresponding_Runtime_Package. This simplified the
3531 -- implementation of s-tposen.adb and provided consistency between
3532 -- all versions of System.Tasking.Protected_Objects.Single_Entry
3535 case Corresponding_Runtime_Package
(Conc_Typ
) is
3536 when System_Tasking_Protected_Objects_Entries
=>
3538 Make_Procedure_Call_Statement
(Loc
,
3541 (RTE
(RE_Timed_Protected_Entry_Call
), Loc
),
3542 Parameter_Associations
=>
3546 Make_Unchecked_Type_Conversion
(Loc
, -- entry index
3549 (RTE
(RE_Protected_Entry_Index
), Loc
),
3551 Make_Identifier
(Loc
, Name_uI
)),
3553 Make_Identifier
(Loc
, Name_uP
), -- parameter block
3554 Make_Identifier
(Loc
, Name_uD
), -- delay
3555 Make_Identifier
(Loc
, Name_uM
), -- delay mode
3556 Make_Identifier
(Loc
, Name_uF
)))); -- status flag
3559 raise Program_Error
;
3565 pragma Assert
(Ekind
(Conc_Typ
) = E_Task_Type
);
3568 -- Timed_Task_Entry_Call (
3570 -- Task_Entry_Index! (I),
3576 -- where T is the task object, I is the entry index, P are the
3577 -- wrapped parameters, D is the delay amount, M is the delay
3578 -- mode and F is the status flag.
3581 Make_Procedure_Call_Statement
(Loc
,
3583 New_Occurrence_Of
(RTE
(RE_Timed_Task_Entry_Call
), Loc
),
3584 Parameter_Associations
=>
3587 Make_Selected_Component
(Loc
, -- T._task_id
3588 Prefix
=> Make_Identifier
(Loc
, Name_uT
),
3589 Selector_Name
=> Make_Identifier
(Loc
, Name_uTask_Id
)),
3591 Make_Unchecked_Type_Conversion
(Loc
, -- entry index
3593 New_Occurrence_Of
(RTE
(RE_Task_Entry_Index
), Loc
),
3594 Expression
=> Make_Identifier
(Loc
, Name_uI
)),
3596 Make_Identifier
(Loc
, Name_uP
), -- parameter block
3597 Make_Identifier
(Loc
, Name_uD
), -- delay
3598 Make_Identifier
(Loc
, Name_uM
), -- delay mode
3599 Make_Identifier
(Loc
, Name_uF
)))); -- status flag
3603 -- Initialize out parameters
3606 Make_Assignment_Statement
(Loc
,
3607 Name
=> Make_Identifier
(Loc
, Name_uF
),
3608 Expression
=> New_Occurrence_Of
(Standard_False
, Loc
)));
3610 Make_Assignment_Statement
(Loc
,
3611 Name
=> Make_Identifier
(Loc
, Name_uC
),
3612 Expression
=> New_Occurrence_Of
(RTE
(RE_POK_Function
), Loc
)));
3616 Make_Subprogram_Body
(Loc
,
3617 Specification
=> Make_Disp_Timed_Select_Spec
(Typ
),
3618 Declarations
=> Decls
,
3619 Handled_Statement_Sequence
=>
3620 Make_Handled_Sequence_Of_Statements
(Loc
, Stmts
));
3621 end Make_Disp_Timed_Select_Body
;
3623 ---------------------------------
3624 -- Make_Disp_Timed_Select_Spec --
3625 ---------------------------------
3627 function Make_Disp_Timed_Select_Spec
3628 (Typ
: Entity_Id
) return Node_Id
3630 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
3631 Def_Id
: constant Node_Id
:=
3632 Make_Defining_Identifier
(Loc
,
3633 Name_uDisp_Timed_Select
);
3634 Params
: constant List_Id
:= New_List
;
3637 pragma Assert
(not Restriction_Active
(No_Dispatching_Calls
));
3639 -- T : in out Typ; -- Object parameter
3640 -- S : Integer; -- Primitive operation slot
3641 -- P : Address; -- Wrapped parameters
3642 -- D : Duration; -- Delay
3643 -- M : Integer; -- Delay Mode
3644 -- C : out Prim_Op_Kind; -- Call kind
3645 -- F : out Boolean; -- Status flag
3647 Append_List_To
(Params
, New_List
(
3649 Make_Parameter_Specification
(Loc
,
3650 Defining_Identifier
=>
3651 Make_Defining_Identifier
(Loc
, Name_uT
),
3653 New_Occurrence_Of
(Typ
, Loc
),
3655 Out_Present
=> True),
3657 Make_Parameter_Specification
(Loc
,
3658 Defining_Identifier
=>
3659 Make_Defining_Identifier
(Loc
, Name_uS
),
3661 New_Occurrence_Of
(Standard_Integer
, Loc
)),
3663 Make_Parameter_Specification
(Loc
,
3664 Defining_Identifier
=>
3665 Make_Defining_Identifier
(Loc
, Name_uP
),
3667 New_Occurrence_Of
(RTE
(RE_Address
), Loc
)),
3669 Make_Parameter_Specification
(Loc
,
3670 Defining_Identifier
=>
3671 Make_Defining_Identifier
(Loc
, Name_uD
),
3673 New_Occurrence_Of
(Standard_Duration
, Loc
)),
3675 Make_Parameter_Specification
(Loc
,
3676 Defining_Identifier
=>
3677 Make_Defining_Identifier
(Loc
, Name_uM
),
3679 New_Occurrence_Of
(Standard_Integer
, Loc
)),
3681 Make_Parameter_Specification
(Loc
,
3682 Defining_Identifier
=>
3683 Make_Defining_Identifier
(Loc
, Name_uC
),
3685 New_Occurrence_Of
(RTE
(RE_Prim_Op_Kind
), Loc
),
3686 Out_Present
=> True)));
3689 Make_Parameter_Specification
(Loc
,
3690 Defining_Identifier
=>
3691 Make_Defining_Identifier
(Loc
, Name_uF
),
3693 New_Occurrence_Of
(Standard_Boolean
, Loc
),
3694 Out_Present
=> True));
3697 Make_Procedure_Specification
(Loc
,
3698 Defining_Unit_Name
=> Def_Id
,
3699 Parameter_Specifications
=> Params
);
3700 end Make_Disp_Timed_Select_Spec
;
3706 -- The frontend supports two models for expanding dispatch tables
3707 -- associated with library-level defined tagged types: statically
3708 -- and non-statically allocated dispatch tables. In the former case
3709 -- the object containing the dispatch table is constant and it is
3710 -- initialized by means of a positional aggregate. In the latter case,
3711 -- the object containing the dispatch table is a variable which is
3712 -- initialized by means of assignments.
3714 -- In case of locally defined tagged types, the object containing the
3715 -- object containing the dispatch table is always a variable (instead
3716 -- of a constant). This is currently required to give support to late
3717 -- overriding of primitives. For example:
3719 -- procedure Example is
3721 -- type T1 is tagged null record;
3722 -- procedure Prim (O : T1);
3725 -- type T2 is new Pkg.T1 with null record;
3726 -- procedure Prim (X : T2) is -- late overriding
3732 function Make_DT
(Typ
: Entity_Id
; N
: Node_Id
:= Empty
) return List_Id
is
3733 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
3735 Max_Predef_Prims
: constant Int
:=
3739 (Parent
(RTE
(RE_Max_Predef_Prims
)))));
3741 DT_Decl
: constant Elist_Id
:= New_Elmt_List
;
3742 DT_Aggr
: constant Elist_Id
:= New_Elmt_List
;
3743 -- Entities marked with attribute Is_Dispatch_Table_Entity
3745 procedure Check_Premature_Freezing
3747 Tagged_Type
: Entity_Id
;
3749 -- Verify that all non-tagged types in the profile of a subprogram
3750 -- are frozen at the point the subprogram is frozen. This enforces
3751 -- the rule on RM 13.14 (14) as modified by AI05-019. At the point a
3752 -- subprogram is frozen, enough must be known about it to build the
3753 -- activation record for it, which requires at least that the size of
3754 -- all parameters be known. Controlling arguments are by-reference,
3755 -- and therefore the rule only applies to non-tagged types.
3756 -- Typical violation of the rule involves an object declaration that
3757 -- freezes a tagged type, when one of its primitive operations has a
3758 -- type in its profile whose full view has not been analyzed yet.
3759 -- More complex cases involve composite types that have one private
3760 -- unfrozen subcomponent.
3762 procedure Export_DT
(Typ
: Entity_Id
; DT
: Entity_Id
; Index
: Nat
:= 0);
3763 -- Export the dispatch table DT of tagged type Typ. Required to generate
3764 -- forward references and statically allocate the table. For primary
3765 -- dispatch tables Index is 0; for secondary dispatch tables the value
3766 -- of index must match the Suffix_Index value assigned to the table by
3767 -- Make_Tags when generating its unique external name, and it is used to
3768 -- retrieve from the Dispatch_Table_Wrappers list associated with Typ
3769 -- the external name generated by Import_DT.
3771 procedure Make_Secondary_DT
3775 Num_Iface_Prims
: Nat
;
3776 Iface_DT_Ptr
: Entity_Id
;
3777 Predef_Prims_Ptr
: Entity_Id
;
3778 Build_Thunks
: Boolean;
3780 -- Ada 2005 (AI-251): Expand the declarations for a Secondary Dispatch
3781 -- Table of Typ associated with Iface. Each abstract interface of Typ
3782 -- has two secondary dispatch tables: one containing pointers to thunks
3783 -- and another containing pointers to the primitives covering the
3784 -- interface primitives. The former secondary table is generated when
3785 -- Build_Thunks is True, and provides common support for dispatching
3786 -- calls through interface types; the latter secondary table is
3787 -- generated when Build_Thunks is False, and provides support for
3788 -- Generic Dispatching Constructors that dispatch calls through
3789 -- interface types. When constructing this latter table the value of
3790 -- Suffix_Index is -1 to indicate that there is no need to export such
3791 -- table when building statically allocated dispatch tables; a positive
3792 -- value of Suffix_Index must match the Suffix_Index value assigned to
3793 -- this secondary dispatch table by Make_Tags when its unique external
3794 -- name was generated.
3796 ------------------------------
3797 -- Check_Premature_Freezing --
3798 ------------------------------
3800 procedure Check_Premature_Freezing
3802 Tagged_Type
: Entity_Id
;
3807 function Is_Actual_For_Formal_Incomplete_Type
3808 (T
: Entity_Id
) return Boolean;
3809 -- In Ada 2012, if a nested generic has an incomplete formal type,
3810 -- the actual may be (and usually is) a private type whose completion
3811 -- appears later. It is safe to build the dispatch table in this
3812 -- case, gigi will have full views available.
3814 ------------------------------------------
3815 -- Is_Actual_For_Formal_Incomplete_Type --
3816 ------------------------------------------
3818 function Is_Actual_For_Formal_Incomplete_Type
3819 (T
: Entity_Id
) return Boolean
3821 Gen_Par
: Entity_Id
;
3825 if not Is_Generic_Instance
(Current_Scope
)
3826 or else not Used_As_Generic_Actual
(T
)
3831 Gen_Par
:= Generic_Parent
(Parent
(Current_Scope
));
3836 (Generic_Formal_Declarations
3837 (Unit_Declaration_Node
(Gen_Par
)));
3838 while Present
(F
) loop
3839 if Ekind
(Defining_Identifier
(F
)) = E_Incomplete_Type
then
3847 end Is_Actual_For_Formal_Incomplete_Type
;
3849 -- Start of processing for Check_Premature_Freezing
3852 -- Note that if the type is a (subtype of) a generic actual, the
3853 -- actual will have been frozen by the instantiation.
3856 and then Is_Private_Type
(Typ
)
3857 and then No
(Full_View
(Typ
))
3858 and then not Is_Generic_Type
(Typ
)
3859 and then not Is_Tagged_Type
(Typ
)
3860 and then not Is_Frozen
(Typ
)
3861 and then not Is_Generic_Actual_Type
(Typ
)
3863 Error_Msg_Sloc
:= Sloc
(Subp
);
3865 ("declaration must appear after completion of type &", N
, Typ
);
3867 ("\which is an untagged type in the profile of"
3868 & " primitive operation & declared#", N
, Subp
);
3871 Comp
:= Private_Component
(Typ
);
3873 if not Is_Tagged_Type
(Typ
)
3874 and then Present
(Comp
)
3875 and then not Is_Frozen
(Comp
)
3877 not Is_Actual_For_Formal_Incomplete_Type
(Comp
)
3879 Error_Msg_Sloc
:= Sloc
(Subp
);
3880 Error_Msg_Node_2
:= Subp
;
3881 Error_Msg_Name_1
:= Chars
(Tagged_Type
);
3883 ("declaration must appear after completion of type &",
3886 ("\which is a component of untagged type& in the profile of"
3887 & " primitive & of type % that is frozen by the declaration ",
3891 end Check_Premature_Freezing
;
3897 procedure Export_DT
(Typ
: Entity_Id
; DT
: Entity_Id
; Index
: Nat
:= 0)
3903 Set_Is_Statically_Allocated
(DT
);
3904 Set_Is_True_Constant
(DT
);
3905 Set_Is_Exported
(DT
);
3908 Elmt
:= First_Elmt
(Dispatch_Table_Wrappers
(Typ
));
3909 while Count
/= Index
loop
3914 pragma Assert
(Related_Type
(Node
(Elmt
)) = Typ
);
3916 Get_External_Name
(Node
(Elmt
));
3917 Set_Interface_Name
(DT
,
3918 Make_String_Literal
(Loc
,
3919 Strval
=> String_From_Name_Buffer
));
3921 -- Ensure proper Sprint output of this implicit importation
3923 Set_Is_Internal
(DT
);
3927 -----------------------
3928 -- Make_Secondary_DT --
3929 -----------------------
3931 procedure Make_Secondary_DT
3935 Num_Iface_Prims
: Nat
;
3936 Iface_DT_Ptr
: Entity_Id
;
3937 Predef_Prims_Ptr
: Entity_Id
;
3938 Build_Thunks
: Boolean;
3941 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
3942 Exporting_Table
: constant Boolean :=
3943 Building_Static_DT
(Typ
)
3944 and then Suffix_Index
> 0;
3945 Iface_DT
: constant Entity_Id
:= Make_Temporary
(Loc
, 'T');
3946 Predef_Prims
: constant Entity_Id
:= Make_Temporary
(Loc
, 'R');
3947 DT_Constr_List
: List_Id
;
3948 DT_Aggr_List
: List_Id
;
3949 Empty_DT
: Boolean := False;
3950 Nb_Predef_Prims
: Nat
:= 0;
3954 OSD_Aggr_List
: List_Id
;
3957 Prim_Elmt
: Elmt_Id
;
3958 Prim_Ops_Aggr_List
: List_Id
;
3961 -- Handle cases in which we do not generate statically allocated
3964 if not Building_Static_DT
(Typ
) then
3965 Set_Ekind
(Predef_Prims
, E_Variable
);
3966 Set_Ekind
(Iface_DT
, E_Variable
);
3968 -- Statically allocated dispatch tables and related entities are
3972 Set_Ekind
(Predef_Prims
, E_Constant
);
3973 Set_Is_Statically_Allocated
(Predef_Prims
);
3974 Set_Is_True_Constant
(Predef_Prims
);
3976 Set_Ekind
(Iface_DT
, E_Constant
);
3977 Set_Is_Statically_Allocated
(Iface_DT
);
3978 Set_Is_True_Constant
(Iface_DT
);
3981 -- Calculate the number of slots of the dispatch table. If the number
3982 -- of primitives of Typ is 0 we reserve a dummy single entry for its
3983 -- DT because at run time the pointer to this dummy entry will be
3986 if Num_Iface_Prims
= 0 then
3990 Nb_Prim
:= Num_Iface_Prims
;
3995 -- Predef_Prims : Address_Array (1 .. Default_Prim_Ops_Count) :=
3996 -- (predef-prim-op-thunk-1'address,
3997 -- predef-prim-op-thunk-2'address,
3999 -- predef-prim-op-thunk-n'address);
4000 -- for Predef_Prims'Alignment use Address'Alignment
4002 -- Stage 1: Calculate the number of predefined primitives
4004 if not Building_Static_DT
(Typ
) then
4005 Nb_Predef_Prims
:= Max_Predef_Prims
;
4007 Prim_Elmt
:= First_Elmt
(Primitive_Operations
(Typ
));
4008 while Present
(Prim_Elmt
) loop
4009 Prim
:= Node
(Prim_Elmt
);
4011 if Is_Predefined_Dispatching_Operation
(Prim
)
4012 and then not Is_Abstract_Subprogram
(Prim
)
4014 Pos
:= UI_To_Int
(DT_Position
(Prim
));
4016 if Pos
> Nb_Predef_Prims
then
4017 Nb_Predef_Prims
:= Pos
;
4021 Next_Elmt
(Prim_Elmt
);
4025 -- Stage 2: Create the thunks associated with the predefined
4026 -- primitives and save their entity to fill the aggregate.
4029 Prim_Table
: array (Nat
range 1 .. Nb_Predef_Prims
) of Entity_Id
;
4031 Thunk_Id
: Entity_Id
;
4032 Thunk_Code
: Node_Id
;
4035 Prim_Ops_Aggr_List
:= New_List
;
4036 Prim_Table
:= (others => Empty
);
4038 if Building_Static_DT
(Typ
) then
4039 Prim_Elmt
:= First_Elmt
(Primitive_Operations
(Typ
));
4040 while Present
(Prim_Elmt
) loop
4041 Prim
:= Node
(Prim_Elmt
);
4043 if Is_Predefined_Dispatching_Operation
(Prim
)
4044 and then not Is_Abstract_Subprogram
(Prim
)
4045 and then not Is_Eliminated
(Prim
)
4046 and then not Present
(Prim_Table
4047 (UI_To_Int
(DT_Position
(Prim
))))
4049 if not Build_Thunks
then
4050 Prim_Table
(UI_To_Int
(DT_Position
(Prim
))) :=
4054 Expand_Interface_Thunk
4055 (Ultimate_Alias
(Prim
), Thunk_Id
, Thunk_Code
);
4057 if Present
(Thunk_Id
) then
4058 Append_To
(Result
, Thunk_Code
);
4059 Prim_Table
(UI_To_Int
(DT_Position
(Prim
)))
4065 Next_Elmt
(Prim_Elmt
);
4069 for J
in Prim_Table
'Range loop
4070 if Present
(Prim_Table
(J
)) then
4072 Unchecked_Convert_To
(RTE
(RE_Prim_Ptr
),
4073 Make_Attribute_Reference
(Loc
,
4074 Prefix
=> New_Occurrence_Of
(Prim_Table
(J
), Loc
),
4075 Attribute_Name
=> Name_Unrestricted_Access
));
4077 New_Node
:= Make_Null
(Loc
);
4080 Append_To
(Prim_Ops_Aggr_List
, New_Node
);
4084 Make_Aggregate
(Loc
,
4085 Expressions
=> Prim_Ops_Aggr_List
);
4087 -- Remember aggregates initializing dispatch tables
4089 Append_Elmt
(New_Node
, DT_Aggr
);
4092 Make_Subtype_Declaration
(Loc
,
4093 Defining_Identifier
=> Make_Temporary
(Loc
, 'S'),
4094 Subtype_Indication
=>
4095 New_Occurrence_Of
(RTE
(RE_Address_Array
), Loc
));
4097 Append_To
(Result
, Decl
);
4100 Make_Object_Declaration
(Loc
,
4101 Defining_Identifier
=> Predef_Prims
,
4102 Constant_Present
=> Building_Static_DT
(Typ
),
4103 Aliased_Present
=> True,
4104 Object_Definition
=> New_Occurrence_Of
4105 (Defining_Identifier
(Decl
), Loc
),
4106 Expression
=> New_Node
));
4109 Make_Attribute_Definition_Clause
(Loc
,
4110 Name
=> New_Occurrence_Of
(Predef_Prims
, Loc
),
4111 Chars
=> Name_Alignment
,
4113 Make_Attribute_Reference
(Loc
,
4115 New_Occurrence_Of
(RTE
(RE_Integer_Address
), Loc
),
4116 Attribute_Name
=> Name_Alignment
)));
4121 -- OSD : Ada.Tags.Object_Specific_Data (Nb_Prims) :=
4122 -- (OSD_Table => (1 => <value>,
4126 -- Iface_DT : Dispatch_Table (Nb_Prims) :=
4127 -- ([ Signature => <sig-value> ],
4128 -- Tag_Kind => <tag_kind-value>,
4129 -- Predef_Prims => Predef_Prims'Address,
4130 -- Offset_To_Top => 0,
4131 -- OSD => OSD'Address,
4132 -- Prims_Ptr => (prim-op-1'address,
4133 -- prim-op-2'address,
4135 -- prim-op-n'address));
4136 -- for Iface_DT'Alignment use Address'Alignment;
4138 -- Stage 3: Initialize the discriminant and the record components
4140 DT_Constr_List
:= New_List
;
4141 DT_Aggr_List
:= New_List
;
4145 Append_To
(DT_Constr_List
, Make_Integer_Literal
(Loc
, Nb_Prim
));
4146 Append_To
(DT_Aggr_List
, Make_Integer_Literal
(Loc
, Nb_Prim
));
4150 if RTE_Record_Component_Available
(RE_Signature
) then
4151 Append_To
(DT_Aggr_List
,
4152 New_Occurrence_Of
(RTE
(RE_Secondary_DT
), Loc
));
4157 if RTE_Record_Component_Available
(RE_Tag_Kind
) then
4158 Append_To
(DT_Aggr_List
, Tagged_Kind
(Typ
));
4163 Append_To
(DT_Aggr_List
,
4164 Make_Attribute_Reference
(Loc
,
4165 Prefix
=> New_Occurrence_Of
(Predef_Prims
, Loc
),
4166 Attribute_Name
=> Name_Address
));
4168 -- Note: The correct value of Offset_To_Top will be set by the init
4171 Append_To
(DT_Aggr_List
, Make_Integer_Literal
(Loc
, 0));
4173 -- Generate the Object Specific Data table required to dispatch calls
4174 -- through synchronized interfaces.
4177 or else Is_Abstract_Type
(Typ
)
4178 or else Is_Controlled
(Typ
)
4179 or else Restriction_Active
(No_Dispatching_Calls
)
4180 or else not Is_Limited_Type
(Typ
)
4181 or else not Has_Interfaces
(Typ
)
4182 or else not Build_Thunks
4183 or else not RTE_Record_Component_Available
(RE_OSD_Table
)
4185 -- No OSD table required
4187 Append_To
(DT_Aggr_List
,
4188 New_Occurrence_Of
(RTE
(RE_Null_Address
), Loc
));
4191 OSD_Aggr_List
:= New_List
;
4194 Prim_Table
: array (Nat
range 1 .. Nb_Prim
) of Entity_Id
;
4196 Prim_Alias
: Entity_Id
;
4197 Prim_Elmt
: Elmt_Id
;
4203 Prim_Table
:= (others => Empty
);
4204 Prim_Alias
:= Empty
;
4206 Prim_Elmt
:= First_Elmt
(Primitive_Operations
(Typ
));
4207 while Present
(Prim_Elmt
) loop
4208 Prim
:= Node
(Prim_Elmt
);
4210 if Present
(Interface_Alias
(Prim
))
4211 and then Find_Dispatching_Type
4212 (Interface_Alias
(Prim
)) = Iface
4214 Prim_Alias
:= Interface_Alias
(Prim
);
4215 E
:= Ultimate_Alias
(Prim
);
4216 Pos
:= UI_To_Int
(DT_Position
(Prim_Alias
));
4218 if Present
(Prim_Table
(Pos
)) then
4219 pragma Assert
(Prim_Table
(Pos
) = E
);
4223 Prim_Table
(Pos
) := E
;
4225 Append_To
(OSD_Aggr_List
,
4226 Make_Component_Association
(Loc
,
4227 Choices
=> New_List
(
4228 Make_Integer_Literal
(Loc
,
4229 DT_Position
(Prim_Alias
))),
4231 Make_Integer_Literal
(Loc
,
4232 DT_Position
(Alias
(Prim
)))));
4238 Next_Elmt
(Prim_Elmt
);
4240 pragma Assert
(Count
= Nb_Prim
);
4243 OSD
:= Make_Temporary
(Loc
, 'I');
4246 Make_Object_Declaration
(Loc
,
4247 Defining_Identifier
=> OSD
,
4248 Object_Definition
=>
4249 Make_Subtype_Indication
(Loc
,
4251 New_Occurrence_Of
(RTE
(RE_Object_Specific_Data
), Loc
),
4253 Make_Index_Or_Discriminant_Constraint
(Loc
,
4254 Constraints
=> New_List
(
4255 Make_Integer_Literal
(Loc
, Nb_Prim
)))),
4258 Make_Aggregate
(Loc
,
4259 Component_Associations
=> New_List
(
4260 Make_Component_Association
(Loc
,
4261 Choices
=> New_List
(
4263 (RTE_Record_Component
(RE_OSD_Num_Prims
), Loc
)),
4265 Make_Integer_Literal
(Loc
, Nb_Prim
)),
4267 Make_Component_Association
(Loc
,
4268 Choices
=> New_List
(
4270 (RTE_Record_Component
(RE_OSD_Table
), Loc
)),
4271 Expression
=> Make_Aggregate
(Loc
,
4272 Component_Associations
=> OSD_Aggr_List
))))));
4275 Make_Attribute_Definition_Clause
(Loc
,
4276 Name
=> New_Occurrence_Of
(OSD
, Loc
),
4277 Chars
=> Name_Alignment
,
4279 Make_Attribute_Reference
(Loc
,
4281 New_Occurrence_Of
(RTE
(RE_Integer_Address
), Loc
),
4282 Attribute_Name
=> Name_Alignment
)));
4284 -- In secondary dispatch tables the Typeinfo component contains
4285 -- the address of the Object Specific Data (see a-tags.ads)
4287 Append_To
(DT_Aggr_List
,
4288 Make_Attribute_Reference
(Loc
,
4289 Prefix
=> New_Occurrence_Of
(OSD
, Loc
),
4290 Attribute_Name
=> Name_Address
));
4293 -- Initialize the table of primitive operations
4295 Prim_Ops_Aggr_List
:= New_List
;
4298 Append_To
(Prim_Ops_Aggr_List
, Make_Null
(Loc
));
4300 elsif Is_Abstract_Type
(Typ
)
4301 or else not Building_Static_DT
(Typ
)
4303 for J
in 1 .. Nb_Prim
loop
4304 Append_To
(Prim_Ops_Aggr_List
, Make_Null
(Loc
));
4309 CPP_Nb_Prims
: constant Nat
:= CPP_Num_Prims
(Typ
);
4312 Prim_Table
: array (Nat
range 1 .. Nb_Prim
) of Entity_Id
;
4313 Thunk_Code
: Node_Id
;
4314 Thunk_Id
: Entity_Id
;
4317 Prim_Table
:= (others => Empty
);
4319 Prim_Elmt
:= First_Elmt
(Primitive_Operations
(Typ
));
4320 while Present
(Prim_Elmt
) loop
4321 Prim
:= Node
(Prim_Elmt
);
4322 E
:= Ultimate_Alias
(Prim
);
4323 Prim_Pos
:= UI_To_Int
(DT_Position
(E
));
4325 -- Do not reference predefined primitives because they are
4326 -- located in a separate dispatch table; skip abstract and
4327 -- eliminated primitives; skip primitives located in the C++
4328 -- part of the dispatch table because their slot is set by
4331 if not Is_Predefined_Dispatching_Operation
(Prim
)
4332 and then Present
(Interface_Alias
(Prim
))
4333 and then not Is_Abstract_Subprogram
(Alias
(Prim
))
4334 and then not Is_Eliminated
(Alias
(Prim
))
4335 and then (not Is_CPP_Class
(Root_Type
(Typ
))
4336 or else Prim_Pos
> CPP_Nb_Prims
)
4337 and then Find_Dispatching_Type
4338 (Interface_Alias
(Prim
)) = Iface
4340 -- Generate the code of the thunk only if the abstract
4341 -- interface type is not an immediate ancestor of
4342 -- Tagged_Type. Otherwise the DT associated with the
4343 -- interface is the primary DT.
4345 and then not Is_Ancestor
(Iface
, Typ
,
4346 Use_Full_View
=> True)
4348 if not Build_Thunks
then
4350 UI_To_Int
(DT_Position
(Interface_Alias
(Prim
)));
4351 Prim_Table
(Prim_Pos
) := Alias
(Prim
);
4354 Expand_Interface_Thunk
(Prim
, Thunk_Id
, Thunk_Code
);
4356 if Present
(Thunk_Id
) then
4358 UI_To_Int
(DT_Position
(Interface_Alias
(Prim
)));
4360 Prim_Table
(Prim_Pos
) := Thunk_Id
;
4361 Append_To
(Result
, Thunk_Code
);
4366 Next_Elmt
(Prim_Elmt
);
4369 for J
in Prim_Table
'Range loop
4370 if Present
(Prim_Table
(J
)) then
4372 Unchecked_Convert_To
(RTE
(RE_Prim_Ptr
),
4373 Make_Attribute_Reference
(Loc
,
4374 Prefix
=> New_Occurrence_Of
(Prim_Table
(J
), Loc
),
4375 Attribute_Name
=> Name_Unrestricted_Access
));
4378 New_Node
:= Make_Null
(Loc
);
4381 Append_To
(Prim_Ops_Aggr_List
, New_Node
);
4387 Make_Aggregate
(Loc
,
4388 Expressions
=> Prim_Ops_Aggr_List
);
4390 Append_To
(DT_Aggr_List
, New_Node
);
4392 -- Remember aggregates initializing dispatch tables
4394 Append_Elmt
(New_Node
, DT_Aggr
);
4396 -- Note: Secondary dispatch tables cannot be declared constant
4397 -- because the component Offset_To_Top is currently initialized
4398 -- by the IP routine.
4401 Make_Object_Declaration
(Loc
,
4402 Defining_Identifier
=> Iface_DT
,
4403 Aliased_Present
=> True,
4404 Constant_Present
=> False,
4406 Object_Definition
=>
4407 Make_Subtype_Indication
(Loc
,
4408 Subtype_Mark
=> New_Occurrence_Of
4409 (RTE
(RE_Dispatch_Table_Wrapper
), Loc
),
4410 Constraint
=> Make_Index_Or_Discriminant_Constraint
(Loc
,
4411 Constraints
=> DT_Constr_List
)),
4414 Make_Aggregate
(Loc
,
4415 Expressions
=> DT_Aggr_List
)));
4418 Make_Attribute_Definition_Clause
(Loc
,
4419 Name
=> New_Occurrence_Of
(Iface_DT
, Loc
),
4420 Chars
=> Name_Alignment
,
4423 Make_Attribute_Reference
(Loc
,
4425 New_Occurrence_Of
(RTE
(RE_Integer_Address
), Loc
),
4426 Attribute_Name
=> Name_Alignment
)));
4428 if Exporting_Table
then
4429 Export_DT
(Typ
, Iface_DT
, Suffix_Index
);
4431 -- Generate code to create the pointer to the dispatch table
4433 -- Iface_DT_Ptr : Tag := Tag!(DT.Prims_Ptr'Address);
4435 -- Note: This declaration is not added here if the table is exported
4436 -- because in such case Make_Tags has already added this declaration.
4440 Make_Object_Declaration
(Loc
,
4441 Defining_Identifier
=> Iface_DT_Ptr
,
4442 Constant_Present
=> True,
4444 Object_Definition
=>
4445 New_Occurrence_Of
(RTE
(RE_Interface_Tag
), Loc
),
4448 Unchecked_Convert_To
(RTE
(RE_Interface_Tag
),
4449 Make_Attribute_Reference
(Loc
,
4451 Make_Selected_Component
(Loc
,
4452 Prefix
=> New_Occurrence_Of
(Iface_DT
, Loc
),
4455 (RTE_Record_Component
(RE_Prims_Ptr
), Loc
)),
4456 Attribute_Name
=> Name_Address
))));
4460 Make_Object_Declaration
(Loc
,
4461 Defining_Identifier
=> Predef_Prims_Ptr
,
4462 Constant_Present
=> True,
4464 Object_Definition
=>
4465 New_Occurrence_Of
(RTE
(RE_Address
), Loc
),
4468 Make_Attribute_Reference
(Loc
,
4470 Make_Selected_Component
(Loc
,
4471 Prefix
=> New_Occurrence_Of
(Iface_DT
, Loc
),
4474 (RTE_Record_Component
(RE_Predef_Prims
), Loc
)),
4475 Attribute_Name
=> Name_Address
)));
4477 -- Remember entities containing dispatch tables
4479 Append_Elmt
(Predef_Prims
, DT_Decl
);
4480 Append_Elmt
(Iface_DT
, DT_Decl
);
4481 end Make_Secondary_DT
;
4485 Elab_Code
: constant List_Id
:= New_List
;
4486 Result
: constant List_Id
:= New_List
;
4487 Tname
: constant Name_Id
:= Chars
(Typ
);
4489 AI_Tag_Elmt
: Elmt_Id
;
4490 AI_Tag_Comp
: Elmt_Id
;
4491 DT_Aggr_List
: List_Id
;
4492 DT_Constr_List
: List_Id
;
4496 Iface_Table_Node
: Node_Id
;
4497 Name_ITable
: Name_Id
;
4498 Nb_Predef_Prims
: Nat
:= 0;
4501 Num_Ifaces
: Nat
:= 0;
4502 Parent_Typ
: Entity_Id
;
4504 Prim_Elmt
: Elmt_Id
;
4505 Prim_Ops_Aggr_List
: List_Id
;
4507 Typ_Comps
: Elist_Id
;
4508 Typ_Ifaces
: Elist_Id
;
4509 TSD_Aggr_List
: List_Id
;
4510 TSD_Tags_List
: List_Id
;
4512 -- The following name entries are used by Make_DT to generate a number
4513 -- of entities related to a tagged type. These entities may be generated
4514 -- in a scope other than that of the tagged type declaration, and if
4515 -- the entities for two tagged types with the same name happen to be
4516 -- generated in the same scope, we have to take care to use different
4517 -- names. This is achieved by means of a unique serial number appended
4518 -- to each generated entity name.
4520 Name_DT
: constant Name_Id
:=
4521 New_External_Name
(Tname
, 'T', Suffix_Index
=> -1);
4522 Name_Exname
: constant Name_Id
:=
4523 New_External_Name
(Tname
, 'E', Suffix_Index
=> -1);
4524 Name_HT_Link
: constant Name_Id
:=
4525 New_External_Name
(Tname
, 'H', Suffix_Index
=> -1);
4526 Name_Predef_Prims
: constant Name_Id
:=
4527 New_External_Name
(Tname
, 'R', Suffix_Index
=> -1);
4528 Name_SSD
: constant Name_Id
:=
4529 New_External_Name
(Tname
, 'S', Suffix_Index
=> -1);
4530 Name_TSD
: constant Name_Id
:=
4531 New_External_Name
(Tname
, 'B', Suffix_Index
=> -1);
4533 -- Entities built with above names
4535 DT
: constant Entity_Id
:=
4536 Make_Defining_Identifier
(Loc
, Name_DT
);
4537 Exname
: constant Entity_Id
:=
4538 Make_Defining_Identifier
(Loc
, Name_Exname
);
4539 HT_Link
: constant Entity_Id
:=
4540 Make_Defining_Identifier
(Loc
, Name_HT_Link
);
4541 Predef_Prims
: constant Entity_Id
:=
4542 Make_Defining_Identifier
(Loc
, Name_Predef_Prims
);
4543 SSD
: constant Entity_Id
:=
4544 Make_Defining_Identifier
(Loc
, Name_SSD
);
4545 TSD
: constant Entity_Id
:=
4546 Make_Defining_Identifier
(Loc
, Name_TSD
);
4548 -- Start of processing for Make_DT
4551 pragma Assert
(Is_Frozen
(Typ
));
4553 -- Handle cases in which there is no need to build the dispatch table
4555 if Has_Dispatch_Table
(Typ
)
4556 or else No
(Access_Disp_Table
(Typ
))
4557 or else Is_CPP_Class
(Typ
)
4558 or else Convention
(Typ
) = Convention_CIL
4559 or else Convention
(Typ
) = Convention_Java
4563 elsif No_Run_Time_Mode
then
4564 Error_Msg_CRT
("tagged types", Typ
);
4567 elsif not RTE_Available
(RE_Tag
) then
4569 Make_Object_Declaration
(Loc
,
4570 Defining_Identifier
=> Node
(First_Elmt
4571 (Access_Disp_Table
(Typ
))),
4572 Object_Definition
=> New_Occurrence_Of
(RTE
(RE_Tag
), Loc
),
4573 Constant_Present
=> True,
4575 Unchecked_Convert_To
(RTE
(RE_Tag
),
4576 New_Occurrence_Of
(RTE
(RE_Null_Address
), Loc
))));
4578 Analyze_List
(Result
, Suppress
=> All_Checks
);
4579 Error_Msg_CRT
("tagged types", Typ
);
4583 -- Ensure that the value of Max_Predef_Prims defined in a-tags is
4584 -- correct. Valid values are 9 under configurable runtime or 15
4585 -- with full runtime.
4587 if RTE_Available
(RE_Interface_Data
) then
4588 if Max_Predef_Prims
/= 15 then
4589 Error_Msg_N
("run-time library configuration error", Typ
);
4593 if Max_Predef_Prims
/= 9 then
4594 Error_Msg_N
("run-time library configuration error", Typ
);
4595 Error_Msg_CRT
("tagged types", Typ
);
4600 -- Initialize Parent_Typ handling private types
4602 Parent_Typ
:= Etype
(Typ
);
4604 if Present
(Full_View
(Parent_Typ
)) then
4605 Parent_Typ
:= Full_View
(Parent_Typ
);
4608 -- Ensure that all the primitives are frozen. This is only required when
4609 -- building static dispatch tables --- the primitives must be frozen to
4610 -- be referenced (otherwise we have problems with the backend). It is
4611 -- not a requirement with nonstatic dispatch tables because in this case
4612 -- we generate now an empty dispatch table; the extra code required to
4613 -- register the primitives in the slots will be generated later --- when
4614 -- each primitive is frozen (see Freeze_Subprogram).
4616 if Building_Static_DT
(Typ
) then
4618 Save
: constant Boolean := Freezing_Library_Level_Tagged_Type
;
4620 Prim_Elmt
: Elmt_Id
;
4624 Freezing_Library_Level_Tagged_Type
:= True;
4626 Prim_Elmt
:= First_Elmt
(Primitive_Operations
(Typ
));
4627 while Present
(Prim_Elmt
) loop
4628 Prim
:= Node
(Prim_Elmt
);
4629 Frnodes
:= Freeze_Entity
(Prim
, Typ
);
4635 F
:= First_Formal
(Prim
);
4636 while Present
(F
) loop
4637 Check_Premature_Freezing
(Prim
, Typ
, Etype
(F
));
4641 Check_Premature_Freezing
(Prim
, Typ
, Etype
(Prim
));
4644 if Present
(Frnodes
) then
4645 Append_List_To
(Result
, Frnodes
);
4648 Next_Elmt
(Prim_Elmt
);
4651 Freezing_Library_Level_Tagged_Type
:= Save
;
4655 -- Ada 2005 (AI-251): Build the secondary dispatch tables
4657 if Has_Interfaces
(Typ
) then
4658 Collect_Interface_Components
(Typ
, Typ_Comps
);
4660 -- Each secondary dispatch table is assigned an unique positive
4661 -- suffix index; such value also corresponds with the location of
4662 -- its entity in the Dispatch_Table_Wrappers list (see Make_Tags).
4664 -- Note: This value must be kept sync with the Suffix_Index values
4665 -- generated by Make_Tags
4669 Next_Elmt
(Next_Elmt
(First_Elmt
(Access_Disp_Table
(Typ
))));
4671 AI_Tag_Comp
:= First_Elmt
(Typ_Comps
);
4672 while Present
(AI_Tag_Comp
) loop
4673 pragma Assert
(Has_Suffix
(Node
(AI_Tag_Elmt
), 'P'));
4675 -- Build the secondary table containing pointers to thunks
4679 Iface
=> Base_Type
(Related_Type
(Node
(AI_Tag_Comp
))),
4680 Suffix_Index
=> Suffix_Index
,
4681 Num_Iface_Prims
=> UI_To_Int
4682 (DT_Entry_Count
(Node
(AI_Tag_Comp
))),
4683 Iface_DT_Ptr
=> Node
(AI_Tag_Elmt
),
4684 Predef_Prims_Ptr
=> Node
(Next_Elmt
(AI_Tag_Elmt
)),
4685 Build_Thunks
=> True,
4688 -- Skip secondary dispatch table referencing thunks to predefined
4691 Next_Elmt
(AI_Tag_Elmt
);
4692 pragma Assert
(Has_Suffix
(Node
(AI_Tag_Elmt
), 'Y'));
4694 -- Secondary dispatch table referencing user-defined primitives
4695 -- covered by this interface.
4697 Next_Elmt
(AI_Tag_Elmt
);
4698 pragma Assert
(Has_Suffix
(Node
(AI_Tag_Elmt
), 'D'));
4700 -- Build the secondary table containing pointers to primitives
4701 -- (used to give support to Generic Dispatching Constructors).
4706 (Related_Type
(Node
(AI_Tag_Comp
))),
4708 Num_Iface_Prims
=> UI_To_Int
4709 (DT_Entry_Count
(Node
(AI_Tag_Comp
))),
4710 Iface_DT_Ptr
=> Node
(AI_Tag_Elmt
),
4711 Predef_Prims_Ptr
=> Node
(Next_Elmt
(AI_Tag_Elmt
)),
4712 Build_Thunks
=> False,
4715 -- Skip secondary dispatch table referencing predefined primitives
4717 Next_Elmt
(AI_Tag_Elmt
);
4718 pragma Assert
(Has_Suffix
(Node
(AI_Tag_Elmt
), 'Z'));
4720 Suffix_Index
:= Suffix_Index
+ 1;
4721 Next_Elmt
(AI_Tag_Elmt
);
4722 Next_Elmt
(AI_Tag_Comp
);
4726 -- Get the _tag entity and number of primitives of its dispatch table
4728 DT_Ptr
:= Node
(First_Elmt
(Access_Disp_Table
(Typ
)));
4729 Nb_Prim
:= UI_To_Int
(DT_Entry_Count
(First_Tag_Component
(Typ
)));
4731 Set_Is_Statically_Allocated
(DT
, Is_Library_Level_Tagged_Type
(Typ
));
4732 Set_Is_Statically_Allocated
(SSD
, Is_Library_Level_Tagged_Type
(Typ
));
4733 Set_Is_Statically_Allocated
(TSD
, Is_Library_Level_Tagged_Type
(Typ
));
4734 Set_Is_Statically_Allocated
(Predef_Prims
,
4735 Is_Library_Level_Tagged_Type
(Typ
));
4737 -- In case of locally defined tagged type we declare the object
4738 -- containing the dispatch table by means of a variable. Its
4739 -- initialization is done later by means of an assignment. This is
4740 -- required to generate its External_Tag.
4742 if not Building_Static_DT
(Typ
) then
4745 -- DT : No_Dispatch_Table_Wrapper;
4746 -- for DT'Alignment use Address'Alignment;
4747 -- DT_Ptr : Tag := !Tag (DT.NDT_Prims_Ptr'Address);
4749 if not Has_DT
(Typ
) then
4751 Make_Object_Declaration
(Loc
,
4752 Defining_Identifier
=> DT
,
4753 Aliased_Present
=> True,
4754 Constant_Present
=> False,
4755 Object_Definition
=>
4757 (RTE
(RE_No_Dispatch_Table_Wrapper
), Loc
)));
4760 Make_Attribute_Definition_Clause
(Loc
,
4761 Name
=> New_Occurrence_Of
(DT
, Loc
),
4762 Chars
=> Name_Alignment
,
4764 Make_Attribute_Reference
(Loc
,
4766 New_Occurrence_Of
(RTE
(RE_Integer_Address
), Loc
),
4767 Attribute_Name
=> Name_Alignment
)));
4770 Make_Object_Declaration
(Loc
,
4771 Defining_Identifier
=> DT_Ptr
,
4772 Object_Definition
=> New_Occurrence_Of
(RTE
(RE_Tag
), Loc
),
4773 Constant_Present
=> True,
4775 Unchecked_Convert_To
(RTE
(RE_Tag
),
4776 Make_Attribute_Reference
(Loc
,
4778 Make_Selected_Component
(Loc
,
4779 Prefix
=> New_Occurrence_Of
(DT
, Loc
),
4782 (RTE_Record_Component
(RE_NDT_Prims_Ptr
), Loc
)),
4783 Attribute_Name
=> Name_Address
))));
4785 Set_Is_Statically_Allocated
(DT_Ptr
,
4786 Is_Library_Level_Tagged_Type
(Typ
));
4788 -- Generate the SCIL node for the previous object declaration
4789 -- because it has a tag initialization.
4791 if Generate_SCIL
then
4793 Make_SCIL_Dispatch_Table_Tag_Init
(Sloc
(Last
(Result
)));
4794 Set_SCIL_Entity
(New_Node
, Typ
);
4795 Set_SCIL_Node
(Last
(Result
), New_Node
);
4799 -- DT : Dispatch_Table_Wrapper (Nb_Prim);
4800 -- for DT'Alignment use Address'Alignment;
4801 -- DT_Ptr : Tag := !Tag (DT.Prims_Ptr'Address);
4804 -- If the tagged type has no primitives we add a dummy slot
4805 -- whose address will be the tag of this type.
4809 New_List
(Make_Integer_Literal
(Loc
, 1));
4812 New_List
(Make_Integer_Literal
(Loc
, Nb_Prim
));
4816 Make_Object_Declaration
(Loc
,
4817 Defining_Identifier
=> DT
,
4818 Aliased_Present
=> True,
4819 Constant_Present
=> False,
4820 Object_Definition
=>
4821 Make_Subtype_Indication
(Loc
,
4823 New_Occurrence_Of
(RTE
(RE_Dispatch_Table_Wrapper
), Loc
),
4824 Constraint
=> Make_Index_Or_Discriminant_Constraint
(Loc
,
4825 Constraints
=> DT_Constr_List
))));
4828 Make_Attribute_Definition_Clause
(Loc
,
4829 Name
=> New_Occurrence_Of
(DT
, Loc
),
4830 Chars
=> Name_Alignment
,
4832 Make_Attribute_Reference
(Loc
,
4834 New_Occurrence_Of
(RTE
(RE_Integer_Address
), Loc
),
4835 Attribute_Name
=> Name_Alignment
)));
4838 Make_Object_Declaration
(Loc
,
4839 Defining_Identifier
=> DT_Ptr
,
4840 Object_Definition
=> New_Occurrence_Of
(RTE
(RE_Tag
), Loc
),
4841 Constant_Present
=> True,
4843 Unchecked_Convert_To
(RTE
(RE_Tag
),
4844 Make_Attribute_Reference
(Loc
,
4846 Make_Selected_Component
(Loc
,
4847 Prefix
=> New_Occurrence_Of
(DT
, Loc
),
4850 (RTE_Record_Component
(RE_Prims_Ptr
), Loc
)),
4851 Attribute_Name
=> Name_Address
))));
4853 Set_Is_Statically_Allocated
(DT_Ptr
,
4854 Is_Library_Level_Tagged_Type
(Typ
));
4856 -- Generate the SCIL node for the previous object declaration
4857 -- because it has a tag initialization.
4859 if Generate_SCIL
then
4861 Make_SCIL_Dispatch_Table_Tag_Init
(Sloc
(Last
(Result
)));
4862 Set_SCIL_Entity
(New_Node
, Typ
);
4863 Set_SCIL_Node
(Last
(Result
), New_Node
);
4867 Make_Object_Declaration
(Loc
,
4868 Defining_Identifier
=>
4869 Node
(Next_Elmt
(First_Elmt
(Access_Disp_Table
(Typ
)))),
4870 Constant_Present
=> True,
4871 Object_Definition
=> New_Occurrence_Of
4872 (RTE
(RE_Address
), Loc
),
4874 Make_Attribute_Reference
(Loc
,
4876 Make_Selected_Component
(Loc
,
4877 Prefix
=> New_Occurrence_Of
(DT
, Loc
),
4880 (RTE_Record_Component
(RE_Predef_Prims
), Loc
)),
4881 Attribute_Name
=> Name_Address
)));
4885 -- Generate: Exname : constant String := full_qualified_name (typ);
4886 -- The type itself may be an anonymous parent type, so use the first
4887 -- subtype to have a user-recognizable name.
4890 Make_Object_Declaration
(Loc
,
4891 Defining_Identifier
=> Exname
,
4892 Constant_Present
=> True,
4893 Object_Definition
=> New_Occurrence_Of
(Standard_String
, Loc
),
4895 Make_String_Literal
(Loc
,
4896 Fully_Qualified_Name_String
(First_Subtype
(Typ
)))));
4898 Set_Is_Statically_Allocated
(Exname
);
4899 Set_Is_True_Constant
(Exname
);
4901 -- Declare the object used by Ada.Tags.Register_Tag
4903 if RTE_Available
(RE_Register_Tag
) then
4905 Make_Object_Declaration
(Loc
,
4906 Defining_Identifier
=> HT_Link
,
4907 Object_Definition
=> New_Occurrence_Of
(RTE
(RE_Tag
), Loc
)));
4910 -- Generate code to create the storage for the type specific data object
4911 -- with enough space to store the tags of the ancestors plus the tags
4912 -- of all the implemented interfaces (as described in a-tags.adb).
4914 -- TSD : Type_Specific_Data (I_Depth) :=
4915 -- (Idepth => I_Depth,
4916 -- Access_Level => Type_Access_Level (Typ),
4917 -- Alignment => Typ'Alignment,
4918 -- Expanded_Name => Cstring_Ptr!(Exname'Address))
4919 -- External_Tag => Cstring_Ptr!(Exname'Address))
4920 -- HT_Link => HT_Link'Address,
4921 -- Transportable => <<boolean-value>>,
4922 -- Type_Is_Abstract => <<boolean-value>>,
4923 -- Needs_Finalization => <<boolean-value>>,
4924 -- [ Size_Func => Size_Prim'Access, ]
4925 -- [ Interfaces_Table => <<access-value>>, ]
4926 -- [ SSD => SSD_Table'Address ]
4927 -- Tags_Table => (0 => null,
4930 -- for TSD'Alignment use Address'Alignment
4932 TSD_Aggr_List
:= New_List
;
4934 -- Idepth: Count ancestors to compute the inheritance depth. For private
4935 -- extensions, always go to the full view in order to compute the real
4936 -- inheritance depth.
4939 Current_Typ
: Entity_Id
;
4940 Parent_Typ
: Entity_Id
;
4946 Parent_Typ
:= Etype
(Current_Typ
);
4948 if Is_Private_Type
(Parent_Typ
) then
4949 Parent_Typ
:= Full_View
(Base_Type
(Parent_Typ
));
4952 exit when Parent_Typ
= Current_Typ
;
4954 I_Depth
:= I_Depth
+ 1;
4955 Current_Typ
:= Parent_Typ
;
4959 Append_To
(TSD_Aggr_List
,
4960 Make_Integer_Literal
(Loc
, I_Depth
));
4964 Append_To
(TSD_Aggr_List
,
4965 Make_Integer_Literal
(Loc
, Type_Access_Level
(Typ
)));
4969 -- For CPP types we cannot rely on the value of 'Alignment provided
4970 -- by the backend to initialize this TSD field.
4972 if Convention
(Typ
) = Convention_CPP
4973 or else Is_CPP_Class
(Root_Type
(Typ
))
4975 Append_To
(TSD_Aggr_List
,
4976 Make_Integer_Literal
(Loc
, 0));
4978 Append_To
(TSD_Aggr_List
,
4979 Make_Attribute_Reference
(Loc
,
4980 Prefix
=> New_Occurrence_Of
(Typ
, Loc
),
4981 Attribute_Name
=> Name_Alignment
));
4986 Append_To
(TSD_Aggr_List
,
4987 Unchecked_Convert_To
(RTE
(RE_Cstring_Ptr
),
4988 Make_Attribute_Reference
(Loc
,
4989 Prefix
=> New_Occurrence_Of
(Exname
, Loc
),
4990 Attribute_Name
=> Name_Address
)));
4992 -- External_Tag of a local tagged type
4994 -- <typ>A : constant String :=
4995 -- "Internal tag at 16#tag-addr#: <full-name-of-typ>";
4997 -- The reason we generate this strange name is that we do not want to
4998 -- enter local tagged types in the global hash table used to compute
4999 -- the Internal_Tag attribute for two reasons:
5001 -- 1. It is hard to avoid a tasking race condition for entering the
5002 -- entry into the hash table.
5004 -- 2. It would cause a storage leak, unless we rig up considerable
5005 -- mechanism to remove the entry from the hash table on exit.
5007 -- So what we do is to generate the above external tag name, where the
5008 -- hex address is the address of the local dispatch table (i.e. exactly
5009 -- the value we want if Internal_Tag is computed from this string).
5011 -- Of course this value will only be valid if the tagged type is still
5012 -- in scope, but it clearly must be erroneous to compute the internal
5013 -- tag of a tagged type that is out of scope.
5015 -- We don't do this processing if an explicit external tag has been
5016 -- specified. That's an odd case for which we have already issued a
5017 -- warning, where we will not be able to compute the internal tag.
5019 if not Is_Library_Level_Entity
(Typ
)
5020 and then not Has_External_Tag_Rep_Clause
(Typ
)
5023 Exname
: constant Entity_Id
:=
5024 Make_Defining_Identifier
(Loc
,
5025 New_External_Name
(Tname
, 'A'));
5027 Full_Name
: constant String_Id
:=
5028 Fully_Qualified_Name_String
(First_Subtype
(Typ
));
5029 Str1_Id
: String_Id
;
5030 Str2_Id
: String_Id
;
5034 -- Str1 = "Internal tag at 16#";
5037 Store_String_Chars
("Internal tag at 16#");
5038 Str1_Id
:= End_String
;
5041 -- Str2 = "#: <type-full-name>";
5044 Store_String_Chars
("#: ");
5045 Store_String_Chars
(Full_Name
);
5046 Str2_Id
:= End_String
;
5049 -- Exname : constant String :=
5050 -- Str1 & Address_Image (Tag) & Str2;
5052 if RTE_Available
(RE_Address_Image
) then
5054 Make_Object_Declaration
(Loc
,
5055 Defining_Identifier
=> Exname
,
5056 Constant_Present
=> True,
5057 Object_Definition
=> New_Occurrence_Of
5058 (Standard_String
, Loc
),
5060 Make_Op_Concat
(Loc
,
5062 Make_String_Literal
(Loc
, Str1_Id
),
5064 Make_Op_Concat
(Loc
,
5066 Make_Function_Call
(Loc
,
5069 (RTE
(RE_Address_Image
), Loc
),
5070 Parameter_Associations
=> New_List
(
5071 Unchecked_Convert_To
(RTE
(RE_Address
),
5072 New_Occurrence_Of
(DT_Ptr
, Loc
)))),
5074 Make_String_Literal
(Loc
, Str2_Id
)))));
5078 Make_Object_Declaration
(Loc
,
5079 Defining_Identifier
=> Exname
,
5080 Constant_Present
=> True,
5081 Object_Definition
=> New_Occurrence_Of
5082 (Standard_String
, Loc
),
5084 Make_Op_Concat
(Loc
,
5086 Make_String_Literal
(Loc
, Str1_Id
),
5088 Make_String_Literal
(Loc
, Str2_Id
))));
5092 Unchecked_Convert_To
(RTE
(RE_Cstring_Ptr
),
5093 Make_Attribute_Reference
(Loc
,
5094 Prefix
=> New_Occurrence_Of
(Exname
, Loc
),
5095 Attribute_Name
=> Name_Address
));
5098 -- External tag of a library-level tagged type: Check for a definition
5099 -- of External_Tag. The clause is considered only if it applies to this
5100 -- specific tagged type, as opposed to one of its ancestors.
5101 -- If the type is an unconstrained type extension, we are building the
5102 -- dispatch table of its anonymous base type, so the external tag, if
5103 -- any was specified, must be retrieved from the first subtype. Go to
5104 -- the full view in case the clause is in the private part.
5108 Def
: constant Node_Id
:= Get_Attribute_Definition_Clause
5109 (Underlying_Type
(First_Subtype
(Typ
)),
5110 Attribute_External_Tag
);
5112 Old_Val
: String_Id
;
5113 New_Val
: String_Id
;
5117 if not Present
(Def
)
5118 or else Entity
(Name
(Def
)) /= First_Subtype
(Typ
)
5121 Unchecked_Convert_To
(RTE
(RE_Cstring_Ptr
),
5122 Make_Attribute_Reference
(Loc
,
5123 Prefix
=> New_Occurrence_Of
(Exname
, Loc
),
5124 Attribute_Name
=> Name_Address
));
5126 Old_Val
:= Strval
(Expr_Value_S
(Expression
(Def
)));
5128 -- For the rep clause "for <typ>'external_tag use y" generate:
5130 -- <typ>A : constant string := y;
5132 -- <typ>A'Address is used to set the External_Tag component
5135 -- Create a new nul terminated string if it is not already
5137 if String_Length
(Old_Val
) > 0
5139 Get_String_Char
(Old_Val
, String_Length
(Old_Val
)) = 0
5143 Start_String
(Old_Val
);
5144 Store_String_Char
(Get_Char_Code
(ASCII
.NUL
));
5145 New_Val
:= End_String
;
5148 E
:= Make_Defining_Identifier
(Loc
,
5149 New_External_Name
(Chars
(Typ
), 'A'));
5152 Make_Object_Declaration
(Loc
,
5153 Defining_Identifier
=> E
,
5154 Constant_Present
=> True,
5155 Object_Definition
=>
5156 New_Occurrence_Of
(Standard_String
, Loc
),
5158 Make_String_Literal
(Loc
, New_Val
)));
5161 Unchecked_Convert_To
(RTE
(RE_Cstring_Ptr
),
5162 Make_Attribute_Reference
(Loc
,
5163 Prefix
=> New_Occurrence_Of
(E
, Loc
),
5164 Attribute_Name
=> Name_Address
));
5169 Append_To
(TSD_Aggr_List
, New_Node
);
5173 if RTE_Available
(RE_Register_Tag
) then
5174 Append_To
(TSD_Aggr_List
,
5175 Unchecked_Convert_To
(RTE
(RE_Tag_Ptr
),
5176 Make_Attribute_Reference
(Loc
,
5177 Prefix
=> New_Occurrence_Of
(HT_Link
, Loc
),
5178 Attribute_Name
=> Name_Address
)));
5180 Append_To
(TSD_Aggr_List
,
5181 Unchecked_Convert_To
(RTE
(RE_Tag_Ptr
),
5182 New_Occurrence_Of
(RTE
(RE_Null_Address
), Loc
)));
5185 -- Transportable: Set for types that can be used in remote calls
5186 -- with respect to E.4(18) legality rules.
5189 Transportable
: Entity_Id
;
5195 or else Is_Shared_Passive
(Typ
)
5197 ((Is_Remote_Types
(Typ
)
5198 or else Is_Remote_Call_Interface
(Typ
))
5199 and then Original_View_In_Visible_Part
(Typ
))
5200 or else not Comes_From_Source
(Typ
));
5202 Append_To
(TSD_Aggr_List
,
5203 New_Occurrence_Of
(Transportable
, Loc
));
5206 -- Type_Is_Abstract (Ada 2012: AI05-0173). This functionality is
5207 -- not available in the HIE runtime.
5209 if RTE_Record_Component_Available
(RE_Type_Is_Abstract
) then
5211 Type_Is_Abstract
: Entity_Id
;
5215 Boolean_Literals
(Is_Abstract_Type
(Typ
));
5217 Append_To
(TSD_Aggr_List
,
5218 New_Occurrence_Of
(Type_Is_Abstract
, Loc
));
5222 -- Needs_Finalization: Set if the type is controlled or has controlled
5226 Needs_Fin
: Entity_Id
;
5229 Needs_Fin
:= Boolean_Literals
(Needs_Finalization
(Typ
));
5230 Append_To
(TSD_Aggr_List
, New_Occurrence_Of
(Needs_Fin
, Loc
));
5235 if RTE_Record_Component_Available
(RE_Size_Func
) then
5237 -- Initialize this field to Null_Address if we are not building
5238 -- static dispatch tables static or if the size function is not
5239 -- available. In the former case we cannot initialize this field
5240 -- until the function is frozen and registered in the dispatch
5241 -- table (see Register_Primitive).
5243 if not Building_Static_DT
(Typ
) or else not Has_DT
(Typ
) then
5244 Append_To
(TSD_Aggr_List
,
5245 Unchecked_Convert_To
(RTE
(RE_Size_Ptr
),
5246 New_Occurrence_Of
(RTE
(RE_Null_Address
), Loc
)));
5250 Prim_Elmt
: Elmt_Id
;
5252 Size_Comp
: Node_Id
;
5255 Prim_Elmt
:= First_Elmt
(Primitive_Operations
(Typ
));
5256 while Present
(Prim_Elmt
) loop
5257 Prim
:= Node
(Prim_Elmt
);
5259 if Chars
(Prim
) = Name_uSize
then
5260 Prim
:= Ultimate_Alias
(Prim
);
5262 if Is_Abstract_Subprogram
(Prim
) then
5264 Unchecked_Convert_To
(RTE
(RE_Size_Ptr
),
5265 New_Occurrence_Of
(RTE
(RE_Null_Address
), Loc
));
5268 Unchecked_Convert_To
(RTE
(RE_Size_Ptr
),
5269 Make_Attribute_Reference
(Loc
,
5270 Prefix
=> New_Occurrence_Of
(Prim
, Loc
),
5271 Attribute_Name
=> Name_Unrestricted_Access
));
5277 Next_Elmt
(Prim_Elmt
);
5280 pragma Assert
(Present
(Size_Comp
));
5281 Append_To
(TSD_Aggr_List
, Size_Comp
);
5286 -- Interfaces_Table (required for AI-405)
5288 if RTE_Record_Component_Available
(RE_Interfaces_Table
) then
5290 -- Count the number of interface types implemented by Typ
5292 Collect_Interfaces
(Typ
, Typ_Ifaces
);
5294 AI
:= First_Elmt
(Typ_Ifaces
);
5295 while Present
(AI
) loop
5296 Num_Ifaces
:= Num_Ifaces
+ 1;
5300 if Num_Ifaces
= 0 then
5301 Iface_Table_Node
:= Make_Null
(Loc
);
5303 -- Generate the Interface_Table object
5307 TSD_Ifaces_List
: constant List_Id
:= New_List
;
5309 Sec_DT_Tag
: Node_Id
;
5312 AI
:= First_Elmt
(Typ_Ifaces
);
5313 while Present
(AI
) loop
5314 if Is_Ancestor
(Node
(AI
), Typ
, Use_Full_View
=> True) then
5316 New_Occurrence_Of
(DT_Ptr
, Loc
);
5320 (Next_Elmt
(First_Elmt
(Access_Disp_Table
(Typ
))));
5321 pragma Assert
(Has_Thunks
(Node
(Elmt
)));
5323 while Is_Tag
(Node
(Elmt
))
5325 Is_Ancestor
(Node
(AI
), Related_Type
(Node
(Elmt
)),
5326 Use_Full_View
=> True)
5328 pragma Assert
(Has_Thunks
(Node
(Elmt
)));
5330 pragma Assert
(Has_Thunks
(Node
(Elmt
)));
5332 pragma Assert
(not Has_Thunks
(Node
(Elmt
)));
5334 pragma Assert
(not Has_Thunks
(Node
(Elmt
)));
5338 pragma Assert
(Ekind
(Node
(Elmt
)) = E_Constant
5340 Has_Thunks
(Node
(Next_Elmt
(Next_Elmt
(Elmt
)))));
5342 New_Occurrence_Of
(Node
(Next_Elmt
(Next_Elmt
(Elmt
))),
5346 Append_To
(TSD_Ifaces_List
,
5347 Make_Aggregate
(Loc
,
5348 Expressions
=> New_List
(
5352 Unchecked_Convert_To
(RTE
(RE_Tag
),
5354 (Node
(First_Elmt
(Access_Disp_Table
(Node
(AI
)))),
5357 -- Static_Offset_To_Top
5359 New_Occurrence_Of
(Standard_True
, Loc
),
5361 -- Offset_To_Top_Value
5363 Make_Integer_Literal
(Loc
, 0),
5365 -- Offset_To_Top_Func
5371 Unchecked_Convert_To
(RTE
(RE_Tag
), Sec_DT_Tag
)
5378 Name_ITable
:= New_External_Name
(Tname
, 'I');
5379 ITable
:= Make_Defining_Identifier
(Loc
, Name_ITable
);
5380 Set_Is_Statically_Allocated
(ITable
,
5381 Is_Library_Level_Tagged_Type
(Typ
));
5383 -- The table of interfaces is not constant; its slots are
5384 -- filled at run time by the IP routine using attribute
5385 -- 'Position to know the location of the tag components
5386 -- (and this attribute cannot be safely used before the
5387 -- object is initialized).
5390 Make_Object_Declaration
(Loc
,
5391 Defining_Identifier
=> ITable
,
5392 Aliased_Present
=> True,
5393 Constant_Present
=> False,
5394 Object_Definition
=>
5395 Make_Subtype_Indication
(Loc
,
5397 New_Occurrence_Of
(RTE
(RE_Interface_Data
), Loc
),
5398 Constraint
=> Make_Index_Or_Discriminant_Constraint
5400 Constraints
=> New_List
(
5401 Make_Integer_Literal
(Loc
, Num_Ifaces
)))),
5403 Expression
=> Make_Aggregate
(Loc
,
5404 Expressions
=> New_List
(
5405 Make_Integer_Literal
(Loc
, Num_Ifaces
),
5406 Make_Aggregate
(Loc
,
5407 Expressions
=> TSD_Ifaces_List
)))));
5410 Make_Attribute_Definition_Clause
(Loc
,
5411 Name
=> New_Occurrence_Of
(ITable
, Loc
),
5412 Chars
=> Name_Alignment
,
5414 Make_Attribute_Reference
(Loc
,
5416 New_Occurrence_Of
(RTE
(RE_Integer_Address
), Loc
),
5417 Attribute_Name
=> Name_Alignment
)));
5420 Make_Attribute_Reference
(Loc
,
5421 Prefix
=> New_Occurrence_Of
(ITable
, Loc
),
5422 Attribute_Name
=> Name_Unchecked_Access
);
5426 Append_To
(TSD_Aggr_List
, Iface_Table_Node
);
5429 -- Generate the Select Specific Data table for synchronized types that
5430 -- implement synchronized interfaces. The size of the table is
5431 -- constrained by the number of non-predefined primitive operations.
5433 if RTE_Record_Component_Available
(RE_SSD
) then
5434 if Ada_Version
>= Ada_2005
5435 and then Has_DT
(Typ
)
5436 and then Is_Concurrent_Record_Type
(Typ
)
5437 and then Has_Interfaces
(Typ
)
5438 and then Nb_Prim
> 0
5439 and then not Is_Abstract_Type
(Typ
)
5440 and then not Is_Controlled
(Typ
)
5441 and then not Restriction_Active
(No_Dispatching_Calls
)
5442 and then not Restriction_Active
(No_Select_Statements
)
5445 Make_Object_Declaration
(Loc
,
5446 Defining_Identifier
=> SSD
,
5447 Aliased_Present
=> True,
5448 Object_Definition
=>
5449 Make_Subtype_Indication
(Loc
,
5450 Subtype_Mark
=> New_Occurrence_Of
(
5451 RTE
(RE_Select_Specific_Data
), Loc
),
5453 Make_Index_Or_Discriminant_Constraint
(Loc
,
5454 Constraints
=> New_List
(
5455 Make_Integer_Literal
(Loc
, Nb_Prim
))))));
5458 Make_Attribute_Definition_Clause
(Loc
,
5459 Name
=> New_Occurrence_Of
(SSD
, Loc
),
5460 Chars
=> Name_Alignment
,
5462 Make_Attribute_Reference
(Loc
,
5464 New_Occurrence_Of
(RTE
(RE_Integer_Address
), Loc
),
5465 Attribute_Name
=> Name_Alignment
)));
5467 -- This table is initialized by Make_Select_Specific_Data_Table,
5468 -- which calls Set_Entry_Index and Set_Prim_Op_Kind.
5470 Append_To
(TSD_Aggr_List
,
5471 Make_Attribute_Reference
(Loc
,
5472 Prefix
=> New_Occurrence_Of
(SSD
, Loc
),
5473 Attribute_Name
=> Name_Unchecked_Access
));
5475 Append_To
(TSD_Aggr_List
, Make_Null
(Loc
));
5479 -- Initialize the table of ancestor tags. In case of interface types
5480 -- this table is not needed.
5482 TSD_Tags_List
:= New_List
;
5484 -- If we are not statically allocating the dispatch table then we must
5485 -- fill position 0 with null because we still have not generated the
5488 if not Building_Static_DT
(Typ
)
5489 or else Is_Interface
(Typ
)
5491 Append_To
(TSD_Tags_List
,
5492 Unchecked_Convert_To
(RTE
(RE_Tag
),
5493 New_Occurrence_Of
(RTE
(RE_Null_Address
), Loc
)));
5495 -- Otherwise we can safely reference the tag
5498 Append_To
(TSD_Tags_List
,
5499 New_Occurrence_Of
(DT_Ptr
, Loc
));
5502 -- Fill the rest of the table with the tags of the ancestors
5505 Current_Typ
: Entity_Id
;
5506 Parent_Typ
: Entity_Id
;
5514 Parent_Typ
:= Etype
(Current_Typ
);
5516 if Is_Private_Type
(Parent_Typ
) then
5517 Parent_Typ
:= Full_View
(Base_Type
(Parent_Typ
));
5520 exit when Parent_Typ
= Current_Typ
;
5522 if Is_CPP_Class
(Parent_Typ
) then
5524 -- The tags defined in the C++ side will be inherited when
5525 -- the object is constructed (Exp_Ch3.Build_Init_Procedure)
5527 Append_To
(TSD_Tags_List
,
5528 Unchecked_Convert_To
(RTE
(RE_Tag
),
5529 New_Occurrence_Of
(RTE
(RE_Null_Address
), Loc
)));
5531 Append_To
(TSD_Tags_List
,
5533 (Node
(First_Elmt
(Access_Disp_Table
(Parent_Typ
))),
5538 Current_Typ
:= Parent_Typ
;
5541 pragma Assert
(Pos
= I_Depth
+ 1);
5544 Append_To
(TSD_Aggr_List
,
5545 Make_Aggregate
(Loc
,
5546 Expressions
=> TSD_Tags_List
));
5548 -- Build the TSD object
5551 Make_Object_Declaration
(Loc
,
5552 Defining_Identifier
=> TSD
,
5553 Aliased_Present
=> True,
5554 Constant_Present
=> Building_Static_DT
(Typ
),
5555 Object_Definition
=>
5556 Make_Subtype_Indication
(Loc
,
5557 Subtype_Mark
=> New_Occurrence_Of
(
5558 RTE
(RE_Type_Specific_Data
), Loc
),
5560 Make_Index_Or_Discriminant_Constraint
(Loc
,
5561 Constraints
=> New_List
(
5562 Make_Integer_Literal
(Loc
, I_Depth
)))),
5564 Expression
=> Make_Aggregate
(Loc
,
5565 Expressions
=> TSD_Aggr_List
)));
5567 Set_Is_True_Constant
(TSD
, Building_Static_DT
(Typ
));
5570 Make_Attribute_Definition_Clause
(Loc
,
5571 Name
=> New_Occurrence_Of
(TSD
, Loc
),
5572 Chars
=> Name_Alignment
,
5574 Make_Attribute_Reference
(Loc
,
5575 Prefix
=> New_Occurrence_Of
(RTE
(RE_Integer_Address
), Loc
),
5576 Attribute_Name
=> Name_Alignment
)));
5578 -- Initialize or declare the dispatch table object
5580 if not Has_DT
(Typ
) then
5581 DT_Constr_List
:= New_List
;
5582 DT_Aggr_List
:= New_List
;
5587 Make_Attribute_Reference
(Loc
,
5588 Prefix
=> New_Occurrence_Of
(TSD
, Loc
),
5589 Attribute_Name
=> Name_Address
);
5591 Append_To
(DT_Constr_List
, New_Node
);
5592 Append_To
(DT_Aggr_List
, New_Copy
(New_Node
));
5593 Append_To
(DT_Aggr_List
, Make_Integer_Literal
(Loc
, 0));
5595 -- In case of locally defined tagged types we have already declared
5596 -- and uninitialized object for the dispatch table, which is now
5597 -- initialized by means of the following assignment:
5599 -- DT := (TSD'Address, 0);
5601 if not Building_Static_DT
(Typ
) then
5603 Make_Assignment_Statement
(Loc
,
5604 Name
=> New_Occurrence_Of
(DT
, Loc
),
5605 Expression
=> Make_Aggregate
(Loc
,
5606 Expressions
=> DT_Aggr_List
)));
5608 -- In case of library level tagged types we declare and export now
5609 -- the constant object containing the dummy dispatch table. There
5610 -- is no need to declare the tag here because it has been previously
5611 -- declared by Make_Tags
5613 -- DT : aliased constant No_Dispatch_Table :=
5614 -- (NDT_TSD => TSD'Address;
5615 -- NDT_Prims_Ptr => 0);
5616 -- for DT'Alignment use Address'Alignment;
5620 Make_Object_Declaration
(Loc
,
5621 Defining_Identifier
=> DT
,
5622 Aliased_Present
=> True,
5623 Constant_Present
=> True,
5624 Object_Definition
=>
5625 New_Occurrence_Of
(RTE
(RE_No_Dispatch_Table_Wrapper
), Loc
),
5626 Expression
=> Make_Aggregate
(Loc
,
5627 Expressions
=> DT_Aggr_List
)));
5630 Make_Attribute_Definition_Clause
(Loc
,
5631 Name
=> New_Occurrence_Of
(DT
, Loc
),
5632 Chars
=> Name_Alignment
,
5634 Make_Attribute_Reference
(Loc
,
5636 New_Occurrence_Of
(RTE
(RE_Integer_Address
), Loc
),
5637 Attribute_Name
=> Name_Alignment
)));
5639 Export_DT
(Typ
, DT
);
5642 -- Common case: Typ has a dispatch table
5646 -- Predef_Prims : Address_Array (1 .. Default_Prim_Ops_Count) :=
5647 -- (predef-prim-op-1'address,
5648 -- predef-prim-op-2'address,
5650 -- predef-prim-op-n'address);
5651 -- for Predef_Prims'Alignment use Address'Alignment
5653 -- DT : Dispatch_Table (Nb_Prims) :=
5654 -- (Signature => <sig-value>,
5655 -- Tag_Kind => <tag_kind-value>,
5656 -- Predef_Prims => Predef_Prims'First'Address,
5657 -- Offset_To_Top => 0,
5658 -- TSD => TSD'Address;
5659 -- Prims_Ptr => (prim-op-1'address,
5660 -- prim-op-2'address,
5662 -- prim-op-n'address));
5663 -- for DT'Alignment use Address'Alignment
5670 if not Building_Static_DT
(Typ
) then
5671 Nb_Predef_Prims
:= Max_Predef_Prims
;
5674 Prim_Elmt
:= First_Elmt
(Primitive_Operations
(Typ
));
5675 while Present
(Prim_Elmt
) loop
5676 Prim
:= Node
(Prim_Elmt
);
5678 if Is_Predefined_Dispatching_Operation
(Prim
)
5679 and then not Is_Abstract_Subprogram
(Prim
)
5681 Pos
:= UI_To_Int
(DT_Position
(Prim
));
5683 if Pos
> Nb_Predef_Prims
then
5684 Nb_Predef_Prims
:= Pos
;
5688 Next_Elmt
(Prim_Elmt
);
5694 (Nat
range 1 .. Nb_Predef_Prims
) of Entity_Id
;
5699 Prim_Ops_Aggr_List
:= New_List
;
5701 Prim_Table
:= (others => Empty
);
5703 if Building_Static_DT
(Typ
) then
5704 Prim_Elmt
:= First_Elmt
(Primitive_Operations
(Typ
));
5705 while Present
(Prim_Elmt
) loop
5706 Prim
:= Node
(Prim_Elmt
);
5708 if Is_Predefined_Dispatching_Operation
(Prim
)
5709 and then not Is_Abstract_Subprogram
(Prim
)
5710 and then not Is_Eliminated
(Prim
)
5711 and then not Present
(Prim_Table
5712 (UI_To_Int
(DT_Position
(Prim
))))
5714 E
:= Ultimate_Alias
(Prim
);
5715 pragma Assert
(not Is_Abstract_Subprogram
(E
));
5716 Prim_Table
(UI_To_Int
(DT_Position
(Prim
))) := E
;
5719 Next_Elmt
(Prim_Elmt
);
5723 for J
in Prim_Table
'Range loop
5724 if Present
(Prim_Table
(J
)) then
5726 Unchecked_Convert_To
(RTE
(RE_Prim_Ptr
),
5727 Make_Attribute_Reference
(Loc
,
5728 Prefix
=> New_Occurrence_Of
(Prim_Table
(J
), Loc
),
5729 Attribute_Name
=> Name_Unrestricted_Access
));
5731 New_Node
:= Make_Null
(Loc
);
5734 Append_To
(Prim_Ops_Aggr_List
, New_Node
);
5738 Make_Aggregate
(Loc
,
5739 Expressions
=> Prim_Ops_Aggr_List
);
5742 Make_Subtype_Declaration
(Loc
,
5743 Defining_Identifier
=> Make_Temporary
(Loc
, 'S'),
5744 Subtype_Indication
=>
5745 New_Occurrence_Of
(RTE
(RE_Address_Array
), Loc
));
5747 Append_To
(Result
, Decl
);
5750 Make_Object_Declaration
(Loc
,
5751 Defining_Identifier
=> Predef_Prims
,
5752 Aliased_Present
=> True,
5753 Constant_Present
=> Building_Static_DT
(Typ
),
5754 Object_Definition
=> New_Occurrence_Of
5755 (Defining_Identifier
(Decl
), Loc
),
5756 Expression
=> New_Node
));
5758 -- Remember aggregates initializing dispatch tables
5760 Append_Elmt
(New_Node
, DT_Aggr
);
5763 Make_Attribute_Definition_Clause
(Loc
,
5764 Name
=> New_Occurrence_Of
(Predef_Prims
, Loc
),
5765 Chars
=> Name_Alignment
,
5767 Make_Attribute_Reference
(Loc
,
5769 New_Occurrence_Of
(RTE
(RE_Integer_Address
), Loc
),
5770 Attribute_Name
=> Name_Alignment
)));
5774 -- Stage 1: Initialize the discriminant and the record components
5776 DT_Constr_List
:= New_List
;
5777 DT_Aggr_List
:= New_List
;
5779 -- Num_Prims. If the tagged type has no primitives we add a dummy
5780 -- slot whose address will be the tag of this type.
5783 New_Node
:= Make_Integer_Literal
(Loc
, 1);
5785 New_Node
:= Make_Integer_Literal
(Loc
, Nb_Prim
);
5788 Append_To
(DT_Constr_List
, New_Node
);
5789 Append_To
(DT_Aggr_List
, New_Copy
(New_Node
));
5793 if RTE_Record_Component_Available
(RE_Signature
) then
5794 Append_To
(DT_Aggr_List
,
5795 New_Occurrence_Of
(RTE
(RE_Primary_DT
), Loc
));
5800 if RTE_Record_Component_Available
(RE_Tag_Kind
) then
5801 Append_To
(DT_Aggr_List
, Tagged_Kind
(Typ
));
5806 Append_To
(DT_Aggr_List
,
5807 Make_Attribute_Reference
(Loc
,
5808 Prefix
=> New_Occurrence_Of
(Predef_Prims
, Loc
),
5809 Attribute_Name
=> Name_Address
));
5813 Append_To
(DT_Aggr_List
, Make_Integer_Literal
(Loc
, 0));
5817 Append_To
(DT_Aggr_List
,
5818 Make_Attribute_Reference
(Loc
,
5819 Prefix
=> New_Occurrence_Of
(TSD
, Loc
),
5820 Attribute_Name
=> Name_Address
));
5822 -- Stage 2: Initialize the table of user-defined primitive operations
5824 Prim_Ops_Aggr_List
:= New_List
;
5827 Append_To
(Prim_Ops_Aggr_List
, Make_Null
(Loc
));
5829 elsif not Building_Static_DT
(Typ
) then
5830 for J
in 1 .. Nb_Prim
loop
5831 Append_To
(Prim_Ops_Aggr_List
, Make_Null
(Loc
));
5836 CPP_Nb_Prims
: constant Nat
:= CPP_Num_Prims
(Typ
);
5839 Prim_Elmt
: Elmt_Id
;
5841 Prim_Table
: array (Nat
range 1 .. Nb_Prim
) of Entity_Id
;
5844 Prim_Table
:= (others => Empty
);
5846 Prim_Elmt
:= First_Elmt
(Primitive_Operations
(Typ
));
5847 while Present
(Prim_Elmt
) loop
5848 Prim
:= Node
(Prim_Elmt
);
5850 -- Retrieve the ultimate alias of the primitive for proper
5851 -- handling of renamings and eliminated primitives.
5853 E
:= Ultimate_Alias
(Prim
);
5854 Prim_Pos
:= UI_To_Int
(DT_Position
(E
));
5856 -- Do not reference predefined primitives because they are
5857 -- located in a separate dispatch table; skip entities with
5858 -- attribute Interface_Alias because they are only required
5859 -- to build secondary dispatch tables; skip abstract and
5860 -- eliminated primitives; for derivations of CPP types skip
5861 -- primitives located in the C++ part of the dispatch table
5862 -- because their slot is initialized by the IC routine.
5864 if not Is_Predefined_Dispatching_Operation
(Prim
)
5865 and then not Is_Predefined_Dispatching_Operation
(E
)
5866 and then not Present
(Interface_Alias
(Prim
))
5867 and then not Is_Abstract_Subprogram
(E
)
5868 and then not Is_Eliminated
(E
)
5869 and then (not Is_CPP_Class
(Root_Type
(Typ
))
5870 or else Prim_Pos
> CPP_Nb_Prims
)
5873 (UI_To_Int
(DT_Position
(Prim
)) <= Nb_Prim
);
5875 Prim_Table
(UI_To_Int
(DT_Position
(Prim
))) := E
;
5878 Next_Elmt
(Prim_Elmt
);
5881 for J
in Prim_Table
'Range loop
5882 if Present
(Prim_Table
(J
)) then
5884 Unchecked_Convert_To
(RTE
(RE_Prim_Ptr
),
5885 Make_Attribute_Reference
(Loc
,
5886 Prefix
=> New_Occurrence_Of
(Prim_Table
(J
), Loc
),
5887 Attribute_Name
=> Name_Unrestricted_Access
));
5889 New_Node
:= Make_Null
(Loc
);
5892 Append_To
(Prim_Ops_Aggr_List
, New_Node
);
5898 Make_Aggregate
(Loc
,
5899 Expressions
=> Prim_Ops_Aggr_List
);
5901 Append_To
(DT_Aggr_List
, New_Node
);
5903 -- Remember aggregates initializing dispatch tables
5905 Append_Elmt
(New_Node
, DT_Aggr
);
5907 -- In case of locally defined tagged types we have already declared
5908 -- and uninitialized object for the dispatch table, which is now
5909 -- initialized by means of an assignment.
5911 if not Building_Static_DT
(Typ
) then
5913 Make_Assignment_Statement
(Loc
,
5914 Name
=> New_Occurrence_Of
(DT
, Loc
),
5915 Expression
=> Make_Aggregate
(Loc
,
5916 Expressions
=> DT_Aggr_List
)));
5918 -- In case of library level tagged types we declare now and export
5919 -- the constant object containing the dispatch table.
5923 Make_Object_Declaration
(Loc
,
5924 Defining_Identifier
=> DT
,
5925 Aliased_Present
=> True,
5926 Constant_Present
=> True,
5927 Object_Definition
=>
5928 Make_Subtype_Indication
(Loc
,
5929 Subtype_Mark
=> New_Occurrence_Of
5930 (RTE
(RE_Dispatch_Table_Wrapper
), Loc
),
5931 Constraint
=> Make_Index_Or_Discriminant_Constraint
(Loc
,
5932 Constraints
=> DT_Constr_List
)),
5933 Expression
=> Make_Aggregate
(Loc
,
5934 Expressions
=> DT_Aggr_List
)));
5937 Make_Attribute_Definition_Clause
(Loc
,
5938 Name
=> New_Occurrence_Of
(DT
, Loc
),
5939 Chars
=> Name_Alignment
,
5941 Make_Attribute_Reference
(Loc
,
5943 New_Occurrence_Of
(RTE
(RE_Integer_Address
), Loc
),
5944 Attribute_Name
=> Name_Alignment
)));
5946 Export_DT
(Typ
, DT
);
5950 -- Initialize the table of ancestor tags if not building static
5953 if not Building_Static_DT
(Typ
)
5954 and then not Is_Interface
(Typ
)
5955 and then not Is_CPP_Class
(Typ
)
5958 Make_Assignment_Statement
(Loc
,
5960 Make_Indexed_Component
(Loc
,
5962 Make_Selected_Component
(Loc
,
5964 New_Occurrence_Of
(TSD
, Loc
),
5967 (RTE_Record_Component
(RE_Tags_Table
), Loc
)),
5969 New_List
(Make_Integer_Literal
(Loc
, 0))),
5973 (Node
(First_Elmt
(Access_Disp_Table
(Typ
))), Loc
)));
5976 -- Inherit the dispatch tables of the parent. There is no need to
5977 -- inherit anything from the parent when building static dispatch tables
5978 -- because the whole dispatch table (including inherited primitives) has
5979 -- been already built.
5981 if Building_Static_DT
(Typ
) then
5984 -- If the ancestor is a CPP_Class type we inherit the dispatch tables
5985 -- in the init proc, and we don't need to fill them in here.
5987 elsif Is_CPP_Class
(Parent_Typ
) then
5990 -- Otherwise we fill in the dispatch tables here
5993 if Typ
/= Parent_Typ
5994 and then not Is_Interface
(Typ
)
5995 and then not Restriction_Active
(No_Dispatching_Calls
)
5997 -- Inherit the dispatch table
5999 if not Is_Interface
(Typ
)
6000 and then not Is_Interface
(Parent_Typ
)
6001 and then not Is_CPP_Class
(Parent_Typ
)
6004 Nb_Prims
: constant Int
:=
6005 UI_To_Int
(DT_Entry_Count
6006 (First_Tag_Component
(Parent_Typ
)));
6009 Append_To
(Elab_Code
,
6010 Build_Inherit_Predefined_Prims
(Loc
,
6016 (Access_Disp_Table
(Parent_Typ
)))), Loc
),
6022 (Access_Disp_Table
(Typ
)))), Loc
)));
6024 if Nb_Prims
/= 0 then
6025 Append_To
(Elab_Code
,
6026 Build_Inherit_Prims
(Loc
,
6032 (Access_Disp_Table
(Parent_Typ
))), Loc
),
6033 New_Tag_Node
=> New_Occurrence_Of
(DT_Ptr
, Loc
),
6034 Num_Prims
=> Nb_Prims
));
6039 -- Inherit the secondary dispatch tables of the ancestor
6041 if not Is_CPP_Class
(Parent_Typ
) then
6043 Sec_DT_Ancestor
: Elmt_Id
:=
6047 (Access_Disp_Table
(Parent_Typ
))));
6048 Sec_DT_Typ
: Elmt_Id
:=
6052 (Access_Disp_Table
(Typ
))));
6054 procedure Copy_Secondary_DTs
(Typ
: Entity_Id
);
6055 -- Local procedure required to climb through the ancestors
6056 -- and copy the contents of all their secondary dispatch
6059 ------------------------
6060 -- Copy_Secondary_DTs --
6061 ------------------------
6063 procedure Copy_Secondary_DTs
(Typ
: Entity_Id
) is
6068 -- Climb to the ancestor (if any) handling private types
6070 if Present
(Full_View
(Etype
(Typ
))) then
6071 if Full_View
(Etype
(Typ
)) /= Typ
then
6072 Copy_Secondary_DTs
(Full_View
(Etype
(Typ
)));
6075 elsif Etype
(Typ
) /= Typ
then
6076 Copy_Secondary_DTs
(Etype
(Typ
));
6079 if Present
(Interfaces
(Typ
))
6080 and then not Is_Empty_Elmt_List
(Interfaces
(Typ
))
6082 Iface
:= First_Elmt
(Interfaces
(Typ
));
6083 E
:= First_Entity
(Typ
);
6085 and then Present
(Node
(Sec_DT_Ancestor
))
6086 and then Ekind
(Node
(Sec_DT_Ancestor
)) = E_Constant
6088 if Is_Tag
(E
) and then Chars
(E
) /= Name_uTag
then
6090 Num_Prims
: constant Int
:=
6091 UI_To_Int
(DT_Entry_Count
(E
));
6094 if not Is_Interface
(Etype
(Typ
)) then
6096 -- Inherit first secondary dispatch table
6098 Append_To
(Elab_Code
,
6099 Build_Inherit_Predefined_Prims
(Loc
,
6101 Unchecked_Convert_To
(RTE
(RE_Tag
),
6104 (Next_Elmt
(Sec_DT_Ancestor
)),
6107 Unchecked_Convert_To
(RTE
(RE_Tag
),
6109 (Node
(Next_Elmt
(Sec_DT_Typ
)),
6112 if Num_Prims
/= 0 then
6113 Append_To
(Elab_Code
,
6114 Build_Inherit_Prims
(Loc
,
6115 Typ
=> Node
(Iface
),
6117 Unchecked_Convert_To
6120 (Node
(Sec_DT_Ancestor
),
6123 Unchecked_Convert_To
6126 (Node
(Sec_DT_Typ
), Loc
)),
6127 Num_Prims
=> Num_Prims
));
6131 Next_Elmt
(Sec_DT_Ancestor
);
6132 Next_Elmt
(Sec_DT_Typ
);
6134 -- Skip the secondary dispatch table of
6135 -- predefined primitives
6137 Next_Elmt
(Sec_DT_Ancestor
);
6138 Next_Elmt
(Sec_DT_Typ
);
6140 if not Is_Interface
(Etype
(Typ
)) then
6142 -- Inherit second secondary dispatch table
6144 Append_To
(Elab_Code
,
6145 Build_Inherit_Predefined_Prims
(Loc
,
6147 Unchecked_Convert_To
(RTE
(RE_Tag
),
6150 (Next_Elmt
(Sec_DT_Ancestor
)),
6153 Unchecked_Convert_To
(RTE
(RE_Tag
),
6155 (Node
(Next_Elmt
(Sec_DT_Typ
)),
6158 if Num_Prims
/= 0 then
6159 Append_To
(Elab_Code
,
6160 Build_Inherit_Prims
(Loc
,
6161 Typ
=> Node
(Iface
),
6163 Unchecked_Convert_To
6166 (Node
(Sec_DT_Ancestor
),
6169 Unchecked_Convert_To
6172 (Node
(Sec_DT_Typ
), Loc
)),
6173 Num_Prims
=> Num_Prims
));
6178 Next_Elmt
(Sec_DT_Ancestor
);
6179 Next_Elmt
(Sec_DT_Typ
);
6181 -- Skip the secondary dispatch table of
6182 -- predefined primitives
6184 Next_Elmt
(Sec_DT_Ancestor
);
6185 Next_Elmt
(Sec_DT_Typ
);
6193 end Copy_Secondary_DTs
;
6196 if Present
(Node
(Sec_DT_Ancestor
))
6197 and then Ekind
(Node
(Sec_DT_Ancestor
)) = E_Constant
6199 -- Handle private types
6201 if Present
(Full_View
(Typ
)) then
6202 Copy_Secondary_DTs
(Full_View
(Typ
));
6204 Copy_Secondary_DTs
(Typ
);
6212 -- If the type has a representation clause which specifies its external
6213 -- tag then generate code to check if the external tag of this type is
6214 -- the same as the external tag of some other declaration.
6216 -- Check_TSD (TSD'Unrestricted_Access);
6218 -- This check is a consequence of AI05-0113-1/06, so it officially
6219 -- applies to Ada 2005 (and Ada 2012). It might be argued that it is
6220 -- a desirable check to add in Ada 95 mode, but we hesitate to make
6221 -- this change, as it would be incompatible, and could conceivably
6222 -- cause a problem in existing Aa 95 code.
6224 -- We check for No_Run_Time_Mode here, because we do not want to pick
6225 -- up the RE_Check_TSD entity and call it in No_Run_Time mode.
6227 if not No_Run_Time_Mode
6228 and then Ada_Version
>= Ada_2005
6229 and then Has_External_Tag_Rep_Clause
(Typ
)
6230 and then RTE_Available
(RE_Check_TSD
)
6231 and then not Debug_Flag_QQ
6233 Append_To
(Elab_Code
,
6234 Make_Procedure_Call_Statement
(Loc
,
6235 Name
=> New_Occurrence_Of
(RTE
(RE_Check_TSD
), Loc
),
6236 Parameter_Associations
=> New_List
(
6237 Make_Attribute_Reference
(Loc
,
6238 Prefix
=> New_Occurrence_Of
(TSD
, Loc
),
6239 Attribute_Name
=> Name_Unchecked_Access
))));
6242 -- Generate code to register the Tag in the External_Tag hash table for
6243 -- the pure Ada type only.
6245 -- Register_Tag (Dt_Ptr);
6247 -- Skip this action in the following cases:
6248 -- 1) if Register_Tag is not available.
6249 -- 2) in No_Run_Time mode.
6250 -- 3) if Typ is not defined at the library level (this is required
6251 -- to avoid adding concurrency control to the hash table used
6252 -- by the run-time to register the tags).
6254 if not No_Run_Time_Mode
6255 and then Is_Library_Level_Entity
(Typ
)
6256 and then RTE_Available
(RE_Register_Tag
)
6258 Append_To
(Elab_Code
,
6259 Make_Procedure_Call_Statement
(Loc
,
6260 Name
=> New_Occurrence_Of
(RTE
(RE_Register_Tag
), Loc
),
6261 Parameter_Associations
=>
6262 New_List
(New_Occurrence_Of
(DT_Ptr
, Loc
))));
6265 if not Is_Empty_List
(Elab_Code
) then
6266 Append_List_To
(Result
, Elab_Code
);
6269 -- Populate the two auxiliary tables used for dispatching asynchronous,
6270 -- conditional and timed selects for synchronized types that implement
6271 -- a limited interface. Skip this step in Ravenscar profile or when
6272 -- general dispatching is forbidden.
6274 if Ada_Version
>= Ada_2005
6275 and then Is_Concurrent_Record_Type
(Typ
)
6276 and then Has_Interfaces
(Typ
)
6277 and then not Restriction_Active
(No_Dispatching_Calls
)
6278 and then not Restriction_Active
(No_Select_Statements
)
6280 Append_List_To
(Result
,
6281 Make_Select_Specific_Data_Table
(Typ
));
6284 -- Remember entities containing dispatch tables
6286 Append_Elmt
(Predef_Prims
, DT_Decl
);
6287 Append_Elmt
(DT
, DT_Decl
);
6289 Analyze_List
(Result
, Suppress
=> All_Checks
);
6290 Set_Has_Dispatch_Table
(Typ
);
6292 -- Mark entities containing dispatch tables. Required by the backend to
6293 -- handle them properly.
6295 if Has_DT
(Typ
) then
6300 -- Object declarations
6302 Elmt
:= First_Elmt
(DT_Decl
);
6303 while Present
(Elmt
) loop
6304 Set_Is_Dispatch_Table_Entity
(Node
(Elmt
));
6305 pragma Assert
(Ekind
(Etype
(Node
(Elmt
))) = E_Array_Subtype
6306 or else Ekind
(Etype
(Node
(Elmt
))) = E_Record_Subtype
);
6307 Set_Is_Dispatch_Table_Entity
(Etype
(Node
(Elmt
)));
6311 -- Aggregates initializing dispatch tables
6313 Elmt
:= First_Elmt
(DT_Aggr
);
6314 while Present
(Elmt
) loop
6315 Set_Is_Dispatch_Table_Entity
(Etype
(Node
(Elmt
)));
6321 -- Register the tagged type in the call graph nodes table
6323 Register_CG_Node
(Typ
);
6332 function Make_VM_TSD
(Typ
: Entity_Id
) return List_Id
is
6333 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
6334 Result
: constant List_Id
:= New_List
;
6336 function Count_Primitives
(Typ
: Entity_Id
) return Nat
;
6337 -- Count the non-predefined primitive operations of Typ
6339 ----------------------
6340 -- Count_Primitives --
6341 ----------------------
6343 function Count_Primitives
(Typ
: Entity_Id
) return Nat
is
6345 Prim_Elmt
: Elmt_Id
;
6351 Prim_Elmt
:= First_Elmt
(Primitive_Operations
(Typ
));
6352 while Present
(Prim_Elmt
) loop
6353 Prim
:= Node
(Prim_Elmt
);
6355 if Is_Predefined_Dispatching_Operation
(Prim
)
6356 or else Is_Predefined_Dispatching_Alias
(Prim
)
6360 elsif Present
(Interface_Alias
(Prim
)) then
6364 Nb_Prim
:= Nb_Prim
+ 1;
6367 Next_Elmt
(Prim_Elmt
);
6371 end Count_Primitives
;
6377 function Make_OSD
(Iface
: Entity_Id
) return Node_Id
;
6378 -- Generate the Object Specific Data table required to dispatch calls
6379 -- through synchronized interfaces. Returns a node that references the
6380 -- generated OSD object.
6382 function Make_OSD
(Iface
: Entity_Id
) return Node_Id
is
6383 Nb_Prim
: constant Nat
:= Count_Primitives
(Iface
);
6385 OSD_Aggr_List
: List_Id
;
6389 -- OSD : Ada.Tags.Object_Specific_Data (Nb_Prims) :=
6390 -- (OSD_Table => (1 => <value>,
6395 or else Is_Abstract_Type
(Typ
)
6396 or else Is_Controlled
(Typ
)
6397 or else Restriction_Active
(No_Dispatching_Calls
)
6398 or else not Is_Limited_Type
(Typ
)
6399 or else not Has_Interfaces
(Typ
)
6400 or else not RTE_Record_Component_Available
(RE_OSD_Table
)
6402 -- No OSD table required
6404 return Make_Null
(Loc
);
6407 OSD_Aggr_List
:= New_List
;
6410 Prim_Table
: array (Nat
range 1 .. Nb_Prim
) of Entity_Id
;
6412 Prim_Alias
: Entity_Id
;
6413 Prim_Elmt
: Elmt_Id
;
6419 Prim_Table
:= (others => Empty
);
6420 Prim_Alias
:= Empty
;
6422 Prim_Elmt
:= First_Elmt
(Primitive_Operations
(Typ
));
6423 while Present
(Prim_Elmt
) loop
6424 Prim
:= Node
(Prim_Elmt
);
6426 if Present
(Interface_Alias
(Prim
))
6427 and then Find_Dispatching_Type
6428 (Interface_Alias
(Prim
)) = Iface
6430 Prim_Alias
:= Interface_Alias
(Prim
);
6431 E
:= Ultimate_Alias
(Prim
);
6432 Pos
:= UI_To_Int
(DT_Position
(Prim_Alias
));
6434 if Present
(Prim_Table
(Pos
)) then
6435 pragma Assert
(Prim_Table
(Pos
) = E
);
6439 Prim_Table
(Pos
) := E
;
6441 Append_To
(OSD_Aggr_List
,
6442 Make_Component_Association
(Loc
,
6443 Choices
=> New_List
(
6444 Make_Integer_Literal
(Loc
,
6445 DT_Position
(Prim_Alias
))),
6447 Make_Integer_Literal
(Loc
,
6448 DT_Position
(Alias
(Prim
)))));
6454 Next_Elmt
(Prim_Elmt
);
6456 pragma Assert
(Count
= Nb_Prim
);
6459 OSD
:= Make_Temporary
(Loc
, 'I');
6462 Make_Object_Declaration
(Loc
,
6463 Defining_Identifier
=> OSD
,
6464 Aliased_Present
=> True,
6465 Constant_Present
=> True,
6466 Object_Definition
=>
6467 Make_Subtype_Indication
(Loc
,
6469 New_Occurrence_Of
(RTE
(RE_Object_Specific_Data
), Loc
),
6471 Make_Index_Or_Discriminant_Constraint
(Loc
,
6472 Constraints
=> New_List
(
6473 Make_Integer_Literal
(Loc
, Nb_Prim
)))),
6476 Make_Aggregate
(Loc
,
6477 Component_Associations
=> New_List
(
6478 Make_Component_Association
(Loc
,
6479 Choices
=> New_List
(
6481 (RTE_Record_Component
(RE_OSD_Num_Prims
), Loc
)),
6483 Make_Integer_Literal
(Loc
, Nb_Prim
)),
6485 Make_Component_Association
(Loc
,
6486 Choices
=> New_List
(
6488 (RTE_Record_Component
(RE_OSD_Table
), Loc
)),
6489 Expression
=> Make_Aggregate
(Loc
,
6490 Component_Associations
=> OSD_Aggr_List
))))));
6493 Make_Attribute_Reference
(Loc
,
6494 Prefix
=> New_Occurrence_Of
(OSD
, Loc
),
6495 Attribute_Name
=> Name_Unchecked_Access
);
6501 Nb_Prim
: constant Nat
:= Count_Primitives
(Typ
);
6504 Iface_Table_Node
: Node_Id
;
6506 TSD_Aggr_List
: List_Id
;
6507 Typ_Ifaces
: Elist_Id
;
6508 TSD_Tags_List
: List_Id
;
6510 Tname
: constant Name_Id
:= Chars
(Typ
);
6511 Name_SSD
: constant Name_Id
:=
6512 New_External_Name
(Tname
, 'S', Suffix_Index
=> -1);
6513 Name_TSD
: constant Name_Id
:=
6514 New_External_Name
(Tname
, 'B', Suffix_Index
=> -1);
6515 SSD
: constant Entity_Id
:=
6516 Make_Defining_Identifier
(Loc
, Name_SSD
);
6517 TSD
: constant Entity_Id
:=
6518 Make_Defining_Identifier
(Loc
, Name_TSD
);
6520 -- Generate code to create the storage for the type specific data object
6521 -- with enough space to store the tags of the ancestors plus the tags
6522 -- of all the implemented interfaces (as described in a-tags.ads).
6524 -- TSD : Type_Specific_Data (I_Depth) :=
6525 -- (Idepth => I_Depth,
6526 -- Tag_Kind => <tag_kind-value>,
6527 -- Access_Level => Type_Access_Level (Typ),
6528 -- Alignment => Typ'Alignment,
6530 -- Type_Is_Abstract => <<boolean-value>>,
6531 -- Type_Is_Library_Level => <<boolean-value>>,
6532 -- Interfaces_Table => <<access-value>>
6533 -- SSD => SSD_Table'Address
6534 -- Tags_Table => (0 => Typ'Tag,
6538 TSD_Aggr_List
:= New_List
;
6540 -- Idepth: Count ancestors to compute the inheritance depth. For private
6541 -- extensions, always go to the full view in order to compute the real
6542 -- inheritance depth.
6545 Current_Typ
: Entity_Id
;
6546 Parent_Typ
: Entity_Id
;
6552 Parent_Typ
:= Etype
(Current_Typ
);
6554 if Is_Private_Type
(Parent_Typ
) then
6555 Parent_Typ
:= Full_View
(Base_Type
(Parent_Typ
));
6558 exit when Parent_Typ
= Current_Typ
;
6560 I_Depth
:= I_Depth
+ 1;
6561 Current_Typ
:= Parent_Typ
;
6567 Append_To
(TSD_Aggr_List
,
6568 Make_Integer_Literal
(Loc
, I_Depth
));
6572 Append_To
(TSD_Aggr_List
, Tagged_Kind
(Typ
));
6576 Append_To
(TSD_Aggr_List
,
6577 Make_Integer_Literal
(Loc
, Type_Access_Level
(Typ
)));
6581 -- For CPP types we cannot rely on the value of 'Alignment provided
6582 -- by the backend to initialize this TSD field. Why not???
6584 if Convention
(Typ
) = Convention_CPP
6585 or else Is_CPP_Class
(Root_Type
(Typ
))
6587 Append_To
(TSD_Aggr_List
,
6588 Make_Integer_Literal
(Loc
, 0));
6590 Append_To
(TSD_Aggr_List
,
6591 Make_Attribute_Reference
(Loc
,
6592 Prefix
=> New_Occurrence_Of
(Typ
, Loc
),
6593 Attribute_Name
=> Name_Alignment
));
6598 Append_To
(TSD_Aggr_List
,
6601 -- Type_Is_Abstract (Ada 2012: AI05-0173)
6604 Type_Is_Abstract
: Entity_Id
;
6608 Boolean_Literals
(Is_Abstract_Type
(Typ
));
6610 Append_To
(TSD_Aggr_List
,
6611 New_Occurrence_Of
(Type_Is_Abstract
, Loc
));
6614 -- Type_Is_Library_Level
6617 Type_Is_Library_Level
: Entity_Id
;
6619 Type_Is_Library_Level
:=
6620 Boolean_Literals
(Is_Library_Level_Entity
(Typ
));
6621 Append_To
(TSD_Aggr_List
,
6622 New_Occurrence_Of
(Type_Is_Library_Level
, Loc
));
6625 -- Interfaces_Table (required for AI-405)
6627 if RTE_Record_Component_Available
(RE_Interfaces_Table
) then
6629 -- Count the number of interface types implemented by Typ
6631 Collect_Interfaces
(Typ
, Typ_Ifaces
);
6634 AI
:= First_Elmt
(Typ_Ifaces
);
6635 while Present
(AI
) loop
6636 Num_Ifaces
:= Num_Ifaces
+ 1;
6640 if Num_Ifaces
= 0 then
6641 Iface_Table_Node
:= Make_Null
(Loc
);
6643 -- Generate the Interface_Table object
6647 TSD_Ifaces_List
: constant List_Id
:= New_List
;
6652 AI
:= First_Elmt
(Typ_Ifaces
);
6653 while Present
(AI
) loop
6656 Append_To
(TSD_Ifaces_List
,
6657 Make_Aggregate
(Loc
,
6658 Expressions
=> New_List
(
6662 Make_Attribute_Reference
(Loc
,
6663 Prefix
=> New_Occurrence_Of
(Iface
, Loc
),
6664 Attribute_Name
=> Name_Tag
),
6668 Make_OSD
(Iface
))));
6673 ITable
:= Make_Temporary
(Loc
, 'I');
6676 Make_Object_Declaration
(Loc
,
6677 Defining_Identifier
=> ITable
,
6678 Aliased_Present
=> True,
6679 Constant_Present
=> True,
6680 Object_Definition
=>
6681 Make_Subtype_Indication
(Loc
,
6683 New_Occurrence_Of
(RTE
(RE_Interface_Data
), Loc
),
6684 Constraint
=> Make_Index_Or_Discriminant_Constraint
6686 Constraints
=> New_List
(
6687 Make_Integer_Literal
(Loc
, Num_Ifaces
)))),
6689 Expression
=> Make_Aggregate
(Loc
,
6690 Expressions
=> New_List
(
6691 Make_Integer_Literal
(Loc
, Num_Ifaces
),
6692 Make_Aggregate
(Loc
,
6693 Expressions
=> TSD_Ifaces_List
)))));
6696 Make_Attribute_Reference
(Loc
,
6697 Prefix
=> New_Occurrence_Of
(ITable
, Loc
),
6698 Attribute_Name
=> Name_Unchecked_Access
);
6702 Append_To
(TSD_Aggr_List
, Iface_Table_Node
);
6705 -- Generate the Select Specific Data table for synchronized types that
6706 -- implement synchronized interfaces. The size of the table is
6707 -- constrained by the number of non-predefined primitive operations.
6709 if RTE_Record_Component_Available
(RE_SSD
) then
6710 if Ada_Version
>= Ada_2005
6711 and then Has_DT
(Typ
)
6712 and then Is_Concurrent_Record_Type
(Typ
)
6713 and then Has_Interfaces
(Typ
)
6714 and then Nb_Prim
> 0
6715 and then not Is_Abstract_Type
(Typ
)
6716 and then not Is_Controlled
(Typ
)
6717 and then not Restriction_Active
(No_Dispatching_Calls
)
6718 and then not Restriction_Active
(No_Select_Statements
)
6721 Make_Object_Declaration
(Loc
,
6722 Defining_Identifier
=> SSD
,
6723 Aliased_Present
=> True,
6724 Object_Definition
=>
6725 Make_Subtype_Indication
(Loc
,
6726 Subtype_Mark
=> New_Occurrence_Of
(
6727 RTE
(RE_Select_Specific_Data
), Loc
),
6729 Make_Index_Or_Discriminant_Constraint
(Loc
,
6730 Constraints
=> New_List
(
6731 Make_Integer_Literal
(Loc
, Nb_Prim
))))));
6733 -- This table is initialized by Make_Select_Specific_Data_Table,
6734 -- which calls Set_Entry_Index and Set_Prim_Op_Kind.
6736 Append_To
(TSD_Aggr_List
,
6737 Make_Attribute_Reference
(Loc
,
6738 Prefix
=> New_Occurrence_Of
(SSD
, Loc
),
6739 Attribute_Name
=> Name_Unchecked_Access
));
6741 Append_To
(TSD_Aggr_List
, Make_Null
(Loc
));
6745 -- Initialize the table of ancestor tags. In case of interface types
6746 -- this table is not needed.
6748 TSD_Tags_List
:= New_List
;
6750 -- Fill position 0 with Typ'Tag
6752 Append_To
(TSD_Tags_List
,
6753 Make_Attribute_Reference
(Loc
,
6754 Prefix
=> New_Occurrence_Of
(Typ
, Loc
),
6755 Attribute_Name
=> Name_Tag
));
6757 -- Fill the rest of the table with the tags of the ancestors
6760 Current_Typ
: Entity_Id
;
6761 Parent_Typ
: Entity_Id
;
6769 Parent_Typ
:= Etype
(Current_Typ
);
6771 if Is_Private_Type
(Parent_Typ
) then
6772 Parent_Typ
:= Full_View
(Base_Type
(Parent_Typ
));
6775 exit when Parent_Typ
= Current_Typ
;
6777 Append_To
(TSD_Tags_List
,
6778 Make_Attribute_Reference
(Loc
,
6779 Prefix
=> New_Occurrence_Of
(Parent_Typ
, Loc
),
6780 Attribute_Name
=> Name_Tag
));
6783 Current_Typ
:= Parent_Typ
;
6786 pragma Assert
(Pos
= I_Depth
+ 1);
6789 Append_To
(TSD_Aggr_List
,
6790 Make_Aggregate
(Loc
,
6791 Expressions
=> TSD_Tags_List
));
6793 -- Build the TSD object
6796 Make_Object_Declaration
(Loc
,
6797 Defining_Identifier
=> TSD
,
6798 Aliased_Present
=> True,
6799 Constant_Present
=> True,
6800 Object_Definition
=>
6801 Make_Subtype_Indication
(Loc
,
6802 Subtype_Mark
=> New_Occurrence_Of
(
6803 RTE
(RE_Type_Specific_Data
), Loc
),
6805 Make_Index_Or_Discriminant_Constraint
(Loc
,
6806 Constraints
=> New_List
(
6807 Make_Integer_Literal
(Loc
, I_Depth
)))),
6809 Expression
=> Make_Aggregate
(Loc
,
6810 Expressions
=> TSD_Aggr_List
)));
6814 -- (TSD => TSD'Unrestricted_Access);
6816 if Ada_Version
>= Ada_2005
6817 and then Is_Library_Level_Entity
(Typ
)
6818 and then Has_External_Tag_Rep_Clause
(Typ
)
6819 and then RTE_Available
(RE_Check_TSD
)
6820 and then not Debug_Flag_QQ
6823 Make_Procedure_Call_Statement
(Loc
,
6824 Name
=> New_Occurrence_Of
(RTE
(RE_Check_TSD
), Loc
),
6825 Parameter_Associations
=> New_List
(
6826 Make_Attribute_Reference
(Loc
,
6827 Prefix
=> New_Occurrence_Of
(TSD
, Loc
),
6828 Attribute_Name
=> Name_Unrestricted_Access
))));
6832 -- Register_TSD (TSD'Unrestricted_Access);
6835 Make_Procedure_Call_Statement
(Loc
,
6836 Name
=> New_Occurrence_Of
(RTE
(RE_Register_TSD
), Loc
),
6837 Parameter_Associations
=> New_List
(
6838 Make_Attribute_Reference
(Loc
,
6839 Prefix
=> New_Occurrence_Of
(TSD
, Loc
),
6840 Attribute_Name
=> Name_Unrestricted_Access
))));
6842 -- Populate the two auxiliary tables used for dispatching asynchronous,
6843 -- conditional and timed selects for synchronized types that implement
6844 -- a limited interface. Skip this step in Ravenscar profile or when
6845 -- general dispatching is forbidden.
6847 if Ada_Version
>= Ada_2005
6848 and then Is_Concurrent_Record_Type
(Typ
)
6849 and then Has_Interfaces
(Typ
)
6850 and then not Restriction_Active
(No_Dispatching_Calls
)
6851 and then not Restriction_Active
(No_Select_Statements
)
6853 Append_List_To
(Result
,
6854 Make_Select_Specific_Data_Table
(Typ
));
6860 -------------------------------------
6861 -- Make_Select_Specific_Data_Table --
6862 -------------------------------------
6864 function Make_Select_Specific_Data_Table
6865 (Typ
: Entity_Id
) return List_Id
6867 Assignments
: constant List_Id
:= New_List
;
6868 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
6870 Conc_Typ
: Entity_Id
;
6873 Prim_Als
: Entity_Id
;
6874 Prim_Elmt
: Elmt_Id
;
6878 type Examined_Array
is array (Int
range <>) of Boolean;
6880 function Find_Entry_Index
(E
: Entity_Id
) return Uint
;
6881 -- Given an entry, find its index in the visible declarations of the
6882 -- corresponding concurrent type of Typ.
6884 ----------------------
6885 -- Find_Entry_Index --
6886 ----------------------
6888 function Find_Entry_Index
(E
: Entity_Id
) return Uint
is
6889 Index
: Uint
:= Uint_1
;
6890 Subp_Decl
: Entity_Id
;
6894 and then not Is_Empty_List
(Decls
)
6896 Subp_Decl
:= First
(Decls
);
6897 while Present
(Subp_Decl
) loop
6898 if Nkind
(Subp_Decl
) = N_Entry_Declaration
then
6899 if Defining_Identifier
(Subp_Decl
) = E
then
6911 end Find_Entry_Index
;
6917 -- Start of processing for Make_Select_Specific_Data_Table
6920 pragma Assert
(not Restriction_Active
(No_Dispatching_Calls
));
6922 if Present
(Corresponding_Concurrent_Type
(Typ
)) then
6923 Conc_Typ
:= Corresponding_Concurrent_Type
(Typ
);
6925 if Present
(Full_View
(Conc_Typ
)) then
6926 Conc_Typ
:= Full_View
(Conc_Typ
);
6929 if Ekind
(Conc_Typ
) = E_Protected_Type
then
6930 Decls
:= Visible_Declarations
(Protected_Definition
(
6931 Parent
(Conc_Typ
)));
6933 pragma Assert
(Ekind
(Conc_Typ
) = E_Task_Type
);
6934 Decls
:= Visible_Declarations
(Task_Definition
(
6935 Parent
(Conc_Typ
)));
6939 -- Count the non-predefined primitive operations
6941 Prim_Elmt
:= First_Elmt
(Primitive_Operations
(Typ
));
6942 while Present
(Prim_Elmt
) loop
6943 Prim
:= Node
(Prim_Elmt
);
6945 if not (Is_Predefined_Dispatching_Operation
(Prim
)
6946 or else Is_Predefined_Dispatching_Alias
(Prim
))
6948 Nb_Prim
:= Nb_Prim
+ 1;
6951 Next_Elmt
(Prim_Elmt
);
6955 Examined
: Examined_Array
(1 .. Nb_Prim
) := (others => False);
6958 Prim_Elmt
:= First_Elmt
(Primitive_Operations
(Typ
));
6959 while Present
(Prim_Elmt
) loop
6960 Prim
:= Node
(Prim_Elmt
);
6962 -- Look for primitive overriding an abstract interface subprogram
6964 if Present
(Interface_Alias
(Prim
))
6967 (Find_Dispatching_Type
(Interface_Alias
(Prim
)), Typ
,
6968 Use_Full_View
=> True)
6969 and then not Examined
(UI_To_Int
(DT_Position
(Alias
(Prim
))))
6971 Prim_Pos
:= DT_Position
(Alias
(Prim
));
6972 pragma Assert
(UI_To_Int
(Prim_Pos
) <= Nb_Prim
);
6973 Examined
(UI_To_Int
(Prim_Pos
)) := True;
6975 -- Set the primitive operation kind regardless of subprogram
6977 -- Ada.Tags.Set_Prim_Op_Kind (DT_Ptr, <position>, <kind>);
6979 if Tagged_Type_Expansion
then
6982 (Node
(First_Elmt
(Access_Disp_Table
(Typ
))), Loc
);
6986 Make_Attribute_Reference
(Loc
,
6987 Prefix
=> New_Occurrence_Of
(Typ
, Loc
),
6988 Attribute_Name
=> Name_Tag
);
6991 Append_To
(Assignments
,
6992 Make_Procedure_Call_Statement
(Loc
,
6993 Name
=> New_Occurrence_Of
(RTE
(RE_Set_Prim_Op_Kind
), Loc
),
6994 Parameter_Associations
=> New_List
(
6996 Make_Integer_Literal
(Loc
, Prim_Pos
),
6997 Prim_Op_Kind
(Alias
(Prim
), Typ
))));
6999 -- Retrieve the root of the alias chain
7001 Prim_Als
:= Ultimate_Alias
(Prim
);
7003 -- In the case of an entry wrapper, set the entry index
7005 if Ekind
(Prim
) = E_Procedure
7006 and then Is_Primitive_Wrapper
(Prim_Als
)
7007 and then Ekind
(Wrapped_Entity
(Prim_Als
)) = E_Entry
7010 -- Ada.Tags.Set_Entry_Index
7011 -- (DT_Ptr, <position>, <index>);
7013 if Tagged_Type_Expansion
then
7016 (Node
(First_Elmt
(Access_Disp_Table
(Typ
))), Loc
);
7019 Make_Attribute_Reference
(Loc
,
7020 Prefix
=> New_Occurrence_Of
(Typ
, Loc
),
7021 Attribute_Name
=> Name_Tag
);
7024 Append_To
(Assignments
,
7025 Make_Procedure_Call_Statement
(Loc
,
7027 New_Occurrence_Of
(RTE
(RE_Set_Entry_Index
), Loc
),
7028 Parameter_Associations
=> New_List
(
7030 Make_Integer_Literal
(Loc
, Prim_Pos
),
7031 Make_Integer_Literal
(Loc
,
7032 Find_Entry_Index
(Wrapped_Entity
(Prim_Als
))))));
7036 Next_Elmt
(Prim_Elmt
);
7041 end Make_Select_Specific_Data_Table
;
7047 function Make_Tags
(Typ
: Entity_Id
) return List_Id
is
7048 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
7049 Result
: constant List_Id
:= New_List
;
7052 (Tag_Typ
: Entity_Id
;
7054 Is_Secondary_DT
: Boolean);
7055 -- Import the dispatch table DT of tagged type Tag_Typ. Required to
7056 -- generate forward references and statically allocate the table. For
7057 -- primary dispatch tables that require no dispatch table generate:
7059 -- DT : static aliased constant Non_Dispatch_Table_Wrapper;
7060 -- pragma Import (Ada, DT);
7062 -- Otherwise generate:
7064 -- DT : static aliased constant Dispatch_Table_Wrapper (Nb_Prim);
7065 -- pragma Import (Ada, DT);
7072 (Tag_Typ
: Entity_Id
;
7074 Is_Secondary_DT
: Boolean)
7076 DT_Constr_List
: List_Id
;
7080 Set_Is_Imported
(DT
);
7081 Set_Ekind
(DT
, E_Constant
);
7082 Set_Related_Type
(DT
, Typ
);
7084 -- The scope must be set now to call Get_External_Name
7086 Set_Scope
(DT
, Current_Scope
);
7088 Get_External_Name
(DT
);
7089 Set_Interface_Name
(DT
,
7090 Make_String_Literal
(Loc
, Strval
=> String_From_Name_Buffer
));
7092 -- Ensure proper Sprint output of this implicit importation
7094 Set_Is_Internal
(DT
);
7096 -- Save this entity to allow Make_DT to generate its exportation
7098 Append_Elmt
(DT
, Dispatch_Table_Wrappers
(Typ
));
7100 -- No dispatch table required
7102 if not Is_Secondary_DT
and then not Has_DT
(Tag_Typ
) then
7104 Make_Object_Declaration
(Loc
,
7105 Defining_Identifier
=> DT
,
7106 Aliased_Present
=> True,
7107 Constant_Present
=> True,
7108 Object_Definition
=>
7110 (RTE
(RE_No_Dispatch_Table_Wrapper
), Loc
)));
7113 -- Calculate the number of primitives of the dispatch table and
7114 -- the size of the Type_Specific_Data record.
7117 UI_To_Int
(DT_Entry_Count
(First_Tag_Component
(Tag_Typ
)));
7119 -- If the tagged type has no primitives we add a dummy slot whose
7120 -- address will be the tag of this type.
7124 New_List
(Make_Integer_Literal
(Loc
, 1));
7127 New_List
(Make_Integer_Literal
(Loc
, Nb_Prim
));
7131 Make_Object_Declaration
(Loc
,
7132 Defining_Identifier
=> DT
,
7133 Aliased_Present
=> True,
7134 Constant_Present
=> True,
7135 Object_Definition
=>
7136 Make_Subtype_Indication
(Loc
,
7138 New_Occurrence_Of
(RTE
(RE_Dispatch_Table_Wrapper
), Loc
),
7139 Constraint
=> Make_Index_Or_Discriminant_Constraint
(Loc
,
7140 Constraints
=> DT_Constr_List
))));
7146 Tname
: constant Name_Id
:= Chars
(Typ
);
7147 AI_Tag_Comp
: Elmt_Id
;
7148 DT
: Node_Id
:= Empty
;
7150 Predef_Prims_Ptr
: Node_Id
;
7151 Iface_DT
: Node_Id
:= Empty
;
7152 Iface_DT_Ptr
: Node_Id
;
7156 Typ_Comps
: Elist_Id
;
7158 -- Start of processing for Make_Tags
7161 pragma Assert
(No
(Access_Disp_Table
(Typ
)));
7162 Set_Access_Disp_Table
(Typ
, New_Elmt_List
);
7164 -- 1) Generate the primary tag entities
7166 -- Primary dispatch table containing user-defined primitives
7168 DT_Ptr
:= Make_Defining_Identifier
(Loc
, New_External_Name
(Tname
, 'P'));
7169 Set_Etype
(DT_Ptr
, RTE
(RE_Tag
));
7170 Append_Elmt
(DT_Ptr
, Access_Disp_Table
(Typ
));
7172 -- Minimum decoration
7174 Set_Ekind
(DT_Ptr
, E_Variable
);
7175 Set_Related_Type
(DT_Ptr
, Typ
);
7177 -- Ensure that entities Prim_Ptr and Predef_Prims_Table_Ptr have
7178 -- the decoration required by the backend.
7180 -- Odd comment, the back end cannot require anything not properly
7181 -- documented in einfo. ???
7183 Set_Is_Dispatch_Table_Entity
(RTE
(RE_Prim_Ptr
));
7184 Set_Is_Dispatch_Table_Entity
(RTE
(RE_Predef_Prims_Table_Ptr
));
7186 -- For CPP types there is no need to build the dispatch tables since
7187 -- they are imported from the C++ side. If the CPP type has an IP then
7188 -- we declare now the variable that will store the copy of the C++ tag.
7189 -- If the CPP type is an interface, we need the variable as well because
7190 -- it becomes the pointer to the corresponding secondary table.
7192 if Is_CPP_Class
(Typ
) then
7193 if Has_CPP_Constructors
(Typ
) or else Is_Interface
(Typ
) then
7195 Make_Object_Declaration
(Loc
,
7196 Defining_Identifier
=> DT_Ptr
,
7197 Object_Definition
=> New_Occurrence_Of
(RTE
(RE_Tag
), Loc
),
7199 Unchecked_Convert_To
(RTE
(RE_Tag
),
7200 New_Occurrence_Of
(RTE
(RE_Null_Address
), Loc
))));
7202 Set_Is_Statically_Allocated
(DT_Ptr
,
7203 Is_Library_Level_Tagged_Type
(Typ
));
7209 -- Primary dispatch table containing predefined primitives
7212 Make_Defining_Identifier
(Loc
,
7213 Chars
=> New_External_Name
(Tname
, 'Y'));
7214 Set_Etype
(Predef_Prims_Ptr
, RTE
(RE_Address
));
7215 Append_Elmt
(Predef_Prims_Ptr
, Access_Disp_Table
(Typ
));
7217 -- Import the forward declaration of the Dispatch Table wrapper
7218 -- record (Make_DT will take care of exporting it).
7220 if Building_Static_DT
(Typ
) then
7221 Set_Dispatch_Table_Wrappers
(Typ
, New_Elmt_List
);
7224 Make_Defining_Identifier
(Loc
,
7225 Chars
=> New_External_Name
(Tname
, 'T'));
7227 Import_DT
(Typ
, DT
, Is_Secondary_DT
=> False);
7229 if Has_DT
(Typ
) then
7231 Make_Object_Declaration
(Loc
,
7232 Defining_Identifier
=> DT_Ptr
,
7233 Constant_Present
=> True,
7234 Object_Definition
=>
7235 New_Occurrence_Of
(RTE
(RE_Tag
), Loc
),
7237 Unchecked_Convert_To
(RTE
(RE_Tag
),
7238 Make_Attribute_Reference
(Loc
,
7240 Make_Selected_Component
(Loc
,
7241 Prefix
=> New_Occurrence_Of
(DT
, Loc
),
7244 (RTE_Record_Component
(RE_Prims_Ptr
), Loc
)),
7245 Attribute_Name
=> Name_Address
))));
7247 -- Generate the SCIL node for the previous object declaration
7248 -- because it has a tag initialization.
7250 if Generate_SCIL
then
7252 Make_SCIL_Dispatch_Table_Tag_Init
(Sloc
(Last
(Result
)));
7253 Set_SCIL_Entity
(New_Node
, Typ
);
7254 Set_SCIL_Node
(Last
(Result
), New_Node
);
7258 Make_Object_Declaration
(Loc
,
7259 Defining_Identifier
=> Predef_Prims_Ptr
,
7260 Constant_Present
=> True,
7261 Object_Definition
=>
7262 New_Occurrence_Of
(RTE
(RE_Address
), Loc
),
7264 Make_Attribute_Reference
(Loc
,
7266 Make_Selected_Component
(Loc
,
7267 Prefix
=> New_Occurrence_Of
(DT
, Loc
),
7270 (RTE_Record_Component
(RE_Predef_Prims
), Loc
)),
7271 Attribute_Name
=> Name_Address
)));
7273 -- No dispatch table required
7277 Make_Object_Declaration
(Loc
,
7278 Defining_Identifier
=> DT_Ptr
,
7279 Constant_Present
=> True,
7280 Object_Definition
=>
7281 New_Occurrence_Of
(RTE
(RE_Tag
), Loc
),
7283 Unchecked_Convert_To
(RTE
(RE_Tag
),
7284 Make_Attribute_Reference
(Loc
,
7286 Make_Selected_Component
(Loc
,
7287 Prefix
=> New_Occurrence_Of
(DT
, Loc
),
7290 (RTE_Record_Component
(RE_NDT_Prims_Ptr
),
7292 Attribute_Name
=> Name_Address
))));
7295 Set_Is_True_Constant
(DT_Ptr
);
7296 Set_Is_Statically_Allocated
(DT_Ptr
);
7300 -- 2) Generate the secondary tag entities
7302 -- Collect the components associated with secondary dispatch tables
7304 if Has_Interfaces
(Typ
) then
7305 Collect_Interface_Components
(Typ
, Typ_Comps
);
7307 -- For each interface type we build a unique external name associated
7308 -- with its secondary dispatch table. This name is used to declare an
7309 -- object that references this secondary dispatch table, whose value
7310 -- will be used for the elaboration of Typ objects, and also for the
7311 -- elaboration of objects of types derived from Typ that do not
7312 -- override the primitives of this interface type.
7316 -- Note: The value of Suffix_Index must be in sync with the
7317 -- Suffix_Index values of secondary dispatch tables generated
7320 if Is_CPP_Class
(Typ
) then
7321 AI_Tag_Comp
:= First_Elmt
(Typ_Comps
);
7322 while Present
(AI_Tag_Comp
) loop
7323 Get_Secondary_DT_External_Name
7324 (Typ
, Related_Type
(Node
(AI_Tag_Comp
)), Suffix_Index
);
7325 Typ_Name
:= Name_Find
;
7327 -- Declare variables that will store the copy of the C++
7331 Make_Defining_Identifier
(Loc
,
7332 Chars
=> New_External_Name
(Typ_Name
, 'P'));
7333 Set_Etype
(Iface_DT_Ptr
, RTE
(RE_Interface_Tag
));
7334 Set_Ekind
(Iface_DT_Ptr
, E_Variable
);
7335 Set_Is_Tag
(Iface_DT_Ptr
);
7337 Set_Has_Thunks
(Iface_DT_Ptr
);
7339 (Iface_DT_Ptr
, Related_Type
(Node
(AI_Tag_Comp
)));
7340 Append_Elmt
(Iface_DT_Ptr
, Access_Disp_Table
(Typ
));
7343 Make_Object_Declaration
(Loc
,
7344 Defining_Identifier
=> Iface_DT_Ptr
,
7345 Object_Definition
=> New_Occurrence_Of
7346 (RTE
(RE_Interface_Tag
), Loc
),
7348 Unchecked_Convert_To
(RTE
(RE_Interface_Tag
),
7349 New_Occurrence_Of
(RTE
(RE_Null_Address
), Loc
))));
7351 Set_Is_Statically_Allocated
(Iface_DT_Ptr
,
7352 Is_Library_Level_Tagged_Type
(Typ
));
7354 Next_Elmt
(AI_Tag_Comp
);
7357 -- This is not a CPP_Class type
7360 AI_Tag_Comp
:= First_Elmt
(Typ_Comps
);
7361 while Present
(AI_Tag_Comp
) loop
7362 Get_Secondary_DT_External_Name
7363 (Typ
, Related_Type
(Node
(AI_Tag_Comp
)), Suffix_Index
);
7364 Typ_Name
:= Name_Find
;
7366 if Building_Static_DT
(Typ
) then
7368 Make_Defining_Identifier
(Loc
,
7369 Chars
=> New_External_Name
7370 (Typ_Name
, 'T', Suffix_Index
=> -1));
7372 (Tag_Typ
=> Related_Type
(Node
(AI_Tag_Comp
)),
7374 Is_Secondary_DT
=> True);
7377 -- Secondary dispatch table referencing thunks to user-defined
7378 -- primitives covered by this interface.
7381 Make_Defining_Identifier
(Loc
,
7382 Chars
=> New_External_Name
(Typ_Name
, 'P'));
7383 Set_Etype
(Iface_DT_Ptr
, RTE
(RE_Interface_Tag
));
7384 Set_Ekind
(Iface_DT_Ptr
, E_Constant
);
7385 Set_Is_Tag
(Iface_DT_Ptr
);
7386 Set_Has_Thunks
(Iface_DT_Ptr
);
7387 Set_Is_Statically_Allocated
(Iface_DT_Ptr
,
7388 Is_Library_Level_Tagged_Type
(Typ
));
7389 Set_Is_True_Constant
(Iface_DT_Ptr
);
7391 (Iface_DT_Ptr
, Related_Type
(Node
(AI_Tag_Comp
)));
7392 Append_Elmt
(Iface_DT_Ptr
, Access_Disp_Table
(Typ
));
7394 if Building_Static_DT
(Typ
) then
7396 Make_Object_Declaration
(Loc
,
7397 Defining_Identifier
=> Iface_DT_Ptr
,
7398 Constant_Present
=> True,
7399 Object_Definition
=> New_Occurrence_Of
7400 (RTE
(RE_Interface_Tag
), Loc
),
7402 Unchecked_Convert_To
(RTE
(RE_Interface_Tag
),
7403 Make_Attribute_Reference
(Loc
,
7405 Make_Selected_Component
(Loc
,
7407 New_Occurrence_Of
(Iface_DT
, Loc
),
7410 (RTE_Record_Component
(RE_Prims_Ptr
),
7412 Attribute_Name
=> Name_Address
))));
7415 -- Secondary dispatch table referencing thunks to predefined
7419 Make_Defining_Identifier
(Loc
,
7420 Chars
=> New_External_Name
(Typ_Name
, 'Y'));
7421 Set_Etype
(Iface_DT_Ptr
, RTE
(RE_Address
));
7422 Set_Ekind
(Iface_DT_Ptr
, E_Constant
);
7423 Set_Is_Tag
(Iface_DT_Ptr
);
7424 Set_Has_Thunks
(Iface_DT_Ptr
);
7425 Set_Is_Statically_Allocated
(Iface_DT_Ptr
,
7426 Is_Library_Level_Tagged_Type
(Typ
));
7427 Set_Is_True_Constant
(Iface_DT_Ptr
);
7429 (Iface_DT_Ptr
, Related_Type
(Node
(AI_Tag_Comp
)));
7430 Append_Elmt
(Iface_DT_Ptr
, Access_Disp_Table
(Typ
));
7432 -- Secondary dispatch table referencing user-defined primitives
7433 -- covered by this interface.
7436 Make_Defining_Identifier
(Loc
,
7437 Chars
=> New_External_Name
(Typ_Name
, 'D'));
7438 Set_Etype
(Iface_DT_Ptr
, RTE
(RE_Interface_Tag
));
7439 Set_Ekind
(Iface_DT_Ptr
, E_Constant
);
7440 Set_Is_Tag
(Iface_DT_Ptr
);
7441 Set_Is_Statically_Allocated
(Iface_DT_Ptr
,
7442 Is_Library_Level_Tagged_Type
(Typ
));
7443 Set_Is_True_Constant
(Iface_DT_Ptr
);
7445 (Iface_DT_Ptr
, Related_Type
(Node
(AI_Tag_Comp
)));
7446 Append_Elmt
(Iface_DT_Ptr
, Access_Disp_Table
(Typ
));
7448 -- Secondary dispatch table referencing predefined primitives
7451 Make_Defining_Identifier
(Loc
,
7452 Chars
=> New_External_Name
(Typ_Name
, 'Z'));
7453 Set_Etype
(Iface_DT_Ptr
, RTE
(RE_Address
));
7454 Set_Ekind
(Iface_DT_Ptr
, E_Constant
);
7455 Set_Is_Tag
(Iface_DT_Ptr
);
7456 Set_Is_Statically_Allocated
(Iface_DT_Ptr
,
7457 Is_Library_Level_Tagged_Type
(Typ
));
7458 Set_Is_True_Constant
(Iface_DT_Ptr
);
7460 (Iface_DT_Ptr
, Related_Type
(Node
(AI_Tag_Comp
)));
7461 Append_Elmt
(Iface_DT_Ptr
, Access_Disp_Table
(Typ
));
7463 Next_Elmt
(AI_Tag_Comp
);
7468 -- 3) At the end of Access_Disp_Table, if the type has user-defined
7469 -- primitives, we add the entity of an access type declaration that
7470 -- is used by Build_Get_Prim_Op_Address to expand dispatching calls
7471 -- through the primary dispatch table.
7473 if UI_To_Int
(DT_Entry_Count
(First_Tag_Component
(Typ
))) = 0 then
7474 Analyze_List
(Result
);
7477 -- type Typ_DT is array (1 .. Nb_Prims) of Prim_Ptr;
7478 -- type Typ_DT_Acc is access Typ_DT;
7482 Name_DT_Prims
: constant Name_Id
:=
7483 New_External_Name
(Tname
, 'G');
7484 Name_DT_Prims_Acc
: constant Name_Id
:=
7485 New_External_Name
(Tname
, 'H');
7486 DT_Prims
: constant Entity_Id
:=
7487 Make_Defining_Identifier
(Loc
,
7489 DT_Prims_Acc
: constant Entity_Id
:=
7490 Make_Defining_Identifier
(Loc
,
7494 Make_Full_Type_Declaration
(Loc
,
7495 Defining_Identifier
=> DT_Prims
,
7497 Make_Constrained_Array_Definition
(Loc
,
7498 Discrete_Subtype_Definitions
=> New_List
(
7500 Low_Bound
=> Make_Integer_Literal
(Loc
, 1),
7501 High_Bound
=> Make_Integer_Literal
(Loc
,
7503 (First_Tag_Component
(Typ
))))),
7504 Component_Definition
=>
7505 Make_Component_Definition
(Loc
,
7506 Subtype_Indication
=>
7507 New_Occurrence_Of
(RTE
(RE_Prim_Ptr
), Loc
)))));
7510 Make_Full_Type_Declaration
(Loc
,
7511 Defining_Identifier
=> DT_Prims_Acc
,
7513 Make_Access_To_Object_Definition
(Loc
,
7514 Subtype_Indication
=>
7515 New_Occurrence_Of
(DT_Prims
, Loc
))));
7517 Append_Elmt
(DT_Prims_Acc
, Access_Disp_Table
(Typ
));
7519 -- Analyze the resulting list and suppress the generation of the
7520 -- Init_Proc associated with the above array declaration because
7521 -- this type is never used in object declarations. It is only used
7522 -- to simplify the expansion associated with dispatching calls.
7524 Analyze_List
(Result
);
7525 Set_Suppress_Initialization
(Base_Type
(DT_Prims
));
7527 -- Disable backend optimizations based on assumptions about the
7528 -- aliasing status of objects designated by the access to the
7529 -- dispatch table. Required to handle dispatch tables imported
7532 Set_No_Strict_Aliasing
(Base_Type
(DT_Prims_Acc
));
7534 -- Add the freezing nodes of these declarations; required to avoid
7535 -- generating these freezing nodes in wrong scopes (for example in
7536 -- the IC routine of a derivation of Typ).
7537 -- What is an "IC routine"? Is "init_proc" meant here???
7539 Append_List_To
(Result
, Freeze_Entity
(DT_Prims
, Typ
));
7540 Append_List_To
(Result
, Freeze_Entity
(DT_Prims_Acc
, Typ
));
7542 -- Mark entity of dispatch table. Required by the back end to
7543 -- handle them properly.
7545 Set_Is_Dispatch_Table_Entity
(DT_Prims
);
7549 -- Mark entities of dispatch table. Required by the back end to handle
7552 if Present
(DT
) then
7553 Set_Is_Dispatch_Table_Entity
(DT
);
7554 Set_Is_Dispatch_Table_Entity
(Etype
(DT
));
7557 if Present
(Iface_DT
) then
7558 Set_Is_Dispatch_Table_Entity
(Iface_DT
);
7559 Set_Is_Dispatch_Table_Entity
(Etype
(Iface_DT
));
7562 if Is_CPP_Class
(Root_Type
(Typ
)) then
7563 Set_Ekind
(DT_Ptr
, E_Variable
);
7565 Set_Ekind
(DT_Ptr
, E_Constant
);
7568 Set_Is_Tag
(DT_Ptr
);
7569 Set_Related_Type
(DT_Ptr
, Typ
);
7578 function New_Value
(From
: Node_Id
) return Node_Id
is
7579 Res
: constant Node_Id
:= Duplicate_Subexpr
(From
);
7581 if Is_Access_Type
(Etype
(From
)) then
7583 Make_Explicit_Dereference
(Sloc
(From
),
7590 -----------------------------------
7591 -- Original_View_In_Visible_Part --
7592 -----------------------------------
7594 function Original_View_In_Visible_Part
(Typ
: Entity_Id
) return Boolean is
7595 Scop
: constant Entity_Id
:= Scope
(Typ
);
7598 -- The scope must be a package
7600 if not Is_Package_Or_Generic_Package
(Scop
) then
7604 -- A type with a private declaration has a private view declared in
7605 -- the visible part.
7607 if Has_Private_Declaration
(Typ
) then
7611 return List_Containing
(Parent
(Typ
)) =
7612 Visible_Declarations
(Package_Specification
(Scop
));
7613 end Original_View_In_Visible_Part
;
7619 function Prim_Op_Kind
7621 Typ
: Entity_Id
) return Node_Id
7623 Full_Typ
: Entity_Id
:= Typ
;
7624 Loc
: constant Source_Ptr
:= Sloc
(Prim
);
7625 Prim_Op
: Entity_Id
;
7628 -- Retrieve the original primitive operation
7630 Prim_Op
:= Ultimate_Alias
(Prim
);
7632 if Ekind
(Typ
) = E_Record_Type
7633 and then Present
(Corresponding_Concurrent_Type
(Typ
))
7635 Full_Typ
:= Corresponding_Concurrent_Type
(Typ
);
7638 -- When a private tagged type is completed by a concurrent type,
7639 -- retrieve the full view.
7641 if Is_Private_Type
(Full_Typ
) then
7642 Full_Typ
:= Full_View
(Full_Typ
);
7645 if Ekind
(Prim_Op
) = E_Function
then
7647 -- Protected function
7649 if Ekind
(Full_Typ
) = E_Protected_Type
then
7650 return New_Occurrence_Of
(RTE
(RE_POK_Protected_Function
), Loc
);
7654 elsif Ekind
(Full_Typ
) = E_Task_Type
then
7655 return New_Occurrence_Of
(RTE
(RE_POK_Task_Function
), Loc
);
7660 return New_Occurrence_Of
(RTE
(RE_POK_Function
), Loc
);
7664 pragma Assert
(Ekind
(Prim_Op
) = E_Procedure
);
7666 if Ekind
(Full_Typ
) = E_Protected_Type
then
7670 if Is_Primitive_Wrapper
(Prim_Op
)
7671 and then Ekind
(Wrapped_Entity
(Prim_Op
)) = E_Entry
7673 return New_Occurrence_Of
(RTE
(RE_POK_Protected_Entry
), Loc
);
7675 -- Protected procedure
7679 New_Occurrence_Of
(RTE
(RE_POK_Protected_Procedure
), Loc
);
7682 elsif Ekind
(Full_Typ
) = E_Task_Type
then
7686 if Is_Primitive_Wrapper
(Prim_Op
)
7687 and then Ekind
(Wrapped_Entity
(Prim_Op
)) = E_Entry
7689 return New_Occurrence_Of
(RTE
(RE_POK_Task_Entry
), Loc
);
7691 -- Task "procedure". These are the internally Expander-generated
7692 -- procedures (task body for instance).
7695 return New_Occurrence_Of
(RTE
(RE_POK_Task_Procedure
), Loc
);
7698 -- Regular procedure
7701 return New_Occurrence_Of
(RTE
(RE_POK_Procedure
), Loc
);
7706 ------------------------
7707 -- Register_Primitive --
7708 ------------------------
7710 function Register_Primitive
7712 Prim
: Entity_Id
) return List_Id
7715 Iface_Prim
: Entity_Id
;
7716 Iface_Typ
: Entity_Id
;
7717 Iface_DT_Ptr
: Entity_Id
;
7718 Iface_DT_Elmt
: Elmt_Id
;
7719 L
: constant List_Id
:= New_List
;
7722 Tag_Typ
: Entity_Id
;
7723 Thunk_Id
: Entity_Id
;
7724 Thunk_Code
: Node_Id
;
7727 pragma Assert
(not Restriction_Active
(No_Dispatching_Calls
));
7728 pragma Assert
(VM_Target
= No_VM
);
7730 -- Do not register in the dispatch table eliminated primitives
7732 if not RTE_Available
(RE_Tag
)
7733 or else Is_Eliminated
(Ultimate_Alias
(Prim
))
7738 if not Present
(Interface_Alias
(Prim
)) then
7739 Tag_Typ
:= Scope
(DTC_Entity
(Prim
));
7740 Pos
:= DT_Position
(Prim
);
7741 Tag
:= First_Tag_Component
(Tag_Typ
);
7743 if Is_Predefined_Dispatching_Operation
(Prim
)
7744 or else Is_Predefined_Dispatching_Alias
(Prim
)
7747 Node
(Next_Elmt
(First_Elmt
(Access_Disp_Table
(Tag_Typ
))));
7750 Build_Set_Predefined_Prim_Op_Address
(Loc
,
7751 Tag_Node
=> New_Occurrence_Of
(DT_Ptr
, Loc
),
7754 Unchecked_Convert_To
(RTE
(RE_Prim_Ptr
),
7755 Make_Attribute_Reference
(Loc
,
7756 Prefix
=> New_Occurrence_Of
(Prim
, Loc
),
7757 Attribute_Name
=> Name_Unrestricted_Access
))));
7759 -- Register copy of the pointer to the 'size primitive in the TSD
7761 if Chars
(Prim
) = Name_uSize
7762 and then RTE_Record_Component_Available
(RE_Size_Func
)
7764 DT_Ptr
:= Node
(First_Elmt
(Access_Disp_Table
(Tag_Typ
)));
7766 Build_Set_Size_Function
(Loc
,
7767 Tag_Node
=> New_Occurrence_Of
(DT_Ptr
, Loc
),
7768 Size_Func
=> Prim
));
7772 pragma Assert
(Pos
/= Uint_0
and then Pos
<= DT_Entry_Count
(Tag
));
7774 -- Skip registration of primitives located in the C++ part of the
7775 -- dispatch table. Their slot is set by the IC routine.
7777 if not Is_CPP_Class
(Root_Type
(Tag_Typ
))
7778 or else Pos
> CPP_Num_Prims
(Tag_Typ
)
7780 DT_Ptr
:= Node
(First_Elmt
(Access_Disp_Table
(Tag_Typ
)));
7782 Build_Set_Prim_Op_Address
(Loc
,
7784 Tag_Node
=> New_Occurrence_Of
(DT_Ptr
, Loc
),
7787 Unchecked_Convert_To
(RTE
(RE_Prim_Ptr
),
7788 Make_Attribute_Reference
(Loc
,
7789 Prefix
=> New_Occurrence_Of
(Prim
, Loc
),
7790 Attribute_Name
=> Name_Unrestricted_Access
))));
7794 -- Ada 2005 (AI-251): Primitive associated with an interface type
7795 -- Generate the code of the thunk only if the interface type is not an
7796 -- immediate ancestor of Typ; otherwise the dispatch table associated
7797 -- with the interface is the primary dispatch table and we have nothing
7801 Tag_Typ
:= Find_Dispatching_Type
(Alias
(Prim
));
7802 Iface_Typ
:= Find_Dispatching_Type
(Interface_Alias
(Prim
));
7804 pragma Assert
(Is_Interface
(Iface_Typ
));
7806 -- No action needed for interfaces that are ancestors of Typ because
7807 -- their primitives are located in the primary dispatch table.
7809 if Is_Ancestor
(Iface_Typ
, Tag_Typ
, Use_Full_View
=> True) then
7812 -- No action needed for primitives located in the C++ part of the
7813 -- dispatch table. Their slot is set by the IC routine.
7815 elsif Is_CPP_Class
(Root_Type
(Tag_Typ
))
7816 and then DT_Position
(Alias
(Prim
)) <= CPP_Num_Prims
(Tag_Typ
)
7817 and then not Is_Predefined_Dispatching_Operation
(Prim
)
7818 and then not Is_Predefined_Dispatching_Alias
(Prim
)
7823 Expand_Interface_Thunk
(Prim
, Thunk_Id
, Thunk_Code
);
7825 if not Is_Ancestor
(Iface_Typ
, Tag_Typ
, Use_Full_View
=> True)
7826 and then Present
(Thunk_Code
)
7828 -- Generate the code necessary to fill the appropriate entry of
7829 -- the secondary dispatch table of Prim's controlling type with
7830 -- Thunk_Id's address.
7832 Iface_DT_Elmt
:= Find_Interface_ADT
(Tag_Typ
, Iface_Typ
);
7833 Iface_DT_Ptr
:= Node
(Iface_DT_Elmt
);
7834 pragma Assert
(Has_Thunks
(Iface_DT_Ptr
));
7836 Iface_Prim
:= Interface_Alias
(Prim
);
7837 Pos
:= DT_Position
(Iface_Prim
);
7838 Tag
:= First_Tag_Component
(Iface_Typ
);
7840 Prepend_To
(L
, Thunk_Code
);
7842 if Is_Predefined_Dispatching_Operation
(Prim
)
7843 or else Is_Predefined_Dispatching_Alias
(Prim
)
7846 Build_Set_Predefined_Prim_Op_Address
(Loc
,
7848 New_Occurrence_Of
(Node
(Next_Elmt
(Iface_DT_Elmt
)), Loc
),
7851 Unchecked_Convert_To
(RTE
(RE_Prim_Ptr
),
7852 Make_Attribute_Reference
(Loc
,
7853 Prefix
=> New_Occurrence_Of
(Thunk_Id
, Loc
),
7854 Attribute_Name
=> Name_Unrestricted_Access
))));
7856 Next_Elmt
(Iface_DT_Elmt
);
7857 Next_Elmt
(Iface_DT_Elmt
);
7858 Iface_DT_Ptr
:= Node
(Iface_DT_Elmt
);
7859 pragma Assert
(not Has_Thunks
(Iface_DT_Ptr
));
7862 Build_Set_Predefined_Prim_Op_Address
(Loc
,
7864 New_Occurrence_Of
(Node
(Next_Elmt
(Iface_DT_Elmt
)), Loc
),
7867 Unchecked_Convert_To
(RTE
(RE_Prim_Ptr
),
7868 Make_Attribute_Reference
(Loc
,
7870 New_Occurrence_Of
(Alias
(Prim
), Loc
),
7871 Attribute_Name
=> Name_Unrestricted_Access
))));
7874 pragma Assert
(Pos
/= Uint_0
7875 and then Pos
<= DT_Entry_Count
(Tag
));
7878 Build_Set_Prim_Op_Address
(Loc
,
7880 Tag_Node
=> New_Occurrence_Of
(Iface_DT_Ptr
, Loc
),
7883 Unchecked_Convert_To
(RTE
(RE_Prim_Ptr
),
7884 Make_Attribute_Reference
(Loc
,
7885 Prefix
=> New_Occurrence_Of
(Thunk_Id
, Loc
),
7886 Attribute_Name
=> Name_Unrestricted_Access
))));
7888 Next_Elmt
(Iface_DT_Elmt
);
7889 Next_Elmt
(Iface_DT_Elmt
);
7890 Iface_DT_Ptr
:= Node
(Iface_DT_Elmt
);
7891 pragma Assert
(not Has_Thunks
(Iface_DT_Ptr
));
7894 Build_Set_Prim_Op_Address
(Loc
,
7896 Tag_Node
=> New_Occurrence_Of
(Iface_DT_Ptr
, Loc
),
7899 Unchecked_Convert_To
(RTE
(RE_Prim_Ptr
),
7900 Make_Attribute_Reference
(Loc
,
7902 New_Occurrence_Of
(Alias
(Prim
), Loc
),
7903 Attribute_Name
=> Name_Unrestricted_Access
))));
7910 end Register_Primitive
;
7912 -------------------------
7913 -- Set_All_DT_Position --
7914 -------------------------
7916 procedure Set_All_DT_Position
(Typ
: Entity_Id
) is
7918 function In_Predef_Prims_DT
(Prim
: Entity_Id
) return Boolean;
7919 -- Returns True if Prim is located in the dispatch table of
7920 -- predefined primitives
7922 procedure Validate_Position
(Prim
: Entity_Id
);
7923 -- Check that the position assigned to Prim is completely safe
7924 -- (it has not been assigned to a previously defined primitive
7925 -- operation of Typ)
7927 ------------------------
7928 -- In_Predef_Prims_DT --
7929 ------------------------
7931 function In_Predef_Prims_DT
(Prim
: Entity_Id
) return Boolean is
7935 -- Predefined primitives
7937 if Is_Predefined_Dispatching_Operation
(Prim
) then
7940 -- Renamings of predefined primitives
7942 elsif Present
(Alias
(Prim
))
7943 and then Is_Predefined_Dispatching_Operation
(Ultimate_Alias
(Prim
))
7945 if Chars
(Ultimate_Alias
(Prim
)) /= Name_Op_Eq
then
7948 -- User-defined renamings of predefined equality have their own
7949 -- slot in the primary dispatch table
7953 while Present
(Alias
(E
)) loop
7954 if Comes_From_Source
(E
) then
7961 return not Comes_From_Source
(E
);
7964 -- User-defined primitives
7969 end In_Predef_Prims_DT
;
7971 -----------------------
7972 -- Validate_Position --
7973 -----------------------
7975 procedure Validate_Position
(Prim
: Entity_Id
) is
7980 -- Aliased primitives are safe
7982 if Present
(Alias
(Prim
)) then
7986 Op_Elmt
:= First_Elmt
(Primitive_Operations
(Typ
));
7987 while Present
(Op_Elmt
) loop
7988 Op
:= Node
(Op_Elmt
);
7990 -- No need to check against itself
7995 -- Primitive operations covering abstract interfaces are
7998 elsif Present
(Interface_Alias
(Op
)) then
8001 -- Predefined dispatching operations are completely safe. They
8002 -- are allocated at fixed positions in a separate table.
8004 elsif Is_Predefined_Dispatching_Operation
(Op
)
8005 or else Is_Predefined_Dispatching_Alias
(Op
)
8009 -- Aliased subprograms are safe
8011 elsif Present
(Alias
(Op
)) then
8014 elsif DT_Position
(Op
) = DT_Position
(Prim
)
8015 and then not Is_Predefined_Dispatching_Operation
(Op
)
8016 and then not Is_Predefined_Dispatching_Operation
(Prim
)
8017 and then not Is_Predefined_Dispatching_Alias
(Op
)
8018 and then not Is_Predefined_Dispatching_Alias
(Prim
)
8021 -- Handle aliased subprograms
8030 if Present
(Overridden_Operation
(Op_1
)) then
8031 Op_1
:= Overridden_Operation
(Op_1
);
8032 elsif Present
(Alias
(Op_1
)) then
8033 Op_1
:= Alias
(Op_1
);
8041 if Present
(Overridden_Operation
(Op_2
)) then
8042 Op_2
:= Overridden_Operation
(Op_2
);
8043 elsif Present
(Alias
(Op_2
)) then
8044 Op_2
:= Alias
(Op_2
);
8050 if Op_1
/= Op_2
then
8051 raise Program_Error
;
8056 Next_Elmt
(Op_Elmt
);
8058 end Validate_Position
;
8062 Parent_Typ
: constant Entity_Id
:= Etype
(Typ
);
8063 First_Prim
: constant Elmt_Id
:= First_Elmt
(Primitive_Operations
(Typ
));
8064 The_Tag
: constant Entity_Id
:= First_Tag_Component
(Typ
);
8066 Adjusted
: Boolean := False;
8067 Finalized
: Boolean := False;
8073 Prim_Elmt
: Elmt_Id
;
8075 -- Start of processing for Set_All_DT_Position
8078 pragma Assert
(Present
(First_Tag_Component
(Typ
)));
8080 -- Set the DT_Position for each primitive operation. Perform some sanity
8081 -- checks to avoid building inconsistent dispatch tables.
8083 -- First stage: Set the DTC entity of all the primitive operations. This
8084 -- is required to properly read the DT_Position attribute in the latter
8087 Prim_Elmt
:= First_Prim
;
8089 while Present
(Prim_Elmt
) loop
8090 Prim
:= Node
(Prim_Elmt
);
8092 -- Predefined primitives have a separate dispatch table
8094 if not In_Predef_Prims_DT
(Prim
) then
8095 Count_Prim
:= Count_Prim
+ 1;
8098 Set_DTC_Entity_Value
(Typ
, Prim
);
8100 -- Clear any previous value of the DT_Position attribute. In this
8101 -- way we ensure that the final position of all the primitives is
8102 -- established by the following stages of this algorithm.
8104 Set_DT_Position
(Prim
, No_Uint
);
8106 Next_Elmt
(Prim_Elmt
);
8110 Fixed_Prim
: array (Int
range 0 .. Count_Prim
) of Boolean :=
8115 procedure Handle_Inherited_Private_Subprograms
(Typ
: Entity_Id
);
8116 -- Called if Typ is declared in a nested package or a public child
8117 -- package to handle inherited primitives that were inherited by Typ
8118 -- in the visible part, but whose declaration was deferred because
8119 -- the parent operation was private and not visible at that point.
8121 procedure Set_Fixed_Prim
(Pos
: Nat
);
8122 -- Sets to true an element of the Fixed_Prim table to indicate
8123 -- that this entry of the dispatch table of Typ is occupied.
8125 ------------------------------------------
8126 -- Handle_Inherited_Private_Subprograms --
8127 ------------------------------------------
8129 procedure Handle_Inherited_Private_Subprograms
(Typ
: Entity_Id
) is
8132 Op_Elmt_2
: Elmt_Id
;
8133 Prim_Op
: Entity_Id
;
8134 Parent_Subp
: Entity_Id
;
8137 Op_List
:= Primitive_Operations
(Typ
);
8139 Op_Elmt
:= First_Elmt
(Op_List
);
8140 while Present
(Op_Elmt
) loop
8141 Prim_Op
:= Node
(Op_Elmt
);
8143 -- Search primitives that are implicit operations with an
8144 -- internal name whose parent operation has a normal name.
8146 if Present
(Alias
(Prim_Op
))
8147 and then Find_Dispatching_Type
(Alias
(Prim_Op
)) /= Typ
8148 and then not Comes_From_Source
(Prim_Op
)
8149 and then Is_Internal_Name
(Chars
(Prim_Op
))
8150 and then not Is_Internal_Name
(Chars
(Alias
(Prim_Op
)))
8152 Parent_Subp
:= Alias
(Prim_Op
);
8154 -- Check if the type has an explicit overriding for this
8157 Op_Elmt_2
:= Next_Elmt
(Op_Elmt
);
8158 while Present
(Op_Elmt_2
) loop
8159 if Chars
(Node
(Op_Elmt_2
)) = Chars
(Parent_Subp
)
8160 and then Type_Conformant
(Prim_Op
, Node
(Op_Elmt_2
))
8162 Set_DT_Position
(Prim_Op
, DT_Position
(Parent_Subp
));
8163 Set_DT_Position
(Node
(Op_Elmt_2
),
8164 DT_Position
(Parent_Subp
));
8165 Set_Fixed_Prim
(UI_To_Int
(DT_Position
(Prim_Op
)));
8167 goto Next_Primitive
;
8170 Next_Elmt
(Op_Elmt_2
);
8175 Next_Elmt
(Op_Elmt
);
8177 end Handle_Inherited_Private_Subprograms
;
8179 --------------------
8180 -- Set_Fixed_Prim --
8181 --------------------
8183 procedure Set_Fixed_Prim
(Pos
: Nat
) is
8185 pragma Assert
(Pos
<= Count_Prim
);
8186 Fixed_Prim
(Pos
) := True;
8188 when Constraint_Error
=>
8189 raise Program_Error
;
8193 -- In case of nested packages and public child package it may be
8194 -- necessary a special management on inherited subprograms so that
8195 -- the dispatch table is properly filled.
8197 if Ekind
(Scope
(Scope
(Typ
))) = E_Package
8198 and then Scope
(Scope
(Typ
)) /= Standard_Standard
8199 and then ((Is_Derived_Type
(Typ
) and then not Is_Private_Type
(Typ
))
8201 (Nkind
(Parent
(Typ
)) = N_Private_Extension_Declaration
8202 and then Is_Generic_Type
(Typ
)))
8203 and then In_Open_Scopes
(Scope
(Etype
(Typ
)))
8204 and then Is_Base_Type
(Typ
)
8206 Handle_Inherited_Private_Subprograms
(Typ
);
8209 -- Second stage: Register fixed entries
8212 Prim_Elmt
:= First_Prim
;
8213 while Present
(Prim_Elmt
) loop
8214 Prim
:= Node
(Prim_Elmt
);
8216 -- Predefined primitives have a separate table and all its
8217 -- entries are at predefined fixed positions.
8219 if In_Predef_Prims_DT
(Prim
) then
8220 if Is_Predefined_Dispatching_Operation
(Prim
) then
8221 Set_DT_Position
(Prim
, Default_Prim_Op_Position
(Prim
));
8223 else pragma Assert
(Present
(Alias
(Prim
)));
8224 Set_DT_Position
(Prim
,
8225 Default_Prim_Op_Position
(Ultimate_Alias
(Prim
)));
8228 -- Overriding primitives of ancestor abstract interfaces
8230 elsif Present
(Interface_Alias
(Prim
))
8231 and then Is_Ancestor
8232 (Find_Dispatching_Type
(Interface_Alias
(Prim
)), Typ
,
8233 Use_Full_View
=> True)
8235 pragma Assert
(DT_Position
(Prim
) = No_Uint
8236 and then Present
(DTC_Entity
(Interface_Alias
(Prim
))));
8238 E
:= Interface_Alias
(Prim
);
8239 Set_DT_Position
(Prim
, DT_Position
(E
));
8242 (DT_Position
(Alias
(Prim
)) = No_Uint
8243 or else DT_Position
(Alias
(Prim
)) = DT_Position
(E
));
8244 Set_DT_Position
(Alias
(Prim
), DT_Position
(E
));
8245 Set_Fixed_Prim
(UI_To_Int
(DT_Position
(Prim
)));
8247 -- Overriding primitives must use the same entry as the
8248 -- overridden primitive.
8250 elsif not Present
(Interface_Alias
(Prim
))
8251 and then Present
(Alias
(Prim
))
8252 and then Chars
(Prim
) = Chars
(Alias
(Prim
))
8253 and then Find_Dispatching_Type
(Alias
(Prim
)) /= Typ
8254 and then Is_Ancestor
8255 (Find_Dispatching_Type
(Alias
(Prim
)), Typ
,
8256 Use_Full_View
=> True)
8257 and then Present
(DTC_Entity
(Alias
(Prim
)))
8260 Set_DT_Position
(Prim
, DT_Position
(E
));
8262 if not Is_Predefined_Dispatching_Alias
(E
) then
8263 Set_Fixed_Prim
(UI_To_Int
(DT_Position
(E
)));
8267 Next_Elmt
(Prim_Elmt
);
8270 -- Third stage: Fix the position of all the new primitives.
8271 -- Entries associated with primitives covering interfaces
8272 -- are handled in a latter round.
8274 Prim_Elmt
:= First_Prim
;
8275 while Present
(Prim_Elmt
) loop
8276 Prim
:= Node
(Prim_Elmt
);
8278 -- Skip primitives previously set entries
8280 if DT_Position
(Prim
) /= No_Uint
then
8283 -- Primitives covering interface primitives are handled later
8285 elsif Present
(Interface_Alias
(Prim
)) then
8289 -- Take the next available position in the DT
8292 Nb_Prim
:= Nb_Prim
+ 1;
8293 pragma Assert
(Nb_Prim
<= Count_Prim
);
8294 exit when not Fixed_Prim
(Nb_Prim
);
8297 Set_DT_Position
(Prim
, UI_From_Int
(Nb_Prim
));
8298 Set_Fixed_Prim
(Nb_Prim
);
8301 Next_Elmt
(Prim_Elmt
);
8305 -- Fourth stage: Complete the decoration of primitives covering
8306 -- interfaces (that is, propagate the DT_Position attribute
8307 -- from the aliased primitive)
8309 Prim_Elmt
:= First_Prim
;
8310 while Present
(Prim_Elmt
) loop
8311 Prim
:= Node
(Prim_Elmt
);
8313 if DT_Position
(Prim
) = No_Uint
8314 and then Present
(Interface_Alias
(Prim
))
8316 pragma Assert
(Present
(Alias
(Prim
))
8317 and then Find_Dispatching_Type
(Alias
(Prim
)) = Typ
);
8319 -- Check if this entry will be placed in the primary DT
8322 (Find_Dispatching_Type
(Interface_Alias
(Prim
)), Typ
,
8323 Use_Full_View
=> True)
8325 pragma Assert
(DT_Position
(Alias
(Prim
)) /= No_Uint
);
8326 Set_DT_Position
(Prim
, DT_Position
(Alias
(Prim
)));
8328 -- Otherwise it will be placed in the secondary DT
8332 (DT_Position
(Interface_Alias
(Prim
)) /= No_Uint
);
8333 Set_DT_Position
(Prim
,
8334 DT_Position
(Interface_Alias
(Prim
)));
8338 Next_Elmt
(Prim_Elmt
);
8341 -- Generate listing showing the contents of the dispatch tables.
8342 -- This action is done before some further static checks because
8343 -- in case of critical errors caused by a wrong dispatch table
8344 -- we need to see the contents of such table.
8346 if Debug_Flag_ZZ
then
8350 -- Final stage: Ensure that the table is correct plus some further
8351 -- verifications concerning the primitives.
8353 Prim_Elmt
:= First_Prim
;
8355 while Present
(Prim_Elmt
) loop
8356 Prim
:= Node
(Prim_Elmt
);
8358 -- At this point all the primitives MUST have a position
8359 -- in the dispatch table.
8361 if DT_Position
(Prim
) = No_Uint
then
8362 raise Program_Error
;
8365 -- Calculate real size of the dispatch table
8367 if not In_Predef_Prims_DT
(Prim
)
8368 and then UI_To_Int
(DT_Position
(Prim
)) > DT_Length
8370 DT_Length
:= UI_To_Int
(DT_Position
(Prim
));
8373 -- Ensure that the assigned position to non-predefined
8374 -- dispatching operations in the dispatch table is correct.
8376 if not Is_Predefined_Dispatching_Operation
(Prim
)
8377 and then not Is_Predefined_Dispatching_Alias
(Prim
)
8379 Validate_Position
(Prim
);
8382 if Chars
(Prim
) = Name_Finalize
then
8386 if Chars
(Prim
) = Name_Adjust
then
8390 -- An abstract operation cannot be declared in the private part for a
8391 -- visible abstract type, because it can't be overridden outside this
8392 -- package hierarchy. For explicit declarations this is checked at
8393 -- the point of declaration, but for inherited operations it must be
8394 -- done when building the dispatch table.
8396 -- Ada 2005 (AI-251): Primitives associated with interfaces are
8397 -- excluded from this check because interfaces must be visible in
8398 -- the public and private part (RM 7.3 (7.3/2))
8400 -- We disable this check in Relaxed_RM_Semantics mode, to
8401 -- accommodate legacy Ada code.
8403 if not Relaxed_RM_Semantics
8404 and then Is_Abstract_Type
(Typ
)
8405 and then Is_Abstract_Subprogram
(Prim
)
8406 and then Present
(Alias
(Prim
))
8407 and then not Is_Interface
8408 (Find_Dispatching_Type
(Ultimate_Alias
(Prim
)))
8409 and then not Present
(Interface_Alias
(Prim
))
8410 and then Is_Derived_Type
(Typ
)
8411 and then In_Private_Part
(Current_Scope
)
8413 List_Containing
(Parent
(Prim
)) =
8414 Private_Declarations
(Package_Specification
(Current_Scope
))
8415 and then Original_View_In_Visible_Part
(Typ
)
8417 -- We exclude Input and Output stream operations because
8418 -- Limited_Controlled inherits useless Input and Output
8419 -- stream operations from Root_Controlled, which can
8420 -- never be overridden.
8422 if not Is_TSS
(Prim
, TSS_Stream_Input
)
8424 not Is_TSS
(Prim
, TSS_Stream_Output
)
8427 ("abstract inherited private operation&" &
8428 " must be overridden (RM 3.9.3(10))",
8429 Parent
(Typ
), Prim
);
8433 Next_Elmt
(Prim_Elmt
);
8438 if Is_Controlled
(Typ
) then
8439 if not Finalized
then
8441 ("controlled type has no explicit Finalize method??", Typ
);
8443 elsif not Adjusted
then
8445 ("controlled type has no explicit Adjust method??", Typ
);
8449 -- Set the final size of the Dispatch Table
8451 Set_DT_Entry_Count
(The_Tag
, UI_From_Int
(DT_Length
));
8453 -- The derived type must have at least as many components as its parent
8454 -- (for root types Etype points to itself and the test cannot fail).
8456 if DT_Entry_Count
(The_Tag
) <
8457 DT_Entry_Count
(First_Tag_Component
(Parent_Typ
))
8459 raise Program_Error
;
8461 end Set_All_DT_Position
;
8463 --------------------------
8464 -- Set_CPP_Constructors --
8465 --------------------------
8467 procedure Set_CPP_Constructors
(Typ
: Entity_Id
) is
8469 function Gen_Parameters_Profile
(E
: Entity_Id
) return List_Id
;
8470 -- Duplicate the parameters profile of the imported C++ constructor
8471 -- adding an access to the object as an additional parameter.
8473 function Gen_Parameters_Profile
(E
: Entity_Id
) return List_Id
is
8474 Loc
: constant Source_Ptr
:= Sloc
(E
);
8481 Make_Parameter_Specification
(Loc
,
8482 Defining_Identifier
=>
8483 Make_Defining_Identifier
(Loc
, Name_uInit
),
8484 Parameter_Type
=> New_Occurrence_Of
(Typ
, Loc
)));
8486 if Present
(Parameter_Specifications
(Parent
(E
))) then
8487 P
:= First
(Parameter_Specifications
(Parent
(E
)));
8488 while Present
(P
) loop
8490 Make_Parameter_Specification
(Loc
,
8491 Defining_Identifier
=>
8492 Make_Defining_Identifier
(Loc
,
8493 Chars
=> Chars
(Defining_Identifier
(P
))),
8494 Parameter_Type
=> New_Copy_Tree
(Parameter_Type
(P
)),
8495 Expression
=> New_Copy_Tree
(Expression
(P
))));
8501 end Gen_Parameters_Profile
;
8507 Found
: Boolean := False;
8513 Covers_Default_Constructor
: Entity_Id
:= Empty
;
8515 -- Start of processing for Set_CPP_Constructor
8518 pragma Assert
(Is_CPP_Class
(Typ
));
8520 -- Look for the constructor entities
8522 E
:= Next_Entity
(Typ
);
8523 while Present
(E
) loop
8524 if Ekind
(E
) = E_Function
8525 and then Is_Constructor
(E
)
8529 Parms
:= Gen_Parameters_Profile
(E
);
8531 Make_Defining_Identifier
(Loc
,
8532 Chars
=> Make_Init_Proc_Name
(Typ
));
8534 -- Case 1: Constructor of non-tagged type
8536 -- If the C++ class has no virtual methods then the matching Ada
8537 -- type is a non-tagged record type. In such case there is no need
8538 -- to generate a wrapper of the C++ constructor because the _tag
8539 -- component is not available.
8541 if not Is_Tagged_Type
(Typ
) then
8543 (Make_Subprogram_Declaration
(Loc
,
8545 Make_Procedure_Specification
(Loc
,
8546 Defining_Unit_Name
=> IP
,
8547 Parameter_Specifications
=> Parms
)));
8549 Set_Init_Proc
(Typ
, IP
);
8550 Set_Is_Imported
(IP
);
8551 Set_Is_Constructor
(IP
);
8552 Set_Interface_Name
(IP
, Interface_Name
(E
));
8553 Set_Convention
(IP
, Convention_CPP
);
8555 Set_Has_Completion
(IP
);
8557 -- Case 2: Constructor of a tagged type
8559 -- In this case we generate the IP as a wrapper of the the
8560 -- C++ constructor because IP must also save copy of the _tag
8561 -- generated in the C++ side. The copy of the _tag is used by
8562 -- Build_CPP_Init_Procedure to elaborate derivations of C++ types.
8565 -- procedure IP (_init : Typ; ...) is
8566 -- procedure ConstructorP (_init : Typ; ...);
8567 -- pragma Import (ConstructorP);
8569 -- ConstructorP (_init, ...);
8570 -- if Typ._tag = null then
8571 -- Typ._tag := _init._tag;
8577 Body_Stmts
: constant List_Id
:= New_List
;
8578 Constructor_Id
: Entity_Id
;
8579 Constructor_Decl_Node
: Node_Id
;
8580 Init_Tags_List
: List_Id
;
8583 Constructor_Id
:= Make_Temporary
(Loc
, 'P');
8585 Constructor_Decl_Node
:=
8586 Make_Subprogram_Declaration
(Loc
,
8587 Make_Procedure_Specification
(Loc
,
8588 Defining_Unit_Name
=> Constructor_Id
,
8589 Parameter_Specifications
=> Parms
));
8591 Set_Is_Imported
(Constructor_Id
);
8592 Set_Is_Constructor
(Constructor_Id
);
8593 Set_Interface_Name
(Constructor_Id
, Interface_Name
(E
));
8594 Set_Convention
(Constructor_Id
, Convention_CPP
);
8595 Set_Is_Public
(Constructor_Id
);
8596 Set_Has_Completion
(Constructor_Id
);
8598 -- Build the init procedure as a wrapper of this constructor
8600 Parms
:= Gen_Parameters_Profile
(E
);
8602 -- Invoke the C++ constructor
8605 Actuals
: constant List_Id
:= New_List
;
8609 while Present
(P
) loop
8611 New_Occurrence_Of
(Defining_Identifier
(P
), Loc
));
8615 Append_To
(Body_Stmts
,
8616 Make_Procedure_Call_Statement
(Loc
,
8617 Name
=> New_Occurrence_Of
(Constructor_Id
, Loc
),
8618 Parameter_Associations
=> Actuals
));
8621 -- Initialize copies of C++ primary and secondary tags
8623 Init_Tags_List
:= New_List
;
8630 Tag_Elmt
:= First_Elmt
(Access_Disp_Table
(Typ
));
8631 Tag_Comp
:= First_Tag_Component
(Typ
);
8633 while Present
(Tag_Elmt
)
8634 and then Is_Tag
(Node
(Tag_Elmt
))
8636 -- Skip the following assertion with primary tags
8637 -- because Related_Type is not set on primary tag
8641 (Tag_Comp
= First_Tag_Component
(Typ
)
8642 or else Related_Type
(Node
(Tag_Elmt
))
8643 = Related_Type
(Tag_Comp
));
8645 Append_To
(Init_Tags_List
,
8646 Make_Assignment_Statement
(Loc
,
8648 New_Occurrence_Of
(Node
(Tag_Elmt
), Loc
),
8650 Make_Selected_Component
(Loc
,
8652 Make_Identifier
(Loc
, Name_uInit
),
8654 New_Occurrence_Of
(Tag_Comp
, Loc
))));
8656 Tag_Comp
:= Next_Tag_Component
(Tag_Comp
);
8657 Next_Elmt
(Tag_Elmt
);
8661 Append_To
(Body_Stmts
,
8662 Make_If_Statement
(Loc
,
8667 (Node
(First_Elmt
(Access_Disp_Table
(Typ
))),
8670 Unchecked_Convert_To
(RTE
(RE_Tag
),
8671 New_Occurrence_Of
(RTE
(RE_Null_Address
), Loc
))),
8672 Then_Statements
=> Init_Tags_List
));
8675 Make_Subprogram_Body
(Loc
,
8677 Make_Procedure_Specification
(Loc
,
8678 Defining_Unit_Name
=> IP
,
8679 Parameter_Specifications
=> Parms
),
8680 Declarations
=> New_List
(Constructor_Decl_Node
),
8681 Handled_Statement_Sequence
=>
8682 Make_Handled_Sequence_Of_Statements
(Loc
,
8683 Statements
=> Body_Stmts
,
8684 Exception_Handlers
=> No_List
));
8686 Discard_Node
(IP_Body
);
8687 Set_Init_Proc
(Typ
, IP
);
8691 -- If this constructor has parameters and all its parameters
8692 -- have defaults then it covers the default constructor. The
8693 -- semantic analyzer ensures that only one constructor with
8694 -- defaults covers the default constructor.
8696 if Present
(Parameter_Specifications
(Parent
(E
)))
8697 and then Needs_No_Actuals
(E
)
8699 Covers_Default_Constructor
:= IP
;
8706 -- If there are no constructors, mark the type as abstract since we
8707 -- won't be able to declare objects of that type.
8710 Set_Is_Abstract_Type
(Typ
);
8713 -- Handle constructor that has all its parameters with defaults and
8714 -- hence it covers the default constructor. We generate a wrapper IP
8715 -- which calls the covering constructor.
8717 if Present
(Covers_Default_Constructor
) then
8719 Body_Stmts
: List_Id
;
8722 Loc
:= Sloc
(Covers_Default_Constructor
);
8724 Body_Stmts
:= New_List
(
8725 Make_Procedure_Call_Statement
(Loc
,
8727 New_Occurrence_Of
(Covers_Default_Constructor
, Loc
),
8728 Parameter_Associations
=> New_List
(
8729 Make_Identifier
(Loc
, Name_uInit
))));
8731 IP
:= Make_Defining_Identifier
(Loc
, Make_Init_Proc_Name
(Typ
));
8734 Make_Subprogram_Body
(Loc
,
8736 Make_Procedure_Specification
(Loc
,
8737 Defining_Unit_Name
=> IP
,
8738 Parameter_Specifications
=> New_List
(
8739 Make_Parameter_Specification
(Loc
,
8740 Defining_Identifier
=>
8741 Make_Defining_Identifier
(Loc
, Name_uInit
),
8742 Parameter_Type
=> New_Occurrence_Of
(Typ
, Loc
)))),
8744 Declarations
=> No_List
,
8746 Handled_Statement_Sequence
=>
8747 Make_Handled_Sequence_Of_Statements
(Loc
,
8748 Statements
=> Body_Stmts
,
8749 Exception_Handlers
=> No_List
));
8751 Discard_Node
(IP_Body
);
8752 Set_Init_Proc
(Typ
, IP
);
8756 -- If the CPP type has constructors then it must import also the default
8757 -- C++ constructor. It is required for default initialization of objects
8758 -- of the type. It is also required to elaborate objects of Ada types
8759 -- that are defined as derivations of this CPP type.
8761 if Has_CPP_Constructors
(Typ
)
8762 and then No
(Init_Proc
(Typ
))
8764 Error_Msg_N
("??default constructor must be imported from C++", Typ
);
8766 end Set_CPP_Constructors
;
8768 --------------------------
8769 -- Set_DTC_Entity_Value --
8770 --------------------------
8772 procedure Set_DTC_Entity_Value
8773 (Tagged_Type
: Entity_Id
;
8777 if Present
(Interface_Alias
(Prim
))
8778 and then Is_Interface
8779 (Find_Dispatching_Type
(Interface_Alias
(Prim
)))
8781 Set_DTC_Entity
(Prim
,
8784 Iface
=> Find_Dispatching_Type
(Interface_Alias
(Prim
))));
8786 Set_DTC_Entity
(Prim
,
8787 First_Tag_Component
(Tagged_Type
));
8789 end Set_DTC_Entity_Value
;
8795 function Tagged_Kind
(T
: Entity_Id
) return Node_Id
is
8796 Conc_Typ
: Entity_Id
;
8797 Loc
: constant Source_Ptr
:= Sloc
(T
);
8801 (Is_Tagged_Type
(T
) and then RTE_Available
(RE_Tagged_Kind
));
8805 if Is_Abstract_Type
(T
) then
8806 if Is_Limited_Record
(T
) then
8807 return New_Occurrence_Of
8808 (RTE
(RE_TK_Abstract_Limited_Tagged
), Loc
);
8810 return New_Occurrence_Of
8811 (RTE
(RE_TK_Abstract_Tagged
), Loc
);
8816 elsif Is_Concurrent_Record_Type
(T
) then
8817 Conc_Typ
:= Corresponding_Concurrent_Type
(T
);
8819 if Present
(Full_View
(Conc_Typ
)) then
8820 Conc_Typ
:= Full_View
(Conc_Typ
);
8823 if Ekind
(Conc_Typ
) = E_Protected_Type
then
8824 return New_Occurrence_Of
(RTE
(RE_TK_Protected
), Loc
);
8826 pragma Assert
(Ekind
(Conc_Typ
) = E_Task_Type
);
8827 return New_Occurrence_Of
(RTE
(RE_TK_Task
), Loc
);
8830 -- Regular tagged kinds
8833 if Is_Limited_Record
(T
) then
8834 return New_Occurrence_Of
(RTE
(RE_TK_Limited_Tagged
), Loc
);
8836 return New_Occurrence_Of
(RTE
(RE_TK_Tagged
), Loc
);
8845 procedure Write_DT
(Typ
: Entity_Id
) is
8850 -- Protect this procedure against wrong usage. Required because it will
8851 -- be used directly from GDB
8853 if not (Typ
<= Last_Node_Id
)
8854 or else not Is_Tagged_Type
(Typ
)
8856 Write_Str
("wrong usage: Write_DT must be used with tagged types");
8861 Write_Int
(Int
(Typ
));
8863 Write_Name
(Chars
(Typ
));
8865 if Is_Interface
(Typ
) then
8866 Write_Str
(" is interface");
8871 Elmt
:= First_Elmt
(Primitive_Operations
(Typ
));
8872 while Present
(Elmt
) loop
8873 Prim
:= Node
(Elmt
);
8876 -- Indicate if this primitive will be allocated in the primary
8877 -- dispatch table or in a secondary dispatch table associated
8878 -- with an abstract interface type
8880 if Present
(DTC_Entity
(Prim
)) then
8881 if Etype
(DTC_Entity
(Prim
)) = RTE
(RE_Tag
) then
8888 -- Output the node of this primitive operation and its name
8890 Write_Int
(Int
(Prim
));
8893 if Is_Predefined_Dispatching_Operation
(Prim
) then
8894 Write_Str
("(predefined) ");
8897 -- Prefix the name of the primitive with its corresponding tagged
8898 -- type to facilitate seeing inherited primitives.
8900 if Present
(Alias
(Prim
)) then
8902 (Chars
(Find_Dispatching_Type
(Ultimate_Alias
(Prim
))));
8904 Write_Name
(Chars
(Typ
));
8908 Write_Name
(Chars
(Prim
));
8910 -- Indicate if this primitive has an aliased primitive
8912 if Present
(Alias
(Prim
)) then
8913 Write_Str
(" (alias = ");
8914 Write_Int
(Int
(Alias
(Prim
)));
8916 -- If the DTC_Entity attribute is already set we can also output
8917 -- the name of the interface covered by this primitive (if any).
8919 if Ekind_In
(Alias
(Prim
), E_Function
, E_Procedure
)
8920 and then Present
(DTC_Entity
(Alias
(Prim
)))
8921 and then Is_Interface
(Scope
(DTC_Entity
(Alias
(Prim
))))
8923 Write_Str
(" from interface ");
8924 Write_Name
(Chars
(Scope
(DTC_Entity
(Alias
(Prim
)))));
8927 if Present
(Interface_Alias
(Prim
)) then
8928 Write_Str
(", AI_Alias of ");
8930 if Is_Null_Interface_Primitive
(Interface_Alias
(Prim
)) then
8931 Write_Str
("null primitive ");
8935 (Chars
(Find_Dispatching_Type
(Interface_Alias
(Prim
))));
8937 Write_Int
(Int
(Interface_Alias
(Prim
)));
8943 -- Display the final position of this primitive in its associated
8944 -- (primary or secondary) dispatch table
8946 if Present
(DTC_Entity
(Prim
))
8947 and then DT_Position
(Prim
) /= No_Uint
8949 Write_Str
(" at #");
8950 Write_Int
(UI_To_Int
(DT_Position
(Prim
)));
8953 if Is_Abstract_Subprogram
(Prim
) then
8954 Write_Str
(" is abstract;");
8956 -- Check if this is a null primitive
8958 elsif Comes_From_Source
(Prim
)
8959 and then Ekind
(Prim
) = E_Procedure
8960 and then Null_Present
(Parent
(Prim
))
8962 Write_Str
(" is null;");
8965 if Is_Eliminated
(Ultimate_Alias
(Prim
)) then
8966 Write_Str
(" (eliminated)");
8969 if Is_Imported
(Prim
)
8970 and then Convention
(Prim
) = Convention_CPP
8972 Write_Str
(" (C++)");