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
;
471 function CPP_Num_Prims
(Typ
: Entity_Id
) return Nat
is
473 Tag_Comp
: Entity_Id
;
476 if not Is_Tagged_Type
(Typ
)
477 or else not Is_CPP_Class
(Root_Type
(Typ
))
482 CPP_Typ
:= Enclosing_CPP_Parent
(Typ
);
483 Tag_Comp
:= First_Tag_Component
(CPP_Typ
);
485 -- If the number of primitives is already set in the tag component
488 if Present
(Tag_Comp
)
489 and then DT_Entry_Count
(Tag_Comp
) /= No_Uint
491 return UI_To_Int
(DT_Entry_Count
(Tag_Comp
));
493 -- Otherwise, count the primitives of the enclosing CPP type
501 Elmt
:= First_Elmt
(Primitive_Operations
(CPP_Typ
));
502 while Present
(Elmt
) loop
513 ------------------------------
514 -- Default_Prim_Op_Position --
515 ------------------------------
517 function Default_Prim_Op_Position
(E
: Entity_Id
) return Uint
is
518 TSS_Name
: TSS_Name_Type
;
521 Get_Name_String
(Chars
(E
));
524 (Name_Buffer
(Name_Len
- TSS_Name
'Length + 1 .. Name_Len
));
526 if Chars
(E
) = Name_uSize
then
529 elsif Chars
(E
) = Name_uAlignment
then
532 elsif TSS_Name
= TSS_Stream_Read
then
535 elsif TSS_Name
= TSS_Stream_Write
then
538 elsif TSS_Name
= TSS_Stream_Input
then
541 elsif TSS_Name
= TSS_Stream_Output
then
544 elsif Chars
(E
) = Name_Op_Eq
then
547 elsif Chars
(E
) = Name_uAssign
then
550 elsif TSS_Name
= TSS_Deep_Adjust
then
553 elsif TSS_Name
= TSS_Deep_Finalize
then
556 elsif Ada_Version
>= Ada_05
then
557 if Chars
(E
) = Name_uDisp_Asynchronous_Select
then
560 elsif Chars
(E
) = Name_uDisp_Conditional_Select
then
563 elsif Chars
(E
) = Name_uDisp_Get_Prim_Op_Kind
then
566 elsif Chars
(E
) = Name_uDisp_Get_Task_Id
then
569 elsif Chars
(E
) = Name_uDisp_Requeue
then
572 elsif Chars
(E
) = Name_uDisp_Timed_Select
then
578 end Default_Prim_Op_Position
;
580 -----------------------------
581 -- Expand_Dispatching_Call --
582 -----------------------------
584 procedure Expand_Dispatching_Call
(Call_Node
: Node_Id
) is
585 Loc
: constant Source_Ptr
:= Sloc
(Call_Node
);
586 Call_Typ
: constant Entity_Id
:= Etype
(Call_Node
);
588 Ctrl_Arg
: constant Node_Id
:= Controlling_Argument
(Call_Node
);
589 Ctrl_Typ
: constant Entity_Id
:= Base_Type
(Etype
(Ctrl_Arg
));
590 Param_List
: constant List_Id
:= Parameter_Associations
(Call_Node
);
595 New_Call_Name
: Node_Id
;
596 New_Params
: List_Id
:= No_List
;
599 Subp_Ptr_Typ
: Entity_Id
;
600 Subp_Typ
: Entity_Id
;
602 Eq_Prim_Op
: Entity_Id
:= Empty
;
603 Controlling_Tag
: Node_Id
;
605 function New_Value
(From
: Node_Id
) return Node_Id
;
606 -- From is the original Expression. New_Value is equivalent to a call
607 -- to Duplicate_Subexpr with an explicit dereference when From is an
614 function New_Value
(From
: Node_Id
) return Node_Id
is
615 Res
: constant Node_Id
:= Duplicate_Subexpr
(From
);
617 if Is_Access_Type
(Etype
(From
)) then
619 Make_Explicit_Dereference
(Sloc
(From
),
630 SCIL_Related_Node
: Node_Id
:= Call_Node
;
632 -- Start of processing for Expand_Dispatching_Call
635 if No_Run_Time_Mode
then
636 Error_Msg_CRT
("tagged types", Call_Node
);
640 -- Expand_Dispatching_Call is called directly from the semantics,
641 -- so we need a check to see whether expansion is active before
642 -- proceeding. In addition, there is no need to expand the call
643 -- if we are compiling under restriction No_Dispatching_Calls;
644 -- the semantic analyzer has previously notified the violation
645 -- of this restriction.
647 if not Expander_Active
648 or else Restriction_Active
(No_Dispatching_Calls
)
653 -- Set subprogram. If this is an inherited operation that was
654 -- overridden, the body that is being called is its alias.
656 Subp
:= Entity
(Name
(Call_Node
));
658 if Present
(Alias
(Subp
))
659 and then Is_Inherited_Operation
(Subp
)
660 and then No
(DTC_Entity
(Subp
))
662 Subp
:= Alias
(Subp
);
665 -- Definition of the class-wide type and the tagged type
667 -- If the controlling argument is itself a tag rather than a tagged
668 -- object, then use the class-wide type associated with the subprogram's
669 -- controlling type. This case can occur when a call to an inherited
670 -- primitive has an actual that originated from a default parameter
671 -- given by a tag-indeterminate call and when there is no other
672 -- controlling argument providing the tag (AI-239 requires dispatching).
673 -- This capability of dispatching directly by tag is also needed by the
674 -- implementation of AI-260 (for the generic dispatching constructors).
676 if Ctrl_Typ
= RTE
(RE_Tag
)
677 or else (RTE_Available
(RE_Interface_Tag
)
678 and then Ctrl_Typ
= RTE
(RE_Interface_Tag
))
680 CW_Typ
:= Class_Wide_Type
(Find_Dispatching_Type
(Subp
));
682 -- Class_Wide_Type is applied to the expressions used to initialize
683 -- CW_Typ, to ensure that CW_Typ always denotes a class-wide type, since
684 -- there are cases where the controlling type is resolved to a specific
685 -- type (such as for designated types of arguments such as CW'Access).
687 elsif Is_Access_Type
(Ctrl_Typ
) then
688 CW_Typ
:= Class_Wide_Type
(Designated_Type
(Ctrl_Typ
));
691 CW_Typ
:= Class_Wide_Type
(Ctrl_Typ
);
694 Typ
:= Root_Type
(CW_Typ
);
696 if Ekind
(Typ
) = E_Incomplete_Type
then
697 Typ
:= Non_Limited_View
(Typ
);
700 if not Is_Limited_Type
(Typ
) then
701 Eq_Prim_Op
:= Find_Prim_Op
(Typ
, Name_Op_Eq
);
704 -- Dispatching call to C++ primitive. Create a new parameter list
705 -- with no tag checks.
707 New_Params
:= New_List
;
709 if Is_CPP_Class
(Typ
) then
710 Param
:= First_Actual
(Call_Node
);
711 while Present
(Param
) loop
712 Append_To
(New_Params
, Relocate_Node
(Param
));
716 -- Dispatching call to Ada primitive
718 elsif Present
(Param_List
) then
719 Apply_Tag_Checks
(Call_Node
);
721 Param
:= First_Actual
(Call_Node
);
722 while Present
(Param
) loop
723 -- Cases in which we may have generated runtime checks
726 or else Subp
= Eq_Prim_Op
728 Append_To
(New_Params
,
729 Duplicate_Subexpr_Move_Checks
(Param
));
731 elsif Nkind
(Parent
(Param
)) /= N_Parameter_Association
732 or else not Is_Accessibility_Actual
(Parent
(Param
))
734 Append_To
(New_Params
, Relocate_Node
(Param
));
741 -- Generate the appropriate subprogram pointer type
743 if Etype
(Subp
) = Typ
then
746 Res_Typ
:= Etype
(Subp
);
749 Subp_Typ
:= Create_Itype
(E_Subprogram_Type
, Call_Node
);
750 Subp_Ptr_Typ
:= Create_Itype
(E_Access_Subprogram_Type
, Call_Node
);
751 Set_Etype
(Subp_Typ
, Res_Typ
);
752 Set_Returns_By_Ref
(Subp_Typ
, Returns_By_Ref
(Subp
));
754 -- Create a new list of parameters which is a copy of the old formal
755 -- list including the creation of a new set of matching entities.
758 Old_Formal
: Entity_Id
:= First_Formal
(Subp
);
759 New_Formal
: Entity_Id
;
760 Extra
: Entity_Id
:= Empty
;
763 if Present
(Old_Formal
) then
764 New_Formal
:= New_Copy
(Old_Formal
);
765 Set_First_Entity
(Subp_Typ
, New_Formal
);
766 Param
:= First_Actual
(Call_Node
);
769 Set_Scope
(New_Formal
, Subp_Typ
);
771 -- Change all the controlling argument types to be class-wide
772 -- to avoid a recursion in dispatching.
774 if Is_Controlling_Formal
(New_Formal
) then
775 Set_Etype
(New_Formal
, Etype
(Param
));
778 -- If the type of the formal is an itype, there was code here
779 -- introduced in 1998 in revision 1.46, to create a new itype
780 -- by copy. This seems useless, and in fact leads to semantic
781 -- errors when the itype is the completion of a type derived
782 -- from a private type.
785 Next_Formal
(Old_Formal
);
786 exit when No
(Old_Formal
);
788 Set_Next_Entity
(New_Formal
, New_Copy
(Old_Formal
));
789 Next_Entity
(New_Formal
);
793 Set_Next_Entity
(New_Formal
, Empty
);
794 Set_Last_Entity
(Subp_Typ
, Extra
);
797 -- Now that the explicit formals have been duplicated, any extra
798 -- formals needed by the subprogram must be created.
800 if Present
(Extra
) then
801 Set_Extra_Formal
(Extra
, Empty
);
804 Create_Extra_Formals
(Subp_Typ
);
807 -- Complete description of pointer type, including size information, as
808 -- must be done with itypes to prevent order-of-elaboration anomalies
811 Set_Etype
(Subp_Ptr_Typ
, Subp_Ptr_Typ
);
812 Set_Directly_Designated_Type
(Subp_Ptr_Typ
, Subp_Typ
);
813 Set_Convention
(Subp_Ptr_Typ
, Convention
(Subp_Typ
));
814 Layout_Type
(Subp_Ptr_Typ
);
816 -- If the controlling argument is a value of type Ada.Tag or an abstract
817 -- interface class-wide type then use it directly. Otherwise, the tag
818 -- must be extracted from the controlling object.
820 if Ctrl_Typ
= RTE
(RE_Tag
)
821 or else (RTE_Available
(RE_Interface_Tag
)
822 and then Ctrl_Typ
= RTE
(RE_Interface_Tag
))
824 Controlling_Tag
:= Duplicate_Subexpr
(Ctrl_Arg
);
826 -- Extract the tag from an unchecked type conversion. Done to avoid
827 -- the expansion of additional code just to obtain the value of such
828 -- tag because the current management of interface type conversions
829 -- generates in some cases this unchecked type conversion with the
830 -- tag of the object (see Expand_Interface_Conversion).
832 elsif Nkind
(Ctrl_Arg
) = N_Unchecked_Type_Conversion
834 (Etype
(Expression
(Ctrl_Arg
)) = RTE
(RE_Tag
)
836 (RTE_Available
(RE_Interface_Tag
)
838 Etype
(Expression
(Ctrl_Arg
)) = RTE
(RE_Interface_Tag
)))
840 Controlling_Tag
:= Duplicate_Subexpr
(Expression
(Ctrl_Arg
));
842 -- Ada 2005 (AI-251): Abstract interface class-wide type
844 elsif Is_Interface
(Ctrl_Typ
)
845 and then Is_Class_Wide_Type
(Ctrl_Typ
)
847 Controlling_Tag
:= Duplicate_Subexpr
(Ctrl_Arg
);
851 Make_Selected_Component
(Loc
,
852 Prefix
=> Duplicate_Subexpr_Move_Checks
(Ctrl_Arg
),
853 Selector_Name
=> New_Reference_To
(DTC_Entity
(Subp
), Loc
));
856 -- Handle dispatching calls to predefined primitives
858 if Is_Predefined_Dispatching_Operation
(Subp
)
859 or else Is_Predefined_Dispatching_Alias
(Subp
)
861 Build_Get_Predefined_Prim_Op_Address
(Loc
,
862 Tag_Node
=> Controlling_Tag
,
863 Position
=> DT_Position
(Subp
),
864 New_Node
=> New_Node
);
866 -- Handle dispatching calls to user-defined primitives
869 Build_Get_Prim_Op_Address
(Loc
,
870 Typ
=> Find_Dispatching_Type
(Subp
),
871 Tag_Node
=> Controlling_Tag
,
872 Position
=> DT_Position
(Subp
),
873 New_Node
=> New_Node
);
877 Unchecked_Convert_To
(Subp_Ptr_Typ
, New_Node
);
879 -- Generate the SCIL node for this dispatching call. Done now because
880 -- attribute SCIL_Controlling_Tag must be set after the new call name
881 -- is built to reference the nodes that will see the SCIL backend
882 -- (because Build_Get_Prim_Op_Address generates an unchecked type
883 -- conversion which relocates the controlling tag node).
885 if Generate_SCIL
then
886 SCIL_Node
:= Make_SCIL_Dispatching_Call
(Sloc
(Call_Node
));
887 Set_SCIL_Entity
(SCIL_Node
, Typ
);
888 Set_SCIL_Target_Prim
(SCIL_Node
, Subp
);
890 -- Common case: the controlling tag is the tag of an object
891 -- (for example, obj.tag)
893 if Nkind
(Controlling_Tag
) = N_Selected_Component
then
894 Set_SCIL_Controlling_Tag
(SCIL_Node
, Controlling_Tag
);
896 -- Handle renaming of selected component
898 elsif Nkind
(Controlling_Tag
) = N_Identifier
899 and then Nkind
(Parent
(Entity
(Controlling_Tag
))) =
900 N_Object_Renaming_Declaration
901 and then Nkind
(Name
(Parent
(Entity
(Controlling_Tag
)))) =
904 Set_SCIL_Controlling_Tag
(SCIL_Node
,
905 Name
(Parent
(Entity
(Controlling_Tag
))));
907 -- If the controlling tag is an identifier, the SCIL node references
908 -- the corresponding object or parameter declaration
910 elsif Nkind
(Controlling_Tag
) = N_Identifier
911 and then Nkind_In
(Parent
(Entity
(Controlling_Tag
)),
912 N_Object_Declaration
,
913 N_Parameter_Specification
)
915 Set_SCIL_Controlling_Tag
(SCIL_Node
,
916 Parent
(Entity
(Controlling_Tag
)));
918 -- If the controlling tag is a dereference, the SCIL node references
919 -- the corresponding object or parameter declaration
921 elsif Nkind
(Controlling_Tag
) = N_Explicit_Dereference
922 and then Nkind
(Prefix
(Controlling_Tag
)) = N_Identifier
923 and then Nkind_In
(Parent
(Entity
(Prefix
(Controlling_Tag
))),
924 N_Object_Declaration
,
925 N_Parameter_Specification
)
927 Set_SCIL_Controlling_Tag
(SCIL_Node
,
928 Parent
(Entity
(Prefix
(Controlling_Tag
))));
930 -- For a direct reference of the tag of the type the SCIL node
931 -- references the the internal object declaration containing the tag
934 elsif Nkind
(Controlling_Tag
) = N_Attribute_Reference
935 and then Attribute_Name
(Controlling_Tag
) = Name_Tag
937 Set_SCIL_Controlling_Tag
(SCIL_Node
,
941 (Access_Disp_Table
(Entity
(Prefix
(Controlling_Tag
)))))));
943 -- Interfaces are not supported. For now we leave the SCIL node
944 -- decorated with the Controlling_Tag. More work needed here???
946 elsif Is_Interface
(Etype
(Controlling_Tag
)) then
947 Set_SCIL_Controlling_Tag
(SCIL_Node
, Controlling_Tag
);
950 pragma Assert
(False);
955 if Nkind
(Call_Node
) = N_Function_Call
then
957 Make_Function_Call
(Loc
,
958 Name
=> New_Call_Name
,
959 Parameter_Associations
=> New_Params
);
961 -- If this is a dispatching "=", we must first compare the tags so
962 -- we generate: x.tag = y.tag and then x = y
964 if Subp
= Eq_Prim_Op
then
965 Param
:= First_Actual
(Call_Node
);
971 Make_Selected_Component
(Loc
,
972 Prefix
=> New_Value
(Param
),
974 New_Reference_To
(First_Tag_Component
(Typ
),
978 Make_Selected_Component
(Loc
,
980 Unchecked_Convert_To
(Typ
,
981 New_Value
(Next_Actual
(Param
))),
984 (First_Tag_Component
(Typ
), Loc
))),
985 Right_Opnd
=> New_Call
);
987 SCIL_Related_Node
:= Right_Opnd
(New_Call
);
992 Make_Procedure_Call_Statement
(Loc
,
993 Name
=> New_Call_Name
,
994 Parameter_Associations
=> New_Params
);
997 -- Register the dispatching call in the call graph nodes table
999 Register_CG_Node
(Call_Node
);
1001 Rewrite
(Call_Node
, New_Call
);
1003 -- Associate the SCIL node of this dispatching call
1005 if Generate_SCIL
then
1006 Set_SCIL_Node
(SCIL_Related_Node
, SCIL_Node
);
1009 -- Suppress all checks during the analysis of the expanded code
1010 -- to avoid the generation of spurious warnings under ZFP run-time.
1012 Analyze_And_Resolve
(Call_Node
, Call_Typ
, Suppress
=> All_Checks
);
1013 end Expand_Dispatching_Call
;
1015 ---------------------------------
1016 -- Expand_Interface_Conversion --
1017 ---------------------------------
1019 procedure Expand_Interface_Conversion
1021 Is_Static
: Boolean := True)
1023 Loc
: constant Source_Ptr
:= Sloc
(N
);
1024 Etyp
: constant Entity_Id
:= Etype
(N
);
1025 Operand
: constant Node_Id
:= Expression
(N
);
1026 Operand_Typ
: Entity_Id
:= Etype
(Operand
);
1028 Iface_Typ
: Entity_Id
:= Etype
(N
);
1029 Iface_Tag
: Entity_Id
;
1032 -- Ada 2005 (AI-345): Handle synchronized interface type derivations
1034 if Is_Concurrent_Type
(Operand_Typ
) then
1035 Operand_Typ
:= Base_Type
(Corresponding_Record_Type
(Operand_Typ
));
1038 -- Handle access to class-wide interface types
1040 if Is_Access_Type
(Iface_Typ
) then
1041 Iface_Typ
:= Etype
(Directly_Designated_Type
(Iface_Typ
));
1044 -- Handle class-wide interface types. This conversion can appear
1045 -- explicitly in the source code. Example: I'Class (Obj)
1047 if Is_Class_Wide_Type
(Iface_Typ
) then
1048 Iface_Typ
:= Root_Type
(Iface_Typ
);
1051 -- If the target type is a tagged synchronized type, the dispatch table
1052 -- info is in the corresponding record type.
1054 if Is_Concurrent_Type
(Iface_Typ
) then
1055 Iface_Typ
:= Corresponding_Record_Type
(Iface_Typ
);
1058 -- Freeze the entity associated with the target interface to have
1059 -- available the attribute Access_Disp_Table.
1061 Freeze_Before
(N
, Iface_Typ
);
1063 pragma Assert
(not Is_Static
1064 or else (not Is_Class_Wide_Type
(Iface_Typ
)
1065 and then Is_Interface
(Iface_Typ
)));
1067 if not Tagged_Type_Expansion
then
1069 -- For VM, just do a conversion ???
1071 Rewrite
(N
, Unchecked_Convert_To
(Etype
(N
), N
));
1076 if not Is_Static
then
1078 -- Give error if configurable run time and Displace not available
1080 if not RTE_Available
(RE_Displace
) then
1081 Error_Msg_CRT
("dynamic interface conversion", N
);
1085 -- Handle conversion of access-to-class-wide interface types. Target
1086 -- can be an access to an object or an access to another class-wide
1087 -- interface (see -1- and -2- in the following example):
1089 -- type Iface1_Ref is access all Iface1'Class;
1090 -- type Iface2_Ref is access all Iface1'Class;
1092 -- Acc1 : Iface1_Ref := new ...
1093 -- Obj : Obj_Ref := Obj_Ref (Acc); -- 1
1094 -- Acc2 : Iface2_Ref := Iface2_Ref (Acc); -- 2
1096 if Is_Access_Type
(Operand_Typ
) then
1098 Unchecked_Convert_To
(Etype
(N
),
1099 Make_Function_Call
(Loc
,
1100 Name
=> New_Reference_To
(RTE
(RE_Displace
), Loc
),
1101 Parameter_Associations
=> New_List
(
1103 Unchecked_Convert_To
(RTE
(RE_Address
),
1104 Relocate_Node
(Expression
(N
))),
1107 (Node
(First_Elmt
(Access_Disp_Table
(Iface_Typ
))),
1115 Make_Function_Call
(Loc
,
1116 Name
=> New_Reference_To
(RTE
(RE_Displace
), Loc
),
1117 Parameter_Associations
=> New_List
(
1118 Make_Attribute_Reference
(Loc
,
1119 Prefix
=> Relocate_Node
(Expression
(N
)),
1120 Attribute_Name
=> Name_Address
),
1123 (Node
(First_Elmt
(Access_Disp_Table
(Iface_Typ
))),
1128 -- If the target is a class-wide interface we change the type of the
1129 -- data returned by IW_Convert to indicate that this is a dispatching
1133 New_Itype
: Entity_Id
;
1136 New_Itype
:= Create_Itype
(E_Anonymous_Access_Type
, N
);
1137 Set_Etype
(New_Itype
, New_Itype
);
1138 Set_Directly_Designated_Type
(New_Itype
, Etyp
);
1141 Make_Explicit_Dereference
(Loc
,
1143 Unchecked_Convert_To
(New_Itype
, Relocate_Node
(N
))));
1145 Freeze_Itype
(New_Itype
, N
);
1151 Iface_Tag
:= Find_Interface_Tag
(Operand_Typ
, Iface_Typ
);
1152 pragma Assert
(Iface_Tag
/= Empty
);
1154 -- Keep separate access types to interfaces because one internal
1155 -- function is used to handle the null value (see following comment)
1157 if not Is_Access_Type
(Etype
(N
)) then
1159 Unchecked_Convert_To
(Etype
(N
),
1160 Make_Selected_Component
(Loc
,
1161 Prefix
=> Relocate_Node
(Expression
(N
)),
1163 New_Occurrence_Of
(Iface_Tag
, Loc
))));
1166 -- Build internal function to handle the case in which the
1167 -- actual is null. If the actual is null returns null because
1168 -- no displacement is required; otherwise performs a type
1169 -- conversion that will be expanded in the code that returns
1170 -- the value of the displaced actual. That is:
1172 -- function Func (O : Address) return Iface_Typ is
1173 -- type Op_Typ is access all Operand_Typ;
1174 -- Aux : Op_Typ := To_Op_Typ (O);
1176 -- if O = Null_Address then
1179 -- return Iface_Typ!(Aux.Iface_Tag'Address);
1184 Desig_Typ
: Entity_Id
;
1186 New_Typ_Decl
: Node_Id
;
1190 Desig_Typ
:= Etype
(Expression
(N
));
1192 if Is_Access_Type
(Desig_Typ
) then
1194 Available_View
(Directly_Designated_Type
(Desig_Typ
));
1197 if Is_Concurrent_Type
(Desig_Typ
) then
1198 Desig_Typ
:= Base_Type
(Corresponding_Record_Type
(Desig_Typ
));
1202 Make_Full_Type_Declaration
(Loc
,
1203 Defining_Identifier
=> Make_Temporary
(Loc
, 'T'),
1205 Make_Access_To_Object_Definition
(Loc
,
1206 All_Present
=> True,
1207 Null_Exclusion_Present
=> False,
1208 Constant_Present
=> False,
1209 Subtype_Indication
=>
1210 New_Reference_To
(Desig_Typ
, Loc
)));
1213 Make_Simple_Return_Statement
(Loc
,
1214 Unchecked_Convert_To
(Etype
(N
),
1215 Make_Attribute_Reference
(Loc
,
1217 Make_Selected_Component
(Loc
,
1219 Unchecked_Convert_To
1220 (Defining_Identifier
(New_Typ_Decl
),
1221 Make_Identifier
(Loc
, Name_uO
)),
1223 New_Occurrence_Of
(Iface_Tag
, Loc
)),
1224 Attribute_Name
=> Name_Address
))));
1226 -- If the type is null-excluding, no need for the null branch.
1227 -- Otherwise we need to check for it and return null.
1229 if not Can_Never_Be_Null
(Etype
(N
)) then
1231 Make_If_Statement
(Loc
,
1234 Left_Opnd
=> Make_Identifier
(Loc
, Name_uO
),
1235 Right_Opnd
=> New_Reference_To
1236 (RTE
(RE_Null_Address
), Loc
)),
1238 Then_Statements
=> New_List
(
1239 Make_Simple_Return_Statement
(Loc
,
1241 Else_Statements
=> Stats
));
1244 Fent
:= Make_Temporary
(Loc
, 'F');
1246 Make_Subprogram_Body
(Loc
,
1248 Make_Function_Specification
(Loc
,
1249 Defining_Unit_Name
=> Fent
,
1251 Parameter_Specifications
=> New_List
(
1252 Make_Parameter_Specification
(Loc
,
1253 Defining_Identifier
=>
1254 Make_Defining_Identifier
(Loc
, Name_uO
),
1256 New_Reference_To
(RTE
(RE_Address
), Loc
))),
1258 Result_Definition
=>
1259 New_Reference_To
(Etype
(N
), Loc
)),
1261 Declarations
=> New_List
(New_Typ_Decl
),
1263 Handled_Statement_Sequence
=>
1264 Make_Handled_Sequence_Of_Statements
(Loc
, Stats
));
1266 -- Place function body before the expression containing the
1267 -- conversion. We suppress all checks because the body of the
1268 -- internally generated function already takes care of the case
1269 -- in which the actual is null; therefore there is no need to
1270 -- double check that the pointer is not null when the program
1271 -- executes the alternative that performs the type conversion).
1273 Insert_Action
(N
, Func
, Suppress
=> All_Checks
);
1275 if Is_Access_Type
(Etype
(Expression
(N
))) then
1277 -- Generate: Func (Address!(Expression))
1280 Make_Function_Call
(Loc
,
1281 Name
=> New_Reference_To
(Fent
, Loc
),
1282 Parameter_Associations
=> New_List
(
1283 Unchecked_Convert_To
(RTE
(RE_Address
),
1284 Relocate_Node
(Expression
(N
))))));
1287 -- Generate: Func (Operand_Typ!(Expression)'Address)
1290 Make_Function_Call
(Loc
,
1291 Name
=> New_Reference_To
(Fent
, Loc
),
1292 Parameter_Associations
=> New_List
(
1293 Make_Attribute_Reference
(Loc
,
1294 Prefix
=> Unchecked_Convert_To
(Operand_Typ
,
1295 Relocate_Node
(Expression
(N
))),
1296 Attribute_Name
=> Name_Address
))));
1302 end Expand_Interface_Conversion
;
1304 ------------------------------
1305 -- Expand_Interface_Actuals --
1306 ------------------------------
1308 procedure Expand_Interface_Actuals
(Call_Node
: Node_Id
) is
1310 Actual_Dup
: Node_Id
;
1311 Actual_Typ
: Entity_Id
;
1313 Conversion
: Node_Id
;
1315 Formal_Typ
: Entity_Id
;
1317 Formal_DDT
: Entity_Id
;
1318 Actual_DDT
: Entity_Id
;
1321 -- This subprogram is called directly from the semantics, so we need a
1322 -- check to see whether expansion is active before proceeding.
1324 if not Expander_Active
then
1328 -- Call using access to subprogram with explicit dereference
1330 if Nkind
(Name
(Call_Node
)) = N_Explicit_Dereference
then
1331 Subp
:= Etype
(Name
(Call_Node
));
1333 -- Call using selected component
1335 elsif Nkind
(Name
(Call_Node
)) = N_Selected_Component
then
1336 Subp
:= Entity
(Selector_Name
(Name
(Call_Node
)));
1338 -- Call using direct name
1341 Subp
:= Entity
(Name
(Call_Node
));
1344 -- Ada 2005 (AI-251): Look for interface type formals to force "this"
1347 Formal
:= First_Formal
(Subp
);
1348 Actual
:= First_Actual
(Call_Node
);
1349 while Present
(Formal
) loop
1350 Formal_Typ
:= Etype
(Formal
);
1352 if Ekind
(Formal_Typ
) = E_Record_Type_With_Private
then
1353 Formal_Typ
:= Full_View
(Formal_Typ
);
1356 if Is_Access_Type
(Formal_Typ
) then
1357 Formal_DDT
:= Directly_Designated_Type
(Formal_Typ
);
1360 Actual_Typ
:= Etype
(Actual
);
1362 if Is_Access_Type
(Actual_Typ
) then
1363 Actual_DDT
:= Directly_Designated_Type
(Actual_Typ
);
1366 if Is_Interface
(Formal_Typ
)
1367 and then Is_Class_Wide_Type
(Formal_Typ
)
1369 -- No need to displace the pointer if the type of the actual
1370 -- coindices with the type of the formal.
1372 if Actual_Typ
= Formal_Typ
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_Typ
, Actual_Typ
) then
1382 -- Implicit conversion to the class-wide formal type to force
1383 -- the displacement of the pointer.
1386 Conversion
:= Convert_To
(Formal_Typ
, Relocate_Node
(Actual
));
1387 Rewrite
(Actual
, Conversion
);
1388 Analyze_And_Resolve
(Actual
, Formal_Typ
);
1391 -- Access to class-wide interface type
1393 elsif Is_Access_Type
(Formal_Typ
)
1394 and then Is_Interface
(Formal_DDT
)
1395 and then Is_Class_Wide_Type
(Formal_DDT
)
1396 and then Interface_Present_In_Ancestor
1398 Iface
=> Etype
(Formal_DDT
))
1400 -- Handle attributes 'Access and 'Unchecked_Access
1402 if Nkind
(Actual
) = N_Attribute_Reference
1404 (Attribute_Name
(Actual
) = Name_Access
1405 or else Attribute_Name
(Actual
) = Name_Unchecked_Access
)
1407 -- This case must have been handled by the analysis and
1408 -- expansion of 'Access. The only exception is when types
1409 -- match and no further expansion is required.
1411 pragma Assert
(Base_Type
(Etype
(Prefix
(Actual
)))
1412 = Base_Type
(Formal_DDT
));
1415 -- No need to displace the pointer if the type of the actual
1416 -- coincides with the type of the formal.
1418 elsif Actual_DDT
= Formal_DDT
then
1421 -- No need to displace the pointer if the interface type is
1422 -- a parent of the type of the actual because in this case the
1423 -- interface primitives are located in the primary dispatch table.
1425 elsif Is_Ancestor
(Formal_DDT
, Actual_DDT
) then
1429 Actual_Dup
:= Relocate_Node
(Actual
);
1431 if From_With_Type
(Actual_Typ
) then
1433 -- If the type of the actual parameter comes from a limited
1434 -- with-clause and the non-limited view is already available
1435 -- we replace the anonymous access type by a duplicate
1436 -- declaration whose designated type is the non-limited view
1438 if Ekind
(Actual_DDT
) = E_Incomplete_Type
1439 and then Present
(Non_Limited_View
(Actual_DDT
))
1441 Anon
:= New_Copy
(Actual_Typ
);
1443 if Is_Itype
(Anon
) then
1444 Set_Scope
(Anon
, Current_Scope
);
1447 Set_Directly_Designated_Type
(Anon
,
1448 Non_Limited_View
(Actual_DDT
));
1449 Set_Etype
(Actual_Dup
, Anon
);
1451 elsif Is_Class_Wide_Type
(Actual_DDT
)
1452 and then Ekind
(Etype
(Actual_DDT
)) = E_Incomplete_Type
1453 and then Present
(Non_Limited_View
(Etype
(Actual_DDT
)))
1455 Anon
:= New_Copy
(Actual_Typ
);
1457 if Is_Itype
(Anon
) then
1458 Set_Scope
(Anon
, Current_Scope
);
1461 Set_Directly_Designated_Type
(Anon
,
1462 New_Copy
(Actual_DDT
));
1463 Set_Class_Wide_Type
(Directly_Designated_Type
(Anon
),
1464 New_Copy
(Class_Wide_Type
(Actual_DDT
)));
1465 Set_Etype
(Directly_Designated_Type
(Anon
),
1466 Non_Limited_View
(Etype
(Actual_DDT
)));
1468 Class_Wide_Type
(Directly_Designated_Type
(Anon
)),
1469 Non_Limited_View
(Etype
(Actual_DDT
)));
1470 Set_Etype
(Actual_Dup
, Anon
);
1474 Conversion
:= Convert_To
(Formal_Typ
, Actual_Dup
);
1475 Rewrite
(Actual
, Conversion
);
1476 Analyze_And_Resolve
(Actual
, Formal_Typ
);
1480 Next_Actual
(Actual
);
1481 Next_Formal
(Formal
);
1483 end Expand_Interface_Actuals
;
1485 ----------------------------
1486 -- Expand_Interface_Thunk --
1487 ----------------------------
1489 procedure Expand_Interface_Thunk
1491 Thunk_Id
: out Entity_Id
;
1492 Thunk_Code
: out Node_Id
)
1494 Loc
: constant Source_Ptr
:= Sloc
(Prim
);
1495 Actuals
: constant List_Id
:= New_List
;
1496 Decl
: constant List_Id
:= New_List
;
1497 Formals
: constant List_Id
:= New_List
;
1498 Target
: constant Entity_Id
:= Ultimate_Alias
(Prim
);
1500 Controlling_Typ
: Entity_Id
;
1506 Iface_Formal
: Node_Id
;
1508 Offset_To_Top
: Node_Id
;
1509 Target_Formal
: Entity_Id
;
1513 Thunk_Code
:= Empty
;
1515 -- No thunk needed if the primitive has been eliminated
1517 if Is_Eliminated
(Ultimate_Alias
(Prim
)) then
1520 -- In case of primitives that are functions without formals and a
1521 -- controlling result there is no need to build the thunk.
1523 elsif not Present
(First_Formal
(Target
)) then
1524 pragma Assert
(Ekind
(Target
) = E_Function
1525 and then Has_Controlling_Result
(Target
));
1529 -- Duplicate the formals of the Target primitive. In the thunk, the type
1530 -- of the controlling formal is the covered interface type (instead of
1531 -- the target tagged type). Done to avoid problems with discriminated
1532 -- tagged types because, if the controlling type has discriminants with
1533 -- default values, then the type conversions done inside the body of
1534 -- the thunk (after the displacement of the pointer to the base of the
1535 -- actual object) generate code that modify its contents.
1537 -- Note: This special management is not done for predefined primitives
1540 if not Is_Predefined_Dispatching_Operation
(Prim
) then
1541 Iface_Formal
:= First_Formal
(Interface_Alias
(Prim
));
1544 Formal
:= First_Formal
(Target
);
1545 while Present
(Formal
) loop
1546 Ftyp
:= Etype
(Formal
);
1548 -- Use the interface type as the type of the controlling formal (see
1551 if not Is_Controlling_Formal
(Formal
)
1552 or else Is_Predefined_Dispatching_Operation
(Prim
)
1554 Ftyp
:= Etype
(Formal
);
1555 Expr
:= New_Copy_Tree
(Expression
(Parent
(Formal
)));
1557 Ftyp
:= Etype
(Iface_Formal
);
1562 Make_Parameter_Specification
(Loc
,
1563 Defining_Identifier
=>
1564 Make_Defining_Identifier
(Sloc
(Formal
),
1565 Chars
=> Chars
(Formal
)),
1566 In_Present
=> In_Present
(Parent
(Formal
)),
1567 Out_Present
=> Out_Present
(Parent
(Formal
)),
1568 Parameter_Type
=> New_Reference_To
(Ftyp
, Loc
),
1569 Expression
=> Expr
));
1571 if not Is_Predefined_Dispatching_Operation
(Prim
) then
1572 Next_Formal
(Iface_Formal
);
1575 Next_Formal
(Formal
);
1578 Controlling_Typ
:= Find_Dispatching_Type
(Target
);
1580 Target_Formal
:= First_Formal
(Target
);
1581 Formal
:= First
(Formals
);
1582 while Present
(Formal
) loop
1584 -- If the parent is a constrained discriminated type, then the
1585 -- primitive operation will have been defined on a first subtype.
1586 -- For proper matching with controlling type, use base type.
1588 if Ekind
(Target_Formal
) = E_In_Parameter
1589 and then Ekind
(Etype
(Target_Formal
)) = E_Anonymous_Access_Type
1592 Base_Type
(Directly_Designated_Type
(Etype
(Target_Formal
)));
1594 Ftyp
:= Base_Type
(Etype
(Target_Formal
));
1597 -- For concurrent types, the relevant information is found in the
1598 -- Corresponding_Record_Type, rather than the type entity itself.
1600 if Is_Concurrent_Type
(Ftyp
) then
1601 Ftyp
:= Corresponding_Record_Type
(Ftyp
);
1604 if Ekind
(Target_Formal
) = E_In_Parameter
1605 and then Ekind
(Etype
(Target_Formal
)) = E_Anonymous_Access_Type
1606 and then Ftyp
= Controlling_Typ
1609 -- type T is access all <<type of the target formal>>
1610 -- S : Storage_Offset := Storage_Offset!(Formal)
1611 -- - Offset_To_Top (address!(Formal))
1614 Make_Full_Type_Declaration
(Loc
,
1615 Defining_Identifier
=> Make_Temporary
(Loc
, 'T'),
1617 Make_Access_To_Object_Definition
(Loc
,
1618 All_Present
=> True,
1619 Null_Exclusion_Present
=> False,
1620 Constant_Present
=> False,
1621 Subtype_Indication
=>
1622 New_Reference_To
(Ftyp
, Loc
)));
1625 Unchecked_Convert_To
(RTE
(RE_Address
),
1626 New_Reference_To
(Defining_Identifier
(Formal
), Loc
));
1628 if not RTE_Available
(RE_Offset_To_Top
) then
1630 Build_Offset_To_Top
(Loc
, New_Arg
);
1633 Make_Function_Call
(Loc
,
1634 Name
=> New_Reference_To
(RTE
(RE_Offset_To_Top
), Loc
),
1635 Parameter_Associations
=> New_List
(New_Arg
));
1639 Make_Object_Declaration
(Loc
,
1640 Defining_Identifier
=> Make_Temporary
(Loc
, 'S'),
1641 Constant_Present
=> True,
1642 Object_Definition
=>
1643 New_Reference_To
(RTE
(RE_Storage_Offset
), Loc
),
1645 Make_Op_Subtract
(Loc
,
1647 Unchecked_Convert_To
1648 (RTE
(RE_Storage_Offset
),
1649 New_Reference_To
(Defining_Identifier
(Formal
), Loc
)),
1653 Append_To
(Decl
, Decl_2
);
1654 Append_To
(Decl
, Decl_1
);
1656 -- Reference the new actual. Generate:
1660 Unchecked_Convert_To
1661 (Defining_Identifier
(Decl_2
),
1662 New_Reference_To
(Defining_Identifier
(Decl_1
), Loc
)));
1664 elsif Ftyp
= Controlling_Typ
then
1667 -- S1 : Storage_Offset := Storage_Offset!(Formal'Address)
1668 -- - Offset_To_Top (Formal'Address)
1669 -- S2 : Addr_Ptr := Addr_Ptr!(S1)
1672 Make_Attribute_Reference
(Loc
,
1674 New_Reference_To
(Defining_Identifier
(Formal
), Loc
),
1678 if not RTE_Available
(RE_Offset_To_Top
) then
1680 Build_Offset_To_Top
(Loc
, New_Arg
);
1683 Make_Function_Call
(Loc
,
1684 Name
=> New_Reference_To
(RTE
(RE_Offset_To_Top
), Loc
),
1685 Parameter_Associations
=> New_List
(New_Arg
));
1689 Make_Object_Declaration
(Loc
,
1690 Defining_Identifier
=> Make_Temporary
(Loc
, 'S'),
1691 Constant_Present
=> True,
1692 Object_Definition
=>
1693 New_Reference_To
(RTE
(RE_Storage_Offset
), Loc
),
1695 Make_Op_Subtract
(Loc
,
1697 Unchecked_Convert_To
1698 (RTE
(RE_Storage_Offset
),
1699 Make_Attribute_Reference
(Loc
,
1702 (Defining_Identifier
(Formal
), Loc
),
1703 Attribute_Name
=> Name_Address
)),
1708 Make_Object_Declaration
(Loc
,
1709 Defining_Identifier
=> Make_Temporary
(Loc
, 'S'),
1710 Constant_Present
=> True,
1711 Object_Definition
=>
1712 New_Reference_To
(RTE
(RE_Addr_Ptr
), Loc
),
1714 Unchecked_Convert_To
1716 New_Reference_To
(Defining_Identifier
(Decl_1
), Loc
)));
1718 Append_To
(Decl
, Decl_1
);
1719 Append_To
(Decl
, Decl_2
);
1721 -- Reference the new actual, generate:
1722 -- Target_Formal (S2.all)
1725 Unchecked_Convert_To
(Ftyp
,
1726 Make_Explicit_Dereference
(Loc
,
1727 New_Reference_To
(Defining_Identifier
(Decl_2
), Loc
))));
1729 -- No special management required for this actual
1733 New_Reference_To
(Defining_Identifier
(Formal
), Loc
));
1736 Next_Formal
(Target_Formal
);
1740 Thunk_Id
:= Make_Temporary
(Loc
, 'T');
1741 Set_Is_Thunk
(Thunk_Id
);
1745 if Ekind
(Target
) = E_Procedure
then
1747 Make_Subprogram_Body
(Loc
,
1749 Make_Procedure_Specification
(Loc
,
1750 Defining_Unit_Name
=> Thunk_Id
,
1751 Parameter_Specifications
=> Formals
),
1752 Declarations
=> Decl
,
1753 Handled_Statement_Sequence
=>
1754 Make_Handled_Sequence_Of_Statements
(Loc
,
1755 Statements
=> New_List
(
1756 Make_Procedure_Call_Statement
(Loc
,
1757 Name
=> New_Occurrence_Of
(Target
, Loc
),
1758 Parameter_Associations
=> Actuals
))));
1762 else pragma Assert
(Ekind
(Target
) = E_Function
);
1764 Make_Subprogram_Body
(Loc
,
1766 Make_Function_Specification
(Loc
,
1767 Defining_Unit_Name
=> Thunk_Id
,
1768 Parameter_Specifications
=> Formals
,
1769 Result_Definition
=>
1770 New_Copy
(Result_Definition
(Parent
(Target
)))),
1771 Declarations
=> Decl
,
1772 Handled_Statement_Sequence
=>
1773 Make_Handled_Sequence_Of_Statements
(Loc
,
1774 Statements
=> New_List
(
1775 Make_Simple_Return_Statement
(Loc
,
1776 Make_Function_Call
(Loc
,
1777 Name
=> New_Occurrence_Of
(Target
, Loc
),
1778 Parameter_Associations
=> Actuals
)))));
1780 end Expand_Interface_Thunk
;
1782 --------------------------
1783 -- Has_CPP_Constructors --
1784 --------------------------
1786 function Has_CPP_Constructors
(Typ
: Entity_Id
) return Boolean is
1790 -- Look for the constructor entities
1792 E
:= Next_Entity
(Typ
);
1793 while Present
(E
) loop
1794 if Ekind
(E
) = E_Function
1795 and then Is_Constructor
(E
)
1804 end Has_CPP_Constructors
;
1810 function Has_DT
(Typ
: Entity_Id
) return Boolean is
1812 return not Is_Interface
(Typ
)
1813 and then not Restriction_Active
(No_Dispatching_Calls
);
1816 -----------------------------------------
1817 -- Is_Predefined_Dispatching_Operation --
1818 -----------------------------------------
1820 function Is_Predefined_Dispatching_Operation
1821 (E
: Entity_Id
) return Boolean
1823 TSS_Name
: TSS_Name_Type
;
1826 if not Is_Dispatching_Operation
(E
) then
1830 Get_Name_String
(Chars
(E
));
1832 -- Most predefined primitives have internally generated names. Equality
1833 -- must be treated differently; the predefined operation is recognized
1834 -- as a homogeneous binary operator that returns Boolean.
1836 if Name_Len
> TSS_Name_Type
'Last then
1837 TSS_Name
:= TSS_Name_Type
(Name_Buffer
(Name_Len
- TSS_Name
'Length + 1
1839 if Chars
(E
) = Name_uSize
1840 or else Chars
(E
) = Name_uAlignment
1841 or else TSS_Name
= TSS_Stream_Read
1842 or else TSS_Name
= TSS_Stream_Write
1843 or else TSS_Name
= TSS_Stream_Input
1844 or else TSS_Name
= TSS_Stream_Output
1846 (Chars
(E
) = Name_Op_Eq
1847 and then Etype
(First_Formal
(E
)) = Etype
(Last_Formal
(E
)))
1848 or else Chars
(E
) = Name_uAssign
1849 or else TSS_Name
= TSS_Deep_Adjust
1850 or else TSS_Name
= TSS_Deep_Finalize
1851 or else Is_Predefined_Interface_Primitive
(E
)
1858 end Is_Predefined_Dispatching_Operation
;
1860 ---------------------------------------
1861 -- Is_Predefined_Internal_Operation --
1862 ---------------------------------------
1864 function Is_Predefined_Internal_Operation
1865 (E
: Entity_Id
) return Boolean
1867 TSS_Name
: TSS_Name_Type
;
1870 if not Is_Dispatching_Operation
(E
) then
1874 Get_Name_String
(Chars
(E
));
1876 -- Most predefined primitives have internally generated names. Equality
1877 -- must be treated differently; the predefined operation is recognized
1878 -- as a homogeneous binary operator that returns Boolean.
1880 if Name_Len
> TSS_Name_Type
'Last then
1883 (Name_Buffer
(Name_Len
- TSS_Name
'Length + 1 .. Name_Len
));
1885 if Chars
(E
) = Name_uSize
1886 or else Chars
(E
) = Name_uAlignment
1888 (Chars
(E
) = Name_Op_Eq
1889 and then Etype
(First_Formal
(E
)) = Etype
(Last_Formal
(E
)))
1890 or else Chars
(E
) = Name_uAssign
1891 or else TSS_Name
= TSS_Deep_Adjust
1892 or else TSS_Name
= TSS_Deep_Finalize
1893 or else Is_Predefined_Interface_Primitive
(E
)
1900 end Is_Predefined_Internal_Operation
;
1902 -------------------------------------
1903 -- Is_Predefined_Dispatching_Alias --
1904 -------------------------------------
1906 function Is_Predefined_Dispatching_Alias
(Prim
: Entity_Id
) return Boolean
1909 return not Is_Predefined_Dispatching_Operation
(Prim
)
1910 and then Present
(Alias
(Prim
))
1911 and then Is_Predefined_Dispatching_Operation
(Ultimate_Alias
(Prim
));
1912 end Is_Predefined_Dispatching_Alias
;
1914 ---------------------------------------
1915 -- Is_Predefined_Interface_Primitive --
1916 ---------------------------------------
1918 function Is_Predefined_Interface_Primitive
(E
: Entity_Id
) return Boolean is
1920 return Ada_Version
>= Ada_05
1921 and then (Chars
(E
) = Name_uDisp_Asynchronous_Select
or else
1922 Chars
(E
) = Name_uDisp_Conditional_Select
or else
1923 Chars
(E
) = Name_uDisp_Get_Prim_Op_Kind
or else
1924 Chars
(E
) = Name_uDisp_Get_Task_Id
or else
1925 Chars
(E
) = Name_uDisp_Requeue
or else
1926 Chars
(E
) = Name_uDisp_Timed_Select
);
1927 end Is_Predefined_Interface_Primitive
;
1929 ----------------------------------------
1930 -- Make_Disp_Asynchronous_Select_Body --
1931 ----------------------------------------
1933 -- For interface types, generate:
1935 -- procedure _Disp_Asynchronous_Select
1936 -- (T : in out <Typ>;
1938 -- P : System.Address;
1939 -- B : out System.Storage_Elements.Dummy_Communication_Block;
1944 -- end _Disp_Asynchronous_Select;
1946 -- For protected types, generate:
1948 -- procedure _Disp_Asynchronous_Select
1949 -- (T : in out <Typ>;
1951 -- P : System.Address;
1952 -- B : out System.Storage_Elements.Dummy_Communication_Block;
1956 -- Ada.Tags.Get_Entry_Index (Ada.Tags.Tag (<Typ>VP, S));
1957 -- Bnn : System.Tasking.Protected_Objects.Operations.
1958 -- Communication_Block;
1960 -- System.Tasking.Protected_Objects.Operations.Protected_Entry_Call
1961 -- (T._object'Access,
1962 -- System.Tasking.Protected_Objects.Protected_Entry_Index (I),
1964 -- System.Tasking.Asynchronous_Call,
1966 -- B := System.Storage_Elements.Dummy_Communication_Block (Bnn);
1967 -- end _Disp_Asynchronous_Select;
1969 -- For task types, generate:
1971 -- procedure _Disp_Asynchronous_Select
1972 -- (T : in out <Typ>;
1974 -- P : System.Address;
1975 -- B : out System.Storage_Elements.Dummy_Communication_Block;
1979 -- Ada.Tags.Get_Entry_Index (Ada.Tags.Tag (<Typ>VP, S));
1981 -- System.Tasking.Rendezvous.Task_Entry_Call
1983 -- System.Tasking.Task_Entry_Index (I),
1985 -- System.Tasking.Asynchronous_Call,
1987 -- end _Disp_Asynchronous_Select;
1989 function Make_Disp_Asynchronous_Select_Body
1990 (Typ
: Entity_Id
) return Node_Id
1992 Com_Block
: Entity_Id
;
1993 Conc_Typ
: Entity_Id
:= Empty
;
1994 Decls
: constant List_Id
:= New_List
;
1996 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
1998 Stmts
: constant List_Id
:= New_List
;
2001 pragma Assert
(not Restriction_Active
(No_Dispatching_Calls
));
2003 -- Null body is generated for interface types
2005 if Is_Interface
(Typ
) then
2007 Make_Subprogram_Body
(Loc
,
2009 Make_Disp_Asynchronous_Select_Spec
(Typ
),
2012 Handled_Statement_Sequence
=>
2013 Make_Handled_Sequence_Of_Statements
(Loc
,
2014 New_List
(Make_Null_Statement
(Loc
))));
2017 DT_Ptr
:= Node
(First_Elmt
(Access_Disp_Table
(Typ
)));
2019 if Is_Concurrent_Record_Type
(Typ
) then
2020 Conc_Typ
:= Corresponding_Concurrent_Type
(Typ
);
2024 -- Ada.Tags.Get_Entry_Index (Ada.Tags.Tag! (<type>VP), S);
2026 -- where I will be used to capture the entry index of the primitive
2027 -- wrapper at position S.
2030 Make_Object_Declaration
(Loc
,
2031 Defining_Identifier
=>
2032 Make_Defining_Identifier
(Loc
, Name_uI
),
2033 Object_Definition
=>
2034 New_Reference_To
(Standard_Integer
, Loc
),
2036 Make_Function_Call
(Loc
,
2038 New_Reference_To
(RTE
(RE_Get_Entry_Index
), Loc
),
2039 Parameter_Associations
=>
2041 Unchecked_Convert_To
(RTE
(RE_Tag
),
2042 New_Reference_To
(DT_Ptr
, Loc
)),
2043 Make_Identifier
(Loc
, Name_uS
)))));
2045 if Ekind
(Conc_Typ
) = E_Protected_Type
then
2048 -- Bnn : Communication_Block;
2050 Com_Block
:= Make_Temporary
(Loc
, 'B');
2052 Make_Object_Declaration
(Loc
,
2053 Defining_Identifier
=>
2055 Object_Definition
=>
2056 New_Reference_To
(RTE
(RE_Communication_Block
), Loc
)));
2058 -- Build T._object'Access for calls below
2061 Make_Attribute_Reference
(Loc
,
2062 Attribute_Name
=> Name_Unchecked_Access
,
2064 Make_Selected_Component
(Loc
,
2065 Prefix
=> Make_Identifier
(Loc
, Name_uT
),
2066 Selector_Name
=> Make_Identifier
(Loc
, Name_uObject
)));
2068 case Corresponding_Runtime_Package
(Conc_Typ
) is
2069 when System_Tasking_Protected_Objects_Entries
=>
2072 -- Protected_Entry_Call
2073 -- (T._object'Access, -- Object
2074 -- Protected_Entry_Index! (I), -- E
2075 -- P, -- Uninterpreted_Data
2076 -- Asynchronous_Call, -- Mode
2077 -- Bnn); -- Communication_Block
2079 -- where T is the protected object, I is the entry index, P
2080 -- is the wrapped parameters and B is the name of the
2081 -- communication block.
2084 Make_Procedure_Call_Statement
(Loc
,
2086 New_Reference_To
(RTE
(RE_Protected_Entry_Call
), Loc
),
2087 Parameter_Associations
=>
2091 Make_Unchecked_Type_Conversion
(Loc
, -- entry index
2094 (RTE
(RE_Protected_Entry_Index
), Loc
),
2095 Expression
=> Make_Identifier
(Loc
, Name_uI
)),
2097 Make_Identifier
(Loc
, Name_uP
), -- parameter block
2098 New_Reference_To
( -- Asynchronous_Call
2099 RTE
(RE_Asynchronous_Call
), Loc
),
2101 New_Reference_To
(Com_Block
, Loc
)))); -- comm block
2103 when System_Tasking_Protected_Objects_Single_Entry
=>
2106 -- procedure Protected_Single_Entry_Call
2107 -- (Object : Protection_Entry_Access;
2108 -- Uninterpreted_Data : System.Address;
2109 -- Mode : Call_Modes);
2112 Make_Procedure_Call_Statement
(Loc
,
2115 (RTE
(RE_Protected_Single_Entry_Call
), Loc
),
2116 Parameter_Associations
=>
2120 Make_Attribute_Reference
(Loc
,
2121 Prefix
=> Make_Identifier
(Loc
, Name_uP
),
2122 Attribute_Name
=> Name_Address
),
2125 (RTE
(RE_Asynchronous_Call
), Loc
))));
2128 raise Program_Error
;
2132 -- B := Dummy_Communication_Block (Bnn);
2135 Make_Assignment_Statement
(Loc
,
2137 Make_Identifier
(Loc
, Name_uB
),
2139 Make_Unchecked_Type_Conversion
(Loc
,
2142 RTE
(RE_Dummy_Communication_Block
), Loc
),
2144 New_Reference_To
(Com_Block
, Loc
))));
2147 pragma Assert
(Ekind
(Conc_Typ
) = E_Task_Type
);
2151 -- (T._task_id, -- Acceptor
2152 -- Task_Entry_Index! (I), -- E
2153 -- P, -- Uninterpreted_Data
2154 -- Asynchronous_Call, -- Mode
2155 -- F); -- Rendezvous_Successful
2157 -- where T is the task object, I is the entry index, P is the
2158 -- wrapped parameters and F is the status flag.
2161 Make_Procedure_Call_Statement
(Loc
,
2163 New_Reference_To
(RTE
(RE_Task_Entry_Call
), Loc
),
2164 Parameter_Associations
=>
2166 Make_Selected_Component
(Loc
, -- T._task_id
2168 Make_Identifier
(Loc
, Name_uT
),
2170 Make_Identifier
(Loc
, Name_uTask_Id
)),
2172 Make_Unchecked_Type_Conversion
(Loc
, -- entry index
2174 New_Reference_To
(RTE
(RE_Task_Entry_Index
), Loc
),
2176 Make_Identifier
(Loc
, Name_uI
)),
2178 Make_Identifier
(Loc
, Name_uP
), -- parameter block
2179 New_Reference_To
( -- Asynchronous_Call
2180 RTE
(RE_Asynchronous_Call
), Loc
),
2181 Make_Identifier
(Loc
, Name_uF
)))); -- status flag
2185 -- Ensure that the statements list is non-empty
2187 Append_To
(Stmts
, Make_Null_Statement
(Loc
));
2191 Make_Subprogram_Body
(Loc
,
2193 Make_Disp_Asynchronous_Select_Spec
(Typ
),
2196 Handled_Statement_Sequence
=>
2197 Make_Handled_Sequence_Of_Statements
(Loc
, Stmts
));
2198 end Make_Disp_Asynchronous_Select_Body
;
2200 ----------------------------------------
2201 -- Make_Disp_Asynchronous_Select_Spec --
2202 ----------------------------------------
2204 function Make_Disp_Asynchronous_Select_Spec
2205 (Typ
: Entity_Id
) return Node_Id
2207 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
2208 Def_Id
: constant Node_Id
:=
2209 Make_Defining_Identifier
(Loc
,
2210 Name_uDisp_Asynchronous_Select
);
2211 Params
: constant List_Id
:= New_List
;
2214 pragma Assert
(not Restriction_Active
(No_Dispatching_Calls
));
2216 -- T : in out Typ; -- Object parameter
2217 -- S : Integer; -- Primitive operation slot
2218 -- P : Address; -- Wrapped parameters
2219 -- B : out Dummy_Communication_Block; -- Communication block dummy
2220 -- F : out Boolean; -- Status flag
2222 Append_List_To
(Params
, New_List
(
2224 Make_Parameter_Specification
(Loc
,
2225 Defining_Identifier
=>
2226 Make_Defining_Identifier
(Loc
, Name_uT
),
2228 New_Reference_To
(Typ
, Loc
),
2230 Out_Present
=> True),
2232 Make_Parameter_Specification
(Loc
,
2233 Defining_Identifier
=>
2234 Make_Defining_Identifier
(Loc
, Name_uS
),
2236 New_Reference_To
(Standard_Integer
, Loc
)),
2238 Make_Parameter_Specification
(Loc
,
2239 Defining_Identifier
=>
2240 Make_Defining_Identifier
(Loc
, Name_uP
),
2242 New_Reference_To
(RTE
(RE_Address
), Loc
)),
2244 Make_Parameter_Specification
(Loc
,
2245 Defining_Identifier
=>
2246 Make_Defining_Identifier
(Loc
, Name_uB
),
2248 New_Reference_To
(RTE
(RE_Dummy_Communication_Block
), Loc
),
2249 Out_Present
=> True),
2251 Make_Parameter_Specification
(Loc
,
2252 Defining_Identifier
=>
2253 Make_Defining_Identifier
(Loc
, Name_uF
),
2255 New_Reference_To
(Standard_Boolean
, Loc
),
2256 Out_Present
=> True)));
2259 Make_Procedure_Specification
(Loc
,
2260 Defining_Unit_Name
=> Def_Id
,
2261 Parameter_Specifications
=> Params
);
2262 end Make_Disp_Asynchronous_Select_Spec
;
2264 ---------------------------------------
2265 -- Make_Disp_Conditional_Select_Body --
2266 ---------------------------------------
2268 -- For interface types, generate:
2270 -- procedure _Disp_Conditional_Select
2271 -- (T : in out <Typ>;
2273 -- P : System.Address;
2274 -- C : out Ada.Tags.Prim_Op_Kind;
2279 -- end _Disp_Conditional_Select;
2281 -- For protected types, generate:
2283 -- procedure _Disp_Conditional_Select
2284 -- (T : in out <Typ>;
2286 -- P : System.Address;
2287 -- C : out Ada.Tags.Prim_Op_Kind;
2291 -- Bnn : System.Tasking.Protected_Objects.Operations.
2292 -- Communication_Block;
2295 -- C := Ada.Tags.Get_Prim_Op_Kind (Ada.Tags.Tag (<Typ>VP, S));
2297 -- if C = Ada.Tags.POK_Procedure
2298 -- or else C = Ada.Tags.POK_Protected_Procedure
2299 -- or else C = Ada.Tags.POK_Task_Procedure
2305 -- I := Ada.Tags.Get_Entry_Index (Ada.Tags.Tag (<Typ>VP, S));
2306 -- System.Tasking.Protected_Objects.Operations.Protected_Entry_Call
2307 -- (T.object'Access,
2308 -- System.Tasking.Protected_Objects.Protected_Entry_Index (I),
2310 -- System.Tasking.Conditional_Call,
2312 -- F := not Cancelled (Bnn);
2313 -- end _Disp_Conditional_Select;
2315 -- For task types, generate:
2317 -- procedure _Disp_Conditional_Select
2318 -- (T : in out <Typ>;
2320 -- P : System.Address;
2321 -- C : out Ada.Tags.Prim_Op_Kind;
2327 -- I := Ada.Tags.Get_Entry_Index (Ada.Tags.Tag (<Typ>VP, S));
2328 -- System.Tasking.Rendezvous.Task_Entry_Call
2330 -- System.Tasking.Task_Entry_Index (I),
2332 -- System.Tasking.Conditional_Call,
2334 -- end _Disp_Conditional_Select;
2336 function Make_Disp_Conditional_Select_Body
2337 (Typ
: Entity_Id
) return Node_Id
2339 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
2340 Blk_Nam
: Entity_Id
;
2341 Conc_Typ
: Entity_Id
:= Empty
;
2342 Decls
: constant List_Id
:= New_List
;
2345 Stmts
: constant List_Id
:= New_List
;
2348 pragma Assert
(not Restriction_Active
(No_Dispatching_Calls
));
2350 -- Null body is generated for interface types
2352 if Is_Interface
(Typ
) then
2354 Make_Subprogram_Body
(Loc
,
2356 Make_Disp_Conditional_Select_Spec
(Typ
),
2359 Handled_Statement_Sequence
=>
2360 Make_Handled_Sequence_Of_Statements
(Loc
,
2361 New_List
(Make_Null_Statement
(Loc
))));
2364 DT_Ptr
:= Node
(First_Elmt
(Access_Disp_Table
(Typ
)));
2366 if Is_Concurrent_Record_Type
(Typ
) then
2367 Conc_Typ
:= Corresponding_Concurrent_Type
(Typ
);
2372 -- where I will be used to capture the entry index of the primitive
2373 -- wrapper at position S.
2376 Make_Object_Declaration
(Loc
,
2377 Defining_Identifier
=>
2378 Make_Defining_Identifier
(Loc
, Name_uI
),
2379 Object_Definition
=>
2380 New_Reference_To
(Standard_Integer
, Loc
)));
2383 -- C := Ada.Tags.Get_Prim_Op_Kind (Ada.Tags.Tag! (<type>VP), S);
2385 -- if C = POK_Procedure
2386 -- or else C = POK_Protected_Procedure
2387 -- or else C = POK_Task_Procedure;
2393 Build_Common_Dispatching_Select_Statements
(Loc
, DT_Ptr
, Stmts
);
2396 -- Bnn : Communication_Block;
2398 -- where Bnn is the name of the communication block used in the
2399 -- call to Protected_Entry_Call.
2401 Blk_Nam
:= Make_Temporary
(Loc
, 'B');
2403 Make_Object_Declaration
(Loc
,
2404 Defining_Identifier
=>
2406 Object_Definition
=>
2407 New_Reference_To
(RTE
(RE_Communication_Block
), Loc
)));
2410 -- I := Ada.Tags.Get_Entry_Index (Ada.Tags.Tag! (<type>VP), S);
2412 -- I is the entry index and S is the dispatch table slot
2415 Make_Assignment_Statement
(Loc
,
2417 Make_Identifier
(Loc
, Name_uI
),
2419 Make_Function_Call
(Loc
,
2421 New_Reference_To
(RTE
(RE_Get_Entry_Index
), Loc
),
2422 Parameter_Associations
=>
2424 Unchecked_Convert_To
(RTE
(RE_Tag
),
2425 New_Reference_To
(DT_Ptr
, Loc
)),
2426 Make_Identifier
(Loc
, Name_uS
)))));
2428 if Ekind
(Conc_Typ
) = E_Protected_Type
then
2430 Obj_Ref
:= -- T._object'Access
2431 Make_Attribute_Reference
(Loc
,
2432 Attribute_Name
=> Name_Unchecked_Access
,
2434 Make_Selected_Component
(Loc
,
2435 Prefix
=> Make_Identifier
(Loc
, Name_uT
),
2436 Selector_Name
=> Make_Identifier
(Loc
, Name_uObject
)));
2438 case Corresponding_Runtime_Package
(Conc_Typ
) is
2439 when System_Tasking_Protected_Objects_Entries
=>
2442 -- Protected_Entry_Call
2443 -- (T._object'Access, -- Object
2444 -- Protected_Entry_Index! (I), -- E
2445 -- P, -- Uninterpreted_Data
2446 -- Conditional_Call, -- Mode
2449 -- where T is the protected object, I is the entry index, P
2450 -- are the wrapped parameters and Bnn is the name of the
2451 -- communication block.
2454 Make_Procedure_Call_Statement
(Loc
,
2456 New_Reference_To
(RTE
(RE_Protected_Entry_Call
), Loc
),
2457 Parameter_Associations
=>
2461 Make_Unchecked_Type_Conversion
(Loc
, -- entry index
2464 (RTE
(RE_Protected_Entry_Index
), Loc
),
2465 Expression
=> Make_Identifier
(Loc
, Name_uI
)),
2467 Make_Identifier
(Loc
, Name_uP
), -- parameter block
2469 New_Reference_To
( -- Conditional_Call
2470 RTE
(RE_Conditional_Call
), Loc
),
2471 New_Reference_To
( -- Bnn
2474 when System_Tasking_Protected_Objects_Single_Entry
=>
2476 -- If we are compiling for a restricted run-time, the call
2477 -- uses the simpler form.
2480 Make_Procedure_Call_Statement
(Loc
,
2483 (RTE
(RE_Protected_Single_Entry_Call
), Loc
),
2484 Parameter_Associations
=>
2488 Make_Attribute_Reference
(Loc
,
2489 Prefix
=> Make_Identifier
(Loc
, Name_uP
),
2490 Attribute_Name
=> Name_Address
),
2493 (RTE
(RE_Conditional_Call
), Loc
))));
2495 raise Program_Error
;
2499 -- F := not Cancelled (Bnn);
2501 -- where F is the success flag. The status of Cancelled is negated
2502 -- in order to match the behaviour of the version for task types.
2505 Make_Assignment_Statement
(Loc
,
2507 Make_Identifier
(Loc
, Name_uF
),
2511 Make_Function_Call
(Loc
,
2513 New_Reference_To
(RTE
(RE_Cancelled
), Loc
),
2514 Parameter_Associations
=>
2516 New_Reference_To
(Blk_Nam
, Loc
))))));
2518 pragma Assert
(Ekind
(Conc_Typ
) = E_Task_Type
);
2522 -- (T._task_id, -- Acceptor
2523 -- Task_Entry_Index! (I), -- E
2524 -- P, -- Uninterpreted_Data
2525 -- Conditional_Call, -- Mode
2526 -- F); -- Rendezvous_Successful
2528 -- where T is the task object, I is the entry index, P are the
2529 -- wrapped parameters and F is the status flag.
2532 Make_Procedure_Call_Statement
(Loc
,
2534 New_Reference_To
(RTE
(RE_Task_Entry_Call
), Loc
),
2535 Parameter_Associations
=>
2538 Make_Selected_Component
(Loc
, -- T._task_id
2540 Make_Identifier
(Loc
, Name_uT
),
2542 Make_Identifier
(Loc
, Name_uTask_Id
)),
2544 Make_Unchecked_Type_Conversion
(Loc
, -- entry index
2546 New_Reference_To
(RTE
(RE_Task_Entry_Index
), Loc
),
2548 Make_Identifier
(Loc
, Name_uI
)),
2550 Make_Identifier
(Loc
, Name_uP
), -- parameter block
2551 New_Reference_To
( -- Conditional_Call
2552 RTE
(RE_Conditional_Call
), Loc
),
2553 Make_Identifier
(Loc
, Name_uF
)))); -- status flag
2557 -- Ensure that the statements list is non-empty
2559 Append_To
(Stmts
, Make_Null_Statement
(Loc
));
2563 Make_Subprogram_Body
(Loc
,
2565 Make_Disp_Conditional_Select_Spec
(Typ
),
2568 Handled_Statement_Sequence
=>
2569 Make_Handled_Sequence_Of_Statements
(Loc
, Stmts
));
2570 end Make_Disp_Conditional_Select_Body
;
2572 ---------------------------------------
2573 -- Make_Disp_Conditional_Select_Spec --
2574 ---------------------------------------
2576 function Make_Disp_Conditional_Select_Spec
2577 (Typ
: Entity_Id
) return Node_Id
2579 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
2580 Def_Id
: constant Node_Id
:=
2581 Make_Defining_Identifier
(Loc
,
2582 Name_uDisp_Conditional_Select
);
2583 Params
: constant List_Id
:= New_List
;
2586 pragma Assert
(not Restriction_Active
(No_Dispatching_Calls
));
2588 -- T : in out Typ; -- Object parameter
2589 -- S : Integer; -- Primitive operation slot
2590 -- P : Address; -- Wrapped parameters
2591 -- C : out Prim_Op_Kind; -- Call kind
2592 -- F : out Boolean; -- Status flag
2594 Append_List_To
(Params
, New_List
(
2596 Make_Parameter_Specification
(Loc
,
2597 Defining_Identifier
=>
2598 Make_Defining_Identifier
(Loc
, Name_uT
),
2600 New_Reference_To
(Typ
, Loc
),
2602 Out_Present
=> True),
2604 Make_Parameter_Specification
(Loc
,
2605 Defining_Identifier
=>
2606 Make_Defining_Identifier
(Loc
, Name_uS
),
2608 New_Reference_To
(Standard_Integer
, Loc
)),
2610 Make_Parameter_Specification
(Loc
,
2611 Defining_Identifier
=>
2612 Make_Defining_Identifier
(Loc
, Name_uP
),
2614 New_Reference_To
(RTE
(RE_Address
), Loc
)),
2616 Make_Parameter_Specification
(Loc
,
2617 Defining_Identifier
=>
2618 Make_Defining_Identifier
(Loc
, Name_uC
),
2620 New_Reference_To
(RTE
(RE_Prim_Op_Kind
), Loc
),
2621 Out_Present
=> True),
2623 Make_Parameter_Specification
(Loc
,
2624 Defining_Identifier
=>
2625 Make_Defining_Identifier
(Loc
, Name_uF
),
2627 New_Reference_To
(Standard_Boolean
, Loc
),
2628 Out_Present
=> True)));
2631 Make_Procedure_Specification
(Loc
,
2632 Defining_Unit_Name
=> Def_Id
,
2633 Parameter_Specifications
=> Params
);
2634 end Make_Disp_Conditional_Select_Spec
;
2636 -------------------------------------
2637 -- Make_Disp_Get_Prim_Op_Kind_Body --
2638 -------------------------------------
2640 function Make_Disp_Get_Prim_Op_Kind_Body
2641 (Typ
: Entity_Id
) return Node_Id
2643 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
2647 pragma Assert
(not Restriction_Active
(No_Dispatching_Calls
));
2649 if Is_Interface
(Typ
) then
2651 Make_Subprogram_Body
(Loc
,
2653 Make_Disp_Get_Prim_Op_Kind_Spec
(Typ
),
2656 Handled_Statement_Sequence
=>
2657 Make_Handled_Sequence_Of_Statements
(Loc
,
2658 New_List
(Make_Null_Statement
(Loc
))));
2661 DT_Ptr
:= Node
(First_Elmt
(Access_Disp_Table
(Typ
)));
2664 -- C := get_prim_op_kind (tag! (<type>VP), S);
2666 -- where C is the out parameter capturing the call kind and S is the
2667 -- dispatch table slot number.
2670 Make_Subprogram_Body
(Loc
,
2672 Make_Disp_Get_Prim_Op_Kind_Spec
(Typ
),
2675 Handled_Statement_Sequence
=>
2676 Make_Handled_Sequence_Of_Statements
(Loc
,
2678 Make_Assignment_Statement
(Loc
,
2680 Make_Identifier
(Loc
, Name_uC
),
2682 Make_Function_Call
(Loc
,
2684 New_Reference_To
(RTE
(RE_Get_Prim_Op_Kind
), Loc
),
2685 Parameter_Associations
=> New_List
(
2686 Unchecked_Convert_To
(RTE
(RE_Tag
),
2687 New_Reference_To
(DT_Ptr
, Loc
)),
2688 Make_Identifier
(Loc
, Name_uS
)))))));
2689 end Make_Disp_Get_Prim_Op_Kind_Body
;
2691 -------------------------------------
2692 -- Make_Disp_Get_Prim_Op_Kind_Spec --
2693 -------------------------------------
2695 function Make_Disp_Get_Prim_Op_Kind_Spec
2696 (Typ
: Entity_Id
) return Node_Id
2698 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
2699 Def_Id
: constant Node_Id
:=
2700 Make_Defining_Identifier
(Loc
,
2701 Name_uDisp_Get_Prim_Op_Kind
);
2702 Params
: constant List_Id
:= New_List
;
2705 pragma Assert
(not Restriction_Active
(No_Dispatching_Calls
));
2707 -- T : in out Typ; -- Object parameter
2708 -- S : Integer; -- Primitive operation slot
2709 -- C : out Prim_Op_Kind; -- Call kind
2711 Append_List_To
(Params
, New_List
(
2713 Make_Parameter_Specification
(Loc
,
2714 Defining_Identifier
=>
2715 Make_Defining_Identifier
(Loc
, Name_uT
),
2717 New_Reference_To
(Typ
, Loc
),
2719 Out_Present
=> True),
2721 Make_Parameter_Specification
(Loc
,
2722 Defining_Identifier
=>
2723 Make_Defining_Identifier
(Loc
, Name_uS
),
2725 New_Reference_To
(Standard_Integer
, Loc
)),
2727 Make_Parameter_Specification
(Loc
,
2728 Defining_Identifier
=>
2729 Make_Defining_Identifier
(Loc
, Name_uC
),
2731 New_Reference_To
(RTE
(RE_Prim_Op_Kind
), Loc
),
2732 Out_Present
=> True)));
2735 Make_Procedure_Specification
(Loc
,
2736 Defining_Unit_Name
=> Def_Id
,
2737 Parameter_Specifications
=> Params
);
2738 end Make_Disp_Get_Prim_Op_Kind_Spec
;
2740 --------------------------------
2741 -- Make_Disp_Get_Task_Id_Body --
2742 --------------------------------
2744 function Make_Disp_Get_Task_Id_Body
2745 (Typ
: Entity_Id
) return Node_Id
2747 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
2751 pragma Assert
(not Restriction_Active
(No_Dispatching_Calls
));
2753 if Is_Concurrent_Record_Type
(Typ
)
2754 and then Ekind
(Corresponding_Concurrent_Type
(Typ
)) = E_Task_Type
2757 -- return To_Address (_T._task_id);
2760 Make_Simple_Return_Statement
(Loc
,
2762 Make_Unchecked_Type_Conversion
(Loc
,
2764 New_Reference_To
(RTE
(RE_Address
), Loc
),
2766 Make_Selected_Component
(Loc
,
2768 Make_Identifier
(Loc
, Name_uT
),
2770 Make_Identifier
(Loc
, Name_uTask_Id
))));
2772 -- A null body is constructed for non-task types
2776 -- return Null_Address;
2779 Make_Simple_Return_Statement
(Loc
,
2781 New_Reference_To
(RTE
(RE_Null_Address
), Loc
));
2785 Make_Subprogram_Body
(Loc
,
2787 Make_Disp_Get_Task_Id_Spec
(Typ
),
2790 Handled_Statement_Sequence
=>
2791 Make_Handled_Sequence_Of_Statements
(Loc
,
2793 end Make_Disp_Get_Task_Id_Body
;
2795 --------------------------------
2796 -- Make_Disp_Get_Task_Id_Spec --
2797 --------------------------------
2799 function Make_Disp_Get_Task_Id_Spec
2800 (Typ
: Entity_Id
) return Node_Id
2802 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
2805 pragma Assert
(not Restriction_Active
(No_Dispatching_Calls
));
2808 Make_Function_Specification
(Loc
,
2809 Defining_Unit_Name
=>
2810 Make_Defining_Identifier
(Loc
, Name_uDisp_Get_Task_Id
),
2811 Parameter_Specifications
=> New_List
(
2812 Make_Parameter_Specification
(Loc
,
2813 Defining_Identifier
=>
2814 Make_Defining_Identifier
(Loc
, Name_uT
),
2816 New_Reference_To
(Typ
, Loc
))),
2817 Result_Definition
=>
2818 New_Reference_To
(RTE
(RE_Address
), Loc
));
2819 end Make_Disp_Get_Task_Id_Spec
;
2821 ----------------------------
2822 -- Make_Disp_Requeue_Body --
2823 ----------------------------
2825 function Make_Disp_Requeue_Body
2826 (Typ
: Entity_Id
) return Node_Id
2828 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
2829 Conc_Typ
: Entity_Id
:= Empty
;
2830 Stmts
: constant List_Id
:= New_List
;
2833 pragma Assert
(not Restriction_Active
(No_Dispatching_Calls
));
2835 -- Null body is generated for interface types and non-concurrent
2838 if Is_Interface
(Typ
)
2839 or else not Is_Concurrent_Record_Type
(Typ
)
2842 Make_Subprogram_Body
(Loc
,
2844 Make_Disp_Requeue_Spec
(Typ
),
2847 Handled_Statement_Sequence
=>
2848 Make_Handled_Sequence_Of_Statements
(Loc
,
2849 New_List
(Make_Null_Statement
(Loc
))));
2852 Conc_Typ
:= Corresponding_Concurrent_Type
(Typ
);
2854 if Ekind
(Conc_Typ
) = E_Protected_Type
then
2856 -- Generate statements:
2858 -- System.Tasking.Protected_Objects.Operations.
2859 -- Requeue_Protected_Entry
2860 -- (Protection_Entries_Access (P),
2861 -- O._object'Unchecked_Access,
2862 -- Protected_Entry_Index (I),
2865 -- System.Tasking.Protected_Objects.Operations.
2866 -- Requeue_Task_To_Protected_Entry
2867 -- (O._object'Unchecked_Access,
2868 -- Protected_Entry_Index (I),
2872 if Restriction_Active
(No_Entry_Queue
) then
2873 Append_To
(Stmts
, Make_Null_Statement
(Loc
));
2876 Make_If_Statement
(Loc
,
2878 Make_Identifier
(Loc
, Name_uF
),
2883 -- Call to Requeue_Protected_Entry
2885 Make_Procedure_Call_Statement
(Loc
,
2888 RTE
(RE_Requeue_Protected_Entry
), Loc
),
2889 Parameter_Associations
=>
2892 Make_Unchecked_Type_Conversion
(Loc
, -- PEA (P)
2895 RTE
(RE_Protection_Entries_Access
), Loc
),
2897 Make_Identifier
(Loc
, Name_uP
)),
2899 Make_Attribute_Reference
(Loc
, -- O._object'Acc
2901 Name_Unchecked_Access
,
2903 Make_Selected_Component
(Loc
,
2905 Make_Identifier
(Loc
, Name_uO
),
2907 Make_Identifier
(Loc
, Name_uObject
))),
2909 Make_Unchecked_Type_Conversion
(Loc
, -- entry index
2912 RTE
(RE_Protected_Entry_Index
), Loc
),
2914 Make_Identifier
(Loc
, Name_uI
)),
2916 Make_Identifier
(Loc
, Name_uA
)))), -- abort status
2921 -- Call to Requeue_Task_To_Protected_Entry
2923 Make_Procedure_Call_Statement
(Loc
,
2926 RTE
(RE_Requeue_Task_To_Protected_Entry
), Loc
),
2927 Parameter_Associations
=>
2930 Make_Attribute_Reference
(Loc
, -- O._object'Acc
2932 Name_Unchecked_Access
,
2934 Make_Selected_Component
(Loc
,
2936 Make_Identifier
(Loc
, Name_uO
),
2938 Make_Identifier
(Loc
, Name_uObject
))),
2940 Make_Unchecked_Type_Conversion
(Loc
, -- entry index
2943 RTE
(RE_Protected_Entry_Index
), Loc
),
2945 Make_Identifier
(Loc
, Name_uI
)),
2947 Make_Identifier
(Loc
, Name_uA
)))))); -- abort status
2950 pragma Assert
(Is_Task_Type
(Conc_Typ
));
2954 -- System.Tasking.Rendezvous.Requeue_Protected_To_Task_Entry
2955 -- (Protection_Entries_Access (P),
2957 -- Task_Entry_Index (I),
2960 -- System.Tasking.Rendezvous.Requeue_Task_Entry
2962 -- Task_Entry_Index (I),
2967 Make_If_Statement
(Loc
,
2969 Make_Identifier
(Loc
, Name_uF
),
2974 -- Call to Requeue_Protected_To_Task_Entry
2976 Make_Procedure_Call_Statement
(Loc
,
2979 RTE
(RE_Requeue_Protected_To_Task_Entry
), Loc
),
2981 Parameter_Associations
=>
2984 Make_Unchecked_Type_Conversion
(Loc
, -- PEA (P)
2987 RTE
(RE_Protection_Entries_Access
), Loc
),
2989 Make_Identifier
(Loc
, Name_uP
)),
2991 Make_Selected_Component
(Loc
, -- O._task_id
2993 Make_Identifier
(Loc
, Name_uO
),
2995 Make_Identifier
(Loc
, Name_uTask_Id
)),
2997 Make_Unchecked_Type_Conversion
(Loc
, -- entry index
3000 RTE
(RE_Task_Entry_Index
), Loc
),
3002 Make_Identifier
(Loc
, Name_uI
)),
3004 Make_Identifier
(Loc
, Name_uA
)))), -- abort status
3009 -- Call to Requeue_Task_Entry
3011 Make_Procedure_Call_Statement
(Loc
,
3013 New_Reference_To
(RTE
(RE_Requeue_Task_Entry
), Loc
),
3015 Parameter_Associations
=>
3018 Make_Selected_Component
(Loc
, -- O._task_id
3020 Make_Identifier
(Loc
, Name_uO
),
3022 Make_Identifier
(Loc
, Name_uTask_Id
)),
3024 Make_Unchecked_Type_Conversion
(Loc
, -- entry index
3027 RTE
(RE_Task_Entry_Index
), Loc
),
3029 Make_Identifier
(Loc
, Name_uI
)),
3031 Make_Identifier
(Loc
, Name_uA
)))))); -- abort status
3034 -- Even though no declarations are needed in both cases, we allocate
3035 -- a list for entities added by Freeze.
3038 Make_Subprogram_Body
(Loc
,
3040 Make_Disp_Requeue_Spec
(Typ
),
3043 Handled_Statement_Sequence
=>
3044 Make_Handled_Sequence_Of_Statements
(Loc
, Stmts
));
3045 end Make_Disp_Requeue_Body
;
3047 ----------------------------
3048 -- Make_Disp_Requeue_Spec --
3049 ----------------------------
3051 function Make_Disp_Requeue_Spec
3052 (Typ
: Entity_Id
) return Node_Id
3054 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
3057 pragma Assert
(not Restriction_Active
(No_Dispatching_Calls
));
3059 -- O : in out Typ; - Object parameter
3060 -- F : Boolean; - Protected (True) / task (False) flag
3061 -- P : Address; - Protection_Entries_Access value
3062 -- I : Entry_Index - Index of entry call
3063 -- A : Boolean - Abort flag
3065 -- Note that the Protection_Entries_Access value is represented as a
3066 -- System.Address in order to avoid dragging in the tasking runtime
3067 -- when compiling sources without tasking constructs.
3070 Make_Procedure_Specification
(Loc
,
3071 Defining_Unit_Name
=>
3072 Make_Defining_Identifier
(Loc
, Name_uDisp_Requeue
),
3074 Parameter_Specifications
=>
3077 Make_Parameter_Specification
(Loc
, -- O
3078 Defining_Identifier
=>
3079 Make_Defining_Identifier
(Loc
, Name_uO
),
3081 New_Reference_To
(Typ
, Loc
),
3083 Out_Present
=> True),
3085 Make_Parameter_Specification
(Loc
, -- F
3086 Defining_Identifier
=>
3087 Make_Defining_Identifier
(Loc
, Name_uF
),
3089 New_Reference_To
(Standard_Boolean
, Loc
)),
3091 Make_Parameter_Specification
(Loc
, -- P
3092 Defining_Identifier
=>
3093 Make_Defining_Identifier
(Loc
, Name_uP
),
3095 New_Reference_To
(RTE
(RE_Address
), Loc
)),
3097 Make_Parameter_Specification
(Loc
, -- I
3098 Defining_Identifier
=>
3099 Make_Defining_Identifier
(Loc
, Name_uI
),
3101 New_Reference_To
(Standard_Integer
, Loc
)),
3103 Make_Parameter_Specification
(Loc
, -- A
3104 Defining_Identifier
=>
3105 Make_Defining_Identifier
(Loc
, Name_uA
),
3107 New_Reference_To
(Standard_Boolean
, Loc
))));
3108 end Make_Disp_Requeue_Spec
;
3110 ---------------------------------
3111 -- Make_Disp_Timed_Select_Body --
3112 ---------------------------------
3114 -- For interface types, generate:
3116 -- procedure _Disp_Timed_Select
3117 -- (T : in out <Typ>;
3119 -- P : System.Address;
3122 -- C : out Ada.Tags.Prim_Op_Kind;
3127 -- end _Disp_Timed_Select;
3129 -- For protected types, generate:
3131 -- procedure _Disp_Timed_Select
3132 -- (T : in out <Typ>;
3134 -- P : System.Address;
3137 -- C : out Ada.Tags.Prim_Op_Kind;
3143 -- C := Ada.Tags.Get_Prim_Op_Kind (Ada.Tags.Tag (<Typ>VP), S);
3145 -- if C = Ada.Tags.POK_Procedure
3146 -- or else C = Ada.Tags.POK_Protected_Procedure
3147 -- or else C = Ada.Tags.POK_Task_Procedure
3153 -- I := Ada.Tags.Get_Entry_Index (Ada.Tags.Tag (<Typ>VP), S);
3154 -- System.Tasking.Protected_Objects.Operations.
3155 -- Timed_Protected_Entry_Call
3156 -- (T._object'Access,
3157 -- System.Tasking.Protected_Objects.Protected_Entry_Index (I),
3162 -- end _Disp_Timed_Select;
3164 -- For task types, generate:
3166 -- procedure _Disp_Timed_Select
3167 -- (T : in out <Typ>;
3169 -- P : System.Address;
3172 -- C : out Ada.Tags.Prim_Op_Kind;
3178 -- I := Ada.Tags.Get_Entry_Index (Ada.Tags.Tag (<Typ>VP), S);
3179 -- System.Tasking.Rendezvous.Timed_Task_Entry_Call
3181 -- System.Tasking.Task_Entry_Index (I),
3186 -- end _Disp_Time_Select;
3188 function Make_Disp_Timed_Select_Body
3189 (Typ
: Entity_Id
) return Node_Id
3191 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
3192 Conc_Typ
: Entity_Id
:= Empty
;
3193 Decls
: constant List_Id
:= New_List
;
3196 Stmts
: constant List_Id
:= New_List
;
3199 pragma Assert
(not Restriction_Active
(No_Dispatching_Calls
));
3201 -- Null body is generated for interface types
3203 if Is_Interface
(Typ
) then
3205 Make_Subprogram_Body
(Loc
,
3207 Make_Disp_Timed_Select_Spec
(Typ
),
3210 Handled_Statement_Sequence
=>
3211 Make_Handled_Sequence_Of_Statements
(Loc
,
3212 New_List
(Make_Null_Statement
(Loc
))));
3215 DT_Ptr
:= Node
(First_Elmt
(Access_Disp_Table
(Typ
)));
3217 if Is_Concurrent_Record_Type
(Typ
) then
3218 Conc_Typ
:= Corresponding_Concurrent_Type
(Typ
);
3223 -- where I will be used to capture the entry index of the primitive
3224 -- wrapper at position S.
3227 Make_Object_Declaration
(Loc
,
3228 Defining_Identifier
=>
3229 Make_Defining_Identifier
(Loc
, Name_uI
),
3230 Object_Definition
=>
3231 New_Reference_To
(Standard_Integer
, Loc
)));
3234 -- C := Get_Prim_Op_Kind (tag! (<type>VP), S);
3236 -- if C = POK_Procedure
3237 -- or else C = POK_Protected_Procedure
3238 -- or else C = POK_Task_Procedure;
3244 Build_Common_Dispatching_Select_Statements
(Loc
, DT_Ptr
, Stmts
);
3247 -- I := Get_Entry_Index (tag! (<type>VP), S);
3249 -- I is the entry index and S is the dispatch table slot
3252 Make_Assignment_Statement
(Loc
,
3254 Make_Identifier
(Loc
, Name_uI
),
3256 Make_Function_Call
(Loc
,
3258 New_Reference_To
(RTE
(RE_Get_Entry_Index
), Loc
),
3259 Parameter_Associations
=>
3261 Unchecked_Convert_To
(RTE
(RE_Tag
),
3262 New_Reference_To
(DT_Ptr
, Loc
)),
3263 Make_Identifier
(Loc
, Name_uS
)))));
3267 if Ekind
(Conc_Typ
) = E_Protected_Type
then
3269 -- Build T._object'Access
3272 Make_Attribute_Reference
(Loc
,
3273 Attribute_Name
=> Name_Unchecked_Access
,
3275 Make_Selected_Component
(Loc
,
3276 Prefix
=> Make_Identifier
(Loc
, Name_uT
),
3277 Selector_Name
=> Make_Identifier
(Loc
, Name_uObject
)));
3279 -- Normal case, No_Entry_Queue restriction not active. In this
3280 -- case we generate:
3282 -- Timed_Protected_Entry_Call
3283 -- (T._object'access,
3284 -- Protected_Entry_Index! (I),
3287 -- where T is the protected object, I is the entry index, P are
3288 -- the wrapped parameters, D is the delay amount, M is the delay
3289 -- mode and F is the status flag.
3291 case Corresponding_Runtime_Package
(Conc_Typ
) is
3292 when System_Tasking_Protected_Objects_Entries
=>
3294 Make_Procedure_Call_Statement
(Loc
,
3297 (RTE
(RE_Timed_Protected_Entry_Call
), Loc
),
3298 Parameter_Associations
=>
3302 Make_Unchecked_Type_Conversion
(Loc
, -- entry index
3305 (RTE
(RE_Protected_Entry_Index
), Loc
),
3307 Make_Identifier
(Loc
, Name_uI
)),
3309 Make_Identifier
(Loc
, Name_uP
), -- parameter block
3310 Make_Identifier
(Loc
, Name_uD
), -- delay
3311 Make_Identifier
(Loc
, Name_uM
), -- delay mode
3312 Make_Identifier
(Loc
, Name_uF
)))); -- status flag
3314 when System_Tasking_Protected_Objects_Single_Entry
=>
3317 -- Timed_Protected_Single_Entry_Call
3318 -- (T._object'access, P, D, M, F);
3320 -- where T is the protected object, P is the wrapped
3321 -- parameters, D is the delay amount, M is the delay mode, F
3322 -- is the status flag.
3325 Make_Procedure_Call_Statement
(Loc
,
3328 (RTE
(RE_Timed_Protected_Single_Entry_Call
), Loc
),
3329 Parameter_Associations
=>
3332 Make_Identifier
(Loc
, Name_uP
), -- parameter block
3333 Make_Identifier
(Loc
, Name_uD
), -- delay
3334 Make_Identifier
(Loc
, Name_uM
), -- delay mode
3335 Make_Identifier
(Loc
, Name_uF
)))); -- status flag
3338 raise Program_Error
;
3344 pragma Assert
(Ekind
(Conc_Typ
) = E_Task_Type
);
3347 -- Timed_Task_Entry_Call (
3349 -- Task_Entry_Index! (I),
3355 -- where T is the task object, I is the entry index, P are the
3356 -- wrapped parameters, D is the delay amount, M is the delay
3357 -- mode and F is the status flag.
3360 Make_Procedure_Call_Statement
(Loc
,
3362 New_Reference_To
(RTE
(RE_Timed_Task_Entry_Call
), Loc
),
3363 Parameter_Associations
=>
3366 Make_Selected_Component
(Loc
, -- T._task_id
3368 Make_Identifier
(Loc
, Name_uT
),
3370 Make_Identifier
(Loc
, Name_uTask_Id
)),
3372 Make_Unchecked_Type_Conversion
(Loc
, -- entry index
3374 New_Reference_To
(RTE
(RE_Task_Entry_Index
), Loc
),
3376 Make_Identifier
(Loc
, Name_uI
)),
3378 Make_Identifier
(Loc
, Name_uP
), -- parameter block
3379 Make_Identifier
(Loc
, Name_uD
), -- delay
3380 Make_Identifier
(Loc
, Name_uM
), -- delay mode
3381 Make_Identifier
(Loc
, Name_uF
)))); -- status flag
3385 -- Ensure that the statements list is non-empty
3387 Append_To
(Stmts
, Make_Null_Statement
(Loc
));
3391 Make_Subprogram_Body
(Loc
,
3393 Make_Disp_Timed_Select_Spec
(Typ
),
3396 Handled_Statement_Sequence
=>
3397 Make_Handled_Sequence_Of_Statements
(Loc
, Stmts
));
3398 end Make_Disp_Timed_Select_Body
;
3400 ---------------------------------
3401 -- Make_Disp_Timed_Select_Spec --
3402 ---------------------------------
3404 function Make_Disp_Timed_Select_Spec
3405 (Typ
: Entity_Id
) return Node_Id
3407 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
3408 Def_Id
: constant Node_Id
:=
3409 Make_Defining_Identifier
(Loc
,
3410 Name_uDisp_Timed_Select
);
3411 Params
: constant List_Id
:= New_List
;
3414 pragma Assert
(not Restriction_Active
(No_Dispatching_Calls
));
3416 -- T : in out Typ; -- Object parameter
3417 -- S : Integer; -- Primitive operation slot
3418 -- P : Address; -- Wrapped parameters
3419 -- D : Duration; -- Delay
3420 -- M : Integer; -- Delay Mode
3421 -- C : out Prim_Op_Kind; -- Call kind
3422 -- F : out Boolean; -- Status flag
3424 Append_List_To
(Params
, New_List
(
3426 Make_Parameter_Specification
(Loc
,
3427 Defining_Identifier
=>
3428 Make_Defining_Identifier
(Loc
, Name_uT
),
3430 New_Reference_To
(Typ
, Loc
),
3432 Out_Present
=> True),
3434 Make_Parameter_Specification
(Loc
,
3435 Defining_Identifier
=>
3436 Make_Defining_Identifier
(Loc
, Name_uS
),
3438 New_Reference_To
(Standard_Integer
, Loc
)),
3440 Make_Parameter_Specification
(Loc
,
3441 Defining_Identifier
=>
3442 Make_Defining_Identifier
(Loc
, Name_uP
),
3444 New_Reference_To
(RTE
(RE_Address
), Loc
)),
3446 Make_Parameter_Specification
(Loc
,
3447 Defining_Identifier
=>
3448 Make_Defining_Identifier
(Loc
, Name_uD
),
3450 New_Reference_To
(Standard_Duration
, Loc
)),
3452 Make_Parameter_Specification
(Loc
,
3453 Defining_Identifier
=>
3454 Make_Defining_Identifier
(Loc
, Name_uM
),
3456 New_Reference_To
(Standard_Integer
, Loc
)),
3458 Make_Parameter_Specification
(Loc
,
3459 Defining_Identifier
=>
3460 Make_Defining_Identifier
(Loc
, Name_uC
),
3462 New_Reference_To
(RTE
(RE_Prim_Op_Kind
), Loc
),
3463 Out_Present
=> True)));
3466 Make_Parameter_Specification
(Loc
,
3467 Defining_Identifier
=>
3468 Make_Defining_Identifier
(Loc
, Name_uF
),
3470 New_Reference_To
(Standard_Boolean
, Loc
),
3471 Out_Present
=> True));
3474 Make_Procedure_Specification
(Loc
,
3475 Defining_Unit_Name
=> Def_Id
,
3476 Parameter_Specifications
=> Params
);
3477 end Make_Disp_Timed_Select_Spec
;
3483 -- The frontend supports two models for expanding dispatch tables
3484 -- associated with library-level defined tagged types: statically
3485 -- and non-statically allocated dispatch tables. In the former case
3486 -- the object containing the dispatch table is constant and it is
3487 -- initialized by means of a positional aggregate. In the latter case,
3488 -- the object containing the dispatch table is a variable which is
3489 -- initialized by means of assignments.
3491 -- In case of locally defined tagged types, the object containing the
3492 -- object containing the dispatch table is always a variable (instead
3493 -- of a constant). This is currently required to give support to late
3494 -- overriding of primitives. For example:
3496 -- procedure Example is
3498 -- type T1 is tagged null record;
3499 -- procedure Prim (O : T1);
3502 -- type T2 is new Pkg.T1 with null record;
3503 -- procedure Prim (X : T2) is -- late overriding
3509 function Make_DT
(Typ
: Entity_Id
; N
: Node_Id
:= Empty
) return List_Id
is
3510 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
3512 Max_Predef_Prims
: constant Int
:=
3516 (Parent
(RTE
(RE_Max_Predef_Prims
)))));
3518 DT_Decl
: constant Elist_Id
:= New_Elmt_List
;
3519 DT_Aggr
: constant Elist_Id
:= New_Elmt_List
;
3520 -- Entities marked with attribute Is_Dispatch_Table_Entity
3522 procedure Check_Premature_Freezing
(Subp
: Entity_Id
; Typ
: Entity_Id
);
3523 -- Verify that all non-tagged types in the profile of a subprogram
3524 -- are frozen at the point the subprogram is frozen. This enforces
3525 -- the rule on RM 13.14 (14) as modified by AI05-019. At the point a
3526 -- subprogram is frozen, enough must be known about it to build the
3527 -- activation record for it, which requires at least that the size of
3528 -- all parameters be known. Controlling arguments are by-reference,
3529 -- and therefore the rule only applies to non-tagged types.
3530 -- Typical violation of the rule involves an object declaration that
3531 -- freezes a tagged type, when one of its primitive operations has a
3532 -- type in its profile whose full view has not been analyzed yet.
3534 procedure Export_DT
(Typ
: Entity_Id
; DT
: Entity_Id
; Index
: Nat
:= 0);
3535 -- Export the dispatch table DT of tagged type Typ. Required to generate
3536 -- forward references and statically allocate the table. For primary
3537 -- dispatch tables Index is 0; for secondary dispatch tables the value
3538 -- of index must match the Suffix_Index value assigned to the table by
3539 -- Make_Tags when generating its unique external name, and it is used to
3540 -- retrieve from the Dispatch_Table_Wrappers list associated with Typ
3541 -- the external name generated by Import_DT.
3543 procedure Make_Secondary_DT
3547 Num_Iface_Prims
: Nat
;
3548 Iface_DT_Ptr
: Entity_Id
;
3549 Predef_Prims_Ptr
: Entity_Id
;
3550 Build_Thunks
: Boolean;
3552 -- Ada 2005 (AI-251): Expand the declarations for a Secondary Dispatch
3553 -- Table of Typ associated with Iface. Each abstract interface of Typ
3554 -- has two secondary dispatch tables: one containing pointers to thunks
3555 -- and another containing pointers to the primitives covering the
3556 -- interface primitives. The former secondary table is generated when
3557 -- Build_Thunks is True, and provides common support for dispatching
3558 -- calls through interface types; the latter secondary table is
3559 -- generated when Build_Thunks is False, and provides support for
3560 -- Generic Dispatching Constructors that dispatch calls through
3561 -- interface types. When constructing this latter table the value
3562 -- of Suffix_Index is -1 to indicate that there is no need to export
3563 -- such table when building statically allocated dispatch tables; a
3564 -- positive value of Suffix_Index must match the Suffix_Index value
3565 -- assigned to this secondary dispatch table by Make_Tags when its
3566 -- unique external name was generated.
3568 ------------------------------
3569 -- Check_Premature_Freezing --
3570 ------------------------------
3572 procedure Check_Premature_Freezing
(Subp
: Entity_Id
; Typ
: Entity_Id
) is
3575 and then Is_Private_Type
(Typ
)
3576 and then No
(Full_View
(Typ
))
3577 and then not Is_Generic_Type
(Typ
)
3578 and then not Is_Tagged_Type
(Typ
)
3579 and then not Is_Frozen
(Typ
)
3581 Error_Msg_Sloc
:= Sloc
(Subp
);
3583 ("declaration must appear after completion of type &", N
, Typ
);
3585 ("\which is an untagged type in the profile of"
3586 & " primitive operation & declared#",
3589 end Check_Premature_Freezing
;
3595 procedure Export_DT
(Typ
: Entity_Id
; DT
: Entity_Id
; Index
: Nat
:= 0)
3601 Set_Is_Statically_Allocated
(DT
);
3602 Set_Is_True_Constant
(DT
);
3603 Set_Is_Exported
(DT
);
3606 Elmt
:= First_Elmt
(Dispatch_Table_Wrappers
(Typ
));
3607 while Count
/= Index
loop
3612 pragma Assert
(Related_Type
(Node
(Elmt
)) = Typ
);
3615 (Entity
=> Node
(Elmt
),
3616 Has_Suffix
=> True);
3618 Set_Interface_Name
(DT
,
3619 Make_String_Literal
(Loc
,
3620 Strval
=> String_From_Name_Buffer
));
3622 -- Ensure proper Sprint output of this implicit importation
3624 Set_Is_Internal
(DT
);
3628 -----------------------
3629 -- Make_Secondary_DT --
3630 -----------------------
3632 procedure Make_Secondary_DT
3636 Num_Iface_Prims
: Nat
;
3637 Iface_DT_Ptr
: Entity_Id
;
3638 Predef_Prims_Ptr
: Entity_Id
;
3639 Build_Thunks
: Boolean;
3642 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
3643 Exporting_Table
: constant Boolean :=
3644 Building_Static_DT
(Typ
)
3645 and then Suffix_Index
> 0;
3646 Iface_DT
: constant Entity_Id
:= Make_Temporary
(Loc
, 'T');
3647 Predef_Prims
: constant Entity_Id
:= Make_Temporary
(Loc
, 'R');
3648 DT_Constr_List
: List_Id
;
3649 DT_Aggr_List
: List_Id
;
3650 Empty_DT
: Boolean := False;
3651 Nb_Predef_Prims
: Nat
:= 0;
3655 OSD_Aggr_List
: List_Id
;
3658 Prim_Elmt
: Elmt_Id
;
3659 Prim_Ops_Aggr_List
: List_Id
;
3662 -- Handle cases in which we do not generate statically allocated
3665 if not Building_Static_DT
(Typ
) then
3666 Set_Ekind
(Predef_Prims
, E_Variable
);
3667 Set_Ekind
(Iface_DT
, E_Variable
);
3669 -- Statically allocated dispatch tables and related entities are
3673 Set_Ekind
(Predef_Prims
, E_Constant
);
3674 Set_Is_Statically_Allocated
(Predef_Prims
);
3675 Set_Is_True_Constant
(Predef_Prims
);
3677 Set_Ekind
(Iface_DT
, E_Constant
);
3678 Set_Is_Statically_Allocated
(Iface_DT
);
3679 Set_Is_True_Constant
(Iface_DT
);
3682 -- Calculate the number of slots of the dispatch table. If the number
3683 -- of primitives of Typ is 0 we reserve a dummy single entry for its
3684 -- DT because at run time the pointer to this dummy entry will be
3687 if Num_Iface_Prims
= 0 then
3691 Nb_Prim
:= Num_Iface_Prims
;
3696 -- Predef_Prims : Address_Array (1 .. Default_Prim_Ops_Count) :=
3697 -- (predef-prim-op-thunk-1'address,
3698 -- predef-prim-op-thunk-2'address,
3700 -- predef-prim-op-thunk-n'address);
3701 -- for Predef_Prims'Alignment use Address'Alignment
3703 -- Stage 1: Calculate the number of predefined primitives
3705 if not Building_Static_DT
(Typ
) then
3706 Nb_Predef_Prims
:= Max_Predef_Prims
;
3708 Prim_Elmt
:= First_Elmt
(Primitive_Operations
(Typ
));
3709 while Present
(Prim_Elmt
) loop
3710 Prim
:= Node
(Prim_Elmt
);
3712 if Is_Predefined_Dispatching_Operation
(Prim
)
3713 and then not Is_Abstract_Subprogram
(Prim
)
3715 Pos
:= UI_To_Int
(DT_Position
(Prim
));
3717 if Pos
> Nb_Predef_Prims
then
3718 Nb_Predef_Prims
:= Pos
;
3722 Next_Elmt
(Prim_Elmt
);
3726 -- Stage 2: Create the thunks associated with the predefined
3727 -- primitives and save their entity to fill the aggregate.
3730 Prim_Table
: array (Nat
range 1 .. Nb_Predef_Prims
) of Entity_Id
;
3732 Thunk_Id
: Entity_Id
;
3733 Thunk_Code
: Node_Id
;
3736 Prim_Ops_Aggr_List
:= New_List
;
3737 Prim_Table
:= (others => Empty
);
3739 if Building_Static_DT
(Typ
) then
3740 Prim_Elmt
:= First_Elmt
(Primitive_Operations
(Typ
));
3741 while Present
(Prim_Elmt
) loop
3742 Prim
:= Node
(Prim_Elmt
);
3744 if Is_Predefined_Dispatching_Operation
(Prim
)
3745 and then not Is_Abstract_Subprogram
(Prim
)
3746 and then not Is_Eliminated
(Prim
)
3747 and then not Present
(Prim_Table
3748 (UI_To_Int
(DT_Position
(Prim
))))
3750 if not Build_Thunks
then
3751 Prim_Table
(UI_To_Int
(DT_Position
(Prim
))) :=
3755 Expand_Interface_Thunk
3756 (Ultimate_Alias
(Prim
), Thunk_Id
, Thunk_Code
);
3758 if Present
(Thunk_Id
) then
3759 Append_To
(Result
, Thunk_Code
);
3760 Prim_Table
(UI_To_Int
(DT_Position
(Prim
)))
3766 Next_Elmt
(Prim_Elmt
);
3770 for J
in Prim_Table
'Range loop
3771 if Present
(Prim_Table
(J
)) then
3773 Unchecked_Convert_To
(RTE
(RE_Prim_Ptr
),
3774 Make_Attribute_Reference
(Loc
,
3775 Prefix
=> New_Reference_To
(Prim_Table
(J
), Loc
),
3776 Attribute_Name
=> Name_Unrestricted_Access
));
3778 New_Node
:= Make_Null
(Loc
);
3781 Append_To
(Prim_Ops_Aggr_List
, New_Node
);
3785 Make_Aggregate
(Loc
,
3786 Expressions
=> Prim_Ops_Aggr_List
);
3788 -- Remember aggregates initializing dispatch tables
3790 Append_Elmt
(New_Node
, DT_Aggr
);
3793 Make_Subtype_Declaration
(Loc
,
3794 Defining_Identifier
=> Make_Temporary
(Loc
, 'S'),
3795 Subtype_Indication
=>
3796 New_Reference_To
(RTE
(RE_Address_Array
), Loc
));
3798 Append_To
(Result
, Decl
);
3801 Make_Object_Declaration
(Loc
,
3802 Defining_Identifier
=> Predef_Prims
,
3803 Constant_Present
=> Building_Static_DT
(Typ
),
3804 Aliased_Present
=> True,
3805 Object_Definition
=> New_Reference_To
3806 (Defining_Identifier
(Decl
), Loc
),
3807 Expression
=> New_Node
));
3810 Make_Attribute_Definition_Clause
(Loc
,
3811 Name
=> New_Reference_To
(Predef_Prims
, Loc
),
3812 Chars
=> Name_Alignment
,
3814 Make_Attribute_Reference
(Loc
,
3816 New_Reference_To
(RTE
(RE_Integer_Address
), Loc
),
3817 Attribute_Name
=> Name_Alignment
)));
3822 -- OSD : Ada.Tags.Object_Specific_Data (Nb_Prims) :=
3823 -- (OSD_Table => (1 => <value>,
3827 -- Iface_DT : Dispatch_Table (Nb_Prims) :=
3828 -- ([ Signature => <sig-value> ],
3829 -- Tag_Kind => <tag_kind-value>,
3830 -- Predef_Prims => Predef_Prims'Address,
3831 -- Offset_To_Top => 0,
3832 -- OSD => OSD'Address,
3833 -- Prims_Ptr => (prim-op-1'address,
3834 -- prim-op-2'address,
3836 -- prim-op-n'address));
3837 -- for Iface_DT'Alignment use Address'Alignment;
3839 -- Stage 3: Initialize the discriminant and the record components
3841 DT_Constr_List
:= New_List
;
3842 DT_Aggr_List
:= New_List
;
3844 -- Nb_Prim. If the tagged type has no primitives we add a dummy
3845 -- slot whose address will be the tag of this type.
3848 New_Node
:= Make_Integer_Literal
(Loc
, 1);
3850 New_Node
:= Make_Integer_Literal
(Loc
, Nb_Prim
);
3853 Append_To
(DT_Constr_List
, New_Node
);
3854 Append_To
(DT_Aggr_List
, New_Copy
(New_Node
));
3858 if RTE_Record_Component_Available
(RE_Signature
) then
3859 Append_To
(DT_Aggr_List
,
3860 New_Reference_To
(RTE
(RE_Secondary_DT
), Loc
));
3865 if RTE_Record_Component_Available
(RE_Tag_Kind
) then
3866 Append_To
(DT_Aggr_List
, Tagged_Kind
(Typ
));
3871 Append_To
(DT_Aggr_List
,
3872 Make_Attribute_Reference
(Loc
,
3873 Prefix
=> New_Reference_To
(Predef_Prims
, Loc
),
3874 Attribute_Name
=> Name_Address
));
3876 -- Note: The correct value of Offset_To_Top will be set by the init
3879 Append_To
(DT_Aggr_List
, Make_Integer_Literal
(Loc
, 0));
3881 -- Generate the Object Specific Data table required to dispatch calls
3882 -- through synchronized interfaces.
3885 or else Is_Abstract_Type
(Typ
)
3886 or else Is_Controlled
(Typ
)
3887 or else Restriction_Active
(No_Dispatching_Calls
)
3888 or else not Is_Limited_Type
(Typ
)
3889 or else not Has_Interfaces
(Typ
)
3890 or else not Build_Thunks
3891 or else not RTE_Record_Component_Available
(RE_OSD_Table
)
3893 -- No OSD table required
3895 Append_To
(DT_Aggr_List
,
3896 New_Reference_To
(RTE
(RE_Null_Address
), Loc
));
3899 OSD_Aggr_List
:= New_List
;
3902 Prim_Table
: array (Nat
range 1 .. Nb_Prim
) of Entity_Id
;
3904 Prim_Alias
: Entity_Id
;
3905 Prim_Elmt
: Elmt_Id
;
3911 Prim_Table
:= (others => Empty
);
3912 Prim_Alias
:= Empty
;
3914 Prim_Elmt
:= First_Elmt
(Primitive_Operations
(Typ
));
3915 while Present
(Prim_Elmt
) loop
3916 Prim
:= Node
(Prim_Elmt
);
3918 if Present
(Interface_Alias
(Prim
))
3919 and then Find_Dispatching_Type
3920 (Interface_Alias
(Prim
)) = Iface
3922 Prim_Alias
:= Interface_Alias
(Prim
);
3923 E
:= Ultimate_Alias
(Prim
);
3924 Pos
:= UI_To_Int
(DT_Position
(Prim_Alias
));
3926 if Present
(Prim_Table
(Pos
)) then
3927 pragma Assert
(Prim_Table
(Pos
) = E
);
3931 Prim_Table
(Pos
) := E
;
3933 Append_To
(OSD_Aggr_List
,
3934 Make_Component_Association
(Loc
,
3935 Choices
=> New_List
(
3936 Make_Integer_Literal
(Loc
,
3937 DT_Position
(Prim_Alias
))),
3939 Make_Integer_Literal
(Loc
,
3940 DT_Position
(Alias
(Prim
)))));
3946 Next_Elmt
(Prim_Elmt
);
3948 pragma Assert
(Count
= Nb_Prim
);
3951 OSD
:= Make_Temporary
(Loc
, 'I');
3954 Make_Object_Declaration
(Loc
,
3955 Defining_Identifier
=> OSD
,
3956 Object_Definition
=>
3957 Make_Subtype_Indication
(Loc
,
3959 New_Reference_To
(RTE
(RE_Object_Specific_Data
), Loc
),
3961 Make_Index_Or_Discriminant_Constraint
(Loc
,
3962 Constraints
=> New_List
(
3963 Make_Integer_Literal
(Loc
, Nb_Prim
)))),
3966 Make_Aggregate
(Loc
,
3967 Component_Associations
=> New_List
(
3968 Make_Component_Association
(Loc
,
3969 Choices
=> New_List
(
3971 (RTE_Record_Component
(RE_OSD_Num_Prims
), Loc
)),
3973 Make_Integer_Literal
(Loc
, Nb_Prim
)),
3975 Make_Component_Association
(Loc
,
3976 Choices
=> New_List
(
3978 (RTE_Record_Component
(RE_OSD_Table
), Loc
)),
3979 Expression
=> Make_Aggregate
(Loc
,
3980 Component_Associations
=> OSD_Aggr_List
))))));
3983 Make_Attribute_Definition_Clause
(Loc
,
3984 Name
=> New_Reference_To
(OSD
, Loc
),
3985 Chars
=> Name_Alignment
,
3987 Make_Attribute_Reference
(Loc
,
3989 New_Reference_To
(RTE
(RE_Integer_Address
), Loc
),
3990 Attribute_Name
=> Name_Alignment
)));
3992 -- In secondary dispatch tables the Typeinfo component contains
3993 -- the address of the Object Specific Data (see a-tags.ads)
3995 Append_To
(DT_Aggr_List
,
3996 Make_Attribute_Reference
(Loc
,
3997 Prefix
=> New_Reference_To
(OSD
, Loc
),
3998 Attribute_Name
=> Name_Address
));
4001 -- Initialize the table of primitive operations
4003 Prim_Ops_Aggr_List
:= New_List
;
4006 Append_To
(Prim_Ops_Aggr_List
, Make_Null
(Loc
));
4008 elsif Is_Abstract_Type
(Typ
)
4009 or else not Static_Dispatch_Tables
4010 or else not Is_Library_Level_Tagged_Type
(Typ
)
4012 for J
in 1 .. Nb_Prim
loop
4013 Append_To
(Prim_Ops_Aggr_List
, Make_Null
(Loc
));
4018 CPP_Nb_Prims
: constant Nat
:= CPP_Num_Prims
(Typ
);
4021 Prim_Table
: array (Nat
range 1 .. Nb_Prim
) of Entity_Id
;
4022 Thunk_Code
: Node_Id
;
4023 Thunk_Id
: Entity_Id
;
4026 Prim_Table
:= (others => Empty
);
4028 Prim_Elmt
:= First_Elmt
(Primitive_Operations
(Typ
));
4029 while Present
(Prim_Elmt
) loop
4030 Prim
:= Node
(Prim_Elmt
);
4031 E
:= Ultimate_Alias
(Prim
);
4032 Prim_Pos
:= UI_To_Int
(DT_Position
(E
));
4034 -- Do not reference predefined primitives because they are
4035 -- located in a separate dispatch table; skip abstract and
4036 -- eliminated primitives; skip primitives located in the C++
4037 -- part of the dispatch table because their slot is set by
4040 if not Is_Predefined_Dispatching_Operation
(Prim
)
4041 and then Present
(Interface_Alias
(Prim
))
4042 and then not Is_Abstract_Subprogram
(Alias
(Prim
))
4043 and then not Is_Eliminated
(Alias
(Prim
))
4044 and then (not Is_CPP_Class
(Root_Type
(Typ
))
4045 or else Prim_Pos
> CPP_Nb_Prims
)
4046 and then Find_Dispatching_Type
4047 (Interface_Alias
(Prim
)) = Iface
4049 -- Generate the code of the thunk only if the abstract
4050 -- interface type is not an immediate ancestor of
4051 -- Tagged_Type. Otherwise the DT associated with the
4052 -- interface is the primary DT.
4054 and then not Is_Ancestor
(Iface
, Typ
)
4056 if not Build_Thunks
then
4058 UI_To_Int
(DT_Position
(Interface_Alias
(Prim
)));
4059 Prim_Table
(Prim_Pos
) := Alias
(Prim
);
4062 Expand_Interface_Thunk
(Prim
, Thunk_Id
, Thunk_Code
);
4064 if Present
(Thunk_Id
) then
4066 UI_To_Int
(DT_Position
(Interface_Alias
(Prim
)));
4068 Prim_Table
(Prim_Pos
) := Thunk_Id
;
4069 Append_To
(Result
, Thunk_Code
);
4074 Next_Elmt
(Prim_Elmt
);
4077 for J
in Prim_Table
'Range loop
4078 if Present
(Prim_Table
(J
)) then
4080 Unchecked_Convert_To
(RTE
(RE_Prim_Ptr
),
4081 Make_Attribute_Reference
(Loc
,
4082 Prefix
=> New_Reference_To
(Prim_Table
(J
), Loc
),
4083 Attribute_Name
=> Name_Unrestricted_Access
));
4086 New_Node
:= Make_Null
(Loc
);
4089 Append_To
(Prim_Ops_Aggr_List
, New_Node
);
4095 Make_Aggregate
(Loc
,
4096 Expressions
=> Prim_Ops_Aggr_List
);
4098 Append_To
(DT_Aggr_List
, New_Node
);
4100 -- Remember aggregates initializing dispatch tables
4102 Append_Elmt
(New_Node
, DT_Aggr
);
4104 -- Note: Secondary dispatch tables cannot be declared constant
4105 -- because the component Offset_To_Top is currently initialized
4106 -- by the IP routine.
4109 Make_Object_Declaration
(Loc
,
4110 Defining_Identifier
=> Iface_DT
,
4111 Aliased_Present
=> True,
4112 Constant_Present
=> False,
4114 Object_Definition
=>
4115 Make_Subtype_Indication
(Loc
,
4116 Subtype_Mark
=> New_Reference_To
4117 (RTE
(RE_Dispatch_Table_Wrapper
), Loc
),
4118 Constraint
=> Make_Index_Or_Discriminant_Constraint
(Loc
,
4119 Constraints
=> DT_Constr_List
)),
4122 Make_Aggregate
(Loc
,
4123 Expressions
=> DT_Aggr_List
)));
4126 Make_Attribute_Definition_Clause
(Loc
,
4127 Name
=> New_Reference_To
(Iface_DT
, Loc
),
4128 Chars
=> Name_Alignment
,
4131 Make_Attribute_Reference
(Loc
,
4133 New_Reference_To
(RTE
(RE_Integer_Address
), Loc
),
4134 Attribute_Name
=> Name_Alignment
)));
4136 if Exporting_Table
then
4137 Export_DT
(Typ
, Iface_DT
, Suffix_Index
);
4139 -- Generate code to create the pointer to the dispatch table
4141 -- Iface_DT_Ptr : Tag := Tag!(DT.Prims_Ptr'Address);
4143 -- Note: This declaration is not added here if the table is exported
4144 -- because in such case Make_Tags has already added this declaration.
4148 Make_Object_Declaration
(Loc
,
4149 Defining_Identifier
=> Iface_DT_Ptr
,
4150 Constant_Present
=> True,
4152 Object_Definition
=>
4153 New_Reference_To
(RTE
(RE_Interface_Tag
), Loc
),
4156 Unchecked_Convert_To
(RTE
(RE_Interface_Tag
),
4157 Make_Attribute_Reference
(Loc
,
4159 Make_Selected_Component
(Loc
,
4160 Prefix
=> New_Reference_To
(Iface_DT
, Loc
),
4163 (RTE_Record_Component
(RE_Prims_Ptr
), Loc
)),
4164 Attribute_Name
=> Name_Address
))));
4168 Make_Object_Declaration
(Loc
,
4169 Defining_Identifier
=> Predef_Prims_Ptr
,
4170 Constant_Present
=> True,
4172 Object_Definition
=>
4173 New_Reference_To
(RTE
(RE_Address
), Loc
),
4176 Make_Attribute_Reference
(Loc
,
4178 Make_Selected_Component
(Loc
,
4179 Prefix
=> New_Reference_To
(Iface_DT
, Loc
),
4182 (RTE_Record_Component
(RE_Predef_Prims
), Loc
)),
4183 Attribute_Name
=> Name_Address
)));
4185 -- Remember entities containing dispatch tables
4187 Append_Elmt
(Predef_Prims
, DT_Decl
);
4188 Append_Elmt
(Iface_DT
, DT_Decl
);
4189 end Make_Secondary_DT
;
4193 Elab_Code
: constant List_Id
:= New_List
;
4194 Result
: constant List_Id
:= New_List
;
4195 Tname
: constant Name_Id
:= Chars
(Typ
);
4197 AI_Tag_Elmt
: Elmt_Id
;
4198 AI_Tag_Comp
: Elmt_Id
;
4199 DT_Aggr_List
: List_Id
;
4200 DT_Constr_List
: List_Id
;
4204 Iface_Table_Node
: Node_Id
;
4205 Name_ITable
: Name_Id
;
4206 Nb_Predef_Prims
: Nat
:= 0;
4209 Num_Ifaces
: Nat
:= 0;
4210 Parent_Typ
: Entity_Id
;
4212 Prim_Elmt
: Elmt_Id
;
4213 Prim_Ops_Aggr_List
: List_Id
;
4215 Typ_Comps
: Elist_Id
;
4216 Typ_Ifaces
: Elist_Id
;
4217 TSD_Aggr_List
: List_Id
;
4218 TSD_Tags_List
: List_Id
;
4220 -- The following name entries are used by Make_DT to generate a number
4221 -- of entities related to a tagged type. These entities may be generated
4222 -- in a scope other than that of the tagged type declaration, and if
4223 -- the entities for two tagged types with the same name happen to be
4224 -- generated in the same scope, we have to take care to use different
4225 -- names. This is achieved by means of a unique serial number appended
4226 -- to each generated entity name.
4228 Name_DT
: constant Name_Id
:=
4229 New_External_Name
(Tname
, 'T', Suffix_Index
=> -1);
4230 Name_Exname
: constant Name_Id
:=
4231 New_External_Name
(Tname
, 'E', Suffix_Index
=> -1);
4232 Name_HT_Link
: constant Name_Id
:=
4233 New_External_Name
(Tname
, 'H', Suffix_Index
=> -1);
4234 Name_Predef_Prims
: constant Name_Id
:=
4235 New_External_Name
(Tname
, 'R', Suffix_Index
=> -1);
4236 Name_SSD
: constant Name_Id
:=
4237 New_External_Name
(Tname
, 'S', Suffix_Index
=> -1);
4238 Name_TSD
: constant Name_Id
:=
4239 New_External_Name
(Tname
, 'B', Suffix_Index
=> -1);
4241 -- Entities built with above names
4243 DT
: constant Entity_Id
:=
4244 Make_Defining_Identifier
(Loc
, Name_DT
);
4245 Exname
: constant Entity_Id
:=
4246 Make_Defining_Identifier
(Loc
, Name_Exname
);
4247 HT_Link
: constant Entity_Id
:=
4248 Make_Defining_Identifier
(Loc
, Name_HT_Link
);
4249 Predef_Prims
: constant Entity_Id
:=
4250 Make_Defining_Identifier
(Loc
, Name_Predef_Prims
);
4251 SSD
: constant Entity_Id
:=
4252 Make_Defining_Identifier
(Loc
, Name_SSD
);
4253 TSD
: constant Entity_Id
:=
4254 Make_Defining_Identifier
(Loc
, Name_TSD
);
4256 -- Start of processing for Make_DT
4259 pragma Assert
(Is_Frozen
(Typ
));
4261 -- Handle cases in which there is no need to build the dispatch table
4263 if Has_Dispatch_Table
(Typ
)
4264 or else No
(Access_Disp_Table
(Typ
))
4265 or else Is_CPP_Class
(Typ
)
4269 elsif No_Run_Time_Mode
then
4270 Error_Msg_CRT
("tagged types", Typ
);
4273 elsif not RTE_Available
(RE_Tag
) then
4275 Make_Object_Declaration
(Loc
,
4276 Defining_Identifier
=> Node
(First_Elmt
4277 (Access_Disp_Table
(Typ
))),
4278 Object_Definition
=> New_Reference_To
(RTE
(RE_Tag
), Loc
),
4279 Constant_Present
=> True,
4281 Unchecked_Convert_To
(RTE
(RE_Tag
),
4282 New_Reference_To
(RTE
(RE_Null_Address
), Loc
))));
4284 Analyze_List
(Result
, Suppress
=> All_Checks
);
4285 Error_Msg_CRT
("tagged types", Typ
);
4289 -- Ensure that the value of Max_Predef_Prims defined in a-tags is
4290 -- correct. Valid values are 10 under configurable runtime or 16
4291 -- with full runtime.
4293 if RTE_Available
(RE_Interface_Data
) then
4294 if Max_Predef_Prims
/= 16 then
4295 Error_Msg_N
("run-time library configuration error", Typ
);
4299 if Max_Predef_Prims
/= 10 then
4300 Error_Msg_N
("run-time library configuration error", Typ
);
4301 Error_Msg_CRT
("tagged types", Typ
);
4306 -- Initialize Parent_Typ handling private types
4308 Parent_Typ
:= Etype
(Typ
);
4310 if Present
(Full_View
(Parent_Typ
)) then
4311 Parent_Typ
:= Full_View
(Parent_Typ
);
4314 -- Ensure that all the primitives are frozen. This is only required when
4315 -- building static dispatch tables --- the primitives must be frozen to
4316 -- be referenced (otherwise we have problems with the backend). It is
4317 -- not a requirement with nonstatic dispatch tables because in this case
4318 -- we generate now an empty dispatch table; the extra code required to
4319 -- register the primitives in the slots will be generated later --- when
4320 -- each primitive is frozen (see Freeze_Subprogram).
4322 if Building_Static_DT
(Typ
) then
4324 Save
: constant Boolean := Freezing_Library_Level_Tagged_Type
;
4326 Prim_Elmt
: Elmt_Id
;
4330 Freezing_Library_Level_Tagged_Type
:= True;
4332 Prim_Elmt
:= First_Elmt
(Primitive_Operations
(Typ
));
4333 while Present
(Prim_Elmt
) loop
4334 Prim
:= Node
(Prim_Elmt
);
4335 Frnodes
:= Freeze_Entity
(Prim
, Loc
);
4341 F
:= First_Formal
(Prim
);
4342 while Present
(F
) loop
4343 Check_Premature_Freezing
(Prim
, Etype
(F
));
4347 Check_Premature_Freezing
(Prim
, Etype
(Prim
));
4350 if Present
(Frnodes
) then
4351 Append_List_To
(Result
, Frnodes
);
4354 Next_Elmt
(Prim_Elmt
);
4357 Freezing_Library_Level_Tagged_Type
:= Save
;
4361 -- Ada 2005 (AI-251): Build the secondary dispatch tables
4363 if Has_Interfaces
(Typ
) then
4364 Collect_Interface_Components
(Typ
, Typ_Comps
);
4366 -- Each secondary dispatch table is assigned an unique positive
4367 -- suffix index; such value also corresponds with the location of
4368 -- its entity in the Dispatch_Table_Wrappers list (see Make_Tags).
4370 -- Note: This value must be kept sync with the Suffix_Index values
4371 -- generated by Make_Tags
4375 Next_Elmt
(Next_Elmt
(First_Elmt
(Access_Disp_Table
(Typ
))));
4377 AI_Tag_Comp
:= First_Elmt
(Typ_Comps
);
4378 while Present
(AI_Tag_Comp
) loop
4379 pragma Assert
(Has_Suffix
(Node
(AI_Tag_Elmt
), 'P'));
4381 -- Build the secondary table containing pointers to thunks
4385 Iface
=> Base_Type
(Related_Type
(Node
(AI_Tag_Comp
))),
4386 Suffix_Index
=> Suffix_Index
,
4387 Num_Iface_Prims
=> UI_To_Int
4388 (DT_Entry_Count
(Node
(AI_Tag_Comp
))),
4389 Iface_DT_Ptr
=> Node
(AI_Tag_Elmt
),
4390 Predef_Prims_Ptr
=> Node
(Next_Elmt
(AI_Tag_Elmt
)),
4391 Build_Thunks
=> True,
4394 -- Skip secondary dispatch table referencing thunks to predefined
4397 Next_Elmt
(AI_Tag_Elmt
);
4398 pragma Assert
(Has_Suffix
(Node
(AI_Tag_Elmt
), 'Y'));
4400 -- Secondary dispatch table referencing user-defined primitives
4401 -- covered by this interface.
4403 Next_Elmt
(AI_Tag_Elmt
);
4404 pragma Assert
(Has_Suffix
(Node
(AI_Tag_Elmt
), 'D'));
4406 -- Build the secondary table containing pointers to primitives
4407 -- (used to give support to Generic Dispatching Constructors).
4412 (Related_Type
(Node
(AI_Tag_Comp
))),
4414 Num_Iface_Prims
=> UI_To_Int
4415 (DT_Entry_Count
(Node
(AI_Tag_Comp
))),
4416 Iface_DT_Ptr
=> Node
(AI_Tag_Elmt
),
4417 Predef_Prims_Ptr
=> Node
(Next_Elmt
(AI_Tag_Elmt
)),
4418 Build_Thunks
=> False,
4421 -- Skip secondary dispatch table referencing predefined primitives
4423 Next_Elmt
(AI_Tag_Elmt
);
4424 pragma Assert
(Has_Suffix
(Node
(AI_Tag_Elmt
), 'Z'));
4426 Suffix_Index
:= Suffix_Index
+ 1;
4427 Next_Elmt
(AI_Tag_Elmt
);
4428 Next_Elmt
(AI_Tag_Comp
);
4432 -- Get the _tag entity and the number of primitives of its dispatch
4435 DT_Ptr
:= Node
(First_Elmt
(Access_Disp_Table
(Typ
)));
4436 Nb_Prim
:= UI_To_Int
(DT_Entry_Count
(First_Tag_Component
(Typ
)));
4438 Set_Is_Statically_Allocated
(DT
, Is_Library_Level_Tagged_Type
(Typ
));
4439 Set_Is_Statically_Allocated
(SSD
, Is_Library_Level_Tagged_Type
(Typ
));
4440 Set_Is_Statically_Allocated
(TSD
, Is_Library_Level_Tagged_Type
(Typ
));
4441 Set_Is_Statically_Allocated
(Predef_Prims
,
4442 Is_Library_Level_Tagged_Type
(Typ
));
4444 -- In case of locally defined tagged type we declare the object
4445 -- containing the dispatch table by means of a variable. Its
4446 -- initialization is done later by means of an assignment. This is
4447 -- required to generate its External_Tag.
4449 if not Building_Static_DT
(Typ
) then
4452 -- DT : No_Dispatch_Table_Wrapper;
4453 -- for DT'Alignment use Address'Alignment;
4454 -- DT_Ptr : Tag := !Tag (DT.NDT_Prims_Ptr'Address);
4456 if not Has_DT
(Typ
) then
4458 Make_Object_Declaration
(Loc
,
4459 Defining_Identifier
=> DT
,
4460 Aliased_Present
=> True,
4461 Constant_Present
=> False,
4462 Object_Definition
=>
4464 (RTE
(RE_No_Dispatch_Table_Wrapper
), Loc
)));
4467 Make_Attribute_Definition_Clause
(Loc
,
4468 Name
=> New_Reference_To
(DT
, Loc
),
4469 Chars
=> Name_Alignment
,
4471 Make_Attribute_Reference
(Loc
,
4473 New_Reference_To
(RTE
(RE_Integer_Address
), Loc
),
4474 Attribute_Name
=> Name_Alignment
)));
4477 Make_Object_Declaration
(Loc
,
4478 Defining_Identifier
=> DT_Ptr
,
4479 Object_Definition
=> New_Reference_To
(RTE
(RE_Tag
), Loc
),
4480 Constant_Present
=> True,
4482 Unchecked_Convert_To
(RTE
(RE_Tag
),
4483 Make_Attribute_Reference
(Loc
,
4485 Make_Selected_Component
(Loc
,
4486 Prefix
=> New_Reference_To
(DT
, Loc
),
4489 (RTE_Record_Component
(RE_NDT_Prims_Ptr
), Loc
)),
4490 Attribute_Name
=> Name_Address
))));
4492 Set_Is_Statically_Allocated
(DT_Ptr
,
4493 Is_Library_Level_Tagged_Type
(Typ
));
4495 -- Generate the SCIL node for the previous object declaration
4496 -- because it has a tag initialization.
4498 if Generate_SCIL
then
4500 Make_SCIL_Dispatch_Table_Tag_Init
(Sloc
(Last
(Result
)));
4501 Set_SCIL_Entity
(New_Node
, Typ
);
4502 Set_SCIL_Node
(Last
(Result
), New_Node
);
4506 -- DT : Dispatch_Table_Wrapper (Nb_Prim);
4507 -- for DT'Alignment use Address'Alignment;
4508 -- DT_Ptr : Tag := !Tag (DT.Prims_Ptr'Address);
4511 -- If the tagged type has no primitives we add a dummy slot
4512 -- whose address will be the tag of this type.
4516 New_List
(Make_Integer_Literal
(Loc
, 1));
4519 New_List
(Make_Integer_Literal
(Loc
, Nb_Prim
));
4523 Make_Object_Declaration
(Loc
,
4524 Defining_Identifier
=> DT
,
4525 Aliased_Present
=> True,
4526 Constant_Present
=> False,
4527 Object_Definition
=>
4528 Make_Subtype_Indication
(Loc
,
4530 New_Reference_To
(RTE
(RE_Dispatch_Table_Wrapper
), Loc
),
4531 Constraint
=> Make_Index_Or_Discriminant_Constraint
(Loc
,
4532 Constraints
=> DT_Constr_List
))));
4535 Make_Attribute_Definition_Clause
(Loc
,
4536 Name
=> New_Reference_To
(DT
, Loc
),
4537 Chars
=> Name_Alignment
,
4539 Make_Attribute_Reference
(Loc
,
4541 New_Reference_To
(RTE
(RE_Integer_Address
), Loc
),
4542 Attribute_Name
=> Name_Alignment
)));
4545 Make_Object_Declaration
(Loc
,
4546 Defining_Identifier
=> DT_Ptr
,
4547 Object_Definition
=> New_Reference_To
(RTE
(RE_Tag
), Loc
),
4548 Constant_Present
=> True,
4550 Unchecked_Convert_To
(RTE
(RE_Tag
),
4551 Make_Attribute_Reference
(Loc
,
4553 Make_Selected_Component
(Loc
,
4554 Prefix
=> New_Reference_To
(DT
, Loc
),
4557 (RTE_Record_Component
(RE_Prims_Ptr
), Loc
)),
4558 Attribute_Name
=> Name_Address
))));
4560 Set_Is_Statically_Allocated
(DT_Ptr
,
4561 Is_Library_Level_Tagged_Type
(Typ
));
4563 -- Generate the SCIL node for the previous object declaration
4564 -- because it has a tag initialization.
4566 if Generate_SCIL
then
4568 Make_SCIL_Dispatch_Table_Tag_Init
(Sloc
(Last
(Result
)));
4569 Set_SCIL_Entity
(New_Node
, Typ
);
4570 Set_SCIL_Node
(Last
(Result
), New_Node
);
4574 Make_Object_Declaration
(Loc
,
4575 Defining_Identifier
=>
4576 Node
(Next_Elmt
(First_Elmt
(Access_Disp_Table
(Typ
)))),
4577 Constant_Present
=> True,
4578 Object_Definition
=> New_Reference_To
4579 (RTE
(RE_Address
), Loc
),
4581 Make_Attribute_Reference
(Loc
,
4583 Make_Selected_Component
(Loc
,
4584 Prefix
=> New_Reference_To
(DT
, Loc
),
4587 (RTE_Record_Component
(RE_Predef_Prims
), Loc
)),
4588 Attribute_Name
=> Name_Address
)));
4592 -- Generate: Exname : constant String := full_qualified_name (typ);
4593 -- The type itself may be an anonymous parent type, so use the first
4594 -- subtype to have a user-recognizable name.
4597 Make_Object_Declaration
(Loc
,
4598 Defining_Identifier
=> Exname
,
4599 Constant_Present
=> True,
4600 Object_Definition
=> New_Reference_To
(Standard_String
, Loc
),
4602 Make_String_Literal
(Loc
,
4603 Full_Qualified_Name
(First_Subtype
(Typ
)))));
4605 Set_Is_Statically_Allocated
(Exname
);
4606 Set_Is_True_Constant
(Exname
);
4608 -- Declare the object used by Ada.Tags.Register_Tag
4610 if RTE_Available
(RE_Register_Tag
) then
4612 Make_Object_Declaration
(Loc
,
4613 Defining_Identifier
=> HT_Link
,
4614 Object_Definition
=> New_Reference_To
(RTE
(RE_Tag
), Loc
)));
4617 -- Generate code to create the storage for the type specific data object
4618 -- with enough space to store the tags of the ancestors plus the tags
4619 -- of all the implemented interfaces (as described in a-tags.adb).
4621 -- TSD : Type_Specific_Data (I_Depth) :=
4622 -- (Idepth => I_Depth,
4623 -- Access_Level => Type_Access_Level (Typ),
4624 -- Expanded_Name => Cstring_Ptr!(Exname'Address))
4625 -- External_Tag => Cstring_Ptr!(Exname'Address))
4626 -- HT_Link => HT_Link'Address,
4627 -- Transportable => <<boolean-value>>,
4628 -- RC_Offset => <<integer-value>>,
4629 -- [ Size_Func => Size_Prim'Access ]
4630 -- [ Interfaces_Table => <<access-value>> ]
4631 -- [ SSD => SSD_Table'Address ]
4632 -- Tags_Table => (0 => null,
4635 -- for TSD'Alignment use Address'Alignment
4637 TSD_Aggr_List
:= New_List
;
4639 -- Idepth: Count ancestors to compute the inheritance depth. For private
4640 -- extensions, always go to the full view in order to compute the real
4641 -- inheritance depth.
4644 Current_Typ
: Entity_Id
;
4645 Parent_Typ
: Entity_Id
;
4651 Parent_Typ
:= Etype
(Current_Typ
);
4653 if Is_Private_Type
(Parent_Typ
) then
4654 Parent_Typ
:= Full_View
(Base_Type
(Parent_Typ
));
4657 exit when Parent_Typ
= Current_Typ
;
4659 I_Depth
:= I_Depth
+ 1;
4660 Current_Typ
:= Parent_Typ
;
4664 Append_To
(TSD_Aggr_List
,
4665 Make_Integer_Literal
(Loc
, I_Depth
));
4669 Append_To
(TSD_Aggr_List
,
4670 Make_Integer_Literal
(Loc
, Type_Access_Level
(Typ
)));
4674 Append_To
(TSD_Aggr_List
,
4675 Unchecked_Convert_To
(RTE
(RE_Cstring_Ptr
),
4676 Make_Attribute_Reference
(Loc
,
4677 Prefix
=> New_Reference_To
(Exname
, Loc
),
4678 Attribute_Name
=> Name_Address
)));
4680 -- External_Tag of a local tagged type
4682 -- <typ>A : constant String :=
4683 -- "Internal tag at 16#tag-addr#: <full-name-of-typ>";
4685 -- The reason we generate this strange name is that we do not want to
4686 -- enter local tagged types in the global hash table used to compute
4687 -- the Internal_Tag attribute for two reasons:
4689 -- 1. It is hard to avoid a tasking race condition for entering the
4690 -- entry into the hash table.
4692 -- 2. It would cause a storage leak, unless we rig up considerable
4693 -- mechanism to remove the entry from the hash table on exit.
4695 -- So what we do is to generate the above external tag name, where the
4696 -- hex address is the address of the local dispatch table (i.e. exactly
4697 -- the value we want if Internal_Tag is computed from this string).
4699 -- Of course this value will only be valid if the tagged type is still
4700 -- in scope, but it clearly must be erroneous to compute the internal
4701 -- tag of a tagged type that is out of scope!
4703 -- We don't do this processing if an explicit external tag has been
4704 -- specified. That's an odd case for which we have already issued a
4705 -- warning, where we will not be able to compute the internal tag.
4707 if not Is_Library_Level_Entity
(Typ
)
4708 and then not Has_External_Tag_Rep_Clause
(Typ
)
4711 Exname
: constant Entity_Id
:=
4712 Make_Defining_Identifier
(Loc
,
4713 New_External_Name
(Tname
, 'A'));
4715 Full_Name
: constant String_Id
:=
4716 Full_Qualified_Name
(First_Subtype
(Typ
));
4717 Str1_Id
: String_Id
;
4718 Str2_Id
: String_Id
;
4722 -- Str1 = "Internal tag at 16#";
4725 Store_String_Chars
("Internal tag at 16#");
4726 Str1_Id
:= End_String
;
4729 -- Str2 = "#: <type-full-name>";
4732 Store_String_Chars
("#: ");
4733 Store_String_Chars
(Full_Name
);
4734 Str2_Id
:= End_String
;
4737 -- Exname : constant String :=
4738 -- Str1 & Address_Image (Tag) & Str2;
4740 if RTE_Available
(RE_Address_Image
) then
4742 Make_Object_Declaration
(Loc
,
4743 Defining_Identifier
=> Exname
,
4744 Constant_Present
=> True,
4745 Object_Definition
=> New_Reference_To
4746 (Standard_String
, Loc
),
4748 Make_Op_Concat
(Loc
,
4750 Make_String_Literal
(Loc
, Str1_Id
),
4752 Make_Op_Concat
(Loc
,
4754 Make_Function_Call
(Loc
,
4757 (RTE
(RE_Address_Image
), Loc
),
4758 Parameter_Associations
=> New_List
(
4759 Unchecked_Convert_To
(RTE
(RE_Address
),
4760 New_Reference_To
(DT_Ptr
, Loc
)))),
4762 Make_String_Literal
(Loc
, Str2_Id
)))));
4766 Make_Object_Declaration
(Loc
,
4767 Defining_Identifier
=> Exname
,
4768 Constant_Present
=> True,
4769 Object_Definition
=> New_Reference_To
4770 (Standard_String
, Loc
),
4772 Make_Op_Concat
(Loc
,
4774 Make_String_Literal
(Loc
, Str1_Id
),
4776 Make_String_Literal
(Loc
, Str2_Id
))));
4780 Unchecked_Convert_To
(RTE
(RE_Cstring_Ptr
),
4781 Make_Attribute_Reference
(Loc
,
4782 Prefix
=> New_Reference_To
(Exname
, Loc
),
4783 Attribute_Name
=> Name_Address
));
4786 -- External tag of a library-level tagged type: Check for a definition
4787 -- of External_Tag. The clause is considered only if it applies to this
4788 -- specific tagged type, as opposed to one of its ancestors.
4789 -- If the type is an unconstrained type extension, we are building the
4790 -- dispatch table of its anonymous base type, so the external tag, if
4791 -- any was specified, must be retrieved from the first subtype. Go to
4792 -- the full view in case the clause is in the private part.
4796 Def
: constant Node_Id
:= Get_Attribute_Definition_Clause
4797 (Underlying_Type
(First_Subtype
(Typ
)),
4798 Attribute_External_Tag
);
4800 Old_Val
: String_Id
;
4801 New_Val
: String_Id
;
4805 if not Present
(Def
)
4806 or else Entity
(Name
(Def
)) /= First_Subtype
(Typ
)
4809 Unchecked_Convert_To
(RTE
(RE_Cstring_Ptr
),
4810 Make_Attribute_Reference
(Loc
,
4811 Prefix
=> New_Reference_To
(Exname
, Loc
),
4812 Attribute_Name
=> Name_Address
));
4814 Old_Val
:= Strval
(Expr_Value_S
(Expression
(Def
)));
4816 -- For the rep clause "for <typ>'external_tag use y" generate:
4818 -- <typ>A : constant string := y;
4820 -- <typ>A'Address is used to set the External_Tag component
4823 -- Create a new nul terminated string if it is not already
4825 if String_Length
(Old_Val
) > 0
4827 Get_String_Char
(Old_Val
, String_Length
(Old_Val
)) = 0
4831 Start_String
(Old_Val
);
4832 Store_String_Char
(Get_Char_Code
(ASCII
.NUL
));
4833 New_Val
:= End_String
;
4836 E
:= Make_Defining_Identifier
(Loc
,
4837 New_External_Name
(Chars
(Typ
), 'A'));
4840 Make_Object_Declaration
(Loc
,
4841 Defining_Identifier
=> E
,
4842 Constant_Present
=> True,
4843 Object_Definition
=>
4844 New_Reference_To
(Standard_String
, Loc
),
4846 Make_String_Literal
(Loc
, New_Val
)));
4849 Unchecked_Convert_To
(RTE
(RE_Cstring_Ptr
),
4850 Make_Attribute_Reference
(Loc
,
4851 Prefix
=> New_Reference_To
(E
, Loc
),
4852 Attribute_Name
=> Name_Address
));
4857 Append_To
(TSD_Aggr_List
, New_Node
);
4861 if RTE_Available
(RE_Register_Tag
) then
4862 Append_To
(TSD_Aggr_List
,
4863 Unchecked_Convert_To
(RTE
(RE_Tag_Ptr
),
4864 Make_Attribute_Reference
(Loc
,
4865 Prefix
=> New_Reference_To
(HT_Link
, Loc
),
4866 Attribute_Name
=> Name_Address
)));
4868 Append_To
(TSD_Aggr_List
,
4869 Unchecked_Convert_To
(RTE
(RE_Tag_Ptr
),
4870 New_Reference_To
(RTE
(RE_Null_Address
), Loc
)));
4873 -- Transportable: Set for types that can be used in remote calls
4874 -- with respect to E.4(18) legality rules.
4877 Transportable
: Entity_Id
;
4883 or else Is_Shared_Passive
(Typ
)
4885 ((Is_Remote_Types
(Typ
)
4886 or else Is_Remote_Call_Interface
(Typ
))
4887 and then Original_View_In_Visible_Part
(Typ
))
4888 or else not Comes_From_Source
(Typ
));
4890 Append_To
(TSD_Aggr_List
,
4891 New_Occurrence_Of
(Transportable
, Loc
));
4894 -- RC_Offset: These are the valid values and their meaning:
4896 -- >0: For simple types with controlled components is
4897 -- type._record_controller'position
4899 -- 0: For types with no controlled components
4901 -- -1: For complex types with controlled components where the position
4902 -- of the record controller is not statically computable but there
4903 -- are controlled components at this level. The _Controller field
4904 -- is available right after the _parent.
4906 -- -2: There are no controlled components at this level. We need to
4907 -- get the position from the parent.
4910 RC_Offset_Node
: Node_Id
;
4913 if not Has_Controlled_Component
(Typ
) then
4914 RC_Offset_Node
:= Make_Integer_Literal
(Loc
, 0);
4916 elsif Etype
(Typ
) /= Typ
4917 and then Has_Discriminants
(Parent_Typ
)
4919 if Has_New_Controlled_Component
(Typ
) then
4920 RC_Offset_Node
:= Make_Integer_Literal
(Loc
, -1);
4922 RC_Offset_Node
:= Make_Integer_Literal
(Loc
, -2);
4926 Make_Attribute_Reference
(Loc
,
4928 Make_Selected_Component
(Loc
,
4929 Prefix
=> New_Reference_To
(Typ
, Loc
),
4931 New_Reference_To
(Controller_Component
(Typ
), Loc
)),
4932 Attribute_Name
=> Name_Position
);
4934 -- This is not proper Ada code to use the attribute 'Position
4935 -- on something else than an object but this is supported by
4936 -- the back end (see comment on the Bit_Component attribute in
4937 -- sem_attr). So we avoid semantic checking here.
4939 -- Is this documented in sinfo.ads??? it should be!
4941 Set_Analyzed
(RC_Offset_Node
);
4942 Set_Etype
(Prefix
(RC_Offset_Node
), RTE
(RE_Record_Controller
));
4943 Set_Etype
(Prefix
(Prefix
(RC_Offset_Node
)), Typ
);
4944 Set_Etype
(Selector_Name
(Prefix
(RC_Offset_Node
)),
4945 RTE
(RE_Record_Controller
));
4946 Set_Etype
(RC_Offset_Node
, RTE
(RE_Storage_Offset
));
4949 Append_To
(TSD_Aggr_List
, RC_Offset_Node
);
4954 if RTE_Record_Component_Available
(RE_Size_Func
) then
4956 -- Initialize this field to Null_Address if we are not building
4957 -- static dispatch tables static or if the size function is not
4958 -- available. In the former case we cannot initialize this field
4959 -- until the function is frozen and registered in the dispatch
4960 -- table (see Register_Primitive).
4962 if not Building_Static_DT
(Typ
) or else not Has_DT
(Typ
) then
4963 Append_To
(TSD_Aggr_List
,
4964 Unchecked_Convert_To
(RTE
(RE_Size_Ptr
),
4965 New_Reference_To
(RTE
(RE_Null_Address
), Loc
)));
4969 Prim_Elmt
: Elmt_Id
;
4973 Prim_Elmt
:= First_Elmt
(Primitive_Operations
(Typ
));
4974 while Present
(Prim_Elmt
) loop
4975 Prim
:= Node
(Prim_Elmt
);
4977 if Chars
(Prim
) = Name_uSize
then
4978 Prim
:= Ultimate_Alias
(Prim
);
4980 if Is_Abstract_Subprogram
(Prim
) then
4981 Append_To
(TSD_Aggr_List
,
4982 Unchecked_Convert_To
(RTE
(RE_Size_Ptr
),
4983 New_Reference_To
(RTE
(RE_Null_Address
), Loc
)));
4985 Append_To
(TSD_Aggr_List
,
4986 Unchecked_Convert_To
(RTE
(RE_Size_Ptr
),
4987 Make_Attribute_Reference
(Loc
,
4988 Prefix
=> New_Reference_To
(Prim
, Loc
),
4989 Attribute_Name
=> Name_Unrestricted_Access
)));
4995 Next_Elmt
(Prim_Elmt
);
5001 -- Interfaces_Table (required for AI-405)
5003 if RTE_Record_Component_Available
(RE_Interfaces_Table
) then
5005 -- Count the number of interface types implemented by Typ
5007 Collect_Interfaces
(Typ
, Typ_Ifaces
);
5009 AI
:= First_Elmt
(Typ_Ifaces
);
5010 while Present
(AI
) loop
5011 Num_Ifaces
:= Num_Ifaces
+ 1;
5015 if Num_Ifaces
= 0 then
5016 Iface_Table_Node
:= Make_Null
(Loc
);
5018 -- Generate the Interface_Table object
5022 TSD_Ifaces_List
: constant List_Id
:= New_List
;
5024 Sec_DT_Tag
: Node_Id
;
5027 AI
:= First_Elmt
(Typ_Ifaces
);
5028 while Present
(AI
) loop
5029 if Is_Ancestor
(Node
(AI
), Typ
) then
5031 New_Reference_To
(DT_Ptr
, Loc
);
5035 (Next_Elmt
(First_Elmt
(Access_Disp_Table
(Typ
))));
5036 pragma Assert
(Has_Thunks
(Node
(Elmt
)));
5038 while Is_Tag
(Node
(Elmt
))
5040 Is_Ancestor
(Node
(AI
), Related_Type
(Node
(Elmt
)))
5042 pragma Assert
(Has_Thunks
(Node
(Elmt
)));
5044 pragma Assert
(Has_Thunks
(Node
(Elmt
)));
5046 pragma Assert
(not Has_Thunks
(Node
(Elmt
)));
5048 pragma Assert
(not Has_Thunks
(Node
(Elmt
)));
5052 pragma Assert
(Ekind
(Node
(Elmt
)) = E_Constant
5054 Has_Thunks
(Node
(Next_Elmt
(Next_Elmt
(Elmt
)))));
5056 New_Reference_To
(Node
(Next_Elmt
(Next_Elmt
(Elmt
))),
5060 Append_To
(TSD_Ifaces_List
,
5061 Make_Aggregate
(Loc
,
5062 Expressions
=> New_List
(
5066 Unchecked_Convert_To
(RTE
(RE_Tag
),
5068 (Node
(First_Elmt
(Access_Disp_Table
(Node
(AI
)))),
5071 -- Static_Offset_To_Top
5073 New_Reference_To
(Standard_True
, Loc
),
5075 -- Offset_To_Top_Value
5077 Make_Integer_Literal
(Loc
, 0),
5079 -- Offset_To_Top_Func
5085 Unchecked_Convert_To
(RTE
(RE_Tag
), Sec_DT_Tag
)
5092 Name_ITable
:= New_External_Name
(Tname
, 'I');
5093 ITable
:= Make_Defining_Identifier
(Loc
, Name_ITable
);
5094 Set_Is_Statically_Allocated
(ITable
,
5095 Is_Library_Level_Tagged_Type
(Typ
));
5097 -- The table of interfaces is not constant; its slots are
5098 -- filled at run time by the IP routine using attribute
5099 -- 'Position to know the location of the tag components
5100 -- (and this attribute cannot be safely used before the
5101 -- object is initialized).
5104 Make_Object_Declaration
(Loc
,
5105 Defining_Identifier
=> ITable
,
5106 Aliased_Present
=> True,
5107 Constant_Present
=> False,
5108 Object_Definition
=>
5109 Make_Subtype_Indication
(Loc
,
5111 New_Reference_To
(RTE
(RE_Interface_Data
), Loc
),
5112 Constraint
=> Make_Index_Or_Discriminant_Constraint
5114 Constraints
=> New_List
(
5115 Make_Integer_Literal
(Loc
, Num_Ifaces
)))),
5117 Expression
=> Make_Aggregate
(Loc
,
5118 Expressions
=> New_List
(
5119 Make_Integer_Literal
(Loc
, Num_Ifaces
),
5120 Make_Aggregate
(Loc
,
5121 Expressions
=> TSD_Ifaces_List
)))));
5124 Make_Attribute_Definition_Clause
(Loc
,
5125 Name
=> New_Reference_To
(ITable
, Loc
),
5126 Chars
=> Name_Alignment
,
5128 Make_Attribute_Reference
(Loc
,
5130 New_Reference_To
(RTE
(RE_Integer_Address
), Loc
),
5131 Attribute_Name
=> Name_Alignment
)));
5134 Make_Attribute_Reference
(Loc
,
5135 Prefix
=> New_Reference_To
(ITable
, Loc
),
5136 Attribute_Name
=> Name_Unchecked_Access
);
5140 Append_To
(TSD_Aggr_List
, Iface_Table_Node
);
5143 -- Generate the Select Specific Data table for synchronized types that
5144 -- implement synchronized interfaces. The size of the table is
5145 -- constrained by the number of non-predefined primitive operations.
5147 if RTE_Record_Component_Available
(RE_SSD
) then
5148 if Ada_Version
>= Ada_05
5149 and then Has_DT
(Typ
)
5150 and then Is_Concurrent_Record_Type
(Typ
)
5151 and then Has_Interfaces
(Typ
)
5152 and then Nb_Prim
> 0
5153 and then not Is_Abstract_Type
(Typ
)
5154 and then not Is_Controlled
(Typ
)
5155 and then not Restriction_Active
(No_Dispatching_Calls
)
5156 and then not Restriction_Active
(No_Select_Statements
)
5159 Make_Object_Declaration
(Loc
,
5160 Defining_Identifier
=> SSD
,
5161 Aliased_Present
=> True,
5162 Object_Definition
=>
5163 Make_Subtype_Indication
(Loc
,
5164 Subtype_Mark
=> New_Reference_To
(
5165 RTE
(RE_Select_Specific_Data
), Loc
),
5167 Make_Index_Or_Discriminant_Constraint
(Loc
,
5168 Constraints
=> New_List
(
5169 Make_Integer_Literal
(Loc
, Nb_Prim
))))));
5172 Make_Attribute_Definition_Clause
(Loc
,
5173 Name
=> New_Reference_To
(SSD
, Loc
),
5174 Chars
=> Name_Alignment
,
5176 Make_Attribute_Reference
(Loc
,
5178 New_Reference_To
(RTE
(RE_Integer_Address
), Loc
),
5179 Attribute_Name
=> Name_Alignment
)));
5181 -- This table is initialized by Make_Select_Specific_Data_Table,
5182 -- which calls Set_Entry_Index and Set_Prim_Op_Kind.
5184 Append_To
(TSD_Aggr_List
,
5185 Make_Attribute_Reference
(Loc
,
5186 Prefix
=> New_Reference_To
(SSD
, Loc
),
5187 Attribute_Name
=> Name_Unchecked_Access
));
5189 Append_To
(TSD_Aggr_List
, Make_Null
(Loc
));
5193 -- Initialize the table of ancestor tags. In case of interface types
5194 -- this table is not needed.
5196 TSD_Tags_List
:= New_List
;
5198 -- If we are not statically allocating the dispatch table then we must
5199 -- fill position 0 with null because we still have not generated the
5202 if not Building_Static_DT
(Typ
)
5203 or else Is_Interface
(Typ
)
5205 Append_To
(TSD_Tags_List
,
5206 Unchecked_Convert_To
(RTE
(RE_Tag
),
5207 New_Reference_To
(RTE
(RE_Null_Address
), Loc
)));
5209 -- Otherwise we can safely reference the tag
5212 Append_To
(TSD_Tags_List
,
5213 New_Reference_To
(DT_Ptr
, Loc
));
5216 -- Fill the rest of the table with the tags of the ancestors
5219 Current_Typ
: Entity_Id
;
5220 Parent_Typ
: Entity_Id
;
5228 Parent_Typ
:= Etype
(Current_Typ
);
5230 if Is_Private_Type
(Parent_Typ
) then
5231 Parent_Typ
:= Full_View
(Base_Type
(Parent_Typ
));
5234 exit when Parent_Typ
= Current_Typ
;
5236 if Is_CPP_Class
(Parent_Typ
) then
5238 -- The tags defined in the C++ side will be inherited when
5239 -- the object is constructed (Exp_Ch3.Build_Init_Procedure)
5241 Append_To
(TSD_Tags_List
,
5242 Unchecked_Convert_To
(RTE
(RE_Tag
),
5243 New_Reference_To
(RTE
(RE_Null_Address
), Loc
)));
5245 Append_To
(TSD_Tags_List
,
5247 (Node
(First_Elmt
(Access_Disp_Table
(Parent_Typ
))),
5252 Current_Typ
:= Parent_Typ
;
5255 pragma Assert
(Pos
= I_Depth
+ 1);
5258 Append_To
(TSD_Aggr_List
,
5259 Make_Aggregate
(Loc
,
5260 Expressions
=> TSD_Tags_List
));
5262 -- Build the TSD object
5265 Make_Object_Declaration
(Loc
,
5266 Defining_Identifier
=> TSD
,
5267 Aliased_Present
=> True,
5268 Constant_Present
=> Building_Static_DT
(Typ
),
5269 Object_Definition
=>
5270 Make_Subtype_Indication
(Loc
,
5271 Subtype_Mark
=> New_Reference_To
(
5272 RTE
(RE_Type_Specific_Data
), Loc
),
5274 Make_Index_Or_Discriminant_Constraint
(Loc
,
5275 Constraints
=> New_List
(
5276 Make_Integer_Literal
(Loc
, I_Depth
)))),
5278 Expression
=> Make_Aggregate
(Loc
,
5279 Expressions
=> TSD_Aggr_List
)));
5281 Set_Is_True_Constant
(TSD
, Building_Static_DT
(Typ
));
5284 Make_Attribute_Definition_Clause
(Loc
,
5285 Name
=> New_Reference_To
(TSD
, Loc
),
5286 Chars
=> Name_Alignment
,
5288 Make_Attribute_Reference
(Loc
,
5289 Prefix
=> New_Reference_To
(RTE
(RE_Integer_Address
), Loc
),
5290 Attribute_Name
=> Name_Alignment
)));
5292 -- Initialize or declare the dispatch table object
5294 if not Has_DT
(Typ
) then
5295 DT_Constr_List
:= New_List
;
5296 DT_Aggr_List
:= New_List
;
5301 Make_Attribute_Reference
(Loc
,
5302 Prefix
=> New_Reference_To
(TSD
, Loc
),
5303 Attribute_Name
=> Name_Address
);
5305 Append_To
(DT_Constr_List
, New_Node
);
5306 Append_To
(DT_Aggr_List
, New_Copy
(New_Node
));
5307 Append_To
(DT_Aggr_List
, Make_Integer_Literal
(Loc
, 0));
5309 -- In case of locally defined tagged types we have already declared
5310 -- and uninitialized object for the dispatch table, which is now
5311 -- initialized by means of the following assignment:
5313 -- DT := (TSD'Address, 0);
5315 if not Building_Static_DT
(Typ
) then
5317 Make_Assignment_Statement
(Loc
,
5318 Name
=> New_Reference_To
(DT
, Loc
),
5319 Expression
=> Make_Aggregate
(Loc
,
5320 Expressions
=> DT_Aggr_List
)));
5322 -- In case of library level tagged types we declare and export now
5323 -- the constant object containing the dummy dispatch table. There
5324 -- is no need to declare the tag here because it has been previously
5325 -- declared by Make_Tags
5327 -- DT : aliased constant No_Dispatch_Table :=
5328 -- (NDT_TSD => TSD'Address;
5329 -- NDT_Prims_Ptr => 0);
5330 -- for DT'Alignment use Address'Alignment;
5334 Make_Object_Declaration
(Loc
,
5335 Defining_Identifier
=> DT
,
5336 Aliased_Present
=> True,
5337 Constant_Present
=> True,
5338 Object_Definition
=>
5339 New_Reference_To
(RTE
(RE_No_Dispatch_Table_Wrapper
), Loc
),
5340 Expression
=> Make_Aggregate
(Loc
,
5341 Expressions
=> DT_Aggr_List
)));
5344 Make_Attribute_Definition_Clause
(Loc
,
5345 Name
=> New_Reference_To
(DT
, Loc
),
5346 Chars
=> Name_Alignment
,
5348 Make_Attribute_Reference
(Loc
,
5350 New_Reference_To
(RTE
(RE_Integer_Address
), Loc
),
5351 Attribute_Name
=> Name_Alignment
)));
5353 Export_DT
(Typ
, DT
);
5356 -- Common case: Typ has a dispatch table
5360 -- Predef_Prims : Address_Array (1 .. Default_Prim_Ops_Count) :=
5361 -- (predef-prim-op-1'address,
5362 -- predef-prim-op-2'address,
5364 -- predef-prim-op-n'address);
5365 -- for Predef_Prims'Alignment use Address'Alignment
5367 -- DT : Dispatch_Table (Nb_Prims) :=
5368 -- (Signature => <sig-value>,
5369 -- Tag_Kind => <tag_kind-value>,
5370 -- Predef_Prims => Predef_Prims'First'Address,
5371 -- Offset_To_Top => 0,
5372 -- TSD => TSD'Address;
5373 -- Prims_Ptr => (prim-op-1'address,
5374 -- prim-op-2'address,
5376 -- prim-op-n'address));
5377 -- for DT'Alignment use Address'Alignment
5384 if not Building_Static_DT
(Typ
) then
5385 Nb_Predef_Prims
:= Max_Predef_Prims
;
5388 Prim_Elmt
:= First_Elmt
(Primitive_Operations
(Typ
));
5389 while Present
(Prim_Elmt
) loop
5390 Prim
:= Node
(Prim_Elmt
);
5392 if Is_Predefined_Dispatching_Operation
(Prim
)
5393 and then not Is_Abstract_Subprogram
(Prim
)
5395 Pos
:= UI_To_Int
(DT_Position
(Prim
));
5397 if Pos
> Nb_Predef_Prims
then
5398 Nb_Predef_Prims
:= Pos
;
5402 Next_Elmt
(Prim_Elmt
);
5408 (Nat
range 1 .. Nb_Predef_Prims
) of Entity_Id
;
5413 Prim_Ops_Aggr_List
:= New_List
;
5415 Prim_Table
:= (others => Empty
);
5417 if Building_Static_DT
(Typ
) then
5418 Prim_Elmt
:= First_Elmt
(Primitive_Operations
(Typ
));
5419 while Present
(Prim_Elmt
) loop
5420 Prim
:= Node
(Prim_Elmt
);
5422 if Is_Predefined_Dispatching_Operation
(Prim
)
5423 and then not Is_Abstract_Subprogram
(Prim
)
5424 and then not Is_Eliminated
(Prim
)
5425 and then not Present
(Prim_Table
5426 (UI_To_Int
(DT_Position
(Prim
))))
5428 E
:= Ultimate_Alias
(Prim
);
5429 pragma Assert
(not Is_Abstract_Subprogram
(E
));
5430 Prim_Table
(UI_To_Int
(DT_Position
(Prim
))) := E
;
5433 Next_Elmt
(Prim_Elmt
);
5437 for J
in Prim_Table
'Range loop
5438 if Present
(Prim_Table
(J
)) then
5440 Unchecked_Convert_To
(RTE
(RE_Prim_Ptr
),
5441 Make_Attribute_Reference
(Loc
,
5442 Prefix
=> New_Reference_To
(Prim_Table
(J
), Loc
),
5443 Attribute_Name
=> Name_Unrestricted_Access
));
5445 New_Node
:= Make_Null
(Loc
);
5448 Append_To
(Prim_Ops_Aggr_List
, New_Node
);
5452 Make_Aggregate
(Loc
,
5453 Expressions
=> Prim_Ops_Aggr_List
);
5456 Make_Subtype_Declaration
(Loc
,
5457 Defining_Identifier
=> Make_Temporary
(Loc
, 'S'),
5458 Subtype_Indication
=>
5459 New_Reference_To
(RTE
(RE_Address_Array
), Loc
));
5461 Append_To
(Result
, Decl
);
5464 Make_Object_Declaration
(Loc
,
5465 Defining_Identifier
=> Predef_Prims
,
5466 Aliased_Present
=> True,
5467 Constant_Present
=> Building_Static_DT
(Typ
),
5468 Object_Definition
=> New_Reference_To
5469 (Defining_Identifier
(Decl
), Loc
),
5470 Expression
=> New_Node
));
5472 -- Remember aggregates initializing dispatch tables
5474 Append_Elmt
(New_Node
, DT_Aggr
);
5477 Make_Attribute_Definition_Clause
(Loc
,
5478 Name
=> New_Reference_To
(Predef_Prims
, Loc
),
5479 Chars
=> Name_Alignment
,
5481 Make_Attribute_Reference
(Loc
,
5483 New_Reference_To
(RTE
(RE_Integer_Address
), Loc
),
5484 Attribute_Name
=> Name_Alignment
)));
5488 -- Stage 1: Initialize the discriminant and the record components
5490 DT_Constr_List
:= New_List
;
5491 DT_Aggr_List
:= New_List
;
5493 -- Num_Prims. If the tagged type has no primitives we add a dummy
5494 -- slot whose address will be the tag of this type.
5497 New_Node
:= Make_Integer_Literal
(Loc
, 1);
5499 New_Node
:= Make_Integer_Literal
(Loc
, Nb_Prim
);
5502 Append_To
(DT_Constr_List
, New_Node
);
5503 Append_To
(DT_Aggr_List
, New_Copy
(New_Node
));
5507 if RTE_Record_Component_Available
(RE_Signature
) then
5508 Append_To
(DT_Aggr_List
,
5509 New_Reference_To
(RTE
(RE_Primary_DT
), Loc
));
5514 if RTE_Record_Component_Available
(RE_Tag_Kind
) then
5515 Append_To
(DT_Aggr_List
, Tagged_Kind
(Typ
));
5520 Append_To
(DT_Aggr_List
,
5521 Make_Attribute_Reference
(Loc
,
5522 Prefix
=> New_Reference_To
(Predef_Prims
, Loc
),
5523 Attribute_Name
=> Name_Address
));
5527 Append_To
(DT_Aggr_List
, Make_Integer_Literal
(Loc
, 0));
5531 Append_To
(DT_Aggr_List
,
5532 Make_Attribute_Reference
(Loc
,
5533 Prefix
=> New_Reference_To
(TSD
, Loc
),
5534 Attribute_Name
=> Name_Address
));
5536 -- Stage 2: Initialize the table of primitive operations
5538 Prim_Ops_Aggr_List
:= New_List
;
5541 Append_To
(Prim_Ops_Aggr_List
, Make_Null
(Loc
));
5543 elsif not Static_Dispatch_Tables
5544 or else not Is_Library_Level_Tagged_Type
(Typ
)
5546 for J
in 1 .. Nb_Prim
loop
5547 Append_To
(Prim_Ops_Aggr_List
, Make_Null
(Loc
));
5552 CPP_Nb_Prims
: constant Nat
:= CPP_Num_Prims
(Typ
);
5555 Prim_Elmt
: Elmt_Id
;
5557 Prim_Table
: array (Nat
range 1 .. Nb_Prim
) of Entity_Id
;
5560 Prim_Table
:= (others => Empty
);
5562 Prim_Elmt
:= First_Elmt
(Primitive_Operations
(Typ
));
5563 while Present
(Prim_Elmt
) loop
5564 Prim
:= Node
(Prim_Elmt
);
5566 -- Retrieve the ultimate alias of the primitive for proper
5567 -- handling of renamings and eliminated primitives.
5569 E
:= Ultimate_Alias
(Prim
);
5570 Prim_Pos
:= UI_To_Int
(DT_Position
(E
));
5572 -- Do not reference predefined primitives because they are
5573 -- located in a separate dispatch table; skip entities with
5574 -- attribute Interface_Alias because they are only required
5575 -- to build secondary dispatch tables; skip abstract and
5576 -- eliminated primitives; for derivations of CPP types skip
5577 -- primitives located in the C++ part of the dispatch table
5578 -- because their slot is initialized by the IC routine.
5580 if not Is_Predefined_Dispatching_Operation
(Prim
)
5581 and then not Is_Predefined_Dispatching_Operation
(E
)
5582 and then not Present
(Interface_Alias
(Prim
))
5583 and then not Is_Abstract_Subprogram
(E
)
5584 and then not Is_Eliminated
(E
)
5585 and then (not Is_CPP_Class
(Root_Type
(Typ
))
5586 or else Prim_Pos
> CPP_Nb_Prims
)
5589 (UI_To_Int
(DT_Position
(Prim
)) <= Nb_Prim
);
5591 Prim_Table
(UI_To_Int
(DT_Position
(Prim
))) := E
;
5594 Next_Elmt
(Prim_Elmt
);
5597 for J
in Prim_Table
'Range loop
5598 if Present
(Prim_Table
(J
)) then
5600 Unchecked_Convert_To
(RTE
(RE_Prim_Ptr
),
5601 Make_Attribute_Reference
(Loc
,
5602 Prefix
=> New_Reference_To
(Prim_Table
(J
), Loc
),
5603 Attribute_Name
=> Name_Unrestricted_Access
));
5605 New_Node
:= Make_Null
(Loc
);
5608 Append_To
(Prim_Ops_Aggr_List
, New_Node
);
5614 Make_Aggregate
(Loc
,
5615 Expressions
=> Prim_Ops_Aggr_List
);
5617 Append_To
(DT_Aggr_List
, New_Node
);
5619 -- Remember aggregates initializing dispatch tables
5621 Append_Elmt
(New_Node
, DT_Aggr
);
5623 -- In case of locally defined tagged types we have already declared
5624 -- and uninitialized object for the dispatch table, which is now
5625 -- initialized by means of an assignment.
5627 if not Building_Static_DT
(Typ
) then
5629 Make_Assignment_Statement
(Loc
,
5630 Name
=> New_Reference_To
(DT
, Loc
),
5631 Expression
=> Make_Aggregate
(Loc
,
5632 Expressions
=> DT_Aggr_List
)));
5634 -- In case of library level tagged types we declare now and export
5635 -- the constant object containing the dispatch table.
5639 Make_Object_Declaration
(Loc
,
5640 Defining_Identifier
=> DT
,
5641 Aliased_Present
=> True,
5642 Constant_Present
=> True,
5643 Object_Definition
=>
5644 Make_Subtype_Indication
(Loc
,
5645 Subtype_Mark
=> New_Reference_To
5646 (RTE
(RE_Dispatch_Table_Wrapper
), Loc
),
5647 Constraint
=> Make_Index_Or_Discriminant_Constraint
(Loc
,
5648 Constraints
=> DT_Constr_List
)),
5649 Expression
=> Make_Aggregate
(Loc
,
5650 Expressions
=> DT_Aggr_List
)));
5653 Make_Attribute_Definition_Clause
(Loc
,
5654 Name
=> New_Reference_To
(DT
, Loc
),
5655 Chars
=> Name_Alignment
,
5657 Make_Attribute_Reference
(Loc
,
5659 New_Reference_To
(RTE
(RE_Integer_Address
), Loc
),
5660 Attribute_Name
=> Name_Alignment
)));
5662 Export_DT
(Typ
, DT
);
5666 -- Initialize the table of ancestor tags if not building static
5669 if not Building_Static_DT
(Typ
)
5670 and then not Is_Interface
(Typ
)
5671 and then not Is_CPP_Class
(Typ
)
5674 Make_Assignment_Statement
(Loc
,
5676 Make_Indexed_Component
(Loc
,
5678 Make_Selected_Component
(Loc
,
5680 New_Reference_To
(TSD
, Loc
),
5683 (RTE_Record_Component
(RE_Tags_Table
), Loc
)),
5685 New_List
(Make_Integer_Literal
(Loc
, 0))),
5689 (Node
(First_Elmt
(Access_Disp_Table
(Typ
))), Loc
)));
5692 -- Inherit the dispatch tables of the parent. There is no need to
5693 -- inherit anything from the parent when building static dispatch tables
5694 -- because the whole dispatch table (including inherited primitives) has
5695 -- been already built.
5697 if Static_Dispatch_Tables
5698 and then Is_Library_Level_Tagged_Type
(Typ
)
5702 -- If the ancestor is a CPP_Class type we inherit the dispatch tables
5703 -- in the init proc, and we don't need to fill them in here.
5705 elsif Is_CPP_Class
(Parent_Typ
) then
5708 -- Otherwise we fill in the dispatch tables here
5711 if Typ
/= Parent_Typ
5712 and then not Is_Interface
(Typ
)
5713 and then not Restriction_Active
(No_Dispatching_Calls
)
5715 -- Inherit the dispatch table
5717 if not Is_Interface
(Typ
)
5718 and then not Is_Interface
(Parent_Typ
)
5719 and then not Is_CPP_Class
(Parent_Typ
)
5722 Nb_Prims
: constant Int
:=
5723 UI_To_Int
(DT_Entry_Count
5724 (First_Tag_Component
(Parent_Typ
)));
5727 Append_To
(Elab_Code
,
5728 Build_Inherit_Predefined_Prims
(Loc
,
5734 (Access_Disp_Table
(Parent_Typ
)))), Loc
),
5740 (Access_Disp_Table
(Typ
)))), Loc
)));
5742 if Nb_Prims
/= 0 then
5743 Append_To
(Elab_Code
,
5744 Build_Inherit_Prims
(Loc
,
5750 (Access_Disp_Table
(Parent_Typ
))), Loc
),
5751 New_Tag_Node
=> New_Reference_To
(DT_Ptr
, Loc
),
5752 Num_Prims
=> Nb_Prims
));
5757 -- Inherit the secondary dispatch tables of the ancestor
5759 if not Is_CPP_Class
(Parent_Typ
) then
5761 Sec_DT_Ancestor
: Elmt_Id
:=
5765 (Access_Disp_Table
(Parent_Typ
))));
5766 Sec_DT_Typ
: Elmt_Id
:=
5770 (Access_Disp_Table
(Typ
))));
5772 procedure Copy_Secondary_DTs
(Typ
: Entity_Id
);
5773 -- Local procedure required to climb through the ancestors
5774 -- and copy the contents of all their secondary dispatch
5777 ------------------------
5778 -- Copy_Secondary_DTs --
5779 ------------------------
5781 procedure Copy_Secondary_DTs
(Typ
: Entity_Id
) is
5786 -- Climb to the ancestor (if any) handling private types
5788 if Present
(Full_View
(Etype
(Typ
))) then
5789 if Full_View
(Etype
(Typ
)) /= Typ
then
5790 Copy_Secondary_DTs
(Full_View
(Etype
(Typ
)));
5793 elsif Etype
(Typ
) /= Typ
then
5794 Copy_Secondary_DTs
(Etype
(Typ
));
5797 if Present
(Interfaces
(Typ
))
5798 and then not Is_Empty_Elmt_List
(Interfaces
(Typ
))
5800 Iface
:= First_Elmt
(Interfaces
(Typ
));
5801 E
:= First_Entity
(Typ
);
5803 and then Present
(Node
(Sec_DT_Ancestor
))
5804 and then Ekind
(Node
(Sec_DT_Ancestor
)) = E_Constant
5806 if Is_Tag
(E
) and then Chars
(E
) /= Name_uTag
then
5808 Num_Prims
: constant Int
:=
5809 UI_To_Int
(DT_Entry_Count
(E
));
5812 if not Is_Interface
(Etype
(Typ
)) then
5814 -- Inherit first secondary dispatch table
5816 Append_To
(Elab_Code
,
5817 Build_Inherit_Predefined_Prims
(Loc
,
5819 Unchecked_Convert_To
(RTE
(RE_Tag
),
5822 (Next_Elmt
(Sec_DT_Ancestor
)),
5825 Unchecked_Convert_To
(RTE
(RE_Tag
),
5827 (Node
(Next_Elmt
(Sec_DT_Typ
)),
5830 if Num_Prims
/= 0 then
5831 Append_To
(Elab_Code
,
5832 Build_Inherit_Prims
(Loc
,
5833 Typ
=> Node
(Iface
),
5835 Unchecked_Convert_To
5838 (Node
(Sec_DT_Ancestor
),
5841 Unchecked_Convert_To
5844 (Node
(Sec_DT_Typ
), Loc
)),
5845 Num_Prims
=> Num_Prims
));
5849 Next_Elmt
(Sec_DT_Ancestor
);
5850 Next_Elmt
(Sec_DT_Typ
);
5852 -- Skip the secondary dispatch table of
5853 -- predefined primitives
5855 Next_Elmt
(Sec_DT_Ancestor
);
5856 Next_Elmt
(Sec_DT_Typ
);
5858 if not Is_Interface
(Etype
(Typ
)) then
5860 -- Inherit second secondary dispatch table
5862 Append_To
(Elab_Code
,
5863 Build_Inherit_Predefined_Prims
(Loc
,
5865 Unchecked_Convert_To
(RTE
(RE_Tag
),
5868 (Next_Elmt
(Sec_DT_Ancestor
)),
5871 Unchecked_Convert_To
(RTE
(RE_Tag
),
5873 (Node
(Next_Elmt
(Sec_DT_Typ
)),
5876 if Num_Prims
/= 0 then
5877 Append_To
(Elab_Code
,
5878 Build_Inherit_Prims
(Loc
,
5879 Typ
=> Node
(Iface
),
5881 Unchecked_Convert_To
5884 (Node
(Sec_DT_Ancestor
),
5887 Unchecked_Convert_To
5890 (Node
(Sec_DT_Typ
), Loc
)),
5891 Num_Prims
=> Num_Prims
));
5896 Next_Elmt
(Sec_DT_Ancestor
);
5897 Next_Elmt
(Sec_DT_Typ
);
5899 -- Skip the secondary dispatch table of
5900 -- predefined primitives
5902 Next_Elmt
(Sec_DT_Ancestor
);
5903 Next_Elmt
(Sec_DT_Typ
);
5911 end Copy_Secondary_DTs
;
5914 if Present
(Node
(Sec_DT_Ancestor
))
5915 and then Ekind
(Node
(Sec_DT_Ancestor
)) = E_Constant
5917 -- Handle private types
5919 if Present
(Full_View
(Typ
)) then
5920 Copy_Secondary_DTs
(Full_View
(Typ
));
5922 Copy_Secondary_DTs
(Typ
);
5930 -- Generate code to register the Tag in the External_Tag hash table for
5931 -- the pure Ada type only.
5933 -- Register_Tag (Dt_Ptr);
5935 -- Skip this action in the following cases:
5936 -- 1) if Register_Tag is not available.
5937 -- 2) in No_Run_Time mode.
5938 -- 3) if Typ is not defined at the library level (this is required
5939 -- to avoid adding concurrency control to the hash table used
5940 -- by the run-time to register the tags).
5942 if not No_Run_Time_Mode
5943 and then Is_Library_Level_Entity
(Typ
)
5944 and then RTE_Available
(RE_Register_Tag
)
5946 Append_To
(Elab_Code
,
5947 Make_Procedure_Call_Statement
(Loc
,
5948 Name
=> New_Reference_To
(RTE
(RE_Register_Tag
), Loc
),
5949 Parameter_Associations
=>
5950 New_List
(New_Reference_To
(DT_Ptr
, Loc
))));
5953 if not Is_Empty_List
(Elab_Code
) then
5954 Append_List_To
(Result
, Elab_Code
);
5957 -- Populate the two auxiliary tables used for dispatching asynchronous,
5958 -- conditional and timed selects for synchronized types that implement
5959 -- a limited interface. Skip this step in Ravenscar profile or when
5960 -- general dispatching is forbidden.
5962 if Ada_Version
>= Ada_05
5963 and then Is_Concurrent_Record_Type
(Typ
)
5964 and then Has_Interfaces
(Typ
)
5965 and then not Restriction_Active
(No_Dispatching_Calls
)
5966 and then not Restriction_Active
(No_Select_Statements
)
5968 Append_List_To
(Result
,
5969 Make_Select_Specific_Data_Table
(Typ
));
5972 -- Remember entities containing dispatch tables
5974 Append_Elmt
(Predef_Prims
, DT_Decl
);
5975 Append_Elmt
(DT
, DT_Decl
);
5977 Analyze_List
(Result
, Suppress
=> All_Checks
);
5978 Set_Has_Dispatch_Table
(Typ
);
5980 -- Mark entities containing dispatch tables. Required by the backend to
5981 -- handle them properly.
5983 if Has_DT
(Typ
) then
5988 -- Ensure that entities Prim_Ptr and Predef_Prims_Table_Ptr have
5989 -- the decoration required by the backend
5991 Set_Is_Dispatch_Table_Entity
(RTE
(RE_Prim_Ptr
));
5992 Set_Is_Dispatch_Table_Entity
(RTE
(RE_Predef_Prims_Table_Ptr
));
5994 -- Object declarations
5996 Elmt
:= First_Elmt
(DT_Decl
);
5997 while Present
(Elmt
) loop
5998 Set_Is_Dispatch_Table_Entity
(Node
(Elmt
));
5999 pragma Assert
(Ekind
(Etype
(Node
(Elmt
))) = E_Array_Subtype
6000 or else Ekind
(Etype
(Node
(Elmt
))) = E_Record_Subtype
);
6001 Set_Is_Dispatch_Table_Entity
(Etype
(Node
(Elmt
)));
6005 -- Aggregates initializing dispatch tables
6007 Elmt
:= First_Elmt
(DT_Aggr
);
6008 while Present
(Elmt
) loop
6009 Set_Is_Dispatch_Table_Entity
(Etype
(Node
(Elmt
)));
6015 -- Register the tagged type in the call graph nodes table
6017 Register_CG_Node
(Typ
);
6022 -------------------------------------
6023 -- Make_Select_Specific_Data_Table --
6024 -------------------------------------
6026 function Make_Select_Specific_Data_Table
6027 (Typ
: Entity_Id
) return List_Id
6029 Assignments
: constant List_Id
:= New_List
;
6030 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
6032 Conc_Typ
: Entity_Id
;
6036 Prim_Als
: Entity_Id
;
6037 Prim_Elmt
: Elmt_Id
;
6041 type Examined_Array
is array (Int
range <>) of Boolean;
6043 function Find_Entry_Index
(E
: Entity_Id
) return Uint
;
6044 -- Given an entry, find its index in the visible declarations of the
6045 -- corresponding concurrent type of Typ.
6047 ----------------------
6048 -- Find_Entry_Index --
6049 ----------------------
6051 function Find_Entry_Index
(E
: Entity_Id
) return Uint
is
6052 Index
: Uint
:= Uint_1
;
6053 Subp_Decl
: Entity_Id
;
6057 and then not Is_Empty_List
(Decls
)
6059 Subp_Decl
:= First
(Decls
);
6060 while Present
(Subp_Decl
) loop
6061 if Nkind
(Subp_Decl
) = N_Entry_Declaration
then
6062 if Defining_Identifier
(Subp_Decl
) = E
then
6074 end Find_Entry_Index
;
6076 -- Start of processing for Make_Select_Specific_Data_Table
6079 pragma Assert
(not Restriction_Active
(No_Dispatching_Calls
));
6081 DT_Ptr
:= Node
(First_Elmt
(Access_Disp_Table
(Typ
)));
6083 if Present
(Corresponding_Concurrent_Type
(Typ
)) then
6084 Conc_Typ
:= Corresponding_Concurrent_Type
(Typ
);
6086 if Present
(Full_View
(Conc_Typ
)) then
6087 Conc_Typ
:= Full_View
(Conc_Typ
);
6090 if Ekind
(Conc_Typ
) = E_Protected_Type
then
6091 Decls
:= Visible_Declarations
(Protected_Definition
(
6092 Parent
(Conc_Typ
)));
6094 pragma Assert
(Ekind
(Conc_Typ
) = E_Task_Type
);
6095 Decls
:= Visible_Declarations
(Task_Definition
(
6096 Parent
(Conc_Typ
)));
6100 -- Count the non-predefined primitive operations
6102 Prim_Elmt
:= First_Elmt
(Primitive_Operations
(Typ
));
6103 while Present
(Prim_Elmt
) loop
6104 Prim
:= Node
(Prim_Elmt
);
6106 if not (Is_Predefined_Dispatching_Operation
(Prim
)
6107 or else Is_Predefined_Dispatching_Alias
(Prim
))
6109 Nb_Prim
:= Nb_Prim
+ 1;
6112 Next_Elmt
(Prim_Elmt
);
6116 Examined
: Examined_Array
(1 .. Nb_Prim
) := (others => False);
6119 Prim_Elmt
:= First_Elmt
(Primitive_Operations
(Typ
));
6120 while Present
(Prim_Elmt
) loop
6121 Prim
:= Node
(Prim_Elmt
);
6123 -- Look for primitive overriding an abstract interface subprogram
6125 if Present
(Interface_Alias
(Prim
))
6128 (Find_Dispatching_Type
(Interface_Alias
(Prim
)), Typ
)
6129 and then not Examined
(UI_To_Int
(DT_Position
(Alias
(Prim
))))
6131 Prim_Pos
:= DT_Position
(Alias
(Prim
));
6132 pragma Assert
(UI_To_Int
(Prim_Pos
) <= Nb_Prim
);
6133 Examined
(UI_To_Int
(Prim_Pos
)) := True;
6135 -- Set the primitive operation kind regardless of subprogram
6137 -- Ada.Tags.Set_Prim_Op_Kind (DT_Ptr, <position>, <kind>);
6139 Append_To
(Assignments
,
6140 Make_Procedure_Call_Statement
(Loc
,
6141 Name
=> New_Reference_To
(RTE
(RE_Set_Prim_Op_Kind
), Loc
),
6142 Parameter_Associations
=> New_List
(
6143 New_Reference_To
(DT_Ptr
, Loc
),
6144 Make_Integer_Literal
(Loc
, Prim_Pos
),
6145 Prim_Op_Kind
(Alias
(Prim
), Typ
))));
6147 -- Retrieve the root of the alias chain
6149 Prim_Als
:= Ultimate_Alias
(Prim
);
6151 -- In the case of an entry wrapper, set the entry index
6153 if Ekind
(Prim
) = E_Procedure
6154 and then Is_Primitive_Wrapper
(Prim_Als
)
6155 and then Ekind
(Wrapped_Entity
(Prim_Als
)) = E_Entry
6158 -- Ada.Tags.Set_Entry_Index
6159 -- (DT_Ptr, <position>, <index>);
6161 Append_To
(Assignments
,
6162 Make_Procedure_Call_Statement
(Loc
,
6164 New_Reference_To
(RTE
(RE_Set_Entry_Index
), Loc
),
6165 Parameter_Associations
=> New_List
(
6166 New_Reference_To
(DT_Ptr
, Loc
),
6167 Make_Integer_Literal
(Loc
, Prim_Pos
),
6168 Make_Integer_Literal
(Loc
,
6169 Find_Entry_Index
(Wrapped_Entity
(Prim_Als
))))));
6173 Next_Elmt
(Prim_Elmt
);
6178 end Make_Select_Specific_Data_Table
;
6184 function Make_Tags
(Typ
: Entity_Id
) return List_Id
is
6185 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
6186 Result
: constant List_Id
:= New_List
;
6189 (Tag_Typ
: Entity_Id
;
6191 Is_Secondary_DT
: Boolean);
6192 -- Import the dispatch table DT of tagged type Tag_Typ. Required to
6193 -- generate forward references and statically allocate the table. For
6194 -- primary dispatch tables that require no dispatch table generate:
6195 -- DT : static aliased constant Non_Dispatch_Table_Wrapper;
6196 -- $pragma import (ada, DT);
6197 -- Otherwise generate:
6198 -- DT : static aliased constant Dispatch_Table_Wrapper (Nb_Prim);
6199 -- $pragma import (ada, DT);
6206 (Tag_Typ
: Entity_Id
;
6208 Is_Secondary_DT
: Boolean)
6210 DT_Constr_List
: List_Id
;
6214 Set_Is_Imported
(DT
);
6215 Set_Ekind
(DT
, E_Constant
);
6216 Set_Related_Type
(DT
, Typ
);
6218 -- The scope must be set now to call Get_External_Name
6220 Set_Scope
(DT
, Current_Scope
);
6222 Get_External_Name
(DT
, True);
6223 Set_Interface_Name
(DT
,
6224 Make_String_Literal
(Loc
,
6225 Strval
=> String_From_Name_Buffer
));
6227 -- Ensure proper Sprint output of this implicit importation
6229 Set_Is_Internal
(DT
);
6231 -- Save this entity to allow Make_DT to generate its exportation
6233 Append_Elmt
(DT
, Dispatch_Table_Wrappers
(Typ
));
6235 -- No dispatch table required
6237 if not Is_Secondary_DT
6238 and then not Has_DT
(Tag_Typ
)
6241 Make_Object_Declaration
(Loc
,
6242 Defining_Identifier
=> DT
,
6243 Aliased_Present
=> True,
6244 Constant_Present
=> True,
6245 Object_Definition
=>
6246 New_Reference_To
(RTE
(RE_No_Dispatch_Table_Wrapper
), Loc
)));
6249 -- Calculate the number of primitives of the dispatch table and
6250 -- the size of the Type_Specific_Data record.
6253 UI_To_Int
(DT_Entry_Count
(First_Tag_Component
(Tag_Typ
)));
6255 -- If the tagged type has no primitives we add a dummy slot
6256 -- whose address will be the tag of this type.
6260 New_List
(Make_Integer_Literal
(Loc
, 1));
6263 New_List
(Make_Integer_Literal
(Loc
, Nb_Prim
));
6267 Make_Object_Declaration
(Loc
,
6268 Defining_Identifier
=> DT
,
6269 Aliased_Present
=> True,
6270 Constant_Present
=> True,
6271 Object_Definition
=>
6272 Make_Subtype_Indication
(Loc
,
6274 New_Reference_To
(RTE
(RE_Dispatch_Table_Wrapper
), Loc
),
6275 Constraint
=> Make_Index_Or_Discriminant_Constraint
(Loc
,
6276 Constraints
=> DT_Constr_List
))));
6282 Tname
: constant Name_Id
:= Chars
(Typ
);
6283 AI_Tag_Comp
: Elmt_Id
;
6284 DT
: Node_Id
:= Empty
;
6286 Predef_Prims_Ptr
: Node_Id
;
6287 Iface_DT
: Node_Id
:= Empty
;
6288 Iface_DT_Ptr
: Node_Id
;
6292 Typ_Comps
: Elist_Id
;
6294 -- Start of processing for Make_Tags
6297 pragma Assert
(No
(Access_Disp_Table
(Typ
)));
6298 Set_Access_Disp_Table
(Typ
, New_Elmt_List
);
6300 -- 1) Generate the primary tag entities
6302 -- Primary dispatch table containing user-defined primitives
6304 DT_Ptr
:= Make_Defining_Identifier
(Loc
, New_External_Name
(Tname
, 'P'));
6305 Set_Etype
(DT_Ptr
, RTE
(RE_Tag
));
6306 Append_Elmt
(DT_Ptr
, Access_Disp_Table
(Typ
));
6308 -- Minimum decoration
6310 Set_Ekind
(DT_Ptr
, E_Variable
);
6311 Set_Related_Type
(DT_Ptr
, Typ
);
6313 -- For CPP types there is no need to build the dispatch tables since
6314 -- they are imported from the C++ side. If the CPP type has an IP then
6315 -- we declare now the variable that will store the copy of the C++ tag.
6316 -- If the CPP type is an interface, we need the variable as well,
6317 -- because it becomes the pointer to the corresponding secondary table.
6319 if Is_CPP_Class
(Typ
) then
6320 if Has_CPP_Constructors
(Typ
) or else Is_Interface
(Typ
) then
6322 Make_Object_Declaration
(Loc
,
6323 Defining_Identifier
=> DT_Ptr
,
6324 Object_Definition
=> New_Reference_To
(RTE
(RE_Tag
), Loc
),
6326 Unchecked_Convert_To
(RTE
(RE_Tag
),
6327 New_Reference_To
(RTE
(RE_Null_Address
), Loc
))));
6329 Set_Is_Statically_Allocated
(DT_Ptr
,
6330 Is_Library_Level_Tagged_Type
(Typ
));
6336 -- Primary dispatch table containing predefined primitives
6339 Make_Defining_Identifier
(Loc
,
6340 Chars
=> New_External_Name
(Tname
, 'Y'));
6341 Set_Etype
(Predef_Prims_Ptr
, RTE
(RE_Address
));
6342 Append_Elmt
(Predef_Prims_Ptr
, Access_Disp_Table
(Typ
));
6344 -- Import the forward declaration of the Dispatch Table wrapper
6345 -- record (Make_DT will take care of its exportation)
6347 if Building_Static_DT
(Typ
) then
6348 Set_Dispatch_Table_Wrappers
(Typ
, New_Elmt_List
);
6351 Make_Defining_Identifier
(Loc
,
6352 Chars
=> New_External_Name
(Tname
, 'T'));
6354 Import_DT
(Typ
, DT
, Is_Secondary_DT
=> False);
6356 if Has_DT
(Typ
) then
6358 Make_Object_Declaration
(Loc
,
6359 Defining_Identifier
=> DT_Ptr
,
6360 Constant_Present
=> True,
6361 Object_Definition
=> New_Reference_To
(RTE
(RE_Tag
), Loc
),
6363 Unchecked_Convert_To
(RTE
(RE_Tag
),
6364 Make_Attribute_Reference
(Loc
,
6366 Make_Selected_Component
(Loc
,
6367 Prefix
=> New_Reference_To
(DT
, Loc
),
6370 (RTE_Record_Component
(RE_Prims_Ptr
), Loc
)),
6371 Attribute_Name
=> Name_Address
))));
6373 -- Generate the SCIL node for the previous object declaration
6374 -- because it has a tag initialization.
6376 if Generate_SCIL
then
6378 Make_SCIL_Dispatch_Table_Tag_Init
(Sloc
(Last
(Result
)));
6379 Set_SCIL_Entity
(New_Node
, Typ
);
6380 Set_SCIL_Node
(Last
(Result
), New_Node
);
6384 Make_Object_Declaration
(Loc
,
6385 Defining_Identifier
=> Predef_Prims_Ptr
,
6386 Constant_Present
=> True,
6387 Object_Definition
=> New_Reference_To
6388 (RTE
(RE_Address
), Loc
),
6390 Make_Attribute_Reference
(Loc
,
6392 Make_Selected_Component
(Loc
,
6393 Prefix
=> New_Reference_To
(DT
, Loc
),
6396 (RTE_Record_Component
(RE_Predef_Prims
), Loc
)),
6397 Attribute_Name
=> Name_Address
)));
6399 -- No dispatch table required
6403 Make_Object_Declaration
(Loc
,
6404 Defining_Identifier
=> DT_Ptr
,
6405 Constant_Present
=> True,
6406 Object_Definition
=> New_Reference_To
(RTE
(RE_Tag
), Loc
),
6408 Unchecked_Convert_To
(RTE
(RE_Tag
),
6409 Make_Attribute_Reference
(Loc
,
6411 Make_Selected_Component
(Loc
,
6412 Prefix
=> New_Reference_To
(DT
, Loc
),
6415 (RTE_Record_Component
(RE_NDT_Prims_Ptr
), Loc
)),
6416 Attribute_Name
=> Name_Address
))));
6419 Set_Is_True_Constant
(DT_Ptr
);
6420 Set_Is_Statically_Allocated
(DT_Ptr
);
6424 -- 2) Generate the secondary tag entities
6426 -- Collect the components associated with secondary dispatch tables
6428 if Has_Interfaces
(Typ
) then
6429 Collect_Interface_Components
(Typ
, Typ_Comps
);
6431 -- For each interface type we build an unique external name
6432 -- associated with its secondary dispatch table. This name is used to
6433 -- declare an object that references this secondary dispatch table,
6434 -- value that will be used for the elaboration of Typ's objects and
6435 -- also for the elaboration of objects of derivations of Typ that do
6436 -- not override the primitives of this interface type.
6440 -- Note: The value of Suffix_Index must be in sync with the
6441 -- Suffix_Index values of secondary dispatch tables generated
6444 if Is_CPP_Class
(Typ
) then
6445 AI_Tag_Comp
:= First_Elmt
(Typ_Comps
);
6446 while Present
(AI_Tag_Comp
) loop
6447 Get_Secondary_DT_External_Name
6448 (Typ
, Related_Type
(Node
(AI_Tag_Comp
)), Suffix_Index
);
6449 Typ_Name
:= Name_Find
;
6451 -- Declare variables that will store the copy of the C++
6455 Make_Defining_Identifier
(Loc
,
6456 Chars
=> New_External_Name
(Typ_Name
, 'P'));
6457 Set_Etype
(Iface_DT_Ptr
, RTE
(RE_Interface_Tag
));
6458 Set_Ekind
(Iface_DT_Ptr
, E_Variable
);
6459 Set_Is_Tag
(Iface_DT_Ptr
);
6461 Set_Has_Thunks
(Iface_DT_Ptr
);
6463 (Iface_DT_Ptr
, Related_Type
(Node
(AI_Tag_Comp
)));
6464 Append_Elmt
(Iface_DT_Ptr
, Access_Disp_Table
(Typ
));
6467 Make_Object_Declaration
(Loc
,
6468 Defining_Identifier
=> Iface_DT_Ptr
,
6469 Object_Definition
=> New_Reference_To
6470 (RTE
(RE_Interface_Tag
), Loc
),
6472 Unchecked_Convert_To
(RTE
(RE_Interface_Tag
),
6473 New_Reference_To
(RTE
(RE_Null_Address
), Loc
))));
6475 Set_Is_Statically_Allocated
(Iface_DT_Ptr
,
6476 Is_Library_Level_Tagged_Type
(Typ
));
6478 Next_Elmt
(AI_Tag_Comp
);
6481 -- This is not a CPP_Class type
6484 AI_Tag_Comp
:= First_Elmt
(Typ_Comps
);
6485 while Present
(AI_Tag_Comp
) loop
6486 Get_Secondary_DT_External_Name
6487 (Typ
, Related_Type
(Node
(AI_Tag_Comp
)), Suffix_Index
);
6488 Typ_Name
:= Name_Find
;
6490 if Building_Static_DT
(Typ
) then
6492 Make_Defining_Identifier
(Loc
,
6493 Chars
=> New_External_Name
6494 (Typ_Name
, 'T', Suffix_Index
=> -1));
6496 (Tag_Typ
=> Related_Type
(Node
(AI_Tag_Comp
)),
6498 Is_Secondary_DT
=> True);
6501 -- Secondary dispatch table referencing thunks to user-defined
6502 -- primitives covered by this interface.
6505 Make_Defining_Identifier
(Loc
,
6506 Chars
=> New_External_Name
(Typ_Name
, 'P'));
6507 Set_Etype
(Iface_DT_Ptr
, RTE
(RE_Interface_Tag
));
6508 Set_Ekind
(Iface_DT_Ptr
, E_Constant
);
6509 Set_Is_Tag
(Iface_DT_Ptr
);
6510 Set_Has_Thunks
(Iface_DT_Ptr
);
6511 Set_Is_Statically_Allocated
(Iface_DT_Ptr
,
6512 Is_Library_Level_Tagged_Type
(Typ
));
6513 Set_Is_True_Constant
(Iface_DT_Ptr
);
6515 (Iface_DT_Ptr
, Related_Type
(Node
(AI_Tag_Comp
)));
6516 Append_Elmt
(Iface_DT_Ptr
, Access_Disp_Table
(Typ
));
6518 if Building_Static_DT
(Typ
) then
6520 Make_Object_Declaration
(Loc
,
6521 Defining_Identifier
=> Iface_DT_Ptr
,
6522 Constant_Present
=> True,
6523 Object_Definition
=> New_Reference_To
6524 (RTE
(RE_Interface_Tag
), Loc
),
6526 Unchecked_Convert_To
(RTE
(RE_Interface_Tag
),
6527 Make_Attribute_Reference
(Loc
,
6529 Make_Selected_Component
(Loc
,
6530 Prefix
=> New_Reference_To
(Iface_DT
, Loc
),
6533 (RTE_Record_Component
(RE_Prims_Ptr
), Loc
)),
6534 Attribute_Name
=> Name_Address
))));
6537 -- Secondary dispatch table referencing thunks to predefined
6541 Make_Defining_Identifier
(Loc
,
6542 Chars
=> New_External_Name
(Typ_Name
, 'Y'));
6543 Set_Etype
(Iface_DT_Ptr
, RTE
(RE_Address
));
6544 Set_Ekind
(Iface_DT_Ptr
, E_Constant
);
6545 Set_Is_Tag
(Iface_DT_Ptr
);
6546 Set_Has_Thunks
(Iface_DT_Ptr
);
6547 Set_Is_Statically_Allocated
(Iface_DT_Ptr
,
6548 Is_Library_Level_Tagged_Type
(Typ
));
6549 Set_Is_True_Constant
(Iface_DT_Ptr
);
6551 (Iface_DT_Ptr
, Related_Type
(Node
(AI_Tag_Comp
)));
6552 Append_Elmt
(Iface_DT_Ptr
, Access_Disp_Table
(Typ
));
6554 -- Secondary dispatch table referencing user-defined primitives
6555 -- covered by this interface.
6558 Make_Defining_Identifier
(Loc
,
6559 Chars
=> New_External_Name
(Typ_Name
, 'D'));
6560 Set_Etype
(Iface_DT_Ptr
, RTE
(RE_Interface_Tag
));
6561 Set_Ekind
(Iface_DT_Ptr
, E_Constant
);
6562 Set_Is_Tag
(Iface_DT_Ptr
);
6563 Set_Is_Statically_Allocated
(Iface_DT_Ptr
,
6564 Is_Library_Level_Tagged_Type
(Typ
));
6565 Set_Is_True_Constant
(Iface_DT_Ptr
);
6567 (Iface_DT_Ptr
, Related_Type
(Node
(AI_Tag_Comp
)));
6568 Append_Elmt
(Iface_DT_Ptr
, Access_Disp_Table
(Typ
));
6570 -- Secondary dispatch table referencing predefined primitives
6573 Make_Defining_Identifier
(Loc
,
6574 Chars
=> New_External_Name
(Typ_Name
, 'Z'));
6575 Set_Etype
(Iface_DT_Ptr
, RTE
(RE_Address
));
6576 Set_Ekind
(Iface_DT_Ptr
, E_Constant
);
6577 Set_Is_Tag
(Iface_DT_Ptr
);
6578 Set_Is_Statically_Allocated
(Iface_DT_Ptr
,
6579 Is_Library_Level_Tagged_Type
(Typ
));
6580 Set_Is_True_Constant
(Iface_DT_Ptr
);
6582 (Iface_DT_Ptr
, Related_Type
(Node
(AI_Tag_Comp
)));
6583 Append_Elmt
(Iface_DT_Ptr
, Access_Disp_Table
(Typ
));
6585 Next_Elmt
(AI_Tag_Comp
);
6590 -- 3) At the end of Access_Disp_Table, if the type has user-defined
6591 -- primitives, we add the entity of an access type declaration that
6592 -- is used by Build_Get_Prim_Op_Address to expand dispatching calls
6593 -- through the primary dispatch table.
6595 if UI_To_Int
(DT_Entry_Count
(First_Tag_Component
(Typ
))) = 0 then
6596 Analyze_List
(Result
);
6599 -- type Typ_DT is array (1 .. Nb_Prims) of Prim_Ptr;
6600 -- type Typ_DT_Acc is access Typ_DT;
6604 Name_DT_Prims
: constant Name_Id
:=
6605 New_External_Name
(Tname
, 'G');
6606 Name_DT_Prims_Acc
: constant Name_Id
:=
6607 New_External_Name
(Tname
, 'H');
6608 DT_Prims
: constant Entity_Id
:=
6609 Make_Defining_Identifier
(Loc
,
6611 DT_Prims_Acc
: constant Entity_Id
:=
6612 Make_Defining_Identifier
(Loc
,
6616 Make_Full_Type_Declaration
(Loc
,
6617 Defining_Identifier
=> DT_Prims
,
6619 Make_Constrained_Array_Definition
(Loc
,
6620 Discrete_Subtype_Definitions
=> New_List
(
6622 Low_Bound
=> Make_Integer_Literal
(Loc
, 1),
6623 High_Bound
=> Make_Integer_Literal
(Loc
,
6625 (First_Tag_Component
(Typ
))))),
6626 Component_Definition
=>
6627 Make_Component_Definition
(Loc
,
6628 Subtype_Indication
=>
6629 New_Reference_To
(RTE
(RE_Prim_Ptr
), Loc
)))));
6632 Make_Full_Type_Declaration
(Loc
,
6633 Defining_Identifier
=> DT_Prims_Acc
,
6635 Make_Access_To_Object_Definition
(Loc
,
6636 Subtype_Indication
=>
6637 New_Occurrence_Of
(DT_Prims
, Loc
))));
6639 Append_Elmt
(DT_Prims_Acc
, Access_Disp_Table
(Typ
));
6641 -- Analyze the resulting list and suppress the generation of the
6642 -- Init_Proc associated with the above array declaration because
6643 -- this type is never used in object declarations. It is only used
6644 -- to simplify the expansion associated with dispatching calls.
6646 Analyze_List
(Result
);
6647 Set_Suppress_Init_Proc
(Base_Type
(DT_Prims
));
6649 -- Disable backend optimizations based on assumptions about the
6650 -- aliasing status of objects designated by the access to the
6651 -- dispatch table. Required to handle dispatch tables imported
6654 Set_No_Strict_Aliasing
(Base_Type
(DT_Prims_Acc
));
6656 -- Add the freezing nodes of these declarations; required to avoid
6657 -- generating these freezing nodes in wrong scopes (for example in
6658 -- the IC routine of a derivation of Typ).
6660 Append_List_To
(Result
, Freeze_Entity
(DT_Prims
, Loc
));
6661 Append_List_To
(Result
, Freeze_Entity
(DT_Prims_Acc
, Loc
));
6663 -- Mark entity of dispatch table. Required by the back end to
6664 -- handle them properly.
6666 Set_Is_Dispatch_Table_Entity
(DT_Prims
);
6670 -- Mark entities of dispatch table. Required by the back end to handle
6673 if Present
(DT
) then
6674 Set_Is_Dispatch_Table_Entity
(DT
);
6675 Set_Is_Dispatch_Table_Entity
(Etype
(DT
));
6678 if Present
(Iface_DT
) then
6679 Set_Is_Dispatch_Table_Entity
(Iface_DT
);
6680 Set_Is_Dispatch_Table_Entity
(Etype
(Iface_DT
));
6683 if Is_CPP_Class
(Root_Type
(Typ
)) then
6684 Set_Ekind
(DT_Ptr
, E_Variable
);
6686 Set_Ekind
(DT_Ptr
, E_Constant
);
6689 Set_Is_Tag
(DT_Ptr
);
6690 Set_Related_Type
(DT_Ptr
, Typ
);
6699 function New_Value
(From
: Node_Id
) return Node_Id
is
6700 Res
: constant Node_Id
:= Duplicate_Subexpr
(From
);
6702 if Is_Access_Type
(Etype
(From
)) then
6704 Make_Explicit_Dereference
(Sloc
(From
),
6711 -----------------------------------
6712 -- Original_View_In_Visible_Part --
6713 -----------------------------------
6715 function Original_View_In_Visible_Part
(Typ
: Entity_Id
) return Boolean is
6716 Scop
: constant Entity_Id
:= Scope
(Typ
);
6719 -- The scope must be a package
6721 if not Is_Package_Or_Generic_Package
(Scop
) then
6725 -- A type with a private declaration has a private view declared in
6726 -- the visible part.
6728 if Has_Private_Declaration
(Typ
) then
6732 return List_Containing
(Parent
(Typ
)) =
6733 Visible_Declarations
(Specification
(Unit_Declaration_Node
(Scop
)));
6734 end Original_View_In_Visible_Part
;
6740 function Prim_Op_Kind
6742 Typ
: Entity_Id
) return Node_Id
6744 Full_Typ
: Entity_Id
:= Typ
;
6745 Loc
: constant Source_Ptr
:= Sloc
(Prim
);
6746 Prim_Op
: Entity_Id
;
6749 -- Retrieve the original primitive operation
6751 Prim_Op
:= Ultimate_Alias
(Prim
);
6753 if Ekind
(Typ
) = E_Record_Type
6754 and then Present
(Corresponding_Concurrent_Type
(Typ
))
6756 Full_Typ
:= Corresponding_Concurrent_Type
(Typ
);
6759 -- When a private tagged type is completed by a concurrent type,
6760 -- retrieve the full view.
6762 if Is_Private_Type
(Full_Typ
) then
6763 Full_Typ
:= Full_View
(Full_Typ
);
6766 if Ekind
(Prim_Op
) = E_Function
then
6768 -- Protected function
6770 if Ekind
(Full_Typ
) = E_Protected_Type
then
6771 return New_Reference_To
(RTE
(RE_POK_Protected_Function
), Loc
);
6775 elsif Ekind
(Full_Typ
) = E_Task_Type
then
6776 return New_Reference_To
(RTE
(RE_POK_Task_Function
), Loc
);
6781 return New_Reference_To
(RTE
(RE_POK_Function
), Loc
);
6785 pragma Assert
(Ekind
(Prim_Op
) = E_Procedure
);
6787 if Ekind
(Full_Typ
) = E_Protected_Type
then
6791 if Is_Primitive_Wrapper
(Prim_Op
)
6792 and then Ekind
(Wrapped_Entity
(Prim_Op
)) = E_Entry
6794 return New_Reference_To
(RTE
(RE_POK_Protected_Entry
), Loc
);
6796 -- Protected procedure
6799 return New_Reference_To
(RTE
(RE_POK_Protected_Procedure
), Loc
);
6802 elsif Ekind
(Full_Typ
) = E_Task_Type
then
6806 if Is_Primitive_Wrapper
(Prim_Op
)
6807 and then Ekind
(Wrapped_Entity
(Prim_Op
)) = E_Entry
6809 return New_Reference_To
(RTE
(RE_POK_Task_Entry
), Loc
);
6811 -- Task "procedure". These are the internally Expander-generated
6812 -- procedures (task body for instance).
6815 return New_Reference_To
(RTE
(RE_POK_Task_Procedure
), Loc
);
6818 -- Regular procedure
6821 return New_Reference_To
(RTE
(RE_POK_Procedure
), Loc
);
6826 ------------------------
6827 -- Register_Primitive --
6828 ------------------------
6830 function Register_Primitive
6832 Prim
: Entity_Id
) return List_Id
6835 Iface_Prim
: Entity_Id
;
6836 Iface_Typ
: Entity_Id
;
6837 Iface_DT_Ptr
: Entity_Id
;
6838 Iface_DT_Elmt
: Elmt_Id
;
6839 L
: constant List_Id
:= New_List
;
6842 Tag_Typ
: Entity_Id
;
6843 Thunk_Id
: Entity_Id
;
6844 Thunk_Code
: Node_Id
;
6847 pragma Assert
(not Restriction_Active
(No_Dispatching_Calls
));
6849 -- Do not register in the dispatch table eliminated primitives
6851 if not RTE_Available
(RE_Tag
)
6852 or else Is_Eliminated
(Ultimate_Alias
(Prim
))
6857 if not Present
(Interface_Alias
(Prim
)) then
6858 Tag_Typ
:= Scope
(DTC_Entity
(Prim
));
6859 Pos
:= DT_Position
(Prim
);
6860 Tag
:= First_Tag_Component
(Tag_Typ
);
6862 if Is_Predefined_Dispatching_Operation
(Prim
)
6863 or else Is_Predefined_Dispatching_Alias
(Prim
)
6866 Node
(Next_Elmt
(First_Elmt
(Access_Disp_Table
(Tag_Typ
))));
6869 Build_Set_Predefined_Prim_Op_Address
(Loc
,
6870 Tag_Node
=> New_Reference_To
(DT_Ptr
, Loc
),
6873 Unchecked_Convert_To
(RTE
(RE_Prim_Ptr
),
6874 Make_Attribute_Reference
(Loc
,
6875 Prefix
=> New_Reference_To
(Prim
, Loc
),
6876 Attribute_Name
=> Name_Unrestricted_Access
))));
6878 -- Register copy of the pointer to the 'size primitive in the TSD
6880 if Chars
(Prim
) = Name_uSize
6881 and then RTE_Record_Component_Available
(RE_Size_Func
)
6883 DT_Ptr
:= Node
(First_Elmt
(Access_Disp_Table
(Tag_Typ
)));
6885 Build_Set_Size_Function
(Loc
,
6886 Tag_Node
=> New_Reference_To
(DT_Ptr
, Loc
),
6887 Size_Func
=> Prim
));
6891 pragma Assert
(Pos
/= Uint_0
and then Pos
<= DT_Entry_Count
(Tag
));
6893 -- Skip registration of primitives located in the C++ part of the
6894 -- dispatch table. Their slot is set by the IC routine.
6896 if not Is_CPP_Class
(Root_Type
(Tag_Typ
))
6897 or else Pos
> CPP_Num_Prims
(Tag_Typ
)
6899 DT_Ptr
:= Node
(First_Elmt
(Access_Disp_Table
(Tag_Typ
)));
6901 Build_Set_Prim_Op_Address
(Loc
,
6903 Tag_Node
=> New_Reference_To
(DT_Ptr
, Loc
),
6906 Unchecked_Convert_To
(RTE
(RE_Prim_Ptr
),
6907 Make_Attribute_Reference
(Loc
,
6908 Prefix
=> New_Reference_To
(Prim
, Loc
),
6909 Attribute_Name
=> Name_Unrestricted_Access
))));
6913 -- Ada 2005 (AI-251): Primitive associated with an interface type
6914 -- Generate the code of the thunk only if the interface type is not an
6915 -- immediate ancestor of Typ; otherwise the dispatch table associated
6916 -- with the interface is the primary dispatch table and we have nothing
6920 Tag_Typ
:= Find_Dispatching_Type
(Alias
(Prim
));
6921 Iface_Typ
:= Find_Dispatching_Type
(Interface_Alias
(Prim
));
6923 pragma Assert
(Is_Interface
(Iface_Typ
));
6925 -- No action needed for interfaces that are ancestors of Typ because
6926 -- their primitives are located in the primary dispatch table.
6928 if Is_Ancestor
(Iface_Typ
, Tag_Typ
) then
6931 -- No action needed for primitives located in the C++ part of the
6932 -- dispatch table. Their slot is set by the IC routine.
6934 elsif Is_CPP_Class
(Root_Type
(Tag_Typ
))
6935 and then DT_Position
(Alias
(Prim
)) <= CPP_Num_Prims
(Tag_Typ
)
6936 and then not Is_Predefined_Dispatching_Operation
(Prim
)
6937 and then not Is_Predefined_Dispatching_Alias
(Prim
)
6942 Expand_Interface_Thunk
(Prim
, Thunk_Id
, Thunk_Code
);
6944 if not Is_Ancestor
(Iface_Typ
, Tag_Typ
)
6945 and then Present
(Thunk_Code
)
6947 -- Generate the code necessary to fill the appropriate entry of
6948 -- the secondary dispatch table of Prim's controlling type with
6949 -- Thunk_Id's address.
6951 Iface_DT_Elmt
:= Find_Interface_ADT
(Tag_Typ
, Iface_Typ
);
6952 Iface_DT_Ptr
:= Node
(Iface_DT_Elmt
);
6953 pragma Assert
(Has_Thunks
(Iface_DT_Ptr
));
6955 Iface_Prim
:= Interface_Alias
(Prim
);
6956 Pos
:= DT_Position
(Iface_Prim
);
6957 Tag
:= First_Tag_Component
(Iface_Typ
);
6959 Prepend_To
(L
, Thunk_Code
);
6961 if Is_Predefined_Dispatching_Operation
(Prim
)
6962 or else Is_Predefined_Dispatching_Alias
(Prim
)
6965 Build_Set_Predefined_Prim_Op_Address
(Loc
,
6967 New_Reference_To
(Node
(Next_Elmt
(Iface_DT_Elmt
)), Loc
),
6970 Unchecked_Convert_To
(RTE
(RE_Prim_Ptr
),
6971 Make_Attribute_Reference
(Loc
,
6972 Prefix
=> New_Reference_To
(Thunk_Id
, Loc
),
6973 Attribute_Name
=> Name_Unrestricted_Access
))));
6975 Next_Elmt
(Iface_DT_Elmt
);
6976 Next_Elmt
(Iface_DT_Elmt
);
6977 Iface_DT_Ptr
:= Node
(Iface_DT_Elmt
);
6978 pragma Assert
(not Has_Thunks
(Iface_DT_Ptr
));
6981 Build_Set_Predefined_Prim_Op_Address
(Loc
,
6983 New_Reference_To
(Node
(Next_Elmt
(Iface_DT_Elmt
)), Loc
),
6986 Unchecked_Convert_To
(RTE
(RE_Prim_Ptr
),
6987 Make_Attribute_Reference
(Loc
,
6988 Prefix
=> New_Reference_To
(Alias
(Prim
), Loc
),
6989 Attribute_Name
=> Name_Unrestricted_Access
))));
6992 pragma Assert
(Pos
/= Uint_0
6993 and then Pos
<= DT_Entry_Count
(Tag
));
6996 Build_Set_Prim_Op_Address
(Loc
,
6998 Tag_Node
=> New_Reference_To
(Iface_DT_Ptr
, Loc
),
7001 Unchecked_Convert_To
(RTE
(RE_Prim_Ptr
),
7002 Make_Attribute_Reference
(Loc
,
7003 Prefix
=> New_Reference_To
(Thunk_Id
, Loc
),
7004 Attribute_Name
=> Name_Unrestricted_Access
))));
7006 Next_Elmt
(Iface_DT_Elmt
);
7007 Next_Elmt
(Iface_DT_Elmt
);
7008 Iface_DT_Ptr
:= Node
(Iface_DT_Elmt
);
7009 pragma Assert
(not Has_Thunks
(Iface_DT_Ptr
));
7012 Build_Set_Prim_Op_Address
(Loc
,
7014 Tag_Node
=> New_Reference_To
(Iface_DT_Ptr
, Loc
),
7017 Unchecked_Convert_To
(RTE
(RE_Prim_Ptr
),
7018 Make_Attribute_Reference
(Loc
,
7019 Prefix
=> New_Reference_To
(Alias
(Prim
), Loc
),
7020 Attribute_Name
=> Name_Unrestricted_Access
))));
7027 end Register_Primitive
;
7029 -------------------------
7030 -- Set_All_DT_Position --
7031 -------------------------
7033 procedure Set_All_DT_Position
(Typ
: Entity_Id
) is
7035 procedure Validate_Position
(Prim
: Entity_Id
);
7036 -- Check that the position assigned to Prim is completely safe
7037 -- (it has not been assigned to a previously defined primitive
7038 -- operation of Typ)
7040 -----------------------
7041 -- Validate_Position --
7042 -----------------------
7044 procedure Validate_Position
(Prim
: Entity_Id
) is
7049 -- Aliased primitives are safe
7051 if Present
(Alias
(Prim
)) then
7055 Op_Elmt
:= First_Elmt
(Primitive_Operations
(Typ
));
7056 while Present
(Op_Elmt
) loop
7057 Op
:= Node
(Op_Elmt
);
7059 -- No need to check against itself
7064 -- Primitive operations covering abstract interfaces are
7067 elsif Present
(Interface_Alias
(Op
)) then
7070 -- Predefined dispatching operations are completely safe. They
7071 -- are allocated at fixed positions in a separate table.
7073 elsif Is_Predefined_Dispatching_Operation
(Op
)
7074 or else Is_Predefined_Dispatching_Alias
(Op
)
7078 -- Aliased subprograms are safe
7080 elsif Present
(Alias
(Op
)) then
7083 elsif DT_Position
(Op
) = DT_Position
(Prim
)
7084 and then not Is_Predefined_Dispatching_Operation
(Op
)
7085 and then not Is_Predefined_Dispatching_Operation
(Prim
)
7086 and then not Is_Predefined_Dispatching_Alias
(Op
)
7087 and then not Is_Predefined_Dispatching_Alias
(Prim
)
7090 -- Handle aliased subprograms
7099 if Present
(Overridden_Operation
(Op_1
)) then
7100 Op_1
:= Overridden_Operation
(Op_1
);
7101 elsif Present
(Alias
(Op_1
)) then
7102 Op_1
:= Alias
(Op_1
);
7110 if Present
(Overridden_Operation
(Op_2
)) then
7111 Op_2
:= Overridden_Operation
(Op_2
);
7112 elsif Present
(Alias
(Op_2
)) then
7113 Op_2
:= Alias
(Op_2
);
7119 if Op_1
/= Op_2
then
7120 raise Program_Error
;
7125 Next_Elmt
(Op_Elmt
);
7127 end Validate_Position
;
7131 Parent_Typ
: constant Entity_Id
:= Etype
(Typ
);
7132 First_Prim
: constant Elmt_Id
:= First_Elmt
(Primitive_Operations
(Typ
));
7133 The_Tag
: constant Entity_Id
:= First_Tag_Component
(Typ
);
7135 Adjusted
: Boolean := False;
7136 Finalized
: Boolean := False;
7142 Prim_Elmt
: Elmt_Id
;
7144 -- Start of processing for Set_All_DT_Position
7147 pragma Assert
(Present
(First_Tag_Component
(Typ
)));
7149 -- Set the DT_Position for each primitive operation. Perform some sanity
7150 -- checks to avoid building inconsistent dispatch tables.
7152 -- First stage: Set the DTC entity of all the primitive operations. This
7153 -- is required to properly read the DT_Position attribute in the latter
7156 Prim_Elmt
:= First_Prim
;
7158 while Present
(Prim_Elmt
) loop
7159 Prim
:= Node
(Prim_Elmt
);
7161 -- Predefined primitives have a separate dispatch table
7163 if not (Is_Predefined_Dispatching_Operation
(Prim
)
7165 Is_Predefined_Dispatching_Alias
(Prim
))
7167 Count_Prim
:= Count_Prim
+ 1;
7170 Set_DTC_Entity_Value
(Typ
, Prim
);
7172 -- Clear any previous value of the DT_Position attribute. In this
7173 -- way we ensure that the final position of all the primitives is
7174 -- established by the following stages of this algorithm.
7176 Set_DT_Position
(Prim
, No_Uint
);
7178 Next_Elmt
(Prim_Elmt
);
7182 Fixed_Prim
: array (Int
range 0 .. Count_Prim
) of Boolean :=
7187 procedure Handle_Inherited_Private_Subprograms
(Typ
: Entity_Id
);
7188 -- Called if Typ is declared in a nested package or a public child
7189 -- package to handle inherited primitives that were inherited by Typ
7190 -- in the visible part, but whose declaration was deferred because
7191 -- the parent operation was private and not visible at that point.
7193 procedure Set_Fixed_Prim
(Pos
: Nat
);
7194 -- Sets to true an element of the Fixed_Prim table to indicate
7195 -- that this entry of the dispatch table of Typ is occupied.
7197 ------------------------------------------
7198 -- Handle_Inherited_Private_Subprograms --
7199 ------------------------------------------
7201 procedure Handle_Inherited_Private_Subprograms
(Typ
: Entity_Id
) is
7204 Op_Elmt_2
: Elmt_Id
;
7205 Prim_Op
: Entity_Id
;
7206 Parent_Subp
: Entity_Id
;
7209 Op_List
:= Primitive_Operations
(Typ
);
7211 Op_Elmt
:= First_Elmt
(Op_List
);
7212 while Present
(Op_Elmt
) loop
7213 Prim_Op
:= Node
(Op_Elmt
);
7215 -- Search primitives that are implicit operations with an
7216 -- internal name whose parent operation has a normal name.
7218 if Present
(Alias
(Prim_Op
))
7219 and then Find_Dispatching_Type
(Alias
(Prim_Op
)) /= Typ
7220 and then not Comes_From_Source
(Prim_Op
)
7221 and then Is_Internal_Name
(Chars
(Prim_Op
))
7222 and then not Is_Internal_Name
(Chars
(Alias
(Prim_Op
)))
7224 Parent_Subp
:= Alias
(Prim_Op
);
7226 -- Check if the type has an explicit overriding for this
7229 Op_Elmt_2
:= Next_Elmt
(Op_Elmt
);
7230 while Present
(Op_Elmt_2
) loop
7231 if Chars
(Node
(Op_Elmt_2
)) = Chars
(Parent_Subp
)
7232 and then Type_Conformant
(Prim_Op
, Node
(Op_Elmt_2
))
7234 Set_DT_Position
(Prim_Op
, DT_Position
(Parent_Subp
));
7235 Set_DT_Position
(Node
(Op_Elmt_2
),
7236 DT_Position
(Parent_Subp
));
7237 Set_Fixed_Prim
(UI_To_Int
(DT_Position
(Prim_Op
)));
7239 goto Next_Primitive
;
7242 Next_Elmt
(Op_Elmt_2
);
7247 Next_Elmt
(Op_Elmt
);
7249 end Handle_Inherited_Private_Subprograms
;
7251 --------------------
7252 -- Set_Fixed_Prim --
7253 --------------------
7255 procedure Set_Fixed_Prim
(Pos
: Nat
) is
7257 pragma Assert
(Pos
<= Count_Prim
);
7258 Fixed_Prim
(Pos
) := True;
7260 when Constraint_Error
=>
7261 raise Program_Error
;
7265 -- In case of nested packages and public child package it may be
7266 -- necessary a special management on inherited subprograms so that
7267 -- the dispatch table is properly filled.
7269 if Ekind
(Scope
(Scope
(Typ
))) = E_Package
7270 and then Scope
(Scope
(Typ
)) /= Standard_Standard
7271 and then ((Is_Derived_Type
(Typ
) and then not Is_Private_Type
(Typ
))
7273 (Nkind
(Parent
(Typ
)) = N_Private_Extension_Declaration
7274 and then Is_Generic_Type
(Typ
)))
7275 and then In_Open_Scopes
(Scope
(Etype
(Typ
)))
7276 and then Typ
= Base_Type
(Typ
)
7278 Handle_Inherited_Private_Subprograms
(Typ
);
7281 -- Second stage: Register fixed entries
7284 Prim_Elmt
:= First_Prim
;
7285 while Present
(Prim_Elmt
) loop
7286 Prim
:= Node
(Prim_Elmt
);
7288 -- Predefined primitives have a separate table and all its
7289 -- entries are at predefined fixed positions.
7291 if Is_Predefined_Dispatching_Operation
(Prim
) then
7292 Set_DT_Position
(Prim
, Default_Prim_Op_Position
(Prim
));
7294 elsif Is_Predefined_Dispatching_Alias
(Prim
) then
7295 Set_DT_Position
(Prim
,
7296 Default_Prim_Op_Position
(Ultimate_Alias
(Prim
)));
7298 -- Overriding primitives of ancestor abstract interfaces
7300 elsif Present
(Interface_Alias
(Prim
))
7301 and then Is_Ancestor
7302 (Find_Dispatching_Type
(Interface_Alias
(Prim
)), Typ
)
7304 pragma Assert
(DT_Position
(Prim
) = No_Uint
7305 and then Present
(DTC_Entity
(Interface_Alias
(Prim
))));
7307 E
:= Interface_Alias
(Prim
);
7308 Set_DT_Position
(Prim
, DT_Position
(E
));
7311 (DT_Position
(Alias
(Prim
)) = No_Uint
7312 or else DT_Position
(Alias
(Prim
)) = DT_Position
(E
));
7313 Set_DT_Position
(Alias
(Prim
), DT_Position
(E
));
7314 Set_Fixed_Prim
(UI_To_Int
(DT_Position
(Prim
)));
7316 -- Overriding primitives must use the same entry as the
7317 -- overridden primitive.
7319 elsif not Present
(Interface_Alias
(Prim
))
7320 and then Present
(Alias
(Prim
))
7321 and then Chars
(Prim
) = Chars
(Alias
(Prim
))
7322 and then Find_Dispatching_Type
(Alias
(Prim
)) /= Typ
7323 and then Is_Ancestor
7324 (Find_Dispatching_Type
(Alias
(Prim
)), Typ
)
7325 and then Present
(DTC_Entity
(Alias
(Prim
)))
7328 Set_DT_Position
(Prim
, DT_Position
(E
));
7330 if not Is_Predefined_Dispatching_Alias
(E
) then
7331 Set_Fixed_Prim
(UI_To_Int
(DT_Position
(E
)));
7335 Next_Elmt
(Prim_Elmt
);
7338 -- Third stage: Fix the position of all the new primitives.
7339 -- Entries associated with primitives covering interfaces
7340 -- are handled in a latter round.
7342 Prim_Elmt
:= First_Prim
;
7343 while Present
(Prim_Elmt
) loop
7344 Prim
:= Node
(Prim_Elmt
);
7346 -- Skip primitives previously set entries
7348 if DT_Position
(Prim
) /= No_Uint
then
7351 -- Primitives covering interface primitives are handled later
7353 elsif Present
(Interface_Alias
(Prim
)) then
7357 -- Take the next available position in the DT
7360 Nb_Prim
:= Nb_Prim
+ 1;
7361 pragma Assert
(Nb_Prim
<= Count_Prim
);
7362 exit when not Fixed_Prim
(Nb_Prim
);
7365 Set_DT_Position
(Prim
, UI_From_Int
(Nb_Prim
));
7366 Set_Fixed_Prim
(Nb_Prim
);
7369 Next_Elmt
(Prim_Elmt
);
7373 -- Fourth stage: Complete the decoration of primitives covering
7374 -- interfaces (that is, propagate the DT_Position attribute
7375 -- from the aliased primitive)
7377 Prim_Elmt
:= First_Prim
;
7378 while Present
(Prim_Elmt
) loop
7379 Prim
:= Node
(Prim_Elmt
);
7381 if DT_Position
(Prim
) = No_Uint
7382 and then Present
(Interface_Alias
(Prim
))
7384 pragma Assert
(Present
(Alias
(Prim
))
7385 and then Find_Dispatching_Type
(Alias
(Prim
)) = Typ
);
7387 -- Check if this entry will be placed in the primary DT
7390 (Find_Dispatching_Type
(Interface_Alias
(Prim
)), Typ
)
7392 pragma Assert
(DT_Position
(Alias
(Prim
)) /= No_Uint
);
7393 Set_DT_Position
(Prim
, DT_Position
(Alias
(Prim
)));
7395 -- Otherwise it will be placed in the secondary DT
7399 (DT_Position
(Interface_Alias
(Prim
)) /= No_Uint
);
7400 Set_DT_Position
(Prim
,
7401 DT_Position
(Interface_Alias
(Prim
)));
7405 Next_Elmt
(Prim_Elmt
);
7408 -- Generate listing showing the contents of the dispatch tables.
7409 -- This action is done before some further static checks because
7410 -- in case of critical errors caused by a wrong dispatch table
7411 -- we need to see the contents of such table.
7413 if Debug_Flag_ZZ
then
7417 -- Final stage: Ensure that the table is correct plus some further
7418 -- verifications concerning the primitives.
7420 Prim_Elmt
:= First_Prim
;
7422 while Present
(Prim_Elmt
) loop
7423 Prim
:= Node
(Prim_Elmt
);
7425 -- At this point all the primitives MUST have a position
7426 -- in the dispatch table.
7428 if DT_Position
(Prim
) = No_Uint
then
7429 raise Program_Error
;
7432 -- Calculate real size of the dispatch table
7434 if not (Is_Predefined_Dispatching_Operation
(Prim
)
7435 or else Is_Predefined_Dispatching_Alias
(Prim
))
7436 and then UI_To_Int
(DT_Position
(Prim
)) > DT_Length
7438 DT_Length
:= UI_To_Int
(DT_Position
(Prim
));
7441 -- Ensure that the assigned position to non-predefined
7442 -- dispatching operations in the dispatch table is correct.
7444 if not (Is_Predefined_Dispatching_Operation
(Prim
)
7445 or else Is_Predefined_Dispatching_Alias
(Prim
))
7447 Validate_Position
(Prim
);
7450 if Chars
(Prim
) = Name_Finalize
then
7454 if Chars
(Prim
) = Name_Adjust
then
7458 -- An abstract operation cannot be declared in the private part for a
7459 -- visible abstract type, because it can't be overridden outside this
7460 -- package hierarchy. For explicit declarations this is checked at
7461 -- the point of declaration, but for inherited operations it must be
7462 -- done when building the dispatch table.
7464 -- Ada 2005 (AI-251): Primitives associated with interfaces are
7465 -- excluded from this check because interfaces must be visible in
7466 -- the public and private part (RM 7.3 (7.3/2))
7468 if Is_Abstract_Type
(Typ
)
7469 and then Is_Abstract_Subprogram
(Prim
)
7470 and then Present
(Alias
(Prim
))
7471 and then not Is_Interface
7472 (Find_Dispatching_Type
(Ultimate_Alias
(Prim
)))
7473 and then not Present
(Interface_Alias
(Prim
))
7474 and then Is_Derived_Type
(Typ
)
7475 and then In_Private_Part
(Current_Scope
)
7477 List_Containing
(Parent
(Prim
)) =
7478 Private_Declarations
7479 (Specification
(Unit_Declaration_Node
(Current_Scope
)))
7480 and then Original_View_In_Visible_Part
(Typ
)
7482 -- We exclude Input and Output stream operations because
7483 -- Limited_Controlled inherits useless Input and Output
7484 -- stream operations from Root_Controlled, which can
7485 -- never be overridden.
7487 if not Is_TSS
(Prim
, TSS_Stream_Input
)
7489 not Is_TSS
(Prim
, TSS_Stream_Output
)
7492 ("abstract inherited private operation&" &
7493 " must be overridden (RM 3.9.3(10))",
7494 Parent
(Typ
), Prim
);
7498 Next_Elmt
(Prim_Elmt
);
7503 if Is_Controlled
(Typ
) then
7504 if not Finalized
then
7506 ("controlled type has no explicit Finalize method?", Typ
);
7508 elsif not Adjusted
then
7510 ("controlled type has no explicit Adjust method?", Typ
);
7514 -- Set the final size of the Dispatch Table
7516 Set_DT_Entry_Count
(The_Tag
, UI_From_Int
(DT_Length
));
7518 -- The derived type must have at least as many components as its parent
7519 -- (for root types Etype points to itself and the test cannot fail).
7521 if DT_Entry_Count
(The_Tag
) <
7522 DT_Entry_Count
(First_Tag_Component
(Parent_Typ
))
7524 raise Program_Error
;
7526 end Set_All_DT_Position
;
7528 --------------------------
7529 -- Set_CPP_Constructors --
7530 --------------------------
7532 procedure Set_CPP_Constructors
(Typ
: Entity_Id
) is
7534 procedure Set_CPP_Constructors_Old
(Typ
: Entity_Id
);
7535 -- For backward compatibility this routine handles CPP constructors
7536 -- of non-tagged types.
7538 procedure Set_CPP_Constructors_Old
(Typ
: Entity_Id
) is
7542 Found
: Boolean := False;
7547 -- Look for the constructor entities
7549 E
:= Next_Entity
(Typ
);
7550 while Present
(E
) loop
7551 if Ekind
(E
) = E_Function
7552 and then Is_Constructor
(E
)
7554 -- Create the init procedure
7558 Init
:= Make_Defining_Identifier
(Loc
,
7559 Make_Init_Proc_Name
(Typ
));
7562 Make_Parameter_Specification
(Loc
,
7563 Defining_Identifier
=>
7564 Make_Defining_Identifier
(Loc
, Name_X
),
7566 New_Reference_To
(Typ
, Loc
)));
7568 if Present
(Parameter_Specifications
(Parent
(E
))) then
7569 P
:= First
(Parameter_Specifications
(Parent
(E
)));
7570 while Present
(P
) loop
7572 Make_Parameter_Specification
(Loc
,
7573 Defining_Identifier
=>
7574 Make_Defining_Identifier
(Loc
,
7575 Chars
(Defining_Identifier
(P
))),
7577 New_Copy_Tree
(Parameter_Type
(P
))));
7583 Make_Subprogram_Declaration
(Loc
,
7584 Make_Procedure_Specification
(Loc
,
7585 Defining_Unit_Name
=> Init
,
7586 Parameter_Specifications
=> Parms
)));
7588 Set_Init_Proc
(Typ
, Init
);
7589 Set_Is_Imported
(Init
);
7590 Set_Interface_Name
(Init
, Interface_Name
(E
));
7591 Set_Convention
(Init
, Convention_C
);
7592 Set_Is_Public
(Init
);
7593 Set_Has_Completion
(Init
);
7599 -- If there are no constructors, mark the type as abstract since we
7600 -- won't be able to declare objects of that type.
7603 Set_Is_Abstract_Type
(Typ
);
7605 end Set_CPP_Constructors_Old
;
7611 Found
: Boolean := False;
7615 Constructor_Decl_Node
: Node_Id
;
7616 Constructor_Id
: Entity_Id
;
7617 Wrapper_Id
: Entity_Id
;
7618 Wrapper_Body_Node
: Node_Id
;
7620 Body_Stmts
: List_Id
;
7621 Init_Tags_List
: List_Id
;
7624 pragma Assert
(Is_CPP_Class
(Typ
));
7626 -- For backward compatibility the compiler accepts C++ classes
7627 -- imported through non-tagged record types. In such case the
7628 -- wrapper of the C++ constructor is useless because the _tag
7629 -- component is not available.
7632 -- type Root is limited record ...
7633 -- pragma Import (CPP, Root);
7634 -- function New_Root return Root;
7635 -- pragma CPP_Constructor (New_Root, ... );
7637 if not Is_Tagged_Type
(Typ
) then
7638 Set_CPP_Constructors_Old
(Typ
);
7642 -- Look for the constructor entities
7644 E
:= Next_Entity
(Typ
);
7645 while Present
(E
) loop
7646 if Ekind
(E
) = E_Function
7647 and then Is_Constructor
(E
)
7652 -- Generate the declaration of the imported C++ constructor
7656 Make_Parameter_Specification
(Loc
,
7657 Defining_Identifier
=>
7658 Make_Defining_Identifier
(Loc
, Name_uInit
),
7660 New_Reference_To
(Typ
, Loc
)));
7662 if Present
(Parameter_Specifications
(Parent
(E
))) then
7663 P
:= First
(Parameter_Specifications
(Parent
(E
)));
7664 while Present
(P
) loop
7666 Make_Parameter_Specification
(Loc
,
7667 Defining_Identifier
=>
7668 Make_Defining_Identifier
(Loc
,
7669 Chars
(Defining_Identifier
(P
))),
7670 Parameter_Type
=> New_Copy_Tree
(Parameter_Type
(P
))));
7675 Constructor_Id
:= Make_Temporary
(Loc
, 'P');
7677 Constructor_Decl_Node
:=
7678 Make_Subprogram_Declaration
(Loc
,
7679 Make_Procedure_Specification
(Loc
,
7680 Defining_Unit_Name
=> Constructor_Id
,
7681 Parameter_Specifications
=> Parms
));
7683 Set_Is_Imported
(Constructor_Id
);
7684 Set_Interface_Name
(Constructor_Id
, Interface_Name
(E
));
7685 Set_Convention
(Constructor_Id
, Convention_C
);
7686 Set_Is_Public
(Constructor_Id
);
7687 Set_Has_Completion
(Constructor_Id
);
7689 -- Build the wrapper of this constructor
7693 Make_Parameter_Specification
(Loc
,
7694 Defining_Identifier
=>
7695 Make_Defining_Identifier
(Loc
, Name_uInit
),
7697 New_Reference_To
(Typ
, Loc
)));
7699 if Present
(Parameter_Specifications
(Parent
(E
))) then
7700 P
:= First
(Parameter_Specifications
(Parent
(E
)));
7701 while Present
(P
) loop
7703 Make_Parameter_Specification
(Loc
,
7704 Defining_Identifier
=>
7705 Make_Defining_Identifier
(Loc
,
7706 Chars
(Defining_Identifier
(P
))),
7707 Parameter_Type
=> New_Copy_Tree
(Parameter_Type
(P
))));
7712 Body_Stmts
:= New_List
;
7714 -- Invoke the C++ constructor
7716 Actuals
:= New_List
;
7719 while Present
(P
) loop
7721 New_Reference_To
(Defining_Identifier
(P
), Loc
));
7725 Append_To
(Body_Stmts
,
7726 Make_Procedure_Call_Statement
(Loc
,
7727 Name
=> New_Reference_To
(Constructor_Id
, Loc
),
7728 Parameter_Associations
=> Actuals
));
7730 -- Initialize copies of C++ primary and secondary tags
7732 Init_Tags_List
:= New_List
;
7739 Tag_Elmt
:= First_Elmt
(Access_Disp_Table
(Typ
));
7740 Tag_Comp
:= First_Tag_Component
(Typ
);
7742 while Present
(Tag_Elmt
)
7743 and then Is_Tag
(Node
(Tag_Elmt
))
7745 -- Skip the following assertion with primary tags because
7746 -- Related_Type is not set on primary tag components
7748 pragma Assert
(Tag_Comp
= First_Tag_Component
(Typ
)
7749 or else Related_Type
(Node
(Tag_Elmt
))
7750 = Related_Type
(Tag_Comp
));
7752 Append_To
(Init_Tags_List
,
7753 Make_Assignment_Statement
(Loc
,
7755 New_Reference_To
(Node
(Tag_Elmt
), Loc
),
7757 Make_Selected_Component
(Loc
,
7758 Prefix
=> Make_Identifier
(Loc
, Name_uInit
),
7760 New_Reference_To
(Tag_Comp
, Loc
))));
7762 Tag_Comp
:= Next_Tag_Component
(Tag_Comp
);
7763 Next_Elmt
(Tag_Elmt
);
7767 Append_To
(Body_Stmts
,
7768 Make_If_Statement
(Loc
,
7773 (Node
(First_Elmt
(Access_Disp_Table
(Typ
))),
7776 Unchecked_Convert_To
(RTE
(RE_Tag
),
7777 New_Reference_To
(RTE
(RE_Null_Address
), Loc
))),
7778 Then_Statements
=> Init_Tags_List
));
7780 Wrapper_Id
:= Make_Defining_Identifier
(Loc
,
7781 Make_Init_Proc_Name
(Typ
));
7783 Wrapper_Body_Node
:=
7784 Make_Subprogram_Body
(Loc
,
7786 Make_Procedure_Specification
(Loc
,
7787 Defining_Unit_Name
=> Wrapper_Id
,
7788 Parameter_Specifications
=> Parms
),
7789 Declarations
=> New_List
(Constructor_Decl_Node
),
7790 Handled_Statement_Sequence
=>
7791 Make_Handled_Sequence_Of_Statements
(Loc
,
7792 Statements
=> Body_Stmts
,
7793 Exception_Handlers
=> No_List
));
7795 Discard_Node
(Wrapper_Body_Node
);
7796 Set_Init_Proc
(Typ
, Wrapper_Id
);
7802 -- If there are no constructors, mark the type as abstract since we
7803 -- won't be able to declare objects of that type.
7806 Set_Is_Abstract_Type
(Typ
);
7809 -- If the CPP type has constructors then it must import also the default
7810 -- C++ constructor. It is required for default initialization of objects
7811 -- of the type. It is also required to elaborate objects of Ada types
7812 -- that are defined as derivations of this CPP type.
7814 if Has_CPP_Constructors
(Typ
)
7815 and then No
(Init_Proc
(Typ
))
7817 Error_Msg_N
("?default constructor must be imported from C++", Typ
);
7819 end Set_CPP_Constructors
;
7821 --------------------------
7822 -- Set_DTC_Entity_Value --
7823 --------------------------
7825 procedure Set_DTC_Entity_Value
7826 (Tagged_Type
: Entity_Id
;
7830 if Present
(Interface_Alias
(Prim
))
7831 and then Is_Interface
7832 (Find_Dispatching_Type
(Interface_Alias
(Prim
)))
7834 Set_DTC_Entity
(Prim
,
7837 Iface
=> Find_Dispatching_Type
(Interface_Alias
(Prim
))));
7839 Set_DTC_Entity
(Prim
,
7840 First_Tag_Component
(Tagged_Type
));
7842 end Set_DTC_Entity_Value
;
7848 function Tagged_Kind
(T
: Entity_Id
) return Node_Id
is
7849 Conc_Typ
: Entity_Id
;
7850 Loc
: constant Source_Ptr
:= Sloc
(T
);
7854 (Is_Tagged_Type
(T
) and then RTE_Available
(RE_Tagged_Kind
));
7858 if Is_Abstract_Type
(T
) then
7859 if Is_Limited_Record
(T
) then
7860 return New_Reference_To
(RTE
(RE_TK_Abstract_Limited_Tagged
), Loc
);
7862 return New_Reference_To
(RTE
(RE_TK_Abstract_Tagged
), Loc
);
7867 elsif Is_Concurrent_Record_Type
(T
) then
7868 Conc_Typ
:= Corresponding_Concurrent_Type
(T
);
7870 if Present
(Full_View
(Conc_Typ
)) then
7871 Conc_Typ
:= Full_View
(Conc_Typ
);
7874 if Ekind
(Conc_Typ
) = E_Protected_Type
then
7875 return New_Reference_To
(RTE
(RE_TK_Protected
), Loc
);
7877 pragma Assert
(Ekind
(Conc_Typ
) = E_Task_Type
);
7878 return New_Reference_To
(RTE
(RE_TK_Task
), Loc
);
7881 -- Regular tagged kinds
7884 if Is_Limited_Record
(T
) then
7885 return New_Reference_To
(RTE
(RE_TK_Limited_Tagged
), Loc
);
7887 return New_Reference_To
(RTE
(RE_TK_Tagged
), Loc
);
7896 procedure Write_DT
(Typ
: Entity_Id
) is
7901 -- Protect this procedure against wrong usage. Required because it will
7902 -- be used directly from GDB
7904 if not (Typ
<= Last_Node_Id
)
7905 or else not Is_Tagged_Type
(Typ
)
7907 Write_Str
("wrong usage: Write_DT must be used with tagged types");
7912 Write_Int
(Int
(Typ
));
7914 Write_Name
(Chars
(Typ
));
7916 if Is_Interface
(Typ
) then
7917 Write_Str
(" is interface");
7922 Elmt
:= First_Elmt
(Primitive_Operations
(Typ
));
7923 while Present
(Elmt
) loop
7924 Prim
:= Node
(Elmt
);
7927 -- Indicate if this primitive will be allocated in the primary
7928 -- dispatch table or in a secondary dispatch table associated
7929 -- with an abstract interface type
7931 if Present
(DTC_Entity
(Prim
)) then
7932 if Etype
(DTC_Entity
(Prim
)) = RTE
(RE_Tag
) then
7939 -- Output the node of this primitive operation and its name
7941 Write_Int
(Int
(Prim
));
7944 if Is_Predefined_Dispatching_Operation
(Prim
) then
7945 Write_Str
("(predefined) ");
7948 -- Prefix the name of the primitive with its corresponding tagged
7949 -- type to facilitate seeing inherited primitives.
7951 if Present
(Alias
(Prim
)) then
7953 (Chars
(Find_Dispatching_Type
(Ultimate_Alias
(Prim
))));
7955 Write_Name
(Chars
(Typ
));
7959 Write_Name
(Chars
(Prim
));
7961 -- Indicate if this primitive has an aliased primitive
7963 if Present
(Alias
(Prim
)) then
7964 Write_Str
(" (alias = ");
7965 Write_Int
(Int
(Alias
(Prim
)));
7967 -- If the DTC_Entity attribute is already set we can also output
7968 -- the name of the interface covered by this primitive (if any)
7970 if Present
(DTC_Entity
(Alias
(Prim
)))
7971 and then Is_Interface
(Scope
(DTC_Entity
(Alias
(Prim
))))
7973 Write_Str
(" from interface ");
7974 Write_Name
(Chars
(Scope
(DTC_Entity
(Alias
(Prim
)))));
7977 if Present
(Interface_Alias
(Prim
)) then
7978 Write_Str
(", AI_Alias of ");
7980 (Chars
(Find_Dispatching_Type
(Interface_Alias
(Prim
))));
7982 Write_Int
(Int
(Interface_Alias
(Prim
)));
7988 -- Display the final position of this primitive in its associated
7989 -- (primary or secondary) dispatch table
7991 if Present
(DTC_Entity
(Prim
))
7992 and then DT_Position
(Prim
) /= No_Uint
7994 Write_Str
(" at #");
7995 Write_Int
(UI_To_Int
(DT_Position
(Prim
)));
7998 if Is_Abstract_Subprogram
(Prim
) then
7999 Write_Str
(" is abstract;");
8001 -- Check if this is a null primitive
8003 elsif Comes_From_Source
(Prim
)
8004 and then Ekind
(Prim
) = E_Procedure
8005 and then Null_Present
(Parent
(Prim
))
8007 Write_Str
(" is null;");
8010 if Is_Eliminated
(Ultimate_Alias
(Prim
)) then
8011 Write_Str
(" (eliminated)");
8014 if Is_Imported
(Prim
)
8015 and then Convention
(Prim
) = Convention_CPP
8017 Write_Str
(" (C++)");