1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2010, 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_Ch7
; use Exp_Ch7
;
34 with Exp_CG
; use Exp_CG
;
35 with Exp_Dbug
; use Exp_Dbug
;
36 with Exp_Tss
; use Exp_Tss
;
37 with Exp_Util
; use Exp_Util
;
38 with Freeze
; use Freeze
;
39 with Itypes
; use Itypes
;
40 with Layout
; use Layout
;
41 with Nlists
; use Nlists
;
42 with Nmake
; use Nmake
;
43 with Namet
; use Namet
;
45 with Output
; use Output
;
46 with Restrict
; use Restrict
;
47 with Rident
; use Rident
;
48 with Rtsfind
; use Rtsfind
;
50 with Sem_Aux
; use Sem_Aux
;
51 with Sem_Ch6
; use Sem_Ch6
;
52 with Sem_Ch7
; use Sem_Ch7
;
53 with Sem_Ch8
; use Sem_Ch8
;
54 with Sem_Disp
; use Sem_Disp
;
55 with Sem_Eval
; use Sem_Eval
;
56 with Sem_Res
; use Sem_Res
;
57 with Sem_Type
; use Sem_Type
;
58 with Sem_Util
; use Sem_Util
;
59 with Sinfo
; use Sinfo
;
60 with Snames
; use Snames
;
61 with Stand
; use Stand
;
62 with Stringt
; use Stringt
;
63 with SCIL_LL
; use SCIL_LL
;
64 with Tbuild
; use Tbuild
;
65 with Uintp
; use Uintp
;
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
87 -- to Duplicate_Subexpr with an explicit dereference when From is an
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
92 -- in 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 need
128 -- a check to see whether expansion is active before proceeding. In
129 -- addition, there is no need to expand the call when compiling under
130 -- 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
:= Root_Type
(CW_Typ
);
182 if Ekind
(Typ
) = E_Incomplete_Type
then
183 Typ
:= Non_Limited_View
(Typ
);
186 if not Is_Limited_Type
(Typ
) then
187 Eq_Prim_Op
:= Find_Prim_Op
(Typ
, Name_Op_Eq
);
190 -- Dispatching call to C++ primitive
192 if Is_CPP_Class
(Typ
) then
195 -- Dispatching call to Ada primitive
197 elsif Present
(Param_List
) then
199 -- Generate the Tag checks when appropriate
201 Param
:= First_Actual
(Call_Node
);
202 while Present
(Param
) loop
204 -- No tag check with itself
206 if Param
= Ctrl_Arg
then
209 -- No tag check for parameter whose type is neither tagged nor
210 -- access to tagged (for access parameters)
212 elsif No
(Find_Controlling_Arg
(Param
)) then
215 -- No tag check for function dispatching on result if the
216 -- Tag given by the context is this one
218 elsif Find_Controlling_Arg
(Param
) = Ctrl_Arg
then
221 -- "=" is the only dispatching operation allowed to get
222 -- operands with incompatible tags (it just returns false).
223 -- We use Duplicate_Subexpr_Move_Checks instead of calling
224 -- Relocate_Node because the value will be duplicated to
227 elsif Subp
= Eq_Prim_Op
then
230 -- No check in presence of suppress flags
232 elsif Tag_Checks_Suppressed
(Etype
(Param
))
233 or else (Is_Access_Type
(Etype
(Param
))
234 and then Tag_Checks_Suppressed
235 (Designated_Type
(Etype
(Param
))))
239 -- Optimization: no tag checks if the parameters are identical
241 elsif Is_Entity_Name
(Param
)
242 and then Is_Entity_Name
(Ctrl_Arg
)
243 and then Entity
(Param
) = Entity
(Ctrl_Arg
)
247 -- Now we need to generate the Tag check
250 -- Generate code for tag equality check
251 -- Perhaps should have Checks.Apply_Tag_Equality_Check???
253 Insert_Action
(Ctrl_Arg
,
254 Make_Implicit_If_Statement
(Call_Node
,
258 Make_Selected_Component
(Loc
,
259 Prefix
=> New_Value
(Ctrl_Arg
),
262 (First_Tag_Component
(Typ
), Loc
)),
265 Make_Selected_Component
(Loc
,
267 Unchecked_Convert_To
(Typ
, New_Value
(Param
)),
270 (First_Tag_Component
(Typ
), Loc
))),
273 New_List
(New_Constraint_Error
(Loc
))));
279 end Apply_Tag_Checks
;
281 ------------------------
282 -- Building_Static_DT --
283 ------------------------
285 function Building_Static_DT
(Typ
: Entity_Id
) return Boolean is
286 Root_Typ
: Entity_Id
:= Root_Type
(Typ
);
289 -- Handle private types
291 if Present
(Full_View
(Root_Typ
)) then
292 Root_Typ
:= Full_View
(Root_Typ
);
295 return Static_Dispatch_Tables
296 and then Is_Library_Level_Tagged_Type
(Typ
)
298 -- If the type is derived from a CPP class we cannot statically
299 -- build the dispatch tables because we must inherit primitives
300 -- from the CPP side.
302 and then not Is_CPP_Class
(Root_Typ
);
303 end Building_Static_DT
;
305 ----------------------------------
306 -- Build_Static_Dispatch_Tables --
307 ----------------------------------
309 procedure Build_Static_Dispatch_Tables
(N
: Entity_Id
) is
310 Target_List
: List_Id
;
312 procedure Build_Dispatch_Tables
(List
: List_Id
);
313 -- Build the static dispatch table of tagged types found in the list of
314 -- declarations. The generated nodes are added at the end of Target_List
316 procedure Build_Package_Dispatch_Tables
(N
: Node_Id
);
317 -- Build static dispatch tables associated with package declaration N
319 ---------------------------
320 -- Build_Dispatch_Tables --
321 ---------------------------
323 procedure Build_Dispatch_Tables
(List
: List_Id
) is
328 while Present
(D
) loop
330 -- Handle nested packages and package bodies recursively. The
331 -- generated code is placed on the Target_List established for
332 -- the enclosing compilation unit.
334 if Nkind
(D
) = N_Package_Declaration
then
335 Build_Package_Dispatch_Tables
(D
);
337 elsif Nkind
(D
) = N_Package_Body
then
338 Build_Dispatch_Tables
(Declarations
(D
));
340 elsif Nkind
(D
) = N_Package_Body_Stub
341 and then Present
(Library_Unit
(D
))
343 Build_Dispatch_Tables
344 (Declarations
(Proper_Body
(Unit
(Library_Unit
(D
)))));
346 -- Handle full type declarations and derivations of library
347 -- level tagged types
349 elsif Nkind_In
(D
, N_Full_Type_Declaration
,
350 N_Derived_Type_Definition
)
351 and then Is_Library_Level_Tagged_Type
(Defining_Entity
(D
))
352 and then Ekind
(Defining_Entity
(D
)) /= E_Record_Subtype
353 and then not Is_Private_Type
(Defining_Entity
(D
))
355 -- We do not generate dispatch tables for the internal types
356 -- created for a type extension with unknown discriminants
357 -- The needed information is shared with the source type,
358 -- See Expand_N_Record_Extension.
360 if Is_Underlying_Record_View
(Defining_Entity
(D
))
362 (not Comes_From_Source
(Defining_Entity
(D
))
364 Has_Unknown_Discriminants
(Etype
(Defining_Entity
(D
)))
366 not Comes_From_Source
367 (First_Subtype
(Defining_Entity
(D
))))
371 Insert_List_After_And_Analyze
(Last
(Target_List
),
372 Make_DT
(Defining_Entity
(D
)));
375 -- Handle private types of library level tagged types. We must
376 -- exchange the private and full-view to ensure the correct
377 -- expansion. If the full view is a synchronized type ignore
378 -- the type because the table will be built for the corresponding
379 -- record type, that has its own declaration.
381 elsif (Nkind
(D
) = N_Private_Type_Declaration
382 or else Nkind
(D
) = N_Private_Extension_Declaration
)
383 and then Present
(Full_View
(Defining_Entity
(D
)))
386 E1
: constant Entity_Id
:= Defining_Entity
(D
);
387 E2
: constant Entity_Id
:= Full_View
(E1
);
390 if Is_Library_Level_Tagged_Type
(E2
)
391 and then Ekind
(E2
) /= E_Record_Subtype
392 and then not Is_Concurrent_Type
(E2
)
394 Exchange_Declarations
(E1
);
395 Insert_List_After_And_Analyze
(Last
(Target_List
),
397 Exchange_Declarations
(E2
);
404 end Build_Dispatch_Tables
;
406 -----------------------------------
407 -- Build_Package_Dispatch_Tables --
408 -----------------------------------
410 procedure Build_Package_Dispatch_Tables
(N
: Node_Id
) is
411 Spec
: constant Node_Id
:= Specification
(N
);
412 Id
: constant Entity_Id
:= Defining_Entity
(N
);
413 Vis_Decls
: constant List_Id
:= Visible_Declarations
(Spec
);
414 Priv_Decls
: constant List_Id
:= Private_Declarations
(Spec
);
419 if Present
(Priv_Decls
) then
420 Build_Dispatch_Tables
(Vis_Decls
);
421 Build_Dispatch_Tables
(Priv_Decls
);
423 elsif Present
(Vis_Decls
) then
424 Build_Dispatch_Tables
(Vis_Decls
);
428 end Build_Package_Dispatch_Tables
;
430 -- Start of processing for Build_Static_Dispatch_Tables
433 if not Expander_Active
434 or else not Tagged_Type_Expansion
439 if Nkind
(N
) = N_Package_Declaration
then
441 Spec
: constant Node_Id
:= Specification
(N
);
442 Vis_Decls
: constant List_Id
:= Visible_Declarations
(Spec
);
443 Priv_Decls
: constant List_Id
:= Private_Declarations
(Spec
);
446 if Present
(Priv_Decls
)
447 and then Is_Non_Empty_List
(Priv_Decls
)
449 Target_List
:= Priv_Decls
;
451 elsif not Present
(Vis_Decls
) then
452 Target_List
:= New_List
;
453 Set_Private_Declarations
(Spec
, Target_List
);
455 Target_List
:= Vis_Decls
;
458 Build_Package_Dispatch_Tables
(N
);
461 else pragma Assert
(Nkind
(N
) = N_Package_Body
);
462 Target_List
:= Declarations
(N
);
463 Build_Dispatch_Tables
(Target_List
);
465 end Build_Static_Dispatch_Tables
;
467 ------------------------------
468 -- Default_Prim_Op_Position --
469 ------------------------------
471 function Default_Prim_Op_Position
(E
: Entity_Id
) return Uint
is
472 TSS_Name
: TSS_Name_Type
;
475 Get_Name_String
(Chars
(E
));
478 (Name_Buffer
(Name_Len
- TSS_Name
'Length + 1 .. Name_Len
));
480 if Chars
(E
) = Name_uSize
then
483 elsif Chars
(E
) = Name_uAlignment
then
486 elsif TSS_Name
= TSS_Stream_Read
then
489 elsif TSS_Name
= TSS_Stream_Write
then
492 elsif TSS_Name
= TSS_Stream_Input
then
495 elsif TSS_Name
= TSS_Stream_Output
then
498 elsif Chars
(E
) = Name_Op_Eq
then
501 elsif Chars
(E
) = Name_uAssign
then
504 elsif TSS_Name
= TSS_Deep_Adjust
then
507 elsif TSS_Name
= TSS_Deep_Finalize
then
510 elsif Ada_Version
>= Ada_05
then
511 if Chars
(E
) = Name_uDisp_Asynchronous_Select
then
514 elsif Chars
(E
) = Name_uDisp_Conditional_Select
then
517 elsif Chars
(E
) = Name_uDisp_Get_Prim_Op_Kind
then
520 elsif Chars
(E
) = Name_uDisp_Get_Task_Id
then
523 elsif Chars
(E
) = Name_uDisp_Requeue
then
526 elsif Chars
(E
) = Name_uDisp_Timed_Select
then
532 end Default_Prim_Op_Position
;
534 -----------------------------
535 -- Expand_Dispatching_Call --
536 -----------------------------
538 procedure Expand_Dispatching_Call
(Call_Node
: Node_Id
) is
539 Loc
: constant Source_Ptr
:= Sloc
(Call_Node
);
540 Call_Typ
: constant Entity_Id
:= Etype
(Call_Node
);
542 Ctrl_Arg
: constant Node_Id
:= Controlling_Argument
(Call_Node
);
543 Ctrl_Typ
: constant Entity_Id
:= Base_Type
(Etype
(Ctrl_Arg
));
544 Param_List
: constant List_Id
:= Parameter_Associations
(Call_Node
);
549 New_Call_Name
: Node_Id
;
550 New_Params
: List_Id
:= No_List
;
553 Subp_Ptr_Typ
: Entity_Id
;
554 Subp_Typ
: Entity_Id
;
556 Eq_Prim_Op
: Entity_Id
:= Empty
;
557 Controlling_Tag
: Node_Id
;
559 function New_Value
(From
: Node_Id
) return Node_Id
;
560 -- From is the original Expression. New_Value is equivalent to a call
561 -- to Duplicate_Subexpr with an explicit dereference when From is an
568 function New_Value
(From
: Node_Id
) return Node_Id
is
569 Res
: constant Node_Id
:= Duplicate_Subexpr
(From
);
571 if Is_Access_Type
(Etype
(From
)) then
573 Make_Explicit_Dereference
(Sloc
(From
),
584 SCIL_Related_Node
: Node_Id
:= Call_Node
;
586 -- Start of processing for Expand_Dispatching_Call
589 if No_Run_Time_Mode
then
590 Error_Msg_CRT
("tagged types", Call_Node
);
594 -- Expand_Dispatching_Call is called directly from the semantics,
595 -- so we need a check to see whether expansion is active before
596 -- proceeding. In addition, there is no need to expand the call
597 -- if we are compiling under restriction No_Dispatching_Calls;
598 -- the semantic analyzer has previously notified the violation
599 -- of this restriction.
601 if not Expander_Active
602 or else Restriction_Active
(No_Dispatching_Calls
)
607 -- Set subprogram. If this is an inherited operation that was
608 -- overridden, the body that is being called is its alias.
610 Subp
:= Entity
(Name
(Call_Node
));
612 if Present
(Alias
(Subp
))
613 and then Is_Inherited_Operation
(Subp
)
614 and then No
(DTC_Entity
(Subp
))
616 Subp
:= Alias
(Subp
);
619 -- Definition of the class-wide type and the tagged type
621 -- If the controlling argument is itself a tag rather than a tagged
622 -- object, then use the class-wide type associated with the subprogram's
623 -- controlling type. This case can occur when a call to an inherited
624 -- primitive has an actual that originated from a default parameter
625 -- given by a tag-indeterminate call and when there is no other
626 -- controlling argument providing the tag (AI-239 requires dispatching).
627 -- This capability of dispatching directly by tag is also needed by the
628 -- implementation of AI-260 (for the generic dispatching constructors).
630 if Ctrl_Typ
= RTE
(RE_Tag
)
631 or else (RTE_Available
(RE_Interface_Tag
)
632 and then Ctrl_Typ
= RTE
(RE_Interface_Tag
))
634 CW_Typ
:= Class_Wide_Type
(Find_Dispatching_Type
(Subp
));
636 -- Class_Wide_Type is applied to the expressions used to initialize
637 -- CW_Typ, to ensure that CW_Typ always denotes a class-wide type, since
638 -- there are cases where the controlling type is resolved to a specific
639 -- type (such as for designated types of arguments such as CW'Access).
641 elsif Is_Access_Type
(Ctrl_Typ
) then
642 CW_Typ
:= Class_Wide_Type
(Designated_Type
(Ctrl_Typ
));
645 CW_Typ
:= Class_Wide_Type
(Ctrl_Typ
);
648 Typ
:= Root_Type
(CW_Typ
);
650 if Ekind
(Typ
) = E_Incomplete_Type
then
651 Typ
:= Non_Limited_View
(Typ
);
654 if not Is_Limited_Type
(Typ
) then
655 Eq_Prim_Op
:= Find_Prim_Op
(Typ
, Name_Op_Eq
);
658 -- Dispatching call to C++ primitive. Create a new parameter list
659 -- with no tag checks.
661 New_Params
:= New_List
;
663 if Is_CPP_Class
(Typ
) then
664 Param
:= First_Actual
(Call_Node
);
665 while Present
(Param
) loop
666 Append_To
(New_Params
, Relocate_Node
(Param
));
670 -- Dispatching call to Ada primitive
672 elsif Present
(Param_List
) then
673 Apply_Tag_Checks
(Call_Node
);
675 Param
:= First_Actual
(Call_Node
);
676 while Present
(Param
) loop
677 -- Cases in which we may have generated runtime checks
680 or else Subp
= Eq_Prim_Op
682 Append_To
(New_Params
,
683 Duplicate_Subexpr_Move_Checks
(Param
));
685 elsif Nkind
(Parent
(Param
)) /= N_Parameter_Association
686 or else not Is_Accessibility_Actual
(Parent
(Param
))
688 Append_To
(New_Params
, Relocate_Node
(Param
));
695 -- Generate the appropriate subprogram pointer type
697 if Etype
(Subp
) = Typ
then
700 Res_Typ
:= Etype
(Subp
);
703 Subp_Typ
:= Create_Itype
(E_Subprogram_Type
, Call_Node
);
704 Subp_Ptr_Typ
:= Create_Itype
(E_Access_Subprogram_Type
, Call_Node
);
705 Set_Etype
(Subp_Typ
, Res_Typ
);
706 Set_Returns_By_Ref
(Subp_Typ
, Returns_By_Ref
(Subp
));
708 -- Create a new list of parameters which is a copy of the old formal
709 -- list including the creation of a new set of matching entities.
712 Old_Formal
: Entity_Id
:= First_Formal
(Subp
);
713 New_Formal
: Entity_Id
;
714 Extra
: Entity_Id
:= Empty
;
717 if Present
(Old_Formal
) then
718 New_Formal
:= New_Copy
(Old_Formal
);
719 Set_First_Entity
(Subp_Typ
, New_Formal
);
720 Param
:= First_Actual
(Call_Node
);
723 Set_Scope
(New_Formal
, Subp_Typ
);
725 -- Change all the controlling argument types to be class-wide
726 -- to avoid a recursion in dispatching.
728 if Is_Controlling_Formal
(New_Formal
) then
729 Set_Etype
(New_Formal
, Etype
(Param
));
732 -- If the type of the formal is an itype, there was code here
733 -- introduced in 1998 in revision 1.46, to create a new itype
734 -- by copy. This seems useless, and in fact leads to semantic
735 -- errors when the itype is the completion of a type derived
736 -- from a private type.
739 Next_Formal
(Old_Formal
);
740 exit when No
(Old_Formal
);
742 Set_Next_Entity
(New_Formal
, New_Copy
(Old_Formal
));
743 Next_Entity
(New_Formal
);
747 Set_Next_Entity
(New_Formal
, Empty
);
748 Set_Last_Entity
(Subp_Typ
, Extra
);
751 -- Now that the explicit formals have been duplicated, any extra
752 -- formals needed by the subprogram must be created.
754 if Present
(Extra
) then
755 Set_Extra_Formal
(Extra
, Empty
);
758 Create_Extra_Formals
(Subp_Typ
);
761 -- Complete description of pointer type, including size information, as
762 -- must be done with itypes to prevent order-of-elaboration anomalies
765 Set_Etype
(Subp_Ptr_Typ
, Subp_Ptr_Typ
);
766 Set_Directly_Designated_Type
(Subp_Ptr_Typ
, Subp_Typ
);
767 Set_Convention
(Subp_Ptr_Typ
, Convention
(Subp_Typ
));
768 Layout_Type
(Subp_Ptr_Typ
);
770 -- If the controlling argument is a value of type Ada.Tag or an abstract
771 -- interface class-wide type then use it directly. Otherwise, the tag
772 -- must be extracted from the controlling object.
774 if Ctrl_Typ
= RTE
(RE_Tag
)
775 or else (RTE_Available
(RE_Interface_Tag
)
776 and then Ctrl_Typ
= RTE
(RE_Interface_Tag
))
778 Controlling_Tag
:= Duplicate_Subexpr
(Ctrl_Arg
);
780 -- Extract the tag from an unchecked type conversion. Done to avoid
781 -- the expansion of additional code just to obtain the value of such
782 -- tag because the current management of interface type conversions
783 -- generates in some cases this unchecked type conversion with the
784 -- tag of the object (see Expand_Interface_Conversion).
786 elsif Nkind
(Ctrl_Arg
) = N_Unchecked_Type_Conversion
788 (Etype
(Expression
(Ctrl_Arg
)) = RTE
(RE_Tag
)
790 (RTE_Available
(RE_Interface_Tag
)
792 Etype
(Expression
(Ctrl_Arg
)) = RTE
(RE_Interface_Tag
)))
794 Controlling_Tag
:= Duplicate_Subexpr
(Expression
(Ctrl_Arg
));
796 -- Ada 2005 (AI-251): Abstract interface class-wide type
798 elsif Is_Interface
(Ctrl_Typ
)
799 and then Is_Class_Wide_Type
(Ctrl_Typ
)
801 Controlling_Tag
:= Duplicate_Subexpr
(Ctrl_Arg
);
805 Make_Selected_Component
(Loc
,
806 Prefix
=> Duplicate_Subexpr_Move_Checks
(Ctrl_Arg
),
807 Selector_Name
=> New_Reference_To
(DTC_Entity
(Subp
), Loc
));
810 -- Handle dispatching calls to predefined primitives
812 if Is_Predefined_Dispatching_Operation
(Subp
)
813 or else Is_Predefined_Dispatching_Alias
(Subp
)
815 Build_Get_Predefined_Prim_Op_Address
(Loc
,
816 Tag_Node
=> Controlling_Tag
,
817 Position
=> DT_Position
(Subp
),
818 New_Node
=> New_Node
);
820 -- Handle dispatching calls to user-defined primitives
823 Build_Get_Prim_Op_Address
(Loc
,
824 Typ
=> Find_Dispatching_Type
(Subp
),
825 Tag_Node
=> Controlling_Tag
,
826 Position
=> DT_Position
(Subp
),
827 New_Node
=> New_Node
);
831 Unchecked_Convert_To
(Subp_Ptr_Typ
, New_Node
);
833 -- Generate the SCIL node for this dispatching call. Done now because
834 -- attribute SCIL_Controlling_Tag must be set after the new call name
835 -- is built to reference the nodes that will see the SCIL backend
836 -- (because Build_Get_Prim_Op_Address generates an unchecked type
837 -- conversion which relocates the controlling tag node).
839 if Generate_SCIL
then
840 SCIL_Node
:= Make_SCIL_Dispatching_Call
(Sloc
(Call_Node
));
841 Set_SCIL_Entity
(SCIL_Node
, Typ
);
842 Set_SCIL_Target_Prim
(SCIL_Node
, Subp
);
844 -- Common case: the controlling tag is the tag of an object
845 -- (for example, obj.tag)
847 if Nkind
(Controlling_Tag
) = N_Selected_Component
then
848 Set_SCIL_Controlling_Tag
(SCIL_Node
, Controlling_Tag
);
850 -- Handle renaming of selected component
852 elsif Nkind
(Controlling_Tag
) = N_Identifier
853 and then Nkind
(Parent
(Entity
(Controlling_Tag
))) =
854 N_Object_Renaming_Declaration
855 and then Nkind
(Name
(Parent
(Entity
(Controlling_Tag
)))) =
858 Set_SCIL_Controlling_Tag
(SCIL_Node
,
859 Name
(Parent
(Entity
(Controlling_Tag
))));
861 -- If the controlling tag is an identifier, the SCIL node references
862 -- the corresponding object or parameter declaration
864 elsif Nkind
(Controlling_Tag
) = N_Identifier
865 and then Nkind_In
(Parent
(Entity
(Controlling_Tag
)),
866 N_Object_Declaration
,
867 N_Parameter_Specification
)
869 Set_SCIL_Controlling_Tag
(SCIL_Node
,
870 Parent
(Entity
(Controlling_Tag
)));
872 -- If the controlling tag is a dereference, the SCIL node references
873 -- the corresponding object or parameter declaration
875 elsif Nkind
(Controlling_Tag
) = N_Explicit_Dereference
876 and then Nkind
(Prefix
(Controlling_Tag
)) = N_Identifier
877 and then Nkind_In
(Parent
(Entity
(Prefix
(Controlling_Tag
))),
878 N_Object_Declaration
,
879 N_Parameter_Specification
)
881 Set_SCIL_Controlling_Tag
(SCIL_Node
,
882 Parent
(Entity
(Prefix
(Controlling_Tag
))));
884 -- For a direct reference of the tag of the type the SCIL node
885 -- references the the internal object declaration containing the tag
888 elsif Nkind
(Controlling_Tag
) = N_Attribute_Reference
889 and then Attribute_Name
(Controlling_Tag
) = Name_Tag
891 Set_SCIL_Controlling_Tag
(SCIL_Node
,
895 (Access_Disp_Table
(Entity
(Prefix
(Controlling_Tag
)))))));
897 -- Interfaces are not supported. For now we leave the SCIL node
898 -- decorated with the Controlling_Tag. More work needed here???
900 elsif Is_Interface
(Etype
(Controlling_Tag
)) then
901 Set_SCIL_Controlling_Tag
(SCIL_Node
, Controlling_Tag
);
904 pragma Assert
(False);
909 if Nkind
(Call_Node
) = N_Function_Call
then
911 Make_Function_Call
(Loc
,
912 Name
=> New_Call_Name
,
913 Parameter_Associations
=> New_Params
);
915 -- If this is a dispatching "=", we must first compare the tags so
916 -- we generate: x.tag = y.tag and then x = y
918 if Subp
= Eq_Prim_Op
then
919 Param
:= First_Actual
(Call_Node
);
925 Make_Selected_Component
(Loc
,
926 Prefix
=> New_Value
(Param
),
928 New_Reference_To
(First_Tag_Component
(Typ
),
932 Make_Selected_Component
(Loc
,
934 Unchecked_Convert_To
(Typ
,
935 New_Value
(Next_Actual
(Param
))),
938 (First_Tag_Component
(Typ
), Loc
))),
939 Right_Opnd
=> New_Call
);
941 SCIL_Related_Node
:= Right_Opnd
(New_Call
);
946 Make_Procedure_Call_Statement
(Loc
,
947 Name
=> New_Call_Name
,
948 Parameter_Associations
=> New_Params
);
951 -- Register the dispatching call in the call graph nodes table
953 Register_CG_Node
(Call_Node
);
955 Rewrite
(Call_Node
, New_Call
);
957 -- Associate the SCIL node of this dispatching call
959 if Generate_SCIL
then
960 Set_SCIL_Node
(SCIL_Related_Node
, SCIL_Node
);
963 -- Suppress all checks during the analysis of the expanded code
964 -- to avoid the generation of spurious warnings under ZFP run-time.
966 Analyze_And_Resolve
(Call_Node
, Call_Typ
, Suppress
=> All_Checks
);
967 end Expand_Dispatching_Call
;
969 ---------------------------------
970 -- Expand_Interface_Conversion --
971 ---------------------------------
973 procedure Expand_Interface_Conversion
975 Is_Static
: Boolean := True)
977 Loc
: constant Source_Ptr
:= Sloc
(N
);
978 Etyp
: constant Entity_Id
:= Etype
(N
);
979 Operand
: constant Node_Id
:= Expression
(N
);
980 Operand_Typ
: Entity_Id
:= Etype
(Operand
);
982 Iface_Typ
: Entity_Id
:= Etype
(N
);
983 Iface_Tag
: Entity_Id
;
986 -- Ada 2005 (AI-345): Handle synchronized interface type derivations
988 if Is_Concurrent_Type
(Operand_Typ
) then
989 Operand_Typ
:= Base_Type
(Corresponding_Record_Type
(Operand_Typ
));
992 -- Handle access to class-wide interface types
994 if Is_Access_Type
(Iface_Typ
) then
995 Iface_Typ
:= Etype
(Directly_Designated_Type
(Iface_Typ
));
998 -- Handle class-wide interface types. This conversion can appear
999 -- explicitly in the source code. Example: I'Class (Obj)
1001 if Is_Class_Wide_Type
(Iface_Typ
) then
1002 Iface_Typ
:= Root_Type
(Iface_Typ
);
1005 -- If the target type is a tagged synchronized type, the dispatch table
1006 -- info is in the corresponding record type.
1008 if Is_Concurrent_Type
(Iface_Typ
) then
1009 Iface_Typ
:= Corresponding_Record_Type
(Iface_Typ
);
1012 -- Freeze the entity associated with the target interface to have
1013 -- available the attribute Access_Disp_Table.
1015 Freeze_Before
(N
, Iface_Typ
);
1017 pragma Assert
(not Is_Static
1018 or else (not Is_Class_Wide_Type
(Iface_Typ
)
1019 and then Is_Interface
(Iface_Typ
)));
1021 if not Tagged_Type_Expansion
then
1023 -- For VM, just do a conversion ???
1025 Rewrite
(N
, Unchecked_Convert_To
(Etype
(N
), N
));
1030 if not Is_Static
then
1032 -- Give error if configurable run time and Displace not available
1034 if not RTE_Available
(RE_Displace
) then
1035 Error_Msg_CRT
("dynamic interface conversion", N
);
1039 -- Handle conversion of access-to-class-wide interface types. Target
1040 -- can be an access to an object or an access to another class-wide
1041 -- interface (see -1- and -2- in the following example):
1043 -- type Iface1_Ref is access all Iface1'Class;
1044 -- type Iface2_Ref is access all Iface1'Class;
1046 -- Acc1 : Iface1_Ref := new ...
1047 -- Obj : Obj_Ref := Obj_Ref (Acc); -- 1
1048 -- Acc2 : Iface2_Ref := Iface2_Ref (Acc); -- 2
1050 if Is_Access_Type
(Operand_Typ
) then
1052 Unchecked_Convert_To
(Etype
(N
),
1053 Make_Function_Call
(Loc
,
1054 Name
=> New_Reference_To
(RTE
(RE_Displace
), Loc
),
1055 Parameter_Associations
=> New_List
(
1057 Unchecked_Convert_To
(RTE
(RE_Address
),
1058 Relocate_Node
(Expression
(N
))),
1061 (Node
(First_Elmt
(Access_Disp_Table
(Iface_Typ
))),
1069 Make_Function_Call
(Loc
,
1070 Name
=> New_Reference_To
(RTE
(RE_Displace
), Loc
),
1071 Parameter_Associations
=> New_List
(
1072 Make_Attribute_Reference
(Loc
,
1073 Prefix
=> Relocate_Node
(Expression
(N
)),
1074 Attribute_Name
=> Name_Address
),
1077 (Node
(First_Elmt
(Access_Disp_Table
(Iface_Typ
))),
1082 -- If the target is a class-wide interface we change the type of the
1083 -- data returned by IW_Convert to indicate that this is a dispatching
1087 New_Itype
: Entity_Id
;
1090 New_Itype
:= Create_Itype
(E_Anonymous_Access_Type
, N
);
1091 Set_Etype
(New_Itype
, New_Itype
);
1092 Set_Directly_Designated_Type
(New_Itype
, Etyp
);
1095 Make_Explicit_Dereference
(Loc
,
1097 Unchecked_Convert_To
(New_Itype
, Relocate_Node
(N
))));
1099 Freeze_Itype
(New_Itype
, N
);
1105 Iface_Tag
:= Find_Interface_Tag
(Operand_Typ
, Iface_Typ
);
1106 pragma Assert
(Iface_Tag
/= Empty
);
1108 -- Keep separate access types to interfaces because one internal
1109 -- function is used to handle the null value (see following comment)
1111 if not Is_Access_Type
(Etype
(N
)) then
1113 Unchecked_Convert_To
(Etype
(N
),
1114 Make_Selected_Component
(Loc
,
1115 Prefix
=> Relocate_Node
(Expression
(N
)),
1117 New_Occurrence_Of
(Iface_Tag
, Loc
))));
1120 -- Build internal function to handle the case in which the
1121 -- actual is null. If the actual is null returns null because
1122 -- no displacement is required; otherwise performs a type
1123 -- conversion that will be expanded in the code that returns
1124 -- the value of the displaced actual. That is:
1126 -- function Func (O : Address) return Iface_Typ is
1127 -- type Op_Typ is access all Operand_Typ;
1128 -- Aux : Op_Typ := To_Op_Typ (O);
1130 -- if O = Null_Address then
1133 -- return Iface_Typ!(Aux.Iface_Tag'Address);
1138 Desig_Typ
: Entity_Id
;
1140 New_Typ_Decl
: Node_Id
;
1144 Desig_Typ
:= Etype
(Expression
(N
));
1146 if Is_Access_Type
(Desig_Typ
) then
1148 Available_View
(Directly_Designated_Type
(Desig_Typ
));
1151 if Is_Concurrent_Type
(Desig_Typ
) then
1152 Desig_Typ
:= Base_Type
(Corresponding_Record_Type
(Desig_Typ
));
1156 Make_Full_Type_Declaration
(Loc
,
1157 Defining_Identifier
=> Make_Temporary
(Loc
, 'T'),
1159 Make_Access_To_Object_Definition
(Loc
,
1160 All_Present
=> True,
1161 Null_Exclusion_Present
=> False,
1162 Constant_Present
=> False,
1163 Subtype_Indication
=>
1164 New_Reference_To
(Desig_Typ
, Loc
)));
1167 Make_Simple_Return_Statement
(Loc
,
1168 Unchecked_Convert_To
(Etype
(N
),
1169 Make_Attribute_Reference
(Loc
,
1171 Make_Selected_Component
(Loc
,
1173 Unchecked_Convert_To
1174 (Defining_Identifier
(New_Typ_Decl
),
1175 Make_Identifier
(Loc
, Name_uO
)),
1177 New_Occurrence_Of
(Iface_Tag
, Loc
)),
1178 Attribute_Name
=> Name_Address
))));
1180 -- If the type is null-excluding, no need for the null branch.
1181 -- Otherwise we need to check for it and return null.
1183 if not Can_Never_Be_Null
(Etype
(N
)) then
1185 Make_If_Statement
(Loc
,
1188 Left_Opnd
=> Make_Identifier
(Loc
, Name_uO
),
1189 Right_Opnd
=> New_Reference_To
1190 (RTE
(RE_Null_Address
), Loc
)),
1192 Then_Statements
=> New_List
(
1193 Make_Simple_Return_Statement
(Loc
,
1195 Else_Statements
=> Stats
));
1198 Fent
:= Make_Temporary
(Loc
, 'F');
1200 Make_Subprogram_Body
(Loc
,
1202 Make_Function_Specification
(Loc
,
1203 Defining_Unit_Name
=> Fent
,
1205 Parameter_Specifications
=> New_List
(
1206 Make_Parameter_Specification
(Loc
,
1207 Defining_Identifier
=>
1208 Make_Defining_Identifier
(Loc
, Name_uO
),
1210 New_Reference_To
(RTE
(RE_Address
), Loc
))),
1212 Result_Definition
=>
1213 New_Reference_To
(Etype
(N
), Loc
)),
1215 Declarations
=> New_List
(New_Typ_Decl
),
1217 Handled_Statement_Sequence
=>
1218 Make_Handled_Sequence_Of_Statements
(Loc
, Stats
));
1220 -- Place function body before the expression containing the
1221 -- conversion. We suppress all checks because the body of the
1222 -- internally generated function already takes care of the case
1223 -- in which the actual is null; therefore there is no need to
1224 -- double check that the pointer is not null when the program
1225 -- executes the alternative that performs the type conversion).
1227 Insert_Action
(N
, Func
, Suppress
=> All_Checks
);
1229 if Is_Access_Type
(Etype
(Expression
(N
))) then
1231 -- Generate: Func (Address!(Expression))
1234 Make_Function_Call
(Loc
,
1235 Name
=> New_Reference_To
(Fent
, Loc
),
1236 Parameter_Associations
=> New_List
(
1237 Unchecked_Convert_To
(RTE
(RE_Address
),
1238 Relocate_Node
(Expression
(N
))))));
1241 -- Generate: Func (Operand_Typ!(Expression)'Address)
1244 Make_Function_Call
(Loc
,
1245 Name
=> New_Reference_To
(Fent
, Loc
),
1246 Parameter_Associations
=> New_List
(
1247 Make_Attribute_Reference
(Loc
,
1248 Prefix
=> Unchecked_Convert_To
(Operand_Typ
,
1249 Relocate_Node
(Expression
(N
))),
1250 Attribute_Name
=> Name_Address
))));
1256 end Expand_Interface_Conversion
;
1258 ------------------------------
1259 -- Expand_Interface_Actuals --
1260 ------------------------------
1262 procedure Expand_Interface_Actuals
(Call_Node
: Node_Id
) is
1264 Actual_Dup
: Node_Id
;
1265 Actual_Typ
: Entity_Id
;
1267 Conversion
: Node_Id
;
1269 Formal_Typ
: Entity_Id
;
1271 Formal_DDT
: Entity_Id
;
1272 Actual_DDT
: Entity_Id
;
1275 -- This subprogram is called directly from the semantics, so we need a
1276 -- check to see whether expansion is active before proceeding.
1278 if not Expander_Active
then
1282 -- Call using access to subprogram with explicit dereference
1284 if Nkind
(Name
(Call_Node
)) = N_Explicit_Dereference
then
1285 Subp
:= Etype
(Name
(Call_Node
));
1287 -- Call using selected component
1289 elsif Nkind
(Name
(Call_Node
)) = N_Selected_Component
then
1290 Subp
:= Entity
(Selector_Name
(Name
(Call_Node
)));
1292 -- Call using direct name
1295 Subp
:= Entity
(Name
(Call_Node
));
1298 -- Ada 2005 (AI-251): Look for interface type formals to force "this"
1301 Formal
:= First_Formal
(Subp
);
1302 Actual
:= First_Actual
(Call_Node
);
1303 while Present
(Formal
) loop
1304 Formal_Typ
:= Etype
(Formal
);
1306 if Ekind
(Formal_Typ
) = E_Record_Type_With_Private
then
1307 Formal_Typ
:= Full_View
(Formal_Typ
);
1310 if Is_Access_Type
(Formal_Typ
) then
1311 Formal_DDT
:= Directly_Designated_Type
(Formal_Typ
);
1314 Actual_Typ
:= Etype
(Actual
);
1316 if Is_Access_Type
(Actual_Typ
) then
1317 Actual_DDT
:= Directly_Designated_Type
(Actual_Typ
);
1320 if Is_Interface
(Formal_Typ
)
1321 and then Is_Class_Wide_Type
(Formal_Typ
)
1323 -- No need to displace the pointer if the type of the actual
1324 -- coindices with the type of the formal.
1326 if Actual_Typ
= Formal_Typ
then
1329 -- No need to displace the pointer if the interface type is
1330 -- a parent of the type of the actual because in this case the
1331 -- interface primitives are located in the primary dispatch table.
1333 elsif Is_Ancestor
(Formal_Typ
, Actual_Typ
) then
1336 -- Implicit conversion to the class-wide formal type to force
1337 -- the displacement of the pointer.
1340 Conversion
:= Convert_To
(Formal_Typ
, Relocate_Node
(Actual
));
1341 Rewrite
(Actual
, Conversion
);
1342 Analyze_And_Resolve
(Actual
, Formal_Typ
);
1345 -- Access to class-wide interface type
1347 elsif Is_Access_Type
(Formal_Typ
)
1348 and then Is_Interface
(Formal_DDT
)
1349 and then Is_Class_Wide_Type
(Formal_DDT
)
1350 and then Interface_Present_In_Ancestor
1352 Iface
=> Etype
(Formal_DDT
))
1354 -- Handle attributes 'Access and 'Unchecked_Access
1356 if Nkind
(Actual
) = N_Attribute_Reference
1358 (Attribute_Name
(Actual
) = Name_Access
1359 or else Attribute_Name
(Actual
) = Name_Unchecked_Access
)
1361 -- This case must have been handled by the analysis and
1362 -- expansion of 'Access. The only exception is when types
1363 -- match and no further expansion is required.
1365 pragma Assert
(Base_Type
(Etype
(Prefix
(Actual
)))
1366 = Base_Type
(Formal_DDT
));
1369 -- No need to displace the pointer if the type of the actual
1370 -- coincides with the type of the formal.
1372 elsif Actual_DDT
= Formal_DDT
then
1375 -- No need to displace the pointer if the interface type is
1376 -- a parent of the type of the actual because in this case the
1377 -- interface primitives are located in the primary dispatch table.
1379 elsif Is_Ancestor
(Formal_DDT
, Actual_DDT
) then
1383 Actual_Dup
:= Relocate_Node
(Actual
);
1385 if From_With_Type
(Actual_Typ
) then
1387 -- If the type of the actual parameter comes from a limited
1388 -- with-clause and the non-limited view is already available
1389 -- we replace the anonymous access type by a duplicate
1390 -- declaration whose designated type is the non-limited view
1392 if Ekind
(Actual_DDT
) = E_Incomplete_Type
1393 and then Present
(Non_Limited_View
(Actual_DDT
))
1395 Anon
:= New_Copy
(Actual_Typ
);
1397 if Is_Itype
(Anon
) then
1398 Set_Scope
(Anon
, Current_Scope
);
1401 Set_Directly_Designated_Type
(Anon
,
1402 Non_Limited_View
(Actual_DDT
));
1403 Set_Etype
(Actual_Dup
, Anon
);
1405 elsif Is_Class_Wide_Type
(Actual_DDT
)
1406 and then Ekind
(Etype
(Actual_DDT
)) = E_Incomplete_Type
1407 and then Present
(Non_Limited_View
(Etype
(Actual_DDT
)))
1409 Anon
:= New_Copy
(Actual_Typ
);
1411 if Is_Itype
(Anon
) then
1412 Set_Scope
(Anon
, Current_Scope
);
1415 Set_Directly_Designated_Type
(Anon
,
1416 New_Copy
(Actual_DDT
));
1417 Set_Class_Wide_Type
(Directly_Designated_Type
(Anon
),
1418 New_Copy
(Class_Wide_Type
(Actual_DDT
)));
1419 Set_Etype
(Directly_Designated_Type
(Anon
),
1420 Non_Limited_View
(Etype
(Actual_DDT
)));
1422 Class_Wide_Type
(Directly_Designated_Type
(Anon
)),
1423 Non_Limited_View
(Etype
(Actual_DDT
)));
1424 Set_Etype
(Actual_Dup
, Anon
);
1428 Conversion
:= Convert_To
(Formal_Typ
, Actual_Dup
);
1429 Rewrite
(Actual
, Conversion
);
1430 Analyze_And_Resolve
(Actual
, Formal_Typ
);
1434 Next_Actual
(Actual
);
1435 Next_Formal
(Formal
);
1437 end Expand_Interface_Actuals
;
1439 ----------------------------
1440 -- Expand_Interface_Thunk --
1441 ----------------------------
1443 procedure Expand_Interface_Thunk
1445 Thunk_Id
: out Entity_Id
;
1446 Thunk_Code
: out Node_Id
)
1448 Loc
: constant Source_Ptr
:= Sloc
(Prim
);
1449 Actuals
: constant List_Id
:= New_List
;
1450 Decl
: constant List_Id
:= New_List
;
1451 Formals
: constant List_Id
:= New_List
;
1452 Target
: constant Entity_Id
:= Ultimate_Alias
(Prim
);
1454 Controlling_Typ
: Entity_Id
;
1460 Iface_Formal
: Node_Id
;
1462 Offset_To_Top
: Node_Id
;
1463 Target_Formal
: Entity_Id
;
1467 Thunk_Code
:= Empty
;
1469 -- No thunk needed if the primitive has been eliminated
1471 if Is_Eliminated
(Ultimate_Alias
(Prim
)) then
1474 -- In case of primitives that are functions without formals and a
1475 -- controlling result there is no need to build the thunk.
1477 elsif not Present
(First_Formal
(Target
)) then
1478 pragma Assert
(Ekind
(Target
) = E_Function
1479 and then Has_Controlling_Result
(Target
));
1483 -- Duplicate the formals of the Target primitive. In the thunk, the type
1484 -- of the controlling formal is the covered interface type (instead of
1485 -- the target tagged type). Done to avoid problems with discriminated
1486 -- tagged types because, if the controlling type has discriminants with
1487 -- default values, then the type conversions done inside the body of
1488 -- the thunk (after the displacement of the pointer to the base of the
1489 -- actual object) generate code that modify its contents.
1491 -- Note: This special management is not done for predefined primitives
1494 if not Is_Predefined_Dispatching_Operation
(Prim
) then
1495 Iface_Formal
:= First_Formal
(Interface_Alias
(Prim
));
1498 Formal
:= First_Formal
(Target
);
1499 while Present
(Formal
) loop
1500 Ftyp
:= Etype
(Formal
);
1502 -- Use the interface type as the type of the controlling formal (see
1505 if not Is_Controlling_Formal
(Formal
)
1506 or else Is_Predefined_Dispatching_Operation
(Prim
)
1508 Ftyp
:= Etype
(Formal
);
1509 Expr
:= New_Copy_Tree
(Expression
(Parent
(Formal
)));
1511 Ftyp
:= Etype
(Iface_Formal
);
1516 Make_Parameter_Specification
(Loc
,
1517 Defining_Identifier
=>
1518 Make_Defining_Identifier
(Sloc
(Formal
),
1519 Chars
=> Chars
(Formal
)),
1520 In_Present
=> In_Present
(Parent
(Formal
)),
1521 Out_Present
=> Out_Present
(Parent
(Formal
)),
1522 Parameter_Type
=> New_Reference_To
(Ftyp
, Loc
),
1523 Expression
=> Expr
));
1525 if not Is_Predefined_Dispatching_Operation
(Prim
) then
1526 Next_Formal
(Iface_Formal
);
1529 Next_Formal
(Formal
);
1532 Controlling_Typ
:= Find_Dispatching_Type
(Target
);
1534 Target_Formal
:= First_Formal
(Target
);
1535 Formal
:= First
(Formals
);
1536 while Present
(Formal
) loop
1538 -- If the parent is a constrained discriminated type, then the
1539 -- primitive operation will have been defined on a first subtype.
1540 -- For proper matching with controlling type, use base type.
1542 if Ekind
(Target_Formal
) = E_In_Parameter
1543 and then Ekind
(Etype
(Target_Formal
)) = E_Anonymous_Access_Type
1546 Base_Type
(Directly_Designated_Type
(Etype
(Target_Formal
)));
1548 Ftyp
:= Base_Type
(Etype
(Target_Formal
));
1551 -- For concurrent types, the relevant information is found in the
1552 -- Corresponding_Record_Type, rather than the type entity itself.
1554 if Is_Concurrent_Type
(Ftyp
) then
1555 Ftyp
:= Corresponding_Record_Type
(Ftyp
);
1558 if Ekind
(Target_Formal
) = E_In_Parameter
1559 and then Ekind
(Etype
(Target_Formal
)) = E_Anonymous_Access_Type
1560 and then Ftyp
= Controlling_Typ
1563 -- type T is access all <<type of the target formal>>
1564 -- S : Storage_Offset := Storage_Offset!(Formal)
1565 -- - Offset_To_Top (address!(Formal))
1568 Make_Full_Type_Declaration
(Loc
,
1569 Defining_Identifier
=> Make_Temporary
(Loc
, 'T'),
1571 Make_Access_To_Object_Definition
(Loc
,
1572 All_Present
=> True,
1573 Null_Exclusion_Present
=> False,
1574 Constant_Present
=> False,
1575 Subtype_Indication
=>
1576 New_Reference_To
(Ftyp
, Loc
)));
1579 Unchecked_Convert_To
(RTE
(RE_Address
),
1580 New_Reference_To
(Defining_Identifier
(Formal
), Loc
));
1582 if not RTE_Available
(RE_Offset_To_Top
) then
1584 Build_Offset_To_Top
(Loc
, New_Arg
);
1587 Make_Function_Call
(Loc
,
1588 Name
=> New_Reference_To
(RTE
(RE_Offset_To_Top
), Loc
),
1589 Parameter_Associations
=> New_List
(New_Arg
));
1593 Make_Object_Declaration
(Loc
,
1594 Defining_Identifier
=> Make_Temporary
(Loc
, 'S'),
1595 Constant_Present
=> True,
1596 Object_Definition
=>
1597 New_Reference_To
(RTE
(RE_Storage_Offset
), Loc
),
1599 Make_Op_Subtract
(Loc
,
1601 Unchecked_Convert_To
1602 (RTE
(RE_Storage_Offset
),
1603 New_Reference_To
(Defining_Identifier
(Formal
), Loc
)),
1607 Append_To
(Decl
, Decl_2
);
1608 Append_To
(Decl
, Decl_1
);
1610 -- Reference the new actual. Generate:
1614 Unchecked_Convert_To
1615 (Defining_Identifier
(Decl_2
),
1616 New_Reference_To
(Defining_Identifier
(Decl_1
), Loc
)));
1618 elsif Ftyp
= Controlling_Typ
then
1621 -- S1 : Storage_Offset := Storage_Offset!(Formal'Address)
1622 -- - Offset_To_Top (Formal'Address)
1623 -- S2 : Addr_Ptr := Addr_Ptr!(S1)
1626 Make_Attribute_Reference
(Loc
,
1628 New_Reference_To
(Defining_Identifier
(Formal
), Loc
),
1632 if not RTE_Available
(RE_Offset_To_Top
) then
1634 Build_Offset_To_Top
(Loc
, New_Arg
);
1637 Make_Function_Call
(Loc
,
1638 Name
=> New_Reference_To
(RTE
(RE_Offset_To_Top
), Loc
),
1639 Parameter_Associations
=> New_List
(New_Arg
));
1643 Make_Object_Declaration
(Loc
,
1644 Defining_Identifier
=> Make_Temporary
(Loc
, 'S'),
1645 Constant_Present
=> True,
1646 Object_Definition
=>
1647 New_Reference_To
(RTE
(RE_Storage_Offset
), Loc
),
1649 Make_Op_Subtract
(Loc
,
1651 Unchecked_Convert_To
1652 (RTE
(RE_Storage_Offset
),
1653 Make_Attribute_Reference
(Loc
,
1656 (Defining_Identifier
(Formal
), Loc
),
1657 Attribute_Name
=> Name_Address
)),
1662 Make_Object_Declaration
(Loc
,
1663 Defining_Identifier
=> Make_Temporary
(Loc
, 'S'),
1664 Constant_Present
=> True,
1665 Object_Definition
=>
1666 New_Reference_To
(RTE
(RE_Addr_Ptr
), Loc
),
1668 Unchecked_Convert_To
1670 New_Reference_To
(Defining_Identifier
(Decl_1
), Loc
)));
1672 Append_To
(Decl
, Decl_1
);
1673 Append_To
(Decl
, Decl_2
);
1675 -- Reference the new actual, generate:
1676 -- Target_Formal (S2.all)
1679 Unchecked_Convert_To
(Ftyp
,
1680 Make_Explicit_Dereference
(Loc
,
1681 New_Reference_To
(Defining_Identifier
(Decl_2
), Loc
))));
1683 -- No special management required for this actual
1687 New_Reference_To
(Defining_Identifier
(Formal
), Loc
));
1690 Next_Formal
(Target_Formal
);
1694 Thunk_Id
:= Make_Temporary
(Loc
, 'T');
1695 Set_Is_Thunk
(Thunk_Id
);
1699 if Ekind
(Target
) = E_Procedure
then
1701 Make_Subprogram_Body
(Loc
,
1703 Make_Procedure_Specification
(Loc
,
1704 Defining_Unit_Name
=> Thunk_Id
,
1705 Parameter_Specifications
=> Formals
),
1706 Declarations
=> Decl
,
1707 Handled_Statement_Sequence
=>
1708 Make_Handled_Sequence_Of_Statements
(Loc
,
1709 Statements
=> New_List
(
1710 Make_Procedure_Call_Statement
(Loc
,
1711 Name
=> New_Occurrence_Of
(Target
, Loc
),
1712 Parameter_Associations
=> Actuals
))));
1716 else pragma Assert
(Ekind
(Target
) = E_Function
);
1718 Make_Subprogram_Body
(Loc
,
1720 Make_Function_Specification
(Loc
,
1721 Defining_Unit_Name
=> Thunk_Id
,
1722 Parameter_Specifications
=> Formals
,
1723 Result_Definition
=>
1724 New_Copy
(Result_Definition
(Parent
(Target
)))),
1725 Declarations
=> Decl
,
1726 Handled_Statement_Sequence
=>
1727 Make_Handled_Sequence_Of_Statements
(Loc
,
1728 Statements
=> New_List
(
1729 Make_Simple_Return_Statement
(Loc
,
1730 Make_Function_Call
(Loc
,
1731 Name
=> New_Occurrence_Of
(Target
, Loc
),
1732 Parameter_Associations
=> Actuals
)))));
1734 end Expand_Interface_Thunk
;
1740 function Has_DT
(Typ
: Entity_Id
) return Boolean is
1742 return not Is_Interface
(Typ
)
1743 and then not Restriction_Active
(No_Dispatching_Calls
);
1746 -----------------------------------------
1747 -- Is_Predefined_Dispatching_Operation --
1748 -----------------------------------------
1750 function Is_Predefined_Dispatching_Operation
1751 (E
: Entity_Id
) return Boolean
1753 TSS_Name
: TSS_Name_Type
;
1756 if not Is_Dispatching_Operation
(E
) then
1760 Get_Name_String
(Chars
(E
));
1762 -- Most predefined primitives have internally generated names. Equality
1763 -- must be treated differently; the predefined operation is recognized
1764 -- as a homogeneous binary operator that returns Boolean.
1766 if Name_Len
> TSS_Name_Type
'Last then
1767 TSS_Name
:= TSS_Name_Type
(Name_Buffer
(Name_Len
- TSS_Name
'Length + 1
1769 if Chars
(E
) = Name_uSize
1770 or else Chars
(E
) = Name_uAlignment
1771 or else TSS_Name
= TSS_Stream_Read
1772 or else TSS_Name
= TSS_Stream_Write
1773 or else TSS_Name
= TSS_Stream_Input
1774 or else TSS_Name
= TSS_Stream_Output
1776 (Chars
(E
) = Name_Op_Eq
1777 and then Etype
(First_Formal
(E
)) = Etype
(Last_Formal
(E
)))
1778 or else Chars
(E
) = Name_uAssign
1779 or else TSS_Name
= TSS_Deep_Adjust
1780 or else TSS_Name
= TSS_Deep_Finalize
1781 or else Is_Predefined_Interface_Primitive
(E
)
1788 end Is_Predefined_Dispatching_Operation
;
1790 ---------------------------------------
1791 -- Is_Predefined_Internal_Operation --
1792 ---------------------------------------
1794 function Is_Predefined_Internal_Operation
1795 (E
: Entity_Id
) return Boolean
1797 TSS_Name
: TSS_Name_Type
;
1800 if not Is_Dispatching_Operation
(E
) then
1804 Get_Name_String
(Chars
(E
));
1806 -- Most predefined primitives have internally generated names. Equality
1807 -- must be treated differently; the predefined operation is recognized
1808 -- as a homogeneous binary operator that returns Boolean.
1810 if Name_Len
> TSS_Name_Type
'Last then
1813 (Name_Buffer
(Name_Len
- TSS_Name
'Length + 1 .. Name_Len
));
1815 if Chars
(E
) = Name_uSize
1816 or else Chars
(E
) = Name_uAlignment
1818 (Chars
(E
) = Name_Op_Eq
1819 and then Etype
(First_Formal
(E
)) = Etype
(Last_Formal
(E
)))
1820 or else Chars
(E
) = Name_uAssign
1821 or else TSS_Name
= TSS_Deep_Adjust
1822 or else TSS_Name
= TSS_Deep_Finalize
1823 or else Is_Predefined_Interface_Primitive
(E
)
1830 end Is_Predefined_Internal_Operation
;
1832 -------------------------------------
1833 -- Is_Predefined_Dispatching_Alias --
1834 -------------------------------------
1836 function Is_Predefined_Dispatching_Alias
(Prim
: Entity_Id
) return Boolean
1839 return not Is_Predefined_Dispatching_Operation
(Prim
)
1840 and then Present
(Alias
(Prim
))
1841 and then Is_Predefined_Dispatching_Operation
(Ultimate_Alias
(Prim
));
1842 end Is_Predefined_Dispatching_Alias
;
1844 ---------------------------------------
1845 -- Is_Predefined_Interface_Primitive --
1846 ---------------------------------------
1848 function Is_Predefined_Interface_Primitive
(E
: Entity_Id
) return Boolean is
1850 return Ada_Version
>= Ada_05
1851 and then (Chars
(E
) = Name_uDisp_Asynchronous_Select
or else
1852 Chars
(E
) = Name_uDisp_Conditional_Select
or else
1853 Chars
(E
) = Name_uDisp_Get_Prim_Op_Kind
or else
1854 Chars
(E
) = Name_uDisp_Get_Task_Id
or else
1855 Chars
(E
) = Name_uDisp_Requeue
or else
1856 Chars
(E
) = Name_uDisp_Timed_Select
);
1857 end Is_Predefined_Interface_Primitive
;
1859 ----------------------------------------
1860 -- Make_Disp_Asynchronous_Select_Body --
1861 ----------------------------------------
1863 -- For interface types, generate:
1865 -- procedure _Disp_Asynchronous_Select
1866 -- (T : in out <Typ>;
1868 -- P : System.Address;
1869 -- B : out System.Storage_Elements.Dummy_Communication_Block;
1874 -- end _Disp_Asynchronous_Select;
1876 -- For protected types, generate:
1878 -- procedure _Disp_Asynchronous_Select
1879 -- (T : in out <Typ>;
1881 -- P : System.Address;
1882 -- B : out System.Storage_Elements.Dummy_Communication_Block;
1886 -- Ada.Tags.Get_Entry_Index (Ada.Tags.Tag (<Typ>VP, S));
1887 -- Bnn : System.Tasking.Protected_Objects.Operations.
1888 -- Communication_Block;
1890 -- System.Tasking.Protected_Objects.Operations.Protected_Entry_Call
1891 -- (T._object'Access,
1892 -- System.Tasking.Protected_Objects.Protected_Entry_Index (I),
1894 -- System.Tasking.Asynchronous_Call,
1896 -- B := System.Storage_Elements.Dummy_Communication_Block (Bnn);
1897 -- end _Disp_Asynchronous_Select;
1899 -- For task types, generate:
1901 -- procedure _Disp_Asynchronous_Select
1902 -- (T : in out <Typ>;
1904 -- P : System.Address;
1905 -- B : out System.Storage_Elements.Dummy_Communication_Block;
1909 -- Ada.Tags.Get_Entry_Index (Ada.Tags.Tag (<Typ>VP, S));
1911 -- System.Tasking.Rendezvous.Task_Entry_Call
1913 -- System.Tasking.Task_Entry_Index (I),
1915 -- System.Tasking.Asynchronous_Call,
1917 -- end _Disp_Asynchronous_Select;
1919 function Make_Disp_Asynchronous_Select_Body
1920 (Typ
: Entity_Id
) return Node_Id
1922 Com_Block
: Entity_Id
;
1923 Conc_Typ
: Entity_Id
:= Empty
;
1924 Decls
: constant List_Id
:= New_List
;
1926 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
1928 Stmts
: constant List_Id
:= New_List
;
1931 pragma Assert
(not Restriction_Active
(No_Dispatching_Calls
));
1933 -- Null body is generated for interface types
1935 if Is_Interface
(Typ
) then
1937 Make_Subprogram_Body
(Loc
,
1939 Make_Disp_Asynchronous_Select_Spec
(Typ
),
1942 Handled_Statement_Sequence
=>
1943 Make_Handled_Sequence_Of_Statements
(Loc
,
1944 New_List
(Make_Null_Statement
(Loc
))));
1947 DT_Ptr
:= Node
(First_Elmt
(Access_Disp_Table
(Typ
)));
1949 if Is_Concurrent_Record_Type
(Typ
) then
1950 Conc_Typ
:= Corresponding_Concurrent_Type
(Typ
);
1954 -- Ada.Tags.Get_Entry_Index (Ada.Tags.Tag! (<type>VP), S);
1956 -- where I will be used to capture the entry index of the primitive
1957 -- wrapper at position S.
1960 Make_Object_Declaration
(Loc
,
1961 Defining_Identifier
=>
1962 Make_Defining_Identifier
(Loc
, Name_uI
),
1963 Object_Definition
=>
1964 New_Reference_To
(Standard_Integer
, Loc
),
1966 Make_Function_Call
(Loc
,
1968 New_Reference_To
(RTE
(RE_Get_Entry_Index
), Loc
),
1969 Parameter_Associations
=>
1971 Unchecked_Convert_To
(RTE
(RE_Tag
),
1972 New_Reference_To
(DT_Ptr
, Loc
)),
1973 Make_Identifier
(Loc
, Name_uS
)))));
1975 if Ekind
(Conc_Typ
) = E_Protected_Type
then
1978 -- Bnn : Communication_Block;
1980 Com_Block
:= Make_Temporary
(Loc
, 'B');
1982 Make_Object_Declaration
(Loc
,
1983 Defining_Identifier
=>
1985 Object_Definition
=>
1986 New_Reference_To
(RTE
(RE_Communication_Block
), Loc
)));
1988 -- Build T._object'Access for calls below
1991 Make_Attribute_Reference
(Loc
,
1992 Attribute_Name
=> Name_Unchecked_Access
,
1994 Make_Selected_Component
(Loc
,
1995 Prefix
=> Make_Identifier
(Loc
, Name_uT
),
1996 Selector_Name
=> Make_Identifier
(Loc
, Name_uObject
)));
1998 case Corresponding_Runtime_Package
(Conc_Typ
) is
1999 when System_Tasking_Protected_Objects_Entries
=>
2002 -- Protected_Entry_Call
2003 -- (T._object'Access, -- Object
2004 -- Protected_Entry_Index! (I), -- E
2005 -- P, -- Uninterpreted_Data
2006 -- Asynchronous_Call, -- Mode
2007 -- Bnn); -- Communication_Block
2009 -- where T is the protected object, I is the entry index, P
2010 -- is the wrapped parameters and B is the name of the
2011 -- communication block.
2014 Make_Procedure_Call_Statement
(Loc
,
2016 New_Reference_To
(RTE
(RE_Protected_Entry_Call
), Loc
),
2017 Parameter_Associations
=>
2021 Make_Unchecked_Type_Conversion
(Loc
, -- entry index
2024 (RTE
(RE_Protected_Entry_Index
), Loc
),
2025 Expression
=> Make_Identifier
(Loc
, Name_uI
)),
2027 Make_Identifier
(Loc
, Name_uP
), -- parameter block
2028 New_Reference_To
( -- Asynchronous_Call
2029 RTE
(RE_Asynchronous_Call
), Loc
),
2031 New_Reference_To
(Com_Block
, Loc
)))); -- comm block
2033 when System_Tasking_Protected_Objects_Single_Entry
=>
2036 -- procedure Protected_Single_Entry_Call
2037 -- (Object : Protection_Entry_Access;
2038 -- Uninterpreted_Data : System.Address;
2039 -- Mode : Call_Modes);
2042 Make_Procedure_Call_Statement
(Loc
,
2045 (RTE
(RE_Protected_Single_Entry_Call
), Loc
),
2046 Parameter_Associations
=>
2050 Make_Attribute_Reference
(Loc
,
2051 Prefix
=> Make_Identifier
(Loc
, Name_uP
),
2052 Attribute_Name
=> Name_Address
),
2055 (RTE
(RE_Asynchronous_Call
), Loc
))));
2058 raise Program_Error
;
2062 -- B := Dummy_Communication_Block (Bnn);
2065 Make_Assignment_Statement
(Loc
,
2067 Make_Identifier
(Loc
, Name_uB
),
2069 Make_Unchecked_Type_Conversion
(Loc
,
2072 RTE
(RE_Dummy_Communication_Block
), Loc
),
2074 New_Reference_To
(Com_Block
, Loc
))));
2077 pragma Assert
(Ekind
(Conc_Typ
) = E_Task_Type
);
2081 -- (T._task_id, -- Acceptor
2082 -- Task_Entry_Index! (I), -- E
2083 -- P, -- Uninterpreted_Data
2084 -- Asynchronous_Call, -- Mode
2085 -- F); -- Rendezvous_Successful
2087 -- where T is the task object, I is the entry index, P is the
2088 -- wrapped parameters and F is the status flag.
2091 Make_Procedure_Call_Statement
(Loc
,
2093 New_Reference_To
(RTE
(RE_Task_Entry_Call
), Loc
),
2094 Parameter_Associations
=>
2096 Make_Selected_Component
(Loc
, -- T._task_id
2098 Make_Identifier
(Loc
, Name_uT
),
2100 Make_Identifier
(Loc
, Name_uTask_Id
)),
2102 Make_Unchecked_Type_Conversion
(Loc
, -- entry index
2104 New_Reference_To
(RTE
(RE_Task_Entry_Index
), Loc
),
2106 Make_Identifier
(Loc
, Name_uI
)),
2108 Make_Identifier
(Loc
, Name_uP
), -- parameter block
2109 New_Reference_To
( -- Asynchronous_Call
2110 RTE
(RE_Asynchronous_Call
), Loc
),
2111 Make_Identifier
(Loc
, Name_uF
)))); -- status flag
2115 -- Ensure that the statements list is non-empty
2117 Append_To
(Stmts
, Make_Null_Statement
(Loc
));
2121 Make_Subprogram_Body
(Loc
,
2123 Make_Disp_Asynchronous_Select_Spec
(Typ
),
2126 Handled_Statement_Sequence
=>
2127 Make_Handled_Sequence_Of_Statements
(Loc
, Stmts
));
2128 end Make_Disp_Asynchronous_Select_Body
;
2130 ----------------------------------------
2131 -- Make_Disp_Asynchronous_Select_Spec --
2132 ----------------------------------------
2134 function Make_Disp_Asynchronous_Select_Spec
2135 (Typ
: Entity_Id
) return Node_Id
2137 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
2138 Def_Id
: constant Node_Id
:=
2139 Make_Defining_Identifier
(Loc
,
2140 Name_uDisp_Asynchronous_Select
);
2141 Params
: constant List_Id
:= New_List
;
2144 pragma Assert
(not Restriction_Active
(No_Dispatching_Calls
));
2146 -- T : in out Typ; -- Object parameter
2147 -- S : Integer; -- Primitive operation slot
2148 -- P : Address; -- Wrapped parameters
2149 -- B : out Dummy_Communication_Block; -- Communication block dummy
2150 -- F : out Boolean; -- Status flag
2152 Append_List_To
(Params
, New_List
(
2154 Make_Parameter_Specification
(Loc
,
2155 Defining_Identifier
=>
2156 Make_Defining_Identifier
(Loc
, Name_uT
),
2158 New_Reference_To
(Typ
, Loc
),
2160 Out_Present
=> True),
2162 Make_Parameter_Specification
(Loc
,
2163 Defining_Identifier
=>
2164 Make_Defining_Identifier
(Loc
, Name_uS
),
2166 New_Reference_To
(Standard_Integer
, Loc
)),
2168 Make_Parameter_Specification
(Loc
,
2169 Defining_Identifier
=>
2170 Make_Defining_Identifier
(Loc
, Name_uP
),
2172 New_Reference_To
(RTE
(RE_Address
), Loc
)),
2174 Make_Parameter_Specification
(Loc
,
2175 Defining_Identifier
=>
2176 Make_Defining_Identifier
(Loc
, Name_uB
),
2178 New_Reference_To
(RTE
(RE_Dummy_Communication_Block
), Loc
),
2179 Out_Present
=> True),
2181 Make_Parameter_Specification
(Loc
,
2182 Defining_Identifier
=>
2183 Make_Defining_Identifier
(Loc
, Name_uF
),
2185 New_Reference_To
(Standard_Boolean
, Loc
),
2186 Out_Present
=> True)));
2189 Make_Procedure_Specification
(Loc
,
2190 Defining_Unit_Name
=> Def_Id
,
2191 Parameter_Specifications
=> Params
);
2192 end Make_Disp_Asynchronous_Select_Spec
;
2194 ---------------------------------------
2195 -- Make_Disp_Conditional_Select_Body --
2196 ---------------------------------------
2198 -- For interface types, generate:
2200 -- procedure _Disp_Conditional_Select
2201 -- (T : in out <Typ>;
2203 -- P : System.Address;
2204 -- C : out Ada.Tags.Prim_Op_Kind;
2209 -- end _Disp_Conditional_Select;
2211 -- For protected types, generate:
2213 -- procedure _Disp_Conditional_Select
2214 -- (T : in out <Typ>;
2216 -- P : System.Address;
2217 -- C : out Ada.Tags.Prim_Op_Kind;
2221 -- Bnn : System.Tasking.Protected_Objects.Operations.
2222 -- Communication_Block;
2225 -- C := Ada.Tags.Get_Prim_Op_Kind (Ada.Tags.Tag (<Typ>VP, S));
2227 -- if C = Ada.Tags.POK_Procedure
2228 -- or else C = Ada.Tags.POK_Protected_Procedure
2229 -- or else C = Ada.Tags.POK_Task_Procedure
2235 -- I := Ada.Tags.Get_Entry_Index (Ada.Tags.Tag (<Typ>VP, S));
2236 -- System.Tasking.Protected_Objects.Operations.Protected_Entry_Call
2237 -- (T.object'Access,
2238 -- System.Tasking.Protected_Objects.Protected_Entry_Index (I),
2240 -- System.Tasking.Conditional_Call,
2242 -- F := not Cancelled (Bnn);
2243 -- end _Disp_Conditional_Select;
2245 -- For task types, generate:
2247 -- procedure _Disp_Conditional_Select
2248 -- (T : in out <Typ>;
2250 -- P : System.Address;
2251 -- C : out Ada.Tags.Prim_Op_Kind;
2257 -- I := Ada.Tags.Get_Entry_Index (Ada.Tags.Tag (<Typ>VP, S));
2258 -- System.Tasking.Rendezvous.Task_Entry_Call
2260 -- System.Tasking.Task_Entry_Index (I),
2262 -- System.Tasking.Conditional_Call,
2264 -- end _Disp_Conditional_Select;
2266 function Make_Disp_Conditional_Select_Body
2267 (Typ
: Entity_Id
) return Node_Id
2269 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
2270 Blk_Nam
: Entity_Id
;
2271 Conc_Typ
: Entity_Id
:= Empty
;
2272 Decls
: constant List_Id
:= New_List
;
2275 Stmts
: constant List_Id
:= New_List
;
2278 pragma Assert
(not Restriction_Active
(No_Dispatching_Calls
));
2280 -- Null body is generated for interface types
2282 if Is_Interface
(Typ
) then
2284 Make_Subprogram_Body
(Loc
,
2286 Make_Disp_Conditional_Select_Spec
(Typ
),
2289 Handled_Statement_Sequence
=>
2290 Make_Handled_Sequence_Of_Statements
(Loc
,
2291 New_List
(Make_Null_Statement
(Loc
))));
2294 DT_Ptr
:= Node
(First_Elmt
(Access_Disp_Table
(Typ
)));
2296 if Is_Concurrent_Record_Type
(Typ
) then
2297 Conc_Typ
:= Corresponding_Concurrent_Type
(Typ
);
2302 -- where I will be used to capture the entry index of the primitive
2303 -- wrapper at position S.
2306 Make_Object_Declaration
(Loc
,
2307 Defining_Identifier
=>
2308 Make_Defining_Identifier
(Loc
, Name_uI
),
2309 Object_Definition
=>
2310 New_Reference_To
(Standard_Integer
, Loc
)));
2313 -- C := Ada.Tags.Get_Prim_Op_Kind (Ada.Tags.Tag! (<type>VP), S);
2315 -- if C = POK_Procedure
2316 -- or else C = POK_Protected_Procedure
2317 -- or else C = POK_Task_Procedure;
2323 Build_Common_Dispatching_Select_Statements
(Loc
, DT_Ptr
, Stmts
);
2326 -- Bnn : Communication_Block;
2328 -- where Bnn is the name of the communication block used in the
2329 -- call to Protected_Entry_Call.
2331 Blk_Nam
:= Make_Temporary
(Loc
, 'B');
2333 Make_Object_Declaration
(Loc
,
2334 Defining_Identifier
=>
2336 Object_Definition
=>
2337 New_Reference_To
(RTE
(RE_Communication_Block
), Loc
)));
2340 -- I := Ada.Tags.Get_Entry_Index (Ada.Tags.Tag! (<type>VP), S);
2342 -- I is the entry index and S is the dispatch table slot
2345 Make_Assignment_Statement
(Loc
,
2347 Make_Identifier
(Loc
, Name_uI
),
2349 Make_Function_Call
(Loc
,
2351 New_Reference_To
(RTE
(RE_Get_Entry_Index
), Loc
),
2352 Parameter_Associations
=>
2354 Unchecked_Convert_To
(RTE
(RE_Tag
),
2355 New_Reference_To
(DT_Ptr
, Loc
)),
2356 Make_Identifier
(Loc
, Name_uS
)))));
2358 if Ekind
(Conc_Typ
) = E_Protected_Type
then
2360 Obj_Ref
:= -- T._object'Access
2361 Make_Attribute_Reference
(Loc
,
2362 Attribute_Name
=> Name_Unchecked_Access
,
2364 Make_Selected_Component
(Loc
,
2365 Prefix
=> Make_Identifier
(Loc
, Name_uT
),
2366 Selector_Name
=> Make_Identifier
(Loc
, Name_uObject
)));
2368 case Corresponding_Runtime_Package
(Conc_Typ
) is
2369 when System_Tasking_Protected_Objects_Entries
=>
2372 -- Protected_Entry_Call
2373 -- (T._object'Access, -- Object
2374 -- Protected_Entry_Index! (I), -- E
2375 -- P, -- Uninterpreted_Data
2376 -- Conditional_Call, -- Mode
2379 -- where T is the protected object, I is the entry index, P
2380 -- are the wrapped parameters and Bnn is the name of the
2381 -- communication block.
2384 Make_Procedure_Call_Statement
(Loc
,
2386 New_Reference_To
(RTE
(RE_Protected_Entry_Call
), Loc
),
2387 Parameter_Associations
=>
2391 Make_Unchecked_Type_Conversion
(Loc
, -- entry index
2394 (RTE
(RE_Protected_Entry_Index
), Loc
),
2395 Expression
=> Make_Identifier
(Loc
, Name_uI
)),
2397 Make_Identifier
(Loc
, Name_uP
), -- parameter block
2399 New_Reference_To
( -- Conditional_Call
2400 RTE
(RE_Conditional_Call
), Loc
),
2401 New_Reference_To
( -- Bnn
2404 when System_Tasking_Protected_Objects_Single_Entry
=>
2406 -- If we are compiling for a restricted run-time, the call
2407 -- uses the simpler form.
2410 Make_Procedure_Call_Statement
(Loc
,
2413 (RTE
(RE_Protected_Single_Entry_Call
), Loc
),
2414 Parameter_Associations
=>
2418 Make_Attribute_Reference
(Loc
,
2419 Prefix
=> Make_Identifier
(Loc
, Name_uP
),
2420 Attribute_Name
=> Name_Address
),
2423 (RTE
(RE_Conditional_Call
), Loc
))));
2425 raise Program_Error
;
2429 -- F := not Cancelled (Bnn);
2431 -- where F is the success flag. The status of Cancelled is negated
2432 -- in order to match the behaviour of the version for task types.
2435 Make_Assignment_Statement
(Loc
,
2437 Make_Identifier
(Loc
, Name_uF
),
2441 Make_Function_Call
(Loc
,
2443 New_Reference_To
(RTE
(RE_Cancelled
), Loc
),
2444 Parameter_Associations
=>
2446 New_Reference_To
(Blk_Nam
, Loc
))))));
2448 pragma Assert
(Ekind
(Conc_Typ
) = E_Task_Type
);
2452 -- (T._task_id, -- Acceptor
2453 -- Task_Entry_Index! (I), -- E
2454 -- P, -- Uninterpreted_Data
2455 -- Conditional_Call, -- Mode
2456 -- F); -- Rendezvous_Successful
2458 -- where T is the task object, I is the entry index, P are the
2459 -- wrapped parameters and F is the status flag.
2462 Make_Procedure_Call_Statement
(Loc
,
2464 New_Reference_To
(RTE
(RE_Task_Entry_Call
), Loc
),
2465 Parameter_Associations
=>
2468 Make_Selected_Component
(Loc
, -- T._task_id
2470 Make_Identifier
(Loc
, Name_uT
),
2472 Make_Identifier
(Loc
, Name_uTask_Id
)),
2474 Make_Unchecked_Type_Conversion
(Loc
, -- entry index
2476 New_Reference_To
(RTE
(RE_Task_Entry_Index
), Loc
),
2478 Make_Identifier
(Loc
, Name_uI
)),
2480 Make_Identifier
(Loc
, Name_uP
), -- parameter block
2481 New_Reference_To
( -- Conditional_Call
2482 RTE
(RE_Conditional_Call
), Loc
),
2483 Make_Identifier
(Loc
, Name_uF
)))); -- status flag
2487 -- Ensure that the statements list is non-empty
2489 Append_To
(Stmts
, Make_Null_Statement
(Loc
));
2493 Make_Subprogram_Body
(Loc
,
2495 Make_Disp_Conditional_Select_Spec
(Typ
),
2498 Handled_Statement_Sequence
=>
2499 Make_Handled_Sequence_Of_Statements
(Loc
, Stmts
));
2500 end Make_Disp_Conditional_Select_Body
;
2502 ---------------------------------------
2503 -- Make_Disp_Conditional_Select_Spec --
2504 ---------------------------------------
2506 function Make_Disp_Conditional_Select_Spec
2507 (Typ
: Entity_Id
) return Node_Id
2509 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
2510 Def_Id
: constant Node_Id
:=
2511 Make_Defining_Identifier
(Loc
,
2512 Name_uDisp_Conditional_Select
);
2513 Params
: constant List_Id
:= New_List
;
2516 pragma Assert
(not Restriction_Active
(No_Dispatching_Calls
));
2518 -- T : in out Typ; -- Object parameter
2519 -- S : Integer; -- Primitive operation slot
2520 -- P : Address; -- Wrapped parameters
2521 -- C : out Prim_Op_Kind; -- Call kind
2522 -- F : out Boolean; -- Status flag
2524 Append_List_To
(Params
, New_List
(
2526 Make_Parameter_Specification
(Loc
,
2527 Defining_Identifier
=>
2528 Make_Defining_Identifier
(Loc
, Name_uT
),
2530 New_Reference_To
(Typ
, Loc
),
2532 Out_Present
=> True),
2534 Make_Parameter_Specification
(Loc
,
2535 Defining_Identifier
=>
2536 Make_Defining_Identifier
(Loc
, Name_uS
),
2538 New_Reference_To
(Standard_Integer
, Loc
)),
2540 Make_Parameter_Specification
(Loc
,
2541 Defining_Identifier
=>
2542 Make_Defining_Identifier
(Loc
, Name_uP
),
2544 New_Reference_To
(RTE
(RE_Address
), Loc
)),
2546 Make_Parameter_Specification
(Loc
,
2547 Defining_Identifier
=>
2548 Make_Defining_Identifier
(Loc
, Name_uC
),
2550 New_Reference_To
(RTE
(RE_Prim_Op_Kind
), Loc
),
2551 Out_Present
=> True),
2553 Make_Parameter_Specification
(Loc
,
2554 Defining_Identifier
=>
2555 Make_Defining_Identifier
(Loc
, Name_uF
),
2557 New_Reference_To
(Standard_Boolean
, Loc
),
2558 Out_Present
=> True)));
2561 Make_Procedure_Specification
(Loc
,
2562 Defining_Unit_Name
=> Def_Id
,
2563 Parameter_Specifications
=> Params
);
2564 end Make_Disp_Conditional_Select_Spec
;
2566 -------------------------------------
2567 -- Make_Disp_Get_Prim_Op_Kind_Body --
2568 -------------------------------------
2570 function Make_Disp_Get_Prim_Op_Kind_Body
2571 (Typ
: Entity_Id
) return Node_Id
2573 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
2577 pragma Assert
(not Restriction_Active
(No_Dispatching_Calls
));
2579 if Is_Interface
(Typ
) then
2581 Make_Subprogram_Body
(Loc
,
2583 Make_Disp_Get_Prim_Op_Kind_Spec
(Typ
),
2586 Handled_Statement_Sequence
=>
2587 Make_Handled_Sequence_Of_Statements
(Loc
,
2588 New_List
(Make_Null_Statement
(Loc
))));
2591 DT_Ptr
:= Node
(First_Elmt
(Access_Disp_Table
(Typ
)));
2594 -- C := get_prim_op_kind (tag! (<type>VP), S);
2596 -- where C is the out parameter capturing the call kind and S is the
2597 -- dispatch table slot number.
2600 Make_Subprogram_Body
(Loc
,
2602 Make_Disp_Get_Prim_Op_Kind_Spec
(Typ
),
2605 Handled_Statement_Sequence
=>
2606 Make_Handled_Sequence_Of_Statements
(Loc
,
2608 Make_Assignment_Statement
(Loc
,
2610 Make_Identifier
(Loc
, Name_uC
),
2612 Make_Function_Call
(Loc
,
2614 New_Reference_To
(RTE
(RE_Get_Prim_Op_Kind
), Loc
),
2615 Parameter_Associations
=> New_List
(
2616 Unchecked_Convert_To
(RTE
(RE_Tag
),
2617 New_Reference_To
(DT_Ptr
, Loc
)),
2618 Make_Identifier
(Loc
, Name_uS
)))))));
2619 end Make_Disp_Get_Prim_Op_Kind_Body
;
2621 -------------------------------------
2622 -- Make_Disp_Get_Prim_Op_Kind_Spec --
2623 -------------------------------------
2625 function Make_Disp_Get_Prim_Op_Kind_Spec
2626 (Typ
: Entity_Id
) return Node_Id
2628 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
2629 Def_Id
: constant Node_Id
:=
2630 Make_Defining_Identifier
(Loc
,
2631 Name_uDisp_Get_Prim_Op_Kind
);
2632 Params
: constant List_Id
:= New_List
;
2635 pragma Assert
(not Restriction_Active
(No_Dispatching_Calls
));
2637 -- T : in out Typ; -- Object parameter
2638 -- S : Integer; -- Primitive operation slot
2639 -- C : out Prim_Op_Kind; -- Call kind
2641 Append_List_To
(Params
, New_List
(
2643 Make_Parameter_Specification
(Loc
,
2644 Defining_Identifier
=>
2645 Make_Defining_Identifier
(Loc
, Name_uT
),
2647 New_Reference_To
(Typ
, Loc
),
2649 Out_Present
=> True),
2651 Make_Parameter_Specification
(Loc
,
2652 Defining_Identifier
=>
2653 Make_Defining_Identifier
(Loc
, Name_uS
),
2655 New_Reference_To
(Standard_Integer
, Loc
)),
2657 Make_Parameter_Specification
(Loc
,
2658 Defining_Identifier
=>
2659 Make_Defining_Identifier
(Loc
, Name_uC
),
2661 New_Reference_To
(RTE
(RE_Prim_Op_Kind
), Loc
),
2662 Out_Present
=> True)));
2665 Make_Procedure_Specification
(Loc
,
2666 Defining_Unit_Name
=> Def_Id
,
2667 Parameter_Specifications
=> Params
);
2668 end Make_Disp_Get_Prim_Op_Kind_Spec
;
2670 --------------------------------
2671 -- Make_Disp_Get_Task_Id_Body --
2672 --------------------------------
2674 function Make_Disp_Get_Task_Id_Body
2675 (Typ
: Entity_Id
) return Node_Id
2677 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
2681 pragma Assert
(not Restriction_Active
(No_Dispatching_Calls
));
2683 if Is_Concurrent_Record_Type
(Typ
)
2684 and then Ekind
(Corresponding_Concurrent_Type
(Typ
)) = E_Task_Type
2687 -- return To_Address (_T._task_id);
2690 Make_Simple_Return_Statement
(Loc
,
2692 Make_Unchecked_Type_Conversion
(Loc
,
2694 New_Reference_To
(RTE
(RE_Address
), Loc
),
2696 Make_Selected_Component
(Loc
,
2698 Make_Identifier
(Loc
, Name_uT
),
2700 Make_Identifier
(Loc
, Name_uTask_Id
))));
2702 -- A null body is constructed for non-task types
2706 -- return Null_Address;
2709 Make_Simple_Return_Statement
(Loc
,
2711 New_Reference_To
(RTE
(RE_Null_Address
), Loc
));
2715 Make_Subprogram_Body
(Loc
,
2717 Make_Disp_Get_Task_Id_Spec
(Typ
),
2720 Handled_Statement_Sequence
=>
2721 Make_Handled_Sequence_Of_Statements
(Loc
,
2723 end Make_Disp_Get_Task_Id_Body
;
2725 --------------------------------
2726 -- Make_Disp_Get_Task_Id_Spec --
2727 --------------------------------
2729 function Make_Disp_Get_Task_Id_Spec
2730 (Typ
: Entity_Id
) return Node_Id
2732 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
2735 pragma Assert
(not Restriction_Active
(No_Dispatching_Calls
));
2738 Make_Function_Specification
(Loc
,
2739 Defining_Unit_Name
=>
2740 Make_Defining_Identifier
(Loc
, Name_uDisp_Get_Task_Id
),
2741 Parameter_Specifications
=> New_List
(
2742 Make_Parameter_Specification
(Loc
,
2743 Defining_Identifier
=>
2744 Make_Defining_Identifier
(Loc
, Name_uT
),
2746 New_Reference_To
(Typ
, Loc
))),
2747 Result_Definition
=>
2748 New_Reference_To
(RTE
(RE_Address
), Loc
));
2749 end Make_Disp_Get_Task_Id_Spec
;
2751 ----------------------------
2752 -- Make_Disp_Requeue_Body --
2753 ----------------------------
2755 function Make_Disp_Requeue_Body
2756 (Typ
: Entity_Id
) return Node_Id
2758 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
2759 Conc_Typ
: Entity_Id
:= Empty
;
2760 Stmts
: constant List_Id
:= New_List
;
2763 pragma Assert
(not Restriction_Active
(No_Dispatching_Calls
));
2765 -- Null body is generated for interface types and non-concurrent
2768 if Is_Interface
(Typ
)
2769 or else not Is_Concurrent_Record_Type
(Typ
)
2772 Make_Subprogram_Body
(Loc
,
2774 Make_Disp_Requeue_Spec
(Typ
),
2777 Handled_Statement_Sequence
=>
2778 Make_Handled_Sequence_Of_Statements
(Loc
,
2779 New_List
(Make_Null_Statement
(Loc
))));
2782 Conc_Typ
:= Corresponding_Concurrent_Type
(Typ
);
2784 if Ekind
(Conc_Typ
) = E_Protected_Type
then
2786 -- Generate statements:
2788 -- System.Tasking.Protected_Objects.Operations.
2789 -- Requeue_Protected_Entry
2790 -- (Protection_Entries_Access (P),
2791 -- O._object'Unchecked_Access,
2792 -- Protected_Entry_Index (I),
2795 -- System.Tasking.Protected_Objects.Operations.
2796 -- Requeue_Task_To_Protected_Entry
2797 -- (O._object'Unchecked_Access,
2798 -- Protected_Entry_Index (I),
2802 if Restriction_Active
(No_Entry_Queue
) then
2803 Append_To
(Stmts
, Make_Null_Statement
(Loc
));
2806 Make_If_Statement
(Loc
,
2808 Make_Identifier
(Loc
, Name_uF
),
2813 -- Call to Requeue_Protected_Entry
2815 Make_Procedure_Call_Statement
(Loc
,
2818 RTE
(RE_Requeue_Protected_Entry
), Loc
),
2819 Parameter_Associations
=>
2822 Make_Unchecked_Type_Conversion
(Loc
, -- PEA (P)
2825 RTE
(RE_Protection_Entries_Access
), Loc
),
2827 Make_Identifier
(Loc
, Name_uP
)),
2829 Make_Attribute_Reference
(Loc
, -- O._object'Acc
2831 Name_Unchecked_Access
,
2833 Make_Selected_Component
(Loc
,
2835 Make_Identifier
(Loc
, Name_uO
),
2837 Make_Identifier
(Loc
, Name_uObject
))),
2839 Make_Unchecked_Type_Conversion
(Loc
, -- entry index
2842 RTE
(RE_Protected_Entry_Index
), Loc
),
2844 Make_Identifier
(Loc
, Name_uI
)),
2846 Make_Identifier
(Loc
, Name_uA
)))), -- abort status
2851 -- Call to Requeue_Task_To_Protected_Entry
2853 Make_Procedure_Call_Statement
(Loc
,
2856 RTE
(RE_Requeue_Task_To_Protected_Entry
), Loc
),
2857 Parameter_Associations
=>
2860 Make_Attribute_Reference
(Loc
, -- O._object'Acc
2862 Name_Unchecked_Access
,
2864 Make_Selected_Component
(Loc
,
2866 Make_Identifier
(Loc
, Name_uO
),
2868 Make_Identifier
(Loc
, Name_uObject
))),
2870 Make_Unchecked_Type_Conversion
(Loc
, -- entry index
2873 RTE
(RE_Protected_Entry_Index
), Loc
),
2875 Make_Identifier
(Loc
, Name_uI
)),
2877 Make_Identifier
(Loc
, Name_uA
)))))); -- abort status
2880 pragma Assert
(Is_Task_Type
(Conc_Typ
));
2884 -- System.Tasking.Rendezvous.Requeue_Protected_To_Task_Entry
2885 -- (Protection_Entries_Access (P),
2887 -- Task_Entry_Index (I),
2890 -- System.Tasking.Rendezvous.Requeue_Task_Entry
2892 -- Task_Entry_Index (I),
2897 Make_If_Statement
(Loc
,
2899 Make_Identifier
(Loc
, Name_uF
),
2904 -- Call to Requeue_Protected_To_Task_Entry
2906 Make_Procedure_Call_Statement
(Loc
,
2909 RTE
(RE_Requeue_Protected_To_Task_Entry
), Loc
),
2911 Parameter_Associations
=>
2914 Make_Unchecked_Type_Conversion
(Loc
, -- PEA (P)
2917 RTE
(RE_Protection_Entries_Access
), Loc
),
2919 Make_Identifier
(Loc
, Name_uP
)),
2921 Make_Selected_Component
(Loc
, -- O._task_id
2923 Make_Identifier
(Loc
, Name_uO
),
2925 Make_Identifier
(Loc
, Name_uTask_Id
)),
2927 Make_Unchecked_Type_Conversion
(Loc
, -- entry index
2930 RTE
(RE_Task_Entry_Index
), Loc
),
2932 Make_Identifier
(Loc
, Name_uI
)),
2934 Make_Identifier
(Loc
, Name_uA
)))), -- abort status
2939 -- Call to Requeue_Task_Entry
2941 Make_Procedure_Call_Statement
(Loc
,
2943 New_Reference_To
(RTE
(RE_Requeue_Task_Entry
), Loc
),
2945 Parameter_Associations
=>
2948 Make_Selected_Component
(Loc
, -- O._task_id
2950 Make_Identifier
(Loc
, Name_uO
),
2952 Make_Identifier
(Loc
, Name_uTask_Id
)),
2954 Make_Unchecked_Type_Conversion
(Loc
, -- entry index
2957 RTE
(RE_Task_Entry_Index
), Loc
),
2959 Make_Identifier
(Loc
, Name_uI
)),
2961 Make_Identifier
(Loc
, Name_uA
)))))); -- abort status
2964 -- Even though no declarations are needed in both cases, we allocate
2965 -- a list for entities added by Freeze.
2968 Make_Subprogram_Body
(Loc
,
2970 Make_Disp_Requeue_Spec
(Typ
),
2973 Handled_Statement_Sequence
=>
2974 Make_Handled_Sequence_Of_Statements
(Loc
, Stmts
));
2975 end Make_Disp_Requeue_Body
;
2977 ----------------------------
2978 -- Make_Disp_Requeue_Spec --
2979 ----------------------------
2981 function Make_Disp_Requeue_Spec
2982 (Typ
: Entity_Id
) return Node_Id
2984 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
2987 pragma Assert
(not Restriction_Active
(No_Dispatching_Calls
));
2989 -- O : in out Typ; - Object parameter
2990 -- F : Boolean; - Protected (True) / task (False) flag
2991 -- P : Address; - Protection_Entries_Access value
2992 -- I : Entry_Index - Index of entry call
2993 -- A : Boolean - Abort flag
2995 -- Note that the Protection_Entries_Access value is represented as a
2996 -- System.Address in order to avoid dragging in the tasking runtime
2997 -- when compiling sources without tasking constructs.
3000 Make_Procedure_Specification
(Loc
,
3001 Defining_Unit_Name
=>
3002 Make_Defining_Identifier
(Loc
, Name_uDisp_Requeue
),
3004 Parameter_Specifications
=>
3007 Make_Parameter_Specification
(Loc
, -- O
3008 Defining_Identifier
=>
3009 Make_Defining_Identifier
(Loc
, Name_uO
),
3011 New_Reference_To
(Typ
, Loc
),
3013 Out_Present
=> True),
3015 Make_Parameter_Specification
(Loc
, -- F
3016 Defining_Identifier
=>
3017 Make_Defining_Identifier
(Loc
, Name_uF
),
3019 New_Reference_To
(Standard_Boolean
, Loc
)),
3021 Make_Parameter_Specification
(Loc
, -- P
3022 Defining_Identifier
=>
3023 Make_Defining_Identifier
(Loc
, Name_uP
),
3025 New_Reference_To
(RTE
(RE_Address
), Loc
)),
3027 Make_Parameter_Specification
(Loc
, -- I
3028 Defining_Identifier
=>
3029 Make_Defining_Identifier
(Loc
, Name_uI
),
3031 New_Reference_To
(Standard_Integer
, Loc
)),
3033 Make_Parameter_Specification
(Loc
, -- A
3034 Defining_Identifier
=>
3035 Make_Defining_Identifier
(Loc
, Name_uA
),
3037 New_Reference_To
(Standard_Boolean
, Loc
))));
3038 end Make_Disp_Requeue_Spec
;
3040 ---------------------------------
3041 -- Make_Disp_Timed_Select_Body --
3042 ---------------------------------
3044 -- For interface types, generate:
3046 -- procedure _Disp_Timed_Select
3047 -- (T : in out <Typ>;
3049 -- P : System.Address;
3052 -- C : out Ada.Tags.Prim_Op_Kind;
3057 -- end _Disp_Timed_Select;
3059 -- For protected types, generate:
3061 -- procedure _Disp_Timed_Select
3062 -- (T : in out <Typ>;
3064 -- P : System.Address;
3067 -- C : out Ada.Tags.Prim_Op_Kind;
3073 -- C := Ada.Tags.Get_Prim_Op_Kind (Ada.Tags.Tag (<Typ>VP), S);
3075 -- if C = Ada.Tags.POK_Procedure
3076 -- or else C = Ada.Tags.POK_Protected_Procedure
3077 -- or else C = Ada.Tags.POK_Task_Procedure
3083 -- I := Ada.Tags.Get_Entry_Index (Ada.Tags.Tag (<Typ>VP), S);
3084 -- System.Tasking.Protected_Objects.Operations.
3085 -- Timed_Protected_Entry_Call
3086 -- (T._object'Access,
3087 -- System.Tasking.Protected_Objects.Protected_Entry_Index (I),
3092 -- end _Disp_Timed_Select;
3094 -- For task types, generate:
3096 -- procedure _Disp_Timed_Select
3097 -- (T : in out <Typ>;
3099 -- P : System.Address;
3102 -- C : out Ada.Tags.Prim_Op_Kind;
3108 -- I := Ada.Tags.Get_Entry_Index (Ada.Tags.Tag (<Typ>VP), S);
3109 -- System.Tasking.Rendezvous.Timed_Task_Entry_Call
3111 -- System.Tasking.Task_Entry_Index (I),
3116 -- end _Disp_Time_Select;
3118 function Make_Disp_Timed_Select_Body
3119 (Typ
: Entity_Id
) return Node_Id
3121 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
3122 Conc_Typ
: Entity_Id
:= Empty
;
3123 Decls
: constant List_Id
:= New_List
;
3126 Stmts
: constant List_Id
:= New_List
;
3129 pragma Assert
(not Restriction_Active
(No_Dispatching_Calls
));
3131 -- Null body is generated for interface types
3133 if Is_Interface
(Typ
) then
3135 Make_Subprogram_Body
(Loc
,
3137 Make_Disp_Timed_Select_Spec
(Typ
),
3140 Handled_Statement_Sequence
=>
3141 Make_Handled_Sequence_Of_Statements
(Loc
,
3142 New_List
(Make_Null_Statement
(Loc
))));
3145 DT_Ptr
:= Node
(First_Elmt
(Access_Disp_Table
(Typ
)));
3147 if Is_Concurrent_Record_Type
(Typ
) then
3148 Conc_Typ
:= Corresponding_Concurrent_Type
(Typ
);
3153 -- where I will be used to capture the entry index of the primitive
3154 -- wrapper at position S.
3157 Make_Object_Declaration
(Loc
,
3158 Defining_Identifier
=>
3159 Make_Defining_Identifier
(Loc
, Name_uI
),
3160 Object_Definition
=>
3161 New_Reference_To
(Standard_Integer
, Loc
)));
3164 -- C := Get_Prim_Op_Kind (tag! (<type>VP), S);
3166 -- if C = POK_Procedure
3167 -- or else C = POK_Protected_Procedure
3168 -- or else C = POK_Task_Procedure;
3174 Build_Common_Dispatching_Select_Statements
(Loc
, DT_Ptr
, Stmts
);
3177 -- I := Get_Entry_Index (tag! (<type>VP), S);
3179 -- I is the entry index and S is the dispatch table slot
3182 Make_Assignment_Statement
(Loc
,
3184 Make_Identifier
(Loc
, Name_uI
),
3186 Make_Function_Call
(Loc
,
3188 New_Reference_To
(RTE
(RE_Get_Entry_Index
), Loc
),
3189 Parameter_Associations
=>
3191 Unchecked_Convert_To
(RTE
(RE_Tag
),
3192 New_Reference_To
(DT_Ptr
, Loc
)),
3193 Make_Identifier
(Loc
, Name_uS
)))));
3197 if Ekind
(Conc_Typ
) = E_Protected_Type
then
3199 -- Build T._object'Access
3202 Make_Attribute_Reference
(Loc
,
3203 Attribute_Name
=> Name_Unchecked_Access
,
3205 Make_Selected_Component
(Loc
,
3206 Prefix
=> Make_Identifier
(Loc
, Name_uT
),
3207 Selector_Name
=> Make_Identifier
(Loc
, Name_uObject
)));
3209 -- Normal case, No_Entry_Queue restriction not active. In this
3210 -- case we generate:
3212 -- Timed_Protected_Entry_Call
3213 -- (T._object'access,
3214 -- Protected_Entry_Index! (I),
3217 -- where T is the protected object, I is the entry index, P are
3218 -- the wrapped parameters, D is the delay amount, M is the delay
3219 -- mode and F is the status flag.
3221 case Corresponding_Runtime_Package
(Conc_Typ
) is
3222 when System_Tasking_Protected_Objects_Entries
=>
3224 Make_Procedure_Call_Statement
(Loc
,
3227 (RTE
(RE_Timed_Protected_Entry_Call
), Loc
),
3228 Parameter_Associations
=>
3232 Make_Unchecked_Type_Conversion
(Loc
, -- entry index
3235 (RTE
(RE_Protected_Entry_Index
), Loc
),
3237 Make_Identifier
(Loc
, Name_uI
)),
3239 Make_Identifier
(Loc
, Name_uP
), -- parameter block
3240 Make_Identifier
(Loc
, Name_uD
), -- delay
3241 Make_Identifier
(Loc
, Name_uM
), -- delay mode
3242 Make_Identifier
(Loc
, Name_uF
)))); -- status flag
3244 when System_Tasking_Protected_Objects_Single_Entry
=>
3247 -- Timed_Protected_Single_Entry_Call
3248 -- (T._object'access, P, D, M, F);
3250 -- where T is the protected object, P is the wrapped
3251 -- parameters, D is the delay amount, M is the delay mode, F
3252 -- is the status flag.
3255 Make_Procedure_Call_Statement
(Loc
,
3258 (RTE
(RE_Timed_Protected_Single_Entry_Call
), Loc
),
3259 Parameter_Associations
=>
3262 Make_Identifier
(Loc
, Name_uP
), -- parameter block
3263 Make_Identifier
(Loc
, Name_uD
), -- delay
3264 Make_Identifier
(Loc
, Name_uM
), -- delay mode
3265 Make_Identifier
(Loc
, Name_uF
)))); -- status flag
3268 raise Program_Error
;
3274 pragma Assert
(Ekind
(Conc_Typ
) = E_Task_Type
);
3277 -- Timed_Task_Entry_Call (
3279 -- Task_Entry_Index! (I),
3285 -- where T is the task object, I is the entry index, P are the
3286 -- wrapped parameters, D is the delay amount, M is the delay
3287 -- mode and F is the status flag.
3290 Make_Procedure_Call_Statement
(Loc
,
3292 New_Reference_To
(RTE
(RE_Timed_Task_Entry_Call
), Loc
),
3293 Parameter_Associations
=>
3296 Make_Selected_Component
(Loc
, -- T._task_id
3298 Make_Identifier
(Loc
, Name_uT
),
3300 Make_Identifier
(Loc
, Name_uTask_Id
)),
3302 Make_Unchecked_Type_Conversion
(Loc
, -- entry index
3304 New_Reference_To
(RTE
(RE_Task_Entry_Index
), Loc
),
3306 Make_Identifier
(Loc
, Name_uI
)),
3308 Make_Identifier
(Loc
, Name_uP
), -- parameter block
3309 Make_Identifier
(Loc
, Name_uD
), -- delay
3310 Make_Identifier
(Loc
, Name_uM
), -- delay mode
3311 Make_Identifier
(Loc
, Name_uF
)))); -- status flag
3315 -- Ensure that the statements list is non-empty
3317 Append_To
(Stmts
, Make_Null_Statement
(Loc
));
3321 Make_Subprogram_Body
(Loc
,
3323 Make_Disp_Timed_Select_Spec
(Typ
),
3326 Handled_Statement_Sequence
=>
3327 Make_Handled_Sequence_Of_Statements
(Loc
, Stmts
));
3328 end Make_Disp_Timed_Select_Body
;
3330 ---------------------------------
3331 -- Make_Disp_Timed_Select_Spec --
3332 ---------------------------------
3334 function Make_Disp_Timed_Select_Spec
3335 (Typ
: Entity_Id
) return Node_Id
3337 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
3338 Def_Id
: constant Node_Id
:=
3339 Make_Defining_Identifier
(Loc
,
3340 Name_uDisp_Timed_Select
);
3341 Params
: constant List_Id
:= New_List
;
3344 pragma Assert
(not Restriction_Active
(No_Dispatching_Calls
));
3346 -- T : in out Typ; -- Object parameter
3347 -- S : Integer; -- Primitive operation slot
3348 -- P : Address; -- Wrapped parameters
3349 -- D : Duration; -- Delay
3350 -- M : Integer; -- Delay Mode
3351 -- C : out Prim_Op_Kind; -- Call kind
3352 -- F : out Boolean; -- Status flag
3354 Append_List_To
(Params
, New_List
(
3356 Make_Parameter_Specification
(Loc
,
3357 Defining_Identifier
=>
3358 Make_Defining_Identifier
(Loc
, Name_uT
),
3360 New_Reference_To
(Typ
, Loc
),
3362 Out_Present
=> True),
3364 Make_Parameter_Specification
(Loc
,
3365 Defining_Identifier
=>
3366 Make_Defining_Identifier
(Loc
, Name_uS
),
3368 New_Reference_To
(Standard_Integer
, Loc
)),
3370 Make_Parameter_Specification
(Loc
,
3371 Defining_Identifier
=>
3372 Make_Defining_Identifier
(Loc
, Name_uP
),
3374 New_Reference_To
(RTE
(RE_Address
), Loc
)),
3376 Make_Parameter_Specification
(Loc
,
3377 Defining_Identifier
=>
3378 Make_Defining_Identifier
(Loc
, Name_uD
),
3380 New_Reference_To
(Standard_Duration
, Loc
)),
3382 Make_Parameter_Specification
(Loc
,
3383 Defining_Identifier
=>
3384 Make_Defining_Identifier
(Loc
, Name_uM
),
3386 New_Reference_To
(Standard_Integer
, Loc
)),
3388 Make_Parameter_Specification
(Loc
,
3389 Defining_Identifier
=>
3390 Make_Defining_Identifier
(Loc
, Name_uC
),
3392 New_Reference_To
(RTE
(RE_Prim_Op_Kind
), Loc
),
3393 Out_Present
=> True)));
3396 Make_Parameter_Specification
(Loc
,
3397 Defining_Identifier
=>
3398 Make_Defining_Identifier
(Loc
, Name_uF
),
3400 New_Reference_To
(Standard_Boolean
, Loc
),
3401 Out_Present
=> True));
3404 Make_Procedure_Specification
(Loc
,
3405 Defining_Unit_Name
=> Def_Id
,
3406 Parameter_Specifications
=> Params
);
3407 end Make_Disp_Timed_Select_Spec
;
3413 -- The frontend supports two models for expanding dispatch tables
3414 -- associated with library-level defined tagged types: statically
3415 -- and non-statically allocated dispatch tables. In the former case
3416 -- the object containing the dispatch table is constant and it is
3417 -- initialized by means of a positional aggregate. In the latter case,
3418 -- the object containing the dispatch table is a variable which is
3419 -- initialized by means of assignments.
3421 -- In case of locally defined tagged types, the object containing the
3422 -- object containing the dispatch table is always a variable (instead
3423 -- of a constant). This is currently required to give support to late
3424 -- overriding of primitives. For example:
3426 -- procedure Example is
3428 -- type T1 is tagged null record;
3429 -- procedure Prim (O : T1);
3432 -- type T2 is new Pkg.T1 with null record;
3433 -- procedure Prim (X : T2) is -- late overriding
3439 function Make_DT
(Typ
: Entity_Id
; N
: Node_Id
:= Empty
) return List_Id
is
3440 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
3442 Max_Predef_Prims
: constant Int
:=
3446 (Parent
(RTE
(RE_Max_Predef_Prims
)))));
3448 DT_Decl
: constant Elist_Id
:= New_Elmt_List
;
3449 DT_Aggr
: constant Elist_Id
:= New_Elmt_List
;
3450 -- Entities marked with attribute Is_Dispatch_Table_Entity
3452 procedure Check_Premature_Freezing
(Subp
: Entity_Id
; Typ
: Entity_Id
);
3453 -- Verify that all non-tagged types in the profile of a subprogram
3454 -- are frozen at the point the subprogram is frozen. This enforces
3455 -- the rule on RM 13.14 (14) as modified by AI05-019. At the point a
3456 -- subprogram is frozen, enough must be known about it to build the
3457 -- activation record for it, which requires at least that the size of
3458 -- all parameters be known. Controlling arguments are by-reference,
3459 -- and therefore the rule only applies to non-tagged types.
3460 -- Typical violation of the rule involves an object declaration that
3461 -- freezes a tagged type, when one of its primitive operations has a
3462 -- type in its profile whose full view has not been analyzed yet.
3464 procedure Export_DT
(Typ
: Entity_Id
; DT
: Entity_Id
; Index
: Nat
:= 0);
3465 -- Export the dispatch table DT of tagged type Typ. Required to generate
3466 -- forward references and statically allocate the table. For primary
3467 -- dispatch tables Index is 0; for secondary dispatch tables the value
3468 -- of index must match the Suffix_Index value assigned to the table by
3469 -- Make_Tags when generating its unique external name, and it is used to
3470 -- retrieve from the Dispatch_Table_Wrappers list associated with Typ
3471 -- the external name generated by Import_DT.
3473 procedure Make_Secondary_DT
3477 Num_Iface_Prims
: Nat
;
3478 Iface_DT_Ptr
: Entity_Id
;
3479 Predef_Prims_Ptr
: Entity_Id
;
3480 Build_Thunks
: Boolean;
3482 -- Ada 2005 (AI-251): Expand the declarations for a Secondary Dispatch
3483 -- Table of Typ associated with Iface. Each abstract interface of Typ
3484 -- has two secondary dispatch tables: one containing pointers to thunks
3485 -- and another containing pointers to the primitives covering the
3486 -- interface primitives. The former secondary table is generated when
3487 -- Build_Thunks is True, and provides common support for dispatching
3488 -- calls through interface types; the latter secondary table is
3489 -- generated when Build_Thunks is False, and provides support for
3490 -- Generic Dispatching Constructors that dispatch calls through
3491 -- interface types. When constructing this latter table the value
3492 -- of Suffix_Index is -1 to indicate that there is no need to export
3493 -- such table when building statically allocated dispatch tables; a
3494 -- positive value of Suffix_Index must match the Suffix_Index value
3495 -- assigned to this secondary dispatch table by Make_Tags when its
3496 -- unique external name was generated.
3498 ------------------------------
3499 -- Check_Premature_Freezing --
3500 ------------------------------
3502 procedure Check_Premature_Freezing
(Subp
: Entity_Id
; Typ
: Entity_Id
) is
3505 and then Is_Private_Type
(Typ
)
3506 and then No
(Full_View
(Typ
))
3507 and then not Is_Generic_Type
(Typ
)
3508 and then not Is_Tagged_Type
(Typ
)
3509 and then not Is_Frozen
(Typ
)
3511 Error_Msg_Sloc
:= Sloc
(Subp
);
3513 ("declaration must appear after completion of type &", N
, Typ
);
3515 ("\which is an untagged type in the profile of"
3516 & " primitive operation & declared#",
3519 end Check_Premature_Freezing
;
3525 procedure Export_DT
(Typ
: Entity_Id
; DT
: Entity_Id
; Index
: Nat
:= 0)
3531 Set_Is_Statically_Allocated
(DT
);
3532 Set_Is_True_Constant
(DT
);
3533 Set_Is_Exported
(DT
);
3536 Elmt
:= First_Elmt
(Dispatch_Table_Wrappers
(Typ
));
3537 while Count
/= Index
loop
3542 pragma Assert
(Related_Type
(Node
(Elmt
)) = Typ
);
3545 (Entity
=> Node
(Elmt
),
3546 Has_Suffix
=> True);
3548 Set_Interface_Name
(DT
,
3549 Make_String_Literal
(Loc
,
3550 Strval
=> String_From_Name_Buffer
));
3552 -- Ensure proper Sprint output of this implicit importation
3554 Set_Is_Internal
(DT
);
3558 -----------------------
3559 -- Make_Secondary_DT --
3560 -----------------------
3562 procedure Make_Secondary_DT
3566 Num_Iface_Prims
: Nat
;
3567 Iface_DT_Ptr
: Entity_Id
;
3568 Predef_Prims_Ptr
: Entity_Id
;
3569 Build_Thunks
: Boolean;
3572 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
3573 Exporting_Table
: constant Boolean :=
3574 Building_Static_DT
(Typ
)
3575 and then Suffix_Index
> 0;
3576 Iface_DT
: constant Entity_Id
:= Make_Temporary
(Loc
, 'T');
3577 Predef_Prims
: constant Entity_Id
:= Make_Temporary
(Loc
, 'R');
3578 DT_Constr_List
: List_Id
;
3579 DT_Aggr_List
: List_Id
;
3580 Empty_DT
: Boolean := False;
3581 Nb_Predef_Prims
: Nat
:= 0;
3585 OSD_Aggr_List
: List_Id
;
3588 Prim_Elmt
: Elmt_Id
;
3589 Prim_Ops_Aggr_List
: List_Id
;
3592 -- Handle cases in which we do not generate statically allocated
3595 if not Building_Static_DT
(Typ
) then
3596 Set_Ekind
(Predef_Prims
, E_Variable
);
3597 Set_Ekind
(Iface_DT
, E_Variable
);
3599 -- Statically allocated dispatch tables and related entities are
3603 Set_Ekind
(Predef_Prims
, E_Constant
);
3604 Set_Is_Statically_Allocated
(Predef_Prims
);
3605 Set_Is_True_Constant
(Predef_Prims
);
3607 Set_Ekind
(Iface_DT
, E_Constant
);
3608 Set_Is_Statically_Allocated
(Iface_DT
);
3609 Set_Is_True_Constant
(Iface_DT
);
3612 -- Calculate the number of slots of the dispatch table. If the number
3613 -- of primitives of Typ is 0 we reserve a dummy single entry for its
3614 -- DT because at run-time the pointer to this dummy entry will be
3617 if Num_Iface_Prims
= 0 then
3621 Nb_Prim
:= Num_Iface_Prims
;
3626 -- Predef_Prims : Address_Array (1 .. Default_Prim_Ops_Count) :=
3627 -- (predef-prim-op-thunk-1'address,
3628 -- predef-prim-op-thunk-2'address,
3630 -- predef-prim-op-thunk-n'address);
3631 -- for Predef_Prims'Alignment use Address'Alignment
3633 -- Stage 1: Calculate the number of predefined primitives
3635 if not Building_Static_DT
(Typ
) then
3636 Nb_Predef_Prims
:= Max_Predef_Prims
;
3638 Prim_Elmt
:= First_Elmt
(Primitive_Operations
(Typ
));
3639 while Present
(Prim_Elmt
) loop
3640 Prim
:= Node
(Prim_Elmt
);
3642 if Is_Predefined_Dispatching_Operation
(Prim
)
3643 and then not Is_Abstract_Subprogram
(Prim
)
3645 Pos
:= UI_To_Int
(DT_Position
(Prim
));
3647 if Pos
> Nb_Predef_Prims
then
3648 Nb_Predef_Prims
:= Pos
;
3652 Next_Elmt
(Prim_Elmt
);
3656 -- Stage 2: Create the thunks associated with the predefined
3657 -- primitives and save their entity to fill the aggregate.
3660 Prim_Table
: array (Nat
range 1 .. Nb_Predef_Prims
) of Entity_Id
;
3662 Thunk_Id
: Entity_Id
;
3663 Thunk_Code
: Node_Id
;
3666 Prim_Ops_Aggr_List
:= New_List
;
3667 Prim_Table
:= (others => Empty
);
3669 if Building_Static_DT
(Typ
) then
3670 Prim_Elmt
:= First_Elmt
(Primitive_Operations
(Typ
));
3671 while Present
(Prim_Elmt
) loop
3672 Prim
:= Node
(Prim_Elmt
);
3674 if Is_Predefined_Dispatching_Operation
(Prim
)
3675 and then not Is_Abstract_Subprogram
(Prim
)
3676 and then not Is_Eliminated
(Prim
)
3677 and then not Present
(Prim_Table
3678 (UI_To_Int
(DT_Position
(Prim
))))
3680 if not Build_Thunks
then
3681 Prim_Table
(UI_To_Int
(DT_Position
(Prim
))) :=
3685 Expand_Interface_Thunk
3686 (Ultimate_Alias
(Prim
), Thunk_Id
, Thunk_Code
);
3688 if Present
(Thunk_Id
) then
3689 Append_To
(Result
, Thunk_Code
);
3690 Prim_Table
(UI_To_Int
(DT_Position
(Prim
)))
3696 Next_Elmt
(Prim_Elmt
);
3700 for J
in Prim_Table
'Range loop
3701 if Present
(Prim_Table
(J
)) then
3703 Unchecked_Convert_To
(RTE
(RE_Prim_Ptr
),
3704 Make_Attribute_Reference
(Loc
,
3705 Prefix
=> New_Reference_To
(Prim_Table
(J
), Loc
),
3706 Attribute_Name
=> Name_Unrestricted_Access
));
3708 New_Node
:= Make_Null
(Loc
);
3711 Append_To
(Prim_Ops_Aggr_List
, New_Node
);
3715 Make_Aggregate
(Loc
,
3716 Expressions
=> Prim_Ops_Aggr_List
);
3718 -- Remember aggregates initializing dispatch tables
3720 Append_Elmt
(New_Node
, DT_Aggr
);
3723 Make_Subtype_Declaration
(Loc
,
3724 Defining_Identifier
=> Make_Temporary
(Loc
, 'S'),
3725 Subtype_Indication
=>
3726 New_Reference_To
(RTE
(RE_Address_Array
), Loc
));
3728 Append_To
(Result
, Decl
);
3731 Make_Object_Declaration
(Loc
,
3732 Defining_Identifier
=> Predef_Prims
,
3733 Constant_Present
=> Building_Static_DT
(Typ
),
3734 Aliased_Present
=> True,
3735 Object_Definition
=> New_Reference_To
3736 (Defining_Identifier
(Decl
), Loc
),
3737 Expression
=> New_Node
));
3740 Make_Attribute_Definition_Clause
(Loc
,
3741 Name
=> New_Reference_To
(Predef_Prims
, Loc
),
3742 Chars
=> Name_Alignment
,
3744 Make_Attribute_Reference
(Loc
,
3746 New_Reference_To
(RTE
(RE_Integer_Address
), Loc
),
3747 Attribute_Name
=> Name_Alignment
)));
3752 -- OSD : Ada.Tags.Object_Specific_Data (Nb_Prims) :=
3753 -- (OSD_Table => (1 => <value>,
3757 -- Iface_DT : Dispatch_Table (Nb_Prims) :=
3758 -- ([ Signature => <sig-value> ],
3759 -- Tag_Kind => <tag_kind-value>,
3760 -- Predef_Prims => Predef_Prims'Address,
3761 -- Offset_To_Top => 0,
3762 -- OSD => OSD'Address,
3763 -- Prims_Ptr => (prim-op-1'address,
3764 -- prim-op-2'address,
3766 -- prim-op-n'address));
3767 -- for Iface_DT'Alignment use Address'Alignment;
3769 -- Stage 3: Initialize the discriminant and the record components
3771 DT_Constr_List
:= New_List
;
3772 DT_Aggr_List
:= New_List
;
3774 -- Nb_Prim. If the tagged type has no primitives we add a dummy
3775 -- slot whose address will be the tag of this type.
3778 New_Node
:= Make_Integer_Literal
(Loc
, 1);
3780 New_Node
:= Make_Integer_Literal
(Loc
, Nb_Prim
);
3783 Append_To
(DT_Constr_List
, New_Node
);
3784 Append_To
(DT_Aggr_List
, New_Copy
(New_Node
));
3788 if RTE_Record_Component_Available
(RE_Signature
) then
3789 Append_To
(DT_Aggr_List
,
3790 New_Reference_To
(RTE
(RE_Secondary_DT
), Loc
));
3795 if RTE_Record_Component_Available
(RE_Tag_Kind
) then
3796 Append_To
(DT_Aggr_List
, Tagged_Kind
(Typ
));
3801 Append_To
(DT_Aggr_List
,
3802 Make_Attribute_Reference
(Loc
,
3803 Prefix
=> New_Reference_To
(Predef_Prims
, Loc
),
3804 Attribute_Name
=> Name_Address
));
3806 -- Note: The correct value of Offset_To_Top will be set by the init
3809 Append_To
(DT_Aggr_List
, Make_Integer_Literal
(Loc
, 0));
3811 -- Generate the Object Specific Data table required to dispatch calls
3812 -- through synchronized interfaces.
3815 or else Is_Abstract_Type
(Typ
)
3816 or else Is_Controlled
(Typ
)
3817 or else Restriction_Active
(No_Dispatching_Calls
)
3818 or else not Is_Limited_Type
(Typ
)
3819 or else not Has_Interfaces
(Typ
)
3820 or else not Build_Thunks
3821 or else not RTE_Record_Component_Available
(RE_OSD_Table
)
3823 -- No OSD table required
3825 Append_To
(DT_Aggr_List
,
3826 New_Reference_To
(RTE
(RE_Null_Address
), Loc
));
3829 OSD_Aggr_List
:= New_List
;
3832 Prim_Table
: array (Nat
range 1 .. Nb_Prim
) of Entity_Id
;
3834 Prim_Alias
: Entity_Id
;
3835 Prim_Elmt
: Elmt_Id
;
3841 Prim_Table
:= (others => Empty
);
3842 Prim_Alias
:= Empty
;
3844 Prim_Elmt
:= First_Elmt
(Primitive_Operations
(Typ
));
3845 while Present
(Prim_Elmt
) loop
3846 Prim
:= Node
(Prim_Elmt
);
3848 if Present
(Interface_Alias
(Prim
))
3849 and then Find_Dispatching_Type
3850 (Interface_Alias
(Prim
)) = Iface
3852 Prim_Alias
:= Interface_Alias
(Prim
);
3853 E
:= Ultimate_Alias
(Prim
);
3854 Pos
:= UI_To_Int
(DT_Position
(Prim_Alias
));
3856 if Present
(Prim_Table
(Pos
)) then
3857 pragma Assert
(Prim_Table
(Pos
) = E
);
3861 Prim_Table
(Pos
) := E
;
3863 Append_To
(OSD_Aggr_List
,
3864 Make_Component_Association
(Loc
,
3865 Choices
=> New_List
(
3866 Make_Integer_Literal
(Loc
,
3867 DT_Position
(Prim_Alias
))),
3869 Make_Integer_Literal
(Loc
,
3870 DT_Position
(Alias
(Prim
)))));
3876 Next_Elmt
(Prim_Elmt
);
3878 pragma Assert
(Count
= Nb_Prim
);
3881 OSD
:= Make_Temporary
(Loc
, 'I');
3884 Make_Object_Declaration
(Loc
,
3885 Defining_Identifier
=> OSD
,
3886 Object_Definition
=>
3887 Make_Subtype_Indication
(Loc
,
3889 New_Reference_To
(RTE
(RE_Object_Specific_Data
), Loc
),
3891 Make_Index_Or_Discriminant_Constraint
(Loc
,
3892 Constraints
=> New_List
(
3893 Make_Integer_Literal
(Loc
, Nb_Prim
)))),
3896 Make_Aggregate
(Loc
,
3897 Component_Associations
=> New_List
(
3898 Make_Component_Association
(Loc
,
3899 Choices
=> New_List
(
3901 (RTE_Record_Component
(RE_OSD_Num_Prims
), Loc
)),
3903 Make_Integer_Literal
(Loc
, Nb_Prim
)),
3905 Make_Component_Association
(Loc
,
3906 Choices
=> New_List
(
3908 (RTE_Record_Component
(RE_OSD_Table
), Loc
)),
3909 Expression
=> Make_Aggregate
(Loc
,
3910 Component_Associations
=> OSD_Aggr_List
))))));
3913 Make_Attribute_Definition_Clause
(Loc
,
3914 Name
=> New_Reference_To
(OSD
, Loc
),
3915 Chars
=> Name_Alignment
,
3917 Make_Attribute_Reference
(Loc
,
3919 New_Reference_To
(RTE
(RE_Integer_Address
), Loc
),
3920 Attribute_Name
=> Name_Alignment
)));
3922 -- In secondary dispatch tables the Typeinfo component contains
3923 -- the address of the Object Specific Data (see a-tags.ads)
3925 Append_To
(DT_Aggr_List
,
3926 Make_Attribute_Reference
(Loc
,
3927 Prefix
=> New_Reference_To
(OSD
, Loc
),
3928 Attribute_Name
=> Name_Address
));
3931 -- Initialize the table of primitive operations
3933 Prim_Ops_Aggr_List
:= New_List
;
3936 Append_To
(Prim_Ops_Aggr_List
, Make_Null
(Loc
));
3938 elsif Is_Abstract_Type
(Typ
)
3939 or else not Building_Static_DT
(Typ
)
3941 for J
in 1 .. Nb_Prim
loop
3942 Append_To
(Prim_Ops_Aggr_List
, Make_Null
(Loc
));
3947 Prim_Table
: array (Nat
range 1 .. Nb_Prim
) of Entity_Id
;
3949 Thunk_Code
: Node_Id
;
3950 Thunk_Id
: Entity_Id
;
3953 Prim_Table
:= (others => Empty
);
3955 Prim_Elmt
:= First_Elmt
(Primitive_Operations
(Typ
));
3956 while Present
(Prim_Elmt
) loop
3957 Prim
:= Node
(Prim_Elmt
);
3959 -- Do not reference predefined primitives because they
3960 -- are located in a separate dispatch table; skip also
3961 -- abstract and eliminated primitives.
3963 if not Is_Predefined_Dispatching_Operation
(Prim
)
3964 and then Present
(Interface_Alias
(Prim
))
3965 and then not Is_Abstract_Subprogram
(Alias
(Prim
))
3966 and then not Is_Eliminated
(Alias
(Prim
))
3967 and then Find_Dispatching_Type
3968 (Interface_Alias
(Prim
)) = Iface
3970 -- Generate the code of the thunk only if the abstract
3971 -- interface type is not an immediate ancestor of
3972 -- Tagged_Type; otherwise the DT associated with the
3973 -- interface is the primary DT.
3975 and then not Is_Ancestor
(Iface
, Typ
)
3977 if not Build_Thunks
then
3979 UI_To_Int
(DT_Position
(Interface_Alias
(Prim
)));
3980 Prim_Table
(Pos
) := Alias
(Prim
);
3982 Expand_Interface_Thunk
(Prim
, Thunk_Id
, Thunk_Code
);
3984 if Present
(Thunk_Id
) then
3986 UI_To_Int
(DT_Position
(Interface_Alias
(Prim
)));
3988 Prim_Table
(Pos
) := Thunk_Id
;
3989 Append_To
(Result
, Thunk_Code
);
3994 Next_Elmt
(Prim_Elmt
);
3997 for J
in Prim_Table
'Range loop
3998 if Present
(Prim_Table
(J
)) then
4000 Unchecked_Convert_To
(RTE
(RE_Prim_Ptr
),
4001 Make_Attribute_Reference
(Loc
,
4002 Prefix
=> New_Reference_To
(Prim_Table
(J
), Loc
),
4003 Attribute_Name
=> Name_Unrestricted_Access
));
4005 New_Node
:= Make_Null
(Loc
);
4008 Append_To
(Prim_Ops_Aggr_List
, New_Node
);
4014 Make_Aggregate
(Loc
,
4015 Expressions
=> Prim_Ops_Aggr_List
);
4017 Append_To
(DT_Aggr_List
, New_Node
);
4019 -- Remember aggregates initializing dispatch tables
4021 Append_Elmt
(New_Node
, DT_Aggr
);
4023 -- Note: Secondary dispatch tables cannot be declared constant
4024 -- because the component Offset_To_Top is currently initialized
4025 -- by the IP routine.
4028 Make_Object_Declaration
(Loc
,
4029 Defining_Identifier
=> Iface_DT
,
4030 Aliased_Present
=> True,
4031 Constant_Present
=> False,
4033 Object_Definition
=>
4034 Make_Subtype_Indication
(Loc
,
4035 Subtype_Mark
=> New_Reference_To
4036 (RTE
(RE_Dispatch_Table_Wrapper
), Loc
),
4037 Constraint
=> Make_Index_Or_Discriminant_Constraint
(Loc
,
4038 Constraints
=> DT_Constr_List
)),
4041 Make_Aggregate
(Loc
,
4042 Expressions
=> DT_Aggr_List
)));
4045 Make_Attribute_Definition_Clause
(Loc
,
4046 Name
=> New_Reference_To
(Iface_DT
, Loc
),
4047 Chars
=> Name_Alignment
,
4050 Make_Attribute_Reference
(Loc
,
4052 New_Reference_To
(RTE
(RE_Integer_Address
), Loc
),
4053 Attribute_Name
=> Name_Alignment
)));
4055 if Exporting_Table
then
4056 Export_DT
(Typ
, Iface_DT
, Suffix_Index
);
4058 -- Generate code to create the pointer to the dispatch table
4060 -- Iface_DT_Ptr : Tag := Tag!(DT.Prims_Ptr'Address);
4062 -- Note: This declaration is not added here if the table is exported
4063 -- because in such case Make_Tags has already added this declaration.
4067 Make_Object_Declaration
(Loc
,
4068 Defining_Identifier
=> Iface_DT_Ptr
,
4069 Constant_Present
=> True,
4071 Object_Definition
=>
4072 New_Reference_To
(RTE
(RE_Interface_Tag
), Loc
),
4075 Unchecked_Convert_To
(RTE
(RE_Interface_Tag
),
4076 Make_Attribute_Reference
(Loc
,
4078 Make_Selected_Component
(Loc
,
4079 Prefix
=> New_Reference_To
(Iface_DT
, Loc
),
4082 (RTE_Record_Component
(RE_Prims_Ptr
), Loc
)),
4083 Attribute_Name
=> Name_Address
))));
4087 Make_Object_Declaration
(Loc
,
4088 Defining_Identifier
=> Predef_Prims_Ptr
,
4089 Constant_Present
=> True,
4091 Object_Definition
=>
4092 New_Reference_To
(RTE
(RE_Address
), Loc
),
4095 Make_Attribute_Reference
(Loc
,
4097 Make_Selected_Component
(Loc
,
4098 Prefix
=> New_Reference_To
(Iface_DT
, Loc
),
4101 (RTE_Record_Component
(RE_Predef_Prims
), Loc
)),
4102 Attribute_Name
=> Name_Address
)));
4104 -- Remember entities containing dispatch tables
4106 Append_Elmt
(Predef_Prims
, DT_Decl
);
4107 Append_Elmt
(Iface_DT
, DT_Decl
);
4108 end Make_Secondary_DT
;
4112 Elab_Code
: constant List_Id
:= New_List
;
4113 Result
: constant List_Id
:= New_List
;
4114 Tname
: constant Name_Id
:= Chars
(Typ
);
4116 AI_Tag_Elmt
: Elmt_Id
;
4117 AI_Tag_Comp
: Elmt_Id
;
4118 DT_Aggr_List
: List_Id
;
4119 DT_Constr_List
: List_Id
;
4123 Iface_Table_Node
: Node_Id
;
4124 Name_ITable
: Name_Id
;
4125 Nb_Predef_Prims
: Nat
:= 0;
4128 Num_Ifaces
: Nat
:= 0;
4129 Parent_Typ
: Entity_Id
;
4131 Prim_Elmt
: Elmt_Id
;
4132 Prim_Ops_Aggr_List
: List_Id
;
4134 Typ_Comps
: Elist_Id
;
4135 Typ_Ifaces
: Elist_Id
;
4136 TSD_Aggr_List
: List_Id
;
4137 TSD_Tags_List
: List_Id
;
4139 -- The following name entries are used by Make_DT to generate a number
4140 -- of entities related to a tagged type. These entities may be generated
4141 -- in a scope other than that of the tagged type declaration, and if
4142 -- the entities for two tagged types with the same name happen to be
4143 -- generated in the same scope, we have to take care to use different
4144 -- names. This is achieved by means of a unique serial number appended
4145 -- to each generated entity name.
4147 Name_DT
: constant Name_Id
:=
4148 New_External_Name
(Tname
, 'T', Suffix_Index
=> -1);
4149 Name_Exname
: constant Name_Id
:=
4150 New_External_Name
(Tname
, 'E', Suffix_Index
=> -1);
4151 Name_HT_Link
: constant Name_Id
:=
4152 New_External_Name
(Tname
, 'H', Suffix_Index
=> -1);
4153 Name_Predef_Prims
: constant Name_Id
:=
4154 New_External_Name
(Tname
, 'R', Suffix_Index
=> -1);
4155 Name_SSD
: constant Name_Id
:=
4156 New_External_Name
(Tname
, 'S', Suffix_Index
=> -1);
4157 Name_TSD
: constant Name_Id
:=
4158 New_External_Name
(Tname
, 'B', Suffix_Index
=> -1);
4160 -- Entities built with above names
4162 DT
: constant Entity_Id
:=
4163 Make_Defining_Identifier
(Loc
, Name_DT
);
4164 Exname
: constant Entity_Id
:=
4165 Make_Defining_Identifier
(Loc
, Name_Exname
);
4166 HT_Link
: constant Entity_Id
:=
4167 Make_Defining_Identifier
(Loc
, Name_HT_Link
);
4168 Predef_Prims
: constant Entity_Id
:=
4169 Make_Defining_Identifier
(Loc
, Name_Predef_Prims
);
4170 SSD
: constant Entity_Id
:=
4171 Make_Defining_Identifier
(Loc
, Name_SSD
);
4172 TSD
: constant Entity_Id
:=
4173 Make_Defining_Identifier
(Loc
, Name_TSD
);
4175 -- Start of processing for Make_DT
4178 pragma Assert
(Is_Frozen
(Typ
));
4180 -- Handle cases in which there is no need to build the dispatch table
4182 if Has_Dispatch_Table
(Typ
)
4183 or else No
(Access_Disp_Table
(Typ
))
4184 or else Is_CPP_Class
(Typ
)
4188 elsif No_Run_Time_Mode
then
4189 Error_Msg_CRT
("tagged types", Typ
);
4192 elsif not RTE_Available
(RE_Tag
) then
4194 Make_Object_Declaration
(Loc
,
4195 Defining_Identifier
=> Node
(First_Elmt
4196 (Access_Disp_Table
(Typ
))),
4197 Object_Definition
=> New_Reference_To
(RTE
(RE_Tag
), Loc
),
4198 Constant_Present
=> True,
4200 Unchecked_Convert_To
(RTE
(RE_Tag
),
4201 New_Reference_To
(RTE
(RE_Null_Address
), Loc
))));
4203 Analyze_List
(Result
, Suppress
=> All_Checks
);
4204 Error_Msg_CRT
("tagged types", Typ
);
4208 -- Ensure that the value of Max_Predef_Prims defined in a-tags is
4209 -- correct. Valid values are 10 under configurable runtime or 16
4210 -- with full runtime.
4212 if RTE_Available
(RE_Interface_Data
) then
4213 if Max_Predef_Prims
/= 16 then
4214 Error_Msg_N
("run-time library configuration error", Typ
);
4218 if Max_Predef_Prims
/= 10 then
4219 Error_Msg_N
("run-time library configuration error", Typ
);
4220 Error_Msg_CRT
("tagged types", Typ
);
4225 -- Initialize Parent_Typ handling private types
4227 Parent_Typ
:= Etype
(Typ
);
4229 if Present
(Full_View
(Parent_Typ
)) then
4230 Parent_Typ
:= Full_View
(Parent_Typ
);
4233 -- Ensure that all the primitives are frozen. This is only required when
4234 -- building static dispatch tables --- the primitives must be frozen to
4235 -- be referenced (otherwise we have problems with the backend). It is
4236 -- not a requirement with nonstatic dispatch tables because in this case
4237 -- we generate now an empty dispatch table; the extra code required to
4238 -- register the primitives in the slots will be generated later --- when
4239 -- each primitive is frozen (see Freeze_Subprogram).
4241 if Building_Static_DT
(Typ
)
4242 and then not Is_CPP_Class
(Typ
)
4245 Save
: constant Boolean := Freezing_Library_Level_Tagged_Type
;
4247 Prim_Elmt
: Elmt_Id
;
4251 Freezing_Library_Level_Tagged_Type
:= True;
4253 Prim_Elmt
:= First_Elmt
(Primitive_Operations
(Typ
));
4254 while Present
(Prim_Elmt
) loop
4255 Prim
:= Node
(Prim_Elmt
);
4256 Frnodes
:= Freeze_Entity
(Prim
, Loc
);
4262 F
:= First_Formal
(Prim
);
4263 while Present
(F
) loop
4264 Check_Premature_Freezing
(Prim
, Etype
(F
));
4268 Check_Premature_Freezing
(Prim
, Etype
(Prim
));
4271 if Present
(Frnodes
) then
4272 Append_List_To
(Result
, Frnodes
);
4275 Next_Elmt
(Prim_Elmt
);
4278 Freezing_Library_Level_Tagged_Type
:= Save
;
4282 -- Ada 2005 (AI-251): Build the secondary dispatch tables
4284 if Has_Interfaces
(Typ
) then
4285 Collect_Interface_Components
(Typ
, Typ_Comps
);
4287 -- Each secondary dispatch table is assigned an unique positive
4288 -- suffix index; such value also corresponds with the location of
4289 -- its entity in the Dispatch_Table_Wrappers list (see Make_Tags).
4291 -- Note: This value must be kept sync with the Suffix_Index values
4292 -- generated by Make_Tags
4296 Next_Elmt
(Next_Elmt
(First_Elmt
(Access_Disp_Table
(Typ
))));
4298 AI_Tag_Comp
:= First_Elmt
(Typ_Comps
);
4299 while Present
(AI_Tag_Comp
) loop
4301 -- Build the secondary table containing pointers to thunks
4305 Iface
=> Base_Type
(Related_Type
(Node
(AI_Tag_Comp
))),
4306 Suffix_Index
=> Suffix_Index
,
4307 Num_Iface_Prims
=> UI_To_Int
4308 (DT_Entry_Count
(Node
(AI_Tag_Comp
))),
4309 Iface_DT_Ptr
=> Node
(AI_Tag_Elmt
),
4310 Predef_Prims_Ptr
=> Node
(Next_Elmt
(AI_Tag_Elmt
)),
4311 Build_Thunks
=> True,
4314 -- Skip secondary dispatch table and secondary dispatch table of
4315 -- predefined primitives
4317 Next_Elmt
(AI_Tag_Elmt
);
4318 Next_Elmt
(AI_Tag_Elmt
);
4320 -- Build the secondary table containing pointers to primitives
4321 -- (used to give support to Generic Dispatching Constructors).
4325 Iface
=> Base_Type
(Related_Type
(Node
(AI_Tag_Comp
))),
4327 Num_Iface_Prims
=> UI_To_Int
4328 (DT_Entry_Count
(Node
(AI_Tag_Comp
))),
4329 Iface_DT_Ptr
=> Node
(AI_Tag_Elmt
),
4330 Predef_Prims_Ptr
=> Node
(Next_Elmt
(AI_Tag_Elmt
)),
4331 Build_Thunks
=> False,
4334 -- Skip secondary dispatch table and secondary dispatch table of
4335 -- predefined primitives
4337 Next_Elmt
(AI_Tag_Elmt
);
4338 Next_Elmt
(AI_Tag_Elmt
);
4340 Suffix_Index
:= Suffix_Index
+ 1;
4341 Next_Elmt
(AI_Tag_Comp
);
4345 -- Get the _tag entity and the number of primitives of its dispatch
4348 DT_Ptr
:= Node
(First_Elmt
(Access_Disp_Table
(Typ
)));
4349 Nb_Prim
:= UI_To_Int
(DT_Entry_Count
(First_Tag_Component
(Typ
)));
4351 Set_Is_Statically_Allocated
(DT
, Is_Library_Level_Tagged_Type
(Typ
));
4352 Set_Is_Statically_Allocated
(SSD
, Is_Library_Level_Tagged_Type
(Typ
));
4353 Set_Is_Statically_Allocated
(TSD
, Is_Library_Level_Tagged_Type
(Typ
));
4354 Set_Is_Statically_Allocated
(Predef_Prims
,
4355 Is_Library_Level_Tagged_Type
(Typ
));
4357 -- In case of locally defined tagged type we declare the object
4358 -- containing the dispatch table by means of a variable. Its
4359 -- initialization is done later by means of an assignment. This is
4360 -- required to generate its External_Tag.
4362 if not Building_Static_DT
(Typ
) then
4365 -- DT : No_Dispatch_Table_Wrapper;
4366 -- for DT'Alignment use Address'Alignment;
4367 -- DT_Ptr : Tag := !Tag (DT.NDT_Prims_Ptr'Address);
4369 if not Has_DT
(Typ
) then
4371 Make_Object_Declaration
(Loc
,
4372 Defining_Identifier
=> DT
,
4373 Aliased_Present
=> True,
4374 Constant_Present
=> False,
4375 Object_Definition
=>
4377 (RTE
(RE_No_Dispatch_Table_Wrapper
), Loc
)));
4380 Make_Attribute_Definition_Clause
(Loc
,
4381 Name
=> New_Reference_To
(DT
, Loc
),
4382 Chars
=> Name_Alignment
,
4384 Make_Attribute_Reference
(Loc
,
4386 New_Reference_To
(RTE
(RE_Integer_Address
), Loc
),
4387 Attribute_Name
=> Name_Alignment
)));
4390 Make_Object_Declaration
(Loc
,
4391 Defining_Identifier
=> DT_Ptr
,
4392 Object_Definition
=> New_Reference_To
(RTE
(RE_Tag
), Loc
),
4393 Constant_Present
=> True,
4395 Unchecked_Convert_To
(RTE
(RE_Tag
),
4396 Make_Attribute_Reference
(Loc
,
4398 Make_Selected_Component
(Loc
,
4399 Prefix
=> New_Reference_To
(DT
, Loc
),
4402 (RTE_Record_Component
(RE_NDT_Prims_Ptr
), Loc
)),
4403 Attribute_Name
=> Name_Address
))));
4405 -- Generate the SCIL node for the previous object declaration
4406 -- because it has a tag initialization.
4408 if Generate_SCIL
then
4410 Make_SCIL_Dispatch_Table_Tag_Init
(Sloc
(Last
(Result
)));
4411 Set_SCIL_Entity
(New_Node
, Typ
);
4412 Set_SCIL_Node
(Last
(Result
), New_Node
);
4416 -- DT : Dispatch_Table_Wrapper (Nb_Prim);
4417 -- for DT'Alignment use Address'Alignment;
4418 -- DT_Ptr : Tag := !Tag (DT.Prims_Ptr'Address);
4421 -- If the tagged type has no primitives we add a dummy slot
4422 -- whose address will be the tag of this type.
4426 New_List
(Make_Integer_Literal
(Loc
, 1));
4429 New_List
(Make_Integer_Literal
(Loc
, Nb_Prim
));
4433 Make_Object_Declaration
(Loc
,
4434 Defining_Identifier
=> DT
,
4435 Aliased_Present
=> True,
4436 Constant_Present
=> False,
4437 Object_Definition
=>
4438 Make_Subtype_Indication
(Loc
,
4440 New_Reference_To
(RTE
(RE_Dispatch_Table_Wrapper
), Loc
),
4441 Constraint
=> Make_Index_Or_Discriminant_Constraint
(Loc
,
4442 Constraints
=> DT_Constr_List
))));
4445 Make_Attribute_Definition_Clause
(Loc
,
4446 Name
=> New_Reference_To
(DT
, Loc
),
4447 Chars
=> Name_Alignment
,
4449 Make_Attribute_Reference
(Loc
,
4451 New_Reference_To
(RTE
(RE_Integer_Address
), Loc
),
4452 Attribute_Name
=> Name_Alignment
)));
4455 Make_Object_Declaration
(Loc
,
4456 Defining_Identifier
=> DT_Ptr
,
4457 Object_Definition
=> New_Reference_To
(RTE
(RE_Tag
), Loc
),
4458 Constant_Present
=> True,
4460 Unchecked_Convert_To
(RTE
(RE_Tag
),
4461 Make_Attribute_Reference
(Loc
,
4463 Make_Selected_Component
(Loc
,
4464 Prefix
=> New_Reference_To
(DT
, Loc
),
4467 (RTE_Record_Component
(RE_Prims_Ptr
), Loc
)),
4468 Attribute_Name
=> Name_Address
))));
4470 -- Generate the SCIL node for the previous object declaration
4471 -- because it has a tag initialization.
4473 if Generate_SCIL
then
4475 Make_SCIL_Dispatch_Table_Tag_Init
(Sloc
(Last
(Result
)));
4476 Set_SCIL_Entity
(New_Node
, Typ
);
4477 Set_SCIL_Node
(Last
(Result
), New_Node
);
4481 Make_Object_Declaration
(Loc
,
4482 Defining_Identifier
=>
4483 Node
(Next_Elmt
(First_Elmt
(Access_Disp_Table
(Typ
)))),
4484 Constant_Present
=> True,
4485 Object_Definition
=> New_Reference_To
4486 (RTE
(RE_Address
), Loc
),
4488 Make_Attribute_Reference
(Loc
,
4490 Make_Selected_Component
(Loc
,
4491 Prefix
=> New_Reference_To
(DT
, Loc
),
4494 (RTE_Record_Component
(RE_Predef_Prims
), Loc
)),
4495 Attribute_Name
=> Name_Address
)));
4499 -- Generate: Exname : constant String := full_qualified_name (typ);
4500 -- The type itself may be an anonymous parent type, so use the first
4501 -- subtype to have a user-recognizable name.
4504 Make_Object_Declaration
(Loc
,
4505 Defining_Identifier
=> Exname
,
4506 Constant_Present
=> True,
4507 Object_Definition
=> New_Reference_To
(Standard_String
, Loc
),
4509 Make_String_Literal
(Loc
,
4510 Full_Qualified_Name
(First_Subtype
(Typ
)))));
4512 Set_Is_Statically_Allocated
(Exname
);
4513 Set_Is_True_Constant
(Exname
);
4515 -- Declare the object used by Ada.Tags.Register_Tag
4517 if RTE_Available
(RE_Register_Tag
) then
4519 Make_Object_Declaration
(Loc
,
4520 Defining_Identifier
=> HT_Link
,
4521 Object_Definition
=> New_Reference_To
(RTE
(RE_Tag
), Loc
)));
4524 -- Generate code to create the storage for the type specific data object
4525 -- with enough space to store the tags of the ancestors plus the tags
4526 -- of all the implemented interfaces (as described in a-tags.adb).
4528 -- TSD : Type_Specific_Data (I_Depth) :=
4529 -- (Idepth => I_Depth,
4530 -- Access_Level => Type_Access_Level (Typ),
4531 -- Expanded_Name => Cstring_Ptr!(Exname'Address))
4532 -- External_Tag => Cstring_Ptr!(Exname'Address))
4533 -- HT_Link => HT_Link'Address,
4534 -- Transportable => <<boolean-value>>,
4535 -- RC_Offset => <<integer-value>>,
4536 -- [ Size_Func => Size_Prim'Access ]
4537 -- [ Interfaces_Table => <<access-value>> ]
4538 -- [ SSD => SSD_Table'Address ]
4539 -- Tags_Table => (0 => null,
4542 -- for TSD'Alignment use Address'Alignment
4544 TSD_Aggr_List
:= New_List
;
4546 -- Idepth: Count ancestors to compute the inheritance depth. For private
4547 -- extensions, always go to the full view in order to compute the real
4548 -- inheritance depth.
4551 Current_Typ
: Entity_Id
;
4552 Parent_Typ
: Entity_Id
;
4558 Parent_Typ
:= Etype
(Current_Typ
);
4560 if Is_Private_Type
(Parent_Typ
) then
4561 Parent_Typ
:= Full_View
(Base_Type
(Parent_Typ
));
4564 exit when Parent_Typ
= Current_Typ
;
4566 I_Depth
:= I_Depth
+ 1;
4567 Current_Typ
:= Parent_Typ
;
4571 Append_To
(TSD_Aggr_List
,
4572 Make_Integer_Literal
(Loc
, I_Depth
));
4576 Append_To
(TSD_Aggr_List
,
4577 Make_Integer_Literal
(Loc
, Type_Access_Level
(Typ
)));
4581 Append_To
(TSD_Aggr_List
,
4582 Unchecked_Convert_To
(RTE
(RE_Cstring_Ptr
),
4583 Make_Attribute_Reference
(Loc
,
4584 Prefix
=> New_Reference_To
(Exname
, Loc
),
4585 Attribute_Name
=> Name_Address
)));
4587 -- External_Tag of a local tagged type
4589 -- <typ>A : constant String :=
4590 -- "Internal tag at 16#tag-addr#: <full-name-of-typ>";
4592 -- The reason we generate this strange name is that we do not want to
4593 -- enter local tagged types in the global hash table used to compute
4594 -- the Internal_Tag attribute for two reasons:
4596 -- 1. It is hard to avoid a tasking race condition for entering the
4597 -- entry into the hash table.
4599 -- 2. It would cause a storage leak, unless we rig up considerable
4600 -- mechanism to remove the entry from the hash table on exit.
4602 -- So what we do is to generate the above external tag name, where the
4603 -- hex address is the address of the local dispatch table (i.e. exactly
4604 -- the value we want if Internal_Tag is computed from this string).
4606 -- Of course this value will only be valid if the tagged type is still
4607 -- in scope, but it clearly must be erroneous to compute the internal
4608 -- tag of a tagged type that is out of scope!
4610 -- We don't do this processing if an explicit external tag has been
4611 -- specified. That's an odd case for which we have already issued a
4612 -- warning, where we will not be able to compute the internal tag.
4614 if not Is_Library_Level_Entity
(Typ
)
4615 and then not Has_External_Tag_Rep_Clause
(Typ
)
4618 Exname
: constant Entity_Id
:=
4619 Make_Defining_Identifier
(Loc
,
4620 New_External_Name
(Tname
, 'A'));
4622 Full_Name
: constant String_Id
:=
4623 Full_Qualified_Name
(First_Subtype
(Typ
));
4624 Str1_Id
: String_Id
;
4625 Str2_Id
: String_Id
;
4629 -- Str1 = "Internal tag at 16#";
4632 Store_String_Chars
("Internal tag at 16#");
4633 Str1_Id
:= End_String
;
4636 -- Str2 = "#: <type-full-name>";
4639 Store_String_Chars
("#: ");
4640 Store_String_Chars
(Full_Name
);
4641 Str2_Id
:= End_String
;
4644 -- Exname : constant String :=
4645 -- Str1 & Address_Image (Tag) & Str2;
4647 if RTE_Available
(RE_Address_Image
) then
4649 Make_Object_Declaration
(Loc
,
4650 Defining_Identifier
=> Exname
,
4651 Constant_Present
=> True,
4652 Object_Definition
=> New_Reference_To
4653 (Standard_String
, Loc
),
4655 Make_Op_Concat
(Loc
,
4657 Make_String_Literal
(Loc
, Str1_Id
),
4659 Make_Op_Concat
(Loc
,
4661 Make_Function_Call
(Loc
,
4664 (RTE
(RE_Address_Image
), Loc
),
4665 Parameter_Associations
=> New_List
(
4666 Unchecked_Convert_To
(RTE
(RE_Address
),
4667 New_Reference_To
(DT_Ptr
, Loc
)))),
4669 Make_String_Literal
(Loc
, Str2_Id
)))));
4673 Make_Object_Declaration
(Loc
,
4674 Defining_Identifier
=> Exname
,
4675 Constant_Present
=> True,
4676 Object_Definition
=> New_Reference_To
4677 (Standard_String
, Loc
),
4679 Make_Op_Concat
(Loc
,
4681 Make_String_Literal
(Loc
, Str1_Id
),
4683 Make_String_Literal
(Loc
, Str2_Id
))));
4687 Unchecked_Convert_To
(RTE
(RE_Cstring_Ptr
),
4688 Make_Attribute_Reference
(Loc
,
4689 Prefix
=> New_Reference_To
(Exname
, Loc
),
4690 Attribute_Name
=> Name_Address
));
4693 -- External tag of a library-level tagged type: Check for a definition
4694 -- of External_Tag. The clause is considered only if it applies to this
4695 -- specific tagged type, as opposed to one of its ancestors.
4696 -- If the type is an unconstrained type extension, we are building the
4697 -- dispatch table of its anonymous base type, so the external tag, if
4698 -- any was specified, must be retrieved from the first subtype. Go to
4699 -- the full view in case the clause is in the private part.
4703 Def
: constant Node_Id
:= Get_Attribute_Definition_Clause
4704 (Underlying_Type
(First_Subtype
(Typ
)),
4705 Attribute_External_Tag
);
4707 Old_Val
: String_Id
;
4708 New_Val
: String_Id
;
4712 if not Present
(Def
)
4713 or else Entity
(Name
(Def
)) /= First_Subtype
(Typ
)
4716 Unchecked_Convert_To
(RTE
(RE_Cstring_Ptr
),
4717 Make_Attribute_Reference
(Loc
,
4718 Prefix
=> New_Reference_To
(Exname
, Loc
),
4719 Attribute_Name
=> Name_Address
));
4721 Old_Val
:= Strval
(Expr_Value_S
(Expression
(Def
)));
4723 -- For the rep clause "for <typ>'external_tag use y" generate:
4725 -- <typ>A : constant string := y;
4727 -- <typ>A'Address is used to set the External_Tag component
4730 -- Create a new nul terminated string if it is not already
4732 if String_Length
(Old_Val
) > 0
4734 Get_String_Char
(Old_Val
, String_Length
(Old_Val
)) = 0
4738 Start_String
(Old_Val
);
4739 Store_String_Char
(Get_Char_Code
(ASCII
.NUL
));
4740 New_Val
:= End_String
;
4743 E
:= Make_Defining_Identifier
(Loc
,
4744 New_External_Name
(Chars
(Typ
), 'A'));
4747 Make_Object_Declaration
(Loc
,
4748 Defining_Identifier
=> E
,
4749 Constant_Present
=> True,
4750 Object_Definition
=>
4751 New_Reference_To
(Standard_String
, Loc
),
4753 Make_String_Literal
(Loc
, New_Val
)));
4756 Unchecked_Convert_To
(RTE
(RE_Cstring_Ptr
),
4757 Make_Attribute_Reference
(Loc
,
4758 Prefix
=> New_Reference_To
(E
, Loc
),
4759 Attribute_Name
=> Name_Address
));
4764 Append_To
(TSD_Aggr_List
, New_Node
);
4768 if RTE_Available
(RE_Register_Tag
) then
4769 Append_To
(TSD_Aggr_List
,
4770 Unchecked_Convert_To
(RTE
(RE_Tag_Ptr
),
4771 Make_Attribute_Reference
(Loc
,
4772 Prefix
=> New_Reference_To
(HT_Link
, Loc
),
4773 Attribute_Name
=> Name_Address
)));
4775 Append_To
(TSD_Aggr_List
,
4776 Unchecked_Convert_To
(RTE
(RE_Tag_Ptr
),
4777 New_Reference_To
(RTE
(RE_Null_Address
), Loc
)));
4780 -- Transportable: Set for types that can be used in remote calls
4781 -- with respect to E.4(18) legality rules.
4784 Transportable
: Entity_Id
;
4790 or else Is_Shared_Passive
(Typ
)
4792 ((Is_Remote_Types
(Typ
)
4793 or else Is_Remote_Call_Interface
(Typ
))
4794 and then Original_View_In_Visible_Part
(Typ
))
4795 or else not Comes_From_Source
(Typ
));
4797 Append_To
(TSD_Aggr_List
,
4798 New_Occurrence_Of
(Transportable
, Loc
));
4801 -- RC_Offset: These are the valid values and their meaning:
4803 -- >0: For simple types with controlled components is
4804 -- type._record_controller'position
4806 -- 0: For types with no controlled components
4808 -- -1: For complex types with controlled components where the position
4809 -- of the record controller is not statically computable but there
4810 -- are controlled components at this level. The _Controller field
4811 -- is available right after the _parent.
4813 -- -2: There are no controlled components at this level. We need to
4814 -- get the position from the parent.
4817 RC_Offset_Node
: Node_Id
;
4820 if not Has_Controlled_Component
(Typ
) then
4821 RC_Offset_Node
:= Make_Integer_Literal
(Loc
, 0);
4823 elsif Etype
(Typ
) /= Typ
4824 and then Has_Discriminants
(Parent_Typ
)
4826 if Has_New_Controlled_Component
(Typ
) then
4827 RC_Offset_Node
:= Make_Integer_Literal
(Loc
, -1);
4829 RC_Offset_Node
:= Make_Integer_Literal
(Loc
, -2);
4833 Make_Attribute_Reference
(Loc
,
4835 Make_Selected_Component
(Loc
,
4836 Prefix
=> New_Reference_To
(Typ
, Loc
),
4838 New_Reference_To
(Controller_Component
(Typ
), Loc
)),
4839 Attribute_Name
=> Name_Position
);
4841 -- This is not proper Ada code to use the attribute 'Position
4842 -- on something else than an object but this is supported by
4843 -- the back end (see comment on the Bit_Component attribute in
4844 -- sem_attr). So we avoid semantic checking here.
4846 -- Is this documented in sinfo.ads??? it should be!
4848 Set_Analyzed
(RC_Offset_Node
);
4849 Set_Etype
(Prefix
(RC_Offset_Node
), RTE
(RE_Record_Controller
));
4850 Set_Etype
(Prefix
(Prefix
(RC_Offset_Node
)), Typ
);
4851 Set_Etype
(Selector_Name
(Prefix
(RC_Offset_Node
)),
4852 RTE
(RE_Record_Controller
));
4853 Set_Etype
(RC_Offset_Node
, RTE
(RE_Storage_Offset
));
4856 Append_To
(TSD_Aggr_List
, RC_Offset_Node
);
4861 if RTE_Record_Component_Available
(RE_Size_Func
) then
4863 -- Initialize this field to Null_Address if we are not building
4864 -- static dispatch tables static or if the size function is not
4865 -- available. In the former case we cannot initialize this field
4866 -- until the function is frozen and registered in the dispatch
4867 -- table (see Register_Primitive).
4869 if not Building_Static_DT
(Typ
) or else not Has_DT
(Typ
) then
4870 Append_To
(TSD_Aggr_List
,
4871 Unchecked_Convert_To
(RTE
(RE_Size_Ptr
),
4872 New_Reference_To
(RTE
(RE_Null_Address
), Loc
)));
4876 Prim_Elmt
: Elmt_Id
;
4880 Prim_Elmt
:= First_Elmt
(Primitive_Operations
(Typ
));
4881 while Present
(Prim_Elmt
) loop
4882 Prim
:= Node
(Prim_Elmt
);
4884 if Chars
(Prim
) = Name_uSize
then
4885 Prim
:= Ultimate_Alias
(Prim
);
4887 if Is_Abstract_Subprogram
(Prim
) then
4888 Append_To
(TSD_Aggr_List
,
4889 Unchecked_Convert_To
(RTE
(RE_Size_Ptr
),
4890 New_Reference_To
(RTE
(RE_Null_Address
), Loc
)));
4892 Append_To
(TSD_Aggr_List
,
4893 Unchecked_Convert_To
(RTE
(RE_Size_Ptr
),
4894 Make_Attribute_Reference
(Loc
,
4895 Prefix
=> New_Reference_To
(Prim
, Loc
),
4896 Attribute_Name
=> Name_Unrestricted_Access
)));
4902 Next_Elmt
(Prim_Elmt
);
4908 -- Interfaces_Table (required for AI-405)
4910 if RTE_Record_Component_Available
(RE_Interfaces_Table
) then
4912 -- Count the number of interface types implemented by Typ
4914 Collect_Interfaces
(Typ
, Typ_Ifaces
);
4916 AI
:= First_Elmt
(Typ_Ifaces
);
4917 while Present
(AI
) loop
4918 Num_Ifaces
:= Num_Ifaces
+ 1;
4922 if Num_Ifaces
= 0 then
4923 Iface_Table_Node
:= Make_Null
(Loc
);
4925 -- Generate the Interface_Table object
4929 TSD_Ifaces_List
: constant List_Id
:= New_List
;
4931 Sec_DT_Tag
: Node_Id
;
4934 AI
:= First_Elmt
(Typ_Ifaces
);
4935 while Present
(AI
) loop
4936 if Is_Ancestor
(Node
(AI
), Typ
) then
4938 New_Reference_To
(DT_Ptr
, Loc
);
4942 (Next_Elmt
(First_Elmt
(Access_Disp_Table
(Typ
))));
4943 pragma Assert
(Has_Thunks
(Node
(Elmt
)));
4945 while Ekind
(Node
(Elmt
)) = E_Constant
4947 Is_Ancestor
(Node
(AI
), Related_Type
(Node
(Elmt
)))
4949 pragma Assert
(Has_Thunks
(Node
(Elmt
)));
4951 pragma Assert
(Has_Thunks
(Node
(Elmt
)));
4953 pragma Assert
(not Has_Thunks
(Node
(Elmt
)));
4955 pragma Assert
(not Has_Thunks
(Node
(Elmt
)));
4959 pragma Assert
(Ekind
(Node
(Elmt
)) = E_Constant
4961 Has_Thunks
(Node
(Next_Elmt
(Next_Elmt
(Elmt
)))));
4963 New_Reference_To
(Node
(Next_Elmt
(Next_Elmt
(Elmt
))),
4967 Append_To
(TSD_Ifaces_List
,
4968 Make_Aggregate
(Loc
,
4969 Expressions
=> New_List
(
4973 Unchecked_Convert_To
(RTE
(RE_Tag
),
4975 (Node
(First_Elmt
(Access_Disp_Table
(Node
(AI
)))),
4978 -- Static_Offset_To_Top
4980 New_Reference_To
(Standard_True
, Loc
),
4982 -- Offset_To_Top_Value
4984 Make_Integer_Literal
(Loc
, 0),
4986 -- Offset_To_Top_Func
4992 Unchecked_Convert_To
(RTE
(RE_Tag
), Sec_DT_Tag
)
4999 Name_ITable
:= New_External_Name
(Tname
, 'I');
5000 ITable
:= Make_Defining_Identifier
(Loc
, Name_ITable
);
5001 Set_Is_Statically_Allocated
(ITable
,
5002 Is_Library_Level_Tagged_Type
(Typ
));
5004 -- The table of interfaces is not constant; its slots are
5005 -- filled at run-time by the IP routine using attribute
5006 -- 'Position to know the location of the tag components
5007 -- (and this attribute cannot be safely used before the
5008 -- object is initialized).
5011 Make_Object_Declaration
(Loc
,
5012 Defining_Identifier
=> ITable
,
5013 Aliased_Present
=> True,
5014 Constant_Present
=> False,
5015 Object_Definition
=>
5016 Make_Subtype_Indication
(Loc
,
5018 New_Reference_To
(RTE
(RE_Interface_Data
), Loc
),
5019 Constraint
=> Make_Index_Or_Discriminant_Constraint
5021 Constraints
=> New_List
(
5022 Make_Integer_Literal
(Loc
, Num_Ifaces
)))),
5024 Expression
=> Make_Aggregate
(Loc
,
5025 Expressions
=> New_List
(
5026 Make_Integer_Literal
(Loc
, Num_Ifaces
),
5027 Make_Aggregate
(Loc
,
5028 Expressions
=> TSD_Ifaces_List
)))));
5031 Make_Attribute_Definition_Clause
(Loc
,
5032 Name
=> New_Reference_To
(ITable
, Loc
),
5033 Chars
=> Name_Alignment
,
5035 Make_Attribute_Reference
(Loc
,
5037 New_Reference_To
(RTE
(RE_Integer_Address
), Loc
),
5038 Attribute_Name
=> Name_Alignment
)));
5041 Make_Attribute_Reference
(Loc
,
5042 Prefix
=> New_Reference_To
(ITable
, Loc
),
5043 Attribute_Name
=> Name_Unchecked_Access
);
5047 Append_To
(TSD_Aggr_List
, Iface_Table_Node
);
5050 -- Generate the Select Specific Data table for synchronized types that
5051 -- implement synchronized interfaces. The size of the table is
5052 -- constrained by the number of non-predefined primitive operations.
5054 if RTE_Record_Component_Available
(RE_SSD
) then
5055 if Ada_Version
>= Ada_05
5056 and then Has_DT
(Typ
)
5057 and then Is_Concurrent_Record_Type
(Typ
)
5058 and then Has_Interfaces
(Typ
)
5059 and then Nb_Prim
> 0
5060 and then not Is_Abstract_Type
(Typ
)
5061 and then not Is_Controlled
(Typ
)
5062 and then not Restriction_Active
(No_Dispatching_Calls
)
5063 and then not Restriction_Active
(No_Select_Statements
)
5066 Make_Object_Declaration
(Loc
,
5067 Defining_Identifier
=> SSD
,
5068 Aliased_Present
=> True,
5069 Object_Definition
=>
5070 Make_Subtype_Indication
(Loc
,
5071 Subtype_Mark
=> New_Reference_To
(
5072 RTE
(RE_Select_Specific_Data
), Loc
),
5074 Make_Index_Or_Discriminant_Constraint
(Loc
,
5075 Constraints
=> New_List
(
5076 Make_Integer_Literal
(Loc
, Nb_Prim
))))));
5079 Make_Attribute_Definition_Clause
(Loc
,
5080 Name
=> New_Reference_To
(SSD
, Loc
),
5081 Chars
=> Name_Alignment
,
5083 Make_Attribute_Reference
(Loc
,
5085 New_Reference_To
(RTE
(RE_Integer_Address
), Loc
),
5086 Attribute_Name
=> Name_Alignment
)));
5088 -- This table is initialized by Make_Select_Specific_Data_Table,
5089 -- which calls Set_Entry_Index and Set_Prim_Op_Kind.
5091 Append_To
(TSD_Aggr_List
,
5092 Make_Attribute_Reference
(Loc
,
5093 Prefix
=> New_Reference_To
(SSD
, Loc
),
5094 Attribute_Name
=> Name_Unchecked_Access
));
5096 Append_To
(TSD_Aggr_List
, Make_Null
(Loc
));
5100 -- Initialize the table of ancestor tags. In case of interface types
5101 -- this table is not needed.
5103 TSD_Tags_List
:= New_List
;
5105 -- If we are not statically allocating the dispatch table then we must
5106 -- fill position 0 with null because we still have not generated the
5109 if not Building_Static_DT
(Typ
)
5110 or else Is_Interface
(Typ
)
5112 Append_To
(TSD_Tags_List
,
5113 Unchecked_Convert_To
(RTE
(RE_Tag
),
5114 New_Reference_To
(RTE
(RE_Null_Address
), Loc
)));
5116 -- Otherwise we can safely reference the tag
5119 Append_To
(TSD_Tags_List
,
5120 New_Reference_To
(DT_Ptr
, Loc
));
5123 -- Fill the rest of the table with the tags of the ancestors
5126 Current_Typ
: Entity_Id
;
5127 Parent_Typ
: Entity_Id
;
5135 Parent_Typ
:= Etype
(Current_Typ
);
5137 if Is_Private_Type
(Parent_Typ
) then
5138 Parent_Typ
:= Full_View
(Base_Type
(Parent_Typ
));
5141 exit when Parent_Typ
= Current_Typ
;
5143 if Is_CPP_Class
(Parent_Typ
) then
5145 -- The tags defined in the C++ side will be inherited when
5146 -- the object is constructed (Exp_Ch3.Build_Init_Procedure)
5148 Append_To
(TSD_Tags_List
,
5149 Unchecked_Convert_To
(RTE
(RE_Tag
),
5150 New_Reference_To
(RTE
(RE_Null_Address
), Loc
)));
5152 Append_To
(TSD_Tags_List
,
5154 (Node
(First_Elmt
(Access_Disp_Table
(Parent_Typ
))),
5159 Current_Typ
:= Parent_Typ
;
5162 pragma Assert
(Pos
= I_Depth
+ 1);
5165 Append_To
(TSD_Aggr_List
,
5166 Make_Aggregate
(Loc
,
5167 Expressions
=> TSD_Tags_List
));
5169 -- Build the TSD object
5172 Make_Object_Declaration
(Loc
,
5173 Defining_Identifier
=> TSD
,
5174 Aliased_Present
=> True,
5175 Constant_Present
=> Building_Static_DT
(Typ
),
5176 Object_Definition
=>
5177 Make_Subtype_Indication
(Loc
,
5178 Subtype_Mark
=> New_Reference_To
(
5179 RTE
(RE_Type_Specific_Data
), Loc
),
5181 Make_Index_Or_Discriminant_Constraint
(Loc
,
5182 Constraints
=> New_List
(
5183 Make_Integer_Literal
(Loc
, I_Depth
)))),
5185 Expression
=> Make_Aggregate
(Loc
,
5186 Expressions
=> TSD_Aggr_List
)));
5188 Set_Is_True_Constant
(TSD
, Building_Static_DT
(Typ
));
5191 Make_Attribute_Definition_Clause
(Loc
,
5192 Name
=> New_Reference_To
(TSD
, Loc
),
5193 Chars
=> Name_Alignment
,
5195 Make_Attribute_Reference
(Loc
,
5196 Prefix
=> New_Reference_To
(RTE
(RE_Integer_Address
), Loc
),
5197 Attribute_Name
=> Name_Alignment
)));
5199 -- Initialize or declare the dispatch table object
5201 if not Has_DT
(Typ
) then
5202 DT_Constr_List
:= New_List
;
5203 DT_Aggr_List
:= New_List
;
5208 Make_Attribute_Reference
(Loc
,
5209 Prefix
=> New_Reference_To
(TSD
, Loc
),
5210 Attribute_Name
=> Name_Address
);
5212 Append_To
(DT_Constr_List
, New_Node
);
5213 Append_To
(DT_Aggr_List
, New_Copy
(New_Node
));
5214 Append_To
(DT_Aggr_List
, Make_Integer_Literal
(Loc
, 0));
5216 -- In case of locally defined tagged types we have already declared
5217 -- and uninitialized object for the dispatch table, which is now
5218 -- initialized by means of the following assignment:
5220 -- DT := (TSD'Address, 0);
5222 if not Building_Static_DT
(Typ
) then
5224 Make_Assignment_Statement
(Loc
,
5225 Name
=> New_Reference_To
(DT
, Loc
),
5226 Expression
=> Make_Aggregate
(Loc
,
5227 Expressions
=> DT_Aggr_List
)));
5229 -- In case of library level tagged types we declare and export now
5230 -- the constant object containing the dummy dispatch table. There
5231 -- is no need to declare the tag here because it has been previously
5232 -- declared by Make_Tags
5234 -- DT : aliased constant No_Dispatch_Table :=
5235 -- (NDT_TSD => TSD'Address;
5236 -- NDT_Prims_Ptr => 0);
5237 -- for DT'Alignment use Address'Alignment;
5241 Make_Object_Declaration
(Loc
,
5242 Defining_Identifier
=> DT
,
5243 Aliased_Present
=> True,
5244 Constant_Present
=> True,
5245 Object_Definition
=>
5246 New_Reference_To
(RTE
(RE_No_Dispatch_Table_Wrapper
), Loc
),
5247 Expression
=> Make_Aggregate
(Loc
,
5248 Expressions
=> DT_Aggr_List
)));
5251 Make_Attribute_Definition_Clause
(Loc
,
5252 Name
=> New_Reference_To
(DT
, Loc
),
5253 Chars
=> Name_Alignment
,
5255 Make_Attribute_Reference
(Loc
,
5257 New_Reference_To
(RTE
(RE_Integer_Address
), Loc
),
5258 Attribute_Name
=> Name_Alignment
)));
5260 Export_DT
(Typ
, DT
);
5263 -- Common case: Typ has a dispatch table
5267 -- Predef_Prims : Address_Array (1 .. Default_Prim_Ops_Count) :=
5268 -- (predef-prim-op-1'address,
5269 -- predef-prim-op-2'address,
5271 -- predef-prim-op-n'address);
5272 -- for Predef_Prims'Alignment use Address'Alignment
5274 -- DT : Dispatch_Table (Nb_Prims) :=
5275 -- (Signature => <sig-value>,
5276 -- Tag_Kind => <tag_kind-value>,
5277 -- Predef_Prims => Predef_Prims'First'Address,
5278 -- Offset_To_Top => 0,
5279 -- TSD => TSD'Address;
5280 -- Prims_Ptr => (prim-op-1'address,
5281 -- prim-op-2'address,
5283 -- prim-op-n'address));
5284 -- for DT'Alignment use Address'Alignment
5291 if not Building_Static_DT
(Typ
) then
5292 Nb_Predef_Prims
:= Max_Predef_Prims
;
5295 Prim_Elmt
:= First_Elmt
(Primitive_Operations
(Typ
));
5296 while Present
(Prim_Elmt
) loop
5297 Prim
:= Node
(Prim_Elmt
);
5299 if Is_Predefined_Dispatching_Operation
(Prim
)
5300 and then not Is_Abstract_Subprogram
(Prim
)
5302 Pos
:= UI_To_Int
(DT_Position
(Prim
));
5304 if Pos
> Nb_Predef_Prims
then
5305 Nb_Predef_Prims
:= Pos
;
5309 Next_Elmt
(Prim_Elmt
);
5315 (Nat
range 1 .. Nb_Predef_Prims
) of Entity_Id
;
5320 Prim_Ops_Aggr_List
:= New_List
;
5322 Prim_Table
:= (others => Empty
);
5324 if Building_Static_DT
(Typ
) then
5325 Prim_Elmt
:= First_Elmt
(Primitive_Operations
(Typ
));
5326 while Present
(Prim_Elmt
) loop
5327 Prim
:= Node
(Prim_Elmt
);
5329 if Is_Predefined_Dispatching_Operation
(Prim
)
5330 and then not Is_Abstract_Subprogram
(Prim
)
5331 and then not Is_Eliminated
(Prim
)
5332 and then not Present
(Prim_Table
5333 (UI_To_Int
(DT_Position
(Prim
))))
5335 E
:= Ultimate_Alias
(Prim
);
5336 pragma Assert
(not Is_Abstract_Subprogram
(E
));
5337 Prim_Table
(UI_To_Int
(DT_Position
(Prim
))) := E
;
5340 Next_Elmt
(Prim_Elmt
);
5344 for J
in Prim_Table
'Range loop
5345 if Present
(Prim_Table
(J
)) then
5347 Unchecked_Convert_To
(RTE
(RE_Prim_Ptr
),
5348 Make_Attribute_Reference
(Loc
,
5349 Prefix
=> New_Reference_To
(Prim_Table
(J
), Loc
),
5350 Attribute_Name
=> Name_Unrestricted_Access
));
5352 New_Node
:= Make_Null
(Loc
);
5355 Append_To
(Prim_Ops_Aggr_List
, New_Node
);
5359 Make_Aggregate
(Loc
,
5360 Expressions
=> Prim_Ops_Aggr_List
);
5363 Make_Subtype_Declaration
(Loc
,
5364 Defining_Identifier
=> Make_Temporary
(Loc
, 'S'),
5365 Subtype_Indication
=>
5366 New_Reference_To
(RTE
(RE_Address_Array
), Loc
));
5368 Append_To
(Result
, Decl
);
5371 Make_Object_Declaration
(Loc
,
5372 Defining_Identifier
=> Predef_Prims
,
5373 Aliased_Present
=> True,
5374 Constant_Present
=> Building_Static_DT
(Typ
),
5375 Object_Definition
=> New_Reference_To
5376 (Defining_Identifier
(Decl
), Loc
),
5377 Expression
=> New_Node
));
5379 -- Remember aggregates initializing dispatch tables
5381 Append_Elmt
(New_Node
, DT_Aggr
);
5384 Make_Attribute_Definition_Clause
(Loc
,
5385 Name
=> New_Reference_To
(Predef_Prims
, Loc
),
5386 Chars
=> Name_Alignment
,
5388 Make_Attribute_Reference
(Loc
,
5390 New_Reference_To
(RTE
(RE_Integer_Address
), Loc
),
5391 Attribute_Name
=> Name_Alignment
)));
5395 -- Stage 1: Initialize the discriminant and the record components
5397 DT_Constr_List
:= New_List
;
5398 DT_Aggr_List
:= New_List
;
5400 -- Num_Prims. If the tagged type has no primitives we add a dummy
5401 -- slot whose address will be the tag of this type.
5404 New_Node
:= Make_Integer_Literal
(Loc
, 1);
5406 New_Node
:= Make_Integer_Literal
(Loc
, Nb_Prim
);
5409 Append_To
(DT_Constr_List
, New_Node
);
5410 Append_To
(DT_Aggr_List
, New_Copy
(New_Node
));
5414 if RTE_Record_Component_Available
(RE_Signature
) then
5415 Append_To
(DT_Aggr_List
,
5416 New_Reference_To
(RTE
(RE_Primary_DT
), Loc
));
5421 if RTE_Record_Component_Available
(RE_Tag_Kind
) then
5422 Append_To
(DT_Aggr_List
, Tagged_Kind
(Typ
));
5427 Append_To
(DT_Aggr_List
,
5428 Make_Attribute_Reference
(Loc
,
5429 Prefix
=> New_Reference_To
(Predef_Prims
, Loc
),
5430 Attribute_Name
=> Name_Address
));
5434 Append_To
(DT_Aggr_List
, Make_Integer_Literal
(Loc
, 0));
5438 Append_To
(DT_Aggr_List
,
5439 Make_Attribute_Reference
(Loc
,
5440 Prefix
=> New_Reference_To
(TSD
, Loc
),
5441 Attribute_Name
=> Name_Address
));
5443 -- Stage 2: Initialize the table of primitive operations
5445 Prim_Ops_Aggr_List
:= New_List
;
5448 Append_To
(Prim_Ops_Aggr_List
, Make_Null
(Loc
));
5450 elsif not Building_Static_DT
(Typ
) then
5451 for J
in 1 .. Nb_Prim
loop
5452 Append_To
(Prim_Ops_Aggr_List
, Make_Null
(Loc
));
5457 Prim_Table
: array (Nat
range 1 .. Nb_Prim
) of Entity_Id
;
5460 Prim_Elmt
: Elmt_Id
;
5463 Prim_Table
:= (others => Empty
);
5465 Prim_Elmt
:= First_Elmt
(Primitive_Operations
(Typ
));
5466 while Present
(Prim_Elmt
) loop
5467 Prim
:= Node
(Prim_Elmt
);
5469 -- Retrieve the ultimate alias of the primitive for proper
5470 -- handling of renamings and eliminated primitives.
5472 E
:= Ultimate_Alias
(Prim
);
5474 -- Do not reference predefined primitives because they are
5475 -- located in a separate dispatch table; skip entities with
5476 -- attribute Interface_Alias because they are only required
5477 -- to build secondary dispatch tables; skip also abstract
5478 -- and eliminated primitives.
5480 if not Is_Predefined_Dispatching_Operation
(Prim
)
5481 and then not Is_Predefined_Dispatching_Operation
(E
)
5482 and then not Present
(Interface_Alias
(Prim
))
5483 and then not Is_Abstract_Subprogram
(E
)
5484 and then not Is_Eliminated
(E
)
5487 (UI_To_Int
(DT_Position
(Prim
)) <= Nb_Prim
);
5489 Prim_Table
(UI_To_Int
(DT_Position
(Prim
))) := E
;
5492 Next_Elmt
(Prim_Elmt
);
5495 for J
in Prim_Table
'Range loop
5496 if Present
(Prim_Table
(J
)) then
5498 Unchecked_Convert_To
(RTE
(RE_Prim_Ptr
),
5499 Make_Attribute_Reference
(Loc
,
5500 Prefix
=> New_Reference_To
(Prim_Table
(J
), Loc
),
5501 Attribute_Name
=> Name_Unrestricted_Access
));
5503 New_Node
:= Make_Null
(Loc
);
5506 Append_To
(Prim_Ops_Aggr_List
, New_Node
);
5512 Make_Aggregate
(Loc
,
5513 Expressions
=> Prim_Ops_Aggr_List
);
5515 Append_To
(DT_Aggr_List
, New_Node
);
5517 -- Remember aggregates initializing dispatch tables
5519 Append_Elmt
(New_Node
, DT_Aggr
);
5521 -- In case of locally defined tagged types we have already declared
5522 -- and uninitialized object for the dispatch table, which is now
5523 -- initialized by means of an assignment.
5525 if not Building_Static_DT
(Typ
) then
5527 Make_Assignment_Statement
(Loc
,
5528 Name
=> New_Reference_To
(DT
, Loc
),
5529 Expression
=> Make_Aggregate
(Loc
,
5530 Expressions
=> DT_Aggr_List
)));
5532 -- In case of library level tagged types we declare now and export
5533 -- the constant object containing the dispatch table.
5537 Make_Object_Declaration
(Loc
,
5538 Defining_Identifier
=> DT
,
5539 Aliased_Present
=> True,
5540 Constant_Present
=> True,
5541 Object_Definition
=>
5542 Make_Subtype_Indication
(Loc
,
5543 Subtype_Mark
=> New_Reference_To
5544 (RTE
(RE_Dispatch_Table_Wrapper
), Loc
),
5545 Constraint
=> Make_Index_Or_Discriminant_Constraint
(Loc
,
5546 Constraints
=> DT_Constr_List
)),
5547 Expression
=> Make_Aggregate
(Loc
,
5548 Expressions
=> DT_Aggr_List
)));
5551 Make_Attribute_Definition_Clause
(Loc
,
5552 Name
=> New_Reference_To
(DT
, Loc
),
5553 Chars
=> Name_Alignment
,
5555 Make_Attribute_Reference
(Loc
,
5557 New_Reference_To
(RTE
(RE_Integer_Address
), Loc
),
5558 Attribute_Name
=> Name_Alignment
)));
5560 Export_DT
(Typ
, DT
);
5564 -- Initialize the table of ancestor tags if not building static
5567 if not Building_Static_DT
(Typ
)
5568 and then not Is_Interface
(Typ
)
5569 and then not Is_CPP_Class
(Typ
)
5572 Make_Assignment_Statement
(Loc
,
5574 Make_Indexed_Component
(Loc
,
5576 Make_Selected_Component
(Loc
,
5578 New_Reference_To
(TSD
, Loc
),
5581 (RTE_Record_Component
(RE_Tags_Table
), Loc
)),
5583 New_List
(Make_Integer_Literal
(Loc
, 0))),
5587 (Node
(First_Elmt
(Access_Disp_Table
(Typ
))), Loc
)));
5590 -- Inherit the dispatch tables of the parent. There is no need to
5591 -- inherit anything from the parent when building static dispatch tables
5592 -- because the whole dispatch table (including inherited primitives) has
5593 -- been already built.
5595 if Building_Static_DT
(Typ
) then
5598 -- If the ancestor is a CPP_Class type we inherit the dispatch tables
5599 -- in the init proc, and we don't need to fill them in here.
5601 elsif Is_CPP_Class
(Parent_Typ
) then
5604 -- Otherwise we fill in the dispatch tables here
5607 if Typ
/= Parent_Typ
5608 and then not Is_Interface
(Typ
)
5609 and then not Restriction_Active
(No_Dispatching_Calls
)
5611 -- Inherit the dispatch table
5613 if not Is_Interface
(Typ
)
5614 and then not Is_Interface
(Parent_Typ
)
5615 and then not Is_CPP_Class
(Parent_Typ
)
5618 Nb_Prims
: constant Int
:=
5619 UI_To_Int
(DT_Entry_Count
5620 (First_Tag_Component
(Parent_Typ
)));
5623 Append_To
(Elab_Code
,
5624 Build_Inherit_Predefined_Prims
(Loc
,
5630 (Access_Disp_Table
(Parent_Typ
)))), Loc
),
5636 (Access_Disp_Table
(Typ
)))), Loc
)));
5638 if Nb_Prims
/= 0 then
5639 Append_To
(Elab_Code
,
5640 Build_Inherit_Prims
(Loc
,
5646 (Access_Disp_Table
(Parent_Typ
))), Loc
),
5647 New_Tag_Node
=> New_Reference_To
(DT_Ptr
, Loc
),
5648 Num_Prims
=> Nb_Prims
));
5653 -- Inherit the secondary dispatch tables of the ancestor
5655 if not Is_CPP_Class
(Parent_Typ
) then
5657 Sec_DT_Ancestor
: Elmt_Id
:=
5661 (Access_Disp_Table
(Parent_Typ
))));
5662 Sec_DT_Typ
: Elmt_Id
:=
5666 (Access_Disp_Table
(Typ
))));
5668 procedure Copy_Secondary_DTs
(Typ
: Entity_Id
);
5669 -- Local procedure required to climb through the ancestors
5670 -- and copy the contents of all their secondary dispatch
5673 ------------------------
5674 -- Copy_Secondary_DTs --
5675 ------------------------
5677 procedure Copy_Secondary_DTs
(Typ
: Entity_Id
) is
5682 -- Climb to the ancestor (if any) handling private types
5684 if Present
(Full_View
(Etype
(Typ
))) then
5685 if Full_View
(Etype
(Typ
)) /= Typ
then
5686 Copy_Secondary_DTs
(Full_View
(Etype
(Typ
)));
5689 elsif Etype
(Typ
) /= Typ
then
5690 Copy_Secondary_DTs
(Etype
(Typ
));
5693 if Present
(Interfaces
(Typ
))
5694 and then not Is_Empty_Elmt_List
(Interfaces
(Typ
))
5696 Iface
:= First_Elmt
(Interfaces
(Typ
));
5697 E
:= First_Entity
(Typ
);
5699 and then Present
(Node
(Sec_DT_Ancestor
))
5700 and then Ekind
(Node
(Sec_DT_Ancestor
)) = E_Constant
5702 if Is_Tag
(E
) and then Chars
(E
) /= Name_uTag
then
5704 Num_Prims
: constant Int
:=
5705 UI_To_Int
(DT_Entry_Count
(E
));
5708 if not Is_Interface
(Etype
(Typ
)) then
5710 -- Inherit first secondary dispatch table
5712 Append_To
(Elab_Code
,
5713 Build_Inherit_Predefined_Prims
(Loc
,
5715 Unchecked_Convert_To
(RTE
(RE_Tag
),
5718 (Next_Elmt
(Sec_DT_Ancestor
)),
5721 Unchecked_Convert_To
(RTE
(RE_Tag
),
5723 (Node
(Next_Elmt
(Sec_DT_Typ
)),
5726 if Num_Prims
/= 0 then
5727 Append_To
(Elab_Code
,
5728 Build_Inherit_Prims
(Loc
,
5729 Typ
=> Node
(Iface
),
5731 Unchecked_Convert_To
5734 (Node
(Sec_DT_Ancestor
),
5737 Unchecked_Convert_To
5740 (Node
(Sec_DT_Typ
), Loc
)),
5741 Num_Prims
=> Num_Prims
));
5745 Next_Elmt
(Sec_DT_Ancestor
);
5746 Next_Elmt
(Sec_DT_Typ
);
5748 -- Skip the secondary dispatch table of
5749 -- predefined primitives
5751 Next_Elmt
(Sec_DT_Ancestor
);
5752 Next_Elmt
(Sec_DT_Typ
);
5754 if not Is_Interface
(Etype
(Typ
)) then
5756 -- Inherit second secondary dispatch table
5758 Append_To
(Elab_Code
,
5759 Build_Inherit_Predefined_Prims
(Loc
,
5761 Unchecked_Convert_To
(RTE
(RE_Tag
),
5764 (Next_Elmt
(Sec_DT_Ancestor
)),
5767 Unchecked_Convert_To
(RTE
(RE_Tag
),
5769 (Node
(Next_Elmt
(Sec_DT_Typ
)),
5772 if Num_Prims
/= 0 then
5773 Append_To
(Elab_Code
,
5774 Build_Inherit_Prims
(Loc
,
5775 Typ
=> Node
(Iface
),
5777 Unchecked_Convert_To
5780 (Node
(Sec_DT_Ancestor
),
5783 Unchecked_Convert_To
5786 (Node
(Sec_DT_Typ
), Loc
)),
5787 Num_Prims
=> Num_Prims
));
5792 Next_Elmt
(Sec_DT_Ancestor
);
5793 Next_Elmt
(Sec_DT_Typ
);
5795 -- Skip the secondary dispatch table of
5796 -- predefined primitives
5798 Next_Elmt
(Sec_DT_Ancestor
);
5799 Next_Elmt
(Sec_DT_Typ
);
5807 end Copy_Secondary_DTs
;
5810 if Present
(Node
(Sec_DT_Ancestor
))
5811 and then Ekind
(Node
(Sec_DT_Ancestor
)) = E_Constant
5813 -- Handle private types
5815 if Present
(Full_View
(Typ
)) then
5816 Copy_Secondary_DTs
(Full_View
(Typ
));
5818 Copy_Secondary_DTs
(Typ
);
5826 -- Generate code to register the Tag in the External_Tag hash table for
5827 -- the pure Ada type only.
5829 -- Register_Tag (Dt_Ptr);
5831 -- Skip this action in the following cases:
5832 -- 1) if Register_Tag is not available.
5833 -- 2) in No_Run_Time mode.
5834 -- 3) if Typ is not defined at the library level (this is required
5835 -- to avoid adding concurrency control to the hash table used
5836 -- by the run-time to register the tags).
5838 if not No_Run_Time_Mode
5839 and then Is_Library_Level_Entity
(Typ
)
5840 and then RTE_Available
(RE_Register_Tag
)
5842 Append_To
(Elab_Code
,
5843 Make_Procedure_Call_Statement
(Loc
,
5844 Name
=> New_Reference_To
(RTE
(RE_Register_Tag
), Loc
),
5845 Parameter_Associations
=>
5846 New_List
(New_Reference_To
(DT_Ptr
, Loc
))));
5849 if not Is_Empty_List
(Elab_Code
) then
5850 Append_List_To
(Result
, Elab_Code
);
5853 -- Populate the two auxiliary tables used for dispatching asynchronous,
5854 -- conditional and timed selects for synchronized types that implement
5855 -- a limited interface. Skip this step in Ravenscar profile or when
5856 -- general dispatching is forbidden.
5858 if Ada_Version
>= Ada_05
5859 and then Is_Concurrent_Record_Type
(Typ
)
5860 and then Has_Interfaces
(Typ
)
5861 and then not Restriction_Active
(No_Dispatching_Calls
)
5862 and then not Restriction_Active
(No_Select_Statements
)
5864 Append_List_To
(Result
,
5865 Make_Select_Specific_Data_Table
(Typ
));
5868 -- Remember entities containing dispatch tables
5870 Append_Elmt
(Predef_Prims
, DT_Decl
);
5871 Append_Elmt
(DT
, DT_Decl
);
5873 Analyze_List
(Result
, Suppress
=> All_Checks
);
5874 Set_Has_Dispatch_Table
(Typ
);
5876 -- Mark entities containing dispatch tables. Required by the backend to
5877 -- handle them properly.
5879 if Has_DT
(Typ
) then
5884 -- Ensure that entities Prim_Ptr and Predef_Prims_Table_Ptr have
5885 -- the decoration required by the backend
5887 Set_Is_Dispatch_Table_Entity
(RTE
(RE_Prim_Ptr
));
5888 Set_Is_Dispatch_Table_Entity
(RTE
(RE_Predef_Prims_Table_Ptr
));
5890 -- Object declarations
5892 Elmt
:= First_Elmt
(DT_Decl
);
5893 while Present
(Elmt
) loop
5894 Set_Is_Dispatch_Table_Entity
(Node
(Elmt
));
5895 pragma Assert
(Ekind
(Etype
(Node
(Elmt
))) = E_Array_Subtype
5896 or else Ekind
(Etype
(Node
(Elmt
))) = E_Record_Subtype
);
5897 Set_Is_Dispatch_Table_Entity
(Etype
(Node
(Elmt
)));
5901 -- Aggregates initializing dispatch tables
5903 Elmt
:= First_Elmt
(DT_Aggr
);
5904 while Present
(Elmt
) loop
5905 Set_Is_Dispatch_Table_Entity
(Etype
(Node
(Elmt
)));
5911 -- Register the tagged type in the call graph nodes table
5913 Register_CG_Node
(Typ
);
5918 -------------------------------------
5919 -- Make_Select_Specific_Data_Table --
5920 -------------------------------------
5922 function Make_Select_Specific_Data_Table
5923 (Typ
: Entity_Id
) return List_Id
5925 Assignments
: constant List_Id
:= New_List
;
5926 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
5928 Conc_Typ
: Entity_Id
;
5932 Prim_Als
: Entity_Id
;
5933 Prim_Elmt
: Elmt_Id
;
5937 type Examined_Array
is array (Int
range <>) of Boolean;
5939 function Find_Entry_Index
(E
: Entity_Id
) return Uint
;
5940 -- Given an entry, find its index in the visible declarations of the
5941 -- corresponding concurrent type of Typ.
5943 ----------------------
5944 -- Find_Entry_Index --
5945 ----------------------
5947 function Find_Entry_Index
(E
: Entity_Id
) return Uint
is
5948 Index
: Uint
:= Uint_1
;
5949 Subp_Decl
: Entity_Id
;
5953 and then not Is_Empty_List
(Decls
)
5955 Subp_Decl
:= First
(Decls
);
5956 while Present
(Subp_Decl
) loop
5957 if Nkind
(Subp_Decl
) = N_Entry_Declaration
then
5958 if Defining_Identifier
(Subp_Decl
) = E
then
5970 end Find_Entry_Index
;
5972 -- Start of processing for Make_Select_Specific_Data_Table
5975 pragma Assert
(not Restriction_Active
(No_Dispatching_Calls
));
5977 DT_Ptr
:= Node
(First_Elmt
(Access_Disp_Table
(Typ
)));
5979 if Present
(Corresponding_Concurrent_Type
(Typ
)) then
5980 Conc_Typ
:= Corresponding_Concurrent_Type
(Typ
);
5982 if Present
(Full_View
(Conc_Typ
)) then
5983 Conc_Typ
:= Full_View
(Conc_Typ
);
5986 if Ekind
(Conc_Typ
) = E_Protected_Type
then
5987 Decls
:= Visible_Declarations
(Protected_Definition
(
5988 Parent
(Conc_Typ
)));
5990 pragma Assert
(Ekind
(Conc_Typ
) = E_Task_Type
);
5991 Decls
:= Visible_Declarations
(Task_Definition
(
5992 Parent
(Conc_Typ
)));
5996 -- Count the non-predefined primitive operations
5998 Prim_Elmt
:= First_Elmt
(Primitive_Operations
(Typ
));
5999 while Present
(Prim_Elmt
) loop
6000 Prim
:= Node
(Prim_Elmt
);
6002 if not (Is_Predefined_Dispatching_Operation
(Prim
)
6003 or else Is_Predefined_Dispatching_Alias
(Prim
))
6005 Nb_Prim
:= Nb_Prim
+ 1;
6008 Next_Elmt
(Prim_Elmt
);
6012 Examined
: Examined_Array
(1 .. Nb_Prim
) := (others => False);
6015 Prim_Elmt
:= First_Elmt
(Primitive_Operations
(Typ
));
6016 while Present
(Prim_Elmt
) loop
6017 Prim
:= Node
(Prim_Elmt
);
6019 -- Look for primitive overriding an abstract interface subprogram
6021 if Present
(Interface_Alias
(Prim
))
6024 (Find_Dispatching_Type
(Interface_Alias
(Prim
)), Typ
)
6025 and then not Examined
(UI_To_Int
(DT_Position
(Alias
(Prim
))))
6027 Prim_Pos
:= DT_Position
(Alias
(Prim
));
6028 pragma Assert
(UI_To_Int
(Prim_Pos
) <= Nb_Prim
);
6029 Examined
(UI_To_Int
(Prim_Pos
)) := True;
6031 -- Set the primitive operation kind regardless of subprogram
6033 -- Ada.Tags.Set_Prim_Op_Kind (DT_Ptr, <position>, <kind>);
6035 Append_To
(Assignments
,
6036 Make_Procedure_Call_Statement
(Loc
,
6037 Name
=> New_Reference_To
(RTE
(RE_Set_Prim_Op_Kind
), Loc
),
6038 Parameter_Associations
=> New_List
(
6039 New_Reference_To
(DT_Ptr
, Loc
),
6040 Make_Integer_Literal
(Loc
, Prim_Pos
),
6041 Prim_Op_Kind
(Alias
(Prim
), Typ
))));
6043 -- Retrieve the root of the alias chain
6045 Prim_Als
:= Ultimate_Alias
(Prim
);
6047 -- In the case of an entry wrapper, set the entry index
6049 if Ekind
(Prim
) = E_Procedure
6050 and then Is_Primitive_Wrapper
(Prim_Als
)
6051 and then Ekind
(Wrapped_Entity
(Prim_Als
)) = E_Entry
6054 -- Ada.Tags.Set_Entry_Index
6055 -- (DT_Ptr, <position>, <index>);
6057 Append_To
(Assignments
,
6058 Make_Procedure_Call_Statement
(Loc
,
6060 New_Reference_To
(RTE
(RE_Set_Entry_Index
), Loc
),
6061 Parameter_Associations
=> New_List
(
6062 New_Reference_To
(DT_Ptr
, Loc
),
6063 Make_Integer_Literal
(Loc
, Prim_Pos
),
6064 Make_Integer_Literal
(Loc
,
6065 Find_Entry_Index
(Wrapped_Entity
(Prim_Als
))))));
6069 Next_Elmt
(Prim_Elmt
);
6074 end Make_Select_Specific_Data_Table
;
6080 function Make_Tags
(Typ
: Entity_Id
) return List_Id
is
6081 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
6082 Result
: constant List_Id
:= New_List
;
6085 (Tag_Typ
: Entity_Id
;
6087 Is_Secondary_DT
: Boolean);
6088 -- Import the dispatch table DT of tagged type Tag_Typ. Required to
6089 -- generate forward references and statically allocate the table. For
6090 -- primary dispatch tables that require no dispatch table generate:
6091 -- DT : static aliased constant Non_Dispatch_Table_Wrapper;
6092 -- $pragma import (ada, DT);
6093 -- Otherwise generate:
6094 -- DT : static aliased constant Dispatch_Table_Wrapper (Nb_Prim);
6095 -- $pragma import (ada, DT);
6102 (Tag_Typ
: Entity_Id
;
6104 Is_Secondary_DT
: Boolean)
6106 DT_Constr_List
: List_Id
;
6110 Set_Is_Imported
(DT
);
6111 Set_Ekind
(DT
, E_Constant
);
6112 Set_Related_Type
(DT
, Typ
);
6114 -- The scope must be set now to call Get_External_Name
6116 Set_Scope
(DT
, Current_Scope
);
6118 Get_External_Name
(DT
, True);
6119 Set_Interface_Name
(DT
,
6120 Make_String_Literal
(Loc
,
6121 Strval
=> String_From_Name_Buffer
));
6123 -- Ensure proper Sprint output of this implicit importation
6125 Set_Is_Internal
(DT
);
6127 -- Save this entity to allow Make_DT to generate its exportation
6129 Append_Elmt
(DT
, Dispatch_Table_Wrappers
(Typ
));
6131 -- No dispatch table required
6133 if not Is_Secondary_DT
6134 and then not Has_DT
(Tag_Typ
)
6137 Make_Object_Declaration
(Loc
,
6138 Defining_Identifier
=> DT
,
6139 Aliased_Present
=> True,
6140 Constant_Present
=> True,
6141 Object_Definition
=>
6142 New_Reference_To
(RTE
(RE_No_Dispatch_Table_Wrapper
), Loc
)));
6145 -- Calculate the number of primitives of the dispatch table and
6146 -- the size of the Type_Specific_Data record.
6149 UI_To_Int
(DT_Entry_Count
(First_Tag_Component
(Tag_Typ
)));
6151 -- If the tagged type has no primitives we add a dummy slot
6152 -- whose address will be the tag of this type.
6156 New_List
(Make_Integer_Literal
(Loc
, 1));
6159 New_List
(Make_Integer_Literal
(Loc
, Nb_Prim
));
6163 Make_Object_Declaration
(Loc
,
6164 Defining_Identifier
=> DT
,
6165 Aliased_Present
=> True,
6166 Constant_Present
=> True,
6167 Object_Definition
=>
6168 Make_Subtype_Indication
(Loc
,
6170 New_Reference_To
(RTE
(RE_Dispatch_Table_Wrapper
), Loc
),
6171 Constraint
=> Make_Index_Or_Discriminant_Constraint
(Loc
,
6172 Constraints
=> DT_Constr_List
))));
6178 Tname
: constant Name_Id
:= Chars
(Typ
);
6179 AI_Tag_Comp
: Elmt_Id
;
6180 DT
: Node_Id
:= Empty
;
6182 Predef_Prims_Ptr
: Node_Id
;
6183 Iface_DT
: Node_Id
:= Empty
;
6184 Iface_DT_Ptr
: Node_Id
;
6188 Typ_Comps
: Elist_Id
;
6190 -- Start of processing for Make_Tags
6193 -- 1) Generate the primary and secondary tag entities
6195 -- Collect the components associated with secondary dispatch tables
6197 if Has_Interfaces
(Typ
) then
6198 Collect_Interface_Components
(Typ
, Typ_Comps
);
6201 -- 1) Generate the primary tag entities
6203 -- Primary dispatch table containing user-defined primitives
6205 DT_Ptr
:= Make_Defining_Identifier
(Loc
,
6206 New_External_Name
(Tname
, 'P'));
6207 Set_Etype
(DT_Ptr
, RTE
(RE_Tag
));
6209 -- Primary dispatch table containing predefined primitives
6212 Make_Defining_Identifier
(Loc
,
6213 Chars
=> New_External_Name
(Tname
, 'Y'));
6214 Set_Etype
(Predef_Prims_Ptr
, RTE
(RE_Address
));
6216 -- Import the forward declaration of the Dispatch Table wrapper record
6217 -- (Make_DT will take care of its exportation)
6219 if Building_Static_DT
(Typ
) then
6220 Set_Dispatch_Table_Wrappers
(Typ
, New_Elmt_List
);
6223 Make_Defining_Identifier
(Loc
,
6224 Chars
=> New_External_Name
(Tname
, 'T'));
6226 Import_DT
(Typ
, DT
, Is_Secondary_DT
=> False);
6228 if Has_DT
(Typ
) then
6230 Make_Object_Declaration
(Loc
,
6231 Defining_Identifier
=> DT_Ptr
,
6232 Constant_Present
=> True,
6233 Object_Definition
=> New_Reference_To
(RTE
(RE_Tag
), Loc
),
6235 Unchecked_Convert_To
(RTE
(RE_Tag
),
6236 Make_Attribute_Reference
(Loc
,
6238 Make_Selected_Component
(Loc
,
6239 Prefix
=> New_Reference_To
(DT
, Loc
),
6242 (RTE_Record_Component
(RE_Prims_Ptr
), Loc
)),
6243 Attribute_Name
=> Name_Address
))));
6245 -- Generate the SCIL node for the previous object declaration
6246 -- because it has a tag initialization.
6248 if Generate_SCIL
then
6250 Make_SCIL_Dispatch_Table_Tag_Init
(Sloc
(Last
(Result
)));
6251 Set_SCIL_Entity
(New_Node
, Typ
);
6252 Set_SCIL_Node
(Last
(Result
), New_Node
);
6256 Make_Object_Declaration
(Loc
,
6257 Defining_Identifier
=> Predef_Prims_Ptr
,
6258 Constant_Present
=> True,
6259 Object_Definition
=> New_Reference_To
6260 (RTE
(RE_Address
), Loc
),
6262 Make_Attribute_Reference
(Loc
,
6264 Make_Selected_Component
(Loc
,
6265 Prefix
=> New_Reference_To
(DT
, Loc
),
6268 (RTE_Record_Component
(RE_Predef_Prims
), Loc
)),
6269 Attribute_Name
=> Name_Address
)));
6271 -- No dispatch table required
6275 Make_Object_Declaration
(Loc
,
6276 Defining_Identifier
=> DT_Ptr
,
6277 Constant_Present
=> True,
6278 Object_Definition
=> New_Reference_To
(RTE
(RE_Tag
), Loc
),
6280 Unchecked_Convert_To
(RTE
(RE_Tag
),
6281 Make_Attribute_Reference
(Loc
,
6283 Make_Selected_Component
(Loc
,
6284 Prefix
=> New_Reference_To
(DT
, Loc
),
6287 (RTE_Record_Component
(RE_NDT_Prims_Ptr
), Loc
)),
6288 Attribute_Name
=> Name_Address
))));
6291 Set_Is_True_Constant
(DT_Ptr
);
6292 Set_Is_Statically_Allocated
(DT_Ptr
);
6295 pragma Assert
(No
(Access_Disp_Table
(Typ
)));
6296 Set_Access_Disp_Table
(Typ
, New_Elmt_List
);
6297 Append_Elmt
(DT_Ptr
, Access_Disp_Table
(Typ
));
6298 Append_Elmt
(Predef_Prims_Ptr
, Access_Disp_Table
(Typ
));
6300 -- 2) Generate the secondary tag entities
6302 if Has_Interfaces
(Typ
) then
6304 -- Note: The following value of Suffix_Index must be in sync with
6305 -- the Suffix_Index values of secondary dispatch tables generated
6310 -- For each interface type we build an unique external name
6311 -- associated with its corresponding secondary dispatch table.
6312 -- This external name will be used to declare an object that
6313 -- references this secondary dispatch table, value that will be
6314 -- used for the elaboration of Typ's objects and also for the
6315 -- elaboration of objects of derivations of Typ that do not
6316 -- override the primitive operation of this interface type.
6318 AI_Tag_Comp
:= First_Elmt
(Typ_Comps
);
6319 while Present
(AI_Tag_Comp
) loop
6320 Get_Secondary_DT_External_Name
6321 (Typ
, Related_Type
(Node
(AI_Tag_Comp
)), Suffix_Index
);
6322 Typ_Name
:= Name_Find
;
6324 if Building_Static_DT
(Typ
) then
6326 Make_Defining_Identifier
(Loc
,
6327 Chars
=> New_External_Name
6328 (Typ_Name
, 'T', Suffix_Index
=> -1));
6330 (Tag_Typ
=> Related_Type
(Node
(AI_Tag_Comp
)),
6332 Is_Secondary_DT
=> True);
6335 -- Secondary dispatch table referencing thunks to user-defined
6336 -- primitives covered by this interface.
6339 Make_Defining_Identifier
(Loc
,
6340 Chars
=> New_External_Name
(Typ_Name
, 'P'));
6341 Set_Etype
(Iface_DT_Ptr
, RTE
(RE_Interface_Tag
));
6342 Set_Ekind
(Iface_DT_Ptr
, E_Constant
);
6343 Set_Is_Tag
(Iface_DT_Ptr
);
6344 Set_Has_Thunks
(Iface_DT_Ptr
);
6345 Set_Is_Statically_Allocated
(Iface_DT_Ptr
,
6346 Is_Library_Level_Tagged_Type
(Typ
));
6347 Set_Is_True_Constant
(Iface_DT_Ptr
);
6349 (Iface_DT_Ptr
, Related_Type
(Node
(AI_Tag_Comp
)));
6350 Append_Elmt
(Iface_DT_Ptr
, Access_Disp_Table
(Typ
));
6352 if Building_Static_DT
(Typ
) then
6354 Make_Object_Declaration
(Loc
,
6355 Defining_Identifier
=> Iface_DT_Ptr
,
6356 Constant_Present
=> True,
6357 Object_Definition
=> New_Reference_To
6358 (RTE
(RE_Interface_Tag
), Loc
),
6360 Unchecked_Convert_To
(RTE
(RE_Interface_Tag
),
6361 Make_Attribute_Reference
(Loc
,
6363 Make_Selected_Component
(Loc
,
6364 Prefix
=> New_Reference_To
(Iface_DT
, Loc
),
6367 (RTE_Record_Component
(RE_Prims_Ptr
), Loc
)),
6368 Attribute_Name
=> Name_Address
))));
6371 -- Secondary dispatch table referencing thunks to predefined
6375 Make_Defining_Identifier
(Loc
,
6376 Chars
=> New_External_Name
(Typ_Name
, 'Y'));
6377 Set_Etype
(Iface_DT_Ptr
, RTE
(RE_Address
));
6378 Set_Ekind
(Iface_DT_Ptr
, E_Constant
);
6379 Set_Is_Tag
(Iface_DT_Ptr
);
6380 Set_Has_Thunks
(Iface_DT_Ptr
);
6381 Set_Is_Statically_Allocated
(Iface_DT_Ptr
,
6382 Is_Library_Level_Tagged_Type
(Typ
));
6383 Set_Is_True_Constant
(Iface_DT_Ptr
);
6385 (Iface_DT_Ptr
, Related_Type
(Node
(AI_Tag_Comp
)));
6386 Append_Elmt
(Iface_DT_Ptr
, Access_Disp_Table
(Typ
));
6388 -- Secondary dispatch table referencing user-defined primitives
6389 -- covered by this interface.
6392 Make_Defining_Identifier
(Loc
,
6393 Chars
=> New_External_Name
(Typ_Name
, 'D'));
6394 Set_Etype
(Iface_DT_Ptr
, RTE
(RE_Interface_Tag
));
6395 Set_Ekind
(Iface_DT_Ptr
, E_Constant
);
6396 Set_Is_Tag
(Iface_DT_Ptr
);
6397 Set_Is_Statically_Allocated
(Iface_DT_Ptr
,
6398 Is_Library_Level_Tagged_Type
(Typ
));
6399 Set_Is_True_Constant
(Iface_DT_Ptr
);
6401 (Iface_DT_Ptr
, Related_Type
(Node
(AI_Tag_Comp
)));
6402 Append_Elmt
(Iface_DT_Ptr
, Access_Disp_Table
(Typ
));
6404 -- Secondary dispatch table referencing predefined primitives
6407 Make_Defining_Identifier
(Loc
,
6408 Chars
=> New_External_Name
(Typ_Name
, 'Z'));
6409 Set_Etype
(Iface_DT_Ptr
, RTE
(RE_Address
));
6410 Set_Ekind
(Iface_DT_Ptr
, E_Constant
);
6411 Set_Is_Tag
(Iface_DT_Ptr
);
6412 Set_Is_Statically_Allocated
(Iface_DT_Ptr
,
6413 Is_Library_Level_Tagged_Type
(Typ
));
6414 Set_Is_True_Constant
(Iface_DT_Ptr
);
6416 (Iface_DT_Ptr
, Related_Type
(Node
(AI_Tag_Comp
)));
6417 Append_Elmt
(Iface_DT_Ptr
, Access_Disp_Table
(Typ
));
6419 Next_Elmt
(AI_Tag_Comp
);
6423 -- 3) At the end of Access_Disp_Table, if the type has user-defined
6424 -- primitives, we add the entity of an access type declaration that
6425 -- is used by Build_Get_Prim_Op_Address to expand dispatching calls
6426 -- through the primary dispatch table.
6428 if UI_To_Int
(DT_Entry_Count
(First_Tag_Component
(Typ
))) = 0 then
6429 Analyze_List
(Result
);
6432 -- type Typ_DT is array (1 .. Nb_Prims) of Prim_Ptr;
6433 -- type Typ_DT_Acc is access Typ_DT;
6437 Name_DT_Prims
: constant Name_Id
:=
6438 New_External_Name
(Tname
, 'G');
6439 Name_DT_Prims_Acc
: constant Name_Id
:=
6440 New_External_Name
(Tname
, 'H');
6441 DT_Prims
: constant Entity_Id
:=
6442 Make_Defining_Identifier
(Loc
,
6444 DT_Prims_Acc
: constant Entity_Id
:=
6445 Make_Defining_Identifier
(Loc
,
6449 Make_Full_Type_Declaration
(Loc
,
6450 Defining_Identifier
=> DT_Prims
,
6452 Make_Constrained_Array_Definition
(Loc
,
6453 Discrete_Subtype_Definitions
=> New_List
(
6455 Low_Bound
=> Make_Integer_Literal
(Loc
, 1),
6456 High_Bound
=> Make_Integer_Literal
(Loc
,
6458 (First_Tag_Component
(Typ
))))),
6459 Component_Definition
=>
6460 Make_Component_Definition
(Loc
,
6461 Subtype_Indication
=>
6462 New_Reference_To
(RTE
(RE_Prim_Ptr
), Loc
)))));
6465 Make_Full_Type_Declaration
(Loc
,
6466 Defining_Identifier
=> DT_Prims_Acc
,
6468 Make_Access_To_Object_Definition
(Loc
,
6469 Subtype_Indication
=>
6470 New_Occurrence_Of
(DT_Prims
, Loc
))));
6472 Append_Elmt
(DT_Prims_Acc
, Access_Disp_Table
(Typ
));
6474 -- Analyze the resulting list and suppress the generation of the
6475 -- Init_Proc associated with the above array declaration because
6476 -- this type is never used in object declarations. It is only used
6477 -- to simplify the expansion associated with dispatching calls.
6479 Analyze_List
(Result
);
6480 Set_Suppress_Init_Proc
(Base_Type
(DT_Prims
));
6482 -- Mark entity of dispatch table. Required by the back end to
6483 -- handle them properly.
6485 Set_Is_Dispatch_Table_Entity
(DT_Prims
);
6489 -- Mark entities of dispatch table. Required by the back end to
6490 -- handle them properly.
6492 if Present
(DT
) then
6493 Set_Is_Dispatch_Table_Entity
(DT
);
6494 Set_Is_Dispatch_Table_Entity
(Etype
(DT
));
6497 if Present
(Iface_DT
) then
6498 Set_Is_Dispatch_Table_Entity
(Iface_DT
);
6499 Set_Is_Dispatch_Table_Entity
(Etype
(Iface_DT
));
6502 Set_Ekind
(DT_Ptr
, E_Constant
);
6503 Set_Is_Tag
(DT_Ptr
);
6504 Set_Related_Type
(DT_Ptr
, Typ
);
6513 function New_Value
(From
: Node_Id
) return Node_Id
is
6514 Res
: constant Node_Id
:= Duplicate_Subexpr
(From
);
6516 if Is_Access_Type
(Etype
(From
)) then
6518 Make_Explicit_Dereference
(Sloc
(From
),
6525 -----------------------------------
6526 -- Original_View_In_Visible_Part --
6527 -----------------------------------
6529 function Original_View_In_Visible_Part
(Typ
: Entity_Id
) return Boolean is
6530 Scop
: constant Entity_Id
:= Scope
(Typ
);
6533 -- The scope must be a package
6535 if not Is_Package_Or_Generic_Package
(Scop
) then
6539 -- A type with a private declaration has a private view declared in
6540 -- the visible part.
6542 if Has_Private_Declaration
(Typ
) then
6546 return List_Containing
(Parent
(Typ
)) =
6547 Visible_Declarations
(Specification
(Unit_Declaration_Node
(Scop
)));
6548 end Original_View_In_Visible_Part
;
6554 function Prim_Op_Kind
6556 Typ
: Entity_Id
) return Node_Id
6558 Full_Typ
: Entity_Id
:= Typ
;
6559 Loc
: constant Source_Ptr
:= Sloc
(Prim
);
6560 Prim_Op
: Entity_Id
;
6563 -- Retrieve the original primitive operation
6565 Prim_Op
:= Ultimate_Alias
(Prim
);
6567 if Ekind
(Typ
) = E_Record_Type
6568 and then Present
(Corresponding_Concurrent_Type
(Typ
))
6570 Full_Typ
:= Corresponding_Concurrent_Type
(Typ
);
6573 -- When a private tagged type is completed by a concurrent type,
6574 -- retrieve the full view.
6576 if Is_Private_Type
(Full_Typ
) then
6577 Full_Typ
:= Full_View
(Full_Typ
);
6580 if Ekind
(Prim_Op
) = E_Function
then
6582 -- Protected function
6584 if Ekind
(Full_Typ
) = E_Protected_Type
then
6585 return New_Reference_To
(RTE
(RE_POK_Protected_Function
), Loc
);
6589 elsif Ekind
(Full_Typ
) = E_Task_Type
then
6590 return New_Reference_To
(RTE
(RE_POK_Task_Function
), Loc
);
6595 return New_Reference_To
(RTE
(RE_POK_Function
), Loc
);
6599 pragma Assert
(Ekind
(Prim_Op
) = E_Procedure
);
6601 if Ekind
(Full_Typ
) = E_Protected_Type
then
6605 if Is_Primitive_Wrapper
(Prim_Op
)
6606 and then Ekind
(Wrapped_Entity
(Prim_Op
)) = E_Entry
6608 return New_Reference_To
(RTE
(RE_POK_Protected_Entry
), Loc
);
6610 -- Protected procedure
6613 return New_Reference_To
(RTE
(RE_POK_Protected_Procedure
), Loc
);
6616 elsif Ekind
(Full_Typ
) = E_Task_Type
then
6620 if Is_Primitive_Wrapper
(Prim_Op
)
6621 and then Ekind
(Wrapped_Entity
(Prim_Op
)) = E_Entry
6623 return New_Reference_To
(RTE
(RE_POK_Task_Entry
), Loc
);
6625 -- Task "procedure". These are the internally Expander-generated
6626 -- procedures (task body for instance).
6629 return New_Reference_To
(RTE
(RE_POK_Task_Procedure
), Loc
);
6632 -- Regular procedure
6635 return New_Reference_To
(RTE
(RE_POK_Procedure
), Loc
);
6640 ------------------------
6641 -- Register_Primitive --
6642 ------------------------
6644 function Register_Primitive
6646 Prim
: Entity_Id
) return List_Id
6649 Iface_Prim
: Entity_Id
;
6650 Iface_Typ
: Entity_Id
;
6651 Iface_DT_Ptr
: Entity_Id
;
6652 Iface_DT_Elmt
: Elmt_Id
;
6653 L
: constant List_Id
:= New_List
;
6656 Tag_Typ
: Entity_Id
;
6657 Thunk_Id
: Entity_Id
;
6658 Thunk_Code
: Node_Id
;
6661 pragma Assert
(not Restriction_Active
(No_Dispatching_Calls
));
6663 -- Do not register in the dispatch table eliminated primitives
6665 if not RTE_Available
(RE_Tag
)
6666 or else Is_Eliminated
(Ultimate_Alias
(Prim
))
6671 if not Present
(Interface_Alias
(Prim
)) then
6672 Tag_Typ
:= Scope
(DTC_Entity
(Prim
));
6673 Pos
:= DT_Position
(Prim
);
6674 Tag
:= First_Tag_Component
(Tag_Typ
);
6676 if Is_Predefined_Dispatching_Operation
(Prim
)
6677 or else Is_Predefined_Dispatching_Alias
(Prim
)
6680 Node
(Next_Elmt
(First_Elmt
(Access_Disp_Table
(Tag_Typ
))));
6683 Build_Set_Predefined_Prim_Op_Address
(Loc
,
6684 Tag_Node
=> New_Reference_To
(DT_Ptr
, Loc
),
6687 Unchecked_Convert_To
(RTE
(RE_Prim_Ptr
),
6688 Make_Attribute_Reference
(Loc
,
6689 Prefix
=> New_Reference_To
(Prim
, Loc
),
6690 Attribute_Name
=> Name_Unrestricted_Access
))));
6692 -- Register copy of the pointer to the 'size primitive in the TSD
6694 if Chars
(Prim
) = Name_uSize
6695 and then RTE_Record_Component_Available
(RE_Size_Func
)
6697 DT_Ptr
:= Node
(First_Elmt
(Access_Disp_Table
(Tag_Typ
)));
6699 Build_Set_Size_Function
(Loc
,
6700 Tag_Node
=> New_Reference_To
(DT_Ptr
, Loc
),
6701 Size_Func
=> Prim
));
6705 pragma Assert
(Pos
/= Uint_0
and then Pos
<= DT_Entry_Count
(Tag
));
6707 DT_Ptr
:= Node
(First_Elmt
(Access_Disp_Table
(Tag_Typ
)));
6709 Build_Set_Prim_Op_Address
(Loc
,
6711 Tag_Node
=> New_Reference_To
(DT_Ptr
, Loc
),
6714 Unchecked_Convert_To
(RTE
(RE_Prim_Ptr
),
6715 Make_Attribute_Reference
(Loc
,
6716 Prefix
=> New_Reference_To
(Prim
, Loc
),
6717 Attribute_Name
=> Name_Unrestricted_Access
))));
6720 -- Ada 2005 (AI-251): Primitive associated with an interface type
6721 -- Generate the code of the thunk only if the interface type is not an
6722 -- immediate ancestor of Typ; otherwise the dispatch table associated
6723 -- with the interface is the primary dispatch table and we have nothing
6727 Tag_Typ
:= Find_Dispatching_Type
(Alias
(Prim
));
6728 Iface_Typ
:= Find_Dispatching_Type
(Interface_Alias
(Prim
));
6730 pragma Assert
(Is_Interface
(Iface_Typ
));
6732 -- No action needed for interfaces that are ancestors of Typ because
6733 -- their primitives are located in the primary dispatch table.
6735 if Is_Ancestor
(Iface_Typ
, Tag_Typ
) then
6739 Expand_Interface_Thunk
(Prim
, Thunk_Id
, Thunk_Code
);
6741 if not Is_Ancestor
(Iface_Typ
, Tag_Typ
)
6742 and then Present
(Thunk_Code
)
6744 -- Generate the code necessary to fill the appropriate entry of
6745 -- the secondary dispatch table of Prim's controlling type with
6746 -- Thunk_Id's address.
6748 Iface_DT_Elmt
:= Find_Interface_ADT
(Tag_Typ
, Iface_Typ
);
6749 Iface_DT_Ptr
:= Node
(Iface_DT_Elmt
);
6750 pragma Assert
(Has_Thunks
(Iface_DT_Ptr
));
6752 Iface_Prim
:= Interface_Alias
(Prim
);
6753 Pos
:= DT_Position
(Iface_Prim
);
6754 Tag
:= First_Tag_Component
(Iface_Typ
);
6756 Prepend_To
(L
, Thunk_Code
);
6758 if Is_Predefined_Dispatching_Operation
(Prim
)
6759 or else Is_Predefined_Dispatching_Alias
(Prim
)
6762 Build_Set_Predefined_Prim_Op_Address
(Loc
,
6764 New_Reference_To
(Node
(Next_Elmt
(Iface_DT_Elmt
)), Loc
),
6767 Unchecked_Convert_To
(RTE
(RE_Prim_Ptr
),
6768 Make_Attribute_Reference
(Loc
,
6769 Prefix
=> New_Reference_To
(Thunk_Id
, Loc
),
6770 Attribute_Name
=> Name_Unrestricted_Access
))));
6772 Next_Elmt
(Iface_DT_Elmt
);
6773 Next_Elmt
(Iface_DT_Elmt
);
6774 Iface_DT_Ptr
:= Node
(Iface_DT_Elmt
);
6775 pragma Assert
(not Has_Thunks
(Iface_DT_Ptr
));
6778 Build_Set_Predefined_Prim_Op_Address
(Loc
,
6780 New_Reference_To
(Node
(Next_Elmt
(Iface_DT_Elmt
)), Loc
),
6783 Unchecked_Convert_To
(RTE
(RE_Prim_Ptr
),
6784 Make_Attribute_Reference
(Loc
,
6785 Prefix
=> New_Reference_To
(Alias
(Prim
), Loc
),
6786 Attribute_Name
=> Name_Unrestricted_Access
))));
6789 pragma Assert
(Pos
/= Uint_0
6790 and then Pos
<= DT_Entry_Count
(Tag
));
6793 Build_Set_Prim_Op_Address
(Loc
,
6795 Tag_Node
=> New_Reference_To
(Iface_DT_Ptr
, Loc
),
6798 Unchecked_Convert_To
(RTE
(RE_Prim_Ptr
),
6799 Make_Attribute_Reference
(Loc
,
6800 Prefix
=> New_Reference_To
(Thunk_Id
, Loc
),
6801 Attribute_Name
=> Name_Unrestricted_Access
))));
6803 Next_Elmt
(Iface_DT_Elmt
);
6804 Next_Elmt
(Iface_DT_Elmt
);
6805 Iface_DT_Ptr
:= Node
(Iface_DT_Elmt
);
6806 pragma Assert
(not Has_Thunks
(Iface_DT_Ptr
));
6809 Build_Set_Prim_Op_Address
(Loc
,
6811 Tag_Node
=> New_Reference_To
(Iface_DT_Ptr
, Loc
),
6814 Unchecked_Convert_To
(RTE
(RE_Prim_Ptr
),
6815 Make_Attribute_Reference
(Loc
,
6816 Prefix
=> New_Reference_To
(Alias
(Prim
), Loc
),
6817 Attribute_Name
=> Name_Unrestricted_Access
))));
6824 end Register_Primitive
;
6826 -------------------------
6827 -- Set_All_DT_Position --
6828 -------------------------
6830 procedure Set_All_DT_Position
(Typ
: Entity_Id
) is
6832 procedure Validate_Position
(Prim
: Entity_Id
);
6833 -- Check that the position assigned to Prim is completely safe
6834 -- (it has not been assigned to a previously defined primitive
6835 -- operation of Typ)
6837 -----------------------
6838 -- Validate_Position --
6839 -----------------------
6841 procedure Validate_Position
(Prim
: Entity_Id
) is
6846 -- Aliased primitives are safe
6848 if Present
(Alias
(Prim
)) then
6852 Op_Elmt
:= First_Elmt
(Primitive_Operations
(Typ
));
6853 while Present
(Op_Elmt
) loop
6854 Op
:= Node
(Op_Elmt
);
6856 -- No need to check against itself
6861 -- Primitive operations covering abstract interfaces are
6864 elsif Present
(Interface_Alias
(Op
)) then
6867 -- Predefined dispatching operations are completely safe. They
6868 -- are allocated at fixed positions in a separate table.
6870 elsif Is_Predefined_Dispatching_Operation
(Op
)
6871 or else Is_Predefined_Dispatching_Alias
(Op
)
6875 -- Aliased subprograms are safe
6877 elsif Present
(Alias
(Op
)) then
6880 elsif DT_Position
(Op
) = DT_Position
(Prim
)
6881 and then not Is_Predefined_Dispatching_Operation
(Op
)
6882 and then not Is_Predefined_Dispatching_Operation
(Prim
)
6883 and then not Is_Predefined_Dispatching_Alias
(Op
)
6884 and then not Is_Predefined_Dispatching_Alias
(Prim
)
6887 -- Handle aliased subprograms
6896 if Present
(Overridden_Operation
(Op_1
)) then
6897 Op_1
:= Overridden_Operation
(Op_1
);
6898 elsif Present
(Alias
(Op_1
)) then
6899 Op_1
:= Alias
(Op_1
);
6907 if Present
(Overridden_Operation
(Op_2
)) then
6908 Op_2
:= Overridden_Operation
(Op_2
);
6909 elsif Present
(Alias
(Op_2
)) then
6910 Op_2
:= Alias
(Op_2
);
6916 if Op_1
/= Op_2
then
6917 raise Program_Error
;
6922 Next_Elmt
(Op_Elmt
);
6924 end Validate_Position
;
6928 Parent_Typ
: constant Entity_Id
:= Etype
(Typ
);
6929 First_Prim
: constant Elmt_Id
:= First_Elmt
(Primitive_Operations
(Typ
));
6930 The_Tag
: constant Entity_Id
:= First_Tag_Component
(Typ
);
6932 Adjusted
: Boolean := False;
6933 Finalized
: Boolean := False;
6939 Prim_Elmt
: Elmt_Id
;
6941 -- Start of processing for Set_All_DT_Position
6944 pragma Assert
(Present
(First_Tag_Component
(Typ
)));
6946 -- Set the DT_Position for each primitive operation. Perform some sanity
6947 -- checks to avoid building inconsistent dispatch tables.
6949 -- First stage: Set the DTC entity of all the primitive operations. This
6950 -- is required to properly read the DT_Position attribute in the latter
6953 Prim_Elmt
:= First_Prim
;
6955 while Present
(Prim_Elmt
) loop
6956 Prim
:= Node
(Prim_Elmt
);
6958 -- Predefined primitives have a separate dispatch table
6960 if not (Is_Predefined_Dispatching_Operation
(Prim
)
6962 Is_Predefined_Dispatching_Alias
(Prim
))
6964 Count_Prim
:= Count_Prim
+ 1;
6967 Set_DTC_Entity_Value
(Typ
, Prim
);
6969 -- Clear any previous value of the DT_Position attribute. In this
6970 -- way we ensure that the final position of all the primitives is
6971 -- established by the following stages of this algorithm.
6973 Set_DT_Position
(Prim
, No_Uint
);
6975 Next_Elmt
(Prim_Elmt
);
6979 Fixed_Prim
: array (Int
range 0 .. Count_Prim
) of Boolean :=
6984 procedure Handle_Inherited_Private_Subprograms
(Typ
: Entity_Id
);
6985 -- Called if Typ is declared in a nested package or a public child
6986 -- package to handle inherited primitives that were inherited by Typ
6987 -- in the visible part, but whose declaration was deferred because
6988 -- the parent operation was private and not visible at that point.
6990 procedure Set_Fixed_Prim
(Pos
: Nat
);
6991 -- Sets to true an element of the Fixed_Prim table to indicate
6992 -- that this entry of the dispatch table of Typ is occupied.
6994 ------------------------------------------
6995 -- Handle_Inherited_Private_Subprograms --
6996 ------------------------------------------
6998 procedure Handle_Inherited_Private_Subprograms
(Typ
: Entity_Id
) is
7001 Op_Elmt_2
: Elmt_Id
;
7002 Prim_Op
: Entity_Id
;
7003 Parent_Subp
: Entity_Id
;
7006 Op_List
:= Primitive_Operations
(Typ
);
7008 Op_Elmt
:= First_Elmt
(Op_List
);
7009 while Present
(Op_Elmt
) loop
7010 Prim_Op
:= Node
(Op_Elmt
);
7012 -- Search primitives that are implicit operations with an
7013 -- internal name whose parent operation has a normal name.
7015 if Present
(Alias
(Prim_Op
))
7016 and then Find_Dispatching_Type
(Alias
(Prim_Op
)) /= Typ
7017 and then not Comes_From_Source
(Prim_Op
)
7018 and then Is_Internal_Name
(Chars
(Prim_Op
))
7019 and then not Is_Internal_Name
(Chars
(Alias
(Prim_Op
)))
7021 Parent_Subp
:= Alias
(Prim_Op
);
7023 -- Check if the type has an explicit overriding for this
7026 Op_Elmt_2
:= Next_Elmt
(Op_Elmt
);
7027 while Present
(Op_Elmt_2
) loop
7028 if Chars
(Node
(Op_Elmt_2
)) = Chars
(Parent_Subp
)
7029 and then Type_Conformant
(Prim_Op
, Node
(Op_Elmt_2
))
7031 Set_DT_Position
(Prim_Op
, DT_Position
(Parent_Subp
));
7032 Set_DT_Position
(Node
(Op_Elmt_2
),
7033 DT_Position
(Parent_Subp
));
7034 Set_Fixed_Prim
(UI_To_Int
(DT_Position
(Prim_Op
)));
7036 goto Next_Primitive
;
7039 Next_Elmt
(Op_Elmt_2
);
7044 Next_Elmt
(Op_Elmt
);
7046 end Handle_Inherited_Private_Subprograms
;
7048 --------------------
7049 -- Set_Fixed_Prim --
7050 --------------------
7052 procedure Set_Fixed_Prim
(Pos
: Nat
) is
7054 pragma Assert
(Pos
<= Count_Prim
);
7055 Fixed_Prim
(Pos
) := True;
7057 when Constraint_Error
=>
7058 raise Program_Error
;
7062 -- In case of nested packages and public child package it may be
7063 -- necessary a special management on inherited subprograms so that
7064 -- the dispatch table is properly filled.
7066 if Ekind
(Scope
(Scope
(Typ
))) = E_Package
7067 and then Scope
(Scope
(Typ
)) /= Standard_Standard
7068 and then ((Is_Derived_Type
(Typ
) and then not Is_Private_Type
(Typ
))
7070 (Nkind
(Parent
(Typ
)) = N_Private_Extension_Declaration
7071 and then Is_Generic_Type
(Typ
)))
7072 and then In_Open_Scopes
(Scope
(Etype
(Typ
)))
7073 and then Typ
= Base_Type
(Typ
)
7075 Handle_Inherited_Private_Subprograms
(Typ
);
7078 -- Second stage: Register fixed entries
7081 Prim_Elmt
:= First_Prim
;
7082 while Present
(Prim_Elmt
) loop
7083 Prim
:= Node
(Prim_Elmt
);
7085 -- Predefined primitives have a separate table and all its
7086 -- entries are at predefined fixed positions.
7088 if Is_Predefined_Dispatching_Operation
(Prim
) then
7089 Set_DT_Position
(Prim
, Default_Prim_Op_Position
(Prim
));
7091 elsif Is_Predefined_Dispatching_Alias
(Prim
) then
7092 Set_DT_Position
(Prim
,
7093 Default_Prim_Op_Position
(Ultimate_Alias
(Prim
)));
7095 -- Overriding primitives of ancestor abstract interfaces
7097 elsif Present
(Interface_Alias
(Prim
))
7098 and then Is_Ancestor
7099 (Find_Dispatching_Type
(Interface_Alias
(Prim
)), Typ
)
7101 pragma Assert
(DT_Position
(Prim
) = No_Uint
7102 and then Present
(DTC_Entity
(Interface_Alias
(Prim
))));
7104 E
:= Interface_Alias
(Prim
);
7105 Set_DT_Position
(Prim
, DT_Position
(E
));
7108 (DT_Position
(Alias
(Prim
)) = No_Uint
7109 or else DT_Position
(Alias
(Prim
)) = DT_Position
(E
));
7110 Set_DT_Position
(Alias
(Prim
), DT_Position
(E
));
7111 Set_Fixed_Prim
(UI_To_Int
(DT_Position
(Prim
)));
7113 -- Overriding primitives must use the same entry as the
7114 -- overridden primitive.
7116 elsif not Present
(Interface_Alias
(Prim
))
7117 and then Present
(Alias
(Prim
))
7118 and then Chars
(Prim
) = Chars
(Alias
(Prim
))
7119 and then Find_Dispatching_Type
(Alias
(Prim
)) /= Typ
7120 and then Is_Ancestor
7121 (Find_Dispatching_Type
(Alias
(Prim
)), Typ
)
7122 and then Present
(DTC_Entity
(Alias
(Prim
)))
7125 Set_DT_Position
(Prim
, DT_Position
(E
));
7127 if not Is_Predefined_Dispatching_Alias
(E
) then
7128 Set_Fixed_Prim
(UI_To_Int
(DT_Position
(E
)));
7132 Next_Elmt
(Prim_Elmt
);
7135 -- Third stage: Fix the position of all the new primitives.
7136 -- Entries associated with primitives covering interfaces
7137 -- are handled in a latter round.
7139 Prim_Elmt
:= First_Prim
;
7140 while Present
(Prim_Elmt
) loop
7141 Prim
:= Node
(Prim_Elmt
);
7143 -- Skip primitives previously set entries
7145 if DT_Position
(Prim
) /= No_Uint
then
7148 -- Primitives covering interface primitives are handled later
7150 elsif Present
(Interface_Alias
(Prim
)) then
7154 -- Take the next available position in the DT
7157 Nb_Prim
:= Nb_Prim
+ 1;
7158 pragma Assert
(Nb_Prim
<= Count_Prim
);
7159 exit when not Fixed_Prim
(Nb_Prim
);
7162 Set_DT_Position
(Prim
, UI_From_Int
(Nb_Prim
));
7163 Set_Fixed_Prim
(Nb_Prim
);
7166 Next_Elmt
(Prim_Elmt
);
7170 -- Fourth stage: Complete the decoration of primitives covering
7171 -- interfaces (that is, propagate the DT_Position attribute
7172 -- from the aliased primitive)
7174 Prim_Elmt
:= First_Prim
;
7175 while Present
(Prim_Elmt
) loop
7176 Prim
:= Node
(Prim_Elmt
);
7178 if DT_Position
(Prim
) = No_Uint
7179 and then Present
(Interface_Alias
(Prim
))
7181 pragma Assert
(Present
(Alias
(Prim
))
7182 and then Find_Dispatching_Type
(Alias
(Prim
)) = Typ
);
7184 -- Check if this entry will be placed in the primary DT
7187 (Find_Dispatching_Type
(Interface_Alias
(Prim
)), Typ
)
7189 pragma Assert
(DT_Position
(Alias
(Prim
)) /= No_Uint
);
7190 Set_DT_Position
(Prim
, DT_Position
(Alias
(Prim
)));
7192 -- Otherwise it will be placed in the secondary DT
7196 (DT_Position
(Interface_Alias
(Prim
)) /= No_Uint
);
7197 Set_DT_Position
(Prim
,
7198 DT_Position
(Interface_Alias
(Prim
)));
7202 Next_Elmt
(Prim_Elmt
);
7205 -- Generate listing showing the contents of the dispatch tables.
7206 -- This action is done before some further static checks because
7207 -- in case of critical errors caused by a wrong dispatch table
7208 -- we need to see the contents of such table.
7210 if Debug_Flag_ZZ
then
7214 -- Final stage: Ensure that the table is correct plus some further
7215 -- verifications concerning the primitives.
7217 Prim_Elmt
:= First_Prim
;
7219 while Present
(Prim_Elmt
) loop
7220 Prim
:= Node
(Prim_Elmt
);
7222 -- At this point all the primitives MUST have a position
7223 -- in the dispatch table.
7225 if DT_Position
(Prim
) = No_Uint
then
7226 raise Program_Error
;
7229 -- Calculate real size of the dispatch table
7231 if not (Is_Predefined_Dispatching_Operation
(Prim
)
7232 or else Is_Predefined_Dispatching_Alias
(Prim
))
7233 and then UI_To_Int
(DT_Position
(Prim
)) > DT_Length
7235 DT_Length
:= UI_To_Int
(DT_Position
(Prim
));
7238 -- Ensure that the assigned position to non-predefined
7239 -- dispatching operations in the dispatch table is correct.
7241 if not (Is_Predefined_Dispatching_Operation
(Prim
)
7242 or else Is_Predefined_Dispatching_Alias
(Prim
))
7244 Validate_Position
(Prim
);
7247 if Chars
(Prim
) = Name_Finalize
then
7251 if Chars
(Prim
) = Name_Adjust
then
7255 -- An abstract operation cannot be declared in the private part for a
7256 -- visible abstract type, because it can't be overridden outside this
7257 -- package hierarchy. For explicit declarations this is checked at
7258 -- the point of declaration, but for inherited operations it must be
7259 -- done when building the dispatch table.
7261 -- Ada 2005 (AI-251): Primitives associated with interfaces are
7262 -- excluded from this check because interfaces must be visible in
7263 -- the public and private part (RM 7.3 (7.3/2))
7265 if Is_Abstract_Type
(Typ
)
7266 and then Is_Abstract_Subprogram
(Prim
)
7267 and then Present
(Alias
(Prim
))
7268 and then not Is_Interface
7269 (Find_Dispatching_Type
(Ultimate_Alias
(Prim
)))
7270 and then not Present
(Interface_Alias
(Prim
))
7271 and then Is_Derived_Type
(Typ
)
7272 and then In_Private_Part
(Current_Scope
)
7274 List_Containing
(Parent
(Prim
)) =
7275 Private_Declarations
7276 (Specification
(Unit_Declaration_Node
(Current_Scope
)))
7277 and then Original_View_In_Visible_Part
(Typ
)
7279 -- We exclude Input and Output stream operations because
7280 -- Limited_Controlled inherits useless Input and Output
7281 -- stream operations from Root_Controlled, which can
7282 -- never be overridden.
7284 if not Is_TSS
(Prim
, TSS_Stream_Input
)
7286 not Is_TSS
(Prim
, TSS_Stream_Output
)
7289 ("abstract inherited private operation&" &
7290 " must be overridden (RM 3.9.3(10))",
7291 Parent
(Typ
), Prim
);
7295 Next_Elmt
(Prim_Elmt
);
7300 if Is_Controlled
(Typ
) then
7301 if not Finalized
then
7303 ("controlled type has no explicit Finalize method?", Typ
);
7305 elsif not Adjusted
then
7307 ("controlled type has no explicit Adjust method?", Typ
);
7311 -- Set the final size of the Dispatch Table
7313 Set_DT_Entry_Count
(The_Tag
, UI_From_Int
(DT_Length
));
7315 -- The derived type must have at least as many components as its parent
7316 -- (for root types Etype points to itself and the test cannot fail).
7318 if DT_Entry_Count
(The_Tag
) <
7319 DT_Entry_Count
(First_Tag_Component
(Parent_Typ
))
7321 raise Program_Error
;
7323 end Set_All_DT_Position
;
7325 --------------------------
7326 -- Set_CPP_Constructors --
7327 --------------------------
7329 procedure Set_CPP_Constructors
(Typ
: Entity_Id
) is
7333 Found
: Boolean := False;
7338 -- Look for the constructor entities
7340 E
:= Next_Entity
(Typ
);
7341 while Present
(E
) loop
7342 if Ekind
(E
) = E_Function
7343 and then Is_Constructor
(E
)
7345 -- Create the init procedure
7349 Init
:= Make_Defining_Identifier
(Loc
, Make_Init_Proc_Name
(Typ
));
7352 Make_Parameter_Specification
(Loc
,
7353 Defining_Identifier
=>
7354 Make_Defining_Identifier
(Loc
, Name_X
),
7356 New_Reference_To
(Typ
, Loc
)));
7358 if Present
(Parameter_Specifications
(Parent
(E
))) then
7359 P
:= First
(Parameter_Specifications
(Parent
(E
)));
7360 while Present
(P
) loop
7362 Make_Parameter_Specification
(Loc
,
7363 Defining_Identifier
=>
7364 Make_Defining_Identifier
(Loc
,
7365 Chars
(Defining_Identifier
(P
))),
7366 Parameter_Type
=> New_Copy_Tree
(Parameter_Type
(P
))));
7372 Make_Subprogram_Declaration
(Loc
,
7373 Make_Procedure_Specification
(Loc
,
7374 Defining_Unit_Name
=> Init
,
7375 Parameter_Specifications
=> Parms
)));
7377 Set_Init_Proc
(Typ
, Init
);
7378 Set_Is_Imported
(Init
);
7379 Set_Interface_Name
(Init
, Interface_Name
(E
));
7380 Set_Convention
(Init
, Convention_C
);
7381 Set_Is_Public
(Init
);
7382 Set_Has_Completion
(Init
);
7388 -- If there are no constructors, mark the type as abstract since we
7389 -- won't be able to declare objects of that type.
7392 Set_Is_Abstract_Type
(Typ
);
7394 end Set_CPP_Constructors
;
7396 --------------------------
7397 -- Set_DTC_Entity_Value --
7398 --------------------------
7400 procedure Set_DTC_Entity_Value
7401 (Tagged_Type
: Entity_Id
;
7405 if Present
(Interface_Alias
(Prim
))
7406 and then Is_Interface
7407 (Find_Dispatching_Type
(Interface_Alias
(Prim
)))
7409 Set_DTC_Entity
(Prim
,
7412 Iface
=> Find_Dispatching_Type
(Interface_Alias
(Prim
))));
7414 Set_DTC_Entity
(Prim
,
7415 First_Tag_Component
(Tagged_Type
));
7417 end Set_DTC_Entity_Value
;
7423 function Tagged_Kind
(T
: Entity_Id
) return Node_Id
is
7424 Conc_Typ
: Entity_Id
;
7425 Loc
: constant Source_Ptr
:= Sloc
(T
);
7429 (Is_Tagged_Type
(T
) and then RTE_Available
(RE_Tagged_Kind
));
7433 if Is_Abstract_Type
(T
) then
7434 if Is_Limited_Record
(T
) then
7435 return New_Reference_To
(RTE
(RE_TK_Abstract_Limited_Tagged
), Loc
);
7437 return New_Reference_To
(RTE
(RE_TK_Abstract_Tagged
), Loc
);
7442 elsif Is_Concurrent_Record_Type
(T
) then
7443 Conc_Typ
:= Corresponding_Concurrent_Type
(T
);
7445 if Present
(Full_View
(Conc_Typ
)) then
7446 Conc_Typ
:= Full_View
(Conc_Typ
);
7449 if Ekind
(Conc_Typ
) = E_Protected_Type
then
7450 return New_Reference_To
(RTE
(RE_TK_Protected
), Loc
);
7452 pragma Assert
(Ekind
(Conc_Typ
) = E_Task_Type
);
7453 return New_Reference_To
(RTE
(RE_TK_Task
), Loc
);
7456 -- Regular tagged kinds
7459 if Is_Limited_Record
(T
) then
7460 return New_Reference_To
(RTE
(RE_TK_Limited_Tagged
), Loc
);
7462 return New_Reference_To
(RTE
(RE_TK_Tagged
), Loc
);
7471 procedure Write_DT
(Typ
: Entity_Id
) is
7476 -- Protect this procedure against wrong usage. Required because it will
7477 -- be used directly from GDB
7479 if not (Typ
<= Last_Node_Id
)
7480 or else not Is_Tagged_Type
(Typ
)
7482 Write_Str
("wrong usage: Write_DT must be used with tagged types");
7487 Write_Int
(Int
(Typ
));
7489 Write_Name
(Chars
(Typ
));
7491 if Is_Interface
(Typ
) then
7492 Write_Str
(" is interface");
7497 Elmt
:= First_Elmt
(Primitive_Operations
(Typ
));
7498 while Present
(Elmt
) loop
7499 Prim
:= Node
(Elmt
);
7502 -- Indicate if this primitive will be allocated in the primary
7503 -- dispatch table or in a secondary dispatch table associated
7504 -- with an abstract interface type
7506 if Present
(DTC_Entity
(Prim
)) then
7507 if Etype
(DTC_Entity
(Prim
)) = RTE
(RE_Tag
) then
7514 -- Output the node of this primitive operation and its name
7516 Write_Int
(Int
(Prim
));
7519 if Is_Predefined_Dispatching_Operation
(Prim
) then
7520 Write_Str
("(predefined) ");
7523 -- Prefix the name of the primitive with its corresponding tagged
7524 -- type to facilitate seeing inherited primitives.
7526 if Present
(Alias
(Prim
)) then
7528 (Chars
(Find_Dispatching_Type
(Ultimate_Alias
(Prim
))));
7530 Write_Name
(Chars
(Typ
));
7534 Write_Name
(Chars
(Prim
));
7536 -- Indicate if this primitive has an aliased primitive
7538 if Present
(Alias
(Prim
)) then
7539 Write_Str
(" (alias = ");
7540 Write_Int
(Int
(Alias
(Prim
)));
7542 -- If the DTC_Entity attribute is already set we can also output
7543 -- the name of the interface covered by this primitive (if any)
7545 if Present
(DTC_Entity
(Alias
(Prim
)))
7546 and then Is_Interface
(Scope
(DTC_Entity
(Alias
(Prim
))))
7548 Write_Str
(" from interface ");
7549 Write_Name
(Chars
(Scope
(DTC_Entity
(Alias
(Prim
)))));
7552 if Present
(Interface_Alias
(Prim
)) then
7553 Write_Str
(", AI_Alias of ");
7555 (Chars
(Find_Dispatching_Type
(Interface_Alias
(Prim
))));
7557 Write_Int
(Int
(Interface_Alias
(Prim
)));
7563 -- Display the final position of this primitive in its associated
7564 -- (primary or secondary) dispatch table
7566 if Present
(DTC_Entity
(Prim
))
7567 and then DT_Position
(Prim
) /= No_Uint
7569 Write_Str
(" at #");
7570 Write_Int
(UI_To_Int
(DT_Position
(Prim
)));
7573 if Is_Abstract_Subprogram
(Prim
) then
7574 Write_Str
(" is abstract;");
7576 -- Check if this is a null primitive
7578 elsif Comes_From_Source
(Prim
)
7579 and then Ekind
(Prim
) = E_Procedure
7580 and then Null_Present
(Parent
(Prim
))
7582 Write_Str
(" is null;");
7585 if Is_Eliminated
(Ultimate_Alias
(Prim
)) then
7586 Write_Str
(" (eliminated)");