1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2014, 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 Has_DT
(Typ
: Entity_Id
) return Boolean;
79 pragma Inline
(Has_DT
);
80 -- Returns true if we generate a dispatch table for tagged type Typ
82 function Is_Predefined_Dispatching_Alias
(Prim
: Entity_Id
) return Boolean;
83 -- Returns true if Prim is not a predefined dispatching primitive but it is
84 -- an alias of a predefined dispatching primitive (i.e. through a renaming)
86 function New_Value
(From
: Node_Id
) return Node_Id
;
87 -- From is the original Expression. New_Value is equivalent to a call to
88 -- Duplicate_Subexpr with an explicit dereference when From is an access
91 function Original_View_In_Visible_Part
(Typ
: Entity_Id
) return Boolean;
92 -- Check if the type has a private view or if the public view appears in
93 -- the visible part of a package spec.
97 Typ
: Entity_Id
) return Node_Id
;
98 -- Ada 2005 (AI-345): Determine the primitive operation kind of Prim
99 -- according to its type Typ. Return a reference to an RE_Prim_Op_Kind
100 -- enumeration value.
102 function Tagged_Kind
(T
: Entity_Id
) return Node_Id
;
103 -- Ada 2005 (AI-345): Determine the tagged kind of T and return a reference
104 -- to an RE_Tagged_Kind enumeration value.
106 ----------------------
107 -- Apply_Tag_Checks --
108 ----------------------
110 procedure Apply_Tag_Checks
(Call_Node
: Node_Id
) is
111 Loc
: constant Source_Ptr
:= Sloc
(Call_Node
);
112 Ctrl_Arg
: constant Node_Id
:= Controlling_Argument
(Call_Node
);
113 Ctrl_Typ
: constant Entity_Id
:= Base_Type
(Etype
(Ctrl_Arg
));
114 Param_List
: constant List_Id
:= Parameter_Associations
(Call_Node
);
120 Eq_Prim_Op
: Entity_Id
:= Empty
;
123 if No_Run_Time_Mode
then
124 Error_Msg_CRT
("tagged types", Call_Node
);
128 -- Apply_Tag_Checks is called directly from the semantics, so we
129 -- need a check to see whether expansion is active before proceeding.
130 -- In addition, there is no need to expand the call when compiling
131 -- under restriction No_Dispatching_Calls; the semantic analyzer has
132 -- previously notified the violation of this restriction.
134 if not Expander_Active
135 or else Restriction_Active
(No_Dispatching_Calls
)
140 -- Set subprogram. If this is an inherited operation that was
141 -- overridden, the body that is being called is its alias.
143 Subp
:= Entity
(Name
(Call_Node
));
145 if Present
(Alias
(Subp
))
146 and then Is_Inherited_Operation
(Subp
)
147 and then No
(DTC_Entity
(Subp
))
149 Subp
:= Alias
(Subp
);
152 -- Definition of the class-wide type and the tagged type
154 -- If the controlling argument is itself a tag rather than a tagged
155 -- object, then use the class-wide type associated with the subprogram's
156 -- controlling type. This case can occur when a call to an inherited
157 -- primitive has an actual that originated from a default parameter
158 -- given by a tag-indeterminate call and when there is no other
159 -- controlling argument providing the tag (AI-239 requires dispatching).
160 -- This capability of dispatching directly by tag is also needed by the
161 -- implementation of AI-260 (for the generic dispatching constructors).
163 if Ctrl_Typ
= RTE
(RE_Tag
)
164 or else (RTE_Available
(RE_Interface_Tag
)
165 and then Ctrl_Typ
= RTE
(RE_Interface_Tag
))
167 CW_Typ
:= Class_Wide_Type
(Find_Dispatching_Type
(Subp
));
169 -- Class_Wide_Type is applied to the expressions used to initialize
170 -- CW_Typ, to ensure that CW_Typ always denotes a class-wide type, since
171 -- there are cases where the controlling type is resolved to a specific
172 -- type (such as for designated types of arguments such as CW'Access).
174 elsif Is_Access_Type
(Ctrl_Typ
) then
175 CW_Typ
:= Class_Wide_Type
(Designated_Type
(Ctrl_Typ
));
178 CW_Typ
:= Class_Wide_Type
(Ctrl_Typ
);
181 Typ
:= Find_Specific_Type
(CW_Typ
);
183 if not Is_Limited_Type
(Typ
) then
184 Eq_Prim_Op
:= Find_Prim_Op
(Typ
, Name_Op_Eq
);
187 -- Dispatching call to C++ primitive
189 if Is_CPP_Class
(Typ
) then
192 -- Dispatching call to Ada primitive
194 elsif Present
(Param_List
) then
196 -- Generate the Tag checks when appropriate
198 Param
:= First_Actual
(Call_Node
);
199 while Present
(Param
) loop
201 -- No tag check with itself
203 if Param
= Ctrl_Arg
then
206 -- No tag check for parameter whose type is neither tagged nor
207 -- access to tagged (for access parameters)
209 elsif No
(Find_Controlling_Arg
(Param
)) then
212 -- No tag check for function dispatching on result if the
213 -- Tag given by the context is this one
215 elsif Find_Controlling_Arg
(Param
) = Ctrl_Arg
then
218 -- "=" is the only dispatching operation allowed to get operands
219 -- with incompatible tags (it just returns false). We use
220 -- Duplicate_Subexpr_Move_Checks instead of calling Relocate_Node
221 -- because the value will be duplicated to check the tags.
223 elsif Subp
= Eq_Prim_Op
then
226 -- No check in presence of suppress flags
228 elsif Tag_Checks_Suppressed
(Etype
(Param
))
229 or else (Is_Access_Type
(Etype
(Param
))
230 and then Tag_Checks_Suppressed
231 (Designated_Type
(Etype
(Param
))))
235 -- Optimization: no tag checks if the parameters are identical
237 elsif Is_Entity_Name
(Param
)
238 and then Is_Entity_Name
(Ctrl_Arg
)
239 and then Entity
(Param
) = Entity
(Ctrl_Arg
)
243 -- Now we need to generate the Tag check
246 -- Generate code for tag equality check
248 -- Perhaps should have Checks.Apply_Tag_Equality_Check???
250 Insert_Action
(Ctrl_Arg
,
251 Make_Implicit_If_Statement
(Call_Node
,
255 Make_Selected_Component
(Loc
,
256 Prefix
=> New_Value
(Ctrl_Arg
),
259 (First_Tag_Component
(Typ
), Loc
)),
262 Make_Selected_Component
(Loc
,
264 Unchecked_Convert_To
(Typ
, New_Value
(Param
)),
267 (First_Tag_Component
(Typ
), Loc
))),
270 New_List
(New_Constraint_Error
(Loc
))));
276 end Apply_Tag_Checks
;
278 ------------------------
279 -- Building_Static_DT --
280 ------------------------
282 function Building_Static_DT
(Typ
: Entity_Id
) return Boolean is
283 Root_Typ
: Entity_Id
:= Root_Type
(Typ
);
286 -- Handle private types
288 if Present
(Full_View
(Root_Typ
)) then
289 Root_Typ
:= Full_View
(Root_Typ
);
292 return Static_Dispatch_Tables
293 and then Is_Library_Level_Tagged_Type
(Typ
)
294 and then VM_Target
= No_VM
296 -- If the type is derived from a CPP class we cannot statically
297 -- build the dispatch tables because we must inherit primitives
298 -- from the CPP side.
300 and then not Is_CPP_Class
(Root_Typ
);
301 end Building_Static_DT
;
303 ----------------------------------
304 -- Build_Static_Dispatch_Tables --
305 ----------------------------------
307 procedure Build_Static_Dispatch_Tables
(N
: Entity_Id
) is
308 Target_List
: List_Id
;
310 procedure Build_Dispatch_Tables
(List
: List_Id
);
311 -- Build the static dispatch table of tagged types found in the list of
312 -- declarations. The generated nodes are added at the end of Target_List
314 procedure Build_Package_Dispatch_Tables
(N
: Node_Id
);
315 -- Build static dispatch tables associated with package declaration N
317 ---------------------------
318 -- Build_Dispatch_Tables --
319 ---------------------------
321 procedure Build_Dispatch_Tables
(List
: List_Id
) is
326 while Present
(D
) loop
328 -- Handle nested packages and package bodies recursively. The
329 -- generated code is placed on the Target_List established for
330 -- the enclosing compilation unit.
332 if Nkind
(D
) = N_Package_Declaration
then
333 Build_Package_Dispatch_Tables
(D
);
335 elsif Nkind
(D
) = N_Package_Body
then
336 Build_Dispatch_Tables
(Declarations
(D
));
338 elsif Nkind
(D
) = N_Package_Body_Stub
339 and then Present
(Library_Unit
(D
))
341 Build_Dispatch_Tables
342 (Declarations
(Proper_Body
(Unit
(Library_Unit
(D
)))));
344 -- Handle full type declarations and derivations of library level
347 elsif Nkind_In
(D
, N_Full_Type_Declaration
,
348 N_Derived_Type_Definition
)
349 and then Is_Library_Level_Tagged_Type
(Defining_Entity
(D
))
350 and then Ekind
(Defining_Entity
(D
)) /= E_Record_Subtype
351 and then not Is_Private_Type
(Defining_Entity
(D
))
353 -- We do not generate dispatch tables for the internal types
354 -- created for a type extension with unknown discriminants
355 -- The needed information is shared with the source type,
356 -- See Expand_N_Record_Extension.
358 if Is_Underlying_Record_View
(Defining_Entity
(D
))
360 (not Comes_From_Source
(Defining_Entity
(D
))
362 Has_Unknown_Discriminants
(Etype
(Defining_Entity
(D
)))
364 not Comes_From_Source
365 (First_Subtype
(Defining_Entity
(D
))))
369 Insert_List_After_And_Analyze
(Last
(Target_List
),
370 Make_DT
(Defining_Entity
(D
)));
373 -- Handle private types of library level tagged types. We must
374 -- exchange the private and full-view to ensure the correct
375 -- expansion. If the full view is a synchronized type ignore
376 -- the type because the table will be built for the corresponding
377 -- record type, that has its own declaration.
379 elsif (Nkind
(D
) = N_Private_Type_Declaration
380 or else Nkind
(D
) = N_Private_Extension_Declaration
)
381 and then Present
(Full_View
(Defining_Entity
(D
)))
384 E1
: constant Entity_Id
:= Defining_Entity
(D
);
385 E2
: constant Entity_Id
:= Full_View
(E1
);
388 if Is_Library_Level_Tagged_Type
(E2
)
389 and then Ekind
(E2
) /= E_Record_Subtype
390 and then not Is_Concurrent_Type
(E2
)
392 Exchange_Declarations
(E1
);
393 Insert_List_After_And_Analyze
(Last
(Target_List
),
395 Exchange_Declarations
(E2
);
402 end Build_Dispatch_Tables
;
404 -----------------------------------
405 -- Build_Package_Dispatch_Tables --
406 -----------------------------------
408 procedure Build_Package_Dispatch_Tables
(N
: Node_Id
) is
409 Spec
: constant Node_Id
:= Specification
(N
);
410 Id
: constant Entity_Id
:= Defining_Entity
(N
);
411 Vis_Decls
: constant List_Id
:= Visible_Declarations
(Spec
);
412 Priv_Decls
: constant List_Id
:= Private_Declarations
(Spec
);
417 if Present
(Priv_Decls
) then
418 Build_Dispatch_Tables
(Vis_Decls
);
419 Build_Dispatch_Tables
(Priv_Decls
);
421 elsif Present
(Vis_Decls
) then
422 Build_Dispatch_Tables
(Vis_Decls
);
426 end Build_Package_Dispatch_Tables
;
428 -- Start of processing for Build_Static_Dispatch_Tables
431 if not Expander_Active
432 or else not Tagged_Type_Expansion
437 if Nkind
(N
) = N_Package_Declaration
then
439 Spec
: constant Node_Id
:= Specification
(N
);
440 Vis_Decls
: constant List_Id
:= Visible_Declarations
(Spec
);
441 Priv_Decls
: constant List_Id
:= Private_Declarations
(Spec
);
444 if Present
(Priv_Decls
)
445 and then Is_Non_Empty_List
(Priv_Decls
)
447 Target_List
:= Priv_Decls
;
449 elsif not Present
(Vis_Decls
) then
450 Target_List
:= New_List
;
451 Set_Private_Declarations
(Spec
, Target_List
);
453 Target_List
:= Vis_Decls
;
456 Build_Package_Dispatch_Tables
(N
);
459 else pragma Assert
(Nkind
(N
) = N_Package_Body
);
460 Target_List
:= Declarations
(N
);
461 Build_Dispatch_Tables
(Target_List
);
463 end Build_Static_Dispatch_Tables
;
465 ------------------------------
466 -- Convert_Tag_To_Interface --
467 ------------------------------
469 function Convert_Tag_To_Interface
471 Expr
: Node_Id
) return Node_Id
473 Loc
: constant Source_Ptr
:= Sloc
(Expr
);
474 Anon_Type
: Entity_Id
;
478 pragma Assert
(Is_Class_Wide_Type
(Typ
)
479 and then Is_Interface
(Typ
)
481 ((Nkind
(Expr
) = N_Selected_Component
482 and then Is_Tag
(Entity
(Selector_Name
(Expr
))))
484 (Nkind
(Expr
) = N_Function_Call
485 and then RTE_Available
(RE_Displace
)
486 and then Entity
(Name
(Expr
)) = RTE
(RE_Displace
))));
488 Anon_Type
:= Create_Itype
(E_Anonymous_Access_Type
, Expr
);
489 Set_Directly_Designated_Type
(Anon_Type
, Typ
);
490 Set_Etype
(Anon_Type
, Anon_Type
);
491 Set_Can_Never_Be_Null
(Anon_Type
);
493 -- Decorate the size and alignment attributes of the anonymous access
494 -- type, as required by the back end.
496 Layout_Type
(Anon_Type
);
498 if Nkind
(Expr
) = N_Selected_Component
499 and then Is_Tag
(Entity
(Selector_Name
(Expr
)))
502 Make_Explicit_Dereference
(Loc
,
503 Unchecked_Convert_To
(Anon_Type
,
504 Make_Attribute_Reference
(Loc
,
506 Attribute_Name
=> Name_Address
)));
509 Make_Explicit_Dereference
(Loc
,
510 Unchecked_Convert_To
(Anon_Type
, Expr
));
514 end Convert_Tag_To_Interface
;
520 function CPP_Num_Prims
(Typ
: Entity_Id
) return Nat
is
522 Tag_Comp
: Entity_Id
;
525 if not Is_Tagged_Type
(Typ
)
526 or else not Is_CPP_Class
(Root_Type
(Typ
))
531 CPP_Typ
:= Enclosing_CPP_Parent
(Typ
);
532 Tag_Comp
:= First_Tag_Component
(CPP_Typ
);
534 -- If number of primitives already set in the tag component, use it
536 if Present
(Tag_Comp
)
537 and then DT_Entry_Count
(Tag_Comp
) /= No_Uint
539 return UI_To_Int
(DT_Entry_Count
(Tag_Comp
));
541 -- Otherwise, count the primitives of the enclosing CPP type
549 Elmt
:= First_Elmt
(Primitive_Operations
(CPP_Typ
));
550 while Present
(Elmt
) loop
561 ------------------------------
562 -- Default_Prim_Op_Position --
563 ------------------------------
565 function Default_Prim_Op_Position
(E
: Entity_Id
) return Uint
is
566 TSS_Name
: TSS_Name_Type
;
569 Get_Name_String
(Chars
(E
));
572 (Name_Buffer
(Name_Len
- TSS_Name
'Length + 1 .. Name_Len
));
574 if Chars
(E
) = Name_uSize
then
577 elsif TSS_Name
= TSS_Stream_Read
then
580 elsif TSS_Name
= TSS_Stream_Write
then
583 elsif TSS_Name
= TSS_Stream_Input
then
586 elsif TSS_Name
= TSS_Stream_Output
then
589 elsif Chars
(E
) = Name_Op_Eq
then
592 elsif Chars
(E
) = Name_uAssign
then
595 elsif TSS_Name
= TSS_Deep_Adjust
then
598 elsif TSS_Name
= TSS_Deep_Finalize
then
601 -- In VM targets unconditionally allow obtaining the position associated
602 -- with predefined interface primitives since in these platforms any
603 -- tagged type has these primitives.
605 elsif Ada_Version
>= Ada_2005
or else not Tagged_Type_Expansion
then
606 if Chars
(E
) = Name_uDisp_Asynchronous_Select
then
609 elsif Chars
(E
) = Name_uDisp_Conditional_Select
then
612 elsif Chars
(E
) = Name_uDisp_Get_Prim_Op_Kind
then
615 elsif Chars
(E
) = Name_uDisp_Get_Task_Id
then
618 elsif Chars
(E
) = Name_uDisp_Requeue
then
621 elsif Chars
(E
) = Name_uDisp_Timed_Select
then
627 end Default_Prim_Op_Position
;
629 -----------------------------
630 -- Expand_Dispatching_Call --
631 -----------------------------
633 procedure Expand_Dispatching_Call
(Call_Node
: Node_Id
) is
634 Loc
: constant Source_Ptr
:= Sloc
(Call_Node
);
635 Call_Typ
: constant Entity_Id
:= Etype
(Call_Node
);
637 Ctrl_Arg
: constant Node_Id
:= Controlling_Argument
(Call_Node
);
638 Ctrl_Typ
: constant Entity_Id
:= Base_Type
(Etype
(Ctrl_Arg
));
639 Param_List
: constant List_Id
:= Parameter_Associations
(Call_Node
);
644 New_Call_Name
: Node_Id
;
645 New_Params
: List_Id
:= No_List
;
648 Subp_Ptr_Typ
: Entity_Id
;
649 Subp_Typ
: Entity_Id
;
651 Eq_Prim_Op
: Entity_Id
:= Empty
;
652 Controlling_Tag
: Node_Id
;
654 function New_Value
(From
: Node_Id
) return Node_Id
;
655 -- From is the original Expression. New_Value is equivalent to a call
656 -- to Duplicate_Subexpr with an explicit dereference when From is an
663 function New_Value
(From
: Node_Id
) return Node_Id
is
664 Res
: constant Node_Id
:= Duplicate_Subexpr
(From
);
666 if Is_Access_Type
(Etype
(From
)) then
668 Make_Explicit_Dereference
(Sloc
(From
),
679 SCIL_Related_Node
: Node_Id
:= Call_Node
;
681 -- Start of processing for Expand_Dispatching_Call
684 if No_Run_Time_Mode
then
685 Error_Msg_CRT
("tagged types", Call_Node
);
689 -- Expand_Dispatching_Call is called directly from the semantics, so we
690 -- only proceed if the expander is active.
692 if not Expander_Active
694 -- And there is no need to expand the call if we are compiling under
695 -- restriction No_Dispatching_Calls; the semantic analyzer has
696 -- previously notified the violation of this restriction.
698 or else Restriction_Active
(No_Dispatching_Calls
)
700 -- No action needed if the dispatching call has been already expanded
702 or else Is_Expanded_Dispatching_Call
(Name
(Call_Node
))
707 -- Set subprogram. If this is an inherited operation that was
708 -- overridden, the body that is being called is its alias.
710 Subp
:= Entity
(Name
(Call_Node
));
712 if Present
(Alias
(Subp
))
713 and then Is_Inherited_Operation
(Subp
)
714 and then No
(DTC_Entity
(Subp
))
716 Subp
:= Alias
(Subp
);
719 -- Definition of the class-wide type and the tagged type
721 -- If the controlling argument is itself a tag rather than a tagged
722 -- object, then use the class-wide type associated with the subprogram's
723 -- controlling type. This case can occur when a call to an inherited
724 -- primitive has an actual that originated from a default parameter
725 -- given by a tag-indeterminate call and when there is no other
726 -- controlling argument providing the tag (AI-239 requires dispatching).
727 -- This capability of dispatching directly by tag is also needed by the
728 -- implementation of AI-260 (for the generic dispatching constructors).
730 if Ctrl_Typ
= RTE
(RE_Tag
)
731 or else (RTE_Available
(RE_Interface_Tag
)
732 and then Ctrl_Typ
= RTE
(RE_Interface_Tag
))
734 CW_Typ
:= Class_Wide_Type
(Find_Dispatching_Type
(Subp
));
736 -- Class_Wide_Type is applied to the expressions used to initialize
737 -- CW_Typ, to ensure that CW_Typ always denotes a class-wide type, since
738 -- there are cases where the controlling type is resolved to a specific
739 -- type (such as for designated types of arguments such as CW'Access).
741 elsif Is_Access_Type
(Ctrl_Typ
) then
742 CW_Typ
:= Class_Wide_Type
(Designated_Type
(Ctrl_Typ
));
745 CW_Typ
:= Class_Wide_Type
(Ctrl_Typ
);
748 Typ
:= Find_Specific_Type
(CW_Typ
);
750 if not Is_Limited_Type
(Typ
) then
751 Eq_Prim_Op
:= Find_Prim_Op
(Typ
, Name_Op_Eq
);
754 -- Dispatching call to C++ primitive. Create a new parameter list
755 -- with no tag checks.
757 New_Params
:= New_List
;
759 if Is_CPP_Class
(Typ
) then
760 Param
:= First_Actual
(Call_Node
);
761 while Present
(Param
) loop
762 Append_To
(New_Params
, Relocate_Node
(Param
));
766 -- Dispatching call to Ada primitive
768 elsif Present
(Param_List
) then
769 Apply_Tag_Checks
(Call_Node
);
771 Param
:= First_Actual
(Call_Node
);
772 while Present
(Param
) loop
774 -- Cases in which we may have generated run-time checks. Note that
775 -- we strip any qualification from Param before comparing with the
776 -- already-stripped controlling argument.
778 if Unqualify
(Param
) = Ctrl_Arg
or else Subp
= Eq_Prim_Op
then
779 Append_To
(New_Params
,
780 Duplicate_Subexpr_Move_Checks
(Param
));
782 elsif Nkind
(Parent
(Param
)) /= N_Parameter_Association
783 or else not Is_Accessibility_Actual
(Parent
(Param
))
785 Append_To
(New_Params
, Relocate_Node
(Param
));
792 -- Generate the appropriate subprogram pointer type
794 if Etype
(Subp
) = Typ
then
797 Res_Typ
:= Etype
(Subp
);
800 Subp_Typ
:= Create_Itype
(E_Subprogram_Type
, Call_Node
);
801 Subp_Ptr_Typ
:= Create_Itype
(E_Access_Subprogram_Type
, Call_Node
);
802 Set_Etype
(Subp_Typ
, Res_Typ
);
803 Set_Returns_By_Ref
(Subp_Typ
, Returns_By_Ref
(Subp
));
804 Set_Convention
(Subp_Typ
, Convention
(Subp
));
806 -- Notify gigi that the designated type is a dispatching primitive
808 Set_Is_Dispatch_Table_Entity
(Subp_Typ
);
810 -- Create a new list of parameters which is a copy of the old formal
811 -- list including the creation of a new set of matching entities.
814 Old_Formal
: Entity_Id
:= First_Formal
(Subp
);
815 New_Formal
: Entity_Id
;
816 Extra
: Entity_Id
:= Empty
;
819 if Present
(Old_Formal
) then
820 New_Formal
:= New_Copy
(Old_Formal
);
821 Set_First_Entity
(Subp_Typ
, New_Formal
);
822 Param
:= First_Actual
(Call_Node
);
825 Set_Scope
(New_Formal
, Subp_Typ
);
827 -- Change all the controlling argument types to be class-wide
828 -- to avoid a recursion in dispatching.
830 if Is_Controlling_Formal
(New_Formal
) then
831 Set_Etype
(New_Formal
, Etype
(Param
));
834 -- If the type of the formal is an itype, there was code here
835 -- introduced in 1998 in revision 1.46, to create a new itype
836 -- by copy. This seems useless, and in fact leads to semantic
837 -- errors when the itype is the completion of a type derived
838 -- from a private type.
841 Next_Formal
(Old_Formal
);
842 exit when No
(Old_Formal
);
844 Set_Next_Entity
(New_Formal
, New_Copy
(Old_Formal
));
845 Next_Entity
(New_Formal
);
849 Set_Next_Entity
(New_Formal
, Empty
);
850 Set_Last_Entity
(Subp_Typ
, Extra
);
853 -- Now that the explicit formals have been duplicated, any extra
854 -- formals needed by the subprogram must be created.
856 if Present
(Extra
) then
857 Set_Extra_Formal
(Extra
, Empty
);
860 Create_Extra_Formals
(Subp_Typ
);
863 -- Complete description of pointer type, including size information, as
864 -- must be done with itypes to prevent order-of-elaboration anomalies
867 Set_Etype
(Subp_Ptr_Typ
, Subp_Ptr_Typ
);
868 Set_Directly_Designated_Type
(Subp_Ptr_Typ
, Subp_Typ
);
869 Set_Convention
(Subp_Ptr_Typ
, Convention
(Subp_Typ
));
870 Layout_Type
(Subp_Ptr_Typ
);
872 -- If the controlling argument is a value of type Ada.Tag or an abstract
873 -- interface class-wide type then use it directly. Otherwise, the tag
874 -- must be extracted from the controlling object.
876 if Ctrl_Typ
= RTE
(RE_Tag
)
877 or else (RTE_Available
(RE_Interface_Tag
)
878 and then Ctrl_Typ
= RTE
(RE_Interface_Tag
))
880 Controlling_Tag
:= Duplicate_Subexpr
(Ctrl_Arg
);
882 -- Extract the tag from an unchecked type conversion. Done to avoid
883 -- the expansion of additional code just to obtain the value of such
884 -- tag because the current management of interface type conversions
885 -- generates in some cases this unchecked type conversion with the
886 -- tag of the object (see Expand_Interface_Conversion).
888 elsif Nkind
(Ctrl_Arg
) = N_Unchecked_Type_Conversion
890 (Etype
(Expression
(Ctrl_Arg
)) = RTE
(RE_Tag
)
892 (RTE_Available
(RE_Interface_Tag
)
894 Etype
(Expression
(Ctrl_Arg
)) = RTE
(RE_Interface_Tag
)))
896 Controlling_Tag
:= Duplicate_Subexpr
(Expression
(Ctrl_Arg
));
898 -- Ada 2005 (AI-251): Abstract interface class-wide type
900 elsif Is_Interface
(Ctrl_Typ
)
901 and then Is_Class_Wide_Type
(Ctrl_Typ
)
903 Controlling_Tag
:= Duplicate_Subexpr
(Ctrl_Arg
);
907 Make_Selected_Component
(Loc
,
908 Prefix
=> Duplicate_Subexpr_Move_Checks
(Ctrl_Arg
),
909 Selector_Name
=> New_Occurrence_Of
(DTC_Entity
(Subp
), Loc
));
912 -- Handle dispatching calls to predefined primitives
914 if Is_Predefined_Dispatching_Operation
(Subp
)
915 or else Is_Predefined_Dispatching_Alias
(Subp
)
917 Build_Get_Predefined_Prim_Op_Address
(Loc
,
918 Tag_Node
=> Controlling_Tag
,
919 Position
=> DT_Position
(Subp
),
920 New_Node
=> New_Node
);
922 -- Handle dispatching calls to user-defined primitives
925 Build_Get_Prim_Op_Address
(Loc
,
926 Typ
=> Underlying_Type
(Find_Dispatching_Type
(Subp
)),
927 Tag_Node
=> Controlling_Tag
,
928 Position
=> DT_Position
(Subp
),
929 New_Node
=> New_Node
);
933 Unchecked_Convert_To
(Subp_Ptr_Typ
, New_Node
);
935 -- Generate the SCIL node for this dispatching call. Done now because
936 -- attribute SCIL_Controlling_Tag must be set after the new call name
937 -- is built to reference the nodes that will see the SCIL backend
938 -- (because Build_Get_Prim_Op_Address generates an unchecked type
939 -- conversion which relocates the controlling tag node).
941 if Generate_SCIL
then
942 SCIL_Node
:= Make_SCIL_Dispatching_Call
(Sloc
(Call_Node
));
943 Set_SCIL_Entity
(SCIL_Node
, Typ
);
944 Set_SCIL_Target_Prim
(SCIL_Node
, Subp
);
946 -- Common case: the controlling tag is the tag of an object
947 -- (for example, obj.tag)
949 if Nkind
(Controlling_Tag
) = N_Selected_Component
then
950 Set_SCIL_Controlling_Tag
(SCIL_Node
, Controlling_Tag
);
952 -- Handle renaming of selected component
954 elsif Nkind
(Controlling_Tag
) = N_Identifier
955 and then Nkind
(Parent
(Entity
(Controlling_Tag
))) =
956 N_Object_Renaming_Declaration
957 and then Nkind
(Name
(Parent
(Entity
(Controlling_Tag
)))) =
960 Set_SCIL_Controlling_Tag
(SCIL_Node
,
961 Name
(Parent
(Entity
(Controlling_Tag
))));
963 -- If the controlling tag is an identifier, the SCIL node references
964 -- the corresponding object or parameter declaration
966 elsif Nkind
(Controlling_Tag
) = N_Identifier
967 and then Nkind_In
(Parent
(Entity
(Controlling_Tag
)),
968 N_Object_Declaration
,
969 N_Parameter_Specification
)
971 Set_SCIL_Controlling_Tag
(SCIL_Node
,
972 Parent
(Entity
(Controlling_Tag
)));
974 -- If the controlling tag is a dereference, the SCIL node references
975 -- the corresponding object or parameter declaration
977 elsif Nkind
(Controlling_Tag
) = N_Explicit_Dereference
978 and then Nkind
(Prefix
(Controlling_Tag
)) = N_Identifier
979 and then Nkind_In
(Parent
(Entity
(Prefix
(Controlling_Tag
))),
980 N_Object_Declaration
,
981 N_Parameter_Specification
)
983 Set_SCIL_Controlling_Tag
(SCIL_Node
,
984 Parent
(Entity
(Prefix
(Controlling_Tag
))));
986 -- For a direct reference of the tag of the type the SCIL node
987 -- references the internal object declaration containing the tag
990 elsif Nkind
(Controlling_Tag
) = N_Attribute_Reference
991 and then Attribute_Name
(Controlling_Tag
) = Name_Tag
993 Set_SCIL_Controlling_Tag
(SCIL_Node
,
997 (Access_Disp_Table
(Entity
(Prefix
(Controlling_Tag
)))))));
999 -- Interfaces are not supported. For now we leave the SCIL node
1000 -- decorated with the Controlling_Tag. More work needed here???
1002 elsif Is_Interface
(Etype
(Controlling_Tag
)) then
1003 Set_SCIL_Controlling_Tag
(SCIL_Node
, Controlling_Tag
);
1006 pragma Assert
(False);
1011 if Nkind
(Call_Node
) = N_Function_Call
then
1013 Make_Function_Call
(Loc
,
1014 Name
=> New_Call_Name
,
1015 Parameter_Associations
=> New_Params
);
1017 -- If this is a dispatching "=", we must first compare the tags so
1018 -- we generate: x.tag = y.tag and then x = y
1020 if Subp
= Eq_Prim_Op
then
1021 Param
:= First_Actual
(Call_Node
);
1027 Make_Selected_Component
(Loc
,
1028 Prefix
=> New_Value
(Param
),
1030 New_Occurrence_Of
(First_Tag_Component
(Typ
),
1034 Make_Selected_Component
(Loc
,
1036 Unchecked_Convert_To
(Typ
,
1037 New_Value
(Next_Actual
(Param
))),
1040 (First_Tag_Component
(Typ
), Loc
))),
1041 Right_Opnd
=> New_Call
);
1043 SCIL_Related_Node
:= Right_Opnd
(New_Call
);
1048 Make_Procedure_Call_Statement
(Loc
,
1049 Name
=> New_Call_Name
,
1050 Parameter_Associations
=> New_Params
);
1053 -- Register the dispatching call in the call graph nodes table
1055 Register_CG_Node
(Call_Node
);
1057 Rewrite
(Call_Node
, New_Call
);
1059 -- Associate the SCIL node of this dispatching call
1061 if Generate_SCIL
then
1062 Set_SCIL_Node
(SCIL_Related_Node
, SCIL_Node
);
1065 -- Suppress all checks during the analysis of the expanded code to avoid
1066 -- the generation of spurious warnings under ZFP run-time.
1068 Analyze_And_Resolve
(Call_Node
, Call_Typ
, Suppress
=> All_Checks
);
1069 end Expand_Dispatching_Call
;
1071 ---------------------------------
1072 -- Expand_Interface_Conversion --
1073 ---------------------------------
1075 procedure Expand_Interface_Conversion
(N
: Node_Id
) is
1076 function Underlying_Record_Type
(Typ
: Entity_Id
) return Entity_Id
;
1077 -- Return the underlying record type of Typ.
1079 ----------------------------
1080 -- Underlying_Record_Type --
1081 ----------------------------
1083 function Underlying_Record_Type
(Typ
: Entity_Id
) return Entity_Id
is
1084 E
: Entity_Id
:= Typ
;
1087 -- Handle access to class-wide interface types
1089 if Is_Access_Type
(E
) then
1090 E
:= Etype
(Directly_Designated_Type
(E
));
1093 -- Handle class-wide types. This conversion can appear explicitly in
1094 -- the source code. Example: I'Class (Obj)
1096 if Is_Class_Wide_Type
(E
) then
1100 -- If the target type is a tagged synchronized type, the dispatch
1101 -- table info is in the corresponding record type.
1103 if Is_Concurrent_Type
(E
) then
1104 E
:= Corresponding_Record_Type
(E
);
1107 -- Handle private types
1109 E
:= Underlying_Type
(E
);
1113 return Base_Type
(E
);
1114 end Underlying_Record_Type
;
1118 Loc
: constant Source_Ptr
:= Sloc
(N
);
1119 Etyp
: constant Entity_Id
:= Etype
(N
);
1120 Operand
: constant Node_Id
:= Expression
(N
);
1121 Operand_Typ
: Entity_Id
:= Etype
(Operand
);
1123 Iface_Typ
: constant Entity_Id
:= Underlying_Record_Type
(Etype
(N
));
1124 Iface_Tag
: Entity_Id
;
1125 Is_Static
: Boolean;
1127 -- Start of processing for Expand_Interface_Conversion
1130 -- Freeze the entity associated with the target interface to have
1131 -- available the attribute Access_Disp_Table.
1133 Freeze_Before
(N
, Iface_Typ
);
1135 -- Ada 2005 (AI-345): Handle synchronized interface type derivations
1137 if Is_Concurrent_Type
(Operand_Typ
) then
1138 Operand_Typ
:= Base_Type
(Corresponding_Record_Type
(Operand_Typ
));
1141 -- No displacement of the pointer to the object needed when the type of
1142 -- the operand is not an interface type and the interface is one of
1143 -- its parent types (since they share the primary dispatch table).
1146 Opnd
: Entity_Id
:= Operand_Typ
;
1149 if Is_Access_Type
(Opnd
) then
1150 Opnd
:= Designated_Type
(Opnd
);
1153 if not Is_Interface
(Opnd
)
1154 and then Is_Ancestor
(Iface_Typ
, Opnd
, Use_Full_View
=> True)
1160 -- Evaluate if we can statically displace the pointer to the object
1163 Opnd_Typ
: constant Node_Id
:= Underlying_Record_Type
(Operand_Typ
);
1167 not Is_Interface
(Opnd_Typ
)
1168 and then Interface_Present_In_Ancestor
1171 and then (Etype
(Opnd_Typ
) = Opnd_Typ
1173 Is_Variable_Size_Record
(Etype
(Opnd_Typ
)));
1176 if not Tagged_Type_Expansion
then
1177 if VM_Target
/= No_VM
then
1178 if Is_Access_Type
(Operand_Typ
) then
1179 Operand_Typ
:= Designated_Type
(Operand_Typ
);
1182 if Is_Class_Wide_Type
(Operand_Typ
) then
1183 Operand_Typ
:= Root_Type
(Operand_Typ
);
1186 if not Is_Static
and then Operand_Typ
/= Iface_Typ
then
1188 Make_Procedure_Call_Statement
(Loc
,
1189 Name
=> New_Occurrence_Of
1190 (RTE
(RE_Check_Interface_Conversion
), Loc
),
1191 Parameter_Associations
=> New_List
(
1192 Make_Attribute_Reference
(Loc
,
1193 Prefix
=> Duplicate_Subexpr
(Expression
(N
)),
1194 Attribute_Name
=> Name_Tag
),
1195 Make_Attribute_Reference
(Loc
,
1196 Prefix
=> New_Occurrence_Of
(Iface_Typ
, Loc
),
1197 Attribute_Name
=> Name_Tag
))));
1200 -- Just do a conversion ???
1202 Rewrite
(N
, Unchecked_Convert_To
(Etype
(N
), N
));
1208 -- A static conversion to an interface type that is not classwide is
1209 -- curious but legal if the interface operation is a null procedure.
1210 -- If the operation is abstract it will be rejected later.
1213 and then Is_Interface
(Etype
(N
))
1214 and then not Is_Class_Wide_Type
(Etype
(N
))
1215 and then Comes_From_Source
(N
)
1217 Rewrite
(N
, Unchecked_Convert_To
(Etype
(N
), N
));
1222 if not Is_Static
then
1224 -- Give error if configurable run time and Displace not available
1226 if not RTE_Available
(RE_Displace
) then
1227 Error_Msg_CRT
("dynamic interface conversion", N
);
1231 -- Handle conversion of access-to-class-wide interface types. Target
1232 -- can be an access to an object or an access to another class-wide
1233 -- interface (see -1- and -2- in the following example):
1235 -- type Iface1_Ref is access all Iface1'Class;
1236 -- type Iface2_Ref is access all Iface1'Class;
1238 -- Acc1 : Iface1_Ref := new ...
1239 -- Obj : Obj_Ref := Obj_Ref (Acc); -- 1
1240 -- Acc2 : Iface2_Ref := Iface2_Ref (Acc); -- 2
1242 if Is_Access_Type
(Operand_Typ
) then
1244 Unchecked_Convert_To
(Etype
(N
),
1245 Make_Function_Call
(Loc
,
1246 Name
=> New_Occurrence_Of
(RTE
(RE_Displace
), Loc
),
1247 Parameter_Associations
=> New_List
(
1249 Unchecked_Convert_To
(RTE
(RE_Address
),
1250 Relocate_Node
(Expression
(N
))),
1253 (Node
(First_Elmt
(Access_Disp_Table
(Iface_Typ
))),
1261 Make_Function_Call
(Loc
,
1262 Name
=> New_Occurrence_Of
(RTE
(RE_Displace
), Loc
),
1263 Parameter_Associations
=> New_List
(
1264 Make_Attribute_Reference
(Loc
,
1265 Prefix
=> Relocate_Node
(Expression
(N
)),
1266 Attribute_Name
=> Name_Address
),
1269 (Node
(First_Elmt
(Access_Disp_Table
(Iface_Typ
))),
1274 -- If target is a class-wide interface, change the type of the data
1275 -- returned by IW_Convert to indicate this is a dispatching call.
1278 New_Itype
: Entity_Id
;
1281 New_Itype
:= Create_Itype
(E_Anonymous_Access_Type
, N
);
1282 Set_Etype
(New_Itype
, New_Itype
);
1283 Set_Directly_Designated_Type
(New_Itype
, Etyp
);
1286 Make_Explicit_Dereference
(Loc
,
1288 Unchecked_Convert_To
(New_Itype
, Relocate_Node
(N
))));
1290 Freeze_Itype
(New_Itype
, N
);
1296 Iface_Tag
:= Find_Interface_Tag
(Operand_Typ
, Iface_Typ
);
1297 pragma Assert
(Iface_Tag
/= Empty
);
1299 -- Keep separate access types to interfaces because one internal
1300 -- function is used to handle the null value (see following comments)
1302 if not Is_Access_Type
(Etype
(N
)) then
1304 -- Statically displace the pointer to the object to reference the
1305 -- component containing the secondary dispatch table.
1308 Convert_Tag_To_Interface
(Class_Wide_Type
(Iface_Typ
),
1309 Make_Selected_Component
(Loc
,
1310 Prefix
=> Relocate_Node
(Expression
(N
)),
1311 Selector_Name
=> New_Occurrence_Of
(Iface_Tag
, Loc
))));
1314 -- Build internal function to handle the case in which the actual is
1315 -- null. If the actual is null returns null because no displacement
1316 -- is required; otherwise performs a type conversion that will be
1317 -- expanded in the code that returns the value of the displaced
1320 -- function Func (O : Address) return Iface_Typ is
1321 -- type Op_Typ is access all Operand_Typ;
1322 -- Aux : Op_Typ := To_Op_Typ (O);
1324 -- if O = Null_Address then
1327 -- return Iface_Typ!(Aux.Iface_Tag'Address);
1332 Desig_Typ
: Entity_Id
;
1334 New_Typ_Decl
: Node_Id
;
1338 Desig_Typ
:= Etype
(Expression
(N
));
1340 if Is_Access_Type
(Desig_Typ
) then
1342 Available_View
(Directly_Designated_Type
(Desig_Typ
));
1345 if Is_Concurrent_Type
(Desig_Typ
) then
1346 Desig_Typ
:= Base_Type
(Corresponding_Record_Type
(Desig_Typ
));
1350 Make_Full_Type_Declaration
(Loc
,
1351 Defining_Identifier
=> Make_Temporary
(Loc
, 'T'),
1353 Make_Access_To_Object_Definition
(Loc
,
1354 All_Present
=> True,
1355 Null_Exclusion_Present
=> False,
1356 Constant_Present
=> False,
1357 Subtype_Indication
=>
1358 New_Occurrence_Of
(Desig_Typ
, Loc
)));
1361 Make_Simple_Return_Statement
(Loc
,
1362 Unchecked_Convert_To
(Etype
(N
),
1363 Make_Attribute_Reference
(Loc
,
1365 Make_Selected_Component
(Loc
,
1367 Unchecked_Convert_To
1368 (Defining_Identifier
(New_Typ_Decl
),
1369 Make_Identifier
(Loc
, Name_uO
)),
1371 New_Occurrence_Of
(Iface_Tag
, Loc
)),
1372 Attribute_Name
=> Name_Address
))));
1374 -- If the type is null-excluding, no need for the null branch.
1375 -- Otherwise we need to check for it and return null.
1377 if not Can_Never_Be_Null
(Etype
(N
)) then
1379 Make_If_Statement
(Loc
,
1382 Left_Opnd
=> Make_Identifier
(Loc
, Name_uO
),
1383 Right_Opnd
=> New_Occurrence_Of
1384 (RTE
(RE_Null_Address
), Loc
)),
1386 Then_Statements
=> New_List
(
1387 Make_Simple_Return_Statement
(Loc
, Make_Null
(Loc
))),
1388 Else_Statements
=> Stats
));
1391 Fent
:= Make_Temporary
(Loc
, 'F');
1393 Make_Subprogram_Body
(Loc
,
1395 Make_Function_Specification
(Loc
,
1396 Defining_Unit_Name
=> Fent
,
1398 Parameter_Specifications
=> New_List
(
1399 Make_Parameter_Specification
(Loc
,
1400 Defining_Identifier
=>
1401 Make_Defining_Identifier
(Loc
, Name_uO
),
1403 New_Occurrence_Of
(RTE
(RE_Address
), Loc
))),
1405 Result_Definition
=>
1406 New_Occurrence_Of
(Etype
(N
), Loc
)),
1408 Declarations
=> New_List
(New_Typ_Decl
),
1410 Handled_Statement_Sequence
=>
1411 Make_Handled_Sequence_Of_Statements
(Loc
, Stats
));
1413 -- Place function body before the expression containing the
1414 -- conversion. We suppress all checks because the body of the
1415 -- internally generated function already takes care of the case
1416 -- in which the actual is null; therefore there is no need to
1417 -- double check that the pointer is not null when the program
1418 -- executes the alternative that performs the type conversion).
1420 Insert_Action
(N
, Func
, Suppress
=> All_Checks
);
1422 if Is_Access_Type
(Etype
(Expression
(N
))) then
1424 -- Generate: Func (Address!(Expression))
1427 Make_Function_Call
(Loc
,
1428 Name
=> New_Occurrence_Of
(Fent
, Loc
),
1429 Parameter_Associations
=> New_List
(
1430 Unchecked_Convert_To
(RTE
(RE_Address
),
1431 Relocate_Node
(Expression
(N
))))));
1434 -- Generate: Func (Operand_Typ!(Expression)'Address)
1437 Make_Function_Call
(Loc
,
1438 Name
=> New_Occurrence_Of
(Fent
, Loc
),
1439 Parameter_Associations
=> New_List
(
1440 Make_Attribute_Reference
(Loc
,
1441 Prefix
=> Unchecked_Convert_To
(Operand_Typ
,
1442 Relocate_Node
(Expression
(N
))),
1443 Attribute_Name
=> Name_Address
))));
1449 end Expand_Interface_Conversion
;
1451 ------------------------------
1452 -- Expand_Interface_Actuals --
1453 ------------------------------
1455 procedure Expand_Interface_Actuals
(Call_Node
: Node_Id
) is
1457 Actual_Dup
: Node_Id
;
1458 Actual_Typ
: Entity_Id
;
1460 Conversion
: Node_Id
;
1462 Formal_Typ
: Entity_Id
;
1464 Formal_DDT
: Entity_Id
;
1465 Actual_DDT
: Entity_Id
;
1468 -- This subprogram is called directly from the semantics, so we need a
1469 -- check to see whether expansion is active before proceeding.
1471 if not Expander_Active
then
1475 -- Call using access to subprogram with explicit dereference
1477 if Nkind
(Name
(Call_Node
)) = N_Explicit_Dereference
then
1478 Subp
:= Etype
(Name
(Call_Node
));
1480 -- Call using selected component
1482 elsif Nkind
(Name
(Call_Node
)) = N_Selected_Component
then
1483 Subp
:= Entity
(Selector_Name
(Name
(Call_Node
)));
1485 -- Call using direct name
1488 Subp
:= Entity
(Name
(Call_Node
));
1491 -- Ada 2005 (AI-251): Look for interface type formals to force "this"
1494 Formal
:= First_Formal
(Subp
);
1495 Actual
:= First_Actual
(Call_Node
);
1496 while Present
(Formal
) loop
1497 Formal_Typ
:= Etype
(Formal
);
1499 if Ekind
(Formal_Typ
) = E_Record_Type_With_Private
then
1500 Formal_Typ
:= Full_View
(Formal_Typ
);
1503 if Is_Access_Type
(Formal_Typ
) then
1504 Formal_DDT
:= Directly_Designated_Type
(Formal_Typ
);
1507 Actual_Typ
:= Etype
(Actual
);
1509 if Is_Access_Type
(Actual_Typ
) then
1510 Actual_DDT
:= Directly_Designated_Type
(Actual_Typ
);
1513 if Is_Interface
(Formal_Typ
)
1514 and then Is_Class_Wide_Type
(Formal_Typ
)
1516 -- No need to displace the pointer if the type of the actual
1517 -- coincides with the type of the formal.
1519 if Actual_Typ
= Formal_Typ
then
1522 -- No need to displace the pointer if the interface type is a
1523 -- parent of the type of the actual because in this case the
1524 -- interface primitives are located in the primary dispatch table.
1526 elsif Is_Ancestor
(Formal_Typ
, Actual_Typ
,
1527 Use_Full_View
=> True)
1531 -- Implicit conversion to the class-wide formal type to force the
1532 -- displacement of the pointer.
1535 -- Normally, expansion of actuals for calls to build-in-place
1536 -- functions happens as part of Expand_Actuals, but in this
1537 -- case the call will be wrapped in a conversion and soon after
1538 -- expanded further to handle the displacement for a class-wide
1539 -- interface conversion, so if this is a BIP call then we need
1540 -- to handle it now.
1542 if Ada_Version
>= Ada_2005
1543 and then Is_Build_In_Place_Function_Call
(Actual
)
1545 Make_Build_In_Place_Call_In_Anonymous_Context
(Actual
);
1548 Conversion
:= Convert_To
(Formal_Typ
, Relocate_Node
(Actual
));
1549 Rewrite
(Actual
, Conversion
);
1550 Analyze_And_Resolve
(Actual
, Formal_Typ
);
1553 -- Access to class-wide interface type
1555 elsif Is_Access_Type
(Formal_Typ
)
1556 and then Is_Interface
(Formal_DDT
)
1557 and then Is_Class_Wide_Type
(Formal_DDT
)
1558 and then Interface_Present_In_Ancestor
1560 Iface
=> Etype
(Formal_DDT
))
1562 -- Handle attributes 'Access and 'Unchecked_Access
1564 if Nkind
(Actual
) = N_Attribute_Reference
1566 (Attribute_Name
(Actual
) = Name_Access
1567 or else Attribute_Name
(Actual
) = Name_Unchecked_Access
)
1569 -- This case must have been handled by the analysis and
1570 -- expansion of 'Access. The only exception is when types
1571 -- match and no further expansion is required.
1573 pragma Assert
(Base_Type
(Etype
(Prefix
(Actual
)))
1574 = Base_Type
(Formal_DDT
));
1577 -- No need to displace the pointer if the type of the actual
1578 -- coincides with the type of the formal.
1580 elsif Actual_DDT
= Formal_DDT
then
1583 -- No need to displace the pointer if the interface type is
1584 -- a parent of the type of the actual because in this case the
1585 -- interface primitives are located in the primary dispatch table.
1587 elsif Is_Ancestor
(Formal_DDT
, Actual_DDT
,
1588 Use_Full_View
=> True)
1593 Actual_Dup
:= Relocate_Node
(Actual
);
1595 if From_Limited_With
(Actual_Typ
) then
1597 -- If the type of the actual parameter comes from a
1598 -- limited with-clause and the non-limited view is already
1599 -- available, we replace the anonymous access type by
1600 -- a duplicate declaration whose designated type is the
1601 -- non-limited view.
1603 if Ekind
(Actual_DDT
) = E_Incomplete_Type
1604 and then Present
(Non_Limited_View
(Actual_DDT
))
1606 Anon
:= New_Copy
(Actual_Typ
);
1608 if Is_Itype
(Anon
) then
1609 Set_Scope
(Anon
, Current_Scope
);
1612 Set_Directly_Designated_Type
(Anon
,
1613 Non_Limited_View
(Actual_DDT
));
1614 Set_Etype
(Actual_Dup
, Anon
);
1616 elsif Is_Class_Wide_Type
(Actual_DDT
)
1617 and then Ekind
(Etype
(Actual_DDT
)) = E_Incomplete_Type
1618 and then Present
(Non_Limited_View
(Etype
(Actual_DDT
)))
1620 Anon
:= New_Copy
(Actual_Typ
);
1622 if Is_Itype
(Anon
) then
1623 Set_Scope
(Anon
, Current_Scope
);
1626 Set_Directly_Designated_Type
(Anon
,
1627 New_Copy
(Actual_DDT
));
1628 Set_Class_Wide_Type
(Directly_Designated_Type
(Anon
),
1629 New_Copy
(Class_Wide_Type
(Actual_DDT
)));
1630 Set_Etype
(Directly_Designated_Type
(Anon
),
1631 Non_Limited_View
(Etype
(Actual_DDT
)));
1633 Class_Wide_Type
(Directly_Designated_Type
(Anon
)),
1634 Non_Limited_View
(Etype
(Actual_DDT
)));
1635 Set_Etype
(Actual_Dup
, Anon
);
1639 Conversion
:= Convert_To
(Formal_Typ
, Actual_Dup
);
1640 Rewrite
(Actual
, Conversion
);
1641 Analyze_And_Resolve
(Actual
, Formal_Typ
);
1645 Next_Actual
(Actual
);
1646 Next_Formal
(Formal
);
1648 end Expand_Interface_Actuals
;
1650 ----------------------------
1651 -- Expand_Interface_Thunk --
1652 ----------------------------
1654 procedure Expand_Interface_Thunk
1656 Thunk_Id
: out Entity_Id
;
1657 Thunk_Code
: out Node_Id
)
1659 Loc
: constant Source_Ptr
:= Sloc
(Prim
);
1660 Actuals
: constant List_Id
:= New_List
;
1661 Decl
: constant List_Id
:= New_List
;
1662 Formals
: constant List_Id
:= New_List
;
1663 Target
: constant Entity_Id
:= Ultimate_Alias
(Prim
);
1670 Iface_Formal
: Node_Id
;
1672 Offset_To_Top
: Node_Id
;
1673 Target_Formal
: Entity_Id
;
1677 Thunk_Code
:= Empty
;
1679 -- No thunk needed if the primitive has been eliminated
1681 if Is_Eliminated
(Ultimate_Alias
(Prim
)) then
1684 -- In case of primitives that are functions without formals and a
1685 -- controlling result there is no need to build the thunk.
1687 elsif not Present
(First_Formal
(Target
)) then
1688 pragma Assert
(Ekind
(Target
) = E_Function
1689 and then Has_Controlling_Result
(Target
));
1693 -- Duplicate the formals of the Target primitive. In the thunk, the type
1694 -- of the controlling formal is the covered interface type (instead of
1695 -- the target tagged type). Done to avoid problems with discriminated
1696 -- tagged types because, if the controlling type has discriminants with
1697 -- default values, then the type conversions done inside the body of
1698 -- the thunk (after the displacement of the pointer to the base of the
1699 -- actual object) generate code that modify its contents.
1701 -- Note: This special management is not done for predefined primitives
1704 if not Is_Predefined_Dispatching_Operation
(Prim
) then
1705 Iface_Formal
:= First_Formal
(Interface_Alias
(Prim
));
1708 Formal
:= First_Formal
(Target
);
1709 while Present
(Formal
) loop
1710 Ftyp
:= Etype
(Formal
);
1712 -- Use the interface type as the type of the controlling formal (see
1715 if not Is_Controlling_Formal
(Formal
)
1716 or else Is_Predefined_Dispatching_Operation
(Prim
)
1718 Ftyp
:= Etype
(Formal
);
1719 Expr
:= New_Copy_Tree
(Expression
(Parent
(Formal
)));
1721 Ftyp
:= Etype
(Iface_Formal
);
1726 Make_Parameter_Specification
(Loc
,
1727 Defining_Identifier
=>
1728 Make_Defining_Identifier
(Sloc
(Formal
),
1729 Chars
=> Chars
(Formal
)),
1730 In_Present
=> In_Present
(Parent
(Formal
)),
1731 Out_Present
=> Out_Present
(Parent
(Formal
)),
1732 Parameter_Type
=> New_Occurrence_Of
(Ftyp
, Loc
),
1733 Expression
=> Expr
));
1735 if not Is_Predefined_Dispatching_Operation
(Prim
) then
1736 Next_Formal
(Iface_Formal
);
1739 Next_Formal
(Formal
);
1742 Target_Formal
:= First_Formal
(Target
);
1743 Formal
:= First
(Formals
);
1744 while Present
(Formal
) loop
1746 -- If the parent is a constrained discriminated type, then the
1747 -- primitive operation will have been defined on a first subtype.
1748 -- For proper matching with controlling type, use base type.
1750 if Ekind
(Target_Formal
) = E_In_Parameter
1751 and then Ekind
(Etype
(Target_Formal
)) = E_Anonymous_Access_Type
1754 Base_Type
(Directly_Designated_Type
(Etype
(Target_Formal
)));
1756 Ftyp
:= Base_Type
(Etype
(Target_Formal
));
1759 -- For concurrent types, the relevant information is found in the
1760 -- Corresponding_Record_Type, rather than the type entity itself.
1762 if Is_Concurrent_Type
(Ftyp
) then
1763 Ftyp
:= Corresponding_Record_Type
(Ftyp
);
1766 if Ekind
(Target_Formal
) = E_In_Parameter
1767 and then Ekind
(Etype
(Target_Formal
)) = E_Anonymous_Access_Type
1768 and then Is_Controlling_Formal
(Target_Formal
)
1771 -- type T is access all <<type of the target formal>>
1772 -- S : Storage_Offset := Storage_Offset!(Formal)
1773 -- - Offset_To_Top (address!(Formal))
1776 Make_Full_Type_Declaration
(Loc
,
1777 Defining_Identifier
=> Make_Temporary
(Loc
, 'T'),
1779 Make_Access_To_Object_Definition
(Loc
,
1780 All_Present
=> True,
1781 Null_Exclusion_Present
=> False,
1782 Constant_Present
=> False,
1783 Subtype_Indication
=>
1784 New_Occurrence_Of
(Ftyp
, Loc
)));
1787 Unchecked_Convert_To
(RTE
(RE_Address
),
1788 New_Occurrence_Of
(Defining_Identifier
(Formal
), Loc
));
1790 if not RTE_Available
(RE_Offset_To_Top
) then
1792 Build_Offset_To_Top
(Loc
, New_Arg
);
1795 Make_Function_Call
(Loc
,
1796 Name
=> New_Occurrence_Of
(RTE
(RE_Offset_To_Top
), Loc
),
1797 Parameter_Associations
=> New_List
(New_Arg
));
1801 Make_Object_Declaration
(Loc
,
1802 Defining_Identifier
=> Make_Temporary
(Loc
, 'S'),
1803 Constant_Present
=> True,
1804 Object_Definition
=>
1805 New_Occurrence_Of
(RTE
(RE_Storage_Offset
), Loc
),
1807 Make_Op_Subtract
(Loc
,
1809 Unchecked_Convert_To
1810 (RTE
(RE_Storage_Offset
),
1812 (Defining_Identifier
(Formal
), Loc
)),
1816 Append_To
(Decl
, Decl_2
);
1817 Append_To
(Decl
, Decl_1
);
1819 -- Reference the new actual. Generate:
1823 Unchecked_Convert_To
1824 (Defining_Identifier
(Decl_2
),
1825 New_Occurrence_Of
(Defining_Identifier
(Decl_1
), Loc
)));
1827 elsif Is_Controlling_Formal
(Target_Formal
) then
1830 -- S1 : Storage_Offset := Storage_Offset!(Formal'Address)
1831 -- - Offset_To_Top (Formal'Address)
1832 -- S2 : Addr_Ptr := Addr_Ptr!(S1)
1835 Make_Attribute_Reference
(Loc
,
1837 New_Occurrence_Of
(Defining_Identifier
(Formal
), Loc
),
1841 if not RTE_Available
(RE_Offset_To_Top
) then
1843 Build_Offset_To_Top
(Loc
, New_Arg
);
1846 Make_Function_Call
(Loc
,
1847 Name
=> New_Occurrence_Of
(RTE
(RE_Offset_To_Top
), Loc
),
1848 Parameter_Associations
=> New_List
(New_Arg
));
1852 Make_Object_Declaration
(Loc
,
1853 Defining_Identifier
=> Make_Temporary
(Loc
, 'S'),
1854 Constant_Present
=> True,
1855 Object_Definition
=>
1856 New_Occurrence_Of
(RTE
(RE_Storage_Offset
), Loc
),
1858 Make_Op_Subtract
(Loc
,
1860 Unchecked_Convert_To
1861 (RTE
(RE_Storage_Offset
),
1862 Make_Attribute_Reference
(Loc
,
1865 (Defining_Identifier
(Formal
), Loc
),
1866 Attribute_Name
=> Name_Address
)),
1871 Make_Object_Declaration
(Loc
,
1872 Defining_Identifier
=> Make_Temporary
(Loc
, 'S'),
1873 Constant_Present
=> True,
1874 Object_Definition
=>
1875 New_Occurrence_Of
(RTE
(RE_Addr_Ptr
), Loc
),
1877 Unchecked_Convert_To
1879 New_Occurrence_Of
(Defining_Identifier
(Decl_1
), Loc
)));
1881 Append_To
(Decl
, Decl_1
);
1882 Append_To
(Decl
, Decl_2
);
1884 -- Reference the new actual, generate:
1885 -- Target_Formal (S2.all)
1888 Unchecked_Convert_To
(Ftyp
,
1889 Make_Explicit_Dereference
(Loc
,
1890 New_Occurrence_Of
(Defining_Identifier
(Decl_2
), Loc
))));
1892 -- Ensure proper matching of access types. Required to avoid
1893 -- reporting spurious errors.
1895 elsif Is_Access_Type
(Etype
(Target_Formal
)) then
1897 Unchecked_Convert_To
(Base_Type
(Etype
(Target_Formal
)),
1898 New_Occurrence_Of
(Defining_Identifier
(Formal
), Loc
)));
1900 -- No special management required for this actual
1904 New_Occurrence_Of
(Defining_Identifier
(Formal
), Loc
));
1907 Next_Formal
(Target_Formal
);
1911 Thunk_Id
:= Make_Temporary
(Loc
, 'T');
1912 Set_Ekind
(Thunk_Id
, Ekind
(Prim
));
1913 Set_Is_Thunk
(Thunk_Id
);
1914 Set_Convention
(Thunk_Id
, Convention
(Prim
));
1915 Set_Thunk_Entity
(Thunk_Id
, Target
);
1919 if Ekind
(Target
) = E_Procedure
then
1921 Make_Subprogram_Body
(Loc
,
1923 Make_Procedure_Specification
(Loc
,
1924 Defining_Unit_Name
=> Thunk_Id
,
1925 Parameter_Specifications
=> Formals
),
1926 Declarations
=> Decl
,
1927 Handled_Statement_Sequence
=>
1928 Make_Handled_Sequence_Of_Statements
(Loc
,
1929 Statements
=> New_List
(
1930 Make_Procedure_Call_Statement
(Loc
,
1931 Name
=> New_Occurrence_Of
(Target
, Loc
),
1932 Parameter_Associations
=> Actuals
))));
1936 else pragma Assert
(Ekind
(Target
) = E_Function
);
1938 Result_Def
: Node_Id
;
1939 Call_Node
: Node_Id
;
1943 Make_Function_Call
(Loc
,
1944 Name
=> New_Occurrence_Of
(Target
, Loc
),
1945 Parameter_Associations
=> Actuals
);
1947 if not Is_Interface
(Etype
(Prim
)) then
1948 Result_Def
:= New_Copy
(Result_Definition
(Parent
(Target
)));
1950 -- Thunk of function returning a class-wide interface object. No
1951 -- extra displacement needed since the displacement is generated
1952 -- in the return statement of Prim. Example:
1954 -- type Iface is interface ...
1955 -- function F (O : Iface) return Iface'Class;
1957 -- type T is new ... and Iface with ...
1958 -- function F (O : T) return Iface'Class;
1960 elsif Is_Class_Wide_Type
(Etype
(Prim
)) then
1961 Result_Def
:= New_Occurrence_Of
(Etype
(Prim
), Loc
);
1963 -- Thunk of function returning an interface object. Displacement
1966 -- type Iface is interface ...
1967 -- function F (O : Iface) return Iface;
1969 -- type T is new ... and Iface with ...
1970 -- function F (O : T) return T;
1974 New_Occurrence_Of
(Class_Wide_Type
(Etype
(Prim
)), Loc
);
1976 -- Adding implicit conversion to force the displacement of
1977 -- the pointer to the object to reference the corresponding
1978 -- secondary dispatch table.
1981 Make_Type_Conversion
(Loc
,
1983 New_Occurrence_Of
(Class_Wide_Type
(Etype
(Prim
)), Loc
),
1984 Expression
=> Relocate_Node
(Call_Node
));
1988 Make_Subprogram_Body
(Loc
,
1990 Make_Function_Specification
(Loc
,
1991 Defining_Unit_Name
=> Thunk_Id
,
1992 Parameter_Specifications
=> Formals
,
1993 Result_Definition
=> Result_Def
),
1994 Declarations
=> Decl
,
1995 Handled_Statement_Sequence
=>
1996 Make_Handled_Sequence_Of_Statements
(Loc
,
1997 Statements
=> New_List
(
1998 Make_Simple_Return_Statement
(Loc
, Call_Node
))));
2001 end Expand_Interface_Thunk
;
2003 --------------------------
2004 -- Has_CPP_Constructors --
2005 --------------------------
2007 function Has_CPP_Constructors
(Typ
: Entity_Id
) return Boolean is
2011 -- Look for the constructor entities
2013 E
:= Next_Entity
(Typ
);
2014 while Present
(E
) loop
2015 if Ekind
(E
) = E_Function
and then Is_Constructor
(E
) then
2023 end Has_CPP_Constructors
;
2029 function Has_DT
(Typ
: Entity_Id
) return Boolean is
2031 return not Is_Interface
(Typ
)
2032 and then not Restriction_Active
(No_Dispatching_Calls
);
2035 ----------------------------------
2036 -- Is_Expanded_Dispatching_Call --
2037 ----------------------------------
2039 function Is_Expanded_Dispatching_Call
(N
: Node_Id
) return Boolean is
2041 return Nkind
(N
) in N_Subprogram_Call
2042 and then Nkind
(Name
(N
)) = N_Explicit_Dereference
2043 and then Is_Dispatch_Table_Entity
(Etype
(Name
(N
)));
2044 end Is_Expanded_Dispatching_Call
;
2046 -----------------------------------------
2047 -- Is_Predefined_Dispatching_Operation --
2048 -----------------------------------------
2050 function Is_Predefined_Dispatching_Operation
2051 (E
: Entity_Id
) return Boolean
2053 TSS_Name
: TSS_Name_Type
;
2056 if not Is_Dispatching_Operation
(E
) then
2060 Get_Name_String
(Chars
(E
));
2062 -- Most predefined primitives have internally generated names. Equality
2063 -- must be treated differently; the predefined operation is recognized
2064 -- as a homogeneous binary operator that returns Boolean.
2066 if Name_Len
> TSS_Name_Type
'Last then
2067 TSS_Name
:= TSS_Name_Type
(Name_Buffer
(Name_Len
- TSS_Name
'Length + 1
2069 if Chars
(E
) = Name_uSize
2070 or else TSS_Name
= TSS_Stream_Read
2071 or else TSS_Name
= TSS_Stream_Write
2072 or else TSS_Name
= TSS_Stream_Input
2073 or else TSS_Name
= TSS_Stream_Output
2075 (Chars
(E
) = Name_Op_Eq
2076 and then Etype
(First_Formal
(E
)) = Etype
(Last_Formal
(E
)))
2077 or else Chars
(E
) = Name_uAssign
2078 or else TSS_Name
= TSS_Deep_Adjust
2079 or else TSS_Name
= TSS_Deep_Finalize
2080 or else Is_Predefined_Interface_Primitive
(E
)
2087 end Is_Predefined_Dispatching_Operation
;
2089 ---------------------------------------
2090 -- Is_Predefined_Internal_Operation --
2091 ---------------------------------------
2093 function Is_Predefined_Internal_Operation
2094 (E
: Entity_Id
) return Boolean
2096 TSS_Name
: TSS_Name_Type
;
2099 if not Is_Dispatching_Operation
(E
) then
2103 Get_Name_String
(Chars
(E
));
2105 -- Most predefined primitives have internally generated names. Equality
2106 -- must be treated differently; the predefined operation is recognized
2107 -- as a homogeneous binary operator that returns Boolean.
2109 if Name_Len
> TSS_Name_Type
'Last then
2112 (Name_Buffer
(Name_Len
- TSS_Name
'Length + 1 .. Name_Len
));
2114 if Nam_In
(Chars
(E
), Name_uSize
, Name_uAssign
)
2116 (Chars
(E
) = Name_Op_Eq
2117 and then Etype
(First_Formal
(E
)) = Etype
(Last_Formal
(E
)))
2118 or else TSS_Name
= TSS_Deep_Adjust
2119 or else TSS_Name
= TSS_Deep_Finalize
2120 or else Is_Predefined_Interface_Primitive
(E
)
2127 end Is_Predefined_Internal_Operation
;
2129 -------------------------------------
2130 -- Is_Predefined_Dispatching_Alias --
2131 -------------------------------------
2133 function Is_Predefined_Dispatching_Alias
(Prim
: Entity_Id
) return Boolean
2136 return not Is_Predefined_Dispatching_Operation
(Prim
)
2137 and then Present
(Alias
(Prim
))
2138 and then Is_Predefined_Dispatching_Operation
(Ultimate_Alias
(Prim
));
2139 end Is_Predefined_Dispatching_Alias
;
2141 ---------------------------------------
2142 -- Is_Predefined_Interface_Primitive --
2143 ---------------------------------------
2145 function Is_Predefined_Interface_Primitive
(E
: Entity_Id
) return Boolean is
2147 -- In VM targets we don't restrict the functionality of this test to
2148 -- compiling in Ada 2005 mode since in VM targets any tagged type has
2149 -- these primitives.
2151 return (Ada_Version
>= Ada_2005
or else not Tagged_Type_Expansion
)
2152 and then Nam_In
(Chars
(E
), Name_uDisp_Asynchronous_Select
,
2153 Name_uDisp_Conditional_Select
,
2154 Name_uDisp_Get_Prim_Op_Kind
,
2155 Name_uDisp_Get_Task_Id
,
2157 Name_uDisp_Timed_Select
);
2158 end Is_Predefined_Interface_Primitive
;
2160 ----------------------------------------
2161 -- Make_Disp_Asynchronous_Select_Body --
2162 ----------------------------------------
2164 -- For interface types, generate:
2166 -- procedure _Disp_Asynchronous_Select
2167 -- (T : in out <Typ>;
2169 -- P : System.Address;
2170 -- B : out System.Storage_Elements.Dummy_Communication_Block;
2175 -- C := Ada.Tags.POK_Function;
2176 -- end _Disp_Asynchronous_Select;
2178 -- For protected types, generate:
2180 -- procedure _Disp_Asynchronous_Select
2181 -- (T : in out <Typ>;
2183 -- P : System.Address;
2184 -- B : out System.Storage_Elements.Dummy_Communication_Block;
2188 -- Ada.Tags.Get_Entry_Index (Ada.Tags.Tag (<Typ>VP, S));
2189 -- Bnn : System.Tasking.Protected_Objects.Operations.
2190 -- Communication_Block;
2192 -- System.Tasking.Protected_Objects.Operations.Protected_Entry_Call
2193 -- (T._object'Access,
2194 -- System.Tasking.Protected_Objects.Protected_Entry_Index (I),
2196 -- System.Tasking.Asynchronous_Call,
2198 -- B := System.Storage_Elements.Dummy_Communication_Block (Bnn);
2199 -- end _Disp_Asynchronous_Select;
2201 -- For task types, generate:
2203 -- procedure _Disp_Asynchronous_Select
2204 -- (T : in out <Typ>;
2206 -- P : System.Address;
2207 -- B : out System.Storage_Elements.Dummy_Communication_Block;
2211 -- Ada.Tags.Get_Entry_Index (Ada.Tags.Tag (<Typ>VP, S));
2213 -- System.Tasking.Rendezvous.Task_Entry_Call
2215 -- System.Tasking.Task_Entry_Index (I),
2217 -- System.Tasking.Asynchronous_Call,
2219 -- end _Disp_Asynchronous_Select;
2221 function Make_Disp_Asynchronous_Select_Body
2222 (Typ
: Entity_Id
) return Node_Id
2224 Com_Block
: Entity_Id
;
2225 Conc_Typ
: Entity_Id
:= Empty
;
2226 Decls
: constant List_Id
:= New_List
;
2227 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
2229 Stmts
: constant List_Id
:= New_List
;
2233 pragma Assert
(not Restriction_Active
(No_Dispatching_Calls
));
2235 -- Null body is generated for interface types
2237 if Is_Interface
(Typ
) then
2239 Make_Subprogram_Body
(Loc
,
2241 Make_Disp_Asynchronous_Select_Spec
(Typ
),
2242 Declarations
=> New_List
,
2243 Handled_Statement_Sequence
=>
2244 Make_Handled_Sequence_Of_Statements
(Loc
,
2246 Make_Assignment_Statement
(Loc
,
2247 Name
=> Make_Identifier
(Loc
, Name_uF
),
2248 Expression
=> New_Occurrence_Of
(Standard_False
, Loc
)))));
2251 if Is_Concurrent_Record_Type
(Typ
) then
2252 Conc_Typ
:= Corresponding_Concurrent_Type
(Typ
);
2256 -- Ada.Tags.Get_Entry_Index (Ada.Tags.Tag! (<type>VP), S);
2258 -- where I will be used to capture the entry index of the primitive
2259 -- wrapper at position S.
2261 if Tagged_Type_Expansion
then
2263 Unchecked_Convert_To
(RTE
(RE_Tag
),
2265 (Node
(First_Elmt
(Access_Disp_Table
(Typ
))), Loc
));
2268 Make_Attribute_Reference
(Loc
,
2269 Prefix
=> New_Occurrence_Of
(Typ
, Loc
),
2270 Attribute_Name
=> Name_Tag
);
2274 Make_Object_Declaration
(Loc
,
2275 Defining_Identifier
=>
2276 Make_Defining_Identifier
(Loc
, Name_uI
),
2277 Object_Definition
=>
2278 New_Occurrence_Of
(Standard_Integer
, Loc
),
2280 Make_Function_Call
(Loc
,
2282 New_Occurrence_Of
(RTE
(RE_Get_Entry_Index
), Loc
),
2283 Parameter_Associations
=>
2284 New_List
(Tag_Node
, Make_Identifier
(Loc
, Name_uS
)))));
2286 if Ekind
(Conc_Typ
) = E_Protected_Type
then
2289 -- Bnn : Communication_Block;
2291 Com_Block
:= Make_Temporary
(Loc
, 'B');
2293 Make_Object_Declaration
(Loc
,
2294 Defining_Identifier
=> Com_Block
,
2295 Object_Definition
=>
2296 New_Occurrence_Of
(RTE
(RE_Communication_Block
), Loc
)));
2298 -- Build T._object'Access for calls below
2301 Make_Attribute_Reference
(Loc
,
2302 Attribute_Name
=> Name_Unchecked_Access
,
2304 Make_Selected_Component
(Loc
,
2305 Prefix
=> Make_Identifier
(Loc
, Name_uT
),
2306 Selector_Name
=> Make_Identifier
(Loc
, Name_uObject
)));
2308 case Corresponding_Runtime_Package
(Conc_Typ
) is
2309 when System_Tasking_Protected_Objects_Entries
=>
2312 -- Protected_Entry_Call
2313 -- (T._object'Access, -- Object
2314 -- Protected_Entry_Index! (I), -- E
2315 -- P, -- Uninterpreted_Data
2316 -- Asynchronous_Call, -- Mode
2317 -- Bnn); -- Communication_Block
2319 -- where T is the protected object, I is the entry index, P
2320 -- is the wrapped parameters and B is the name of the
2321 -- communication block.
2324 Make_Procedure_Call_Statement
(Loc
,
2326 New_Occurrence_Of
(RTE
(RE_Protected_Entry_Call
), Loc
),
2327 Parameter_Associations
=>
2331 Make_Unchecked_Type_Conversion
(Loc
, -- entry index
2334 (RTE
(RE_Protected_Entry_Index
), Loc
),
2335 Expression
=> Make_Identifier
(Loc
, Name_uI
)),
2337 Make_Identifier
(Loc
, Name_uP
), -- parameter block
2338 New_Occurrence_Of
-- Asynchronous_Call
2339 (RTE
(RE_Asynchronous_Call
), Loc
),
2340 New_Occurrence_Of
-- comm block
2341 (Com_Block
, Loc
))));
2344 raise Program_Error
;
2348 -- B := Dummy_Communication_Block (Bnn);
2351 Make_Assignment_Statement
(Loc
,
2352 Name
=> Make_Identifier
(Loc
, Name_uB
),
2354 Make_Unchecked_Type_Conversion
(Loc
,
2357 (RTE
(RE_Dummy_Communication_Block
), Loc
),
2358 Expression
=> New_Occurrence_Of
(Com_Block
, Loc
))));
2364 Make_Assignment_Statement
(Loc
,
2365 Name
=> Make_Identifier
(Loc
, Name_uF
),
2366 Expression
=> New_Occurrence_Of
(Standard_False
, Loc
)));
2369 pragma Assert
(Ekind
(Conc_Typ
) = E_Task_Type
);
2373 -- (T._task_id, -- Acceptor
2374 -- Task_Entry_Index! (I), -- E
2375 -- P, -- Uninterpreted_Data
2376 -- Asynchronous_Call, -- Mode
2377 -- F); -- Rendezvous_Successful
2379 -- where T is the task object, I is the entry index, P is the
2380 -- wrapped parameters and F is the status flag.
2383 Make_Procedure_Call_Statement
(Loc
,
2385 New_Occurrence_Of
(RTE
(RE_Task_Entry_Call
), Loc
),
2386 Parameter_Associations
=>
2388 Make_Selected_Component
(Loc
, -- T._task_id
2389 Prefix
=> Make_Identifier
(Loc
, Name_uT
),
2390 Selector_Name
=> Make_Identifier
(Loc
, Name_uTask_Id
)),
2392 Make_Unchecked_Type_Conversion
(Loc
, -- entry index
2394 New_Occurrence_Of
(RTE
(RE_Task_Entry_Index
), Loc
),
2395 Expression
=> Make_Identifier
(Loc
, Name_uI
)),
2397 Make_Identifier
(Loc
, Name_uP
), -- parameter block
2398 New_Occurrence_Of
-- Asynchronous_Call
2399 (RTE
(RE_Asynchronous_Call
), Loc
),
2400 Make_Identifier
(Loc
, Name_uF
)))); -- status flag
2404 -- Ensure that the statements list is non-empty
2407 Make_Assignment_Statement
(Loc
,
2408 Name
=> Make_Identifier
(Loc
, Name_uF
),
2409 Expression
=> New_Occurrence_Of
(Standard_False
, Loc
)));
2413 Make_Subprogram_Body
(Loc
,
2415 Make_Disp_Asynchronous_Select_Spec
(Typ
),
2416 Declarations
=> Decls
,
2417 Handled_Statement_Sequence
=>
2418 Make_Handled_Sequence_Of_Statements
(Loc
, Stmts
));
2419 end Make_Disp_Asynchronous_Select_Body
;
2421 ----------------------------------------
2422 -- Make_Disp_Asynchronous_Select_Spec --
2423 ----------------------------------------
2425 function Make_Disp_Asynchronous_Select_Spec
2426 (Typ
: Entity_Id
) return Node_Id
2428 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
2429 Def_Id
: constant Node_Id
:=
2430 Make_Defining_Identifier
(Loc
,
2431 Name_uDisp_Asynchronous_Select
);
2432 Params
: constant List_Id
:= New_List
;
2435 pragma Assert
(not Restriction_Active
(No_Dispatching_Calls
));
2437 -- T : in out Typ; -- Object parameter
2438 -- S : Integer; -- Primitive operation slot
2439 -- P : Address; -- Wrapped parameters
2440 -- B : out Dummy_Communication_Block; -- Communication block dummy
2441 -- F : out Boolean; -- Status flag
2443 Append_List_To
(Params
, New_List
(
2445 Make_Parameter_Specification
(Loc
,
2446 Defining_Identifier
=> Make_Defining_Identifier
(Loc
, Name_uT
),
2447 Parameter_Type
=> New_Occurrence_Of
(Typ
, Loc
),
2449 Out_Present
=> True),
2451 Make_Parameter_Specification
(Loc
,
2452 Defining_Identifier
=> Make_Defining_Identifier
(Loc
, Name_uS
),
2453 Parameter_Type
=> New_Occurrence_Of
(Standard_Integer
, Loc
)),
2455 Make_Parameter_Specification
(Loc
,
2456 Defining_Identifier
=> Make_Defining_Identifier
(Loc
, Name_uP
),
2457 Parameter_Type
=> New_Occurrence_Of
(RTE
(RE_Address
), Loc
)),
2459 Make_Parameter_Specification
(Loc
,
2460 Defining_Identifier
=> Make_Defining_Identifier
(Loc
, Name_uB
),
2462 New_Occurrence_Of
(RTE
(RE_Dummy_Communication_Block
), Loc
),
2463 Out_Present
=> True),
2465 Make_Parameter_Specification
(Loc
,
2466 Defining_Identifier
=> Make_Defining_Identifier
(Loc
, Name_uF
),
2467 Parameter_Type
=> New_Occurrence_Of
(Standard_Boolean
, Loc
),
2468 Out_Present
=> True)));
2471 Make_Procedure_Specification
(Loc
,
2472 Defining_Unit_Name
=> Def_Id
,
2473 Parameter_Specifications
=> Params
);
2474 end Make_Disp_Asynchronous_Select_Spec
;
2476 ---------------------------------------
2477 -- Make_Disp_Conditional_Select_Body --
2478 ---------------------------------------
2480 -- For interface types, generate:
2482 -- procedure _Disp_Conditional_Select
2483 -- (T : in out <Typ>;
2485 -- P : System.Address;
2486 -- C : out Ada.Tags.Prim_Op_Kind;
2491 -- C := Ada.Tags.POK_Function;
2492 -- end _Disp_Conditional_Select;
2494 -- For protected types, generate:
2496 -- procedure _Disp_Conditional_Select
2497 -- (T : in out <Typ>;
2499 -- P : System.Address;
2500 -- C : out Ada.Tags.Prim_Op_Kind;
2504 -- Bnn : System.Tasking.Protected_Objects.Operations.
2505 -- Communication_Block;
2508 -- C := Ada.Tags.Get_Prim_Op_Kind (Ada.Tags.Tag (<Typ>VP, S));
2510 -- if C = Ada.Tags.POK_Procedure
2511 -- or else C = Ada.Tags.POK_Protected_Procedure
2512 -- or else C = Ada.Tags.POK_Task_Procedure
2518 -- I := Ada.Tags.Get_Entry_Index (Ada.Tags.Tag (<Typ>VP, S));
2519 -- System.Tasking.Protected_Objects.Operations.Protected_Entry_Call
2520 -- (T.object'Access,
2521 -- System.Tasking.Protected_Objects.Protected_Entry_Index (I),
2523 -- System.Tasking.Conditional_Call,
2525 -- F := not Cancelled (Bnn);
2526 -- end _Disp_Conditional_Select;
2528 -- For task types, generate:
2530 -- procedure _Disp_Conditional_Select
2531 -- (T : in out <Typ>;
2533 -- P : System.Address;
2534 -- C : out Ada.Tags.Prim_Op_Kind;
2540 -- I := Ada.Tags.Get_Entry_Index (Ada.Tags.Tag (<Typ>VP, S));
2541 -- System.Tasking.Rendezvous.Task_Entry_Call
2543 -- System.Tasking.Task_Entry_Index (I),
2545 -- System.Tasking.Conditional_Call,
2547 -- end _Disp_Conditional_Select;
2549 function Make_Disp_Conditional_Select_Body
2550 (Typ
: Entity_Id
) return Node_Id
2552 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
2553 Blk_Nam
: Entity_Id
;
2554 Conc_Typ
: Entity_Id
:= Empty
;
2555 Decls
: constant List_Id
:= New_List
;
2557 Stmts
: constant List_Id
:= New_List
;
2561 pragma Assert
(not Restriction_Active
(No_Dispatching_Calls
));
2563 -- Null body is generated for interface types
2565 if Is_Interface
(Typ
) then
2567 Make_Subprogram_Body
(Loc
,
2569 Make_Disp_Conditional_Select_Spec
(Typ
),
2570 Declarations
=> No_List
,
2571 Handled_Statement_Sequence
=>
2572 Make_Handled_Sequence_Of_Statements
(Loc
,
2573 New_List
(Make_Assignment_Statement
(Loc
,
2574 Name
=> Make_Identifier
(Loc
, Name_uF
),
2575 Expression
=> New_Occurrence_Of
(Standard_False
, Loc
)))));
2578 if Is_Concurrent_Record_Type
(Typ
) then
2579 Conc_Typ
:= Corresponding_Concurrent_Type
(Typ
);
2584 -- where I will be used to capture the entry index of the primitive
2585 -- wrapper at position S.
2588 Make_Object_Declaration
(Loc
,
2589 Defining_Identifier
=> Make_Defining_Identifier
(Loc
, Name_uI
),
2590 Object_Definition
=>
2591 New_Occurrence_Of
(Standard_Integer
, Loc
)));
2594 -- C := Ada.Tags.Get_Prim_Op_Kind (Ada.Tags.Tag! (<type>VP), S);
2596 -- if C = POK_Procedure
2597 -- or else C = POK_Protected_Procedure
2598 -- or else C = POK_Task_Procedure;
2604 Build_Common_Dispatching_Select_Statements
(Typ
, Stmts
);
2607 -- Bnn : Communication_Block;
2609 -- where Bnn is the name of the communication block used in the
2610 -- call to Protected_Entry_Call.
2612 Blk_Nam
:= Make_Temporary
(Loc
, 'B');
2614 Make_Object_Declaration
(Loc
,
2615 Defining_Identifier
=> Blk_Nam
,
2616 Object_Definition
=>
2617 New_Occurrence_Of
(RTE
(RE_Communication_Block
), Loc
)));
2620 -- I := Ada.Tags.Get_Entry_Index (Ada.Tags.Tag! (<type>VP), S);
2622 -- I is the entry index and S is the dispatch table slot
2624 if Tagged_Type_Expansion
then
2626 Unchecked_Convert_To
(RTE
(RE_Tag
),
2628 (Node
(First_Elmt
(Access_Disp_Table
(Typ
))), Loc
));
2632 Make_Attribute_Reference
(Loc
,
2633 Prefix
=> New_Occurrence_Of
(Typ
, Loc
),
2634 Attribute_Name
=> Name_Tag
);
2638 Make_Assignment_Statement
(Loc
,
2639 Name
=> Make_Identifier
(Loc
, Name_uI
),
2641 Make_Function_Call
(Loc
,
2643 New_Occurrence_Of
(RTE
(RE_Get_Entry_Index
), Loc
),
2644 Parameter_Associations
=> New_List
(
2646 Make_Identifier
(Loc
, Name_uS
)))));
2648 if Ekind
(Conc_Typ
) = E_Protected_Type
then
2650 Obj_Ref
:= -- T._object'Access
2651 Make_Attribute_Reference
(Loc
,
2652 Attribute_Name
=> Name_Unchecked_Access
,
2654 Make_Selected_Component
(Loc
,
2655 Prefix
=> Make_Identifier
(Loc
, Name_uT
),
2656 Selector_Name
=> Make_Identifier
(Loc
, Name_uObject
)));
2658 case Corresponding_Runtime_Package
(Conc_Typ
) is
2659 when System_Tasking_Protected_Objects_Entries
=>
2662 -- Protected_Entry_Call
2663 -- (T._object'Access, -- Object
2664 -- Protected_Entry_Index! (I), -- E
2665 -- P, -- Uninterpreted_Data
2666 -- Conditional_Call, -- Mode
2669 -- where T is the protected object, I is the entry index, P
2670 -- are the wrapped parameters and Bnn is the name of the
2671 -- communication block.
2674 Make_Procedure_Call_Statement
(Loc
,
2676 New_Occurrence_Of
(RTE
(RE_Protected_Entry_Call
), Loc
),
2677 Parameter_Associations
=> New_List
(
2680 Make_Unchecked_Type_Conversion
(Loc
, -- entry index
2683 (RTE
(RE_Protected_Entry_Index
), Loc
),
2684 Expression
=> Make_Identifier
(Loc
, Name_uI
)),
2686 Make_Identifier
(Loc
, Name_uP
), -- parameter block
2688 New_Occurrence_Of
-- Conditional_Call
2689 (RTE
(RE_Conditional_Call
), Loc
),
2690 New_Occurrence_Of
-- Bnn
2693 when System_Tasking_Protected_Objects_Single_Entry
=>
2695 -- If we are compiling for a restricted run-time, the call
2696 -- uses the simpler form.
2699 Make_Procedure_Call_Statement
(Loc
,
2702 (RTE
(RE_Protected_Single_Entry_Call
), Loc
),
2703 Parameter_Associations
=> New_List
(
2706 Make_Attribute_Reference
(Loc
,
2707 Prefix
=> Make_Identifier
(Loc
, Name_uP
),
2708 Attribute_Name
=> Name_Address
),
2711 (RTE
(RE_Conditional_Call
), Loc
))));
2713 raise Program_Error
;
2717 -- F := not Cancelled (Bnn);
2719 -- where F is the success flag. The status of Cancelled is negated
2720 -- in order to match the behaviour of the version for task types.
2723 Make_Assignment_Statement
(Loc
,
2724 Name
=> Make_Identifier
(Loc
, Name_uF
),
2728 Make_Function_Call
(Loc
,
2730 New_Occurrence_Of
(RTE
(RE_Cancelled
), Loc
),
2731 Parameter_Associations
=> New_List
(
2732 New_Occurrence_Of
(Blk_Nam
, Loc
))))));
2734 pragma Assert
(Ekind
(Conc_Typ
) = E_Task_Type
);
2738 -- (T._task_id, -- Acceptor
2739 -- Task_Entry_Index! (I), -- E
2740 -- P, -- Uninterpreted_Data
2741 -- Conditional_Call, -- Mode
2742 -- F); -- Rendezvous_Successful
2744 -- where T is the task object, I is the entry index, P are the
2745 -- wrapped parameters and F is the status flag.
2748 Make_Procedure_Call_Statement
(Loc
,
2750 New_Occurrence_Of
(RTE
(RE_Task_Entry_Call
), Loc
),
2751 Parameter_Associations
=> New_List
(
2753 Make_Selected_Component
(Loc
, -- T._task_id
2754 Prefix
=> Make_Identifier
(Loc
, Name_uT
),
2755 Selector_Name
=> Make_Identifier
(Loc
, Name_uTask_Id
)),
2757 Make_Unchecked_Type_Conversion
(Loc
, -- entry index
2759 New_Occurrence_Of
(RTE
(RE_Task_Entry_Index
), Loc
),
2760 Expression
=> Make_Identifier
(Loc
, Name_uI
)),
2762 Make_Identifier
(Loc
, Name_uP
), -- parameter block
2763 New_Occurrence_Of
-- Conditional_Call
2764 (RTE
(RE_Conditional_Call
), Loc
),
2765 Make_Identifier
(Loc
, Name_uF
)))); -- status flag
2769 -- Initialize out parameters
2772 Make_Assignment_Statement
(Loc
,
2773 Name
=> Make_Identifier
(Loc
, Name_uF
),
2774 Expression
=> New_Occurrence_Of
(Standard_False
, Loc
)));
2776 Make_Assignment_Statement
(Loc
,
2777 Name
=> Make_Identifier
(Loc
, Name_uC
),
2778 Expression
=> New_Occurrence_Of
(RTE
(RE_POK_Function
), Loc
)));
2782 Make_Subprogram_Body
(Loc
,
2784 Make_Disp_Conditional_Select_Spec
(Typ
),
2785 Declarations
=> Decls
,
2786 Handled_Statement_Sequence
=>
2787 Make_Handled_Sequence_Of_Statements
(Loc
, Stmts
));
2788 end Make_Disp_Conditional_Select_Body
;
2790 ---------------------------------------
2791 -- Make_Disp_Conditional_Select_Spec --
2792 ---------------------------------------
2794 function Make_Disp_Conditional_Select_Spec
2795 (Typ
: Entity_Id
) return Node_Id
2797 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
2798 Def_Id
: constant Node_Id
:=
2799 Make_Defining_Identifier
(Loc
,
2800 Name_uDisp_Conditional_Select
);
2801 Params
: constant List_Id
:= New_List
;
2804 pragma Assert
(not Restriction_Active
(No_Dispatching_Calls
));
2806 -- T : in out Typ; -- Object parameter
2807 -- S : Integer; -- Primitive operation slot
2808 -- P : Address; -- Wrapped parameters
2809 -- C : out Prim_Op_Kind; -- Call kind
2810 -- F : out Boolean; -- Status flag
2812 Append_List_To
(Params
, New_List
(
2814 Make_Parameter_Specification
(Loc
,
2815 Defining_Identifier
=> Make_Defining_Identifier
(Loc
, Name_uT
),
2816 Parameter_Type
=> New_Occurrence_Of
(Typ
, Loc
),
2818 Out_Present
=> True),
2820 Make_Parameter_Specification
(Loc
,
2821 Defining_Identifier
=> Make_Defining_Identifier
(Loc
, Name_uS
),
2822 Parameter_Type
=> New_Occurrence_Of
(Standard_Integer
, Loc
)),
2824 Make_Parameter_Specification
(Loc
,
2825 Defining_Identifier
=> Make_Defining_Identifier
(Loc
, Name_uP
),
2826 Parameter_Type
=> New_Occurrence_Of
(RTE
(RE_Address
), Loc
)),
2828 Make_Parameter_Specification
(Loc
,
2829 Defining_Identifier
=> Make_Defining_Identifier
(Loc
, Name_uC
),
2831 New_Occurrence_Of
(RTE
(RE_Prim_Op_Kind
), Loc
),
2832 Out_Present
=> True),
2834 Make_Parameter_Specification
(Loc
,
2835 Defining_Identifier
=> Make_Defining_Identifier
(Loc
, Name_uF
),
2836 Parameter_Type
=> New_Occurrence_Of
(Standard_Boolean
, Loc
),
2837 Out_Present
=> True)));
2840 Make_Procedure_Specification
(Loc
,
2841 Defining_Unit_Name
=> Def_Id
,
2842 Parameter_Specifications
=> Params
);
2843 end Make_Disp_Conditional_Select_Spec
;
2845 -------------------------------------
2846 -- Make_Disp_Get_Prim_Op_Kind_Body --
2847 -------------------------------------
2849 function Make_Disp_Get_Prim_Op_Kind_Body
(Typ
: Entity_Id
) return Node_Id
is
2850 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
2854 pragma Assert
(not Restriction_Active
(No_Dispatching_Calls
));
2856 if Is_Interface
(Typ
) then
2858 Make_Subprogram_Body
(Loc
,
2860 Make_Disp_Get_Prim_Op_Kind_Spec
(Typ
),
2861 Declarations
=> New_List
,
2862 Handled_Statement_Sequence
=>
2863 Make_Handled_Sequence_Of_Statements
(Loc
,
2864 New_List
(Make_Null_Statement
(Loc
))));
2868 -- C := get_prim_op_kind (tag! (<type>VP), S);
2870 -- where C is the out parameter capturing the call kind and S is the
2871 -- dispatch table slot number.
2873 if Tagged_Type_Expansion
then
2875 Unchecked_Convert_To
(RTE
(RE_Tag
),
2877 (Node
(First_Elmt
(Access_Disp_Table
(Typ
))), Loc
));
2881 Make_Attribute_Reference
(Loc
,
2882 Prefix
=> New_Occurrence_Of
(Typ
, Loc
),
2883 Attribute_Name
=> Name_Tag
);
2887 Make_Subprogram_Body
(Loc
,
2889 Make_Disp_Get_Prim_Op_Kind_Spec
(Typ
),
2890 Declarations
=> New_List
,
2891 Handled_Statement_Sequence
=>
2892 Make_Handled_Sequence_Of_Statements
(Loc
,
2894 Make_Assignment_Statement
(Loc
,
2895 Name
=> Make_Identifier
(Loc
, Name_uC
),
2897 Make_Function_Call
(Loc
,
2899 New_Occurrence_Of
(RTE
(RE_Get_Prim_Op_Kind
), Loc
),
2900 Parameter_Associations
=> New_List
(
2902 Make_Identifier
(Loc
, Name_uS
)))))));
2903 end Make_Disp_Get_Prim_Op_Kind_Body
;
2905 -------------------------------------
2906 -- Make_Disp_Get_Prim_Op_Kind_Spec --
2907 -------------------------------------
2909 function Make_Disp_Get_Prim_Op_Kind_Spec
2910 (Typ
: Entity_Id
) return Node_Id
2912 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
2913 Def_Id
: constant Node_Id
:=
2914 Make_Defining_Identifier
(Loc
, Name_uDisp_Get_Prim_Op_Kind
);
2915 Params
: constant List_Id
:= New_List
;
2918 pragma Assert
(not Restriction_Active
(No_Dispatching_Calls
));
2920 -- T : in out Typ; -- Object parameter
2921 -- S : Integer; -- Primitive operation slot
2922 -- C : out Prim_Op_Kind; -- Call kind
2924 Append_List_To
(Params
, New_List
(
2926 Make_Parameter_Specification
(Loc
,
2927 Defining_Identifier
=> Make_Defining_Identifier
(Loc
, Name_uT
),
2928 Parameter_Type
=> New_Occurrence_Of
(Typ
, Loc
),
2930 Out_Present
=> True),
2932 Make_Parameter_Specification
(Loc
,
2933 Defining_Identifier
=> Make_Defining_Identifier
(Loc
, Name_uS
),
2934 Parameter_Type
=> New_Occurrence_Of
(Standard_Integer
, Loc
)),
2936 Make_Parameter_Specification
(Loc
,
2937 Defining_Identifier
=> Make_Defining_Identifier
(Loc
, Name_uC
),
2939 New_Occurrence_Of
(RTE
(RE_Prim_Op_Kind
), Loc
),
2940 Out_Present
=> True)));
2943 Make_Procedure_Specification
(Loc
,
2944 Defining_Unit_Name
=> Def_Id
,
2945 Parameter_Specifications
=> Params
);
2946 end Make_Disp_Get_Prim_Op_Kind_Spec
;
2948 --------------------------------
2949 -- Make_Disp_Get_Task_Id_Body --
2950 --------------------------------
2952 function Make_Disp_Get_Task_Id_Body
2953 (Typ
: Entity_Id
) return Node_Id
2955 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
2959 pragma Assert
(not Restriction_Active
(No_Dispatching_Calls
));
2961 if Is_Concurrent_Record_Type
(Typ
)
2962 and then Ekind
(Corresponding_Concurrent_Type
(Typ
)) = E_Task_Type
2965 -- return To_Address (_T._task_id);
2968 Make_Simple_Return_Statement
(Loc
,
2970 Make_Unchecked_Type_Conversion
(Loc
,
2971 Subtype_Mark
=> New_Occurrence_Of
(RTE
(RE_Address
), Loc
),
2973 Make_Selected_Component
(Loc
,
2974 Prefix
=> Make_Identifier
(Loc
, Name_uT
),
2975 Selector_Name
=> Make_Identifier
(Loc
, Name_uTask_Id
))));
2977 -- A null body is constructed for non-task types
2981 -- return Null_Address;
2984 Make_Simple_Return_Statement
(Loc
,
2985 Expression
=> New_Occurrence_Of
(RTE
(RE_Null_Address
), Loc
));
2989 Make_Subprogram_Body
(Loc
,
2990 Specification
=> Make_Disp_Get_Task_Id_Spec
(Typ
),
2991 Declarations
=> New_List
,
2992 Handled_Statement_Sequence
=>
2993 Make_Handled_Sequence_Of_Statements
(Loc
, New_List
(Ret
)));
2994 end Make_Disp_Get_Task_Id_Body
;
2996 --------------------------------
2997 -- Make_Disp_Get_Task_Id_Spec --
2998 --------------------------------
3000 function Make_Disp_Get_Task_Id_Spec
3001 (Typ
: Entity_Id
) return Node_Id
3003 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
3006 pragma Assert
(not Restriction_Active
(No_Dispatching_Calls
));
3009 Make_Function_Specification
(Loc
,
3010 Defining_Unit_Name
=>
3011 Make_Defining_Identifier
(Loc
, Name_uDisp_Get_Task_Id
),
3012 Parameter_Specifications
=> New_List
(
3013 Make_Parameter_Specification
(Loc
,
3014 Defining_Identifier
=> Make_Defining_Identifier
(Loc
, Name_uT
),
3015 Parameter_Type
=> New_Occurrence_Of
(Typ
, Loc
))),
3016 Result_Definition
=>
3017 New_Occurrence_Of
(RTE
(RE_Address
), Loc
));
3018 end Make_Disp_Get_Task_Id_Spec
;
3020 ----------------------------
3021 -- Make_Disp_Requeue_Body --
3022 ----------------------------
3024 function Make_Disp_Requeue_Body
3025 (Typ
: Entity_Id
) return Node_Id
3027 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
3028 Conc_Typ
: Entity_Id
:= Empty
;
3029 Stmts
: constant List_Id
:= New_List
;
3032 pragma Assert
(not Restriction_Active
(No_Dispatching_Calls
));
3034 -- Null body is generated for interface types and non-concurrent
3037 if Is_Interface
(Typ
)
3038 or else not Is_Concurrent_Record_Type
(Typ
)
3041 Make_Subprogram_Body
(Loc
,
3042 Specification
=> Make_Disp_Requeue_Spec
(Typ
),
3043 Declarations
=> No_List
,
3044 Handled_Statement_Sequence
=>
3045 Make_Handled_Sequence_Of_Statements
(Loc
,
3046 New_List
(Make_Null_Statement
(Loc
))));
3049 Conc_Typ
:= Corresponding_Concurrent_Type
(Typ
);
3051 if Ekind
(Conc_Typ
) = E_Protected_Type
then
3053 -- Generate statements:
3055 -- System.Tasking.Protected_Objects.Operations.
3056 -- Requeue_Protected_Entry
3057 -- (Protection_Entries_Access (P),
3058 -- O._object'Unchecked_Access,
3059 -- Protected_Entry_Index (I),
3062 -- System.Tasking.Protected_Objects.Operations.
3063 -- Requeue_Task_To_Protected_Entry
3064 -- (O._object'Unchecked_Access,
3065 -- Protected_Entry_Index (I),
3069 if Restriction_Active
(No_Entry_Queue
) then
3070 Append_To
(Stmts
, Make_Null_Statement
(Loc
));
3073 Make_If_Statement
(Loc
,
3074 Condition
=> Make_Identifier
(Loc
, Name_uF
),
3079 -- Call to Requeue_Protected_Entry
3081 Make_Procedure_Call_Statement
(Loc
,
3084 (RTE
(RE_Requeue_Protected_Entry
), Loc
),
3085 Parameter_Associations
=>
3088 Make_Unchecked_Type_Conversion
(Loc
, -- PEA (P)
3091 RTE
(RE_Protection_Entries_Access
), Loc
),
3093 Make_Identifier
(Loc
, Name_uP
)),
3095 Make_Attribute_Reference
(Loc
, -- O._object'Acc
3097 Name_Unchecked_Access
,
3099 Make_Selected_Component
(Loc
,
3101 Make_Identifier
(Loc
, Name_uO
),
3103 Make_Identifier
(Loc
, Name_uObject
))),
3105 Make_Unchecked_Type_Conversion
(Loc
, -- entry index
3108 (RTE
(RE_Protected_Entry_Index
), Loc
),
3109 Expression
=> Make_Identifier
(Loc
, Name_uI
)),
3111 Make_Identifier
(Loc
, Name_uA
)))), -- abort status
3116 -- Call to Requeue_Task_To_Protected_Entry
3118 Make_Procedure_Call_Statement
(Loc
,
3121 (RTE
(RE_Requeue_Task_To_Protected_Entry
), Loc
),
3122 Parameter_Associations
=>
3125 Make_Attribute_Reference
(Loc
, -- O._object'Acc
3126 Attribute_Name
=> Name_Unchecked_Access
,
3128 Make_Selected_Component
(Loc
,
3130 Make_Identifier
(Loc
, Name_uO
),
3132 Make_Identifier
(Loc
, Name_uObject
))),
3134 Make_Unchecked_Type_Conversion
(Loc
, -- entry index
3137 (RTE
(RE_Protected_Entry_Index
), Loc
),
3138 Expression
=> Make_Identifier
(Loc
, Name_uI
)),
3140 Make_Identifier
(Loc
, Name_uA
)))))); -- abort status
3144 pragma Assert
(Is_Task_Type
(Conc_Typ
));
3148 -- System.Tasking.Rendezvous.Requeue_Protected_To_Task_Entry
3149 -- (Protection_Entries_Access (P),
3151 -- Task_Entry_Index (I),
3154 -- System.Tasking.Rendezvous.Requeue_Task_Entry
3156 -- Task_Entry_Index (I),
3161 Make_If_Statement
(Loc
,
3162 Condition
=> Make_Identifier
(Loc
, Name_uF
),
3164 Then_Statements
=> New_List
(
3166 -- Call to Requeue_Protected_To_Task_Entry
3168 Make_Procedure_Call_Statement
(Loc
,
3171 (RTE
(RE_Requeue_Protected_To_Task_Entry
), Loc
),
3173 Parameter_Associations
=> New_List
(
3175 Make_Unchecked_Type_Conversion
(Loc
, -- PEA (P)
3178 (RTE
(RE_Protection_Entries_Access
), Loc
),
3179 Expression
=> Make_Identifier
(Loc
, Name_uP
)),
3181 Make_Selected_Component
(Loc
, -- O._task_id
3182 Prefix
=> Make_Identifier
(Loc
, Name_uO
),
3183 Selector_Name
=> Make_Identifier
(Loc
, Name_uTask_Id
)),
3185 Make_Unchecked_Type_Conversion
(Loc
, -- entry index
3187 New_Occurrence_Of
(RTE
(RE_Task_Entry_Index
), Loc
),
3188 Expression
=> Make_Identifier
(Loc
, Name_uI
)),
3190 Make_Identifier
(Loc
, Name_uA
)))), -- abort status
3192 Else_Statements
=> New_List
(
3194 -- Call to Requeue_Task_Entry
3196 Make_Procedure_Call_Statement
(Loc
,
3198 New_Occurrence_Of
(RTE
(RE_Requeue_Task_Entry
), Loc
),
3200 Parameter_Associations
=> New_List
(
3202 Make_Selected_Component
(Loc
, -- O._task_id
3203 Prefix
=> Make_Identifier
(Loc
, Name_uO
),
3204 Selector_Name
=> Make_Identifier
(Loc
, Name_uTask_Id
)),
3206 Make_Unchecked_Type_Conversion
(Loc
, -- entry index
3208 New_Occurrence_Of
(RTE
(RE_Task_Entry_Index
), Loc
),
3209 Expression
=> Make_Identifier
(Loc
, Name_uI
)),
3211 Make_Identifier
(Loc
, Name_uA
)))))); -- abort status
3214 -- Even though no declarations are needed in both cases, we allocate
3215 -- a list for entities added by Freeze.
3218 Make_Subprogram_Body
(Loc
,
3219 Specification
=> Make_Disp_Requeue_Spec
(Typ
),
3220 Declarations
=> New_List
,
3221 Handled_Statement_Sequence
=>
3222 Make_Handled_Sequence_Of_Statements
(Loc
, Stmts
));
3223 end Make_Disp_Requeue_Body
;
3225 ----------------------------
3226 -- Make_Disp_Requeue_Spec --
3227 ----------------------------
3229 function Make_Disp_Requeue_Spec
3230 (Typ
: Entity_Id
) return Node_Id
3232 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
3235 pragma Assert
(not Restriction_Active
(No_Dispatching_Calls
));
3237 -- O : in out Typ; - Object parameter
3238 -- F : Boolean; - Protected (True) / task (False) flag
3239 -- P : Address; - Protection_Entries_Access value
3240 -- I : Entry_Index - Index of entry call
3241 -- A : Boolean - Abort flag
3243 -- Note that the Protection_Entries_Access value is represented as a
3244 -- System.Address in order to avoid dragging in the tasking runtime
3245 -- when compiling sources without tasking constructs.
3248 Make_Procedure_Specification
(Loc
,
3249 Defining_Unit_Name
=>
3250 Make_Defining_Identifier
(Loc
, Name_uDisp_Requeue
),
3252 Parameter_Specifications
=> New_List
(
3254 Make_Parameter_Specification
(Loc
, -- O
3255 Defining_Identifier
=>
3256 Make_Defining_Identifier
(Loc
, Name_uO
),
3258 New_Occurrence_Of
(Typ
, Loc
),
3260 Out_Present
=> True),
3262 Make_Parameter_Specification
(Loc
, -- F
3263 Defining_Identifier
=>
3264 Make_Defining_Identifier
(Loc
, Name_uF
),
3266 New_Occurrence_Of
(Standard_Boolean
, Loc
)),
3268 Make_Parameter_Specification
(Loc
, -- P
3269 Defining_Identifier
=>
3270 Make_Defining_Identifier
(Loc
, Name_uP
),
3272 New_Occurrence_Of
(RTE
(RE_Address
), Loc
)),
3274 Make_Parameter_Specification
(Loc
, -- I
3275 Defining_Identifier
=>
3276 Make_Defining_Identifier
(Loc
, Name_uI
),
3278 New_Occurrence_Of
(Standard_Integer
, Loc
)),
3280 Make_Parameter_Specification
(Loc
, -- A
3281 Defining_Identifier
=>
3282 Make_Defining_Identifier
(Loc
, Name_uA
),
3284 New_Occurrence_Of
(Standard_Boolean
, Loc
))));
3285 end Make_Disp_Requeue_Spec
;
3287 ---------------------------------
3288 -- Make_Disp_Timed_Select_Body --
3289 ---------------------------------
3291 -- For interface types, generate:
3293 -- procedure _Disp_Timed_Select
3294 -- (T : in out <Typ>;
3296 -- P : System.Address;
3299 -- C : out Ada.Tags.Prim_Op_Kind;
3304 -- C := Ada.Tags.POK_Function;
3305 -- end _Disp_Timed_Select;
3307 -- For protected types, generate:
3309 -- procedure _Disp_Timed_Select
3310 -- (T : in out <Typ>;
3312 -- P : System.Address;
3315 -- C : out Ada.Tags.Prim_Op_Kind;
3321 -- C := Ada.Tags.Get_Prim_Op_Kind (Ada.Tags.Tag (<Typ>VP), S);
3323 -- if C = Ada.Tags.POK_Procedure
3324 -- or else C = Ada.Tags.POK_Protected_Procedure
3325 -- or else C = Ada.Tags.POK_Task_Procedure
3331 -- I := Ada.Tags.Get_Entry_Index (Ada.Tags.Tag (<Typ>VP), S);
3332 -- System.Tasking.Protected_Objects.Operations.
3333 -- Timed_Protected_Entry_Call
3334 -- (T._object'Access,
3335 -- System.Tasking.Protected_Objects.Protected_Entry_Index (I),
3340 -- end _Disp_Timed_Select;
3342 -- For task types, generate:
3344 -- procedure _Disp_Timed_Select
3345 -- (T : in out <Typ>;
3347 -- P : System.Address;
3350 -- C : out Ada.Tags.Prim_Op_Kind;
3356 -- I := Ada.Tags.Get_Entry_Index (Ada.Tags.Tag (<Typ>VP), S);
3357 -- System.Tasking.Rendezvous.Timed_Task_Entry_Call
3359 -- System.Tasking.Task_Entry_Index (I),
3364 -- end _Disp_Time_Select;
3366 function Make_Disp_Timed_Select_Body
3367 (Typ
: Entity_Id
) return Node_Id
3369 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
3370 Conc_Typ
: Entity_Id
:= Empty
;
3371 Decls
: constant List_Id
:= New_List
;
3373 Stmts
: constant List_Id
:= New_List
;
3377 pragma Assert
(not Restriction_Active
(No_Dispatching_Calls
));
3379 -- Null body is generated for interface types
3381 if Is_Interface
(Typ
) then
3383 Make_Subprogram_Body
(Loc
,
3384 Specification
=> Make_Disp_Timed_Select_Spec
(Typ
),
3385 Declarations
=> New_List
,
3386 Handled_Statement_Sequence
=>
3387 Make_Handled_Sequence_Of_Statements
(Loc
,
3389 Make_Assignment_Statement
(Loc
,
3390 Name
=> Make_Identifier
(Loc
, Name_uF
),
3391 Expression
=> New_Occurrence_Of
(Standard_False
, Loc
)))));
3394 if Is_Concurrent_Record_Type
(Typ
) then
3395 Conc_Typ
:= Corresponding_Concurrent_Type
(Typ
);
3400 -- where I will be used to capture the entry index of the primitive
3401 -- wrapper at position S.
3404 Make_Object_Declaration
(Loc
,
3405 Defining_Identifier
=> Make_Defining_Identifier
(Loc
, Name_uI
),
3406 Object_Definition
=>
3407 New_Occurrence_Of
(Standard_Integer
, Loc
)));
3410 -- C := Get_Prim_Op_Kind (tag! (<type>VP), S);
3412 -- if C = POK_Procedure
3413 -- or else C = POK_Protected_Procedure
3414 -- or else C = POK_Task_Procedure;
3420 Build_Common_Dispatching_Select_Statements
(Typ
, Stmts
);
3423 -- I := Get_Entry_Index (tag! (<type>VP), S);
3425 -- I is the entry index and S is the dispatch table slot
3427 if Tagged_Type_Expansion
then
3429 Unchecked_Convert_To
(RTE
(RE_Tag
),
3431 (Node
(First_Elmt
(Access_Disp_Table
(Typ
))), Loc
));
3435 Make_Attribute_Reference
(Loc
,
3436 Prefix
=> New_Occurrence_Of
(Typ
, Loc
),
3437 Attribute_Name
=> Name_Tag
);
3441 Make_Assignment_Statement
(Loc
,
3442 Name
=> Make_Identifier
(Loc
, Name_uI
),
3444 Make_Function_Call
(Loc
,
3445 Name
=> New_Occurrence_Of
(RTE
(RE_Get_Entry_Index
), Loc
),
3446 Parameter_Associations
=> New_List
(
3448 Make_Identifier
(Loc
, Name_uS
)))));
3452 if Ekind
(Conc_Typ
) = E_Protected_Type
then
3454 -- Build T._object'Access
3457 Make_Attribute_Reference
(Loc
,
3458 Attribute_Name
=> Name_Unchecked_Access
,
3460 Make_Selected_Component
(Loc
,
3461 Prefix
=> Make_Identifier
(Loc
, Name_uT
),
3462 Selector_Name
=> Make_Identifier
(Loc
, Name_uObject
)));
3464 -- Normal case, No_Entry_Queue restriction not active. In this
3465 -- case we generate:
3467 -- Timed_Protected_Entry_Call
3468 -- (T._object'access,
3469 -- Protected_Entry_Index! (I),
3472 -- where T is the protected object, I is the entry index, P are
3473 -- the wrapped parameters, D is the delay amount, M is the delay
3474 -- mode and F is the status flag.
3476 -- Historically, there was also an implementation for single
3477 -- entry protected types (in s-tposen). However, it was removed
3478 -- by also testing for no No_Select_Statements restriction in
3479 -- Exp_Utils.Corresponding_Runtime_Package. This simplified the
3480 -- implementation of s-tposen.adb and provided consistency between
3481 -- all versions of System.Tasking.Protected_Objects.Single_Entry
3484 case Corresponding_Runtime_Package
(Conc_Typ
) is
3485 when System_Tasking_Protected_Objects_Entries
=>
3487 Make_Procedure_Call_Statement
(Loc
,
3490 (RTE
(RE_Timed_Protected_Entry_Call
), Loc
),
3491 Parameter_Associations
=> New_List
(
3494 Make_Unchecked_Type_Conversion
(Loc
, -- entry index
3497 (RTE
(RE_Protected_Entry_Index
), Loc
),
3498 Expression
=> Make_Identifier
(Loc
, Name_uI
)),
3500 Make_Identifier
(Loc
, Name_uP
), -- parameter block
3501 Make_Identifier
(Loc
, Name_uD
), -- delay
3502 Make_Identifier
(Loc
, Name_uM
), -- delay mode
3503 Make_Identifier
(Loc
, Name_uF
)))); -- status flag
3506 raise Program_Error
;
3512 pragma Assert
(Ekind
(Conc_Typ
) = E_Task_Type
);
3515 -- Timed_Task_Entry_Call (
3517 -- Task_Entry_Index! (I),
3523 -- where T is the task object, I is the entry index, P are the
3524 -- wrapped parameters, D is the delay amount, M is the delay
3525 -- mode and F is the status flag.
3528 Make_Procedure_Call_Statement
(Loc
,
3530 New_Occurrence_Of
(RTE
(RE_Timed_Task_Entry_Call
), Loc
),
3532 Parameter_Associations
=> New_List
(
3533 Make_Selected_Component
(Loc
, -- T._task_id
3534 Prefix
=> Make_Identifier
(Loc
, Name_uT
),
3535 Selector_Name
=> Make_Identifier
(Loc
, Name_uTask_Id
)),
3537 Make_Unchecked_Type_Conversion
(Loc
, -- entry index
3539 New_Occurrence_Of
(RTE
(RE_Task_Entry_Index
), Loc
),
3540 Expression
=> Make_Identifier
(Loc
, Name_uI
)),
3542 Make_Identifier
(Loc
, Name_uP
), -- parameter block
3543 Make_Identifier
(Loc
, Name_uD
), -- delay
3544 Make_Identifier
(Loc
, Name_uM
), -- delay mode
3545 Make_Identifier
(Loc
, Name_uF
)))); -- status flag
3549 -- Initialize out parameters
3552 Make_Assignment_Statement
(Loc
,
3553 Name
=> Make_Identifier
(Loc
, Name_uF
),
3554 Expression
=> New_Occurrence_Of
(Standard_False
, Loc
)));
3556 Make_Assignment_Statement
(Loc
,
3557 Name
=> Make_Identifier
(Loc
, Name_uC
),
3558 Expression
=> New_Occurrence_Of
(RTE
(RE_POK_Function
), Loc
)));
3562 Make_Subprogram_Body
(Loc
,
3563 Specification
=> Make_Disp_Timed_Select_Spec
(Typ
),
3564 Declarations
=> Decls
,
3565 Handled_Statement_Sequence
=>
3566 Make_Handled_Sequence_Of_Statements
(Loc
, Stmts
));
3567 end Make_Disp_Timed_Select_Body
;
3569 ---------------------------------
3570 -- Make_Disp_Timed_Select_Spec --
3571 ---------------------------------
3573 function Make_Disp_Timed_Select_Spec
3574 (Typ
: Entity_Id
) return Node_Id
3576 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
3577 Def_Id
: constant Node_Id
:=
3578 Make_Defining_Identifier
(Loc
,
3579 Name_uDisp_Timed_Select
);
3580 Params
: constant List_Id
:= New_List
;
3583 pragma Assert
(not Restriction_Active
(No_Dispatching_Calls
));
3585 -- T : in out Typ; -- Object parameter
3586 -- S : Integer; -- Primitive operation slot
3587 -- P : Address; -- Wrapped parameters
3588 -- D : Duration; -- Delay
3589 -- M : Integer; -- Delay Mode
3590 -- C : out Prim_Op_Kind; -- Call kind
3591 -- F : out Boolean; -- Status flag
3593 Append_List_To
(Params
, New_List
(
3595 Make_Parameter_Specification
(Loc
,
3596 Defining_Identifier
=> Make_Defining_Identifier
(Loc
, Name_uT
),
3597 Parameter_Type
=> New_Occurrence_Of
(Typ
, Loc
),
3599 Out_Present
=> True),
3601 Make_Parameter_Specification
(Loc
,
3602 Defining_Identifier
=> Make_Defining_Identifier
(Loc
, Name_uS
),
3603 Parameter_Type
=> New_Occurrence_Of
(Standard_Integer
, Loc
)),
3605 Make_Parameter_Specification
(Loc
,
3606 Defining_Identifier
=> Make_Defining_Identifier
(Loc
, Name_uP
),
3607 Parameter_Type
=> New_Occurrence_Of
(RTE
(RE_Address
), Loc
)),
3609 Make_Parameter_Specification
(Loc
,
3610 Defining_Identifier
=> Make_Defining_Identifier
(Loc
, Name_uD
),
3611 Parameter_Type
=> New_Occurrence_Of
(Standard_Duration
, Loc
)),
3613 Make_Parameter_Specification
(Loc
,
3614 Defining_Identifier
=> Make_Defining_Identifier
(Loc
, Name_uM
),
3615 Parameter_Type
=> New_Occurrence_Of
(Standard_Integer
, Loc
)),
3617 Make_Parameter_Specification
(Loc
,
3618 Defining_Identifier
=> Make_Defining_Identifier
(Loc
, Name_uC
),
3620 New_Occurrence_Of
(RTE
(RE_Prim_Op_Kind
), Loc
),
3621 Out_Present
=> True)));
3624 Make_Parameter_Specification
(Loc
,
3625 Defining_Identifier
=> Make_Defining_Identifier
(Loc
, Name_uF
),
3626 Parameter_Type
=> New_Occurrence_Of
(Standard_Boolean
, Loc
),
3627 Out_Present
=> True));
3630 Make_Procedure_Specification
(Loc
,
3631 Defining_Unit_Name
=> Def_Id
,
3632 Parameter_Specifications
=> Params
);
3633 end Make_Disp_Timed_Select_Spec
;
3639 -- The frontend supports two models for expanding dispatch tables
3640 -- associated with library-level defined tagged types: statically and
3641 -- non-statically allocated dispatch tables. In the former case the object
3642 -- containing the dispatch table is constant and it is initialized by means
3643 -- of a positional aggregate. In the latter case, the object containing
3644 -- the dispatch table is a variable which is initialized by means of
3647 -- In case of locally defined tagged types, the object containing the
3648 -- object containing the dispatch table is always a variable (instead of a
3649 -- constant). This is currently required to give support to late overriding
3650 -- of primitives. For example:
3652 -- procedure Example is
3654 -- type T1 is tagged null record;
3655 -- procedure Prim (O : T1);
3658 -- type T2 is new Pkg.T1 with null record;
3659 -- procedure Prim (X : T2) is -- late overriding
3665 function Make_DT
(Typ
: Entity_Id
; N
: Node_Id
:= Empty
) return List_Id
is
3666 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
3668 Max_Predef_Prims
: constant Int
:=
3672 (Parent
(RTE
(RE_Max_Predef_Prims
)))));
3674 DT_Decl
: constant Elist_Id
:= New_Elmt_List
;
3675 DT_Aggr
: constant Elist_Id
:= New_Elmt_List
;
3676 -- Entities marked with attribute Is_Dispatch_Table_Entity
3678 procedure Check_Premature_Freezing
3680 Tagged_Type
: Entity_Id
;
3682 -- Verify that all untagged types in the profile of a subprogram are
3683 -- frozen at the point the subprogram is frozen. This enforces the rule
3684 -- on RM 13.14 (14) as modified by AI05-019. At the point a subprogram
3685 -- is frozen, enough must be known about it to build the activation
3686 -- record for it, which requires at least that the size of all
3687 -- parameters be known. Controlling arguments are by-reference,
3688 -- and therefore the rule only applies to untagged types. Typical
3689 -- violation of the rule involves an object declaration that freezes a
3690 -- tagged type, when one of its primitive operations has a type in its
3691 -- profile whose full view has not been analyzed yet. More complex cases
3692 -- involve composite types that have one private unfrozen subcomponent.
3694 procedure Export_DT
(Typ
: Entity_Id
; DT
: Entity_Id
; Index
: Nat
:= 0);
3695 -- Export the dispatch table DT of tagged type Typ. Required to generate
3696 -- forward references and statically allocate the table. For primary
3697 -- dispatch tables Index is 0; for secondary dispatch tables the value
3698 -- of index must match the Suffix_Index value assigned to the table by
3699 -- Make_Tags when generating its unique external name, and it is used to
3700 -- retrieve from the Dispatch_Table_Wrappers list associated with Typ
3701 -- the external name generated by Import_DT.
3703 procedure Make_Secondary_DT
3707 Num_Iface_Prims
: Nat
;
3708 Iface_DT_Ptr
: Entity_Id
;
3709 Predef_Prims_Ptr
: Entity_Id
;
3710 Build_Thunks
: Boolean;
3712 -- Ada 2005 (AI-251): Expand the declarations for a Secondary Dispatch
3713 -- Table of Typ associated with Iface. Each abstract interface of Typ
3714 -- has two secondary dispatch tables: one containing pointers to thunks
3715 -- and another containing pointers to the primitives covering the
3716 -- interface primitives. The former secondary table is generated when
3717 -- Build_Thunks is True, and provides common support for dispatching
3718 -- calls through interface types; the latter secondary table is
3719 -- generated when Build_Thunks is False, and provides support for
3720 -- Generic Dispatching Constructors that dispatch calls through
3721 -- interface types. When constructing this latter table the value of
3722 -- Suffix_Index is -1 to indicate that there is no need to export such
3723 -- table when building statically allocated dispatch tables; a positive
3724 -- value of Suffix_Index must match the Suffix_Index value assigned to
3725 -- this secondary dispatch table by Make_Tags when its unique external
3726 -- name was generated.
3728 ------------------------------
3729 -- Check_Premature_Freezing --
3730 ------------------------------
3732 procedure Check_Premature_Freezing
3734 Tagged_Type
: Entity_Id
;
3739 function Is_Actual_For_Formal_Incomplete_Type
3740 (T
: Entity_Id
) return Boolean;
3741 -- In Ada 2012, if a nested generic has an incomplete formal type,
3742 -- the actual may be (and usually is) a private type whose completion
3743 -- appears later. It is safe to build the dispatch table in this
3744 -- case, gigi will have full views available.
3746 ------------------------------------------
3747 -- Is_Actual_For_Formal_Incomplete_Type --
3748 ------------------------------------------
3750 function Is_Actual_For_Formal_Incomplete_Type
3751 (T
: Entity_Id
) return Boolean
3753 Gen_Par
: Entity_Id
;
3757 if not Is_Generic_Instance
(Current_Scope
)
3758 or else not Used_As_Generic_Actual
(T
)
3762 Gen_Par
:= Generic_Parent
(Parent
(Current_Scope
));
3767 (Generic_Formal_Declarations
3768 (Unit_Declaration_Node
(Gen_Par
)));
3769 while Present
(F
) loop
3770 if Ekind
(Defining_Identifier
(F
)) = E_Incomplete_Type
then
3778 end Is_Actual_For_Formal_Incomplete_Type
;
3780 -- Start of processing for Check_Premature_Freezing
3783 -- Note that if the type is a (subtype of) a generic actual, the
3784 -- actual will have been frozen by the instantiation.
3787 and then Is_Private_Type
(Typ
)
3788 and then No
(Full_View
(Typ
))
3789 and then not Is_Generic_Type
(Typ
)
3790 and then not Is_Tagged_Type
(Typ
)
3791 and then not Is_Frozen
(Typ
)
3792 and then not Is_Generic_Actual_Type
(Typ
)
3794 Error_Msg_Sloc
:= Sloc
(Subp
);
3796 ("declaration must appear after completion of type &", N
, Typ
);
3798 ("\which is an untagged type in the profile of "
3799 & "primitive operation & declared#", N
, Subp
);
3802 Comp
:= Private_Component
(Typ
);
3804 if not Is_Tagged_Type
(Typ
)
3805 and then Present
(Comp
)
3806 and then not Is_Frozen
(Comp
)
3807 and then not Is_Actual_For_Formal_Incomplete_Type
(Comp
)
3809 Error_Msg_Sloc
:= Sloc
(Subp
);
3810 Error_Msg_Node_2
:= Subp
;
3811 Error_Msg_Name_1
:= Chars
(Tagged_Type
);
3813 ("declaration must appear after completion of type &",
3816 ("\which is a component of untagged type& in the profile "
3817 & "of primitive & of type % that is frozen by the "
3818 & "declaration ", N
, Typ
);
3821 end Check_Premature_Freezing
;
3827 procedure Export_DT
(Typ
: Entity_Id
; DT
: Entity_Id
; Index
: Nat
:= 0)
3833 Set_Is_Statically_Allocated
(DT
);
3834 Set_Is_True_Constant
(DT
);
3835 Set_Is_Exported
(DT
);
3838 Elmt
:= First_Elmt
(Dispatch_Table_Wrappers
(Typ
));
3839 while Count
/= Index
loop
3844 pragma Assert
(Related_Type
(Node
(Elmt
)) = Typ
);
3846 Get_External_Name
(Node
(Elmt
));
3847 Set_Interface_Name
(DT
,
3848 Make_String_Literal
(Loc
,
3849 Strval
=> String_From_Name_Buffer
));
3851 -- Ensure proper Sprint output of this implicit importation
3853 Set_Is_Internal
(DT
);
3857 -----------------------
3858 -- Make_Secondary_DT --
3859 -----------------------
3861 procedure Make_Secondary_DT
3865 Num_Iface_Prims
: Nat
;
3866 Iface_DT_Ptr
: Entity_Id
;
3867 Predef_Prims_Ptr
: Entity_Id
;
3868 Build_Thunks
: Boolean;
3871 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
3872 Exporting_Table
: constant Boolean :=
3873 Building_Static_DT
(Typ
)
3874 and then Suffix_Index
> 0;
3875 Iface_DT
: constant Entity_Id
:= Make_Temporary
(Loc
, 'T');
3876 Predef_Prims
: constant Entity_Id
:= Make_Temporary
(Loc
, 'R');
3877 DT_Constr_List
: List_Id
;
3878 DT_Aggr_List
: List_Id
;
3879 Empty_DT
: Boolean := False;
3880 Nb_Predef_Prims
: Nat
:= 0;
3884 OSD_Aggr_List
: List_Id
;
3887 Prim_Elmt
: Elmt_Id
;
3888 Prim_Ops_Aggr_List
: List_Id
;
3891 -- Handle cases in which we do not generate statically allocated
3894 if not Building_Static_DT
(Typ
) then
3895 Set_Ekind
(Predef_Prims
, E_Variable
);
3896 Set_Ekind
(Iface_DT
, E_Variable
);
3898 -- Statically allocated dispatch tables and related entities are
3902 Set_Ekind
(Predef_Prims
, E_Constant
);
3903 Set_Is_Statically_Allocated
(Predef_Prims
);
3904 Set_Is_True_Constant
(Predef_Prims
);
3906 Set_Ekind
(Iface_DT
, E_Constant
);
3907 Set_Is_Statically_Allocated
(Iface_DT
);
3908 Set_Is_True_Constant
(Iface_DT
);
3911 -- Calculate the number of slots of the dispatch table. If the number
3912 -- of primitives of Typ is 0 we reserve a dummy single entry for its
3913 -- DT because at run time the pointer to this dummy entry will be
3916 if Num_Iface_Prims
= 0 then
3920 Nb_Prim
:= Num_Iface_Prims
;
3925 -- Predef_Prims : Address_Array (1 .. Default_Prim_Ops_Count) :=
3926 -- (predef-prim-op-thunk-1'address,
3927 -- predef-prim-op-thunk-2'address,
3929 -- predef-prim-op-thunk-n'address);
3930 -- for Predef_Prims'Alignment use Address'Alignment
3932 -- Stage 1: Calculate the number of predefined primitives
3934 if not Building_Static_DT
(Typ
) then
3935 Nb_Predef_Prims
:= Max_Predef_Prims
;
3937 Prim_Elmt
:= First_Elmt
(Primitive_Operations
(Typ
));
3938 while Present
(Prim_Elmt
) loop
3939 Prim
:= Node
(Prim_Elmt
);
3941 if Is_Predefined_Dispatching_Operation
(Prim
)
3942 and then not Is_Abstract_Subprogram
(Prim
)
3944 Pos
:= UI_To_Int
(DT_Position
(Prim
));
3946 if Pos
> Nb_Predef_Prims
then
3947 Nb_Predef_Prims
:= Pos
;
3951 Next_Elmt
(Prim_Elmt
);
3955 -- Stage 2: Create the thunks associated with the predefined
3956 -- primitives and save their entity to fill the aggregate.
3959 Prim_Table
: array (Nat
range 1 .. Nb_Predef_Prims
) of Entity_Id
;
3961 Thunk_Id
: Entity_Id
;
3962 Thunk_Code
: Node_Id
;
3965 Prim_Ops_Aggr_List
:= New_List
;
3966 Prim_Table
:= (others => Empty
);
3968 if Building_Static_DT
(Typ
) then
3969 Prim_Elmt
:= First_Elmt
(Primitive_Operations
(Typ
));
3970 while Present
(Prim_Elmt
) loop
3971 Prim
:= Node
(Prim_Elmt
);
3973 if Is_Predefined_Dispatching_Operation
(Prim
)
3974 and then not Is_Abstract_Subprogram
(Prim
)
3975 and then not Is_Eliminated
(Prim
)
3976 and then not Present
(Prim_Table
3977 (UI_To_Int
(DT_Position
(Prim
))))
3979 if not Build_Thunks
then
3980 Prim_Table
(UI_To_Int
(DT_Position
(Prim
))) :=
3984 Expand_Interface_Thunk
3985 (Ultimate_Alias
(Prim
), Thunk_Id
, Thunk_Code
);
3987 if Present
(Thunk_Id
) then
3988 Append_To
(Result
, Thunk_Code
);
3989 Prim_Table
(UI_To_Int
(DT_Position
(Prim
)))
3995 Next_Elmt
(Prim_Elmt
);
3999 for J
in Prim_Table
'Range loop
4000 if Present
(Prim_Table
(J
)) then
4002 Unchecked_Convert_To
(RTE
(RE_Prim_Ptr
),
4003 Make_Attribute_Reference
(Loc
,
4004 Prefix
=> New_Occurrence_Of
(Prim_Table
(J
), Loc
),
4005 Attribute_Name
=> Name_Unrestricted_Access
));
4007 New_Node
:= Make_Null
(Loc
);
4010 Append_To
(Prim_Ops_Aggr_List
, New_Node
);
4014 Make_Aggregate
(Loc
, Expressions
=> Prim_Ops_Aggr_List
);
4016 -- Remember aggregates initializing dispatch tables
4018 Append_Elmt
(New_Node
, DT_Aggr
);
4021 Make_Subtype_Declaration
(Loc
,
4022 Defining_Identifier
=> Make_Temporary
(Loc
, 'S'),
4023 Subtype_Indication
=>
4024 New_Occurrence_Of
(RTE
(RE_Address_Array
), Loc
));
4026 Append_To
(Result
, Decl
);
4029 Make_Object_Declaration
(Loc
,
4030 Defining_Identifier
=> Predef_Prims
,
4031 Constant_Present
=> Building_Static_DT
(Typ
),
4032 Aliased_Present
=> True,
4033 Object_Definition
=> New_Occurrence_Of
4034 (Defining_Identifier
(Decl
), Loc
),
4035 Expression
=> New_Node
));
4038 Make_Attribute_Definition_Clause
(Loc
,
4039 Name
=> New_Occurrence_Of
(Predef_Prims
, Loc
),
4040 Chars
=> Name_Alignment
,
4042 Make_Attribute_Reference
(Loc
,
4044 New_Occurrence_Of
(RTE
(RE_Integer_Address
), Loc
),
4045 Attribute_Name
=> Name_Alignment
)));
4050 -- OSD : Ada.Tags.Object_Specific_Data (Nb_Prims) :=
4051 -- (OSD_Table => (1 => <value>,
4055 -- Iface_DT : Dispatch_Table (Nb_Prims) :=
4056 -- ([ Signature => <sig-value> ],
4057 -- Tag_Kind => <tag_kind-value>,
4058 -- Predef_Prims => Predef_Prims'Address,
4059 -- Offset_To_Top => 0,
4060 -- OSD => OSD'Address,
4061 -- Prims_Ptr => (prim-op-1'address,
4062 -- prim-op-2'address,
4064 -- prim-op-n'address));
4065 -- for Iface_DT'Alignment use Address'Alignment;
4067 -- Stage 3: Initialize the discriminant and the record components
4069 DT_Constr_List
:= New_List
;
4070 DT_Aggr_List
:= New_List
;
4074 Append_To
(DT_Constr_List
, Make_Integer_Literal
(Loc
, Nb_Prim
));
4075 Append_To
(DT_Aggr_List
, Make_Integer_Literal
(Loc
, Nb_Prim
));
4079 if RTE_Record_Component_Available
(RE_Signature
) then
4080 Append_To
(DT_Aggr_List
,
4081 New_Occurrence_Of
(RTE
(RE_Secondary_DT
), Loc
));
4086 if RTE_Record_Component_Available
(RE_Tag_Kind
) then
4087 Append_To
(DT_Aggr_List
, Tagged_Kind
(Typ
));
4092 Append_To
(DT_Aggr_List
,
4093 Make_Attribute_Reference
(Loc
,
4094 Prefix
=> New_Occurrence_Of
(Predef_Prims
, Loc
),
4095 Attribute_Name
=> Name_Address
));
4097 -- Note: The correct value of Offset_To_Top will be set by the init
4100 Append_To
(DT_Aggr_List
, Make_Integer_Literal
(Loc
, 0));
4102 -- Generate the Object Specific Data table required to dispatch calls
4103 -- through synchronized interfaces.
4106 or else Is_Abstract_Type
(Typ
)
4107 or else Is_Controlled
(Typ
)
4108 or else Restriction_Active
(No_Dispatching_Calls
)
4109 or else not Is_Limited_Type
(Typ
)
4110 or else not Has_Interfaces
(Typ
)
4111 or else not Build_Thunks
4112 or else not RTE_Record_Component_Available
(RE_OSD_Table
)
4114 -- No OSD table required
4116 Append_To
(DT_Aggr_List
,
4117 New_Occurrence_Of
(RTE
(RE_Null_Address
), Loc
));
4120 OSD_Aggr_List
:= New_List
;
4123 Prim_Table
: array (Nat
range 1 .. Nb_Prim
) of Entity_Id
;
4125 Prim_Alias
: Entity_Id
;
4126 Prim_Elmt
: Elmt_Id
;
4132 Prim_Table
:= (others => Empty
);
4133 Prim_Alias
:= Empty
;
4135 Prim_Elmt
:= First_Elmt
(Primitive_Operations
(Typ
));
4136 while Present
(Prim_Elmt
) loop
4137 Prim
:= Node
(Prim_Elmt
);
4139 if Present
(Interface_Alias
(Prim
))
4140 and then Find_Dispatching_Type
4141 (Interface_Alias
(Prim
)) = Iface
4143 Prim_Alias
:= Interface_Alias
(Prim
);
4144 E
:= Ultimate_Alias
(Prim
);
4145 Pos
:= UI_To_Int
(DT_Position
(Prim_Alias
));
4147 if Present
(Prim_Table
(Pos
)) then
4148 pragma Assert
(Prim_Table
(Pos
) = E
);
4152 Prim_Table
(Pos
) := E
;
4154 Append_To
(OSD_Aggr_List
,
4155 Make_Component_Association
(Loc
,
4156 Choices
=> New_List
(
4157 Make_Integer_Literal
(Loc
,
4158 DT_Position
(Prim_Alias
))),
4160 Make_Integer_Literal
(Loc
,
4161 DT_Position
(Alias
(Prim
)))));
4167 Next_Elmt
(Prim_Elmt
);
4169 pragma Assert
(Count
= Nb_Prim
);
4172 OSD
:= Make_Temporary
(Loc
, 'I');
4175 Make_Object_Declaration
(Loc
,
4176 Defining_Identifier
=> OSD
,
4177 Object_Definition
=>
4178 Make_Subtype_Indication
(Loc
,
4180 New_Occurrence_Of
(RTE
(RE_Object_Specific_Data
), Loc
),
4182 Make_Index_Or_Discriminant_Constraint
(Loc
,
4183 Constraints
=> New_List
(
4184 Make_Integer_Literal
(Loc
, Nb_Prim
)))),
4187 Make_Aggregate
(Loc
,
4188 Component_Associations
=> New_List
(
4189 Make_Component_Association
(Loc
,
4190 Choices
=> New_List
(
4192 (RTE_Record_Component
(RE_OSD_Num_Prims
), Loc
)),
4194 Make_Integer_Literal
(Loc
, Nb_Prim
)),
4196 Make_Component_Association
(Loc
,
4197 Choices
=> New_List
(
4199 (RTE_Record_Component
(RE_OSD_Table
), Loc
)),
4200 Expression
=> Make_Aggregate
(Loc
,
4201 Component_Associations
=> OSD_Aggr_List
))))));
4204 Make_Attribute_Definition_Clause
(Loc
,
4205 Name
=> New_Occurrence_Of
(OSD
, Loc
),
4206 Chars
=> Name_Alignment
,
4208 Make_Attribute_Reference
(Loc
,
4210 New_Occurrence_Of
(RTE
(RE_Integer_Address
), Loc
),
4211 Attribute_Name
=> Name_Alignment
)));
4213 -- In secondary dispatch tables the Typeinfo component contains
4214 -- the address of the Object Specific Data (see a-tags.ads)
4216 Append_To
(DT_Aggr_List
,
4217 Make_Attribute_Reference
(Loc
,
4218 Prefix
=> New_Occurrence_Of
(OSD
, Loc
),
4219 Attribute_Name
=> Name_Address
));
4222 -- Initialize the table of primitive operations
4224 Prim_Ops_Aggr_List
:= New_List
;
4227 Append_To
(Prim_Ops_Aggr_List
, Make_Null
(Loc
));
4229 elsif Is_Abstract_Type
(Typ
)
4230 or else not Building_Static_DT
(Typ
)
4232 for J
in 1 .. Nb_Prim
loop
4233 Append_To
(Prim_Ops_Aggr_List
, Make_Null
(Loc
));
4238 CPP_Nb_Prims
: constant Nat
:= CPP_Num_Prims
(Typ
);
4241 Prim_Table
: array (Nat
range 1 .. Nb_Prim
) of Entity_Id
;
4242 Thunk_Code
: Node_Id
;
4243 Thunk_Id
: Entity_Id
;
4246 Prim_Table
:= (others => Empty
);
4248 Prim_Elmt
:= First_Elmt
(Primitive_Operations
(Typ
));
4249 while Present
(Prim_Elmt
) loop
4250 Prim
:= Node
(Prim_Elmt
);
4251 E
:= Ultimate_Alias
(Prim
);
4252 Prim_Pos
:= UI_To_Int
(DT_Position
(E
));
4254 -- Do not reference predefined primitives because they are
4255 -- located in a separate dispatch table; skip abstract and
4256 -- eliminated primitives; skip primitives located in the C++
4257 -- part of the dispatch table because their slot is set by
4260 if not Is_Predefined_Dispatching_Operation
(Prim
)
4261 and then Present
(Interface_Alias
(Prim
))
4262 and then not Is_Abstract_Subprogram
(Alias
(Prim
))
4263 and then not Is_Eliminated
(Alias
(Prim
))
4264 and then (not Is_CPP_Class
(Root_Type
(Typ
))
4265 or else Prim_Pos
> CPP_Nb_Prims
)
4266 and then Find_Dispatching_Type
4267 (Interface_Alias
(Prim
)) = Iface
4269 -- Generate the code of the thunk only if the abstract
4270 -- interface type is not an immediate ancestor of
4271 -- Tagged_Type. Otherwise the DT associated with the
4272 -- interface is the primary DT.
4274 and then not Is_Ancestor
(Iface
, Typ
,
4275 Use_Full_View
=> True)
4277 if not Build_Thunks
then
4279 UI_To_Int
(DT_Position
(Interface_Alias
(Prim
)));
4280 Prim_Table
(Prim_Pos
) := Alias
(Prim
);
4283 Expand_Interface_Thunk
(Prim
, Thunk_Id
, Thunk_Code
);
4285 if Present
(Thunk_Id
) then
4287 UI_To_Int
(DT_Position
(Interface_Alias
(Prim
)));
4289 Prim_Table
(Prim_Pos
) := Thunk_Id
;
4290 Append_To
(Result
, Thunk_Code
);
4295 Next_Elmt
(Prim_Elmt
);
4298 for J
in Prim_Table
'Range loop
4299 if Present
(Prim_Table
(J
)) then
4301 Unchecked_Convert_To
(RTE
(RE_Prim_Ptr
),
4302 Make_Attribute_Reference
(Loc
,
4303 Prefix
=> New_Occurrence_Of
(Prim_Table
(J
), Loc
),
4304 Attribute_Name
=> Name_Unrestricted_Access
));
4307 New_Node
:= Make_Null
(Loc
);
4310 Append_To
(Prim_Ops_Aggr_List
, New_Node
);
4316 Make_Aggregate
(Loc
,
4317 Expressions
=> Prim_Ops_Aggr_List
);
4319 Append_To
(DT_Aggr_List
, New_Node
);
4321 -- Remember aggregates initializing dispatch tables
4323 Append_Elmt
(New_Node
, DT_Aggr
);
4325 -- Note: Secondary dispatch tables cannot be declared constant
4326 -- because the component Offset_To_Top is currently initialized
4327 -- by the IP routine.
4330 Make_Object_Declaration
(Loc
,
4331 Defining_Identifier
=> Iface_DT
,
4332 Aliased_Present
=> True,
4333 Constant_Present
=> False,
4335 Object_Definition
=>
4336 Make_Subtype_Indication
(Loc
,
4337 Subtype_Mark
=> New_Occurrence_Of
4338 (RTE
(RE_Dispatch_Table_Wrapper
), Loc
),
4339 Constraint
=> Make_Index_Or_Discriminant_Constraint
(Loc
,
4340 Constraints
=> DT_Constr_List
)),
4343 Make_Aggregate
(Loc
,
4344 Expressions
=> DT_Aggr_List
)));
4347 Make_Attribute_Definition_Clause
(Loc
,
4348 Name
=> New_Occurrence_Of
(Iface_DT
, Loc
),
4349 Chars
=> Name_Alignment
,
4352 Make_Attribute_Reference
(Loc
,
4354 New_Occurrence_Of
(RTE
(RE_Integer_Address
), Loc
),
4355 Attribute_Name
=> Name_Alignment
)));
4357 if Exporting_Table
then
4358 Export_DT
(Typ
, Iface_DT
, Suffix_Index
);
4360 -- Generate code to create the pointer to the dispatch table
4362 -- Iface_DT_Ptr : Tag := Tag!(DT.Prims_Ptr'Address);
4364 -- Note: This declaration is not added here if the table is exported
4365 -- because in such case Make_Tags has already added this declaration.
4369 Make_Object_Declaration
(Loc
,
4370 Defining_Identifier
=> Iface_DT_Ptr
,
4371 Constant_Present
=> True,
4373 Object_Definition
=>
4374 New_Occurrence_Of
(RTE
(RE_Interface_Tag
), Loc
),
4377 Unchecked_Convert_To
(RTE
(RE_Interface_Tag
),
4378 Make_Attribute_Reference
(Loc
,
4380 Make_Selected_Component
(Loc
,
4381 Prefix
=> New_Occurrence_Of
(Iface_DT
, Loc
),
4384 (RTE_Record_Component
(RE_Prims_Ptr
), Loc
)),
4385 Attribute_Name
=> Name_Address
))));
4389 Make_Object_Declaration
(Loc
,
4390 Defining_Identifier
=> Predef_Prims_Ptr
,
4391 Constant_Present
=> True,
4393 Object_Definition
=>
4394 New_Occurrence_Of
(RTE
(RE_Address
), Loc
),
4397 Make_Attribute_Reference
(Loc
,
4399 Make_Selected_Component
(Loc
,
4400 Prefix
=> New_Occurrence_Of
(Iface_DT
, Loc
),
4403 (RTE_Record_Component
(RE_Predef_Prims
), Loc
)),
4404 Attribute_Name
=> Name_Address
)));
4406 -- Remember entities containing dispatch tables
4408 Append_Elmt
(Predef_Prims
, DT_Decl
);
4409 Append_Elmt
(Iface_DT
, DT_Decl
);
4410 end Make_Secondary_DT
;
4414 Elab_Code
: constant List_Id
:= New_List
;
4415 Result
: constant List_Id
:= New_List
;
4416 Tname
: constant Name_Id
:= Chars
(Typ
);
4418 AI_Tag_Elmt
: Elmt_Id
;
4419 AI_Tag_Comp
: Elmt_Id
;
4420 DT_Aggr_List
: List_Id
;
4421 DT_Constr_List
: List_Id
;
4425 Iface_Table_Node
: Node_Id
;
4426 Name_ITable
: Name_Id
;
4427 Nb_Predef_Prims
: Nat
:= 0;
4430 Num_Ifaces
: Nat
:= 0;
4431 Parent_Typ
: Entity_Id
;
4433 Prim_Elmt
: Elmt_Id
;
4434 Prim_Ops_Aggr_List
: List_Id
;
4436 Typ_Comps
: Elist_Id
;
4437 Typ_Ifaces
: Elist_Id
;
4438 TSD_Aggr_List
: List_Id
;
4439 TSD_Tags_List
: List_Id
;
4441 -- The following name entries are used by Make_DT to generate a number
4442 -- of entities related to a tagged type. These entities may be generated
4443 -- in a scope other than that of the tagged type declaration, and if
4444 -- the entities for two tagged types with the same name happen to be
4445 -- generated in the same scope, we have to take care to use different
4446 -- names. This is achieved by means of a unique serial number appended
4447 -- to each generated entity name.
4449 Name_DT
: constant Name_Id
:=
4450 New_External_Name
(Tname
, 'T', Suffix_Index
=> -1);
4451 Name_Exname
: constant Name_Id
:=
4452 New_External_Name
(Tname
, 'E', Suffix_Index
=> -1);
4453 Name_HT_Link
: constant Name_Id
:=
4454 New_External_Name
(Tname
, 'H', Suffix_Index
=> -1);
4455 Name_Predef_Prims
: constant Name_Id
:=
4456 New_External_Name
(Tname
, 'R', Suffix_Index
=> -1);
4457 Name_SSD
: constant Name_Id
:=
4458 New_External_Name
(Tname
, 'S', Suffix_Index
=> -1);
4459 Name_TSD
: constant Name_Id
:=
4460 New_External_Name
(Tname
, 'B', Suffix_Index
=> -1);
4462 -- Entities built with above names
4464 DT
: constant Entity_Id
:=
4465 Make_Defining_Identifier
(Loc
, Name_DT
);
4466 Exname
: constant Entity_Id
:=
4467 Make_Defining_Identifier
(Loc
, Name_Exname
);
4468 HT_Link
: constant Entity_Id
:=
4469 Make_Defining_Identifier
(Loc
, Name_HT_Link
);
4470 Predef_Prims
: constant Entity_Id
:=
4471 Make_Defining_Identifier
(Loc
, Name_Predef_Prims
);
4472 SSD
: constant Entity_Id
:=
4473 Make_Defining_Identifier
(Loc
, Name_SSD
);
4474 TSD
: constant Entity_Id
:=
4475 Make_Defining_Identifier
(Loc
, Name_TSD
);
4477 -- Start of processing for Make_DT
4480 pragma Assert
(Is_Frozen
(Typ
));
4482 -- Handle cases in which there is no need to build the dispatch table
4484 if Has_Dispatch_Table
(Typ
)
4485 or else No
(Access_Disp_Table
(Typ
))
4486 or else Is_CPP_Class
(Typ
)
4487 or else Convention
(Typ
) = Convention_CIL
4488 or else Convention
(Typ
) = Convention_Java
4492 elsif No_Run_Time_Mode
then
4493 Error_Msg_CRT
("tagged types", Typ
);
4496 elsif not RTE_Available
(RE_Tag
) then
4498 Make_Object_Declaration
(Loc
,
4499 Defining_Identifier
=> Node
(First_Elmt
4500 (Access_Disp_Table
(Typ
))),
4501 Object_Definition
=> New_Occurrence_Of
(RTE
(RE_Tag
), Loc
),
4502 Constant_Present
=> True,
4504 Unchecked_Convert_To
(RTE
(RE_Tag
),
4505 New_Occurrence_Of
(RTE
(RE_Null_Address
), Loc
))));
4507 Analyze_List
(Result
, Suppress
=> All_Checks
);
4508 Error_Msg_CRT
("tagged types", Typ
);
4512 -- Ensure that the value of Max_Predef_Prims defined in a-tags is
4513 -- correct. Valid values are 9 under configurable runtime or 15
4514 -- with full runtime.
4516 if RTE_Available
(RE_Interface_Data
) then
4517 if Max_Predef_Prims
/= 15 then
4518 Error_Msg_N
("run-time library configuration error", Typ
);
4522 if Max_Predef_Prims
/= 9 then
4523 Error_Msg_N
("run-time library configuration error", Typ
);
4524 Error_Msg_CRT
("tagged types", Typ
);
4529 -- Initialize Parent_Typ handling private types
4531 Parent_Typ
:= Etype
(Typ
);
4533 if Present
(Full_View
(Parent_Typ
)) then
4534 Parent_Typ
:= Full_View
(Parent_Typ
);
4537 -- Ensure that all the primitives are frozen. This is only required when
4538 -- building static dispatch tables --- the primitives must be frozen to
4539 -- be referenced (otherwise we have problems with the backend). It is
4540 -- not a requirement with nonstatic dispatch tables because in this case
4541 -- we generate now an empty dispatch table; the extra code required to
4542 -- register the primitives in the slots will be generated later --- when
4543 -- each primitive is frozen (see Freeze_Subprogram).
4545 if Building_Static_DT
(Typ
) then
4547 Save
: constant Boolean := Freezing_Library_Level_Tagged_Type
;
4549 Prim_Elmt
: Elmt_Id
;
4553 Freezing_Library_Level_Tagged_Type
:= True;
4555 Prim_Elmt
:= First_Elmt
(Primitive_Operations
(Typ
));
4556 while Present
(Prim_Elmt
) loop
4557 Prim
:= Node
(Prim_Elmt
);
4558 Frnodes
:= Freeze_Entity
(Prim
, Typ
);
4564 F
:= First_Formal
(Prim
);
4565 while Present
(F
) loop
4566 Check_Premature_Freezing
(Prim
, Typ
, Etype
(F
));
4570 Check_Premature_Freezing
(Prim
, Typ
, Etype
(Prim
));
4573 if Present
(Frnodes
) then
4574 Append_List_To
(Result
, Frnodes
);
4577 Next_Elmt
(Prim_Elmt
);
4580 Freezing_Library_Level_Tagged_Type
:= Save
;
4584 -- Ada 2005 (AI-251): Build the secondary dispatch tables
4586 if Has_Interfaces
(Typ
) then
4587 Collect_Interface_Components
(Typ
, Typ_Comps
);
4589 -- Each secondary dispatch table is assigned an unique positive
4590 -- suffix index; such value also corresponds with the location of
4591 -- its entity in the Dispatch_Table_Wrappers list (see Make_Tags).
4593 -- Note: This value must be kept sync with the Suffix_Index values
4594 -- generated by Make_Tags
4598 Next_Elmt
(Next_Elmt
(First_Elmt
(Access_Disp_Table
(Typ
))));
4600 AI_Tag_Comp
:= First_Elmt
(Typ_Comps
);
4601 while Present
(AI_Tag_Comp
) loop
4602 pragma Assert
(Has_Suffix
(Node
(AI_Tag_Elmt
), 'P'));
4604 -- Build the secondary table containing pointers to thunks
4609 (Related_Type
(Node
(AI_Tag_Comp
))),
4610 Suffix_Index
=> Suffix_Index
,
4611 Num_Iface_Prims
=> UI_To_Int
4612 (DT_Entry_Count
(Node
(AI_Tag_Comp
))),
4613 Iface_DT_Ptr
=> Node
(AI_Tag_Elmt
),
4614 Predef_Prims_Ptr
=> Node
(Next_Elmt
(AI_Tag_Elmt
)),
4615 Build_Thunks
=> True,
4618 -- Skip secondary dispatch table referencing thunks to predefined
4621 Next_Elmt
(AI_Tag_Elmt
);
4622 pragma Assert
(Has_Suffix
(Node
(AI_Tag_Elmt
), 'Y'));
4624 -- Secondary dispatch table referencing user-defined primitives
4625 -- covered by this interface.
4627 Next_Elmt
(AI_Tag_Elmt
);
4628 pragma Assert
(Has_Suffix
(Node
(AI_Tag_Elmt
), 'D'));
4630 -- Build the secondary table containing pointers to primitives
4631 -- (used to give support to Generic Dispatching Constructors).
4636 (Related_Type
(Node
(AI_Tag_Comp
))),
4638 Num_Iface_Prims
=> UI_To_Int
4639 (DT_Entry_Count
(Node
(AI_Tag_Comp
))),
4640 Iface_DT_Ptr
=> Node
(AI_Tag_Elmt
),
4641 Predef_Prims_Ptr
=> Node
(Next_Elmt
(AI_Tag_Elmt
)),
4642 Build_Thunks
=> False,
4645 -- Skip secondary dispatch table referencing predefined primitives
4647 Next_Elmt
(AI_Tag_Elmt
);
4648 pragma Assert
(Has_Suffix
(Node
(AI_Tag_Elmt
), 'Z'));
4650 Suffix_Index
:= Suffix_Index
+ 1;
4651 Next_Elmt
(AI_Tag_Elmt
);
4652 Next_Elmt
(AI_Tag_Comp
);
4656 -- Get the _tag entity and number of primitives of its dispatch table
4658 DT_Ptr
:= Node
(First_Elmt
(Access_Disp_Table
(Typ
)));
4659 Nb_Prim
:= UI_To_Int
(DT_Entry_Count
(First_Tag_Component
(Typ
)));
4661 Set_Is_Statically_Allocated
(DT
, Is_Library_Level_Tagged_Type
(Typ
));
4662 Set_Is_Statically_Allocated
(SSD
, Is_Library_Level_Tagged_Type
(Typ
));
4663 Set_Is_Statically_Allocated
(TSD
, Is_Library_Level_Tagged_Type
(Typ
));
4664 Set_Is_Statically_Allocated
(Predef_Prims
,
4665 Is_Library_Level_Tagged_Type
(Typ
));
4667 -- In case of locally defined tagged type we declare the object
4668 -- containing the dispatch table by means of a variable. Its
4669 -- initialization is done later by means of an assignment. This is
4670 -- required to generate its External_Tag.
4672 if not Building_Static_DT
(Typ
) then
4675 -- DT : No_Dispatch_Table_Wrapper;
4676 -- for DT'Alignment use Address'Alignment;
4677 -- DT_Ptr : Tag := !Tag (DT.NDT_Prims_Ptr'Address);
4679 if not Has_DT
(Typ
) then
4681 Make_Object_Declaration
(Loc
,
4682 Defining_Identifier
=> DT
,
4683 Aliased_Present
=> True,
4684 Constant_Present
=> False,
4685 Object_Definition
=>
4687 (RTE
(RE_No_Dispatch_Table_Wrapper
), Loc
)));
4690 Make_Attribute_Definition_Clause
(Loc
,
4691 Name
=> New_Occurrence_Of
(DT
, Loc
),
4692 Chars
=> Name_Alignment
,
4694 Make_Attribute_Reference
(Loc
,
4696 New_Occurrence_Of
(RTE
(RE_Integer_Address
), Loc
),
4697 Attribute_Name
=> Name_Alignment
)));
4700 Make_Object_Declaration
(Loc
,
4701 Defining_Identifier
=> DT_Ptr
,
4702 Object_Definition
=> New_Occurrence_Of
(RTE
(RE_Tag
), Loc
),
4703 Constant_Present
=> True,
4705 Unchecked_Convert_To
(RTE
(RE_Tag
),
4706 Make_Attribute_Reference
(Loc
,
4708 Make_Selected_Component
(Loc
,
4709 Prefix
=> New_Occurrence_Of
(DT
, Loc
),
4712 (RTE_Record_Component
(RE_NDT_Prims_Ptr
), Loc
)),
4713 Attribute_Name
=> Name_Address
))));
4715 Set_Is_Statically_Allocated
(DT_Ptr
,
4716 Is_Library_Level_Tagged_Type
(Typ
));
4718 -- Generate the SCIL node for the previous object declaration
4719 -- because it has a tag initialization.
4721 if Generate_SCIL
then
4723 Make_SCIL_Dispatch_Table_Tag_Init
(Sloc
(Last
(Result
)));
4724 Set_SCIL_Entity
(New_Node
, Typ
);
4725 Set_SCIL_Node
(Last
(Result
), New_Node
);
4729 -- DT : Dispatch_Table_Wrapper (Nb_Prim);
4730 -- for DT'Alignment use Address'Alignment;
4731 -- DT_Ptr : Tag := !Tag (DT.Prims_Ptr'Address);
4734 -- If the tagged type has no primitives we add a dummy slot
4735 -- whose address will be the tag of this type.
4739 New_List
(Make_Integer_Literal
(Loc
, 1));
4742 New_List
(Make_Integer_Literal
(Loc
, Nb_Prim
));
4746 Make_Object_Declaration
(Loc
,
4747 Defining_Identifier
=> DT
,
4748 Aliased_Present
=> True,
4749 Constant_Present
=> False,
4750 Object_Definition
=>
4751 Make_Subtype_Indication
(Loc
,
4753 New_Occurrence_Of
(RTE
(RE_Dispatch_Table_Wrapper
), Loc
),
4755 Make_Index_Or_Discriminant_Constraint
(Loc
,
4756 Constraints
=> DT_Constr_List
))));
4759 Make_Attribute_Definition_Clause
(Loc
,
4760 Name
=> New_Occurrence_Of
(DT
, Loc
),
4761 Chars
=> Name_Alignment
,
4763 Make_Attribute_Reference
(Loc
,
4765 New_Occurrence_Of
(RTE
(RE_Integer_Address
), Loc
),
4766 Attribute_Name
=> Name_Alignment
)));
4769 Make_Object_Declaration
(Loc
,
4770 Defining_Identifier
=> DT_Ptr
,
4771 Object_Definition
=> New_Occurrence_Of
(RTE
(RE_Tag
), Loc
),
4772 Constant_Present
=> True,
4774 Unchecked_Convert_To
(RTE
(RE_Tag
),
4775 Make_Attribute_Reference
(Loc
,
4777 Make_Selected_Component
(Loc
,
4778 Prefix
=> New_Occurrence_Of
(DT
, Loc
),
4781 (RTE_Record_Component
(RE_Prims_Ptr
), Loc
)),
4782 Attribute_Name
=> Name_Address
))));
4784 Set_Is_Statically_Allocated
(DT_Ptr
,
4785 Is_Library_Level_Tagged_Type
(Typ
));
4787 -- Generate the SCIL node for the previous object declaration
4788 -- because it has a tag initialization.
4790 if Generate_SCIL
then
4792 Make_SCIL_Dispatch_Table_Tag_Init
(Sloc
(Last
(Result
)));
4793 Set_SCIL_Entity
(New_Node
, Typ
);
4794 Set_SCIL_Node
(Last
(Result
), New_Node
);
4798 Make_Object_Declaration
(Loc
,
4799 Defining_Identifier
=>
4800 Node
(Next_Elmt
(First_Elmt
(Access_Disp_Table
(Typ
)))),
4801 Constant_Present
=> True,
4802 Object_Definition
=>
4803 New_Occurrence_Of
(RTE
(RE_Address
), Loc
),
4805 Make_Attribute_Reference
(Loc
,
4807 Make_Selected_Component
(Loc
,
4808 Prefix
=> New_Occurrence_Of
(DT
, Loc
),
4811 (RTE_Record_Component
(RE_Predef_Prims
), Loc
)),
4812 Attribute_Name
=> Name_Address
)));
4816 -- Generate: Exname : constant String := full_qualified_name (typ);
4817 -- The type itself may be an anonymous parent type, so use the first
4818 -- subtype to have a user-recognizable name.
4821 Make_Object_Declaration
(Loc
,
4822 Defining_Identifier
=> Exname
,
4823 Constant_Present
=> True,
4824 Object_Definition
=> New_Occurrence_Of
(Standard_String
, Loc
),
4826 Make_String_Literal
(Loc
,
4827 Strval
=> Fully_Qualified_Name_String
(First_Subtype
(Typ
)))));
4828 Set_Is_Statically_Allocated
(Exname
);
4829 Set_Is_True_Constant
(Exname
);
4831 -- Declare the object used by Ada.Tags.Register_Tag
4833 if RTE_Available
(RE_Register_Tag
) then
4835 Make_Object_Declaration
(Loc
,
4836 Defining_Identifier
=> HT_Link
,
4837 Object_Definition
=> New_Occurrence_Of
(RTE
(RE_Tag
), Loc
)));
4840 -- Generate code to create the storage for the type specific data object
4841 -- with enough space to store the tags of the ancestors plus the tags
4842 -- of all the implemented interfaces (as described in a-tags.adb).
4844 -- TSD : Type_Specific_Data (I_Depth) :=
4845 -- (Idepth => I_Depth,
4846 -- Access_Level => Type_Access_Level (Typ),
4847 -- Alignment => Typ'Alignment,
4848 -- Expanded_Name => Cstring_Ptr!(Exname'Address))
4849 -- External_Tag => Cstring_Ptr!(Exname'Address))
4850 -- HT_Link => HT_Link'Address,
4851 -- Transportable => <<boolean-value>>,
4852 -- Type_Is_Abstract => <<boolean-value>>,
4853 -- Needs_Finalization => <<boolean-value>>,
4854 -- [ Size_Func => Size_Prim'Access, ]
4855 -- [ Interfaces_Table => <<access-value>>, ]
4856 -- [ SSD => SSD_Table'Address ]
4857 -- Tags_Table => (0 => null,
4860 -- for TSD'Alignment use Address'Alignment
4862 TSD_Aggr_List
:= New_List
;
4864 -- Idepth: Count ancestors to compute the inheritance depth. For private
4865 -- extensions, always go to the full view in order to compute the real
4866 -- inheritance depth.
4869 Current_Typ
: Entity_Id
;
4870 Parent_Typ
: Entity_Id
;
4876 Parent_Typ
:= Etype
(Current_Typ
);
4878 if Is_Private_Type
(Parent_Typ
) then
4879 Parent_Typ
:= Full_View
(Base_Type
(Parent_Typ
));
4882 exit when Parent_Typ
= Current_Typ
;
4884 I_Depth
:= I_Depth
+ 1;
4885 Current_Typ
:= Parent_Typ
;
4889 Append_To
(TSD_Aggr_List
,
4890 Make_Integer_Literal
(Loc
, I_Depth
));
4894 Append_To
(TSD_Aggr_List
,
4895 Make_Integer_Literal
(Loc
, Type_Access_Level
(Typ
)));
4899 -- For CPP types we cannot rely on the value of 'Alignment provided
4900 -- by the backend to initialize this TSD field.
4902 if Convention
(Typ
) = Convention_CPP
4903 or else Is_CPP_Class
(Root_Type
(Typ
))
4905 Append_To
(TSD_Aggr_List
,
4906 Make_Integer_Literal
(Loc
, 0));
4908 Append_To
(TSD_Aggr_List
,
4909 Make_Attribute_Reference
(Loc
,
4910 Prefix
=> New_Occurrence_Of
(Typ
, Loc
),
4911 Attribute_Name
=> Name_Alignment
));
4916 Append_To
(TSD_Aggr_List
,
4917 Unchecked_Convert_To
(RTE
(RE_Cstring_Ptr
),
4918 Make_Attribute_Reference
(Loc
,
4919 Prefix
=> New_Occurrence_Of
(Exname
, Loc
),
4920 Attribute_Name
=> Name_Address
)));
4922 -- External_Tag of a local tagged type
4924 -- <typ>A : constant String :=
4925 -- "Internal tag at 16#tag-addr#: <full-name-of-typ>";
4927 -- The reason we generate this strange name is that we do not want to
4928 -- enter local tagged types in the global hash table used to compute
4929 -- the Internal_Tag attribute for two reasons:
4931 -- 1. It is hard to avoid a tasking race condition for entering the
4932 -- entry into the hash table.
4934 -- 2. It would cause a storage leak, unless we rig up considerable
4935 -- mechanism to remove the entry from the hash table on exit.
4937 -- So what we do is to generate the above external tag name, where the
4938 -- hex address is the address of the local dispatch table (i.e. exactly
4939 -- the value we want if Internal_Tag is computed from this string).
4941 -- Of course this value will only be valid if the tagged type is still
4942 -- in scope, but it clearly must be erroneous to compute the internal
4943 -- tag of a tagged type that is out of scope.
4945 -- We don't do this processing if an explicit external tag has been
4946 -- specified. That's an odd case for which we have already issued a
4947 -- warning, where we will not be able to compute the internal tag.
4949 if not Is_Library_Level_Entity
(Typ
)
4950 and then not Has_External_Tag_Rep_Clause
(Typ
)
4953 Exname
: constant Entity_Id
:=
4954 Make_Defining_Identifier
(Loc
,
4955 Chars
=> New_External_Name
(Tname
, 'A'));
4956 Full_Name
: constant String_Id
:=
4957 Fully_Qualified_Name_String
(First_Subtype
(Typ
));
4958 Str1_Id
: String_Id
;
4959 Str2_Id
: String_Id
;
4963 -- Str1 = "Internal tag at 16#";
4966 Store_String_Chars
("Internal tag at 16#");
4967 Str1_Id
:= End_String
;
4970 -- Str2 = "#: <type-full-name>";
4973 Store_String_Chars
("#: ");
4974 Store_String_Chars
(Full_Name
);
4975 Str2_Id
:= End_String
;
4978 -- Exname : constant String :=
4979 -- Str1 & Address_Image (Tag) & Str2;
4981 if RTE_Available
(RE_Address_Image
) then
4983 Make_Object_Declaration
(Loc
,
4984 Defining_Identifier
=> Exname
,
4985 Constant_Present
=> True,
4986 Object_Definition
=> New_Occurrence_Of
4987 (Standard_String
, Loc
),
4989 Make_Op_Concat
(Loc
,
4990 Left_Opnd
=> Make_String_Literal
(Loc
, Str1_Id
),
4992 Make_Op_Concat
(Loc
,
4994 Make_Function_Call
(Loc
,
4997 (RTE
(RE_Address_Image
), Loc
),
4998 Parameter_Associations
=> New_List
(
4999 Unchecked_Convert_To
(RTE
(RE_Address
),
5000 New_Occurrence_Of
(DT_Ptr
, Loc
)))),
5002 Make_String_Literal
(Loc
, Str2_Id
)))));
5006 Make_Object_Declaration
(Loc
,
5007 Defining_Identifier
=> Exname
,
5008 Constant_Present
=> True,
5009 Object_Definition
=>
5010 New_Occurrence_Of
(Standard_String
, Loc
),
5012 Make_Op_Concat
(Loc
,
5013 Left_Opnd
=> Make_String_Literal
(Loc
, Str1_Id
),
5014 Right_Opnd
=> Make_String_Literal
(Loc
, Str2_Id
))));
5018 Unchecked_Convert_To
(RTE
(RE_Cstring_Ptr
),
5019 Make_Attribute_Reference
(Loc
,
5020 Prefix
=> New_Occurrence_Of
(Exname
, Loc
),
5021 Attribute_Name
=> Name_Address
));
5024 -- External tag of a library-level tagged type: Check for a definition
5025 -- of External_Tag. The clause is considered only if it applies to this
5026 -- specific tagged type, as opposed to one of its ancestors.
5027 -- If the type is an unconstrained type extension, we are building the
5028 -- dispatch table of its anonymous base type, so the external tag, if
5029 -- any was specified, must be retrieved from the first subtype. Go to
5030 -- the full view in case the clause is in the private part.
5034 Def
: constant Node_Id
:= Get_Attribute_Definition_Clause
5035 (Underlying_Type
(First_Subtype
(Typ
)),
5036 Attribute_External_Tag
);
5038 Old_Val
: String_Id
;
5039 New_Val
: String_Id
;
5043 if not Present
(Def
)
5044 or else Entity
(Name
(Def
)) /= First_Subtype
(Typ
)
5047 Unchecked_Convert_To
(RTE
(RE_Cstring_Ptr
),
5048 Make_Attribute_Reference
(Loc
,
5049 Prefix
=> New_Occurrence_Of
(Exname
, Loc
),
5050 Attribute_Name
=> Name_Address
));
5052 Old_Val
:= Strval
(Expr_Value_S
(Expression
(Def
)));
5054 -- For the rep clause "for <typ>'external_tag use y" generate:
5056 -- <typ>A : constant string := y;
5058 -- <typ>A'Address is used to set the External_Tag component
5061 -- Create a new nul terminated string if it is not already
5063 if String_Length
(Old_Val
) > 0
5065 Get_String_Char
(Old_Val
, String_Length
(Old_Val
)) = 0
5069 Start_String
(Old_Val
);
5070 Store_String_Char
(Get_Char_Code
(ASCII
.NUL
));
5071 New_Val
:= End_String
;
5074 E
:= Make_Defining_Identifier
(Loc
,
5075 New_External_Name
(Chars
(Typ
), 'A'));
5078 Make_Object_Declaration
(Loc
,
5079 Defining_Identifier
=> E
,
5080 Constant_Present
=> True,
5081 Object_Definition
=>
5082 New_Occurrence_Of
(Standard_String
, Loc
),
5084 Make_String_Literal
(Loc
, New_Val
)));
5087 Unchecked_Convert_To
(RTE
(RE_Cstring_Ptr
),
5088 Make_Attribute_Reference
(Loc
,
5089 Prefix
=> New_Occurrence_Of
(E
, Loc
),
5090 Attribute_Name
=> Name_Address
));
5095 Append_To
(TSD_Aggr_List
, New_Node
);
5099 if RTE_Available
(RE_Register_Tag
) then
5100 Append_To
(TSD_Aggr_List
,
5101 Unchecked_Convert_To
(RTE
(RE_Tag_Ptr
),
5102 Make_Attribute_Reference
(Loc
,
5103 Prefix
=> New_Occurrence_Of
(HT_Link
, Loc
),
5104 Attribute_Name
=> Name_Address
)));
5106 Append_To
(TSD_Aggr_List
,
5107 Unchecked_Convert_To
(RTE
(RE_Tag_Ptr
),
5108 New_Occurrence_Of
(RTE
(RE_Null_Address
), Loc
)));
5111 -- Transportable: Set for types that can be used in remote calls
5112 -- with respect to E.4(18) legality rules.
5115 Transportable
: Entity_Id
;
5121 or else Is_Shared_Passive
(Typ
)
5123 ((Is_Remote_Types
(Typ
)
5124 or else Is_Remote_Call_Interface
(Typ
))
5125 and then Original_View_In_Visible_Part
(Typ
))
5126 or else not Comes_From_Source
(Typ
));
5128 Append_To
(TSD_Aggr_List
,
5129 New_Occurrence_Of
(Transportable
, Loc
));
5132 -- Type_Is_Abstract (Ada 2012: AI05-0173). This functionality is
5133 -- not available in the HIE runtime.
5135 if RTE_Record_Component_Available
(RE_Type_Is_Abstract
) then
5137 Type_Is_Abstract
: Entity_Id
;
5139 Type_Is_Abstract
:= Boolean_Literals
(Is_Abstract_Type
(Typ
));
5140 Append_To
(TSD_Aggr_List
,
5141 New_Occurrence_Of
(Type_Is_Abstract
, Loc
));
5145 -- Needs_Finalization: Set if the type is controlled or has controlled
5149 Needs_Fin
: Entity_Id
;
5151 Needs_Fin
:= Boolean_Literals
(Needs_Finalization
(Typ
));
5152 Append_To
(TSD_Aggr_List
, New_Occurrence_Of
(Needs_Fin
, Loc
));
5157 if RTE_Record_Component_Available
(RE_Size_Func
) then
5159 -- Initialize this field to Null_Address if we are not building
5160 -- static dispatch tables static or if the size function is not
5161 -- available. In the former case we cannot initialize this field
5162 -- until the function is frozen and registered in the dispatch
5163 -- table (see Register_Primitive).
5165 if not Building_Static_DT
(Typ
) or else not Has_DT
(Typ
) then
5166 Append_To
(TSD_Aggr_List
,
5167 Unchecked_Convert_To
(RTE
(RE_Size_Ptr
),
5168 New_Occurrence_Of
(RTE
(RE_Null_Address
), Loc
)));
5172 Prim_Elmt
: Elmt_Id
;
5174 Size_Comp
: Node_Id
;
5177 Prim_Elmt
:= First_Elmt
(Primitive_Operations
(Typ
));
5178 while Present
(Prim_Elmt
) loop
5179 Prim
:= Node
(Prim_Elmt
);
5181 if Chars
(Prim
) = Name_uSize
then
5182 Prim
:= Ultimate_Alias
(Prim
);
5184 if Is_Abstract_Subprogram
(Prim
) then
5186 Unchecked_Convert_To
(RTE
(RE_Size_Ptr
),
5187 New_Occurrence_Of
(RTE
(RE_Null_Address
), Loc
));
5190 Unchecked_Convert_To
(RTE
(RE_Size_Ptr
),
5191 Make_Attribute_Reference
(Loc
,
5192 Prefix
=> New_Occurrence_Of
(Prim
, Loc
),
5193 Attribute_Name
=> Name_Unrestricted_Access
));
5199 Next_Elmt
(Prim_Elmt
);
5202 pragma Assert
(Present
(Size_Comp
));
5203 Append_To
(TSD_Aggr_List
, Size_Comp
);
5208 -- Interfaces_Table (required for AI-405)
5210 if RTE_Record_Component_Available
(RE_Interfaces_Table
) then
5212 -- Count the number of interface types implemented by Typ
5214 Collect_Interfaces
(Typ
, Typ_Ifaces
);
5216 AI
:= First_Elmt
(Typ_Ifaces
);
5217 while Present
(AI
) loop
5218 Num_Ifaces
:= Num_Ifaces
+ 1;
5222 if Num_Ifaces
= 0 then
5223 Iface_Table_Node
:= Make_Null
(Loc
);
5225 -- Generate the Interface_Table object
5229 TSD_Ifaces_List
: constant List_Id
:= New_List
;
5231 Sec_DT_Tag
: Node_Id
;
5234 AI
:= First_Elmt
(Typ_Ifaces
);
5235 while Present
(AI
) loop
5236 if Is_Ancestor
(Node
(AI
), Typ
, Use_Full_View
=> True) then
5238 New_Occurrence_Of
(DT_Ptr
, Loc
);
5242 (Next_Elmt
(First_Elmt
(Access_Disp_Table
(Typ
))));
5243 pragma Assert
(Has_Thunks
(Node
(Elmt
)));
5245 while Is_Tag
(Node
(Elmt
))
5247 Is_Ancestor
(Node
(AI
), Related_Type
(Node
(Elmt
)),
5248 Use_Full_View
=> True)
5250 pragma Assert
(Has_Thunks
(Node
(Elmt
)));
5252 pragma Assert
(Has_Thunks
(Node
(Elmt
)));
5254 pragma Assert
(not Has_Thunks
(Node
(Elmt
)));
5256 pragma Assert
(not Has_Thunks
(Node
(Elmt
)));
5260 pragma Assert
(Ekind
(Node
(Elmt
)) = E_Constant
5262 Has_Thunks
(Node
(Next_Elmt
(Next_Elmt
(Elmt
)))));
5264 New_Occurrence_Of
(Node
(Next_Elmt
(Next_Elmt
(Elmt
))),
5268 Append_To
(TSD_Ifaces_List
,
5269 Make_Aggregate
(Loc
,
5270 Expressions
=> New_List
(
5274 Unchecked_Convert_To
(RTE
(RE_Tag
),
5276 (Node
(First_Elmt
(Access_Disp_Table
(Node
(AI
)))),
5279 -- Static_Offset_To_Top
5281 New_Occurrence_Of
(Standard_True
, Loc
),
5283 -- Offset_To_Top_Value
5285 Make_Integer_Literal
(Loc
, 0),
5287 -- Offset_To_Top_Func
5293 Unchecked_Convert_To
(RTE
(RE_Tag
), Sec_DT_Tag
)
5300 Name_ITable
:= New_External_Name
(Tname
, 'I');
5301 ITable
:= Make_Defining_Identifier
(Loc
, Name_ITable
);
5302 Set_Is_Statically_Allocated
(ITable
,
5303 Is_Library_Level_Tagged_Type
(Typ
));
5305 -- The table of interfaces is not constant; its slots are
5306 -- filled at run time by the IP routine using attribute
5307 -- 'Position to know the location of the tag components
5308 -- (and this attribute cannot be safely used before the
5309 -- object is initialized).
5312 Make_Object_Declaration
(Loc
,
5313 Defining_Identifier
=> ITable
,
5314 Aliased_Present
=> True,
5315 Constant_Present
=> False,
5316 Object_Definition
=>
5317 Make_Subtype_Indication
(Loc
,
5319 New_Occurrence_Of
(RTE
(RE_Interface_Data
), Loc
),
5321 Make_Index_Or_Discriminant_Constraint
(Loc
,
5322 Constraints
=> New_List
(
5323 Make_Integer_Literal
(Loc
, Num_Ifaces
)))),
5325 Expression
=> Make_Aggregate
(Loc
,
5326 Expressions
=> New_List
(
5327 Make_Integer_Literal
(Loc
, Num_Ifaces
),
5328 Make_Aggregate
(Loc
, TSD_Ifaces_List
)))));
5331 Make_Attribute_Definition_Clause
(Loc
,
5332 Name
=> New_Occurrence_Of
(ITable
, Loc
),
5333 Chars
=> Name_Alignment
,
5335 Make_Attribute_Reference
(Loc
,
5337 New_Occurrence_Of
(RTE
(RE_Integer_Address
), Loc
),
5338 Attribute_Name
=> Name_Alignment
)));
5341 Make_Attribute_Reference
(Loc
,
5342 Prefix
=> New_Occurrence_Of
(ITable
, Loc
),
5343 Attribute_Name
=> Name_Unchecked_Access
);
5347 Append_To
(TSD_Aggr_List
, Iface_Table_Node
);
5350 -- Generate the Select Specific Data table for synchronized types that
5351 -- implement synchronized interfaces. The size of the table is
5352 -- constrained by the number of non-predefined primitive operations.
5354 if RTE_Record_Component_Available
(RE_SSD
) then
5355 if Ada_Version
>= Ada_2005
5356 and then Has_DT
(Typ
)
5357 and then Is_Concurrent_Record_Type
(Typ
)
5358 and then Has_Interfaces
(Typ
)
5359 and then Nb_Prim
> 0
5360 and then not Is_Abstract_Type
(Typ
)
5361 and then not Is_Controlled
(Typ
)
5362 and then not Restriction_Active
(No_Dispatching_Calls
)
5363 and then not Restriction_Active
(No_Select_Statements
)
5366 Make_Object_Declaration
(Loc
,
5367 Defining_Identifier
=> SSD
,
5368 Aliased_Present
=> True,
5369 Object_Definition
=>
5370 Make_Subtype_Indication
(Loc
,
5371 Subtype_Mark
=> New_Occurrence_Of
(
5372 RTE
(RE_Select_Specific_Data
), Loc
),
5374 Make_Index_Or_Discriminant_Constraint
(Loc
,
5375 Constraints
=> New_List
(
5376 Make_Integer_Literal
(Loc
, Nb_Prim
))))));
5379 Make_Attribute_Definition_Clause
(Loc
,
5380 Name
=> New_Occurrence_Of
(SSD
, Loc
),
5381 Chars
=> Name_Alignment
,
5383 Make_Attribute_Reference
(Loc
,
5385 New_Occurrence_Of
(RTE
(RE_Integer_Address
), Loc
),
5386 Attribute_Name
=> Name_Alignment
)));
5388 -- This table is initialized by Make_Select_Specific_Data_Table,
5389 -- which calls Set_Entry_Index and Set_Prim_Op_Kind.
5391 Append_To
(TSD_Aggr_List
,
5392 Make_Attribute_Reference
(Loc
,
5393 Prefix
=> New_Occurrence_Of
(SSD
, Loc
),
5394 Attribute_Name
=> Name_Unchecked_Access
));
5396 Append_To
(TSD_Aggr_List
, Make_Null
(Loc
));
5400 -- Initialize the table of ancestor tags. In case of interface types
5401 -- this table is not needed.
5403 TSD_Tags_List
:= New_List
;
5405 -- If we are not statically allocating the dispatch table then we must
5406 -- fill position 0 with null because we still have not generated the
5409 if not Building_Static_DT
(Typ
)
5410 or else Is_Interface
(Typ
)
5412 Append_To
(TSD_Tags_List
,
5413 Unchecked_Convert_To
(RTE
(RE_Tag
),
5414 New_Occurrence_Of
(RTE
(RE_Null_Address
), Loc
)));
5416 -- Otherwise we can safely reference the tag
5419 Append_To
(TSD_Tags_List
,
5420 New_Occurrence_Of
(DT_Ptr
, Loc
));
5423 -- Fill the rest of the table with the tags of the ancestors
5426 Current_Typ
: Entity_Id
;
5427 Parent_Typ
: Entity_Id
;
5435 Parent_Typ
:= Etype
(Current_Typ
);
5437 if Is_Private_Type
(Parent_Typ
) then
5438 Parent_Typ
:= Full_View
(Base_Type
(Parent_Typ
));
5441 exit when Parent_Typ
= Current_Typ
;
5443 if Is_CPP_Class
(Parent_Typ
) then
5445 -- The tags defined in the C++ side will be inherited when
5446 -- the object is constructed (Exp_Ch3.Build_Init_Procedure)
5448 Append_To
(TSD_Tags_List
,
5449 Unchecked_Convert_To
(RTE
(RE_Tag
),
5450 New_Occurrence_Of
(RTE
(RE_Null_Address
), Loc
)));
5452 Append_To
(TSD_Tags_List
,
5454 (Node
(First_Elmt
(Access_Disp_Table
(Parent_Typ
))),
5459 Current_Typ
:= Parent_Typ
;
5462 pragma Assert
(Pos
= I_Depth
+ 1);
5465 Append_To
(TSD_Aggr_List
,
5466 Make_Aggregate
(Loc
,
5467 Expressions
=> TSD_Tags_List
));
5469 -- Build the TSD object
5472 Make_Object_Declaration
(Loc
,
5473 Defining_Identifier
=> TSD
,
5474 Aliased_Present
=> True,
5475 Constant_Present
=> Building_Static_DT
(Typ
),
5476 Object_Definition
=>
5477 Make_Subtype_Indication
(Loc
,
5478 Subtype_Mark
=> New_Occurrence_Of
(
5479 RTE
(RE_Type_Specific_Data
), Loc
),
5481 Make_Index_Or_Discriminant_Constraint
(Loc
,
5482 Constraints
=> New_List
(
5483 Make_Integer_Literal
(Loc
, I_Depth
)))),
5485 Expression
=> Make_Aggregate
(Loc
,
5486 Expressions
=> TSD_Aggr_List
)));
5488 Set_Is_True_Constant
(TSD
, Building_Static_DT
(Typ
));
5491 Make_Attribute_Definition_Clause
(Loc
,
5492 Name
=> New_Occurrence_Of
(TSD
, Loc
),
5493 Chars
=> Name_Alignment
,
5495 Make_Attribute_Reference
(Loc
,
5497 New_Occurrence_Of
(RTE
(RE_Integer_Address
), Loc
),
5498 Attribute_Name
=> Name_Alignment
)));
5500 -- Initialize or declare the dispatch table object
5502 if not Has_DT
(Typ
) then
5503 DT_Constr_List
:= New_List
;
5504 DT_Aggr_List
:= New_List
;
5509 Make_Attribute_Reference
(Loc
,
5510 Prefix
=> New_Occurrence_Of
(TSD
, Loc
),
5511 Attribute_Name
=> Name_Address
);
5513 Append_To
(DT_Constr_List
, New_Node
);
5514 Append_To
(DT_Aggr_List
, New_Copy
(New_Node
));
5515 Append_To
(DT_Aggr_List
, Make_Integer_Literal
(Loc
, 0));
5517 -- In case of locally defined tagged types we have already declared
5518 -- and uninitialized object for the dispatch table, which is now
5519 -- initialized by means of the following assignment:
5521 -- DT := (TSD'Address, 0);
5523 if not Building_Static_DT
(Typ
) then
5525 Make_Assignment_Statement
(Loc
,
5526 Name
=> New_Occurrence_Of
(DT
, Loc
),
5527 Expression
=> Make_Aggregate
(Loc
, DT_Aggr_List
)));
5529 -- In case of library level tagged types we declare and export now
5530 -- the constant object containing the dummy dispatch table. There
5531 -- is no need to declare the tag here because it has been previously
5532 -- declared by Make_Tags
5534 -- DT : aliased constant No_Dispatch_Table :=
5535 -- (NDT_TSD => TSD'Address;
5536 -- NDT_Prims_Ptr => 0);
5537 -- for DT'Alignment use Address'Alignment;
5541 Make_Object_Declaration
(Loc
,
5542 Defining_Identifier
=> DT
,
5543 Aliased_Present
=> True,
5544 Constant_Present
=> True,
5545 Object_Definition
=>
5546 New_Occurrence_Of
(RTE
(RE_No_Dispatch_Table_Wrapper
), Loc
),
5547 Expression
=> Make_Aggregate
(Loc
, DT_Aggr_List
)));
5550 Make_Attribute_Definition_Clause
(Loc
,
5551 Name
=> New_Occurrence_Of
(DT
, Loc
),
5552 Chars
=> Name_Alignment
,
5554 Make_Attribute_Reference
(Loc
,
5556 New_Occurrence_Of
(RTE
(RE_Integer_Address
), Loc
),
5557 Attribute_Name
=> Name_Alignment
)));
5559 Export_DT
(Typ
, DT
);
5562 -- Common case: Typ has a dispatch table
5566 -- Predef_Prims : Address_Array (1 .. Default_Prim_Ops_Count) :=
5567 -- (predef-prim-op-1'address,
5568 -- predef-prim-op-2'address,
5570 -- predef-prim-op-n'address);
5571 -- for Predef_Prims'Alignment use Address'Alignment
5573 -- DT : Dispatch_Table (Nb_Prims) :=
5574 -- (Signature => <sig-value>,
5575 -- Tag_Kind => <tag_kind-value>,
5576 -- Predef_Prims => Predef_Prims'First'Address,
5577 -- Offset_To_Top => 0,
5578 -- TSD => TSD'Address;
5579 -- Prims_Ptr => (prim-op-1'address,
5580 -- prim-op-2'address,
5582 -- prim-op-n'address));
5583 -- for DT'Alignment use Address'Alignment
5590 if not Building_Static_DT
(Typ
) then
5591 Nb_Predef_Prims
:= Max_Predef_Prims
;
5594 Prim_Elmt
:= First_Elmt
(Primitive_Operations
(Typ
));
5595 while Present
(Prim_Elmt
) loop
5596 Prim
:= Node
(Prim_Elmt
);
5598 if Is_Predefined_Dispatching_Operation
(Prim
)
5599 and then not Is_Abstract_Subprogram
(Prim
)
5601 Pos
:= UI_To_Int
(DT_Position
(Prim
));
5603 if Pos
> Nb_Predef_Prims
then
5604 Nb_Predef_Prims
:= Pos
;
5608 Next_Elmt
(Prim_Elmt
);
5614 (Nat
range 1 .. Nb_Predef_Prims
) of Entity_Id
;
5619 Prim_Ops_Aggr_List
:= New_List
;
5621 Prim_Table
:= (others => Empty
);
5623 if Building_Static_DT
(Typ
) then
5624 Prim_Elmt
:= First_Elmt
(Primitive_Operations
(Typ
));
5625 while Present
(Prim_Elmt
) loop
5626 Prim
:= Node
(Prim_Elmt
);
5628 if Is_Predefined_Dispatching_Operation
(Prim
)
5629 and then not Is_Abstract_Subprogram
(Prim
)
5630 and then not Is_Eliminated
(Prim
)
5631 and then not Present
(Prim_Table
5632 (UI_To_Int
(DT_Position
(Prim
))))
5634 E
:= Ultimate_Alias
(Prim
);
5635 pragma Assert
(not Is_Abstract_Subprogram
(E
));
5636 Prim_Table
(UI_To_Int
(DT_Position
(Prim
))) := E
;
5639 Next_Elmt
(Prim_Elmt
);
5643 for J
in Prim_Table
'Range loop
5644 if Present
(Prim_Table
(J
)) then
5646 Unchecked_Convert_To
(RTE
(RE_Prim_Ptr
),
5647 Make_Attribute_Reference
(Loc
,
5649 New_Occurrence_Of
(Prim_Table
(J
), Loc
),
5650 Attribute_Name
=> Name_Unrestricted_Access
));
5652 New_Node
:= Make_Null
(Loc
);
5655 Append_To
(Prim_Ops_Aggr_List
, New_Node
);
5659 Make_Aggregate
(Loc
,
5660 Expressions
=> Prim_Ops_Aggr_List
);
5663 Make_Subtype_Declaration
(Loc
,
5664 Defining_Identifier
=> Make_Temporary
(Loc
, 'S'),
5665 Subtype_Indication
=>
5666 New_Occurrence_Of
(RTE
(RE_Address_Array
), Loc
));
5668 Append_To
(Result
, Decl
);
5671 Make_Object_Declaration
(Loc
,
5672 Defining_Identifier
=> Predef_Prims
,
5673 Aliased_Present
=> True,
5674 Constant_Present
=> Building_Static_DT
(Typ
),
5675 Object_Definition
=>
5676 New_Occurrence_Of
(Defining_Identifier
(Decl
), Loc
),
5677 Expression
=> New_Node
));
5679 -- Remember aggregates initializing dispatch tables
5681 Append_Elmt
(New_Node
, DT_Aggr
);
5684 Make_Attribute_Definition_Clause
(Loc
,
5685 Name
=> New_Occurrence_Of
(Predef_Prims
, Loc
),
5686 Chars
=> Name_Alignment
,
5688 Make_Attribute_Reference
(Loc
,
5690 New_Occurrence_Of
(RTE
(RE_Integer_Address
), Loc
),
5691 Attribute_Name
=> Name_Alignment
)));
5695 -- Stage 1: Initialize the discriminant and the record components
5697 DT_Constr_List
:= New_List
;
5698 DT_Aggr_List
:= New_List
;
5700 -- Num_Prims. If the tagged type has no primitives we add a dummy
5701 -- slot whose address will be the tag of this type.
5704 New_Node
:= Make_Integer_Literal
(Loc
, 1);
5706 New_Node
:= Make_Integer_Literal
(Loc
, Nb_Prim
);
5709 Append_To
(DT_Constr_List
, New_Node
);
5710 Append_To
(DT_Aggr_List
, New_Copy
(New_Node
));
5714 if RTE_Record_Component_Available
(RE_Signature
) then
5715 Append_To
(DT_Aggr_List
,
5716 New_Occurrence_Of
(RTE
(RE_Primary_DT
), Loc
));
5721 if RTE_Record_Component_Available
(RE_Tag_Kind
) then
5722 Append_To
(DT_Aggr_List
, Tagged_Kind
(Typ
));
5727 Append_To
(DT_Aggr_List
,
5728 Make_Attribute_Reference
(Loc
,
5729 Prefix
=> New_Occurrence_Of
(Predef_Prims
, Loc
),
5730 Attribute_Name
=> Name_Address
));
5734 Append_To
(DT_Aggr_List
, Make_Integer_Literal
(Loc
, 0));
5738 Append_To
(DT_Aggr_List
,
5739 Make_Attribute_Reference
(Loc
,
5740 Prefix
=> New_Occurrence_Of
(TSD
, Loc
),
5741 Attribute_Name
=> Name_Address
));
5743 -- Stage 2: Initialize the table of user-defined primitive operations
5745 Prim_Ops_Aggr_List
:= New_List
;
5748 Append_To
(Prim_Ops_Aggr_List
, Make_Null
(Loc
));
5750 elsif not Building_Static_DT
(Typ
) then
5751 for J
in 1 .. Nb_Prim
loop
5752 Append_To
(Prim_Ops_Aggr_List
, Make_Null
(Loc
));
5757 CPP_Nb_Prims
: constant Nat
:= CPP_Num_Prims
(Typ
);
5760 Prim_Elmt
: Elmt_Id
;
5762 Prim_Table
: array (Nat
range 1 .. Nb_Prim
) of Entity_Id
;
5765 Prim_Table
:= (others => Empty
);
5767 Prim_Elmt
:= First_Elmt
(Primitive_Operations
(Typ
));
5768 while Present
(Prim_Elmt
) loop
5769 Prim
:= Node
(Prim_Elmt
);
5771 -- Retrieve the ultimate alias of the primitive for proper
5772 -- handling of renamings and eliminated primitives.
5774 E
:= Ultimate_Alias
(Prim
);
5775 Prim_Pos
:= UI_To_Int
(DT_Position
(E
));
5777 -- Do not reference predefined primitives because they are
5778 -- located in a separate dispatch table; skip entities with
5779 -- attribute Interface_Alias because they are only required
5780 -- to build secondary dispatch tables; skip abstract and
5781 -- eliminated primitives; for derivations of CPP types skip
5782 -- primitives located in the C++ part of the dispatch table
5783 -- because their slot is initialized by the IC routine.
5785 if not Is_Predefined_Dispatching_Operation
(Prim
)
5786 and then not Is_Predefined_Dispatching_Operation
(E
)
5787 and then not Present
(Interface_Alias
(Prim
))
5788 and then not Is_Abstract_Subprogram
(E
)
5789 and then not Is_Eliminated
(E
)
5790 and then (not Is_CPP_Class
(Root_Type
(Typ
))
5791 or else Prim_Pos
> CPP_Nb_Prims
)
5794 (UI_To_Int
(DT_Position
(Prim
)) <= Nb_Prim
);
5796 Prim_Table
(UI_To_Int
(DT_Position
(Prim
))) := E
;
5799 Next_Elmt
(Prim_Elmt
);
5802 for J
in Prim_Table
'Range loop
5803 if Present
(Prim_Table
(J
)) then
5805 Unchecked_Convert_To
(RTE
(RE_Prim_Ptr
),
5806 Make_Attribute_Reference
(Loc
,
5808 New_Occurrence_Of
(Prim_Table
(J
), Loc
),
5809 Attribute_Name
=> Name_Unrestricted_Access
));
5811 New_Node
:= Make_Null
(Loc
);
5814 Append_To
(Prim_Ops_Aggr_List
, New_Node
);
5820 Make_Aggregate
(Loc
,
5821 Expressions
=> Prim_Ops_Aggr_List
);
5823 Append_To
(DT_Aggr_List
, New_Node
);
5825 -- Remember aggregates initializing dispatch tables
5827 Append_Elmt
(New_Node
, DT_Aggr
);
5829 -- In case of locally defined tagged types we have already declared
5830 -- and uninitialized object for the dispatch table, which is now
5831 -- initialized by means of an assignment.
5833 if not Building_Static_DT
(Typ
) then
5835 Make_Assignment_Statement
(Loc
,
5836 Name
=> New_Occurrence_Of
(DT
, Loc
),
5837 Expression
=> Make_Aggregate
(Loc
, DT_Aggr_List
)));
5839 -- In case of library level tagged types we declare now and export
5840 -- the constant object containing the dispatch table.
5844 Make_Object_Declaration
(Loc
,
5845 Defining_Identifier
=> DT
,
5846 Aliased_Present
=> True,
5847 Constant_Present
=> True,
5848 Object_Definition
=>
5849 Make_Subtype_Indication
(Loc
,
5850 Subtype_Mark
=> New_Occurrence_Of
5851 (RTE
(RE_Dispatch_Table_Wrapper
), Loc
),
5852 Constraint
=> Make_Index_Or_Discriminant_Constraint
(Loc
,
5853 Constraints
=> DT_Constr_List
)),
5854 Expression
=> Make_Aggregate
(Loc
, DT_Aggr_List
)));
5857 Make_Attribute_Definition_Clause
(Loc
,
5858 Name
=> New_Occurrence_Of
(DT
, Loc
),
5859 Chars
=> Name_Alignment
,
5861 Make_Attribute_Reference
(Loc
,
5863 New_Occurrence_Of
(RTE
(RE_Integer_Address
), Loc
),
5864 Attribute_Name
=> Name_Alignment
)));
5866 Export_DT
(Typ
, DT
);
5870 -- Initialize the table of ancestor tags if not building static
5873 if not Building_Static_DT
(Typ
)
5874 and then not Is_Interface
(Typ
)
5875 and then not Is_CPP_Class
(Typ
)
5878 Make_Assignment_Statement
(Loc
,
5880 Make_Indexed_Component
(Loc
,
5882 Make_Selected_Component
(Loc
,
5883 Prefix
=> New_Occurrence_Of
(TSD
, Loc
),
5886 (RTE_Record_Component
(RE_Tags_Table
), Loc
)),
5888 New_List
(Make_Integer_Literal
(Loc
, 0))),
5892 (Node
(First_Elmt
(Access_Disp_Table
(Typ
))), Loc
)));
5895 -- Inherit the dispatch tables of the parent. There is no need to
5896 -- inherit anything from the parent when building static dispatch tables
5897 -- because the whole dispatch table (including inherited primitives) has
5898 -- been already built.
5900 if Building_Static_DT
(Typ
) then
5903 -- If the ancestor is a CPP_Class type we inherit the dispatch tables
5904 -- in the init proc, and we don't need to fill them in here.
5906 elsif Is_CPP_Class
(Parent_Typ
) then
5909 -- Otherwise we fill in the dispatch tables here
5912 if Typ
/= Parent_Typ
5913 and then not Is_Interface
(Typ
)
5914 and then not Restriction_Active
(No_Dispatching_Calls
)
5916 -- Inherit the dispatch table
5918 if not Is_Interface
(Typ
)
5919 and then not Is_Interface
(Parent_Typ
)
5920 and then not Is_CPP_Class
(Parent_Typ
)
5923 Nb_Prims
: constant Int
:=
5924 UI_To_Int
(DT_Entry_Count
5925 (First_Tag_Component
(Parent_Typ
)));
5928 Append_To
(Elab_Code
,
5929 Build_Inherit_Predefined_Prims
(Loc
,
5935 (Access_Disp_Table
(Parent_Typ
)))), Loc
),
5941 (Access_Disp_Table
(Typ
)))), Loc
)));
5943 if Nb_Prims
/= 0 then
5944 Append_To
(Elab_Code
,
5945 Build_Inherit_Prims
(Loc
,
5951 (Access_Disp_Table
(Parent_Typ
))), Loc
),
5952 New_Tag_Node
=> New_Occurrence_Of
(DT_Ptr
, Loc
),
5953 Num_Prims
=> Nb_Prims
));
5958 -- Inherit the secondary dispatch tables of the ancestor
5960 if not Is_CPP_Class
(Parent_Typ
) then
5962 Sec_DT_Ancestor
: Elmt_Id
:=
5968 Sec_DT_Typ
: Elmt_Id
:=
5972 (Access_Disp_Table
(Typ
))));
5974 procedure Copy_Secondary_DTs
(Typ
: Entity_Id
);
5975 -- Local procedure required to climb through the ancestors
5976 -- and copy the contents of all their secondary dispatch
5979 ------------------------
5980 -- Copy_Secondary_DTs --
5981 ------------------------
5983 procedure Copy_Secondary_DTs
(Typ
: Entity_Id
) is
5988 -- Climb to the ancestor (if any) handling private types
5990 if Present
(Full_View
(Etype
(Typ
))) then
5991 if Full_View
(Etype
(Typ
)) /= Typ
then
5992 Copy_Secondary_DTs
(Full_View
(Etype
(Typ
)));
5995 elsif Etype
(Typ
) /= Typ
then
5996 Copy_Secondary_DTs
(Etype
(Typ
));
5999 if Present
(Interfaces
(Typ
))
6000 and then not Is_Empty_Elmt_List
(Interfaces
(Typ
))
6002 Iface
:= First_Elmt
(Interfaces
(Typ
));
6003 E
:= First_Entity
(Typ
);
6005 and then Present
(Node
(Sec_DT_Ancestor
))
6006 and then Ekind
(Node
(Sec_DT_Ancestor
)) = E_Constant
6008 if Is_Tag
(E
) and then Chars
(E
) /= Name_uTag
then
6010 Num_Prims
: constant Int
:=
6011 UI_To_Int
(DT_Entry_Count
(E
));
6014 if not Is_Interface
(Etype
(Typ
)) then
6016 -- Inherit first secondary dispatch table
6018 Append_To
(Elab_Code
,
6019 Build_Inherit_Predefined_Prims
(Loc
,
6021 Unchecked_Convert_To
(RTE
(RE_Tag
),
6024 (Next_Elmt
(Sec_DT_Ancestor
)),
6027 Unchecked_Convert_To
(RTE
(RE_Tag
),
6029 (Node
(Next_Elmt
(Sec_DT_Typ
)),
6032 if Num_Prims
/= 0 then
6033 Append_To
(Elab_Code
,
6034 Build_Inherit_Prims
(Loc
,
6035 Typ
=> Node
(Iface
),
6037 Unchecked_Convert_To
6040 (Node
(Sec_DT_Ancestor
),
6043 Unchecked_Convert_To
6046 (Node
(Sec_DT_Typ
), Loc
)),
6047 Num_Prims
=> Num_Prims
));
6051 Next_Elmt
(Sec_DT_Ancestor
);
6052 Next_Elmt
(Sec_DT_Typ
);
6054 -- Skip the secondary dispatch table of
6055 -- predefined primitives
6057 Next_Elmt
(Sec_DT_Ancestor
);
6058 Next_Elmt
(Sec_DT_Typ
);
6060 if not Is_Interface
(Etype
(Typ
)) then
6062 -- Inherit second secondary dispatch table
6064 Append_To
(Elab_Code
,
6065 Build_Inherit_Predefined_Prims
(Loc
,
6067 Unchecked_Convert_To
(RTE
(RE_Tag
),
6070 (Next_Elmt
(Sec_DT_Ancestor
)),
6073 Unchecked_Convert_To
(RTE
(RE_Tag
),
6075 (Node
(Next_Elmt
(Sec_DT_Typ
)),
6078 if Num_Prims
/= 0 then
6079 Append_To
(Elab_Code
,
6080 Build_Inherit_Prims
(Loc
,
6081 Typ
=> Node
(Iface
),
6083 Unchecked_Convert_To
6086 (Node
(Sec_DT_Ancestor
),
6089 Unchecked_Convert_To
6092 (Node
(Sec_DT_Typ
), Loc
)),
6093 Num_Prims
=> Num_Prims
));
6098 Next_Elmt
(Sec_DT_Ancestor
);
6099 Next_Elmt
(Sec_DT_Typ
);
6101 -- Skip the secondary dispatch table of
6102 -- predefined primitives
6104 Next_Elmt
(Sec_DT_Ancestor
);
6105 Next_Elmt
(Sec_DT_Typ
);
6113 end Copy_Secondary_DTs
;
6116 if Present
(Node
(Sec_DT_Ancestor
))
6117 and then Ekind
(Node
(Sec_DT_Ancestor
)) = E_Constant
6119 -- Handle private types
6121 if Present
(Full_View
(Typ
)) then
6122 Copy_Secondary_DTs
(Full_View
(Typ
));
6124 Copy_Secondary_DTs
(Typ
);
6132 -- Generate code to check if the external tag of this type is the same
6133 -- as the external tag of some other declaration.
6135 -- Check_TSD (TSD'Unrestricted_Access);
6137 -- This check is a consequence of AI05-0113-1/06, so it officially
6138 -- applies to Ada 2005 (and Ada 2012). It might be argued that it is
6139 -- a desirable check to add in Ada 95 mode, but we hesitate to make
6140 -- this change, as it would be incompatible, and could conceivably
6141 -- cause a problem in existing Aa 95 code.
6143 -- We check for No_Run_Time_Mode here, because we do not want to pick
6144 -- up the RE_Check_TSD entity and call it in No_Run_Time mode.
6146 if not No_Run_Time_Mode
6147 and then Ada_Version
>= Ada_2005
6148 and then RTE_Available
(RE_Check_TSD
)
6149 and then not Duplicated_Tag_Checks_Suppressed
(Typ
)
6151 Append_To
(Elab_Code
,
6152 Make_Procedure_Call_Statement
(Loc
,
6154 New_Occurrence_Of
(RTE
(RE_Check_TSD
), Loc
),
6155 Parameter_Associations
=> New_List
(
6156 Make_Attribute_Reference
(Loc
,
6157 Prefix
=> New_Occurrence_Of
(TSD
, Loc
),
6158 Attribute_Name
=> Name_Unchecked_Access
))));
6161 -- Generate code to register the Tag in the External_Tag hash table for
6162 -- the pure Ada type only.
6164 -- Register_Tag (Dt_Ptr);
6166 -- Skip this action in the following cases:
6167 -- 1) if Register_Tag is not available.
6168 -- 2) in No_Run_Time mode.
6169 -- 3) if Typ is not defined at the library level (this is required
6170 -- to avoid adding concurrency control to the hash table used
6171 -- by the run-time to register the tags).
6173 if not No_Run_Time_Mode
6174 and then Is_Library_Level_Entity
(Typ
)
6175 and then RTE_Available
(RE_Register_Tag
)
6177 Append_To
(Elab_Code
,
6178 Make_Procedure_Call_Statement
(Loc
,
6180 New_Occurrence_Of
(RTE
(RE_Register_Tag
), Loc
),
6181 Parameter_Associations
=>
6182 New_List
(New_Occurrence_Of
(DT_Ptr
, Loc
))));
6185 if not Is_Empty_List
(Elab_Code
) then
6186 Append_List_To
(Result
, Elab_Code
);
6189 -- Populate the two auxiliary tables used for dispatching asynchronous,
6190 -- conditional and timed selects for synchronized types that implement
6191 -- a limited interface. Skip this step in Ravenscar profile or when
6192 -- general dispatching is forbidden.
6194 if Ada_Version
>= Ada_2005
6195 and then Is_Concurrent_Record_Type
(Typ
)
6196 and then Has_Interfaces
(Typ
)
6197 and then not Restriction_Active
(No_Dispatching_Calls
)
6198 and then not Restriction_Active
(No_Select_Statements
)
6200 Append_List_To
(Result
,
6201 Make_Select_Specific_Data_Table
(Typ
));
6204 -- Remember entities containing dispatch tables
6206 Append_Elmt
(Predef_Prims
, DT_Decl
);
6207 Append_Elmt
(DT
, DT_Decl
);
6209 Analyze_List
(Result
, Suppress
=> All_Checks
);
6210 Set_Has_Dispatch_Table
(Typ
);
6212 -- Mark entities containing dispatch tables. Required by the backend to
6213 -- handle them properly.
6215 if Has_DT
(Typ
) then
6220 -- Object declarations
6222 Elmt
:= First_Elmt
(DT_Decl
);
6223 while Present
(Elmt
) loop
6224 Set_Is_Dispatch_Table_Entity
(Node
(Elmt
));
6225 pragma Assert
(Ekind
(Etype
(Node
(Elmt
))) = E_Array_Subtype
6226 or else Ekind
(Etype
(Node
(Elmt
))) = E_Record_Subtype
);
6227 Set_Is_Dispatch_Table_Entity
(Etype
(Node
(Elmt
)));
6231 -- Aggregates initializing dispatch tables
6233 Elmt
:= First_Elmt
(DT_Aggr
);
6234 while Present
(Elmt
) loop
6235 Set_Is_Dispatch_Table_Entity
(Etype
(Node
(Elmt
)));
6241 -- Register the tagged type in the call graph nodes table
6243 Register_CG_Node
(Typ
);
6252 function Make_VM_TSD
(Typ
: Entity_Id
) return List_Id
is
6253 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
6254 Result
: constant List_Id
:= New_List
;
6256 function Count_Primitives
(Typ
: Entity_Id
) return Nat
;
6257 -- Count the non-predefined primitive operations of Typ
6259 ----------------------
6260 -- Count_Primitives --
6261 ----------------------
6263 function Count_Primitives
(Typ
: Entity_Id
) return Nat
is
6265 Prim_Elmt
: Elmt_Id
;
6271 Prim_Elmt
:= First_Elmt
(Primitive_Operations
(Typ
));
6272 while Present
(Prim_Elmt
) loop
6273 Prim
:= Node
(Prim_Elmt
);
6275 if Is_Predefined_Dispatching_Operation
(Prim
)
6276 or else Is_Predefined_Dispatching_Alias
(Prim
)
6280 elsif Present
(Interface_Alias
(Prim
)) then
6284 Nb_Prim
:= Nb_Prim
+ 1;
6287 Next_Elmt
(Prim_Elmt
);
6291 end Count_Primitives
;
6297 function Make_OSD
(Iface
: Entity_Id
) return Node_Id
;
6298 -- Generate the Object Specific Data table required to dispatch calls
6299 -- through synchronized interfaces. Returns a node that references the
6300 -- generated OSD object.
6302 function Make_OSD
(Iface
: Entity_Id
) return Node_Id
is
6303 Nb_Prim
: constant Nat
:= Count_Primitives
(Iface
);
6305 OSD_Aggr_List
: List_Id
;
6309 -- OSD : Ada.Tags.Object_Specific_Data (Nb_Prims) :=
6310 -- (OSD_Table => (1 => <value>,
6315 or else Is_Abstract_Type
(Typ
)
6316 or else Is_Controlled
(Typ
)
6317 or else Restriction_Active
(No_Dispatching_Calls
)
6318 or else not Is_Limited_Type
(Typ
)
6319 or else not Has_Interfaces
(Typ
)
6320 or else not RTE_Record_Component_Available
(RE_OSD_Table
)
6322 -- No OSD table required
6324 return Make_Null
(Loc
);
6327 OSD_Aggr_List
:= New_List
;
6330 Prim_Table
: array (Nat
range 1 .. Nb_Prim
) of Entity_Id
;
6332 Prim_Alias
: Entity_Id
;
6333 Prim_Elmt
: Elmt_Id
;
6339 Prim_Table
:= (others => Empty
);
6340 Prim_Alias
:= Empty
;
6342 Prim_Elmt
:= First_Elmt
(Primitive_Operations
(Typ
));
6343 while Present
(Prim_Elmt
) loop
6344 Prim
:= Node
(Prim_Elmt
);
6346 if Present
(Interface_Alias
(Prim
))
6347 and then Find_Dispatching_Type
6348 (Interface_Alias
(Prim
)) = Iface
6350 Prim_Alias
:= Interface_Alias
(Prim
);
6351 E
:= Ultimate_Alias
(Prim
);
6352 Pos
:= UI_To_Int
(DT_Position
(Prim_Alias
));
6354 if Present
(Prim_Table
(Pos
)) then
6355 pragma Assert
(Prim_Table
(Pos
) = E
);
6359 Prim_Table
(Pos
) := E
;
6361 Append_To
(OSD_Aggr_List
,
6362 Make_Component_Association
(Loc
,
6363 Choices
=> New_List
(
6364 Make_Integer_Literal
(Loc
,
6365 DT_Position
(Prim_Alias
))),
6367 Make_Integer_Literal
(Loc
,
6368 DT_Position
(Alias
(Prim
)))));
6374 Next_Elmt
(Prim_Elmt
);
6377 pragma Assert
(Count
= Nb_Prim
);
6380 OSD
:= Make_Temporary
(Loc
, 'I');
6383 Make_Object_Declaration
(Loc
,
6384 Defining_Identifier
=> OSD
,
6385 Aliased_Present
=> True,
6386 Constant_Present
=> True,
6387 Object_Definition
=>
6388 Make_Subtype_Indication
(Loc
,
6390 New_Occurrence_Of
(RTE
(RE_Object_Specific_Data
), Loc
),
6392 Make_Index_Or_Discriminant_Constraint
(Loc
,
6393 Constraints
=> New_List
(
6394 Make_Integer_Literal
(Loc
, Nb_Prim
)))),
6397 Make_Aggregate
(Loc
,
6398 Component_Associations
=> New_List
(
6399 Make_Component_Association
(Loc
,
6400 Choices
=> New_List
(
6402 (RTE_Record_Component
(RE_OSD_Num_Prims
), Loc
)),
6404 Make_Integer_Literal
(Loc
, Nb_Prim
)),
6406 Make_Component_Association
(Loc
,
6407 Choices
=> New_List
(
6409 (RTE_Record_Component
(RE_OSD_Table
), Loc
)),
6410 Expression
=> Make_Aggregate
(Loc
,
6411 Component_Associations
=> OSD_Aggr_List
))))));
6414 Make_Attribute_Reference
(Loc
,
6415 Prefix
=> New_Occurrence_Of
(OSD
, Loc
),
6416 Attribute_Name
=> Name_Unchecked_Access
);
6422 Nb_Prim
: constant Nat
:= Count_Primitives
(Typ
);
6425 Iface_Table_Node
: Node_Id
;
6427 TSD_Aggr_List
: List_Id
;
6428 Typ_Ifaces
: Elist_Id
;
6429 TSD_Tags_List
: List_Id
;
6431 Tname
: constant Name_Id
:= Chars
(Typ
);
6432 Name_SSD
: constant Name_Id
:=
6433 New_External_Name
(Tname
, 'S', Suffix_Index
=> -1);
6434 Name_TSD
: constant Name_Id
:=
6435 New_External_Name
(Tname
, 'B', Suffix_Index
=> -1);
6436 SSD
: constant Entity_Id
:=
6437 Make_Defining_Identifier
(Loc
, Name_SSD
);
6438 TSD
: constant Entity_Id
:=
6439 Make_Defining_Identifier
(Loc
, Name_TSD
);
6441 -- Generate code to create the storage for the type specific data object
6442 -- with enough space to store the tags of the ancestors plus the tags
6443 -- of all the implemented interfaces (as described in a-tags.ads).
6445 -- TSD : Type_Specific_Data (I_Depth) :=
6446 -- (Idepth => I_Depth,
6447 -- Tag_Kind => <tag_kind-value>,
6448 -- Access_Level => Type_Access_Level (Typ),
6449 -- Alignment => Typ'Alignment,
6451 -- Type_Is_Abstract => <<boolean-value>>,
6452 -- Type_Is_Library_Level => <<boolean-value>>,
6453 -- Interfaces_Table => <<access-value>>
6454 -- SSD => SSD_Table'Address
6455 -- Tags_Table => (0 => Typ'Tag,
6459 TSD_Aggr_List
:= New_List
;
6461 -- Idepth: Count ancestors to compute the inheritance depth. For private
6462 -- extensions, always go to the full view in order to compute the real
6463 -- inheritance depth.
6466 Current_Typ
: Entity_Id
;
6467 Parent_Typ
: Entity_Id
;
6473 Parent_Typ
:= Etype
(Current_Typ
);
6475 if Is_Private_Type
(Parent_Typ
) then
6476 Parent_Typ
:= Full_View
(Base_Type
(Parent_Typ
));
6479 exit when Parent_Typ
= Current_Typ
;
6481 I_Depth
:= I_Depth
+ 1;
6482 Current_Typ
:= Parent_Typ
;
6488 Append_To
(TSD_Aggr_List
,
6489 Make_Integer_Literal
(Loc
, I_Depth
));
6493 Append_To
(TSD_Aggr_List
, Tagged_Kind
(Typ
));
6497 Append_To
(TSD_Aggr_List
,
6498 Make_Integer_Literal
(Loc
, Type_Access_Level
(Typ
)));
6502 -- For CPP types we cannot rely on the value of 'Alignment provided
6503 -- by the backend to initialize this TSD field. Why not???
6505 if Convention
(Typ
) = Convention_CPP
6506 or else Is_CPP_Class
(Root_Type
(Typ
))
6508 Append_To
(TSD_Aggr_List
,
6509 Make_Integer_Literal
(Loc
, 0));
6511 Append_To
(TSD_Aggr_List
,
6512 Make_Attribute_Reference
(Loc
,
6513 Prefix
=> New_Occurrence_Of
(Typ
, Loc
),
6514 Attribute_Name
=> Name_Alignment
));
6519 Append_To
(TSD_Aggr_List
,
6522 -- Type_Is_Abstract (Ada 2012: AI05-0173)
6525 Type_Is_Abstract
: Entity_Id
;
6529 Boolean_Literals
(Is_Abstract_Type
(Typ
));
6531 Append_To
(TSD_Aggr_List
,
6532 New_Occurrence_Of
(Type_Is_Abstract
, Loc
));
6535 -- Type_Is_Library_Level
6538 Type_Is_Library_Level
: Entity_Id
;
6540 Type_Is_Library_Level
:=
6541 Boolean_Literals
(Is_Library_Level_Entity
(Typ
));
6542 Append_To
(TSD_Aggr_List
,
6543 New_Occurrence_Of
(Type_Is_Library_Level
, Loc
));
6546 -- Interfaces_Table (required for AI-405)
6548 if RTE_Record_Component_Available
(RE_Interfaces_Table
) then
6550 -- Count the number of interface types implemented by Typ
6552 Collect_Interfaces
(Typ
, Typ_Ifaces
);
6555 AI
:= First_Elmt
(Typ_Ifaces
);
6556 while Present
(AI
) loop
6557 Num_Ifaces
:= Num_Ifaces
+ 1;
6561 if Num_Ifaces
= 0 then
6562 Iface_Table_Node
:= Make_Null
(Loc
);
6564 -- Generate the Interface_Table object
6568 TSD_Ifaces_List
: constant List_Id
:= New_List
;
6573 AI
:= First_Elmt
(Typ_Ifaces
);
6574 while Present
(AI
) loop
6577 Append_To
(TSD_Ifaces_List
,
6578 Make_Aggregate
(Loc
,
6579 Expressions
=> New_List
(
6583 Make_Attribute_Reference
(Loc
,
6584 Prefix
=> New_Occurrence_Of
(Iface
, Loc
),
6585 Attribute_Name
=> Name_Tag
),
6589 Make_OSD
(Iface
))));
6594 ITable
:= Make_Temporary
(Loc
, 'I');
6597 Make_Object_Declaration
(Loc
,
6598 Defining_Identifier
=> ITable
,
6599 Aliased_Present
=> True,
6600 Constant_Present
=> True,
6601 Object_Definition
=>
6602 Make_Subtype_Indication
(Loc
,
6604 New_Occurrence_Of
(RTE
(RE_Interface_Data
), Loc
),
6605 Constraint
=> Make_Index_Or_Discriminant_Constraint
6607 Constraints
=> New_List
(
6608 Make_Integer_Literal
(Loc
, Num_Ifaces
)))),
6610 Expression
=> Make_Aggregate
(Loc
,
6611 Expressions
=> New_List
(
6612 Make_Integer_Literal
(Loc
, Num_Ifaces
),
6613 Make_Aggregate
(Loc
,
6614 Expressions
=> TSD_Ifaces_List
)))));
6617 Make_Attribute_Reference
(Loc
,
6618 Prefix
=> New_Occurrence_Of
(ITable
, Loc
),
6619 Attribute_Name
=> Name_Unchecked_Access
);
6623 Append_To
(TSD_Aggr_List
, Iface_Table_Node
);
6626 -- Generate the Select Specific Data table for synchronized types that
6627 -- implement synchronized interfaces. The size of the table is
6628 -- constrained by the number of non-predefined primitive operations.
6630 if RTE_Record_Component_Available
(RE_SSD
) then
6631 if Ada_Version
>= Ada_2005
6632 and then Has_DT
(Typ
)
6633 and then Is_Concurrent_Record_Type
(Typ
)
6634 and then Has_Interfaces
(Typ
)
6635 and then Nb_Prim
> 0
6636 and then not Is_Abstract_Type
(Typ
)
6637 and then not Is_Controlled
(Typ
)
6638 and then not Restriction_Active
(No_Dispatching_Calls
)
6639 and then not Restriction_Active
(No_Select_Statements
)
6642 Make_Object_Declaration
(Loc
,
6643 Defining_Identifier
=> SSD
,
6644 Aliased_Present
=> True,
6645 Object_Definition
=>
6646 Make_Subtype_Indication
(Loc
,
6647 Subtype_Mark
=> New_Occurrence_Of
(
6648 RTE
(RE_Select_Specific_Data
), Loc
),
6650 Make_Index_Or_Discriminant_Constraint
(Loc
,
6651 Constraints
=> New_List
(
6652 Make_Integer_Literal
(Loc
, Nb_Prim
))))));
6654 -- This table is initialized by Make_Select_Specific_Data_Table,
6655 -- which calls Set_Entry_Index and Set_Prim_Op_Kind.
6657 Append_To
(TSD_Aggr_List
,
6658 Make_Attribute_Reference
(Loc
,
6659 Prefix
=> New_Occurrence_Of
(SSD
, Loc
),
6660 Attribute_Name
=> Name_Unchecked_Access
));
6662 Append_To
(TSD_Aggr_List
, Make_Null
(Loc
));
6666 -- Initialize the table of ancestor tags. In case of interface types
6667 -- this table is not needed.
6669 TSD_Tags_List
:= New_List
;
6671 -- Fill position 0 with Typ'Tag
6673 Append_To
(TSD_Tags_List
,
6674 Make_Attribute_Reference
(Loc
,
6675 Prefix
=> New_Occurrence_Of
(Typ
, Loc
),
6676 Attribute_Name
=> Name_Tag
));
6678 -- Fill the rest of the table with the tags of the ancestors
6681 Current_Typ
: Entity_Id
;
6682 Parent_Typ
: Entity_Id
;
6690 Parent_Typ
:= Etype
(Current_Typ
);
6692 if Is_Private_Type
(Parent_Typ
) then
6693 Parent_Typ
:= Full_View
(Base_Type
(Parent_Typ
));
6696 exit when Parent_Typ
= Current_Typ
;
6698 Append_To
(TSD_Tags_List
,
6699 Make_Attribute_Reference
(Loc
,
6700 Prefix
=> New_Occurrence_Of
(Parent_Typ
, Loc
),
6701 Attribute_Name
=> Name_Tag
));
6704 Current_Typ
:= Parent_Typ
;
6707 pragma Assert
(Pos
= I_Depth
+ 1);
6710 Append_To
(TSD_Aggr_List
,
6711 Make_Aggregate
(Loc
,
6712 Expressions
=> TSD_Tags_List
));
6714 -- Build the TSD object
6717 Make_Object_Declaration
(Loc
,
6718 Defining_Identifier
=> TSD
,
6719 Aliased_Present
=> True,
6720 Constant_Present
=> True,
6721 Object_Definition
=>
6722 Make_Subtype_Indication
(Loc
,
6723 Subtype_Mark
=> New_Occurrence_Of
(
6724 RTE
(RE_Type_Specific_Data
), Loc
),
6726 Make_Index_Or_Discriminant_Constraint
(Loc
,
6727 Constraints
=> New_List
(
6728 Make_Integer_Literal
(Loc
, I_Depth
)))),
6730 Expression
=> Make_Aggregate
(Loc
,
6731 Expressions
=> TSD_Aggr_List
)));
6734 -- Check_TSD (TSD => TSD'Unrestricted_Access);
6736 if Ada_Version
>= Ada_2005
6737 and then Is_Library_Level_Entity
(Typ
)
6738 and then RTE_Available
(RE_Check_TSD
)
6739 and then not Duplicated_Tag_Checks_Suppressed
(Typ
)
6742 Make_Procedure_Call_Statement
(Loc
,
6743 Name
=> New_Occurrence_Of
(RTE
(RE_Check_TSD
), Loc
),
6744 Parameter_Associations
=> New_List
(
6745 Make_Attribute_Reference
(Loc
,
6746 Prefix
=> New_Occurrence_Of
(TSD
, Loc
),
6747 Attribute_Name
=> Name_Unrestricted_Access
))));
6751 -- Register_TSD (TSD'Unrestricted_Access);
6754 Make_Procedure_Call_Statement
(Loc
,
6755 Name
=> New_Occurrence_Of
(RTE
(RE_Register_TSD
), Loc
),
6756 Parameter_Associations
=> New_List
(
6757 Make_Attribute_Reference
(Loc
,
6758 Prefix
=> New_Occurrence_Of
(TSD
, Loc
),
6759 Attribute_Name
=> Name_Unrestricted_Access
))));
6761 -- Populate the two auxiliary tables used for dispatching asynchronous,
6762 -- conditional and timed selects for synchronized types that implement
6763 -- a limited interface. Skip this step in Ravenscar profile or when
6764 -- general dispatching is forbidden.
6766 if Ada_Version
>= Ada_2005
6767 and then Is_Concurrent_Record_Type
(Typ
)
6768 and then Has_Interfaces
(Typ
)
6769 and then not Restriction_Active
(No_Dispatching_Calls
)
6770 and then not Restriction_Active
(No_Select_Statements
)
6772 Append_List_To
(Result
,
6773 Make_Select_Specific_Data_Table
(Typ
));
6779 -------------------------------------
6780 -- Make_Select_Specific_Data_Table --
6781 -------------------------------------
6783 function Make_Select_Specific_Data_Table
6784 (Typ
: Entity_Id
) return List_Id
6786 Assignments
: constant List_Id
:= New_List
;
6787 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
6789 Conc_Typ
: Entity_Id
;
6792 Prim_Als
: Entity_Id
;
6793 Prim_Elmt
: Elmt_Id
;
6797 type Examined_Array
is array (Int
range <>) of Boolean;
6799 function Find_Entry_Index
(E
: Entity_Id
) return Uint
;
6800 -- Given an entry, find its index in the visible declarations of the
6801 -- corresponding concurrent type of Typ.
6803 ----------------------
6804 -- Find_Entry_Index --
6805 ----------------------
6807 function Find_Entry_Index
(E
: Entity_Id
) return Uint
is
6808 Index
: Uint
:= Uint_1
;
6809 Subp_Decl
: Entity_Id
;
6813 and then not Is_Empty_List
(Decls
)
6815 Subp_Decl
:= First
(Decls
);
6816 while Present
(Subp_Decl
) loop
6817 if Nkind
(Subp_Decl
) = N_Entry_Declaration
then
6818 if Defining_Identifier
(Subp_Decl
) = E
then
6830 end Find_Entry_Index
;
6836 -- Start of processing for Make_Select_Specific_Data_Table
6839 pragma Assert
(not Restriction_Active
(No_Dispatching_Calls
));
6841 if Present
(Corresponding_Concurrent_Type
(Typ
)) then
6842 Conc_Typ
:= Corresponding_Concurrent_Type
(Typ
);
6844 if Present
(Full_View
(Conc_Typ
)) then
6845 Conc_Typ
:= Full_View
(Conc_Typ
);
6848 if Ekind
(Conc_Typ
) = E_Protected_Type
then
6849 Decls
:= Visible_Declarations
(Protected_Definition
(
6850 Parent
(Conc_Typ
)));
6852 pragma Assert
(Ekind
(Conc_Typ
) = E_Task_Type
);
6853 Decls
:= Visible_Declarations
(Task_Definition
(
6854 Parent
(Conc_Typ
)));
6858 -- Count the non-predefined primitive operations
6860 Prim_Elmt
:= First_Elmt
(Primitive_Operations
(Typ
));
6861 while Present
(Prim_Elmt
) loop
6862 Prim
:= Node
(Prim_Elmt
);
6864 if not (Is_Predefined_Dispatching_Operation
(Prim
)
6865 or else Is_Predefined_Dispatching_Alias
(Prim
))
6867 Nb_Prim
:= Nb_Prim
+ 1;
6870 Next_Elmt
(Prim_Elmt
);
6874 Examined
: Examined_Array
(1 .. Nb_Prim
) := (others => False);
6877 Prim_Elmt
:= First_Elmt
(Primitive_Operations
(Typ
));
6878 while Present
(Prim_Elmt
) loop
6879 Prim
:= Node
(Prim_Elmt
);
6881 -- Look for primitive overriding an abstract interface subprogram
6883 if Present
(Interface_Alias
(Prim
))
6886 (Find_Dispatching_Type
(Interface_Alias
(Prim
)), Typ
,
6887 Use_Full_View
=> True)
6888 and then not Examined
(UI_To_Int
(DT_Position
(Alias
(Prim
))))
6890 Prim_Pos
:= DT_Position
(Alias
(Prim
));
6891 pragma Assert
(UI_To_Int
(Prim_Pos
) <= Nb_Prim
);
6892 Examined
(UI_To_Int
(Prim_Pos
)) := True;
6894 -- Set the primitive operation kind regardless of subprogram
6896 -- Ada.Tags.Set_Prim_Op_Kind (DT_Ptr, <position>, <kind>);
6898 if Tagged_Type_Expansion
then
6901 (Node
(First_Elmt
(Access_Disp_Table
(Typ
))), Loc
);
6905 Make_Attribute_Reference
(Loc
,
6906 Prefix
=> New_Occurrence_Of
(Typ
, Loc
),
6907 Attribute_Name
=> Name_Tag
);
6910 Append_To
(Assignments
,
6911 Make_Procedure_Call_Statement
(Loc
,
6912 Name
=> New_Occurrence_Of
(RTE
(RE_Set_Prim_Op_Kind
), Loc
),
6913 Parameter_Associations
=> New_List
(
6915 Make_Integer_Literal
(Loc
, Prim_Pos
),
6916 Prim_Op_Kind
(Alias
(Prim
), Typ
))));
6918 -- Retrieve the root of the alias chain
6920 Prim_Als
:= Ultimate_Alias
(Prim
);
6922 -- In the case of an entry wrapper, set the entry index
6924 if Ekind
(Prim
) = E_Procedure
6925 and then Is_Primitive_Wrapper
(Prim_Als
)
6926 and then Ekind
(Wrapped_Entity
(Prim_Als
)) = E_Entry
6929 -- Ada.Tags.Set_Entry_Index
6930 -- (DT_Ptr, <position>, <index>);
6932 if Tagged_Type_Expansion
then
6935 (Node
(First_Elmt
(Access_Disp_Table
(Typ
))), Loc
);
6938 Make_Attribute_Reference
(Loc
,
6939 Prefix
=> New_Occurrence_Of
(Typ
, Loc
),
6940 Attribute_Name
=> Name_Tag
);
6943 Append_To
(Assignments
,
6944 Make_Procedure_Call_Statement
(Loc
,
6946 New_Occurrence_Of
(RTE
(RE_Set_Entry_Index
), Loc
),
6947 Parameter_Associations
=> New_List
(
6949 Make_Integer_Literal
(Loc
, Prim_Pos
),
6950 Make_Integer_Literal
(Loc
,
6951 Find_Entry_Index
(Wrapped_Entity
(Prim_Als
))))));
6955 Next_Elmt
(Prim_Elmt
);
6960 end Make_Select_Specific_Data_Table
;
6966 function Make_Tags
(Typ
: Entity_Id
) return List_Id
is
6967 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
6968 Result
: constant List_Id
:= New_List
;
6971 (Tag_Typ
: Entity_Id
;
6973 Is_Secondary_DT
: Boolean);
6974 -- Import the dispatch table DT of tagged type Tag_Typ. Required to
6975 -- generate forward references and statically allocate the table. For
6976 -- primary dispatch tables that require no dispatch table generate:
6978 -- DT : static aliased constant Non_Dispatch_Table_Wrapper;
6979 -- pragma Import (Ada, DT);
6981 -- Otherwise generate:
6983 -- DT : static aliased constant Dispatch_Table_Wrapper (Nb_Prim);
6984 -- pragma Import (Ada, DT);
6991 (Tag_Typ
: Entity_Id
;
6993 Is_Secondary_DT
: Boolean)
6995 DT_Constr_List
: List_Id
;
6999 Set_Is_Imported
(DT
);
7000 Set_Ekind
(DT
, E_Constant
);
7001 Set_Related_Type
(DT
, Typ
);
7003 -- The scope must be set now to call Get_External_Name
7005 Set_Scope
(DT
, Current_Scope
);
7007 Get_External_Name
(DT
);
7008 Set_Interface_Name
(DT
,
7009 Make_String_Literal
(Loc
, Strval
=> String_From_Name_Buffer
));
7011 -- Ensure proper Sprint output of this implicit importation
7013 Set_Is_Internal
(DT
);
7015 -- Save this entity to allow Make_DT to generate its exportation
7017 Append_Elmt
(DT
, Dispatch_Table_Wrappers
(Typ
));
7019 -- No dispatch table required
7021 if not Is_Secondary_DT
and then not Has_DT
(Tag_Typ
) then
7023 Make_Object_Declaration
(Loc
,
7024 Defining_Identifier
=> DT
,
7025 Aliased_Present
=> True,
7026 Constant_Present
=> True,
7027 Object_Definition
=>
7029 (RTE
(RE_No_Dispatch_Table_Wrapper
), Loc
)));
7032 -- Calculate the number of primitives of the dispatch table and
7033 -- the size of the Type_Specific_Data record.
7036 UI_To_Int
(DT_Entry_Count
(First_Tag_Component
(Tag_Typ
)));
7038 -- If the tagged type has no primitives we add a dummy slot whose
7039 -- address will be the tag of this type.
7043 New_List
(Make_Integer_Literal
(Loc
, 1));
7046 New_List
(Make_Integer_Literal
(Loc
, Nb_Prim
));
7050 Make_Object_Declaration
(Loc
,
7051 Defining_Identifier
=> DT
,
7052 Aliased_Present
=> True,
7053 Constant_Present
=> True,
7054 Object_Definition
=>
7055 Make_Subtype_Indication
(Loc
,
7057 New_Occurrence_Of
(RTE
(RE_Dispatch_Table_Wrapper
), Loc
),
7058 Constraint
=> Make_Index_Or_Discriminant_Constraint
(Loc
,
7059 Constraints
=> DT_Constr_List
))));
7065 Tname
: constant Name_Id
:= Chars
(Typ
);
7066 AI_Tag_Comp
: Elmt_Id
;
7067 DT
: Node_Id
:= Empty
;
7069 Predef_Prims_Ptr
: Node_Id
;
7070 Iface_DT
: Node_Id
:= Empty
;
7071 Iface_DT_Ptr
: Node_Id
;
7075 Typ_Comps
: Elist_Id
;
7077 -- Start of processing for Make_Tags
7080 pragma Assert
(No
(Access_Disp_Table
(Typ
)));
7081 Set_Access_Disp_Table
(Typ
, New_Elmt_List
);
7083 -- 1) Generate the primary tag entities
7085 -- Primary dispatch table containing user-defined primitives
7087 DT_Ptr
:= Make_Defining_Identifier
(Loc
, New_External_Name
(Tname
, 'P'));
7088 Set_Etype
(DT_Ptr
, RTE
(RE_Tag
));
7089 Append_Elmt
(DT_Ptr
, Access_Disp_Table
(Typ
));
7091 -- Minimum decoration
7093 Set_Ekind
(DT_Ptr
, E_Variable
);
7094 Set_Related_Type
(DT_Ptr
, Typ
);
7096 -- Notify back end that the types are associated with a dispatch table
7098 Set_Is_Dispatch_Table_Entity
(RTE
(RE_Prim_Ptr
));
7099 Set_Is_Dispatch_Table_Entity
(RTE
(RE_Predef_Prims_Table_Ptr
));
7101 -- For CPP types there is no need to build the dispatch tables since
7102 -- they are imported from the C++ side. If the CPP type has an IP then
7103 -- we declare now the variable that will store the copy of the C++ tag.
7104 -- If the CPP type is an interface, we need the variable as well because
7105 -- it becomes the pointer to the corresponding secondary table.
7107 if Is_CPP_Class
(Typ
) then
7108 if Has_CPP_Constructors
(Typ
) or else Is_Interface
(Typ
) then
7110 Make_Object_Declaration
(Loc
,
7111 Defining_Identifier
=> DT_Ptr
,
7112 Object_Definition
=> New_Occurrence_Of
(RTE
(RE_Tag
), Loc
),
7114 Unchecked_Convert_To
(RTE
(RE_Tag
),
7115 New_Occurrence_Of
(RTE
(RE_Null_Address
), Loc
))));
7117 Set_Is_Statically_Allocated
(DT_Ptr
,
7118 Is_Library_Level_Tagged_Type
(Typ
));
7124 -- Primary dispatch table containing predefined primitives
7127 Make_Defining_Identifier
(Loc
,
7128 Chars
=> New_External_Name
(Tname
, 'Y'));
7129 Set_Etype
(Predef_Prims_Ptr
, RTE
(RE_Address
));
7130 Append_Elmt
(Predef_Prims_Ptr
, Access_Disp_Table
(Typ
));
7132 -- Import the forward declaration of the Dispatch Table wrapper
7133 -- record (Make_DT will take care of exporting it).
7135 if Building_Static_DT
(Typ
) then
7136 Set_Dispatch_Table_Wrappers
(Typ
, New_Elmt_List
);
7139 Make_Defining_Identifier
(Loc
,
7140 Chars
=> New_External_Name
(Tname
, 'T'));
7142 Import_DT
(Typ
, DT
, Is_Secondary_DT
=> False);
7144 if Has_DT
(Typ
) then
7146 Make_Object_Declaration
(Loc
,
7147 Defining_Identifier
=> DT_Ptr
,
7148 Constant_Present
=> True,
7149 Object_Definition
=>
7150 New_Occurrence_Of
(RTE
(RE_Tag
), Loc
),
7152 Unchecked_Convert_To
(RTE
(RE_Tag
),
7153 Make_Attribute_Reference
(Loc
,
7155 Make_Selected_Component
(Loc
,
7156 Prefix
=> New_Occurrence_Of
(DT
, Loc
),
7159 (RTE_Record_Component
(RE_Prims_Ptr
), Loc
)),
7160 Attribute_Name
=> Name_Address
))));
7162 -- Generate the SCIL node for the previous object declaration
7163 -- because it has a tag initialization.
7165 if Generate_SCIL
then
7167 Make_SCIL_Dispatch_Table_Tag_Init
(Sloc
(Last
(Result
)));
7168 Set_SCIL_Entity
(New_Node
, Typ
);
7169 Set_SCIL_Node
(Last
(Result
), New_Node
);
7173 Make_Object_Declaration
(Loc
,
7174 Defining_Identifier
=> Predef_Prims_Ptr
,
7175 Constant_Present
=> True,
7176 Object_Definition
=>
7177 New_Occurrence_Of
(RTE
(RE_Address
), Loc
),
7179 Make_Attribute_Reference
(Loc
,
7181 Make_Selected_Component
(Loc
,
7182 Prefix
=> New_Occurrence_Of
(DT
, Loc
),
7185 (RTE_Record_Component
(RE_Predef_Prims
), Loc
)),
7186 Attribute_Name
=> Name_Address
)));
7188 -- No dispatch table required
7192 Make_Object_Declaration
(Loc
,
7193 Defining_Identifier
=> DT_Ptr
,
7194 Constant_Present
=> True,
7195 Object_Definition
=>
7196 New_Occurrence_Of
(RTE
(RE_Tag
), Loc
),
7198 Unchecked_Convert_To
(RTE
(RE_Tag
),
7199 Make_Attribute_Reference
(Loc
,
7201 Make_Selected_Component
(Loc
,
7202 Prefix
=> New_Occurrence_Of
(DT
, Loc
),
7205 (RTE_Record_Component
(RE_NDT_Prims_Ptr
),
7207 Attribute_Name
=> Name_Address
))));
7210 Set_Is_True_Constant
(DT_Ptr
);
7211 Set_Is_Statically_Allocated
(DT_Ptr
);
7215 -- 2) Generate the secondary tag entities
7217 -- Collect the components associated with secondary dispatch tables
7219 if Has_Interfaces
(Typ
) then
7220 Collect_Interface_Components
(Typ
, Typ_Comps
);
7222 -- For each interface type we build a unique external name associated
7223 -- with its secondary dispatch table. This name is used to declare an
7224 -- object that references this secondary dispatch table, whose value
7225 -- will be used for the elaboration of Typ objects, and also for the
7226 -- elaboration of objects of types derived from Typ that do not
7227 -- override the primitives of this interface type.
7231 -- Note: The value of Suffix_Index must be in sync with the values of
7232 -- Suffix_Index in secondary dispatch tables generated by Make_DT.
7234 if Is_CPP_Class
(Typ
) then
7235 AI_Tag_Comp
:= First_Elmt
(Typ_Comps
);
7236 while Present
(AI_Tag_Comp
) loop
7237 Get_Secondary_DT_External_Name
7238 (Typ
, Related_Type
(Node
(AI_Tag_Comp
)), Suffix_Index
);
7239 Typ_Name
:= Name_Find
;
7241 -- Declare variables to store copy of the C++ secondary tags
7244 Make_Defining_Identifier
(Loc
,
7245 Chars
=> New_External_Name
(Typ_Name
, 'P'));
7246 Set_Etype
(Iface_DT_Ptr
, RTE
(RE_Interface_Tag
));
7247 Set_Ekind
(Iface_DT_Ptr
, E_Variable
);
7248 Set_Is_Tag
(Iface_DT_Ptr
);
7250 Set_Has_Thunks
(Iface_DT_Ptr
);
7252 (Iface_DT_Ptr
, Related_Type
(Node
(AI_Tag_Comp
)));
7253 Append_Elmt
(Iface_DT_Ptr
, Access_Disp_Table
(Typ
));
7256 Make_Object_Declaration
(Loc
,
7257 Defining_Identifier
=> Iface_DT_Ptr
,
7258 Object_Definition
=> New_Occurrence_Of
7259 (RTE
(RE_Interface_Tag
), Loc
),
7261 Unchecked_Convert_To
(RTE
(RE_Interface_Tag
),
7262 New_Occurrence_Of
(RTE
(RE_Null_Address
), Loc
))));
7264 Set_Is_Statically_Allocated
(Iface_DT_Ptr
,
7265 Is_Library_Level_Tagged_Type
(Typ
));
7267 Next_Elmt
(AI_Tag_Comp
);
7270 -- This is not a CPP_Class type
7273 AI_Tag_Comp
:= First_Elmt
(Typ_Comps
);
7274 while Present
(AI_Tag_Comp
) loop
7275 Get_Secondary_DT_External_Name
7276 (Typ
, Related_Type
(Node
(AI_Tag_Comp
)), Suffix_Index
);
7277 Typ_Name
:= Name_Find
;
7279 if Building_Static_DT
(Typ
) then
7281 Make_Defining_Identifier
(Loc
,
7282 Chars
=> New_External_Name
7283 (Typ_Name
, 'T', Suffix_Index
=> -1));
7285 (Tag_Typ
=> Related_Type
(Node
(AI_Tag_Comp
)),
7287 Is_Secondary_DT
=> True);
7290 -- Secondary dispatch table referencing thunks to user-defined
7291 -- primitives covered by this interface.
7294 Make_Defining_Identifier
(Loc
,
7295 Chars
=> New_External_Name
(Typ_Name
, 'P'));
7296 Set_Etype
(Iface_DT_Ptr
, RTE
(RE_Interface_Tag
));
7297 Set_Ekind
(Iface_DT_Ptr
, E_Constant
);
7298 Set_Is_Tag
(Iface_DT_Ptr
);
7299 Set_Has_Thunks
(Iface_DT_Ptr
);
7300 Set_Is_Statically_Allocated
(Iface_DT_Ptr
,
7301 Is_Library_Level_Tagged_Type
(Typ
));
7302 Set_Is_True_Constant
(Iface_DT_Ptr
);
7304 (Iface_DT_Ptr
, Related_Type
(Node
(AI_Tag_Comp
)));
7305 Append_Elmt
(Iface_DT_Ptr
, Access_Disp_Table
(Typ
));
7307 if Building_Static_DT
(Typ
) then
7309 Make_Object_Declaration
(Loc
,
7310 Defining_Identifier
=> Iface_DT_Ptr
,
7311 Constant_Present
=> True,
7312 Object_Definition
=> New_Occurrence_Of
7313 (RTE
(RE_Interface_Tag
), Loc
),
7315 Unchecked_Convert_To
(RTE
(RE_Interface_Tag
),
7316 Make_Attribute_Reference
(Loc
,
7318 Make_Selected_Component
(Loc
,
7320 New_Occurrence_Of
(Iface_DT
, Loc
),
7323 (RTE_Record_Component
(RE_Prims_Ptr
),
7325 Attribute_Name
=> Name_Address
))));
7328 -- Secondary dispatch table referencing thunks to predefined
7332 Make_Defining_Identifier
(Loc
,
7333 Chars
=> New_External_Name
(Typ_Name
, 'Y'));
7334 Set_Etype
(Iface_DT_Ptr
, RTE
(RE_Address
));
7335 Set_Ekind
(Iface_DT_Ptr
, E_Constant
);
7336 Set_Is_Tag
(Iface_DT_Ptr
);
7337 Set_Has_Thunks
(Iface_DT_Ptr
);
7338 Set_Is_Statically_Allocated
(Iface_DT_Ptr
,
7339 Is_Library_Level_Tagged_Type
(Typ
));
7340 Set_Is_True_Constant
(Iface_DT_Ptr
);
7342 (Iface_DT_Ptr
, Related_Type
(Node
(AI_Tag_Comp
)));
7343 Append_Elmt
(Iface_DT_Ptr
, Access_Disp_Table
(Typ
));
7345 -- Secondary dispatch table referencing user-defined primitives
7346 -- covered by this interface.
7349 Make_Defining_Identifier
(Loc
,
7350 Chars
=> New_External_Name
(Typ_Name
, 'D'));
7351 Set_Etype
(Iface_DT_Ptr
, RTE
(RE_Interface_Tag
));
7352 Set_Ekind
(Iface_DT_Ptr
, E_Constant
);
7353 Set_Is_Tag
(Iface_DT_Ptr
);
7354 Set_Is_Statically_Allocated
(Iface_DT_Ptr
,
7355 Is_Library_Level_Tagged_Type
(Typ
));
7356 Set_Is_True_Constant
(Iface_DT_Ptr
);
7358 (Iface_DT_Ptr
, Related_Type
(Node
(AI_Tag_Comp
)));
7359 Append_Elmt
(Iface_DT_Ptr
, Access_Disp_Table
(Typ
));
7361 -- Secondary dispatch table referencing predefined primitives
7364 Make_Defining_Identifier
(Loc
,
7365 Chars
=> New_External_Name
(Typ_Name
, 'Z'));
7366 Set_Etype
(Iface_DT_Ptr
, RTE
(RE_Address
));
7367 Set_Ekind
(Iface_DT_Ptr
, E_Constant
);
7368 Set_Is_Tag
(Iface_DT_Ptr
);
7369 Set_Is_Statically_Allocated
(Iface_DT_Ptr
,
7370 Is_Library_Level_Tagged_Type
(Typ
));
7371 Set_Is_True_Constant
(Iface_DT_Ptr
);
7373 (Iface_DT_Ptr
, Related_Type
(Node
(AI_Tag_Comp
)));
7374 Append_Elmt
(Iface_DT_Ptr
, Access_Disp_Table
(Typ
));
7376 Next_Elmt
(AI_Tag_Comp
);
7381 -- 3) At the end of Access_Disp_Table, if the type has user-defined
7382 -- primitives, we add the entity of an access type declaration that
7383 -- is used by Build_Get_Prim_Op_Address to expand dispatching calls
7384 -- through the primary dispatch table.
7386 if UI_To_Int
(DT_Entry_Count
(First_Tag_Component
(Typ
))) = 0 then
7387 Analyze_List
(Result
);
7390 -- type Typ_DT is array (1 .. Nb_Prims) of Prim_Ptr;
7391 -- type Typ_DT_Acc is access Typ_DT;
7395 Name_DT_Prims
: constant Name_Id
:=
7396 New_External_Name
(Tname
, 'G');
7397 Name_DT_Prims_Acc
: constant Name_Id
:=
7398 New_External_Name
(Tname
, 'H');
7399 DT_Prims
: constant Entity_Id
:=
7400 Make_Defining_Identifier
(Loc
,
7402 DT_Prims_Acc
: constant Entity_Id
:=
7403 Make_Defining_Identifier
(Loc
,
7407 Make_Full_Type_Declaration
(Loc
,
7408 Defining_Identifier
=> DT_Prims
,
7410 Make_Constrained_Array_Definition
(Loc
,
7411 Discrete_Subtype_Definitions
=> New_List
(
7413 Low_Bound
=> Make_Integer_Literal
(Loc
, 1),
7414 High_Bound
=> Make_Integer_Literal
(Loc
,
7416 (First_Tag_Component
(Typ
))))),
7417 Component_Definition
=>
7418 Make_Component_Definition
(Loc
,
7419 Subtype_Indication
=>
7420 New_Occurrence_Of
(RTE
(RE_Prim_Ptr
), Loc
)))));
7423 Make_Full_Type_Declaration
(Loc
,
7424 Defining_Identifier
=> DT_Prims_Acc
,
7426 Make_Access_To_Object_Definition
(Loc
,
7427 Subtype_Indication
=>
7428 New_Occurrence_Of
(DT_Prims
, Loc
))));
7430 Append_Elmt
(DT_Prims_Acc
, Access_Disp_Table
(Typ
));
7432 -- Analyze the resulting list and suppress the generation of the
7433 -- Init_Proc associated with the above array declaration because
7434 -- this type is never used in object declarations. It is only used
7435 -- to simplify the expansion associated with dispatching calls.
7437 Analyze_List
(Result
);
7438 Set_Suppress_Initialization
(Base_Type
(DT_Prims
));
7440 -- Disable backend optimizations based on assumptions about the
7441 -- aliasing status of objects designated by the access to the
7442 -- dispatch table. Required to handle dispatch tables imported
7445 Set_No_Strict_Aliasing
(Base_Type
(DT_Prims_Acc
));
7447 -- Add the freezing nodes of these declarations; required to avoid
7448 -- generating these freezing nodes in wrong scopes (for example in
7449 -- the IC routine of a derivation of Typ).
7451 -- What is an "IC routine"? Is "init_proc" meant here???
7453 Append_List_To
(Result
, Freeze_Entity
(DT_Prims
, Typ
));
7454 Append_List_To
(Result
, Freeze_Entity
(DT_Prims_Acc
, Typ
));
7456 -- Mark entity of dispatch table. Required by the back end to
7457 -- handle them properly.
7459 Set_Is_Dispatch_Table_Entity
(DT_Prims
);
7463 -- Mark entities of dispatch table. Required by the back end to handle
7466 if Present
(DT
) then
7467 Set_Is_Dispatch_Table_Entity
(DT
);
7468 Set_Is_Dispatch_Table_Entity
(Etype
(DT
));
7471 if Present
(Iface_DT
) then
7472 Set_Is_Dispatch_Table_Entity
(Iface_DT
);
7473 Set_Is_Dispatch_Table_Entity
(Etype
(Iface_DT
));
7476 if Is_CPP_Class
(Root_Type
(Typ
)) then
7477 Set_Ekind
(DT_Ptr
, E_Variable
);
7479 Set_Ekind
(DT_Ptr
, E_Constant
);
7482 Set_Is_Tag
(DT_Ptr
);
7483 Set_Related_Type
(DT_Ptr
, Typ
);
7492 function New_Value
(From
: Node_Id
) return Node_Id
is
7493 Res
: constant Node_Id
:= Duplicate_Subexpr
(From
);
7495 if Is_Access_Type
(Etype
(From
)) then
7496 return Make_Explicit_Dereference
(Sloc
(From
), Prefix
=> Res
);
7502 -----------------------------------
7503 -- Original_View_In_Visible_Part --
7504 -----------------------------------
7506 function Original_View_In_Visible_Part
(Typ
: Entity_Id
) return Boolean is
7507 Scop
: constant Entity_Id
:= Scope
(Typ
);
7510 -- The scope must be a package
7512 if not Is_Package_Or_Generic_Package
(Scop
) then
7516 -- A type with a private declaration has a private view declared in
7517 -- the visible part.
7519 if Has_Private_Declaration
(Typ
) then
7523 return List_Containing
(Parent
(Typ
)) =
7524 Visible_Declarations
(Package_Specification
(Scop
));
7525 end Original_View_In_Visible_Part
;
7531 function Prim_Op_Kind
7533 Typ
: Entity_Id
) return Node_Id
7535 Full_Typ
: Entity_Id
:= Typ
;
7536 Loc
: constant Source_Ptr
:= Sloc
(Prim
);
7537 Prim_Op
: Entity_Id
;
7540 -- Retrieve the original primitive operation
7542 Prim_Op
:= Ultimate_Alias
(Prim
);
7544 if Ekind
(Typ
) = E_Record_Type
7545 and then Present
(Corresponding_Concurrent_Type
(Typ
))
7547 Full_Typ
:= Corresponding_Concurrent_Type
(Typ
);
7550 -- When a private tagged type is completed by a concurrent type,
7551 -- retrieve the full view.
7553 if Is_Private_Type
(Full_Typ
) then
7554 Full_Typ
:= Full_View
(Full_Typ
);
7557 if Ekind
(Prim_Op
) = E_Function
then
7559 -- Protected function
7561 if Ekind
(Full_Typ
) = E_Protected_Type
then
7562 return New_Occurrence_Of
(RTE
(RE_POK_Protected_Function
), Loc
);
7566 elsif Ekind
(Full_Typ
) = E_Task_Type
then
7567 return New_Occurrence_Of
(RTE
(RE_POK_Task_Function
), Loc
);
7572 return New_Occurrence_Of
(RTE
(RE_POK_Function
), Loc
);
7576 pragma Assert
(Ekind
(Prim_Op
) = E_Procedure
);
7578 if Ekind
(Full_Typ
) = E_Protected_Type
then
7582 if Is_Primitive_Wrapper
(Prim_Op
)
7583 and then Ekind
(Wrapped_Entity
(Prim_Op
)) = E_Entry
7585 return New_Occurrence_Of
(RTE
(RE_POK_Protected_Entry
), Loc
);
7587 -- Protected procedure
7591 New_Occurrence_Of
(RTE
(RE_POK_Protected_Procedure
), Loc
);
7594 elsif Ekind
(Full_Typ
) = E_Task_Type
then
7598 if Is_Primitive_Wrapper
(Prim_Op
)
7599 and then Ekind
(Wrapped_Entity
(Prim_Op
)) = E_Entry
7601 return New_Occurrence_Of
(RTE
(RE_POK_Task_Entry
), Loc
);
7603 -- Task "procedure". These are the internally Expander-generated
7604 -- procedures (task body for instance).
7607 return New_Occurrence_Of
(RTE
(RE_POK_Task_Procedure
), Loc
);
7610 -- Regular procedure
7613 return New_Occurrence_Of
(RTE
(RE_POK_Procedure
), Loc
);
7618 ------------------------
7619 -- Register_Primitive --
7620 ------------------------
7622 function Register_Primitive
7624 Prim
: Entity_Id
) return List_Id
7627 Iface_Prim
: Entity_Id
;
7628 Iface_Typ
: Entity_Id
;
7629 Iface_DT_Ptr
: Entity_Id
;
7630 Iface_DT_Elmt
: Elmt_Id
;
7631 L
: constant List_Id
:= New_List
;
7634 Tag_Typ
: Entity_Id
;
7635 Thunk_Id
: Entity_Id
;
7636 Thunk_Code
: Node_Id
;
7639 pragma Assert
(not Restriction_Active
(No_Dispatching_Calls
));
7640 pragma Assert
(VM_Target
= No_VM
);
7642 -- Do not register in the dispatch table eliminated primitives
7644 if not RTE_Available
(RE_Tag
)
7645 or else Is_Eliminated
(Ultimate_Alias
(Prim
))
7650 if not Present
(Interface_Alias
(Prim
)) then
7651 Tag_Typ
:= Scope
(DTC_Entity
(Prim
));
7652 Pos
:= DT_Position
(Prim
);
7653 Tag
:= First_Tag_Component
(Tag_Typ
);
7655 if Is_Predefined_Dispatching_Operation
(Prim
)
7656 or else Is_Predefined_Dispatching_Alias
(Prim
)
7659 Node
(Next_Elmt
(First_Elmt
(Access_Disp_Table
(Tag_Typ
))));
7662 Build_Set_Predefined_Prim_Op_Address
(Loc
,
7663 Tag_Node
=> New_Occurrence_Of
(DT_Ptr
, Loc
),
7666 Unchecked_Convert_To
(RTE
(RE_Prim_Ptr
),
7667 Make_Attribute_Reference
(Loc
,
7668 Prefix
=> New_Occurrence_Of
(Prim
, Loc
),
7669 Attribute_Name
=> Name_Unrestricted_Access
))));
7671 -- Register copy of the pointer to the 'size primitive in the TSD
7673 if Chars
(Prim
) = Name_uSize
7674 and then RTE_Record_Component_Available
(RE_Size_Func
)
7676 DT_Ptr
:= Node
(First_Elmt
(Access_Disp_Table
(Tag_Typ
)));
7678 Build_Set_Size_Function
(Loc
,
7679 Tag_Node
=> New_Occurrence_Of
(DT_Ptr
, Loc
),
7680 Size_Func
=> Prim
));
7684 pragma Assert
(Pos
/= Uint_0
and then Pos
<= DT_Entry_Count
(Tag
));
7686 -- Skip registration of primitives located in the C++ part of the
7687 -- dispatch table. Their slot is set by the IC routine.
7689 if not Is_CPP_Class
(Root_Type
(Tag_Typ
))
7690 or else Pos
> CPP_Num_Prims
(Tag_Typ
)
7692 DT_Ptr
:= Node
(First_Elmt
(Access_Disp_Table
(Tag_Typ
)));
7694 Build_Set_Prim_Op_Address
(Loc
,
7696 Tag_Node
=> New_Occurrence_Of
(DT_Ptr
, Loc
),
7699 Unchecked_Convert_To
(RTE
(RE_Prim_Ptr
),
7700 Make_Attribute_Reference
(Loc
,
7701 Prefix
=> New_Occurrence_Of
(Prim
, Loc
),
7702 Attribute_Name
=> Name_Unrestricted_Access
))));
7706 -- Ada 2005 (AI-251): Primitive associated with an interface type
7708 -- Generate the code of the thunk only if the interface type is not an
7709 -- immediate ancestor of Typ; otherwise the dispatch table associated
7710 -- with the interface is the primary dispatch table and we have nothing
7714 Tag_Typ
:= Find_Dispatching_Type
(Alias
(Prim
));
7715 Iface_Typ
:= Find_Dispatching_Type
(Interface_Alias
(Prim
));
7717 pragma Assert
(Is_Interface
(Iface_Typ
));
7719 -- No action needed for interfaces that are ancestors of Typ because
7720 -- their primitives are located in the primary dispatch table.
7722 if Is_Ancestor
(Iface_Typ
, Tag_Typ
, Use_Full_View
=> True) then
7725 -- No action needed for primitives located in the C++ part of the
7726 -- dispatch table. Their slot is set by the IC routine.
7728 elsif Is_CPP_Class
(Root_Type
(Tag_Typ
))
7729 and then DT_Position
(Alias
(Prim
)) <= CPP_Num_Prims
(Tag_Typ
)
7730 and then not Is_Predefined_Dispatching_Operation
(Prim
)
7731 and then not Is_Predefined_Dispatching_Alias
(Prim
)
7736 Expand_Interface_Thunk
(Prim
, Thunk_Id
, Thunk_Code
);
7738 if not Is_Ancestor
(Iface_Typ
, Tag_Typ
, Use_Full_View
=> True)
7739 and then Present
(Thunk_Code
)
7741 -- Generate the code necessary to fill the appropriate entry of
7742 -- the secondary dispatch table of Prim's controlling type with
7743 -- Thunk_Id's address.
7745 Iface_DT_Elmt
:= Find_Interface_ADT
(Tag_Typ
, Iface_Typ
);
7746 Iface_DT_Ptr
:= Node
(Iface_DT_Elmt
);
7747 pragma Assert
(Has_Thunks
(Iface_DT_Ptr
));
7749 Iface_Prim
:= Interface_Alias
(Prim
);
7750 Pos
:= DT_Position
(Iface_Prim
);
7751 Tag
:= First_Tag_Component
(Iface_Typ
);
7753 Prepend_To
(L
, Thunk_Code
);
7755 if Is_Predefined_Dispatching_Operation
(Prim
)
7756 or else Is_Predefined_Dispatching_Alias
(Prim
)
7759 Build_Set_Predefined_Prim_Op_Address
(Loc
,
7761 New_Occurrence_Of
(Node
(Next_Elmt
(Iface_DT_Elmt
)), Loc
),
7764 Unchecked_Convert_To
(RTE
(RE_Prim_Ptr
),
7765 Make_Attribute_Reference
(Loc
,
7766 Prefix
=> New_Occurrence_Of
(Thunk_Id
, Loc
),
7767 Attribute_Name
=> Name_Unrestricted_Access
))));
7769 Next_Elmt
(Iface_DT_Elmt
);
7770 Next_Elmt
(Iface_DT_Elmt
);
7771 Iface_DT_Ptr
:= Node
(Iface_DT_Elmt
);
7772 pragma Assert
(not Has_Thunks
(Iface_DT_Ptr
));
7775 Build_Set_Predefined_Prim_Op_Address
(Loc
,
7777 New_Occurrence_Of
(Node
(Next_Elmt
(Iface_DT_Elmt
)), Loc
),
7780 Unchecked_Convert_To
(RTE
(RE_Prim_Ptr
),
7781 Make_Attribute_Reference
(Loc
,
7783 New_Occurrence_Of
(Alias
(Prim
), Loc
),
7784 Attribute_Name
=> Name_Unrestricted_Access
))));
7787 pragma Assert
(Pos
/= Uint_0
7788 and then Pos
<= DT_Entry_Count
(Tag
));
7791 Build_Set_Prim_Op_Address
(Loc
,
7793 Tag_Node
=> New_Occurrence_Of
(Iface_DT_Ptr
, Loc
),
7796 Unchecked_Convert_To
(RTE
(RE_Prim_Ptr
),
7797 Make_Attribute_Reference
(Loc
,
7798 Prefix
=> New_Occurrence_Of
(Thunk_Id
, Loc
),
7799 Attribute_Name
=> Name_Unrestricted_Access
))));
7801 Next_Elmt
(Iface_DT_Elmt
);
7802 Next_Elmt
(Iface_DT_Elmt
);
7803 Iface_DT_Ptr
:= Node
(Iface_DT_Elmt
);
7804 pragma Assert
(not Has_Thunks
(Iface_DT_Ptr
));
7807 Build_Set_Prim_Op_Address
(Loc
,
7809 Tag_Node
=> New_Occurrence_Of
(Iface_DT_Ptr
, Loc
),
7812 Unchecked_Convert_To
(RTE
(RE_Prim_Ptr
),
7813 Make_Attribute_Reference
(Loc
,
7815 New_Occurrence_Of
(Alias
(Prim
), Loc
),
7816 Attribute_Name
=> Name_Unrestricted_Access
))));
7823 end Register_Primitive
;
7825 -------------------------
7826 -- Set_All_DT_Position --
7827 -------------------------
7829 procedure Set_All_DT_Position
(Typ
: Entity_Id
) is
7831 function In_Predef_Prims_DT
(Prim
: Entity_Id
) return Boolean;
7832 -- Returns True if Prim is located in the dispatch table of
7833 -- predefined primitives
7835 procedure Validate_Position
(Prim
: Entity_Id
);
7836 -- Check that position assigned to Prim is completely safe (it has not
7837 -- been assigned to a previously defined primitive operation of Typ).
7839 ------------------------
7840 -- In_Predef_Prims_DT --
7841 ------------------------
7843 function In_Predef_Prims_DT
(Prim
: Entity_Id
) return Boolean is
7847 -- Predefined primitives
7849 if Is_Predefined_Dispatching_Operation
(Prim
) then
7852 -- Renamings of predefined primitives
7854 elsif Present
(Alias
(Prim
))
7855 and then Is_Predefined_Dispatching_Operation
(Ultimate_Alias
(Prim
))
7857 if Chars
(Ultimate_Alias
(Prim
)) /= Name_Op_Eq
then
7860 -- User-defined renamings of predefined equality have their own
7861 -- slot in the primary dispatch table
7865 while Present
(Alias
(E
)) loop
7866 if Comes_From_Source
(E
) then
7873 return not Comes_From_Source
(E
);
7876 -- User-defined primitives
7881 end In_Predef_Prims_DT
;
7883 -----------------------
7884 -- Validate_Position --
7885 -----------------------
7887 procedure Validate_Position
(Prim
: Entity_Id
) is
7892 -- Aliased primitives are safe
7894 if Present
(Alias
(Prim
)) then
7898 Op_Elmt
:= First_Elmt
(Primitive_Operations
(Typ
));
7899 while Present
(Op_Elmt
) loop
7900 Op
:= Node
(Op_Elmt
);
7902 -- No need to check against itself
7907 -- Primitive operations covering abstract interfaces are
7910 elsif Present
(Interface_Alias
(Op
)) then
7913 -- Predefined dispatching operations are completely safe. They
7914 -- are allocated at fixed positions in a separate table.
7916 elsif Is_Predefined_Dispatching_Operation
(Op
)
7917 or else Is_Predefined_Dispatching_Alias
(Op
)
7921 -- Aliased subprograms are safe
7923 elsif Present
(Alias
(Op
)) then
7926 elsif DT_Position
(Op
) = DT_Position
(Prim
)
7927 and then not Is_Predefined_Dispatching_Operation
(Op
)
7928 and then not Is_Predefined_Dispatching_Operation
(Prim
)
7929 and then not Is_Predefined_Dispatching_Alias
(Op
)
7930 and then not Is_Predefined_Dispatching_Alias
(Prim
)
7932 -- Handle aliased subprograms
7941 if Present
(Overridden_Operation
(Op_1
)) then
7942 Op_1
:= Overridden_Operation
(Op_1
);
7943 elsif Present
(Alias
(Op_1
)) then
7944 Op_1
:= Alias
(Op_1
);
7952 if Present
(Overridden_Operation
(Op_2
)) then
7953 Op_2
:= Overridden_Operation
(Op_2
);
7954 elsif Present
(Alias
(Op_2
)) then
7955 Op_2
:= Alias
(Op_2
);
7961 if Op_1
/= Op_2
then
7962 raise Program_Error
;
7967 Next_Elmt
(Op_Elmt
);
7969 end Validate_Position
;
7973 Parent_Typ
: constant Entity_Id
:= Etype
(Typ
);
7974 First_Prim
: constant Elmt_Id
:= First_Elmt
(Primitive_Operations
(Typ
));
7975 The_Tag
: constant Entity_Id
:= First_Tag_Component
(Typ
);
7977 Adjusted
: Boolean := False;
7978 Finalized
: Boolean := False;
7984 Prim_Elmt
: Elmt_Id
;
7986 -- Start of processing for Set_All_DT_Position
7989 pragma Assert
(Present
(First_Tag_Component
(Typ
)));
7991 -- Set the DT_Position for each primitive operation. Perform some sanity
7992 -- checks to avoid building inconsistent dispatch tables.
7994 -- First stage: Set DTC entity of all the primitive operations. This is
7995 -- required to properly read the DT_Position attribute in latter stages.
7997 Prim_Elmt
:= First_Prim
;
7999 while Present
(Prim_Elmt
) loop
8000 Prim
:= Node
(Prim_Elmt
);
8002 -- Predefined primitives have a separate dispatch table
8004 if not In_Predef_Prims_DT
(Prim
) then
8005 Count_Prim
:= Count_Prim
+ 1;
8008 Set_DTC_Entity_Value
(Typ
, Prim
);
8010 -- Clear any previous value of the DT_Position attribute. In this
8011 -- way we ensure that the final position of all the primitives is
8012 -- established by the following stages of this algorithm.
8014 Set_DT_Position
(Prim
, No_Uint
);
8016 Next_Elmt
(Prim_Elmt
);
8020 Fixed_Prim
: array (Int
range 0 .. Count_Prim
) of Boolean :=
8025 procedure Handle_Inherited_Private_Subprograms
(Typ
: Entity_Id
);
8026 -- Called if Typ is declared in a nested package or a public child
8027 -- package to handle inherited primitives that were inherited by Typ
8028 -- in the visible part, but whose declaration was deferred because
8029 -- the parent operation was private and not visible at that point.
8031 procedure Set_Fixed_Prim
(Pos
: Nat
);
8032 -- Sets to true an element of the Fixed_Prim table to indicate
8033 -- that this entry of the dispatch table of Typ is occupied.
8035 ------------------------------------------
8036 -- Handle_Inherited_Private_Subprograms --
8037 ------------------------------------------
8039 procedure Handle_Inherited_Private_Subprograms
(Typ
: Entity_Id
) is
8042 Op_Elmt_2
: Elmt_Id
;
8043 Prim_Op
: Entity_Id
;
8044 Parent_Subp
: Entity_Id
;
8047 Op_List
:= Primitive_Operations
(Typ
);
8049 Op_Elmt
:= First_Elmt
(Op_List
);
8050 while Present
(Op_Elmt
) loop
8051 Prim_Op
:= Node
(Op_Elmt
);
8053 -- Search primitives that are implicit operations with an
8054 -- internal name whose parent operation has a normal name.
8056 if Present
(Alias
(Prim_Op
))
8057 and then Find_Dispatching_Type
(Alias
(Prim_Op
)) /= Typ
8058 and then not Comes_From_Source
(Prim_Op
)
8059 and then Is_Internal_Name
(Chars
(Prim_Op
))
8060 and then not Is_Internal_Name
(Chars
(Alias
(Prim_Op
)))
8062 Parent_Subp
:= Alias
(Prim_Op
);
8064 -- Check if the type has an explicit overriding for this
8067 Op_Elmt_2
:= Next_Elmt
(Op_Elmt
);
8068 while Present
(Op_Elmt_2
) loop
8069 if Chars
(Node
(Op_Elmt_2
)) = Chars
(Parent_Subp
)
8070 and then Type_Conformant
(Prim_Op
, Node
(Op_Elmt_2
))
8072 Set_DT_Position
(Prim_Op
, DT_Position
(Parent_Subp
));
8073 Set_DT_Position
(Node
(Op_Elmt_2
),
8074 DT_Position
(Parent_Subp
));
8075 Set_Fixed_Prim
(UI_To_Int
(DT_Position
(Prim_Op
)));
8077 goto Next_Primitive
;
8080 Next_Elmt
(Op_Elmt_2
);
8085 Next_Elmt
(Op_Elmt
);
8087 end Handle_Inherited_Private_Subprograms
;
8089 --------------------
8090 -- Set_Fixed_Prim --
8091 --------------------
8093 procedure Set_Fixed_Prim
(Pos
: Nat
) is
8095 pragma Assert
(Pos
<= Count_Prim
);
8096 Fixed_Prim
(Pos
) := True;
8098 when Constraint_Error
=>
8099 raise Program_Error
;
8103 -- In case of nested packages and public child package it may be
8104 -- necessary a special management on inherited subprograms so that
8105 -- the dispatch table is properly filled.
8107 if Ekind
(Scope
(Scope
(Typ
))) = E_Package
8108 and then Scope
(Scope
(Typ
)) /= Standard_Standard
8109 and then ((Is_Derived_Type
(Typ
) and then not Is_Private_Type
(Typ
))
8111 (Nkind
(Parent
(Typ
)) = N_Private_Extension_Declaration
8112 and then Is_Generic_Type
(Typ
)))
8113 and then In_Open_Scopes
(Scope
(Etype
(Typ
)))
8114 and then Is_Base_Type
(Typ
)
8116 Handle_Inherited_Private_Subprograms
(Typ
);
8119 -- Second stage: Register fixed entries
8122 Prim_Elmt
:= First_Prim
;
8123 while Present
(Prim_Elmt
) loop
8124 Prim
:= Node
(Prim_Elmt
);
8126 -- Predefined primitives have a separate table and all its
8127 -- entries are at predefined fixed positions.
8129 if In_Predef_Prims_DT
(Prim
) then
8130 if Is_Predefined_Dispatching_Operation
(Prim
) then
8131 Set_DT_Position
(Prim
, Default_Prim_Op_Position
(Prim
));
8133 else pragma Assert
(Present
(Alias
(Prim
)));
8134 Set_DT_Position
(Prim
,
8135 Default_Prim_Op_Position
(Ultimate_Alias
(Prim
)));
8138 -- Overriding primitives of ancestor abstract interfaces
8140 elsif Present
(Interface_Alias
(Prim
))
8141 and then Is_Ancestor
8142 (Find_Dispatching_Type
(Interface_Alias
(Prim
)), Typ
,
8143 Use_Full_View
=> True)
8145 pragma Assert
(DT_Position
(Prim
) = No_Uint
8146 and then Present
(DTC_Entity
(Interface_Alias
(Prim
))));
8148 E
:= Interface_Alias
(Prim
);
8149 Set_DT_Position
(Prim
, DT_Position
(E
));
8152 (DT_Position
(Alias
(Prim
)) = No_Uint
8153 or else DT_Position
(Alias
(Prim
)) = DT_Position
(E
));
8154 Set_DT_Position
(Alias
(Prim
), DT_Position
(E
));
8155 Set_Fixed_Prim
(UI_To_Int
(DT_Position
(Prim
)));
8157 -- Overriding primitives must use the same entry as the
8158 -- overridden primitive.
8160 elsif not Present
(Interface_Alias
(Prim
))
8161 and then Present
(Alias
(Prim
))
8162 and then Chars
(Prim
) = Chars
(Alias
(Prim
))
8163 and then Find_Dispatching_Type
(Alias
(Prim
)) /= Typ
8164 and then Is_Ancestor
8165 (Find_Dispatching_Type
(Alias
(Prim
)), Typ
,
8166 Use_Full_View
=> True)
8167 and then Present
(DTC_Entity
(Alias
(Prim
)))
8170 Set_DT_Position
(Prim
, DT_Position
(E
));
8172 if not Is_Predefined_Dispatching_Alias
(E
) then
8173 Set_Fixed_Prim
(UI_To_Int
(DT_Position
(E
)));
8177 Next_Elmt
(Prim_Elmt
);
8180 -- Third stage: Fix the position of all the new primitives. Entries
8181 -- associated with primitives covering interfaces are handled in a
8184 Prim_Elmt
:= First_Prim
;
8185 while Present
(Prim_Elmt
) loop
8186 Prim
:= Node
(Prim_Elmt
);
8188 -- Skip primitives previously set entries
8190 if DT_Position
(Prim
) /= No_Uint
then
8193 -- Primitives covering interface primitives are handled later
8195 elsif Present
(Interface_Alias
(Prim
)) then
8199 -- Take the next available position in the DT
8202 Nb_Prim
:= Nb_Prim
+ 1;
8203 pragma Assert
(Nb_Prim
<= Count_Prim
);
8204 exit when not Fixed_Prim
(Nb_Prim
);
8207 Set_DT_Position
(Prim
, UI_From_Int
(Nb_Prim
));
8208 Set_Fixed_Prim
(Nb_Prim
);
8211 Next_Elmt
(Prim_Elmt
);
8215 -- Fourth stage: Complete the decoration of primitives covering
8216 -- interfaces (that is, propagate the DT_Position attribute from
8217 -- the aliased primitive)
8219 Prim_Elmt
:= First_Prim
;
8220 while Present
(Prim_Elmt
) loop
8221 Prim
:= Node
(Prim_Elmt
);
8223 if DT_Position
(Prim
) = No_Uint
8224 and then Present
(Interface_Alias
(Prim
))
8226 pragma Assert
(Present
(Alias
(Prim
))
8227 and then Find_Dispatching_Type
(Alias
(Prim
)) = Typ
);
8229 -- Check if this entry will be placed in the primary DT
8232 (Find_Dispatching_Type
(Interface_Alias
(Prim
)), Typ
,
8233 Use_Full_View
=> True)
8235 pragma Assert
(DT_Position
(Alias
(Prim
)) /= No_Uint
);
8236 Set_DT_Position
(Prim
, DT_Position
(Alias
(Prim
)));
8238 -- Otherwise it will be placed in the secondary DT
8242 (DT_Position
(Interface_Alias
(Prim
)) /= No_Uint
);
8243 Set_DT_Position
(Prim
,
8244 DT_Position
(Interface_Alias
(Prim
)));
8248 Next_Elmt
(Prim_Elmt
);
8251 -- Generate listing showing the contents of the dispatch tables. This
8252 -- action is done before some further static checks because in case of
8253 -- critical errors caused by a wrong dispatch table we need to see the
8254 -- contents of such table.
8256 if Debug_Flag_ZZ
then
8260 -- Final stage: Ensure that the table is correct plus some further
8261 -- verifications concerning the primitives.
8263 Prim_Elmt
:= First_Prim
;
8265 while Present
(Prim_Elmt
) loop
8266 Prim
:= Node
(Prim_Elmt
);
8268 -- At this point all the primitives MUST have a position in the
8271 if DT_Position
(Prim
) = No_Uint
then
8272 raise Program_Error
;
8275 -- Calculate real size of the dispatch table
8277 if not In_Predef_Prims_DT
(Prim
)
8278 and then UI_To_Int
(DT_Position
(Prim
)) > DT_Length
8280 DT_Length
:= UI_To_Int
(DT_Position
(Prim
));
8283 -- Ensure that the assigned position to non-predefined dispatching
8284 -- operations in the dispatch table is correct.
8286 if not Is_Predefined_Dispatching_Operation
(Prim
)
8287 and then not Is_Predefined_Dispatching_Alias
(Prim
)
8289 Validate_Position
(Prim
);
8292 if Chars
(Prim
) = Name_Finalize
then
8296 if Chars
(Prim
) = Name_Adjust
then
8300 -- An abstract operation cannot be declared in the private part for a
8301 -- visible abstract type, because it can't be overridden outside this
8302 -- package hierarchy. For explicit declarations this is checked at
8303 -- the point of declaration, but for inherited operations it must be
8304 -- done when building the dispatch table.
8306 -- Ada 2005 (AI-251): Primitives associated with interfaces are
8307 -- excluded from this check because interfaces must be visible in
8308 -- the public and private part (RM 7.3 (7.3/2))
8310 -- We disable this check in Relaxed_RM_Semantics mode, to accommodate
8313 if not Relaxed_RM_Semantics
8314 and then Is_Abstract_Type
(Typ
)
8315 and then Is_Abstract_Subprogram
(Prim
)
8316 and then Present
(Alias
(Prim
))
8317 and then not Is_Interface
8318 (Find_Dispatching_Type
(Ultimate_Alias
(Prim
)))
8319 and then not Present
(Interface_Alias
(Prim
))
8320 and then Is_Derived_Type
(Typ
)
8321 and then In_Private_Part
(Current_Scope
)
8323 List_Containing
(Parent
(Prim
)) =
8324 Private_Declarations
(Package_Specification
(Current_Scope
))
8325 and then Original_View_In_Visible_Part
(Typ
)
8327 -- We exclude Input and Output stream operations because
8328 -- Limited_Controlled inherits useless Input and Output stream
8329 -- operations from Root_Controlled, which can never be overridden.
8331 if not Is_TSS
(Prim
, TSS_Stream_Input
)
8333 not Is_TSS
(Prim
, TSS_Stream_Output
)
8336 ("abstract inherited private operation&" &
8337 " must be overridden (RM 3.9.3(10))",
8338 Parent
(Typ
), Prim
);
8342 Next_Elmt
(Prim_Elmt
);
8347 if Is_Controlled
(Typ
) then
8348 if not Finalized
then
8350 ("controlled type has no explicit Finalize method??", Typ
);
8352 elsif not Adjusted
then
8354 ("controlled type has no explicit Adjust method??", Typ
);
8358 -- Set the final size of the Dispatch Table
8360 Set_DT_Entry_Count
(The_Tag
, UI_From_Int
(DT_Length
));
8362 -- The derived type must have at least as many components as its parent
8363 -- (for root types Etype points to itself and the test cannot fail).
8365 if DT_Entry_Count
(The_Tag
) <
8366 DT_Entry_Count
(First_Tag_Component
(Parent_Typ
))
8368 raise Program_Error
;
8370 end Set_All_DT_Position
;
8372 --------------------------
8373 -- Set_CPP_Constructors --
8374 --------------------------
8376 procedure Set_CPP_Constructors
(Typ
: Entity_Id
) is
8378 function Gen_Parameters_Profile
(E
: Entity_Id
) return List_Id
;
8379 -- Duplicate the parameters profile of the imported C++ constructor
8380 -- adding an access to the object as an additional parameter.
8382 ----------------------------
8383 -- Gen_Parameters_Profile --
8384 ----------------------------
8386 function Gen_Parameters_Profile
(E
: Entity_Id
) return List_Id
is
8387 Loc
: constant Source_Ptr
:= Sloc
(E
);
8394 Make_Parameter_Specification
(Loc
,
8395 Defining_Identifier
=>
8396 Make_Defining_Identifier
(Loc
, Name_uInit
),
8397 Parameter_Type
=> New_Occurrence_Of
(Typ
, Loc
)));
8399 if Present
(Parameter_Specifications
(Parent
(E
))) then
8400 P
:= First
(Parameter_Specifications
(Parent
(E
)));
8401 while Present
(P
) loop
8403 Make_Parameter_Specification
(Loc
,
8404 Defining_Identifier
=>
8405 Make_Defining_Identifier
(Loc
,
8406 Chars
=> Chars
(Defining_Identifier
(P
))),
8407 Parameter_Type
=> New_Copy_Tree
(Parameter_Type
(P
)),
8408 Expression
=> New_Copy_Tree
(Expression
(P
))));
8414 end Gen_Parameters_Profile
;
8420 Found
: Boolean := False;
8426 Covers_Default_Constructor
: Entity_Id
:= Empty
;
8428 -- Start of processing for Set_CPP_Constructor
8431 pragma Assert
(Is_CPP_Class
(Typ
));
8433 -- Look for the constructor entities
8435 E
:= Next_Entity
(Typ
);
8436 while Present
(E
) loop
8437 if Ekind
(E
) = E_Function
8438 and then Is_Constructor
(E
)
8442 Parms
:= Gen_Parameters_Profile
(E
);
8444 Make_Defining_Identifier
(Loc
,
8445 Chars
=> Make_Init_Proc_Name
(Typ
));
8447 -- Case 1: Constructor of untagged type
8449 -- If the C++ class has no virtual methods then the matching Ada
8450 -- type is an untagged record type. In such case there is no need
8451 -- to generate a wrapper of the C++ constructor because the _tag
8452 -- component is not available.
8454 if not Is_Tagged_Type
(Typ
) then
8456 (Make_Subprogram_Declaration
(Loc
,
8458 Make_Procedure_Specification
(Loc
,
8459 Defining_Unit_Name
=> IP
,
8460 Parameter_Specifications
=> Parms
)));
8462 Set_Init_Proc
(Typ
, IP
);
8463 Set_Is_Imported
(IP
);
8464 Set_Is_Constructor
(IP
);
8465 Set_Interface_Name
(IP
, Interface_Name
(E
));
8466 Set_Convention
(IP
, Convention_CPP
);
8468 Set_Has_Completion
(IP
);
8470 -- Case 2: Constructor of a tagged type
8472 -- In this case we generate the IP as a wrapper of the the
8473 -- C++ constructor because IP must also save copy of the _tag
8474 -- generated in the C++ side. The copy of the _tag is used by
8475 -- Build_CPP_Init_Procedure to elaborate derivations of C++ types.
8478 -- procedure IP (_init : Typ; ...) is
8479 -- procedure ConstructorP (_init : Typ; ...);
8480 -- pragma Import (ConstructorP);
8482 -- ConstructorP (_init, ...);
8483 -- if Typ._tag = null then
8484 -- Typ._tag := _init._tag;
8490 Body_Stmts
: constant List_Id
:= New_List
;
8491 Constructor_Id
: Entity_Id
;
8492 Constructor_Decl_Node
: Node_Id
;
8493 Init_Tags_List
: List_Id
;
8496 Constructor_Id
:= Make_Temporary
(Loc
, 'P');
8498 Constructor_Decl_Node
:=
8499 Make_Subprogram_Declaration
(Loc
,
8500 Make_Procedure_Specification
(Loc
,
8501 Defining_Unit_Name
=> Constructor_Id
,
8502 Parameter_Specifications
=> Parms
));
8504 Set_Is_Imported
(Constructor_Id
);
8505 Set_Is_Constructor
(Constructor_Id
);
8506 Set_Interface_Name
(Constructor_Id
, Interface_Name
(E
));
8507 Set_Convention
(Constructor_Id
, Convention_CPP
);
8508 Set_Is_Public
(Constructor_Id
);
8509 Set_Has_Completion
(Constructor_Id
);
8511 -- Build the init procedure as a wrapper of this constructor
8513 Parms
:= Gen_Parameters_Profile
(E
);
8515 -- Invoke the C++ constructor
8518 Actuals
: constant List_Id
:= New_List
;
8522 while Present
(P
) loop
8524 New_Occurrence_Of
(Defining_Identifier
(P
), Loc
));
8528 Append_To
(Body_Stmts
,
8529 Make_Procedure_Call_Statement
(Loc
,
8530 Name
=> New_Occurrence_Of
(Constructor_Id
, Loc
),
8531 Parameter_Associations
=> Actuals
));
8534 -- Initialize copies of C++ primary and secondary tags
8536 Init_Tags_List
:= New_List
;
8543 Tag_Elmt
:= First_Elmt
(Access_Disp_Table
(Typ
));
8544 Tag_Comp
:= First_Tag_Component
(Typ
);
8546 while Present
(Tag_Elmt
)
8547 and then Is_Tag
(Node
(Tag_Elmt
))
8549 -- Skip the following assertion with primary tags
8550 -- because Related_Type is not set on primary tag
8554 (Tag_Comp
= First_Tag_Component
(Typ
)
8555 or else Related_Type
(Node
(Tag_Elmt
))
8556 = Related_Type
(Tag_Comp
));
8558 Append_To
(Init_Tags_List
,
8559 Make_Assignment_Statement
(Loc
,
8561 New_Occurrence_Of
(Node
(Tag_Elmt
), Loc
),
8563 Make_Selected_Component
(Loc
,
8565 Make_Identifier
(Loc
, Name_uInit
),
8567 New_Occurrence_Of
(Tag_Comp
, Loc
))));
8569 Tag_Comp
:= Next_Tag_Component
(Tag_Comp
);
8570 Next_Elmt
(Tag_Elmt
);
8574 Append_To
(Body_Stmts
,
8575 Make_If_Statement
(Loc
,
8580 (Node
(First_Elmt
(Access_Disp_Table
(Typ
))),
8583 Unchecked_Convert_To
(RTE
(RE_Tag
),
8584 New_Occurrence_Of
(RTE
(RE_Null_Address
), Loc
))),
8585 Then_Statements
=> Init_Tags_List
));
8588 Make_Subprogram_Body
(Loc
,
8590 Make_Procedure_Specification
(Loc
,
8591 Defining_Unit_Name
=> IP
,
8592 Parameter_Specifications
=> Parms
),
8593 Declarations
=> New_List
(Constructor_Decl_Node
),
8594 Handled_Statement_Sequence
=>
8595 Make_Handled_Sequence_Of_Statements
(Loc
,
8596 Statements
=> Body_Stmts
,
8597 Exception_Handlers
=> No_List
));
8599 Discard_Node
(IP_Body
);
8600 Set_Init_Proc
(Typ
, IP
);
8604 -- If this constructor has parameters and all its parameters have
8605 -- defaults then it covers the default constructor. The semantic
8606 -- analyzer ensures that only one constructor with defaults covers
8607 -- the default constructor.
8609 if Present
(Parameter_Specifications
(Parent
(E
)))
8610 and then Needs_No_Actuals
(E
)
8612 Covers_Default_Constructor
:= IP
;
8619 -- If there are no constructors, mark the type as abstract since we
8620 -- won't be able to declare objects of that type.
8623 Set_Is_Abstract_Type
(Typ
);
8626 -- Handle constructor that has all its parameters with defaults and
8627 -- hence it covers the default constructor. We generate a wrapper IP
8628 -- which calls the covering constructor.
8630 if Present
(Covers_Default_Constructor
) then
8632 Body_Stmts
: List_Id
;
8635 Loc
:= Sloc
(Covers_Default_Constructor
);
8637 Body_Stmts
:= New_List
(
8638 Make_Procedure_Call_Statement
(Loc
,
8640 New_Occurrence_Of
(Covers_Default_Constructor
, Loc
),
8641 Parameter_Associations
=> New_List
(
8642 Make_Identifier
(Loc
, Name_uInit
))));
8644 IP
:= Make_Defining_Identifier
(Loc
, Make_Init_Proc_Name
(Typ
));
8647 Make_Subprogram_Body
(Loc
,
8649 Make_Procedure_Specification
(Loc
,
8650 Defining_Unit_Name
=> IP
,
8651 Parameter_Specifications
=> New_List
(
8652 Make_Parameter_Specification
(Loc
,
8653 Defining_Identifier
=>
8654 Make_Defining_Identifier
(Loc
, Name_uInit
),
8655 Parameter_Type
=> New_Occurrence_Of
(Typ
, Loc
)))),
8657 Declarations
=> No_List
,
8659 Handled_Statement_Sequence
=>
8660 Make_Handled_Sequence_Of_Statements
(Loc
,
8661 Statements
=> Body_Stmts
,
8662 Exception_Handlers
=> No_List
));
8664 Discard_Node
(IP_Body
);
8665 Set_Init_Proc
(Typ
, IP
);
8669 -- If the CPP type has constructors then it must import also the default
8670 -- C++ constructor. It is required for default initialization of objects
8671 -- of the type. It is also required to elaborate objects of Ada types
8672 -- that are defined as derivations of this CPP type.
8674 if Has_CPP_Constructors
(Typ
)
8675 and then No
(Init_Proc
(Typ
))
8677 Error_Msg_N
("??default constructor must be imported from C++", Typ
);
8679 end Set_CPP_Constructors
;
8681 --------------------------
8682 -- Set_DTC_Entity_Value --
8683 --------------------------
8685 procedure Set_DTC_Entity_Value
8686 (Tagged_Type
: Entity_Id
;
8690 if Present
(Interface_Alias
(Prim
))
8691 and then Is_Interface
8692 (Find_Dispatching_Type
(Interface_Alias
(Prim
)))
8694 Set_DTC_Entity
(Prim
,
8697 Iface
=> Find_Dispatching_Type
(Interface_Alias
(Prim
))));
8699 Set_DTC_Entity
(Prim
,
8700 First_Tag_Component
(Tagged_Type
));
8702 end Set_DTC_Entity_Value
;
8708 function Tagged_Kind
(T
: Entity_Id
) return Node_Id
is
8709 Conc_Typ
: Entity_Id
;
8710 Loc
: constant Source_Ptr
:= Sloc
(T
);
8714 (Is_Tagged_Type
(T
) and then RTE_Available
(RE_Tagged_Kind
));
8718 if Is_Abstract_Type
(T
) then
8719 if Is_Limited_Record
(T
) then
8720 return New_Occurrence_Of
8721 (RTE
(RE_TK_Abstract_Limited_Tagged
), Loc
);
8723 return New_Occurrence_Of
8724 (RTE
(RE_TK_Abstract_Tagged
), Loc
);
8729 elsif Is_Concurrent_Record_Type
(T
) then
8730 Conc_Typ
:= Corresponding_Concurrent_Type
(T
);
8732 if Present
(Full_View
(Conc_Typ
)) then
8733 Conc_Typ
:= Full_View
(Conc_Typ
);
8736 if Ekind
(Conc_Typ
) = E_Protected_Type
then
8737 return New_Occurrence_Of
(RTE
(RE_TK_Protected
), Loc
);
8739 pragma Assert
(Ekind
(Conc_Typ
) = E_Task_Type
);
8740 return New_Occurrence_Of
(RTE
(RE_TK_Task
), Loc
);
8743 -- Regular tagged kinds
8746 if Is_Limited_Record
(T
) then
8747 return New_Occurrence_Of
(RTE
(RE_TK_Limited_Tagged
), Loc
);
8749 return New_Occurrence_Of
(RTE
(RE_TK_Tagged
), Loc
);
8758 procedure Write_DT
(Typ
: Entity_Id
) is
8763 -- Protect this procedure against wrong usage. Required because it will
8764 -- be used directly from GDB
8766 if not (Typ
<= Last_Node_Id
)
8767 or else not Is_Tagged_Type
(Typ
)
8769 Write_Str
("wrong usage: Write_DT must be used with tagged types");
8774 Write_Int
(Int
(Typ
));
8776 Write_Name
(Chars
(Typ
));
8778 if Is_Interface
(Typ
) then
8779 Write_Str
(" is interface");
8784 Elmt
:= First_Elmt
(Primitive_Operations
(Typ
));
8785 while Present
(Elmt
) loop
8786 Prim
:= Node
(Elmt
);
8789 -- Indicate if this primitive will be allocated in the primary
8790 -- dispatch table or in a secondary dispatch table associated
8791 -- with an abstract interface type
8793 if Present
(DTC_Entity
(Prim
)) then
8794 if Etype
(DTC_Entity
(Prim
)) = RTE
(RE_Tag
) then
8801 -- Output the node of this primitive operation and its name
8803 Write_Int
(Int
(Prim
));
8806 if Is_Predefined_Dispatching_Operation
(Prim
) then
8807 Write_Str
("(predefined) ");
8810 -- Prefix the name of the primitive with its corresponding tagged
8811 -- type to facilitate seeing inherited primitives.
8813 if Present
(Alias
(Prim
)) then
8815 (Chars
(Find_Dispatching_Type
(Ultimate_Alias
(Prim
))));
8817 Write_Name
(Chars
(Typ
));
8821 Write_Name
(Chars
(Prim
));
8823 -- Indicate if this primitive has an aliased primitive
8825 if Present
(Alias
(Prim
)) then
8826 Write_Str
(" (alias = ");
8827 Write_Int
(Int
(Alias
(Prim
)));
8829 -- If the DTC_Entity attribute is already set we can also output
8830 -- the name of the interface covered by this primitive (if any).
8832 if Ekind_In
(Alias
(Prim
), E_Function
, E_Procedure
)
8833 and then Present
(DTC_Entity
(Alias
(Prim
)))
8834 and then Is_Interface
(Scope
(DTC_Entity
(Alias
(Prim
))))
8836 Write_Str
(" from interface ");
8837 Write_Name
(Chars
(Scope
(DTC_Entity
(Alias
(Prim
)))));
8840 if Present
(Interface_Alias
(Prim
)) then
8841 Write_Str
(", AI_Alias of ");
8843 if Is_Null_Interface_Primitive
(Interface_Alias
(Prim
)) then
8844 Write_Str
("null primitive ");
8848 (Chars
(Find_Dispatching_Type
(Interface_Alias
(Prim
))));
8850 Write_Int
(Int
(Interface_Alias
(Prim
)));
8856 -- Display the final position of this primitive in its associated
8857 -- (primary or secondary) dispatch table.
8859 if Present
(DTC_Entity
(Prim
))
8860 and then DT_Position
(Prim
) /= No_Uint
8862 Write_Str
(" at #");
8863 Write_Int
(UI_To_Int
(DT_Position
(Prim
)));
8866 if Is_Abstract_Subprogram
(Prim
) then
8867 Write_Str
(" is abstract;");
8869 -- Check if this is a null primitive
8871 elsif Comes_From_Source
(Prim
)
8872 and then Ekind
(Prim
) = E_Procedure
8873 and then Null_Present
(Parent
(Prim
))
8875 Write_Str
(" is null;");
8878 if Is_Eliminated
(Ultimate_Alias
(Prim
)) then
8879 Write_Str
(" (eliminated)");
8882 if Is_Imported
(Prim
)
8883 and then Convention
(Prim
) = Convention_CPP
8885 Write_Str
(" (C++)");