1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2012, Free Software Foundation, Inc. --
11 -- GNAT is free software; you can redistribute it and/or modify it under --
12 -- terms of the GNU General Public License as published by the Free Soft- --
13 -- ware Foundation; either version 3, or (at your option) any later ver- --
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
16 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
17 -- for more details. You should have received a copy of the GNU General --
18 -- Public License distributed with GNAT; see file COPYING3. If not, go to --
19 -- http://www.gnu.org/licenses for a complete copy of the license. --
21 -- GNAT was originally developed by the GNAT team at New York University. --
22 -- Extensive contributions were provided by Ada Core Technologies Inc. --
24 ------------------------------------------------------------------------------
26 with Atree; use Atree;
27 with Checks; use Checks;
28 with Debug; use Debug;
29 with Einfo; use Einfo;
30 with Elists; use Elists;
31 with Errout; use Errout;
32 with Exp_Atag; use Exp_Atag;
33 with Exp_Ch6; use Exp_Ch6;
34 with Exp_CG; use Exp_CG;
35 with Exp_Dbug; use Exp_Dbug;
36 with Exp_Tss; use Exp_Tss;
37 with Exp_Util; use Exp_Util;
38 with Freeze; use Freeze;
39 with Itypes; use Itypes;
40 with Layout; use Layout;
41 with Nlists; use Nlists;
42 with Nmake; use Nmake;
43 with Namet; use Namet;
45 with Output; use Output;
46 with Restrict; use Restrict;
47 with Rident; use Rident;
48 with Rtsfind; use Rtsfind;
50 with Sem_Aux; use Sem_Aux;
51 with Sem_Ch6; use Sem_Ch6;
52 with Sem_Ch7; use Sem_Ch7;
53 with Sem_Ch8; use Sem_Ch8;
54 with Sem_Disp; use Sem_Disp;
55 with Sem_Eval; use Sem_Eval;
56 with Sem_Res; use Sem_Res;
57 with Sem_Type; use Sem_Type;
58 with Sem_Util; use Sem_Util;
59 with Sinfo; use Sinfo;
60 with Snames; use Snames;
61 with Stand; use Stand;
62 with Stringt; use Stringt;
63 with SCIL_LL; use SCIL_LL;
64 with Targparm; use Targparm;
65 with Tbuild; use Tbuild;
66 with Uintp; use Uintp;
68 package body Exp_Disp is
70 -----------------------
71 -- Local Subprograms --
72 -----------------------
74 function Default_Prim_Op_Position (E : Entity_Id) return Uint;
75 -- Ada 2005 (AI-251): Returns the fixed position in the dispatch table
76 -- of the default primitive operations.
78 function Find_Specific_Type (CW : Entity_Id) return Entity_Id;
79 -- Find specific type of a class-wide type, and handle the case of an
80 -- incomplete type coming either from a limited_with clause or from an
81 -- incomplete type declaration. Shouldn't this be in Sem_Util? It seems
82 -- like a general purpose semantic routine ???
84 function Has_DT (Typ : Entity_Id) return Boolean;
85 pragma Inline (Has_DT);
86 -- Returns true if we generate a dispatch table for tagged type Typ
88 function Is_Predefined_Dispatching_Alias (Prim : Entity_Id) return Boolean;
89 -- Returns true if Prim is not a predefined dispatching primitive but it is
90 -- an alias of a predefined dispatching primitive (i.e. through a renaming)
92 function New_Value (From : Node_Id) return Node_Id;
93 -- From is the original Expression. New_Value is equivalent to a call
94 -- to Duplicate_Subexpr with an explicit dereference when From is an
97 function Original_View_In_Visible_Part (Typ : Entity_Id) return Boolean;
98 -- Check if the type has a private view or if the public view appears
99 -- in the visible part of a package spec.
101 function Prim_Op_Kind
103 Typ : Entity_Id) return Node_Id;
104 -- Ada 2005 (AI-345): Determine the primitive operation kind of Prim
105 -- according to its type Typ. Return a reference to an RE_Prim_Op_Kind
106 -- enumeration value.
108 function Tagged_Kind (T : Entity_Id) return Node_Id;
109 -- Ada 2005 (AI-345): Determine the tagged kind of T and return a reference
110 -- to an RE_Tagged_Kind enumeration value.
112 ----------------------
113 -- Apply_Tag_Checks --
114 ----------------------
116 procedure Apply_Tag_Checks (Call_Node : Node_Id) is
117 Loc : constant Source_Ptr := Sloc (Call_Node);
118 Ctrl_Arg : constant Node_Id := Controlling_Argument (Call_Node);
119 Ctrl_Typ : constant Entity_Id := Base_Type (Etype (Ctrl_Arg));
120 Param_List : constant List_Id := Parameter_Associations (Call_Node);
126 Eq_Prim_Op : Entity_Id := Empty;
129 if No_Run_Time_Mode then
130 Error_Msg_CRT ("tagged types", Call_Node);
134 -- Apply_Tag_Checks is called directly from the semantics, so we need
135 -- a check to see whether expansion is active before proceeding. In
136 -- addition, there is no need to expand the call when compiling under
137 -- restriction No_Dispatching_Calls; the semantic analyzer has
138 -- previously notified the violation of this restriction.
140 if not Expander_Active
141 or else Restriction_Active (No_Dispatching_Calls)
146 -- Set subprogram. If this is an inherited operation that was
147 -- overridden, the body that is being called is its alias.
149 Subp := Entity (Name (Call_Node));
151 if Present (Alias (Subp))
152 and then Is_Inherited_Operation (Subp)
153 and then No (DTC_Entity (Subp))
155 Subp := Alias (Subp);
158 -- Definition of the class-wide type and the tagged type
160 -- If the controlling argument is itself a tag rather than a tagged
161 -- object, then use the class-wide type associated with the subprogram's
162 -- controlling type. This case can occur when a call to an inherited
163 -- primitive has an actual that originated from a default parameter
164 -- given by a tag-indeterminate call and when there is no other
165 -- controlling argument providing the tag (AI-239 requires dispatching).
166 -- This capability of dispatching directly by tag is also needed by the
167 -- implementation of AI-260 (for the generic dispatching constructors).
169 if Ctrl_Typ = RTE (RE_Tag)
170 or else (RTE_Available (RE_Interface_Tag)
171 and then Ctrl_Typ = RTE (RE_Interface_Tag))
173 CW_Typ := Class_Wide_Type (Find_Dispatching_Type (Subp));
175 -- Class_Wide_Type is applied to the expressions used to initialize
176 -- CW_Typ, to ensure that CW_Typ always denotes a class-wide type, since
177 -- there are cases where the controlling type is resolved to a specific
178 -- type (such as for designated types of arguments such as CW'Access).
180 elsif Is_Access_Type (Ctrl_Typ) then
181 CW_Typ := Class_Wide_Type (Designated_Type (Ctrl_Typ));
184 CW_Typ := Class_Wide_Type (Ctrl_Typ);
187 Typ := Find_Specific_Type (CW_Typ);
189 if not Is_Limited_Type (Typ) then
190 Eq_Prim_Op := Find_Prim_Op (Typ, Name_Op_Eq);
193 -- Dispatching call to C++ primitive
195 if Is_CPP_Class (Typ) then
198 -- Dispatching call to Ada primitive
200 elsif Present (Param_List) then
202 -- Generate the Tag checks when appropriate
204 Param := First_Actual (Call_Node);
205 while Present (Param) loop
207 -- No tag check with itself
209 if Param = Ctrl_Arg then
212 -- No tag check for parameter whose type is neither tagged nor
213 -- access to tagged (for access parameters)
215 elsif No (Find_Controlling_Arg (Param)) then
218 -- No tag check for function dispatching on result if the
219 -- Tag given by the context is this one
221 elsif Find_Controlling_Arg (Param) = Ctrl_Arg then
224 -- "=" is the only dispatching operation allowed to get
225 -- operands with incompatible tags (it just returns false).
226 -- We use Duplicate_Subexpr_Move_Checks instead of calling
227 -- Relocate_Node because the value will be duplicated to
230 elsif Subp = Eq_Prim_Op then
233 -- No check in presence of suppress flags
235 elsif Tag_Checks_Suppressed (Etype (Param))
236 or else (Is_Access_Type (Etype (Param))
237 and then Tag_Checks_Suppressed
238 (Designated_Type (Etype (Param))))
242 -- Optimization: no tag checks if the parameters are identical
244 elsif Is_Entity_Name (Param)
245 and then Is_Entity_Name (Ctrl_Arg)
246 and then Entity (Param) = Entity (Ctrl_Arg)
250 -- Now we need to generate the Tag check
253 -- Generate code for tag equality check
254 -- Perhaps should have Checks.Apply_Tag_Equality_Check???
256 Insert_Action (Ctrl_Arg,
257 Make_Implicit_If_Statement (Call_Node,
261 Make_Selected_Component (Loc,
262 Prefix => New_Value (Ctrl_Arg),
265 (First_Tag_Component (Typ), Loc)),
268 Make_Selected_Component (Loc,
270 Unchecked_Convert_To (Typ, New_Value (Param)),
273 (First_Tag_Component (Typ), Loc))),
276 New_List (New_Constraint_Error (Loc))));
282 end Apply_Tag_Checks;
284 ------------------------
285 -- Building_Static_DT --
286 ------------------------
288 function Building_Static_DT (Typ : Entity_Id) return Boolean is
289 Root_Typ : Entity_Id := Root_Type (Typ);
292 -- Handle private types
294 if Present (Full_View (Root_Typ)) then
295 Root_Typ := Full_View (Root_Typ);
298 return Static_Dispatch_Tables
299 and then Is_Library_Level_Tagged_Type (Typ)
300 and then VM_Target = No_VM
302 -- If the type is derived from a CPP class we cannot statically
303 -- build the dispatch tables because we must inherit primitives
304 -- from the CPP side.
306 and then not Is_CPP_Class (Root_Typ);
307 end Building_Static_DT;
309 ----------------------------------
310 -- Build_Static_Dispatch_Tables --
311 ----------------------------------
313 procedure Build_Static_Dispatch_Tables (N : Entity_Id) is
314 Target_List : List_Id;
316 procedure Build_Dispatch_Tables (List : List_Id);
317 -- Build the static dispatch table of tagged types found in the list of
318 -- declarations. The generated nodes are added at the end of Target_List
320 procedure Build_Package_Dispatch_Tables (N : Node_Id);
321 -- Build static dispatch tables associated with package declaration N
323 ---------------------------
324 -- Build_Dispatch_Tables --
325 ---------------------------
327 procedure Build_Dispatch_Tables (List : List_Id) is
332 while Present (D) loop
334 -- Handle nested packages and package bodies recursively. The
335 -- generated code is placed on the Target_List established for
336 -- the enclosing compilation unit.
338 if Nkind (D) = N_Package_Declaration then
339 Build_Package_Dispatch_Tables (D);
341 elsif Nkind (D) = N_Package_Body then
342 Build_Dispatch_Tables (Declarations (D));
344 elsif Nkind (D) = N_Package_Body_Stub
345 and then Present (Library_Unit (D))
347 Build_Dispatch_Tables
348 (Declarations (Proper_Body (Unit (Library_Unit (D)))));
350 -- Handle full type declarations and derivations of library
351 -- level tagged types
353 elsif Nkind_In (D, N_Full_Type_Declaration,
354 N_Derived_Type_Definition)
355 and then Is_Library_Level_Tagged_Type (Defining_Entity (D))
356 and then Ekind (Defining_Entity (D)) /= E_Record_Subtype
357 and then not Is_Private_Type (Defining_Entity (D))
359 -- We do not generate dispatch tables for the internal types
360 -- created for a type extension with unknown discriminants
361 -- The needed information is shared with the source type,
362 -- See Expand_N_Record_Extension.
364 if Is_Underlying_Record_View (Defining_Entity (D))
366 (not Comes_From_Source (Defining_Entity (D))
368 Has_Unknown_Discriminants (Etype (Defining_Entity (D)))
370 not Comes_From_Source
371 (First_Subtype (Defining_Entity (D))))
375 Insert_List_After_And_Analyze (Last (Target_List),
376 Make_DT (Defining_Entity (D)));
379 -- Handle private types of library level tagged types. We must
380 -- exchange the private and full-view to ensure the correct
381 -- expansion. If the full view is a synchronized type ignore
382 -- the type because the table will be built for the corresponding
383 -- record type, that has its own declaration.
385 elsif (Nkind (D) = N_Private_Type_Declaration
386 or else Nkind (D) = N_Private_Extension_Declaration)
387 and then Present (Full_View (Defining_Entity (D)))
390 E1 : constant Entity_Id := Defining_Entity (D);
391 E2 : constant Entity_Id := Full_View (E1);
394 if Is_Library_Level_Tagged_Type (E2)
395 and then Ekind (E2) /= E_Record_Subtype
396 and then not Is_Concurrent_Type (E2)
398 Exchange_Declarations (E1);
399 Insert_List_After_And_Analyze (Last (Target_List),
401 Exchange_Declarations (E2);
408 end Build_Dispatch_Tables;
410 -----------------------------------
411 -- Build_Package_Dispatch_Tables --
412 -----------------------------------
414 procedure Build_Package_Dispatch_Tables (N : Node_Id) is
415 Spec : constant Node_Id := Specification (N);
416 Id : constant Entity_Id := Defining_Entity (N);
417 Vis_Decls : constant List_Id := Visible_Declarations (Spec);
418 Priv_Decls : constant List_Id := Private_Declarations (Spec);
423 if Present (Priv_Decls) then
424 Build_Dispatch_Tables (Vis_Decls);
425 Build_Dispatch_Tables (Priv_Decls);
427 elsif Present (Vis_Decls) then
428 Build_Dispatch_Tables (Vis_Decls);
432 end Build_Package_Dispatch_Tables;
434 -- Start of processing for Build_Static_Dispatch_Tables
437 if not Expander_Active
438 or else not Tagged_Type_Expansion
443 if Nkind (N) = N_Package_Declaration then
445 Spec : constant Node_Id := Specification (N);
446 Vis_Decls : constant List_Id := Visible_Declarations (Spec);
447 Priv_Decls : constant List_Id := Private_Declarations (Spec);
450 if Present (Priv_Decls)
451 and then Is_Non_Empty_List (Priv_Decls)
453 Target_List := Priv_Decls;
455 elsif not Present (Vis_Decls) then
456 Target_List := New_List;
457 Set_Private_Declarations (Spec, Target_List);
459 Target_List := Vis_Decls;
462 Build_Package_Dispatch_Tables (N);
465 else pragma Assert (Nkind (N) = N_Package_Body);
466 Target_List := Declarations (N);
467 Build_Dispatch_Tables (Target_List);
469 end Build_Static_Dispatch_Tables;
471 ------------------------------
472 -- Convert_Tag_To_Interface --
473 ------------------------------
475 function Convert_Tag_To_Interface
477 Expr : Node_Id) return Node_Id
479 Loc : constant Source_Ptr := Sloc (Expr);
480 Anon_Type : Entity_Id;
484 pragma Assert (Is_Class_Wide_Type (Typ)
485 and then Is_Interface (Typ)
487 ((Nkind (Expr) = N_Selected_Component
488 and then Is_Tag (Entity (Selector_Name (Expr))))
490 (Nkind (Expr) = N_Function_Call
491 and then RTE_Available (RE_Displace)
492 and then Entity (Name (Expr)) = RTE (RE_Displace))));
494 Anon_Type := Create_Itype (E_Anonymous_Access_Type, Expr);
495 Set_Directly_Designated_Type (Anon_Type, Typ);
496 Set_Etype (Anon_Type, Anon_Type);
497 Set_Can_Never_Be_Null (Anon_Type);
499 -- Decorate the size and alignment attributes of the anonymous access
500 -- type, as required by gigi.
502 Layout_Type (Anon_Type);
504 if Nkind (Expr) = N_Selected_Component
505 and then Is_Tag (Entity (Selector_Name (Expr)))
508 Make_Explicit_Dereference (Loc,
509 Unchecked_Convert_To (Anon_Type,
510 Make_Attribute_Reference (Loc,
512 Attribute_Name => Name_Address)));
515 Make_Explicit_Dereference (Loc,
516 Unchecked_Convert_To (Anon_Type, Expr));
520 end Convert_Tag_To_Interface;
526 function CPP_Num_Prims (Typ : Entity_Id) return Nat is
528 Tag_Comp : Entity_Id;
531 if not Is_Tagged_Type (Typ)
532 or else not Is_CPP_Class (Root_Type (Typ))
537 CPP_Typ := Enclosing_CPP_Parent (Typ);
538 Tag_Comp := First_Tag_Component (CPP_Typ);
540 -- If the number of primitives is already set in the tag component
543 if Present (Tag_Comp)
544 and then DT_Entry_Count (Tag_Comp) /= No_Uint
546 return UI_To_Int (DT_Entry_Count (Tag_Comp));
548 -- Otherwise, count the primitives of the enclosing CPP type
556 Elmt := First_Elmt (Primitive_Operations (CPP_Typ));
557 while Present (Elmt) loop
568 ------------------------------
569 -- Default_Prim_Op_Position --
570 ------------------------------
572 function Default_Prim_Op_Position (E : Entity_Id) return Uint is
573 TSS_Name : TSS_Name_Type;
576 Get_Name_String (Chars (E));
579 (Name_Buffer (Name_Len - TSS_Name'Length + 1 .. Name_Len));
581 if Chars (E) = Name_uSize then
584 elsif TSS_Name = TSS_Stream_Read then
587 elsif TSS_Name = TSS_Stream_Write then
590 elsif TSS_Name = TSS_Stream_Input then
593 elsif TSS_Name = TSS_Stream_Output then
596 elsif Chars (E) = Name_Op_Eq then
599 elsif Chars (E) = Name_uAssign then
602 elsif TSS_Name = TSS_Deep_Adjust then
605 elsif TSS_Name = TSS_Deep_Finalize then
608 -- In VM targets unconditionally allow obtaining the position associated
609 -- with predefined interface primitives since in these platforms any
610 -- tagged type has these primitives.
612 elsif Ada_Version >= Ada_2005 or else not Tagged_Type_Expansion then
613 if Chars (E) = Name_uDisp_Asynchronous_Select then
616 elsif Chars (E) = Name_uDisp_Conditional_Select then
619 elsif Chars (E) = Name_uDisp_Get_Prim_Op_Kind then
622 elsif Chars (E) = Name_uDisp_Get_Task_Id then
625 elsif Chars (E) = Name_uDisp_Requeue then
628 elsif Chars (E) = Name_uDisp_Timed_Select then
634 end Default_Prim_Op_Position;
636 -----------------------------
637 -- Expand_Dispatching_Call --
638 -----------------------------
640 procedure Expand_Dispatching_Call (Call_Node : Node_Id) is
641 Loc : constant Source_Ptr := Sloc (Call_Node);
642 Call_Typ : constant Entity_Id := Etype (Call_Node);
644 Ctrl_Arg : constant Node_Id := Controlling_Argument (Call_Node);
645 Ctrl_Typ : constant Entity_Id := Base_Type (Etype (Ctrl_Arg));
646 Param_List : constant List_Id := Parameter_Associations (Call_Node);
651 New_Call_Name : Node_Id;
652 New_Params : List_Id := No_List;
655 Subp_Ptr_Typ : Entity_Id;
656 Subp_Typ : Entity_Id;
658 Eq_Prim_Op : Entity_Id := Empty;
659 Controlling_Tag : Node_Id;
661 function New_Value (From : Node_Id) return Node_Id;
662 -- From is the original Expression. New_Value is equivalent to a call
663 -- to Duplicate_Subexpr with an explicit dereference when From is an
670 function New_Value (From : Node_Id) return Node_Id is
671 Res : constant Node_Id := Duplicate_Subexpr (From);
673 if Is_Access_Type (Etype (From)) then
675 Make_Explicit_Dereference (Sloc (From),
686 SCIL_Related_Node : Node_Id := Call_Node;
688 -- Start of processing for Expand_Dispatching_Call
691 if No_Run_Time_Mode then
692 Error_Msg_CRT ("tagged types", Call_Node);
696 -- Expand_Dispatching_Call is called directly from the semantics,
697 -- so we only proceed if the expander is active.
699 if not Full_Expander_Active
701 -- And there is no need to expand the call if we are compiling under
702 -- restriction No_Dispatching_Calls; the semantic analyzer has
703 -- previously notified the violation of this restriction.
705 or else Restriction_Active (No_Dispatching_Calls)
710 -- Set subprogram. If this is an inherited operation that was
711 -- overridden, the body that is being called is its alias.
713 Subp := Entity (Name (Call_Node));
715 if Present (Alias (Subp))
716 and then Is_Inherited_Operation (Subp)
717 and then No (DTC_Entity (Subp))
719 Subp := Alias (Subp);
722 -- Definition of the class-wide type and the tagged type
724 -- If the controlling argument is itself a tag rather than a tagged
725 -- object, then use the class-wide type associated with the subprogram's
726 -- controlling type. This case can occur when a call to an inherited
727 -- primitive has an actual that originated from a default parameter
728 -- given by a tag-indeterminate call and when there is no other
729 -- controlling argument providing the tag (AI-239 requires dispatching).
730 -- This capability of dispatching directly by tag is also needed by the
731 -- implementation of AI-260 (for the generic dispatching constructors).
733 if Ctrl_Typ = RTE (RE_Tag)
734 or else (RTE_Available (RE_Interface_Tag)
735 and then Ctrl_Typ = RTE (RE_Interface_Tag))
737 CW_Typ := Class_Wide_Type (Find_Dispatching_Type (Subp));
739 -- Class_Wide_Type is applied to the expressions used to initialize
740 -- CW_Typ, to ensure that CW_Typ always denotes a class-wide type, since
741 -- there are cases where the controlling type is resolved to a specific
742 -- type (such as for designated types of arguments such as CW'Access).
744 elsif Is_Access_Type (Ctrl_Typ) then
745 CW_Typ := Class_Wide_Type (Designated_Type (Ctrl_Typ));
748 CW_Typ := Class_Wide_Type (Ctrl_Typ);
751 Typ := Find_Specific_Type (CW_Typ);
753 if not Is_Limited_Type (Typ) then
754 Eq_Prim_Op := Find_Prim_Op (Typ, Name_Op_Eq);
757 -- Dispatching call to C++ primitive. Create a new parameter list
758 -- with no tag checks.
760 New_Params := New_List;
762 if Is_CPP_Class (Typ) then
763 Param := First_Actual (Call_Node);
764 while Present (Param) loop
765 Append_To (New_Params, Relocate_Node (Param));
769 -- Dispatching call to Ada primitive
771 elsif Present (Param_List) then
772 Apply_Tag_Checks (Call_Node);
774 Param := First_Actual (Call_Node);
775 while Present (Param) loop
776 -- Cases in which we may have generated runtime checks
779 or else Subp = Eq_Prim_Op
781 Append_To (New_Params,
782 Duplicate_Subexpr_Move_Checks (Param));
784 elsif Nkind (Parent (Param)) /= N_Parameter_Association
785 or else not Is_Accessibility_Actual (Parent (Param))
787 Append_To (New_Params, Relocate_Node (Param));
794 -- Generate the appropriate subprogram pointer type
796 if Etype (Subp) = Typ then
799 Res_Typ := Etype (Subp);
802 Subp_Typ := Create_Itype (E_Subprogram_Type, Call_Node);
803 Subp_Ptr_Typ := Create_Itype (E_Access_Subprogram_Type, Call_Node);
804 Set_Etype (Subp_Typ, Res_Typ);
805 Set_Returns_By_Ref (Subp_Typ, Returns_By_Ref (Subp));
807 -- Create a new list of parameters which is a copy of the old formal
808 -- list including the creation of a new set of matching entities.
811 Old_Formal : Entity_Id := First_Formal (Subp);
812 New_Formal : Entity_Id;
813 Extra : Entity_Id := Empty;
816 if Present (Old_Formal) then
817 New_Formal := New_Copy (Old_Formal);
818 Set_First_Entity (Subp_Typ, New_Formal);
819 Param := First_Actual (Call_Node);
822 Set_Scope (New_Formal, Subp_Typ);
824 -- Change all the controlling argument types to be class-wide
825 -- to avoid a recursion in dispatching.
827 if Is_Controlling_Formal (New_Formal) then
828 Set_Etype (New_Formal, Etype (Param));
831 -- If the type of the formal is an itype, there was code here
832 -- introduced in 1998 in revision 1.46, to create a new itype
833 -- by copy. This seems useless, and in fact leads to semantic
834 -- errors when the itype is the completion of a type derived
835 -- from a private type.
838 Next_Formal (Old_Formal);
839 exit when No (Old_Formal);
841 Set_Next_Entity (New_Formal, New_Copy (Old_Formal));
842 Next_Entity (New_Formal);
846 Set_Next_Entity (New_Formal, Empty);
847 Set_Last_Entity (Subp_Typ, Extra);
850 -- Now that the explicit formals have been duplicated, any extra
851 -- formals needed by the subprogram must be created.
853 if Present (Extra) then
854 Set_Extra_Formal (Extra, Empty);
857 Create_Extra_Formals (Subp_Typ);
860 -- Complete description of pointer type, including size information, as
861 -- must be done with itypes to prevent order-of-elaboration anomalies
864 Set_Etype (Subp_Ptr_Typ, Subp_Ptr_Typ);
865 Set_Directly_Designated_Type (Subp_Ptr_Typ, Subp_Typ);
866 Set_Convention (Subp_Ptr_Typ, Convention (Subp_Typ));
867 Layout_Type (Subp_Ptr_Typ);
869 -- If the controlling argument is a value of type Ada.Tag or an abstract
870 -- interface class-wide type then use it directly. Otherwise, the tag
871 -- must be extracted from the controlling object.
873 if Ctrl_Typ = RTE (RE_Tag)
874 or else (RTE_Available (RE_Interface_Tag)
875 and then Ctrl_Typ = RTE (RE_Interface_Tag))
877 Controlling_Tag := Duplicate_Subexpr (Ctrl_Arg);
879 -- Extract the tag from an unchecked type conversion. Done to avoid
880 -- the expansion of additional code just to obtain the value of such
881 -- tag because the current management of interface type conversions
882 -- generates in some cases this unchecked type conversion with the
883 -- tag of the object (see Expand_Interface_Conversion).
885 elsif Nkind (Ctrl_Arg) = N_Unchecked_Type_Conversion
887 (Etype (Expression (Ctrl_Arg)) = RTE (RE_Tag)
889 (RTE_Available (RE_Interface_Tag)
891 Etype (Expression (Ctrl_Arg)) = RTE (RE_Interface_Tag)))
893 Controlling_Tag := Duplicate_Subexpr (Expression (Ctrl_Arg));
895 -- Ada 2005 (AI-251): Abstract interface class-wide type
897 elsif Is_Interface (Ctrl_Typ)
898 and then Is_Class_Wide_Type (Ctrl_Typ)
900 Controlling_Tag := Duplicate_Subexpr (Ctrl_Arg);
904 Make_Selected_Component (Loc,
905 Prefix => Duplicate_Subexpr_Move_Checks (Ctrl_Arg),
906 Selector_Name => New_Reference_To (DTC_Entity (Subp), Loc));
909 -- Handle dispatching calls to predefined primitives
911 if Is_Predefined_Dispatching_Operation (Subp)
912 or else Is_Predefined_Dispatching_Alias (Subp)
914 Build_Get_Predefined_Prim_Op_Address (Loc,
915 Tag_Node => Controlling_Tag,
916 Position => DT_Position (Subp),
917 New_Node => New_Node);
919 -- Handle dispatching calls to user-defined primitives
922 Build_Get_Prim_Op_Address (Loc,
923 Typ => Underlying_Type (Find_Dispatching_Type (Subp)),
924 Tag_Node => Controlling_Tag,
925 Position => DT_Position (Subp),
926 New_Node => New_Node);
930 Unchecked_Convert_To (Subp_Ptr_Typ, New_Node);
932 -- Generate the SCIL node for this dispatching call. Done now because
933 -- attribute SCIL_Controlling_Tag must be set after the new call name
934 -- is built to reference the nodes that will see the SCIL backend
935 -- (because Build_Get_Prim_Op_Address generates an unchecked type
936 -- conversion which relocates the controlling tag node).
938 if Generate_SCIL then
939 SCIL_Node := Make_SCIL_Dispatching_Call (Sloc (Call_Node));
940 Set_SCIL_Entity (SCIL_Node, Typ);
941 Set_SCIL_Target_Prim (SCIL_Node, Subp);
943 -- Common case: the controlling tag is the tag of an object
944 -- (for example, obj.tag)
946 if Nkind (Controlling_Tag) = N_Selected_Component then
947 Set_SCIL_Controlling_Tag (SCIL_Node, Controlling_Tag);
949 -- Handle renaming of selected component
951 elsif Nkind (Controlling_Tag) = N_Identifier
952 and then Nkind (Parent (Entity (Controlling_Tag))) =
953 N_Object_Renaming_Declaration
954 and then Nkind (Name (Parent (Entity (Controlling_Tag)))) =
957 Set_SCIL_Controlling_Tag (SCIL_Node,
958 Name (Parent (Entity (Controlling_Tag))));
960 -- If the controlling tag is an identifier, the SCIL node references
961 -- the corresponding object or parameter declaration
963 elsif Nkind (Controlling_Tag) = N_Identifier
964 and then Nkind_In (Parent (Entity (Controlling_Tag)),
965 N_Object_Declaration,
966 N_Parameter_Specification)
968 Set_SCIL_Controlling_Tag (SCIL_Node,
969 Parent (Entity (Controlling_Tag)));
971 -- If the controlling tag is a dereference, the SCIL node references
972 -- the corresponding object or parameter declaration
974 elsif Nkind (Controlling_Tag) = N_Explicit_Dereference
975 and then Nkind (Prefix (Controlling_Tag)) = N_Identifier
976 and then Nkind_In (Parent (Entity (Prefix (Controlling_Tag))),
977 N_Object_Declaration,
978 N_Parameter_Specification)
980 Set_SCIL_Controlling_Tag (SCIL_Node,
981 Parent (Entity (Prefix (Controlling_Tag))));
983 -- For a direct reference of the tag of the type the SCIL node
984 -- references the internal object declaration containing the tag
987 elsif Nkind (Controlling_Tag) = N_Attribute_Reference
988 and then Attribute_Name (Controlling_Tag) = Name_Tag
990 Set_SCIL_Controlling_Tag (SCIL_Node,
994 (Access_Disp_Table (Entity (Prefix (Controlling_Tag)))))));
996 -- Interfaces are not supported. For now we leave the SCIL node
997 -- decorated with the Controlling_Tag. More work needed here???
999 elsif Is_Interface (Etype (Controlling_Tag)) then
1000 Set_SCIL_Controlling_Tag (SCIL_Node, Controlling_Tag);
1003 pragma Assert (False);
1008 if Nkind (Call_Node) = N_Function_Call then
1010 Make_Function_Call (Loc,
1011 Name => New_Call_Name,
1012 Parameter_Associations => New_Params);
1014 -- If this is a dispatching "=", we must first compare the tags so
1015 -- we generate: x.tag = y.tag and then x = y
1017 if Subp = Eq_Prim_Op then
1018 Param := First_Actual (Call_Node);
1024 Make_Selected_Component (Loc,
1025 Prefix => New_Value (Param),
1027 New_Reference_To (First_Tag_Component (Typ),
1031 Make_Selected_Component (Loc,
1033 Unchecked_Convert_To (Typ,
1034 New_Value (Next_Actual (Param))),
1037 (First_Tag_Component (Typ), Loc))),
1038 Right_Opnd => New_Call);
1040 SCIL_Related_Node := Right_Opnd (New_Call);
1045 Make_Procedure_Call_Statement (Loc,
1046 Name => New_Call_Name,
1047 Parameter_Associations => New_Params);
1050 -- Register the dispatching call in the call graph nodes table
1052 Register_CG_Node (Call_Node);
1054 Rewrite (Call_Node, New_Call);
1056 -- Associate the SCIL node of this dispatching call
1058 if Generate_SCIL then
1059 Set_SCIL_Node (SCIL_Related_Node, SCIL_Node);
1062 -- Suppress all checks during the analysis of the expanded code
1063 -- to avoid the generation of spurious warnings under ZFP run-time.
1065 Analyze_And_Resolve (Call_Node, Call_Typ, Suppress => All_Checks);
1066 end Expand_Dispatching_Call;
1068 ---------------------------------
1069 -- Expand_Interface_Conversion --
1070 ---------------------------------
1072 procedure Expand_Interface_Conversion
1074 Is_Static : Boolean := True)
1076 Loc : constant Source_Ptr := Sloc (N);
1077 Etyp : constant Entity_Id := Etype (N);
1078 Operand : constant Node_Id := Expression (N);
1079 Operand_Typ : Entity_Id := Etype (Operand);
1081 Iface_Typ : Entity_Id := Etype (N);
1082 Iface_Tag : Entity_Id;
1085 -- Ada 2005 (AI-345): Handle synchronized interface type derivations
1087 if Is_Concurrent_Type (Operand_Typ) then
1088 Operand_Typ := Base_Type (Corresponding_Record_Type (Operand_Typ));
1091 -- Handle access to class-wide interface types
1093 if Is_Access_Type (Iface_Typ) then
1094 Iface_Typ := Etype (Directly_Designated_Type (Iface_Typ));
1097 -- Handle class-wide interface types. This conversion can appear
1098 -- explicitly in the source code. Example: I'Class (Obj)
1100 if Is_Class_Wide_Type (Iface_Typ) then
1101 Iface_Typ := Root_Type (Iface_Typ);
1104 -- If the target type is a tagged synchronized type, the dispatch table
1105 -- info is in the corresponding record type.
1107 if Is_Concurrent_Type (Iface_Typ) then
1108 Iface_Typ := Corresponding_Record_Type (Iface_Typ);
1111 -- Handle private types
1113 Iface_Typ := Underlying_Type (Iface_Typ);
1115 -- Freeze the entity associated with the target interface to have
1116 -- available the attribute Access_Disp_Table.
1118 Freeze_Before (N, Iface_Typ);
1120 pragma Assert (not Is_Static
1121 or else (not Is_Class_Wide_Type (Iface_Typ)
1122 and then Is_Interface (Iface_Typ)));
1124 if not Tagged_Type_Expansion then
1125 if VM_Target /= No_VM then
1126 if Is_Access_Type (Operand_Typ) then
1127 Operand_Typ := Designated_Type (Operand_Typ);
1130 if Is_Class_Wide_Type (Operand_Typ) then
1131 Operand_Typ := Root_Type (Operand_Typ);
1135 and then Operand_Typ /= Iface_Typ
1138 Make_Procedure_Call_Statement (Loc,
1139 Name => New_Occurrence_Of
1140 (RTE (RE_Check_Interface_Conversion), Loc),
1141 Parameter_Associations => New_List (
1142 Make_Attribute_Reference (Loc,
1143 Prefix => Duplicate_Subexpr (Expression (N)),
1144 Attribute_Name => Name_Tag),
1145 Make_Attribute_Reference (Loc,
1146 Prefix => New_Reference_To (Iface_Typ, Loc),
1147 Attribute_Name => Name_Tag))));
1150 -- Just do a conversion ???
1152 Rewrite (N, Unchecked_Convert_To (Etype (N), N));
1159 if not Is_Static then
1161 -- Give error if configurable run time and Displace not available
1163 if not RTE_Available (RE_Displace) then
1164 Error_Msg_CRT ("dynamic interface conversion", N);
1168 -- Handle conversion of access-to-class-wide interface types. Target
1169 -- can be an access to an object or an access to another class-wide
1170 -- interface (see -1- and -2- in the following example):
1172 -- type Iface1_Ref is access all Iface1'Class;
1173 -- type Iface2_Ref is access all Iface1'Class;
1175 -- Acc1 : Iface1_Ref := new ...
1176 -- Obj : Obj_Ref := Obj_Ref (Acc); -- 1
1177 -- Acc2 : Iface2_Ref := Iface2_Ref (Acc); -- 2
1179 if Is_Access_Type (Operand_Typ) then
1181 Unchecked_Convert_To (Etype (N),
1182 Make_Function_Call (Loc,
1183 Name => New_Reference_To (RTE (RE_Displace), Loc),
1184 Parameter_Associations => New_List (
1186 Unchecked_Convert_To (RTE (RE_Address),
1187 Relocate_Node (Expression (N))),
1190 (Node (First_Elmt (Access_Disp_Table (Iface_Typ))),
1198 Make_Function_Call (Loc,
1199 Name => New_Reference_To (RTE (RE_Displace), Loc),
1200 Parameter_Associations => New_List (
1201 Make_Attribute_Reference (Loc,
1202 Prefix => Relocate_Node (Expression (N)),
1203 Attribute_Name => Name_Address),
1206 (Node (First_Elmt (Access_Disp_Table (Iface_Typ))),
1211 -- If the target is a class-wide interface we change the type of the
1212 -- data returned by IW_Convert to indicate that this is a dispatching
1216 New_Itype : Entity_Id;
1219 New_Itype := Create_Itype (E_Anonymous_Access_Type, N);
1220 Set_Etype (New_Itype, New_Itype);
1221 Set_Directly_Designated_Type (New_Itype, Etyp);
1224 Make_Explicit_Dereference (Loc,
1226 Unchecked_Convert_To (New_Itype, Relocate_Node (N))));
1228 Freeze_Itype (New_Itype, N);
1234 Iface_Tag := Find_Interface_Tag (Operand_Typ, Iface_Typ);
1235 pragma Assert (Iface_Tag /= Empty);
1237 -- Keep separate access types to interfaces because one internal
1238 -- function is used to handle the null value (see following comments)
1240 if not Is_Access_Type (Etype (N)) then
1242 -- Statically displace the pointer to the object to reference
1243 -- the component containing the secondary dispatch table.
1246 Convert_Tag_To_Interface (Class_Wide_Type (Iface_Typ),
1247 Make_Selected_Component (Loc,
1248 Prefix => Relocate_Node (Expression (N)),
1249 Selector_Name => New_Occurrence_Of (Iface_Tag, Loc))));
1252 -- Build internal function to handle the case in which the
1253 -- actual is null. If the actual is null returns null because
1254 -- no displacement is required; otherwise performs a type
1255 -- conversion that will be expanded in the code that returns
1256 -- the value of the displaced actual. That is:
1258 -- function Func (O : Address) return Iface_Typ is
1259 -- type Op_Typ is access all Operand_Typ;
1260 -- Aux : Op_Typ := To_Op_Typ (O);
1262 -- if O = Null_Address then
1265 -- return Iface_Typ!(Aux.Iface_Tag'Address);
1270 Desig_Typ : Entity_Id;
1272 New_Typ_Decl : Node_Id;
1276 Desig_Typ := Etype (Expression (N));
1278 if Is_Access_Type (Desig_Typ) then
1280 Available_View (Directly_Designated_Type (Desig_Typ));
1283 if Is_Concurrent_Type (Desig_Typ) then
1284 Desig_Typ := Base_Type (Corresponding_Record_Type (Desig_Typ));
1288 Make_Full_Type_Declaration (Loc,
1289 Defining_Identifier => Make_Temporary (Loc, 'T'),
1291 Make_Access_To_Object_Definition (Loc,
1292 All_Present => True,
1293 Null_Exclusion_Present => False,
1294 Constant_Present => False,
1295 Subtype_Indication =>
1296 New_Reference_To (Desig_Typ, Loc)));
1299 Make_Simple_Return_Statement (Loc,
1300 Unchecked_Convert_To (Etype (N),
1301 Make_Attribute_Reference (Loc,
1303 Make_Selected_Component (Loc,
1305 Unchecked_Convert_To
1306 (Defining_Identifier (New_Typ_Decl),
1307 Make_Identifier (Loc, Name_uO)),
1309 New_Occurrence_Of (Iface_Tag, Loc)),
1310 Attribute_Name => Name_Address))));
1312 -- If the type is null-excluding, no need for the null branch.
1313 -- Otherwise we need to check for it and return null.
1315 if not Can_Never_Be_Null (Etype (N)) then
1317 Make_If_Statement (Loc,
1320 Left_Opnd => Make_Identifier (Loc, Name_uO),
1321 Right_Opnd => New_Reference_To
1322 (RTE (RE_Null_Address), Loc)),
1324 Then_Statements => New_List (
1325 Make_Simple_Return_Statement (Loc,
1327 Else_Statements => Stats));
1330 Fent := Make_Temporary (Loc, 'F');
1332 Make_Subprogram_Body (Loc,
1334 Make_Function_Specification (Loc,
1335 Defining_Unit_Name => Fent,
1337 Parameter_Specifications => New_List (
1338 Make_Parameter_Specification (Loc,
1339 Defining_Identifier =>
1340 Make_Defining_Identifier (Loc, Name_uO),
1342 New_Reference_To (RTE (RE_Address), Loc))),
1344 Result_Definition =>
1345 New_Reference_To (Etype (N), Loc)),
1347 Declarations => New_List (New_Typ_Decl),
1349 Handled_Statement_Sequence =>
1350 Make_Handled_Sequence_Of_Statements (Loc, Stats));
1352 -- Place function body before the expression containing the
1353 -- conversion. We suppress all checks because the body of the
1354 -- internally generated function already takes care of the case
1355 -- in which the actual is null; therefore there is no need to
1356 -- double check that the pointer is not null when the program
1357 -- executes the alternative that performs the type conversion).
1359 Insert_Action (N, Func, Suppress => All_Checks);
1361 if Is_Access_Type (Etype (Expression (N))) then
1363 -- Generate: Func (Address!(Expression))
1366 Make_Function_Call (Loc,
1367 Name => New_Reference_To (Fent, Loc),
1368 Parameter_Associations => New_List (
1369 Unchecked_Convert_To (RTE (RE_Address),
1370 Relocate_Node (Expression (N))))));
1373 -- Generate: Func (Operand_Typ!(Expression)'Address)
1376 Make_Function_Call (Loc,
1377 Name => New_Reference_To (Fent, Loc),
1378 Parameter_Associations => New_List (
1379 Make_Attribute_Reference (Loc,
1380 Prefix => Unchecked_Convert_To (Operand_Typ,
1381 Relocate_Node (Expression (N))),
1382 Attribute_Name => Name_Address))));
1388 end Expand_Interface_Conversion;
1390 ------------------------------
1391 -- Expand_Interface_Actuals --
1392 ------------------------------
1394 procedure Expand_Interface_Actuals (Call_Node : Node_Id) is
1396 Actual_Dup : Node_Id;
1397 Actual_Typ : Entity_Id;
1399 Conversion : Node_Id;
1401 Formal_Typ : Entity_Id;
1403 Formal_DDT : Entity_Id;
1404 Actual_DDT : Entity_Id;
1407 -- This subprogram is called directly from the semantics, so we need a
1408 -- check to see whether expansion is active before proceeding.
1410 if not Expander_Active then
1414 -- Call using access to subprogram with explicit dereference
1416 if Nkind (Name (Call_Node)) = N_Explicit_Dereference then
1417 Subp := Etype (Name (Call_Node));
1419 -- Call using selected component
1421 elsif Nkind (Name (Call_Node)) = N_Selected_Component then
1422 Subp := Entity (Selector_Name (Name (Call_Node)));
1424 -- Call using direct name
1427 Subp := Entity (Name (Call_Node));
1430 -- Ada 2005 (AI-251): Look for interface type formals to force "this"
1433 Formal := First_Formal (Subp);
1434 Actual := First_Actual (Call_Node);
1435 while Present (Formal) loop
1436 Formal_Typ := Etype (Formal);
1438 if Ekind (Formal_Typ) = E_Record_Type_With_Private then
1439 Formal_Typ := Full_View (Formal_Typ);
1442 if Is_Access_Type (Formal_Typ) then
1443 Formal_DDT := Directly_Designated_Type (Formal_Typ);
1446 Actual_Typ := Etype (Actual);
1448 if Is_Access_Type (Actual_Typ) then
1449 Actual_DDT := Directly_Designated_Type (Actual_Typ);
1452 if Is_Interface (Formal_Typ)
1453 and then Is_Class_Wide_Type (Formal_Typ)
1455 -- No need to displace the pointer if the type of the actual
1456 -- coincides with the type of the formal.
1458 if Actual_Typ = Formal_Typ then
1461 -- No need to displace the pointer if the interface type is
1462 -- a parent of the type of the actual because in this case the
1463 -- interface primitives are located in the primary dispatch table.
1465 elsif Is_Ancestor (Formal_Typ, Actual_Typ,
1466 Use_Full_View => True)
1470 -- Implicit conversion to the class-wide formal type to force
1471 -- the displacement of the pointer.
1474 -- Normally, expansion of actuals for calls to build-in-place
1475 -- functions happens as part of Expand_Actuals, but in this
1476 -- case the call will be wrapped in a conversion and soon after
1477 -- expanded further to handle the displacement for a class-wide
1478 -- interface conversion, so if this is a BIP call then we need
1479 -- to handle it now.
1481 if Ada_Version >= Ada_2005
1482 and then Is_Build_In_Place_Function_Call (Actual)
1484 Make_Build_In_Place_Call_In_Anonymous_Context (Actual);
1487 Conversion := Convert_To (Formal_Typ, Relocate_Node (Actual));
1488 Rewrite (Actual, Conversion);
1489 Analyze_And_Resolve (Actual, Formal_Typ);
1492 -- Access to class-wide interface type
1494 elsif Is_Access_Type (Formal_Typ)
1495 and then Is_Interface (Formal_DDT)
1496 and then Is_Class_Wide_Type (Formal_DDT)
1497 and then Interface_Present_In_Ancestor
1499 Iface => Etype (Formal_DDT))
1501 -- Handle attributes 'Access and 'Unchecked_Access
1503 if Nkind (Actual) = N_Attribute_Reference
1505 (Attribute_Name (Actual) = Name_Access
1506 or else Attribute_Name (Actual) = Name_Unchecked_Access)
1508 -- This case must have been handled by the analysis and
1509 -- expansion of 'Access. The only exception is when types
1510 -- match and no further expansion is required.
1512 pragma Assert (Base_Type (Etype (Prefix (Actual)))
1513 = Base_Type (Formal_DDT));
1516 -- No need to displace the pointer if the type of the actual
1517 -- coincides with the type of the formal.
1519 elsif Actual_DDT = Formal_DDT then
1522 -- No need to displace the pointer if the interface type is
1523 -- a parent of the type of the actual because in this case the
1524 -- interface primitives are located in the primary dispatch table.
1526 elsif Is_Ancestor (Formal_DDT, Actual_DDT,
1527 Use_Full_View => True)
1532 Actual_Dup := Relocate_Node (Actual);
1534 if From_With_Type (Actual_Typ) then
1536 -- If the type of the actual parameter comes from a limited
1537 -- with-clause and the non-limited view is already available
1538 -- we replace the anonymous access type by a duplicate
1539 -- declaration whose designated type is the non-limited view
1541 if Ekind (Actual_DDT) = E_Incomplete_Type
1542 and then Present (Non_Limited_View (Actual_DDT))
1544 Anon := New_Copy (Actual_Typ);
1546 if Is_Itype (Anon) then
1547 Set_Scope (Anon, Current_Scope);
1550 Set_Directly_Designated_Type (Anon,
1551 Non_Limited_View (Actual_DDT));
1552 Set_Etype (Actual_Dup, Anon);
1554 elsif Is_Class_Wide_Type (Actual_DDT)
1555 and then Ekind (Etype (Actual_DDT)) = E_Incomplete_Type
1556 and then Present (Non_Limited_View (Etype (Actual_DDT)))
1558 Anon := New_Copy (Actual_Typ);
1560 if Is_Itype (Anon) then
1561 Set_Scope (Anon, Current_Scope);
1564 Set_Directly_Designated_Type (Anon,
1565 New_Copy (Actual_DDT));
1566 Set_Class_Wide_Type (Directly_Designated_Type (Anon),
1567 New_Copy (Class_Wide_Type (Actual_DDT)));
1568 Set_Etype (Directly_Designated_Type (Anon),
1569 Non_Limited_View (Etype (Actual_DDT)));
1571 Class_Wide_Type (Directly_Designated_Type (Anon)),
1572 Non_Limited_View (Etype (Actual_DDT)));
1573 Set_Etype (Actual_Dup, Anon);
1577 Conversion := Convert_To (Formal_Typ, Actual_Dup);
1578 Rewrite (Actual, Conversion);
1579 Analyze_And_Resolve (Actual, Formal_Typ);
1583 Next_Actual (Actual);
1584 Next_Formal (Formal);
1586 end Expand_Interface_Actuals;
1588 ----------------------------
1589 -- Expand_Interface_Thunk --
1590 ----------------------------
1592 procedure Expand_Interface_Thunk
1594 Thunk_Id : out Entity_Id;
1595 Thunk_Code : out Node_Id)
1597 Loc : constant Source_Ptr := Sloc (Prim);
1598 Actuals : constant List_Id := New_List;
1599 Decl : constant List_Id := New_List;
1600 Formals : constant List_Id := New_List;
1601 Target : constant Entity_Id := Ultimate_Alias (Prim);
1603 Controlling_Typ : Entity_Id;
1609 Iface_Formal : Node_Id;
1611 Offset_To_Top : Node_Id;
1612 Target_Formal : Entity_Id;
1616 Thunk_Code := Empty;
1618 -- No thunk needed if the primitive has been eliminated
1620 if Is_Eliminated (Ultimate_Alias (Prim)) then
1623 -- In case of primitives that are functions without formals and a
1624 -- controlling result there is no need to build the thunk.
1626 elsif not Present (First_Formal (Target)) then
1627 pragma Assert (Ekind (Target) = E_Function
1628 and then Has_Controlling_Result (Target));
1632 -- Duplicate the formals of the Target primitive. In the thunk, the type
1633 -- of the controlling formal is the covered interface type (instead of
1634 -- the target tagged type). Done to avoid problems with discriminated
1635 -- tagged types because, if the controlling type has discriminants with
1636 -- default values, then the type conversions done inside the body of
1637 -- the thunk (after the displacement of the pointer to the base of the
1638 -- actual object) generate code that modify its contents.
1640 -- Note: This special management is not done for predefined primitives
1643 if not Is_Predefined_Dispatching_Operation (Prim) then
1644 Iface_Formal := First_Formal (Interface_Alias (Prim));
1647 Formal := First_Formal (Target);
1648 while Present (Formal) loop
1649 Ftyp := Etype (Formal);
1651 -- Use the interface type as the type of the controlling formal (see
1654 if not Is_Controlling_Formal (Formal)
1655 or else Is_Predefined_Dispatching_Operation (Prim)
1657 Ftyp := Etype (Formal);
1658 Expr := New_Copy_Tree (Expression (Parent (Formal)));
1660 Ftyp := Etype (Iface_Formal);
1665 Make_Parameter_Specification (Loc,
1666 Defining_Identifier =>
1667 Make_Defining_Identifier (Sloc (Formal),
1668 Chars => Chars (Formal)),
1669 In_Present => In_Present (Parent (Formal)),
1670 Out_Present => Out_Present (Parent (Formal)),
1671 Parameter_Type => New_Reference_To (Ftyp, Loc),
1672 Expression => Expr));
1674 if not Is_Predefined_Dispatching_Operation (Prim) then
1675 Next_Formal (Iface_Formal);
1678 Next_Formal (Formal);
1681 Controlling_Typ := Find_Dispatching_Type (Target);
1683 Target_Formal := First_Formal (Target);
1684 Formal := First (Formals);
1685 while Present (Formal) loop
1687 -- If the parent is a constrained discriminated type, then the
1688 -- primitive operation will have been defined on a first subtype.
1689 -- For proper matching with controlling type, use base type.
1691 if Ekind (Target_Formal) = E_In_Parameter
1692 and then Ekind (Etype (Target_Formal)) = E_Anonymous_Access_Type
1695 Base_Type (Directly_Designated_Type (Etype (Target_Formal)));
1697 Ftyp := Base_Type (Etype (Target_Formal));
1700 -- For concurrent types, the relevant information is found in the
1701 -- Corresponding_Record_Type, rather than the type entity itself.
1703 if Is_Concurrent_Type (Ftyp) then
1704 Ftyp := Corresponding_Record_Type (Ftyp);
1707 if Ekind (Target_Formal) = E_In_Parameter
1708 and then Ekind (Etype (Target_Formal)) = E_Anonymous_Access_Type
1709 and then Ftyp = Controlling_Typ
1712 -- type T is access all <<type of the target formal>>
1713 -- S : Storage_Offset := Storage_Offset!(Formal)
1714 -- - Offset_To_Top (address!(Formal))
1717 Make_Full_Type_Declaration (Loc,
1718 Defining_Identifier => Make_Temporary (Loc, 'T'),
1720 Make_Access_To_Object_Definition (Loc,
1721 All_Present => True,
1722 Null_Exclusion_Present => False,
1723 Constant_Present => False,
1724 Subtype_Indication =>
1725 New_Reference_To (Ftyp, Loc)));
1728 Unchecked_Convert_To (RTE (RE_Address),
1729 New_Reference_To (Defining_Identifier (Formal), Loc));
1731 if not RTE_Available (RE_Offset_To_Top) then
1733 Build_Offset_To_Top (Loc, New_Arg);
1736 Make_Function_Call (Loc,
1737 Name => New_Reference_To (RTE (RE_Offset_To_Top), Loc),
1738 Parameter_Associations => New_List (New_Arg));
1742 Make_Object_Declaration (Loc,
1743 Defining_Identifier => Make_Temporary (Loc, 'S'),
1744 Constant_Present => True,
1745 Object_Definition =>
1746 New_Reference_To (RTE (RE_Storage_Offset), Loc),
1748 Make_Op_Subtract (Loc,
1750 Unchecked_Convert_To
1751 (RTE (RE_Storage_Offset),
1752 New_Reference_To (Defining_Identifier (Formal), Loc)),
1756 Append_To (Decl, Decl_2);
1757 Append_To (Decl, Decl_1);
1759 -- Reference the new actual. Generate:
1763 Unchecked_Convert_To
1764 (Defining_Identifier (Decl_2),
1765 New_Reference_To (Defining_Identifier (Decl_1), Loc)));
1767 elsif Ftyp = Controlling_Typ then
1770 -- S1 : Storage_Offset := Storage_Offset!(Formal'Address)
1771 -- - Offset_To_Top (Formal'Address)
1772 -- S2 : Addr_Ptr := Addr_Ptr!(S1)
1775 Make_Attribute_Reference (Loc,
1777 New_Reference_To (Defining_Identifier (Formal), Loc),
1781 if not RTE_Available (RE_Offset_To_Top) then
1783 Build_Offset_To_Top (Loc, New_Arg);
1786 Make_Function_Call (Loc,
1787 Name => New_Reference_To (RTE (RE_Offset_To_Top), Loc),
1788 Parameter_Associations => New_List (New_Arg));
1792 Make_Object_Declaration (Loc,
1793 Defining_Identifier => Make_Temporary (Loc, 'S'),
1794 Constant_Present => True,
1795 Object_Definition =>
1796 New_Reference_To (RTE (RE_Storage_Offset), Loc),
1798 Make_Op_Subtract (Loc,
1800 Unchecked_Convert_To
1801 (RTE (RE_Storage_Offset),
1802 Make_Attribute_Reference (Loc,
1805 (Defining_Identifier (Formal), Loc),
1806 Attribute_Name => Name_Address)),
1811 Make_Object_Declaration (Loc,
1812 Defining_Identifier => Make_Temporary (Loc, 'S'),
1813 Constant_Present => True,
1814 Object_Definition =>
1815 New_Reference_To (RTE (RE_Addr_Ptr), Loc),
1817 Unchecked_Convert_To
1819 New_Reference_To (Defining_Identifier (Decl_1), Loc)));
1821 Append_To (Decl, Decl_1);
1822 Append_To (Decl, Decl_2);
1824 -- Reference the new actual, generate:
1825 -- Target_Formal (S2.all)
1828 Unchecked_Convert_To (Ftyp,
1829 Make_Explicit_Dereference (Loc,
1830 New_Reference_To (Defining_Identifier (Decl_2), Loc))));
1832 -- No special management required for this actual
1836 New_Reference_To (Defining_Identifier (Formal), Loc));
1839 Next_Formal (Target_Formal);
1843 Thunk_Id := Make_Temporary (Loc, 'T');
1844 Set_Is_Thunk (Thunk_Id);
1848 if Ekind (Target) = E_Procedure then
1850 Make_Subprogram_Body (Loc,
1852 Make_Procedure_Specification (Loc,
1853 Defining_Unit_Name => Thunk_Id,
1854 Parameter_Specifications => Formals),
1855 Declarations => Decl,
1856 Handled_Statement_Sequence =>
1857 Make_Handled_Sequence_Of_Statements (Loc,
1858 Statements => New_List (
1859 Make_Procedure_Call_Statement (Loc,
1860 Name => New_Occurrence_Of (Target, Loc),
1861 Parameter_Associations => Actuals))));
1865 else pragma Assert (Ekind (Target) = E_Function);
1867 Make_Subprogram_Body (Loc,
1869 Make_Function_Specification (Loc,
1870 Defining_Unit_Name => Thunk_Id,
1871 Parameter_Specifications => Formals,
1872 Result_Definition =>
1873 New_Copy (Result_Definition (Parent (Target)))),
1874 Declarations => Decl,
1875 Handled_Statement_Sequence =>
1876 Make_Handled_Sequence_Of_Statements (Loc,
1877 Statements => New_List (
1878 Make_Simple_Return_Statement (Loc,
1879 Make_Function_Call (Loc,
1880 Name => New_Occurrence_Of (Target, Loc),
1881 Parameter_Associations => Actuals)))));
1883 end Expand_Interface_Thunk;
1885 ------------------------
1886 -- Find_Specific_Type --
1887 ------------------------
1889 function Find_Specific_Type (CW : Entity_Id) return Entity_Id is
1890 Typ : Entity_Id := Root_Type (CW);
1893 if Ekind (Typ) = E_Incomplete_Type then
1894 if From_With_Type (Typ) then
1895 Typ := Non_Limited_View (Typ);
1897 Typ := Full_View (Typ);
1902 end Find_Specific_Type;
1904 --------------------------
1905 -- Has_CPP_Constructors --
1906 --------------------------
1908 function Has_CPP_Constructors (Typ : Entity_Id) return Boolean is
1912 -- Look for the constructor entities
1914 E := Next_Entity (Typ);
1915 while Present (E) loop
1916 if Ekind (E) = E_Function
1917 and then Is_Constructor (E)
1926 end Has_CPP_Constructors;
1932 function Has_DT (Typ : Entity_Id) return Boolean is
1934 return not Is_Interface (Typ)
1935 and then not Restriction_Active (No_Dispatching_Calls);
1938 -----------------------------------------
1939 -- Is_Predefined_Dispatching_Operation --
1940 -----------------------------------------
1942 function Is_Predefined_Dispatching_Operation
1943 (E : Entity_Id) return Boolean
1945 TSS_Name : TSS_Name_Type;
1948 if not Is_Dispatching_Operation (E) then
1952 Get_Name_String (Chars (E));
1954 -- Most predefined primitives have internally generated names. Equality
1955 -- must be treated differently; the predefined operation is recognized
1956 -- as a homogeneous binary operator that returns Boolean.
1958 if Name_Len > TSS_Name_Type'Last then
1959 TSS_Name := TSS_Name_Type (Name_Buffer (Name_Len - TSS_Name'Length + 1
1961 if Chars (E) = Name_uSize
1962 or else TSS_Name = TSS_Stream_Read
1963 or else TSS_Name = TSS_Stream_Write
1964 or else TSS_Name = TSS_Stream_Input
1965 or else TSS_Name = TSS_Stream_Output
1967 (Chars (E) = Name_Op_Eq
1968 and then Etype (First_Formal (E)) = Etype (Last_Formal (E)))
1969 or else Chars (E) = Name_uAssign
1970 or else TSS_Name = TSS_Deep_Adjust
1971 or else TSS_Name = TSS_Deep_Finalize
1972 or else Is_Predefined_Interface_Primitive (E)
1979 end Is_Predefined_Dispatching_Operation;
1981 ---------------------------------------
1982 -- Is_Predefined_Internal_Operation --
1983 ---------------------------------------
1985 function Is_Predefined_Internal_Operation
1986 (E : Entity_Id) return Boolean
1988 TSS_Name : TSS_Name_Type;
1991 if not Is_Dispatching_Operation (E) then
1995 Get_Name_String (Chars (E));
1997 -- Most predefined primitives have internally generated names. Equality
1998 -- must be treated differently; the predefined operation is recognized
1999 -- as a homogeneous binary operator that returns Boolean.
2001 if Name_Len > TSS_Name_Type'Last then
2004 (Name_Buffer (Name_Len - TSS_Name'Length + 1 .. Name_Len));
2006 if Chars (E) = Name_uSize
2008 (Chars (E) = Name_Op_Eq
2009 and then Etype (First_Formal (E)) = Etype (Last_Formal (E)))
2010 or else Chars (E) = Name_uAssign
2011 or else TSS_Name = TSS_Deep_Adjust
2012 or else TSS_Name = TSS_Deep_Finalize
2013 or else Is_Predefined_Interface_Primitive (E)
2020 end Is_Predefined_Internal_Operation;
2022 -------------------------------------
2023 -- Is_Predefined_Dispatching_Alias --
2024 -------------------------------------
2026 function Is_Predefined_Dispatching_Alias (Prim : Entity_Id) return Boolean
2029 return not Is_Predefined_Dispatching_Operation (Prim)
2030 and then Present (Alias (Prim))
2031 and then Is_Predefined_Dispatching_Operation (Ultimate_Alias (Prim));
2032 end Is_Predefined_Dispatching_Alias;
2034 ---------------------------------------
2035 -- Is_Predefined_Interface_Primitive --
2036 ---------------------------------------
2038 function Is_Predefined_Interface_Primitive (E : Entity_Id) return Boolean is
2040 -- In VM targets we don't restrict the functionality of this test to
2041 -- compiling in Ada 2005 mode since in VM targets any tagged type has
2044 return (Ada_Version >= Ada_2005 or else not Tagged_Type_Expansion)
2045 and then (Chars (E) = Name_uDisp_Asynchronous_Select or else
2046 Chars (E) = Name_uDisp_Conditional_Select or else
2047 Chars (E) = Name_uDisp_Get_Prim_Op_Kind or else
2048 Chars (E) = Name_uDisp_Get_Task_Id or else
2049 Chars (E) = Name_uDisp_Requeue or else
2050 Chars (E) = Name_uDisp_Timed_Select);
2051 end Is_Predefined_Interface_Primitive;
2053 ----------------------------------------
2054 -- Make_Disp_Asynchronous_Select_Body --
2055 ----------------------------------------
2057 -- For interface types, generate:
2059 -- procedure _Disp_Asynchronous_Select
2060 -- (T : in out <Typ>;
2062 -- P : System.Address;
2063 -- B : out System.Storage_Elements.Dummy_Communication_Block;
2068 -- C := Ada.Tags.POK_Function;
2069 -- end _Disp_Asynchronous_Select;
2071 -- For protected types, generate:
2073 -- procedure _Disp_Asynchronous_Select
2074 -- (T : in out <Typ>;
2076 -- P : System.Address;
2077 -- B : out System.Storage_Elements.Dummy_Communication_Block;
2081 -- Ada.Tags.Get_Entry_Index (Ada.Tags.Tag (<Typ>VP, S));
2082 -- Bnn : System.Tasking.Protected_Objects.Operations.
2083 -- Communication_Block;
2085 -- System.Tasking.Protected_Objects.Operations.Protected_Entry_Call
2086 -- (T._object'Access,
2087 -- System.Tasking.Protected_Objects.Protected_Entry_Index (I),
2089 -- System.Tasking.Asynchronous_Call,
2091 -- B := System.Storage_Elements.Dummy_Communication_Block (Bnn);
2092 -- end _Disp_Asynchronous_Select;
2094 -- For task types, generate:
2096 -- procedure _Disp_Asynchronous_Select
2097 -- (T : in out <Typ>;
2099 -- P : System.Address;
2100 -- B : out System.Storage_Elements.Dummy_Communication_Block;
2104 -- Ada.Tags.Get_Entry_Index (Ada.Tags.Tag (<Typ>VP, S));
2106 -- System.Tasking.Rendezvous.Task_Entry_Call
2108 -- System.Tasking.Task_Entry_Index (I),
2110 -- System.Tasking.Asynchronous_Call,
2112 -- end _Disp_Asynchronous_Select;
2114 function Make_Disp_Asynchronous_Select_Body
2115 (Typ : Entity_Id) return Node_Id
2117 Com_Block : Entity_Id;
2118 Conc_Typ : Entity_Id := Empty;
2119 Decls : constant List_Id := New_List;
2120 Loc : constant Source_Ptr := Sloc (Typ);
2122 Stmts : constant List_Id := New_List;
2126 pragma Assert (not Restriction_Active (No_Dispatching_Calls));
2128 -- Null body is generated for interface types
2130 if Is_Interface (Typ) then
2132 Make_Subprogram_Body (Loc,
2133 Specification => Make_Disp_Asynchronous_Select_Spec (Typ),
2134 Declarations => New_List,
2135 Handled_Statement_Sequence =>
2136 Make_Handled_Sequence_Of_Statements (Loc,
2137 New_List (Make_Assignment_Statement (Loc,
2138 Name => Make_Identifier (Loc, Name_uF),
2139 Expression => New_Reference_To (Standard_False, Loc)))));
2142 if Is_Concurrent_Record_Type (Typ) then
2143 Conc_Typ := Corresponding_Concurrent_Type (Typ);
2147 -- Ada.Tags.Get_Entry_Index (Ada.Tags.Tag! (<type>VP), S);
2149 -- where I will be used to capture the entry index of the primitive
2150 -- wrapper at position S.
2152 if Tagged_Type_Expansion then
2154 Unchecked_Convert_To (RTE (RE_Tag),
2156 (Node (First_Elmt (Access_Disp_Table (Typ))), Loc));
2159 Make_Attribute_Reference (Loc,
2160 Prefix => New_Reference_To (Typ, Loc),
2161 Attribute_Name => Name_Tag);
2165 Make_Object_Declaration (Loc,
2166 Defining_Identifier =>
2167 Make_Defining_Identifier (Loc, Name_uI),
2168 Object_Definition =>
2169 New_Reference_To (Standard_Integer, Loc),
2171 Make_Function_Call (Loc,
2173 New_Reference_To (RTE (RE_Get_Entry_Index), Loc),
2174 Parameter_Associations =>
2177 Make_Identifier (Loc, Name_uS)))));
2179 if Ekind (Conc_Typ) = E_Protected_Type then
2182 -- Bnn : Communication_Block;
2184 Com_Block := Make_Temporary (Loc, 'B');
2186 Make_Object_Declaration (Loc,
2187 Defining_Identifier =>
2189 Object_Definition =>
2190 New_Reference_To (RTE (RE_Communication_Block), Loc)));
2192 -- Build T._object'Access for calls below
2195 Make_Attribute_Reference (Loc,
2196 Attribute_Name => Name_Unchecked_Access,
2198 Make_Selected_Component (Loc,
2199 Prefix => Make_Identifier (Loc, Name_uT),
2200 Selector_Name => Make_Identifier (Loc, Name_uObject)));
2202 case Corresponding_Runtime_Package (Conc_Typ) is
2203 when System_Tasking_Protected_Objects_Entries =>
2206 -- Protected_Entry_Call
2207 -- (T._object'Access, -- Object
2208 -- Protected_Entry_Index! (I), -- E
2209 -- P, -- Uninterpreted_Data
2210 -- Asynchronous_Call, -- Mode
2211 -- Bnn); -- Communication_Block
2213 -- where T is the protected object, I is the entry index, P
2214 -- is the wrapped parameters and B is the name of the
2215 -- communication block.
2218 Make_Procedure_Call_Statement (Loc,
2220 New_Reference_To (RTE (RE_Protected_Entry_Call), Loc),
2221 Parameter_Associations =>
2225 Make_Unchecked_Type_Conversion (Loc, -- entry index
2228 (RTE (RE_Protected_Entry_Index), Loc),
2229 Expression => Make_Identifier (Loc, Name_uI)),
2231 Make_Identifier (Loc, Name_uP), -- parameter block
2232 New_Reference_To -- Asynchronous_Call
2233 (RTE (RE_Asynchronous_Call), Loc),
2235 New_Reference_To (Com_Block, Loc)))); -- comm block
2237 when System_Tasking_Protected_Objects_Single_Entry =>
2240 -- procedure Protected_Single_Entry_Call
2241 -- (Object : Protection_Entry_Access;
2242 -- Uninterpreted_Data : System.Address;
2243 -- Mode : Call_Modes);
2246 Make_Procedure_Call_Statement (Loc,
2249 (RTE (RE_Protected_Single_Entry_Call), Loc),
2250 Parameter_Associations =>
2254 Make_Attribute_Reference (Loc,
2255 Prefix => Make_Identifier (Loc, Name_uP),
2256 Attribute_Name => Name_Address),
2259 (RTE (RE_Asynchronous_Call), Loc))));
2262 raise Program_Error;
2266 -- B := Dummy_Communication_Block (Bnn);
2269 Make_Assignment_Statement (Loc,
2270 Name => Make_Identifier (Loc, Name_uB),
2272 Make_Unchecked_Type_Conversion (Loc,
2275 RTE (RE_Dummy_Communication_Block), Loc),
2277 New_Reference_To (Com_Block, Loc))));
2283 Make_Assignment_Statement (Loc,
2284 Name => Make_Identifier (Loc, Name_uF),
2285 Expression => New_Reference_To (Standard_False, Loc)));
2288 pragma Assert (Ekind (Conc_Typ) = E_Task_Type);
2292 -- (T._task_id, -- Acceptor
2293 -- Task_Entry_Index! (I), -- E
2294 -- P, -- Uninterpreted_Data
2295 -- Asynchronous_Call, -- Mode
2296 -- F); -- Rendezvous_Successful
2298 -- where T is the task object, I is the entry index, P is the
2299 -- wrapped parameters and F is the status flag.
2302 Make_Procedure_Call_Statement (Loc,
2304 New_Reference_To (RTE (RE_Task_Entry_Call), Loc),
2305 Parameter_Associations =>
2307 Make_Selected_Component (Loc, -- T._task_id
2308 Prefix => Make_Identifier (Loc, Name_uT),
2309 Selector_Name => Make_Identifier (Loc, Name_uTask_Id)),
2311 Make_Unchecked_Type_Conversion (Loc, -- entry index
2313 New_Reference_To (RTE (RE_Task_Entry_Index), Loc),
2314 Expression => Make_Identifier (Loc, Name_uI)),
2316 Make_Identifier (Loc, Name_uP), -- parameter block
2317 New_Reference_To -- Asynchronous_Call
2318 (RTE (RE_Asynchronous_Call), Loc),
2319 Make_Identifier (Loc, Name_uF)))); -- status flag
2323 -- Ensure that the statements list is non-empty
2326 Make_Assignment_Statement (Loc,
2327 Name => Make_Identifier (Loc, Name_uF),
2328 Expression => New_Reference_To (Standard_False, Loc)));
2332 Make_Subprogram_Body (Loc,
2334 Make_Disp_Asynchronous_Select_Spec (Typ),
2335 Declarations => Decls,
2336 Handled_Statement_Sequence =>
2337 Make_Handled_Sequence_Of_Statements (Loc, Stmts));
2338 end Make_Disp_Asynchronous_Select_Body;
2340 ----------------------------------------
2341 -- Make_Disp_Asynchronous_Select_Spec --
2342 ----------------------------------------
2344 function Make_Disp_Asynchronous_Select_Spec
2345 (Typ : Entity_Id) return Node_Id
2347 Loc : constant Source_Ptr := Sloc (Typ);
2348 Def_Id : constant Node_Id :=
2349 Make_Defining_Identifier (Loc,
2350 Name_uDisp_Asynchronous_Select);
2351 Params : constant List_Id := New_List;
2354 pragma Assert (not Restriction_Active (No_Dispatching_Calls));
2356 -- T : in out Typ; -- Object parameter
2357 -- S : Integer; -- Primitive operation slot
2358 -- P : Address; -- Wrapped parameters
2359 -- B : out Dummy_Communication_Block; -- Communication block dummy
2360 -- F : out Boolean; -- Status flag
2362 Append_List_To (Params, New_List (
2364 Make_Parameter_Specification (Loc,
2365 Defining_Identifier =>
2366 Make_Defining_Identifier (Loc, Name_uT),
2368 New_Reference_To (Typ, Loc),
2370 Out_Present => True),
2372 Make_Parameter_Specification (Loc,
2373 Defining_Identifier =>
2374 Make_Defining_Identifier (Loc, Name_uS),
2376 New_Reference_To (Standard_Integer, Loc)),
2378 Make_Parameter_Specification (Loc,
2379 Defining_Identifier =>
2380 Make_Defining_Identifier (Loc, Name_uP),
2382 New_Reference_To (RTE (RE_Address), Loc)),
2384 Make_Parameter_Specification (Loc,
2385 Defining_Identifier =>
2386 Make_Defining_Identifier (Loc, Name_uB),
2388 New_Reference_To (RTE (RE_Dummy_Communication_Block), Loc),
2389 Out_Present => True),
2391 Make_Parameter_Specification (Loc,
2392 Defining_Identifier =>
2393 Make_Defining_Identifier (Loc, Name_uF),
2395 New_Reference_To (Standard_Boolean, Loc),
2396 Out_Present => True)));
2399 Make_Procedure_Specification (Loc,
2400 Defining_Unit_Name => Def_Id,
2401 Parameter_Specifications => Params);
2402 end Make_Disp_Asynchronous_Select_Spec;
2404 ---------------------------------------
2405 -- Make_Disp_Conditional_Select_Body --
2406 ---------------------------------------
2408 -- For interface types, generate:
2410 -- procedure _Disp_Conditional_Select
2411 -- (T : in out <Typ>;
2413 -- P : System.Address;
2414 -- C : out Ada.Tags.Prim_Op_Kind;
2419 -- C := Ada.Tags.POK_Function;
2420 -- end _Disp_Conditional_Select;
2422 -- For protected types, generate:
2424 -- procedure _Disp_Conditional_Select
2425 -- (T : in out <Typ>;
2427 -- P : System.Address;
2428 -- C : out Ada.Tags.Prim_Op_Kind;
2432 -- Bnn : System.Tasking.Protected_Objects.Operations.
2433 -- Communication_Block;
2436 -- C := Ada.Tags.Get_Prim_Op_Kind (Ada.Tags.Tag (<Typ>VP, S));
2438 -- if C = Ada.Tags.POK_Procedure
2439 -- or else C = Ada.Tags.POK_Protected_Procedure
2440 -- or else C = Ada.Tags.POK_Task_Procedure
2446 -- I := Ada.Tags.Get_Entry_Index (Ada.Tags.Tag (<Typ>VP, S));
2447 -- System.Tasking.Protected_Objects.Operations.Protected_Entry_Call
2448 -- (T.object'Access,
2449 -- System.Tasking.Protected_Objects.Protected_Entry_Index (I),
2451 -- System.Tasking.Conditional_Call,
2453 -- F := not Cancelled (Bnn);
2454 -- end _Disp_Conditional_Select;
2456 -- For task types, generate:
2458 -- procedure _Disp_Conditional_Select
2459 -- (T : in out <Typ>;
2461 -- P : System.Address;
2462 -- C : out Ada.Tags.Prim_Op_Kind;
2468 -- I := Ada.Tags.Get_Entry_Index (Ada.Tags.Tag (<Typ>VP, S));
2469 -- System.Tasking.Rendezvous.Task_Entry_Call
2471 -- System.Tasking.Task_Entry_Index (I),
2473 -- System.Tasking.Conditional_Call,
2475 -- end _Disp_Conditional_Select;
2477 function Make_Disp_Conditional_Select_Body
2478 (Typ : Entity_Id) return Node_Id
2480 Loc : constant Source_Ptr := Sloc (Typ);
2481 Blk_Nam : Entity_Id;
2482 Conc_Typ : Entity_Id := Empty;
2483 Decls : constant List_Id := New_List;
2485 Stmts : constant List_Id := New_List;
2489 pragma Assert (not Restriction_Active (No_Dispatching_Calls));
2491 -- Null body is generated for interface types
2493 if Is_Interface (Typ) then
2495 Make_Subprogram_Body (Loc,
2497 Make_Disp_Conditional_Select_Spec (Typ),
2500 Handled_Statement_Sequence =>
2501 Make_Handled_Sequence_Of_Statements (Loc,
2502 New_List (Make_Assignment_Statement (Loc,
2503 Name => Make_Identifier (Loc, Name_uF),
2504 Expression => New_Reference_To (Standard_False, Loc)))));
2507 if Is_Concurrent_Record_Type (Typ) then
2508 Conc_Typ := Corresponding_Concurrent_Type (Typ);
2513 -- where I will be used to capture the entry index of the primitive
2514 -- wrapper at position S.
2517 Make_Object_Declaration (Loc,
2518 Defining_Identifier =>
2519 Make_Defining_Identifier (Loc, Name_uI),
2520 Object_Definition =>
2521 New_Reference_To (Standard_Integer, Loc)));
2524 -- C := Ada.Tags.Get_Prim_Op_Kind (Ada.Tags.Tag! (<type>VP), S);
2526 -- if C = POK_Procedure
2527 -- or else C = POK_Protected_Procedure
2528 -- or else C = POK_Task_Procedure;
2534 Build_Common_Dispatching_Select_Statements (Typ, Stmts);
2537 -- Bnn : Communication_Block;
2539 -- where Bnn is the name of the communication block used in the
2540 -- call to Protected_Entry_Call.
2542 Blk_Nam := Make_Temporary (Loc, 'B');
2544 Make_Object_Declaration (Loc,
2545 Defining_Identifier =>
2547 Object_Definition =>
2548 New_Reference_To (RTE (RE_Communication_Block), Loc)));
2551 -- I := Ada.Tags.Get_Entry_Index (Ada.Tags.Tag! (<type>VP), S);
2553 -- I is the entry index and S is the dispatch table slot
2555 if Tagged_Type_Expansion then
2557 Unchecked_Convert_To (RTE (RE_Tag),
2559 (Node (First_Elmt (Access_Disp_Table (Typ))), Loc));
2563 Make_Attribute_Reference (Loc,
2564 Prefix => New_Reference_To (Typ, Loc),
2565 Attribute_Name => Name_Tag);
2569 Make_Assignment_Statement (Loc,
2570 Name => Make_Identifier (Loc, Name_uI),
2572 Make_Function_Call (Loc,
2574 New_Reference_To (RTE (RE_Get_Entry_Index), Loc),
2575 Parameter_Associations =>
2578 Make_Identifier (Loc, Name_uS)))));
2580 if Ekind (Conc_Typ) = E_Protected_Type then
2582 Obj_Ref := -- T._object'Access
2583 Make_Attribute_Reference (Loc,
2584 Attribute_Name => Name_Unchecked_Access,
2586 Make_Selected_Component (Loc,
2587 Prefix => Make_Identifier (Loc, Name_uT),
2588 Selector_Name => Make_Identifier (Loc, Name_uObject)));
2590 case Corresponding_Runtime_Package (Conc_Typ) is
2591 when System_Tasking_Protected_Objects_Entries =>
2594 -- Protected_Entry_Call
2595 -- (T._object'Access, -- Object
2596 -- Protected_Entry_Index! (I), -- E
2597 -- P, -- Uninterpreted_Data
2598 -- Conditional_Call, -- Mode
2601 -- where T is the protected object, I is the entry index, P
2602 -- are the wrapped parameters and Bnn is the name of the
2603 -- communication block.
2606 Make_Procedure_Call_Statement (Loc,
2608 New_Reference_To (RTE (RE_Protected_Entry_Call), Loc),
2609 Parameter_Associations =>
2613 Make_Unchecked_Type_Conversion (Loc, -- entry index
2616 (RTE (RE_Protected_Entry_Index), Loc),
2617 Expression => Make_Identifier (Loc, Name_uI)),
2619 Make_Identifier (Loc, Name_uP), -- parameter block
2621 New_Reference_To ( -- Conditional_Call
2622 RTE (RE_Conditional_Call), Loc),
2623 New_Reference_To ( -- Bnn
2626 when System_Tasking_Protected_Objects_Single_Entry =>
2628 -- If we are compiling for a restricted run-time, the call
2629 -- uses the simpler form.
2632 Make_Procedure_Call_Statement (Loc,
2635 (RTE (RE_Protected_Single_Entry_Call), Loc),
2636 Parameter_Associations =>
2640 Make_Attribute_Reference (Loc,
2641 Prefix => Make_Identifier (Loc, Name_uP),
2642 Attribute_Name => Name_Address),
2645 (RTE (RE_Conditional_Call), Loc))));
2647 raise Program_Error;
2651 -- F := not Cancelled (Bnn);
2653 -- where F is the success flag. The status of Cancelled is negated
2654 -- in order to match the behaviour of the version for task types.
2657 Make_Assignment_Statement (Loc,
2658 Name => Make_Identifier (Loc, Name_uF),
2662 Make_Function_Call (Loc,
2664 New_Reference_To (RTE (RE_Cancelled), Loc),
2665 Parameter_Associations =>
2667 New_Reference_To (Blk_Nam, Loc))))));
2669 pragma Assert (Ekind (Conc_Typ) = E_Task_Type);
2673 -- (T._task_id, -- Acceptor
2674 -- Task_Entry_Index! (I), -- E
2675 -- P, -- Uninterpreted_Data
2676 -- Conditional_Call, -- Mode
2677 -- F); -- Rendezvous_Successful
2679 -- where T is the task object, I is the entry index, P are the
2680 -- wrapped parameters and F is the status flag.
2683 Make_Procedure_Call_Statement (Loc,
2685 New_Reference_To (RTE (RE_Task_Entry_Call), Loc),
2686 Parameter_Associations =>
2689 Make_Selected_Component (Loc, -- T._task_id
2690 Prefix => Make_Identifier (Loc, Name_uT),
2691 Selector_Name => Make_Identifier (Loc, Name_uTask_Id)),
2693 Make_Unchecked_Type_Conversion (Loc, -- entry index
2695 New_Reference_To (RTE (RE_Task_Entry_Index), Loc),
2696 Expression => Make_Identifier (Loc, Name_uI)),
2698 Make_Identifier (Loc, Name_uP), -- parameter block
2699 New_Reference_To -- Conditional_Call
2700 (RTE (RE_Conditional_Call), Loc),
2701 Make_Identifier (Loc, Name_uF)))); -- status flag
2705 -- Initialize out parameters
2708 Make_Assignment_Statement (Loc,
2709 Name => Make_Identifier (Loc, Name_uF),
2710 Expression => New_Reference_To (Standard_False, Loc)));
2712 Make_Assignment_Statement (Loc,
2713 Name => Make_Identifier (Loc, Name_uC),
2714 Expression => New_Reference_To (RTE (RE_POK_Function), Loc)));
2718 Make_Subprogram_Body (Loc,
2720 Make_Disp_Conditional_Select_Spec (Typ),
2721 Declarations => Decls,
2722 Handled_Statement_Sequence =>
2723 Make_Handled_Sequence_Of_Statements (Loc, Stmts));
2724 end Make_Disp_Conditional_Select_Body;
2726 ---------------------------------------
2727 -- Make_Disp_Conditional_Select_Spec --
2728 ---------------------------------------
2730 function Make_Disp_Conditional_Select_Spec
2731 (Typ : Entity_Id) return Node_Id
2733 Loc : constant Source_Ptr := Sloc (Typ);
2734 Def_Id : constant Node_Id :=
2735 Make_Defining_Identifier (Loc,
2736 Name_uDisp_Conditional_Select);
2737 Params : constant List_Id := New_List;
2740 pragma Assert (not Restriction_Active (No_Dispatching_Calls));
2742 -- T : in out Typ; -- Object parameter
2743 -- S : Integer; -- Primitive operation slot
2744 -- P : Address; -- Wrapped parameters
2745 -- C : out Prim_Op_Kind; -- Call kind
2746 -- F : out Boolean; -- Status flag
2748 Append_List_To (Params, New_List (
2750 Make_Parameter_Specification (Loc,
2751 Defining_Identifier =>
2752 Make_Defining_Identifier (Loc, Name_uT),
2754 New_Reference_To (Typ, Loc),
2756 Out_Present => True),
2758 Make_Parameter_Specification (Loc,
2759 Defining_Identifier =>
2760 Make_Defining_Identifier (Loc, Name_uS),
2762 New_Reference_To (Standard_Integer, Loc)),
2764 Make_Parameter_Specification (Loc,
2765 Defining_Identifier =>
2766 Make_Defining_Identifier (Loc, Name_uP),
2768 New_Reference_To (RTE (RE_Address), Loc)),
2770 Make_Parameter_Specification (Loc,
2771 Defining_Identifier =>
2772 Make_Defining_Identifier (Loc, Name_uC),
2774 New_Reference_To (RTE (RE_Prim_Op_Kind), Loc),
2775 Out_Present => True),
2777 Make_Parameter_Specification (Loc,
2778 Defining_Identifier =>
2779 Make_Defining_Identifier (Loc, Name_uF),
2781 New_Reference_To (Standard_Boolean, Loc),
2782 Out_Present => True)));
2785 Make_Procedure_Specification (Loc,
2786 Defining_Unit_Name => Def_Id,
2787 Parameter_Specifications => Params);
2788 end Make_Disp_Conditional_Select_Spec;
2790 -------------------------------------
2791 -- Make_Disp_Get_Prim_Op_Kind_Body --
2792 -------------------------------------
2794 function Make_Disp_Get_Prim_Op_Kind_Body
2795 (Typ : Entity_Id) return Node_Id
2797 Loc : constant Source_Ptr := Sloc (Typ);
2801 pragma Assert (not Restriction_Active (No_Dispatching_Calls));
2803 if Is_Interface (Typ) then
2805 Make_Subprogram_Body (Loc,
2807 Make_Disp_Get_Prim_Op_Kind_Spec (Typ),
2810 Handled_Statement_Sequence =>
2811 Make_Handled_Sequence_Of_Statements (Loc,
2812 New_List (Make_Null_Statement (Loc))));
2816 -- C := get_prim_op_kind (tag! (<type>VP), S);
2818 -- where C is the out parameter capturing the call kind and S is the
2819 -- dispatch table slot number.
2821 if Tagged_Type_Expansion then
2823 Unchecked_Convert_To (RTE (RE_Tag),
2825 (Node (First_Elmt (Access_Disp_Table (Typ))), Loc));
2829 Make_Attribute_Reference (Loc,
2830 Prefix => New_Reference_To (Typ, Loc),
2831 Attribute_Name => Name_Tag);
2835 Make_Subprogram_Body (Loc,
2837 Make_Disp_Get_Prim_Op_Kind_Spec (Typ),
2840 Handled_Statement_Sequence =>
2841 Make_Handled_Sequence_Of_Statements (Loc,
2843 Make_Assignment_Statement (Loc,
2845 Make_Identifier (Loc, Name_uC),
2847 Make_Function_Call (Loc,
2849 New_Reference_To (RTE (RE_Get_Prim_Op_Kind), Loc),
2850 Parameter_Associations => New_List (
2852 Make_Identifier (Loc, Name_uS)))))));
2853 end Make_Disp_Get_Prim_Op_Kind_Body;
2855 -------------------------------------
2856 -- Make_Disp_Get_Prim_Op_Kind_Spec --
2857 -------------------------------------
2859 function Make_Disp_Get_Prim_Op_Kind_Spec
2860 (Typ : Entity_Id) return Node_Id
2862 Loc : constant Source_Ptr := Sloc (Typ);
2863 Def_Id : constant Node_Id :=
2864 Make_Defining_Identifier (Loc,
2865 Name_uDisp_Get_Prim_Op_Kind);
2866 Params : constant List_Id := New_List;
2869 pragma Assert (not Restriction_Active (No_Dispatching_Calls));
2871 -- T : in out Typ; -- Object parameter
2872 -- S : Integer; -- Primitive operation slot
2873 -- C : out Prim_Op_Kind; -- Call kind
2875 Append_List_To (Params, New_List (
2877 Make_Parameter_Specification (Loc,
2878 Defining_Identifier =>
2879 Make_Defining_Identifier (Loc, Name_uT),
2881 New_Reference_To (Typ, Loc),
2883 Out_Present => True),
2885 Make_Parameter_Specification (Loc,
2886 Defining_Identifier =>
2887 Make_Defining_Identifier (Loc, Name_uS),
2889 New_Reference_To (Standard_Integer, Loc)),
2891 Make_Parameter_Specification (Loc,
2892 Defining_Identifier =>
2893 Make_Defining_Identifier (Loc, Name_uC),
2895 New_Reference_To (RTE (RE_Prim_Op_Kind), Loc),
2896 Out_Present => True)));
2899 Make_Procedure_Specification (Loc,
2900 Defining_Unit_Name => Def_Id,
2901 Parameter_Specifications => Params);
2902 end Make_Disp_Get_Prim_Op_Kind_Spec;
2904 --------------------------------
2905 -- Make_Disp_Get_Task_Id_Body --
2906 --------------------------------
2908 function Make_Disp_Get_Task_Id_Body
2909 (Typ : Entity_Id) return Node_Id
2911 Loc : constant Source_Ptr := Sloc (Typ);
2915 pragma Assert (not Restriction_Active (No_Dispatching_Calls));
2917 if Is_Concurrent_Record_Type (Typ)
2918 and then Ekind (Corresponding_Concurrent_Type (Typ)) = E_Task_Type
2921 -- return To_Address (_T._task_id);
2924 Make_Simple_Return_Statement (Loc,
2926 Make_Unchecked_Type_Conversion (Loc,
2928 New_Reference_To (RTE (RE_Address), Loc),
2930 Make_Selected_Component (Loc,
2931 Prefix => Make_Identifier (Loc, Name_uT),
2932 Selector_Name => Make_Identifier (Loc, Name_uTask_Id))));
2934 -- A null body is constructed for non-task types
2938 -- return Null_Address;
2941 Make_Simple_Return_Statement (Loc,
2943 New_Reference_To (RTE (RE_Null_Address), Loc));
2947 Make_Subprogram_Body (Loc,
2949 Make_Disp_Get_Task_Id_Spec (Typ),
2952 Handled_Statement_Sequence =>
2953 Make_Handled_Sequence_Of_Statements (Loc,
2955 end Make_Disp_Get_Task_Id_Body;
2957 --------------------------------
2958 -- Make_Disp_Get_Task_Id_Spec --
2959 --------------------------------
2961 function Make_Disp_Get_Task_Id_Spec
2962 (Typ : Entity_Id) return Node_Id
2964 Loc : constant Source_Ptr := Sloc (Typ);
2967 pragma Assert (not Restriction_Active (No_Dispatching_Calls));
2970 Make_Function_Specification (Loc,
2971 Defining_Unit_Name =>
2972 Make_Defining_Identifier (Loc, Name_uDisp_Get_Task_Id),
2973 Parameter_Specifications => New_List (
2974 Make_Parameter_Specification (Loc,
2975 Defining_Identifier =>
2976 Make_Defining_Identifier (Loc, Name_uT),
2978 New_Reference_To (Typ, Loc))),
2979 Result_Definition =>
2980 New_Reference_To (RTE (RE_Address), Loc));
2981 end Make_Disp_Get_Task_Id_Spec;
2983 ----------------------------
2984 -- Make_Disp_Requeue_Body --
2985 ----------------------------
2987 function Make_Disp_Requeue_Body
2988 (Typ : Entity_Id) return Node_Id
2990 Loc : constant Source_Ptr := Sloc (Typ);
2991 Conc_Typ : Entity_Id := Empty;
2992 Stmts : constant List_Id := New_List;
2995 pragma Assert (not Restriction_Active (No_Dispatching_Calls));
2997 -- Null body is generated for interface types and non-concurrent
3000 if Is_Interface (Typ)
3001 or else not Is_Concurrent_Record_Type (Typ)
3004 Make_Subprogram_Body (Loc,
3006 Make_Disp_Requeue_Spec (Typ),
3009 Handled_Statement_Sequence =>
3010 Make_Handled_Sequence_Of_Statements (Loc,
3011 New_List (Make_Null_Statement (Loc))));
3014 Conc_Typ := Corresponding_Concurrent_Type (Typ);
3016 if Ekind (Conc_Typ) = E_Protected_Type then
3018 -- Generate statements:
3020 -- System.Tasking.Protected_Objects.Operations.
3021 -- Requeue_Protected_Entry
3022 -- (Protection_Entries_Access (P),
3023 -- O._object'Unchecked_Access,
3024 -- Protected_Entry_Index (I),
3027 -- System.Tasking.Protected_Objects.Operations.
3028 -- Requeue_Task_To_Protected_Entry
3029 -- (O._object'Unchecked_Access,
3030 -- Protected_Entry_Index (I),
3034 if Restriction_Active (No_Entry_Queue) then
3035 Append_To (Stmts, Make_Null_Statement (Loc));
3038 Make_If_Statement (Loc,
3039 Condition => Make_Identifier (Loc, Name_uF),
3044 -- Call to Requeue_Protected_Entry
3046 Make_Procedure_Call_Statement (Loc,
3049 RTE (RE_Requeue_Protected_Entry), Loc),
3050 Parameter_Associations =>
3053 Make_Unchecked_Type_Conversion (Loc, -- PEA (P)
3056 RTE (RE_Protection_Entries_Access), Loc),
3058 Make_Identifier (Loc, Name_uP)),
3060 Make_Attribute_Reference (Loc, -- O._object'Acc
3062 Name_Unchecked_Access,
3064 Make_Selected_Component (Loc,
3066 Make_Identifier (Loc, Name_uO),
3068 Make_Identifier (Loc, Name_uObject))),
3070 Make_Unchecked_Type_Conversion (Loc, -- entry index
3073 RTE (RE_Protected_Entry_Index), Loc),
3074 Expression => Make_Identifier (Loc, Name_uI)),
3076 Make_Identifier (Loc, Name_uA)))), -- abort status
3081 -- Call to Requeue_Task_To_Protected_Entry
3083 Make_Procedure_Call_Statement (Loc,
3086 RTE (RE_Requeue_Task_To_Protected_Entry), Loc),
3087 Parameter_Associations =>
3090 Make_Attribute_Reference (Loc, -- O._object'Acc
3092 Name_Unchecked_Access,
3094 Make_Selected_Component (Loc,
3096 Make_Identifier (Loc, Name_uO),
3098 Make_Identifier (Loc, Name_uObject))),
3100 Make_Unchecked_Type_Conversion (Loc, -- entry index
3103 RTE (RE_Protected_Entry_Index), Loc),
3105 Make_Identifier (Loc, Name_uI)),
3107 Make_Identifier (Loc, Name_uA)))))); -- abort status
3110 pragma Assert (Is_Task_Type (Conc_Typ));
3114 -- System.Tasking.Rendezvous.Requeue_Protected_To_Task_Entry
3115 -- (Protection_Entries_Access (P),
3117 -- Task_Entry_Index (I),
3120 -- System.Tasking.Rendezvous.Requeue_Task_Entry
3122 -- Task_Entry_Index (I),
3127 Make_If_Statement (Loc,
3128 Condition => Make_Identifier (Loc, Name_uF),
3130 Then_Statements => New_List (
3132 -- Call to Requeue_Protected_To_Task_Entry
3134 Make_Procedure_Call_Statement (Loc,
3137 (RTE (RE_Requeue_Protected_To_Task_Entry), Loc),
3139 Parameter_Associations => New_List (
3141 Make_Unchecked_Type_Conversion (Loc, -- PEA (P)
3144 (RTE (RE_Protection_Entries_Access), Loc),
3145 Expression => Make_Identifier (Loc, Name_uP)),
3147 Make_Selected_Component (Loc, -- O._task_id
3148 Prefix => Make_Identifier (Loc, Name_uO),
3149 Selector_Name => Make_Identifier (Loc, Name_uTask_Id)),
3151 Make_Unchecked_Type_Conversion (Loc, -- entry index
3153 New_Reference_To (RTE (RE_Task_Entry_Index), Loc),
3154 Expression => Make_Identifier (Loc, Name_uI)),
3156 Make_Identifier (Loc, Name_uA)))), -- abort status
3158 Else_Statements => New_List (
3160 -- Call to Requeue_Task_Entry
3162 Make_Procedure_Call_Statement (Loc,
3163 Name => New_Reference_To (RTE (RE_Requeue_Task_Entry), Loc),
3165 Parameter_Associations => New_List (
3167 Make_Selected_Component (Loc, -- O._task_id
3168 Prefix => Make_Identifier (Loc, Name_uO),
3169 Selector_Name => Make_Identifier (Loc, Name_uTask_Id)),
3171 Make_Unchecked_Type_Conversion (Loc, -- entry index
3173 New_Reference_To (RTE (RE_Task_Entry_Index), Loc),
3174 Expression => Make_Identifier (Loc, Name_uI)),
3176 Make_Identifier (Loc, Name_uA)))))); -- abort status
3179 -- Even though no declarations are needed in both cases, we allocate
3180 -- a list for entities added by Freeze.
3183 Make_Subprogram_Body (Loc,
3185 Make_Disp_Requeue_Spec (Typ),
3188 Handled_Statement_Sequence =>
3189 Make_Handled_Sequence_Of_Statements (Loc, Stmts));
3190 end Make_Disp_Requeue_Body;
3192 ----------------------------
3193 -- Make_Disp_Requeue_Spec --
3194 ----------------------------
3196 function Make_Disp_Requeue_Spec
3197 (Typ : Entity_Id) return Node_Id
3199 Loc : constant Source_Ptr := Sloc (Typ);
3202 pragma Assert (not Restriction_Active (No_Dispatching_Calls));
3204 -- O : in out Typ; - Object parameter
3205 -- F : Boolean; - Protected (True) / task (False) flag
3206 -- P : Address; - Protection_Entries_Access value
3207 -- I : Entry_Index - Index of entry call
3208 -- A : Boolean - Abort flag
3210 -- Note that the Protection_Entries_Access value is represented as a
3211 -- System.Address in order to avoid dragging in the tasking runtime
3212 -- when compiling sources without tasking constructs.
3215 Make_Procedure_Specification (Loc,
3216 Defining_Unit_Name =>
3217 Make_Defining_Identifier (Loc, Name_uDisp_Requeue),
3219 Parameter_Specifications =>
3222 Make_Parameter_Specification (Loc, -- O
3223 Defining_Identifier =>
3224 Make_Defining_Identifier (Loc, Name_uO),
3226 New_Reference_To (Typ, Loc),
3228 Out_Present => True),
3230 Make_Parameter_Specification (Loc, -- F
3231 Defining_Identifier =>
3232 Make_Defining_Identifier (Loc, Name_uF),
3234 New_Reference_To (Standard_Boolean, Loc)),
3236 Make_Parameter_Specification (Loc, -- P
3237 Defining_Identifier =>
3238 Make_Defining_Identifier (Loc, Name_uP),
3240 New_Reference_To (RTE (RE_Address), Loc)),
3242 Make_Parameter_Specification (Loc, -- I
3243 Defining_Identifier =>
3244 Make_Defining_Identifier (Loc, Name_uI),
3246 New_Reference_To (Standard_Integer, Loc)),
3248 Make_Parameter_Specification (Loc, -- A
3249 Defining_Identifier =>
3250 Make_Defining_Identifier (Loc, Name_uA),
3252 New_Reference_To (Standard_Boolean, Loc))));
3253 end Make_Disp_Requeue_Spec;
3255 ---------------------------------
3256 -- Make_Disp_Timed_Select_Body --
3257 ---------------------------------
3259 -- For interface types, generate:
3261 -- procedure _Disp_Timed_Select
3262 -- (T : in out <Typ>;
3264 -- P : System.Address;
3267 -- C : out Ada.Tags.Prim_Op_Kind;
3272 -- C := Ada.Tags.POK_Function;
3273 -- end _Disp_Timed_Select;
3275 -- For protected types, generate:
3277 -- procedure _Disp_Timed_Select
3278 -- (T : in out <Typ>;
3280 -- P : System.Address;
3283 -- C : out Ada.Tags.Prim_Op_Kind;
3289 -- C := Ada.Tags.Get_Prim_Op_Kind (Ada.Tags.Tag (<Typ>VP), S);
3291 -- if C = Ada.Tags.POK_Procedure
3292 -- or else C = Ada.Tags.POK_Protected_Procedure
3293 -- or else C = Ada.Tags.POK_Task_Procedure
3299 -- I := Ada.Tags.Get_Entry_Index (Ada.Tags.Tag (<Typ>VP), S);
3300 -- System.Tasking.Protected_Objects.Operations.
3301 -- Timed_Protected_Entry_Call
3302 -- (T._object'Access,
3303 -- System.Tasking.Protected_Objects.Protected_Entry_Index (I),
3308 -- end _Disp_Timed_Select;
3310 -- For task types, generate:
3312 -- procedure _Disp_Timed_Select
3313 -- (T : in out <Typ>;
3315 -- P : System.Address;
3318 -- C : out Ada.Tags.Prim_Op_Kind;
3324 -- I := Ada.Tags.Get_Entry_Index (Ada.Tags.Tag (<Typ>VP), S);
3325 -- System.Tasking.Rendezvous.Timed_Task_Entry_Call
3327 -- System.Tasking.Task_Entry_Index (I),
3332 -- end _Disp_Time_Select;
3334 function Make_Disp_Timed_Select_Body
3335 (Typ : Entity_Id) return Node_Id
3337 Loc : constant Source_Ptr := Sloc (Typ);
3338 Conc_Typ : Entity_Id := Empty;
3339 Decls : constant List_Id := New_List;
3341 Stmts : constant List_Id := New_List;
3345 pragma Assert (not Restriction_Active (No_Dispatching_Calls));
3347 -- Null body is generated for interface types
3349 if Is_Interface (Typ) then
3351 Make_Subprogram_Body (Loc,
3353 Make_Disp_Timed_Select_Spec (Typ),
3356 Handled_Statement_Sequence =>
3357 Make_Handled_Sequence_Of_Statements (Loc,
3359 Make_Assignment_Statement (Loc,
3360 Name => Make_Identifier (Loc, Name_uF),
3361 Expression => New_Reference_To (Standard_False, Loc)))));
3364 if Is_Concurrent_Record_Type (Typ) then
3365 Conc_Typ := Corresponding_Concurrent_Type (Typ);
3370 -- where I will be used to capture the entry index of the primitive
3371 -- wrapper at position S.
3374 Make_Object_Declaration (Loc,
3375 Defining_Identifier => Make_Defining_Identifier (Loc, Name_uI),
3376 Object_Definition => New_Reference_To (Standard_Integer, Loc)));
3379 -- C := Get_Prim_Op_Kind (tag! (<type>VP), S);
3381 -- if C = POK_Procedure
3382 -- or else C = POK_Protected_Procedure
3383 -- or else C = POK_Task_Procedure;
3389 Build_Common_Dispatching_Select_Statements (Typ, Stmts);
3392 -- I := Get_Entry_Index (tag! (<type>VP), S);
3394 -- I is the entry index and S is the dispatch table slot
3396 if Tagged_Type_Expansion then
3398 Unchecked_Convert_To (RTE (RE_Tag),
3400 (Node (First_Elmt (Access_Disp_Table (Typ))), Loc));
3404 Make_Attribute_Reference (Loc,
3405 Prefix => New_Reference_To (Typ, Loc),
3406 Attribute_Name => Name_Tag);
3410 Make_Assignment_Statement (Loc,
3411 Name => Make_Identifier (Loc, Name_uI),
3413 Make_Function_Call (Loc,
3414 Name => New_Reference_To (RTE (RE_Get_Entry_Index), Loc),
3415 Parameter_Associations =>
3418 Make_Identifier (Loc, Name_uS)))));
3422 if Ekind (Conc_Typ) = E_Protected_Type then
3424 -- Build T._object'Access
3427 Make_Attribute_Reference (Loc,
3428 Attribute_Name => Name_Unchecked_Access,
3430 Make_Selected_Component (Loc,
3431 Prefix => Make_Identifier (Loc, Name_uT),
3432 Selector_Name => Make_Identifier (Loc, Name_uObject)));
3434 -- Normal case, No_Entry_Queue restriction not active. In this
3435 -- case we generate:
3437 -- Timed_Protected_Entry_Call
3438 -- (T._object'access,
3439 -- Protected_Entry_Index! (I),
3442 -- where T is the protected object, I is the entry index, P are
3443 -- the wrapped parameters, D is the delay amount, M is the delay
3444 -- mode and F is the status flag.
3446 case Corresponding_Runtime_Package (Conc_Typ) is
3447 when System_Tasking_Protected_Objects_Entries =>
3449 Make_Procedure_Call_Statement (Loc,
3452 (RTE (RE_Timed_Protected_Entry_Call), Loc),
3453 Parameter_Associations =>
3457 Make_Unchecked_Type_Conversion (Loc, -- entry index
3460 (RTE (RE_Protected_Entry_Index), Loc),
3462 Make_Identifier (Loc, Name_uI)),
3464 Make_Identifier (Loc, Name_uP), -- parameter block
3465 Make_Identifier (Loc, Name_uD), -- delay
3466 Make_Identifier (Loc, Name_uM), -- delay mode
3467 Make_Identifier (Loc, Name_uF)))); -- status flag
3469 when System_Tasking_Protected_Objects_Single_Entry =>
3472 -- Timed_Protected_Single_Entry_Call
3473 -- (T._object'access, P, D, M, F);
3475 -- where T is the protected object, P is the wrapped
3476 -- parameters, D is the delay amount, M is the delay mode, F
3477 -- is the status flag.
3480 Make_Procedure_Call_Statement (Loc,
3483 (RTE (RE_Timed_Protected_Single_Entry_Call), Loc),
3484 Parameter_Associations =>
3487 Make_Identifier (Loc, Name_uP), -- parameter block
3488 Make_Identifier (Loc, Name_uD), -- delay
3489 Make_Identifier (Loc, Name_uM), -- delay mode
3490 Make_Identifier (Loc, Name_uF)))); -- status flag
3493 raise Program_Error;
3499 pragma Assert (Ekind (Conc_Typ) = E_Task_Type);
3502 -- Timed_Task_Entry_Call (
3504 -- Task_Entry_Index! (I),
3510 -- where T is the task object, I is the entry index, P are the
3511 -- wrapped parameters, D is the delay amount, M is the delay
3512 -- mode and F is the status flag.
3515 Make_Procedure_Call_Statement (Loc,
3517 New_Reference_To (RTE (RE_Timed_Task_Entry_Call), Loc),
3518 Parameter_Associations =>
3521 Make_Selected_Component (Loc, -- T._task_id
3522 Prefix => Make_Identifier (Loc, Name_uT),
3523 Selector_Name => Make_Identifier (Loc, Name_uTask_Id)),
3525 Make_Unchecked_Type_Conversion (Loc, -- entry index
3527 New_Reference_To (RTE (RE_Task_Entry_Index), Loc),
3528 Expression => Make_Identifier (Loc, Name_uI)),
3530 Make_Identifier (Loc, Name_uP), -- parameter block
3531 Make_Identifier (Loc, Name_uD), -- delay
3532 Make_Identifier (Loc, Name_uM), -- delay mode
3533 Make_Identifier (Loc, Name_uF)))); -- status flag
3537 -- Initialize out parameters
3540 Make_Assignment_Statement (Loc,
3541 Name => Make_Identifier (Loc, Name_uF),
3542 Expression => New_Reference_To (Standard_False, Loc)));
3544 Make_Assignment_Statement (Loc,
3545 Name => Make_Identifier (Loc, Name_uC),
3546 Expression => New_Reference_To (RTE (RE_POK_Function), Loc)));
3550 Make_Subprogram_Body (Loc,
3551 Specification => Make_Disp_Timed_Select_Spec (Typ),
3552 Declarations => Decls,
3553 Handled_Statement_Sequence =>
3554 Make_Handled_Sequence_Of_Statements (Loc, Stmts));
3555 end Make_Disp_Timed_Select_Body;
3557 ---------------------------------
3558 -- Make_Disp_Timed_Select_Spec --
3559 ---------------------------------
3561 function Make_Disp_Timed_Select_Spec
3562 (Typ : Entity_Id) return Node_Id
3564 Loc : constant Source_Ptr := Sloc (Typ);
3565 Def_Id : constant Node_Id :=
3566 Make_Defining_Identifier (Loc,
3567 Name_uDisp_Timed_Select);
3568 Params : constant List_Id := New_List;
3571 pragma Assert (not Restriction_Active (No_Dispatching_Calls));
3573 -- T : in out Typ; -- Object parameter
3574 -- S : Integer; -- Primitive operation slot
3575 -- P : Address; -- Wrapped parameters
3576 -- D : Duration; -- Delay
3577 -- M : Integer; -- Delay Mode
3578 -- C : out Prim_Op_Kind; -- Call kind
3579 -- F : out Boolean; -- Status flag
3581 Append_List_To (Params, New_List (
3583 Make_Parameter_Specification (Loc,
3584 Defining_Identifier =>
3585 Make_Defining_Identifier (Loc, Name_uT),
3587 New_Reference_To (Typ, Loc),
3589 Out_Present => True),
3591 Make_Parameter_Specification (Loc,
3592 Defining_Identifier =>
3593 Make_Defining_Identifier (Loc, Name_uS),
3595 New_Reference_To (Standard_Integer, Loc)),
3597 Make_Parameter_Specification (Loc,
3598 Defining_Identifier =>
3599 Make_Defining_Identifier (Loc, Name_uP),
3601 New_Reference_To (RTE (RE_Address), Loc)),
3603 Make_Parameter_Specification (Loc,
3604 Defining_Identifier =>
3605 Make_Defining_Identifier (Loc, Name_uD),
3607 New_Reference_To (Standard_Duration, Loc)),
3609 Make_Parameter_Specification (Loc,
3610 Defining_Identifier =>
3611 Make_Defining_Identifier (Loc, Name_uM),
3613 New_Reference_To (Standard_Integer, Loc)),
3615 Make_Parameter_Specification (Loc,
3616 Defining_Identifier =>
3617 Make_Defining_Identifier (Loc, Name_uC),
3619 New_Reference_To (RTE (RE_Prim_Op_Kind), Loc),
3620 Out_Present => True)));
3623 Make_Parameter_Specification (Loc,
3624 Defining_Identifier =>
3625 Make_Defining_Identifier (Loc, Name_uF),
3627 New_Reference_To (Standard_Boolean, Loc),
3628 Out_Present => True));
3631 Make_Procedure_Specification (Loc,
3632 Defining_Unit_Name => Def_Id,
3633 Parameter_Specifications => Params);
3634 end Make_Disp_Timed_Select_Spec;
3640 -- The frontend supports two models for expanding dispatch tables
3641 -- associated with library-level defined tagged types: statically
3642 -- and non-statically allocated dispatch tables. In the former case
3643 -- the object containing the dispatch table is constant and it is
3644 -- initialized by means of a positional aggregate. In the latter case,
3645 -- the object containing the dispatch table is a variable which is
3646 -- initialized by means of assignments.
3648 -- In case of locally defined tagged types, the object containing the
3649 -- object containing the dispatch table is always a variable (instead
3650 -- of a constant). This is currently required to give support to late
3651 -- overriding of primitives. For example:
3653 -- procedure Example is
3655 -- type T1 is tagged null record;
3656 -- procedure Prim (O : T1);
3659 -- type T2 is new Pkg.T1 with null record;
3660 -- procedure Prim (X : T2) is -- late overriding
3666 function Make_DT (Typ : Entity_Id; N : Node_Id := Empty) return List_Id is
3667 Loc : constant Source_Ptr := Sloc (Typ);
3669 Max_Predef_Prims : constant Int :=
3673 (Parent (RTE (RE_Max_Predef_Prims)))));
3675 DT_Decl : constant Elist_Id := New_Elmt_List;
3676 DT_Aggr : constant Elist_Id := New_Elmt_List;
3677 -- Entities marked with attribute Is_Dispatch_Table_Entity
3679 procedure Check_Premature_Freezing
3681 Tagged_Type : Entity_Id;
3683 -- Verify that all non-tagged types in the profile of a subprogram
3684 -- are frozen at the point the subprogram is frozen. This enforces
3685 -- the rule on RM 13.14 (14) as modified by AI05-019. At the point a
3686 -- subprogram is frozen, enough must be known about it to build the
3687 -- activation record for it, which requires at least that the size of
3688 -- all parameters be known. Controlling arguments are by-reference,
3689 -- and therefore the rule only applies to non-tagged types.
3690 -- Typical violation of the rule involves an object declaration that
3691 -- freezes a tagged type, when one of its primitive operations has a
3692 -- type in its profile whose full view has not been analyzed yet.
3693 -- More complex cases involve composite types that have one private
3694 -- unfrozen subcomponent.
3696 procedure Export_DT (Typ : Entity_Id; DT : Entity_Id; Index : Nat := 0);
3697 -- Export the dispatch table DT of tagged type Typ. Required to generate
3698 -- forward references and statically allocate the table. For primary
3699 -- dispatch tables Index is 0; for secondary dispatch tables the value
3700 -- of index must match the Suffix_Index value assigned to the table by
3701 -- Make_Tags when generating its unique external name, and it is used to
3702 -- retrieve from the Dispatch_Table_Wrappers list associated with Typ
3703 -- the external name generated by Import_DT.
3705 procedure Make_Secondary_DT
3709 Num_Iface_Prims : Nat;
3710 Iface_DT_Ptr : Entity_Id;
3711 Predef_Prims_Ptr : Entity_Id;
3712 Build_Thunks : Boolean;
3714 -- Ada 2005 (AI-251): Expand the declarations for a Secondary Dispatch
3715 -- Table of Typ associated with Iface. Each abstract interface of Typ
3716 -- has two secondary dispatch tables: one containing pointers to thunks
3717 -- and another containing pointers to the primitives covering the
3718 -- interface primitives. The former secondary table is generated when
3719 -- Build_Thunks is True, and provides common support for dispatching
3720 -- calls through interface types; the latter secondary table is
3721 -- generated when Build_Thunks is False, and provides support for
3722 -- Generic Dispatching Constructors that dispatch calls through
3723 -- interface types. When constructing this latter table the value of
3724 -- Suffix_Index is -1 to indicate that there is no need to export such
3725 -- table when building statically allocated dispatch tables; a positive
3726 -- value of Suffix_Index must match the Suffix_Index value assigned to
3727 -- this secondary dispatch table by Make_Tags when its unique external
3728 -- name was generated.
3730 ------------------------------
3731 -- Check_Premature_Freezing --
3732 ------------------------------
3734 procedure Check_Premature_Freezing
3736 Tagged_Type : Entity_Id;
3741 function Is_Actual_For_Formal_Incomplete_Type
3742 (T : Entity_Id) return Boolean;
3743 -- In Ada 2012, if a nested generic has an incomplete formal type,
3744 -- the actual may be (and usually is) a private type whose completion
3745 -- appears later. It is safe to build the dispatch table in this
3746 -- case, gigi will have full views available.
3748 ------------------------------------------
3749 -- Is_Actual_For_Formal_Incomplete_Type --
3750 ------------------------------------------
3752 function Is_Actual_For_Formal_Incomplete_Type
3753 (T : Entity_Id) return Boolean
3755 Gen_Par : Entity_Id;
3759 if not Is_Generic_Instance (Current_Scope)
3760 or else not Used_As_Generic_Actual (T)
3765 Gen_Par := Generic_Parent (Parent (Current_Scope));
3770 (Generic_Formal_Declarations
3771 (Unit_Declaration_Node (Gen_Par)));
3772 while Present (F) loop
3773 if Ekind (Defining_Identifier (F)) = E_Incomplete_Type then
3781 end Is_Actual_For_Formal_Incomplete_Type;
3783 -- Start of processing for Check_Premature_Freezing
3786 -- Note that if the type is a (subtype of) a generic actual, the
3787 -- actual will have been frozen by the instantiation.
3790 and then Is_Private_Type (Typ)
3791 and then No (Full_View (Typ))
3792 and then not Is_Generic_Type (Typ)
3793 and then not Is_Tagged_Type (Typ)
3794 and then not Is_Frozen (Typ)
3795 and then not Is_Generic_Actual_Type (Typ)
3797 Error_Msg_Sloc := Sloc (Subp);
3799 ("declaration must appear after completion of type &", N, Typ);
3801 ("\which is an untagged type in the profile of"
3802 & " primitive operation & declared#", N, Subp);
3805 Comp := Private_Component (Typ);
3807 if not Is_Tagged_Type (Typ)
3808 and then Present (Comp)
3809 and then not Is_Frozen (Comp)
3811 not Is_Actual_For_Formal_Incomplete_Type (Comp)
3813 Error_Msg_Sloc := Sloc (Subp);
3814 Error_Msg_Node_2 := Subp;
3815 Error_Msg_Name_1 := Chars (Tagged_Type);
3817 ("declaration must appear after completion of type &",
3820 ("\which is a component of untagged type& in the profile of"
3821 & " primitive & of type % that is frozen by the declaration ",
3825 end Check_Premature_Freezing;
3831 procedure Export_DT (Typ : Entity_Id; DT : Entity_Id; Index : Nat := 0)
3837 Set_Is_Statically_Allocated (DT);
3838 Set_Is_True_Constant (DT);
3839 Set_Is_Exported (DT);
3842 Elmt := First_Elmt (Dispatch_Table_Wrappers (Typ));
3843 while Count /= Index loop
3848 pragma Assert (Related_Type (Node (Elmt)) = Typ);
3851 (Entity => Node (Elmt),
3852 Has_Suffix => True);
3854 Set_Interface_Name (DT,
3855 Make_String_Literal (Loc,
3856 Strval => String_From_Name_Buffer));
3858 -- Ensure proper Sprint output of this implicit importation
3860 Set_Is_Internal (DT);
3864 -----------------------
3865 -- Make_Secondary_DT --
3866 -----------------------
3868 procedure Make_Secondary_DT
3872 Num_Iface_Prims : Nat;
3873 Iface_DT_Ptr : Entity_Id;
3874 Predef_Prims_Ptr : Entity_Id;
3875 Build_Thunks : Boolean;
3878 Loc : constant Source_Ptr := Sloc (Typ);
3879 Exporting_Table : constant Boolean :=
3880 Building_Static_DT (Typ)
3881 and then Suffix_Index > 0;
3882 Iface_DT : constant Entity_Id := Make_Temporary (Loc, 'T');
3883 Predef_Prims : constant Entity_Id := Make_Temporary (Loc, 'R');
3884 DT_Constr_List : List_Id;
3885 DT_Aggr_List : List_Id;
3886 Empty_DT : Boolean := False;
3887 Nb_Predef_Prims : Nat := 0;
3891 OSD_Aggr_List : List_Id;
3894 Prim_Elmt : Elmt_Id;
3895 Prim_Ops_Aggr_List : List_Id;
3898 -- Handle cases in which we do not generate statically allocated
3901 if not Building_Static_DT (Typ) then
3902 Set_Ekind (Predef_Prims, E_Variable);
3903 Set_Ekind (Iface_DT, E_Variable);
3905 -- Statically allocated dispatch tables and related entities are
3909 Set_Ekind (Predef_Prims, E_Constant);
3910 Set_Is_Statically_Allocated (Predef_Prims);
3911 Set_Is_True_Constant (Predef_Prims);
3913 Set_Ekind (Iface_DT, E_Constant);
3914 Set_Is_Statically_Allocated (Iface_DT);
3915 Set_Is_True_Constant (Iface_DT);
3918 -- Calculate the number of slots of the dispatch table. If the number
3919 -- of primitives of Typ is 0 we reserve a dummy single entry for its
3920 -- DT because at run time the pointer to this dummy entry will be
3923 if Num_Iface_Prims = 0 then
3927 Nb_Prim := Num_Iface_Prims;
3932 -- Predef_Prims : Address_Array (1 .. Default_Prim_Ops_Count) :=
3933 -- (predef-prim-op-thunk-1'address,
3934 -- predef-prim-op-thunk-2'address,
3936 -- predef-prim-op-thunk-n'address);
3937 -- for Predef_Prims'Alignment use Address'Alignment
3939 -- Stage 1: Calculate the number of predefined primitives
3941 if not Building_Static_DT (Typ) then
3942 Nb_Predef_Prims := Max_Predef_Prims;
3944 Prim_Elmt := First_Elmt (Primitive_Operations (Typ));
3945 while Present (Prim_Elmt) loop
3946 Prim := Node (Prim_Elmt);
3948 if Is_Predefined_Dispatching_Operation (Prim)
3949 and then not Is_Abstract_Subprogram (Prim)
3951 Pos := UI_To_Int (DT_Position (Prim));
3953 if Pos > Nb_Predef_Prims then
3954 Nb_Predef_Prims := Pos;
3958 Next_Elmt (Prim_Elmt);
3962 -- Stage 2: Create the thunks associated with the predefined
3963 -- primitives and save their entity to fill the aggregate.
3966 Prim_Table : array (Nat range 1 .. Nb_Predef_Prims) of Entity_Id;
3968 Thunk_Id : Entity_Id;
3969 Thunk_Code : Node_Id;
3972 Prim_Ops_Aggr_List := New_List;
3973 Prim_Table := (others => Empty);
3975 if Building_Static_DT (Typ) then
3976 Prim_Elmt := First_Elmt (Primitive_Operations (Typ));
3977 while Present (Prim_Elmt) loop
3978 Prim := Node (Prim_Elmt);
3980 if Is_Predefined_Dispatching_Operation (Prim)
3981 and then not Is_Abstract_Subprogram (Prim)
3982 and then not Is_Eliminated (Prim)
3983 and then not Present (Prim_Table
3984 (UI_To_Int (DT_Position (Prim))))
3986 if not Build_Thunks then
3987 Prim_Table (UI_To_Int (DT_Position (Prim))) :=
3991 Expand_Interface_Thunk
3992 (Ultimate_Alias (Prim), Thunk_Id, Thunk_Code);
3994 if Present (Thunk_Id) then
3995 Append_To (Result, Thunk_Code);
3996 Prim_Table (UI_To_Int (DT_Position (Prim)))
4002 Next_Elmt (Prim_Elmt);
4006 for J in Prim_Table'Range loop
4007 if Present (Prim_Table (J)) then
4009 Unchecked_Convert_To (RTE (RE_Prim_Ptr),
4010 Make_Attribute_Reference (Loc,
4011 Prefix => New_Reference_To (Prim_Table (J), Loc),
4012 Attribute_Name => Name_Unrestricted_Access));
4014 New_Node := Make_Null (Loc);
4017 Append_To (Prim_Ops_Aggr_List, New_Node);
4021 Make_Aggregate (Loc,
4022 Expressions => Prim_Ops_Aggr_List);
4024 -- Remember aggregates initializing dispatch tables
4026 Append_Elmt (New_Node, DT_Aggr);
4029 Make_Subtype_Declaration (Loc,
4030 Defining_Identifier => Make_Temporary (Loc, 'S'),
4031 Subtype_Indication =>
4032 New_Reference_To (RTE (RE_Address_Array), Loc));
4034 Append_To (Result, Decl);
4037 Make_Object_Declaration (Loc,
4038 Defining_Identifier => Predef_Prims,
4039 Constant_Present => Building_Static_DT (Typ),
4040 Aliased_Present => True,
4041 Object_Definition => New_Reference_To
4042 (Defining_Identifier (Decl), Loc),
4043 Expression => New_Node));
4046 Make_Attribute_Definition_Clause (Loc,
4047 Name => New_Reference_To (Predef_Prims, Loc),
4048 Chars => Name_Alignment,
4050 Make_Attribute_Reference (Loc,
4052 New_Reference_To (RTE (RE_Integer_Address), Loc),
4053 Attribute_Name => Name_Alignment)));
4058 -- OSD : Ada.Tags.Object_Specific_Data (Nb_Prims) :=
4059 -- (OSD_Table => (1 => <value>,
4063 -- Iface_DT : Dispatch_Table (Nb_Prims) :=
4064 -- ([ Signature => <sig-value> ],
4065 -- Tag_Kind => <tag_kind-value>,
4066 -- Predef_Prims => Predef_Prims'Address,
4067 -- Offset_To_Top => 0,
4068 -- OSD => OSD'Address,
4069 -- Prims_Ptr => (prim-op-1'address,
4070 -- prim-op-2'address,
4072 -- prim-op-n'address));
4073 -- for Iface_DT'Alignment use Address'Alignment;
4075 -- Stage 3: Initialize the discriminant and the record components
4077 DT_Constr_List := New_List;
4078 DT_Aggr_List := New_List;
4080 -- Nb_Prim. If the tagged type has no primitives we add a dummy
4081 -- slot whose address will be the tag of this type.
4084 New_Node := Make_Integer_Literal (Loc, 1);
4086 New_Node := Make_Integer_Literal (Loc, Nb_Prim);
4089 Append_To (DT_Constr_List, New_Node);
4090 Append_To (DT_Aggr_List, New_Copy (New_Node));
4094 if RTE_Record_Component_Available (RE_Signature) then
4095 Append_To (DT_Aggr_List,
4096 New_Reference_To (RTE (RE_Secondary_DT), Loc));
4101 if RTE_Record_Component_Available (RE_Tag_Kind) then
4102 Append_To (DT_Aggr_List, Tagged_Kind (Typ));
4107 Append_To (DT_Aggr_List,
4108 Make_Attribute_Reference (Loc,
4109 Prefix => New_Reference_To (Predef_Prims, Loc),
4110 Attribute_Name => Name_Address));
4112 -- Note: The correct value of Offset_To_Top will be set by the init
4115 Append_To (DT_Aggr_List, Make_Integer_Literal (Loc, 0));
4117 -- Generate the Object Specific Data table required to dispatch calls
4118 -- through synchronized interfaces.
4121 or else Is_Abstract_Type (Typ)
4122 or else Is_Controlled (Typ)
4123 or else Restriction_Active (No_Dispatching_Calls)
4124 or else not Is_Limited_Type (Typ)
4125 or else not Has_Interfaces (Typ)
4126 or else not Build_Thunks
4127 or else not RTE_Record_Component_Available (RE_OSD_Table)
4129 -- No OSD table required
4131 Append_To (DT_Aggr_List,
4132 New_Reference_To (RTE (RE_Null_Address), Loc));
4135 OSD_Aggr_List := New_List;
4138 Prim_Table : array (Nat range 1 .. Nb_Prim) of Entity_Id;
4140 Prim_Alias : Entity_Id;
4141 Prim_Elmt : Elmt_Id;
4147 Prim_Table := (others => Empty);
4148 Prim_Alias := Empty;
4150 Prim_Elmt := First_Elmt (Primitive_Operations (Typ));
4151 while Present (Prim_Elmt) loop
4152 Prim := Node (Prim_Elmt);
4154 if Present (Interface_Alias (Prim))
4155 and then Find_Dispatching_Type
4156 (Interface_Alias (Prim)) = Iface
4158 Prim_Alias := Interface_Alias (Prim);
4159 E := Ultimate_Alias (Prim);
4160 Pos := UI_To_Int (DT_Position (Prim_Alias));
4162 if Present (Prim_Table (Pos)) then
4163 pragma Assert (Prim_Table (Pos) = E);
4167 Prim_Table (Pos) := E;
4169 Append_To (OSD_Aggr_List,
4170 Make_Component_Association (Loc,
4171 Choices => New_List (
4172 Make_Integer_Literal (Loc,
4173 DT_Position (Prim_Alias))),
4175 Make_Integer_Literal (Loc,
4176 DT_Position (Alias (Prim)))));
4182 Next_Elmt (Prim_Elmt);
4184 pragma Assert (Count = Nb_Prim);
4187 OSD := Make_Temporary (Loc, 'I');
4190 Make_Object_Declaration (Loc,
4191 Defining_Identifier => OSD,
4192 Object_Definition =>
4193 Make_Subtype_Indication (Loc,
4195 New_Reference_To (RTE (RE_Object_Specific_Data), Loc),
4197 Make_Index_Or_Discriminant_Constraint (Loc,
4198 Constraints => New_List (
4199 Make_Integer_Literal (Loc, Nb_Prim)))),
4202 Make_Aggregate (Loc,
4203 Component_Associations => New_List (
4204 Make_Component_Association (Loc,
4205 Choices => New_List (
4207 (RTE_Record_Component (RE_OSD_Num_Prims), Loc)),
4209 Make_Integer_Literal (Loc, Nb_Prim)),
4211 Make_Component_Association (Loc,
4212 Choices => New_List (
4214 (RTE_Record_Component (RE_OSD_Table), Loc)),
4215 Expression => Make_Aggregate (Loc,
4216 Component_Associations => OSD_Aggr_List))))));
4219 Make_Attribute_Definition_Clause (Loc,
4220 Name => New_Reference_To (OSD, Loc),
4221 Chars => Name_Alignment,
4223 Make_Attribute_Reference (Loc,
4225 New_Reference_To (RTE (RE_Integer_Address), Loc),
4226 Attribute_Name => Name_Alignment)));
4228 -- In secondary dispatch tables the Typeinfo component contains
4229 -- the address of the Object Specific Data (see a-tags.ads)
4231 Append_To (DT_Aggr_List,
4232 Make_Attribute_Reference (Loc,
4233 Prefix => New_Reference_To (OSD, Loc),
4234 Attribute_Name => Name_Address));
4237 -- Initialize the table of primitive operations
4239 Prim_Ops_Aggr_List := New_List;
4242 Append_To (Prim_Ops_Aggr_List, Make_Null (Loc));
4244 elsif Is_Abstract_Type (Typ)
4245 or else not Building_Static_DT (Typ)
4247 for J in 1 .. Nb_Prim loop
4248 Append_To (Prim_Ops_Aggr_List, Make_Null (Loc));
4253 CPP_Nb_Prims : constant Nat := CPP_Num_Prims (Typ);
4256 Prim_Table : array (Nat range 1 .. Nb_Prim) of Entity_Id;
4257 Thunk_Code : Node_Id;
4258 Thunk_Id : Entity_Id;
4261 Prim_Table := (others => Empty);
4263 Prim_Elmt := First_Elmt (Primitive_Operations (Typ));
4264 while Present (Prim_Elmt) loop
4265 Prim := Node (Prim_Elmt);
4266 E := Ultimate_Alias (Prim);
4267 Prim_Pos := UI_To_Int (DT_Position (E));
4269 -- Do not reference predefined primitives because they are
4270 -- located in a separate dispatch table; skip abstract and
4271 -- eliminated primitives; skip primitives located in the C++
4272 -- part of the dispatch table because their slot is set by
4275 if not Is_Predefined_Dispatching_Operation (Prim)
4276 and then Present (Interface_Alias (Prim))
4277 and then not Is_Abstract_Subprogram (Alias (Prim))
4278 and then not Is_Eliminated (Alias (Prim))
4279 and then (not Is_CPP_Class (Root_Type (Typ))
4280 or else Prim_Pos > CPP_Nb_Prims)
4281 and then Find_Dispatching_Type
4282 (Interface_Alias (Prim)) = Iface
4284 -- Generate the code of the thunk only if the abstract
4285 -- interface type is not an immediate ancestor of
4286 -- Tagged_Type. Otherwise the DT associated with the
4287 -- interface is the primary DT.
4289 and then not Is_Ancestor (Iface, Typ,
4290 Use_Full_View => True)
4292 if not Build_Thunks then
4294 UI_To_Int (DT_Position (Interface_Alias (Prim)));
4295 Prim_Table (Prim_Pos) := Alias (Prim);
4298 Expand_Interface_Thunk (Prim, Thunk_Id, Thunk_Code);
4300 if Present (Thunk_Id) then
4302 UI_To_Int (DT_Position (Interface_Alias (Prim)));
4304 Prim_Table (Prim_Pos) := Thunk_Id;
4305 Append_To (Result, Thunk_Code);
4310 Next_Elmt (Prim_Elmt);
4313 for J in Prim_Table'Range loop
4314 if Present (Prim_Table (J)) then
4316 Unchecked_Convert_To (RTE (RE_Prim_Ptr),
4317 Make_Attribute_Reference (Loc,
4318 Prefix => New_Reference_To (Prim_Table (J), Loc),
4319 Attribute_Name => Name_Unrestricted_Access));
4322 New_Node := Make_Null (Loc);
4325 Append_To (Prim_Ops_Aggr_List, New_Node);
4331 Make_Aggregate (Loc,
4332 Expressions => Prim_Ops_Aggr_List);
4334 Append_To (DT_Aggr_List, New_Node);
4336 -- Remember aggregates initializing dispatch tables
4338 Append_Elmt (New_Node, DT_Aggr);
4340 -- Note: Secondary dispatch tables cannot be declared constant
4341 -- because the component Offset_To_Top is currently initialized
4342 -- by the IP routine.
4345 Make_Object_Declaration (Loc,
4346 Defining_Identifier => Iface_DT,
4347 Aliased_Present => True,
4348 Constant_Present => False,
4350 Object_Definition =>
4351 Make_Subtype_Indication (Loc,
4352 Subtype_Mark => New_Reference_To
4353 (RTE (RE_Dispatch_Table_Wrapper), Loc),
4354 Constraint => Make_Index_Or_Discriminant_Constraint (Loc,
4355 Constraints => DT_Constr_List)),
4358 Make_Aggregate (Loc,
4359 Expressions => DT_Aggr_List)));
4362 Make_Attribute_Definition_Clause (Loc,
4363 Name => New_Reference_To (Iface_DT, Loc),
4364 Chars => Name_Alignment,
4367 Make_Attribute_Reference (Loc,
4369 New_Reference_To (RTE (RE_Integer_Address), Loc),
4370 Attribute_Name => Name_Alignment)));
4372 if Exporting_Table then
4373 Export_DT (Typ, Iface_DT, Suffix_Index);
4375 -- Generate code to create the pointer to the dispatch table
4377 -- Iface_DT_Ptr : Tag := Tag!(DT.Prims_Ptr'Address);
4379 -- Note: This declaration is not added here if the table is exported
4380 -- because in such case Make_Tags has already added this declaration.
4384 Make_Object_Declaration (Loc,
4385 Defining_Identifier => Iface_DT_Ptr,
4386 Constant_Present => True,
4388 Object_Definition =>
4389 New_Reference_To (RTE (RE_Interface_Tag), Loc),
4392 Unchecked_Convert_To (RTE (RE_Interface_Tag),
4393 Make_Attribute_Reference (Loc,
4395 Make_Selected_Component (Loc,
4396 Prefix => New_Reference_To (Iface_DT, Loc),
4399 (RTE_Record_Component (RE_Prims_Ptr), Loc)),
4400 Attribute_Name => Name_Address))));
4404 Make_Object_Declaration (Loc,
4405 Defining_Identifier => Predef_Prims_Ptr,
4406 Constant_Present => True,
4408 Object_Definition =>
4409 New_Reference_To (RTE (RE_Address), Loc),
4412 Make_Attribute_Reference (Loc,
4414 Make_Selected_Component (Loc,
4415 Prefix => New_Reference_To (Iface_DT, Loc),
4418 (RTE_Record_Component (RE_Predef_Prims), Loc)),
4419 Attribute_Name => Name_Address)));
4421 -- Remember entities containing dispatch tables
4423 Append_Elmt (Predef_Prims, DT_Decl);
4424 Append_Elmt (Iface_DT, DT_Decl);
4425 end Make_Secondary_DT;
4429 Elab_Code : constant List_Id := New_List;
4430 Result : constant List_Id := New_List;
4431 Tname : constant Name_Id := Chars (Typ);
4433 AI_Tag_Elmt : Elmt_Id;
4434 AI_Tag_Comp : Elmt_Id;
4435 DT_Aggr_List : List_Id;
4436 DT_Constr_List : List_Id;
4440 Iface_Table_Node : Node_Id;
4441 Name_ITable : Name_Id;
4442 Nb_Predef_Prims : Nat := 0;
4445 Num_Ifaces : Nat := 0;
4446 Parent_Typ : Entity_Id;
4448 Prim_Elmt : Elmt_Id;
4449 Prim_Ops_Aggr_List : List_Id;
4451 Typ_Comps : Elist_Id;
4452 Typ_Ifaces : Elist_Id;
4453 TSD_Aggr_List : List_Id;
4454 TSD_Tags_List : List_Id;
4456 -- The following name entries are used by Make_DT to generate a number
4457 -- of entities related to a tagged type. These entities may be generated
4458 -- in a scope other than that of the tagged type declaration, and if
4459 -- the entities for two tagged types with the same name happen to be
4460 -- generated in the same scope, we have to take care to use different
4461 -- names. This is achieved by means of a unique serial number appended
4462 -- to each generated entity name.
4464 Name_DT : constant Name_Id :=
4465 New_External_Name (Tname, 'T', Suffix_Index => -1);
4466 Name_Exname : constant Name_Id :=
4467 New_External_Name (Tname, 'E', Suffix_Index => -1);
4468 Name_HT_Link : constant Name_Id :=
4469 New_External_Name (Tname, 'H', Suffix_Index => -1);
4470 Name_Predef_Prims : constant Name_Id :=
4471 New_External_Name (Tname, 'R', Suffix_Index => -1);
4472 Name_SSD : constant Name_Id :=
4473 New_External_Name (Tname, 'S', Suffix_Index => -1);
4474 Name_TSD : constant Name_Id :=
4475 New_External_Name (Tname, 'B', Suffix_Index => -1);
4477 -- Entities built with above names
4479 DT : constant Entity_Id :=
4480 Make_Defining_Identifier (Loc, Name_DT);
4481 Exname : constant Entity_Id :=
4482 Make_Defining_Identifier (Loc, Name_Exname);
4483 HT_Link : constant Entity_Id :=
4484 Make_Defining_Identifier (Loc, Name_HT_Link);
4485 Predef_Prims : constant Entity_Id :=
4486 Make_Defining_Identifier (Loc, Name_Predef_Prims);
4487 SSD : constant Entity_Id :=
4488 Make_Defining_Identifier (Loc, Name_SSD);
4489 TSD : constant Entity_Id :=
4490 Make_Defining_Identifier (Loc, Name_TSD);
4492 -- Start of processing for Make_DT
4495 pragma Assert (Is_Frozen (Typ));
4497 -- Handle cases in which there is no need to build the dispatch table
4499 if Has_Dispatch_Table (Typ)
4500 or else No (Access_Disp_Table (Typ))
4501 or else Is_CPP_Class (Typ)
4502 or else Convention (Typ) = Convention_CIL
4503 or else Convention (Typ) = Convention_Java
4507 elsif No_Run_Time_Mode then
4508 Error_Msg_CRT ("tagged types", Typ);
4511 elsif not RTE_Available (RE_Tag) then
4513 Make_Object_Declaration (Loc,
4514 Defining_Identifier => Node (First_Elmt
4515 (Access_Disp_Table (Typ))),
4516 Object_Definition => New_Reference_To (RTE (RE_Tag), Loc),
4517 Constant_Present => True,
4519 Unchecked_Convert_To (RTE (RE_Tag),
4520 New_Reference_To (RTE (RE_Null_Address), Loc))));
4522 Analyze_List (Result, Suppress => All_Checks);
4523 Error_Msg_CRT ("tagged types", Typ);
4527 -- Ensure that the value of Max_Predef_Prims defined in a-tags is
4528 -- correct. Valid values are 9 under configurable runtime or 15
4529 -- with full runtime.
4531 if RTE_Available (RE_Interface_Data) then
4532 if Max_Predef_Prims /= 15 then
4533 Error_Msg_N ("run-time library configuration error", Typ);
4537 if Max_Predef_Prims /= 9 then
4538 Error_Msg_N ("run-time library configuration error", Typ);
4539 Error_Msg_CRT ("tagged types", Typ);
4544 -- Initialize Parent_Typ handling private types
4546 Parent_Typ := Etype (Typ);
4548 if Present (Full_View (Parent_Typ)) then
4549 Parent_Typ := Full_View (Parent_Typ);
4552 -- Ensure that all the primitives are frozen. This is only required when
4553 -- building static dispatch tables --- the primitives must be frozen to
4554 -- be referenced (otherwise we have problems with the backend). It is
4555 -- not a requirement with nonstatic dispatch tables because in this case
4556 -- we generate now an empty dispatch table; the extra code required to
4557 -- register the primitives in the slots will be generated later --- when
4558 -- each primitive is frozen (see Freeze_Subprogram).
4560 if Building_Static_DT (Typ) then
4562 Save : constant Boolean := Freezing_Library_Level_Tagged_Type;
4564 Prim_Elmt : Elmt_Id;
4568 Freezing_Library_Level_Tagged_Type := True;
4570 Prim_Elmt := First_Elmt (Primitive_Operations (Typ));
4571 while Present (Prim_Elmt) loop
4572 Prim := Node (Prim_Elmt);
4573 Frnodes := Freeze_Entity (Prim, Typ);
4579 F := First_Formal (Prim);
4580 while Present (F) loop
4581 Check_Premature_Freezing (Prim, Typ, Etype (F));
4585 Check_Premature_Freezing (Prim, Typ, Etype (Prim));
4588 if Present (Frnodes) then
4589 Append_List_To (Result, Frnodes);
4592 Next_Elmt (Prim_Elmt);
4595 Freezing_Library_Level_Tagged_Type := Save;
4599 -- Ada 2005 (AI-251): Build the secondary dispatch tables
4601 if Has_Interfaces (Typ) then
4602 Collect_Interface_Components (Typ, Typ_Comps);
4604 -- Each secondary dispatch table is assigned an unique positive
4605 -- suffix index; such value also corresponds with the location of
4606 -- its entity in the Dispatch_Table_Wrappers list (see Make_Tags).
4608 -- Note: This value must be kept sync with the Suffix_Index values
4609 -- generated by Make_Tags
4613 Next_Elmt (Next_Elmt (First_Elmt (Access_Disp_Table (Typ))));
4615 AI_Tag_Comp := First_Elmt (Typ_Comps);
4616 while Present (AI_Tag_Comp) loop
4617 pragma Assert (Has_Suffix (Node (AI_Tag_Elmt), 'P'));
4619 -- Build the secondary table containing pointers to thunks
4623 Iface => Base_Type (Related_Type (Node (AI_Tag_Comp))),
4624 Suffix_Index => Suffix_Index,
4625 Num_Iface_Prims => UI_To_Int
4626 (DT_Entry_Count (Node (AI_Tag_Comp))),
4627 Iface_DT_Ptr => Node (AI_Tag_Elmt),
4628 Predef_Prims_Ptr => Node (Next_Elmt (AI_Tag_Elmt)),
4629 Build_Thunks => True,
4632 -- Skip secondary dispatch table referencing thunks to predefined
4635 Next_Elmt (AI_Tag_Elmt);
4636 pragma Assert (Has_Suffix (Node (AI_Tag_Elmt), 'Y'));
4638 -- Secondary dispatch table referencing user-defined primitives
4639 -- covered by this interface.
4641 Next_Elmt (AI_Tag_Elmt);
4642 pragma Assert (Has_Suffix (Node (AI_Tag_Elmt), 'D'));
4644 -- Build the secondary table containing pointers to primitives
4645 -- (used to give support to Generic Dispatching Constructors).
4650 (Related_Type (Node (AI_Tag_Comp))),
4652 Num_Iface_Prims => UI_To_Int
4653 (DT_Entry_Count (Node (AI_Tag_Comp))),
4654 Iface_DT_Ptr => Node (AI_Tag_Elmt),
4655 Predef_Prims_Ptr => Node (Next_Elmt (AI_Tag_Elmt)),
4656 Build_Thunks => False,
4659 -- Skip secondary dispatch table referencing predefined primitives
4661 Next_Elmt (AI_Tag_Elmt);
4662 pragma Assert (Has_Suffix (Node (AI_Tag_Elmt), 'Z'));
4664 Suffix_Index := Suffix_Index + 1;
4665 Next_Elmt (AI_Tag_Elmt);
4666 Next_Elmt (AI_Tag_Comp);
4670 -- Get the _tag entity and number of primitives of its dispatch table
4672 DT_Ptr := Node (First_Elmt (Access_Disp_Table (Typ)));
4673 Nb_Prim := UI_To_Int (DT_Entry_Count (First_Tag_Component (Typ)));
4675 Set_Is_Statically_Allocated (DT, Is_Library_Level_Tagged_Type (Typ));
4676 Set_Is_Statically_Allocated (SSD, Is_Library_Level_Tagged_Type (Typ));
4677 Set_Is_Statically_Allocated (TSD, Is_Library_Level_Tagged_Type (Typ));
4678 Set_Is_Statically_Allocated (Predef_Prims,
4679 Is_Library_Level_Tagged_Type (Typ));
4681 -- In case of locally defined tagged type we declare the object
4682 -- containing the dispatch table by means of a variable. Its
4683 -- initialization is done later by means of an assignment. This is
4684 -- required to generate its External_Tag.
4686 if not Building_Static_DT (Typ) then
4689 -- DT : No_Dispatch_Table_Wrapper;
4690 -- for DT'Alignment use Address'Alignment;
4691 -- DT_Ptr : Tag := !Tag (DT.NDT_Prims_Ptr'Address);
4693 if not Has_DT (Typ) then
4695 Make_Object_Declaration (Loc,
4696 Defining_Identifier => DT,
4697 Aliased_Present => True,
4698 Constant_Present => False,
4699 Object_Definition =>
4701 (RTE (RE_No_Dispatch_Table_Wrapper), Loc)));
4704 Make_Attribute_Definition_Clause (Loc,
4705 Name => New_Reference_To (DT, Loc),
4706 Chars => Name_Alignment,
4708 Make_Attribute_Reference (Loc,
4710 New_Reference_To (RTE (RE_Integer_Address), Loc),
4711 Attribute_Name => Name_Alignment)));
4714 Make_Object_Declaration (Loc,
4715 Defining_Identifier => DT_Ptr,
4716 Object_Definition => New_Reference_To (RTE (RE_Tag), Loc),
4717 Constant_Present => True,
4719 Unchecked_Convert_To (RTE (RE_Tag),
4720 Make_Attribute_Reference (Loc,
4722 Make_Selected_Component (Loc,
4723 Prefix => New_Reference_To (DT, Loc),
4726 (RTE_Record_Component (RE_NDT_Prims_Ptr), Loc)),
4727 Attribute_Name => Name_Address))));
4729 Set_Is_Statically_Allocated (DT_Ptr,
4730 Is_Library_Level_Tagged_Type (Typ));
4732 -- Generate the SCIL node for the previous object declaration
4733 -- because it has a tag initialization.
4735 if Generate_SCIL then
4737 Make_SCIL_Dispatch_Table_Tag_Init (Sloc (Last (Result)));
4738 Set_SCIL_Entity (New_Node, Typ);
4739 Set_SCIL_Node (Last (Result), New_Node);
4743 -- DT : Dispatch_Table_Wrapper (Nb_Prim);
4744 -- for DT'Alignment use Address'Alignment;
4745 -- DT_Ptr : Tag := !Tag (DT.Prims_Ptr'Address);
4748 -- If the tagged type has no primitives we add a dummy slot
4749 -- whose address will be the tag of this type.
4753 New_List (Make_Integer_Literal (Loc, 1));
4756 New_List (Make_Integer_Literal (Loc, Nb_Prim));
4760 Make_Object_Declaration (Loc,
4761 Defining_Identifier => DT,
4762 Aliased_Present => True,
4763 Constant_Present => False,
4764 Object_Definition =>
4765 Make_Subtype_Indication (Loc,
4767 New_Reference_To (RTE (RE_Dispatch_Table_Wrapper), Loc),
4768 Constraint => Make_Index_Or_Discriminant_Constraint (Loc,
4769 Constraints => DT_Constr_List))));
4772 Make_Attribute_Definition_Clause (Loc,
4773 Name => New_Reference_To (DT, Loc),
4774 Chars => Name_Alignment,
4776 Make_Attribute_Reference (Loc,
4778 New_Reference_To (RTE (RE_Integer_Address), Loc),
4779 Attribute_Name => Name_Alignment)));
4782 Make_Object_Declaration (Loc,
4783 Defining_Identifier => DT_Ptr,
4784 Object_Definition => New_Reference_To (RTE (RE_Tag), Loc),
4785 Constant_Present => True,
4787 Unchecked_Convert_To (RTE (RE_Tag),
4788 Make_Attribute_Reference (Loc,
4790 Make_Selected_Component (Loc,
4791 Prefix => New_Reference_To (DT, Loc),
4794 (RTE_Record_Component (RE_Prims_Ptr), Loc)),
4795 Attribute_Name => Name_Address))));
4797 Set_Is_Statically_Allocated (DT_Ptr,
4798 Is_Library_Level_Tagged_Type (Typ));
4800 -- Generate the SCIL node for the previous object declaration
4801 -- because it has a tag initialization.
4803 if Generate_SCIL then
4805 Make_SCIL_Dispatch_Table_Tag_Init (Sloc (Last (Result)));
4806 Set_SCIL_Entity (New_Node, Typ);
4807 Set_SCIL_Node (Last (Result), New_Node);
4811 Make_Object_Declaration (Loc,
4812 Defining_Identifier =>
4813 Node (Next_Elmt (First_Elmt (Access_Disp_Table (Typ)))),
4814 Constant_Present => True,
4815 Object_Definition => New_Reference_To
4816 (RTE (RE_Address), Loc),
4818 Make_Attribute_Reference (Loc,
4820 Make_Selected_Component (Loc,
4821 Prefix => New_Reference_To (DT, Loc),
4824 (RTE_Record_Component (RE_Predef_Prims), Loc)),
4825 Attribute_Name => Name_Address)));
4829 -- Generate: Exname : constant String := full_qualified_name (typ);
4830 -- The type itself may be an anonymous parent type, so use the first
4831 -- subtype to have a user-recognizable name.
4834 Make_Object_Declaration (Loc,
4835 Defining_Identifier => Exname,
4836 Constant_Present => True,
4837 Object_Definition => New_Reference_To (Standard_String, Loc),
4839 Make_String_Literal (Loc,
4840 Fully_Qualified_Name_String (First_Subtype (Typ)))));
4842 Set_Is_Statically_Allocated (Exname);
4843 Set_Is_True_Constant (Exname);
4845 -- Declare the object used by Ada.Tags.Register_Tag
4847 if RTE_Available (RE_Register_Tag) then
4849 Make_Object_Declaration (Loc,
4850 Defining_Identifier => HT_Link,
4851 Object_Definition => New_Reference_To (RTE (RE_Tag), Loc)));
4854 -- Generate code to create the storage for the type specific data object
4855 -- with enough space to store the tags of the ancestors plus the tags
4856 -- of all the implemented interfaces (as described in a-tags.adb).
4858 -- TSD : Type_Specific_Data (I_Depth) :=
4859 -- (Idepth => I_Depth,
4860 -- Access_Level => Type_Access_Level (Typ),
4861 -- Alignment => Typ'Alignment,
4862 -- Expanded_Name => Cstring_Ptr!(Exname'Address))
4863 -- External_Tag => Cstring_Ptr!(Exname'Address))
4864 -- HT_Link => HT_Link'Address,
4865 -- Transportable => <<boolean-value>>,
4866 -- Type_Is_Abstract => <<boolean-value>>,
4867 -- Needs_Finalization => <<boolean-value>>,
4868 -- [ Size_Func => Size_Prim'Access, ]
4869 -- [ Interfaces_Table => <<access-value>>, ]
4870 -- [ SSD => SSD_Table'Address ]
4871 -- Tags_Table => (0 => null,
4874 -- for TSD'Alignment use Address'Alignment
4876 TSD_Aggr_List := New_List;
4878 -- Idepth: Count ancestors to compute the inheritance depth. For private
4879 -- extensions, always go to the full view in order to compute the real
4880 -- inheritance depth.
4883 Current_Typ : Entity_Id;
4884 Parent_Typ : Entity_Id;
4890 Parent_Typ := Etype (Current_Typ);
4892 if Is_Private_Type (Parent_Typ) then
4893 Parent_Typ := Full_View (Base_Type (Parent_Typ));
4896 exit when Parent_Typ = Current_Typ;
4898 I_Depth := I_Depth + 1;
4899 Current_Typ := Parent_Typ;
4903 Append_To (TSD_Aggr_List,
4904 Make_Integer_Literal (Loc, I_Depth));
4908 Append_To (TSD_Aggr_List,
4909 Make_Integer_Literal (Loc, Type_Access_Level (Typ)));
4913 -- For CPP types we cannot rely on the value of 'Alignment provided
4914 -- by the backend to initialize this TSD field.
4916 if Convention (Typ) = Convention_CPP
4917 or else Is_CPP_Class (Root_Type (Typ))
4919 Append_To (TSD_Aggr_List,
4920 Make_Integer_Literal (Loc, 0));
4922 Append_To (TSD_Aggr_List,
4923 Make_Attribute_Reference (Loc,
4924 Prefix => New_Reference_To (Typ, Loc),
4925 Attribute_Name => Name_Alignment));
4930 Append_To (TSD_Aggr_List,
4931 Unchecked_Convert_To (RTE (RE_Cstring_Ptr),
4932 Make_Attribute_Reference (Loc,
4933 Prefix => New_Reference_To (Exname, Loc),
4934 Attribute_Name => Name_Address)));
4936 -- External_Tag of a local tagged type
4938 -- <typ>A : constant String :=
4939 -- "Internal tag at 16#tag-addr#: <full-name-of-typ>";
4941 -- The reason we generate this strange name is that we do not want to
4942 -- enter local tagged types in the global hash table used to compute
4943 -- the Internal_Tag attribute for two reasons:
4945 -- 1. It is hard to avoid a tasking race condition for entering the
4946 -- entry into the hash table.
4948 -- 2. It would cause a storage leak, unless we rig up considerable
4949 -- mechanism to remove the entry from the hash table on exit.
4951 -- So what we do is to generate the above external tag name, where the
4952 -- hex address is the address of the local dispatch table (i.e. exactly
4953 -- the value we want if Internal_Tag is computed from this string).
4955 -- Of course this value will only be valid if the tagged type is still
4956 -- in scope, but it clearly must be erroneous to compute the internal
4957 -- tag of a tagged type that is out of scope!
4959 -- We don't do this processing if an explicit external tag has been
4960 -- specified. That's an odd case for which we have already issued a
4961 -- warning, where we will not be able to compute the internal tag.
4963 if not Is_Library_Level_Entity (Typ)
4964 and then not Has_External_Tag_Rep_Clause (Typ)
4967 Exname : constant Entity_Id :=
4968 Make_Defining_Identifier (Loc,
4969 New_External_Name (Tname, 'A'));
4971 Full_Name : constant String_Id :=
4972 Fully_Qualified_Name_String (First_Subtype (Typ));
4973 Str1_Id : String_Id;
4974 Str2_Id : String_Id;
4978 -- Str1 = "Internal tag at 16#";
4981 Store_String_Chars ("Internal tag at 16#");
4982 Str1_Id := End_String;
4985 -- Str2 = "#: <type-full-name>";
4988 Store_String_Chars ("#: ");
4989 Store_String_Chars (Full_Name);
4990 Str2_Id := End_String;
4993 -- Exname : constant String :=
4994 -- Str1 & Address_Image (Tag) & Str2;
4996 if RTE_Available (RE_Address_Image) then
4998 Make_Object_Declaration (Loc,
4999 Defining_Identifier => Exname,
5000 Constant_Present => True,
5001 Object_Definition => New_Reference_To
5002 (Standard_String, Loc),
5004 Make_Op_Concat (Loc,
5006 Make_String_Literal (Loc, Str1_Id),
5008 Make_Op_Concat (Loc,
5010 Make_Function_Call (Loc,
5013 (RTE (RE_Address_Image), Loc),
5014 Parameter_Associations => New_List (
5015 Unchecked_Convert_To (RTE (RE_Address),
5016 New_Reference_To (DT_Ptr, Loc)))),
5018 Make_String_Literal (Loc, Str2_Id)))));
5022 Make_Object_Declaration (Loc,
5023 Defining_Identifier => Exname,
5024 Constant_Present => True,
5025 Object_Definition => New_Reference_To
5026 (Standard_String, Loc),
5028 Make_Op_Concat (Loc,
5030 Make_String_Literal (Loc, Str1_Id),
5032 Make_String_Literal (Loc, Str2_Id))));
5036 Unchecked_Convert_To (RTE (RE_Cstring_Ptr),
5037 Make_Attribute_Reference (Loc,
5038 Prefix => New_Reference_To (Exname, Loc),
5039 Attribute_Name => Name_Address));
5042 -- External tag of a library-level tagged type: Check for a definition
5043 -- of External_Tag. The clause is considered only if it applies to this
5044 -- specific tagged type, as opposed to one of its ancestors.
5045 -- If the type is an unconstrained type extension, we are building the
5046 -- dispatch table of its anonymous base type, so the external tag, if
5047 -- any was specified, must be retrieved from the first subtype. Go to
5048 -- the full view in case the clause is in the private part.
5052 Def : constant Node_Id := Get_Attribute_Definition_Clause
5053 (Underlying_Type (First_Subtype (Typ)),
5054 Attribute_External_Tag);
5056 Old_Val : String_Id;
5057 New_Val : String_Id;
5061 if not Present (Def)
5062 or else Entity (Name (Def)) /= First_Subtype (Typ)
5065 Unchecked_Convert_To (RTE (RE_Cstring_Ptr),
5066 Make_Attribute_Reference (Loc,
5067 Prefix => New_Reference_To (Exname, Loc),
5068 Attribute_Name => Name_Address));
5070 Old_Val := Strval (Expr_Value_S (Expression (Def)));
5072 -- For the rep clause "for <typ>'external_tag use y" generate:
5074 -- <typ>A : constant string := y;
5076 -- <typ>A'Address is used to set the External_Tag component
5079 -- Create a new nul terminated string if it is not already
5081 if String_Length (Old_Val) > 0
5083 Get_String_Char (Old_Val, String_Length (Old_Val)) = 0
5087 Start_String (Old_Val);
5088 Store_String_Char (Get_Char_Code (ASCII.NUL));
5089 New_Val := End_String;
5092 E := Make_Defining_Identifier (Loc,
5093 New_External_Name (Chars (Typ), 'A'));
5096 Make_Object_Declaration (Loc,
5097 Defining_Identifier => E,
5098 Constant_Present => True,
5099 Object_Definition =>
5100 New_Reference_To (Standard_String, Loc),
5102 Make_String_Literal (Loc, New_Val)));
5105 Unchecked_Convert_To (RTE (RE_Cstring_Ptr),
5106 Make_Attribute_Reference (Loc,
5107 Prefix => New_Reference_To (E, Loc),
5108 Attribute_Name => Name_Address));
5113 Append_To (TSD_Aggr_List, New_Node);
5117 if RTE_Available (RE_Register_Tag) then
5118 Append_To (TSD_Aggr_List,
5119 Unchecked_Convert_To (RTE (RE_Tag_Ptr),
5120 Make_Attribute_Reference (Loc,
5121 Prefix => New_Reference_To (HT_Link, Loc),
5122 Attribute_Name => Name_Address)));
5124 Append_To (TSD_Aggr_List,
5125 Unchecked_Convert_To (RTE (RE_Tag_Ptr),
5126 New_Reference_To (RTE (RE_Null_Address), Loc)));
5129 -- Transportable: Set for types that can be used in remote calls
5130 -- with respect to E.4(18) legality rules.
5133 Transportable : Entity_Id;
5139 or else Is_Shared_Passive (Typ)
5141 ((Is_Remote_Types (Typ)
5142 or else Is_Remote_Call_Interface (Typ))
5143 and then Original_View_In_Visible_Part (Typ))
5144 or else not Comes_From_Source (Typ));
5146 Append_To (TSD_Aggr_List,
5147 New_Occurrence_Of (Transportable, Loc));
5150 -- Type_Is_Abstract (Ada 2012: AI05-0173). This functionality is
5151 -- not available in the HIE runtime.
5153 if RTE_Record_Component_Available (RE_Type_Is_Abstract) then
5155 Type_Is_Abstract : Entity_Id;
5159 Boolean_Literals (Is_Abstract_Type (Typ));
5161 Append_To (TSD_Aggr_List,
5162 New_Occurrence_Of (Type_Is_Abstract, Loc));
5166 -- Needs_Finalization: Set if the type is controlled or has controlled
5170 Needs_Fin : Entity_Id;
5173 Needs_Fin := Boolean_Literals (Needs_Finalization (Typ));
5174 Append_To (TSD_Aggr_List, New_Occurrence_Of (Needs_Fin, Loc));
5179 if RTE_Record_Component_Available (RE_Size_Func) then
5181 -- Initialize this field to Null_Address if we are not building
5182 -- static dispatch tables static or if the size function is not
5183 -- available. In the former case we cannot initialize this field
5184 -- until the function is frozen and registered in the dispatch
5185 -- table (see Register_Primitive).
5187 if not Building_Static_DT (Typ) or else not Has_DT (Typ) then
5188 Append_To (TSD_Aggr_List,
5189 Unchecked_Convert_To (RTE (RE_Size_Ptr),
5190 New_Reference_To (RTE (RE_Null_Address), Loc)));
5194 Prim_Elmt : Elmt_Id;
5196 Size_Comp : Node_Id;
5199 Prim_Elmt := First_Elmt (Primitive_Operations (Typ));
5200 while Present (Prim_Elmt) loop
5201 Prim := Node (Prim_Elmt);
5203 if Chars (Prim) = Name_uSize then
5204 Prim := Ultimate_Alias (Prim);
5206 if Is_Abstract_Subprogram (Prim) then
5208 Unchecked_Convert_To (RTE (RE_Size_Ptr),
5209 New_Reference_To (RTE (RE_Null_Address), Loc));
5212 Unchecked_Convert_To (RTE (RE_Size_Ptr),
5213 Make_Attribute_Reference (Loc,
5214 Prefix => New_Reference_To (Prim, Loc),
5215 Attribute_Name => Name_Unrestricted_Access));
5221 Next_Elmt (Prim_Elmt);
5224 pragma Assert (Present (Size_Comp));
5225 Append_To (TSD_Aggr_List, Size_Comp);
5230 -- Interfaces_Table (required for AI-405)
5232 if RTE_Record_Component_Available (RE_Interfaces_Table) then
5234 -- Count the number of interface types implemented by Typ
5236 Collect_Interfaces (Typ, Typ_Ifaces);
5238 AI := First_Elmt (Typ_Ifaces);
5239 while Present (AI) loop
5240 Num_Ifaces := Num_Ifaces + 1;
5244 if Num_Ifaces = 0 then
5245 Iface_Table_Node := Make_Null (Loc);
5247 -- Generate the Interface_Table object
5251 TSD_Ifaces_List : constant List_Id := New_List;
5253 Sec_DT_Tag : Node_Id;
5256 AI := First_Elmt (Typ_Ifaces);
5257 while Present (AI) loop
5258 if Is_Ancestor (Node (AI), Typ, Use_Full_View => True) then
5260 New_Reference_To (DT_Ptr, Loc);
5264 (Next_Elmt (First_Elmt (Access_Disp_Table (Typ))));
5265 pragma Assert (Has_Thunks (Node (Elmt)));
5267 while Is_Tag (Node (Elmt))
5269 Is_Ancestor (Node (AI), Related_Type (Node (Elmt)),
5270 Use_Full_View => True)
5272 pragma Assert (Has_Thunks (Node (Elmt)));
5274 pragma Assert (Has_Thunks (Node (Elmt)));
5276 pragma Assert (not Has_Thunks (Node (Elmt)));
5278 pragma Assert (not Has_Thunks (Node (Elmt)));
5282 pragma Assert (Ekind (Node (Elmt)) = E_Constant
5284 Has_Thunks (Node (Next_Elmt (Next_Elmt (Elmt)))));
5286 New_Reference_To (Node (Next_Elmt (Next_Elmt (Elmt))),
5290 Append_To (TSD_Ifaces_List,
5291 Make_Aggregate (Loc,
5292 Expressions => New_List (
5296 Unchecked_Convert_To (RTE (RE_Tag),
5298 (Node (First_Elmt (Access_Disp_Table (Node (AI)))),
5301 -- Static_Offset_To_Top
5303 New_Reference_To (Standard_True, Loc),
5305 -- Offset_To_Top_Value
5307 Make_Integer_Literal (Loc, 0),
5309 -- Offset_To_Top_Func
5315 Unchecked_Convert_To (RTE (RE_Tag), Sec_DT_Tag)
5322 Name_ITable := New_External_Name (Tname, 'I');
5323 ITable := Make_Defining_Identifier (Loc, Name_ITable);
5324 Set_Is_Statically_Allocated (ITable,
5325 Is_Library_Level_Tagged_Type (Typ));
5327 -- The table of interfaces is not constant; its slots are
5328 -- filled at run time by the IP routine using attribute
5329 -- 'Position to know the location of the tag components
5330 -- (and this attribute cannot be safely used before the
5331 -- object is initialized).
5334 Make_Object_Declaration (Loc,
5335 Defining_Identifier => ITable,
5336 Aliased_Present => True,
5337 Constant_Present => False,
5338 Object_Definition =>
5339 Make_Subtype_Indication (Loc,
5341 New_Reference_To (RTE (RE_Interface_Data), Loc),
5342 Constraint => Make_Index_Or_Discriminant_Constraint
5344 Constraints => New_List (
5345 Make_Integer_Literal (Loc, Num_Ifaces)))),
5347 Expression => Make_Aggregate (Loc,
5348 Expressions => New_List (
5349 Make_Integer_Literal (Loc, Num_Ifaces),
5350 Make_Aggregate (Loc,
5351 Expressions => TSD_Ifaces_List)))));
5354 Make_Attribute_Definition_Clause (Loc,
5355 Name => New_Reference_To (ITable, Loc),
5356 Chars => Name_Alignment,
5358 Make_Attribute_Reference (Loc,
5360 New_Reference_To (RTE (RE_Integer_Address), Loc),
5361 Attribute_Name => Name_Alignment)));
5364 Make_Attribute_Reference (Loc,
5365 Prefix => New_Reference_To (ITable, Loc),
5366 Attribute_Name => Name_Unchecked_Access);
5370 Append_To (TSD_Aggr_List, Iface_Table_Node);
5373 -- Generate the Select Specific Data table for synchronized types that
5374 -- implement synchronized interfaces. The size of the table is
5375 -- constrained by the number of non-predefined primitive operations.
5377 if RTE_Record_Component_Available (RE_SSD) then
5378 if Ada_Version >= Ada_2005
5379 and then Has_DT (Typ)
5380 and then Is_Concurrent_Record_Type (Typ)
5381 and then Has_Interfaces (Typ)
5382 and then Nb_Prim > 0
5383 and then not Is_Abstract_Type (Typ)
5384 and then not Is_Controlled (Typ)
5385 and then not Restriction_Active (No_Dispatching_Calls)
5386 and then not Restriction_Active (No_Select_Statements)
5389 Make_Object_Declaration (Loc,
5390 Defining_Identifier => SSD,
5391 Aliased_Present => True,
5392 Object_Definition =>
5393 Make_Subtype_Indication (Loc,
5394 Subtype_Mark => New_Reference_To (
5395 RTE (RE_Select_Specific_Data), Loc),
5397 Make_Index_Or_Discriminant_Constraint (Loc,
5398 Constraints => New_List (
5399 Make_Integer_Literal (Loc, Nb_Prim))))));
5402 Make_Attribute_Definition_Clause (Loc,
5403 Name => New_Reference_To (SSD, Loc),
5404 Chars => Name_Alignment,
5406 Make_Attribute_Reference (Loc,
5408 New_Reference_To (RTE (RE_Integer_Address), Loc),
5409 Attribute_Name => Name_Alignment)));
5411 -- This table is initialized by Make_Select_Specific_Data_Table,
5412 -- which calls Set_Entry_Index and Set_Prim_Op_Kind.
5414 Append_To (TSD_Aggr_List,
5415 Make_Attribute_Reference (Loc,
5416 Prefix => New_Reference_To (SSD, Loc),
5417 Attribute_Name => Name_Unchecked_Access));
5419 Append_To (TSD_Aggr_List, Make_Null (Loc));
5423 -- Initialize the table of ancestor tags. In case of interface types
5424 -- this table is not needed.
5426 TSD_Tags_List := New_List;
5428 -- If we are not statically allocating the dispatch table then we must
5429 -- fill position 0 with null because we still have not generated the
5432 if not Building_Static_DT (Typ)
5433 or else Is_Interface (Typ)
5435 Append_To (TSD_Tags_List,
5436 Unchecked_Convert_To (RTE (RE_Tag),
5437 New_Reference_To (RTE (RE_Null_Address), Loc)));
5439 -- Otherwise we can safely reference the tag
5442 Append_To (TSD_Tags_List,
5443 New_Reference_To (DT_Ptr, Loc));
5446 -- Fill the rest of the table with the tags of the ancestors
5449 Current_Typ : Entity_Id;
5450 Parent_Typ : Entity_Id;
5458 Parent_Typ := Etype (Current_Typ);
5460 if Is_Private_Type (Parent_Typ) then
5461 Parent_Typ := Full_View (Base_Type (Parent_Typ));
5464 exit when Parent_Typ = Current_Typ;
5466 if Is_CPP_Class (Parent_Typ) then
5468 -- The tags defined in the C++ side will be inherited when
5469 -- the object is constructed (Exp_Ch3.Build_Init_Procedure)
5471 Append_To (TSD_Tags_List,
5472 Unchecked_Convert_To (RTE (RE_Tag),
5473 New_Reference_To (RTE (RE_Null_Address), Loc)));
5475 Append_To (TSD_Tags_List,
5477 (Node (First_Elmt (Access_Disp_Table (Parent_Typ))),
5482 Current_Typ := Parent_Typ;
5485 pragma Assert (Pos = I_Depth + 1);
5488 Append_To (TSD_Aggr_List,
5489 Make_Aggregate (Loc,
5490 Expressions => TSD_Tags_List));
5492 -- Build the TSD object
5495 Make_Object_Declaration (Loc,
5496 Defining_Identifier => TSD,
5497 Aliased_Present => True,
5498 Constant_Present => Building_Static_DT (Typ),
5499 Object_Definition =>
5500 Make_Subtype_Indication (Loc,
5501 Subtype_Mark => New_Reference_To (
5502 RTE (RE_Type_Specific_Data), Loc),
5504 Make_Index_Or_Discriminant_Constraint (Loc,
5505 Constraints => New_List (
5506 Make_Integer_Literal (Loc, I_Depth)))),
5508 Expression => Make_Aggregate (Loc,
5509 Expressions => TSD_Aggr_List)));
5511 Set_Is_True_Constant (TSD, Building_Static_DT (Typ));
5514 Make_Attribute_Definition_Clause (Loc,
5515 Name => New_Reference_To (TSD, Loc),
5516 Chars => Name_Alignment,
5518 Make_Attribute_Reference (Loc,
5519 Prefix => New_Reference_To (RTE (RE_Integer_Address), Loc),
5520 Attribute_Name => Name_Alignment)));
5522 -- Initialize or declare the dispatch table object
5524 if not Has_DT (Typ) then
5525 DT_Constr_List := New_List;
5526 DT_Aggr_List := New_List;
5531 Make_Attribute_Reference (Loc,
5532 Prefix => New_Reference_To (TSD, Loc),
5533 Attribute_Name => Name_Address);
5535 Append_To (DT_Constr_List, New_Node);
5536 Append_To (DT_Aggr_List, New_Copy (New_Node));
5537 Append_To (DT_Aggr_List, Make_Integer_Literal (Loc, 0));
5539 -- In case of locally defined tagged types we have already declared
5540 -- and uninitialized object for the dispatch table, which is now
5541 -- initialized by means of the following assignment:
5543 -- DT := (TSD'Address, 0);
5545 if not Building_Static_DT (Typ) then
5547 Make_Assignment_Statement (Loc,
5548 Name => New_Reference_To (DT, Loc),
5549 Expression => Make_Aggregate (Loc,
5550 Expressions => DT_Aggr_List)));
5552 -- In case of library level tagged types we declare and export now
5553 -- the constant object containing the dummy dispatch table. There
5554 -- is no need to declare the tag here because it has been previously
5555 -- declared by Make_Tags
5557 -- DT : aliased constant No_Dispatch_Table :=
5558 -- (NDT_TSD => TSD'Address;
5559 -- NDT_Prims_Ptr => 0);
5560 -- for DT'Alignment use Address'Alignment;
5564 Make_Object_Declaration (Loc,
5565 Defining_Identifier => DT,
5566 Aliased_Present => True,
5567 Constant_Present => True,
5568 Object_Definition =>
5569 New_Reference_To (RTE (RE_No_Dispatch_Table_Wrapper), Loc),
5570 Expression => Make_Aggregate (Loc,
5571 Expressions => DT_Aggr_List)));
5574 Make_Attribute_Definition_Clause (Loc,
5575 Name => New_Reference_To (DT, Loc),
5576 Chars => Name_Alignment,
5578 Make_Attribute_Reference (Loc,
5580 New_Reference_To (RTE (RE_Integer_Address), Loc),
5581 Attribute_Name => Name_Alignment)));
5583 Export_DT (Typ, DT);
5586 -- Common case: Typ has a dispatch table
5590 -- Predef_Prims : Address_Array (1 .. Default_Prim_Ops_Count) :=
5591 -- (predef-prim-op-1'address,
5592 -- predef-prim-op-2'address,
5594 -- predef-prim-op-n'address);
5595 -- for Predef_Prims'Alignment use Address'Alignment
5597 -- DT : Dispatch_Table (Nb_Prims) :=
5598 -- (Signature => <sig-value>,
5599 -- Tag_Kind => <tag_kind-value>,
5600 -- Predef_Prims => Predef_Prims'First'Address,
5601 -- Offset_To_Top => 0,
5602 -- TSD => TSD'Address;
5603 -- Prims_Ptr => (prim-op-1'address,
5604 -- prim-op-2'address,
5606 -- prim-op-n'address));
5607 -- for DT'Alignment use Address'Alignment
5614 if not Building_Static_DT (Typ) then
5615 Nb_Predef_Prims := Max_Predef_Prims;
5618 Prim_Elmt := First_Elmt (Primitive_Operations (Typ));
5619 while Present (Prim_Elmt) loop
5620 Prim := Node (Prim_Elmt);
5622 if Is_Predefined_Dispatching_Operation (Prim)
5623 and then not Is_Abstract_Subprogram (Prim)
5625 Pos := UI_To_Int (DT_Position (Prim));
5627 if Pos > Nb_Predef_Prims then
5628 Nb_Predef_Prims := Pos;
5632 Next_Elmt (Prim_Elmt);
5638 (Nat range 1 .. Nb_Predef_Prims) of Entity_Id;
5643 Prim_Ops_Aggr_List := New_List;
5645 Prim_Table := (others => Empty);
5647 if Building_Static_DT (Typ) then
5648 Prim_Elmt := First_Elmt (Primitive_Operations (Typ));
5649 while Present (Prim_Elmt) loop
5650 Prim := Node (Prim_Elmt);
5652 if Is_Predefined_Dispatching_Operation (Prim)
5653 and then not Is_Abstract_Subprogram (Prim)
5654 and then not Is_Eliminated (Prim)
5655 and then not Present (Prim_Table
5656 (UI_To_Int (DT_Position (Prim))))
5658 E := Ultimate_Alias (Prim);
5659 pragma Assert (not Is_Abstract_Subprogram (E));
5660 Prim_Table (UI_To_Int (DT_Position (Prim))) := E;
5663 Next_Elmt (Prim_Elmt);
5667 for J in Prim_Table'Range loop
5668 if Present (Prim_Table (J)) then
5670 Unchecked_Convert_To (RTE (RE_Prim_Ptr),
5671 Make_Attribute_Reference (Loc,
5672 Prefix => New_Reference_To (Prim_Table (J), Loc),
5673 Attribute_Name => Name_Unrestricted_Access));
5675 New_Node := Make_Null (Loc);
5678 Append_To (Prim_Ops_Aggr_List, New_Node);
5682 Make_Aggregate (Loc,
5683 Expressions => Prim_Ops_Aggr_List);
5686 Make_Subtype_Declaration (Loc,
5687 Defining_Identifier => Make_Temporary (Loc, 'S'),
5688 Subtype_Indication =>
5689 New_Reference_To (RTE (RE_Address_Array), Loc));
5691 Append_To (Result, Decl);
5694 Make_Object_Declaration (Loc,
5695 Defining_Identifier => Predef_Prims,
5696 Aliased_Present => True,
5697 Constant_Present => Building_Static_DT (Typ),
5698 Object_Definition => New_Reference_To
5699 (Defining_Identifier (Decl), Loc),
5700 Expression => New_Node));
5702 -- Remember aggregates initializing dispatch tables
5704 Append_Elmt (New_Node, DT_Aggr);
5707 Make_Attribute_Definition_Clause (Loc,
5708 Name => New_Reference_To (Predef_Prims, Loc),
5709 Chars => Name_Alignment,
5711 Make_Attribute_Reference (Loc,
5713 New_Reference_To (RTE (RE_Integer_Address), Loc),
5714 Attribute_Name => Name_Alignment)));
5718 -- Stage 1: Initialize the discriminant and the record components
5720 DT_Constr_List := New_List;
5721 DT_Aggr_List := New_List;
5723 -- Num_Prims. If the tagged type has no primitives we add a dummy
5724 -- slot whose address will be the tag of this type.
5727 New_Node := Make_Integer_Literal (Loc, 1);
5729 New_Node := Make_Integer_Literal (Loc, Nb_Prim);
5732 Append_To (DT_Constr_List, New_Node);
5733 Append_To (DT_Aggr_List, New_Copy (New_Node));
5737 if RTE_Record_Component_Available (RE_Signature) then
5738 Append_To (DT_Aggr_List,
5739 New_Reference_To (RTE (RE_Primary_DT), Loc));
5744 if RTE_Record_Component_Available (RE_Tag_Kind) then
5745 Append_To (DT_Aggr_List, Tagged_Kind (Typ));
5750 Append_To (DT_Aggr_List,
5751 Make_Attribute_Reference (Loc,
5752 Prefix => New_Reference_To (Predef_Prims, Loc),
5753 Attribute_Name => Name_Address));
5757 Append_To (DT_Aggr_List, Make_Integer_Literal (Loc, 0));
5761 Append_To (DT_Aggr_List,
5762 Make_Attribute_Reference (Loc,
5763 Prefix => New_Reference_To (TSD, Loc),
5764 Attribute_Name => Name_Address));
5766 -- Stage 2: Initialize the table of primitive operations
5768 Prim_Ops_Aggr_List := New_List;
5771 Append_To (Prim_Ops_Aggr_List, Make_Null (Loc));
5773 elsif not Building_Static_DT (Typ) then
5774 for J in 1 .. Nb_Prim loop
5775 Append_To (Prim_Ops_Aggr_List, Make_Null (Loc));
5780 CPP_Nb_Prims : constant Nat := CPP_Num_Prims (Typ);
5783 Prim_Elmt : Elmt_Id;
5785 Prim_Table : array (Nat range 1 .. Nb_Prim) of Entity_Id;
5788 Prim_Table := (others => Empty);
5790 Prim_Elmt := First_Elmt (Primitive_Operations (Typ));
5791 while Present (Prim_Elmt) loop
5792 Prim := Node (Prim_Elmt);
5794 -- Retrieve the ultimate alias of the primitive for proper
5795 -- handling of renamings and eliminated primitives.
5797 E := Ultimate_Alias (Prim);
5798 Prim_Pos := UI_To_Int (DT_Position (E));
5800 -- Do not reference predefined primitives because they are
5801 -- located in a separate dispatch table; skip entities with
5802 -- attribute Interface_Alias because they are only required
5803 -- to build secondary dispatch tables; skip abstract and
5804 -- eliminated primitives; for derivations of CPP types skip
5805 -- primitives located in the C++ part of the dispatch table
5806 -- because their slot is initialized by the IC routine.
5808 if not Is_Predefined_Dispatching_Operation (Prim)
5809 and then not Is_Predefined_Dispatching_Operation (E)
5810 and then not Present (Interface_Alias (Prim))
5811 and then not Is_Abstract_Subprogram (E)
5812 and then not Is_Eliminated (E)
5813 and then (not Is_CPP_Class (Root_Type (Typ))
5814 or else Prim_Pos > CPP_Nb_Prims)
5817 (UI_To_Int (DT_Position (Prim)) <= Nb_Prim);
5819 Prim_Table (UI_To_Int (DT_Position (Prim))) := E;
5822 Next_Elmt (Prim_Elmt);
5825 for J in Prim_Table'Range loop
5826 if Present (Prim_Table (J)) then
5828 Unchecked_Convert_To (RTE (RE_Prim_Ptr),
5829 Make_Attribute_Reference (Loc,
5830 Prefix => New_Reference_To (Prim_Table (J), Loc),
5831 Attribute_Name => Name_Unrestricted_Access));
5833 New_Node := Make_Null (Loc);
5836 Append_To (Prim_Ops_Aggr_List, New_Node);
5842 Make_Aggregate (Loc,
5843 Expressions => Prim_Ops_Aggr_List);
5845 Append_To (DT_Aggr_List, New_Node);
5847 -- Remember aggregates initializing dispatch tables
5849 Append_Elmt (New_Node, DT_Aggr);
5851 -- In case of locally defined tagged types we have already declared
5852 -- and uninitialized object for the dispatch table, which is now
5853 -- initialized by means of an assignment.
5855 if not Building_Static_DT (Typ) then
5857 Make_Assignment_Statement (Loc,
5858 Name => New_Reference_To (DT, Loc),
5859 Expression => Make_Aggregate (Loc,
5860 Expressions => DT_Aggr_List)));
5862 -- In case of library level tagged types we declare now and export
5863 -- the constant object containing the dispatch table.
5867 Make_Object_Declaration (Loc,
5868 Defining_Identifier => DT,
5869 Aliased_Present => True,
5870 Constant_Present => True,
5871 Object_Definition =>
5872 Make_Subtype_Indication (Loc,
5873 Subtype_Mark => New_Reference_To
5874 (RTE (RE_Dispatch_Table_Wrapper), Loc),
5875 Constraint => Make_Index_Or_Discriminant_Constraint (Loc,
5876 Constraints => DT_Constr_List)),
5877 Expression => Make_Aggregate (Loc,
5878 Expressions => DT_Aggr_List)));
5881 Make_Attribute_Definition_Clause (Loc,
5882 Name => New_Reference_To (DT, Loc),
5883 Chars => Name_Alignment,
5885 Make_Attribute_Reference (Loc,
5887 New_Reference_To (RTE (RE_Integer_Address), Loc),
5888 Attribute_Name => Name_Alignment)));
5890 Export_DT (Typ, DT);
5894 -- Initialize the table of ancestor tags if not building static
5897 if not Building_Static_DT (Typ)
5898 and then not Is_Interface (Typ)
5899 and then not Is_CPP_Class (Typ)
5902 Make_Assignment_Statement (Loc,
5904 Make_Indexed_Component (Loc,
5906 Make_Selected_Component (Loc,
5908 New_Reference_To (TSD, Loc),
5911 (RTE_Record_Component (RE_Tags_Table), Loc)),
5913 New_List (Make_Integer_Literal (Loc, 0))),
5917 (Node (First_Elmt (Access_Disp_Table (Typ))), Loc)));
5920 -- Inherit the dispatch tables of the parent. There is no need to
5921 -- inherit anything from the parent when building static dispatch tables
5922 -- because the whole dispatch table (including inherited primitives) has
5923 -- been already built.
5925 if Building_Static_DT (Typ) then
5928 -- If the ancestor is a CPP_Class type we inherit the dispatch tables
5929 -- in the init proc, and we don't need to fill them in here.
5931 elsif Is_CPP_Class (Parent_Typ) then
5934 -- Otherwise we fill in the dispatch tables here
5937 if Typ /= Parent_Typ
5938 and then not Is_Interface (Typ)
5939 and then not Restriction_Active (No_Dispatching_Calls)
5941 -- Inherit the dispatch table
5943 if not Is_Interface (Typ)
5944 and then not Is_Interface (Parent_Typ)
5945 and then not Is_CPP_Class (Parent_Typ)
5948 Nb_Prims : constant Int :=
5949 UI_To_Int (DT_Entry_Count
5950 (First_Tag_Component (Parent_Typ)));
5953 Append_To (Elab_Code,
5954 Build_Inherit_Predefined_Prims (Loc,
5960 (Access_Disp_Table (Parent_Typ)))), Loc),
5966 (Access_Disp_Table (Typ)))), Loc)));
5968 if Nb_Prims /= 0 then
5969 Append_To (Elab_Code,
5970 Build_Inherit_Prims (Loc,
5976 (Access_Disp_Table (Parent_Typ))), Loc),
5977 New_Tag_Node => New_Reference_To (DT_Ptr, Loc),
5978 Num_Prims => Nb_Prims));
5983 -- Inherit the secondary dispatch tables of the ancestor
5985 if not Is_CPP_Class (Parent_Typ) then
5987 Sec_DT_Ancestor : Elmt_Id :=
5991 (Access_Disp_Table (Parent_Typ))));
5992 Sec_DT_Typ : Elmt_Id :=
5996 (Access_Disp_Table (Typ))));
5998 procedure Copy_Secondary_DTs (Typ : Entity_Id);
5999 -- Local procedure required to climb through the ancestors
6000 -- and copy the contents of all their secondary dispatch
6003 ------------------------
6004 -- Copy_Secondary_DTs --
6005 ------------------------
6007 procedure Copy_Secondary_DTs (Typ : Entity_Id) is
6012 -- Climb to the ancestor (if any) handling private types
6014 if Present (Full_View (Etype (Typ))) then
6015 if Full_View (Etype (Typ)) /= Typ then
6016 Copy_Secondary_DTs (Full_View (Etype (Typ)));
6019 elsif Etype (Typ) /= Typ then
6020 Copy_Secondary_DTs (Etype (Typ));
6023 if Present (Interfaces (Typ))
6024 and then not Is_Empty_Elmt_List (Interfaces (Typ))
6026 Iface := First_Elmt (Interfaces (Typ));
6027 E := First_Entity (Typ);
6029 and then Present (Node (Sec_DT_Ancestor))
6030 and then Ekind (Node (Sec_DT_Ancestor)) = E_Constant
6032 if Is_Tag (E) and then Chars (E) /= Name_uTag then
6034 Num_Prims : constant Int :=
6035 UI_To_Int (DT_Entry_Count (E));
6038 if not Is_Interface (Etype (Typ)) then
6040 -- Inherit first secondary dispatch table
6042 Append_To (Elab_Code,
6043 Build_Inherit_Predefined_Prims (Loc,
6045 Unchecked_Convert_To (RTE (RE_Tag),
6048 (Next_Elmt (Sec_DT_Ancestor)),
6051 Unchecked_Convert_To (RTE (RE_Tag),
6053 (Node (Next_Elmt (Sec_DT_Typ)),
6056 if Num_Prims /= 0 then
6057 Append_To (Elab_Code,
6058 Build_Inherit_Prims (Loc,
6059 Typ => Node (Iface),
6061 Unchecked_Convert_To
6064 (Node (Sec_DT_Ancestor),
6067 Unchecked_Convert_To
6070 (Node (Sec_DT_Typ), Loc)),
6071 Num_Prims => Num_Prims));
6075 Next_Elmt (Sec_DT_Ancestor);
6076 Next_Elmt (Sec_DT_Typ);
6078 -- Skip the secondary dispatch table of
6079 -- predefined primitives
6081 Next_Elmt (Sec_DT_Ancestor);
6082 Next_Elmt (Sec_DT_Typ);
6084 if not Is_Interface (Etype (Typ)) then
6086 -- Inherit second secondary dispatch table
6088 Append_To (Elab_Code,
6089 Build_Inherit_Predefined_Prims (Loc,
6091 Unchecked_Convert_To (RTE (RE_Tag),
6094 (Next_Elmt (Sec_DT_Ancestor)),
6097 Unchecked_Convert_To (RTE (RE_Tag),
6099 (Node (Next_Elmt (Sec_DT_Typ)),
6102 if Num_Prims /= 0 then
6103 Append_To (Elab_Code,
6104 Build_Inherit_Prims (Loc,
6105 Typ => Node (Iface),
6107 Unchecked_Convert_To
6110 (Node (Sec_DT_Ancestor),
6113 Unchecked_Convert_To
6116 (Node (Sec_DT_Typ), Loc)),
6117 Num_Prims => Num_Prims));
6122 Next_Elmt (Sec_DT_Ancestor);
6123 Next_Elmt (Sec_DT_Typ);
6125 -- Skip the secondary dispatch table of
6126 -- predefined primitives
6128 Next_Elmt (Sec_DT_Ancestor);
6129 Next_Elmt (Sec_DT_Typ);
6137 end Copy_Secondary_DTs;
6140 if Present (Node (Sec_DT_Ancestor))
6141 and then Ekind (Node (Sec_DT_Ancestor)) = E_Constant
6143 -- Handle private types
6145 if Present (Full_View (Typ)) then
6146 Copy_Secondary_DTs (Full_View (Typ));
6148 Copy_Secondary_DTs (Typ);
6156 -- If the type has a representation clause which specifies its external
6157 -- tag then generate code to check if the external tag of this type is
6158 -- the same as the external tag of some other declaration.
6160 -- Check_TSD (TSD'Unrestricted_Access);
6162 -- This check is a consequence of AI05-0113-1/06, so it officially
6163 -- applies to Ada 2005 (and Ada 2012). It might be argued that it is
6164 -- a desirable check to add in Ada 95 mode, but we hesitate to make
6165 -- this change, as it would be incompatible, and could conceivably
6166 -- cause a problem in existing Aa 95 code.
6168 -- We check for No_Run_Time_Mode here, because we do not want to pick
6169 -- up the RE_Check_TSD entity and call it in No_Run_Time mode.
6171 if not No_Run_Time_Mode
6172 and then Ada_Version >= Ada_2005
6173 and then Has_External_Tag_Rep_Clause (Typ)
6174 and then RTE_Available (RE_Check_TSD)
6175 and then not Debug_Flag_QQ
6177 Append_To (Elab_Code,
6178 Make_Procedure_Call_Statement (Loc,
6179 Name => New_Reference_To (RTE (RE_Check_TSD), Loc),
6180 Parameter_Associations => New_List (
6181 Make_Attribute_Reference (Loc,
6182 Prefix => New_Reference_To (TSD, Loc),
6183 Attribute_Name => Name_Unchecked_Access))));
6186 -- Generate code to register the Tag in the External_Tag hash table for
6187 -- the pure Ada type only.
6189 -- Register_Tag (Dt_Ptr);
6191 -- Skip this action in the following cases:
6192 -- 1) if Register_Tag is not available.
6193 -- 2) in No_Run_Time mode.
6194 -- 3) if Typ is not defined at the library level (this is required
6195 -- to avoid adding concurrency control to the hash table used
6196 -- by the run-time to register the tags).
6198 if not No_Run_Time_Mode
6199 and then Is_Library_Level_Entity (Typ)
6200 and then RTE_Available (RE_Register_Tag)
6202 Append_To (Elab_Code,
6203 Make_Procedure_Call_Statement (Loc,
6204 Name => New_Reference_To (RTE (RE_Register_Tag), Loc),
6205 Parameter_Associations =>
6206 New_List (New_Reference_To (DT_Ptr, Loc))));
6209 if not Is_Empty_List (Elab_Code) then
6210 Append_List_To (Result, Elab_Code);
6213 -- Populate the two auxiliary tables used for dispatching asynchronous,
6214 -- conditional and timed selects for synchronized types that implement
6215 -- a limited interface. Skip this step in Ravenscar profile or when
6216 -- general dispatching is forbidden.
6218 if Ada_Version >= Ada_2005
6219 and then Is_Concurrent_Record_Type (Typ)
6220 and then Has_Interfaces (Typ)
6221 and then not Restriction_Active (No_Dispatching_Calls)
6222 and then not Restriction_Active (No_Select_Statements)
6224 Append_List_To (Result,
6225 Make_Select_Specific_Data_Table (Typ));
6228 -- Remember entities containing dispatch tables
6230 Append_Elmt (Predef_Prims, DT_Decl);
6231 Append_Elmt (DT, DT_Decl);
6233 Analyze_List (Result, Suppress => All_Checks);
6234 Set_Has_Dispatch_Table (Typ);
6236 -- Mark entities containing dispatch tables. Required by the backend to
6237 -- handle them properly.
6239 if Has_DT (Typ) then
6244 -- Ensure that entities Prim_Ptr and Predef_Prims_Table_Ptr have
6245 -- the decoration required by the backend
6247 Set_Is_Dispatch_Table_Entity (RTE (RE_Prim_Ptr));
6248 Set_Is_Dispatch_Table_Entity (RTE (RE_Predef_Prims_Table_Ptr));
6250 -- Object declarations
6252 Elmt := First_Elmt (DT_Decl);
6253 while Present (Elmt) loop
6254 Set_Is_Dispatch_Table_Entity (Node (Elmt));
6255 pragma Assert (Ekind (Etype (Node (Elmt))) = E_Array_Subtype
6256 or else Ekind (Etype (Node (Elmt))) = E_Record_Subtype);
6257 Set_Is_Dispatch_Table_Entity (Etype (Node (Elmt)));
6261 -- Aggregates initializing dispatch tables
6263 Elmt := First_Elmt (DT_Aggr);
6264 while Present (Elmt) loop
6265 Set_Is_Dispatch_Table_Entity (Etype (Node (Elmt)));
6271 -- Register the tagged type in the call graph nodes table
6273 Register_CG_Node (Typ);
6282 function Make_VM_TSD (Typ : Entity_Id) return List_Id is
6283 Loc : constant Source_Ptr := Sloc (Typ);
6284 Result : constant List_Id := New_List;
6286 function Count_Primitives (Typ : Entity_Id) return Nat;
6287 -- Count the non-predefined primitive operations of Typ
6289 ----------------------
6290 -- Count_Primitives --
6291 ----------------------
6293 function Count_Primitives (Typ : Entity_Id) return Nat is
6295 Prim_Elmt : Elmt_Id;
6301 Prim_Elmt := First_Elmt (Primitive_Operations (Typ));
6302 while Present (Prim_Elmt) loop
6303 Prim := Node (Prim_Elmt);
6305 if Is_Predefined_Dispatching_Operation (Prim)
6306 or else Is_Predefined_Dispatching_Alias (Prim)
6310 elsif Present (Interface_Alias (Prim)) then
6314 Nb_Prim := Nb_Prim + 1;
6317 Next_Elmt (Prim_Elmt);
6321 end Count_Primitives;
6327 function Make_OSD (Iface : Entity_Id) return Node_Id;
6328 -- Generate the Object Specific Data table required to dispatch calls
6329 -- through synchronized interfaces. Returns a node that references the
6330 -- generated OSD object.
6332 function Make_OSD (Iface : Entity_Id) return Node_Id is
6333 Nb_Prim : constant Nat := Count_Primitives (Iface);
6335 OSD_Aggr_List : List_Id;
6339 -- OSD : Ada.Tags.Object_Specific_Data (Nb_Prims) :=
6340 -- (OSD_Table => (1 => <value>,
6345 or else Is_Abstract_Type (Typ)
6346 or else Is_Controlled (Typ)
6347 or else Restriction_Active (No_Dispatching_Calls)
6348 or else not Is_Limited_Type (Typ)
6349 or else not Has_Interfaces (Typ)
6350 or else not RTE_Record_Component_Available (RE_OSD_Table)
6352 -- No OSD table required
6354 return Make_Null (Loc);
6357 OSD_Aggr_List := New_List;
6360 Prim_Table : array (Nat range 1 .. Nb_Prim) of Entity_Id;
6362 Prim_Alias : Entity_Id;
6363 Prim_Elmt : Elmt_Id;
6369 Prim_Table := (others => Empty);
6370 Prim_Alias := Empty;
6372 Prim_Elmt := First_Elmt (Primitive_Operations (Typ));
6373 while Present (Prim_Elmt) loop
6374 Prim := Node (Prim_Elmt);
6376 if Present (Interface_Alias (Prim))
6377 and then Find_Dispatching_Type
6378 (Interface_Alias (Prim)) = Iface
6380 Prim_Alias := Interface_Alias (Prim);
6381 E := Ultimate_Alias (Prim);
6382 Pos := UI_To_Int (DT_Position (Prim_Alias));
6384 if Present (Prim_Table (Pos)) then
6385 pragma Assert (Prim_Table (Pos) = E);
6389 Prim_Table (Pos) := E;
6391 Append_To (OSD_Aggr_List,
6392 Make_Component_Association (Loc,
6393 Choices => New_List (
6394 Make_Integer_Literal (Loc,
6395 DT_Position (Prim_Alias))),
6397 Make_Integer_Literal (Loc,
6398 DT_Position (Alias (Prim)))));
6404 Next_Elmt (Prim_Elmt);
6406 pragma Assert (Count = Nb_Prim);
6409 OSD := Make_Temporary (Loc, 'I');
6412 Make_Object_Declaration (Loc,
6413 Defining_Identifier => OSD,
6414 Aliased_Present => True,
6415 Constant_Present => True,
6416 Object_Definition =>
6417 Make_Subtype_Indication (Loc,
6419 New_Reference_To (RTE (RE_Object_Specific_Data), Loc),
6421 Make_Index_Or_Discriminant_Constraint (Loc,
6422 Constraints => New_List (
6423 Make_Integer_Literal (Loc, Nb_Prim)))),
6426 Make_Aggregate (Loc,
6427 Component_Associations => New_List (
6428 Make_Component_Association (Loc,
6429 Choices => New_List (
6431 (RTE_Record_Component (RE_OSD_Num_Prims), Loc)),
6433 Make_Integer_Literal (Loc, Nb_Prim)),
6435 Make_Component_Association (Loc,
6436 Choices => New_List (
6438 (RTE_Record_Component (RE_OSD_Table), Loc)),
6439 Expression => Make_Aggregate (Loc,
6440 Component_Associations => OSD_Aggr_List))))));
6443 Make_Attribute_Reference (Loc,
6444 Prefix => New_Reference_To (OSD, Loc),
6445 Attribute_Name => Name_Unchecked_Access);
6451 Nb_Prim : constant Nat := Count_Primitives (Typ);
6454 Iface_Table_Node : Node_Id;
6456 TSD_Aggr_List : List_Id;
6457 Typ_Ifaces : Elist_Id;
6458 TSD_Tags_List : List_Id;
6460 Tname : constant Name_Id := Chars (Typ);
6461 Name_SSD : constant Name_Id :=
6462 New_External_Name (Tname, 'S', Suffix_Index => -1);
6463 Name_TSD : constant Name_Id :=
6464 New_External_Name (Tname, 'B', Suffix_Index => -1);
6465 SSD : constant Entity_Id :=
6466 Make_Defining_Identifier (Loc, Name_SSD);
6467 TSD : constant Entity_Id :=
6468 Make_Defining_Identifier (Loc, Name_TSD);
6470 -- Generate code to create the storage for the type specific data object
6471 -- with enough space to store the tags of the ancestors plus the tags
6472 -- of all the implemented interfaces (as described in a-tags.ads).
6474 -- TSD : Type_Specific_Data (I_Depth) :=
6475 -- (Idepth => I_Depth,
6476 -- Tag_Kind => <tag_kind-value>,
6477 -- Access_Level => Type_Access_Level (Typ),
6478 -- Alignment => Typ'Alignment,
6480 -- Type_Is_Abstract => <<boolean-value>>,
6481 -- Type_Is_Library_Level => <<boolean-value>>,
6482 -- Interfaces_Table => <<access-value>>
6483 -- SSD => SSD_Table'Address
6484 -- Tags_Table => (0 => Typ'Tag,
6488 TSD_Aggr_List := New_List;
6490 -- Idepth: Count ancestors to compute the inheritance depth. For private
6491 -- extensions, always go to the full view in order to compute the real
6492 -- inheritance depth.
6495 Current_Typ : Entity_Id;
6496 Parent_Typ : Entity_Id;
6502 Parent_Typ := Etype (Current_Typ);
6504 if Is_Private_Type (Parent_Typ) then
6505 Parent_Typ := Full_View (Base_Type (Parent_Typ));
6508 exit when Parent_Typ = Current_Typ;
6510 I_Depth := I_Depth + 1;
6511 Current_Typ := Parent_Typ;
6517 Append_To (TSD_Aggr_List,
6518 Make_Integer_Literal (Loc, I_Depth));
6522 Append_To (TSD_Aggr_List, Tagged_Kind (Typ));
6526 Append_To (TSD_Aggr_List,
6527 Make_Integer_Literal (Loc, Type_Access_Level (Typ)));
6531 -- For CPP types we cannot rely on the value of 'Alignment provided
6532 -- by the backend to initialize this TSD field. Why not???
6534 if Convention (Typ) = Convention_CPP
6535 or else Is_CPP_Class (Root_Type (Typ))
6537 Append_To (TSD_Aggr_List,
6538 Make_Integer_Literal (Loc, 0));
6540 Append_To (TSD_Aggr_List,
6541 Make_Attribute_Reference (Loc,
6542 Prefix => New_Reference_To (Typ, Loc),
6543 Attribute_Name => Name_Alignment));
6548 Append_To (TSD_Aggr_List,
6551 -- Type_Is_Abstract (Ada 2012: AI05-0173)
6554 Type_Is_Abstract : Entity_Id;
6558 Boolean_Literals (Is_Abstract_Type (Typ));
6560 Append_To (TSD_Aggr_List,
6561 New_Occurrence_Of (Type_Is_Abstract, Loc));
6564 -- Type_Is_Library_Level
6567 Type_Is_Library_Level : Entity_Id;
6569 Type_Is_Library_Level :=
6570 Boolean_Literals (Is_Library_Level_Entity (Typ));
6571 Append_To (TSD_Aggr_List,
6572 New_Occurrence_Of (Type_Is_Library_Level, Loc));
6575 -- Interfaces_Table (required for AI-405)
6577 if RTE_Record_Component_Available (RE_Interfaces_Table) then
6579 -- Count the number of interface types implemented by Typ
6581 Collect_Interfaces (Typ, Typ_Ifaces);
6584 AI := First_Elmt (Typ_Ifaces);
6585 while Present (AI) loop
6586 Num_Ifaces := Num_Ifaces + 1;
6590 if Num_Ifaces = 0 then
6591 Iface_Table_Node := Make_Null (Loc);
6593 -- Generate the Interface_Table object
6597 TSD_Ifaces_List : constant List_Id := New_List;
6602 AI := First_Elmt (Typ_Ifaces);
6603 while Present (AI) loop
6606 Append_To (TSD_Ifaces_List,
6607 Make_Aggregate (Loc,
6608 Expressions => New_List (
6612 Make_Attribute_Reference (Loc,
6613 Prefix => New_Reference_To (Iface, Loc),
6614 Attribute_Name => Name_Tag),
6618 Make_OSD (Iface))));
6623 ITable := Make_Temporary (Loc, 'I');
6626 Make_Object_Declaration (Loc,
6627 Defining_Identifier => ITable,
6628 Aliased_Present => True,
6629 Constant_Present => True,
6630 Object_Definition =>
6631 Make_Subtype_Indication (Loc,
6633 New_Reference_To (RTE (RE_Interface_Data), Loc),
6634 Constraint => Make_Index_Or_Discriminant_Constraint
6636 Constraints => New_List (
6637 Make_Integer_Literal (Loc, Num_Ifaces)))),
6639 Expression => Make_Aggregate (Loc,
6640 Expressions => New_List (
6641 Make_Integer_Literal (Loc, Num_Ifaces),
6642 Make_Aggregate (Loc,
6643 Expressions => TSD_Ifaces_List)))));
6646 Make_Attribute_Reference (Loc,
6647 Prefix => New_Reference_To (ITable, Loc),
6648 Attribute_Name => Name_Unchecked_Access);
6652 Append_To (TSD_Aggr_List, Iface_Table_Node);
6655 -- Generate the Select Specific Data table for synchronized types that
6656 -- implement synchronized interfaces. The size of the table is
6657 -- constrained by the number of non-predefined primitive operations.
6659 if RTE_Record_Component_Available (RE_SSD) then
6660 if Ada_Version >= Ada_2005
6661 and then Has_DT (Typ)
6662 and then Is_Concurrent_Record_Type (Typ)
6663 and then Has_Interfaces (Typ)
6664 and then Nb_Prim > 0
6665 and then not Is_Abstract_Type (Typ)
6666 and then not Is_Controlled (Typ)
6667 and then not Restriction_Active (No_Dispatching_Calls)
6668 and then not Restriction_Active (No_Select_Statements)
6671 Make_Object_Declaration (Loc,
6672 Defining_Identifier => SSD,
6673 Aliased_Present => True,
6674 Object_Definition =>
6675 Make_Subtype_Indication (Loc,
6676 Subtype_Mark => New_Reference_To (
6677 RTE (RE_Select_Specific_Data), Loc),
6679 Make_Index_Or_Discriminant_Constraint (Loc,
6680 Constraints => New_List (
6681 Make_Integer_Literal (Loc, Nb_Prim))))));
6683 -- This table is initialized by Make_Select_Specific_Data_Table,
6684 -- which calls Set_Entry_Index and Set_Prim_Op_Kind.
6686 Append_To (TSD_Aggr_List,
6687 Make_Attribute_Reference (Loc,
6688 Prefix => New_Reference_To (SSD, Loc),
6689 Attribute_Name => Name_Unchecked_Access));
6691 Append_To (TSD_Aggr_List, Make_Null (Loc));
6695 -- Initialize the table of ancestor tags. In case of interface types
6696 -- this table is not needed.
6698 TSD_Tags_List := New_List;
6700 -- Fill position 0 with Typ'Tag
6702 Append_To (TSD_Tags_List,
6703 Make_Attribute_Reference (Loc,
6704 Prefix => New_Reference_To (Typ, Loc),
6705 Attribute_Name => Name_Tag));
6707 -- Fill the rest of the table with the tags of the ancestors
6710 Current_Typ : Entity_Id;
6711 Parent_Typ : Entity_Id;
6719 Parent_Typ := Etype (Current_Typ);
6721 if Is_Private_Type (Parent_Typ) then
6722 Parent_Typ := Full_View (Base_Type (Parent_Typ));
6725 exit when Parent_Typ = Current_Typ;
6727 Append_To (TSD_Tags_List,
6728 Make_Attribute_Reference (Loc,
6729 Prefix => New_Reference_To (Parent_Typ, Loc),
6730 Attribute_Name => Name_Tag));
6733 Current_Typ := Parent_Typ;
6736 pragma Assert (Pos = I_Depth + 1);
6739 Append_To (TSD_Aggr_List,
6740 Make_Aggregate (Loc,
6741 Expressions => TSD_Tags_List));
6743 -- Build the TSD object
6746 Make_Object_Declaration (Loc,
6747 Defining_Identifier => TSD,
6748 Aliased_Present => True,
6749 Constant_Present => True,
6750 Object_Definition =>
6751 Make_Subtype_Indication (Loc,
6752 Subtype_Mark => New_Reference_To (
6753 RTE (RE_Type_Specific_Data), Loc),
6755 Make_Index_Or_Discriminant_Constraint (Loc,
6756 Constraints => New_List (
6757 Make_Integer_Literal (Loc, I_Depth)))),
6759 Expression => Make_Aggregate (Loc,
6760 Expressions => TSD_Aggr_List)));
6764 -- (TSD => TSD'Unrestricted_Access);
6766 if Ada_Version >= Ada_2005
6767 and then Is_Library_Level_Entity (Typ)
6768 and then Has_External_Tag_Rep_Clause (Typ)
6769 and then RTE_Available (RE_Check_TSD)
6770 and then not Debug_Flag_QQ
6773 Make_Procedure_Call_Statement (Loc,
6774 Name => New_Reference_To (RTE (RE_Check_TSD), Loc),
6775 Parameter_Associations => New_List (
6776 Make_Attribute_Reference (Loc,
6777 Prefix => New_Reference_To (TSD, Loc),
6778 Attribute_Name => Name_Unrestricted_Access))));
6782 -- Register_TSD (TSD'Unrestricted_Access);
6785 Make_Procedure_Call_Statement (Loc,
6786 Name => New_Reference_To (RTE (RE_Register_TSD), Loc),
6787 Parameter_Associations => New_List (
6788 Make_Attribute_Reference (Loc,
6789 Prefix => New_Reference_To (TSD, Loc),
6790 Attribute_Name => Name_Unrestricted_Access))));
6792 -- Populate the two auxiliary tables used for dispatching asynchronous,
6793 -- conditional and timed selects for synchronized types that implement
6794 -- a limited interface. Skip this step in Ravenscar profile or when
6795 -- general dispatching is forbidden.
6797 if Ada_Version >= Ada_2005
6798 and then Is_Concurrent_Record_Type (Typ)
6799 and then Has_Interfaces (Typ)
6800 and then not Restriction_Active (No_Dispatching_Calls)
6801 and then not Restriction_Active (No_Select_Statements)
6803 Append_List_To (Result,
6804 Make_Select_Specific_Data_Table (Typ));
6810 -------------------------------------
6811 -- Make_Select_Specific_Data_Table --
6812 -------------------------------------
6814 function Make_Select_Specific_Data_Table
6815 (Typ : Entity_Id) return List_Id
6817 Assignments : constant List_Id := New_List;
6818 Loc : constant Source_Ptr := Sloc (Typ);
6820 Conc_Typ : Entity_Id;
6823 Prim_Als : Entity_Id;
6824 Prim_Elmt : Elmt_Id;
6828 type Examined_Array is array (Int range <>) of Boolean;
6830 function Find_Entry_Index (E : Entity_Id) return Uint;
6831 -- Given an entry, find its index in the visible declarations of the
6832 -- corresponding concurrent type of Typ.
6834 ----------------------
6835 -- Find_Entry_Index --
6836 ----------------------
6838 function Find_Entry_Index (E : Entity_Id) return Uint is
6839 Index : Uint := Uint_1;
6840 Subp_Decl : Entity_Id;
6844 and then not Is_Empty_List (Decls)
6846 Subp_Decl := First (Decls);
6847 while Present (Subp_Decl) loop
6848 if Nkind (Subp_Decl) = N_Entry_Declaration then
6849 if Defining_Identifier (Subp_Decl) = E then
6861 end Find_Entry_Index;
6867 -- Start of processing for Make_Select_Specific_Data_Table
6870 pragma Assert (not Restriction_Active (No_Dispatching_Calls));
6872 if Present (Corresponding_Concurrent_Type (Typ)) then
6873 Conc_Typ := Corresponding_Concurrent_Type (Typ);
6875 if Present (Full_View (Conc_Typ)) then
6876 Conc_Typ := Full_View (Conc_Typ);
6879 if Ekind (Conc_Typ) = E_Protected_Type then
6880 Decls := Visible_Declarations (Protected_Definition (
6881 Parent (Conc_Typ)));
6883 pragma Assert (Ekind (Conc_Typ) = E_Task_Type);
6884 Decls := Visible_Declarations (Task_Definition (
6885 Parent (Conc_Typ)));
6889 -- Count the non-predefined primitive operations
6891 Prim_Elmt := First_Elmt (Primitive_Operations (Typ));
6892 while Present (Prim_Elmt) loop
6893 Prim := Node (Prim_Elmt);
6895 if not (Is_Predefined_Dispatching_Operation (Prim)
6896 or else Is_Predefined_Dispatching_Alias (Prim))
6898 Nb_Prim := Nb_Prim + 1;
6901 Next_Elmt (Prim_Elmt);
6905 Examined : Examined_Array (1 .. Nb_Prim) := (others => False);
6908 Prim_Elmt := First_Elmt (Primitive_Operations (Typ));
6909 while Present (Prim_Elmt) loop
6910 Prim := Node (Prim_Elmt);
6912 -- Look for primitive overriding an abstract interface subprogram
6914 if Present (Interface_Alias (Prim))
6917 (Find_Dispatching_Type (Interface_Alias (Prim)), Typ,
6918 Use_Full_View => True)
6919 and then not Examined (UI_To_Int (DT_Position (Alias (Prim))))
6921 Prim_Pos := DT_Position (Alias (Prim));
6922 pragma Assert (UI_To_Int (Prim_Pos) <= Nb_Prim);
6923 Examined (UI_To_Int (Prim_Pos)) := True;
6925 -- Set the primitive operation kind regardless of subprogram
6927 -- Ada.Tags.Set_Prim_Op_Kind (DT_Ptr, <position>, <kind>);
6929 if Tagged_Type_Expansion then
6932 (Node (First_Elmt (Access_Disp_Table (Typ))), Loc);
6936 Make_Attribute_Reference (Loc,
6937 Prefix => New_Reference_To (Typ, Loc),
6938 Attribute_Name => Name_Tag);
6941 Append_To (Assignments,
6942 Make_Procedure_Call_Statement (Loc,
6943 Name => New_Reference_To (RTE (RE_Set_Prim_Op_Kind), Loc),
6944 Parameter_Associations => New_List (
6946 Make_Integer_Literal (Loc, Prim_Pos),
6947 Prim_Op_Kind (Alias (Prim), Typ))));
6949 -- Retrieve the root of the alias chain
6951 Prim_Als := Ultimate_Alias (Prim);
6953 -- In the case of an entry wrapper, set the entry index
6955 if Ekind (Prim) = E_Procedure
6956 and then Is_Primitive_Wrapper (Prim_Als)
6957 and then Ekind (Wrapped_Entity (Prim_Als)) = E_Entry
6960 -- Ada.Tags.Set_Entry_Index
6961 -- (DT_Ptr, <position>, <index>);
6963 if Tagged_Type_Expansion then
6966 (Node (First_Elmt (Access_Disp_Table (Typ))), Loc);
6969 Make_Attribute_Reference (Loc,
6970 Prefix => New_Reference_To (Typ, Loc),
6971 Attribute_Name => Name_Tag);
6974 Append_To (Assignments,
6975 Make_Procedure_Call_Statement (Loc,
6977 New_Reference_To (RTE (RE_Set_Entry_Index), Loc),
6978 Parameter_Associations => New_List (
6980 Make_Integer_Literal (Loc, Prim_Pos),
6981 Make_Integer_Literal (Loc,
6982 Find_Entry_Index (Wrapped_Entity (Prim_Als))))));
6986 Next_Elmt (Prim_Elmt);
6991 end Make_Select_Specific_Data_Table;
6997 function Make_Tags (Typ : Entity_Id) return List_Id is
6998 Loc : constant Source_Ptr := Sloc (Typ);
6999 Result : constant List_Id := New_List;
7002 (Tag_Typ : Entity_Id;
7004 Is_Secondary_DT : Boolean);
7005 -- Import the dispatch table DT of tagged type Tag_Typ. Required to
7006 -- generate forward references and statically allocate the table. For
7007 -- primary dispatch tables that require no dispatch table generate:
7009 -- DT : static aliased constant Non_Dispatch_Table_Wrapper;
7010 -- pragma Import (Ada, DT);
7012 -- Otherwise generate:
7014 -- DT : static aliased constant Dispatch_Table_Wrapper (Nb_Prim);
7015 -- pragma Import (Ada, DT);
7022 (Tag_Typ : Entity_Id;
7024 Is_Secondary_DT : Boolean)
7026 DT_Constr_List : List_Id;
7030 Set_Is_Imported (DT);
7031 Set_Ekind (DT, E_Constant);
7032 Set_Related_Type (DT, Typ);
7034 -- The scope must be set now to call Get_External_Name
7036 Set_Scope (DT, Current_Scope);
7038 Get_External_Name (DT, True);
7039 Set_Interface_Name (DT,
7040 Make_String_Literal (Loc, Strval => String_From_Name_Buffer));
7042 -- Ensure proper Sprint output of this implicit importation
7044 Set_Is_Internal (DT);
7046 -- Save this entity to allow Make_DT to generate its exportation
7048 Append_Elmt (DT, Dispatch_Table_Wrappers (Typ));
7050 -- No dispatch table required
7052 if not Is_Secondary_DT and then not Has_DT (Tag_Typ) then
7054 Make_Object_Declaration (Loc,
7055 Defining_Identifier => DT,
7056 Aliased_Present => True,
7057 Constant_Present => True,
7058 Object_Definition =>
7059 New_Reference_To (RTE (RE_No_Dispatch_Table_Wrapper), Loc)));
7062 -- Calculate the number of primitives of the dispatch table and
7063 -- the size of the Type_Specific_Data record.
7066 UI_To_Int (DT_Entry_Count (First_Tag_Component (Tag_Typ)));
7068 -- If the tagged type has no primitives we add a dummy slot whose
7069 -- address will be the tag of this type.
7073 New_List (Make_Integer_Literal (Loc, 1));
7076 New_List (Make_Integer_Literal (Loc, Nb_Prim));
7080 Make_Object_Declaration (Loc,
7081 Defining_Identifier => DT,
7082 Aliased_Present => True,
7083 Constant_Present => True,
7084 Object_Definition =>
7085 Make_Subtype_Indication (Loc,
7087 New_Reference_To (RTE (RE_Dispatch_Table_Wrapper), Loc),
7088 Constraint => Make_Index_Or_Discriminant_Constraint (Loc,
7089 Constraints => DT_Constr_List))));
7095 Tname : constant Name_Id := Chars (Typ);
7096 AI_Tag_Comp : Elmt_Id;
7097 DT : Node_Id := Empty;
7099 Predef_Prims_Ptr : Node_Id;
7100 Iface_DT : Node_Id := Empty;
7101 Iface_DT_Ptr : Node_Id;
7105 Typ_Comps : Elist_Id;
7107 -- Start of processing for Make_Tags
7110 pragma Assert (No (Access_Disp_Table (Typ)));
7111 Set_Access_Disp_Table (Typ, New_Elmt_List);
7113 -- 1) Generate the primary tag entities
7115 -- Primary dispatch table containing user-defined primitives
7117 DT_Ptr := Make_Defining_Identifier (Loc, New_External_Name (Tname, 'P'));
7118 Set_Etype (DT_Ptr, RTE (RE_Tag));
7119 Append_Elmt (DT_Ptr, Access_Disp_Table (Typ));
7121 -- Minimum decoration
7123 Set_Ekind (DT_Ptr, E_Variable);
7124 Set_Related_Type (DT_Ptr, Typ);
7126 -- For CPP types there is no need to build the dispatch tables since
7127 -- they are imported from the C++ side. If the CPP type has an IP then
7128 -- we declare now the variable that will store the copy of the C++ tag.
7129 -- If the CPP type is an interface, we need the variable as well because
7130 -- it becomes the pointer to the corresponding secondary table.
7132 if Is_CPP_Class (Typ) then
7133 if Has_CPP_Constructors (Typ) or else Is_Interface (Typ) then
7135 Make_Object_Declaration (Loc,
7136 Defining_Identifier => DT_Ptr,
7137 Object_Definition => New_Reference_To (RTE (RE_Tag), Loc),
7139 Unchecked_Convert_To (RTE (RE_Tag),
7140 New_Reference_To (RTE (RE_Null_Address), Loc))));
7142 Set_Is_Statically_Allocated (DT_Ptr,
7143 Is_Library_Level_Tagged_Type (Typ));
7149 -- Primary dispatch table containing predefined primitives
7152 Make_Defining_Identifier (Loc,
7153 Chars => New_External_Name (Tname, 'Y'));
7154 Set_Etype (Predef_Prims_Ptr, RTE (RE_Address));
7155 Append_Elmt (Predef_Prims_Ptr, Access_Disp_Table (Typ));
7157 -- Import the forward declaration of the Dispatch Table wrapper
7158 -- record (Make_DT will take care of exporting it).
7160 if Building_Static_DT (Typ) then
7161 Set_Dispatch_Table_Wrappers (Typ, New_Elmt_List);
7164 Make_Defining_Identifier (Loc,
7165 Chars => New_External_Name (Tname, 'T'));
7167 Import_DT (Typ, DT, Is_Secondary_DT => False);
7169 if Has_DT (Typ) then
7171 Make_Object_Declaration (Loc,
7172 Defining_Identifier => DT_Ptr,
7173 Constant_Present => True,
7174 Object_Definition => New_Reference_To (RTE (RE_Tag), Loc),
7176 Unchecked_Convert_To (RTE (RE_Tag),
7177 Make_Attribute_Reference (Loc,
7179 Make_Selected_Component (Loc,
7180 Prefix => New_Reference_To (DT, Loc),
7183 (RTE_Record_Component (RE_Prims_Ptr), Loc)),
7184 Attribute_Name => Name_Address))));
7186 -- Generate the SCIL node for the previous object declaration
7187 -- because it has a tag initialization.
7189 if Generate_SCIL then
7191 Make_SCIL_Dispatch_Table_Tag_Init (Sloc (Last (Result)));
7192 Set_SCIL_Entity (New_Node, Typ);
7193 Set_SCIL_Node (Last (Result), New_Node);
7197 Make_Object_Declaration (Loc,
7198 Defining_Identifier => Predef_Prims_Ptr,
7199 Constant_Present => True,
7200 Object_Definition =>
7201 New_Reference_To (RTE (RE_Address), Loc),
7203 Make_Attribute_Reference (Loc,
7205 Make_Selected_Component (Loc,
7206 Prefix => New_Reference_To (DT, Loc),
7209 (RTE_Record_Component (RE_Predef_Prims), Loc)),
7210 Attribute_Name => Name_Address)));
7212 -- No dispatch table required
7216 Make_Object_Declaration (Loc,
7217 Defining_Identifier => DT_Ptr,
7218 Constant_Present => True,
7219 Object_Definition => New_Reference_To (RTE (RE_Tag), Loc),
7221 Unchecked_Convert_To (RTE (RE_Tag),
7222 Make_Attribute_Reference (Loc,
7224 Make_Selected_Component (Loc,
7225 Prefix => New_Reference_To (DT, Loc),
7228 (RTE_Record_Component (RE_NDT_Prims_Ptr),
7230 Attribute_Name => Name_Address))));
7233 Set_Is_True_Constant (DT_Ptr);
7234 Set_Is_Statically_Allocated (DT_Ptr);
7238 -- 2) Generate the secondary tag entities
7240 -- Collect the components associated with secondary dispatch tables
7242 if Has_Interfaces (Typ) then
7243 Collect_Interface_Components (Typ, Typ_Comps);
7245 -- For each interface type we build a unique external name associated
7246 -- with its secondary dispatch table. This name is used to declare an
7247 -- object that references this secondary dispatch table, whose value
7248 -- will be used for the elaboration of Typ objects, and also for the
7249 -- elaboration of objects of types derived from Typ that do not
7250 -- override the primitives of this interface type.
7254 -- Note: The value of Suffix_Index must be in sync with the
7255 -- Suffix_Index values of secondary dispatch tables generated
7258 if Is_CPP_Class (Typ) then
7259 AI_Tag_Comp := First_Elmt (Typ_Comps);
7260 while Present (AI_Tag_Comp) loop
7261 Get_Secondary_DT_External_Name
7262 (Typ, Related_Type (Node (AI_Tag_Comp)), Suffix_Index);
7263 Typ_Name := Name_Find;
7265 -- Declare variables that will store the copy of the C++
7269 Make_Defining_Identifier (Loc,
7270 Chars => New_External_Name (Typ_Name, 'P'));
7271 Set_Etype (Iface_DT_Ptr, RTE (RE_Interface_Tag));
7272 Set_Ekind (Iface_DT_Ptr, E_Variable);
7273 Set_Is_Tag (Iface_DT_Ptr);
7275 Set_Has_Thunks (Iface_DT_Ptr);
7277 (Iface_DT_Ptr, Related_Type (Node (AI_Tag_Comp)));
7278 Append_Elmt (Iface_DT_Ptr, Access_Disp_Table (Typ));
7281 Make_Object_Declaration (Loc,
7282 Defining_Identifier => Iface_DT_Ptr,
7283 Object_Definition => New_Reference_To
7284 (RTE (RE_Interface_Tag), Loc),
7286 Unchecked_Convert_To (RTE (RE_Interface_Tag),
7287 New_Reference_To (RTE (RE_Null_Address), Loc))));
7289 Set_Is_Statically_Allocated (Iface_DT_Ptr,
7290 Is_Library_Level_Tagged_Type (Typ));
7292 Next_Elmt (AI_Tag_Comp);
7295 -- This is not a CPP_Class type
7298 AI_Tag_Comp := First_Elmt (Typ_Comps);
7299 while Present (AI_Tag_Comp) loop
7300 Get_Secondary_DT_External_Name
7301 (Typ, Related_Type (Node (AI_Tag_Comp)), Suffix_Index);
7302 Typ_Name := Name_Find;
7304 if Building_Static_DT (Typ) then
7306 Make_Defining_Identifier (Loc,
7307 Chars => New_External_Name
7308 (Typ_Name, 'T', Suffix_Index => -1));
7310 (Tag_Typ => Related_Type (Node (AI_Tag_Comp)),
7312 Is_Secondary_DT => True);
7315 -- Secondary dispatch table referencing thunks to user-defined
7316 -- primitives covered by this interface.
7319 Make_Defining_Identifier (Loc,
7320 Chars => New_External_Name (Typ_Name, 'P'));
7321 Set_Etype (Iface_DT_Ptr, RTE (RE_Interface_Tag));
7322 Set_Ekind (Iface_DT_Ptr, E_Constant);
7323 Set_Is_Tag (Iface_DT_Ptr);
7324 Set_Has_Thunks (Iface_DT_Ptr);
7325 Set_Is_Statically_Allocated (Iface_DT_Ptr,
7326 Is_Library_Level_Tagged_Type (Typ));
7327 Set_Is_True_Constant (Iface_DT_Ptr);
7329 (Iface_DT_Ptr, Related_Type (Node (AI_Tag_Comp)));
7330 Append_Elmt (Iface_DT_Ptr, Access_Disp_Table (Typ));
7332 if Building_Static_DT (Typ) then
7334 Make_Object_Declaration (Loc,
7335 Defining_Identifier => Iface_DT_Ptr,
7336 Constant_Present => True,
7337 Object_Definition => New_Reference_To
7338 (RTE (RE_Interface_Tag), Loc),
7340 Unchecked_Convert_To (RTE (RE_Interface_Tag),
7341 Make_Attribute_Reference (Loc,
7343 Make_Selected_Component (Loc,
7345 New_Reference_To (Iface_DT, Loc),
7348 (RTE_Record_Component (RE_Prims_Ptr),
7350 Attribute_Name => Name_Address))));
7353 -- Secondary dispatch table referencing thunks to predefined
7357 Make_Defining_Identifier (Loc,
7358 Chars => New_External_Name (Typ_Name, 'Y'));
7359 Set_Etype (Iface_DT_Ptr, RTE (RE_Address));
7360 Set_Ekind (Iface_DT_Ptr, E_Constant);
7361 Set_Is_Tag (Iface_DT_Ptr);
7362 Set_Has_Thunks (Iface_DT_Ptr);
7363 Set_Is_Statically_Allocated (Iface_DT_Ptr,
7364 Is_Library_Level_Tagged_Type (Typ));
7365 Set_Is_True_Constant (Iface_DT_Ptr);
7367 (Iface_DT_Ptr, Related_Type (Node (AI_Tag_Comp)));
7368 Append_Elmt (Iface_DT_Ptr, Access_Disp_Table (Typ));
7370 -- Secondary dispatch table referencing user-defined primitives
7371 -- covered by this interface.
7374 Make_Defining_Identifier (Loc,
7375 Chars => New_External_Name (Typ_Name, 'D'));
7376 Set_Etype (Iface_DT_Ptr, RTE (RE_Interface_Tag));
7377 Set_Ekind (Iface_DT_Ptr, E_Constant);
7378 Set_Is_Tag (Iface_DT_Ptr);
7379 Set_Is_Statically_Allocated (Iface_DT_Ptr,
7380 Is_Library_Level_Tagged_Type (Typ));
7381 Set_Is_True_Constant (Iface_DT_Ptr);
7383 (Iface_DT_Ptr, Related_Type (Node (AI_Tag_Comp)));
7384 Append_Elmt (Iface_DT_Ptr, Access_Disp_Table (Typ));
7386 -- Secondary dispatch table referencing predefined primitives
7389 Make_Defining_Identifier (Loc,
7390 Chars => New_External_Name (Typ_Name, 'Z'));
7391 Set_Etype (Iface_DT_Ptr, RTE (RE_Address));
7392 Set_Ekind (Iface_DT_Ptr, E_Constant);
7393 Set_Is_Tag (Iface_DT_Ptr);
7394 Set_Is_Statically_Allocated (Iface_DT_Ptr,
7395 Is_Library_Level_Tagged_Type (Typ));
7396 Set_Is_True_Constant (Iface_DT_Ptr);
7398 (Iface_DT_Ptr, Related_Type (Node (AI_Tag_Comp)));
7399 Append_Elmt (Iface_DT_Ptr, Access_Disp_Table (Typ));
7401 Next_Elmt (AI_Tag_Comp);
7406 -- 3) At the end of Access_Disp_Table, if the type has user-defined
7407 -- primitives, we add the entity of an access type declaration that
7408 -- is used by Build_Get_Prim_Op_Address to expand dispatching calls
7409 -- through the primary dispatch table.
7411 if UI_To_Int (DT_Entry_Count (First_Tag_Component (Typ))) = 0 then
7412 Analyze_List (Result);
7415 -- type Typ_DT is array (1 .. Nb_Prims) of Prim_Ptr;
7416 -- type Typ_DT_Acc is access Typ_DT;
7420 Name_DT_Prims : constant Name_Id :=
7421 New_External_Name (Tname, 'G');
7422 Name_DT_Prims_Acc : constant Name_Id :=
7423 New_External_Name (Tname, 'H');
7424 DT_Prims : constant Entity_Id :=
7425 Make_Defining_Identifier (Loc,
7427 DT_Prims_Acc : constant Entity_Id :=
7428 Make_Defining_Identifier (Loc,
7432 Make_Full_Type_Declaration (Loc,
7433 Defining_Identifier => DT_Prims,
7435 Make_Constrained_Array_Definition (Loc,
7436 Discrete_Subtype_Definitions => New_List (
7438 Low_Bound => Make_Integer_Literal (Loc, 1),
7439 High_Bound => Make_Integer_Literal (Loc,
7441 (First_Tag_Component (Typ))))),
7442 Component_Definition =>
7443 Make_Component_Definition (Loc,
7444 Subtype_Indication =>
7445 New_Reference_To (RTE (RE_Prim_Ptr), Loc)))));
7448 Make_Full_Type_Declaration (Loc,
7449 Defining_Identifier => DT_Prims_Acc,
7451 Make_Access_To_Object_Definition (Loc,
7452 Subtype_Indication =>
7453 New_Occurrence_Of (DT_Prims, Loc))));
7455 Append_Elmt (DT_Prims_Acc, Access_Disp_Table (Typ));
7457 -- Analyze the resulting list and suppress the generation of the
7458 -- Init_Proc associated with the above array declaration because
7459 -- this type is never used in object declarations. It is only used
7460 -- to simplify the expansion associated with dispatching calls.
7462 Analyze_List (Result);
7463 Set_Suppress_Initialization (Base_Type (DT_Prims));
7465 -- Disable backend optimizations based on assumptions about the
7466 -- aliasing status of objects designated by the access to the
7467 -- dispatch table. Required to handle dispatch tables imported
7470 Set_No_Strict_Aliasing (Base_Type (DT_Prims_Acc));
7472 -- Add the freezing nodes of these declarations; required to avoid
7473 -- generating these freezing nodes in wrong scopes (for example in
7474 -- the IC routine of a derivation of Typ).
7475 -- What is an "IC routine"? Is "init_proc" meant here???
7477 Append_List_To (Result, Freeze_Entity (DT_Prims, Typ));
7478 Append_List_To (Result, Freeze_Entity (DT_Prims_Acc, Typ));
7480 -- Mark entity of dispatch table. Required by the back end to
7481 -- handle them properly.
7483 Set_Is_Dispatch_Table_Entity (DT_Prims);
7487 -- Mark entities of dispatch table. Required by the back end to handle
7490 if Present (DT) then
7491 Set_Is_Dispatch_Table_Entity (DT);
7492 Set_Is_Dispatch_Table_Entity (Etype (DT));
7495 if Present (Iface_DT) then
7496 Set_Is_Dispatch_Table_Entity (Iface_DT);
7497 Set_Is_Dispatch_Table_Entity (Etype (Iface_DT));
7500 if Is_CPP_Class (Root_Type (Typ)) then
7501 Set_Ekind (DT_Ptr, E_Variable);
7503 Set_Ekind (DT_Ptr, E_Constant);
7506 Set_Is_Tag (DT_Ptr);
7507 Set_Related_Type (DT_Ptr, Typ);
7516 function New_Value (From : Node_Id) return Node_Id is
7517 Res : constant Node_Id := Duplicate_Subexpr (From);
7519 if Is_Access_Type (Etype (From)) then
7521 Make_Explicit_Dereference (Sloc (From),
7528 -----------------------------------
7529 -- Original_View_In_Visible_Part --
7530 -----------------------------------
7532 function Original_View_In_Visible_Part (Typ : Entity_Id) return Boolean is
7533 Scop : constant Entity_Id := Scope (Typ);
7536 -- The scope must be a package
7538 if not Is_Package_Or_Generic_Package (Scop) then
7542 -- A type with a private declaration has a private view declared in
7543 -- the visible part.
7545 if Has_Private_Declaration (Typ) then
7549 return List_Containing (Parent (Typ)) =
7550 Visible_Declarations (Specification (Unit_Declaration_Node (Scop)));
7551 end Original_View_In_Visible_Part;
7557 function Prim_Op_Kind
7559 Typ : Entity_Id) return Node_Id
7561 Full_Typ : Entity_Id := Typ;
7562 Loc : constant Source_Ptr := Sloc (Prim);
7563 Prim_Op : Entity_Id;
7566 -- Retrieve the original primitive operation
7568 Prim_Op := Ultimate_Alias (Prim);
7570 if Ekind (Typ) = E_Record_Type
7571 and then Present (Corresponding_Concurrent_Type (Typ))
7573 Full_Typ := Corresponding_Concurrent_Type (Typ);
7576 -- When a private tagged type is completed by a concurrent type,
7577 -- retrieve the full view.
7579 if Is_Private_Type (Full_Typ) then
7580 Full_Typ := Full_View (Full_Typ);
7583 if Ekind (Prim_Op) = E_Function then
7585 -- Protected function
7587 if Ekind (Full_Typ) = E_Protected_Type then
7588 return New_Reference_To (RTE (RE_POK_Protected_Function), Loc);
7592 elsif Ekind (Full_Typ) = E_Task_Type then
7593 return New_Reference_To (RTE (RE_POK_Task_Function), Loc);
7598 return New_Reference_To (RTE (RE_POK_Function), Loc);
7602 pragma Assert (Ekind (Prim_Op) = E_Procedure);
7604 if Ekind (Full_Typ) = E_Protected_Type then
7608 if Is_Primitive_Wrapper (Prim_Op)
7609 and then Ekind (Wrapped_Entity (Prim_Op)) = E_Entry
7611 return New_Reference_To (RTE (RE_POK_Protected_Entry), Loc);
7613 -- Protected procedure
7616 return New_Reference_To (RTE (RE_POK_Protected_Procedure), Loc);
7619 elsif Ekind (Full_Typ) = E_Task_Type then
7623 if Is_Primitive_Wrapper (Prim_Op)
7624 and then Ekind (Wrapped_Entity (Prim_Op)) = E_Entry
7626 return New_Reference_To (RTE (RE_POK_Task_Entry), Loc);
7628 -- Task "procedure". These are the internally Expander-generated
7629 -- procedures (task body for instance).
7632 return New_Reference_To (RTE (RE_POK_Task_Procedure), Loc);
7635 -- Regular procedure
7638 return New_Reference_To (RTE (RE_POK_Procedure), Loc);
7643 ------------------------
7644 -- Register_Primitive --
7645 ------------------------
7647 function Register_Primitive
7649 Prim : Entity_Id) return List_Id
7652 Iface_Prim : Entity_Id;
7653 Iface_Typ : Entity_Id;
7654 Iface_DT_Ptr : Entity_Id;
7655 Iface_DT_Elmt : Elmt_Id;
7656 L : constant List_Id := New_List;
7659 Tag_Typ : Entity_Id;
7660 Thunk_Id : Entity_Id;
7661 Thunk_Code : Node_Id;
7664 pragma Assert (not Restriction_Active (No_Dispatching_Calls));
7665 pragma Assert (VM_Target = No_VM);
7667 -- Do not register in the dispatch table eliminated primitives
7669 if not RTE_Available (RE_Tag)
7670 or else Is_Eliminated (Ultimate_Alias (Prim))
7675 if not Present (Interface_Alias (Prim)) then
7676 Tag_Typ := Scope (DTC_Entity (Prim));
7677 Pos := DT_Position (Prim);
7678 Tag := First_Tag_Component (Tag_Typ);
7680 if Is_Predefined_Dispatching_Operation (Prim)
7681 or else Is_Predefined_Dispatching_Alias (Prim)
7684 Node (Next_Elmt (First_Elmt (Access_Disp_Table (Tag_Typ))));
7687 Build_Set_Predefined_Prim_Op_Address (Loc,
7688 Tag_Node => New_Reference_To (DT_Ptr, Loc),
7691 Unchecked_Convert_To (RTE (RE_Prim_Ptr),
7692 Make_Attribute_Reference (Loc,
7693 Prefix => New_Reference_To (Prim, Loc),
7694 Attribute_Name => Name_Unrestricted_Access))));
7696 -- Register copy of the pointer to the 'size primitive in the TSD
7698 if Chars (Prim) = Name_uSize
7699 and then RTE_Record_Component_Available (RE_Size_Func)
7701 DT_Ptr := Node (First_Elmt (Access_Disp_Table (Tag_Typ)));
7703 Build_Set_Size_Function (Loc,
7704 Tag_Node => New_Reference_To (DT_Ptr, Loc),
7705 Size_Func => Prim));
7709 pragma Assert (Pos /= Uint_0 and then Pos <= DT_Entry_Count (Tag));
7711 -- Skip registration of primitives located in the C++ part of the
7712 -- dispatch table. Their slot is set by the IC routine.
7714 if not Is_CPP_Class (Root_Type (Tag_Typ))
7715 or else Pos > CPP_Num_Prims (Tag_Typ)
7717 DT_Ptr := Node (First_Elmt (Access_Disp_Table (Tag_Typ)));
7719 Build_Set_Prim_Op_Address (Loc,
7721 Tag_Node => New_Reference_To (DT_Ptr, Loc),
7724 Unchecked_Convert_To (RTE (RE_Prim_Ptr),
7725 Make_Attribute_Reference (Loc,
7726 Prefix => New_Reference_To (Prim, Loc),
7727 Attribute_Name => Name_Unrestricted_Access))));
7731 -- Ada 2005 (AI-251): Primitive associated with an interface type
7732 -- Generate the code of the thunk only if the interface type is not an
7733 -- immediate ancestor of Typ; otherwise the dispatch table associated
7734 -- with the interface is the primary dispatch table and we have nothing
7738 Tag_Typ := Find_Dispatching_Type (Alias (Prim));
7739 Iface_Typ := Find_Dispatching_Type (Interface_Alias (Prim));
7741 pragma Assert (Is_Interface (Iface_Typ));
7743 -- No action needed for interfaces that are ancestors of Typ because
7744 -- their primitives are located in the primary dispatch table.
7746 if Is_Ancestor (Iface_Typ, Tag_Typ, Use_Full_View => True) then
7749 -- No action needed for primitives located in the C++ part of the
7750 -- dispatch table. Their slot is set by the IC routine.
7752 elsif Is_CPP_Class (Root_Type (Tag_Typ))
7753 and then DT_Position (Alias (Prim)) <= CPP_Num_Prims (Tag_Typ)
7754 and then not Is_Predefined_Dispatching_Operation (Prim)
7755 and then not Is_Predefined_Dispatching_Alias (Prim)
7760 Expand_Interface_Thunk (Prim, Thunk_Id, Thunk_Code);
7762 if not Is_Ancestor (Iface_Typ, Tag_Typ, Use_Full_View => True)
7763 and then Present (Thunk_Code)
7765 -- Generate the code necessary to fill the appropriate entry of
7766 -- the secondary dispatch table of Prim's controlling type with
7767 -- Thunk_Id's address.
7769 Iface_DT_Elmt := Find_Interface_ADT (Tag_Typ, Iface_Typ);
7770 Iface_DT_Ptr := Node (Iface_DT_Elmt);
7771 pragma Assert (Has_Thunks (Iface_DT_Ptr));
7773 Iface_Prim := Interface_Alias (Prim);
7774 Pos := DT_Position (Iface_Prim);
7775 Tag := First_Tag_Component (Iface_Typ);
7777 Prepend_To (L, Thunk_Code);
7779 if Is_Predefined_Dispatching_Operation (Prim)
7780 or else Is_Predefined_Dispatching_Alias (Prim)
7783 Build_Set_Predefined_Prim_Op_Address (Loc,
7785 New_Reference_To (Node (Next_Elmt (Iface_DT_Elmt)), Loc),
7788 Unchecked_Convert_To (RTE (RE_Prim_Ptr),
7789 Make_Attribute_Reference (Loc,
7790 Prefix => New_Reference_To (Thunk_Id, Loc),
7791 Attribute_Name => Name_Unrestricted_Access))));
7793 Next_Elmt (Iface_DT_Elmt);
7794 Next_Elmt (Iface_DT_Elmt);
7795 Iface_DT_Ptr := Node (Iface_DT_Elmt);
7796 pragma Assert (not Has_Thunks (Iface_DT_Ptr));
7799 Build_Set_Predefined_Prim_Op_Address (Loc,
7801 New_Reference_To (Node (Next_Elmt (Iface_DT_Elmt)), Loc),
7804 Unchecked_Convert_To (RTE (RE_Prim_Ptr),
7805 Make_Attribute_Reference (Loc,
7807 New_Reference_To (Alias (Prim), Loc),
7808 Attribute_Name => Name_Unrestricted_Access))));
7811 pragma Assert (Pos /= Uint_0
7812 and then Pos <= DT_Entry_Count (Tag));
7815 Build_Set_Prim_Op_Address (Loc,
7817 Tag_Node => New_Reference_To (Iface_DT_Ptr, Loc),
7820 Unchecked_Convert_To (RTE (RE_Prim_Ptr),
7821 Make_Attribute_Reference (Loc,
7822 Prefix => New_Reference_To (Thunk_Id, Loc),
7823 Attribute_Name => Name_Unrestricted_Access))));
7825 Next_Elmt (Iface_DT_Elmt);
7826 Next_Elmt (Iface_DT_Elmt);
7827 Iface_DT_Ptr := Node (Iface_DT_Elmt);
7828 pragma Assert (not Has_Thunks (Iface_DT_Ptr));
7831 Build_Set_Prim_Op_Address (Loc,
7833 Tag_Node => New_Reference_To (Iface_DT_Ptr, Loc),
7836 Unchecked_Convert_To (RTE (RE_Prim_Ptr),
7837 Make_Attribute_Reference (Loc,
7839 New_Reference_To (Alias (Prim), Loc),
7840 Attribute_Name => Name_Unrestricted_Access))));
7847 end Register_Primitive;
7849 -------------------------
7850 -- Set_All_DT_Position --
7851 -------------------------
7853 procedure Set_All_DT_Position (Typ : Entity_Id) is
7855 function In_Predef_Prims_DT (Prim : Entity_Id) return Boolean;
7856 -- Returns True if Prim is located in the dispatch table of
7857 -- predefined primitives
7859 procedure Validate_Position (Prim : Entity_Id);
7860 -- Check that the position assigned to Prim is completely safe
7861 -- (it has not been assigned to a previously defined primitive
7862 -- operation of Typ)
7864 ------------------------
7865 -- In_Predef_Prims_DT --
7866 ------------------------
7868 function In_Predef_Prims_DT (Prim : Entity_Id) return Boolean is
7872 -- Predefined primitives
7874 if Is_Predefined_Dispatching_Operation (Prim) then
7877 -- Renamings of predefined primitives
7879 elsif Present (Alias (Prim))
7880 and then Is_Predefined_Dispatching_Operation (Ultimate_Alias (Prim))
7882 if Chars (Ultimate_Alias (Prim)) /= Name_Op_Eq then
7885 -- User-defined renamings of predefined equality have their own
7886 -- slot in the primary dispatch table
7890 while Present (Alias (E)) loop
7891 if Comes_From_Source (E) then
7898 return not Comes_From_Source (E);
7901 -- User-defined primitives
7906 end In_Predef_Prims_DT;
7908 -----------------------
7909 -- Validate_Position --
7910 -----------------------
7912 procedure Validate_Position (Prim : Entity_Id) is
7917 -- Aliased primitives are safe
7919 if Present (Alias (Prim)) then
7923 Op_Elmt := First_Elmt (Primitive_Operations (Typ));
7924 while Present (Op_Elmt) loop
7925 Op := Node (Op_Elmt);
7927 -- No need to check against itself
7932 -- Primitive operations covering abstract interfaces are
7935 elsif Present (Interface_Alias (Op)) then
7938 -- Predefined dispatching operations are completely safe. They
7939 -- are allocated at fixed positions in a separate table.
7941 elsif Is_Predefined_Dispatching_Operation (Op)
7942 or else Is_Predefined_Dispatching_Alias (Op)
7946 -- Aliased subprograms are safe
7948 elsif Present (Alias (Op)) then
7951 elsif DT_Position (Op) = DT_Position (Prim)
7952 and then not Is_Predefined_Dispatching_Operation (Op)
7953 and then not Is_Predefined_Dispatching_Operation (Prim)
7954 and then not Is_Predefined_Dispatching_Alias (Op)
7955 and then not Is_Predefined_Dispatching_Alias (Prim)
7958 -- Handle aliased subprograms
7967 if Present (Overridden_Operation (Op_1)) then
7968 Op_1 := Overridden_Operation (Op_1);
7969 elsif Present (Alias (Op_1)) then
7970 Op_1 := Alias (Op_1);
7978 if Present (Overridden_Operation (Op_2)) then
7979 Op_2 := Overridden_Operation (Op_2);
7980 elsif Present (Alias (Op_2)) then
7981 Op_2 := Alias (Op_2);
7987 if Op_1 /= Op_2 then
7988 raise Program_Error;
7993 Next_Elmt (Op_Elmt);
7995 end Validate_Position;
7999 Parent_Typ : constant Entity_Id := Etype (Typ);
8000 First_Prim : constant Elmt_Id := First_Elmt (Primitive_Operations (Typ));
8001 The_Tag : constant Entity_Id := First_Tag_Component (Typ);
8003 Adjusted : Boolean := False;
8004 Finalized : Boolean := False;
8010 Prim_Elmt : Elmt_Id;
8012 -- Start of processing for Set_All_DT_Position
8015 pragma Assert (Present (First_Tag_Component (Typ)));
8017 -- Set the DT_Position for each primitive operation. Perform some sanity
8018 -- checks to avoid building inconsistent dispatch tables.
8020 -- First stage: Set the DTC entity of all the primitive operations. This
8021 -- is required to properly read the DT_Position attribute in the latter
8024 Prim_Elmt := First_Prim;
8026 while Present (Prim_Elmt) loop
8027 Prim := Node (Prim_Elmt);
8029 -- Predefined primitives have a separate dispatch table
8031 if not In_Predef_Prims_DT (Prim) then
8032 Count_Prim := Count_Prim + 1;
8035 Set_DTC_Entity_Value (Typ, Prim);
8037 -- Clear any previous value of the DT_Position attribute. In this
8038 -- way we ensure that the final position of all the primitives is
8039 -- established by the following stages of this algorithm.
8041 Set_DT_Position (Prim, No_Uint);
8043 Next_Elmt (Prim_Elmt);
8047 Fixed_Prim : array (Int range 0 .. Count_Prim) of Boolean :=
8052 procedure Handle_Inherited_Private_Subprograms (Typ : Entity_Id);
8053 -- Called if Typ is declared in a nested package or a public child
8054 -- package to handle inherited primitives that were inherited by Typ
8055 -- in the visible part, but whose declaration was deferred because
8056 -- the parent operation was private and not visible at that point.
8058 procedure Set_Fixed_Prim (Pos : Nat);
8059 -- Sets to true an element of the Fixed_Prim table to indicate
8060 -- that this entry of the dispatch table of Typ is occupied.
8062 ------------------------------------------
8063 -- Handle_Inherited_Private_Subprograms --
8064 ------------------------------------------
8066 procedure Handle_Inherited_Private_Subprograms (Typ : Entity_Id) is
8069 Op_Elmt_2 : Elmt_Id;
8070 Prim_Op : Entity_Id;
8071 Parent_Subp : Entity_Id;
8074 Op_List := Primitive_Operations (Typ);
8076 Op_Elmt := First_Elmt (Op_List);
8077 while Present (Op_Elmt) loop
8078 Prim_Op := Node (Op_Elmt);
8080 -- Search primitives that are implicit operations with an
8081 -- internal name whose parent operation has a normal name.
8083 if Present (Alias (Prim_Op))
8084 and then Find_Dispatching_Type (Alias (Prim_Op)) /= Typ
8085 and then not Comes_From_Source (Prim_Op)
8086 and then Is_Internal_Name (Chars (Prim_Op))
8087 and then not Is_Internal_Name (Chars (Alias (Prim_Op)))
8089 Parent_Subp := Alias (Prim_Op);
8091 -- Check if the type has an explicit overriding for this
8094 Op_Elmt_2 := Next_Elmt (Op_Elmt);
8095 while Present (Op_Elmt_2) loop
8096 if Chars (Node (Op_Elmt_2)) = Chars (Parent_Subp)
8097 and then Type_Conformant (Prim_Op, Node (Op_Elmt_2))
8099 Set_DT_Position (Prim_Op, DT_Position (Parent_Subp));
8100 Set_DT_Position (Node (Op_Elmt_2),
8101 DT_Position (Parent_Subp));
8102 Set_Fixed_Prim (UI_To_Int (DT_Position (Prim_Op)));
8104 goto Next_Primitive;
8107 Next_Elmt (Op_Elmt_2);
8112 Next_Elmt (Op_Elmt);
8114 end Handle_Inherited_Private_Subprograms;
8116 --------------------
8117 -- Set_Fixed_Prim --
8118 --------------------
8120 procedure Set_Fixed_Prim (Pos : Nat) is
8122 pragma Assert (Pos <= Count_Prim);
8123 Fixed_Prim (Pos) := True;
8125 when Constraint_Error =>
8126 raise Program_Error;
8130 -- In case of nested packages and public child package it may be
8131 -- necessary a special management on inherited subprograms so that
8132 -- the dispatch table is properly filled.
8134 if Ekind (Scope (Scope (Typ))) = E_Package
8135 and then Scope (Scope (Typ)) /= Standard_Standard
8136 and then ((Is_Derived_Type (Typ) and then not Is_Private_Type (Typ))
8138 (Nkind (Parent (Typ)) = N_Private_Extension_Declaration
8139 and then Is_Generic_Type (Typ)))
8140 and then In_Open_Scopes (Scope (Etype (Typ)))
8141 and then Is_Base_Type (Typ)
8143 Handle_Inherited_Private_Subprograms (Typ);
8146 -- Second stage: Register fixed entries
8149 Prim_Elmt := First_Prim;
8150 while Present (Prim_Elmt) loop
8151 Prim := Node (Prim_Elmt);
8153 -- Predefined primitives have a separate table and all its
8154 -- entries are at predefined fixed positions.
8156 if In_Predef_Prims_DT (Prim) then
8157 if Is_Predefined_Dispatching_Operation (Prim) then
8158 Set_DT_Position (Prim, Default_Prim_Op_Position (Prim));
8160 else pragma Assert (Present (Alias (Prim)));
8161 Set_DT_Position (Prim,
8162 Default_Prim_Op_Position (Ultimate_Alias (Prim)));
8165 -- Overriding primitives of ancestor abstract interfaces
8167 elsif Present (Interface_Alias (Prim))
8168 and then Is_Ancestor
8169 (Find_Dispatching_Type (Interface_Alias (Prim)), Typ,
8170 Use_Full_View => True)
8172 pragma Assert (DT_Position (Prim) = No_Uint
8173 and then Present (DTC_Entity (Interface_Alias (Prim))));
8175 E := Interface_Alias (Prim);
8176 Set_DT_Position (Prim, DT_Position (E));
8179 (DT_Position (Alias (Prim)) = No_Uint
8180 or else DT_Position (Alias (Prim)) = DT_Position (E));
8181 Set_DT_Position (Alias (Prim), DT_Position (E));
8182 Set_Fixed_Prim (UI_To_Int (DT_Position (Prim)));
8184 -- Overriding primitives must use the same entry as the
8185 -- overridden primitive.
8187 elsif not Present (Interface_Alias (Prim))
8188 and then Present (Alias (Prim))
8189 and then Chars (Prim) = Chars (Alias (Prim))
8190 and then Find_Dispatching_Type (Alias (Prim)) /= Typ
8191 and then Is_Ancestor
8192 (Find_Dispatching_Type (Alias (Prim)), Typ,
8193 Use_Full_View => True)
8194 and then Present (DTC_Entity (Alias (Prim)))
8197 Set_DT_Position (Prim, DT_Position (E));
8199 if not Is_Predefined_Dispatching_Alias (E) then
8200 Set_Fixed_Prim (UI_To_Int (DT_Position (E)));
8204 Next_Elmt (Prim_Elmt);
8207 -- Third stage: Fix the position of all the new primitives.
8208 -- Entries associated with primitives covering interfaces
8209 -- are handled in a latter round.
8211 Prim_Elmt := First_Prim;
8212 while Present (Prim_Elmt) loop
8213 Prim := Node (Prim_Elmt);
8215 -- Skip primitives previously set entries
8217 if DT_Position (Prim) /= No_Uint then
8220 -- Primitives covering interface primitives are handled later
8222 elsif Present (Interface_Alias (Prim)) then
8226 -- Take the next available position in the DT
8229 Nb_Prim := Nb_Prim + 1;
8230 pragma Assert (Nb_Prim <= Count_Prim);
8231 exit when not Fixed_Prim (Nb_Prim);
8234 Set_DT_Position (Prim, UI_From_Int (Nb_Prim));
8235 Set_Fixed_Prim (Nb_Prim);
8238 Next_Elmt (Prim_Elmt);
8242 -- Fourth stage: Complete the decoration of primitives covering
8243 -- interfaces (that is, propagate the DT_Position attribute
8244 -- from the aliased primitive)
8246 Prim_Elmt := First_Prim;
8247 while Present (Prim_Elmt) loop
8248 Prim := Node (Prim_Elmt);
8250 if DT_Position (Prim) = No_Uint
8251 and then Present (Interface_Alias (Prim))
8253 pragma Assert (Present (Alias (Prim))
8254 and then Find_Dispatching_Type (Alias (Prim)) = Typ);
8256 -- Check if this entry will be placed in the primary DT
8259 (Find_Dispatching_Type (Interface_Alias (Prim)), Typ,
8260 Use_Full_View => True)
8262 pragma Assert (DT_Position (Alias (Prim)) /= No_Uint);
8263 Set_DT_Position (Prim, DT_Position (Alias (Prim)));
8265 -- Otherwise it will be placed in the secondary DT
8269 (DT_Position (Interface_Alias (Prim)) /= No_Uint);
8270 Set_DT_Position (Prim,
8271 DT_Position (Interface_Alias (Prim)));
8275 Next_Elmt (Prim_Elmt);
8278 -- Generate listing showing the contents of the dispatch tables.
8279 -- This action is done before some further static checks because
8280 -- in case of critical errors caused by a wrong dispatch table
8281 -- we need to see the contents of such table.
8283 if Debug_Flag_ZZ then
8287 -- Final stage: Ensure that the table is correct plus some further
8288 -- verifications concerning the primitives.
8290 Prim_Elmt := First_Prim;
8292 while Present (Prim_Elmt) loop
8293 Prim := Node (Prim_Elmt);
8295 -- At this point all the primitives MUST have a position
8296 -- in the dispatch table.
8298 if DT_Position (Prim) = No_Uint then
8299 raise Program_Error;
8302 -- Calculate real size of the dispatch table
8304 if not In_Predef_Prims_DT (Prim)
8305 and then UI_To_Int (DT_Position (Prim)) > DT_Length
8307 DT_Length := UI_To_Int (DT_Position (Prim));
8310 -- Ensure that the assigned position to non-predefined
8311 -- dispatching operations in the dispatch table is correct.
8313 if not Is_Predefined_Dispatching_Operation (Prim)
8314 and then not Is_Predefined_Dispatching_Alias (Prim)
8316 Validate_Position (Prim);
8319 if Chars (Prim) = Name_Finalize then
8323 if Chars (Prim) = Name_Adjust then
8327 -- An abstract operation cannot be declared in the private part for a
8328 -- visible abstract type, because it can't be overridden outside this
8329 -- package hierarchy. For explicit declarations this is checked at
8330 -- the point of declaration, but for inherited operations it must be
8331 -- done when building the dispatch table.
8333 -- Ada 2005 (AI-251): Primitives associated with interfaces are
8334 -- excluded from this check because interfaces must be visible in
8335 -- the public and private part (RM 7.3 (7.3/2))
8337 -- We disable this check in CodePeer mode, to accommodate legacy
8340 if not CodePeer_Mode
8341 and then Is_Abstract_Type (Typ)
8342 and then Is_Abstract_Subprogram (Prim)
8343 and then Present (Alias (Prim))
8344 and then not Is_Interface
8345 (Find_Dispatching_Type (Ultimate_Alias (Prim)))
8346 and then not Present (Interface_Alias (Prim))
8347 and then Is_Derived_Type (Typ)
8348 and then In_Private_Part (Current_Scope)
8350 List_Containing (Parent (Prim)) =
8351 Private_Declarations
8352 (Specification (Unit_Declaration_Node (Current_Scope)))
8353 and then Original_View_In_Visible_Part (Typ)
8355 -- We exclude Input and Output stream operations because
8356 -- Limited_Controlled inherits useless Input and Output
8357 -- stream operations from Root_Controlled, which can
8358 -- never be overridden.
8360 if not Is_TSS (Prim, TSS_Stream_Input)
8362 not Is_TSS (Prim, TSS_Stream_Output)
8365 ("abstract inherited private operation&" &
8366 " must be overridden (RM 3.9.3(10))",
8367 Parent (Typ), Prim);
8371 Next_Elmt (Prim_Elmt);
8376 if Is_Controlled (Typ) then
8377 if not Finalized then
8379 ("controlled type has no explicit Finalize method?", Typ);
8381 elsif not Adjusted then
8383 ("controlled type has no explicit Adjust method?", Typ);
8387 -- Set the final size of the Dispatch Table
8389 Set_DT_Entry_Count (The_Tag, UI_From_Int (DT_Length));
8391 -- The derived type must have at least as many components as its parent
8392 -- (for root types Etype points to itself and the test cannot fail).
8394 if DT_Entry_Count (The_Tag) <
8395 DT_Entry_Count (First_Tag_Component (Parent_Typ))
8397 raise Program_Error;
8399 end Set_All_DT_Position;
8401 --------------------------
8402 -- Set_CPP_Constructors --
8403 --------------------------
8405 procedure Set_CPP_Constructors (Typ : Entity_Id) is
8407 procedure Set_CPP_Constructors_Old (Typ : Entity_Id);
8408 -- For backward compatibility this routine handles CPP constructors
8409 -- of non-tagged types.
8411 procedure Set_CPP_Constructors_Old (Typ : Entity_Id) is
8415 Found : Boolean := False;
8420 -- Look for the constructor entities
8422 E := Next_Entity (Typ);
8423 while Present (E) loop
8424 if Ekind (E) = E_Function
8425 and then Is_Constructor (E)
8427 -- Create the init procedure
8431 Init := Make_Defining_Identifier (Loc,
8432 Make_Init_Proc_Name (Typ));
8435 Make_Parameter_Specification (Loc,
8436 Defining_Identifier =>
8437 Make_Defining_Identifier (Loc, Name_X),
8439 New_Reference_To (Typ, Loc)));
8441 if Present (Parameter_Specifications (Parent (E))) then
8442 P := First (Parameter_Specifications (Parent (E)));
8443 while Present (P) loop
8445 Make_Parameter_Specification (Loc,
8446 Defining_Identifier =>
8447 Make_Defining_Identifier (Loc,
8448 Chars (Defining_Identifier (P))),
8450 New_Copy_Tree (Parameter_Type (P))));
8456 Make_Subprogram_Declaration (Loc,
8457 Make_Procedure_Specification (Loc,
8458 Defining_Unit_Name => Init,
8459 Parameter_Specifications => Parms)));
8461 Set_Init_Proc (Typ, Init);
8462 Set_Is_Imported (Init);
8463 Set_Interface_Name (Init, Interface_Name (E));
8464 Set_Convention (Init, Convention_C);
8465 Set_Is_Public (Init);
8466 Set_Has_Completion (Init);
8472 -- If there are no constructors, mark the type as abstract since we
8473 -- won't be able to declare objects of that type.
8476 Set_Is_Abstract_Type (Typ);
8478 end Set_CPP_Constructors_Old;
8484 Found : Boolean := False;
8488 Constructor_Decl_Node : Node_Id;
8489 Constructor_Id : Entity_Id;
8490 Wrapper_Id : Entity_Id;
8491 Wrapper_Body_Node : Node_Id;
8493 Body_Stmts : List_Id;
8494 Init_Tags_List : List_Id;
8497 pragma Assert (Is_CPP_Class (Typ));
8499 -- For backward compatibility the compiler accepts C++ classes
8500 -- imported through non-tagged record types. In such case the
8501 -- wrapper of the C++ constructor is useless because the _tag
8502 -- component is not available.
8505 -- type Root is limited record ...
8506 -- pragma Import (CPP, Root);
8507 -- function New_Root return Root;
8508 -- pragma CPP_Constructor (New_Root, ... );
8510 if not Is_Tagged_Type (Typ) then
8511 Set_CPP_Constructors_Old (Typ);
8515 -- Look for the constructor entities
8517 E := Next_Entity (Typ);
8518 while Present (E) loop
8519 if Ekind (E) = E_Function
8520 and then Is_Constructor (E)
8525 -- Generate the declaration of the imported C++ constructor
8529 Make_Parameter_Specification (Loc,
8530 Defining_Identifier =>
8531 Make_Defining_Identifier (Loc, Name_uInit),
8533 New_Reference_To (Typ, Loc)));
8535 if Present (Parameter_Specifications (Parent (E))) then
8536 P := First (Parameter_Specifications (Parent (E)));
8537 while Present (P) loop
8539 Make_Parameter_Specification (Loc,
8540 Defining_Identifier =>
8541 Make_Defining_Identifier (Loc,
8542 Chars (Defining_Identifier (P))),
8543 Parameter_Type => New_Copy_Tree (Parameter_Type (P))));
8548 Constructor_Id := Make_Temporary (Loc, 'P');
8550 Constructor_Decl_Node :=
8551 Make_Subprogram_Declaration (Loc,
8552 Make_Procedure_Specification (Loc,
8553 Defining_Unit_Name => Constructor_Id,
8554 Parameter_Specifications => Parms));
8556 Set_Is_Imported (Constructor_Id);
8557 Set_Interface_Name (Constructor_Id, Interface_Name (E));
8558 Set_Convention (Constructor_Id, Convention_C);
8559 Set_Is_Public (Constructor_Id);
8560 Set_Has_Completion (Constructor_Id);
8562 -- Build the wrapper of this constructor
8566 Make_Parameter_Specification (Loc,
8567 Defining_Identifier =>
8568 Make_Defining_Identifier (Loc, Name_uInit),
8570 New_Reference_To (Typ, Loc)));
8572 if Present (Parameter_Specifications (Parent (E))) then
8573 P := First (Parameter_Specifications (Parent (E)));
8574 while Present (P) loop
8576 Make_Parameter_Specification (Loc,
8577 Defining_Identifier =>
8578 Make_Defining_Identifier (Loc,
8579 Chars (Defining_Identifier (P))),
8580 Parameter_Type => New_Copy_Tree (Parameter_Type (P))));
8585 Body_Stmts := New_List;
8587 -- Invoke the C++ constructor
8589 Actuals := New_List;
8592 while Present (P) loop
8594 New_Reference_To (Defining_Identifier (P), Loc));
8598 Append_To (Body_Stmts,
8599 Make_Procedure_Call_Statement (Loc,
8600 Name => New_Reference_To (Constructor_Id, Loc),
8601 Parameter_Associations => Actuals));
8603 -- Initialize copies of C++ primary and secondary tags
8605 Init_Tags_List := New_List;
8612 Tag_Elmt := First_Elmt (Access_Disp_Table (Typ));
8613 Tag_Comp := First_Tag_Component (Typ);
8615 while Present (Tag_Elmt)
8616 and then Is_Tag (Node (Tag_Elmt))
8618 -- Skip the following assertion with primary tags because
8619 -- Related_Type is not set on primary tag components
8621 pragma Assert (Tag_Comp = First_Tag_Component (Typ)
8622 or else Related_Type (Node (Tag_Elmt))
8623 = Related_Type (Tag_Comp));
8625 Append_To (Init_Tags_List,
8626 Make_Assignment_Statement (Loc,
8628 New_Reference_To (Node (Tag_Elmt), Loc),
8630 Make_Selected_Component (Loc,
8632 Make_Identifier (Loc, Name_uInit),
8634 New_Reference_To (Tag_Comp, Loc))));
8636 Tag_Comp := Next_Tag_Component (Tag_Comp);
8637 Next_Elmt (Tag_Elmt);
8641 Append_To (Body_Stmts,
8642 Make_If_Statement (Loc,
8647 (Node (First_Elmt (Access_Disp_Table (Typ))),
8650 Unchecked_Convert_To (RTE (RE_Tag),
8651 New_Reference_To (RTE (RE_Null_Address), Loc))),
8652 Then_Statements => Init_Tags_List));
8654 Wrapper_Id := Make_Defining_Identifier (Loc,
8655 Make_Init_Proc_Name (Typ));
8657 Wrapper_Body_Node :=
8658 Make_Subprogram_Body (Loc,
8660 Make_Procedure_Specification (Loc,
8661 Defining_Unit_Name => Wrapper_Id,
8662 Parameter_Specifications => Parms),
8663 Declarations => New_List (Constructor_Decl_Node),
8664 Handled_Statement_Sequence =>
8665 Make_Handled_Sequence_Of_Statements (Loc,
8666 Statements => Body_Stmts,
8667 Exception_Handlers => No_List));
8669 Discard_Node (Wrapper_Body_Node);
8670 Set_Init_Proc (Typ, Wrapper_Id);
8676 -- If there are no constructors, mark the type as abstract since we
8677 -- won't be able to declare objects of that type.
8680 Set_Is_Abstract_Type (Typ);
8683 -- If the CPP type has constructors then it must import also the default
8684 -- C++ constructor. It is required for default initialization of objects
8685 -- of the type. It is also required to elaborate objects of Ada types
8686 -- that are defined as derivations of this CPP type.
8688 if Has_CPP_Constructors (Typ)
8689 and then No (Init_Proc (Typ))
8691 Error_Msg_N ("?default constructor must be imported from C++", Typ);
8693 end Set_CPP_Constructors;
8695 --------------------------
8696 -- Set_DTC_Entity_Value --
8697 --------------------------
8699 procedure Set_DTC_Entity_Value
8700 (Tagged_Type : Entity_Id;
8704 if Present (Interface_Alias (Prim))
8705 and then Is_Interface
8706 (Find_Dispatching_Type (Interface_Alias (Prim)))
8708 Set_DTC_Entity (Prim,
8711 Iface => Find_Dispatching_Type (Interface_Alias (Prim))));
8713 Set_DTC_Entity (Prim,
8714 First_Tag_Component (Tagged_Type));
8716 end Set_DTC_Entity_Value;
8722 function Tagged_Kind (T : Entity_Id) return Node_Id is
8723 Conc_Typ : Entity_Id;
8724 Loc : constant Source_Ptr := Sloc (T);
8728 (Is_Tagged_Type (T) and then RTE_Available (RE_Tagged_Kind));
8732 if Is_Abstract_Type (T) then
8733 if Is_Limited_Record (T) then
8734 return New_Reference_To (RTE (RE_TK_Abstract_Limited_Tagged), Loc);
8736 return New_Reference_To (RTE (RE_TK_Abstract_Tagged), Loc);
8741 elsif Is_Concurrent_Record_Type (T) then
8742 Conc_Typ := Corresponding_Concurrent_Type (T);
8744 if Present (Full_View (Conc_Typ)) then
8745 Conc_Typ := Full_View (Conc_Typ);
8748 if Ekind (Conc_Typ) = E_Protected_Type then
8749 return New_Reference_To (RTE (RE_TK_Protected), Loc);
8751 pragma Assert (Ekind (Conc_Typ) = E_Task_Type);
8752 return New_Reference_To (RTE (RE_TK_Task), Loc);
8755 -- Regular tagged kinds
8758 if Is_Limited_Record (T) then
8759 return New_Reference_To (RTE (RE_TK_Limited_Tagged), Loc);
8761 return New_Reference_To (RTE (RE_TK_Tagged), Loc);
8770 procedure Write_DT (Typ : Entity_Id) is
8775 -- Protect this procedure against wrong usage. Required because it will
8776 -- be used directly from GDB
8778 if not (Typ <= Last_Node_Id)
8779 or else not Is_Tagged_Type (Typ)
8781 Write_Str ("wrong usage: Write_DT must be used with tagged types");
8786 Write_Int (Int (Typ));
8788 Write_Name (Chars (Typ));
8790 if Is_Interface (Typ) then
8791 Write_Str (" is interface");
8796 Elmt := First_Elmt (Primitive_Operations (Typ));
8797 while Present (Elmt) loop
8798 Prim := Node (Elmt);
8801 -- Indicate if this primitive will be allocated in the primary
8802 -- dispatch table or in a secondary dispatch table associated
8803 -- with an abstract interface type
8805 if Present (DTC_Entity (Prim)) then
8806 if Etype (DTC_Entity (Prim)) = RTE (RE_Tag) then
8813 -- Output the node of this primitive operation and its name
8815 Write_Int (Int (Prim));
8818 if Is_Predefined_Dispatching_Operation (Prim) then
8819 Write_Str ("(predefined) ");
8822 -- Prefix the name of the primitive with its corresponding tagged
8823 -- type to facilitate seeing inherited primitives.
8825 if Present (Alias (Prim)) then
8827 (Chars (Find_Dispatching_Type (Ultimate_Alias (Prim))));
8829 Write_Name (Chars (Typ));
8833 Write_Name (Chars (Prim));
8835 -- Indicate if this primitive has an aliased primitive
8837 if Present (Alias (Prim)) then
8838 Write_Str (" (alias = ");
8839 Write_Int (Int (Alias (Prim)));
8841 -- If the DTC_Entity attribute is already set we can also output
8842 -- the name of the interface covered by this primitive (if any).
8844 if Present (DTC_Entity (Alias (Prim)))
8845 and then Is_Interface (Scope (DTC_Entity (Alias (Prim))))
8847 Write_Str (" from interface ");
8848 Write_Name (Chars (Scope (DTC_Entity (Alias (Prim)))));
8851 if Present (Interface_Alias (Prim)) then
8852 Write_Str (", AI_Alias of ");
8854 if Is_Null_Interface_Primitive (Interface_Alias (Prim)) then
8855 Write_Str ("null primitive ");
8859 (Chars (Find_Dispatching_Type (Interface_Alias (Prim))));
8861 Write_Int (Int (Interface_Alias (Prim)));
8867 -- Display the final position of this primitive in its associated
8868 -- (primary or secondary) dispatch table
8870 if Present (DTC_Entity (Prim))
8871 and then DT_Position (Prim) /= No_Uint
8873 Write_Str (" at #");
8874 Write_Int (UI_To_Int (DT_Position (Prim)));
8877 if Is_Abstract_Subprogram (Prim) then
8878 Write_Str (" is abstract;");
8880 -- Check if this is a null primitive
8882 elsif Comes_From_Source (Prim)
8883 and then Ekind (Prim) = E_Procedure
8884 and then Null_Present (Parent (Prim))
8886 Write_Str (" is null;");
8889 if Is_Eliminated (Ultimate_Alias (Prim)) then
8890 Write_Str (" (eliminated)");
8893 if Is_Imported (Prim)
8894 and then Convention (Prim) = Convention_CPP
8896 Write_Str (" (C++)");