1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2009, Free Software Foundation, Inc. --
11 -- GNAT is free software; you can redistribute it and/or modify it under --
12 -- terms of the GNU General Public License as published by the Free Soft- --
13 -- ware Foundation; either version 3, or (at your option) any later ver- --
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
16 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
17 -- for more details. You should have received a copy of the GNU General --
18 -- Public License distributed with GNAT; see file COPYING3. If not, go to --
19 -- http://www.gnu.org/licenses for a complete copy of the license. --
21 -- GNAT was originally developed by the GNAT team at New York University. --
22 -- Extensive contributions were provided by Ada Core Technologies Inc. --
24 ------------------------------------------------------------------------------
26 with Atree; use Atree;
27 with Checks; use Checks;
28 with Debug; use Debug;
29 with Einfo; use Einfo;
30 with Elists; use Elists;
31 with Errout; use Errout;
32 with Exp_Atag; use Exp_Atag;
33 with Exp_Ch7; use Exp_Ch7;
34 with Exp_Dbug; use Exp_Dbug;
35 with Exp_Tss; use Exp_Tss;
36 with Exp_Util; use Exp_Util;
37 with Freeze; use Freeze;
38 with Itypes; use Itypes;
39 with Layout; use Layout;
40 with Nlists; use Nlists;
41 with Nmake; use Nmake;
42 with Namet; use Namet;
44 with Output; use Output;
45 with Restrict; use Restrict;
46 with Rident; use Rident;
47 with Rtsfind; use Rtsfind;
49 with Sem_Aux; use Sem_Aux;
50 with Sem_Ch6; use Sem_Ch6;
51 with Sem_Ch7; use Sem_Ch7;
52 with Sem_Ch8; use Sem_Ch8;
53 with Sem_Disp; use Sem_Disp;
54 with Sem_Eval; use Sem_Eval;
55 with Sem_Res; use Sem_Res;
56 with Sem_Type; use Sem_Type;
57 with Sem_Util; use Sem_Util;
58 with Sinfo; use Sinfo;
59 with Snames; use Snames;
60 with Stand; use Stand;
61 with Stringt; use Stringt;
62 with Tbuild; use Tbuild;
63 with Uintp; use Uintp;
65 package body Exp_Disp is
67 -----------------------
68 -- Local Subprograms --
69 -----------------------
71 function Default_Prim_Op_Position (E : Entity_Id) return Uint;
72 -- Ada 2005 (AI-251): Returns the fixed position in the dispatch table
73 -- of the default primitive operations.
75 function Has_DT (Typ : Entity_Id) return Boolean;
76 pragma Inline (Has_DT);
77 -- Returns true if we generate a dispatch table for tagged type Typ
79 function Is_Predefined_Dispatching_Alias (Prim : Entity_Id) return Boolean;
80 -- Returns true if Prim is not a predefined dispatching primitive but it is
81 -- an alias of a predefined dispatching primitive (i.e. through a renaming)
83 function New_Value (From : Node_Id) return Node_Id;
84 -- From is the original Expression. New_Value is equivalent to a call
85 -- to Duplicate_Subexpr with an explicit dereference when From is an
88 function Original_View_In_Visible_Part (Typ : Entity_Id) return Boolean;
89 -- Check if the type has a private view or if the public view appears
90 -- in the visible part of a package spec.
94 Typ : Entity_Id) return Node_Id;
95 -- Ada 2005 (AI-345): Determine the primitive operation kind of Prim
96 -- according to its type Typ. Return a reference to an RE_Prim_Op_Kind
99 function Tagged_Kind (T : Entity_Id) return Node_Id;
100 -- Ada 2005 (AI-345): Determine the tagged kind of T and return a reference
101 -- to an RE_Tagged_Kind enumeration value.
103 ----------------------
104 -- Apply_Tag_Checks --
105 ----------------------
107 procedure Apply_Tag_Checks (Call_Node : Node_Id) is
108 Loc : constant Source_Ptr := Sloc (Call_Node);
109 Ctrl_Arg : constant Node_Id := Controlling_Argument (Call_Node);
110 Ctrl_Typ : constant Entity_Id := Base_Type (Etype (Ctrl_Arg));
111 Param_List : constant List_Id := Parameter_Associations (Call_Node);
117 Eq_Prim_Op : Entity_Id := Empty;
120 if No_Run_Time_Mode then
121 Error_Msg_CRT ("tagged types", Call_Node);
125 -- Apply_Tag_Checks is called directly from the semantics, so we need
126 -- a check to see whether expansion is active before proceeding. In
127 -- addition, there is no need to expand the call when compiling under
128 -- restriction No_Dispatching_Calls; the semantic analyzer has
129 -- previously notified the violation of this restriction.
131 if not Expander_Active
132 or else Restriction_Active (No_Dispatching_Calls)
137 -- Set subprogram. If this is an inherited operation that was
138 -- overridden, the body that is being called is its alias.
140 Subp := Entity (Name (Call_Node));
142 if Present (Alias (Subp))
143 and then Is_Inherited_Operation (Subp)
144 and then No (DTC_Entity (Subp))
146 Subp := Alias (Subp);
149 -- Definition of the class-wide type and the tagged type
151 -- If the controlling argument is itself a tag rather than a tagged
152 -- object, then use the class-wide type associated with the subprogram's
153 -- controlling type. This case can occur when a call to an inherited
154 -- primitive has an actual that originated from a default parameter
155 -- given by a tag-indeterminate call and when there is no other
156 -- controlling argument providing the tag (AI-239 requires dispatching).
157 -- This capability of dispatching directly by tag is also needed by the
158 -- implementation of AI-260 (for the generic dispatching constructors).
160 if Ctrl_Typ = RTE (RE_Tag)
161 or else (RTE_Available (RE_Interface_Tag)
162 and then Ctrl_Typ = RTE (RE_Interface_Tag))
164 CW_Typ := Class_Wide_Type (Find_Dispatching_Type (Subp));
166 -- Class_Wide_Type is applied to the expressions used to initialize
167 -- CW_Typ, to ensure that CW_Typ always denotes a class-wide type, since
168 -- there are cases where the controlling type is resolved to a specific
169 -- type (such as for designated types of arguments such as CW'Access).
171 elsif Is_Access_Type (Ctrl_Typ) then
172 CW_Typ := Class_Wide_Type (Designated_Type (Ctrl_Typ));
175 CW_Typ := Class_Wide_Type (Ctrl_Typ);
178 Typ := Root_Type (CW_Typ);
180 if Ekind (Typ) = E_Incomplete_Type then
181 Typ := Non_Limited_View (Typ);
184 if not Is_Limited_Type (Typ) then
185 Eq_Prim_Op := Find_Prim_Op (Typ, Name_Op_Eq);
188 -- Dispatching call to C++ primitive
190 if Is_CPP_Class (Typ) then
193 -- Dispatching call to Ada primitive
195 elsif Present (Param_List) then
197 -- Generate the Tag checks when appropriate
199 Param := First_Actual (Call_Node);
200 while Present (Param) loop
202 -- No tag check with itself
204 if Param = Ctrl_Arg then
207 -- No tag check for parameter whose type is neither tagged nor
208 -- access to tagged (for access parameters)
210 elsif No (Find_Controlling_Arg (Param)) then
213 -- No tag check for function dispatching on result if the
214 -- Tag given by the context is this one
216 elsif Find_Controlling_Arg (Param) = Ctrl_Arg then
219 -- "=" is the only dispatching operation allowed to get
220 -- operands with incompatible tags (it just returns false).
221 -- We use Duplicate_Subexpr_Move_Checks instead of calling
222 -- Relocate_Node because the value will be duplicated to
225 elsif Subp = Eq_Prim_Op then
228 -- No check in presence of suppress flags
230 elsif Tag_Checks_Suppressed (Etype (Param))
231 or else (Is_Access_Type (Etype (Param))
232 and then Tag_Checks_Suppressed
233 (Designated_Type (Etype (Param))))
237 -- Optimization: no tag checks if the parameters are identical
239 elsif Is_Entity_Name (Param)
240 and then Is_Entity_Name (Ctrl_Arg)
241 and then Entity (Param) = Entity (Ctrl_Arg)
245 -- Now we need to generate the Tag check
248 -- Generate code for tag equality check
249 -- Perhaps should have Checks.Apply_Tag_Equality_Check???
251 Insert_Action (Ctrl_Arg,
252 Make_Implicit_If_Statement (Call_Node,
256 Make_Selected_Component (Loc,
257 Prefix => New_Value (Ctrl_Arg),
260 (First_Tag_Component (Typ), Loc)),
263 Make_Selected_Component (Loc,
265 Unchecked_Convert_To (Typ, New_Value (Param)),
268 (First_Tag_Component (Typ), Loc))),
271 New_List (New_Constraint_Error (Loc))));
277 end Apply_Tag_Checks;
279 ------------------------
280 -- Building_Static_DT --
281 ------------------------
283 function Building_Static_DT (Typ : Entity_Id) return Boolean is
284 Root_Typ : Entity_Id := Root_Type (Typ);
287 -- Handle private types
289 if Present (Full_View (Root_Typ)) then
290 Root_Typ := Full_View (Root_Typ);
293 return Static_Dispatch_Tables
294 and then Is_Library_Level_Tagged_Type (Typ)
296 -- If the type is derived from a CPP class we cannot statically
297 -- build the dispatch tables because we must inherit primitives
298 -- from the CPP side.
300 and then not Is_CPP_Class (Root_Typ);
301 end Building_Static_DT;
303 ----------------------------------
304 -- Build_Static_Dispatch_Tables --
305 ----------------------------------
307 procedure Build_Static_Dispatch_Tables (N : Entity_Id) is
308 Target_List : List_Id;
310 procedure Build_Dispatch_Tables (List : List_Id);
311 -- Build the static dispatch table of tagged types found in the list of
312 -- declarations. The generated nodes are added at the end of Target_List
314 procedure Build_Package_Dispatch_Tables (N : Node_Id);
315 -- Build static dispatch tables associated with package declaration N
317 ---------------------------
318 -- Build_Dispatch_Tables --
319 ---------------------------
321 procedure Build_Dispatch_Tables (List : List_Id) is
326 while Present (D) loop
328 -- Handle nested packages and package bodies recursively. The
329 -- generated code is placed on the Target_List established for
330 -- the enclosing compilation unit.
332 if Nkind (D) = N_Package_Declaration then
333 Build_Package_Dispatch_Tables (D);
335 elsif Nkind (D) = N_Package_Body then
336 Build_Dispatch_Tables (Declarations (D));
338 elsif Nkind (D) = N_Package_Body_Stub
339 and then Present (Library_Unit (D))
341 Build_Dispatch_Tables
342 (Declarations (Proper_Body (Unit (Library_Unit (D)))));
344 -- Handle full type declarations and derivations of library
345 -- level tagged types
347 elsif Nkind_In (D, N_Full_Type_Declaration,
348 N_Derived_Type_Definition)
349 and then Is_Library_Level_Tagged_Type (Defining_Entity (D))
350 and then Ekind (Defining_Entity (D)) /= E_Record_Subtype
351 and then not Is_Private_Type (Defining_Entity (D))
353 -- We do not generate dispatch tables for the internal types
354 -- created for a type extension with unknown discriminants
355 -- The needed information is shared with the source type,
356 -- See Expand_N_Record_Extension.
358 if Is_Underlying_Record_View (Defining_Entity (D))
360 (not Comes_From_Source (Defining_Entity (D))
362 Has_Unknown_Discriminants (Etype (Defining_Entity (D)))
364 not Comes_From_Source
365 (First_Subtype (Defining_Entity (D))))
369 Insert_List_After_And_Analyze (Last (Target_List),
370 Make_DT (Defining_Entity (D)));
373 -- Handle private types of library level tagged types. We must
374 -- exchange the private and full-view to ensure the correct
375 -- expansion. If the full view is a synchronized type ignore
376 -- the type because the table will be built for the corresponding
377 -- record type, that has its own declaration.
379 elsif (Nkind (D) = N_Private_Type_Declaration
380 or else Nkind (D) = N_Private_Extension_Declaration)
381 and then Present (Full_View (Defining_Entity (D)))
384 E1 : constant Entity_Id := Defining_Entity (D);
385 E2 : constant Entity_Id := Full_View (E1);
388 if Is_Library_Level_Tagged_Type (E2)
389 and then Ekind (E2) /= E_Record_Subtype
390 and then not Is_Concurrent_Type (E2)
392 Exchange_Declarations (E1);
393 Insert_List_After_And_Analyze (Last (Target_List),
395 Exchange_Declarations (E2);
402 end Build_Dispatch_Tables;
404 -----------------------------------
405 -- Build_Package_Dispatch_Tables --
406 -----------------------------------
408 procedure Build_Package_Dispatch_Tables (N : Node_Id) is
409 Spec : constant Node_Id := Specification (N);
410 Id : constant Entity_Id := Defining_Entity (N);
411 Vis_Decls : constant List_Id := Visible_Declarations (Spec);
412 Priv_Decls : constant List_Id := Private_Declarations (Spec);
417 if Present (Priv_Decls) then
418 Build_Dispatch_Tables (Vis_Decls);
419 Build_Dispatch_Tables (Priv_Decls);
421 elsif Present (Vis_Decls) then
422 Build_Dispatch_Tables (Vis_Decls);
426 end Build_Package_Dispatch_Tables;
428 -- Start of processing for Build_Static_Dispatch_Tables
431 if not Expander_Active
432 or else not Tagged_Type_Expansion
437 if Nkind (N) = N_Package_Declaration then
439 Spec : constant Node_Id := Specification (N);
440 Vis_Decls : constant List_Id := Visible_Declarations (Spec);
441 Priv_Decls : constant List_Id := Private_Declarations (Spec);
444 if Present (Priv_Decls)
445 and then Is_Non_Empty_List (Priv_Decls)
447 Target_List := Priv_Decls;
449 elsif not Present (Vis_Decls) then
450 Target_List := New_List;
451 Set_Private_Declarations (Spec, Target_List);
453 Target_List := Vis_Decls;
456 Build_Package_Dispatch_Tables (N);
459 else pragma Assert (Nkind (N) = N_Package_Body);
460 Target_List := Declarations (N);
461 Build_Dispatch_Tables (Target_List);
463 end Build_Static_Dispatch_Tables;
465 ------------------------------
466 -- Default_Prim_Op_Position --
467 ------------------------------
469 function Default_Prim_Op_Position (E : Entity_Id) return Uint is
470 TSS_Name : TSS_Name_Type;
473 Get_Name_String (Chars (E));
476 (Name_Buffer (Name_Len - TSS_Name'Length + 1 .. Name_Len));
478 if Chars (E) = Name_uSize then
481 elsif Chars (E) = Name_uAlignment then
484 elsif TSS_Name = TSS_Stream_Read then
487 elsif TSS_Name = TSS_Stream_Write then
490 elsif TSS_Name = TSS_Stream_Input then
493 elsif TSS_Name = TSS_Stream_Output then
496 elsif Chars (E) = Name_Op_Eq then
499 elsif Chars (E) = Name_uAssign then
502 elsif TSS_Name = TSS_Deep_Adjust then
505 elsif TSS_Name = TSS_Deep_Finalize then
508 elsif Ada_Version >= Ada_05 then
509 if Chars (E) = Name_uDisp_Asynchronous_Select then
512 elsif Chars (E) = Name_uDisp_Conditional_Select then
515 elsif Chars (E) = Name_uDisp_Get_Prim_Op_Kind then
518 elsif Chars (E) = Name_uDisp_Get_Task_Id then
521 elsif Chars (E) = Name_uDisp_Requeue then
524 elsif Chars (E) = Name_uDisp_Timed_Select then
530 end Default_Prim_Op_Position;
532 -----------------------------
533 -- Expand_Dispatching_Call --
534 -----------------------------
536 procedure Expand_Dispatching_Call (Call_Node : Node_Id) is
537 Loc : constant Source_Ptr := Sloc (Call_Node);
538 Call_Typ : constant Entity_Id := Etype (Call_Node);
540 Ctrl_Arg : constant Node_Id := Controlling_Argument (Call_Node);
541 Ctrl_Typ : constant Entity_Id := Base_Type (Etype (Ctrl_Arg));
542 Param_List : constant List_Id := Parameter_Associations (Call_Node);
547 New_Call_Name : Node_Id;
548 New_Params : List_Id := No_List;
551 Subp_Ptr_Typ : Entity_Id;
552 Subp_Typ : Entity_Id;
554 Eq_Prim_Op : Entity_Id := Empty;
555 Controlling_Tag : Node_Id;
557 function New_Value (From : Node_Id) return Node_Id;
558 -- From is the original Expression. New_Value is equivalent to a call
559 -- to Duplicate_Subexpr with an explicit dereference when From is an
566 function New_Value (From : Node_Id) return Node_Id is
567 Res : constant Node_Id := Duplicate_Subexpr (From);
569 if Is_Access_Type (Etype (From)) then
571 Make_Explicit_Dereference (Sloc (From),
578 -- Start of processing for Expand_Dispatching_Call
581 if No_Run_Time_Mode then
582 Error_Msg_CRT ("tagged types", Call_Node);
586 -- Expand_Dispatching_Call is called directly from the semantics,
587 -- so we need a check to see whether expansion is active before
588 -- proceeding. In addition, there is no need to expand the call
589 -- if we are compiling under restriction No_Dispatching_Calls;
590 -- the semantic analyzer has previously notified the violation
591 -- of this restriction.
593 if not Expander_Active
594 or else Restriction_Active (No_Dispatching_Calls)
599 -- Set subprogram. If this is an inherited operation that was
600 -- overridden, the body that is being called is its alias.
602 Subp := Entity (Name (Call_Node));
604 if Present (Alias (Subp))
605 and then Is_Inherited_Operation (Subp)
606 and then No (DTC_Entity (Subp))
608 Subp := Alias (Subp);
611 -- Definition of the class-wide type and the tagged type
613 -- If the controlling argument is itself a tag rather than a tagged
614 -- object, then use the class-wide type associated with the subprogram's
615 -- controlling type. This case can occur when a call to an inherited
616 -- primitive has an actual that originated from a default parameter
617 -- given by a tag-indeterminate call and when there is no other
618 -- controlling argument providing the tag (AI-239 requires dispatching).
619 -- This capability of dispatching directly by tag is also needed by the
620 -- implementation of AI-260 (for the generic dispatching constructors).
622 if Ctrl_Typ = RTE (RE_Tag)
623 or else (RTE_Available (RE_Interface_Tag)
624 and then Ctrl_Typ = RTE (RE_Interface_Tag))
626 CW_Typ := Class_Wide_Type (Find_Dispatching_Type (Subp));
628 -- Class_Wide_Type is applied to the expressions used to initialize
629 -- CW_Typ, to ensure that CW_Typ always denotes a class-wide type, since
630 -- there are cases where the controlling type is resolved to a specific
631 -- type (such as for designated types of arguments such as CW'Access).
633 elsif Is_Access_Type (Ctrl_Typ) then
634 CW_Typ := Class_Wide_Type (Designated_Type (Ctrl_Typ));
637 CW_Typ := Class_Wide_Type (Ctrl_Typ);
640 Typ := Root_Type (CW_Typ);
642 if Ekind (Typ) = E_Incomplete_Type then
643 Typ := Non_Limited_View (Typ);
646 -- Generate the SCIL node for this dispatching call
648 if Generate_SCIL then
649 Insert_Action (Call_Node,
651 (Nkind => Dispatching_Call,
652 Related_Node => Call_Node,
654 Target_Prim => Subp));
657 if not Is_Limited_Type (Typ) then
658 Eq_Prim_Op := Find_Prim_Op (Typ, Name_Op_Eq);
661 -- Dispatching call to C++ primitive. Create a new parameter list
662 -- with no tag checks.
664 New_Params := New_List;
666 if Is_CPP_Class (Typ) then
667 Param := First_Actual (Call_Node);
668 while Present (Param) loop
669 Append_To (New_Params, Relocate_Node (Param));
673 -- Dispatching call to Ada primitive
675 elsif Present (Param_List) then
676 Apply_Tag_Checks (Call_Node);
678 Param := First_Actual (Call_Node);
679 while Present (Param) loop
680 -- Cases in which we may have generated runtime checks
683 or else Subp = Eq_Prim_Op
685 Append_To (New_Params,
686 Duplicate_Subexpr_Move_Checks (Param));
689 Append_To (New_Params, Relocate_Node (Param));
696 -- Generate the appropriate subprogram pointer type
698 if Etype (Subp) = Typ then
701 Res_Typ := Etype (Subp);
704 Subp_Typ := Create_Itype (E_Subprogram_Type, Call_Node);
705 Subp_Ptr_Typ := Create_Itype (E_Access_Subprogram_Type, Call_Node);
706 Set_Etype (Subp_Typ, Res_Typ);
707 Set_Returns_By_Ref (Subp_Typ, Returns_By_Ref (Subp));
709 -- Create a new list of parameters which is a copy of the old formal
710 -- list including the creation of a new set of matching entities.
713 Old_Formal : Entity_Id := First_Formal (Subp);
714 New_Formal : Entity_Id;
715 Extra : Entity_Id := Empty;
718 if Present (Old_Formal) then
719 New_Formal := New_Copy (Old_Formal);
720 Set_First_Entity (Subp_Typ, New_Formal);
721 Param := First_Actual (Call_Node);
724 Set_Scope (New_Formal, Subp_Typ);
726 -- Change all the controlling argument types to be class-wide
727 -- to avoid a recursion in dispatching.
729 if Is_Controlling_Formal (New_Formal) then
730 Set_Etype (New_Formal, Etype (Param));
733 -- If the type of the formal is an itype, there was code here
734 -- introduced in 1998 in revision 1.46, to create a new itype
735 -- by copy. This seems useless, and in fact leads to semantic
736 -- errors when the itype is the completion of a type derived
737 -- from a private type.
740 Next_Formal (Old_Formal);
741 exit when No (Old_Formal);
743 Set_Next_Entity (New_Formal, New_Copy (Old_Formal));
744 Next_Entity (New_Formal);
748 Set_Next_Entity (New_Formal, Empty);
749 Set_Last_Entity (Subp_Typ, Extra);
752 -- Now that the explicit formals have been duplicated, any extra
753 -- formals needed by the subprogram must be created.
755 if Present (Extra) then
756 Set_Extra_Formal (Extra, Empty);
759 Create_Extra_Formals (Subp_Typ);
762 -- Complete description of pointer type, including size information, as
763 -- must be done with itypes to prevent order-of-elaboration anomalies
766 Set_Etype (Subp_Ptr_Typ, Subp_Ptr_Typ);
767 Set_Directly_Designated_Type (Subp_Ptr_Typ, Subp_Typ);
768 Set_Convention (Subp_Ptr_Typ, Convention (Subp_Typ));
769 Layout_Type (Subp_Ptr_Typ);
771 -- If the controlling argument is a value of type Ada.Tag or an abstract
772 -- interface class-wide type then use it directly. Otherwise, the tag
773 -- must be extracted from the controlling object.
775 if Ctrl_Typ = RTE (RE_Tag)
776 or else (RTE_Available (RE_Interface_Tag)
777 and then Ctrl_Typ = RTE (RE_Interface_Tag))
779 Controlling_Tag := Duplicate_Subexpr (Ctrl_Arg);
781 -- Extract the tag from an unchecked type conversion. Done to avoid
782 -- the expansion of additional code just to obtain the value of such
783 -- tag because the current management of interface type conversions
784 -- generates in some cases this unchecked type conversion with the
785 -- tag of the object (see Expand_Interface_Conversion).
787 elsif Nkind (Ctrl_Arg) = N_Unchecked_Type_Conversion
789 (Etype (Expression (Ctrl_Arg)) = RTE (RE_Tag)
791 (RTE_Available (RE_Interface_Tag)
793 Etype (Expression (Ctrl_Arg)) = RTE (RE_Interface_Tag)))
795 Controlling_Tag := Duplicate_Subexpr (Expression (Ctrl_Arg));
797 -- Ada 2005 (AI-251): Abstract interface class-wide type
799 elsif Is_Interface (Ctrl_Typ)
800 and then Is_Class_Wide_Type (Ctrl_Typ)
802 Controlling_Tag := Duplicate_Subexpr (Ctrl_Arg);
806 Make_Selected_Component (Loc,
807 Prefix => Duplicate_Subexpr_Move_Checks (Ctrl_Arg),
808 Selector_Name => New_Reference_To (DTC_Entity (Subp), Loc));
811 -- Handle dispatching calls to predefined primitives
813 if Is_Predefined_Dispatching_Operation (Subp)
814 or else Is_Predefined_Dispatching_Alias (Subp)
817 Unchecked_Convert_To (Subp_Ptr_Typ,
818 Build_Get_Predefined_Prim_Op_Address (Loc,
819 Tag_Node => Controlling_Tag,
820 Position => DT_Position (Subp)));
822 -- Handle dispatching calls to user-defined primitives
826 Unchecked_Convert_To (Subp_Ptr_Typ,
827 Build_Get_Prim_Op_Address (Loc,
828 Typ => Find_Dispatching_Type (Subp),
829 Tag_Node => Controlling_Tag,
830 Position => DT_Position (Subp)));
833 if Nkind (Call_Node) = N_Function_Call then
836 Make_Function_Call (Loc,
837 Name => New_Call_Name,
838 Parameter_Associations => New_Params);
840 -- If this is a dispatching "=", we must first compare the tags so
841 -- we generate: x.tag = y.tag and then x = y
843 if Subp = Eq_Prim_Op then
844 Param := First_Actual (Call_Node);
850 Make_Selected_Component (Loc,
851 Prefix => New_Value (Param),
853 New_Reference_To (First_Tag_Component (Typ),
857 Make_Selected_Component (Loc,
859 Unchecked_Convert_To (Typ,
860 New_Value (Next_Actual (Param))),
862 New_Reference_To (First_Tag_Component (Typ),
864 Right_Opnd => New_Call);
869 Make_Procedure_Call_Statement (Loc,
870 Name => New_Call_Name,
871 Parameter_Associations => New_Params);
874 Rewrite (Call_Node, New_Call);
876 -- Suppress all checks during the analysis of the expanded code
877 -- to avoid the generation of spurious warnings under ZFP run-time.
879 Analyze_And_Resolve (Call_Node, Call_Typ, Suppress => All_Checks);
880 end Expand_Dispatching_Call;
882 ---------------------------------
883 -- Expand_Interface_Conversion --
884 ---------------------------------
886 procedure Expand_Interface_Conversion
888 Is_Static : Boolean := True)
890 Loc : constant Source_Ptr := Sloc (N);
891 Etyp : constant Entity_Id := Etype (N);
892 Operand : constant Node_Id := Expression (N);
893 Operand_Typ : Entity_Id := Etype (Operand);
895 Iface_Typ : Entity_Id := Etype (N);
896 Iface_Tag : Entity_Id;
899 -- Ada 2005 (AI-345): Handle synchronized interface type derivations
901 if Is_Concurrent_Type (Operand_Typ) then
902 Operand_Typ := Base_Type (Corresponding_Record_Type (Operand_Typ));
905 -- Handle access to class-wide interface types
907 if Is_Access_Type (Iface_Typ) then
908 Iface_Typ := Etype (Directly_Designated_Type (Iface_Typ));
911 -- Handle class-wide interface types. This conversion can appear
912 -- explicitly in the source code. Example: I'Class (Obj)
914 if Is_Class_Wide_Type (Iface_Typ) then
915 Iface_Typ := Root_Type (Iface_Typ);
918 -- If the target type is a tagged synchronized type, the dispatch table
919 -- info is in the corresponding record type.
921 if Is_Concurrent_Type (Iface_Typ) then
922 Iface_Typ := Corresponding_Record_Type (Iface_Typ);
925 -- Freeze the entity associated with the target interface to have
926 -- available the attribute Access_Disp_Table.
928 Freeze_Before (N, Iface_Typ);
930 pragma Assert (not Is_Static
931 or else (not Is_Class_Wide_Type (Iface_Typ)
932 and then Is_Interface (Iface_Typ)));
934 if not Tagged_Type_Expansion then
936 -- For VM, just do a conversion ???
938 Rewrite (N, Unchecked_Convert_To (Etype (N), N));
943 if not Is_Static then
945 -- Give error if configurable run time and Displace not available
947 if not RTE_Available (RE_Displace) then
948 Error_Msg_CRT ("dynamic interface conversion", N);
952 -- Handle conversion of access-to-class-wide interface types. Target
953 -- can be an access to an object or an access to another class-wide
954 -- interface (see -1- and -2- in the following example):
956 -- type Iface1_Ref is access all Iface1'Class;
957 -- type Iface2_Ref is access all Iface1'Class;
959 -- Acc1 : Iface1_Ref := new ...
960 -- Obj : Obj_Ref := Obj_Ref (Acc); -- 1
961 -- Acc2 : Iface2_Ref := Iface2_Ref (Acc); -- 2
963 if Is_Access_Type (Operand_Typ) then
965 Unchecked_Convert_To (Etype (N),
966 Make_Function_Call (Loc,
967 Name => New_Reference_To (RTE (RE_Displace), Loc),
968 Parameter_Associations => New_List (
970 Unchecked_Convert_To (RTE (RE_Address),
971 Relocate_Node (Expression (N))),
974 (Node (First_Elmt (Access_Disp_Table (Iface_Typ))),
982 Make_Function_Call (Loc,
983 Name => New_Reference_To (RTE (RE_Displace), Loc),
984 Parameter_Associations => New_List (
985 Make_Attribute_Reference (Loc,
986 Prefix => Relocate_Node (Expression (N)),
987 Attribute_Name => Name_Address),
990 (Node (First_Elmt (Access_Disp_Table (Iface_Typ))),
995 -- If the target is a class-wide interface we change the type of the
996 -- data returned by IW_Convert to indicate that this is a dispatching
1000 New_Itype : Entity_Id;
1003 New_Itype := Create_Itype (E_Anonymous_Access_Type, N);
1004 Set_Etype (New_Itype, New_Itype);
1005 Set_Directly_Designated_Type (New_Itype, Etyp);
1008 Make_Explicit_Dereference (Loc,
1010 Unchecked_Convert_To (New_Itype, Relocate_Node (N))));
1012 Freeze_Itype (New_Itype, N);
1018 Iface_Tag := Find_Interface_Tag (Operand_Typ, Iface_Typ);
1019 pragma Assert (Iface_Tag /= Empty);
1021 -- Keep separate access types to interfaces because one internal
1022 -- function is used to handle the null value (see following comment)
1024 if not Is_Access_Type (Etype (N)) then
1026 Unchecked_Convert_To (Etype (N),
1027 Make_Selected_Component (Loc,
1028 Prefix => Relocate_Node (Expression (N)),
1030 New_Occurrence_Of (Iface_Tag, Loc))));
1033 -- Build internal function to handle the case in which the
1034 -- actual is null. If the actual is null returns null because
1035 -- no displacement is required; otherwise performs a type
1036 -- conversion that will be expanded in the code that returns
1037 -- the value of the displaced actual. That is:
1039 -- function Func (O : Address) return Iface_Typ is
1040 -- type Op_Typ is access all Operand_Typ;
1041 -- Aux : Op_Typ := To_Op_Typ (O);
1043 -- if O = Null_Address then
1046 -- return Iface_Typ!(Aux.Iface_Tag'Address);
1051 Desig_Typ : Entity_Id;
1053 New_Typ_Decl : Node_Id;
1057 Desig_Typ := Etype (Expression (N));
1059 if Is_Access_Type (Desig_Typ) then
1061 Available_View (Directly_Designated_Type (Desig_Typ));
1064 if Is_Concurrent_Type (Desig_Typ) then
1065 Desig_Typ := Base_Type (Corresponding_Record_Type (Desig_Typ));
1069 Make_Full_Type_Declaration (Loc,
1070 Defining_Identifier =>
1071 Make_Defining_Identifier (Loc, New_Internal_Name ('T')),
1073 Make_Access_To_Object_Definition (Loc,
1074 All_Present => True,
1075 Null_Exclusion_Present => False,
1076 Constant_Present => False,
1077 Subtype_Indication =>
1078 New_Reference_To (Desig_Typ, Loc)));
1081 Make_Simple_Return_Statement (Loc,
1082 Unchecked_Convert_To (Etype (N),
1083 Make_Attribute_Reference (Loc,
1085 Make_Selected_Component (Loc,
1087 Unchecked_Convert_To
1088 (Defining_Identifier (New_Typ_Decl),
1089 Make_Identifier (Loc, Name_uO)),
1091 New_Occurrence_Of (Iface_Tag, Loc)),
1092 Attribute_Name => Name_Address))));
1094 -- If the type is null-excluding, no need for the null branch.
1095 -- Otherwise we need to check for it and return null.
1097 if not Can_Never_Be_Null (Etype (N)) then
1099 Make_If_Statement (Loc,
1102 Left_Opnd => Make_Identifier (Loc, Name_uO),
1103 Right_Opnd => New_Reference_To
1104 (RTE (RE_Null_Address), Loc)),
1106 Then_Statements => New_List (
1107 Make_Simple_Return_Statement (Loc,
1109 Else_Statements => Stats));
1113 Make_Defining_Identifier (Loc,
1114 New_Internal_Name ('F'));
1117 Make_Subprogram_Body (Loc,
1119 Make_Function_Specification (Loc,
1120 Defining_Unit_Name => Fent,
1122 Parameter_Specifications => New_List (
1123 Make_Parameter_Specification (Loc,
1124 Defining_Identifier =>
1125 Make_Defining_Identifier (Loc, Name_uO),
1127 New_Reference_To (RTE (RE_Address), Loc))),
1129 Result_Definition =>
1130 New_Reference_To (Etype (N), Loc)),
1132 Declarations => New_List (New_Typ_Decl),
1134 Handled_Statement_Sequence =>
1135 Make_Handled_Sequence_Of_Statements (Loc, Stats));
1137 -- Place function body before the expression containing the
1138 -- conversion. We suppress all checks because the body of the
1139 -- internally generated function already takes care of the case
1140 -- in which the actual is null; therefore there is no need to
1141 -- double check that the pointer is not null when the program
1142 -- executes the alternative that performs the type conversion).
1144 Insert_Action (N, Func, Suppress => All_Checks);
1146 if Is_Access_Type (Etype (Expression (N))) then
1148 -- Generate: Func (Address!(Expression))
1151 Make_Function_Call (Loc,
1152 Name => New_Reference_To (Fent, Loc),
1153 Parameter_Associations => New_List (
1154 Unchecked_Convert_To (RTE (RE_Address),
1155 Relocate_Node (Expression (N))))));
1158 -- Generate: Func (Operand_Typ!(Expression)'Address)
1161 Make_Function_Call (Loc,
1162 Name => New_Reference_To (Fent, Loc),
1163 Parameter_Associations => New_List (
1164 Make_Attribute_Reference (Loc,
1165 Prefix => Unchecked_Convert_To (Operand_Typ,
1166 Relocate_Node (Expression (N))),
1167 Attribute_Name => Name_Address))));
1173 end Expand_Interface_Conversion;
1175 ------------------------------
1176 -- Expand_Interface_Actuals --
1177 ------------------------------
1179 procedure Expand_Interface_Actuals (Call_Node : Node_Id) is
1181 Actual_Dup : Node_Id;
1182 Actual_Typ : Entity_Id;
1184 Conversion : Node_Id;
1186 Formal_Typ : Entity_Id;
1188 Formal_DDT : Entity_Id;
1189 Actual_DDT : Entity_Id;
1192 -- This subprogram is called directly from the semantics, so we need a
1193 -- check to see whether expansion is active before proceeding.
1195 if not Expander_Active then
1199 -- Call using access to subprogram with explicit dereference
1201 if Nkind (Name (Call_Node)) = N_Explicit_Dereference then
1202 Subp := Etype (Name (Call_Node));
1204 -- Call using selected component
1206 elsif Nkind (Name (Call_Node)) = N_Selected_Component then
1207 Subp := Entity (Selector_Name (Name (Call_Node)));
1209 -- Call using direct name
1212 Subp := Entity (Name (Call_Node));
1215 -- Ada 2005 (AI-251): Look for interface type formals to force "this"
1218 Formal := First_Formal (Subp);
1219 Actual := First_Actual (Call_Node);
1220 while Present (Formal) loop
1221 Formal_Typ := Etype (Formal);
1223 if Ekind (Formal_Typ) = E_Record_Type_With_Private then
1224 Formal_Typ := Full_View (Formal_Typ);
1227 if Is_Access_Type (Formal_Typ) then
1228 Formal_DDT := Directly_Designated_Type (Formal_Typ);
1231 Actual_Typ := Etype (Actual);
1233 if Is_Access_Type (Actual_Typ) then
1234 Actual_DDT := Directly_Designated_Type (Actual_Typ);
1237 if Is_Interface (Formal_Typ)
1238 and then Is_Class_Wide_Type (Formal_Typ)
1240 -- No need to displace the pointer if the type of the actual
1241 -- coindices with the type of the formal.
1243 if Actual_Typ = Formal_Typ then
1246 -- No need to displace the pointer if the interface type is
1247 -- a parent of the type of the actual because in this case the
1248 -- interface primitives are located in the primary dispatch table.
1250 elsif Is_Ancestor (Formal_Typ, Actual_Typ) then
1253 -- Implicit conversion to the class-wide formal type to force
1254 -- the displacement of the pointer.
1257 Conversion := Convert_To (Formal_Typ, Relocate_Node (Actual));
1258 Rewrite (Actual, Conversion);
1259 Analyze_And_Resolve (Actual, Formal_Typ);
1262 -- Access to class-wide interface type
1264 elsif Is_Access_Type (Formal_Typ)
1265 and then Is_Interface (Formal_DDT)
1266 and then Is_Class_Wide_Type (Formal_DDT)
1267 and then Interface_Present_In_Ancestor
1269 Iface => Etype (Formal_DDT))
1271 -- Handle attributes 'Access and 'Unchecked_Access
1273 if Nkind (Actual) = N_Attribute_Reference
1275 (Attribute_Name (Actual) = Name_Access
1276 or else Attribute_Name (Actual) = Name_Unchecked_Access)
1278 -- This case must have been handled by the analysis and
1279 -- expansion of 'Access. The only exception is when types
1280 -- match and no further expansion is required.
1282 pragma Assert (Base_Type (Etype (Prefix (Actual)))
1283 = Base_Type (Formal_DDT));
1286 -- No need to displace the pointer if the type of the actual
1287 -- coincides with the type of the formal.
1289 elsif Actual_DDT = Formal_DDT then
1292 -- No need to displace the pointer if the interface type is
1293 -- a parent of the type of the actual because in this case the
1294 -- interface primitives are located in the primary dispatch table.
1296 elsif Is_Ancestor (Formal_DDT, Actual_DDT) then
1300 Actual_Dup := Relocate_Node (Actual);
1302 if From_With_Type (Actual_Typ) then
1304 -- If the type of the actual parameter comes from a limited
1305 -- with-clause and the non-limited view is already available
1306 -- we replace the anonymous access type by a duplicate
1307 -- declaration whose designated type is the non-limited view
1309 if Ekind (Actual_DDT) = E_Incomplete_Type
1310 and then Present (Non_Limited_View (Actual_DDT))
1312 Anon := New_Copy (Actual_Typ);
1314 if Is_Itype (Anon) then
1315 Set_Scope (Anon, Current_Scope);
1318 Set_Directly_Designated_Type (Anon,
1319 Non_Limited_View (Actual_DDT));
1320 Set_Etype (Actual_Dup, Anon);
1322 elsif Is_Class_Wide_Type (Actual_DDT)
1323 and then Ekind (Etype (Actual_DDT)) = E_Incomplete_Type
1324 and then Present (Non_Limited_View (Etype (Actual_DDT)))
1326 Anon := New_Copy (Actual_Typ);
1328 if Is_Itype (Anon) then
1329 Set_Scope (Anon, Current_Scope);
1332 Set_Directly_Designated_Type (Anon,
1333 New_Copy (Actual_DDT));
1334 Set_Class_Wide_Type (Directly_Designated_Type (Anon),
1335 New_Copy (Class_Wide_Type (Actual_DDT)));
1336 Set_Etype (Directly_Designated_Type (Anon),
1337 Non_Limited_View (Etype (Actual_DDT)));
1339 Class_Wide_Type (Directly_Designated_Type (Anon)),
1340 Non_Limited_View (Etype (Actual_DDT)));
1341 Set_Etype (Actual_Dup, Anon);
1345 Conversion := Convert_To (Formal_Typ, Actual_Dup);
1346 Rewrite (Actual, Conversion);
1347 Analyze_And_Resolve (Actual, Formal_Typ);
1351 Next_Actual (Actual);
1352 Next_Formal (Formal);
1354 end Expand_Interface_Actuals;
1356 ----------------------------
1357 -- Expand_Interface_Thunk --
1358 ----------------------------
1360 procedure Expand_Interface_Thunk
1362 Thunk_Id : out Entity_Id;
1363 Thunk_Code : out Node_Id)
1365 Loc : constant Source_Ptr := Sloc (Prim);
1366 Actuals : constant List_Id := New_List;
1367 Decl : constant List_Id := New_List;
1368 Formals : constant List_Id := New_List;
1370 Controlling_Typ : Entity_Id;
1375 Offset_To_Top : Node_Id;
1377 Target_Formal : Entity_Id;
1381 Thunk_Code := Empty;
1383 -- Traverse the list of alias to find the final target
1386 while Present (Alias (Target)) loop
1387 Target := Alias (Target);
1390 -- In case of primitives that are functions without formals and
1391 -- a controlling result there is no need to build the thunk.
1393 if not Present (First_Formal (Target)) then
1394 pragma Assert (Ekind (Target) = E_Function
1395 and then Has_Controlling_Result (Target));
1399 -- Duplicate the formals
1401 Formal := First_Formal (Target);
1402 while Present (Formal) loop
1404 Make_Parameter_Specification (Loc,
1405 Defining_Identifier =>
1406 Make_Defining_Identifier (Sloc (Formal),
1407 Chars => Chars (Formal)),
1408 In_Present => In_Present (Parent (Formal)),
1409 Out_Present => Out_Present (Parent (Formal)),
1411 New_Reference_To (Etype (Formal), Loc),
1412 Expression => New_Copy_Tree (Expression (Parent (Formal)))));
1414 Next_Formal (Formal);
1417 Controlling_Typ := Find_Dispatching_Type (Target);
1419 Target_Formal := First_Formal (Target);
1420 Formal := First (Formals);
1421 while Present (Formal) loop
1422 if Ekind (Target_Formal) = E_In_Parameter
1423 and then Ekind (Etype (Target_Formal)) = E_Anonymous_Access_Type
1424 and then Directly_Designated_Type (Etype (Target_Formal))
1429 -- type T is access all <<type of the target formal>>
1430 -- S : Storage_Offset := Storage_Offset!(Formal)
1431 -- - Offset_To_Top (address!(Formal))
1434 Make_Full_Type_Declaration (Loc,
1435 Defining_Identifier =>
1436 Make_Defining_Identifier (Loc,
1437 New_Internal_Name ('T')),
1439 Make_Access_To_Object_Definition (Loc,
1440 All_Present => True,
1441 Null_Exclusion_Present => False,
1442 Constant_Present => False,
1443 Subtype_Indication =>
1445 (Directly_Designated_Type
1446 (Etype (Target_Formal)), Loc)));
1449 Unchecked_Convert_To (RTE (RE_Address),
1450 New_Reference_To (Defining_Identifier (Formal), Loc));
1452 if not RTE_Available (RE_Offset_To_Top) then
1454 Build_Offset_To_Top (Loc, New_Arg);
1457 Make_Function_Call (Loc,
1458 Name => New_Reference_To (RTE (RE_Offset_To_Top), Loc),
1459 Parameter_Associations => New_List (New_Arg));
1463 Make_Object_Declaration (Loc,
1464 Defining_Identifier =>
1465 Make_Defining_Identifier (Loc,
1466 New_Internal_Name ('S')),
1467 Constant_Present => True,
1468 Object_Definition =>
1469 New_Reference_To (RTE (RE_Storage_Offset), Loc),
1471 Make_Op_Subtract (Loc,
1473 Unchecked_Convert_To
1474 (RTE (RE_Storage_Offset),
1475 New_Reference_To (Defining_Identifier (Formal), Loc)),
1479 Append_To (Decl, Decl_2);
1480 Append_To (Decl, Decl_1);
1482 -- Reference the new actual. Generate:
1486 Unchecked_Convert_To
1487 (Defining_Identifier (Decl_2),
1488 New_Reference_To (Defining_Identifier (Decl_1), Loc)));
1490 elsif Etype (Target_Formal) = Controlling_Typ then
1493 -- S1 : Storage_Offset := Storage_Offset!(Formal'Address)
1494 -- - Offset_To_Top (Formal'Address)
1495 -- S2 : Addr_Ptr := Addr_Ptr!(S1)
1498 Make_Attribute_Reference (Loc,
1500 New_Reference_To (Defining_Identifier (Formal), Loc),
1504 if not RTE_Available (RE_Offset_To_Top) then
1506 Build_Offset_To_Top (Loc, New_Arg);
1509 Make_Function_Call (Loc,
1510 Name => New_Reference_To (RTE (RE_Offset_To_Top), Loc),
1511 Parameter_Associations => New_List (New_Arg));
1515 Make_Object_Declaration (Loc,
1516 Defining_Identifier =>
1517 Make_Defining_Identifier (Loc, New_Internal_Name ('S')),
1518 Constant_Present => True,
1519 Object_Definition =>
1520 New_Reference_To (RTE (RE_Storage_Offset), Loc),
1522 Make_Op_Subtract (Loc,
1524 Unchecked_Convert_To
1525 (RTE (RE_Storage_Offset),
1526 Make_Attribute_Reference (Loc,
1529 (Defining_Identifier (Formal), Loc),
1530 Attribute_Name => Name_Address)),
1535 Make_Object_Declaration (Loc,
1536 Defining_Identifier =>
1537 Make_Defining_Identifier (Loc, New_Internal_Name ('S')),
1538 Constant_Present => True,
1539 Object_Definition => New_Reference_To (RTE (RE_Addr_Ptr), Loc),
1541 Unchecked_Convert_To
1543 New_Reference_To (Defining_Identifier (Decl_1), Loc)));
1545 Append_To (Decl, Decl_1);
1546 Append_To (Decl, Decl_2);
1548 -- Reference the new actual. Generate:
1549 -- Target_Formal (S2.all)
1552 Unchecked_Convert_To
1553 (Etype (Target_Formal),
1554 Make_Explicit_Dereference (Loc,
1555 New_Reference_To (Defining_Identifier (Decl_2), Loc))));
1557 -- No special management required for this actual
1561 New_Reference_To (Defining_Identifier (Formal), Loc));
1564 Next_Formal (Target_Formal);
1569 Make_Defining_Identifier (Loc,
1570 Chars => New_Internal_Name ('T'));
1572 Set_Is_Thunk (Thunk_Id);
1574 if Ekind (Target) = E_Procedure then
1576 Make_Subprogram_Body (Loc,
1578 Make_Procedure_Specification (Loc,
1579 Defining_Unit_Name => Thunk_Id,
1580 Parameter_Specifications => Formals),
1581 Declarations => Decl,
1582 Handled_Statement_Sequence =>
1583 Make_Handled_Sequence_Of_Statements (Loc,
1584 Statements => New_List (
1585 Make_Procedure_Call_Statement (Loc,
1586 Name => New_Occurrence_Of (Target, Loc),
1587 Parameter_Associations => Actuals))));
1589 else pragma Assert (Ekind (Target) = E_Function);
1592 Make_Subprogram_Body (Loc,
1594 Make_Function_Specification (Loc,
1595 Defining_Unit_Name => Thunk_Id,
1596 Parameter_Specifications => Formals,
1597 Result_Definition =>
1598 New_Copy (Result_Definition (Parent (Target)))),
1599 Declarations => Decl,
1600 Handled_Statement_Sequence =>
1601 Make_Handled_Sequence_Of_Statements (Loc,
1602 Statements => New_List (
1603 Make_Simple_Return_Statement (Loc,
1604 Make_Function_Call (Loc,
1605 Name => New_Occurrence_Of (Target, Loc),
1606 Parameter_Associations => Actuals)))));
1608 end Expand_Interface_Thunk;
1610 ------------------------
1611 -- Get_Scil_Node_Kind --
1612 ------------------------
1614 function Get_Scil_Node_Kind (Node : Node_Id) return Scil_Node_Kind is
1617 (Nkind (Node) = N_Null_Statement and then Is_Scil_Node (Node));
1618 return Scil_Node_Kind'Val (UI_To_Int (Scil_Nkind (Node)));
1619 end Get_Scil_Node_Kind;
1625 function Has_DT (Typ : Entity_Id) return Boolean is
1627 return not Is_Interface (Typ)
1628 and then not Restriction_Active (No_Dispatching_Calls);
1631 -----------------------------------------
1632 -- Is_Predefined_Dispatching_Operation --
1633 -----------------------------------------
1635 function Is_Predefined_Dispatching_Operation
1636 (E : Entity_Id) return Boolean
1638 TSS_Name : TSS_Name_Type;
1641 if not Is_Dispatching_Operation (E) then
1645 Get_Name_String (Chars (E));
1647 -- Most predefined primitives have internally generated names. Equality
1648 -- must be treated differently; the predefined operation is recognized
1649 -- as a homogeneous binary operator that returns Boolean.
1651 if Name_Len > TSS_Name_Type'Last then
1652 TSS_Name := TSS_Name_Type (Name_Buffer (Name_Len - TSS_Name'Length + 1
1654 if Chars (E) = Name_uSize
1655 or else Chars (E) = Name_uAlignment
1656 or else TSS_Name = TSS_Stream_Read
1657 or else TSS_Name = TSS_Stream_Write
1658 or else TSS_Name = TSS_Stream_Input
1659 or else TSS_Name = TSS_Stream_Output
1661 (Chars (E) = Name_Op_Eq
1662 and then Etype (First_Entity (E)) = Etype (Last_Entity (E)))
1663 or else Chars (E) = Name_uAssign
1664 or else TSS_Name = TSS_Deep_Adjust
1665 or else TSS_Name = TSS_Deep_Finalize
1666 or else Is_Predefined_Interface_Primitive (E)
1673 end Is_Predefined_Dispatching_Operation;
1675 -------------------------------------
1676 -- Is_Predefined_Dispatching_Alias --
1677 -------------------------------------
1679 function Is_Predefined_Dispatching_Alias (Prim : Entity_Id) return Boolean
1684 if not Is_Predefined_Dispatching_Operation (Prim)
1685 and then Present (Alias (Prim))
1688 while Present (Alias (E)) loop
1692 if Is_Predefined_Dispatching_Operation (E) then
1698 end Is_Predefined_Dispatching_Alias;
1700 ---------------------------------------
1701 -- Is_Predefined_Interface_Primitive --
1702 ---------------------------------------
1704 function Is_Predefined_Interface_Primitive (E : Entity_Id) return Boolean is
1706 return Ada_Version >= Ada_05
1707 and then (Chars (E) = Name_uDisp_Asynchronous_Select or else
1708 Chars (E) = Name_uDisp_Conditional_Select or else
1709 Chars (E) = Name_uDisp_Get_Prim_Op_Kind or else
1710 Chars (E) = Name_uDisp_Get_Task_Id or else
1711 Chars (E) = Name_uDisp_Requeue or else
1712 Chars (E) = Name_uDisp_Timed_Select);
1713 end Is_Predefined_Interface_Primitive;
1715 ----------------------------------------
1716 -- Make_Disp_Asynchronous_Select_Body --
1717 ----------------------------------------
1719 -- For interface types, generate:
1721 -- procedure _Disp_Asynchronous_Select
1722 -- (T : in out <Typ>;
1724 -- P : System.Address;
1725 -- B : out System.Storage_Elements.Dummy_Communication_Block;
1730 -- end _Disp_Asynchronous_Select;
1732 -- For protected types, generate:
1734 -- procedure _Disp_Asynchronous_Select
1735 -- (T : in out <Typ>;
1737 -- P : System.Address;
1738 -- B : out System.Storage_Elements.Dummy_Communication_Block;
1742 -- Ada.Tags.Get_Entry_Index (Ada.Tags.Tag (<Typ>VP, S));
1743 -- Bnn : System.Tasking.Protected_Objects.Operations.
1744 -- Communication_Block;
1746 -- System.Tasking.Protected_Objects.Operations.Protected_Entry_Call
1747 -- (T._object'Access,
1748 -- System.Tasking.Protected_Objects.Protected_Entry_Index (I),
1750 -- System.Tasking.Asynchronous_Call,
1752 -- B := System.Storage_Elements.Dummy_Communication_Block (Bnn);
1753 -- end _Disp_Asynchronous_Select;
1755 -- For task types, generate:
1757 -- procedure _Disp_Asynchronous_Select
1758 -- (T : in out <Typ>;
1760 -- P : System.Address;
1761 -- B : out System.Storage_Elements.Dummy_Communication_Block;
1765 -- Ada.Tags.Get_Entry_Index (Ada.Tags.Tag (<Typ>VP, S));
1767 -- System.Tasking.Rendezvous.Task_Entry_Call
1769 -- System.Tasking.Task_Entry_Index (I),
1771 -- System.Tasking.Asynchronous_Call,
1773 -- end _Disp_Asynchronous_Select;
1775 function Make_Disp_Asynchronous_Select_Body
1776 (Typ : Entity_Id) return Node_Id
1778 Com_Block : Entity_Id;
1779 Conc_Typ : Entity_Id := Empty;
1780 Decls : constant List_Id := New_List;
1782 Loc : constant Source_Ptr := Sloc (Typ);
1784 Stmts : constant List_Id := New_List;
1787 pragma Assert (not Restriction_Active (No_Dispatching_Calls));
1789 -- Null body is generated for interface types
1791 if Is_Interface (Typ) then
1793 Make_Subprogram_Body (Loc,
1795 Make_Disp_Asynchronous_Select_Spec (Typ),
1798 Handled_Statement_Sequence =>
1799 Make_Handled_Sequence_Of_Statements (Loc,
1800 New_List (Make_Null_Statement (Loc))));
1803 DT_Ptr := Node (First_Elmt (Access_Disp_Table (Typ)));
1805 if Is_Concurrent_Record_Type (Typ) then
1806 Conc_Typ := Corresponding_Concurrent_Type (Typ);
1810 -- Ada.Tags.Get_Entry_Index (Ada.Tags.Tag! (<type>VP), S);
1812 -- where I will be used to capture the entry index of the primitive
1813 -- wrapper at position S.
1816 Make_Object_Declaration (Loc,
1817 Defining_Identifier =>
1818 Make_Defining_Identifier (Loc, Name_uI),
1819 Object_Definition =>
1820 New_Reference_To (Standard_Integer, Loc),
1822 Make_Function_Call (Loc,
1824 New_Reference_To (RTE (RE_Get_Entry_Index), Loc),
1825 Parameter_Associations =>
1827 Unchecked_Convert_To (RTE (RE_Tag),
1828 New_Reference_To (DT_Ptr, Loc)),
1829 Make_Identifier (Loc, Name_uS)))));
1831 if Ekind (Conc_Typ) = E_Protected_Type then
1834 -- Bnn : Communication_Block;
1837 Make_Defining_Identifier (Loc, New_Internal_Name ('B'));
1840 Make_Object_Declaration (Loc,
1841 Defining_Identifier =>
1843 Object_Definition =>
1844 New_Reference_To (RTE (RE_Communication_Block), Loc)));
1846 -- Build T._object'Access for calls below
1849 Make_Attribute_Reference (Loc,
1850 Attribute_Name => Name_Unchecked_Access,
1852 Make_Selected_Component (Loc,
1853 Prefix => Make_Identifier (Loc, Name_uT),
1854 Selector_Name => Make_Identifier (Loc, Name_uObject)));
1856 case Corresponding_Runtime_Package (Conc_Typ) is
1857 when System_Tasking_Protected_Objects_Entries =>
1860 -- Protected_Entry_Call
1861 -- (T._object'Access, -- Object
1862 -- Protected_Entry_Index! (I), -- E
1863 -- P, -- Uninterpreted_Data
1864 -- Asynchronous_Call, -- Mode
1865 -- Bnn); -- Communication_Block
1867 -- where T is the protected object, I is the entry index, P
1868 -- is the wrapped parameters and B is the name of the
1869 -- communication block.
1872 Make_Procedure_Call_Statement (Loc,
1874 New_Reference_To (RTE (RE_Protected_Entry_Call), Loc),
1875 Parameter_Associations =>
1879 Make_Unchecked_Type_Conversion (Loc, -- entry index
1882 (RTE (RE_Protected_Entry_Index), Loc),
1883 Expression => Make_Identifier (Loc, Name_uI)),
1885 Make_Identifier (Loc, Name_uP), -- parameter block
1886 New_Reference_To ( -- Asynchronous_Call
1887 RTE (RE_Asynchronous_Call), Loc),
1889 New_Reference_To (Com_Block, Loc)))); -- comm block
1891 when System_Tasking_Protected_Objects_Single_Entry =>
1894 -- procedure Protected_Single_Entry_Call
1895 -- (Object : Protection_Entry_Access;
1896 -- Uninterpreted_Data : System.Address;
1897 -- Mode : Call_Modes);
1900 Make_Procedure_Call_Statement (Loc,
1903 (RTE (RE_Protected_Single_Entry_Call), Loc),
1904 Parameter_Associations =>
1908 Make_Attribute_Reference (Loc,
1909 Prefix => Make_Identifier (Loc, Name_uP),
1910 Attribute_Name => Name_Address),
1913 (RTE (RE_Asynchronous_Call), Loc))));
1916 raise Program_Error;
1920 -- B := Dummy_Communication_Block (Bnn);
1923 Make_Assignment_Statement (Loc,
1925 Make_Identifier (Loc, Name_uB),
1927 Make_Unchecked_Type_Conversion (Loc,
1930 RTE (RE_Dummy_Communication_Block), Loc),
1932 New_Reference_To (Com_Block, Loc))));
1935 pragma Assert (Ekind (Conc_Typ) = E_Task_Type);
1939 -- (T._task_id, -- Acceptor
1940 -- Task_Entry_Index! (I), -- E
1941 -- P, -- Uninterpreted_Data
1942 -- Asynchronous_Call, -- Mode
1943 -- F); -- Rendezvous_Successful
1945 -- where T is the task object, I is the entry index, P is the
1946 -- wrapped parameters and F is the status flag.
1949 Make_Procedure_Call_Statement (Loc,
1951 New_Reference_To (RTE (RE_Task_Entry_Call), Loc),
1952 Parameter_Associations =>
1954 Make_Selected_Component (Loc, -- T._task_id
1956 Make_Identifier (Loc, Name_uT),
1958 Make_Identifier (Loc, Name_uTask_Id)),
1960 Make_Unchecked_Type_Conversion (Loc, -- entry index
1962 New_Reference_To (RTE (RE_Task_Entry_Index), Loc),
1964 Make_Identifier (Loc, Name_uI)),
1966 Make_Identifier (Loc, Name_uP), -- parameter block
1967 New_Reference_To ( -- Asynchronous_Call
1968 RTE (RE_Asynchronous_Call), Loc),
1969 Make_Identifier (Loc, Name_uF)))); -- status flag
1973 -- Ensure that the statements list is non-empty
1975 Append_To (Stmts, Make_Null_Statement (Loc));
1979 Make_Subprogram_Body (Loc,
1981 Make_Disp_Asynchronous_Select_Spec (Typ),
1984 Handled_Statement_Sequence =>
1985 Make_Handled_Sequence_Of_Statements (Loc, Stmts));
1986 end Make_Disp_Asynchronous_Select_Body;
1988 ----------------------------------------
1989 -- Make_Disp_Asynchronous_Select_Spec --
1990 ----------------------------------------
1992 function Make_Disp_Asynchronous_Select_Spec
1993 (Typ : Entity_Id) return Node_Id
1995 Loc : constant Source_Ptr := Sloc (Typ);
1996 Def_Id : constant Node_Id :=
1997 Make_Defining_Identifier (Loc,
1998 Name_uDisp_Asynchronous_Select);
1999 Params : constant List_Id := New_List;
2002 pragma Assert (not Restriction_Active (No_Dispatching_Calls));
2004 -- T : in out Typ; -- Object parameter
2005 -- S : Integer; -- Primitive operation slot
2006 -- P : Address; -- Wrapped parameters
2007 -- B : out Dummy_Communication_Block; -- Communication block dummy
2008 -- F : out Boolean; -- Status flag
2010 Append_List_To (Params, New_List (
2012 Make_Parameter_Specification (Loc,
2013 Defining_Identifier =>
2014 Make_Defining_Identifier (Loc, Name_uT),
2016 New_Reference_To (Typ, Loc),
2018 Out_Present => True),
2020 Make_Parameter_Specification (Loc,
2021 Defining_Identifier =>
2022 Make_Defining_Identifier (Loc, Name_uS),
2024 New_Reference_To (Standard_Integer, Loc)),
2026 Make_Parameter_Specification (Loc,
2027 Defining_Identifier =>
2028 Make_Defining_Identifier (Loc, Name_uP),
2030 New_Reference_To (RTE (RE_Address), Loc)),
2032 Make_Parameter_Specification (Loc,
2033 Defining_Identifier =>
2034 Make_Defining_Identifier (Loc, Name_uB),
2036 New_Reference_To (RTE (RE_Dummy_Communication_Block), Loc),
2037 Out_Present => True),
2039 Make_Parameter_Specification (Loc,
2040 Defining_Identifier =>
2041 Make_Defining_Identifier (Loc, Name_uF),
2043 New_Reference_To (Standard_Boolean, Loc),
2044 Out_Present => True)));
2047 Make_Procedure_Specification (Loc,
2048 Defining_Unit_Name => Def_Id,
2049 Parameter_Specifications => Params);
2050 end Make_Disp_Asynchronous_Select_Spec;
2052 ---------------------------------------
2053 -- Make_Disp_Conditional_Select_Body --
2054 ---------------------------------------
2056 -- For interface types, generate:
2058 -- procedure _Disp_Conditional_Select
2059 -- (T : in out <Typ>;
2061 -- P : System.Address;
2062 -- C : out Ada.Tags.Prim_Op_Kind;
2067 -- end _Disp_Conditional_Select;
2069 -- For protected types, generate:
2071 -- procedure _Disp_Conditional_Select
2072 -- (T : in out <Typ>;
2074 -- P : System.Address;
2075 -- C : out Ada.Tags.Prim_Op_Kind;
2079 -- Bnn : System.Tasking.Protected_Objects.Operations.
2080 -- Communication_Block;
2083 -- C := Ada.Tags.Get_Prim_Op_Kind (Ada.Tags.Tag (<Typ>VP, S));
2085 -- if C = Ada.Tags.POK_Procedure
2086 -- or else C = Ada.Tags.POK_Protected_Procedure
2087 -- or else C = Ada.Tags.POK_Task_Procedure
2093 -- I := Ada.Tags.Get_Entry_Index (Ada.Tags.Tag (<Typ>VP, S));
2094 -- System.Tasking.Protected_Objects.Operations.Protected_Entry_Call
2095 -- (T.object'Access,
2096 -- System.Tasking.Protected_Objects.Protected_Entry_Index (I),
2098 -- System.Tasking.Conditional_Call,
2100 -- F := not Cancelled (Bnn);
2101 -- end _Disp_Conditional_Select;
2103 -- For task types, generate:
2105 -- procedure _Disp_Conditional_Select
2106 -- (T : in out <Typ>;
2108 -- P : System.Address;
2109 -- C : out Ada.Tags.Prim_Op_Kind;
2115 -- I := Ada.Tags.Get_Entry_Index (Ada.Tags.Tag (<Typ>VP, S));
2116 -- System.Tasking.Rendezvous.Task_Entry_Call
2118 -- System.Tasking.Task_Entry_Index (I),
2120 -- System.Tasking.Conditional_Call,
2122 -- end _Disp_Conditional_Select;
2124 function Make_Disp_Conditional_Select_Body
2125 (Typ : Entity_Id) return Node_Id
2127 Loc : constant Source_Ptr := Sloc (Typ);
2128 Blk_Nam : Entity_Id;
2129 Conc_Typ : Entity_Id := Empty;
2130 Decls : constant List_Id := New_List;
2133 Stmts : constant List_Id := New_List;
2136 pragma Assert (not Restriction_Active (No_Dispatching_Calls));
2138 -- Null body is generated for interface types
2140 if Is_Interface (Typ) then
2142 Make_Subprogram_Body (Loc,
2144 Make_Disp_Conditional_Select_Spec (Typ),
2147 Handled_Statement_Sequence =>
2148 Make_Handled_Sequence_Of_Statements (Loc,
2149 New_List (Make_Null_Statement (Loc))));
2152 DT_Ptr := Node (First_Elmt (Access_Disp_Table (Typ)));
2154 if Is_Concurrent_Record_Type (Typ) then
2155 Conc_Typ := Corresponding_Concurrent_Type (Typ);
2160 -- where I will be used to capture the entry index of the primitive
2161 -- wrapper at position S.
2164 Make_Object_Declaration (Loc,
2165 Defining_Identifier =>
2166 Make_Defining_Identifier (Loc, Name_uI),
2167 Object_Definition =>
2168 New_Reference_To (Standard_Integer, Loc)));
2171 -- C := Ada.Tags.Get_Prim_Op_Kind (Ada.Tags.Tag! (<type>VP), S);
2173 -- if C = POK_Procedure
2174 -- or else C = POK_Protected_Procedure
2175 -- or else C = POK_Task_Procedure;
2181 Build_Common_Dispatching_Select_Statements (Loc, DT_Ptr, Stmts);
2184 -- Bnn : Communication_Block;
2186 -- where Bnn is the name of the communication block used in the
2187 -- call to Protected_Entry_Call.
2189 Blk_Nam := Make_Defining_Identifier (Loc, New_Internal_Name ('B'));
2192 Make_Object_Declaration (Loc,
2193 Defining_Identifier =>
2195 Object_Definition =>
2196 New_Reference_To (RTE (RE_Communication_Block), Loc)));
2199 -- I := Ada.Tags.Get_Entry_Index (Ada.Tags.Tag! (<type>VP), S);
2201 -- I is the entry index and S is the dispatch table slot
2204 Make_Assignment_Statement (Loc,
2206 Make_Identifier (Loc, Name_uI),
2208 Make_Function_Call (Loc,
2210 New_Reference_To (RTE (RE_Get_Entry_Index), Loc),
2211 Parameter_Associations =>
2213 Unchecked_Convert_To (RTE (RE_Tag),
2214 New_Reference_To (DT_Ptr, Loc)),
2215 Make_Identifier (Loc, Name_uS)))));
2217 if Ekind (Conc_Typ) = E_Protected_Type then
2219 Obj_Ref := -- T._object'Access
2220 Make_Attribute_Reference (Loc,
2221 Attribute_Name => Name_Unchecked_Access,
2223 Make_Selected_Component (Loc,
2224 Prefix => Make_Identifier (Loc, Name_uT),
2225 Selector_Name => Make_Identifier (Loc, Name_uObject)));
2227 case Corresponding_Runtime_Package (Conc_Typ) is
2228 when System_Tasking_Protected_Objects_Entries =>
2231 -- Protected_Entry_Call
2232 -- (T._object'Access, -- Object
2233 -- Protected_Entry_Index! (I), -- E
2234 -- P, -- Uninterpreted_Data
2235 -- Conditional_Call, -- Mode
2238 -- where T is the protected object, I is the entry index, P
2239 -- are the wrapped parameters and Bnn is the name of the
2240 -- communication block.
2243 Make_Procedure_Call_Statement (Loc,
2245 New_Reference_To (RTE (RE_Protected_Entry_Call), Loc),
2246 Parameter_Associations =>
2250 Make_Unchecked_Type_Conversion (Loc, -- entry index
2253 (RTE (RE_Protected_Entry_Index), Loc),
2254 Expression => Make_Identifier (Loc, Name_uI)),
2256 Make_Identifier (Loc, Name_uP), -- parameter block
2258 New_Reference_To ( -- Conditional_Call
2259 RTE (RE_Conditional_Call), Loc),
2260 New_Reference_To ( -- Bnn
2263 when System_Tasking_Protected_Objects_Single_Entry =>
2265 -- If we are compiling for a restricted run-time, the call
2266 -- uses the simpler form.
2269 Make_Procedure_Call_Statement (Loc,
2272 (RTE (RE_Protected_Single_Entry_Call), Loc),
2273 Parameter_Associations =>
2277 Make_Attribute_Reference (Loc,
2278 Prefix => Make_Identifier (Loc, Name_uP),
2279 Attribute_Name => Name_Address),
2282 (RTE (RE_Conditional_Call), Loc))));
2284 raise Program_Error;
2288 -- F := not Cancelled (Bnn);
2290 -- where F is the success flag. The status of Cancelled is negated
2291 -- in order to match the behaviour of the version for task types.
2294 Make_Assignment_Statement (Loc,
2296 Make_Identifier (Loc, Name_uF),
2300 Make_Function_Call (Loc,
2302 New_Reference_To (RTE (RE_Cancelled), Loc),
2303 Parameter_Associations =>
2305 New_Reference_To (Blk_Nam, Loc))))));
2307 pragma Assert (Ekind (Conc_Typ) = E_Task_Type);
2311 -- (T._task_id, -- Acceptor
2312 -- Task_Entry_Index! (I), -- E
2313 -- P, -- Uninterpreted_Data
2314 -- Conditional_Call, -- Mode
2315 -- F); -- Rendezvous_Successful
2317 -- where T is the task object, I is the entry index, P are the
2318 -- wrapped parameters and F is the status flag.
2321 Make_Procedure_Call_Statement (Loc,
2323 New_Reference_To (RTE (RE_Task_Entry_Call), Loc),
2324 Parameter_Associations =>
2327 Make_Selected_Component (Loc, -- T._task_id
2329 Make_Identifier (Loc, Name_uT),
2331 Make_Identifier (Loc, Name_uTask_Id)),
2333 Make_Unchecked_Type_Conversion (Loc, -- entry index
2335 New_Reference_To (RTE (RE_Task_Entry_Index), Loc),
2337 Make_Identifier (Loc, Name_uI)),
2339 Make_Identifier (Loc, Name_uP), -- parameter block
2340 New_Reference_To ( -- Conditional_Call
2341 RTE (RE_Conditional_Call), Loc),
2342 Make_Identifier (Loc, Name_uF)))); -- status flag
2346 -- Ensure that the statements list is non-empty
2348 Append_To (Stmts, Make_Null_Statement (Loc));
2352 Make_Subprogram_Body (Loc,
2354 Make_Disp_Conditional_Select_Spec (Typ),
2357 Handled_Statement_Sequence =>
2358 Make_Handled_Sequence_Of_Statements (Loc, Stmts));
2359 end Make_Disp_Conditional_Select_Body;
2361 ---------------------------------------
2362 -- Make_Disp_Conditional_Select_Spec --
2363 ---------------------------------------
2365 function Make_Disp_Conditional_Select_Spec
2366 (Typ : Entity_Id) return Node_Id
2368 Loc : constant Source_Ptr := Sloc (Typ);
2369 Def_Id : constant Node_Id :=
2370 Make_Defining_Identifier (Loc,
2371 Name_uDisp_Conditional_Select);
2372 Params : constant List_Id := New_List;
2375 pragma Assert (not Restriction_Active (No_Dispatching_Calls));
2377 -- T : in out Typ; -- Object parameter
2378 -- S : Integer; -- Primitive operation slot
2379 -- P : Address; -- Wrapped parameters
2380 -- C : out Prim_Op_Kind; -- Call kind
2381 -- F : out Boolean; -- Status flag
2383 Append_List_To (Params, New_List (
2385 Make_Parameter_Specification (Loc,
2386 Defining_Identifier =>
2387 Make_Defining_Identifier (Loc, Name_uT),
2389 New_Reference_To (Typ, Loc),
2391 Out_Present => True),
2393 Make_Parameter_Specification (Loc,
2394 Defining_Identifier =>
2395 Make_Defining_Identifier (Loc, Name_uS),
2397 New_Reference_To (Standard_Integer, Loc)),
2399 Make_Parameter_Specification (Loc,
2400 Defining_Identifier =>
2401 Make_Defining_Identifier (Loc, Name_uP),
2403 New_Reference_To (RTE (RE_Address), Loc)),
2405 Make_Parameter_Specification (Loc,
2406 Defining_Identifier =>
2407 Make_Defining_Identifier (Loc, Name_uC),
2409 New_Reference_To (RTE (RE_Prim_Op_Kind), Loc),
2410 Out_Present => True),
2412 Make_Parameter_Specification (Loc,
2413 Defining_Identifier =>
2414 Make_Defining_Identifier (Loc, Name_uF),
2416 New_Reference_To (Standard_Boolean, Loc),
2417 Out_Present => True)));
2420 Make_Procedure_Specification (Loc,
2421 Defining_Unit_Name => Def_Id,
2422 Parameter_Specifications => Params);
2423 end Make_Disp_Conditional_Select_Spec;
2425 -------------------------------------
2426 -- Make_Disp_Get_Prim_Op_Kind_Body --
2427 -------------------------------------
2429 function Make_Disp_Get_Prim_Op_Kind_Body
2430 (Typ : Entity_Id) return Node_Id
2432 Loc : constant Source_Ptr := Sloc (Typ);
2436 pragma Assert (not Restriction_Active (No_Dispatching_Calls));
2438 if Is_Interface (Typ) then
2440 Make_Subprogram_Body (Loc,
2442 Make_Disp_Get_Prim_Op_Kind_Spec (Typ),
2445 Handled_Statement_Sequence =>
2446 Make_Handled_Sequence_Of_Statements (Loc,
2447 New_List (Make_Null_Statement (Loc))));
2450 DT_Ptr := Node (First_Elmt (Access_Disp_Table (Typ)));
2453 -- C := get_prim_op_kind (tag! (<type>VP), S);
2455 -- where C is the out parameter capturing the call kind and S is the
2456 -- dispatch table slot number.
2459 Make_Subprogram_Body (Loc,
2461 Make_Disp_Get_Prim_Op_Kind_Spec (Typ),
2464 Handled_Statement_Sequence =>
2465 Make_Handled_Sequence_Of_Statements (Loc,
2467 Make_Assignment_Statement (Loc,
2469 Make_Identifier (Loc, Name_uC),
2471 Make_Function_Call (Loc,
2473 New_Reference_To (RTE (RE_Get_Prim_Op_Kind), Loc),
2474 Parameter_Associations => New_List (
2475 Unchecked_Convert_To (RTE (RE_Tag),
2476 New_Reference_To (DT_Ptr, Loc)),
2477 Make_Identifier (Loc, Name_uS)))))));
2478 end Make_Disp_Get_Prim_Op_Kind_Body;
2480 -------------------------------------
2481 -- Make_Disp_Get_Prim_Op_Kind_Spec --
2482 -------------------------------------
2484 function Make_Disp_Get_Prim_Op_Kind_Spec
2485 (Typ : Entity_Id) return Node_Id
2487 Loc : constant Source_Ptr := Sloc (Typ);
2488 Def_Id : constant Node_Id :=
2489 Make_Defining_Identifier (Loc,
2490 Name_uDisp_Get_Prim_Op_Kind);
2491 Params : constant List_Id := New_List;
2494 pragma Assert (not Restriction_Active (No_Dispatching_Calls));
2496 -- T : in out Typ; -- Object parameter
2497 -- S : Integer; -- Primitive operation slot
2498 -- C : out Prim_Op_Kind; -- Call kind
2500 Append_List_To (Params, New_List (
2502 Make_Parameter_Specification (Loc,
2503 Defining_Identifier =>
2504 Make_Defining_Identifier (Loc, Name_uT),
2506 New_Reference_To (Typ, Loc),
2508 Out_Present => True),
2510 Make_Parameter_Specification (Loc,
2511 Defining_Identifier =>
2512 Make_Defining_Identifier (Loc, Name_uS),
2514 New_Reference_To (Standard_Integer, Loc)),
2516 Make_Parameter_Specification (Loc,
2517 Defining_Identifier =>
2518 Make_Defining_Identifier (Loc, Name_uC),
2520 New_Reference_To (RTE (RE_Prim_Op_Kind), Loc),
2521 Out_Present => True)));
2524 Make_Procedure_Specification (Loc,
2525 Defining_Unit_Name => Def_Id,
2526 Parameter_Specifications => Params);
2527 end Make_Disp_Get_Prim_Op_Kind_Spec;
2529 --------------------------------
2530 -- Make_Disp_Get_Task_Id_Body --
2531 --------------------------------
2533 function Make_Disp_Get_Task_Id_Body
2534 (Typ : Entity_Id) return Node_Id
2536 Loc : constant Source_Ptr := Sloc (Typ);
2540 pragma Assert (not Restriction_Active (No_Dispatching_Calls));
2542 if Is_Concurrent_Record_Type (Typ)
2543 and then Ekind (Corresponding_Concurrent_Type (Typ)) = E_Task_Type
2546 -- return To_Address (_T._task_id);
2549 Make_Simple_Return_Statement (Loc,
2551 Make_Unchecked_Type_Conversion (Loc,
2553 New_Reference_To (RTE (RE_Address), Loc),
2555 Make_Selected_Component (Loc,
2557 Make_Identifier (Loc, Name_uT),
2559 Make_Identifier (Loc, Name_uTask_Id))));
2561 -- A null body is constructed for non-task types
2565 -- return Null_Address;
2568 Make_Simple_Return_Statement (Loc,
2570 New_Reference_To (RTE (RE_Null_Address), Loc));
2574 Make_Subprogram_Body (Loc,
2576 Make_Disp_Get_Task_Id_Spec (Typ),
2579 Handled_Statement_Sequence =>
2580 Make_Handled_Sequence_Of_Statements (Loc,
2582 end Make_Disp_Get_Task_Id_Body;
2584 --------------------------------
2585 -- Make_Disp_Get_Task_Id_Spec --
2586 --------------------------------
2588 function Make_Disp_Get_Task_Id_Spec
2589 (Typ : Entity_Id) return Node_Id
2591 Loc : constant Source_Ptr := Sloc (Typ);
2594 pragma Assert (not Restriction_Active (No_Dispatching_Calls));
2597 Make_Function_Specification (Loc,
2598 Defining_Unit_Name =>
2599 Make_Defining_Identifier (Loc, Name_uDisp_Get_Task_Id),
2600 Parameter_Specifications => New_List (
2601 Make_Parameter_Specification (Loc,
2602 Defining_Identifier =>
2603 Make_Defining_Identifier (Loc, Name_uT),
2605 New_Reference_To (Typ, Loc))),
2606 Result_Definition =>
2607 New_Reference_To (RTE (RE_Address), Loc));
2608 end Make_Disp_Get_Task_Id_Spec;
2610 ----------------------------
2611 -- Make_Disp_Requeue_Body --
2612 ----------------------------
2614 function Make_Disp_Requeue_Body
2615 (Typ : Entity_Id) return Node_Id
2617 Loc : constant Source_Ptr := Sloc (Typ);
2618 Conc_Typ : Entity_Id := Empty;
2619 Stmts : constant List_Id := New_List;
2622 pragma Assert (not Restriction_Active (No_Dispatching_Calls));
2624 -- Null body is generated for interface types and non-concurrent
2627 if Is_Interface (Typ)
2628 or else not Is_Concurrent_Record_Type (Typ)
2631 Make_Subprogram_Body (Loc,
2633 Make_Disp_Requeue_Spec (Typ),
2636 Handled_Statement_Sequence =>
2637 Make_Handled_Sequence_Of_Statements (Loc,
2638 New_List (Make_Null_Statement (Loc))));
2641 Conc_Typ := Corresponding_Concurrent_Type (Typ);
2643 if Ekind (Conc_Typ) = E_Protected_Type then
2645 -- Generate statements:
2647 -- System.Tasking.Protected_Objects.Operations.
2648 -- Requeue_Protected_Entry
2649 -- (Protection_Entries_Access (P),
2650 -- O._object'Unchecked_Access,
2651 -- Protected_Entry_Index (I),
2654 -- System.Tasking.Protected_Objects.Operations.
2655 -- Requeue_Task_To_Protected_Entry
2656 -- (O._object'Unchecked_Access,
2657 -- Protected_Entry_Index (I),
2661 if Restriction_Active (No_Entry_Queue) then
2662 Append_To (Stmts, Make_Null_Statement (Loc));
2665 Make_If_Statement (Loc,
2667 Make_Identifier (Loc, Name_uF),
2672 -- Call to Requeue_Protected_Entry
2674 Make_Procedure_Call_Statement (Loc,
2677 RTE (RE_Requeue_Protected_Entry), Loc),
2678 Parameter_Associations =>
2681 Make_Unchecked_Type_Conversion (Loc, -- PEA (P)
2684 RTE (RE_Protection_Entries_Access), Loc),
2686 Make_Identifier (Loc, Name_uP)),
2688 Make_Attribute_Reference (Loc, -- O._object'Acc
2690 Name_Unchecked_Access,
2692 Make_Selected_Component (Loc,
2694 Make_Identifier (Loc, Name_uO),
2696 Make_Identifier (Loc, Name_uObject))),
2698 Make_Unchecked_Type_Conversion (Loc, -- entry index
2701 RTE (RE_Protected_Entry_Index), Loc),
2703 Make_Identifier (Loc, Name_uI)),
2705 Make_Identifier (Loc, Name_uA)))), -- abort status
2710 -- Call to Requeue_Task_To_Protected_Entry
2712 Make_Procedure_Call_Statement (Loc,
2715 RTE (RE_Requeue_Task_To_Protected_Entry), Loc),
2716 Parameter_Associations =>
2719 Make_Attribute_Reference (Loc, -- O._object'Acc
2721 Name_Unchecked_Access,
2723 Make_Selected_Component (Loc,
2725 Make_Identifier (Loc, Name_uO),
2727 Make_Identifier (Loc, Name_uObject))),
2729 Make_Unchecked_Type_Conversion (Loc, -- entry index
2732 RTE (RE_Protected_Entry_Index), Loc),
2734 Make_Identifier (Loc, Name_uI)),
2736 Make_Identifier (Loc, Name_uA)))))); -- abort status
2739 pragma Assert (Is_Task_Type (Conc_Typ));
2743 -- System.Tasking.Rendezvous.Requeue_Protected_To_Task_Entry
2744 -- (Protection_Entries_Access (P),
2746 -- Task_Entry_Index (I),
2749 -- System.Tasking.Rendezvous.Requeue_Task_Entry
2751 -- Task_Entry_Index (I),
2756 Make_If_Statement (Loc,
2758 Make_Identifier (Loc, Name_uF),
2763 -- Call to Requeue_Protected_To_Task_Entry
2765 Make_Procedure_Call_Statement (Loc,
2768 RTE (RE_Requeue_Protected_To_Task_Entry), Loc),
2770 Parameter_Associations =>
2773 Make_Unchecked_Type_Conversion (Loc, -- PEA (P)
2776 RTE (RE_Protection_Entries_Access), Loc),
2778 Make_Identifier (Loc, Name_uP)),
2780 Make_Selected_Component (Loc, -- O._task_id
2782 Make_Identifier (Loc, Name_uO),
2784 Make_Identifier (Loc, Name_uTask_Id)),
2786 Make_Unchecked_Type_Conversion (Loc, -- entry index
2789 RTE (RE_Task_Entry_Index), Loc),
2791 Make_Identifier (Loc, Name_uI)),
2793 Make_Identifier (Loc, Name_uA)))), -- abort status
2798 -- Call to Requeue_Task_Entry
2800 Make_Procedure_Call_Statement (Loc,
2802 New_Reference_To (RTE (RE_Requeue_Task_Entry), Loc),
2804 Parameter_Associations =>
2807 Make_Selected_Component (Loc, -- O._task_id
2809 Make_Identifier (Loc, Name_uO),
2811 Make_Identifier (Loc, Name_uTask_Id)),
2813 Make_Unchecked_Type_Conversion (Loc, -- entry index
2816 RTE (RE_Task_Entry_Index), Loc),
2818 Make_Identifier (Loc, Name_uI)),
2820 Make_Identifier (Loc, Name_uA)))))); -- abort status
2823 -- Even though no declarations are needed in both cases, we allocate
2824 -- a list for entities added by Freeze.
2827 Make_Subprogram_Body (Loc,
2829 Make_Disp_Requeue_Spec (Typ),
2832 Handled_Statement_Sequence =>
2833 Make_Handled_Sequence_Of_Statements (Loc, Stmts));
2834 end Make_Disp_Requeue_Body;
2836 ----------------------------
2837 -- Make_Disp_Requeue_Spec --
2838 ----------------------------
2840 function Make_Disp_Requeue_Spec
2841 (Typ : Entity_Id) return Node_Id
2843 Loc : constant Source_Ptr := Sloc (Typ);
2846 pragma Assert (not Restriction_Active (No_Dispatching_Calls));
2848 -- O : in out Typ; - Object parameter
2849 -- F : Boolean; - Protected (True) / task (False) flag
2850 -- P : Address; - Protection_Entries_Access value
2851 -- I : Entry_Index - Index of entry call
2852 -- A : Boolean - Abort flag
2854 -- Note that the Protection_Entries_Access value is represented as a
2855 -- System.Address in order to avoid dragging in the tasking runtime
2856 -- when compiling sources without tasking constructs.
2859 Make_Procedure_Specification (Loc,
2860 Defining_Unit_Name =>
2861 Make_Defining_Identifier (Loc, Name_uDisp_Requeue),
2863 Parameter_Specifications =>
2866 Make_Parameter_Specification (Loc, -- O
2867 Defining_Identifier =>
2868 Make_Defining_Identifier (Loc, Name_uO),
2870 New_Reference_To (Typ, Loc),
2872 Out_Present => True),
2874 Make_Parameter_Specification (Loc, -- F
2875 Defining_Identifier =>
2876 Make_Defining_Identifier (Loc, Name_uF),
2878 New_Reference_To (Standard_Boolean, Loc)),
2880 Make_Parameter_Specification (Loc, -- P
2881 Defining_Identifier =>
2882 Make_Defining_Identifier (Loc, Name_uP),
2884 New_Reference_To (RTE (RE_Address), Loc)),
2886 Make_Parameter_Specification (Loc, -- I
2887 Defining_Identifier =>
2888 Make_Defining_Identifier (Loc, Name_uI),
2890 New_Reference_To (Standard_Integer, Loc)),
2892 Make_Parameter_Specification (Loc, -- A
2893 Defining_Identifier =>
2894 Make_Defining_Identifier (Loc, Name_uA),
2896 New_Reference_To (Standard_Boolean, Loc))));
2897 end Make_Disp_Requeue_Spec;
2899 ---------------------------------
2900 -- Make_Disp_Timed_Select_Body --
2901 ---------------------------------
2903 -- For interface types, generate:
2905 -- procedure _Disp_Timed_Select
2906 -- (T : in out <Typ>;
2908 -- P : System.Address;
2911 -- C : out Ada.Tags.Prim_Op_Kind;
2916 -- end _Disp_Timed_Select;
2918 -- For protected types, generate:
2920 -- procedure _Disp_Timed_Select
2921 -- (T : in out <Typ>;
2923 -- P : System.Address;
2926 -- C : out Ada.Tags.Prim_Op_Kind;
2932 -- C := Ada.Tags.Get_Prim_Op_Kind (Ada.Tags.Tag (<Typ>VP), S);
2934 -- if C = Ada.Tags.POK_Procedure
2935 -- or else C = Ada.Tags.POK_Protected_Procedure
2936 -- or else C = Ada.Tags.POK_Task_Procedure
2942 -- I := Ada.Tags.Get_Entry_Index (Ada.Tags.Tag (<Typ>VP), S);
2943 -- System.Tasking.Protected_Objects.Operations.
2944 -- Timed_Protected_Entry_Call
2945 -- (T._object'Access,
2946 -- System.Tasking.Protected_Objects.Protected_Entry_Index (I),
2951 -- end _Disp_Timed_Select;
2953 -- For task types, generate:
2955 -- procedure _Disp_Timed_Select
2956 -- (T : in out <Typ>;
2958 -- P : System.Address;
2961 -- C : out Ada.Tags.Prim_Op_Kind;
2967 -- I := Ada.Tags.Get_Entry_Index (Ada.Tags.Tag (<Typ>VP), S);
2968 -- System.Tasking.Rendezvous.Timed_Task_Entry_Call
2970 -- System.Tasking.Task_Entry_Index (I),
2975 -- end _Disp_Time_Select;
2977 function Make_Disp_Timed_Select_Body
2978 (Typ : Entity_Id) return Node_Id
2980 Loc : constant Source_Ptr := Sloc (Typ);
2981 Conc_Typ : Entity_Id := Empty;
2982 Decls : constant List_Id := New_List;
2985 Stmts : constant List_Id := New_List;
2988 pragma Assert (not Restriction_Active (No_Dispatching_Calls));
2990 -- Null body is generated for interface types
2992 if Is_Interface (Typ) then
2994 Make_Subprogram_Body (Loc,
2996 Make_Disp_Timed_Select_Spec (Typ),
2999 Handled_Statement_Sequence =>
3000 Make_Handled_Sequence_Of_Statements (Loc,
3001 New_List (Make_Null_Statement (Loc))));
3004 DT_Ptr := Node (First_Elmt (Access_Disp_Table (Typ)));
3006 if Is_Concurrent_Record_Type (Typ) then
3007 Conc_Typ := Corresponding_Concurrent_Type (Typ);
3012 -- where I will be used to capture the entry index of the primitive
3013 -- wrapper at position S.
3016 Make_Object_Declaration (Loc,
3017 Defining_Identifier =>
3018 Make_Defining_Identifier (Loc, Name_uI),
3019 Object_Definition =>
3020 New_Reference_To (Standard_Integer, Loc)));
3023 -- C := Get_Prim_Op_Kind (tag! (<type>VP), S);
3025 -- if C = POK_Procedure
3026 -- or else C = POK_Protected_Procedure
3027 -- or else C = POK_Task_Procedure;
3033 Build_Common_Dispatching_Select_Statements (Loc, DT_Ptr, Stmts);
3036 -- I := Get_Entry_Index (tag! (<type>VP), S);
3038 -- I is the entry index and S is the dispatch table slot
3041 Make_Assignment_Statement (Loc,
3043 Make_Identifier (Loc, Name_uI),
3045 Make_Function_Call (Loc,
3047 New_Reference_To (RTE (RE_Get_Entry_Index), Loc),
3048 Parameter_Associations =>
3050 Unchecked_Convert_To (RTE (RE_Tag),
3051 New_Reference_To (DT_Ptr, Loc)),
3052 Make_Identifier (Loc, Name_uS)))));
3056 if Ekind (Conc_Typ) = E_Protected_Type then
3058 -- Build T._object'Access
3061 Make_Attribute_Reference (Loc,
3062 Attribute_Name => Name_Unchecked_Access,
3064 Make_Selected_Component (Loc,
3065 Prefix => Make_Identifier (Loc, Name_uT),
3066 Selector_Name => Make_Identifier (Loc, Name_uObject)));
3068 -- Normal case, No_Entry_Queue restriction not active. In this
3069 -- case we generate:
3071 -- Timed_Protected_Entry_Call
3072 -- (T._object'access,
3073 -- Protected_Entry_Index! (I),
3076 -- where T is the protected object, I is the entry index, P are
3077 -- the wrapped parameters, D is the delay amount, M is the delay
3078 -- mode and F is the status flag.
3080 case Corresponding_Runtime_Package (Conc_Typ) is
3081 when System_Tasking_Protected_Objects_Entries =>
3083 Make_Procedure_Call_Statement (Loc,
3086 (RTE (RE_Timed_Protected_Entry_Call), Loc),
3087 Parameter_Associations =>
3091 Make_Unchecked_Type_Conversion (Loc, -- entry index
3094 (RTE (RE_Protected_Entry_Index), Loc),
3096 Make_Identifier (Loc, Name_uI)),
3098 Make_Identifier (Loc, Name_uP), -- parameter block
3099 Make_Identifier (Loc, Name_uD), -- delay
3100 Make_Identifier (Loc, Name_uM), -- delay mode
3101 Make_Identifier (Loc, Name_uF)))); -- status flag
3103 when System_Tasking_Protected_Objects_Single_Entry =>
3106 -- Timed_Protected_Single_Entry_Call
3107 -- (T._object'access, P, D, M, F);
3109 -- where T is the protected object, P is the wrapped
3110 -- parameters, D is the delay amount, M is the delay mode, F
3111 -- is the status flag.
3114 Make_Procedure_Call_Statement (Loc,
3117 (RTE (RE_Timed_Protected_Single_Entry_Call), Loc),
3118 Parameter_Associations =>
3121 Make_Identifier (Loc, Name_uP), -- parameter block
3122 Make_Identifier (Loc, Name_uD), -- delay
3123 Make_Identifier (Loc, Name_uM), -- delay mode
3124 Make_Identifier (Loc, Name_uF)))); -- status flag
3127 raise Program_Error;
3133 pragma Assert (Ekind (Conc_Typ) = E_Task_Type);
3136 -- Timed_Task_Entry_Call (
3138 -- Task_Entry_Index! (I),
3144 -- where T is the task object, I is the entry index, P are the
3145 -- wrapped parameters, D is the delay amount, M is the delay
3146 -- mode and F is the status flag.
3149 Make_Procedure_Call_Statement (Loc,
3151 New_Reference_To (RTE (RE_Timed_Task_Entry_Call), Loc),
3152 Parameter_Associations =>
3155 Make_Selected_Component (Loc, -- T._task_id
3157 Make_Identifier (Loc, Name_uT),
3159 Make_Identifier (Loc, Name_uTask_Id)),
3161 Make_Unchecked_Type_Conversion (Loc, -- entry index
3163 New_Reference_To (RTE (RE_Task_Entry_Index), Loc),
3165 Make_Identifier (Loc, Name_uI)),
3167 Make_Identifier (Loc, Name_uP), -- parameter block
3168 Make_Identifier (Loc, Name_uD), -- delay
3169 Make_Identifier (Loc, Name_uM), -- delay mode
3170 Make_Identifier (Loc, Name_uF)))); -- status flag
3174 -- Ensure that the statements list is non-empty
3176 Append_To (Stmts, Make_Null_Statement (Loc));
3180 Make_Subprogram_Body (Loc,
3182 Make_Disp_Timed_Select_Spec (Typ),
3185 Handled_Statement_Sequence =>
3186 Make_Handled_Sequence_Of_Statements (Loc, Stmts));
3187 end Make_Disp_Timed_Select_Body;
3189 ---------------------------------
3190 -- Make_Disp_Timed_Select_Spec --
3191 ---------------------------------
3193 function Make_Disp_Timed_Select_Spec
3194 (Typ : Entity_Id) return Node_Id
3196 Loc : constant Source_Ptr := Sloc (Typ);
3197 Def_Id : constant Node_Id :=
3198 Make_Defining_Identifier (Loc,
3199 Name_uDisp_Timed_Select);
3200 Params : constant List_Id := New_List;
3203 pragma Assert (not Restriction_Active (No_Dispatching_Calls));
3205 -- T : in out Typ; -- Object parameter
3206 -- S : Integer; -- Primitive operation slot
3207 -- P : Address; -- Wrapped parameters
3208 -- D : Duration; -- Delay
3209 -- M : Integer; -- Delay Mode
3210 -- C : out Prim_Op_Kind; -- Call kind
3211 -- F : out Boolean; -- Status flag
3213 Append_List_To (Params, New_List (
3215 Make_Parameter_Specification (Loc,
3216 Defining_Identifier =>
3217 Make_Defining_Identifier (Loc, Name_uT),
3219 New_Reference_To (Typ, Loc),
3221 Out_Present => True),
3223 Make_Parameter_Specification (Loc,
3224 Defining_Identifier =>
3225 Make_Defining_Identifier (Loc, Name_uS),
3227 New_Reference_To (Standard_Integer, Loc)),
3229 Make_Parameter_Specification (Loc,
3230 Defining_Identifier =>
3231 Make_Defining_Identifier (Loc, Name_uP),
3233 New_Reference_To (RTE (RE_Address), Loc)),
3235 Make_Parameter_Specification (Loc,
3236 Defining_Identifier =>
3237 Make_Defining_Identifier (Loc, Name_uD),
3239 New_Reference_To (Standard_Duration, Loc)),
3241 Make_Parameter_Specification (Loc,
3242 Defining_Identifier =>
3243 Make_Defining_Identifier (Loc, Name_uM),
3245 New_Reference_To (Standard_Integer, Loc)),
3247 Make_Parameter_Specification (Loc,
3248 Defining_Identifier =>
3249 Make_Defining_Identifier (Loc, Name_uC),
3251 New_Reference_To (RTE (RE_Prim_Op_Kind), Loc),
3252 Out_Present => True)));
3255 Make_Parameter_Specification (Loc,
3256 Defining_Identifier =>
3257 Make_Defining_Identifier (Loc, Name_uF),
3259 New_Reference_To (Standard_Boolean, Loc),
3260 Out_Present => True));
3263 Make_Procedure_Specification (Loc,
3264 Defining_Unit_Name => Def_Id,
3265 Parameter_Specifications => Params);
3266 end Make_Disp_Timed_Select_Spec;
3272 -- The frontend supports two models for expanding dispatch tables
3273 -- associated with library-level defined tagged types: statically
3274 -- and non-statically allocated dispatch tables. In the former case
3275 -- the object containing the dispatch table is constant and it is
3276 -- initialized by means of a positional aggregate. In the latter case,
3277 -- the object containing the dispatch table is a variable which is
3278 -- initialized by means of assignments.
3280 -- In case of locally defined tagged types, the object containing the
3281 -- object containing the dispatch table is always a variable (instead
3282 -- of a constant). This is currently required to give support to late
3283 -- overriding of primitives. For example:
3285 -- procedure Example is
3287 -- type T1 is tagged null record;
3288 -- procedure Prim (O : T1);
3291 -- type T2 is new Pkg.T1 with null record;
3292 -- procedure Prim (X : T2) is -- late overriding
3298 function Make_DT (Typ : Entity_Id; N : Node_Id := Empty) return List_Id is
3299 Loc : constant Source_Ptr := Sloc (Typ);
3301 Max_Predef_Prims : constant Int :=
3305 (Parent (RTE (RE_Max_Predef_Prims)))));
3307 DT_Decl : constant Elist_Id := New_Elmt_List;
3308 DT_Aggr : constant Elist_Id := New_Elmt_List;
3309 -- Entities marked with attribute Is_Dispatch_Table_Entity
3311 procedure Check_Premature_Freezing (Subp : Entity_Id; Typ : Entity_Id);
3312 -- Verify that all non-tagged types in the profile of a subprogram
3313 -- are frozen at the point the subprogram is frozen. This enforces
3314 -- the rule on RM 13.14 (14) as modified by AI05-019. At the point a
3315 -- subprogram is frozen, enough must be known about it to build the
3316 -- activation record for it, which requires at least that the size of
3317 -- all parameters be known. Controlling arguments are by-reference,
3318 -- and therefore the rule only applies to non-tagged types.
3319 -- Typical violation of the rule involves an object declaration that
3320 -- freezes a tagged type, when one of its primitive operations has a
3321 -- type in its profile whose full view has not been analyzed yet.
3323 procedure Export_DT (Typ : Entity_Id; DT : Entity_Id; Index : Nat := 0);
3324 -- Export the dispatch table DT of tagged type Typ. Required to generate
3325 -- forward references and statically allocate the table. For primary
3326 -- dispatch tables Index is 0; for secondary dispatch tables the value
3327 -- of index must match the Suffix_Index value assigned to the table by
3328 -- Make_Tags when generating its unique external name, and it is used to
3329 -- retrieve from the Dispatch_Table_Wrappers list associated with Typ
3330 -- the external name generated by Import_DT.
3332 procedure Make_Secondary_DT
3336 Num_Iface_Prims : Nat;
3337 Iface_DT_Ptr : Entity_Id;
3338 Predef_Prims_Ptr : Entity_Id;
3339 Build_Thunks : Boolean;
3341 -- Ada 2005 (AI-251): Expand the declarations for a Secondary Dispatch
3342 -- Table of Typ associated with Iface. Each abstract interface of Typ
3343 -- has two secondary dispatch tables: one containing pointers to thunks
3344 -- and another containing pointers to the primitives covering the
3345 -- interface primitives. The former secondary table is generated when
3346 -- Build_Thunks is True, and provides common support for dispatching
3347 -- calls through interface types; the latter secondary table is
3348 -- generated when Build_Thunks is False, and provides support for
3349 -- Generic Dispatching Constructors that dispatch calls through
3350 -- interface types. When constructing this latter table the value
3351 -- of Suffix_Index is -1 to indicate that there is no need to export
3352 -- such table when building statically allocated dispatch tables; a
3353 -- positive value of Suffix_Index must match the Suffix_Index value
3354 -- assigned to this secondary dispatch table by Make_Tags when its
3355 -- unique external name was generated.
3357 ------------------------------
3358 -- Check_Premature_Freezing --
3359 ------------------------------
3361 procedure Check_Premature_Freezing (Subp : Entity_Id; Typ : Entity_Id) is
3364 and then Is_Private_Type (Typ)
3365 and then No (Full_View (Typ))
3366 and then not Is_Generic_Type (Typ)
3367 and then not Is_Tagged_Type (Typ)
3368 and then not Is_Frozen (Typ)
3370 Error_Msg_Sloc := Sloc (Subp);
3372 ("declaration must appear after completion of type &", N, Typ);
3374 ("\which is an untagged type in the profile of"
3375 & " primitive operation & declared#",
3378 end Check_Premature_Freezing;
3384 procedure Export_DT (Typ : Entity_Id; DT : Entity_Id; Index : Nat := 0)
3390 Set_Is_Statically_Allocated (DT);
3391 Set_Is_True_Constant (DT);
3392 Set_Is_Exported (DT);
3395 Elmt := First_Elmt (Dispatch_Table_Wrappers (Typ));
3396 while Count /= Index loop
3401 pragma Assert (Related_Type (Node (Elmt)) = Typ);
3404 (Entity => Node (Elmt),
3405 Has_Suffix => True);
3407 Set_Interface_Name (DT,
3408 Make_String_Literal (Loc,
3409 Strval => String_From_Name_Buffer));
3411 -- Ensure proper Sprint output of this implicit importation
3413 Set_Is_Internal (DT);
3417 -----------------------
3418 -- Make_Secondary_DT --
3419 -----------------------
3421 procedure Make_Secondary_DT
3425 Num_Iface_Prims : Nat;
3426 Iface_DT_Ptr : Entity_Id;
3427 Predef_Prims_Ptr : Entity_Id;
3428 Build_Thunks : Boolean;
3431 Loc : constant Source_Ptr := Sloc (Typ);
3432 Exporting_Table : constant Boolean :=
3433 Building_Static_DT (Typ)
3434 and then Suffix_Index > 0;
3435 Iface_DT : constant Entity_Id :=
3436 Make_Defining_Identifier (Loc,
3437 Chars => New_Internal_Name ('T'));
3438 Name_Predef_Prims : constant Name_Id := New_Internal_Name ('R');
3439 Predef_Prims : constant Entity_Id :=
3440 Make_Defining_Identifier (Loc,
3441 Chars => Name_Predef_Prims);
3442 DT_Constr_List : List_Id;
3443 DT_Aggr_List : List_Id;
3444 Empty_DT : Boolean := False;
3445 Nb_Predef_Prims : Nat := 0;
3449 OSD_Aggr_List : List_Id;
3452 Prim_Elmt : Elmt_Id;
3453 Prim_Ops_Aggr_List : List_Id;
3456 -- Handle cases in which we do not generate statically allocated
3459 if not Building_Static_DT (Typ) then
3460 Set_Ekind (Predef_Prims, E_Variable);
3461 Set_Ekind (Iface_DT, E_Variable);
3463 -- Statically allocated dispatch tables and related entities are
3467 Set_Ekind (Predef_Prims, E_Constant);
3468 Set_Is_Statically_Allocated (Predef_Prims);
3469 Set_Is_True_Constant (Predef_Prims);
3471 Set_Ekind (Iface_DT, E_Constant);
3472 Set_Is_Statically_Allocated (Iface_DT);
3473 Set_Is_True_Constant (Iface_DT);
3476 -- Calculate the number of slots of the dispatch table. If the number
3477 -- of primitives of Typ is 0 we reserve a dummy single entry for its
3478 -- DT because at run-time the pointer to this dummy entry will be
3481 if Num_Iface_Prims = 0 then
3485 Nb_Prim := Num_Iface_Prims;
3490 -- Predef_Prims : Address_Array (1 .. Default_Prim_Ops_Count) :=
3491 -- (predef-prim-op-thunk-1'address,
3492 -- predef-prim-op-thunk-2'address,
3494 -- predef-prim-op-thunk-n'address);
3495 -- for Predef_Prims'Alignment use Address'Alignment
3497 -- Stage 1: Calculate the number of predefined primitives
3499 if not Building_Static_DT (Typ) then
3500 Nb_Predef_Prims := Max_Predef_Prims;
3502 Prim_Elmt := First_Elmt (Primitive_Operations (Typ));
3503 while Present (Prim_Elmt) loop
3504 Prim := Node (Prim_Elmt);
3506 if Is_Predefined_Dispatching_Operation (Prim)
3507 and then not Is_Abstract_Subprogram (Prim)
3509 Pos := UI_To_Int (DT_Position (Prim));
3511 if Pos > Nb_Predef_Prims then
3512 Nb_Predef_Prims := Pos;
3516 Next_Elmt (Prim_Elmt);
3520 -- Stage 2: Create the thunks associated with the predefined
3521 -- primitives and save their entity to fill the aggregate.
3524 Prim_Table : array (Nat range 1 .. Nb_Predef_Prims) of Entity_Id;
3526 Thunk_Id : Entity_Id;
3527 Thunk_Code : Node_Id;
3530 Prim_Ops_Aggr_List := New_List;
3531 Prim_Table := (others => Empty);
3533 if Building_Static_DT (Typ) then
3534 Prim_Elmt := First_Elmt (Primitive_Operations (Typ));
3535 while Present (Prim_Elmt) loop
3536 Prim := Node (Prim_Elmt);
3538 if Is_Predefined_Dispatching_Operation (Prim)
3539 and then not Is_Abstract_Subprogram (Prim)
3540 and then not Present (Prim_Table
3541 (UI_To_Int (DT_Position (Prim))))
3543 if not Build_Thunks then
3544 Prim_Table (UI_To_Int (DT_Position (Prim))) :=
3548 while Present (Alias (Prim)) loop
3549 Prim := Alias (Prim);
3552 Expand_Interface_Thunk (Prim, Thunk_Id, Thunk_Code);
3554 if Present (Thunk_Id) then
3555 Append_To (Result, Thunk_Code);
3556 Prim_Table (UI_To_Int (DT_Position (Prim)))
3562 Next_Elmt (Prim_Elmt);
3566 for J in Prim_Table'Range loop
3567 if Present (Prim_Table (J)) then
3569 Unchecked_Convert_To (RTE (RE_Prim_Ptr),
3570 Make_Attribute_Reference (Loc,
3571 Prefix => New_Reference_To (Prim_Table (J), Loc),
3572 Attribute_Name => Name_Unrestricted_Access));
3574 New_Node := Make_Null (Loc);
3577 Append_To (Prim_Ops_Aggr_List, New_Node);
3581 Make_Aggregate (Loc,
3582 Expressions => Prim_Ops_Aggr_List);
3584 -- Remember aggregates initializing dispatch tables
3586 Append_Elmt (New_Node, DT_Aggr);
3589 Make_Subtype_Declaration (Loc,
3590 Defining_Identifier =>
3591 Make_Defining_Identifier (Loc,
3592 New_Internal_Name ('S')),
3593 Subtype_Indication =>
3594 New_Reference_To (RTE (RE_Address_Array), Loc));
3596 Append_To (Result, Decl);
3599 Make_Object_Declaration (Loc,
3600 Defining_Identifier => Predef_Prims,
3601 Constant_Present => Building_Static_DT (Typ),
3602 Aliased_Present => True,
3603 Object_Definition => New_Reference_To
3604 (Defining_Identifier (Decl), Loc),
3605 Expression => New_Node));
3608 Make_Attribute_Definition_Clause (Loc,
3609 Name => New_Reference_To (Predef_Prims, Loc),
3610 Chars => Name_Alignment,
3612 Make_Attribute_Reference (Loc,
3614 New_Reference_To (RTE (RE_Integer_Address), Loc),
3615 Attribute_Name => Name_Alignment)));
3620 -- OSD : Ada.Tags.Object_Specific_Data (Nb_Prims) :=
3621 -- (OSD_Table => (1 => <value>,
3625 -- Iface_DT : Dispatch_Table (Nb_Prims) :=
3626 -- ([ Signature => <sig-value> ],
3627 -- Tag_Kind => <tag_kind-value>,
3628 -- Predef_Prims => Predef_Prims'Address,
3629 -- Offset_To_Top => 0,
3630 -- OSD => OSD'Address,
3631 -- Prims_Ptr => (prim-op-1'address,
3632 -- prim-op-2'address,
3634 -- prim-op-n'address));
3635 -- for Iface_DT'Alignment use Address'Alignment;
3637 -- Stage 3: Initialize the discriminant and the record components
3639 DT_Constr_List := New_List;
3640 DT_Aggr_List := New_List;
3642 -- Nb_Prim. If the tagged type has no primitives we add a dummy
3643 -- slot whose address will be the tag of this type.
3646 New_Node := Make_Integer_Literal (Loc, 1);
3648 New_Node := Make_Integer_Literal (Loc, Nb_Prim);
3651 Append_To (DT_Constr_List, New_Node);
3652 Append_To (DT_Aggr_List, New_Copy (New_Node));
3656 if RTE_Record_Component_Available (RE_Signature) then
3657 Append_To (DT_Aggr_List,
3658 New_Reference_To (RTE (RE_Secondary_DT), Loc));
3663 if RTE_Record_Component_Available (RE_Tag_Kind) then
3664 Append_To (DT_Aggr_List, Tagged_Kind (Typ));
3669 Append_To (DT_Aggr_List,
3670 Make_Attribute_Reference (Loc,
3671 Prefix => New_Reference_To (Predef_Prims, Loc),
3672 Attribute_Name => Name_Address));
3674 -- Note: The correct value of Offset_To_Top will be set by the init
3677 Append_To (DT_Aggr_List, Make_Integer_Literal (Loc, 0));
3679 -- Generate the Object Specific Data table required to dispatch calls
3680 -- through synchronized interfaces.
3683 or else Is_Abstract_Type (Typ)
3684 or else Is_Controlled (Typ)
3685 or else Restriction_Active (No_Dispatching_Calls)
3686 or else not Is_Limited_Type (Typ)
3687 or else not Has_Interfaces (Typ)
3688 or else not Build_Thunks
3689 or else not RTE_Record_Component_Available (RE_OSD_Table)
3691 -- No OSD table required
3693 Append_To (DT_Aggr_List,
3694 New_Reference_To (RTE (RE_Null_Address), Loc));
3697 OSD_Aggr_List := New_List;
3700 Prim_Table : array (Nat range 1 .. Nb_Prim) of Entity_Id;
3702 Prim_Alias : Entity_Id;
3703 Prim_Elmt : Elmt_Id;
3709 Prim_Table := (others => Empty);
3710 Prim_Alias := Empty;
3712 Prim_Elmt := First_Elmt (Primitive_Operations (Typ));
3713 while Present (Prim_Elmt) loop
3714 Prim := Node (Prim_Elmt);
3716 if Present (Interface_Alias (Prim))
3717 and then Find_Dispatching_Type
3718 (Interface_Alias (Prim)) = Iface
3720 Prim_Alias := Interface_Alias (Prim);
3723 while Present (Alias (E)) loop
3727 Pos := UI_To_Int (DT_Position (Prim_Alias));
3729 if Present (Prim_Table (Pos)) then
3730 pragma Assert (Prim_Table (Pos) = E);
3734 Prim_Table (Pos) := E;
3736 Append_To (OSD_Aggr_List,
3737 Make_Component_Association (Loc,
3738 Choices => New_List (
3739 Make_Integer_Literal (Loc,
3740 DT_Position (Prim_Alias))),
3742 Make_Integer_Literal (Loc,
3743 DT_Position (Alias (Prim)))));
3749 Next_Elmt (Prim_Elmt);
3751 pragma Assert (Count = Nb_Prim);
3754 OSD := Make_Defining_Identifier (Loc, New_Internal_Name ('I'));
3757 Make_Object_Declaration (Loc,
3758 Defining_Identifier => OSD,
3759 Object_Definition =>
3760 Make_Subtype_Indication (Loc,
3762 New_Reference_To (RTE (RE_Object_Specific_Data), Loc),
3764 Make_Index_Or_Discriminant_Constraint (Loc,
3765 Constraints => New_List (
3766 Make_Integer_Literal (Loc, Nb_Prim)))),
3767 Expression => Make_Aggregate (Loc,
3768 Component_Associations => New_List (
3769 Make_Component_Association (Loc,
3770 Choices => New_List (
3772 (RTE_Record_Component (RE_OSD_Num_Prims), Loc)),
3774 Make_Integer_Literal (Loc, Nb_Prim)),
3776 Make_Component_Association (Loc,
3777 Choices => New_List (
3779 (RTE_Record_Component (RE_OSD_Table), Loc)),
3780 Expression => Make_Aggregate (Loc,
3781 Component_Associations => OSD_Aggr_List))))));
3784 Make_Attribute_Definition_Clause (Loc,
3785 Name => New_Reference_To (OSD, Loc),
3786 Chars => Name_Alignment,
3788 Make_Attribute_Reference (Loc,
3790 New_Reference_To (RTE (RE_Integer_Address), Loc),
3791 Attribute_Name => Name_Alignment)));
3793 -- In secondary dispatch tables the Typeinfo component contains
3794 -- the address of the Object Specific Data (see a-tags.ads)
3796 Append_To (DT_Aggr_List,
3797 Make_Attribute_Reference (Loc,
3798 Prefix => New_Reference_To (OSD, Loc),
3799 Attribute_Name => Name_Address));
3802 -- Initialize the table of primitive operations
3804 Prim_Ops_Aggr_List := New_List;
3807 Append_To (Prim_Ops_Aggr_List, Make_Null (Loc));
3809 elsif Is_Abstract_Type (Typ)
3810 or else not Building_Static_DT (Typ)
3812 for J in 1 .. Nb_Prim loop
3813 Append_To (Prim_Ops_Aggr_List, Make_Null (Loc));
3818 Prim_Table : array (Nat range 1 .. Nb_Prim) of Entity_Id;
3820 Thunk_Code : Node_Id;
3821 Thunk_Id : Entity_Id;
3824 Prim_Table := (others => Empty);
3826 Prim_Elmt := First_Elmt (Primitive_Operations (Typ));
3827 while Present (Prim_Elmt) loop
3828 Prim := Node (Prim_Elmt);
3830 if not Is_Predefined_Dispatching_Operation (Prim)
3831 and then Present (Interface_Alias (Prim))
3832 and then not Is_Abstract_Subprogram (Alias (Prim))
3833 and then not Is_Imported (Alias (Prim))
3834 and then Find_Dispatching_Type
3835 (Interface_Alias (Prim)) = Iface
3837 -- Generate the code of the thunk only if the abstract
3838 -- interface type is not an immediate ancestor of
3839 -- Tagged_Type; otherwise the DT associated with the
3840 -- interface is the primary DT.
3842 and then not Is_Ancestor (Iface, Typ)
3844 if not Build_Thunks then
3846 UI_To_Int (DT_Position (Interface_Alias (Prim)));
3847 Prim_Table (Pos) := Alias (Prim);
3849 Expand_Interface_Thunk (Prim, Thunk_Id, Thunk_Code);
3851 if Present (Thunk_Id) then
3853 UI_To_Int (DT_Position (Interface_Alias (Prim)));
3855 Prim_Table (Pos) := Thunk_Id;
3856 Append_To (Result, Thunk_Code);
3861 Next_Elmt (Prim_Elmt);
3864 for J in Prim_Table'Range loop
3865 if Present (Prim_Table (J)) then
3867 Unchecked_Convert_To (RTE (RE_Prim_Ptr),
3868 Make_Attribute_Reference (Loc,
3869 Prefix => New_Reference_To (Prim_Table (J), Loc),
3870 Attribute_Name => Name_Unrestricted_Access));
3872 New_Node := Make_Null (Loc);
3875 Append_To (Prim_Ops_Aggr_List, New_Node);
3881 Make_Aggregate (Loc,
3882 Expressions => Prim_Ops_Aggr_List);
3884 Append_To (DT_Aggr_List, New_Node);
3886 -- Remember aggregates initializing dispatch tables
3888 Append_Elmt (New_Node, DT_Aggr);
3890 -- Note: Secondary dispatch tables cannot be declared constant
3891 -- because the component Offset_To_Top is currently initialized
3892 -- by the IP routine.
3895 Make_Object_Declaration (Loc,
3896 Defining_Identifier => Iface_DT,
3897 Aliased_Present => True,
3898 Constant_Present => False,
3900 Object_Definition =>
3901 Make_Subtype_Indication (Loc,
3902 Subtype_Mark => New_Reference_To
3903 (RTE (RE_Dispatch_Table_Wrapper), Loc),
3904 Constraint => Make_Index_Or_Discriminant_Constraint (Loc,
3905 Constraints => DT_Constr_List)),
3908 Make_Aggregate (Loc,
3909 Expressions => DT_Aggr_List)));
3912 Make_Attribute_Definition_Clause (Loc,
3913 Name => New_Reference_To (Iface_DT, Loc),
3914 Chars => Name_Alignment,
3917 Make_Attribute_Reference (Loc,
3919 New_Reference_To (RTE (RE_Integer_Address), Loc),
3920 Attribute_Name => Name_Alignment)));
3922 if Exporting_Table then
3923 Export_DT (Typ, Iface_DT, Suffix_Index);
3925 -- Generate code to create the pointer to the dispatch table
3927 -- Iface_DT_Ptr : Tag := Tag!(DT.Prims_Ptr'Address);
3929 -- Note: This declaration is not added here if the table is exported
3930 -- because in such case Make_Tags has already added this declaration.
3934 Make_Object_Declaration (Loc,
3935 Defining_Identifier => Iface_DT_Ptr,
3936 Constant_Present => True,
3938 Object_Definition =>
3939 New_Reference_To (RTE (RE_Interface_Tag), Loc),
3942 Unchecked_Convert_To (RTE (RE_Interface_Tag),
3943 Make_Attribute_Reference (Loc,
3945 Make_Selected_Component (Loc,
3946 Prefix => New_Reference_To (Iface_DT, Loc),
3949 (RTE_Record_Component (RE_Prims_Ptr), Loc)),
3950 Attribute_Name => Name_Address))));
3954 Make_Object_Declaration (Loc,
3955 Defining_Identifier => Predef_Prims_Ptr,
3956 Constant_Present => True,
3958 Object_Definition =>
3959 New_Reference_To (RTE (RE_Address), Loc),
3962 Make_Attribute_Reference (Loc,
3964 Make_Selected_Component (Loc,
3965 Prefix => New_Reference_To (Iface_DT, Loc),
3968 (RTE_Record_Component (RE_Predef_Prims), Loc)),
3969 Attribute_Name => Name_Address)));
3971 -- Remember entities containing dispatch tables
3973 Append_Elmt (Predef_Prims, DT_Decl);
3974 Append_Elmt (Iface_DT, DT_Decl);
3975 end Make_Secondary_DT;
3979 Elab_Code : constant List_Id := New_List;
3980 Result : constant List_Id := New_List;
3981 Tname : constant Name_Id := Chars (Typ);
3983 AI_Tag_Elmt : Elmt_Id;
3984 AI_Tag_Comp : Elmt_Id;
3985 DT_Aggr_List : List_Id;
3986 DT_Constr_List : List_Id;
3990 Iface_Table_Node : Node_Id;
3991 Name_ITable : Name_Id;
3992 Nb_Predef_Prims : Nat := 0;
3995 Num_Ifaces : Nat := 0;
3996 Parent_Typ : Entity_Id;
3998 Prim_Elmt : Elmt_Id;
3999 Prim_Ops_Aggr_List : List_Id;
4001 Typ_Comps : Elist_Id;
4002 Typ_Ifaces : Elist_Id;
4003 TSD_Aggr_List : List_Id;
4004 TSD_Tags_List : List_Id;
4006 -- The following name entries are used by Make_DT to generate a number
4007 -- of entities related to a tagged type. These entities may be generated
4008 -- in a scope other than that of the tagged type declaration, and if
4009 -- the entities for two tagged types with the same name happen to be
4010 -- generated in the same scope, we have to take care to use different
4011 -- names. This is achieved by means of a unique serial number appended
4012 -- to each generated entity name.
4014 Name_DT : constant Name_Id :=
4015 New_External_Name (Tname, 'T', Suffix_Index => -1);
4016 Name_Exname : constant Name_Id :=
4017 New_External_Name (Tname, 'E', Suffix_Index => -1);
4018 Name_HT_Link : constant Name_Id :=
4019 New_External_Name (Tname, 'H', Suffix_Index => -1);
4020 Name_Predef_Prims : constant Name_Id :=
4021 New_External_Name (Tname, 'R', Suffix_Index => -1);
4022 Name_SSD : constant Name_Id :=
4023 New_External_Name (Tname, 'S', Suffix_Index => -1);
4024 Name_TSD : constant Name_Id :=
4025 New_External_Name (Tname, 'B', Suffix_Index => -1);
4027 -- Entities built with above names
4029 DT : constant Entity_Id :=
4030 Make_Defining_Identifier (Loc, Name_DT);
4031 Exname : constant Entity_Id :=
4032 Make_Defining_Identifier (Loc, Name_Exname);
4033 HT_Link : constant Entity_Id :=
4034 Make_Defining_Identifier (Loc, Name_HT_Link);
4035 Predef_Prims : constant Entity_Id :=
4036 Make_Defining_Identifier (Loc, Name_Predef_Prims);
4037 SSD : constant Entity_Id :=
4038 Make_Defining_Identifier (Loc, Name_SSD);
4039 TSD : constant Entity_Id :=
4040 Make_Defining_Identifier (Loc, Name_TSD);
4042 -- Start of processing for Make_DT
4045 pragma Assert (Is_Frozen (Typ));
4047 -- Handle cases in which there is no need to build the dispatch table
4049 if Has_Dispatch_Table (Typ)
4050 or else No (Access_Disp_Table (Typ))
4051 or else Is_CPP_Class (Typ)
4055 elsif No_Run_Time_Mode then
4056 Error_Msg_CRT ("tagged types", Typ);
4059 elsif not RTE_Available (RE_Tag) then
4061 Make_Object_Declaration (Loc,
4062 Defining_Identifier => Node (First_Elmt
4063 (Access_Disp_Table (Typ))),
4064 Object_Definition => New_Reference_To (RTE (RE_Tag), Loc),
4065 Constant_Present => True,
4067 Unchecked_Convert_To (RTE (RE_Tag),
4068 New_Reference_To (RTE (RE_Null_Address), Loc))));
4070 Analyze_List (Result, Suppress => All_Checks);
4071 Error_Msg_CRT ("tagged types", Typ);
4075 -- Ensure that the value of Max_Predef_Prims defined in a-tags is
4076 -- correct. Valid values are 10 under configurable runtime or 16
4077 -- with full runtime.
4079 if RTE_Available (RE_Interface_Data) then
4080 if Max_Predef_Prims /= 16 then
4081 Error_Msg_N ("run-time library configuration error", Typ);
4085 if Max_Predef_Prims /= 10 then
4086 Error_Msg_N ("run-time library configuration error", Typ);
4087 Error_Msg_CRT ("tagged types", Typ);
4092 -- Initialize Parent_Typ handling private types
4094 Parent_Typ := Etype (Typ);
4096 if Present (Full_View (Parent_Typ)) then
4097 Parent_Typ := Full_View (Parent_Typ);
4100 -- Ensure that all the primitives are frozen. This is only required when
4101 -- building static dispatch tables --- the primitives must be frozen to
4102 -- be referenced (otherwise we have problems with the backend). It is
4103 -- not a requirement with nonstatic dispatch tables because in this case
4104 -- we generate now an empty dispatch table; the extra code required to
4105 -- register the primitives in the slots will be generated later --- when
4106 -- each primitive is frozen (see Freeze_Subprogram).
4108 if Building_Static_DT (Typ)
4109 and then not Is_CPP_Class (Typ)
4112 Save : constant Boolean := Freezing_Library_Level_Tagged_Type;
4114 Prim_Elmt : Elmt_Id;
4118 Freezing_Library_Level_Tagged_Type := True;
4120 Prim_Elmt := First_Elmt (Primitive_Operations (Typ));
4121 while Present (Prim_Elmt) loop
4122 Prim := Node (Prim_Elmt);
4123 Frnodes := Freeze_Entity (Prim, Loc);
4129 F := First_Formal (Prim);
4130 while Present (F) loop
4131 Check_Premature_Freezing (Prim, Etype (F));
4135 Check_Premature_Freezing (Prim, Etype (Prim));
4138 if Present (Frnodes) then
4139 Append_List_To (Result, Frnodes);
4142 Next_Elmt (Prim_Elmt);
4145 Freezing_Library_Level_Tagged_Type := Save;
4149 -- Ada 2005 (AI-251): Build the secondary dispatch tables
4151 if Has_Interfaces (Typ) then
4152 Collect_Interface_Components (Typ, Typ_Comps);
4154 -- Each secondary dispatch table is assigned an unique positive
4155 -- suffix index; such value also corresponds with the location of
4156 -- its entity in the Dispatch_Table_Wrappers list (see Make_Tags).
4158 -- Note: This value must be kept sync with the Suffix_Index values
4159 -- generated by Make_Tags
4163 Next_Elmt (Next_Elmt (First_Elmt (Access_Disp_Table (Typ))));
4165 AI_Tag_Comp := First_Elmt (Typ_Comps);
4166 while Present (AI_Tag_Comp) loop
4168 -- Build the secondary table containing pointers to thunks
4172 Iface => Base_Type (Related_Type (Node (AI_Tag_Comp))),
4173 Suffix_Index => Suffix_Index,
4174 Num_Iface_Prims => UI_To_Int
4175 (DT_Entry_Count (Node (AI_Tag_Comp))),
4176 Iface_DT_Ptr => Node (AI_Tag_Elmt),
4177 Predef_Prims_Ptr => Node (Next_Elmt (AI_Tag_Elmt)),
4178 Build_Thunks => True,
4181 -- Skip secondary dispatch table and secondary dispatch table of
4182 -- predefined primitives
4184 Next_Elmt (AI_Tag_Elmt);
4185 Next_Elmt (AI_Tag_Elmt);
4187 -- Build the secondary table containing pointers to primitives
4188 -- (used to give support to Generic Dispatching Constructors).
4192 Iface => Base_Type (Related_Type (Node (AI_Tag_Comp))),
4194 Num_Iface_Prims => UI_To_Int
4195 (DT_Entry_Count (Node (AI_Tag_Comp))),
4196 Iface_DT_Ptr => Node (AI_Tag_Elmt),
4197 Predef_Prims_Ptr => Node (Next_Elmt (AI_Tag_Elmt)),
4198 Build_Thunks => False,
4201 -- Skip secondary dispatch table and secondary dispatch table of
4202 -- predefined primitives
4204 Next_Elmt (AI_Tag_Elmt);
4205 Next_Elmt (AI_Tag_Elmt);
4207 Suffix_Index := Suffix_Index + 1;
4208 Next_Elmt (AI_Tag_Comp);
4212 -- Get the _tag entity and the number of primitives of its dispatch
4215 DT_Ptr := Node (First_Elmt (Access_Disp_Table (Typ)));
4216 Nb_Prim := UI_To_Int (DT_Entry_Count (First_Tag_Component (Typ)));
4218 Set_Is_Statically_Allocated (DT, Is_Library_Level_Tagged_Type (Typ));
4219 Set_Is_Statically_Allocated (SSD, Is_Library_Level_Tagged_Type (Typ));
4220 Set_Is_Statically_Allocated (TSD, Is_Library_Level_Tagged_Type (Typ));
4221 Set_Is_Statically_Allocated (Predef_Prims,
4222 Is_Library_Level_Tagged_Type (Typ));
4224 -- In case of locally defined tagged type we declare the object
4225 -- containing the dispatch table by means of a variable. Its
4226 -- initialization is done later by means of an assignment. This is
4227 -- required to generate its External_Tag.
4229 if not Building_Static_DT (Typ) then
4232 -- DT : No_Dispatch_Table_Wrapper;
4233 -- for DT'Alignment use Address'Alignment;
4234 -- DT_Ptr : Tag := !Tag (DT.NDT_Prims_Ptr'Address);
4236 if not Has_DT (Typ) then
4238 Make_Object_Declaration (Loc,
4239 Defining_Identifier => DT,
4240 Aliased_Present => True,
4241 Constant_Present => False,
4242 Object_Definition =>
4244 (RTE (RE_No_Dispatch_Table_Wrapper), Loc)));
4246 -- Generate a SCIL node for the previous object declaration
4247 -- because it has a null dispatch table.
4249 if Generate_SCIL then
4250 Insert_Before (Last (Result),
4252 (Nkind => Dispatch_Table_Object_Init,
4253 Related_Node => Last (Result),
4258 Make_Attribute_Definition_Clause (Loc,
4259 Name => New_Reference_To (DT, Loc),
4260 Chars => Name_Alignment,
4262 Make_Attribute_Reference (Loc,
4264 New_Reference_To (RTE (RE_Integer_Address), Loc),
4265 Attribute_Name => Name_Alignment)));
4268 Make_Object_Declaration (Loc,
4269 Defining_Identifier => DT_Ptr,
4270 Object_Definition => New_Reference_To (RTE (RE_Tag), Loc),
4271 Constant_Present => True,
4273 Unchecked_Convert_To (RTE (RE_Tag),
4274 Make_Attribute_Reference (Loc,
4276 Make_Selected_Component (Loc,
4277 Prefix => New_Reference_To (DT, Loc),
4280 (RTE_Record_Component (RE_NDT_Prims_Ptr), Loc)),
4281 Attribute_Name => Name_Address))));
4283 -- Generate the SCIL node for the previous object declaration
4284 -- because it has a tag initialization.
4286 if Generate_SCIL then
4287 Insert_Before (Last (Result),
4289 (Nkind => Dispatch_Table_Tag_Init,
4290 Related_Node => Last (Result),
4295 -- DT : Dispatch_Table_Wrapper (Nb_Prim);
4296 -- for DT'Alignment use Address'Alignment;
4297 -- DT_Ptr : Tag := !Tag (DT.Prims_Ptr'Address);
4300 -- If the tagged type has no primitives we add a dummy slot
4301 -- whose address will be the tag of this type.
4305 New_List (Make_Integer_Literal (Loc, 1));
4308 New_List (Make_Integer_Literal (Loc, Nb_Prim));
4312 Make_Object_Declaration (Loc,
4313 Defining_Identifier => DT,
4314 Aliased_Present => True,
4315 Constant_Present => False,
4316 Object_Definition =>
4317 Make_Subtype_Indication (Loc,
4319 New_Reference_To (RTE (RE_Dispatch_Table_Wrapper), Loc),
4320 Constraint => Make_Index_Or_Discriminant_Constraint (Loc,
4321 Constraints => DT_Constr_List))));
4323 -- Generate the SCIL node for the previous object declaration
4324 -- because it contains a dispatch table.
4326 if Generate_SCIL then
4327 Insert_Before (Last (Result),
4329 (Nkind => Dispatch_Table_Object_Init,
4330 Related_Node => Last (Result),
4335 Make_Attribute_Definition_Clause (Loc,
4336 Name => New_Reference_To (DT, Loc),
4337 Chars => Name_Alignment,
4339 Make_Attribute_Reference (Loc,
4341 New_Reference_To (RTE (RE_Integer_Address), Loc),
4342 Attribute_Name => Name_Alignment)));
4345 Make_Object_Declaration (Loc,
4346 Defining_Identifier => DT_Ptr,
4347 Object_Definition => New_Reference_To (RTE (RE_Tag), Loc),
4348 Constant_Present => True,
4350 Unchecked_Convert_To (RTE (RE_Tag),
4351 Make_Attribute_Reference (Loc,
4353 Make_Selected_Component (Loc,
4354 Prefix => New_Reference_To (DT, Loc),
4357 (RTE_Record_Component (RE_Prims_Ptr), Loc)),
4358 Attribute_Name => Name_Address))));
4360 -- Generate the SCIL node for the previous object declaration
4361 -- because it has a tag initialization.
4363 if Generate_SCIL then
4364 Insert_Before (Last (Result),
4366 (Nkind => Dispatch_Table_Tag_Init,
4367 Related_Node => Last (Result),
4372 Make_Object_Declaration (Loc,
4373 Defining_Identifier =>
4374 Node (Next_Elmt (First_Elmt (Access_Disp_Table (Typ)))),
4375 Constant_Present => True,
4376 Object_Definition => New_Reference_To
4377 (RTE (RE_Address), Loc),
4379 Make_Attribute_Reference (Loc,
4381 Make_Selected_Component (Loc,
4382 Prefix => New_Reference_To (DT, Loc),
4385 (RTE_Record_Component (RE_Predef_Prims), Loc)),
4386 Attribute_Name => Name_Address)));
4390 -- Generate: Exname : constant String := full_qualified_name (typ);
4391 -- The type itself may be an anonymous parent type, so use the first
4392 -- subtype to have a user-recognizable name.
4395 Make_Object_Declaration (Loc,
4396 Defining_Identifier => Exname,
4397 Constant_Present => True,
4398 Object_Definition => New_Reference_To (Standard_String, Loc),
4400 Make_String_Literal (Loc,
4401 Full_Qualified_Name (First_Subtype (Typ)))));
4403 Set_Is_Statically_Allocated (Exname);
4404 Set_Is_True_Constant (Exname);
4406 -- Declare the object used by Ada.Tags.Register_Tag
4408 if RTE_Available (RE_Register_Tag) then
4410 Make_Object_Declaration (Loc,
4411 Defining_Identifier => HT_Link,
4412 Object_Definition => New_Reference_To (RTE (RE_Tag), Loc)));
4415 -- Generate code to create the storage for the type specific data object
4416 -- with enough space to store the tags of the ancestors plus the tags
4417 -- of all the implemented interfaces (as described in a-tags.adb).
4419 -- TSD : Type_Specific_Data (I_Depth) :=
4420 -- (Idepth => I_Depth,
4421 -- Access_Level => Type_Access_Level (Typ),
4422 -- Expanded_Name => Cstring_Ptr!(Exname'Address))
4423 -- External_Tag => Cstring_Ptr!(Exname'Address))
4424 -- HT_Link => HT_Link'Address,
4425 -- Transportable => <<boolean-value>>,
4426 -- RC_Offset => <<integer-value>>,
4427 -- [ Size_Func => Size_Prim'Access ]
4428 -- [ Interfaces_Table => <<access-value>> ]
4429 -- [ SSD => SSD_Table'Address ]
4430 -- Tags_Table => (0 => null,
4433 -- for TSD'Alignment use Address'Alignment
4435 TSD_Aggr_List := New_List;
4437 -- Idepth: Count ancestors to compute the inheritance depth. For private
4438 -- extensions, always go to the full view in order to compute the real
4439 -- inheritance depth.
4442 Current_Typ : Entity_Id;
4443 Parent_Typ : Entity_Id;
4449 Parent_Typ := Etype (Current_Typ);
4451 if Is_Private_Type (Parent_Typ) then
4452 Parent_Typ := Full_View (Base_Type (Parent_Typ));
4455 exit when Parent_Typ = Current_Typ;
4457 I_Depth := I_Depth + 1;
4458 Current_Typ := Parent_Typ;
4462 Append_To (TSD_Aggr_List,
4463 Make_Integer_Literal (Loc, I_Depth));
4467 Append_To (TSD_Aggr_List,
4468 Make_Integer_Literal (Loc, Type_Access_Level (Typ)));
4472 Append_To (TSD_Aggr_List,
4473 Unchecked_Convert_To (RTE (RE_Cstring_Ptr),
4474 Make_Attribute_Reference (Loc,
4475 Prefix => New_Reference_To (Exname, Loc),
4476 Attribute_Name => Name_Address)));
4478 -- External_Tag of a local tagged type
4480 -- <typ>A : constant String :=
4481 -- "Internal tag at 16#tag-addr#: <full-name-of-typ>";
4483 -- The reason we generate this strange name is that we do not want to
4484 -- enter local tagged types in the global hash table used to compute
4485 -- the Internal_Tag attribute for two reasons:
4487 -- 1. It is hard to avoid a tasking race condition for entering the
4488 -- entry into the hash table.
4490 -- 2. It would cause a storage leak, unless we rig up considerable
4491 -- mechanism to remove the entry from the hash table on exit.
4493 -- So what we do is to generate the above external tag name, where the
4494 -- hex address is the address of the local dispatch table (i.e. exactly
4495 -- the value we want if Internal_Tag is computed from this string).
4497 -- Of course this value will only be valid if the tagged type is still
4498 -- in scope, but it clearly must be erroneous to compute the internal
4499 -- tag of a tagged type that is out of scope!
4501 -- We don't do this processing if an explicit external tag has been
4502 -- specified. That's an odd case for which we have already issued a
4503 -- warning, where we will not be able to compute the internal tag.
4505 if not Is_Library_Level_Entity (Typ)
4506 and then not Has_External_Tag_Rep_Clause (Typ)
4509 Exname : constant Entity_Id :=
4510 Make_Defining_Identifier (Loc,
4511 New_External_Name (Tname, 'A'));
4513 Full_Name : constant String_Id :=
4514 Full_Qualified_Name (First_Subtype (Typ));
4515 Str1_Id : String_Id;
4516 Str2_Id : String_Id;
4520 -- Str1 = "Internal tag at 16#";
4523 Store_String_Chars ("Internal tag at 16#");
4524 Str1_Id := End_String;
4527 -- Str2 = "#: <type-full-name>";
4530 Store_String_Chars ("#: ");
4531 Store_String_Chars (Full_Name);
4532 Str2_Id := End_String;
4535 -- Exname : constant String :=
4536 -- Str1 & Address_Image (Tag) & Str2;
4538 if RTE_Available (RE_Address_Image) then
4540 Make_Object_Declaration (Loc,
4541 Defining_Identifier => Exname,
4542 Constant_Present => True,
4543 Object_Definition => New_Reference_To
4544 (Standard_String, Loc),
4546 Make_Op_Concat (Loc,
4548 Make_String_Literal (Loc, Str1_Id),
4550 Make_Op_Concat (Loc,
4552 Make_Function_Call (Loc,
4555 (RTE (RE_Address_Image), Loc),
4556 Parameter_Associations => New_List (
4557 Unchecked_Convert_To (RTE (RE_Address),
4558 New_Reference_To (DT_Ptr, Loc)))),
4560 Make_String_Literal (Loc, Str2_Id)))));
4564 Make_Object_Declaration (Loc,
4565 Defining_Identifier => Exname,
4566 Constant_Present => True,
4567 Object_Definition => New_Reference_To
4568 (Standard_String, Loc),
4570 Make_Op_Concat (Loc,
4572 Make_String_Literal (Loc, Str1_Id),
4574 Make_String_Literal (Loc, Str2_Id))));
4578 Unchecked_Convert_To (RTE (RE_Cstring_Ptr),
4579 Make_Attribute_Reference (Loc,
4580 Prefix => New_Reference_To (Exname, Loc),
4581 Attribute_Name => Name_Address));
4584 -- External tag of a library-level tagged type: Check for a definition
4585 -- of External_Tag. The clause is considered only if it applies to this
4586 -- specific tagged type, as opposed to one of its ancestors.
4587 -- If the type is an unconstrained type extension, we are building the
4588 -- dispatch table of its anonymous base type, so the external tag, if
4589 -- any was specified, must be retrieved from the first subtype. Go to
4590 -- the full view in case the clause is in the private part.
4594 Def : constant Node_Id := Get_Attribute_Definition_Clause
4595 (Underlying_Type (First_Subtype (Typ)),
4596 Attribute_External_Tag);
4598 Old_Val : String_Id;
4599 New_Val : String_Id;
4603 if not Present (Def)
4604 or else Entity (Name (Def)) /= First_Subtype (Typ)
4607 Unchecked_Convert_To (RTE (RE_Cstring_Ptr),
4608 Make_Attribute_Reference (Loc,
4609 Prefix => New_Reference_To (Exname, Loc),
4610 Attribute_Name => Name_Address));
4612 Old_Val := Strval (Expr_Value_S (Expression (Def)));
4614 -- For the rep clause "for <typ>'external_tag use y" generate:
4616 -- <typ>A : constant string := y;
4618 -- <typ>A'Address is used to set the External_Tag component
4621 -- Create a new nul terminated string if it is not already
4623 if String_Length (Old_Val) > 0
4625 Get_String_Char (Old_Val, String_Length (Old_Val)) = 0
4629 Start_String (Old_Val);
4630 Store_String_Char (Get_Char_Code (ASCII.NUL));
4631 New_Val := End_String;
4634 E := Make_Defining_Identifier (Loc,
4635 New_External_Name (Chars (Typ), 'A'));
4638 Make_Object_Declaration (Loc,
4639 Defining_Identifier => E,
4640 Constant_Present => True,
4641 Object_Definition =>
4642 New_Reference_To (Standard_String, Loc),
4644 Make_String_Literal (Loc, New_Val)));
4647 Unchecked_Convert_To (RTE (RE_Cstring_Ptr),
4648 Make_Attribute_Reference (Loc,
4649 Prefix => New_Reference_To (E, Loc),
4650 Attribute_Name => Name_Address));
4655 Append_To (TSD_Aggr_List, New_Node);
4659 if RTE_Available (RE_Register_Tag) then
4660 Append_To (TSD_Aggr_List,
4661 Unchecked_Convert_To (RTE (RE_Tag_Ptr),
4662 Make_Attribute_Reference (Loc,
4663 Prefix => New_Reference_To (HT_Link, Loc),
4664 Attribute_Name => Name_Address)));
4666 Append_To (TSD_Aggr_List,
4667 Unchecked_Convert_To (RTE (RE_Tag_Ptr),
4668 New_Reference_To (RTE (RE_Null_Address), Loc)));
4671 -- Transportable: Set for types that can be used in remote calls
4672 -- with respect to E.4(18) legality rules.
4675 Transportable : Entity_Id;
4681 or else Is_Shared_Passive (Typ)
4683 ((Is_Remote_Types (Typ)
4684 or else Is_Remote_Call_Interface (Typ))
4685 and then Original_View_In_Visible_Part (Typ))
4686 or else not Comes_From_Source (Typ));
4688 Append_To (TSD_Aggr_List,
4689 New_Occurrence_Of (Transportable, Loc));
4692 -- RC_Offset: These are the valid values and their meaning:
4694 -- >0: For simple types with controlled components is
4695 -- type._record_controller'position
4697 -- 0: For types with no controlled components
4699 -- -1: For complex types with controlled components where the position
4700 -- of the record controller is not statically computable but there
4701 -- are controlled components at this level. The _Controller field
4702 -- is available right after the _parent.
4704 -- -2: There are no controlled components at this level. We need to
4705 -- get the position from the parent.
4708 RC_Offset_Node : Node_Id;
4711 if not Has_Controlled_Component (Typ) then
4712 RC_Offset_Node := Make_Integer_Literal (Loc, 0);
4714 elsif Etype (Typ) /= Typ
4715 and then Has_Discriminants (Parent_Typ)
4717 if Has_New_Controlled_Component (Typ) then
4718 RC_Offset_Node := Make_Integer_Literal (Loc, -1);
4720 RC_Offset_Node := Make_Integer_Literal (Loc, -2);
4724 Make_Attribute_Reference (Loc,
4726 Make_Selected_Component (Loc,
4727 Prefix => New_Reference_To (Typ, Loc),
4729 New_Reference_To (Controller_Component (Typ), Loc)),
4730 Attribute_Name => Name_Position);
4732 -- This is not proper Ada code to use the attribute 'Position
4733 -- on something else than an object but this is supported by
4734 -- the back end (see comment on the Bit_Component attribute in
4735 -- sem_attr). So we avoid semantic checking here.
4737 -- Is this documented in sinfo.ads??? it should be!
4739 Set_Analyzed (RC_Offset_Node);
4740 Set_Etype (Prefix (RC_Offset_Node), RTE (RE_Record_Controller));
4741 Set_Etype (Prefix (Prefix (RC_Offset_Node)), Typ);
4742 Set_Etype (Selector_Name (Prefix (RC_Offset_Node)),
4743 RTE (RE_Record_Controller));
4744 Set_Etype (RC_Offset_Node, RTE (RE_Storage_Offset));
4747 Append_To (TSD_Aggr_List, RC_Offset_Node);
4752 if RTE_Record_Component_Available (RE_Size_Func) then
4753 if not Building_Static_DT (Typ)
4754 or else Is_Interface (Typ)
4756 Append_To (TSD_Aggr_List,
4757 Unchecked_Convert_To (RTE (RE_Size_Ptr),
4758 New_Reference_To (RTE (RE_Null_Address), Loc)));
4762 Prim_Elmt : Elmt_Id;
4766 Prim_Elmt := First_Elmt (Primitive_Operations (Typ));
4767 while Present (Prim_Elmt) loop
4768 Prim := Node (Prim_Elmt);
4770 if Chars (Prim) = Name_uSize then
4771 while Present (Alias (Prim)) loop
4772 Prim := Alias (Prim);
4775 if Is_Abstract_Subprogram (Prim) then
4776 Append_To (TSD_Aggr_List,
4777 Unchecked_Convert_To (RTE (RE_Size_Ptr),
4778 New_Reference_To (RTE (RE_Null_Address), Loc)));
4780 Append_To (TSD_Aggr_List,
4781 Unchecked_Convert_To (RTE (RE_Size_Ptr),
4782 Make_Attribute_Reference (Loc,
4783 Prefix => New_Reference_To (Prim, Loc),
4784 Attribute_Name => Name_Unrestricted_Access)));
4790 Next_Elmt (Prim_Elmt);
4796 -- Interfaces_Table (required for AI-405)
4798 if RTE_Record_Component_Available (RE_Interfaces_Table) then
4800 -- Count the number of interface types implemented by Typ
4802 Collect_Interfaces (Typ, Typ_Ifaces);
4804 AI := First_Elmt (Typ_Ifaces);
4805 while Present (AI) loop
4806 Num_Ifaces := Num_Ifaces + 1;
4810 if Num_Ifaces = 0 then
4811 Iface_Table_Node := Make_Null (Loc);
4813 -- Generate the Interface_Table object
4817 TSD_Ifaces_List : constant List_Id := New_List;
4819 Sec_DT_Tag : Node_Id;
4822 AI := First_Elmt (Typ_Ifaces);
4823 while Present (AI) loop
4824 if Is_Ancestor (Node (AI), Typ) then
4826 New_Reference_To (DT_Ptr, Loc);
4830 (Next_Elmt (First_Elmt (Access_Disp_Table (Typ))));
4831 pragma Assert (Has_Thunks (Node (Elmt)));
4833 while Ekind (Node (Elmt)) = E_Constant
4835 Is_Ancestor (Node (AI), Related_Type (Node (Elmt)))
4837 pragma Assert (Has_Thunks (Node (Elmt)));
4839 pragma Assert (Has_Thunks (Node (Elmt)));
4841 pragma Assert (not Has_Thunks (Node (Elmt)));
4843 pragma Assert (not Has_Thunks (Node (Elmt)));
4847 pragma Assert (Ekind (Node (Elmt)) = E_Constant
4849 Has_Thunks (Node (Next_Elmt (Next_Elmt (Elmt)))));
4851 New_Reference_To (Node (Next_Elmt (Next_Elmt (Elmt))),
4855 Append_To (TSD_Ifaces_List,
4856 Make_Aggregate (Loc,
4857 Expressions => New_List (
4861 Unchecked_Convert_To (RTE (RE_Tag),
4863 (Node (First_Elmt (Access_Disp_Table (Node (AI)))),
4866 -- Static_Offset_To_Top
4868 New_Reference_To (Standard_True, Loc),
4870 -- Offset_To_Top_Value
4872 Make_Integer_Literal (Loc, 0),
4874 -- Offset_To_Top_Func
4880 Unchecked_Convert_To (RTE (RE_Tag), Sec_DT_Tag)
4887 Name_ITable := New_External_Name (Tname, 'I');
4888 ITable := Make_Defining_Identifier (Loc, Name_ITable);
4889 Set_Is_Statically_Allocated (ITable,
4890 Is_Library_Level_Tagged_Type (Typ));
4892 -- The table of interfaces is not constant; its slots are
4893 -- filled at run-time by the IP routine using attribute
4894 -- 'Position to know the location of the tag components
4895 -- (and this attribute cannot be safely used before the
4896 -- object is initialized).
4899 Make_Object_Declaration (Loc,
4900 Defining_Identifier => ITable,
4901 Aliased_Present => True,
4902 Constant_Present => False,
4903 Object_Definition =>
4904 Make_Subtype_Indication (Loc,
4906 New_Reference_To (RTE (RE_Interface_Data), Loc),
4907 Constraint => Make_Index_Or_Discriminant_Constraint
4909 Constraints => New_List (
4910 Make_Integer_Literal (Loc, Num_Ifaces)))),
4912 Expression => Make_Aggregate (Loc,
4913 Expressions => New_List (
4914 Make_Integer_Literal (Loc, Num_Ifaces),
4915 Make_Aggregate (Loc,
4916 Expressions => TSD_Ifaces_List)))));
4919 Make_Attribute_Definition_Clause (Loc,
4920 Name => New_Reference_To (ITable, Loc),
4921 Chars => Name_Alignment,
4923 Make_Attribute_Reference (Loc,
4925 New_Reference_To (RTE (RE_Integer_Address), Loc),
4926 Attribute_Name => Name_Alignment)));
4929 Make_Attribute_Reference (Loc,
4930 Prefix => New_Reference_To (ITable, Loc),
4931 Attribute_Name => Name_Unchecked_Access);
4935 Append_To (TSD_Aggr_List, Iface_Table_Node);
4938 -- Generate the Select Specific Data table for synchronized types that
4939 -- implement synchronized interfaces. The size of the table is
4940 -- constrained by the number of non-predefined primitive operations.
4942 if RTE_Record_Component_Available (RE_SSD) then
4943 if Ada_Version >= Ada_05
4944 and then Has_DT (Typ)
4945 and then Is_Concurrent_Record_Type (Typ)
4946 and then Has_Interfaces (Typ)
4947 and then Nb_Prim > 0
4948 and then not Is_Abstract_Type (Typ)
4949 and then not Is_Controlled (Typ)
4950 and then not Restriction_Active (No_Dispatching_Calls)
4951 and then not Restriction_Active (No_Select_Statements)
4954 Make_Object_Declaration (Loc,
4955 Defining_Identifier => SSD,
4956 Aliased_Present => True,
4957 Object_Definition =>
4958 Make_Subtype_Indication (Loc,
4959 Subtype_Mark => New_Reference_To (
4960 RTE (RE_Select_Specific_Data), Loc),
4962 Make_Index_Or_Discriminant_Constraint (Loc,
4963 Constraints => New_List (
4964 Make_Integer_Literal (Loc, Nb_Prim))))));
4967 Make_Attribute_Definition_Clause (Loc,
4968 Name => New_Reference_To (SSD, Loc),
4969 Chars => Name_Alignment,
4971 Make_Attribute_Reference (Loc,
4973 New_Reference_To (RTE (RE_Integer_Address), Loc),
4974 Attribute_Name => Name_Alignment)));
4976 -- This table is initialized by Make_Select_Specific_Data_Table,
4977 -- which calls Set_Entry_Index and Set_Prim_Op_Kind.
4979 Append_To (TSD_Aggr_List,
4980 Make_Attribute_Reference (Loc,
4981 Prefix => New_Reference_To (SSD, Loc),
4982 Attribute_Name => Name_Unchecked_Access));
4984 Append_To (TSD_Aggr_List, Make_Null (Loc));
4988 -- Initialize the table of ancestor tags. In case of interface types
4989 -- this table is not needed.
4991 TSD_Tags_List := New_List;
4993 -- If we are not statically allocating the dispatch table then we must
4994 -- fill position 0 with null because we still have not generated the
4997 if not Building_Static_DT (Typ)
4998 or else Is_Interface (Typ)
5000 Append_To (TSD_Tags_List,
5001 Unchecked_Convert_To (RTE (RE_Tag),
5002 New_Reference_To (RTE (RE_Null_Address), Loc)));
5004 -- Otherwise we can safely reference the tag
5007 Append_To (TSD_Tags_List,
5008 New_Reference_To (DT_Ptr, Loc));
5011 -- Fill the rest of the table with the tags of the ancestors
5014 Current_Typ : Entity_Id;
5015 Parent_Typ : Entity_Id;
5023 Parent_Typ := Etype (Current_Typ);
5025 if Is_Private_Type (Parent_Typ) then
5026 Parent_Typ := Full_View (Base_Type (Parent_Typ));
5029 exit when Parent_Typ = Current_Typ;
5031 if Is_CPP_Class (Parent_Typ)
5032 or else Is_Interface (Typ)
5034 -- The tags defined in the C++ side will be inherited when
5035 -- the object is constructed (Exp_Ch3.Build_Init_Procedure)
5037 Append_To (TSD_Tags_List,
5038 Unchecked_Convert_To (RTE (RE_Tag),
5039 New_Reference_To (RTE (RE_Null_Address), Loc)));
5041 Append_To (TSD_Tags_List,
5043 (Node (First_Elmt (Access_Disp_Table (Parent_Typ))),
5048 Current_Typ := Parent_Typ;
5051 pragma Assert (Pos = I_Depth + 1);
5054 Append_To (TSD_Aggr_List,
5055 Make_Aggregate (Loc,
5056 Expressions => TSD_Tags_List));
5058 -- Build the TSD object
5061 Make_Object_Declaration (Loc,
5062 Defining_Identifier => TSD,
5063 Aliased_Present => True,
5064 Constant_Present => Building_Static_DT (Typ),
5065 Object_Definition =>
5066 Make_Subtype_Indication (Loc,
5067 Subtype_Mark => New_Reference_To (
5068 RTE (RE_Type_Specific_Data), Loc),
5070 Make_Index_Or_Discriminant_Constraint (Loc,
5071 Constraints => New_List (
5072 Make_Integer_Literal (Loc, I_Depth)))),
5074 Expression => Make_Aggregate (Loc,
5075 Expressions => TSD_Aggr_List)));
5077 Set_Is_True_Constant (TSD, Building_Static_DT (Typ));
5080 Make_Attribute_Definition_Clause (Loc,
5081 Name => New_Reference_To (TSD, Loc),
5082 Chars => Name_Alignment,
5084 Make_Attribute_Reference (Loc,
5085 Prefix => New_Reference_To (RTE (RE_Integer_Address), Loc),
5086 Attribute_Name => Name_Alignment)));
5088 -- Initialize or declare the dispatch table object
5090 if not Has_DT (Typ) then
5091 DT_Constr_List := New_List;
5092 DT_Aggr_List := New_List;
5097 Make_Attribute_Reference (Loc,
5098 Prefix => New_Reference_To (TSD, Loc),
5099 Attribute_Name => Name_Address);
5101 Append_To (DT_Constr_List, New_Node);
5102 Append_To (DT_Aggr_List, New_Copy (New_Node));
5103 Append_To (DT_Aggr_List, Make_Integer_Literal (Loc, 0));
5105 -- In case of locally defined tagged types we have already declared
5106 -- and uninitialized object for the dispatch table, which is now
5107 -- initialized by means of the following assignment:
5109 -- DT := (TSD'Address, 0);
5111 if not Building_Static_DT (Typ) then
5113 Make_Assignment_Statement (Loc,
5114 Name => New_Reference_To (DT, Loc),
5115 Expression => Make_Aggregate (Loc,
5116 Expressions => DT_Aggr_List)));
5118 -- In case of library level tagged types we declare and export now
5119 -- the constant object containing the dummy dispatch table. There
5120 -- is no need to declare the tag here because it has been previously
5121 -- declared by Make_Tags
5123 -- DT : aliased constant No_Dispatch_Table :=
5124 -- (NDT_TSD => TSD'Address;
5125 -- NDT_Prims_Ptr => 0);
5126 -- for DT'Alignment use Address'Alignment;
5130 Make_Object_Declaration (Loc,
5131 Defining_Identifier => DT,
5132 Aliased_Present => True,
5133 Constant_Present => True,
5134 Object_Definition =>
5135 New_Reference_To (RTE (RE_No_Dispatch_Table_Wrapper), Loc),
5136 Expression => Make_Aggregate (Loc,
5137 Expressions => DT_Aggr_List)));
5139 -- Generate the SCIL node for the previous object declaration
5140 -- because it has a null dispatch table.
5142 if Generate_SCIL then
5143 Insert_Before (Last (Result),
5145 (Nkind => Dispatch_Table_Object_Init,
5146 Related_Node => Last (Result),
5151 Make_Attribute_Definition_Clause (Loc,
5152 Name => New_Reference_To (DT, Loc),
5153 Chars => Name_Alignment,
5155 Make_Attribute_Reference (Loc,
5157 New_Reference_To (RTE (RE_Integer_Address), Loc),
5158 Attribute_Name => Name_Alignment)));
5160 Export_DT (Typ, DT);
5163 -- Common case: Typ has a dispatch table
5167 -- Predef_Prims : Address_Array (1 .. Default_Prim_Ops_Count) :=
5168 -- (predef-prim-op-1'address,
5169 -- predef-prim-op-2'address,
5171 -- predef-prim-op-n'address);
5172 -- for Predef_Prims'Alignment use Address'Alignment
5174 -- DT : Dispatch_Table (Nb_Prims) :=
5175 -- (Signature => <sig-value>,
5176 -- Tag_Kind => <tag_kind-value>,
5177 -- Predef_Prims => Predef_Prims'First'Address,
5178 -- Offset_To_Top => 0,
5179 -- TSD => TSD'Address;
5180 -- Prims_Ptr => (prim-op-1'address,
5181 -- prim-op-2'address,
5183 -- prim-op-n'address));
5184 -- for DT'Alignment use Address'Alignment
5191 if not Building_Static_DT (Typ) then
5192 Nb_Predef_Prims := Max_Predef_Prims;
5195 Prim_Elmt := First_Elmt (Primitive_Operations (Typ));
5196 while Present (Prim_Elmt) loop
5197 Prim := Node (Prim_Elmt);
5199 if Is_Predefined_Dispatching_Operation (Prim)
5200 and then not Is_Abstract_Subprogram (Prim)
5202 Pos := UI_To_Int (DT_Position (Prim));
5204 if Pos > Nb_Predef_Prims then
5205 Nb_Predef_Prims := Pos;
5209 Next_Elmt (Prim_Elmt);
5215 (Nat range 1 .. Nb_Predef_Prims) of Entity_Id;
5220 Prim_Ops_Aggr_List := New_List;
5222 Prim_Table := (others => Empty);
5224 if Building_Static_DT (Typ) then
5225 Prim_Elmt := First_Elmt (Primitive_Operations (Typ));
5226 while Present (Prim_Elmt) loop
5227 Prim := Node (Prim_Elmt);
5229 if Is_Predefined_Dispatching_Operation (Prim)
5230 and then not Is_Abstract_Subprogram (Prim)
5231 and then not Present (Prim_Table
5232 (UI_To_Int (DT_Position (Prim))))
5235 while Present (Alias (E)) loop
5239 pragma Assert (not Is_Abstract_Subprogram (E));
5240 Prim_Table (UI_To_Int (DT_Position (Prim))) := E;
5243 Next_Elmt (Prim_Elmt);
5247 for J in Prim_Table'Range loop
5248 if Present (Prim_Table (J)) then
5250 Unchecked_Convert_To (RTE (RE_Prim_Ptr),
5251 Make_Attribute_Reference (Loc,
5252 Prefix => New_Reference_To (Prim_Table (J), Loc),
5253 Attribute_Name => Name_Unrestricted_Access));
5255 New_Node := Make_Null (Loc);
5258 Append_To (Prim_Ops_Aggr_List, New_Node);
5262 Make_Aggregate (Loc,
5263 Expressions => Prim_Ops_Aggr_List);
5266 Make_Subtype_Declaration (Loc,
5267 Defining_Identifier =>
5268 Make_Defining_Identifier (Loc,
5269 New_Internal_Name ('S')),
5270 Subtype_Indication =>
5271 New_Reference_To (RTE (RE_Address_Array), Loc));
5273 Append_To (Result, Decl);
5276 Make_Object_Declaration (Loc,
5277 Defining_Identifier => Predef_Prims,
5278 Aliased_Present => True,
5279 Constant_Present => Building_Static_DT (Typ),
5280 Object_Definition => New_Reference_To
5281 (Defining_Identifier (Decl), Loc),
5282 Expression => New_Node));
5284 -- Remember aggregates initializing dispatch tables
5286 Append_Elmt (New_Node, DT_Aggr);
5289 Make_Attribute_Definition_Clause (Loc,
5290 Name => New_Reference_To (Predef_Prims, Loc),
5291 Chars => Name_Alignment,
5293 Make_Attribute_Reference (Loc,
5295 New_Reference_To (RTE (RE_Integer_Address), Loc),
5296 Attribute_Name => Name_Alignment)));
5300 -- Stage 1: Initialize the discriminant and the record components
5302 DT_Constr_List := New_List;
5303 DT_Aggr_List := New_List;
5305 -- Num_Prims. If the tagged type has no primitives we add a dummy
5306 -- slot whose address will be the tag of this type.
5309 New_Node := Make_Integer_Literal (Loc, 1);
5311 New_Node := Make_Integer_Literal (Loc, Nb_Prim);
5314 Append_To (DT_Constr_List, New_Node);
5315 Append_To (DT_Aggr_List, New_Copy (New_Node));
5319 if RTE_Record_Component_Available (RE_Signature) then
5320 Append_To (DT_Aggr_List,
5321 New_Reference_To (RTE (RE_Primary_DT), Loc));
5326 if RTE_Record_Component_Available (RE_Tag_Kind) then
5327 Append_To (DT_Aggr_List, Tagged_Kind (Typ));
5332 Append_To (DT_Aggr_List,
5333 Make_Attribute_Reference (Loc,
5334 Prefix => New_Reference_To (Predef_Prims, Loc),
5335 Attribute_Name => Name_Address));
5339 Append_To (DT_Aggr_List, Make_Integer_Literal (Loc, 0));
5343 Append_To (DT_Aggr_List,
5344 Make_Attribute_Reference (Loc,
5345 Prefix => New_Reference_To (TSD, Loc),
5346 Attribute_Name => Name_Address));
5348 -- Stage 2: Initialize the table of primitive operations
5350 Prim_Ops_Aggr_List := New_List;
5353 Append_To (Prim_Ops_Aggr_List, Make_Null (Loc));
5355 elsif not Building_Static_DT (Typ) then
5356 for J in 1 .. Nb_Prim loop
5357 Append_To (Prim_Ops_Aggr_List, Make_Null (Loc));
5362 Prim_Table : array (Nat range 1 .. Nb_Prim) of Entity_Id;
5365 Prim_Elmt : Elmt_Id;
5368 Prim_Table := (others => Empty);
5370 Prim_Elmt := First_Elmt (Primitive_Operations (Typ));
5371 while Present (Prim_Elmt) loop
5372 Prim := Node (Prim_Elmt);
5374 -- Retrieve the ultimate alias of the primitive for proper
5375 -- handling of renamings and eliminated primitives.
5377 E := Ultimate_Alias (Prim);
5379 if Is_Imported (Prim)
5380 or else Present (Interface_Alias (Prim))
5381 or else Is_Predefined_Dispatching_Operation (Prim)
5382 or else Is_Eliminated (E)
5387 if not Is_Predefined_Dispatching_Operation (E)
5388 and then not Is_Abstract_Subprogram (E)
5389 and then not Present (Interface_Alias (E))
5392 (UI_To_Int (DT_Position (Prim)) <= Nb_Prim);
5394 Prim_Table (UI_To_Int (DT_Position (Prim))) := E;
5398 Next_Elmt (Prim_Elmt);
5401 for J in Prim_Table'Range loop
5402 if Present (Prim_Table (J)) then
5404 Unchecked_Convert_To (RTE (RE_Prim_Ptr),
5405 Make_Attribute_Reference (Loc,
5406 Prefix => New_Reference_To (Prim_Table (J), Loc),
5407 Attribute_Name => Name_Unrestricted_Access));
5409 New_Node := Make_Null (Loc);
5412 Append_To (Prim_Ops_Aggr_List, New_Node);
5418 Make_Aggregate (Loc,
5419 Expressions => Prim_Ops_Aggr_List);
5421 Append_To (DT_Aggr_List, New_Node);
5423 -- Remember aggregates initializing dispatch tables
5425 Append_Elmt (New_Node, DT_Aggr);
5427 -- In case of locally defined tagged types we have already declared
5428 -- and uninitialized object for the dispatch table, which is now
5429 -- initialized by means of an assignment.
5431 if not Building_Static_DT (Typ) then
5433 Make_Assignment_Statement (Loc,
5434 Name => New_Reference_To (DT, Loc),
5435 Expression => Make_Aggregate (Loc,
5436 Expressions => DT_Aggr_List)));
5438 -- In case of library level tagged types we declare now and export
5439 -- the constant object containing the dispatch table.
5443 Make_Object_Declaration (Loc,
5444 Defining_Identifier => DT,
5445 Aliased_Present => True,
5446 Constant_Present => True,
5447 Object_Definition =>
5448 Make_Subtype_Indication (Loc,
5449 Subtype_Mark => New_Reference_To
5450 (RTE (RE_Dispatch_Table_Wrapper), Loc),
5451 Constraint => Make_Index_Or_Discriminant_Constraint (Loc,
5452 Constraints => DT_Constr_List)),
5453 Expression => Make_Aggregate (Loc,
5454 Expressions => DT_Aggr_List)));
5456 -- Generate the SCIL node for the previous object declaration
5457 -- because it contains a dispatch table.
5459 if Generate_SCIL then
5460 Insert_Before (Last (Result),
5462 (Nkind => Dispatch_Table_Object_Init,
5463 Related_Node => Last (Result),
5468 Make_Attribute_Definition_Clause (Loc,
5469 Name => New_Reference_To (DT, Loc),
5470 Chars => Name_Alignment,
5472 Make_Attribute_Reference (Loc,
5474 New_Reference_To (RTE (RE_Integer_Address), Loc),
5475 Attribute_Name => Name_Alignment)));
5477 Export_DT (Typ, DT);
5481 -- Initialize the table of ancestor tags if not building static
5484 if not Building_Static_DT (Typ)
5485 and then not Is_Interface (Typ)
5486 and then not Is_CPP_Class (Typ)
5489 Make_Assignment_Statement (Loc,
5491 Make_Indexed_Component (Loc,
5493 Make_Selected_Component (Loc,
5495 New_Reference_To (TSD, Loc),
5498 (RTE_Record_Component (RE_Tags_Table), Loc)),
5500 New_List (Make_Integer_Literal (Loc, 0))),
5504 (Node (First_Elmt (Access_Disp_Table (Typ))), Loc)));
5507 -- Inherit the dispatch tables of the parent. There is no need to
5508 -- inherit anything from the parent when building static dispatch tables
5509 -- because the whole dispatch table (including inherited primitives) has
5510 -- been already built.
5512 if Building_Static_DT (Typ) then
5515 -- If the ancestor is a CPP_Class type we inherit the dispatch tables
5516 -- in the init proc, and we don't need to fill them in here.
5518 elsif Is_CPP_Class (Parent_Typ) then
5521 -- Otherwise we fill in the dispatch tables here
5524 if Typ /= Parent_Typ
5525 and then not Is_Interface (Typ)
5526 and then not Restriction_Active (No_Dispatching_Calls)
5528 -- Inherit the dispatch table
5530 if not Is_Interface (Typ)
5531 and then not Is_Interface (Parent_Typ)
5532 and then not Is_CPP_Class (Parent_Typ)
5535 Nb_Prims : constant Int :=
5536 UI_To_Int (DT_Entry_Count
5537 (First_Tag_Component (Parent_Typ)));
5540 Append_To (Elab_Code,
5541 Build_Inherit_Predefined_Prims (Loc,
5547 (Access_Disp_Table (Parent_Typ)))), Loc),
5553 (Access_Disp_Table (Typ)))), Loc)));
5555 if Nb_Prims /= 0 then
5556 Append_To (Elab_Code,
5557 Build_Inherit_Prims (Loc,
5563 (Access_Disp_Table (Parent_Typ))), Loc),
5564 New_Tag_Node => New_Reference_To (DT_Ptr, Loc),
5565 Num_Prims => Nb_Prims));
5570 -- Inherit the secondary dispatch tables of the ancestor
5572 if not Is_CPP_Class (Parent_Typ) then
5574 Sec_DT_Ancestor : Elmt_Id :=
5578 (Access_Disp_Table (Parent_Typ))));
5579 Sec_DT_Typ : Elmt_Id :=
5583 (Access_Disp_Table (Typ))));
5585 procedure Copy_Secondary_DTs (Typ : Entity_Id);
5586 -- Local procedure required to climb through the ancestors
5587 -- and copy the contents of all their secondary dispatch
5590 ------------------------
5591 -- Copy_Secondary_DTs --
5592 ------------------------
5594 procedure Copy_Secondary_DTs (Typ : Entity_Id) is
5599 -- Climb to the ancestor (if any) handling private types
5601 if Present (Full_View (Etype (Typ))) then
5602 if Full_View (Etype (Typ)) /= Typ then
5603 Copy_Secondary_DTs (Full_View (Etype (Typ)));
5606 elsif Etype (Typ) /= Typ then
5607 Copy_Secondary_DTs (Etype (Typ));
5610 if Present (Interfaces (Typ))
5611 and then not Is_Empty_Elmt_List (Interfaces (Typ))
5613 Iface := First_Elmt (Interfaces (Typ));
5614 E := First_Entity (Typ);
5616 and then Present (Node (Sec_DT_Ancestor))
5617 and then Ekind (Node (Sec_DT_Ancestor)) = E_Constant
5619 if Is_Tag (E) and then Chars (E) /= Name_uTag then
5621 Num_Prims : constant Int :=
5622 UI_To_Int (DT_Entry_Count (E));
5625 if not Is_Interface (Etype (Typ)) then
5627 -- Inherit first secondary dispatch table
5629 Append_To (Elab_Code,
5630 Build_Inherit_Predefined_Prims (Loc,
5632 Unchecked_Convert_To (RTE (RE_Tag),
5635 (Next_Elmt (Sec_DT_Ancestor)),
5638 Unchecked_Convert_To (RTE (RE_Tag),
5640 (Node (Next_Elmt (Sec_DT_Typ)),
5643 if Num_Prims /= 0 then
5644 Append_To (Elab_Code,
5645 Build_Inherit_Prims (Loc,
5646 Typ => Node (Iface),
5648 Unchecked_Convert_To
5651 (Node (Sec_DT_Ancestor),
5654 Unchecked_Convert_To
5657 (Node (Sec_DT_Typ), Loc)),
5658 Num_Prims => Num_Prims));
5662 Next_Elmt (Sec_DT_Ancestor);
5663 Next_Elmt (Sec_DT_Typ);
5665 -- Skip the secondary dispatch table of
5666 -- predefined primitives
5668 Next_Elmt (Sec_DT_Ancestor);
5669 Next_Elmt (Sec_DT_Typ);
5671 if not Is_Interface (Etype (Typ)) then
5673 -- Inherit second secondary dispatch table
5675 Append_To (Elab_Code,
5676 Build_Inherit_Predefined_Prims (Loc,
5678 Unchecked_Convert_To (RTE (RE_Tag),
5681 (Next_Elmt (Sec_DT_Ancestor)),
5684 Unchecked_Convert_To (RTE (RE_Tag),
5686 (Node (Next_Elmt (Sec_DT_Typ)),
5689 if Num_Prims /= 0 then
5690 Append_To (Elab_Code,
5691 Build_Inherit_Prims (Loc,
5692 Typ => Node (Iface),
5694 Unchecked_Convert_To
5697 (Node (Sec_DT_Ancestor),
5700 Unchecked_Convert_To
5703 (Node (Sec_DT_Typ), Loc)),
5704 Num_Prims => Num_Prims));
5709 Next_Elmt (Sec_DT_Ancestor);
5710 Next_Elmt (Sec_DT_Typ);
5712 -- Skip the secondary dispatch table of
5713 -- predefined primitives
5715 Next_Elmt (Sec_DT_Ancestor);
5716 Next_Elmt (Sec_DT_Typ);
5724 end Copy_Secondary_DTs;
5727 if Present (Node (Sec_DT_Ancestor))
5728 and then Ekind (Node (Sec_DT_Ancestor)) = E_Constant
5730 -- Handle private types
5732 if Present (Full_View (Typ)) then
5733 Copy_Secondary_DTs (Full_View (Typ));
5735 Copy_Secondary_DTs (Typ);
5743 -- Generate code to register the Tag in the External_Tag hash table for
5744 -- the pure Ada type only.
5746 -- Register_Tag (Dt_Ptr);
5748 -- Skip this action in the following cases:
5749 -- 1) if Register_Tag is not available.
5750 -- 2) in No_Run_Time mode.
5751 -- 3) if Typ is not defined at the library level (this is required
5752 -- to avoid adding concurrency control to the hash table used
5753 -- by the run-time to register the tags).
5755 if not No_Run_Time_Mode
5756 and then Is_Library_Level_Entity (Typ)
5757 and then RTE_Available (RE_Register_Tag)
5759 Append_To (Elab_Code,
5760 Make_Procedure_Call_Statement (Loc,
5761 Name => New_Reference_To (RTE (RE_Register_Tag), Loc),
5762 Parameter_Associations =>
5763 New_List (New_Reference_To (DT_Ptr, Loc))));
5766 if not Is_Empty_List (Elab_Code) then
5767 Append_List_To (Result, Elab_Code);
5770 -- Populate the two auxiliary tables used for dispatching asynchronous,
5771 -- conditional and timed selects for synchronized types that implement
5772 -- a limited interface. Skip this step in Ravenscar profile or when
5773 -- general dispatching is forbidden.
5775 if Ada_Version >= Ada_05
5776 and then Is_Concurrent_Record_Type (Typ)
5777 and then Has_Interfaces (Typ)
5778 and then not Restriction_Active (No_Dispatching_Calls)
5779 and then not Restriction_Active (No_Select_Statements)
5781 Append_List_To (Result,
5782 Make_Select_Specific_Data_Table (Typ));
5785 -- Remember entities containing dispatch tables
5787 Append_Elmt (Predef_Prims, DT_Decl);
5788 Append_Elmt (DT, DT_Decl);
5790 Analyze_List (Result, Suppress => All_Checks);
5791 Set_Has_Dispatch_Table (Typ);
5793 -- Mark entities containing dispatch tables. Required by the backend to
5794 -- handle them properly.
5796 if not Is_Interface (Typ) then
5801 -- Ensure that entities Prim_Ptr and Predef_Prims_Table_Ptr have
5802 -- the decoration required by the backend
5804 Set_Is_Dispatch_Table_Entity (RTE (RE_Prim_Ptr));
5805 Set_Is_Dispatch_Table_Entity (RTE (RE_Predef_Prims_Table_Ptr));
5807 -- Object declarations
5809 Elmt := First_Elmt (DT_Decl);
5810 while Present (Elmt) loop
5811 Set_Is_Dispatch_Table_Entity (Node (Elmt));
5812 pragma Assert (Ekind (Etype (Node (Elmt))) = E_Array_Subtype
5813 or else Ekind (Etype (Node (Elmt))) = E_Record_Subtype);
5814 Set_Is_Dispatch_Table_Entity (Etype (Node (Elmt)));
5818 -- Aggregates initializing dispatch tables
5820 Elmt := First_Elmt (DT_Aggr);
5821 while Present (Elmt) loop
5822 Set_Is_Dispatch_Table_Entity (Etype (Node (Elmt)));
5831 -------------------------------------
5832 -- Make_Select_Specific_Data_Table --
5833 -------------------------------------
5835 function Make_Select_Specific_Data_Table
5836 (Typ : Entity_Id) return List_Id
5838 Assignments : constant List_Id := New_List;
5839 Loc : constant Source_Ptr := Sloc (Typ);
5841 Conc_Typ : Entity_Id;
5845 Prim_Als : Entity_Id;
5846 Prim_Elmt : Elmt_Id;
5850 type Examined_Array is array (Int range <>) of Boolean;
5852 function Find_Entry_Index (E : Entity_Id) return Uint;
5853 -- Given an entry, find its index in the visible declarations of the
5854 -- corresponding concurrent type of Typ.
5856 ----------------------
5857 -- Find_Entry_Index --
5858 ----------------------
5860 function Find_Entry_Index (E : Entity_Id) return Uint is
5861 Index : Uint := Uint_1;
5862 Subp_Decl : Entity_Id;
5866 and then not Is_Empty_List (Decls)
5868 Subp_Decl := First (Decls);
5869 while Present (Subp_Decl) loop
5870 if Nkind (Subp_Decl) = N_Entry_Declaration then
5871 if Defining_Identifier (Subp_Decl) = E then
5883 end Find_Entry_Index;
5885 -- Start of processing for Make_Select_Specific_Data_Table
5888 pragma Assert (not Restriction_Active (No_Dispatching_Calls));
5890 DT_Ptr := Node (First_Elmt (Access_Disp_Table (Typ)));
5892 if Present (Corresponding_Concurrent_Type (Typ)) then
5893 Conc_Typ := Corresponding_Concurrent_Type (Typ);
5895 if Present (Full_View (Conc_Typ)) then
5896 Conc_Typ := Full_View (Conc_Typ);
5899 if Ekind (Conc_Typ) = E_Protected_Type then
5900 Decls := Visible_Declarations (Protected_Definition (
5901 Parent (Conc_Typ)));
5903 pragma Assert (Ekind (Conc_Typ) = E_Task_Type);
5904 Decls := Visible_Declarations (Task_Definition (
5905 Parent (Conc_Typ)));
5909 -- Count the non-predefined primitive operations
5911 Prim_Elmt := First_Elmt (Primitive_Operations (Typ));
5912 while Present (Prim_Elmt) loop
5913 Prim := Node (Prim_Elmt);
5915 if not (Is_Predefined_Dispatching_Operation (Prim)
5916 or else Is_Predefined_Dispatching_Alias (Prim))
5918 Nb_Prim := Nb_Prim + 1;
5921 Next_Elmt (Prim_Elmt);
5925 Examined : Examined_Array (1 .. Nb_Prim) := (others => False);
5928 Prim_Elmt := First_Elmt (Primitive_Operations (Typ));
5929 while Present (Prim_Elmt) loop
5930 Prim := Node (Prim_Elmt);
5932 -- Look for primitive overriding an abstract interface subprogram
5934 if Present (Interface_Alias (Prim))
5935 and then not Examined (UI_To_Int (DT_Position (Alias (Prim))))
5937 Prim_Pos := DT_Position (Alias (Prim));
5938 pragma Assert (UI_To_Int (Prim_Pos) <= Nb_Prim);
5939 Examined (UI_To_Int (Prim_Pos)) := True;
5941 -- Set the primitive operation kind regardless of subprogram
5943 -- Ada.Tags.Set_Prim_Op_Kind (DT_Ptr, <position>, <kind>);
5945 Append_To (Assignments,
5946 Make_Procedure_Call_Statement (Loc,
5947 Name => New_Reference_To (RTE (RE_Set_Prim_Op_Kind), Loc),
5948 Parameter_Associations => New_List (
5949 New_Reference_To (DT_Ptr, Loc),
5950 Make_Integer_Literal (Loc, Prim_Pos),
5951 Prim_Op_Kind (Alias (Prim), Typ))));
5953 -- Retrieve the root of the alias chain
5956 while Present (Alias (Prim_Als)) loop
5957 Prim_Als := Alias (Prim_Als);
5960 -- In the case of an entry wrapper, set the entry index
5962 if Ekind (Prim) = E_Procedure
5963 and then Is_Primitive_Wrapper (Prim_Als)
5964 and then Ekind (Wrapped_Entity (Prim_Als)) = E_Entry
5967 -- Ada.Tags.Set_Entry_Index
5968 -- (DT_Ptr, <position>, <index>);
5970 Append_To (Assignments,
5971 Make_Procedure_Call_Statement (Loc,
5973 New_Reference_To (RTE (RE_Set_Entry_Index), Loc),
5974 Parameter_Associations => New_List (
5975 New_Reference_To (DT_Ptr, Loc),
5976 Make_Integer_Literal (Loc, Prim_Pos),
5977 Make_Integer_Literal (Loc,
5978 Find_Entry_Index (Wrapped_Entity (Prim_Als))))));
5982 Next_Elmt (Prim_Elmt);
5987 end Make_Select_Specific_Data_Table;
5993 function Make_Tags (Typ : Entity_Id) return List_Id is
5994 Loc : constant Source_Ptr := Sloc (Typ);
5995 Result : constant List_Id := New_List;
5998 (Tag_Typ : Entity_Id;
6000 Is_Secondary_DT : Boolean);
6001 -- Import the dispatch table DT of tagged type Tag_Typ. Required to
6002 -- generate forward references and statically allocate the table. For
6003 -- primary dispatch tables that require no dispatch table generate:
6004 -- DT : static aliased constant Non_Dispatch_Table_Wrapper;
6005 -- $pragma import (ada, DT);
6006 -- Otherwise generate:
6007 -- DT : static aliased constant Dispatch_Table_Wrapper (Nb_Prim);
6008 -- $pragma import (ada, DT);
6015 (Tag_Typ : Entity_Id;
6017 Is_Secondary_DT : Boolean)
6019 DT_Constr_List : List_Id;
6023 Set_Is_Imported (DT);
6024 Set_Ekind (DT, E_Constant);
6025 Set_Related_Type (DT, Typ);
6027 -- The scope must be set now to call Get_External_Name
6029 Set_Scope (DT, Current_Scope);
6031 Get_External_Name (DT, True);
6032 Set_Interface_Name (DT,
6033 Make_String_Literal (Loc,
6034 Strval => String_From_Name_Buffer));
6036 -- Ensure proper Sprint output of this implicit importation
6038 Set_Is_Internal (DT);
6040 -- Save this entity to allow Make_DT to generate its exportation
6042 Append_Elmt (DT, Dispatch_Table_Wrappers (Typ));
6044 -- No dispatch table required
6046 if not Is_Secondary_DT
6047 and then not Has_DT (Tag_Typ)
6050 Make_Object_Declaration (Loc,
6051 Defining_Identifier => DT,
6052 Aliased_Present => True,
6053 Constant_Present => True,
6054 Object_Definition =>
6055 New_Reference_To (RTE (RE_No_Dispatch_Table_Wrapper), Loc)));
6058 -- Calculate the number of primitives of the dispatch table and
6059 -- the size of the Type_Specific_Data record.
6062 UI_To_Int (DT_Entry_Count (First_Tag_Component (Tag_Typ)));
6064 -- If the tagged type has no primitives we add a dummy slot
6065 -- whose address will be the tag of this type.
6069 New_List (Make_Integer_Literal (Loc, 1));
6072 New_List (Make_Integer_Literal (Loc, Nb_Prim));
6076 Make_Object_Declaration (Loc,
6077 Defining_Identifier => DT,
6078 Aliased_Present => True,
6079 Constant_Present => True,
6080 Object_Definition =>
6081 Make_Subtype_Indication (Loc,
6083 New_Reference_To (RTE (RE_Dispatch_Table_Wrapper), Loc),
6084 Constraint => Make_Index_Or_Discriminant_Constraint (Loc,
6085 Constraints => DT_Constr_List))));
6091 Tname : constant Name_Id := Chars (Typ);
6092 AI_Tag_Comp : Elmt_Id;
6095 Predef_Prims_Ptr : Node_Id;
6097 Iface_DT_Ptr : Node_Id;
6100 Typ_Comps : Elist_Id;
6102 -- Start of processing for Make_Tags
6105 -- 1) Generate the primary and secondary tag entities
6107 -- Collect the components associated with secondary dispatch tables
6109 if Has_Interfaces (Typ) then
6110 Collect_Interface_Components (Typ, Typ_Comps);
6113 -- 1) Generate the primary tag entities
6115 -- Primary dispatch table containing user-defined primitives
6117 DT_Ptr := Make_Defining_Identifier (Loc,
6118 New_External_Name (Tname, 'P'));
6119 Set_Etype (DT_Ptr, RTE (RE_Tag));
6121 -- Primary dispatch table containing predefined primitives
6124 Make_Defining_Identifier (Loc,
6125 Chars => New_External_Name (Tname, 'Y'));
6126 Set_Etype (Predef_Prims_Ptr, RTE (RE_Address));
6128 -- Import the forward declaration of the Dispatch Table wrapper record
6129 -- (Make_DT will take care of its exportation)
6131 if Building_Static_DT (Typ) then
6132 Set_Dispatch_Table_Wrappers (Typ, New_Elmt_List);
6135 Make_Defining_Identifier (Loc,
6136 Chars => New_External_Name (Tname, 'T'));
6138 Import_DT (Typ, DT, Is_Secondary_DT => False);
6140 if Has_DT (Typ) then
6142 Make_Object_Declaration (Loc,
6143 Defining_Identifier => DT_Ptr,
6144 Constant_Present => True,
6145 Object_Definition => New_Reference_To (RTE (RE_Tag), Loc),
6147 Unchecked_Convert_To (RTE (RE_Tag),
6148 Make_Attribute_Reference (Loc,
6150 Make_Selected_Component (Loc,
6151 Prefix => New_Reference_To (DT, Loc),
6154 (RTE_Record_Component (RE_Prims_Ptr), Loc)),
6155 Attribute_Name => Name_Address))));
6157 -- Generate the SCIL node for the previous object declaration
6158 -- because it has a tag initialization.
6160 if Generate_SCIL then
6161 Insert_Before (Last (Result),
6163 (Nkind => Dispatch_Table_Tag_Init,
6164 Related_Node => Last (Result),
6169 Make_Object_Declaration (Loc,
6170 Defining_Identifier => Predef_Prims_Ptr,
6171 Constant_Present => True,
6172 Object_Definition => New_Reference_To
6173 (RTE (RE_Address), Loc),
6175 Make_Attribute_Reference (Loc,
6177 Make_Selected_Component (Loc,
6178 Prefix => New_Reference_To (DT, Loc),
6181 (RTE_Record_Component (RE_Predef_Prims), Loc)),
6182 Attribute_Name => Name_Address)));
6184 -- No dispatch table required
6188 Make_Object_Declaration (Loc,
6189 Defining_Identifier => DT_Ptr,
6190 Constant_Present => True,
6191 Object_Definition => New_Reference_To (RTE (RE_Tag), Loc),
6193 Unchecked_Convert_To (RTE (RE_Tag),
6194 Make_Attribute_Reference (Loc,
6196 Make_Selected_Component (Loc,
6197 Prefix => New_Reference_To (DT, Loc),
6200 (RTE_Record_Component (RE_NDT_Prims_Ptr), Loc)),
6201 Attribute_Name => Name_Address))));
6203 -- Generate the SCIL node for the previous object declaration
6204 -- because it has a tag initialization.
6206 if Generate_SCIL then
6207 Insert_Before (Last (Result),
6209 (Nkind => Dispatch_Table_Tag_Init,
6210 Related_Node => Last (Result),
6215 Set_Is_True_Constant (DT_Ptr);
6216 Set_Is_Statically_Allocated (DT_Ptr);
6219 pragma Assert (No (Access_Disp_Table (Typ)));
6220 Set_Access_Disp_Table (Typ, New_Elmt_List);
6221 Append_Elmt (DT_Ptr, Access_Disp_Table (Typ));
6222 Append_Elmt (Predef_Prims_Ptr, Access_Disp_Table (Typ));
6224 -- 2) Generate the secondary tag entities
6226 if Has_Interfaces (Typ) then
6228 -- Note: The following value of Suffix_Index must be in sync with
6229 -- the Suffix_Index values of secondary dispatch tables generated
6234 -- For each interface type we build an unique external name
6235 -- associated with its corresponding secondary dispatch table.
6236 -- This external name will be used to declare an object that
6237 -- references this secondary dispatch table, value that will be
6238 -- used for the elaboration of Typ's objects and also for the
6239 -- elaboration of objects of derivations of Typ that do not
6240 -- override the primitive operation of this interface type.
6242 AI_Tag_Comp := First_Elmt (Typ_Comps);
6243 while Present (AI_Tag_Comp) loop
6244 Get_Secondary_DT_External_Name
6245 (Typ, Related_Type (Node (AI_Tag_Comp)), Suffix_Index);
6246 Typ_Name := Name_Find;
6248 if Building_Static_DT (Typ) then
6250 Make_Defining_Identifier (Loc,
6251 Chars => New_External_Name
6252 (Typ_Name, 'T', Suffix_Index => -1));
6254 (Tag_Typ => Related_Type (Node (AI_Tag_Comp)),
6256 Is_Secondary_DT => True);
6259 -- Secondary dispatch table referencing thunks to user-defined
6260 -- primitives covered by this interface.
6263 Make_Defining_Identifier (Loc,
6264 Chars => New_External_Name (Typ_Name, 'P'));
6265 Set_Etype (Iface_DT_Ptr, RTE (RE_Interface_Tag));
6266 Set_Ekind (Iface_DT_Ptr, E_Constant);
6267 Set_Is_Tag (Iface_DT_Ptr);
6268 Set_Has_Thunks (Iface_DT_Ptr);
6269 Set_Is_Statically_Allocated (Iface_DT_Ptr,
6270 Is_Library_Level_Tagged_Type (Typ));
6271 Set_Is_True_Constant (Iface_DT_Ptr);
6273 (Iface_DT_Ptr, Related_Type (Node (AI_Tag_Comp)));
6274 Append_Elmt (Iface_DT_Ptr, Access_Disp_Table (Typ));
6276 if Building_Static_DT (Typ) then
6278 Make_Object_Declaration (Loc,
6279 Defining_Identifier => Iface_DT_Ptr,
6280 Constant_Present => True,
6281 Object_Definition => New_Reference_To
6282 (RTE (RE_Interface_Tag), Loc),
6284 Unchecked_Convert_To (RTE (RE_Interface_Tag),
6285 Make_Attribute_Reference (Loc,
6287 Make_Selected_Component (Loc,
6288 Prefix => New_Reference_To (Iface_DT, Loc),
6291 (RTE_Record_Component (RE_Prims_Ptr), Loc)),
6292 Attribute_Name => Name_Address))));
6295 -- Secondary dispatch table referencing thunks to predefined
6299 Make_Defining_Identifier (Loc,
6300 Chars => New_External_Name (Typ_Name, 'Y'));
6301 Set_Etype (Iface_DT_Ptr, RTE (RE_Address));
6302 Set_Ekind (Iface_DT_Ptr, E_Constant);
6303 Set_Is_Tag (Iface_DT_Ptr);
6304 Set_Has_Thunks (Iface_DT_Ptr);
6305 Set_Is_Statically_Allocated (Iface_DT_Ptr,
6306 Is_Library_Level_Tagged_Type (Typ));
6307 Set_Is_True_Constant (Iface_DT_Ptr);
6309 (Iface_DT_Ptr, Related_Type (Node (AI_Tag_Comp)));
6310 Append_Elmt (Iface_DT_Ptr, Access_Disp_Table (Typ));
6312 -- Secondary dispatch table referencing user-defined primitives
6313 -- covered by this interface.
6316 Make_Defining_Identifier (Loc,
6317 Chars => New_External_Name (Typ_Name, 'D'));
6318 Set_Etype (Iface_DT_Ptr, RTE (RE_Interface_Tag));
6319 Set_Ekind (Iface_DT_Ptr, E_Constant);
6320 Set_Is_Tag (Iface_DT_Ptr);
6321 Set_Is_Statically_Allocated (Iface_DT_Ptr,
6322 Is_Library_Level_Tagged_Type (Typ));
6323 Set_Is_True_Constant (Iface_DT_Ptr);
6325 (Iface_DT_Ptr, Related_Type (Node (AI_Tag_Comp)));
6326 Append_Elmt (Iface_DT_Ptr, Access_Disp_Table (Typ));
6328 -- Secondary dispatch table referencing predefined primitives
6331 Make_Defining_Identifier (Loc,
6332 Chars => New_External_Name (Typ_Name, 'Z'));
6333 Set_Etype (Iface_DT_Ptr, RTE (RE_Address));
6334 Set_Ekind (Iface_DT_Ptr, E_Constant);
6335 Set_Is_Tag (Iface_DT_Ptr);
6336 Set_Is_Statically_Allocated (Iface_DT_Ptr,
6337 Is_Library_Level_Tagged_Type (Typ));
6338 Set_Is_True_Constant (Iface_DT_Ptr);
6340 (Iface_DT_Ptr, Related_Type (Node (AI_Tag_Comp)));
6341 Append_Elmt (Iface_DT_Ptr, Access_Disp_Table (Typ));
6343 Next_Elmt (AI_Tag_Comp);
6347 -- 3) At the end of Access_Disp_Table, if the type has user-defined
6348 -- primitives, we add the entity of an access type declaration that
6349 -- is used by Build_Get_Prim_Op_Address to expand dispatching calls
6350 -- through the primary dispatch table.
6352 if UI_To_Int (DT_Entry_Count (First_Tag_Component (Typ))) = 0 then
6353 Analyze_List (Result);
6356 -- type Typ_DT is array (1 .. Nb_Prims) of Prim_Ptr;
6357 -- type Typ_DT_Acc is access Typ_DT;
6361 Name_DT_Prims : constant Name_Id :=
6362 New_External_Name (Tname, 'G');
6363 Name_DT_Prims_Acc : constant Name_Id :=
6364 New_External_Name (Tname, 'H');
6365 DT_Prims : constant Entity_Id :=
6366 Make_Defining_Identifier (Loc,
6368 DT_Prims_Acc : constant Entity_Id :=
6369 Make_Defining_Identifier (Loc,
6373 Make_Full_Type_Declaration (Loc,
6374 Defining_Identifier => DT_Prims,
6376 Make_Constrained_Array_Definition (Loc,
6377 Discrete_Subtype_Definitions => New_List (
6379 Low_Bound => Make_Integer_Literal (Loc, 1),
6380 High_Bound => Make_Integer_Literal (Loc,
6382 (First_Tag_Component (Typ))))),
6383 Component_Definition =>
6384 Make_Component_Definition (Loc,
6385 Subtype_Indication =>
6386 New_Reference_To (RTE (RE_Prim_Ptr), Loc)))));
6389 Make_Full_Type_Declaration (Loc,
6390 Defining_Identifier => DT_Prims_Acc,
6392 Make_Access_To_Object_Definition (Loc,
6393 Subtype_Indication =>
6394 New_Occurrence_Of (DT_Prims, Loc))));
6396 Append_Elmt (DT_Prims_Acc, Access_Disp_Table (Typ));
6398 -- Analyze the resulting list and suppress the generation of the
6399 -- Init_Proc associated with the above array declaration because
6400 -- this type is never used in object declarations. It is only used
6401 -- to simplify the expansion associated with dispatching calls.
6403 Analyze_List (Result);
6404 Set_Suppress_Init_Proc (Base_Type (DT_Prims));
6406 -- Mark entity of dispatch table. Required by the back end to
6407 -- handle them properly.
6409 Set_Is_Dispatch_Table_Entity (DT_Prims);
6413 Set_Ekind (DT_Ptr, E_Constant);
6414 Set_Is_Tag (DT_Ptr);
6415 Set_Related_Type (DT_Ptr, Typ);
6424 function New_Value (From : Node_Id) return Node_Id is
6425 Res : constant Node_Id := Duplicate_Subexpr (From);
6427 if Is_Access_Type (Etype (From)) then
6429 Make_Explicit_Dereference (Sloc (From),
6440 function New_Scil_Node
6441 (Nkind : Scil_Node_Kind;
6442 Related_Node : Node_Id;
6443 Entity : Entity_Id := Empty;
6444 Target_Prim : Entity_Id := Empty) return Node_Id
6446 New_N : constant Node_Id :=
6447 New_Node (N_Null_Statement, Sloc (Related_Node));
6449 Set_Is_Scil_Node (New_N);
6450 Set_Scil_Nkind (New_N, UI_From_Int (Scil_Node_Kind'Pos (Nkind)));
6451 Set_Scil_Related_Node (New_N, Related_Node);
6452 Set_Entity (New_N, Entity);
6453 Set_Scil_Target_Prim (New_N, Target_Prim);
6457 -----------------------------------
6458 -- Original_View_In_Visible_Part --
6459 -----------------------------------
6461 function Original_View_In_Visible_Part (Typ : Entity_Id) return Boolean is
6462 Scop : constant Entity_Id := Scope (Typ);
6465 -- The scope must be a package
6467 if not Is_Package_Or_Generic_Package (Scop) then
6471 -- A type with a private declaration has a private view declared in
6472 -- the visible part.
6474 if Has_Private_Declaration (Typ) then
6478 return List_Containing (Parent (Typ)) =
6479 Visible_Declarations (Specification (Unit_Declaration_Node (Scop)));
6480 end Original_View_In_Visible_Part;
6486 function Prim_Op_Kind
6488 Typ : Entity_Id) return Node_Id
6490 Full_Typ : Entity_Id := Typ;
6491 Loc : constant Source_Ptr := Sloc (Prim);
6492 Prim_Op : Entity_Id;
6495 -- Retrieve the original primitive operation
6498 while Present (Alias (Prim_Op)) loop
6499 Prim_Op := Alias (Prim_Op);
6502 if Ekind (Typ) = E_Record_Type
6503 and then Present (Corresponding_Concurrent_Type (Typ))
6505 Full_Typ := Corresponding_Concurrent_Type (Typ);
6508 -- When a private tagged type is completed by a concurrent type,
6509 -- retrieve the full view.
6511 if Is_Private_Type (Full_Typ) then
6512 Full_Typ := Full_View (Full_Typ);
6515 if Ekind (Prim_Op) = E_Function then
6517 -- Protected function
6519 if Ekind (Full_Typ) = E_Protected_Type then
6520 return New_Reference_To (RTE (RE_POK_Protected_Function), Loc);
6524 elsif Ekind (Full_Typ) = E_Task_Type then
6525 return New_Reference_To (RTE (RE_POK_Task_Function), Loc);
6530 return New_Reference_To (RTE (RE_POK_Function), Loc);
6534 pragma Assert (Ekind (Prim_Op) = E_Procedure);
6536 if Ekind (Full_Typ) = E_Protected_Type then
6540 if Is_Primitive_Wrapper (Prim_Op)
6541 and then Ekind (Wrapped_Entity (Prim_Op)) = E_Entry
6543 return New_Reference_To (RTE (RE_POK_Protected_Entry), Loc);
6545 -- Protected procedure
6548 return New_Reference_To (RTE (RE_POK_Protected_Procedure), Loc);
6551 elsif Ekind (Full_Typ) = E_Task_Type then
6555 if Is_Primitive_Wrapper (Prim_Op)
6556 and then Ekind (Wrapped_Entity (Prim_Op)) = E_Entry
6558 return New_Reference_To (RTE (RE_POK_Task_Entry), Loc);
6560 -- Task "procedure". These are the internally Expander-generated
6561 -- procedures (task body for instance).
6564 return New_Reference_To (RTE (RE_POK_Task_Procedure), Loc);
6567 -- Regular procedure
6570 return New_Reference_To (RTE (RE_POK_Procedure), Loc);
6575 ------------------------
6576 -- Register_Primitive --
6577 ------------------------
6579 function Register_Primitive
6581 Prim : Entity_Id) return List_Id
6584 Iface_Prim : Entity_Id;
6585 Iface_Typ : Entity_Id;
6586 Iface_DT_Ptr : Entity_Id;
6587 Iface_DT_Elmt : Elmt_Id;
6588 L : constant List_Id := New_List;
6591 Tag_Typ : Entity_Id;
6592 Thunk_Id : Entity_Id;
6593 Thunk_Code : Node_Id;
6596 pragma Assert (not Restriction_Active (No_Dispatching_Calls));
6598 if not RTE_Available (RE_Tag) then
6602 if not Present (Interface_Alias (Prim)) then
6603 Tag_Typ := Scope (DTC_Entity (Prim));
6604 Pos := DT_Position (Prim);
6605 Tag := First_Tag_Component (Tag_Typ);
6607 if Is_Predefined_Dispatching_Operation (Prim)
6608 or else Is_Predefined_Dispatching_Alias (Prim)
6611 Node (Next_Elmt (First_Elmt (Access_Disp_Table (Tag_Typ))));
6614 Build_Set_Predefined_Prim_Op_Address (Loc,
6615 Tag_Node => New_Reference_To (DT_Ptr, Loc),
6618 Unchecked_Convert_To (RTE (RE_Prim_Ptr),
6619 Make_Attribute_Reference (Loc,
6620 Prefix => New_Reference_To (Prim, Loc),
6621 Attribute_Name => Name_Unrestricted_Access))));
6623 -- Register copy of the pointer to the 'size primitive in the TSD
6625 if Chars (Prim) = Name_uSize
6626 and then RTE_Record_Component_Available (RE_Size_Func)
6628 DT_Ptr := Node (First_Elmt (Access_Disp_Table (Tag_Typ)));
6630 Build_Set_Size_Function (Loc,
6631 Tag_Node => New_Reference_To (DT_Ptr, Loc),
6632 Size_Func => Prim));
6636 pragma Assert (Pos /= Uint_0 and then Pos <= DT_Entry_Count (Tag));
6638 DT_Ptr := Node (First_Elmt (Access_Disp_Table (Tag_Typ)));
6640 Build_Set_Prim_Op_Address (Loc,
6642 Tag_Node => New_Reference_To (DT_Ptr, Loc),
6645 Unchecked_Convert_To (RTE (RE_Prim_Ptr),
6646 Make_Attribute_Reference (Loc,
6647 Prefix => New_Reference_To (Prim, Loc),
6648 Attribute_Name => Name_Unrestricted_Access))));
6651 -- Ada 2005 (AI-251): Primitive associated with an interface type
6652 -- Generate the code of the thunk only if the interface type is not an
6653 -- immediate ancestor of Typ; otherwise the dispatch table associated
6654 -- with the interface is the primary dispatch table and we have nothing
6658 Tag_Typ := Find_Dispatching_Type (Alias (Prim));
6659 Iface_Typ := Find_Dispatching_Type (Interface_Alias (Prim));
6661 pragma Assert (Is_Interface (Iface_Typ));
6663 Expand_Interface_Thunk (Prim, Thunk_Id, Thunk_Code);
6665 if not Is_Ancestor (Iface_Typ, Tag_Typ)
6666 and then Present (Thunk_Code)
6668 -- Generate the code necessary to fill the appropriate entry of
6669 -- the secondary dispatch table of Prim's controlling type with
6670 -- Thunk_Id's address.
6672 Iface_DT_Elmt := Find_Interface_ADT (Tag_Typ, Iface_Typ);
6673 Iface_DT_Ptr := Node (Iface_DT_Elmt);
6674 pragma Assert (Has_Thunks (Iface_DT_Ptr));
6676 Iface_Prim := Interface_Alias (Prim);
6677 Pos := DT_Position (Iface_Prim);
6678 Tag := First_Tag_Component (Iface_Typ);
6680 Prepend_To (L, Thunk_Code);
6682 if Is_Predefined_Dispatching_Operation (Prim)
6683 or else Is_Predefined_Dispatching_Alias (Prim)
6686 Build_Set_Predefined_Prim_Op_Address (Loc,
6688 New_Reference_To (Node (Next_Elmt (Iface_DT_Elmt)), Loc),
6691 Unchecked_Convert_To (RTE (RE_Prim_Ptr),
6692 Make_Attribute_Reference (Loc,
6693 Prefix => New_Reference_To (Thunk_Id, Loc),
6694 Attribute_Name => Name_Unrestricted_Access))));
6696 Next_Elmt (Iface_DT_Elmt);
6697 Next_Elmt (Iface_DT_Elmt);
6698 Iface_DT_Ptr := Node (Iface_DT_Elmt);
6699 pragma Assert (not Has_Thunks (Iface_DT_Ptr));
6702 Build_Set_Predefined_Prim_Op_Address (Loc,
6704 New_Reference_To (Node (Next_Elmt (Iface_DT_Elmt)), Loc),
6707 Unchecked_Convert_To (RTE (RE_Prim_Ptr),
6708 Make_Attribute_Reference (Loc,
6709 Prefix => New_Reference_To (Alias (Prim), Loc),
6710 Attribute_Name => Name_Unrestricted_Access))));
6713 pragma Assert (Pos /= Uint_0
6714 and then Pos <= DT_Entry_Count (Tag));
6717 Build_Set_Prim_Op_Address (Loc,
6719 Tag_Node => New_Reference_To (Iface_DT_Ptr, Loc),
6722 Unchecked_Convert_To (RTE (RE_Prim_Ptr),
6723 Make_Attribute_Reference (Loc,
6724 Prefix => New_Reference_To (Thunk_Id, Loc),
6725 Attribute_Name => Name_Unrestricted_Access))));
6727 Next_Elmt (Iface_DT_Elmt);
6728 Next_Elmt (Iface_DT_Elmt);
6729 Iface_DT_Ptr := Node (Iface_DT_Elmt);
6730 pragma Assert (not Has_Thunks (Iface_DT_Ptr));
6733 Build_Set_Prim_Op_Address (Loc,
6735 Tag_Node => New_Reference_To (Iface_DT_Ptr, Loc),
6738 Unchecked_Convert_To (RTE (RE_Prim_Ptr),
6739 Make_Attribute_Reference (Loc,
6740 Prefix => New_Reference_To (Alias (Prim), Loc),
6741 Attribute_Name => Name_Unrestricted_Access))));
6748 end Register_Primitive;
6750 -------------------------
6751 -- Set_All_DT_Position --
6752 -------------------------
6754 procedure Set_All_DT_Position (Typ : Entity_Id) is
6756 procedure Validate_Position (Prim : Entity_Id);
6757 -- Check that the position assigned to Prim is completely safe
6758 -- (it has not been assigned to a previously defined primitive
6759 -- operation of Typ)
6761 -----------------------
6762 -- Validate_Position --
6763 -----------------------
6765 procedure Validate_Position (Prim : Entity_Id) is
6770 -- Aliased primitives are safe
6772 if Present (Alias (Prim)) then
6776 Op_Elmt := First_Elmt (Primitive_Operations (Typ));
6777 while Present (Op_Elmt) loop
6778 Op := Node (Op_Elmt);
6780 -- No need to check against itself
6785 -- Primitive operations covering abstract interfaces are
6788 elsif Present (Interface_Alias (Op)) then
6791 -- Predefined dispatching operations are completely safe. They
6792 -- are allocated at fixed positions in a separate table.
6794 elsif Is_Predefined_Dispatching_Operation (Op)
6795 or else Is_Predefined_Dispatching_Alias (Op)
6799 -- Aliased subprograms are safe
6801 elsif Present (Alias (Op)) then
6804 elsif DT_Position (Op) = DT_Position (Prim)
6805 and then not Is_Predefined_Dispatching_Operation (Op)
6806 and then not Is_Predefined_Dispatching_Operation (Prim)
6807 and then not Is_Predefined_Dispatching_Alias (Op)
6808 and then not Is_Predefined_Dispatching_Alias (Prim)
6811 -- Handle aliased subprograms
6820 if Present (Overridden_Operation (Op_1)) then
6821 Op_1 := Overridden_Operation (Op_1);
6822 elsif Present (Alias (Op_1)) then
6823 Op_1 := Alias (Op_1);
6831 if Present (Overridden_Operation (Op_2)) then
6832 Op_2 := Overridden_Operation (Op_2);
6833 elsif Present (Alias (Op_2)) then
6834 Op_2 := Alias (Op_2);
6840 if Op_1 /= Op_2 then
6841 raise Program_Error;
6846 Next_Elmt (Op_Elmt);
6848 end Validate_Position;
6852 Parent_Typ : constant Entity_Id := Etype (Typ);
6853 First_Prim : constant Elmt_Id := First_Elmt (Primitive_Operations (Typ));
6854 The_Tag : constant Entity_Id := First_Tag_Component (Typ);
6856 Adjusted : Boolean := False;
6857 Finalized : Boolean := False;
6863 Prim_Elmt : Elmt_Id;
6865 -- Start of processing for Set_All_DT_Position
6868 pragma Assert (Present (First_Tag_Component (Typ)));
6870 -- Set the DT_Position for each primitive operation. Perform some
6871 -- sanity checks to avoid to build completely inconsistent dispatch
6874 -- First stage: Set the DTC entity of all the primitive operations
6875 -- This is required to properly read the DT_Position attribute in
6876 -- the latter stages.
6878 Prim_Elmt := First_Prim;
6880 while Present (Prim_Elmt) loop
6881 Prim := Node (Prim_Elmt);
6883 -- Predefined primitives have a separate dispatch table
6885 if not (Is_Predefined_Dispatching_Operation (Prim)
6886 or else Is_Predefined_Dispatching_Alias (Prim))
6888 Count_Prim := Count_Prim + 1;
6891 Set_DTC_Entity_Value (Typ, Prim);
6893 -- Clear any previous value of the DT_Position attribute. In this
6894 -- way we ensure that the final position of all the primitives is
6895 -- established by the following stages of this algorithm.
6897 Set_DT_Position (Prim, No_Uint);
6899 Next_Elmt (Prim_Elmt);
6903 Fixed_Prim : array (Int range 0 .. Count_Prim) of Boolean :=
6908 procedure Handle_Inherited_Private_Subprograms (Typ : Entity_Id);
6909 -- Called if Typ is declared in a nested package or a public child
6910 -- package to handle inherited primitives that were inherited by Typ
6911 -- in the visible part, but whose declaration was deferred because
6912 -- the parent operation was private and not visible at that point.
6914 procedure Set_Fixed_Prim (Pos : Nat);
6915 -- Sets to true an element of the Fixed_Prim table to indicate
6916 -- that this entry of the dispatch table of Typ is occupied.
6918 ------------------------------------------
6919 -- Handle_Inherited_Private_Subprograms --
6920 ------------------------------------------
6922 procedure Handle_Inherited_Private_Subprograms (Typ : Entity_Id) is
6925 Op_Elmt_2 : Elmt_Id;
6926 Prim_Op : Entity_Id;
6927 Parent_Subp : Entity_Id;
6930 Op_List := Primitive_Operations (Typ);
6932 Op_Elmt := First_Elmt (Op_List);
6933 while Present (Op_Elmt) loop
6934 Prim_Op := Node (Op_Elmt);
6936 -- Search primitives that are implicit operations with an
6937 -- internal name whose parent operation has a normal name.
6939 if Present (Alias (Prim_Op))
6940 and then Find_Dispatching_Type (Alias (Prim_Op)) /= Typ
6941 and then not Comes_From_Source (Prim_Op)
6942 and then Is_Internal_Name (Chars (Prim_Op))
6943 and then not Is_Internal_Name (Chars (Alias (Prim_Op)))
6945 Parent_Subp := Alias (Prim_Op);
6947 -- Check if the type has an explicit overriding for this
6950 Op_Elmt_2 := Next_Elmt (Op_Elmt);
6951 while Present (Op_Elmt_2) loop
6952 if Chars (Node (Op_Elmt_2)) = Chars (Parent_Subp)
6953 and then Type_Conformant (Prim_Op, Node (Op_Elmt_2))
6955 Set_DT_Position (Prim_Op, DT_Position (Parent_Subp));
6956 Set_DT_Position (Node (Op_Elmt_2),
6957 DT_Position (Parent_Subp));
6958 Set_Fixed_Prim (UI_To_Int (DT_Position (Prim_Op)));
6960 goto Next_Primitive;
6963 Next_Elmt (Op_Elmt_2);
6968 Next_Elmt (Op_Elmt);
6970 end Handle_Inherited_Private_Subprograms;
6972 --------------------
6973 -- Set_Fixed_Prim --
6974 --------------------
6976 procedure Set_Fixed_Prim (Pos : Nat) is
6978 pragma Assert (Pos <= Count_Prim);
6979 Fixed_Prim (Pos) := True;
6981 when Constraint_Error =>
6982 raise Program_Error;
6986 -- In case of nested packages and public child package it may be
6987 -- necessary a special management on inherited subprograms so that
6988 -- the dispatch table is properly filled.
6990 if Ekind (Scope (Scope (Typ))) = E_Package
6991 and then Scope (Scope (Typ)) /= Standard_Standard
6992 and then ((Is_Derived_Type (Typ) and then not Is_Private_Type (Typ))
6994 (Nkind (Parent (Typ)) = N_Private_Extension_Declaration
6995 and then Is_Generic_Type (Typ)))
6996 and then In_Open_Scopes (Scope (Etype (Typ)))
6997 and then Typ = Base_Type (Typ)
6999 Handle_Inherited_Private_Subprograms (Typ);
7002 -- Second stage: Register fixed entries
7005 Prim_Elmt := First_Prim;
7006 while Present (Prim_Elmt) loop
7007 Prim := Node (Prim_Elmt);
7009 -- Predefined primitives have a separate table and all its
7010 -- entries are at predefined fixed positions.
7012 if Is_Predefined_Dispatching_Operation (Prim) then
7013 Set_DT_Position (Prim, Default_Prim_Op_Position (Prim));
7015 elsif Is_Predefined_Dispatching_Alias (Prim) then
7017 while Present (Alias (E)) loop
7021 Set_DT_Position (Prim, Default_Prim_Op_Position (E));
7023 -- Overriding primitives of ancestor abstract interfaces
7025 elsif Present (Interface_Alias (Prim))
7026 and then Is_Ancestor
7027 (Find_Dispatching_Type (Interface_Alias (Prim)), Typ)
7029 pragma Assert (DT_Position (Prim) = No_Uint
7030 and then Present (DTC_Entity (Interface_Alias (Prim))));
7032 E := Interface_Alias (Prim);
7033 Set_DT_Position (Prim, DT_Position (E));
7036 (DT_Position (Alias (Prim)) = No_Uint
7037 or else DT_Position (Alias (Prim)) = DT_Position (E));
7038 Set_DT_Position (Alias (Prim), DT_Position (E));
7039 Set_Fixed_Prim (UI_To_Int (DT_Position (Prim)));
7041 -- Overriding primitives must use the same entry as the
7042 -- overridden primitive.
7044 elsif not Present (Interface_Alias (Prim))
7045 and then Present (Alias (Prim))
7046 and then Chars (Prim) = Chars (Alias (Prim))
7047 and then Find_Dispatching_Type (Alias (Prim)) /= Typ
7048 and then Is_Ancestor
7049 (Find_Dispatching_Type (Alias (Prim)), Typ)
7050 and then Present (DTC_Entity (Alias (Prim)))
7053 Set_DT_Position (Prim, DT_Position (E));
7055 if not Is_Predefined_Dispatching_Alias (E) then
7056 Set_Fixed_Prim (UI_To_Int (DT_Position (E)));
7060 Next_Elmt (Prim_Elmt);
7063 -- Third stage: Fix the position of all the new primitives
7064 -- Entries associated with primitives covering interfaces
7065 -- are handled in a latter round.
7067 Prim_Elmt := First_Prim;
7068 while Present (Prim_Elmt) loop
7069 Prim := Node (Prim_Elmt);
7071 -- Skip primitives previously set entries
7073 if DT_Position (Prim) /= No_Uint then
7076 -- Primitives covering interface primitives are handled later
7078 elsif Present (Interface_Alias (Prim)) then
7082 -- Take the next available position in the DT
7085 Nb_Prim := Nb_Prim + 1;
7086 pragma Assert (Nb_Prim <= Count_Prim);
7087 exit when not Fixed_Prim (Nb_Prim);
7090 Set_DT_Position (Prim, UI_From_Int (Nb_Prim));
7091 Set_Fixed_Prim (Nb_Prim);
7094 Next_Elmt (Prim_Elmt);
7098 -- Fourth stage: Complete the decoration of primitives covering
7099 -- interfaces (that is, propagate the DT_Position attribute
7100 -- from the aliased primitive)
7102 Prim_Elmt := First_Prim;
7103 while Present (Prim_Elmt) loop
7104 Prim := Node (Prim_Elmt);
7106 if DT_Position (Prim) = No_Uint
7107 and then Present (Interface_Alias (Prim))
7109 pragma Assert (Present (Alias (Prim))
7110 and then Find_Dispatching_Type (Alias (Prim)) = Typ);
7112 -- Check if this entry will be placed in the primary DT
7115 (Find_Dispatching_Type (Interface_Alias (Prim)), Typ)
7117 pragma Assert (DT_Position (Alias (Prim)) /= No_Uint);
7118 Set_DT_Position (Prim, DT_Position (Alias (Prim)));
7120 -- Otherwise it will be placed in the secondary DT
7124 (DT_Position (Interface_Alias (Prim)) /= No_Uint);
7125 Set_DT_Position (Prim,
7126 DT_Position (Interface_Alias (Prim)));
7130 Next_Elmt (Prim_Elmt);
7133 -- Generate listing showing the contents of the dispatch tables.
7134 -- This action is done before some further static checks because
7135 -- in case of critical errors caused by a wrong dispatch table
7136 -- we need to see the contents of such table.
7138 if Debug_Flag_ZZ then
7142 -- Final stage: Ensure that the table is correct plus some further
7143 -- verifications concerning the primitives.
7145 Prim_Elmt := First_Prim;
7147 while Present (Prim_Elmt) loop
7148 Prim := Node (Prim_Elmt);
7150 -- At this point all the primitives MUST have a position
7151 -- in the dispatch table.
7153 if DT_Position (Prim) = No_Uint then
7154 raise Program_Error;
7157 -- Calculate real size of the dispatch table
7159 if not (Is_Predefined_Dispatching_Operation (Prim)
7160 or else Is_Predefined_Dispatching_Alias (Prim))
7161 and then UI_To_Int (DT_Position (Prim)) > DT_Length
7163 DT_Length := UI_To_Int (DT_Position (Prim));
7166 -- Ensure that the assigned position to non-predefined
7167 -- dispatching operations in the dispatch table is correct.
7169 if not (Is_Predefined_Dispatching_Operation (Prim)
7170 or else Is_Predefined_Dispatching_Alias (Prim))
7172 Validate_Position (Prim);
7175 if Chars (Prim) = Name_Finalize then
7179 if Chars (Prim) = Name_Adjust then
7183 -- An abstract operation cannot be declared in the private part
7184 -- for a visible abstract type, because it could never be over-
7185 -- ridden. For explicit declarations this is checked at the
7186 -- point of declaration, but for inherited operations it must
7187 -- be done when building the dispatch table.
7189 -- Ada 2005 (AI-251): Primitives associated with interfaces are
7190 -- excluded from this check because interfaces must be visible in
7191 -- the public and private part (RM 7.3 (7.3/2))
7193 if Is_Abstract_Type (Typ)
7194 and then Is_Abstract_Subprogram (Prim)
7195 and then Present (Alias (Prim))
7196 and then not Is_Interface
7197 (Find_Dispatching_Type (Ultimate_Alias (Prim)))
7198 and then not Present (Interface_Alias (Prim))
7199 and then Is_Derived_Type (Typ)
7200 and then In_Private_Part (Current_Scope)
7202 List_Containing (Parent (Prim)) =
7203 Private_Declarations
7204 (Specification (Unit_Declaration_Node (Current_Scope)))
7205 and then Original_View_In_Visible_Part (Typ)
7207 -- We exclude Input and Output stream operations because
7208 -- Limited_Controlled inherits useless Input and Output
7209 -- stream operations from Root_Controlled, which can
7210 -- never be overridden.
7212 if not Is_TSS (Prim, TSS_Stream_Input)
7214 not Is_TSS (Prim, TSS_Stream_Output)
7217 ("abstract inherited private operation&" &
7218 " must be overridden (RM 3.9.3(10))",
7219 Parent (Typ), Prim);
7223 Next_Elmt (Prim_Elmt);
7228 if Is_Controlled (Typ) then
7229 if not Finalized then
7231 ("controlled type has no explicit Finalize method?", Typ);
7233 elsif not Adjusted then
7235 ("controlled type has no explicit Adjust method?", Typ);
7239 -- Set the final size of the Dispatch Table
7241 Set_DT_Entry_Count (The_Tag, UI_From_Int (DT_Length));
7243 -- The derived type must have at least as many components as its parent
7244 -- (for root types Etype points to itself and the test cannot fail).
7246 if DT_Entry_Count (The_Tag) <
7247 DT_Entry_Count (First_Tag_Component (Parent_Typ))
7249 raise Program_Error;
7251 end Set_All_DT_Position;
7253 --------------------------
7254 -- Set_CPP_Constructors --
7255 --------------------------
7257 procedure Set_CPP_Constructors (Typ : Entity_Id) is
7261 Found : Boolean := False;
7266 -- Look for the constructor entities
7268 E := Next_Entity (Typ);
7269 while Present (E) loop
7270 if Ekind (E) = E_Function
7271 and then Is_Constructor (E)
7273 -- Create the init procedure
7277 Init := Make_Defining_Identifier (Loc, Make_Init_Proc_Name (Typ));
7280 Make_Parameter_Specification (Loc,
7281 Defining_Identifier =>
7282 Make_Defining_Identifier (Loc, Name_X),
7284 New_Reference_To (Typ, Loc)));
7286 if Present (Parameter_Specifications (Parent (E))) then
7287 P := First (Parameter_Specifications (Parent (E)));
7288 while Present (P) loop
7290 Make_Parameter_Specification (Loc,
7291 Defining_Identifier =>
7292 Make_Defining_Identifier (Loc,
7293 Chars (Defining_Identifier (P))),
7294 Parameter_Type => New_Copy_Tree (Parameter_Type (P))));
7300 Make_Subprogram_Declaration (Loc,
7301 Make_Procedure_Specification (Loc,
7302 Defining_Unit_Name => Init,
7303 Parameter_Specifications => Parms)));
7305 Set_Init_Proc (Typ, Init);
7306 Set_Is_Imported (Init);
7307 Set_Interface_Name (Init, Interface_Name (E));
7308 Set_Convention (Init, Convention_C);
7309 Set_Is_Public (Init);
7310 Set_Has_Completion (Init);
7316 -- If there are no constructors, mark the type as abstract since we
7317 -- won't be able to declare objects of that type.
7320 Set_Is_Abstract_Type (Typ);
7322 end Set_CPP_Constructors;
7324 --------------------------
7325 -- Set_DTC_Entity_Value --
7326 --------------------------
7328 procedure Set_DTC_Entity_Value
7329 (Tagged_Type : Entity_Id;
7333 if Present (Interface_Alias (Prim))
7334 and then Is_Interface
7335 (Find_Dispatching_Type (Interface_Alias (Prim)))
7337 Set_DTC_Entity (Prim,
7340 Iface => Find_Dispatching_Type (Interface_Alias (Prim))));
7342 Set_DTC_Entity (Prim,
7343 First_Tag_Component (Tagged_Type));
7345 end Set_DTC_Entity_Value;
7351 function Tagged_Kind (T : Entity_Id) return Node_Id is
7352 Conc_Typ : Entity_Id;
7353 Loc : constant Source_Ptr := Sloc (T);
7357 (Is_Tagged_Type (T) and then RTE_Available (RE_Tagged_Kind));
7361 if Is_Abstract_Type (T) then
7362 if Is_Limited_Record (T) then
7363 return New_Reference_To (RTE (RE_TK_Abstract_Limited_Tagged), Loc);
7365 return New_Reference_To (RTE (RE_TK_Abstract_Tagged), Loc);
7370 elsif Is_Concurrent_Record_Type (T) then
7371 Conc_Typ := Corresponding_Concurrent_Type (T);
7373 if Present (Full_View (Conc_Typ)) then
7374 Conc_Typ := Full_View (Conc_Typ);
7377 if Ekind (Conc_Typ) = E_Protected_Type then
7378 return New_Reference_To (RTE (RE_TK_Protected), Loc);
7380 pragma Assert (Ekind (Conc_Typ) = E_Task_Type);
7381 return New_Reference_To (RTE (RE_TK_Task), Loc);
7384 -- Regular tagged kinds
7387 if Is_Limited_Record (T) then
7388 return New_Reference_To (RTE (RE_TK_Limited_Tagged), Loc);
7390 return New_Reference_To (RTE (RE_TK_Tagged), Loc);
7399 procedure Write_DT (Typ : Entity_Id) is
7404 -- Protect this procedure against wrong usage. Required because it will
7405 -- be used directly from GDB
7407 if not (Typ <= Last_Node_Id)
7408 or else not Is_Tagged_Type (Typ)
7410 Write_Str ("wrong usage: Write_DT must be used with tagged types");
7415 Write_Int (Int (Typ));
7417 Write_Name (Chars (Typ));
7419 if Is_Interface (Typ) then
7420 Write_Str (" is interface");
7425 Elmt := First_Elmt (Primitive_Operations (Typ));
7426 while Present (Elmt) loop
7427 Prim := Node (Elmt);
7430 -- Indicate if this primitive will be allocated in the primary
7431 -- dispatch table or in a secondary dispatch table associated
7432 -- with an abstract interface type
7434 if Present (DTC_Entity (Prim)) then
7435 if Etype (DTC_Entity (Prim)) = RTE (RE_Tag) then
7442 -- Output the node of this primitive operation and its name
7444 Write_Int (Int (Prim));
7447 if Is_Predefined_Dispatching_Operation (Prim) then
7448 Write_Str ("(predefined) ");
7451 Write_Name (Chars (Prim));
7453 -- Indicate if this primitive has an aliased primitive
7455 if Present (Alias (Prim)) then
7456 Write_Str (" (alias = ");
7457 Write_Int (Int (Alias (Prim)));
7459 -- If the DTC_Entity attribute is already set we can also output
7460 -- the name of the interface covered by this primitive (if any)
7462 if Present (DTC_Entity (Alias (Prim)))
7463 and then Is_Interface (Scope (DTC_Entity (Alias (Prim))))
7465 Write_Str (" from interface ");
7466 Write_Name (Chars (Scope (DTC_Entity (Alias (Prim)))));
7469 if Present (Interface_Alias (Prim)) then
7470 Write_Str (", AI_Alias of ");
7472 (Chars (Find_Dispatching_Type (Interface_Alias (Prim))));
7474 Write_Int (Int (Interface_Alias (Prim)));
7480 -- Display the final position of this primitive in its associated
7481 -- (primary or secondary) dispatch table
7483 if Present (DTC_Entity (Prim))
7484 and then DT_Position (Prim) /= No_Uint
7486 Write_Str (" at #");
7487 Write_Int (UI_To_Int (DT_Position (Prim)));
7490 if Is_Abstract_Subprogram (Prim) then
7491 Write_Str (" is abstract;");
7493 -- Check if this is a null primitive
7495 elsif Comes_From_Source (Prim)
7496 and then Ekind (Prim) = E_Procedure
7497 and then Null_Present (Parent (Prim))
7499 Write_Str (" is null;");
7502 if Is_Eliminated (Ultimate_Alias (Prim)) then
7503 Write_Str (" (eliminated)");