1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2017, Free Software Foundation, Inc. --
11 -- GNAT is free software; you can redistribute it and/or modify it under --
12 -- terms of the GNU General Public License as published by the Free Soft- --
13 -- ware Foundation; either version 3, or (at your option) any later ver- --
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
16 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
17 -- for more details. You should have received a copy of the GNU General --
18 -- Public License distributed with GNAT; see file COPYING3. If not, go to --
19 -- http://www.gnu.org/licenses for a complete copy of the license. --
21 -- GNAT was originally developed by the GNAT team at New York University. --
22 -- Extensive contributions were provided by Ada Core Technologies Inc. --
24 ------------------------------------------------------------------------------
26 with Atree
; use Atree
;
27 with Checks
; use Checks
;
28 with Debug
; use Debug
;
29 with Einfo
; use Einfo
;
30 with Elists
; use Elists
;
31 with Errout
; use Errout
;
32 with Exp_Atag
; use Exp_Atag
;
33 with Exp_Ch6
; use Exp_Ch6
;
34 with Exp_CG
; use Exp_CG
;
35 with Exp_Dbug
; use Exp_Dbug
;
36 with Exp_Tss
; use Exp_Tss
;
37 with Exp_Util
; use Exp_Util
;
38 with Freeze
; use Freeze
;
39 with Ghost
; use Ghost
;
40 with Itypes
; use Itypes
;
41 with Layout
; use Layout
;
42 with Nlists
; use Nlists
;
43 with Nmake
; use Nmake
;
44 with Namet
; use Namet
;
46 with Output
; use Output
;
47 with Restrict
; use Restrict
;
48 with Rident
; use Rident
;
49 with Rtsfind
; use Rtsfind
;
51 with Sem_Aux
; use Sem_Aux
;
52 with Sem_Ch6
; use Sem_Ch6
;
53 with Sem_Ch7
; use Sem_Ch7
;
54 with Sem_Ch8
; use Sem_Ch8
;
55 with Sem_Disp
; use Sem_Disp
;
56 with Sem_Eval
; use Sem_Eval
;
57 with Sem_Res
; use Sem_Res
;
58 with Sem_Type
; use Sem_Type
;
59 with Sem_Util
; use Sem_Util
;
60 with Sinfo
; use Sinfo
;
61 with Sinput
; use Sinput
;
62 with Snames
; use Snames
;
63 with Stand
; use Stand
;
64 with Stringt
; use Stringt
;
65 with SCIL_LL
; use SCIL_LL
;
66 with Tbuild
; use Tbuild
;
68 package body Exp_Disp
is
70 -----------------------
71 -- Local Subprograms --
72 -----------------------
74 function Default_Prim_Op_Position
(E
: Entity_Id
) return Uint
;
75 -- Ada 2005 (AI-251): Returns the fixed position in the dispatch table
76 -- of the default primitive operations.
78 function Has_DT
(Typ
: Entity_Id
) return Boolean;
79 pragma Inline
(Has_DT
);
80 -- Returns true if we generate a dispatch table for tagged type Typ
82 function Is_Predefined_Dispatching_Alias
(Prim
: Entity_Id
) return Boolean;
83 -- Returns true if Prim is not a predefined dispatching primitive but it is
84 -- an alias of a predefined dispatching primitive (i.e. through a renaming)
86 function New_Value
(From
: Node_Id
) return Node_Id
;
87 -- From is the original Expression. New_Value is equivalent to a call to
88 -- Duplicate_Subexpr with an explicit dereference when From is an access
91 function Original_View_In_Visible_Part
(Typ
: Entity_Id
) return Boolean;
92 -- Check if the type has a private view or if the public view appears in
93 -- the visible part of a package spec.
97 Typ
: Entity_Id
) return Node_Id
;
98 -- Ada 2005 (AI-345): Determine the primitive operation kind of Prim
99 -- according to its type Typ. Return a reference to an RE_Prim_Op_Kind
100 -- enumeration value.
102 function Tagged_Kind
(T
: Entity_Id
) return Node_Id
;
103 -- Ada 2005 (AI-345): Determine the tagged kind of T and return a reference
104 -- to an RE_Tagged_Kind enumeration value.
106 ----------------------
107 -- Apply_Tag_Checks --
108 ----------------------
110 procedure Apply_Tag_Checks
(Call_Node
: Node_Id
) is
111 Loc
: constant Source_Ptr
:= Sloc
(Call_Node
);
112 Ctrl_Arg
: constant Node_Id
:= Controlling_Argument
(Call_Node
);
113 Ctrl_Typ
: constant Entity_Id
:= Base_Type
(Etype
(Ctrl_Arg
));
114 Param_List
: constant List_Id
:= Parameter_Associations
(Call_Node
);
120 Eq_Prim_Op
: Entity_Id
:= Empty
;
123 if No_Run_Time_Mode
then
124 Error_Msg_CRT
("tagged types", Call_Node
);
128 -- Apply_Tag_Checks is called directly from the semantics, so we
129 -- need a check to see whether expansion is active before proceeding.
130 -- In addition, there is no need to expand the call when compiling
131 -- under restriction No_Dispatching_Calls; the semantic analyzer has
132 -- previously notified the violation of this restriction.
134 if not Expander_Active
135 or else Restriction_Active
(No_Dispatching_Calls
)
140 -- Set subprogram. If this is an inherited operation that was
141 -- overridden, the body that is being called is its alias.
143 Subp
:= Entity
(Name
(Call_Node
));
145 if Present
(Alias
(Subp
))
146 and then Is_Inherited_Operation
(Subp
)
147 and then No
(DTC_Entity
(Subp
))
149 Subp
:= Alias
(Subp
);
152 -- Definition of the class-wide type and the tagged type
154 -- If the controlling argument is itself a tag rather than a tagged
155 -- object, then use the class-wide type associated with the subprogram's
156 -- controlling type. This case can occur when a call to an inherited
157 -- primitive has an actual that originated from a default parameter
158 -- given by a tag-indeterminate call and when there is no other
159 -- controlling argument providing the tag (AI-239 requires dispatching).
160 -- This capability of dispatching directly by tag is also needed by the
161 -- implementation of AI-260 (for the generic dispatching constructors).
163 if Ctrl_Typ
= RTE
(RE_Tag
)
164 or else (RTE_Available
(RE_Interface_Tag
)
165 and then Ctrl_Typ
= RTE
(RE_Interface_Tag
))
167 CW_Typ
:= Class_Wide_Type
(Find_Dispatching_Type
(Subp
));
169 -- Class_Wide_Type is applied to the expressions used to initialize
170 -- CW_Typ, to ensure that CW_Typ always denotes a class-wide type, since
171 -- there are cases where the controlling type is resolved to a specific
172 -- type (such as for designated types of arguments such as CW'Access).
174 elsif Is_Access_Type
(Ctrl_Typ
) then
175 CW_Typ
:= Class_Wide_Type
(Designated_Type
(Ctrl_Typ
));
178 CW_Typ
:= Class_Wide_Type
(Ctrl_Typ
);
181 Typ
:= Find_Specific_Type
(CW_Typ
);
183 if not Is_Limited_Type
(Typ
) then
184 Eq_Prim_Op
:= Find_Prim_Op
(Typ
, Name_Op_Eq
);
187 -- Dispatching call to C++ primitive
189 if Is_CPP_Class
(Typ
) then
192 -- Dispatching call to Ada primitive
194 elsif Present
(Param_List
) then
196 -- Generate the Tag checks when appropriate
198 Param
:= First_Actual
(Call_Node
);
199 while Present
(Param
) loop
201 -- No tag check with itself
203 if Param
= Ctrl_Arg
then
206 -- No tag check for parameter whose type is neither tagged nor
207 -- access to tagged (for access parameters)
209 elsif No
(Find_Controlling_Arg
(Param
)) then
212 -- No tag check for function dispatching on result if the
213 -- Tag given by the context is this one
215 elsif Find_Controlling_Arg
(Param
) = Ctrl_Arg
then
218 -- "=" is the only dispatching operation allowed to get operands
219 -- with incompatible tags (it just returns false). We use
220 -- Duplicate_Subexpr_Move_Checks instead of calling Relocate_Node
221 -- because the value will be duplicated to check the tags.
223 elsif Subp
= Eq_Prim_Op
then
226 -- No check in presence of suppress flags
228 elsif Tag_Checks_Suppressed
(Etype
(Param
))
229 or else (Is_Access_Type
(Etype
(Param
))
230 and then Tag_Checks_Suppressed
231 (Designated_Type
(Etype
(Param
))))
235 -- Optimization: no tag checks if the parameters are identical
237 elsif Is_Entity_Name
(Param
)
238 and then Is_Entity_Name
(Ctrl_Arg
)
239 and then Entity
(Param
) = Entity
(Ctrl_Arg
)
243 -- Now we need to generate the Tag check
246 -- Generate code for tag equality check
248 -- Perhaps should have Checks.Apply_Tag_Equality_Check???
250 Insert_Action
(Ctrl_Arg
,
251 Make_Implicit_If_Statement
(Call_Node
,
255 Make_Selected_Component
(Loc
,
256 Prefix
=> New_Value
(Ctrl_Arg
),
259 (First_Tag_Component
(Typ
), Loc
)),
262 Make_Selected_Component
(Loc
,
264 Unchecked_Convert_To
(Typ
, New_Value
(Param
)),
267 (First_Tag_Component
(Typ
), Loc
))),
270 New_List
(New_Constraint_Error
(Loc
))));
276 end Apply_Tag_Checks
;
278 ------------------------
279 -- Building_Static_DT --
280 ------------------------
282 function Building_Static_DT
(Typ
: Entity_Id
) return Boolean is
283 Root_Typ
: Entity_Id
:= Root_Type
(Typ
);
286 -- Handle private types
288 if Present
(Full_View
(Root_Typ
)) then
289 Root_Typ
:= Full_View
(Root_Typ
);
292 return Static_Dispatch_Tables
293 and then Is_Library_Level_Tagged_Type
(Typ
)
295 -- If the type is derived from a CPP class we cannot statically
296 -- build the dispatch tables because we must inherit primitives
297 -- from the CPP side.
299 and then not Is_CPP_Class
(Root_Typ
);
300 end Building_Static_DT
;
302 ----------------------------------
303 -- Build_Static_Dispatch_Tables --
304 ----------------------------------
306 procedure Build_Static_Dispatch_Tables
(N
: Entity_Id
) is
307 Target_List
: List_Id
;
309 procedure Build_Dispatch_Tables
(List
: List_Id
);
310 -- Build the static dispatch table of tagged types found in the list of
311 -- declarations. The generated nodes are added at the end of Target_List
313 procedure Build_Package_Dispatch_Tables
(N
: Node_Id
);
314 -- Build static dispatch tables associated with package declaration N
316 ---------------------------
317 -- Build_Dispatch_Tables --
318 ---------------------------
320 procedure Build_Dispatch_Tables
(List
: List_Id
) is
325 while Present
(D
) loop
327 -- Handle nested packages and package bodies recursively. The
328 -- generated code is placed on the Target_List established for
329 -- the enclosing compilation unit.
331 if Nkind
(D
) = N_Package_Declaration
then
332 Build_Package_Dispatch_Tables
(D
);
334 elsif Nkind
(D
) = N_Package_Body
then
335 Build_Dispatch_Tables
(Declarations
(D
));
337 elsif Nkind
(D
) = N_Package_Body_Stub
338 and then Present
(Library_Unit
(D
))
340 Build_Dispatch_Tables
341 (Declarations
(Proper_Body
(Unit
(Library_Unit
(D
)))));
343 -- Handle full type declarations and derivations of library level
346 elsif Nkind_In
(D
, N_Full_Type_Declaration
,
347 N_Derived_Type_Definition
)
348 and then Is_Library_Level_Tagged_Type
(Defining_Entity
(D
))
349 and then Ekind
(Defining_Entity
(D
)) /= E_Record_Subtype
350 and then not Is_Private_Type
(Defining_Entity
(D
))
352 -- We do not generate dispatch tables for the internal types
353 -- created for a type extension with unknown discriminants
354 -- The needed information is shared with the source type,
355 -- See Expand_N_Record_Extension.
357 if Is_Underlying_Record_View
(Defining_Entity
(D
))
359 (not Comes_From_Source
(Defining_Entity
(D
))
361 Has_Unknown_Discriminants
(Etype
(Defining_Entity
(D
)))
363 not Comes_From_Source
364 (First_Subtype
(Defining_Entity
(D
))))
368 Insert_List_After_And_Analyze
(Last
(Target_List
),
369 Make_DT
(Defining_Entity
(D
)));
372 -- Handle private types of library level tagged types. We must
373 -- exchange the private and full-view to ensure the correct
374 -- expansion. If the full view is a synchronized type ignore
375 -- the type because the table will be built for the corresponding
376 -- record type, that has its own declaration.
378 elsif (Nkind
(D
) = N_Private_Type_Declaration
379 or else Nkind
(D
) = N_Private_Extension_Declaration
)
380 and then Present
(Full_View
(Defining_Entity
(D
)))
383 E1
: constant Entity_Id
:= Defining_Entity
(D
);
384 E2
: constant Entity_Id
:= Full_View
(E1
);
387 if Is_Library_Level_Tagged_Type
(E2
)
388 and then Ekind
(E2
) /= E_Record_Subtype
389 and then not Is_Concurrent_Type
(E2
)
391 Exchange_Declarations
(E1
);
392 Insert_List_After_And_Analyze
(Last
(Target_List
),
394 Exchange_Declarations
(E2
);
401 end Build_Dispatch_Tables
;
403 -----------------------------------
404 -- Build_Package_Dispatch_Tables --
405 -----------------------------------
407 procedure Build_Package_Dispatch_Tables
(N
: Node_Id
) is
408 Spec
: constant Node_Id
:= Specification
(N
);
409 Id
: constant Entity_Id
:= Defining_Entity
(N
);
410 Vis_Decls
: constant List_Id
:= Visible_Declarations
(Spec
);
411 Priv_Decls
: constant List_Id
:= Private_Declarations
(Spec
);
416 if Present
(Priv_Decls
) then
417 Build_Dispatch_Tables
(Vis_Decls
);
418 Build_Dispatch_Tables
(Priv_Decls
);
420 elsif Present
(Vis_Decls
) then
421 Build_Dispatch_Tables
(Vis_Decls
);
425 end Build_Package_Dispatch_Tables
;
427 -- Start of processing for Build_Static_Dispatch_Tables
430 if not Expander_Active
431 or else not Tagged_Type_Expansion
436 if Nkind
(N
) = N_Package_Declaration
then
438 Spec
: constant Node_Id
:= Specification
(N
);
439 Vis_Decls
: constant List_Id
:= Visible_Declarations
(Spec
);
440 Priv_Decls
: constant List_Id
:= Private_Declarations
(Spec
);
443 if Present
(Priv_Decls
)
444 and then Is_Non_Empty_List
(Priv_Decls
)
446 Target_List
:= Priv_Decls
;
448 elsif not Present
(Vis_Decls
) then
449 Target_List
:= New_List
;
450 Set_Private_Declarations
(Spec
, Target_List
);
452 Target_List
:= Vis_Decls
;
455 Build_Package_Dispatch_Tables
(N
);
458 else pragma Assert
(Nkind
(N
) = N_Package_Body
);
459 Target_List
:= Declarations
(N
);
460 Build_Dispatch_Tables
(Target_List
);
462 end Build_Static_Dispatch_Tables
;
464 ------------------------------
465 -- Convert_Tag_To_Interface --
466 ------------------------------
468 function Convert_Tag_To_Interface
470 Expr
: Node_Id
) return Node_Id
472 Loc
: constant Source_Ptr
:= Sloc
(Expr
);
473 Anon_Type
: Entity_Id
;
477 pragma Assert
(Is_Class_Wide_Type
(Typ
)
478 and then Is_Interface
(Typ
)
480 ((Nkind
(Expr
) = N_Selected_Component
481 and then Is_Tag
(Entity
(Selector_Name
(Expr
))))
483 (Nkind
(Expr
) = N_Function_Call
484 and then RTE_Available
(RE_Displace
)
485 and then Entity
(Name
(Expr
)) = RTE
(RE_Displace
))));
487 Anon_Type
:= Create_Itype
(E_Anonymous_Access_Type
, Expr
);
488 Set_Directly_Designated_Type
(Anon_Type
, Typ
);
489 Set_Etype
(Anon_Type
, Anon_Type
);
490 Set_Can_Never_Be_Null
(Anon_Type
);
492 -- Decorate the size and alignment attributes of the anonymous access
493 -- type, as required by the back end.
495 Layout_Type
(Anon_Type
);
497 if Nkind
(Expr
) = N_Selected_Component
498 and then Is_Tag
(Entity
(Selector_Name
(Expr
)))
501 Make_Explicit_Dereference
(Loc
,
502 Unchecked_Convert_To
(Anon_Type
,
503 Make_Attribute_Reference
(Loc
,
505 Attribute_Name
=> Name_Address
)));
508 Make_Explicit_Dereference
(Loc
,
509 Unchecked_Convert_To
(Anon_Type
, Expr
));
513 end Convert_Tag_To_Interface
;
519 function CPP_Num_Prims
(Typ
: Entity_Id
) return Nat
is
521 Tag_Comp
: Entity_Id
;
524 if not Is_Tagged_Type
(Typ
)
525 or else not Is_CPP_Class
(Root_Type
(Typ
))
530 CPP_Typ
:= Enclosing_CPP_Parent
(Typ
);
531 Tag_Comp
:= First_Tag_Component
(CPP_Typ
);
533 -- If number of primitives already set in the tag component, use it
535 if Present
(Tag_Comp
)
536 and then DT_Entry_Count
(Tag_Comp
) /= No_Uint
538 return UI_To_Int
(DT_Entry_Count
(Tag_Comp
));
540 -- Otherwise, count the primitives of the enclosing CPP type
548 Elmt
:= First_Elmt
(Primitive_Operations
(CPP_Typ
));
549 while Present
(Elmt
) loop
560 ------------------------------
561 -- Default_Prim_Op_Position --
562 ------------------------------
564 function Default_Prim_Op_Position
(E
: Entity_Id
) return Uint
is
565 TSS_Name
: TSS_Name_Type
;
568 Get_Name_String
(Chars
(E
));
571 (Name_Buffer
(Name_Len
- TSS_Name
'Length + 1 .. Name_Len
));
573 if Chars
(E
) = Name_uSize
then
576 elsif TSS_Name
= TSS_Stream_Read
then
579 elsif TSS_Name
= TSS_Stream_Write
then
582 elsif TSS_Name
= TSS_Stream_Input
then
585 elsif TSS_Name
= TSS_Stream_Output
then
588 elsif Chars
(E
) = Name_Op_Eq
then
591 elsif Chars
(E
) = Name_uAssign
then
594 elsif TSS_Name
= TSS_Deep_Adjust
then
597 elsif TSS_Name
= TSS_Deep_Finalize
then
600 -- In VM targets unconditionally allow obtaining the position associated
601 -- with predefined interface primitives since in these platforms any
602 -- tagged type has these primitives.
604 elsif Ada_Version
>= Ada_2005
or else not Tagged_Type_Expansion
then
605 if Chars
(E
) = Name_uDisp_Asynchronous_Select
then
608 elsif Chars
(E
) = Name_uDisp_Conditional_Select
then
611 elsif Chars
(E
) = Name_uDisp_Get_Prim_Op_Kind
then
614 elsif Chars
(E
) = Name_uDisp_Get_Task_Id
then
617 elsif Chars
(E
) = Name_uDisp_Requeue
then
620 elsif Chars
(E
) = Name_uDisp_Timed_Select
then
626 end Default_Prim_Op_Position
;
628 ----------------------
629 -- Elab_Flag_Needed --
630 ----------------------
632 function Elab_Flag_Needed
(Typ
: Entity_Id
) return Boolean is
634 return Ada_Version
>= Ada_2005
635 and then not Is_Interface
(Typ
)
636 and then Has_Interfaces
(Typ
);
637 end Elab_Flag_Needed
;
639 -----------------------------
640 -- Expand_Dispatching_Call --
641 -----------------------------
643 procedure Expand_Dispatching_Call
(Call_Node
: Node_Id
) is
644 Loc
: constant Source_Ptr
:= Sloc
(Call_Node
);
645 Call_Typ
: constant Entity_Id
:= Etype
(Call_Node
);
647 Ctrl_Arg
: constant Node_Id
:= Controlling_Argument
(Call_Node
);
648 Ctrl_Typ
: constant Entity_Id
:= Base_Type
(Etype
(Ctrl_Arg
));
649 Param_List
: constant List_Id
:= Parameter_Associations
(Call_Node
);
654 New_Call_Name
: Node_Id
;
655 New_Params
: List_Id
:= No_List
;
658 Subp_Ptr_Typ
: Entity_Id
;
659 Subp_Typ
: Entity_Id
;
661 Eq_Prim_Op
: Entity_Id
:= Empty
;
662 Controlling_Tag
: Node_Id
;
664 procedure Build_Class_Wide_Check
;
665 -- If the denoted subprogram has a class-wide precondition, generate a
666 -- check using that precondition before the dispatching call, because
667 -- this is the only class-wide precondition that applies to the call.
669 function New_Value
(From
: Node_Id
) return Node_Id
;
670 -- From is the original Expression. New_Value is equivalent to a call
671 -- to Duplicate_Subexpr with an explicit dereference when From is an
674 ----------------------------
675 -- Build_Class_Wide_Check --
676 ----------------------------
678 procedure Build_Class_Wide_Check
is
679 function Replace_Formals
(N
: Node_Id
) return Traverse_Result
;
680 -- Replace occurrences of the formals of the subprogram by the
681 -- corresponding actuals in the call, given that this check is
682 -- performed outside of the body of the subprogram.
684 ---------------------
685 -- Replace_Formals --
686 ---------------------
688 function Replace_Formals
(N
: Node_Id
) return Traverse_Result
is
690 if Is_Entity_Name
(N
)
691 and then Present
(Entity
(N
))
692 and then Is_Formal
(Entity
(N
))
699 F
:= First_Formal
(Subp
);
700 A
:= First_Actual
(Call_Node
);
701 while Present
(F
) loop
702 if F
= Entity
(N
) then
703 Rewrite
(N
, New_Copy_Tree
(A
));
705 -- If the formal is class-wide, and thus not a
706 -- controlling argument, preserve its type because
707 -- it may appear in a nested call with a class-wide
710 if Is_Class_Wide_Type
(Etype
(F
)) then
711 Set_Etype
(N
, Etype
(F
));
726 procedure Update
is new Traverse_Proc
(Replace_Formals
);
730 Str_Loc
: constant String := Build_Location_String
(Loc
);
736 -- Start of processing for Build_Class_Wide_Check
740 -- Locate class-wide precondition, if any
742 if Present
(Contract
(Subp
))
743 and then Present
(Pre_Post_Conditions
(Contract
(Subp
)))
745 Prec
:= Pre_Post_Conditions
(Contract
(Subp
));
747 while Present
(Prec
) loop
748 exit when Pragma_Name
(Prec
) = Name_Precondition
749 and then Class_Present
(Prec
);
750 Prec
:= Next_Pragma
(Prec
);
757 -- The expression for the precondition is analyzed within the
758 -- generated pragma. The message text is the last parameter of
759 -- the generated pragma, indicating source of precondition.
763 (Expression
(First
(Pragma_Argument_Associations
(Prec
))));
766 -- Build message indicating the failed precondition and the
767 -- dispatching call that caused it.
769 Msg
:= Expression
(Last
(Pragma_Argument_Associations
(Prec
)));
771 Append
(Global_Name_Buffer
, Strval
(Msg
));
772 Append
(Global_Name_Buffer
, " in dispatching call at ");
773 Append
(Global_Name_Buffer
, Str_Loc
);
774 Msg
:= Make_String_Literal
(Loc
, Name_Buffer
(1 .. Name_Len
));
776 Insert_Action
(Call_Node
,
777 Make_If_Statement
(Loc
,
778 Condition
=> Make_Op_Not
(Loc
, Cond
),
779 Then_Statements
=> New_List
(
780 Make_Procedure_Call_Statement
(Loc
,
782 New_Occurrence_Of
(RTE
(RE_Raise_Assert_Failure
), Loc
),
783 Parameter_Associations
=> New_List
(Msg
)))));
785 end Build_Class_Wide_Check
;
791 function New_Value
(From
: Node_Id
) return Node_Id
is
792 Res
: constant Node_Id
:= Duplicate_Subexpr
(From
);
794 if Is_Access_Type
(Etype
(From
)) then
796 Make_Explicit_Dereference
(Sloc
(From
),
806 SCIL_Node
: Node_Id
:= Empty
;
807 SCIL_Related_Node
: Node_Id
:= Call_Node
;
809 -- Start of processing for Expand_Dispatching_Call
812 if No_Run_Time_Mode
then
813 Error_Msg_CRT
("tagged types", Call_Node
);
817 -- Expand_Dispatching_Call is called directly from the semantics, so we
818 -- only proceed if the expander is active.
820 if not Expander_Active
822 -- And there is no need to expand the call if we are compiling under
823 -- restriction No_Dispatching_Calls; the semantic analyzer has
824 -- previously notified the violation of this restriction.
826 or else Restriction_Active
(No_Dispatching_Calls
)
828 -- No action needed if the dispatching call has been already expanded
830 or else Is_Expanded_Dispatching_Call
(Name
(Call_Node
))
835 -- Set subprogram. If this is an inherited operation that was
836 -- overridden, the body that is being called is its alias.
838 Subp
:= Entity
(Name
(Call_Node
));
840 if Present
(Alias
(Subp
))
841 and then Is_Inherited_Operation
(Subp
)
842 and then No
(DTC_Entity
(Subp
))
844 Subp
:= Alias
(Subp
);
847 Build_Class_Wide_Check
;
849 -- Definition of the class-wide type and the tagged type
851 -- If the controlling argument is itself a tag rather than a tagged
852 -- object, then use the class-wide type associated with the subprogram's
853 -- controlling type. This case can occur when a call to an inherited
854 -- primitive has an actual that originated from a default parameter
855 -- given by a tag-indeterminate call and when there is no other
856 -- controlling argument providing the tag (AI-239 requires dispatching).
857 -- This capability of dispatching directly by tag is also needed by the
858 -- implementation of AI-260 (for the generic dispatching constructors).
860 if Ctrl_Typ
= RTE
(RE_Tag
)
861 or else (RTE_Available
(RE_Interface_Tag
)
862 and then Ctrl_Typ
= RTE
(RE_Interface_Tag
))
864 CW_Typ
:= Class_Wide_Type
(Find_Dispatching_Type
(Subp
));
866 -- Class_Wide_Type is applied to the expressions used to initialize
867 -- CW_Typ, to ensure that CW_Typ always denotes a class-wide type, since
868 -- there are cases where the controlling type is resolved to a specific
869 -- type (such as for designated types of arguments such as CW'Access).
871 elsif Is_Access_Type
(Ctrl_Typ
) then
872 CW_Typ
:= Class_Wide_Type
(Designated_Type
(Ctrl_Typ
));
875 CW_Typ
:= Class_Wide_Type
(Ctrl_Typ
);
878 Typ
:= Find_Specific_Type
(CW_Typ
);
880 if not Is_Limited_Type
(Typ
) then
881 Eq_Prim_Op
:= Find_Prim_Op
(Typ
, Name_Op_Eq
);
884 -- Dispatching call to C++ primitive. Create a new parameter list
885 -- with no tag checks.
887 New_Params
:= New_List
;
889 if Is_CPP_Class
(Typ
) then
890 Param
:= First_Actual
(Call_Node
);
891 while Present
(Param
) loop
892 Append_To
(New_Params
, Relocate_Node
(Param
));
896 -- Dispatching call to Ada primitive
898 elsif Present
(Param_List
) then
899 Apply_Tag_Checks
(Call_Node
);
901 Param
:= First_Actual
(Call_Node
);
902 while Present
(Param
) loop
904 -- Cases in which we may have generated run-time checks. Note that
905 -- we strip any qualification from Param before comparing with the
906 -- already-stripped controlling argument.
908 if Unqualify
(Param
) = Ctrl_Arg
or else Subp
= Eq_Prim_Op
then
909 Append_To
(New_Params
,
910 Duplicate_Subexpr_Move_Checks
(Param
));
912 elsif Nkind
(Parent
(Param
)) /= N_Parameter_Association
913 or else not Is_Accessibility_Actual
(Parent
(Param
))
915 Append_To
(New_Params
, Relocate_Node
(Param
));
922 -- Generate the appropriate subprogram pointer type
924 if Etype
(Subp
) = Typ
then
927 Res_Typ
:= Etype
(Subp
);
930 Subp_Typ
:= Create_Itype
(E_Subprogram_Type
, Call_Node
);
931 Subp_Ptr_Typ
:= Create_Itype
(E_Access_Subprogram_Type
, Call_Node
);
932 Set_Etype
(Subp_Typ
, Res_Typ
);
933 Set_Returns_By_Ref
(Subp_Typ
, Returns_By_Ref
(Subp
));
934 Set_Convention
(Subp_Typ
, Convention
(Subp
));
936 -- Notify gigi that the designated type is a dispatching primitive
938 Set_Is_Dispatch_Table_Entity
(Subp_Typ
);
940 -- Create a new list of parameters which is a copy of the old formal
941 -- list including the creation of a new set of matching entities.
944 Old_Formal
: Entity_Id
:= First_Formal
(Subp
);
945 New_Formal
: Entity_Id
;
946 Extra
: Entity_Id
:= Empty
;
949 if Present
(Old_Formal
) then
950 New_Formal
:= New_Copy
(Old_Formal
);
951 Set_First_Entity
(Subp_Typ
, New_Formal
);
952 Param
:= First_Actual
(Call_Node
);
955 Set_Scope
(New_Formal
, Subp_Typ
);
957 -- Change all the controlling argument types to be class-wide
958 -- to avoid a recursion in dispatching.
960 if Is_Controlling_Formal
(New_Formal
) then
961 Set_Etype
(New_Formal
, Etype
(Param
));
964 -- If the type of the formal is an itype, there was code here
965 -- introduced in 1998 in revision 1.46, to create a new itype
966 -- by copy. This seems useless, and in fact leads to semantic
967 -- errors when the itype is the completion of a type derived
968 -- from a private type.
971 Next_Formal
(Old_Formal
);
972 exit when No
(Old_Formal
);
974 Set_Next_Entity
(New_Formal
, New_Copy
(Old_Formal
));
975 Next_Entity
(New_Formal
);
979 Set_Next_Entity
(New_Formal
, Empty
);
980 Set_Last_Entity
(Subp_Typ
, Extra
);
983 -- Now that the explicit formals have been duplicated, any extra
984 -- formals needed by the subprogram must be created.
986 if Present
(Extra
) then
987 Set_Extra_Formal
(Extra
, Empty
);
990 Create_Extra_Formals
(Subp_Typ
);
993 -- Complete description of pointer type, including size information, as
994 -- must be done with itypes to prevent order-of-elaboration anomalies
997 Set_Etype
(Subp_Ptr_Typ
, Subp_Ptr_Typ
);
998 Set_Directly_Designated_Type
(Subp_Ptr_Typ
, Subp_Typ
);
999 Set_Convention
(Subp_Ptr_Typ
, Convention
(Subp_Typ
));
1000 Layout_Type
(Subp_Ptr_Typ
);
1002 -- If the controlling argument is a value of type Ada.Tag or an abstract
1003 -- interface class-wide type then use it directly. Otherwise, the tag
1004 -- must be extracted from the controlling object.
1006 if Ctrl_Typ
= RTE
(RE_Tag
)
1007 or else (RTE_Available
(RE_Interface_Tag
)
1008 and then Ctrl_Typ
= RTE
(RE_Interface_Tag
))
1010 Controlling_Tag
:= Duplicate_Subexpr
(Ctrl_Arg
);
1012 -- Extract the tag from an unchecked type conversion. Done to avoid
1013 -- the expansion of additional code just to obtain the value of such
1014 -- tag because the current management of interface type conversions
1015 -- generates in some cases this unchecked type conversion with the
1016 -- tag of the object (see Expand_Interface_Conversion).
1018 elsif Nkind
(Ctrl_Arg
) = N_Unchecked_Type_Conversion
1020 (Etype
(Expression
(Ctrl_Arg
)) = RTE
(RE_Tag
)
1022 (RTE_Available
(RE_Interface_Tag
)
1024 Etype
(Expression
(Ctrl_Arg
)) = RTE
(RE_Interface_Tag
)))
1026 Controlling_Tag
:= Duplicate_Subexpr
(Expression
(Ctrl_Arg
));
1028 -- Ada 2005 (AI-251): Abstract interface class-wide type
1030 elsif Is_Interface
(Ctrl_Typ
)
1031 and then Is_Class_Wide_Type
(Ctrl_Typ
)
1033 Controlling_Tag
:= Duplicate_Subexpr
(Ctrl_Arg
);
1037 Make_Selected_Component
(Loc
,
1038 Prefix
=> Duplicate_Subexpr_Move_Checks
(Ctrl_Arg
),
1039 Selector_Name
=> New_Occurrence_Of
(DTC_Entity
(Subp
), Loc
));
1042 -- Handle dispatching calls to predefined primitives
1044 if Is_Predefined_Dispatching_Operation
(Subp
)
1045 or else Is_Predefined_Dispatching_Alias
(Subp
)
1047 Build_Get_Predefined_Prim_Op_Address
(Loc
,
1048 Tag_Node
=> Controlling_Tag
,
1049 Position
=> DT_Position
(Subp
),
1050 New_Node
=> New_Node
);
1052 -- Handle dispatching calls to user-defined primitives
1055 Build_Get_Prim_Op_Address
(Loc
,
1056 Typ
=> Underlying_Type
(Find_Dispatching_Type
(Subp
)),
1057 Tag_Node
=> Controlling_Tag
,
1058 Position
=> DT_Position
(Subp
),
1059 New_Node
=> New_Node
);
1063 Unchecked_Convert_To
(Subp_Ptr_Typ
, New_Node
);
1065 -- Generate the SCIL node for this dispatching call. Done now because
1066 -- attribute SCIL_Controlling_Tag must be set after the new call name
1067 -- is built to reference the nodes that will see the SCIL backend
1068 -- (because Build_Get_Prim_Op_Address generates an unchecked type
1069 -- conversion which relocates the controlling tag node).
1071 if Generate_SCIL
then
1072 SCIL_Node
:= Make_SCIL_Dispatching_Call
(Sloc
(Call_Node
));
1073 Set_SCIL_Entity
(SCIL_Node
, Typ
);
1074 Set_SCIL_Target_Prim
(SCIL_Node
, Subp
);
1076 -- Common case: the controlling tag is the tag of an object
1077 -- (for example, obj.tag)
1079 if Nkind
(Controlling_Tag
) = N_Selected_Component
then
1080 Set_SCIL_Controlling_Tag
(SCIL_Node
, Controlling_Tag
);
1082 -- Handle renaming of selected component
1084 elsif Nkind
(Controlling_Tag
) = N_Identifier
1085 and then Nkind
(Parent
(Entity
(Controlling_Tag
))) =
1086 N_Object_Renaming_Declaration
1087 and then Nkind
(Name
(Parent
(Entity
(Controlling_Tag
)))) =
1088 N_Selected_Component
1090 Set_SCIL_Controlling_Tag
(SCIL_Node
,
1091 Name
(Parent
(Entity
(Controlling_Tag
))));
1093 -- If the controlling tag is an identifier, the SCIL node references
1094 -- the corresponding object or parameter declaration
1096 elsif Nkind
(Controlling_Tag
) = N_Identifier
1097 and then Nkind_In
(Parent
(Entity
(Controlling_Tag
)),
1098 N_Object_Declaration
,
1099 N_Parameter_Specification
)
1101 Set_SCIL_Controlling_Tag
(SCIL_Node
,
1102 Parent
(Entity
(Controlling_Tag
)));
1104 -- If the controlling tag is a dereference, the SCIL node references
1105 -- the corresponding object or parameter declaration
1107 elsif Nkind
(Controlling_Tag
) = N_Explicit_Dereference
1108 and then Nkind
(Prefix
(Controlling_Tag
)) = N_Identifier
1109 and then Nkind_In
(Parent
(Entity
(Prefix
(Controlling_Tag
))),
1110 N_Object_Declaration
,
1111 N_Parameter_Specification
)
1113 Set_SCIL_Controlling_Tag
(SCIL_Node
,
1114 Parent
(Entity
(Prefix
(Controlling_Tag
))));
1116 -- For a direct reference of the tag of the type the SCIL node
1117 -- references the internal object declaration containing the tag
1120 elsif Nkind
(Controlling_Tag
) = N_Attribute_Reference
1121 and then Attribute_Name
(Controlling_Tag
) = Name_Tag
1123 Set_SCIL_Controlling_Tag
(SCIL_Node
,
1127 (Access_Disp_Table
(Entity
(Prefix
(Controlling_Tag
)))))));
1129 -- Interfaces are not supported. For now we leave the SCIL node
1130 -- decorated with the Controlling_Tag. More work needed here???
1132 elsif Is_Interface
(Etype
(Controlling_Tag
)) then
1133 Set_SCIL_Controlling_Tag
(SCIL_Node
, Controlling_Tag
);
1136 pragma Assert
(False);
1141 if Nkind
(Call_Node
) = N_Function_Call
then
1143 Make_Function_Call
(Loc
,
1144 Name
=> New_Call_Name
,
1145 Parameter_Associations
=> New_Params
);
1147 -- If this is a dispatching "=", we must first compare the tags so
1148 -- we generate: x.tag = y.tag and then x = y
1150 if Subp
= Eq_Prim_Op
then
1151 Param
:= First_Actual
(Call_Node
);
1157 Make_Selected_Component
(Loc
,
1158 Prefix
=> New_Value
(Param
),
1160 New_Occurrence_Of
(First_Tag_Component
(Typ
),
1164 Make_Selected_Component
(Loc
,
1166 Unchecked_Convert_To
(Typ
,
1167 New_Value
(Next_Actual
(Param
))),
1170 (First_Tag_Component
(Typ
), Loc
))),
1171 Right_Opnd
=> New_Call
);
1173 SCIL_Related_Node
:= Right_Opnd
(New_Call
);
1178 Make_Procedure_Call_Statement
(Loc
,
1179 Name
=> New_Call_Name
,
1180 Parameter_Associations
=> New_Params
);
1183 -- Register the dispatching call in the call graph nodes table
1185 Register_CG_Node
(Call_Node
);
1187 Rewrite
(Call_Node
, New_Call
);
1189 -- Associate the SCIL node of this dispatching call
1191 if Generate_SCIL
then
1192 Set_SCIL_Node
(SCIL_Related_Node
, SCIL_Node
);
1195 -- Suppress all checks during the analysis of the expanded code to avoid
1196 -- the generation of spurious warnings under ZFP run-time.
1198 Analyze_And_Resolve
(Call_Node
, Call_Typ
, Suppress
=> All_Checks
);
1199 end Expand_Dispatching_Call
;
1201 ---------------------------------
1202 -- Expand_Interface_Conversion --
1203 ---------------------------------
1205 procedure Expand_Interface_Conversion
(N
: Node_Id
) is
1206 function Underlying_Record_Type
(Typ
: Entity_Id
) return Entity_Id
;
1207 -- Return the underlying record type of Typ
1209 ----------------------------
1210 -- Underlying_Record_Type --
1211 ----------------------------
1213 function Underlying_Record_Type
(Typ
: Entity_Id
) return Entity_Id
is
1214 E
: Entity_Id
:= Typ
;
1217 -- Handle access types
1219 if Is_Access_Type
(E
) then
1220 E
:= Directly_Designated_Type
(E
);
1223 -- Handle class-wide types. This conversion can appear explicitly in
1224 -- the source code. Example: I'Class (Obj)
1226 if Is_Class_Wide_Type
(E
) then
1230 -- If the target type is a tagged synchronized type, the dispatch
1231 -- table info is in the corresponding record type.
1233 if Is_Concurrent_Type
(E
) then
1234 E
:= Corresponding_Record_Type
(E
);
1237 -- Handle private types
1239 E
:= Underlying_Type
(E
);
1243 return Base_Type
(E
);
1244 end Underlying_Record_Type
;
1248 Loc
: constant Source_Ptr
:= Sloc
(N
);
1249 Etyp
: constant Entity_Id
:= Etype
(N
);
1250 Operand
: constant Node_Id
:= Expression
(N
);
1251 Operand_Typ
: Entity_Id
:= Etype
(Operand
);
1253 Iface_Typ
: constant Entity_Id
:= Underlying_Record_Type
(Etype
(N
));
1254 Iface_Tag
: Entity_Id
;
1255 Is_Static
: Boolean;
1257 -- Start of processing for Expand_Interface_Conversion
1260 -- Freeze the entity associated with the target interface to have
1261 -- available the attribute Access_Disp_Table.
1263 Freeze_Before
(N
, Iface_Typ
);
1265 -- Ada 2005 (AI-345): Handle synchronized interface type derivations
1267 if Is_Concurrent_Type
(Operand_Typ
) then
1268 Operand_Typ
:= Base_Type
(Corresponding_Record_Type
(Operand_Typ
));
1271 -- No displacement of the pointer to the object needed when the type of
1272 -- the operand is not an interface type and the interface is one of
1273 -- its parent types (since they share the primary dispatch table).
1276 Opnd
: Entity_Id
:= Operand_Typ
;
1279 if Is_Access_Type
(Opnd
) then
1280 Opnd
:= Designated_Type
(Opnd
);
1283 if not Is_Interface
(Opnd
)
1284 and then Is_Ancestor
(Iface_Typ
, Opnd
, Use_Full_View
=> True)
1290 -- Evaluate if we can statically displace the pointer to the object
1293 Opnd_Typ
: constant Node_Id
:= Underlying_Record_Type
(Operand_Typ
);
1297 not Is_Interface
(Opnd_Typ
)
1298 and then Interface_Present_In_Ancestor
1301 and then (Etype
(Opnd_Typ
) = Opnd_Typ
1303 Is_Variable_Size_Record
(Etype
(Opnd_Typ
)));
1306 if not Tagged_Type_Expansion
then
1309 -- A static conversion to an interface type that is not class-wide is
1310 -- curious but legal if the interface operation is a null procedure.
1311 -- If the operation is abstract it will be rejected later.
1314 and then Is_Interface
(Etype
(N
))
1315 and then not Is_Class_Wide_Type
(Etype
(N
))
1316 and then Comes_From_Source
(N
)
1318 Rewrite
(N
, Unchecked_Convert_To
(Etype
(N
), N
));
1323 if not Is_Static
then
1325 -- Give error if configurable run-time and Displace not available
1327 if not RTE_Available
(RE_Displace
) then
1328 Error_Msg_CRT
("dynamic interface conversion", N
);
1332 -- Handle conversion of access-to-class-wide interface types. Target
1333 -- can be an access to an object or an access to another class-wide
1334 -- interface (see -1- and -2- in the following example):
1336 -- type Iface1_Ref is access all Iface1'Class;
1337 -- type Iface2_Ref is access all Iface1'Class;
1339 -- Acc1 : Iface1_Ref := new ...
1340 -- Obj : Obj_Ref := Obj_Ref (Acc); -- 1
1341 -- Acc2 : Iface2_Ref := Iface2_Ref (Acc); -- 2
1343 if Is_Access_Type
(Operand_Typ
) then
1345 Unchecked_Convert_To
(Etype
(N
),
1346 Make_Function_Call
(Loc
,
1347 Name
=> New_Occurrence_Of
(RTE
(RE_Displace
), Loc
),
1348 Parameter_Associations
=> New_List
(
1350 Unchecked_Convert_To
(RTE
(RE_Address
),
1351 Relocate_Node
(Expression
(N
))),
1354 (Node
(First_Elmt
(Access_Disp_Table
(Iface_Typ
))),
1362 Make_Function_Call
(Loc
,
1363 Name
=> New_Occurrence_Of
(RTE
(RE_Displace
), Loc
),
1364 Parameter_Associations
=> New_List
(
1365 Make_Attribute_Reference
(Loc
,
1366 Prefix
=> Relocate_Node
(Expression
(N
)),
1367 Attribute_Name
=> Name_Address
),
1370 (Node
(First_Elmt
(Access_Disp_Table
(Iface_Typ
))),
1375 -- If target is a class-wide interface, change the type of the data
1376 -- returned by IW_Convert to indicate this is a dispatching call.
1379 New_Itype
: Entity_Id
;
1382 New_Itype
:= Create_Itype
(E_Anonymous_Access_Type
, N
);
1383 Set_Etype
(New_Itype
, New_Itype
);
1384 Set_Directly_Designated_Type
(New_Itype
, Etyp
);
1387 Make_Explicit_Dereference
(Loc
,
1389 Unchecked_Convert_To
(New_Itype
, Relocate_Node
(N
))));
1391 Freeze_Itype
(New_Itype
, N
);
1397 Iface_Tag
:= Find_Interface_Tag
(Operand_Typ
, Iface_Typ
);
1398 pragma Assert
(Iface_Tag
/= Empty
);
1400 -- Keep separate access types to interfaces because one internal
1401 -- function is used to handle the null value (see following comments)
1403 if not Is_Access_Type
(Etype
(N
)) then
1405 -- Statically displace the pointer to the object to reference the
1406 -- component containing the secondary dispatch table.
1409 Convert_Tag_To_Interface
(Class_Wide_Type
(Iface_Typ
),
1410 Make_Selected_Component
(Loc
,
1411 Prefix
=> Relocate_Node
(Expression
(N
)),
1412 Selector_Name
=> New_Occurrence_Of
(Iface_Tag
, Loc
))));
1415 -- Build internal function to handle the case in which the actual is
1416 -- null. If the actual is null returns null because no displacement
1417 -- is required; otherwise performs a type conversion that will be
1418 -- expanded in the code that returns the value of the displaced
1421 -- function Func (O : Address) return Iface_Typ is
1422 -- type Op_Typ is access all Operand_Typ;
1423 -- Aux : Op_Typ := To_Op_Typ (O);
1425 -- if O = Null_Address then
1428 -- return Iface_Typ!(Aux.Iface_Tag'Address);
1433 Desig_Typ
: Entity_Id
;
1435 New_Typ_Decl
: Node_Id
;
1439 Desig_Typ
:= Etype
(Expression
(N
));
1441 if Is_Access_Type
(Desig_Typ
) then
1443 Available_View
(Directly_Designated_Type
(Desig_Typ
));
1446 if Is_Concurrent_Type
(Desig_Typ
) then
1447 Desig_Typ
:= Base_Type
(Corresponding_Record_Type
(Desig_Typ
));
1451 Make_Full_Type_Declaration
(Loc
,
1452 Defining_Identifier
=> Make_Temporary
(Loc
, 'T'),
1454 Make_Access_To_Object_Definition
(Loc
,
1455 All_Present
=> True,
1456 Null_Exclusion_Present
=> False,
1457 Constant_Present
=> False,
1458 Subtype_Indication
=>
1459 New_Occurrence_Of
(Desig_Typ
, Loc
)));
1462 Make_Simple_Return_Statement
(Loc
,
1463 Unchecked_Convert_To
(Etype
(N
),
1464 Make_Attribute_Reference
(Loc
,
1466 Make_Selected_Component
(Loc
,
1468 Unchecked_Convert_To
1469 (Defining_Identifier
(New_Typ_Decl
),
1470 Make_Identifier
(Loc
, Name_uO
)),
1472 New_Occurrence_Of
(Iface_Tag
, Loc
)),
1473 Attribute_Name
=> Name_Address
))));
1475 -- If the type is null-excluding, no need for the null branch.
1476 -- Otherwise we need to check for it and return null.
1478 if not Can_Never_Be_Null
(Etype
(N
)) then
1480 Make_If_Statement
(Loc
,
1483 Left_Opnd
=> Make_Identifier
(Loc
, Name_uO
),
1484 Right_Opnd
=> New_Occurrence_Of
1485 (RTE
(RE_Null_Address
), Loc
)),
1487 Then_Statements
=> New_List
(
1488 Make_Simple_Return_Statement
(Loc
, Make_Null
(Loc
))),
1489 Else_Statements
=> Stats
));
1492 Fent
:= Make_Temporary
(Loc
, 'F');
1494 Make_Subprogram_Body
(Loc
,
1496 Make_Function_Specification
(Loc
,
1497 Defining_Unit_Name
=> Fent
,
1499 Parameter_Specifications
=> New_List
(
1500 Make_Parameter_Specification
(Loc
,
1501 Defining_Identifier
=>
1502 Make_Defining_Identifier
(Loc
, Name_uO
),
1504 New_Occurrence_Of
(RTE
(RE_Address
), Loc
))),
1506 Result_Definition
=>
1507 New_Occurrence_Of
(Etype
(N
), Loc
)),
1509 Declarations
=> New_List
(New_Typ_Decl
),
1511 Handled_Statement_Sequence
=>
1512 Make_Handled_Sequence_Of_Statements
(Loc
, Stats
));
1514 -- Place function body before the expression containing the
1515 -- conversion. We suppress all checks because the body of the
1516 -- internally generated function already takes care of the case
1517 -- in which the actual is null; therefore there is no need to
1518 -- double check that the pointer is not null when the program
1519 -- executes the alternative that performs the type conversion).
1521 Insert_Action
(N
, Func
, Suppress
=> All_Checks
);
1523 if Is_Access_Type
(Etype
(Expression
(N
))) then
1525 -- Generate: Func (Address!(Expression))
1528 Make_Function_Call
(Loc
,
1529 Name
=> New_Occurrence_Of
(Fent
, Loc
),
1530 Parameter_Associations
=> New_List
(
1531 Unchecked_Convert_To
(RTE
(RE_Address
),
1532 Relocate_Node
(Expression
(N
))))));
1535 -- Generate: Func (Operand_Typ!(Expression)'Address)
1538 Make_Function_Call
(Loc
,
1539 Name
=> New_Occurrence_Of
(Fent
, Loc
),
1540 Parameter_Associations
=> New_List
(
1541 Make_Attribute_Reference
(Loc
,
1542 Prefix
=> Unchecked_Convert_To
(Operand_Typ
,
1543 Relocate_Node
(Expression
(N
))),
1544 Attribute_Name
=> Name_Address
))));
1550 end Expand_Interface_Conversion
;
1552 ------------------------------
1553 -- Expand_Interface_Actuals --
1554 ------------------------------
1556 procedure Expand_Interface_Actuals
(Call_Node
: Node_Id
) is
1558 Actual_Dup
: Node_Id
;
1559 Actual_Typ
: Entity_Id
;
1561 Conversion
: Node_Id
;
1563 Formal_Typ
: Entity_Id
;
1565 Formal_DDT
: Entity_Id
:= Empty
; -- initialize to prevent warning
1566 Actual_DDT
: Entity_Id
:= Empty
; -- initialize to prevent warning
1569 -- This subprogram is called directly from the semantics, so we need a
1570 -- check to see whether expansion is active before proceeding.
1572 if not Expander_Active
then
1576 -- Call using access to subprogram with explicit dereference
1578 if Nkind
(Name
(Call_Node
)) = N_Explicit_Dereference
then
1579 Subp
:= Etype
(Name
(Call_Node
));
1581 -- Call using selected component
1583 elsif Nkind
(Name
(Call_Node
)) = N_Selected_Component
then
1584 Subp
:= Entity
(Selector_Name
(Name
(Call_Node
)));
1586 -- Call using direct name
1589 Subp
:= Entity
(Name
(Call_Node
));
1592 -- Ada 2005 (AI-251): Look for interface type formals to force "this"
1595 Formal
:= First_Formal
(Subp
);
1596 Actual
:= First_Actual
(Call_Node
);
1597 while Present
(Formal
) loop
1598 Formal_Typ
:= Etype
(Formal
);
1600 if Ekind
(Formal_Typ
) = E_Record_Type_With_Private
then
1601 Formal_Typ
:= Full_View
(Formal_Typ
);
1604 if Is_Access_Type
(Formal_Typ
) then
1605 Formal_DDT
:= Directly_Designated_Type
(Formal_Typ
);
1608 Actual_Typ
:= Etype
(Actual
);
1610 if Is_Access_Type
(Actual_Typ
) then
1611 Actual_DDT
:= Directly_Designated_Type
(Actual_Typ
);
1614 if Is_Interface
(Formal_Typ
)
1615 and then Is_Class_Wide_Type
(Formal_Typ
)
1617 -- No need to displace the pointer if the type of the actual
1618 -- coincides with the type of the formal.
1620 if Actual_Typ
= Formal_Typ
then
1623 -- No need to displace the pointer if the interface type is a
1624 -- parent of the type of the actual because in this case the
1625 -- interface primitives are located in the primary dispatch table.
1627 elsif Is_Ancestor
(Formal_Typ
, Actual_Typ
,
1628 Use_Full_View
=> True)
1632 -- Implicit conversion to the class-wide formal type to force the
1633 -- displacement of the pointer.
1636 -- Normally, expansion of actuals for calls to build-in-place
1637 -- functions happens as part of Expand_Actuals, but in this
1638 -- case the call will be wrapped in a conversion and soon after
1639 -- expanded further to handle the displacement for a class-wide
1640 -- interface conversion, so if this is a BIP call then we need
1641 -- to handle it now.
1643 if Ada_Version
>= Ada_2005
1644 and then Is_Build_In_Place_Function_Call
(Actual
)
1646 Make_Build_In_Place_Call_In_Anonymous_Context
(Actual
);
1649 Conversion
:= Convert_To
(Formal_Typ
, Relocate_Node
(Actual
));
1650 Rewrite
(Actual
, Conversion
);
1651 Analyze_And_Resolve
(Actual
, Formal_Typ
);
1654 -- Access to class-wide interface type
1656 elsif Is_Access_Type
(Formal_Typ
)
1657 and then Is_Interface
(Formal_DDT
)
1658 and then Is_Class_Wide_Type
(Formal_DDT
)
1659 and then Interface_Present_In_Ancestor
1661 Iface
=> Etype
(Formal_DDT
))
1663 -- Handle attributes 'Access and 'Unchecked_Access
1665 if Nkind
(Actual
) = N_Attribute_Reference
1667 (Attribute_Name
(Actual
) = Name_Access
1668 or else Attribute_Name
(Actual
) = Name_Unchecked_Access
)
1670 -- This case must have been handled by the analysis and
1671 -- expansion of 'Access. The only exception is when types
1672 -- match and no further expansion is required.
1674 pragma Assert
(Base_Type
(Etype
(Prefix
(Actual
)))
1675 = Base_Type
(Formal_DDT
));
1678 -- No need to displace the pointer if the type of the actual
1679 -- coincides with the type of the formal.
1681 elsif Actual_DDT
= Formal_DDT
then
1684 -- No need to displace the pointer if the interface type is
1685 -- a parent of the type of the actual because in this case the
1686 -- interface primitives are located in the primary dispatch table.
1688 elsif Is_Ancestor
(Formal_DDT
, Actual_DDT
,
1689 Use_Full_View
=> True)
1694 Actual_Dup
:= Relocate_Node
(Actual
);
1696 if From_Limited_With
(Actual_Typ
) then
1698 -- If the type of the actual parameter comes from a
1699 -- limited with-clause and the non-limited view is already
1700 -- available, we replace the anonymous access type by
1701 -- a duplicate declaration whose designated type is the
1702 -- non-limited view.
1704 if Has_Non_Limited_View
(Actual_DDT
) then
1705 Anon
:= New_Copy
(Actual_Typ
);
1707 if Is_Itype
(Anon
) then
1708 Set_Scope
(Anon
, Current_Scope
);
1711 Set_Directly_Designated_Type
1712 (Anon
, Non_Limited_View
(Actual_DDT
));
1713 Set_Etype
(Actual_Dup
, Anon
);
1717 Conversion
:= Convert_To
(Formal_Typ
, Actual_Dup
);
1718 Rewrite
(Actual
, Conversion
);
1719 Analyze_And_Resolve
(Actual
, Formal_Typ
);
1723 Next_Actual
(Actual
);
1724 Next_Formal
(Formal
);
1726 end Expand_Interface_Actuals
;
1728 ----------------------------
1729 -- Expand_Interface_Thunk --
1730 ----------------------------
1732 procedure Expand_Interface_Thunk
1734 Thunk_Id
: out Entity_Id
;
1735 Thunk_Code
: out Node_Id
)
1737 Loc
: constant Source_Ptr
:= Sloc
(Prim
);
1738 Actuals
: constant List_Id
:= New_List
;
1739 Decl
: constant List_Id
:= New_List
;
1740 Formals
: constant List_Id
:= New_List
;
1741 Target
: constant Entity_Id
:= Ultimate_Alias
(Prim
);
1748 Iface_Formal
: Node_Id
:= Empty
; -- initialize to prevent warning
1750 Offset_To_Top
: Node_Id
;
1751 Target_Formal
: Entity_Id
;
1755 Thunk_Code
:= Empty
;
1757 -- No thunk needed if the primitive has been eliminated
1759 if Is_Eliminated
(Ultimate_Alias
(Prim
)) then
1762 -- In case of primitives that are functions without formals and a
1763 -- controlling result there is no need to build the thunk.
1765 elsif not Present
(First_Formal
(Target
)) then
1766 pragma Assert
(Ekind
(Target
) = E_Function
1767 and then Has_Controlling_Result
(Target
));
1771 -- Duplicate the formals of the Target primitive. In the thunk, the type
1772 -- of the controlling formal is the covered interface type (instead of
1773 -- the target tagged type). Done to avoid problems with discriminated
1774 -- tagged types because, if the controlling type has discriminants with
1775 -- default values, then the type conversions done inside the body of
1776 -- the thunk (after the displacement of the pointer to the base of the
1777 -- actual object) generate code that modify its contents.
1779 -- Note: This special management is not done for predefined primitives
1782 if not Is_Predefined_Dispatching_Operation
(Prim
) then
1783 Iface_Formal
:= First_Formal
(Interface_Alias
(Prim
));
1786 Formal
:= First_Formal
(Target
);
1787 while Present
(Formal
) loop
1788 Ftyp
:= Etype
(Formal
);
1790 -- Use the interface type as the type of the controlling formal (see
1793 if not Is_Controlling_Formal
(Formal
)
1794 or else Is_Predefined_Dispatching_Operation
(Prim
)
1796 Ftyp
:= Etype
(Formal
);
1797 Expr
:= New_Copy_Tree
(Expression
(Parent
(Formal
)));
1799 Ftyp
:= Etype
(Iface_Formal
);
1804 Make_Parameter_Specification
(Loc
,
1805 Defining_Identifier
=>
1806 Make_Defining_Identifier
(Sloc
(Formal
),
1807 Chars
=> Chars
(Formal
)),
1808 In_Present
=> In_Present
(Parent
(Formal
)),
1809 Out_Present
=> Out_Present
(Parent
(Formal
)),
1810 Parameter_Type
=> New_Occurrence_Of
(Ftyp
, Loc
),
1811 Expression
=> Expr
));
1813 if not Is_Predefined_Dispatching_Operation
(Prim
) then
1814 Next_Formal
(Iface_Formal
);
1817 Next_Formal
(Formal
);
1820 Target_Formal
:= First_Formal
(Target
);
1821 Formal
:= First
(Formals
);
1822 while Present
(Formal
) loop
1824 -- If the parent is a constrained discriminated type, then the
1825 -- primitive operation will have been defined on a first subtype.
1826 -- For proper matching with controlling type, use base type.
1828 if Ekind
(Target_Formal
) = E_In_Parameter
1829 and then Ekind
(Etype
(Target_Formal
)) = E_Anonymous_Access_Type
1832 Base_Type
(Directly_Designated_Type
(Etype
(Target_Formal
)));
1834 Ftyp
:= Base_Type
(Etype
(Target_Formal
));
1837 -- For concurrent types, the relevant information is found in the
1838 -- Corresponding_Record_Type, rather than the type entity itself.
1840 if Is_Concurrent_Type
(Ftyp
) then
1841 Ftyp
:= Corresponding_Record_Type
(Ftyp
);
1844 if Ekind
(Target_Formal
) = E_In_Parameter
1845 and then Ekind
(Etype
(Target_Formal
)) = E_Anonymous_Access_Type
1846 and then Is_Controlling_Formal
(Target_Formal
)
1849 -- type T is access all <<type of the target formal>>
1850 -- S : Storage_Offset := Storage_Offset!(Formal)
1851 -- - Offset_To_Top (address!(Formal))
1854 Make_Full_Type_Declaration
(Loc
,
1855 Defining_Identifier
=> Make_Temporary
(Loc
, 'T'),
1857 Make_Access_To_Object_Definition
(Loc
,
1858 All_Present
=> True,
1859 Null_Exclusion_Present
=> False,
1860 Constant_Present
=> False,
1861 Subtype_Indication
=>
1862 New_Occurrence_Of
(Ftyp
, Loc
)));
1865 Unchecked_Convert_To
(RTE
(RE_Address
),
1866 New_Occurrence_Of
(Defining_Identifier
(Formal
), Loc
));
1868 if not RTE_Available
(RE_Offset_To_Top
) then
1870 Build_Offset_To_Top
(Loc
, New_Arg
);
1873 Make_Function_Call
(Loc
,
1874 Name
=> New_Occurrence_Of
(RTE
(RE_Offset_To_Top
), Loc
),
1875 Parameter_Associations
=> New_List
(New_Arg
));
1879 Make_Object_Declaration
(Loc
,
1880 Defining_Identifier
=> Make_Temporary
(Loc
, 'S'),
1881 Constant_Present
=> True,
1882 Object_Definition
=>
1883 New_Occurrence_Of
(RTE
(RE_Storage_Offset
), Loc
),
1885 Make_Op_Subtract
(Loc
,
1887 Unchecked_Convert_To
1888 (RTE
(RE_Storage_Offset
),
1890 (Defining_Identifier
(Formal
), Loc
)),
1894 Append_To
(Decl
, Decl_2
);
1895 Append_To
(Decl
, Decl_1
);
1897 -- Reference the new actual. Generate:
1901 Unchecked_Convert_To
1902 (Defining_Identifier
(Decl_2
),
1903 New_Occurrence_Of
(Defining_Identifier
(Decl_1
), Loc
)));
1905 elsif Is_Controlling_Formal
(Target_Formal
) then
1908 -- S1 : Storage_Offset := Storage_Offset!(Formal'Address)
1909 -- - Offset_To_Top (Formal'Address)
1910 -- S2 : Addr_Ptr := Addr_Ptr!(S1)
1913 Make_Attribute_Reference
(Loc
,
1915 New_Occurrence_Of
(Defining_Identifier
(Formal
), Loc
),
1919 if not RTE_Available
(RE_Offset_To_Top
) then
1921 Build_Offset_To_Top
(Loc
, New_Arg
);
1924 Make_Function_Call
(Loc
,
1925 Name
=> New_Occurrence_Of
(RTE
(RE_Offset_To_Top
), Loc
),
1926 Parameter_Associations
=> New_List
(New_Arg
));
1930 Make_Object_Declaration
(Loc
,
1931 Defining_Identifier
=> Make_Temporary
(Loc
, 'S'),
1932 Constant_Present
=> True,
1933 Object_Definition
=>
1934 New_Occurrence_Of
(RTE
(RE_Storage_Offset
), Loc
),
1936 Make_Op_Subtract
(Loc
,
1938 Unchecked_Convert_To
1939 (RTE
(RE_Storage_Offset
),
1940 Make_Attribute_Reference
(Loc
,
1943 (Defining_Identifier
(Formal
), Loc
),
1944 Attribute_Name
=> Name_Address
)),
1949 Make_Object_Declaration
(Loc
,
1950 Defining_Identifier
=> Make_Temporary
(Loc
, 'S'),
1951 Constant_Present
=> True,
1952 Object_Definition
=>
1953 New_Occurrence_Of
(RTE
(RE_Addr_Ptr
), Loc
),
1955 Unchecked_Convert_To
1957 New_Occurrence_Of
(Defining_Identifier
(Decl_1
), Loc
)));
1959 Append_To
(Decl
, Decl_1
);
1960 Append_To
(Decl
, Decl_2
);
1962 -- Reference the new actual, generate:
1963 -- Target_Formal (S2.all)
1966 Unchecked_Convert_To
(Ftyp
,
1967 Make_Explicit_Dereference
(Loc
,
1968 New_Occurrence_Of
(Defining_Identifier
(Decl_2
), Loc
))));
1970 -- Ensure proper matching of access types. Required to avoid
1971 -- reporting spurious errors.
1973 elsif Is_Access_Type
(Etype
(Target_Formal
)) then
1975 Unchecked_Convert_To
(Base_Type
(Etype
(Target_Formal
)),
1976 New_Occurrence_Of
(Defining_Identifier
(Formal
), Loc
)));
1978 -- No special management required for this actual
1982 New_Occurrence_Of
(Defining_Identifier
(Formal
), Loc
));
1985 Next_Formal
(Target_Formal
);
1989 Thunk_Id
:= Make_Temporary
(Loc
, 'T');
1990 Set_Ekind
(Thunk_Id
, Ekind
(Prim
));
1991 Set_Is_Thunk
(Thunk_Id
);
1992 Set_Convention
(Thunk_Id
, Convention
(Prim
));
1993 Set_Thunk_Entity
(Thunk_Id
, Target
);
1997 if Ekind
(Target
) = E_Procedure
then
1999 Make_Subprogram_Body
(Loc
,
2001 Make_Procedure_Specification
(Loc
,
2002 Defining_Unit_Name
=> Thunk_Id
,
2003 Parameter_Specifications
=> Formals
),
2004 Declarations
=> Decl
,
2005 Handled_Statement_Sequence
=>
2006 Make_Handled_Sequence_Of_Statements
(Loc
,
2007 Statements
=> New_List
(
2008 Make_Procedure_Call_Statement
(Loc
,
2009 Name
=> New_Occurrence_Of
(Target
, Loc
),
2010 Parameter_Associations
=> Actuals
))));
2014 else pragma Assert
(Ekind
(Target
) = E_Function
);
2016 Result_Def
: Node_Id
;
2017 Call_Node
: Node_Id
;
2021 Make_Function_Call
(Loc
,
2022 Name
=> New_Occurrence_Of
(Target
, Loc
),
2023 Parameter_Associations
=> Actuals
);
2025 if not Is_Interface
(Etype
(Prim
)) then
2026 Result_Def
:= New_Copy
(Result_Definition
(Parent
(Target
)));
2028 -- Thunk of function returning a class-wide interface object. No
2029 -- extra displacement needed since the displacement is generated
2030 -- in the return statement of Prim. Example:
2032 -- type Iface is interface ...
2033 -- function F (O : Iface) return Iface'Class;
2035 -- type T is new ... and Iface with ...
2036 -- function F (O : T) return Iface'Class;
2038 elsif Is_Class_Wide_Type
(Etype
(Prim
)) then
2039 Result_Def
:= New_Occurrence_Of
(Etype
(Prim
), Loc
);
2041 -- Thunk of function returning an interface object. Displacement
2044 -- type Iface is interface ...
2045 -- function F (O : Iface) return Iface;
2047 -- type T is new ... and Iface with ...
2048 -- function F (O : T) return T;
2052 New_Occurrence_Of
(Class_Wide_Type
(Etype
(Prim
)), Loc
);
2054 -- Adding implicit conversion to force the displacement of
2055 -- the pointer to the object to reference the corresponding
2056 -- secondary dispatch table.
2059 Make_Type_Conversion
(Loc
,
2061 New_Occurrence_Of
(Class_Wide_Type
(Etype
(Prim
)), Loc
),
2062 Expression
=> Relocate_Node
(Call_Node
));
2066 Make_Subprogram_Body
(Loc
,
2068 Make_Function_Specification
(Loc
,
2069 Defining_Unit_Name
=> Thunk_Id
,
2070 Parameter_Specifications
=> Formals
,
2071 Result_Definition
=> Result_Def
),
2072 Declarations
=> Decl
,
2073 Handled_Statement_Sequence
=>
2074 Make_Handled_Sequence_Of_Statements
(Loc
,
2075 Statements
=> New_List
(
2076 Make_Simple_Return_Statement
(Loc
, Call_Node
))));
2079 end Expand_Interface_Thunk
;
2081 --------------------------
2082 -- Has_CPP_Constructors --
2083 --------------------------
2085 function Has_CPP_Constructors
(Typ
: Entity_Id
) return Boolean is
2089 -- Look for the constructor entities
2091 E
:= Next_Entity
(Typ
);
2092 while Present
(E
) loop
2093 if Ekind
(E
) = E_Function
and then Is_Constructor
(E
) then
2101 end Has_CPP_Constructors
;
2107 function Has_DT
(Typ
: Entity_Id
) return Boolean is
2109 return not Is_Interface
(Typ
)
2110 and then not Restriction_Active
(No_Dispatching_Calls
);
2113 ----------------------------------
2114 -- Is_Expanded_Dispatching_Call --
2115 ----------------------------------
2117 function Is_Expanded_Dispatching_Call
(N
: Node_Id
) return Boolean is
2119 return Nkind
(N
) in N_Subprogram_Call
2120 and then Nkind
(Name
(N
)) = N_Explicit_Dereference
2121 and then Is_Dispatch_Table_Entity
(Etype
(Name
(N
)));
2122 end Is_Expanded_Dispatching_Call
;
2124 -----------------------------------------
2125 -- Is_Predefined_Dispatching_Operation --
2126 -----------------------------------------
2128 function Is_Predefined_Dispatching_Operation
2129 (E
: Entity_Id
) return Boolean
2131 TSS_Name
: TSS_Name_Type
;
2134 if not Is_Dispatching_Operation
(E
) then
2138 Get_Name_String
(Chars
(E
));
2140 -- Most predefined primitives have internally generated names. Equality
2141 -- must be treated differently; the predefined operation is recognized
2142 -- as a homogeneous binary operator that returns Boolean.
2144 if Name_Len
> TSS_Name_Type
'Last then
2145 TSS_Name
:= TSS_Name_Type
(Name_Buffer
(Name_Len
- TSS_Name
'Length + 1
2147 if Chars
(E
) = Name_uSize
2148 or else TSS_Name
= TSS_Stream_Read
2149 or else TSS_Name
= TSS_Stream_Write
2150 or else TSS_Name
= TSS_Stream_Input
2151 or else TSS_Name
= TSS_Stream_Output
2153 (Chars
(E
) = Name_Op_Eq
2154 and then Etype
(First_Formal
(E
)) = Etype
(Last_Formal
(E
)))
2155 or else Chars
(E
) = Name_uAssign
2156 or else TSS_Name
= TSS_Deep_Adjust
2157 or else TSS_Name
= TSS_Deep_Finalize
2158 or else Is_Predefined_Interface_Primitive
(E
)
2165 end Is_Predefined_Dispatching_Operation
;
2167 ---------------------------------------
2168 -- Is_Predefined_Internal_Operation --
2169 ---------------------------------------
2171 function Is_Predefined_Internal_Operation
2172 (E
: Entity_Id
) return Boolean
2174 TSS_Name
: TSS_Name_Type
;
2177 if not Is_Dispatching_Operation
(E
) then
2181 Get_Name_String
(Chars
(E
));
2183 -- Most predefined primitives have internally generated names. Equality
2184 -- must be treated differently; the predefined operation is recognized
2185 -- as a homogeneous binary operator that returns Boolean.
2187 if Name_Len
> TSS_Name_Type
'Last then
2190 (Name_Buffer
(Name_Len
- TSS_Name
'Length + 1 .. Name_Len
));
2192 if Nam_In
(Chars
(E
), Name_uSize
, Name_uAssign
)
2194 (Chars
(E
) = Name_Op_Eq
2195 and then Etype
(First_Formal
(E
)) = Etype
(Last_Formal
(E
)))
2196 or else TSS_Name
= TSS_Deep_Adjust
2197 or else TSS_Name
= TSS_Deep_Finalize
2198 or else Is_Predefined_Interface_Primitive
(E
)
2205 end Is_Predefined_Internal_Operation
;
2207 -------------------------------------
2208 -- Is_Predefined_Dispatching_Alias --
2209 -------------------------------------
2211 function Is_Predefined_Dispatching_Alias
(Prim
: Entity_Id
) return Boolean
2214 return not Is_Predefined_Dispatching_Operation
(Prim
)
2215 and then Present
(Alias
(Prim
))
2216 and then Is_Predefined_Dispatching_Operation
(Ultimate_Alias
(Prim
));
2217 end Is_Predefined_Dispatching_Alias
;
2219 ---------------------------------------
2220 -- Is_Predefined_Interface_Primitive --
2221 ---------------------------------------
2223 function Is_Predefined_Interface_Primitive
(E
: Entity_Id
) return Boolean is
2225 -- In VM targets we don't restrict the functionality of this test to
2226 -- compiling in Ada 2005 mode since in VM targets any tagged type has
2227 -- these primitives.
2229 return (Ada_Version
>= Ada_2005
or else not Tagged_Type_Expansion
)
2230 and then Nam_In
(Chars
(E
), Name_uDisp_Asynchronous_Select
,
2231 Name_uDisp_Conditional_Select
,
2232 Name_uDisp_Get_Prim_Op_Kind
,
2233 Name_uDisp_Get_Task_Id
,
2235 Name_uDisp_Timed_Select
);
2236 end Is_Predefined_Interface_Primitive
;
2238 ----------------------------------------
2239 -- Make_Disp_Asynchronous_Select_Body --
2240 ----------------------------------------
2242 -- For interface types, generate:
2244 -- procedure _Disp_Asynchronous_Select
2245 -- (T : in out <Typ>;
2247 -- P : System.Address;
2248 -- B : out System.Storage_Elements.Dummy_Communication_Block;
2253 -- C := Ada.Tags.POK_Function;
2254 -- end _Disp_Asynchronous_Select;
2256 -- For protected types, generate:
2258 -- procedure _Disp_Asynchronous_Select
2259 -- (T : in out <Typ>;
2261 -- P : System.Address;
2262 -- B : out System.Storage_Elements.Dummy_Communication_Block;
2266 -- Ada.Tags.Get_Entry_Index (Ada.Tags.Tag (<Typ>VP, S));
2267 -- Bnn : System.Tasking.Protected_Objects.Operations.
2268 -- Communication_Block;
2270 -- System.Tasking.Protected_Objects.Operations.Protected_Entry_Call
2271 -- (T._object'Access,
2272 -- System.Tasking.Protected_Objects.Protected_Entry_Index (I),
2274 -- System.Tasking.Asynchronous_Call,
2276 -- B := System.Storage_Elements.Dummy_Communication_Block (Bnn);
2277 -- end _Disp_Asynchronous_Select;
2279 -- For task types, generate:
2281 -- procedure _Disp_Asynchronous_Select
2282 -- (T : in out <Typ>;
2284 -- P : System.Address;
2285 -- B : out System.Storage_Elements.Dummy_Communication_Block;
2289 -- Ada.Tags.Get_Entry_Index (Ada.Tags.Tag (<Typ>VP, S));
2291 -- System.Tasking.Rendezvous.Task_Entry_Call
2293 -- System.Tasking.Task_Entry_Index (I),
2295 -- System.Tasking.Asynchronous_Call,
2297 -- end _Disp_Asynchronous_Select;
2299 function Make_Disp_Asynchronous_Select_Body
2300 (Typ
: Entity_Id
) return Node_Id
2302 Com_Block
: Entity_Id
;
2303 Conc_Typ
: Entity_Id
:= Empty
;
2304 Decls
: constant List_Id
:= New_List
;
2305 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
2307 Stmts
: constant List_Id
:= New_List
;
2311 pragma Assert
(not Restriction_Active
(No_Dispatching_Calls
));
2313 -- Null body is generated for interface types
2315 if Is_Interface
(Typ
) then
2317 Make_Subprogram_Body
(Loc
,
2319 Make_Disp_Asynchronous_Select_Spec
(Typ
),
2320 Declarations
=> New_List
,
2321 Handled_Statement_Sequence
=>
2322 Make_Handled_Sequence_Of_Statements
(Loc
,
2324 Make_Assignment_Statement
(Loc
,
2325 Name
=> Make_Identifier
(Loc
, Name_uF
),
2326 Expression
=> New_Occurrence_Of
(Standard_False
, Loc
)))));
2329 if Is_Concurrent_Record_Type
(Typ
) then
2330 Conc_Typ
:= Corresponding_Concurrent_Type
(Typ
);
2334 -- Ada.Tags.Get_Entry_Index (Ada.Tags.Tag! (<type>VP), S);
2336 -- where I will be used to capture the entry index of the primitive
2337 -- wrapper at position S.
2339 if Tagged_Type_Expansion
then
2341 Unchecked_Convert_To
(RTE
(RE_Tag
),
2343 (Node
(First_Elmt
(Access_Disp_Table
(Typ
))), Loc
));
2346 Make_Attribute_Reference
(Loc
,
2347 Prefix
=> New_Occurrence_Of
(Typ
, Loc
),
2348 Attribute_Name
=> Name_Tag
);
2352 Make_Object_Declaration
(Loc
,
2353 Defining_Identifier
=>
2354 Make_Defining_Identifier
(Loc
, Name_uI
),
2355 Object_Definition
=>
2356 New_Occurrence_Of
(Standard_Integer
, Loc
),
2358 Make_Function_Call
(Loc
,
2360 New_Occurrence_Of
(RTE
(RE_Get_Entry_Index
), Loc
),
2361 Parameter_Associations
=>
2362 New_List
(Tag_Node
, Make_Identifier
(Loc
, Name_uS
)))));
2364 if Ekind
(Conc_Typ
) = E_Protected_Type
then
2367 -- Bnn : Communication_Block;
2369 Com_Block
:= Make_Temporary
(Loc
, 'B');
2371 Make_Object_Declaration
(Loc
,
2372 Defining_Identifier
=> Com_Block
,
2373 Object_Definition
=>
2374 New_Occurrence_Of
(RTE
(RE_Communication_Block
), Loc
)));
2376 -- Build T._object'Access for calls below
2379 Make_Attribute_Reference
(Loc
,
2380 Attribute_Name
=> Name_Unchecked_Access
,
2382 Make_Selected_Component
(Loc
,
2383 Prefix
=> Make_Identifier
(Loc
, Name_uT
),
2384 Selector_Name
=> Make_Identifier
(Loc
, Name_uObject
)));
2386 case Corresponding_Runtime_Package
(Conc_Typ
) is
2387 when System_Tasking_Protected_Objects_Entries
=>
2390 -- Protected_Entry_Call
2391 -- (T._object'Access, -- Object
2392 -- Protected_Entry_Index! (I), -- E
2393 -- P, -- Uninterpreted_Data
2394 -- Asynchronous_Call, -- Mode
2395 -- Bnn); -- Communication_Block
2397 -- where T is the protected object, I is the entry index, P
2398 -- is the wrapped parameters and B is the name of the
2399 -- communication block.
2402 Make_Procedure_Call_Statement
(Loc
,
2404 New_Occurrence_Of
(RTE
(RE_Protected_Entry_Call
), Loc
),
2405 Parameter_Associations
=>
2409 Make_Unchecked_Type_Conversion
(Loc
, -- entry index
2412 (RTE
(RE_Protected_Entry_Index
), Loc
),
2413 Expression
=> Make_Identifier
(Loc
, Name_uI
)),
2415 Make_Identifier
(Loc
, Name_uP
), -- parameter block
2416 New_Occurrence_Of
-- Asynchronous_Call
2417 (RTE
(RE_Asynchronous_Call
), Loc
),
2418 New_Occurrence_Of
-- comm block
2419 (Com_Block
, Loc
))));
2422 raise Program_Error
;
2426 -- B := Dummy_Communication_Block (Bnn);
2429 Make_Assignment_Statement
(Loc
,
2430 Name
=> Make_Identifier
(Loc
, Name_uB
),
2432 Make_Unchecked_Type_Conversion
(Loc
,
2435 (RTE
(RE_Dummy_Communication_Block
), Loc
),
2436 Expression
=> New_Occurrence_Of
(Com_Block
, Loc
))));
2442 Make_Assignment_Statement
(Loc
,
2443 Name
=> Make_Identifier
(Loc
, Name_uF
),
2444 Expression
=> New_Occurrence_Of
(Standard_False
, Loc
)));
2447 pragma Assert
(Ekind
(Conc_Typ
) = E_Task_Type
);
2451 -- (T._task_id, -- Acceptor
2452 -- Task_Entry_Index! (I), -- E
2453 -- P, -- Uninterpreted_Data
2454 -- Asynchronous_Call, -- Mode
2455 -- F); -- Rendezvous_Successful
2457 -- where T is the task object, I is the entry index, P is the
2458 -- wrapped parameters and F is the status flag.
2461 Make_Procedure_Call_Statement
(Loc
,
2463 New_Occurrence_Of
(RTE
(RE_Task_Entry_Call
), Loc
),
2464 Parameter_Associations
=>
2466 Make_Selected_Component
(Loc
, -- T._task_id
2467 Prefix
=> Make_Identifier
(Loc
, Name_uT
),
2468 Selector_Name
=> Make_Identifier
(Loc
, Name_uTask_Id
)),
2470 Make_Unchecked_Type_Conversion
(Loc
, -- entry index
2472 New_Occurrence_Of
(RTE
(RE_Task_Entry_Index
), Loc
),
2473 Expression
=> Make_Identifier
(Loc
, Name_uI
)),
2475 Make_Identifier
(Loc
, Name_uP
), -- parameter block
2476 New_Occurrence_Of
-- Asynchronous_Call
2477 (RTE
(RE_Asynchronous_Call
), Loc
),
2478 Make_Identifier
(Loc
, Name_uF
)))); -- status flag
2482 -- Ensure that the statements list is non-empty
2485 Make_Assignment_Statement
(Loc
,
2486 Name
=> Make_Identifier
(Loc
, Name_uF
),
2487 Expression
=> New_Occurrence_Of
(Standard_False
, Loc
)));
2491 Make_Subprogram_Body
(Loc
,
2493 Make_Disp_Asynchronous_Select_Spec
(Typ
),
2494 Declarations
=> Decls
,
2495 Handled_Statement_Sequence
=>
2496 Make_Handled_Sequence_Of_Statements
(Loc
, Stmts
));
2497 end Make_Disp_Asynchronous_Select_Body
;
2499 ----------------------------------------
2500 -- Make_Disp_Asynchronous_Select_Spec --
2501 ----------------------------------------
2503 function Make_Disp_Asynchronous_Select_Spec
2504 (Typ
: Entity_Id
) return Node_Id
2506 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
2507 Def_Id
: constant Node_Id
:=
2508 Make_Defining_Identifier
(Loc
,
2509 Name_uDisp_Asynchronous_Select
);
2510 Params
: constant List_Id
:= New_List
;
2513 pragma Assert
(not Restriction_Active
(No_Dispatching_Calls
));
2515 -- T : in out Typ; -- Object parameter
2516 -- S : Integer; -- Primitive operation slot
2517 -- P : Address; -- Wrapped parameters
2518 -- B : out Dummy_Communication_Block; -- Communication block dummy
2519 -- F : out Boolean; -- Status flag
2521 Append_List_To
(Params
, New_List
(
2523 Make_Parameter_Specification
(Loc
,
2524 Defining_Identifier
=> Make_Defining_Identifier
(Loc
, Name_uT
),
2525 Parameter_Type
=> New_Occurrence_Of
(Typ
, Loc
),
2527 Out_Present
=> True),
2529 Make_Parameter_Specification
(Loc
,
2530 Defining_Identifier
=> Make_Defining_Identifier
(Loc
, Name_uS
),
2531 Parameter_Type
=> New_Occurrence_Of
(Standard_Integer
, Loc
)),
2533 Make_Parameter_Specification
(Loc
,
2534 Defining_Identifier
=> Make_Defining_Identifier
(Loc
, Name_uP
),
2535 Parameter_Type
=> New_Occurrence_Of
(RTE
(RE_Address
), Loc
)),
2537 Make_Parameter_Specification
(Loc
,
2538 Defining_Identifier
=> Make_Defining_Identifier
(Loc
, Name_uB
),
2540 New_Occurrence_Of
(RTE
(RE_Dummy_Communication_Block
), Loc
),
2541 Out_Present
=> True),
2543 Make_Parameter_Specification
(Loc
,
2544 Defining_Identifier
=> Make_Defining_Identifier
(Loc
, Name_uF
),
2545 Parameter_Type
=> New_Occurrence_Of
(Standard_Boolean
, Loc
),
2546 Out_Present
=> True)));
2549 Make_Procedure_Specification
(Loc
,
2550 Defining_Unit_Name
=> Def_Id
,
2551 Parameter_Specifications
=> Params
);
2552 end Make_Disp_Asynchronous_Select_Spec
;
2554 ---------------------------------------
2555 -- Make_Disp_Conditional_Select_Body --
2556 ---------------------------------------
2558 -- For interface types, generate:
2560 -- procedure _Disp_Conditional_Select
2561 -- (T : in out <Typ>;
2563 -- P : System.Address;
2564 -- C : out Ada.Tags.Prim_Op_Kind;
2569 -- C := Ada.Tags.POK_Function;
2570 -- end _Disp_Conditional_Select;
2572 -- For protected types, generate:
2574 -- procedure _Disp_Conditional_Select
2575 -- (T : in out <Typ>;
2577 -- P : System.Address;
2578 -- C : out Ada.Tags.Prim_Op_Kind;
2582 -- Bnn : System.Tasking.Protected_Objects.Operations.
2583 -- Communication_Block;
2586 -- C := Ada.Tags.Get_Prim_Op_Kind (Ada.Tags.Tag (<Typ>VP, S));
2588 -- if C = Ada.Tags.POK_Procedure
2589 -- or else C = Ada.Tags.POK_Protected_Procedure
2590 -- or else C = Ada.Tags.POK_Task_Procedure
2596 -- I := Ada.Tags.Get_Entry_Index (Ada.Tags.Tag (<Typ>VP, S));
2597 -- System.Tasking.Protected_Objects.Operations.Protected_Entry_Call
2598 -- (T.object'Access,
2599 -- System.Tasking.Protected_Objects.Protected_Entry_Index (I),
2601 -- System.Tasking.Conditional_Call,
2603 -- F := not Cancelled (Bnn);
2604 -- end _Disp_Conditional_Select;
2606 -- For task types, generate:
2608 -- procedure _Disp_Conditional_Select
2609 -- (T : in out <Typ>;
2611 -- P : System.Address;
2612 -- C : out Ada.Tags.Prim_Op_Kind;
2618 -- I := Ada.Tags.Get_Entry_Index (Ada.Tags.Tag (<Typ>VP, S));
2619 -- System.Tasking.Rendezvous.Task_Entry_Call
2621 -- System.Tasking.Task_Entry_Index (I),
2623 -- System.Tasking.Conditional_Call,
2625 -- end _Disp_Conditional_Select;
2627 function Make_Disp_Conditional_Select_Body
2628 (Typ
: Entity_Id
) return Node_Id
2630 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
2631 Blk_Nam
: Entity_Id
;
2632 Conc_Typ
: Entity_Id
:= Empty
;
2633 Decls
: constant List_Id
:= New_List
;
2635 Stmts
: constant List_Id
:= New_List
;
2639 pragma Assert
(not Restriction_Active
(No_Dispatching_Calls
));
2641 -- Null body is generated for interface types
2643 if Is_Interface
(Typ
) then
2645 Make_Subprogram_Body
(Loc
,
2647 Make_Disp_Conditional_Select_Spec
(Typ
),
2648 Declarations
=> No_List
,
2649 Handled_Statement_Sequence
=>
2650 Make_Handled_Sequence_Of_Statements
(Loc
,
2651 New_List
(Make_Assignment_Statement
(Loc
,
2652 Name
=> Make_Identifier
(Loc
, Name_uF
),
2653 Expression
=> New_Occurrence_Of
(Standard_False
, Loc
)))));
2656 if Is_Concurrent_Record_Type
(Typ
) then
2657 Conc_Typ
:= Corresponding_Concurrent_Type
(Typ
);
2662 -- where I will be used to capture the entry index of the primitive
2663 -- wrapper at position S.
2666 Make_Object_Declaration
(Loc
,
2667 Defining_Identifier
=> Make_Defining_Identifier
(Loc
, Name_uI
),
2668 Object_Definition
=>
2669 New_Occurrence_Of
(Standard_Integer
, Loc
)));
2672 -- C := Ada.Tags.Get_Prim_Op_Kind (Ada.Tags.Tag! (<type>VP), S);
2674 -- if C = POK_Procedure
2675 -- or else C = POK_Protected_Procedure
2676 -- or else C = POK_Task_Procedure;
2682 Build_Common_Dispatching_Select_Statements
(Typ
, Stmts
);
2685 -- Bnn : Communication_Block;
2687 -- where Bnn is the name of the communication block used in the
2688 -- call to Protected_Entry_Call.
2690 Blk_Nam
:= Make_Temporary
(Loc
, 'B');
2692 Make_Object_Declaration
(Loc
,
2693 Defining_Identifier
=> Blk_Nam
,
2694 Object_Definition
=>
2695 New_Occurrence_Of
(RTE
(RE_Communication_Block
), Loc
)));
2698 -- I := Ada.Tags.Get_Entry_Index (Ada.Tags.Tag! (<type>VP), S);
2700 -- I is the entry index and S is the dispatch table slot
2702 if Tagged_Type_Expansion
then
2704 Unchecked_Convert_To
(RTE
(RE_Tag
),
2706 (Node
(First_Elmt
(Access_Disp_Table
(Typ
))), Loc
));
2710 Make_Attribute_Reference
(Loc
,
2711 Prefix
=> New_Occurrence_Of
(Typ
, Loc
),
2712 Attribute_Name
=> Name_Tag
);
2716 Make_Assignment_Statement
(Loc
,
2717 Name
=> Make_Identifier
(Loc
, Name_uI
),
2719 Make_Function_Call
(Loc
,
2721 New_Occurrence_Of
(RTE
(RE_Get_Entry_Index
), Loc
),
2722 Parameter_Associations
=> New_List
(
2724 Make_Identifier
(Loc
, Name_uS
)))));
2726 if Ekind
(Conc_Typ
) = E_Protected_Type
then
2728 Obj_Ref
:= -- T._object'Access
2729 Make_Attribute_Reference
(Loc
,
2730 Attribute_Name
=> Name_Unchecked_Access
,
2732 Make_Selected_Component
(Loc
,
2733 Prefix
=> Make_Identifier
(Loc
, Name_uT
),
2734 Selector_Name
=> Make_Identifier
(Loc
, Name_uObject
)));
2736 case Corresponding_Runtime_Package
(Conc_Typ
) is
2737 when System_Tasking_Protected_Objects_Entries
=>
2740 -- Protected_Entry_Call
2741 -- (T._object'Access, -- Object
2742 -- Protected_Entry_Index! (I), -- E
2743 -- P, -- Uninterpreted_Data
2744 -- Conditional_Call, -- Mode
2747 -- where T is the protected object, I is the entry index, P
2748 -- are the wrapped parameters and Bnn is the name of the
2749 -- communication block.
2752 Make_Procedure_Call_Statement
(Loc
,
2754 New_Occurrence_Of
(RTE
(RE_Protected_Entry_Call
), Loc
),
2755 Parameter_Associations
=> New_List
(
2758 Make_Unchecked_Type_Conversion
(Loc
, -- entry index
2761 (RTE
(RE_Protected_Entry_Index
), Loc
),
2762 Expression
=> Make_Identifier
(Loc
, Name_uI
)),
2764 Make_Identifier
(Loc
, Name_uP
), -- parameter block
2766 New_Occurrence_Of
-- Conditional_Call
2767 (RTE
(RE_Conditional_Call
), Loc
),
2768 New_Occurrence_Of
-- Bnn
2771 when System_Tasking_Protected_Objects_Single_Entry
=>
2773 -- If we are compiling for a restricted run-time, the call
2774 -- uses the simpler form.
2777 Make_Procedure_Call_Statement
(Loc
,
2780 (RTE
(RE_Protected_Single_Entry_Call
), Loc
),
2781 Parameter_Associations
=> New_List
(
2784 Make_Attribute_Reference
(Loc
,
2785 Prefix
=> Make_Identifier
(Loc
, Name_uP
),
2786 Attribute_Name
=> Name_Address
),
2789 (RTE
(RE_Conditional_Call
), Loc
))));
2791 raise Program_Error
;
2795 -- F := not Cancelled (Bnn);
2797 -- where F is the success flag. The status of Cancelled is negated
2798 -- in order to match the behavior of the version for task types.
2801 Make_Assignment_Statement
(Loc
,
2802 Name
=> Make_Identifier
(Loc
, Name_uF
),
2806 Make_Function_Call
(Loc
,
2808 New_Occurrence_Of
(RTE
(RE_Cancelled
), Loc
),
2809 Parameter_Associations
=> New_List
(
2810 New_Occurrence_Of
(Blk_Nam
, Loc
))))));
2812 pragma Assert
(Ekind
(Conc_Typ
) = E_Task_Type
);
2816 -- (T._task_id, -- Acceptor
2817 -- Task_Entry_Index! (I), -- E
2818 -- P, -- Uninterpreted_Data
2819 -- Conditional_Call, -- Mode
2820 -- F); -- Rendezvous_Successful
2822 -- where T is the task object, I is the entry index, P are the
2823 -- wrapped parameters and F is the status flag.
2826 Make_Procedure_Call_Statement
(Loc
,
2828 New_Occurrence_Of
(RTE
(RE_Task_Entry_Call
), Loc
),
2829 Parameter_Associations
=> New_List
(
2831 Make_Selected_Component
(Loc
, -- T._task_id
2832 Prefix
=> Make_Identifier
(Loc
, Name_uT
),
2833 Selector_Name
=> Make_Identifier
(Loc
, Name_uTask_Id
)),
2835 Make_Unchecked_Type_Conversion
(Loc
, -- entry index
2837 New_Occurrence_Of
(RTE
(RE_Task_Entry_Index
), Loc
),
2838 Expression
=> Make_Identifier
(Loc
, Name_uI
)),
2840 Make_Identifier
(Loc
, Name_uP
), -- parameter block
2841 New_Occurrence_Of
-- Conditional_Call
2842 (RTE
(RE_Conditional_Call
), Loc
),
2843 Make_Identifier
(Loc
, Name_uF
)))); -- status flag
2847 -- Initialize out parameters
2850 Make_Assignment_Statement
(Loc
,
2851 Name
=> Make_Identifier
(Loc
, Name_uF
),
2852 Expression
=> New_Occurrence_Of
(Standard_False
, Loc
)));
2854 Make_Assignment_Statement
(Loc
,
2855 Name
=> Make_Identifier
(Loc
, Name_uC
),
2856 Expression
=> New_Occurrence_Of
(RTE
(RE_POK_Function
), Loc
)));
2860 Make_Subprogram_Body
(Loc
,
2862 Make_Disp_Conditional_Select_Spec
(Typ
),
2863 Declarations
=> Decls
,
2864 Handled_Statement_Sequence
=>
2865 Make_Handled_Sequence_Of_Statements
(Loc
, Stmts
));
2866 end Make_Disp_Conditional_Select_Body
;
2868 ---------------------------------------
2869 -- Make_Disp_Conditional_Select_Spec --
2870 ---------------------------------------
2872 function Make_Disp_Conditional_Select_Spec
2873 (Typ
: Entity_Id
) return Node_Id
2875 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
2876 Def_Id
: constant Node_Id
:=
2877 Make_Defining_Identifier
(Loc
,
2878 Name_uDisp_Conditional_Select
);
2879 Params
: constant List_Id
:= New_List
;
2882 pragma Assert
(not Restriction_Active
(No_Dispatching_Calls
));
2884 -- T : in out Typ; -- Object parameter
2885 -- S : Integer; -- Primitive operation slot
2886 -- P : Address; -- Wrapped parameters
2887 -- C : out Prim_Op_Kind; -- Call kind
2888 -- F : out Boolean; -- Status flag
2890 Append_List_To
(Params
, New_List
(
2892 Make_Parameter_Specification
(Loc
,
2893 Defining_Identifier
=> Make_Defining_Identifier
(Loc
, Name_uT
),
2894 Parameter_Type
=> New_Occurrence_Of
(Typ
, Loc
),
2896 Out_Present
=> True),
2898 Make_Parameter_Specification
(Loc
,
2899 Defining_Identifier
=> Make_Defining_Identifier
(Loc
, Name_uS
),
2900 Parameter_Type
=> New_Occurrence_Of
(Standard_Integer
, Loc
)),
2902 Make_Parameter_Specification
(Loc
,
2903 Defining_Identifier
=> Make_Defining_Identifier
(Loc
, Name_uP
),
2904 Parameter_Type
=> New_Occurrence_Of
(RTE
(RE_Address
), Loc
)),
2906 Make_Parameter_Specification
(Loc
,
2907 Defining_Identifier
=> Make_Defining_Identifier
(Loc
, Name_uC
),
2909 New_Occurrence_Of
(RTE
(RE_Prim_Op_Kind
), Loc
),
2910 Out_Present
=> True),
2912 Make_Parameter_Specification
(Loc
,
2913 Defining_Identifier
=> Make_Defining_Identifier
(Loc
, Name_uF
),
2914 Parameter_Type
=> New_Occurrence_Of
(Standard_Boolean
, Loc
),
2915 Out_Present
=> True)));
2918 Make_Procedure_Specification
(Loc
,
2919 Defining_Unit_Name
=> Def_Id
,
2920 Parameter_Specifications
=> Params
);
2921 end Make_Disp_Conditional_Select_Spec
;
2923 -------------------------------------
2924 -- Make_Disp_Get_Prim_Op_Kind_Body --
2925 -------------------------------------
2927 function Make_Disp_Get_Prim_Op_Kind_Body
(Typ
: Entity_Id
) return Node_Id
is
2928 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
2932 pragma Assert
(not Restriction_Active
(No_Dispatching_Calls
));
2934 if Is_Interface
(Typ
) then
2936 Make_Subprogram_Body
(Loc
,
2938 Make_Disp_Get_Prim_Op_Kind_Spec
(Typ
),
2939 Declarations
=> New_List
,
2940 Handled_Statement_Sequence
=>
2941 Make_Handled_Sequence_Of_Statements
(Loc
,
2942 New_List
(Make_Null_Statement
(Loc
))));
2946 -- C := get_prim_op_kind (tag! (<type>VP), S);
2948 -- where C is the out parameter capturing the call kind and S is the
2949 -- dispatch table slot number.
2951 if Tagged_Type_Expansion
then
2953 Unchecked_Convert_To
(RTE
(RE_Tag
),
2955 (Node
(First_Elmt
(Access_Disp_Table
(Typ
))), Loc
));
2959 Make_Attribute_Reference
(Loc
,
2960 Prefix
=> New_Occurrence_Of
(Typ
, Loc
),
2961 Attribute_Name
=> Name_Tag
);
2965 Make_Subprogram_Body
(Loc
,
2967 Make_Disp_Get_Prim_Op_Kind_Spec
(Typ
),
2968 Declarations
=> New_List
,
2969 Handled_Statement_Sequence
=>
2970 Make_Handled_Sequence_Of_Statements
(Loc
,
2972 Make_Assignment_Statement
(Loc
,
2973 Name
=> Make_Identifier
(Loc
, Name_uC
),
2975 Make_Function_Call
(Loc
,
2977 New_Occurrence_Of
(RTE
(RE_Get_Prim_Op_Kind
), Loc
),
2978 Parameter_Associations
=> New_List
(
2980 Make_Identifier
(Loc
, Name_uS
)))))));
2981 end Make_Disp_Get_Prim_Op_Kind_Body
;
2983 -------------------------------------
2984 -- Make_Disp_Get_Prim_Op_Kind_Spec --
2985 -------------------------------------
2987 function Make_Disp_Get_Prim_Op_Kind_Spec
2988 (Typ
: Entity_Id
) return Node_Id
2990 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
2991 Def_Id
: constant Node_Id
:=
2992 Make_Defining_Identifier
(Loc
, Name_uDisp_Get_Prim_Op_Kind
);
2993 Params
: constant List_Id
:= New_List
;
2996 pragma Assert
(not Restriction_Active
(No_Dispatching_Calls
));
2998 -- T : in out Typ; -- Object parameter
2999 -- S : Integer; -- Primitive operation slot
3000 -- C : out Prim_Op_Kind; -- Call kind
3002 Append_List_To
(Params
, New_List
(
3004 Make_Parameter_Specification
(Loc
,
3005 Defining_Identifier
=> Make_Defining_Identifier
(Loc
, Name_uT
),
3006 Parameter_Type
=> New_Occurrence_Of
(Typ
, Loc
),
3008 Out_Present
=> True),
3010 Make_Parameter_Specification
(Loc
,
3011 Defining_Identifier
=> Make_Defining_Identifier
(Loc
, Name_uS
),
3012 Parameter_Type
=> New_Occurrence_Of
(Standard_Integer
, Loc
)),
3014 Make_Parameter_Specification
(Loc
,
3015 Defining_Identifier
=> Make_Defining_Identifier
(Loc
, Name_uC
),
3017 New_Occurrence_Of
(RTE
(RE_Prim_Op_Kind
), Loc
),
3018 Out_Present
=> True)));
3021 Make_Procedure_Specification
(Loc
,
3022 Defining_Unit_Name
=> Def_Id
,
3023 Parameter_Specifications
=> Params
);
3024 end Make_Disp_Get_Prim_Op_Kind_Spec
;
3026 --------------------------------
3027 -- Make_Disp_Get_Task_Id_Body --
3028 --------------------------------
3030 function Make_Disp_Get_Task_Id_Body
3031 (Typ
: Entity_Id
) return Node_Id
3033 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
3037 pragma Assert
(not Restriction_Active
(No_Dispatching_Calls
));
3039 if Is_Concurrent_Record_Type
(Typ
)
3040 and then Ekind
(Corresponding_Concurrent_Type
(Typ
)) = E_Task_Type
3043 -- return To_Address (_T._task_id);
3046 Make_Simple_Return_Statement
(Loc
,
3048 Make_Unchecked_Type_Conversion
(Loc
,
3049 Subtype_Mark
=> New_Occurrence_Of
(RTE
(RE_Address
), Loc
),
3051 Make_Selected_Component
(Loc
,
3052 Prefix
=> Make_Identifier
(Loc
, Name_uT
),
3053 Selector_Name
=> Make_Identifier
(Loc
, Name_uTask_Id
))));
3055 -- A null body is constructed for non-task types
3059 -- return Null_Address;
3062 Make_Simple_Return_Statement
(Loc
,
3063 Expression
=> New_Occurrence_Of
(RTE
(RE_Null_Address
), Loc
));
3067 Make_Subprogram_Body
(Loc
,
3068 Specification
=> Make_Disp_Get_Task_Id_Spec
(Typ
),
3069 Declarations
=> New_List
,
3070 Handled_Statement_Sequence
=>
3071 Make_Handled_Sequence_Of_Statements
(Loc
, New_List
(Ret
)));
3072 end Make_Disp_Get_Task_Id_Body
;
3074 --------------------------------
3075 -- Make_Disp_Get_Task_Id_Spec --
3076 --------------------------------
3078 function Make_Disp_Get_Task_Id_Spec
3079 (Typ
: Entity_Id
) return Node_Id
3081 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
3084 pragma Assert
(not Restriction_Active
(No_Dispatching_Calls
));
3087 Make_Function_Specification
(Loc
,
3088 Defining_Unit_Name
=>
3089 Make_Defining_Identifier
(Loc
, Name_uDisp_Get_Task_Id
),
3090 Parameter_Specifications
=> New_List
(
3091 Make_Parameter_Specification
(Loc
,
3092 Defining_Identifier
=> Make_Defining_Identifier
(Loc
, Name_uT
),
3093 Parameter_Type
=> New_Occurrence_Of
(Typ
, Loc
))),
3094 Result_Definition
=>
3095 New_Occurrence_Of
(RTE
(RE_Address
), Loc
));
3096 end Make_Disp_Get_Task_Id_Spec
;
3098 ----------------------------
3099 -- Make_Disp_Requeue_Body --
3100 ----------------------------
3102 function Make_Disp_Requeue_Body
3103 (Typ
: Entity_Id
) return Node_Id
3105 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
3106 Conc_Typ
: Entity_Id
:= Empty
;
3107 Stmts
: constant List_Id
:= New_List
;
3110 pragma Assert
(not Restriction_Active
(No_Dispatching_Calls
));
3112 -- Null body is generated for interface types and non-concurrent
3115 if Is_Interface
(Typ
)
3116 or else not Is_Concurrent_Record_Type
(Typ
)
3119 Make_Subprogram_Body
(Loc
,
3120 Specification
=> Make_Disp_Requeue_Spec
(Typ
),
3121 Declarations
=> No_List
,
3122 Handled_Statement_Sequence
=>
3123 Make_Handled_Sequence_Of_Statements
(Loc
,
3124 New_List
(Make_Null_Statement
(Loc
))));
3127 Conc_Typ
:= Corresponding_Concurrent_Type
(Typ
);
3129 if Ekind
(Conc_Typ
) = E_Protected_Type
then
3131 -- Generate statements:
3133 -- System.Tasking.Protected_Objects.Operations.
3134 -- Requeue_Protected_Entry
3135 -- (Protection_Entries_Access (P),
3136 -- O._object'Unchecked_Access,
3137 -- Protected_Entry_Index (I),
3140 -- System.Tasking.Protected_Objects.Operations.
3141 -- Requeue_Task_To_Protected_Entry
3142 -- (O._object'Unchecked_Access,
3143 -- Protected_Entry_Index (I),
3147 if Restriction_Active
(No_Entry_Queue
) then
3148 Append_To
(Stmts
, Make_Null_Statement
(Loc
));
3151 Make_If_Statement
(Loc
,
3152 Condition
=> Make_Identifier
(Loc
, Name_uF
),
3157 -- Call to Requeue_Protected_Entry
3159 Make_Procedure_Call_Statement
(Loc
,
3162 (RTE
(RE_Requeue_Protected_Entry
), Loc
),
3163 Parameter_Associations
=>
3166 Make_Unchecked_Type_Conversion
(Loc
, -- PEA (P)
3169 RTE
(RE_Protection_Entries_Access
), Loc
),
3171 Make_Identifier
(Loc
, Name_uP
)),
3173 Make_Attribute_Reference
(Loc
, -- O._object'Acc
3175 Name_Unchecked_Access
,
3177 Make_Selected_Component
(Loc
,
3179 Make_Identifier
(Loc
, Name_uO
),
3181 Make_Identifier
(Loc
, Name_uObject
))),
3183 Make_Unchecked_Type_Conversion
(Loc
, -- entry index
3186 (RTE
(RE_Protected_Entry_Index
), Loc
),
3187 Expression
=> Make_Identifier
(Loc
, Name_uI
)),
3189 Make_Identifier
(Loc
, Name_uA
)))), -- abort status
3194 -- Call to Requeue_Task_To_Protected_Entry
3196 Make_Procedure_Call_Statement
(Loc
,
3199 (RTE
(RE_Requeue_Task_To_Protected_Entry
), Loc
),
3200 Parameter_Associations
=>
3203 Make_Attribute_Reference
(Loc
, -- O._object'Acc
3204 Attribute_Name
=> Name_Unchecked_Access
,
3206 Make_Selected_Component
(Loc
,
3208 Make_Identifier
(Loc
, Name_uO
),
3210 Make_Identifier
(Loc
, Name_uObject
))),
3212 Make_Unchecked_Type_Conversion
(Loc
, -- entry index
3215 (RTE
(RE_Protected_Entry_Index
), Loc
),
3216 Expression
=> Make_Identifier
(Loc
, Name_uI
)),
3218 Make_Identifier
(Loc
, Name_uA
)))))); -- abort status
3222 pragma Assert
(Is_Task_Type
(Conc_Typ
));
3226 -- System.Tasking.Rendezvous.Requeue_Protected_To_Task_Entry
3227 -- (Protection_Entries_Access (P),
3229 -- Task_Entry_Index (I),
3232 -- System.Tasking.Rendezvous.Requeue_Task_Entry
3234 -- Task_Entry_Index (I),
3239 Make_If_Statement
(Loc
,
3240 Condition
=> Make_Identifier
(Loc
, Name_uF
),
3242 Then_Statements
=> New_List
(
3244 -- Call to Requeue_Protected_To_Task_Entry
3246 Make_Procedure_Call_Statement
(Loc
,
3249 (RTE
(RE_Requeue_Protected_To_Task_Entry
), Loc
),
3251 Parameter_Associations
=> New_List
(
3253 Make_Unchecked_Type_Conversion
(Loc
, -- PEA (P)
3256 (RTE
(RE_Protection_Entries_Access
), Loc
),
3257 Expression
=> Make_Identifier
(Loc
, Name_uP
)),
3259 Make_Selected_Component
(Loc
, -- O._task_id
3260 Prefix
=> Make_Identifier
(Loc
, Name_uO
),
3261 Selector_Name
=> Make_Identifier
(Loc
, Name_uTask_Id
)),
3263 Make_Unchecked_Type_Conversion
(Loc
, -- entry index
3265 New_Occurrence_Of
(RTE
(RE_Task_Entry_Index
), Loc
),
3266 Expression
=> Make_Identifier
(Loc
, Name_uI
)),
3268 Make_Identifier
(Loc
, Name_uA
)))), -- abort status
3270 Else_Statements
=> New_List
(
3272 -- Call to Requeue_Task_Entry
3274 Make_Procedure_Call_Statement
(Loc
,
3276 New_Occurrence_Of
(RTE
(RE_Requeue_Task_Entry
), Loc
),
3278 Parameter_Associations
=> New_List
(
3280 Make_Selected_Component
(Loc
, -- O._task_id
3281 Prefix
=> Make_Identifier
(Loc
, Name_uO
),
3282 Selector_Name
=> Make_Identifier
(Loc
, Name_uTask_Id
)),
3284 Make_Unchecked_Type_Conversion
(Loc
, -- entry index
3286 New_Occurrence_Of
(RTE
(RE_Task_Entry_Index
), Loc
),
3287 Expression
=> Make_Identifier
(Loc
, Name_uI
)),
3289 Make_Identifier
(Loc
, Name_uA
)))))); -- abort status
3292 -- Even though no declarations are needed in both cases, we allocate
3293 -- a list for entities added by Freeze.
3296 Make_Subprogram_Body
(Loc
,
3297 Specification
=> Make_Disp_Requeue_Spec
(Typ
),
3298 Declarations
=> New_List
,
3299 Handled_Statement_Sequence
=>
3300 Make_Handled_Sequence_Of_Statements
(Loc
, Stmts
));
3301 end Make_Disp_Requeue_Body
;
3303 ----------------------------
3304 -- Make_Disp_Requeue_Spec --
3305 ----------------------------
3307 function Make_Disp_Requeue_Spec
3308 (Typ
: Entity_Id
) return Node_Id
3310 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
3313 pragma Assert
(not Restriction_Active
(No_Dispatching_Calls
));
3315 -- O : in out Typ; - Object parameter
3316 -- F : Boolean; - Protected (True) / task (False) flag
3317 -- P : Address; - Protection_Entries_Access value
3318 -- I : Entry_Index - Index of entry call
3319 -- A : Boolean - Abort flag
3321 -- Note that the Protection_Entries_Access value is represented as a
3322 -- System.Address in order to avoid dragging in the tasking runtime
3323 -- when compiling sources without tasking constructs.
3326 Make_Procedure_Specification
(Loc
,
3327 Defining_Unit_Name
=>
3328 Make_Defining_Identifier
(Loc
, Name_uDisp_Requeue
),
3330 Parameter_Specifications
=> New_List
(
3332 Make_Parameter_Specification
(Loc
, -- O
3333 Defining_Identifier
=>
3334 Make_Defining_Identifier
(Loc
, Name_uO
),
3336 New_Occurrence_Of
(Typ
, Loc
),
3338 Out_Present
=> True),
3340 Make_Parameter_Specification
(Loc
, -- F
3341 Defining_Identifier
=>
3342 Make_Defining_Identifier
(Loc
, Name_uF
),
3344 New_Occurrence_Of
(Standard_Boolean
, Loc
)),
3346 Make_Parameter_Specification
(Loc
, -- P
3347 Defining_Identifier
=>
3348 Make_Defining_Identifier
(Loc
, Name_uP
),
3350 New_Occurrence_Of
(RTE
(RE_Address
), Loc
)),
3352 Make_Parameter_Specification
(Loc
, -- I
3353 Defining_Identifier
=>
3354 Make_Defining_Identifier
(Loc
, Name_uI
),
3356 New_Occurrence_Of
(Standard_Integer
, Loc
)),
3358 Make_Parameter_Specification
(Loc
, -- A
3359 Defining_Identifier
=>
3360 Make_Defining_Identifier
(Loc
, Name_uA
),
3362 New_Occurrence_Of
(Standard_Boolean
, Loc
))));
3363 end Make_Disp_Requeue_Spec
;
3365 ---------------------------------
3366 -- Make_Disp_Timed_Select_Body --
3367 ---------------------------------
3369 -- For interface types, generate:
3371 -- procedure _Disp_Timed_Select
3372 -- (T : in out <Typ>;
3374 -- P : System.Address;
3377 -- C : out Ada.Tags.Prim_Op_Kind;
3382 -- C := Ada.Tags.POK_Function;
3383 -- end _Disp_Timed_Select;
3385 -- For protected types, generate:
3387 -- procedure _Disp_Timed_Select
3388 -- (T : in out <Typ>;
3390 -- P : System.Address;
3393 -- C : out Ada.Tags.Prim_Op_Kind;
3399 -- C := Ada.Tags.Get_Prim_Op_Kind (Ada.Tags.Tag (<Typ>VP), S);
3401 -- if C = Ada.Tags.POK_Procedure
3402 -- or else C = Ada.Tags.POK_Protected_Procedure
3403 -- or else C = Ada.Tags.POK_Task_Procedure
3409 -- I := Ada.Tags.Get_Entry_Index (Ada.Tags.Tag (<Typ>VP), S);
3410 -- System.Tasking.Protected_Objects.Operations.
3411 -- Timed_Protected_Entry_Call
3412 -- (T._object'Access,
3413 -- System.Tasking.Protected_Objects.Protected_Entry_Index (I),
3418 -- end _Disp_Timed_Select;
3420 -- For task types, generate:
3422 -- procedure _Disp_Timed_Select
3423 -- (T : in out <Typ>;
3425 -- P : System.Address;
3428 -- C : out Ada.Tags.Prim_Op_Kind;
3434 -- I := Ada.Tags.Get_Entry_Index (Ada.Tags.Tag (<Typ>VP), S);
3435 -- System.Tasking.Rendezvous.Timed_Task_Entry_Call
3437 -- System.Tasking.Task_Entry_Index (I),
3442 -- end _Disp_Time_Select;
3444 function Make_Disp_Timed_Select_Body
3445 (Typ
: Entity_Id
) return Node_Id
3447 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
3448 Conc_Typ
: Entity_Id
:= Empty
;
3449 Decls
: constant List_Id
:= New_List
;
3451 Stmts
: constant List_Id
:= New_List
;
3455 pragma Assert
(not Restriction_Active
(No_Dispatching_Calls
));
3457 -- Null body is generated for interface types
3459 if Is_Interface
(Typ
) then
3461 Make_Subprogram_Body
(Loc
,
3462 Specification
=> Make_Disp_Timed_Select_Spec
(Typ
),
3463 Declarations
=> New_List
,
3464 Handled_Statement_Sequence
=>
3465 Make_Handled_Sequence_Of_Statements
(Loc
,
3467 Make_Assignment_Statement
(Loc
,
3468 Name
=> Make_Identifier
(Loc
, Name_uF
),
3469 Expression
=> New_Occurrence_Of
(Standard_False
, Loc
)))));
3472 if Is_Concurrent_Record_Type
(Typ
) then
3473 Conc_Typ
:= Corresponding_Concurrent_Type
(Typ
);
3478 -- where I will be used to capture the entry index of the primitive
3479 -- wrapper at position S.
3482 Make_Object_Declaration
(Loc
,
3483 Defining_Identifier
=> Make_Defining_Identifier
(Loc
, Name_uI
),
3484 Object_Definition
=>
3485 New_Occurrence_Of
(Standard_Integer
, Loc
)));
3488 -- C := Get_Prim_Op_Kind (tag! (<type>VP), S);
3490 -- if C = POK_Procedure
3491 -- or else C = POK_Protected_Procedure
3492 -- or else C = POK_Task_Procedure;
3498 Build_Common_Dispatching_Select_Statements
(Typ
, Stmts
);
3501 -- I := Get_Entry_Index (tag! (<type>VP), S);
3503 -- I is the entry index and S is the dispatch table slot
3505 if Tagged_Type_Expansion
then
3507 Unchecked_Convert_To
(RTE
(RE_Tag
),
3509 (Node
(First_Elmt
(Access_Disp_Table
(Typ
))), Loc
));
3513 Make_Attribute_Reference
(Loc
,
3514 Prefix
=> New_Occurrence_Of
(Typ
, Loc
),
3515 Attribute_Name
=> Name_Tag
);
3519 Make_Assignment_Statement
(Loc
,
3520 Name
=> Make_Identifier
(Loc
, Name_uI
),
3522 Make_Function_Call
(Loc
,
3523 Name
=> New_Occurrence_Of
(RTE
(RE_Get_Entry_Index
), Loc
),
3524 Parameter_Associations
=> New_List
(
3526 Make_Identifier
(Loc
, Name_uS
)))));
3530 if Ekind
(Conc_Typ
) = E_Protected_Type
then
3532 -- Build T._object'Access
3535 Make_Attribute_Reference
(Loc
,
3536 Attribute_Name
=> Name_Unchecked_Access
,
3538 Make_Selected_Component
(Loc
,
3539 Prefix
=> Make_Identifier
(Loc
, Name_uT
),
3540 Selector_Name
=> Make_Identifier
(Loc
, Name_uObject
)));
3542 -- Normal case, No_Entry_Queue restriction not active. In this
3543 -- case we generate:
3545 -- Timed_Protected_Entry_Call
3546 -- (T._object'access,
3547 -- Protected_Entry_Index! (I),
3550 -- where T is the protected object, I is the entry index, P are
3551 -- the wrapped parameters, D is the delay amount, M is the delay
3552 -- mode and F is the status flag.
3554 -- Historically, there was also an implementation for single
3555 -- entry protected types (in s-tposen). However, it was removed
3556 -- by also testing for no No_Select_Statements restriction in
3557 -- Exp_Utils.Corresponding_Runtime_Package. This simplified the
3558 -- implementation of s-tposen.adb and provided consistency between
3559 -- all versions of System.Tasking.Protected_Objects.Single_Entry
3562 case Corresponding_Runtime_Package
(Conc_Typ
) is
3563 when System_Tasking_Protected_Objects_Entries
=>
3565 Make_Procedure_Call_Statement
(Loc
,
3568 (RTE
(RE_Timed_Protected_Entry_Call
), Loc
),
3569 Parameter_Associations
=> New_List
(
3572 Make_Unchecked_Type_Conversion
(Loc
, -- entry index
3575 (RTE
(RE_Protected_Entry_Index
), Loc
),
3576 Expression
=> Make_Identifier
(Loc
, Name_uI
)),
3578 Make_Identifier
(Loc
, Name_uP
), -- parameter block
3579 Make_Identifier
(Loc
, Name_uD
), -- delay
3580 Make_Identifier
(Loc
, Name_uM
), -- delay mode
3581 Make_Identifier
(Loc
, Name_uF
)))); -- status flag
3584 raise Program_Error
;
3590 pragma Assert
(Ekind
(Conc_Typ
) = E_Task_Type
);
3593 -- Timed_Task_Entry_Call (
3595 -- Task_Entry_Index! (I),
3601 -- where T is the task object, I is the entry index, P are the
3602 -- wrapped parameters, D is the delay amount, M is the delay
3603 -- mode and F is the status flag.
3606 Make_Procedure_Call_Statement
(Loc
,
3608 New_Occurrence_Of
(RTE
(RE_Timed_Task_Entry_Call
), Loc
),
3610 Parameter_Associations
=> New_List
(
3611 Make_Selected_Component
(Loc
, -- T._task_id
3612 Prefix
=> Make_Identifier
(Loc
, Name_uT
),
3613 Selector_Name
=> Make_Identifier
(Loc
, Name_uTask_Id
)),
3615 Make_Unchecked_Type_Conversion
(Loc
, -- entry index
3617 New_Occurrence_Of
(RTE
(RE_Task_Entry_Index
), Loc
),
3618 Expression
=> Make_Identifier
(Loc
, Name_uI
)),
3620 Make_Identifier
(Loc
, Name_uP
), -- parameter block
3621 Make_Identifier
(Loc
, Name_uD
), -- delay
3622 Make_Identifier
(Loc
, Name_uM
), -- delay mode
3623 Make_Identifier
(Loc
, Name_uF
)))); -- status flag
3627 -- Initialize out parameters
3630 Make_Assignment_Statement
(Loc
,
3631 Name
=> Make_Identifier
(Loc
, Name_uF
),
3632 Expression
=> New_Occurrence_Of
(Standard_False
, Loc
)));
3634 Make_Assignment_Statement
(Loc
,
3635 Name
=> Make_Identifier
(Loc
, Name_uC
),
3636 Expression
=> New_Occurrence_Of
(RTE
(RE_POK_Function
), Loc
)));
3640 Make_Subprogram_Body
(Loc
,
3641 Specification
=> Make_Disp_Timed_Select_Spec
(Typ
),
3642 Declarations
=> Decls
,
3643 Handled_Statement_Sequence
=>
3644 Make_Handled_Sequence_Of_Statements
(Loc
, Stmts
));
3645 end Make_Disp_Timed_Select_Body
;
3647 ---------------------------------
3648 -- Make_Disp_Timed_Select_Spec --
3649 ---------------------------------
3651 function Make_Disp_Timed_Select_Spec
3652 (Typ
: Entity_Id
) return Node_Id
3654 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
3655 Def_Id
: constant Node_Id
:=
3656 Make_Defining_Identifier
(Loc
,
3657 Name_uDisp_Timed_Select
);
3658 Params
: constant List_Id
:= New_List
;
3661 pragma Assert
(not Restriction_Active
(No_Dispatching_Calls
));
3663 -- T : in out Typ; -- Object parameter
3664 -- S : Integer; -- Primitive operation slot
3665 -- P : Address; -- Wrapped parameters
3666 -- D : Duration; -- Delay
3667 -- M : Integer; -- Delay Mode
3668 -- C : out Prim_Op_Kind; -- Call kind
3669 -- F : out Boolean; -- Status flag
3671 Append_List_To
(Params
, New_List
(
3673 Make_Parameter_Specification
(Loc
,
3674 Defining_Identifier
=> Make_Defining_Identifier
(Loc
, Name_uT
),
3675 Parameter_Type
=> New_Occurrence_Of
(Typ
, Loc
),
3677 Out_Present
=> True),
3679 Make_Parameter_Specification
(Loc
,
3680 Defining_Identifier
=> Make_Defining_Identifier
(Loc
, Name_uS
),
3681 Parameter_Type
=> New_Occurrence_Of
(Standard_Integer
, Loc
)),
3683 Make_Parameter_Specification
(Loc
,
3684 Defining_Identifier
=> Make_Defining_Identifier
(Loc
, Name_uP
),
3685 Parameter_Type
=> New_Occurrence_Of
(RTE
(RE_Address
), Loc
)),
3687 Make_Parameter_Specification
(Loc
,
3688 Defining_Identifier
=> Make_Defining_Identifier
(Loc
, Name_uD
),
3689 Parameter_Type
=> New_Occurrence_Of
(Standard_Duration
, Loc
)),
3691 Make_Parameter_Specification
(Loc
,
3692 Defining_Identifier
=> Make_Defining_Identifier
(Loc
, Name_uM
),
3693 Parameter_Type
=> New_Occurrence_Of
(Standard_Integer
, Loc
)),
3695 Make_Parameter_Specification
(Loc
,
3696 Defining_Identifier
=> Make_Defining_Identifier
(Loc
, Name_uC
),
3698 New_Occurrence_Of
(RTE
(RE_Prim_Op_Kind
), Loc
),
3699 Out_Present
=> True)));
3702 Make_Parameter_Specification
(Loc
,
3703 Defining_Identifier
=> Make_Defining_Identifier
(Loc
, Name_uF
),
3704 Parameter_Type
=> New_Occurrence_Of
(Standard_Boolean
, Loc
),
3705 Out_Present
=> True));
3708 Make_Procedure_Specification
(Loc
,
3709 Defining_Unit_Name
=> Def_Id
,
3710 Parameter_Specifications
=> Params
);
3711 end Make_Disp_Timed_Select_Spec
;
3717 -- The frontend supports two models for expanding dispatch tables
3718 -- associated with library-level defined tagged types: statically and
3719 -- non-statically allocated dispatch tables. In the former case the object
3720 -- containing the dispatch table is constant and it is initialized by means
3721 -- of a positional aggregate. In the latter case, the object containing
3722 -- the dispatch table is a variable which is initialized by means of
3725 -- In case of locally defined tagged types, the object containing the
3726 -- object containing the dispatch table is always a variable (instead of a
3727 -- constant). This is currently required to give support to late overriding
3728 -- of primitives. For example:
3730 -- procedure Example is
3732 -- type T1 is tagged null record;
3733 -- procedure Prim (O : T1);
3736 -- type T2 is new Pkg.T1 with null record;
3737 -- procedure Prim (X : T2) is -- late overriding
3743 -- WARNING: This routine manages Ghost regions. Return statements must be
3744 -- replaced by gotos which jump to the end of the routine and restore the
3747 function Make_DT
(Typ
: Entity_Id
; N
: Node_Id
:= Empty
) return List_Id
is
3748 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
3750 Max_Predef_Prims
: constant Int
:=
3754 (Parent
(RTE
(RE_Max_Predef_Prims
)))));
3756 DT_Decl
: constant Elist_Id
:= New_Elmt_List
;
3757 DT_Aggr
: constant Elist_Id
:= New_Elmt_List
;
3758 -- Entities marked with attribute Is_Dispatch_Table_Entity
3760 procedure Check_Premature_Freezing
3762 Tagged_Type
: Entity_Id
;
3764 -- Verify that all untagged types in the profile of a subprogram are
3765 -- frozen at the point the subprogram is frozen. This enforces the rule
3766 -- on RM 13.14 (14) as modified by AI05-019. At the point a subprogram
3767 -- is frozen, enough must be known about it to build the activation
3768 -- record for it, which requires at least that the size of all
3769 -- parameters be known. Controlling arguments are by-reference,
3770 -- and therefore the rule only applies to untagged types. Typical
3771 -- violation of the rule involves an object declaration that freezes a
3772 -- tagged type, when one of its primitive operations has a type in its
3773 -- profile whose full view has not been analyzed yet. More complex cases
3774 -- involve composite types that have one private unfrozen subcomponent.
3776 procedure Export_DT
(Typ
: Entity_Id
; DT
: Entity_Id
; Index
: Nat
:= 0);
3777 -- Export the dispatch table DT of tagged type Typ. Required to generate
3778 -- forward references and statically allocate the table. For primary
3779 -- dispatch tables Index is 0; for secondary dispatch tables the value
3780 -- of index must match the Suffix_Index value assigned to the table by
3781 -- Make_Tags when generating its unique external name, and it is used to
3782 -- retrieve from the Dispatch_Table_Wrappers list associated with Typ
3783 -- the external name generated by Import_DT.
3785 procedure Make_Secondary_DT
3789 Num_Iface_Prims
: Nat
;
3790 Iface_DT_Ptr
: Entity_Id
;
3791 Predef_Prims_Ptr
: Entity_Id
;
3792 Build_Thunks
: Boolean;
3794 -- Ada 2005 (AI-251): Expand the declarations for a Secondary Dispatch
3795 -- Table of Typ associated with Iface. Each abstract interface of Typ
3796 -- has two secondary dispatch tables: one containing pointers to thunks
3797 -- and another containing pointers to the primitives covering the
3798 -- interface primitives. The former secondary table is generated when
3799 -- Build_Thunks is True, and provides common support for dispatching
3800 -- calls through interface types; the latter secondary table is
3801 -- generated when Build_Thunks is False, and provides support for
3802 -- Generic Dispatching Constructors that dispatch calls through
3803 -- interface types. When constructing this latter table the value of
3804 -- Suffix_Index is -1 to indicate that there is no need to export such
3805 -- table when building statically allocated dispatch tables; a positive
3806 -- value of Suffix_Index must match the Suffix_Index value assigned to
3807 -- this secondary dispatch table by Make_Tags when its unique external
3808 -- name was generated.
3810 ------------------------------
3811 -- Check_Premature_Freezing --
3812 ------------------------------
3814 procedure Check_Premature_Freezing
3816 Tagged_Type
: Entity_Id
;
3821 function Is_Actual_For_Formal_Incomplete_Type
3822 (T
: Entity_Id
) return Boolean;
3823 -- In Ada 2012, if a nested generic has an incomplete formal type,
3824 -- the actual may be (and usually is) a private type whose completion
3825 -- appears later. It is safe to build the dispatch table in this
3826 -- case, gigi will have full views available.
3828 ------------------------------------------
3829 -- Is_Actual_For_Formal_Incomplete_Type --
3830 ------------------------------------------
3832 function Is_Actual_For_Formal_Incomplete_Type
3833 (T
: Entity_Id
) return Boolean
3835 Gen_Par
: Entity_Id
;
3839 if not Is_Generic_Instance
(Current_Scope
)
3840 or else not Used_As_Generic_Actual
(T
)
3844 Gen_Par
:= Generic_Parent
(Parent
(Current_Scope
));
3849 (Generic_Formal_Declarations
3850 (Unit_Declaration_Node
(Gen_Par
)));
3851 while Present
(F
) loop
3852 if Ekind
(Defining_Identifier
(F
)) = E_Incomplete_Type
then
3860 end Is_Actual_For_Formal_Incomplete_Type
;
3862 -- Start of processing for Check_Premature_Freezing
3865 -- Note that if the type is a (subtype of) a generic actual, the
3866 -- actual will have been frozen by the instantiation.
3869 and then Is_Private_Type
(Typ
)
3870 and then No
(Full_View
(Typ
))
3871 and then not Is_Generic_Type
(Typ
)
3872 and then not Is_Tagged_Type
(Typ
)
3873 and then not Is_Frozen
(Typ
)
3874 and then not Is_Generic_Actual_Type
(Typ
)
3876 Error_Msg_Sloc
:= Sloc
(Subp
);
3878 ("declaration must appear after completion of type &", N
, Typ
);
3880 ("\which is an untagged type in the profile of "
3881 & "primitive operation & declared#", N
, Subp
);
3884 Comp
:= Private_Component
(Typ
);
3886 if not Is_Tagged_Type
(Typ
)
3887 and then Present
(Comp
)
3888 and then not Is_Frozen
(Comp
)
3889 and then not Is_Actual_For_Formal_Incomplete_Type
(Comp
)
3891 Error_Msg_Sloc
:= Sloc
(Subp
);
3892 Error_Msg_Node_2
:= Subp
;
3893 Error_Msg_Name_1
:= Chars
(Tagged_Type
);
3895 ("declaration must appear after completion of type &",
3898 ("\which is a component of untagged type& in the profile "
3899 & "of primitive & of type % that is frozen by the "
3900 & "declaration ", N
, Typ
);
3903 end Check_Premature_Freezing
;
3909 procedure Export_DT
(Typ
: Entity_Id
; DT
: Entity_Id
; Index
: Nat
:= 0)
3915 Set_Is_Statically_Allocated
(DT
);
3916 Set_Is_True_Constant
(DT
);
3917 Set_Is_Exported
(DT
);
3920 Elmt
:= First_Elmt
(Dispatch_Table_Wrappers
(Typ
));
3921 while Count
/= Index
loop
3926 pragma Assert
(Related_Type
(Node
(Elmt
)) = Typ
);
3928 Get_External_Name
(Node
(Elmt
));
3929 Set_Interface_Name
(DT
,
3930 Make_String_Literal
(Loc
,
3931 Strval
=> String_From_Name_Buffer
));
3933 -- Ensure proper Sprint output of this implicit importation
3935 Set_Is_Internal
(DT
);
3939 -----------------------
3940 -- Make_Secondary_DT --
3941 -----------------------
3943 procedure Make_Secondary_DT
3947 Num_Iface_Prims
: Nat
;
3948 Iface_DT_Ptr
: Entity_Id
;
3949 Predef_Prims_Ptr
: Entity_Id
;
3950 Build_Thunks
: Boolean;
3953 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
3954 Exporting_Table
: constant Boolean :=
3955 Building_Static_DT
(Typ
)
3956 and then Suffix_Index
> 0;
3957 Iface_DT
: constant Entity_Id
:= Make_Temporary
(Loc
, 'T');
3958 Predef_Prims
: constant Entity_Id
:= Make_Temporary
(Loc
, 'R');
3959 DT_Constr_List
: List_Id
;
3960 DT_Aggr_List
: List_Id
;
3961 Empty_DT
: Boolean := False;
3962 Nb_Predef_Prims
: Nat
:= 0;
3966 OSD_Aggr_List
: List_Id
;
3969 Prim_Elmt
: Elmt_Id
;
3970 Prim_Ops_Aggr_List
: List_Id
;
3973 -- Handle cases in which we do not generate statically allocated
3976 if not Building_Static_DT
(Typ
) then
3977 Set_Ekind
(Predef_Prims
, E_Variable
);
3978 Set_Ekind
(Iface_DT
, E_Variable
);
3980 -- Statically allocated dispatch tables and related entities are
3984 Set_Ekind
(Predef_Prims
, E_Constant
);
3985 Set_Is_Statically_Allocated
(Predef_Prims
);
3986 Set_Is_True_Constant
(Predef_Prims
);
3988 Set_Ekind
(Iface_DT
, E_Constant
);
3989 Set_Is_Statically_Allocated
(Iface_DT
);
3990 Set_Is_True_Constant
(Iface_DT
);
3993 -- Calculate the number of slots of the dispatch table. If the number
3994 -- of primitives of Typ is 0 we reserve a dummy single entry for its
3995 -- DT because at run time the pointer to this dummy entry will be
3998 if Num_Iface_Prims
= 0 then
4002 Nb_Prim
:= Num_Iface_Prims
;
4007 -- Predef_Prims : Address_Array (1 .. Default_Prim_Ops_Count) :=
4008 -- (predef-prim-op-thunk-1'address,
4009 -- predef-prim-op-thunk-2'address,
4011 -- predef-prim-op-thunk-n'address);
4012 -- for Predef_Prims'Alignment use Address'Alignment
4014 -- Stage 1: Calculate the number of predefined primitives
4016 if not Building_Static_DT
(Typ
) then
4017 Nb_Predef_Prims
:= Max_Predef_Prims
;
4019 Prim_Elmt
:= First_Elmt
(Primitive_Operations
(Typ
));
4020 while Present
(Prim_Elmt
) loop
4021 Prim
:= Node
(Prim_Elmt
);
4023 if Is_Predefined_Dispatching_Operation
(Prim
)
4024 and then not Is_Abstract_Subprogram
(Prim
)
4026 Pos
:= UI_To_Int
(DT_Position
(Prim
));
4028 if Pos
> Nb_Predef_Prims
then
4029 Nb_Predef_Prims
:= Pos
;
4033 Next_Elmt
(Prim_Elmt
);
4037 if Generate_SCIL
then
4038 Nb_Predef_Prims
:= 0;
4041 -- Stage 2: Create the thunks associated with the predefined
4042 -- primitives and save their entity to fill the aggregate.
4045 Prim_Table
: array (Nat
range 1 .. Nb_Predef_Prims
) of Entity_Id
;
4047 Thunk_Id
: Entity_Id
;
4048 Thunk_Code
: Node_Id
;
4051 Prim_Ops_Aggr_List
:= New_List
;
4052 Prim_Table
:= (others => Empty
);
4054 if Building_Static_DT
(Typ
) then
4055 Prim_Elmt
:= First_Elmt
(Primitive_Operations
(Typ
));
4056 while Present
(Prim_Elmt
) loop
4057 Prim
:= Node
(Prim_Elmt
);
4059 if Is_Predefined_Dispatching_Operation
(Prim
)
4060 and then not Is_Abstract_Subprogram
(Prim
)
4061 and then not Is_Eliminated
(Prim
)
4062 and then not Generate_SCIL
4063 and then not Present
(Prim_Table
4064 (UI_To_Int
(DT_Position
(Prim
))))
4066 if not Build_Thunks
then
4067 Prim_Table
(UI_To_Int
(DT_Position
(Prim
))) :=
4071 Expand_Interface_Thunk
4072 (Ultimate_Alias
(Prim
), Thunk_Id
, Thunk_Code
);
4074 if Present
(Thunk_Id
) then
4075 Append_To
(Result
, Thunk_Code
);
4076 Prim_Table
(UI_To_Int
(DT_Position
(Prim
))) :=
4082 Next_Elmt
(Prim_Elmt
);
4086 for J
in Prim_Table
'Range loop
4087 if Present
(Prim_Table
(J
)) then
4089 Unchecked_Convert_To
(RTE
(RE_Prim_Ptr
),
4090 Make_Attribute_Reference
(Loc
,
4091 Prefix
=> New_Occurrence_Of
(Prim_Table
(J
), Loc
),
4092 Attribute_Name
=> Name_Unrestricted_Access
));
4094 New_Node
:= Make_Null
(Loc
);
4097 Append_To
(Prim_Ops_Aggr_List
, New_Node
);
4101 Make_Aggregate
(Loc
, Expressions
=> Prim_Ops_Aggr_List
);
4103 -- Remember aggregates initializing dispatch tables
4105 Append_Elmt
(New_Node
, DT_Aggr
);
4108 Make_Subtype_Declaration
(Loc
,
4109 Defining_Identifier
=> Make_Temporary
(Loc
, 'S'),
4110 Subtype_Indication
=>
4111 New_Occurrence_Of
(RTE
(RE_Address_Array
), Loc
));
4113 Append_To
(Result
, Decl
);
4116 Make_Object_Declaration
(Loc
,
4117 Defining_Identifier
=> Predef_Prims
,
4118 Constant_Present
=> Building_Static_DT
(Typ
),
4119 Aliased_Present
=> True,
4120 Object_Definition
=> New_Occurrence_Of
4121 (Defining_Identifier
(Decl
), Loc
),
4122 Expression
=> New_Node
));
4125 Make_Attribute_Definition_Clause
(Loc
,
4126 Name
=> New_Occurrence_Of
(Predef_Prims
, Loc
),
4127 Chars
=> Name_Alignment
,
4129 Make_Attribute_Reference
(Loc
,
4131 New_Occurrence_Of
(RTE
(RE_Integer_Address
), Loc
),
4132 Attribute_Name
=> Name_Alignment
)));
4137 -- OSD : Ada.Tags.Object_Specific_Data (Nb_Prims) :=
4138 -- (OSD_Table => (1 => <value>,
4142 -- Iface_DT : Dispatch_Table (Nb_Prims) :=
4143 -- ([ Signature => <sig-value> ],
4144 -- Tag_Kind => <tag_kind-value>,
4145 -- Predef_Prims => Predef_Prims'Address,
4146 -- Offset_To_Top => 0,
4147 -- OSD => OSD'Address,
4148 -- Prims_Ptr => (prim-op-1'address,
4149 -- prim-op-2'address,
4151 -- prim-op-n'address));
4152 -- for Iface_DT'Alignment use Address'Alignment;
4154 -- Stage 3: Initialize the discriminant and the record components
4156 DT_Constr_List
:= New_List
;
4157 DT_Aggr_List
:= New_List
;
4161 Append_To
(DT_Constr_List
, Make_Integer_Literal
(Loc
, Nb_Prim
));
4162 Append_To
(DT_Aggr_List
, Make_Integer_Literal
(Loc
, Nb_Prim
));
4166 if RTE_Record_Component_Available
(RE_Signature
) then
4167 Append_To
(DT_Aggr_List
,
4168 New_Occurrence_Of
(RTE
(RE_Secondary_DT
), Loc
));
4173 if RTE_Record_Component_Available
(RE_Tag_Kind
) then
4174 Append_To
(DT_Aggr_List
, Tagged_Kind
(Typ
));
4179 Append_To
(DT_Aggr_List
,
4180 Make_Attribute_Reference
(Loc
,
4181 Prefix
=> New_Occurrence_Of
(Predef_Prims
, Loc
),
4182 Attribute_Name
=> Name_Address
));
4184 -- Note: The correct value of Offset_To_Top will be set by the init
4187 Append_To
(DT_Aggr_List
, Make_Integer_Literal
(Loc
, 0));
4189 -- Generate the Object Specific Data table required to dispatch calls
4190 -- through synchronized interfaces.
4193 or else Is_Abstract_Type
(Typ
)
4194 or else Is_Controlled
(Typ
)
4195 or else Restriction_Active
(No_Dispatching_Calls
)
4196 or else not Is_Limited_Type
(Typ
)
4197 or else not Has_Interfaces
(Typ
)
4198 or else not Build_Thunks
4199 or else not RTE_Record_Component_Available
(RE_OSD_Table
)
4201 -- No OSD table required
4203 Append_To
(DT_Aggr_List
,
4204 New_Occurrence_Of
(RTE
(RE_Null_Address
), Loc
));
4207 OSD_Aggr_List
:= New_List
;
4210 Prim_Table
: array (Nat
range 1 .. Nb_Prim
) of Entity_Id
;
4212 Prim_Alias
: Entity_Id
;
4213 Prim_Elmt
: Elmt_Id
;
4219 Prim_Table
:= (others => Empty
);
4220 Prim_Alias
:= Empty
;
4222 Prim_Elmt
:= First_Elmt
(Primitive_Operations
(Typ
));
4223 while Present
(Prim_Elmt
) loop
4224 Prim
:= Node
(Prim_Elmt
);
4226 if Present
(Interface_Alias
(Prim
))
4227 and then Find_Dispatching_Type
4228 (Interface_Alias
(Prim
)) = Iface
4230 Prim_Alias
:= Interface_Alias
(Prim
);
4231 E
:= Ultimate_Alias
(Prim
);
4232 Pos
:= UI_To_Int
(DT_Position
(Prim_Alias
));
4234 if Present
(Prim_Table
(Pos
)) then
4235 pragma Assert
(Prim_Table
(Pos
) = E
);
4239 Prim_Table
(Pos
) := E
;
4241 Append_To
(OSD_Aggr_List
,
4242 Make_Component_Association
(Loc
,
4243 Choices
=> New_List
(
4244 Make_Integer_Literal
(Loc
,
4245 DT_Position
(Prim_Alias
))),
4247 Make_Integer_Literal
(Loc
,
4248 DT_Position
(Alias
(Prim
)))));
4254 Next_Elmt
(Prim_Elmt
);
4256 pragma Assert
(Count
= Nb_Prim
);
4259 OSD
:= Make_Temporary
(Loc
, 'I');
4262 Make_Object_Declaration
(Loc
,
4263 Defining_Identifier
=> OSD
,
4264 Object_Definition
=>
4265 Make_Subtype_Indication
(Loc
,
4267 New_Occurrence_Of
(RTE
(RE_Object_Specific_Data
), Loc
),
4269 Make_Index_Or_Discriminant_Constraint
(Loc
,
4270 Constraints
=> New_List
(
4271 Make_Integer_Literal
(Loc
, Nb_Prim
)))),
4274 Make_Aggregate
(Loc
,
4275 Component_Associations
=> New_List
(
4276 Make_Component_Association
(Loc
,
4277 Choices
=> New_List
(
4279 (RTE_Record_Component
(RE_OSD_Num_Prims
), Loc
)),
4281 Make_Integer_Literal
(Loc
, Nb_Prim
)),
4283 Make_Component_Association
(Loc
,
4284 Choices
=> New_List
(
4286 (RTE_Record_Component
(RE_OSD_Table
), Loc
)),
4287 Expression
=> Make_Aggregate
(Loc
,
4288 Component_Associations
=> OSD_Aggr_List
))))));
4291 Make_Attribute_Definition_Clause
(Loc
,
4292 Name
=> New_Occurrence_Of
(OSD
, Loc
),
4293 Chars
=> Name_Alignment
,
4295 Make_Attribute_Reference
(Loc
,
4297 New_Occurrence_Of
(RTE
(RE_Integer_Address
), Loc
),
4298 Attribute_Name
=> Name_Alignment
)));
4300 -- In secondary dispatch tables the Typeinfo component contains
4301 -- the address of the Object Specific Data (see a-tags.ads)
4303 Append_To
(DT_Aggr_List
,
4304 Make_Attribute_Reference
(Loc
,
4305 Prefix
=> New_Occurrence_Of
(OSD
, Loc
),
4306 Attribute_Name
=> Name_Address
));
4309 -- Initialize the table of primitive operations
4311 Prim_Ops_Aggr_List
:= New_List
;
4314 Append_To
(Prim_Ops_Aggr_List
, Make_Null
(Loc
));
4316 elsif Is_Abstract_Type
(Typ
)
4317 or else not Building_Static_DT
(Typ
)
4319 for J
in 1 .. Nb_Prim
loop
4320 Append_To
(Prim_Ops_Aggr_List
, Make_Null
(Loc
));
4325 CPP_Nb_Prims
: constant Nat
:= CPP_Num_Prims
(Typ
);
4328 Prim_Table
: array (Nat
range 1 .. Nb_Prim
) of Entity_Id
;
4329 Thunk_Code
: Node_Id
;
4330 Thunk_Id
: Entity_Id
;
4333 Prim_Table
:= (others => Empty
);
4335 Prim_Elmt
:= First_Elmt
(Primitive_Operations
(Typ
));
4336 while Present
(Prim_Elmt
) loop
4337 Prim
:= Node
(Prim_Elmt
);
4338 E
:= Ultimate_Alias
(Prim
);
4339 Prim_Pos
:= UI_To_Int
(DT_Position
(E
));
4341 -- Do not reference predefined primitives because they are
4342 -- located in a separate dispatch table; skip abstract and
4343 -- eliminated primitives; skip primitives located in the C++
4344 -- part of the dispatch table because their slot is set by
4347 if not Is_Predefined_Dispatching_Operation
(Prim
)
4348 and then Present
(Interface_Alias
(Prim
))
4349 and then not Is_Abstract_Subprogram
(Alias
(Prim
))
4350 and then not Is_Eliminated
(Alias
(Prim
))
4351 and then (not Is_CPP_Class
(Root_Type
(Typ
))
4352 or else Prim_Pos
> CPP_Nb_Prims
)
4353 and then Find_Dispatching_Type
4354 (Interface_Alias
(Prim
)) = Iface
4356 -- Generate the code of the thunk only if the abstract
4357 -- interface type is not an immediate ancestor of
4358 -- Tagged_Type. Otherwise the DT associated with the
4359 -- interface is the primary DT.
4361 and then not Is_Ancestor
(Iface
, Typ
,
4362 Use_Full_View
=> True)
4364 if not Build_Thunks
then
4366 UI_To_Int
(DT_Position
(Interface_Alias
(Prim
)));
4367 Prim_Table
(Prim_Pos
) := Alias
(Prim
);
4370 Expand_Interface_Thunk
(Prim
, Thunk_Id
, Thunk_Code
);
4372 if Present
(Thunk_Id
) then
4374 UI_To_Int
(DT_Position
(Interface_Alias
(Prim
)));
4376 Prim_Table
(Prim_Pos
) := Thunk_Id
;
4377 Append_To
(Result
, Thunk_Code
);
4382 Next_Elmt
(Prim_Elmt
);
4385 for J
in Prim_Table
'Range loop
4386 if Present
(Prim_Table
(J
)) then
4388 Unchecked_Convert_To
(RTE
(RE_Prim_Ptr
),
4389 Make_Attribute_Reference
(Loc
,
4390 Prefix
=> New_Occurrence_Of
(Prim_Table
(J
), Loc
),
4391 Attribute_Name
=> Name_Unrestricted_Access
));
4394 New_Node
:= Make_Null
(Loc
);
4397 Append_To
(Prim_Ops_Aggr_List
, New_Node
);
4403 Make_Aggregate
(Loc
,
4404 Expressions
=> Prim_Ops_Aggr_List
);
4406 Append_To
(DT_Aggr_List
, New_Node
);
4408 -- Remember aggregates initializing dispatch tables
4410 Append_Elmt
(New_Node
, DT_Aggr
);
4412 -- Note: Secondary dispatch tables cannot be declared constant
4413 -- because the component Offset_To_Top is currently initialized
4414 -- by the IP routine.
4417 Make_Object_Declaration
(Loc
,
4418 Defining_Identifier
=> Iface_DT
,
4419 Aliased_Present
=> True,
4420 Constant_Present
=> False,
4422 Object_Definition
=>
4423 Make_Subtype_Indication
(Loc
,
4424 Subtype_Mark
=> New_Occurrence_Of
4425 (RTE
(RE_Dispatch_Table_Wrapper
), Loc
),
4426 Constraint
=> Make_Index_Or_Discriminant_Constraint
(Loc
,
4427 Constraints
=> DT_Constr_List
)),
4430 Make_Aggregate
(Loc
,
4431 Expressions
=> DT_Aggr_List
)));
4434 Make_Attribute_Definition_Clause
(Loc
,
4435 Name
=> New_Occurrence_Of
(Iface_DT
, Loc
),
4436 Chars
=> Name_Alignment
,
4439 Make_Attribute_Reference
(Loc
,
4441 New_Occurrence_Of
(RTE
(RE_Integer_Address
), Loc
),
4442 Attribute_Name
=> Name_Alignment
)));
4444 if Exporting_Table
then
4445 Export_DT
(Typ
, Iface_DT
, Suffix_Index
);
4447 -- Generate code to create the pointer to the dispatch table
4449 -- Iface_DT_Ptr : Tag := Tag!(DT.Prims_Ptr'Address);
4451 -- Note: This declaration is not added here if the table is exported
4452 -- because in such case Make_Tags has already added this declaration.
4456 Make_Object_Declaration
(Loc
,
4457 Defining_Identifier
=> Iface_DT_Ptr
,
4458 Constant_Present
=> True,
4460 Object_Definition
=>
4461 New_Occurrence_Of
(RTE
(RE_Interface_Tag
), Loc
),
4464 Unchecked_Convert_To
(RTE
(RE_Interface_Tag
),
4465 Make_Attribute_Reference
(Loc
,
4467 Make_Selected_Component
(Loc
,
4468 Prefix
=> New_Occurrence_Of
(Iface_DT
, Loc
),
4471 (RTE_Record_Component
(RE_Prims_Ptr
), Loc
)),
4472 Attribute_Name
=> Name_Address
))));
4476 Make_Object_Declaration
(Loc
,
4477 Defining_Identifier
=> Predef_Prims_Ptr
,
4478 Constant_Present
=> True,
4480 Object_Definition
=>
4481 New_Occurrence_Of
(RTE
(RE_Address
), Loc
),
4484 Make_Attribute_Reference
(Loc
,
4486 Make_Selected_Component
(Loc
,
4487 Prefix
=> New_Occurrence_Of
(Iface_DT
, Loc
),
4490 (RTE_Record_Component
(RE_Predef_Prims
), Loc
)),
4491 Attribute_Name
=> Name_Address
)));
4493 -- Remember entities containing dispatch tables
4495 Append_Elmt
(Predef_Prims
, DT_Decl
);
4496 Append_Elmt
(Iface_DT
, DT_Decl
);
4497 end Make_Secondary_DT
;
4501 Elab_Code
: constant List_Id
:= New_List
;
4502 Result
: constant List_Id
:= New_List
;
4503 Tname
: constant Name_Id
:= Chars
(Typ
);
4505 -- The following name entries are used by Make_DT to generate a number
4506 -- of entities related to a tagged type. These entities may be generated
4507 -- in a scope other than that of the tagged type declaration, and if
4508 -- the entities for two tagged types with the same name happen to be
4509 -- generated in the same scope, we have to take care to use different
4510 -- names. This is achieved by means of a unique serial number appended
4511 -- to each generated entity name.
4513 Name_DT
: constant Name_Id
:=
4514 New_External_Name
(Tname
, 'T', Suffix_Index
=> -1);
4515 Name_Exname
: constant Name_Id
:=
4516 New_External_Name
(Tname
, 'E', Suffix_Index
=> -1);
4517 Name_HT_Link
: constant Name_Id
:=
4518 New_External_Name
(Tname
, 'H', Suffix_Index
=> -1);
4519 Name_Predef_Prims
: constant Name_Id
:=
4520 New_External_Name
(Tname
, 'R', Suffix_Index
=> -1);
4521 Name_SSD
: constant Name_Id
:=
4522 New_External_Name
(Tname
, 'S', Suffix_Index
=> -1);
4523 Name_TSD
: constant Name_Id
:=
4524 New_External_Name
(Tname
, 'B', Suffix_Index
=> -1);
4526 Saved_GM
: constant Ghost_Mode_Type
:= Ghost_Mode
;
4527 -- Save the Ghost mode to restore on exit
4530 AI_Tag_Elmt
: Elmt_Id
;
4531 AI_Tag_Comp
: Elmt_Id
;
4533 DT_Aggr_List
: List_Id
;
4534 DT_Constr_List
: List_Id
;
4537 HT_Link
: Entity_Id
;
4540 Iface_Table_Node
: Node_Id
;
4541 Name_ITable
: Name_Id
;
4542 Nb_Predef_Prims
: Nat
:= 0;
4545 Num_Ifaces
: Nat
:= 0;
4546 Parent_Typ
: Entity_Id
;
4547 Predef_Prims
: Entity_Id
;
4549 Prim_Elmt
: Elmt_Id
;
4550 Prim_Ops_Aggr_List
: List_Id
;
4553 Typ_Comps
: Elist_Id
;
4554 Typ_Ifaces
: Elist_Id
;
4556 TSD_Aggr_List
: List_Id
;
4557 TSD_Tags_List
: List_Id
;
4559 -- Start of processing for Make_DT
4562 pragma Assert
(Is_Frozen
(Typ
));
4564 -- The tagged type being processed may be subject to pragma Ghost. Set
4565 -- the mode now to ensure that any nodes generated during dispatch table
4566 -- creation are properly marked as Ghost.
4568 Set_Ghost_Mode
(Typ
);
4570 -- Handle cases in which there is no need to build the dispatch table
4572 if Has_Dispatch_Table
(Typ
)
4573 or else No
(Access_Disp_Table
(Typ
))
4574 or else Is_CPP_Class
(Typ
)
4578 elsif No_Run_Time_Mode
then
4579 Error_Msg_CRT
("tagged types", Typ
);
4582 elsif not RTE_Available
(RE_Tag
) then
4584 Make_Object_Declaration
(Loc
,
4585 Defining_Identifier
=>
4586 Node
(First_Elmt
(Access_Disp_Table
(Typ
))),
4587 Object_Definition
=> New_Occurrence_Of
(RTE
(RE_Tag
), Loc
),
4588 Constant_Present
=> True,
4590 Unchecked_Convert_To
(RTE
(RE_Tag
),
4591 New_Occurrence_Of
(RTE
(RE_Null_Address
), Loc
))));
4593 Analyze_List
(Result
, Suppress
=> All_Checks
);
4594 Error_Msg_CRT
("tagged types", Typ
);
4598 -- Ensure that the value of Max_Predef_Prims defined in a-tags is
4599 -- correct. Valid values are 9 under configurable runtime or 15
4600 -- with full runtime.
4602 if RTE_Available
(RE_Interface_Data
) then
4603 if Max_Predef_Prims
/= 15 then
4604 Error_Msg_N
("run-time library configuration error", Typ
);
4608 if Max_Predef_Prims
/= 9 then
4609 Error_Msg_N
("run-time library configuration error", Typ
);
4610 Error_Msg_CRT
("tagged types", Typ
);
4615 DT
:= Make_Defining_Identifier
(Loc
, Name_DT
);
4616 Exname
:= Make_Defining_Identifier
(Loc
, Name_Exname
);
4617 HT_Link
:= Make_Defining_Identifier
(Loc
, Name_HT_Link
);
4618 Predef_Prims
:= Make_Defining_Identifier
(Loc
, Name_Predef_Prims
);
4619 SSD
:= Make_Defining_Identifier
(Loc
, Name_SSD
);
4620 TSD
:= Make_Defining_Identifier
(Loc
, Name_TSD
);
4622 -- Initialize Parent_Typ handling private types
4624 Parent_Typ
:= Etype
(Typ
);
4626 if Present
(Full_View
(Parent_Typ
)) then
4627 Parent_Typ
:= Full_View
(Parent_Typ
);
4630 -- Ensure that all the primitives are frozen. This is only required when
4631 -- building static dispatch tables --- the primitives must be frozen to
4632 -- be referenced (otherwise we have problems with the backend). It is
4633 -- not a requirement with nonstatic dispatch tables because in this case
4634 -- we generate now an empty dispatch table; the extra code required to
4635 -- register the primitives in the slots will be generated later --- when
4636 -- each primitive is frozen (see Freeze_Subprogram).
4638 if Building_Static_DT
(Typ
) then
4640 Saved_FLLTT
: constant Boolean :=
4641 Freezing_Library_Level_Tagged_Type
;
4646 Prim_Elmt
: Elmt_Id
;
4649 Freezing_Library_Level_Tagged_Type
:= True;
4651 Prim_Elmt
:= First_Elmt
(Primitive_Operations
(Typ
));
4652 while Present
(Prim_Elmt
) loop
4653 Prim
:= Node
(Prim_Elmt
);
4654 Frnodes
:= Freeze_Entity
(Prim
, Typ
);
4656 -- We disable this check for abstract subprograms, given that
4657 -- they cannot be called directly and thus the state of their
4658 -- untagged formals is of no concern. The RM is unclear in any
4659 -- case concerning the need for this check, and this topic may
4660 -- go back to the ARG.
4662 if not Is_Abstract_Subprogram
(Prim
) then
4663 Formal
:= First_Formal
(Prim
);
4664 while Present
(Formal
) loop
4665 Check_Premature_Freezing
(Prim
, Typ
, Etype
(Formal
));
4666 Next_Formal
(Formal
);
4669 Check_Premature_Freezing
(Prim
, Typ
, Etype
(Prim
));
4672 if Present
(Frnodes
) then
4673 Append_List_To
(Result
, Frnodes
);
4676 Next_Elmt
(Prim_Elmt
);
4679 Freezing_Library_Level_Tagged_Type
:= Saved_FLLTT
;
4683 -- Ada 2005 (AI-251): Build the secondary dispatch tables
4685 if Has_Interfaces
(Typ
) then
4686 Collect_Interface_Components
(Typ
, Typ_Comps
);
4688 -- Each secondary dispatch table is assigned an unique positive
4689 -- suffix index; such value also corresponds with the location of
4690 -- its entity in the Dispatch_Table_Wrappers list (see Make_Tags).
4692 -- Note: This value must be kept sync with the Suffix_Index values
4693 -- generated by Make_Tags
4697 Next_Elmt
(Next_Elmt
(First_Elmt
(Access_Disp_Table
(Typ
))));
4699 AI_Tag_Comp
:= First_Elmt
(Typ_Comps
);
4700 while Present
(AI_Tag_Comp
) loop
4701 pragma Assert
(Has_Suffix
(Node
(AI_Tag_Elmt
), 'P'));
4703 -- Build the secondary table containing pointers to thunks
4708 (Related_Type
(Node
(AI_Tag_Comp
))),
4709 Suffix_Index
=> Suffix_Index
,
4710 Num_Iface_Prims
=> UI_To_Int
4711 (DT_Entry_Count
(Node
(AI_Tag_Comp
))),
4712 Iface_DT_Ptr
=> Node
(AI_Tag_Elmt
),
4713 Predef_Prims_Ptr
=> Node
(Next_Elmt
(AI_Tag_Elmt
)),
4714 Build_Thunks
=> True,
4717 -- Skip secondary dispatch table referencing thunks to predefined
4720 Next_Elmt
(AI_Tag_Elmt
);
4721 pragma Assert
(Has_Suffix
(Node
(AI_Tag_Elmt
), 'Y'));
4723 -- Secondary dispatch table referencing user-defined primitives
4724 -- covered by this interface.
4726 Next_Elmt
(AI_Tag_Elmt
);
4727 pragma Assert
(Has_Suffix
(Node
(AI_Tag_Elmt
), 'D'));
4729 -- Build the secondary table containing pointers to primitives
4730 -- (used to give support to Generic Dispatching Constructors).
4735 (Related_Type
(Node
(AI_Tag_Comp
))),
4737 Num_Iface_Prims
=> UI_To_Int
4738 (DT_Entry_Count
(Node
(AI_Tag_Comp
))),
4739 Iface_DT_Ptr
=> Node
(AI_Tag_Elmt
),
4740 Predef_Prims_Ptr
=> Node
(Next_Elmt
(AI_Tag_Elmt
)),
4741 Build_Thunks
=> False,
4744 -- Skip secondary dispatch table referencing predefined primitives
4746 Next_Elmt
(AI_Tag_Elmt
);
4747 pragma Assert
(Has_Suffix
(Node
(AI_Tag_Elmt
), 'Z'));
4749 Suffix_Index
:= Suffix_Index
+ 1;
4750 Next_Elmt
(AI_Tag_Elmt
);
4751 Next_Elmt
(AI_Tag_Comp
);
4755 -- Get the _tag entity and number of primitives of its dispatch table
4757 DT_Ptr
:= Node
(First_Elmt
(Access_Disp_Table
(Typ
)));
4758 Nb_Prim
:= UI_To_Int
(DT_Entry_Count
(First_Tag_Component
(Typ
)));
4760 if Generate_SCIL
then
4764 Set_Is_Statically_Allocated
(DT
, Is_Library_Level_Tagged_Type
(Typ
));
4765 Set_Is_Statically_Allocated
(SSD
, Is_Library_Level_Tagged_Type
(Typ
));
4766 Set_Is_Statically_Allocated
(TSD
, Is_Library_Level_Tagged_Type
(Typ
));
4767 Set_Is_Statically_Allocated
(Predef_Prims
,
4768 Is_Library_Level_Tagged_Type
(Typ
));
4770 -- In case of locally defined tagged type we declare the object
4771 -- containing the dispatch table by means of a variable. Its
4772 -- initialization is done later by means of an assignment. This is
4773 -- required to generate its External_Tag.
4775 if not Building_Static_DT
(Typ
) then
4778 -- DT : No_Dispatch_Table_Wrapper;
4779 -- for DT'Alignment use Address'Alignment;
4780 -- DT_Ptr : Tag := !Tag (DT.NDT_Prims_Ptr'Address);
4782 if not Has_DT
(Typ
) then
4784 Make_Object_Declaration
(Loc
,
4785 Defining_Identifier
=> DT
,
4786 Aliased_Present
=> True,
4787 Constant_Present
=> False,
4788 Object_Definition
=>
4790 (RTE
(RE_No_Dispatch_Table_Wrapper
), Loc
)));
4793 Make_Attribute_Definition_Clause
(Loc
,
4794 Name
=> New_Occurrence_Of
(DT
, Loc
),
4795 Chars
=> Name_Alignment
,
4797 Make_Attribute_Reference
(Loc
,
4799 New_Occurrence_Of
(RTE
(RE_Integer_Address
), Loc
),
4800 Attribute_Name
=> Name_Alignment
)));
4803 Make_Object_Declaration
(Loc
,
4804 Defining_Identifier
=> DT_Ptr
,
4805 Object_Definition
=> New_Occurrence_Of
(RTE
(RE_Tag
), Loc
),
4806 Constant_Present
=> True,
4808 Unchecked_Convert_To
(RTE
(RE_Tag
),
4809 Make_Attribute_Reference
(Loc
,
4811 Make_Selected_Component
(Loc
,
4812 Prefix
=> New_Occurrence_Of
(DT
, Loc
),
4815 (RTE_Record_Component
(RE_NDT_Prims_Ptr
), Loc
)),
4816 Attribute_Name
=> Name_Address
))));
4818 Set_Is_Statically_Allocated
(DT_Ptr
,
4819 Is_Library_Level_Tagged_Type
(Typ
));
4821 -- Generate the SCIL node for the previous object declaration
4822 -- because it has a tag initialization.
4824 if Generate_SCIL
then
4826 Make_SCIL_Dispatch_Table_Tag_Init
(Sloc
(Last
(Result
)));
4827 Set_SCIL_Entity
(New_Node
, Typ
);
4828 Set_SCIL_Node
(Last
(Result
), New_Node
);
4832 -- Gnat2scil has its own implementation of dispatch tables,
4833 -- different than what is being implemented here. Generating
4834 -- further dispatch table initialization code would just
4835 -- cause gnat2scil to generate useless Scil which CodePeer
4836 -- would waste time and space analyzing, so we skip it.
4840 -- DT : Dispatch_Table_Wrapper (Nb_Prim);
4841 -- for DT'Alignment use Address'Alignment;
4842 -- DT_Ptr : Tag := !Tag (DT.Prims_Ptr'Address);
4845 -- If the tagged type has no primitives we add a dummy slot
4846 -- whose address will be the tag of this type.
4850 New_List
(Make_Integer_Literal
(Loc
, 1));
4853 New_List
(Make_Integer_Literal
(Loc
, Nb_Prim
));
4857 Make_Object_Declaration
(Loc
,
4858 Defining_Identifier
=> DT
,
4859 Aliased_Present
=> True,
4860 Constant_Present
=> False,
4861 Object_Definition
=>
4862 Make_Subtype_Indication
(Loc
,
4864 New_Occurrence_Of
(RTE
(RE_Dispatch_Table_Wrapper
), Loc
),
4866 Make_Index_Or_Discriminant_Constraint
(Loc
,
4867 Constraints
=> DT_Constr_List
))));
4870 Make_Attribute_Definition_Clause
(Loc
,
4871 Name
=> New_Occurrence_Of
(DT
, Loc
),
4872 Chars
=> Name_Alignment
,
4874 Make_Attribute_Reference
(Loc
,
4876 New_Occurrence_Of
(RTE
(RE_Integer_Address
), Loc
),
4877 Attribute_Name
=> Name_Alignment
)));
4880 Make_Object_Declaration
(Loc
,
4881 Defining_Identifier
=> DT_Ptr
,
4882 Object_Definition
=> New_Occurrence_Of
(RTE
(RE_Tag
), Loc
),
4883 Constant_Present
=> True,
4885 Unchecked_Convert_To
(RTE
(RE_Tag
),
4886 Make_Attribute_Reference
(Loc
,
4888 Make_Selected_Component
(Loc
,
4889 Prefix
=> New_Occurrence_Of
(DT
, Loc
),
4892 (RTE_Record_Component
(RE_Prims_Ptr
), Loc
)),
4893 Attribute_Name
=> Name_Address
))));
4895 Set_Is_Statically_Allocated
(DT_Ptr
,
4896 Is_Library_Level_Tagged_Type
(Typ
));
4898 -- Generate the SCIL node for the previous object declaration
4899 -- because it has a tag initialization.
4901 if Generate_SCIL
then
4903 Make_SCIL_Dispatch_Table_Tag_Init
(Sloc
(Last
(Result
)));
4904 Set_SCIL_Entity
(New_Node
, Typ
);
4905 Set_SCIL_Node
(Last
(Result
), New_Node
);
4909 -- Gnat2scil has its own implementation of dispatch tables,
4910 -- different than what is being implemented here. Generating
4911 -- further dispatch table initialization code would just
4912 -- cause gnat2scil to generate useless Scil which CodePeer
4913 -- would waste time and space analyzing, so we skip it.
4917 Make_Object_Declaration
(Loc
,
4918 Defining_Identifier
=>
4919 Node
(Next_Elmt
(First_Elmt
(Access_Disp_Table
(Typ
)))),
4920 Constant_Present
=> True,
4921 Object_Definition
=>
4922 New_Occurrence_Of
(RTE
(RE_Address
), Loc
),
4924 Make_Attribute_Reference
(Loc
,
4926 Make_Selected_Component
(Loc
,
4927 Prefix
=> New_Occurrence_Of
(DT
, Loc
),
4930 (RTE_Record_Component
(RE_Predef_Prims
), Loc
)),
4931 Attribute_Name
=> Name_Address
)));
4935 -- Generate: Exname : constant String := full_qualified_name (typ);
4936 -- The type itself may be an anonymous parent type, so use the first
4937 -- subtype to have a user-recognizable name.
4940 Make_Object_Declaration
(Loc
,
4941 Defining_Identifier
=> Exname
,
4942 Constant_Present
=> True,
4943 Object_Definition
=> New_Occurrence_Of
(Standard_String
, Loc
),
4945 Make_String_Literal
(Loc
,
4946 Strval
=> Fully_Qualified_Name_String
(First_Subtype
(Typ
)))));
4947 Set_Is_Statically_Allocated
(Exname
);
4948 Set_Is_True_Constant
(Exname
);
4950 -- Declare the object used by Ada.Tags.Register_Tag
4952 if RTE_Available
(RE_Register_Tag
) then
4954 Make_Object_Declaration
(Loc
,
4955 Defining_Identifier
=> HT_Link
,
4956 Object_Definition
=> New_Occurrence_Of
(RTE
(RE_Tag
), Loc
)));
4959 -- Generate code to create the storage for the type specific data object
4960 -- with enough space to store the tags of the ancestors plus the tags
4961 -- of all the implemented interfaces (as described in a-tags.adb).
4963 -- TSD : Type_Specific_Data (I_Depth) :=
4964 -- (Idepth => I_Depth,
4965 -- Access_Level => Type_Access_Level (Typ),
4966 -- Alignment => Typ'Alignment,
4967 -- Expanded_Name => Cstring_Ptr!(Exname'Address))
4968 -- External_Tag => Cstring_Ptr!(Exname'Address))
4969 -- HT_Link => HT_Link'Address,
4970 -- Transportable => <<boolean-value>>,
4971 -- Is_Abstract => <<boolean-value>>,
4972 -- Needs_Finalization => <<boolean-value>>,
4973 -- [ Size_Func => Size_Prim'Access, ]
4974 -- [ Interfaces_Table => <<access-value>>, ]
4975 -- [ SSD => SSD_Table'Address ]
4976 -- Tags_Table => (0 => null,
4979 -- for TSD'Alignment use Address'Alignment
4981 TSD_Aggr_List
:= New_List
;
4983 -- Idepth: Count ancestors to compute the inheritance depth. For private
4984 -- extensions, always go to the full view in order to compute the real
4985 -- inheritance depth.
4988 Current_Typ
: Entity_Id
;
4989 Parent_Typ
: Entity_Id
;
4995 Parent_Typ
:= Etype
(Current_Typ
);
4997 if Is_Private_Type
(Parent_Typ
) then
4998 Parent_Typ
:= Full_View
(Base_Type
(Parent_Typ
));
5001 exit when Parent_Typ
= Current_Typ
;
5003 I_Depth
:= I_Depth
+ 1;
5004 Current_Typ
:= Parent_Typ
;
5008 Append_To
(TSD_Aggr_List
,
5009 Make_Integer_Literal
(Loc
, I_Depth
));
5013 Append_To
(TSD_Aggr_List
,
5014 Make_Integer_Literal
(Loc
, Type_Access_Level
(Typ
)));
5018 -- For CPP types we cannot rely on the value of 'Alignment provided
5019 -- by the backend to initialize this TSD field.
5021 if Convention
(Typ
) = Convention_CPP
5022 or else Is_CPP_Class
(Root_Type
(Typ
))
5024 Append_To
(TSD_Aggr_List
,
5025 Make_Integer_Literal
(Loc
, 0));
5027 Append_To
(TSD_Aggr_List
,
5028 Make_Attribute_Reference
(Loc
,
5029 Prefix
=> New_Occurrence_Of
(Typ
, Loc
),
5030 Attribute_Name
=> Name_Alignment
));
5035 Append_To
(TSD_Aggr_List
,
5036 Unchecked_Convert_To
(RTE
(RE_Cstring_Ptr
),
5037 Make_Attribute_Reference
(Loc
,
5038 Prefix
=> New_Occurrence_Of
(Exname
, Loc
),
5039 Attribute_Name
=> Name_Address
)));
5041 -- External_Tag of a local tagged type
5043 -- <typ>A : constant String :=
5044 -- "Internal tag at 16#tag-addr#: <full-name-of-typ>";
5046 -- The reason we generate this strange name is that we do not want to
5047 -- enter local tagged types in the global hash table used to compute
5048 -- the Internal_Tag attribute for two reasons:
5050 -- 1. It is hard to avoid a tasking race condition for entering the
5051 -- entry into the hash table.
5053 -- 2. It would cause a storage leak, unless we rig up considerable
5054 -- mechanism to remove the entry from the hash table on exit.
5056 -- So what we do is to generate the above external tag name, where the
5057 -- hex address is the address of the local dispatch table (i.e. exactly
5058 -- the value we want if Internal_Tag is computed from this string).
5060 -- Of course this value will only be valid if the tagged type is still
5061 -- in scope, but it clearly must be erroneous to compute the internal
5062 -- tag of a tagged type that is out of scope.
5064 -- We don't do this processing if an explicit external tag has been
5065 -- specified. That's an odd case for which we have already issued a
5066 -- warning, where we will not be able to compute the internal tag.
5068 if not Is_Library_Level_Entity
(Typ
)
5069 and then not Has_External_Tag_Rep_Clause
(Typ
)
5072 Exname
: constant Entity_Id
:=
5073 Make_Defining_Identifier
(Loc
,
5074 Chars
=> New_External_Name
(Tname
, 'A'));
5075 Full_Name
: constant String_Id
:=
5076 Fully_Qualified_Name_String
(First_Subtype
(Typ
));
5077 Str1_Id
: String_Id
;
5078 Str2_Id
: String_Id
;
5082 -- Str1 = "Internal tag at 16#";
5085 Store_String_Chars
("Internal tag at 16#");
5086 Str1_Id
:= End_String
;
5089 -- Str2 = "#: <type-full-name>";
5092 Store_String_Chars
("#: ");
5093 Store_String_Chars
(Full_Name
);
5094 Str2_Id
:= End_String
;
5097 -- Exname : constant String :=
5098 -- Str1 & Address_Image (Tag) & Str2;
5100 if RTE_Available
(RE_Address_Image
) then
5102 Make_Object_Declaration
(Loc
,
5103 Defining_Identifier
=> Exname
,
5104 Constant_Present
=> True,
5105 Object_Definition
=> New_Occurrence_Of
5106 (Standard_String
, Loc
),
5108 Make_Op_Concat
(Loc
,
5109 Left_Opnd
=> Make_String_Literal
(Loc
, Str1_Id
),
5111 Make_Op_Concat
(Loc
,
5113 Make_Function_Call
(Loc
,
5116 (RTE
(RE_Address_Image
), Loc
),
5117 Parameter_Associations
=> New_List
(
5118 Unchecked_Convert_To
(RTE
(RE_Address
),
5119 New_Occurrence_Of
(DT_Ptr
, Loc
)))),
5121 Make_String_Literal
(Loc
, Str2_Id
)))));
5125 Make_Object_Declaration
(Loc
,
5126 Defining_Identifier
=> Exname
,
5127 Constant_Present
=> True,
5128 Object_Definition
=>
5129 New_Occurrence_Of
(Standard_String
, Loc
),
5131 Make_Op_Concat
(Loc
,
5132 Left_Opnd
=> Make_String_Literal
(Loc
, Str1_Id
),
5133 Right_Opnd
=> Make_String_Literal
(Loc
, Str2_Id
))));
5137 Unchecked_Convert_To
(RTE
(RE_Cstring_Ptr
),
5138 Make_Attribute_Reference
(Loc
,
5139 Prefix
=> New_Occurrence_Of
(Exname
, Loc
),
5140 Attribute_Name
=> Name_Address
));
5143 -- External tag of a library-level tagged type: Check for a definition
5144 -- of External_Tag. The clause is considered only if it applies to this
5145 -- specific tagged type, as opposed to one of its ancestors.
5146 -- If the type is an unconstrained type extension, we are building the
5147 -- dispatch table of its anonymous base type, so the external tag, if
5148 -- any was specified, must be retrieved from the first subtype. Go to
5149 -- the full view in case the clause is in the private part.
5153 Def
: constant Node_Id
:= Get_Attribute_Definition_Clause
5154 (Underlying_Type
(First_Subtype
(Typ
)),
5155 Attribute_External_Tag
);
5157 Old_Val
: String_Id
;
5158 New_Val
: String_Id
;
5162 if not Present
(Def
)
5163 or else Entity
(Name
(Def
)) /= First_Subtype
(Typ
)
5166 Unchecked_Convert_To
(RTE
(RE_Cstring_Ptr
),
5167 Make_Attribute_Reference
(Loc
,
5168 Prefix
=> New_Occurrence_Of
(Exname
, Loc
),
5169 Attribute_Name
=> Name_Address
));
5171 Old_Val
:= Strval
(Expr_Value_S
(Expression
(Def
)));
5173 -- For the rep clause "for <typ>'external_tag use y" generate:
5175 -- <typ>A : constant string := y;
5177 -- <typ>A'Address is used to set the External_Tag component
5180 -- Create a new nul terminated string if it is not already
5182 if String_Length
(Old_Val
) > 0
5184 Get_String_Char
(Old_Val
, String_Length
(Old_Val
)) = 0
5188 Start_String
(Old_Val
);
5189 Store_String_Char
(Get_Char_Code
(ASCII
.NUL
));
5190 New_Val
:= End_String
;
5193 E
:= Make_Defining_Identifier
(Loc
,
5194 New_External_Name
(Chars
(Typ
), 'A'));
5197 Make_Object_Declaration
(Loc
,
5198 Defining_Identifier
=> E
,
5199 Constant_Present
=> True,
5200 Object_Definition
=>
5201 New_Occurrence_Of
(Standard_String
, Loc
),
5203 Make_String_Literal
(Loc
, New_Val
)));
5206 Unchecked_Convert_To
(RTE
(RE_Cstring_Ptr
),
5207 Make_Attribute_Reference
(Loc
,
5208 Prefix
=> New_Occurrence_Of
(E
, Loc
),
5209 Attribute_Name
=> Name_Address
));
5214 Append_To
(TSD_Aggr_List
, New_Node
);
5218 if RTE_Available
(RE_Register_Tag
) then
5219 Append_To
(TSD_Aggr_List
,
5220 Unchecked_Convert_To
(RTE
(RE_Tag_Ptr
),
5221 Make_Attribute_Reference
(Loc
,
5222 Prefix
=> New_Occurrence_Of
(HT_Link
, Loc
),
5223 Attribute_Name
=> Name_Address
)));
5225 Append_To
(TSD_Aggr_List
,
5226 Unchecked_Convert_To
(RTE
(RE_Tag_Ptr
),
5227 New_Occurrence_Of
(RTE
(RE_Null_Address
), Loc
)));
5230 -- Transportable: Set for types that can be used in remote calls
5231 -- with respect to E.4(18) legality rules.
5234 Transportable
: Entity_Id
;
5240 or else Is_Shared_Passive
(Typ
)
5242 ((Is_Remote_Types
(Typ
)
5243 or else Is_Remote_Call_Interface
(Typ
))
5244 and then Original_View_In_Visible_Part
(Typ
))
5245 or else not Comes_From_Source
(Typ
));
5247 Append_To
(TSD_Aggr_List
,
5248 New_Occurrence_Of
(Transportable
, Loc
));
5251 -- Is_Abstract (Ada 2012: AI05-0173). This functionality is not
5252 -- available in the HIE runtime.
5254 if RTE_Record_Component_Available
(RE_Is_Abstract
) then
5256 Is_Abstract
: Entity_Id
;
5258 Is_Abstract
:= Boolean_Literals
(Is_Abstract_Type
(Typ
));
5259 Append_To
(TSD_Aggr_List
,
5260 New_Occurrence_Of
(Is_Abstract
, Loc
));
5264 -- Needs_Finalization: Set if the type is controlled or has controlled
5268 Needs_Fin
: Entity_Id
;
5270 Needs_Fin
:= Boolean_Literals
(Needs_Finalization
(Typ
));
5271 Append_To
(TSD_Aggr_List
, New_Occurrence_Of
(Needs_Fin
, Loc
));
5276 if RTE_Record_Component_Available
(RE_Size_Func
) then
5278 -- Initialize this field to Null_Address if we are not building
5279 -- static dispatch tables static or if the size function is not
5280 -- available. In the former case we cannot initialize this field
5281 -- until the function is frozen and registered in the dispatch
5282 -- table (see Register_Primitive).
5284 if not Building_Static_DT
(Typ
) or else not Has_DT
(Typ
) then
5285 Append_To
(TSD_Aggr_List
,
5286 Unchecked_Convert_To
(RTE
(RE_Size_Ptr
),
5287 New_Occurrence_Of
(RTE
(RE_Null_Address
), Loc
)));
5291 Prim_Elmt
: Elmt_Id
;
5293 Size_Comp
: Node_Id
:= Empty
;
5296 Prim_Elmt
:= First_Elmt
(Primitive_Operations
(Typ
));
5297 while Present
(Prim_Elmt
) loop
5298 Prim
:= Node
(Prim_Elmt
);
5300 if Chars
(Prim
) = Name_uSize
then
5301 Prim
:= Ultimate_Alias
(Prim
);
5303 if Is_Abstract_Subprogram
(Prim
) then
5305 Unchecked_Convert_To
(RTE
(RE_Size_Ptr
),
5306 New_Occurrence_Of
(RTE
(RE_Null_Address
), Loc
));
5309 Unchecked_Convert_To
(RTE
(RE_Size_Ptr
),
5310 Make_Attribute_Reference
(Loc
,
5311 Prefix
=> New_Occurrence_Of
(Prim
, Loc
),
5312 Attribute_Name
=> Name_Unrestricted_Access
));
5318 Next_Elmt
(Prim_Elmt
);
5321 pragma Assert
(Present
(Size_Comp
));
5322 Append_To
(TSD_Aggr_List
, Size_Comp
);
5327 -- Interfaces_Table (required for AI-405)
5329 if RTE_Record_Component_Available
(RE_Interfaces_Table
) then
5331 -- Count the number of interface types implemented by Typ
5333 Collect_Interfaces
(Typ
, Typ_Ifaces
);
5335 AI
:= First_Elmt
(Typ_Ifaces
);
5336 while Present
(AI
) loop
5337 Num_Ifaces
:= Num_Ifaces
+ 1;
5341 if Num_Ifaces
= 0 then
5342 Iface_Table_Node
:= Make_Null
(Loc
);
5344 -- Generate the Interface_Table object
5348 TSD_Ifaces_List
: constant List_Id
:= New_List
;
5350 Sec_DT_Tag
: Node_Id
;
5353 AI
:= First_Elmt
(Typ_Ifaces
);
5354 while Present
(AI
) loop
5355 if Is_Ancestor
(Node
(AI
), Typ
, Use_Full_View
=> True) then
5357 New_Occurrence_Of
(DT_Ptr
, Loc
);
5361 (Next_Elmt
(First_Elmt
(Access_Disp_Table
(Typ
))));
5362 pragma Assert
(Has_Thunks
(Node
(Elmt
)));
5364 while Is_Tag
(Node
(Elmt
))
5366 Is_Ancestor
(Node
(AI
), Related_Type
(Node
(Elmt
)),
5367 Use_Full_View
=> True)
5369 pragma Assert
(Has_Thunks
(Node
(Elmt
)));
5371 pragma Assert
(Has_Thunks
(Node
(Elmt
)));
5373 pragma Assert
(not Has_Thunks
(Node
(Elmt
)));
5375 pragma Assert
(not Has_Thunks
(Node
(Elmt
)));
5379 pragma Assert
(Ekind
(Node
(Elmt
)) = E_Constant
5381 Has_Thunks
(Node
(Next_Elmt
(Next_Elmt
(Elmt
)))));
5383 New_Occurrence_Of
(Node
(Next_Elmt
(Next_Elmt
(Elmt
))),
5387 Append_To
(TSD_Ifaces_List
,
5388 Make_Aggregate
(Loc
,
5389 Expressions
=> New_List
(
5393 Unchecked_Convert_To
(RTE
(RE_Tag
),
5395 (Node
(First_Elmt
(Access_Disp_Table
(Node
(AI
)))),
5398 -- Static_Offset_To_Top
5400 New_Occurrence_Of
(Standard_True
, Loc
),
5402 -- Offset_To_Top_Value
5404 Make_Integer_Literal
(Loc
, 0),
5406 -- Offset_To_Top_Func
5412 Unchecked_Convert_To
(RTE
(RE_Tag
), Sec_DT_Tag
)
5419 Name_ITable
:= New_External_Name
(Tname
, 'I');
5420 ITable
:= Make_Defining_Identifier
(Loc
, Name_ITable
);
5421 Set_Is_Statically_Allocated
(ITable
,
5422 Is_Library_Level_Tagged_Type
(Typ
));
5424 -- The table of interfaces is not constant; its slots are
5425 -- filled at run time by the IP routine using attribute
5426 -- 'Position to know the location of the tag components
5427 -- (and this attribute cannot be safely used before the
5428 -- object is initialized).
5431 Make_Object_Declaration
(Loc
,
5432 Defining_Identifier
=> ITable
,
5433 Aliased_Present
=> True,
5434 Constant_Present
=> False,
5435 Object_Definition
=>
5436 Make_Subtype_Indication
(Loc
,
5438 New_Occurrence_Of
(RTE
(RE_Interface_Data
), Loc
),
5440 Make_Index_Or_Discriminant_Constraint
(Loc
,
5441 Constraints
=> New_List
(
5442 Make_Integer_Literal
(Loc
, Num_Ifaces
)))),
5444 Expression
=> Make_Aggregate
(Loc
,
5445 Expressions
=> New_List
(
5446 Make_Integer_Literal
(Loc
, Num_Ifaces
),
5447 Make_Aggregate
(Loc
, TSD_Ifaces_List
)))));
5450 Make_Attribute_Definition_Clause
(Loc
,
5451 Name
=> New_Occurrence_Of
(ITable
, Loc
),
5452 Chars
=> Name_Alignment
,
5454 Make_Attribute_Reference
(Loc
,
5456 New_Occurrence_Of
(RTE
(RE_Integer_Address
), Loc
),
5457 Attribute_Name
=> Name_Alignment
)));
5460 Make_Attribute_Reference
(Loc
,
5461 Prefix
=> New_Occurrence_Of
(ITable
, Loc
),
5462 Attribute_Name
=> Name_Unchecked_Access
);
5466 Append_To
(TSD_Aggr_List
, Iface_Table_Node
);
5469 -- Generate the Select Specific Data table for synchronized types that
5470 -- implement synchronized interfaces. The size of the table is
5471 -- constrained by the number of non-predefined primitive operations.
5473 if RTE_Record_Component_Available
(RE_SSD
) then
5474 if Ada_Version
>= Ada_2005
5475 and then Has_DT
(Typ
)
5476 and then Is_Concurrent_Record_Type
(Typ
)
5477 and then Has_Interfaces
(Typ
)
5478 and then Nb_Prim
> 0
5479 and then not Is_Abstract_Type
(Typ
)
5480 and then not Is_Controlled
(Typ
)
5481 and then not Restriction_Active
(No_Dispatching_Calls
)
5482 and then not Restriction_Active
(No_Select_Statements
)
5485 Make_Object_Declaration
(Loc
,
5486 Defining_Identifier
=> SSD
,
5487 Aliased_Present
=> True,
5488 Object_Definition
=>
5489 Make_Subtype_Indication
(Loc
,
5490 Subtype_Mark
=> New_Occurrence_Of
(
5491 RTE
(RE_Select_Specific_Data
), Loc
),
5493 Make_Index_Or_Discriminant_Constraint
(Loc
,
5494 Constraints
=> New_List
(
5495 Make_Integer_Literal
(Loc
, Nb_Prim
))))));
5498 Make_Attribute_Definition_Clause
(Loc
,
5499 Name
=> New_Occurrence_Of
(SSD
, Loc
),
5500 Chars
=> Name_Alignment
,
5502 Make_Attribute_Reference
(Loc
,
5504 New_Occurrence_Of
(RTE
(RE_Integer_Address
), Loc
),
5505 Attribute_Name
=> Name_Alignment
)));
5507 -- This table is initialized by Make_Select_Specific_Data_Table,
5508 -- which calls Set_Entry_Index and Set_Prim_Op_Kind.
5510 Append_To
(TSD_Aggr_List
,
5511 Make_Attribute_Reference
(Loc
,
5512 Prefix
=> New_Occurrence_Of
(SSD
, Loc
),
5513 Attribute_Name
=> Name_Unchecked_Access
));
5515 Append_To
(TSD_Aggr_List
, Make_Null
(Loc
));
5519 -- Initialize the table of ancestor tags. In case of interface types
5520 -- this table is not needed.
5522 TSD_Tags_List
:= New_List
;
5524 -- If we are not statically allocating the dispatch table then we must
5525 -- fill position 0 with null because we still have not generated the
5528 if not Building_Static_DT
(Typ
)
5529 or else Is_Interface
(Typ
)
5531 Append_To
(TSD_Tags_List
,
5532 Unchecked_Convert_To
(RTE
(RE_Tag
),
5533 New_Occurrence_Of
(RTE
(RE_Null_Address
), Loc
)));
5535 -- Otherwise we can safely reference the tag
5538 Append_To
(TSD_Tags_List
,
5539 New_Occurrence_Of
(DT_Ptr
, Loc
));
5542 -- Fill the rest of the table with the tags of the ancestors
5545 Current_Typ
: Entity_Id
;
5546 Parent_Typ
: Entity_Id
;
5554 Parent_Typ
:= Etype
(Current_Typ
);
5556 if Is_Private_Type
(Parent_Typ
) then
5557 Parent_Typ
:= Full_View
(Base_Type
(Parent_Typ
));
5560 exit when Parent_Typ
= Current_Typ
;
5562 if Is_CPP_Class
(Parent_Typ
) then
5564 -- The tags defined in the C++ side will be inherited when
5565 -- the object is constructed (Exp_Ch3.Build_Init_Procedure)
5567 Append_To
(TSD_Tags_List
,
5568 Unchecked_Convert_To
(RTE
(RE_Tag
),
5569 New_Occurrence_Of
(RTE
(RE_Null_Address
), Loc
)));
5571 Append_To
(TSD_Tags_List
,
5573 (Node
(First_Elmt
(Access_Disp_Table
(Parent_Typ
))),
5578 Current_Typ
:= Parent_Typ
;
5581 pragma Assert
(Pos
= I_Depth
+ 1);
5584 Append_To
(TSD_Aggr_List
,
5585 Make_Aggregate
(Loc
,
5586 Expressions
=> TSD_Tags_List
));
5588 -- Build the TSD object
5591 Make_Object_Declaration
(Loc
,
5592 Defining_Identifier
=> TSD
,
5593 Aliased_Present
=> True,
5594 Constant_Present
=> Building_Static_DT
(Typ
),
5595 Object_Definition
=>
5596 Make_Subtype_Indication
(Loc
,
5597 Subtype_Mark
=> New_Occurrence_Of
(
5598 RTE
(RE_Type_Specific_Data
), Loc
),
5600 Make_Index_Or_Discriminant_Constraint
(Loc
,
5601 Constraints
=> New_List
(
5602 Make_Integer_Literal
(Loc
, I_Depth
)))),
5604 Expression
=> Make_Aggregate
(Loc
,
5605 Expressions
=> TSD_Aggr_List
)));
5607 Set_Is_True_Constant
(TSD
, Building_Static_DT
(Typ
));
5610 Make_Attribute_Definition_Clause
(Loc
,
5611 Name
=> New_Occurrence_Of
(TSD
, Loc
),
5612 Chars
=> Name_Alignment
,
5614 Make_Attribute_Reference
(Loc
,
5616 New_Occurrence_Of
(RTE
(RE_Integer_Address
), Loc
),
5617 Attribute_Name
=> Name_Alignment
)));
5619 -- Initialize or declare the dispatch table object
5621 if not Has_DT
(Typ
) then
5622 DT_Constr_List
:= New_List
;
5623 DT_Aggr_List
:= New_List
;
5628 Make_Attribute_Reference
(Loc
,
5629 Prefix
=> New_Occurrence_Of
(TSD
, Loc
),
5630 Attribute_Name
=> Name_Address
);
5632 Append_To
(DT_Constr_List
, New_Node
);
5633 Append_To
(DT_Aggr_List
, New_Copy
(New_Node
));
5634 Append_To
(DT_Aggr_List
, Make_Integer_Literal
(Loc
, 0));
5636 -- In case of locally defined tagged types we have already declared
5637 -- and uninitialized object for the dispatch table, which is now
5638 -- initialized by means of the following assignment:
5640 -- DT := (TSD'Address, 0);
5642 if not Building_Static_DT
(Typ
) then
5644 Make_Assignment_Statement
(Loc
,
5645 Name
=> New_Occurrence_Of
(DT
, Loc
),
5646 Expression
=> Make_Aggregate
(Loc
, DT_Aggr_List
)));
5648 -- In case of library level tagged types we declare and export now
5649 -- the constant object containing the dummy dispatch table. There
5650 -- is no need to declare the tag here because it has been previously
5651 -- declared by Make_Tags
5653 -- DT : aliased constant No_Dispatch_Table :=
5654 -- (NDT_TSD => TSD'Address;
5655 -- NDT_Prims_Ptr => 0);
5656 -- for DT'Alignment use Address'Alignment;
5660 Make_Object_Declaration
(Loc
,
5661 Defining_Identifier
=> DT
,
5662 Aliased_Present
=> True,
5663 Constant_Present
=> True,
5664 Object_Definition
=>
5665 New_Occurrence_Of
(RTE
(RE_No_Dispatch_Table_Wrapper
), Loc
),
5666 Expression
=> Make_Aggregate
(Loc
, DT_Aggr_List
)));
5669 Make_Attribute_Definition_Clause
(Loc
,
5670 Name
=> New_Occurrence_Of
(DT
, Loc
),
5671 Chars
=> Name_Alignment
,
5673 Make_Attribute_Reference
(Loc
,
5675 New_Occurrence_Of
(RTE
(RE_Integer_Address
), Loc
),
5676 Attribute_Name
=> Name_Alignment
)));
5678 Export_DT
(Typ
, DT
);
5681 -- Common case: Typ has a dispatch table
5685 -- Predef_Prims : Address_Array (1 .. Default_Prim_Ops_Count) :=
5686 -- (predef-prim-op-1'address,
5687 -- predef-prim-op-2'address,
5689 -- predef-prim-op-n'address);
5690 -- for Predef_Prims'Alignment use Address'Alignment
5692 -- DT : Dispatch_Table (Nb_Prims) :=
5693 -- (Signature => <sig-value>,
5694 -- Tag_Kind => <tag_kind-value>,
5695 -- Predef_Prims => Predef_Prims'First'Address,
5696 -- Offset_To_Top => 0,
5697 -- TSD => TSD'Address;
5698 -- Prims_Ptr => (prim-op-1'address,
5699 -- prim-op-2'address,
5701 -- prim-op-n'address));
5702 -- for DT'Alignment use Address'Alignment
5709 if not Building_Static_DT
(Typ
) then
5710 Nb_Predef_Prims
:= Max_Predef_Prims
;
5713 Prim_Elmt
:= First_Elmt
(Primitive_Operations
(Typ
));
5714 while Present
(Prim_Elmt
) loop
5715 Prim
:= Node
(Prim_Elmt
);
5717 if Is_Predefined_Dispatching_Operation
(Prim
)
5718 and then not Is_Abstract_Subprogram
(Prim
)
5720 Pos
:= UI_To_Int
(DT_Position
(Prim
));
5722 if Pos
> Nb_Predef_Prims
then
5723 Nb_Predef_Prims
:= Pos
;
5727 Next_Elmt
(Prim_Elmt
);
5733 (Nat
range 1 .. Nb_Predef_Prims
) of Entity_Id
;
5738 Prim_Ops_Aggr_List
:= New_List
;
5740 Prim_Table
:= (others => Empty
);
5742 if Building_Static_DT
(Typ
) then
5743 Prim_Elmt
:= First_Elmt
(Primitive_Operations
(Typ
));
5744 while Present
(Prim_Elmt
) loop
5745 Prim
:= Node
(Prim_Elmt
);
5747 if Is_Predefined_Dispatching_Operation
(Prim
)
5748 and then not Is_Abstract_Subprogram
(Prim
)
5749 and then not Is_Eliminated
(Prim
)
5750 and then not Present
(Prim_Table
5751 (UI_To_Int
(DT_Position
(Prim
))))
5753 E
:= Ultimate_Alias
(Prim
);
5754 pragma Assert
(not Is_Abstract_Subprogram
(E
));
5755 Prim_Table
(UI_To_Int
(DT_Position
(Prim
))) := E
;
5758 Next_Elmt
(Prim_Elmt
);
5762 for J
in Prim_Table
'Range loop
5763 if Present
(Prim_Table
(J
)) then
5765 Unchecked_Convert_To
(RTE
(RE_Prim_Ptr
),
5766 Make_Attribute_Reference
(Loc
,
5768 New_Occurrence_Of
(Prim_Table
(J
), Loc
),
5769 Attribute_Name
=> Name_Unrestricted_Access
));
5771 New_Node
:= Make_Null
(Loc
);
5774 Append_To
(Prim_Ops_Aggr_List
, New_Node
);
5778 Make_Aggregate
(Loc
,
5779 Expressions
=> Prim_Ops_Aggr_List
);
5782 Make_Subtype_Declaration
(Loc
,
5783 Defining_Identifier
=> Make_Temporary
(Loc
, 'S'),
5784 Subtype_Indication
=>
5785 New_Occurrence_Of
(RTE
(RE_Address_Array
), Loc
));
5787 Append_To
(Result
, Decl
);
5790 Make_Object_Declaration
(Loc
,
5791 Defining_Identifier
=> Predef_Prims
,
5792 Aliased_Present
=> True,
5793 Constant_Present
=> Building_Static_DT
(Typ
),
5794 Object_Definition
=>
5795 New_Occurrence_Of
(Defining_Identifier
(Decl
), Loc
),
5796 Expression
=> New_Node
));
5798 -- Remember aggregates initializing dispatch tables
5800 Append_Elmt
(New_Node
, DT_Aggr
);
5803 Make_Attribute_Definition_Clause
(Loc
,
5804 Name
=> New_Occurrence_Of
(Predef_Prims
, Loc
),
5805 Chars
=> Name_Alignment
,
5807 Make_Attribute_Reference
(Loc
,
5809 New_Occurrence_Of
(RTE
(RE_Integer_Address
), Loc
),
5810 Attribute_Name
=> Name_Alignment
)));
5814 -- Stage 1: Initialize the discriminant and the record components
5816 DT_Constr_List
:= New_List
;
5817 DT_Aggr_List
:= New_List
;
5819 -- Num_Prims. If the tagged type has no primitives we add a dummy
5820 -- slot whose address will be the tag of this type.
5823 New_Node
:= Make_Integer_Literal
(Loc
, 1);
5825 New_Node
:= Make_Integer_Literal
(Loc
, Nb_Prim
);
5828 Append_To
(DT_Constr_List
, New_Node
);
5829 Append_To
(DT_Aggr_List
, New_Copy
(New_Node
));
5833 if RTE_Record_Component_Available
(RE_Signature
) then
5834 Append_To
(DT_Aggr_List
,
5835 New_Occurrence_Of
(RTE
(RE_Primary_DT
), Loc
));
5840 if RTE_Record_Component_Available
(RE_Tag_Kind
) then
5841 Append_To
(DT_Aggr_List
, Tagged_Kind
(Typ
));
5846 Append_To
(DT_Aggr_List
,
5847 Make_Attribute_Reference
(Loc
,
5848 Prefix
=> New_Occurrence_Of
(Predef_Prims
, Loc
),
5849 Attribute_Name
=> Name_Address
));
5853 Append_To
(DT_Aggr_List
, Make_Integer_Literal
(Loc
, 0));
5857 Append_To
(DT_Aggr_List
,
5858 Make_Attribute_Reference
(Loc
,
5859 Prefix
=> New_Occurrence_Of
(TSD
, Loc
),
5860 Attribute_Name
=> Name_Address
));
5862 -- Stage 2: Initialize the table of user-defined primitive operations
5864 Prim_Ops_Aggr_List
:= New_List
;
5867 Append_To
(Prim_Ops_Aggr_List
, Make_Null
(Loc
));
5869 elsif not Building_Static_DT
(Typ
) then
5870 for J
in 1 .. Nb_Prim
loop
5871 Append_To
(Prim_Ops_Aggr_List
, Make_Null
(Loc
));
5876 CPP_Nb_Prims
: constant Nat
:= CPP_Num_Prims
(Typ
);
5879 Prim_Elmt
: Elmt_Id
;
5881 Prim_Table
: array (Nat
range 1 .. Nb_Prim
) of Entity_Id
;
5884 Prim_Table
:= (others => Empty
);
5886 Prim_Elmt
:= First_Elmt
(Primitive_Operations
(Typ
));
5887 while Present
(Prim_Elmt
) loop
5888 Prim
:= Node
(Prim_Elmt
);
5890 -- Retrieve the ultimate alias of the primitive for proper
5891 -- handling of renamings and eliminated primitives.
5893 E
:= Ultimate_Alias
(Prim
);
5895 -- If the alias is not a primitive operation then Prim does
5896 -- not rename another primitive, but rather an operation
5897 -- declared elsewhere (e.g. in another scope) and therefore
5898 -- Prim is a new primitive.
5900 if No
(Find_Dispatching_Type
(E
)) then
5904 Prim_Pos
:= UI_To_Int
(DT_Position
(E
));
5906 -- Skip predefined primitives because they are located in a
5907 -- separate dispatch table.
5909 if not Is_Predefined_Dispatching_Operation
(Prim
)
5910 and then not Is_Predefined_Dispatching_Operation
(E
)
5912 -- Skip entities with attribute Interface_Alias because
5913 -- those are only required to build secondary dispatch
5916 and then not Present
(Interface_Alias
(Prim
))
5918 -- Skip abstract and eliminated primitives
5920 and then not Is_Abstract_Subprogram
(E
)
5921 and then not Is_Eliminated
(E
)
5923 -- For derivations of CPP types skip primitives located in
5924 -- the C++ part of the dispatch table because their slots
5925 -- are initialized by the IC routine.
5927 and then (not Is_CPP_Class
(Root_Type
(Typ
))
5928 or else Prim_Pos
> CPP_Nb_Prims
)
5930 -- Skip ignored Ghost subprograms as those will be removed
5931 -- from the executable.
5933 and then not Is_Ignored_Ghost_Entity
(E
)
5936 (UI_To_Int
(DT_Position
(Prim
)) <= Nb_Prim
);
5938 Prim_Table
(UI_To_Int
(DT_Position
(Prim
))) := E
;
5941 Next_Elmt
(Prim_Elmt
);
5944 for J
in Prim_Table
'Range loop
5945 if Present
(Prim_Table
(J
)) then
5947 Unchecked_Convert_To
(RTE
(RE_Prim_Ptr
),
5948 Make_Attribute_Reference
(Loc
,
5950 New_Occurrence_Of
(Prim_Table
(J
), Loc
),
5951 Attribute_Name
=> Name_Unrestricted_Access
));
5953 New_Node
:= Make_Null
(Loc
);
5956 Append_To
(Prim_Ops_Aggr_List
, New_Node
);
5962 Make_Aggregate
(Loc
,
5963 Expressions
=> Prim_Ops_Aggr_List
);
5965 Append_To
(DT_Aggr_List
, New_Node
);
5967 -- Remember aggregates initializing dispatch tables
5969 Append_Elmt
(New_Node
, DT_Aggr
);
5971 -- In case of locally defined tagged types we have already declared
5972 -- and uninitialized object for the dispatch table, which is now
5973 -- initialized by means of an assignment.
5975 if not Building_Static_DT
(Typ
) then
5977 Make_Assignment_Statement
(Loc
,
5978 Name
=> New_Occurrence_Of
(DT
, Loc
),
5979 Expression
=> Make_Aggregate
(Loc
, DT_Aggr_List
)));
5981 -- In case of library level tagged types we declare now and export
5982 -- the constant object containing the dispatch table.
5986 Make_Object_Declaration
(Loc
,
5987 Defining_Identifier
=> DT
,
5988 Aliased_Present
=> True,
5989 Constant_Present
=> True,
5990 Object_Definition
=>
5991 Make_Subtype_Indication
(Loc
,
5992 Subtype_Mark
=> New_Occurrence_Of
5993 (RTE
(RE_Dispatch_Table_Wrapper
), Loc
),
5994 Constraint
=> Make_Index_Or_Discriminant_Constraint
(Loc
,
5995 Constraints
=> DT_Constr_List
)),
5996 Expression
=> Make_Aggregate
(Loc
, DT_Aggr_List
)));
5999 Make_Attribute_Definition_Clause
(Loc
,
6000 Name
=> New_Occurrence_Of
(DT
, Loc
),
6001 Chars
=> Name_Alignment
,
6003 Make_Attribute_Reference
(Loc
,
6005 New_Occurrence_Of
(RTE
(RE_Integer_Address
), Loc
),
6006 Attribute_Name
=> Name_Alignment
)));
6008 Export_DT
(Typ
, DT
);
6012 -- Initialize the table of ancestor tags if not building static
6015 if not Building_Static_DT
(Typ
)
6016 and then not Is_Interface
(Typ
)
6017 and then not Is_CPP_Class
(Typ
)
6020 Make_Assignment_Statement
(Loc
,
6022 Make_Indexed_Component
(Loc
,
6024 Make_Selected_Component
(Loc
,
6025 Prefix
=> New_Occurrence_Of
(TSD
, Loc
),
6028 (RTE_Record_Component
(RE_Tags_Table
), Loc
)),
6030 New_List
(Make_Integer_Literal
(Loc
, 0))),
6034 (Node
(First_Elmt
(Access_Disp_Table
(Typ
))), Loc
)));
6037 -- Inherit the dispatch tables of the parent. There is no need to
6038 -- inherit anything from the parent when building static dispatch tables
6039 -- because the whole dispatch table (including inherited primitives) has
6040 -- been already built.
6042 if Building_Static_DT
(Typ
) then
6045 -- If the ancestor is a CPP_Class type we inherit the dispatch tables
6046 -- in the init proc, and we don't need to fill them in here.
6048 elsif Is_CPP_Class
(Parent_Typ
) then
6051 -- Otherwise we fill in the dispatch tables here
6054 if Typ
/= Parent_Typ
6055 and then not Is_Interface
(Typ
)
6056 and then not Restriction_Active
(No_Dispatching_Calls
)
6058 -- Inherit the dispatch table
6060 if not Is_Interface
(Typ
)
6061 and then not Is_Interface
(Parent_Typ
)
6062 and then not Is_CPP_Class
(Parent_Typ
)
6065 Nb_Prims
: constant Int
:=
6066 UI_To_Int
(DT_Entry_Count
6067 (First_Tag_Component
(Parent_Typ
)));
6070 Append_To
(Elab_Code
,
6071 Build_Inherit_Predefined_Prims
(Loc
,
6077 (Access_Disp_Table
(Parent_Typ
)))), Loc
),
6083 (Access_Disp_Table
(Typ
)))), Loc
)));
6085 if Nb_Prims
/= 0 then
6086 Append_To
(Elab_Code
,
6087 Build_Inherit_Prims
(Loc
,
6093 (Access_Disp_Table
(Parent_Typ
))), Loc
),
6094 New_Tag_Node
=> New_Occurrence_Of
(DT_Ptr
, Loc
),
6095 Num_Prims
=> Nb_Prims
));
6100 -- Inherit the secondary dispatch tables of the ancestor
6102 if not Is_CPP_Class
(Parent_Typ
) then
6104 Sec_DT_Ancestor
: Elmt_Id
:=
6110 Sec_DT_Typ
: Elmt_Id
:=
6114 (Access_Disp_Table
(Typ
))));
6116 procedure Copy_Secondary_DTs
(Typ
: Entity_Id
);
6117 -- Local procedure required to climb through the ancestors
6118 -- and copy the contents of all their secondary dispatch
6121 ------------------------
6122 -- Copy_Secondary_DTs --
6123 ------------------------
6125 procedure Copy_Secondary_DTs
(Typ
: Entity_Id
) is
6130 -- Climb to the ancestor (if any) handling private types
6132 if Present
(Full_View
(Etype
(Typ
))) then
6133 if Full_View
(Etype
(Typ
)) /= Typ
then
6134 Copy_Secondary_DTs
(Full_View
(Etype
(Typ
)));
6137 elsif Etype
(Typ
) /= Typ
then
6138 Copy_Secondary_DTs
(Etype
(Typ
));
6141 if Present
(Interfaces
(Typ
))
6142 and then not Is_Empty_Elmt_List
(Interfaces
(Typ
))
6144 Iface
:= First_Elmt
(Interfaces
(Typ
));
6145 E
:= First_Entity
(Typ
);
6147 and then Present
(Node
(Sec_DT_Ancestor
))
6148 and then Ekind
(Node
(Sec_DT_Ancestor
)) = E_Constant
6150 if Is_Tag
(E
) and then Chars
(E
) /= Name_uTag
then
6152 Num_Prims
: constant Int
:=
6153 UI_To_Int
(DT_Entry_Count
(E
));
6156 if not Is_Interface
(Etype
(Typ
)) then
6158 -- Inherit first secondary dispatch table
6160 Append_To
(Elab_Code
,
6161 Build_Inherit_Predefined_Prims
(Loc
,
6163 Unchecked_Convert_To
(RTE
(RE_Tag
),
6166 (Next_Elmt
(Sec_DT_Ancestor
)),
6169 Unchecked_Convert_To
(RTE
(RE_Tag
),
6171 (Node
(Next_Elmt
(Sec_DT_Typ
)),
6174 if Num_Prims
/= 0 then
6175 Append_To
(Elab_Code
,
6176 Build_Inherit_Prims
(Loc
,
6177 Typ
=> Node
(Iface
),
6179 Unchecked_Convert_To
6182 (Node
(Sec_DT_Ancestor
),
6185 Unchecked_Convert_To
6188 (Node
(Sec_DT_Typ
), Loc
)),
6189 Num_Prims
=> Num_Prims
));
6193 Next_Elmt
(Sec_DT_Ancestor
);
6194 Next_Elmt
(Sec_DT_Typ
);
6196 -- Skip the secondary dispatch table of
6197 -- predefined primitives
6199 Next_Elmt
(Sec_DT_Ancestor
);
6200 Next_Elmt
(Sec_DT_Typ
);
6202 if not Is_Interface
(Etype
(Typ
)) then
6204 -- Inherit second secondary dispatch table
6206 Append_To
(Elab_Code
,
6207 Build_Inherit_Predefined_Prims
(Loc
,
6209 Unchecked_Convert_To
(RTE
(RE_Tag
),
6212 (Next_Elmt
(Sec_DT_Ancestor
)),
6215 Unchecked_Convert_To
(RTE
(RE_Tag
),
6217 (Node
(Next_Elmt
(Sec_DT_Typ
)),
6220 if Num_Prims
/= 0 then
6221 Append_To
(Elab_Code
,
6222 Build_Inherit_Prims
(Loc
,
6223 Typ
=> Node
(Iface
),
6225 Unchecked_Convert_To
6228 (Node
(Sec_DT_Ancestor
),
6231 Unchecked_Convert_To
6234 (Node
(Sec_DT_Typ
), Loc
)),
6235 Num_Prims
=> Num_Prims
));
6240 Next_Elmt
(Sec_DT_Ancestor
);
6241 Next_Elmt
(Sec_DT_Typ
);
6243 -- Skip the secondary dispatch table of
6244 -- predefined primitives
6246 Next_Elmt
(Sec_DT_Ancestor
);
6247 Next_Elmt
(Sec_DT_Typ
);
6255 end Copy_Secondary_DTs
;
6258 if Present
(Node
(Sec_DT_Ancestor
))
6259 and then Ekind
(Node
(Sec_DT_Ancestor
)) = E_Constant
6261 -- Handle private types
6263 if Present
(Full_View
(Typ
)) then
6264 Copy_Secondary_DTs
(Full_View
(Typ
));
6266 Copy_Secondary_DTs
(Typ
);
6274 -- Generate code to check if the external tag of this type is the same
6275 -- as the external tag of some other declaration.
6277 -- Check_TSD (TSD'Unrestricted_Access);
6279 -- This check is a consequence of AI05-0113-1/06, so it officially
6280 -- applies to Ada 2005 (and Ada 2012). It might be argued that it is
6281 -- a desirable check to add in Ada 95 mode, but we hesitate to make
6282 -- this change, as it would be incompatible, and could conceivably
6283 -- cause a problem in existing Aa 95 code.
6285 -- We check for No_Run_Time_Mode here, because we do not want to pick
6286 -- up the RE_Check_TSD entity and call it in No_Run_Time mode.
6288 if not No_Run_Time_Mode
6289 and then Ada_Version
>= Ada_2005
6290 and then RTE_Available
(RE_Check_TSD
)
6291 and then not Duplicated_Tag_Checks_Suppressed
(Typ
)
6293 Append_To
(Elab_Code
,
6294 Make_Procedure_Call_Statement
(Loc
,
6296 New_Occurrence_Of
(RTE
(RE_Check_TSD
), Loc
),
6297 Parameter_Associations
=> New_List
(
6298 Make_Attribute_Reference
(Loc
,
6299 Prefix
=> New_Occurrence_Of
(TSD
, Loc
),
6300 Attribute_Name
=> Name_Unchecked_Access
))));
6303 -- Generate code to register the Tag in the External_Tag hash table for
6304 -- the pure Ada type only.
6306 -- Register_Tag (Dt_Ptr);
6308 -- Skip this action in the following cases:
6309 -- 1) if Register_Tag is not available.
6310 -- 2) in No_Run_Time mode.
6311 -- 3) if Typ is not defined at the library level (this is required
6312 -- to avoid adding concurrency control to the hash table used
6313 -- by the run-time to register the tags).
6315 if not No_Run_Time_Mode
6316 and then Is_Library_Level_Entity
(Typ
)
6317 and then RTE_Available
(RE_Register_Tag
)
6319 Append_To
(Elab_Code
,
6320 Make_Procedure_Call_Statement
(Loc
,
6322 New_Occurrence_Of
(RTE
(RE_Register_Tag
), Loc
),
6323 Parameter_Associations
=>
6324 New_List
(New_Occurrence_Of
(DT_Ptr
, Loc
))));
6327 if not Is_Empty_List
(Elab_Code
) then
6328 Append_List_To
(Result
, Elab_Code
);
6331 -- Populate the two auxiliary tables used for dispatching asynchronous,
6332 -- conditional and timed selects for synchronized types that implement
6333 -- a limited interface. Skip this step in Ravenscar profile or when
6334 -- general dispatching is forbidden.
6336 if Ada_Version
>= Ada_2005
6337 and then Is_Concurrent_Record_Type
(Typ
)
6338 and then Has_Interfaces
(Typ
)
6339 and then not Restriction_Active
(No_Dispatching_Calls
)
6340 and then not Restriction_Active
(No_Select_Statements
)
6342 Append_List_To
(Result
,
6343 Make_Select_Specific_Data_Table
(Typ
));
6346 -- Remember entities containing dispatch tables
6348 Append_Elmt
(Predef_Prims
, DT_Decl
);
6349 Append_Elmt
(DT
, DT_Decl
);
6351 Analyze_List
(Result
, Suppress
=> All_Checks
);
6352 Set_Has_Dispatch_Table
(Typ
);
6354 -- Mark entities containing dispatch tables. Required by the backend to
6355 -- handle them properly.
6357 if Has_DT
(Typ
) then
6362 -- Object declarations
6364 Elmt
:= First_Elmt
(DT_Decl
);
6365 while Present
(Elmt
) loop
6366 Set_Is_Dispatch_Table_Entity
(Node
(Elmt
));
6367 pragma Assert
(Ekind
(Etype
(Node
(Elmt
))) = E_Array_Subtype
6368 or else Ekind
(Etype
(Node
(Elmt
))) = E_Record_Subtype
);
6369 Set_Is_Dispatch_Table_Entity
(Etype
(Node
(Elmt
)));
6373 -- Aggregates initializing dispatch tables
6375 Elmt
:= First_Elmt
(DT_Aggr
);
6376 while Present
(Elmt
) loop
6377 Set_Is_Dispatch_Table_Entity
(Etype
(Node
(Elmt
)));
6385 -- Register the tagged type in the call graph nodes table
6387 Register_CG_Node
(Typ
);
6390 Restore_Ghost_Mode
(Saved_GM
);
6395 -------------------------------------
6396 -- Make_Select_Specific_Data_Table --
6397 -------------------------------------
6399 function Make_Select_Specific_Data_Table
6400 (Typ
: Entity_Id
) return List_Id
6402 Assignments
: constant List_Id
:= New_List
;
6403 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
6405 Conc_Typ
: Entity_Id
;
6406 Decls
: List_Id
:= No_List
;
6408 Prim_Als
: Entity_Id
;
6409 Prim_Elmt
: Elmt_Id
;
6413 type Examined_Array
is array (Int
range <>) of Boolean;
6415 function Find_Entry_Index
(E
: Entity_Id
) return Uint
;
6416 -- Given an entry, find its index in the visible declarations of the
6417 -- corresponding concurrent type of Typ.
6419 ----------------------
6420 -- Find_Entry_Index --
6421 ----------------------
6423 function Find_Entry_Index
(E
: Entity_Id
) return Uint
is
6424 Index
: Uint
:= Uint_1
;
6425 Subp_Decl
: Entity_Id
;
6429 and then not Is_Empty_List
(Decls
)
6431 Subp_Decl
:= First
(Decls
);
6432 while Present
(Subp_Decl
) loop
6433 if Nkind
(Subp_Decl
) = N_Entry_Declaration
then
6434 if Defining_Identifier
(Subp_Decl
) = E
then
6446 end Find_Entry_Index
;
6452 -- Start of processing for Make_Select_Specific_Data_Table
6455 pragma Assert
(not Restriction_Active
(No_Dispatching_Calls
));
6457 if Present
(Corresponding_Concurrent_Type
(Typ
)) then
6458 Conc_Typ
:= Corresponding_Concurrent_Type
(Typ
);
6460 if Present
(Full_View
(Conc_Typ
)) then
6461 Conc_Typ
:= Full_View
(Conc_Typ
);
6464 if Ekind
(Conc_Typ
) = E_Protected_Type
then
6465 Decls
:= Visible_Declarations
(Protected_Definition
(
6466 Parent
(Conc_Typ
)));
6468 pragma Assert
(Ekind
(Conc_Typ
) = E_Task_Type
);
6469 Decls
:= Visible_Declarations
(Task_Definition
(
6470 Parent
(Conc_Typ
)));
6474 -- Count the non-predefined primitive operations
6476 Prim_Elmt
:= First_Elmt
(Primitive_Operations
(Typ
));
6477 while Present
(Prim_Elmt
) loop
6478 Prim
:= Node
(Prim_Elmt
);
6480 if not (Is_Predefined_Dispatching_Operation
(Prim
)
6481 or else Is_Predefined_Dispatching_Alias
(Prim
))
6483 Nb_Prim
:= Nb_Prim
+ 1;
6486 Next_Elmt
(Prim_Elmt
);
6490 Examined
: Examined_Array
(1 .. Nb_Prim
) := (others => False);
6493 Prim_Elmt
:= First_Elmt
(Primitive_Operations
(Typ
));
6494 while Present
(Prim_Elmt
) loop
6495 Prim
:= Node
(Prim_Elmt
);
6497 -- Look for primitive overriding an abstract interface subprogram
6499 if Present
(Interface_Alias
(Prim
))
6502 (Find_Dispatching_Type
(Interface_Alias
(Prim
)), Typ
,
6503 Use_Full_View
=> True)
6504 and then not Examined
(UI_To_Int
(DT_Position
(Alias
(Prim
))))
6506 Prim_Pos
:= DT_Position
(Alias
(Prim
));
6507 pragma Assert
(UI_To_Int
(Prim_Pos
) <= Nb_Prim
);
6508 Examined
(UI_To_Int
(Prim_Pos
)) := True;
6510 -- Set the primitive operation kind regardless of subprogram
6512 -- Ada.Tags.Set_Prim_Op_Kind (DT_Ptr, <position>, <kind>);
6514 if Tagged_Type_Expansion
then
6517 (Node
(First_Elmt
(Access_Disp_Table
(Typ
))), Loc
);
6521 Make_Attribute_Reference
(Loc
,
6522 Prefix
=> New_Occurrence_Of
(Typ
, Loc
),
6523 Attribute_Name
=> Name_Tag
);
6526 Append_To
(Assignments
,
6527 Make_Procedure_Call_Statement
(Loc
,
6528 Name
=> New_Occurrence_Of
(RTE
(RE_Set_Prim_Op_Kind
), Loc
),
6529 Parameter_Associations
=> New_List
(
6531 Make_Integer_Literal
(Loc
, Prim_Pos
),
6532 Prim_Op_Kind
(Alias
(Prim
), Typ
))));
6534 -- Retrieve the root of the alias chain
6536 Prim_Als
:= Ultimate_Alias
(Prim
);
6538 -- In the case of an entry wrapper, set the entry index
6540 if Ekind
(Prim
) = E_Procedure
6541 and then Is_Primitive_Wrapper
(Prim_Als
)
6542 and then Ekind
(Wrapped_Entity
(Prim_Als
)) = E_Entry
6545 -- Ada.Tags.Set_Entry_Index
6546 -- (DT_Ptr, <position>, <index>);
6548 if Tagged_Type_Expansion
then
6551 (Node
(First_Elmt
(Access_Disp_Table
(Typ
))), Loc
);
6554 Make_Attribute_Reference
(Loc
,
6555 Prefix
=> New_Occurrence_Of
(Typ
, Loc
),
6556 Attribute_Name
=> Name_Tag
);
6559 Append_To
(Assignments
,
6560 Make_Procedure_Call_Statement
(Loc
,
6562 New_Occurrence_Of
(RTE
(RE_Set_Entry_Index
), Loc
),
6563 Parameter_Associations
=> New_List
(
6565 Make_Integer_Literal
(Loc
, Prim_Pos
),
6566 Make_Integer_Literal
(Loc
,
6567 Find_Entry_Index
(Wrapped_Entity
(Prim_Als
))))));
6571 Next_Elmt
(Prim_Elmt
);
6576 end Make_Select_Specific_Data_Table
;
6582 function Make_Tags
(Typ
: Entity_Id
) return List_Id
is
6583 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
6584 Result
: constant List_Id
:= New_List
;
6587 (Tag_Typ
: Entity_Id
;
6589 Is_Secondary_DT
: Boolean);
6590 -- Import the dispatch table DT of tagged type Tag_Typ. Required to
6591 -- generate forward references and statically allocate the table. For
6592 -- primary dispatch tables that require no dispatch table generate:
6594 -- DT : static aliased constant Non_Dispatch_Table_Wrapper;
6595 -- pragma Import (Ada, DT);
6597 -- Otherwise generate:
6599 -- DT : static aliased constant Dispatch_Table_Wrapper (Nb_Prim);
6600 -- pragma Import (Ada, DT);
6607 (Tag_Typ
: Entity_Id
;
6609 Is_Secondary_DT
: Boolean)
6611 DT_Constr_List
: List_Id
;
6615 Set_Is_Imported
(DT
);
6616 Set_Ekind
(DT
, E_Constant
);
6617 Set_Related_Type
(DT
, Typ
);
6619 -- The scope must be set now to call Get_External_Name
6621 Set_Scope
(DT
, Current_Scope
);
6623 Get_External_Name
(DT
);
6624 Set_Interface_Name
(DT
,
6625 Make_String_Literal
(Loc
, Strval
=> String_From_Name_Buffer
));
6627 -- Ensure proper Sprint output of this implicit importation
6629 Set_Is_Internal
(DT
);
6631 -- Save this entity to allow Make_DT to generate its exportation
6633 Append_Elmt
(DT
, Dispatch_Table_Wrappers
(Typ
));
6635 -- No dispatch table required
6637 if not Is_Secondary_DT
and then not Has_DT
(Tag_Typ
) then
6639 Make_Object_Declaration
(Loc
,
6640 Defining_Identifier
=> DT
,
6641 Aliased_Present
=> True,
6642 Constant_Present
=> True,
6643 Object_Definition
=>
6645 (RTE
(RE_No_Dispatch_Table_Wrapper
), Loc
)));
6648 -- Calculate the number of primitives of the dispatch table and
6649 -- the size of the Type_Specific_Data record.
6652 UI_To_Int
(DT_Entry_Count
(First_Tag_Component
(Tag_Typ
)));
6654 -- If the tagged type has no primitives we add a dummy slot whose
6655 -- address will be the tag of this type.
6659 New_List
(Make_Integer_Literal
(Loc
, 1));
6662 New_List
(Make_Integer_Literal
(Loc
, Nb_Prim
));
6666 Make_Object_Declaration
(Loc
,
6667 Defining_Identifier
=> DT
,
6668 Aliased_Present
=> True,
6669 Constant_Present
=> True,
6670 Object_Definition
=>
6671 Make_Subtype_Indication
(Loc
,
6673 New_Occurrence_Of
(RTE
(RE_Dispatch_Table_Wrapper
), Loc
),
6674 Constraint
=> Make_Index_Or_Discriminant_Constraint
(Loc
,
6675 Constraints
=> DT_Constr_List
))));
6681 Tname
: constant Name_Id
:= Chars
(Typ
);
6682 AI_Tag_Comp
: Elmt_Id
;
6683 DT
: Node_Id
:= Empty
;
6685 Predef_Prims_Ptr
: Node_Id
;
6686 Iface_DT
: Node_Id
:= Empty
;
6687 Iface_DT_Ptr
: Node_Id
;
6691 Typ_Comps
: Elist_Id
;
6693 -- Start of processing for Make_Tags
6696 pragma Assert
(No
(Access_Disp_Table
(Typ
)));
6697 Set_Access_Disp_Table
(Typ
, New_Elmt_List
);
6699 -- If the elaboration of this tagged type needs a boolean flag then
6700 -- define now its entity. It is initialized to True to indicate that
6701 -- elaboration is still pending; set to False by the IP routine.
6703 -- TypFxx : boolean := True;
6705 if Elab_Flag_Needed
(Typ
) then
6706 Set_Access_Disp_Table_Elab_Flag
(Typ
,
6707 Make_Defining_Identifier
(Loc
,
6708 Chars
=> New_External_Name
(Tname
, 'F')));
6711 Make_Object_Declaration
(Loc
,
6712 Defining_Identifier
=> Access_Disp_Table_Elab_Flag
(Typ
),
6713 Object_Definition
=> New_Occurrence_Of
(Standard_Boolean
, Loc
),
6714 Expression
=> New_Occurrence_Of
(Standard_True
, Loc
)));
6717 -- 1) Generate the primary tag entities
6719 -- Primary dispatch table containing user-defined primitives
6721 DT_Ptr
:= Make_Defining_Identifier
(Loc
, New_External_Name
(Tname
, 'P'));
6722 Set_Etype
(DT_Ptr
, RTE
(RE_Tag
));
6723 Append_Elmt
(DT_Ptr
, Access_Disp_Table
(Typ
));
6725 -- Minimum decoration
6727 Set_Ekind
(DT_Ptr
, E_Variable
);
6728 Set_Related_Type
(DT_Ptr
, Typ
);
6730 -- Notify back end that the types are associated with a dispatch table
6732 Set_Is_Dispatch_Table_Entity
(RTE
(RE_Prim_Ptr
));
6733 Set_Is_Dispatch_Table_Entity
(RTE
(RE_Predef_Prims_Table_Ptr
));
6735 -- For CPP types there is no need to build the dispatch tables since
6736 -- they are imported from the C++ side. If the CPP type has an IP then
6737 -- we declare now the variable that will store the copy of the C++ tag.
6738 -- If the CPP type is an interface, we need the variable as well because
6739 -- it becomes the pointer to the corresponding secondary table.
6741 if Is_CPP_Class
(Typ
) then
6742 if Has_CPP_Constructors
(Typ
) or else Is_Interface
(Typ
) then
6744 Make_Object_Declaration
(Loc
,
6745 Defining_Identifier
=> DT_Ptr
,
6746 Object_Definition
=> New_Occurrence_Of
(RTE
(RE_Tag
), Loc
),
6748 Unchecked_Convert_To
(RTE
(RE_Tag
),
6749 New_Occurrence_Of
(RTE
(RE_Null_Address
), Loc
))));
6751 Set_Is_Statically_Allocated
(DT_Ptr
,
6752 Is_Library_Level_Tagged_Type
(Typ
));
6758 -- Primary dispatch table containing predefined primitives
6761 Make_Defining_Identifier
(Loc
,
6762 Chars
=> New_External_Name
(Tname
, 'Y'));
6763 Set_Etype
(Predef_Prims_Ptr
, RTE
(RE_Address
));
6764 Append_Elmt
(Predef_Prims_Ptr
, Access_Disp_Table
(Typ
));
6766 -- Import the forward declaration of the Dispatch Table wrapper
6767 -- record (Make_DT will take care of exporting it).
6769 if Building_Static_DT
(Typ
) then
6770 Set_Dispatch_Table_Wrappers
(Typ
, New_Elmt_List
);
6773 Make_Defining_Identifier
(Loc
,
6774 Chars
=> New_External_Name
(Tname
, 'T'));
6776 Import_DT
(Typ
, DT
, Is_Secondary_DT
=> False);
6778 if Has_DT
(Typ
) then
6780 Make_Object_Declaration
(Loc
,
6781 Defining_Identifier
=> DT_Ptr
,
6782 Constant_Present
=> True,
6783 Object_Definition
=>
6784 New_Occurrence_Of
(RTE
(RE_Tag
), Loc
),
6786 Unchecked_Convert_To
(RTE
(RE_Tag
),
6787 Make_Attribute_Reference
(Loc
,
6789 Make_Selected_Component
(Loc
,
6790 Prefix
=> New_Occurrence_Of
(DT
, Loc
),
6793 (RTE_Record_Component
(RE_Prims_Ptr
), Loc
)),
6794 Attribute_Name
=> Name_Address
))));
6796 -- Generate the SCIL node for the previous object declaration
6797 -- because it has a tag initialization.
6799 if Generate_SCIL
then
6801 Make_SCIL_Dispatch_Table_Tag_Init
(Sloc
(Last
(Result
)));
6802 Set_SCIL_Entity
(New_Node
, Typ
);
6803 Set_SCIL_Node
(Last
(Result
), New_Node
);
6807 Make_Object_Declaration
(Loc
,
6808 Defining_Identifier
=> Predef_Prims_Ptr
,
6809 Constant_Present
=> True,
6810 Object_Definition
=>
6811 New_Occurrence_Of
(RTE
(RE_Address
), Loc
),
6813 Make_Attribute_Reference
(Loc
,
6815 Make_Selected_Component
(Loc
,
6816 Prefix
=> New_Occurrence_Of
(DT
, Loc
),
6819 (RTE_Record_Component
(RE_Predef_Prims
), Loc
)),
6820 Attribute_Name
=> Name_Address
)));
6822 -- No dispatch table required
6826 Make_Object_Declaration
(Loc
,
6827 Defining_Identifier
=> DT_Ptr
,
6828 Constant_Present
=> True,
6829 Object_Definition
=>
6830 New_Occurrence_Of
(RTE
(RE_Tag
), Loc
),
6832 Unchecked_Convert_To
(RTE
(RE_Tag
),
6833 Make_Attribute_Reference
(Loc
,
6835 Make_Selected_Component
(Loc
,
6836 Prefix
=> New_Occurrence_Of
(DT
, Loc
),
6839 (RTE_Record_Component
(RE_NDT_Prims_Ptr
),
6841 Attribute_Name
=> Name_Address
))));
6844 Set_Is_True_Constant
(DT_Ptr
);
6845 Set_Is_Statically_Allocated
(DT_Ptr
);
6849 -- 2) Generate the secondary tag entities
6851 -- Collect the components associated with secondary dispatch tables
6853 if Has_Interfaces
(Typ
) then
6854 Collect_Interface_Components
(Typ
, Typ_Comps
);
6856 -- For each interface type we build a unique external name associated
6857 -- with its secondary dispatch table. This name is used to declare an
6858 -- object that references this secondary dispatch table, whose value
6859 -- will be used for the elaboration of Typ objects, and also for the
6860 -- elaboration of objects of types derived from Typ that do not
6861 -- override the primitives of this interface type.
6865 -- Note: The value of Suffix_Index must be in sync with the values of
6866 -- Suffix_Index in secondary dispatch tables generated by Make_DT.
6868 if Is_CPP_Class
(Typ
) then
6869 AI_Tag_Comp
:= First_Elmt
(Typ_Comps
);
6870 while Present
(AI_Tag_Comp
) loop
6871 Get_Secondary_DT_External_Name
6872 (Typ
, Related_Type
(Node
(AI_Tag_Comp
)), Suffix_Index
);
6873 Typ_Name
:= Name_Find
;
6875 -- Declare variables to store copy of the C++ secondary tags
6878 Make_Defining_Identifier
(Loc
,
6879 Chars
=> New_External_Name
(Typ_Name
, 'P'));
6880 Set_Etype
(Iface_DT_Ptr
, RTE
(RE_Interface_Tag
));
6881 Set_Ekind
(Iface_DT_Ptr
, E_Variable
);
6882 Set_Is_Tag
(Iface_DT_Ptr
);
6884 Set_Has_Thunks
(Iface_DT_Ptr
);
6886 (Iface_DT_Ptr
, Related_Type
(Node
(AI_Tag_Comp
)));
6887 Append_Elmt
(Iface_DT_Ptr
, Access_Disp_Table
(Typ
));
6890 Make_Object_Declaration
(Loc
,
6891 Defining_Identifier
=> Iface_DT_Ptr
,
6892 Object_Definition
=> New_Occurrence_Of
6893 (RTE
(RE_Interface_Tag
), Loc
),
6895 Unchecked_Convert_To
(RTE
(RE_Interface_Tag
),
6896 New_Occurrence_Of
(RTE
(RE_Null_Address
), Loc
))));
6898 Set_Is_Statically_Allocated
(Iface_DT_Ptr
,
6899 Is_Library_Level_Tagged_Type
(Typ
));
6901 Next_Elmt
(AI_Tag_Comp
);
6904 -- This is not a CPP_Class type
6907 AI_Tag_Comp
:= First_Elmt
(Typ_Comps
);
6908 while Present
(AI_Tag_Comp
) loop
6909 Get_Secondary_DT_External_Name
6910 (Typ
, Related_Type
(Node
(AI_Tag_Comp
)), Suffix_Index
);
6911 Typ_Name
:= Name_Find
;
6913 if Building_Static_DT
(Typ
) then
6915 Make_Defining_Identifier
(Loc
,
6916 Chars
=> New_External_Name
(Typ_Name
, 'T'));
6918 (Tag_Typ
=> Related_Type
(Node
(AI_Tag_Comp
)),
6920 Is_Secondary_DT
=> True);
6923 -- Secondary dispatch table referencing thunks to user-defined
6924 -- primitives covered by this interface.
6927 Make_Defining_Identifier
(Loc
,
6928 Chars
=> New_External_Name
(Typ_Name
, 'P'));
6929 Set_Etype
(Iface_DT_Ptr
, RTE
(RE_Interface_Tag
));
6930 Set_Ekind
(Iface_DT_Ptr
, E_Constant
);
6931 Set_Is_Tag
(Iface_DT_Ptr
);
6932 Set_Has_Thunks
(Iface_DT_Ptr
);
6933 Set_Is_Statically_Allocated
(Iface_DT_Ptr
,
6934 Is_Library_Level_Tagged_Type
(Typ
));
6935 Set_Is_True_Constant
(Iface_DT_Ptr
);
6937 (Iface_DT_Ptr
, Related_Type
(Node
(AI_Tag_Comp
)));
6938 Append_Elmt
(Iface_DT_Ptr
, Access_Disp_Table
(Typ
));
6940 if Building_Static_DT
(Typ
) then
6942 Make_Object_Declaration
(Loc
,
6943 Defining_Identifier
=> Iface_DT_Ptr
,
6944 Constant_Present
=> True,
6945 Object_Definition
=> New_Occurrence_Of
6946 (RTE
(RE_Interface_Tag
), Loc
),
6948 Unchecked_Convert_To
(RTE
(RE_Interface_Tag
),
6949 Make_Attribute_Reference
(Loc
,
6951 Make_Selected_Component
(Loc
,
6953 New_Occurrence_Of
(Iface_DT
, Loc
),
6956 (RTE_Record_Component
(RE_Prims_Ptr
),
6958 Attribute_Name
=> Name_Address
))));
6961 -- Secondary dispatch table referencing thunks to predefined
6965 Make_Defining_Identifier
(Loc
,
6966 Chars
=> New_External_Name
(Typ_Name
, 'Y'));
6967 Set_Etype
(Iface_DT_Ptr
, RTE
(RE_Address
));
6968 Set_Ekind
(Iface_DT_Ptr
, E_Constant
);
6969 Set_Is_Tag
(Iface_DT_Ptr
);
6970 Set_Has_Thunks
(Iface_DT_Ptr
);
6971 Set_Is_Statically_Allocated
(Iface_DT_Ptr
,
6972 Is_Library_Level_Tagged_Type
(Typ
));
6973 Set_Is_True_Constant
(Iface_DT_Ptr
);
6975 (Iface_DT_Ptr
, Related_Type
(Node
(AI_Tag_Comp
)));
6976 Append_Elmt
(Iface_DT_Ptr
, Access_Disp_Table
(Typ
));
6978 -- Secondary dispatch table referencing user-defined primitives
6979 -- covered by this interface.
6982 Make_Defining_Identifier
(Loc
,
6983 Chars
=> New_External_Name
(Typ_Name
, 'D'));
6984 Set_Etype
(Iface_DT_Ptr
, RTE
(RE_Interface_Tag
));
6985 Set_Ekind
(Iface_DT_Ptr
, E_Constant
);
6986 Set_Is_Tag
(Iface_DT_Ptr
);
6987 Set_Is_Statically_Allocated
(Iface_DT_Ptr
,
6988 Is_Library_Level_Tagged_Type
(Typ
));
6989 Set_Is_True_Constant
(Iface_DT_Ptr
);
6991 (Iface_DT_Ptr
, Related_Type
(Node
(AI_Tag_Comp
)));
6992 Append_Elmt
(Iface_DT_Ptr
, Access_Disp_Table
(Typ
));
6994 -- Secondary dispatch table referencing predefined primitives
6997 Make_Defining_Identifier
(Loc
,
6998 Chars
=> New_External_Name
(Typ_Name
, 'Z'));
6999 Set_Etype
(Iface_DT_Ptr
, RTE
(RE_Address
));
7000 Set_Ekind
(Iface_DT_Ptr
, E_Constant
);
7001 Set_Is_Tag
(Iface_DT_Ptr
);
7002 Set_Is_Statically_Allocated
(Iface_DT_Ptr
,
7003 Is_Library_Level_Tagged_Type
(Typ
));
7004 Set_Is_True_Constant
(Iface_DT_Ptr
);
7006 (Iface_DT_Ptr
, Related_Type
(Node
(AI_Tag_Comp
)));
7007 Append_Elmt
(Iface_DT_Ptr
, Access_Disp_Table
(Typ
));
7009 Next_Elmt
(AI_Tag_Comp
);
7014 -- 3) At the end of Access_Disp_Table, if the type has user-defined
7015 -- primitives, we add the entity of an access type declaration that
7016 -- is used by Build_Get_Prim_Op_Address to expand dispatching calls
7017 -- through the primary dispatch table.
7019 if UI_To_Int
(DT_Entry_Count
(First_Tag_Component
(Typ
))) = 0 then
7020 Analyze_List
(Result
);
7023 -- type Typ_DT is array (1 .. Nb_Prims) of Prim_Ptr;
7024 -- type Typ_DT_Acc is access Typ_DT;
7028 Name_DT_Prims
: constant Name_Id
:=
7029 New_External_Name
(Tname
, 'G');
7030 Name_DT_Prims_Acc
: constant Name_Id
:=
7031 New_External_Name
(Tname
, 'H');
7032 DT_Prims
: constant Entity_Id
:=
7033 Make_Defining_Identifier
(Loc
,
7035 DT_Prims_Acc
: constant Entity_Id
:=
7036 Make_Defining_Identifier
(Loc
,
7040 Make_Full_Type_Declaration
(Loc
,
7041 Defining_Identifier
=> DT_Prims
,
7043 Make_Constrained_Array_Definition
(Loc
,
7044 Discrete_Subtype_Definitions
=> New_List
(
7046 Low_Bound
=> Make_Integer_Literal
(Loc
, 1),
7047 High_Bound
=> Make_Integer_Literal
(Loc
,
7049 (First_Tag_Component
(Typ
))))),
7050 Component_Definition
=>
7051 Make_Component_Definition
(Loc
,
7052 Subtype_Indication
=>
7053 New_Occurrence_Of
(RTE
(RE_Prim_Ptr
), Loc
)))));
7056 Make_Full_Type_Declaration
(Loc
,
7057 Defining_Identifier
=> DT_Prims_Acc
,
7059 Make_Access_To_Object_Definition
(Loc
,
7060 Subtype_Indication
=>
7061 New_Occurrence_Of
(DT_Prims
, Loc
))));
7063 Append_Elmt
(DT_Prims_Acc
, Access_Disp_Table
(Typ
));
7065 -- Analyze the resulting list and suppress the generation of the
7066 -- Init_Proc associated with the above array declaration because
7067 -- this type is never used in object declarations. It is only used
7068 -- to simplify the expansion associated with dispatching calls.
7070 Analyze_List
(Result
);
7071 Set_Suppress_Initialization
(Base_Type
(DT_Prims
));
7073 -- Disable backend optimizations based on assumptions about the
7074 -- aliasing status of objects designated by the access to the
7075 -- dispatch table. Required to handle dispatch tables imported
7078 Set_No_Strict_Aliasing
(Base_Type
(DT_Prims_Acc
));
7080 -- Add the freezing nodes of these declarations; required to avoid
7081 -- generating these freezing nodes in wrong scopes (for example in
7082 -- the IC routine of a derivation of Typ).
7084 -- What is an "IC routine"? Is "init_proc" meant here???
7086 Append_List_To
(Result
, Freeze_Entity
(DT_Prims
, Typ
));
7087 Append_List_To
(Result
, Freeze_Entity
(DT_Prims_Acc
, Typ
));
7089 -- Mark entity of dispatch table. Required by the back end to
7090 -- handle them properly.
7092 Set_Is_Dispatch_Table_Entity
(DT_Prims
);
7096 -- Mark entities of dispatch table. Required by the back end to handle
7099 if Present
(DT
) then
7100 Set_Is_Dispatch_Table_Entity
(DT
);
7101 Set_Is_Dispatch_Table_Entity
(Etype
(DT
));
7104 if Present
(Iface_DT
) then
7105 Set_Is_Dispatch_Table_Entity
(Iface_DT
);
7106 Set_Is_Dispatch_Table_Entity
(Etype
(Iface_DT
));
7109 if Is_CPP_Class
(Root_Type
(Typ
)) then
7110 Set_Ekind
(DT_Ptr
, E_Variable
);
7112 Set_Ekind
(DT_Ptr
, E_Constant
);
7115 Set_Is_Tag
(DT_Ptr
);
7116 Set_Related_Type
(DT_Ptr
, Typ
);
7125 function New_Value
(From
: Node_Id
) return Node_Id
is
7126 Res
: constant Node_Id
:= Duplicate_Subexpr
(From
);
7128 if Is_Access_Type
(Etype
(From
)) then
7129 return Make_Explicit_Dereference
(Sloc
(From
), Prefix
=> Res
);
7135 -----------------------------------
7136 -- Original_View_In_Visible_Part --
7137 -----------------------------------
7139 function Original_View_In_Visible_Part
(Typ
: Entity_Id
) return Boolean is
7140 Scop
: constant Entity_Id
:= Scope
(Typ
);
7143 -- The scope must be a package
7145 if not Is_Package_Or_Generic_Package
(Scop
) then
7149 -- A type with a private declaration has a private view declared in
7150 -- the visible part.
7152 if Has_Private_Declaration
(Typ
) then
7156 return List_Containing
(Parent
(Typ
)) =
7157 Visible_Declarations
(Package_Specification
(Scop
));
7158 end Original_View_In_Visible_Part
;
7164 function Prim_Op_Kind
7166 Typ
: Entity_Id
) return Node_Id
7168 Full_Typ
: Entity_Id
:= Typ
;
7169 Loc
: constant Source_Ptr
:= Sloc
(Prim
);
7170 Prim_Op
: Entity_Id
;
7173 -- Retrieve the original primitive operation
7175 Prim_Op
:= Ultimate_Alias
(Prim
);
7177 if Ekind
(Typ
) = E_Record_Type
7178 and then Present
(Corresponding_Concurrent_Type
(Typ
))
7180 Full_Typ
:= Corresponding_Concurrent_Type
(Typ
);
7183 -- When a private tagged type is completed by a concurrent type,
7184 -- retrieve the full view.
7186 if Is_Private_Type
(Full_Typ
) then
7187 Full_Typ
:= Full_View
(Full_Typ
);
7190 if Ekind
(Prim_Op
) = E_Function
then
7192 -- Protected function
7194 if Ekind
(Full_Typ
) = E_Protected_Type
then
7195 return New_Occurrence_Of
(RTE
(RE_POK_Protected_Function
), Loc
);
7199 elsif Ekind
(Full_Typ
) = E_Task_Type
then
7200 return New_Occurrence_Of
(RTE
(RE_POK_Task_Function
), Loc
);
7205 return New_Occurrence_Of
(RTE
(RE_POK_Function
), Loc
);
7209 pragma Assert
(Ekind
(Prim_Op
) = E_Procedure
);
7211 if Ekind
(Full_Typ
) = E_Protected_Type
then
7215 if Is_Primitive_Wrapper
(Prim_Op
)
7216 and then Ekind
(Wrapped_Entity
(Prim_Op
)) = E_Entry
7218 return New_Occurrence_Of
(RTE
(RE_POK_Protected_Entry
), Loc
);
7220 -- Protected procedure
7224 New_Occurrence_Of
(RTE
(RE_POK_Protected_Procedure
), Loc
);
7227 elsif Ekind
(Full_Typ
) = E_Task_Type
then
7231 if Is_Primitive_Wrapper
(Prim_Op
)
7232 and then Ekind
(Wrapped_Entity
(Prim_Op
)) = E_Entry
7234 return New_Occurrence_Of
(RTE
(RE_POK_Task_Entry
), Loc
);
7236 -- Task "procedure". These are the internally Expander-generated
7237 -- procedures (task body for instance).
7240 return New_Occurrence_Of
(RTE
(RE_POK_Task_Procedure
), Loc
);
7243 -- Regular procedure
7246 return New_Occurrence_Of
(RTE
(RE_POK_Procedure
), Loc
);
7251 ------------------------
7252 -- Register_Primitive --
7253 ------------------------
7255 function Register_Primitive
7257 Prim
: Entity_Id
) return List_Id
7260 Iface_Prim
: Entity_Id
;
7261 Iface_Typ
: Entity_Id
;
7262 Iface_DT_Ptr
: Entity_Id
;
7263 Iface_DT_Elmt
: Elmt_Id
;
7264 L
: constant List_Id
:= New_List
;
7267 Tag_Typ
: Entity_Id
;
7268 Thunk_Id
: Entity_Id
;
7269 Thunk_Code
: Node_Id
;
7272 pragma Assert
(not Restriction_Active
(No_Dispatching_Calls
));
7274 -- Do not register in the dispatch table eliminated primitives
7276 if not RTE_Available
(RE_Tag
)
7277 or else Is_Eliminated
(Ultimate_Alias
(Prim
))
7278 or else Generate_SCIL
7283 if not Present
(Interface_Alias
(Prim
)) then
7284 Tag_Typ
:= Scope
(DTC_Entity
(Prim
));
7285 Pos
:= DT_Position
(Prim
);
7286 Tag
:= First_Tag_Component
(Tag_Typ
);
7288 if Is_Predefined_Dispatching_Operation
(Prim
)
7289 or else Is_Predefined_Dispatching_Alias
(Prim
)
7292 Node
(Next_Elmt
(First_Elmt
(Access_Disp_Table
(Tag_Typ
))));
7295 Build_Set_Predefined_Prim_Op_Address
(Loc
,
7296 Tag_Node
=> New_Occurrence_Of
(DT_Ptr
, Loc
),
7299 Unchecked_Convert_To
(RTE
(RE_Prim_Ptr
),
7300 Make_Attribute_Reference
(Loc
,
7301 Prefix
=> New_Occurrence_Of
(Prim
, Loc
),
7302 Attribute_Name
=> Name_Unrestricted_Access
))));
7304 -- Register copy of the pointer to the 'size primitive in the TSD
7306 if Chars
(Prim
) = Name_uSize
7307 and then RTE_Record_Component_Available
(RE_Size_Func
)
7309 DT_Ptr
:= Node
(First_Elmt
(Access_Disp_Table
(Tag_Typ
)));
7311 Build_Set_Size_Function
(Loc
,
7312 Tag_Node
=> New_Occurrence_Of
(DT_Ptr
, Loc
),
7313 Size_Func
=> Prim
));
7317 pragma Assert
(Pos
/= Uint_0
and then Pos
<= DT_Entry_Count
(Tag
));
7319 -- Skip registration of primitives located in the C++ part of the
7320 -- dispatch table. Their slot is set by the IC routine.
7322 if not Is_CPP_Class
(Root_Type
(Tag_Typ
))
7323 or else Pos
> CPP_Num_Prims
(Tag_Typ
)
7325 DT_Ptr
:= Node
(First_Elmt
(Access_Disp_Table
(Tag_Typ
)));
7327 Build_Set_Prim_Op_Address
(Loc
,
7329 Tag_Node
=> New_Occurrence_Of
(DT_Ptr
, Loc
),
7332 Unchecked_Convert_To
(RTE
(RE_Prim_Ptr
),
7333 Make_Attribute_Reference
(Loc
,
7334 Prefix
=> New_Occurrence_Of
(Prim
, Loc
),
7335 Attribute_Name
=> Name_Unrestricted_Access
))));
7339 -- Ada 2005 (AI-251): Primitive associated with an interface type
7341 -- Generate the code of the thunk only if the interface type is not an
7342 -- immediate ancestor of Typ; otherwise the dispatch table associated
7343 -- with the interface is the primary dispatch table and we have nothing
7347 Tag_Typ
:= Find_Dispatching_Type
(Alias
(Prim
));
7348 Iface_Typ
:= Find_Dispatching_Type
(Interface_Alias
(Prim
));
7350 pragma Assert
(Is_Interface
(Iface_Typ
));
7352 -- No action needed for interfaces that are ancestors of Typ because
7353 -- their primitives are located in the primary dispatch table.
7355 if Is_Ancestor
(Iface_Typ
, Tag_Typ
, Use_Full_View
=> True) then
7358 -- No action needed for primitives located in the C++ part of the
7359 -- dispatch table. Their slot is set by the IC routine.
7361 elsif Is_CPP_Class
(Root_Type
(Tag_Typ
))
7362 and then DT_Position
(Alias
(Prim
)) <= CPP_Num_Prims
(Tag_Typ
)
7363 and then not Is_Predefined_Dispatching_Operation
(Prim
)
7364 and then not Is_Predefined_Dispatching_Alias
(Prim
)
7369 Expand_Interface_Thunk
(Prim
, Thunk_Id
, Thunk_Code
);
7371 if not Is_Ancestor
(Iface_Typ
, Tag_Typ
, Use_Full_View
=> True)
7372 and then Present
(Thunk_Code
)
7374 -- Generate the code necessary to fill the appropriate entry of
7375 -- the secondary dispatch table of Prim's controlling type with
7376 -- Thunk_Id's address.
7378 Iface_DT_Elmt
:= Find_Interface_ADT
(Tag_Typ
, Iface_Typ
);
7379 Iface_DT_Ptr
:= Node
(Iface_DT_Elmt
);
7380 pragma Assert
(Has_Thunks
(Iface_DT_Ptr
));
7382 Iface_Prim
:= Interface_Alias
(Prim
);
7383 Pos
:= DT_Position
(Iface_Prim
);
7384 Tag
:= First_Tag_Component
(Iface_Typ
);
7386 Prepend_To
(L
, Thunk_Code
);
7388 if Is_Predefined_Dispatching_Operation
(Prim
)
7389 or else Is_Predefined_Dispatching_Alias
(Prim
)
7392 Build_Set_Predefined_Prim_Op_Address
(Loc
,
7394 New_Occurrence_Of
(Node
(Next_Elmt
(Iface_DT_Elmt
)), Loc
),
7397 Unchecked_Convert_To
(RTE
(RE_Prim_Ptr
),
7398 Make_Attribute_Reference
(Loc
,
7399 Prefix
=> New_Occurrence_Of
(Thunk_Id
, Loc
),
7400 Attribute_Name
=> Name_Unrestricted_Access
))));
7402 Next_Elmt
(Iface_DT_Elmt
);
7403 Next_Elmt
(Iface_DT_Elmt
);
7404 Iface_DT_Ptr
:= Node
(Iface_DT_Elmt
);
7405 pragma Assert
(not Has_Thunks
(Iface_DT_Ptr
));
7408 Build_Set_Predefined_Prim_Op_Address
(Loc
,
7410 New_Occurrence_Of
(Node
(Next_Elmt
(Iface_DT_Elmt
)), Loc
),
7413 Unchecked_Convert_To
(RTE
(RE_Prim_Ptr
),
7414 Make_Attribute_Reference
(Loc
,
7416 New_Occurrence_Of
(Alias
(Prim
), Loc
),
7417 Attribute_Name
=> Name_Unrestricted_Access
))));
7420 pragma Assert
(Pos
/= Uint_0
7421 and then Pos
<= DT_Entry_Count
(Tag
));
7424 Build_Set_Prim_Op_Address
(Loc
,
7426 Tag_Node
=> New_Occurrence_Of
(Iface_DT_Ptr
, Loc
),
7429 Unchecked_Convert_To
(RTE
(RE_Prim_Ptr
),
7430 Make_Attribute_Reference
(Loc
,
7431 Prefix
=> New_Occurrence_Of
(Thunk_Id
, Loc
),
7432 Attribute_Name
=> Name_Unrestricted_Access
))));
7434 Next_Elmt
(Iface_DT_Elmt
);
7435 Next_Elmt
(Iface_DT_Elmt
);
7436 Iface_DT_Ptr
:= Node
(Iface_DT_Elmt
);
7437 pragma Assert
(not Has_Thunks
(Iface_DT_Ptr
));
7440 Build_Set_Prim_Op_Address
(Loc
,
7442 Tag_Node
=> New_Occurrence_Of
(Iface_DT_Ptr
, Loc
),
7445 Unchecked_Convert_To
(RTE
(RE_Prim_Ptr
),
7446 Make_Attribute_Reference
(Loc
,
7448 New_Occurrence_Of
(Alias
(Prim
), Loc
),
7449 Attribute_Name
=> Name_Unrestricted_Access
))));
7456 end Register_Primitive
;
7458 -------------------------
7459 -- Set_All_DT_Position --
7460 -------------------------
7462 procedure Set_All_DT_Position
(Typ
: Entity_Id
) is
7464 function In_Predef_Prims_DT
(Prim
: Entity_Id
) return Boolean;
7465 -- Returns True if Prim is located in the dispatch table of
7466 -- predefined primitives
7468 procedure Validate_Position
(Prim
: Entity_Id
);
7469 -- Check that position assigned to Prim is completely safe (it has not
7470 -- been assigned to a previously defined primitive operation of Typ).
7472 ------------------------
7473 -- In_Predef_Prims_DT --
7474 ------------------------
7476 function In_Predef_Prims_DT
(Prim
: Entity_Id
) return Boolean is
7478 -- Predefined primitives
7480 if Is_Predefined_Dispatching_Operation
(Prim
) then
7483 -- Renamings of predefined primitives
7485 elsif Present
(Alias
(Prim
))
7486 and then Is_Predefined_Dispatching_Operation
(Ultimate_Alias
(Prim
))
7488 if Chars
(Ultimate_Alias
(Prim
)) /= Name_Op_Eq
then
7491 -- An overriding operation that is a user-defined renaming of
7492 -- predefined equality inherits its slot from the overridden
7493 -- operation. Otherwise it is treated as a predefined op and
7494 -- occupies the same predefined slot as equality. A call to it is
7495 -- transformed into a call to its alias, which is the predefined
7496 -- equality op. A dispatching call thus uses the proper slot if
7497 -- operation is further inherited and called with class-wide
7502 not Comes_From_Source
(Prim
)
7503 or else No
(Overridden_Operation
(Prim
));
7506 -- User-defined primitives
7511 end In_Predef_Prims_DT
;
7513 -----------------------
7514 -- Validate_Position --
7515 -----------------------
7517 procedure Validate_Position
(Prim
: Entity_Id
) is
7522 -- Aliased primitives are safe
7524 if Present
(Alias
(Prim
)) then
7528 Op_Elmt
:= First_Elmt
(Primitive_Operations
(Typ
));
7529 while Present
(Op_Elmt
) loop
7530 Op
:= Node
(Op_Elmt
);
7532 -- No need to check against itself
7537 -- Primitive operations covering abstract interfaces are
7540 elsif Present
(Interface_Alias
(Op
)) then
7543 -- Predefined dispatching operations are completely safe. They
7544 -- are allocated at fixed positions in a separate table.
7546 elsif Is_Predefined_Dispatching_Operation
(Op
)
7547 or else Is_Predefined_Dispatching_Alias
(Op
)
7551 -- Aliased subprograms are safe
7553 elsif Present
(Alias
(Op
)) then
7556 elsif DT_Position
(Op
) = DT_Position
(Prim
)
7557 and then not Is_Predefined_Dispatching_Operation
(Op
)
7558 and then not Is_Predefined_Dispatching_Operation
(Prim
)
7559 and then not Is_Predefined_Dispatching_Alias
(Op
)
7560 and then not Is_Predefined_Dispatching_Alias
(Prim
)
7562 -- Handle aliased subprograms
7571 if Present
(Overridden_Operation
(Op_1
)) then
7572 Op_1
:= Overridden_Operation
(Op_1
);
7573 elsif Present
(Alias
(Op_1
)) then
7574 Op_1
:= Alias
(Op_1
);
7582 if Present
(Overridden_Operation
(Op_2
)) then
7583 Op_2
:= Overridden_Operation
(Op_2
);
7584 elsif Present
(Alias
(Op_2
)) then
7585 Op_2
:= Alias
(Op_2
);
7591 if Op_1
/= Op_2
then
7592 raise Program_Error
;
7597 Next_Elmt
(Op_Elmt
);
7599 end Validate_Position
;
7603 Parent_Typ
: constant Entity_Id
:= Etype
(Typ
);
7604 First_Prim
: constant Elmt_Id
:= First_Elmt
(Primitive_Operations
(Typ
));
7605 The_Tag
: constant Entity_Id
:= First_Tag_Component
(Typ
);
7607 Adjusted
: Boolean := False;
7608 Finalized
: Boolean := False;
7614 Prim_Elmt
: Elmt_Id
;
7616 -- Start of processing for Set_All_DT_Position
7619 pragma Assert
(Present
(First_Tag_Component
(Typ
)));
7621 -- Set the DT_Position for each primitive operation. Perform some sanity
7622 -- checks to avoid building inconsistent dispatch tables.
7624 -- First stage: Set DTC entity of all the primitive operations. This is
7625 -- required to properly read the DT_Position attribute in latter stages.
7627 Prim_Elmt
:= First_Prim
;
7629 while Present
(Prim_Elmt
) loop
7630 Prim
:= Node
(Prim_Elmt
);
7632 -- Predefined primitives have a separate dispatch table
7634 if not In_Predef_Prims_DT
(Prim
) then
7635 Count_Prim
:= Count_Prim
+ 1;
7638 Set_DTC_Entity_Value
(Typ
, Prim
);
7640 -- Clear any previous value of the DT_Position attribute. In this
7641 -- way we ensure that the final position of all the primitives is
7642 -- established by the following stages of this algorithm.
7644 Set_DT_Position_Value
(Prim
, No_Uint
);
7646 Next_Elmt
(Prim_Elmt
);
7650 Fixed_Prim
: array (Int
range 0 .. Count_Prim
) of Boolean :=
7655 procedure Handle_Inherited_Private_Subprograms
(Typ
: Entity_Id
);
7656 -- Called if Typ is declared in a nested package or a public child
7657 -- package to handle inherited primitives that were inherited by Typ
7658 -- in the visible part, but whose declaration was deferred because
7659 -- the parent operation was private and not visible at that point.
7661 procedure Set_Fixed_Prim
(Pos
: Nat
);
7662 -- Sets to true an element of the Fixed_Prim table to indicate
7663 -- that this entry of the dispatch table of Typ is occupied.
7665 ------------------------------------------
7666 -- Handle_Inherited_Private_Subprograms --
7667 ------------------------------------------
7669 procedure Handle_Inherited_Private_Subprograms
(Typ
: Entity_Id
) is
7672 Op_Elmt_2
: Elmt_Id
;
7673 Prim_Op
: Entity_Id
;
7674 Parent_Subp
: Entity_Id
;
7677 Op_List
:= Primitive_Operations
(Typ
);
7679 Op_Elmt
:= First_Elmt
(Op_List
);
7680 while Present
(Op_Elmt
) loop
7681 Prim_Op
:= Node
(Op_Elmt
);
7683 -- Search primitives that are implicit operations with an
7684 -- internal name whose parent operation has a normal name.
7686 if Present
(Alias
(Prim_Op
))
7687 and then Find_Dispatching_Type
(Alias
(Prim_Op
)) /= Typ
7688 and then not Comes_From_Source
(Prim_Op
)
7689 and then Is_Internal_Name
(Chars
(Prim_Op
))
7690 and then not Is_Internal_Name
(Chars
(Alias
(Prim_Op
)))
7692 Parent_Subp
:= Alias
(Prim_Op
);
7694 -- Check if the type has an explicit overriding for this
7697 Op_Elmt_2
:= Next_Elmt
(Op_Elmt
);
7698 while Present
(Op_Elmt_2
) loop
7699 if Chars
(Node
(Op_Elmt_2
)) = Chars
(Parent_Subp
)
7700 and then Type_Conformant
(Prim_Op
, Node
(Op_Elmt_2
))
7702 Set_DT_Position_Value
(Prim_Op
,
7703 DT_Position
(Parent_Subp
));
7704 Set_DT_Position_Value
(Node
(Op_Elmt_2
),
7705 DT_Position
(Parent_Subp
));
7706 Set_Fixed_Prim
(UI_To_Int
(DT_Position
(Prim_Op
)));
7708 goto Next_Primitive
;
7711 Next_Elmt
(Op_Elmt_2
);
7716 Next_Elmt
(Op_Elmt
);
7718 end Handle_Inherited_Private_Subprograms
;
7720 --------------------
7721 -- Set_Fixed_Prim --
7722 --------------------
7724 procedure Set_Fixed_Prim
(Pos
: Nat
) is
7726 pragma Assert
(Pos
<= Count_Prim
);
7727 Fixed_Prim
(Pos
) := True;
7729 when Constraint_Error
=>
7730 raise Program_Error
;
7734 -- In case of nested packages and public child package it may be
7735 -- necessary a special management on inherited subprograms so that
7736 -- the dispatch table is properly filled.
7738 if Ekind
(Scope
(Scope
(Typ
))) = E_Package
7739 and then Scope
(Scope
(Typ
)) /= Standard_Standard
7740 and then ((Is_Derived_Type
(Typ
) and then not Is_Private_Type
(Typ
))
7742 (Nkind
(Parent
(Typ
)) = N_Private_Extension_Declaration
7743 and then Is_Generic_Type
(Typ
)))
7744 and then In_Open_Scopes
(Scope
(Etype
(Typ
)))
7745 and then Is_Base_Type
(Typ
)
7747 Handle_Inherited_Private_Subprograms
(Typ
);
7750 -- Second stage: Register fixed entries
7753 Prim_Elmt
:= First_Prim
;
7754 while Present
(Prim_Elmt
) loop
7755 Prim
:= Node
(Prim_Elmt
);
7757 -- Predefined primitives have a separate table and all its
7758 -- entries are at predefined fixed positions.
7760 if In_Predef_Prims_DT
(Prim
) then
7761 if Is_Predefined_Dispatching_Operation
(Prim
) then
7762 Set_DT_Position_Value
(Prim
,
7763 Default_Prim_Op_Position
(Prim
));
7765 else pragma Assert
(Present
(Alias
(Prim
)));
7766 Set_DT_Position_Value
(Prim
,
7767 Default_Prim_Op_Position
(Ultimate_Alias
(Prim
)));
7770 -- Overriding primitives of ancestor abstract interfaces
7772 elsif Present
(Interface_Alias
(Prim
))
7773 and then Is_Ancestor
7774 (Find_Dispatching_Type
(Interface_Alias
(Prim
)), Typ
,
7775 Use_Full_View
=> True)
7777 pragma Assert
(DT_Position
(Prim
) = No_Uint
7778 and then Present
(DTC_Entity
(Interface_Alias
(Prim
))));
7780 E
:= Interface_Alias
(Prim
);
7781 Set_DT_Position_Value
(Prim
, DT_Position
(E
));
7784 (DT_Position
(Alias
(Prim
)) = No_Uint
7785 or else DT_Position
(Alias
(Prim
)) = DT_Position
(E
));
7786 Set_DT_Position_Value
(Alias
(Prim
), DT_Position
(E
));
7787 Set_Fixed_Prim
(UI_To_Int
(DT_Position
(Prim
)));
7789 -- Overriding primitives must use the same entry as the overridden
7790 -- primitive. Note that the Alias of the operation is set when the
7791 -- operation is declared by a renaming, in which case it is not
7792 -- overriding. If it renames another primitive it will use the
7793 -- same dispatch table slot, but if it renames an operation in a
7794 -- nested package it's a new primitive and will have its own slot.
7796 elsif not Present
(Interface_Alias
(Prim
))
7797 and then Present
(Alias
(Prim
))
7798 and then Chars
(Prim
) = Chars
(Alias
(Prim
))
7799 and then Nkind
(Unit_Declaration_Node
(Prim
)) /=
7800 N_Subprogram_Renaming_Declaration
7803 Par_Type
: constant Entity_Id
:=
7804 Find_Dispatching_Type
(Alias
(Prim
));
7807 if Present
(Par_Type
)
7808 and then Par_Type
/= Typ
7809 and then Is_Ancestor
(Par_Type
, Typ
, Use_Full_View
=> True)
7810 and then Present
(DTC_Entity
(Alias
(Prim
)))
7813 Set_DT_Position_Value
(Prim
, DT_Position
(E
));
7815 if not Is_Predefined_Dispatching_Alias
(E
) then
7816 Set_Fixed_Prim
(UI_To_Int
(DT_Position
(E
)));
7822 Next_Elmt
(Prim_Elmt
);
7825 -- Third stage: Fix the position of all the new primitives. Entries
7826 -- associated with primitives covering interfaces are handled in a
7829 Prim_Elmt
:= First_Prim
;
7830 while Present
(Prim_Elmt
) loop
7831 Prim
:= Node
(Prim_Elmt
);
7833 -- Skip primitives previously set entries
7835 if DT_Position
(Prim
) /= No_Uint
then
7838 -- Primitives covering interface primitives are handled later
7840 elsif Present
(Interface_Alias
(Prim
)) then
7844 -- Take the next available position in the DT
7847 Nb_Prim
:= Nb_Prim
+ 1;
7848 pragma Assert
(Nb_Prim
<= Count_Prim
);
7849 exit when not Fixed_Prim
(Nb_Prim
);
7852 Set_DT_Position_Value
(Prim
, UI_From_Int
(Nb_Prim
));
7853 Set_Fixed_Prim
(Nb_Prim
);
7856 Next_Elmt
(Prim_Elmt
);
7860 -- Fourth stage: Complete the decoration of primitives covering
7861 -- interfaces (that is, propagate the DT_Position attribute from
7862 -- the aliased primitive)
7864 Prim_Elmt
:= First_Prim
;
7865 while Present
(Prim_Elmt
) loop
7866 Prim
:= Node
(Prim_Elmt
);
7868 if DT_Position
(Prim
) = No_Uint
7869 and then Present
(Interface_Alias
(Prim
))
7871 pragma Assert
(Present
(Alias
(Prim
))
7872 and then Find_Dispatching_Type
(Alias
(Prim
)) = Typ
);
7874 -- Check if this entry will be placed in the primary DT
7877 (Find_Dispatching_Type
(Interface_Alias
(Prim
)), Typ
,
7878 Use_Full_View
=> True)
7880 pragma Assert
(DT_Position
(Alias
(Prim
)) /= No_Uint
);
7881 Set_DT_Position_Value
(Prim
, DT_Position
(Alias
(Prim
)));
7883 -- Otherwise it will be placed in the secondary DT
7887 (DT_Position
(Interface_Alias
(Prim
)) /= No_Uint
);
7888 Set_DT_Position_Value
(Prim
,
7889 DT_Position
(Interface_Alias
(Prim
)));
7893 Next_Elmt
(Prim_Elmt
);
7896 -- Generate listing showing the contents of the dispatch tables. This
7897 -- action is done before some further static checks because in case of
7898 -- critical errors caused by a wrong dispatch table we need to see the
7899 -- contents of such table.
7901 if Debug_Flag_ZZ
then
7905 -- Final stage: Ensure that the table is correct plus some further
7906 -- verifications concerning the primitives.
7908 Prim_Elmt
:= First_Prim
;
7910 while Present
(Prim_Elmt
) loop
7911 Prim
:= Node
(Prim_Elmt
);
7913 -- At this point all the primitives MUST have a position in the
7916 if DT_Position
(Prim
) = No_Uint
then
7917 raise Program_Error
;
7920 -- Calculate real size of the dispatch table
7922 if not In_Predef_Prims_DT
(Prim
)
7923 and then UI_To_Int
(DT_Position
(Prim
)) > DT_Length
7925 DT_Length
:= UI_To_Int
(DT_Position
(Prim
));
7928 -- Ensure that the assigned position to non-predefined dispatching
7929 -- operations in the dispatch table is correct.
7931 if not Is_Predefined_Dispatching_Operation
(Prim
)
7932 and then not Is_Predefined_Dispatching_Alias
(Prim
)
7934 Validate_Position
(Prim
);
7937 if Chars
(Prim
) = Name_Finalize
then
7941 if Chars
(Prim
) = Name_Adjust
then
7945 -- An abstract operation cannot be declared in the private part for a
7946 -- visible abstract type, because it can't be overridden outside this
7947 -- package hierarchy. For explicit declarations this is checked at
7948 -- the point of declaration, but for inherited operations it must be
7949 -- done when building the dispatch table.
7951 -- Ada 2005 (AI-251): Primitives associated with interfaces are
7952 -- excluded from this check because interfaces must be visible in
7953 -- the public and private part (RM 7.3 (7.3/2))
7955 -- We disable this check in Relaxed_RM_Semantics mode, to accommodate
7958 if not Relaxed_RM_Semantics
7959 and then Is_Abstract_Type
(Typ
)
7960 and then Is_Abstract_Subprogram
(Prim
)
7961 and then Present
(Alias
(Prim
))
7962 and then not Is_Interface
7963 (Find_Dispatching_Type
(Ultimate_Alias
(Prim
)))
7964 and then not Present
(Interface_Alias
(Prim
))
7965 and then Is_Derived_Type
(Typ
)
7966 and then In_Private_Part
(Current_Scope
)
7968 List_Containing
(Parent
(Prim
)) =
7969 Private_Declarations
(Package_Specification
(Current_Scope
))
7970 and then Original_View_In_Visible_Part
(Typ
)
7972 -- We exclude Input and Output stream operations because
7973 -- Limited_Controlled inherits useless Input and Output stream
7974 -- operations from Root_Controlled, which can never be overridden.
7976 if not Is_TSS
(Prim
, TSS_Stream_Input
)
7978 not Is_TSS
(Prim
, TSS_Stream_Output
)
7981 ("abstract inherited private operation&" &
7982 " must be overridden (RM 3.9.3(10))",
7983 Parent
(Typ
), Prim
);
7987 Next_Elmt
(Prim_Elmt
);
7992 if Is_Controlled
(Typ
) then
7993 if not Finalized
then
7995 ("controlled type has no explicit Finalize method??", Typ
);
7997 elsif not Adjusted
then
7999 ("controlled type has no explicit Adjust method??", Typ
);
8003 -- Set the final size of the Dispatch Table
8005 Set_DT_Entry_Count
(The_Tag
, UI_From_Int
(DT_Length
));
8007 -- The derived type must have at least as many components as its parent
8008 -- (for root types Etype points to itself and the test cannot fail).
8010 if DT_Entry_Count
(The_Tag
) <
8011 DT_Entry_Count
(First_Tag_Component
(Parent_Typ
))
8013 raise Program_Error
;
8015 end Set_All_DT_Position
;
8017 --------------------------
8018 -- Set_CPP_Constructors --
8019 --------------------------
8021 procedure Set_CPP_Constructors
(Typ
: Entity_Id
) is
8023 function Gen_Parameters_Profile
(E
: Entity_Id
) return List_Id
;
8024 -- Duplicate the parameters profile of the imported C++ constructor
8025 -- adding an access to the object as an additional parameter.
8027 ----------------------------
8028 -- Gen_Parameters_Profile --
8029 ----------------------------
8031 function Gen_Parameters_Profile
(E
: Entity_Id
) return List_Id
is
8032 Loc
: constant Source_Ptr
:= Sloc
(E
);
8039 Make_Parameter_Specification
(Loc
,
8040 Defining_Identifier
=>
8041 Make_Defining_Identifier
(Loc
, Name_uInit
),
8042 Parameter_Type
=> New_Occurrence_Of
(Typ
, Loc
)));
8044 if Present
(Parameter_Specifications
(Parent
(E
))) then
8045 P
:= First
(Parameter_Specifications
(Parent
(E
)));
8046 while Present
(P
) loop
8048 Make_Parameter_Specification
(Loc
,
8049 Defining_Identifier
=>
8050 Make_Defining_Identifier
(Loc
,
8051 Chars
=> Chars
(Defining_Identifier
(P
))),
8052 Parameter_Type
=> New_Copy_Tree
(Parameter_Type
(P
)),
8053 Expression
=> New_Copy_Tree
(Expression
(P
))));
8059 end Gen_Parameters_Profile
;
8065 Found
: Boolean := False;
8071 Covers_Default_Constructor
: Entity_Id
:= Empty
;
8073 -- Start of processing for Set_CPP_Constructor
8076 pragma Assert
(Is_CPP_Class
(Typ
));
8078 -- Look for the constructor entities
8080 E
:= Next_Entity
(Typ
);
8081 while Present
(E
) loop
8082 if Ekind
(E
) = E_Function
8083 and then Is_Constructor
(E
)
8087 Parms
:= Gen_Parameters_Profile
(E
);
8089 Make_Defining_Identifier
(Loc
,
8090 Chars
=> Make_Init_Proc_Name
(Typ
));
8092 -- Case 1: Constructor of untagged type
8094 -- If the C++ class has no virtual methods then the matching Ada
8095 -- type is an untagged record type. In such case there is no need
8096 -- to generate a wrapper of the C++ constructor because the _tag
8097 -- component is not available.
8099 if not Is_Tagged_Type
(Typ
) then
8101 (Make_Subprogram_Declaration
(Loc
,
8103 Make_Procedure_Specification
(Loc
,
8104 Defining_Unit_Name
=> IP
,
8105 Parameter_Specifications
=> Parms
)));
8107 Set_Init_Proc
(Typ
, IP
);
8108 Set_Is_Imported
(IP
);
8109 Set_Is_Constructor
(IP
);
8110 Set_Interface_Name
(IP
, Interface_Name
(E
));
8111 Set_Convention
(IP
, Convention_CPP
);
8113 Set_Has_Completion
(IP
);
8115 -- Case 2: Constructor of a tagged type
8117 -- In this case we generate the IP as a wrapper of the the
8118 -- C++ constructor because IP must also save copy of the _tag
8119 -- generated in the C++ side. The copy of the _tag is used by
8120 -- Build_CPP_Init_Procedure to elaborate derivations of C++ types.
8123 -- procedure IP (_init : Typ; ...) is
8124 -- procedure ConstructorP (_init : Typ; ...);
8125 -- pragma Import (ConstructorP);
8127 -- ConstructorP (_init, ...);
8128 -- if Typ._tag = null then
8129 -- Typ._tag := _init._tag;
8135 Body_Stmts
: constant List_Id
:= New_List
;
8136 Constructor_Id
: Entity_Id
;
8137 Constructor_Decl_Node
: Node_Id
;
8138 Init_Tags_List
: List_Id
;
8141 Constructor_Id
:= Make_Temporary
(Loc
, 'P');
8143 Constructor_Decl_Node
:=
8144 Make_Subprogram_Declaration
(Loc
,
8145 Make_Procedure_Specification
(Loc
,
8146 Defining_Unit_Name
=> Constructor_Id
,
8147 Parameter_Specifications
=> Parms
));
8149 Set_Is_Imported
(Constructor_Id
);
8150 Set_Is_Constructor
(Constructor_Id
);
8151 Set_Interface_Name
(Constructor_Id
, Interface_Name
(E
));
8152 Set_Convention
(Constructor_Id
, Convention_CPP
);
8153 Set_Is_Public
(Constructor_Id
);
8154 Set_Has_Completion
(Constructor_Id
);
8156 -- Build the init procedure as a wrapper of this constructor
8158 Parms
:= Gen_Parameters_Profile
(E
);
8160 -- Invoke the C++ constructor
8163 Actuals
: constant List_Id
:= New_List
;
8167 while Present
(P
) loop
8169 New_Occurrence_Of
(Defining_Identifier
(P
), Loc
));
8173 Append_To
(Body_Stmts
,
8174 Make_Procedure_Call_Statement
(Loc
,
8175 Name
=> New_Occurrence_Of
(Constructor_Id
, Loc
),
8176 Parameter_Associations
=> Actuals
));
8179 -- Initialize copies of C++ primary and secondary tags
8181 Init_Tags_List
:= New_List
;
8188 Tag_Elmt
:= First_Elmt
(Access_Disp_Table
(Typ
));
8189 Tag_Comp
:= First_Tag_Component
(Typ
);
8191 while Present
(Tag_Elmt
)
8192 and then Is_Tag
(Node
(Tag_Elmt
))
8194 -- Skip the following assertion with primary tags
8195 -- because Related_Type is not set on primary tag
8199 (Tag_Comp
= First_Tag_Component
(Typ
)
8200 or else Related_Type
(Node
(Tag_Elmt
))
8201 = Related_Type
(Tag_Comp
));
8203 Append_To
(Init_Tags_List
,
8204 Make_Assignment_Statement
(Loc
,
8206 New_Occurrence_Of
(Node
(Tag_Elmt
), Loc
),
8208 Make_Selected_Component
(Loc
,
8210 Make_Identifier
(Loc
, Name_uInit
),
8212 New_Occurrence_Of
(Tag_Comp
, Loc
))));
8214 Tag_Comp
:= Next_Tag_Component
(Tag_Comp
);
8215 Next_Elmt
(Tag_Elmt
);
8219 Append_To
(Body_Stmts
,
8220 Make_If_Statement
(Loc
,
8225 (Node
(First_Elmt
(Access_Disp_Table
(Typ
))),
8228 Unchecked_Convert_To
(RTE
(RE_Tag
),
8229 New_Occurrence_Of
(RTE
(RE_Null_Address
), Loc
))),
8230 Then_Statements
=> Init_Tags_List
));
8233 Make_Subprogram_Body
(Loc
,
8235 Make_Procedure_Specification
(Loc
,
8236 Defining_Unit_Name
=> IP
,
8237 Parameter_Specifications
=> Parms
),
8238 Declarations
=> New_List
(Constructor_Decl_Node
),
8239 Handled_Statement_Sequence
=>
8240 Make_Handled_Sequence_Of_Statements
(Loc
,
8241 Statements
=> Body_Stmts
,
8242 Exception_Handlers
=> No_List
));
8244 Discard_Node
(IP_Body
);
8245 Set_Init_Proc
(Typ
, IP
);
8249 -- If this constructor has parameters and all its parameters have
8250 -- defaults then it covers the default constructor. The semantic
8251 -- analyzer ensures that only one constructor with defaults covers
8252 -- the default constructor.
8254 if Present
(Parameter_Specifications
(Parent
(E
)))
8255 and then Needs_No_Actuals
(E
)
8257 Covers_Default_Constructor
:= IP
;
8264 -- If there are no constructors, mark the type as abstract since we
8265 -- won't be able to declare objects of that type.
8268 Set_Is_Abstract_Type
(Typ
);
8271 -- Handle constructor that has all its parameters with defaults and
8272 -- hence it covers the default constructor. We generate a wrapper IP
8273 -- which calls the covering constructor.
8275 if Present
(Covers_Default_Constructor
) then
8277 Body_Stmts
: List_Id
;
8280 Loc
:= Sloc
(Covers_Default_Constructor
);
8282 Body_Stmts
:= New_List
(
8283 Make_Procedure_Call_Statement
(Loc
,
8285 New_Occurrence_Of
(Covers_Default_Constructor
, Loc
),
8286 Parameter_Associations
=> New_List
(
8287 Make_Identifier
(Loc
, Name_uInit
))));
8289 IP
:= Make_Defining_Identifier
(Loc
, Make_Init_Proc_Name
(Typ
));
8292 Make_Subprogram_Body
(Loc
,
8294 Make_Procedure_Specification
(Loc
,
8295 Defining_Unit_Name
=> IP
,
8296 Parameter_Specifications
=> New_List
(
8297 Make_Parameter_Specification
(Loc
,
8298 Defining_Identifier
=>
8299 Make_Defining_Identifier
(Loc
, Name_uInit
),
8300 Parameter_Type
=> New_Occurrence_Of
(Typ
, Loc
)))),
8302 Declarations
=> No_List
,
8304 Handled_Statement_Sequence
=>
8305 Make_Handled_Sequence_Of_Statements
(Loc
,
8306 Statements
=> Body_Stmts
,
8307 Exception_Handlers
=> No_List
));
8309 Discard_Node
(IP_Body
);
8310 Set_Init_Proc
(Typ
, IP
);
8314 -- If the CPP type has constructors then it must import also the default
8315 -- C++ constructor. It is required for default initialization of objects
8316 -- of the type. It is also required to elaborate objects of Ada types
8317 -- that are defined as derivations of this CPP type.
8319 if Has_CPP_Constructors
(Typ
)
8320 and then No
(Init_Proc
(Typ
))
8322 Error_Msg_N
("??default constructor must be imported from C++", Typ
);
8324 end Set_CPP_Constructors
;
8326 ---------------------------
8327 -- Set_DT_Position_Value --
8328 ---------------------------
8330 procedure Set_DT_Position_Value
(Prim
: Entity_Id
; Value
: Uint
) is
8332 Set_DT_Position
(Prim
, Value
);
8334 -- Propagate the value to the wrapped subprogram (if one is present)
8336 if Ekind_In
(Prim
, E_Function
, E_Procedure
)
8337 and then Is_Primitive_Wrapper
(Prim
)
8338 and then Present
(Wrapped_Entity
(Prim
))
8339 and then Is_Dispatching_Operation
(Wrapped_Entity
(Prim
))
8341 Set_DT_Position
(Wrapped_Entity
(Prim
), Value
);
8343 end Set_DT_Position_Value
;
8345 --------------------------
8346 -- Set_DTC_Entity_Value --
8347 --------------------------
8349 procedure Set_DTC_Entity_Value
8350 (Tagged_Type
: Entity_Id
;
8354 if Present
(Interface_Alias
(Prim
))
8355 and then Is_Interface
8356 (Find_Dispatching_Type
(Interface_Alias
(Prim
)))
8358 Set_DTC_Entity
(Prim
,
8361 Iface
=> Find_Dispatching_Type
(Interface_Alias
(Prim
))));
8363 Set_DTC_Entity
(Prim
,
8364 First_Tag_Component
(Tagged_Type
));
8367 -- Propagate the value to the wrapped subprogram (if one is present)
8369 if Ekind_In
(Prim
, E_Function
, E_Procedure
)
8370 and then Is_Primitive_Wrapper
(Prim
)
8371 and then Present
(Wrapped_Entity
(Prim
))
8372 and then Is_Dispatching_Operation
(Wrapped_Entity
(Prim
))
8374 Set_DTC_Entity
(Wrapped_Entity
(Prim
), DTC_Entity
(Prim
));
8376 end Set_DTC_Entity_Value
;
8382 function Tagged_Kind
(T
: Entity_Id
) return Node_Id
is
8383 Conc_Typ
: Entity_Id
;
8384 Loc
: constant Source_Ptr
:= Sloc
(T
);
8388 (Is_Tagged_Type
(T
) and then RTE_Available
(RE_Tagged_Kind
));
8392 if Is_Abstract_Type
(T
) then
8393 if Is_Limited_Record
(T
) then
8394 return New_Occurrence_Of
8395 (RTE
(RE_TK_Abstract_Limited_Tagged
), Loc
);
8397 return New_Occurrence_Of
8398 (RTE
(RE_TK_Abstract_Tagged
), Loc
);
8403 elsif Is_Concurrent_Record_Type
(T
) then
8404 Conc_Typ
:= Corresponding_Concurrent_Type
(T
);
8406 if Present
(Full_View
(Conc_Typ
)) then
8407 Conc_Typ
:= Full_View
(Conc_Typ
);
8410 if Ekind
(Conc_Typ
) = E_Protected_Type
then
8411 return New_Occurrence_Of
(RTE
(RE_TK_Protected
), Loc
);
8413 pragma Assert
(Ekind
(Conc_Typ
) = E_Task_Type
);
8414 return New_Occurrence_Of
(RTE
(RE_TK_Task
), Loc
);
8417 -- Regular tagged kinds
8420 if Is_Limited_Record
(T
) then
8421 return New_Occurrence_Of
(RTE
(RE_TK_Limited_Tagged
), Loc
);
8423 return New_Occurrence_Of
(RTE
(RE_TK_Tagged
), Loc
);
8432 procedure Write_DT
(Typ
: Entity_Id
) is
8437 -- Protect this procedure against wrong usage. Required because it will
8438 -- be used directly from GDB
8440 if not (Typ
<= Last_Node_Id
)
8441 or else not Is_Tagged_Type
(Typ
)
8443 Write_Str
("wrong usage: Write_DT must be used with tagged types");
8448 Write_Int
(Int
(Typ
));
8450 Write_Name
(Chars
(Typ
));
8452 if Is_Interface
(Typ
) then
8453 Write_Str
(" is interface");
8458 Elmt
:= First_Elmt
(Primitive_Operations
(Typ
));
8459 while Present
(Elmt
) loop
8460 Prim
:= Node
(Elmt
);
8463 -- Indicate if this primitive will be allocated in the primary
8464 -- dispatch table or in a secondary dispatch table associated
8465 -- with an abstract interface type
8467 if Present
(DTC_Entity
(Prim
)) then
8468 if Etype
(DTC_Entity
(Prim
)) = RTE
(RE_Tag
) then
8475 -- Output the node of this primitive operation and its name
8477 Write_Int
(Int
(Prim
));
8480 if Is_Predefined_Dispatching_Operation
(Prim
) then
8481 Write_Str
("(predefined) ");
8484 -- Prefix the name of the primitive with its corresponding tagged
8485 -- type to facilitate seeing inherited primitives.
8487 if Present
(Alias
(Prim
)) then
8489 (Chars
(Find_Dispatching_Type
(Ultimate_Alias
(Prim
))));
8491 Write_Name
(Chars
(Typ
));
8495 Write_Name
(Chars
(Prim
));
8497 -- Indicate if this primitive has an aliased primitive
8499 if Present
(Alias
(Prim
)) then
8500 Write_Str
(" (alias = ");
8501 Write_Int
(Int
(Alias
(Prim
)));
8503 -- If the DTC_Entity attribute is already set we can also output
8504 -- the name of the interface covered by this primitive (if any).
8506 if Ekind_In
(Alias
(Prim
), E_Function
, E_Procedure
)
8507 and then Present
(DTC_Entity
(Alias
(Prim
)))
8508 and then Is_Interface
(Scope
(DTC_Entity
(Alias
(Prim
))))
8510 Write_Str
(" from interface ");
8511 Write_Name
(Chars
(Scope
(DTC_Entity
(Alias
(Prim
)))));
8514 if Present
(Interface_Alias
(Prim
)) then
8515 Write_Str
(", AI_Alias of ");
8517 if Is_Null_Interface_Primitive
(Interface_Alias
(Prim
)) then
8518 Write_Str
("null primitive ");
8522 (Chars
(Find_Dispatching_Type
(Interface_Alias
(Prim
))));
8524 Write_Int
(Int
(Interface_Alias
(Prim
)));
8530 -- Display the final position of this primitive in its associated
8531 -- (primary or secondary) dispatch table.
8533 if Present
(DTC_Entity
(Prim
))
8534 and then DT_Position
(Prim
) /= No_Uint
8536 Write_Str
(" at #");
8537 Write_Int
(UI_To_Int
(DT_Position
(Prim
)));
8540 if Is_Abstract_Subprogram
(Prim
) then
8541 Write_Str
(" is abstract;");
8543 -- Check if this is a null primitive
8545 elsif Comes_From_Source
(Prim
)
8546 and then Ekind
(Prim
) = E_Procedure
8547 and then Null_Present
(Parent
(Prim
))
8549 Write_Str
(" is null;");
8552 if Is_Eliminated
(Ultimate_Alias
(Prim
)) then
8553 Write_Str
(" (eliminated)");
8556 if Is_Imported
(Prim
)
8557 and then Convention
(Prim
) = Convention_CPP
8559 Write_Str
(" (C++)");