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 -- Evaluate if we can statically displace the pointer to the object
1144 Opnd_Typ
: constant Node_Id
:= Underlying_Record_Type
(Operand_Typ
);
1148 not Is_Interface
(Opnd_Typ
)
1149 and then Interface_Present_In_Ancestor
1152 and then (Etype
(Opnd_Typ
) = Opnd_Typ
1154 Is_Variable_Size_Record
(Etype
(Opnd_Typ
)));
1157 if not Tagged_Type_Expansion
then
1158 if VM_Target
/= No_VM
then
1159 if Is_Access_Type
(Operand_Typ
) then
1160 Operand_Typ
:= Designated_Type
(Operand_Typ
);
1163 if Is_Class_Wide_Type
(Operand_Typ
) then
1164 Operand_Typ
:= Root_Type
(Operand_Typ
);
1167 if not Is_Static
and then Operand_Typ
/= Iface_Typ
then
1169 Make_Procedure_Call_Statement
(Loc
,
1170 Name
=> New_Occurrence_Of
1171 (RTE
(RE_Check_Interface_Conversion
), Loc
),
1172 Parameter_Associations
=> New_List
(
1173 Make_Attribute_Reference
(Loc
,
1174 Prefix
=> Duplicate_Subexpr
(Expression
(N
)),
1175 Attribute_Name
=> Name_Tag
),
1176 Make_Attribute_Reference
(Loc
,
1177 Prefix
=> New_Occurrence_Of
(Iface_Typ
, Loc
),
1178 Attribute_Name
=> Name_Tag
))));
1181 -- Just do a conversion ???
1183 Rewrite
(N
, Unchecked_Convert_To
(Etype
(N
), N
));
1189 -- A static conversion to an interface type that is not classwide is
1190 -- curious but legal if the interface operation is a null procedure.
1191 -- If the operation is abstract it will be rejected later.
1194 and then Is_Interface
(Etype
(N
))
1195 and then not Is_Class_Wide_Type
(Etype
(N
))
1196 and then Comes_From_Source
(N
)
1198 Rewrite
(N
, Unchecked_Convert_To
(Etype
(N
), N
));
1203 if not Is_Static
then
1205 -- Give error if configurable run time and Displace not available
1207 if not RTE_Available
(RE_Displace
) then
1208 Error_Msg_CRT
("dynamic interface conversion", N
);
1212 -- Handle conversion of access-to-class-wide interface types. Target
1213 -- can be an access to an object or an access to another class-wide
1214 -- interface (see -1- and -2- in the following example):
1216 -- type Iface1_Ref is access all Iface1'Class;
1217 -- type Iface2_Ref is access all Iface1'Class;
1219 -- Acc1 : Iface1_Ref := new ...
1220 -- Obj : Obj_Ref := Obj_Ref (Acc); -- 1
1221 -- Acc2 : Iface2_Ref := Iface2_Ref (Acc); -- 2
1223 if Is_Access_Type
(Operand_Typ
) then
1225 Unchecked_Convert_To
(Etype
(N
),
1226 Make_Function_Call
(Loc
,
1227 Name
=> New_Occurrence_Of
(RTE
(RE_Displace
), Loc
),
1228 Parameter_Associations
=> New_List
(
1230 Unchecked_Convert_To
(RTE
(RE_Address
),
1231 Relocate_Node
(Expression
(N
))),
1234 (Node
(First_Elmt
(Access_Disp_Table
(Iface_Typ
))),
1242 Make_Function_Call
(Loc
,
1243 Name
=> New_Occurrence_Of
(RTE
(RE_Displace
), Loc
),
1244 Parameter_Associations
=> New_List
(
1245 Make_Attribute_Reference
(Loc
,
1246 Prefix
=> Relocate_Node
(Expression
(N
)),
1247 Attribute_Name
=> Name_Address
),
1250 (Node
(First_Elmt
(Access_Disp_Table
(Iface_Typ
))),
1255 -- If target is a class-wide interface, change the type of the data
1256 -- returned by IW_Convert to indicate this is a dispatching call.
1259 New_Itype
: Entity_Id
;
1262 New_Itype
:= Create_Itype
(E_Anonymous_Access_Type
, N
);
1263 Set_Etype
(New_Itype
, New_Itype
);
1264 Set_Directly_Designated_Type
(New_Itype
, Etyp
);
1267 Make_Explicit_Dereference
(Loc
,
1269 Unchecked_Convert_To
(New_Itype
, Relocate_Node
(N
))));
1271 Freeze_Itype
(New_Itype
, N
);
1277 Iface_Tag
:= Find_Interface_Tag
(Operand_Typ
, Iface_Typ
);
1278 pragma Assert
(Iface_Tag
/= Empty
);
1280 -- Keep separate access types to interfaces because one internal
1281 -- function is used to handle the null value (see following comments)
1283 if not Is_Access_Type
(Etype
(N
)) then
1285 -- Statically displace the pointer to the object to reference the
1286 -- component containing the secondary dispatch table.
1289 Convert_Tag_To_Interface
(Class_Wide_Type
(Iface_Typ
),
1290 Make_Selected_Component
(Loc
,
1291 Prefix
=> Relocate_Node
(Expression
(N
)),
1292 Selector_Name
=> New_Occurrence_Of
(Iface_Tag
, Loc
))));
1295 -- Build internal function to handle the case in which the actual is
1296 -- null. If the actual is null returns null because no displacement
1297 -- is required; otherwise performs a type conversion that will be
1298 -- expanded in the code that returns the value of the displaced
1301 -- function Func (O : Address) return Iface_Typ is
1302 -- type Op_Typ is access all Operand_Typ;
1303 -- Aux : Op_Typ := To_Op_Typ (O);
1305 -- if O = Null_Address then
1308 -- return Iface_Typ!(Aux.Iface_Tag'Address);
1313 Desig_Typ
: Entity_Id
;
1315 New_Typ_Decl
: Node_Id
;
1319 Desig_Typ
:= Etype
(Expression
(N
));
1321 if Is_Access_Type
(Desig_Typ
) then
1323 Available_View
(Directly_Designated_Type
(Desig_Typ
));
1326 if Is_Concurrent_Type
(Desig_Typ
) then
1327 Desig_Typ
:= Base_Type
(Corresponding_Record_Type
(Desig_Typ
));
1331 Make_Full_Type_Declaration
(Loc
,
1332 Defining_Identifier
=> Make_Temporary
(Loc
, 'T'),
1334 Make_Access_To_Object_Definition
(Loc
,
1335 All_Present
=> True,
1336 Null_Exclusion_Present
=> False,
1337 Constant_Present
=> False,
1338 Subtype_Indication
=>
1339 New_Occurrence_Of
(Desig_Typ
, Loc
)));
1342 Make_Simple_Return_Statement
(Loc
,
1343 Unchecked_Convert_To
(Etype
(N
),
1344 Make_Attribute_Reference
(Loc
,
1346 Make_Selected_Component
(Loc
,
1348 Unchecked_Convert_To
1349 (Defining_Identifier
(New_Typ_Decl
),
1350 Make_Identifier
(Loc
, Name_uO
)),
1352 New_Occurrence_Of
(Iface_Tag
, Loc
)),
1353 Attribute_Name
=> Name_Address
))));
1355 -- If the type is null-excluding, no need for the null branch.
1356 -- Otherwise we need to check for it and return null.
1358 if not Can_Never_Be_Null
(Etype
(N
)) then
1360 Make_If_Statement
(Loc
,
1363 Left_Opnd
=> Make_Identifier
(Loc
, Name_uO
),
1364 Right_Opnd
=> New_Occurrence_Of
1365 (RTE
(RE_Null_Address
), Loc
)),
1367 Then_Statements
=> New_List
(
1368 Make_Simple_Return_Statement
(Loc
, Make_Null
(Loc
))),
1369 Else_Statements
=> Stats
));
1372 Fent
:= Make_Temporary
(Loc
, 'F');
1374 Make_Subprogram_Body
(Loc
,
1376 Make_Function_Specification
(Loc
,
1377 Defining_Unit_Name
=> Fent
,
1379 Parameter_Specifications
=> New_List
(
1380 Make_Parameter_Specification
(Loc
,
1381 Defining_Identifier
=>
1382 Make_Defining_Identifier
(Loc
, Name_uO
),
1384 New_Occurrence_Of
(RTE
(RE_Address
), Loc
))),
1386 Result_Definition
=>
1387 New_Occurrence_Of
(Etype
(N
), Loc
)),
1389 Declarations
=> New_List
(New_Typ_Decl
),
1391 Handled_Statement_Sequence
=>
1392 Make_Handled_Sequence_Of_Statements
(Loc
, Stats
));
1394 -- Place function body before the expression containing the
1395 -- conversion. We suppress all checks because the body of the
1396 -- internally generated function already takes care of the case
1397 -- in which the actual is null; therefore there is no need to
1398 -- double check that the pointer is not null when the program
1399 -- executes the alternative that performs the type conversion).
1401 Insert_Action
(N
, Func
, Suppress
=> All_Checks
);
1403 if Is_Access_Type
(Etype
(Expression
(N
))) then
1405 -- Generate: Func (Address!(Expression))
1408 Make_Function_Call
(Loc
,
1409 Name
=> New_Occurrence_Of
(Fent
, Loc
),
1410 Parameter_Associations
=> New_List
(
1411 Unchecked_Convert_To
(RTE
(RE_Address
),
1412 Relocate_Node
(Expression
(N
))))));
1415 -- Generate: Func (Operand_Typ!(Expression)'Address)
1418 Make_Function_Call
(Loc
,
1419 Name
=> New_Occurrence_Of
(Fent
, Loc
),
1420 Parameter_Associations
=> New_List
(
1421 Make_Attribute_Reference
(Loc
,
1422 Prefix
=> Unchecked_Convert_To
(Operand_Typ
,
1423 Relocate_Node
(Expression
(N
))),
1424 Attribute_Name
=> Name_Address
))));
1430 end Expand_Interface_Conversion
;
1432 ------------------------------
1433 -- Expand_Interface_Actuals --
1434 ------------------------------
1436 procedure Expand_Interface_Actuals
(Call_Node
: Node_Id
) is
1438 Actual_Dup
: Node_Id
;
1439 Actual_Typ
: Entity_Id
;
1441 Conversion
: Node_Id
;
1443 Formal_Typ
: Entity_Id
;
1445 Formal_DDT
: Entity_Id
;
1446 Actual_DDT
: Entity_Id
;
1449 -- This subprogram is called directly from the semantics, so we need a
1450 -- check to see whether expansion is active before proceeding.
1452 if not Expander_Active
then
1456 -- Call using access to subprogram with explicit dereference
1458 if Nkind
(Name
(Call_Node
)) = N_Explicit_Dereference
then
1459 Subp
:= Etype
(Name
(Call_Node
));
1461 -- Call using selected component
1463 elsif Nkind
(Name
(Call_Node
)) = N_Selected_Component
then
1464 Subp
:= Entity
(Selector_Name
(Name
(Call_Node
)));
1466 -- Call using direct name
1469 Subp
:= Entity
(Name
(Call_Node
));
1472 -- Ada 2005 (AI-251): Look for interface type formals to force "this"
1475 Formal
:= First_Formal
(Subp
);
1476 Actual
:= First_Actual
(Call_Node
);
1477 while Present
(Formal
) loop
1478 Formal_Typ
:= Etype
(Formal
);
1480 if Ekind
(Formal_Typ
) = E_Record_Type_With_Private
then
1481 Formal_Typ
:= Full_View
(Formal_Typ
);
1484 if Is_Access_Type
(Formal_Typ
) then
1485 Formal_DDT
:= Directly_Designated_Type
(Formal_Typ
);
1488 Actual_Typ
:= Etype
(Actual
);
1490 if Is_Access_Type
(Actual_Typ
) then
1491 Actual_DDT
:= Directly_Designated_Type
(Actual_Typ
);
1494 if Is_Interface
(Formal_Typ
)
1495 and then Is_Class_Wide_Type
(Formal_Typ
)
1497 -- No need to displace the pointer if the type of the actual
1498 -- coincides with the type of the formal.
1500 if Actual_Typ
= Formal_Typ
then
1503 -- No need to displace the pointer if the interface type is a
1504 -- parent of the type of the actual because in this case the
1505 -- interface primitives are located in the primary dispatch table.
1507 elsif Is_Ancestor
(Formal_Typ
, Actual_Typ
,
1508 Use_Full_View
=> True)
1512 -- Implicit conversion to the class-wide formal type to force the
1513 -- displacement of the pointer.
1516 -- Normally, expansion of actuals for calls to build-in-place
1517 -- functions happens as part of Expand_Actuals, but in this
1518 -- case the call will be wrapped in a conversion and soon after
1519 -- expanded further to handle the displacement for a class-wide
1520 -- interface conversion, so if this is a BIP call then we need
1521 -- to handle it now.
1523 if Ada_Version
>= Ada_2005
1524 and then Is_Build_In_Place_Function_Call
(Actual
)
1526 Make_Build_In_Place_Call_In_Anonymous_Context
(Actual
);
1529 Conversion
:= Convert_To
(Formal_Typ
, Relocate_Node
(Actual
));
1530 Rewrite
(Actual
, Conversion
);
1531 Analyze_And_Resolve
(Actual
, Formal_Typ
);
1534 -- Access to class-wide interface type
1536 elsif Is_Access_Type
(Formal_Typ
)
1537 and then Is_Interface
(Formal_DDT
)
1538 and then Is_Class_Wide_Type
(Formal_DDT
)
1539 and then Interface_Present_In_Ancestor
1541 Iface
=> Etype
(Formal_DDT
))
1543 -- Handle attributes 'Access and 'Unchecked_Access
1545 if Nkind
(Actual
) = N_Attribute_Reference
1547 (Attribute_Name
(Actual
) = Name_Access
1548 or else Attribute_Name
(Actual
) = Name_Unchecked_Access
)
1550 -- This case must have been handled by the analysis and
1551 -- expansion of 'Access. The only exception is when types
1552 -- match and no further expansion is required.
1554 pragma Assert
(Base_Type
(Etype
(Prefix
(Actual
)))
1555 = Base_Type
(Formal_DDT
));
1558 -- No need to displace the pointer if the type of the actual
1559 -- coincides with the type of the formal.
1561 elsif Actual_DDT
= Formal_DDT
then
1564 -- No need to displace the pointer if the interface type is
1565 -- a parent of the type of the actual because in this case the
1566 -- interface primitives are located in the primary dispatch table.
1568 elsif Is_Ancestor
(Formal_DDT
, Actual_DDT
,
1569 Use_Full_View
=> True)
1574 Actual_Dup
:= Relocate_Node
(Actual
);
1576 if From_Limited_With
(Actual_Typ
) then
1578 -- If the type of the actual parameter comes from a
1579 -- limited with-clause and the non-limited view is already
1580 -- available, we replace the anonymous access type by
1581 -- a duplicate declaration whose designated type is the
1582 -- non-limited view.
1584 if Ekind
(Actual_DDT
) = E_Incomplete_Type
1585 and then Present
(Non_Limited_View
(Actual_DDT
))
1587 Anon
:= New_Copy
(Actual_Typ
);
1589 if Is_Itype
(Anon
) then
1590 Set_Scope
(Anon
, Current_Scope
);
1593 Set_Directly_Designated_Type
(Anon
,
1594 Non_Limited_View
(Actual_DDT
));
1595 Set_Etype
(Actual_Dup
, Anon
);
1597 elsif Is_Class_Wide_Type
(Actual_DDT
)
1598 and then Ekind
(Etype
(Actual_DDT
)) = E_Incomplete_Type
1599 and then Present
(Non_Limited_View
(Etype
(Actual_DDT
)))
1601 Anon
:= New_Copy
(Actual_Typ
);
1603 if Is_Itype
(Anon
) then
1604 Set_Scope
(Anon
, Current_Scope
);
1607 Set_Directly_Designated_Type
(Anon
,
1608 New_Copy
(Actual_DDT
));
1609 Set_Class_Wide_Type
(Directly_Designated_Type
(Anon
),
1610 New_Copy
(Class_Wide_Type
(Actual_DDT
)));
1611 Set_Etype
(Directly_Designated_Type
(Anon
),
1612 Non_Limited_View
(Etype
(Actual_DDT
)));
1614 Class_Wide_Type
(Directly_Designated_Type
(Anon
)),
1615 Non_Limited_View
(Etype
(Actual_DDT
)));
1616 Set_Etype
(Actual_Dup
, Anon
);
1620 Conversion
:= Convert_To
(Formal_Typ
, Actual_Dup
);
1621 Rewrite
(Actual
, Conversion
);
1622 Analyze_And_Resolve
(Actual
, Formal_Typ
);
1626 Next_Actual
(Actual
);
1627 Next_Formal
(Formal
);
1629 end Expand_Interface_Actuals
;
1631 ----------------------------
1632 -- Expand_Interface_Thunk --
1633 ----------------------------
1635 procedure Expand_Interface_Thunk
1637 Thunk_Id
: out Entity_Id
;
1638 Thunk_Code
: out Node_Id
)
1640 Loc
: constant Source_Ptr
:= Sloc
(Prim
);
1641 Actuals
: constant List_Id
:= New_List
;
1642 Decl
: constant List_Id
:= New_List
;
1643 Formals
: constant List_Id
:= New_List
;
1644 Target
: constant Entity_Id
:= Ultimate_Alias
(Prim
);
1651 Iface_Formal
: Node_Id
;
1653 Offset_To_Top
: Node_Id
;
1654 Target_Formal
: Entity_Id
;
1658 Thunk_Code
:= Empty
;
1660 -- No thunk needed if the primitive has been eliminated
1662 if Is_Eliminated
(Ultimate_Alias
(Prim
)) then
1665 -- In case of primitives that are functions without formals and a
1666 -- controlling result there is no need to build the thunk.
1668 elsif not Present
(First_Formal
(Target
)) then
1669 pragma Assert
(Ekind
(Target
) = E_Function
1670 and then Has_Controlling_Result
(Target
));
1674 -- Duplicate the formals of the Target primitive. In the thunk, the type
1675 -- of the controlling formal is the covered interface type (instead of
1676 -- the target tagged type). Done to avoid problems with discriminated
1677 -- tagged types because, if the controlling type has discriminants with
1678 -- default values, then the type conversions done inside the body of
1679 -- the thunk (after the displacement of the pointer to the base of the
1680 -- actual object) generate code that modify its contents.
1682 -- Note: This special management is not done for predefined primitives
1685 if not Is_Predefined_Dispatching_Operation
(Prim
) then
1686 Iface_Formal
:= First_Formal
(Interface_Alias
(Prim
));
1689 Formal
:= First_Formal
(Target
);
1690 while Present
(Formal
) loop
1691 Ftyp
:= Etype
(Formal
);
1693 -- Use the interface type as the type of the controlling formal (see
1696 if not Is_Controlling_Formal
(Formal
)
1697 or else Is_Predefined_Dispatching_Operation
(Prim
)
1699 Ftyp
:= Etype
(Formal
);
1700 Expr
:= New_Copy_Tree
(Expression
(Parent
(Formal
)));
1702 Ftyp
:= Etype
(Iface_Formal
);
1707 Make_Parameter_Specification
(Loc
,
1708 Defining_Identifier
=>
1709 Make_Defining_Identifier
(Sloc
(Formal
),
1710 Chars
=> Chars
(Formal
)),
1711 In_Present
=> In_Present
(Parent
(Formal
)),
1712 Out_Present
=> Out_Present
(Parent
(Formal
)),
1713 Parameter_Type
=> New_Occurrence_Of
(Ftyp
, Loc
),
1714 Expression
=> Expr
));
1716 if not Is_Predefined_Dispatching_Operation
(Prim
) then
1717 Next_Formal
(Iface_Formal
);
1720 Next_Formal
(Formal
);
1723 Target_Formal
:= First_Formal
(Target
);
1724 Formal
:= First
(Formals
);
1725 while Present
(Formal
) loop
1727 -- If the parent is a constrained discriminated type, then the
1728 -- primitive operation will have been defined on a first subtype.
1729 -- For proper matching with controlling type, use base type.
1731 if Ekind
(Target_Formal
) = E_In_Parameter
1732 and then Ekind
(Etype
(Target_Formal
)) = E_Anonymous_Access_Type
1735 Base_Type
(Directly_Designated_Type
(Etype
(Target_Formal
)));
1737 Ftyp
:= Base_Type
(Etype
(Target_Formal
));
1740 -- For concurrent types, the relevant information is found in the
1741 -- Corresponding_Record_Type, rather than the type entity itself.
1743 if Is_Concurrent_Type
(Ftyp
) then
1744 Ftyp
:= Corresponding_Record_Type
(Ftyp
);
1747 if Ekind
(Target_Formal
) = E_In_Parameter
1748 and then Ekind
(Etype
(Target_Formal
)) = E_Anonymous_Access_Type
1749 and then Is_Controlling_Formal
(Target_Formal
)
1752 -- type T is access all <<type of the target formal>>
1753 -- S : Storage_Offset := Storage_Offset!(Formal)
1754 -- - Offset_To_Top (address!(Formal))
1757 Make_Full_Type_Declaration
(Loc
,
1758 Defining_Identifier
=> Make_Temporary
(Loc
, 'T'),
1760 Make_Access_To_Object_Definition
(Loc
,
1761 All_Present
=> True,
1762 Null_Exclusion_Present
=> False,
1763 Constant_Present
=> False,
1764 Subtype_Indication
=>
1765 New_Occurrence_Of
(Ftyp
, Loc
)));
1768 Unchecked_Convert_To
(RTE
(RE_Address
),
1769 New_Occurrence_Of
(Defining_Identifier
(Formal
), Loc
));
1771 if not RTE_Available
(RE_Offset_To_Top
) then
1773 Build_Offset_To_Top
(Loc
, New_Arg
);
1776 Make_Function_Call
(Loc
,
1777 Name
=> New_Occurrence_Of
(RTE
(RE_Offset_To_Top
), Loc
),
1778 Parameter_Associations
=> New_List
(New_Arg
));
1782 Make_Object_Declaration
(Loc
,
1783 Defining_Identifier
=> Make_Temporary
(Loc
, 'S'),
1784 Constant_Present
=> True,
1785 Object_Definition
=>
1786 New_Occurrence_Of
(RTE
(RE_Storage_Offset
), Loc
),
1788 Make_Op_Subtract
(Loc
,
1790 Unchecked_Convert_To
1791 (RTE
(RE_Storage_Offset
),
1793 (Defining_Identifier
(Formal
), Loc
)),
1797 Append_To
(Decl
, Decl_2
);
1798 Append_To
(Decl
, Decl_1
);
1800 -- Reference the new actual. Generate:
1804 Unchecked_Convert_To
1805 (Defining_Identifier
(Decl_2
),
1806 New_Occurrence_Of
(Defining_Identifier
(Decl_1
), Loc
)));
1808 elsif Is_Controlling_Formal
(Target_Formal
) then
1811 -- S1 : Storage_Offset := Storage_Offset!(Formal'Address)
1812 -- - Offset_To_Top (Formal'Address)
1813 -- S2 : Addr_Ptr := Addr_Ptr!(S1)
1816 Make_Attribute_Reference
(Loc
,
1818 New_Occurrence_Of
(Defining_Identifier
(Formal
), Loc
),
1822 if not RTE_Available
(RE_Offset_To_Top
) then
1824 Build_Offset_To_Top
(Loc
, New_Arg
);
1827 Make_Function_Call
(Loc
,
1828 Name
=> New_Occurrence_Of
(RTE
(RE_Offset_To_Top
), Loc
),
1829 Parameter_Associations
=> New_List
(New_Arg
));
1833 Make_Object_Declaration
(Loc
,
1834 Defining_Identifier
=> Make_Temporary
(Loc
, 'S'),
1835 Constant_Present
=> True,
1836 Object_Definition
=>
1837 New_Occurrence_Of
(RTE
(RE_Storage_Offset
), Loc
),
1839 Make_Op_Subtract
(Loc
,
1841 Unchecked_Convert_To
1842 (RTE
(RE_Storage_Offset
),
1843 Make_Attribute_Reference
(Loc
,
1846 (Defining_Identifier
(Formal
), Loc
),
1847 Attribute_Name
=> Name_Address
)),
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_Addr_Ptr
), Loc
),
1858 Unchecked_Convert_To
1860 New_Occurrence_Of
(Defining_Identifier
(Decl_1
), Loc
)));
1862 Append_To
(Decl
, Decl_1
);
1863 Append_To
(Decl
, Decl_2
);
1865 -- Reference the new actual, generate:
1866 -- Target_Formal (S2.all)
1869 Unchecked_Convert_To
(Ftyp
,
1870 Make_Explicit_Dereference
(Loc
,
1871 New_Occurrence_Of
(Defining_Identifier
(Decl_2
), Loc
))));
1873 -- Ensure proper matching of access types. Required to avoid
1874 -- reporting spurious errors.
1876 elsif Is_Access_Type
(Etype
(Target_Formal
)) then
1878 Unchecked_Convert_To
(Base_Type
(Etype
(Target_Formal
)),
1879 New_Occurrence_Of
(Defining_Identifier
(Formal
), Loc
)));
1881 -- No special management required for this actual
1885 New_Occurrence_Of
(Defining_Identifier
(Formal
), Loc
));
1888 Next_Formal
(Target_Formal
);
1892 Thunk_Id
:= Make_Temporary
(Loc
, 'T');
1893 Set_Ekind
(Thunk_Id
, Ekind
(Prim
));
1894 Set_Is_Thunk
(Thunk_Id
);
1895 Set_Convention
(Thunk_Id
, Convention
(Prim
));
1896 Set_Thunk_Entity
(Thunk_Id
, Target
);
1900 if Ekind
(Target
) = E_Procedure
then
1902 Make_Subprogram_Body
(Loc
,
1904 Make_Procedure_Specification
(Loc
,
1905 Defining_Unit_Name
=> Thunk_Id
,
1906 Parameter_Specifications
=> Formals
),
1907 Declarations
=> Decl
,
1908 Handled_Statement_Sequence
=>
1909 Make_Handled_Sequence_Of_Statements
(Loc
,
1910 Statements
=> New_List
(
1911 Make_Procedure_Call_Statement
(Loc
,
1912 Name
=> New_Occurrence_Of
(Target
, Loc
),
1913 Parameter_Associations
=> Actuals
))));
1917 else pragma Assert
(Ekind
(Target
) = E_Function
);
1919 Result_Def
: Node_Id
;
1920 Call_Node
: Node_Id
;
1924 Make_Function_Call
(Loc
,
1925 Name
=> New_Occurrence_Of
(Target
, Loc
),
1926 Parameter_Associations
=> Actuals
);
1928 if not Is_Interface
(Etype
(Prim
)) then
1929 Result_Def
:= New_Copy
(Result_Definition
(Parent
(Target
)));
1931 -- Thunk of function returning a class-wide interface object. No
1932 -- extra displacement needed since the displacement is generated
1933 -- in the return statement of Prim. Example:
1935 -- type Iface is interface ...
1936 -- function F (O : Iface) return Iface'Class;
1938 -- type T is new ... and Iface with ...
1939 -- function F (O : T) return Iface'Class;
1941 elsif Is_Class_Wide_Type
(Etype
(Prim
)) then
1942 Result_Def
:= New_Occurrence_Of
(Etype
(Prim
), Loc
);
1944 -- Thunk of function returning an interface object. Displacement
1947 -- type Iface is interface ...
1948 -- function F (O : Iface) return Iface;
1950 -- type T is new ... and Iface with ...
1951 -- function F (O : T) return T;
1955 New_Occurrence_Of
(Class_Wide_Type
(Etype
(Prim
)), Loc
);
1957 -- Adding implicit conversion to force the displacement of
1958 -- the pointer to the object to reference the corresponding
1959 -- secondary dispatch table.
1962 Make_Type_Conversion
(Loc
,
1964 New_Occurrence_Of
(Class_Wide_Type
(Etype
(Prim
)), Loc
),
1965 Expression
=> Relocate_Node
(Call_Node
));
1969 Make_Subprogram_Body
(Loc
,
1971 Make_Function_Specification
(Loc
,
1972 Defining_Unit_Name
=> Thunk_Id
,
1973 Parameter_Specifications
=> Formals
,
1974 Result_Definition
=> Result_Def
),
1975 Declarations
=> Decl
,
1976 Handled_Statement_Sequence
=>
1977 Make_Handled_Sequence_Of_Statements
(Loc
,
1978 Statements
=> New_List
(
1979 Make_Simple_Return_Statement
(Loc
, Call_Node
))));
1982 end Expand_Interface_Thunk
;
1984 --------------------------
1985 -- Has_CPP_Constructors --
1986 --------------------------
1988 function Has_CPP_Constructors
(Typ
: Entity_Id
) return Boolean is
1992 -- Look for the constructor entities
1994 E
:= Next_Entity
(Typ
);
1995 while Present
(E
) loop
1996 if Ekind
(E
) = E_Function
and then Is_Constructor
(E
) then
2004 end Has_CPP_Constructors
;
2010 function Has_DT
(Typ
: Entity_Id
) return Boolean is
2012 return not Is_Interface
(Typ
)
2013 and then not Restriction_Active
(No_Dispatching_Calls
);
2016 ----------------------------------
2017 -- Is_Expanded_Dispatching_Call --
2018 ----------------------------------
2020 function Is_Expanded_Dispatching_Call
(N
: Node_Id
) return Boolean is
2022 return Nkind
(N
) in N_Subprogram_Call
2023 and then Nkind
(Name
(N
)) = N_Explicit_Dereference
2024 and then Is_Dispatch_Table_Entity
(Etype
(Name
(N
)));
2025 end Is_Expanded_Dispatching_Call
;
2027 -----------------------------------------
2028 -- Is_Predefined_Dispatching_Operation --
2029 -----------------------------------------
2031 function Is_Predefined_Dispatching_Operation
2032 (E
: Entity_Id
) return Boolean
2034 TSS_Name
: TSS_Name_Type
;
2037 if not Is_Dispatching_Operation
(E
) then
2041 Get_Name_String
(Chars
(E
));
2043 -- Most predefined primitives have internally generated names. Equality
2044 -- must be treated differently; the predefined operation is recognized
2045 -- as a homogeneous binary operator that returns Boolean.
2047 if Name_Len
> TSS_Name_Type
'Last then
2048 TSS_Name
:= TSS_Name_Type
(Name_Buffer
(Name_Len
- TSS_Name
'Length + 1
2050 if Chars
(E
) = Name_uSize
2051 or else TSS_Name
= TSS_Stream_Read
2052 or else TSS_Name
= TSS_Stream_Write
2053 or else TSS_Name
= TSS_Stream_Input
2054 or else TSS_Name
= TSS_Stream_Output
2056 (Chars
(E
) = Name_Op_Eq
2057 and then Etype
(First_Formal
(E
)) = Etype
(Last_Formal
(E
)))
2058 or else Chars
(E
) = Name_uAssign
2059 or else TSS_Name
= TSS_Deep_Adjust
2060 or else TSS_Name
= TSS_Deep_Finalize
2061 or else Is_Predefined_Interface_Primitive
(E
)
2068 end Is_Predefined_Dispatching_Operation
;
2070 ---------------------------------------
2071 -- Is_Predefined_Internal_Operation --
2072 ---------------------------------------
2074 function Is_Predefined_Internal_Operation
2075 (E
: Entity_Id
) return Boolean
2077 TSS_Name
: TSS_Name_Type
;
2080 if not Is_Dispatching_Operation
(E
) then
2084 Get_Name_String
(Chars
(E
));
2086 -- Most predefined primitives have internally generated names. Equality
2087 -- must be treated differently; the predefined operation is recognized
2088 -- as a homogeneous binary operator that returns Boolean.
2090 if Name_Len
> TSS_Name_Type
'Last then
2093 (Name_Buffer
(Name_Len
- TSS_Name
'Length + 1 .. Name_Len
));
2095 if Nam_In
(Chars
(E
), Name_uSize
, Name_uAssign
)
2097 (Chars
(E
) = Name_Op_Eq
2098 and then Etype
(First_Formal
(E
)) = Etype
(Last_Formal
(E
)))
2099 or else TSS_Name
= TSS_Deep_Adjust
2100 or else TSS_Name
= TSS_Deep_Finalize
2101 or else Is_Predefined_Interface_Primitive
(E
)
2108 end Is_Predefined_Internal_Operation
;
2110 -------------------------------------
2111 -- Is_Predefined_Dispatching_Alias --
2112 -------------------------------------
2114 function Is_Predefined_Dispatching_Alias
(Prim
: Entity_Id
) return Boolean
2117 return not Is_Predefined_Dispatching_Operation
(Prim
)
2118 and then Present
(Alias
(Prim
))
2119 and then Is_Predefined_Dispatching_Operation
(Ultimate_Alias
(Prim
));
2120 end Is_Predefined_Dispatching_Alias
;
2122 ---------------------------------------
2123 -- Is_Predefined_Interface_Primitive --
2124 ---------------------------------------
2126 function Is_Predefined_Interface_Primitive
(E
: Entity_Id
) return Boolean is
2128 -- In VM targets we don't restrict the functionality of this test to
2129 -- compiling in Ada 2005 mode since in VM targets any tagged type has
2130 -- these primitives.
2132 return (Ada_Version
>= Ada_2005
or else not Tagged_Type_Expansion
)
2133 and then Nam_In
(Chars
(E
), Name_uDisp_Asynchronous_Select
,
2134 Name_uDisp_Conditional_Select
,
2135 Name_uDisp_Get_Prim_Op_Kind
,
2136 Name_uDisp_Get_Task_Id
,
2138 Name_uDisp_Timed_Select
);
2139 end Is_Predefined_Interface_Primitive
;
2141 ----------------------------------------
2142 -- Make_Disp_Asynchronous_Select_Body --
2143 ----------------------------------------
2145 -- For interface types, generate:
2147 -- procedure _Disp_Asynchronous_Select
2148 -- (T : in out <Typ>;
2150 -- P : System.Address;
2151 -- B : out System.Storage_Elements.Dummy_Communication_Block;
2156 -- C := Ada.Tags.POK_Function;
2157 -- end _Disp_Asynchronous_Select;
2159 -- For protected types, generate:
2161 -- procedure _Disp_Asynchronous_Select
2162 -- (T : in out <Typ>;
2164 -- P : System.Address;
2165 -- B : out System.Storage_Elements.Dummy_Communication_Block;
2169 -- Ada.Tags.Get_Entry_Index (Ada.Tags.Tag (<Typ>VP, S));
2170 -- Bnn : System.Tasking.Protected_Objects.Operations.
2171 -- Communication_Block;
2173 -- System.Tasking.Protected_Objects.Operations.Protected_Entry_Call
2174 -- (T._object'Access,
2175 -- System.Tasking.Protected_Objects.Protected_Entry_Index (I),
2177 -- System.Tasking.Asynchronous_Call,
2179 -- B := System.Storage_Elements.Dummy_Communication_Block (Bnn);
2180 -- end _Disp_Asynchronous_Select;
2182 -- For task types, generate:
2184 -- procedure _Disp_Asynchronous_Select
2185 -- (T : in out <Typ>;
2187 -- P : System.Address;
2188 -- B : out System.Storage_Elements.Dummy_Communication_Block;
2192 -- Ada.Tags.Get_Entry_Index (Ada.Tags.Tag (<Typ>VP, S));
2194 -- System.Tasking.Rendezvous.Task_Entry_Call
2196 -- System.Tasking.Task_Entry_Index (I),
2198 -- System.Tasking.Asynchronous_Call,
2200 -- end _Disp_Asynchronous_Select;
2202 function Make_Disp_Asynchronous_Select_Body
2203 (Typ
: Entity_Id
) return Node_Id
2205 Com_Block
: Entity_Id
;
2206 Conc_Typ
: Entity_Id
:= Empty
;
2207 Decls
: constant List_Id
:= New_List
;
2208 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
2210 Stmts
: constant List_Id
:= New_List
;
2214 pragma Assert
(not Restriction_Active
(No_Dispatching_Calls
));
2216 -- Null body is generated for interface types
2218 if Is_Interface
(Typ
) then
2220 Make_Subprogram_Body
(Loc
,
2222 Make_Disp_Asynchronous_Select_Spec
(Typ
),
2223 Declarations
=> New_List
,
2224 Handled_Statement_Sequence
=>
2225 Make_Handled_Sequence_Of_Statements
(Loc
,
2227 Make_Assignment_Statement
(Loc
,
2228 Name
=> Make_Identifier
(Loc
, Name_uF
),
2229 Expression
=> New_Occurrence_Of
(Standard_False
, Loc
)))));
2232 if Is_Concurrent_Record_Type
(Typ
) then
2233 Conc_Typ
:= Corresponding_Concurrent_Type
(Typ
);
2237 -- Ada.Tags.Get_Entry_Index (Ada.Tags.Tag! (<type>VP), S);
2239 -- where I will be used to capture the entry index of the primitive
2240 -- wrapper at position S.
2242 if Tagged_Type_Expansion
then
2244 Unchecked_Convert_To
(RTE
(RE_Tag
),
2246 (Node
(First_Elmt
(Access_Disp_Table
(Typ
))), Loc
));
2249 Make_Attribute_Reference
(Loc
,
2250 Prefix
=> New_Occurrence_Of
(Typ
, Loc
),
2251 Attribute_Name
=> Name_Tag
);
2255 Make_Object_Declaration
(Loc
,
2256 Defining_Identifier
=>
2257 Make_Defining_Identifier
(Loc
, Name_uI
),
2258 Object_Definition
=>
2259 New_Occurrence_Of
(Standard_Integer
, Loc
),
2261 Make_Function_Call
(Loc
,
2263 New_Occurrence_Of
(RTE
(RE_Get_Entry_Index
), Loc
),
2264 Parameter_Associations
=>
2265 New_List
(Tag_Node
, Make_Identifier
(Loc
, Name_uS
)))));
2267 if Ekind
(Conc_Typ
) = E_Protected_Type
then
2270 -- Bnn : Communication_Block;
2272 Com_Block
:= Make_Temporary
(Loc
, 'B');
2274 Make_Object_Declaration
(Loc
,
2275 Defining_Identifier
=> Com_Block
,
2276 Object_Definition
=>
2277 New_Occurrence_Of
(RTE
(RE_Communication_Block
), Loc
)));
2279 -- Build T._object'Access for calls below
2282 Make_Attribute_Reference
(Loc
,
2283 Attribute_Name
=> Name_Unchecked_Access
,
2285 Make_Selected_Component
(Loc
,
2286 Prefix
=> Make_Identifier
(Loc
, Name_uT
),
2287 Selector_Name
=> Make_Identifier
(Loc
, Name_uObject
)));
2289 case Corresponding_Runtime_Package
(Conc_Typ
) is
2290 when System_Tasking_Protected_Objects_Entries
=>
2293 -- Protected_Entry_Call
2294 -- (T._object'Access, -- Object
2295 -- Protected_Entry_Index! (I), -- E
2296 -- P, -- Uninterpreted_Data
2297 -- Asynchronous_Call, -- Mode
2298 -- Bnn); -- Communication_Block
2300 -- where T is the protected object, I is the entry index, P
2301 -- is the wrapped parameters and B is the name of the
2302 -- communication block.
2305 Make_Procedure_Call_Statement
(Loc
,
2307 New_Occurrence_Of
(RTE
(RE_Protected_Entry_Call
), Loc
),
2308 Parameter_Associations
=>
2312 Make_Unchecked_Type_Conversion
(Loc
, -- entry index
2315 (RTE
(RE_Protected_Entry_Index
), Loc
),
2316 Expression
=> Make_Identifier
(Loc
, Name_uI
)),
2318 Make_Identifier
(Loc
, Name_uP
), -- parameter block
2319 New_Occurrence_Of
-- Asynchronous_Call
2320 (RTE
(RE_Asynchronous_Call
), Loc
),
2321 New_Occurrence_Of
-- comm block
2322 (Com_Block
, Loc
))));
2325 raise Program_Error
;
2329 -- B := Dummy_Communication_Block (Bnn);
2332 Make_Assignment_Statement
(Loc
,
2333 Name
=> Make_Identifier
(Loc
, Name_uB
),
2335 Make_Unchecked_Type_Conversion
(Loc
,
2338 (RTE
(RE_Dummy_Communication_Block
), Loc
),
2339 Expression
=> New_Occurrence_Of
(Com_Block
, Loc
))));
2345 Make_Assignment_Statement
(Loc
,
2346 Name
=> Make_Identifier
(Loc
, Name_uF
),
2347 Expression
=> New_Occurrence_Of
(Standard_False
, Loc
)));
2350 pragma Assert
(Ekind
(Conc_Typ
) = E_Task_Type
);
2354 -- (T._task_id, -- Acceptor
2355 -- Task_Entry_Index! (I), -- E
2356 -- P, -- Uninterpreted_Data
2357 -- Asynchronous_Call, -- Mode
2358 -- F); -- Rendezvous_Successful
2360 -- where T is the task object, I is the entry index, P is the
2361 -- wrapped parameters and F is the status flag.
2364 Make_Procedure_Call_Statement
(Loc
,
2366 New_Occurrence_Of
(RTE
(RE_Task_Entry_Call
), Loc
),
2367 Parameter_Associations
=>
2369 Make_Selected_Component
(Loc
, -- T._task_id
2370 Prefix
=> Make_Identifier
(Loc
, Name_uT
),
2371 Selector_Name
=> Make_Identifier
(Loc
, Name_uTask_Id
)),
2373 Make_Unchecked_Type_Conversion
(Loc
, -- entry index
2375 New_Occurrence_Of
(RTE
(RE_Task_Entry_Index
), Loc
),
2376 Expression
=> Make_Identifier
(Loc
, Name_uI
)),
2378 Make_Identifier
(Loc
, Name_uP
), -- parameter block
2379 New_Occurrence_Of
-- Asynchronous_Call
2380 (RTE
(RE_Asynchronous_Call
), Loc
),
2381 Make_Identifier
(Loc
, Name_uF
)))); -- status flag
2385 -- Ensure that the statements list is non-empty
2388 Make_Assignment_Statement
(Loc
,
2389 Name
=> Make_Identifier
(Loc
, Name_uF
),
2390 Expression
=> New_Occurrence_Of
(Standard_False
, Loc
)));
2394 Make_Subprogram_Body
(Loc
,
2396 Make_Disp_Asynchronous_Select_Spec
(Typ
),
2397 Declarations
=> Decls
,
2398 Handled_Statement_Sequence
=>
2399 Make_Handled_Sequence_Of_Statements
(Loc
, Stmts
));
2400 end Make_Disp_Asynchronous_Select_Body
;
2402 ----------------------------------------
2403 -- Make_Disp_Asynchronous_Select_Spec --
2404 ----------------------------------------
2406 function Make_Disp_Asynchronous_Select_Spec
2407 (Typ
: Entity_Id
) return Node_Id
2409 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
2410 Def_Id
: constant Node_Id
:=
2411 Make_Defining_Identifier
(Loc
,
2412 Name_uDisp_Asynchronous_Select
);
2413 Params
: constant List_Id
:= New_List
;
2416 pragma Assert
(not Restriction_Active
(No_Dispatching_Calls
));
2418 -- T : in out Typ; -- Object parameter
2419 -- S : Integer; -- Primitive operation slot
2420 -- P : Address; -- Wrapped parameters
2421 -- B : out Dummy_Communication_Block; -- Communication block dummy
2422 -- F : out Boolean; -- Status flag
2424 Append_List_To
(Params
, New_List
(
2426 Make_Parameter_Specification
(Loc
,
2427 Defining_Identifier
=> Make_Defining_Identifier
(Loc
, Name_uT
),
2428 Parameter_Type
=> New_Occurrence_Of
(Typ
, Loc
),
2430 Out_Present
=> True),
2432 Make_Parameter_Specification
(Loc
,
2433 Defining_Identifier
=> Make_Defining_Identifier
(Loc
, Name_uS
),
2434 Parameter_Type
=> New_Occurrence_Of
(Standard_Integer
, Loc
)),
2436 Make_Parameter_Specification
(Loc
,
2437 Defining_Identifier
=> Make_Defining_Identifier
(Loc
, Name_uP
),
2438 Parameter_Type
=> New_Occurrence_Of
(RTE
(RE_Address
), Loc
)),
2440 Make_Parameter_Specification
(Loc
,
2441 Defining_Identifier
=> Make_Defining_Identifier
(Loc
, Name_uB
),
2443 New_Occurrence_Of
(RTE
(RE_Dummy_Communication_Block
), Loc
),
2444 Out_Present
=> True),
2446 Make_Parameter_Specification
(Loc
,
2447 Defining_Identifier
=> Make_Defining_Identifier
(Loc
, Name_uF
),
2448 Parameter_Type
=> New_Occurrence_Of
(Standard_Boolean
, Loc
),
2449 Out_Present
=> True)));
2452 Make_Procedure_Specification
(Loc
,
2453 Defining_Unit_Name
=> Def_Id
,
2454 Parameter_Specifications
=> Params
);
2455 end Make_Disp_Asynchronous_Select_Spec
;
2457 ---------------------------------------
2458 -- Make_Disp_Conditional_Select_Body --
2459 ---------------------------------------
2461 -- For interface types, generate:
2463 -- procedure _Disp_Conditional_Select
2464 -- (T : in out <Typ>;
2466 -- P : System.Address;
2467 -- C : out Ada.Tags.Prim_Op_Kind;
2472 -- C := Ada.Tags.POK_Function;
2473 -- end _Disp_Conditional_Select;
2475 -- For protected types, generate:
2477 -- procedure _Disp_Conditional_Select
2478 -- (T : in out <Typ>;
2480 -- P : System.Address;
2481 -- C : out Ada.Tags.Prim_Op_Kind;
2485 -- Bnn : System.Tasking.Protected_Objects.Operations.
2486 -- Communication_Block;
2489 -- C := Ada.Tags.Get_Prim_Op_Kind (Ada.Tags.Tag (<Typ>VP, S));
2491 -- if C = Ada.Tags.POK_Procedure
2492 -- or else C = Ada.Tags.POK_Protected_Procedure
2493 -- or else C = Ada.Tags.POK_Task_Procedure
2499 -- I := Ada.Tags.Get_Entry_Index (Ada.Tags.Tag (<Typ>VP, S));
2500 -- System.Tasking.Protected_Objects.Operations.Protected_Entry_Call
2501 -- (T.object'Access,
2502 -- System.Tasking.Protected_Objects.Protected_Entry_Index (I),
2504 -- System.Tasking.Conditional_Call,
2506 -- F := not Cancelled (Bnn);
2507 -- end _Disp_Conditional_Select;
2509 -- For task types, generate:
2511 -- procedure _Disp_Conditional_Select
2512 -- (T : in out <Typ>;
2514 -- P : System.Address;
2515 -- C : out Ada.Tags.Prim_Op_Kind;
2521 -- I := Ada.Tags.Get_Entry_Index (Ada.Tags.Tag (<Typ>VP, S));
2522 -- System.Tasking.Rendezvous.Task_Entry_Call
2524 -- System.Tasking.Task_Entry_Index (I),
2526 -- System.Tasking.Conditional_Call,
2528 -- end _Disp_Conditional_Select;
2530 function Make_Disp_Conditional_Select_Body
2531 (Typ
: Entity_Id
) return Node_Id
2533 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
2534 Blk_Nam
: Entity_Id
;
2535 Conc_Typ
: Entity_Id
:= Empty
;
2536 Decls
: constant List_Id
:= New_List
;
2538 Stmts
: constant List_Id
:= New_List
;
2542 pragma Assert
(not Restriction_Active
(No_Dispatching_Calls
));
2544 -- Null body is generated for interface types
2546 if Is_Interface
(Typ
) then
2548 Make_Subprogram_Body
(Loc
,
2550 Make_Disp_Conditional_Select_Spec
(Typ
),
2551 Declarations
=> No_List
,
2552 Handled_Statement_Sequence
=>
2553 Make_Handled_Sequence_Of_Statements
(Loc
,
2554 New_List
(Make_Assignment_Statement
(Loc
,
2555 Name
=> Make_Identifier
(Loc
, Name_uF
),
2556 Expression
=> New_Occurrence_Of
(Standard_False
, Loc
)))));
2559 if Is_Concurrent_Record_Type
(Typ
) then
2560 Conc_Typ
:= Corresponding_Concurrent_Type
(Typ
);
2565 -- where I will be used to capture the entry index of the primitive
2566 -- wrapper at position S.
2569 Make_Object_Declaration
(Loc
,
2570 Defining_Identifier
=> Make_Defining_Identifier
(Loc
, Name_uI
),
2571 Object_Definition
=>
2572 New_Occurrence_Of
(Standard_Integer
, Loc
)));
2575 -- C := Ada.Tags.Get_Prim_Op_Kind (Ada.Tags.Tag! (<type>VP), S);
2577 -- if C = POK_Procedure
2578 -- or else C = POK_Protected_Procedure
2579 -- or else C = POK_Task_Procedure;
2585 Build_Common_Dispatching_Select_Statements
(Typ
, Stmts
);
2588 -- Bnn : Communication_Block;
2590 -- where Bnn is the name of the communication block used in the
2591 -- call to Protected_Entry_Call.
2593 Blk_Nam
:= Make_Temporary
(Loc
, 'B');
2595 Make_Object_Declaration
(Loc
,
2596 Defining_Identifier
=> Blk_Nam
,
2597 Object_Definition
=>
2598 New_Occurrence_Of
(RTE
(RE_Communication_Block
), Loc
)));
2601 -- I := Ada.Tags.Get_Entry_Index (Ada.Tags.Tag! (<type>VP), S);
2603 -- I is the entry index and S is the dispatch table slot
2605 if Tagged_Type_Expansion
then
2607 Unchecked_Convert_To
(RTE
(RE_Tag
),
2609 (Node
(First_Elmt
(Access_Disp_Table
(Typ
))), Loc
));
2613 Make_Attribute_Reference
(Loc
,
2614 Prefix
=> New_Occurrence_Of
(Typ
, Loc
),
2615 Attribute_Name
=> Name_Tag
);
2619 Make_Assignment_Statement
(Loc
,
2620 Name
=> Make_Identifier
(Loc
, Name_uI
),
2622 Make_Function_Call
(Loc
,
2624 New_Occurrence_Of
(RTE
(RE_Get_Entry_Index
), Loc
),
2625 Parameter_Associations
=> New_List
(
2627 Make_Identifier
(Loc
, Name_uS
)))));
2629 if Ekind
(Conc_Typ
) = E_Protected_Type
then
2631 Obj_Ref
:= -- T._object'Access
2632 Make_Attribute_Reference
(Loc
,
2633 Attribute_Name
=> Name_Unchecked_Access
,
2635 Make_Selected_Component
(Loc
,
2636 Prefix
=> Make_Identifier
(Loc
, Name_uT
),
2637 Selector_Name
=> Make_Identifier
(Loc
, Name_uObject
)));
2639 case Corresponding_Runtime_Package
(Conc_Typ
) is
2640 when System_Tasking_Protected_Objects_Entries
=>
2643 -- Protected_Entry_Call
2644 -- (T._object'Access, -- Object
2645 -- Protected_Entry_Index! (I), -- E
2646 -- P, -- Uninterpreted_Data
2647 -- Conditional_Call, -- Mode
2650 -- where T is the protected object, I is the entry index, P
2651 -- are the wrapped parameters and Bnn is the name of the
2652 -- communication block.
2655 Make_Procedure_Call_Statement
(Loc
,
2657 New_Occurrence_Of
(RTE
(RE_Protected_Entry_Call
), Loc
),
2658 Parameter_Associations
=> New_List
(
2661 Make_Unchecked_Type_Conversion
(Loc
, -- entry index
2664 (RTE
(RE_Protected_Entry_Index
), Loc
),
2665 Expression
=> Make_Identifier
(Loc
, Name_uI
)),
2667 Make_Identifier
(Loc
, Name_uP
), -- parameter block
2669 New_Occurrence_Of
-- Conditional_Call
2670 (RTE
(RE_Conditional_Call
), Loc
),
2671 New_Occurrence_Of
-- Bnn
2674 when System_Tasking_Protected_Objects_Single_Entry
=>
2676 -- If we are compiling for a restricted run-time, the call
2677 -- uses the simpler form.
2680 Make_Procedure_Call_Statement
(Loc
,
2683 (RTE
(RE_Protected_Single_Entry_Call
), Loc
),
2684 Parameter_Associations
=> New_List
(
2687 Make_Attribute_Reference
(Loc
,
2688 Prefix
=> Make_Identifier
(Loc
, Name_uP
),
2689 Attribute_Name
=> Name_Address
),
2692 (RTE
(RE_Conditional_Call
), Loc
))));
2694 raise Program_Error
;
2698 -- F := not Cancelled (Bnn);
2700 -- where F is the success flag. The status of Cancelled is negated
2701 -- in order to match the behaviour of the version for task types.
2704 Make_Assignment_Statement
(Loc
,
2705 Name
=> Make_Identifier
(Loc
, Name_uF
),
2709 Make_Function_Call
(Loc
,
2711 New_Occurrence_Of
(RTE
(RE_Cancelled
), Loc
),
2712 Parameter_Associations
=> New_List
(
2713 New_Occurrence_Of
(Blk_Nam
, Loc
))))));
2715 pragma Assert
(Ekind
(Conc_Typ
) = E_Task_Type
);
2719 -- (T._task_id, -- Acceptor
2720 -- Task_Entry_Index! (I), -- E
2721 -- P, -- Uninterpreted_Data
2722 -- Conditional_Call, -- Mode
2723 -- F); -- Rendezvous_Successful
2725 -- where T is the task object, I is the entry index, P are the
2726 -- wrapped parameters and F is the status flag.
2729 Make_Procedure_Call_Statement
(Loc
,
2731 New_Occurrence_Of
(RTE
(RE_Task_Entry_Call
), Loc
),
2732 Parameter_Associations
=> New_List
(
2734 Make_Selected_Component
(Loc
, -- T._task_id
2735 Prefix
=> Make_Identifier
(Loc
, Name_uT
),
2736 Selector_Name
=> Make_Identifier
(Loc
, Name_uTask_Id
)),
2738 Make_Unchecked_Type_Conversion
(Loc
, -- entry index
2740 New_Occurrence_Of
(RTE
(RE_Task_Entry_Index
), Loc
),
2741 Expression
=> Make_Identifier
(Loc
, Name_uI
)),
2743 Make_Identifier
(Loc
, Name_uP
), -- parameter block
2744 New_Occurrence_Of
-- Conditional_Call
2745 (RTE
(RE_Conditional_Call
), Loc
),
2746 Make_Identifier
(Loc
, Name_uF
)))); -- status flag
2750 -- Initialize out parameters
2753 Make_Assignment_Statement
(Loc
,
2754 Name
=> Make_Identifier
(Loc
, Name_uF
),
2755 Expression
=> New_Occurrence_Of
(Standard_False
, Loc
)));
2757 Make_Assignment_Statement
(Loc
,
2758 Name
=> Make_Identifier
(Loc
, Name_uC
),
2759 Expression
=> New_Occurrence_Of
(RTE
(RE_POK_Function
), Loc
)));
2763 Make_Subprogram_Body
(Loc
,
2765 Make_Disp_Conditional_Select_Spec
(Typ
),
2766 Declarations
=> Decls
,
2767 Handled_Statement_Sequence
=>
2768 Make_Handled_Sequence_Of_Statements
(Loc
, Stmts
));
2769 end Make_Disp_Conditional_Select_Body
;
2771 ---------------------------------------
2772 -- Make_Disp_Conditional_Select_Spec --
2773 ---------------------------------------
2775 function Make_Disp_Conditional_Select_Spec
2776 (Typ
: Entity_Id
) return Node_Id
2778 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
2779 Def_Id
: constant Node_Id
:=
2780 Make_Defining_Identifier
(Loc
,
2781 Name_uDisp_Conditional_Select
);
2782 Params
: constant List_Id
:= New_List
;
2785 pragma Assert
(not Restriction_Active
(No_Dispatching_Calls
));
2787 -- T : in out Typ; -- Object parameter
2788 -- S : Integer; -- Primitive operation slot
2789 -- P : Address; -- Wrapped parameters
2790 -- C : out Prim_Op_Kind; -- Call kind
2791 -- F : out Boolean; -- Status flag
2793 Append_List_To
(Params
, New_List
(
2795 Make_Parameter_Specification
(Loc
,
2796 Defining_Identifier
=> Make_Defining_Identifier
(Loc
, Name_uT
),
2797 Parameter_Type
=> New_Occurrence_Of
(Typ
, Loc
),
2799 Out_Present
=> True),
2801 Make_Parameter_Specification
(Loc
,
2802 Defining_Identifier
=> Make_Defining_Identifier
(Loc
, Name_uS
),
2803 Parameter_Type
=> New_Occurrence_Of
(Standard_Integer
, Loc
)),
2805 Make_Parameter_Specification
(Loc
,
2806 Defining_Identifier
=> Make_Defining_Identifier
(Loc
, Name_uP
),
2807 Parameter_Type
=> New_Occurrence_Of
(RTE
(RE_Address
), Loc
)),
2809 Make_Parameter_Specification
(Loc
,
2810 Defining_Identifier
=> Make_Defining_Identifier
(Loc
, Name_uC
),
2812 New_Occurrence_Of
(RTE
(RE_Prim_Op_Kind
), Loc
),
2813 Out_Present
=> True),
2815 Make_Parameter_Specification
(Loc
,
2816 Defining_Identifier
=> Make_Defining_Identifier
(Loc
, Name_uF
),
2817 Parameter_Type
=> New_Occurrence_Of
(Standard_Boolean
, Loc
),
2818 Out_Present
=> True)));
2821 Make_Procedure_Specification
(Loc
,
2822 Defining_Unit_Name
=> Def_Id
,
2823 Parameter_Specifications
=> Params
);
2824 end Make_Disp_Conditional_Select_Spec
;
2826 -------------------------------------
2827 -- Make_Disp_Get_Prim_Op_Kind_Body --
2828 -------------------------------------
2830 function Make_Disp_Get_Prim_Op_Kind_Body
(Typ
: Entity_Id
) return Node_Id
is
2831 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
2835 pragma Assert
(not Restriction_Active
(No_Dispatching_Calls
));
2837 if Is_Interface
(Typ
) then
2839 Make_Subprogram_Body
(Loc
,
2841 Make_Disp_Get_Prim_Op_Kind_Spec
(Typ
),
2842 Declarations
=> New_List
,
2843 Handled_Statement_Sequence
=>
2844 Make_Handled_Sequence_Of_Statements
(Loc
,
2845 New_List
(Make_Null_Statement
(Loc
))));
2849 -- C := get_prim_op_kind (tag! (<type>VP), S);
2851 -- where C is the out parameter capturing the call kind and S is the
2852 -- dispatch table slot number.
2854 if Tagged_Type_Expansion
then
2856 Unchecked_Convert_To
(RTE
(RE_Tag
),
2858 (Node
(First_Elmt
(Access_Disp_Table
(Typ
))), Loc
));
2862 Make_Attribute_Reference
(Loc
,
2863 Prefix
=> New_Occurrence_Of
(Typ
, Loc
),
2864 Attribute_Name
=> Name_Tag
);
2868 Make_Subprogram_Body
(Loc
,
2870 Make_Disp_Get_Prim_Op_Kind_Spec
(Typ
),
2871 Declarations
=> New_List
,
2872 Handled_Statement_Sequence
=>
2873 Make_Handled_Sequence_Of_Statements
(Loc
,
2875 Make_Assignment_Statement
(Loc
,
2876 Name
=> Make_Identifier
(Loc
, Name_uC
),
2878 Make_Function_Call
(Loc
,
2880 New_Occurrence_Of
(RTE
(RE_Get_Prim_Op_Kind
), Loc
),
2881 Parameter_Associations
=> New_List
(
2883 Make_Identifier
(Loc
, Name_uS
)))))));
2884 end Make_Disp_Get_Prim_Op_Kind_Body
;
2886 -------------------------------------
2887 -- Make_Disp_Get_Prim_Op_Kind_Spec --
2888 -------------------------------------
2890 function Make_Disp_Get_Prim_Op_Kind_Spec
2891 (Typ
: Entity_Id
) return Node_Id
2893 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
2894 Def_Id
: constant Node_Id
:=
2895 Make_Defining_Identifier
(Loc
, Name_uDisp_Get_Prim_Op_Kind
);
2896 Params
: constant List_Id
:= New_List
;
2899 pragma Assert
(not Restriction_Active
(No_Dispatching_Calls
));
2901 -- T : in out Typ; -- Object parameter
2902 -- S : Integer; -- Primitive operation slot
2903 -- C : out Prim_Op_Kind; -- Call kind
2905 Append_List_To
(Params
, New_List
(
2907 Make_Parameter_Specification
(Loc
,
2908 Defining_Identifier
=> Make_Defining_Identifier
(Loc
, Name_uT
),
2909 Parameter_Type
=> New_Occurrence_Of
(Typ
, Loc
),
2911 Out_Present
=> True),
2913 Make_Parameter_Specification
(Loc
,
2914 Defining_Identifier
=> Make_Defining_Identifier
(Loc
, Name_uS
),
2915 Parameter_Type
=> New_Occurrence_Of
(Standard_Integer
, Loc
)),
2917 Make_Parameter_Specification
(Loc
,
2918 Defining_Identifier
=> Make_Defining_Identifier
(Loc
, Name_uC
),
2920 New_Occurrence_Of
(RTE
(RE_Prim_Op_Kind
), Loc
),
2921 Out_Present
=> True)));
2924 Make_Procedure_Specification
(Loc
,
2925 Defining_Unit_Name
=> Def_Id
,
2926 Parameter_Specifications
=> Params
);
2927 end Make_Disp_Get_Prim_Op_Kind_Spec
;
2929 --------------------------------
2930 -- Make_Disp_Get_Task_Id_Body --
2931 --------------------------------
2933 function Make_Disp_Get_Task_Id_Body
2934 (Typ
: Entity_Id
) return Node_Id
2936 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
2940 pragma Assert
(not Restriction_Active
(No_Dispatching_Calls
));
2942 if Is_Concurrent_Record_Type
(Typ
)
2943 and then Ekind
(Corresponding_Concurrent_Type
(Typ
)) = E_Task_Type
2946 -- return To_Address (_T._task_id);
2949 Make_Simple_Return_Statement
(Loc
,
2951 Make_Unchecked_Type_Conversion
(Loc
,
2952 Subtype_Mark
=> New_Occurrence_Of
(RTE
(RE_Address
), Loc
),
2954 Make_Selected_Component
(Loc
,
2955 Prefix
=> Make_Identifier
(Loc
, Name_uT
),
2956 Selector_Name
=> Make_Identifier
(Loc
, Name_uTask_Id
))));
2958 -- A null body is constructed for non-task types
2962 -- return Null_Address;
2965 Make_Simple_Return_Statement
(Loc
,
2966 Expression
=> New_Occurrence_Of
(RTE
(RE_Null_Address
), Loc
));
2970 Make_Subprogram_Body
(Loc
,
2971 Specification
=> Make_Disp_Get_Task_Id_Spec
(Typ
),
2972 Declarations
=> New_List
,
2973 Handled_Statement_Sequence
=>
2974 Make_Handled_Sequence_Of_Statements
(Loc
, New_List
(Ret
)));
2975 end Make_Disp_Get_Task_Id_Body
;
2977 --------------------------------
2978 -- Make_Disp_Get_Task_Id_Spec --
2979 --------------------------------
2981 function Make_Disp_Get_Task_Id_Spec
2982 (Typ
: Entity_Id
) return Node_Id
2984 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
2987 pragma Assert
(not Restriction_Active
(No_Dispatching_Calls
));
2990 Make_Function_Specification
(Loc
,
2991 Defining_Unit_Name
=>
2992 Make_Defining_Identifier
(Loc
, Name_uDisp_Get_Task_Id
),
2993 Parameter_Specifications
=> New_List
(
2994 Make_Parameter_Specification
(Loc
,
2995 Defining_Identifier
=> Make_Defining_Identifier
(Loc
, Name_uT
),
2996 Parameter_Type
=> New_Occurrence_Of
(Typ
, Loc
))),
2997 Result_Definition
=>
2998 New_Occurrence_Of
(RTE
(RE_Address
), Loc
));
2999 end Make_Disp_Get_Task_Id_Spec
;
3001 ----------------------------
3002 -- Make_Disp_Requeue_Body --
3003 ----------------------------
3005 function Make_Disp_Requeue_Body
3006 (Typ
: Entity_Id
) return Node_Id
3008 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
3009 Conc_Typ
: Entity_Id
:= Empty
;
3010 Stmts
: constant List_Id
:= New_List
;
3013 pragma Assert
(not Restriction_Active
(No_Dispatching_Calls
));
3015 -- Null body is generated for interface types and non-concurrent
3018 if Is_Interface
(Typ
)
3019 or else not Is_Concurrent_Record_Type
(Typ
)
3022 Make_Subprogram_Body
(Loc
,
3023 Specification
=> Make_Disp_Requeue_Spec
(Typ
),
3024 Declarations
=> No_List
,
3025 Handled_Statement_Sequence
=>
3026 Make_Handled_Sequence_Of_Statements
(Loc
,
3027 New_List
(Make_Null_Statement
(Loc
))));
3030 Conc_Typ
:= Corresponding_Concurrent_Type
(Typ
);
3032 if Ekind
(Conc_Typ
) = E_Protected_Type
then
3034 -- Generate statements:
3036 -- System.Tasking.Protected_Objects.Operations.
3037 -- Requeue_Protected_Entry
3038 -- (Protection_Entries_Access (P),
3039 -- O._object'Unchecked_Access,
3040 -- Protected_Entry_Index (I),
3043 -- System.Tasking.Protected_Objects.Operations.
3044 -- Requeue_Task_To_Protected_Entry
3045 -- (O._object'Unchecked_Access,
3046 -- Protected_Entry_Index (I),
3050 if Restriction_Active
(No_Entry_Queue
) then
3051 Append_To
(Stmts
, Make_Null_Statement
(Loc
));
3054 Make_If_Statement
(Loc
,
3055 Condition
=> Make_Identifier
(Loc
, Name_uF
),
3060 -- Call to Requeue_Protected_Entry
3062 Make_Procedure_Call_Statement
(Loc
,
3065 (RTE
(RE_Requeue_Protected_Entry
), Loc
),
3066 Parameter_Associations
=>
3069 Make_Unchecked_Type_Conversion
(Loc
, -- PEA (P)
3072 RTE
(RE_Protection_Entries_Access
), Loc
),
3074 Make_Identifier
(Loc
, Name_uP
)),
3076 Make_Attribute_Reference
(Loc
, -- O._object'Acc
3078 Name_Unchecked_Access
,
3080 Make_Selected_Component
(Loc
,
3082 Make_Identifier
(Loc
, Name_uO
),
3084 Make_Identifier
(Loc
, Name_uObject
))),
3086 Make_Unchecked_Type_Conversion
(Loc
, -- entry index
3089 (RTE
(RE_Protected_Entry_Index
), Loc
),
3090 Expression
=> Make_Identifier
(Loc
, Name_uI
)),
3092 Make_Identifier
(Loc
, Name_uA
)))), -- abort status
3097 -- Call to Requeue_Task_To_Protected_Entry
3099 Make_Procedure_Call_Statement
(Loc
,
3102 (RTE
(RE_Requeue_Task_To_Protected_Entry
), Loc
),
3103 Parameter_Associations
=>
3106 Make_Attribute_Reference
(Loc
, -- O._object'Acc
3107 Attribute_Name
=> Name_Unchecked_Access
,
3109 Make_Selected_Component
(Loc
,
3111 Make_Identifier
(Loc
, Name_uO
),
3113 Make_Identifier
(Loc
, Name_uObject
))),
3115 Make_Unchecked_Type_Conversion
(Loc
, -- entry index
3118 (RTE
(RE_Protected_Entry_Index
), Loc
),
3119 Expression
=> Make_Identifier
(Loc
, Name_uI
)),
3121 Make_Identifier
(Loc
, Name_uA
)))))); -- abort status
3125 pragma Assert
(Is_Task_Type
(Conc_Typ
));
3129 -- System.Tasking.Rendezvous.Requeue_Protected_To_Task_Entry
3130 -- (Protection_Entries_Access (P),
3132 -- Task_Entry_Index (I),
3135 -- System.Tasking.Rendezvous.Requeue_Task_Entry
3137 -- Task_Entry_Index (I),
3142 Make_If_Statement
(Loc
,
3143 Condition
=> Make_Identifier
(Loc
, Name_uF
),
3145 Then_Statements
=> New_List
(
3147 -- Call to Requeue_Protected_To_Task_Entry
3149 Make_Procedure_Call_Statement
(Loc
,
3152 (RTE
(RE_Requeue_Protected_To_Task_Entry
), Loc
),
3154 Parameter_Associations
=> New_List
(
3156 Make_Unchecked_Type_Conversion
(Loc
, -- PEA (P)
3159 (RTE
(RE_Protection_Entries_Access
), Loc
),
3160 Expression
=> Make_Identifier
(Loc
, Name_uP
)),
3162 Make_Selected_Component
(Loc
, -- O._task_id
3163 Prefix
=> Make_Identifier
(Loc
, Name_uO
),
3164 Selector_Name
=> Make_Identifier
(Loc
, Name_uTask_Id
)),
3166 Make_Unchecked_Type_Conversion
(Loc
, -- entry index
3168 New_Occurrence_Of
(RTE
(RE_Task_Entry_Index
), Loc
),
3169 Expression
=> Make_Identifier
(Loc
, Name_uI
)),
3171 Make_Identifier
(Loc
, Name_uA
)))), -- abort status
3173 Else_Statements
=> New_List
(
3175 -- Call to Requeue_Task_Entry
3177 Make_Procedure_Call_Statement
(Loc
,
3179 New_Occurrence_Of
(RTE
(RE_Requeue_Task_Entry
), Loc
),
3181 Parameter_Associations
=> New_List
(
3183 Make_Selected_Component
(Loc
, -- O._task_id
3184 Prefix
=> Make_Identifier
(Loc
, Name_uO
),
3185 Selector_Name
=> Make_Identifier
(Loc
, Name_uTask_Id
)),
3187 Make_Unchecked_Type_Conversion
(Loc
, -- entry index
3189 New_Occurrence_Of
(RTE
(RE_Task_Entry_Index
), Loc
),
3190 Expression
=> Make_Identifier
(Loc
, Name_uI
)),
3192 Make_Identifier
(Loc
, Name_uA
)))))); -- abort status
3195 -- Even though no declarations are needed in both cases, we allocate
3196 -- a list for entities added by Freeze.
3199 Make_Subprogram_Body
(Loc
,
3200 Specification
=> Make_Disp_Requeue_Spec
(Typ
),
3201 Declarations
=> New_List
,
3202 Handled_Statement_Sequence
=>
3203 Make_Handled_Sequence_Of_Statements
(Loc
, Stmts
));
3204 end Make_Disp_Requeue_Body
;
3206 ----------------------------
3207 -- Make_Disp_Requeue_Spec --
3208 ----------------------------
3210 function Make_Disp_Requeue_Spec
3211 (Typ
: Entity_Id
) return Node_Id
3213 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
3216 pragma Assert
(not Restriction_Active
(No_Dispatching_Calls
));
3218 -- O : in out Typ; - Object parameter
3219 -- F : Boolean; - Protected (True) / task (False) flag
3220 -- P : Address; - Protection_Entries_Access value
3221 -- I : Entry_Index - Index of entry call
3222 -- A : Boolean - Abort flag
3224 -- Note that the Protection_Entries_Access value is represented as a
3225 -- System.Address in order to avoid dragging in the tasking runtime
3226 -- when compiling sources without tasking constructs.
3229 Make_Procedure_Specification
(Loc
,
3230 Defining_Unit_Name
=>
3231 Make_Defining_Identifier
(Loc
, Name_uDisp_Requeue
),
3233 Parameter_Specifications
=> New_List
(
3235 Make_Parameter_Specification
(Loc
, -- O
3236 Defining_Identifier
=>
3237 Make_Defining_Identifier
(Loc
, Name_uO
),
3239 New_Occurrence_Of
(Typ
, Loc
),
3241 Out_Present
=> True),
3243 Make_Parameter_Specification
(Loc
, -- F
3244 Defining_Identifier
=>
3245 Make_Defining_Identifier
(Loc
, Name_uF
),
3247 New_Occurrence_Of
(Standard_Boolean
, Loc
)),
3249 Make_Parameter_Specification
(Loc
, -- P
3250 Defining_Identifier
=>
3251 Make_Defining_Identifier
(Loc
, Name_uP
),
3253 New_Occurrence_Of
(RTE
(RE_Address
), Loc
)),
3255 Make_Parameter_Specification
(Loc
, -- I
3256 Defining_Identifier
=>
3257 Make_Defining_Identifier
(Loc
, Name_uI
),
3259 New_Occurrence_Of
(Standard_Integer
, Loc
)),
3261 Make_Parameter_Specification
(Loc
, -- A
3262 Defining_Identifier
=>
3263 Make_Defining_Identifier
(Loc
, Name_uA
),
3265 New_Occurrence_Of
(Standard_Boolean
, Loc
))));
3266 end Make_Disp_Requeue_Spec
;
3268 ---------------------------------
3269 -- Make_Disp_Timed_Select_Body --
3270 ---------------------------------
3272 -- For interface types, generate:
3274 -- procedure _Disp_Timed_Select
3275 -- (T : in out <Typ>;
3277 -- P : System.Address;
3280 -- C : out Ada.Tags.Prim_Op_Kind;
3285 -- C := Ada.Tags.POK_Function;
3286 -- end _Disp_Timed_Select;
3288 -- For protected types, generate:
3290 -- procedure _Disp_Timed_Select
3291 -- (T : in out <Typ>;
3293 -- P : System.Address;
3296 -- C : out Ada.Tags.Prim_Op_Kind;
3302 -- C := Ada.Tags.Get_Prim_Op_Kind (Ada.Tags.Tag (<Typ>VP), S);
3304 -- if C = Ada.Tags.POK_Procedure
3305 -- or else C = Ada.Tags.POK_Protected_Procedure
3306 -- or else C = Ada.Tags.POK_Task_Procedure
3312 -- I := Ada.Tags.Get_Entry_Index (Ada.Tags.Tag (<Typ>VP), S);
3313 -- System.Tasking.Protected_Objects.Operations.
3314 -- Timed_Protected_Entry_Call
3315 -- (T._object'Access,
3316 -- System.Tasking.Protected_Objects.Protected_Entry_Index (I),
3321 -- end _Disp_Timed_Select;
3323 -- For task types, generate:
3325 -- procedure _Disp_Timed_Select
3326 -- (T : in out <Typ>;
3328 -- P : System.Address;
3331 -- C : out Ada.Tags.Prim_Op_Kind;
3337 -- I := Ada.Tags.Get_Entry_Index (Ada.Tags.Tag (<Typ>VP), S);
3338 -- System.Tasking.Rendezvous.Timed_Task_Entry_Call
3340 -- System.Tasking.Task_Entry_Index (I),
3345 -- end _Disp_Time_Select;
3347 function Make_Disp_Timed_Select_Body
3348 (Typ
: Entity_Id
) return Node_Id
3350 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
3351 Conc_Typ
: Entity_Id
:= Empty
;
3352 Decls
: constant List_Id
:= New_List
;
3354 Stmts
: constant List_Id
:= New_List
;
3358 pragma Assert
(not Restriction_Active
(No_Dispatching_Calls
));
3360 -- Null body is generated for interface types
3362 if Is_Interface
(Typ
) then
3364 Make_Subprogram_Body
(Loc
,
3365 Specification
=> Make_Disp_Timed_Select_Spec
(Typ
),
3366 Declarations
=> New_List
,
3367 Handled_Statement_Sequence
=>
3368 Make_Handled_Sequence_Of_Statements
(Loc
,
3370 Make_Assignment_Statement
(Loc
,
3371 Name
=> Make_Identifier
(Loc
, Name_uF
),
3372 Expression
=> New_Occurrence_Of
(Standard_False
, Loc
)))));
3375 if Is_Concurrent_Record_Type
(Typ
) then
3376 Conc_Typ
:= Corresponding_Concurrent_Type
(Typ
);
3381 -- where I will be used to capture the entry index of the primitive
3382 -- wrapper at position S.
3385 Make_Object_Declaration
(Loc
,
3386 Defining_Identifier
=> Make_Defining_Identifier
(Loc
, Name_uI
),
3387 Object_Definition
=>
3388 New_Occurrence_Of
(Standard_Integer
, Loc
)));
3391 -- C := Get_Prim_Op_Kind (tag! (<type>VP), S);
3393 -- if C = POK_Procedure
3394 -- or else C = POK_Protected_Procedure
3395 -- or else C = POK_Task_Procedure;
3401 Build_Common_Dispatching_Select_Statements
(Typ
, Stmts
);
3404 -- I := Get_Entry_Index (tag! (<type>VP), S);
3406 -- I is the entry index and S is the dispatch table slot
3408 if Tagged_Type_Expansion
then
3410 Unchecked_Convert_To
(RTE
(RE_Tag
),
3412 (Node
(First_Elmt
(Access_Disp_Table
(Typ
))), Loc
));
3416 Make_Attribute_Reference
(Loc
,
3417 Prefix
=> New_Occurrence_Of
(Typ
, Loc
),
3418 Attribute_Name
=> Name_Tag
);
3422 Make_Assignment_Statement
(Loc
,
3423 Name
=> Make_Identifier
(Loc
, Name_uI
),
3425 Make_Function_Call
(Loc
,
3426 Name
=> New_Occurrence_Of
(RTE
(RE_Get_Entry_Index
), Loc
),
3427 Parameter_Associations
=> New_List
(
3429 Make_Identifier
(Loc
, Name_uS
)))));
3433 if Ekind
(Conc_Typ
) = E_Protected_Type
then
3435 -- Build T._object'Access
3438 Make_Attribute_Reference
(Loc
,
3439 Attribute_Name
=> Name_Unchecked_Access
,
3441 Make_Selected_Component
(Loc
,
3442 Prefix
=> Make_Identifier
(Loc
, Name_uT
),
3443 Selector_Name
=> Make_Identifier
(Loc
, Name_uObject
)));
3445 -- Normal case, No_Entry_Queue restriction not active. In this
3446 -- case we generate:
3448 -- Timed_Protected_Entry_Call
3449 -- (T._object'access,
3450 -- Protected_Entry_Index! (I),
3453 -- where T is the protected object, I is the entry index, P are
3454 -- the wrapped parameters, D is the delay amount, M is the delay
3455 -- mode and F is the status flag.
3457 -- Historically, there was also an implementation for single
3458 -- entry protected types (in s-tposen). However, it was removed
3459 -- by also testing for no No_Select_Statements restriction in
3460 -- Exp_Utils.Corresponding_Runtime_Package. This simplified the
3461 -- implementation of s-tposen.adb and provided consistency between
3462 -- all versions of System.Tasking.Protected_Objects.Single_Entry
3465 case Corresponding_Runtime_Package
(Conc_Typ
) is
3466 when System_Tasking_Protected_Objects_Entries
=>
3468 Make_Procedure_Call_Statement
(Loc
,
3471 (RTE
(RE_Timed_Protected_Entry_Call
), Loc
),
3472 Parameter_Associations
=> New_List
(
3475 Make_Unchecked_Type_Conversion
(Loc
, -- entry index
3478 (RTE
(RE_Protected_Entry_Index
), Loc
),
3479 Expression
=> Make_Identifier
(Loc
, Name_uI
)),
3481 Make_Identifier
(Loc
, Name_uP
), -- parameter block
3482 Make_Identifier
(Loc
, Name_uD
), -- delay
3483 Make_Identifier
(Loc
, Name_uM
), -- delay mode
3484 Make_Identifier
(Loc
, Name_uF
)))); -- status flag
3487 raise Program_Error
;
3493 pragma Assert
(Ekind
(Conc_Typ
) = E_Task_Type
);
3496 -- Timed_Task_Entry_Call (
3498 -- Task_Entry_Index! (I),
3504 -- where T is the task object, I is the entry index, P are the
3505 -- wrapped parameters, D is the delay amount, M is the delay
3506 -- mode and F is the status flag.
3509 Make_Procedure_Call_Statement
(Loc
,
3511 New_Occurrence_Of
(RTE
(RE_Timed_Task_Entry_Call
), Loc
),
3513 Parameter_Associations
=> New_List
(
3514 Make_Selected_Component
(Loc
, -- T._task_id
3515 Prefix
=> Make_Identifier
(Loc
, Name_uT
),
3516 Selector_Name
=> Make_Identifier
(Loc
, Name_uTask_Id
)),
3518 Make_Unchecked_Type_Conversion
(Loc
, -- entry index
3520 New_Occurrence_Of
(RTE
(RE_Task_Entry_Index
), Loc
),
3521 Expression
=> Make_Identifier
(Loc
, Name_uI
)),
3523 Make_Identifier
(Loc
, Name_uP
), -- parameter block
3524 Make_Identifier
(Loc
, Name_uD
), -- delay
3525 Make_Identifier
(Loc
, Name_uM
), -- delay mode
3526 Make_Identifier
(Loc
, Name_uF
)))); -- status flag
3530 -- Initialize out parameters
3533 Make_Assignment_Statement
(Loc
,
3534 Name
=> Make_Identifier
(Loc
, Name_uF
),
3535 Expression
=> New_Occurrence_Of
(Standard_False
, Loc
)));
3537 Make_Assignment_Statement
(Loc
,
3538 Name
=> Make_Identifier
(Loc
, Name_uC
),
3539 Expression
=> New_Occurrence_Of
(RTE
(RE_POK_Function
), Loc
)));
3543 Make_Subprogram_Body
(Loc
,
3544 Specification
=> Make_Disp_Timed_Select_Spec
(Typ
),
3545 Declarations
=> Decls
,
3546 Handled_Statement_Sequence
=>
3547 Make_Handled_Sequence_Of_Statements
(Loc
, Stmts
));
3548 end Make_Disp_Timed_Select_Body
;
3550 ---------------------------------
3551 -- Make_Disp_Timed_Select_Spec --
3552 ---------------------------------
3554 function Make_Disp_Timed_Select_Spec
3555 (Typ
: Entity_Id
) return Node_Id
3557 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
3558 Def_Id
: constant Node_Id
:=
3559 Make_Defining_Identifier
(Loc
,
3560 Name_uDisp_Timed_Select
);
3561 Params
: constant List_Id
:= New_List
;
3564 pragma Assert
(not Restriction_Active
(No_Dispatching_Calls
));
3566 -- T : in out Typ; -- Object parameter
3567 -- S : Integer; -- Primitive operation slot
3568 -- P : Address; -- Wrapped parameters
3569 -- D : Duration; -- Delay
3570 -- M : Integer; -- Delay Mode
3571 -- C : out Prim_Op_Kind; -- Call kind
3572 -- F : out Boolean; -- Status flag
3574 Append_List_To
(Params
, New_List
(
3576 Make_Parameter_Specification
(Loc
,
3577 Defining_Identifier
=> Make_Defining_Identifier
(Loc
, Name_uT
),
3578 Parameter_Type
=> New_Occurrence_Of
(Typ
, Loc
),
3580 Out_Present
=> True),
3582 Make_Parameter_Specification
(Loc
,
3583 Defining_Identifier
=> Make_Defining_Identifier
(Loc
, Name_uS
),
3584 Parameter_Type
=> New_Occurrence_Of
(Standard_Integer
, Loc
)),
3586 Make_Parameter_Specification
(Loc
,
3587 Defining_Identifier
=> Make_Defining_Identifier
(Loc
, Name_uP
),
3588 Parameter_Type
=> New_Occurrence_Of
(RTE
(RE_Address
), Loc
)),
3590 Make_Parameter_Specification
(Loc
,
3591 Defining_Identifier
=> Make_Defining_Identifier
(Loc
, Name_uD
),
3592 Parameter_Type
=> New_Occurrence_Of
(Standard_Duration
, Loc
)),
3594 Make_Parameter_Specification
(Loc
,
3595 Defining_Identifier
=> Make_Defining_Identifier
(Loc
, Name_uM
),
3596 Parameter_Type
=> New_Occurrence_Of
(Standard_Integer
, Loc
)),
3598 Make_Parameter_Specification
(Loc
,
3599 Defining_Identifier
=> Make_Defining_Identifier
(Loc
, Name_uC
),
3601 New_Occurrence_Of
(RTE
(RE_Prim_Op_Kind
), Loc
),
3602 Out_Present
=> True)));
3605 Make_Parameter_Specification
(Loc
,
3606 Defining_Identifier
=> Make_Defining_Identifier
(Loc
, Name_uF
),
3607 Parameter_Type
=> New_Occurrence_Of
(Standard_Boolean
, Loc
),
3608 Out_Present
=> True));
3611 Make_Procedure_Specification
(Loc
,
3612 Defining_Unit_Name
=> Def_Id
,
3613 Parameter_Specifications
=> Params
);
3614 end Make_Disp_Timed_Select_Spec
;
3620 -- The frontend supports two models for expanding dispatch tables
3621 -- associated with library-level defined tagged types: statically and
3622 -- non-statically allocated dispatch tables. In the former case the object
3623 -- containing the dispatch table is constant and it is initialized by means
3624 -- of a positional aggregate. In the latter case, the object containing
3625 -- the dispatch table is a variable which is initialized by means of
3628 -- In case of locally defined tagged types, the object containing the
3629 -- object containing the dispatch table is always a variable (instead of a
3630 -- constant). This is currently required to give support to late overriding
3631 -- of primitives. For example:
3633 -- procedure Example is
3635 -- type T1 is tagged null record;
3636 -- procedure Prim (O : T1);
3639 -- type T2 is new Pkg.T1 with null record;
3640 -- procedure Prim (X : T2) is -- late overriding
3646 function Make_DT
(Typ
: Entity_Id
; N
: Node_Id
:= Empty
) return List_Id
is
3647 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
3649 Max_Predef_Prims
: constant Int
:=
3653 (Parent
(RTE
(RE_Max_Predef_Prims
)))));
3655 DT_Decl
: constant Elist_Id
:= New_Elmt_List
;
3656 DT_Aggr
: constant Elist_Id
:= New_Elmt_List
;
3657 -- Entities marked with attribute Is_Dispatch_Table_Entity
3659 procedure Check_Premature_Freezing
3661 Tagged_Type
: Entity_Id
;
3663 -- Verify that all untagged types in the profile of a subprogram are
3664 -- frozen at the point the subprogram is frozen. This enforces the rule
3665 -- on RM 13.14 (14) as modified by AI05-019. At the point a subprogram
3666 -- is frozen, enough must be known about it to build the activation
3667 -- record for it, which requires at least that the size of all
3668 -- parameters be known. Controlling arguments are by-reference,
3669 -- and therefore the rule only applies to untagged types. Typical
3670 -- violation of the rule involves an object declaration that freezes a
3671 -- tagged type, when one of its primitive operations has a type in its
3672 -- profile whose full view has not been analyzed yet. More complex cases
3673 -- involve composite types that have one private unfrozen subcomponent.
3675 procedure Export_DT
(Typ
: Entity_Id
; DT
: Entity_Id
; Index
: Nat
:= 0);
3676 -- Export the dispatch table DT of tagged type Typ. Required to generate
3677 -- forward references and statically allocate the table. For primary
3678 -- dispatch tables Index is 0; for secondary dispatch tables the value
3679 -- of index must match the Suffix_Index value assigned to the table by
3680 -- Make_Tags when generating its unique external name, and it is used to
3681 -- retrieve from the Dispatch_Table_Wrappers list associated with Typ
3682 -- the external name generated by Import_DT.
3684 procedure Make_Secondary_DT
3688 Num_Iface_Prims
: Nat
;
3689 Iface_DT_Ptr
: Entity_Id
;
3690 Predef_Prims_Ptr
: Entity_Id
;
3691 Build_Thunks
: Boolean;
3693 -- Ada 2005 (AI-251): Expand the declarations for a Secondary Dispatch
3694 -- Table of Typ associated with Iface. Each abstract interface of Typ
3695 -- has two secondary dispatch tables: one containing pointers to thunks
3696 -- and another containing pointers to the primitives covering the
3697 -- interface primitives. The former secondary table is generated when
3698 -- Build_Thunks is True, and provides common support for dispatching
3699 -- calls through interface types; the latter secondary table is
3700 -- generated when Build_Thunks is False, and provides support for
3701 -- Generic Dispatching Constructors that dispatch calls through
3702 -- interface types. When constructing this latter table the value of
3703 -- Suffix_Index is -1 to indicate that there is no need to export such
3704 -- table when building statically allocated dispatch tables; a positive
3705 -- value of Suffix_Index must match the Suffix_Index value assigned to
3706 -- this secondary dispatch table by Make_Tags when its unique external
3707 -- name was generated.
3709 ------------------------------
3710 -- Check_Premature_Freezing --
3711 ------------------------------
3713 procedure Check_Premature_Freezing
3715 Tagged_Type
: Entity_Id
;
3720 function Is_Actual_For_Formal_Incomplete_Type
3721 (T
: Entity_Id
) return Boolean;
3722 -- In Ada 2012, if a nested generic has an incomplete formal type,
3723 -- the actual may be (and usually is) a private type whose completion
3724 -- appears later. It is safe to build the dispatch table in this
3725 -- case, gigi will have full views available.
3727 ------------------------------------------
3728 -- Is_Actual_For_Formal_Incomplete_Type --
3729 ------------------------------------------
3731 function Is_Actual_For_Formal_Incomplete_Type
3732 (T
: Entity_Id
) return Boolean
3734 Gen_Par
: Entity_Id
;
3738 if not Is_Generic_Instance
(Current_Scope
)
3739 or else not Used_As_Generic_Actual
(T
)
3743 Gen_Par
:= Generic_Parent
(Parent
(Current_Scope
));
3748 (Generic_Formal_Declarations
3749 (Unit_Declaration_Node
(Gen_Par
)));
3750 while Present
(F
) loop
3751 if Ekind
(Defining_Identifier
(F
)) = E_Incomplete_Type
then
3759 end Is_Actual_For_Formal_Incomplete_Type
;
3761 -- Start of processing for Check_Premature_Freezing
3764 -- Note that if the type is a (subtype of) a generic actual, the
3765 -- actual will have been frozen by the instantiation.
3768 and then Is_Private_Type
(Typ
)
3769 and then No
(Full_View
(Typ
))
3770 and then not Is_Generic_Type
(Typ
)
3771 and then not Is_Tagged_Type
(Typ
)
3772 and then not Is_Frozen
(Typ
)
3773 and then not Is_Generic_Actual_Type
(Typ
)
3775 Error_Msg_Sloc
:= Sloc
(Subp
);
3777 ("declaration must appear after completion of type &", N
, Typ
);
3779 ("\which is an untagged type in the profile of "
3780 & "primitive operation & declared#", N
, Subp
);
3783 Comp
:= Private_Component
(Typ
);
3785 if not Is_Tagged_Type
(Typ
)
3786 and then Present
(Comp
)
3787 and then not Is_Frozen
(Comp
)
3788 and then not Is_Actual_For_Formal_Incomplete_Type
(Comp
)
3790 Error_Msg_Sloc
:= Sloc
(Subp
);
3791 Error_Msg_Node_2
:= Subp
;
3792 Error_Msg_Name_1
:= Chars
(Tagged_Type
);
3794 ("declaration must appear after completion of type &",
3797 ("\which is a component of untagged type& in the profile "
3798 & "of primitive & of type % that is frozen by the "
3799 & "declaration ", N
, Typ
);
3802 end Check_Premature_Freezing
;
3808 procedure Export_DT
(Typ
: Entity_Id
; DT
: Entity_Id
; Index
: Nat
:= 0)
3814 Set_Is_Statically_Allocated
(DT
);
3815 Set_Is_True_Constant
(DT
);
3816 Set_Is_Exported
(DT
);
3819 Elmt
:= First_Elmt
(Dispatch_Table_Wrappers
(Typ
));
3820 while Count
/= Index
loop
3825 pragma Assert
(Related_Type
(Node
(Elmt
)) = Typ
);
3827 Get_External_Name
(Node
(Elmt
));
3828 Set_Interface_Name
(DT
,
3829 Make_String_Literal
(Loc
,
3830 Strval
=> String_From_Name_Buffer
));
3832 -- Ensure proper Sprint output of this implicit importation
3834 Set_Is_Internal
(DT
);
3838 -----------------------
3839 -- Make_Secondary_DT --
3840 -----------------------
3842 procedure Make_Secondary_DT
3846 Num_Iface_Prims
: Nat
;
3847 Iface_DT_Ptr
: Entity_Id
;
3848 Predef_Prims_Ptr
: Entity_Id
;
3849 Build_Thunks
: Boolean;
3852 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
3853 Exporting_Table
: constant Boolean :=
3854 Building_Static_DT
(Typ
)
3855 and then Suffix_Index
> 0;
3856 Iface_DT
: constant Entity_Id
:= Make_Temporary
(Loc
, 'T');
3857 Predef_Prims
: constant Entity_Id
:= Make_Temporary
(Loc
, 'R');
3858 DT_Constr_List
: List_Id
;
3859 DT_Aggr_List
: List_Id
;
3860 Empty_DT
: Boolean := False;
3861 Nb_Predef_Prims
: Nat
:= 0;
3865 OSD_Aggr_List
: List_Id
;
3868 Prim_Elmt
: Elmt_Id
;
3869 Prim_Ops_Aggr_List
: List_Id
;
3872 -- Handle cases in which we do not generate statically allocated
3875 if not Building_Static_DT
(Typ
) then
3876 Set_Ekind
(Predef_Prims
, E_Variable
);
3877 Set_Ekind
(Iface_DT
, E_Variable
);
3879 -- Statically allocated dispatch tables and related entities are
3883 Set_Ekind
(Predef_Prims
, E_Constant
);
3884 Set_Is_Statically_Allocated
(Predef_Prims
);
3885 Set_Is_True_Constant
(Predef_Prims
);
3887 Set_Ekind
(Iface_DT
, E_Constant
);
3888 Set_Is_Statically_Allocated
(Iface_DT
);
3889 Set_Is_True_Constant
(Iface_DT
);
3892 -- Calculate the number of slots of the dispatch table. If the number
3893 -- of primitives of Typ is 0 we reserve a dummy single entry for its
3894 -- DT because at run time the pointer to this dummy entry will be
3897 if Num_Iface_Prims
= 0 then
3901 Nb_Prim
:= Num_Iface_Prims
;
3906 -- Predef_Prims : Address_Array (1 .. Default_Prim_Ops_Count) :=
3907 -- (predef-prim-op-thunk-1'address,
3908 -- predef-prim-op-thunk-2'address,
3910 -- predef-prim-op-thunk-n'address);
3911 -- for Predef_Prims'Alignment use Address'Alignment
3913 -- Stage 1: Calculate the number of predefined primitives
3915 if not Building_Static_DT
(Typ
) then
3916 Nb_Predef_Prims
:= Max_Predef_Prims
;
3918 Prim_Elmt
:= First_Elmt
(Primitive_Operations
(Typ
));
3919 while Present
(Prim_Elmt
) loop
3920 Prim
:= Node
(Prim_Elmt
);
3922 if Is_Predefined_Dispatching_Operation
(Prim
)
3923 and then not Is_Abstract_Subprogram
(Prim
)
3925 Pos
:= UI_To_Int
(DT_Position
(Prim
));
3927 if Pos
> Nb_Predef_Prims
then
3928 Nb_Predef_Prims
:= Pos
;
3932 Next_Elmt
(Prim_Elmt
);
3936 -- Stage 2: Create the thunks associated with the predefined
3937 -- primitives and save their entity to fill the aggregate.
3940 Prim_Table
: array (Nat
range 1 .. Nb_Predef_Prims
) of Entity_Id
;
3942 Thunk_Id
: Entity_Id
;
3943 Thunk_Code
: Node_Id
;
3946 Prim_Ops_Aggr_List
:= New_List
;
3947 Prim_Table
:= (others => Empty
);
3949 if Building_Static_DT
(Typ
) then
3950 Prim_Elmt
:= First_Elmt
(Primitive_Operations
(Typ
));
3951 while Present
(Prim_Elmt
) loop
3952 Prim
:= Node
(Prim_Elmt
);
3954 if Is_Predefined_Dispatching_Operation
(Prim
)
3955 and then not Is_Abstract_Subprogram
(Prim
)
3956 and then not Is_Eliminated
(Prim
)
3957 and then not Present
(Prim_Table
3958 (UI_To_Int
(DT_Position
(Prim
))))
3960 if not Build_Thunks
then
3961 Prim_Table
(UI_To_Int
(DT_Position
(Prim
))) :=
3965 Expand_Interface_Thunk
3966 (Ultimate_Alias
(Prim
), Thunk_Id
, Thunk_Code
);
3968 if Present
(Thunk_Id
) then
3969 Append_To
(Result
, Thunk_Code
);
3970 Prim_Table
(UI_To_Int
(DT_Position
(Prim
)))
3976 Next_Elmt
(Prim_Elmt
);
3980 for J
in Prim_Table
'Range loop
3981 if Present
(Prim_Table
(J
)) then
3983 Unchecked_Convert_To
(RTE
(RE_Prim_Ptr
),
3984 Make_Attribute_Reference
(Loc
,
3985 Prefix
=> New_Occurrence_Of
(Prim_Table
(J
), Loc
),
3986 Attribute_Name
=> Name_Unrestricted_Access
));
3988 New_Node
:= Make_Null
(Loc
);
3991 Append_To
(Prim_Ops_Aggr_List
, New_Node
);
3995 Make_Aggregate
(Loc
, Expressions
=> Prim_Ops_Aggr_List
);
3997 -- Remember aggregates initializing dispatch tables
3999 Append_Elmt
(New_Node
, DT_Aggr
);
4002 Make_Subtype_Declaration
(Loc
,
4003 Defining_Identifier
=> Make_Temporary
(Loc
, 'S'),
4004 Subtype_Indication
=>
4005 New_Occurrence_Of
(RTE
(RE_Address_Array
), Loc
));
4007 Append_To
(Result
, Decl
);
4010 Make_Object_Declaration
(Loc
,
4011 Defining_Identifier
=> Predef_Prims
,
4012 Constant_Present
=> Building_Static_DT
(Typ
),
4013 Aliased_Present
=> True,
4014 Object_Definition
=> New_Occurrence_Of
4015 (Defining_Identifier
(Decl
), Loc
),
4016 Expression
=> New_Node
));
4019 Make_Attribute_Definition_Clause
(Loc
,
4020 Name
=> New_Occurrence_Of
(Predef_Prims
, Loc
),
4021 Chars
=> Name_Alignment
,
4023 Make_Attribute_Reference
(Loc
,
4025 New_Occurrence_Of
(RTE
(RE_Integer_Address
), Loc
),
4026 Attribute_Name
=> Name_Alignment
)));
4031 -- OSD : Ada.Tags.Object_Specific_Data (Nb_Prims) :=
4032 -- (OSD_Table => (1 => <value>,
4036 -- Iface_DT : Dispatch_Table (Nb_Prims) :=
4037 -- ([ Signature => <sig-value> ],
4038 -- Tag_Kind => <tag_kind-value>,
4039 -- Predef_Prims => Predef_Prims'Address,
4040 -- Offset_To_Top => 0,
4041 -- OSD => OSD'Address,
4042 -- Prims_Ptr => (prim-op-1'address,
4043 -- prim-op-2'address,
4045 -- prim-op-n'address));
4046 -- for Iface_DT'Alignment use Address'Alignment;
4048 -- Stage 3: Initialize the discriminant and the record components
4050 DT_Constr_List
:= New_List
;
4051 DT_Aggr_List
:= New_List
;
4055 Append_To
(DT_Constr_List
, Make_Integer_Literal
(Loc
, Nb_Prim
));
4056 Append_To
(DT_Aggr_List
, Make_Integer_Literal
(Loc
, Nb_Prim
));
4060 if RTE_Record_Component_Available
(RE_Signature
) then
4061 Append_To
(DT_Aggr_List
,
4062 New_Occurrence_Of
(RTE
(RE_Secondary_DT
), Loc
));
4067 if RTE_Record_Component_Available
(RE_Tag_Kind
) then
4068 Append_To
(DT_Aggr_List
, Tagged_Kind
(Typ
));
4073 Append_To
(DT_Aggr_List
,
4074 Make_Attribute_Reference
(Loc
,
4075 Prefix
=> New_Occurrence_Of
(Predef_Prims
, Loc
),
4076 Attribute_Name
=> Name_Address
));
4078 -- Note: The correct value of Offset_To_Top will be set by the init
4081 Append_To
(DT_Aggr_List
, Make_Integer_Literal
(Loc
, 0));
4083 -- Generate the Object Specific Data table required to dispatch calls
4084 -- through synchronized interfaces.
4087 or else Is_Abstract_Type
(Typ
)
4088 or else Is_Controlled
(Typ
)
4089 or else Restriction_Active
(No_Dispatching_Calls
)
4090 or else not Is_Limited_Type
(Typ
)
4091 or else not Has_Interfaces
(Typ
)
4092 or else not Build_Thunks
4093 or else not RTE_Record_Component_Available
(RE_OSD_Table
)
4095 -- No OSD table required
4097 Append_To
(DT_Aggr_List
,
4098 New_Occurrence_Of
(RTE
(RE_Null_Address
), Loc
));
4101 OSD_Aggr_List
:= New_List
;
4104 Prim_Table
: array (Nat
range 1 .. Nb_Prim
) of Entity_Id
;
4106 Prim_Alias
: Entity_Id
;
4107 Prim_Elmt
: Elmt_Id
;
4113 Prim_Table
:= (others => Empty
);
4114 Prim_Alias
:= Empty
;
4116 Prim_Elmt
:= First_Elmt
(Primitive_Operations
(Typ
));
4117 while Present
(Prim_Elmt
) loop
4118 Prim
:= Node
(Prim_Elmt
);
4120 if Present
(Interface_Alias
(Prim
))
4121 and then Find_Dispatching_Type
4122 (Interface_Alias
(Prim
)) = Iface
4124 Prim_Alias
:= Interface_Alias
(Prim
);
4125 E
:= Ultimate_Alias
(Prim
);
4126 Pos
:= UI_To_Int
(DT_Position
(Prim_Alias
));
4128 if Present
(Prim_Table
(Pos
)) then
4129 pragma Assert
(Prim_Table
(Pos
) = E
);
4133 Prim_Table
(Pos
) := E
;
4135 Append_To
(OSD_Aggr_List
,
4136 Make_Component_Association
(Loc
,
4137 Choices
=> New_List
(
4138 Make_Integer_Literal
(Loc
,
4139 DT_Position
(Prim_Alias
))),
4141 Make_Integer_Literal
(Loc
,
4142 DT_Position
(Alias
(Prim
)))));
4148 Next_Elmt
(Prim_Elmt
);
4150 pragma Assert
(Count
= Nb_Prim
);
4153 OSD
:= Make_Temporary
(Loc
, 'I');
4156 Make_Object_Declaration
(Loc
,
4157 Defining_Identifier
=> OSD
,
4158 Object_Definition
=>
4159 Make_Subtype_Indication
(Loc
,
4161 New_Occurrence_Of
(RTE
(RE_Object_Specific_Data
), Loc
),
4163 Make_Index_Or_Discriminant_Constraint
(Loc
,
4164 Constraints
=> New_List
(
4165 Make_Integer_Literal
(Loc
, Nb_Prim
)))),
4168 Make_Aggregate
(Loc
,
4169 Component_Associations
=> New_List
(
4170 Make_Component_Association
(Loc
,
4171 Choices
=> New_List
(
4173 (RTE_Record_Component
(RE_OSD_Num_Prims
), Loc
)),
4175 Make_Integer_Literal
(Loc
, Nb_Prim
)),
4177 Make_Component_Association
(Loc
,
4178 Choices
=> New_List
(
4180 (RTE_Record_Component
(RE_OSD_Table
), Loc
)),
4181 Expression
=> Make_Aggregate
(Loc
,
4182 Component_Associations
=> OSD_Aggr_List
))))));
4185 Make_Attribute_Definition_Clause
(Loc
,
4186 Name
=> New_Occurrence_Of
(OSD
, Loc
),
4187 Chars
=> Name_Alignment
,
4189 Make_Attribute_Reference
(Loc
,
4191 New_Occurrence_Of
(RTE
(RE_Integer_Address
), Loc
),
4192 Attribute_Name
=> Name_Alignment
)));
4194 -- In secondary dispatch tables the Typeinfo component contains
4195 -- the address of the Object Specific Data (see a-tags.ads)
4197 Append_To
(DT_Aggr_List
,
4198 Make_Attribute_Reference
(Loc
,
4199 Prefix
=> New_Occurrence_Of
(OSD
, Loc
),
4200 Attribute_Name
=> Name_Address
));
4203 -- Initialize the table of primitive operations
4205 Prim_Ops_Aggr_List
:= New_List
;
4208 Append_To
(Prim_Ops_Aggr_List
, Make_Null
(Loc
));
4210 elsif Is_Abstract_Type
(Typ
)
4211 or else not Building_Static_DT
(Typ
)
4213 for J
in 1 .. Nb_Prim
loop
4214 Append_To
(Prim_Ops_Aggr_List
, Make_Null
(Loc
));
4219 CPP_Nb_Prims
: constant Nat
:= CPP_Num_Prims
(Typ
);
4222 Prim_Table
: array (Nat
range 1 .. Nb_Prim
) of Entity_Id
;
4223 Thunk_Code
: Node_Id
;
4224 Thunk_Id
: Entity_Id
;
4227 Prim_Table
:= (others => Empty
);
4229 Prim_Elmt
:= First_Elmt
(Primitive_Operations
(Typ
));
4230 while Present
(Prim_Elmt
) loop
4231 Prim
:= Node
(Prim_Elmt
);
4232 E
:= Ultimate_Alias
(Prim
);
4233 Prim_Pos
:= UI_To_Int
(DT_Position
(E
));
4235 -- Do not reference predefined primitives because they are
4236 -- located in a separate dispatch table; skip abstract and
4237 -- eliminated primitives; skip primitives located in the C++
4238 -- part of the dispatch table because their slot is set by
4241 if not Is_Predefined_Dispatching_Operation
(Prim
)
4242 and then Present
(Interface_Alias
(Prim
))
4243 and then not Is_Abstract_Subprogram
(Alias
(Prim
))
4244 and then not Is_Eliminated
(Alias
(Prim
))
4245 and then (not Is_CPP_Class
(Root_Type
(Typ
))
4246 or else Prim_Pos
> CPP_Nb_Prims
)
4247 and then Find_Dispatching_Type
4248 (Interface_Alias
(Prim
)) = Iface
4250 -- Generate the code of the thunk only if the abstract
4251 -- interface type is not an immediate ancestor of
4252 -- Tagged_Type. Otherwise the DT associated with the
4253 -- interface is the primary DT.
4255 and then not Is_Ancestor
(Iface
, Typ
,
4256 Use_Full_View
=> True)
4258 if not Build_Thunks
then
4260 UI_To_Int
(DT_Position
(Interface_Alias
(Prim
)));
4261 Prim_Table
(Prim_Pos
) := Alias
(Prim
);
4264 Expand_Interface_Thunk
(Prim
, Thunk_Id
, Thunk_Code
);
4266 if Present
(Thunk_Id
) then
4268 UI_To_Int
(DT_Position
(Interface_Alias
(Prim
)));
4270 Prim_Table
(Prim_Pos
) := Thunk_Id
;
4271 Append_To
(Result
, Thunk_Code
);
4276 Next_Elmt
(Prim_Elmt
);
4279 for J
in Prim_Table
'Range loop
4280 if Present
(Prim_Table
(J
)) then
4282 Unchecked_Convert_To
(RTE
(RE_Prim_Ptr
),
4283 Make_Attribute_Reference
(Loc
,
4284 Prefix
=> New_Occurrence_Of
(Prim_Table
(J
), Loc
),
4285 Attribute_Name
=> Name_Unrestricted_Access
));
4288 New_Node
:= Make_Null
(Loc
);
4291 Append_To
(Prim_Ops_Aggr_List
, New_Node
);
4297 Make_Aggregate
(Loc
,
4298 Expressions
=> Prim_Ops_Aggr_List
);
4300 Append_To
(DT_Aggr_List
, New_Node
);
4302 -- Remember aggregates initializing dispatch tables
4304 Append_Elmt
(New_Node
, DT_Aggr
);
4306 -- Note: Secondary dispatch tables cannot be declared constant
4307 -- because the component Offset_To_Top is currently initialized
4308 -- by the IP routine.
4311 Make_Object_Declaration
(Loc
,
4312 Defining_Identifier
=> Iface_DT
,
4313 Aliased_Present
=> True,
4314 Constant_Present
=> False,
4316 Object_Definition
=>
4317 Make_Subtype_Indication
(Loc
,
4318 Subtype_Mark
=> New_Occurrence_Of
4319 (RTE
(RE_Dispatch_Table_Wrapper
), Loc
),
4320 Constraint
=> Make_Index_Or_Discriminant_Constraint
(Loc
,
4321 Constraints
=> DT_Constr_List
)),
4324 Make_Aggregate
(Loc
,
4325 Expressions
=> DT_Aggr_List
)));
4328 Make_Attribute_Definition_Clause
(Loc
,
4329 Name
=> New_Occurrence_Of
(Iface_DT
, Loc
),
4330 Chars
=> Name_Alignment
,
4333 Make_Attribute_Reference
(Loc
,
4335 New_Occurrence_Of
(RTE
(RE_Integer_Address
), Loc
),
4336 Attribute_Name
=> Name_Alignment
)));
4338 if Exporting_Table
then
4339 Export_DT
(Typ
, Iface_DT
, Suffix_Index
);
4341 -- Generate code to create the pointer to the dispatch table
4343 -- Iface_DT_Ptr : Tag := Tag!(DT.Prims_Ptr'Address);
4345 -- Note: This declaration is not added here if the table is exported
4346 -- because in such case Make_Tags has already added this declaration.
4350 Make_Object_Declaration
(Loc
,
4351 Defining_Identifier
=> Iface_DT_Ptr
,
4352 Constant_Present
=> True,
4354 Object_Definition
=>
4355 New_Occurrence_Of
(RTE
(RE_Interface_Tag
), Loc
),
4358 Unchecked_Convert_To
(RTE
(RE_Interface_Tag
),
4359 Make_Attribute_Reference
(Loc
,
4361 Make_Selected_Component
(Loc
,
4362 Prefix
=> New_Occurrence_Of
(Iface_DT
, Loc
),
4365 (RTE_Record_Component
(RE_Prims_Ptr
), Loc
)),
4366 Attribute_Name
=> Name_Address
))));
4370 Make_Object_Declaration
(Loc
,
4371 Defining_Identifier
=> Predef_Prims_Ptr
,
4372 Constant_Present
=> True,
4374 Object_Definition
=>
4375 New_Occurrence_Of
(RTE
(RE_Address
), Loc
),
4378 Make_Attribute_Reference
(Loc
,
4380 Make_Selected_Component
(Loc
,
4381 Prefix
=> New_Occurrence_Of
(Iface_DT
, Loc
),
4384 (RTE_Record_Component
(RE_Predef_Prims
), Loc
)),
4385 Attribute_Name
=> Name_Address
)));
4387 -- Remember entities containing dispatch tables
4389 Append_Elmt
(Predef_Prims
, DT_Decl
);
4390 Append_Elmt
(Iface_DT
, DT_Decl
);
4391 end Make_Secondary_DT
;
4395 Elab_Code
: constant List_Id
:= New_List
;
4396 Result
: constant List_Id
:= New_List
;
4397 Tname
: constant Name_Id
:= Chars
(Typ
);
4399 AI_Tag_Elmt
: Elmt_Id
;
4400 AI_Tag_Comp
: Elmt_Id
;
4401 DT_Aggr_List
: List_Id
;
4402 DT_Constr_List
: List_Id
;
4406 Iface_Table_Node
: Node_Id
;
4407 Name_ITable
: Name_Id
;
4408 Nb_Predef_Prims
: Nat
:= 0;
4411 Num_Ifaces
: Nat
:= 0;
4412 Parent_Typ
: Entity_Id
;
4414 Prim_Elmt
: Elmt_Id
;
4415 Prim_Ops_Aggr_List
: List_Id
;
4417 Typ_Comps
: Elist_Id
;
4418 Typ_Ifaces
: Elist_Id
;
4419 TSD_Aggr_List
: List_Id
;
4420 TSD_Tags_List
: List_Id
;
4422 -- The following name entries are used by Make_DT to generate a number
4423 -- of entities related to a tagged type. These entities may be generated
4424 -- in a scope other than that of the tagged type declaration, and if
4425 -- the entities for two tagged types with the same name happen to be
4426 -- generated in the same scope, we have to take care to use different
4427 -- names. This is achieved by means of a unique serial number appended
4428 -- to each generated entity name.
4430 Name_DT
: constant Name_Id
:=
4431 New_External_Name
(Tname
, 'T', Suffix_Index
=> -1);
4432 Name_Exname
: constant Name_Id
:=
4433 New_External_Name
(Tname
, 'E', Suffix_Index
=> -1);
4434 Name_HT_Link
: constant Name_Id
:=
4435 New_External_Name
(Tname
, 'H', Suffix_Index
=> -1);
4436 Name_Predef_Prims
: constant Name_Id
:=
4437 New_External_Name
(Tname
, 'R', Suffix_Index
=> -1);
4438 Name_SSD
: constant Name_Id
:=
4439 New_External_Name
(Tname
, 'S', Suffix_Index
=> -1);
4440 Name_TSD
: constant Name_Id
:=
4441 New_External_Name
(Tname
, 'B', Suffix_Index
=> -1);
4443 -- Entities built with above names
4445 DT
: constant Entity_Id
:=
4446 Make_Defining_Identifier
(Loc
, Name_DT
);
4447 Exname
: constant Entity_Id
:=
4448 Make_Defining_Identifier
(Loc
, Name_Exname
);
4449 HT_Link
: constant Entity_Id
:=
4450 Make_Defining_Identifier
(Loc
, Name_HT_Link
);
4451 Predef_Prims
: constant Entity_Id
:=
4452 Make_Defining_Identifier
(Loc
, Name_Predef_Prims
);
4453 SSD
: constant Entity_Id
:=
4454 Make_Defining_Identifier
(Loc
, Name_SSD
);
4455 TSD
: constant Entity_Id
:=
4456 Make_Defining_Identifier
(Loc
, Name_TSD
);
4458 -- Start of processing for Make_DT
4461 pragma Assert
(Is_Frozen
(Typ
));
4463 -- Handle cases in which there is no need to build the dispatch table
4465 if Has_Dispatch_Table
(Typ
)
4466 or else No
(Access_Disp_Table
(Typ
))
4467 or else Is_CPP_Class
(Typ
)
4468 or else Convention
(Typ
) = Convention_CIL
4469 or else Convention
(Typ
) = Convention_Java
4473 elsif No_Run_Time_Mode
then
4474 Error_Msg_CRT
("tagged types", Typ
);
4477 elsif not RTE_Available
(RE_Tag
) then
4479 Make_Object_Declaration
(Loc
,
4480 Defining_Identifier
=> Node
(First_Elmt
4481 (Access_Disp_Table
(Typ
))),
4482 Object_Definition
=> New_Occurrence_Of
(RTE
(RE_Tag
), Loc
),
4483 Constant_Present
=> True,
4485 Unchecked_Convert_To
(RTE
(RE_Tag
),
4486 New_Occurrence_Of
(RTE
(RE_Null_Address
), Loc
))));
4488 Analyze_List
(Result
, Suppress
=> All_Checks
);
4489 Error_Msg_CRT
("tagged types", Typ
);
4493 -- Ensure that the value of Max_Predef_Prims defined in a-tags is
4494 -- correct. Valid values are 9 under configurable runtime or 15
4495 -- with full runtime.
4497 if RTE_Available
(RE_Interface_Data
) then
4498 if Max_Predef_Prims
/= 15 then
4499 Error_Msg_N
("run-time library configuration error", Typ
);
4503 if Max_Predef_Prims
/= 9 then
4504 Error_Msg_N
("run-time library configuration error", Typ
);
4505 Error_Msg_CRT
("tagged types", Typ
);
4510 -- Initialize Parent_Typ handling private types
4512 Parent_Typ
:= Etype
(Typ
);
4514 if Present
(Full_View
(Parent_Typ
)) then
4515 Parent_Typ
:= Full_View
(Parent_Typ
);
4518 -- Ensure that all the primitives are frozen. This is only required when
4519 -- building static dispatch tables --- the primitives must be frozen to
4520 -- be referenced (otherwise we have problems with the backend). It is
4521 -- not a requirement with nonstatic dispatch tables because in this case
4522 -- we generate now an empty dispatch table; the extra code required to
4523 -- register the primitives in the slots will be generated later --- when
4524 -- each primitive is frozen (see Freeze_Subprogram).
4526 if Building_Static_DT
(Typ
) then
4528 Save
: constant Boolean := Freezing_Library_Level_Tagged_Type
;
4530 Prim_Elmt
: Elmt_Id
;
4534 Freezing_Library_Level_Tagged_Type
:= True;
4536 Prim_Elmt
:= First_Elmt
(Primitive_Operations
(Typ
));
4537 while Present
(Prim_Elmt
) loop
4538 Prim
:= Node
(Prim_Elmt
);
4539 Frnodes
:= Freeze_Entity
(Prim
, Typ
);
4545 F
:= First_Formal
(Prim
);
4546 while Present
(F
) loop
4547 Check_Premature_Freezing
(Prim
, Typ
, Etype
(F
));
4551 Check_Premature_Freezing
(Prim
, Typ
, Etype
(Prim
));
4554 if Present
(Frnodes
) then
4555 Append_List_To
(Result
, Frnodes
);
4558 Next_Elmt
(Prim_Elmt
);
4561 Freezing_Library_Level_Tagged_Type
:= Save
;
4565 -- Ada 2005 (AI-251): Build the secondary dispatch tables
4567 if Has_Interfaces
(Typ
) then
4568 Collect_Interface_Components
(Typ
, Typ_Comps
);
4570 -- Each secondary dispatch table is assigned an unique positive
4571 -- suffix index; such value also corresponds with the location of
4572 -- its entity in the Dispatch_Table_Wrappers list (see Make_Tags).
4574 -- Note: This value must be kept sync with the Suffix_Index values
4575 -- generated by Make_Tags
4579 Next_Elmt
(Next_Elmt
(First_Elmt
(Access_Disp_Table
(Typ
))));
4581 AI_Tag_Comp
:= First_Elmt
(Typ_Comps
);
4582 while Present
(AI_Tag_Comp
) loop
4583 pragma Assert
(Has_Suffix
(Node
(AI_Tag_Elmt
), 'P'));
4585 -- Build the secondary table containing pointers to thunks
4590 (Related_Type
(Node
(AI_Tag_Comp
))),
4591 Suffix_Index
=> Suffix_Index
,
4592 Num_Iface_Prims
=> UI_To_Int
4593 (DT_Entry_Count
(Node
(AI_Tag_Comp
))),
4594 Iface_DT_Ptr
=> Node
(AI_Tag_Elmt
),
4595 Predef_Prims_Ptr
=> Node
(Next_Elmt
(AI_Tag_Elmt
)),
4596 Build_Thunks
=> True,
4599 -- Skip secondary dispatch table referencing thunks to predefined
4602 Next_Elmt
(AI_Tag_Elmt
);
4603 pragma Assert
(Has_Suffix
(Node
(AI_Tag_Elmt
), 'Y'));
4605 -- Secondary dispatch table referencing user-defined primitives
4606 -- covered by this interface.
4608 Next_Elmt
(AI_Tag_Elmt
);
4609 pragma Assert
(Has_Suffix
(Node
(AI_Tag_Elmt
), 'D'));
4611 -- Build the secondary table containing pointers to primitives
4612 -- (used to give support to Generic Dispatching Constructors).
4617 (Related_Type
(Node
(AI_Tag_Comp
))),
4619 Num_Iface_Prims
=> UI_To_Int
4620 (DT_Entry_Count
(Node
(AI_Tag_Comp
))),
4621 Iface_DT_Ptr
=> Node
(AI_Tag_Elmt
),
4622 Predef_Prims_Ptr
=> Node
(Next_Elmt
(AI_Tag_Elmt
)),
4623 Build_Thunks
=> False,
4626 -- Skip secondary dispatch table referencing predefined primitives
4628 Next_Elmt
(AI_Tag_Elmt
);
4629 pragma Assert
(Has_Suffix
(Node
(AI_Tag_Elmt
), 'Z'));
4631 Suffix_Index
:= Suffix_Index
+ 1;
4632 Next_Elmt
(AI_Tag_Elmt
);
4633 Next_Elmt
(AI_Tag_Comp
);
4637 -- Get the _tag entity and number of primitives of its dispatch table
4639 DT_Ptr
:= Node
(First_Elmt
(Access_Disp_Table
(Typ
)));
4640 Nb_Prim
:= UI_To_Int
(DT_Entry_Count
(First_Tag_Component
(Typ
)));
4642 Set_Is_Statically_Allocated
(DT
, Is_Library_Level_Tagged_Type
(Typ
));
4643 Set_Is_Statically_Allocated
(SSD
, Is_Library_Level_Tagged_Type
(Typ
));
4644 Set_Is_Statically_Allocated
(TSD
, Is_Library_Level_Tagged_Type
(Typ
));
4645 Set_Is_Statically_Allocated
(Predef_Prims
,
4646 Is_Library_Level_Tagged_Type
(Typ
));
4648 -- In case of locally defined tagged type we declare the object
4649 -- containing the dispatch table by means of a variable. Its
4650 -- initialization is done later by means of an assignment. This is
4651 -- required to generate its External_Tag.
4653 if not Building_Static_DT
(Typ
) then
4656 -- DT : No_Dispatch_Table_Wrapper;
4657 -- for DT'Alignment use Address'Alignment;
4658 -- DT_Ptr : Tag := !Tag (DT.NDT_Prims_Ptr'Address);
4660 if not Has_DT
(Typ
) then
4662 Make_Object_Declaration
(Loc
,
4663 Defining_Identifier
=> DT
,
4664 Aliased_Present
=> True,
4665 Constant_Present
=> False,
4666 Object_Definition
=>
4668 (RTE
(RE_No_Dispatch_Table_Wrapper
), Loc
)));
4671 Make_Attribute_Definition_Clause
(Loc
,
4672 Name
=> New_Occurrence_Of
(DT
, Loc
),
4673 Chars
=> Name_Alignment
,
4675 Make_Attribute_Reference
(Loc
,
4677 New_Occurrence_Of
(RTE
(RE_Integer_Address
), Loc
),
4678 Attribute_Name
=> Name_Alignment
)));
4681 Make_Object_Declaration
(Loc
,
4682 Defining_Identifier
=> DT_Ptr
,
4683 Object_Definition
=> New_Occurrence_Of
(RTE
(RE_Tag
), Loc
),
4684 Constant_Present
=> True,
4686 Unchecked_Convert_To
(RTE
(RE_Tag
),
4687 Make_Attribute_Reference
(Loc
,
4689 Make_Selected_Component
(Loc
,
4690 Prefix
=> New_Occurrence_Of
(DT
, Loc
),
4693 (RTE_Record_Component
(RE_NDT_Prims_Ptr
), Loc
)),
4694 Attribute_Name
=> Name_Address
))));
4696 Set_Is_Statically_Allocated
(DT_Ptr
,
4697 Is_Library_Level_Tagged_Type
(Typ
));
4699 -- Generate the SCIL node for the previous object declaration
4700 -- because it has a tag initialization.
4702 if Generate_SCIL
then
4704 Make_SCIL_Dispatch_Table_Tag_Init
(Sloc
(Last
(Result
)));
4705 Set_SCIL_Entity
(New_Node
, Typ
);
4706 Set_SCIL_Node
(Last
(Result
), New_Node
);
4710 -- DT : Dispatch_Table_Wrapper (Nb_Prim);
4711 -- for DT'Alignment use Address'Alignment;
4712 -- DT_Ptr : Tag := !Tag (DT.Prims_Ptr'Address);
4715 -- If the tagged type has no primitives we add a dummy slot
4716 -- whose address will be the tag of this type.
4720 New_List
(Make_Integer_Literal
(Loc
, 1));
4723 New_List
(Make_Integer_Literal
(Loc
, Nb_Prim
));
4727 Make_Object_Declaration
(Loc
,
4728 Defining_Identifier
=> DT
,
4729 Aliased_Present
=> True,
4730 Constant_Present
=> False,
4731 Object_Definition
=>
4732 Make_Subtype_Indication
(Loc
,
4734 New_Occurrence_Of
(RTE
(RE_Dispatch_Table_Wrapper
), Loc
),
4736 Make_Index_Or_Discriminant_Constraint
(Loc
,
4737 Constraints
=> DT_Constr_List
))));
4740 Make_Attribute_Definition_Clause
(Loc
,
4741 Name
=> New_Occurrence_Of
(DT
, Loc
),
4742 Chars
=> Name_Alignment
,
4744 Make_Attribute_Reference
(Loc
,
4746 New_Occurrence_Of
(RTE
(RE_Integer_Address
), Loc
),
4747 Attribute_Name
=> Name_Alignment
)));
4750 Make_Object_Declaration
(Loc
,
4751 Defining_Identifier
=> DT_Ptr
,
4752 Object_Definition
=> New_Occurrence_Of
(RTE
(RE_Tag
), Loc
),
4753 Constant_Present
=> True,
4755 Unchecked_Convert_To
(RTE
(RE_Tag
),
4756 Make_Attribute_Reference
(Loc
,
4758 Make_Selected_Component
(Loc
,
4759 Prefix
=> New_Occurrence_Of
(DT
, Loc
),
4762 (RTE_Record_Component
(RE_Prims_Ptr
), Loc
)),
4763 Attribute_Name
=> Name_Address
))));
4765 Set_Is_Statically_Allocated
(DT_Ptr
,
4766 Is_Library_Level_Tagged_Type
(Typ
));
4768 -- Generate the SCIL node for the previous object declaration
4769 -- because it has a tag initialization.
4771 if Generate_SCIL
then
4773 Make_SCIL_Dispatch_Table_Tag_Init
(Sloc
(Last
(Result
)));
4774 Set_SCIL_Entity
(New_Node
, Typ
);
4775 Set_SCIL_Node
(Last
(Result
), New_Node
);
4779 Make_Object_Declaration
(Loc
,
4780 Defining_Identifier
=>
4781 Node
(Next_Elmt
(First_Elmt
(Access_Disp_Table
(Typ
)))),
4782 Constant_Present
=> True,
4783 Object_Definition
=>
4784 New_Occurrence_Of
(RTE
(RE_Address
), Loc
),
4786 Make_Attribute_Reference
(Loc
,
4788 Make_Selected_Component
(Loc
,
4789 Prefix
=> New_Occurrence_Of
(DT
, Loc
),
4792 (RTE_Record_Component
(RE_Predef_Prims
), Loc
)),
4793 Attribute_Name
=> Name_Address
)));
4797 -- Generate: Exname : constant String := full_qualified_name (typ);
4798 -- The type itself may be an anonymous parent type, so use the first
4799 -- subtype to have a user-recognizable name.
4802 Make_Object_Declaration
(Loc
,
4803 Defining_Identifier
=> Exname
,
4804 Constant_Present
=> True,
4805 Object_Definition
=> New_Occurrence_Of
(Standard_String
, Loc
),
4807 Make_String_Literal
(Loc
,
4808 Strval
=> Fully_Qualified_Name_String
(First_Subtype
(Typ
)))));
4809 Set_Is_Statically_Allocated
(Exname
);
4810 Set_Is_True_Constant
(Exname
);
4812 -- Declare the object used by Ada.Tags.Register_Tag
4814 if RTE_Available
(RE_Register_Tag
) then
4816 Make_Object_Declaration
(Loc
,
4817 Defining_Identifier
=> HT_Link
,
4818 Object_Definition
=> New_Occurrence_Of
(RTE
(RE_Tag
), Loc
)));
4821 -- Generate code to create the storage for the type specific data object
4822 -- with enough space to store the tags of the ancestors plus the tags
4823 -- of all the implemented interfaces (as described in a-tags.adb).
4825 -- TSD : Type_Specific_Data (I_Depth) :=
4826 -- (Idepth => I_Depth,
4827 -- Access_Level => Type_Access_Level (Typ),
4828 -- Alignment => Typ'Alignment,
4829 -- Expanded_Name => Cstring_Ptr!(Exname'Address))
4830 -- External_Tag => Cstring_Ptr!(Exname'Address))
4831 -- HT_Link => HT_Link'Address,
4832 -- Transportable => <<boolean-value>>,
4833 -- Type_Is_Abstract => <<boolean-value>>,
4834 -- Needs_Finalization => <<boolean-value>>,
4835 -- [ Size_Func => Size_Prim'Access, ]
4836 -- [ Interfaces_Table => <<access-value>>, ]
4837 -- [ SSD => SSD_Table'Address ]
4838 -- Tags_Table => (0 => null,
4841 -- for TSD'Alignment use Address'Alignment
4843 TSD_Aggr_List
:= New_List
;
4845 -- Idepth: Count ancestors to compute the inheritance depth. For private
4846 -- extensions, always go to the full view in order to compute the real
4847 -- inheritance depth.
4850 Current_Typ
: Entity_Id
;
4851 Parent_Typ
: Entity_Id
;
4857 Parent_Typ
:= Etype
(Current_Typ
);
4859 if Is_Private_Type
(Parent_Typ
) then
4860 Parent_Typ
:= Full_View
(Base_Type
(Parent_Typ
));
4863 exit when Parent_Typ
= Current_Typ
;
4865 I_Depth
:= I_Depth
+ 1;
4866 Current_Typ
:= Parent_Typ
;
4870 Append_To
(TSD_Aggr_List
,
4871 Make_Integer_Literal
(Loc
, I_Depth
));
4875 Append_To
(TSD_Aggr_List
,
4876 Make_Integer_Literal
(Loc
, Type_Access_Level
(Typ
)));
4880 -- For CPP types we cannot rely on the value of 'Alignment provided
4881 -- by the backend to initialize this TSD field.
4883 if Convention
(Typ
) = Convention_CPP
4884 or else Is_CPP_Class
(Root_Type
(Typ
))
4886 Append_To
(TSD_Aggr_List
,
4887 Make_Integer_Literal
(Loc
, 0));
4889 Append_To
(TSD_Aggr_List
,
4890 Make_Attribute_Reference
(Loc
,
4891 Prefix
=> New_Occurrence_Of
(Typ
, Loc
),
4892 Attribute_Name
=> Name_Alignment
));
4897 Append_To
(TSD_Aggr_List
,
4898 Unchecked_Convert_To
(RTE
(RE_Cstring_Ptr
),
4899 Make_Attribute_Reference
(Loc
,
4900 Prefix
=> New_Occurrence_Of
(Exname
, Loc
),
4901 Attribute_Name
=> Name_Address
)));
4903 -- External_Tag of a local tagged type
4905 -- <typ>A : constant String :=
4906 -- "Internal tag at 16#tag-addr#: <full-name-of-typ>";
4908 -- The reason we generate this strange name is that we do not want to
4909 -- enter local tagged types in the global hash table used to compute
4910 -- the Internal_Tag attribute for two reasons:
4912 -- 1. It is hard to avoid a tasking race condition for entering the
4913 -- entry into the hash table.
4915 -- 2. It would cause a storage leak, unless we rig up considerable
4916 -- mechanism to remove the entry from the hash table on exit.
4918 -- So what we do is to generate the above external tag name, where the
4919 -- hex address is the address of the local dispatch table (i.e. exactly
4920 -- the value we want if Internal_Tag is computed from this string).
4922 -- Of course this value will only be valid if the tagged type is still
4923 -- in scope, but it clearly must be erroneous to compute the internal
4924 -- tag of a tagged type that is out of scope.
4926 -- We don't do this processing if an explicit external tag has been
4927 -- specified. That's an odd case for which we have already issued a
4928 -- warning, where we will not be able to compute the internal tag.
4930 if not Is_Library_Level_Entity
(Typ
)
4931 and then not Has_External_Tag_Rep_Clause
(Typ
)
4934 Exname
: constant Entity_Id
:=
4935 Make_Defining_Identifier
(Loc
,
4936 Chars
=> New_External_Name
(Tname
, 'A'));
4937 Full_Name
: constant String_Id
:=
4938 Fully_Qualified_Name_String
(First_Subtype
(Typ
));
4939 Str1_Id
: String_Id
;
4940 Str2_Id
: String_Id
;
4944 -- Str1 = "Internal tag at 16#";
4947 Store_String_Chars
("Internal tag at 16#");
4948 Str1_Id
:= End_String
;
4951 -- Str2 = "#: <type-full-name>";
4954 Store_String_Chars
("#: ");
4955 Store_String_Chars
(Full_Name
);
4956 Str2_Id
:= End_String
;
4959 -- Exname : constant String :=
4960 -- Str1 & Address_Image (Tag) & Str2;
4962 if RTE_Available
(RE_Address_Image
) then
4964 Make_Object_Declaration
(Loc
,
4965 Defining_Identifier
=> Exname
,
4966 Constant_Present
=> True,
4967 Object_Definition
=> New_Occurrence_Of
4968 (Standard_String
, Loc
),
4970 Make_Op_Concat
(Loc
,
4971 Left_Opnd
=> Make_String_Literal
(Loc
, Str1_Id
),
4973 Make_Op_Concat
(Loc
,
4975 Make_Function_Call
(Loc
,
4978 (RTE
(RE_Address_Image
), Loc
),
4979 Parameter_Associations
=> New_List
(
4980 Unchecked_Convert_To
(RTE
(RE_Address
),
4981 New_Occurrence_Of
(DT_Ptr
, Loc
)))),
4983 Make_String_Literal
(Loc
, Str2_Id
)))));
4987 Make_Object_Declaration
(Loc
,
4988 Defining_Identifier
=> Exname
,
4989 Constant_Present
=> True,
4990 Object_Definition
=>
4991 New_Occurrence_Of
(Standard_String
, Loc
),
4993 Make_Op_Concat
(Loc
,
4994 Left_Opnd
=> Make_String_Literal
(Loc
, Str1_Id
),
4995 Right_Opnd
=> Make_String_Literal
(Loc
, Str2_Id
))));
4999 Unchecked_Convert_To
(RTE
(RE_Cstring_Ptr
),
5000 Make_Attribute_Reference
(Loc
,
5001 Prefix
=> New_Occurrence_Of
(Exname
, Loc
),
5002 Attribute_Name
=> Name_Address
));
5005 -- External tag of a library-level tagged type: Check for a definition
5006 -- of External_Tag. The clause is considered only if it applies to this
5007 -- specific tagged type, as opposed to one of its ancestors.
5008 -- If the type is an unconstrained type extension, we are building the
5009 -- dispatch table of its anonymous base type, so the external tag, if
5010 -- any was specified, must be retrieved from the first subtype. Go to
5011 -- the full view in case the clause is in the private part.
5015 Def
: constant Node_Id
:= Get_Attribute_Definition_Clause
5016 (Underlying_Type
(First_Subtype
(Typ
)),
5017 Attribute_External_Tag
);
5019 Old_Val
: String_Id
;
5020 New_Val
: String_Id
;
5024 if not Present
(Def
)
5025 or else Entity
(Name
(Def
)) /= First_Subtype
(Typ
)
5028 Unchecked_Convert_To
(RTE
(RE_Cstring_Ptr
),
5029 Make_Attribute_Reference
(Loc
,
5030 Prefix
=> New_Occurrence_Of
(Exname
, Loc
),
5031 Attribute_Name
=> Name_Address
));
5033 Old_Val
:= Strval
(Expr_Value_S
(Expression
(Def
)));
5035 -- For the rep clause "for <typ>'external_tag use y" generate:
5037 -- <typ>A : constant string := y;
5039 -- <typ>A'Address is used to set the External_Tag component
5042 -- Create a new nul terminated string if it is not already
5044 if String_Length
(Old_Val
) > 0
5046 Get_String_Char
(Old_Val
, String_Length
(Old_Val
)) = 0
5050 Start_String
(Old_Val
);
5051 Store_String_Char
(Get_Char_Code
(ASCII
.NUL
));
5052 New_Val
:= End_String
;
5055 E
:= Make_Defining_Identifier
(Loc
,
5056 New_External_Name
(Chars
(Typ
), 'A'));
5059 Make_Object_Declaration
(Loc
,
5060 Defining_Identifier
=> E
,
5061 Constant_Present
=> True,
5062 Object_Definition
=>
5063 New_Occurrence_Of
(Standard_String
, Loc
),
5065 Make_String_Literal
(Loc
, New_Val
)));
5068 Unchecked_Convert_To
(RTE
(RE_Cstring_Ptr
),
5069 Make_Attribute_Reference
(Loc
,
5070 Prefix
=> New_Occurrence_Of
(E
, Loc
),
5071 Attribute_Name
=> Name_Address
));
5076 Append_To
(TSD_Aggr_List
, New_Node
);
5080 if RTE_Available
(RE_Register_Tag
) then
5081 Append_To
(TSD_Aggr_List
,
5082 Unchecked_Convert_To
(RTE
(RE_Tag_Ptr
),
5083 Make_Attribute_Reference
(Loc
,
5084 Prefix
=> New_Occurrence_Of
(HT_Link
, Loc
),
5085 Attribute_Name
=> Name_Address
)));
5087 Append_To
(TSD_Aggr_List
,
5088 Unchecked_Convert_To
(RTE
(RE_Tag_Ptr
),
5089 New_Occurrence_Of
(RTE
(RE_Null_Address
), Loc
)));
5092 -- Transportable: Set for types that can be used in remote calls
5093 -- with respect to E.4(18) legality rules.
5096 Transportable
: Entity_Id
;
5102 or else Is_Shared_Passive
(Typ
)
5104 ((Is_Remote_Types
(Typ
)
5105 or else Is_Remote_Call_Interface
(Typ
))
5106 and then Original_View_In_Visible_Part
(Typ
))
5107 or else not Comes_From_Source
(Typ
));
5109 Append_To
(TSD_Aggr_List
,
5110 New_Occurrence_Of
(Transportable
, Loc
));
5113 -- Type_Is_Abstract (Ada 2012: AI05-0173). This functionality is
5114 -- not available in the HIE runtime.
5116 if RTE_Record_Component_Available
(RE_Type_Is_Abstract
) then
5118 Type_Is_Abstract
: Entity_Id
;
5120 Type_Is_Abstract
:= Boolean_Literals
(Is_Abstract_Type
(Typ
));
5121 Append_To
(TSD_Aggr_List
,
5122 New_Occurrence_Of
(Type_Is_Abstract
, Loc
));
5126 -- Needs_Finalization: Set if the type is controlled or has controlled
5130 Needs_Fin
: Entity_Id
;
5132 Needs_Fin
:= Boolean_Literals
(Needs_Finalization
(Typ
));
5133 Append_To
(TSD_Aggr_List
, New_Occurrence_Of
(Needs_Fin
, Loc
));
5138 if RTE_Record_Component_Available
(RE_Size_Func
) then
5140 -- Initialize this field to Null_Address if we are not building
5141 -- static dispatch tables static or if the size function is not
5142 -- available. In the former case we cannot initialize this field
5143 -- until the function is frozen and registered in the dispatch
5144 -- table (see Register_Primitive).
5146 if not Building_Static_DT
(Typ
) or else not Has_DT
(Typ
) then
5147 Append_To
(TSD_Aggr_List
,
5148 Unchecked_Convert_To
(RTE
(RE_Size_Ptr
),
5149 New_Occurrence_Of
(RTE
(RE_Null_Address
), Loc
)));
5153 Prim_Elmt
: Elmt_Id
;
5155 Size_Comp
: Node_Id
;
5158 Prim_Elmt
:= First_Elmt
(Primitive_Operations
(Typ
));
5159 while Present
(Prim_Elmt
) loop
5160 Prim
:= Node
(Prim_Elmt
);
5162 if Chars
(Prim
) = Name_uSize
then
5163 Prim
:= Ultimate_Alias
(Prim
);
5165 if Is_Abstract_Subprogram
(Prim
) then
5167 Unchecked_Convert_To
(RTE
(RE_Size_Ptr
),
5168 New_Occurrence_Of
(RTE
(RE_Null_Address
), Loc
));
5171 Unchecked_Convert_To
(RTE
(RE_Size_Ptr
),
5172 Make_Attribute_Reference
(Loc
,
5173 Prefix
=> New_Occurrence_Of
(Prim
, Loc
),
5174 Attribute_Name
=> Name_Unrestricted_Access
));
5180 Next_Elmt
(Prim_Elmt
);
5183 pragma Assert
(Present
(Size_Comp
));
5184 Append_To
(TSD_Aggr_List
, Size_Comp
);
5189 -- Interfaces_Table (required for AI-405)
5191 if RTE_Record_Component_Available
(RE_Interfaces_Table
) then
5193 -- Count the number of interface types implemented by Typ
5195 Collect_Interfaces
(Typ
, Typ_Ifaces
);
5197 AI
:= First_Elmt
(Typ_Ifaces
);
5198 while Present
(AI
) loop
5199 Num_Ifaces
:= Num_Ifaces
+ 1;
5203 if Num_Ifaces
= 0 then
5204 Iface_Table_Node
:= Make_Null
(Loc
);
5206 -- Generate the Interface_Table object
5210 TSD_Ifaces_List
: constant List_Id
:= New_List
;
5212 Sec_DT_Tag
: Node_Id
;
5215 AI
:= First_Elmt
(Typ_Ifaces
);
5216 while Present
(AI
) loop
5217 if Is_Ancestor
(Node
(AI
), Typ
, Use_Full_View
=> True) then
5219 New_Occurrence_Of
(DT_Ptr
, Loc
);
5223 (Next_Elmt
(First_Elmt
(Access_Disp_Table
(Typ
))));
5224 pragma Assert
(Has_Thunks
(Node
(Elmt
)));
5226 while Is_Tag
(Node
(Elmt
))
5228 Is_Ancestor
(Node
(AI
), Related_Type
(Node
(Elmt
)),
5229 Use_Full_View
=> True)
5231 pragma Assert
(Has_Thunks
(Node
(Elmt
)));
5233 pragma Assert
(Has_Thunks
(Node
(Elmt
)));
5235 pragma Assert
(not Has_Thunks
(Node
(Elmt
)));
5237 pragma Assert
(not Has_Thunks
(Node
(Elmt
)));
5241 pragma Assert
(Ekind
(Node
(Elmt
)) = E_Constant
5243 Has_Thunks
(Node
(Next_Elmt
(Next_Elmt
(Elmt
)))));
5245 New_Occurrence_Of
(Node
(Next_Elmt
(Next_Elmt
(Elmt
))),
5249 Append_To
(TSD_Ifaces_List
,
5250 Make_Aggregate
(Loc
,
5251 Expressions
=> New_List
(
5255 Unchecked_Convert_To
(RTE
(RE_Tag
),
5257 (Node
(First_Elmt
(Access_Disp_Table
(Node
(AI
)))),
5260 -- Static_Offset_To_Top
5262 New_Occurrence_Of
(Standard_True
, Loc
),
5264 -- Offset_To_Top_Value
5266 Make_Integer_Literal
(Loc
, 0),
5268 -- Offset_To_Top_Func
5274 Unchecked_Convert_To
(RTE
(RE_Tag
), Sec_DT_Tag
)
5281 Name_ITable
:= New_External_Name
(Tname
, 'I');
5282 ITable
:= Make_Defining_Identifier
(Loc
, Name_ITable
);
5283 Set_Is_Statically_Allocated
(ITable
,
5284 Is_Library_Level_Tagged_Type
(Typ
));
5286 -- The table of interfaces is not constant; its slots are
5287 -- filled at run time by the IP routine using attribute
5288 -- 'Position to know the location of the tag components
5289 -- (and this attribute cannot be safely used before the
5290 -- object is initialized).
5293 Make_Object_Declaration
(Loc
,
5294 Defining_Identifier
=> ITable
,
5295 Aliased_Present
=> True,
5296 Constant_Present
=> False,
5297 Object_Definition
=>
5298 Make_Subtype_Indication
(Loc
,
5300 New_Occurrence_Of
(RTE
(RE_Interface_Data
), Loc
),
5302 Make_Index_Or_Discriminant_Constraint
(Loc
,
5303 Constraints
=> New_List
(
5304 Make_Integer_Literal
(Loc
, Num_Ifaces
)))),
5306 Expression
=> Make_Aggregate
(Loc
,
5307 Expressions
=> New_List
(
5308 Make_Integer_Literal
(Loc
, Num_Ifaces
),
5309 Make_Aggregate
(Loc
, TSD_Ifaces_List
)))));
5312 Make_Attribute_Definition_Clause
(Loc
,
5313 Name
=> New_Occurrence_Of
(ITable
, Loc
),
5314 Chars
=> Name_Alignment
,
5316 Make_Attribute_Reference
(Loc
,
5318 New_Occurrence_Of
(RTE
(RE_Integer_Address
), Loc
),
5319 Attribute_Name
=> Name_Alignment
)));
5322 Make_Attribute_Reference
(Loc
,
5323 Prefix
=> New_Occurrence_Of
(ITable
, Loc
),
5324 Attribute_Name
=> Name_Unchecked_Access
);
5328 Append_To
(TSD_Aggr_List
, Iface_Table_Node
);
5331 -- Generate the Select Specific Data table for synchronized types that
5332 -- implement synchronized interfaces. The size of the table is
5333 -- constrained by the number of non-predefined primitive operations.
5335 if RTE_Record_Component_Available
(RE_SSD
) then
5336 if Ada_Version
>= Ada_2005
5337 and then Has_DT
(Typ
)
5338 and then Is_Concurrent_Record_Type
(Typ
)
5339 and then Has_Interfaces
(Typ
)
5340 and then Nb_Prim
> 0
5341 and then not Is_Abstract_Type
(Typ
)
5342 and then not Is_Controlled
(Typ
)
5343 and then not Restriction_Active
(No_Dispatching_Calls
)
5344 and then not Restriction_Active
(No_Select_Statements
)
5347 Make_Object_Declaration
(Loc
,
5348 Defining_Identifier
=> SSD
,
5349 Aliased_Present
=> True,
5350 Object_Definition
=>
5351 Make_Subtype_Indication
(Loc
,
5352 Subtype_Mark
=> New_Occurrence_Of
(
5353 RTE
(RE_Select_Specific_Data
), Loc
),
5355 Make_Index_Or_Discriminant_Constraint
(Loc
,
5356 Constraints
=> New_List
(
5357 Make_Integer_Literal
(Loc
, Nb_Prim
))))));
5360 Make_Attribute_Definition_Clause
(Loc
,
5361 Name
=> New_Occurrence_Of
(SSD
, Loc
),
5362 Chars
=> Name_Alignment
,
5364 Make_Attribute_Reference
(Loc
,
5366 New_Occurrence_Of
(RTE
(RE_Integer_Address
), Loc
),
5367 Attribute_Name
=> Name_Alignment
)));
5369 -- This table is initialized by Make_Select_Specific_Data_Table,
5370 -- which calls Set_Entry_Index and Set_Prim_Op_Kind.
5372 Append_To
(TSD_Aggr_List
,
5373 Make_Attribute_Reference
(Loc
,
5374 Prefix
=> New_Occurrence_Of
(SSD
, Loc
),
5375 Attribute_Name
=> Name_Unchecked_Access
));
5377 Append_To
(TSD_Aggr_List
, Make_Null
(Loc
));
5381 -- Initialize the table of ancestor tags. In case of interface types
5382 -- this table is not needed.
5384 TSD_Tags_List
:= New_List
;
5386 -- If we are not statically allocating the dispatch table then we must
5387 -- fill position 0 with null because we still have not generated the
5390 if not Building_Static_DT
(Typ
)
5391 or else Is_Interface
(Typ
)
5393 Append_To
(TSD_Tags_List
,
5394 Unchecked_Convert_To
(RTE
(RE_Tag
),
5395 New_Occurrence_Of
(RTE
(RE_Null_Address
), Loc
)));
5397 -- Otherwise we can safely reference the tag
5400 Append_To
(TSD_Tags_List
,
5401 New_Occurrence_Of
(DT_Ptr
, Loc
));
5404 -- Fill the rest of the table with the tags of the ancestors
5407 Current_Typ
: Entity_Id
;
5408 Parent_Typ
: Entity_Id
;
5416 Parent_Typ
:= Etype
(Current_Typ
);
5418 if Is_Private_Type
(Parent_Typ
) then
5419 Parent_Typ
:= Full_View
(Base_Type
(Parent_Typ
));
5422 exit when Parent_Typ
= Current_Typ
;
5424 if Is_CPP_Class
(Parent_Typ
) then
5426 -- The tags defined in the C++ side will be inherited when
5427 -- the object is constructed (Exp_Ch3.Build_Init_Procedure)
5429 Append_To
(TSD_Tags_List
,
5430 Unchecked_Convert_To
(RTE
(RE_Tag
),
5431 New_Occurrence_Of
(RTE
(RE_Null_Address
), Loc
)));
5433 Append_To
(TSD_Tags_List
,
5435 (Node
(First_Elmt
(Access_Disp_Table
(Parent_Typ
))),
5440 Current_Typ
:= Parent_Typ
;
5443 pragma Assert
(Pos
= I_Depth
+ 1);
5446 Append_To
(TSD_Aggr_List
,
5447 Make_Aggregate
(Loc
,
5448 Expressions
=> TSD_Tags_List
));
5450 -- Build the TSD object
5453 Make_Object_Declaration
(Loc
,
5454 Defining_Identifier
=> TSD
,
5455 Aliased_Present
=> True,
5456 Constant_Present
=> Building_Static_DT
(Typ
),
5457 Object_Definition
=>
5458 Make_Subtype_Indication
(Loc
,
5459 Subtype_Mark
=> New_Occurrence_Of
(
5460 RTE
(RE_Type_Specific_Data
), Loc
),
5462 Make_Index_Or_Discriminant_Constraint
(Loc
,
5463 Constraints
=> New_List
(
5464 Make_Integer_Literal
(Loc
, I_Depth
)))),
5466 Expression
=> Make_Aggregate
(Loc
,
5467 Expressions
=> TSD_Aggr_List
)));
5469 Set_Is_True_Constant
(TSD
, Building_Static_DT
(Typ
));
5472 Make_Attribute_Definition_Clause
(Loc
,
5473 Name
=> New_Occurrence_Of
(TSD
, Loc
),
5474 Chars
=> Name_Alignment
,
5476 Make_Attribute_Reference
(Loc
,
5478 New_Occurrence_Of
(RTE
(RE_Integer_Address
), Loc
),
5479 Attribute_Name
=> Name_Alignment
)));
5481 -- Initialize or declare the dispatch table object
5483 if not Has_DT
(Typ
) then
5484 DT_Constr_List
:= New_List
;
5485 DT_Aggr_List
:= New_List
;
5490 Make_Attribute_Reference
(Loc
,
5491 Prefix
=> New_Occurrence_Of
(TSD
, Loc
),
5492 Attribute_Name
=> Name_Address
);
5494 Append_To
(DT_Constr_List
, New_Node
);
5495 Append_To
(DT_Aggr_List
, New_Copy
(New_Node
));
5496 Append_To
(DT_Aggr_List
, Make_Integer_Literal
(Loc
, 0));
5498 -- In case of locally defined tagged types we have already declared
5499 -- and uninitialized object for the dispatch table, which is now
5500 -- initialized by means of the following assignment:
5502 -- DT := (TSD'Address, 0);
5504 if not Building_Static_DT
(Typ
) then
5506 Make_Assignment_Statement
(Loc
,
5507 Name
=> New_Occurrence_Of
(DT
, Loc
),
5508 Expression
=> Make_Aggregate
(Loc
, DT_Aggr_List
)));
5510 -- In case of library level tagged types we declare and export now
5511 -- the constant object containing the dummy dispatch table. There
5512 -- is no need to declare the tag here because it has been previously
5513 -- declared by Make_Tags
5515 -- DT : aliased constant No_Dispatch_Table :=
5516 -- (NDT_TSD => TSD'Address;
5517 -- NDT_Prims_Ptr => 0);
5518 -- for DT'Alignment use Address'Alignment;
5522 Make_Object_Declaration
(Loc
,
5523 Defining_Identifier
=> DT
,
5524 Aliased_Present
=> True,
5525 Constant_Present
=> True,
5526 Object_Definition
=>
5527 New_Occurrence_Of
(RTE
(RE_No_Dispatch_Table_Wrapper
), Loc
),
5528 Expression
=> Make_Aggregate
(Loc
, DT_Aggr_List
)));
5531 Make_Attribute_Definition_Clause
(Loc
,
5532 Name
=> New_Occurrence_Of
(DT
, Loc
),
5533 Chars
=> Name_Alignment
,
5535 Make_Attribute_Reference
(Loc
,
5537 New_Occurrence_Of
(RTE
(RE_Integer_Address
), Loc
),
5538 Attribute_Name
=> Name_Alignment
)));
5540 Export_DT
(Typ
, DT
);
5543 -- Common case: Typ has a dispatch table
5547 -- Predef_Prims : Address_Array (1 .. Default_Prim_Ops_Count) :=
5548 -- (predef-prim-op-1'address,
5549 -- predef-prim-op-2'address,
5551 -- predef-prim-op-n'address);
5552 -- for Predef_Prims'Alignment use Address'Alignment
5554 -- DT : Dispatch_Table (Nb_Prims) :=
5555 -- (Signature => <sig-value>,
5556 -- Tag_Kind => <tag_kind-value>,
5557 -- Predef_Prims => Predef_Prims'First'Address,
5558 -- Offset_To_Top => 0,
5559 -- TSD => TSD'Address;
5560 -- Prims_Ptr => (prim-op-1'address,
5561 -- prim-op-2'address,
5563 -- prim-op-n'address));
5564 -- for DT'Alignment use Address'Alignment
5571 if not Building_Static_DT
(Typ
) then
5572 Nb_Predef_Prims
:= Max_Predef_Prims
;
5575 Prim_Elmt
:= First_Elmt
(Primitive_Operations
(Typ
));
5576 while Present
(Prim_Elmt
) loop
5577 Prim
:= Node
(Prim_Elmt
);
5579 if Is_Predefined_Dispatching_Operation
(Prim
)
5580 and then not Is_Abstract_Subprogram
(Prim
)
5582 Pos
:= UI_To_Int
(DT_Position
(Prim
));
5584 if Pos
> Nb_Predef_Prims
then
5585 Nb_Predef_Prims
:= Pos
;
5589 Next_Elmt
(Prim_Elmt
);
5595 (Nat
range 1 .. Nb_Predef_Prims
) of Entity_Id
;
5600 Prim_Ops_Aggr_List
:= New_List
;
5602 Prim_Table
:= (others => Empty
);
5604 if Building_Static_DT
(Typ
) then
5605 Prim_Elmt
:= First_Elmt
(Primitive_Operations
(Typ
));
5606 while Present
(Prim_Elmt
) loop
5607 Prim
:= Node
(Prim_Elmt
);
5609 if Is_Predefined_Dispatching_Operation
(Prim
)
5610 and then not Is_Abstract_Subprogram
(Prim
)
5611 and then not Is_Eliminated
(Prim
)
5612 and then not Present
(Prim_Table
5613 (UI_To_Int
(DT_Position
(Prim
))))
5615 E
:= Ultimate_Alias
(Prim
);
5616 pragma Assert
(not Is_Abstract_Subprogram
(E
));
5617 Prim_Table
(UI_To_Int
(DT_Position
(Prim
))) := E
;
5620 Next_Elmt
(Prim_Elmt
);
5624 for J
in Prim_Table
'Range loop
5625 if Present
(Prim_Table
(J
)) then
5627 Unchecked_Convert_To
(RTE
(RE_Prim_Ptr
),
5628 Make_Attribute_Reference
(Loc
,
5630 New_Occurrence_Of
(Prim_Table
(J
), Loc
),
5631 Attribute_Name
=> Name_Unrestricted_Access
));
5633 New_Node
:= Make_Null
(Loc
);
5636 Append_To
(Prim_Ops_Aggr_List
, New_Node
);
5640 Make_Aggregate
(Loc
,
5641 Expressions
=> Prim_Ops_Aggr_List
);
5644 Make_Subtype_Declaration
(Loc
,
5645 Defining_Identifier
=> Make_Temporary
(Loc
, 'S'),
5646 Subtype_Indication
=>
5647 New_Occurrence_Of
(RTE
(RE_Address_Array
), Loc
));
5649 Append_To
(Result
, Decl
);
5652 Make_Object_Declaration
(Loc
,
5653 Defining_Identifier
=> Predef_Prims
,
5654 Aliased_Present
=> True,
5655 Constant_Present
=> Building_Static_DT
(Typ
),
5656 Object_Definition
=>
5657 New_Occurrence_Of
(Defining_Identifier
(Decl
), Loc
),
5658 Expression
=> New_Node
));
5660 -- Remember aggregates initializing dispatch tables
5662 Append_Elmt
(New_Node
, DT_Aggr
);
5665 Make_Attribute_Definition_Clause
(Loc
,
5666 Name
=> New_Occurrence_Of
(Predef_Prims
, Loc
),
5667 Chars
=> Name_Alignment
,
5669 Make_Attribute_Reference
(Loc
,
5671 New_Occurrence_Of
(RTE
(RE_Integer_Address
), Loc
),
5672 Attribute_Name
=> Name_Alignment
)));
5676 -- Stage 1: Initialize the discriminant and the record components
5678 DT_Constr_List
:= New_List
;
5679 DT_Aggr_List
:= New_List
;
5681 -- Num_Prims. If the tagged type has no primitives we add a dummy
5682 -- slot whose address will be the tag of this type.
5685 New_Node
:= Make_Integer_Literal
(Loc
, 1);
5687 New_Node
:= Make_Integer_Literal
(Loc
, Nb_Prim
);
5690 Append_To
(DT_Constr_List
, New_Node
);
5691 Append_To
(DT_Aggr_List
, New_Copy
(New_Node
));
5695 if RTE_Record_Component_Available
(RE_Signature
) then
5696 Append_To
(DT_Aggr_List
,
5697 New_Occurrence_Of
(RTE
(RE_Primary_DT
), Loc
));
5702 if RTE_Record_Component_Available
(RE_Tag_Kind
) then
5703 Append_To
(DT_Aggr_List
, Tagged_Kind
(Typ
));
5708 Append_To
(DT_Aggr_List
,
5709 Make_Attribute_Reference
(Loc
,
5710 Prefix
=> New_Occurrence_Of
(Predef_Prims
, Loc
),
5711 Attribute_Name
=> Name_Address
));
5715 Append_To
(DT_Aggr_List
, Make_Integer_Literal
(Loc
, 0));
5719 Append_To
(DT_Aggr_List
,
5720 Make_Attribute_Reference
(Loc
,
5721 Prefix
=> New_Occurrence_Of
(TSD
, Loc
),
5722 Attribute_Name
=> Name_Address
));
5724 -- Stage 2: Initialize the table of user-defined primitive operations
5726 Prim_Ops_Aggr_List
:= New_List
;
5729 Append_To
(Prim_Ops_Aggr_List
, Make_Null
(Loc
));
5731 elsif not Building_Static_DT
(Typ
) then
5732 for J
in 1 .. Nb_Prim
loop
5733 Append_To
(Prim_Ops_Aggr_List
, Make_Null
(Loc
));
5738 CPP_Nb_Prims
: constant Nat
:= CPP_Num_Prims
(Typ
);
5741 Prim_Elmt
: Elmt_Id
;
5743 Prim_Table
: array (Nat
range 1 .. Nb_Prim
) of Entity_Id
;
5746 Prim_Table
:= (others => Empty
);
5748 Prim_Elmt
:= First_Elmt
(Primitive_Operations
(Typ
));
5749 while Present
(Prim_Elmt
) loop
5750 Prim
:= Node
(Prim_Elmt
);
5752 -- Retrieve the ultimate alias of the primitive for proper
5753 -- handling of renamings and eliminated primitives.
5755 E
:= Ultimate_Alias
(Prim
);
5756 Prim_Pos
:= UI_To_Int
(DT_Position
(E
));
5758 -- Do not reference predefined primitives because they are
5759 -- located in a separate dispatch table; skip entities with
5760 -- attribute Interface_Alias because they are only required
5761 -- to build secondary dispatch tables; skip abstract and
5762 -- eliminated primitives; for derivations of CPP types skip
5763 -- primitives located in the C++ part of the dispatch table
5764 -- because their slot is initialized by the IC routine.
5766 if not Is_Predefined_Dispatching_Operation
(Prim
)
5767 and then not Is_Predefined_Dispatching_Operation
(E
)
5768 and then not Present
(Interface_Alias
(Prim
))
5769 and then not Is_Abstract_Subprogram
(E
)
5770 and then not Is_Eliminated
(E
)
5771 and then (not Is_CPP_Class
(Root_Type
(Typ
))
5772 or else Prim_Pos
> CPP_Nb_Prims
)
5775 (UI_To_Int
(DT_Position
(Prim
)) <= Nb_Prim
);
5777 Prim_Table
(UI_To_Int
(DT_Position
(Prim
))) := E
;
5780 Next_Elmt
(Prim_Elmt
);
5783 for J
in Prim_Table
'Range loop
5784 if Present
(Prim_Table
(J
)) then
5786 Unchecked_Convert_To
(RTE
(RE_Prim_Ptr
),
5787 Make_Attribute_Reference
(Loc
,
5789 New_Occurrence_Of
(Prim_Table
(J
), Loc
),
5790 Attribute_Name
=> Name_Unrestricted_Access
));
5792 New_Node
:= Make_Null
(Loc
);
5795 Append_To
(Prim_Ops_Aggr_List
, New_Node
);
5801 Make_Aggregate
(Loc
,
5802 Expressions
=> Prim_Ops_Aggr_List
);
5804 Append_To
(DT_Aggr_List
, New_Node
);
5806 -- Remember aggregates initializing dispatch tables
5808 Append_Elmt
(New_Node
, DT_Aggr
);
5810 -- In case of locally defined tagged types we have already declared
5811 -- and uninitialized object for the dispatch table, which is now
5812 -- initialized by means of an assignment.
5814 if not Building_Static_DT
(Typ
) then
5816 Make_Assignment_Statement
(Loc
,
5817 Name
=> New_Occurrence_Of
(DT
, Loc
),
5818 Expression
=> Make_Aggregate
(Loc
, DT_Aggr_List
)));
5820 -- In case of library level tagged types we declare now and export
5821 -- the constant object containing the dispatch table.
5825 Make_Object_Declaration
(Loc
,
5826 Defining_Identifier
=> DT
,
5827 Aliased_Present
=> True,
5828 Constant_Present
=> True,
5829 Object_Definition
=>
5830 Make_Subtype_Indication
(Loc
,
5831 Subtype_Mark
=> New_Occurrence_Of
5832 (RTE
(RE_Dispatch_Table_Wrapper
), Loc
),
5833 Constraint
=> Make_Index_Or_Discriminant_Constraint
(Loc
,
5834 Constraints
=> DT_Constr_List
)),
5835 Expression
=> Make_Aggregate
(Loc
, DT_Aggr_List
)));
5838 Make_Attribute_Definition_Clause
(Loc
,
5839 Name
=> New_Occurrence_Of
(DT
, Loc
),
5840 Chars
=> Name_Alignment
,
5842 Make_Attribute_Reference
(Loc
,
5844 New_Occurrence_Of
(RTE
(RE_Integer_Address
), Loc
),
5845 Attribute_Name
=> Name_Alignment
)));
5847 Export_DT
(Typ
, DT
);
5851 -- Initialize the table of ancestor tags if not building static
5854 if not Building_Static_DT
(Typ
)
5855 and then not Is_Interface
(Typ
)
5856 and then not Is_CPP_Class
(Typ
)
5859 Make_Assignment_Statement
(Loc
,
5861 Make_Indexed_Component
(Loc
,
5863 Make_Selected_Component
(Loc
,
5864 Prefix
=> New_Occurrence_Of
(TSD
, Loc
),
5867 (RTE_Record_Component
(RE_Tags_Table
), Loc
)),
5869 New_List
(Make_Integer_Literal
(Loc
, 0))),
5873 (Node
(First_Elmt
(Access_Disp_Table
(Typ
))), Loc
)));
5876 -- Inherit the dispatch tables of the parent. There is no need to
5877 -- inherit anything from the parent when building static dispatch tables
5878 -- because the whole dispatch table (including inherited primitives) has
5879 -- been already built.
5881 if Building_Static_DT
(Typ
) then
5884 -- If the ancestor is a CPP_Class type we inherit the dispatch tables
5885 -- in the init proc, and we don't need to fill them in here.
5887 elsif Is_CPP_Class
(Parent_Typ
) then
5890 -- Otherwise we fill in the dispatch tables here
5893 if Typ
/= Parent_Typ
5894 and then not Is_Interface
(Typ
)
5895 and then not Restriction_Active
(No_Dispatching_Calls
)
5897 -- Inherit the dispatch table
5899 if not Is_Interface
(Typ
)
5900 and then not Is_Interface
(Parent_Typ
)
5901 and then not Is_CPP_Class
(Parent_Typ
)
5904 Nb_Prims
: constant Int
:=
5905 UI_To_Int
(DT_Entry_Count
5906 (First_Tag_Component
(Parent_Typ
)));
5909 Append_To
(Elab_Code
,
5910 Build_Inherit_Predefined_Prims
(Loc
,
5916 (Access_Disp_Table
(Parent_Typ
)))), Loc
),
5922 (Access_Disp_Table
(Typ
)))), Loc
)));
5924 if Nb_Prims
/= 0 then
5925 Append_To
(Elab_Code
,
5926 Build_Inherit_Prims
(Loc
,
5932 (Access_Disp_Table
(Parent_Typ
))), Loc
),
5933 New_Tag_Node
=> New_Occurrence_Of
(DT_Ptr
, Loc
),
5934 Num_Prims
=> Nb_Prims
));
5939 -- Inherit the secondary dispatch tables of the ancestor
5941 if not Is_CPP_Class
(Parent_Typ
) then
5943 Sec_DT_Ancestor
: Elmt_Id
:=
5949 Sec_DT_Typ
: Elmt_Id
:=
5953 (Access_Disp_Table
(Typ
))));
5955 procedure Copy_Secondary_DTs
(Typ
: Entity_Id
);
5956 -- Local procedure required to climb through the ancestors
5957 -- and copy the contents of all their secondary dispatch
5960 ------------------------
5961 -- Copy_Secondary_DTs --
5962 ------------------------
5964 procedure Copy_Secondary_DTs
(Typ
: Entity_Id
) is
5969 -- Climb to the ancestor (if any) handling private types
5971 if Present
(Full_View
(Etype
(Typ
))) then
5972 if Full_View
(Etype
(Typ
)) /= Typ
then
5973 Copy_Secondary_DTs
(Full_View
(Etype
(Typ
)));
5976 elsif Etype
(Typ
) /= Typ
then
5977 Copy_Secondary_DTs
(Etype
(Typ
));
5980 if Present
(Interfaces
(Typ
))
5981 and then not Is_Empty_Elmt_List
(Interfaces
(Typ
))
5983 Iface
:= First_Elmt
(Interfaces
(Typ
));
5984 E
:= First_Entity
(Typ
);
5986 and then Present
(Node
(Sec_DT_Ancestor
))
5987 and then Ekind
(Node
(Sec_DT_Ancestor
)) = E_Constant
5989 if Is_Tag
(E
) and then Chars
(E
) /= Name_uTag
then
5991 Num_Prims
: constant Int
:=
5992 UI_To_Int
(DT_Entry_Count
(E
));
5995 if not Is_Interface
(Etype
(Typ
)) then
5997 -- Inherit first secondary dispatch table
5999 Append_To
(Elab_Code
,
6000 Build_Inherit_Predefined_Prims
(Loc
,
6002 Unchecked_Convert_To
(RTE
(RE_Tag
),
6005 (Next_Elmt
(Sec_DT_Ancestor
)),
6008 Unchecked_Convert_To
(RTE
(RE_Tag
),
6010 (Node
(Next_Elmt
(Sec_DT_Typ
)),
6013 if Num_Prims
/= 0 then
6014 Append_To
(Elab_Code
,
6015 Build_Inherit_Prims
(Loc
,
6016 Typ
=> Node
(Iface
),
6018 Unchecked_Convert_To
6021 (Node
(Sec_DT_Ancestor
),
6024 Unchecked_Convert_To
6027 (Node
(Sec_DT_Typ
), Loc
)),
6028 Num_Prims
=> Num_Prims
));
6032 Next_Elmt
(Sec_DT_Ancestor
);
6033 Next_Elmt
(Sec_DT_Typ
);
6035 -- Skip the secondary dispatch table of
6036 -- predefined primitives
6038 Next_Elmt
(Sec_DT_Ancestor
);
6039 Next_Elmt
(Sec_DT_Typ
);
6041 if not Is_Interface
(Etype
(Typ
)) then
6043 -- Inherit second secondary dispatch table
6045 Append_To
(Elab_Code
,
6046 Build_Inherit_Predefined_Prims
(Loc
,
6048 Unchecked_Convert_To
(RTE
(RE_Tag
),
6051 (Next_Elmt
(Sec_DT_Ancestor
)),
6054 Unchecked_Convert_To
(RTE
(RE_Tag
),
6056 (Node
(Next_Elmt
(Sec_DT_Typ
)),
6059 if Num_Prims
/= 0 then
6060 Append_To
(Elab_Code
,
6061 Build_Inherit_Prims
(Loc
,
6062 Typ
=> Node
(Iface
),
6064 Unchecked_Convert_To
6067 (Node
(Sec_DT_Ancestor
),
6070 Unchecked_Convert_To
6073 (Node
(Sec_DT_Typ
), Loc
)),
6074 Num_Prims
=> Num_Prims
));
6079 Next_Elmt
(Sec_DT_Ancestor
);
6080 Next_Elmt
(Sec_DT_Typ
);
6082 -- Skip the secondary dispatch table of
6083 -- predefined primitives
6085 Next_Elmt
(Sec_DT_Ancestor
);
6086 Next_Elmt
(Sec_DT_Typ
);
6094 end Copy_Secondary_DTs
;
6097 if Present
(Node
(Sec_DT_Ancestor
))
6098 and then Ekind
(Node
(Sec_DT_Ancestor
)) = E_Constant
6100 -- Handle private types
6102 if Present
(Full_View
(Typ
)) then
6103 Copy_Secondary_DTs
(Full_View
(Typ
));
6105 Copy_Secondary_DTs
(Typ
);
6113 -- Generate code to check if the external tag of this type is the same
6114 -- as the external tag of some other declaration.
6116 -- Check_TSD (TSD'Unrestricted_Access);
6118 -- This check is a consequence of AI05-0113-1/06, so it officially
6119 -- applies to Ada 2005 (and Ada 2012). It might be argued that it is
6120 -- a desirable check to add in Ada 95 mode, but we hesitate to make
6121 -- this change, as it would be incompatible, and could conceivably
6122 -- cause a problem in existing Aa 95 code.
6124 -- We check for No_Run_Time_Mode here, because we do not want to pick
6125 -- up the RE_Check_TSD entity and call it in No_Run_Time mode.
6127 if not No_Run_Time_Mode
6128 and then Ada_Version
>= Ada_2005
6129 and then RTE_Available
(RE_Check_TSD
)
6130 and then not Duplicated_Tag_Checks_Suppressed
(Typ
)
6132 Append_To
(Elab_Code
,
6133 Make_Procedure_Call_Statement
(Loc
,
6135 New_Occurrence_Of
(RTE
(RE_Check_TSD
), Loc
),
6136 Parameter_Associations
=> New_List
(
6137 Make_Attribute_Reference
(Loc
,
6138 Prefix
=> New_Occurrence_Of
(TSD
, Loc
),
6139 Attribute_Name
=> Name_Unchecked_Access
))));
6142 -- Generate code to register the Tag in the External_Tag hash table for
6143 -- the pure Ada type only.
6145 -- Register_Tag (Dt_Ptr);
6147 -- Skip this action in the following cases:
6148 -- 1) if Register_Tag is not available.
6149 -- 2) in No_Run_Time mode.
6150 -- 3) if Typ is not defined at the library level (this is required
6151 -- to avoid adding concurrency control to the hash table used
6152 -- by the run-time to register the tags).
6154 if not No_Run_Time_Mode
6155 and then Is_Library_Level_Entity
(Typ
)
6156 and then RTE_Available
(RE_Register_Tag
)
6158 Append_To
(Elab_Code
,
6159 Make_Procedure_Call_Statement
(Loc
,
6161 New_Occurrence_Of
(RTE
(RE_Register_Tag
), Loc
),
6162 Parameter_Associations
=>
6163 New_List
(New_Occurrence_Of
(DT_Ptr
, Loc
))));
6166 if not Is_Empty_List
(Elab_Code
) then
6167 Append_List_To
(Result
, Elab_Code
);
6170 -- Populate the two auxiliary tables used for dispatching asynchronous,
6171 -- conditional and timed selects for synchronized types that implement
6172 -- a limited interface. Skip this step in Ravenscar profile or when
6173 -- general dispatching is forbidden.
6175 if Ada_Version
>= Ada_2005
6176 and then Is_Concurrent_Record_Type
(Typ
)
6177 and then Has_Interfaces
(Typ
)
6178 and then not Restriction_Active
(No_Dispatching_Calls
)
6179 and then not Restriction_Active
(No_Select_Statements
)
6181 Append_List_To
(Result
,
6182 Make_Select_Specific_Data_Table
(Typ
));
6185 -- Remember entities containing dispatch tables
6187 Append_Elmt
(Predef_Prims
, DT_Decl
);
6188 Append_Elmt
(DT
, DT_Decl
);
6190 Analyze_List
(Result
, Suppress
=> All_Checks
);
6191 Set_Has_Dispatch_Table
(Typ
);
6193 -- Mark entities containing dispatch tables. Required by the backend to
6194 -- handle them properly.
6196 if Has_DT
(Typ
) then
6201 -- Object declarations
6203 Elmt
:= First_Elmt
(DT_Decl
);
6204 while Present
(Elmt
) loop
6205 Set_Is_Dispatch_Table_Entity
(Node
(Elmt
));
6206 pragma Assert
(Ekind
(Etype
(Node
(Elmt
))) = E_Array_Subtype
6207 or else Ekind
(Etype
(Node
(Elmt
))) = E_Record_Subtype
);
6208 Set_Is_Dispatch_Table_Entity
(Etype
(Node
(Elmt
)));
6212 -- Aggregates initializing dispatch tables
6214 Elmt
:= First_Elmt
(DT_Aggr
);
6215 while Present
(Elmt
) loop
6216 Set_Is_Dispatch_Table_Entity
(Etype
(Node
(Elmt
)));
6222 -- Register the tagged type in the call graph nodes table
6224 Register_CG_Node
(Typ
);
6233 function Make_VM_TSD
(Typ
: Entity_Id
) return List_Id
is
6234 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
6235 Result
: constant List_Id
:= New_List
;
6237 function Count_Primitives
(Typ
: Entity_Id
) return Nat
;
6238 -- Count the non-predefined primitive operations of Typ
6240 ----------------------
6241 -- Count_Primitives --
6242 ----------------------
6244 function Count_Primitives
(Typ
: Entity_Id
) return Nat
is
6246 Prim_Elmt
: Elmt_Id
;
6252 Prim_Elmt
:= First_Elmt
(Primitive_Operations
(Typ
));
6253 while Present
(Prim_Elmt
) loop
6254 Prim
:= Node
(Prim_Elmt
);
6256 if Is_Predefined_Dispatching_Operation
(Prim
)
6257 or else Is_Predefined_Dispatching_Alias
(Prim
)
6261 elsif Present
(Interface_Alias
(Prim
)) then
6265 Nb_Prim
:= Nb_Prim
+ 1;
6268 Next_Elmt
(Prim_Elmt
);
6272 end Count_Primitives
;
6278 function Make_OSD
(Iface
: Entity_Id
) return Node_Id
;
6279 -- Generate the Object Specific Data table required to dispatch calls
6280 -- through synchronized interfaces. Returns a node that references the
6281 -- generated OSD object.
6283 function Make_OSD
(Iface
: Entity_Id
) return Node_Id
is
6284 Nb_Prim
: constant Nat
:= Count_Primitives
(Iface
);
6286 OSD_Aggr_List
: List_Id
;
6290 -- OSD : Ada.Tags.Object_Specific_Data (Nb_Prims) :=
6291 -- (OSD_Table => (1 => <value>,
6296 or else Is_Abstract_Type
(Typ
)
6297 or else Is_Controlled
(Typ
)
6298 or else Restriction_Active
(No_Dispatching_Calls
)
6299 or else not Is_Limited_Type
(Typ
)
6300 or else not Has_Interfaces
(Typ
)
6301 or else not RTE_Record_Component_Available
(RE_OSD_Table
)
6303 -- No OSD table required
6305 return Make_Null
(Loc
);
6308 OSD_Aggr_List
:= New_List
;
6311 Prim_Table
: array (Nat
range 1 .. Nb_Prim
) of Entity_Id
;
6313 Prim_Alias
: Entity_Id
;
6314 Prim_Elmt
: Elmt_Id
;
6320 Prim_Table
:= (others => Empty
);
6321 Prim_Alias
:= Empty
;
6323 Prim_Elmt
:= First_Elmt
(Primitive_Operations
(Typ
));
6324 while Present
(Prim_Elmt
) loop
6325 Prim
:= Node
(Prim_Elmt
);
6327 if Present
(Interface_Alias
(Prim
))
6328 and then Find_Dispatching_Type
6329 (Interface_Alias
(Prim
)) = Iface
6331 Prim_Alias
:= Interface_Alias
(Prim
);
6332 E
:= Ultimate_Alias
(Prim
);
6333 Pos
:= UI_To_Int
(DT_Position
(Prim_Alias
));
6335 if Present
(Prim_Table
(Pos
)) then
6336 pragma Assert
(Prim_Table
(Pos
) = E
);
6340 Prim_Table
(Pos
) := E
;
6342 Append_To
(OSD_Aggr_List
,
6343 Make_Component_Association
(Loc
,
6344 Choices
=> New_List
(
6345 Make_Integer_Literal
(Loc
,
6346 DT_Position
(Prim_Alias
))),
6348 Make_Integer_Literal
(Loc
,
6349 DT_Position
(Alias
(Prim
)))));
6355 Next_Elmt
(Prim_Elmt
);
6358 pragma Assert
(Count
= Nb_Prim
);
6361 OSD
:= Make_Temporary
(Loc
, 'I');
6364 Make_Object_Declaration
(Loc
,
6365 Defining_Identifier
=> OSD
,
6366 Aliased_Present
=> True,
6367 Constant_Present
=> True,
6368 Object_Definition
=>
6369 Make_Subtype_Indication
(Loc
,
6371 New_Occurrence_Of
(RTE
(RE_Object_Specific_Data
), Loc
),
6373 Make_Index_Or_Discriminant_Constraint
(Loc
,
6374 Constraints
=> New_List
(
6375 Make_Integer_Literal
(Loc
, Nb_Prim
)))),
6378 Make_Aggregate
(Loc
,
6379 Component_Associations
=> New_List
(
6380 Make_Component_Association
(Loc
,
6381 Choices
=> New_List
(
6383 (RTE_Record_Component
(RE_OSD_Num_Prims
), Loc
)),
6385 Make_Integer_Literal
(Loc
, Nb_Prim
)),
6387 Make_Component_Association
(Loc
,
6388 Choices
=> New_List
(
6390 (RTE_Record_Component
(RE_OSD_Table
), Loc
)),
6391 Expression
=> Make_Aggregate
(Loc
,
6392 Component_Associations
=> OSD_Aggr_List
))))));
6395 Make_Attribute_Reference
(Loc
,
6396 Prefix
=> New_Occurrence_Of
(OSD
, Loc
),
6397 Attribute_Name
=> Name_Unchecked_Access
);
6403 Nb_Prim
: constant Nat
:= Count_Primitives
(Typ
);
6406 Iface_Table_Node
: Node_Id
;
6408 TSD_Aggr_List
: List_Id
;
6409 Typ_Ifaces
: Elist_Id
;
6410 TSD_Tags_List
: List_Id
;
6412 Tname
: constant Name_Id
:= Chars
(Typ
);
6413 Name_SSD
: constant Name_Id
:=
6414 New_External_Name
(Tname
, 'S', Suffix_Index
=> -1);
6415 Name_TSD
: constant Name_Id
:=
6416 New_External_Name
(Tname
, 'B', Suffix_Index
=> -1);
6417 SSD
: constant Entity_Id
:=
6418 Make_Defining_Identifier
(Loc
, Name_SSD
);
6419 TSD
: constant Entity_Id
:=
6420 Make_Defining_Identifier
(Loc
, Name_TSD
);
6422 -- Generate code to create the storage for the type specific data object
6423 -- with enough space to store the tags of the ancestors plus the tags
6424 -- of all the implemented interfaces (as described in a-tags.ads).
6426 -- TSD : Type_Specific_Data (I_Depth) :=
6427 -- (Idepth => I_Depth,
6428 -- Tag_Kind => <tag_kind-value>,
6429 -- Access_Level => Type_Access_Level (Typ),
6430 -- Alignment => Typ'Alignment,
6432 -- Type_Is_Abstract => <<boolean-value>>,
6433 -- Type_Is_Library_Level => <<boolean-value>>,
6434 -- Interfaces_Table => <<access-value>>
6435 -- SSD => SSD_Table'Address
6436 -- Tags_Table => (0 => Typ'Tag,
6440 TSD_Aggr_List
:= New_List
;
6442 -- Idepth: Count ancestors to compute the inheritance depth. For private
6443 -- extensions, always go to the full view in order to compute the real
6444 -- inheritance depth.
6447 Current_Typ
: Entity_Id
;
6448 Parent_Typ
: Entity_Id
;
6454 Parent_Typ
:= Etype
(Current_Typ
);
6456 if Is_Private_Type
(Parent_Typ
) then
6457 Parent_Typ
:= Full_View
(Base_Type
(Parent_Typ
));
6460 exit when Parent_Typ
= Current_Typ
;
6462 I_Depth
:= I_Depth
+ 1;
6463 Current_Typ
:= Parent_Typ
;
6469 Append_To
(TSD_Aggr_List
,
6470 Make_Integer_Literal
(Loc
, I_Depth
));
6474 Append_To
(TSD_Aggr_List
, Tagged_Kind
(Typ
));
6478 Append_To
(TSD_Aggr_List
,
6479 Make_Integer_Literal
(Loc
, Type_Access_Level
(Typ
)));
6483 -- For CPP types we cannot rely on the value of 'Alignment provided
6484 -- by the backend to initialize this TSD field. Why not???
6486 if Convention
(Typ
) = Convention_CPP
6487 or else Is_CPP_Class
(Root_Type
(Typ
))
6489 Append_To
(TSD_Aggr_List
,
6490 Make_Integer_Literal
(Loc
, 0));
6492 Append_To
(TSD_Aggr_List
,
6493 Make_Attribute_Reference
(Loc
,
6494 Prefix
=> New_Occurrence_Of
(Typ
, Loc
),
6495 Attribute_Name
=> Name_Alignment
));
6500 Append_To
(TSD_Aggr_List
,
6503 -- Type_Is_Abstract (Ada 2012: AI05-0173)
6506 Type_Is_Abstract
: Entity_Id
;
6510 Boolean_Literals
(Is_Abstract_Type
(Typ
));
6512 Append_To
(TSD_Aggr_List
,
6513 New_Occurrence_Of
(Type_Is_Abstract
, Loc
));
6516 -- Type_Is_Library_Level
6519 Type_Is_Library_Level
: Entity_Id
;
6521 Type_Is_Library_Level
:=
6522 Boolean_Literals
(Is_Library_Level_Entity
(Typ
));
6523 Append_To
(TSD_Aggr_List
,
6524 New_Occurrence_Of
(Type_Is_Library_Level
, Loc
));
6527 -- Interfaces_Table (required for AI-405)
6529 if RTE_Record_Component_Available
(RE_Interfaces_Table
) then
6531 -- Count the number of interface types implemented by Typ
6533 Collect_Interfaces
(Typ
, Typ_Ifaces
);
6536 AI
:= First_Elmt
(Typ_Ifaces
);
6537 while Present
(AI
) loop
6538 Num_Ifaces
:= Num_Ifaces
+ 1;
6542 if Num_Ifaces
= 0 then
6543 Iface_Table_Node
:= Make_Null
(Loc
);
6545 -- Generate the Interface_Table object
6549 TSD_Ifaces_List
: constant List_Id
:= New_List
;
6554 AI
:= First_Elmt
(Typ_Ifaces
);
6555 while Present
(AI
) loop
6558 Append_To
(TSD_Ifaces_List
,
6559 Make_Aggregate
(Loc
,
6560 Expressions
=> New_List
(
6564 Make_Attribute_Reference
(Loc
,
6565 Prefix
=> New_Occurrence_Of
(Iface
, Loc
),
6566 Attribute_Name
=> Name_Tag
),
6570 Make_OSD
(Iface
))));
6575 ITable
:= Make_Temporary
(Loc
, 'I');
6578 Make_Object_Declaration
(Loc
,
6579 Defining_Identifier
=> ITable
,
6580 Aliased_Present
=> True,
6581 Constant_Present
=> True,
6582 Object_Definition
=>
6583 Make_Subtype_Indication
(Loc
,
6585 New_Occurrence_Of
(RTE
(RE_Interface_Data
), Loc
),
6586 Constraint
=> Make_Index_Or_Discriminant_Constraint
6588 Constraints
=> New_List
(
6589 Make_Integer_Literal
(Loc
, Num_Ifaces
)))),
6591 Expression
=> Make_Aggregate
(Loc
,
6592 Expressions
=> New_List
(
6593 Make_Integer_Literal
(Loc
, Num_Ifaces
),
6594 Make_Aggregate
(Loc
,
6595 Expressions
=> TSD_Ifaces_List
)))));
6598 Make_Attribute_Reference
(Loc
,
6599 Prefix
=> New_Occurrence_Of
(ITable
, Loc
),
6600 Attribute_Name
=> Name_Unchecked_Access
);
6604 Append_To
(TSD_Aggr_List
, Iface_Table_Node
);
6607 -- Generate the Select Specific Data table for synchronized types that
6608 -- implement synchronized interfaces. The size of the table is
6609 -- constrained by the number of non-predefined primitive operations.
6611 if RTE_Record_Component_Available
(RE_SSD
) then
6612 if Ada_Version
>= Ada_2005
6613 and then Has_DT
(Typ
)
6614 and then Is_Concurrent_Record_Type
(Typ
)
6615 and then Has_Interfaces
(Typ
)
6616 and then Nb_Prim
> 0
6617 and then not Is_Abstract_Type
(Typ
)
6618 and then not Is_Controlled
(Typ
)
6619 and then not Restriction_Active
(No_Dispatching_Calls
)
6620 and then not Restriction_Active
(No_Select_Statements
)
6623 Make_Object_Declaration
(Loc
,
6624 Defining_Identifier
=> SSD
,
6625 Aliased_Present
=> True,
6626 Object_Definition
=>
6627 Make_Subtype_Indication
(Loc
,
6628 Subtype_Mark
=> New_Occurrence_Of
(
6629 RTE
(RE_Select_Specific_Data
), Loc
),
6631 Make_Index_Or_Discriminant_Constraint
(Loc
,
6632 Constraints
=> New_List
(
6633 Make_Integer_Literal
(Loc
, Nb_Prim
))))));
6635 -- This table is initialized by Make_Select_Specific_Data_Table,
6636 -- which calls Set_Entry_Index and Set_Prim_Op_Kind.
6638 Append_To
(TSD_Aggr_List
,
6639 Make_Attribute_Reference
(Loc
,
6640 Prefix
=> New_Occurrence_Of
(SSD
, Loc
),
6641 Attribute_Name
=> Name_Unchecked_Access
));
6643 Append_To
(TSD_Aggr_List
, Make_Null
(Loc
));
6647 -- Initialize the table of ancestor tags. In case of interface types
6648 -- this table is not needed.
6650 TSD_Tags_List
:= New_List
;
6652 -- Fill position 0 with Typ'Tag
6654 Append_To
(TSD_Tags_List
,
6655 Make_Attribute_Reference
(Loc
,
6656 Prefix
=> New_Occurrence_Of
(Typ
, Loc
),
6657 Attribute_Name
=> Name_Tag
));
6659 -- Fill the rest of the table with the tags of the ancestors
6662 Current_Typ
: Entity_Id
;
6663 Parent_Typ
: Entity_Id
;
6671 Parent_Typ
:= Etype
(Current_Typ
);
6673 if Is_Private_Type
(Parent_Typ
) then
6674 Parent_Typ
:= Full_View
(Base_Type
(Parent_Typ
));
6677 exit when Parent_Typ
= Current_Typ
;
6679 Append_To
(TSD_Tags_List
,
6680 Make_Attribute_Reference
(Loc
,
6681 Prefix
=> New_Occurrence_Of
(Parent_Typ
, Loc
),
6682 Attribute_Name
=> Name_Tag
));
6685 Current_Typ
:= Parent_Typ
;
6688 pragma Assert
(Pos
= I_Depth
+ 1);
6691 Append_To
(TSD_Aggr_List
,
6692 Make_Aggregate
(Loc
,
6693 Expressions
=> TSD_Tags_List
));
6695 -- Build the TSD object
6698 Make_Object_Declaration
(Loc
,
6699 Defining_Identifier
=> TSD
,
6700 Aliased_Present
=> True,
6701 Constant_Present
=> True,
6702 Object_Definition
=>
6703 Make_Subtype_Indication
(Loc
,
6704 Subtype_Mark
=> New_Occurrence_Of
(
6705 RTE
(RE_Type_Specific_Data
), Loc
),
6707 Make_Index_Or_Discriminant_Constraint
(Loc
,
6708 Constraints
=> New_List
(
6709 Make_Integer_Literal
(Loc
, I_Depth
)))),
6711 Expression
=> Make_Aggregate
(Loc
,
6712 Expressions
=> TSD_Aggr_List
)));
6715 -- Check_TSD (TSD => TSD'Unrestricted_Access);
6717 if Ada_Version
>= Ada_2005
6718 and then Is_Library_Level_Entity
(Typ
)
6719 and then RTE_Available
(RE_Check_TSD
)
6720 and then not Duplicated_Tag_Checks_Suppressed
(Typ
)
6723 Make_Procedure_Call_Statement
(Loc
,
6724 Name
=> New_Occurrence_Of
(RTE
(RE_Check_TSD
), Loc
),
6725 Parameter_Associations
=> New_List
(
6726 Make_Attribute_Reference
(Loc
,
6727 Prefix
=> New_Occurrence_Of
(TSD
, Loc
),
6728 Attribute_Name
=> Name_Unrestricted_Access
))));
6732 -- Register_TSD (TSD'Unrestricted_Access);
6735 Make_Procedure_Call_Statement
(Loc
,
6736 Name
=> New_Occurrence_Of
(RTE
(RE_Register_TSD
), Loc
),
6737 Parameter_Associations
=> New_List
(
6738 Make_Attribute_Reference
(Loc
,
6739 Prefix
=> New_Occurrence_Of
(TSD
, Loc
),
6740 Attribute_Name
=> Name_Unrestricted_Access
))));
6742 -- Populate the two auxiliary tables used for dispatching asynchronous,
6743 -- conditional and timed selects for synchronized types that implement
6744 -- a limited interface. Skip this step in Ravenscar profile or when
6745 -- general dispatching is forbidden.
6747 if Ada_Version
>= Ada_2005
6748 and then Is_Concurrent_Record_Type
(Typ
)
6749 and then Has_Interfaces
(Typ
)
6750 and then not Restriction_Active
(No_Dispatching_Calls
)
6751 and then not Restriction_Active
(No_Select_Statements
)
6753 Append_List_To
(Result
,
6754 Make_Select_Specific_Data_Table
(Typ
));
6760 -------------------------------------
6761 -- Make_Select_Specific_Data_Table --
6762 -------------------------------------
6764 function Make_Select_Specific_Data_Table
6765 (Typ
: Entity_Id
) return List_Id
6767 Assignments
: constant List_Id
:= New_List
;
6768 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
6770 Conc_Typ
: Entity_Id
;
6773 Prim_Als
: Entity_Id
;
6774 Prim_Elmt
: Elmt_Id
;
6778 type Examined_Array
is array (Int
range <>) of Boolean;
6780 function Find_Entry_Index
(E
: Entity_Id
) return Uint
;
6781 -- Given an entry, find its index in the visible declarations of the
6782 -- corresponding concurrent type of Typ.
6784 ----------------------
6785 -- Find_Entry_Index --
6786 ----------------------
6788 function Find_Entry_Index
(E
: Entity_Id
) return Uint
is
6789 Index
: Uint
:= Uint_1
;
6790 Subp_Decl
: Entity_Id
;
6794 and then not Is_Empty_List
(Decls
)
6796 Subp_Decl
:= First
(Decls
);
6797 while Present
(Subp_Decl
) loop
6798 if Nkind
(Subp_Decl
) = N_Entry_Declaration
then
6799 if Defining_Identifier
(Subp_Decl
) = E
then
6811 end Find_Entry_Index
;
6817 -- Start of processing for Make_Select_Specific_Data_Table
6820 pragma Assert
(not Restriction_Active
(No_Dispatching_Calls
));
6822 if Present
(Corresponding_Concurrent_Type
(Typ
)) then
6823 Conc_Typ
:= Corresponding_Concurrent_Type
(Typ
);
6825 if Present
(Full_View
(Conc_Typ
)) then
6826 Conc_Typ
:= Full_View
(Conc_Typ
);
6829 if Ekind
(Conc_Typ
) = E_Protected_Type
then
6830 Decls
:= Visible_Declarations
(Protected_Definition
(
6831 Parent
(Conc_Typ
)));
6833 pragma Assert
(Ekind
(Conc_Typ
) = E_Task_Type
);
6834 Decls
:= Visible_Declarations
(Task_Definition
(
6835 Parent
(Conc_Typ
)));
6839 -- Count the non-predefined primitive operations
6841 Prim_Elmt
:= First_Elmt
(Primitive_Operations
(Typ
));
6842 while Present
(Prim_Elmt
) loop
6843 Prim
:= Node
(Prim_Elmt
);
6845 if not (Is_Predefined_Dispatching_Operation
(Prim
)
6846 or else Is_Predefined_Dispatching_Alias
(Prim
))
6848 Nb_Prim
:= Nb_Prim
+ 1;
6851 Next_Elmt
(Prim_Elmt
);
6855 Examined
: Examined_Array
(1 .. Nb_Prim
) := (others => False);
6858 Prim_Elmt
:= First_Elmt
(Primitive_Operations
(Typ
));
6859 while Present
(Prim_Elmt
) loop
6860 Prim
:= Node
(Prim_Elmt
);
6862 -- Look for primitive overriding an abstract interface subprogram
6864 if Present
(Interface_Alias
(Prim
))
6867 (Find_Dispatching_Type
(Interface_Alias
(Prim
)), Typ
,
6868 Use_Full_View
=> True)
6869 and then not Examined
(UI_To_Int
(DT_Position
(Alias
(Prim
))))
6871 Prim_Pos
:= DT_Position
(Alias
(Prim
));
6872 pragma Assert
(UI_To_Int
(Prim_Pos
) <= Nb_Prim
);
6873 Examined
(UI_To_Int
(Prim_Pos
)) := True;
6875 -- Set the primitive operation kind regardless of subprogram
6877 -- Ada.Tags.Set_Prim_Op_Kind (DT_Ptr, <position>, <kind>);
6879 if Tagged_Type_Expansion
then
6882 (Node
(First_Elmt
(Access_Disp_Table
(Typ
))), Loc
);
6886 Make_Attribute_Reference
(Loc
,
6887 Prefix
=> New_Occurrence_Of
(Typ
, Loc
),
6888 Attribute_Name
=> Name_Tag
);
6891 Append_To
(Assignments
,
6892 Make_Procedure_Call_Statement
(Loc
,
6893 Name
=> New_Occurrence_Of
(RTE
(RE_Set_Prim_Op_Kind
), Loc
),
6894 Parameter_Associations
=> New_List
(
6896 Make_Integer_Literal
(Loc
, Prim_Pos
),
6897 Prim_Op_Kind
(Alias
(Prim
), Typ
))));
6899 -- Retrieve the root of the alias chain
6901 Prim_Als
:= Ultimate_Alias
(Prim
);
6903 -- In the case of an entry wrapper, set the entry index
6905 if Ekind
(Prim
) = E_Procedure
6906 and then Is_Primitive_Wrapper
(Prim_Als
)
6907 and then Ekind
(Wrapped_Entity
(Prim_Als
)) = E_Entry
6910 -- Ada.Tags.Set_Entry_Index
6911 -- (DT_Ptr, <position>, <index>);
6913 if Tagged_Type_Expansion
then
6916 (Node
(First_Elmt
(Access_Disp_Table
(Typ
))), Loc
);
6919 Make_Attribute_Reference
(Loc
,
6920 Prefix
=> New_Occurrence_Of
(Typ
, Loc
),
6921 Attribute_Name
=> Name_Tag
);
6924 Append_To
(Assignments
,
6925 Make_Procedure_Call_Statement
(Loc
,
6927 New_Occurrence_Of
(RTE
(RE_Set_Entry_Index
), Loc
),
6928 Parameter_Associations
=> New_List
(
6930 Make_Integer_Literal
(Loc
, Prim_Pos
),
6931 Make_Integer_Literal
(Loc
,
6932 Find_Entry_Index
(Wrapped_Entity
(Prim_Als
))))));
6936 Next_Elmt
(Prim_Elmt
);
6941 end Make_Select_Specific_Data_Table
;
6947 function Make_Tags
(Typ
: Entity_Id
) return List_Id
is
6948 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
6949 Result
: constant List_Id
:= New_List
;
6952 (Tag_Typ
: Entity_Id
;
6954 Is_Secondary_DT
: Boolean);
6955 -- Import the dispatch table DT of tagged type Tag_Typ. Required to
6956 -- generate forward references and statically allocate the table. For
6957 -- primary dispatch tables that require no dispatch table generate:
6959 -- DT : static aliased constant Non_Dispatch_Table_Wrapper;
6960 -- pragma Import (Ada, DT);
6962 -- Otherwise generate:
6964 -- DT : static aliased constant Dispatch_Table_Wrapper (Nb_Prim);
6965 -- pragma Import (Ada, DT);
6972 (Tag_Typ
: Entity_Id
;
6974 Is_Secondary_DT
: Boolean)
6976 DT_Constr_List
: List_Id
;
6980 Set_Is_Imported
(DT
);
6981 Set_Ekind
(DT
, E_Constant
);
6982 Set_Related_Type
(DT
, Typ
);
6984 -- The scope must be set now to call Get_External_Name
6986 Set_Scope
(DT
, Current_Scope
);
6988 Get_External_Name
(DT
);
6989 Set_Interface_Name
(DT
,
6990 Make_String_Literal
(Loc
, Strval
=> String_From_Name_Buffer
));
6992 -- Ensure proper Sprint output of this implicit importation
6994 Set_Is_Internal
(DT
);
6996 -- Save this entity to allow Make_DT to generate its exportation
6998 Append_Elmt
(DT
, Dispatch_Table_Wrappers
(Typ
));
7000 -- No dispatch table required
7002 if not Is_Secondary_DT
and then not Has_DT
(Tag_Typ
) then
7004 Make_Object_Declaration
(Loc
,
7005 Defining_Identifier
=> DT
,
7006 Aliased_Present
=> True,
7007 Constant_Present
=> True,
7008 Object_Definition
=>
7010 (RTE
(RE_No_Dispatch_Table_Wrapper
), Loc
)));
7013 -- Calculate the number of primitives of the dispatch table and
7014 -- the size of the Type_Specific_Data record.
7017 UI_To_Int
(DT_Entry_Count
(First_Tag_Component
(Tag_Typ
)));
7019 -- If the tagged type has no primitives we add a dummy slot whose
7020 -- address will be the tag of this type.
7024 New_List
(Make_Integer_Literal
(Loc
, 1));
7027 New_List
(Make_Integer_Literal
(Loc
, Nb_Prim
));
7031 Make_Object_Declaration
(Loc
,
7032 Defining_Identifier
=> DT
,
7033 Aliased_Present
=> True,
7034 Constant_Present
=> True,
7035 Object_Definition
=>
7036 Make_Subtype_Indication
(Loc
,
7038 New_Occurrence_Of
(RTE
(RE_Dispatch_Table_Wrapper
), Loc
),
7039 Constraint
=> Make_Index_Or_Discriminant_Constraint
(Loc
,
7040 Constraints
=> DT_Constr_List
))));
7046 Tname
: constant Name_Id
:= Chars
(Typ
);
7047 AI_Tag_Comp
: Elmt_Id
;
7048 DT
: Node_Id
:= Empty
;
7050 Predef_Prims_Ptr
: Node_Id
;
7051 Iface_DT
: Node_Id
:= Empty
;
7052 Iface_DT_Ptr
: Node_Id
;
7056 Typ_Comps
: Elist_Id
;
7058 -- Start of processing for Make_Tags
7061 pragma Assert
(No
(Access_Disp_Table
(Typ
)));
7062 Set_Access_Disp_Table
(Typ
, New_Elmt_List
);
7064 -- 1) Generate the primary tag entities
7066 -- Primary dispatch table containing user-defined primitives
7068 DT_Ptr
:= Make_Defining_Identifier
(Loc
, New_External_Name
(Tname
, 'P'));
7069 Set_Etype
(DT_Ptr
, RTE
(RE_Tag
));
7070 Append_Elmt
(DT_Ptr
, Access_Disp_Table
(Typ
));
7072 -- Minimum decoration
7074 Set_Ekind
(DT_Ptr
, E_Variable
);
7075 Set_Related_Type
(DT_Ptr
, Typ
);
7077 -- Notify back end that the types are associated with a dispatch table
7079 Set_Is_Dispatch_Table_Entity
(RTE
(RE_Prim_Ptr
));
7080 Set_Is_Dispatch_Table_Entity
(RTE
(RE_Predef_Prims_Table_Ptr
));
7082 -- For CPP types there is no need to build the dispatch tables since
7083 -- they are imported from the C++ side. If the CPP type has an IP then
7084 -- we declare now the variable that will store the copy of the C++ tag.
7085 -- If the CPP type is an interface, we need the variable as well because
7086 -- it becomes the pointer to the corresponding secondary table.
7088 if Is_CPP_Class
(Typ
) then
7089 if Has_CPP_Constructors
(Typ
) or else Is_Interface
(Typ
) then
7091 Make_Object_Declaration
(Loc
,
7092 Defining_Identifier
=> DT_Ptr
,
7093 Object_Definition
=> New_Occurrence_Of
(RTE
(RE_Tag
), Loc
),
7095 Unchecked_Convert_To
(RTE
(RE_Tag
),
7096 New_Occurrence_Of
(RTE
(RE_Null_Address
), Loc
))));
7098 Set_Is_Statically_Allocated
(DT_Ptr
,
7099 Is_Library_Level_Tagged_Type
(Typ
));
7105 -- Primary dispatch table containing predefined primitives
7108 Make_Defining_Identifier
(Loc
,
7109 Chars
=> New_External_Name
(Tname
, 'Y'));
7110 Set_Etype
(Predef_Prims_Ptr
, RTE
(RE_Address
));
7111 Append_Elmt
(Predef_Prims_Ptr
, Access_Disp_Table
(Typ
));
7113 -- Import the forward declaration of the Dispatch Table wrapper
7114 -- record (Make_DT will take care of exporting it).
7116 if Building_Static_DT
(Typ
) then
7117 Set_Dispatch_Table_Wrappers
(Typ
, New_Elmt_List
);
7120 Make_Defining_Identifier
(Loc
,
7121 Chars
=> New_External_Name
(Tname
, 'T'));
7123 Import_DT
(Typ
, DT
, Is_Secondary_DT
=> False);
7125 if Has_DT
(Typ
) then
7127 Make_Object_Declaration
(Loc
,
7128 Defining_Identifier
=> DT_Ptr
,
7129 Constant_Present
=> True,
7130 Object_Definition
=>
7131 New_Occurrence_Of
(RTE
(RE_Tag
), Loc
),
7133 Unchecked_Convert_To
(RTE
(RE_Tag
),
7134 Make_Attribute_Reference
(Loc
,
7136 Make_Selected_Component
(Loc
,
7137 Prefix
=> New_Occurrence_Of
(DT
, Loc
),
7140 (RTE_Record_Component
(RE_Prims_Ptr
), Loc
)),
7141 Attribute_Name
=> Name_Address
))));
7143 -- Generate the SCIL node for the previous object declaration
7144 -- because it has a tag initialization.
7146 if Generate_SCIL
then
7148 Make_SCIL_Dispatch_Table_Tag_Init
(Sloc
(Last
(Result
)));
7149 Set_SCIL_Entity
(New_Node
, Typ
);
7150 Set_SCIL_Node
(Last
(Result
), New_Node
);
7154 Make_Object_Declaration
(Loc
,
7155 Defining_Identifier
=> Predef_Prims_Ptr
,
7156 Constant_Present
=> True,
7157 Object_Definition
=>
7158 New_Occurrence_Of
(RTE
(RE_Address
), Loc
),
7160 Make_Attribute_Reference
(Loc
,
7162 Make_Selected_Component
(Loc
,
7163 Prefix
=> New_Occurrence_Of
(DT
, Loc
),
7166 (RTE_Record_Component
(RE_Predef_Prims
), Loc
)),
7167 Attribute_Name
=> Name_Address
)));
7169 -- No dispatch table required
7173 Make_Object_Declaration
(Loc
,
7174 Defining_Identifier
=> DT_Ptr
,
7175 Constant_Present
=> True,
7176 Object_Definition
=>
7177 New_Occurrence_Of
(RTE
(RE_Tag
), Loc
),
7179 Unchecked_Convert_To
(RTE
(RE_Tag
),
7180 Make_Attribute_Reference
(Loc
,
7182 Make_Selected_Component
(Loc
,
7183 Prefix
=> New_Occurrence_Of
(DT
, Loc
),
7186 (RTE_Record_Component
(RE_NDT_Prims_Ptr
),
7188 Attribute_Name
=> Name_Address
))));
7191 Set_Is_True_Constant
(DT_Ptr
);
7192 Set_Is_Statically_Allocated
(DT_Ptr
);
7196 -- 2) Generate the secondary tag entities
7198 -- Collect the components associated with secondary dispatch tables
7200 if Has_Interfaces
(Typ
) then
7201 Collect_Interface_Components
(Typ
, Typ_Comps
);
7203 -- For each interface type we build a unique external name associated
7204 -- with its secondary dispatch table. This name is used to declare an
7205 -- object that references this secondary dispatch table, whose value
7206 -- will be used for the elaboration of Typ objects, and also for the
7207 -- elaboration of objects of types derived from Typ that do not
7208 -- override the primitives of this interface type.
7212 -- Note: The value of Suffix_Index must be in sync with the values of
7213 -- Suffix_Index in secondary dispatch tables generated by Make_DT.
7215 if Is_CPP_Class
(Typ
) then
7216 AI_Tag_Comp
:= First_Elmt
(Typ_Comps
);
7217 while Present
(AI_Tag_Comp
) loop
7218 Get_Secondary_DT_External_Name
7219 (Typ
, Related_Type
(Node
(AI_Tag_Comp
)), Suffix_Index
);
7220 Typ_Name
:= Name_Find
;
7222 -- Declare variables to store copy of the C++ secondary tags
7225 Make_Defining_Identifier
(Loc
,
7226 Chars
=> New_External_Name
(Typ_Name
, 'P'));
7227 Set_Etype
(Iface_DT_Ptr
, RTE
(RE_Interface_Tag
));
7228 Set_Ekind
(Iface_DT_Ptr
, E_Variable
);
7229 Set_Is_Tag
(Iface_DT_Ptr
);
7231 Set_Has_Thunks
(Iface_DT_Ptr
);
7233 (Iface_DT_Ptr
, Related_Type
(Node
(AI_Tag_Comp
)));
7234 Append_Elmt
(Iface_DT_Ptr
, Access_Disp_Table
(Typ
));
7237 Make_Object_Declaration
(Loc
,
7238 Defining_Identifier
=> Iface_DT_Ptr
,
7239 Object_Definition
=> New_Occurrence_Of
7240 (RTE
(RE_Interface_Tag
), Loc
),
7242 Unchecked_Convert_To
(RTE
(RE_Interface_Tag
),
7243 New_Occurrence_Of
(RTE
(RE_Null_Address
), Loc
))));
7245 Set_Is_Statically_Allocated
(Iface_DT_Ptr
,
7246 Is_Library_Level_Tagged_Type
(Typ
));
7248 Next_Elmt
(AI_Tag_Comp
);
7251 -- This is not a CPP_Class type
7254 AI_Tag_Comp
:= First_Elmt
(Typ_Comps
);
7255 while Present
(AI_Tag_Comp
) loop
7256 Get_Secondary_DT_External_Name
7257 (Typ
, Related_Type
(Node
(AI_Tag_Comp
)), Suffix_Index
);
7258 Typ_Name
:= Name_Find
;
7260 if Building_Static_DT
(Typ
) then
7262 Make_Defining_Identifier
(Loc
,
7263 Chars
=> New_External_Name
7264 (Typ_Name
, 'T', Suffix_Index
=> -1));
7266 (Tag_Typ
=> Related_Type
(Node
(AI_Tag_Comp
)),
7268 Is_Secondary_DT
=> True);
7271 -- Secondary dispatch table referencing thunks to user-defined
7272 -- primitives covered by this interface.
7275 Make_Defining_Identifier
(Loc
,
7276 Chars
=> New_External_Name
(Typ_Name
, 'P'));
7277 Set_Etype
(Iface_DT_Ptr
, RTE
(RE_Interface_Tag
));
7278 Set_Ekind
(Iface_DT_Ptr
, E_Constant
);
7279 Set_Is_Tag
(Iface_DT_Ptr
);
7280 Set_Has_Thunks
(Iface_DT_Ptr
);
7281 Set_Is_Statically_Allocated
(Iface_DT_Ptr
,
7282 Is_Library_Level_Tagged_Type
(Typ
));
7283 Set_Is_True_Constant
(Iface_DT_Ptr
);
7285 (Iface_DT_Ptr
, Related_Type
(Node
(AI_Tag_Comp
)));
7286 Append_Elmt
(Iface_DT_Ptr
, Access_Disp_Table
(Typ
));
7288 if Building_Static_DT
(Typ
) then
7290 Make_Object_Declaration
(Loc
,
7291 Defining_Identifier
=> Iface_DT_Ptr
,
7292 Constant_Present
=> True,
7293 Object_Definition
=> New_Occurrence_Of
7294 (RTE
(RE_Interface_Tag
), Loc
),
7296 Unchecked_Convert_To
(RTE
(RE_Interface_Tag
),
7297 Make_Attribute_Reference
(Loc
,
7299 Make_Selected_Component
(Loc
,
7301 New_Occurrence_Of
(Iface_DT
, Loc
),
7304 (RTE_Record_Component
(RE_Prims_Ptr
),
7306 Attribute_Name
=> Name_Address
))));
7309 -- Secondary dispatch table referencing thunks to predefined
7313 Make_Defining_Identifier
(Loc
,
7314 Chars
=> New_External_Name
(Typ_Name
, 'Y'));
7315 Set_Etype
(Iface_DT_Ptr
, RTE
(RE_Address
));
7316 Set_Ekind
(Iface_DT_Ptr
, E_Constant
);
7317 Set_Is_Tag
(Iface_DT_Ptr
);
7318 Set_Has_Thunks
(Iface_DT_Ptr
);
7319 Set_Is_Statically_Allocated
(Iface_DT_Ptr
,
7320 Is_Library_Level_Tagged_Type
(Typ
));
7321 Set_Is_True_Constant
(Iface_DT_Ptr
);
7323 (Iface_DT_Ptr
, Related_Type
(Node
(AI_Tag_Comp
)));
7324 Append_Elmt
(Iface_DT_Ptr
, Access_Disp_Table
(Typ
));
7326 -- Secondary dispatch table referencing user-defined primitives
7327 -- covered by this interface.
7330 Make_Defining_Identifier
(Loc
,
7331 Chars
=> New_External_Name
(Typ_Name
, 'D'));
7332 Set_Etype
(Iface_DT_Ptr
, RTE
(RE_Interface_Tag
));
7333 Set_Ekind
(Iface_DT_Ptr
, E_Constant
);
7334 Set_Is_Tag
(Iface_DT_Ptr
);
7335 Set_Is_Statically_Allocated
(Iface_DT_Ptr
,
7336 Is_Library_Level_Tagged_Type
(Typ
));
7337 Set_Is_True_Constant
(Iface_DT_Ptr
);
7339 (Iface_DT_Ptr
, Related_Type
(Node
(AI_Tag_Comp
)));
7340 Append_Elmt
(Iface_DT_Ptr
, Access_Disp_Table
(Typ
));
7342 -- Secondary dispatch table referencing predefined primitives
7345 Make_Defining_Identifier
(Loc
,
7346 Chars
=> New_External_Name
(Typ_Name
, 'Z'));
7347 Set_Etype
(Iface_DT_Ptr
, RTE
(RE_Address
));
7348 Set_Ekind
(Iface_DT_Ptr
, E_Constant
);
7349 Set_Is_Tag
(Iface_DT_Ptr
);
7350 Set_Is_Statically_Allocated
(Iface_DT_Ptr
,
7351 Is_Library_Level_Tagged_Type
(Typ
));
7352 Set_Is_True_Constant
(Iface_DT_Ptr
);
7354 (Iface_DT_Ptr
, Related_Type
(Node
(AI_Tag_Comp
)));
7355 Append_Elmt
(Iface_DT_Ptr
, Access_Disp_Table
(Typ
));
7357 Next_Elmt
(AI_Tag_Comp
);
7362 -- 3) At the end of Access_Disp_Table, if the type has user-defined
7363 -- primitives, we add the entity of an access type declaration that
7364 -- is used by Build_Get_Prim_Op_Address to expand dispatching calls
7365 -- through the primary dispatch table.
7367 if UI_To_Int
(DT_Entry_Count
(First_Tag_Component
(Typ
))) = 0 then
7368 Analyze_List
(Result
);
7371 -- type Typ_DT is array (1 .. Nb_Prims) of Prim_Ptr;
7372 -- type Typ_DT_Acc is access Typ_DT;
7376 Name_DT_Prims
: constant Name_Id
:=
7377 New_External_Name
(Tname
, 'G');
7378 Name_DT_Prims_Acc
: constant Name_Id
:=
7379 New_External_Name
(Tname
, 'H');
7380 DT_Prims
: constant Entity_Id
:=
7381 Make_Defining_Identifier
(Loc
,
7383 DT_Prims_Acc
: constant Entity_Id
:=
7384 Make_Defining_Identifier
(Loc
,
7388 Make_Full_Type_Declaration
(Loc
,
7389 Defining_Identifier
=> DT_Prims
,
7391 Make_Constrained_Array_Definition
(Loc
,
7392 Discrete_Subtype_Definitions
=> New_List
(
7394 Low_Bound
=> Make_Integer_Literal
(Loc
, 1),
7395 High_Bound
=> Make_Integer_Literal
(Loc
,
7397 (First_Tag_Component
(Typ
))))),
7398 Component_Definition
=>
7399 Make_Component_Definition
(Loc
,
7400 Subtype_Indication
=>
7401 New_Occurrence_Of
(RTE
(RE_Prim_Ptr
), Loc
)))));
7404 Make_Full_Type_Declaration
(Loc
,
7405 Defining_Identifier
=> DT_Prims_Acc
,
7407 Make_Access_To_Object_Definition
(Loc
,
7408 Subtype_Indication
=>
7409 New_Occurrence_Of
(DT_Prims
, Loc
))));
7411 Append_Elmt
(DT_Prims_Acc
, Access_Disp_Table
(Typ
));
7413 -- Analyze the resulting list and suppress the generation of the
7414 -- Init_Proc associated with the above array declaration because
7415 -- this type is never used in object declarations. It is only used
7416 -- to simplify the expansion associated with dispatching calls.
7418 Analyze_List
(Result
);
7419 Set_Suppress_Initialization
(Base_Type
(DT_Prims
));
7421 -- Disable backend optimizations based on assumptions about the
7422 -- aliasing status of objects designated by the access to the
7423 -- dispatch table. Required to handle dispatch tables imported
7426 Set_No_Strict_Aliasing
(Base_Type
(DT_Prims_Acc
));
7428 -- Add the freezing nodes of these declarations; required to avoid
7429 -- generating these freezing nodes in wrong scopes (for example in
7430 -- the IC routine of a derivation of Typ).
7432 -- What is an "IC routine"? Is "init_proc" meant here???
7434 Append_List_To
(Result
, Freeze_Entity
(DT_Prims
, Typ
));
7435 Append_List_To
(Result
, Freeze_Entity
(DT_Prims_Acc
, Typ
));
7437 -- Mark entity of dispatch table. Required by the back end to
7438 -- handle them properly.
7440 Set_Is_Dispatch_Table_Entity
(DT_Prims
);
7444 -- Mark entities of dispatch table. Required by the back end to handle
7447 if Present
(DT
) then
7448 Set_Is_Dispatch_Table_Entity
(DT
);
7449 Set_Is_Dispatch_Table_Entity
(Etype
(DT
));
7452 if Present
(Iface_DT
) then
7453 Set_Is_Dispatch_Table_Entity
(Iface_DT
);
7454 Set_Is_Dispatch_Table_Entity
(Etype
(Iface_DT
));
7457 if Is_CPP_Class
(Root_Type
(Typ
)) then
7458 Set_Ekind
(DT_Ptr
, E_Variable
);
7460 Set_Ekind
(DT_Ptr
, E_Constant
);
7463 Set_Is_Tag
(DT_Ptr
);
7464 Set_Related_Type
(DT_Ptr
, Typ
);
7473 function New_Value
(From
: Node_Id
) return Node_Id
is
7474 Res
: constant Node_Id
:= Duplicate_Subexpr
(From
);
7476 if Is_Access_Type
(Etype
(From
)) then
7477 return Make_Explicit_Dereference
(Sloc
(From
), Prefix
=> Res
);
7483 -----------------------------------
7484 -- Original_View_In_Visible_Part --
7485 -----------------------------------
7487 function Original_View_In_Visible_Part
(Typ
: Entity_Id
) return Boolean is
7488 Scop
: constant Entity_Id
:= Scope
(Typ
);
7491 -- The scope must be a package
7493 if not Is_Package_Or_Generic_Package
(Scop
) then
7497 -- A type with a private declaration has a private view declared in
7498 -- the visible part.
7500 if Has_Private_Declaration
(Typ
) then
7504 return List_Containing
(Parent
(Typ
)) =
7505 Visible_Declarations
(Package_Specification
(Scop
));
7506 end Original_View_In_Visible_Part
;
7512 function Prim_Op_Kind
7514 Typ
: Entity_Id
) return Node_Id
7516 Full_Typ
: Entity_Id
:= Typ
;
7517 Loc
: constant Source_Ptr
:= Sloc
(Prim
);
7518 Prim_Op
: Entity_Id
;
7521 -- Retrieve the original primitive operation
7523 Prim_Op
:= Ultimate_Alias
(Prim
);
7525 if Ekind
(Typ
) = E_Record_Type
7526 and then Present
(Corresponding_Concurrent_Type
(Typ
))
7528 Full_Typ
:= Corresponding_Concurrent_Type
(Typ
);
7531 -- When a private tagged type is completed by a concurrent type,
7532 -- retrieve the full view.
7534 if Is_Private_Type
(Full_Typ
) then
7535 Full_Typ
:= Full_View
(Full_Typ
);
7538 if Ekind
(Prim_Op
) = E_Function
then
7540 -- Protected function
7542 if Ekind
(Full_Typ
) = E_Protected_Type
then
7543 return New_Occurrence_Of
(RTE
(RE_POK_Protected_Function
), Loc
);
7547 elsif Ekind
(Full_Typ
) = E_Task_Type
then
7548 return New_Occurrence_Of
(RTE
(RE_POK_Task_Function
), Loc
);
7553 return New_Occurrence_Of
(RTE
(RE_POK_Function
), Loc
);
7557 pragma Assert
(Ekind
(Prim_Op
) = E_Procedure
);
7559 if Ekind
(Full_Typ
) = E_Protected_Type
then
7563 if Is_Primitive_Wrapper
(Prim_Op
)
7564 and then Ekind
(Wrapped_Entity
(Prim_Op
)) = E_Entry
7566 return New_Occurrence_Of
(RTE
(RE_POK_Protected_Entry
), Loc
);
7568 -- Protected procedure
7572 New_Occurrence_Of
(RTE
(RE_POK_Protected_Procedure
), Loc
);
7575 elsif Ekind
(Full_Typ
) = E_Task_Type
then
7579 if Is_Primitive_Wrapper
(Prim_Op
)
7580 and then Ekind
(Wrapped_Entity
(Prim_Op
)) = E_Entry
7582 return New_Occurrence_Of
(RTE
(RE_POK_Task_Entry
), Loc
);
7584 -- Task "procedure". These are the internally Expander-generated
7585 -- procedures (task body for instance).
7588 return New_Occurrence_Of
(RTE
(RE_POK_Task_Procedure
), Loc
);
7591 -- Regular procedure
7594 return New_Occurrence_Of
(RTE
(RE_POK_Procedure
), Loc
);
7599 ------------------------
7600 -- Register_Primitive --
7601 ------------------------
7603 function Register_Primitive
7605 Prim
: Entity_Id
) return List_Id
7608 Iface_Prim
: Entity_Id
;
7609 Iface_Typ
: Entity_Id
;
7610 Iface_DT_Ptr
: Entity_Id
;
7611 Iface_DT_Elmt
: Elmt_Id
;
7612 L
: constant List_Id
:= New_List
;
7615 Tag_Typ
: Entity_Id
;
7616 Thunk_Id
: Entity_Id
;
7617 Thunk_Code
: Node_Id
;
7620 pragma Assert
(not Restriction_Active
(No_Dispatching_Calls
));
7621 pragma Assert
(VM_Target
= No_VM
);
7623 -- Do not register in the dispatch table eliminated primitives
7625 if not RTE_Available
(RE_Tag
)
7626 or else Is_Eliminated
(Ultimate_Alias
(Prim
))
7631 if not Present
(Interface_Alias
(Prim
)) then
7632 Tag_Typ
:= Scope
(DTC_Entity
(Prim
));
7633 Pos
:= DT_Position
(Prim
);
7634 Tag
:= First_Tag_Component
(Tag_Typ
);
7636 if Is_Predefined_Dispatching_Operation
(Prim
)
7637 or else Is_Predefined_Dispatching_Alias
(Prim
)
7640 Node
(Next_Elmt
(First_Elmt
(Access_Disp_Table
(Tag_Typ
))));
7643 Build_Set_Predefined_Prim_Op_Address
(Loc
,
7644 Tag_Node
=> New_Occurrence_Of
(DT_Ptr
, Loc
),
7647 Unchecked_Convert_To
(RTE
(RE_Prim_Ptr
),
7648 Make_Attribute_Reference
(Loc
,
7649 Prefix
=> New_Occurrence_Of
(Prim
, Loc
),
7650 Attribute_Name
=> Name_Unrestricted_Access
))));
7652 -- Register copy of the pointer to the 'size primitive in the TSD
7654 if Chars
(Prim
) = Name_uSize
7655 and then RTE_Record_Component_Available
(RE_Size_Func
)
7657 DT_Ptr
:= Node
(First_Elmt
(Access_Disp_Table
(Tag_Typ
)));
7659 Build_Set_Size_Function
(Loc
,
7660 Tag_Node
=> New_Occurrence_Of
(DT_Ptr
, Loc
),
7661 Size_Func
=> Prim
));
7665 pragma Assert
(Pos
/= Uint_0
and then Pos
<= DT_Entry_Count
(Tag
));
7667 -- Skip registration of primitives located in the C++ part of the
7668 -- dispatch table. Their slot is set by the IC routine.
7670 if not Is_CPP_Class
(Root_Type
(Tag_Typ
))
7671 or else Pos
> CPP_Num_Prims
(Tag_Typ
)
7673 DT_Ptr
:= Node
(First_Elmt
(Access_Disp_Table
(Tag_Typ
)));
7675 Build_Set_Prim_Op_Address
(Loc
,
7677 Tag_Node
=> New_Occurrence_Of
(DT_Ptr
, Loc
),
7680 Unchecked_Convert_To
(RTE
(RE_Prim_Ptr
),
7681 Make_Attribute_Reference
(Loc
,
7682 Prefix
=> New_Occurrence_Of
(Prim
, Loc
),
7683 Attribute_Name
=> Name_Unrestricted_Access
))));
7687 -- Ada 2005 (AI-251): Primitive associated with an interface type
7689 -- Generate the code of the thunk only if the interface type is not an
7690 -- immediate ancestor of Typ; otherwise the dispatch table associated
7691 -- with the interface is the primary dispatch table and we have nothing
7695 Tag_Typ
:= Find_Dispatching_Type
(Alias
(Prim
));
7696 Iface_Typ
:= Find_Dispatching_Type
(Interface_Alias
(Prim
));
7698 pragma Assert
(Is_Interface
(Iface_Typ
));
7700 -- No action needed for interfaces that are ancestors of Typ because
7701 -- their primitives are located in the primary dispatch table.
7703 if Is_Ancestor
(Iface_Typ
, Tag_Typ
, Use_Full_View
=> True) then
7706 -- No action needed for primitives located in the C++ part of the
7707 -- dispatch table. Their slot is set by the IC routine.
7709 elsif Is_CPP_Class
(Root_Type
(Tag_Typ
))
7710 and then DT_Position
(Alias
(Prim
)) <= CPP_Num_Prims
(Tag_Typ
)
7711 and then not Is_Predefined_Dispatching_Operation
(Prim
)
7712 and then not Is_Predefined_Dispatching_Alias
(Prim
)
7717 Expand_Interface_Thunk
(Prim
, Thunk_Id
, Thunk_Code
);
7719 if not Is_Ancestor
(Iface_Typ
, Tag_Typ
, Use_Full_View
=> True)
7720 and then Present
(Thunk_Code
)
7722 -- Generate the code necessary to fill the appropriate entry of
7723 -- the secondary dispatch table of Prim's controlling type with
7724 -- Thunk_Id's address.
7726 Iface_DT_Elmt
:= Find_Interface_ADT
(Tag_Typ
, Iface_Typ
);
7727 Iface_DT_Ptr
:= Node
(Iface_DT_Elmt
);
7728 pragma Assert
(Has_Thunks
(Iface_DT_Ptr
));
7730 Iface_Prim
:= Interface_Alias
(Prim
);
7731 Pos
:= DT_Position
(Iface_Prim
);
7732 Tag
:= First_Tag_Component
(Iface_Typ
);
7734 Prepend_To
(L
, Thunk_Code
);
7736 if Is_Predefined_Dispatching_Operation
(Prim
)
7737 or else Is_Predefined_Dispatching_Alias
(Prim
)
7740 Build_Set_Predefined_Prim_Op_Address
(Loc
,
7742 New_Occurrence_Of
(Node
(Next_Elmt
(Iface_DT_Elmt
)), Loc
),
7745 Unchecked_Convert_To
(RTE
(RE_Prim_Ptr
),
7746 Make_Attribute_Reference
(Loc
,
7747 Prefix
=> New_Occurrence_Of
(Thunk_Id
, Loc
),
7748 Attribute_Name
=> Name_Unrestricted_Access
))));
7750 Next_Elmt
(Iface_DT_Elmt
);
7751 Next_Elmt
(Iface_DT_Elmt
);
7752 Iface_DT_Ptr
:= Node
(Iface_DT_Elmt
);
7753 pragma Assert
(not Has_Thunks
(Iface_DT_Ptr
));
7756 Build_Set_Predefined_Prim_Op_Address
(Loc
,
7758 New_Occurrence_Of
(Node
(Next_Elmt
(Iface_DT_Elmt
)), Loc
),
7761 Unchecked_Convert_To
(RTE
(RE_Prim_Ptr
),
7762 Make_Attribute_Reference
(Loc
,
7764 New_Occurrence_Of
(Alias
(Prim
), Loc
),
7765 Attribute_Name
=> Name_Unrestricted_Access
))));
7768 pragma Assert
(Pos
/= Uint_0
7769 and then Pos
<= DT_Entry_Count
(Tag
));
7772 Build_Set_Prim_Op_Address
(Loc
,
7774 Tag_Node
=> New_Occurrence_Of
(Iface_DT_Ptr
, Loc
),
7777 Unchecked_Convert_To
(RTE
(RE_Prim_Ptr
),
7778 Make_Attribute_Reference
(Loc
,
7779 Prefix
=> New_Occurrence_Of
(Thunk_Id
, Loc
),
7780 Attribute_Name
=> Name_Unrestricted_Access
))));
7782 Next_Elmt
(Iface_DT_Elmt
);
7783 Next_Elmt
(Iface_DT_Elmt
);
7784 Iface_DT_Ptr
:= Node
(Iface_DT_Elmt
);
7785 pragma Assert
(not Has_Thunks
(Iface_DT_Ptr
));
7788 Build_Set_Prim_Op_Address
(Loc
,
7790 Tag_Node
=> New_Occurrence_Of
(Iface_DT_Ptr
, Loc
),
7793 Unchecked_Convert_To
(RTE
(RE_Prim_Ptr
),
7794 Make_Attribute_Reference
(Loc
,
7796 New_Occurrence_Of
(Alias
(Prim
), Loc
),
7797 Attribute_Name
=> Name_Unrestricted_Access
))));
7804 end Register_Primitive
;
7806 -------------------------
7807 -- Set_All_DT_Position --
7808 -------------------------
7810 procedure Set_All_DT_Position
(Typ
: Entity_Id
) is
7812 function In_Predef_Prims_DT
(Prim
: Entity_Id
) return Boolean;
7813 -- Returns True if Prim is located in the dispatch table of
7814 -- predefined primitives
7816 procedure Validate_Position
(Prim
: Entity_Id
);
7817 -- Check that position assigned to Prim is completely safe (it has not
7818 -- been assigned to a previously defined primitive operation of Typ).
7820 ------------------------
7821 -- In_Predef_Prims_DT --
7822 ------------------------
7824 function In_Predef_Prims_DT
(Prim
: Entity_Id
) return Boolean is
7828 -- Predefined primitives
7830 if Is_Predefined_Dispatching_Operation
(Prim
) then
7833 -- Renamings of predefined primitives
7835 elsif Present
(Alias
(Prim
))
7836 and then Is_Predefined_Dispatching_Operation
(Ultimate_Alias
(Prim
))
7838 if Chars
(Ultimate_Alias
(Prim
)) /= Name_Op_Eq
then
7841 -- User-defined renamings of predefined equality have their own
7842 -- slot in the primary dispatch table
7846 while Present
(Alias
(E
)) loop
7847 if Comes_From_Source
(E
) then
7854 return not Comes_From_Source
(E
);
7857 -- User-defined primitives
7862 end In_Predef_Prims_DT
;
7864 -----------------------
7865 -- Validate_Position --
7866 -----------------------
7868 procedure Validate_Position
(Prim
: Entity_Id
) is
7873 -- Aliased primitives are safe
7875 if Present
(Alias
(Prim
)) then
7879 Op_Elmt
:= First_Elmt
(Primitive_Operations
(Typ
));
7880 while Present
(Op_Elmt
) loop
7881 Op
:= Node
(Op_Elmt
);
7883 -- No need to check against itself
7888 -- Primitive operations covering abstract interfaces are
7891 elsif Present
(Interface_Alias
(Op
)) then
7894 -- Predefined dispatching operations are completely safe. They
7895 -- are allocated at fixed positions in a separate table.
7897 elsif Is_Predefined_Dispatching_Operation
(Op
)
7898 or else Is_Predefined_Dispatching_Alias
(Op
)
7902 -- Aliased subprograms are safe
7904 elsif Present
(Alias
(Op
)) then
7907 elsif DT_Position
(Op
) = DT_Position
(Prim
)
7908 and then not Is_Predefined_Dispatching_Operation
(Op
)
7909 and then not Is_Predefined_Dispatching_Operation
(Prim
)
7910 and then not Is_Predefined_Dispatching_Alias
(Op
)
7911 and then not Is_Predefined_Dispatching_Alias
(Prim
)
7913 -- Handle aliased subprograms
7922 if Present
(Overridden_Operation
(Op_1
)) then
7923 Op_1
:= Overridden_Operation
(Op_1
);
7924 elsif Present
(Alias
(Op_1
)) then
7925 Op_1
:= Alias
(Op_1
);
7933 if Present
(Overridden_Operation
(Op_2
)) then
7934 Op_2
:= Overridden_Operation
(Op_2
);
7935 elsif Present
(Alias
(Op_2
)) then
7936 Op_2
:= Alias
(Op_2
);
7942 if Op_1
/= Op_2
then
7943 raise Program_Error
;
7948 Next_Elmt
(Op_Elmt
);
7950 end Validate_Position
;
7954 Parent_Typ
: constant Entity_Id
:= Etype
(Typ
);
7955 First_Prim
: constant Elmt_Id
:= First_Elmt
(Primitive_Operations
(Typ
));
7956 The_Tag
: constant Entity_Id
:= First_Tag_Component
(Typ
);
7958 Adjusted
: Boolean := False;
7959 Finalized
: Boolean := False;
7965 Prim_Elmt
: Elmt_Id
;
7967 -- Start of processing for Set_All_DT_Position
7970 pragma Assert
(Present
(First_Tag_Component
(Typ
)));
7972 -- Set the DT_Position for each primitive operation. Perform some sanity
7973 -- checks to avoid building inconsistent dispatch tables.
7975 -- First stage: Set DTC entity of all the primitive operations. This is
7976 -- required to properly read the DT_Position attribute in latter stages.
7978 Prim_Elmt
:= First_Prim
;
7980 while Present
(Prim_Elmt
) loop
7981 Prim
:= Node
(Prim_Elmt
);
7983 -- Predefined primitives have a separate dispatch table
7985 if not In_Predef_Prims_DT
(Prim
) then
7986 Count_Prim
:= Count_Prim
+ 1;
7989 Set_DTC_Entity_Value
(Typ
, Prim
);
7991 -- Clear any previous value of the DT_Position attribute. In this
7992 -- way we ensure that the final position of all the primitives is
7993 -- established by the following stages of this algorithm.
7995 Set_DT_Position
(Prim
, No_Uint
);
7997 Next_Elmt
(Prim_Elmt
);
8001 Fixed_Prim
: array (Int
range 0 .. Count_Prim
) of Boolean :=
8006 procedure Handle_Inherited_Private_Subprograms
(Typ
: Entity_Id
);
8007 -- Called if Typ is declared in a nested package or a public child
8008 -- package to handle inherited primitives that were inherited by Typ
8009 -- in the visible part, but whose declaration was deferred because
8010 -- the parent operation was private and not visible at that point.
8012 procedure Set_Fixed_Prim
(Pos
: Nat
);
8013 -- Sets to true an element of the Fixed_Prim table to indicate
8014 -- that this entry of the dispatch table of Typ is occupied.
8016 ------------------------------------------
8017 -- Handle_Inherited_Private_Subprograms --
8018 ------------------------------------------
8020 procedure Handle_Inherited_Private_Subprograms
(Typ
: Entity_Id
) is
8023 Op_Elmt_2
: Elmt_Id
;
8024 Prim_Op
: Entity_Id
;
8025 Parent_Subp
: Entity_Id
;
8028 Op_List
:= Primitive_Operations
(Typ
);
8030 Op_Elmt
:= First_Elmt
(Op_List
);
8031 while Present
(Op_Elmt
) loop
8032 Prim_Op
:= Node
(Op_Elmt
);
8034 -- Search primitives that are implicit operations with an
8035 -- internal name whose parent operation has a normal name.
8037 if Present
(Alias
(Prim_Op
))
8038 and then Find_Dispatching_Type
(Alias
(Prim_Op
)) /= Typ
8039 and then not Comes_From_Source
(Prim_Op
)
8040 and then Is_Internal_Name
(Chars
(Prim_Op
))
8041 and then not Is_Internal_Name
(Chars
(Alias
(Prim_Op
)))
8043 Parent_Subp
:= Alias
(Prim_Op
);
8045 -- Check if the type has an explicit overriding for this
8048 Op_Elmt_2
:= Next_Elmt
(Op_Elmt
);
8049 while Present
(Op_Elmt_2
) loop
8050 if Chars
(Node
(Op_Elmt_2
)) = Chars
(Parent_Subp
)
8051 and then Type_Conformant
(Prim_Op
, Node
(Op_Elmt_2
))
8053 Set_DT_Position
(Prim_Op
, DT_Position
(Parent_Subp
));
8054 Set_DT_Position
(Node
(Op_Elmt_2
),
8055 DT_Position
(Parent_Subp
));
8056 Set_Fixed_Prim
(UI_To_Int
(DT_Position
(Prim_Op
)));
8058 goto Next_Primitive
;
8061 Next_Elmt
(Op_Elmt_2
);
8066 Next_Elmt
(Op_Elmt
);
8068 end Handle_Inherited_Private_Subprograms
;
8070 --------------------
8071 -- Set_Fixed_Prim --
8072 --------------------
8074 procedure Set_Fixed_Prim
(Pos
: Nat
) is
8076 pragma Assert
(Pos
<= Count_Prim
);
8077 Fixed_Prim
(Pos
) := True;
8079 when Constraint_Error
=>
8080 raise Program_Error
;
8084 -- In case of nested packages and public child package it may be
8085 -- necessary a special management on inherited subprograms so that
8086 -- the dispatch table is properly filled.
8088 if Ekind
(Scope
(Scope
(Typ
))) = E_Package
8089 and then Scope
(Scope
(Typ
)) /= Standard_Standard
8090 and then ((Is_Derived_Type
(Typ
) and then not Is_Private_Type
(Typ
))
8092 (Nkind
(Parent
(Typ
)) = N_Private_Extension_Declaration
8093 and then Is_Generic_Type
(Typ
)))
8094 and then In_Open_Scopes
(Scope
(Etype
(Typ
)))
8095 and then Is_Base_Type
(Typ
)
8097 Handle_Inherited_Private_Subprograms
(Typ
);
8100 -- Second stage: Register fixed entries
8103 Prim_Elmt
:= First_Prim
;
8104 while Present
(Prim_Elmt
) loop
8105 Prim
:= Node
(Prim_Elmt
);
8107 -- Predefined primitives have a separate table and all its
8108 -- entries are at predefined fixed positions.
8110 if In_Predef_Prims_DT
(Prim
) then
8111 if Is_Predefined_Dispatching_Operation
(Prim
) then
8112 Set_DT_Position
(Prim
, Default_Prim_Op_Position
(Prim
));
8114 else pragma Assert
(Present
(Alias
(Prim
)));
8115 Set_DT_Position
(Prim
,
8116 Default_Prim_Op_Position
(Ultimate_Alias
(Prim
)));
8119 -- Overriding primitives of ancestor abstract interfaces
8121 elsif Present
(Interface_Alias
(Prim
))
8122 and then Is_Ancestor
8123 (Find_Dispatching_Type
(Interface_Alias
(Prim
)), Typ
,
8124 Use_Full_View
=> True)
8126 pragma Assert
(DT_Position
(Prim
) = No_Uint
8127 and then Present
(DTC_Entity
(Interface_Alias
(Prim
))));
8129 E
:= Interface_Alias
(Prim
);
8130 Set_DT_Position
(Prim
, DT_Position
(E
));
8133 (DT_Position
(Alias
(Prim
)) = No_Uint
8134 or else DT_Position
(Alias
(Prim
)) = DT_Position
(E
));
8135 Set_DT_Position
(Alias
(Prim
), DT_Position
(E
));
8136 Set_Fixed_Prim
(UI_To_Int
(DT_Position
(Prim
)));
8138 -- Overriding primitives must use the same entry as the
8139 -- overridden primitive.
8141 elsif not Present
(Interface_Alias
(Prim
))
8142 and then Present
(Alias
(Prim
))
8143 and then Chars
(Prim
) = Chars
(Alias
(Prim
))
8144 and then Find_Dispatching_Type
(Alias
(Prim
)) /= Typ
8145 and then Is_Ancestor
8146 (Find_Dispatching_Type
(Alias
(Prim
)), Typ
,
8147 Use_Full_View
=> True)
8148 and then Present
(DTC_Entity
(Alias
(Prim
)))
8151 Set_DT_Position
(Prim
, DT_Position
(E
));
8153 if not Is_Predefined_Dispatching_Alias
(E
) then
8154 Set_Fixed_Prim
(UI_To_Int
(DT_Position
(E
)));
8158 Next_Elmt
(Prim_Elmt
);
8161 -- Third stage: Fix the position of all the new primitives. Entries
8162 -- associated with primitives covering interfaces are handled in a
8165 Prim_Elmt
:= First_Prim
;
8166 while Present
(Prim_Elmt
) loop
8167 Prim
:= Node
(Prim_Elmt
);
8169 -- Skip primitives previously set entries
8171 if DT_Position
(Prim
) /= No_Uint
then
8174 -- Primitives covering interface primitives are handled later
8176 elsif Present
(Interface_Alias
(Prim
)) then
8180 -- Take the next available position in the DT
8183 Nb_Prim
:= Nb_Prim
+ 1;
8184 pragma Assert
(Nb_Prim
<= Count_Prim
);
8185 exit when not Fixed_Prim
(Nb_Prim
);
8188 Set_DT_Position
(Prim
, UI_From_Int
(Nb_Prim
));
8189 Set_Fixed_Prim
(Nb_Prim
);
8192 Next_Elmt
(Prim_Elmt
);
8196 -- Fourth stage: Complete the decoration of primitives covering
8197 -- interfaces (that is, propagate the DT_Position attribute from
8198 -- the aliased primitive)
8200 Prim_Elmt
:= First_Prim
;
8201 while Present
(Prim_Elmt
) loop
8202 Prim
:= Node
(Prim_Elmt
);
8204 if DT_Position
(Prim
) = No_Uint
8205 and then Present
(Interface_Alias
(Prim
))
8207 pragma Assert
(Present
(Alias
(Prim
))
8208 and then Find_Dispatching_Type
(Alias
(Prim
)) = Typ
);
8210 -- Check if this entry will be placed in the primary DT
8213 (Find_Dispatching_Type
(Interface_Alias
(Prim
)), Typ
,
8214 Use_Full_View
=> True)
8216 pragma Assert
(DT_Position
(Alias
(Prim
)) /= No_Uint
);
8217 Set_DT_Position
(Prim
, DT_Position
(Alias
(Prim
)));
8219 -- Otherwise it will be placed in the secondary DT
8223 (DT_Position
(Interface_Alias
(Prim
)) /= No_Uint
);
8224 Set_DT_Position
(Prim
,
8225 DT_Position
(Interface_Alias
(Prim
)));
8229 Next_Elmt
(Prim_Elmt
);
8232 -- Generate listing showing the contents of the dispatch tables. This
8233 -- action is done before some further static checks because in case of
8234 -- critical errors caused by a wrong dispatch table we need to see the
8235 -- contents of such table.
8237 if Debug_Flag_ZZ
then
8241 -- Final stage: Ensure that the table is correct plus some further
8242 -- verifications concerning the primitives.
8244 Prim_Elmt
:= First_Prim
;
8246 while Present
(Prim_Elmt
) loop
8247 Prim
:= Node
(Prim_Elmt
);
8249 -- At this point all the primitives MUST have a position in the
8252 if DT_Position
(Prim
) = No_Uint
then
8253 raise Program_Error
;
8256 -- Calculate real size of the dispatch table
8258 if not In_Predef_Prims_DT
(Prim
)
8259 and then UI_To_Int
(DT_Position
(Prim
)) > DT_Length
8261 DT_Length
:= UI_To_Int
(DT_Position
(Prim
));
8264 -- Ensure that the assigned position to non-predefined dispatching
8265 -- operations in the dispatch table is correct.
8267 if not Is_Predefined_Dispatching_Operation
(Prim
)
8268 and then not Is_Predefined_Dispatching_Alias
(Prim
)
8270 Validate_Position
(Prim
);
8273 if Chars
(Prim
) = Name_Finalize
then
8277 if Chars
(Prim
) = Name_Adjust
then
8281 -- An abstract operation cannot be declared in the private part for a
8282 -- visible abstract type, because it can't be overridden outside this
8283 -- package hierarchy. For explicit declarations this is checked at
8284 -- the point of declaration, but for inherited operations it must be
8285 -- done when building the dispatch table.
8287 -- Ada 2005 (AI-251): Primitives associated with interfaces are
8288 -- excluded from this check because interfaces must be visible in
8289 -- the public and private part (RM 7.3 (7.3/2))
8291 -- We disable this check in Relaxed_RM_Semantics mode, to accommodate
8294 if not Relaxed_RM_Semantics
8295 and then Is_Abstract_Type
(Typ
)
8296 and then Is_Abstract_Subprogram
(Prim
)
8297 and then Present
(Alias
(Prim
))
8298 and then not Is_Interface
8299 (Find_Dispatching_Type
(Ultimate_Alias
(Prim
)))
8300 and then not Present
(Interface_Alias
(Prim
))
8301 and then Is_Derived_Type
(Typ
)
8302 and then In_Private_Part
(Current_Scope
)
8304 List_Containing
(Parent
(Prim
)) =
8305 Private_Declarations
(Package_Specification
(Current_Scope
))
8306 and then Original_View_In_Visible_Part
(Typ
)
8308 -- We exclude Input and Output stream operations because
8309 -- Limited_Controlled inherits useless Input and Output stream
8310 -- operations from Root_Controlled, which can never be overridden.
8312 if not Is_TSS
(Prim
, TSS_Stream_Input
)
8314 not Is_TSS
(Prim
, TSS_Stream_Output
)
8317 ("abstract inherited private operation&" &
8318 " must be overridden (RM 3.9.3(10))",
8319 Parent
(Typ
), Prim
);
8323 Next_Elmt
(Prim_Elmt
);
8328 if Is_Controlled
(Typ
) then
8329 if not Finalized
then
8331 ("controlled type has no explicit Finalize method??", Typ
);
8333 elsif not Adjusted
then
8335 ("controlled type has no explicit Adjust method??", Typ
);
8339 -- Set the final size of the Dispatch Table
8341 Set_DT_Entry_Count
(The_Tag
, UI_From_Int
(DT_Length
));
8343 -- The derived type must have at least as many components as its parent
8344 -- (for root types Etype points to itself and the test cannot fail).
8346 if DT_Entry_Count
(The_Tag
) <
8347 DT_Entry_Count
(First_Tag_Component
(Parent_Typ
))
8349 raise Program_Error
;
8351 end Set_All_DT_Position
;
8353 --------------------------
8354 -- Set_CPP_Constructors --
8355 --------------------------
8357 procedure Set_CPP_Constructors
(Typ
: Entity_Id
) is
8359 function Gen_Parameters_Profile
(E
: Entity_Id
) return List_Id
;
8360 -- Duplicate the parameters profile of the imported C++ constructor
8361 -- adding an access to the object as an additional parameter.
8363 ----------------------------
8364 -- Gen_Parameters_Profile --
8365 ----------------------------
8367 function Gen_Parameters_Profile
(E
: Entity_Id
) return List_Id
is
8368 Loc
: constant Source_Ptr
:= Sloc
(E
);
8375 Make_Parameter_Specification
(Loc
,
8376 Defining_Identifier
=>
8377 Make_Defining_Identifier
(Loc
, Name_uInit
),
8378 Parameter_Type
=> New_Occurrence_Of
(Typ
, Loc
)));
8380 if Present
(Parameter_Specifications
(Parent
(E
))) then
8381 P
:= First
(Parameter_Specifications
(Parent
(E
)));
8382 while Present
(P
) loop
8384 Make_Parameter_Specification
(Loc
,
8385 Defining_Identifier
=>
8386 Make_Defining_Identifier
(Loc
,
8387 Chars
=> Chars
(Defining_Identifier
(P
))),
8388 Parameter_Type
=> New_Copy_Tree
(Parameter_Type
(P
)),
8389 Expression
=> New_Copy_Tree
(Expression
(P
))));
8395 end Gen_Parameters_Profile
;
8401 Found
: Boolean := False;
8407 Covers_Default_Constructor
: Entity_Id
:= Empty
;
8409 -- Start of processing for Set_CPP_Constructor
8412 pragma Assert
(Is_CPP_Class
(Typ
));
8414 -- Look for the constructor entities
8416 E
:= Next_Entity
(Typ
);
8417 while Present
(E
) loop
8418 if Ekind
(E
) = E_Function
8419 and then Is_Constructor
(E
)
8423 Parms
:= Gen_Parameters_Profile
(E
);
8425 Make_Defining_Identifier
(Loc
,
8426 Chars
=> Make_Init_Proc_Name
(Typ
));
8428 -- Case 1: Constructor of untagged type
8430 -- If the C++ class has no virtual methods then the matching Ada
8431 -- type is an untagged record type. In such case there is no need
8432 -- to generate a wrapper of the C++ constructor because the _tag
8433 -- component is not available.
8435 if not Is_Tagged_Type
(Typ
) then
8437 (Make_Subprogram_Declaration
(Loc
,
8439 Make_Procedure_Specification
(Loc
,
8440 Defining_Unit_Name
=> IP
,
8441 Parameter_Specifications
=> Parms
)));
8443 Set_Init_Proc
(Typ
, IP
);
8444 Set_Is_Imported
(IP
);
8445 Set_Is_Constructor
(IP
);
8446 Set_Interface_Name
(IP
, Interface_Name
(E
));
8447 Set_Convention
(IP
, Convention_CPP
);
8449 Set_Has_Completion
(IP
);
8451 -- Case 2: Constructor of a tagged type
8453 -- In this case we generate the IP as a wrapper of the the
8454 -- C++ constructor because IP must also save copy of the _tag
8455 -- generated in the C++ side. The copy of the _tag is used by
8456 -- Build_CPP_Init_Procedure to elaborate derivations of C++ types.
8459 -- procedure IP (_init : Typ; ...) is
8460 -- procedure ConstructorP (_init : Typ; ...);
8461 -- pragma Import (ConstructorP);
8463 -- ConstructorP (_init, ...);
8464 -- if Typ._tag = null then
8465 -- Typ._tag := _init._tag;
8471 Body_Stmts
: constant List_Id
:= New_List
;
8472 Constructor_Id
: Entity_Id
;
8473 Constructor_Decl_Node
: Node_Id
;
8474 Init_Tags_List
: List_Id
;
8477 Constructor_Id
:= Make_Temporary
(Loc
, 'P');
8479 Constructor_Decl_Node
:=
8480 Make_Subprogram_Declaration
(Loc
,
8481 Make_Procedure_Specification
(Loc
,
8482 Defining_Unit_Name
=> Constructor_Id
,
8483 Parameter_Specifications
=> Parms
));
8485 Set_Is_Imported
(Constructor_Id
);
8486 Set_Is_Constructor
(Constructor_Id
);
8487 Set_Interface_Name
(Constructor_Id
, Interface_Name
(E
));
8488 Set_Convention
(Constructor_Id
, Convention_CPP
);
8489 Set_Is_Public
(Constructor_Id
);
8490 Set_Has_Completion
(Constructor_Id
);
8492 -- Build the init procedure as a wrapper of this constructor
8494 Parms
:= Gen_Parameters_Profile
(E
);
8496 -- Invoke the C++ constructor
8499 Actuals
: constant List_Id
:= New_List
;
8503 while Present
(P
) loop
8505 New_Occurrence_Of
(Defining_Identifier
(P
), Loc
));
8509 Append_To
(Body_Stmts
,
8510 Make_Procedure_Call_Statement
(Loc
,
8511 Name
=> New_Occurrence_Of
(Constructor_Id
, Loc
),
8512 Parameter_Associations
=> Actuals
));
8515 -- Initialize copies of C++ primary and secondary tags
8517 Init_Tags_List
:= New_List
;
8524 Tag_Elmt
:= First_Elmt
(Access_Disp_Table
(Typ
));
8525 Tag_Comp
:= First_Tag_Component
(Typ
);
8527 while Present
(Tag_Elmt
)
8528 and then Is_Tag
(Node
(Tag_Elmt
))
8530 -- Skip the following assertion with primary tags
8531 -- because Related_Type is not set on primary tag
8535 (Tag_Comp
= First_Tag_Component
(Typ
)
8536 or else Related_Type
(Node
(Tag_Elmt
))
8537 = Related_Type
(Tag_Comp
));
8539 Append_To
(Init_Tags_List
,
8540 Make_Assignment_Statement
(Loc
,
8542 New_Occurrence_Of
(Node
(Tag_Elmt
), Loc
),
8544 Make_Selected_Component
(Loc
,
8546 Make_Identifier
(Loc
, Name_uInit
),
8548 New_Occurrence_Of
(Tag_Comp
, Loc
))));
8550 Tag_Comp
:= Next_Tag_Component
(Tag_Comp
);
8551 Next_Elmt
(Tag_Elmt
);
8555 Append_To
(Body_Stmts
,
8556 Make_If_Statement
(Loc
,
8561 (Node
(First_Elmt
(Access_Disp_Table
(Typ
))),
8564 Unchecked_Convert_To
(RTE
(RE_Tag
),
8565 New_Occurrence_Of
(RTE
(RE_Null_Address
), Loc
))),
8566 Then_Statements
=> Init_Tags_List
));
8569 Make_Subprogram_Body
(Loc
,
8571 Make_Procedure_Specification
(Loc
,
8572 Defining_Unit_Name
=> IP
,
8573 Parameter_Specifications
=> Parms
),
8574 Declarations
=> New_List
(Constructor_Decl_Node
),
8575 Handled_Statement_Sequence
=>
8576 Make_Handled_Sequence_Of_Statements
(Loc
,
8577 Statements
=> Body_Stmts
,
8578 Exception_Handlers
=> No_List
));
8580 Discard_Node
(IP_Body
);
8581 Set_Init_Proc
(Typ
, IP
);
8585 -- If this constructor has parameters and all its parameters have
8586 -- defaults then it covers the default constructor. The semantic
8587 -- analyzer ensures that only one constructor with defaults covers
8588 -- the default constructor.
8590 if Present
(Parameter_Specifications
(Parent
(E
)))
8591 and then Needs_No_Actuals
(E
)
8593 Covers_Default_Constructor
:= IP
;
8600 -- If there are no constructors, mark the type as abstract since we
8601 -- won't be able to declare objects of that type.
8604 Set_Is_Abstract_Type
(Typ
);
8607 -- Handle constructor that has all its parameters with defaults and
8608 -- hence it covers the default constructor. We generate a wrapper IP
8609 -- which calls the covering constructor.
8611 if Present
(Covers_Default_Constructor
) then
8613 Body_Stmts
: List_Id
;
8616 Loc
:= Sloc
(Covers_Default_Constructor
);
8618 Body_Stmts
:= New_List
(
8619 Make_Procedure_Call_Statement
(Loc
,
8621 New_Occurrence_Of
(Covers_Default_Constructor
, Loc
),
8622 Parameter_Associations
=> New_List
(
8623 Make_Identifier
(Loc
, Name_uInit
))));
8625 IP
:= Make_Defining_Identifier
(Loc
, Make_Init_Proc_Name
(Typ
));
8628 Make_Subprogram_Body
(Loc
,
8630 Make_Procedure_Specification
(Loc
,
8631 Defining_Unit_Name
=> IP
,
8632 Parameter_Specifications
=> New_List
(
8633 Make_Parameter_Specification
(Loc
,
8634 Defining_Identifier
=>
8635 Make_Defining_Identifier
(Loc
, Name_uInit
),
8636 Parameter_Type
=> New_Occurrence_Of
(Typ
, Loc
)))),
8638 Declarations
=> No_List
,
8640 Handled_Statement_Sequence
=>
8641 Make_Handled_Sequence_Of_Statements
(Loc
,
8642 Statements
=> Body_Stmts
,
8643 Exception_Handlers
=> No_List
));
8645 Discard_Node
(IP_Body
);
8646 Set_Init_Proc
(Typ
, IP
);
8650 -- If the CPP type has constructors then it must import also the default
8651 -- C++ constructor. It is required for default initialization of objects
8652 -- of the type. It is also required to elaborate objects of Ada types
8653 -- that are defined as derivations of this CPP type.
8655 if Has_CPP_Constructors
(Typ
)
8656 and then No
(Init_Proc
(Typ
))
8658 Error_Msg_N
("??default constructor must be imported from C++", Typ
);
8660 end Set_CPP_Constructors
;
8662 --------------------------
8663 -- Set_DTC_Entity_Value --
8664 --------------------------
8666 procedure Set_DTC_Entity_Value
8667 (Tagged_Type
: Entity_Id
;
8671 if Present
(Interface_Alias
(Prim
))
8672 and then Is_Interface
8673 (Find_Dispatching_Type
(Interface_Alias
(Prim
)))
8675 Set_DTC_Entity
(Prim
,
8678 Iface
=> Find_Dispatching_Type
(Interface_Alias
(Prim
))));
8680 Set_DTC_Entity
(Prim
,
8681 First_Tag_Component
(Tagged_Type
));
8683 end Set_DTC_Entity_Value
;
8689 function Tagged_Kind
(T
: Entity_Id
) return Node_Id
is
8690 Conc_Typ
: Entity_Id
;
8691 Loc
: constant Source_Ptr
:= Sloc
(T
);
8695 (Is_Tagged_Type
(T
) and then RTE_Available
(RE_Tagged_Kind
));
8699 if Is_Abstract_Type
(T
) then
8700 if Is_Limited_Record
(T
) then
8701 return New_Occurrence_Of
8702 (RTE
(RE_TK_Abstract_Limited_Tagged
), Loc
);
8704 return New_Occurrence_Of
8705 (RTE
(RE_TK_Abstract_Tagged
), Loc
);
8710 elsif Is_Concurrent_Record_Type
(T
) then
8711 Conc_Typ
:= Corresponding_Concurrent_Type
(T
);
8713 if Present
(Full_View
(Conc_Typ
)) then
8714 Conc_Typ
:= Full_View
(Conc_Typ
);
8717 if Ekind
(Conc_Typ
) = E_Protected_Type
then
8718 return New_Occurrence_Of
(RTE
(RE_TK_Protected
), Loc
);
8720 pragma Assert
(Ekind
(Conc_Typ
) = E_Task_Type
);
8721 return New_Occurrence_Of
(RTE
(RE_TK_Task
), Loc
);
8724 -- Regular tagged kinds
8727 if Is_Limited_Record
(T
) then
8728 return New_Occurrence_Of
(RTE
(RE_TK_Limited_Tagged
), Loc
);
8730 return New_Occurrence_Of
(RTE
(RE_TK_Tagged
), Loc
);
8739 procedure Write_DT
(Typ
: Entity_Id
) is
8744 -- Protect this procedure against wrong usage. Required because it will
8745 -- be used directly from GDB
8747 if not (Typ
<= Last_Node_Id
)
8748 or else not Is_Tagged_Type
(Typ
)
8750 Write_Str
("wrong usage: Write_DT must be used with tagged types");
8755 Write_Int
(Int
(Typ
));
8757 Write_Name
(Chars
(Typ
));
8759 if Is_Interface
(Typ
) then
8760 Write_Str
(" is interface");
8765 Elmt
:= First_Elmt
(Primitive_Operations
(Typ
));
8766 while Present
(Elmt
) loop
8767 Prim
:= Node
(Elmt
);
8770 -- Indicate if this primitive will be allocated in the primary
8771 -- dispatch table or in a secondary dispatch table associated
8772 -- with an abstract interface type
8774 if Present
(DTC_Entity
(Prim
)) then
8775 if Etype
(DTC_Entity
(Prim
)) = RTE
(RE_Tag
) then
8782 -- Output the node of this primitive operation and its name
8784 Write_Int
(Int
(Prim
));
8787 if Is_Predefined_Dispatching_Operation
(Prim
) then
8788 Write_Str
("(predefined) ");
8791 -- Prefix the name of the primitive with its corresponding tagged
8792 -- type to facilitate seeing inherited primitives.
8794 if Present
(Alias
(Prim
)) then
8796 (Chars
(Find_Dispatching_Type
(Ultimate_Alias
(Prim
))));
8798 Write_Name
(Chars
(Typ
));
8802 Write_Name
(Chars
(Prim
));
8804 -- Indicate if this primitive has an aliased primitive
8806 if Present
(Alias
(Prim
)) then
8807 Write_Str
(" (alias = ");
8808 Write_Int
(Int
(Alias
(Prim
)));
8810 -- If the DTC_Entity attribute is already set we can also output
8811 -- the name of the interface covered by this primitive (if any).
8813 if Ekind_In
(Alias
(Prim
), E_Function
, E_Procedure
)
8814 and then Present
(DTC_Entity
(Alias
(Prim
)))
8815 and then Is_Interface
(Scope
(DTC_Entity
(Alias
(Prim
))))
8817 Write_Str
(" from interface ");
8818 Write_Name
(Chars
(Scope
(DTC_Entity
(Alias
(Prim
)))));
8821 if Present
(Interface_Alias
(Prim
)) then
8822 Write_Str
(", AI_Alias of ");
8824 if Is_Null_Interface_Primitive
(Interface_Alias
(Prim
)) then
8825 Write_Str
("null primitive ");
8829 (Chars
(Find_Dispatching_Type
(Interface_Alias
(Prim
))));
8831 Write_Int
(Int
(Interface_Alias
(Prim
)));
8837 -- Display the final position of this primitive in its associated
8838 -- (primary or secondary) dispatch table.
8840 if Present
(DTC_Entity
(Prim
))
8841 and then DT_Position
(Prim
) /= No_Uint
8843 Write_Str
(" at #");
8844 Write_Int
(UI_To_Int
(DT_Position
(Prim
)));
8847 if Is_Abstract_Subprogram
(Prim
) then
8848 Write_Str
(" is abstract;");
8850 -- Check if this is a null primitive
8852 elsif Comes_From_Source
(Prim
)
8853 and then Ekind
(Prim
) = E_Procedure
8854 and then Null_Present
(Parent
(Prim
))
8856 Write_Str
(" is null;");
8859 if Is_Eliminated
(Ultimate_Alias
(Prim
)) then
8860 Write_Str
(" (eliminated)");
8863 if Is_Imported
(Prim
)
8864 and then Convention
(Prim
) = Convention_CPP
8866 Write_Str
(" (C++)");