1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2016, 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 Snames
; use Snames
;
62 with Stand
; use Stand
;
63 with Stringt
; use Stringt
;
64 with SCIL_LL
; use SCIL_LL
;
65 with Tbuild
; use Tbuild
;
67 package body Exp_Disp
is
69 -----------------------
70 -- Local Subprograms --
71 -----------------------
73 function Default_Prim_Op_Position
(E
: Entity_Id
) return Uint
;
74 -- Ada 2005 (AI-251): Returns the fixed position in the dispatch table
75 -- of the default primitive operations.
77 function Has_DT
(Typ
: Entity_Id
) return Boolean;
78 pragma Inline
(Has_DT
);
79 -- Returns true if we generate a dispatch table for tagged type Typ
81 function Is_Predefined_Dispatching_Alias
(Prim
: Entity_Id
) return Boolean;
82 -- Returns true if Prim is not a predefined dispatching primitive but it is
83 -- an alias of a predefined dispatching primitive (i.e. through a renaming)
85 function New_Value
(From
: Node_Id
) return Node_Id
;
86 -- From is the original Expression. New_Value is equivalent to a call to
87 -- Duplicate_Subexpr with an explicit dereference when From is an access
90 function Original_View_In_Visible_Part
(Typ
: Entity_Id
) return Boolean;
91 -- Check if the type has a private view or if the public view appears in
92 -- the visible part of a package spec.
96 Typ
: Entity_Id
) return Node_Id
;
97 -- Ada 2005 (AI-345): Determine the primitive operation kind of Prim
98 -- according to its type Typ. Return a reference to an RE_Prim_Op_Kind
101 function Tagged_Kind
(T
: Entity_Id
) return Node_Id
;
102 -- Ada 2005 (AI-345): Determine the tagged kind of T and return a reference
103 -- to an RE_Tagged_Kind enumeration value.
105 ----------------------
106 -- Apply_Tag_Checks --
107 ----------------------
109 procedure Apply_Tag_Checks
(Call_Node
: Node_Id
) is
110 Loc
: constant Source_Ptr
:= Sloc
(Call_Node
);
111 Ctrl_Arg
: constant Node_Id
:= Controlling_Argument
(Call_Node
);
112 Ctrl_Typ
: constant Entity_Id
:= Base_Type
(Etype
(Ctrl_Arg
));
113 Param_List
: constant List_Id
:= Parameter_Associations
(Call_Node
);
119 Eq_Prim_Op
: Entity_Id
:= Empty
;
122 if No_Run_Time_Mode
then
123 Error_Msg_CRT
("tagged types", Call_Node
);
127 -- Apply_Tag_Checks is called directly from the semantics, so we
128 -- need a check to see whether expansion is active before proceeding.
129 -- In addition, there is no need to expand the call when compiling
130 -- under restriction No_Dispatching_Calls; the semantic analyzer has
131 -- previously notified the violation of this restriction.
133 if not Expander_Active
134 or else Restriction_Active
(No_Dispatching_Calls
)
139 -- Set subprogram. If this is an inherited operation that was
140 -- overridden, the body that is being called is its alias.
142 Subp
:= Entity
(Name
(Call_Node
));
144 if Present
(Alias
(Subp
))
145 and then Is_Inherited_Operation
(Subp
)
146 and then No
(DTC_Entity
(Subp
))
148 Subp
:= Alias
(Subp
);
151 -- Definition of the class-wide type and the tagged type
153 -- If the controlling argument is itself a tag rather than a tagged
154 -- object, then use the class-wide type associated with the subprogram's
155 -- controlling type. This case can occur when a call to an inherited
156 -- primitive has an actual that originated from a default parameter
157 -- given by a tag-indeterminate call and when there is no other
158 -- controlling argument providing the tag (AI-239 requires dispatching).
159 -- This capability of dispatching directly by tag is also needed by the
160 -- implementation of AI-260 (for the generic dispatching constructors).
162 if Ctrl_Typ
= RTE
(RE_Tag
)
163 or else (RTE_Available
(RE_Interface_Tag
)
164 and then Ctrl_Typ
= RTE
(RE_Interface_Tag
))
166 CW_Typ
:= Class_Wide_Type
(Find_Dispatching_Type
(Subp
));
168 -- Class_Wide_Type is applied to the expressions used to initialize
169 -- CW_Typ, to ensure that CW_Typ always denotes a class-wide type, since
170 -- there are cases where the controlling type is resolved to a specific
171 -- type (such as for designated types of arguments such as CW'Access).
173 elsif Is_Access_Type
(Ctrl_Typ
) then
174 CW_Typ
:= Class_Wide_Type
(Designated_Type
(Ctrl_Typ
));
177 CW_Typ
:= Class_Wide_Type
(Ctrl_Typ
);
180 Typ
:= Find_Specific_Type
(CW_Typ
);
182 if not Is_Limited_Type
(Typ
) then
183 Eq_Prim_Op
:= Find_Prim_Op
(Typ
, Name_Op_Eq
);
186 -- Dispatching call to C++ primitive
188 if Is_CPP_Class
(Typ
) then
191 -- Dispatching call to Ada primitive
193 elsif Present
(Param_List
) then
195 -- Generate the Tag checks when appropriate
197 Param
:= First_Actual
(Call_Node
);
198 while Present
(Param
) loop
200 -- No tag check with itself
202 if Param
= Ctrl_Arg
then
205 -- No tag check for parameter whose type is neither tagged nor
206 -- access to tagged (for access parameters)
208 elsif No
(Find_Controlling_Arg
(Param
)) then
211 -- No tag check for function dispatching on result if the
212 -- Tag given by the context is this one
214 elsif Find_Controlling_Arg
(Param
) = Ctrl_Arg
then
217 -- "=" is the only dispatching operation allowed to get operands
218 -- with incompatible tags (it just returns false). We use
219 -- Duplicate_Subexpr_Move_Checks instead of calling Relocate_Node
220 -- because the value will be duplicated to check the tags.
222 elsif Subp
= Eq_Prim_Op
then
225 -- No check in presence of suppress flags
227 elsif Tag_Checks_Suppressed
(Etype
(Param
))
228 or else (Is_Access_Type
(Etype
(Param
))
229 and then Tag_Checks_Suppressed
230 (Designated_Type
(Etype
(Param
))))
234 -- Optimization: no tag checks if the parameters are identical
236 elsif Is_Entity_Name
(Param
)
237 and then Is_Entity_Name
(Ctrl_Arg
)
238 and then Entity
(Param
) = Entity
(Ctrl_Arg
)
242 -- Now we need to generate the Tag check
245 -- Generate code for tag equality check
247 -- Perhaps should have Checks.Apply_Tag_Equality_Check???
249 Insert_Action
(Ctrl_Arg
,
250 Make_Implicit_If_Statement
(Call_Node
,
254 Make_Selected_Component
(Loc
,
255 Prefix
=> New_Value
(Ctrl_Arg
),
258 (First_Tag_Component
(Typ
), Loc
)),
261 Make_Selected_Component
(Loc
,
263 Unchecked_Convert_To
(Typ
, New_Value
(Param
)),
266 (First_Tag_Component
(Typ
), Loc
))),
269 New_List
(New_Constraint_Error
(Loc
))));
275 end Apply_Tag_Checks
;
277 ------------------------
278 -- Building_Static_DT --
279 ------------------------
281 function Building_Static_DT
(Typ
: Entity_Id
) return Boolean is
282 Root_Typ
: Entity_Id
:= Root_Type
(Typ
);
285 -- Handle private types
287 if Present
(Full_View
(Root_Typ
)) then
288 Root_Typ
:= Full_View
(Root_Typ
);
291 return Static_Dispatch_Tables
292 and then Is_Library_Level_Tagged_Type
(Typ
)
294 -- If the type is derived from a CPP class we cannot statically
295 -- build the dispatch tables because we must inherit primitives
296 -- from the CPP side.
298 and then not Is_CPP_Class
(Root_Typ
);
299 end Building_Static_DT
;
301 ----------------------------------
302 -- Build_Static_Dispatch_Tables --
303 ----------------------------------
305 procedure Build_Static_Dispatch_Tables
(N
: Entity_Id
) is
306 Target_List
: List_Id
;
308 procedure Build_Dispatch_Tables
(List
: List_Id
);
309 -- Build the static dispatch table of tagged types found in the list of
310 -- declarations. The generated nodes are added at the end of Target_List
312 procedure Build_Package_Dispatch_Tables
(N
: Node_Id
);
313 -- Build static dispatch tables associated with package declaration N
315 ---------------------------
316 -- Build_Dispatch_Tables --
317 ---------------------------
319 procedure Build_Dispatch_Tables
(List
: List_Id
) is
324 while Present
(D
) loop
326 -- Handle nested packages and package bodies recursively. The
327 -- generated code is placed on the Target_List established for
328 -- the enclosing compilation unit.
330 if Nkind
(D
) = N_Package_Declaration
then
331 Build_Package_Dispatch_Tables
(D
);
333 elsif Nkind
(D
) = N_Package_Body
then
334 Build_Dispatch_Tables
(Declarations
(D
));
336 elsif Nkind
(D
) = N_Package_Body_Stub
337 and then Present
(Library_Unit
(D
))
339 Build_Dispatch_Tables
340 (Declarations
(Proper_Body
(Unit
(Library_Unit
(D
)))));
342 -- Handle full type declarations and derivations of library level
345 elsif Nkind_In
(D
, N_Full_Type_Declaration
,
346 N_Derived_Type_Definition
)
347 and then Is_Library_Level_Tagged_Type
(Defining_Entity
(D
))
348 and then Ekind
(Defining_Entity
(D
)) /= E_Record_Subtype
349 and then not Is_Private_Type
(Defining_Entity
(D
))
351 -- We do not generate dispatch tables for the internal types
352 -- created for a type extension with unknown discriminants
353 -- The needed information is shared with the source type,
354 -- See Expand_N_Record_Extension.
356 if Is_Underlying_Record_View
(Defining_Entity
(D
))
358 (not Comes_From_Source
(Defining_Entity
(D
))
360 Has_Unknown_Discriminants
(Etype
(Defining_Entity
(D
)))
362 not Comes_From_Source
363 (First_Subtype
(Defining_Entity
(D
))))
367 Insert_List_After_And_Analyze
(Last
(Target_List
),
368 Make_DT
(Defining_Entity
(D
)));
371 -- Handle private types of library level tagged types. We must
372 -- exchange the private and full-view to ensure the correct
373 -- expansion. If the full view is a synchronized type ignore
374 -- the type because the table will be built for the corresponding
375 -- record type, that has its own declaration.
377 elsif (Nkind
(D
) = N_Private_Type_Declaration
378 or else Nkind
(D
) = N_Private_Extension_Declaration
)
379 and then Present
(Full_View
(Defining_Entity
(D
)))
382 E1
: constant Entity_Id
:= Defining_Entity
(D
);
383 E2
: constant Entity_Id
:= Full_View
(E1
);
386 if Is_Library_Level_Tagged_Type
(E2
)
387 and then Ekind
(E2
) /= E_Record_Subtype
388 and then not Is_Concurrent_Type
(E2
)
390 Exchange_Declarations
(E1
);
391 Insert_List_After_And_Analyze
(Last
(Target_List
),
393 Exchange_Declarations
(E2
);
400 end Build_Dispatch_Tables
;
402 -----------------------------------
403 -- Build_Package_Dispatch_Tables --
404 -----------------------------------
406 procedure Build_Package_Dispatch_Tables
(N
: Node_Id
) is
407 Spec
: constant Node_Id
:= Specification
(N
);
408 Id
: constant Entity_Id
:= Defining_Entity
(N
);
409 Vis_Decls
: constant List_Id
:= Visible_Declarations
(Spec
);
410 Priv_Decls
: constant List_Id
:= Private_Declarations
(Spec
);
415 if Present
(Priv_Decls
) then
416 Build_Dispatch_Tables
(Vis_Decls
);
417 Build_Dispatch_Tables
(Priv_Decls
);
419 elsif Present
(Vis_Decls
) then
420 Build_Dispatch_Tables
(Vis_Decls
);
424 end Build_Package_Dispatch_Tables
;
426 -- Start of processing for Build_Static_Dispatch_Tables
429 if not Expander_Active
430 or else not Tagged_Type_Expansion
435 if Nkind
(N
) = N_Package_Declaration
then
437 Spec
: constant Node_Id
:= Specification
(N
);
438 Vis_Decls
: constant List_Id
:= Visible_Declarations
(Spec
);
439 Priv_Decls
: constant List_Id
:= Private_Declarations
(Spec
);
442 if Present
(Priv_Decls
)
443 and then Is_Non_Empty_List
(Priv_Decls
)
445 Target_List
:= Priv_Decls
;
447 elsif not Present
(Vis_Decls
) then
448 Target_List
:= New_List
;
449 Set_Private_Declarations
(Spec
, Target_List
);
451 Target_List
:= Vis_Decls
;
454 Build_Package_Dispatch_Tables
(N
);
457 else pragma Assert
(Nkind
(N
) = N_Package_Body
);
458 Target_List
:= Declarations
(N
);
459 Build_Dispatch_Tables
(Target_List
);
461 end Build_Static_Dispatch_Tables
;
463 ------------------------------
464 -- Convert_Tag_To_Interface --
465 ------------------------------
467 function Convert_Tag_To_Interface
469 Expr
: Node_Id
) return Node_Id
471 Loc
: constant Source_Ptr
:= Sloc
(Expr
);
472 Anon_Type
: Entity_Id
;
476 pragma Assert
(Is_Class_Wide_Type
(Typ
)
477 and then Is_Interface
(Typ
)
479 ((Nkind
(Expr
) = N_Selected_Component
480 and then Is_Tag
(Entity
(Selector_Name
(Expr
))))
482 (Nkind
(Expr
) = N_Function_Call
483 and then RTE_Available
(RE_Displace
)
484 and then Entity
(Name
(Expr
)) = RTE
(RE_Displace
))));
486 Anon_Type
:= Create_Itype
(E_Anonymous_Access_Type
, Expr
);
487 Set_Directly_Designated_Type
(Anon_Type
, Typ
);
488 Set_Etype
(Anon_Type
, Anon_Type
);
489 Set_Can_Never_Be_Null
(Anon_Type
);
491 -- Decorate the size and alignment attributes of the anonymous access
492 -- type, as required by the back end.
494 Layout_Type
(Anon_Type
);
496 if Nkind
(Expr
) = N_Selected_Component
497 and then Is_Tag
(Entity
(Selector_Name
(Expr
)))
500 Make_Explicit_Dereference
(Loc
,
501 Unchecked_Convert_To
(Anon_Type
,
502 Make_Attribute_Reference
(Loc
,
504 Attribute_Name
=> Name_Address
)));
507 Make_Explicit_Dereference
(Loc
,
508 Unchecked_Convert_To
(Anon_Type
, Expr
));
512 end Convert_Tag_To_Interface
;
518 function CPP_Num_Prims
(Typ
: Entity_Id
) return Nat
is
520 Tag_Comp
: Entity_Id
;
523 if not Is_Tagged_Type
(Typ
)
524 or else not Is_CPP_Class
(Root_Type
(Typ
))
529 CPP_Typ
:= Enclosing_CPP_Parent
(Typ
);
530 Tag_Comp
:= First_Tag_Component
(CPP_Typ
);
532 -- If number of primitives already set in the tag component, use it
534 if Present
(Tag_Comp
)
535 and then DT_Entry_Count
(Tag_Comp
) /= No_Uint
537 return UI_To_Int
(DT_Entry_Count
(Tag_Comp
));
539 -- Otherwise, count the primitives of the enclosing CPP type
547 Elmt
:= First_Elmt
(Primitive_Operations
(CPP_Typ
));
548 while Present
(Elmt
) loop
559 ------------------------------
560 -- Default_Prim_Op_Position --
561 ------------------------------
563 function Default_Prim_Op_Position
(E
: Entity_Id
) return Uint
is
564 TSS_Name
: TSS_Name_Type
;
567 Get_Name_String
(Chars
(E
));
570 (Name_Buffer
(Name_Len
- TSS_Name
'Length + 1 .. Name_Len
));
572 if Chars
(E
) = Name_uSize
then
575 elsif TSS_Name
= TSS_Stream_Read
then
578 elsif TSS_Name
= TSS_Stream_Write
then
581 elsif TSS_Name
= TSS_Stream_Input
then
584 elsif TSS_Name
= TSS_Stream_Output
then
587 elsif Chars
(E
) = Name_Op_Eq
then
590 elsif Chars
(E
) = Name_uAssign
then
593 elsif TSS_Name
= TSS_Deep_Adjust
then
596 elsif TSS_Name
= TSS_Deep_Finalize
then
599 -- In VM targets unconditionally allow obtaining the position associated
600 -- with predefined interface primitives since in these platforms any
601 -- tagged type has these primitives.
603 elsif Ada_Version
>= Ada_2005
or else not Tagged_Type_Expansion
then
604 if Chars
(E
) = Name_uDisp_Asynchronous_Select
then
607 elsif Chars
(E
) = Name_uDisp_Conditional_Select
then
610 elsif Chars
(E
) = Name_uDisp_Get_Prim_Op_Kind
then
613 elsif Chars
(E
) = Name_uDisp_Get_Task_Id
then
616 elsif Chars
(E
) = Name_uDisp_Requeue
then
619 elsif Chars
(E
) = Name_uDisp_Timed_Select
then
625 end Default_Prim_Op_Position
;
627 -----------------------------
628 -- Expand_Dispatching_Call --
629 -----------------------------
631 procedure Expand_Dispatching_Call
(Call_Node
: Node_Id
) is
632 Loc
: constant Source_Ptr
:= Sloc
(Call_Node
);
633 Call_Typ
: constant Entity_Id
:= Etype
(Call_Node
);
635 Ctrl_Arg
: constant Node_Id
:= Controlling_Argument
(Call_Node
);
636 Ctrl_Typ
: constant Entity_Id
:= Base_Type
(Etype
(Ctrl_Arg
));
637 Param_List
: constant List_Id
:= Parameter_Associations
(Call_Node
);
642 New_Call_Name
: Node_Id
;
643 New_Params
: List_Id
:= No_List
;
646 Subp_Ptr_Typ
: Entity_Id
;
647 Subp_Typ
: Entity_Id
;
649 Eq_Prim_Op
: Entity_Id
:= Empty
;
650 Controlling_Tag
: Node_Id
;
652 function New_Value
(From
: Node_Id
) return Node_Id
;
653 -- From is the original Expression. New_Value is equivalent to a call
654 -- to Duplicate_Subexpr with an explicit dereference when From is an
661 function New_Value
(From
: Node_Id
) return Node_Id
is
662 Res
: constant Node_Id
:= Duplicate_Subexpr
(From
);
664 if Is_Access_Type
(Etype
(From
)) then
666 Make_Explicit_Dereference
(Sloc
(From
),
677 SCIL_Related_Node
: Node_Id
:= Call_Node
;
679 -- Start of processing for Expand_Dispatching_Call
682 if No_Run_Time_Mode
then
683 Error_Msg_CRT
("tagged types", Call_Node
);
687 -- Expand_Dispatching_Call is called directly from the semantics, so we
688 -- only proceed if the expander is active.
690 if not Expander_Active
692 -- And there is no need to expand the call if we are compiling under
693 -- restriction No_Dispatching_Calls; the semantic analyzer has
694 -- previously notified the violation of this restriction.
696 or else Restriction_Active
(No_Dispatching_Calls
)
698 -- No action needed if the dispatching call has been already expanded
700 or else Is_Expanded_Dispatching_Call
(Name
(Call_Node
))
705 -- Set subprogram. If this is an inherited operation that was
706 -- overridden, the body that is being called is its alias.
708 Subp
:= Entity
(Name
(Call_Node
));
710 if Present
(Alias
(Subp
))
711 and then Is_Inherited_Operation
(Subp
)
712 and then No
(DTC_Entity
(Subp
))
714 Subp
:= Alias
(Subp
);
717 -- Definition of the class-wide type and the tagged type
719 -- If the controlling argument is itself a tag rather than a tagged
720 -- object, then use the class-wide type associated with the subprogram's
721 -- controlling type. This case can occur when a call to an inherited
722 -- primitive has an actual that originated from a default parameter
723 -- given by a tag-indeterminate call and when there is no other
724 -- controlling argument providing the tag (AI-239 requires dispatching).
725 -- This capability of dispatching directly by tag is also needed by the
726 -- implementation of AI-260 (for the generic dispatching constructors).
728 if Ctrl_Typ
= RTE
(RE_Tag
)
729 or else (RTE_Available
(RE_Interface_Tag
)
730 and then Ctrl_Typ
= RTE
(RE_Interface_Tag
))
732 CW_Typ
:= Class_Wide_Type
(Find_Dispatching_Type
(Subp
));
734 -- Class_Wide_Type is applied to the expressions used to initialize
735 -- CW_Typ, to ensure that CW_Typ always denotes a class-wide type, since
736 -- there are cases where the controlling type is resolved to a specific
737 -- type (such as for designated types of arguments such as CW'Access).
739 elsif Is_Access_Type
(Ctrl_Typ
) then
740 CW_Typ
:= Class_Wide_Type
(Designated_Type
(Ctrl_Typ
));
743 CW_Typ
:= Class_Wide_Type
(Ctrl_Typ
);
746 Typ
:= Find_Specific_Type
(CW_Typ
);
748 if not Is_Limited_Type
(Typ
) then
749 Eq_Prim_Op
:= Find_Prim_Op
(Typ
, Name_Op_Eq
);
752 -- Dispatching call to C++ primitive. Create a new parameter list
753 -- with no tag checks.
755 New_Params
:= New_List
;
757 if Is_CPP_Class
(Typ
) then
758 Param
:= First_Actual
(Call_Node
);
759 while Present
(Param
) loop
760 Append_To
(New_Params
, Relocate_Node
(Param
));
764 -- Dispatching call to Ada primitive
766 elsif Present
(Param_List
) then
767 Apply_Tag_Checks
(Call_Node
);
769 Param
:= First_Actual
(Call_Node
);
770 while Present
(Param
) loop
772 -- Cases in which we may have generated run-time checks. Note that
773 -- we strip any qualification from Param before comparing with the
774 -- already-stripped controlling argument.
776 if Unqualify
(Param
) = Ctrl_Arg
or else Subp
= Eq_Prim_Op
then
777 Append_To
(New_Params
,
778 Duplicate_Subexpr_Move_Checks
(Param
));
780 elsif Nkind
(Parent
(Param
)) /= N_Parameter_Association
781 or else not Is_Accessibility_Actual
(Parent
(Param
))
783 Append_To
(New_Params
, Relocate_Node
(Param
));
790 -- Generate the appropriate subprogram pointer type
792 if Etype
(Subp
) = Typ
then
795 Res_Typ
:= Etype
(Subp
);
798 Subp_Typ
:= Create_Itype
(E_Subprogram_Type
, Call_Node
);
799 Subp_Ptr_Typ
:= Create_Itype
(E_Access_Subprogram_Type
, Call_Node
);
800 Set_Etype
(Subp_Typ
, Res_Typ
);
801 Set_Returns_By_Ref
(Subp_Typ
, Returns_By_Ref
(Subp
));
802 Set_Convention
(Subp_Typ
, Convention
(Subp
));
804 -- Notify gigi that the designated type is a dispatching primitive
806 Set_Is_Dispatch_Table_Entity
(Subp_Typ
);
808 -- Create a new list of parameters which is a copy of the old formal
809 -- list including the creation of a new set of matching entities.
812 Old_Formal
: Entity_Id
:= First_Formal
(Subp
);
813 New_Formal
: Entity_Id
;
814 Extra
: Entity_Id
:= Empty
;
817 if Present
(Old_Formal
) then
818 New_Formal
:= New_Copy
(Old_Formal
);
819 Set_First_Entity
(Subp_Typ
, New_Formal
);
820 Param
:= First_Actual
(Call_Node
);
823 Set_Scope
(New_Formal
, Subp_Typ
);
825 -- Change all the controlling argument types to be class-wide
826 -- to avoid a recursion in dispatching.
828 if Is_Controlling_Formal
(New_Formal
) then
829 Set_Etype
(New_Formal
, Etype
(Param
));
832 -- If the type of the formal is an itype, there was code here
833 -- introduced in 1998 in revision 1.46, to create a new itype
834 -- by copy. This seems useless, and in fact leads to semantic
835 -- errors when the itype is the completion of a type derived
836 -- from a private type.
839 Next_Formal
(Old_Formal
);
840 exit when No
(Old_Formal
);
842 Set_Next_Entity
(New_Formal
, New_Copy
(Old_Formal
));
843 Next_Entity
(New_Formal
);
847 Set_Next_Entity
(New_Formal
, Empty
);
848 Set_Last_Entity
(Subp_Typ
, Extra
);
851 -- Now that the explicit formals have been duplicated, any extra
852 -- formals needed by the subprogram must be created.
854 if Present
(Extra
) then
855 Set_Extra_Formal
(Extra
, Empty
);
858 Create_Extra_Formals
(Subp_Typ
);
861 -- Complete description of pointer type, including size information, as
862 -- must be done with itypes to prevent order-of-elaboration anomalies
865 Set_Etype
(Subp_Ptr_Typ
, Subp_Ptr_Typ
);
866 Set_Directly_Designated_Type
(Subp_Ptr_Typ
, Subp_Typ
);
867 Set_Convention
(Subp_Ptr_Typ
, Convention
(Subp_Typ
));
868 Layout_Type
(Subp_Ptr_Typ
);
870 -- If the controlling argument is a value of type Ada.Tag or an abstract
871 -- interface class-wide type then use it directly. Otherwise, the tag
872 -- must be extracted from the controlling object.
874 if Ctrl_Typ
= RTE
(RE_Tag
)
875 or else (RTE_Available
(RE_Interface_Tag
)
876 and then Ctrl_Typ
= RTE
(RE_Interface_Tag
))
878 Controlling_Tag
:= Duplicate_Subexpr
(Ctrl_Arg
);
880 -- Extract the tag from an unchecked type conversion. Done to avoid
881 -- the expansion of additional code just to obtain the value of such
882 -- tag because the current management of interface type conversions
883 -- generates in some cases this unchecked type conversion with the
884 -- tag of the object (see Expand_Interface_Conversion).
886 elsif Nkind
(Ctrl_Arg
) = N_Unchecked_Type_Conversion
888 (Etype
(Expression
(Ctrl_Arg
)) = RTE
(RE_Tag
)
890 (RTE_Available
(RE_Interface_Tag
)
892 Etype
(Expression
(Ctrl_Arg
)) = RTE
(RE_Interface_Tag
)))
894 Controlling_Tag
:= Duplicate_Subexpr
(Expression
(Ctrl_Arg
));
896 -- Ada 2005 (AI-251): Abstract interface class-wide type
898 elsif Is_Interface
(Ctrl_Typ
)
899 and then Is_Class_Wide_Type
(Ctrl_Typ
)
901 Controlling_Tag
:= Duplicate_Subexpr
(Ctrl_Arg
);
905 Make_Selected_Component
(Loc
,
906 Prefix
=> Duplicate_Subexpr_Move_Checks
(Ctrl_Arg
),
907 Selector_Name
=> New_Occurrence_Of
(DTC_Entity
(Subp
), Loc
));
910 -- Handle dispatching calls to predefined primitives
912 if Is_Predefined_Dispatching_Operation
(Subp
)
913 or else Is_Predefined_Dispatching_Alias
(Subp
)
915 Build_Get_Predefined_Prim_Op_Address
(Loc
,
916 Tag_Node
=> Controlling_Tag
,
917 Position
=> DT_Position
(Subp
),
918 New_Node
=> New_Node
);
920 -- Handle dispatching calls to user-defined primitives
923 Build_Get_Prim_Op_Address
(Loc
,
924 Typ
=> Underlying_Type
(Find_Dispatching_Type
(Subp
)),
925 Tag_Node
=> Controlling_Tag
,
926 Position
=> DT_Position
(Subp
),
927 New_Node
=> New_Node
);
931 Unchecked_Convert_To
(Subp_Ptr_Typ
, New_Node
);
933 -- Generate the SCIL node for this dispatching call. Done now because
934 -- attribute SCIL_Controlling_Tag must be set after the new call name
935 -- is built to reference the nodes that will see the SCIL backend
936 -- (because Build_Get_Prim_Op_Address generates an unchecked type
937 -- conversion which relocates the controlling tag node).
939 if Generate_SCIL
then
940 SCIL_Node
:= Make_SCIL_Dispatching_Call
(Sloc
(Call_Node
));
941 Set_SCIL_Entity
(SCIL_Node
, Typ
);
942 Set_SCIL_Target_Prim
(SCIL_Node
, Subp
);
944 -- Common case: the controlling tag is the tag of an object
945 -- (for example, obj.tag)
947 if Nkind
(Controlling_Tag
) = N_Selected_Component
then
948 Set_SCIL_Controlling_Tag
(SCIL_Node
, Controlling_Tag
);
950 -- Handle renaming of selected component
952 elsif Nkind
(Controlling_Tag
) = N_Identifier
953 and then Nkind
(Parent
(Entity
(Controlling_Tag
))) =
954 N_Object_Renaming_Declaration
955 and then Nkind
(Name
(Parent
(Entity
(Controlling_Tag
)))) =
958 Set_SCIL_Controlling_Tag
(SCIL_Node
,
959 Name
(Parent
(Entity
(Controlling_Tag
))));
961 -- If the controlling tag is an identifier, the SCIL node references
962 -- the corresponding object or parameter declaration
964 elsif Nkind
(Controlling_Tag
) = N_Identifier
965 and then Nkind_In
(Parent
(Entity
(Controlling_Tag
)),
966 N_Object_Declaration
,
967 N_Parameter_Specification
)
969 Set_SCIL_Controlling_Tag
(SCIL_Node
,
970 Parent
(Entity
(Controlling_Tag
)));
972 -- If the controlling tag is a dereference, the SCIL node references
973 -- the corresponding object or parameter declaration
975 elsif Nkind
(Controlling_Tag
) = N_Explicit_Dereference
976 and then Nkind
(Prefix
(Controlling_Tag
)) = N_Identifier
977 and then Nkind_In
(Parent
(Entity
(Prefix
(Controlling_Tag
))),
978 N_Object_Declaration
,
979 N_Parameter_Specification
)
981 Set_SCIL_Controlling_Tag
(SCIL_Node
,
982 Parent
(Entity
(Prefix
(Controlling_Tag
))));
984 -- For a direct reference of the tag of the type the SCIL node
985 -- references the internal object declaration containing the tag
988 elsif Nkind
(Controlling_Tag
) = N_Attribute_Reference
989 and then Attribute_Name
(Controlling_Tag
) = Name_Tag
991 Set_SCIL_Controlling_Tag
(SCIL_Node
,
995 (Access_Disp_Table
(Entity
(Prefix
(Controlling_Tag
)))))));
997 -- Interfaces are not supported. For now we leave the SCIL node
998 -- decorated with the Controlling_Tag. More work needed here???
1000 elsif Is_Interface
(Etype
(Controlling_Tag
)) then
1001 Set_SCIL_Controlling_Tag
(SCIL_Node
, Controlling_Tag
);
1004 pragma Assert
(False);
1009 if Nkind
(Call_Node
) = N_Function_Call
then
1011 Make_Function_Call
(Loc
,
1012 Name
=> New_Call_Name
,
1013 Parameter_Associations
=> New_Params
);
1015 -- If this is a dispatching "=", we must first compare the tags so
1016 -- we generate: x.tag = y.tag and then x = y
1018 if Subp
= Eq_Prim_Op
then
1019 Param
:= First_Actual
(Call_Node
);
1025 Make_Selected_Component
(Loc
,
1026 Prefix
=> New_Value
(Param
),
1028 New_Occurrence_Of
(First_Tag_Component
(Typ
),
1032 Make_Selected_Component
(Loc
,
1034 Unchecked_Convert_To
(Typ
,
1035 New_Value
(Next_Actual
(Param
))),
1038 (First_Tag_Component
(Typ
), Loc
))),
1039 Right_Opnd
=> New_Call
);
1041 SCIL_Related_Node
:= Right_Opnd
(New_Call
);
1046 Make_Procedure_Call_Statement
(Loc
,
1047 Name
=> New_Call_Name
,
1048 Parameter_Associations
=> New_Params
);
1051 -- Register the dispatching call in the call graph nodes table
1053 Register_CG_Node
(Call_Node
);
1055 Rewrite
(Call_Node
, New_Call
);
1057 -- Associate the SCIL node of this dispatching call
1059 if Generate_SCIL
then
1060 Set_SCIL_Node
(SCIL_Related_Node
, SCIL_Node
);
1063 -- Suppress all checks during the analysis of the expanded code to avoid
1064 -- the generation of spurious warnings under ZFP run-time.
1066 Analyze_And_Resolve
(Call_Node
, Call_Typ
, Suppress
=> All_Checks
);
1067 end Expand_Dispatching_Call
;
1069 ---------------------------------
1070 -- Expand_Interface_Conversion --
1071 ---------------------------------
1073 procedure Expand_Interface_Conversion
(N
: Node_Id
) is
1074 function Underlying_Record_Type
(Typ
: Entity_Id
) return Entity_Id
;
1075 -- Return the underlying record type of Typ.
1077 ----------------------------
1078 -- Underlying_Record_Type --
1079 ----------------------------
1081 function Underlying_Record_Type
(Typ
: Entity_Id
) return Entity_Id
is
1082 E
: Entity_Id
:= Typ
;
1085 -- Handle access to class-wide interface types
1087 if Is_Access_Type
(E
) then
1088 E
:= Etype
(Directly_Designated_Type
(E
));
1091 -- Handle class-wide types. This conversion can appear explicitly in
1092 -- the source code. Example: I'Class (Obj)
1094 if Is_Class_Wide_Type
(E
) then
1098 -- If the target type is a tagged synchronized type, the dispatch
1099 -- table info is in the corresponding record type.
1101 if Is_Concurrent_Type
(E
) then
1102 E
:= Corresponding_Record_Type
(E
);
1105 -- Handle private types
1107 E
:= Underlying_Type
(E
);
1111 return Base_Type
(E
);
1112 end Underlying_Record_Type
;
1116 Loc
: constant Source_Ptr
:= Sloc
(N
);
1117 Etyp
: constant Entity_Id
:= Etype
(N
);
1118 Operand
: constant Node_Id
:= Expression
(N
);
1119 Operand_Typ
: Entity_Id
:= Etype
(Operand
);
1121 Iface_Typ
: constant Entity_Id
:= Underlying_Record_Type
(Etype
(N
));
1122 Iface_Tag
: Entity_Id
;
1123 Is_Static
: Boolean;
1125 -- Start of processing for Expand_Interface_Conversion
1128 -- Freeze the entity associated with the target interface to have
1129 -- available the attribute Access_Disp_Table.
1131 Freeze_Before
(N
, Iface_Typ
);
1133 -- Ada 2005 (AI-345): Handle synchronized interface type derivations
1135 if Is_Concurrent_Type
(Operand_Typ
) then
1136 Operand_Typ
:= Base_Type
(Corresponding_Record_Type
(Operand_Typ
));
1139 -- No displacement of the pointer to the object needed when the type of
1140 -- the operand is not an interface type and the interface is one of
1141 -- its parent types (since they share the primary dispatch table).
1144 Opnd
: Entity_Id
:= Operand_Typ
;
1147 if Is_Access_Type
(Opnd
) then
1148 Opnd
:= Designated_Type
(Opnd
);
1151 if not Is_Interface
(Opnd
)
1152 and then Is_Ancestor
(Iface_Typ
, Opnd
, Use_Full_View
=> True)
1158 -- Evaluate if we can statically displace the pointer to the object
1161 Opnd_Typ
: constant Node_Id
:= Underlying_Record_Type
(Operand_Typ
);
1165 not Is_Interface
(Opnd_Typ
)
1166 and then Interface_Present_In_Ancestor
1169 and then (Etype
(Opnd_Typ
) = Opnd_Typ
1171 Is_Variable_Size_Record
(Etype
(Opnd_Typ
)));
1174 if not Tagged_Type_Expansion
then
1177 -- A static conversion to an interface type that is not classwide is
1178 -- curious but legal if the interface operation is a null procedure.
1179 -- If the operation is abstract it will be rejected later.
1182 and then Is_Interface
(Etype
(N
))
1183 and then not Is_Class_Wide_Type
(Etype
(N
))
1184 and then Comes_From_Source
(N
)
1186 Rewrite
(N
, Unchecked_Convert_To
(Etype
(N
), N
));
1191 if not Is_Static
then
1193 -- Give error if configurable run time and Displace not available
1195 if not RTE_Available
(RE_Displace
) then
1196 Error_Msg_CRT
("dynamic interface conversion", N
);
1200 -- Handle conversion of access-to-class-wide interface types. Target
1201 -- can be an access to an object or an access to another class-wide
1202 -- interface (see -1- and -2- in the following example):
1204 -- type Iface1_Ref is access all Iface1'Class;
1205 -- type Iface2_Ref is access all Iface1'Class;
1207 -- Acc1 : Iface1_Ref := new ...
1208 -- Obj : Obj_Ref := Obj_Ref (Acc); -- 1
1209 -- Acc2 : Iface2_Ref := Iface2_Ref (Acc); -- 2
1211 if Is_Access_Type
(Operand_Typ
) then
1213 Unchecked_Convert_To
(Etype
(N
),
1214 Make_Function_Call
(Loc
,
1215 Name
=> New_Occurrence_Of
(RTE
(RE_Displace
), Loc
),
1216 Parameter_Associations
=> New_List
(
1218 Unchecked_Convert_To
(RTE
(RE_Address
),
1219 Relocate_Node
(Expression
(N
))),
1222 (Node
(First_Elmt
(Access_Disp_Table
(Iface_Typ
))),
1230 Make_Function_Call
(Loc
,
1231 Name
=> New_Occurrence_Of
(RTE
(RE_Displace
), Loc
),
1232 Parameter_Associations
=> New_List
(
1233 Make_Attribute_Reference
(Loc
,
1234 Prefix
=> Relocate_Node
(Expression
(N
)),
1235 Attribute_Name
=> Name_Address
),
1238 (Node
(First_Elmt
(Access_Disp_Table
(Iface_Typ
))),
1243 -- If target is a class-wide interface, change the type of the data
1244 -- returned by IW_Convert to indicate this is a dispatching call.
1247 New_Itype
: Entity_Id
;
1250 New_Itype
:= Create_Itype
(E_Anonymous_Access_Type
, N
);
1251 Set_Etype
(New_Itype
, New_Itype
);
1252 Set_Directly_Designated_Type
(New_Itype
, Etyp
);
1255 Make_Explicit_Dereference
(Loc
,
1257 Unchecked_Convert_To
(New_Itype
, Relocate_Node
(N
))));
1259 Freeze_Itype
(New_Itype
, N
);
1265 Iface_Tag
:= Find_Interface_Tag
(Operand_Typ
, Iface_Typ
);
1266 pragma Assert
(Iface_Tag
/= Empty
);
1268 -- Keep separate access types to interfaces because one internal
1269 -- function is used to handle the null value (see following comments)
1271 if not Is_Access_Type
(Etype
(N
)) then
1273 -- Statically displace the pointer to the object to reference the
1274 -- component containing the secondary dispatch table.
1277 Convert_Tag_To_Interface
(Class_Wide_Type
(Iface_Typ
),
1278 Make_Selected_Component
(Loc
,
1279 Prefix
=> Relocate_Node
(Expression
(N
)),
1280 Selector_Name
=> New_Occurrence_Of
(Iface_Tag
, Loc
))));
1283 -- Build internal function to handle the case in which the actual is
1284 -- null. If the actual is null returns null because no displacement
1285 -- is required; otherwise performs a type conversion that will be
1286 -- expanded in the code that returns the value of the displaced
1289 -- function Func (O : Address) return Iface_Typ is
1290 -- type Op_Typ is access all Operand_Typ;
1291 -- Aux : Op_Typ := To_Op_Typ (O);
1293 -- if O = Null_Address then
1296 -- return Iface_Typ!(Aux.Iface_Tag'Address);
1301 Desig_Typ
: Entity_Id
;
1303 New_Typ_Decl
: Node_Id
;
1307 Desig_Typ
:= Etype
(Expression
(N
));
1309 if Is_Access_Type
(Desig_Typ
) then
1311 Available_View
(Directly_Designated_Type
(Desig_Typ
));
1314 if Is_Concurrent_Type
(Desig_Typ
) then
1315 Desig_Typ
:= Base_Type
(Corresponding_Record_Type
(Desig_Typ
));
1319 Make_Full_Type_Declaration
(Loc
,
1320 Defining_Identifier
=> Make_Temporary
(Loc
, 'T'),
1322 Make_Access_To_Object_Definition
(Loc
,
1323 All_Present
=> True,
1324 Null_Exclusion_Present
=> False,
1325 Constant_Present
=> False,
1326 Subtype_Indication
=>
1327 New_Occurrence_Of
(Desig_Typ
, Loc
)));
1330 Make_Simple_Return_Statement
(Loc
,
1331 Unchecked_Convert_To
(Etype
(N
),
1332 Make_Attribute_Reference
(Loc
,
1334 Make_Selected_Component
(Loc
,
1336 Unchecked_Convert_To
1337 (Defining_Identifier
(New_Typ_Decl
),
1338 Make_Identifier
(Loc
, Name_uO
)),
1340 New_Occurrence_Of
(Iface_Tag
, Loc
)),
1341 Attribute_Name
=> Name_Address
))));
1343 -- If the type is null-excluding, no need for the null branch.
1344 -- Otherwise we need to check for it and return null.
1346 if not Can_Never_Be_Null
(Etype
(N
)) then
1348 Make_If_Statement
(Loc
,
1351 Left_Opnd
=> Make_Identifier
(Loc
, Name_uO
),
1352 Right_Opnd
=> New_Occurrence_Of
1353 (RTE
(RE_Null_Address
), Loc
)),
1355 Then_Statements
=> New_List
(
1356 Make_Simple_Return_Statement
(Loc
, Make_Null
(Loc
))),
1357 Else_Statements
=> Stats
));
1360 Fent
:= Make_Temporary
(Loc
, 'F');
1362 Make_Subprogram_Body
(Loc
,
1364 Make_Function_Specification
(Loc
,
1365 Defining_Unit_Name
=> Fent
,
1367 Parameter_Specifications
=> New_List
(
1368 Make_Parameter_Specification
(Loc
,
1369 Defining_Identifier
=>
1370 Make_Defining_Identifier
(Loc
, Name_uO
),
1372 New_Occurrence_Of
(RTE
(RE_Address
), Loc
))),
1374 Result_Definition
=>
1375 New_Occurrence_Of
(Etype
(N
), Loc
)),
1377 Declarations
=> New_List
(New_Typ_Decl
),
1379 Handled_Statement_Sequence
=>
1380 Make_Handled_Sequence_Of_Statements
(Loc
, Stats
));
1382 -- Place function body before the expression containing the
1383 -- conversion. We suppress all checks because the body of the
1384 -- internally generated function already takes care of the case
1385 -- in which the actual is null; therefore there is no need to
1386 -- double check that the pointer is not null when the program
1387 -- executes the alternative that performs the type conversion).
1389 Insert_Action
(N
, Func
, Suppress
=> All_Checks
);
1391 if Is_Access_Type
(Etype
(Expression
(N
))) then
1393 Apply_Accessibility_Check
1394 (N
=> Expression
(N
),
1398 -- Generate: Func (Address!(Expression))
1401 Make_Function_Call
(Loc
,
1402 Name
=> New_Occurrence_Of
(Fent
, Loc
),
1403 Parameter_Associations
=> New_List
(
1404 Unchecked_Convert_To
(RTE
(RE_Address
),
1405 Relocate_Node
(Expression
(N
))))));
1408 -- Generate: Func (Operand_Typ!(Expression)'Address)
1411 Make_Function_Call
(Loc
,
1412 Name
=> New_Occurrence_Of
(Fent
, Loc
),
1413 Parameter_Associations
=> New_List
(
1414 Make_Attribute_Reference
(Loc
,
1415 Prefix
=> Unchecked_Convert_To
(Operand_Typ
,
1416 Relocate_Node
(Expression
(N
))),
1417 Attribute_Name
=> Name_Address
))));
1423 end Expand_Interface_Conversion
;
1425 ------------------------------
1426 -- Expand_Interface_Actuals --
1427 ------------------------------
1429 procedure Expand_Interface_Actuals
(Call_Node
: Node_Id
) is
1431 Actual_Dup
: Node_Id
;
1432 Actual_Typ
: Entity_Id
;
1434 Conversion
: Node_Id
;
1436 Formal_Typ
: Entity_Id
;
1438 Formal_DDT
: Entity_Id
;
1439 Actual_DDT
: Entity_Id
;
1442 -- This subprogram is called directly from the semantics, so we need a
1443 -- check to see whether expansion is active before proceeding.
1445 if not Expander_Active
then
1449 -- Call using access to subprogram with explicit dereference
1451 if Nkind
(Name
(Call_Node
)) = N_Explicit_Dereference
then
1452 Subp
:= Etype
(Name
(Call_Node
));
1454 -- Call using selected component
1456 elsif Nkind
(Name
(Call_Node
)) = N_Selected_Component
then
1457 Subp
:= Entity
(Selector_Name
(Name
(Call_Node
)));
1459 -- Call using direct name
1462 Subp
:= Entity
(Name
(Call_Node
));
1465 -- Ada 2005 (AI-251): Look for interface type formals to force "this"
1468 Formal
:= First_Formal
(Subp
);
1469 Actual
:= First_Actual
(Call_Node
);
1470 while Present
(Formal
) loop
1471 Formal_Typ
:= Etype
(Formal
);
1473 if Ekind
(Formal_Typ
) = E_Record_Type_With_Private
then
1474 Formal_Typ
:= Full_View
(Formal_Typ
);
1477 if Is_Access_Type
(Formal_Typ
) then
1478 Formal_DDT
:= Directly_Designated_Type
(Formal_Typ
);
1481 Actual_Typ
:= Etype
(Actual
);
1483 if Is_Access_Type
(Actual_Typ
) then
1484 Actual_DDT
:= Directly_Designated_Type
(Actual_Typ
);
1487 if Is_Interface
(Formal_Typ
)
1488 and then Is_Class_Wide_Type
(Formal_Typ
)
1490 -- No need to displace the pointer if the type of the actual
1491 -- coincides with the type of the formal.
1493 if Actual_Typ
= Formal_Typ
then
1496 -- No need to displace the pointer if the interface type is a
1497 -- parent of the type of the actual because in this case the
1498 -- interface primitives are located in the primary dispatch table.
1500 elsif Is_Ancestor
(Formal_Typ
, Actual_Typ
,
1501 Use_Full_View
=> True)
1505 -- Implicit conversion to the class-wide formal type to force the
1506 -- displacement of the pointer.
1509 -- Normally, expansion of actuals for calls to build-in-place
1510 -- functions happens as part of Expand_Actuals, but in this
1511 -- case the call will be wrapped in a conversion and soon after
1512 -- expanded further to handle the displacement for a class-wide
1513 -- interface conversion, so if this is a BIP call then we need
1514 -- to handle it now.
1516 if Ada_Version
>= Ada_2005
1517 and then Is_Build_In_Place_Function_Call
(Actual
)
1519 Make_Build_In_Place_Call_In_Anonymous_Context
(Actual
);
1522 Conversion
:= Convert_To
(Formal_Typ
, Relocate_Node
(Actual
));
1523 Rewrite
(Actual
, Conversion
);
1524 Analyze_And_Resolve
(Actual
, Formal_Typ
);
1527 -- Access to class-wide interface type
1529 elsif Is_Access_Type
(Formal_Typ
)
1530 and then Is_Interface
(Formal_DDT
)
1531 and then Is_Class_Wide_Type
(Formal_DDT
)
1532 and then Interface_Present_In_Ancestor
1534 Iface
=> Etype
(Formal_DDT
))
1536 -- Handle attributes 'Access and 'Unchecked_Access
1538 if Nkind
(Actual
) = N_Attribute_Reference
1540 (Attribute_Name
(Actual
) = Name_Access
1541 or else Attribute_Name
(Actual
) = Name_Unchecked_Access
)
1543 -- This case must have been handled by the analysis and
1544 -- expansion of 'Access. The only exception is when types
1545 -- match and no further expansion is required.
1547 pragma Assert
(Base_Type
(Etype
(Prefix
(Actual
)))
1548 = Base_Type
(Formal_DDT
));
1551 -- No need to displace the pointer if the type of the actual
1552 -- coincides with the type of the formal.
1554 elsif Actual_DDT
= Formal_DDT
then
1557 -- No need to displace the pointer if the interface type is
1558 -- a parent of the type of the actual because in this case the
1559 -- interface primitives are located in the primary dispatch table.
1561 elsif Is_Ancestor
(Formal_DDT
, Actual_DDT
,
1562 Use_Full_View
=> True)
1567 Actual_Dup
:= Relocate_Node
(Actual
);
1569 if From_Limited_With
(Actual_Typ
) then
1571 -- If the type of the actual parameter comes from a
1572 -- limited with-clause and the non-limited view is already
1573 -- available, we replace the anonymous access type by
1574 -- a duplicate declaration whose designated type is the
1575 -- non-limited view.
1577 if Has_Non_Limited_View
(Actual_DDT
) then
1578 Anon
:= New_Copy
(Actual_Typ
);
1580 if Is_Itype
(Anon
) then
1581 Set_Scope
(Anon
, Current_Scope
);
1584 Set_Directly_Designated_Type
1585 (Anon
, Non_Limited_View
(Actual_DDT
));
1586 Set_Etype
(Actual_Dup
, Anon
);
1590 Conversion
:= Convert_To
(Formal_Typ
, Actual_Dup
);
1591 Rewrite
(Actual
, Conversion
);
1592 Analyze_And_Resolve
(Actual
, Formal_Typ
);
1596 Next_Actual
(Actual
);
1597 Next_Formal
(Formal
);
1599 end Expand_Interface_Actuals
;
1601 ----------------------------
1602 -- Expand_Interface_Thunk --
1603 ----------------------------
1605 procedure Expand_Interface_Thunk
1607 Thunk_Id
: out Entity_Id
;
1608 Thunk_Code
: out Node_Id
)
1610 Loc
: constant Source_Ptr
:= Sloc
(Prim
);
1611 Actuals
: constant List_Id
:= New_List
;
1612 Decl
: constant List_Id
:= New_List
;
1613 Formals
: constant List_Id
:= New_List
;
1614 Target
: constant Entity_Id
:= Ultimate_Alias
(Prim
);
1621 Iface_Formal
: Node_Id
;
1623 Offset_To_Top
: Node_Id
;
1624 Target_Formal
: Entity_Id
;
1628 Thunk_Code
:= Empty
;
1630 -- No thunk needed if the primitive has been eliminated
1632 if Is_Eliminated
(Ultimate_Alias
(Prim
)) then
1635 -- In case of primitives that are functions without formals and a
1636 -- controlling result there is no need to build the thunk.
1638 elsif not Present
(First_Formal
(Target
)) then
1639 pragma Assert
(Ekind
(Target
) = E_Function
1640 and then Has_Controlling_Result
(Target
));
1644 -- Duplicate the formals of the Target primitive. In the thunk, the type
1645 -- of the controlling formal is the covered interface type (instead of
1646 -- the target tagged type). Done to avoid problems with discriminated
1647 -- tagged types because, if the controlling type has discriminants with
1648 -- default values, then the type conversions done inside the body of
1649 -- the thunk (after the displacement of the pointer to the base of the
1650 -- actual object) generate code that modify its contents.
1652 -- Note: This special management is not done for predefined primitives
1655 if not Is_Predefined_Dispatching_Operation
(Prim
) then
1656 Iface_Formal
:= First_Formal
(Interface_Alias
(Prim
));
1659 Formal
:= First_Formal
(Target
);
1660 while Present
(Formal
) loop
1661 Ftyp
:= Etype
(Formal
);
1663 -- Use the interface type as the type of the controlling formal (see
1666 if not Is_Controlling_Formal
(Formal
)
1667 or else Is_Predefined_Dispatching_Operation
(Prim
)
1669 Ftyp
:= Etype
(Formal
);
1670 Expr
:= New_Copy_Tree
(Expression
(Parent
(Formal
)));
1672 Ftyp
:= Etype
(Iface_Formal
);
1677 Make_Parameter_Specification
(Loc
,
1678 Defining_Identifier
=>
1679 Make_Defining_Identifier
(Sloc
(Formal
),
1680 Chars
=> Chars
(Formal
)),
1681 In_Present
=> In_Present
(Parent
(Formal
)),
1682 Out_Present
=> Out_Present
(Parent
(Formal
)),
1683 Parameter_Type
=> New_Occurrence_Of
(Ftyp
, Loc
),
1684 Expression
=> Expr
));
1686 if not Is_Predefined_Dispatching_Operation
(Prim
) then
1687 Next_Formal
(Iface_Formal
);
1690 Next_Formal
(Formal
);
1693 Target_Formal
:= First_Formal
(Target
);
1694 Formal
:= First
(Formals
);
1695 while Present
(Formal
) loop
1697 -- If the parent is a constrained discriminated type, then the
1698 -- primitive operation will have been defined on a first subtype.
1699 -- For proper matching with controlling type, use base type.
1701 if Ekind
(Target_Formal
) = E_In_Parameter
1702 and then Ekind
(Etype
(Target_Formal
)) = E_Anonymous_Access_Type
1705 Base_Type
(Directly_Designated_Type
(Etype
(Target_Formal
)));
1707 Ftyp
:= Base_Type
(Etype
(Target_Formal
));
1710 -- For concurrent types, the relevant information is found in the
1711 -- Corresponding_Record_Type, rather than the type entity itself.
1713 if Is_Concurrent_Type
(Ftyp
) then
1714 Ftyp
:= Corresponding_Record_Type
(Ftyp
);
1717 if Ekind
(Target_Formal
) = E_In_Parameter
1718 and then Ekind
(Etype
(Target_Formal
)) = E_Anonymous_Access_Type
1719 and then Is_Controlling_Formal
(Target_Formal
)
1722 -- type T is access all <<type of the target formal>>
1723 -- S : Storage_Offset := Storage_Offset!(Formal)
1724 -- - Offset_To_Top (address!(Formal))
1727 Make_Full_Type_Declaration
(Loc
,
1728 Defining_Identifier
=> Make_Temporary
(Loc
, 'T'),
1730 Make_Access_To_Object_Definition
(Loc
,
1731 All_Present
=> True,
1732 Null_Exclusion_Present
=> False,
1733 Constant_Present
=> False,
1734 Subtype_Indication
=>
1735 New_Occurrence_Of
(Ftyp
, Loc
)));
1738 Unchecked_Convert_To
(RTE
(RE_Address
),
1739 New_Occurrence_Of
(Defining_Identifier
(Formal
), Loc
));
1741 if not RTE_Available
(RE_Offset_To_Top
) then
1743 Build_Offset_To_Top
(Loc
, New_Arg
);
1746 Make_Function_Call
(Loc
,
1747 Name
=> New_Occurrence_Of
(RTE
(RE_Offset_To_Top
), Loc
),
1748 Parameter_Associations
=> New_List
(New_Arg
));
1752 Make_Object_Declaration
(Loc
,
1753 Defining_Identifier
=> Make_Temporary
(Loc
, 'S'),
1754 Constant_Present
=> True,
1755 Object_Definition
=>
1756 New_Occurrence_Of
(RTE
(RE_Storage_Offset
), Loc
),
1758 Make_Op_Subtract
(Loc
,
1760 Unchecked_Convert_To
1761 (RTE
(RE_Storage_Offset
),
1763 (Defining_Identifier
(Formal
), Loc
)),
1767 Append_To
(Decl
, Decl_2
);
1768 Append_To
(Decl
, Decl_1
);
1770 -- Reference the new actual. Generate:
1774 Unchecked_Convert_To
1775 (Defining_Identifier
(Decl_2
),
1776 New_Occurrence_Of
(Defining_Identifier
(Decl_1
), Loc
)));
1778 elsif Is_Controlling_Formal
(Target_Formal
) then
1781 -- S1 : Storage_Offset := Storage_Offset!(Formal'Address)
1782 -- - Offset_To_Top (Formal'Address)
1783 -- S2 : Addr_Ptr := Addr_Ptr!(S1)
1786 Make_Attribute_Reference
(Loc
,
1788 New_Occurrence_Of
(Defining_Identifier
(Formal
), Loc
),
1792 if not RTE_Available
(RE_Offset_To_Top
) then
1794 Build_Offset_To_Top
(Loc
, New_Arg
);
1797 Make_Function_Call
(Loc
,
1798 Name
=> New_Occurrence_Of
(RTE
(RE_Offset_To_Top
), Loc
),
1799 Parameter_Associations
=> New_List
(New_Arg
));
1803 Make_Object_Declaration
(Loc
,
1804 Defining_Identifier
=> Make_Temporary
(Loc
, 'S'),
1805 Constant_Present
=> True,
1806 Object_Definition
=>
1807 New_Occurrence_Of
(RTE
(RE_Storage_Offset
), Loc
),
1809 Make_Op_Subtract
(Loc
,
1811 Unchecked_Convert_To
1812 (RTE
(RE_Storage_Offset
),
1813 Make_Attribute_Reference
(Loc
,
1816 (Defining_Identifier
(Formal
), Loc
),
1817 Attribute_Name
=> Name_Address
)),
1822 Make_Object_Declaration
(Loc
,
1823 Defining_Identifier
=> Make_Temporary
(Loc
, 'S'),
1824 Constant_Present
=> True,
1825 Object_Definition
=>
1826 New_Occurrence_Of
(RTE
(RE_Addr_Ptr
), Loc
),
1828 Unchecked_Convert_To
1830 New_Occurrence_Of
(Defining_Identifier
(Decl_1
), Loc
)));
1832 Append_To
(Decl
, Decl_1
);
1833 Append_To
(Decl
, Decl_2
);
1835 -- Reference the new actual, generate:
1836 -- Target_Formal (S2.all)
1839 Unchecked_Convert_To
(Ftyp
,
1840 Make_Explicit_Dereference
(Loc
,
1841 New_Occurrence_Of
(Defining_Identifier
(Decl_2
), Loc
))));
1843 -- Ensure proper matching of access types. Required to avoid
1844 -- reporting spurious errors.
1846 elsif Is_Access_Type
(Etype
(Target_Formal
)) then
1848 Unchecked_Convert_To
(Base_Type
(Etype
(Target_Formal
)),
1849 New_Occurrence_Of
(Defining_Identifier
(Formal
), Loc
)));
1851 -- No special management required for this actual
1855 New_Occurrence_Of
(Defining_Identifier
(Formal
), Loc
));
1858 Next_Formal
(Target_Formal
);
1862 Thunk_Id
:= Make_Temporary
(Loc
, 'T');
1863 Set_Ekind
(Thunk_Id
, Ekind
(Prim
));
1864 Set_Is_Thunk
(Thunk_Id
);
1865 Set_Convention
(Thunk_Id
, Convention
(Prim
));
1866 Set_Thunk_Entity
(Thunk_Id
, Target
);
1870 if Ekind
(Target
) = E_Procedure
then
1872 Make_Subprogram_Body
(Loc
,
1874 Make_Procedure_Specification
(Loc
,
1875 Defining_Unit_Name
=> Thunk_Id
,
1876 Parameter_Specifications
=> Formals
),
1877 Declarations
=> Decl
,
1878 Handled_Statement_Sequence
=>
1879 Make_Handled_Sequence_Of_Statements
(Loc
,
1880 Statements
=> New_List
(
1881 Make_Procedure_Call_Statement
(Loc
,
1882 Name
=> New_Occurrence_Of
(Target
, Loc
),
1883 Parameter_Associations
=> Actuals
))));
1887 else pragma Assert
(Ekind
(Target
) = E_Function
);
1889 Result_Def
: Node_Id
;
1890 Call_Node
: Node_Id
;
1894 Make_Function_Call
(Loc
,
1895 Name
=> New_Occurrence_Of
(Target
, Loc
),
1896 Parameter_Associations
=> Actuals
);
1898 if not Is_Interface
(Etype
(Prim
)) then
1899 Result_Def
:= New_Copy
(Result_Definition
(Parent
(Target
)));
1901 -- Thunk of function returning a class-wide interface object. No
1902 -- extra displacement needed since the displacement is generated
1903 -- in the return statement of Prim. Example:
1905 -- type Iface is interface ...
1906 -- function F (O : Iface) return Iface'Class;
1908 -- type T is new ... and Iface with ...
1909 -- function F (O : T) return Iface'Class;
1911 elsif Is_Class_Wide_Type
(Etype
(Prim
)) then
1912 Result_Def
:= New_Occurrence_Of
(Etype
(Prim
), Loc
);
1914 -- Thunk of function returning an interface object. Displacement
1917 -- type Iface is interface ...
1918 -- function F (O : Iface) return Iface;
1920 -- type T is new ... and Iface with ...
1921 -- function F (O : T) return T;
1925 New_Occurrence_Of
(Class_Wide_Type
(Etype
(Prim
)), Loc
);
1927 -- Adding implicit conversion to force the displacement of
1928 -- the pointer to the object to reference the corresponding
1929 -- secondary dispatch table.
1932 Make_Type_Conversion
(Loc
,
1934 New_Occurrence_Of
(Class_Wide_Type
(Etype
(Prim
)), Loc
),
1935 Expression
=> Relocate_Node
(Call_Node
));
1939 Make_Subprogram_Body
(Loc
,
1941 Make_Function_Specification
(Loc
,
1942 Defining_Unit_Name
=> Thunk_Id
,
1943 Parameter_Specifications
=> Formals
,
1944 Result_Definition
=> Result_Def
),
1945 Declarations
=> Decl
,
1946 Handled_Statement_Sequence
=>
1947 Make_Handled_Sequence_Of_Statements
(Loc
,
1948 Statements
=> New_List
(
1949 Make_Simple_Return_Statement
(Loc
, Call_Node
))));
1952 end Expand_Interface_Thunk
;
1954 --------------------------
1955 -- Has_CPP_Constructors --
1956 --------------------------
1958 function Has_CPP_Constructors
(Typ
: Entity_Id
) return Boolean is
1962 -- Look for the constructor entities
1964 E
:= Next_Entity
(Typ
);
1965 while Present
(E
) loop
1966 if Ekind
(E
) = E_Function
and then Is_Constructor
(E
) then
1974 end Has_CPP_Constructors
;
1980 function Has_DT
(Typ
: Entity_Id
) return Boolean is
1982 return not Is_Interface
(Typ
)
1983 and then not Restriction_Active
(No_Dispatching_Calls
);
1986 ----------------------------------
1987 -- Is_Expanded_Dispatching_Call --
1988 ----------------------------------
1990 function Is_Expanded_Dispatching_Call
(N
: Node_Id
) return Boolean is
1992 return Nkind
(N
) in N_Subprogram_Call
1993 and then Nkind
(Name
(N
)) = N_Explicit_Dereference
1994 and then Is_Dispatch_Table_Entity
(Etype
(Name
(N
)));
1995 end Is_Expanded_Dispatching_Call
;
1997 -----------------------------------------
1998 -- Is_Predefined_Dispatching_Operation --
1999 -----------------------------------------
2001 function Is_Predefined_Dispatching_Operation
2002 (E
: Entity_Id
) return Boolean
2004 TSS_Name
: TSS_Name_Type
;
2007 if not Is_Dispatching_Operation
(E
) then
2011 Get_Name_String
(Chars
(E
));
2013 -- Most predefined primitives have internally generated names. Equality
2014 -- must be treated differently; the predefined operation is recognized
2015 -- as a homogeneous binary operator that returns Boolean.
2017 if Name_Len
> TSS_Name_Type
'Last then
2018 TSS_Name
:= TSS_Name_Type
(Name_Buffer
(Name_Len
- TSS_Name
'Length + 1
2020 if Chars
(E
) = Name_uSize
2021 or else TSS_Name
= TSS_Stream_Read
2022 or else TSS_Name
= TSS_Stream_Write
2023 or else TSS_Name
= TSS_Stream_Input
2024 or else TSS_Name
= TSS_Stream_Output
2026 (Chars
(E
) = Name_Op_Eq
2027 and then Etype
(First_Formal
(E
)) = Etype
(Last_Formal
(E
)))
2028 or else Chars
(E
) = Name_uAssign
2029 or else TSS_Name
= TSS_Deep_Adjust
2030 or else TSS_Name
= TSS_Deep_Finalize
2031 or else Is_Predefined_Interface_Primitive
(E
)
2038 end Is_Predefined_Dispatching_Operation
;
2040 ---------------------------------------
2041 -- Is_Predefined_Internal_Operation --
2042 ---------------------------------------
2044 function Is_Predefined_Internal_Operation
2045 (E
: Entity_Id
) return Boolean
2047 TSS_Name
: TSS_Name_Type
;
2050 if not Is_Dispatching_Operation
(E
) then
2054 Get_Name_String
(Chars
(E
));
2056 -- Most predefined primitives have internally generated names. Equality
2057 -- must be treated differently; the predefined operation is recognized
2058 -- as a homogeneous binary operator that returns Boolean.
2060 if Name_Len
> TSS_Name_Type
'Last then
2063 (Name_Buffer
(Name_Len
- TSS_Name
'Length + 1 .. Name_Len
));
2065 if Nam_In
(Chars
(E
), Name_uSize
, Name_uAssign
)
2067 (Chars
(E
) = Name_Op_Eq
2068 and then Etype
(First_Formal
(E
)) = Etype
(Last_Formal
(E
)))
2069 or else TSS_Name
= TSS_Deep_Adjust
2070 or else TSS_Name
= TSS_Deep_Finalize
2071 or else Is_Predefined_Interface_Primitive
(E
)
2078 end Is_Predefined_Internal_Operation
;
2080 -------------------------------------
2081 -- Is_Predefined_Dispatching_Alias --
2082 -------------------------------------
2084 function Is_Predefined_Dispatching_Alias
(Prim
: Entity_Id
) return Boolean
2087 return not Is_Predefined_Dispatching_Operation
(Prim
)
2088 and then Present
(Alias
(Prim
))
2089 and then Is_Predefined_Dispatching_Operation
(Ultimate_Alias
(Prim
));
2090 end Is_Predefined_Dispatching_Alias
;
2092 ---------------------------------------
2093 -- Is_Predefined_Interface_Primitive --
2094 ---------------------------------------
2096 function Is_Predefined_Interface_Primitive
(E
: Entity_Id
) return Boolean is
2098 -- In VM targets we don't restrict the functionality of this test to
2099 -- compiling in Ada 2005 mode since in VM targets any tagged type has
2100 -- these primitives.
2102 return (Ada_Version
>= Ada_2005
or else not Tagged_Type_Expansion
)
2103 and then Nam_In
(Chars
(E
), Name_uDisp_Asynchronous_Select
,
2104 Name_uDisp_Conditional_Select
,
2105 Name_uDisp_Get_Prim_Op_Kind
,
2106 Name_uDisp_Get_Task_Id
,
2108 Name_uDisp_Timed_Select
);
2109 end Is_Predefined_Interface_Primitive
;
2111 ----------------------------------------
2112 -- Make_Disp_Asynchronous_Select_Body --
2113 ----------------------------------------
2115 -- For interface types, generate:
2117 -- procedure _Disp_Asynchronous_Select
2118 -- (T : in out <Typ>;
2120 -- P : System.Address;
2121 -- B : out System.Storage_Elements.Dummy_Communication_Block;
2126 -- C := Ada.Tags.POK_Function;
2127 -- end _Disp_Asynchronous_Select;
2129 -- For protected types, generate:
2131 -- procedure _Disp_Asynchronous_Select
2132 -- (T : in out <Typ>;
2134 -- P : System.Address;
2135 -- B : out System.Storage_Elements.Dummy_Communication_Block;
2139 -- Ada.Tags.Get_Entry_Index (Ada.Tags.Tag (<Typ>VP, S));
2140 -- Bnn : System.Tasking.Protected_Objects.Operations.
2141 -- Communication_Block;
2143 -- System.Tasking.Protected_Objects.Operations.Protected_Entry_Call
2144 -- (T._object'Access,
2145 -- System.Tasking.Protected_Objects.Protected_Entry_Index (I),
2147 -- System.Tasking.Asynchronous_Call,
2149 -- B := System.Storage_Elements.Dummy_Communication_Block (Bnn);
2150 -- end _Disp_Asynchronous_Select;
2152 -- For task types, generate:
2154 -- procedure _Disp_Asynchronous_Select
2155 -- (T : in out <Typ>;
2157 -- P : System.Address;
2158 -- B : out System.Storage_Elements.Dummy_Communication_Block;
2162 -- Ada.Tags.Get_Entry_Index (Ada.Tags.Tag (<Typ>VP, S));
2164 -- System.Tasking.Rendezvous.Task_Entry_Call
2166 -- System.Tasking.Task_Entry_Index (I),
2168 -- System.Tasking.Asynchronous_Call,
2170 -- end _Disp_Asynchronous_Select;
2172 function Make_Disp_Asynchronous_Select_Body
2173 (Typ
: Entity_Id
) return Node_Id
2175 Com_Block
: Entity_Id
;
2176 Conc_Typ
: Entity_Id
:= Empty
;
2177 Decls
: constant List_Id
:= New_List
;
2178 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
2180 Stmts
: constant List_Id
:= New_List
;
2184 pragma Assert
(not Restriction_Active
(No_Dispatching_Calls
));
2186 -- Null body is generated for interface types
2188 if Is_Interface
(Typ
) then
2190 Make_Subprogram_Body
(Loc
,
2192 Make_Disp_Asynchronous_Select_Spec
(Typ
),
2193 Declarations
=> New_List
,
2194 Handled_Statement_Sequence
=>
2195 Make_Handled_Sequence_Of_Statements
(Loc
,
2197 Make_Assignment_Statement
(Loc
,
2198 Name
=> Make_Identifier
(Loc
, Name_uF
),
2199 Expression
=> New_Occurrence_Of
(Standard_False
, Loc
)))));
2202 if Is_Concurrent_Record_Type
(Typ
) then
2203 Conc_Typ
:= Corresponding_Concurrent_Type
(Typ
);
2207 -- Ada.Tags.Get_Entry_Index (Ada.Tags.Tag! (<type>VP), S);
2209 -- where I will be used to capture the entry index of the primitive
2210 -- wrapper at position S.
2212 if Tagged_Type_Expansion
then
2214 Unchecked_Convert_To
(RTE
(RE_Tag
),
2216 (Node
(First_Elmt
(Access_Disp_Table
(Typ
))), Loc
));
2219 Make_Attribute_Reference
(Loc
,
2220 Prefix
=> New_Occurrence_Of
(Typ
, Loc
),
2221 Attribute_Name
=> Name_Tag
);
2225 Make_Object_Declaration
(Loc
,
2226 Defining_Identifier
=>
2227 Make_Defining_Identifier
(Loc
, Name_uI
),
2228 Object_Definition
=>
2229 New_Occurrence_Of
(Standard_Integer
, Loc
),
2231 Make_Function_Call
(Loc
,
2233 New_Occurrence_Of
(RTE
(RE_Get_Entry_Index
), Loc
),
2234 Parameter_Associations
=>
2235 New_List
(Tag_Node
, Make_Identifier
(Loc
, Name_uS
)))));
2237 if Ekind
(Conc_Typ
) = E_Protected_Type
then
2240 -- Bnn : Communication_Block;
2242 Com_Block
:= Make_Temporary
(Loc
, 'B');
2244 Make_Object_Declaration
(Loc
,
2245 Defining_Identifier
=> Com_Block
,
2246 Object_Definition
=>
2247 New_Occurrence_Of
(RTE
(RE_Communication_Block
), Loc
)));
2249 -- Build T._object'Access for calls below
2252 Make_Attribute_Reference
(Loc
,
2253 Attribute_Name
=> Name_Unchecked_Access
,
2255 Make_Selected_Component
(Loc
,
2256 Prefix
=> Make_Identifier
(Loc
, Name_uT
),
2257 Selector_Name
=> Make_Identifier
(Loc
, Name_uObject
)));
2259 case Corresponding_Runtime_Package
(Conc_Typ
) is
2260 when System_Tasking_Protected_Objects_Entries
=>
2263 -- Protected_Entry_Call
2264 -- (T._object'Access, -- Object
2265 -- Protected_Entry_Index! (I), -- E
2266 -- P, -- Uninterpreted_Data
2267 -- Asynchronous_Call, -- Mode
2268 -- Bnn); -- Communication_Block
2270 -- where T is the protected object, I is the entry index, P
2271 -- is the wrapped parameters and B is the name of the
2272 -- communication block.
2275 Make_Procedure_Call_Statement
(Loc
,
2277 New_Occurrence_Of
(RTE
(RE_Protected_Entry_Call
), Loc
),
2278 Parameter_Associations
=>
2282 Make_Unchecked_Type_Conversion
(Loc
, -- entry index
2285 (RTE
(RE_Protected_Entry_Index
), Loc
),
2286 Expression
=> Make_Identifier
(Loc
, Name_uI
)),
2288 Make_Identifier
(Loc
, Name_uP
), -- parameter block
2289 New_Occurrence_Of
-- Asynchronous_Call
2290 (RTE
(RE_Asynchronous_Call
), Loc
),
2291 New_Occurrence_Of
-- comm block
2292 (Com_Block
, Loc
))));
2295 raise Program_Error
;
2299 -- B := Dummy_Communication_Block (Bnn);
2302 Make_Assignment_Statement
(Loc
,
2303 Name
=> Make_Identifier
(Loc
, Name_uB
),
2305 Make_Unchecked_Type_Conversion
(Loc
,
2308 (RTE
(RE_Dummy_Communication_Block
), Loc
),
2309 Expression
=> New_Occurrence_Of
(Com_Block
, Loc
))));
2315 Make_Assignment_Statement
(Loc
,
2316 Name
=> Make_Identifier
(Loc
, Name_uF
),
2317 Expression
=> New_Occurrence_Of
(Standard_False
, Loc
)));
2320 pragma Assert
(Ekind
(Conc_Typ
) = E_Task_Type
);
2324 -- (T._task_id, -- Acceptor
2325 -- Task_Entry_Index! (I), -- E
2326 -- P, -- Uninterpreted_Data
2327 -- Asynchronous_Call, -- Mode
2328 -- F); -- Rendezvous_Successful
2330 -- where T is the task object, I is the entry index, P is the
2331 -- wrapped parameters and F is the status flag.
2334 Make_Procedure_Call_Statement
(Loc
,
2336 New_Occurrence_Of
(RTE
(RE_Task_Entry_Call
), Loc
),
2337 Parameter_Associations
=>
2339 Make_Selected_Component
(Loc
, -- T._task_id
2340 Prefix
=> Make_Identifier
(Loc
, Name_uT
),
2341 Selector_Name
=> Make_Identifier
(Loc
, Name_uTask_Id
)),
2343 Make_Unchecked_Type_Conversion
(Loc
, -- entry index
2345 New_Occurrence_Of
(RTE
(RE_Task_Entry_Index
), Loc
),
2346 Expression
=> Make_Identifier
(Loc
, Name_uI
)),
2348 Make_Identifier
(Loc
, Name_uP
), -- parameter block
2349 New_Occurrence_Of
-- Asynchronous_Call
2350 (RTE
(RE_Asynchronous_Call
), Loc
),
2351 Make_Identifier
(Loc
, Name_uF
)))); -- status flag
2355 -- Ensure that the statements list is non-empty
2358 Make_Assignment_Statement
(Loc
,
2359 Name
=> Make_Identifier
(Loc
, Name_uF
),
2360 Expression
=> New_Occurrence_Of
(Standard_False
, Loc
)));
2364 Make_Subprogram_Body
(Loc
,
2366 Make_Disp_Asynchronous_Select_Spec
(Typ
),
2367 Declarations
=> Decls
,
2368 Handled_Statement_Sequence
=>
2369 Make_Handled_Sequence_Of_Statements
(Loc
, Stmts
));
2370 end Make_Disp_Asynchronous_Select_Body
;
2372 ----------------------------------------
2373 -- Make_Disp_Asynchronous_Select_Spec --
2374 ----------------------------------------
2376 function Make_Disp_Asynchronous_Select_Spec
2377 (Typ
: Entity_Id
) return Node_Id
2379 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
2380 Def_Id
: constant Node_Id
:=
2381 Make_Defining_Identifier
(Loc
,
2382 Name_uDisp_Asynchronous_Select
);
2383 Params
: constant List_Id
:= New_List
;
2386 pragma Assert
(not Restriction_Active
(No_Dispatching_Calls
));
2388 -- T : in out Typ; -- Object parameter
2389 -- S : Integer; -- Primitive operation slot
2390 -- P : Address; -- Wrapped parameters
2391 -- B : out Dummy_Communication_Block; -- Communication block dummy
2392 -- F : out Boolean; -- Status flag
2394 Append_List_To
(Params
, New_List
(
2396 Make_Parameter_Specification
(Loc
,
2397 Defining_Identifier
=> Make_Defining_Identifier
(Loc
, Name_uT
),
2398 Parameter_Type
=> New_Occurrence_Of
(Typ
, Loc
),
2400 Out_Present
=> True),
2402 Make_Parameter_Specification
(Loc
,
2403 Defining_Identifier
=> Make_Defining_Identifier
(Loc
, Name_uS
),
2404 Parameter_Type
=> New_Occurrence_Of
(Standard_Integer
, Loc
)),
2406 Make_Parameter_Specification
(Loc
,
2407 Defining_Identifier
=> Make_Defining_Identifier
(Loc
, Name_uP
),
2408 Parameter_Type
=> New_Occurrence_Of
(RTE
(RE_Address
), Loc
)),
2410 Make_Parameter_Specification
(Loc
,
2411 Defining_Identifier
=> Make_Defining_Identifier
(Loc
, Name_uB
),
2413 New_Occurrence_Of
(RTE
(RE_Dummy_Communication_Block
), Loc
),
2414 Out_Present
=> True),
2416 Make_Parameter_Specification
(Loc
,
2417 Defining_Identifier
=> Make_Defining_Identifier
(Loc
, Name_uF
),
2418 Parameter_Type
=> New_Occurrence_Of
(Standard_Boolean
, Loc
),
2419 Out_Present
=> True)));
2422 Make_Procedure_Specification
(Loc
,
2423 Defining_Unit_Name
=> Def_Id
,
2424 Parameter_Specifications
=> Params
);
2425 end Make_Disp_Asynchronous_Select_Spec
;
2427 ---------------------------------------
2428 -- Make_Disp_Conditional_Select_Body --
2429 ---------------------------------------
2431 -- For interface types, generate:
2433 -- procedure _Disp_Conditional_Select
2434 -- (T : in out <Typ>;
2436 -- P : System.Address;
2437 -- C : out Ada.Tags.Prim_Op_Kind;
2442 -- C := Ada.Tags.POK_Function;
2443 -- end _Disp_Conditional_Select;
2445 -- For protected types, generate:
2447 -- procedure _Disp_Conditional_Select
2448 -- (T : in out <Typ>;
2450 -- P : System.Address;
2451 -- C : out Ada.Tags.Prim_Op_Kind;
2455 -- Bnn : System.Tasking.Protected_Objects.Operations.
2456 -- Communication_Block;
2459 -- C := Ada.Tags.Get_Prim_Op_Kind (Ada.Tags.Tag (<Typ>VP, S));
2461 -- if C = Ada.Tags.POK_Procedure
2462 -- or else C = Ada.Tags.POK_Protected_Procedure
2463 -- or else C = Ada.Tags.POK_Task_Procedure
2469 -- I := Ada.Tags.Get_Entry_Index (Ada.Tags.Tag (<Typ>VP, S));
2470 -- System.Tasking.Protected_Objects.Operations.Protected_Entry_Call
2471 -- (T.object'Access,
2472 -- System.Tasking.Protected_Objects.Protected_Entry_Index (I),
2474 -- System.Tasking.Conditional_Call,
2476 -- F := not Cancelled (Bnn);
2477 -- end _Disp_Conditional_Select;
2479 -- For task types, generate:
2481 -- procedure _Disp_Conditional_Select
2482 -- (T : in out <Typ>;
2484 -- P : System.Address;
2485 -- C : out Ada.Tags.Prim_Op_Kind;
2491 -- I := Ada.Tags.Get_Entry_Index (Ada.Tags.Tag (<Typ>VP, S));
2492 -- System.Tasking.Rendezvous.Task_Entry_Call
2494 -- System.Tasking.Task_Entry_Index (I),
2496 -- System.Tasking.Conditional_Call,
2498 -- end _Disp_Conditional_Select;
2500 function Make_Disp_Conditional_Select_Body
2501 (Typ
: Entity_Id
) return Node_Id
2503 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
2504 Blk_Nam
: Entity_Id
;
2505 Conc_Typ
: Entity_Id
:= Empty
;
2506 Decls
: constant List_Id
:= New_List
;
2508 Stmts
: constant List_Id
:= New_List
;
2512 pragma Assert
(not Restriction_Active
(No_Dispatching_Calls
));
2514 -- Null body is generated for interface types
2516 if Is_Interface
(Typ
) then
2518 Make_Subprogram_Body
(Loc
,
2520 Make_Disp_Conditional_Select_Spec
(Typ
),
2521 Declarations
=> No_List
,
2522 Handled_Statement_Sequence
=>
2523 Make_Handled_Sequence_Of_Statements
(Loc
,
2524 New_List
(Make_Assignment_Statement
(Loc
,
2525 Name
=> Make_Identifier
(Loc
, Name_uF
),
2526 Expression
=> New_Occurrence_Of
(Standard_False
, Loc
)))));
2529 if Is_Concurrent_Record_Type
(Typ
) then
2530 Conc_Typ
:= Corresponding_Concurrent_Type
(Typ
);
2535 -- where I will be used to capture the entry index of the primitive
2536 -- wrapper at position S.
2539 Make_Object_Declaration
(Loc
,
2540 Defining_Identifier
=> Make_Defining_Identifier
(Loc
, Name_uI
),
2541 Object_Definition
=>
2542 New_Occurrence_Of
(Standard_Integer
, Loc
)));
2545 -- C := Ada.Tags.Get_Prim_Op_Kind (Ada.Tags.Tag! (<type>VP), S);
2547 -- if C = POK_Procedure
2548 -- or else C = POK_Protected_Procedure
2549 -- or else C = POK_Task_Procedure;
2555 Build_Common_Dispatching_Select_Statements
(Typ
, Stmts
);
2558 -- Bnn : Communication_Block;
2560 -- where Bnn is the name of the communication block used in the
2561 -- call to Protected_Entry_Call.
2563 Blk_Nam
:= Make_Temporary
(Loc
, 'B');
2565 Make_Object_Declaration
(Loc
,
2566 Defining_Identifier
=> Blk_Nam
,
2567 Object_Definition
=>
2568 New_Occurrence_Of
(RTE
(RE_Communication_Block
), Loc
)));
2571 -- I := Ada.Tags.Get_Entry_Index (Ada.Tags.Tag! (<type>VP), S);
2573 -- I is the entry index and S is the dispatch table slot
2575 if Tagged_Type_Expansion
then
2577 Unchecked_Convert_To
(RTE
(RE_Tag
),
2579 (Node
(First_Elmt
(Access_Disp_Table
(Typ
))), Loc
));
2583 Make_Attribute_Reference
(Loc
,
2584 Prefix
=> New_Occurrence_Of
(Typ
, Loc
),
2585 Attribute_Name
=> Name_Tag
);
2589 Make_Assignment_Statement
(Loc
,
2590 Name
=> Make_Identifier
(Loc
, Name_uI
),
2592 Make_Function_Call
(Loc
,
2594 New_Occurrence_Of
(RTE
(RE_Get_Entry_Index
), Loc
),
2595 Parameter_Associations
=> New_List
(
2597 Make_Identifier
(Loc
, Name_uS
)))));
2599 if Ekind
(Conc_Typ
) = E_Protected_Type
then
2601 Obj_Ref
:= -- T._object'Access
2602 Make_Attribute_Reference
(Loc
,
2603 Attribute_Name
=> Name_Unchecked_Access
,
2605 Make_Selected_Component
(Loc
,
2606 Prefix
=> Make_Identifier
(Loc
, Name_uT
),
2607 Selector_Name
=> Make_Identifier
(Loc
, Name_uObject
)));
2609 case Corresponding_Runtime_Package
(Conc_Typ
) is
2610 when System_Tasking_Protected_Objects_Entries
=>
2613 -- Protected_Entry_Call
2614 -- (T._object'Access, -- Object
2615 -- Protected_Entry_Index! (I), -- E
2616 -- P, -- Uninterpreted_Data
2617 -- Conditional_Call, -- Mode
2620 -- where T is the protected object, I is the entry index, P
2621 -- are the wrapped parameters and Bnn is the name of the
2622 -- communication block.
2625 Make_Procedure_Call_Statement
(Loc
,
2627 New_Occurrence_Of
(RTE
(RE_Protected_Entry_Call
), Loc
),
2628 Parameter_Associations
=> New_List
(
2631 Make_Unchecked_Type_Conversion
(Loc
, -- entry index
2634 (RTE
(RE_Protected_Entry_Index
), Loc
),
2635 Expression
=> Make_Identifier
(Loc
, Name_uI
)),
2637 Make_Identifier
(Loc
, Name_uP
), -- parameter block
2639 New_Occurrence_Of
-- Conditional_Call
2640 (RTE
(RE_Conditional_Call
), Loc
),
2641 New_Occurrence_Of
-- Bnn
2644 when System_Tasking_Protected_Objects_Single_Entry
=>
2646 -- If we are compiling for a restricted run-time, the call
2647 -- uses the simpler form.
2650 Make_Procedure_Call_Statement
(Loc
,
2653 (RTE
(RE_Protected_Single_Entry_Call
), Loc
),
2654 Parameter_Associations
=> New_List
(
2657 Make_Attribute_Reference
(Loc
,
2658 Prefix
=> Make_Identifier
(Loc
, Name_uP
),
2659 Attribute_Name
=> Name_Address
),
2662 (RTE
(RE_Conditional_Call
), Loc
))));
2664 raise Program_Error
;
2668 -- F := not Cancelled (Bnn);
2670 -- where F is the success flag. The status of Cancelled is negated
2671 -- in order to match the behavior of the version for task types.
2674 Make_Assignment_Statement
(Loc
,
2675 Name
=> Make_Identifier
(Loc
, Name_uF
),
2679 Make_Function_Call
(Loc
,
2681 New_Occurrence_Of
(RTE
(RE_Cancelled
), Loc
),
2682 Parameter_Associations
=> New_List
(
2683 New_Occurrence_Of
(Blk_Nam
, Loc
))))));
2685 pragma Assert
(Ekind
(Conc_Typ
) = E_Task_Type
);
2689 -- (T._task_id, -- Acceptor
2690 -- Task_Entry_Index! (I), -- E
2691 -- P, -- Uninterpreted_Data
2692 -- Conditional_Call, -- Mode
2693 -- F); -- Rendezvous_Successful
2695 -- where T is the task object, I is the entry index, P are the
2696 -- wrapped parameters and F is the status flag.
2699 Make_Procedure_Call_Statement
(Loc
,
2701 New_Occurrence_Of
(RTE
(RE_Task_Entry_Call
), Loc
),
2702 Parameter_Associations
=> New_List
(
2704 Make_Selected_Component
(Loc
, -- T._task_id
2705 Prefix
=> Make_Identifier
(Loc
, Name_uT
),
2706 Selector_Name
=> Make_Identifier
(Loc
, Name_uTask_Id
)),
2708 Make_Unchecked_Type_Conversion
(Loc
, -- entry index
2710 New_Occurrence_Of
(RTE
(RE_Task_Entry_Index
), Loc
),
2711 Expression
=> Make_Identifier
(Loc
, Name_uI
)),
2713 Make_Identifier
(Loc
, Name_uP
), -- parameter block
2714 New_Occurrence_Of
-- Conditional_Call
2715 (RTE
(RE_Conditional_Call
), Loc
),
2716 Make_Identifier
(Loc
, Name_uF
)))); -- status flag
2720 -- Initialize out parameters
2723 Make_Assignment_Statement
(Loc
,
2724 Name
=> Make_Identifier
(Loc
, Name_uF
),
2725 Expression
=> New_Occurrence_Of
(Standard_False
, Loc
)));
2727 Make_Assignment_Statement
(Loc
,
2728 Name
=> Make_Identifier
(Loc
, Name_uC
),
2729 Expression
=> New_Occurrence_Of
(RTE
(RE_POK_Function
), Loc
)));
2733 Make_Subprogram_Body
(Loc
,
2735 Make_Disp_Conditional_Select_Spec
(Typ
),
2736 Declarations
=> Decls
,
2737 Handled_Statement_Sequence
=>
2738 Make_Handled_Sequence_Of_Statements
(Loc
, Stmts
));
2739 end Make_Disp_Conditional_Select_Body
;
2741 ---------------------------------------
2742 -- Make_Disp_Conditional_Select_Spec --
2743 ---------------------------------------
2745 function Make_Disp_Conditional_Select_Spec
2746 (Typ
: Entity_Id
) return Node_Id
2748 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
2749 Def_Id
: constant Node_Id
:=
2750 Make_Defining_Identifier
(Loc
,
2751 Name_uDisp_Conditional_Select
);
2752 Params
: constant List_Id
:= New_List
;
2755 pragma Assert
(not Restriction_Active
(No_Dispatching_Calls
));
2757 -- T : in out Typ; -- Object parameter
2758 -- S : Integer; -- Primitive operation slot
2759 -- P : Address; -- Wrapped parameters
2760 -- C : out Prim_Op_Kind; -- Call kind
2761 -- F : out Boolean; -- Status flag
2763 Append_List_To
(Params
, New_List
(
2765 Make_Parameter_Specification
(Loc
,
2766 Defining_Identifier
=> Make_Defining_Identifier
(Loc
, Name_uT
),
2767 Parameter_Type
=> New_Occurrence_Of
(Typ
, Loc
),
2769 Out_Present
=> True),
2771 Make_Parameter_Specification
(Loc
,
2772 Defining_Identifier
=> Make_Defining_Identifier
(Loc
, Name_uS
),
2773 Parameter_Type
=> New_Occurrence_Of
(Standard_Integer
, Loc
)),
2775 Make_Parameter_Specification
(Loc
,
2776 Defining_Identifier
=> Make_Defining_Identifier
(Loc
, Name_uP
),
2777 Parameter_Type
=> New_Occurrence_Of
(RTE
(RE_Address
), Loc
)),
2779 Make_Parameter_Specification
(Loc
,
2780 Defining_Identifier
=> Make_Defining_Identifier
(Loc
, Name_uC
),
2782 New_Occurrence_Of
(RTE
(RE_Prim_Op_Kind
), Loc
),
2783 Out_Present
=> True),
2785 Make_Parameter_Specification
(Loc
,
2786 Defining_Identifier
=> Make_Defining_Identifier
(Loc
, Name_uF
),
2787 Parameter_Type
=> New_Occurrence_Of
(Standard_Boolean
, Loc
),
2788 Out_Present
=> True)));
2791 Make_Procedure_Specification
(Loc
,
2792 Defining_Unit_Name
=> Def_Id
,
2793 Parameter_Specifications
=> Params
);
2794 end Make_Disp_Conditional_Select_Spec
;
2796 -------------------------------------
2797 -- Make_Disp_Get_Prim_Op_Kind_Body --
2798 -------------------------------------
2800 function Make_Disp_Get_Prim_Op_Kind_Body
(Typ
: Entity_Id
) return Node_Id
is
2801 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
2805 pragma Assert
(not Restriction_Active
(No_Dispatching_Calls
));
2807 if Is_Interface
(Typ
) then
2809 Make_Subprogram_Body
(Loc
,
2811 Make_Disp_Get_Prim_Op_Kind_Spec
(Typ
),
2812 Declarations
=> New_List
,
2813 Handled_Statement_Sequence
=>
2814 Make_Handled_Sequence_Of_Statements
(Loc
,
2815 New_List
(Make_Null_Statement
(Loc
))));
2819 -- C := get_prim_op_kind (tag! (<type>VP), S);
2821 -- where C is the out parameter capturing the call kind and S is the
2822 -- dispatch table slot number.
2824 if Tagged_Type_Expansion
then
2826 Unchecked_Convert_To
(RTE
(RE_Tag
),
2828 (Node
(First_Elmt
(Access_Disp_Table
(Typ
))), Loc
));
2832 Make_Attribute_Reference
(Loc
,
2833 Prefix
=> New_Occurrence_Of
(Typ
, Loc
),
2834 Attribute_Name
=> Name_Tag
);
2838 Make_Subprogram_Body
(Loc
,
2840 Make_Disp_Get_Prim_Op_Kind_Spec
(Typ
),
2841 Declarations
=> New_List
,
2842 Handled_Statement_Sequence
=>
2843 Make_Handled_Sequence_Of_Statements
(Loc
,
2845 Make_Assignment_Statement
(Loc
,
2846 Name
=> Make_Identifier
(Loc
, Name_uC
),
2848 Make_Function_Call
(Loc
,
2850 New_Occurrence_Of
(RTE
(RE_Get_Prim_Op_Kind
), Loc
),
2851 Parameter_Associations
=> New_List
(
2853 Make_Identifier
(Loc
, Name_uS
)))))));
2854 end Make_Disp_Get_Prim_Op_Kind_Body
;
2856 -------------------------------------
2857 -- Make_Disp_Get_Prim_Op_Kind_Spec --
2858 -------------------------------------
2860 function Make_Disp_Get_Prim_Op_Kind_Spec
2861 (Typ
: Entity_Id
) return Node_Id
2863 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
2864 Def_Id
: constant Node_Id
:=
2865 Make_Defining_Identifier
(Loc
, Name_uDisp_Get_Prim_Op_Kind
);
2866 Params
: constant List_Id
:= New_List
;
2869 pragma Assert
(not Restriction_Active
(No_Dispatching_Calls
));
2871 -- T : in out Typ; -- Object parameter
2872 -- S : Integer; -- Primitive operation slot
2873 -- C : out Prim_Op_Kind; -- Call kind
2875 Append_List_To
(Params
, New_List
(
2877 Make_Parameter_Specification
(Loc
,
2878 Defining_Identifier
=> Make_Defining_Identifier
(Loc
, Name_uT
),
2879 Parameter_Type
=> New_Occurrence_Of
(Typ
, Loc
),
2881 Out_Present
=> True),
2883 Make_Parameter_Specification
(Loc
,
2884 Defining_Identifier
=> Make_Defining_Identifier
(Loc
, Name_uS
),
2885 Parameter_Type
=> New_Occurrence_Of
(Standard_Integer
, Loc
)),
2887 Make_Parameter_Specification
(Loc
,
2888 Defining_Identifier
=> Make_Defining_Identifier
(Loc
, Name_uC
),
2890 New_Occurrence_Of
(RTE
(RE_Prim_Op_Kind
), Loc
),
2891 Out_Present
=> True)));
2894 Make_Procedure_Specification
(Loc
,
2895 Defining_Unit_Name
=> Def_Id
,
2896 Parameter_Specifications
=> Params
);
2897 end Make_Disp_Get_Prim_Op_Kind_Spec
;
2899 --------------------------------
2900 -- Make_Disp_Get_Task_Id_Body --
2901 --------------------------------
2903 function Make_Disp_Get_Task_Id_Body
2904 (Typ
: Entity_Id
) return Node_Id
2906 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
2910 pragma Assert
(not Restriction_Active
(No_Dispatching_Calls
));
2912 if Is_Concurrent_Record_Type
(Typ
)
2913 and then Ekind
(Corresponding_Concurrent_Type
(Typ
)) = E_Task_Type
2916 -- return To_Address (_T._task_id);
2919 Make_Simple_Return_Statement
(Loc
,
2921 Make_Unchecked_Type_Conversion
(Loc
,
2922 Subtype_Mark
=> New_Occurrence_Of
(RTE
(RE_Address
), Loc
),
2924 Make_Selected_Component
(Loc
,
2925 Prefix
=> Make_Identifier
(Loc
, Name_uT
),
2926 Selector_Name
=> Make_Identifier
(Loc
, Name_uTask_Id
))));
2928 -- A null body is constructed for non-task types
2932 -- return Null_Address;
2935 Make_Simple_Return_Statement
(Loc
,
2936 Expression
=> New_Occurrence_Of
(RTE
(RE_Null_Address
), Loc
));
2940 Make_Subprogram_Body
(Loc
,
2941 Specification
=> Make_Disp_Get_Task_Id_Spec
(Typ
),
2942 Declarations
=> New_List
,
2943 Handled_Statement_Sequence
=>
2944 Make_Handled_Sequence_Of_Statements
(Loc
, New_List
(Ret
)));
2945 end Make_Disp_Get_Task_Id_Body
;
2947 --------------------------------
2948 -- Make_Disp_Get_Task_Id_Spec --
2949 --------------------------------
2951 function Make_Disp_Get_Task_Id_Spec
2952 (Typ
: Entity_Id
) return Node_Id
2954 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
2957 pragma Assert
(not Restriction_Active
(No_Dispatching_Calls
));
2960 Make_Function_Specification
(Loc
,
2961 Defining_Unit_Name
=>
2962 Make_Defining_Identifier
(Loc
, Name_uDisp_Get_Task_Id
),
2963 Parameter_Specifications
=> New_List
(
2964 Make_Parameter_Specification
(Loc
,
2965 Defining_Identifier
=> Make_Defining_Identifier
(Loc
, Name_uT
),
2966 Parameter_Type
=> New_Occurrence_Of
(Typ
, Loc
))),
2967 Result_Definition
=>
2968 New_Occurrence_Of
(RTE
(RE_Address
), Loc
));
2969 end Make_Disp_Get_Task_Id_Spec
;
2971 ----------------------------
2972 -- Make_Disp_Requeue_Body --
2973 ----------------------------
2975 function Make_Disp_Requeue_Body
2976 (Typ
: Entity_Id
) return Node_Id
2978 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
2979 Conc_Typ
: Entity_Id
:= Empty
;
2980 Stmts
: constant List_Id
:= New_List
;
2983 pragma Assert
(not Restriction_Active
(No_Dispatching_Calls
));
2985 -- Null body is generated for interface types and non-concurrent
2988 if Is_Interface
(Typ
)
2989 or else not Is_Concurrent_Record_Type
(Typ
)
2992 Make_Subprogram_Body
(Loc
,
2993 Specification
=> Make_Disp_Requeue_Spec
(Typ
),
2994 Declarations
=> No_List
,
2995 Handled_Statement_Sequence
=>
2996 Make_Handled_Sequence_Of_Statements
(Loc
,
2997 New_List
(Make_Null_Statement
(Loc
))));
3000 Conc_Typ
:= Corresponding_Concurrent_Type
(Typ
);
3002 if Ekind
(Conc_Typ
) = E_Protected_Type
then
3004 -- Generate statements:
3006 -- System.Tasking.Protected_Objects.Operations.
3007 -- Requeue_Protected_Entry
3008 -- (Protection_Entries_Access (P),
3009 -- O._object'Unchecked_Access,
3010 -- Protected_Entry_Index (I),
3013 -- System.Tasking.Protected_Objects.Operations.
3014 -- Requeue_Task_To_Protected_Entry
3015 -- (O._object'Unchecked_Access,
3016 -- Protected_Entry_Index (I),
3020 if Restriction_Active
(No_Entry_Queue
) then
3021 Append_To
(Stmts
, Make_Null_Statement
(Loc
));
3024 Make_If_Statement
(Loc
,
3025 Condition
=> Make_Identifier
(Loc
, Name_uF
),
3030 -- Call to Requeue_Protected_Entry
3032 Make_Procedure_Call_Statement
(Loc
,
3035 (RTE
(RE_Requeue_Protected_Entry
), Loc
),
3036 Parameter_Associations
=>
3039 Make_Unchecked_Type_Conversion
(Loc
, -- PEA (P)
3042 RTE
(RE_Protection_Entries_Access
), Loc
),
3044 Make_Identifier
(Loc
, Name_uP
)),
3046 Make_Attribute_Reference
(Loc
, -- O._object'Acc
3048 Name_Unchecked_Access
,
3050 Make_Selected_Component
(Loc
,
3052 Make_Identifier
(Loc
, Name_uO
),
3054 Make_Identifier
(Loc
, Name_uObject
))),
3056 Make_Unchecked_Type_Conversion
(Loc
, -- entry index
3059 (RTE
(RE_Protected_Entry_Index
), Loc
),
3060 Expression
=> Make_Identifier
(Loc
, Name_uI
)),
3062 Make_Identifier
(Loc
, Name_uA
)))), -- abort status
3067 -- Call to Requeue_Task_To_Protected_Entry
3069 Make_Procedure_Call_Statement
(Loc
,
3072 (RTE
(RE_Requeue_Task_To_Protected_Entry
), Loc
),
3073 Parameter_Associations
=>
3076 Make_Attribute_Reference
(Loc
, -- O._object'Acc
3077 Attribute_Name
=> Name_Unchecked_Access
,
3079 Make_Selected_Component
(Loc
,
3081 Make_Identifier
(Loc
, Name_uO
),
3083 Make_Identifier
(Loc
, Name_uObject
))),
3085 Make_Unchecked_Type_Conversion
(Loc
, -- entry index
3088 (RTE
(RE_Protected_Entry_Index
), Loc
),
3089 Expression
=> Make_Identifier
(Loc
, Name_uI
)),
3091 Make_Identifier
(Loc
, Name_uA
)))))); -- abort status
3095 pragma Assert
(Is_Task_Type
(Conc_Typ
));
3099 -- System.Tasking.Rendezvous.Requeue_Protected_To_Task_Entry
3100 -- (Protection_Entries_Access (P),
3102 -- Task_Entry_Index (I),
3105 -- System.Tasking.Rendezvous.Requeue_Task_Entry
3107 -- Task_Entry_Index (I),
3112 Make_If_Statement
(Loc
,
3113 Condition
=> Make_Identifier
(Loc
, Name_uF
),
3115 Then_Statements
=> New_List
(
3117 -- Call to Requeue_Protected_To_Task_Entry
3119 Make_Procedure_Call_Statement
(Loc
,
3122 (RTE
(RE_Requeue_Protected_To_Task_Entry
), Loc
),
3124 Parameter_Associations
=> New_List
(
3126 Make_Unchecked_Type_Conversion
(Loc
, -- PEA (P)
3129 (RTE
(RE_Protection_Entries_Access
), Loc
),
3130 Expression
=> Make_Identifier
(Loc
, Name_uP
)),
3132 Make_Selected_Component
(Loc
, -- O._task_id
3133 Prefix
=> Make_Identifier
(Loc
, Name_uO
),
3134 Selector_Name
=> Make_Identifier
(Loc
, Name_uTask_Id
)),
3136 Make_Unchecked_Type_Conversion
(Loc
, -- entry index
3138 New_Occurrence_Of
(RTE
(RE_Task_Entry_Index
), Loc
),
3139 Expression
=> Make_Identifier
(Loc
, Name_uI
)),
3141 Make_Identifier
(Loc
, Name_uA
)))), -- abort status
3143 Else_Statements
=> New_List
(
3145 -- Call to Requeue_Task_Entry
3147 Make_Procedure_Call_Statement
(Loc
,
3149 New_Occurrence_Of
(RTE
(RE_Requeue_Task_Entry
), Loc
),
3151 Parameter_Associations
=> New_List
(
3153 Make_Selected_Component
(Loc
, -- O._task_id
3154 Prefix
=> Make_Identifier
(Loc
, Name_uO
),
3155 Selector_Name
=> Make_Identifier
(Loc
, Name_uTask_Id
)),
3157 Make_Unchecked_Type_Conversion
(Loc
, -- entry index
3159 New_Occurrence_Of
(RTE
(RE_Task_Entry_Index
), Loc
),
3160 Expression
=> Make_Identifier
(Loc
, Name_uI
)),
3162 Make_Identifier
(Loc
, Name_uA
)))))); -- abort status
3165 -- Even though no declarations are needed in both cases, we allocate
3166 -- a list for entities added by Freeze.
3169 Make_Subprogram_Body
(Loc
,
3170 Specification
=> Make_Disp_Requeue_Spec
(Typ
),
3171 Declarations
=> New_List
,
3172 Handled_Statement_Sequence
=>
3173 Make_Handled_Sequence_Of_Statements
(Loc
, Stmts
));
3174 end Make_Disp_Requeue_Body
;
3176 ----------------------------
3177 -- Make_Disp_Requeue_Spec --
3178 ----------------------------
3180 function Make_Disp_Requeue_Spec
3181 (Typ
: Entity_Id
) return Node_Id
3183 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
3186 pragma Assert
(not Restriction_Active
(No_Dispatching_Calls
));
3188 -- O : in out Typ; - Object parameter
3189 -- F : Boolean; - Protected (True) / task (False) flag
3190 -- P : Address; - Protection_Entries_Access value
3191 -- I : Entry_Index - Index of entry call
3192 -- A : Boolean - Abort flag
3194 -- Note that the Protection_Entries_Access value is represented as a
3195 -- System.Address in order to avoid dragging in the tasking runtime
3196 -- when compiling sources without tasking constructs.
3199 Make_Procedure_Specification
(Loc
,
3200 Defining_Unit_Name
=>
3201 Make_Defining_Identifier
(Loc
, Name_uDisp_Requeue
),
3203 Parameter_Specifications
=> New_List
(
3205 Make_Parameter_Specification
(Loc
, -- O
3206 Defining_Identifier
=>
3207 Make_Defining_Identifier
(Loc
, Name_uO
),
3209 New_Occurrence_Of
(Typ
, Loc
),
3211 Out_Present
=> True),
3213 Make_Parameter_Specification
(Loc
, -- F
3214 Defining_Identifier
=>
3215 Make_Defining_Identifier
(Loc
, Name_uF
),
3217 New_Occurrence_Of
(Standard_Boolean
, Loc
)),
3219 Make_Parameter_Specification
(Loc
, -- P
3220 Defining_Identifier
=>
3221 Make_Defining_Identifier
(Loc
, Name_uP
),
3223 New_Occurrence_Of
(RTE
(RE_Address
), Loc
)),
3225 Make_Parameter_Specification
(Loc
, -- I
3226 Defining_Identifier
=>
3227 Make_Defining_Identifier
(Loc
, Name_uI
),
3229 New_Occurrence_Of
(Standard_Integer
, Loc
)),
3231 Make_Parameter_Specification
(Loc
, -- A
3232 Defining_Identifier
=>
3233 Make_Defining_Identifier
(Loc
, Name_uA
),
3235 New_Occurrence_Of
(Standard_Boolean
, Loc
))));
3236 end Make_Disp_Requeue_Spec
;
3238 ---------------------------------
3239 -- Make_Disp_Timed_Select_Body --
3240 ---------------------------------
3242 -- For interface types, generate:
3244 -- procedure _Disp_Timed_Select
3245 -- (T : in out <Typ>;
3247 -- P : System.Address;
3250 -- C : out Ada.Tags.Prim_Op_Kind;
3255 -- C := Ada.Tags.POK_Function;
3256 -- end _Disp_Timed_Select;
3258 -- For protected types, generate:
3260 -- procedure _Disp_Timed_Select
3261 -- (T : in out <Typ>;
3263 -- P : System.Address;
3266 -- C : out Ada.Tags.Prim_Op_Kind;
3272 -- C := Ada.Tags.Get_Prim_Op_Kind (Ada.Tags.Tag (<Typ>VP), S);
3274 -- if C = Ada.Tags.POK_Procedure
3275 -- or else C = Ada.Tags.POK_Protected_Procedure
3276 -- or else C = Ada.Tags.POK_Task_Procedure
3282 -- I := Ada.Tags.Get_Entry_Index (Ada.Tags.Tag (<Typ>VP), S);
3283 -- System.Tasking.Protected_Objects.Operations.
3284 -- Timed_Protected_Entry_Call
3285 -- (T._object'Access,
3286 -- System.Tasking.Protected_Objects.Protected_Entry_Index (I),
3291 -- end _Disp_Timed_Select;
3293 -- For task types, generate:
3295 -- procedure _Disp_Timed_Select
3296 -- (T : in out <Typ>;
3298 -- P : System.Address;
3301 -- C : out Ada.Tags.Prim_Op_Kind;
3307 -- I := Ada.Tags.Get_Entry_Index (Ada.Tags.Tag (<Typ>VP), S);
3308 -- System.Tasking.Rendezvous.Timed_Task_Entry_Call
3310 -- System.Tasking.Task_Entry_Index (I),
3315 -- end _Disp_Time_Select;
3317 function Make_Disp_Timed_Select_Body
3318 (Typ
: Entity_Id
) return Node_Id
3320 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
3321 Conc_Typ
: Entity_Id
:= Empty
;
3322 Decls
: constant List_Id
:= New_List
;
3324 Stmts
: constant List_Id
:= New_List
;
3328 pragma Assert
(not Restriction_Active
(No_Dispatching_Calls
));
3330 -- Null body is generated for interface types
3332 if Is_Interface
(Typ
) then
3334 Make_Subprogram_Body
(Loc
,
3335 Specification
=> Make_Disp_Timed_Select_Spec
(Typ
),
3336 Declarations
=> New_List
,
3337 Handled_Statement_Sequence
=>
3338 Make_Handled_Sequence_Of_Statements
(Loc
,
3340 Make_Assignment_Statement
(Loc
,
3341 Name
=> Make_Identifier
(Loc
, Name_uF
),
3342 Expression
=> New_Occurrence_Of
(Standard_False
, Loc
)))));
3345 if Is_Concurrent_Record_Type
(Typ
) then
3346 Conc_Typ
:= Corresponding_Concurrent_Type
(Typ
);
3351 -- where I will be used to capture the entry index of the primitive
3352 -- wrapper at position S.
3355 Make_Object_Declaration
(Loc
,
3356 Defining_Identifier
=> Make_Defining_Identifier
(Loc
, Name_uI
),
3357 Object_Definition
=>
3358 New_Occurrence_Of
(Standard_Integer
, Loc
)));
3361 -- C := Get_Prim_Op_Kind (tag! (<type>VP), S);
3363 -- if C = POK_Procedure
3364 -- or else C = POK_Protected_Procedure
3365 -- or else C = POK_Task_Procedure;
3371 Build_Common_Dispatching_Select_Statements
(Typ
, Stmts
);
3374 -- I := Get_Entry_Index (tag! (<type>VP), S);
3376 -- I is the entry index and S is the dispatch table slot
3378 if Tagged_Type_Expansion
then
3380 Unchecked_Convert_To
(RTE
(RE_Tag
),
3382 (Node
(First_Elmt
(Access_Disp_Table
(Typ
))), Loc
));
3386 Make_Attribute_Reference
(Loc
,
3387 Prefix
=> New_Occurrence_Of
(Typ
, Loc
),
3388 Attribute_Name
=> Name_Tag
);
3392 Make_Assignment_Statement
(Loc
,
3393 Name
=> Make_Identifier
(Loc
, Name_uI
),
3395 Make_Function_Call
(Loc
,
3396 Name
=> New_Occurrence_Of
(RTE
(RE_Get_Entry_Index
), Loc
),
3397 Parameter_Associations
=> New_List
(
3399 Make_Identifier
(Loc
, Name_uS
)))));
3403 if Ekind
(Conc_Typ
) = E_Protected_Type
then
3405 -- Build T._object'Access
3408 Make_Attribute_Reference
(Loc
,
3409 Attribute_Name
=> Name_Unchecked_Access
,
3411 Make_Selected_Component
(Loc
,
3412 Prefix
=> Make_Identifier
(Loc
, Name_uT
),
3413 Selector_Name
=> Make_Identifier
(Loc
, Name_uObject
)));
3415 -- Normal case, No_Entry_Queue restriction not active. In this
3416 -- case we generate:
3418 -- Timed_Protected_Entry_Call
3419 -- (T._object'access,
3420 -- Protected_Entry_Index! (I),
3423 -- where T is the protected object, I is the entry index, P are
3424 -- the wrapped parameters, D is the delay amount, M is the delay
3425 -- mode and F is the status flag.
3427 -- Historically, there was also an implementation for single
3428 -- entry protected types (in s-tposen). However, it was removed
3429 -- by also testing for no No_Select_Statements restriction in
3430 -- Exp_Utils.Corresponding_Runtime_Package. This simplified the
3431 -- implementation of s-tposen.adb and provided consistency between
3432 -- all versions of System.Tasking.Protected_Objects.Single_Entry
3435 case Corresponding_Runtime_Package
(Conc_Typ
) is
3436 when System_Tasking_Protected_Objects_Entries
=>
3438 Make_Procedure_Call_Statement
(Loc
,
3441 (RTE
(RE_Timed_Protected_Entry_Call
), Loc
),
3442 Parameter_Associations
=> New_List
(
3445 Make_Unchecked_Type_Conversion
(Loc
, -- entry index
3448 (RTE
(RE_Protected_Entry_Index
), Loc
),
3449 Expression
=> Make_Identifier
(Loc
, Name_uI
)),
3451 Make_Identifier
(Loc
, Name_uP
), -- parameter block
3452 Make_Identifier
(Loc
, Name_uD
), -- delay
3453 Make_Identifier
(Loc
, Name_uM
), -- delay mode
3454 Make_Identifier
(Loc
, Name_uF
)))); -- status flag
3457 raise Program_Error
;
3463 pragma Assert
(Ekind
(Conc_Typ
) = E_Task_Type
);
3466 -- Timed_Task_Entry_Call (
3468 -- Task_Entry_Index! (I),
3474 -- where T is the task object, I is the entry index, P are the
3475 -- wrapped parameters, D is the delay amount, M is the delay
3476 -- mode and F is the status flag.
3479 Make_Procedure_Call_Statement
(Loc
,
3481 New_Occurrence_Of
(RTE
(RE_Timed_Task_Entry_Call
), Loc
),
3483 Parameter_Associations
=> New_List
(
3484 Make_Selected_Component
(Loc
, -- T._task_id
3485 Prefix
=> Make_Identifier
(Loc
, Name_uT
),
3486 Selector_Name
=> Make_Identifier
(Loc
, Name_uTask_Id
)),
3488 Make_Unchecked_Type_Conversion
(Loc
, -- entry index
3490 New_Occurrence_Of
(RTE
(RE_Task_Entry_Index
), Loc
),
3491 Expression
=> Make_Identifier
(Loc
, Name_uI
)),
3493 Make_Identifier
(Loc
, Name_uP
), -- parameter block
3494 Make_Identifier
(Loc
, Name_uD
), -- delay
3495 Make_Identifier
(Loc
, Name_uM
), -- delay mode
3496 Make_Identifier
(Loc
, Name_uF
)))); -- status flag
3500 -- Initialize out parameters
3503 Make_Assignment_Statement
(Loc
,
3504 Name
=> Make_Identifier
(Loc
, Name_uF
),
3505 Expression
=> New_Occurrence_Of
(Standard_False
, Loc
)));
3507 Make_Assignment_Statement
(Loc
,
3508 Name
=> Make_Identifier
(Loc
, Name_uC
),
3509 Expression
=> New_Occurrence_Of
(RTE
(RE_POK_Function
), Loc
)));
3513 Make_Subprogram_Body
(Loc
,
3514 Specification
=> Make_Disp_Timed_Select_Spec
(Typ
),
3515 Declarations
=> Decls
,
3516 Handled_Statement_Sequence
=>
3517 Make_Handled_Sequence_Of_Statements
(Loc
, Stmts
));
3518 end Make_Disp_Timed_Select_Body
;
3520 ---------------------------------
3521 -- Make_Disp_Timed_Select_Spec --
3522 ---------------------------------
3524 function Make_Disp_Timed_Select_Spec
3525 (Typ
: Entity_Id
) return Node_Id
3527 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
3528 Def_Id
: constant Node_Id
:=
3529 Make_Defining_Identifier
(Loc
,
3530 Name_uDisp_Timed_Select
);
3531 Params
: constant List_Id
:= New_List
;
3534 pragma Assert
(not Restriction_Active
(No_Dispatching_Calls
));
3536 -- T : in out Typ; -- Object parameter
3537 -- S : Integer; -- Primitive operation slot
3538 -- P : Address; -- Wrapped parameters
3539 -- D : Duration; -- Delay
3540 -- M : Integer; -- Delay Mode
3541 -- C : out Prim_Op_Kind; -- Call kind
3542 -- F : out Boolean; -- Status flag
3544 Append_List_To
(Params
, New_List
(
3546 Make_Parameter_Specification
(Loc
,
3547 Defining_Identifier
=> Make_Defining_Identifier
(Loc
, Name_uT
),
3548 Parameter_Type
=> New_Occurrence_Of
(Typ
, Loc
),
3550 Out_Present
=> True),
3552 Make_Parameter_Specification
(Loc
,
3553 Defining_Identifier
=> Make_Defining_Identifier
(Loc
, Name_uS
),
3554 Parameter_Type
=> New_Occurrence_Of
(Standard_Integer
, Loc
)),
3556 Make_Parameter_Specification
(Loc
,
3557 Defining_Identifier
=> Make_Defining_Identifier
(Loc
, Name_uP
),
3558 Parameter_Type
=> New_Occurrence_Of
(RTE
(RE_Address
), Loc
)),
3560 Make_Parameter_Specification
(Loc
,
3561 Defining_Identifier
=> Make_Defining_Identifier
(Loc
, Name_uD
),
3562 Parameter_Type
=> New_Occurrence_Of
(Standard_Duration
, Loc
)),
3564 Make_Parameter_Specification
(Loc
,
3565 Defining_Identifier
=> Make_Defining_Identifier
(Loc
, Name_uM
),
3566 Parameter_Type
=> New_Occurrence_Of
(Standard_Integer
, Loc
)),
3568 Make_Parameter_Specification
(Loc
,
3569 Defining_Identifier
=> Make_Defining_Identifier
(Loc
, Name_uC
),
3571 New_Occurrence_Of
(RTE
(RE_Prim_Op_Kind
), Loc
),
3572 Out_Present
=> True)));
3575 Make_Parameter_Specification
(Loc
,
3576 Defining_Identifier
=> Make_Defining_Identifier
(Loc
, Name_uF
),
3577 Parameter_Type
=> New_Occurrence_Of
(Standard_Boolean
, Loc
),
3578 Out_Present
=> True));
3581 Make_Procedure_Specification
(Loc
,
3582 Defining_Unit_Name
=> Def_Id
,
3583 Parameter_Specifications
=> Params
);
3584 end Make_Disp_Timed_Select_Spec
;
3590 -- The frontend supports two models for expanding dispatch tables
3591 -- associated with library-level defined tagged types: statically and
3592 -- non-statically allocated dispatch tables. In the former case the object
3593 -- containing the dispatch table is constant and it is initialized by means
3594 -- of a positional aggregate. In the latter case, the object containing
3595 -- the dispatch table is a variable which is initialized by means of
3598 -- In case of locally defined tagged types, the object containing the
3599 -- object containing the dispatch table is always a variable (instead of a
3600 -- constant). This is currently required to give support to late overriding
3601 -- of primitives. For example:
3603 -- procedure Example is
3605 -- type T1 is tagged null record;
3606 -- procedure Prim (O : T1);
3609 -- type T2 is new Pkg.T1 with null record;
3610 -- procedure Prim (X : T2) is -- late overriding
3616 -- WARNING: This routine manages Ghost regions. Return statements must be
3617 -- replaced by gotos which jump to the end of the routine and restore the
3620 function Make_DT
(Typ
: Entity_Id
; N
: Node_Id
:= Empty
) return List_Id
is
3621 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
3623 Max_Predef_Prims
: constant Int
:=
3627 (Parent
(RTE
(RE_Max_Predef_Prims
)))));
3629 DT_Decl
: constant Elist_Id
:= New_Elmt_List
;
3630 DT_Aggr
: constant Elist_Id
:= New_Elmt_List
;
3631 -- Entities marked with attribute Is_Dispatch_Table_Entity
3633 procedure Check_Premature_Freezing
3635 Tagged_Type
: Entity_Id
;
3637 -- Verify that all untagged types in the profile of a subprogram are
3638 -- frozen at the point the subprogram is frozen. This enforces the rule
3639 -- on RM 13.14 (14) as modified by AI05-019. At the point a subprogram
3640 -- is frozen, enough must be known about it to build the activation
3641 -- record for it, which requires at least that the size of all
3642 -- parameters be known. Controlling arguments are by-reference,
3643 -- and therefore the rule only applies to untagged types. Typical
3644 -- violation of the rule involves an object declaration that freezes a
3645 -- tagged type, when one of its primitive operations has a type in its
3646 -- profile whose full view has not been analyzed yet. More complex cases
3647 -- involve composite types that have one private unfrozen subcomponent.
3649 procedure Export_DT
(Typ
: Entity_Id
; DT
: Entity_Id
; Index
: Nat
:= 0);
3650 -- Export the dispatch table DT of tagged type Typ. Required to generate
3651 -- forward references and statically allocate the table. For primary
3652 -- dispatch tables Index is 0; for secondary dispatch tables the value
3653 -- of index must match the Suffix_Index value assigned to the table by
3654 -- Make_Tags when generating its unique external name, and it is used to
3655 -- retrieve from the Dispatch_Table_Wrappers list associated with Typ
3656 -- the external name generated by Import_DT.
3658 procedure Make_Secondary_DT
3662 Num_Iface_Prims
: Nat
;
3663 Iface_DT_Ptr
: Entity_Id
;
3664 Predef_Prims_Ptr
: Entity_Id
;
3665 Build_Thunks
: Boolean;
3667 -- Ada 2005 (AI-251): Expand the declarations for a Secondary Dispatch
3668 -- Table of Typ associated with Iface. Each abstract interface of Typ
3669 -- has two secondary dispatch tables: one containing pointers to thunks
3670 -- and another containing pointers to the primitives covering the
3671 -- interface primitives. The former secondary table is generated when
3672 -- Build_Thunks is True, and provides common support for dispatching
3673 -- calls through interface types; the latter secondary table is
3674 -- generated when Build_Thunks is False, and provides support for
3675 -- Generic Dispatching Constructors that dispatch calls through
3676 -- interface types. When constructing this latter table the value of
3677 -- Suffix_Index is -1 to indicate that there is no need to export such
3678 -- table when building statically allocated dispatch tables; a positive
3679 -- value of Suffix_Index must match the Suffix_Index value assigned to
3680 -- this secondary dispatch table by Make_Tags when its unique external
3681 -- name was generated.
3683 ------------------------------
3684 -- Check_Premature_Freezing --
3685 ------------------------------
3687 procedure Check_Premature_Freezing
3689 Tagged_Type
: Entity_Id
;
3694 function Is_Actual_For_Formal_Incomplete_Type
3695 (T
: Entity_Id
) return Boolean;
3696 -- In Ada 2012, if a nested generic has an incomplete formal type,
3697 -- the actual may be (and usually is) a private type whose completion
3698 -- appears later. It is safe to build the dispatch table in this
3699 -- case, gigi will have full views available.
3701 ------------------------------------------
3702 -- Is_Actual_For_Formal_Incomplete_Type --
3703 ------------------------------------------
3705 function Is_Actual_For_Formal_Incomplete_Type
3706 (T
: Entity_Id
) return Boolean
3708 Gen_Par
: Entity_Id
;
3712 if not Is_Generic_Instance
(Current_Scope
)
3713 or else not Used_As_Generic_Actual
(T
)
3717 Gen_Par
:= Generic_Parent
(Parent
(Current_Scope
));
3722 (Generic_Formal_Declarations
3723 (Unit_Declaration_Node
(Gen_Par
)));
3724 while Present
(F
) loop
3725 if Ekind
(Defining_Identifier
(F
)) = E_Incomplete_Type
then
3733 end Is_Actual_For_Formal_Incomplete_Type
;
3735 -- Start of processing for Check_Premature_Freezing
3738 -- Note that if the type is a (subtype of) a generic actual, the
3739 -- actual will have been frozen by the instantiation.
3742 and then Is_Private_Type
(Typ
)
3743 and then No
(Full_View
(Typ
))
3744 and then not Is_Generic_Type
(Typ
)
3745 and then not Is_Tagged_Type
(Typ
)
3746 and then not Is_Frozen
(Typ
)
3747 and then not Is_Generic_Actual_Type
(Typ
)
3749 Error_Msg_Sloc
:= Sloc
(Subp
);
3751 ("declaration must appear after completion of type &", N
, Typ
);
3753 ("\which is an untagged type in the profile of "
3754 & "primitive operation & declared#", N
, Subp
);
3757 Comp
:= Private_Component
(Typ
);
3759 if not Is_Tagged_Type
(Typ
)
3760 and then Present
(Comp
)
3761 and then not Is_Frozen
(Comp
)
3762 and then not Is_Actual_For_Formal_Incomplete_Type
(Comp
)
3764 Error_Msg_Sloc
:= Sloc
(Subp
);
3765 Error_Msg_Node_2
:= Subp
;
3766 Error_Msg_Name_1
:= Chars
(Tagged_Type
);
3768 ("declaration must appear after completion of type &",
3771 ("\which is a component of untagged type& in the profile "
3772 & "of primitive & of type % that is frozen by the "
3773 & "declaration ", N
, Typ
);
3776 end Check_Premature_Freezing
;
3782 procedure Export_DT
(Typ
: Entity_Id
; DT
: Entity_Id
; Index
: Nat
:= 0)
3788 Set_Is_Statically_Allocated
(DT
);
3789 Set_Is_True_Constant
(DT
);
3790 Set_Is_Exported
(DT
);
3793 Elmt
:= First_Elmt
(Dispatch_Table_Wrappers
(Typ
));
3794 while Count
/= Index
loop
3799 pragma Assert
(Related_Type
(Node
(Elmt
)) = Typ
);
3801 Get_External_Name
(Node
(Elmt
));
3802 Set_Interface_Name
(DT
,
3803 Make_String_Literal
(Loc
,
3804 Strval
=> String_From_Name_Buffer
));
3806 -- Ensure proper Sprint output of this implicit importation
3808 Set_Is_Internal
(DT
);
3812 -----------------------
3813 -- Make_Secondary_DT --
3814 -----------------------
3816 procedure Make_Secondary_DT
3820 Num_Iface_Prims
: Nat
;
3821 Iface_DT_Ptr
: Entity_Id
;
3822 Predef_Prims_Ptr
: Entity_Id
;
3823 Build_Thunks
: Boolean;
3826 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
3827 Exporting_Table
: constant Boolean :=
3828 Building_Static_DT
(Typ
)
3829 and then Suffix_Index
> 0;
3830 Iface_DT
: constant Entity_Id
:= Make_Temporary
(Loc
, 'T');
3831 Predef_Prims
: constant Entity_Id
:= Make_Temporary
(Loc
, 'R');
3832 DT_Constr_List
: List_Id
;
3833 DT_Aggr_List
: List_Id
;
3834 Empty_DT
: Boolean := False;
3835 Nb_Predef_Prims
: Nat
:= 0;
3839 OSD_Aggr_List
: List_Id
;
3842 Prim_Elmt
: Elmt_Id
;
3843 Prim_Ops_Aggr_List
: List_Id
;
3846 -- Handle cases in which we do not generate statically allocated
3849 if not Building_Static_DT
(Typ
) then
3850 Set_Ekind
(Predef_Prims
, E_Variable
);
3851 Set_Ekind
(Iface_DT
, E_Variable
);
3853 -- Statically allocated dispatch tables and related entities are
3857 Set_Ekind
(Predef_Prims
, E_Constant
);
3858 Set_Is_Statically_Allocated
(Predef_Prims
);
3859 Set_Is_True_Constant
(Predef_Prims
);
3861 Set_Ekind
(Iface_DT
, E_Constant
);
3862 Set_Is_Statically_Allocated
(Iface_DT
);
3863 Set_Is_True_Constant
(Iface_DT
);
3866 -- Calculate the number of slots of the dispatch table. If the number
3867 -- of primitives of Typ is 0 we reserve a dummy single entry for its
3868 -- DT because at run time the pointer to this dummy entry will be
3871 if Num_Iface_Prims
= 0 then
3875 Nb_Prim
:= Num_Iface_Prims
;
3880 -- Predef_Prims : Address_Array (1 .. Default_Prim_Ops_Count) :=
3881 -- (predef-prim-op-thunk-1'address,
3882 -- predef-prim-op-thunk-2'address,
3884 -- predef-prim-op-thunk-n'address);
3885 -- for Predef_Prims'Alignment use Address'Alignment
3887 -- Stage 1: Calculate the number of predefined primitives
3889 if not Building_Static_DT
(Typ
) then
3890 Nb_Predef_Prims
:= Max_Predef_Prims
;
3892 Prim_Elmt
:= First_Elmt
(Primitive_Operations
(Typ
));
3893 while Present
(Prim_Elmt
) loop
3894 Prim
:= Node
(Prim_Elmt
);
3896 if Is_Predefined_Dispatching_Operation
(Prim
)
3897 and then not Is_Abstract_Subprogram
(Prim
)
3899 Pos
:= UI_To_Int
(DT_Position
(Prim
));
3901 if Pos
> Nb_Predef_Prims
then
3902 Nb_Predef_Prims
:= Pos
;
3906 Next_Elmt
(Prim_Elmt
);
3910 if Generate_SCIL
then
3911 Nb_Predef_Prims
:= 0;
3914 -- Stage 2: Create the thunks associated with the predefined
3915 -- primitives and save their entity to fill the aggregate.
3918 Prim_Table
: array (Nat
range 1 .. Nb_Predef_Prims
) of Entity_Id
;
3920 Thunk_Id
: Entity_Id
;
3921 Thunk_Code
: Node_Id
;
3924 Prim_Ops_Aggr_List
:= New_List
;
3925 Prim_Table
:= (others => Empty
);
3927 if Building_Static_DT
(Typ
) then
3928 Prim_Elmt
:= First_Elmt
(Primitive_Operations
(Typ
));
3929 while Present
(Prim_Elmt
) loop
3930 Prim
:= Node
(Prim_Elmt
);
3932 if Is_Predefined_Dispatching_Operation
(Prim
)
3933 and then not Is_Abstract_Subprogram
(Prim
)
3934 and then not Is_Eliminated
(Prim
)
3935 and then not Generate_SCIL
3936 and then not Present
(Prim_Table
3937 (UI_To_Int
(DT_Position
(Prim
))))
3939 if not Build_Thunks
then
3940 Prim_Table
(UI_To_Int
(DT_Position
(Prim
))) :=
3944 Expand_Interface_Thunk
3945 (Ultimate_Alias
(Prim
), Thunk_Id
, Thunk_Code
);
3947 if Present
(Thunk_Id
) then
3948 Append_To
(Result
, Thunk_Code
);
3949 Prim_Table
(UI_To_Int
(DT_Position
(Prim
))) :=
3955 Next_Elmt
(Prim_Elmt
);
3959 for J
in Prim_Table
'Range loop
3960 if Present
(Prim_Table
(J
)) then
3962 Unchecked_Convert_To
(RTE
(RE_Prim_Ptr
),
3963 Make_Attribute_Reference
(Loc
,
3964 Prefix
=> New_Occurrence_Of
(Prim_Table
(J
), Loc
),
3965 Attribute_Name
=> Name_Unrestricted_Access
));
3967 New_Node
:= Make_Null
(Loc
);
3970 Append_To
(Prim_Ops_Aggr_List
, New_Node
);
3974 Make_Aggregate
(Loc
, Expressions
=> Prim_Ops_Aggr_List
);
3976 -- Remember aggregates initializing dispatch tables
3978 Append_Elmt
(New_Node
, DT_Aggr
);
3981 Make_Subtype_Declaration
(Loc
,
3982 Defining_Identifier
=> Make_Temporary
(Loc
, 'S'),
3983 Subtype_Indication
=>
3984 New_Occurrence_Of
(RTE
(RE_Address_Array
), Loc
));
3986 Append_To
(Result
, Decl
);
3989 Make_Object_Declaration
(Loc
,
3990 Defining_Identifier
=> Predef_Prims
,
3991 Constant_Present
=> Building_Static_DT
(Typ
),
3992 Aliased_Present
=> True,
3993 Object_Definition
=> New_Occurrence_Of
3994 (Defining_Identifier
(Decl
), Loc
),
3995 Expression
=> New_Node
));
3998 Make_Attribute_Definition_Clause
(Loc
,
3999 Name
=> New_Occurrence_Of
(Predef_Prims
, Loc
),
4000 Chars
=> Name_Alignment
,
4002 Make_Attribute_Reference
(Loc
,
4004 New_Occurrence_Of
(RTE
(RE_Integer_Address
), Loc
),
4005 Attribute_Name
=> Name_Alignment
)));
4010 -- OSD : Ada.Tags.Object_Specific_Data (Nb_Prims) :=
4011 -- (OSD_Table => (1 => <value>,
4015 -- Iface_DT : Dispatch_Table (Nb_Prims) :=
4016 -- ([ Signature => <sig-value> ],
4017 -- Tag_Kind => <tag_kind-value>,
4018 -- Predef_Prims => Predef_Prims'Address,
4019 -- Offset_To_Top => 0,
4020 -- OSD => OSD'Address,
4021 -- Prims_Ptr => (prim-op-1'address,
4022 -- prim-op-2'address,
4024 -- prim-op-n'address));
4025 -- for Iface_DT'Alignment use Address'Alignment;
4027 -- Stage 3: Initialize the discriminant and the record components
4029 DT_Constr_List
:= New_List
;
4030 DT_Aggr_List
:= New_List
;
4034 Append_To
(DT_Constr_List
, Make_Integer_Literal
(Loc
, Nb_Prim
));
4035 Append_To
(DT_Aggr_List
, Make_Integer_Literal
(Loc
, Nb_Prim
));
4039 if RTE_Record_Component_Available
(RE_Signature
) then
4040 Append_To
(DT_Aggr_List
,
4041 New_Occurrence_Of
(RTE
(RE_Secondary_DT
), Loc
));
4046 if RTE_Record_Component_Available
(RE_Tag_Kind
) then
4047 Append_To
(DT_Aggr_List
, Tagged_Kind
(Typ
));
4052 Append_To
(DT_Aggr_List
,
4053 Make_Attribute_Reference
(Loc
,
4054 Prefix
=> New_Occurrence_Of
(Predef_Prims
, Loc
),
4055 Attribute_Name
=> Name_Address
));
4057 -- Note: The correct value of Offset_To_Top will be set by the init
4060 Append_To
(DT_Aggr_List
, Make_Integer_Literal
(Loc
, 0));
4062 -- Generate the Object Specific Data table required to dispatch calls
4063 -- through synchronized interfaces.
4066 or else Is_Abstract_Type
(Typ
)
4067 or else Is_Controlled
(Typ
)
4068 or else Restriction_Active
(No_Dispatching_Calls
)
4069 or else not Is_Limited_Type
(Typ
)
4070 or else not Has_Interfaces
(Typ
)
4071 or else not Build_Thunks
4072 or else not RTE_Record_Component_Available
(RE_OSD_Table
)
4074 -- No OSD table required
4076 Append_To
(DT_Aggr_List
,
4077 New_Occurrence_Of
(RTE
(RE_Null_Address
), Loc
));
4080 OSD_Aggr_List
:= New_List
;
4083 Prim_Table
: array (Nat
range 1 .. Nb_Prim
) of Entity_Id
;
4085 Prim_Alias
: Entity_Id
;
4086 Prim_Elmt
: Elmt_Id
;
4092 Prim_Table
:= (others => Empty
);
4093 Prim_Alias
:= Empty
;
4095 Prim_Elmt
:= First_Elmt
(Primitive_Operations
(Typ
));
4096 while Present
(Prim_Elmt
) loop
4097 Prim
:= Node
(Prim_Elmt
);
4099 if Present
(Interface_Alias
(Prim
))
4100 and then Find_Dispatching_Type
4101 (Interface_Alias
(Prim
)) = Iface
4103 Prim_Alias
:= Interface_Alias
(Prim
);
4104 E
:= Ultimate_Alias
(Prim
);
4105 Pos
:= UI_To_Int
(DT_Position
(Prim_Alias
));
4107 if Present
(Prim_Table
(Pos
)) then
4108 pragma Assert
(Prim_Table
(Pos
) = E
);
4112 Prim_Table
(Pos
) := E
;
4114 Append_To
(OSD_Aggr_List
,
4115 Make_Component_Association
(Loc
,
4116 Choices
=> New_List
(
4117 Make_Integer_Literal
(Loc
,
4118 DT_Position
(Prim_Alias
))),
4120 Make_Integer_Literal
(Loc
,
4121 DT_Position
(Alias
(Prim
)))));
4127 Next_Elmt
(Prim_Elmt
);
4129 pragma Assert
(Count
= Nb_Prim
);
4132 OSD
:= Make_Temporary
(Loc
, 'I');
4135 Make_Object_Declaration
(Loc
,
4136 Defining_Identifier
=> OSD
,
4137 Object_Definition
=>
4138 Make_Subtype_Indication
(Loc
,
4140 New_Occurrence_Of
(RTE
(RE_Object_Specific_Data
), Loc
),
4142 Make_Index_Or_Discriminant_Constraint
(Loc
,
4143 Constraints
=> New_List
(
4144 Make_Integer_Literal
(Loc
, Nb_Prim
)))),
4147 Make_Aggregate
(Loc
,
4148 Component_Associations
=> New_List
(
4149 Make_Component_Association
(Loc
,
4150 Choices
=> New_List
(
4152 (RTE_Record_Component
(RE_OSD_Num_Prims
), Loc
)),
4154 Make_Integer_Literal
(Loc
, Nb_Prim
)),
4156 Make_Component_Association
(Loc
,
4157 Choices
=> New_List
(
4159 (RTE_Record_Component
(RE_OSD_Table
), Loc
)),
4160 Expression
=> Make_Aggregate
(Loc
,
4161 Component_Associations
=> OSD_Aggr_List
))))));
4164 Make_Attribute_Definition_Clause
(Loc
,
4165 Name
=> New_Occurrence_Of
(OSD
, Loc
),
4166 Chars
=> Name_Alignment
,
4168 Make_Attribute_Reference
(Loc
,
4170 New_Occurrence_Of
(RTE
(RE_Integer_Address
), Loc
),
4171 Attribute_Name
=> Name_Alignment
)));
4173 -- In secondary dispatch tables the Typeinfo component contains
4174 -- the address of the Object Specific Data (see a-tags.ads)
4176 Append_To
(DT_Aggr_List
,
4177 Make_Attribute_Reference
(Loc
,
4178 Prefix
=> New_Occurrence_Of
(OSD
, Loc
),
4179 Attribute_Name
=> Name_Address
));
4182 -- Initialize the table of primitive operations
4184 Prim_Ops_Aggr_List
:= New_List
;
4187 Append_To
(Prim_Ops_Aggr_List
, Make_Null
(Loc
));
4189 elsif Is_Abstract_Type
(Typ
)
4190 or else not Building_Static_DT
(Typ
)
4192 for J
in 1 .. Nb_Prim
loop
4193 Append_To
(Prim_Ops_Aggr_List
, Make_Null
(Loc
));
4198 CPP_Nb_Prims
: constant Nat
:= CPP_Num_Prims
(Typ
);
4201 Prim_Table
: array (Nat
range 1 .. Nb_Prim
) of Entity_Id
;
4202 Thunk_Code
: Node_Id
;
4203 Thunk_Id
: Entity_Id
;
4206 Prim_Table
:= (others => Empty
);
4208 Prim_Elmt
:= First_Elmt
(Primitive_Operations
(Typ
));
4209 while Present
(Prim_Elmt
) loop
4210 Prim
:= Node
(Prim_Elmt
);
4211 E
:= Ultimate_Alias
(Prim
);
4212 Prim_Pos
:= UI_To_Int
(DT_Position
(E
));
4214 -- Do not reference predefined primitives because they are
4215 -- located in a separate dispatch table; skip abstract and
4216 -- eliminated primitives; skip primitives located in the C++
4217 -- part of the dispatch table because their slot is set by
4220 if not Is_Predefined_Dispatching_Operation
(Prim
)
4221 and then Present
(Interface_Alias
(Prim
))
4222 and then not Is_Abstract_Subprogram
(Alias
(Prim
))
4223 and then not Is_Eliminated
(Alias
(Prim
))
4224 and then (not Is_CPP_Class
(Root_Type
(Typ
))
4225 or else Prim_Pos
> CPP_Nb_Prims
)
4226 and then Find_Dispatching_Type
4227 (Interface_Alias
(Prim
)) = Iface
4229 -- Generate the code of the thunk only if the abstract
4230 -- interface type is not an immediate ancestor of
4231 -- Tagged_Type. Otherwise the DT associated with the
4232 -- interface is the primary DT.
4234 and then not Is_Ancestor
(Iface
, Typ
,
4235 Use_Full_View
=> True)
4237 if not Build_Thunks
then
4239 UI_To_Int
(DT_Position
(Interface_Alias
(Prim
)));
4240 Prim_Table
(Prim_Pos
) := Alias
(Prim
);
4243 Expand_Interface_Thunk
(Prim
, Thunk_Id
, Thunk_Code
);
4245 if Present
(Thunk_Id
) then
4247 UI_To_Int
(DT_Position
(Interface_Alias
(Prim
)));
4249 Prim_Table
(Prim_Pos
) := Thunk_Id
;
4250 Append_To
(Result
, Thunk_Code
);
4255 Next_Elmt
(Prim_Elmt
);
4258 for J
in Prim_Table
'Range loop
4259 if Present
(Prim_Table
(J
)) then
4261 Unchecked_Convert_To
(RTE
(RE_Prim_Ptr
),
4262 Make_Attribute_Reference
(Loc
,
4263 Prefix
=> New_Occurrence_Of
(Prim_Table
(J
), Loc
),
4264 Attribute_Name
=> Name_Unrestricted_Access
));
4267 New_Node
:= Make_Null
(Loc
);
4270 Append_To
(Prim_Ops_Aggr_List
, New_Node
);
4276 Make_Aggregate
(Loc
,
4277 Expressions
=> Prim_Ops_Aggr_List
);
4279 Append_To
(DT_Aggr_List
, New_Node
);
4281 -- Remember aggregates initializing dispatch tables
4283 Append_Elmt
(New_Node
, DT_Aggr
);
4285 -- Note: Secondary dispatch tables cannot be declared constant
4286 -- because the component Offset_To_Top is currently initialized
4287 -- by the IP routine.
4290 Make_Object_Declaration
(Loc
,
4291 Defining_Identifier
=> Iface_DT
,
4292 Aliased_Present
=> True,
4293 Constant_Present
=> False,
4295 Object_Definition
=>
4296 Make_Subtype_Indication
(Loc
,
4297 Subtype_Mark
=> New_Occurrence_Of
4298 (RTE
(RE_Dispatch_Table_Wrapper
), Loc
),
4299 Constraint
=> Make_Index_Or_Discriminant_Constraint
(Loc
,
4300 Constraints
=> DT_Constr_List
)),
4303 Make_Aggregate
(Loc
,
4304 Expressions
=> DT_Aggr_List
)));
4307 Make_Attribute_Definition_Clause
(Loc
,
4308 Name
=> New_Occurrence_Of
(Iface_DT
, Loc
),
4309 Chars
=> Name_Alignment
,
4312 Make_Attribute_Reference
(Loc
,
4314 New_Occurrence_Of
(RTE
(RE_Integer_Address
), Loc
),
4315 Attribute_Name
=> Name_Alignment
)));
4317 if Exporting_Table
then
4318 Export_DT
(Typ
, Iface_DT
, Suffix_Index
);
4320 -- Generate code to create the pointer to the dispatch table
4322 -- Iface_DT_Ptr : Tag := Tag!(DT.Prims_Ptr'Address);
4324 -- Note: This declaration is not added here if the table is exported
4325 -- because in such case Make_Tags has already added this declaration.
4329 Make_Object_Declaration
(Loc
,
4330 Defining_Identifier
=> Iface_DT_Ptr
,
4331 Constant_Present
=> True,
4333 Object_Definition
=>
4334 New_Occurrence_Of
(RTE
(RE_Interface_Tag
), Loc
),
4337 Unchecked_Convert_To
(RTE
(RE_Interface_Tag
),
4338 Make_Attribute_Reference
(Loc
,
4340 Make_Selected_Component
(Loc
,
4341 Prefix
=> New_Occurrence_Of
(Iface_DT
, Loc
),
4344 (RTE_Record_Component
(RE_Prims_Ptr
), Loc
)),
4345 Attribute_Name
=> Name_Address
))));
4349 Make_Object_Declaration
(Loc
,
4350 Defining_Identifier
=> Predef_Prims_Ptr
,
4351 Constant_Present
=> True,
4353 Object_Definition
=>
4354 New_Occurrence_Of
(RTE
(RE_Address
), Loc
),
4357 Make_Attribute_Reference
(Loc
,
4359 Make_Selected_Component
(Loc
,
4360 Prefix
=> New_Occurrence_Of
(Iface_DT
, Loc
),
4363 (RTE_Record_Component
(RE_Predef_Prims
), Loc
)),
4364 Attribute_Name
=> Name_Address
)));
4366 -- Remember entities containing dispatch tables
4368 Append_Elmt
(Predef_Prims
, DT_Decl
);
4369 Append_Elmt
(Iface_DT
, DT_Decl
);
4370 end Make_Secondary_DT
;
4374 Elab_Code
: constant List_Id
:= New_List
;
4375 Result
: constant List_Id
:= New_List
;
4376 Tname
: constant Name_Id
:= Chars
(Typ
);
4378 -- The following name entries are used by Make_DT to generate a number
4379 -- of entities related to a tagged type. These entities may be generated
4380 -- in a scope other than that of the tagged type declaration, and if
4381 -- the entities for two tagged types with the same name happen to be
4382 -- generated in the same scope, we have to take care to use different
4383 -- names. This is achieved by means of a unique serial number appended
4384 -- to each generated entity name.
4386 Name_DT
: constant Name_Id
:=
4387 New_External_Name
(Tname
, 'T', Suffix_Index
=> -1);
4388 Name_Exname
: constant Name_Id
:=
4389 New_External_Name
(Tname
, 'E', Suffix_Index
=> -1);
4390 Name_HT_Link
: constant Name_Id
:=
4391 New_External_Name
(Tname
, 'H', Suffix_Index
=> -1);
4392 Name_Predef_Prims
: constant Name_Id
:=
4393 New_External_Name
(Tname
, 'R', Suffix_Index
=> -1);
4394 Name_SSD
: constant Name_Id
:=
4395 New_External_Name
(Tname
, 'S', Suffix_Index
=> -1);
4396 Name_TSD
: constant Name_Id
:=
4397 New_External_Name
(Tname
, 'B', Suffix_Index
=> -1);
4400 AI_Tag_Elmt
: Elmt_Id
;
4401 AI_Tag_Comp
: Elmt_Id
;
4403 DT_Aggr_List
: List_Id
;
4404 DT_Constr_List
: List_Id
;
4407 HT_Link
: Entity_Id
;
4410 Iface_Table_Node
: Node_Id
;
4411 Mode
: Ghost_Mode_Type
;
4412 Name_ITable
: Name_Id
;
4413 Nb_Predef_Prims
: Nat
:= 0;
4416 Num_Ifaces
: Nat
:= 0;
4417 Parent_Typ
: Entity_Id
;
4418 Predef_Prims
: Entity_Id
;
4420 Prim_Elmt
: Elmt_Id
;
4421 Prim_Ops_Aggr_List
: List_Id
;
4424 Typ_Comps
: Elist_Id
;
4425 Typ_Ifaces
: Elist_Id
;
4427 TSD_Aggr_List
: List_Id
;
4428 TSD_Tags_List
: List_Id
;
4430 -- Start of processing for Make_DT
4433 pragma Assert
(Is_Frozen
(Typ
));
4435 -- The tagged type being processed may be subject to pragma Ghost. Set
4436 -- the mode now to ensure that any nodes generated during dispatch table
4437 -- creation are properly marked as Ghost.
4439 Set_Ghost_Mode
(Typ
, Mode
);
4441 -- Handle cases in which there is no need to build the dispatch table
4443 if Has_Dispatch_Table
(Typ
)
4444 or else No
(Access_Disp_Table
(Typ
))
4445 or else Is_CPP_Class
(Typ
)
4449 elsif No_Run_Time_Mode
then
4450 Error_Msg_CRT
("tagged types", Typ
);
4453 elsif not RTE_Available
(RE_Tag
) then
4455 Make_Object_Declaration
(Loc
,
4456 Defining_Identifier
=>
4457 Node
(First_Elmt
(Access_Disp_Table
(Typ
))),
4458 Object_Definition
=> New_Occurrence_Of
(RTE
(RE_Tag
), Loc
),
4459 Constant_Present
=> True,
4461 Unchecked_Convert_To
(RTE
(RE_Tag
),
4462 New_Occurrence_Of
(RTE
(RE_Null_Address
), Loc
))));
4464 Analyze_List
(Result
, Suppress
=> All_Checks
);
4465 Error_Msg_CRT
("tagged types", Typ
);
4469 -- Ensure that the value of Max_Predef_Prims defined in a-tags is
4470 -- correct. Valid values are 9 under configurable runtime or 15
4471 -- with full runtime.
4473 if RTE_Available
(RE_Interface_Data
) then
4474 if Max_Predef_Prims
/= 15 then
4475 Error_Msg_N
("run-time library configuration error", Typ
);
4479 if Max_Predef_Prims
/= 9 then
4480 Error_Msg_N
("run-time library configuration error", Typ
);
4481 Error_Msg_CRT
("tagged types", Typ
);
4486 DT
:= Make_Defining_Identifier
(Loc
, Name_DT
);
4487 Exname
:= Make_Defining_Identifier
(Loc
, Name_Exname
);
4488 HT_Link
:= Make_Defining_Identifier
(Loc
, Name_HT_Link
);
4489 Predef_Prims
:= Make_Defining_Identifier
(Loc
, Name_Predef_Prims
);
4490 SSD
:= Make_Defining_Identifier
(Loc
, Name_SSD
);
4491 TSD
:= Make_Defining_Identifier
(Loc
, Name_TSD
);
4493 -- Initialize Parent_Typ handling private types
4495 Parent_Typ
:= Etype
(Typ
);
4497 if Present
(Full_View
(Parent_Typ
)) then
4498 Parent_Typ
:= Full_View
(Parent_Typ
);
4501 -- Ensure that all the primitives are frozen. This is only required when
4502 -- building static dispatch tables --- the primitives must be frozen to
4503 -- be referenced (otherwise we have problems with the backend). It is
4504 -- not a requirement with nonstatic dispatch tables because in this case
4505 -- we generate now an empty dispatch table; the extra code required to
4506 -- register the primitives in the slots will be generated later --- when
4507 -- each primitive is frozen (see Freeze_Subprogram).
4509 if Building_Static_DT
(Typ
) then
4511 Save
: constant Boolean := Freezing_Library_Level_Tagged_Type
;
4513 Prim_Elmt
: Elmt_Id
;
4517 Freezing_Library_Level_Tagged_Type
:= True;
4519 Prim_Elmt
:= First_Elmt
(Primitive_Operations
(Typ
));
4520 while Present
(Prim_Elmt
) loop
4521 Prim
:= Node
(Prim_Elmt
);
4522 Frnodes
:= Freeze_Entity
(Prim
, Typ
);
4528 F
:= First_Formal
(Prim
);
4529 while Present
(F
) loop
4530 Check_Premature_Freezing
(Prim
, Typ
, Etype
(F
));
4534 Check_Premature_Freezing
(Prim
, Typ
, Etype
(Prim
));
4537 if Present
(Frnodes
) then
4538 Append_List_To
(Result
, Frnodes
);
4541 Next_Elmt
(Prim_Elmt
);
4544 Freezing_Library_Level_Tagged_Type
:= Save
;
4548 -- Ada 2005 (AI-251): Build the secondary dispatch tables
4550 if Has_Interfaces
(Typ
) then
4551 Collect_Interface_Components
(Typ
, Typ_Comps
);
4553 -- Each secondary dispatch table is assigned an unique positive
4554 -- suffix index; such value also corresponds with the location of
4555 -- its entity in the Dispatch_Table_Wrappers list (see Make_Tags).
4557 -- Note: This value must be kept sync with the Suffix_Index values
4558 -- generated by Make_Tags
4562 Next_Elmt
(Next_Elmt
(First_Elmt
(Access_Disp_Table
(Typ
))));
4564 AI_Tag_Comp
:= First_Elmt
(Typ_Comps
);
4565 while Present
(AI_Tag_Comp
) loop
4566 pragma Assert
(Has_Suffix
(Node
(AI_Tag_Elmt
), 'P'));
4568 -- Build the secondary table containing pointers to thunks
4573 (Related_Type
(Node
(AI_Tag_Comp
))),
4574 Suffix_Index
=> Suffix_Index
,
4575 Num_Iface_Prims
=> UI_To_Int
4576 (DT_Entry_Count
(Node
(AI_Tag_Comp
))),
4577 Iface_DT_Ptr
=> Node
(AI_Tag_Elmt
),
4578 Predef_Prims_Ptr
=> Node
(Next_Elmt
(AI_Tag_Elmt
)),
4579 Build_Thunks
=> True,
4582 -- Skip secondary dispatch table referencing thunks to predefined
4585 Next_Elmt
(AI_Tag_Elmt
);
4586 pragma Assert
(Has_Suffix
(Node
(AI_Tag_Elmt
), 'Y'));
4588 -- Secondary dispatch table referencing user-defined primitives
4589 -- covered by this interface.
4591 Next_Elmt
(AI_Tag_Elmt
);
4592 pragma Assert
(Has_Suffix
(Node
(AI_Tag_Elmt
), 'D'));
4594 -- Build the secondary table containing pointers to primitives
4595 -- (used to give support to Generic Dispatching Constructors).
4600 (Related_Type
(Node
(AI_Tag_Comp
))),
4602 Num_Iface_Prims
=> UI_To_Int
4603 (DT_Entry_Count
(Node
(AI_Tag_Comp
))),
4604 Iface_DT_Ptr
=> Node
(AI_Tag_Elmt
),
4605 Predef_Prims_Ptr
=> Node
(Next_Elmt
(AI_Tag_Elmt
)),
4606 Build_Thunks
=> False,
4609 -- Skip secondary dispatch table referencing predefined primitives
4611 Next_Elmt
(AI_Tag_Elmt
);
4612 pragma Assert
(Has_Suffix
(Node
(AI_Tag_Elmt
), 'Z'));
4614 Suffix_Index
:= Suffix_Index
+ 1;
4615 Next_Elmt
(AI_Tag_Elmt
);
4616 Next_Elmt
(AI_Tag_Comp
);
4620 -- Get the _tag entity and number of primitives of its dispatch table
4622 DT_Ptr
:= Node
(First_Elmt
(Access_Disp_Table
(Typ
)));
4623 Nb_Prim
:= UI_To_Int
(DT_Entry_Count
(First_Tag_Component
(Typ
)));
4625 if Generate_SCIL
then
4629 Set_Is_Statically_Allocated
(DT
, Is_Library_Level_Tagged_Type
(Typ
));
4630 Set_Is_Statically_Allocated
(SSD
, Is_Library_Level_Tagged_Type
(Typ
));
4631 Set_Is_Statically_Allocated
(TSD
, Is_Library_Level_Tagged_Type
(Typ
));
4632 Set_Is_Statically_Allocated
(Predef_Prims
,
4633 Is_Library_Level_Tagged_Type
(Typ
));
4635 -- In case of locally defined tagged type we declare the object
4636 -- containing the dispatch table by means of a variable. Its
4637 -- initialization is done later by means of an assignment. This is
4638 -- required to generate its External_Tag.
4640 if not Building_Static_DT
(Typ
) then
4643 -- DT : No_Dispatch_Table_Wrapper;
4644 -- for DT'Alignment use Address'Alignment;
4645 -- DT_Ptr : Tag := !Tag (DT.NDT_Prims_Ptr'Address);
4647 if not Has_DT
(Typ
) then
4649 Make_Object_Declaration
(Loc
,
4650 Defining_Identifier
=> DT
,
4651 Aliased_Present
=> True,
4652 Constant_Present
=> False,
4653 Object_Definition
=>
4655 (RTE
(RE_No_Dispatch_Table_Wrapper
), Loc
)));
4658 Make_Attribute_Definition_Clause
(Loc
,
4659 Name
=> New_Occurrence_Of
(DT
, Loc
),
4660 Chars
=> Name_Alignment
,
4662 Make_Attribute_Reference
(Loc
,
4664 New_Occurrence_Of
(RTE
(RE_Integer_Address
), Loc
),
4665 Attribute_Name
=> Name_Alignment
)));
4668 Make_Object_Declaration
(Loc
,
4669 Defining_Identifier
=> DT_Ptr
,
4670 Object_Definition
=> New_Occurrence_Of
(RTE
(RE_Tag
), Loc
),
4671 Constant_Present
=> True,
4673 Unchecked_Convert_To
(RTE
(RE_Tag
),
4674 Make_Attribute_Reference
(Loc
,
4676 Make_Selected_Component
(Loc
,
4677 Prefix
=> New_Occurrence_Of
(DT
, Loc
),
4680 (RTE_Record_Component
(RE_NDT_Prims_Ptr
), Loc
)),
4681 Attribute_Name
=> Name_Address
))));
4683 Set_Is_Statically_Allocated
(DT_Ptr
,
4684 Is_Library_Level_Tagged_Type
(Typ
));
4686 -- Generate the SCIL node for the previous object declaration
4687 -- because it has a tag initialization.
4689 if Generate_SCIL
then
4691 Make_SCIL_Dispatch_Table_Tag_Init
(Sloc
(Last
(Result
)));
4692 Set_SCIL_Entity
(New_Node
, Typ
);
4693 Set_SCIL_Node
(Last
(Result
), New_Node
);
4697 -- Gnat2scil has its own implementation of dispatch tables,
4698 -- different than what is being implemented here. Generating
4699 -- further dispatch table initialization code would just
4700 -- cause gnat2scil to generate useless Scil which CodePeer
4701 -- would waste time and space analyzing, so we skip it.
4705 -- DT : Dispatch_Table_Wrapper (Nb_Prim);
4706 -- for DT'Alignment use Address'Alignment;
4707 -- DT_Ptr : Tag := !Tag (DT.Prims_Ptr'Address);
4710 -- If the tagged type has no primitives we add a dummy slot
4711 -- whose address will be the tag of this type.
4715 New_List
(Make_Integer_Literal
(Loc
, 1));
4718 New_List
(Make_Integer_Literal
(Loc
, Nb_Prim
));
4722 Make_Object_Declaration
(Loc
,
4723 Defining_Identifier
=> DT
,
4724 Aliased_Present
=> True,
4725 Constant_Present
=> False,
4726 Object_Definition
=>
4727 Make_Subtype_Indication
(Loc
,
4729 New_Occurrence_Of
(RTE
(RE_Dispatch_Table_Wrapper
), Loc
),
4731 Make_Index_Or_Discriminant_Constraint
(Loc
,
4732 Constraints
=> DT_Constr_List
))));
4735 Make_Attribute_Definition_Clause
(Loc
,
4736 Name
=> New_Occurrence_Of
(DT
, Loc
),
4737 Chars
=> Name_Alignment
,
4739 Make_Attribute_Reference
(Loc
,
4741 New_Occurrence_Of
(RTE
(RE_Integer_Address
), Loc
),
4742 Attribute_Name
=> Name_Alignment
)));
4745 Make_Object_Declaration
(Loc
,
4746 Defining_Identifier
=> DT_Ptr
,
4747 Object_Definition
=> New_Occurrence_Of
(RTE
(RE_Tag
), Loc
),
4748 Constant_Present
=> True,
4750 Unchecked_Convert_To
(RTE
(RE_Tag
),
4751 Make_Attribute_Reference
(Loc
,
4753 Make_Selected_Component
(Loc
,
4754 Prefix
=> New_Occurrence_Of
(DT
, Loc
),
4757 (RTE_Record_Component
(RE_Prims_Ptr
), Loc
)),
4758 Attribute_Name
=> Name_Address
))));
4760 Set_Is_Statically_Allocated
(DT_Ptr
,
4761 Is_Library_Level_Tagged_Type
(Typ
));
4763 -- Generate the SCIL node for the previous object declaration
4764 -- because it has a tag initialization.
4766 if Generate_SCIL
then
4768 Make_SCIL_Dispatch_Table_Tag_Init
(Sloc
(Last
(Result
)));
4769 Set_SCIL_Entity
(New_Node
, Typ
);
4770 Set_SCIL_Node
(Last
(Result
), New_Node
);
4774 -- Gnat2scil has its own implementation of dispatch tables,
4775 -- different than what is being implemented here. Generating
4776 -- further dispatch table initialization code would just
4777 -- cause gnat2scil to generate useless Scil which CodePeer
4778 -- would waste time and space analyzing, so we skip it.
4782 Make_Object_Declaration
(Loc
,
4783 Defining_Identifier
=>
4784 Node
(Next_Elmt
(First_Elmt
(Access_Disp_Table
(Typ
)))),
4785 Constant_Present
=> True,
4786 Object_Definition
=>
4787 New_Occurrence_Of
(RTE
(RE_Address
), Loc
),
4789 Make_Attribute_Reference
(Loc
,
4791 Make_Selected_Component
(Loc
,
4792 Prefix
=> New_Occurrence_Of
(DT
, Loc
),
4795 (RTE_Record_Component
(RE_Predef_Prims
), Loc
)),
4796 Attribute_Name
=> Name_Address
)));
4800 -- Generate: Exname : constant String := full_qualified_name (typ);
4801 -- The type itself may be an anonymous parent type, so use the first
4802 -- subtype to have a user-recognizable name.
4805 Make_Object_Declaration
(Loc
,
4806 Defining_Identifier
=> Exname
,
4807 Constant_Present
=> True,
4808 Object_Definition
=> New_Occurrence_Of
(Standard_String
, Loc
),
4810 Make_String_Literal
(Loc
,
4811 Strval
=> Fully_Qualified_Name_String
(First_Subtype
(Typ
)))));
4812 Set_Is_Statically_Allocated
(Exname
);
4813 Set_Is_True_Constant
(Exname
);
4815 -- Declare the object used by Ada.Tags.Register_Tag
4817 if RTE_Available
(RE_Register_Tag
) then
4819 Make_Object_Declaration
(Loc
,
4820 Defining_Identifier
=> HT_Link
,
4821 Object_Definition
=> New_Occurrence_Of
(RTE
(RE_Tag
), Loc
)));
4824 -- Generate code to create the storage for the type specific data object
4825 -- with enough space to store the tags of the ancestors plus the tags
4826 -- of all the implemented interfaces (as described in a-tags.adb).
4828 -- TSD : Type_Specific_Data (I_Depth) :=
4829 -- (Idepth => I_Depth,
4830 -- Access_Level => Type_Access_Level (Typ),
4831 -- Alignment => Typ'Alignment,
4832 -- Expanded_Name => Cstring_Ptr!(Exname'Address))
4833 -- External_Tag => Cstring_Ptr!(Exname'Address))
4834 -- HT_Link => HT_Link'Address,
4835 -- Transportable => <<boolean-value>>,
4836 -- Type_Is_Abstract => <<boolean-value>>,
4837 -- Needs_Finalization => <<boolean-value>>,
4838 -- [ Size_Func => Size_Prim'Access, ]
4839 -- [ Interfaces_Table => <<access-value>>, ]
4840 -- [ SSD => SSD_Table'Address ]
4841 -- Tags_Table => (0 => null,
4844 -- for TSD'Alignment use Address'Alignment
4846 TSD_Aggr_List
:= New_List
;
4848 -- Idepth: Count ancestors to compute the inheritance depth. For private
4849 -- extensions, always go to the full view in order to compute the real
4850 -- inheritance depth.
4853 Current_Typ
: Entity_Id
;
4854 Parent_Typ
: Entity_Id
;
4860 Parent_Typ
:= Etype
(Current_Typ
);
4862 if Is_Private_Type
(Parent_Typ
) then
4863 Parent_Typ
:= Full_View
(Base_Type
(Parent_Typ
));
4866 exit when Parent_Typ
= Current_Typ
;
4868 I_Depth
:= I_Depth
+ 1;
4869 Current_Typ
:= Parent_Typ
;
4873 Append_To
(TSD_Aggr_List
,
4874 Make_Integer_Literal
(Loc
, I_Depth
));
4878 Append_To
(TSD_Aggr_List
,
4879 Make_Integer_Literal
(Loc
, Type_Access_Level
(Typ
)));
4883 -- For CPP types we cannot rely on the value of 'Alignment provided
4884 -- by the backend to initialize this TSD field.
4886 if Convention
(Typ
) = Convention_CPP
4887 or else Is_CPP_Class
(Root_Type
(Typ
))
4889 Append_To
(TSD_Aggr_List
,
4890 Make_Integer_Literal
(Loc
, 0));
4892 Append_To
(TSD_Aggr_List
,
4893 Make_Attribute_Reference
(Loc
,
4894 Prefix
=> New_Occurrence_Of
(Typ
, Loc
),
4895 Attribute_Name
=> Name_Alignment
));
4900 Append_To
(TSD_Aggr_List
,
4901 Unchecked_Convert_To
(RTE
(RE_Cstring_Ptr
),
4902 Make_Attribute_Reference
(Loc
,
4903 Prefix
=> New_Occurrence_Of
(Exname
, Loc
),
4904 Attribute_Name
=> Name_Address
)));
4906 -- External_Tag of a local tagged type
4908 -- <typ>A : constant String :=
4909 -- "Internal tag at 16#tag-addr#: <full-name-of-typ>";
4911 -- The reason we generate this strange name is that we do not want to
4912 -- enter local tagged types in the global hash table used to compute
4913 -- the Internal_Tag attribute for two reasons:
4915 -- 1. It is hard to avoid a tasking race condition for entering the
4916 -- entry into the hash table.
4918 -- 2. It would cause a storage leak, unless we rig up considerable
4919 -- mechanism to remove the entry from the hash table on exit.
4921 -- So what we do is to generate the above external tag name, where the
4922 -- hex address is the address of the local dispatch table (i.e. exactly
4923 -- the value we want if Internal_Tag is computed from this string).
4925 -- Of course this value will only be valid if the tagged type is still
4926 -- in scope, but it clearly must be erroneous to compute the internal
4927 -- tag of a tagged type that is out of scope.
4929 -- We don't do this processing if an explicit external tag has been
4930 -- specified. That's an odd case for which we have already issued a
4931 -- warning, where we will not be able to compute the internal tag.
4933 if not Is_Library_Level_Entity
(Typ
)
4934 and then not Has_External_Tag_Rep_Clause
(Typ
)
4937 Exname
: constant Entity_Id
:=
4938 Make_Defining_Identifier
(Loc
,
4939 Chars
=> New_External_Name
(Tname
, 'A'));
4940 Full_Name
: constant String_Id
:=
4941 Fully_Qualified_Name_String
(First_Subtype
(Typ
));
4942 Str1_Id
: String_Id
;
4943 Str2_Id
: String_Id
;
4947 -- Str1 = "Internal tag at 16#";
4950 Store_String_Chars
("Internal tag at 16#");
4951 Str1_Id
:= End_String
;
4954 -- Str2 = "#: <type-full-name>";
4957 Store_String_Chars
("#: ");
4958 Store_String_Chars
(Full_Name
);
4959 Str2_Id
:= End_String
;
4962 -- Exname : constant String :=
4963 -- Str1 & Address_Image (Tag) & Str2;
4965 if RTE_Available
(RE_Address_Image
) then
4967 Make_Object_Declaration
(Loc
,
4968 Defining_Identifier
=> Exname
,
4969 Constant_Present
=> True,
4970 Object_Definition
=> New_Occurrence_Of
4971 (Standard_String
, Loc
),
4973 Make_Op_Concat
(Loc
,
4974 Left_Opnd
=> Make_String_Literal
(Loc
, Str1_Id
),
4976 Make_Op_Concat
(Loc
,
4978 Make_Function_Call
(Loc
,
4981 (RTE
(RE_Address_Image
), Loc
),
4982 Parameter_Associations
=> New_List
(
4983 Unchecked_Convert_To
(RTE
(RE_Address
),
4984 New_Occurrence_Of
(DT_Ptr
, Loc
)))),
4986 Make_String_Literal
(Loc
, Str2_Id
)))));
4990 Make_Object_Declaration
(Loc
,
4991 Defining_Identifier
=> Exname
,
4992 Constant_Present
=> True,
4993 Object_Definition
=>
4994 New_Occurrence_Of
(Standard_String
, Loc
),
4996 Make_Op_Concat
(Loc
,
4997 Left_Opnd
=> Make_String_Literal
(Loc
, Str1_Id
),
4998 Right_Opnd
=> Make_String_Literal
(Loc
, Str2_Id
))));
5002 Unchecked_Convert_To
(RTE
(RE_Cstring_Ptr
),
5003 Make_Attribute_Reference
(Loc
,
5004 Prefix
=> New_Occurrence_Of
(Exname
, Loc
),
5005 Attribute_Name
=> Name_Address
));
5008 -- External tag of a library-level tagged type: Check for a definition
5009 -- of External_Tag. The clause is considered only if it applies to this
5010 -- specific tagged type, as opposed to one of its ancestors.
5011 -- If the type is an unconstrained type extension, we are building the
5012 -- dispatch table of its anonymous base type, so the external tag, if
5013 -- any was specified, must be retrieved from the first subtype. Go to
5014 -- the full view in case the clause is in the private part.
5018 Def
: constant Node_Id
:= Get_Attribute_Definition_Clause
5019 (Underlying_Type
(First_Subtype
(Typ
)),
5020 Attribute_External_Tag
);
5022 Old_Val
: String_Id
;
5023 New_Val
: String_Id
;
5027 if not Present
(Def
)
5028 or else Entity
(Name
(Def
)) /= First_Subtype
(Typ
)
5031 Unchecked_Convert_To
(RTE
(RE_Cstring_Ptr
),
5032 Make_Attribute_Reference
(Loc
,
5033 Prefix
=> New_Occurrence_Of
(Exname
, Loc
),
5034 Attribute_Name
=> Name_Address
));
5036 Old_Val
:= Strval
(Expr_Value_S
(Expression
(Def
)));
5038 -- For the rep clause "for <typ>'external_tag use y" generate:
5040 -- <typ>A : constant string := y;
5042 -- <typ>A'Address is used to set the External_Tag component
5045 -- Create a new nul terminated string if it is not already
5047 if String_Length
(Old_Val
) > 0
5049 Get_String_Char
(Old_Val
, String_Length
(Old_Val
)) = 0
5053 Start_String
(Old_Val
);
5054 Store_String_Char
(Get_Char_Code
(ASCII
.NUL
));
5055 New_Val
:= End_String
;
5058 E
:= Make_Defining_Identifier
(Loc
,
5059 New_External_Name
(Chars
(Typ
), 'A'));
5062 Make_Object_Declaration
(Loc
,
5063 Defining_Identifier
=> E
,
5064 Constant_Present
=> True,
5065 Object_Definition
=>
5066 New_Occurrence_Of
(Standard_String
, Loc
),
5068 Make_String_Literal
(Loc
, New_Val
)));
5071 Unchecked_Convert_To
(RTE
(RE_Cstring_Ptr
),
5072 Make_Attribute_Reference
(Loc
,
5073 Prefix
=> New_Occurrence_Of
(E
, Loc
),
5074 Attribute_Name
=> Name_Address
));
5079 Append_To
(TSD_Aggr_List
, New_Node
);
5083 if RTE_Available
(RE_Register_Tag
) then
5084 Append_To
(TSD_Aggr_List
,
5085 Unchecked_Convert_To
(RTE
(RE_Tag_Ptr
),
5086 Make_Attribute_Reference
(Loc
,
5087 Prefix
=> New_Occurrence_Of
(HT_Link
, Loc
),
5088 Attribute_Name
=> Name_Address
)));
5090 Append_To
(TSD_Aggr_List
,
5091 Unchecked_Convert_To
(RTE
(RE_Tag_Ptr
),
5092 New_Occurrence_Of
(RTE
(RE_Null_Address
), Loc
)));
5095 -- Transportable: Set for types that can be used in remote calls
5096 -- with respect to E.4(18) legality rules.
5099 Transportable
: Entity_Id
;
5105 or else Is_Shared_Passive
(Typ
)
5107 ((Is_Remote_Types
(Typ
)
5108 or else Is_Remote_Call_Interface
(Typ
))
5109 and then Original_View_In_Visible_Part
(Typ
))
5110 or else not Comes_From_Source
(Typ
));
5112 Append_To
(TSD_Aggr_List
,
5113 New_Occurrence_Of
(Transportable
, Loc
));
5116 -- Type_Is_Abstract (Ada 2012: AI05-0173). This functionality is
5117 -- not available in the HIE runtime.
5119 if RTE_Record_Component_Available
(RE_Type_Is_Abstract
) then
5121 Type_Is_Abstract
: Entity_Id
;
5123 Type_Is_Abstract
:= Boolean_Literals
(Is_Abstract_Type
(Typ
));
5124 Append_To
(TSD_Aggr_List
,
5125 New_Occurrence_Of
(Type_Is_Abstract
, Loc
));
5129 -- Needs_Finalization: Set if the type is controlled or has controlled
5133 Needs_Fin
: Entity_Id
;
5135 Needs_Fin
:= Boolean_Literals
(Needs_Finalization
(Typ
));
5136 Append_To
(TSD_Aggr_List
, New_Occurrence_Of
(Needs_Fin
, Loc
));
5141 if RTE_Record_Component_Available
(RE_Size_Func
) then
5143 -- Initialize this field to Null_Address if we are not building
5144 -- static dispatch tables static or if the size function is not
5145 -- available. In the former case we cannot initialize this field
5146 -- until the function is frozen and registered in the dispatch
5147 -- table (see Register_Primitive).
5149 if not Building_Static_DT
(Typ
) or else not Has_DT
(Typ
) then
5150 Append_To
(TSD_Aggr_List
,
5151 Unchecked_Convert_To
(RTE
(RE_Size_Ptr
),
5152 New_Occurrence_Of
(RTE
(RE_Null_Address
), Loc
)));
5156 Prim_Elmt
: Elmt_Id
;
5158 Size_Comp
: Node_Id
;
5161 Prim_Elmt
:= First_Elmt
(Primitive_Operations
(Typ
));
5162 while Present
(Prim_Elmt
) loop
5163 Prim
:= Node
(Prim_Elmt
);
5165 if Chars
(Prim
) = Name_uSize
then
5166 Prim
:= Ultimate_Alias
(Prim
);
5168 if Is_Abstract_Subprogram
(Prim
) then
5170 Unchecked_Convert_To
(RTE
(RE_Size_Ptr
),
5171 New_Occurrence_Of
(RTE
(RE_Null_Address
), Loc
));
5174 Unchecked_Convert_To
(RTE
(RE_Size_Ptr
),
5175 Make_Attribute_Reference
(Loc
,
5176 Prefix
=> New_Occurrence_Of
(Prim
, Loc
),
5177 Attribute_Name
=> Name_Unrestricted_Access
));
5183 Next_Elmt
(Prim_Elmt
);
5186 pragma Assert
(Present
(Size_Comp
));
5187 Append_To
(TSD_Aggr_List
, Size_Comp
);
5192 -- Interfaces_Table (required for AI-405)
5194 if RTE_Record_Component_Available
(RE_Interfaces_Table
) then
5196 -- Count the number of interface types implemented by Typ
5198 Collect_Interfaces
(Typ
, Typ_Ifaces
);
5200 AI
:= First_Elmt
(Typ_Ifaces
);
5201 while Present
(AI
) loop
5202 Num_Ifaces
:= Num_Ifaces
+ 1;
5206 if Num_Ifaces
= 0 then
5207 Iface_Table_Node
:= Make_Null
(Loc
);
5209 -- Generate the Interface_Table object
5213 TSD_Ifaces_List
: constant List_Id
:= New_List
;
5215 Sec_DT_Tag
: Node_Id
;
5218 AI
:= First_Elmt
(Typ_Ifaces
);
5219 while Present
(AI
) loop
5220 if Is_Ancestor
(Node
(AI
), Typ
, Use_Full_View
=> True) then
5222 New_Occurrence_Of
(DT_Ptr
, Loc
);
5226 (Next_Elmt
(First_Elmt
(Access_Disp_Table
(Typ
))));
5227 pragma Assert
(Has_Thunks
(Node
(Elmt
)));
5229 while Is_Tag
(Node
(Elmt
))
5231 Is_Ancestor
(Node
(AI
), Related_Type
(Node
(Elmt
)),
5232 Use_Full_View
=> True)
5234 pragma Assert
(Has_Thunks
(Node
(Elmt
)));
5236 pragma Assert
(Has_Thunks
(Node
(Elmt
)));
5238 pragma Assert
(not Has_Thunks
(Node
(Elmt
)));
5240 pragma Assert
(not Has_Thunks
(Node
(Elmt
)));
5244 pragma Assert
(Ekind
(Node
(Elmt
)) = E_Constant
5246 Has_Thunks
(Node
(Next_Elmt
(Next_Elmt
(Elmt
)))));
5248 New_Occurrence_Of
(Node
(Next_Elmt
(Next_Elmt
(Elmt
))),
5252 Append_To
(TSD_Ifaces_List
,
5253 Make_Aggregate
(Loc
,
5254 Expressions
=> New_List
(
5258 Unchecked_Convert_To
(RTE
(RE_Tag
),
5260 (Node
(First_Elmt
(Access_Disp_Table
(Node
(AI
)))),
5263 -- Static_Offset_To_Top
5265 New_Occurrence_Of
(Standard_True
, Loc
),
5267 -- Offset_To_Top_Value
5269 Make_Integer_Literal
(Loc
, 0),
5271 -- Offset_To_Top_Func
5277 Unchecked_Convert_To
(RTE
(RE_Tag
), Sec_DT_Tag
)
5284 Name_ITable
:= New_External_Name
(Tname
, 'I');
5285 ITable
:= Make_Defining_Identifier
(Loc
, Name_ITable
);
5286 Set_Is_Statically_Allocated
(ITable
,
5287 Is_Library_Level_Tagged_Type
(Typ
));
5289 -- The table of interfaces is not constant; its slots are
5290 -- filled at run time by the IP routine using attribute
5291 -- 'Position to know the location of the tag components
5292 -- (and this attribute cannot be safely used before the
5293 -- object is initialized).
5296 Make_Object_Declaration
(Loc
,
5297 Defining_Identifier
=> ITable
,
5298 Aliased_Present
=> True,
5299 Constant_Present
=> False,
5300 Object_Definition
=>
5301 Make_Subtype_Indication
(Loc
,
5303 New_Occurrence_Of
(RTE
(RE_Interface_Data
), Loc
),
5305 Make_Index_Or_Discriminant_Constraint
(Loc
,
5306 Constraints
=> New_List
(
5307 Make_Integer_Literal
(Loc
, Num_Ifaces
)))),
5309 Expression
=> Make_Aggregate
(Loc
,
5310 Expressions
=> New_List
(
5311 Make_Integer_Literal
(Loc
, Num_Ifaces
),
5312 Make_Aggregate
(Loc
, TSD_Ifaces_List
)))));
5315 Make_Attribute_Definition_Clause
(Loc
,
5316 Name
=> New_Occurrence_Of
(ITable
, Loc
),
5317 Chars
=> Name_Alignment
,
5319 Make_Attribute_Reference
(Loc
,
5321 New_Occurrence_Of
(RTE
(RE_Integer_Address
), Loc
),
5322 Attribute_Name
=> Name_Alignment
)));
5325 Make_Attribute_Reference
(Loc
,
5326 Prefix
=> New_Occurrence_Of
(ITable
, Loc
),
5327 Attribute_Name
=> Name_Unchecked_Access
);
5331 Append_To
(TSD_Aggr_List
, Iface_Table_Node
);
5334 -- Generate the Select Specific Data table for synchronized types that
5335 -- implement synchronized interfaces. The size of the table is
5336 -- constrained by the number of non-predefined primitive operations.
5338 if RTE_Record_Component_Available
(RE_SSD
) then
5339 if Ada_Version
>= Ada_2005
5340 and then Has_DT
(Typ
)
5341 and then Is_Concurrent_Record_Type
(Typ
)
5342 and then Has_Interfaces
(Typ
)
5343 and then Nb_Prim
> 0
5344 and then not Is_Abstract_Type
(Typ
)
5345 and then not Is_Controlled
(Typ
)
5346 and then not Restriction_Active
(No_Dispatching_Calls
)
5347 and then not Restriction_Active
(No_Select_Statements
)
5350 Make_Object_Declaration
(Loc
,
5351 Defining_Identifier
=> SSD
,
5352 Aliased_Present
=> True,
5353 Object_Definition
=>
5354 Make_Subtype_Indication
(Loc
,
5355 Subtype_Mark
=> New_Occurrence_Of
(
5356 RTE
(RE_Select_Specific_Data
), Loc
),
5358 Make_Index_Or_Discriminant_Constraint
(Loc
,
5359 Constraints
=> New_List
(
5360 Make_Integer_Literal
(Loc
, Nb_Prim
))))));
5363 Make_Attribute_Definition_Clause
(Loc
,
5364 Name
=> New_Occurrence_Of
(SSD
, Loc
),
5365 Chars
=> Name_Alignment
,
5367 Make_Attribute_Reference
(Loc
,
5369 New_Occurrence_Of
(RTE
(RE_Integer_Address
), Loc
),
5370 Attribute_Name
=> Name_Alignment
)));
5372 -- This table is initialized by Make_Select_Specific_Data_Table,
5373 -- which calls Set_Entry_Index and Set_Prim_Op_Kind.
5375 Append_To
(TSD_Aggr_List
,
5376 Make_Attribute_Reference
(Loc
,
5377 Prefix
=> New_Occurrence_Of
(SSD
, Loc
),
5378 Attribute_Name
=> Name_Unchecked_Access
));
5380 Append_To
(TSD_Aggr_List
, Make_Null
(Loc
));
5384 -- Initialize the table of ancestor tags. In case of interface types
5385 -- this table is not needed.
5387 TSD_Tags_List
:= New_List
;
5389 -- If we are not statically allocating the dispatch table then we must
5390 -- fill position 0 with null because we still have not generated the
5393 if not Building_Static_DT
(Typ
)
5394 or else Is_Interface
(Typ
)
5396 Append_To
(TSD_Tags_List
,
5397 Unchecked_Convert_To
(RTE
(RE_Tag
),
5398 New_Occurrence_Of
(RTE
(RE_Null_Address
), Loc
)));
5400 -- Otherwise we can safely reference the tag
5403 Append_To
(TSD_Tags_List
,
5404 New_Occurrence_Of
(DT_Ptr
, Loc
));
5407 -- Fill the rest of the table with the tags of the ancestors
5410 Current_Typ
: Entity_Id
;
5411 Parent_Typ
: Entity_Id
;
5419 Parent_Typ
:= Etype
(Current_Typ
);
5421 if Is_Private_Type
(Parent_Typ
) then
5422 Parent_Typ
:= Full_View
(Base_Type
(Parent_Typ
));
5425 exit when Parent_Typ
= Current_Typ
;
5427 if Is_CPP_Class
(Parent_Typ
) then
5429 -- The tags defined in the C++ side will be inherited when
5430 -- the object is constructed (Exp_Ch3.Build_Init_Procedure)
5432 Append_To
(TSD_Tags_List
,
5433 Unchecked_Convert_To
(RTE
(RE_Tag
),
5434 New_Occurrence_Of
(RTE
(RE_Null_Address
), Loc
)));
5436 Append_To
(TSD_Tags_List
,
5438 (Node
(First_Elmt
(Access_Disp_Table
(Parent_Typ
))),
5443 Current_Typ
:= Parent_Typ
;
5446 pragma Assert
(Pos
= I_Depth
+ 1);
5449 Append_To
(TSD_Aggr_List
,
5450 Make_Aggregate
(Loc
,
5451 Expressions
=> TSD_Tags_List
));
5453 -- Build the TSD object
5456 Make_Object_Declaration
(Loc
,
5457 Defining_Identifier
=> TSD
,
5458 Aliased_Present
=> True,
5459 Constant_Present
=> Building_Static_DT
(Typ
),
5460 Object_Definition
=>
5461 Make_Subtype_Indication
(Loc
,
5462 Subtype_Mark
=> New_Occurrence_Of
(
5463 RTE
(RE_Type_Specific_Data
), Loc
),
5465 Make_Index_Or_Discriminant_Constraint
(Loc
,
5466 Constraints
=> New_List
(
5467 Make_Integer_Literal
(Loc
, I_Depth
)))),
5469 Expression
=> Make_Aggregate
(Loc
,
5470 Expressions
=> TSD_Aggr_List
)));
5472 Set_Is_True_Constant
(TSD
, Building_Static_DT
(Typ
));
5475 Make_Attribute_Definition_Clause
(Loc
,
5476 Name
=> New_Occurrence_Of
(TSD
, Loc
),
5477 Chars
=> Name_Alignment
,
5479 Make_Attribute_Reference
(Loc
,
5481 New_Occurrence_Of
(RTE
(RE_Integer_Address
), Loc
),
5482 Attribute_Name
=> Name_Alignment
)));
5484 -- Initialize or declare the dispatch table object
5486 if not Has_DT
(Typ
) then
5487 DT_Constr_List
:= New_List
;
5488 DT_Aggr_List
:= New_List
;
5493 Make_Attribute_Reference
(Loc
,
5494 Prefix
=> New_Occurrence_Of
(TSD
, Loc
),
5495 Attribute_Name
=> Name_Address
);
5497 Append_To
(DT_Constr_List
, New_Node
);
5498 Append_To
(DT_Aggr_List
, New_Copy
(New_Node
));
5499 Append_To
(DT_Aggr_List
, Make_Integer_Literal
(Loc
, 0));
5501 -- In case of locally defined tagged types we have already declared
5502 -- and uninitialized object for the dispatch table, which is now
5503 -- initialized by means of the following assignment:
5505 -- DT := (TSD'Address, 0);
5507 if not Building_Static_DT
(Typ
) then
5509 Make_Assignment_Statement
(Loc
,
5510 Name
=> New_Occurrence_Of
(DT
, Loc
),
5511 Expression
=> Make_Aggregate
(Loc
, DT_Aggr_List
)));
5513 -- In case of library level tagged types we declare and export now
5514 -- the constant object containing the dummy dispatch table. There
5515 -- is no need to declare the tag here because it has been previously
5516 -- declared by Make_Tags
5518 -- DT : aliased constant No_Dispatch_Table :=
5519 -- (NDT_TSD => TSD'Address;
5520 -- NDT_Prims_Ptr => 0);
5521 -- for DT'Alignment use Address'Alignment;
5525 Make_Object_Declaration
(Loc
,
5526 Defining_Identifier
=> DT
,
5527 Aliased_Present
=> True,
5528 Constant_Present
=> True,
5529 Object_Definition
=>
5530 New_Occurrence_Of
(RTE
(RE_No_Dispatch_Table_Wrapper
), Loc
),
5531 Expression
=> Make_Aggregate
(Loc
, DT_Aggr_List
)));
5534 Make_Attribute_Definition_Clause
(Loc
,
5535 Name
=> New_Occurrence_Of
(DT
, Loc
),
5536 Chars
=> Name_Alignment
,
5538 Make_Attribute_Reference
(Loc
,
5540 New_Occurrence_Of
(RTE
(RE_Integer_Address
), Loc
),
5541 Attribute_Name
=> Name_Alignment
)));
5543 Export_DT
(Typ
, DT
);
5546 -- Common case: Typ has a dispatch table
5550 -- Predef_Prims : Address_Array (1 .. Default_Prim_Ops_Count) :=
5551 -- (predef-prim-op-1'address,
5552 -- predef-prim-op-2'address,
5554 -- predef-prim-op-n'address);
5555 -- for Predef_Prims'Alignment use Address'Alignment
5557 -- DT : Dispatch_Table (Nb_Prims) :=
5558 -- (Signature => <sig-value>,
5559 -- Tag_Kind => <tag_kind-value>,
5560 -- Predef_Prims => Predef_Prims'First'Address,
5561 -- Offset_To_Top => 0,
5562 -- TSD => TSD'Address;
5563 -- Prims_Ptr => (prim-op-1'address,
5564 -- prim-op-2'address,
5566 -- prim-op-n'address));
5567 -- for DT'Alignment use Address'Alignment
5574 if not Building_Static_DT
(Typ
) then
5575 Nb_Predef_Prims
:= Max_Predef_Prims
;
5578 Prim_Elmt
:= First_Elmt
(Primitive_Operations
(Typ
));
5579 while Present
(Prim_Elmt
) loop
5580 Prim
:= Node
(Prim_Elmt
);
5582 if Is_Predefined_Dispatching_Operation
(Prim
)
5583 and then not Is_Abstract_Subprogram
(Prim
)
5585 Pos
:= UI_To_Int
(DT_Position
(Prim
));
5587 if Pos
> Nb_Predef_Prims
then
5588 Nb_Predef_Prims
:= Pos
;
5592 Next_Elmt
(Prim_Elmt
);
5598 (Nat
range 1 .. Nb_Predef_Prims
) of Entity_Id
;
5603 Prim_Ops_Aggr_List
:= New_List
;
5605 Prim_Table
:= (others => Empty
);
5607 if Building_Static_DT
(Typ
) then
5608 Prim_Elmt
:= First_Elmt
(Primitive_Operations
(Typ
));
5609 while Present
(Prim_Elmt
) loop
5610 Prim
:= Node
(Prim_Elmt
);
5612 if Is_Predefined_Dispatching_Operation
(Prim
)
5613 and then not Is_Abstract_Subprogram
(Prim
)
5614 and then not Is_Eliminated
(Prim
)
5615 and then not Present
(Prim_Table
5616 (UI_To_Int
(DT_Position
(Prim
))))
5618 E
:= Ultimate_Alias
(Prim
);
5619 pragma Assert
(not Is_Abstract_Subprogram
(E
));
5620 Prim_Table
(UI_To_Int
(DT_Position
(Prim
))) := E
;
5623 Next_Elmt
(Prim_Elmt
);
5627 for J
in Prim_Table
'Range loop
5628 if Present
(Prim_Table
(J
)) then
5630 Unchecked_Convert_To
(RTE
(RE_Prim_Ptr
),
5631 Make_Attribute_Reference
(Loc
,
5633 New_Occurrence_Of
(Prim_Table
(J
), Loc
),
5634 Attribute_Name
=> Name_Unrestricted_Access
));
5636 New_Node
:= Make_Null
(Loc
);
5639 Append_To
(Prim_Ops_Aggr_List
, New_Node
);
5643 Make_Aggregate
(Loc
,
5644 Expressions
=> Prim_Ops_Aggr_List
);
5647 Make_Subtype_Declaration
(Loc
,
5648 Defining_Identifier
=> Make_Temporary
(Loc
, 'S'),
5649 Subtype_Indication
=>
5650 New_Occurrence_Of
(RTE
(RE_Address_Array
), Loc
));
5652 Append_To
(Result
, Decl
);
5655 Make_Object_Declaration
(Loc
,
5656 Defining_Identifier
=> Predef_Prims
,
5657 Aliased_Present
=> True,
5658 Constant_Present
=> Building_Static_DT
(Typ
),
5659 Object_Definition
=>
5660 New_Occurrence_Of
(Defining_Identifier
(Decl
), Loc
),
5661 Expression
=> New_Node
));
5663 -- Remember aggregates initializing dispatch tables
5665 Append_Elmt
(New_Node
, DT_Aggr
);
5668 Make_Attribute_Definition_Clause
(Loc
,
5669 Name
=> New_Occurrence_Of
(Predef_Prims
, Loc
),
5670 Chars
=> Name_Alignment
,
5672 Make_Attribute_Reference
(Loc
,
5674 New_Occurrence_Of
(RTE
(RE_Integer_Address
), Loc
),
5675 Attribute_Name
=> Name_Alignment
)));
5679 -- Stage 1: Initialize the discriminant and the record components
5681 DT_Constr_List
:= New_List
;
5682 DT_Aggr_List
:= New_List
;
5684 -- Num_Prims. If the tagged type has no primitives we add a dummy
5685 -- slot whose address will be the tag of this type.
5688 New_Node
:= Make_Integer_Literal
(Loc
, 1);
5690 New_Node
:= Make_Integer_Literal
(Loc
, Nb_Prim
);
5693 Append_To
(DT_Constr_List
, New_Node
);
5694 Append_To
(DT_Aggr_List
, New_Copy
(New_Node
));
5698 if RTE_Record_Component_Available
(RE_Signature
) then
5699 Append_To
(DT_Aggr_List
,
5700 New_Occurrence_Of
(RTE
(RE_Primary_DT
), Loc
));
5705 if RTE_Record_Component_Available
(RE_Tag_Kind
) then
5706 Append_To
(DT_Aggr_List
, Tagged_Kind
(Typ
));
5711 Append_To
(DT_Aggr_List
,
5712 Make_Attribute_Reference
(Loc
,
5713 Prefix
=> New_Occurrence_Of
(Predef_Prims
, Loc
),
5714 Attribute_Name
=> Name_Address
));
5718 Append_To
(DT_Aggr_List
, Make_Integer_Literal
(Loc
, 0));
5722 Append_To
(DT_Aggr_List
,
5723 Make_Attribute_Reference
(Loc
,
5724 Prefix
=> New_Occurrence_Of
(TSD
, Loc
),
5725 Attribute_Name
=> Name_Address
));
5727 -- Stage 2: Initialize the table of user-defined primitive operations
5729 Prim_Ops_Aggr_List
:= New_List
;
5732 Append_To
(Prim_Ops_Aggr_List
, Make_Null
(Loc
));
5734 elsif not Building_Static_DT
(Typ
) then
5735 for J
in 1 .. Nb_Prim
loop
5736 Append_To
(Prim_Ops_Aggr_List
, Make_Null
(Loc
));
5741 CPP_Nb_Prims
: constant Nat
:= CPP_Num_Prims
(Typ
);
5744 Prim_Elmt
: Elmt_Id
;
5746 Prim_Table
: array (Nat
range 1 .. Nb_Prim
) of Entity_Id
;
5749 Prim_Table
:= (others => Empty
);
5751 Prim_Elmt
:= First_Elmt
(Primitive_Operations
(Typ
));
5752 while Present
(Prim_Elmt
) loop
5753 Prim
:= Node
(Prim_Elmt
);
5755 -- Retrieve the ultimate alias of the primitive for proper
5756 -- handling of renamings and eliminated primitives.
5758 E
:= Ultimate_Alias
(Prim
);
5759 Prim_Pos
:= UI_To_Int
(DT_Position
(E
));
5761 -- Skip predefined primitives because they are located in a
5762 -- separate dispatch table.
5764 if not Is_Predefined_Dispatching_Operation
(Prim
)
5765 and then not Is_Predefined_Dispatching_Operation
(E
)
5767 -- Skip entities with attribute Interface_Alias because
5768 -- those are only required to build secondary dispatch
5771 and then not Present
(Interface_Alias
(Prim
))
5773 -- Skip abstract and eliminated primitives
5775 and then not Is_Abstract_Subprogram
(E
)
5776 and then not Is_Eliminated
(E
)
5778 -- For derivations of CPP types skip primitives located in
5779 -- the C++ part of the dispatch table because their slots
5780 -- are initialized by the IC routine.
5782 and then (not Is_CPP_Class
(Root_Type
(Typ
))
5783 or else Prim_Pos
> CPP_Nb_Prims
)
5785 -- Skip ignored Ghost subprograms as those will be removed
5786 -- from the executable.
5788 and then not Is_Ignored_Ghost_Entity
(E
)
5791 (UI_To_Int
(DT_Position
(Prim
)) <= Nb_Prim
);
5793 Prim_Table
(UI_To_Int
(DT_Position
(Prim
))) := E
;
5796 Next_Elmt
(Prim_Elmt
);
5799 for J
in Prim_Table
'Range loop
5800 if Present
(Prim_Table
(J
)) then
5802 Unchecked_Convert_To
(RTE
(RE_Prim_Ptr
),
5803 Make_Attribute_Reference
(Loc
,
5805 New_Occurrence_Of
(Prim_Table
(J
), Loc
),
5806 Attribute_Name
=> Name_Unrestricted_Access
));
5808 New_Node
:= Make_Null
(Loc
);
5811 Append_To
(Prim_Ops_Aggr_List
, New_Node
);
5817 Make_Aggregate
(Loc
,
5818 Expressions
=> Prim_Ops_Aggr_List
);
5820 Append_To
(DT_Aggr_List
, New_Node
);
5822 -- Remember aggregates initializing dispatch tables
5824 Append_Elmt
(New_Node
, DT_Aggr
);
5826 -- In case of locally defined tagged types we have already declared
5827 -- and uninitialized object for the dispatch table, which is now
5828 -- initialized by means of an assignment.
5830 if not Building_Static_DT
(Typ
) then
5832 Make_Assignment_Statement
(Loc
,
5833 Name
=> New_Occurrence_Of
(DT
, Loc
),
5834 Expression
=> Make_Aggregate
(Loc
, DT_Aggr_List
)));
5836 -- In case of library level tagged types we declare now and export
5837 -- the constant object containing the dispatch table.
5841 Make_Object_Declaration
(Loc
,
5842 Defining_Identifier
=> DT
,
5843 Aliased_Present
=> True,
5844 Constant_Present
=> True,
5845 Object_Definition
=>
5846 Make_Subtype_Indication
(Loc
,
5847 Subtype_Mark
=> New_Occurrence_Of
5848 (RTE
(RE_Dispatch_Table_Wrapper
), Loc
),
5849 Constraint
=> Make_Index_Or_Discriminant_Constraint
(Loc
,
5850 Constraints
=> DT_Constr_List
)),
5851 Expression
=> Make_Aggregate
(Loc
, DT_Aggr_List
)));
5854 Make_Attribute_Definition_Clause
(Loc
,
5855 Name
=> New_Occurrence_Of
(DT
, Loc
),
5856 Chars
=> Name_Alignment
,
5858 Make_Attribute_Reference
(Loc
,
5860 New_Occurrence_Of
(RTE
(RE_Integer_Address
), Loc
),
5861 Attribute_Name
=> Name_Alignment
)));
5863 Export_DT
(Typ
, DT
);
5867 -- Initialize the table of ancestor tags if not building static
5870 if not Building_Static_DT
(Typ
)
5871 and then not Is_Interface
(Typ
)
5872 and then not Is_CPP_Class
(Typ
)
5875 Make_Assignment_Statement
(Loc
,
5877 Make_Indexed_Component
(Loc
,
5879 Make_Selected_Component
(Loc
,
5880 Prefix
=> New_Occurrence_Of
(TSD
, Loc
),
5883 (RTE_Record_Component
(RE_Tags_Table
), Loc
)),
5885 New_List
(Make_Integer_Literal
(Loc
, 0))),
5889 (Node
(First_Elmt
(Access_Disp_Table
(Typ
))), Loc
)));
5892 -- Inherit the dispatch tables of the parent. There is no need to
5893 -- inherit anything from the parent when building static dispatch tables
5894 -- because the whole dispatch table (including inherited primitives) has
5895 -- been already built.
5897 if Building_Static_DT
(Typ
) then
5900 -- If the ancestor is a CPP_Class type we inherit the dispatch tables
5901 -- in the init proc, and we don't need to fill them in here.
5903 elsif Is_CPP_Class
(Parent_Typ
) then
5906 -- Otherwise we fill in the dispatch tables here
5909 if Typ
/= Parent_Typ
5910 and then not Is_Interface
(Typ
)
5911 and then not Restriction_Active
(No_Dispatching_Calls
)
5913 -- Inherit the dispatch table
5915 if not Is_Interface
(Typ
)
5916 and then not Is_Interface
(Parent_Typ
)
5917 and then not Is_CPP_Class
(Parent_Typ
)
5920 Nb_Prims
: constant Int
:=
5921 UI_To_Int
(DT_Entry_Count
5922 (First_Tag_Component
(Parent_Typ
)));
5925 Append_To
(Elab_Code
,
5926 Build_Inherit_Predefined_Prims
(Loc
,
5932 (Access_Disp_Table
(Parent_Typ
)))), Loc
),
5938 (Access_Disp_Table
(Typ
)))), Loc
)));
5940 if Nb_Prims
/= 0 then
5941 Append_To
(Elab_Code
,
5942 Build_Inherit_Prims
(Loc
,
5948 (Access_Disp_Table
(Parent_Typ
))), Loc
),
5949 New_Tag_Node
=> New_Occurrence_Of
(DT_Ptr
, Loc
),
5950 Num_Prims
=> Nb_Prims
));
5955 -- Inherit the secondary dispatch tables of the ancestor
5957 if not Is_CPP_Class
(Parent_Typ
) then
5959 Sec_DT_Ancestor
: Elmt_Id
:=
5965 Sec_DT_Typ
: Elmt_Id
:=
5969 (Access_Disp_Table
(Typ
))));
5971 procedure Copy_Secondary_DTs
(Typ
: Entity_Id
);
5972 -- Local procedure required to climb through the ancestors
5973 -- and copy the contents of all their secondary dispatch
5976 ------------------------
5977 -- Copy_Secondary_DTs --
5978 ------------------------
5980 procedure Copy_Secondary_DTs
(Typ
: Entity_Id
) is
5985 -- Climb to the ancestor (if any) handling private types
5987 if Present
(Full_View
(Etype
(Typ
))) then
5988 if Full_View
(Etype
(Typ
)) /= Typ
then
5989 Copy_Secondary_DTs
(Full_View
(Etype
(Typ
)));
5992 elsif Etype
(Typ
) /= Typ
then
5993 Copy_Secondary_DTs
(Etype
(Typ
));
5996 if Present
(Interfaces
(Typ
))
5997 and then not Is_Empty_Elmt_List
(Interfaces
(Typ
))
5999 Iface
:= First_Elmt
(Interfaces
(Typ
));
6000 E
:= First_Entity
(Typ
);
6002 and then Present
(Node
(Sec_DT_Ancestor
))
6003 and then Ekind
(Node
(Sec_DT_Ancestor
)) = E_Constant
6005 if Is_Tag
(E
) and then Chars
(E
) /= Name_uTag
then
6007 Num_Prims
: constant Int
:=
6008 UI_To_Int
(DT_Entry_Count
(E
));
6011 if not Is_Interface
(Etype
(Typ
)) then
6013 -- Inherit first secondary dispatch table
6015 Append_To
(Elab_Code
,
6016 Build_Inherit_Predefined_Prims
(Loc
,
6018 Unchecked_Convert_To
(RTE
(RE_Tag
),
6021 (Next_Elmt
(Sec_DT_Ancestor
)),
6024 Unchecked_Convert_To
(RTE
(RE_Tag
),
6026 (Node
(Next_Elmt
(Sec_DT_Typ
)),
6029 if Num_Prims
/= 0 then
6030 Append_To
(Elab_Code
,
6031 Build_Inherit_Prims
(Loc
,
6032 Typ
=> Node
(Iface
),
6034 Unchecked_Convert_To
6037 (Node
(Sec_DT_Ancestor
),
6040 Unchecked_Convert_To
6043 (Node
(Sec_DT_Typ
), Loc
)),
6044 Num_Prims
=> Num_Prims
));
6048 Next_Elmt
(Sec_DT_Ancestor
);
6049 Next_Elmt
(Sec_DT_Typ
);
6051 -- Skip the secondary dispatch table of
6052 -- predefined primitives
6054 Next_Elmt
(Sec_DT_Ancestor
);
6055 Next_Elmt
(Sec_DT_Typ
);
6057 if not Is_Interface
(Etype
(Typ
)) then
6059 -- Inherit second secondary dispatch table
6061 Append_To
(Elab_Code
,
6062 Build_Inherit_Predefined_Prims
(Loc
,
6064 Unchecked_Convert_To
(RTE
(RE_Tag
),
6067 (Next_Elmt
(Sec_DT_Ancestor
)),
6070 Unchecked_Convert_To
(RTE
(RE_Tag
),
6072 (Node
(Next_Elmt
(Sec_DT_Typ
)),
6075 if Num_Prims
/= 0 then
6076 Append_To
(Elab_Code
,
6077 Build_Inherit_Prims
(Loc
,
6078 Typ
=> Node
(Iface
),
6080 Unchecked_Convert_To
6083 (Node
(Sec_DT_Ancestor
),
6086 Unchecked_Convert_To
6089 (Node
(Sec_DT_Typ
), Loc
)),
6090 Num_Prims
=> Num_Prims
));
6095 Next_Elmt
(Sec_DT_Ancestor
);
6096 Next_Elmt
(Sec_DT_Typ
);
6098 -- Skip the secondary dispatch table of
6099 -- predefined primitives
6101 Next_Elmt
(Sec_DT_Ancestor
);
6102 Next_Elmt
(Sec_DT_Typ
);
6110 end Copy_Secondary_DTs
;
6113 if Present
(Node
(Sec_DT_Ancestor
))
6114 and then Ekind
(Node
(Sec_DT_Ancestor
)) = E_Constant
6116 -- Handle private types
6118 if Present
(Full_View
(Typ
)) then
6119 Copy_Secondary_DTs
(Full_View
(Typ
));
6121 Copy_Secondary_DTs
(Typ
);
6129 -- Generate code to check if the external tag of this type is the same
6130 -- as the external tag of some other declaration.
6132 -- Check_TSD (TSD'Unrestricted_Access);
6134 -- This check is a consequence of AI05-0113-1/06, so it officially
6135 -- applies to Ada 2005 (and Ada 2012). It might be argued that it is
6136 -- a desirable check to add in Ada 95 mode, but we hesitate to make
6137 -- this change, as it would be incompatible, and could conceivably
6138 -- cause a problem in existing Aa 95 code.
6140 -- We check for No_Run_Time_Mode here, because we do not want to pick
6141 -- up the RE_Check_TSD entity and call it in No_Run_Time mode.
6143 if not No_Run_Time_Mode
6144 and then Ada_Version
>= Ada_2005
6145 and then RTE_Available
(RE_Check_TSD
)
6146 and then not Duplicated_Tag_Checks_Suppressed
(Typ
)
6148 Append_To
(Elab_Code
,
6149 Make_Procedure_Call_Statement
(Loc
,
6151 New_Occurrence_Of
(RTE
(RE_Check_TSD
), Loc
),
6152 Parameter_Associations
=> New_List
(
6153 Make_Attribute_Reference
(Loc
,
6154 Prefix
=> New_Occurrence_Of
(TSD
, Loc
),
6155 Attribute_Name
=> Name_Unchecked_Access
))));
6158 -- Generate code to register the Tag in the External_Tag hash table for
6159 -- the pure Ada type only.
6161 -- Register_Tag (Dt_Ptr);
6163 -- Skip this action in the following cases:
6164 -- 1) if Register_Tag is not available.
6165 -- 2) in No_Run_Time mode.
6166 -- 3) if Typ is not defined at the library level (this is required
6167 -- to avoid adding concurrency control to the hash table used
6168 -- by the run-time to register the tags).
6170 if not No_Run_Time_Mode
6171 and then Is_Library_Level_Entity
(Typ
)
6172 and then RTE_Available
(RE_Register_Tag
)
6174 Append_To
(Elab_Code
,
6175 Make_Procedure_Call_Statement
(Loc
,
6177 New_Occurrence_Of
(RTE
(RE_Register_Tag
), Loc
),
6178 Parameter_Associations
=>
6179 New_List
(New_Occurrence_Of
(DT_Ptr
, Loc
))));
6182 if not Is_Empty_List
(Elab_Code
) then
6183 Append_List_To
(Result
, Elab_Code
);
6186 -- Populate the two auxiliary tables used for dispatching asynchronous,
6187 -- conditional and timed selects for synchronized types that implement
6188 -- a limited interface. Skip this step in Ravenscar profile or when
6189 -- general dispatching is forbidden.
6191 if Ada_Version
>= Ada_2005
6192 and then Is_Concurrent_Record_Type
(Typ
)
6193 and then Has_Interfaces
(Typ
)
6194 and then not Restriction_Active
(No_Dispatching_Calls
)
6195 and then not Restriction_Active
(No_Select_Statements
)
6197 Append_List_To
(Result
,
6198 Make_Select_Specific_Data_Table
(Typ
));
6201 -- Remember entities containing dispatch tables
6203 Append_Elmt
(Predef_Prims
, DT_Decl
);
6204 Append_Elmt
(DT
, DT_Decl
);
6206 Analyze_List
(Result
, Suppress
=> All_Checks
);
6207 Set_Has_Dispatch_Table
(Typ
);
6209 -- Mark entities containing dispatch tables. Required by the backend to
6210 -- handle them properly.
6212 if Has_DT
(Typ
) then
6217 -- Object declarations
6219 Elmt
:= First_Elmt
(DT_Decl
);
6220 while Present
(Elmt
) loop
6221 Set_Is_Dispatch_Table_Entity
(Node
(Elmt
));
6222 pragma Assert
(Ekind
(Etype
(Node
(Elmt
))) = E_Array_Subtype
6223 or else Ekind
(Etype
(Node
(Elmt
))) = E_Record_Subtype
);
6224 Set_Is_Dispatch_Table_Entity
(Etype
(Node
(Elmt
)));
6228 -- Aggregates initializing dispatch tables
6230 Elmt
:= First_Elmt
(DT_Aggr
);
6231 while Present
(Elmt
) loop
6232 Set_Is_Dispatch_Table_Entity
(Etype
(Node
(Elmt
)));
6240 -- Register the tagged type in the call graph nodes table
6242 Register_CG_Node
(Typ
);
6245 Restore_Ghost_Mode
(Mode
);
6250 -------------------------------------
6251 -- Make_Select_Specific_Data_Table --
6252 -------------------------------------
6254 function Make_Select_Specific_Data_Table
6255 (Typ
: Entity_Id
) return List_Id
6257 Assignments
: constant List_Id
:= New_List
;
6258 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
6260 Conc_Typ
: Entity_Id
;
6263 Prim_Als
: Entity_Id
;
6264 Prim_Elmt
: Elmt_Id
;
6268 type Examined_Array
is array (Int
range <>) of Boolean;
6270 function Find_Entry_Index
(E
: Entity_Id
) return Uint
;
6271 -- Given an entry, find its index in the visible declarations of the
6272 -- corresponding concurrent type of Typ.
6274 ----------------------
6275 -- Find_Entry_Index --
6276 ----------------------
6278 function Find_Entry_Index
(E
: Entity_Id
) return Uint
is
6279 Index
: Uint
:= Uint_1
;
6280 Subp_Decl
: Entity_Id
;
6284 and then not Is_Empty_List
(Decls
)
6286 Subp_Decl
:= First
(Decls
);
6287 while Present
(Subp_Decl
) loop
6288 if Nkind
(Subp_Decl
) = N_Entry_Declaration
then
6289 if Defining_Identifier
(Subp_Decl
) = E
then
6301 end Find_Entry_Index
;
6307 -- Start of processing for Make_Select_Specific_Data_Table
6310 pragma Assert
(not Restriction_Active
(No_Dispatching_Calls
));
6312 if Present
(Corresponding_Concurrent_Type
(Typ
)) then
6313 Conc_Typ
:= Corresponding_Concurrent_Type
(Typ
);
6315 if Present
(Full_View
(Conc_Typ
)) then
6316 Conc_Typ
:= Full_View
(Conc_Typ
);
6319 if Ekind
(Conc_Typ
) = E_Protected_Type
then
6320 Decls
:= Visible_Declarations
(Protected_Definition
(
6321 Parent
(Conc_Typ
)));
6323 pragma Assert
(Ekind
(Conc_Typ
) = E_Task_Type
);
6324 Decls
:= Visible_Declarations
(Task_Definition
(
6325 Parent
(Conc_Typ
)));
6329 -- Count the non-predefined primitive operations
6331 Prim_Elmt
:= First_Elmt
(Primitive_Operations
(Typ
));
6332 while Present
(Prim_Elmt
) loop
6333 Prim
:= Node
(Prim_Elmt
);
6335 if not (Is_Predefined_Dispatching_Operation
(Prim
)
6336 or else Is_Predefined_Dispatching_Alias
(Prim
))
6338 Nb_Prim
:= Nb_Prim
+ 1;
6341 Next_Elmt
(Prim_Elmt
);
6345 Examined
: Examined_Array
(1 .. Nb_Prim
) := (others => False);
6348 Prim_Elmt
:= First_Elmt
(Primitive_Operations
(Typ
));
6349 while Present
(Prim_Elmt
) loop
6350 Prim
:= Node
(Prim_Elmt
);
6352 -- Look for primitive overriding an abstract interface subprogram
6354 if Present
(Interface_Alias
(Prim
))
6357 (Find_Dispatching_Type
(Interface_Alias
(Prim
)), Typ
,
6358 Use_Full_View
=> True)
6359 and then not Examined
(UI_To_Int
(DT_Position
(Alias
(Prim
))))
6361 Prim_Pos
:= DT_Position
(Alias
(Prim
));
6362 pragma Assert
(UI_To_Int
(Prim_Pos
) <= Nb_Prim
);
6363 Examined
(UI_To_Int
(Prim_Pos
)) := True;
6365 -- Set the primitive operation kind regardless of subprogram
6367 -- Ada.Tags.Set_Prim_Op_Kind (DT_Ptr, <position>, <kind>);
6369 if Tagged_Type_Expansion
then
6372 (Node
(First_Elmt
(Access_Disp_Table
(Typ
))), Loc
);
6376 Make_Attribute_Reference
(Loc
,
6377 Prefix
=> New_Occurrence_Of
(Typ
, Loc
),
6378 Attribute_Name
=> Name_Tag
);
6381 Append_To
(Assignments
,
6382 Make_Procedure_Call_Statement
(Loc
,
6383 Name
=> New_Occurrence_Of
(RTE
(RE_Set_Prim_Op_Kind
), Loc
),
6384 Parameter_Associations
=> New_List
(
6386 Make_Integer_Literal
(Loc
, Prim_Pos
),
6387 Prim_Op_Kind
(Alias
(Prim
), Typ
))));
6389 -- Retrieve the root of the alias chain
6391 Prim_Als
:= Ultimate_Alias
(Prim
);
6393 -- In the case of an entry wrapper, set the entry index
6395 if Ekind
(Prim
) = E_Procedure
6396 and then Is_Primitive_Wrapper
(Prim_Als
)
6397 and then Ekind
(Wrapped_Entity
(Prim_Als
)) = E_Entry
6400 -- Ada.Tags.Set_Entry_Index
6401 -- (DT_Ptr, <position>, <index>);
6403 if Tagged_Type_Expansion
then
6406 (Node
(First_Elmt
(Access_Disp_Table
(Typ
))), Loc
);
6409 Make_Attribute_Reference
(Loc
,
6410 Prefix
=> New_Occurrence_Of
(Typ
, Loc
),
6411 Attribute_Name
=> Name_Tag
);
6414 Append_To
(Assignments
,
6415 Make_Procedure_Call_Statement
(Loc
,
6417 New_Occurrence_Of
(RTE
(RE_Set_Entry_Index
), Loc
),
6418 Parameter_Associations
=> New_List
(
6420 Make_Integer_Literal
(Loc
, Prim_Pos
),
6421 Make_Integer_Literal
(Loc
,
6422 Find_Entry_Index
(Wrapped_Entity
(Prim_Als
))))));
6426 Next_Elmt
(Prim_Elmt
);
6431 end Make_Select_Specific_Data_Table
;
6437 function Make_Tags
(Typ
: Entity_Id
) return List_Id
is
6438 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
6439 Result
: constant List_Id
:= New_List
;
6442 (Tag_Typ
: Entity_Id
;
6444 Is_Secondary_DT
: Boolean);
6445 -- Import the dispatch table DT of tagged type Tag_Typ. Required to
6446 -- generate forward references and statically allocate the table. For
6447 -- primary dispatch tables that require no dispatch table generate:
6449 -- DT : static aliased constant Non_Dispatch_Table_Wrapper;
6450 -- pragma Import (Ada, DT);
6452 -- Otherwise generate:
6454 -- DT : static aliased constant Dispatch_Table_Wrapper (Nb_Prim);
6455 -- pragma Import (Ada, DT);
6462 (Tag_Typ
: Entity_Id
;
6464 Is_Secondary_DT
: Boolean)
6466 DT_Constr_List
: List_Id
;
6470 Set_Is_Imported
(DT
);
6471 Set_Ekind
(DT
, E_Constant
);
6472 Set_Related_Type
(DT
, Typ
);
6474 -- The scope must be set now to call Get_External_Name
6476 Set_Scope
(DT
, Current_Scope
);
6478 Get_External_Name
(DT
);
6479 Set_Interface_Name
(DT
,
6480 Make_String_Literal
(Loc
, Strval
=> String_From_Name_Buffer
));
6482 -- Ensure proper Sprint output of this implicit importation
6484 Set_Is_Internal
(DT
);
6486 -- Save this entity to allow Make_DT to generate its exportation
6488 Append_Elmt
(DT
, Dispatch_Table_Wrappers
(Typ
));
6490 -- No dispatch table required
6492 if not Is_Secondary_DT
and then not Has_DT
(Tag_Typ
) then
6494 Make_Object_Declaration
(Loc
,
6495 Defining_Identifier
=> DT
,
6496 Aliased_Present
=> True,
6497 Constant_Present
=> True,
6498 Object_Definition
=>
6500 (RTE
(RE_No_Dispatch_Table_Wrapper
), Loc
)));
6503 -- Calculate the number of primitives of the dispatch table and
6504 -- the size of the Type_Specific_Data record.
6507 UI_To_Int
(DT_Entry_Count
(First_Tag_Component
(Tag_Typ
)));
6509 -- If the tagged type has no primitives we add a dummy slot whose
6510 -- address will be the tag of this type.
6514 New_List
(Make_Integer_Literal
(Loc
, 1));
6517 New_List
(Make_Integer_Literal
(Loc
, Nb_Prim
));
6521 Make_Object_Declaration
(Loc
,
6522 Defining_Identifier
=> DT
,
6523 Aliased_Present
=> True,
6524 Constant_Present
=> True,
6525 Object_Definition
=>
6526 Make_Subtype_Indication
(Loc
,
6528 New_Occurrence_Of
(RTE
(RE_Dispatch_Table_Wrapper
), Loc
),
6529 Constraint
=> Make_Index_Or_Discriminant_Constraint
(Loc
,
6530 Constraints
=> DT_Constr_List
))));
6536 Tname
: constant Name_Id
:= Chars
(Typ
);
6537 AI_Tag_Comp
: Elmt_Id
;
6538 DT
: Node_Id
:= Empty
;
6540 Predef_Prims_Ptr
: Node_Id
;
6541 Iface_DT
: Node_Id
:= Empty
;
6542 Iface_DT_Ptr
: Node_Id
;
6546 Typ_Comps
: Elist_Id
;
6548 -- Start of processing for Make_Tags
6551 pragma Assert
(No
(Access_Disp_Table
(Typ
)));
6552 Set_Access_Disp_Table
(Typ
, New_Elmt_List
);
6554 -- 1) Generate the primary tag entities
6556 -- Primary dispatch table containing user-defined primitives
6558 DT_Ptr
:= Make_Defining_Identifier
(Loc
, New_External_Name
(Tname
, 'P'));
6559 Set_Etype
(DT_Ptr
, RTE
(RE_Tag
));
6560 Append_Elmt
(DT_Ptr
, Access_Disp_Table
(Typ
));
6562 -- Minimum decoration
6564 Set_Ekind
(DT_Ptr
, E_Variable
);
6565 Set_Related_Type
(DT_Ptr
, Typ
);
6567 -- Notify back end that the types are associated with a dispatch table
6569 Set_Is_Dispatch_Table_Entity
(RTE
(RE_Prim_Ptr
));
6570 Set_Is_Dispatch_Table_Entity
(RTE
(RE_Predef_Prims_Table_Ptr
));
6572 -- For CPP types there is no need to build the dispatch tables since
6573 -- they are imported from the C++ side. If the CPP type has an IP then
6574 -- we declare now the variable that will store the copy of the C++ tag.
6575 -- If the CPP type is an interface, we need the variable as well because
6576 -- it becomes the pointer to the corresponding secondary table.
6578 if Is_CPP_Class
(Typ
) then
6579 if Has_CPP_Constructors
(Typ
) or else Is_Interface
(Typ
) then
6581 Make_Object_Declaration
(Loc
,
6582 Defining_Identifier
=> DT_Ptr
,
6583 Object_Definition
=> New_Occurrence_Of
(RTE
(RE_Tag
), Loc
),
6585 Unchecked_Convert_To
(RTE
(RE_Tag
),
6586 New_Occurrence_Of
(RTE
(RE_Null_Address
), Loc
))));
6588 Set_Is_Statically_Allocated
(DT_Ptr
,
6589 Is_Library_Level_Tagged_Type
(Typ
));
6595 -- Primary dispatch table containing predefined primitives
6598 Make_Defining_Identifier
(Loc
,
6599 Chars
=> New_External_Name
(Tname
, 'Y'));
6600 Set_Etype
(Predef_Prims_Ptr
, RTE
(RE_Address
));
6601 Append_Elmt
(Predef_Prims_Ptr
, Access_Disp_Table
(Typ
));
6603 -- Import the forward declaration of the Dispatch Table wrapper
6604 -- record (Make_DT will take care of exporting it).
6606 if Building_Static_DT
(Typ
) then
6607 Set_Dispatch_Table_Wrappers
(Typ
, New_Elmt_List
);
6610 Make_Defining_Identifier
(Loc
,
6611 Chars
=> New_External_Name
(Tname
, 'T'));
6613 Import_DT
(Typ
, DT
, Is_Secondary_DT
=> False);
6615 if Has_DT
(Typ
) then
6617 Make_Object_Declaration
(Loc
,
6618 Defining_Identifier
=> DT_Ptr
,
6619 Constant_Present
=> True,
6620 Object_Definition
=>
6621 New_Occurrence_Of
(RTE
(RE_Tag
), Loc
),
6623 Unchecked_Convert_To
(RTE
(RE_Tag
),
6624 Make_Attribute_Reference
(Loc
,
6626 Make_Selected_Component
(Loc
,
6627 Prefix
=> New_Occurrence_Of
(DT
, Loc
),
6630 (RTE_Record_Component
(RE_Prims_Ptr
), Loc
)),
6631 Attribute_Name
=> Name_Address
))));
6633 -- Generate the SCIL node for the previous object declaration
6634 -- because it has a tag initialization.
6636 if Generate_SCIL
then
6638 Make_SCIL_Dispatch_Table_Tag_Init
(Sloc
(Last
(Result
)));
6639 Set_SCIL_Entity
(New_Node
, Typ
);
6640 Set_SCIL_Node
(Last
(Result
), New_Node
);
6644 Make_Object_Declaration
(Loc
,
6645 Defining_Identifier
=> Predef_Prims_Ptr
,
6646 Constant_Present
=> True,
6647 Object_Definition
=>
6648 New_Occurrence_Of
(RTE
(RE_Address
), Loc
),
6650 Make_Attribute_Reference
(Loc
,
6652 Make_Selected_Component
(Loc
,
6653 Prefix
=> New_Occurrence_Of
(DT
, Loc
),
6656 (RTE_Record_Component
(RE_Predef_Prims
), Loc
)),
6657 Attribute_Name
=> Name_Address
)));
6659 -- No dispatch table required
6663 Make_Object_Declaration
(Loc
,
6664 Defining_Identifier
=> DT_Ptr
,
6665 Constant_Present
=> True,
6666 Object_Definition
=>
6667 New_Occurrence_Of
(RTE
(RE_Tag
), Loc
),
6669 Unchecked_Convert_To
(RTE
(RE_Tag
),
6670 Make_Attribute_Reference
(Loc
,
6672 Make_Selected_Component
(Loc
,
6673 Prefix
=> New_Occurrence_Of
(DT
, Loc
),
6676 (RTE_Record_Component
(RE_NDT_Prims_Ptr
),
6678 Attribute_Name
=> Name_Address
))));
6681 Set_Is_True_Constant
(DT_Ptr
);
6682 Set_Is_Statically_Allocated
(DT_Ptr
);
6686 -- 2) Generate the secondary tag entities
6688 -- Collect the components associated with secondary dispatch tables
6690 if Has_Interfaces
(Typ
) then
6691 Collect_Interface_Components
(Typ
, Typ_Comps
);
6693 -- For each interface type we build a unique external name associated
6694 -- with its secondary dispatch table. This name is used to declare an
6695 -- object that references this secondary dispatch table, whose value
6696 -- will be used for the elaboration of Typ objects, and also for the
6697 -- elaboration of objects of types derived from Typ that do not
6698 -- override the primitives of this interface type.
6702 -- Note: The value of Suffix_Index must be in sync with the values of
6703 -- Suffix_Index in secondary dispatch tables generated by Make_DT.
6705 if Is_CPP_Class
(Typ
) then
6706 AI_Tag_Comp
:= First_Elmt
(Typ_Comps
);
6707 while Present
(AI_Tag_Comp
) loop
6708 Get_Secondary_DT_External_Name
6709 (Typ
, Related_Type
(Node
(AI_Tag_Comp
)), Suffix_Index
);
6710 Typ_Name
:= Name_Find
;
6712 -- Declare variables to store copy of the C++ secondary tags
6715 Make_Defining_Identifier
(Loc
,
6716 Chars
=> New_External_Name
(Typ_Name
, 'P'));
6717 Set_Etype
(Iface_DT_Ptr
, RTE
(RE_Interface_Tag
));
6718 Set_Ekind
(Iface_DT_Ptr
, E_Variable
);
6719 Set_Is_Tag
(Iface_DT_Ptr
);
6721 Set_Has_Thunks
(Iface_DT_Ptr
);
6723 (Iface_DT_Ptr
, Related_Type
(Node
(AI_Tag_Comp
)));
6724 Append_Elmt
(Iface_DT_Ptr
, Access_Disp_Table
(Typ
));
6727 Make_Object_Declaration
(Loc
,
6728 Defining_Identifier
=> Iface_DT_Ptr
,
6729 Object_Definition
=> New_Occurrence_Of
6730 (RTE
(RE_Interface_Tag
), Loc
),
6732 Unchecked_Convert_To
(RTE
(RE_Interface_Tag
),
6733 New_Occurrence_Of
(RTE
(RE_Null_Address
), Loc
))));
6735 Set_Is_Statically_Allocated
(Iface_DT_Ptr
,
6736 Is_Library_Level_Tagged_Type
(Typ
));
6738 Next_Elmt
(AI_Tag_Comp
);
6741 -- This is not a CPP_Class type
6744 AI_Tag_Comp
:= First_Elmt
(Typ_Comps
);
6745 while Present
(AI_Tag_Comp
) loop
6746 Get_Secondary_DT_External_Name
6747 (Typ
, Related_Type
(Node
(AI_Tag_Comp
)), Suffix_Index
);
6748 Typ_Name
:= Name_Find
;
6750 if Building_Static_DT
(Typ
) then
6752 Make_Defining_Identifier
(Loc
,
6753 Chars
=> New_External_Name
(Typ_Name
, 'T'));
6755 (Tag_Typ
=> Related_Type
(Node
(AI_Tag_Comp
)),
6757 Is_Secondary_DT
=> True);
6760 -- Secondary dispatch table referencing thunks to user-defined
6761 -- primitives covered by this interface.
6764 Make_Defining_Identifier
(Loc
,
6765 Chars
=> New_External_Name
(Typ_Name
, 'P'));
6766 Set_Etype
(Iface_DT_Ptr
, RTE
(RE_Interface_Tag
));
6767 Set_Ekind
(Iface_DT_Ptr
, E_Constant
);
6768 Set_Is_Tag
(Iface_DT_Ptr
);
6769 Set_Has_Thunks
(Iface_DT_Ptr
);
6770 Set_Is_Statically_Allocated
(Iface_DT_Ptr
,
6771 Is_Library_Level_Tagged_Type
(Typ
));
6772 Set_Is_True_Constant
(Iface_DT_Ptr
);
6774 (Iface_DT_Ptr
, Related_Type
(Node
(AI_Tag_Comp
)));
6775 Append_Elmt
(Iface_DT_Ptr
, Access_Disp_Table
(Typ
));
6777 if Building_Static_DT
(Typ
) then
6779 Make_Object_Declaration
(Loc
,
6780 Defining_Identifier
=> Iface_DT_Ptr
,
6781 Constant_Present
=> True,
6782 Object_Definition
=> New_Occurrence_Of
6783 (RTE
(RE_Interface_Tag
), Loc
),
6785 Unchecked_Convert_To
(RTE
(RE_Interface_Tag
),
6786 Make_Attribute_Reference
(Loc
,
6788 Make_Selected_Component
(Loc
,
6790 New_Occurrence_Of
(Iface_DT
, Loc
),
6793 (RTE_Record_Component
(RE_Prims_Ptr
),
6795 Attribute_Name
=> Name_Address
))));
6798 -- Secondary dispatch table referencing thunks to predefined
6802 Make_Defining_Identifier
(Loc
,
6803 Chars
=> New_External_Name
(Typ_Name
, 'Y'));
6804 Set_Etype
(Iface_DT_Ptr
, RTE
(RE_Address
));
6805 Set_Ekind
(Iface_DT_Ptr
, E_Constant
);
6806 Set_Is_Tag
(Iface_DT_Ptr
);
6807 Set_Has_Thunks
(Iface_DT_Ptr
);
6808 Set_Is_Statically_Allocated
(Iface_DT_Ptr
,
6809 Is_Library_Level_Tagged_Type
(Typ
));
6810 Set_Is_True_Constant
(Iface_DT_Ptr
);
6812 (Iface_DT_Ptr
, Related_Type
(Node
(AI_Tag_Comp
)));
6813 Append_Elmt
(Iface_DT_Ptr
, Access_Disp_Table
(Typ
));
6815 -- Secondary dispatch table referencing user-defined primitives
6816 -- covered by this interface.
6819 Make_Defining_Identifier
(Loc
,
6820 Chars
=> New_External_Name
(Typ_Name
, 'D'));
6821 Set_Etype
(Iface_DT_Ptr
, RTE
(RE_Interface_Tag
));
6822 Set_Ekind
(Iface_DT_Ptr
, E_Constant
);
6823 Set_Is_Tag
(Iface_DT_Ptr
);
6824 Set_Is_Statically_Allocated
(Iface_DT_Ptr
,
6825 Is_Library_Level_Tagged_Type
(Typ
));
6826 Set_Is_True_Constant
(Iface_DT_Ptr
);
6828 (Iface_DT_Ptr
, Related_Type
(Node
(AI_Tag_Comp
)));
6829 Append_Elmt
(Iface_DT_Ptr
, Access_Disp_Table
(Typ
));
6831 -- Secondary dispatch table referencing predefined primitives
6834 Make_Defining_Identifier
(Loc
,
6835 Chars
=> New_External_Name
(Typ_Name
, 'Z'));
6836 Set_Etype
(Iface_DT_Ptr
, RTE
(RE_Address
));
6837 Set_Ekind
(Iface_DT_Ptr
, E_Constant
);
6838 Set_Is_Tag
(Iface_DT_Ptr
);
6839 Set_Is_Statically_Allocated
(Iface_DT_Ptr
,
6840 Is_Library_Level_Tagged_Type
(Typ
));
6841 Set_Is_True_Constant
(Iface_DT_Ptr
);
6843 (Iface_DT_Ptr
, Related_Type
(Node
(AI_Tag_Comp
)));
6844 Append_Elmt
(Iface_DT_Ptr
, Access_Disp_Table
(Typ
));
6846 Next_Elmt
(AI_Tag_Comp
);
6851 -- 3) At the end of Access_Disp_Table, if the type has user-defined
6852 -- primitives, we add the entity of an access type declaration that
6853 -- is used by Build_Get_Prim_Op_Address to expand dispatching calls
6854 -- through the primary dispatch table.
6856 if UI_To_Int
(DT_Entry_Count
(First_Tag_Component
(Typ
))) = 0 then
6857 Analyze_List
(Result
);
6860 -- type Typ_DT is array (1 .. Nb_Prims) of Prim_Ptr;
6861 -- type Typ_DT_Acc is access Typ_DT;
6865 Name_DT_Prims
: constant Name_Id
:=
6866 New_External_Name
(Tname
, 'G');
6867 Name_DT_Prims_Acc
: constant Name_Id
:=
6868 New_External_Name
(Tname
, 'H');
6869 DT_Prims
: constant Entity_Id
:=
6870 Make_Defining_Identifier
(Loc
,
6872 DT_Prims_Acc
: constant Entity_Id
:=
6873 Make_Defining_Identifier
(Loc
,
6877 Make_Full_Type_Declaration
(Loc
,
6878 Defining_Identifier
=> DT_Prims
,
6880 Make_Constrained_Array_Definition
(Loc
,
6881 Discrete_Subtype_Definitions
=> New_List
(
6883 Low_Bound
=> Make_Integer_Literal
(Loc
, 1),
6884 High_Bound
=> Make_Integer_Literal
(Loc
,
6886 (First_Tag_Component
(Typ
))))),
6887 Component_Definition
=>
6888 Make_Component_Definition
(Loc
,
6889 Subtype_Indication
=>
6890 New_Occurrence_Of
(RTE
(RE_Prim_Ptr
), Loc
)))));
6893 Make_Full_Type_Declaration
(Loc
,
6894 Defining_Identifier
=> DT_Prims_Acc
,
6896 Make_Access_To_Object_Definition
(Loc
,
6897 Subtype_Indication
=>
6898 New_Occurrence_Of
(DT_Prims
, Loc
))));
6900 Append_Elmt
(DT_Prims_Acc
, Access_Disp_Table
(Typ
));
6902 -- Analyze the resulting list and suppress the generation of the
6903 -- Init_Proc associated with the above array declaration because
6904 -- this type is never used in object declarations. It is only used
6905 -- to simplify the expansion associated with dispatching calls.
6907 Analyze_List
(Result
);
6908 Set_Suppress_Initialization
(Base_Type
(DT_Prims
));
6910 -- Disable backend optimizations based on assumptions about the
6911 -- aliasing status of objects designated by the access to the
6912 -- dispatch table. Required to handle dispatch tables imported
6915 Set_No_Strict_Aliasing
(Base_Type
(DT_Prims_Acc
));
6917 -- Add the freezing nodes of these declarations; required to avoid
6918 -- generating these freezing nodes in wrong scopes (for example in
6919 -- the IC routine of a derivation of Typ).
6921 -- What is an "IC routine"? Is "init_proc" meant here???
6923 Append_List_To
(Result
, Freeze_Entity
(DT_Prims
, Typ
));
6924 Append_List_To
(Result
, Freeze_Entity
(DT_Prims_Acc
, Typ
));
6926 -- Mark entity of dispatch table. Required by the back end to
6927 -- handle them properly.
6929 Set_Is_Dispatch_Table_Entity
(DT_Prims
);
6933 -- Mark entities of dispatch table. Required by the back end to handle
6936 if Present
(DT
) then
6937 Set_Is_Dispatch_Table_Entity
(DT
);
6938 Set_Is_Dispatch_Table_Entity
(Etype
(DT
));
6941 if Present
(Iface_DT
) then
6942 Set_Is_Dispatch_Table_Entity
(Iface_DT
);
6943 Set_Is_Dispatch_Table_Entity
(Etype
(Iface_DT
));
6946 if Is_CPP_Class
(Root_Type
(Typ
)) then
6947 Set_Ekind
(DT_Ptr
, E_Variable
);
6949 Set_Ekind
(DT_Ptr
, E_Constant
);
6952 Set_Is_Tag
(DT_Ptr
);
6953 Set_Related_Type
(DT_Ptr
, Typ
);
6962 function New_Value
(From
: Node_Id
) return Node_Id
is
6963 Res
: constant Node_Id
:= Duplicate_Subexpr
(From
);
6965 if Is_Access_Type
(Etype
(From
)) then
6966 return Make_Explicit_Dereference
(Sloc
(From
), Prefix
=> Res
);
6972 -----------------------------------
6973 -- Original_View_In_Visible_Part --
6974 -----------------------------------
6976 function Original_View_In_Visible_Part
(Typ
: Entity_Id
) return Boolean is
6977 Scop
: constant Entity_Id
:= Scope
(Typ
);
6980 -- The scope must be a package
6982 if not Is_Package_Or_Generic_Package
(Scop
) then
6986 -- A type with a private declaration has a private view declared in
6987 -- the visible part.
6989 if Has_Private_Declaration
(Typ
) then
6993 return List_Containing
(Parent
(Typ
)) =
6994 Visible_Declarations
(Package_Specification
(Scop
));
6995 end Original_View_In_Visible_Part
;
7001 function Prim_Op_Kind
7003 Typ
: Entity_Id
) return Node_Id
7005 Full_Typ
: Entity_Id
:= Typ
;
7006 Loc
: constant Source_Ptr
:= Sloc
(Prim
);
7007 Prim_Op
: Entity_Id
;
7010 -- Retrieve the original primitive operation
7012 Prim_Op
:= Ultimate_Alias
(Prim
);
7014 if Ekind
(Typ
) = E_Record_Type
7015 and then Present
(Corresponding_Concurrent_Type
(Typ
))
7017 Full_Typ
:= Corresponding_Concurrent_Type
(Typ
);
7020 -- When a private tagged type is completed by a concurrent type,
7021 -- retrieve the full view.
7023 if Is_Private_Type
(Full_Typ
) then
7024 Full_Typ
:= Full_View
(Full_Typ
);
7027 if Ekind
(Prim_Op
) = E_Function
then
7029 -- Protected function
7031 if Ekind
(Full_Typ
) = E_Protected_Type
then
7032 return New_Occurrence_Of
(RTE
(RE_POK_Protected_Function
), Loc
);
7036 elsif Ekind
(Full_Typ
) = E_Task_Type
then
7037 return New_Occurrence_Of
(RTE
(RE_POK_Task_Function
), Loc
);
7042 return New_Occurrence_Of
(RTE
(RE_POK_Function
), Loc
);
7046 pragma Assert
(Ekind
(Prim_Op
) = E_Procedure
);
7048 if Ekind
(Full_Typ
) = E_Protected_Type
then
7052 if Is_Primitive_Wrapper
(Prim_Op
)
7053 and then Ekind
(Wrapped_Entity
(Prim_Op
)) = E_Entry
7055 return New_Occurrence_Of
(RTE
(RE_POK_Protected_Entry
), Loc
);
7057 -- Protected procedure
7061 New_Occurrence_Of
(RTE
(RE_POK_Protected_Procedure
), Loc
);
7064 elsif Ekind
(Full_Typ
) = E_Task_Type
then
7068 if Is_Primitive_Wrapper
(Prim_Op
)
7069 and then Ekind
(Wrapped_Entity
(Prim_Op
)) = E_Entry
7071 return New_Occurrence_Of
(RTE
(RE_POK_Task_Entry
), Loc
);
7073 -- Task "procedure". These are the internally Expander-generated
7074 -- procedures (task body for instance).
7077 return New_Occurrence_Of
(RTE
(RE_POK_Task_Procedure
), Loc
);
7080 -- Regular procedure
7083 return New_Occurrence_Of
(RTE
(RE_POK_Procedure
), Loc
);
7088 ------------------------
7089 -- Register_Primitive --
7090 ------------------------
7092 function Register_Primitive
7094 Prim
: Entity_Id
) return List_Id
7097 Iface_Prim
: Entity_Id
;
7098 Iface_Typ
: Entity_Id
;
7099 Iface_DT_Ptr
: Entity_Id
;
7100 Iface_DT_Elmt
: Elmt_Id
;
7101 L
: constant List_Id
:= New_List
;
7104 Tag_Typ
: Entity_Id
;
7105 Thunk_Id
: Entity_Id
;
7106 Thunk_Code
: Node_Id
;
7109 pragma Assert
(not Restriction_Active
(No_Dispatching_Calls
));
7111 -- Do not register in the dispatch table eliminated primitives
7113 if not RTE_Available
(RE_Tag
)
7114 or else Is_Eliminated
(Ultimate_Alias
(Prim
))
7115 or else Generate_SCIL
7120 if not Present
(Interface_Alias
(Prim
)) then
7121 Tag_Typ
:= Scope
(DTC_Entity
(Prim
));
7122 Pos
:= DT_Position
(Prim
);
7123 Tag
:= First_Tag_Component
(Tag_Typ
);
7125 if Is_Predefined_Dispatching_Operation
(Prim
)
7126 or else Is_Predefined_Dispatching_Alias
(Prim
)
7129 Node
(Next_Elmt
(First_Elmt
(Access_Disp_Table
(Tag_Typ
))));
7132 Build_Set_Predefined_Prim_Op_Address
(Loc
,
7133 Tag_Node
=> New_Occurrence_Of
(DT_Ptr
, Loc
),
7136 Unchecked_Convert_To
(RTE
(RE_Prim_Ptr
),
7137 Make_Attribute_Reference
(Loc
,
7138 Prefix
=> New_Occurrence_Of
(Prim
, Loc
),
7139 Attribute_Name
=> Name_Unrestricted_Access
))));
7141 -- Register copy of the pointer to the 'size primitive in the TSD
7143 if Chars
(Prim
) = Name_uSize
7144 and then RTE_Record_Component_Available
(RE_Size_Func
)
7146 DT_Ptr
:= Node
(First_Elmt
(Access_Disp_Table
(Tag_Typ
)));
7148 Build_Set_Size_Function
(Loc
,
7149 Tag_Node
=> New_Occurrence_Of
(DT_Ptr
, Loc
),
7150 Size_Func
=> Prim
));
7154 pragma Assert
(Pos
/= Uint_0
and then Pos
<= DT_Entry_Count
(Tag
));
7156 -- Skip registration of primitives located in the C++ part of the
7157 -- dispatch table. Their slot is set by the IC routine.
7159 if not Is_CPP_Class
(Root_Type
(Tag_Typ
))
7160 or else Pos
> CPP_Num_Prims
(Tag_Typ
)
7162 DT_Ptr
:= Node
(First_Elmt
(Access_Disp_Table
(Tag_Typ
)));
7164 Build_Set_Prim_Op_Address
(Loc
,
7166 Tag_Node
=> New_Occurrence_Of
(DT_Ptr
, Loc
),
7169 Unchecked_Convert_To
(RTE
(RE_Prim_Ptr
),
7170 Make_Attribute_Reference
(Loc
,
7171 Prefix
=> New_Occurrence_Of
(Prim
, Loc
),
7172 Attribute_Name
=> Name_Unrestricted_Access
))));
7176 -- Ada 2005 (AI-251): Primitive associated with an interface type
7178 -- Generate the code of the thunk only if the interface type is not an
7179 -- immediate ancestor of Typ; otherwise the dispatch table associated
7180 -- with the interface is the primary dispatch table and we have nothing
7184 Tag_Typ
:= Find_Dispatching_Type
(Alias
(Prim
));
7185 Iface_Typ
:= Find_Dispatching_Type
(Interface_Alias
(Prim
));
7187 pragma Assert
(Is_Interface
(Iface_Typ
));
7189 -- No action needed for interfaces that are ancestors of Typ because
7190 -- their primitives are located in the primary dispatch table.
7192 if Is_Ancestor
(Iface_Typ
, Tag_Typ
, Use_Full_View
=> True) then
7195 -- No action needed for primitives located in the C++ part of the
7196 -- dispatch table. Their slot is set by the IC routine.
7198 elsif Is_CPP_Class
(Root_Type
(Tag_Typ
))
7199 and then DT_Position
(Alias
(Prim
)) <= CPP_Num_Prims
(Tag_Typ
)
7200 and then not Is_Predefined_Dispatching_Operation
(Prim
)
7201 and then not Is_Predefined_Dispatching_Alias
(Prim
)
7206 Expand_Interface_Thunk
(Prim
, Thunk_Id
, Thunk_Code
);
7208 if not Is_Ancestor
(Iface_Typ
, Tag_Typ
, Use_Full_View
=> True)
7209 and then Present
(Thunk_Code
)
7211 -- Generate the code necessary to fill the appropriate entry of
7212 -- the secondary dispatch table of Prim's controlling type with
7213 -- Thunk_Id's address.
7215 Iface_DT_Elmt
:= Find_Interface_ADT
(Tag_Typ
, Iface_Typ
);
7216 Iface_DT_Ptr
:= Node
(Iface_DT_Elmt
);
7217 pragma Assert
(Has_Thunks
(Iface_DT_Ptr
));
7219 Iface_Prim
:= Interface_Alias
(Prim
);
7220 Pos
:= DT_Position
(Iface_Prim
);
7221 Tag
:= First_Tag_Component
(Iface_Typ
);
7223 Prepend_To
(L
, Thunk_Code
);
7225 if Is_Predefined_Dispatching_Operation
(Prim
)
7226 or else Is_Predefined_Dispatching_Alias
(Prim
)
7229 Build_Set_Predefined_Prim_Op_Address
(Loc
,
7231 New_Occurrence_Of
(Node
(Next_Elmt
(Iface_DT_Elmt
)), Loc
),
7234 Unchecked_Convert_To
(RTE
(RE_Prim_Ptr
),
7235 Make_Attribute_Reference
(Loc
,
7236 Prefix
=> New_Occurrence_Of
(Thunk_Id
, Loc
),
7237 Attribute_Name
=> Name_Unrestricted_Access
))));
7239 Next_Elmt
(Iface_DT_Elmt
);
7240 Next_Elmt
(Iface_DT_Elmt
);
7241 Iface_DT_Ptr
:= Node
(Iface_DT_Elmt
);
7242 pragma Assert
(not Has_Thunks
(Iface_DT_Ptr
));
7245 Build_Set_Predefined_Prim_Op_Address
(Loc
,
7247 New_Occurrence_Of
(Node
(Next_Elmt
(Iface_DT_Elmt
)), Loc
),
7250 Unchecked_Convert_To
(RTE
(RE_Prim_Ptr
),
7251 Make_Attribute_Reference
(Loc
,
7253 New_Occurrence_Of
(Alias
(Prim
), Loc
),
7254 Attribute_Name
=> Name_Unrestricted_Access
))));
7257 pragma Assert
(Pos
/= Uint_0
7258 and then Pos
<= DT_Entry_Count
(Tag
));
7261 Build_Set_Prim_Op_Address
(Loc
,
7263 Tag_Node
=> New_Occurrence_Of
(Iface_DT_Ptr
, Loc
),
7266 Unchecked_Convert_To
(RTE
(RE_Prim_Ptr
),
7267 Make_Attribute_Reference
(Loc
,
7268 Prefix
=> New_Occurrence_Of
(Thunk_Id
, Loc
),
7269 Attribute_Name
=> Name_Unrestricted_Access
))));
7271 Next_Elmt
(Iface_DT_Elmt
);
7272 Next_Elmt
(Iface_DT_Elmt
);
7273 Iface_DT_Ptr
:= Node
(Iface_DT_Elmt
);
7274 pragma Assert
(not Has_Thunks
(Iface_DT_Ptr
));
7277 Build_Set_Prim_Op_Address
(Loc
,
7279 Tag_Node
=> New_Occurrence_Of
(Iface_DT_Ptr
, Loc
),
7282 Unchecked_Convert_To
(RTE
(RE_Prim_Ptr
),
7283 Make_Attribute_Reference
(Loc
,
7285 New_Occurrence_Of
(Alias
(Prim
), Loc
),
7286 Attribute_Name
=> Name_Unrestricted_Access
))));
7293 end Register_Primitive
;
7295 -------------------------
7296 -- Set_All_DT_Position --
7297 -------------------------
7299 procedure Set_All_DT_Position
(Typ
: Entity_Id
) is
7301 function In_Predef_Prims_DT
(Prim
: Entity_Id
) return Boolean;
7302 -- Returns True if Prim is located in the dispatch table of
7303 -- predefined primitives
7305 procedure Validate_Position
(Prim
: Entity_Id
);
7306 -- Check that position assigned to Prim is completely safe (it has not
7307 -- been assigned to a previously defined primitive operation of Typ).
7309 ------------------------
7310 -- In_Predef_Prims_DT --
7311 ------------------------
7313 function In_Predef_Prims_DT
(Prim
: Entity_Id
) return Boolean is
7317 -- Predefined primitives
7319 if Is_Predefined_Dispatching_Operation
(Prim
) then
7322 -- Renamings of predefined primitives
7324 elsif Present
(Alias
(Prim
))
7325 and then Is_Predefined_Dispatching_Operation
(Ultimate_Alias
(Prim
))
7327 if Chars
(Ultimate_Alias
(Prim
)) /= Name_Op_Eq
then
7330 -- User-defined renamings of predefined equality have their own
7331 -- slot in the primary dispatch table
7335 while Present
(Alias
(E
)) loop
7336 if Comes_From_Source
(E
) then
7343 return not Comes_From_Source
(E
);
7346 -- User-defined primitives
7351 end In_Predef_Prims_DT
;
7353 -----------------------
7354 -- Validate_Position --
7355 -----------------------
7357 procedure Validate_Position
(Prim
: Entity_Id
) is
7362 -- Aliased primitives are safe
7364 if Present
(Alias
(Prim
)) then
7368 Op_Elmt
:= First_Elmt
(Primitive_Operations
(Typ
));
7369 while Present
(Op_Elmt
) loop
7370 Op
:= Node
(Op_Elmt
);
7372 -- No need to check against itself
7377 -- Primitive operations covering abstract interfaces are
7380 elsif Present
(Interface_Alias
(Op
)) then
7383 -- Predefined dispatching operations are completely safe. They
7384 -- are allocated at fixed positions in a separate table.
7386 elsif Is_Predefined_Dispatching_Operation
(Op
)
7387 or else Is_Predefined_Dispatching_Alias
(Op
)
7391 -- Aliased subprograms are safe
7393 elsif Present
(Alias
(Op
)) then
7396 elsif DT_Position
(Op
) = DT_Position
(Prim
)
7397 and then not Is_Predefined_Dispatching_Operation
(Op
)
7398 and then not Is_Predefined_Dispatching_Operation
(Prim
)
7399 and then not Is_Predefined_Dispatching_Alias
(Op
)
7400 and then not Is_Predefined_Dispatching_Alias
(Prim
)
7402 -- Handle aliased subprograms
7411 if Present
(Overridden_Operation
(Op_1
)) then
7412 Op_1
:= Overridden_Operation
(Op_1
);
7413 elsif Present
(Alias
(Op_1
)) then
7414 Op_1
:= Alias
(Op_1
);
7422 if Present
(Overridden_Operation
(Op_2
)) then
7423 Op_2
:= Overridden_Operation
(Op_2
);
7424 elsif Present
(Alias
(Op_2
)) then
7425 Op_2
:= Alias
(Op_2
);
7431 if Op_1
/= Op_2
then
7432 raise Program_Error
;
7437 Next_Elmt
(Op_Elmt
);
7439 end Validate_Position
;
7443 Parent_Typ
: constant Entity_Id
:= Etype
(Typ
);
7444 First_Prim
: constant Elmt_Id
:= First_Elmt
(Primitive_Operations
(Typ
));
7445 The_Tag
: constant Entity_Id
:= First_Tag_Component
(Typ
);
7447 Adjusted
: Boolean := False;
7448 Finalized
: Boolean := False;
7454 Prim_Elmt
: Elmt_Id
;
7456 -- Start of processing for Set_All_DT_Position
7459 pragma Assert
(Present
(First_Tag_Component
(Typ
)));
7461 -- Set the DT_Position for each primitive operation. Perform some sanity
7462 -- checks to avoid building inconsistent dispatch tables.
7464 -- First stage: Set DTC entity of all the primitive operations. This is
7465 -- required to properly read the DT_Position attribute in latter stages.
7467 Prim_Elmt
:= First_Prim
;
7469 while Present
(Prim_Elmt
) loop
7470 Prim
:= Node
(Prim_Elmt
);
7472 -- Predefined primitives have a separate dispatch table
7474 if not In_Predef_Prims_DT
(Prim
) then
7475 Count_Prim
:= Count_Prim
+ 1;
7478 Set_DTC_Entity_Value
(Typ
, Prim
);
7480 -- Clear any previous value of the DT_Position attribute. In this
7481 -- way we ensure that the final position of all the primitives is
7482 -- established by the following stages of this algorithm.
7484 Set_DT_Position_Value
(Prim
, No_Uint
);
7486 Next_Elmt
(Prim_Elmt
);
7490 Fixed_Prim
: array (Int
range 0 .. Count_Prim
) of Boolean :=
7495 procedure Handle_Inherited_Private_Subprograms
(Typ
: Entity_Id
);
7496 -- Called if Typ is declared in a nested package or a public child
7497 -- package to handle inherited primitives that were inherited by Typ
7498 -- in the visible part, but whose declaration was deferred because
7499 -- the parent operation was private and not visible at that point.
7501 procedure Set_Fixed_Prim
(Pos
: Nat
);
7502 -- Sets to true an element of the Fixed_Prim table to indicate
7503 -- that this entry of the dispatch table of Typ is occupied.
7505 ------------------------------------------
7506 -- Handle_Inherited_Private_Subprograms --
7507 ------------------------------------------
7509 procedure Handle_Inherited_Private_Subprograms
(Typ
: Entity_Id
) is
7512 Op_Elmt_2
: Elmt_Id
;
7513 Prim_Op
: Entity_Id
;
7514 Parent_Subp
: Entity_Id
;
7517 Op_List
:= Primitive_Operations
(Typ
);
7519 Op_Elmt
:= First_Elmt
(Op_List
);
7520 while Present
(Op_Elmt
) loop
7521 Prim_Op
:= Node
(Op_Elmt
);
7523 -- Search primitives that are implicit operations with an
7524 -- internal name whose parent operation has a normal name.
7526 if Present
(Alias
(Prim_Op
))
7527 and then Find_Dispatching_Type
(Alias
(Prim_Op
)) /= Typ
7528 and then not Comes_From_Source
(Prim_Op
)
7529 and then Is_Internal_Name
(Chars
(Prim_Op
))
7530 and then not Is_Internal_Name
(Chars
(Alias
(Prim_Op
)))
7532 Parent_Subp
:= Alias
(Prim_Op
);
7534 -- Check if the type has an explicit overriding for this
7537 Op_Elmt_2
:= Next_Elmt
(Op_Elmt
);
7538 while Present
(Op_Elmt_2
) loop
7539 if Chars
(Node
(Op_Elmt_2
)) = Chars
(Parent_Subp
)
7540 and then Type_Conformant
(Prim_Op
, Node
(Op_Elmt_2
))
7542 Set_DT_Position_Value
(Prim_Op
,
7543 DT_Position
(Parent_Subp
));
7544 Set_DT_Position_Value
(Node
(Op_Elmt_2
),
7545 DT_Position
(Parent_Subp
));
7546 Set_Fixed_Prim
(UI_To_Int
(DT_Position
(Prim_Op
)));
7548 goto Next_Primitive
;
7551 Next_Elmt
(Op_Elmt_2
);
7556 Next_Elmt
(Op_Elmt
);
7558 end Handle_Inherited_Private_Subprograms
;
7560 --------------------
7561 -- Set_Fixed_Prim --
7562 --------------------
7564 procedure Set_Fixed_Prim
(Pos
: Nat
) is
7566 pragma Assert
(Pos
<= Count_Prim
);
7567 Fixed_Prim
(Pos
) := True;
7569 when Constraint_Error
=>
7570 raise Program_Error
;
7574 -- In case of nested packages and public child package it may be
7575 -- necessary a special management on inherited subprograms so that
7576 -- the dispatch table is properly filled.
7578 if Ekind
(Scope
(Scope
(Typ
))) = E_Package
7579 and then Scope
(Scope
(Typ
)) /= Standard_Standard
7580 and then ((Is_Derived_Type
(Typ
) and then not Is_Private_Type
(Typ
))
7582 (Nkind
(Parent
(Typ
)) = N_Private_Extension_Declaration
7583 and then Is_Generic_Type
(Typ
)))
7584 and then In_Open_Scopes
(Scope
(Etype
(Typ
)))
7585 and then Is_Base_Type
(Typ
)
7587 Handle_Inherited_Private_Subprograms
(Typ
);
7590 -- Second stage: Register fixed entries
7593 Prim_Elmt
:= First_Prim
;
7594 while Present
(Prim_Elmt
) loop
7595 Prim
:= Node
(Prim_Elmt
);
7597 -- Predefined primitives have a separate table and all its
7598 -- entries are at predefined fixed positions.
7600 if In_Predef_Prims_DT
(Prim
) then
7601 if Is_Predefined_Dispatching_Operation
(Prim
) then
7602 Set_DT_Position_Value
(Prim
,
7603 Default_Prim_Op_Position
(Prim
));
7605 else pragma Assert
(Present
(Alias
(Prim
)));
7606 Set_DT_Position_Value
(Prim
,
7607 Default_Prim_Op_Position
(Ultimate_Alias
(Prim
)));
7610 -- Overriding primitives of ancestor abstract interfaces
7612 elsif Present
(Interface_Alias
(Prim
))
7613 and then Is_Ancestor
7614 (Find_Dispatching_Type
(Interface_Alias
(Prim
)), Typ
,
7615 Use_Full_View
=> True)
7617 pragma Assert
(DT_Position
(Prim
) = No_Uint
7618 and then Present
(DTC_Entity
(Interface_Alias
(Prim
))));
7620 E
:= Interface_Alias
(Prim
);
7621 Set_DT_Position_Value
(Prim
, DT_Position
(E
));
7624 (DT_Position
(Alias
(Prim
)) = No_Uint
7625 or else DT_Position
(Alias
(Prim
)) = DT_Position
(E
));
7626 Set_DT_Position_Value
(Alias
(Prim
), DT_Position
(E
));
7627 Set_Fixed_Prim
(UI_To_Int
(DT_Position
(Prim
)));
7629 -- Overriding primitives must use the same entry as the
7630 -- overridden primitive.
7632 elsif not Present
(Interface_Alias
(Prim
))
7633 and then Present
(Alias
(Prim
))
7634 and then Chars
(Prim
) = Chars
(Alias
(Prim
))
7635 and then Find_Dispatching_Type
(Alias
(Prim
)) /= Typ
7636 and then Is_Ancestor
7637 (Find_Dispatching_Type
(Alias
(Prim
)), Typ
,
7638 Use_Full_View
=> True)
7639 and then Present
(DTC_Entity
(Alias
(Prim
)))
7642 Set_DT_Position_Value
(Prim
, DT_Position
(E
));
7644 if not Is_Predefined_Dispatching_Alias
(E
) then
7645 Set_Fixed_Prim
(UI_To_Int
(DT_Position
(E
)));
7649 Next_Elmt
(Prim_Elmt
);
7652 -- Third stage: Fix the position of all the new primitives. Entries
7653 -- associated with primitives covering interfaces are handled in a
7656 Prim_Elmt
:= First_Prim
;
7657 while Present
(Prim_Elmt
) loop
7658 Prim
:= Node
(Prim_Elmt
);
7660 -- Skip primitives previously set entries
7662 if DT_Position
(Prim
) /= No_Uint
then
7665 -- Primitives covering interface primitives are handled later
7667 elsif Present
(Interface_Alias
(Prim
)) then
7671 -- Take the next available position in the DT
7674 Nb_Prim
:= Nb_Prim
+ 1;
7675 pragma Assert
(Nb_Prim
<= Count_Prim
);
7676 exit when not Fixed_Prim
(Nb_Prim
);
7679 Set_DT_Position_Value
(Prim
, UI_From_Int
(Nb_Prim
));
7680 Set_Fixed_Prim
(Nb_Prim
);
7683 Next_Elmt
(Prim_Elmt
);
7687 -- Fourth stage: Complete the decoration of primitives covering
7688 -- interfaces (that is, propagate the DT_Position attribute from
7689 -- the aliased primitive)
7691 Prim_Elmt
:= First_Prim
;
7692 while Present
(Prim_Elmt
) loop
7693 Prim
:= Node
(Prim_Elmt
);
7695 if DT_Position
(Prim
) = No_Uint
7696 and then Present
(Interface_Alias
(Prim
))
7698 pragma Assert
(Present
(Alias
(Prim
))
7699 and then Find_Dispatching_Type
(Alias
(Prim
)) = Typ
);
7701 -- Check if this entry will be placed in the primary DT
7704 (Find_Dispatching_Type
(Interface_Alias
(Prim
)), Typ
,
7705 Use_Full_View
=> True)
7707 pragma Assert
(DT_Position
(Alias
(Prim
)) /= No_Uint
);
7708 Set_DT_Position_Value
(Prim
, DT_Position
(Alias
(Prim
)));
7710 -- Otherwise it will be placed in the secondary DT
7714 (DT_Position
(Interface_Alias
(Prim
)) /= No_Uint
);
7715 Set_DT_Position_Value
(Prim
,
7716 DT_Position
(Interface_Alias
(Prim
)));
7720 Next_Elmt
(Prim_Elmt
);
7723 -- Generate listing showing the contents of the dispatch tables. This
7724 -- action is done before some further static checks because in case of
7725 -- critical errors caused by a wrong dispatch table we need to see the
7726 -- contents of such table.
7728 if Debug_Flag_ZZ
then
7732 -- Final stage: Ensure that the table is correct plus some further
7733 -- verifications concerning the primitives.
7735 Prim_Elmt
:= First_Prim
;
7737 while Present
(Prim_Elmt
) loop
7738 Prim
:= Node
(Prim_Elmt
);
7740 -- At this point all the primitives MUST have a position in the
7743 if DT_Position
(Prim
) = No_Uint
then
7744 raise Program_Error
;
7747 -- Calculate real size of the dispatch table
7749 if not In_Predef_Prims_DT
(Prim
)
7750 and then UI_To_Int
(DT_Position
(Prim
)) > DT_Length
7752 DT_Length
:= UI_To_Int
(DT_Position
(Prim
));
7755 -- Ensure that the assigned position to non-predefined dispatching
7756 -- operations in the dispatch table is correct.
7758 if not Is_Predefined_Dispatching_Operation
(Prim
)
7759 and then not Is_Predefined_Dispatching_Alias
(Prim
)
7761 Validate_Position
(Prim
);
7764 if Chars
(Prim
) = Name_Finalize
then
7768 if Chars
(Prim
) = Name_Adjust
then
7772 -- An abstract operation cannot be declared in the private part for a
7773 -- visible abstract type, because it can't be overridden outside this
7774 -- package hierarchy. For explicit declarations this is checked at
7775 -- the point of declaration, but for inherited operations it must be
7776 -- done when building the dispatch table.
7778 -- Ada 2005 (AI-251): Primitives associated with interfaces are
7779 -- excluded from this check because interfaces must be visible in
7780 -- the public and private part (RM 7.3 (7.3/2))
7782 -- We disable this check in Relaxed_RM_Semantics mode, to accommodate
7785 if not Relaxed_RM_Semantics
7786 and then Is_Abstract_Type
(Typ
)
7787 and then Is_Abstract_Subprogram
(Prim
)
7788 and then Present
(Alias
(Prim
))
7789 and then not Is_Interface
7790 (Find_Dispatching_Type
(Ultimate_Alias
(Prim
)))
7791 and then not Present
(Interface_Alias
(Prim
))
7792 and then Is_Derived_Type
(Typ
)
7793 and then In_Private_Part
(Current_Scope
)
7795 List_Containing
(Parent
(Prim
)) =
7796 Private_Declarations
(Package_Specification
(Current_Scope
))
7797 and then Original_View_In_Visible_Part
(Typ
)
7799 -- We exclude Input and Output stream operations because
7800 -- Limited_Controlled inherits useless Input and Output stream
7801 -- operations from Root_Controlled, which can never be overridden.
7803 if not Is_TSS
(Prim
, TSS_Stream_Input
)
7805 not Is_TSS
(Prim
, TSS_Stream_Output
)
7808 ("abstract inherited private operation&" &
7809 " must be overridden (RM 3.9.3(10))",
7810 Parent
(Typ
), Prim
);
7814 Next_Elmt
(Prim_Elmt
);
7819 if Is_Controlled
(Typ
) then
7820 if not Finalized
then
7822 ("controlled type has no explicit Finalize method??", Typ
);
7824 elsif not Adjusted
then
7826 ("controlled type has no explicit Adjust method??", Typ
);
7830 -- Set the final size of the Dispatch Table
7832 Set_DT_Entry_Count
(The_Tag
, UI_From_Int
(DT_Length
));
7834 -- The derived type must have at least as many components as its parent
7835 -- (for root types Etype points to itself and the test cannot fail).
7837 if DT_Entry_Count
(The_Tag
) <
7838 DT_Entry_Count
(First_Tag_Component
(Parent_Typ
))
7840 raise Program_Error
;
7842 end Set_All_DT_Position
;
7844 --------------------------
7845 -- Set_CPP_Constructors --
7846 --------------------------
7848 procedure Set_CPP_Constructors
(Typ
: Entity_Id
) is
7850 function Gen_Parameters_Profile
(E
: Entity_Id
) return List_Id
;
7851 -- Duplicate the parameters profile of the imported C++ constructor
7852 -- adding an access to the object as an additional parameter.
7854 ----------------------------
7855 -- Gen_Parameters_Profile --
7856 ----------------------------
7858 function Gen_Parameters_Profile
(E
: Entity_Id
) return List_Id
is
7859 Loc
: constant Source_Ptr
:= Sloc
(E
);
7866 Make_Parameter_Specification
(Loc
,
7867 Defining_Identifier
=>
7868 Make_Defining_Identifier
(Loc
, Name_uInit
),
7869 Parameter_Type
=> New_Occurrence_Of
(Typ
, Loc
)));
7871 if Present
(Parameter_Specifications
(Parent
(E
))) then
7872 P
:= First
(Parameter_Specifications
(Parent
(E
)));
7873 while Present
(P
) loop
7875 Make_Parameter_Specification
(Loc
,
7876 Defining_Identifier
=>
7877 Make_Defining_Identifier
(Loc
,
7878 Chars
=> Chars
(Defining_Identifier
(P
))),
7879 Parameter_Type
=> New_Copy_Tree
(Parameter_Type
(P
)),
7880 Expression
=> New_Copy_Tree
(Expression
(P
))));
7886 end Gen_Parameters_Profile
;
7892 Found
: Boolean := False;
7898 Covers_Default_Constructor
: Entity_Id
:= Empty
;
7900 -- Start of processing for Set_CPP_Constructor
7903 pragma Assert
(Is_CPP_Class
(Typ
));
7905 -- Look for the constructor entities
7907 E
:= Next_Entity
(Typ
);
7908 while Present
(E
) loop
7909 if Ekind
(E
) = E_Function
7910 and then Is_Constructor
(E
)
7914 Parms
:= Gen_Parameters_Profile
(E
);
7916 Make_Defining_Identifier
(Loc
,
7917 Chars
=> Make_Init_Proc_Name
(Typ
));
7919 -- Case 1: Constructor of untagged type
7921 -- If the C++ class has no virtual methods then the matching Ada
7922 -- type is an untagged record type. In such case there is no need
7923 -- to generate a wrapper of the C++ constructor because the _tag
7924 -- component is not available.
7926 if not Is_Tagged_Type
(Typ
) then
7928 (Make_Subprogram_Declaration
(Loc
,
7930 Make_Procedure_Specification
(Loc
,
7931 Defining_Unit_Name
=> IP
,
7932 Parameter_Specifications
=> Parms
)));
7934 Set_Init_Proc
(Typ
, IP
);
7935 Set_Is_Imported
(IP
);
7936 Set_Is_Constructor
(IP
);
7937 Set_Interface_Name
(IP
, Interface_Name
(E
));
7938 Set_Convention
(IP
, Convention_CPP
);
7940 Set_Has_Completion
(IP
);
7942 -- Case 2: Constructor of a tagged type
7944 -- In this case we generate the IP as a wrapper of the the
7945 -- C++ constructor because IP must also save copy of the _tag
7946 -- generated in the C++ side. The copy of the _tag is used by
7947 -- Build_CPP_Init_Procedure to elaborate derivations of C++ types.
7950 -- procedure IP (_init : Typ; ...) is
7951 -- procedure ConstructorP (_init : Typ; ...);
7952 -- pragma Import (ConstructorP);
7954 -- ConstructorP (_init, ...);
7955 -- if Typ._tag = null then
7956 -- Typ._tag := _init._tag;
7962 Body_Stmts
: constant List_Id
:= New_List
;
7963 Constructor_Id
: Entity_Id
;
7964 Constructor_Decl_Node
: Node_Id
;
7965 Init_Tags_List
: List_Id
;
7968 Constructor_Id
:= Make_Temporary
(Loc
, 'P');
7970 Constructor_Decl_Node
:=
7971 Make_Subprogram_Declaration
(Loc
,
7972 Make_Procedure_Specification
(Loc
,
7973 Defining_Unit_Name
=> Constructor_Id
,
7974 Parameter_Specifications
=> Parms
));
7976 Set_Is_Imported
(Constructor_Id
);
7977 Set_Is_Constructor
(Constructor_Id
);
7978 Set_Interface_Name
(Constructor_Id
, Interface_Name
(E
));
7979 Set_Convention
(Constructor_Id
, Convention_CPP
);
7980 Set_Is_Public
(Constructor_Id
);
7981 Set_Has_Completion
(Constructor_Id
);
7983 -- Build the init procedure as a wrapper of this constructor
7985 Parms
:= Gen_Parameters_Profile
(E
);
7987 -- Invoke the C++ constructor
7990 Actuals
: constant List_Id
:= New_List
;
7994 while Present
(P
) loop
7996 New_Occurrence_Of
(Defining_Identifier
(P
), Loc
));
8000 Append_To
(Body_Stmts
,
8001 Make_Procedure_Call_Statement
(Loc
,
8002 Name
=> New_Occurrence_Of
(Constructor_Id
, Loc
),
8003 Parameter_Associations
=> Actuals
));
8006 -- Initialize copies of C++ primary and secondary tags
8008 Init_Tags_List
:= New_List
;
8015 Tag_Elmt
:= First_Elmt
(Access_Disp_Table
(Typ
));
8016 Tag_Comp
:= First_Tag_Component
(Typ
);
8018 while Present
(Tag_Elmt
)
8019 and then Is_Tag
(Node
(Tag_Elmt
))
8021 -- Skip the following assertion with primary tags
8022 -- because Related_Type is not set on primary tag
8026 (Tag_Comp
= First_Tag_Component
(Typ
)
8027 or else Related_Type
(Node
(Tag_Elmt
))
8028 = Related_Type
(Tag_Comp
));
8030 Append_To
(Init_Tags_List
,
8031 Make_Assignment_Statement
(Loc
,
8033 New_Occurrence_Of
(Node
(Tag_Elmt
), Loc
),
8035 Make_Selected_Component
(Loc
,
8037 Make_Identifier
(Loc
, Name_uInit
),
8039 New_Occurrence_Of
(Tag_Comp
, Loc
))));
8041 Tag_Comp
:= Next_Tag_Component
(Tag_Comp
);
8042 Next_Elmt
(Tag_Elmt
);
8046 Append_To
(Body_Stmts
,
8047 Make_If_Statement
(Loc
,
8052 (Node
(First_Elmt
(Access_Disp_Table
(Typ
))),
8055 Unchecked_Convert_To
(RTE
(RE_Tag
),
8056 New_Occurrence_Of
(RTE
(RE_Null_Address
), Loc
))),
8057 Then_Statements
=> Init_Tags_List
));
8060 Make_Subprogram_Body
(Loc
,
8062 Make_Procedure_Specification
(Loc
,
8063 Defining_Unit_Name
=> IP
,
8064 Parameter_Specifications
=> Parms
),
8065 Declarations
=> New_List
(Constructor_Decl_Node
),
8066 Handled_Statement_Sequence
=>
8067 Make_Handled_Sequence_Of_Statements
(Loc
,
8068 Statements
=> Body_Stmts
,
8069 Exception_Handlers
=> No_List
));
8071 Discard_Node
(IP_Body
);
8072 Set_Init_Proc
(Typ
, IP
);
8076 -- If this constructor has parameters and all its parameters have
8077 -- defaults then it covers the default constructor. The semantic
8078 -- analyzer ensures that only one constructor with defaults covers
8079 -- the default constructor.
8081 if Present
(Parameter_Specifications
(Parent
(E
)))
8082 and then Needs_No_Actuals
(E
)
8084 Covers_Default_Constructor
:= IP
;
8091 -- If there are no constructors, mark the type as abstract since we
8092 -- won't be able to declare objects of that type.
8095 Set_Is_Abstract_Type
(Typ
);
8098 -- Handle constructor that has all its parameters with defaults and
8099 -- hence it covers the default constructor. We generate a wrapper IP
8100 -- which calls the covering constructor.
8102 if Present
(Covers_Default_Constructor
) then
8104 Body_Stmts
: List_Id
;
8107 Loc
:= Sloc
(Covers_Default_Constructor
);
8109 Body_Stmts
:= New_List
(
8110 Make_Procedure_Call_Statement
(Loc
,
8112 New_Occurrence_Of
(Covers_Default_Constructor
, Loc
),
8113 Parameter_Associations
=> New_List
(
8114 Make_Identifier
(Loc
, Name_uInit
))));
8116 IP
:= Make_Defining_Identifier
(Loc
, Make_Init_Proc_Name
(Typ
));
8119 Make_Subprogram_Body
(Loc
,
8121 Make_Procedure_Specification
(Loc
,
8122 Defining_Unit_Name
=> IP
,
8123 Parameter_Specifications
=> New_List
(
8124 Make_Parameter_Specification
(Loc
,
8125 Defining_Identifier
=>
8126 Make_Defining_Identifier
(Loc
, Name_uInit
),
8127 Parameter_Type
=> New_Occurrence_Of
(Typ
, Loc
)))),
8129 Declarations
=> No_List
,
8131 Handled_Statement_Sequence
=>
8132 Make_Handled_Sequence_Of_Statements
(Loc
,
8133 Statements
=> Body_Stmts
,
8134 Exception_Handlers
=> No_List
));
8136 Discard_Node
(IP_Body
);
8137 Set_Init_Proc
(Typ
, IP
);
8141 -- If the CPP type has constructors then it must import also the default
8142 -- C++ constructor. It is required for default initialization of objects
8143 -- of the type. It is also required to elaborate objects of Ada types
8144 -- that are defined as derivations of this CPP type.
8146 if Has_CPP_Constructors
(Typ
)
8147 and then No
(Init_Proc
(Typ
))
8149 Error_Msg_N
("??default constructor must be imported from C++", Typ
);
8151 end Set_CPP_Constructors
;
8153 ---------------------------
8154 -- Set_DT_Position_Value --
8155 ---------------------------
8157 procedure Set_DT_Position_Value
(Prim
: Entity_Id
; Value
: Uint
) is
8159 Set_DT_Position
(Prim
, Value
);
8161 -- Propagate the value to the wrapped subprogram (if one is present)
8163 if Ekind_In
(Prim
, E_Function
, E_Procedure
)
8164 and then Is_Primitive_Wrapper
(Prim
)
8165 and then Present
(Wrapped_Entity
(Prim
))
8166 and then Is_Dispatching_Operation
(Wrapped_Entity
(Prim
))
8168 Set_DT_Position
(Wrapped_Entity
(Prim
), Value
);
8170 end Set_DT_Position_Value
;
8172 --------------------------
8173 -- Set_DTC_Entity_Value --
8174 --------------------------
8176 procedure Set_DTC_Entity_Value
8177 (Tagged_Type
: Entity_Id
;
8181 if Present
(Interface_Alias
(Prim
))
8182 and then Is_Interface
8183 (Find_Dispatching_Type
(Interface_Alias
(Prim
)))
8185 Set_DTC_Entity
(Prim
,
8188 Iface
=> Find_Dispatching_Type
(Interface_Alias
(Prim
))));
8190 Set_DTC_Entity
(Prim
,
8191 First_Tag_Component
(Tagged_Type
));
8194 -- Propagate the value to the wrapped subprogram (if one is present)
8196 if Ekind_In
(Prim
, E_Function
, E_Procedure
)
8197 and then Is_Primitive_Wrapper
(Prim
)
8198 and then Present
(Wrapped_Entity
(Prim
))
8199 and then Is_Dispatching_Operation
(Wrapped_Entity
(Prim
))
8201 Set_DTC_Entity
(Wrapped_Entity
(Prim
), DTC_Entity
(Prim
));
8203 end Set_DTC_Entity_Value
;
8209 function Tagged_Kind
(T
: Entity_Id
) return Node_Id
is
8210 Conc_Typ
: Entity_Id
;
8211 Loc
: constant Source_Ptr
:= Sloc
(T
);
8215 (Is_Tagged_Type
(T
) and then RTE_Available
(RE_Tagged_Kind
));
8219 if Is_Abstract_Type
(T
) then
8220 if Is_Limited_Record
(T
) then
8221 return New_Occurrence_Of
8222 (RTE
(RE_TK_Abstract_Limited_Tagged
), Loc
);
8224 return New_Occurrence_Of
8225 (RTE
(RE_TK_Abstract_Tagged
), Loc
);
8230 elsif Is_Concurrent_Record_Type
(T
) then
8231 Conc_Typ
:= Corresponding_Concurrent_Type
(T
);
8233 if Present
(Full_View
(Conc_Typ
)) then
8234 Conc_Typ
:= Full_View
(Conc_Typ
);
8237 if Ekind
(Conc_Typ
) = E_Protected_Type
then
8238 return New_Occurrence_Of
(RTE
(RE_TK_Protected
), Loc
);
8240 pragma Assert
(Ekind
(Conc_Typ
) = E_Task_Type
);
8241 return New_Occurrence_Of
(RTE
(RE_TK_Task
), Loc
);
8244 -- Regular tagged kinds
8247 if Is_Limited_Record
(T
) then
8248 return New_Occurrence_Of
(RTE
(RE_TK_Limited_Tagged
), Loc
);
8250 return New_Occurrence_Of
(RTE
(RE_TK_Tagged
), Loc
);
8259 procedure Write_DT
(Typ
: Entity_Id
) is
8264 -- Protect this procedure against wrong usage. Required because it will
8265 -- be used directly from GDB
8267 if not (Typ
<= Last_Node_Id
)
8268 or else not Is_Tagged_Type
(Typ
)
8270 Write_Str
("wrong usage: Write_DT must be used with tagged types");
8275 Write_Int
(Int
(Typ
));
8277 Write_Name
(Chars
(Typ
));
8279 if Is_Interface
(Typ
) then
8280 Write_Str
(" is interface");
8285 Elmt
:= First_Elmt
(Primitive_Operations
(Typ
));
8286 while Present
(Elmt
) loop
8287 Prim
:= Node
(Elmt
);
8290 -- Indicate if this primitive will be allocated in the primary
8291 -- dispatch table or in a secondary dispatch table associated
8292 -- with an abstract interface type
8294 if Present
(DTC_Entity
(Prim
)) then
8295 if Etype
(DTC_Entity
(Prim
)) = RTE
(RE_Tag
) then
8302 -- Output the node of this primitive operation and its name
8304 Write_Int
(Int
(Prim
));
8307 if Is_Predefined_Dispatching_Operation
(Prim
) then
8308 Write_Str
("(predefined) ");
8311 -- Prefix the name of the primitive with its corresponding tagged
8312 -- type to facilitate seeing inherited primitives.
8314 if Present
(Alias
(Prim
)) then
8316 (Chars
(Find_Dispatching_Type
(Ultimate_Alias
(Prim
))));
8318 Write_Name
(Chars
(Typ
));
8322 Write_Name
(Chars
(Prim
));
8324 -- Indicate if this primitive has an aliased primitive
8326 if Present
(Alias
(Prim
)) then
8327 Write_Str
(" (alias = ");
8328 Write_Int
(Int
(Alias
(Prim
)));
8330 -- If the DTC_Entity attribute is already set we can also output
8331 -- the name of the interface covered by this primitive (if any).
8333 if Ekind_In
(Alias
(Prim
), E_Function
, E_Procedure
)
8334 and then Present
(DTC_Entity
(Alias
(Prim
)))
8335 and then Is_Interface
(Scope
(DTC_Entity
(Alias
(Prim
))))
8337 Write_Str
(" from interface ");
8338 Write_Name
(Chars
(Scope
(DTC_Entity
(Alias
(Prim
)))));
8341 if Present
(Interface_Alias
(Prim
)) then
8342 Write_Str
(", AI_Alias of ");
8344 if Is_Null_Interface_Primitive
(Interface_Alias
(Prim
)) then
8345 Write_Str
("null primitive ");
8349 (Chars
(Find_Dispatching_Type
(Interface_Alias
(Prim
))));
8351 Write_Int
(Int
(Interface_Alias
(Prim
)));
8357 -- Display the final position of this primitive in its associated
8358 -- (primary or secondary) dispatch table.
8360 if Present
(DTC_Entity
(Prim
))
8361 and then DT_Position
(Prim
) /= No_Uint
8363 Write_Str
(" at #");
8364 Write_Int
(UI_To_Int
(DT_Position
(Prim
)));
8367 if Is_Abstract_Subprogram
(Prim
) then
8368 Write_Str
(" is abstract;");
8370 -- Check if this is a null primitive
8372 elsif Comes_From_Source
(Prim
)
8373 and then Ekind
(Prim
) = E_Procedure
8374 and then Null_Present
(Parent
(Prim
))
8376 Write_Str
(" is null;");
8379 if Is_Eliminated
(Ultimate_Alias
(Prim
)) then
8380 Write_Str
(" (eliminated)");
8383 if Is_Imported
(Prim
)
8384 and then Convention
(Prim
) = Convention_CPP
8386 Write_Str
(" (C++)");