1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2007, 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_Dbug
; use Exp_Dbug
;
35 with Exp_Tss
; use Exp_Tss
;
36 with Exp_Util
; use Exp_Util
;
37 with Freeze
; use Freeze
;
38 with Itypes
; use Itypes
;
39 with Nlists
; use Nlists
;
40 with Nmake
; use Nmake
;
41 with Namet
; use Namet
;
43 with Output
; use Output
;
44 with Restrict
; use Restrict
;
45 with Rident
; use Rident
;
46 with Rtsfind
; use Rtsfind
;
48 with Sem_Ch6
; use Sem_Ch6
;
49 with Sem_Ch8
; use Sem_Ch8
;
50 with Sem_Disp
; use Sem_Disp
;
51 with Sem_Eval
; use Sem_Eval
;
52 with Sem_Res
; use Sem_Res
;
53 with Sem_Type
; use Sem_Type
;
54 with Sem_Util
; use Sem_Util
;
55 with Sinfo
; use Sinfo
;
56 with Snames
; use Snames
;
57 with Stand
; use Stand
;
58 with Stringt
; use Stringt
;
59 with Targparm
; use Targparm
;
60 with Tbuild
; use Tbuild
;
61 with Uintp
; use Uintp
;
63 package body Exp_Disp
is
65 -----------------------
66 -- Local Subprograms --
67 -----------------------
69 function Default_Prim_Op_Position
(E
: Entity_Id
) return Uint
;
70 -- Ada 2005 (AI-251): Returns the fixed position in the dispatch table
71 -- of the default primitive operations.
73 function Has_DT
(Typ
: Entity_Id
) return Boolean;
74 pragma Inline
(Has_DT
);
75 -- Returns true if we generate a dispatch table for tagged type Typ
77 function Is_Predefined_Dispatching_Alias
(Prim
: Entity_Id
) return Boolean;
78 -- Returns true if Prim is not a predefined dispatching primitive but it is
79 -- an alias of a predefined dispatching primitive (ie. through a renaming)
81 function Original_View_In_Visible_Part
(Typ
: Entity_Id
) return Boolean;
82 -- Check if the type has a private view or if the public view appears
83 -- in the visible part of a package spec.
87 Typ
: Entity_Id
) return Node_Id
;
88 -- Ada 2005 (AI-345): Determine the primitive operation kind of Prim
89 -- according to its type Typ. Return a reference to an RE_Prim_Op_Kind
92 function Tagged_Kind
(T
: Entity_Id
) return Node_Id
;
93 -- Ada 2005 (AI-345): Determine the tagged kind of T and return a reference
94 -- to an RE_Tagged_Kind enumeration value.
96 ------------------------
97 -- Building_Static_DT --
98 ------------------------
100 function Building_Static_DT
(Typ
: Entity_Id
) return Boolean is
102 return Static_Dispatch_Tables
103 and then Is_Library_Level_Tagged_Type
(Typ
)
105 -- If the type is derived from a CPP class we cannot statically
106 -- build the dispatch tables because we must inherit primitives
107 -- from the CPP side.
109 and then not Is_CPP_Class
(Root_Type
(Typ
));
110 end Building_Static_DT
;
112 ----------------------------------
113 -- Build_Static_Dispatch_Tables --
114 ----------------------------------
116 procedure Build_Static_Dispatch_Tables
(N
: Entity_Id
) is
117 Target_List
: List_Id
;
119 procedure Build_Dispatch_Tables
(List
: List_Id
);
120 -- Build the static dispatch table of tagged types found in the list of
121 -- declarations. The generated nodes are added at the end of Target_List
123 procedure Build_Package_Dispatch_Tables
(N
: Node_Id
);
124 -- Build static dispatch tables associated with package declaration N
126 ---------------------------
127 -- Build_Dispatch_Tables --
128 ---------------------------
130 procedure Build_Dispatch_Tables
(List
: List_Id
) is
135 while Present
(D
) loop
137 -- Handle nested packages and package bodies recursively. The
138 -- generated code is placed on the Target_List established for
139 -- the enclosing compilation unit.
141 if Nkind
(D
) = N_Package_Declaration
then
142 Build_Package_Dispatch_Tables
(D
);
144 elsif Nkind
(D
) = N_Package_Body
then
145 Build_Dispatch_Tables
(Declarations
(D
));
147 elsif Nkind
(D
) = N_Package_Body_Stub
148 and then Present
(Library_Unit
(D
))
150 Build_Dispatch_Tables
151 (Declarations
(Proper_Body
(Unit
(Library_Unit
(D
)))));
153 -- Handle full type declarations and derivations of library
154 -- level tagged types
156 elsif (Nkind
(D
) = N_Full_Type_Declaration
157 or else Nkind
(D
) = N_Derived_Type_Definition
)
158 and then Is_Library_Level_Tagged_Type
(Defining_Entity
(D
))
159 and then Ekind
(Defining_Entity
(D
)) /= E_Record_Subtype
160 and then not Is_Private_Type
(Defining_Entity
(D
))
162 Insert_List_After_And_Analyze
(Last
(Target_List
),
163 Make_DT
(Defining_Entity
(D
)));
165 -- Handle private types of library level tagged types. We must
166 -- exchange the private and full-view to ensure the correct
169 elsif (Nkind
(D
) = N_Private_Type_Declaration
170 or else Nkind
(D
) = N_Private_Extension_Declaration
)
171 and then Present
(Full_View
(Defining_Entity
(D
)))
172 and then Is_Library_Level_Tagged_Type
173 (Full_View
(Defining_Entity
(D
)))
174 and then Ekind
(Full_View
(Defining_Entity
(D
)))
180 E1
:= Defining_Entity
(D
);
181 E2
:= Full_View
(Defining_Entity
(D
));
182 Exchange_Entities
(E1
, E2
);
183 Insert_List_After_And_Analyze
(Last
(Target_List
),
185 Exchange_Entities
(E1
, E2
);
191 end Build_Dispatch_Tables
;
193 -----------------------------------
194 -- Build_Package_Dispatch_Tables --
195 -----------------------------------
197 procedure Build_Package_Dispatch_Tables
(N
: Node_Id
) is
198 Spec
: constant Node_Id
:= Specification
(N
);
199 Id
: constant Entity_Id
:= Defining_Entity
(N
);
200 Vis_Decls
: constant List_Id
:= Visible_Declarations
(Spec
);
201 Priv_Decls
: constant List_Id
:= Private_Declarations
(Spec
);
206 if Present
(Priv_Decls
) then
207 Build_Dispatch_Tables
(Vis_Decls
);
208 Build_Dispatch_Tables
(Priv_Decls
);
210 elsif Present
(Vis_Decls
) then
211 Build_Dispatch_Tables
(Vis_Decls
);
215 end Build_Package_Dispatch_Tables
;
217 -- Start of processing for Build_Static_Dispatch_Tables
220 if not Expander_Active
221 or else VM_Target
/= No_VM
226 if Nkind
(N
) = N_Package_Declaration
then
228 Spec
: constant Node_Id
:= Specification
(N
);
229 Vis_Decls
: constant List_Id
:= Visible_Declarations
(Spec
);
230 Priv_Decls
: constant List_Id
:= Private_Declarations
(Spec
);
233 if Present
(Priv_Decls
)
234 and then Is_Non_Empty_List
(Priv_Decls
)
236 Target_List
:= Priv_Decls
;
238 elsif not Present
(Vis_Decls
) then
239 Target_List
:= New_List
;
240 Set_Private_Declarations
(Spec
, Target_List
);
242 Target_List
:= Vis_Decls
;
245 Build_Package_Dispatch_Tables
(N
);
248 else pragma Assert
(Nkind
(N
) = N_Package_Body
);
249 Target_List
:= Declarations
(N
);
250 Build_Dispatch_Tables
(Target_List
);
252 end Build_Static_Dispatch_Tables
;
254 ------------------------------
255 -- Default_Prim_Op_Position --
256 ------------------------------
258 function Default_Prim_Op_Position
(E
: Entity_Id
) return Uint
is
259 TSS_Name
: TSS_Name_Type
;
262 Get_Name_String
(Chars
(E
));
265 (Name_Buffer
(Name_Len
- TSS_Name
'Length + 1 .. Name_Len
));
267 if Chars
(E
) = Name_uSize
then
270 elsif Chars
(E
) = Name_uAlignment
then
273 elsif TSS_Name
= TSS_Stream_Read
then
276 elsif TSS_Name
= TSS_Stream_Write
then
279 elsif TSS_Name
= TSS_Stream_Input
then
282 elsif TSS_Name
= TSS_Stream_Output
then
285 elsif Chars
(E
) = Name_Op_Eq
then
288 elsif Chars
(E
) = Name_uAssign
then
291 elsif TSS_Name
= TSS_Deep_Adjust
then
294 elsif TSS_Name
= TSS_Deep_Finalize
then
297 elsif Ada_Version
>= Ada_05
then
298 if Chars
(E
) = Name_uDisp_Asynchronous_Select
then
301 elsif Chars
(E
) = Name_uDisp_Conditional_Select
then
304 elsif Chars
(E
) = Name_uDisp_Get_Prim_Op_Kind
then
307 elsif Chars
(E
) = Name_uDisp_Get_Task_Id
then
310 elsif Chars
(E
) = Name_uDisp_Requeue
then
313 elsif Chars
(E
) = Name_uDisp_Timed_Select
then
319 end Default_Prim_Op_Position
;
321 -----------------------------
322 -- Expand_Dispatching_Call --
323 -----------------------------
325 procedure Expand_Dispatching_Call
(Call_Node
: Node_Id
) is
326 Loc
: constant Source_Ptr
:= Sloc
(Call_Node
);
327 Call_Typ
: constant Entity_Id
:= Etype
(Call_Node
);
329 Ctrl_Arg
: constant Node_Id
:= Controlling_Argument
(Call_Node
);
330 Param_List
: constant List_Id
:= Parameter_Associations
(Call_Node
);
335 New_Call_Name
: Node_Id
;
336 New_Params
: List_Id
:= No_List
;
339 Subp_Ptr_Typ
: Entity_Id
;
340 Subp_Typ
: Entity_Id
;
342 Eq_Prim_Op
: Entity_Id
:= Empty
;
343 Controlling_Tag
: Node_Id
;
345 function New_Value
(From
: Node_Id
) return Node_Id
;
346 -- From is the original Expression. New_Value is equivalent to a call
347 -- to Duplicate_Subexpr with an explicit dereference when From is an
354 function New_Value
(From
: Node_Id
) return Node_Id
is
355 Res
: constant Node_Id
:= Duplicate_Subexpr
(From
);
357 if Is_Access_Type
(Etype
(From
)) then
359 Make_Explicit_Dereference
(Sloc
(From
),
366 -- Start of processing for Expand_Dispatching_Call
369 if No_Run_Time_Mode
then
370 Error_Msg_CRT
("tagged types", Call_Node
);
374 -- Expand_Dispatching_Call is called directly from the semantics,
375 -- so we need a check to see whether expansion is active before
376 -- proceeding. In addition, there is no need to expand the call
377 -- if we are compiling under restriction No_Dispatching_Calls;
378 -- the semantic analyzer has previously notified the violation
379 -- of this restriction.
381 if not Expander_Active
382 or else Restriction_Active
(No_Dispatching_Calls
)
387 -- Set subprogram. If this is an inherited operation that was
388 -- overridden, the body that is being called is its alias.
390 Subp
:= Entity
(Name
(Call_Node
));
392 if Present
(Alias
(Subp
))
393 and then Is_Inherited_Operation
(Subp
)
394 and then No
(DTC_Entity
(Subp
))
396 Subp
:= Alias
(Subp
);
399 -- Definition of the class-wide type and the tagged type
401 -- If the controlling argument is itself a tag rather than a tagged
402 -- object, then use the class-wide type associated with the subprogram's
403 -- controlling type. This case can occur when a call to an inherited
404 -- primitive has an actual that originated from a default parameter
405 -- given by a tag-indeterminate call and when there is no other
406 -- controlling argument providing the tag (AI-239 requires dispatching).
407 -- This capability of dispatching directly by tag is also needed by the
408 -- implementation of AI-260 (for the generic dispatching constructors).
410 if Etype
(Ctrl_Arg
) = RTE
(RE_Tag
)
411 or else (RTE_Available
(RE_Interface_Tag
)
412 and then Etype
(Ctrl_Arg
) = RTE
(RE_Interface_Tag
))
414 CW_Typ
:= Class_Wide_Type
(Find_Dispatching_Type
(Subp
));
416 -- Class_Wide_Type is applied to the expressions used to initialize
417 -- CW_Typ, to ensure that CW_Typ always denotes a class-wide type, since
418 -- there are cases where the controlling type is resolved to a specific
419 -- type (such as for designated types of arguments such as CW'Access).
421 elsif Is_Access_Type
(Etype
(Ctrl_Arg
)) then
422 CW_Typ
:= Class_Wide_Type
(Designated_Type
(Etype
(Ctrl_Arg
)));
425 CW_Typ
:= Class_Wide_Type
(Etype
(Ctrl_Arg
));
428 Typ
:= Root_Type
(CW_Typ
);
430 if Ekind
(Typ
) = E_Incomplete_Type
then
431 Typ
:= Non_Limited_View
(Typ
);
434 if not Is_Limited_Type
(Typ
) then
435 Eq_Prim_Op
:= Find_Prim_Op
(Typ
, Name_Op_Eq
);
438 -- Dispatching call to C++ primitive. Create a new parameter list
439 -- with no tag checks.
441 if Is_CPP_Class
(Typ
) then
442 New_Params
:= New_List
;
443 Param
:= First_Actual
(Call_Node
);
444 while Present
(Param
) loop
445 Append_To
(New_Params
, Relocate_Node
(Param
));
449 -- Dispatching call to Ada primitive
451 elsif Present
(Param_List
) then
453 -- Generate the Tag checks when appropriate
455 New_Params
:= New_List
;
456 Param
:= First_Actual
(Call_Node
);
457 while Present
(Param
) loop
459 -- No tag check with itself
461 if Param
= Ctrl_Arg
then
462 Append_To
(New_Params
,
463 Duplicate_Subexpr_Move_Checks
(Param
));
465 -- No tag check for parameter whose type is neither tagged nor
466 -- access to tagged (for access parameters)
468 elsif No
(Find_Controlling_Arg
(Param
)) then
469 Append_To
(New_Params
, Relocate_Node
(Param
));
471 -- No tag check for function dispatching on result if the
472 -- Tag given by the context is this one
474 elsif Find_Controlling_Arg
(Param
) = Ctrl_Arg
then
475 Append_To
(New_Params
, Relocate_Node
(Param
));
477 -- "=" is the only dispatching operation allowed to get
478 -- operands with incompatible tags (it just returns false).
479 -- We use Duplicate_Subexpr_Move_Checks instead of calling
480 -- Relocate_Node because the value will be duplicated to
483 elsif Subp
= Eq_Prim_Op
then
484 Append_To
(New_Params
,
485 Duplicate_Subexpr_Move_Checks
(Param
));
487 -- No check in presence of suppress flags
489 elsif Tag_Checks_Suppressed
(Etype
(Param
))
490 or else (Is_Access_Type
(Etype
(Param
))
491 and then Tag_Checks_Suppressed
492 (Designated_Type
(Etype
(Param
))))
494 Append_To
(New_Params
, Relocate_Node
(Param
));
496 -- Optimization: no tag checks if the parameters are identical
498 elsif Is_Entity_Name
(Param
)
499 and then Is_Entity_Name
(Ctrl_Arg
)
500 and then Entity
(Param
) = Entity
(Ctrl_Arg
)
502 Append_To
(New_Params
, Relocate_Node
(Param
));
504 -- Now we need to generate the Tag check
507 -- Generate code for tag equality check
508 -- Perhaps should have Checks.Apply_Tag_Equality_Check???
510 Insert_Action
(Ctrl_Arg
,
511 Make_Implicit_If_Statement
(Call_Node
,
515 Make_Selected_Component
(Loc
,
516 Prefix
=> New_Value
(Ctrl_Arg
),
519 (First_Tag_Component
(Typ
), Loc
)),
522 Make_Selected_Component
(Loc
,
524 Unchecked_Convert_To
(Typ
, New_Value
(Param
)),
527 (First_Tag_Component
(Typ
), Loc
))),
530 New_List
(New_Constraint_Error
(Loc
))));
532 Append_To
(New_Params
, Relocate_Node
(Param
));
539 -- Generate the appropriate subprogram pointer type
541 if Etype
(Subp
) = Typ
then
544 Res_Typ
:= Etype
(Subp
);
547 Subp_Typ
:= Create_Itype
(E_Subprogram_Type
, Call_Node
);
548 Subp_Ptr_Typ
:= Create_Itype
(E_Access_Subprogram_Type
, Call_Node
);
549 Set_Etype
(Subp_Typ
, Res_Typ
);
550 Init_Size_Align
(Subp_Ptr_Typ
);
551 Set_Returns_By_Ref
(Subp_Typ
, Returns_By_Ref
(Subp
));
553 -- Create a new list of parameters which is a copy of the old formal
554 -- list including the creation of a new set of matching entities.
557 Old_Formal
: Entity_Id
:= First_Formal
(Subp
);
558 New_Formal
: Entity_Id
;
559 Extra
: Entity_Id
:= Empty
;
562 if Present
(Old_Formal
) then
563 New_Formal
:= New_Copy
(Old_Formal
);
564 Set_First_Entity
(Subp_Typ
, New_Formal
);
565 Param
:= First_Actual
(Call_Node
);
568 Set_Scope
(New_Formal
, Subp_Typ
);
570 -- Change all the controlling argument types to be class-wide
571 -- to avoid a recursion in dispatching.
573 if Is_Controlling_Formal
(New_Formal
) then
574 Set_Etype
(New_Formal
, Etype
(Param
));
577 if Is_Itype
(Etype
(New_Formal
)) then
578 Extra
:= New_Copy
(Etype
(New_Formal
));
580 if Ekind
(Extra
) = E_Record_Subtype
581 or else Ekind
(Extra
) = E_Class_Wide_Subtype
583 Set_Cloned_Subtype
(Extra
, Etype
(New_Formal
));
586 Set_Etype
(New_Formal
, Extra
);
587 Set_Scope
(Etype
(New_Formal
), Subp_Typ
);
591 Next_Formal
(Old_Formal
);
592 exit when No
(Old_Formal
);
594 Set_Next_Entity
(New_Formal
, New_Copy
(Old_Formal
));
595 Next_Entity
(New_Formal
);
599 Set_Next_Entity
(New_Formal
, Empty
);
600 Set_Last_Entity
(Subp_Typ
, Extra
);
603 -- Now that the explicit formals have been duplicated, any extra
604 -- formals needed by the subprogram must be created.
606 if Present
(Extra
) then
607 Set_Extra_Formal
(Extra
, Empty
);
610 Create_Extra_Formals
(Subp_Typ
);
613 Set_Etype
(Subp_Ptr_Typ
, Subp_Ptr_Typ
);
614 Set_Directly_Designated_Type
(Subp_Ptr_Typ
, Subp_Typ
);
616 -- If the controlling argument is a value of type Ada.Tag or an abstract
617 -- interface class-wide type then use it directly. Otherwise, the tag
618 -- must be extracted from the controlling object.
620 if Etype
(Ctrl_Arg
) = RTE
(RE_Tag
)
621 or else (RTE_Available
(RE_Interface_Tag
)
622 and then Etype
(Ctrl_Arg
) = RTE
(RE_Interface_Tag
))
624 Controlling_Tag
:= Duplicate_Subexpr
(Ctrl_Arg
);
626 -- Extract the tag from an unchecked type conversion. Done to avoid
627 -- the expansion of additional code just to obtain the value of such
628 -- tag because the current management of interface type conversions
629 -- generates in some cases this unchecked type conversion with the
630 -- tag of the object (see Expand_Interface_Conversion).
632 elsif Nkind
(Ctrl_Arg
) = N_Unchecked_Type_Conversion
634 (Etype
(Expression
(Ctrl_Arg
)) = RTE
(RE_Tag
)
636 (RTE_Available
(RE_Interface_Tag
)
638 Etype
(Expression
(Ctrl_Arg
)) = RTE
(RE_Interface_Tag
)))
640 Controlling_Tag
:= Duplicate_Subexpr
(Expression
(Ctrl_Arg
));
642 -- Ada 2005 (AI-251): Abstract interface class-wide type
644 elsif Is_Interface
(Etype
(Ctrl_Arg
))
645 and then Is_Class_Wide_Type
(Etype
(Ctrl_Arg
))
647 Controlling_Tag
:= Duplicate_Subexpr
(Ctrl_Arg
);
651 Make_Selected_Component
(Loc
,
652 Prefix
=> Duplicate_Subexpr_Move_Checks
(Ctrl_Arg
),
653 Selector_Name
=> New_Reference_To
(DTC_Entity
(Subp
), Loc
));
656 -- Handle dispatching calls to predefined primitives
658 if Is_Predefined_Dispatching_Operation
(Subp
)
659 or else Is_Predefined_Dispatching_Alias
(Subp
)
662 Unchecked_Convert_To
(Subp_Ptr_Typ
,
663 Build_Get_Predefined_Prim_Op_Address
(Loc
,
664 Tag_Node
=> Controlling_Tag
,
665 Position
=> DT_Position
(Subp
)));
667 -- Handle dispatching calls to user-defined primitives
671 Unchecked_Convert_To
(Subp_Ptr_Typ
,
672 Build_Get_Prim_Op_Address
(Loc
,
673 Typ
=> Find_Dispatching_Type
(Subp
),
674 Tag_Node
=> Controlling_Tag
,
675 Position
=> DT_Position
(Subp
)));
678 if Nkind
(Call_Node
) = N_Function_Call
then
681 Make_Function_Call
(Loc
,
682 Name
=> New_Call_Name
,
683 Parameter_Associations
=> New_Params
);
685 -- If this is a dispatching "=", we must first compare the tags so
686 -- we generate: x.tag = y.tag and then x = y
688 if Subp
= Eq_Prim_Op
then
689 Param
:= First_Actual
(Call_Node
);
695 Make_Selected_Component
(Loc
,
696 Prefix
=> New_Value
(Param
),
698 New_Reference_To
(First_Tag_Component
(Typ
),
702 Make_Selected_Component
(Loc
,
704 Unchecked_Convert_To
(Typ
,
705 New_Value
(Next_Actual
(Param
))),
707 New_Reference_To
(First_Tag_Component
(Typ
),
709 Right_Opnd
=> New_Call
);
714 Make_Procedure_Call_Statement
(Loc
,
715 Name
=> New_Call_Name
,
716 Parameter_Associations
=> New_Params
);
719 Rewrite
(Call_Node
, New_Call
);
721 -- Suppress all checks during the analysis of the expanded code
722 -- to avoid the generation of spureous warnings under ZFP run-time.
724 Analyze_And_Resolve
(Call_Node
, Call_Typ
, Suppress
=> All_Checks
);
725 end Expand_Dispatching_Call
;
727 ---------------------------------
728 -- Expand_Interface_Conversion --
729 ---------------------------------
731 procedure Expand_Interface_Conversion
733 Is_Static
: Boolean := True)
735 Loc
: constant Source_Ptr
:= Sloc
(N
);
736 Etyp
: constant Entity_Id
:= Etype
(N
);
737 Operand
: constant Node_Id
:= Expression
(N
);
738 Operand_Typ
: Entity_Id
:= Etype
(Operand
);
740 Iface_Typ
: Entity_Id
:= Etype
(N
);
741 Iface_Tag
: Entity_Id
;
744 -- Ada 2005 (AI-345): Handle synchronized interface type derivations
746 if Is_Concurrent_Type
(Operand_Typ
) then
747 Operand_Typ
:= Base_Type
(Corresponding_Record_Type
(Operand_Typ
));
750 -- Handle access to class-wide interface types
752 if Is_Access_Type
(Iface_Typ
) then
753 Iface_Typ
:= Etype
(Directly_Designated_Type
(Iface_Typ
));
756 -- Handle class-wide interface types. This conversion can appear
757 -- explicitly in the source code. Example: I'Class (Obj)
759 if Is_Class_Wide_Type
(Iface_Typ
) then
760 Iface_Typ
:= Root_Type
(Iface_Typ
);
763 pragma Assert
(not Is_Static
764 or else (not Is_Class_Wide_Type
(Iface_Typ
)
765 and then Is_Interface
(Iface_Typ
)));
767 if VM_Target
/= No_VM
then
769 -- For VM, just do a conversion ???
771 Rewrite
(N
, Unchecked_Convert_To
(Etype
(N
), N
));
776 if not Is_Static
then
778 -- Give error if configurable run time and Displace not available
780 if not RTE_Available
(RE_Displace
) then
781 Error_Msg_CRT
("abstract interface types", N
);
785 -- Handle conversion of access-to-class-wide interface types. Target
786 -- can be an access to an object or an access to another class-wide
787 -- interface (see -1- and -2- in the following example):
789 -- type Iface1_Ref is access all Iface1'Class;
790 -- type Iface2_Ref is access all Iface1'Class;
792 -- Acc1 : Iface1_Ref := new ...
793 -- Obj : Obj_Ref := Obj_Ref (Acc); -- 1
794 -- Acc2 : Iface2_Ref := Iface2_Ref (Acc); -- 2
796 if Is_Access_Type
(Operand_Typ
) then
798 (Is_Interface
(Directly_Designated_Type
(Operand_Typ
)));
801 Unchecked_Convert_To
(Etype
(N
),
802 Make_Function_Call
(Loc
,
803 Name
=> New_Reference_To
(RTE
(RE_Displace
), Loc
),
804 Parameter_Associations
=> New_List
(
806 Unchecked_Convert_To
(RTE
(RE_Address
),
807 Relocate_Node
(Expression
(N
))),
810 (Node
(First_Elmt
(Access_Disp_Table
(Iface_Typ
))),
818 Make_Function_Call
(Loc
,
819 Name
=> New_Reference_To
(RTE
(RE_Displace
), Loc
),
820 Parameter_Associations
=> New_List
(
821 Make_Attribute_Reference
(Loc
,
822 Prefix
=> Relocate_Node
(Expression
(N
)),
823 Attribute_Name
=> Name_Address
),
826 (Node
(First_Elmt
(Access_Disp_Table
(Iface_Typ
))),
831 -- If the target is a class-wide interface we change the type of the
832 -- data returned by IW_Convert to indicate that this is a dispatching
836 New_Itype
: Entity_Id
;
839 New_Itype
:= Create_Itype
(E_Anonymous_Access_Type
, N
);
840 Set_Etype
(New_Itype
, New_Itype
);
841 Init_Esize
(New_Itype
);
842 Init_Size_Align
(New_Itype
);
843 Set_Directly_Designated_Type
(New_Itype
, Etyp
);
846 Make_Explicit_Dereference
(Loc
,
848 Unchecked_Convert_To
(New_Itype
, Relocate_Node
(N
))));
850 Freeze_Itype
(New_Itype
, N
);
856 Iface_Tag
:= Find_Interface_Tag
(Operand_Typ
, Iface_Typ
);
857 pragma Assert
(Iface_Tag
/= Empty
);
859 -- Keep separate access types to interfaces because one internal
860 -- function is used to handle the null value (see following comment)
862 if not Is_Access_Type
(Etype
(N
)) then
864 Unchecked_Convert_To
(Etype
(N
),
865 Make_Selected_Component
(Loc
,
866 Prefix
=> Relocate_Node
(Expression
(N
)),
868 New_Occurrence_Of
(Iface_Tag
, Loc
))));
871 -- Build internal function to handle the case in which the
872 -- actual is null. If the actual is null returns null because
873 -- no displacement is required; otherwise performs a type
874 -- conversion that will be expanded in the code that returns
875 -- the value of the displaced actual. That is:
877 -- function Func (O : Address) return Iface_Typ is
878 -- type Op_Typ is access all Operand_Typ;
879 -- Aux : Op_Typ := To_Op_Typ (O);
881 -- if O = Null_Address then
884 -- return Iface_Typ!(Aux.Iface_Tag'Address);
889 Desig_Typ
: Entity_Id
;
891 New_Typ_Decl
: Node_Id
;
895 Desig_Typ
:= Etype
(Expression
(N
));
897 if Is_Access_Type
(Desig_Typ
) then
898 Desig_Typ
:= Directly_Designated_Type
(Desig_Typ
);
901 if Is_Concurrent_Type
(Desig_Typ
) then
902 Desig_Typ
:= Base_Type
(Corresponding_Record_Type
(Desig_Typ
));
906 Make_Full_Type_Declaration
(Loc
,
907 Defining_Identifier
=>
908 Make_Defining_Identifier
(Loc
, New_Internal_Name
('T')),
910 Make_Access_To_Object_Definition
(Loc
,
912 Null_Exclusion_Present
=> False,
913 Constant_Present
=> False,
914 Subtype_Indication
=>
915 New_Reference_To
(Desig_Typ
, Loc
)));
918 Make_Simple_Return_Statement
(Loc
,
919 Unchecked_Convert_To
(Etype
(N
),
920 Make_Attribute_Reference
(Loc
,
922 Make_Selected_Component
(Loc
,
925 (Defining_Identifier
(New_Typ_Decl
),
926 Make_Identifier
(Loc
, Name_uO
)),
928 New_Occurrence_Of
(Iface_Tag
, Loc
)),
929 Attribute_Name
=> Name_Address
))));
931 -- If the type is null-excluding, no need for the null branch.
932 -- Otherwise we need to check for it and return null.
934 if not Can_Never_Be_Null
(Etype
(N
)) then
936 Make_If_Statement
(Loc
,
939 Left_Opnd
=> Make_Identifier
(Loc
, Name_uO
),
940 Right_Opnd
=> New_Reference_To
941 (RTE
(RE_Null_Address
), Loc
)),
943 Then_Statements
=> New_List
(
944 Make_Simple_Return_Statement
(Loc
,
946 Else_Statements
=> Stats
));
950 Make_Defining_Identifier
(Loc
,
951 New_Internal_Name
('F'));
954 Make_Subprogram_Body
(Loc
,
956 Make_Function_Specification
(Loc
,
957 Defining_Unit_Name
=> Fent
,
959 Parameter_Specifications
=> New_List
(
960 Make_Parameter_Specification
(Loc
,
961 Defining_Identifier
=>
962 Make_Defining_Identifier
(Loc
, Name_uO
),
964 New_Reference_To
(RTE
(RE_Address
), Loc
))),
967 New_Reference_To
(Etype
(N
), Loc
)),
969 Declarations
=> New_List
(New_Typ_Decl
),
971 Handled_Statement_Sequence
=>
972 Make_Handled_Sequence_Of_Statements
(Loc
, Stats
));
974 -- Place function body before the expression containing the
975 -- conversion. We suppress all checks because the body of the
976 -- internally generated function already takes care of the case
977 -- in which the actual is null; therefore there is no need to
978 -- double check that the pointer is not null when the program
979 -- executes the alternative that performs the type conversion).
981 Insert_Action
(N
, Func
, Suppress
=> All_Checks
);
983 if Is_Access_Type
(Etype
(Expression
(N
))) then
985 -- Generate: Func (Address!(Expression))
988 Make_Function_Call
(Loc
,
989 Name
=> New_Reference_To
(Fent
, Loc
),
990 Parameter_Associations
=> New_List
(
991 Unchecked_Convert_To
(RTE
(RE_Address
),
992 Relocate_Node
(Expression
(N
))))));
995 -- Generate: Func (Operand_Typ!(Expression)'Address)
998 Make_Function_Call
(Loc
,
999 Name
=> New_Reference_To
(Fent
, Loc
),
1000 Parameter_Associations
=> New_List
(
1001 Make_Attribute_Reference
(Loc
,
1002 Prefix
=> Unchecked_Convert_To
(Operand_Typ
,
1003 Relocate_Node
(Expression
(N
))),
1004 Attribute_Name
=> Name_Address
))));
1010 end Expand_Interface_Conversion
;
1012 ------------------------------
1013 -- Expand_Interface_Actuals --
1014 ------------------------------
1016 procedure Expand_Interface_Actuals
(Call_Node
: Node_Id
) is
1018 Actual_Dup
: Node_Id
;
1019 Actual_Typ
: Entity_Id
;
1021 Conversion
: Node_Id
;
1023 Formal_Typ
: Entity_Id
;
1025 Formal_DDT
: Entity_Id
;
1026 Actual_DDT
: Entity_Id
;
1029 -- This subprogram is called directly from the semantics, so we need a
1030 -- check to see whether expansion is active before proceeding.
1032 if not Expander_Active
then
1036 -- Call using access to subprogram with explicit dereference
1038 if Nkind
(Name
(Call_Node
)) = N_Explicit_Dereference
then
1039 Subp
:= Etype
(Name
(Call_Node
));
1044 Subp
:= Entity
(Name
(Call_Node
));
1047 -- Ada 2005 (AI-251): Look for interface type formals to force "this"
1050 Formal
:= First_Formal
(Subp
);
1051 Actual
:= First_Actual
(Call_Node
);
1052 while Present
(Formal
) loop
1053 Formal_Typ
:= Etype
(Formal
);
1055 if Ekind
(Formal_Typ
) = E_Record_Type_With_Private
then
1056 Formal_Typ
:= Full_View
(Formal_Typ
);
1059 if Is_Access_Type
(Formal_Typ
) then
1060 Formal_DDT
:= Directly_Designated_Type
(Formal_Typ
);
1063 Actual_Typ
:= Etype
(Actual
);
1065 if Is_Access_Type
(Actual_Typ
) then
1066 Actual_DDT
:= Directly_Designated_Type
(Actual_Typ
);
1069 if Is_Interface
(Formal_Typ
)
1070 and then Is_Class_Wide_Type
(Formal_Typ
)
1072 -- No need to displace the pointer if the type of the actual
1073 -- coindices with the type of the formal.
1075 if Actual_Typ
= Formal_Typ
then
1078 -- No need to displace the pointer if the interface type is
1079 -- a parent of the type of the actual because in this case the
1080 -- interface primitives are located in the primary dispatch table.
1082 elsif Is_Parent
(Formal_Typ
, Actual_Typ
) then
1085 -- Implicit conversion to the class-wide formal type to force
1086 -- the displacement of the pointer.
1089 Conversion
:= Convert_To
(Formal_Typ
, Relocate_Node
(Actual
));
1090 Rewrite
(Actual
, Conversion
);
1091 Analyze_And_Resolve
(Actual
, Formal_Typ
);
1094 -- Access to class-wide interface type
1096 elsif Is_Access_Type
(Formal_Typ
)
1097 and then Is_Interface
(Formal_DDT
)
1098 and then Is_Class_Wide_Type
(Formal_DDT
)
1099 and then Interface_Present_In_Ancestor
1101 Iface
=> Etype
(Formal_DDT
))
1103 -- Handle attributes 'Access and 'Unchecked_Access
1105 if Nkind
(Actual
) = N_Attribute_Reference
1107 (Attribute_Name
(Actual
) = Name_Access
1108 or else Attribute_Name
(Actual
) = Name_Unchecked_Access
)
1110 -- This case must have been handled by the analysis and
1111 -- expansion of 'Access. The only exception is when types
1112 -- match and no further expansion is required.
1114 pragma Assert
(Base_Type
(Etype
(Prefix
(Actual
)))
1115 = Base_Type
(Formal_DDT
));
1118 -- No need to displace the pointer if the type of the actual
1119 -- coincides with the type of the formal.
1121 elsif Actual_DDT
= Formal_DDT
then
1124 -- No need to displace the pointer if the interface type is
1125 -- a parent of the type of the actual because in this case the
1126 -- interface primitives are located in the primary dispatch table.
1128 elsif Is_Parent
(Formal_DDT
, Actual_DDT
) then
1132 Actual_Dup
:= Relocate_Node
(Actual
);
1134 if From_With_Type
(Actual_Typ
) then
1136 -- If the type of the actual parameter comes from a limited
1137 -- with-clause and the non-limited view is already available
1138 -- we replace the anonymous access type by a duplicate decla
1139 -- ration whose designated type is the non-limited view
1141 if Ekind
(Actual_DDT
) = E_Incomplete_Type
1142 and then Present
(Non_Limited_View
(Actual_DDT
))
1144 Anon
:= New_Copy
(Actual_Typ
);
1146 if Is_Itype
(Anon
) then
1147 Set_Scope
(Anon
, Current_Scope
);
1150 Set_Directly_Designated_Type
(Anon
,
1151 Non_Limited_View
(Actual_DDT
));
1152 Set_Etype
(Actual_Dup
, Anon
);
1154 elsif Is_Class_Wide_Type
(Actual_DDT
)
1155 and then Ekind
(Etype
(Actual_DDT
)) = E_Incomplete_Type
1156 and then Present
(Non_Limited_View
(Etype
(Actual_DDT
)))
1158 Anon
:= New_Copy
(Actual_Typ
);
1160 if Is_Itype
(Anon
) then
1161 Set_Scope
(Anon
, Current_Scope
);
1164 Set_Directly_Designated_Type
(Anon
,
1165 New_Copy
(Actual_DDT
));
1166 Set_Class_Wide_Type
(Directly_Designated_Type
(Anon
),
1167 New_Copy
(Class_Wide_Type
(Actual_DDT
)));
1168 Set_Etype
(Directly_Designated_Type
(Anon
),
1169 Non_Limited_View
(Etype
(Actual_DDT
)));
1171 Class_Wide_Type
(Directly_Designated_Type
(Anon
)),
1172 Non_Limited_View
(Etype
(Actual_DDT
)));
1173 Set_Etype
(Actual_Dup
, Anon
);
1177 Conversion
:= Convert_To
(Formal_Typ
, Actual_Dup
);
1178 Rewrite
(Actual
, Conversion
);
1179 Analyze_And_Resolve
(Actual
, Formal_Typ
);
1183 Next_Actual
(Actual
);
1184 Next_Formal
(Formal
);
1186 end Expand_Interface_Actuals
;
1188 ----------------------------
1189 -- Expand_Interface_Thunk --
1190 ----------------------------
1192 procedure Expand_Interface_Thunk
1194 Thunk_Id
: out Entity_Id
;
1195 Thunk_Code
: out Node_Id
)
1197 Loc
: constant Source_Ptr
:= Sloc
(Prim
);
1198 Actuals
: constant List_Id
:= New_List
;
1199 Decl
: constant List_Id
:= New_List
;
1200 Formals
: constant List_Id
:= New_List
;
1202 Controlling_Typ
: Entity_Id
;
1207 Target_Formal
: Entity_Id
;
1211 Thunk_Code
:= Empty
;
1213 -- Give message if configurable run-time and Offset_To_Top unavailable
1215 if not RTE_Available
(RE_Offset_To_Top
) then
1216 Error_Msg_CRT
("abstract interface types", Prim
);
1220 -- Traverse the list of alias to find the final target
1223 while Present
(Alias
(Target
)) loop
1224 Target
:= Alias
(Target
);
1227 -- In case of primitives that are functions without formals and
1228 -- a controlling result there is no need to build the thunk.
1230 if not Present
(First_Formal
(Target
)) then
1231 pragma Assert
(Ekind
(Target
) = E_Function
1232 and then Has_Controlling_Result
(Target
));
1236 -- Duplicate the formals
1238 Formal
:= First_Formal
(Target
);
1239 while Present
(Formal
) loop
1241 Make_Parameter_Specification
(Loc
,
1242 Defining_Identifier
=>
1243 Make_Defining_Identifier
(Sloc
(Formal
),
1244 Chars
=> Chars
(Formal
)),
1245 In_Present
=> In_Present
(Parent
(Formal
)),
1246 Out_Present
=> Out_Present
(Parent
(Formal
)),
1248 New_Reference_To
(Etype
(Formal
), Loc
),
1249 Expression
=> New_Copy_Tree
(Expression
(Parent
(Formal
)))));
1251 Next_Formal
(Formal
);
1254 Controlling_Typ
:= Find_Dispatching_Type
(Target
);
1256 Target_Formal
:= First_Formal
(Target
);
1257 Formal
:= First
(Formals
);
1258 while Present
(Formal
) loop
1259 if Ekind
(Target_Formal
) = E_In_Parameter
1260 and then Ekind
(Etype
(Target_Formal
)) = E_Anonymous_Access_Type
1261 and then Directly_Designated_Type
(Etype
(Target_Formal
))
1266 -- type T is access all <<type of the target formal>>
1267 -- S : Storage_Offset := Storage_Offset!(Formal)
1268 -- - Offset_To_Top (address!(Formal))
1271 Make_Full_Type_Declaration
(Loc
,
1272 Defining_Identifier
=>
1273 Make_Defining_Identifier
(Loc
,
1274 New_Internal_Name
('T')),
1276 Make_Access_To_Object_Definition
(Loc
,
1277 All_Present
=> True,
1278 Null_Exclusion_Present
=> False,
1279 Constant_Present
=> False,
1280 Subtype_Indication
=>
1282 (Directly_Designated_Type
1283 (Etype
(Target_Formal
)), Loc
)));
1286 Make_Object_Declaration
(Loc
,
1287 Defining_Identifier
=>
1288 Make_Defining_Identifier
(Loc
,
1289 New_Internal_Name
('S')),
1290 Constant_Present
=> True,
1291 Object_Definition
=>
1292 New_Reference_To
(RTE
(RE_Storage_Offset
), Loc
),
1294 Make_Op_Subtract
(Loc
,
1296 Unchecked_Convert_To
1297 (RTE
(RE_Storage_Offset
),
1298 New_Reference_To
(Defining_Identifier
(Formal
), Loc
)),
1300 Make_Function_Call
(Loc
,
1302 New_Reference_To
(RTE
(RE_Offset_To_Top
), Loc
),
1303 Parameter_Associations
=> New_List
(
1304 Unchecked_Convert_To
1307 (Defining_Identifier
(Formal
), Loc
))))));
1309 Append_To
(Decl
, Decl_2
);
1310 Append_To
(Decl
, Decl_1
);
1312 -- Reference the new actual. Generate:
1316 Unchecked_Convert_To
1317 (Defining_Identifier
(Decl_2
),
1318 New_Reference_To
(Defining_Identifier
(Decl_1
), Loc
)));
1320 elsif Etype
(Target_Formal
) = Controlling_Typ
then
1323 -- S1 : Storage_Offset := Storage_Offset!(Formal'Address)
1324 -- - Offset_To_Top (Formal'Address)
1325 -- S2 : Addr_Ptr := Addr_Ptr!(S1)
1328 Make_Object_Declaration
(Loc
,
1329 Defining_Identifier
=>
1330 Make_Defining_Identifier
(Loc
, New_Internal_Name
('S')),
1331 Constant_Present
=> True,
1332 Object_Definition
=>
1333 New_Reference_To
(RTE
(RE_Storage_Offset
), Loc
),
1335 Make_Op_Subtract
(Loc
,
1337 Unchecked_Convert_To
1338 (RTE
(RE_Storage_Offset
),
1339 Make_Attribute_Reference
(Loc
,
1342 (Defining_Identifier
(Formal
), Loc
),
1343 Attribute_Name
=> Name_Address
)),
1345 Make_Function_Call
(Loc
,
1347 New_Reference_To
(RTE
(RE_Offset_To_Top
), Loc
),
1348 Parameter_Associations
=> New_List
(
1349 Make_Attribute_Reference
(Loc
,
1352 (Defining_Identifier
(Formal
), Loc
),
1353 Attribute_Name
=> Name_Address
)))));
1356 Make_Object_Declaration
(Loc
,
1357 Defining_Identifier
=>
1358 Make_Defining_Identifier
(Loc
, New_Internal_Name
('S')),
1359 Constant_Present
=> True,
1360 Object_Definition
=> New_Reference_To
(RTE
(RE_Addr_Ptr
), Loc
),
1362 Unchecked_Convert_To
1364 New_Reference_To
(Defining_Identifier
(Decl_1
), Loc
)));
1366 Append_To
(Decl
, Decl_1
);
1367 Append_To
(Decl
, Decl_2
);
1369 -- Reference the new actual. Generate:
1370 -- Target_Formal (S2.all)
1373 Unchecked_Convert_To
1374 (Etype
(Target_Formal
),
1375 Make_Explicit_Dereference
(Loc
,
1376 New_Reference_To
(Defining_Identifier
(Decl_2
), Loc
))));
1378 -- No special management required for this actual
1382 New_Reference_To
(Defining_Identifier
(Formal
), Loc
));
1385 Next_Formal
(Target_Formal
);
1390 Make_Defining_Identifier
(Loc
,
1391 Chars
=> New_Internal_Name
('T'));
1393 Set_Is_Thunk
(Thunk_Id
);
1395 if Ekind
(Target
) = E_Procedure
then
1397 Make_Subprogram_Body
(Loc
,
1399 Make_Procedure_Specification
(Loc
,
1400 Defining_Unit_Name
=> Thunk_Id
,
1401 Parameter_Specifications
=> Formals
),
1402 Declarations
=> Decl
,
1403 Handled_Statement_Sequence
=>
1404 Make_Handled_Sequence_Of_Statements
(Loc
,
1405 Statements
=> New_List
(
1406 Make_Procedure_Call_Statement
(Loc
,
1407 Name
=> New_Occurrence_Of
(Target
, Loc
),
1408 Parameter_Associations
=> Actuals
))));
1410 else pragma Assert
(Ekind
(Target
) = E_Function
);
1413 Make_Subprogram_Body
(Loc
,
1415 Make_Function_Specification
(Loc
,
1416 Defining_Unit_Name
=> Thunk_Id
,
1417 Parameter_Specifications
=> Formals
,
1418 Result_Definition
=>
1419 New_Copy
(Result_Definition
(Parent
(Target
)))),
1420 Declarations
=> Decl
,
1421 Handled_Statement_Sequence
=>
1422 Make_Handled_Sequence_Of_Statements
(Loc
,
1423 Statements
=> New_List
(
1424 Make_Simple_Return_Statement
(Loc
,
1425 Make_Function_Call
(Loc
,
1426 Name
=> New_Occurrence_Of
(Target
, Loc
),
1427 Parameter_Associations
=> Actuals
)))));
1429 end Expand_Interface_Thunk
;
1435 function Has_DT
(Typ
: Entity_Id
) return Boolean is
1437 return not Is_Interface
(Typ
)
1438 and then not Restriction_Active
(No_Dispatching_Calls
);
1441 -------------------------------------
1442 -- Is_Predefined_Dispatching_Alias --
1443 -------------------------------------
1445 function Is_Predefined_Dispatching_Alias
(Prim
: Entity_Id
) return Boolean
1450 if not Is_Predefined_Dispatching_Operation
(Prim
)
1451 and then Present
(Alias
(Prim
))
1454 while Present
(Alias
(E
)) loop
1458 if Is_Predefined_Dispatching_Operation
(E
) then
1464 end Is_Predefined_Dispatching_Alias
;
1466 ----------------------------------------
1467 -- Make_Disp_Asynchronous_Select_Body --
1468 ----------------------------------------
1470 -- For interface types, generate:
1472 -- procedure _Disp_Asynchronous_Select
1473 -- (T : in out <Typ>;
1475 -- P : System.Address;
1476 -- B : out System.Storage_Elements.Dummy_Communication_Block;
1481 -- end _Disp_Asynchronous_Select;
1483 -- For protected types, generate:
1485 -- procedure _Disp_Asynchronous_Select
1486 -- (T : in out <Typ>;
1488 -- P : System.Address;
1489 -- B : out System.Storage_Elements.Dummy_Communication_Block;
1493 -- Ada.Tags.Get_Entry_Index (Ada.Tags.Tag (<Typ>VP, S));
1494 -- Bnn : System.Tasking.Protected_Objects.Operations.
1495 -- Communication_Block;
1497 -- System.Tasking.Protected_Objects.Operations.Protected_Entry_Call
1498 -- (T._object'Access,
1499 -- System.Tasking.Protected_Objects.Protected_Entry_Index (I),
1501 -- System.Tasking.Asynchronous_Call,
1503 -- B := System.Storage_Elements.Dummy_Communication_Block (Bnn);
1504 -- end _Disp_Asynchronous_Select;
1506 -- For task types, generate:
1508 -- procedure _Disp_Asynchronous_Select
1509 -- (T : in out <Typ>;
1511 -- P : System.Address;
1512 -- B : out System.Storage_Elements.Dummy_Communication_Block;
1516 -- Ada.Tags.Get_Entry_Index (Ada.Tags.Tag (<Typ>VP, S));
1518 -- System.Tasking.Rendezvous.Task_Entry_Call
1520 -- System.Tasking.Task_Entry_Index (I),
1522 -- System.Tasking.Asynchronous_Call,
1524 -- end _Disp_Asynchronous_Select;
1526 function Make_Disp_Asynchronous_Select_Body
1527 (Typ
: Entity_Id
) return Node_Id
1529 Com_Block
: Entity_Id
;
1530 Conc_Typ
: Entity_Id
:= Empty
;
1531 Decls
: constant List_Id
:= New_List
;
1533 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
1534 Stmts
: constant List_Id
:= New_List
;
1537 pragma Assert
(not Restriction_Active
(No_Dispatching_Calls
));
1539 -- Null body is generated for interface types
1541 if Is_Interface
(Typ
) then
1543 Make_Subprogram_Body
(Loc
,
1545 Make_Disp_Asynchronous_Select_Spec
(Typ
),
1548 Handled_Statement_Sequence
=>
1549 Make_Handled_Sequence_Of_Statements
(Loc
,
1550 New_List
(Make_Null_Statement
(Loc
))));
1553 DT_Ptr
:= Node
(First_Elmt
(Access_Disp_Table
(Typ
)));
1555 if Is_Concurrent_Record_Type
(Typ
) then
1556 Conc_Typ
:= Corresponding_Concurrent_Type
(Typ
);
1560 -- Ada.Tags.Get_Entry_Index (Ada.Tags.Tag! (<type>VP), S);
1562 -- where I will be used to capture the entry index of the primitive
1563 -- wrapper at position S.
1566 Make_Object_Declaration
(Loc
,
1567 Defining_Identifier
=>
1568 Make_Defining_Identifier
(Loc
, Name_uI
),
1569 Object_Definition
=>
1570 New_Reference_To
(Standard_Integer
, Loc
),
1572 Make_Function_Call
(Loc
,
1574 New_Reference_To
(RTE
(RE_Get_Entry_Index
), Loc
),
1575 Parameter_Associations
=>
1577 Unchecked_Convert_To
(RTE
(RE_Tag
),
1578 New_Reference_To
(DT_Ptr
, Loc
)),
1579 Make_Identifier
(Loc
, Name_uS
)))));
1581 if Ekind
(Conc_Typ
) = E_Protected_Type
then
1584 -- Bnn : Communication_Block;
1587 Make_Defining_Identifier
(Loc
, New_Internal_Name
('B'));
1590 Make_Object_Declaration
(Loc
,
1591 Defining_Identifier
=>
1593 Object_Definition
=>
1594 New_Reference_To
(RTE
(RE_Communication_Block
), Loc
)));
1597 -- Protected_Entry_Call
1598 -- (T._object'Access, -- Object
1599 -- Protected_Entry_Index! (I), -- E
1600 -- P, -- Uninterpreted_Data
1601 -- Asynchronous_Call, -- Mode
1602 -- Bnn); -- Communication_Block
1604 -- where T is the protected object, I is the entry index, P are
1605 -- the wrapped parameters and B is the name of the communication
1609 Make_Procedure_Call_Statement
(Loc
,
1611 New_Reference_To
(RTE
(RE_Protected_Entry_Call
), Loc
),
1612 Parameter_Associations
=>
1615 Make_Attribute_Reference
(Loc
, -- T._object'Access
1617 Name_Unchecked_Access
,
1619 Make_Selected_Component
(Loc
,
1621 Make_Identifier
(Loc
, Name_uT
),
1623 Make_Identifier
(Loc
, Name_uObject
))),
1625 Make_Unchecked_Type_Conversion
(Loc
, -- entry index
1627 New_Reference_To
(RTE
(RE_Protected_Entry_Index
), Loc
),
1629 Make_Identifier
(Loc
, Name_uI
)),
1631 Make_Identifier
(Loc
, Name_uP
), -- parameter block
1632 New_Reference_To
( -- Asynchronous_Call
1633 RTE
(RE_Asynchronous_Call
), Loc
),
1635 New_Reference_To
(Com_Block
, Loc
)))); -- comm block
1638 -- B := Dummy_Communication_Block (Bnn);
1641 Make_Assignment_Statement
(Loc
,
1643 Make_Identifier
(Loc
, Name_uB
),
1645 Make_Unchecked_Type_Conversion
(Loc
,
1648 RTE
(RE_Dummy_Communication_Block
), Loc
),
1650 New_Reference_To
(Com_Block
, Loc
))));
1653 pragma Assert
(Ekind
(Conc_Typ
) = E_Task_Type
);
1657 -- (T._task_id, -- Acceptor
1658 -- Task_Entry_Index! (I), -- E
1659 -- P, -- Uninterpreted_Data
1660 -- Asynchronous_Call, -- Mode
1661 -- F); -- Rendezvous_Successful
1663 -- where T is the task object, I is the entry index, P are the
1664 -- wrapped parameters and F is the status flag.
1667 Make_Procedure_Call_Statement
(Loc
,
1669 New_Reference_To
(RTE
(RE_Task_Entry_Call
), Loc
),
1670 Parameter_Associations
=>
1673 Make_Selected_Component
(Loc
, -- T._task_id
1675 Make_Identifier
(Loc
, Name_uT
),
1677 Make_Identifier
(Loc
, Name_uTask_Id
)),
1679 Make_Unchecked_Type_Conversion
(Loc
, -- entry index
1681 New_Reference_To
(RTE
(RE_Task_Entry_Index
), Loc
),
1683 Make_Identifier
(Loc
, Name_uI
)),
1685 Make_Identifier
(Loc
, Name_uP
), -- parameter block
1686 New_Reference_To
( -- Asynchronous_Call
1687 RTE
(RE_Asynchronous_Call
), Loc
),
1688 Make_Identifier
(Loc
, Name_uF
)))); -- status flag
1693 Make_Subprogram_Body
(Loc
,
1695 Make_Disp_Asynchronous_Select_Spec
(Typ
),
1698 Handled_Statement_Sequence
=>
1699 Make_Handled_Sequence_Of_Statements
(Loc
, Stmts
));
1700 end Make_Disp_Asynchronous_Select_Body
;
1702 ----------------------------------------
1703 -- Make_Disp_Asynchronous_Select_Spec --
1704 ----------------------------------------
1706 function Make_Disp_Asynchronous_Select_Spec
1707 (Typ
: Entity_Id
) return Node_Id
1709 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
1710 Def_Id
: constant Node_Id
:=
1711 Make_Defining_Identifier
(Loc
,
1712 Name_uDisp_Asynchronous_Select
);
1713 Params
: constant List_Id
:= New_List
;
1716 pragma Assert
(not Restriction_Active
(No_Dispatching_Calls
));
1718 -- T : in out Typ; -- Object parameter
1719 -- S : Integer; -- Primitive operation slot
1720 -- P : Address; -- Wrapped parameters
1721 -- B : out Dummy_Communication_Block; -- Communication block dummy
1722 -- F : out Boolean; -- Status flag
1724 Append_List_To
(Params
, New_List
(
1726 Make_Parameter_Specification
(Loc
,
1727 Defining_Identifier
=>
1728 Make_Defining_Identifier
(Loc
, Name_uT
),
1730 New_Reference_To
(Typ
, Loc
),
1732 Out_Present
=> True),
1734 Make_Parameter_Specification
(Loc
,
1735 Defining_Identifier
=>
1736 Make_Defining_Identifier
(Loc
, Name_uS
),
1738 New_Reference_To
(Standard_Integer
, Loc
)),
1740 Make_Parameter_Specification
(Loc
,
1741 Defining_Identifier
=>
1742 Make_Defining_Identifier
(Loc
, Name_uP
),
1744 New_Reference_To
(RTE
(RE_Address
), Loc
)),
1746 Make_Parameter_Specification
(Loc
,
1747 Defining_Identifier
=>
1748 Make_Defining_Identifier
(Loc
, Name_uB
),
1750 New_Reference_To
(RTE
(RE_Dummy_Communication_Block
), Loc
),
1751 Out_Present
=> True),
1753 Make_Parameter_Specification
(Loc
,
1754 Defining_Identifier
=>
1755 Make_Defining_Identifier
(Loc
, Name_uF
),
1757 New_Reference_To
(Standard_Boolean
, Loc
),
1758 Out_Present
=> True)));
1761 Make_Procedure_Specification
(Loc
,
1762 Defining_Unit_Name
=> Def_Id
,
1763 Parameter_Specifications
=> Params
);
1764 end Make_Disp_Asynchronous_Select_Spec
;
1766 ---------------------------------------
1767 -- Make_Disp_Conditional_Select_Body --
1768 ---------------------------------------
1770 -- For interface types, generate:
1772 -- procedure _Disp_Conditional_Select
1773 -- (T : in out <Typ>;
1775 -- P : System.Address;
1776 -- C : out Ada.Tags.Prim_Op_Kind;
1781 -- end _Disp_Conditional_Select;
1783 -- For protected types, generate:
1785 -- procedure _Disp_Conditional_Select
1786 -- (T : in out <Typ>;
1788 -- P : System.Address;
1789 -- C : out Ada.Tags.Prim_Op_Kind;
1793 -- Bnn : System.Tasking.Protected_Objects.Operations.
1794 -- Communication_Block;
1797 -- C := Ada.Tags.Get_Prim_Op_Kind (Ada.Tags.Tag (<Typ>VP, S));
1799 -- if C = Ada.Tags.POK_Procedure
1800 -- or else C = Ada.Tags.POK_Protected_Procedure
1801 -- or else C = Ada.Tags.POK_Task_Procedure
1807 -- I := Ada.Tags.Get_Entry_Index (Ada.Tags.Tag (<Typ>VP, S));
1808 -- System.Tasking.Protected_Objects.Operations.Protected_Entry_Call
1809 -- (T.object'Access,
1810 -- System.Tasking.Protected_Objects.Protected_Entry_Index (I),
1812 -- System.Tasking.Conditional_Call,
1814 -- F := not Cancelled (Bnn);
1815 -- end _Disp_Conditional_Select;
1817 -- For task types, generate:
1819 -- procedure _Disp_Conditional_Select
1820 -- (T : in out <Typ>;
1822 -- P : System.Address;
1823 -- C : out Ada.Tags.Prim_Op_Kind;
1829 -- I := Ada.Tags.Get_Entry_Index (Ada.Tags.Tag (<Typ>VP, S));
1830 -- System.Tasking.Rendezvous.Task_Entry_Call
1832 -- System.Tasking.Task_Entry_Index (I),
1834 -- System.Tasking.Conditional_Call,
1836 -- end _Disp_Conditional_Select;
1838 function Make_Disp_Conditional_Select_Body
1839 (Typ
: Entity_Id
) return Node_Id
1841 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
1842 Blk_Nam
: Entity_Id
;
1843 Conc_Typ
: Entity_Id
:= Empty
;
1844 Decls
: constant List_Id
:= New_List
;
1846 Stmts
: constant List_Id
:= New_List
;
1849 pragma Assert
(not Restriction_Active
(No_Dispatching_Calls
));
1851 -- Null body is generated for interface types
1853 if Is_Interface
(Typ
) then
1855 Make_Subprogram_Body
(Loc
,
1857 Make_Disp_Conditional_Select_Spec
(Typ
),
1860 Handled_Statement_Sequence
=>
1861 Make_Handled_Sequence_Of_Statements
(Loc
,
1862 New_List
(Make_Null_Statement
(Loc
))));
1865 DT_Ptr
:= Node
(First_Elmt
(Access_Disp_Table
(Typ
)));
1867 if Is_Concurrent_Record_Type
(Typ
) then
1868 Conc_Typ
:= Corresponding_Concurrent_Type
(Typ
);
1873 -- where I will be used to capture the entry index of the primitive
1874 -- wrapper at position S.
1877 Make_Object_Declaration
(Loc
,
1878 Defining_Identifier
=>
1879 Make_Defining_Identifier
(Loc
, Name_uI
),
1880 Object_Definition
=>
1881 New_Reference_To
(Standard_Integer
, Loc
)));
1884 -- C := Ada.Tags.Get_Prim_Op_Kind (Ada.Tags.Tag! (<type>VP), S);
1886 -- if C = POK_Procedure
1887 -- or else C = POK_Protected_Procedure
1888 -- or else C = POK_Task_Procedure;
1894 Build_Common_Dispatching_Select_Statements
(Loc
, DT_Ptr
, Stmts
);
1897 -- Bnn : Communication_Block;
1899 -- where Bnn is the name of the communication block used in the
1900 -- call to Protected_Entry_Call.
1902 Blk_Nam
:= Make_Defining_Identifier
(Loc
, New_Internal_Name
('B'));
1905 Make_Object_Declaration
(Loc
,
1906 Defining_Identifier
=>
1908 Object_Definition
=>
1909 New_Reference_To
(RTE
(RE_Communication_Block
), Loc
)));
1912 -- I := Ada.Tags.Get_Entry_Index (Ada.Tags.Tag! (<type>VP), S);
1914 -- I is the entry index and S is the dispatch table slot
1917 Make_Assignment_Statement
(Loc
,
1919 Make_Identifier
(Loc
, Name_uI
),
1921 Make_Function_Call
(Loc
,
1923 New_Reference_To
(RTE
(RE_Get_Entry_Index
), Loc
),
1924 Parameter_Associations
=>
1926 Unchecked_Convert_To
(RTE
(RE_Tag
),
1927 New_Reference_To
(DT_Ptr
, Loc
)),
1928 Make_Identifier
(Loc
, Name_uS
)))));
1930 if Ekind
(Conc_Typ
) = E_Protected_Type
then
1933 -- Protected_Entry_Call
1934 -- (T._object'Access, -- Object
1935 -- Protected_Entry_Index! (I), -- E
1936 -- P, -- Uninterpreted_Data
1937 -- Conditional_Call, -- Mode
1940 -- where T is the protected object, I is the entry index, P are
1941 -- the wrapped parameters and Bnn is the name of the communication
1945 Make_Procedure_Call_Statement
(Loc
,
1947 New_Reference_To
(RTE
(RE_Protected_Entry_Call
), Loc
),
1948 Parameter_Associations
=>
1951 Make_Attribute_Reference
(Loc
, -- T._object'Access
1953 Name_Unchecked_Access
,
1955 Make_Selected_Component
(Loc
,
1957 Make_Identifier
(Loc
, Name_uT
),
1959 Make_Identifier
(Loc
, Name_uObject
))),
1961 Make_Unchecked_Type_Conversion
(Loc
, -- entry index
1963 New_Reference_To
(RTE
(RE_Protected_Entry_Index
), Loc
),
1965 Make_Identifier
(Loc
, Name_uI
)),
1967 Make_Identifier
(Loc
, Name_uP
), -- parameter block
1968 New_Reference_To
( -- Conditional_Call
1969 RTE
(RE_Conditional_Call
), Loc
),
1970 New_Reference_To
( -- Bnn
1974 -- F := not Cancelled (Bnn);
1976 -- where F is the success flag. The status of Cancelled is negated
1977 -- in order to match the behaviour of the version for task types.
1980 Make_Assignment_Statement
(Loc
,
1982 Make_Identifier
(Loc
, Name_uF
),
1986 Make_Function_Call
(Loc
,
1988 New_Reference_To
(RTE
(RE_Cancelled
), Loc
),
1989 Parameter_Associations
=>
1991 New_Reference_To
(Blk_Nam
, Loc
))))));
1993 pragma Assert
(Ekind
(Conc_Typ
) = E_Task_Type
);
1997 -- (T._task_id, -- Acceptor
1998 -- Task_Entry_Index! (I), -- E
1999 -- P, -- Uninterpreted_Data
2000 -- Conditional_Call, -- Mode
2001 -- F); -- Rendezvous_Successful
2003 -- where T is the task object, I is the entry index, P are the
2004 -- wrapped parameters and F is the status flag.
2007 Make_Procedure_Call_Statement
(Loc
,
2009 New_Reference_To
(RTE
(RE_Task_Entry_Call
), Loc
),
2010 Parameter_Associations
=>
2013 Make_Selected_Component
(Loc
, -- T._task_id
2015 Make_Identifier
(Loc
, Name_uT
),
2017 Make_Identifier
(Loc
, Name_uTask_Id
)),
2019 Make_Unchecked_Type_Conversion
(Loc
, -- entry index
2021 New_Reference_To
(RTE
(RE_Task_Entry_Index
), Loc
),
2023 Make_Identifier
(Loc
, Name_uI
)),
2025 Make_Identifier
(Loc
, Name_uP
), -- parameter block
2026 New_Reference_To
( -- Conditional_Call
2027 RTE
(RE_Conditional_Call
), Loc
),
2028 Make_Identifier
(Loc
, Name_uF
)))); -- status flag
2033 Make_Subprogram_Body
(Loc
,
2035 Make_Disp_Conditional_Select_Spec
(Typ
),
2038 Handled_Statement_Sequence
=>
2039 Make_Handled_Sequence_Of_Statements
(Loc
, Stmts
));
2040 end Make_Disp_Conditional_Select_Body
;
2042 ---------------------------------------
2043 -- Make_Disp_Conditional_Select_Spec --
2044 ---------------------------------------
2046 function Make_Disp_Conditional_Select_Spec
2047 (Typ
: Entity_Id
) return Node_Id
2049 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
2050 Def_Id
: constant Node_Id
:=
2051 Make_Defining_Identifier
(Loc
,
2052 Name_uDisp_Conditional_Select
);
2053 Params
: constant List_Id
:= New_List
;
2056 pragma Assert
(not Restriction_Active
(No_Dispatching_Calls
));
2058 -- T : in out Typ; -- Object parameter
2059 -- S : Integer; -- Primitive operation slot
2060 -- P : Address; -- Wrapped parameters
2061 -- C : out Prim_Op_Kind; -- Call kind
2062 -- F : out Boolean; -- Status flag
2064 Append_List_To
(Params
, New_List
(
2066 Make_Parameter_Specification
(Loc
,
2067 Defining_Identifier
=>
2068 Make_Defining_Identifier
(Loc
, Name_uT
),
2070 New_Reference_To
(Typ
, Loc
),
2072 Out_Present
=> True),
2074 Make_Parameter_Specification
(Loc
,
2075 Defining_Identifier
=>
2076 Make_Defining_Identifier
(Loc
, Name_uS
),
2078 New_Reference_To
(Standard_Integer
, Loc
)),
2080 Make_Parameter_Specification
(Loc
,
2081 Defining_Identifier
=>
2082 Make_Defining_Identifier
(Loc
, Name_uP
),
2084 New_Reference_To
(RTE
(RE_Address
), Loc
)),
2086 Make_Parameter_Specification
(Loc
,
2087 Defining_Identifier
=>
2088 Make_Defining_Identifier
(Loc
, Name_uC
),
2090 New_Reference_To
(RTE
(RE_Prim_Op_Kind
), Loc
),
2091 Out_Present
=> True),
2093 Make_Parameter_Specification
(Loc
,
2094 Defining_Identifier
=>
2095 Make_Defining_Identifier
(Loc
, Name_uF
),
2097 New_Reference_To
(Standard_Boolean
, Loc
),
2098 Out_Present
=> True)));
2101 Make_Procedure_Specification
(Loc
,
2102 Defining_Unit_Name
=> Def_Id
,
2103 Parameter_Specifications
=> Params
);
2104 end Make_Disp_Conditional_Select_Spec
;
2106 -------------------------------------
2107 -- Make_Disp_Get_Prim_Op_Kind_Body --
2108 -------------------------------------
2110 function Make_Disp_Get_Prim_Op_Kind_Body
2111 (Typ
: Entity_Id
) return Node_Id
2113 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
2117 pragma Assert
(not Restriction_Active
(No_Dispatching_Calls
));
2119 if Is_Interface
(Typ
) then
2121 Make_Subprogram_Body
(Loc
,
2123 Make_Disp_Get_Prim_Op_Kind_Spec
(Typ
),
2126 Handled_Statement_Sequence
=>
2127 Make_Handled_Sequence_Of_Statements
(Loc
,
2128 New_List
(Make_Null_Statement
(Loc
))));
2131 DT_Ptr
:= Node
(First_Elmt
(Access_Disp_Table
(Typ
)));
2134 -- C := get_prim_op_kind (tag! (<type>VP), S);
2136 -- where C is the out parameter capturing the call kind and S is the
2137 -- dispatch table slot number.
2140 Make_Subprogram_Body
(Loc
,
2142 Make_Disp_Get_Prim_Op_Kind_Spec
(Typ
),
2145 Handled_Statement_Sequence
=>
2146 Make_Handled_Sequence_Of_Statements
(Loc
,
2148 Make_Assignment_Statement
(Loc
,
2150 Make_Identifier
(Loc
, Name_uC
),
2152 Make_Function_Call
(Loc
,
2154 New_Reference_To
(RTE
(RE_Get_Prim_Op_Kind
), Loc
),
2155 Parameter_Associations
=> New_List
(
2156 Unchecked_Convert_To
(RTE
(RE_Tag
),
2157 New_Reference_To
(DT_Ptr
, Loc
)),
2158 Make_Identifier
(Loc
, Name_uS
)))))));
2159 end Make_Disp_Get_Prim_Op_Kind_Body
;
2161 -------------------------------------
2162 -- Make_Disp_Get_Prim_Op_Kind_Spec --
2163 -------------------------------------
2165 function Make_Disp_Get_Prim_Op_Kind_Spec
2166 (Typ
: Entity_Id
) return Node_Id
2168 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
2169 Def_Id
: constant Node_Id
:=
2170 Make_Defining_Identifier
(Loc
,
2171 Name_uDisp_Get_Prim_Op_Kind
);
2172 Params
: constant List_Id
:= New_List
;
2175 pragma Assert
(not Restriction_Active
(No_Dispatching_Calls
));
2177 -- T : in out Typ; -- Object parameter
2178 -- S : Integer; -- Primitive operation slot
2179 -- C : out Prim_Op_Kind; -- Call kind
2181 Append_List_To
(Params
, New_List
(
2183 Make_Parameter_Specification
(Loc
,
2184 Defining_Identifier
=>
2185 Make_Defining_Identifier
(Loc
, Name_uT
),
2187 New_Reference_To
(Typ
, Loc
),
2189 Out_Present
=> True),
2191 Make_Parameter_Specification
(Loc
,
2192 Defining_Identifier
=>
2193 Make_Defining_Identifier
(Loc
, Name_uS
),
2195 New_Reference_To
(Standard_Integer
, Loc
)),
2197 Make_Parameter_Specification
(Loc
,
2198 Defining_Identifier
=>
2199 Make_Defining_Identifier
(Loc
, Name_uC
),
2201 New_Reference_To
(RTE
(RE_Prim_Op_Kind
), Loc
),
2202 Out_Present
=> True)));
2205 Make_Procedure_Specification
(Loc
,
2206 Defining_Unit_Name
=> Def_Id
,
2207 Parameter_Specifications
=> Params
);
2208 end Make_Disp_Get_Prim_Op_Kind_Spec
;
2210 --------------------------------
2211 -- Make_Disp_Get_Task_Id_Body --
2212 --------------------------------
2214 function Make_Disp_Get_Task_Id_Body
2215 (Typ
: Entity_Id
) return Node_Id
2217 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
2221 pragma Assert
(not Restriction_Active
(No_Dispatching_Calls
));
2223 if Is_Concurrent_Record_Type
(Typ
)
2224 and then Ekind
(Corresponding_Concurrent_Type
(Typ
)) = E_Task_Type
2227 -- return To_Address (_T._task_id);
2230 Make_Simple_Return_Statement
(Loc
,
2232 Make_Unchecked_Type_Conversion
(Loc
,
2234 New_Reference_To
(RTE
(RE_Address
), Loc
),
2236 Make_Selected_Component
(Loc
,
2238 Make_Identifier
(Loc
, Name_uT
),
2240 Make_Identifier
(Loc
, Name_uTask_Id
))));
2242 -- A null body is constructed for non-task types
2246 -- return Null_Address;
2249 Make_Simple_Return_Statement
(Loc
,
2251 New_Reference_To
(RTE
(RE_Null_Address
), Loc
));
2255 Make_Subprogram_Body
(Loc
,
2257 Make_Disp_Get_Task_Id_Spec
(Typ
),
2260 Handled_Statement_Sequence
=>
2261 Make_Handled_Sequence_Of_Statements
(Loc
,
2263 end Make_Disp_Get_Task_Id_Body
;
2265 --------------------------------
2266 -- Make_Disp_Get_Task_Id_Spec --
2267 --------------------------------
2269 function Make_Disp_Get_Task_Id_Spec
2270 (Typ
: Entity_Id
) return Node_Id
2272 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
2275 pragma Assert
(not Restriction_Active
(No_Dispatching_Calls
));
2278 Make_Function_Specification
(Loc
,
2279 Defining_Unit_Name
=>
2280 Make_Defining_Identifier
(Loc
, Name_uDisp_Get_Task_Id
),
2281 Parameter_Specifications
=> New_List
(
2282 Make_Parameter_Specification
(Loc
,
2283 Defining_Identifier
=>
2284 Make_Defining_Identifier
(Loc
, Name_uT
),
2286 New_Reference_To
(Typ
, Loc
))),
2287 Result_Definition
=>
2288 New_Reference_To
(RTE
(RE_Address
), Loc
));
2289 end Make_Disp_Get_Task_Id_Spec
;
2291 ----------------------------
2292 -- Make_Disp_Requeue_Body --
2293 ----------------------------
2295 function Make_Disp_Requeue_Body
2296 (Typ
: Entity_Id
) return Node_Id
2298 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
2299 Conc_Typ
: Entity_Id
:= Empty
;
2300 Stmts
: constant List_Id
:= New_List
;
2303 pragma Assert
(not Restriction_Active
(No_Dispatching_Calls
));
2305 -- Null body is generated for interface types and non-concurrent
2308 if Is_Interface
(Typ
)
2309 or else not Is_Concurrent_Record_Type
(Typ
)
2312 Make_Subprogram_Body
(Loc
,
2314 Make_Disp_Requeue_Spec
(Typ
),
2317 Handled_Statement_Sequence
=>
2318 Make_Handled_Sequence_Of_Statements
(Loc
,
2319 New_List
(Make_Null_Statement
(Loc
))));
2322 Conc_Typ
:= Corresponding_Concurrent_Type
(Typ
);
2324 if Ekind
(Conc_Typ
) = E_Protected_Type
then
2326 -- Generate statements:
2328 -- System.Tasking.Protected_Objects.Operations.
2329 -- Requeue_Protected_Entry
2330 -- (Protection_Entries_Access (P),
2331 -- O._object'Unchecked_Access,
2332 -- Protected_Entry_Index (I),
2335 -- System.Tasking.Protected_Objects.Operations.
2336 -- Requeue_Task_To_Protected_Entry
2337 -- (O._object'Unchecked_Access,
2338 -- Protected_Entry_Index (I),
2343 Make_If_Statement
(Loc
,
2345 Make_Identifier
(Loc
, Name_uF
),
2350 -- Call to Requeue_Protected_Entry
2352 Make_Procedure_Call_Statement
(Loc
,
2355 RTE
(RE_Requeue_Protected_Entry
), Loc
),
2356 Parameter_Associations
=>
2359 Make_Unchecked_Type_Conversion
(Loc
, -- PEA (P)
2362 RTE
(RE_Protection_Entries_Access
), Loc
),
2364 Make_Identifier
(Loc
, Name_uP
)),
2366 Make_Attribute_Reference
(Loc
, -- O._object'Acc
2368 Name_Unchecked_Access
,
2370 Make_Selected_Component
(Loc
,
2372 Make_Identifier
(Loc
, Name_uO
),
2374 Make_Identifier
(Loc
, Name_uObject
))),
2376 Make_Unchecked_Type_Conversion
(Loc
, -- entry index
2379 RTE
(RE_Protected_Entry_Index
), Loc
),
2381 Make_Identifier
(Loc
, Name_uI
)),
2383 Make_Identifier
(Loc
, Name_uA
)))), -- abort status
2388 -- Call to Requeue_Task_To_Protected_Entry
2390 Make_Procedure_Call_Statement
(Loc
,
2393 RTE
(RE_Requeue_Task_To_Protected_Entry
), Loc
),
2394 Parameter_Associations
=>
2397 Make_Attribute_Reference
(Loc
, -- O._object'Acc
2399 Name_Unchecked_Access
,
2401 Make_Selected_Component
(Loc
,
2403 Make_Identifier
(Loc
, Name_uO
),
2405 Make_Identifier
(Loc
, Name_uObject
))),
2407 Make_Unchecked_Type_Conversion
(Loc
, -- entry index
2410 RTE
(RE_Protected_Entry_Index
), Loc
),
2412 Make_Identifier
(Loc
, Name_uI
)),
2414 Make_Identifier
(Loc
, Name_uA
)))))); -- abort status
2416 pragma Assert
(Is_Task_Type
(Conc_Typ
));
2420 -- System.Tasking.Rendezvous.Requeue_Protected_To_Task_Entry
2421 -- (Protection_Entries_Access (P),
2423 -- Task_Entry_Index (I),
2426 -- System.Tasking.Rendezvous.Requeue_Task_Entry
2428 -- Task_Entry_Index (I),
2433 Make_If_Statement
(Loc
,
2435 Make_Identifier
(Loc
, Name_uF
),
2440 -- Call to Requeue_Protected_To_Task_Entry
2442 Make_Procedure_Call_Statement
(Loc
,
2445 RTE
(RE_Requeue_Protected_To_Task_Entry
), Loc
),
2447 Parameter_Associations
=>
2450 Make_Unchecked_Type_Conversion
(Loc
, -- PEA (P)
2453 RTE
(RE_Protection_Entries_Access
), Loc
),
2455 Make_Identifier
(Loc
, Name_uP
)),
2457 Make_Selected_Component
(Loc
, -- O._task_id
2459 Make_Identifier
(Loc
, Name_uO
),
2461 Make_Identifier
(Loc
, Name_uTask_Id
)),
2463 Make_Unchecked_Type_Conversion
(Loc
, -- entry index
2466 RTE
(RE_Task_Entry_Index
), Loc
),
2468 Make_Identifier
(Loc
, Name_uI
)),
2470 Make_Identifier
(Loc
, Name_uA
)))), -- abort status
2475 -- Call to Requeue_Task_Entry
2477 Make_Procedure_Call_Statement
(Loc
,
2479 New_Reference_To
(RTE
(RE_Requeue_Task_Entry
), Loc
),
2481 Parameter_Associations
=>
2484 Make_Selected_Component
(Loc
, -- O._task_id
2486 Make_Identifier
(Loc
, Name_uO
),
2488 Make_Identifier
(Loc
, Name_uTask_Id
)),
2490 Make_Unchecked_Type_Conversion
(Loc
, -- entry index
2493 RTE
(RE_Task_Entry_Index
), Loc
),
2495 Make_Identifier
(Loc
, Name_uI
)),
2497 Make_Identifier
(Loc
, Name_uA
)))))); -- abort status
2500 -- Even though no declarations are needed in both cases, we allocate
2501 -- a list for entities added by Freeze.
2504 Make_Subprogram_Body
(Loc
,
2506 Make_Disp_Requeue_Spec
(Typ
),
2509 Handled_Statement_Sequence
=>
2510 Make_Handled_Sequence_Of_Statements
(Loc
, Stmts
));
2511 end Make_Disp_Requeue_Body
;
2513 ----------------------------
2514 -- Make_Disp_Requeue_Spec --
2515 ----------------------------
2517 function Make_Disp_Requeue_Spec
2518 (Typ
: Entity_Id
) return Node_Id
2520 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
2523 pragma Assert
(not Restriction_Active
(No_Dispatching_Calls
));
2525 -- O : in out Typ; - Object parameter
2526 -- F : Boolean; - Protected (True) / task (False) flag
2527 -- P : Address; - Protection_Entries_Access value
2528 -- I : Entry_Index - Index of entry call
2529 -- A : Boolean - Abort flag
2531 -- Note that the Protection_Entries_Access value is represented as a
2532 -- System.Address in order to avoid dragging in the tasking runtime
2533 -- when compiling sources without tasking constructs.
2536 Make_Procedure_Specification
(Loc
,
2537 Defining_Unit_Name
=>
2538 Make_Defining_Identifier
(Loc
, Name_uDisp_Requeue
),
2540 Parameter_Specifications
=>
2543 Make_Parameter_Specification
(Loc
, -- O
2544 Defining_Identifier
=>
2545 Make_Defining_Identifier
(Loc
, Name_uO
),
2547 New_Reference_To
(Typ
, Loc
),
2549 Out_Present
=> True),
2551 Make_Parameter_Specification
(Loc
, -- F
2552 Defining_Identifier
=>
2553 Make_Defining_Identifier
(Loc
, Name_uF
),
2555 New_Reference_To
(Standard_Boolean
, Loc
)),
2557 Make_Parameter_Specification
(Loc
, -- P
2558 Defining_Identifier
=>
2559 Make_Defining_Identifier
(Loc
, Name_uP
),
2561 New_Reference_To
(RTE
(RE_Address
), Loc
)),
2563 Make_Parameter_Specification
(Loc
, -- I
2564 Defining_Identifier
=>
2565 Make_Defining_Identifier
(Loc
, Name_uI
),
2567 New_Reference_To
(Standard_Integer
, Loc
)),
2569 Make_Parameter_Specification
(Loc
, -- A
2570 Defining_Identifier
=>
2571 Make_Defining_Identifier
(Loc
, Name_uA
),
2573 New_Reference_To
(Standard_Boolean
, Loc
))));
2574 end Make_Disp_Requeue_Spec
;
2576 ---------------------------------
2577 -- Make_Disp_Timed_Select_Body --
2578 ---------------------------------
2580 -- For interface types, generate:
2582 -- procedure _Disp_Timed_Select
2583 -- (T : in out <Typ>;
2585 -- P : System.Address;
2588 -- C : out Ada.Tags.Prim_Op_Kind;
2593 -- end _Disp_Timed_Select;
2595 -- For protected types, generate:
2597 -- procedure _Disp_Timed_Select
2598 -- (T : in out <Typ>;
2600 -- P : System.Address;
2603 -- C : out Ada.Tags.Prim_Op_Kind;
2609 -- C := Ada.Tags.Get_Prim_Op_Kind (Ada.Tags.Tag (<Typ>VP), S);
2611 -- if C = Ada.Tags.POK_Procedure
2612 -- or else C = Ada.Tags.POK_Protected_Procedure
2613 -- or else C = Ada.Tags.POK_Task_Procedure
2619 -- I := Ada.Tags.Get_Entry_Index (Ada.Tags.Tag (<Typ>VP), S);
2620 -- System.Tasking.Protected_Objects.Operations.
2621 -- Timed_Protected_Entry_Call
2622 -- (T._object'Access,
2623 -- System.Tasking.Protected_Objects.Protected_Entry_Index (I),
2628 -- end _Disp_Timed_Select;
2630 -- For task types, generate:
2632 -- procedure _Disp_Timed_Select
2633 -- (T : in out <Typ>;
2635 -- P : System.Address;
2638 -- C : out Ada.Tags.Prim_Op_Kind;
2644 -- I := Ada.Tags.Get_Entry_Index (Ada.Tags.Tag (<Typ>VP), S);
2645 -- System.Tasking.Rendezvous.Timed_Task_Entry_Call
2647 -- System.Tasking.Task_Entry_Index (I),
2652 -- end _Disp_Time_Select;
2654 function Make_Disp_Timed_Select_Body
2655 (Typ
: Entity_Id
) return Node_Id
2657 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
2658 Conc_Typ
: Entity_Id
:= Empty
;
2659 Decls
: constant List_Id
:= New_List
;
2661 Stmts
: constant List_Id
:= New_List
;
2664 pragma Assert
(not Restriction_Active
(No_Dispatching_Calls
));
2666 -- Null body is generated for interface types
2668 if Is_Interface
(Typ
) then
2670 Make_Subprogram_Body
(Loc
,
2672 Make_Disp_Timed_Select_Spec
(Typ
),
2675 Handled_Statement_Sequence
=>
2676 Make_Handled_Sequence_Of_Statements
(Loc
,
2677 New_List
(Make_Null_Statement
(Loc
))));
2680 DT_Ptr
:= Node
(First_Elmt
(Access_Disp_Table
(Typ
)));
2682 if Is_Concurrent_Record_Type
(Typ
) then
2683 Conc_Typ
:= Corresponding_Concurrent_Type
(Typ
);
2688 -- where I will be used to capture the entry index of the primitive
2689 -- wrapper at position S.
2692 Make_Object_Declaration
(Loc
,
2693 Defining_Identifier
=>
2694 Make_Defining_Identifier
(Loc
, Name_uI
),
2695 Object_Definition
=>
2696 New_Reference_To
(Standard_Integer
, Loc
)));
2699 -- C := Get_Prim_Op_Kind (tag! (<type>VP), S);
2701 -- if C = POK_Procedure
2702 -- or else C = POK_Protected_Procedure
2703 -- or else C = POK_Task_Procedure;
2709 Build_Common_Dispatching_Select_Statements
(Loc
, DT_Ptr
, Stmts
);
2712 -- I := Get_Entry_Index (tag! (<type>VP), S);
2714 -- I is the entry index and S is the dispatch table slot
2717 Make_Assignment_Statement
(Loc
,
2719 Make_Identifier
(Loc
, Name_uI
),
2721 Make_Function_Call
(Loc
,
2723 New_Reference_To
(RTE
(RE_Get_Entry_Index
), Loc
),
2724 Parameter_Associations
=>
2726 Unchecked_Convert_To
(RTE
(RE_Tag
),
2727 New_Reference_To
(DT_Ptr
, Loc
)),
2728 Make_Identifier
(Loc
, Name_uS
)))));
2730 if Ekind
(Conc_Typ
) = E_Protected_Type
then
2733 -- Timed_Protected_Entry_Call (
2734 -- T._object'access,
2735 -- Protected_Entry_Index! (I),
2741 -- where T is the protected object, I is the entry index, P are
2742 -- the wrapped parameters, D is the delay amount, M is the delay
2743 -- mode and F is the status flag.
2746 Make_Procedure_Call_Statement
(Loc
,
2748 New_Reference_To
(RTE
(RE_Timed_Protected_Entry_Call
), Loc
),
2749 Parameter_Associations
=>
2752 Make_Attribute_Reference
(Loc
, -- T._object'access
2754 Name_Unchecked_Access
,
2756 Make_Selected_Component
(Loc
,
2758 Make_Identifier
(Loc
, Name_uT
),
2760 Make_Identifier
(Loc
, Name_uObject
))),
2762 Make_Unchecked_Type_Conversion
(Loc
, -- entry index
2764 New_Reference_To
(RTE
(RE_Protected_Entry_Index
), Loc
),
2766 Make_Identifier
(Loc
, Name_uI
)),
2768 Make_Identifier
(Loc
, Name_uP
), -- parameter block
2769 Make_Identifier
(Loc
, Name_uD
), -- delay
2770 Make_Identifier
(Loc
, Name_uM
), -- delay mode
2771 Make_Identifier
(Loc
, Name_uF
)))); -- status flag
2774 pragma Assert
(Ekind
(Conc_Typ
) = E_Task_Type
);
2777 -- Timed_Task_Entry_Call (
2779 -- Task_Entry_Index! (I),
2785 -- where T is the task object, I is the entry index, P are the
2786 -- wrapped parameters, D is the delay amount, M is the delay
2787 -- mode and F is the status flag.
2790 Make_Procedure_Call_Statement
(Loc
,
2792 New_Reference_To
(RTE
(RE_Timed_Task_Entry_Call
), Loc
),
2793 Parameter_Associations
=>
2796 Make_Selected_Component
(Loc
, -- T._task_id
2798 Make_Identifier
(Loc
, Name_uT
),
2800 Make_Identifier
(Loc
, Name_uTask_Id
)),
2802 Make_Unchecked_Type_Conversion
(Loc
, -- entry index
2804 New_Reference_To
(RTE
(RE_Task_Entry_Index
), Loc
),
2806 Make_Identifier
(Loc
, Name_uI
)),
2808 Make_Identifier
(Loc
, Name_uP
), -- parameter block
2809 Make_Identifier
(Loc
, Name_uD
), -- delay
2810 Make_Identifier
(Loc
, Name_uM
), -- delay mode
2811 Make_Identifier
(Loc
, Name_uF
)))); -- status flag
2816 Make_Subprogram_Body
(Loc
,
2818 Make_Disp_Timed_Select_Spec
(Typ
),
2821 Handled_Statement_Sequence
=>
2822 Make_Handled_Sequence_Of_Statements
(Loc
, Stmts
));
2823 end Make_Disp_Timed_Select_Body
;
2825 ---------------------------------
2826 -- Make_Disp_Timed_Select_Spec --
2827 ---------------------------------
2829 function Make_Disp_Timed_Select_Spec
2830 (Typ
: Entity_Id
) return Node_Id
2832 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
2833 Def_Id
: constant Node_Id
:=
2834 Make_Defining_Identifier
(Loc
,
2835 Name_uDisp_Timed_Select
);
2836 Params
: constant List_Id
:= New_List
;
2839 pragma Assert
(not Restriction_Active
(No_Dispatching_Calls
));
2841 -- T : in out Typ; -- Object parameter
2842 -- S : Integer; -- Primitive operation slot
2843 -- P : Address; -- Wrapped parameters
2844 -- D : Duration; -- Delay
2845 -- M : Integer; -- Delay Mode
2846 -- C : out Prim_Op_Kind; -- Call kind
2847 -- F : out Boolean; -- Status flag
2849 Append_List_To
(Params
, New_List
(
2851 Make_Parameter_Specification
(Loc
,
2852 Defining_Identifier
=>
2853 Make_Defining_Identifier
(Loc
, Name_uT
),
2855 New_Reference_To
(Typ
, Loc
),
2857 Out_Present
=> True),
2859 Make_Parameter_Specification
(Loc
,
2860 Defining_Identifier
=>
2861 Make_Defining_Identifier
(Loc
, Name_uS
),
2863 New_Reference_To
(Standard_Integer
, Loc
)),
2865 Make_Parameter_Specification
(Loc
,
2866 Defining_Identifier
=>
2867 Make_Defining_Identifier
(Loc
, Name_uP
),
2869 New_Reference_To
(RTE
(RE_Address
), Loc
)),
2871 Make_Parameter_Specification
(Loc
,
2872 Defining_Identifier
=>
2873 Make_Defining_Identifier
(Loc
, Name_uD
),
2875 New_Reference_To
(Standard_Duration
, Loc
)),
2877 Make_Parameter_Specification
(Loc
,
2878 Defining_Identifier
=>
2879 Make_Defining_Identifier
(Loc
, Name_uM
),
2881 New_Reference_To
(Standard_Integer
, Loc
)),
2883 Make_Parameter_Specification
(Loc
,
2884 Defining_Identifier
=>
2885 Make_Defining_Identifier
(Loc
, Name_uC
),
2887 New_Reference_To
(RTE
(RE_Prim_Op_Kind
), Loc
),
2888 Out_Present
=> True)));
2891 Make_Parameter_Specification
(Loc
,
2892 Defining_Identifier
=>
2893 Make_Defining_Identifier
(Loc
, Name_uF
),
2895 New_Reference_To
(Standard_Boolean
, Loc
),
2896 Out_Present
=> True));
2899 Make_Procedure_Specification
(Loc
,
2900 Defining_Unit_Name
=> Def_Id
,
2901 Parameter_Specifications
=> Params
);
2902 end Make_Disp_Timed_Select_Spec
;
2908 -- The frontend supports two models for expanding dispatch tables
2909 -- associated with library-level defined tagged types: statically
2910 -- and non-statically allocated dispatch tables. In the former case
2911 -- the object containing the dispatch table is constant and it is
2912 -- initialized by means of a positional aggregate. In the latter case,
2913 -- the object containing the dispatch table is a variable which is
2914 -- initialized by means of assignments.
2916 -- In case of locally defined tagged types, the object containing the
2917 -- object containing the dispatch table is always a variable (instead
2918 -- of a constant). This is currently required to give support to late
2919 -- overriding of primitives. For example:
2921 -- procedure Example is
2923 -- type T1 is tagged null record;
2924 -- procedure Prim (O : T1);
2927 -- type T2 is new Pkg.T1 with null record;
2928 -- procedure Prim (X : T2) is -- late overriding
2934 function Make_DT
(Typ
: Entity_Id
; N
: Node_Id
:= Empty
) return List_Id
is
2935 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
2937 Max_Predef_Prims
: constant Int
:=
2941 (Parent
(RTE
(RE_Max_Predef_Prims
)))));
2943 procedure Check_Premature_Freezing
(Subp
: Entity_Id
; Typ
: Entity_Id
);
2944 -- Verify that all non-tagged types in the profile of a subprogram
2945 -- are frozen at the point the subprogram is frozen. This enforces
2946 -- the rule on RM 13.14 (14) as modified by AI05-019. At the point a
2947 -- subprogram is frozen, enough must be known about it to build the
2948 -- activation record for it, which requires at least that the size of
2949 -- all parameters be known. Controlling arguments are by-reference,
2950 -- and therefore the rule only applies to non-tagged types.
2951 -- Typical violation of the rule involves an object declaration that
2952 -- freezes a tagged type, when one of its primitive operations has a
2953 -- type in its profile whose full view has not been analyzed yet.
2955 procedure Export_DT
(Typ
: Entity_Id
; DT
: Entity_Id
);
2956 -- Export the dispatch table entity DT of tagged type Typ. Required to
2957 -- generate forward references and statically allocate the table.
2959 procedure Make_Secondary_DT
2962 Num_Iface_Prims
: Nat
;
2963 Iface_DT_Ptr
: Entity_Id
;
2964 Build_Thunks
: Boolean;
2966 -- Ada 2005 (AI-251): Expand the declarations for a Secondary Dispatch
2967 -- Table of Typ associated with Iface. Each abstract interface of Typ
2968 -- has two secondary dispatch tables: one containing pointers to thunks
2969 -- and another containing pointers to the primitives covering the
2970 -- interface primitives. The former secondary table is generated when
2971 -- Build_Thunks is True, and provides common support for dispatching
2972 -- calls through interface types; the latter secondary table is
2973 -- generated when Build_Thunks is False, and provides support for
2974 -- Generic Dispatching Constructors that dispatch calls through
2977 ------------------------------
2978 -- Check_Premature_Freezing --
2979 ------------------------------
2981 procedure Check_Premature_Freezing
(Subp
: Entity_Id
; Typ
: Entity_Id
) is
2984 and then Is_Private_Type
(Typ
)
2985 and then No
(Full_View
(Typ
))
2986 and then not Is_Generic_Type
(Typ
)
2987 and then not Is_Tagged_Type
(Typ
)
2988 and then not Is_Frozen
(Typ
)
2990 Error_Msg_Sloc
:= Sloc
(Subp
);
2992 ("declaration must appear after completion of type &", N
, Typ
);
2994 ("\which is an untagged type in the profile of"
2995 & " primitive operation & declared#",
2998 end Check_Premature_Freezing
;
3004 procedure Export_DT
(Typ
: Entity_Id
; DT
: Entity_Id
) is
3006 Set_Is_Statically_Allocated
(DT
);
3007 Set_Is_True_Constant
(DT
);
3008 Set_Is_Exported
(DT
);
3010 pragma Assert
(Present
(Dispatch_Table_Wrapper
(Typ
)));
3011 Get_External_Name
(Dispatch_Table_Wrapper
(Typ
), True);
3012 Set_Interface_Name
(DT
,
3013 Make_String_Literal
(Loc
,
3014 Strval
=> String_From_Name_Buffer
));
3016 -- Ensure proper Sprint output of this implicit importation
3018 Set_Is_Internal
(DT
);
3022 -----------------------
3023 -- Make_Secondary_DT --
3024 -----------------------
3026 procedure Make_Secondary_DT
3029 Num_Iface_Prims
: Nat
;
3030 Iface_DT_Ptr
: Entity_Id
;
3031 Build_Thunks
: Boolean;
3034 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
3035 Name_DT
: constant Name_Id
:= New_Internal_Name
('T');
3036 Iface_DT
: constant Entity_Id
:=
3037 Make_Defining_Identifier
(Loc
, Name_DT
);
3038 Name_Predef_Prims
: constant Name_Id
:= New_Internal_Name
('R');
3039 Predef_Prims
: constant Entity_Id
:=
3040 Make_Defining_Identifier
(Loc
,
3042 DT_Constr_List
: List_Id
;
3043 DT_Aggr_List
: List_Id
;
3044 Empty_DT
: Boolean := False;
3045 Nb_Predef_Prims
: Nat
:= 0;
3049 OSD_Aggr_List
: List_Id
;
3052 Prim_Elmt
: Elmt_Id
;
3053 Prim_Ops_Aggr_List
: List_Id
;
3056 -- Handle cases in which we do not generate statically allocated
3059 if not Building_Static_DT
(Typ
) then
3060 Set_Ekind
(Predef_Prims
, E_Variable
);
3061 Set_Is_Statically_Allocated
(Predef_Prims
);
3063 Set_Ekind
(Iface_DT
, E_Variable
);
3064 Set_Is_Statically_Allocated
(Iface_DT
);
3066 -- Statically allocated dispatch tables and related entities are
3070 Set_Ekind
(Predef_Prims
, E_Constant
);
3071 Set_Is_Statically_Allocated
(Predef_Prims
);
3072 Set_Is_True_Constant
(Predef_Prims
);
3074 Set_Ekind
(Iface_DT
, E_Constant
);
3075 Set_Is_Statically_Allocated
(Iface_DT
);
3076 Set_Is_True_Constant
(Iface_DT
);
3079 -- Generate code to create the storage for the Dispatch_Table object.
3080 -- If the number of primitives of Typ is 0 we reserve a dummy single
3081 -- entry for its DT because at run-time the pointer to this dummy
3082 -- entry will be used as the tag.
3084 if Num_Iface_Prims
= 0 then
3088 Nb_Prim
:= Num_Iface_Prims
;
3093 -- Predef_Prims : Address_Array (1 .. Default_Prim_Ops_Count) :=
3094 -- (predef-prim-op-thunk-1'address,
3095 -- predef-prim-op-thunk-2'address,
3097 -- predef-prim-op-thunk-n'address);
3098 -- for Predef_Prims'Alignment use Address'Alignment
3100 -- Stage 1: Calculate the number of predefined primitives
3102 if not Building_Static_DT
(Typ
) then
3103 Nb_Predef_Prims
:= Max_Predef_Prims
;
3105 Prim_Elmt
:= First_Elmt
(Primitive_Operations
(Typ
));
3106 while Present
(Prim_Elmt
) loop
3107 Prim
:= Node
(Prim_Elmt
);
3109 if Is_Predefined_Dispatching_Operation
(Prim
)
3110 and then not Is_Abstract_Subprogram
(Prim
)
3112 Pos
:= UI_To_Int
(DT_Position
(Prim
));
3114 if Pos
> Nb_Predef_Prims
then
3115 Nb_Predef_Prims
:= Pos
;
3119 Next_Elmt
(Prim_Elmt
);
3123 -- Stage 2: Create the thunks associated with the predefined
3124 -- primitives and save their entity to fill the aggregate.
3127 Prim_Table
: array (Nat
range 1 .. Nb_Predef_Prims
) of Entity_Id
;
3128 Thunk_Id
: Entity_Id
;
3129 Thunk_Code
: Node_Id
;
3132 Prim_Ops_Aggr_List
:= New_List
;
3133 Prim_Table
:= (others => Empty
);
3135 if Building_Static_DT
(Typ
) then
3136 Prim_Elmt
:= First_Elmt
(Primitive_Operations
(Typ
));
3137 while Present
(Prim_Elmt
) loop
3138 Prim
:= Node
(Prim_Elmt
);
3140 if Is_Predefined_Dispatching_Operation
(Prim
)
3141 and then not Is_Abstract_Subprogram
(Prim
)
3142 and then not Present
(Prim_Table
3143 (UI_To_Int
(DT_Position
(Prim
))))
3145 if not Build_Thunks
then
3146 Prim_Table
(UI_To_Int
(DT_Position
(Prim
))) :=
3150 while Present
(Alias
(Prim
)) loop
3151 Prim
:= Alias
(Prim
);
3154 Expand_Interface_Thunk
(Prim
, Thunk_Id
, Thunk_Code
);
3156 if Present
(Thunk_Id
) then
3157 Append_To
(Result
, Thunk_Code
);
3158 Prim_Table
(UI_To_Int
(DT_Position
(Prim
)))
3164 Next_Elmt
(Prim_Elmt
);
3168 for J
in Prim_Table
'Range loop
3169 if Present
(Prim_Table
(J
)) then
3171 Make_Attribute_Reference
(Loc
,
3172 Prefix
=> New_Reference_To
(Prim_Table
(J
), Loc
),
3173 Attribute_Name
=> Name_Address
);
3176 New_Reference_To
(RTE
(RE_Null_Address
), Loc
);
3179 Append_To
(Prim_Ops_Aggr_List
, New_Node
);
3183 Make_Object_Declaration
(Loc
,
3184 Defining_Identifier
=> Predef_Prims
,
3185 Constant_Present
=> Building_Static_DT
(Typ
),
3186 Aliased_Present
=> True,
3187 Object_Definition
=>
3188 New_Reference_To
(RTE
(RE_Address_Array
), Loc
),
3189 Expression
=> Make_Aggregate
(Loc
,
3190 Expressions
=> Prim_Ops_Aggr_List
)));
3193 Make_Attribute_Definition_Clause
(Loc
,
3194 Name
=> New_Reference_To
(Predef_Prims
, Loc
),
3195 Chars
=> Name_Alignment
,
3197 Make_Attribute_Reference
(Loc
,
3199 New_Reference_To
(RTE
(RE_Integer_Address
), Loc
),
3200 Attribute_Name
=> Name_Alignment
)));
3205 -- OSD : Ada.Tags.Object_Specific_Data (Nb_Prims) :=
3206 -- (OSD_Table => (1 => <value>,
3210 -- Iface_DT : Dispatch_Table (Nb_Prims) :=
3211 -- ([ Signature => <sig-value> ],
3212 -- Tag_Kind => <tag_kind-value>,
3213 -- Predef_Prims => Predef_Prims'Address,
3214 -- Offset_To_Top => 0,
3215 -- OSD => OSD'Address,
3216 -- Prims_Ptr => (prim-op-1'address,
3217 -- prim-op-2'address,
3219 -- prim-op-n'address));
3221 -- Stage 3: Initialize the discriminant and the record components
3223 DT_Constr_List
:= New_List
;
3224 DT_Aggr_List
:= New_List
;
3226 -- Nb_Prim. If the tagged type has no primitives we add a dummy
3227 -- slot whose address will be the tag of this type.
3230 New_Node
:= Make_Integer_Literal
(Loc
, 1);
3232 New_Node
:= Make_Integer_Literal
(Loc
, Nb_Prim
);
3235 Append_To
(DT_Constr_List
, New_Node
);
3236 Append_To
(DT_Aggr_List
, New_Copy
(New_Node
));
3240 if RTE_Record_Component_Available
(RE_Signature
) then
3241 Append_To
(DT_Aggr_List
,
3242 New_Reference_To
(RTE
(RE_Secondary_DT
), Loc
));
3247 if RTE_Record_Component_Available
(RE_Tag_Kind
) then
3248 Append_To
(DT_Aggr_List
, Tagged_Kind
(Typ
));
3253 Append_To
(DT_Aggr_List
,
3254 Make_Attribute_Reference
(Loc
,
3255 Prefix
=> New_Reference_To
(Predef_Prims
, Loc
),
3256 Attribute_Name
=> Name_Address
));
3258 -- Note: The correct value of Offset_To_Top will be set by the init
3261 Append_To
(DT_Aggr_List
, Make_Integer_Literal
(Loc
, 0));
3263 -- Generate the Object Specific Data table required to dispatch calls
3264 -- through synchronized interfaces.
3267 or else Is_Abstract_Type
(Typ
)
3268 or else Is_Controlled
(Typ
)
3269 or else Restriction_Active
(No_Dispatching_Calls
)
3270 or else not Is_Limited_Type
(Typ
)
3271 or else not Has_Abstract_Interfaces
(Typ
)
3272 or else not Build_Thunks
3274 -- No OSD table required
3276 Append_To
(DT_Aggr_List
,
3277 New_Reference_To
(RTE
(RE_Null_Address
), Loc
));
3280 OSD_Aggr_List
:= New_List
;
3283 Prim_Table
: array (Nat
range 1 .. Nb_Prim
) of Entity_Id
;
3285 Prim_Alias
: Entity_Id
;
3286 Prim_Elmt
: Elmt_Id
;
3292 Prim_Table
:= (others => Empty
);
3293 Prim_Alias
:= Empty
;
3295 Prim_Elmt
:= First_Elmt
(Primitive_Operations
(Typ
));
3296 while Present
(Prim_Elmt
) loop
3297 Prim
:= Node
(Prim_Elmt
);
3299 if Present
(Abstract_Interface_Alias
(Prim
))
3300 and then Find_Dispatching_Type
3301 (Abstract_Interface_Alias
(Prim
)) = Iface
3303 Prim_Alias
:= Abstract_Interface_Alias
(Prim
);
3306 while Present
(Alias
(E
)) loop
3310 Pos
:= UI_To_Int
(DT_Position
(Prim_Alias
));
3312 if Present
(Prim_Table
(Pos
)) then
3313 pragma Assert
(Prim_Table
(Pos
) = E
);
3317 Prim_Table
(Pos
) := E
;
3319 Append_To
(OSD_Aggr_List
,
3320 Make_Component_Association
(Loc
,
3321 Choices
=> New_List
(
3322 Make_Integer_Literal
(Loc
,
3323 DT_Position
(Prim_Alias
))),
3325 Make_Integer_Literal
(Loc
,
3326 DT_Position
(Alias
(Prim
)))));
3332 Next_Elmt
(Prim_Elmt
);
3334 pragma Assert
(Count
= Nb_Prim
);
3337 OSD
:= Make_Defining_Identifier
(Loc
, New_Internal_Name
('I'));
3340 Make_Object_Declaration
(Loc
,
3341 Defining_Identifier
=> OSD
,
3342 Object_Definition
=>
3343 Make_Subtype_Indication
(Loc
,
3345 New_Reference_To
(RTE
(RE_Object_Specific_Data
), Loc
),
3347 Make_Index_Or_Discriminant_Constraint
(Loc
,
3348 Constraints
=> New_List
(
3349 Make_Integer_Literal
(Loc
, Nb_Prim
)))),
3350 Expression
=> Make_Aggregate
(Loc
,
3351 Component_Associations
=> New_List
(
3352 Make_Component_Association
(Loc
,
3353 Choices
=> New_List
(
3355 (RTE_Record_Component
(RE_OSD_Num_Prims
), Loc
)),
3357 Make_Integer_Literal
(Loc
, Nb_Prim
)),
3359 Make_Component_Association
(Loc
,
3360 Choices
=> New_List
(
3362 (RTE_Record_Component
(RE_OSD_Table
), Loc
)),
3363 Expression
=> Make_Aggregate
(Loc
,
3364 Component_Associations
=> OSD_Aggr_List
))))));
3367 Make_Attribute_Definition_Clause
(Loc
,
3368 Name
=> New_Reference_To
(OSD
, Loc
),
3369 Chars
=> Name_Alignment
,
3371 Make_Attribute_Reference
(Loc
,
3373 New_Reference_To
(RTE
(RE_Integer_Address
), Loc
),
3374 Attribute_Name
=> Name_Alignment
)));
3376 -- In secondary dispatch tables the Typeinfo component contains
3377 -- the address of the Object Specific Data (see a-tags.ads)
3379 Append_To
(DT_Aggr_List
,
3380 Make_Attribute_Reference
(Loc
,
3381 Prefix
=> New_Reference_To
(OSD
, Loc
),
3382 Attribute_Name
=> Name_Address
));
3385 -- Initialize the table of primitive operations
3387 Prim_Ops_Aggr_List
:= New_List
;
3390 Append_To
(Prim_Ops_Aggr_List
,
3391 New_Reference_To
(RTE
(RE_Null_Address
), Loc
));
3393 elsif Is_Abstract_Type
(Typ
)
3394 or else not Building_Static_DT
(Typ
)
3396 for J
in 1 .. Nb_Prim
loop
3397 Append_To
(Prim_Ops_Aggr_List
,
3398 New_Reference_To
(RTE
(RE_Null_Address
), Loc
));
3403 Prim_Table
: array (Nat
range 1 .. Nb_Prim
) of Entity_Id
;
3405 Thunk_Code
: Node_Id
;
3406 Thunk_Id
: Entity_Id
;
3409 Prim_Table
:= (others => Empty
);
3411 Prim_Elmt
:= First_Elmt
(Primitive_Operations
(Typ
));
3412 while Present
(Prim_Elmt
) loop
3413 Prim
:= Node
(Prim_Elmt
);
3415 if not Is_Predefined_Dispatching_Operation
(Prim
)
3416 and then Present
(Abstract_Interface_Alias
(Prim
))
3417 and then not Is_Abstract_Subprogram
(Alias
(Prim
))
3418 and then not Is_Imported
(Alias
(Prim
))
3419 and then Find_Dispatching_Type
3420 (Abstract_Interface_Alias
(Prim
)) = Iface
3422 -- Generate the code of the thunk only if the abstract
3423 -- interface type is not an immediate ancestor of
3424 -- Tagged_Type; otherwise the DT associated with the
3425 -- interface is the primary DT.
3427 and then not Is_Parent
(Iface
, Typ
)
3429 if not Build_Thunks
then
3432 (DT_Position
(Abstract_Interface_Alias
(Prim
)));
3433 Prim_Table
(Pos
) := Alias
(Prim
);
3435 Expand_Interface_Thunk
(Prim
, Thunk_Id
, Thunk_Code
);
3437 if Present
(Thunk_Id
) then
3440 (DT_Position
(Abstract_Interface_Alias
(Prim
)));
3442 Prim_Table
(Pos
) := Thunk_Id
;
3443 Append_To
(Result
, Thunk_Code
);
3448 Next_Elmt
(Prim_Elmt
);
3451 for J
in Prim_Table
'Range loop
3452 if Present
(Prim_Table
(J
)) then
3454 Make_Attribute_Reference
(Loc
,
3455 Prefix
=> New_Reference_To
(Prim_Table
(J
), Loc
),
3456 Attribute_Name
=> Name_Address
);
3459 New_Reference_To
(RTE
(RE_Null_Address
), Loc
);
3462 Append_To
(Prim_Ops_Aggr_List
, New_Node
);
3467 Append_To
(DT_Aggr_List
,
3468 Make_Aggregate
(Loc
,
3469 Expressions
=> Prim_Ops_Aggr_List
));
3472 Make_Object_Declaration
(Loc
,
3473 Defining_Identifier
=> Iface_DT
,
3474 Aliased_Present
=> True,
3475 Object_Definition
=>
3476 Make_Subtype_Indication
(Loc
,
3477 Subtype_Mark
=> New_Reference_To
3478 (RTE
(RE_Dispatch_Table_Wrapper
), Loc
),
3479 Constraint
=> Make_Index_Or_Discriminant_Constraint
(Loc
,
3480 Constraints
=> DT_Constr_List
)),
3482 Expression
=> Make_Aggregate
(Loc
,
3483 Expressions
=> DT_Aggr_List
)));
3486 Make_Attribute_Definition_Clause
(Loc
,
3487 Name
=> New_Reference_To
(Iface_DT
, Loc
),
3488 Chars
=> Name_Alignment
,
3490 Make_Attribute_Reference
(Loc
,
3492 New_Reference_To
(RTE
(RE_Integer_Address
), Loc
),
3493 Attribute_Name
=> Name_Alignment
)));
3495 -- Generate code to create the pointer to the dispatch table
3497 -- Iface_DT_Ptr : Tag := Tag!(DT'Address);
3500 Make_Object_Declaration
(Loc
,
3501 Defining_Identifier
=> Iface_DT_Ptr
,
3502 Constant_Present
=> True,
3503 Object_Definition
=>
3504 New_Reference_To
(RTE
(RE_Interface_Tag
), Loc
),
3506 Unchecked_Convert_To
(RTE
(RE_Interface_Tag
),
3507 Make_Attribute_Reference
(Loc
,
3509 Make_Selected_Component
(Loc
,
3510 Prefix
=> New_Reference_To
(Iface_DT
, Loc
),
3513 (RTE_Record_Component
(RE_Prims_Ptr
), Loc
)),
3514 Attribute_Name
=> Name_Address
))));
3516 end Make_Secondary_DT
;
3520 Elab_Code
: constant List_Id
:= New_List
;
3521 Result
: constant List_Id
:= New_List
;
3522 Tname
: constant Name_Id
:= Chars
(Typ
);
3524 AI_Tag_Elmt
: Elmt_Id
;
3525 AI_Tag_Comp
: Elmt_Id
;
3526 DT_Aggr_List
: List_Id
;
3527 DT_Constr_List
: List_Id
;
3531 Iface_Table_Node
: Node_Id
;
3532 Name_ITable
: Name_Id
;
3533 Name_No_Reg
: Name_Id
;
3534 Nb_Predef_Prims
: Nat
:= 0;
3538 Null_Parent_Tag
: Boolean := False;
3539 Num_Ifaces
: Nat
:= 0;
3543 Prim_Elmt
: Elmt_Id
;
3544 Prim_Ops_Aggr_List
: List_Id
;
3546 Typ_Comps
: Elist_Id
;
3547 Typ_Ifaces
: Elist_Id
;
3548 TSD_Aggr_List
: List_Id
;
3549 TSD_Tags_List
: List_Id
;
3551 -- The following name entries are used by Make_DT to generate a number
3552 -- of entities related to a tagged type. These entities may be generated
3553 -- in a scope other than that of the tagged type declaration, and if
3554 -- the entities for two tagged types with the same name happen to be
3555 -- generated in the same scope, we have to take care to use different
3556 -- names. This is achieved by means of a unique serial number appended
3557 -- to each generated entity name.
3559 Name_DT
: constant Name_Id
:=
3560 New_External_Name
(Tname
, 'T', Suffix_Index
=> -1);
3561 Name_Exname
: constant Name_Id
:=
3562 New_External_Name
(Tname
, 'E', Suffix_Index
=> -1);
3563 Name_HT_Link
: constant Name_Id
:=
3564 New_External_Name
(Tname
, 'H', Suffix_Index
=> -1);
3565 Name_Predef_Prims
: constant Name_Id
:=
3566 New_External_Name
(Tname
, 'R', Suffix_Index
=> -1);
3567 Name_SSD
: constant Name_Id
:=
3568 New_External_Name
(Tname
, 'S', Suffix_Index
=> -1);
3569 Name_TSD
: constant Name_Id
:=
3570 New_External_Name
(Tname
, 'B', Suffix_Index
=> -1);
3572 -- Entities built with above names
3574 DT
: constant Entity_Id
:=
3575 Make_Defining_Identifier
(Loc
, Name_DT
);
3576 Exname
: constant Entity_Id
:=
3577 Make_Defining_Identifier
(Loc
, Name_Exname
);
3578 HT_Link
: constant Entity_Id
:=
3579 Make_Defining_Identifier
(Loc
, Name_HT_Link
);
3580 Predef_Prims
: constant Entity_Id
:=
3581 Make_Defining_Identifier
(Loc
, Name_Predef_Prims
);
3582 SSD
: constant Entity_Id
:=
3583 Make_Defining_Identifier
(Loc
, Name_SSD
);
3584 TSD
: constant Entity_Id
:=
3585 Make_Defining_Identifier
(Loc
, Name_TSD
);
3587 -- Start of processing for Make_DT
3590 pragma Assert
(Is_Frozen
(Typ
));
3592 -- Handle cases in which there is no need to build the dispatch table
3594 if Has_Dispatch_Table
(Typ
)
3595 or else No
(Access_Disp_Table
(Typ
))
3596 or else Is_CPP_Class
(Typ
)
3600 elsif No_Run_Time_Mode
then
3601 Error_Msg_CRT
("tagged types", Typ
);
3604 elsif not RTE_Available
(RE_Tag
) then
3606 Make_Object_Declaration
(Loc
,
3607 Defining_Identifier
=> Node
(First_Elmt
3608 (Access_Disp_Table
(Typ
))),
3609 Object_Definition
=> New_Reference_To
(RTE
(RE_Tag
), Loc
),
3610 Constant_Present
=> True,
3612 Unchecked_Convert_To
(RTE
(RE_Tag
),
3613 New_Reference_To
(RTE
(RE_Null_Address
), Loc
))));
3615 Analyze_List
(Result
, Suppress
=> All_Checks
);
3616 Error_Msg_CRT
("tagged types", Typ
);
3620 -- Ensure that the value of Max_Predef_Prims defined in a-tags is
3621 -- correct. Valid values are 10 under configurable runtime or 16
3622 -- with full runtime.
3624 if RTE_Available
(RE_Interface_Data
) then
3625 if Max_Predef_Prims
/= 16 then
3626 Error_Msg_N
("run-time library configuration error", Typ
);
3630 if Max_Predef_Prims
/= 10 then
3631 Error_Msg_N
("run-time library configuration error", Typ
);
3632 Error_Msg_CRT
("tagged types", Typ
);
3637 -- Ensure that all the primitives are frozen. This is only required when
3638 -- building static dispatch tables --- the primitives must be frozen to
3639 -- be referenced (otherwise we have problems with the backend). It is
3640 -- not a requirement with nonstatic dispatch tables because in this case
3641 -- we generate now an empty dispatch table; the extra code required to
3642 -- register the primitives in the slots will be generated later --- when
3643 -- each primitive is frozen (see Freeze_Subprogram).
3645 if Building_Static_DT
(Typ
)
3646 and then not Is_CPP_Class
(Typ
)
3649 Save
: constant Boolean := Freezing_Library_Level_Tagged_Type
;
3650 Prim_Elmt
: Elmt_Id
;
3654 Freezing_Library_Level_Tagged_Type
:= True;
3655 Prim_Elmt
:= First_Elmt
(Primitive_Operations
(Typ
));
3656 while Present
(Prim_Elmt
) loop
3657 Frnodes
:= Freeze_Entity
(Node
(Prim_Elmt
), Loc
);
3660 Subp
: constant Entity_Id
:= Node
(Prim_Elmt
);
3664 F
:= First_Formal
(Subp
);
3665 while Present
(F
) loop
3666 Check_Premature_Freezing
(Subp
, Etype
(F
));
3670 Check_Premature_Freezing
(Subp
, Etype
(Subp
));
3673 if Present
(Frnodes
) then
3674 Append_List_To
(Result
, Frnodes
);
3677 Next_Elmt
(Prim_Elmt
);
3679 Freezing_Library_Level_Tagged_Type
:= Save
;
3683 -- Ada 2005 (AI-251): Build the secondary dispatch tables
3685 if Has_Abstract_Interfaces
(Typ
) then
3686 Collect_Interface_Components
(Typ
, Typ_Comps
);
3689 AI_Tag_Elmt
:= Next_Elmt
(First_Elmt
(Access_Disp_Table
(Typ
)));
3691 AI_Tag_Comp
:= First_Elmt
(Typ_Comps
);
3692 while Present
(AI_Tag_Comp
) loop
3694 -- Build the secondary table containing pointers to thunks
3698 Iface
=> Base_Type
(Related_Type
(Node
(AI_Tag_Comp
))),
3699 Num_Iface_Prims
=> UI_To_Int
3700 (DT_Entry_Count
(Node
(AI_Tag_Comp
))),
3701 Iface_DT_Ptr
=> Node
(AI_Tag_Elmt
),
3702 Build_Thunks
=> True,
3704 Next_Elmt
(AI_Tag_Elmt
);
3706 -- Build the secondary table contaning pointers to primitives
3707 -- (used to give support to Generic Dispatching Constructors).
3711 Iface
=> Base_Type
(Related_Type
(Node
(AI_Tag_Comp
))),
3712 Num_Iface_Prims
=> UI_To_Int
3713 (DT_Entry_Count
(Node
(AI_Tag_Comp
))),
3714 Iface_DT_Ptr
=> Node
(AI_Tag_Elmt
),
3715 Build_Thunks
=> False,
3717 Next_Elmt
(AI_Tag_Elmt
);
3719 Suffix_Index
:= Suffix_Index
+ 1;
3720 Next_Elmt
(AI_Tag_Comp
);
3724 -- Get the _tag entity and the number of primitives of its dispatch
3727 DT_Ptr
:= Node
(First_Elmt
(Access_Disp_Table
(Typ
)));
3728 Nb_Prim
:= UI_To_Int
(DT_Entry_Count
(First_Tag_Component
(Typ
)));
3730 Set_Is_Statically_Allocated
(DT
);
3731 Set_Is_Statically_Allocated
(SSD
);
3732 Set_Is_Statically_Allocated
(TSD
);
3733 Set_Is_Statically_Allocated
(Predef_Prims
);
3735 -- Generate code to define the boolean that controls registration, in
3736 -- order to avoid multiple registrations for tagged types defined in
3737 -- multiple-called scopes.
3739 Name_No_Reg
:= New_External_Name
(Tname
, 'F', Suffix_Index
=> -1);
3740 No_Reg
:= Make_Defining_Identifier
(Loc
, Name_No_Reg
);
3742 Set_Ekind
(No_Reg
, E_Variable
);
3743 Set_Is_Statically_Allocated
(No_Reg
);
3746 Make_Object_Declaration
(Loc
,
3747 Defining_Identifier
=> No_Reg
,
3748 Object_Definition
=> New_Reference_To
(Standard_Boolean
, Loc
),
3749 Expression
=> New_Reference_To
(Standard_True
, Loc
)));
3751 -- In case of locally defined tagged type we declare the object
3752 -- contanining the dispatch table by means of a variable. Its
3753 -- initialization is done later by means of an assignment. This is
3754 -- required to generate its External_Tag.
3756 if not Building_Static_DT
(Typ
) then
3759 -- DT : No_Dispatch_Table_Wrapper;
3760 -- for DT'Alignment use Address'Alignment;
3761 -- DT_Ptr : Tag := !Tag (DT.NDT_Prims_Ptr'Address);
3763 if not Has_DT
(Typ
) then
3765 Make_Object_Declaration
(Loc
,
3766 Defining_Identifier
=> DT
,
3767 Aliased_Present
=> True,
3768 Constant_Present
=> False,
3769 Object_Definition
=>
3771 (RTE
(RE_No_Dispatch_Table_Wrapper
), Loc
)));
3774 Make_Attribute_Definition_Clause
(Loc
,
3775 Name
=> New_Reference_To
(DT
, Loc
),
3776 Chars
=> Name_Alignment
,
3778 Make_Attribute_Reference
(Loc
,
3780 New_Reference_To
(RTE
(RE_Integer_Address
), Loc
),
3781 Attribute_Name
=> Name_Alignment
)));
3784 Make_Object_Declaration
(Loc
,
3785 Defining_Identifier
=> DT_Ptr
,
3786 Object_Definition
=> New_Reference_To
(RTE
(RE_Tag
), Loc
),
3787 Constant_Present
=> True,
3789 Unchecked_Convert_To
(RTE
(RE_Tag
),
3790 Make_Attribute_Reference
(Loc
,
3792 Make_Selected_Component
(Loc
,
3793 Prefix
=> New_Reference_To
(DT
, Loc
),
3796 (RTE_Record_Component
(RE_NDT_Prims_Ptr
), Loc
)),
3797 Attribute_Name
=> Name_Address
))));
3800 -- DT : Dispatch_Table_Wrapper (Nb_Prim);
3801 -- for DT'Alignment use Address'Alignment;
3802 -- DT_Ptr : Tag := !Tag (DT.Prims_Ptr'Address);
3805 -- If the tagged type has no primitives we add a dummy slot
3806 -- whose address will be the tag of this type.
3810 New_List
(Make_Integer_Literal
(Loc
, 1));
3813 New_List
(Make_Integer_Literal
(Loc
, Nb_Prim
));
3817 Make_Object_Declaration
(Loc
,
3818 Defining_Identifier
=> DT
,
3819 Aliased_Present
=> True,
3820 Constant_Present
=> False,
3821 Object_Definition
=>
3822 Make_Subtype_Indication
(Loc
,
3824 New_Reference_To
(RTE
(RE_Dispatch_Table_Wrapper
), Loc
),
3825 Constraint
=> Make_Index_Or_Discriminant_Constraint
(Loc
,
3826 Constraints
=> DT_Constr_List
))));
3829 Make_Attribute_Definition_Clause
(Loc
,
3830 Name
=> New_Reference_To
(DT
, Loc
),
3831 Chars
=> Name_Alignment
,
3833 Make_Attribute_Reference
(Loc
,
3835 New_Reference_To
(RTE
(RE_Integer_Address
), Loc
),
3836 Attribute_Name
=> Name_Alignment
)));
3839 Make_Object_Declaration
(Loc
,
3840 Defining_Identifier
=> DT_Ptr
,
3841 Object_Definition
=> New_Reference_To
(RTE
(RE_Tag
), Loc
),
3842 Constant_Present
=> True,
3844 Unchecked_Convert_To
(RTE
(RE_Tag
),
3845 Make_Attribute_Reference
(Loc
,
3847 Make_Selected_Component
(Loc
,
3848 Prefix
=> New_Reference_To
(DT
, Loc
),
3851 (RTE_Record_Component
(RE_Prims_Ptr
), Loc
)),
3852 Attribute_Name
=> Name_Address
))));
3856 -- Generate: Exname : constant String := full_qualified_name (typ);
3857 -- The type itself may be an anonymous parent type, so use the first
3858 -- subtype to have a user-recognizable name.
3861 Make_Object_Declaration
(Loc
,
3862 Defining_Identifier
=> Exname
,
3863 Constant_Present
=> True,
3864 Object_Definition
=> New_Reference_To
(Standard_String
, Loc
),
3866 Make_String_Literal
(Loc
,
3867 Full_Qualified_Name
(First_Subtype
(Typ
)))));
3869 Set_Is_Statically_Allocated
(Exname
);
3870 Set_Is_True_Constant
(Exname
);
3872 -- Declare the object used by Ada.Tags.Register_Tag
3874 if RTE_Available
(RE_Register_Tag
) then
3876 Make_Object_Declaration
(Loc
,
3877 Defining_Identifier
=> HT_Link
,
3878 Object_Definition
=> New_Reference_To
(RTE
(RE_Tag
), Loc
)));
3881 -- Generate code to create the storage for the type specific data object
3882 -- with enough space to store the tags of the ancestors plus the tags
3883 -- of all the implemented interfaces (as described in a-tags.adb).
3885 -- TSD : Type_Specific_Data (I_Depth) :=
3886 -- (Idepth => I_Depth,
3887 -- Access_Level => Type_Access_Level (Typ),
3888 -- Expanded_Name => Cstring_Ptr!(Exname'Address))
3889 -- External_Tag => Cstring_Ptr!(Exname'Address))
3890 -- HT_Link => HT_Link'Address,
3891 -- Transportable => <<boolean-value>>,
3892 -- RC_Offset => <<integer-value>>,
3893 -- [ Interfaces_Table => <<access-value>> ]
3894 -- [ SSD => SSD_Table'Address ]
3895 -- Tags_Table => (0 => null,
3898 -- for TSD'Alignment use Address'Alignment
3900 TSD_Aggr_List
:= New_List
;
3902 -- Idepth: Count ancestors to compute the inheritance depth. For private
3903 -- extensions, always go to the full view in order to compute the real
3904 -- inheritance depth.
3907 Current_Typ
: Entity_Id
;
3908 Parent_Typ
: Entity_Id
;
3914 Parent_Typ
:= Etype
(Current_Typ
);
3916 if Is_Private_Type
(Parent_Typ
) then
3917 Parent_Typ
:= Full_View
(Base_Type
(Parent_Typ
));
3920 exit when Parent_Typ
= Current_Typ
;
3922 I_Depth
:= I_Depth
+ 1;
3923 Current_Typ
:= Parent_Typ
;
3927 Append_To
(TSD_Aggr_List
,
3928 Make_Integer_Literal
(Loc
, I_Depth
));
3932 Append_To
(TSD_Aggr_List
,
3933 Make_Integer_Literal
(Loc
, Type_Access_Level
(Typ
)));
3937 Append_To
(TSD_Aggr_List
,
3938 Unchecked_Convert_To
(RTE
(RE_Cstring_Ptr
),
3939 Make_Attribute_Reference
(Loc
,
3940 Prefix
=> New_Reference_To
(Exname
, Loc
),
3941 Attribute_Name
=> Name_Address
)));
3943 -- External_Tag of a local tagged type
3945 -- <typ>A : constant String :=
3946 -- "Internal tag at 16#tag-addr#: <full-name-of-typ>";
3948 -- The reason we generate this strange name is that we do not want to
3949 -- enter local tagged types in the global hash table used to compute
3950 -- the Internal_Tag attribute for two reasons:
3952 -- 1. It is hard to avoid a tasking race condition for entering the
3953 -- entry into the hash table.
3955 -- 2. It would cause a storage leak, unless we rig up considerable
3956 -- mechanism to remove the entry from the hash table on exit.
3958 -- So what we do is to generate the above external tag name, where the
3959 -- hex address is the address of the local dispatch table (i.e. exactly
3960 -- the value we want if Internal_Tag is computed from this string).
3962 -- Of course this value will only be valid if the tagged type is still
3963 -- in scope, but it clearly must be erroneous to compute the internal
3964 -- tag of a tagged type that is out of scope!
3966 -- We don't do this processing if an explicit external tag has been
3967 -- specified. That's an odd case for which we have already issued a
3968 -- warning, where we will not be able to compute the internal tag.
3970 if not Is_Library_Level_Entity
(Typ
)
3971 and then not Has_External_Tag_Rep_Clause
(Typ
)
3974 Exname
: constant Entity_Id
:=
3975 Make_Defining_Identifier
(Loc
,
3976 New_External_Name
(Tname
, 'A'));
3978 Full_Name
: constant String_Id
:=
3979 Full_Qualified_Name
(First_Subtype
(Typ
));
3980 Str1_Id
: String_Id
;
3981 Str2_Id
: String_Id
;
3985 -- Str1 = "Internal tag at 16#";
3988 Store_String_Chars
("Internal tag at 16#");
3989 Str1_Id
:= End_String
;
3992 -- Str2 = "#: <type-full-name>";
3995 Store_String_Chars
("#: ");
3996 Store_String_Chars
(Full_Name
);
3997 Str2_Id
:= End_String
;
4000 -- Exname : constant String :=
4001 -- Str1 & Address_Image (Tag) & Str2;
4003 if RTE_Available
(RE_Address_Image
) then
4005 Make_Object_Declaration
(Loc
,
4006 Defining_Identifier
=> Exname
,
4007 Constant_Present
=> True,
4008 Object_Definition
=> New_Reference_To
4009 (Standard_String
, Loc
),
4011 Make_Op_Concat
(Loc
,
4013 Make_String_Literal
(Loc
, Str1_Id
),
4015 Make_Op_Concat
(Loc
,
4017 Make_Function_Call
(Loc
,
4020 (RTE
(RE_Address_Image
), Loc
),
4021 Parameter_Associations
=> New_List
(
4022 Unchecked_Convert_To
(RTE
(RE_Address
),
4023 New_Reference_To
(DT_Ptr
, Loc
)))),
4025 Make_String_Literal
(Loc
, Str2_Id
)))));
4029 Make_Object_Declaration
(Loc
,
4030 Defining_Identifier
=> Exname
,
4031 Constant_Present
=> True,
4032 Object_Definition
=> New_Reference_To
4033 (Standard_String
, Loc
),
4035 Make_Op_Concat
(Loc
,
4037 Make_String_Literal
(Loc
, Str1_Id
),
4039 Make_String_Literal
(Loc
, Str2_Id
))));
4043 Unchecked_Convert_To
(RTE
(RE_Cstring_Ptr
),
4044 Make_Attribute_Reference
(Loc
,
4045 Prefix
=> New_Reference_To
(Exname
, Loc
),
4046 Attribute_Name
=> Name_Address
));
4049 -- External tag of a library-level tagged type: Check for a definition
4050 -- of External_Tag. The clause is considered only if it applies to this
4051 -- specific tagged type, as opposed to one of its ancestors.
4055 Def
: constant Node_Id
:= Get_Attribute_Definition_Clause
(Typ
,
4056 Attribute_External_Tag
);
4057 Old_Val
: String_Id
;
4058 New_Val
: String_Id
;
4062 if not Present
(Def
)
4063 or else Entity
(Name
(Def
)) /= Typ
4066 Unchecked_Convert_To
(RTE
(RE_Cstring_Ptr
),
4067 Make_Attribute_Reference
(Loc
,
4068 Prefix
=> New_Reference_To
(Exname
, Loc
),
4069 Attribute_Name
=> Name_Address
));
4071 Old_Val
:= Strval
(Expr_Value_S
(Expression
(Def
)));
4073 -- For the rep clause "for <typ>'external_tag use y" generate:
4075 -- <typ>A : constant string := y;
4077 -- <typ>A'Address is used to set the External_Tag component
4080 -- Create a new nul terminated string if it is not already
4082 if String_Length
(Old_Val
) > 0
4084 Get_String_Char
(Old_Val
, String_Length
(Old_Val
)) = 0
4088 Start_String
(Old_Val
);
4089 Store_String_Char
(Get_Char_Code
(ASCII
.NUL
));
4090 New_Val
:= End_String
;
4093 E
:= Make_Defining_Identifier
(Loc
,
4094 New_External_Name
(Chars
(Typ
), 'A'));
4097 Make_Object_Declaration
(Loc
,
4098 Defining_Identifier
=> E
,
4099 Constant_Present
=> True,
4100 Object_Definition
=>
4101 New_Reference_To
(Standard_String
, Loc
),
4103 Make_String_Literal
(Loc
, New_Val
)));
4106 Unchecked_Convert_To
(RTE
(RE_Cstring_Ptr
),
4107 Make_Attribute_Reference
(Loc
,
4108 Prefix
=> New_Reference_To
(E
, Loc
),
4109 Attribute_Name
=> Name_Address
));
4114 Append_To
(TSD_Aggr_List
, New_Node
);
4118 if RTE_Available
(RE_Register_Tag
) then
4119 Append_To
(TSD_Aggr_List
,
4120 Unchecked_Convert_To
(RTE
(RE_Tag_Ptr
),
4121 Make_Attribute_Reference
(Loc
,
4122 Prefix
=> New_Reference_To
(HT_Link
, Loc
),
4123 Attribute_Name
=> Name_Address
)));
4125 Append_To
(TSD_Aggr_List
,
4126 Unchecked_Convert_To
(RTE
(RE_Tag_Ptr
),
4127 New_Reference_To
(RTE
(RE_Null_Address
), Loc
)));
4130 -- Transportable: Set for types that can be used in remote calls
4131 -- with respect to E.4(18) legality rules.
4134 Transportable
: Entity_Id
;
4140 or else Is_Shared_Passive
(Typ
)
4142 ((Is_Remote_Types
(Typ
)
4143 or else Is_Remote_Call_Interface
(Typ
))
4144 and then Original_View_In_Visible_Part
(Typ
))
4145 or else not Comes_From_Source
(Typ
));
4147 Append_To
(TSD_Aggr_List
,
4148 New_Occurrence_Of
(Transportable
, Loc
));
4151 -- RC_Offset: These are the valid values and their meaning:
4153 -- >0: For simple types with controlled components is
4154 -- type._record_controller'position
4156 -- 0: For types with no controlled components
4158 -- -1: For complex types with controlled components where the position
4159 -- of the record controller is not statically computable but there
4160 -- are controlled components at this level. The _Controller field
4161 -- is available right after the _parent.
4163 -- -2: There are no controlled components at this level. We need to
4164 -- get the position from the parent.
4167 RC_Offset_Node
: Node_Id
;
4168 Parent_Typ
: Entity_Id
;
4171 if Present
(Full_View
(Etype
(Typ
))) then
4172 Parent_Typ
:= Full_View
(Etype
(Typ
));
4174 Parent_Typ
:= Etype
(Typ
);
4177 if not Has_Controlled_Component
(Typ
) then
4178 RC_Offset_Node
:= Make_Integer_Literal
(Loc
, 0);
4180 elsif Etype
(Typ
) /= Typ
4181 and then Has_Discriminants
(Parent_Typ
)
4183 if Has_New_Controlled_Component
(Typ
) then
4184 RC_Offset_Node
:= Make_Integer_Literal
(Loc
, -1);
4186 RC_Offset_Node
:= Make_Integer_Literal
(Loc
, -2);
4190 Make_Attribute_Reference
(Loc
,
4192 Make_Selected_Component
(Loc
,
4193 Prefix
=> New_Reference_To
(Typ
, Loc
),
4195 New_Reference_To
(Controller_Component
(Typ
), Loc
)),
4196 Attribute_Name
=> Name_Position
);
4198 -- This is not proper Ada code to use the attribute 'Position
4199 -- on something else than an object but this is supported by
4200 -- the back end (see comment on the Bit_Component attribute in
4201 -- sem_attr). So we avoid semantic checking here.
4203 -- Is this documented in sinfo.ads??? it should be!
4205 Set_Analyzed
(RC_Offset_Node
);
4206 Set_Etype
(Prefix
(RC_Offset_Node
), RTE
(RE_Record_Controller
));
4207 Set_Etype
(Prefix
(Prefix
(RC_Offset_Node
)), Typ
);
4208 Set_Etype
(Selector_Name
(Prefix
(RC_Offset_Node
)),
4209 RTE
(RE_Record_Controller
));
4210 Set_Etype
(RC_Offset_Node
, RTE
(RE_Storage_Offset
));
4213 Append_To
(TSD_Aggr_List
, RC_Offset_Node
);
4216 -- Interfaces_Table (required for AI-405)
4218 if RTE_Record_Component_Available
(RE_Interfaces_Table
) then
4220 -- Count the number of interface types implemented by Typ
4222 Collect_Abstract_Interfaces
(Typ
, Typ_Ifaces
);
4224 AI
:= First_Elmt
(Typ_Ifaces
);
4225 while Present
(AI
) loop
4226 Num_Ifaces
:= Num_Ifaces
+ 1;
4230 if Num_Ifaces
= 0 then
4231 Iface_Table_Node
:= Make_Null
(Loc
);
4233 -- Generate the Interface_Table object
4237 TSD_Ifaces_List
: constant List_Id
:= New_List
;
4239 Sec_DT_Tag
: Node_Id
;
4242 AI
:= First_Elmt
(Typ_Ifaces
);
4243 while Present
(AI
) loop
4244 if Is_Parent
(Node
(AI
), Typ
) then
4246 New_Reference_To
(DT_Ptr
, Loc
);
4248 Elmt
:= Next_Elmt
(First_Elmt
(Access_Disp_Table
(Typ
)));
4249 pragma Assert
(Has_Thunks
(Node
(Elmt
)));
4251 while Ekind
(Node
(Elmt
)) = E_Constant
4253 Is_Parent
(Node
(AI
), Related_Type
(Node
(Elmt
)))
4255 pragma Assert
(Has_Thunks
(Node
(Elmt
)));
4257 pragma Assert
(not Has_Thunks
(Node
(Elmt
)));
4261 pragma Assert
(Ekind
(Node
(Elmt
)) = E_Constant
4262 and then not Has_Thunks
(Node
(Next_Elmt
(Elmt
))));
4264 New_Reference_To
(Node
(Next_Elmt
(Elmt
)), Loc
);
4267 Append_To
(TSD_Ifaces_List
,
4268 Make_Aggregate
(Loc
,
4269 Expressions
=> New_List
(
4273 Unchecked_Convert_To
(RTE
(RE_Tag
),
4275 (Node
(First_Elmt
(Access_Disp_Table
(Node
(AI
)))),
4278 -- Static_Offset_To_Top
4280 New_Reference_To
(Standard_True
, Loc
),
4282 -- Offset_To_Top_Value
4284 Make_Integer_Literal
(Loc
, 0),
4286 -- Offset_To_Top_Func
4292 Unchecked_Convert_To
(RTE
(RE_Tag
), Sec_DT_Tag
)
4299 Name_ITable
:= New_External_Name
(Tname
, 'I');
4300 ITable
:= Make_Defining_Identifier
(Loc
, Name_ITable
);
4301 Set_Is_Statically_Allocated
(ITable
);
4303 -- The table of interfaces is not constant; its slots are
4304 -- filled at run-time by the IP routine using attribute
4305 -- 'Position to know the location of the tag components
4306 -- (and this attribute cannot be safely used before the
4307 -- object is initialized).
4310 Make_Object_Declaration
(Loc
,
4311 Defining_Identifier
=> ITable
,
4312 Aliased_Present
=> True,
4313 Constant_Present
=> False,
4314 Object_Definition
=>
4315 Make_Subtype_Indication
(Loc
,
4317 New_Reference_To
(RTE
(RE_Interface_Data
), Loc
),
4318 Constraint
=> Make_Index_Or_Discriminant_Constraint
4320 Constraints
=> New_List
(
4321 Make_Integer_Literal
(Loc
, Num_Ifaces
)))),
4323 Expression
=> Make_Aggregate
(Loc
,
4324 Expressions
=> New_List
(
4325 Make_Integer_Literal
(Loc
, Num_Ifaces
),
4326 Make_Aggregate
(Loc
,
4327 Expressions
=> TSD_Ifaces_List
)))));
4330 Make_Attribute_Definition_Clause
(Loc
,
4331 Name
=> New_Reference_To
(ITable
, Loc
),
4332 Chars
=> Name_Alignment
,
4334 Make_Attribute_Reference
(Loc
,
4336 New_Reference_To
(RTE
(RE_Integer_Address
), Loc
),
4337 Attribute_Name
=> Name_Alignment
)));
4340 Make_Attribute_Reference
(Loc
,
4341 Prefix
=> New_Reference_To
(ITable
, Loc
),
4342 Attribute_Name
=> Name_Unchecked_Access
);
4346 Append_To
(TSD_Aggr_List
, Iface_Table_Node
);
4349 -- Generate the Select Specific Data table for synchronized types that
4350 -- implement synchronized interfaces. The size of the table is
4351 -- constrained by the number of non-predefined primitive operations.
4353 if RTE_Record_Component_Available
(RE_SSD
) then
4354 if Ada_Version
>= Ada_05
4355 and then Has_DT
(Typ
)
4356 and then Is_Concurrent_Record_Type
(Typ
)
4357 and then Has_Abstract_Interfaces
(Typ
)
4358 and then Nb_Prim
> 0
4359 and then not Is_Abstract_Type
(Typ
)
4360 and then not Is_Controlled
(Typ
)
4361 and then not Restriction_Active
(No_Dispatching_Calls
)
4364 Make_Object_Declaration
(Loc
,
4365 Defining_Identifier
=> SSD
,
4366 Aliased_Present
=> True,
4367 Object_Definition
=>
4368 Make_Subtype_Indication
(Loc
,
4369 Subtype_Mark
=> New_Reference_To
(
4370 RTE
(RE_Select_Specific_Data
), Loc
),
4372 Make_Index_Or_Discriminant_Constraint
(Loc
,
4373 Constraints
=> New_List
(
4374 Make_Integer_Literal
(Loc
, Nb_Prim
))))));
4377 Make_Attribute_Definition_Clause
(Loc
,
4378 Name
=> New_Reference_To
(SSD
, Loc
),
4379 Chars
=> Name_Alignment
,
4381 Make_Attribute_Reference
(Loc
,
4383 New_Reference_To
(RTE
(RE_Integer_Address
), Loc
),
4384 Attribute_Name
=> Name_Alignment
)));
4386 -- This table is initialized by Make_Select_Specific_Data_Table,
4387 -- which calls Set_Entry_Index and Set_Prim_Op_Kind.
4389 Append_To
(TSD_Aggr_List
,
4390 Make_Attribute_Reference
(Loc
,
4391 Prefix
=> New_Reference_To
(SSD
, Loc
),
4392 Attribute_Name
=> Name_Unchecked_Access
));
4394 Append_To
(TSD_Aggr_List
, Make_Null
(Loc
));
4398 -- Initialize the table of ancestor tags. In case of interface types
4399 -- this table is not needed.
4402 Current_Typ
: Entity_Id
;
4403 Parent_Typ
: Entity_Id
;
4407 TSD_Tags_List
:= New_List
;
4409 -- If we are not statically allocating the dispatch table then we
4410 -- must fill position 0 with null because we still have not
4411 -- generated the tag of Typ.
4413 if not Building_Static_DT
(Typ
)
4414 or else Is_Interface
(Typ
)
4416 Append_To
(TSD_Tags_List
,
4417 Unchecked_Convert_To
(RTE
(RE_Tag
),
4418 New_Reference_To
(RTE
(RE_Null_Address
), Loc
)));
4420 -- Otherwise we can safely reference the tag
4423 Append_To
(TSD_Tags_List
,
4424 New_Reference_To
(DT_Ptr
, Loc
));
4427 -- Fill the rest of the table with the tags of the ancestors
4433 Parent_Typ
:= Etype
(Current_Typ
);
4435 if Is_Private_Type
(Parent_Typ
) then
4436 Parent_Typ
:= Full_View
(Base_Type
(Parent_Typ
));
4439 exit when Parent_Typ
= Current_Typ
;
4441 if Is_CPP_Class
(Parent_Typ
)
4442 or else Is_Interface
(Typ
)
4444 -- The tags defined in the C++ side will be inherited when
4445 -- the object is constructed (Exp_Ch3.Build_Init_Procedure)
4447 Append_To
(TSD_Tags_List
,
4448 Unchecked_Convert_To
(RTE
(RE_Tag
),
4449 New_Reference_To
(RTE
(RE_Null_Address
), Loc
)));
4451 Append_To
(TSD_Tags_List
,
4453 (Node
(First_Elmt
(Access_Disp_Table
(Parent_Typ
))),
4458 Current_Typ
:= Parent_Typ
;
4461 pragma Assert
(Pos
= I_Depth
+ 1);
4464 Append_To
(TSD_Aggr_List
,
4465 Make_Aggregate
(Loc
,
4466 Expressions
=> TSD_Tags_List
));
4468 -- Build the TSD object
4471 Make_Object_Declaration
(Loc
,
4472 Defining_Identifier
=> TSD
,
4473 Aliased_Present
=> True,
4474 Constant_Present
=> Building_Static_DT
(Typ
),
4475 Object_Definition
=>
4476 Make_Subtype_Indication
(Loc
,
4477 Subtype_Mark
=> New_Reference_To
(
4478 RTE
(RE_Type_Specific_Data
), Loc
),
4480 Make_Index_Or_Discriminant_Constraint
(Loc
,
4481 Constraints
=> New_List
(
4482 Make_Integer_Literal
(Loc
, I_Depth
)))),
4484 Expression
=> Make_Aggregate
(Loc
,
4485 Expressions
=> TSD_Aggr_List
)));
4487 Set_Is_True_Constant
(TSD
, Building_Static_DT
(Typ
));
4490 Make_Attribute_Definition_Clause
(Loc
,
4491 Name
=> New_Reference_To
(TSD
, Loc
),
4492 Chars
=> Name_Alignment
,
4494 Make_Attribute_Reference
(Loc
,
4495 Prefix
=> New_Reference_To
(RTE
(RE_Integer_Address
), Loc
),
4496 Attribute_Name
=> Name_Alignment
)));
4498 -- Initialize or declare the dispatch table object
4500 if not Has_DT
(Typ
) then
4501 DT_Constr_List
:= New_List
;
4502 DT_Aggr_List
:= New_List
;
4507 Make_Attribute_Reference
(Loc
,
4508 Prefix
=> New_Reference_To
(TSD
, Loc
),
4509 Attribute_Name
=> Name_Address
);
4511 Append_To
(DT_Constr_List
, New_Node
);
4512 Append_To
(DT_Aggr_List
, New_Copy
(New_Node
));
4513 Append_To
(DT_Aggr_List
, Make_Integer_Literal
(Loc
, 0));
4515 -- In case of locally defined tagged types we have already declared
4516 -- and uninitialized object for the dispatch table, which is now
4517 -- initialized by means of the following assignment:
4519 -- DT := (TSD'Address, 0);
4521 if not Building_Static_DT
(Typ
) then
4523 Make_Assignment_Statement
(Loc
,
4524 Name
=> New_Reference_To
(DT
, Loc
),
4525 Expression
=> Make_Aggregate
(Loc
,
4526 Expressions
=> DT_Aggr_List
)));
4528 -- In case of library level tagged types we declare and export now
4529 -- the constant object containing the dummy dispatch table. There
4530 -- is no need to declare the tag here because it has been previously
4531 -- declared by Make_Tags
4533 -- DT : aliased constant No_Dispatch_Table :=
4534 -- (NDT_TSD => TSD'Address;
4535 -- NDT_Prims_Ptr => 0);
4536 -- for DT'Alignment use Address'Alignment;
4540 Make_Object_Declaration
(Loc
,
4541 Defining_Identifier
=> DT
,
4542 Aliased_Present
=> True,
4543 Constant_Present
=> True,
4544 Object_Definition
=>
4545 New_Reference_To
(RTE
(RE_No_Dispatch_Table_Wrapper
), Loc
),
4546 Expression
=> Make_Aggregate
(Loc
,
4547 Expressions
=> DT_Aggr_List
)));
4550 Make_Attribute_Definition_Clause
(Loc
,
4551 Name
=> New_Reference_To
(DT
, Loc
),
4552 Chars
=> Name_Alignment
,
4554 Make_Attribute_Reference
(Loc
,
4556 New_Reference_To
(RTE
(RE_Integer_Address
), Loc
),
4557 Attribute_Name
=> Name_Alignment
)));
4559 Export_DT
(Typ
, DT
);
4562 -- Common case: Typ has a dispatch table
4566 -- Predef_Prims : Address_Array (1 .. Default_Prim_Ops_Count) :=
4567 -- (predef-prim-op-1'address,
4568 -- predef-prim-op-2'address,
4570 -- predef-prim-op-n'address);
4571 -- for Predef_Prims'Alignment use Address'Alignment
4573 -- DT : Dispatch_Table (Nb_Prims) :=
4574 -- (Signature => <sig-value>,
4575 -- Tag_Kind => <tag_kind-value>,
4576 -- Predef_Prims => Predef_Prims'First'Address,
4577 -- Offset_To_Top => 0,
4578 -- TSD => TSD'Address;
4579 -- Prims_Ptr => (prim-op-1'address,
4580 -- prim-op-2'address,
4582 -- prim-op-n'address));
4583 -- for DT'Alignment use Address'Alignment
4590 if not Building_Static_DT
(Typ
) then
4591 Nb_Predef_Prims
:= Max_Predef_Prims
;
4594 Prim_Elmt
:= First_Elmt
(Primitive_Operations
(Typ
));
4595 while Present
(Prim_Elmt
) loop
4596 Prim
:= Node
(Prim_Elmt
);
4598 if Is_Predefined_Dispatching_Operation
(Prim
)
4599 and then not Is_Abstract_Subprogram
(Prim
)
4601 Pos
:= UI_To_Int
(DT_Position
(Prim
));
4603 if Pos
> Nb_Predef_Prims
then
4604 Nb_Predef_Prims
:= Pos
;
4608 Next_Elmt
(Prim_Elmt
);
4614 (Nat
range 1 .. Nb_Predef_Prims
) of Entity_Id
;
4618 Prim_Ops_Aggr_List
:= New_List
;
4620 Prim_Table
:= (others => Empty
);
4622 if Building_Static_DT
(Typ
) then
4623 Prim_Elmt
:= First_Elmt
(Primitive_Operations
(Typ
));
4624 while Present
(Prim_Elmt
) loop
4625 Prim
:= Node
(Prim_Elmt
);
4627 if Is_Predefined_Dispatching_Operation
(Prim
)
4628 and then not Is_Abstract_Subprogram
(Prim
)
4629 and then not Present
(Prim_Table
4630 (UI_To_Int
(DT_Position
(Prim
))))
4633 while Present
(Alias
(E
)) loop
4637 pragma Assert
(not Is_Abstract_Subprogram
(E
));
4638 Prim_Table
(UI_To_Int
(DT_Position
(Prim
))) := E
;
4641 Next_Elmt
(Prim_Elmt
);
4645 for J
in Prim_Table
'Range loop
4646 if Present
(Prim_Table
(J
)) then
4648 Make_Attribute_Reference
(Loc
,
4649 Prefix
=> New_Reference_To
(Prim_Table
(J
), Loc
),
4650 Attribute_Name
=> Name_Address
);
4652 New_Node
:= New_Reference_To
(RTE
(RE_Null_Address
), Loc
);
4655 Append_To
(Prim_Ops_Aggr_List
, New_Node
);
4659 Make_Object_Declaration
(Loc
,
4660 Defining_Identifier
=> Predef_Prims
,
4661 Aliased_Present
=> True,
4662 Constant_Present
=> Building_Static_DT
(Typ
),
4663 Object_Definition
=>
4664 New_Reference_To
(RTE
(RE_Address_Array
), Loc
),
4665 Expression
=> Make_Aggregate
(Loc
,
4666 Expressions
=> Prim_Ops_Aggr_List
)));
4669 Make_Attribute_Definition_Clause
(Loc
,
4670 Name
=> New_Reference_To
(Predef_Prims
, Loc
),
4671 Chars
=> Name_Alignment
,
4673 Make_Attribute_Reference
(Loc
,
4675 New_Reference_To
(RTE
(RE_Integer_Address
), Loc
),
4676 Attribute_Name
=> Name_Alignment
)));
4680 -- Stage 1: Initialize the discriminant and the record components
4682 DT_Constr_List
:= New_List
;
4683 DT_Aggr_List
:= New_List
;
4685 -- Num_Prims. If the tagged type has no primitives we add a dummy
4686 -- slot whose address will be the tag of this type.
4689 New_Node
:= Make_Integer_Literal
(Loc
, 1);
4691 New_Node
:= Make_Integer_Literal
(Loc
, Nb_Prim
);
4694 Append_To
(DT_Constr_List
, New_Node
);
4695 Append_To
(DT_Aggr_List
, New_Copy
(New_Node
));
4699 if RTE_Record_Component_Available
(RE_Signature
) then
4700 Append_To
(DT_Aggr_List
,
4701 New_Reference_To
(RTE
(RE_Primary_DT
), Loc
));
4706 if RTE_Record_Component_Available
(RE_Tag_Kind
) then
4707 Append_To
(DT_Aggr_List
, Tagged_Kind
(Typ
));
4712 Append_To
(DT_Aggr_List
,
4713 Make_Attribute_Reference
(Loc
,
4714 Prefix
=> New_Reference_To
(Predef_Prims
, Loc
),
4715 Attribute_Name
=> Name_Address
));
4719 if RTE_Record_Component_Available
(RE_Offset_To_Top
) then
4720 Append_To
(DT_Aggr_List
, Make_Integer_Literal
(Loc
, 0));
4725 Append_To
(DT_Aggr_List
,
4726 Make_Attribute_Reference
(Loc
,
4727 Prefix
=> New_Reference_To
(TSD
, Loc
),
4728 Attribute_Name
=> Name_Address
));
4730 -- Stage 2: Initialize the table of primitive operations
4732 Prim_Ops_Aggr_List
:= New_List
;
4735 Append_To
(Prim_Ops_Aggr_List
,
4736 New_Reference_To
(RTE
(RE_Null_Address
), Loc
));
4738 elsif not Building_Static_DT
(Typ
) then
4739 for J
in 1 .. Nb_Prim
loop
4740 Append_To
(Prim_Ops_Aggr_List
,
4741 New_Reference_To
(RTE
(RE_Null_Address
), Loc
));
4746 Prim_Table
: array (Nat
range 1 .. Nb_Prim
) of Entity_Id
;
4749 Prim_Elmt
: Elmt_Id
;
4752 Prim_Table
:= (others => Empty
);
4754 Prim_Elmt
:= First_Elmt
(Primitive_Operations
(Typ
));
4755 while Present
(Prim_Elmt
) loop
4756 Prim
:= Node
(Prim_Elmt
);
4758 if Is_Imported
(Prim
)
4759 or else Present
(Abstract_Interface_Alias
(Prim
))
4760 or else Is_Predefined_Dispatching_Operation
(Prim
)
4765 -- Traverse the list of aliased entities to handle
4766 -- renamings of predefined primitives.
4769 while Present
(Alias
(E
)) loop
4773 if not Is_Predefined_Dispatching_Operation
(E
)
4774 and then not Is_Abstract_Subprogram
(E
)
4775 and then not Present
(Abstract_Interface_Alias
(E
))
4778 (UI_To_Int
(DT_Position
(Prim
)) <= Nb_Prim
);
4780 Prim_Table
(UI_To_Int
(DT_Position
(Prim
))) := E
;
4784 Next_Elmt
(Prim_Elmt
);
4787 for J
in Prim_Table
'Range loop
4788 if Present
(Prim_Table
(J
)) then
4790 Make_Attribute_Reference
(Loc
,
4791 Prefix
=> New_Reference_To
(Prim_Table
(J
), Loc
),
4792 Attribute_Name
=> Name_Address
);
4794 New_Node
:= New_Reference_To
(RTE
(RE_Null_Address
), Loc
);
4797 Append_To
(Prim_Ops_Aggr_List
, New_Node
);
4802 Append_To
(DT_Aggr_List
,
4803 Make_Aggregate
(Loc
,
4804 Expressions
=> Prim_Ops_Aggr_List
));
4806 -- In case of locally defined tagged types we have already declared
4807 -- and uninitialized object for the dispatch table, which is now
4808 -- initialized by means of an assignment.
4810 if not Building_Static_DT
(Typ
) then
4812 Make_Assignment_Statement
(Loc
,
4813 Name
=> New_Reference_To
(DT
, Loc
),
4814 Expression
=> Make_Aggregate
(Loc
,
4815 Expressions
=> DT_Aggr_List
)));
4817 -- In case of library level tagged types we declare now and export
4818 -- the constant object containing the dispatch table.
4822 Make_Object_Declaration
(Loc
,
4823 Defining_Identifier
=> DT
,
4824 Aliased_Present
=> True,
4825 Constant_Present
=> True,
4826 Object_Definition
=>
4827 Make_Subtype_Indication
(Loc
,
4828 Subtype_Mark
=> New_Reference_To
4829 (RTE
(RE_Dispatch_Table_Wrapper
), Loc
),
4830 Constraint
=> Make_Index_Or_Discriminant_Constraint
(Loc
,
4831 Constraints
=> DT_Constr_List
)),
4832 Expression
=> Make_Aggregate
(Loc
,
4833 Expressions
=> DT_Aggr_List
)));
4836 Make_Attribute_Definition_Clause
(Loc
,
4837 Name
=> New_Reference_To
(DT
, Loc
),
4838 Chars
=> Name_Alignment
,
4840 Make_Attribute_Reference
(Loc
,
4842 New_Reference_To
(RTE
(RE_Integer_Address
), Loc
),
4843 Attribute_Name
=> Name_Alignment
)));
4845 Export_DT
(Typ
, DT
);
4849 -- Initialize the table of ancestor tags
4851 if not Building_Static_DT
(Typ
)
4852 and then not Is_Interface
(Typ
)
4853 and then not Is_CPP_Class
(Typ
)
4856 Make_Assignment_Statement
(Loc
,
4858 Make_Indexed_Component
(Loc
,
4860 Make_Selected_Component
(Loc
,
4862 New_Reference_To
(TSD
, Loc
),
4865 (RTE_Record_Component
(RE_Tags_Table
), Loc
)),
4867 New_List
(Make_Integer_Literal
(Loc
, 0))),
4871 (Node
(First_Elmt
(Access_Disp_Table
(Typ
))), Loc
)));
4874 if Building_Static_DT
(Typ
) then
4877 -- If the ancestor is a CPP_Class type we inherit the dispatch tables
4878 -- in the init proc, and we don't need to fill them in here.
4880 elsif Is_CPP_Class
(Etype
(Typ
)) then
4883 -- Otherwise we fill in the dispatch tables here
4886 if Typ
= Etype
(Typ
)
4887 or else Is_CPP_Class
(Etype
(Typ
))
4888 or else Is_Interface
(Typ
)
4890 Null_Parent_Tag
:= True;
4893 Unchecked_Convert_To
(RTE
(RE_Tag
),
4894 Make_Integer_Literal
(Loc
, 0));
4896 Unchecked_Convert_To
(RTE
(RE_Tag
),
4897 Make_Integer_Literal
(Loc
, 0));
4902 (Node
(First_Elmt
(Access_Disp_Table
(Etype
(Typ
)))), Loc
);
4905 (Node
(First_Elmt
(Access_Disp_Table
(Etype
(Typ
)))), Loc
);
4908 if Typ
/= Etype
(Typ
)
4909 and then not Is_Interface
(Typ
)
4910 and then not Restriction_Active
(No_Dispatching_Calls
)
4912 -- Inherit the dispatch table
4914 if not Is_Interface
(Etype
(Typ
)) then
4915 if not Null_Parent_Tag
then
4917 Nb_Prims
: constant Int
:=
4918 UI_To_Int
(DT_Entry_Count
4919 (First_Tag_Component
(Etype
(Typ
))));
4921 Append_To
(Elab_Code
,
4922 Build_Inherit_Predefined_Prims
(Loc
,
4923 Old_Tag_Node
=> Old_Tag1
,
4925 New_Reference_To
(DT_Ptr
, Loc
)));
4927 if Nb_Prims
/= 0 then
4928 Append_To
(Elab_Code
,
4929 Build_Inherit_Prims
(Loc
,
4931 Old_Tag_Node
=> Old_Tag2
,
4932 New_Tag_Node
=> New_Reference_To
(DT_Ptr
, Loc
),
4933 Num_Prims
=> Nb_Prims
));
4939 -- Inherit the secondary dispatch tables of the ancestor
4941 if not Is_CPP_Class
(Etype
(Typ
)) then
4943 Sec_DT_Ancestor
: Elmt_Id
:=
4946 (Access_Disp_Table
(Etype
(Typ
))));
4947 Sec_DT_Typ
: Elmt_Id
:=
4950 (Access_Disp_Table
(Typ
)));
4952 procedure Copy_Secondary_DTs
(Typ
: Entity_Id
);
4953 -- Local procedure required to climb through the ancestors
4954 -- and copy the contents of all their secondary dispatch
4957 ------------------------
4958 -- Copy_Secondary_DTs --
4959 ------------------------
4961 procedure Copy_Secondary_DTs
(Typ
: Entity_Id
) is
4966 -- Climb to the ancestor (if any) handling private types
4968 if Present
(Full_View
(Etype
(Typ
))) then
4969 if Full_View
(Etype
(Typ
)) /= Typ
then
4970 Copy_Secondary_DTs
(Full_View
(Etype
(Typ
)));
4973 elsif Etype
(Typ
) /= Typ
then
4974 Copy_Secondary_DTs
(Etype
(Typ
));
4977 if Present
(Abstract_Interfaces
(Typ
))
4978 and then not Is_Empty_Elmt_List
4979 (Abstract_Interfaces
(Typ
))
4981 Iface
:= First_Elmt
(Abstract_Interfaces
(Typ
));
4982 E
:= First_Entity
(Typ
);
4984 and then Present
(Node
(Sec_DT_Ancestor
))
4985 and then Ekind
(Node
(Sec_DT_Ancestor
)) = E_Constant
4987 if Is_Tag
(E
) and then Chars
(E
) /= Name_uTag
then
4989 Num_Prims
: constant Int
:=
4990 UI_To_Int
(DT_Entry_Count
(E
));
4993 if not Is_Interface
(Etype
(Typ
)) then
4995 -- Inherit first secondary dispatch table
4997 Append_To
(Elab_Code
,
4998 Build_Inherit_Predefined_Prims
(Loc
,
5000 Unchecked_Convert_To
(RTE
(RE_Tag
),
5002 (Node
(Sec_DT_Ancestor
), Loc
)),
5004 Unchecked_Convert_To
(RTE
(RE_Tag
),
5006 (Node
(Sec_DT_Typ
), Loc
))));
5008 if Num_Prims
/= 0 then
5009 Append_To
(Elab_Code
,
5010 Build_Inherit_Prims
(Loc
,
5011 Typ
=> Node
(Iface
),
5013 Unchecked_Convert_To
5016 (Node
(Sec_DT_Ancestor
),
5019 Unchecked_Convert_To
5022 (Node
(Sec_DT_Typ
), Loc
)),
5023 Num_Prims
=> Num_Prims
));
5027 Next_Elmt
(Sec_DT_Ancestor
);
5028 Next_Elmt
(Sec_DT_Typ
);
5030 if not Is_Interface
(Etype
(Typ
)) then
5032 -- Inherit second secondary dispatch table
5034 Append_To
(Elab_Code
,
5035 Build_Inherit_Predefined_Prims
(Loc
,
5037 Unchecked_Convert_To
(RTE
(RE_Tag
),
5039 (Node
(Sec_DT_Ancestor
), Loc
)),
5041 Unchecked_Convert_To
(RTE
(RE_Tag
),
5043 (Node
(Sec_DT_Typ
), Loc
))));
5045 if Num_Prims
/= 0 then
5046 Append_To
(Elab_Code
,
5047 Build_Inherit_Prims
(Loc
,
5048 Typ
=> Node
(Iface
),
5050 Unchecked_Convert_To
5053 (Node
(Sec_DT_Ancestor
),
5056 Unchecked_Convert_To
5059 (Node
(Sec_DT_Typ
), Loc
)),
5060 Num_Prims
=> Num_Prims
));
5065 Next_Elmt
(Sec_DT_Ancestor
);
5066 Next_Elmt
(Sec_DT_Typ
);
5073 end Copy_Secondary_DTs
;
5076 if Present
(Node
(Sec_DT_Ancestor
))
5077 and then Ekind
(Node
(Sec_DT_Ancestor
)) = E_Constant
5079 -- Handle private types
5081 if Present
(Full_View
(Typ
)) then
5082 Copy_Secondary_DTs
(Full_View
(Typ
));
5084 Copy_Secondary_DTs
(Typ
);
5092 -- Generate code to register the Tag in the External_Tag hash table for
5093 -- the pure Ada type only.
5095 -- Register_Tag (Dt_Ptr);
5097 -- Skip this action in the following cases:
5098 -- 1) if Register_Tag is not available.
5099 -- 2) in No_Run_Time mode.
5100 -- 3) if Typ is an abstract interface type (the secondary tags will
5101 -- be registered later in types implementing this interface type).
5102 -- 4) if Typ is not defined at the library level (this is required
5103 -- to avoid adding concurrency control to the hash table used
5104 -- by the run-time to register the tags).
5109 -- [ Register_Tag (Dt_Ptr); ]
5113 if not No_Run_Time_Mode
5114 and then Is_Library_Level_Entity
(Typ
)
5115 and then RTE_Available
(RE_Register_Tag
)
5117 Append_To
(Elab_Code
,
5118 Make_Procedure_Call_Statement
(Loc
,
5119 Name
=> New_Reference_To
(RTE
(RE_Register_Tag
), Loc
),
5120 Parameter_Associations
=>
5121 New_List
(New_Reference_To
(DT_Ptr
, Loc
))));
5124 Append_To
(Elab_Code
,
5125 Make_Assignment_Statement
(Loc
,
5126 Name
=> New_Reference_To
(No_Reg
, Loc
),
5127 Expression
=> New_Reference_To
(Standard_False
, Loc
)));
5130 Make_Implicit_If_Statement
(Typ
,
5131 Condition
=> New_Reference_To
(No_Reg
, Loc
),
5132 Then_Statements
=> Elab_Code
));
5134 -- Populate the two auxiliary tables used for dispatching
5135 -- asynchronous, conditional and timed selects for synchronized
5136 -- types that implement a limited interface.
5138 if Ada_Version
>= Ada_05
5139 and then Is_Concurrent_Record_Type
(Typ
)
5140 and then Has_Abstract_Interfaces
(Typ
)
5142 Append_List_To
(Result
,
5143 Make_Select_Specific_Data_Table
(Typ
));
5146 Analyze_List
(Result
, Suppress
=> All_Checks
);
5147 Set_Has_Dispatch_Table
(Typ
);
5152 -------------------------------------
5153 -- Make_Select_Specific_Data_Table --
5154 -------------------------------------
5156 function Make_Select_Specific_Data_Table
5157 (Typ
: Entity_Id
) return List_Id
5159 Assignments
: constant List_Id
:= New_List
;
5160 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
5162 Conc_Typ
: Entity_Id
;
5166 Prim_Als
: Entity_Id
;
5167 Prim_Elmt
: Elmt_Id
;
5171 type Examined_Array
is array (Int
range <>) of Boolean;
5173 function Find_Entry_Index
(E
: Entity_Id
) return Uint
;
5174 -- Given an entry, find its index in the visible declarations of the
5175 -- corresponding concurrent type of Typ.
5177 ----------------------
5178 -- Find_Entry_Index --
5179 ----------------------
5181 function Find_Entry_Index
(E
: Entity_Id
) return Uint
is
5182 Index
: Uint
:= Uint_1
;
5183 Subp_Decl
: Entity_Id
;
5187 and then not Is_Empty_List
(Decls
)
5189 Subp_Decl
:= First
(Decls
);
5190 while Present
(Subp_Decl
) loop
5191 if Nkind
(Subp_Decl
) = N_Entry_Declaration
then
5192 if Defining_Identifier
(Subp_Decl
) = E
then
5204 end Find_Entry_Index
;
5206 -- Start of processing for Make_Select_Specific_Data_Table
5209 pragma Assert
(not Restriction_Active
(No_Dispatching_Calls
));
5211 DT_Ptr
:= Node
(First_Elmt
(Access_Disp_Table
(Typ
)));
5213 if Present
(Corresponding_Concurrent_Type
(Typ
)) then
5214 Conc_Typ
:= Corresponding_Concurrent_Type
(Typ
);
5216 if Present
(Full_View
(Conc_Typ
)) then
5217 Conc_Typ
:= Full_View
(Conc_Typ
);
5220 if Ekind
(Conc_Typ
) = E_Protected_Type
then
5221 Decls
:= Visible_Declarations
(Protected_Definition
(
5222 Parent
(Conc_Typ
)));
5224 pragma Assert
(Ekind
(Conc_Typ
) = E_Task_Type
);
5225 Decls
:= Visible_Declarations
(Task_Definition
(
5226 Parent
(Conc_Typ
)));
5230 -- Count the non-predefined primitive operations
5232 Prim_Elmt
:= First_Elmt
(Primitive_Operations
(Typ
));
5233 while Present
(Prim_Elmt
) loop
5234 Prim
:= Node
(Prim_Elmt
);
5236 if not (Is_Predefined_Dispatching_Operation
(Prim
)
5237 or else Is_Predefined_Dispatching_Alias
(Prim
))
5239 Nb_Prim
:= Nb_Prim
+ 1;
5242 Next_Elmt
(Prim_Elmt
);
5246 Examined
: Examined_Array
(1 .. Nb_Prim
) := (others => False);
5249 Prim_Elmt
:= First_Elmt
(Primitive_Operations
(Typ
));
5250 while Present
(Prim_Elmt
) loop
5251 Prim
:= Node
(Prim_Elmt
);
5253 -- Look for primitive overriding an abstract interface subprogram
5255 if Present
(Abstract_Interface_Alias
(Prim
))
5256 and then not Examined
(UI_To_Int
(DT_Position
(Alias
(Prim
))))
5258 Prim_Pos
:= DT_Position
(Alias
(Prim
));
5259 pragma Assert
(UI_To_Int
(Prim_Pos
) <= Nb_Prim
);
5260 Examined
(UI_To_Int
(Prim_Pos
)) := True;
5262 -- Set the primitive operation kind regardless of subprogram
5264 -- Ada.Tags.Set_Prim_Op_Kind (DT_Ptr, <position>, <kind>);
5266 Append_To
(Assignments
,
5267 Make_Procedure_Call_Statement
(Loc
,
5268 Name
=> New_Reference_To
(RTE
(RE_Set_Prim_Op_Kind
), Loc
),
5269 Parameter_Associations
=> New_List
(
5270 New_Reference_To
(DT_Ptr
, Loc
),
5271 Make_Integer_Literal
(Loc
, Prim_Pos
),
5272 Prim_Op_Kind
(Alias
(Prim
), Typ
))));
5274 -- Retrieve the root of the alias chain
5277 while Present
(Alias
(Prim_Als
)) loop
5278 Prim_Als
:= Alias
(Prim_Als
);
5281 -- In the case of an entry wrapper, set the entry index
5283 if Ekind
(Prim
) = E_Procedure
5284 and then Is_Primitive_Wrapper
(Prim_Als
)
5285 and then Ekind
(Wrapped_Entity
(Prim_Als
)) = E_Entry
5288 -- Ada.Tags.Set_Entry_Index
5289 -- (DT_Ptr, <position>, <index>);
5291 Append_To
(Assignments
,
5292 Make_Procedure_Call_Statement
(Loc
,
5294 New_Reference_To
(RTE
(RE_Set_Entry_Index
), Loc
),
5295 Parameter_Associations
=> New_List
(
5296 New_Reference_To
(DT_Ptr
, Loc
),
5297 Make_Integer_Literal
(Loc
, Prim_Pos
),
5298 Make_Integer_Literal
(Loc
,
5299 Find_Entry_Index
(Wrapped_Entity
(Prim_Als
))))));
5303 Next_Elmt
(Prim_Elmt
);
5308 end Make_Select_Specific_Data_Table
;
5314 function Make_Tags
(Typ
: Entity_Id
) return List_Id
is
5315 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
5316 Tname
: constant Name_Id
:= Chars
(Typ
);
5317 Result
: constant List_Id
:= New_List
;
5318 AI_Tag_Comp
: Elmt_Id
;
5320 DT_Constr_List
: List_Id
;
5322 Iface_DT_Ptr
: Node_Id
;
5326 Typ_Comps
: Elist_Id
;
5329 -- 1) Generate the primary and secondary tag entities
5331 -- Collect the components associated with secondary dispatch tables
5333 if Has_Abstract_Interfaces
(Typ
) then
5334 Collect_Interface_Components
(Typ
, Typ_Comps
);
5337 -- 1) Generate the primary tag entity
5339 DT_Ptr
:= Make_Defining_Identifier
(Loc
,
5340 New_External_Name
(Tname
, 'P'));
5341 Set_Etype
(DT_Ptr
, RTE
(RE_Tag
));
5343 -- Import the forward declaration of the Dispatch Table wrapper record
5344 -- (Make_DT will take care of its exportation)
5346 if Building_Static_DT
(Typ
) then
5347 DT
:= Make_Defining_Identifier
(Loc
,
5348 New_External_Name
(Tname
, 'T'));
5351 -- DT : static aliased constant Dispatch_Table_Wrapper (Nb_Prim);
5352 -- $pragma import (ada, DT);
5354 Set_Is_Imported
(DT
);
5356 -- The scope must be set now to call Get_External_Name
5358 Set_Scope
(DT
, Current_Scope
);
5360 Get_External_Name
(DT
, True);
5361 Set_Interface_Name
(DT
,
5362 Make_String_Literal
(Loc
,
5363 Strval
=> String_From_Name_Buffer
));
5365 -- Ensure proper Sprint output of this implicit importation
5367 Set_Is_Internal
(DT
);
5369 -- Save this entity to allow Make_DT to generate its exportation
5371 Set_Dispatch_Table_Wrapper
(Typ
, DT
);
5373 if Has_DT
(Typ
) then
5374 -- Calculate the number of primitives of the dispatch table and
5375 -- the size of the Type_Specific_Data record.
5377 Nb_Prim
:= UI_To_Int
(DT_Entry_Count
(First_Tag_Component
(Typ
)));
5379 -- If the tagged type has no primitives we add a dummy slot
5380 -- whose address will be the tag of this type.
5384 New_List
(Make_Integer_Literal
(Loc
, 1));
5387 New_List
(Make_Integer_Literal
(Loc
, Nb_Prim
));
5391 Make_Object_Declaration
(Loc
,
5392 Defining_Identifier
=> DT
,
5393 Aliased_Present
=> True,
5394 Constant_Present
=> True,
5395 Object_Definition
=>
5396 Make_Subtype_Indication
(Loc
,
5398 New_Reference_To
(RTE
(RE_Dispatch_Table_Wrapper
), Loc
),
5399 Constraint
=> Make_Index_Or_Discriminant_Constraint
(Loc
,
5400 Constraints
=> DT_Constr_List
))));
5403 Make_Object_Declaration
(Loc
,
5404 Defining_Identifier
=> DT_Ptr
,
5405 Constant_Present
=> True,
5406 Object_Definition
=> New_Reference_To
(RTE
(RE_Tag
), Loc
),
5408 Unchecked_Convert_To
(RTE
(RE_Tag
),
5409 Make_Attribute_Reference
(Loc
,
5411 Make_Selected_Component
(Loc
,
5412 Prefix
=> New_Reference_To
(DT
, Loc
),
5415 (RTE_Record_Component
(RE_Prims_Ptr
), Loc
)),
5416 Attribute_Name
=> Name_Address
))));
5418 -- No dispatch table required
5422 Make_Object_Declaration
(Loc
,
5423 Defining_Identifier
=> DT
,
5424 Aliased_Present
=> True,
5425 Constant_Present
=> True,
5426 Object_Definition
=>
5427 New_Reference_To
(RTE
(RE_No_Dispatch_Table_Wrapper
), Loc
)));
5430 Make_Object_Declaration
(Loc
,
5431 Defining_Identifier
=> DT_Ptr
,
5432 Constant_Present
=> True,
5433 Object_Definition
=> New_Reference_To
(RTE
(RE_Tag
), Loc
),
5435 Unchecked_Convert_To
(RTE
(RE_Tag
),
5436 Make_Attribute_Reference
(Loc
,
5438 Make_Selected_Component
(Loc
,
5439 Prefix
=> New_Reference_To
(DT
, Loc
),
5442 (RTE_Record_Component
(RE_NDT_Prims_Ptr
), Loc
)),
5443 Attribute_Name
=> Name_Address
))));
5446 Set_Is_True_Constant
(DT_Ptr
);
5447 Set_Is_Statically_Allocated
(DT_Ptr
);
5450 pragma Assert
(No
(Access_Disp_Table
(Typ
)));
5451 Set_Access_Disp_Table
(Typ
, New_Elmt_List
);
5452 Append_Elmt
(DT_Ptr
, Access_Disp_Table
(Typ
));
5454 -- 2) Generate the secondary tag entities
5456 if Has_Abstract_Interfaces
(Typ
) then
5459 -- For each interface type we build an unique external name
5460 -- associated with its corresponding secondary dispatch table.
5461 -- This external name will be used to declare an object that
5462 -- references this secondary dispatch table, value that will be
5463 -- used for the elaboration of Typ's objects and also for the
5464 -- elaboration of objects of derivations of Typ that do not
5465 -- override the primitive operation of this interface type.
5467 AI_Tag_Comp
:= First_Elmt
(Typ_Comps
);
5468 while Present
(AI_Tag_Comp
) loop
5469 Get_Secondary_DT_External_Name
5470 (Typ
, Related_Type
(Node
(AI_Tag_Comp
)), Suffix_Index
);
5472 Typ_Name
:= Name_Find
;
5475 Make_Defining_Identifier
(Loc
,
5476 Chars
=> New_External_Name
(Typ_Name
, 'P'));
5477 Set_Etype
(Iface_DT_Ptr
, RTE
(RE_Interface_Tag
));
5478 Set_Ekind
(Iface_DT_Ptr
, E_Constant
);
5479 Set_Is_Tag
(Iface_DT_Ptr
);
5480 Set_Has_Thunks
(Iface_DT_Ptr
);
5481 Set_Is_Statically_Allocated
(Iface_DT_Ptr
);
5482 Set_Is_True_Constant
(Iface_DT_Ptr
);
5484 (Iface_DT_Ptr
, Related_Type
(Node
(AI_Tag_Comp
)));
5485 Append_Elmt
(Iface_DT_Ptr
, Access_Disp_Table
(Typ
));
5488 Make_Defining_Identifier
(Loc
,
5489 Chars
=> New_External_Name
(Typ_Name
, 'D'));
5490 Set_Etype
(Iface_DT_Ptr
, RTE
(RE_Interface_Tag
));
5491 Set_Ekind
(Iface_DT_Ptr
, E_Constant
);
5492 Set_Is_Tag
(Iface_DT_Ptr
);
5493 Set_Is_Statically_Allocated
(Iface_DT_Ptr
);
5494 Set_Is_True_Constant
(Iface_DT_Ptr
);
5496 (Iface_DT_Ptr
, Related_Type
(Node
(AI_Tag_Comp
)));
5497 Append_Elmt
(Iface_DT_Ptr
, Access_Disp_Table
(Typ
));
5499 Next_Elmt
(AI_Tag_Comp
);
5503 -- 3) At the end of Access_Disp_Table we add the entity of an access
5504 -- type declaration. It is used by Build_Get_Prim_Op_Address to
5505 -- expand dispatching calls through the primary dispatch table.
5508 -- type Typ_DT is array (1 .. Nb_Prims) of Address;
5509 -- type Typ_DT_Acc is access Typ_DT;
5512 Name_DT_Prims
: constant Name_Id
:=
5513 New_External_Name
(Tname
, 'G');
5514 Name_DT_Prims_Acc
: constant Name_Id
:=
5515 New_External_Name
(Tname
, 'H');
5516 DT_Prims
: constant Entity_Id
:=
5517 Make_Defining_Identifier
(Loc
, Name_DT_Prims
);
5518 DT_Prims_Acc
: constant Entity_Id
:=
5519 Make_Defining_Identifier
(Loc
,
5523 Make_Full_Type_Declaration
(Loc
,
5524 Defining_Identifier
=> DT_Prims
,
5526 Make_Constrained_Array_Definition
(Loc
,
5527 Discrete_Subtype_Definitions
=> New_List
(
5529 Low_Bound
=> Make_Integer_Literal
(Loc
, 1),
5530 High_Bound
=> Make_Integer_Literal
(Loc
,
5532 (First_Tag_Component
(Typ
))))),
5533 Component_Definition
=>
5534 Make_Component_Definition
(Loc
,
5535 Subtype_Indication
=>
5536 New_Reference_To
(RTE
(RE_Address
), Loc
)))));
5539 Make_Full_Type_Declaration
(Loc
,
5540 Defining_Identifier
=> DT_Prims_Acc
,
5542 Make_Access_To_Object_Definition
(Loc
,
5543 Subtype_Indication
=>
5544 New_Occurrence_Of
(DT_Prims
, Loc
))));
5546 Append_Elmt
(DT_Prims_Acc
, Access_Disp_Table
(Typ
));
5548 -- Analyze the resulting list and suppress the generation of the
5549 -- Init_Proc associated with the above array declaration because
5550 -- we never use such type in object declarations; this type is only
5551 -- used to simplify the expansion associated with dispatching calls.
5553 Analyze_List
(Result
);
5554 Set_Suppress_Init_Proc
(Base_Type
(DT_Prims
));
5557 Set_Ekind
(DT_Ptr
, E_Constant
);
5558 Set_Is_Tag
(DT_Ptr
);
5559 Set_Related_Type
(DT_Ptr
, Typ
);
5564 -----------------------------------
5565 -- Original_View_In_Visible_Part --
5566 -----------------------------------
5568 function Original_View_In_Visible_Part
(Typ
: Entity_Id
) return Boolean is
5569 Scop
: constant Entity_Id
:= Scope
(Typ
);
5572 -- The scope must be a package
5574 if Ekind
(Scop
) /= E_Package
5575 and then Ekind
(Scop
) /= E_Generic_Package
5580 -- A type with a private declaration has a private view declared in
5581 -- the visible part.
5583 if Has_Private_Declaration
(Typ
) then
5587 return List_Containing
(Parent
(Typ
)) =
5588 Visible_Declarations
(Specification
(Unit_Declaration_Node
(Scop
)));
5589 end Original_View_In_Visible_Part
;
5595 function Prim_Op_Kind
5597 Typ
: Entity_Id
) return Node_Id
5599 Full_Typ
: Entity_Id
:= Typ
;
5600 Loc
: constant Source_Ptr
:= Sloc
(Prim
);
5601 Prim_Op
: Entity_Id
;
5604 -- Retrieve the original primitive operation
5607 while Present
(Alias
(Prim_Op
)) loop
5608 Prim_Op
:= Alias
(Prim_Op
);
5611 if Ekind
(Typ
) = E_Record_Type
5612 and then Present
(Corresponding_Concurrent_Type
(Typ
))
5614 Full_Typ
:= Corresponding_Concurrent_Type
(Typ
);
5617 if Ekind
(Prim_Op
) = E_Function
then
5619 -- Protected function
5621 if Ekind
(Full_Typ
) = E_Protected_Type
then
5622 return New_Reference_To
(RTE
(RE_POK_Protected_Function
), Loc
);
5626 elsif Ekind
(Full_Typ
) = E_Task_Type
then
5627 return New_Reference_To
(RTE
(RE_POK_Task_Function
), Loc
);
5632 return New_Reference_To
(RTE
(RE_POK_Function
), Loc
);
5636 pragma Assert
(Ekind
(Prim_Op
) = E_Procedure
);
5638 if Ekind
(Full_Typ
) = E_Protected_Type
then
5642 if Is_Primitive_Wrapper
(Prim_Op
)
5643 and then Ekind
(Wrapped_Entity
(Prim_Op
)) = E_Entry
5645 return New_Reference_To
(RTE
(RE_POK_Protected_Entry
), Loc
);
5647 -- Protected procedure
5650 return New_Reference_To
(RTE
(RE_POK_Protected_Procedure
), Loc
);
5653 elsif Ekind
(Full_Typ
) = E_Task_Type
then
5657 if Is_Primitive_Wrapper
(Prim_Op
)
5658 and then Ekind
(Wrapped_Entity
(Prim_Op
)) = E_Entry
5660 return New_Reference_To
(RTE
(RE_POK_Task_Entry
), Loc
);
5662 -- Task "procedure". These are the internally Expander-generated
5663 -- procedures (task body for instance).
5666 return New_Reference_To
(RTE
(RE_POK_Task_Procedure
), Loc
);
5669 -- Regular procedure
5672 return New_Reference_To
(RTE
(RE_POK_Procedure
), Loc
);
5677 ------------------------
5678 -- Register_Primitive --
5679 ------------------------
5681 procedure Register_Primitive
5687 Iface_Prim
: Entity_Id
;
5688 Iface_Typ
: Entity_Id
;
5689 Iface_DT_Ptr
: Entity_Id
;
5690 Iface_DT_Elmt
: Elmt_Id
;
5694 Thunk_Id
: Entity_Id
;
5695 Thunk_Code
: Node_Id
;
5699 pragma Assert
(not Restriction_Active
(No_Dispatching_Calls
));
5701 if not RTE_Available
(RE_Tag
) then
5705 if not Present
(Abstract_Interface_Alias
(Prim
)) then
5706 Typ
:= Scope
(DTC_Entity
(Prim
));
5707 DT_Ptr
:= Node
(First_Elmt
(Access_Disp_Table
(Typ
)));
5708 Pos
:= DT_Position
(Prim
);
5709 Tag
:= First_Tag_Component
(Typ
);
5711 if Is_Predefined_Dispatching_Operation
(Prim
)
5712 or else Is_Predefined_Dispatching_Alias
(Prim
)
5714 Insert_After
(Ins_Nod
,
5715 Build_Set_Predefined_Prim_Op_Address
(Loc
,
5716 Tag_Node
=> New_Reference_To
(DT_Ptr
, Loc
),
5718 Address_Node
=> Make_Attribute_Reference
(Loc
,
5719 Prefix
=> New_Reference_To
(Prim
, Loc
),
5720 Attribute_Name
=> Name_Address
)));
5723 pragma Assert
(Pos
/= Uint_0
and then Pos
<= DT_Entry_Count
(Tag
));
5725 Insert_After
(Ins_Nod
,
5726 Build_Set_Prim_Op_Address
(Loc
,
5728 Tag_Node
=> New_Reference_To
(DT_Ptr
, Loc
),
5730 Address_Node
=> Make_Attribute_Reference
(Loc
,
5731 Prefix
=> New_Reference_To
(Prim
, Loc
),
5732 Attribute_Name
=> Name_Address
)));
5735 -- Ada 2005 (AI-251): Primitive associated with an interface type
5736 -- Generate the code of the thunk only if the interface type is not an
5737 -- immediate ancestor of Typ; otherwise the dispatch table associated
5738 -- with the interface is the primary dispatch table and we have nothing
5742 Typ
:= Find_Dispatching_Type
(Alias
(Prim
));
5743 Iface_Typ
:= Find_Dispatching_Type
(Abstract_Interface_Alias
(Prim
));
5745 pragma Assert
(Is_Interface
(Iface_Typ
));
5747 Expand_Interface_Thunk
(Prim
, Thunk_Id
, Thunk_Code
);
5749 if not Is_Parent
(Iface_Typ
, Typ
)
5750 and then Present
(Thunk_Code
)
5752 -- Comment needed on why checks are suppressed. This is not just
5753 -- efficiency, but fundamental functionality (see 1.295 RH, which
5754 -- still does not answer this question) ???
5756 Insert_Action
(Ins_Nod
, Thunk_Code
, Suppress
=> All_Checks
);
5758 -- Generate the code necessary to fill the appropriate entry of
5759 -- the secondary dispatch table of Prim's controlling type with
5760 -- Thunk_Id's address.
5762 Iface_DT_Elmt
:= Find_Interface_ADT
(Typ
, Iface_Typ
);
5763 Iface_DT_Ptr
:= Node
(Iface_DT_Elmt
);
5764 pragma Assert
(Has_Thunks
(Iface_DT_Ptr
));
5766 Iface_Prim
:= Abstract_Interface_Alias
(Prim
);
5767 Pos
:= DT_Position
(Iface_Prim
);
5768 Tag
:= First_Tag_Component
(Iface_Typ
);
5771 if Is_Predefined_Dispatching_Operation
(Prim
)
5772 or else Is_Predefined_Dispatching_Alias
(Prim
)
5775 Build_Set_Predefined_Prim_Op_Address
(Loc
,
5776 Tag_Node
=> New_Reference_To
(Iface_DT_Ptr
, Loc
),
5779 Make_Attribute_Reference
(Loc
,
5780 Prefix
=> New_Reference_To
(Thunk_Id
, Loc
),
5781 Attribute_Name
=> Name_Address
)));
5783 Next_Elmt
(Iface_DT_Elmt
);
5784 Iface_DT_Ptr
:= Node
(Iface_DT_Elmt
);
5785 pragma Assert
(not Has_Thunks
(Iface_DT_Ptr
));
5788 Build_Set_Predefined_Prim_Op_Address
(Loc
,
5789 Tag_Node
=> New_Reference_To
(Iface_DT_Ptr
, Loc
),
5792 Make_Attribute_Reference
(Loc
,
5793 Prefix
=> New_Reference_To
(Alias
(Prim
), Loc
),
5794 Attribute_Name
=> Name_Address
)));
5796 Insert_Actions_After
(Ins_Nod
, L
);
5799 pragma Assert
(Pos
/= Uint_0
5800 and then Pos
<= DT_Entry_Count
(Tag
));
5803 Build_Set_Prim_Op_Address
(Loc
,
5805 Tag_Node
=> New_Reference_To
(Iface_DT_Ptr
, Loc
),
5807 Address_Node
=> Make_Attribute_Reference
(Loc
,
5809 New_Reference_To
(Thunk_Id
, Loc
),
5810 Attribute_Name
=> Name_Address
)));
5812 Next_Elmt
(Iface_DT_Elmt
);
5813 Iface_DT_Ptr
:= Node
(Iface_DT_Elmt
);
5814 pragma Assert
(not Has_Thunks
(Iface_DT_Ptr
));
5817 Build_Set_Prim_Op_Address
(Loc
,
5819 Tag_Node
=> New_Reference_To
(Iface_DT_Ptr
, Loc
),
5821 Address_Node
=> Make_Attribute_Reference
(Loc
,
5823 New_Reference_To
(Alias
(Prim
), Loc
),
5824 Attribute_Name
=> Name_Address
)));
5826 Insert_Actions_After
(Ins_Nod
, L
);
5830 end Register_Primitive
;
5832 -------------------------
5833 -- Set_All_DT_Position --
5834 -------------------------
5836 procedure Set_All_DT_Position
(Typ
: Entity_Id
) is
5838 procedure Validate_Position
(Prim
: Entity_Id
);
5839 -- Check that the position assignated to Prim is completely safe
5840 -- (it has not been assigned to a previously defined primitive
5841 -- operation of Typ)
5843 -----------------------
5844 -- Validate_Position --
5845 -----------------------
5847 procedure Validate_Position
(Prim
: Entity_Id
) is
5852 -- Aliased primitives are safe
5854 if Present
(Alias
(Prim
)) then
5858 Op_Elmt
:= First_Elmt
(Primitive_Operations
(Typ
));
5859 while Present
(Op_Elmt
) loop
5860 Op
:= Node
(Op_Elmt
);
5862 -- No need to check against itself
5867 -- Primitive operations covering abstract interfaces are
5870 elsif Present
(Abstract_Interface_Alias
(Op
)) then
5873 -- Predefined dispatching operations are completely safe. They
5874 -- are allocated at fixed positions in a separate table.
5876 elsif Is_Predefined_Dispatching_Operation
(Op
)
5877 or else Is_Predefined_Dispatching_Alias
(Op
)
5881 -- Aliased subprograms are safe
5883 elsif Present
(Alias
(Op
)) then
5886 elsif DT_Position
(Op
) = DT_Position
(Prim
)
5887 and then not Is_Predefined_Dispatching_Operation
(Op
)
5888 and then not Is_Predefined_Dispatching_Operation
(Prim
)
5889 and then not Is_Predefined_Dispatching_Alias
(Op
)
5890 and then not Is_Predefined_Dispatching_Alias
(Prim
)
5893 -- Handle aliased subprograms
5902 if Present
(Overridden_Operation
(Op_1
)) then
5903 Op_1
:= Overridden_Operation
(Op_1
);
5904 elsif Present
(Alias
(Op_1
)) then
5905 Op_1
:= Alias
(Op_1
);
5913 if Present
(Overridden_Operation
(Op_2
)) then
5914 Op_2
:= Overridden_Operation
(Op_2
);
5915 elsif Present
(Alias
(Op_2
)) then
5916 Op_2
:= Alias
(Op_2
);
5922 if Op_1
/= Op_2
then
5923 raise Program_Error
;
5928 Next_Elmt
(Op_Elmt
);
5930 end Validate_Position
;
5934 Parent_Typ
: constant Entity_Id
:= Etype
(Typ
);
5935 First_Prim
: constant Elmt_Id
:= First_Elmt
(Primitive_Operations
(Typ
));
5936 The_Tag
: constant Entity_Id
:= First_Tag_Component
(Typ
);
5938 Adjusted
: Boolean := False;
5939 Finalized
: Boolean := False;
5945 Prim_Elmt
: Elmt_Id
;
5947 -- Start of processing for Set_All_DT_Position
5950 -- Set the DT_Position for each primitive operation. Perform some
5951 -- sanity checks to avoid to build completely inconsistant dispatch
5954 -- First stage: Set the DTC entity of all the primitive operations
5955 -- This is required to properly read the DT_Position attribute in
5956 -- the latter stages.
5958 Prim_Elmt
:= First_Prim
;
5960 while Present
(Prim_Elmt
) loop
5961 Prim
:= Node
(Prim_Elmt
);
5963 -- Predefined primitives have a separate dispatch table
5965 if not (Is_Predefined_Dispatching_Operation
(Prim
)
5966 or else Is_Predefined_Dispatching_Alias
(Prim
))
5968 Count_Prim
:= Count_Prim
+ 1;
5971 Set_DTC_Entity_Value
(Typ
, Prim
);
5973 -- Clear any previous value of the DT_Position attribute. In this
5974 -- way we ensure that the final position of all the primitives is
5975 -- stablished by the following stages of this algorithm.
5977 Set_DT_Position
(Prim
, No_Uint
);
5979 Next_Elmt
(Prim_Elmt
);
5983 Fixed_Prim
: array (Int
range 0 .. Count_Prim
) of Boolean
5984 := (others => False);
5987 procedure Handle_Inherited_Private_Subprograms
(Typ
: Entity_Id
);
5988 -- Called if Typ is declared in a nested package or a public child
5989 -- package to handle inherited primitives that were inherited by Typ
5990 -- in the visible part, but whose declaration was deferred because
5991 -- the parent operation was private and not visible at that point.
5993 procedure Set_Fixed_Prim
(Pos
: Nat
);
5994 -- Sets to true an element of the Fixed_Prim table to indicate
5995 -- that this entry of the dispatch table of Typ is occupied.
5997 ------------------------------------------
5998 -- Handle_Inherited_Private_Subprograms --
5999 ------------------------------------------
6001 procedure Handle_Inherited_Private_Subprograms
(Typ
: Entity_Id
) is
6004 Op_Elmt_2
: Elmt_Id
;
6005 Prim_Op
: Entity_Id
;
6006 Parent_Subp
: Entity_Id
;
6009 Op_List
:= Primitive_Operations
(Typ
);
6011 Op_Elmt
:= First_Elmt
(Op_List
);
6012 while Present
(Op_Elmt
) loop
6013 Prim_Op
:= Node
(Op_Elmt
);
6015 -- Search primitives that are implicit operations with an
6016 -- internal name whose parent operation has a normal name.
6018 if Present
(Alias
(Prim_Op
))
6019 and then Find_Dispatching_Type
(Alias
(Prim_Op
)) /= Typ
6020 and then not Comes_From_Source
(Prim_Op
)
6021 and then Is_Internal_Name
(Chars
(Prim_Op
))
6022 and then not Is_Internal_Name
(Chars
(Alias
(Prim_Op
)))
6024 Parent_Subp
:= Alias
(Prim_Op
);
6026 -- Check if the type has an explicit overriding for this
6029 Op_Elmt_2
:= Next_Elmt
(Op_Elmt
);
6030 while Present
(Op_Elmt_2
) loop
6031 if Chars
(Node
(Op_Elmt_2
)) = Chars
(Parent_Subp
)
6032 and then Type_Conformant
(Prim_Op
, Node
(Op_Elmt_2
))
6034 Set_DT_Position
(Prim_Op
, DT_Position
(Parent_Subp
));
6035 Set_DT_Position
(Node
(Op_Elmt_2
),
6036 DT_Position
(Parent_Subp
));
6037 Set_Fixed_Prim
(UI_To_Int
(DT_Position
(Prim_Op
)));
6039 goto Next_Primitive
;
6042 Next_Elmt
(Op_Elmt_2
);
6047 Next_Elmt
(Op_Elmt
);
6049 end Handle_Inherited_Private_Subprograms
;
6051 --------------------
6052 -- Set_Fixed_Prim --
6053 --------------------
6055 procedure Set_Fixed_Prim
(Pos
: Nat
) is
6057 pragma Assert
(Pos
>= 0 and then Pos
<= Count_Prim
);
6058 Fixed_Prim
(Pos
) := True;
6060 when Constraint_Error
=>
6061 raise Program_Error
;
6065 -- In case of nested packages and public child package it may be
6066 -- necessary a special management on inherited subprograms so that
6067 -- the dispatch table is properly filled.
6069 if Ekind
(Scope
(Scope
(Typ
))) = E_Package
6070 and then Scope
(Scope
(Typ
)) /= Standard_Standard
6071 and then ((Is_Derived_Type
(Typ
) and then not Is_Private_Type
(Typ
))
6073 (Nkind
(Parent
(Typ
)) = N_Private_Extension_Declaration
6074 and then Is_Generic_Type
(Typ
)))
6075 and then In_Open_Scopes
(Scope
(Etype
(Typ
)))
6076 and then Typ
= Base_Type
(Typ
)
6078 Handle_Inherited_Private_Subprograms
(Typ
);
6081 -- Second stage: Register fixed entries
6084 Prim_Elmt
:= First_Prim
;
6085 while Present
(Prim_Elmt
) loop
6086 Prim
:= Node
(Prim_Elmt
);
6088 -- Predefined primitives have a separate table and all its
6089 -- entries are at predefined fixed positions.
6091 if Is_Predefined_Dispatching_Operation
(Prim
) then
6092 Set_DT_Position
(Prim
, Default_Prim_Op_Position
(Prim
));
6094 elsif Is_Predefined_Dispatching_Alias
(Prim
) then
6096 while Present
(Alias
(E
)) loop
6100 Set_DT_Position
(Prim
, Default_Prim_Op_Position
(E
));
6102 -- Overriding primitives of ancestor abstract interfaces
6104 elsif Present
(Abstract_Interface_Alias
(Prim
))
6106 (Find_Dispatching_Type
6107 (Abstract_Interface_Alias
(Prim
)),
6110 pragma Assert
(DT_Position
(Prim
) = No_Uint
6111 and then Present
(DTC_Entity
6112 (Abstract_Interface_Alias
(Prim
))));
6114 E
:= Abstract_Interface_Alias
(Prim
);
6115 Set_DT_Position
(Prim
, DT_Position
(E
));
6118 (DT_Position
(Alias
(Prim
)) = No_Uint
6119 or else DT_Position
(Alias
(Prim
)) = DT_Position
(E
));
6120 Set_DT_Position
(Alias
(Prim
), DT_Position
(E
));
6121 Set_Fixed_Prim
(UI_To_Int
(DT_Position
(Prim
)));
6123 -- Overriding primitives must use the same entry as the
6124 -- overriden primitive.
6126 elsif not Present
(Abstract_Interface_Alias
(Prim
))
6127 and then Present
(Alias
(Prim
))
6128 and then Chars
(Prim
) = Chars
(Alias
(Prim
))
6129 and then Find_Dispatching_Type
(Alias
(Prim
)) /= Typ
6131 (Find_Dispatching_Type
(Alias
(Prim
)), Typ
)
6132 and then Present
(DTC_Entity
(Alias
(Prim
)))
6135 Set_DT_Position
(Prim
, DT_Position
(E
));
6137 if not Is_Predefined_Dispatching_Alias
(E
) then
6138 Set_Fixed_Prim
(UI_To_Int
(DT_Position
(E
)));
6142 Next_Elmt
(Prim_Elmt
);
6145 -- Third stage: Fix the position of all the new primitives
6146 -- Entries associated with primitives covering interfaces
6147 -- are handled in a latter round.
6149 Prim_Elmt
:= First_Prim
;
6150 while Present
(Prim_Elmt
) loop
6151 Prim
:= Node
(Prim_Elmt
);
6153 -- Skip primitives previously set entries
6155 if DT_Position
(Prim
) /= No_Uint
then
6158 -- Primitives covering interface primitives are handled later
6160 elsif Present
(Abstract_Interface_Alias
(Prim
)) then
6164 -- Take the next available position in the DT
6167 Nb_Prim
:= Nb_Prim
+ 1;
6168 pragma Assert
(Nb_Prim
<= Count_Prim
);
6169 exit when not Fixed_Prim
(Nb_Prim
);
6172 Set_DT_Position
(Prim
, UI_From_Int
(Nb_Prim
));
6173 Set_Fixed_Prim
(Nb_Prim
);
6176 Next_Elmt
(Prim_Elmt
);
6180 -- Fourth stage: Complete the decoration of primitives covering
6181 -- interfaces (that is, propagate the DT_Position attribute
6182 -- from the aliased primitive)
6184 Prim_Elmt
:= First_Prim
;
6185 while Present
(Prim_Elmt
) loop
6186 Prim
:= Node
(Prim_Elmt
);
6188 if DT_Position
(Prim
) = No_Uint
6189 and then Present
(Abstract_Interface_Alias
(Prim
))
6191 pragma Assert
(Present
(Alias
(Prim
))
6192 and then Find_Dispatching_Type
(Alias
(Prim
)) = Typ
);
6194 -- Check if this entry will be placed in the primary DT
6196 if Is_Parent
(Find_Dispatching_Type
6197 (Abstract_Interface_Alias
(Prim
)),
6200 pragma Assert
(DT_Position
(Alias
(Prim
)) /= No_Uint
);
6201 Set_DT_Position
(Prim
, DT_Position
(Alias
(Prim
)));
6203 -- Otherwise it will be placed in the secondary DT
6207 (DT_Position
(Abstract_Interface_Alias
(Prim
)) /= No_Uint
);
6208 Set_DT_Position
(Prim
,
6209 DT_Position
(Abstract_Interface_Alias
(Prim
)));
6213 Next_Elmt
(Prim_Elmt
);
6216 -- Generate listing showing the contents of the dispatch tables.
6217 -- This action is done before some further static checks because
6218 -- in case of critical errors caused by a wrong dispatch table
6219 -- we need to see the contents of such table.
6221 if Debug_Flag_ZZ
then
6225 -- Final stage: Ensure that the table is correct plus some further
6226 -- verifications concerning the primitives.
6228 Prim_Elmt
:= First_Prim
;
6230 while Present
(Prim_Elmt
) loop
6231 Prim
:= Node
(Prim_Elmt
);
6233 -- At this point all the primitives MUST have a position
6234 -- in the dispatch table
6236 if DT_Position
(Prim
) = No_Uint
then
6237 raise Program_Error
;
6240 -- Calculate real size of the dispatch table
6242 if not (Is_Predefined_Dispatching_Operation
(Prim
)
6243 or else Is_Predefined_Dispatching_Alias
(Prim
))
6244 and then UI_To_Int
(DT_Position
(Prim
)) > DT_Length
6246 DT_Length
:= UI_To_Int
(DT_Position
(Prim
));
6249 -- Ensure that the asignated position to non-predefined
6250 -- dispatching operations in the dispatch table is correct.
6252 if not (Is_Predefined_Dispatching_Operation
(Prim
)
6253 or else Is_Predefined_Dispatching_Alias
(Prim
))
6255 Validate_Position
(Prim
);
6258 if Chars
(Prim
) = Name_Finalize
then
6262 if Chars
(Prim
) = Name_Adjust
then
6266 -- An abstract operation cannot be declared in the private part
6267 -- for a visible abstract type, because it could never be over-
6268 -- ridden. For explicit declarations this is checked at the
6269 -- point of declaration, but for inherited operations it must
6270 -- be done when building the dispatch table.
6272 -- Ada 2005 (AI-251): Hidden entities associated with abstract
6273 -- interface primitives are not taken into account because the
6274 -- check is done with the aliased primitive.
6276 if Is_Abstract_Type
(Typ
)
6277 and then Is_Abstract_Subprogram
(Prim
)
6278 and then Present
(Alias
(Prim
))
6279 and then not Present
(Abstract_Interface_Alias
(Prim
))
6280 and then Is_Derived_Type
(Typ
)
6281 and then In_Private_Part
(Current_Scope
)
6283 List_Containing
(Parent
(Prim
)) =
6284 Private_Declarations
6285 (Specification
(Unit_Declaration_Node
(Current_Scope
)))
6286 and then Original_View_In_Visible_Part
(Typ
)
6288 -- We exclude Input and Output stream operations because
6289 -- Limited_Controlled inherits useless Input and Output
6290 -- stream operations from Root_Controlled, which can
6291 -- never be overridden.
6293 if not Is_TSS
(Prim
, TSS_Stream_Input
)
6295 not Is_TSS
(Prim
, TSS_Stream_Output
)
6298 ("abstract inherited private operation&" &
6299 " must be overridden (RM 3.9.3(10))",
6300 Parent
(Typ
), Prim
);
6304 Next_Elmt
(Prim_Elmt
);
6309 if Is_Controlled
(Typ
) then
6310 if not Finalized
then
6312 ("controlled type has no explicit Finalize method?", Typ
);
6314 elsif not Adjusted
then
6316 ("controlled type has no explicit Adjust method?", Typ
);
6320 -- Set the final size of the Dispatch Table
6322 Set_DT_Entry_Count
(The_Tag
, UI_From_Int
(DT_Length
));
6324 -- The derived type must have at least as many components as its parent
6325 -- (for root types, the Etype points back to itself and the test cannot
6328 if DT_Entry_Count
(The_Tag
) <
6329 DT_Entry_Count
(First_Tag_Component
(Parent_Typ
))
6331 raise Program_Error
;
6333 end Set_All_DT_Position
;
6335 -----------------------------
6336 -- Set_Default_Constructor --
6337 -----------------------------
6339 procedure Set_Default_Constructor
(Typ
: Entity_Id
) is
6346 -- Look for the default constructor entity. For now only the
6347 -- default constructor has the flag Is_Constructor.
6349 E
:= Next_Entity
(Typ
);
6351 and then (Ekind
(E
) /= E_Function
or else not Is_Constructor
(E
))
6356 -- Create the init procedure
6360 Init
:= Make_Defining_Identifier
(Loc
, Make_Init_Proc_Name
(Typ
));
6361 Param
:= Make_Defining_Identifier
(Loc
, Name_X
);
6364 Make_Subprogram_Declaration
(Loc
,
6365 Make_Procedure_Specification
(Loc
,
6366 Defining_Unit_Name
=> Init
,
6367 Parameter_Specifications
=> New_List
(
6368 Make_Parameter_Specification
(Loc
,
6369 Defining_Identifier
=> Param
,
6370 Parameter_Type
=> New_Reference_To
(Typ
, Loc
))))));
6372 Set_Init_Proc
(Typ
, Init
);
6373 Set_Is_Imported
(Init
);
6374 Set_Interface_Name
(Init
, Interface_Name
(E
));
6375 Set_Convention
(Init
, Convention_C
);
6376 Set_Is_Public
(Init
);
6377 Set_Has_Completion
(Init
);
6379 -- If there are no constructors, mark the type as abstract since we
6380 -- won't be able to declare objects of that type.
6383 Set_Is_Abstract_Type
(Typ
);
6385 end Set_Default_Constructor
;
6387 --------------------------
6388 -- Set_DTC_Entity_Value --
6389 --------------------------
6391 procedure Set_DTC_Entity_Value
6392 (Tagged_Type
: Entity_Id
;
6396 if Present
(Abstract_Interface_Alias
(Prim
))
6397 and then Is_Interface
6398 (Find_Dispatching_Type
6399 (Abstract_Interface_Alias
(Prim
)))
6401 Set_DTC_Entity
(Prim
,
6404 Iface
=> Find_Dispatching_Type
6405 (Abstract_Interface_Alias
(Prim
))));
6407 Set_DTC_Entity
(Prim
,
6408 First_Tag_Component
(Tagged_Type
));
6410 end Set_DTC_Entity_Value
;
6416 function Tagged_Kind
(T
: Entity_Id
) return Node_Id
is
6417 Conc_Typ
: Entity_Id
;
6418 Loc
: constant Source_Ptr
:= Sloc
(T
);
6422 (Is_Tagged_Type
(T
) and then RTE_Available
(RE_Tagged_Kind
));
6426 if Is_Abstract_Type
(T
) then
6427 if Is_Limited_Record
(T
) then
6428 return New_Reference_To
(RTE
(RE_TK_Abstract_Limited_Tagged
), Loc
);
6430 return New_Reference_To
(RTE
(RE_TK_Abstract_Tagged
), Loc
);
6435 elsif Is_Concurrent_Record_Type
(T
) then
6436 Conc_Typ
:= Corresponding_Concurrent_Type
(T
);
6438 if Present
(Full_View
(Conc_Typ
)) then
6439 Conc_Typ
:= Full_View
(Conc_Typ
);
6442 if Ekind
(Conc_Typ
) = E_Protected_Type
then
6443 return New_Reference_To
(RTE
(RE_TK_Protected
), Loc
);
6445 pragma Assert
(Ekind
(Conc_Typ
) = E_Task_Type
);
6446 return New_Reference_To
(RTE
(RE_TK_Task
), Loc
);
6449 -- Regular tagged kinds
6452 if Is_Limited_Record
(T
) then
6453 return New_Reference_To
(RTE
(RE_TK_Limited_Tagged
), Loc
);
6455 return New_Reference_To
(RTE
(RE_TK_Tagged
), Loc
);
6464 procedure Write_DT
(Typ
: Entity_Id
) is
6469 -- Protect this procedure against wrong usage. Required because it will
6470 -- be used directly from GDB
6472 if not (Typ
<= Last_Node_Id
)
6473 or else not Is_Tagged_Type
(Typ
)
6475 Write_Str
("wrong usage: Write_DT must be used with tagged types");
6480 Write_Int
(Int
(Typ
));
6482 Write_Name
(Chars
(Typ
));
6484 if Is_Interface
(Typ
) then
6485 Write_Str
(" is interface");
6490 Elmt
:= First_Elmt
(Primitive_Operations
(Typ
));
6491 while Present
(Elmt
) loop
6492 Prim
:= Node
(Elmt
);
6495 -- Indicate if this primitive will be allocated in the primary
6496 -- dispatch table or in a secondary dispatch table associated
6497 -- with an abstract interface type
6499 if Present
(DTC_Entity
(Prim
)) then
6500 if Etype
(DTC_Entity
(Prim
)) = RTE
(RE_Tag
) then
6507 -- Output the node of this primitive operation and its name
6509 Write_Int
(Int
(Prim
));
6512 if Is_Predefined_Dispatching_Operation
(Prim
) then
6513 Write_Str
("(predefined) ");
6516 Write_Name
(Chars
(Prim
));
6518 -- Indicate if this primitive has an aliased primitive
6520 if Present
(Alias
(Prim
)) then
6521 Write_Str
(" (alias = ");
6522 Write_Int
(Int
(Alias
(Prim
)));
6524 -- If the DTC_Entity attribute is already set we can also output
6525 -- the name of the interface covered by this primitive (if any)
6527 if Present
(DTC_Entity
(Alias
(Prim
)))
6528 and then Is_Interface
(Scope
(DTC_Entity
(Alias
(Prim
))))
6530 Write_Str
(" from interface ");
6531 Write_Name
(Chars
(Scope
(DTC_Entity
(Alias
(Prim
)))));
6534 if Present
(Abstract_Interface_Alias
(Prim
)) then
6535 Write_Str
(", AI_Alias of ");
6536 Write_Name
(Chars
(Scope
(DTC_Entity
6537 (Abstract_Interface_Alias
(Prim
)))));
6539 Write_Int
(Int
(Abstract_Interface_Alias
(Prim
)));
6545 -- Display the final position of this primitive in its associated
6546 -- (primary or secondary) dispatch table
6548 if Present
(DTC_Entity
(Prim
))
6549 and then DT_Position
(Prim
) /= No_Uint
6551 Write_Str
(" at #");
6552 Write_Int
(UI_To_Int
(DT_Position
(Prim
)));
6555 if Is_Abstract_Subprogram
(Prim
) then
6556 Write_Str
(" is abstract;");
6558 -- Check if this is a null primitive
6560 elsif Comes_From_Source
(Prim
)
6561 and then Ekind
(Prim
) = E_Procedure
6562 and then Null_Present
(Parent
(Prim
))
6564 Write_Str
(" is null;");