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 function Make_DT
(Typ
: Entity_Id
; N
: Node_Id
:= Empty
) return List_Id
is
3617 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
3619 Max_Predef_Prims
: constant Int
:=
3623 (Parent
(RTE
(RE_Max_Predef_Prims
)))));
3625 DT_Decl
: constant Elist_Id
:= New_Elmt_List
;
3626 DT_Aggr
: constant Elist_Id
:= New_Elmt_List
;
3627 -- Entities marked with attribute Is_Dispatch_Table_Entity
3629 procedure Check_Premature_Freezing
3631 Tagged_Type
: Entity_Id
;
3633 -- Verify that all untagged types in the profile of a subprogram are
3634 -- frozen at the point the subprogram is frozen. This enforces the rule
3635 -- on RM 13.14 (14) as modified by AI05-019. At the point a subprogram
3636 -- is frozen, enough must be known about it to build the activation
3637 -- record for it, which requires at least that the size of all
3638 -- parameters be known. Controlling arguments are by-reference,
3639 -- and therefore the rule only applies to untagged types. Typical
3640 -- violation of the rule involves an object declaration that freezes a
3641 -- tagged type, when one of its primitive operations has a type in its
3642 -- profile whose full view has not been analyzed yet. More complex cases
3643 -- involve composite types that have one private unfrozen subcomponent.
3645 procedure Export_DT
(Typ
: Entity_Id
; DT
: Entity_Id
; Index
: Nat
:= 0);
3646 -- Export the dispatch table DT of tagged type Typ. Required to generate
3647 -- forward references and statically allocate the table. For primary
3648 -- dispatch tables Index is 0; for secondary dispatch tables the value
3649 -- of index must match the Suffix_Index value assigned to the table by
3650 -- Make_Tags when generating its unique external name, and it is used to
3651 -- retrieve from the Dispatch_Table_Wrappers list associated with Typ
3652 -- the external name generated by Import_DT.
3654 procedure Make_Secondary_DT
3658 Num_Iface_Prims
: Nat
;
3659 Iface_DT_Ptr
: Entity_Id
;
3660 Predef_Prims_Ptr
: Entity_Id
;
3661 Build_Thunks
: Boolean;
3663 -- Ada 2005 (AI-251): Expand the declarations for a Secondary Dispatch
3664 -- Table of Typ associated with Iface. Each abstract interface of Typ
3665 -- has two secondary dispatch tables: one containing pointers to thunks
3666 -- and another containing pointers to the primitives covering the
3667 -- interface primitives. The former secondary table is generated when
3668 -- Build_Thunks is True, and provides common support for dispatching
3669 -- calls through interface types; the latter secondary table is
3670 -- generated when Build_Thunks is False, and provides support for
3671 -- Generic Dispatching Constructors that dispatch calls through
3672 -- interface types. When constructing this latter table the value of
3673 -- Suffix_Index is -1 to indicate that there is no need to export such
3674 -- table when building statically allocated dispatch tables; a positive
3675 -- value of Suffix_Index must match the Suffix_Index value assigned to
3676 -- this secondary dispatch table by Make_Tags when its unique external
3677 -- name was generated.
3679 ------------------------------
3680 -- Check_Premature_Freezing --
3681 ------------------------------
3683 procedure Check_Premature_Freezing
3685 Tagged_Type
: Entity_Id
;
3690 function Is_Actual_For_Formal_Incomplete_Type
3691 (T
: Entity_Id
) return Boolean;
3692 -- In Ada 2012, if a nested generic has an incomplete formal type,
3693 -- the actual may be (and usually is) a private type whose completion
3694 -- appears later. It is safe to build the dispatch table in this
3695 -- case, gigi will have full views available.
3697 ------------------------------------------
3698 -- Is_Actual_For_Formal_Incomplete_Type --
3699 ------------------------------------------
3701 function Is_Actual_For_Formal_Incomplete_Type
3702 (T
: Entity_Id
) return Boolean
3704 Gen_Par
: Entity_Id
;
3708 if not Is_Generic_Instance
(Current_Scope
)
3709 or else not Used_As_Generic_Actual
(T
)
3713 Gen_Par
:= Generic_Parent
(Parent
(Current_Scope
));
3718 (Generic_Formal_Declarations
3719 (Unit_Declaration_Node
(Gen_Par
)));
3720 while Present
(F
) loop
3721 if Ekind
(Defining_Identifier
(F
)) = E_Incomplete_Type
then
3729 end Is_Actual_For_Formal_Incomplete_Type
;
3731 -- Start of processing for Check_Premature_Freezing
3734 -- Note that if the type is a (subtype of) a generic actual, the
3735 -- actual will have been frozen by the instantiation.
3738 and then Is_Private_Type
(Typ
)
3739 and then No
(Full_View
(Typ
))
3740 and then not Is_Generic_Type
(Typ
)
3741 and then not Is_Tagged_Type
(Typ
)
3742 and then not Is_Frozen
(Typ
)
3743 and then not Is_Generic_Actual_Type
(Typ
)
3745 Error_Msg_Sloc
:= Sloc
(Subp
);
3747 ("declaration must appear after completion of type &", N
, Typ
);
3749 ("\which is an untagged type in the profile of "
3750 & "primitive operation & declared#", N
, Subp
);
3753 Comp
:= Private_Component
(Typ
);
3755 if not Is_Tagged_Type
(Typ
)
3756 and then Present
(Comp
)
3757 and then not Is_Frozen
(Comp
)
3758 and then not Is_Actual_For_Formal_Incomplete_Type
(Comp
)
3760 Error_Msg_Sloc
:= Sloc
(Subp
);
3761 Error_Msg_Node_2
:= Subp
;
3762 Error_Msg_Name_1
:= Chars
(Tagged_Type
);
3764 ("declaration must appear after completion of type &",
3767 ("\which is a component of untagged type& in the profile "
3768 & "of primitive & of type % that is frozen by the "
3769 & "declaration ", N
, Typ
);
3772 end Check_Premature_Freezing
;
3778 procedure Export_DT
(Typ
: Entity_Id
; DT
: Entity_Id
; Index
: Nat
:= 0)
3784 Set_Is_Statically_Allocated
(DT
);
3785 Set_Is_True_Constant
(DT
);
3786 Set_Is_Exported
(DT
);
3789 Elmt
:= First_Elmt
(Dispatch_Table_Wrappers
(Typ
));
3790 while Count
/= Index
loop
3795 pragma Assert
(Related_Type
(Node
(Elmt
)) = Typ
);
3797 Get_External_Name
(Node
(Elmt
));
3798 Set_Interface_Name
(DT
,
3799 Make_String_Literal
(Loc
,
3800 Strval
=> String_From_Name_Buffer
));
3802 -- Ensure proper Sprint output of this implicit importation
3804 Set_Is_Internal
(DT
);
3808 -----------------------
3809 -- Make_Secondary_DT --
3810 -----------------------
3812 procedure Make_Secondary_DT
3816 Num_Iface_Prims
: Nat
;
3817 Iface_DT_Ptr
: Entity_Id
;
3818 Predef_Prims_Ptr
: Entity_Id
;
3819 Build_Thunks
: Boolean;
3822 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
3823 Exporting_Table
: constant Boolean :=
3824 Building_Static_DT
(Typ
)
3825 and then Suffix_Index
> 0;
3826 Iface_DT
: constant Entity_Id
:= Make_Temporary
(Loc
, 'T');
3827 Predef_Prims
: constant Entity_Id
:= Make_Temporary
(Loc
, 'R');
3828 DT_Constr_List
: List_Id
;
3829 DT_Aggr_List
: List_Id
;
3830 Empty_DT
: Boolean := False;
3831 Nb_Predef_Prims
: Nat
:= 0;
3835 OSD_Aggr_List
: List_Id
;
3838 Prim_Elmt
: Elmt_Id
;
3839 Prim_Ops_Aggr_List
: List_Id
;
3842 -- Handle cases in which we do not generate statically allocated
3845 if not Building_Static_DT
(Typ
) then
3846 Set_Ekind
(Predef_Prims
, E_Variable
);
3847 Set_Ekind
(Iface_DT
, E_Variable
);
3849 -- Statically allocated dispatch tables and related entities are
3853 Set_Ekind
(Predef_Prims
, E_Constant
);
3854 Set_Is_Statically_Allocated
(Predef_Prims
);
3855 Set_Is_True_Constant
(Predef_Prims
);
3857 Set_Ekind
(Iface_DT
, E_Constant
);
3858 Set_Is_Statically_Allocated
(Iface_DT
);
3859 Set_Is_True_Constant
(Iface_DT
);
3862 -- Calculate the number of slots of the dispatch table. If the number
3863 -- of primitives of Typ is 0 we reserve a dummy single entry for its
3864 -- DT because at run time the pointer to this dummy entry will be
3867 if Num_Iface_Prims
= 0 then
3871 Nb_Prim
:= Num_Iface_Prims
;
3876 -- Predef_Prims : Address_Array (1 .. Default_Prim_Ops_Count) :=
3877 -- (predef-prim-op-thunk-1'address,
3878 -- predef-prim-op-thunk-2'address,
3880 -- predef-prim-op-thunk-n'address);
3881 -- for Predef_Prims'Alignment use Address'Alignment
3883 -- Stage 1: Calculate the number of predefined primitives
3885 if not Building_Static_DT
(Typ
) then
3886 Nb_Predef_Prims
:= Max_Predef_Prims
;
3888 Prim_Elmt
:= First_Elmt
(Primitive_Operations
(Typ
));
3889 while Present
(Prim_Elmt
) loop
3890 Prim
:= Node
(Prim_Elmt
);
3892 if Is_Predefined_Dispatching_Operation
(Prim
)
3893 and then not Is_Abstract_Subprogram
(Prim
)
3895 Pos
:= UI_To_Int
(DT_Position
(Prim
));
3897 if Pos
> Nb_Predef_Prims
then
3898 Nb_Predef_Prims
:= Pos
;
3902 Next_Elmt
(Prim_Elmt
);
3906 if Generate_SCIL
then
3907 Nb_Predef_Prims
:= 0;
3910 -- Stage 2: Create the thunks associated with the predefined
3911 -- primitives and save their entity to fill the aggregate.
3914 Prim_Table
: array (Nat
range 1 .. Nb_Predef_Prims
) of Entity_Id
;
3916 Thunk_Id
: Entity_Id
;
3917 Thunk_Code
: Node_Id
;
3920 Prim_Ops_Aggr_List
:= New_List
;
3921 Prim_Table
:= (others => Empty
);
3923 if Building_Static_DT
(Typ
) then
3924 Prim_Elmt
:= First_Elmt
(Primitive_Operations
(Typ
));
3925 while Present
(Prim_Elmt
) loop
3926 Prim
:= Node
(Prim_Elmt
);
3928 if Is_Predefined_Dispatching_Operation
(Prim
)
3929 and then not Is_Abstract_Subprogram
(Prim
)
3930 and then not Is_Eliminated
(Prim
)
3931 and then not Generate_SCIL
3932 and then not Present
(Prim_Table
3933 (UI_To_Int
(DT_Position
(Prim
))))
3935 if not Build_Thunks
then
3936 Prim_Table
(UI_To_Int
(DT_Position
(Prim
))) :=
3940 Expand_Interface_Thunk
3941 (Ultimate_Alias
(Prim
), Thunk_Id
, Thunk_Code
);
3943 if Present
(Thunk_Id
) then
3944 Append_To
(Result
, Thunk_Code
);
3945 Prim_Table
(UI_To_Int
(DT_Position
(Prim
))) :=
3951 Next_Elmt
(Prim_Elmt
);
3955 for J
in Prim_Table
'Range loop
3956 if Present
(Prim_Table
(J
)) then
3958 Unchecked_Convert_To
(RTE
(RE_Prim_Ptr
),
3959 Make_Attribute_Reference
(Loc
,
3960 Prefix
=> New_Occurrence_Of
(Prim_Table
(J
), Loc
),
3961 Attribute_Name
=> Name_Unrestricted_Access
));
3963 New_Node
:= Make_Null
(Loc
);
3966 Append_To
(Prim_Ops_Aggr_List
, New_Node
);
3970 Make_Aggregate
(Loc
, Expressions
=> Prim_Ops_Aggr_List
);
3972 -- Remember aggregates initializing dispatch tables
3974 Append_Elmt
(New_Node
, DT_Aggr
);
3977 Make_Subtype_Declaration
(Loc
,
3978 Defining_Identifier
=> Make_Temporary
(Loc
, 'S'),
3979 Subtype_Indication
=>
3980 New_Occurrence_Of
(RTE
(RE_Address_Array
), Loc
));
3982 Append_To
(Result
, Decl
);
3985 Make_Object_Declaration
(Loc
,
3986 Defining_Identifier
=> Predef_Prims
,
3987 Constant_Present
=> Building_Static_DT
(Typ
),
3988 Aliased_Present
=> True,
3989 Object_Definition
=> New_Occurrence_Of
3990 (Defining_Identifier
(Decl
), Loc
),
3991 Expression
=> New_Node
));
3994 Make_Attribute_Definition_Clause
(Loc
,
3995 Name
=> New_Occurrence_Of
(Predef_Prims
, Loc
),
3996 Chars
=> Name_Alignment
,
3998 Make_Attribute_Reference
(Loc
,
4000 New_Occurrence_Of
(RTE
(RE_Integer_Address
), Loc
),
4001 Attribute_Name
=> Name_Alignment
)));
4006 -- OSD : Ada.Tags.Object_Specific_Data (Nb_Prims) :=
4007 -- (OSD_Table => (1 => <value>,
4011 -- Iface_DT : Dispatch_Table (Nb_Prims) :=
4012 -- ([ Signature => <sig-value> ],
4013 -- Tag_Kind => <tag_kind-value>,
4014 -- Predef_Prims => Predef_Prims'Address,
4015 -- Offset_To_Top => 0,
4016 -- OSD => OSD'Address,
4017 -- Prims_Ptr => (prim-op-1'address,
4018 -- prim-op-2'address,
4020 -- prim-op-n'address));
4021 -- for Iface_DT'Alignment use Address'Alignment;
4023 -- Stage 3: Initialize the discriminant and the record components
4025 DT_Constr_List
:= New_List
;
4026 DT_Aggr_List
:= New_List
;
4030 Append_To
(DT_Constr_List
, Make_Integer_Literal
(Loc
, Nb_Prim
));
4031 Append_To
(DT_Aggr_List
, Make_Integer_Literal
(Loc
, Nb_Prim
));
4035 if RTE_Record_Component_Available
(RE_Signature
) then
4036 Append_To
(DT_Aggr_List
,
4037 New_Occurrence_Of
(RTE
(RE_Secondary_DT
), Loc
));
4042 if RTE_Record_Component_Available
(RE_Tag_Kind
) then
4043 Append_To
(DT_Aggr_List
, Tagged_Kind
(Typ
));
4048 Append_To
(DT_Aggr_List
,
4049 Make_Attribute_Reference
(Loc
,
4050 Prefix
=> New_Occurrence_Of
(Predef_Prims
, Loc
),
4051 Attribute_Name
=> Name_Address
));
4053 -- Note: The correct value of Offset_To_Top will be set by the init
4056 Append_To
(DT_Aggr_List
, Make_Integer_Literal
(Loc
, 0));
4058 -- Generate the Object Specific Data table required to dispatch calls
4059 -- through synchronized interfaces.
4062 or else Is_Abstract_Type
(Typ
)
4063 or else Is_Controlled
(Typ
)
4064 or else Restriction_Active
(No_Dispatching_Calls
)
4065 or else not Is_Limited_Type
(Typ
)
4066 or else not Has_Interfaces
(Typ
)
4067 or else not Build_Thunks
4068 or else not RTE_Record_Component_Available
(RE_OSD_Table
)
4070 -- No OSD table required
4072 Append_To
(DT_Aggr_List
,
4073 New_Occurrence_Of
(RTE
(RE_Null_Address
), Loc
));
4076 OSD_Aggr_List
:= New_List
;
4079 Prim_Table
: array (Nat
range 1 .. Nb_Prim
) of Entity_Id
;
4081 Prim_Alias
: Entity_Id
;
4082 Prim_Elmt
: Elmt_Id
;
4088 Prim_Table
:= (others => Empty
);
4089 Prim_Alias
:= Empty
;
4091 Prim_Elmt
:= First_Elmt
(Primitive_Operations
(Typ
));
4092 while Present
(Prim_Elmt
) loop
4093 Prim
:= Node
(Prim_Elmt
);
4095 if Present
(Interface_Alias
(Prim
))
4096 and then Find_Dispatching_Type
4097 (Interface_Alias
(Prim
)) = Iface
4099 Prim_Alias
:= Interface_Alias
(Prim
);
4100 E
:= Ultimate_Alias
(Prim
);
4101 Pos
:= UI_To_Int
(DT_Position
(Prim_Alias
));
4103 if Present
(Prim_Table
(Pos
)) then
4104 pragma Assert
(Prim_Table
(Pos
) = E
);
4108 Prim_Table
(Pos
) := E
;
4110 Append_To
(OSD_Aggr_List
,
4111 Make_Component_Association
(Loc
,
4112 Choices
=> New_List
(
4113 Make_Integer_Literal
(Loc
,
4114 DT_Position
(Prim_Alias
))),
4116 Make_Integer_Literal
(Loc
,
4117 DT_Position
(Alias
(Prim
)))));
4123 Next_Elmt
(Prim_Elmt
);
4125 pragma Assert
(Count
= Nb_Prim
);
4128 OSD
:= Make_Temporary
(Loc
, 'I');
4131 Make_Object_Declaration
(Loc
,
4132 Defining_Identifier
=> OSD
,
4133 Object_Definition
=>
4134 Make_Subtype_Indication
(Loc
,
4136 New_Occurrence_Of
(RTE
(RE_Object_Specific_Data
), Loc
),
4138 Make_Index_Or_Discriminant_Constraint
(Loc
,
4139 Constraints
=> New_List
(
4140 Make_Integer_Literal
(Loc
, Nb_Prim
)))),
4143 Make_Aggregate
(Loc
,
4144 Component_Associations
=> New_List
(
4145 Make_Component_Association
(Loc
,
4146 Choices
=> New_List
(
4148 (RTE_Record_Component
(RE_OSD_Num_Prims
), Loc
)),
4150 Make_Integer_Literal
(Loc
, Nb_Prim
)),
4152 Make_Component_Association
(Loc
,
4153 Choices
=> New_List
(
4155 (RTE_Record_Component
(RE_OSD_Table
), Loc
)),
4156 Expression
=> Make_Aggregate
(Loc
,
4157 Component_Associations
=> OSD_Aggr_List
))))));
4160 Make_Attribute_Definition_Clause
(Loc
,
4161 Name
=> New_Occurrence_Of
(OSD
, Loc
),
4162 Chars
=> Name_Alignment
,
4164 Make_Attribute_Reference
(Loc
,
4166 New_Occurrence_Of
(RTE
(RE_Integer_Address
), Loc
),
4167 Attribute_Name
=> Name_Alignment
)));
4169 -- In secondary dispatch tables the Typeinfo component contains
4170 -- the address of the Object Specific Data (see a-tags.ads)
4172 Append_To
(DT_Aggr_List
,
4173 Make_Attribute_Reference
(Loc
,
4174 Prefix
=> New_Occurrence_Of
(OSD
, Loc
),
4175 Attribute_Name
=> Name_Address
));
4178 -- Initialize the table of primitive operations
4180 Prim_Ops_Aggr_List
:= New_List
;
4183 Append_To
(Prim_Ops_Aggr_List
, Make_Null
(Loc
));
4185 elsif Is_Abstract_Type
(Typ
)
4186 or else not Building_Static_DT
(Typ
)
4188 for J
in 1 .. Nb_Prim
loop
4189 Append_To
(Prim_Ops_Aggr_List
, Make_Null
(Loc
));
4194 CPP_Nb_Prims
: constant Nat
:= CPP_Num_Prims
(Typ
);
4197 Prim_Table
: array (Nat
range 1 .. Nb_Prim
) of Entity_Id
;
4198 Thunk_Code
: Node_Id
;
4199 Thunk_Id
: Entity_Id
;
4202 Prim_Table
:= (others => Empty
);
4204 Prim_Elmt
:= First_Elmt
(Primitive_Operations
(Typ
));
4205 while Present
(Prim_Elmt
) loop
4206 Prim
:= Node
(Prim_Elmt
);
4207 E
:= Ultimate_Alias
(Prim
);
4208 Prim_Pos
:= UI_To_Int
(DT_Position
(E
));
4210 -- Do not reference predefined primitives because they are
4211 -- located in a separate dispatch table; skip abstract and
4212 -- eliminated primitives; skip primitives located in the C++
4213 -- part of the dispatch table because their slot is set by
4216 if not Is_Predefined_Dispatching_Operation
(Prim
)
4217 and then Present
(Interface_Alias
(Prim
))
4218 and then not Is_Abstract_Subprogram
(Alias
(Prim
))
4219 and then not Is_Eliminated
(Alias
(Prim
))
4220 and then (not Is_CPP_Class
(Root_Type
(Typ
))
4221 or else Prim_Pos
> CPP_Nb_Prims
)
4222 and then Find_Dispatching_Type
4223 (Interface_Alias
(Prim
)) = Iface
4225 -- Generate the code of the thunk only if the abstract
4226 -- interface type is not an immediate ancestor of
4227 -- Tagged_Type. Otherwise the DT associated with the
4228 -- interface is the primary DT.
4230 and then not Is_Ancestor
(Iface
, Typ
,
4231 Use_Full_View
=> True)
4233 if not Build_Thunks
then
4235 UI_To_Int
(DT_Position
(Interface_Alias
(Prim
)));
4236 Prim_Table
(Prim_Pos
) := Alias
(Prim
);
4239 Expand_Interface_Thunk
(Prim
, Thunk_Id
, Thunk_Code
);
4241 if Present
(Thunk_Id
) then
4243 UI_To_Int
(DT_Position
(Interface_Alias
(Prim
)));
4245 Prim_Table
(Prim_Pos
) := Thunk_Id
;
4246 Append_To
(Result
, Thunk_Code
);
4251 Next_Elmt
(Prim_Elmt
);
4254 for J
in Prim_Table
'Range loop
4255 if Present
(Prim_Table
(J
)) then
4257 Unchecked_Convert_To
(RTE
(RE_Prim_Ptr
),
4258 Make_Attribute_Reference
(Loc
,
4259 Prefix
=> New_Occurrence_Of
(Prim_Table
(J
), Loc
),
4260 Attribute_Name
=> Name_Unrestricted_Access
));
4263 New_Node
:= Make_Null
(Loc
);
4266 Append_To
(Prim_Ops_Aggr_List
, New_Node
);
4272 Make_Aggregate
(Loc
,
4273 Expressions
=> Prim_Ops_Aggr_List
);
4275 Append_To
(DT_Aggr_List
, New_Node
);
4277 -- Remember aggregates initializing dispatch tables
4279 Append_Elmt
(New_Node
, DT_Aggr
);
4281 -- Note: Secondary dispatch tables cannot be declared constant
4282 -- because the component Offset_To_Top is currently initialized
4283 -- by the IP routine.
4286 Make_Object_Declaration
(Loc
,
4287 Defining_Identifier
=> Iface_DT
,
4288 Aliased_Present
=> True,
4289 Constant_Present
=> False,
4291 Object_Definition
=>
4292 Make_Subtype_Indication
(Loc
,
4293 Subtype_Mark
=> New_Occurrence_Of
4294 (RTE
(RE_Dispatch_Table_Wrapper
), Loc
),
4295 Constraint
=> Make_Index_Or_Discriminant_Constraint
(Loc
,
4296 Constraints
=> DT_Constr_List
)),
4299 Make_Aggregate
(Loc
,
4300 Expressions
=> DT_Aggr_List
)));
4303 Make_Attribute_Definition_Clause
(Loc
,
4304 Name
=> New_Occurrence_Of
(Iface_DT
, Loc
),
4305 Chars
=> Name_Alignment
,
4308 Make_Attribute_Reference
(Loc
,
4310 New_Occurrence_Of
(RTE
(RE_Integer_Address
), Loc
),
4311 Attribute_Name
=> Name_Alignment
)));
4313 if Exporting_Table
then
4314 Export_DT
(Typ
, Iface_DT
, Suffix_Index
);
4316 -- Generate code to create the pointer to the dispatch table
4318 -- Iface_DT_Ptr : Tag := Tag!(DT.Prims_Ptr'Address);
4320 -- Note: This declaration is not added here if the table is exported
4321 -- because in such case Make_Tags has already added this declaration.
4325 Make_Object_Declaration
(Loc
,
4326 Defining_Identifier
=> Iface_DT_Ptr
,
4327 Constant_Present
=> True,
4329 Object_Definition
=>
4330 New_Occurrence_Of
(RTE
(RE_Interface_Tag
), Loc
),
4333 Unchecked_Convert_To
(RTE
(RE_Interface_Tag
),
4334 Make_Attribute_Reference
(Loc
,
4336 Make_Selected_Component
(Loc
,
4337 Prefix
=> New_Occurrence_Of
(Iface_DT
, Loc
),
4340 (RTE_Record_Component
(RE_Prims_Ptr
), Loc
)),
4341 Attribute_Name
=> Name_Address
))));
4345 Make_Object_Declaration
(Loc
,
4346 Defining_Identifier
=> Predef_Prims_Ptr
,
4347 Constant_Present
=> True,
4349 Object_Definition
=>
4350 New_Occurrence_Of
(RTE
(RE_Address
), Loc
),
4353 Make_Attribute_Reference
(Loc
,
4355 Make_Selected_Component
(Loc
,
4356 Prefix
=> New_Occurrence_Of
(Iface_DT
, Loc
),
4359 (RTE_Record_Component
(RE_Predef_Prims
), Loc
)),
4360 Attribute_Name
=> Name_Address
)));
4362 -- Remember entities containing dispatch tables
4364 Append_Elmt
(Predef_Prims
, DT_Decl
);
4365 Append_Elmt
(Iface_DT
, DT_Decl
);
4366 end Make_Secondary_DT
;
4370 Elab_Code
: constant List_Id
:= New_List
;
4371 Result
: constant List_Id
:= New_List
;
4372 Tname
: constant Name_Id
:= Chars
(Typ
);
4374 AI_Tag_Elmt
: Elmt_Id
;
4375 AI_Tag_Comp
: Elmt_Id
;
4376 DT_Aggr_List
: List_Id
;
4377 DT_Constr_List
: List_Id
;
4381 Iface_Table_Node
: Node_Id
;
4382 Name_ITable
: Name_Id
;
4383 Nb_Predef_Prims
: Nat
:= 0;
4386 Num_Ifaces
: Nat
:= 0;
4387 Parent_Typ
: Entity_Id
;
4389 Prim_Elmt
: Elmt_Id
;
4390 Prim_Ops_Aggr_List
: List_Id
;
4392 Typ_Comps
: Elist_Id
;
4393 Typ_Ifaces
: Elist_Id
;
4394 TSD_Aggr_List
: List_Id
;
4395 TSD_Tags_List
: List_Id
;
4397 Save_Ghost_Mode
: constant Ghost_Mode_Type
:= Ghost_Mode
;
4399 -- The following name entries are used by Make_DT to generate a number
4400 -- of entities related to a tagged type. These entities may be generated
4401 -- in a scope other than that of the tagged type declaration, and if
4402 -- the entities for two tagged types with the same name happen to be
4403 -- generated in the same scope, we have to take care to use different
4404 -- names. This is achieved by means of a unique serial number appended
4405 -- to each generated entity name.
4407 Name_DT
: constant Name_Id
:=
4408 New_External_Name
(Tname
, 'T', Suffix_Index
=> -1);
4409 Name_Exname
: constant Name_Id
:=
4410 New_External_Name
(Tname
, 'E', Suffix_Index
=> -1);
4411 Name_HT_Link
: constant Name_Id
:=
4412 New_External_Name
(Tname
, 'H', Suffix_Index
=> -1);
4413 Name_Predef_Prims
: constant Name_Id
:=
4414 New_External_Name
(Tname
, 'R', Suffix_Index
=> -1);
4415 Name_SSD
: constant Name_Id
:=
4416 New_External_Name
(Tname
, 'S', Suffix_Index
=> -1);
4417 Name_TSD
: constant Name_Id
:=
4418 New_External_Name
(Tname
, 'B', Suffix_Index
=> -1);
4420 -- Entities built with above names
4422 DT
: constant Entity_Id
:=
4423 Make_Defining_Identifier
(Loc
, Name_DT
);
4424 Exname
: constant Entity_Id
:=
4425 Make_Defining_Identifier
(Loc
, Name_Exname
);
4426 HT_Link
: constant Entity_Id
:=
4427 Make_Defining_Identifier
(Loc
, Name_HT_Link
);
4428 Predef_Prims
: constant Entity_Id
:=
4429 Make_Defining_Identifier
(Loc
, Name_Predef_Prims
);
4430 SSD
: constant Entity_Id
:=
4431 Make_Defining_Identifier
(Loc
, Name_SSD
);
4432 TSD
: constant Entity_Id
:=
4433 Make_Defining_Identifier
(Loc
, Name_TSD
);
4435 -- Start of processing for Make_DT
4438 pragma Assert
(Is_Frozen
(Typ
));
4440 -- The tagged type being processed may be subject to pragma Ghost. Set
4441 -- the mode now to ensure that any nodes generated during dispatch table
4442 -- creation are properly marked as Ghost.
4444 Set_Ghost_Mode
(Declaration_Node
(Typ
), Typ
);
4446 -- Handle cases in which there is no need to build the dispatch table
4448 if Has_Dispatch_Table
(Typ
)
4449 or else No
(Access_Disp_Table
(Typ
))
4450 or else Is_CPP_Class
(Typ
)
4452 Ghost_Mode
:= Save_Ghost_Mode
;
4455 elsif No_Run_Time_Mode
then
4456 Error_Msg_CRT
("tagged types", Typ
);
4457 Ghost_Mode
:= Save_Ghost_Mode
;
4460 elsif not RTE_Available
(RE_Tag
) then
4462 Make_Object_Declaration
(Loc
,
4463 Defining_Identifier
=> Node
(First_Elmt
4464 (Access_Disp_Table
(Typ
))),
4465 Object_Definition
=> New_Occurrence_Of
(RTE
(RE_Tag
), Loc
),
4466 Constant_Present
=> True,
4468 Unchecked_Convert_To
(RTE
(RE_Tag
),
4469 New_Occurrence_Of
(RTE
(RE_Null_Address
), Loc
))));
4471 Analyze_List
(Result
, Suppress
=> All_Checks
);
4472 Error_Msg_CRT
("tagged types", Typ
);
4473 Ghost_Mode
:= Save_Ghost_Mode
;
4477 -- Ensure that the value of Max_Predef_Prims defined in a-tags is
4478 -- correct. Valid values are 9 under configurable runtime or 15
4479 -- with full runtime.
4481 if RTE_Available
(RE_Interface_Data
) then
4482 if Max_Predef_Prims
/= 15 then
4483 Error_Msg_N
("run-time library configuration error", Typ
);
4484 Ghost_Mode
:= Save_Ghost_Mode
;
4488 if Max_Predef_Prims
/= 9 then
4489 Error_Msg_N
("run-time library configuration error", Typ
);
4490 Error_Msg_CRT
("tagged types", Typ
);
4491 Ghost_Mode
:= Save_Ghost_Mode
;
4496 -- Initialize Parent_Typ handling private types
4498 Parent_Typ
:= Etype
(Typ
);
4500 if Present
(Full_View
(Parent_Typ
)) then
4501 Parent_Typ
:= Full_View
(Parent_Typ
);
4504 -- Ensure that all the primitives are frozen. This is only required when
4505 -- building static dispatch tables --- the primitives must be frozen to
4506 -- be referenced (otherwise we have problems with the backend). It is
4507 -- not a requirement with nonstatic dispatch tables because in this case
4508 -- we generate now an empty dispatch table; the extra code required to
4509 -- register the primitives in the slots will be generated later --- when
4510 -- each primitive is frozen (see Freeze_Subprogram).
4512 if Building_Static_DT
(Typ
) then
4514 Save
: constant Boolean := Freezing_Library_Level_Tagged_Type
;
4516 Prim_Elmt
: Elmt_Id
;
4520 Freezing_Library_Level_Tagged_Type
:= True;
4522 Prim_Elmt
:= First_Elmt
(Primitive_Operations
(Typ
));
4523 while Present
(Prim_Elmt
) loop
4524 Prim
:= Node
(Prim_Elmt
);
4525 Frnodes
:= Freeze_Entity
(Prim
, Typ
);
4531 F
:= First_Formal
(Prim
);
4532 while Present
(F
) loop
4533 Check_Premature_Freezing
(Prim
, Typ
, Etype
(F
));
4537 Check_Premature_Freezing
(Prim
, Typ
, Etype
(Prim
));
4540 if Present
(Frnodes
) then
4541 Append_List_To
(Result
, Frnodes
);
4544 Next_Elmt
(Prim_Elmt
);
4547 Freezing_Library_Level_Tagged_Type
:= Save
;
4551 -- Ada 2005 (AI-251): Build the secondary dispatch tables
4553 if Has_Interfaces
(Typ
) then
4554 Collect_Interface_Components
(Typ
, Typ_Comps
);
4556 -- Each secondary dispatch table is assigned an unique positive
4557 -- suffix index; such value also corresponds with the location of
4558 -- its entity in the Dispatch_Table_Wrappers list (see Make_Tags).
4560 -- Note: This value must be kept sync with the Suffix_Index values
4561 -- generated by Make_Tags
4565 Next_Elmt
(Next_Elmt
(First_Elmt
(Access_Disp_Table
(Typ
))));
4567 AI_Tag_Comp
:= First_Elmt
(Typ_Comps
);
4568 while Present
(AI_Tag_Comp
) loop
4569 pragma Assert
(Has_Suffix
(Node
(AI_Tag_Elmt
), 'P'));
4571 -- Build the secondary table containing pointers to thunks
4576 (Related_Type
(Node
(AI_Tag_Comp
))),
4577 Suffix_Index
=> Suffix_Index
,
4578 Num_Iface_Prims
=> UI_To_Int
4579 (DT_Entry_Count
(Node
(AI_Tag_Comp
))),
4580 Iface_DT_Ptr
=> Node
(AI_Tag_Elmt
),
4581 Predef_Prims_Ptr
=> Node
(Next_Elmt
(AI_Tag_Elmt
)),
4582 Build_Thunks
=> True,
4585 -- Skip secondary dispatch table referencing thunks to predefined
4588 Next_Elmt
(AI_Tag_Elmt
);
4589 pragma Assert
(Has_Suffix
(Node
(AI_Tag_Elmt
), 'Y'));
4591 -- Secondary dispatch table referencing user-defined primitives
4592 -- covered by this interface.
4594 Next_Elmt
(AI_Tag_Elmt
);
4595 pragma Assert
(Has_Suffix
(Node
(AI_Tag_Elmt
), 'D'));
4597 -- Build the secondary table containing pointers to primitives
4598 -- (used to give support to Generic Dispatching Constructors).
4603 (Related_Type
(Node
(AI_Tag_Comp
))),
4605 Num_Iface_Prims
=> UI_To_Int
4606 (DT_Entry_Count
(Node
(AI_Tag_Comp
))),
4607 Iface_DT_Ptr
=> Node
(AI_Tag_Elmt
),
4608 Predef_Prims_Ptr
=> Node
(Next_Elmt
(AI_Tag_Elmt
)),
4609 Build_Thunks
=> False,
4612 -- Skip secondary dispatch table referencing predefined primitives
4614 Next_Elmt
(AI_Tag_Elmt
);
4615 pragma Assert
(Has_Suffix
(Node
(AI_Tag_Elmt
), 'Z'));
4617 Suffix_Index
:= Suffix_Index
+ 1;
4618 Next_Elmt
(AI_Tag_Elmt
);
4619 Next_Elmt
(AI_Tag_Comp
);
4623 -- Get the _tag entity and number of primitives of its dispatch table
4625 DT_Ptr
:= Node
(First_Elmt
(Access_Disp_Table
(Typ
)));
4626 Nb_Prim
:= UI_To_Int
(DT_Entry_Count
(First_Tag_Component
(Typ
)));
4628 if Generate_SCIL
then
4632 Set_Is_Statically_Allocated
(DT
, Is_Library_Level_Tagged_Type
(Typ
));
4633 Set_Is_Statically_Allocated
(SSD
, Is_Library_Level_Tagged_Type
(Typ
));
4634 Set_Is_Statically_Allocated
(TSD
, Is_Library_Level_Tagged_Type
(Typ
));
4635 Set_Is_Statically_Allocated
(Predef_Prims
,
4636 Is_Library_Level_Tagged_Type
(Typ
));
4638 -- In case of locally defined tagged type we declare the object
4639 -- containing the dispatch table by means of a variable. Its
4640 -- initialization is done later by means of an assignment. This is
4641 -- required to generate its External_Tag.
4643 if not Building_Static_DT
(Typ
) then
4646 -- DT : No_Dispatch_Table_Wrapper;
4647 -- for DT'Alignment use Address'Alignment;
4648 -- DT_Ptr : Tag := !Tag (DT.NDT_Prims_Ptr'Address);
4650 if not Has_DT
(Typ
) then
4652 Make_Object_Declaration
(Loc
,
4653 Defining_Identifier
=> DT
,
4654 Aliased_Present
=> True,
4655 Constant_Present
=> False,
4656 Object_Definition
=>
4658 (RTE
(RE_No_Dispatch_Table_Wrapper
), Loc
)));
4661 Make_Attribute_Definition_Clause
(Loc
,
4662 Name
=> New_Occurrence_Of
(DT
, Loc
),
4663 Chars
=> Name_Alignment
,
4665 Make_Attribute_Reference
(Loc
,
4667 New_Occurrence_Of
(RTE
(RE_Integer_Address
), Loc
),
4668 Attribute_Name
=> Name_Alignment
)));
4671 Make_Object_Declaration
(Loc
,
4672 Defining_Identifier
=> DT_Ptr
,
4673 Object_Definition
=> New_Occurrence_Of
(RTE
(RE_Tag
), Loc
),
4674 Constant_Present
=> True,
4676 Unchecked_Convert_To
(RTE
(RE_Tag
),
4677 Make_Attribute_Reference
(Loc
,
4679 Make_Selected_Component
(Loc
,
4680 Prefix
=> New_Occurrence_Of
(DT
, Loc
),
4683 (RTE_Record_Component
(RE_NDT_Prims_Ptr
), Loc
)),
4684 Attribute_Name
=> Name_Address
))));
4686 Set_Is_Statically_Allocated
(DT_Ptr
,
4687 Is_Library_Level_Tagged_Type
(Typ
));
4689 -- Generate the SCIL node for the previous object declaration
4690 -- because it has a tag initialization.
4692 if Generate_SCIL
then
4694 Make_SCIL_Dispatch_Table_Tag_Init
(Sloc
(Last
(Result
)));
4695 Set_SCIL_Entity
(New_Node
, Typ
);
4696 Set_SCIL_Node
(Last
(Result
), New_Node
);
4698 goto Early_Exit_For_SCIL
;
4700 -- Gnat2scil has its own implementation of dispatch tables,
4701 -- different than what is being implemented here. Generating
4702 -- further dispatch table initialization code would just
4703 -- cause gnat2scil to generate useless Scil which CodePeer
4704 -- would waste time and space analyzing, so we skip it.
4708 -- DT : Dispatch_Table_Wrapper (Nb_Prim);
4709 -- for DT'Alignment use Address'Alignment;
4710 -- DT_Ptr : Tag := !Tag (DT.Prims_Ptr'Address);
4713 -- If the tagged type has no primitives we add a dummy slot
4714 -- whose address will be the tag of this type.
4718 New_List
(Make_Integer_Literal
(Loc
, 1));
4721 New_List
(Make_Integer_Literal
(Loc
, Nb_Prim
));
4725 Make_Object_Declaration
(Loc
,
4726 Defining_Identifier
=> DT
,
4727 Aliased_Present
=> True,
4728 Constant_Present
=> False,
4729 Object_Definition
=>
4730 Make_Subtype_Indication
(Loc
,
4732 New_Occurrence_Of
(RTE
(RE_Dispatch_Table_Wrapper
), Loc
),
4734 Make_Index_Or_Discriminant_Constraint
(Loc
,
4735 Constraints
=> DT_Constr_List
))));
4738 Make_Attribute_Definition_Clause
(Loc
,
4739 Name
=> New_Occurrence_Of
(DT
, Loc
),
4740 Chars
=> Name_Alignment
,
4742 Make_Attribute_Reference
(Loc
,
4744 New_Occurrence_Of
(RTE
(RE_Integer_Address
), Loc
),
4745 Attribute_Name
=> Name_Alignment
)));
4748 Make_Object_Declaration
(Loc
,
4749 Defining_Identifier
=> DT_Ptr
,
4750 Object_Definition
=> New_Occurrence_Of
(RTE
(RE_Tag
), Loc
),
4751 Constant_Present
=> True,
4753 Unchecked_Convert_To
(RTE
(RE_Tag
),
4754 Make_Attribute_Reference
(Loc
,
4756 Make_Selected_Component
(Loc
,
4757 Prefix
=> New_Occurrence_Of
(DT
, Loc
),
4760 (RTE_Record_Component
(RE_Prims_Ptr
), Loc
)),
4761 Attribute_Name
=> Name_Address
))));
4763 Set_Is_Statically_Allocated
(DT_Ptr
,
4764 Is_Library_Level_Tagged_Type
(Typ
));
4766 -- Generate the SCIL node for the previous object declaration
4767 -- because it has a tag initialization.
4769 if Generate_SCIL
then
4771 Make_SCIL_Dispatch_Table_Tag_Init
(Sloc
(Last
(Result
)));
4772 Set_SCIL_Entity
(New_Node
, Typ
);
4773 Set_SCIL_Node
(Last
(Result
), New_Node
);
4775 goto Early_Exit_For_SCIL
;
4777 -- Gnat2scil has its own implementation of dispatch tables,
4778 -- different than what is being implemented here. Generating
4779 -- further dispatch table initialization code would just
4780 -- cause gnat2scil to generate useless Scil which CodePeer
4781 -- would waste time and space analyzing, so we skip it.
4785 Make_Object_Declaration
(Loc
,
4786 Defining_Identifier
=>
4787 Node
(Next_Elmt
(First_Elmt
(Access_Disp_Table
(Typ
)))),
4788 Constant_Present
=> True,
4789 Object_Definition
=>
4790 New_Occurrence_Of
(RTE
(RE_Address
), Loc
),
4792 Make_Attribute_Reference
(Loc
,
4794 Make_Selected_Component
(Loc
,
4795 Prefix
=> New_Occurrence_Of
(DT
, Loc
),
4798 (RTE_Record_Component
(RE_Predef_Prims
), Loc
)),
4799 Attribute_Name
=> Name_Address
)));
4803 -- Generate: Exname : constant String := full_qualified_name (typ);
4804 -- The type itself may be an anonymous parent type, so use the first
4805 -- subtype to have a user-recognizable name.
4808 Make_Object_Declaration
(Loc
,
4809 Defining_Identifier
=> Exname
,
4810 Constant_Present
=> True,
4811 Object_Definition
=> New_Occurrence_Of
(Standard_String
, Loc
),
4813 Make_String_Literal
(Loc
,
4814 Strval
=> Fully_Qualified_Name_String
(First_Subtype
(Typ
)))));
4815 Set_Is_Statically_Allocated
(Exname
);
4816 Set_Is_True_Constant
(Exname
);
4818 -- Declare the object used by Ada.Tags.Register_Tag
4820 if RTE_Available
(RE_Register_Tag
) then
4822 Make_Object_Declaration
(Loc
,
4823 Defining_Identifier
=> HT_Link
,
4824 Object_Definition
=> New_Occurrence_Of
(RTE
(RE_Tag
), Loc
)));
4827 -- Generate code to create the storage for the type specific data object
4828 -- with enough space to store the tags of the ancestors plus the tags
4829 -- of all the implemented interfaces (as described in a-tags.adb).
4831 -- TSD : Type_Specific_Data (I_Depth) :=
4832 -- (Idepth => I_Depth,
4833 -- Access_Level => Type_Access_Level (Typ),
4834 -- Alignment => Typ'Alignment,
4835 -- Expanded_Name => Cstring_Ptr!(Exname'Address))
4836 -- External_Tag => Cstring_Ptr!(Exname'Address))
4837 -- HT_Link => HT_Link'Address,
4838 -- Transportable => <<boolean-value>>,
4839 -- Type_Is_Abstract => <<boolean-value>>,
4840 -- Needs_Finalization => <<boolean-value>>,
4841 -- [ Size_Func => Size_Prim'Access, ]
4842 -- [ Interfaces_Table => <<access-value>>, ]
4843 -- [ SSD => SSD_Table'Address ]
4844 -- Tags_Table => (0 => null,
4847 -- for TSD'Alignment use Address'Alignment
4849 TSD_Aggr_List
:= New_List
;
4851 -- Idepth: Count ancestors to compute the inheritance depth. For private
4852 -- extensions, always go to the full view in order to compute the real
4853 -- inheritance depth.
4856 Current_Typ
: Entity_Id
;
4857 Parent_Typ
: Entity_Id
;
4863 Parent_Typ
:= Etype
(Current_Typ
);
4865 if Is_Private_Type
(Parent_Typ
) then
4866 Parent_Typ
:= Full_View
(Base_Type
(Parent_Typ
));
4869 exit when Parent_Typ
= Current_Typ
;
4871 I_Depth
:= I_Depth
+ 1;
4872 Current_Typ
:= Parent_Typ
;
4876 Append_To
(TSD_Aggr_List
,
4877 Make_Integer_Literal
(Loc
, I_Depth
));
4881 Append_To
(TSD_Aggr_List
,
4882 Make_Integer_Literal
(Loc
, Type_Access_Level
(Typ
)));
4886 -- For CPP types we cannot rely on the value of 'Alignment provided
4887 -- by the backend to initialize this TSD field.
4889 if Convention
(Typ
) = Convention_CPP
4890 or else Is_CPP_Class
(Root_Type
(Typ
))
4892 Append_To
(TSD_Aggr_List
,
4893 Make_Integer_Literal
(Loc
, 0));
4895 Append_To
(TSD_Aggr_List
,
4896 Make_Attribute_Reference
(Loc
,
4897 Prefix
=> New_Occurrence_Of
(Typ
, Loc
),
4898 Attribute_Name
=> Name_Alignment
));
4903 Append_To
(TSD_Aggr_List
,
4904 Unchecked_Convert_To
(RTE
(RE_Cstring_Ptr
),
4905 Make_Attribute_Reference
(Loc
,
4906 Prefix
=> New_Occurrence_Of
(Exname
, Loc
),
4907 Attribute_Name
=> Name_Address
)));
4909 -- External_Tag of a local tagged type
4911 -- <typ>A : constant String :=
4912 -- "Internal tag at 16#tag-addr#: <full-name-of-typ>";
4914 -- The reason we generate this strange name is that we do not want to
4915 -- enter local tagged types in the global hash table used to compute
4916 -- the Internal_Tag attribute for two reasons:
4918 -- 1. It is hard to avoid a tasking race condition for entering the
4919 -- entry into the hash table.
4921 -- 2. It would cause a storage leak, unless we rig up considerable
4922 -- mechanism to remove the entry from the hash table on exit.
4924 -- So what we do is to generate the above external tag name, where the
4925 -- hex address is the address of the local dispatch table (i.e. exactly
4926 -- the value we want if Internal_Tag is computed from this string).
4928 -- Of course this value will only be valid if the tagged type is still
4929 -- in scope, but it clearly must be erroneous to compute the internal
4930 -- tag of a tagged type that is out of scope.
4932 -- We don't do this processing if an explicit external tag has been
4933 -- specified. That's an odd case for which we have already issued a
4934 -- warning, where we will not be able to compute the internal tag.
4936 if not Is_Library_Level_Entity
(Typ
)
4937 and then not Has_External_Tag_Rep_Clause
(Typ
)
4940 Exname
: constant Entity_Id
:=
4941 Make_Defining_Identifier
(Loc
,
4942 Chars
=> New_External_Name
(Tname
, 'A'));
4943 Full_Name
: constant String_Id
:=
4944 Fully_Qualified_Name_String
(First_Subtype
(Typ
));
4945 Str1_Id
: String_Id
;
4946 Str2_Id
: String_Id
;
4950 -- Str1 = "Internal tag at 16#";
4953 Store_String_Chars
("Internal tag at 16#");
4954 Str1_Id
:= End_String
;
4957 -- Str2 = "#: <type-full-name>";
4960 Store_String_Chars
("#: ");
4961 Store_String_Chars
(Full_Name
);
4962 Str2_Id
:= End_String
;
4965 -- Exname : constant String :=
4966 -- Str1 & Address_Image (Tag) & Str2;
4968 if RTE_Available
(RE_Address_Image
) then
4970 Make_Object_Declaration
(Loc
,
4971 Defining_Identifier
=> Exname
,
4972 Constant_Present
=> True,
4973 Object_Definition
=> New_Occurrence_Of
4974 (Standard_String
, Loc
),
4976 Make_Op_Concat
(Loc
,
4977 Left_Opnd
=> Make_String_Literal
(Loc
, Str1_Id
),
4979 Make_Op_Concat
(Loc
,
4981 Make_Function_Call
(Loc
,
4984 (RTE
(RE_Address_Image
), Loc
),
4985 Parameter_Associations
=> New_List
(
4986 Unchecked_Convert_To
(RTE
(RE_Address
),
4987 New_Occurrence_Of
(DT_Ptr
, Loc
)))),
4989 Make_String_Literal
(Loc
, Str2_Id
)))));
4993 Make_Object_Declaration
(Loc
,
4994 Defining_Identifier
=> Exname
,
4995 Constant_Present
=> True,
4996 Object_Definition
=>
4997 New_Occurrence_Of
(Standard_String
, Loc
),
4999 Make_Op_Concat
(Loc
,
5000 Left_Opnd
=> Make_String_Literal
(Loc
, Str1_Id
),
5001 Right_Opnd
=> Make_String_Literal
(Loc
, Str2_Id
))));
5005 Unchecked_Convert_To
(RTE
(RE_Cstring_Ptr
),
5006 Make_Attribute_Reference
(Loc
,
5007 Prefix
=> New_Occurrence_Of
(Exname
, Loc
),
5008 Attribute_Name
=> Name_Address
));
5011 -- External tag of a library-level tagged type: Check for a definition
5012 -- of External_Tag. The clause is considered only if it applies to this
5013 -- specific tagged type, as opposed to one of its ancestors.
5014 -- If the type is an unconstrained type extension, we are building the
5015 -- dispatch table of its anonymous base type, so the external tag, if
5016 -- any was specified, must be retrieved from the first subtype. Go to
5017 -- the full view in case the clause is in the private part.
5021 Def
: constant Node_Id
:= Get_Attribute_Definition_Clause
5022 (Underlying_Type
(First_Subtype
(Typ
)),
5023 Attribute_External_Tag
);
5025 Old_Val
: String_Id
;
5026 New_Val
: String_Id
;
5030 if not Present
(Def
)
5031 or else Entity
(Name
(Def
)) /= First_Subtype
(Typ
)
5034 Unchecked_Convert_To
(RTE
(RE_Cstring_Ptr
),
5035 Make_Attribute_Reference
(Loc
,
5036 Prefix
=> New_Occurrence_Of
(Exname
, Loc
),
5037 Attribute_Name
=> Name_Address
));
5039 Old_Val
:= Strval
(Expr_Value_S
(Expression
(Def
)));
5041 -- For the rep clause "for <typ>'external_tag use y" generate:
5043 -- <typ>A : constant string := y;
5045 -- <typ>A'Address is used to set the External_Tag component
5048 -- Create a new nul terminated string if it is not already
5050 if String_Length
(Old_Val
) > 0
5052 Get_String_Char
(Old_Val
, String_Length
(Old_Val
)) = 0
5056 Start_String
(Old_Val
);
5057 Store_String_Char
(Get_Char_Code
(ASCII
.NUL
));
5058 New_Val
:= End_String
;
5061 E
:= Make_Defining_Identifier
(Loc
,
5062 New_External_Name
(Chars
(Typ
), 'A'));
5065 Make_Object_Declaration
(Loc
,
5066 Defining_Identifier
=> E
,
5067 Constant_Present
=> True,
5068 Object_Definition
=>
5069 New_Occurrence_Of
(Standard_String
, Loc
),
5071 Make_String_Literal
(Loc
, New_Val
)));
5074 Unchecked_Convert_To
(RTE
(RE_Cstring_Ptr
),
5075 Make_Attribute_Reference
(Loc
,
5076 Prefix
=> New_Occurrence_Of
(E
, Loc
),
5077 Attribute_Name
=> Name_Address
));
5082 Append_To
(TSD_Aggr_List
, New_Node
);
5086 if RTE_Available
(RE_Register_Tag
) then
5087 Append_To
(TSD_Aggr_List
,
5088 Unchecked_Convert_To
(RTE
(RE_Tag_Ptr
),
5089 Make_Attribute_Reference
(Loc
,
5090 Prefix
=> New_Occurrence_Of
(HT_Link
, Loc
),
5091 Attribute_Name
=> Name_Address
)));
5093 Append_To
(TSD_Aggr_List
,
5094 Unchecked_Convert_To
(RTE
(RE_Tag_Ptr
),
5095 New_Occurrence_Of
(RTE
(RE_Null_Address
), Loc
)));
5098 -- Transportable: Set for types that can be used in remote calls
5099 -- with respect to E.4(18) legality rules.
5102 Transportable
: Entity_Id
;
5108 or else Is_Shared_Passive
(Typ
)
5110 ((Is_Remote_Types
(Typ
)
5111 or else Is_Remote_Call_Interface
(Typ
))
5112 and then Original_View_In_Visible_Part
(Typ
))
5113 or else not Comes_From_Source
(Typ
));
5115 Append_To
(TSD_Aggr_List
,
5116 New_Occurrence_Of
(Transportable
, Loc
));
5119 -- Type_Is_Abstract (Ada 2012: AI05-0173). This functionality is
5120 -- not available in the HIE runtime.
5122 if RTE_Record_Component_Available
(RE_Type_Is_Abstract
) then
5124 Type_Is_Abstract
: Entity_Id
;
5126 Type_Is_Abstract
:= Boolean_Literals
(Is_Abstract_Type
(Typ
));
5127 Append_To
(TSD_Aggr_List
,
5128 New_Occurrence_Of
(Type_Is_Abstract
, Loc
));
5132 -- Needs_Finalization: Set if the type is controlled or has controlled
5136 Needs_Fin
: Entity_Id
;
5138 Needs_Fin
:= Boolean_Literals
(Needs_Finalization
(Typ
));
5139 Append_To
(TSD_Aggr_List
, New_Occurrence_Of
(Needs_Fin
, Loc
));
5144 if RTE_Record_Component_Available
(RE_Size_Func
) then
5146 -- Initialize this field to Null_Address if we are not building
5147 -- static dispatch tables static or if the size function is not
5148 -- available. In the former case we cannot initialize this field
5149 -- until the function is frozen and registered in the dispatch
5150 -- table (see Register_Primitive).
5152 if not Building_Static_DT
(Typ
) or else not Has_DT
(Typ
) then
5153 Append_To
(TSD_Aggr_List
,
5154 Unchecked_Convert_To
(RTE
(RE_Size_Ptr
),
5155 New_Occurrence_Of
(RTE
(RE_Null_Address
), Loc
)));
5159 Prim_Elmt
: Elmt_Id
;
5161 Size_Comp
: Node_Id
;
5164 Prim_Elmt
:= First_Elmt
(Primitive_Operations
(Typ
));
5165 while Present
(Prim_Elmt
) loop
5166 Prim
:= Node
(Prim_Elmt
);
5168 if Chars
(Prim
) = Name_uSize
then
5169 Prim
:= Ultimate_Alias
(Prim
);
5171 if Is_Abstract_Subprogram
(Prim
) then
5173 Unchecked_Convert_To
(RTE
(RE_Size_Ptr
),
5174 New_Occurrence_Of
(RTE
(RE_Null_Address
), Loc
));
5177 Unchecked_Convert_To
(RTE
(RE_Size_Ptr
),
5178 Make_Attribute_Reference
(Loc
,
5179 Prefix
=> New_Occurrence_Of
(Prim
, Loc
),
5180 Attribute_Name
=> Name_Unrestricted_Access
));
5186 Next_Elmt
(Prim_Elmt
);
5189 pragma Assert
(Present
(Size_Comp
));
5190 Append_To
(TSD_Aggr_List
, Size_Comp
);
5195 -- Interfaces_Table (required for AI-405)
5197 if RTE_Record_Component_Available
(RE_Interfaces_Table
) then
5199 -- Count the number of interface types implemented by Typ
5201 Collect_Interfaces
(Typ
, Typ_Ifaces
);
5203 AI
:= First_Elmt
(Typ_Ifaces
);
5204 while Present
(AI
) loop
5205 Num_Ifaces
:= Num_Ifaces
+ 1;
5209 if Num_Ifaces
= 0 then
5210 Iface_Table_Node
:= Make_Null
(Loc
);
5212 -- Generate the Interface_Table object
5216 TSD_Ifaces_List
: constant List_Id
:= New_List
;
5218 Sec_DT_Tag
: Node_Id
;
5221 AI
:= First_Elmt
(Typ_Ifaces
);
5222 while Present
(AI
) loop
5223 if Is_Ancestor
(Node
(AI
), Typ
, Use_Full_View
=> True) then
5225 New_Occurrence_Of
(DT_Ptr
, Loc
);
5229 (Next_Elmt
(First_Elmt
(Access_Disp_Table
(Typ
))));
5230 pragma Assert
(Has_Thunks
(Node
(Elmt
)));
5232 while Is_Tag
(Node
(Elmt
))
5234 Is_Ancestor
(Node
(AI
), Related_Type
(Node
(Elmt
)),
5235 Use_Full_View
=> True)
5237 pragma Assert
(Has_Thunks
(Node
(Elmt
)));
5239 pragma Assert
(Has_Thunks
(Node
(Elmt
)));
5241 pragma Assert
(not Has_Thunks
(Node
(Elmt
)));
5243 pragma Assert
(not Has_Thunks
(Node
(Elmt
)));
5247 pragma Assert
(Ekind
(Node
(Elmt
)) = E_Constant
5249 Has_Thunks
(Node
(Next_Elmt
(Next_Elmt
(Elmt
)))));
5251 New_Occurrence_Of
(Node
(Next_Elmt
(Next_Elmt
(Elmt
))),
5255 Append_To
(TSD_Ifaces_List
,
5256 Make_Aggregate
(Loc
,
5257 Expressions
=> New_List
(
5261 Unchecked_Convert_To
(RTE
(RE_Tag
),
5263 (Node
(First_Elmt
(Access_Disp_Table
(Node
(AI
)))),
5266 -- Static_Offset_To_Top
5268 New_Occurrence_Of
(Standard_True
, Loc
),
5270 -- Offset_To_Top_Value
5272 Make_Integer_Literal
(Loc
, 0),
5274 -- Offset_To_Top_Func
5280 Unchecked_Convert_To
(RTE
(RE_Tag
), Sec_DT_Tag
)
5287 Name_ITable
:= New_External_Name
(Tname
, 'I');
5288 ITable
:= Make_Defining_Identifier
(Loc
, Name_ITable
);
5289 Set_Is_Statically_Allocated
(ITable
,
5290 Is_Library_Level_Tagged_Type
(Typ
));
5292 -- The table of interfaces is not constant; its slots are
5293 -- filled at run time by the IP routine using attribute
5294 -- 'Position to know the location of the tag components
5295 -- (and this attribute cannot be safely used before the
5296 -- object is initialized).
5299 Make_Object_Declaration
(Loc
,
5300 Defining_Identifier
=> ITable
,
5301 Aliased_Present
=> True,
5302 Constant_Present
=> False,
5303 Object_Definition
=>
5304 Make_Subtype_Indication
(Loc
,
5306 New_Occurrence_Of
(RTE
(RE_Interface_Data
), Loc
),
5308 Make_Index_Or_Discriminant_Constraint
(Loc
,
5309 Constraints
=> New_List
(
5310 Make_Integer_Literal
(Loc
, Num_Ifaces
)))),
5312 Expression
=> Make_Aggregate
(Loc
,
5313 Expressions
=> New_List
(
5314 Make_Integer_Literal
(Loc
, Num_Ifaces
),
5315 Make_Aggregate
(Loc
, TSD_Ifaces_List
)))));
5318 Make_Attribute_Definition_Clause
(Loc
,
5319 Name
=> New_Occurrence_Of
(ITable
, Loc
),
5320 Chars
=> Name_Alignment
,
5322 Make_Attribute_Reference
(Loc
,
5324 New_Occurrence_Of
(RTE
(RE_Integer_Address
), Loc
),
5325 Attribute_Name
=> Name_Alignment
)));
5328 Make_Attribute_Reference
(Loc
,
5329 Prefix
=> New_Occurrence_Of
(ITable
, Loc
),
5330 Attribute_Name
=> Name_Unchecked_Access
);
5334 Append_To
(TSD_Aggr_List
, Iface_Table_Node
);
5337 -- Generate the Select Specific Data table for synchronized types that
5338 -- implement synchronized interfaces. The size of the table is
5339 -- constrained by the number of non-predefined primitive operations.
5341 if RTE_Record_Component_Available
(RE_SSD
) then
5342 if Ada_Version
>= Ada_2005
5343 and then Has_DT
(Typ
)
5344 and then Is_Concurrent_Record_Type
(Typ
)
5345 and then Has_Interfaces
(Typ
)
5346 and then Nb_Prim
> 0
5347 and then not Is_Abstract_Type
(Typ
)
5348 and then not Is_Controlled
(Typ
)
5349 and then not Restriction_Active
(No_Dispatching_Calls
)
5350 and then not Restriction_Active
(No_Select_Statements
)
5353 Make_Object_Declaration
(Loc
,
5354 Defining_Identifier
=> SSD
,
5355 Aliased_Present
=> True,
5356 Object_Definition
=>
5357 Make_Subtype_Indication
(Loc
,
5358 Subtype_Mark
=> New_Occurrence_Of
(
5359 RTE
(RE_Select_Specific_Data
), Loc
),
5361 Make_Index_Or_Discriminant_Constraint
(Loc
,
5362 Constraints
=> New_List
(
5363 Make_Integer_Literal
(Loc
, Nb_Prim
))))));
5366 Make_Attribute_Definition_Clause
(Loc
,
5367 Name
=> New_Occurrence_Of
(SSD
, Loc
),
5368 Chars
=> Name_Alignment
,
5370 Make_Attribute_Reference
(Loc
,
5372 New_Occurrence_Of
(RTE
(RE_Integer_Address
), Loc
),
5373 Attribute_Name
=> Name_Alignment
)));
5375 -- This table is initialized by Make_Select_Specific_Data_Table,
5376 -- which calls Set_Entry_Index and Set_Prim_Op_Kind.
5378 Append_To
(TSD_Aggr_List
,
5379 Make_Attribute_Reference
(Loc
,
5380 Prefix
=> New_Occurrence_Of
(SSD
, Loc
),
5381 Attribute_Name
=> Name_Unchecked_Access
));
5383 Append_To
(TSD_Aggr_List
, Make_Null
(Loc
));
5387 -- Initialize the table of ancestor tags. In case of interface types
5388 -- this table is not needed.
5390 TSD_Tags_List
:= New_List
;
5392 -- If we are not statically allocating the dispatch table then we must
5393 -- fill position 0 with null because we still have not generated the
5396 if not Building_Static_DT
(Typ
)
5397 or else Is_Interface
(Typ
)
5399 Append_To
(TSD_Tags_List
,
5400 Unchecked_Convert_To
(RTE
(RE_Tag
),
5401 New_Occurrence_Of
(RTE
(RE_Null_Address
), Loc
)));
5403 -- Otherwise we can safely reference the tag
5406 Append_To
(TSD_Tags_List
,
5407 New_Occurrence_Of
(DT_Ptr
, Loc
));
5410 -- Fill the rest of the table with the tags of the ancestors
5413 Current_Typ
: Entity_Id
;
5414 Parent_Typ
: Entity_Id
;
5422 Parent_Typ
:= Etype
(Current_Typ
);
5424 if Is_Private_Type
(Parent_Typ
) then
5425 Parent_Typ
:= Full_View
(Base_Type
(Parent_Typ
));
5428 exit when Parent_Typ
= Current_Typ
;
5430 if Is_CPP_Class
(Parent_Typ
) then
5432 -- The tags defined in the C++ side will be inherited when
5433 -- the object is constructed (Exp_Ch3.Build_Init_Procedure)
5435 Append_To
(TSD_Tags_List
,
5436 Unchecked_Convert_To
(RTE
(RE_Tag
),
5437 New_Occurrence_Of
(RTE
(RE_Null_Address
), Loc
)));
5439 Append_To
(TSD_Tags_List
,
5441 (Node
(First_Elmt
(Access_Disp_Table
(Parent_Typ
))),
5446 Current_Typ
:= Parent_Typ
;
5449 pragma Assert
(Pos
= I_Depth
+ 1);
5452 Append_To
(TSD_Aggr_List
,
5453 Make_Aggregate
(Loc
,
5454 Expressions
=> TSD_Tags_List
));
5456 -- Build the TSD object
5459 Make_Object_Declaration
(Loc
,
5460 Defining_Identifier
=> TSD
,
5461 Aliased_Present
=> True,
5462 Constant_Present
=> Building_Static_DT
(Typ
),
5463 Object_Definition
=>
5464 Make_Subtype_Indication
(Loc
,
5465 Subtype_Mark
=> New_Occurrence_Of
(
5466 RTE
(RE_Type_Specific_Data
), Loc
),
5468 Make_Index_Or_Discriminant_Constraint
(Loc
,
5469 Constraints
=> New_List
(
5470 Make_Integer_Literal
(Loc
, I_Depth
)))),
5472 Expression
=> Make_Aggregate
(Loc
,
5473 Expressions
=> TSD_Aggr_List
)));
5475 Set_Is_True_Constant
(TSD
, Building_Static_DT
(Typ
));
5478 Make_Attribute_Definition_Clause
(Loc
,
5479 Name
=> New_Occurrence_Of
(TSD
, Loc
),
5480 Chars
=> Name_Alignment
,
5482 Make_Attribute_Reference
(Loc
,
5484 New_Occurrence_Of
(RTE
(RE_Integer_Address
), Loc
),
5485 Attribute_Name
=> Name_Alignment
)));
5487 -- Initialize or declare the dispatch table object
5489 if not Has_DT
(Typ
) then
5490 DT_Constr_List
:= New_List
;
5491 DT_Aggr_List
:= New_List
;
5496 Make_Attribute_Reference
(Loc
,
5497 Prefix
=> New_Occurrence_Of
(TSD
, Loc
),
5498 Attribute_Name
=> Name_Address
);
5500 Append_To
(DT_Constr_List
, New_Node
);
5501 Append_To
(DT_Aggr_List
, New_Copy
(New_Node
));
5502 Append_To
(DT_Aggr_List
, Make_Integer_Literal
(Loc
, 0));
5504 -- In case of locally defined tagged types we have already declared
5505 -- and uninitialized object for the dispatch table, which is now
5506 -- initialized by means of the following assignment:
5508 -- DT := (TSD'Address, 0);
5510 if not Building_Static_DT
(Typ
) then
5512 Make_Assignment_Statement
(Loc
,
5513 Name
=> New_Occurrence_Of
(DT
, Loc
),
5514 Expression
=> Make_Aggregate
(Loc
, DT_Aggr_List
)));
5516 -- In case of library level tagged types we declare and export now
5517 -- the constant object containing the dummy dispatch table. There
5518 -- is no need to declare the tag here because it has been previously
5519 -- declared by Make_Tags
5521 -- DT : aliased constant No_Dispatch_Table :=
5522 -- (NDT_TSD => TSD'Address;
5523 -- NDT_Prims_Ptr => 0);
5524 -- for DT'Alignment use Address'Alignment;
5528 Make_Object_Declaration
(Loc
,
5529 Defining_Identifier
=> DT
,
5530 Aliased_Present
=> True,
5531 Constant_Present
=> True,
5532 Object_Definition
=>
5533 New_Occurrence_Of
(RTE
(RE_No_Dispatch_Table_Wrapper
), Loc
),
5534 Expression
=> Make_Aggregate
(Loc
, DT_Aggr_List
)));
5537 Make_Attribute_Definition_Clause
(Loc
,
5538 Name
=> New_Occurrence_Of
(DT
, Loc
),
5539 Chars
=> Name_Alignment
,
5541 Make_Attribute_Reference
(Loc
,
5543 New_Occurrence_Of
(RTE
(RE_Integer_Address
), Loc
),
5544 Attribute_Name
=> Name_Alignment
)));
5546 Export_DT
(Typ
, DT
);
5549 -- Common case: Typ has a dispatch table
5553 -- Predef_Prims : Address_Array (1 .. Default_Prim_Ops_Count) :=
5554 -- (predef-prim-op-1'address,
5555 -- predef-prim-op-2'address,
5557 -- predef-prim-op-n'address);
5558 -- for Predef_Prims'Alignment use Address'Alignment
5560 -- DT : Dispatch_Table (Nb_Prims) :=
5561 -- (Signature => <sig-value>,
5562 -- Tag_Kind => <tag_kind-value>,
5563 -- Predef_Prims => Predef_Prims'First'Address,
5564 -- Offset_To_Top => 0,
5565 -- TSD => TSD'Address;
5566 -- Prims_Ptr => (prim-op-1'address,
5567 -- prim-op-2'address,
5569 -- prim-op-n'address));
5570 -- for DT'Alignment use Address'Alignment
5577 if not Building_Static_DT
(Typ
) then
5578 Nb_Predef_Prims
:= Max_Predef_Prims
;
5581 Prim_Elmt
:= First_Elmt
(Primitive_Operations
(Typ
));
5582 while Present
(Prim_Elmt
) loop
5583 Prim
:= Node
(Prim_Elmt
);
5585 if Is_Predefined_Dispatching_Operation
(Prim
)
5586 and then not Is_Abstract_Subprogram
(Prim
)
5588 Pos
:= UI_To_Int
(DT_Position
(Prim
));
5590 if Pos
> Nb_Predef_Prims
then
5591 Nb_Predef_Prims
:= Pos
;
5595 Next_Elmt
(Prim_Elmt
);
5601 (Nat
range 1 .. Nb_Predef_Prims
) of Entity_Id
;
5606 Prim_Ops_Aggr_List
:= New_List
;
5608 Prim_Table
:= (others => Empty
);
5610 if Building_Static_DT
(Typ
) then
5611 Prim_Elmt
:= First_Elmt
(Primitive_Operations
(Typ
));
5612 while Present
(Prim_Elmt
) loop
5613 Prim
:= Node
(Prim_Elmt
);
5615 if Is_Predefined_Dispatching_Operation
(Prim
)
5616 and then not Is_Abstract_Subprogram
(Prim
)
5617 and then not Is_Eliminated
(Prim
)
5618 and then not Present
(Prim_Table
5619 (UI_To_Int
(DT_Position
(Prim
))))
5621 E
:= Ultimate_Alias
(Prim
);
5622 pragma Assert
(not Is_Abstract_Subprogram
(E
));
5623 Prim_Table
(UI_To_Int
(DT_Position
(Prim
))) := E
;
5626 Next_Elmt
(Prim_Elmt
);
5630 for J
in Prim_Table
'Range loop
5631 if Present
(Prim_Table
(J
)) then
5633 Unchecked_Convert_To
(RTE
(RE_Prim_Ptr
),
5634 Make_Attribute_Reference
(Loc
,
5636 New_Occurrence_Of
(Prim_Table
(J
), Loc
),
5637 Attribute_Name
=> Name_Unrestricted_Access
));
5639 New_Node
:= Make_Null
(Loc
);
5642 Append_To
(Prim_Ops_Aggr_List
, New_Node
);
5646 Make_Aggregate
(Loc
,
5647 Expressions
=> Prim_Ops_Aggr_List
);
5650 Make_Subtype_Declaration
(Loc
,
5651 Defining_Identifier
=> Make_Temporary
(Loc
, 'S'),
5652 Subtype_Indication
=>
5653 New_Occurrence_Of
(RTE
(RE_Address_Array
), Loc
));
5655 Append_To
(Result
, Decl
);
5658 Make_Object_Declaration
(Loc
,
5659 Defining_Identifier
=> Predef_Prims
,
5660 Aliased_Present
=> True,
5661 Constant_Present
=> Building_Static_DT
(Typ
),
5662 Object_Definition
=>
5663 New_Occurrence_Of
(Defining_Identifier
(Decl
), Loc
),
5664 Expression
=> New_Node
));
5666 -- Remember aggregates initializing dispatch tables
5668 Append_Elmt
(New_Node
, DT_Aggr
);
5671 Make_Attribute_Definition_Clause
(Loc
,
5672 Name
=> New_Occurrence_Of
(Predef_Prims
, Loc
),
5673 Chars
=> Name_Alignment
,
5675 Make_Attribute_Reference
(Loc
,
5677 New_Occurrence_Of
(RTE
(RE_Integer_Address
), Loc
),
5678 Attribute_Name
=> Name_Alignment
)));
5682 -- Stage 1: Initialize the discriminant and the record components
5684 DT_Constr_List
:= New_List
;
5685 DT_Aggr_List
:= New_List
;
5687 -- Num_Prims. If the tagged type has no primitives we add a dummy
5688 -- slot whose address will be the tag of this type.
5691 New_Node
:= Make_Integer_Literal
(Loc
, 1);
5693 New_Node
:= Make_Integer_Literal
(Loc
, Nb_Prim
);
5696 Append_To
(DT_Constr_List
, New_Node
);
5697 Append_To
(DT_Aggr_List
, New_Copy
(New_Node
));
5701 if RTE_Record_Component_Available
(RE_Signature
) then
5702 Append_To
(DT_Aggr_List
,
5703 New_Occurrence_Of
(RTE
(RE_Primary_DT
), Loc
));
5708 if RTE_Record_Component_Available
(RE_Tag_Kind
) then
5709 Append_To
(DT_Aggr_List
, Tagged_Kind
(Typ
));
5714 Append_To
(DT_Aggr_List
,
5715 Make_Attribute_Reference
(Loc
,
5716 Prefix
=> New_Occurrence_Of
(Predef_Prims
, Loc
),
5717 Attribute_Name
=> Name_Address
));
5721 Append_To
(DT_Aggr_List
, Make_Integer_Literal
(Loc
, 0));
5725 Append_To
(DT_Aggr_List
,
5726 Make_Attribute_Reference
(Loc
,
5727 Prefix
=> New_Occurrence_Of
(TSD
, Loc
),
5728 Attribute_Name
=> Name_Address
));
5730 -- Stage 2: Initialize the table of user-defined primitive operations
5732 Prim_Ops_Aggr_List
:= New_List
;
5735 Append_To
(Prim_Ops_Aggr_List
, Make_Null
(Loc
));
5737 elsif not Building_Static_DT
(Typ
) then
5738 for J
in 1 .. Nb_Prim
loop
5739 Append_To
(Prim_Ops_Aggr_List
, Make_Null
(Loc
));
5744 CPP_Nb_Prims
: constant Nat
:= CPP_Num_Prims
(Typ
);
5747 Prim_Elmt
: Elmt_Id
;
5749 Prim_Table
: array (Nat
range 1 .. Nb_Prim
) of Entity_Id
;
5752 Prim_Table
:= (others => Empty
);
5754 Prim_Elmt
:= First_Elmt
(Primitive_Operations
(Typ
));
5755 while Present
(Prim_Elmt
) loop
5756 Prim
:= Node
(Prim_Elmt
);
5758 -- Retrieve the ultimate alias of the primitive for proper
5759 -- handling of renamings and eliminated primitives.
5761 E
:= Ultimate_Alias
(Prim
);
5762 Prim_Pos
:= UI_To_Int
(DT_Position
(E
));
5764 -- Skip predefined primitives because they are located in a
5765 -- separate dispatch table.
5767 if not Is_Predefined_Dispatching_Operation
(Prim
)
5768 and then not Is_Predefined_Dispatching_Operation
(E
)
5770 -- Skip entities with attribute Interface_Alias because
5771 -- those are only required to build secondary dispatch
5774 and then not Present
(Interface_Alias
(Prim
))
5776 -- Skip abstract and eliminated primitives
5778 and then not Is_Abstract_Subprogram
(E
)
5779 and then not Is_Eliminated
(E
)
5781 -- For derivations of CPP types skip primitives located in
5782 -- the C++ part of the dispatch table because their slots
5783 -- are initialized by the IC routine.
5785 and then (not Is_CPP_Class
(Root_Type
(Typ
))
5786 or else Prim_Pos
> CPP_Nb_Prims
)
5788 -- Skip ignored Ghost subprograms as those will be removed
5789 -- from the executable.
5791 and then not Is_Ignored_Ghost_Entity
(E
)
5794 (UI_To_Int
(DT_Position
(Prim
)) <= Nb_Prim
);
5796 Prim_Table
(UI_To_Int
(DT_Position
(Prim
))) := E
;
5799 Next_Elmt
(Prim_Elmt
);
5802 for J
in Prim_Table
'Range loop
5803 if Present
(Prim_Table
(J
)) then
5805 Unchecked_Convert_To
(RTE
(RE_Prim_Ptr
),
5806 Make_Attribute_Reference
(Loc
,
5808 New_Occurrence_Of
(Prim_Table
(J
), Loc
),
5809 Attribute_Name
=> Name_Unrestricted_Access
));
5811 New_Node
:= Make_Null
(Loc
);
5814 Append_To
(Prim_Ops_Aggr_List
, New_Node
);
5820 Make_Aggregate
(Loc
,
5821 Expressions
=> Prim_Ops_Aggr_List
);
5823 Append_To
(DT_Aggr_List
, New_Node
);
5825 -- Remember aggregates initializing dispatch tables
5827 Append_Elmt
(New_Node
, DT_Aggr
);
5829 -- In case of locally defined tagged types we have already declared
5830 -- and uninitialized object for the dispatch table, which is now
5831 -- initialized by means of an assignment.
5833 if not Building_Static_DT
(Typ
) then
5835 Make_Assignment_Statement
(Loc
,
5836 Name
=> New_Occurrence_Of
(DT
, Loc
),
5837 Expression
=> Make_Aggregate
(Loc
, DT_Aggr_List
)));
5839 -- In case of library level tagged types we declare now and export
5840 -- the constant object containing the dispatch table.
5844 Make_Object_Declaration
(Loc
,
5845 Defining_Identifier
=> DT
,
5846 Aliased_Present
=> True,
5847 Constant_Present
=> True,
5848 Object_Definition
=>
5849 Make_Subtype_Indication
(Loc
,
5850 Subtype_Mark
=> New_Occurrence_Of
5851 (RTE
(RE_Dispatch_Table_Wrapper
), Loc
),
5852 Constraint
=> Make_Index_Or_Discriminant_Constraint
(Loc
,
5853 Constraints
=> DT_Constr_List
)),
5854 Expression
=> Make_Aggregate
(Loc
, DT_Aggr_List
)));
5857 Make_Attribute_Definition_Clause
(Loc
,
5858 Name
=> New_Occurrence_Of
(DT
, Loc
),
5859 Chars
=> Name_Alignment
,
5861 Make_Attribute_Reference
(Loc
,
5863 New_Occurrence_Of
(RTE
(RE_Integer_Address
), Loc
),
5864 Attribute_Name
=> Name_Alignment
)));
5866 Export_DT
(Typ
, DT
);
5870 -- Initialize the table of ancestor tags if not building static
5873 if not Building_Static_DT
(Typ
)
5874 and then not Is_Interface
(Typ
)
5875 and then not Is_CPP_Class
(Typ
)
5878 Make_Assignment_Statement
(Loc
,
5880 Make_Indexed_Component
(Loc
,
5882 Make_Selected_Component
(Loc
,
5883 Prefix
=> New_Occurrence_Of
(TSD
, Loc
),
5886 (RTE_Record_Component
(RE_Tags_Table
), Loc
)),
5888 New_List
(Make_Integer_Literal
(Loc
, 0))),
5892 (Node
(First_Elmt
(Access_Disp_Table
(Typ
))), Loc
)));
5895 -- Inherit the dispatch tables of the parent. There is no need to
5896 -- inherit anything from the parent when building static dispatch tables
5897 -- because the whole dispatch table (including inherited primitives) has
5898 -- been already built.
5900 if Building_Static_DT
(Typ
) then
5903 -- If the ancestor is a CPP_Class type we inherit the dispatch tables
5904 -- in the init proc, and we don't need to fill them in here.
5906 elsif Is_CPP_Class
(Parent_Typ
) then
5909 -- Otherwise we fill in the dispatch tables here
5912 if Typ
/= Parent_Typ
5913 and then not Is_Interface
(Typ
)
5914 and then not Restriction_Active
(No_Dispatching_Calls
)
5916 -- Inherit the dispatch table
5918 if not Is_Interface
(Typ
)
5919 and then not Is_Interface
(Parent_Typ
)
5920 and then not Is_CPP_Class
(Parent_Typ
)
5923 Nb_Prims
: constant Int
:=
5924 UI_To_Int
(DT_Entry_Count
5925 (First_Tag_Component
(Parent_Typ
)));
5928 Append_To
(Elab_Code
,
5929 Build_Inherit_Predefined_Prims
(Loc
,
5935 (Access_Disp_Table
(Parent_Typ
)))), Loc
),
5941 (Access_Disp_Table
(Typ
)))), Loc
)));
5943 if Nb_Prims
/= 0 then
5944 Append_To
(Elab_Code
,
5945 Build_Inherit_Prims
(Loc
,
5951 (Access_Disp_Table
(Parent_Typ
))), Loc
),
5952 New_Tag_Node
=> New_Occurrence_Of
(DT_Ptr
, Loc
),
5953 Num_Prims
=> Nb_Prims
));
5958 -- Inherit the secondary dispatch tables of the ancestor
5960 if not Is_CPP_Class
(Parent_Typ
) then
5962 Sec_DT_Ancestor
: Elmt_Id
:=
5968 Sec_DT_Typ
: Elmt_Id
:=
5972 (Access_Disp_Table
(Typ
))));
5974 procedure Copy_Secondary_DTs
(Typ
: Entity_Id
);
5975 -- Local procedure required to climb through the ancestors
5976 -- and copy the contents of all their secondary dispatch
5979 ------------------------
5980 -- Copy_Secondary_DTs --
5981 ------------------------
5983 procedure Copy_Secondary_DTs
(Typ
: Entity_Id
) is
5988 -- Climb to the ancestor (if any) handling private types
5990 if Present
(Full_View
(Etype
(Typ
))) then
5991 if Full_View
(Etype
(Typ
)) /= Typ
then
5992 Copy_Secondary_DTs
(Full_View
(Etype
(Typ
)));
5995 elsif Etype
(Typ
) /= Typ
then
5996 Copy_Secondary_DTs
(Etype
(Typ
));
5999 if Present
(Interfaces
(Typ
))
6000 and then not Is_Empty_Elmt_List
(Interfaces
(Typ
))
6002 Iface
:= First_Elmt
(Interfaces
(Typ
));
6003 E
:= First_Entity
(Typ
);
6005 and then Present
(Node
(Sec_DT_Ancestor
))
6006 and then Ekind
(Node
(Sec_DT_Ancestor
)) = E_Constant
6008 if Is_Tag
(E
) and then Chars
(E
) /= Name_uTag
then
6010 Num_Prims
: constant Int
:=
6011 UI_To_Int
(DT_Entry_Count
(E
));
6014 if not Is_Interface
(Etype
(Typ
)) then
6016 -- Inherit first secondary dispatch table
6018 Append_To
(Elab_Code
,
6019 Build_Inherit_Predefined_Prims
(Loc
,
6021 Unchecked_Convert_To
(RTE
(RE_Tag
),
6024 (Next_Elmt
(Sec_DT_Ancestor
)),
6027 Unchecked_Convert_To
(RTE
(RE_Tag
),
6029 (Node
(Next_Elmt
(Sec_DT_Typ
)),
6032 if Num_Prims
/= 0 then
6033 Append_To
(Elab_Code
,
6034 Build_Inherit_Prims
(Loc
,
6035 Typ
=> Node
(Iface
),
6037 Unchecked_Convert_To
6040 (Node
(Sec_DT_Ancestor
),
6043 Unchecked_Convert_To
6046 (Node
(Sec_DT_Typ
), Loc
)),
6047 Num_Prims
=> Num_Prims
));
6051 Next_Elmt
(Sec_DT_Ancestor
);
6052 Next_Elmt
(Sec_DT_Typ
);
6054 -- Skip the secondary dispatch table of
6055 -- predefined primitives
6057 Next_Elmt
(Sec_DT_Ancestor
);
6058 Next_Elmt
(Sec_DT_Typ
);
6060 if not Is_Interface
(Etype
(Typ
)) then
6062 -- Inherit second secondary dispatch table
6064 Append_To
(Elab_Code
,
6065 Build_Inherit_Predefined_Prims
(Loc
,
6067 Unchecked_Convert_To
(RTE
(RE_Tag
),
6070 (Next_Elmt
(Sec_DT_Ancestor
)),
6073 Unchecked_Convert_To
(RTE
(RE_Tag
),
6075 (Node
(Next_Elmt
(Sec_DT_Typ
)),
6078 if Num_Prims
/= 0 then
6079 Append_To
(Elab_Code
,
6080 Build_Inherit_Prims
(Loc
,
6081 Typ
=> Node
(Iface
),
6083 Unchecked_Convert_To
6086 (Node
(Sec_DT_Ancestor
),
6089 Unchecked_Convert_To
6092 (Node
(Sec_DT_Typ
), Loc
)),
6093 Num_Prims
=> Num_Prims
));
6098 Next_Elmt
(Sec_DT_Ancestor
);
6099 Next_Elmt
(Sec_DT_Typ
);
6101 -- Skip the secondary dispatch table of
6102 -- predefined primitives
6104 Next_Elmt
(Sec_DT_Ancestor
);
6105 Next_Elmt
(Sec_DT_Typ
);
6113 end Copy_Secondary_DTs
;
6116 if Present
(Node
(Sec_DT_Ancestor
))
6117 and then Ekind
(Node
(Sec_DT_Ancestor
)) = E_Constant
6119 -- Handle private types
6121 if Present
(Full_View
(Typ
)) then
6122 Copy_Secondary_DTs
(Full_View
(Typ
));
6124 Copy_Secondary_DTs
(Typ
);
6132 -- Generate code to check if the external tag of this type is the same
6133 -- as the external tag of some other declaration.
6135 -- Check_TSD (TSD'Unrestricted_Access);
6137 -- This check is a consequence of AI05-0113-1/06, so it officially
6138 -- applies to Ada 2005 (and Ada 2012). It might be argued that it is
6139 -- a desirable check to add in Ada 95 mode, but we hesitate to make
6140 -- this change, as it would be incompatible, and could conceivably
6141 -- cause a problem in existing Aa 95 code.
6143 -- We check for No_Run_Time_Mode here, because we do not want to pick
6144 -- up the RE_Check_TSD entity and call it in No_Run_Time mode.
6146 if not No_Run_Time_Mode
6147 and then Ada_Version
>= Ada_2005
6148 and then RTE_Available
(RE_Check_TSD
)
6149 and then not Duplicated_Tag_Checks_Suppressed
(Typ
)
6151 Append_To
(Elab_Code
,
6152 Make_Procedure_Call_Statement
(Loc
,
6154 New_Occurrence_Of
(RTE
(RE_Check_TSD
), Loc
),
6155 Parameter_Associations
=> New_List
(
6156 Make_Attribute_Reference
(Loc
,
6157 Prefix
=> New_Occurrence_Of
(TSD
, Loc
),
6158 Attribute_Name
=> Name_Unchecked_Access
))));
6161 -- Generate code to register the Tag in the External_Tag hash table for
6162 -- the pure Ada type only.
6164 -- Register_Tag (Dt_Ptr);
6166 -- Skip this action in the following cases:
6167 -- 1) if Register_Tag is not available.
6168 -- 2) in No_Run_Time mode.
6169 -- 3) if Typ is not defined at the library level (this is required
6170 -- to avoid adding concurrency control to the hash table used
6171 -- by the run-time to register the tags).
6173 if not No_Run_Time_Mode
6174 and then Is_Library_Level_Entity
(Typ
)
6175 and then RTE_Available
(RE_Register_Tag
)
6177 Append_To
(Elab_Code
,
6178 Make_Procedure_Call_Statement
(Loc
,
6180 New_Occurrence_Of
(RTE
(RE_Register_Tag
), Loc
),
6181 Parameter_Associations
=>
6182 New_List
(New_Occurrence_Of
(DT_Ptr
, Loc
))));
6185 if not Is_Empty_List
(Elab_Code
) then
6186 Append_List_To
(Result
, Elab_Code
);
6189 -- Populate the two auxiliary tables used for dispatching asynchronous,
6190 -- conditional and timed selects for synchronized types that implement
6191 -- a limited interface. Skip this step in Ravenscar profile or when
6192 -- general dispatching is forbidden.
6194 if Ada_Version
>= Ada_2005
6195 and then Is_Concurrent_Record_Type
(Typ
)
6196 and then Has_Interfaces
(Typ
)
6197 and then not Restriction_Active
(No_Dispatching_Calls
)
6198 and then not Restriction_Active
(No_Select_Statements
)
6200 Append_List_To
(Result
,
6201 Make_Select_Specific_Data_Table
(Typ
));
6204 -- Remember entities containing dispatch tables
6206 Append_Elmt
(Predef_Prims
, DT_Decl
);
6207 Append_Elmt
(DT
, DT_Decl
);
6209 Analyze_List
(Result
, Suppress
=> All_Checks
);
6210 Set_Has_Dispatch_Table
(Typ
);
6212 -- Mark entities containing dispatch tables. Required by the backend to
6213 -- handle them properly.
6215 if Has_DT
(Typ
) then
6220 -- Object declarations
6222 Elmt
:= First_Elmt
(DT_Decl
);
6223 while Present
(Elmt
) loop
6224 Set_Is_Dispatch_Table_Entity
(Node
(Elmt
));
6225 pragma Assert
(Ekind
(Etype
(Node
(Elmt
))) = E_Array_Subtype
6226 or else Ekind
(Etype
(Node
(Elmt
))) = E_Record_Subtype
);
6227 Set_Is_Dispatch_Table_Entity
(Etype
(Node
(Elmt
)));
6231 -- Aggregates initializing dispatch tables
6233 Elmt
:= First_Elmt
(DT_Aggr
);
6234 while Present
(Elmt
) loop
6235 Set_Is_Dispatch_Table_Entity
(Etype
(Node
(Elmt
)));
6241 <<Early_Exit_For_SCIL
>>
6243 -- Register the tagged type in the call graph nodes table
6245 Register_CG_Node
(Typ
);
6247 Ghost_Mode
:= Save_Ghost_Mode
;
6251 -------------------------------------
6252 -- Make_Select_Specific_Data_Table --
6253 -------------------------------------
6255 function Make_Select_Specific_Data_Table
6256 (Typ
: Entity_Id
) return List_Id
6258 Assignments
: constant List_Id
:= New_List
;
6259 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
6261 Conc_Typ
: Entity_Id
;
6264 Prim_Als
: Entity_Id
;
6265 Prim_Elmt
: Elmt_Id
;
6269 type Examined_Array
is array (Int
range <>) of Boolean;
6271 function Find_Entry_Index
(E
: Entity_Id
) return Uint
;
6272 -- Given an entry, find its index in the visible declarations of the
6273 -- corresponding concurrent type of Typ.
6275 ----------------------
6276 -- Find_Entry_Index --
6277 ----------------------
6279 function Find_Entry_Index
(E
: Entity_Id
) return Uint
is
6280 Index
: Uint
:= Uint_1
;
6281 Subp_Decl
: Entity_Id
;
6285 and then not Is_Empty_List
(Decls
)
6287 Subp_Decl
:= First
(Decls
);
6288 while Present
(Subp_Decl
) loop
6289 if Nkind
(Subp_Decl
) = N_Entry_Declaration
then
6290 if Defining_Identifier
(Subp_Decl
) = E
then
6302 end Find_Entry_Index
;
6308 -- Start of processing for Make_Select_Specific_Data_Table
6311 pragma Assert
(not Restriction_Active
(No_Dispatching_Calls
));
6313 if Present
(Corresponding_Concurrent_Type
(Typ
)) then
6314 Conc_Typ
:= Corresponding_Concurrent_Type
(Typ
);
6316 if Present
(Full_View
(Conc_Typ
)) then
6317 Conc_Typ
:= Full_View
(Conc_Typ
);
6320 if Ekind
(Conc_Typ
) = E_Protected_Type
then
6321 Decls
:= Visible_Declarations
(Protected_Definition
(
6322 Parent
(Conc_Typ
)));
6324 pragma Assert
(Ekind
(Conc_Typ
) = E_Task_Type
);
6325 Decls
:= Visible_Declarations
(Task_Definition
(
6326 Parent
(Conc_Typ
)));
6330 -- Count the non-predefined primitive operations
6332 Prim_Elmt
:= First_Elmt
(Primitive_Operations
(Typ
));
6333 while Present
(Prim_Elmt
) loop
6334 Prim
:= Node
(Prim_Elmt
);
6336 if not (Is_Predefined_Dispatching_Operation
(Prim
)
6337 or else Is_Predefined_Dispatching_Alias
(Prim
))
6339 Nb_Prim
:= Nb_Prim
+ 1;
6342 Next_Elmt
(Prim_Elmt
);
6346 Examined
: Examined_Array
(1 .. Nb_Prim
) := (others => False);
6349 Prim_Elmt
:= First_Elmt
(Primitive_Operations
(Typ
));
6350 while Present
(Prim_Elmt
) loop
6351 Prim
:= Node
(Prim_Elmt
);
6353 -- Look for primitive overriding an abstract interface subprogram
6355 if Present
(Interface_Alias
(Prim
))
6358 (Find_Dispatching_Type
(Interface_Alias
(Prim
)), Typ
,
6359 Use_Full_View
=> True)
6360 and then not Examined
(UI_To_Int
(DT_Position
(Alias
(Prim
))))
6362 Prim_Pos
:= DT_Position
(Alias
(Prim
));
6363 pragma Assert
(UI_To_Int
(Prim_Pos
) <= Nb_Prim
);
6364 Examined
(UI_To_Int
(Prim_Pos
)) := True;
6366 -- Set the primitive operation kind regardless of subprogram
6368 -- Ada.Tags.Set_Prim_Op_Kind (DT_Ptr, <position>, <kind>);
6370 if Tagged_Type_Expansion
then
6373 (Node
(First_Elmt
(Access_Disp_Table
(Typ
))), Loc
);
6377 Make_Attribute_Reference
(Loc
,
6378 Prefix
=> New_Occurrence_Of
(Typ
, Loc
),
6379 Attribute_Name
=> Name_Tag
);
6382 Append_To
(Assignments
,
6383 Make_Procedure_Call_Statement
(Loc
,
6384 Name
=> New_Occurrence_Of
(RTE
(RE_Set_Prim_Op_Kind
), Loc
),
6385 Parameter_Associations
=> New_List
(
6387 Make_Integer_Literal
(Loc
, Prim_Pos
),
6388 Prim_Op_Kind
(Alias
(Prim
), Typ
))));
6390 -- Retrieve the root of the alias chain
6392 Prim_Als
:= Ultimate_Alias
(Prim
);
6394 -- In the case of an entry wrapper, set the entry index
6396 if Ekind
(Prim
) = E_Procedure
6397 and then Is_Primitive_Wrapper
(Prim_Als
)
6398 and then Ekind
(Wrapped_Entity
(Prim_Als
)) = E_Entry
6401 -- Ada.Tags.Set_Entry_Index
6402 -- (DT_Ptr, <position>, <index>);
6404 if Tagged_Type_Expansion
then
6407 (Node
(First_Elmt
(Access_Disp_Table
(Typ
))), Loc
);
6410 Make_Attribute_Reference
(Loc
,
6411 Prefix
=> New_Occurrence_Of
(Typ
, Loc
),
6412 Attribute_Name
=> Name_Tag
);
6415 Append_To
(Assignments
,
6416 Make_Procedure_Call_Statement
(Loc
,
6418 New_Occurrence_Of
(RTE
(RE_Set_Entry_Index
), Loc
),
6419 Parameter_Associations
=> New_List
(
6421 Make_Integer_Literal
(Loc
, Prim_Pos
),
6422 Make_Integer_Literal
(Loc
,
6423 Find_Entry_Index
(Wrapped_Entity
(Prim_Als
))))));
6427 Next_Elmt
(Prim_Elmt
);
6432 end Make_Select_Specific_Data_Table
;
6438 function Make_Tags
(Typ
: Entity_Id
) return List_Id
is
6439 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
6440 Result
: constant List_Id
:= New_List
;
6443 (Tag_Typ
: Entity_Id
;
6445 Is_Secondary_DT
: Boolean);
6446 -- Import the dispatch table DT of tagged type Tag_Typ. Required to
6447 -- generate forward references and statically allocate the table. For
6448 -- primary dispatch tables that require no dispatch table generate:
6450 -- DT : static aliased constant Non_Dispatch_Table_Wrapper;
6451 -- pragma Import (Ada, DT);
6453 -- Otherwise generate:
6455 -- DT : static aliased constant Dispatch_Table_Wrapper (Nb_Prim);
6456 -- pragma Import (Ada, DT);
6463 (Tag_Typ
: Entity_Id
;
6465 Is_Secondary_DT
: Boolean)
6467 DT_Constr_List
: List_Id
;
6471 Set_Is_Imported
(DT
);
6472 Set_Ekind
(DT
, E_Constant
);
6473 Set_Related_Type
(DT
, Typ
);
6475 -- The scope must be set now to call Get_External_Name
6477 Set_Scope
(DT
, Current_Scope
);
6479 Get_External_Name
(DT
);
6480 Set_Interface_Name
(DT
,
6481 Make_String_Literal
(Loc
, Strval
=> String_From_Name_Buffer
));
6483 -- Ensure proper Sprint output of this implicit importation
6485 Set_Is_Internal
(DT
);
6487 -- Save this entity to allow Make_DT to generate its exportation
6489 Append_Elmt
(DT
, Dispatch_Table_Wrappers
(Typ
));
6491 -- No dispatch table required
6493 if not Is_Secondary_DT
and then not Has_DT
(Tag_Typ
) then
6495 Make_Object_Declaration
(Loc
,
6496 Defining_Identifier
=> DT
,
6497 Aliased_Present
=> True,
6498 Constant_Present
=> True,
6499 Object_Definition
=>
6501 (RTE
(RE_No_Dispatch_Table_Wrapper
), Loc
)));
6504 -- Calculate the number of primitives of the dispatch table and
6505 -- the size of the Type_Specific_Data record.
6508 UI_To_Int
(DT_Entry_Count
(First_Tag_Component
(Tag_Typ
)));
6510 -- If the tagged type has no primitives we add a dummy slot whose
6511 -- address will be the tag of this type.
6515 New_List
(Make_Integer_Literal
(Loc
, 1));
6518 New_List
(Make_Integer_Literal
(Loc
, Nb_Prim
));
6522 Make_Object_Declaration
(Loc
,
6523 Defining_Identifier
=> DT
,
6524 Aliased_Present
=> True,
6525 Constant_Present
=> True,
6526 Object_Definition
=>
6527 Make_Subtype_Indication
(Loc
,
6529 New_Occurrence_Of
(RTE
(RE_Dispatch_Table_Wrapper
), Loc
),
6530 Constraint
=> Make_Index_Or_Discriminant_Constraint
(Loc
,
6531 Constraints
=> DT_Constr_List
))));
6537 Tname
: constant Name_Id
:= Chars
(Typ
);
6538 AI_Tag_Comp
: Elmt_Id
;
6539 DT
: Node_Id
:= Empty
;
6541 Predef_Prims_Ptr
: Node_Id
;
6542 Iface_DT
: Node_Id
:= Empty
;
6543 Iface_DT_Ptr
: Node_Id
;
6547 Typ_Comps
: Elist_Id
;
6549 -- Start of processing for Make_Tags
6552 pragma Assert
(No
(Access_Disp_Table
(Typ
)));
6553 Set_Access_Disp_Table
(Typ
, New_Elmt_List
);
6555 -- 1) Generate the primary tag entities
6557 -- Primary dispatch table containing user-defined primitives
6559 DT_Ptr
:= Make_Defining_Identifier
(Loc
, New_External_Name
(Tname
, 'P'));
6560 Set_Etype
(DT_Ptr
, RTE
(RE_Tag
));
6561 Append_Elmt
(DT_Ptr
, Access_Disp_Table
(Typ
));
6563 -- Minimum decoration
6565 Set_Ekind
(DT_Ptr
, E_Variable
);
6566 Set_Related_Type
(DT_Ptr
, Typ
);
6568 -- Notify back end that the types are associated with a dispatch table
6570 Set_Is_Dispatch_Table_Entity
(RTE
(RE_Prim_Ptr
));
6571 Set_Is_Dispatch_Table_Entity
(RTE
(RE_Predef_Prims_Table_Ptr
));
6573 -- For CPP types there is no need to build the dispatch tables since
6574 -- they are imported from the C++ side. If the CPP type has an IP then
6575 -- we declare now the variable that will store the copy of the C++ tag.
6576 -- If the CPP type is an interface, we need the variable as well because
6577 -- it becomes the pointer to the corresponding secondary table.
6579 if Is_CPP_Class
(Typ
) then
6580 if Has_CPP_Constructors
(Typ
) or else Is_Interface
(Typ
) then
6582 Make_Object_Declaration
(Loc
,
6583 Defining_Identifier
=> DT_Ptr
,
6584 Object_Definition
=> New_Occurrence_Of
(RTE
(RE_Tag
), Loc
),
6586 Unchecked_Convert_To
(RTE
(RE_Tag
),
6587 New_Occurrence_Of
(RTE
(RE_Null_Address
), Loc
))));
6589 Set_Is_Statically_Allocated
(DT_Ptr
,
6590 Is_Library_Level_Tagged_Type
(Typ
));
6596 -- Primary dispatch table containing predefined primitives
6599 Make_Defining_Identifier
(Loc
,
6600 Chars
=> New_External_Name
(Tname
, 'Y'));
6601 Set_Etype
(Predef_Prims_Ptr
, RTE
(RE_Address
));
6602 Append_Elmt
(Predef_Prims_Ptr
, Access_Disp_Table
(Typ
));
6604 -- Import the forward declaration of the Dispatch Table wrapper
6605 -- record (Make_DT will take care of exporting it).
6607 if Building_Static_DT
(Typ
) then
6608 Set_Dispatch_Table_Wrappers
(Typ
, New_Elmt_List
);
6611 Make_Defining_Identifier
(Loc
,
6612 Chars
=> New_External_Name
(Tname
, 'T'));
6614 Import_DT
(Typ
, DT
, Is_Secondary_DT
=> False);
6616 if Has_DT
(Typ
) then
6618 Make_Object_Declaration
(Loc
,
6619 Defining_Identifier
=> DT_Ptr
,
6620 Constant_Present
=> True,
6621 Object_Definition
=>
6622 New_Occurrence_Of
(RTE
(RE_Tag
), Loc
),
6624 Unchecked_Convert_To
(RTE
(RE_Tag
),
6625 Make_Attribute_Reference
(Loc
,
6627 Make_Selected_Component
(Loc
,
6628 Prefix
=> New_Occurrence_Of
(DT
, Loc
),
6631 (RTE_Record_Component
(RE_Prims_Ptr
), Loc
)),
6632 Attribute_Name
=> Name_Address
))));
6634 -- Generate the SCIL node for the previous object declaration
6635 -- because it has a tag initialization.
6637 if Generate_SCIL
then
6639 Make_SCIL_Dispatch_Table_Tag_Init
(Sloc
(Last
(Result
)));
6640 Set_SCIL_Entity
(New_Node
, Typ
);
6641 Set_SCIL_Node
(Last
(Result
), New_Node
);
6645 Make_Object_Declaration
(Loc
,
6646 Defining_Identifier
=> Predef_Prims_Ptr
,
6647 Constant_Present
=> True,
6648 Object_Definition
=>
6649 New_Occurrence_Of
(RTE
(RE_Address
), Loc
),
6651 Make_Attribute_Reference
(Loc
,
6653 Make_Selected_Component
(Loc
,
6654 Prefix
=> New_Occurrence_Of
(DT
, Loc
),
6657 (RTE_Record_Component
(RE_Predef_Prims
), Loc
)),
6658 Attribute_Name
=> Name_Address
)));
6660 -- No dispatch table required
6664 Make_Object_Declaration
(Loc
,
6665 Defining_Identifier
=> DT_Ptr
,
6666 Constant_Present
=> True,
6667 Object_Definition
=>
6668 New_Occurrence_Of
(RTE
(RE_Tag
), Loc
),
6670 Unchecked_Convert_To
(RTE
(RE_Tag
),
6671 Make_Attribute_Reference
(Loc
,
6673 Make_Selected_Component
(Loc
,
6674 Prefix
=> New_Occurrence_Of
(DT
, Loc
),
6677 (RTE_Record_Component
(RE_NDT_Prims_Ptr
),
6679 Attribute_Name
=> Name_Address
))));
6682 Set_Is_True_Constant
(DT_Ptr
);
6683 Set_Is_Statically_Allocated
(DT_Ptr
);
6687 -- 2) Generate the secondary tag entities
6689 -- Collect the components associated with secondary dispatch tables
6691 if Has_Interfaces
(Typ
) then
6692 Collect_Interface_Components
(Typ
, Typ_Comps
);
6694 -- For each interface type we build a unique external name associated
6695 -- with its secondary dispatch table. This name is used to declare an
6696 -- object that references this secondary dispatch table, whose value
6697 -- will be used for the elaboration of Typ objects, and also for the
6698 -- elaboration of objects of types derived from Typ that do not
6699 -- override the primitives of this interface type.
6703 -- Note: The value of Suffix_Index must be in sync with the values of
6704 -- Suffix_Index in secondary dispatch tables generated by Make_DT.
6706 if Is_CPP_Class
(Typ
) then
6707 AI_Tag_Comp
:= First_Elmt
(Typ_Comps
);
6708 while Present
(AI_Tag_Comp
) loop
6709 Get_Secondary_DT_External_Name
6710 (Typ
, Related_Type
(Node
(AI_Tag_Comp
)), Suffix_Index
);
6711 Typ_Name
:= Name_Find
;
6713 -- Declare variables to store copy of the C++ secondary tags
6716 Make_Defining_Identifier
(Loc
,
6717 Chars
=> New_External_Name
(Typ_Name
, 'P'));
6718 Set_Etype
(Iface_DT_Ptr
, RTE
(RE_Interface_Tag
));
6719 Set_Ekind
(Iface_DT_Ptr
, E_Variable
);
6720 Set_Is_Tag
(Iface_DT_Ptr
);
6722 Set_Has_Thunks
(Iface_DT_Ptr
);
6724 (Iface_DT_Ptr
, Related_Type
(Node
(AI_Tag_Comp
)));
6725 Append_Elmt
(Iface_DT_Ptr
, Access_Disp_Table
(Typ
));
6728 Make_Object_Declaration
(Loc
,
6729 Defining_Identifier
=> Iface_DT_Ptr
,
6730 Object_Definition
=> New_Occurrence_Of
6731 (RTE
(RE_Interface_Tag
), Loc
),
6733 Unchecked_Convert_To
(RTE
(RE_Interface_Tag
),
6734 New_Occurrence_Of
(RTE
(RE_Null_Address
), Loc
))));
6736 Set_Is_Statically_Allocated
(Iface_DT_Ptr
,
6737 Is_Library_Level_Tagged_Type
(Typ
));
6739 Next_Elmt
(AI_Tag_Comp
);
6742 -- This is not a CPP_Class type
6745 AI_Tag_Comp
:= First_Elmt
(Typ_Comps
);
6746 while Present
(AI_Tag_Comp
) loop
6747 Get_Secondary_DT_External_Name
6748 (Typ
, Related_Type
(Node
(AI_Tag_Comp
)), Suffix_Index
);
6749 Typ_Name
:= Name_Find
;
6751 if Building_Static_DT
(Typ
) then
6753 Make_Defining_Identifier
(Loc
,
6754 Chars
=> New_External_Name
(Typ_Name
, 'T'));
6756 (Tag_Typ
=> Related_Type
(Node
(AI_Tag_Comp
)),
6758 Is_Secondary_DT
=> True);
6761 -- Secondary dispatch table referencing thunks to user-defined
6762 -- primitives covered by this interface.
6765 Make_Defining_Identifier
(Loc
,
6766 Chars
=> New_External_Name
(Typ_Name
, 'P'));
6767 Set_Etype
(Iface_DT_Ptr
, RTE
(RE_Interface_Tag
));
6768 Set_Ekind
(Iface_DT_Ptr
, E_Constant
);
6769 Set_Is_Tag
(Iface_DT_Ptr
);
6770 Set_Has_Thunks
(Iface_DT_Ptr
);
6771 Set_Is_Statically_Allocated
(Iface_DT_Ptr
,
6772 Is_Library_Level_Tagged_Type
(Typ
));
6773 Set_Is_True_Constant
(Iface_DT_Ptr
);
6775 (Iface_DT_Ptr
, Related_Type
(Node
(AI_Tag_Comp
)));
6776 Append_Elmt
(Iface_DT_Ptr
, Access_Disp_Table
(Typ
));
6778 if Building_Static_DT
(Typ
) then
6780 Make_Object_Declaration
(Loc
,
6781 Defining_Identifier
=> Iface_DT_Ptr
,
6782 Constant_Present
=> True,
6783 Object_Definition
=> New_Occurrence_Of
6784 (RTE
(RE_Interface_Tag
), Loc
),
6786 Unchecked_Convert_To
(RTE
(RE_Interface_Tag
),
6787 Make_Attribute_Reference
(Loc
,
6789 Make_Selected_Component
(Loc
,
6791 New_Occurrence_Of
(Iface_DT
, Loc
),
6794 (RTE_Record_Component
(RE_Prims_Ptr
),
6796 Attribute_Name
=> Name_Address
))));
6799 -- Secondary dispatch table referencing thunks to predefined
6803 Make_Defining_Identifier
(Loc
,
6804 Chars
=> New_External_Name
(Typ_Name
, 'Y'));
6805 Set_Etype
(Iface_DT_Ptr
, RTE
(RE_Address
));
6806 Set_Ekind
(Iface_DT_Ptr
, E_Constant
);
6807 Set_Is_Tag
(Iface_DT_Ptr
);
6808 Set_Has_Thunks
(Iface_DT_Ptr
);
6809 Set_Is_Statically_Allocated
(Iface_DT_Ptr
,
6810 Is_Library_Level_Tagged_Type
(Typ
));
6811 Set_Is_True_Constant
(Iface_DT_Ptr
);
6813 (Iface_DT_Ptr
, Related_Type
(Node
(AI_Tag_Comp
)));
6814 Append_Elmt
(Iface_DT_Ptr
, Access_Disp_Table
(Typ
));
6816 -- Secondary dispatch table referencing user-defined primitives
6817 -- covered by this interface.
6820 Make_Defining_Identifier
(Loc
,
6821 Chars
=> New_External_Name
(Typ_Name
, 'D'));
6822 Set_Etype
(Iface_DT_Ptr
, RTE
(RE_Interface_Tag
));
6823 Set_Ekind
(Iface_DT_Ptr
, E_Constant
);
6824 Set_Is_Tag
(Iface_DT_Ptr
);
6825 Set_Is_Statically_Allocated
(Iface_DT_Ptr
,
6826 Is_Library_Level_Tagged_Type
(Typ
));
6827 Set_Is_True_Constant
(Iface_DT_Ptr
);
6829 (Iface_DT_Ptr
, Related_Type
(Node
(AI_Tag_Comp
)));
6830 Append_Elmt
(Iface_DT_Ptr
, Access_Disp_Table
(Typ
));
6832 -- Secondary dispatch table referencing predefined primitives
6835 Make_Defining_Identifier
(Loc
,
6836 Chars
=> New_External_Name
(Typ_Name
, 'Z'));
6837 Set_Etype
(Iface_DT_Ptr
, RTE
(RE_Address
));
6838 Set_Ekind
(Iface_DT_Ptr
, E_Constant
);
6839 Set_Is_Tag
(Iface_DT_Ptr
);
6840 Set_Is_Statically_Allocated
(Iface_DT_Ptr
,
6841 Is_Library_Level_Tagged_Type
(Typ
));
6842 Set_Is_True_Constant
(Iface_DT_Ptr
);
6844 (Iface_DT_Ptr
, Related_Type
(Node
(AI_Tag_Comp
)));
6845 Append_Elmt
(Iface_DT_Ptr
, Access_Disp_Table
(Typ
));
6847 Next_Elmt
(AI_Tag_Comp
);
6852 -- 3) At the end of Access_Disp_Table, if the type has user-defined
6853 -- primitives, we add the entity of an access type declaration that
6854 -- is used by Build_Get_Prim_Op_Address to expand dispatching calls
6855 -- through the primary dispatch table.
6857 if UI_To_Int
(DT_Entry_Count
(First_Tag_Component
(Typ
))) = 0 then
6858 Analyze_List
(Result
);
6861 -- type Typ_DT is array (1 .. Nb_Prims) of Prim_Ptr;
6862 -- type Typ_DT_Acc is access Typ_DT;
6866 Name_DT_Prims
: constant Name_Id
:=
6867 New_External_Name
(Tname
, 'G');
6868 Name_DT_Prims_Acc
: constant Name_Id
:=
6869 New_External_Name
(Tname
, 'H');
6870 DT_Prims
: constant Entity_Id
:=
6871 Make_Defining_Identifier
(Loc
,
6873 DT_Prims_Acc
: constant Entity_Id
:=
6874 Make_Defining_Identifier
(Loc
,
6878 Make_Full_Type_Declaration
(Loc
,
6879 Defining_Identifier
=> DT_Prims
,
6881 Make_Constrained_Array_Definition
(Loc
,
6882 Discrete_Subtype_Definitions
=> New_List
(
6884 Low_Bound
=> Make_Integer_Literal
(Loc
, 1),
6885 High_Bound
=> Make_Integer_Literal
(Loc
,
6887 (First_Tag_Component
(Typ
))))),
6888 Component_Definition
=>
6889 Make_Component_Definition
(Loc
,
6890 Subtype_Indication
=>
6891 New_Occurrence_Of
(RTE
(RE_Prim_Ptr
), Loc
)))));
6894 Make_Full_Type_Declaration
(Loc
,
6895 Defining_Identifier
=> DT_Prims_Acc
,
6897 Make_Access_To_Object_Definition
(Loc
,
6898 Subtype_Indication
=>
6899 New_Occurrence_Of
(DT_Prims
, Loc
))));
6901 Append_Elmt
(DT_Prims_Acc
, Access_Disp_Table
(Typ
));
6903 -- Analyze the resulting list and suppress the generation of the
6904 -- Init_Proc associated with the above array declaration because
6905 -- this type is never used in object declarations. It is only used
6906 -- to simplify the expansion associated with dispatching calls.
6908 Analyze_List
(Result
);
6909 Set_Suppress_Initialization
(Base_Type
(DT_Prims
));
6911 -- Disable backend optimizations based on assumptions about the
6912 -- aliasing status of objects designated by the access to the
6913 -- dispatch table. Required to handle dispatch tables imported
6916 Set_No_Strict_Aliasing
(Base_Type
(DT_Prims_Acc
));
6918 -- Add the freezing nodes of these declarations; required to avoid
6919 -- generating these freezing nodes in wrong scopes (for example in
6920 -- the IC routine of a derivation of Typ).
6922 -- What is an "IC routine"? Is "init_proc" meant here???
6924 Append_List_To
(Result
, Freeze_Entity
(DT_Prims
, Typ
));
6925 Append_List_To
(Result
, Freeze_Entity
(DT_Prims_Acc
, Typ
));
6927 -- Mark entity of dispatch table. Required by the back end to
6928 -- handle them properly.
6930 Set_Is_Dispatch_Table_Entity
(DT_Prims
);
6934 -- Mark entities of dispatch table. Required by the back end to handle
6937 if Present
(DT
) then
6938 Set_Is_Dispatch_Table_Entity
(DT
);
6939 Set_Is_Dispatch_Table_Entity
(Etype
(DT
));
6942 if Present
(Iface_DT
) then
6943 Set_Is_Dispatch_Table_Entity
(Iface_DT
);
6944 Set_Is_Dispatch_Table_Entity
(Etype
(Iface_DT
));
6947 if Is_CPP_Class
(Root_Type
(Typ
)) then
6948 Set_Ekind
(DT_Ptr
, E_Variable
);
6950 Set_Ekind
(DT_Ptr
, E_Constant
);
6953 Set_Is_Tag
(DT_Ptr
);
6954 Set_Related_Type
(DT_Ptr
, Typ
);
6963 function New_Value
(From
: Node_Id
) return Node_Id
is
6964 Res
: constant Node_Id
:= Duplicate_Subexpr
(From
);
6966 if Is_Access_Type
(Etype
(From
)) then
6967 return Make_Explicit_Dereference
(Sloc
(From
), Prefix
=> Res
);
6973 -----------------------------------
6974 -- Original_View_In_Visible_Part --
6975 -----------------------------------
6977 function Original_View_In_Visible_Part
(Typ
: Entity_Id
) return Boolean is
6978 Scop
: constant Entity_Id
:= Scope
(Typ
);
6981 -- The scope must be a package
6983 if not Is_Package_Or_Generic_Package
(Scop
) then
6987 -- A type with a private declaration has a private view declared in
6988 -- the visible part.
6990 if Has_Private_Declaration
(Typ
) then
6994 return List_Containing
(Parent
(Typ
)) =
6995 Visible_Declarations
(Package_Specification
(Scop
));
6996 end Original_View_In_Visible_Part
;
7002 function Prim_Op_Kind
7004 Typ
: Entity_Id
) return Node_Id
7006 Full_Typ
: Entity_Id
:= Typ
;
7007 Loc
: constant Source_Ptr
:= Sloc
(Prim
);
7008 Prim_Op
: Entity_Id
;
7011 -- Retrieve the original primitive operation
7013 Prim_Op
:= Ultimate_Alias
(Prim
);
7015 if Ekind
(Typ
) = E_Record_Type
7016 and then Present
(Corresponding_Concurrent_Type
(Typ
))
7018 Full_Typ
:= Corresponding_Concurrent_Type
(Typ
);
7021 -- When a private tagged type is completed by a concurrent type,
7022 -- retrieve the full view.
7024 if Is_Private_Type
(Full_Typ
) then
7025 Full_Typ
:= Full_View
(Full_Typ
);
7028 if Ekind
(Prim_Op
) = E_Function
then
7030 -- Protected function
7032 if Ekind
(Full_Typ
) = E_Protected_Type
then
7033 return New_Occurrence_Of
(RTE
(RE_POK_Protected_Function
), Loc
);
7037 elsif Ekind
(Full_Typ
) = E_Task_Type
then
7038 return New_Occurrence_Of
(RTE
(RE_POK_Task_Function
), Loc
);
7043 return New_Occurrence_Of
(RTE
(RE_POK_Function
), Loc
);
7047 pragma Assert
(Ekind
(Prim_Op
) = E_Procedure
);
7049 if Ekind
(Full_Typ
) = E_Protected_Type
then
7053 if Is_Primitive_Wrapper
(Prim_Op
)
7054 and then Ekind
(Wrapped_Entity
(Prim_Op
)) = E_Entry
7056 return New_Occurrence_Of
(RTE
(RE_POK_Protected_Entry
), Loc
);
7058 -- Protected procedure
7062 New_Occurrence_Of
(RTE
(RE_POK_Protected_Procedure
), Loc
);
7065 elsif Ekind
(Full_Typ
) = E_Task_Type
then
7069 if Is_Primitive_Wrapper
(Prim_Op
)
7070 and then Ekind
(Wrapped_Entity
(Prim_Op
)) = E_Entry
7072 return New_Occurrence_Of
(RTE
(RE_POK_Task_Entry
), Loc
);
7074 -- Task "procedure". These are the internally Expander-generated
7075 -- procedures (task body for instance).
7078 return New_Occurrence_Of
(RTE
(RE_POK_Task_Procedure
), Loc
);
7081 -- Regular procedure
7084 return New_Occurrence_Of
(RTE
(RE_POK_Procedure
), Loc
);
7089 ------------------------
7090 -- Register_Primitive --
7091 ------------------------
7093 function Register_Primitive
7095 Prim
: Entity_Id
) return List_Id
7098 Iface_Prim
: Entity_Id
;
7099 Iface_Typ
: Entity_Id
;
7100 Iface_DT_Ptr
: Entity_Id
;
7101 Iface_DT_Elmt
: Elmt_Id
;
7102 L
: constant List_Id
:= New_List
;
7105 Tag_Typ
: Entity_Id
;
7106 Thunk_Id
: Entity_Id
;
7107 Thunk_Code
: Node_Id
;
7110 pragma Assert
(not Restriction_Active
(No_Dispatching_Calls
));
7112 -- Do not register in the dispatch table eliminated primitives
7114 if not RTE_Available
(RE_Tag
)
7115 or else Is_Eliminated
(Ultimate_Alias
(Prim
))
7116 or else Generate_SCIL
7121 if not Present
(Interface_Alias
(Prim
)) then
7122 Tag_Typ
:= Scope
(DTC_Entity
(Prim
));
7123 Pos
:= DT_Position
(Prim
);
7124 Tag
:= First_Tag_Component
(Tag_Typ
);
7126 if Is_Predefined_Dispatching_Operation
(Prim
)
7127 or else Is_Predefined_Dispatching_Alias
(Prim
)
7130 Node
(Next_Elmt
(First_Elmt
(Access_Disp_Table
(Tag_Typ
))));
7133 Build_Set_Predefined_Prim_Op_Address
(Loc
,
7134 Tag_Node
=> New_Occurrence_Of
(DT_Ptr
, Loc
),
7137 Unchecked_Convert_To
(RTE
(RE_Prim_Ptr
),
7138 Make_Attribute_Reference
(Loc
,
7139 Prefix
=> New_Occurrence_Of
(Prim
, Loc
),
7140 Attribute_Name
=> Name_Unrestricted_Access
))));
7142 -- Register copy of the pointer to the 'size primitive in the TSD
7144 if Chars
(Prim
) = Name_uSize
7145 and then RTE_Record_Component_Available
(RE_Size_Func
)
7147 DT_Ptr
:= Node
(First_Elmt
(Access_Disp_Table
(Tag_Typ
)));
7149 Build_Set_Size_Function
(Loc
,
7150 Tag_Node
=> New_Occurrence_Of
(DT_Ptr
, Loc
),
7151 Size_Func
=> Prim
));
7155 pragma Assert
(Pos
/= Uint_0
and then Pos
<= DT_Entry_Count
(Tag
));
7157 -- Skip registration of primitives located in the C++ part of the
7158 -- dispatch table. Their slot is set by the IC routine.
7160 if not Is_CPP_Class
(Root_Type
(Tag_Typ
))
7161 or else Pos
> CPP_Num_Prims
(Tag_Typ
)
7163 DT_Ptr
:= Node
(First_Elmt
(Access_Disp_Table
(Tag_Typ
)));
7165 Build_Set_Prim_Op_Address
(Loc
,
7167 Tag_Node
=> New_Occurrence_Of
(DT_Ptr
, Loc
),
7170 Unchecked_Convert_To
(RTE
(RE_Prim_Ptr
),
7171 Make_Attribute_Reference
(Loc
,
7172 Prefix
=> New_Occurrence_Of
(Prim
, Loc
),
7173 Attribute_Name
=> Name_Unrestricted_Access
))));
7177 -- Ada 2005 (AI-251): Primitive associated with an interface type
7179 -- Generate the code of the thunk only if the interface type is not an
7180 -- immediate ancestor of Typ; otherwise the dispatch table associated
7181 -- with the interface is the primary dispatch table and we have nothing
7185 Tag_Typ
:= Find_Dispatching_Type
(Alias
(Prim
));
7186 Iface_Typ
:= Find_Dispatching_Type
(Interface_Alias
(Prim
));
7188 pragma Assert
(Is_Interface
(Iface_Typ
));
7190 -- No action needed for interfaces that are ancestors of Typ because
7191 -- their primitives are located in the primary dispatch table.
7193 if Is_Ancestor
(Iface_Typ
, Tag_Typ
, Use_Full_View
=> True) then
7196 -- No action needed for primitives located in the C++ part of the
7197 -- dispatch table. Their slot is set by the IC routine.
7199 elsif Is_CPP_Class
(Root_Type
(Tag_Typ
))
7200 and then DT_Position
(Alias
(Prim
)) <= CPP_Num_Prims
(Tag_Typ
)
7201 and then not Is_Predefined_Dispatching_Operation
(Prim
)
7202 and then not Is_Predefined_Dispatching_Alias
(Prim
)
7207 Expand_Interface_Thunk
(Prim
, Thunk_Id
, Thunk_Code
);
7209 if not Is_Ancestor
(Iface_Typ
, Tag_Typ
, Use_Full_View
=> True)
7210 and then Present
(Thunk_Code
)
7212 -- Generate the code necessary to fill the appropriate entry of
7213 -- the secondary dispatch table of Prim's controlling type with
7214 -- Thunk_Id's address.
7216 Iface_DT_Elmt
:= Find_Interface_ADT
(Tag_Typ
, Iface_Typ
);
7217 Iface_DT_Ptr
:= Node
(Iface_DT_Elmt
);
7218 pragma Assert
(Has_Thunks
(Iface_DT_Ptr
));
7220 Iface_Prim
:= Interface_Alias
(Prim
);
7221 Pos
:= DT_Position
(Iface_Prim
);
7222 Tag
:= First_Tag_Component
(Iface_Typ
);
7224 Prepend_To
(L
, Thunk_Code
);
7226 if Is_Predefined_Dispatching_Operation
(Prim
)
7227 or else Is_Predefined_Dispatching_Alias
(Prim
)
7230 Build_Set_Predefined_Prim_Op_Address
(Loc
,
7232 New_Occurrence_Of
(Node
(Next_Elmt
(Iface_DT_Elmt
)), Loc
),
7235 Unchecked_Convert_To
(RTE
(RE_Prim_Ptr
),
7236 Make_Attribute_Reference
(Loc
,
7237 Prefix
=> New_Occurrence_Of
(Thunk_Id
, Loc
),
7238 Attribute_Name
=> Name_Unrestricted_Access
))));
7240 Next_Elmt
(Iface_DT_Elmt
);
7241 Next_Elmt
(Iface_DT_Elmt
);
7242 Iface_DT_Ptr
:= Node
(Iface_DT_Elmt
);
7243 pragma Assert
(not Has_Thunks
(Iface_DT_Ptr
));
7246 Build_Set_Predefined_Prim_Op_Address
(Loc
,
7248 New_Occurrence_Of
(Node
(Next_Elmt
(Iface_DT_Elmt
)), Loc
),
7251 Unchecked_Convert_To
(RTE
(RE_Prim_Ptr
),
7252 Make_Attribute_Reference
(Loc
,
7254 New_Occurrence_Of
(Alias
(Prim
), Loc
),
7255 Attribute_Name
=> Name_Unrestricted_Access
))));
7258 pragma Assert
(Pos
/= Uint_0
7259 and then Pos
<= DT_Entry_Count
(Tag
));
7262 Build_Set_Prim_Op_Address
(Loc
,
7264 Tag_Node
=> New_Occurrence_Of
(Iface_DT_Ptr
, Loc
),
7267 Unchecked_Convert_To
(RTE
(RE_Prim_Ptr
),
7268 Make_Attribute_Reference
(Loc
,
7269 Prefix
=> New_Occurrence_Of
(Thunk_Id
, Loc
),
7270 Attribute_Name
=> Name_Unrestricted_Access
))));
7272 Next_Elmt
(Iface_DT_Elmt
);
7273 Next_Elmt
(Iface_DT_Elmt
);
7274 Iface_DT_Ptr
:= Node
(Iface_DT_Elmt
);
7275 pragma Assert
(not Has_Thunks
(Iface_DT_Ptr
));
7278 Build_Set_Prim_Op_Address
(Loc
,
7280 Tag_Node
=> New_Occurrence_Of
(Iface_DT_Ptr
, Loc
),
7283 Unchecked_Convert_To
(RTE
(RE_Prim_Ptr
),
7284 Make_Attribute_Reference
(Loc
,
7286 New_Occurrence_Of
(Alias
(Prim
), Loc
),
7287 Attribute_Name
=> Name_Unrestricted_Access
))));
7294 end Register_Primitive
;
7296 -------------------------
7297 -- Set_All_DT_Position --
7298 -------------------------
7300 procedure Set_All_DT_Position
(Typ
: Entity_Id
) is
7302 function In_Predef_Prims_DT
(Prim
: Entity_Id
) return Boolean;
7303 -- Returns True if Prim is located in the dispatch table of
7304 -- predefined primitives
7306 procedure Validate_Position
(Prim
: Entity_Id
);
7307 -- Check that position assigned to Prim is completely safe (it has not
7308 -- been assigned to a previously defined primitive operation of Typ).
7310 ------------------------
7311 -- In_Predef_Prims_DT --
7312 ------------------------
7314 function In_Predef_Prims_DT
(Prim
: Entity_Id
) return Boolean is
7318 -- Predefined primitives
7320 if Is_Predefined_Dispatching_Operation
(Prim
) then
7323 -- Renamings of predefined primitives
7325 elsif Present
(Alias
(Prim
))
7326 and then Is_Predefined_Dispatching_Operation
(Ultimate_Alias
(Prim
))
7328 if Chars
(Ultimate_Alias
(Prim
)) /= Name_Op_Eq
then
7331 -- User-defined renamings of predefined equality have their own
7332 -- slot in the primary dispatch table
7336 while Present
(Alias
(E
)) loop
7337 if Comes_From_Source
(E
) then
7344 return not Comes_From_Source
(E
);
7347 -- User-defined primitives
7352 end In_Predef_Prims_DT
;
7354 -----------------------
7355 -- Validate_Position --
7356 -----------------------
7358 procedure Validate_Position
(Prim
: Entity_Id
) is
7363 -- Aliased primitives are safe
7365 if Present
(Alias
(Prim
)) then
7369 Op_Elmt
:= First_Elmt
(Primitive_Operations
(Typ
));
7370 while Present
(Op_Elmt
) loop
7371 Op
:= Node
(Op_Elmt
);
7373 -- No need to check against itself
7378 -- Primitive operations covering abstract interfaces are
7381 elsif Present
(Interface_Alias
(Op
)) then
7384 -- Predefined dispatching operations are completely safe. They
7385 -- are allocated at fixed positions in a separate table.
7387 elsif Is_Predefined_Dispatching_Operation
(Op
)
7388 or else Is_Predefined_Dispatching_Alias
(Op
)
7392 -- Aliased subprograms are safe
7394 elsif Present
(Alias
(Op
)) then
7397 elsif DT_Position
(Op
) = DT_Position
(Prim
)
7398 and then not Is_Predefined_Dispatching_Operation
(Op
)
7399 and then not Is_Predefined_Dispatching_Operation
(Prim
)
7400 and then not Is_Predefined_Dispatching_Alias
(Op
)
7401 and then not Is_Predefined_Dispatching_Alias
(Prim
)
7403 -- Handle aliased subprograms
7412 if Present
(Overridden_Operation
(Op_1
)) then
7413 Op_1
:= Overridden_Operation
(Op_1
);
7414 elsif Present
(Alias
(Op_1
)) then
7415 Op_1
:= Alias
(Op_1
);
7423 if Present
(Overridden_Operation
(Op_2
)) then
7424 Op_2
:= Overridden_Operation
(Op_2
);
7425 elsif Present
(Alias
(Op_2
)) then
7426 Op_2
:= Alias
(Op_2
);
7432 if Op_1
/= Op_2
then
7433 raise Program_Error
;
7438 Next_Elmt
(Op_Elmt
);
7440 end Validate_Position
;
7444 Parent_Typ
: constant Entity_Id
:= Etype
(Typ
);
7445 First_Prim
: constant Elmt_Id
:= First_Elmt
(Primitive_Operations
(Typ
));
7446 The_Tag
: constant Entity_Id
:= First_Tag_Component
(Typ
);
7448 Adjusted
: Boolean := False;
7449 Finalized
: Boolean := False;
7455 Prim_Elmt
: Elmt_Id
;
7457 -- Start of processing for Set_All_DT_Position
7460 pragma Assert
(Present
(First_Tag_Component
(Typ
)));
7462 -- Set the DT_Position for each primitive operation. Perform some sanity
7463 -- checks to avoid building inconsistent dispatch tables.
7465 -- First stage: Set DTC entity of all the primitive operations. This is
7466 -- required to properly read the DT_Position attribute in latter stages.
7468 Prim_Elmt
:= First_Prim
;
7470 while Present
(Prim_Elmt
) loop
7471 Prim
:= Node
(Prim_Elmt
);
7473 -- Predefined primitives have a separate dispatch table
7475 if not In_Predef_Prims_DT
(Prim
) then
7476 Count_Prim
:= Count_Prim
+ 1;
7479 Set_DTC_Entity_Value
(Typ
, Prim
);
7481 -- Clear any previous value of the DT_Position attribute. In this
7482 -- way we ensure that the final position of all the primitives is
7483 -- established by the following stages of this algorithm.
7485 Set_DT_Position_Value
(Prim
, No_Uint
);
7487 Next_Elmt
(Prim_Elmt
);
7491 Fixed_Prim
: array (Int
range 0 .. Count_Prim
) of Boolean :=
7496 procedure Handle_Inherited_Private_Subprograms
(Typ
: Entity_Id
);
7497 -- Called if Typ is declared in a nested package or a public child
7498 -- package to handle inherited primitives that were inherited by Typ
7499 -- in the visible part, but whose declaration was deferred because
7500 -- the parent operation was private and not visible at that point.
7502 procedure Set_Fixed_Prim
(Pos
: Nat
);
7503 -- Sets to true an element of the Fixed_Prim table to indicate
7504 -- that this entry of the dispatch table of Typ is occupied.
7506 ------------------------------------------
7507 -- Handle_Inherited_Private_Subprograms --
7508 ------------------------------------------
7510 procedure Handle_Inherited_Private_Subprograms
(Typ
: Entity_Id
) is
7513 Op_Elmt_2
: Elmt_Id
;
7514 Prim_Op
: Entity_Id
;
7515 Parent_Subp
: Entity_Id
;
7518 Op_List
:= Primitive_Operations
(Typ
);
7520 Op_Elmt
:= First_Elmt
(Op_List
);
7521 while Present
(Op_Elmt
) loop
7522 Prim_Op
:= Node
(Op_Elmt
);
7524 -- Search primitives that are implicit operations with an
7525 -- internal name whose parent operation has a normal name.
7527 if Present
(Alias
(Prim_Op
))
7528 and then Find_Dispatching_Type
(Alias
(Prim_Op
)) /= Typ
7529 and then not Comes_From_Source
(Prim_Op
)
7530 and then Is_Internal_Name
(Chars
(Prim_Op
))
7531 and then not Is_Internal_Name
(Chars
(Alias
(Prim_Op
)))
7533 Parent_Subp
:= Alias
(Prim_Op
);
7535 -- Check if the type has an explicit overriding for this
7538 Op_Elmt_2
:= Next_Elmt
(Op_Elmt
);
7539 while Present
(Op_Elmt_2
) loop
7540 if Chars
(Node
(Op_Elmt_2
)) = Chars
(Parent_Subp
)
7541 and then Type_Conformant
(Prim_Op
, Node
(Op_Elmt_2
))
7543 Set_DT_Position_Value
(Prim_Op
,
7544 DT_Position
(Parent_Subp
));
7545 Set_DT_Position_Value
(Node
(Op_Elmt_2
),
7546 DT_Position
(Parent_Subp
));
7547 Set_Fixed_Prim
(UI_To_Int
(DT_Position
(Prim_Op
)));
7549 goto Next_Primitive
;
7552 Next_Elmt
(Op_Elmt_2
);
7557 Next_Elmt
(Op_Elmt
);
7559 end Handle_Inherited_Private_Subprograms
;
7561 --------------------
7562 -- Set_Fixed_Prim --
7563 --------------------
7565 procedure Set_Fixed_Prim
(Pos
: Nat
) is
7567 pragma Assert
(Pos
<= Count_Prim
);
7568 Fixed_Prim
(Pos
) := True;
7570 when Constraint_Error
=>
7571 raise Program_Error
;
7575 -- In case of nested packages and public child package it may be
7576 -- necessary a special management on inherited subprograms so that
7577 -- the dispatch table is properly filled.
7579 if Ekind
(Scope
(Scope
(Typ
))) = E_Package
7580 and then Scope
(Scope
(Typ
)) /= Standard_Standard
7581 and then ((Is_Derived_Type
(Typ
) and then not Is_Private_Type
(Typ
))
7583 (Nkind
(Parent
(Typ
)) = N_Private_Extension_Declaration
7584 and then Is_Generic_Type
(Typ
)))
7585 and then In_Open_Scopes
(Scope
(Etype
(Typ
)))
7586 and then Is_Base_Type
(Typ
)
7588 Handle_Inherited_Private_Subprograms
(Typ
);
7591 -- Second stage: Register fixed entries
7594 Prim_Elmt
:= First_Prim
;
7595 while Present
(Prim_Elmt
) loop
7596 Prim
:= Node
(Prim_Elmt
);
7598 -- Predefined primitives have a separate table and all its
7599 -- entries are at predefined fixed positions.
7601 if In_Predef_Prims_DT
(Prim
) then
7602 if Is_Predefined_Dispatching_Operation
(Prim
) then
7603 Set_DT_Position_Value
(Prim
,
7604 Default_Prim_Op_Position
(Prim
));
7606 else pragma Assert
(Present
(Alias
(Prim
)));
7607 Set_DT_Position_Value
(Prim
,
7608 Default_Prim_Op_Position
(Ultimate_Alias
(Prim
)));
7611 -- Overriding primitives of ancestor abstract interfaces
7613 elsif Present
(Interface_Alias
(Prim
))
7614 and then Is_Ancestor
7615 (Find_Dispatching_Type
(Interface_Alias
(Prim
)), Typ
,
7616 Use_Full_View
=> True)
7618 pragma Assert
(DT_Position
(Prim
) = No_Uint
7619 and then Present
(DTC_Entity
(Interface_Alias
(Prim
))));
7621 E
:= Interface_Alias
(Prim
);
7622 Set_DT_Position_Value
(Prim
, DT_Position
(E
));
7625 (DT_Position
(Alias
(Prim
)) = No_Uint
7626 or else DT_Position
(Alias
(Prim
)) = DT_Position
(E
));
7627 Set_DT_Position_Value
(Alias
(Prim
), DT_Position
(E
));
7628 Set_Fixed_Prim
(UI_To_Int
(DT_Position
(Prim
)));
7630 -- Overriding primitives must use the same entry as the
7631 -- overridden primitive.
7633 elsif not Present
(Interface_Alias
(Prim
))
7634 and then Present
(Alias
(Prim
))
7635 and then Chars
(Prim
) = Chars
(Alias
(Prim
))
7636 and then Find_Dispatching_Type
(Alias
(Prim
)) /= Typ
7637 and then Is_Ancestor
7638 (Find_Dispatching_Type
(Alias
(Prim
)), Typ
,
7639 Use_Full_View
=> True)
7640 and then Present
(DTC_Entity
(Alias
(Prim
)))
7643 Set_DT_Position_Value
(Prim
, DT_Position
(E
));
7645 if not Is_Predefined_Dispatching_Alias
(E
) then
7646 Set_Fixed_Prim
(UI_To_Int
(DT_Position
(E
)));
7650 Next_Elmt
(Prim_Elmt
);
7653 -- Third stage: Fix the position of all the new primitives. Entries
7654 -- associated with primitives covering interfaces are handled in a
7657 Prim_Elmt
:= First_Prim
;
7658 while Present
(Prim_Elmt
) loop
7659 Prim
:= Node
(Prim_Elmt
);
7661 -- Skip primitives previously set entries
7663 if DT_Position
(Prim
) /= No_Uint
then
7666 -- Primitives covering interface primitives are handled later
7668 elsif Present
(Interface_Alias
(Prim
)) then
7672 -- Take the next available position in the DT
7675 Nb_Prim
:= Nb_Prim
+ 1;
7676 pragma Assert
(Nb_Prim
<= Count_Prim
);
7677 exit when not Fixed_Prim
(Nb_Prim
);
7680 Set_DT_Position_Value
(Prim
, UI_From_Int
(Nb_Prim
));
7681 Set_Fixed_Prim
(Nb_Prim
);
7684 Next_Elmt
(Prim_Elmt
);
7688 -- Fourth stage: Complete the decoration of primitives covering
7689 -- interfaces (that is, propagate the DT_Position attribute from
7690 -- the aliased primitive)
7692 Prim_Elmt
:= First_Prim
;
7693 while Present
(Prim_Elmt
) loop
7694 Prim
:= Node
(Prim_Elmt
);
7696 if DT_Position
(Prim
) = No_Uint
7697 and then Present
(Interface_Alias
(Prim
))
7699 pragma Assert
(Present
(Alias
(Prim
))
7700 and then Find_Dispatching_Type
(Alias
(Prim
)) = Typ
);
7702 -- Check if this entry will be placed in the primary DT
7705 (Find_Dispatching_Type
(Interface_Alias
(Prim
)), Typ
,
7706 Use_Full_View
=> True)
7708 pragma Assert
(DT_Position
(Alias
(Prim
)) /= No_Uint
);
7709 Set_DT_Position_Value
(Prim
, DT_Position
(Alias
(Prim
)));
7711 -- Otherwise it will be placed in the secondary DT
7715 (DT_Position
(Interface_Alias
(Prim
)) /= No_Uint
);
7716 Set_DT_Position_Value
(Prim
,
7717 DT_Position
(Interface_Alias
(Prim
)));
7721 Next_Elmt
(Prim_Elmt
);
7724 -- Generate listing showing the contents of the dispatch tables. This
7725 -- action is done before some further static checks because in case of
7726 -- critical errors caused by a wrong dispatch table we need to see the
7727 -- contents of such table.
7729 if Debug_Flag_ZZ
then
7733 -- Final stage: Ensure that the table is correct plus some further
7734 -- verifications concerning the primitives.
7736 Prim_Elmt
:= First_Prim
;
7738 while Present
(Prim_Elmt
) loop
7739 Prim
:= Node
(Prim_Elmt
);
7741 -- At this point all the primitives MUST have a position in the
7744 if DT_Position
(Prim
) = No_Uint
then
7745 raise Program_Error
;
7748 -- Calculate real size of the dispatch table
7750 if not In_Predef_Prims_DT
(Prim
)
7751 and then UI_To_Int
(DT_Position
(Prim
)) > DT_Length
7753 DT_Length
:= UI_To_Int
(DT_Position
(Prim
));
7756 -- Ensure that the assigned position to non-predefined dispatching
7757 -- operations in the dispatch table is correct.
7759 if not Is_Predefined_Dispatching_Operation
(Prim
)
7760 and then not Is_Predefined_Dispatching_Alias
(Prim
)
7762 Validate_Position
(Prim
);
7765 if Chars
(Prim
) = Name_Finalize
then
7769 if Chars
(Prim
) = Name_Adjust
then
7773 -- An abstract operation cannot be declared in the private part for a
7774 -- visible abstract type, because it can't be overridden outside this
7775 -- package hierarchy. For explicit declarations this is checked at
7776 -- the point of declaration, but for inherited operations it must be
7777 -- done when building the dispatch table.
7779 -- Ada 2005 (AI-251): Primitives associated with interfaces are
7780 -- excluded from this check because interfaces must be visible in
7781 -- the public and private part (RM 7.3 (7.3/2))
7783 -- We disable this check in Relaxed_RM_Semantics mode, to accommodate
7786 if not Relaxed_RM_Semantics
7787 and then Is_Abstract_Type
(Typ
)
7788 and then Is_Abstract_Subprogram
(Prim
)
7789 and then Present
(Alias
(Prim
))
7790 and then not Is_Interface
7791 (Find_Dispatching_Type
(Ultimate_Alias
(Prim
)))
7792 and then not Present
(Interface_Alias
(Prim
))
7793 and then Is_Derived_Type
(Typ
)
7794 and then In_Private_Part
(Current_Scope
)
7796 List_Containing
(Parent
(Prim
)) =
7797 Private_Declarations
(Package_Specification
(Current_Scope
))
7798 and then Original_View_In_Visible_Part
(Typ
)
7800 -- We exclude Input and Output stream operations because
7801 -- Limited_Controlled inherits useless Input and Output stream
7802 -- operations from Root_Controlled, which can never be overridden.
7804 if not Is_TSS
(Prim
, TSS_Stream_Input
)
7806 not Is_TSS
(Prim
, TSS_Stream_Output
)
7809 ("abstract inherited private operation&" &
7810 " must be overridden (RM 3.9.3(10))",
7811 Parent
(Typ
), Prim
);
7815 Next_Elmt
(Prim_Elmt
);
7820 if Is_Controlled
(Typ
) then
7821 if not Finalized
then
7823 ("controlled type has no explicit Finalize method??", Typ
);
7825 elsif not Adjusted
then
7827 ("controlled type has no explicit Adjust method??", Typ
);
7831 -- Set the final size of the Dispatch Table
7833 Set_DT_Entry_Count
(The_Tag
, UI_From_Int
(DT_Length
));
7835 -- The derived type must have at least as many components as its parent
7836 -- (for root types Etype points to itself and the test cannot fail).
7838 if DT_Entry_Count
(The_Tag
) <
7839 DT_Entry_Count
(First_Tag_Component
(Parent_Typ
))
7841 raise Program_Error
;
7843 end Set_All_DT_Position
;
7845 --------------------------
7846 -- Set_CPP_Constructors --
7847 --------------------------
7849 procedure Set_CPP_Constructors
(Typ
: Entity_Id
) is
7851 function Gen_Parameters_Profile
(E
: Entity_Id
) return List_Id
;
7852 -- Duplicate the parameters profile of the imported C++ constructor
7853 -- adding an access to the object as an additional parameter.
7855 ----------------------------
7856 -- Gen_Parameters_Profile --
7857 ----------------------------
7859 function Gen_Parameters_Profile
(E
: Entity_Id
) return List_Id
is
7860 Loc
: constant Source_Ptr
:= Sloc
(E
);
7867 Make_Parameter_Specification
(Loc
,
7868 Defining_Identifier
=>
7869 Make_Defining_Identifier
(Loc
, Name_uInit
),
7870 Parameter_Type
=> New_Occurrence_Of
(Typ
, Loc
)));
7872 if Present
(Parameter_Specifications
(Parent
(E
))) then
7873 P
:= First
(Parameter_Specifications
(Parent
(E
)));
7874 while Present
(P
) loop
7876 Make_Parameter_Specification
(Loc
,
7877 Defining_Identifier
=>
7878 Make_Defining_Identifier
(Loc
,
7879 Chars
=> Chars
(Defining_Identifier
(P
))),
7880 Parameter_Type
=> New_Copy_Tree
(Parameter_Type
(P
)),
7881 Expression
=> New_Copy_Tree
(Expression
(P
))));
7887 end Gen_Parameters_Profile
;
7893 Found
: Boolean := False;
7899 Covers_Default_Constructor
: Entity_Id
:= Empty
;
7901 -- Start of processing for Set_CPP_Constructor
7904 pragma Assert
(Is_CPP_Class
(Typ
));
7906 -- Look for the constructor entities
7908 E
:= Next_Entity
(Typ
);
7909 while Present
(E
) loop
7910 if Ekind
(E
) = E_Function
7911 and then Is_Constructor
(E
)
7915 Parms
:= Gen_Parameters_Profile
(E
);
7917 Make_Defining_Identifier
(Loc
,
7918 Chars
=> Make_Init_Proc_Name
(Typ
));
7920 -- Case 1: Constructor of untagged type
7922 -- If the C++ class has no virtual methods then the matching Ada
7923 -- type is an untagged record type. In such case there is no need
7924 -- to generate a wrapper of the C++ constructor because the _tag
7925 -- component is not available.
7927 if not Is_Tagged_Type
(Typ
) then
7929 (Make_Subprogram_Declaration
(Loc
,
7931 Make_Procedure_Specification
(Loc
,
7932 Defining_Unit_Name
=> IP
,
7933 Parameter_Specifications
=> Parms
)));
7935 Set_Init_Proc
(Typ
, IP
);
7936 Set_Is_Imported
(IP
);
7937 Set_Is_Constructor
(IP
);
7938 Set_Interface_Name
(IP
, Interface_Name
(E
));
7939 Set_Convention
(IP
, Convention_CPP
);
7941 Set_Has_Completion
(IP
);
7943 -- Case 2: Constructor of a tagged type
7945 -- In this case we generate the IP as a wrapper of the the
7946 -- C++ constructor because IP must also save copy of the _tag
7947 -- generated in the C++ side. The copy of the _tag is used by
7948 -- Build_CPP_Init_Procedure to elaborate derivations of C++ types.
7951 -- procedure IP (_init : Typ; ...) is
7952 -- procedure ConstructorP (_init : Typ; ...);
7953 -- pragma Import (ConstructorP);
7955 -- ConstructorP (_init, ...);
7956 -- if Typ._tag = null then
7957 -- Typ._tag := _init._tag;
7963 Body_Stmts
: constant List_Id
:= New_List
;
7964 Constructor_Id
: Entity_Id
;
7965 Constructor_Decl_Node
: Node_Id
;
7966 Init_Tags_List
: List_Id
;
7969 Constructor_Id
:= Make_Temporary
(Loc
, 'P');
7971 Constructor_Decl_Node
:=
7972 Make_Subprogram_Declaration
(Loc
,
7973 Make_Procedure_Specification
(Loc
,
7974 Defining_Unit_Name
=> Constructor_Id
,
7975 Parameter_Specifications
=> Parms
));
7977 Set_Is_Imported
(Constructor_Id
);
7978 Set_Is_Constructor
(Constructor_Id
);
7979 Set_Interface_Name
(Constructor_Id
, Interface_Name
(E
));
7980 Set_Convention
(Constructor_Id
, Convention_CPP
);
7981 Set_Is_Public
(Constructor_Id
);
7982 Set_Has_Completion
(Constructor_Id
);
7984 -- Build the init procedure as a wrapper of this constructor
7986 Parms
:= Gen_Parameters_Profile
(E
);
7988 -- Invoke the C++ constructor
7991 Actuals
: constant List_Id
:= New_List
;
7995 while Present
(P
) loop
7997 New_Occurrence_Of
(Defining_Identifier
(P
), Loc
));
8001 Append_To
(Body_Stmts
,
8002 Make_Procedure_Call_Statement
(Loc
,
8003 Name
=> New_Occurrence_Of
(Constructor_Id
, Loc
),
8004 Parameter_Associations
=> Actuals
));
8007 -- Initialize copies of C++ primary and secondary tags
8009 Init_Tags_List
:= New_List
;
8016 Tag_Elmt
:= First_Elmt
(Access_Disp_Table
(Typ
));
8017 Tag_Comp
:= First_Tag_Component
(Typ
);
8019 while Present
(Tag_Elmt
)
8020 and then Is_Tag
(Node
(Tag_Elmt
))
8022 -- Skip the following assertion with primary tags
8023 -- because Related_Type is not set on primary tag
8027 (Tag_Comp
= First_Tag_Component
(Typ
)
8028 or else Related_Type
(Node
(Tag_Elmt
))
8029 = Related_Type
(Tag_Comp
));
8031 Append_To
(Init_Tags_List
,
8032 Make_Assignment_Statement
(Loc
,
8034 New_Occurrence_Of
(Node
(Tag_Elmt
), Loc
),
8036 Make_Selected_Component
(Loc
,
8038 Make_Identifier
(Loc
, Name_uInit
),
8040 New_Occurrence_Of
(Tag_Comp
, Loc
))));
8042 Tag_Comp
:= Next_Tag_Component
(Tag_Comp
);
8043 Next_Elmt
(Tag_Elmt
);
8047 Append_To
(Body_Stmts
,
8048 Make_If_Statement
(Loc
,
8053 (Node
(First_Elmt
(Access_Disp_Table
(Typ
))),
8056 Unchecked_Convert_To
(RTE
(RE_Tag
),
8057 New_Occurrence_Of
(RTE
(RE_Null_Address
), Loc
))),
8058 Then_Statements
=> Init_Tags_List
));
8061 Make_Subprogram_Body
(Loc
,
8063 Make_Procedure_Specification
(Loc
,
8064 Defining_Unit_Name
=> IP
,
8065 Parameter_Specifications
=> Parms
),
8066 Declarations
=> New_List
(Constructor_Decl_Node
),
8067 Handled_Statement_Sequence
=>
8068 Make_Handled_Sequence_Of_Statements
(Loc
,
8069 Statements
=> Body_Stmts
,
8070 Exception_Handlers
=> No_List
));
8072 Discard_Node
(IP_Body
);
8073 Set_Init_Proc
(Typ
, IP
);
8077 -- If this constructor has parameters and all its parameters have
8078 -- defaults then it covers the default constructor. The semantic
8079 -- analyzer ensures that only one constructor with defaults covers
8080 -- the default constructor.
8082 if Present
(Parameter_Specifications
(Parent
(E
)))
8083 and then Needs_No_Actuals
(E
)
8085 Covers_Default_Constructor
:= IP
;
8092 -- If there are no constructors, mark the type as abstract since we
8093 -- won't be able to declare objects of that type.
8096 Set_Is_Abstract_Type
(Typ
);
8099 -- Handle constructor that has all its parameters with defaults and
8100 -- hence it covers the default constructor. We generate a wrapper IP
8101 -- which calls the covering constructor.
8103 if Present
(Covers_Default_Constructor
) then
8105 Body_Stmts
: List_Id
;
8108 Loc
:= Sloc
(Covers_Default_Constructor
);
8110 Body_Stmts
:= New_List
(
8111 Make_Procedure_Call_Statement
(Loc
,
8113 New_Occurrence_Of
(Covers_Default_Constructor
, Loc
),
8114 Parameter_Associations
=> New_List
(
8115 Make_Identifier
(Loc
, Name_uInit
))));
8117 IP
:= Make_Defining_Identifier
(Loc
, Make_Init_Proc_Name
(Typ
));
8120 Make_Subprogram_Body
(Loc
,
8122 Make_Procedure_Specification
(Loc
,
8123 Defining_Unit_Name
=> IP
,
8124 Parameter_Specifications
=> New_List
(
8125 Make_Parameter_Specification
(Loc
,
8126 Defining_Identifier
=>
8127 Make_Defining_Identifier
(Loc
, Name_uInit
),
8128 Parameter_Type
=> New_Occurrence_Of
(Typ
, Loc
)))),
8130 Declarations
=> No_List
,
8132 Handled_Statement_Sequence
=>
8133 Make_Handled_Sequence_Of_Statements
(Loc
,
8134 Statements
=> Body_Stmts
,
8135 Exception_Handlers
=> No_List
));
8137 Discard_Node
(IP_Body
);
8138 Set_Init_Proc
(Typ
, IP
);
8142 -- If the CPP type has constructors then it must import also the default
8143 -- C++ constructor. It is required for default initialization of objects
8144 -- of the type. It is also required to elaborate objects of Ada types
8145 -- that are defined as derivations of this CPP type.
8147 if Has_CPP_Constructors
(Typ
)
8148 and then No
(Init_Proc
(Typ
))
8150 Error_Msg_N
("??default constructor must be imported from C++", Typ
);
8152 end Set_CPP_Constructors
;
8154 ---------------------------
8155 -- Set_DT_Position_Value --
8156 ---------------------------
8158 procedure Set_DT_Position_Value
(Prim
: Entity_Id
; Value
: Uint
) is
8160 Set_DT_Position
(Prim
, Value
);
8162 -- Propagate the value to the wrapped subprogram (if one is present)
8164 if Ekind_In
(Prim
, E_Function
, E_Procedure
)
8165 and then Is_Primitive_Wrapper
(Prim
)
8166 and then Present
(Wrapped_Entity
(Prim
))
8167 and then Is_Dispatching_Operation
(Wrapped_Entity
(Prim
))
8169 Set_DT_Position
(Wrapped_Entity
(Prim
), Value
);
8171 end Set_DT_Position_Value
;
8173 --------------------------
8174 -- Set_DTC_Entity_Value --
8175 --------------------------
8177 procedure Set_DTC_Entity_Value
8178 (Tagged_Type
: Entity_Id
;
8182 if Present
(Interface_Alias
(Prim
))
8183 and then Is_Interface
8184 (Find_Dispatching_Type
(Interface_Alias
(Prim
)))
8186 Set_DTC_Entity
(Prim
,
8189 Iface
=> Find_Dispatching_Type
(Interface_Alias
(Prim
))));
8191 Set_DTC_Entity
(Prim
,
8192 First_Tag_Component
(Tagged_Type
));
8195 -- Propagate the value to the wrapped subprogram (if one is present)
8197 if Ekind_In
(Prim
, E_Function
, E_Procedure
)
8198 and then Is_Primitive_Wrapper
(Prim
)
8199 and then Present
(Wrapped_Entity
(Prim
))
8200 and then Is_Dispatching_Operation
(Wrapped_Entity
(Prim
))
8202 Set_DTC_Entity
(Wrapped_Entity
(Prim
), DTC_Entity
(Prim
));
8204 end Set_DTC_Entity_Value
;
8210 function Tagged_Kind
(T
: Entity_Id
) return Node_Id
is
8211 Conc_Typ
: Entity_Id
;
8212 Loc
: constant Source_Ptr
:= Sloc
(T
);
8216 (Is_Tagged_Type
(T
) and then RTE_Available
(RE_Tagged_Kind
));
8220 if Is_Abstract_Type
(T
) then
8221 if Is_Limited_Record
(T
) then
8222 return New_Occurrence_Of
8223 (RTE
(RE_TK_Abstract_Limited_Tagged
), Loc
);
8225 return New_Occurrence_Of
8226 (RTE
(RE_TK_Abstract_Tagged
), Loc
);
8231 elsif Is_Concurrent_Record_Type
(T
) then
8232 Conc_Typ
:= Corresponding_Concurrent_Type
(T
);
8234 if Present
(Full_View
(Conc_Typ
)) then
8235 Conc_Typ
:= Full_View
(Conc_Typ
);
8238 if Ekind
(Conc_Typ
) = E_Protected_Type
then
8239 return New_Occurrence_Of
(RTE
(RE_TK_Protected
), Loc
);
8241 pragma Assert
(Ekind
(Conc_Typ
) = E_Task_Type
);
8242 return New_Occurrence_Of
(RTE
(RE_TK_Task
), Loc
);
8245 -- Regular tagged kinds
8248 if Is_Limited_Record
(T
) then
8249 return New_Occurrence_Of
(RTE
(RE_TK_Limited_Tagged
), Loc
);
8251 return New_Occurrence_Of
(RTE
(RE_TK_Tagged
), Loc
);
8260 procedure Write_DT
(Typ
: Entity_Id
) is
8265 -- Protect this procedure against wrong usage. Required because it will
8266 -- be used directly from GDB
8268 if not (Typ
<= Last_Node_Id
)
8269 or else not Is_Tagged_Type
(Typ
)
8271 Write_Str
("wrong usage: Write_DT must be used with tagged types");
8276 Write_Int
(Int
(Typ
));
8278 Write_Name
(Chars
(Typ
));
8280 if Is_Interface
(Typ
) then
8281 Write_Str
(" is interface");
8286 Elmt
:= First_Elmt
(Primitive_Operations
(Typ
));
8287 while Present
(Elmt
) loop
8288 Prim
:= Node
(Elmt
);
8291 -- Indicate if this primitive will be allocated in the primary
8292 -- dispatch table or in a secondary dispatch table associated
8293 -- with an abstract interface type
8295 if Present
(DTC_Entity
(Prim
)) then
8296 if Etype
(DTC_Entity
(Prim
)) = RTE
(RE_Tag
) then
8303 -- Output the node of this primitive operation and its name
8305 Write_Int
(Int
(Prim
));
8308 if Is_Predefined_Dispatching_Operation
(Prim
) then
8309 Write_Str
("(predefined) ");
8312 -- Prefix the name of the primitive with its corresponding tagged
8313 -- type to facilitate seeing inherited primitives.
8315 if Present
(Alias
(Prim
)) then
8317 (Chars
(Find_Dispatching_Type
(Ultimate_Alias
(Prim
))));
8319 Write_Name
(Chars
(Typ
));
8323 Write_Name
(Chars
(Prim
));
8325 -- Indicate if this primitive has an aliased primitive
8327 if Present
(Alias
(Prim
)) then
8328 Write_Str
(" (alias = ");
8329 Write_Int
(Int
(Alias
(Prim
)));
8331 -- If the DTC_Entity attribute is already set we can also output
8332 -- the name of the interface covered by this primitive (if any).
8334 if Ekind_In
(Alias
(Prim
), E_Function
, E_Procedure
)
8335 and then Present
(DTC_Entity
(Alias
(Prim
)))
8336 and then Is_Interface
(Scope
(DTC_Entity
(Alias
(Prim
))))
8338 Write_Str
(" from interface ");
8339 Write_Name
(Chars
(Scope
(DTC_Entity
(Alias
(Prim
)))));
8342 if Present
(Interface_Alias
(Prim
)) then
8343 Write_Str
(", AI_Alias of ");
8345 if Is_Null_Interface_Primitive
(Interface_Alias
(Prim
)) then
8346 Write_Str
("null primitive ");
8350 (Chars
(Find_Dispatching_Type
(Interface_Alias
(Prim
))));
8352 Write_Int
(Int
(Interface_Alias
(Prim
)));
8358 -- Display the final position of this primitive in its associated
8359 -- (primary or secondary) dispatch table.
8361 if Present
(DTC_Entity
(Prim
))
8362 and then DT_Position
(Prim
) /= No_Uint
8364 Write_Str
(" at #");
8365 Write_Int
(UI_To_Int
(DT_Position
(Prim
)));
8368 if Is_Abstract_Subprogram
(Prim
) then
8369 Write_Str
(" is abstract;");
8371 -- Check if this is a null primitive
8373 elsif Comes_From_Source
(Prim
)
8374 and then Ekind
(Prim
) = E_Procedure
8375 and then Null_Present
(Parent
(Prim
))
8377 Write_Str
(" is null;");
8380 if Is_Eliminated
(Ultimate_Alias
(Prim
)) then
8381 Write_Str
(" (eliminated)");
8384 if Is_Imported
(Prim
)
8385 and then Convention
(Prim
) = Convention_CPP
8387 Write_Str
(" (C++)");