1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2023, 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 Accessibility
; use Accessibility
;
27 with Atree
; use Atree
;
28 with Checks
; use Checks
;
29 with Debug
; use Debug
;
30 with Einfo
; use Einfo
;
31 with Einfo
.Entities
; use Einfo
.Entities
;
32 with Einfo
.Utils
; use Einfo
.Utils
;
33 with Elists
; use Elists
;
34 with Errout
; use Errout
;
35 with Expander
; use Expander
;
36 with Exp_Atag
; use Exp_Atag
;
37 with Exp_Ch6
; use Exp_Ch6
;
38 with Exp_CG
; use Exp_CG
;
39 with Exp_Dbug
; use Exp_Dbug
;
40 with Exp_Tss
; use Exp_Tss
;
41 with Exp_Util
; use Exp_Util
;
42 with Freeze
; use Freeze
;
43 with Ghost
; use Ghost
;
44 with Itypes
; use Itypes
;
45 with Layout
; use Layout
;
46 with Nlists
; use Nlists
;
47 with Nmake
; use Nmake
;
48 with Namet
; use Namet
;
50 with Output
; use Output
;
51 with Restrict
; use Restrict
;
52 with Rident
; use Rident
;
53 with Rtsfind
; use Rtsfind
;
55 with Sem_Aux
; use Sem_Aux
;
56 with Sem_Ch6
; use Sem_Ch6
;
57 with Sem_Ch7
; use Sem_Ch7
;
58 with Sem_Ch8
; use Sem_Ch8
;
59 with Sem_Disp
; use Sem_Disp
;
60 with Sem_Eval
; use Sem_Eval
;
61 with Sem_Res
; use Sem_Res
;
62 with Sem_Type
; use Sem_Type
;
63 with Sem_Util
; use Sem_Util
;
64 with Sinfo
; use Sinfo
;
65 with Sinfo
.Nodes
; use Sinfo
.Nodes
;
66 with Sinfo
.Utils
; use Sinfo
.Utils
;
67 with Snames
; use Snames
;
68 with Stand
; use Stand
;
69 with Stringt
; use Stringt
;
70 with Strub
; use Strub
;
71 with SCIL_LL
; use SCIL_LL
;
72 with Tbuild
; use Tbuild
;
74 package body Exp_Disp
is
76 -----------------------
77 -- Local Subprograms --
78 -----------------------
80 function Default_Prim_Op_Position
(E
: Entity_Id
) return Uint
;
81 -- Ada 2005 (AI-251): Returns the fixed position in the dispatch table
82 -- of the default primitive operations.
84 procedure Expand_Interface_Thunk
86 Thunk_Id
: out Entity_Id
;
87 Thunk_Code
: out List_Id
;
89 -- Ada 2005 (AI-251): When a tagged type implements abstract interfaces we
90 -- generate additional subprograms (thunks) associated with each primitive
91 -- Prim to have a layout compatible with the C++ ABI. The thunk displaces
92 -- the pointers to the actuals that depend on the controlling type before
93 -- transferring control to the target subprogram. If there is no need to
94 -- generate the thunk, then Thunk_Id is set to Empty. Otherwise Thunk_Id
95 -- is set to the defining identifier of the thunk and Thunk_Code to the
96 -- code generated for the thunk respectively.
98 procedure Expand_Secondary_Stack_Thunk
100 Thunk_Id
: out Entity_Id
;
101 Thunk_Code
: out Node_Id
);
102 -- When a primitive function of a tagged type can dispatch on result and
103 -- the tagged type is not returned on the secondary stack, we generate an
104 -- additional function (thunk) that calls the primitive function with the
105 -- same actuals and move its result onto the secondary stack. This thunk
106 -- is intended to be put into the slot of the primitive function in the
107 -- dispatch table, so as to be invoked in lieu of the primitive function
108 -- in dispatching calls. If there is no need to generate the thunk, then
109 -- Thunk_Id is set to Empty. Otherwise Thunk_Id is set to the defining
110 -- identifier of the thunk and Thunk_Code to the code generated for the
111 -- thunk respectively.
113 function Has_DT
(Typ
: Entity_Id
) return Boolean;
114 pragma Inline
(Has_DT
);
115 -- Returns true if we generate a dispatch table for tagged type Typ
117 function Is_Predefined_Dispatching_Alias
(Prim
: Entity_Id
) return Boolean;
118 -- Returns true if Prim is not a predefined dispatching primitive but it is
119 -- an alias of a predefined dispatching primitive (i.e. through a renaming)
121 function New_Value
(From
: Node_Id
) return Node_Id
;
122 -- From is the original Expression. New_Value is equivalent to a call to
123 -- Duplicate_Subexpr with an explicit dereference when From is an access
126 function Prim_Op_Kind
128 Typ
: Entity_Id
) return Node_Id
;
129 -- Ada 2005 (AI-345): Determine the primitive operation kind of Prim
130 -- according to its type Typ. Return a reference to an RE_Prim_Op_Kind
131 -- enumeration value.
133 function Tagged_Kind
(T
: Entity_Id
) return Node_Id
;
134 -- Ada 2005 (AI-345): Determine the tagged kind of T and return a reference
135 -- to an RE_Tagged_Kind enumeration value.
137 ----------------------
138 -- Apply_Tag_Checks --
139 ----------------------
141 procedure Apply_Tag_Checks
(Call_Node
: Node_Id
) is
142 Loc
: constant Source_Ptr
:= Sloc
(Call_Node
);
143 Ctrl_Arg
: constant Node_Id
:= Controlling_Argument
(Call_Node
);
144 Ctrl_Typ
: constant Entity_Id
:= Base_Type
(Etype
(Ctrl_Arg
));
145 Param_List
: constant List_Id
:= Parameter_Associations
(Call_Node
);
151 Eq_Prim_Op
: Entity_Id
:= Empty
;
154 if No_Run_Time_Mode
then
155 Error_Msg_CRT
("tagged types", Call_Node
);
159 -- Apply_Tag_Checks is called directly from the semantics, so we
160 -- need a check to see whether expansion is active before proceeding.
161 -- In addition, there is no need to expand the call when compiling
162 -- under restriction No_Dispatching_Calls; the semantic analyzer has
163 -- previously notified the violation of this restriction.
165 if not Expander_Active
166 or else Restriction_Active
(No_Dispatching_Calls
)
171 -- Set subprogram. If this is an inherited operation that was
172 -- overridden, the body that is being called is its alias.
174 Subp
:= Entity
(Name
(Call_Node
));
176 if Present
(Alias
(Subp
))
177 and then Is_Inherited_Operation
(Subp
)
178 and then No
(DTC_Entity
(Subp
))
180 Subp
:= Alias
(Subp
);
183 -- Definition of the class-wide type and the tagged type
185 -- If the controlling argument is itself a tag rather than a tagged
186 -- object, then use the class-wide type associated with the subprogram's
187 -- controlling type. This case can occur when a call to an inherited
188 -- primitive has an actual that originated from a default parameter
189 -- given by a tag-indeterminate call and when there is no other
190 -- controlling argument providing the tag (AI-239 requires dispatching).
191 -- This capability of dispatching directly by tag is also needed by the
192 -- implementation of AI-260 (for the generic dispatching constructors).
194 if Is_RTE
(Ctrl_Typ
, RE_Tag
)
195 or else Is_RTE
(Ctrl_Typ
, RE_Interface_Tag
)
197 CW_Typ
:= Class_Wide_Type
(Find_Dispatching_Type
(Subp
));
199 -- Class_Wide_Type is applied to the expressions used to initialize
200 -- CW_Typ, to ensure that CW_Typ always denotes a class-wide type, since
201 -- there are cases where the controlling type is resolved to a specific
202 -- type (such as for designated types of arguments such as CW'Access).
204 elsif Is_Access_Type
(Ctrl_Typ
) then
205 CW_Typ
:= Class_Wide_Type
(Designated_Type
(Ctrl_Typ
));
208 CW_Typ
:= Class_Wide_Type
(Ctrl_Typ
);
211 Typ
:= Find_Specific_Type
(CW_Typ
);
213 if not Is_Limited_Type
(Typ
) then
214 Eq_Prim_Op
:= Find_Prim_Op
(Typ
, Name_Op_Eq
);
217 -- Dispatching call to C++ primitive
219 if Is_CPP_Class
(Typ
) then
222 -- Dispatching call to Ada primitive
224 elsif Present
(Param_List
) then
226 -- Generate the Tag checks when appropriate
228 Param
:= First_Actual
(Call_Node
);
229 while Present
(Param
) loop
231 -- No tag check with itself
233 if Param
= Ctrl_Arg
then
236 -- No tag check for parameter whose type is neither tagged nor
237 -- access to tagged (for access parameters)
239 elsif No
(Find_Controlling_Arg
(Param
)) then
242 -- No tag check for function dispatching on result if the
243 -- Tag given by the context is this one
245 elsif Find_Controlling_Arg
(Param
) = Ctrl_Arg
then
248 -- "=" is the only dispatching operation allowed to get operands
249 -- with incompatible tags (it just returns false). We use
250 -- Duplicate_Subexpr_Move_Checks instead of calling Relocate_Node
251 -- because the value will be duplicated to check the tags.
253 elsif Subp
= Eq_Prim_Op
then
256 -- No check in presence of suppress flags
258 elsif Tag_Checks_Suppressed
(Etype
(Param
))
259 or else (Is_Access_Type
(Etype
(Param
))
260 and then Tag_Checks_Suppressed
261 (Designated_Type
(Etype
(Param
))))
265 -- Optimization: no tag checks if the parameters are identical
267 elsif Is_Entity_Name
(Param
)
268 and then Is_Entity_Name
(Ctrl_Arg
)
269 and then Entity
(Param
) = Entity
(Ctrl_Arg
)
273 -- Now we need to generate the Tag check
276 -- Generate code for tag equality check
278 -- Perhaps should have Checks.Apply_Tag_Equality_Check???
280 Insert_Action
(Ctrl_Arg
,
281 Make_Implicit_If_Statement
(Call_Node
,
285 Make_Selected_Component
(Loc
,
286 Prefix
=> New_Value
(Ctrl_Arg
),
289 (First_Tag_Component
(Typ
), Loc
)),
292 Make_Selected_Component
(Loc
,
294 Unchecked_Convert_To
(Typ
, New_Value
(Param
)),
297 (First_Tag_Component
(Typ
), Loc
))),
300 New_List
(New_Constraint_Error
(Loc
))));
306 end Apply_Tag_Checks
;
308 ------------------------
309 -- Building_Static_DT --
310 ------------------------
312 function Building_Static_DT
(Typ
: Entity_Id
) return Boolean is
313 Root_Typ
: Entity_Id
:= Root_Type
(Typ
);
317 -- Handle private types
319 if Present
(Full_View
(Root_Typ
)) then
320 Root_Typ
:= Full_View
(Root_Typ
);
324 Building_Static_Dispatch_Tables
325 and then Is_Library_Level_Tagged_Type
(Typ
)
327 -- If the type is derived from a CPP class we cannot statically
328 -- build the dispatch tables because we must inherit primitives
329 -- from the CPP side.
331 and then not Is_CPP_Class
(Root_Typ
);
333 if not Static_DT
then
334 Check_Restriction
(Static_Dispatch_Tables
, Typ
);
338 end Building_Static_DT
;
340 ----------------------------------
341 -- Building_Static_Secondary_DT --
342 ----------------------------------
344 function Building_Static_Secondary_DT
(Typ
: Entity_Id
) return Boolean is
345 Full_Typ
: Entity_Id
:= Typ
;
346 Root_Typ
: Entity_Id
:= Root_Type
(Typ
);
350 -- Handle private types
352 if Present
(Full_View
(Typ
)) then
353 Full_Typ
:= Full_View
(Typ
);
356 if Present
(Full_View
(Root_Typ
)) then
357 Root_Typ
:= Full_View
(Root_Typ
);
361 Building_Static_DT
(Full_Typ
)
362 and then not Is_Interface
(Full_Typ
)
363 and then Has_Interfaces
(Full_Typ
)
364 and then (Full_Typ
= Root_Typ
365 or else not Is_Variable_Size_Record
(Etype
(Full_Typ
)));
368 and then not Is_Interface
(Full_Typ
)
369 and then Has_Interfaces
(Full_Typ
)
371 Check_Restriction
(Static_Dispatch_Tables
, Typ
);
375 end Building_Static_Secondary_DT
;
377 ----------------------------------
378 -- Build_Static_Dispatch_Tables --
379 ----------------------------------
381 procedure Build_Static_Dispatch_Tables
(N
: Node_Id
) is
382 Target_List
: List_Id
;
384 procedure Build_Dispatch_Tables
(List
: List_Id
);
385 -- Build the static dispatch table of tagged types found in the list of
386 -- declarations. The generated nodes are added at the end of Target_List
388 procedure Build_Package_Dispatch_Tables
(N
: Node_Id
);
389 -- Build static dispatch tables associated with package declaration N
391 procedure Make_And_Insert_Dispatch_Table
(Typ
: Entity_Id
);
392 -- Build the dispatch table of the tagged type Typ and insert it at the
393 -- end of Target_List after wrapping it in the Actions list of a freeze
394 -- node, so that it is skipped by Sem_Elab (Expand_Freeze_Record_Type
395 -- does the same for nonstatic dispatch tables).
397 ---------------------------
398 -- Build_Dispatch_Tables --
399 ---------------------------
401 procedure Build_Dispatch_Tables
(List
: List_Id
) is
406 while Present
(D
) loop
408 -- Handle nested packages and package bodies recursively. The
409 -- generated code is placed on the Target_List established for
410 -- the enclosing compilation unit.
412 if Nkind
(D
) = N_Package_Declaration
then
413 Build_Package_Dispatch_Tables
(D
);
415 elsif Nkind
(D
) = N_Package_Body
then
416 Build_Dispatch_Tables
(Declarations
(D
));
418 elsif Nkind
(D
) = N_Package_Body_Stub
419 and then Present
(Library_Unit
(D
))
421 Build_Dispatch_Tables
422 (Declarations
(Proper_Body
(Unit
(Library_Unit
(D
)))));
424 -- Handle full type declarations and derivations of library level
428 N_Full_Type_Declaration | N_Derived_Type_Definition
429 and then Is_Library_Level_Tagged_Type
(Defining_Entity
(D
))
430 and then Ekind
(Defining_Entity
(D
)) /= E_Record_Subtype
431 and then not Is_Private_Type
(Defining_Entity
(D
))
433 -- We do not generate dispatch tables for the internal types
434 -- created for a type extension with unknown discriminants
435 -- The needed information is shared with the source type,
436 -- See Expand_N_Record_Extension.
438 if Is_Underlying_Record_View
(Defining_Entity
(D
))
440 (not Comes_From_Source
(Defining_Entity
(D
))
442 Has_Unknown_Discriminants
(Etype
(Defining_Entity
(D
)))
444 not Comes_From_Source
445 (First_Subtype
(Defining_Entity
(D
))))
449 Make_And_Insert_Dispatch_Table
(Defining_Entity
(D
));
452 -- Handle private types of library level tagged types. We must
453 -- exchange the private and full-view to ensure the correct
454 -- expansion. If the full view is a synchronized type ignore
455 -- the type because the table will be built for the corresponding
456 -- record type, that has its own declaration.
458 elsif (Nkind
(D
) = N_Private_Type_Declaration
459 or else Nkind
(D
) = N_Private_Extension_Declaration
)
460 and then Present
(Full_View
(Defining_Entity
(D
)))
463 E1
: constant Entity_Id
:= Defining_Entity
(D
);
464 E2
: constant Entity_Id
:= Full_View
(E1
);
467 if Is_Library_Level_Tagged_Type
(E2
)
468 and then Ekind
(E2
) /= E_Record_Subtype
469 and then not Is_Concurrent_Type
(E2
)
471 Exchange_Declarations
(E1
);
472 Make_And_Insert_Dispatch_Table
(E1
);
473 Exchange_Declarations
(E2
);
480 end Build_Dispatch_Tables
;
482 -----------------------------------
483 -- Build_Package_Dispatch_Tables --
484 -----------------------------------
486 procedure Build_Package_Dispatch_Tables
(N
: Node_Id
) is
487 Spec
: constant Node_Id
:= Specification
(N
);
488 Id
: constant Entity_Id
:= Defining_Entity
(N
);
489 Vis_Decls
: constant List_Id
:= Visible_Declarations
(Spec
);
490 Priv_Decls
: constant List_Id
:= Private_Declarations
(Spec
);
495 if Present
(Priv_Decls
) then
496 Build_Dispatch_Tables
(Vis_Decls
);
497 Build_Dispatch_Tables
(Priv_Decls
);
499 elsif Present
(Vis_Decls
) then
500 Build_Dispatch_Tables
(Vis_Decls
);
504 end Build_Package_Dispatch_Tables
;
506 ------------------------------------
507 -- Make_And_Insert_Dispatch_Table --
508 ------------------------------------
510 procedure Make_And_Insert_Dispatch_Table
(Typ
: Entity_Id
) is
511 F_Typ
: constant Entity_Id
:= Create_Itype
(E_Class_Wide_Type
, Typ
);
512 -- The code generator discards freeze nodes of CW types after
513 -- evaluating their side effects, so create an artificial one.
515 F_Nod
: constant Node_Id
:= Make_Freeze_Entity
(Sloc
(Typ
));
518 Set_Is_Frozen
(F_Typ
);
519 Set_Entity
(F_Nod
, F_Typ
);
520 Set_Actions
(F_Nod
, Make_DT
(Typ
));
522 Insert_After_And_Analyze
(Last
(Target_List
), F_Nod
);
523 end Make_And_Insert_Dispatch_Table
;
525 -- Start of processing for Build_Static_Dispatch_Tables
528 if Nkind
(N
) = N_Package_Declaration
then
530 Spec
: constant Node_Id
:= Specification
(N
);
531 Vis_Decls
: constant List_Id
:= Visible_Declarations
(Spec
);
532 Priv_Decls
: constant List_Id
:= Private_Declarations
(Spec
);
535 if Present
(Priv_Decls
)
536 and then Is_Non_Empty_List
(Priv_Decls
)
538 Target_List
:= Priv_Decls
;
540 elsif No
(Vis_Decls
) then
541 Target_List
:= New_List
;
542 Set_Private_Declarations
(Spec
, Target_List
);
544 Target_List
:= Vis_Decls
;
547 Build_Package_Dispatch_Tables
(N
);
550 else pragma Assert
(Nkind
(N
) = N_Package_Body
);
552 Spec_Id
: constant Entity_Id
:= Corresponding_Spec
(N
);
555 Push_Scope
(Spec_Id
);
556 Target_List
:= Declarations
(N
);
557 Build_Dispatch_Tables
(Target_List
);
561 end Build_Static_Dispatch_Tables
;
563 ------------------------------
564 -- Convert_Tag_To_Interface --
565 ------------------------------
567 function Convert_Tag_To_Interface
569 Expr
: Node_Id
) return Node_Id
571 Loc
: constant Source_Ptr
:= Sloc
(Expr
);
572 Anon_Type
: Entity_Id
;
576 pragma Assert
(Is_Class_Wide_Type
(Typ
)
577 and then Is_Interface
(Typ
)
579 ((Nkind
(Expr
) = N_Selected_Component
580 and then Is_Tag
(Entity
(Selector_Name
(Expr
))))
582 (Nkind
(Expr
) = N_Function_Call
583 and then Is_RTE
(Entity
(Name
(Expr
)), RE_Displace
))));
585 Anon_Type
:= Create_Itype
(E_Anonymous_Access_Type
, Expr
);
586 Set_Directly_Designated_Type
(Anon_Type
, Typ
);
587 Set_Etype
(Anon_Type
, Anon_Type
);
588 Set_Can_Never_Be_Null
(Anon_Type
);
590 -- Decorate the size and alignment attributes of the anonymous access
591 -- type, as required by the back end.
593 Layout_Type
(Anon_Type
);
595 if Nkind
(Expr
) = N_Selected_Component
596 and then Is_Tag
(Entity
(Selector_Name
(Expr
)))
599 Make_Explicit_Dereference
(Loc
,
600 Unchecked_Convert_To
(Anon_Type
,
601 Make_Attribute_Reference
(Loc
,
603 Attribute_Name
=> Name_Address
)));
606 Make_Explicit_Dereference
(Loc
,
607 Unchecked_Convert_To
(Anon_Type
, Expr
));
611 end Convert_Tag_To_Interface
;
617 function CPP_Num_Prims
(Typ
: Entity_Id
) return Nat
is
619 Tag_Comp
: Entity_Id
;
622 if not Is_Tagged_Type
(Typ
)
623 or else not Is_CPP_Class
(Root_Type
(Typ
))
628 CPP_Typ
:= Enclosing_CPP_Parent
(Typ
);
629 Tag_Comp
:= First_Tag_Component
(CPP_Typ
);
631 -- If number of primitives already set in the tag component, use it
633 if Present
(Tag_Comp
)
634 and then Present
(DT_Entry_Count
(Tag_Comp
))
636 return UI_To_Int
(DT_Entry_Count
(Tag_Comp
));
638 -- Otherwise, count the primitives of the enclosing CPP type
641 return List_Length
(Primitive_Operations
(CPP_Typ
));
646 ------------------------------
647 -- Default_Prim_Op_Position --
648 ------------------------------
650 function Default_Prim_Op_Position
(E
: Entity_Id
) return Uint
is
651 TSS_Name
: TSS_Name_Type
;
654 Get_Name_String
(Chars
(E
));
657 (Name_Buffer
(Name_Len
- TSS_Name
'Length + 1 .. Name_Len
));
659 if Chars
(E
) = Name_uSize
then
662 elsif TSS_Name
= TSS_Stream_Read
then
665 elsif TSS_Name
= TSS_Stream_Write
then
668 elsif TSS_Name
= TSS_Stream_Input
then
671 elsif TSS_Name
= TSS_Stream_Output
then
674 elsif Chars
(E
) = Name_Op_Eq
then
677 elsif Chars
(E
) = Name_uAssign
then
680 elsif TSS_Name
= TSS_Deep_Adjust
then
683 elsif TSS_Name
= TSS_Deep_Finalize
then
686 elsif TSS_Name
= TSS_Put_Image
then
689 -- In VM targets unconditionally allow obtaining the position associated
690 -- with predefined interface primitives since in these platforms any
691 -- tagged type has these primitives.
693 elsif Ada_Version
>= Ada_2005
or else not Tagged_Type_Expansion
then
694 if Chars
(E
) = Name_uDisp_Asynchronous_Select
then
697 elsif Chars
(E
) = Name_uDisp_Conditional_Select
then
700 elsif Chars
(E
) = Name_uDisp_Get_Prim_Op_Kind
then
703 elsif Chars
(E
) = Name_uDisp_Get_Task_Id
then
706 elsif Chars
(E
) = Name_uDisp_Requeue
then
709 elsif Chars
(E
) = Name_uDisp_Timed_Select
then
715 end Default_Prim_Op_Position
;
717 ----------------------
718 -- Elab_Flag_Needed --
719 ----------------------
721 function Elab_Flag_Needed
(Typ
: Entity_Id
) return Boolean is
723 return Ada_Version
>= Ada_2005
724 and then not Is_Interface
(Typ
)
725 and then Has_Interfaces
(Typ
)
726 and then not Building_Static_DT
(Typ
);
727 end Elab_Flag_Needed
;
729 -----------------------------
730 -- Expand_Dispatching_Call --
731 -----------------------------
733 procedure Expand_Dispatching_Call
(Call_Node
: Node_Id
) is
734 Loc
: constant Source_Ptr
:= Sloc
(Call_Node
);
735 Call_Typ
: constant Entity_Id
:= Etype
(Call_Node
);
737 Ctrl_Arg
: constant Node_Id
:= Controlling_Argument
(Call_Node
);
738 Ctrl_Typ
: constant Entity_Id
:= Base_Type
(Etype
(Ctrl_Arg
));
739 Param_List
: constant List_Id
:= Parameter_Associations
(Call_Node
);
744 New_Call_Name
: Node_Id
;
745 New_Params
: List_Id
:= No_List
;
747 Subp_Ptr_Typ
: Entity_Id
;
748 Subp_Typ
: Entity_Id
;
750 Eq_Prim_Op
: Entity_Id
:= Empty
;
751 Controlling_Tag
: Node_Id
;
753 function New_Value
(From
: Node_Id
) return Node_Id
;
754 -- From is the original Expression. New_Value is equivalent to a call
755 -- to Duplicate_Subexpr with an explicit dereference when From is an
762 function New_Value
(From
: Node_Id
) return Node_Id
is
763 Res
: constant Node_Id
:= Duplicate_Subexpr
(From
);
765 if Is_Access_Type
(Etype
(From
)) then
767 Make_Explicit_Dereference
(Sloc
(From
),
777 SCIL_Node
: Node_Id
:= Empty
;
778 SCIL_Related_Node
: Node_Id
:= Call_Node
;
780 -- Start of processing for Expand_Dispatching_Call
783 if No_Run_Time_Mode
then
784 Error_Msg_CRT
("tagged types", Call_Node
);
788 -- Expand_Dispatching_Call is called directly from the semantics, so we
789 -- only proceed if the expander is active.
791 if not Expander_Active
793 -- And there is no need to expand the call if we are compiling under
794 -- restriction No_Dispatching_Calls; the semantic analyzer has
795 -- previously notified the violation of this restriction.
797 or else Restriction_Active
(No_Dispatching_Calls
)
799 -- No action needed if the dispatching call has been already expanded
801 or else Is_Expanded_Dispatching_Call
(Name
(Call_Node
))
806 -- Set subprogram. If this is an inherited operation that was
807 -- overridden, the body that is being called is its alias.
809 Subp
:= Entity
(Name
(Call_Node
));
811 if Present
(Alias
(Subp
))
812 and then Is_Inherited_Operation
(Subp
)
813 and then No
(DTC_Entity
(Subp
))
815 Subp
:= Alias
(Subp
);
818 -- Definition of the class-wide type and the tagged type
820 -- If the controlling argument is itself a tag rather than a tagged
821 -- object, then use the class-wide type associated with the subprogram's
822 -- controlling type. This case can occur when a call to an inherited
823 -- primitive has an actual that originated from a default parameter
824 -- given by a tag-indeterminate call and when there is no other
825 -- controlling argument providing the tag (AI-239 requires dispatching).
826 -- This capability of dispatching directly by tag is also needed by the
827 -- implementation of AI-260 (for the generic dispatching constructors).
829 if Is_RTE
(Ctrl_Typ
, RE_Tag
)
830 or else Is_RTE
(Ctrl_Typ
, RE_Interface_Tag
)
832 CW_Typ
:= Class_Wide_Type
(Find_Dispatching_Type
(Subp
));
834 -- Class_Wide_Type is applied to the expressions used to initialize
835 -- CW_Typ, to ensure that CW_Typ always denotes a class-wide type, since
836 -- there are cases where the controlling type is resolved to a specific
837 -- type (such as for designated types of arguments such as CW'Access).
839 elsif Is_Access_Type
(Ctrl_Typ
) then
840 CW_Typ
:= Class_Wide_Type
(Designated_Type
(Ctrl_Typ
));
843 CW_Typ
:= Class_Wide_Type
(Ctrl_Typ
);
846 Typ
:= Find_Specific_Type
(CW_Typ
);
848 -- The tagged type of a dispatching call must be frozen at this stage
850 pragma Assert
(Is_Frozen
(Typ
));
852 if not Is_Limited_Type
(Typ
) then
853 Eq_Prim_Op
:= Find_Prim_Op
(Typ
, Name_Op_Eq
);
856 -- Dispatching call to C++ primitive. Create a new parameter list
857 -- with no tag checks.
859 New_Params
:= New_List
;
861 if Is_CPP_Class
(Typ
) then
862 Param
:= First_Actual
(Call_Node
);
863 while Present
(Param
) loop
864 Append_To
(New_Params
, Relocate_Node
(Param
));
868 -- Dispatching call to Ada primitive
870 elsif Present
(Param_List
) then
871 Apply_Tag_Checks
(Call_Node
);
873 Param
:= First_Actual
(Call_Node
);
874 while Present
(Param
) loop
876 -- Cases in which we may have generated run-time checks. Note that
877 -- we strip any qualification from Param before comparing with the
878 -- already-stripped controlling argument.
880 if Unqualify
(Param
) = Ctrl_Arg
or else Subp
= Eq_Prim_Op
then
881 Append_To
(New_Params
,
882 Duplicate_Subexpr_Move_Checks
(Param
));
884 elsif Nkind
(Parent
(Param
)) /= N_Parameter_Association
885 or else not Is_Accessibility_Actual
(Parent
(Param
))
887 Append_To
(New_Params
, Relocate_Node
(Param
));
894 -- Generate the appropriate subprogram designated type
896 Subp_Typ
:= Create_Itype
(E_Subprogram_Type
, Call_Node
);
897 Copy_Strub_Mode
(Subp_Typ
, Subp
);
898 Set_Convention
(Subp_Typ
, Convention
(Subp
));
900 -- If this is a function and it has a controlling tagged result, then
901 -- the call is dispatching on result and returns the class-wide type.
903 if Ekind
(Subp
) = E_Function
904 and then Has_Controlling_Result
(Subp
)
905 and then Is_Tagged_Type
(Etype
(Subp
))
907 Set_Etype
(Subp_Typ
, Class_Wide_Type
(Etype
(Subp
)));
908 Set_Returns_By_Ref
(Subp_Typ
, True);
910 Set_Etype
(Subp_Typ
, Etype
(Subp
));
911 Set_Returns_By_Ref
(Subp_Typ
, Returns_By_Ref
(Subp
));
914 -- Notify gigi that the designated type is a dispatching primitive
916 Set_Is_Dispatch_Table_Entity
(Subp_Typ
);
918 -- Create a new list of parameters which is a copy of the old formal
919 -- list including the creation of a new set of matching entities.
922 Old_Formal
: Entity_Id
:= First_Formal
(Subp
);
923 New_Formal
: Entity_Id
;
924 Last_Formal
: Entity_Id
:= Empty
;
927 if Present
(Old_Formal
) then
928 New_Formal
:= New_Copy
(Old_Formal
);
929 Set_First_Entity
(Subp_Typ
, New_Formal
);
930 Param
:= First_Actual
(Call_Node
);
933 Set_Scope
(New_Formal
, Subp_Typ
);
935 -- Change all the controlling argument types to be class-wide
936 -- to avoid a recursion in dispatching.
938 if Is_Controlling_Formal
(New_Formal
) then
939 Set_Etype
(New_Formal
, Etype
(Param
));
942 -- If the type of the formal is an itype, there was code here
943 -- introduced in 1998 in revision 1.46, to create a new itype
944 -- by copy. This seems useless, and in fact leads to semantic
945 -- errors when the itype is the completion of a type derived
946 -- from a private type.
948 Last_Formal
:= New_Formal
;
949 Next_Formal
(Old_Formal
);
950 exit when No
(Old_Formal
);
952 Link_Entities
(New_Formal
, New_Copy
(Old_Formal
));
953 Next_Entity
(New_Formal
);
957 Unlink_Next_Entity
(New_Formal
);
958 Set_Last_Entity
(Subp_Typ
, Last_Formal
);
961 -- Now that the explicit formals have been duplicated, any extra
962 -- formals needed by the subprogram must be duplicated; we know
963 -- that extra formals are available because they were added when
964 -- the tagged type was frozen (see Expand_Freeze_Record_Type).
966 pragma Assert
(Is_Frozen
(Typ
));
968 -- Warning: The addition of the extra formals cannot be performed
969 -- here invoking Create_Extra_Formals since we must ensure that all
970 -- the extra formals of the pointer type and the target subprogram
971 -- match (and for functions that return a tagged type the profile of
972 -- the built subprogram type always returns a class-wide type, which
973 -- may affect the addition of some extra formals).
975 if Present
(Last_Formal
)
976 and then Present
(Extra_Formal
(Last_Formal
))
978 Old_Formal
:= Extra_Formal
(Last_Formal
);
979 New_Formal
:= New_Copy
(Old_Formal
);
980 Set_Scope
(New_Formal
, Subp_Typ
);
982 Set_Extra_Formal
(Last_Formal
, New_Formal
);
983 Set_Extra_Formals
(Subp_Typ
, New_Formal
);
985 if Ekind
(Subp
) = E_Function
986 and then Present
(Extra_Accessibility_Of_Result
(Subp
))
987 and then Extra_Accessibility_Of_Result
(Subp
) = Old_Formal
989 Set_Extra_Accessibility_Of_Result
(Subp_Typ
, New_Formal
);
992 Old_Formal
:= Extra_Formal
(Old_Formal
);
993 while Present
(Old_Formal
) loop
994 Set_Extra_Formal
(New_Formal
, New_Copy
(Old_Formal
));
995 New_Formal
:= Extra_Formal
(New_Formal
);
996 Set_Scope
(New_Formal
, Subp_Typ
);
998 if Ekind
(Subp
) = E_Function
999 and then Present
(Extra_Accessibility_Of_Result
(Subp
))
1000 and then Extra_Accessibility_Of_Result
(Subp
) = Old_Formal
1002 Set_Extra_Accessibility_Of_Result
(Subp_Typ
, New_Formal
);
1005 Old_Formal
:= Extra_Formal
(Old_Formal
);
1010 -- Generate the appropriate subprogram pointer type and decorate it
1012 Subp_Ptr_Typ
:= Create_Itype
(E_Access_Subprogram_Type
, Call_Node
);
1013 Set_Etype
(Subp_Ptr_Typ
, Subp_Ptr_Typ
);
1014 Set_Directly_Designated_Type
(Subp_Ptr_Typ
, Subp_Typ
);
1015 Set_Convention
(Subp_Ptr_Typ
, Convention
(Subp_Typ
));
1016 Layout_Type
(Subp_Ptr_Typ
);
1018 -- If the controlling argument is a value of type Ada.Tag or an abstract
1019 -- interface class-wide type then use it directly. Otherwise, the tag
1020 -- must be extracted from the controlling object.
1022 if Is_RTE
(Ctrl_Typ
, RE_Tag
)
1023 or else Is_RTE
(Ctrl_Typ
, RE_Interface_Tag
)
1025 Controlling_Tag
:= Duplicate_Subexpr
(Ctrl_Arg
);
1027 -- Extract the tag from an unchecked type conversion. Done to avoid
1028 -- the expansion of additional code just to obtain the value of such
1029 -- tag because the current management of interface type conversions
1030 -- generates in some cases this unchecked type conversion with the
1031 -- tag of the object (see Expand_Interface_Conversion).
1033 elsif Nkind
(Ctrl_Arg
) = N_Unchecked_Type_Conversion
1035 (Is_RTE
(Etype
(Expression
(Ctrl_Arg
)), RE_Tag
)
1037 Is_RTE
(Etype
(Expression
(Ctrl_Arg
)), RE_Interface_Tag
))
1039 Controlling_Tag
:= Duplicate_Subexpr
(Expression
(Ctrl_Arg
));
1041 -- Ada 2005 (AI-251): Abstract interface class-wide type
1043 elsif Is_Interface
(Ctrl_Typ
) and then Is_Class_Wide_Type
(Ctrl_Typ
) then
1045 Make_Attribute_Reference
(Loc
,
1046 Prefix
=> Duplicate_Subexpr
(Ctrl_Arg
),
1047 Attribute_Name
=> Name_Tag
);
1049 elsif Is_Access_Type
(Ctrl_Typ
) then
1051 Make_Selected_Component
(Loc
,
1053 Make_Explicit_Dereference
(Loc
,
1054 Duplicate_Subexpr_Move_Checks
(Ctrl_Arg
)),
1055 Selector_Name
=> New_Occurrence_Of
(DTC_Entity
(Subp
), Loc
));
1059 Make_Selected_Component
(Loc
,
1060 Prefix
=> Duplicate_Subexpr_Move_Checks
(Ctrl_Arg
),
1061 Selector_Name
=> New_Occurrence_Of
(DTC_Entity
(Subp
), Loc
));
1064 -- Handle dispatching calls to predefined primitives
1066 if Is_Predefined_Dispatching_Operation
(Subp
)
1067 or else Is_Predefined_Dispatching_Alias
(Subp
)
1069 Build_Get_Predefined_Prim_Op_Address
(Loc
,
1070 Tag_Node
=> Controlling_Tag
,
1071 Position
=> DT_Position
(Subp
),
1072 New_Node
=> New_Node
);
1074 -- Handle dispatching calls to user-defined primitives
1077 Build_Get_Prim_Op_Address
(Loc
,
1078 Typ
=> Underlying_Type
(Find_Dispatching_Type
(Subp
)),
1079 Tag_Node
=> Controlling_Tag
,
1080 Position
=> DT_Position
(Subp
),
1081 New_Node
=> New_Node
);
1085 Unchecked_Convert_To
(Subp_Ptr_Typ
, New_Node
);
1087 -- Generate the SCIL node for this dispatching call. Done now because
1088 -- attribute SCIL_Controlling_Tag must be set after the new call name
1089 -- is built to reference the nodes that will see the SCIL backend
1090 -- (because Build_Get_Prim_Op_Address generates an unchecked type
1091 -- conversion which relocates the controlling tag node).
1093 if Generate_SCIL
then
1094 SCIL_Node
:= Make_SCIL_Dispatching_Call
(Sloc
(Call_Node
));
1095 Set_SCIL_Entity
(SCIL_Node
, Typ
);
1096 Set_SCIL_Target_Prim
(SCIL_Node
, Subp
);
1098 -- Common case: the controlling tag is the tag of an object
1099 -- (for example, obj.tag)
1101 if Nkind
(Controlling_Tag
) = N_Selected_Component
then
1102 Set_SCIL_Controlling_Tag
(SCIL_Node
, Controlling_Tag
);
1104 -- Handle renaming of selected component
1106 elsif Nkind
(Controlling_Tag
) = N_Identifier
1107 and then Nkind
(Parent
(Entity
(Controlling_Tag
))) =
1108 N_Object_Renaming_Declaration
1109 and then Nkind
(Name
(Parent
(Entity
(Controlling_Tag
)))) =
1110 N_Selected_Component
1112 Set_SCIL_Controlling_Tag
(SCIL_Node
,
1113 Name
(Parent
(Entity
(Controlling_Tag
))));
1115 -- If the controlling tag is an identifier, the SCIL node references
1116 -- the corresponding object or parameter declaration
1118 elsif Nkind
(Controlling_Tag
) = N_Identifier
1119 and then Nkind
(Parent
(Entity
(Controlling_Tag
))) in
1120 N_Object_Declaration | N_Parameter_Specification
1122 Set_SCIL_Controlling_Tag
(SCIL_Node
,
1123 Parent
(Entity
(Controlling_Tag
)));
1125 -- If the controlling tag is a dereference, the SCIL node references
1126 -- the corresponding object or parameter declaration
1128 elsif Nkind
(Controlling_Tag
) = N_Explicit_Dereference
1129 and then Nkind
(Prefix
(Controlling_Tag
)) = N_Identifier
1130 and then Nkind
(Parent
(Entity
(Prefix
(Controlling_Tag
)))) in
1131 N_Object_Declaration | N_Parameter_Specification
1133 Set_SCIL_Controlling_Tag
(SCIL_Node
,
1134 Parent
(Entity
(Prefix
(Controlling_Tag
))));
1136 -- Depending on whether a dereference is involved, the SCIL node
1137 -- references the corresponding object/parameter declaration or
1138 -- the internal object declaration containing the tag of the type.
1140 elsif Nkind
(Controlling_Tag
) = N_Attribute_Reference
1141 and then Attribute_Name
(Controlling_Tag
) = Name_Tag
1144 Prefix_Node
: constant Node_Id
:= Prefix
(Controlling_Tag
);
1145 Ent
: constant Entity_Id
:= Entity
1146 (if Nkind
(Prefix_Node
) = N_Explicit_Dereference
then
1147 Prefix
(Prefix_Node
)
1152 if Ekind
(Ent
) in E_Record_Type
1154 | E_Record_Type_With_Private
1156 Set_SCIL_Controlling_Tag
(SCIL_Node
,
1160 (Access_Disp_Table
(Ent
)))));
1163 Set_SCIL_Controlling_Tag
(SCIL_Node
, Parent
(Ent
));
1167 -- Interfaces are not supported. For now we leave the SCIL node
1168 -- decorated with the Controlling_Tag. More work needed here???
1170 elsif Is_Interface
(Etype
(Controlling_Tag
)) then
1171 Set_SCIL_Controlling_Tag
(SCIL_Node
, Controlling_Tag
);
1174 pragma Assert
(False);
1179 if Nkind
(Call_Node
) = N_Function_Call
then
1181 Make_Function_Call
(Loc
,
1182 Name
=> New_Call_Name
,
1183 Parameter_Associations
=> New_Params
);
1185 -- If this is a dispatching "=", we must first compare the tags so
1186 -- we generate: x.tag = y.tag and then x = y
1188 if Subp
= Eq_Prim_Op
then
1189 Param
:= First_Actual
(Call_Node
);
1195 Make_Selected_Component
(Loc
,
1196 Prefix
=> New_Value
(Param
),
1198 New_Occurrence_Of
(First_Tag_Component
(Typ
),
1202 Make_Selected_Component
(Loc
,
1204 Unchecked_Convert_To
(Typ
,
1205 New_Value
(Next_Actual
(Param
))),
1208 (First_Tag_Component
(Typ
), Loc
))),
1209 Right_Opnd
=> New_Call
);
1211 SCIL_Related_Node
:= Right_Opnd
(New_Call
);
1216 Make_Procedure_Call_Statement
(Loc
,
1217 Name
=> New_Call_Name
,
1218 Parameter_Associations
=> New_Params
);
1221 -- Register the dispatching call in the call graph nodes table
1223 Register_CG_Node
(Call_Node
);
1225 Rewrite
(Call_Node
, New_Call
);
1227 -- Associate the SCIL node of this dispatching call
1229 if Generate_SCIL
then
1230 Set_SCIL_Node
(SCIL_Related_Node
, SCIL_Node
);
1233 -- Suppress all checks during the analysis of the expanded code to avoid
1234 -- the generation of spurious warnings under ZFP run-time.
1236 Analyze_And_Resolve
(Call_Node
, Call_Typ
, Suppress
=> All_Checks
);
1237 end Expand_Dispatching_Call
;
1239 ---------------------------------
1240 -- Expand_Interface_Conversion --
1241 ---------------------------------
1243 procedure Expand_Interface_Conversion
(N
: Node_Id
) is
1245 function Underlying_Record_Type
(Typ
: Entity_Id
) return Entity_Id
;
1246 -- Return the underlying record type of Typ
1248 ----------------------------
1249 -- Underlying_Record_Type --
1250 ----------------------------
1252 function Underlying_Record_Type
(Typ
: Entity_Id
) return Entity_Id
is
1253 E
: Entity_Id
:= Typ
;
1256 -- Handle access types
1258 if Is_Access_Type
(E
) then
1259 E
:= Directly_Designated_Type
(E
);
1262 -- Handle class-wide types. This conversion can appear explicitly in
1263 -- the source code. Example: I'Class (Obj)
1265 if Is_Class_Wide_Type
(E
) then
1269 -- If the target type is a tagged synchronized type, the dispatch
1270 -- table info is in the corresponding record type.
1272 if Is_Concurrent_Type
(E
) then
1273 E
:= Corresponding_Record_Type
(E
);
1276 -- Handle private types
1278 E
:= Underlying_Type
(E
);
1282 return Base_Type
(E
);
1283 end Underlying_Record_Type
;
1287 Loc
: constant Source_Ptr
:= Sloc
(N
);
1288 Etyp
: constant Entity_Id
:= Etype
(N
);
1289 Operand
: constant Node_Id
:= Expression
(N
);
1290 Operand_Typ
: Entity_Id
:= Etype
(Operand
);
1292 Iface_Typ
: constant Entity_Id
:= Underlying_Record_Type
(Etype
(N
));
1293 Iface_Tag
: Entity_Id
;
1294 Is_Static
: Boolean;
1296 -- Start of processing for Expand_Interface_Conversion
1299 -- Freeze the entity associated with the target interface to have
1300 -- available the attribute Access_Disp_Table.
1302 Freeze_Before
(N
, Iface_Typ
);
1304 -- Ada 2005 (AI-345): Handle synchronized interface type derivations
1306 if Is_Concurrent_Type
(Operand_Typ
) then
1307 Operand_Typ
:= Base_Type
(Corresponding_Record_Type
(Operand_Typ
));
1310 -- No displacement of the pointer to the object needed when the type of
1311 -- the operand is not an interface type and the interface is one of
1312 -- its parent types (since they share the primary dispatch table).
1315 Opnd
: Entity_Id
:= Operand_Typ
;
1318 if Is_Access_Type
(Opnd
) then
1319 Opnd
:= Designated_Type
(Opnd
);
1322 Opnd
:= Underlying_Record_Type
(Opnd
);
1324 if not Is_Interface
(Opnd
)
1325 and then Is_Ancestor
(Iface_Typ
, Opnd
, Use_Full_View
=> True)
1329 -- When the target type is an interface type that is an ancestor of
1330 -- the operand type, it is generally safe to skip generating code to
1331 -- displace the pointer to the object to reference the secondary
1332 -- dispatch table of the target interface type. Two scenarios are
1334 -- 1) The operand type is a regular tagged type
1335 -- 2) The operand type is an interface type
1336 -- In the former case the target interface and the regular tagged
1337 -- type share the primary dispatch table of the object; in the latter
1338 -- case the operand interface has all the primitives of the ancestor
1339 -- interface type (and exactly in the same dispatch table slots).
1341 -- The exception to this general rule is when the underlying object
1342 -- is built by means of a dispatching constructor (since in such case
1343 -- the expansion of the constructor call is a direct call to an
1344 -- object primitive, i.e. without thunks, and the expansion of
1345 -- the constructor call adds this explicit conversion to the target
1346 -- interface type to force the displacement of the pointer to the
1347 -- object to reference the corresponding secondary dispatch table
1348 -- (cf. Make_DT and Expand_Dispatching_Constructor_Call)).
1350 -- Under configurable runtime it is safe to skip generating code to
1351 -- displace the pointer to the object, because generic dispatching
1352 -- constructors are not supported.
1354 elsif Is_Interface
(Iface_Typ
)
1355 and then Is_Ancestor
(Iface_Typ
, Opnd
, Use_Full_View
=> True)
1356 and then not RTE_Available
(RE_Displace
)
1362 -- Evaluate if we can statically displace the pointer to the object
1365 Opnd_Typ
: constant Node_Id
:= Underlying_Record_Type
(Operand_Typ
);
1369 not Is_Interface
(Opnd_Typ
)
1370 and then Interface_Present_In_Ancestor
1373 and then (Etype
(Opnd_Typ
) = Opnd_Typ
1375 Is_Variable_Size_Record
(Etype
(Opnd_Typ
)));
1378 if not Tagged_Type_Expansion
then
1381 -- A static conversion to an interface type that is not class-wide is
1382 -- curious but legal if the interface operation is a null procedure.
1383 -- If the operation is abstract it will be rejected later.
1386 and then Is_Interface
(Etype
(N
))
1387 and then not Is_Class_Wide_Type
(Etype
(N
))
1388 and then Comes_From_Source
(N
)
1390 Rewrite
(N
, Unchecked_Convert_To
(Etype
(N
), N
));
1395 if not Is_Static
then
1397 -- Give error if configurable run-time and Displace not available
1399 if not RTE_Available
(RE_Displace
) then
1400 Error_Msg_CRT
("dynamic interface conversion", N
);
1404 -- Handle conversion of access-to-class-wide interface types. Target
1405 -- can be an access to an object or an access to another class-wide
1406 -- interface (see -1- and -2- in the following example):
1408 -- type Iface1_Ref is access all Iface1'Class;
1409 -- type Iface2_Ref is access all Iface1'Class;
1411 -- Acc1 : Iface1_Ref := new ...
1412 -- Obj : Obj_Ref := Obj_Ref (Acc); -- 1
1413 -- Acc2 : Iface2_Ref := Iface2_Ref (Acc); -- 2
1415 if Is_Access_Type
(Operand_Typ
) then
1417 Unchecked_Convert_To
(Etype
(N
),
1418 Make_Function_Call
(Loc
,
1419 Name
=> New_Occurrence_Of
(RTE
(RE_Displace
), Loc
),
1420 Parameter_Associations
=> New_List
(
1422 Unchecked_Convert_To
(RTE
(RE_Address
),
1423 Relocate_Node
(Expression
(N
))),
1426 (Node
(First_Elmt
(Access_Disp_Table
(Iface_Typ
))),
1434 Make_Function_Call
(Loc
,
1435 Name
=> New_Occurrence_Of
(RTE
(RE_Displace
), Loc
),
1436 Parameter_Associations
=> New_List
(
1437 Make_Attribute_Reference
(Loc
,
1438 Prefix
=> Relocate_Node
(Expression
(N
)),
1439 Attribute_Name
=> Name_Address
),
1442 (Node
(First_Elmt
(Access_Disp_Table
(Iface_Typ
))),
1447 -- If target is a class-wide interface, change the type of the data
1448 -- returned by IW_Convert to indicate this is a dispatching call.
1451 New_Itype
: Entity_Id
;
1454 New_Itype
:= Create_Itype
(E_Anonymous_Access_Type
, N
);
1455 Set_Etype
(New_Itype
, New_Itype
);
1456 Set_Directly_Designated_Type
(New_Itype
, Etyp
);
1459 Make_Explicit_Dereference
(Loc
,
1461 Unchecked_Convert_To
(New_Itype
, Relocate_Node
(N
))));
1463 Freeze_Itype
(New_Itype
, N
);
1469 Iface_Tag
:= Find_Interface_Tag
(Operand_Typ
, Iface_Typ
);
1470 pragma Assert
(Present
(Iface_Tag
));
1472 -- Keep separate access types to interfaces because one internal
1473 -- function is used to handle the null value (see following comments)
1475 if not Is_Access_Type
(Etype
(N
)) then
1477 -- Statically displace the pointer to the object to reference the
1478 -- component containing the secondary dispatch table.
1481 Convert_Tag_To_Interface
(Class_Wide_Type
(Iface_Typ
),
1482 Make_Selected_Component
(Loc
,
1483 Prefix
=> Relocate_Node
(Expression
(N
)),
1484 Selector_Name
=> New_Occurrence_Of
(Iface_Tag
, Loc
))));
1487 -- Build internal function to handle the case in which the actual is
1488 -- null. If the actual is null returns null because no displacement
1489 -- is required; otherwise performs a type conversion that will be
1490 -- expanded in the code that returns the value of the displaced
1493 -- function Func (O : Address) return Iface_Typ is
1494 -- type Op_Typ is access all Operand_Typ;
1495 -- Aux : Op_Typ := To_Op_Typ (O);
1497 -- if O = Null_Address then
1500 -- return Iface_Typ!(Aux.Iface_Tag'Address);
1505 Desig_Typ
: Entity_Id
;
1507 New_Typ_Decl
: Node_Id
;
1511 Desig_Typ
:= Etype
(Expression
(N
));
1513 if Is_Access_Type
(Desig_Typ
) then
1515 Available_View
(Directly_Designated_Type
(Desig_Typ
));
1518 if Is_Concurrent_Type
(Desig_Typ
) then
1519 Desig_Typ
:= Base_Type
(Corresponding_Record_Type
(Desig_Typ
));
1523 Make_Full_Type_Declaration
(Loc
,
1524 Defining_Identifier
=> Make_Temporary
(Loc
, 'T'),
1526 Make_Access_To_Object_Definition
(Loc
,
1527 All_Present
=> True,
1528 Null_Exclusion_Present
=> False,
1529 Constant_Present
=> False,
1530 Subtype_Indication
=>
1531 New_Occurrence_Of
(Desig_Typ
, Loc
)));
1534 Make_Simple_Return_Statement
(Loc
,
1535 Unchecked_Convert_To
(Etype
(N
),
1536 Make_Attribute_Reference
(Loc
,
1538 Make_Selected_Component
(Loc
,
1540 Unchecked_Convert_To
1541 (Defining_Identifier
(New_Typ_Decl
),
1542 Make_Identifier
(Loc
, Name_uO
)),
1544 New_Occurrence_Of
(Iface_Tag
, Loc
)),
1545 Attribute_Name
=> Name_Address
))));
1547 -- If the type is null-excluding, no need for the null branch.
1548 -- Otherwise we need to check for it and return null.
1550 if not Can_Never_Be_Null
(Etype
(N
)) then
1552 Make_If_Statement
(Loc
,
1555 Left_Opnd
=> Make_Identifier
(Loc
, Name_uO
),
1556 Right_Opnd
=> New_Occurrence_Of
1557 (RTE
(RE_Null_Address
), Loc
)),
1559 Then_Statements
=> New_List
(
1560 Make_Simple_Return_Statement
(Loc
, Make_Null
(Loc
))),
1561 Else_Statements
=> Stats
));
1564 Fent
:= Make_Temporary
(Loc
, 'F');
1566 Make_Subprogram_Body
(Loc
,
1568 Make_Function_Specification
(Loc
,
1569 Defining_Unit_Name
=> Fent
,
1571 Parameter_Specifications
=> New_List
(
1572 Make_Parameter_Specification
(Loc
,
1573 Defining_Identifier
=>
1574 Make_Defining_Identifier
(Loc
, Name_uO
),
1576 New_Occurrence_Of
(RTE
(RE_Address
), Loc
))),
1578 Result_Definition
=>
1579 New_Occurrence_Of
(Etype
(N
), Loc
)),
1581 Declarations
=> New_List
(New_Typ_Decl
),
1583 Handled_Statement_Sequence
=>
1584 Make_Handled_Sequence_Of_Statements
(Loc
, Stats
));
1586 -- Place function body before the expression containing the
1587 -- conversion. We suppress all checks because the body of the
1588 -- internally generated function already takes care of the case
1589 -- in which the actual is null; therefore there is no need to
1590 -- double check that the pointer is not null when the program
1591 -- executes the alternative that performs the type conversion).
1593 Insert_Action
(N
, Func
, Suppress
=> All_Checks
);
1595 if Is_Access_Type
(Etype
(Expression
(N
))) then
1597 -- Generate: Func (Address!(Expression))
1600 Make_Function_Call
(Loc
,
1601 Name
=> New_Occurrence_Of
(Fent
, Loc
),
1602 Parameter_Associations
=> New_List
(
1603 Unchecked_Convert_To
(RTE
(RE_Address
),
1604 Relocate_Node
(Expression
(N
))))));
1607 -- Generate: Func (Operand_Typ!(Expression)'Address)
1610 Make_Function_Call
(Loc
,
1611 Name
=> New_Occurrence_Of
(Fent
, Loc
),
1612 Parameter_Associations
=> New_List
(
1613 Make_Attribute_Reference
(Loc
,
1614 Prefix
=> Unchecked_Convert_To
(Operand_Typ
,
1615 Relocate_Node
(Expression
(N
))),
1616 Attribute_Name
=> Name_Address
))));
1622 end Expand_Interface_Conversion
;
1624 ------------------------------
1625 -- Expand_Interface_Actuals --
1626 ------------------------------
1628 procedure Expand_Interface_Actuals
(Call_Node
: Node_Id
) is
1630 Actual_Dup
: Node_Id
;
1631 Actual_Typ
: Entity_Id
;
1633 Conversion
: Node_Id
;
1635 Formal_Typ
: Entity_Id
;
1637 Formal_DDT
: Entity_Id
:= Empty
; -- initialize to prevent warning
1638 Actual_DDT
: Entity_Id
:= Empty
; -- initialize to prevent warning
1641 -- This subprogram is called directly from the semantics, so we need a
1642 -- check to see whether expansion is active before proceeding.
1644 if not Expander_Active
then
1648 -- Call using access to subprogram with explicit dereference
1650 if Nkind
(Name
(Call_Node
)) = N_Explicit_Dereference
then
1651 Subp
:= Etype
(Name
(Call_Node
));
1653 -- Call using selected component
1655 elsif Nkind
(Name
(Call_Node
)) = N_Selected_Component
then
1656 Subp
:= Entity
(Selector_Name
(Name
(Call_Node
)));
1658 -- Call using direct name
1661 Subp
:= Entity
(Name
(Call_Node
));
1664 -- Ada 2005 (AI-251): Look for interface type formals to force "this"
1667 Formal
:= First_Formal
(Subp
);
1668 Actual
:= First_Actual
(Call_Node
);
1669 while Present
(Formal
) loop
1670 Formal_Typ
:= Etype
(Formal
);
1672 if Has_Non_Limited_View
(Formal_Typ
) then
1673 Formal_Typ
:= Non_Limited_View
(Formal_Typ
);
1676 if Ekind
(Formal_Typ
) = E_Record_Type_With_Private
then
1677 Formal_Typ
:= Full_View
(Formal_Typ
);
1680 if Is_Access_Type
(Formal_Typ
) then
1681 Formal_DDT
:= Directly_Designated_Type
(Formal_Typ
);
1683 if Has_Non_Limited_View
(Formal_DDT
) then
1684 Formal_DDT
:= Non_Limited_View
(Formal_DDT
);
1688 Actual_Typ
:= Etype
(Actual
);
1690 if Has_Non_Limited_View
(Actual_Typ
) then
1691 Actual_Typ
:= Non_Limited_View
(Actual_Typ
);
1694 if Is_Access_Type
(Actual_Typ
) then
1695 Actual_DDT
:= Directly_Designated_Type
(Actual_Typ
);
1697 if Has_Non_Limited_View
(Actual_DDT
) then
1698 Actual_DDT
:= Non_Limited_View
(Actual_DDT
);
1702 if Is_Interface
(Formal_Typ
)
1703 and then Is_Class_Wide_Type
(Formal_Typ
)
1705 -- No need to displace the pointer if the type of the actual
1706 -- coincides with the type of the formal.
1708 if Actual_Typ
= Formal_Typ
then
1711 -- No need to displace the pointer if the interface type is a
1712 -- parent of the type of the actual because in this case the
1713 -- interface primitives are located in the primary dispatch table.
1715 elsif Is_Ancestor
(Formal_Typ
, Actual_Typ
,
1716 Use_Full_View
=> True)
1720 -- Implicit conversion to the class-wide formal type to force the
1721 -- displacement of the pointer.
1724 -- Normally, expansion of actuals for calls to build-in-place
1725 -- functions happens as part of Expand_Actuals, but in this
1726 -- case the call will be wrapped in a conversion and soon after
1727 -- expanded further to handle the displacement for a class-wide
1728 -- interface conversion, so if this is a BIP call then we need
1729 -- to handle it now.
1731 if Is_Build_In_Place_Function_Call
(Actual
) then
1732 Make_Build_In_Place_Call_In_Anonymous_Context
(Actual
);
1735 Conversion
:= Convert_To
(Formal_Typ
, Relocate_Node
(Actual
));
1736 Rewrite
(Actual
, Conversion
);
1737 Analyze_And_Resolve
(Actual
, Formal_Typ
);
1740 -- Access to class-wide interface type
1742 elsif Is_Access_Type
(Formal_Typ
)
1743 and then Is_Interface
(Formal_DDT
)
1744 and then Is_Class_Wide_Type
(Formal_DDT
)
1745 and then Interface_Present_In_Ancestor
1747 Iface
=> Etype
(Formal_DDT
))
1749 -- Handle attributes 'Access and 'Unchecked_Access
1751 if Nkind
(Actual
) = N_Attribute_Reference
1753 (Attribute_Name
(Actual
) = Name_Access
1754 or else Attribute_Name
(Actual
) = Name_Unchecked_Access
)
1756 -- This case must have been handled by the analysis and
1757 -- expansion of 'Access. The only exception is when types
1758 -- match and no further expansion is required.
1760 pragma Assert
(Base_Type
(Etype
(Prefix
(Actual
)))
1761 = Base_Type
(Formal_DDT
));
1764 -- No need to displace the pointer if the type of the actual
1765 -- coincides with the type of the formal.
1767 elsif Actual_DDT
= Formal_DDT
then
1770 -- No need to displace the pointer if the interface type is
1771 -- a parent of the type of the actual because in this case the
1772 -- interface primitives are located in the primary dispatch table.
1774 elsif Is_Ancestor
(Formal_DDT
, Actual_DDT
,
1775 Use_Full_View
=> True)
1780 Actual_Dup
:= Relocate_Node
(Actual
);
1782 if From_Limited_With
(Actual_Typ
) then
1784 -- If the type of the actual parameter comes from a limited
1785 -- with_clause and the nonlimited view is already available,
1786 -- we replace the anonymous access type by a duplicate
1787 -- declaration whose designated type is the nonlimited view.
1789 if Has_Non_Limited_View
(Actual_DDT
) then
1790 Anon
:= New_Copy
(Actual_Typ
);
1792 if Is_Itype
(Anon
) then
1793 Set_Scope
(Anon
, Current_Scope
);
1796 Set_Directly_Designated_Type
1797 (Anon
, Non_Limited_View
(Actual_DDT
));
1798 Set_Etype
(Actual_Dup
, Anon
);
1802 Conversion
:= Convert_To
(Formal_Typ
, Actual_Dup
);
1803 Rewrite
(Actual
, Conversion
);
1804 Analyze_And_Resolve
(Actual
, Formal_Typ
);
1808 Next_Actual
(Actual
);
1809 Next_Formal
(Formal
);
1811 end Expand_Interface_Actuals
;
1813 ----------------------------
1814 -- Expand_Interface_Thunk --
1815 ----------------------------
1817 procedure Expand_Interface_Thunk
1819 Thunk_Id
: out Entity_Id
;
1820 Thunk_Code
: out List_Id
;
1823 Actuals
: constant List_Id
:= New_List
;
1824 Decl
: constant List_Id
:= New_List
;
1825 Formals
: constant List_Id
:= New_List
;
1826 Loc
: constant Source_Ptr
:= Sloc
(Prim
);
1827 Target
: constant Entity_Id
:= Ultimate_Alias
(Prim
);
1828 Is_Predef_Op
: constant Boolean :=
1829 Is_Predefined_Dispatching_Operation
(Prim
)
1830 or else Is_Predefined_Dispatching_Operation
(Target
);
1837 Iface_Formal
: Entity_Id
;
1839 Offset_To_Top
: Node_Id
;
1840 Target_Formal
: Entity_Id
;
1844 Thunk_Code
:= Empty_List
;
1846 -- No thunk needed if the primitive has been eliminated
1848 if Is_Eliminated
(Target
) then
1851 -- No thunk needed if the primitive has no formals. In this case, this
1852 -- must be a function with a controlling result.
1854 elsif No
(First_Formal
(Target
)) then
1855 pragma Assert
(Ekind
(Target
) = E_Function
1856 and then Has_Controlling_Result
(Target
));
1861 -- Duplicate the formals of the target primitive. In the thunk, the type
1862 -- of the controlling formal is the covered interface type (instead of
1863 -- the target tagged type). Done to avoid problems with discriminated
1864 -- tagged types because, if the controlling type has discriminants with
1865 -- default values, then the type conversions done inside the body of
1866 -- the thunk (after the displacement of the pointer to the base of the
1867 -- actual object) generate code that modify its contents.
1869 -- Note: This special management is not done for predefined primitives
1870 -- because they don't have available the Interface_Alias attribute (see
1871 -- Sem_Ch3.Add_Internal_Interface_Entities).
1873 if Is_Predef_Op
then
1874 Iface_Formal
:= Empty
;
1876 Iface_Formal
:= First_Formal
(Interface_Alias
(Prim
));
1879 Formal
:= First_Formal
(Target
);
1880 while Present
(Formal
) loop
1881 -- Use the interface type as the type of the controlling formal (see
1884 if not Is_Controlling_Formal
(Formal
) then
1885 Ftyp
:= Etype
(Formal
);
1886 Expr
:= New_Copy_Tree
(Expression
(Parent
(Formal
)));
1888 -- For predefined primitives the controlling type of the thunk is
1889 -- the interface type passed by the caller (since they don't have
1890 -- available the Interface_Alias attribute; see comment above).
1892 elsif Is_Predef_Op
then
1897 Ftyp
:= Etype
(Iface_Formal
);
1900 -- Sanity check performed to ensure the proper controlling type
1901 -- when the thunk has exactly one controlling parameter and it
1902 -- comes first. In such a case, the GCC back end reuses the C++
1903 -- thunks machinery which perform a computation equivalent to
1904 -- the code generated by the expander; for other cases the GCC
1905 -- back end translates the expanded code unmodified. However, as
1906 -- a generalization, the check is performed for all controlling
1909 if Is_Access_Type
(Ftyp
) then
1910 pragma Assert
(Base_Type
(Designated_Type
(Ftyp
)) = Iface
);
1913 Ftyp
:= Base_Type
(Ftyp
);
1914 pragma Assert
(Ftyp
= Iface
);
1919 Make_Parameter_Specification
(Loc
,
1920 Defining_Identifier
=>
1921 Make_Defining_Identifier
(Sloc
(Formal
),
1922 Chars
=> Chars
(Formal
)),
1923 Aliased_Present
=> Aliased_Present
(Parent
(Formal
)),
1924 In_Present
=> In_Present
(Parent
(Formal
)),
1925 Out_Present
=> Out_Present
(Parent
(Formal
)),
1926 Parameter_Type
=> New_Occurrence_Of
(Ftyp
, Loc
),
1927 Expression
=> Expr
));
1929 if not Is_Predef_Op
then
1930 Next_Formal
(Iface_Formal
);
1933 Next_Formal
(Formal
);
1936 Target_Formal
:= First_Formal
(Target
);
1937 Formal
:= First
(Formals
);
1938 while Present
(Formal
) loop
1940 -- If the parent is a constrained discriminated type, then the
1941 -- primitive operation will have been defined on a first subtype.
1942 -- For proper matching with controlling type, use base type.
1944 if Ekind
(Target_Formal
) = E_In_Parameter
1945 and then Ekind
(Etype
(Target_Formal
)) = E_Anonymous_Access_Type
1948 Base_Type
(Directly_Designated_Type
(Etype
(Target_Formal
)));
1950 Ftyp
:= Base_Type
(Etype
(Target_Formal
));
1953 -- For concurrent types, the relevant information is found in the
1954 -- Corresponding_Record_Type, rather than the type entity itself.
1956 if Is_Concurrent_Type
(Ftyp
) then
1957 Ftyp
:= Corresponding_Record_Type
(Ftyp
);
1960 if Ekind
(Target_Formal
) = E_In_Parameter
1961 and then Ekind
(Etype
(Target_Formal
)) = E_Anonymous_Access_Type
1962 and then Is_Controlling_Formal
(Target_Formal
)
1965 -- type T is access all <<type of the target formal>>
1966 -- S : constant Address := Address!(Formal)
1967 -- + Offset_To_Top (Address!(Formal))
1970 Make_Full_Type_Declaration
(Loc
,
1971 Defining_Identifier
=> Make_Temporary
(Loc
, 'T'),
1973 Make_Access_To_Object_Definition
(Loc
,
1974 All_Present
=> True,
1975 Null_Exclusion_Present
=> False,
1976 Constant_Present
=> False,
1977 Subtype_Indication
=>
1978 New_Occurrence_Of
(Ftyp
, Loc
)));
1981 Unchecked_Convert_To
(RTE
(RE_Address
),
1982 New_Occurrence_Of
(Defining_Identifier
(Formal
), Loc
));
1984 if not RTE_Available
(RE_Offset_To_Top
) then
1986 Build_Offset_To_Top
(Loc
, New_Arg
);
1989 Make_Function_Call
(Loc
,
1990 Name
=> New_Occurrence_Of
(RTE
(RE_Offset_To_Top
), Loc
),
1991 Parameter_Associations
=> New_List
(New_Arg
));
1995 Make_Object_Declaration
(Loc
,
1996 Defining_Identifier
=> Make_Temporary
(Loc
, 'S'),
1997 Constant_Present
=> True,
1998 Object_Definition
=>
1999 New_Occurrence_Of
(RTE
(RE_Address
), Loc
),
2001 Make_Function_Call
(Loc
,
2003 Make_Expanded_Name
(Loc
,
2004 Chars
=> Name_Op_Add
,
2007 (RTU_Entity
(System_Storage_Elements
), Loc
),
2009 Make_Identifier
(Loc
, Name_Op_Add
)),
2010 Parameter_Associations
=> New_List
(
2011 New_Copy_Tree
(New_Arg
),
2014 Append_To
(Decl
, Decl_2
);
2015 Append_To
(Decl
, Decl_1
);
2017 -- Reference the new actual. Generate:
2021 Unchecked_Convert_To
2022 (Defining_Identifier
(Decl_2
),
2023 New_Occurrence_Of
(Defining_Identifier
(Decl_1
), Loc
)));
2025 elsif Is_Controlling_Formal
(Target_Formal
) then
2028 -- S1 : constant Address := Formal'Address
2029 -- + Offset_To_Top (Formal'Address)
2030 -- S2 : constant Addr_Ptr := Addr_Ptr!(S1)
2033 Make_Attribute_Reference
(Loc
,
2035 New_Occurrence_Of
(Defining_Identifier
(Formal
), Loc
),
2036 Attribute_Name
=> Name_Address
);
2038 if not RTE_Available
(RE_Offset_To_Top
) then
2040 Build_Offset_To_Top
(Loc
, New_Arg
);
2043 Make_Function_Call
(Loc
,
2044 Name
=> New_Occurrence_Of
(RTE
(RE_Offset_To_Top
), Loc
),
2045 Parameter_Associations
=> New_List
(New_Arg
));
2049 Make_Object_Declaration
(Loc
,
2050 Defining_Identifier
=> Make_Temporary
(Loc
, 'S'),
2051 Constant_Present
=> True,
2052 Object_Definition
=>
2053 New_Occurrence_Of
(RTE
(RE_Address
), Loc
),
2055 Make_Function_Call
(Loc
,
2057 Make_Expanded_Name
(Loc
,
2058 Chars
=> Name_Op_Add
,
2061 (RTU_Entity
(System_Storage_Elements
), Loc
),
2063 Make_Identifier
(Loc
, Name_Op_Add
)),
2064 Parameter_Associations
=> New_List
(
2065 New_Copy_Tree
(New_Arg
),
2069 Make_Object_Declaration
(Loc
,
2070 Defining_Identifier
=> Make_Temporary
(Loc
, 'S'),
2071 Constant_Present
=> True,
2072 Object_Definition
=>
2073 New_Occurrence_Of
(RTE
(RE_Addr_Ptr
), Loc
),
2075 Unchecked_Convert_To
2077 New_Occurrence_Of
(Defining_Identifier
(Decl_1
), Loc
)));
2079 Append_To
(Decl
, Decl_1
);
2080 Append_To
(Decl
, Decl_2
);
2082 -- Reference the new actual, generate:
2083 -- Target_Formal (S2.all)
2086 Unchecked_Convert_To
(Ftyp
,
2087 Make_Explicit_Dereference
(Loc
,
2088 New_Occurrence_Of
(Defining_Identifier
(Decl_2
), Loc
))));
2090 -- Ensure proper matching of access types. Required to avoid
2091 -- reporting spurious errors.
2093 elsif Is_Access_Type
(Etype
(Target_Formal
)) then
2095 Unchecked_Convert_To
(Base_Type
(Etype
(Target_Formal
)),
2096 New_Occurrence_Of
(Defining_Identifier
(Formal
), Loc
)));
2098 -- No special management required for this actual
2102 New_Occurrence_Of
(Defining_Identifier
(Formal
), Loc
));
2105 Next_Formal
(Target_Formal
);
2109 Thunk_Id
:= Make_Temporary
(Loc
, 'T');
2111 -- Note: any change to this symbol name needs to be coordinated
2112 -- with GNATcoverage, as that tool relies on it to identify
2113 -- thunks and exclude them from source coverage analysis.
2115 Mutate_Ekind
(Thunk_Id
, Ekind
(Prim
));
2116 Set_Is_Thunk
(Thunk_Id
);
2117 Set_Has_Controlling_Result
(Thunk_Id
, False);
2118 Set_Convention
(Thunk_Id
, Convention
(Prim
));
2119 Set_Needs_Debug_Info
(Thunk_Id
, Needs_Debug_Info
(Target
));
2120 Set_Thunk_Entity
(Thunk_Id
, Target
);
2122 Thunk_Code
:= New_List
;
2126 if Ekind
(Target
) = E_Procedure
then
2127 Append_To
(Thunk_Code
,
2128 Make_Subprogram_Body
(Loc
,
2130 Make_Procedure_Specification
(Loc
,
2131 Defining_Unit_Name
=> Thunk_Id
,
2132 Parameter_Specifications
=> Formals
),
2133 Declarations
=> Decl
,
2134 Handled_Statement_Sequence
=>
2135 Make_Handled_Sequence_Of_Statements
(Loc
,
2136 Statements
=> New_List
(
2137 Make_Procedure_Call_Statement
(Loc
,
2138 Name
=> New_Occurrence_Of
(Target
, Loc
),
2139 Parameter_Associations
=> Actuals
)))));
2143 else pragma Assert
(Ekind
(Target
) = E_Function
);
2145 Call_Node
: Node_Id
;
2146 Result_Def
: Node_Id
;
2147 SS_Thunk_Id
: Entity_Id
;
2148 SS_Thunk_Code
: Node_Id
;
2152 Make_Function_Call
(Loc
,
2153 Name
=> New_Occurrence_Of
(Target
, Loc
),
2154 Parameter_Associations
=> Actuals
);
2156 if not Is_Interface
(Etype
(Prim
)) then
2157 Result_Def
:= New_Copy
(Result_Definition
(Parent
(Target
)));
2159 -- Thunk of function returning a class-wide interface object. No
2160 -- extra displacement needed since the displacement is generated
2161 -- in the return statement of Prim. Example:
2163 -- type Iface is interface ...
2164 -- function F (O : Iface) return Iface'Class;
2166 -- type T is new ... and Iface with ...
2167 -- function F (O : T) return Iface'Class;
2169 elsif Is_Class_Wide_Type
(Etype
(Prim
)) then
2170 Result_Def
:= New_Occurrence_Of
(Etype
(Prim
), Loc
);
2172 -- Thunk of function returning an interface object. Displacement
2175 -- type Iface is interface ...
2176 -- function F (O : Iface) return Iface;
2178 -- type T is new ... and Iface with ...
2179 -- function F (O : T) return T;
2182 Expand_Secondary_Stack_Thunk
2183 (Target
, SS_Thunk_Id
, SS_Thunk_Code
);
2185 if Present
(SS_Thunk_Id
) then
2186 Set_Thunk_Entity
(Thunk_Id
, SS_Thunk_Id
);
2188 Make_Function_Call
(Loc
,
2190 New_Occurrence_Of
(SS_Thunk_Id
, Loc
),
2191 Parameter_Associations
=> Actuals
);
2192 Append_To
(Thunk_Code
, SS_Thunk_Code
);
2196 New_Occurrence_Of
(Class_Wide_Type
(Etype
(Prim
)), Loc
);
2198 -- Adding implicit conversion to force the displacement of
2199 -- the pointer to the object to reference the corresponding
2200 -- secondary dispatch table.
2203 Make_Type_Conversion
(Loc
,
2205 New_Occurrence_Of
(Class_Wide_Type
(Etype
(Prim
)), Loc
),
2206 Expression
=> Relocate_Node
(Call_Node
));
2209 Append_To
(Thunk_Code
,
2210 Make_Subprogram_Body
(Loc
,
2212 Make_Function_Specification
(Loc
,
2213 Defining_Unit_Name
=> Thunk_Id
,
2214 Parameter_Specifications
=> Formals
,
2215 Result_Definition
=> Result_Def
),
2216 Declarations
=> Decl
,
2217 Handled_Statement_Sequence
=>
2218 Make_Handled_Sequence_Of_Statements
(Loc
,
2219 Statements
=> New_List
(
2220 Make_Simple_Return_Statement
(Loc
, Call_Node
)))));
2223 end Expand_Interface_Thunk
;
2225 ------------------------------------
2226 -- Expand_Secondary_Stack_Thunk --
2227 ------------------------------------
2229 procedure Expand_Secondary_Stack_Thunk
2231 Thunk_Id
: out Entity_Id
;
2232 Thunk_Code
: out Node_Id
)
2234 Actuals
: constant List_Id
:= New_List
;
2235 Formals
: constant List_Id
:= New_List
;
2236 Loc
: constant Source_Ptr
:= Sloc
(Prim
);
2237 Typ
: constant Entity_Id
:= Etype
(Prim
);
2239 Call_Node
: Node_Id
;
2242 Prim_Formal
: Entity_Id
;
2243 Result_Def
: Node_Id
;
2247 Thunk_Code
:= Empty
;
2249 -- No thunk needed if the primitive has been eliminated
2251 if Is_Eliminated
(Prim
) then
2254 -- No thunk needed for procedures or functions not dispatching on result
2256 elsif Ekind
(Prim
) = E_Procedure
2257 or else not Has_Controlling_Result
(Prim
)
2261 -- No thunk needed if the result type is an access type
2263 elsif Is_Access_Type
(Typ
) then
2266 -- No thunk needed if the tagged type is returned in place
2268 elsif Is_Build_In_Place_Result_Type
(Typ
) then
2271 -- No thunk needed if the tagged type is returned on the secondary stack
2273 elsif Needs_Secondary_Stack
(Typ
) then
2277 pragma Assert
(Is_Tagged_Type
(Typ
));
2279 -- Duplicate the formals of the target primitive and build the actuals
2281 Prim_Formal
:= First_Formal
(Prim
);
2282 while Present
(Prim_Formal
) loop
2283 Expr
:= New_Copy_Tree
(Expression
(Parent
(Prim_Formal
)));
2286 Make_Defining_Identifier
(Sloc
(Prim_Formal
),
2287 Chars
=> Chars
(Prim_Formal
));
2290 Make_Parameter_Specification
(Loc
,
2291 Defining_Identifier
=> Formal
,
2292 Aliased_Present
=> Aliased_Present
(Parent
(Prim_Formal
)),
2293 In_Present
=> In_Present
(Parent
(Prim_Formal
)),
2294 Out_Present
=> Out_Present
(Parent
(Prim_Formal
)),
2295 Parameter_Type
=> New_Occurrence_Of
(Etype
(Prim_Formal
), Loc
),
2296 Expression
=> Expr
));
2298 -- Ensure proper matching of access types. Required to avoid
2299 -- reporting spurious errors.
2301 if Is_Access_Type
(Etype
(Prim_Formal
)) then
2303 Unchecked_Convert_To
(Base_Type
(Etype
(Prim_Formal
)),
2304 New_Occurrence_Of
(Formal
, Loc
)));
2306 -- No special management required for this actual
2309 Append_To
(Actuals
, New_Occurrence_Of
(Formal
, Loc
));
2312 Next_Formal
(Prim_Formal
);
2315 Thunk_Id
:= Make_Temporary
(Loc
, 'T');
2317 -- Note: any change to this symbol name needs to be coordinated
2318 -- with GNATcoverage, as that tool relies on it to identify
2319 -- thunks and exclude them from source coverage analysis.
2321 Mutate_Ekind
(Thunk_Id
, E_Function
);
2322 Set_Is_Thunk
(Thunk_Id
);
2323 Set_Has_Controlling_Result
(Thunk_Id
, True);
2324 Set_Convention
(Thunk_Id
, Convention
(Prim
));
2325 Set_Needs_Debug_Info
(Thunk_Id
, Needs_Debug_Info
(Prim
));
2326 Set_Thunk_Entity
(Thunk_Id
, Prim
);
2328 Result_Def
:= New_Copy
(Result_Definition
(Parent
(Prim
)));
2331 Make_Function_Call
(Loc
,
2332 Name
=> New_Occurrence_Of
(Prim
, Loc
),
2333 Parameter_Associations
=> Actuals
);
2336 Make_Subprogram_Body
(Loc
,
2338 Make_Function_Specification
(Loc
,
2339 Defining_Unit_Name
=> Thunk_Id
,
2340 Parameter_Specifications
=> Formals
,
2341 Result_Definition
=> Result_Def
),
2342 Declarations
=> Empty_List
,
2343 Handled_Statement_Sequence
=>
2344 Make_Handled_Sequence_Of_Statements
(Loc
,
2345 Statements
=> New_List
(
2346 Make_Simple_Return_Statement
(Loc
, Call_Node
))));
2347 end Expand_Secondary_Stack_Thunk
;
2349 --------------------------
2350 -- Has_CPP_Constructors --
2351 --------------------------
2353 function Has_CPP_Constructors
(Typ
: Entity_Id
) return Boolean is
2357 -- Look for the constructor entities
2359 E
:= Next_Entity
(Typ
);
2360 while Present
(E
) loop
2361 if Ekind
(E
) = E_Function
and then Is_Constructor
(E
) then
2369 end Has_CPP_Constructors
;
2375 function Has_DT
(Typ
: Entity_Id
) return Boolean is
2377 return not Is_Interface
(Typ
)
2378 and then not Restriction_Active
(No_Dispatching_Calls
);
2381 ----------------------------------
2382 -- Is_Expanded_Dispatching_Call --
2383 ----------------------------------
2385 function Is_Expanded_Dispatching_Call
(N
: Node_Id
) return Boolean is
2387 return Nkind
(N
) in N_Subprogram_Call
2388 and then Nkind
(Name
(N
)) = N_Explicit_Dereference
2389 and then Is_Dispatch_Table_Entity
(Etype
(Name
(N
)));
2390 end Is_Expanded_Dispatching_Call
;
2392 -------------------------------------
2393 -- Is_Predefined_Dispatching_Alias --
2394 -------------------------------------
2396 function Is_Predefined_Dispatching_Alias
(Prim
: Entity_Id
) return Boolean
2399 return not Is_Predefined_Dispatching_Operation
(Prim
)
2400 and then Present
(Alias
(Prim
))
2401 and then Is_Predefined_Dispatching_Operation
(Ultimate_Alias
(Prim
));
2402 end Is_Predefined_Dispatching_Alias
;
2404 ----------------------------------------
2405 -- Make_Disp_Asynchronous_Select_Body --
2406 ----------------------------------------
2408 -- For interface types, generate:
2410 -- procedure _Disp_Asynchronous_Select
2411 -- (T : in out <Typ>;
2413 -- P : System.Address;
2414 -- B : out System.Storage_Elements.Dummy_Communication_Block;
2419 -- C := Ada.Tags.POK_Function;
2420 -- end _Disp_Asynchronous_Select;
2422 -- For protected types, generate:
2424 -- procedure _Disp_Asynchronous_Select
2425 -- (T : in out <Typ>;
2427 -- P : System.Address;
2428 -- B : out System.Storage_Elements.Dummy_Communication_Block;
2432 -- Ada.Tags.Get_Entry_Index (Ada.Tags.Tag (<Typ>VP, S));
2433 -- Bnn : System.Tasking.Protected_Objects.Operations.
2434 -- Communication_Block;
2436 -- System.Tasking.Protected_Objects.Operations.Protected_Entry_Call
2437 -- (T._object'Access,
2438 -- System.Tasking.Protected_Objects.Protected_Entry_Index (I),
2440 -- System.Tasking.Asynchronous_Call,
2442 -- B := System.Storage_Elements.Dummy_Communication_Block (Bnn);
2443 -- end _Disp_Asynchronous_Select;
2445 -- For task types, generate:
2447 -- procedure _Disp_Asynchronous_Select
2448 -- (T : in out <Typ>;
2450 -- P : System.Address;
2451 -- B : out System.Storage_Elements.Dummy_Communication_Block;
2455 -- Ada.Tags.Get_Entry_Index (Ada.Tags.Tag (<Typ>VP, S));
2457 -- System.Tasking.Rendezvous.Task_Entry_Call
2459 -- System.Tasking.Task_Entry_Index (I),
2461 -- System.Tasking.Asynchronous_Call,
2463 -- end _Disp_Asynchronous_Select;
2465 function Make_Disp_Asynchronous_Select_Body
2466 (Typ
: Entity_Id
) return Node_Id
2468 Com_Block
: Entity_Id
;
2469 Conc_Typ
: Entity_Id
:= Empty
;
2470 Decls
: constant List_Id
:= New_List
;
2471 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
2473 Stmts
: constant List_Id
:= New_List
;
2477 pragma Assert
(not Restriction_Active
(No_Dispatching_Calls
));
2479 -- Null body is generated for interface types
2481 if Is_Interface
(Typ
) then
2483 Make_Subprogram_Body
(Loc
,
2485 Make_Disp_Asynchronous_Select_Spec
(Typ
),
2486 Declarations
=> New_List
,
2487 Handled_Statement_Sequence
=>
2488 Make_Handled_Sequence_Of_Statements
(Loc
,
2490 Make_Assignment_Statement
(Loc
,
2491 Name
=> Make_Identifier
(Loc
, Name_uF
),
2492 Expression
=> New_Occurrence_Of
(Standard_False
, Loc
)))));
2495 if Is_Concurrent_Record_Type
(Typ
) then
2496 Conc_Typ
:= Corresponding_Concurrent_Type
(Typ
);
2500 -- Ada.Tags.Get_Entry_Index (Ada.Tags.Tag! (<type>VP), S);
2502 -- where I will be used to capture the entry index of the primitive
2503 -- wrapper at position S.
2505 if Tagged_Type_Expansion
then
2507 Unchecked_Convert_To
(RTE
(RE_Tag
),
2509 (Node
(First_Elmt
(Access_Disp_Table
(Typ
))), Loc
));
2512 Make_Attribute_Reference
(Loc
,
2513 Prefix
=> New_Occurrence_Of
(Typ
, Loc
),
2514 Attribute_Name
=> Name_Tag
);
2518 Make_Object_Declaration
(Loc
,
2519 Defining_Identifier
=>
2520 Make_Defining_Identifier
(Loc
, Name_uI
),
2521 Object_Definition
=>
2522 New_Occurrence_Of
(Standard_Integer
, Loc
),
2524 Make_Function_Call
(Loc
,
2526 New_Occurrence_Of
(RTE
(RE_Get_Entry_Index
), Loc
),
2527 Parameter_Associations
=>
2528 New_List
(Tag_Node
, Make_Identifier
(Loc
, Name_uS
)))));
2530 if Ekind
(Conc_Typ
) = E_Protected_Type
then
2533 -- Bnn : Communication_Block;
2535 Com_Block
:= Make_Temporary
(Loc
, 'B');
2537 Make_Object_Declaration
(Loc
,
2538 Defining_Identifier
=> Com_Block
,
2539 Object_Definition
=>
2540 New_Occurrence_Of
(RTE
(RE_Communication_Block
), Loc
)));
2542 -- Build T._object'Access for calls below
2545 Make_Attribute_Reference
(Loc
,
2546 Attribute_Name
=> Name_Unchecked_Access
,
2548 Make_Selected_Component
(Loc
,
2549 Prefix
=> Make_Identifier
(Loc
, Name_uT
),
2550 Selector_Name
=> Make_Identifier
(Loc
, Name_uObject
)));
2552 case Corresponding_Runtime_Package
(Conc_Typ
) is
2553 when System_Tasking_Protected_Objects_Entries
=>
2556 -- Protected_Entry_Call
2557 -- (T._object'Access, -- Object
2558 -- Protected_Entry_Index! (I), -- E
2559 -- P, -- Uninterpreted_Data
2560 -- Asynchronous_Call, -- Mode
2561 -- Bnn); -- Communication_Block
2563 -- where T is the protected object, I is the entry index, P
2564 -- is the wrapped parameters and B is the name of the
2565 -- communication block.
2568 Make_Procedure_Call_Statement
(Loc
,
2570 New_Occurrence_Of
(RTE
(RE_Protected_Entry_Call
), Loc
),
2571 Parameter_Associations
=>
2575 Unchecked_Convert_To
( -- entry index
2576 RTE
(RE_Protected_Entry_Index
),
2577 Make_Identifier
(Loc
, Name_uI
)),
2579 Make_Identifier
(Loc
, Name_uP
), -- parameter block
2580 New_Occurrence_Of
-- Asynchronous_Call
2581 (RTE
(RE_Asynchronous_Call
), Loc
),
2582 New_Occurrence_Of
-- comm block
2583 (Com_Block
, Loc
))));
2586 raise Program_Error
;
2590 -- B := Dummy_Communication_Block (Bnn);
2593 Make_Assignment_Statement
(Loc
,
2594 Name
=> Make_Identifier
(Loc
, Name_uB
),
2596 Unchecked_Convert_To
2597 (RTE
(RE_Dummy_Communication_Block
),
2598 New_Occurrence_Of
(Com_Block
, Loc
))));
2604 Make_Assignment_Statement
(Loc
,
2605 Name
=> Make_Identifier
(Loc
, Name_uF
),
2606 Expression
=> New_Occurrence_Of
(Standard_False
, Loc
)));
2609 pragma Assert
(Ekind
(Conc_Typ
) = E_Task_Type
);
2613 -- (T._task_id, -- Acceptor
2614 -- Task_Entry_Index! (I), -- E
2615 -- P, -- Uninterpreted_Data
2616 -- Asynchronous_Call, -- Mode
2617 -- F); -- Rendezvous_Successful
2619 -- where T is the task object, I is the entry index, P is the
2620 -- wrapped parameters and F is the status flag.
2623 Make_Procedure_Call_Statement
(Loc
,
2625 New_Occurrence_Of
(RTE
(RE_Task_Entry_Call
), Loc
),
2626 Parameter_Associations
=>
2628 Make_Selected_Component
(Loc
, -- T._task_id
2629 Prefix
=> Make_Identifier
(Loc
, Name_uT
),
2630 Selector_Name
=> Make_Identifier
(Loc
, Name_uTask_Id
)),
2632 Unchecked_Convert_To
( -- entry index
2633 RTE
(RE_Task_Entry_Index
),
2634 Make_Identifier
(Loc
, Name_uI
)),
2636 Make_Identifier
(Loc
, Name_uP
), -- parameter block
2637 New_Occurrence_Of
-- Asynchronous_Call
2638 (RTE
(RE_Asynchronous_Call
), Loc
),
2639 Make_Identifier
(Loc
, Name_uF
)))); -- status flag
2643 -- Ensure that the statements list is non-empty
2646 Make_Assignment_Statement
(Loc
,
2647 Name
=> Make_Identifier
(Loc
, Name_uF
),
2648 Expression
=> New_Occurrence_Of
(Standard_False
, Loc
)));
2652 Make_Subprogram_Body
(Loc
,
2654 Make_Disp_Asynchronous_Select_Spec
(Typ
),
2655 Declarations
=> Decls
,
2656 Handled_Statement_Sequence
=>
2657 Make_Handled_Sequence_Of_Statements
(Loc
, Stmts
));
2658 end Make_Disp_Asynchronous_Select_Body
;
2660 ----------------------------------------
2661 -- Make_Disp_Asynchronous_Select_Spec --
2662 ----------------------------------------
2664 function Make_Disp_Asynchronous_Select_Spec
2665 (Typ
: Entity_Id
) return Node_Id
2667 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
2668 B_Id
: constant Entity_Id
:= Make_Defining_Identifier
(Loc
, Name_uB
);
2669 Def_Id
: constant Entity_Id
:=
2670 Make_Defining_Identifier
(Loc
,
2671 Name_uDisp_Asynchronous_Select
);
2675 pragma Assert
(not Restriction_Active
(No_Dispatching_Calls
));
2677 -- T : in out Typ; -- Object parameter
2678 -- S : Integer; -- Primitive operation slot
2679 -- P : Address; -- Wrapped parameters
2680 -- B : out Dummy_Communication_Block; -- Communication block dummy
2681 -- F : out Boolean; -- Status flag
2683 -- The B parameter may be left uninitialized
2685 Set_Warnings_Off
(B_Id
);
2687 Params
:= New_List
(
2689 Make_Parameter_Specification
(Loc
,
2690 Defining_Identifier
=> Make_Defining_Identifier
(Loc
, Name_uT
),
2691 Parameter_Type
=> New_Occurrence_Of
(Typ
, Loc
),
2693 Out_Present
=> True),
2695 Make_Parameter_Specification
(Loc
,
2696 Defining_Identifier
=> Make_Defining_Identifier
(Loc
, Name_uS
),
2697 Parameter_Type
=> New_Occurrence_Of
(Standard_Integer
, Loc
)),
2699 Make_Parameter_Specification
(Loc
,
2700 Defining_Identifier
=> Make_Defining_Identifier
(Loc
, Name_uP
),
2701 Parameter_Type
=> New_Occurrence_Of
(RTE
(RE_Address
), Loc
)),
2703 Make_Parameter_Specification
(Loc
,
2704 Defining_Identifier
=> B_Id
,
2706 New_Occurrence_Of
(RTE
(RE_Dummy_Communication_Block
), Loc
),
2707 Out_Present
=> True),
2709 Make_Parameter_Specification
(Loc
,
2710 Defining_Identifier
=> Make_Defining_Identifier
(Loc
, Name_uF
),
2711 Parameter_Type
=> New_Occurrence_Of
(Standard_Boolean
, Loc
),
2712 Out_Present
=> True));
2715 Make_Procedure_Specification
(Loc
,
2716 Defining_Unit_Name
=> Def_Id
,
2717 Parameter_Specifications
=> Params
);
2718 end Make_Disp_Asynchronous_Select_Spec
;
2720 ---------------------------------------
2721 -- Make_Disp_Conditional_Select_Body --
2722 ---------------------------------------
2724 -- For interface types, generate:
2726 -- procedure _Disp_Conditional_Select
2727 -- (T : in out <Typ>;
2729 -- P : System.Address;
2730 -- C : out Ada.Tags.Prim_Op_Kind;
2735 -- C := Ada.Tags.POK_Function;
2736 -- end _Disp_Conditional_Select;
2738 -- For protected types, generate:
2740 -- procedure _Disp_Conditional_Select
2741 -- (T : in out <Typ>;
2743 -- P : System.Address;
2744 -- C : out Ada.Tags.Prim_Op_Kind;
2748 -- Bnn : System.Tasking.Protected_Objects.Operations.
2749 -- Communication_Block;
2752 -- C := Ada.Tags.Get_Prim_Op_Kind (Ada.Tags.Tag (<Typ>VP, S));
2754 -- if C = Ada.Tags.POK_Procedure
2755 -- or else C = Ada.Tags.POK_Protected_Procedure
2756 -- or else C = Ada.Tags.POK_Task_Procedure
2762 -- I := Ada.Tags.Get_Entry_Index (Ada.Tags.Tag (<Typ>VP, S));
2763 -- System.Tasking.Protected_Objects.Operations.Protected_Entry_Call
2764 -- (T.object'Access,
2765 -- System.Tasking.Protected_Objects.Protected_Entry_Index (I),
2767 -- System.Tasking.Conditional_Call,
2769 -- F := not Cancelled (Bnn);
2770 -- end _Disp_Conditional_Select;
2772 -- For task types, generate:
2774 -- procedure _Disp_Conditional_Select
2775 -- (T : in out <Typ>;
2777 -- P : System.Address;
2778 -- C : out Ada.Tags.Prim_Op_Kind;
2784 -- I := Ada.Tags.Get_Entry_Index (Ada.Tags.Tag (<Typ>VP, S));
2785 -- System.Tasking.Rendezvous.Task_Entry_Call
2787 -- System.Tasking.Task_Entry_Index (I),
2789 -- System.Tasking.Conditional_Call,
2791 -- end _Disp_Conditional_Select;
2793 function Make_Disp_Conditional_Select_Body
2794 (Typ
: Entity_Id
) return Node_Id
2796 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
2797 Blk_Nam
: Entity_Id
;
2798 Conc_Typ
: Entity_Id
:= Empty
;
2799 Decls
: constant List_Id
:= New_List
;
2801 Stmts
: constant List_Id
:= New_List
;
2805 pragma Assert
(not Restriction_Active
(No_Dispatching_Calls
));
2807 -- Null body is generated for interface types
2809 if Is_Interface
(Typ
) then
2811 Make_Subprogram_Body
(Loc
,
2813 Make_Disp_Conditional_Select_Spec
(Typ
),
2814 Declarations
=> No_List
,
2815 Handled_Statement_Sequence
=>
2816 Make_Handled_Sequence_Of_Statements
(Loc
,
2817 New_List
(Make_Assignment_Statement
(Loc
,
2818 Name
=> Make_Identifier
(Loc
, Name_uF
),
2819 Expression
=> New_Occurrence_Of
(Standard_False
, Loc
)))));
2822 if Is_Concurrent_Record_Type
(Typ
) then
2823 Conc_Typ
:= Corresponding_Concurrent_Type
(Typ
);
2828 -- where I will be used to capture the entry index of the primitive
2829 -- wrapper at position S.
2832 Make_Object_Declaration
(Loc
,
2833 Defining_Identifier
=> Make_Defining_Identifier
(Loc
, Name_uI
),
2834 Object_Definition
=>
2835 New_Occurrence_Of
(Standard_Integer
, Loc
)));
2838 -- C := Ada.Tags.Get_Prim_Op_Kind (Ada.Tags.Tag! (<type>VP), S);
2840 -- if C = POK_Procedure
2841 -- or else C = POK_Protected_Procedure
2842 -- or else C = POK_Task_Procedure;
2848 Build_Common_Dispatching_Select_Statements
(Typ
, Stmts
);
2851 -- Bnn : Communication_Block;
2853 -- where Bnn is the name of the communication block used in the
2854 -- call to Protected_Entry_Call.
2856 Blk_Nam
:= Make_Temporary
(Loc
, 'B');
2858 Make_Object_Declaration
(Loc
,
2859 Defining_Identifier
=> Blk_Nam
,
2860 Object_Definition
=>
2861 New_Occurrence_Of
(RTE
(RE_Communication_Block
), Loc
)));
2864 -- I := Ada.Tags.Get_Entry_Index (Ada.Tags.Tag! (<type>VP), S);
2866 -- I is the entry index and S is the dispatch table slot
2868 if Tagged_Type_Expansion
then
2870 Unchecked_Convert_To
(RTE
(RE_Tag
),
2872 (Node
(First_Elmt
(Access_Disp_Table
(Typ
))), Loc
));
2876 Make_Attribute_Reference
(Loc
,
2877 Prefix
=> New_Occurrence_Of
(Typ
, Loc
),
2878 Attribute_Name
=> Name_Tag
);
2882 Make_Assignment_Statement
(Loc
,
2883 Name
=> Make_Identifier
(Loc
, Name_uI
),
2885 Make_Function_Call
(Loc
,
2887 New_Occurrence_Of
(RTE
(RE_Get_Entry_Index
), Loc
),
2888 Parameter_Associations
=> New_List
(
2890 Make_Identifier
(Loc
, Name_uS
)))));
2892 if Ekind
(Conc_Typ
) = E_Protected_Type
then
2894 Obj_Ref
:= -- T._object'Access
2895 Make_Attribute_Reference
(Loc
,
2896 Attribute_Name
=> Name_Unchecked_Access
,
2898 Make_Selected_Component
(Loc
,
2899 Prefix
=> Make_Identifier
(Loc
, Name_uT
),
2900 Selector_Name
=> Make_Identifier
(Loc
, Name_uObject
)));
2902 case Corresponding_Runtime_Package
(Conc_Typ
) is
2903 when System_Tasking_Protected_Objects_Entries
=>
2906 -- Protected_Entry_Call
2907 -- (T._object'Access, -- Object
2908 -- Protected_Entry_Index! (I), -- E
2909 -- P, -- Uninterpreted_Data
2910 -- Conditional_Call, -- Mode
2913 -- where T is the protected object, I is the entry index, P
2914 -- are the wrapped parameters and Bnn is the name of the
2915 -- communication block.
2918 Make_Procedure_Call_Statement
(Loc
,
2920 New_Occurrence_Of
(RTE
(RE_Protected_Entry_Call
), Loc
),
2921 Parameter_Associations
=> New_List
(
2924 Unchecked_Convert_To
( -- entry index
2925 RTE
(RE_Protected_Entry_Index
),
2926 Make_Identifier
(Loc
, Name_uI
)),
2928 Make_Identifier
(Loc
, Name_uP
), -- parameter block
2930 New_Occurrence_Of
-- Conditional_Call
2931 (RTE
(RE_Conditional_Call
), Loc
),
2932 New_Occurrence_Of
-- Bnn
2935 when System_Tasking_Protected_Objects_Single_Entry
=>
2937 -- If we are compiling for a restricted run-time, the call
2938 -- uses the simpler form.
2941 Make_Procedure_Call_Statement
(Loc
,
2944 (RTE
(RE_Protected_Single_Entry_Call
), Loc
),
2945 Parameter_Associations
=> New_List
(
2948 Make_Attribute_Reference
(Loc
,
2949 Prefix
=> Make_Identifier
(Loc
, Name_uP
),
2950 Attribute_Name
=> Name_Address
),
2953 (RTE
(RE_Conditional_Call
), Loc
))));
2955 raise Program_Error
;
2959 -- F := not Cancelled (Bnn);
2961 -- where F is the success flag. The status of Cancelled is negated
2962 -- in order to match the behavior of the version for task types.
2965 Make_Assignment_Statement
(Loc
,
2966 Name
=> Make_Identifier
(Loc
, Name_uF
),
2970 Make_Function_Call
(Loc
,
2972 New_Occurrence_Of
(RTE
(RE_Cancelled
), Loc
),
2973 Parameter_Associations
=> New_List
(
2974 New_Occurrence_Of
(Blk_Nam
, Loc
))))));
2976 pragma Assert
(Ekind
(Conc_Typ
) = E_Task_Type
);
2980 -- (T._task_id, -- Acceptor
2981 -- Task_Entry_Index! (I), -- E
2982 -- P, -- Uninterpreted_Data
2983 -- Conditional_Call, -- Mode
2984 -- F); -- Rendezvous_Successful
2986 -- where T is the task object, I is the entry index, P are the
2987 -- wrapped parameters and F is the status flag.
2990 Make_Procedure_Call_Statement
(Loc
,
2992 New_Occurrence_Of
(RTE
(RE_Task_Entry_Call
), Loc
),
2993 Parameter_Associations
=> New_List
(
2995 Make_Selected_Component
(Loc
, -- T._task_id
2996 Prefix
=> Make_Identifier
(Loc
, Name_uT
),
2997 Selector_Name
=> Make_Identifier
(Loc
, Name_uTask_Id
)),
2999 Unchecked_Convert_To
( -- entry index
3000 RTE
(RE_Task_Entry_Index
),
3001 Make_Identifier
(Loc
, Name_uI
)),
3003 Make_Identifier
(Loc
, Name_uP
), -- parameter block
3004 New_Occurrence_Of
-- Conditional_Call
3005 (RTE
(RE_Conditional_Call
), Loc
),
3006 Make_Identifier
(Loc
, Name_uF
)))); -- status flag
3010 -- Initialize out parameters
3013 Make_Assignment_Statement
(Loc
,
3014 Name
=> Make_Identifier
(Loc
, Name_uF
),
3015 Expression
=> New_Occurrence_Of
(Standard_False
, Loc
)));
3017 Make_Assignment_Statement
(Loc
,
3018 Name
=> Make_Identifier
(Loc
, Name_uC
),
3019 Expression
=> New_Occurrence_Of
(RTE
(RE_POK_Function
), Loc
)));
3023 Make_Subprogram_Body
(Loc
,
3025 Make_Disp_Conditional_Select_Spec
(Typ
),
3026 Declarations
=> Decls
,
3027 Handled_Statement_Sequence
=>
3028 Make_Handled_Sequence_Of_Statements
(Loc
, Stmts
));
3029 end Make_Disp_Conditional_Select_Body
;
3031 ---------------------------------------
3032 -- Make_Disp_Conditional_Select_Spec --
3033 ---------------------------------------
3035 function Make_Disp_Conditional_Select_Spec
3036 (Typ
: Entity_Id
) return Node_Id
3038 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
3039 Def_Id
: constant Node_Id
:=
3040 Make_Defining_Identifier
(Loc
,
3041 Name_uDisp_Conditional_Select
);
3042 Params
: constant List_Id
:= New_List
;
3045 pragma Assert
(not Restriction_Active
(No_Dispatching_Calls
));
3047 -- T : in out Typ; -- Object parameter
3048 -- S : Integer; -- Primitive operation slot
3049 -- P : Address; -- Wrapped parameters
3050 -- C : out Prim_Op_Kind; -- Call kind
3051 -- F : out Boolean; -- Status flag
3053 Append_List_To
(Params
, New_List
(
3055 Make_Parameter_Specification
(Loc
,
3056 Defining_Identifier
=> Make_Defining_Identifier
(Loc
, Name_uT
),
3057 Parameter_Type
=> New_Occurrence_Of
(Typ
, Loc
),
3059 Out_Present
=> True),
3061 Make_Parameter_Specification
(Loc
,
3062 Defining_Identifier
=> Make_Defining_Identifier
(Loc
, Name_uS
),
3063 Parameter_Type
=> New_Occurrence_Of
(Standard_Integer
, Loc
)),
3065 Make_Parameter_Specification
(Loc
,
3066 Defining_Identifier
=> Make_Defining_Identifier
(Loc
, Name_uP
),
3067 Parameter_Type
=> New_Occurrence_Of
(RTE
(RE_Address
), Loc
)),
3069 Make_Parameter_Specification
(Loc
,
3070 Defining_Identifier
=> Make_Defining_Identifier
(Loc
, Name_uC
),
3072 New_Occurrence_Of
(RTE
(RE_Prim_Op_Kind
), Loc
),
3073 Out_Present
=> True),
3075 Make_Parameter_Specification
(Loc
,
3076 Defining_Identifier
=> Make_Defining_Identifier
(Loc
, Name_uF
),
3077 Parameter_Type
=> New_Occurrence_Of
(Standard_Boolean
, Loc
),
3078 Out_Present
=> True)));
3081 Make_Procedure_Specification
(Loc
,
3082 Defining_Unit_Name
=> Def_Id
,
3083 Parameter_Specifications
=> Params
);
3084 end Make_Disp_Conditional_Select_Spec
;
3086 -------------------------------------
3087 -- Make_Disp_Get_Prim_Op_Kind_Body --
3088 -------------------------------------
3090 function Make_Disp_Get_Prim_Op_Kind_Body
(Typ
: Entity_Id
) return Node_Id
is
3091 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
3095 pragma Assert
(not Restriction_Active
(No_Dispatching_Calls
));
3097 if Is_Interface
(Typ
) then
3099 Make_Subprogram_Body
(Loc
,
3101 Make_Disp_Get_Prim_Op_Kind_Spec
(Typ
),
3102 Declarations
=> New_List
,
3103 Handled_Statement_Sequence
=>
3104 Make_Handled_Sequence_Of_Statements
(Loc
,
3105 New_List
(Make_Null_Statement
(Loc
))));
3109 -- C := get_prim_op_kind (tag! (<type>VP), S);
3111 -- where C is the out parameter capturing the call kind and S is the
3112 -- dispatch table slot number.
3114 if Tagged_Type_Expansion
then
3116 Unchecked_Convert_To
(RTE
(RE_Tag
),
3118 (Node
(First_Elmt
(Access_Disp_Table
(Typ
))), Loc
));
3122 Make_Attribute_Reference
(Loc
,
3123 Prefix
=> New_Occurrence_Of
(Typ
, Loc
),
3124 Attribute_Name
=> Name_Tag
);
3128 Make_Subprogram_Body
(Loc
,
3130 Make_Disp_Get_Prim_Op_Kind_Spec
(Typ
),
3131 Declarations
=> New_List
,
3132 Handled_Statement_Sequence
=>
3133 Make_Handled_Sequence_Of_Statements
(Loc
,
3135 Make_Assignment_Statement
(Loc
,
3136 Name
=> Make_Identifier
(Loc
, Name_uC
),
3138 Make_Function_Call
(Loc
,
3140 New_Occurrence_Of
(RTE
(RE_Get_Prim_Op_Kind
), Loc
),
3141 Parameter_Associations
=> New_List
(
3143 Make_Identifier
(Loc
, Name_uS
)))))));
3144 end Make_Disp_Get_Prim_Op_Kind_Body
;
3146 -------------------------------------
3147 -- Make_Disp_Get_Prim_Op_Kind_Spec --
3148 -------------------------------------
3150 function Make_Disp_Get_Prim_Op_Kind_Spec
3151 (Typ
: Entity_Id
) return Node_Id
3153 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
3154 Def_Id
: constant Node_Id
:=
3155 Make_Defining_Identifier
(Loc
, Name_uDisp_Get_Prim_Op_Kind
);
3156 Params
: constant List_Id
:= New_List
;
3159 pragma Assert
(not Restriction_Active
(No_Dispatching_Calls
));
3161 -- T : in out Typ; -- Object parameter
3162 -- S : Integer; -- Primitive operation slot
3163 -- C : out Prim_Op_Kind; -- Call kind
3165 Append_List_To
(Params
, New_List
(
3167 Make_Parameter_Specification
(Loc
,
3168 Defining_Identifier
=> Make_Defining_Identifier
(Loc
, Name_uT
),
3169 Parameter_Type
=> New_Occurrence_Of
(Typ
, Loc
),
3171 Out_Present
=> True),
3173 Make_Parameter_Specification
(Loc
,
3174 Defining_Identifier
=> Make_Defining_Identifier
(Loc
, Name_uS
),
3175 Parameter_Type
=> New_Occurrence_Of
(Standard_Integer
, Loc
)),
3177 Make_Parameter_Specification
(Loc
,
3178 Defining_Identifier
=> Make_Defining_Identifier
(Loc
, Name_uC
),
3180 New_Occurrence_Of
(RTE
(RE_Prim_Op_Kind
), Loc
),
3181 Out_Present
=> True)));
3184 Make_Procedure_Specification
(Loc
,
3185 Defining_Unit_Name
=> Def_Id
,
3186 Parameter_Specifications
=> Params
);
3187 end Make_Disp_Get_Prim_Op_Kind_Spec
;
3189 --------------------------------
3190 -- Make_Disp_Get_Task_Id_Body --
3191 --------------------------------
3193 function Make_Disp_Get_Task_Id_Body
3194 (Typ
: Entity_Id
) return Node_Id
3196 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
3200 pragma Assert
(not Restriction_Active
(No_Dispatching_Calls
));
3202 if Is_Concurrent_Record_Type
(Typ
)
3203 and then Ekind
(Corresponding_Concurrent_Type
(Typ
)) = E_Task_Type
3206 -- return To_Address (_T._task_id);
3209 Make_Simple_Return_Statement
(Loc
,
3211 Unchecked_Convert_To
3213 Make_Selected_Component
(Loc
,
3214 Prefix
=> Make_Identifier
(Loc
, Name_uT
),
3215 Selector_Name
=> Make_Identifier
(Loc
, Name_uTask_Id
))));
3217 -- A null body is constructed for non-task types
3221 -- return Null_Address;
3224 Make_Simple_Return_Statement
(Loc
,
3225 Expression
=> New_Occurrence_Of
(RTE
(RE_Null_Address
), Loc
));
3229 Make_Subprogram_Body
(Loc
,
3230 Specification
=> Make_Disp_Get_Task_Id_Spec
(Typ
),
3231 Declarations
=> New_List
,
3232 Handled_Statement_Sequence
=>
3233 Make_Handled_Sequence_Of_Statements
(Loc
, New_List
(Ret
)));
3234 end Make_Disp_Get_Task_Id_Body
;
3236 --------------------------------
3237 -- Make_Disp_Get_Task_Id_Spec --
3238 --------------------------------
3240 function Make_Disp_Get_Task_Id_Spec
3241 (Typ
: Entity_Id
) return Node_Id
3243 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
3246 pragma Assert
(not Restriction_Active
(No_Dispatching_Calls
));
3249 Make_Function_Specification
(Loc
,
3250 Defining_Unit_Name
=>
3251 Make_Defining_Identifier
(Loc
, Name_uDisp_Get_Task_Id
),
3252 Parameter_Specifications
=> New_List
(
3253 Make_Parameter_Specification
(Loc
,
3254 Defining_Identifier
=> Make_Defining_Identifier
(Loc
, Name_uT
),
3255 Parameter_Type
=> New_Occurrence_Of
(Typ
, Loc
))),
3256 Result_Definition
=>
3257 New_Occurrence_Of
(RTE
(RE_Address
), Loc
));
3258 end Make_Disp_Get_Task_Id_Spec
;
3260 ----------------------------
3261 -- Make_Disp_Requeue_Body --
3262 ----------------------------
3264 function Make_Disp_Requeue_Body
3265 (Typ
: Entity_Id
) return Node_Id
3267 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
3268 Conc_Typ
: Entity_Id
:= Empty
;
3269 Stmts
: constant List_Id
:= New_List
;
3272 pragma Assert
(not Restriction_Active
(No_Dispatching_Calls
));
3274 -- Null body is generated for interface types and nonconcurrent
3277 if Is_Interface
(Typ
)
3278 or else not Is_Concurrent_Record_Type
(Typ
)
3281 Make_Subprogram_Body
(Loc
,
3282 Specification
=> Make_Disp_Requeue_Spec
(Typ
),
3283 Declarations
=> No_List
,
3284 Handled_Statement_Sequence
=>
3285 Make_Handled_Sequence_Of_Statements
(Loc
,
3286 New_List
(Make_Null_Statement
(Loc
))));
3289 Conc_Typ
:= Corresponding_Concurrent_Type
(Typ
);
3291 if Ekind
(Conc_Typ
) = E_Protected_Type
then
3293 -- Generate statements:
3295 -- System.Tasking.Protected_Objects.Operations.
3296 -- Requeue_Protected_Entry
3297 -- (Protection_Entries_Access (P),
3298 -- O._object'Unchecked_Access,
3299 -- Protected_Entry_Index (I),
3302 -- System.Tasking.Protected_Objects.Operations.
3303 -- Requeue_Task_To_Protected_Entry
3304 -- (O._object'Unchecked_Access,
3305 -- Protected_Entry_Index (I),
3309 if Restriction_Active
(No_Entry_Queue
) then
3310 Append_To
(Stmts
, Make_Null_Statement
(Loc
));
3313 Make_If_Statement
(Loc
,
3314 Condition
=> Make_Identifier
(Loc
, Name_uF
),
3319 -- Call to Requeue_Protected_Entry
3321 Make_Procedure_Call_Statement
(Loc
,
3324 (RTE
(RE_Requeue_Protected_Entry
), Loc
),
3325 Parameter_Associations
=>
3328 Unchecked_Convert_To
( -- PEA (P)
3329 RTE
(RE_Protection_Entries_Access
),
3330 Make_Identifier
(Loc
, Name_uP
)),
3332 Make_Attribute_Reference
(Loc
, -- O._object'Acc
3334 Name_Unchecked_Access
,
3336 Make_Selected_Component
(Loc
,
3338 Make_Identifier
(Loc
, Name_uO
),
3340 Make_Identifier
(Loc
, Name_uObject
))),
3342 Unchecked_Convert_To
( -- entry index
3343 RTE
(RE_Protected_Entry_Index
),
3344 Make_Identifier
(Loc
, Name_uI
)),
3346 Make_Identifier
(Loc
, Name_uA
)))), -- abort status
3351 -- Call to Requeue_Task_To_Protected_Entry
3353 Make_Procedure_Call_Statement
(Loc
,
3356 (RTE
(RE_Requeue_Task_To_Protected_Entry
), Loc
),
3357 Parameter_Associations
=>
3360 Make_Attribute_Reference
(Loc
, -- O._object'Acc
3361 Attribute_Name
=> Name_Unchecked_Access
,
3363 Make_Selected_Component
(Loc
,
3365 Make_Identifier
(Loc
, Name_uO
),
3367 Make_Identifier
(Loc
, Name_uObject
))),
3369 Unchecked_Convert_To
( -- entry index
3370 RTE
(RE_Protected_Entry_Index
),
3371 Make_Identifier
(Loc
, Name_uI
)),
3373 Make_Identifier
(Loc
, Name_uA
)))))); -- abort status
3377 pragma Assert
(Is_Task_Type
(Conc_Typ
));
3381 -- System.Tasking.Rendezvous.Requeue_Protected_To_Task_Entry
3382 -- (Protection_Entries_Access (P),
3384 -- Task_Entry_Index (I),
3387 -- System.Tasking.Rendezvous.Requeue_Task_Entry
3389 -- Task_Entry_Index (I),
3394 Make_If_Statement
(Loc
,
3395 Condition
=> Make_Identifier
(Loc
, Name_uF
),
3397 Then_Statements
=> New_List
(
3399 -- Call to Requeue_Protected_To_Task_Entry
3401 Make_Procedure_Call_Statement
(Loc
,
3404 (RTE
(RE_Requeue_Protected_To_Task_Entry
), Loc
),
3406 Parameter_Associations
=> New_List
(
3408 Unchecked_Convert_To
( -- PEA (P)
3409 RTE
(RE_Protection_Entries_Access
),
3410 Make_Identifier
(Loc
, Name_uP
)),
3412 Make_Selected_Component
(Loc
, -- O._task_id
3413 Prefix
=> Make_Identifier
(Loc
, Name_uO
),
3414 Selector_Name
=> Make_Identifier
(Loc
, Name_uTask_Id
)),
3416 Unchecked_Convert_To
( -- entry index
3417 RTE
(RE_Task_Entry_Index
),
3418 Make_Identifier
(Loc
, Name_uI
)),
3420 Make_Identifier
(Loc
, Name_uA
)))), -- abort status
3422 Else_Statements
=> New_List
(
3424 -- Call to Requeue_Task_Entry
3426 Make_Procedure_Call_Statement
(Loc
,
3428 New_Occurrence_Of
(RTE
(RE_Requeue_Task_Entry
), Loc
),
3430 Parameter_Associations
=> New_List
(
3432 Make_Selected_Component
(Loc
, -- O._task_id
3433 Prefix
=> Make_Identifier
(Loc
, Name_uO
),
3434 Selector_Name
=> Make_Identifier
(Loc
, Name_uTask_Id
)),
3436 Unchecked_Convert_To
( -- entry index
3437 RTE
(RE_Task_Entry_Index
),
3438 Make_Identifier
(Loc
, Name_uI
)),
3440 Make_Identifier
(Loc
, Name_uA
)))))); -- abort status
3443 -- Even though no declarations are needed in both cases, we allocate
3444 -- a list for entities added by Freeze.
3447 Make_Subprogram_Body
(Loc
,
3448 Specification
=> Make_Disp_Requeue_Spec
(Typ
),
3449 Declarations
=> New_List
,
3450 Handled_Statement_Sequence
=>
3451 Make_Handled_Sequence_Of_Statements
(Loc
, Stmts
));
3452 end Make_Disp_Requeue_Body
;
3454 ----------------------------
3455 -- Make_Disp_Requeue_Spec --
3456 ----------------------------
3458 function Make_Disp_Requeue_Spec
3459 (Typ
: Entity_Id
) return Node_Id
3461 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
3464 pragma Assert
(not Restriction_Active
(No_Dispatching_Calls
));
3466 -- O : in out Typ; - Object parameter
3467 -- F : Boolean; - Protected (True) / task (False) flag
3468 -- P : Address; - Protection_Entries_Access value
3469 -- I : Entry_Index - Index of entry call
3470 -- A : Boolean - Abort flag
3472 -- Note that the Protection_Entries_Access value is represented as a
3473 -- System.Address in order to avoid dragging in the tasking runtime
3474 -- when compiling sources without tasking constructs.
3477 Make_Procedure_Specification
(Loc
,
3478 Defining_Unit_Name
=>
3479 Make_Defining_Identifier
(Loc
, Name_uDisp_Requeue
),
3481 Parameter_Specifications
=> New_List
(
3483 Make_Parameter_Specification
(Loc
, -- O
3484 Defining_Identifier
=>
3485 Make_Defining_Identifier
(Loc
, Name_uO
),
3487 New_Occurrence_Of
(Typ
, Loc
),
3489 Out_Present
=> True),
3491 Make_Parameter_Specification
(Loc
, -- F
3492 Defining_Identifier
=>
3493 Make_Defining_Identifier
(Loc
, Name_uF
),
3495 New_Occurrence_Of
(Standard_Boolean
, Loc
)),
3497 Make_Parameter_Specification
(Loc
, -- P
3498 Defining_Identifier
=>
3499 Make_Defining_Identifier
(Loc
, Name_uP
),
3501 New_Occurrence_Of
(RTE
(RE_Address
), Loc
)),
3503 Make_Parameter_Specification
(Loc
, -- I
3504 Defining_Identifier
=>
3505 Make_Defining_Identifier
(Loc
, Name_uI
),
3507 New_Occurrence_Of
(Standard_Integer
, Loc
)),
3509 Make_Parameter_Specification
(Loc
, -- A
3510 Defining_Identifier
=>
3511 Make_Defining_Identifier
(Loc
, Name_uA
),
3513 New_Occurrence_Of
(Standard_Boolean
, Loc
))));
3514 end Make_Disp_Requeue_Spec
;
3516 ---------------------------------
3517 -- Make_Disp_Timed_Select_Body --
3518 ---------------------------------
3520 -- For interface types, generate:
3522 -- procedure _Disp_Timed_Select
3523 -- (T : in out <Typ>;
3525 -- P : System.Address;
3528 -- C : out Ada.Tags.Prim_Op_Kind;
3533 -- C := Ada.Tags.POK_Function;
3534 -- end _Disp_Timed_Select;
3536 -- For protected types, generate:
3538 -- procedure _Disp_Timed_Select
3539 -- (T : in out <Typ>;
3541 -- P : System.Address;
3544 -- C : out Ada.Tags.Prim_Op_Kind;
3550 -- C := Ada.Tags.Get_Prim_Op_Kind (Ada.Tags.Tag (<Typ>VP), S);
3552 -- if C = Ada.Tags.POK_Procedure
3553 -- or else C = Ada.Tags.POK_Protected_Procedure
3554 -- or else C = Ada.Tags.POK_Task_Procedure
3560 -- I := Ada.Tags.Get_Entry_Index (Ada.Tags.Tag (<Typ>VP), S);
3561 -- System.Tasking.Protected_Objects.Operations.
3562 -- Timed_Protected_Entry_Call
3563 -- (T._object'Access,
3564 -- System.Tasking.Protected_Objects.Protected_Entry_Index (I),
3569 -- end _Disp_Timed_Select;
3571 -- For task types, generate:
3573 -- procedure _Disp_Timed_Select
3574 -- (T : in out <Typ>;
3576 -- P : System.Address;
3579 -- C : out Ada.Tags.Prim_Op_Kind;
3585 -- I := Ada.Tags.Get_Entry_Index (Ada.Tags.Tag (<Typ>VP), S);
3586 -- System.Tasking.Rendezvous.Timed_Task_Entry_Call
3588 -- System.Tasking.Task_Entry_Index (I),
3593 -- end _Disp_Time_Select;
3595 function Make_Disp_Timed_Select_Body
3596 (Typ
: Entity_Id
) return Node_Id
3598 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
3599 Conc_Typ
: Entity_Id
:= Empty
;
3600 Decls
: constant List_Id
:= New_List
;
3602 Stmts
: constant List_Id
:= New_List
;
3606 pragma Assert
(not Restriction_Active
(No_Dispatching_Calls
));
3608 -- Null body is generated for interface types
3610 if Is_Interface
(Typ
) then
3612 Make_Subprogram_Body
(Loc
,
3613 Specification
=> Make_Disp_Timed_Select_Spec
(Typ
),
3614 Declarations
=> New_List
,
3615 Handled_Statement_Sequence
=>
3616 Make_Handled_Sequence_Of_Statements
(Loc
,
3618 Make_Assignment_Statement
(Loc
,
3619 Name
=> Make_Identifier
(Loc
, Name_uF
),
3620 Expression
=> New_Occurrence_Of
(Standard_False
, Loc
)))));
3623 if Is_Concurrent_Record_Type
(Typ
) then
3624 Conc_Typ
:= Corresponding_Concurrent_Type
(Typ
);
3629 -- where I will be used to capture the entry index of the primitive
3630 -- wrapper at position S.
3633 Make_Object_Declaration
(Loc
,
3634 Defining_Identifier
=> Make_Defining_Identifier
(Loc
, Name_uI
),
3635 Object_Definition
=>
3636 New_Occurrence_Of
(Standard_Integer
, Loc
)));
3639 -- C := Get_Prim_Op_Kind (tag! (<type>VP), S);
3641 -- if C = POK_Procedure
3642 -- or else C = POK_Protected_Procedure
3643 -- or else C = POK_Task_Procedure;
3649 Build_Common_Dispatching_Select_Statements
(Typ
, Stmts
);
3652 -- I := Get_Entry_Index (tag! (<type>VP), S);
3654 -- I is the entry index and S is the dispatch table slot
3656 if Tagged_Type_Expansion
then
3658 Unchecked_Convert_To
(RTE
(RE_Tag
),
3660 (Node
(First_Elmt
(Access_Disp_Table
(Typ
))), Loc
));
3664 Make_Attribute_Reference
(Loc
,
3665 Prefix
=> New_Occurrence_Of
(Typ
, Loc
),
3666 Attribute_Name
=> Name_Tag
);
3670 Make_Assignment_Statement
(Loc
,
3671 Name
=> Make_Identifier
(Loc
, Name_uI
),
3673 Make_Function_Call
(Loc
,
3674 Name
=> New_Occurrence_Of
(RTE
(RE_Get_Entry_Index
), Loc
),
3675 Parameter_Associations
=> New_List
(
3677 Make_Identifier
(Loc
, Name_uS
)))));
3681 if Ekind
(Conc_Typ
) = E_Protected_Type
then
3683 -- Build T._object'Access
3686 Make_Attribute_Reference
(Loc
,
3687 Attribute_Name
=> Name_Unchecked_Access
,
3689 Make_Selected_Component
(Loc
,
3690 Prefix
=> Make_Identifier
(Loc
, Name_uT
),
3691 Selector_Name
=> Make_Identifier
(Loc
, Name_uObject
)));
3693 -- Normal case, No_Entry_Queue restriction not active. In this
3694 -- case we generate:
3696 -- Timed_Protected_Entry_Call
3697 -- (T._object'access,
3698 -- Protected_Entry_Index! (I),
3701 -- where T is the protected object, I is the entry index, P are
3702 -- the wrapped parameters, D is the delay amount, M is the delay
3703 -- mode and F is the status flag.
3705 -- Historically, there was also an implementation for single
3706 -- entry protected types (in s-tposen). However, it was removed
3707 -- by also testing for no No_Select_Statements restriction in
3708 -- Exp_Utils.Corresponding_Runtime_Package. This simplified the
3709 -- implementation of s-tposen.adb and provided consistency between
3710 -- all versions of System.Tasking.Protected_Objects.Single_Entry
3713 case Corresponding_Runtime_Package
(Conc_Typ
) is
3714 when System_Tasking_Protected_Objects_Entries
=>
3716 Make_Procedure_Call_Statement
(Loc
,
3719 (RTE
(RE_Timed_Protected_Entry_Call
), Loc
),
3720 Parameter_Associations
=> New_List
(
3723 Unchecked_Convert_To
( -- entry index
3724 RTE
(RE_Protected_Entry_Index
),
3725 Make_Identifier
(Loc
, Name_uI
)),
3727 Make_Identifier
(Loc
, Name_uP
), -- parameter block
3728 Make_Identifier
(Loc
, Name_uD
), -- delay
3729 Make_Identifier
(Loc
, Name_uM
), -- delay mode
3730 Make_Identifier
(Loc
, Name_uF
)))); -- status flag
3733 raise Program_Error
;
3739 pragma Assert
(Ekind
(Conc_Typ
) = E_Task_Type
);
3742 -- Timed_Task_Entry_Call (
3744 -- Task_Entry_Index! (I),
3750 -- where T is the task object, I is the entry index, P are the
3751 -- wrapped parameters, D is the delay amount, M is the delay
3752 -- mode and F is the status flag.
3755 Make_Procedure_Call_Statement
(Loc
,
3757 New_Occurrence_Of
(RTE
(RE_Timed_Task_Entry_Call
), Loc
),
3759 Parameter_Associations
=> New_List
(
3760 Make_Selected_Component
(Loc
, -- T._task_id
3761 Prefix
=> Make_Identifier
(Loc
, Name_uT
),
3762 Selector_Name
=> Make_Identifier
(Loc
, Name_uTask_Id
)),
3764 Unchecked_Convert_To
( -- entry index
3765 RTE
(RE_Task_Entry_Index
),
3766 Make_Identifier
(Loc
, Name_uI
)),
3768 Make_Identifier
(Loc
, Name_uP
), -- parameter block
3769 Make_Identifier
(Loc
, Name_uD
), -- delay
3770 Make_Identifier
(Loc
, Name_uM
), -- delay mode
3771 Make_Identifier
(Loc
, Name_uF
)))); -- status flag
3775 -- Initialize out parameters
3778 Make_Assignment_Statement
(Loc
,
3779 Name
=> Make_Identifier
(Loc
, Name_uF
),
3780 Expression
=> New_Occurrence_Of
(Standard_False
, Loc
)));
3782 Make_Assignment_Statement
(Loc
,
3783 Name
=> Make_Identifier
(Loc
, Name_uC
),
3784 Expression
=> New_Occurrence_Of
(RTE
(RE_POK_Function
), Loc
)));
3788 Make_Subprogram_Body
(Loc
,
3789 Specification
=> Make_Disp_Timed_Select_Spec
(Typ
),
3790 Declarations
=> Decls
,
3791 Handled_Statement_Sequence
=>
3792 Make_Handled_Sequence_Of_Statements
(Loc
, Stmts
));
3793 end Make_Disp_Timed_Select_Body
;
3795 ---------------------------------
3796 -- Make_Disp_Timed_Select_Spec --
3797 ---------------------------------
3799 function Make_Disp_Timed_Select_Spec
3800 (Typ
: Entity_Id
) return Node_Id
3802 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
3803 Def_Id
: constant Node_Id
:=
3804 Make_Defining_Identifier
(Loc
,
3805 Name_uDisp_Timed_Select
);
3806 Params
: constant List_Id
:= New_List
;
3809 pragma Assert
(not Restriction_Active
(No_Dispatching_Calls
));
3811 -- T : in out Typ; -- Object parameter
3812 -- S : Integer; -- Primitive operation slot
3813 -- P : Address; -- Wrapped parameters
3814 -- D : Duration; -- Delay
3815 -- M : Integer; -- Delay Mode
3816 -- C : out Prim_Op_Kind; -- Call kind
3817 -- F : out Boolean; -- Status flag
3819 Append_List_To
(Params
, New_List
(
3821 Make_Parameter_Specification
(Loc
,
3822 Defining_Identifier
=> Make_Defining_Identifier
(Loc
, Name_uT
),
3823 Parameter_Type
=> New_Occurrence_Of
(Typ
, Loc
),
3825 Out_Present
=> True),
3827 Make_Parameter_Specification
(Loc
,
3828 Defining_Identifier
=> Make_Defining_Identifier
(Loc
, Name_uS
),
3829 Parameter_Type
=> New_Occurrence_Of
(Standard_Integer
, Loc
)),
3831 Make_Parameter_Specification
(Loc
,
3832 Defining_Identifier
=> Make_Defining_Identifier
(Loc
, Name_uP
),
3833 Parameter_Type
=> New_Occurrence_Of
(RTE
(RE_Address
), Loc
)),
3835 Make_Parameter_Specification
(Loc
,
3836 Defining_Identifier
=> Make_Defining_Identifier
(Loc
, Name_uD
),
3837 Parameter_Type
=> New_Occurrence_Of
(Standard_Duration
, Loc
)),
3839 Make_Parameter_Specification
(Loc
,
3840 Defining_Identifier
=> Make_Defining_Identifier
(Loc
, Name_uM
),
3841 Parameter_Type
=> New_Occurrence_Of
(Standard_Integer
, Loc
)),
3843 Make_Parameter_Specification
(Loc
,
3844 Defining_Identifier
=> Make_Defining_Identifier
(Loc
, Name_uC
),
3846 New_Occurrence_Of
(RTE
(RE_Prim_Op_Kind
), Loc
),
3847 Out_Present
=> True)));
3850 Make_Parameter_Specification
(Loc
,
3851 Defining_Identifier
=> Make_Defining_Identifier
(Loc
, Name_uF
),
3852 Parameter_Type
=> New_Occurrence_Of
(Standard_Boolean
, Loc
),
3853 Out_Present
=> True));
3856 Make_Procedure_Specification
(Loc
,
3857 Defining_Unit_Name
=> Def_Id
,
3858 Parameter_Specifications
=> Params
);
3859 end Make_Disp_Timed_Select_Spec
;
3865 -- The frontend supports two models for expanding dispatch tables
3866 -- associated with library-level defined tagged types: statically and
3867 -- non-statically allocated dispatch tables. In the former case the object
3868 -- containing the dispatch table is constant and it is initialized by means
3869 -- of a positional aggregate. In the latter case, the object containing
3870 -- the dispatch table is a variable which is initialized by means of
3873 -- In case of locally defined tagged types, the object containing the
3874 -- object containing the dispatch table is always a variable (instead of a
3875 -- constant). This is currently required to give support to late overriding
3876 -- of primitives. For example:
3878 -- procedure Example is
3880 -- type T1 is tagged null record;
3881 -- procedure Prim (O : T1);
3884 -- type T2 is new Pkg.T1 with null record;
3885 -- procedure Prim (X : T2) is -- late overriding
3891 -- WARNING: This routine manages Ghost regions. Return statements must be
3892 -- replaced by gotos which jump to the end of the routine and restore the
3895 function Make_DT
(Typ
: Entity_Id
) return List_Id
is
3896 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
3898 Max_Predef_Prims
: constant Int
:=
3902 (Parent
(RTE
(RE_Max_Predef_Prims
)))));
3904 DT_Decl
: constant Elist_Id
:= New_Elmt_List
;
3905 DT_Aggr
: constant Elist_Id
:= New_Elmt_List
;
3906 -- Entities marked with attribute Is_Dispatch_Table_Entity
3908 Dummy_Object
: Entity_Id
:= Empty
;
3909 -- Extra nonexistent object of type Typ internally used to compute the
3910 -- offset to the components that reference secondary dispatch tables.
3911 -- Used to compute the offset of components located at fixed position.
3913 procedure Export_DT
(Typ
: Entity_Id
; DT
: Entity_Id
; Index
: Nat
:= 0);
3914 -- Export the dispatch table DT of tagged type Typ. Required to generate
3915 -- forward references and statically allocate the table. For primary
3916 -- dispatch tables Index is 0; for secondary dispatch tables the value
3917 -- of index must match the Suffix_Index value assigned to the table by
3918 -- Make_Tags when generating its unique external name, and it is used to
3919 -- retrieve from the Dispatch_Table_Wrappers list associated with Typ
3920 -- the external name generated by Import_DT.
3922 procedure Make_Secondary_DT
3925 Iface_Comp
: Node_Id
;
3927 Num_Iface_Prims
: Nat
;
3928 Iface_DT_Ptr
: Entity_Id
;
3929 Predef_Prims_Ptr
: Entity_Id
;
3930 Build_Thunks
: Boolean;
3932 -- Ada 2005 (AI-251): Expand the declarations for a Secondary Dispatch
3933 -- Table of Typ associated with Iface. Each abstract interface of Typ
3934 -- has two secondary dispatch tables: one containing pointers to thunks
3935 -- and another containing pointers to the primitives covering the
3936 -- interface primitives. The former secondary table is generated when
3937 -- Build_Thunks is True, and provides common support for dispatching
3938 -- calls through interface types; the latter secondary table is
3939 -- generated when Build_Thunks is False, and provides support for
3940 -- Generic Dispatching Constructors that dispatch calls through
3941 -- interface types. When constructing this latter table the value of
3942 -- Suffix_Index is -1 to indicate that there is no need to export such
3943 -- table when building statically allocated dispatch tables; a positive
3944 -- value of Suffix_Index must match the Suffix_Index value assigned to
3945 -- this secondary dispatch table by Make_Tags when its unique external
3946 -- name was generated.
3948 function Number_Of_Predefined_Prims
(Typ
: Entity_Id
) return Nat
;
3949 -- Returns the number of predefined primitives of Typ
3955 procedure Export_DT
(Typ
: Entity_Id
; DT
: Entity_Id
; Index
: Nat
:= 0)
3961 Set_Is_Statically_Allocated
(DT
);
3962 Set_Is_True_Constant
(DT
);
3963 Set_Is_Exported
(DT
);
3966 Elmt
:= First_Elmt
(Dispatch_Table_Wrappers
(Typ
));
3967 while Count
/= Index
loop
3972 -- Related_Type (Node (Elmt)) should be equal to Typ here, but we
3973 -- can't assert that, because it is sometimes false in illegal
3974 -- programs. We can't check Serious_Errors_Detected, because the
3975 -- errors have not yet been detected.
3977 Get_External_Name
(Node
(Elmt
));
3978 Set_Interface_Name
(DT
,
3979 Make_String_Literal
(Loc
,
3980 Strval
=> String_From_Name_Buffer
));
3982 -- Ensure proper Sprint output of this implicit importation
3984 Set_Is_Internal
(DT
);
3988 -----------------------
3989 -- Make_Secondary_DT --
3990 -----------------------
3992 procedure Make_Secondary_DT
3995 Iface_Comp
: Node_Id
;
3997 Num_Iface_Prims
: Nat
;
3998 Iface_DT_Ptr
: Entity_Id
;
3999 Predef_Prims_Ptr
: Entity_Id
;
4000 Build_Thunks
: Boolean;
4003 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
4004 Exporting_Table
: constant Boolean :=
4005 Building_Static_DT
(Typ
)
4006 and then Suffix_Index
> 0;
4007 Iface_DT
: constant Entity_Id
:= Make_Temporary
(Loc
, 'T');
4008 Predef_Prims
: constant Entity_Id
:= Make_Temporary
(Loc
, 'R');
4009 DT_Constr_List
: List_Id
;
4010 DT_Aggr_List
: List_Id
;
4011 Empty_DT
: Boolean := False;
4015 OSD_Aggr_List
: List_Id
;
4017 Prim_Elmt
: Elmt_Id
;
4018 Prim_Ops_Aggr_List
: List_Id
;
4021 -- Handle cases in which we do not generate statically allocated
4024 if not Building_Static_DT
(Typ
) then
4025 Mutate_Ekind
(Predef_Prims
, E_Variable
);
4026 Mutate_Ekind
(Iface_DT
, E_Variable
);
4028 -- Statically allocated dispatch tables and related entities are
4032 Mutate_Ekind
(Predef_Prims
, E_Constant
);
4033 Set_Is_Statically_Allocated
(Predef_Prims
);
4034 Set_Is_True_Constant
(Predef_Prims
);
4036 Mutate_Ekind
(Iface_DT
, E_Constant
);
4037 Set_Is_Statically_Allocated
(Iface_DT
);
4038 Set_Is_True_Constant
(Iface_DT
);
4041 -- Calculate the number of slots of the dispatch table. If the number
4042 -- of primitives of Typ is 0 we reserve a dummy single entry for its
4043 -- DT because at run time the pointer to this dummy entry will be
4046 if Num_Iface_Prims
= 0 then
4050 Nb_Prim
:= Num_Iface_Prims
;
4055 -- Predef_Prims : Address_Array (1 .. Default_Prim_Ops_Count) :=
4056 -- (predef-prim-op-thunk-1'address,
4057 -- predef-prim-op-thunk-2'address,
4059 -- predef-prim-op-thunk-n'address);
4061 -- Create the thunks associated with the predefined primitives and
4062 -- save their entity to fill the aggregate.
4065 Nb_P_Prims
: constant Nat
:= Number_Of_Predefined_Prims
(Typ
);
4066 Prim_Table
: array (Nat
range 1 .. Nb_P_Prims
) of Entity_Id
;
4069 SS_Thunk_Id
: Entity_Id
;
4070 SS_Thunk_Code
: Node_Id
;
4071 Thunk_Id
: Entity_Id
;
4072 Thunk_Code
: List_Id
;
4075 Prim_Ops_Aggr_List
:= New_List
;
4076 Prim_Table
:= (others => Empty
);
4078 if Building_Static_DT
(Typ
) then
4079 Prim_Elmt
:= First_Elmt
(Primitive_Operations
(Typ
));
4080 while Present
(Prim_Elmt
) loop
4081 Prim
:= Node
(Prim_Elmt
);
4083 if Is_Predefined_Dispatching_Operation
(Prim
)
4084 and then not Is_Abstract_Subprogram
(Prim
)
4085 and then not Is_Eliminated
(Prim
)
4086 and then not Generate_SCIL
4087 and then No
(Prim_Table
(UI_To_Int
(DT_Position
(Prim
))))
4089 if not Build_Thunks
then
4090 E
:= Ultimate_Alias
(Prim
);
4091 Expand_Secondary_Stack_Thunk
4092 (E
, SS_Thunk_Id
, SS_Thunk_Code
);
4094 if Present
(SS_Thunk_Id
) then
4096 Append_To
(Result
, SS_Thunk_Code
);
4099 Prim_Table
(UI_To_Int
(DT_Position
(Prim
))) := E
;
4102 Expand_Interface_Thunk
4103 (Prim
, Thunk_Id
, Thunk_Code
, Iface
);
4105 if Present
(Thunk_Id
) then
4106 Append_List_To
(Result
, Thunk_Code
);
4107 Prim_Table
(UI_To_Int
(DT_Position
(Prim
))) :=
4113 Next_Elmt
(Prim_Elmt
);
4117 for J
in Prim_Table
'Range loop
4118 if Present
(Prim_Table
(J
)) then
4120 Unchecked_Convert_To
(RTE
(RE_Prim_Ptr
),
4121 Make_Attribute_Reference
(Loc
,
4122 Prefix
=> New_Occurrence_Of
(Prim_Table
(J
), Loc
),
4123 Attribute_Name
=> Name_Unrestricted_Access
));
4125 New_Node
:= Make_Null
(Loc
);
4128 Append_To
(Prim_Ops_Aggr_List
, New_Node
);
4132 Make_Aggregate
(Loc
, Expressions
=> Prim_Ops_Aggr_List
);
4134 -- Remember aggregates initializing dispatch tables
4136 Append_Elmt
(New_Node
, DT_Aggr
);
4139 Make_Subtype_Declaration
(Loc
,
4140 Defining_Identifier
=> Make_Temporary
(Loc
, 'S'),
4141 Subtype_Indication
=>
4142 New_Occurrence_Of
(RTE
(RE_Address_Array
), Loc
));
4144 Append_To
(Result
, Decl
);
4147 Make_Object_Declaration
(Loc
,
4148 Defining_Identifier
=> Predef_Prims
,
4149 Constant_Present
=> Building_Static_DT
(Typ
),
4150 Aliased_Present
=> True,
4151 Object_Definition
=> New_Occurrence_Of
4152 (Defining_Identifier
(Decl
), Loc
),
4153 Expression
=> New_Node
));
4158 -- OSD : Ada.Tags.Object_Specific_Data (Nb_Prims) :=
4159 -- (OSD_Table => (1 => <value>,
4162 -- for OSD'Alignment use Address'Alignment;
4164 -- Iface_DT : Dispatch_Table (Nb_Prims) :=
4165 -- ([ Signature => <sig-value> ],
4166 -- Tag_Kind => <tag_kind-value>,
4167 -- Predef_Prims => Predef_Prims'Address,
4168 -- Offset_To_Top => 0,
4169 -- OSD => OSD'Address,
4170 -- Prims_Ptr => (prim-op-1'address,
4171 -- prim-op-2'address,
4173 -- prim-op-n'address));
4175 -- Stage 3: Initialize the discriminant and the record components
4177 DT_Constr_List
:= New_List
;
4178 DT_Aggr_List
:= New_List
;
4182 Append_To
(DT_Constr_List
, Make_Integer_Literal
(Loc
, Nb_Prim
));
4183 Append_To
(DT_Aggr_List
, Make_Integer_Literal
(Loc
, Nb_Prim
));
4187 if RTE_Record_Component_Available
(RE_Signature
) then
4188 Append_To
(DT_Aggr_List
,
4189 New_Occurrence_Of
(RTE
(RE_Secondary_DT
), Loc
));
4194 if RTE_Record_Component_Available
(RE_Tag_Kind
) then
4195 Append_To
(DT_Aggr_List
, Tagged_Kind
(Typ
));
4200 Append_To
(DT_Aggr_List
,
4201 Make_Attribute_Reference
(Loc
,
4202 Prefix
=> New_Occurrence_Of
(Predef_Prims
, Loc
),
4203 Attribute_Name
=> Name_Address
));
4205 -- Interface component located at variable offset; the value of
4206 -- Offset_To_Top will be set by the init subprogram.
4208 if No
(Dummy_Object
)
4209 or else Is_Variable_Size_Record
(Etype
(Scope
(Iface_Comp
)))
4211 Append_To
(DT_Aggr_List
, Make_Integer_Literal
(Loc
, 0));
4213 -- Interface component located at fixed offset
4216 Append_To
(DT_Aggr_List
,
4218 Make_Attribute_Reference
(Loc
,
4220 Make_Selected_Component
(Loc
,
4222 New_Occurrence_Of
(Dummy_Object
, Loc
),
4224 New_Occurrence_Of
(Iface_Comp
, Loc
)),
4225 Attribute_Name
=> Name_Position
)));
4228 -- Generate the Object Specific Data table required to dispatch calls
4229 -- through synchronized interfaces.
4232 or else Is_Abstract_Type
(Typ
)
4233 or else Is_Controlled
(Typ
)
4234 or else Restriction_Active
(No_Dispatching_Calls
)
4235 or else not Is_Limited_Type
(Typ
)
4236 or else not Has_Interfaces
(Typ
)
4237 or else not Build_Thunks
4238 or else not RTE_Record_Component_Available
(RE_OSD_Table
)
4240 -- No OSD table required
4242 Append_To
(DT_Aggr_List
,
4243 New_Occurrence_Of
(RTE
(RE_Null_Address
), Loc
));
4246 OSD_Aggr_List
:= New_List
;
4249 Prim_Table
: array (Nat
range 1 .. Nb_Prim
) of Entity_Id
;
4251 Prim_Alias
: Entity_Id
;
4252 Prim_Elmt
: Elmt_Id
;
4256 SS_Thunk_Id
: Entity_Id
;
4257 SS_Thunk_Code
: Node_Id
;
4260 Prim_Table
:= (others => Empty
);
4261 Prim_Alias
:= Empty
;
4264 Prim_Elmt
:= First_Elmt
(Primitive_Operations
(Typ
));
4265 while Present
(Prim_Elmt
) loop
4266 Prim
:= Node
(Prim_Elmt
);
4268 if Present
(Interface_Alias
(Prim
))
4269 and then Find_Dispatching_Type
4270 (Interface_Alias
(Prim
)) = Iface
4272 Prim_Alias
:= Interface_Alias
(Prim
);
4273 E
:= Ultimate_Alias
(Prim
);
4274 Pos
:= UI_To_Int
(DT_Position
(Prim_Alias
));
4276 if No
(Prim_Table
(Pos
)) then
4277 Expand_Secondary_Stack_Thunk
4278 (E
, SS_Thunk_Id
, SS_Thunk_Code
);
4280 if Present
(SS_Thunk_Id
) then
4282 Append_To
(Result
, SS_Thunk_Code
);
4285 Prim_Table
(Pos
) := E
;
4287 Append_To
(OSD_Aggr_List
,
4288 Make_Component_Association
(Loc
,
4289 Choices
=> New_List
(
4290 Make_Integer_Literal
(Loc
,
4291 DT_Position
(Prim_Alias
))),
4293 Make_Integer_Literal
(Loc
,
4294 DT_Position
(Alias
(Prim
)))));
4300 Next_Elmt
(Prim_Elmt
);
4302 pragma Assert
(Count
= Nb_Prim
);
4305 OSD
:= Make_Temporary
(Loc
, 'I');
4308 Make_Object_Declaration
(Loc
,
4309 Defining_Identifier
=> OSD
,
4310 Constant_Present
=> True,
4311 Object_Definition
=>
4312 Make_Subtype_Indication
(Loc
,
4314 New_Occurrence_Of
(RTE
(RE_Object_Specific_Data
), Loc
),
4316 Make_Index_Or_Discriminant_Constraint
(Loc
,
4317 Constraints
=> New_List
(
4318 Make_Integer_Literal
(Loc
, Nb_Prim
)))),
4321 Make_Aggregate
(Loc
,
4322 Component_Associations
=> New_List
(
4323 Make_Component_Association
(Loc
,
4324 Choices
=> New_List
(
4326 (RTE_Record_Component
(RE_OSD_Num_Prims
), Loc
)),
4328 Make_Integer_Literal
(Loc
, Nb_Prim
)),
4330 Make_Component_Association
(Loc
,
4331 Choices
=> New_List
(
4333 (RTE_Record_Component
(RE_OSD_Table
), Loc
)),
4334 Expression
=> Make_Aggregate
(Loc
,
4335 Component_Associations
=> OSD_Aggr_List
))))));
4338 Make_Attribute_Definition_Clause
(Loc
,
4339 Name
=> New_Occurrence_Of
(OSD
, Loc
),
4340 Chars
=> Name_Alignment
,
4342 Make_Attribute_Reference
(Loc
,
4344 New_Occurrence_Of
(RTE
(RE_Integer_Address
), Loc
),
4345 Attribute_Name
=> Name_Alignment
)));
4347 -- In secondary dispatch tables the Typeinfo component contains
4348 -- the address of the Object Specific Data (see a-tags.ads).
4350 Append_To
(DT_Aggr_List
,
4351 Make_Attribute_Reference
(Loc
,
4352 Prefix
=> New_Occurrence_Of
(OSD
, Loc
),
4353 Attribute_Name
=> Name_Address
));
4356 -- Initialize the table of primitive operations
4358 Prim_Ops_Aggr_List
:= New_List
;
4361 Append_To
(Prim_Ops_Aggr_List
, Make_Null
(Loc
));
4363 elsif Is_Abstract_Type
(Typ
)
4364 or else not Building_Static_DT
(Typ
)
4366 for J
in 1 .. Nb_Prim
loop
4367 Append_To
(Prim_Ops_Aggr_List
, Make_Null
(Loc
));
4372 CPP_Nb_Prims
: constant Nat
:= CPP_Num_Prims
(Typ
);
4375 Prim_Table
: array (Nat
range 1 .. Nb_Prim
) of Entity_Id
;
4376 SS_Thunk_Id
: Entity_Id
;
4377 SS_Thunk_Code
: Node_Id
;
4378 Thunk_Id
: Entity_Id
;
4379 Thunk_Code
: List_Id
;
4382 Prim_Table
:= (others => Empty
);
4384 Prim_Elmt
:= First_Elmt
(Primitive_Operations
(Typ
));
4385 while Present
(Prim_Elmt
) loop
4386 Prim
:= Node
(Prim_Elmt
);
4387 E
:= Ultimate_Alias
(Prim
);
4388 Prim_Pos
:= UI_To_Int
(DT_Position
(E
));
4390 -- Do not reference predefined primitives because they are
4391 -- located in a separate dispatch table; skip abstract and
4392 -- eliminated primitives; skip primitives located in the C++
4393 -- part of the dispatch table because their slot is set by
4396 if not Is_Predefined_Dispatching_Operation
(Prim
)
4397 and then Present
(Interface_Alias
(Prim
))
4398 and then not Is_Abstract_Subprogram
(Alias
(Prim
))
4399 and then not Is_Eliminated
(Alias
(Prim
))
4400 and then (not Is_CPP_Class
(Root_Type
(Typ
))
4401 or else Prim_Pos
> CPP_Nb_Prims
)
4402 and then Find_Dispatching_Type
4403 (Interface_Alias
(Prim
)) = Iface
4405 -- Generate the code of the thunk only if the abstract
4406 -- interface type is not an immediate ancestor of
4407 -- Tagged_Type. Otherwise the DT associated with the
4408 -- interface is the primary DT.
4410 and then not Is_Ancestor
(Iface
, Typ
,
4411 Use_Full_View
=> True)
4413 if not Build_Thunks
then
4415 Expand_Secondary_Stack_Thunk
4416 (E
, SS_Thunk_Id
, SS_Thunk_Code
);
4418 if Present
(SS_Thunk_Id
) then
4420 Append_To
(Result
, SS_Thunk_Code
);
4424 UI_To_Int
(DT_Position
(Interface_Alias
(Prim
)));
4425 Prim_Table
(Prim_Pos
) := E
;
4428 Expand_Interface_Thunk
4429 (Prim
, Thunk_Id
, Thunk_Code
, Iface
);
4431 if Present
(Thunk_Id
) then
4433 UI_To_Int
(DT_Position
(Interface_Alias
(Prim
)));
4435 Prim_Table
(Prim_Pos
) := Thunk_Id
;
4436 Append_List_To
(Result
, Thunk_Code
);
4441 Next_Elmt
(Prim_Elmt
);
4444 for J
in Prim_Table
'Range loop
4445 if Present
(Prim_Table
(J
)) then
4447 Unchecked_Convert_To
(RTE
(RE_Prim_Ptr
),
4448 Make_Attribute_Reference
(Loc
,
4449 Prefix
=> New_Occurrence_Of
(Prim_Table
(J
), Loc
),
4450 Attribute_Name
=> Name_Unrestricted_Access
));
4453 New_Node
:= Make_Null
(Loc
);
4456 Append_To
(Prim_Ops_Aggr_List
, New_Node
);
4462 Make_Aggregate
(Loc
,
4463 Expressions
=> Prim_Ops_Aggr_List
);
4465 Append_To
(DT_Aggr_List
, New_Node
);
4467 -- Remember aggregates initializing dispatch tables
4469 Append_Elmt
(New_Node
, DT_Aggr
);
4471 -- Note: Secondary dispatch tables are declared constant only if
4472 -- we can compute their offset field by means of the extra dummy
4473 -- object; otherwise they cannot be declared constant and the
4474 -- Offset_To_Top component is initialized by the IP routine.
4477 Make_Object_Declaration
(Loc
,
4478 Defining_Identifier
=> Iface_DT
,
4479 Aliased_Present
=> True,
4480 Constant_Present
=> Building_Static_Secondary_DT
(Typ
),
4482 Object_Definition
=>
4483 Make_Subtype_Indication
(Loc
,
4484 Subtype_Mark
=> New_Occurrence_Of
4485 (RTE
(RE_Dispatch_Table_Wrapper
), Loc
),
4486 Constraint
=> Make_Index_Or_Discriminant_Constraint
(Loc
,
4487 Constraints
=> DT_Constr_List
)),
4490 Make_Aggregate
(Loc
,
4491 Expressions
=> DT_Aggr_List
)));
4493 if Exporting_Table
then
4494 Export_DT
(Typ
, Iface_DT
, Suffix_Index
);
4496 -- Generate code to create the pointer to the dispatch table
4498 -- Iface_DT_Ptr : Tag := Tag!(DT.Prims_Ptr'Address);
4500 -- Note: This declaration is not added here if the table is exported
4501 -- because in such case Make_Tags has already added this declaration.
4505 Make_Object_Declaration
(Loc
,
4506 Defining_Identifier
=> Iface_DT_Ptr
,
4507 Constant_Present
=> True,
4509 Object_Definition
=>
4510 New_Occurrence_Of
(RTE
(RE_Interface_Tag
), Loc
),
4513 Unchecked_Convert_To
(RTE
(RE_Interface_Tag
),
4514 Make_Attribute_Reference
(Loc
,
4516 Make_Selected_Component
(Loc
,
4517 Prefix
=> New_Occurrence_Of
(Iface_DT
, Loc
),
4520 (RTE_Record_Component
(RE_Prims_Ptr
), Loc
)),
4521 Attribute_Name
=> Name_Address
))));
4525 Make_Object_Declaration
(Loc
,
4526 Defining_Identifier
=> Predef_Prims_Ptr
,
4527 Constant_Present
=> True,
4529 Object_Definition
=>
4530 New_Occurrence_Of
(RTE
(RE_Address
), Loc
),
4533 Make_Attribute_Reference
(Loc
,
4535 Make_Selected_Component
(Loc
,
4536 Prefix
=> New_Occurrence_Of
(Iface_DT
, Loc
),
4539 (RTE_Record_Component
(RE_Predef_Prims
), Loc
)),
4540 Attribute_Name
=> Name_Address
)));
4542 -- Remember entities containing dispatch tables
4544 Append_Elmt
(Predef_Prims
, DT_Decl
);
4545 Append_Elmt
(Iface_DT
, DT_Decl
);
4546 end Make_Secondary_DT
;
4548 --------------------------------
4549 -- Number_Of_Predefined_Prims --
4550 --------------------------------
4552 function Number_Of_Predefined_Prims
(Typ
: Entity_Id
) return Nat
is
4553 Nb_Predef_Prims
: Nat
:= 0;
4556 if not Generate_SCIL
then
4559 Prim_Elmt
: Elmt_Id
;
4563 Prim_Elmt
:= First_Elmt
(Primitive_Operations
(Typ
));
4564 while Present
(Prim_Elmt
) loop
4565 Prim
:= Node
(Prim_Elmt
);
4567 if Is_Predefined_Dispatching_Operation
(Prim
)
4568 and then not Is_Abstract_Subprogram
(Prim
)
4570 Pos
:= UI_To_Int
(DT_Position
(Prim
));
4572 if Pos
> Nb_Predef_Prims
then
4573 Nb_Predef_Prims
:= Pos
;
4577 Next_Elmt
(Prim_Elmt
);
4582 pragma Assert
(Nb_Predef_Prims
<= Max_Predef_Prims
);
4583 return Nb_Predef_Prims
;
4584 end Number_Of_Predefined_Prims
;
4588 Elab_Code
: constant List_Id
:= New_List
;
4589 Result
: constant List_Id
:= New_List
;
4590 Tname
: constant Name_Id
:= Chars
(Typ
);
4592 -- When pragmas Discard_Names and No_Tagged_Streams simultaneously apply
4593 -- we initialize the Expanded_Name and the External_Tag of this tagged
4594 -- type with an empty string. This is useful to avoid exposing entity
4595 -- names at binary level. It can be done when both pragmas apply because
4596 -- (1) Discard_Names allows initializing Expanded_Name with an
4597 -- implementation defined value (Ada RM Section C.5 (7/2)).
4598 -- (2) External_Tag (combined with Internal_Tag) is used for object
4599 -- streaming and No_Tagged_Streams inhibits the generation of
4602 Discard_Names
: constant Boolean :=
4603 Present
(No_Tagged_Streams_Pragma
(Typ
))
4605 (Global_Discard_Names
or else Einfo
.Entities
.Discard_Names
(Typ
));
4607 -- The following name entries are used by Make_DT to generate a number
4608 -- of entities related to a tagged type. These entities may be generated
4609 -- in a scope other than that of the tagged type declaration, and if
4610 -- the entities for two tagged types with the same name happen to be
4611 -- generated in the same scope, we have to take care to use different
4612 -- names. This is achieved by means of a unique serial number appended
4613 -- to each generated entity name.
4615 Name_DT
: constant Name_Id
:=
4616 New_External_Name
(Tname
, 'T', Suffix_Index
=> -1);
4617 Name_Exname
: constant Name_Id
:=
4618 New_External_Name
(Tname
, 'E', Suffix_Index
=> -1);
4619 Name_HT_Link
: constant Name_Id
:=
4620 New_External_Name
(Tname
, 'H', Suffix_Index
=> -1);
4621 Name_Predef_Prims
: constant Name_Id
:=
4622 New_External_Name
(Tname
, 'R', Suffix_Index
=> -1);
4623 Name_SSD
: constant Name_Id
:=
4624 New_External_Name
(Tname
, 'S', Suffix_Index
=> -1);
4625 Name_TSD
: constant Name_Id
:=
4626 New_External_Name
(Tname
, 'B', Suffix_Index
=> -1);
4628 Saved_GM
: constant Ghost_Mode_Type
:= Ghost_Mode
;
4629 Saved_IGR
: constant Node_Id
:= Ignored_Ghost_Region
;
4630 -- Save the Ghost-related attributes to restore on exit
4633 AI_Tag_Elmt
: Elmt_Id
;
4634 AI_Tag_Comp
: Elmt_Id
;
4636 DT_Aggr_List
: List_Id
;
4637 DT_Constr_List
: List_Id
;
4640 HT_Link
: Entity_Id
;
4643 Iface_Table_Node
: Node_Id
;
4644 Name_ITable
: Name_Id
;
4647 Num_Ifaces
: Nat
:= 0;
4648 Parent_Typ
: Entity_Id
;
4649 Predef_Prims
: Entity_Id
;
4651 Prim_Elmt
: Elmt_Id
;
4652 Prim_Ops_Aggr_List
: List_Id
;
4655 Typ_Comps
: Elist_Id
;
4656 Typ_Ifaces
: Elist_Id
;
4658 TSD_Aggr_List
: List_Id
;
4659 TSD_Tags_List
: List_Id
;
4661 -- Start of processing for Make_DT
4664 pragma Assert
(Is_Frozen
(Typ
));
4666 -- The tagged type being processed may be subject to pragma Ghost. Set
4667 -- the mode now to ensure that any nodes generated during dispatch table
4668 -- creation are properly marked as Ghost.
4670 Set_Ghost_Mode
(Typ
);
4672 -- Handle cases in which there is no need to build the dispatch table
4674 if Has_Dispatch_Table
(Typ
)
4675 or else No
(Access_Disp_Table
(Typ
))
4676 or else Is_CPP_Class
(Typ
)
4680 elsif No_Run_Time_Mode
then
4681 Error_Msg_CRT
("tagged types", Typ
);
4684 elsif not RTE_Available
(RE_Tag
) then
4686 Make_Object_Declaration
(Loc
,
4687 Defining_Identifier
=>
4688 Node
(First_Elmt
(Access_Disp_Table
(Typ
))),
4689 Object_Definition
=> New_Occurrence_Of
(RTE
(RE_Tag
), Loc
),
4690 Constant_Present
=> True,
4692 Unchecked_Convert_To
(RTE
(RE_Tag
),
4693 New_Occurrence_Of
(RTE
(RE_Null_Address
), Loc
))));
4695 Analyze_List
(Result
, Suppress
=> All_Checks
);
4696 Error_Msg_CRT
("tagged types", Typ
);
4700 -- Ensure that the value of Max_Predef_Prims defined in a-tags is
4701 -- correct. Valid values are 10 under configurable runtime or 16
4702 -- with full runtime.
4704 if RTE_Available
(RE_Interface_Data
) then
4705 if Max_Predef_Prims
/= 16 then
4706 Error_Msg_N
("run-time library configuration error", Typ
);
4710 if Max_Predef_Prims
/= 10 then
4711 Error_Msg_N
("run-time library configuration error", Typ
);
4712 Error_Msg_CRT
("tagged types", Typ
);
4717 DT
:= Make_Defining_Identifier
(Loc
, Name_DT
);
4718 Exname
:= Make_Defining_Identifier
(Loc
, Name_Exname
);
4719 HT_Link
:= Make_Defining_Identifier
(Loc
, Name_HT_Link
);
4720 Predef_Prims
:= Make_Defining_Identifier
(Loc
, Name_Predef_Prims
);
4721 SSD
:= Make_Defining_Identifier
(Loc
, Name_SSD
);
4722 TSD
:= Make_Defining_Identifier
(Loc
, Name_TSD
);
4724 -- Initialize Parent_Typ handling private types
4726 Parent_Typ
:= Etype
(Typ
);
4728 if Present
(Full_View
(Parent_Typ
)) then
4729 Parent_Typ
:= Full_View
(Parent_Typ
);
4732 if not Is_Interface
(Typ
) and then Has_Interfaces
(Typ
) then
4734 Cannot_Have_Null_Disc
: Boolean := False;
4735 Dummy_Object_Typ
: constant Entity_Id
:= Typ
;
4736 Name_Dummy_Object
: constant Name_Id
:=
4737 New_External_Name
(Tname
,
4738 'P', Suffix_Index
=> -1);
4740 Dummy_Object
:= Make_Defining_Identifier
(Loc
, Name_Dummy_Object
);
4742 -- Define the extra object imported and constant to avoid linker
4743 -- errors (since this object is never declared). Required because
4744 -- we implement RM 13.3(19) for exported and imported (variable)
4745 -- objects by making them volatile.
4747 Set_Is_Imported
(Dummy_Object
);
4748 Mutate_Ekind
(Dummy_Object
, E_Constant
);
4749 Set_Is_True_Constant
(Dummy_Object
);
4750 Set_Related_Type
(Dummy_Object
, Typ
);
4752 -- The scope must be set now to call Get_External_Name
4754 Set_Scope
(Dummy_Object
, Current_Scope
);
4756 Get_External_Name
(Dummy_Object
);
4757 Set_Interface_Name
(Dummy_Object
,
4758 Make_String_Literal
(Loc
, Strval
=> String_From_Name_Buffer
));
4760 -- Ensure proper Sprint output of this implicit importation
4762 Set_Is_Internal
(Dummy_Object
);
4764 if not Has_Discriminants
(Dummy_Object_Typ
) then
4766 Make_Object_Declaration
(Loc
,
4767 Defining_Identifier
=> Dummy_Object
,
4768 Constant_Present
=> True,
4769 Object_Definition
=> New_Occurrence_Of
4770 (Dummy_Object_Typ
, Loc
)));
4773 Constr_List
: constant List_Id
:= New_List
;
4777 Discrim
:= First_Discriminant
(Dummy_Object_Typ
);
4778 while Present
(Discrim
) loop
4779 if Is_Discrete_Type
(Etype
(Discrim
)) then
4780 Append_To
(Constr_List
,
4781 Make_Attribute_Reference
(Loc
,
4783 New_Occurrence_Of
(Etype
(Discrim
), Loc
),
4784 Attribute_Name
=> Name_First
));
4787 pragma Assert
(Is_Access_Type
(Etype
(Discrim
)));
4788 Cannot_Have_Null_Disc
:=
4789 Cannot_Have_Null_Disc
4790 or else Can_Never_Be_Null
(Etype
(Discrim
));
4791 Append_To
(Constr_List
, Make_Null
(Loc
));
4794 Next_Discriminant
(Discrim
);
4798 Make_Object_Declaration
(Loc
,
4799 Defining_Identifier
=> Dummy_Object
,
4800 Constant_Present
=> True,
4801 Object_Definition
=>
4802 Make_Subtype_Indication
(Loc
,
4804 New_Occurrence_Of
(Dummy_Object_Typ
, Loc
),
4806 Make_Index_Or_Discriminant_Constraint
(Loc
,
4807 Constraints
=> Constr_List
))));
4811 -- Given that the dummy object will not be declared at run time,
4812 -- analyze its declaration with expansion disabled and warnings
4813 -- and error messages ignored.
4815 Expander_Mode_Save_And_Set
(False);
4816 Ignore_Errors_Enable
:= Ignore_Errors_Enable
+ 1;
4817 Analyze
(Last
(Result
), Suppress
=> All_Checks
);
4818 Ignore_Errors_Enable
:= Ignore_Errors_Enable
- 1;
4819 Expander_Mode_Restore
;
4823 -- Ada 2005 (AI-251): Build the secondary dispatch tables
4825 if Has_Interfaces
(Typ
) then
4826 Collect_Interface_Components
(Typ
, Typ_Comps
);
4828 -- Each secondary dispatch table is assigned an unique positive
4829 -- suffix index; such value also corresponds with the location of
4830 -- its entity in the Dispatch_Table_Wrappers list (see Make_Tags).
4832 -- Note: This value must be kept sync with the Suffix_Index values
4833 -- generated by Make_Tags
4837 Next_Elmt
(Next_Elmt
(First_Elmt
(Access_Disp_Table
(Typ
))));
4839 AI_Tag_Comp
:= First_Elmt
(Typ_Comps
);
4840 while Present
(AI_Tag_Comp
) loop
4841 pragma Assert
(Has_Suffix
(Node
(AI_Tag_Elmt
), 'P'));
4843 -- Build the secondary table containing pointers to thunks
4848 Base_Type
(Related_Type
(Node
(AI_Tag_Comp
))),
4849 Iface_Comp
=> Node
(AI_Tag_Comp
),
4850 Suffix_Index
=> Suffix_Index
,
4852 UI_To_Int
(DT_Entry_Count
(Node
(AI_Tag_Comp
))),
4853 Iface_DT_Ptr
=> Node
(AI_Tag_Elmt
),
4854 Predef_Prims_Ptr
=> Node
(Next_Elmt
(AI_Tag_Elmt
)),
4855 Build_Thunks
=> True,
4858 -- Skip secondary dispatch table referencing thunks to predefined
4861 Next_Elmt
(AI_Tag_Elmt
);
4862 pragma Assert
(Has_Suffix
(Node
(AI_Tag_Elmt
), 'Y'));
4864 -- Secondary dispatch table referencing user-defined primitives
4865 -- covered by this interface.
4867 Next_Elmt
(AI_Tag_Elmt
);
4868 pragma Assert
(Has_Suffix
(Node
(AI_Tag_Elmt
), 'D'));
4870 -- Build the secondary table containing pointers to primitives
4871 -- (used to give support to Generic Dispatching Constructors).
4876 (Related_Type
(Node
(AI_Tag_Comp
))),
4877 Iface_Comp
=> Node
(AI_Tag_Comp
),
4879 Num_Iface_Prims
=> UI_To_Int
4880 (DT_Entry_Count
(Node
(AI_Tag_Comp
))),
4881 Iface_DT_Ptr
=> Node
(AI_Tag_Elmt
),
4882 Predef_Prims_Ptr
=> Node
(Next_Elmt
(AI_Tag_Elmt
)),
4883 Build_Thunks
=> False,
4886 -- Skip secondary dispatch table referencing predefined primitives
4888 Next_Elmt
(AI_Tag_Elmt
);
4889 pragma Assert
(Has_Suffix
(Node
(AI_Tag_Elmt
), 'Z'));
4891 Suffix_Index
:= Suffix_Index
+ 1;
4892 Next_Elmt
(AI_Tag_Elmt
);
4893 Next_Elmt
(AI_Tag_Comp
);
4897 -- Get the _tag entity and number of primitives of its dispatch table
4899 DT_Ptr
:= Node
(First_Elmt
(Access_Disp_Table
(Typ
)));
4900 Nb_Prim
:= UI_To_Int
(DT_Entry_Count
(First_Tag_Component
(Typ
)));
4902 if Generate_SCIL
then
4906 Set_Is_Statically_Allocated
(DT
, Is_Library_Level_Tagged_Type
(Typ
));
4907 Set_Is_Statically_Allocated
(SSD
, Is_Library_Level_Tagged_Type
(Typ
));
4908 Set_Is_Statically_Allocated
(TSD
, Is_Library_Level_Tagged_Type
(Typ
));
4909 Set_Is_Statically_Allocated
(Predef_Prims
,
4910 Is_Library_Level_Tagged_Type
(Typ
));
4912 -- In case of locally defined tagged type we declare the object
4913 -- containing the dispatch table by means of a variable. Its
4914 -- initialization is done later by means of an assignment. This is
4915 -- required to generate its External_Tag.
4917 if not Building_Static_DT
(Typ
) then
4920 -- DT : No_Dispatch_Table_Wrapper;
4921 -- DT_Ptr : Tag := !Tag (DT.NDT_Prims_Ptr'Address);
4923 if not Has_DT
(Typ
) then
4925 Make_Object_Declaration
(Loc
,
4926 Defining_Identifier
=> DT
,
4927 Aliased_Present
=> True,
4928 Constant_Present
=> False,
4929 Object_Definition
=>
4931 (RTE
(RE_No_Dispatch_Table_Wrapper
), Loc
)));
4934 Make_Object_Declaration
(Loc
,
4935 Defining_Identifier
=> DT_Ptr
,
4936 Object_Definition
=> New_Occurrence_Of
(RTE
(RE_Tag
), Loc
),
4937 Constant_Present
=> True,
4939 Unchecked_Convert_To
(RTE
(RE_Tag
),
4940 Make_Attribute_Reference
(Loc
,
4942 Make_Selected_Component
(Loc
,
4943 Prefix
=> New_Occurrence_Of
(DT
, Loc
),
4946 (RTE_Record_Component
(RE_NDT_Prims_Ptr
), Loc
)),
4947 Attribute_Name
=> Name_Address
))));
4949 Set_Is_Statically_Allocated
(DT_Ptr
,
4950 Is_Library_Level_Tagged_Type
(Typ
));
4952 -- Generate the SCIL node for the previous object declaration
4953 -- because it has a tag initialization.
4955 if Generate_SCIL
then
4957 Make_SCIL_Dispatch_Table_Tag_Init
(Sloc
(Last
(Result
)));
4958 Set_SCIL_Entity
(New_Node
, Typ
);
4959 Set_SCIL_Node
(Last
(Result
), New_Node
);
4963 -- Gnat2scil has its own implementation of dispatch tables,
4964 -- different than what is being implemented here. Generating
4965 -- further dispatch table initialization code would just
4966 -- cause gnat2scil to generate useless Scil which CodePeer
4967 -- would waste time and space analyzing, so we skip it.
4971 -- DT : Dispatch_Table_Wrapper (Nb_Prim);
4972 -- DT_Ptr : Tag := !Tag (DT.Prims_Ptr'Address);
4975 -- If the tagged type has no primitives we add a dummy slot
4976 -- whose address will be the tag of this type.
4980 New_List
(Make_Integer_Literal
(Loc
, 1));
4983 New_List
(Make_Integer_Literal
(Loc
, Nb_Prim
));
4987 Make_Object_Declaration
(Loc
,
4988 Defining_Identifier
=> DT
,
4989 Aliased_Present
=> True,
4990 Constant_Present
=> False,
4991 Object_Definition
=>
4992 Make_Subtype_Indication
(Loc
,
4994 New_Occurrence_Of
(RTE
(RE_Dispatch_Table_Wrapper
), Loc
),
4996 Make_Index_Or_Discriminant_Constraint
(Loc
,
4997 Constraints
=> DT_Constr_List
))));
5000 Make_Object_Declaration
(Loc
,
5001 Defining_Identifier
=> DT_Ptr
,
5002 Object_Definition
=> New_Occurrence_Of
(RTE
(RE_Tag
), Loc
),
5003 Constant_Present
=> True,
5005 Unchecked_Convert_To
(RTE
(RE_Tag
),
5006 Make_Attribute_Reference
(Loc
,
5008 Make_Selected_Component
(Loc
,
5009 Prefix
=> New_Occurrence_Of
(DT
, Loc
),
5012 (RTE_Record_Component
(RE_Prims_Ptr
), Loc
)),
5013 Attribute_Name
=> Name_Address
))));
5015 Set_Is_Statically_Allocated
(DT_Ptr
,
5016 Is_Library_Level_Tagged_Type
(Typ
));
5018 -- Generate the SCIL node for the previous object declaration
5019 -- because it has a tag initialization.
5021 if Generate_SCIL
then
5023 Make_SCIL_Dispatch_Table_Tag_Init
(Sloc
(Last
(Result
)));
5024 Set_SCIL_Entity
(New_Node
, Typ
);
5025 Set_SCIL_Node
(Last
(Result
), New_Node
);
5029 -- Gnat2scil has its own implementation of dispatch tables,
5030 -- different than what is being implemented here. Generating
5031 -- further dispatch table initialization code would just
5032 -- cause gnat2scil to generate useless Scil which CodePeer
5033 -- would waste time and space analyzing, so we skip it.
5037 Make_Object_Declaration
(Loc
,
5038 Defining_Identifier
=>
5039 Node
(Next_Elmt
(First_Elmt
(Access_Disp_Table
(Typ
)))),
5040 Constant_Present
=> True,
5041 Object_Definition
=>
5042 New_Occurrence_Of
(RTE
(RE_Address
), Loc
),
5044 Make_Attribute_Reference
(Loc
,
5046 Make_Selected_Component
(Loc
,
5047 Prefix
=> New_Occurrence_Of
(DT
, Loc
),
5050 (RTE_Record_Component
(RE_Predef_Prims
), Loc
)),
5051 Attribute_Name
=> Name_Address
)));
5055 -- Generate: Expanded_Name : constant String := "";
5057 if Discard_Names
then
5059 Make_Object_Declaration
(Loc
,
5060 Defining_Identifier
=> Exname
,
5061 Constant_Present
=> True,
5062 Object_Definition
=> New_Occurrence_Of
(Standard_String
, Loc
),
5064 Make_String_Literal
(Loc
, "")));
5066 -- Generate: Exname : constant String := full_qualified_name (typ);
5067 -- The type itself may be an anonymous parent type, so use the first
5068 -- subtype to have a user-recognizable name.
5072 Make_Object_Declaration
(Loc
,
5073 Defining_Identifier
=> Exname
,
5074 Constant_Present
=> True,
5075 Object_Definition
=> New_Occurrence_Of
(Standard_String
, Loc
),
5077 Make_String_Literal
(Loc
,
5078 Fully_Qualified_Name_String
(First_Subtype
(Typ
)))));
5081 Set_Is_Statically_Allocated
(Exname
);
5082 Set_Is_True_Constant
(Exname
);
5084 -- Declare the object used by Ada.Tags.Register_Tag, unless
5085 -- No_Tagged_Type_Registration is active.
5087 if not Restriction_Active
(No_Tagged_Type_Registration
)
5088 and then RTE_Available
(RE_Register_Tag
)
5091 Make_Object_Declaration
(Loc
,
5092 Defining_Identifier
=> HT_Link
,
5093 Object_Definition
=> New_Occurrence_Of
(RTE
(RE_Tag
), Loc
),
5094 Expression
=> New_Occurrence_Of
(RTE
(RE_No_Tag
), Loc
)));
5097 -- Generate code to create the storage for the type specific data object
5098 -- with enough space to store the tags of the ancestors plus the tags
5099 -- of all the implemented interfaces (as described in a-tags.adb).
5101 -- TSD : Type_Specific_Data (I_Depth) :=
5102 -- (Idepth => I_Depth,
5103 -- Access_Level => Type_Access_Level (Typ),
5104 -- Alignment => Typ'Alignment,
5105 -- Expanded_Name => Cstring_Ptr!(Exname'Address))
5106 -- External_Tag => Cstring_Ptr!(Exname'Address))
5107 -- HT_Link => HT_Link'Address,
5108 -- Transportable => <<boolean-value>>,
5109 -- Is_Abstract => <<boolean-value>>,
5110 -- Needs_Finalization => <<boolean-value>>,
5111 -- [ Size_Func => Size_Prim'Access, ]
5112 -- [ Interfaces_Table => <<access-value>>, ]
5113 -- [ SSD => SSD_Table'Address ]
5114 -- Tags_Table => (0 => null,
5118 TSD_Aggr_List
:= New_List
;
5120 -- Idepth: Count ancestors to compute the inheritance depth. For private
5121 -- extensions, always go to the full view in order to compute the real
5122 -- inheritance depth.
5125 Current_Typ
: Entity_Id
;
5126 Parent_Typ
: Entity_Id
;
5132 Parent_Typ
:= Etype
(Current_Typ
);
5134 if Is_Private_Type
(Parent_Typ
) then
5135 Parent_Typ
:= Full_View
(Base_Type
(Parent_Typ
));
5138 exit when Parent_Typ
= Current_Typ
;
5140 I_Depth
:= I_Depth
+ 1;
5141 Current_Typ
:= Parent_Typ
;
5145 Append_To
(TSD_Aggr_List
,
5146 Make_Integer_Literal
(Loc
, I_Depth
));
5150 Append_To
(TSD_Aggr_List
,
5151 Make_Integer_Literal
(Loc
, Type_Access_Level
(Typ
)));
5155 -- For CPP types we cannot rely on the value of 'Alignment provided
5156 -- by the backend to initialize this TSD field.
5158 if Convention
(Typ
) = Convention_CPP
5159 or else Is_CPP_Class
(Root_Type
(Typ
))
5161 Append_To
(TSD_Aggr_List
,
5162 Make_Integer_Literal
(Loc
, 0));
5164 Append_To
(TSD_Aggr_List
,
5165 Make_Attribute_Reference
(Loc
,
5166 Prefix
=> New_Occurrence_Of
(Typ
, Loc
),
5167 Attribute_Name
=> Name_Alignment
));
5172 Append_To
(TSD_Aggr_List
,
5173 Unchecked_Convert_To
(RTE
(RE_Cstring_Ptr
),
5174 Make_Attribute_Reference
(Loc
,
5175 Prefix
=> New_Occurrence_Of
(Exname
, Loc
),
5176 Attribute_Name
=> Name_Address
)));
5178 -- External_Tag of a local tagged type
5180 -- <typ>A : constant String :=
5181 -- "Internal tag at 16#tag-addr#: <full-name-of-typ>";
5183 -- The reason we generate this strange name is that we do not want to
5184 -- enter local tagged types in the global hash table used to compute
5185 -- the Internal_Tag attribute for two reasons:
5187 -- 1. It is hard to avoid a tasking race condition for entering the
5188 -- entry into the hash table.
5190 -- 2. It would cause a storage leak, unless we rig up considerable
5191 -- mechanism to remove the entry from the hash table on exit.
5193 -- So what we do is to generate the above external tag name, where the
5194 -- hex address is the address of the local dispatch table (i.e. exactly
5195 -- the value we want if Internal_Tag is computed from this string).
5197 -- Of course this value will only be valid if the tagged type is still
5198 -- in scope, but it clearly must be erroneous to compute the internal
5199 -- tag of a tagged type that is out of scope.
5201 -- We don't do this processing if an explicit external tag has been
5202 -- specified. That's an odd case for which we have already issued a
5203 -- warning, where we will not be able to compute the internal tag.
5205 if not Discard_Names
5206 and then not Is_Library_Level_Entity
(Typ
)
5207 and then not Has_External_Tag_Rep_Clause
(Typ
)
5210 Exname
: constant Entity_Id
:=
5211 Make_Defining_Identifier
(Loc
,
5212 Chars
=> New_External_Name
(Tname
, 'A'));
5213 Full_Name
: constant String_Id
:=
5214 Fully_Qualified_Name_String
(First_Subtype
(Typ
));
5215 Str1_Id
: String_Id
;
5216 Str2_Id
: String_Id
;
5220 -- Str1 = "Internal tag at 16#";
5223 Store_String_Chars
("Internal tag at 16#");
5224 Str1_Id
:= End_String
;
5227 -- Str2 = "#: <type-full-name>";
5230 Store_String_Chars
("#: ");
5231 Store_String_Chars
(Full_Name
);
5232 Str2_Id
:= End_String
;
5235 -- Exname : constant String :=
5236 -- Str1 & Address_Image (Tag) & Str2;
5238 if RTE_Available
(RE_Address_Image
) then
5240 Make_Object_Declaration
(Loc
,
5241 Defining_Identifier
=> Exname
,
5242 Constant_Present
=> True,
5243 Object_Definition
=> New_Occurrence_Of
5244 (Standard_String
, Loc
),
5246 Make_Op_Concat
(Loc
,
5247 Left_Opnd
=> Make_String_Literal
(Loc
, Str1_Id
),
5249 Make_Op_Concat
(Loc
,
5251 Make_Function_Call
(Loc
,
5254 (RTE
(RE_Address_Image
), Loc
),
5255 Parameter_Associations
=> New_List
(
5256 Unchecked_Convert_To
(RTE
(RE_Address
),
5257 New_Occurrence_Of
(DT_Ptr
, Loc
)))),
5259 Make_String_Literal
(Loc
, Str2_Id
)))));
5262 -- Exname : constant String := Str1 & Str2;
5266 Make_Object_Declaration
(Loc
,
5267 Defining_Identifier
=> Exname
,
5268 Constant_Present
=> True,
5269 Object_Definition
=>
5270 New_Occurrence_Of
(Standard_String
, Loc
),
5272 Make_Op_Concat
(Loc
,
5273 Left_Opnd
=> Make_String_Literal
(Loc
, Str1_Id
),
5274 Right_Opnd
=> Make_String_Literal
(Loc
, Str2_Id
))));
5278 Unchecked_Convert_To
(RTE
(RE_Cstring_Ptr
),
5279 Make_Attribute_Reference
(Loc
,
5280 Prefix
=> New_Occurrence_Of
(Exname
, Loc
),
5281 Attribute_Name
=> Name_Address
));
5284 -- External tag of a library-level tagged type: Check for a definition
5285 -- of External_Tag. The clause is considered only if it applies to this
5286 -- specific tagged type, as opposed to one of its ancestors.
5287 -- If the type is an unconstrained type extension, we are building the
5288 -- dispatch table of its anonymous base type, so the external tag, if
5289 -- any was specified, must be retrieved from the first subtype. Go to
5290 -- the full view in case the clause is in the private part.
5294 Def
: constant Node_Id
:= Get_Attribute_Definition_Clause
5295 (Underlying_Type
(First_Subtype
(Typ
)),
5296 Attribute_External_Tag
);
5298 Old_Val
: String_Id
;
5299 New_Val
: String_Id
;
5304 or else Entity
(Name
(Def
)) /= First_Subtype
(Typ
)
5307 Unchecked_Convert_To
(RTE
(RE_Cstring_Ptr
),
5308 Make_Attribute_Reference
(Loc
,
5309 Prefix
=> New_Occurrence_Of
(Exname
, Loc
),
5310 Attribute_Name
=> Name_Address
));
5312 Old_Val
:= Strval
(Expr_Value_S
(Expression
(Def
)));
5314 -- For the rep clause "for <typ>'external_tag use y" generate:
5316 -- <typ>A : constant string := y;
5318 -- <typ>A'Address is used to set the External_Tag component
5321 -- Create a new nul terminated string if it is not already
5323 if String_Length
(Old_Val
) > 0
5325 Get_String_Char
(Old_Val
, String_Length
(Old_Val
)) = 0
5329 Start_String
(Old_Val
);
5330 Store_String_Char
(Get_Char_Code
(ASCII
.NUL
));
5331 New_Val
:= End_String
;
5334 E
:= Make_Defining_Identifier
(Loc
,
5335 New_External_Name
(Chars
(Typ
), 'A'));
5338 Make_Object_Declaration
(Loc
,
5339 Defining_Identifier
=> E
,
5340 Constant_Present
=> True,
5341 Object_Definition
=>
5342 New_Occurrence_Of
(Standard_String
, Loc
),
5344 Make_String_Literal
(Loc
, New_Val
)));
5347 Unchecked_Convert_To
(RTE
(RE_Cstring_Ptr
),
5348 Make_Attribute_Reference
(Loc
,
5349 Prefix
=> New_Occurrence_Of
(E
, Loc
),
5350 Attribute_Name
=> Name_Address
));
5355 Append_To
(TSD_Aggr_List
, New_Node
);
5359 if not Restriction_Active
(No_Tagged_Type_Registration
)
5360 and then RTE_Available
(RE_Register_Tag
)
5362 Append_To
(TSD_Aggr_List
,
5363 Unchecked_Convert_To
(RTE
(RE_Tag_Ptr
),
5364 Make_Attribute_Reference
(Loc
,
5365 Prefix
=> New_Occurrence_Of
(HT_Link
, Loc
),
5366 Attribute_Name
=> Name_Address
)));
5368 elsif RTE_Record_Component_Available
(RE_HT_Link
) then
5369 Append_To
(TSD_Aggr_List
,
5370 Unchecked_Convert_To
(RTE
(RE_Tag_Ptr
),
5371 New_Occurrence_Of
(RTE
(RE_Null_Address
), Loc
)));
5374 -- Transportable: Set for types that can be used in remote calls
5375 -- with respect to E.4(18) legality rules.
5378 Transportable
: Entity_Id
;
5384 or else Is_Shared_Passive
(Typ
)
5386 ((Is_Remote_Types
(Typ
)
5387 or else Is_Remote_Call_Interface
(Typ
))
5388 and then Original_View_In_Visible_Part
(Typ
))
5389 or else not Comes_From_Source
(Typ
));
5391 Append_To
(TSD_Aggr_List
,
5392 New_Occurrence_Of
(Transportable
, Loc
));
5395 -- Is_Abstract (Ada 2012: AI05-0173). This functionality is not
5396 -- available in the HIE runtime.
5398 if RTE_Record_Component_Available
(RE_Is_Abstract
) then
5400 Is_Abstract
: Entity_Id
;
5402 Is_Abstract
:= Boolean_Literals
(Is_Abstract_Type
(Typ
));
5403 Append_To
(TSD_Aggr_List
,
5404 New_Occurrence_Of
(Is_Abstract
, Loc
));
5408 -- Needs_Finalization: Set if the type is controlled or has controlled
5412 Needs_Fin
: Entity_Id
;
5414 Needs_Fin
:= Boolean_Literals
(Needs_Finalization
(Typ
));
5415 Append_To
(TSD_Aggr_List
, New_Occurrence_Of
(Needs_Fin
, Loc
));
5420 if RTE_Record_Component_Available
(RE_Size_Func
) then
5422 -- Initialize this field to Null_Address if we are not building
5423 -- static dispatch tables static or if the size function is not
5424 -- available. In the former case we cannot initialize this field
5425 -- until the function is frozen and registered in the dispatch
5426 -- table (see Register_Primitive).
5428 if not Building_Static_DT
(Typ
) or else not Has_DT
(Typ
) then
5429 Append_To
(TSD_Aggr_List
,
5430 Unchecked_Convert_To
(RTE
(RE_Size_Ptr
),
5431 New_Occurrence_Of
(RTE
(RE_Null_Address
), Loc
)));
5435 Prim_Elmt
: Elmt_Id
;
5437 Size_Comp
: Node_Id
:= Empty
;
5440 Prim_Elmt
:= First_Elmt
(Primitive_Operations
(Typ
));
5441 while Present
(Prim_Elmt
) loop
5442 Prim
:= Node
(Prim_Elmt
);
5444 if Chars
(Prim
) = Name_uSize
then
5445 Prim
:= Ultimate_Alias
(Prim
);
5447 if Is_Abstract_Subprogram
(Prim
) then
5449 Unchecked_Convert_To
(RTE
(RE_Size_Ptr
),
5450 New_Occurrence_Of
(RTE
(RE_Null_Address
), Loc
));
5453 Unchecked_Convert_To
(RTE
(RE_Size_Ptr
),
5454 Make_Attribute_Reference
(Loc
,
5455 Prefix
=> New_Occurrence_Of
(Prim
, Loc
),
5456 Attribute_Name
=> Name_Unrestricted_Access
));
5462 Next_Elmt
(Prim_Elmt
);
5465 pragma Assert
(Present
(Size_Comp
));
5466 Append_To
(TSD_Aggr_List
, Size_Comp
);
5471 -- Interfaces_Table (required for AI-405)
5473 if RTE_Record_Component_Available
(RE_Interfaces_Table
) then
5475 -- Count the number of interface types implemented by Typ
5477 Collect_Interfaces
(Typ
, Typ_Ifaces
);
5479 AI
:= First_Elmt
(Typ_Ifaces
);
5480 while Present
(AI
) loop
5481 Num_Ifaces
:= Num_Ifaces
+ 1;
5485 if Num_Ifaces
= 0 then
5486 Iface_Table_Node
:= Make_Null
(Loc
);
5488 -- Generate the Interface_Table object
5492 TSD_Ifaces_List
: constant List_Id
:= New_List
;
5494 Offset_To_Top
: Node_Id
;
5495 Sec_DT_Tag
: Node_Id
;
5497 Dummy_Object_Ifaces_List
: Elist_Id
:= No_Elist
;
5498 Dummy_Object_Ifaces_Comp_List
: Elist_Id
:= No_Elist
;
5499 Dummy_Object_Ifaces_Tag_List
: Elist_Id
:= No_Elist
;
5500 -- Interfaces information of the dummy object
5503 -- Collect interfaces information if we need to compute the
5504 -- offset to the top using the dummy object.
5506 if Present
(Dummy_Object
) then
5507 Collect_Interfaces_Info
(Typ
,
5508 Ifaces_List
=> Dummy_Object_Ifaces_List
,
5509 Components_List
=> Dummy_Object_Ifaces_Comp_List
,
5510 Tags_List
=> Dummy_Object_Ifaces_Tag_List
);
5513 AI
:= First_Elmt
(Typ_Ifaces
);
5514 while Present
(AI
) loop
5515 if Is_Ancestor
(Node
(AI
), Typ
, Use_Full_View
=> True) then
5516 Sec_DT_Tag
:= New_Occurrence_Of
(DT_Ptr
, Loc
);
5521 (Next_Elmt
(First_Elmt
(Access_Disp_Table
(Typ
))));
5522 pragma Assert
(Has_Thunks
(Node
(Elmt
)));
5524 while Is_Tag
(Node
(Elmt
))
5526 Is_Ancestor
(Node
(AI
), Related_Type
(Node
(Elmt
)),
5527 Use_Full_View
=> True)
5529 pragma Assert
(Has_Thunks
(Node
(Elmt
)));
5531 pragma Assert
(Has_Thunks
(Node
(Elmt
)));
5533 pragma Assert
(not Has_Thunks
(Node
(Elmt
)));
5535 pragma Assert
(not Has_Thunks
(Node
(Elmt
)));
5539 pragma Assert
(Ekind
(Node
(Elmt
)) = E_Constant
5541 Has_Thunks
(Node
(Next_Elmt
(Next_Elmt
(Elmt
)))));
5545 (Node
(Next_Elmt
(Next_Elmt
(Elmt
))), Loc
);
5548 -- Use the dummy object to compute Offset_To_Top of
5549 -- components located at fixed position.
5551 if Present
(Dummy_Object
) then
5553 Iface
: constant Node_Id
:= Node
(AI
);
5554 Iface_Comp
: Node_Id
:= Empty
;
5555 Iface_Comp_Elmt
: Elmt_Id
;
5556 Iface_Elmt
: Elmt_Id
;
5560 First_Elmt
(Dummy_Object_Ifaces_List
);
5562 First_Elmt
(Dummy_Object_Ifaces_Comp_List
);
5564 while Present
(Iface_Elmt
) loop
5565 if Node
(Iface_Elmt
) = Iface
then
5566 Iface_Comp
:= Node
(Iface_Comp_Elmt
);
5570 Next_Elmt
(Iface_Elmt
);
5571 Next_Elmt
(Iface_Comp_Elmt
);
5574 pragma Assert
(Present
(Iface_Comp
));
5577 Is_Variable_Size_Record
(Etype
(Scope
(Iface_Comp
)))
5581 Make_Attribute_Reference
(Loc
,
5583 Make_Selected_Component
(Loc
,
5585 New_Occurrence_Of
(Dummy_Object
, Loc
),
5587 New_Occurrence_Of
(Iface_Comp
, Loc
)),
5588 Attribute_Name
=> Name_Position
));
5590 Offset_To_Top
:= Make_Integer_Literal
(Loc
, 0);
5594 Offset_To_Top
:= Make_Integer_Literal
(Loc
, 0);
5597 Append_To
(TSD_Ifaces_List
,
5598 Make_Aggregate
(Loc
,
5599 Expressions
=> New_List
(
5603 Unchecked_Convert_To
(RTE
(RE_Tag
),
5605 (Node
(First_Elmt
(Access_Disp_Table
(Node
(AI
)))),
5608 -- Static_Offset_To_Top
5610 New_Occurrence_Of
(Standard_True
, Loc
),
5612 -- Offset_To_Top_Value
5616 -- Offset_To_Top_Func
5622 Unchecked_Convert_To
(RTE
(RE_Tag
), Sec_DT_Tag
))));
5627 Name_ITable
:= New_External_Name
(Tname
, 'I');
5628 ITable
:= Make_Defining_Identifier
(Loc
, Name_ITable
);
5629 Set_Is_Statically_Allocated
(ITable
,
5630 Is_Library_Level_Tagged_Type
(Typ
));
5632 -- The table of interfaces is constant if we are building a
5633 -- static dispatch table; otherwise is not constant because
5634 -- its slots are filled at run time by the IP routine.
5637 Make_Object_Declaration
(Loc
,
5638 Defining_Identifier
=> ITable
,
5639 Aliased_Present
=> True,
5640 Constant_Present
=> Building_Static_Secondary_DT
(Typ
),
5641 Object_Definition
=>
5642 Make_Subtype_Indication
(Loc
,
5644 New_Occurrence_Of
(RTE
(RE_Interface_Data
), Loc
),
5646 Make_Index_Or_Discriminant_Constraint
(Loc
,
5647 Constraints
=> New_List
(
5648 Make_Integer_Literal
(Loc
, Num_Ifaces
)))),
5651 Make_Aggregate
(Loc
,
5652 Expressions
=> New_List
(
5653 Make_Integer_Literal
(Loc
, Num_Ifaces
),
5654 Make_Aggregate
(Loc
, TSD_Ifaces_List
)))));
5657 Make_Attribute_Reference
(Loc
,
5658 Prefix
=> New_Occurrence_Of
(ITable
, Loc
),
5659 Attribute_Name
=> Name_Unchecked_Access
);
5663 Append_To
(TSD_Aggr_List
, Iface_Table_Node
);
5666 -- Generate the Select Specific Data table for synchronized types that
5667 -- implement synchronized interfaces. The size of the table is
5668 -- constrained by the number of non-predefined primitive operations.
5670 if RTE_Record_Component_Available
(RE_SSD
) then
5671 if Ada_Version
>= Ada_2005
5672 and then Has_DT
(Typ
)
5673 and then Is_Concurrent_Record_Type
(Typ
)
5674 and then Has_Interfaces
(Typ
)
5675 and then Nb_Prim
> 0
5676 and then not Is_Abstract_Type
(Typ
)
5677 and then not Is_Controlled
(Typ
)
5678 and then not Restriction_Active
(No_Dispatching_Calls
)
5679 and then not Restriction_Active
(No_Select_Statements
)
5682 Make_Object_Declaration
(Loc
,
5683 Defining_Identifier
=> SSD
,
5684 Aliased_Present
=> True,
5685 Object_Definition
=>
5686 Make_Subtype_Indication
(Loc
,
5687 Subtype_Mark
=> New_Occurrence_Of
(
5688 RTE
(RE_Select_Specific_Data
), Loc
),
5690 Make_Index_Or_Discriminant_Constraint
(Loc
,
5691 Constraints
=> New_List
(
5692 Make_Integer_Literal
(Loc
, Nb_Prim
))))));
5695 Make_Attribute_Definition_Clause
(Loc
,
5696 Name
=> New_Occurrence_Of
(SSD
, Loc
),
5697 Chars
=> Name_Alignment
,
5699 Make_Attribute_Reference
(Loc
,
5701 New_Occurrence_Of
(RTE
(RE_Integer_Address
), Loc
),
5702 Attribute_Name
=> Name_Alignment
)));
5704 -- This table is initialized by Make_Select_Specific_Data_Table,
5705 -- which calls Set_Entry_Index and Set_Prim_Op_Kind.
5707 Append_To
(TSD_Aggr_List
,
5708 Make_Attribute_Reference
(Loc
,
5709 Prefix
=> New_Occurrence_Of
(SSD
, Loc
),
5710 Attribute_Name
=> Name_Unchecked_Access
));
5712 Append_To
(TSD_Aggr_List
, Make_Null
(Loc
));
5716 -- Initialize the table of ancestor tags. In case of interface types
5717 -- this table is not needed.
5719 TSD_Tags_List
:= New_List
;
5721 -- If we are not statically allocating the dispatch table then we must
5722 -- fill position 0 with null because we still have not generated the
5725 if not Building_Static_DT
(Typ
)
5726 or else Is_Interface
(Typ
)
5728 Append_To
(TSD_Tags_List
,
5729 Unchecked_Convert_To
(RTE
(RE_Tag
),
5730 New_Occurrence_Of
(RTE
(RE_Null_Address
), Loc
)));
5732 -- Otherwise we can safely reference the tag
5735 Append_To
(TSD_Tags_List
,
5736 New_Occurrence_Of
(DT_Ptr
, Loc
));
5739 -- Fill the rest of the table with the tags of the ancestors
5742 Current_Typ
: Entity_Id
;
5743 Parent_Typ
: Entity_Id
;
5751 Parent_Typ
:= Etype
(Current_Typ
);
5753 if Is_Private_Type
(Parent_Typ
) then
5754 Parent_Typ
:= Full_View
(Base_Type
(Parent_Typ
));
5757 exit when Parent_Typ
= Current_Typ
;
5759 if Is_CPP_Class
(Parent_Typ
) then
5761 -- The tags defined in the C++ side will be inherited when
5762 -- the object is constructed (Exp_Ch3.Build_Init_Procedure)
5764 Append_To
(TSD_Tags_List
,
5765 Unchecked_Convert_To
(RTE
(RE_Tag
),
5766 New_Occurrence_Of
(RTE
(RE_Null_Address
), Loc
)));
5768 Append_To
(TSD_Tags_List
,
5770 (Node
(First_Elmt
(Access_Disp_Table
(Parent_Typ
))),
5775 Current_Typ
:= Parent_Typ
;
5778 pragma Assert
(Pos
= I_Depth
+ 1);
5781 Append_To
(TSD_Aggr_List
,
5782 Make_Aggregate
(Loc
,
5783 Expressions
=> TSD_Tags_List
));
5785 -- Build the TSD object
5788 Make_Object_Declaration
(Loc
,
5789 Defining_Identifier
=> TSD
,
5790 Aliased_Present
=> True,
5791 Constant_Present
=> Building_Static_DT
(Typ
),
5792 Object_Definition
=>
5793 Make_Subtype_Indication
(Loc
,
5794 Subtype_Mark
=> New_Occurrence_Of
(
5795 RTE
(RE_Type_Specific_Data
), Loc
),
5797 Make_Index_Or_Discriminant_Constraint
(Loc
,
5798 Constraints
=> New_List
(
5799 Make_Integer_Literal
(Loc
, I_Depth
)))),
5801 Expression
=> Make_Aggregate
(Loc
,
5802 Expressions
=> TSD_Aggr_List
)));
5804 Set_Is_True_Constant
(TSD
, Building_Static_DT
(Typ
));
5806 -- The debugging information for type Ada.Tags.Type_Specific_Data is
5807 -- needed by the debugger in order to display values of tagged types.
5809 Set_Needs_Debug_Info
(TSD
, Needs_Debug_Info
(Typ
));
5811 -- Initialize or declare the dispatch table object
5813 if not Has_DT
(Typ
) then
5814 DT_Constr_List
:= New_List
;
5815 DT_Aggr_List
:= New_List
;
5820 Make_Attribute_Reference
(Loc
,
5821 Prefix
=> New_Occurrence_Of
(TSD
, Loc
),
5822 Attribute_Name
=> Name_Address
);
5824 Append_To
(DT_Constr_List
, New_Node
);
5825 Append_To
(DT_Aggr_List
, New_Copy
(New_Node
));
5826 Append_To
(DT_Aggr_List
, Make_Integer_Literal
(Loc
, 0));
5828 -- In case of locally defined tagged types we have already declared
5829 -- and uninitialized object for the dispatch table, which is now
5830 -- initialized by means of the following assignment:
5832 -- DT := (TSD'Address, 0);
5834 if not Building_Static_DT
(Typ
) then
5836 Make_Assignment_Statement
(Loc
,
5837 Name
=> New_Occurrence_Of
(DT
, Loc
),
5838 Expression
=> Make_Aggregate
(Loc
, DT_Aggr_List
)));
5840 -- In case of library level tagged types we declare and export now
5841 -- the constant object containing the dummy dispatch table. There
5842 -- is no need to declare the tag here because it has been previously
5843 -- declared by Make_Tags
5845 -- DT : aliased constant No_Dispatch_Table :=
5846 -- (NDT_TSD => TSD'Address;
5847 -- NDT_Prims_Ptr => 0);
5851 Make_Object_Declaration
(Loc
,
5852 Defining_Identifier
=> DT
,
5853 Aliased_Present
=> True,
5854 Constant_Present
=> True,
5855 Object_Definition
=>
5856 New_Occurrence_Of
(RTE
(RE_No_Dispatch_Table_Wrapper
), Loc
),
5857 Expression
=> Make_Aggregate
(Loc
, DT_Aggr_List
)));
5859 Export_DT
(Typ
, DT
);
5862 -- Common case: Typ has a dispatch table
5866 -- Predef_Prims : Address_Array (1 .. Default_Prim_Ops_Count) :=
5867 -- (predef-prim-op-1'address,
5868 -- predef-prim-op-2'address,
5870 -- predef-prim-op-n'address);
5872 -- DT : Dispatch_Table (Nb_Prims) :=
5873 -- (Signature => <sig-value>,
5874 -- Tag_Kind => <tag_kind-value>,
5875 -- Predef_Prims => Predef_Prims'First'Address,
5876 -- Offset_To_Top => 0,
5877 -- TSD => TSD'Address;
5878 -- Prims_Ptr => (prim-op-1'address,
5879 -- prim-op-2'address,
5881 -- prim-op-n'address));
5882 -- for DT'Alignment use Address'Alignment
5886 Nb_P_Prims
: constant Nat
:= Number_Of_Predefined_Prims
(Typ
);
5887 Prim_Table
: array (Nat
range 1 .. Nb_P_Prims
) of Entity_Id
;
5890 SS_Thunk_Id
: Entity_Id
;
5891 SS_Thunk_Code
: Node_Id
;
5894 Prim_Ops_Aggr_List
:= New_List
;
5895 Prim_Table
:= (others => Empty
);
5897 if Building_Static_DT
(Typ
) then
5898 Prim_Elmt
:= First_Elmt
(Primitive_Operations
(Typ
));
5899 while Present
(Prim_Elmt
) loop
5900 Prim
:= Node
(Prim_Elmt
);
5902 if Is_Predefined_Dispatching_Operation
(Prim
)
5903 and then not Is_Abstract_Subprogram
(Prim
)
5904 and then not Is_Eliminated
(Prim
)
5905 and then not Generate_SCIL
5906 and then No
(Prim_Table
(UI_To_Int
(DT_Position
(Prim
))))
5908 E
:= Ultimate_Alias
(Prim
);
5909 pragma Assert
(not Is_Abstract_Subprogram
(E
));
5911 Expand_Secondary_Stack_Thunk
5912 (E
, SS_Thunk_Id
, SS_Thunk_Code
);
5914 if Present
(SS_Thunk_Id
) then
5916 Append_To
(Result
, SS_Thunk_Code
);
5919 Prim_Table
(UI_To_Int
(DT_Position
(Prim
))) := E
;
5922 Next_Elmt
(Prim_Elmt
);
5926 for J
in Prim_Table
'Range loop
5927 if Present
(Prim_Table
(J
)) then
5929 Unchecked_Convert_To
(RTE
(RE_Prim_Ptr
),
5930 Make_Attribute_Reference
(Loc
,
5932 New_Occurrence_Of
(Prim_Table
(J
), Loc
),
5933 Attribute_Name
=> Name_Unrestricted_Access
));
5935 New_Node
:= Make_Null
(Loc
);
5938 Append_To
(Prim_Ops_Aggr_List
, New_Node
);
5942 Make_Aggregate
(Loc
,
5943 Expressions
=> Prim_Ops_Aggr_List
);
5946 Make_Subtype_Declaration
(Loc
,
5947 Defining_Identifier
=> Make_Temporary
(Loc
, 'S'),
5948 Subtype_Indication
=>
5949 New_Occurrence_Of
(RTE
(RE_Address_Array
), Loc
));
5951 Append_To
(Result
, Decl
);
5954 Make_Object_Declaration
(Loc
,
5955 Defining_Identifier
=> Predef_Prims
,
5956 Aliased_Present
=> True,
5957 Constant_Present
=> Building_Static_DT
(Typ
),
5958 Object_Definition
=>
5959 New_Occurrence_Of
(Defining_Identifier
(Decl
), Loc
),
5960 Expression
=> New_Node
));
5962 -- Remember aggregates initializing dispatch tables
5964 Append_Elmt
(New_Node
, DT_Aggr
);
5967 -- Stage 1: Initialize the discriminant and the record components
5969 DT_Constr_List
:= New_List
;
5970 DT_Aggr_List
:= New_List
;
5972 -- Num_Prims. If the tagged type has no primitives we add a dummy
5973 -- slot whose address will be the tag of this type.
5976 New_Node
:= Make_Integer_Literal
(Loc
, 1);
5978 New_Node
:= Make_Integer_Literal
(Loc
, Nb_Prim
);
5981 Append_To
(DT_Constr_List
, New_Node
);
5982 Append_To
(DT_Aggr_List
, New_Copy
(New_Node
));
5986 if RTE_Record_Component_Available
(RE_Signature
) then
5987 Append_To
(DT_Aggr_List
,
5988 New_Occurrence_Of
(RTE
(RE_Primary_DT
), Loc
));
5993 if RTE_Record_Component_Available
(RE_Tag_Kind
) then
5994 Append_To
(DT_Aggr_List
, Tagged_Kind
(Typ
));
5999 Append_To
(DT_Aggr_List
,
6000 Make_Attribute_Reference
(Loc
,
6001 Prefix
=> New_Occurrence_Of
(Predef_Prims
, Loc
),
6002 Attribute_Name
=> Name_Address
));
6006 Append_To
(DT_Aggr_List
, Make_Integer_Literal
(Loc
, 0));
6010 Append_To
(DT_Aggr_List
,
6011 Make_Attribute_Reference
(Loc
,
6012 Prefix
=> New_Occurrence_Of
(TSD
, Loc
),
6013 Attribute_Name
=> Name_Address
));
6015 -- Stage 2: Initialize the table of user-defined primitive operations
6017 Prim_Ops_Aggr_List
:= New_List
;
6020 Append_To
(Prim_Ops_Aggr_List
, Make_Null
(Loc
));
6022 elsif not Building_Static_DT
(Typ
) then
6023 for J
in 1 .. Nb_Prim
loop
6024 Append_To
(Prim_Ops_Aggr_List
, Make_Null
(Loc
));
6029 CPP_Nb_Prims
: constant Nat
:= CPP_Num_Prims
(Typ
);
6032 Prim_Elmt
: Elmt_Id
;
6034 Prim_Table
: array (Nat
range 1 .. Nb_Prim
) of Entity_Id
;
6035 SS_Thunk_Id
: Entity_Id
;
6036 SS_Thunk_Code
: Node_Id
;
6039 Prim_Table
:= (others => Empty
);
6041 Prim_Elmt
:= First_Elmt
(Primitive_Operations
(Typ
));
6042 while Present
(Prim_Elmt
) loop
6043 Prim
:= Node
(Prim_Elmt
);
6045 -- Retrieve the ultimate alias of the primitive for proper
6046 -- handling of renamings and eliminated primitives.
6048 E
:= Ultimate_Alias
(Prim
);
6050 -- If the alias is not a primitive operation then Prim does
6051 -- not rename another primitive, but rather an operation
6052 -- declared elsewhere (e.g. in another scope) and therefore
6053 -- Prim is a new primitive.
6055 if No
(Find_Dispatching_Type
(E
)) then
6059 Prim_Pos
:= UI_To_Int
(DT_Position
(E
));
6061 -- Skip predefined primitives because they are located in a
6062 -- separate dispatch table.
6064 if not Is_Predefined_Dispatching_Operation
(Prim
)
6065 and then not Is_Predefined_Dispatching_Operation
(E
)
6067 -- Skip entities with attribute Interface_Alias because
6068 -- those are only required to build secondary dispatch
6071 and then No
(Interface_Alias
(Prim
))
6073 -- Skip abstract and eliminated primitives
6075 and then not Is_Abstract_Subprogram
(E
)
6076 and then not Is_Eliminated
(E
)
6078 -- For derivations of CPP types skip primitives located in
6079 -- the C++ part of the dispatch table because their slots
6080 -- are initialized by the IC routine.
6082 and then (not Is_CPP_Class
(Root_Type
(Typ
))
6083 or else Prim_Pos
> CPP_Nb_Prims
)
6085 -- Skip ignored Ghost subprograms as those will be removed
6086 -- from the executable.
6088 and then not Is_Ignored_Ghost_Entity
(E
)
6091 (UI_To_Int
(DT_Position
(Prim
)) <= Nb_Prim
);
6093 Expand_Secondary_Stack_Thunk
6094 (E
, SS_Thunk_Id
, SS_Thunk_Code
);
6096 if Present
(SS_Thunk_Id
) then
6098 Append_To
(Result
, SS_Thunk_Code
);
6101 Prim_Table
(UI_To_Int
(DT_Position
(Prim
))) := E
;
6104 Next_Elmt
(Prim_Elmt
);
6107 for J
in Prim_Table
'Range loop
6108 if Present
(Prim_Table
(J
)) then
6110 Unchecked_Convert_To
(RTE
(RE_Prim_Ptr
),
6111 Make_Attribute_Reference
(Loc
,
6113 New_Occurrence_Of
(Prim_Table
(J
), Loc
),
6114 Attribute_Name
=> Name_Unrestricted_Access
));
6116 New_Node
:= Make_Null
(Loc
);
6119 Append_To
(Prim_Ops_Aggr_List
, New_Node
);
6125 Make_Aggregate
(Loc
,
6126 Expressions
=> Prim_Ops_Aggr_List
);
6128 Append_To
(DT_Aggr_List
, New_Node
);
6130 -- Remember aggregates initializing dispatch tables
6132 Append_Elmt
(New_Node
, DT_Aggr
);
6134 -- In case of locally defined tagged types we have already declared
6135 -- and uninitialized object for the dispatch table, which is now
6136 -- initialized by means of an assignment.
6138 if not Building_Static_DT
(Typ
) then
6140 Make_Assignment_Statement
(Loc
,
6141 Name
=> New_Occurrence_Of
(DT
, Loc
),
6142 Expression
=> Make_Aggregate
(Loc
, DT_Aggr_List
)));
6144 -- In case of library level tagged types we declare now and export
6145 -- the constant object containing the dispatch table.
6149 Make_Object_Declaration
(Loc
,
6150 Defining_Identifier
=> DT
,
6151 Aliased_Present
=> True,
6152 Constant_Present
=> True,
6153 Object_Definition
=>
6154 Make_Subtype_Indication
(Loc
,
6155 Subtype_Mark
=> New_Occurrence_Of
6156 (RTE
(RE_Dispatch_Table_Wrapper
), Loc
),
6157 Constraint
=> Make_Index_Or_Discriminant_Constraint
(Loc
,
6158 Constraints
=> DT_Constr_List
)),
6159 Expression
=> Make_Aggregate
(Loc
, DT_Aggr_List
)));
6161 Export_DT
(Typ
, DT
);
6165 -- Initialize the table of ancestor tags if not building static
6168 if not Building_Static_DT
(Typ
)
6169 and then not Is_Interface
(Typ
)
6170 and then not Is_CPP_Class
(Typ
)
6173 Make_Assignment_Statement
(Loc
,
6175 Make_Indexed_Component
(Loc
,
6177 Make_Selected_Component
(Loc
,
6178 Prefix
=> New_Occurrence_Of
(TSD
, Loc
),
6181 (RTE_Record_Component
(RE_Tags_Table
), Loc
)),
6183 New_List
(Make_Integer_Literal
(Loc
, 0))),
6187 (Node
(First_Elmt
(Access_Disp_Table
(Typ
))), Loc
)));
6190 -- Inherit the dispatch tables of the parent. There is no need to
6191 -- inherit anything from the parent when building static dispatch tables
6192 -- because the whole dispatch table (including inherited primitives) has
6193 -- been already built.
6195 if Building_Static_DT
(Typ
) then
6198 -- If the ancestor is a CPP_Class type we inherit the dispatch tables
6199 -- in the init proc, and we don't need to fill them in here.
6201 elsif Is_CPP_Class
(Parent_Typ
) then
6204 -- Otherwise we fill in the dispatch tables here
6207 if Typ
/= Parent_Typ
6208 and then not Is_Interface
(Typ
)
6209 and then not Restriction_Active
(No_Dispatching_Calls
)
6211 -- Inherit the dispatch table
6213 if not Is_Interface
(Typ
)
6214 and then not Is_Interface
(Parent_Typ
)
6215 and then not Is_CPP_Class
(Parent_Typ
)
6218 Nb_Prims
: constant Int
:=
6219 UI_To_Int
(DT_Entry_Count
6220 (First_Tag_Component
(Parent_Typ
)));
6223 Append_To
(Elab_Code
,
6224 Build_Inherit_Predefined_Prims
(Loc
,
6230 (Access_Disp_Table
(Parent_Typ
)))), Loc
),
6236 (Access_Disp_Table
(Typ
)))), Loc
),
6238 Number_Of_Predefined_Prims
(Parent_Typ
)));
6240 if Nb_Prims
/= 0 then
6241 Append_To
(Elab_Code
,
6242 Build_Inherit_Prims
(Loc
,
6248 (Access_Disp_Table
(Parent_Typ
))), Loc
),
6249 New_Tag_Node
=> New_Occurrence_Of
(DT_Ptr
, Loc
),
6250 Num_Prims
=> Nb_Prims
));
6255 -- Inherit the secondary dispatch tables of the ancestor
6257 if not Is_CPP_Class
(Parent_Typ
) then
6259 Sec_DT_Ancestor
: Elmt_Id
:=
6265 Sec_DT_Typ
: Elmt_Id
:=
6269 (Access_Disp_Table
(Typ
))));
6271 procedure Copy_Secondary_DTs
(Typ
: Entity_Id
);
6272 -- Local procedure required to climb through the ancestors
6273 -- and copy the contents of all their secondary dispatch
6276 ------------------------
6277 -- Copy_Secondary_DTs --
6278 ------------------------
6280 procedure Copy_Secondary_DTs
(Typ
: Entity_Id
) is
6285 -- Climb to the ancestor (if any) handling private types
6287 if Present
(Full_View
(Etype
(Typ
))) then
6288 if Full_View
(Etype
(Typ
)) /= Typ
then
6289 Copy_Secondary_DTs
(Full_View
(Etype
(Typ
)));
6292 elsif Etype
(Typ
) /= Typ
then
6293 Copy_Secondary_DTs
(Etype
(Typ
));
6296 if Present
(Interfaces
(Typ
))
6297 and then not Is_Empty_Elmt_List
(Interfaces
(Typ
))
6299 Iface
:= First_Elmt
(Interfaces
(Typ
));
6300 E
:= First_Entity
(Typ
);
6302 and then Present
(Node
(Sec_DT_Ancestor
))
6303 and then Ekind
(Node
(Sec_DT_Ancestor
)) = E_Constant
6305 if Is_Tag
(E
) and then Chars
(E
) /= Name_uTag
then
6307 Num_Prims
: constant Int
:=
6308 UI_To_Int
(DT_Entry_Count
(E
));
6311 if not Is_Interface
(Etype
(Typ
)) then
6313 -- Inherit first secondary dispatch table
6315 Append_To
(Elab_Code
,
6316 Build_Inherit_Predefined_Prims
(Loc
,
6318 Unchecked_Convert_To
(RTE
(RE_Tag
),
6321 (Next_Elmt
(Sec_DT_Ancestor
)),
6324 Unchecked_Convert_To
(RTE
(RE_Tag
),
6326 (Node
(Next_Elmt
(Sec_DT_Typ
)),
6329 Number_Of_Predefined_Prims
6332 if Num_Prims
/= 0 then
6333 Append_To
(Elab_Code
,
6334 Build_Inherit_Prims
(Loc
,
6335 Typ
=> Node
(Iface
),
6337 Unchecked_Convert_To
6340 (Node
(Sec_DT_Ancestor
),
6343 Unchecked_Convert_To
6346 (Node
(Sec_DT_Typ
), Loc
)),
6347 Num_Prims
=> Num_Prims
));
6351 Next_Elmt
(Sec_DT_Ancestor
);
6352 Next_Elmt
(Sec_DT_Typ
);
6354 -- Skip the secondary dispatch table of
6355 -- predefined primitives
6357 Next_Elmt
(Sec_DT_Ancestor
);
6358 Next_Elmt
(Sec_DT_Typ
);
6360 if not Is_Interface
(Etype
(Typ
)) then
6362 -- Inherit second secondary dispatch table
6364 Append_To
(Elab_Code
,
6365 Build_Inherit_Predefined_Prims
(Loc
,
6367 Unchecked_Convert_To
(RTE
(RE_Tag
),
6370 (Next_Elmt
(Sec_DT_Ancestor
)),
6373 Unchecked_Convert_To
(RTE
(RE_Tag
),
6375 (Node
(Next_Elmt
(Sec_DT_Typ
)),
6378 Number_Of_Predefined_Prims
6381 if Num_Prims
/= 0 then
6382 Append_To
(Elab_Code
,
6383 Build_Inherit_Prims
(Loc
,
6384 Typ
=> Node
(Iface
),
6386 Unchecked_Convert_To
6389 (Node
(Sec_DT_Ancestor
),
6392 Unchecked_Convert_To
6395 (Node
(Sec_DT_Typ
), Loc
)),
6396 Num_Prims
=> Num_Prims
));
6401 Next_Elmt
(Sec_DT_Ancestor
);
6402 Next_Elmt
(Sec_DT_Typ
);
6404 -- Skip the secondary dispatch table of
6405 -- predefined primitives
6407 Next_Elmt
(Sec_DT_Ancestor
);
6408 Next_Elmt
(Sec_DT_Typ
);
6416 end Copy_Secondary_DTs
;
6419 if Present
(Node
(Sec_DT_Ancestor
))
6420 and then Ekind
(Node
(Sec_DT_Ancestor
)) = E_Constant
6422 -- Handle private types
6424 if Present
(Full_View
(Typ
)) then
6425 Copy_Secondary_DTs
(Full_View
(Typ
));
6427 Copy_Secondary_DTs
(Typ
);
6435 -- Generate code to check if the external tag of this type is the same
6436 -- as the external tag of some other declaration.
6438 -- Check_TSD (TSD'Unrestricted_Access);
6440 -- This check is a consequence of AI05-0113-1/06, so it officially
6441 -- applies to Ada 2005 (and Ada 2012). It might be argued that it is
6442 -- a desirable check to add in Ada 95 mode, but we hesitate to make
6443 -- this change, as it would be incompatible, and could conceivably
6444 -- cause a problem in existing Ada 95 code.
6446 -- We check for No_Run_Time_Mode here, because we do not want to pick
6447 -- up the RE_Check_TSD entity and call it in No_Run_Time mode.
6449 -- We cannot perform this check if the generation of its expanded name
6450 -- was discarded or if No_Tagged_Type_Registration is active.
6452 if not No_Run_Time_Mode
6453 and then not Discard_Names
6454 and then Ada_Version
>= Ada_2005
6455 and then not Duplicated_Tag_Checks_Suppressed
(Typ
)
6456 and then not Restriction_Active
(No_Tagged_Type_Registration
)
6457 and then RTE_Available
(RE_Check_TSD
)
6459 Append_To
(Elab_Code
,
6460 Make_Procedure_Call_Statement
(Loc
,
6462 New_Occurrence_Of
(RTE
(RE_Check_TSD
), Loc
),
6463 Parameter_Associations
=> New_List
(
6464 Make_Attribute_Reference
(Loc
,
6465 Prefix
=> New_Occurrence_Of
(TSD
, Loc
),
6466 Attribute_Name
=> Name_Unchecked_Access
))));
6469 -- Generate code to register the Tag in the External_Tag hash table for
6470 -- the pure Ada type only.
6472 -- Register_Tag (Dt_Ptr);
6474 -- Skip this action in the following cases:
6475 -- 1) if Register_Tag is not available.
6476 -- 2) in No_Run_Time mode.
6477 -- 3) if Typ is not defined at the library level (this is required
6478 -- to avoid adding concurrency control to the hash table used
6479 -- by the run-time to register the tags).
6480 -- 4) No_Tagged_Type_Registration is active.
6482 if not No_Run_Time_Mode
6483 and then Is_Library_Level_Entity
(Typ
)
6484 and then not Restriction_Active
(No_Tagged_Type_Registration
)
6485 and then RTE_Available
(RE_Register_Tag
)
6487 Append_To
(Elab_Code
,
6488 Make_Procedure_Call_Statement
(Loc
,
6490 New_Occurrence_Of
(RTE
(RE_Register_Tag
), Loc
),
6491 Parameter_Associations
=>
6492 New_List
(New_Occurrence_Of
(DT_Ptr
, Loc
))));
6495 Append_List_To
(Result
, Elab_Code
);
6497 -- Populate the two auxiliary tables used for dispatching asynchronous,
6498 -- conditional and timed selects for synchronized types that implement
6499 -- a limited interface. Skip this step in Ravenscar profile or when
6500 -- general dispatching is forbidden.
6502 if Ada_Version
>= Ada_2005
6503 and then Is_Concurrent_Record_Type
(Typ
)
6504 and then Has_Interfaces
(Typ
)
6505 and then not Restriction_Active
(No_Dispatching_Calls
)
6506 and then not Restriction_Active
(No_Select_Statements
)
6508 Append_List_To
(Result
,
6509 Make_Select_Specific_Data_Table
(Typ
));
6512 -- Remember entities containing dispatch tables
6514 Append_Elmt
(Predef_Prims
, DT_Decl
);
6515 Append_Elmt
(DT
, DT_Decl
);
6517 Analyze_List
(Result
, Suppress
=> All_Checks
);
6519 -- Mark entities containing dispatch tables. Required by the backend to
6520 -- handle them properly.
6522 if Has_DT
(Typ
) then
6527 -- Object declarations
6529 Elmt
:= First_Elmt
(DT_Decl
);
6530 while Present
(Elmt
) loop
6531 Set_Is_Dispatch_Table_Entity
(Node
(Elmt
));
6532 pragma Assert
(Ekind
(Etype
(Node
(Elmt
))) = E_Array_Subtype
6533 or else Ekind
(Etype
(Node
(Elmt
))) = E_Record_Subtype
);
6534 Set_Is_Dispatch_Table_Entity
(Etype
(Node
(Elmt
)));
6538 -- Aggregates initializing dispatch tables
6540 Elmt
:= First_Elmt
(DT_Aggr
);
6541 while Present
(Elmt
) loop
6542 Set_Is_Dispatch_Table_Entity
(Etype
(Node
(Elmt
)));
6550 Set_Has_Dispatch_Table
(Typ
);
6552 -- Register the tagged type in the call graph nodes table
6554 Register_CG_Node
(Typ
);
6557 Restore_Ghost_Region
(Saved_GM
, Saved_IGR
);
6562 -------------------------------------
6563 -- Make_Select_Specific_Data_Table --
6564 -------------------------------------
6566 function Make_Select_Specific_Data_Table
6567 (Typ
: Entity_Id
) return List_Id
6569 Assignments
: constant List_Id
:= New_List
;
6570 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
6572 Conc_Typ
: Entity_Id
;
6573 Decls
: List_Id
:= No_List
;
6575 Prim_Als
: Entity_Id
;
6576 Prim_Elmt
: Elmt_Id
;
6580 type Examined_Array
is array (Int
range <>) of Boolean;
6582 function Find_Entry_Index
(E
: Entity_Id
) return Uint
;
6583 -- Given an entry, find its index in the visible declarations of the
6584 -- corresponding concurrent type of Typ.
6586 ----------------------
6587 -- Find_Entry_Index --
6588 ----------------------
6590 function Find_Entry_Index
(E
: Entity_Id
) return Uint
is
6591 Index
: Uint
:= Uint_0
;
6592 Subp_Decl
: Node_Id
;
6595 Subp_Decl
:= First
(Decls
);
6596 while Present
(Subp_Decl
) loop
6597 if Nkind
(Subp_Decl
) = N_Entry_Declaration
then
6600 if Defining_Identifier
(Subp_Decl
) = E
then
6610 end Find_Entry_Index
;
6616 -- Start of processing for Make_Select_Specific_Data_Table
6619 pragma Assert
(not Restriction_Active
(No_Dispatching_Calls
));
6621 if Present
(Corresponding_Concurrent_Type
(Typ
)) then
6622 Conc_Typ
:= Corresponding_Concurrent_Type
(Typ
);
6624 if Present
(Full_View
(Conc_Typ
)) then
6625 Conc_Typ
:= Full_View
(Conc_Typ
);
6628 if Ekind
(Conc_Typ
) = E_Protected_Type
then
6629 Decls
:= Visible_Declarations
(Protected_Definition
(
6630 Parent
(Conc_Typ
)));
6632 pragma Assert
(Ekind
(Conc_Typ
) = E_Task_Type
);
6633 Decls
:= Visible_Declarations
(Task_Definition
(
6634 Parent
(Conc_Typ
)));
6638 -- Count the non-predefined primitive operations
6640 Prim_Elmt
:= First_Elmt
(Primitive_Operations
(Typ
));
6641 while Present
(Prim_Elmt
) loop
6642 Prim
:= Node
(Prim_Elmt
);
6644 if not (Is_Predefined_Dispatching_Operation
(Prim
)
6645 or else Is_Predefined_Dispatching_Alias
(Prim
))
6647 Nb_Prim
:= Nb_Prim
+ 1;
6650 Next_Elmt
(Prim_Elmt
);
6654 Examined
: Examined_Array
(1 .. Nb_Prim
) := (others => False);
6657 Prim_Elmt
:= First_Elmt
(Primitive_Operations
(Typ
));
6658 while Present
(Prim_Elmt
) loop
6659 Prim
:= Node
(Prim_Elmt
);
6661 -- Look for primitive overriding an abstract interface subprogram
6663 if Present
(Interface_Alias
(Prim
))
6666 (Find_Dispatching_Type
(Interface_Alias
(Prim
)), Typ
,
6667 Use_Full_View
=> True)
6668 and then not Examined
(UI_To_Int
(DT_Position
(Alias
(Prim
))))
6670 Prim_Pos
:= DT_Position
(Alias
(Prim
));
6671 pragma Assert
(UI_To_Int
(Prim_Pos
) <= Nb_Prim
);
6672 Examined
(UI_To_Int
(Prim_Pos
)) := True;
6674 -- Set the primitive operation kind regardless of subprogram
6676 -- Ada.Tags.Set_Prim_Op_Kind (DT_Ptr, <position>, <kind>);
6678 if Tagged_Type_Expansion
then
6681 (Node
(First_Elmt
(Access_Disp_Table
(Typ
))), Loc
);
6685 Make_Attribute_Reference
(Loc
,
6686 Prefix
=> New_Occurrence_Of
(Typ
, Loc
),
6687 Attribute_Name
=> Name_Tag
);
6690 Append_To
(Assignments
,
6691 Make_Procedure_Call_Statement
(Loc
,
6692 Name
=> New_Occurrence_Of
(RTE
(RE_Set_Prim_Op_Kind
), Loc
),
6693 Parameter_Associations
=> New_List
(
6695 Make_Integer_Literal
(Loc
, Prim_Pos
),
6696 Prim_Op_Kind
(Alias
(Prim
), Typ
))));
6698 -- Retrieve the root of the alias chain
6700 Prim_Als
:= Ultimate_Alias
(Prim
);
6702 -- In the case of an entry wrapper, set the entry index
6704 if Ekind
(Prim
) = E_Procedure
6705 and then Is_Primitive_Wrapper
(Prim_Als
)
6706 and then Ekind
(Wrapped_Entity
(Prim_Als
)) = E_Entry
6709 -- Ada.Tags.Set_Entry_Index
6710 -- (DT_Ptr, <position>, <index>);
6712 if Tagged_Type_Expansion
then
6715 (Node
(First_Elmt
(Access_Disp_Table
(Typ
))), Loc
);
6718 Make_Attribute_Reference
(Loc
,
6719 Prefix
=> New_Occurrence_Of
(Typ
, Loc
),
6720 Attribute_Name
=> Name_Tag
);
6723 Append_To
(Assignments
,
6724 Make_Procedure_Call_Statement
(Loc
,
6726 New_Occurrence_Of
(RTE
(RE_Set_Entry_Index
), Loc
),
6727 Parameter_Associations
=> New_List
(
6729 Make_Integer_Literal
(Loc
, Prim_Pos
),
6730 Make_Integer_Literal
(Loc
,
6731 Find_Entry_Index
(Wrapped_Entity
(Prim_Als
))))));
6735 Next_Elmt
(Prim_Elmt
);
6740 end Make_Select_Specific_Data_Table
;
6746 function Make_Tags
(Typ
: Entity_Id
) return List_Id
is
6747 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
6748 Result
: constant List_Id
:= New_List
;
6751 (Tag_Typ
: Entity_Id
;
6753 Is_Secondary_DT
: Boolean);
6754 -- Import the dispatch table DT of tagged type Tag_Typ. Required to
6755 -- generate forward references and statically allocate the table. For
6756 -- primary dispatch tables that require no dispatch table generate:
6758 -- DT : static aliased constant Non_Dispatch_Table_Wrapper;
6759 -- pragma Import (Ada, DT);
6761 -- Otherwise generate:
6763 -- DT : static aliased constant Dispatch_Table_Wrapper (Nb_Prim);
6764 -- pragma Import (Ada, DT);
6771 (Tag_Typ
: Entity_Id
;
6773 Is_Secondary_DT
: Boolean)
6775 DT_Constr_List
: List_Id
;
6779 Set_Is_Imported
(DT
);
6780 Mutate_Ekind
(DT
, E_Constant
);
6781 Set_Related_Type
(DT
, Typ
);
6783 -- The scope must be set now to call Get_External_Name
6785 Set_Scope
(DT
, Current_Scope
);
6787 Get_External_Name
(DT
);
6788 Set_Interface_Name
(DT
,
6789 Make_String_Literal
(Loc
, Strval
=> String_From_Name_Buffer
));
6791 -- Ensure proper Sprint output of this implicit importation
6793 Set_Is_Internal
(DT
);
6795 -- Save this entity to allow Make_DT to generate its exportation
6797 Append_Elmt
(DT
, Dispatch_Table_Wrappers
(Typ
));
6799 -- No dispatch table required
6801 if not Is_Secondary_DT
and then not Has_DT
(Tag_Typ
) then
6803 Make_Object_Declaration
(Loc
,
6804 Defining_Identifier
=> DT
,
6805 Aliased_Present
=> True,
6806 Constant_Present
=> True,
6807 Object_Definition
=>
6809 (RTE
(RE_No_Dispatch_Table_Wrapper
), Loc
)));
6812 -- Calculate the number of primitives of the dispatch table and
6813 -- the size of the Type_Specific_Data record.
6816 UI_To_Int
(DT_Entry_Count
(First_Tag_Component
(Tag_Typ
)));
6818 -- If the tagged type has no primitives we add a dummy slot whose
6819 -- address will be the tag of this type.
6823 New_List
(Make_Integer_Literal
(Loc
, 1));
6826 New_List
(Make_Integer_Literal
(Loc
, Nb_Prim
));
6830 Make_Object_Declaration
(Loc
,
6831 Defining_Identifier
=> DT
,
6832 Aliased_Present
=> True,
6833 Constant_Present
=> True,
6834 Object_Definition
=>
6835 Make_Subtype_Indication
(Loc
,
6837 New_Occurrence_Of
(RTE
(RE_Dispatch_Table_Wrapper
), Loc
),
6838 Constraint
=> Make_Index_Or_Discriminant_Constraint
(Loc
,
6839 Constraints
=> DT_Constr_List
))));
6845 Tname
: constant Name_Id
:= Chars
(Typ
);
6846 AI_Tag_Comp
: Elmt_Id
;
6847 DT
: Node_Id
:= Empty
;
6849 Predef_Prims_Ptr
: Node_Id
;
6850 Iface_DT
: Node_Id
:= Empty
;
6851 Iface_DT_Ptr
: Node_Id
;
6855 Typ_Comps
: Elist_Id
;
6857 -- Start of processing for Make_Tags
6860 pragma Assert
(No
(Access_Disp_Table
(Typ
)));
6861 Set_Access_Disp_Table
(Typ
, New_Elmt_List
);
6863 -- If the elaboration of this tagged type needs a boolean flag then
6864 -- define now its entity. It is initialized to True to indicate that
6865 -- elaboration is still pending; set to False by the IP routine.
6867 -- TypFxx : boolean := True;
6869 if Elab_Flag_Needed
(Typ
) then
6870 Set_Access_Disp_Table_Elab_Flag
(Typ
,
6871 Make_Defining_Identifier
(Loc
,
6872 Chars
=> New_External_Name
(Tname
, 'F')));
6875 Make_Object_Declaration
(Loc
,
6876 Defining_Identifier
=> Access_Disp_Table_Elab_Flag
(Typ
),
6877 Object_Definition
=> New_Occurrence_Of
(Standard_Boolean
, Loc
),
6878 Expression
=> New_Occurrence_Of
(Standard_True
, Loc
)));
6881 -- 1) Generate the primary tag entities
6883 -- Primary dispatch table containing user-defined primitives
6885 DT_Ptr
:= Make_Defining_Identifier
(Loc
, New_External_Name
(Tname
, 'P'));
6886 Set_Etype
(DT_Ptr
, RTE
(RE_Tag
));
6887 Append_Elmt
(DT_Ptr
, Access_Disp_Table
(Typ
));
6889 -- Minimum decoration
6891 Mutate_Ekind
(DT_Ptr
, E_Variable
);
6892 Set_Related_Type
(DT_Ptr
, Typ
);
6894 -- Notify back end that the types are associated with a dispatch table
6896 Set_Is_Dispatch_Table_Entity
(RTE
(RE_Prim_Ptr
));
6897 Set_Is_Dispatch_Table_Entity
(RTE
(RE_Predef_Prims_Table_Ptr
));
6899 -- For CPP types there is no need to build the dispatch tables since
6900 -- they are imported from the C++ side. If the CPP type has an IP then
6901 -- we declare now the variable that will store the copy of the C++ tag.
6902 -- If the CPP type is an interface, we need the variable as well because
6903 -- it becomes the pointer to the corresponding secondary table.
6905 if Is_CPP_Class
(Typ
) then
6906 if Has_CPP_Constructors
(Typ
) or else Is_Interface
(Typ
) then
6908 Make_Object_Declaration
(Loc
,
6909 Defining_Identifier
=> DT_Ptr
,
6910 Object_Definition
=> New_Occurrence_Of
(RTE
(RE_Tag
), Loc
),
6912 Unchecked_Convert_To
(RTE
(RE_Tag
),
6913 New_Occurrence_Of
(RTE
(RE_Null_Address
), Loc
))));
6915 Set_Is_Statically_Allocated
(DT_Ptr
,
6916 Is_Library_Level_Tagged_Type
(Typ
));
6922 -- Primary dispatch table containing predefined primitives
6925 Make_Defining_Identifier
(Loc
,
6926 Chars
=> New_External_Name
(Tname
, 'Y'));
6927 Set_Etype
(Predef_Prims_Ptr
, RTE
(RE_Address
));
6928 Append_Elmt
(Predef_Prims_Ptr
, Access_Disp_Table
(Typ
));
6930 -- Import the forward declaration of the Dispatch Table wrapper
6931 -- record (Make_DT will take care of exporting it).
6933 if Building_Static_DT
(Typ
) then
6934 Set_Dispatch_Table_Wrappers
(Typ
, New_Elmt_List
);
6937 Make_Defining_Identifier
(Loc
,
6938 Chars
=> New_External_Name
(Tname
, 'T'));
6940 Import_DT
(Typ
, DT
, Is_Secondary_DT
=> False);
6942 if Has_DT
(Typ
) then
6944 Make_Object_Declaration
(Loc
,
6945 Defining_Identifier
=> DT_Ptr
,
6946 Constant_Present
=> True,
6947 Object_Definition
=>
6948 New_Occurrence_Of
(RTE
(RE_Tag
), Loc
),
6950 Unchecked_Convert_To
(RTE
(RE_Tag
),
6951 Make_Attribute_Reference
(Loc
,
6953 Make_Selected_Component
(Loc
,
6954 Prefix
=> New_Occurrence_Of
(DT
, Loc
),
6957 (RTE_Record_Component
(RE_Prims_Ptr
), Loc
)),
6958 Attribute_Name
=> Name_Address
))));
6960 -- Generate the SCIL node for the previous object declaration
6961 -- because it has a tag initialization.
6963 if Generate_SCIL
then
6965 Make_SCIL_Dispatch_Table_Tag_Init
(Sloc
(Last
(Result
)));
6966 Set_SCIL_Entity
(New_Node
, Typ
);
6967 Set_SCIL_Node
(Last
(Result
), New_Node
);
6971 Make_Object_Declaration
(Loc
,
6972 Defining_Identifier
=> Predef_Prims_Ptr
,
6973 Constant_Present
=> True,
6974 Object_Definition
=>
6975 New_Occurrence_Of
(RTE
(RE_Address
), Loc
),
6977 Make_Attribute_Reference
(Loc
,
6979 Make_Selected_Component
(Loc
,
6980 Prefix
=> New_Occurrence_Of
(DT
, Loc
),
6983 (RTE_Record_Component
(RE_Predef_Prims
), Loc
)),
6984 Attribute_Name
=> Name_Address
)));
6986 -- No dispatch table required
6990 Make_Object_Declaration
(Loc
,
6991 Defining_Identifier
=> DT_Ptr
,
6992 Constant_Present
=> True,
6993 Object_Definition
=>
6994 New_Occurrence_Of
(RTE
(RE_Tag
), Loc
),
6996 Unchecked_Convert_To
(RTE
(RE_Tag
),
6997 Make_Attribute_Reference
(Loc
,
6999 Make_Selected_Component
(Loc
,
7000 Prefix
=> New_Occurrence_Of
(DT
, Loc
),
7003 (RTE_Record_Component
(RE_NDT_Prims_Ptr
),
7005 Attribute_Name
=> Name_Address
))));
7008 Set_Is_True_Constant
(DT_Ptr
);
7009 Set_Is_Statically_Allocated
(DT_Ptr
);
7013 -- 2) Generate the secondary tag entities
7015 -- Collect the components associated with secondary dispatch tables
7017 if Has_Interfaces
(Typ
) then
7018 Collect_Interface_Components
(Typ
, Typ_Comps
);
7020 -- For each interface type we build a unique external name associated
7021 -- with its secondary dispatch table. This name is used to declare an
7022 -- object that references this secondary dispatch table, whose value
7023 -- will be used for the elaboration of Typ objects, and also for the
7024 -- elaboration of objects of types derived from Typ that do not
7025 -- override the primitives of this interface type.
7029 -- Note: The value of Suffix_Index must be in sync with the values of
7030 -- Suffix_Index in secondary dispatch tables generated by Make_DT.
7032 if Is_CPP_Class
(Typ
) then
7033 AI_Tag_Comp
:= First_Elmt
(Typ_Comps
);
7034 while Present
(AI_Tag_Comp
) loop
7035 Get_Secondary_DT_External_Name
7036 (Typ
, Related_Type
(Node
(AI_Tag_Comp
)), Suffix_Index
);
7037 Typ_Name
:= Name_Find
;
7039 -- Declare variables to store copy of the C++ secondary tags
7042 Make_Defining_Identifier
(Loc
,
7043 Chars
=> New_External_Name
(Typ_Name
, 'P'));
7044 Set_Etype
(Iface_DT_Ptr
, RTE
(RE_Interface_Tag
));
7045 Mutate_Ekind
(Iface_DT_Ptr
, E_Variable
);
7046 Set_Is_Tag
(Iface_DT_Ptr
);
7048 Set_Has_Thunks
(Iface_DT_Ptr
);
7050 (Iface_DT_Ptr
, Related_Type
(Node
(AI_Tag_Comp
)));
7051 Append_Elmt
(Iface_DT_Ptr
, Access_Disp_Table
(Typ
));
7054 Make_Object_Declaration
(Loc
,
7055 Defining_Identifier
=> Iface_DT_Ptr
,
7056 Object_Definition
=> New_Occurrence_Of
7057 (RTE
(RE_Interface_Tag
), Loc
),
7059 Unchecked_Convert_To
(RTE
(RE_Interface_Tag
),
7060 New_Occurrence_Of
(RTE
(RE_Null_Address
), Loc
))));
7062 Set_Is_Statically_Allocated
(Iface_DT_Ptr
,
7063 Is_Library_Level_Tagged_Type
(Typ
));
7065 Next_Elmt
(AI_Tag_Comp
);
7068 -- This is not a CPP_Class type
7071 AI_Tag_Comp
:= First_Elmt
(Typ_Comps
);
7072 while Present
(AI_Tag_Comp
) loop
7073 Get_Secondary_DT_External_Name
7074 (Typ
, Related_Type
(Node
(AI_Tag_Comp
)), Suffix_Index
);
7075 Typ_Name
:= Name_Find
;
7077 if Building_Static_DT
(Typ
) then
7079 Make_Defining_Identifier
(Loc
,
7080 Chars
=> New_External_Name
(Typ_Name
, 'T'));
7082 (Tag_Typ
=> Related_Type
(Node
(AI_Tag_Comp
)),
7084 Is_Secondary_DT
=> True);
7087 -- Secondary dispatch table referencing thunks to user-defined
7088 -- primitives covered by this interface.
7091 Make_Defining_Identifier
(Loc
,
7092 Chars
=> New_External_Name
(Typ_Name
, 'P'));
7093 Set_Etype
(Iface_DT_Ptr
, RTE
(RE_Interface_Tag
));
7094 Mutate_Ekind
(Iface_DT_Ptr
, E_Constant
);
7095 Set_Is_Tag
(Iface_DT_Ptr
);
7096 Set_Has_Thunks
(Iface_DT_Ptr
);
7097 Set_Is_Statically_Allocated
(Iface_DT_Ptr
,
7098 Is_Library_Level_Tagged_Type
(Typ
));
7099 Set_Is_True_Constant
(Iface_DT_Ptr
);
7101 (Iface_DT_Ptr
, Related_Type
(Node
(AI_Tag_Comp
)));
7102 Append_Elmt
(Iface_DT_Ptr
, Access_Disp_Table
(Typ
));
7104 if Building_Static_DT
(Typ
) then
7106 Make_Object_Declaration
(Loc
,
7107 Defining_Identifier
=> Iface_DT_Ptr
,
7108 Constant_Present
=> True,
7109 Object_Definition
=> New_Occurrence_Of
7110 (RTE
(RE_Interface_Tag
), Loc
),
7112 Unchecked_Convert_To
(RTE
(RE_Interface_Tag
),
7113 Make_Attribute_Reference
(Loc
,
7115 Make_Selected_Component
(Loc
,
7117 New_Occurrence_Of
(Iface_DT
, Loc
),
7120 (RTE_Record_Component
(RE_Prims_Ptr
),
7122 Attribute_Name
=> Name_Address
))));
7125 -- Secondary dispatch table referencing thunks to predefined
7129 Make_Defining_Identifier
(Loc
,
7130 Chars
=> New_External_Name
(Typ_Name
, 'Y'));
7131 Set_Etype
(Iface_DT_Ptr
, RTE
(RE_Address
));
7132 Mutate_Ekind
(Iface_DT_Ptr
, E_Constant
);
7133 Set_Is_Tag
(Iface_DT_Ptr
);
7134 Set_Has_Thunks
(Iface_DT_Ptr
);
7135 Set_Is_Statically_Allocated
(Iface_DT_Ptr
,
7136 Is_Library_Level_Tagged_Type
(Typ
));
7137 Set_Is_True_Constant
(Iface_DT_Ptr
);
7139 (Iface_DT_Ptr
, Related_Type
(Node
(AI_Tag_Comp
)));
7140 Append_Elmt
(Iface_DT_Ptr
, Access_Disp_Table
(Typ
));
7142 -- Secondary dispatch table referencing user-defined primitives
7143 -- covered by this interface.
7146 Make_Defining_Identifier
(Loc
,
7147 Chars
=> New_External_Name
(Typ_Name
, 'D'));
7148 Set_Etype
(Iface_DT_Ptr
, RTE
(RE_Interface_Tag
));
7149 Mutate_Ekind
(Iface_DT_Ptr
, E_Constant
);
7150 Set_Is_Tag
(Iface_DT_Ptr
);
7151 Set_Is_Statically_Allocated
(Iface_DT_Ptr
,
7152 Is_Library_Level_Tagged_Type
(Typ
));
7153 Set_Is_True_Constant
(Iface_DT_Ptr
);
7155 (Iface_DT_Ptr
, Related_Type
(Node
(AI_Tag_Comp
)));
7156 Append_Elmt
(Iface_DT_Ptr
, Access_Disp_Table
(Typ
));
7158 -- Secondary dispatch table referencing predefined primitives
7161 Make_Defining_Identifier
(Loc
,
7162 Chars
=> New_External_Name
(Typ_Name
, 'Z'));
7163 Set_Etype
(Iface_DT_Ptr
, RTE
(RE_Address
));
7164 Mutate_Ekind
(Iface_DT_Ptr
, E_Constant
);
7165 Set_Is_Tag
(Iface_DT_Ptr
);
7166 Set_Is_Statically_Allocated
(Iface_DT_Ptr
,
7167 Is_Library_Level_Tagged_Type
(Typ
));
7168 Set_Is_True_Constant
(Iface_DT_Ptr
);
7170 (Iface_DT_Ptr
, Related_Type
(Node
(AI_Tag_Comp
)));
7171 Append_Elmt
(Iface_DT_Ptr
, Access_Disp_Table
(Typ
));
7173 Next_Elmt
(AI_Tag_Comp
);
7178 -- 3) At the end of Access_Disp_Table, if the type has user-defined
7179 -- primitives, we add the entity of an access type declaration that
7180 -- is used by Build_Get_Prim_Op_Address to expand dispatching calls
7181 -- through the primary dispatch table.
7183 if DT_Entry_Count
(First_Tag_Component
(Typ
)) = 0 then
7184 Analyze_List
(Result
);
7187 -- subtype Typ_DT is Address_Array (1 .. Nb_Prims);
7188 -- type Typ_DT_Acc is access Typ_DT;
7192 Name_DT_Prims
: constant Name_Id
:=
7193 New_External_Name
(Tname
, 'G');
7194 Name_DT_Prims_Acc
: constant Name_Id
:=
7195 New_External_Name
(Tname
, 'H');
7196 DT_Prims
: constant Entity_Id
:=
7197 Make_Defining_Identifier
(Loc
,
7199 DT_Prims_Acc
: constant Entity_Id
:=
7200 Make_Defining_Identifier
(Loc
,
7204 Make_Subtype_Declaration
(Loc
,
7205 Defining_Identifier
=> DT_Prims
,
7206 Subtype_Indication
=>
7207 Make_Subtype_Indication
(Loc
,
7209 New_Occurrence_Of
(RTE
(RE_Address_Array
), Loc
),
7211 Make_Index_Or_Discriminant_Constraint
(Loc
, New_List
(
7213 Low_Bound
=> Make_Integer_Literal
(Loc
, 1),
7215 Make_Integer_Literal
(Loc
,
7217 (First_Tag_Component
(Typ
)))))))));
7220 Make_Full_Type_Declaration
(Loc
,
7221 Defining_Identifier
=> DT_Prims_Acc
,
7223 Make_Access_To_Object_Definition
(Loc
,
7224 Subtype_Indication
=>
7225 New_Occurrence_Of
(DT_Prims
, Loc
))));
7227 Append_Elmt
(DT_Prims_Acc
, Access_Disp_Table
(Typ
));
7229 -- Analyze the resulting list and suppress the generation of the
7230 -- Init_Proc associated with the above array declaration because
7231 -- this type is never used in object declarations. It is only used
7232 -- to simplify the expansion associated with dispatching calls.
7234 Analyze_List
(Result
);
7235 Set_Suppress_Initialization
(Base_Type
(DT_Prims
));
7237 -- Disable backend optimizations based on assumptions about the
7238 -- aliasing status of objects designated by the access to the
7239 -- dispatch table. Required to handle dispatch tables imported
7242 Set_No_Strict_Aliasing
(Base_Type
(DT_Prims_Acc
));
7244 -- Add the freezing nodes of these declarations; required to avoid
7245 -- generating these freezing nodes in wrong scopes (for example in
7246 -- the IC routine of a derivation of Typ).
7248 -- What is an "IC routine"? Is "init_proc" meant here???
7250 Append_List_To
(Result
, Freeze_Entity
(DT_Prims
, Typ
));
7251 Append_List_To
(Result
, Freeze_Entity
(DT_Prims_Acc
, Typ
));
7253 -- Mark entity of dispatch table. Required by the back end to
7254 -- handle them properly.
7256 Set_Is_Dispatch_Table_Entity
(DT_Prims
);
7260 -- Mark entities of dispatch table. Required by the back end to handle
7263 if Present
(DT
) then
7264 Set_Is_Dispatch_Table_Entity
(DT
);
7265 Set_Is_Dispatch_Table_Entity
(Etype
(DT
));
7268 if Present
(Iface_DT
) then
7269 Set_Is_Dispatch_Table_Entity
(Iface_DT
);
7270 Set_Is_Dispatch_Table_Entity
(Etype
(Iface_DT
));
7273 if Is_CPP_Class
(Root_Type
(Typ
)) then
7274 Mutate_Ekind
(DT_Ptr
, E_Variable
);
7276 Mutate_Ekind
(DT_Ptr
, E_Constant
);
7279 Set_Is_Tag
(DT_Ptr
);
7280 Set_Related_Type
(DT_Ptr
, Typ
);
7289 function New_Value
(From
: Node_Id
) return Node_Id
is
7290 Res
: constant Node_Id
:= Duplicate_Subexpr
(From
);
7292 if Is_Access_Type
(Etype
(From
)) then
7293 return Make_Explicit_Dereference
(Sloc
(From
), Prefix
=> Res
);
7303 function Prim_Op_Kind
7305 Typ
: Entity_Id
) return Node_Id
7307 Full_Typ
: Entity_Id
:= Typ
;
7308 Loc
: constant Source_Ptr
:= Sloc
(Prim
);
7309 Prim_Op
: Entity_Id
;
7312 -- Retrieve the original primitive operation
7314 Prim_Op
:= Ultimate_Alias
(Prim
);
7316 if Ekind
(Typ
) = E_Record_Type
7317 and then Present
(Corresponding_Concurrent_Type
(Typ
))
7319 Full_Typ
:= Corresponding_Concurrent_Type
(Typ
);
7322 -- When a private tagged type is completed by a concurrent type,
7323 -- retrieve the full view.
7325 if Is_Private_Type
(Full_Typ
) then
7326 Full_Typ
:= Full_View
(Full_Typ
);
7329 if Ekind
(Prim_Op
) = E_Function
then
7331 -- Protected function
7333 if Ekind
(Full_Typ
) = E_Protected_Type
then
7334 return New_Occurrence_Of
(RTE
(RE_POK_Protected_Function
), Loc
);
7338 elsif Ekind
(Full_Typ
) = E_Task_Type
then
7339 return New_Occurrence_Of
(RTE
(RE_POK_Task_Function
), Loc
);
7344 return New_Occurrence_Of
(RTE
(RE_POK_Function
), Loc
);
7348 pragma Assert
(Ekind
(Prim_Op
) = E_Procedure
);
7350 if Ekind
(Full_Typ
) = E_Protected_Type
then
7354 if Is_Primitive_Wrapper
(Prim_Op
)
7355 and then Ekind
(Wrapped_Entity
(Prim_Op
)) = E_Entry
7357 return New_Occurrence_Of
(RTE
(RE_POK_Protected_Entry
), Loc
);
7359 -- Protected procedure
7363 New_Occurrence_Of
(RTE
(RE_POK_Protected_Procedure
), Loc
);
7366 elsif Ekind
(Full_Typ
) = E_Task_Type
then
7370 if Is_Primitive_Wrapper
(Prim_Op
)
7371 and then Ekind
(Wrapped_Entity
(Prim_Op
)) = E_Entry
7373 return New_Occurrence_Of
(RTE
(RE_POK_Task_Entry
), Loc
);
7375 -- Task "procedure". These are the internally Expander-generated
7376 -- procedures (task body for instance).
7379 return New_Occurrence_Of
(RTE
(RE_POK_Task_Procedure
), Loc
);
7382 -- Regular procedure
7385 return New_Occurrence_Of
(RTE
(RE_POK_Procedure
), Loc
);
7390 -----------------------------------
7391 -- Register_Predefined_Primitive --
7392 -----------------------------------
7394 function Register_Predefined_Primitive
7396 Prim
: Entity_Id
) return List_Id
7398 L
: constant List_Id
:= New_List
;
7399 Tagged_Typ
: constant Entity_Id
:= Find_Dispatching_Type
(Prim
);
7402 Iface_DT_Ptr
: Elmt_Id
;
7403 SS_Thunk_Id
: Entity_Id
;
7404 SS_Thunk_Code
: Node_Id
;
7405 Thunk_Id
: Entity_Id
;
7406 Thunk_Code
: List_Id
;
7409 if No
(Access_Disp_Table
(Tagged_Typ
))
7410 or else not Has_Interfaces
(Tagged_Typ
)
7411 or else not RTE_Available
(RE_Interface_Tag
)
7412 or else Restriction_Active
(No_Dispatching_Calls
)
7417 -- Skip the first two access-to-dispatch-table pointers since they
7418 -- leads to the primary dispatch table (predefined DT and user
7419 -- defined DT). We are only concerned with the secondary dispatch
7420 -- table pointers. Note that the access-to- dispatch-table pointer
7421 -- corresponds to the first implemented interface retrieved below.
7424 Next_Elmt
(Next_Elmt
(First_Elmt
(Access_Disp_Table
(Tagged_Typ
))));
7426 while Present
(Iface_DT_Ptr
)
7427 and then Ekind
(Node
(Iface_DT_Ptr
)) = E_Constant
7429 pragma Assert
(Has_Thunks
(Node
(Iface_DT_Ptr
)));
7431 Expand_Interface_Thunk
7432 (Prim
, Thunk_Id
, Thunk_Code
, Related_Type
(Node
(Iface_DT_Ptr
)));
7434 if Present
(Thunk_Id
) then
7435 Append_List_To
(L
, Thunk_Code
);
7438 Expand_Secondary_Stack_Thunk
(E
, SS_Thunk_Id
, SS_Thunk_Code
);
7440 if Present
(SS_Thunk_Id
) then
7442 Append_To
(L
, SS_Thunk_Code
);
7446 Build_Set_Predefined_Prim_Op_Address
(Loc
,
7448 New_Occurrence_Of
(Node
(Next_Elmt
(Iface_DT_Ptr
)), Loc
),
7449 Position
=> DT_Position
(Prim
),
7451 Unchecked_Convert_To
(RTE
(RE_Prim_Ptr
),
7452 Make_Attribute_Reference
(Loc
,
7453 Prefix
=> New_Occurrence_Of
(Thunk_Id
, Loc
),
7454 Attribute_Name
=> Name_Unrestricted_Access
))));
7457 Build_Set_Predefined_Prim_Op_Address
(Loc
,
7460 (Node
(Next_Elmt
(Next_Elmt
(Next_Elmt
(Iface_DT_Ptr
)))),
7462 Position
=> DT_Position
(Prim
),
7464 Unchecked_Convert_To
(RTE
(RE_Prim_Ptr
),
7465 Make_Attribute_Reference
(Loc
,
7466 Prefix
=> New_Occurrence_Of
(E
, Loc
),
7467 Attribute_Name
=> Name_Unrestricted_Access
))));
7470 -- Skip the tag of the predefined primitives dispatch table
7472 Next_Elmt
(Iface_DT_Ptr
);
7473 pragma Assert
(Has_Thunks
(Node
(Iface_DT_Ptr
)));
7475 -- Skip tag of the no-thunks dispatch table
7477 Next_Elmt
(Iface_DT_Ptr
);
7478 pragma Assert
(not Has_Thunks
(Node
(Iface_DT_Ptr
)));
7480 -- Skip tag of predefined primitives no-thunks dispatch table
7482 Next_Elmt
(Iface_DT_Ptr
);
7483 pragma Assert
(not Has_Thunks
(Node
(Iface_DT_Ptr
)));
7485 Next_Elmt
(Iface_DT_Ptr
);
7489 end Register_Predefined_Primitive
;
7491 ------------------------
7492 -- Register_Primitive --
7493 ------------------------
7495 function Register_Primitive
7497 Prim
: Entity_Id
) return List_Id
7499 L
: constant List_Id
:= New_List
;
7503 Iface_Prim
: Entity_Id
;
7504 Iface_Typ
: Entity_Id
;
7505 Iface_DT_Ptr
: Entity_Id
;
7506 Iface_DT_Elmt
: Elmt_Id
;
7508 SS_Thunk_Id
: Entity_Id
;
7509 SS_Thunk_Code
: Node_Id
;
7511 Tag_Typ
: Entity_Id
;
7512 Thunk_Id
: Entity_Id
;
7513 Thunk_Code
: List_Id
;
7516 pragma Assert
(not Restriction_Active
(No_Dispatching_Calls
));
7518 -- Do not register eliminated primitives in the dispatch table
7520 if not RTE_Available
(RE_Tag
)
7521 or else Is_Eliminated
(Ultimate_Alias
(Prim
))
7522 or else Generate_SCIL
7527 -- Primitive associated with a tagged type
7529 if No
(Interface_Alias
(Prim
)) then
7530 Tag_Typ
:= Scope
(DTC_Entity
(Prim
));
7531 Pos
:= DT_Position
(Prim
);
7532 Tag
:= First_Tag_Component
(Tag_Typ
);
7535 Expand_Secondary_Stack_Thunk
(E
, SS_Thunk_Id
, SS_Thunk_Code
);
7537 if Present
(SS_Thunk_Id
) then
7539 Append_To
(L
, SS_Thunk_Code
);
7542 if Is_Predefined_Dispatching_Operation
(Prim
)
7543 or else Is_Predefined_Dispatching_Alias
(Prim
)
7546 Node
(Next_Elmt
(First_Elmt
(Access_Disp_Table
(Tag_Typ
))));
7549 Build_Set_Predefined_Prim_Op_Address
(Loc
,
7550 Tag_Node
=> New_Occurrence_Of
(DT_Ptr
, Loc
),
7553 Unchecked_Convert_To
(RTE
(RE_Prim_Ptr
),
7554 Make_Attribute_Reference
(Loc
,
7555 Prefix
=> New_Occurrence_Of
(E
, Loc
),
7556 Attribute_Name
=> Name_Unrestricted_Access
))));
7558 -- Register copy of the pointer to the 'size primitive in the TSD
7560 if Chars
(Prim
) = Name_uSize
7561 and then RTE_Record_Component_Available
(RE_Size_Func
)
7563 DT_Ptr
:= Node
(First_Elmt
(Access_Disp_Table
(Tag_Typ
)));
7565 Build_Set_Size_Function
(Loc
,
7566 Tag_Node
=> New_Occurrence_Of
(DT_Ptr
, Loc
),
7567 Size_Func
=> Prim
));
7571 pragma Assert
(Pos
/= Uint_0
and then Pos
<= DT_Entry_Count
(Tag
));
7573 -- Skip registration of primitives located in the C++ part of the
7574 -- dispatch table. Their slot is set by the IC routine.
7576 if not Is_CPP_Class
(Root_Type
(Tag_Typ
))
7577 or else Pos
> CPP_Num_Prims
(Tag_Typ
)
7579 DT_Ptr
:= Node
(First_Elmt
(Access_Disp_Table
(Tag_Typ
)));
7581 Build_Set_Prim_Op_Address
(Loc
,
7583 Tag_Node
=> New_Occurrence_Of
(DT_Ptr
, Loc
),
7586 Unchecked_Convert_To
(RTE
(RE_Prim_Ptr
),
7587 Make_Attribute_Reference
(Loc
,
7588 Prefix
=> New_Occurrence_Of
(E
, Loc
),
7589 Attribute_Name
=> Name_Unrestricted_Access
))));
7593 -- Ada 2005 (AI-251): Primitive associated with an interface type
7595 -- Generate the code of the thunk only if the interface type is not an
7596 -- immediate ancestor of Typ; otherwise the dispatch table associated
7597 -- with the interface is the primary dispatch table and we have nothing
7601 Tag_Typ
:= Find_Dispatching_Type
(Alias
(Prim
));
7602 Iface_Typ
:= Find_Dispatching_Type
(Interface_Alias
(Prim
));
7604 pragma Assert
(Is_Interface
(Iface_Typ
));
7606 -- No action needed for interfaces that are ancestors of Typ because
7607 -- their primitives are located in the primary dispatch table.
7609 if Is_Ancestor
(Iface_Typ
, Tag_Typ
, Use_Full_View
=> True) then
7612 -- No action needed for primitives located in the C++ part of the
7613 -- dispatch table. Their slot is set by the IC routine.
7615 elsif Is_CPP_Class
(Root_Type
(Tag_Typ
))
7616 and then DT_Position
(Alias
(Prim
)) <= CPP_Num_Prims
(Tag_Typ
)
7617 and then not Is_Predefined_Dispatching_Operation
(Prim
)
7618 and then not Is_Predefined_Dispatching_Alias
(Prim
)
7623 Expand_Interface_Thunk
(Prim
, Thunk_Id
, Thunk_Code
, Iface_Typ
);
7625 if Present
(Thunk_Id
)
7626 and then not Is_Ancestor
(Iface_Typ
, Tag_Typ
, Use_Full_View
=> True)
7628 -- Generate the code necessary to fill the appropriate entry of
7629 -- the secondary dispatch table of Prim's controlling type with
7630 -- Thunk_Id's address.
7632 Iface_DT_Elmt
:= Find_Interface_ADT
(Tag_Typ
, Iface_Typ
);
7633 Iface_DT_Ptr
:= Node
(Iface_DT_Elmt
);
7634 pragma Assert
(Has_Thunks
(Iface_DT_Ptr
));
7636 Iface_Prim
:= Interface_Alias
(Prim
);
7637 Pos
:= DT_Position
(Iface_Prim
);
7638 Tag
:= First_Tag_Component
(Iface_Typ
);
7640 Append_List_To
(L
, Thunk_Code
);
7642 E
:= Ultimate_Alias
(Prim
);
7643 Expand_Secondary_Stack_Thunk
(E
, SS_Thunk_Id
, SS_Thunk_Code
);
7645 if Present
(SS_Thunk_Id
) then
7647 Append_To
(L
, SS_Thunk_Code
);
7650 if Is_Predefined_Dispatching_Operation
(Prim
)
7651 or else Is_Predefined_Dispatching_Alias
(Prim
)
7654 Build_Set_Predefined_Prim_Op_Address
(Loc
,
7656 New_Occurrence_Of
(Node
(Next_Elmt
(Iface_DT_Elmt
)), Loc
),
7659 Unchecked_Convert_To
(RTE
(RE_Prim_Ptr
),
7660 Make_Attribute_Reference
(Loc
,
7661 Prefix
=> New_Occurrence_Of
(Thunk_Id
, Loc
),
7662 Attribute_Name
=> Name_Unrestricted_Access
))));
7664 Next_Elmt
(Iface_DT_Elmt
);
7665 Next_Elmt
(Iface_DT_Elmt
);
7666 Iface_DT_Ptr
:= Node
(Iface_DT_Elmt
);
7667 pragma Assert
(not Has_Thunks
(Iface_DT_Ptr
));
7670 Build_Set_Predefined_Prim_Op_Address
(Loc
,
7672 New_Occurrence_Of
(Node
(Next_Elmt
(Iface_DT_Elmt
)), Loc
),
7675 Unchecked_Convert_To
(RTE
(RE_Prim_Ptr
),
7676 Make_Attribute_Reference
(Loc
,
7677 Prefix
=> New_Occurrence_Of
(E
, Loc
),
7678 Attribute_Name
=> Name_Unrestricted_Access
))));
7681 pragma Assert
(Pos
/= Uint_0
7682 and then Pos
<= DT_Entry_Count
(Tag
));
7685 Build_Set_Prim_Op_Address
(Loc
,
7687 Tag_Node
=> New_Occurrence_Of
(Iface_DT_Ptr
, Loc
),
7690 Unchecked_Convert_To
(RTE
(RE_Prim_Ptr
),
7691 Make_Attribute_Reference
(Loc
,
7692 Prefix
=> New_Occurrence_Of
(Thunk_Id
, Loc
),
7693 Attribute_Name
=> Name_Unrestricted_Access
))));
7695 Next_Elmt
(Iface_DT_Elmt
);
7696 Next_Elmt
(Iface_DT_Elmt
);
7697 Iface_DT_Ptr
:= Node
(Iface_DT_Elmt
);
7698 pragma Assert
(not Has_Thunks
(Iface_DT_Ptr
));
7701 Build_Set_Prim_Op_Address
(Loc
,
7703 Tag_Node
=> New_Occurrence_Of
(Iface_DT_Ptr
, Loc
),
7706 Unchecked_Convert_To
(RTE
(RE_Prim_Ptr
),
7707 Make_Attribute_Reference
(Loc
,
7708 Prefix
=> New_Occurrence_Of
(E
, Loc
),
7709 Attribute_Name
=> Name_Unrestricted_Access
))));
7716 end Register_Primitive
;
7718 -------------------------
7719 -- Set_All_DT_Position --
7720 -------------------------
7722 procedure Set_All_DT_Position
(Typ
: Entity_Id
) is
7724 function In_Predef_Prims_DT
(Prim
: Entity_Id
) return Boolean;
7725 -- Returns True if Prim is located in the dispatch table of
7726 -- predefined primitives
7728 procedure Validate_Position
(Prim
: Entity_Id
);
7729 -- Check that position assigned to Prim is completely safe (it has not
7730 -- been assigned to a previously defined primitive operation of Typ).
7732 ------------------------
7733 -- In_Predef_Prims_DT --
7734 ------------------------
7736 function In_Predef_Prims_DT
(Prim
: Entity_Id
) return Boolean is
7738 -- Predefined primitives
7740 if Is_Predefined_Dispatching_Operation
(Prim
) then
7743 -- Renamings of predefined primitives
7745 elsif Present
(Alias
(Prim
))
7746 and then Is_Predefined_Dispatching_Operation
(Ultimate_Alias
(Prim
))
7748 if Chars
(Ultimate_Alias
(Prim
)) /= Name_Op_Eq
then
7751 -- An overriding operation that is a user-defined renaming of
7752 -- predefined equality inherits its slot from the overridden
7753 -- operation. Otherwise it is treated as a predefined op and
7754 -- occupies the same predefined slot as equality. A call to it is
7755 -- transformed into a call to its alias, which is the predefined
7756 -- equality op. A dispatching call thus uses the proper slot if
7757 -- operation is further inherited and called with class-wide
7762 not Comes_From_Source
(Prim
)
7763 or else No
(Overridden_Operation
(Prim
));
7766 -- User-defined primitives
7771 end In_Predef_Prims_DT
;
7773 -----------------------
7774 -- Validate_Position --
7775 -----------------------
7777 procedure Validate_Position
(Prim
: Entity_Id
) is
7782 -- Aliased primitives are safe
7784 if Present
(Alias
(Prim
)) then
7788 Op_Elmt
:= First_Elmt
(Primitive_Operations
(Typ
));
7789 while Present
(Op_Elmt
) loop
7790 Op
:= Node
(Op_Elmt
);
7792 -- No need to check against itself
7797 -- Primitive operations covering abstract interfaces are
7800 elsif Present
(Interface_Alias
(Op
)) then
7803 -- Predefined dispatching operations are completely safe. They
7804 -- are allocated at fixed positions in a separate table.
7806 elsif Is_Predefined_Dispatching_Operation
(Op
)
7807 or else Is_Predefined_Dispatching_Alias
(Op
)
7811 -- Aliased subprograms are safe
7813 elsif Present
(Alias
(Op
)) then
7816 elsif DT_Position
(Op
) = DT_Position
(Prim
)
7817 and then not Is_Predefined_Dispatching_Operation
(Op
)
7818 and then not Is_Predefined_Dispatching_Operation
(Prim
)
7819 and then not Is_Predefined_Dispatching_Alias
(Op
)
7820 and then not Is_Predefined_Dispatching_Alias
(Prim
)
7822 -- Handle aliased subprograms
7831 if Present
(Overridden_Operation
(Op_1
)) then
7832 Op_1
:= Overridden_Operation
(Op_1
);
7833 elsif Present
(Alias
(Op_1
)) then
7834 Op_1
:= Alias
(Op_1
);
7842 if Present
(Overridden_Operation
(Op_2
)) then
7843 Op_2
:= Overridden_Operation
(Op_2
);
7844 elsif Present
(Alias
(Op_2
)) then
7845 Op_2
:= Alias
(Op_2
);
7851 if Op_1
/= Op_2
then
7852 raise Program_Error
;
7857 Next_Elmt
(Op_Elmt
);
7859 end Validate_Position
;
7863 Parent_Typ
: constant Entity_Id
:= Etype
(Typ
);
7864 First_Prim
: constant Elmt_Id
:= First_Elmt
(Primitive_Operations
(Typ
));
7865 The_Tag
: constant Entity_Id
:= First_Tag_Component
(Typ
);
7867 Adjusted
: Boolean := False;
7868 Finalized
: Boolean := False;
7874 Prim_Elmt
: Elmt_Id
;
7876 -- Start of processing for Set_All_DT_Position
7879 pragma Assert
(Present
(First_Tag_Component
(Typ
)));
7881 -- Set the DT_Position for each primitive operation. Perform some sanity
7882 -- checks to avoid building inconsistent dispatch tables.
7884 -- First stage: Set DTC entity of all the primitive operations. This is
7885 -- required to properly read the DT_Position attribute in latter stages.
7887 Prim_Elmt
:= First_Prim
;
7889 while Present
(Prim_Elmt
) loop
7890 Prim
:= Node
(Prim_Elmt
);
7892 -- Predefined primitives have a separate dispatch table
7894 if not In_Predef_Prims_DT
(Prim
) then
7895 Count_Prim
:= Count_Prim
+ 1;
7898 Set_DTC_Entity_Value
(Typ
, Prim
);
7900 -- Clear any previous value of the DT_Position attribute. In this
7901 -- way we ensure that the final position of all the primitives is
7902 -- established by the following stages of this algorithm.
7904 Set_DT_Position_Value
(Prim
, No_Uint
);
7906 Next_Elmt
(Prim_Elmt
);
7910 Fixed_Prim
: array (Int
range 0 .. Count_Prim
) of Boolean :=
7915 procedure Handle_Inherited_Private_Subprograms
(Typ
: Entity_Id
);
7916 -- Called if Typ is declared in a nested package or a public child
7917 -- package to handle inherited primitives that were inherited by Typ
7918 -- in the visible part, but whose declaration was deferred because
7919 -- the parent operation was private and not visible at that point.
7921 procedure Set_Fixed_Prim
(Pos
: Nat
);
7922 -- Sets to true an element of the Fixed_Prim table to indicate
7923 -- that this entry of the dispatch table of Typ is occupied.
7925 ------------------------------------------
7926 -- Handle_Inherited_Private_Subprograms --
7927 ------------------------------------------
7929 procedure Handle_Inherited_Private_Subprograms
(Typ
: Entity_Id
) is
7932 Op_Elmt_2
: Elmt_Id
;
7933 Prim_Op
: Entity_Id
;
7934 Parent_Subp
: Entity_Id
;
7937 Op_List
:= Primitive_Operations
(Typ
);
7939 Op_Elmt
:= First_Elmt
(Op_List
);
7940 while Present
(Op_Elmt
) loop
7941 Prim_Op
:= Node
(Op_Elmt
);
7943 -- Search primitives that are implicit operations with an
7944 -- internal name whose parent operation has a normal name.
7946 if Present
(Alias
(Prim_Op
))
7947 and then Find_Dispatching_Type
(Alias
(Prim_Op
)) /= Typ
7948 and then not Comes_From_Source
(Prim_Op
)
7949 and then Is_Internal_Name
(Chars
(Prim_Op
))
7950 and then not Is_Internal_Name
(Chars
(Alias
(Prim_Op
)))
7952 Parent_Subp
:= Alias
(Prim_Op
);
7954 -- Check if the type has an explicit overriding for this
7957 Op_Elmt_2
:= Next_Elmt
(Op_Elmt
);
7958 while Present
(Op_Elmt_2
) loop
7959 if Chars
(Node
(Op_Elmt_2
)) = Chars
(Parent_Subp
)
7960 and then Type_Conformant
(Prim_Op
, Node
(Op_Elmt_2
))
7962 Set_DT_Position_Value
(Prim_Op
,
7963 DT_Position
(Parent_Subp
));
7964 Set_DT_Position_Value
(Node
(Op_Elmt_2
),
7965 DT_Position
(Parent_Subp
));
7966 Set_Fixed_Prim
(UI_To_Int
(DT_Position
(Prim_Op
)));
7968 goto Next_Primitive
;
7971 Next_Elmt
(Op_Elmt_2
);
7976 Next_Elmt
(Op_Elmt
);
7978 end Handle_Inherited_Private_Subprograms
;
7980 --------------------
7981 -- Set_Fixed_Prim --
7982 --------------------
7984 procedure Set_Fixed_Prim
(Pos
: Nat
) is
7986 pragma Assert
(Pos
<= Count_Prim
);
7987 Fixed_Prim
(Pos
) := True;
7989 when Constraint_Error
=>
7990 raise Program_Error
;
7994 -- In case of nested packages and public child package it may be
7995 -- necessary a special management on inherited subprograms so that
7996 -- the dispatch table is properly filled.
7998 if Ekind
(Scope
(Scope
(Typ
))) = E_Package
7999 and then Scope
(Scope
(Typ
)) /= Standard_Standard
8000 and then ((Is_Derived_Type
(Typ
) and then not Is_Private_Type
(Typ
))
8002 (Nkind
(Parent
(Typ
)) = N_Private_Extension_Declaration
8003 and then Is_Generic_Type
(Typ
)))
8004 and then In_Open_Scopes
(Scope
(Etype
(Typ
)))
8005 and then Is_Base_Type
(Typ
)
8007 Handle_Inherited_Private_Subprograms
(Typ
);
8010 -- Second stage: Register fixed entries
8013 Prim_Elmt
:= First_Prim
;
8014 while Present
(Prim_Elmt
) loop
8015 Prim
:= Node
(Prim_Elmt
);
8017 -- Predefined primitives have a separate table and all its
8018 -- entries are at predefined fixed positions.
8020 if In_Predef_Prims_DT
(Prim
) then
8021 if Is_Predefined_Dispatching_Operation
(Prim
) then
8022 Set_DT_Position_Value
(Prim
,
8023 Default_Prim_Op_Position
(Prim
));
8025 else pragma Assert
(Present
(Alias
(Prim
)));
8026 Set_DT_Position_Value
(Prim
,
8027 Default_Prim_Op_Position
(Ultimate_Alias
(Prim
)));
8030 -- Overriding primitives of ancestor abstract interfaces
8032 elsif Present
(Interface_Alias
(Prim
))
8033 and then Is_Ancestor
8034 (Find_Dispatching_Type
(Interface_Alias
(Prim
)), Typ
,
8035 Use_Full_View
=> True)
8037 pragma Assert
(No
(DT_Position
(Prim
)));
8038 pragma Assert
(Present
(DTC_Entity
(Interface_Alias
(Prim
))));
8040 E
:= Interface_Alias
(Prim
);
8041 Set_DT_Position_Value
(Prim
, DT_Position
(E
));
8044 (No
(DT_Position
(Alias
(Prim
)))
8045 or else DT_Position
(Alias
(Prim
)) = DT_Position
(E
));
8046 Set_DT_Position_Value
(Alias
(Prim
), DT_Position
(E
));
8047 Set_Fixed_Prim
(UI_To_Int
(DT_Position
(Prim
)));
8049 -- Overriding primitives must use the same entry as the overridden
8050 -- primitive. Note that the Alias of the operation is set when the
8051 -- operation is declared by a renaming, in which case it is not
8052 -- overriding. If it renames another primitive it will use the
8053 -- same dispatch table slot, but if it renames an operation in a
8054 -- nested package it's a new primitive and will have its own slot.
8056 elsif No
(Interface_Alias
(Prim
))
8057 and then Present
(Alias
(Prim
))
8058 and then Chars
(Prim
) = Chars
(Alias
(Prim
))
8059 and then Nkind
(Unit_Declaration_Node
(Prim
)) /=
8060 N_Subprogram_Renaming_Declaration
8063 Par_Type
: constant Entity_Id
:=
8064 Find_Dispatching_Type
(Alias
(Prim
));
8067 if Present
(Par_Type
)
8068 and then Par_Type
/= Typ
8069 and then Is_Ancestor
(Par_Type
, Typ
, Use_Full_View
=> True)
8070 and then Present
(DTC_Entity
(Alias
(Prim
)))
8073 Set_DT_Position_Value
(Prim
, DT_Position
(E
));
8075 if not Is_Predefined_Dispatching_Alias
(E
) then
8076 Set_Fixed_Prim
(UI_To_Int
(DT_Position
(E
)));
8082 Next_Elmt
(Prim_Elmt
);
8085 -- Third stage: Fix the position of all the new primitives. Entries
8086 -- associated with primitives covering interfaces are handled in a
8089 Prim_Elmt
:= First_Prim
;
8090 while Present
(Prim_Elmt
) loop
8091 Prim
:= Node
(Prim_Elmt
);
8093 -- Skip primitives previously set entries
8095 if Present
(DT_Position
(Prim
)) then
8098 -- Primitives covering interface primitives are handled later
8100 elsif Present
(Interface_Alias
(Prim
)) then
8104 -- Take the next available position in the DT
8107 Nb_Prim
:= Nb_Prim
+ 1;
8108 pragma Assert
(Nb_Prim
<= Count_Prim
);
8109 exit when not Fixed_Prim
(Nb_Prim
);
8112 Set_DT_Position_Value
(Prim
, UI_From_Int
(Nb_Prim
));
8113 Set_Fixed_Prim
(Nb_Prim
);
8116 Next_Elmt
(Prim_Elmt
);
8120 -- Fourth stage: Complete the decoration of primitives covering
8121 -- interfaces (that is, propagate the DT_Position attribute from
8122 -- the aliased primitive)
8124 Prim_Elmt
:= First_Prim
;
8125 while Present
(Prim_Elmt
) loop
8126 Prim
:= Node
(Prim_Elmt
);
8128 if No
(DT_Position
(Prim
))
8129 and then Present
(Interface_Alias
(Prim
))
8131 pragma Assert
(Present
(Alias
(Prim
))
8132 and then Find_Dispatching_Type
(Alias
(Prim
)) = Typ
);
8134 -- Check if this entry will be placed in the primary DT
8137 (Find_Dispatching_Type
(Interface_Alias
(Prim
)), Typ
,
8138 Use_Full_View
=> True)
8140 pragma Assert
(Present
(DT_Position
(Alias
(Prim
))));
8141 Set_DT_Position_Value
(Prim
, DT_Position
(Alias
(Prim
)));
8143 -- Otherwise it will be placed in the secondary DT
8147 (Present
(DT_Position
(Interface_Alias
(Prim
))));
8148 Set_DT_Position_Value
(Prim
,
8149 DT_Position
(Interface_Alias
(Prim
)));
8153 Next_Elmt
(Prim_Elmt
);
8156 -- Generate listing showing the contents of the dispatch tables. This
8157 -- action is done before some further static checks because in case of
8158 -- critical errors caused by a wrong dispatch table we need to see the
8159 -- contents of such table.
8161 if Debug_Flag_ZZ
then
8165 -- Final stage: Ensure that the table is correct plus some further
8166 -- verifications concerning the primitives.
8168 Prim_Elmt
:= First_Prim
;
8170 while Present
(Prim_Elmt
) loop
8171 Prim
:= Node
(Prim_Elmt
);
8173 -- At this point all the primitives MUST have a position in the
8176 if No
(DT_Position
(Prim
)) then
8177 raise Program_Error
;
8180 -- Calculate real size of the dispatch table
8182 if not In_Predef_Prims_DT
(Prim
)
8183 and then UI_To_Int
(DT_Position
(Prim
)) > DT_Length
8185 DT_Length
:= UI_To_Int
(DT_Position
(Prim
));
8188 -- Ensure that the assigned position to non-predefined dispatching
8189 -- operations in the dispatch table is correct.
8191 if not Is_Predefined_Dispatching_Operation
(Prim
)
8192 and then not Is_Predefined_Dispatching_Alias
(Prim
)
8194 Validate_Position
(Prim
);
8197 if Chars
(Prim
) = Name_Finalize
then
8201 if Chars
(Prim
) = Name_Adjust
then
8205 -- An abstract operation cannot be declared in the private part for a
8206 -- visible abstract type, because it can't be overridden outside this
8207 -- package hierarchy. For explicit declarations this is checked at
8208 -- the point of declaration, but for inherited operations it must be
8209 -- done when building the dispatch table.
8211 -- Ada 2005 (AI-251): Primitives associated with interfaces are
8212 -- excluded from this check because interfaces must be visible in
8213 -- the public and private part (RM 7.3 (7.3/2))
8215 -- We disable this check in Relaxed_RM_Semantics mode, to accommodate
8218 if not Relaxed_RM_Semantics
8219 and then Is_Abstract_Type
(Typ
)
8220 and then Is_Abstract_Subprogram
(Prim
)
8221 and then Present
(Alias
(Prim
))
8222 and then not Is_Interface
8223 (Find_Dispatching_Type
(Ultimate_Alias
(Prim
)))
8224 and then No
(Interface_Alias
(Prim
))
8225 and then Is_Derived_Type
(Typ
)
8226 and then In_Private_Part
(Current_Scope
)
8228 List_Containing
(Parent
(Prim
)) =
8229 Private_Declarations
(Package_Specification
(Current_Scope
))
8230 and then Original_View_In_Visible_Part
(Typ
)
8232 -- We exclude Input and Output stream operations because
8233 -- Limited_Controlled inherits useless Input and Output stream
8234 -- operations from Root_Controlled, which can never be overridden.
8235 -- Move this check to sem???
8237 if not Is_TSS
(Prim
, TSS_Stream_Input
)
8239 not Is_TSS
(Prim
, TSS_Stream_Output
)
8242 ("abstract inherited private operation&" &
8243 " must be overridden (RM 3.9.3(10))",
8244 Parent
(Typ
), Prim
);
8248 Next_Elmt
(Prim_Elmt
);
8253 if Is_Controlled
(Typ
) then
8254 if not Finalized
then
8256 ("controlled type has no explicit Finalize method??", Typ
);
8258 elsif not Adjusted
then
8260 ("controlled type has no explicit Adjust method??", Typ
);
8264 -- Set the final size of the Dispatch Table
8266 Set_DT_Entry_Count
(The_Tag
, UI_From_Int
(DT_Length
));
8268 -- The derived type must have at least as many components as its parent
8269 -- (for root types Etype points to itself and the test cannot fail).
8271 if DT_Entry_Count
(The_Tag
) <
8272 DT_Entry_Count
(First_Tag_Component
(Parent_Typ
))
8274 raise Program_Error
;
8276 end Set_All_DT_Position
;
8278 --------------------------
8279 -- Set_CPP_Constructors --
8280 --------------------------
8282 procedure Set_CPP_Constructors
(Typ
: Entity_Id
) is
8284 function Gen_Parameters_Profile
(E
: Entity_Id
) return List_Id
;
8285 -- Duplicate the parameters profile of the imported C++ constructor
8286 -- adding the "this" pointer to the object as the additional first
8287 -- parameter under the usual form _Init : in out Typ.
8289 ----------------------------
8290 -- Gen_Parameters_Profile --
8291 ----------------------------
8293 function Gen_Parameters_Profile
(E
: Entity_Id
) return List_Id
is
8294 Loc
: constant Source_Ptr
:= Sloc
(E
);
8301 Make_Parameter_Specification
(Loc
,
8302 Defining_Identifier
=>
8303 Make_Defining_Identifier
(Loc
, Name_uInit
),
8305 Out_Present
=> True,
8306 Parameter_Type
=> New_Occurrence_Of
(Typ
, Loc
)));
8308 P
:= First
(Parameter_Specifications
(Parent
(E
)));
8309 while Present
(P
) loop
8311 Make_Parameter_Specification
(Loc
,
8312 Defining_Identifier
=>
8313 Make_Defining_Identifier
(Loc
,
8314 Chars
=> Chars
(Defining_Identifier
(P
))),
8315 Parameter_Type
=> New_Copy_Tree
(Parameter_Type
(P
)),
8316 Expression
=> New_Copy_Tree
(Expression
(P
))));
8321 end Gen_Parameters_Profile
;
8327 Found
: Boolean := False;
8333 Covers_Default_Constructor
: Entity_Id
:= Empty
;
8335 -- Start of processing for Set_CPP_Constructor
8338 pragma Assert
(Is_CPP_Class
(Typ
));
8340 -- Look for the constructor entities
8342 E
:= Next_Entity
(Typ
);
8343 while Present
(E
) loop
8344 if Ekind
(E
) = E_Function
8345 and then Is_Constructor
(E
)
8349 Parms
:= Gen_Parameters_Profile
(E
);
8350 IP
:= Make_Defining_Identifier
(Loc
, Make_Init_Proc_Name
(Typ
));
8352 -- Case 1: Constructor of untagged type
8354 -- If the C++ class has no virtual methods then the matching Ada
8355 -- type is an untagged record type. In such case there is no need
8356 -- to generate a wrapper of the C++ constructor because the _tag
8357 -- component is not available.
8359 if not Is_Tagged_Type
(Typ
) then
8361 (Make_Subprogram_Declaration
(Loc
,
8363 Make_Procedure_Specification
(Loc
,
8364 Defining_Unit_Name
=> IP
,
8365 Parameter_Specifications
=> Parms
)));
8367 Set_Init_Proc
(Typ
, IP
);
8368 Set_Is_Imported
(IP
);
8369 Set_Is_Constructor
(IP
);
8370 Set_Interface_Name
(IP
, Interface_Name
(E
));
8371 Set_Convention
(IP
, Convention_CPP
);
8373 Set_Has_Completion
(IP
);
8375 -- Case 2: Constructor of a tagged type
8377 -- In this case we generate the IP routine as a wrapper of the
8378 -- C++ constructor because IP must also save a copy of the _tag
8379 -- generated in the C++ side. The copy of the _tag is used by
8380 -- Build_CPP_Init_Procedure to elaborate derivations of C++ types.
8383 -- procedure IP (_init : in out Typ; ...) is
8384 -- procedure ConstructorP (_init : in out Typ; ...);
8385 -- pragma Import (ConstructorP);
8387 -- ConstructorP (_init, ...);
8388 -- if Typ._tag = null then
8389 -- Typ._tag := _init._tag;
8395 Body_Stmts
: constant List_Id
:= New_List
;
8396 Constructor_Id
: Entity_Id
;
8397 Constructor_Decl_Node
: Node_Id
;
8398 Init_Tags_List
: List_Id
;
8401 Constructor_Id
:= Make_Temporary
(Loc
, 'P');
8403 Constructor_Decl_Node
:=
8404 Make_Subprogram_Declaration
(Loc
,
8405 Make_Procedure_Specification
(Loc
,
8406 Defining_Unit_Name
=> Constructor_Id
,
8407 Parameter_Specifications
=> Parms
));
8409 Set_Is_Imported
(Constructor_Id
);
8410 Set_Is_Constructor
(Constructor_Id
);
8411 Set_Interface_Name
(Constructor_Id
, Interface_Name
(E
));
8412 Set_Convention
(Constructor_Id
, Convention_CPP
);
8413 Set_Is_Public
(Constructor_Id
);
8414 Set_Has_Completion
(Constructor_Id
);
8416 -- Build the init procedure as a wrapper of this constructor
8418 Parms
:= Gen_Parameters_Profile
(E
);
8420 -- Invoke the C++ constructor
8423 Actuals
: constant List_Id
:= New_List
;
8427 while Present
(P
) loop
8429 New_Occurrence_Of
(Defining_Identifier
(P
), Loc
));
8433 Append_To
(Body_Stmts
,
8434 Make_Procedure_Call_Statement
(Loc
,
8435 Name
=> New_Occurrence_Of
(Constructor_Id
, Loc
),
8436 Parameter_Associations
=> Actuals
));
8439 -- Initialize copies of C++ primary and secondary tags
8441 Init_Tags_List
:= New_List
;
8448 Tag_Elmt
:= First_Elmt
(Access_Disp_Table
(Typ
));
8449 Tag_Comp
:= First_Tag_Component
(Typ
);
8451 while Present
(Tag_Elmt
)
8452 and then Is_Tag
(Node
(Tag_Elmt
))
8454 -- Skip the following assertion with primary tags
8455 -- because Related_Type is not set on primary tag
8459 (Tag_Comp
= First_Tag_Component
(Typ
)
8460 or else Related_Type
(Node
(Tag_Elmt
))
8461 = Related_Type
(Tag_Comp
));
8463 Append_To
(Init_Tags_List
,
8464 Make_Assignment_Statement
(Loc
,
8466 New_Occurrence_Of
(Node
(Tag_Elmt
), Loc
),
8468 Make_Selected_Component
(Loc
,
8470 Make_Identifier
(Loc
, Name_uInit
),
8472 New_Occurrence_Of
(Tag_Comp
, Loc
))));
8474 Tag_Comp
:= Next_Tag_Component
(Tag_Comp
);
8475 Next_Elmt
(Tag_Elmt
);
8479 Append_To
(Body_Stmts
,
8480 Make_If_Statement
(Loc
,
8485 (Node
(First_Elmt
(Access_Disp_Table
(Typ
))),
8488 Unchecked_Convert_To
(RTE
(RE_Tag
),
8489 New_Occurrence_Of
(RTE
(RE_Null_Address
), Loc
))),
8490 Then_Statements
=> Init_Tags_List
));
8493 Make_Subprogram_Body
(Loc
,
8495 Make_Procedure_Specification
(Loc
,
8496 Defining_Unit_Name
=> IP
,
8497 Parameter_Specifications
=> Parms
),
8498 Declarations
=> New_List
(Constructor_Decl_Node
),
8499 Handled_Statement_Sequence
=>
8500 Make_Handled_Sequence_Of_Statements
(Loc
,
8501 Statements
=> Body_Stmts
,
8502 Exception_Handlers
=> No_List
));
8504 Discard_Node
(IP_Body
);
8505 Set_Init_Proc
(Typ
, IP
);
8509 -- If this constructor has parameters and all its parameters have
8510 -- defaults then it covers the default constructor. The semantic
8511 -- analyzer ensures that only one constructor with defaults covers
8512 -- the default constructor.
8514 if Present
(Parameter_Specifications
(Parent
(E
)))
8515 and then Needs_No_Actuals
(E
)
8517 Covers_Default_Constructor
:= IP
;
8524 -- If there are no constructors, mark the type as abstract since we
8525 -- won't be able to declare objects of that type.
8528 Set_Is_Abstract_Type
(Typ
);
8531 -- Handle constructor that has all its parameters with defaults and
8532 -- hence it covers the default constructor. We generate a wrapper IP
8533 -- which calls the covering constructor.
8535 if Present
(Covers_Default_Constructor
) then
8537 Body_Stmts
: List_Id
;
8540 Loc
:= Sloc
(Covers_Default_Constructor
);
8542 Body_Stmts
:= New_List
(
8543 Make_Procedure_Call_Statement
(Loc
,
8545 New_Occurrence_Of
(Covers_Default_Constructor
, Loc
),
8546 Parameter_Associations
=> New_List
(
8547 Make_Identifier
(Loc
, Name_uInit
))));
8549 IP
:= Make_Defining_Identifier
(Loc
, Make_Init_Proc_Name
(Typ
));
8552 Make_Subprogram_Body
(Loc
,
8554 Make_Procedure_Specification
(Loc
,
8555 Defining_Unit_Name
=> IP
,
8556 Parameter_Specifications
=> New_List
(
8557 Make_Parameter_Specification
(Loc
,
8558 Defining_Identifier
=>
8559 Make_Defining_Identifier
(Loc
, Name_uInit
),
8560 Parameter_Type
=> New_Occurrence_Of
(Typ
, Loc
)))),
8562 Declarations
=> No_List
,
8564 Handled_Statement_Sequence
=>
8565 Make_Handled_Sequence_Of_Statements
(Loc
,
8566 Statements
=> Body_Stmts
,
8567 Exception_Handlers
=> No_List
));
8569 Discard_Node
(IP_Body
);
8570 Set_Init_Proc
(Typ
, IP
);
8574 -- If the CPP type has constructors then it must import also the default
8575 -- C++ constructor. It is required for default initialization of objects
8576 -- of the type. It is also required to elaborate objects of Ada types
8577 -- that are defined as derivations of this CPP type.
8579 if Has_CPP_Constructors
(Typ
)
8580 and then No
(Init_Proc
(Typ
))
8582 Error_Msg_N
("??default constructor must be imported from C++", Typ
);
8584 end Set_CPP_Constructors
;
8586 ---------------------------
8587 -- Set_DT_Position_Value --
8588 ---------------------------
8590 procedure Set_DT_Position_Value
(Prim
: Entity_Id
; Value
: Uint
) is
8592 Set_DT_Position
(Prim
, Value
);
8594 -- Propagate the value to the wrapped subprogram (if one is present)
8596 if Ekind
(Prim
) in E_Function | E_Procedure
8597 and then Is_Primitive_Wrapper
(Prim
)
8598 and then Present
(Wrapped_Entity
(Prim
))
8599 and then Is_Dispatching_Operation
(Wrapped_Entity
(Prim
))
8601 Set_DT_Position
(Wrapped_Entity
(Prim
), Value
);
8603 end Set_DT_Position_Value
;
8605 --------------------------
8606 -- Set_DTC_Entity_Value --
8607 --------------------------
8609 procedure Set_DTC_Entity_Value
8610 (Tagged_Type
: Entity_Id
;
8614 if Present
(Interface_Alias
(Prim
))
8615 and then Is_Interface
8616 (Find_Dispatching_Type
(Interface_Alias
(Prim
)))
8618 Set_DTC_Entity
(Prim
,
8621 Iface
=> Find_Dispatching_Type
(Interface_Alias
(Prim
))));
8623 Set_DTC_Entity
(Prim
,
8624 First_Tag_Component
(Tagged_Type
));
8627 -- Propagate the value to the wrapped subprogram (if one is present)
8629 if Ekind
(Prim
) in E_Function | E_Procedure
8630 and then Is_Primitive_Wrapper
(Prim
)
8631 and then Present
(Wrapped_Entity
(Prim
))
8632 and then Is_Dispatching_Operation
(Wrapped_Entity
(Prim
))
8634 Set_DTC_Entity
(Wrapped_Entity
(Prim
), DTC_Entity
(Prim
));
8636 end Set_DTC_Entity_Value
;
8642 function Tagged_Kind
(T
: Entity_Id
) return Node_Id
is
8643 Conc_Typ
: Entity_Id
;
8644 Loc
: constant Source_Ptr
:= Sloc
(T
);
8648 (Is_Tagged_Type
(T
) and then RTE_Available
(RE_Tagged_Kind
));
8652 if Is_Abstract_Type
(T
) then
8653 if Is_Limited_Record
(T
) then
8654 return New_Occurrence_Of
8655 (RTE
(RE_TK_Abstract_Limited_Tagged
), Loc
);
8657 return New_Occurrence_Of
8658 (RTE
(RE_TK_Abstract_Tagged
), Loc
);
8663 elsif Is_Concurrent_Record_Type
(T
) then
8664 Conc_Typ
:= Corresponding_Concurrent_Type
(T
);
8666 if Present
(Full_View
(Conc_Typ
)) then
8667 Conc_Typ
:= Full_View
(Conc_Typ
);
8670 if Ekind
(Conc_Typ
) = E_Protected_Type
then
8671 return New_Occurrence_Of
(RTE
(RE_TK_Protected
), Loc
);
8673 pragma Assert
(Ekind
(Conc_Typ
) = E_Task_Type
);
8674 return New_Occurrence_Of
(RTE
(RE_TK_Task
), Loc
);
8677 -- Regular tagged kinds
8680 if Is_Limited_Record
(T
) then
8681 return New_Occurrence_Of
(RTE
(RE_TK_Limited_Tagged
), Loc
);
8683 return New_Occurrence_Of
(RTE
(RE_TK_Tagged
), Loc
);
8692 procedure Write_DT
(Typ
: Entity_Id
) is
8697 -- Protect this procedure against wrong usage. Required because it will
8698 -- be used directly from GDB
8700 if not (Typ
<= Last_Node_Id
)
8701 or else not Is_Tagged_Type
(Typ
)
8703 Write_Str
("wrong usage: Write_DT must be used with tagged types");
8708 Write_Int
(Int
(Typ
));
8710 Write_Name
(Chars
(Typ
));
8712 if Is_Interface
(Typ
) then
8713 Write_Str
(" is interface");
8718 Elmt
:= First_Elmt
(Primitive_Operations
(Typ
));
8719 while Present
(Elmt
) loop
8720 Prim
:= Node
(Elmt
);
8723 -- Indicate if this primitive will be allocated in the primary
8724 -- dispatch table or in a secondary dispatch table associated
8725 -- with an abstract interface type
8727 if Present
(DTC_Entity
(Prim
)) then
8728 if Is_RTE
(Etype
(DTC_Entity
(Prim
)), RE_Tag
) then
8735 -- Output the node of this primitive operation and its name
8737 Write_Int
(Int
(Prim
));
8740 if Is_Predefined_Dispatching_Operation
(Prim
) then
8741 Write_Str
("(predefined) ");
8744 -- Prefix the name of the primitive with its corresponding tagged
8745 -- type to facilitate seeing inherited primitives.
8747 if Present
(Alias
(Prim
)) then
8749 (Chars
(Find_Dispatching_Type
(Ultimate_Alias
(Prim
))));
8751 Write_Name
(Chars
(Typ
));
8755 Write_Name
(Chars
(Prim
));
8757 -- Indicate if this primitive has an aliased primitive
8759 if Present
(Alias
(Prim
)) then
8760 Write_Str
(" (alias = ");
8761 Write_Int
(Int
(Alias
(Prim
)));
8763 -- If the DTC_Entity attribute is already set we can also output
8764 -- the name of the interface covered by this primitive (if any).
8766 if Ekind
(Alias
(Prim
)) in E_Function | E_Procedure
8767 and then Present
(DTC_Entity
(Alias
(Prim
)))
8768 and then Is_Interface
(Scope
(DTC_Entity
(Alias
(Prim
))))
8770 Write_Str
(" from interface ");
8771 Write_Name
(Chars
(Scope
(DTC_Entity
(Alias
(Prim
)))));
8774 if Present
(Interface_Alias
(Prim
)) then
8775 Write_Str
(", AI_Alias of ");
8777 if Is_Null_Interface_Primitive
(Interface_Alias
(Prim
)) then
8778 Write_Str
("null primitive ");
8782 (Chars
(Find_Dispatching_Type
(Interface_Alias
(Prim
))));
8784 Write_Int
(Int
(Interface_Alias
(Prim
)));
8790 -- Display the final position of this primitive in its associated
8791 -- (primary or secondary) dispatch table.
8793 if Present
(DTC_Entity
(Prim
))
8794 and then Present
(DT_Position
(Prim
))
8796 Write_Str
(" at #");
8797 Write_Int
(UI_To_Int
(DT_Position
(Prim
)));
8800 if Is_Abstract_Subprogram
(Prim
) then
8801 Write_Str
(" is abstract;");
8803 -- Check if this is a null primitive
8805 elsif Comes_From_Source
(Prim
)
8806 and then Ekind
(Prim
) = E_Procedure
8807 and then Null_Present
(Parent
(Prim
))
8809 Write_Str
(" is null;");
8812 if Is_Eliminated
(Ultimate_Alias
(Prim
)) then
8813 Write_Str
(" (eliminated)");
8816 if Is_Imported
(Prim
)
8817 and then Convention
(Prim
) = Convention_CPP
8819 Write_Str
(" (C++)");