1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2008, 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 Targparm; use Targparm;
63 with Tbuild; use Tbuild;
64 with Uintp; use Uintp;
66 package body Exp_Disp is
68 -----------------------
69 -- Local Subprograms --
70 -----------------------
72 function Default_Prim_Op_Position (E : Entity_Id) return Uint;
73 -- Ada 2005 (AI-251): Returns the fixed position in the dispatch table
74 -- of the default primitive operations.
76 function Has_DT (Typ : Entity_Id) return Boolean;
77 pragma Inline (Has_DT);
78 -- Returns true if we generate a dispatch table for tagged type Typ
80 function Is_Predefined_Dispatching_Alias (Prim : Entity_Id) return Boolean;
81 -- Returns true if Prim is not a predefined dispatching primitive but it is
82 -- an alias of a predefined dispatching primitive (i.e. through a renaming)
84 function Original_View_In_Visible_Part (Typ : Entity_Id) return Boolean;
85 -- Check if the type has a private view or if the public view appears
86 -- in the visible part of a package spec.
90 Typ : Entity_Id) return Node_Id;
91 -- Ada 2005 (AI-345): Determine the primitive operation kind of Prim
92 -- according to its type Typ. Return a reference to an RE_Prim_Op_Kind
95 function Tagged_Kind (T : Entity_Id) return Node_Id;
96 -- Ada 2005 (AI-345): Determine the tagged kind of T and return a reference
97 -- to an RE_Tagged_Kind enumeration value.
99 ------------------------
100 -- Building_Static_DT --
101 ------------------------
103 function Building_Static_DT (Typ : Entity_Id) return Boolean is
104 Root_Typ : Entity_Id := Root_Type (Typ);
107 -- Handle private types
109 if Present (Full_View (Root_Typ)) then
110 Root_Typ := Full_View (Root_Typ);
113 return Static_Dispatch_Tables
114 and then Is_Library_Level_Tagged_Type (Typ)
116 -- If the type is derived from a CPP class we cannot statically
117 -- build the dispatch tables because we must inherit primitives
118 -- from the CPP side.
120 and then not Is_CPP_Class (Root_Typ);
121 end Building_Static_DT;
123 ----------------------------------
124 -- Build_Static_Dispatch_Tables --
125 ----------------------------------
127 procedure Build_Static_Dispatch_Tables (N : Entity_Id) is
128 Target_List : List_Id;
130 procedure Build_Dispatch_Tables (List : List_Id);
131 -- Build the static dispatch table of tagged types found in the list of
132 -- declarations. The generated nodes are added at the end of Target_List
134 procedure Build_Package_Dispatch_Tables (N : Node_Id);
135 -- Build static dispatch tables associated with package declaration N
137 ---------------------------
138 -- Build_Dispatch_Tables --
139 ---------------------------
141 procedure Build_Dispatch_Tables (List : List_Id) is
146 while Present (D) loop
148 -- Handle nested packages and package bodies recursively. The
149 -- generated code is placed on the Target_List established for
150 -- the enclosing compilation unit.
152 if Nkind (D) = N_Package_Declaration then
153 Build_Package_Dispatch_Tables (D);
155 elsif Nkind (D) = N_Package_Body then
156 Build_Dispatch_Tables (Declarations (D));
158 elsif Nkind (D) = N_Package_Body_Stub
159 and then Present (Library_Unit (D))
161 Build_Dispatch_Tables
162 (Declarations (Proper_Body (Unit (Library_Unit (D)))));
164 -- Handle full type declarations and derivations of library
165 -- level tagged types
167 elsif (Nkind (D) = N_Full_Type_Declaration
168 or else Nkind (D) = N_Derived_Type_Definition)
169 and then Is_Library_Level_Tagged_Type (Defining_Entity (D))
170 and then Ekind (Defining_Entity (D)) /= E_Record_Subtype
171 and then not Is_Private_Type (Defining_Entity (D))
173 Insert_List_After_And_Analyze (Last (Target_List),
174 Make_DT (Defining_Entity (D)));
176 -- Handle private types of library level tagged types. We must
177 -- exchange the private and full-view to ensure the correct
178 -- expansion. If the full view is a synchronized type ignore
179 -- the type because the table will be built for the corresponding
180 -- record type, that has its own declaration.
182 elsif (Nkind (D) = N_Private_Type_Declaration
183 or else Nkind (D) = N_Private_Extension_Declaration)
184 and then Present (Full_View (Defining_Entity (D)))
187 E1 : constant Entity_Id := Defining_Entity (D);
188 E2 : constant Entity_Id := Full_View (E1);
191 if Is_Library_Level_Tagged_Type (E2)
192 and then Ekind (E2) /= E_Record_Subtype
193 and then not Is_Concurrent_Type (E2)
195 Exchange_Declarations (E1);
196 Insert_List_After_And_Analyze (Last (Target_List),
198 Exchange_Declarations (E2);
205 end Build_Dispatch_Tables;
207 -----------------------------------
208 -- Build_Package_Dispatch_Tables --
209 -----------------------------------
211 procedure Build_Package_Dispatch_Tables (N : Node_Id) is
212 Spec : constant Node_Id := Specification (N);
213 Id : constant Entity_Id := Defining_Entity (N);
214 Vis_Decls : constant List_Id := Visible_Declarations (Spec);
215 Priv_Decls : constant List_Id := Private_Declarations (Spec);
220 if Present (Priv_Decls) then
221 Build_Dispatch_Tables (Vis_Decls);
222 Build_Dispatch_Tables (Priv_Decls);
224 elsif Present (Vis_Decls) then
225 Build_Dispatch_Tables (Vis_Decls);
229 end Build_Package_Dispatch_Tables;
231 -- Start of processing for Build_Static_Dispatch_Tables
234 if not Expander_Active
235 or else VM_Target /= No_VM
240 if Nkind (N) = N_Package_Declaration then
242 Spec : constant Node_Id := Specification (N);
243 Vis_Decls : constant List_Id := Visible_Declarations (Spec);
244 Priv_Decls : constant List_Id := Private_Declarations (Spec);
247 if Present (Priv_Decls)
248 and then Is_Non_Empty_List (Priv_Decls)
250 Target_List := Priv_Decls;
252 elsif not Present (Vis_Decls) then
253 Target_List := New_List;
254 Set_Private_Declarations (Spec, Target_List);
256 Target_List := Vis_Decls;
259 Build_Package_Dispatch_Tables (N);
262 else pragma Assert (Nkind (N) = N_Package_Body);
263 Target_List := Declarations (N);
264 Build_Dispatch_Tables (Target_List);
266 end Build_Static_Dispatch_Tables;
268 ------------------------------
269 -- Default_Prim_Op_Position --
270 ------------------------------
272 function Default_Prim_Op_Position (E : Entity_Id) return Uint is
273 TSS_Name : TSS_Name_Type;
276 Get_Name_String (Chars (E));
279 (Name_Buffer (Name_Len - TSS_Name'Length + 1 .. Name_Len));
281 if Chars (E) = Name_uSize then
284 elsif Chars (E) = Name_uAlignment then
287 elsif TSS_Name = TSS_Stream_Read then
290 elsif TSS_Name = TSS_Stream_Write then
293 elsif TSS_Name = TSS_Stream_Input then
296 elsif TSS_Name = TSS_Stream_Output then
299 elsif Chars (E) = Name_Op_Eq then
302 elsif Chars (E) = Name_uAssign then
305 elsif TSS_Name = TSS_Deep_Adjust then
308 elsif TSS_Name = TSS_Deep_Finalize then
311 elsif Ada_Version >= Ada_05 then
312 if Chars (E) = Name_uDisp_Asynchronous_Select then
315 elsif Chars (E) = Name_uDisp_Conditional_Select then
318 elsif Chars (E) = Name_uDisp_Get_Prim_Op_Kind then
321 elsif Chars (E) = Name_uDisp_Get_Task_Id then
324 elsif Chars (E) = Name_uDisp_Requeue then
327 elsif Chars (E) = Name_uDisp_Timed_Select then
333 end Default_Prim_Op_Position;
335 -----------------------------
336 -- Expand_Dispatching_Call --
337 -----------------------------
339 procedure Expand_Dispatching_Call (Call_Node : Node_Id) is
340 Loc : constant Source_Ptr := Sloc (Call_Node);
341 Call_Typ : constant Entity_Id := Etype (Call_Node);
343 Ctrl_Arg : constant Node_Id := Controlling_Argument (Call_Node);
344 Ctrl_Typ : constant Entity_Id := Base_Type (Etype (Ctrl_Arg));
345 Param_List : constant List_Id := Parameter_Associations (Call_Node);
350 New_Call_Name : Node_Id;
351 New_Params : List_Id := No_List;
354 Subp_Ptr_Typ : Entity_Id;
355 Subp_Typ : Entity_Id;
357 Eq_Prim_Op : Entity_Id := Empty;
358 Controlling_Tag : Node_Id;
360 function New_Value (From : Node_Id) return Node_Id;
361 -- From is the original Expression. New_Value is equivalent to a call
362 -- to Duplicate_Subexpr with an explicit dereference when From is an
369 function New_Value (From : Node_Id) return Node_Id is
370 Res : constant Node_Id := Duplicate_Subexpr (From);
372 if Is_Access_Type (Etype (From)) then
374 Make_Explicit_Dereference (Sloc (From),
381 -- Start of processing for Expand_Dispatching_Call
384 if No_Run_Time_Mode then
385 Error_Msg_CRT ("tagged types", Call_Node);
389 -- Expand_Dispatching_Call is called directly from the semantics,
390 -- so we need a check to see whether expansion is active before
391 -- proceeding. In addition, there is no need to expand the call
392 -- if we are compiling under restriction No_Dispatching_Calls;
393 -- the semantic analyzer has previously notified the violation
394 -- of this restriction.
396 if not Expander_Active
397 or else Restriction_Active (No_Dispatching_Calls)
402 -- Set subprogram. If this is an inherited operation that was
403 -- overridden, the body that is being called is its alias.
405 Subp := Entity (Name (Call_Node));
407 if Present (Alias (Subp))
408 and then Is_Inherited_Operation (Subp)
409 and then No (DTC_Entity (Subp))
411 Subp := Alias (Subp);
414 -- Definition of the class-wide type and the tagged type
416 -- If the controlling argument is itself a tag rather than a tagged
417 -- object, then use the class-wide type associated with the subprogram's
418 -- controlling type. This case can occur when a call to an inherited
419 -- primitive has an actual that originated from a default parameter
420 -- given by a tag-indeterminate call and when there is no other
421 -- controlling argument providing the tag (AI-239 requires dispatching).
422 -- This capability of dispatching directly by tag is also needed by the
423 -- implementation of AI-260 (for the generic dispatching constructors).
425 if Ctrl_Typ = RTE (RE_Tag)
426 or else (RTE_Available (RE_Interface_Tag)
427 and then Ctrl_Typ = RTE (RE_Interface_Tag))
429 CW_Typ := Class_Wide_Type (Find_Dispatching_Type (Subp));
431 -- Class_Wide_Type is applied to the expressions used to initialize
432 -- CW_Typ, to ensure that CW_Typ always denotes a class-wide type, since
433 -- there are cases where the controlling type is resolved to a specific
434 -- type (such as for designated types of arguments such as CW'Access).
436 elsif Is_Access_Type (Ctrl_Typ) then
437 CW_Typ := Class_Wide_Type (Designated_Type (Ctrl_Typ));
440 CW_Typ := Class_Wide_Type (Ctrl_Typ);
443 Typ := Root_Type (CW_Typ);
445 if Ekind (Typ) = E_Incomplete_Type then
446 Typ := Non_Limited_View (Typ);
449 if not Is_Limited_Type (Typ) then
450 Eq_Prim_Op := Find_Prim_Op (Typ, Name_Op_Eq);
453 -- Dispatching call to C++ primitive. Create a new parameter list
454 -- with no tag checks.
456 if Is_CPP_Class (Typ) then
457 New_Params := New_List;
458 Param := First_Actual (Call_Node);
459 while Present (Param) loop
460 Append_To (New_Params, Relocate_Node (Param));
464 -- Dispatching call to Ada primitive
466 elsif Present (Param_List) then
468 -- Generate the Tag checks when appropriate
470 New_Params := New_List;
471 Param := First_Actual (Call_Node);
472 while Present (Param) loop
474 -- No tag check with itself
476 if Param = Ctrl_Arg then
477 Append_To (New_Params,
478 Duplicate_Subexpr_Move_Checks (Param));
480 -- No tag check for parameter whose type is neither tagged nor
481 -- access to tagged (for access parameters)
483 elsif No (Find_Controlling_Arg (Param)) then
484 Append_To (New_Params, Relocate_Node (Param));
486 -- No tag check for function dispatching on result if the
487 -- Tag given by the context is this one
489 elsif Find_Controlling_Arg (Param) = Ctrl_Arg then
490 Append_To (New_Params, Relocate_Node (Param));
492 -- "=" is the only dispatching operation allowed to get
493 -- operands with incompatible tags (it just returns false).
494 -- We use Duplicate_Subexpr_Move_Checks instead of calling
495 -- Relocate_Node because the value will be duplicated to
498 elsif Subp = Eq_Prim_Op then
499 Append_To (New_Params,
500 Duplicate_Subexpr_Move_Checks (Param));
502 -- No check in presence of suppress flags
504 elsif Tag_Checks_Suppressed (Etype (Param))
505 or else (Is_Access_Type (Etype (Param))
506 and then Tag_Checks_Suppressed
507 (Designated_Type (Etype (Param))))
509 Append_To (New_Params, Relocate_Node (Param));
511 -- Optimization: no tag checks if the parameters are identical
513 elsif Is_Entity_Name (Param)
514 and then Is_Entity_Name (Ctrl_Arg)
515 and then Entity (Param) = Entity (Ctrl_Arg)
517 Append_To (New_Params, Relocate_Node (Param));
519 -- Now we need to generate the Tag check
522 -- Generate code for tag equality check
523 -- Perhaps should have Checks.Apply_Tag_Equality_Check???
525 Insert_Action (Ctrl_Arg,
526 Make_Implicit_If_Statement (Call_Node,
530 Make_Selected_Component (Loc,
531 Prefix => New_Value (Ctrl_Arg),
534 (First_Tag_Component (Typ), Loc)),
537 Make_Selected_Component (Loc,
539 Unchecked_Convert_To (Typ, New_Value (Param)),
542 (First_Tag_Component (Typ), Loc))),
545 New_List (New_Constraint_Error (Loc))));
547 Append_To (New_Params, Relocate_Node (Param));
554 -- Generate the appropriate subprogram pointer type
556 if Etype (Subp) = Typ then
559 Res_Typ := Etype (Subp);
562 Subp_Typ := Create_Itype (E_Subprogram_Type, Call_Node);
563 Subp_Ptr_Typ := Create_Itype (E_Access_Subprogram_Type, Call_Node);
564 Set_Etype (Subp_Typ, Res_Typ);
565 Set_Returns_By_Ref (Subp_Typ, Returns_By_Ref (Subp));
567 -- Create a new list of parameters which is a copy of the old formal
568 -- list including the creation of a new set of matching entities.
571 Old_Formal : Entity_Id := First_Formal (Subp);
572 New_Formal : Entity_Id;
573 Extra : Entity_Id := Empty;
576 if Present (Old_Formal) then
577 New_Formal := New_Copy (Old_Formal);
578 Set_First_Entity (Subp_Typ, New_Formal);
579 Param := First_Actual (Call_Node);
582 Set_Scope (New_Formal, Subp_Typ);
584 -- Change all the controlling argument types to be class-wide
585 -- to avoid a recursion in dispatching.
587 if Is_Controlling_Formal (New_Formal) then
588 Set_Etype (New_Formal, Etype (Param));
591 -- If the type of the formal is an itype, there was code here
592 -- introduced in 1998 in revision 1.46, to create a new itype
593 -- by copy. This seems useless, and in fact leads to semantic
594 -- errors when the itype is the completion of a type derived
595 -- from a private type.
598 Next_Formal (Old_Formal);
599 exit when No (Old_Formal);
601 Set_Next_Entity (New_Formal, New_Copy (Old_Formal));
602 Next_Entity (New_Formal);
606 Set_Next_Entity (New_Formal, Empty);
607 Set_Last_Entity (Subp_Typ, Extra);
610 -- Now that the explicit formals have been duplicated, any extra
611 -- formals needed by the subprogram must be created.
613 if Present (Extra) then
614 Set_Extra_Formal (Extra, Empty);
617 Create_Extra_Formals (Subp_Typ);
620 -- Complete description of pointer type, including size information, as
621 -- must be done with itypes to prevent order-of-elaboration anomalies
624 Set_Etype (Subp_Ptr_Typ, Subp_Ptr_Typ);
625 Set_Directly_Designated_Type (Subp_Ptr_Typ, Subp_Typ);
626 Set_Convention (Subp_Ptr_Typ, Convention (Subp_Typ));
627 Layout_Type (Subp_Ptr_Typ);
629 -- If the controlling argument is a value of type Ada.Tag or an abstract
630 -- interface class-wide type then use it directly. Otherwise, the tag
631 -- must be extracted from the controlling object.
633 if Ctrl_Typ = RTE (RE_Tag)
634 or else (RTE_Available (RE_Interface_Tag)
635 and then Ctrl_Typ = RTE (RE_Interface_Tag))
637 Controlling_Tag := Duplicate_Subexpr (Ctrl_Arg);
639 -- Extract the tag from an unchecked type conversion. Done to avoid
640 -- the expansion of additional code just to obtain the value of such
641 -- tag because the current management of interface type conversions
642 -- generates in some cases this unchecked type conversion with the
643 -- tag of the object (see Expand_Interface_Conversion).
645 elsif Nkind (Ctrl_Arg) = N_Unchecked_Type_Conversion
647 (Etype (Expression (Ctrl_Arg)) = RTE (RE_Tag)
649 (RTE_Available (RE_Interface_Tag)
651 Etype (Expression (Ctrl_Arg)) = RTE (RE_Interface_Tag)))
653 Controlling_Tag := Duplicate_Subexpr (Expression (Ctrl_Arg));
655 -- Ada 2005 (AI-251): Abstract interface class-wide type
657 elsif Is_Interface (Ctrl_Typ)
658 and then Is_Class_Wide_Type (Ctrl_Typ)
660 Controlling_Tag := Duplicate_Subexpr (Ctrl_Arg);
664 Make_Selected_Component (Loc,
665 Prefix => Duplicate_Subexpr_Move_Checks (Ctrl_Arg),
666 Selector_Name => New_Reference_To (DTC_Entity (Subp), Loc));
669 -- Handle dispatching calls to predefined primitives
671 if Is_Predefined_Dispatching_Operation (Subp)
672 or else Is_Predefined_Dispatching_Alias (Subp)
675 Unchecked_Convert_To (Subp_Ptr_Typ,
676 Build_Get_Predefined_Prim_Op_Address (Loc,
677 Tag_Node => Controlling_Tag,
678 Position => DT_Position (Subp)));
680 -- Handle dispatching calls to user-defined primitives
684 Unchecked_Convert_To (Subp_Ptr_Typ,
685 Build_Get_Prim_Op_Address (Loc,
686 Typ => Find_Dispatching_Type (Subp),
687 Tag_Node => Controlling_Tag,
688 Position => DT_Position (Subp)));
691 if Nkind (Call_Node) = N_Function_Call then
694 Make_Function_Call (Loc,
695 Name => New_Call_Name,
696 Parameter_Associations => New_Params);
698 -- If this is a dispatching "=", we must first compare the tags so
699 -- we generate: x.tag = y.tag and then x = y
701 if Subp = Eq_Prim_Op then
702 Param := First_Actual (Call_Node);
708 Make_Selected_Component (Loc,
709 Prefix => New_Value (Param),
711 New_Reference_To (First_Tag_Component (Typ),
715 Make_Selected_Component (Loc,
717 Unchecked_Convert_To (Typ,
718 New_Value (Next_Actual (Param))),
720 New_Reference_To (First_Tag_Component (Typ),
722 Right_Opnd => New_Call);
727 Make_Procedure_Call_Statement (Loc,
728 Name => New_Call_Name,
729 Parameter_Associations => New_Params);
732 Rewrite (Call_Node, New_Call);
734 -- Suppress all checks during the analysis of the expanded code
735 -- to avoid the generation of spurious warnings under ZFP run-time.
737 Analyze_And_Resolve (Call_Node, Call_Typ, Suppress => All_Checks);
738 end Expand_Dispatching_Call;
740 ---------------------------------
741 -- Expand_Interface_Conversion --
742 ---------------------------------
744 procedure Expand_Interface_Conversion
746 Is_Static : Boolean := True)
748 Loc : constant Source_Ptr := Sloc (N);
749 Etyp : constant Entity_Id := Etype (N);
750 Operand : constant Node_Id := Expression (N);
751 Operand_Typ : Entity_Id := Etype (Operand);
753 Iface_Typ : Entity_Id := Etype (N);
754 Iface_Tag : Entity_Id;
757 -- Ada 2005 (AI-345): Handle synchronized interface type derivations
759 if Is_Concurrent_Type (Operand_Typ) then
760 Operand_Typ := Base_Type (Corresponding_Record_Type (Operand_Typ));
763 -- Handle access to class-wide interface types
765 if Is_Access_Type (Iface_Typ) then
766 Iface_Typ := Etype (Directly_Designated_Type (Iface_Typ));
769 -- Handle class-wide interface types. This conversion can appear
770 -- explicitly in the source code. Example: I'Class (Obj)
772 if Is_Class_Wide_Type (Iface_Typ) then
773 Iface_Typ := Root_Type (Iface_Typ);
776 -- If the target type is a tagged synchronized type, the dispatch table
777 -- info is in the corresponding record type.
779 if Is_Concurrent_Type (Iface_Typ) then
780 Iface_Typ := Corresponding_Record_Type (Iface_Typ);
783 -- Freeze the entity associated with the target interface to have
784 -- available the attribute Access_Disp_Table.
786 Freeze_Before (N, Iface_Typ);
788 pragma Assert (not Is_Static
789 or else (not Is_Class_Wide_Type (Iface_Typ)
790 and then Is_Interface (Iface_Typ)));
792 if VM_Target /= No_VM then
794 -- For VM, just do a conversion ???
796 Rewrite (N, Unchecked_Convert_To (Etype (N), N));
801 if not Is_Static then
803 -- Give error if configurable run time and Displace not available
805 if not RTE_Available (RE_Displace) then
806 Error_Msg_CRT ("dynamic interface conversion", N);
810 -- Handle conversion of access-to-class-wide interface types. Target
811 -- can be an access to an object or an access to another class-wide
812 -- interface (see -1- and -2- in the following example):
814 -- type Iface1_Ref is access all Iface1'Class;
815 -- type Iface2_Ref is access all Iface1'Class;
817 -- Acc1 : Iface1_Ref := new ...
818 -- Obj : Obj_Ref := Obj_Ref (Acc); -- 1
819 -- Acc2 : Iface2_Ref := Iface2_Ref (Acc); -- 2
821 if Is_Access_Type (Operand_Typ) then
823 Unchecked_Convert_To (Etype (N),
824 Make_Function_Call (Loc,
825 Name => New_Reference_To (RTE (RE_Displace), Loc),
826 Parameter_Associations => New_List (
828 Unchecked_Convert_To (RTE (RE_Address),
829 Relocate_Node (Expression (N))),
832 (Node (First_Elmt (Access_Disp_Table (Iface_Typ))),
840 Make_Function_Call (Loc,
841 Name => New_Reference_To (RTE (RE_Displace), Loc),
842 Parameter_Associations => New_List (
843 Make_Attribute_Reference (Loc,
844 Prefix => Relocate_Node (Expression (N)),
845 Attribute_Name => Name_Address),
848 (Node (First_Elmt (Access_Disp_Table (Iface_Typ))),
853 -- If the target is a class-wide interface we change the type of the
854 -- data returned by IW_Convert to indicate that this is a dispatching
858 New_Itype : Entity_Id;
861 New_Itype := Create_Itype (E_Anonymous_Access_Type, N);
862 Set_Etype (New_Itype, New_Itype);
863 Set_Directly_Designated_Type (New_Itype, Etyp);
866 Make_Explicit_Dereference (Loc,
868 Unchecked_Convert_To (New_Itype, Relocate_Node (N))));
870 Freeze_Itype (New_Itype, N);
876 Iface_Tag := Find_Interface_Tag (Operand_Typ, Iface_Typ);
877 pragma Assert (Iface_Tag /= Empty);
879 -- Keep separate access types to interfaces because one internal
880 -- function is used to handle the null value (see following comment)
882 if not Is_Access_Type (Etype (N)) then
884 Unchecked_Convert_To (Etype (N),
885 Make_Selected_Component (Loc,
886 Prefix => Relocate_Node (Expression (N)),
888 New_Occurrence_Of (Iface_Tag, Loc))));
891 -- Build internal function to handle the case in which the
892 -- actual is null. If the actual is null returns null because
893 -- no displacement is required; otherwise performs a type
894 -- conversion that will be expanded in the code that returns
895 -- the value of the displaced actual. That is:
897 -- function Func (O : Address) return Iface_Typ is
898 -- type Op_Typ is access all Operand_Typ;
899 -- Aux : Op_Typ := To_Op_Typ (O);
901 -- if O = Null_Address then
904 -- return Iface_Typ!(Aux.Iface_Tag'Address);
909 Desig_Typ : Entity_Id;
911 New_Typ_Decl : Node_Id;
915 Desig_Typ := Etype (Expression (N));
917 if Is_Access_Type (Desig_Typ) then
918 Desig_Typ := Directly_Designated_Type (Desig_Typ);
921 if Is_Concurrent_Type (Desig_Typ) then
922 Desig_Typ := Base_Type (Corresponding_Record_Type (Desig_Typ));
926 Make_Full_Type_Declaration (Loc,
927 Defining_Identifier =>
928 Make_Defining_Identifier (Loc, New_Internal_Name ('T')),
930 Make_Access_To_Object_Definition (Loc,
932 Null_Exclusion_Present => False,
933 Constant_Present => False,
934 Subtype_Indication =>
935 New_Reference_To (Desig_Typ, Loc)));
938 Make_Simple_Return_Statement (Loc,
939 Unchecked_Convert_To (Etype (N),
940 Make_Attribute_Reference (Loc,
942 Make_Selected_Component (Loc,
945 (Defining_Identifier (New_Typ_Decl),
946 Make_Identifier (Loc, Name_uO)),
948 New_Occurrence_Of (Iface_Tag, Loc)),
949 Attribute_Name => Name_Address))));
951 -- If the type is null-excluding, no need for the null branch.
952 -- Otherwise we need to check for it and return null.
954 if not Can_Never_Be_Null (Etype (N)) then
956 Make_If_Statement (Loc,
959 Left_Opnd => Make_Identifier (Loc, Name_uO),
960 Right_Opnd => New_Reference_To
961 (RTE (RE_Null_Address), Loc)),
963 Then_Statements => New_List (
964 Make_Simple_Return_Statement (Loc,
966 Else_Statements => Stats));
970 Make_Defining_Identifier (Loc,
971 New_Internal_Name ('F'));
974 Make_Subprogram_Body (Loc,
976 Make_Function_Specification (Loc,
977 Defining_Unit_Name => Fent,
979 Parameter_Specifications => New_List (
980 Make_Parameter_Specification (Loc,
981 Defining_Identifier =>
982 Make_Defining_Identifier (Loc, Name_uO),
984 New_Reference_To (RTE (RE_Address), Loc))),
987 New_Reference_To (Etype (N), Loc)),
989 Declarations => New_List (New_Typ_Decl),
991 Handled_Statement_Sequence =>
992 Make_Handled_Sequence_Of_Statements (Loc, Stats));
994 -- Place function body before the expression containing the
995 -- conversion. We suppress all checks because the body of the
996 -- internally generated function already takes care of the case
997 -- in which the actual is null; therefore there is no need to
998 -- double check that the pointer is not null when the program
999 -- executes the alternative that performs the type conversion).
1001 Insert_Action (N, Func, Suppress => All_Checks);
1003 if Is_Access_Type (Etype (Expression (N))) then
1005 -- Generate: Func (Address!(Expression))
1008 Make_Function_Call (Loc,
1009 Name => New_Reference_To (Fent, Loc),
1010 Parameter_Associations => New_List (
1011 Unchecked_Convert_To (RTE (RE_Address),
1012 Relocate_Node (Expression (N))))));
1015 -- Generate: Func (Operand_Typ!(Expression)'Address)
1018 Make_Function_Call (Loc,
1019 Name => New_Reference_To (Fent, Loc),
1020 Parameter_Associations => New_List (
1021 Make_Attribute_Reference (Loc,
1022 Prefix => Unchecked_Convert_To (Operand_Typ,
1023 Relocate_Node (Expression (N))),
1024 Attribute_Name => Name_Address))));
1030 end Expand_Interface_Conversion;
1032 ------------------------------
1033 -- Expand_Interface_Actuals --
1034 ------------------------------
1036 procedure Expand_Interface_Actuals (Call_Node : Node_Id) is
1038 Actual_Dup : Node_Id;
1039 Actual_Typ : Entity_Id;
1041 Conversion : Node_Id;
1043 Formal_Typ : Entity_Id;
1045 Formal_DDT : Entity_Id;
1046 Actual_DDT : Entity_Id;
1049 -- This subprogram is called directly from the semantics, so we need a
1050 -- check to see whether expansion is active before proceeding.
1052 if not Expander_Active then
1056 -- Call using access to subprogram with explicit dereference
1058 if Nkind (Name (Call_Node)) = N_Explicit_Dereference then
1059 Subp := Etype (Name (Call_Node));
1061 -- Call using selected component
1063 elsif Nkind (Name (Call_Node)) = N_Selected_Component then
1064 Subp := Entity (Selector_Name (Name (Call_Node)));
1066 -- Call using direct name
1069 Subp := Entity (Name (Call_Node));
1072 -- Ada 2005 (AI-251): Look for interface type formals to force "this"
1075 Formal := First_Formal (Subp);
1076 Actual := First_Actual (Call_Node);
1077 while Present (Formal) loop
1078 Formal_Typ := Etype (Formal);
1080 if Ekind (Formal_Typ) = E_Record_Type_With_Private then
1081 Formal_Typ := Full_View (Formal_Typ);
1084 if Is_Access_Type (Formal_Typ) then
1085 Formal_DDT := Directly_Designated_Type (Formal_Typ);
1088 Actual_Typ := Etype (Actual);
1090 if Is_Access_Type (Actual_Typ) then
1091 Actual_DDT := Directly_Designated_Type (Actual_Typ);
1094 if Is_Interface (Formal_Typ)
1095 and then Is_Class_Wide_Type (Formal_Typ)
1097 -- No need to displace the pointer if the type of the actual
1098 -- coindices with the type of the formal.
1100 if Actual_Typ = Formal_Typ then
1103 -- No need to displace the pointer if the interface type is
1104 -- a parent of the type of the actual because in this case the
1105 -- interface primitives are located in the primary dispatch table.
1107 elsif Is_Ancestor (Formal_Typ, Actual_Typ) then
1110 -- Implicit conversion to the class-wide formal type to force
1111 -- the displacement of the pointer.
1114 Conversion := Convert_To (Formal_Typ, Relocate_Node (Actual));
1115 Rewrite (Actual, Conversion);
1116 Analyze_And_Resolve (Actual, Formal_Typ);
1119 -- Access to class-wide interface type
1121 elsif Is_Access_Type (Formal_Typ)
1122 and then Is_Interface (Formal_DDT)
1123 and then Is_Class_Wide_Type (Formal_DDT)
1124 and then Interface_Present_In_Ancestor
1126 Iface => Etype (Formal_DDT))
1128 -- Handle attributes 'Access and 'Unchecked_Access
1130 if Nkind (Actual) = N_Attribute_Reference
1132 (Attribute_Name (Actual) = Name_Access
1133 or else Attribute_Name (Actual) = Name_Unchecked_Access)
1135 -- This case must have been handled by the analysis and
1136 -- expansion of 'Access. The only exception is when types
1137 -- match and no further expansion is required.
1139 pragma Assert (Base_Type (Etype (Prefix (Actual)))
1140 = Base_Type (Formal_DDT));
1143 -- No need to displace the pointer if the type of the actual
1144 -- coincides with the type of the formal.
1146 elsif Actual_DDT = Formal_DDT then
1149 -- No need to displace the pointer if the interface type is
1150 -- a parent of the type of the actual because in this case the
1151 -- interface primitives are located in the primary dispatch table.
1153 elsif Is_Ancestor (Formal_DDT, Actual_DDT) then
1157 Actual_Dup := Relocate_Node (Actual);
1159 if From_With_Type (Actual_Typ) then
1161 -- If the type of the actual parameter comes from a limited
1162 -- with-clause and the non-limited view is already available
1163 -- we replace the anonymous access type by a duplicate
1164 -- declaration whose designated type is the non-limited view
1166 if Ekind (Actual_DDT) = E_Incomplete_Type
1167 and then Present (Non_Limited_View (Actual_DDT))
1169 Anon := New_Copy (Actual_Typ);
1171 if Is_Itype (Anon) then
1172 Set_Scope (Anon, Current_Scope);
1175 Set_Directly_Designated_Type (Anon,
1176 Non_Limited_View (Actual_DDT));
1177 Set_Etype (Actual_Dup, Anon);
1179 elsif Is_Class_Wide_Type (Actual_DDT)
1180 and then Ekind (Etype (Actual_DDT)) = E_Incomplete_Type
1181 and then Present (Non_Limited_View (Etype (Actual_DDT)))
1183 Anon := New_Copy (Actual_Typ);
1185 if Is_Itype (Anon) then
1186 Set_Scope (Anon, Current_Scope);
1189 Set_Directly_Designated_Type (Anon,
1190 New_Copy (Actual_DDT));
1191 Set_Class_Wide_Type (Directly_Designated_Type (Anon),
1192 New_Copy (Class_Wide_Type (Actual_DDT)));
1193 Set_Etype (Directly_Designated_Type (Anon),
1194 Non_Limited_View (Etype (Actual_DDT)));
1196 Class_Wide_Type (Directly_Designated_Type (Anon)),
1197 Non_Limited_View (Etype (Actual_DDT)));
1198 Set_Etype (Actual_Dup, Anon);
1202 Conversion := Convert_To (Formal_Typ, Actual_Dup);
1203 Rewrite (Actual, Conversion);
1204 Analyze_And_Resolve (Actual, Formal_Typ);
1208 Next_Actual (Actual);
1209 Next_Formal (Formal);
1211 end Expand_Interface_Actuals;
1213 ----------------------------
1214 -- Expand_Interface_Thunk --
1215 ----------------------------
1217 procedure Expand_Interface_Thunk
1219 Thunk_Id : out Entity_Id;
1220 Thunk_Code : out Node_Id)
1222 Loc : constant Source_Ptr := Sloc (Prim);
1223 Actuals : constant List_Id := New_List;
1224 Decl : constant List_Id := New_List;
1225 Formals : constant List_Id := New_List;
1227 Controlling_Typ : Entity_Id;
1232 Offset_To_Top : Node_Id;
1234 Target_Formal : Entity_Id;
1238 Thunk_Code := Empty;
1240 -- Traverse the list of alias to find the final target
1243 while Present (Alias (Target)) loop
1244 Target := Alias (Target);
1247 -- In case of primitives that are functions without formals and
1248 -- a controlling result there is no need to build the thunk.
1250 if not Present (First_Formal (Target)) then
1251 pragma Assert (Ekind (Target) = E_Function
1252 and then Has_Controlling_Result (Target));
1256 -- Duplicate the formals
1258 Formal := First_Formal (Target);
1259 while Present (Formal) loop
1261 Make_Parameter_Specification (Loc,
1262 Defining_Identifier =>
1263 Make_Defining_Identifier (Sloc (Formal),
1264 Chars => Chars (Formal)),
1265 In_Present => In_Present (Parent (Formal)),
1266 Out_Present => Out_Present (Parent (Formal)),
1268 New_Reference_To (Etype (Formal), Loc),
1269 Expression => New_Copy_Tree (Expression (Parent (Formal)))));
1271 Next_Formal (Formal);
1274 Controlling_Typ := Find_Dispatching_Type (Target);
1276 Target_Formal := First_Formal (Target);
1277 Formal := First (Formals);
1278 while Present (Formal) loop
1279 if Ekind (Target_Formal) = E_In_Parameter
1280 and then Ekind (Etype (Target_Formal)) = E_Anonymous_Access_Type
1281 and then Directly_Designated_Type (Etype (Target_Formal))
1286 -- type T is access all <<type of the target formal>>
1287 -- S : Storage_Offset := Storage_Offset!(Formal)
1288 -- - Offset_To_Top (address!(Formal))
1291 Make_Full_Type_Declaration (Loc,
1292 Defining_Identifier =>
1293 Make_Defining_Identifier (Loc,
1294 New_Internal_Name ('T')),
1296 Make_Access_To_Object_Definition (Loc,
1297 All_Present => True,
1298 Null_Exclusion_Present => False,
1299 Constant_Present => False,
1300 Subtype_Indication =>
1302 (Directly_Designated_Type
1303 (Etype (Target_Formal)), Loc)));
1306 Unchecked_Convert_To (RTE (RE_Address),
1307 New_Reference_To (Defining_Identifier (Formal), Loc));
1309 if not RTE_Available (RE_Offset_To_Top) then
1311 Build_Offset_To_Top (Loc, New_Arg);
1314 Make_Function_Call (Loc,
1315 Name => New_Reference_To (RTE (RE_Offset_To_Top), Loc),
1316 Parameter_Associations => New_List (New_Arg));
1320 Make_Object_Declaration (Loc,
1321 Defining_Identifier =>
1322 Make_Defining_Identifier (Loc,
1323 New_Internal_Name ('S')),
1324 Constant_Present => True,
1325 Object_Definition =>
1326 New_Reference_To (RTE (RE_Storage_Offset), Loc),
1328 Make_Op_Subtract (Loc,
1330 Unchecked_Convert_To
1331 (RTE (RE_Storage_Offset),
1332 New_Reference_To (Defining_Identifier (Formal), Loc)),
1336 Append_To (Decl, Decl_2);
1337 Append_To (Decl, Decl_1);
1339 -- Reference the new actual. Generate:
1343 Unchecked_Convert_To
1344 (Defining_Identifier (Decl_2),
1345 New_Reference_To (Defining_Identifier (Decl_1), Loc)));
1347 elsif Etype (Target_Formal) = Controlling_Typ then
1350 -- S1 : Storage_Offset := Storage_Offset!(Formal'Address)
1351 -- - Offset_To_Top (Formal'Address)
1352 -- S2 : Addr_Ptr := Addr_Ptr!(S1)
1355 Make_Attribute_Reference (Loc,
1357 New_Reference_To (Defining_Identifier (Formal), Loc),
1361 if not RTE_Available (RE_Offset_To_Top) then
1363 Build_Offset_To_Top (Loc, New_Arg);
1366 Make_Function_Call (Loc,
1367 Name => New_Reference_To (RTE (RE_Offset_To_Top), Loc),
1368 Parameter_Associations => New_List (New_Arg));
1372 Make_Object_Declaration (Loc,
1373 Defining_Identifier =>
1374 Make_Defining_Identifier (Loc, New_Internal_Name ('S')),
1375 Constant_Present => True,
1376 Object_Definition =>
1377 New_Reference_To (RTE (RE_Storage_Offset), Loc),
1379 Make_Op_Subtract (Loc,
1381 Unchecked_Convert_To
1382 (RTE (RE_Storage_Offset),
1383 Make_Attribute_Reference (Loc,
1386 (Defining_Identifier (Formal), Loc),
1387 Attribute_Name => Name_Address)),
1392 Make_Object_Declaration (Loc,
1393 Defining_Identifier =>
1394 Make_Defining_Identifier (Loc, New_Internal_Name ('S')),
1395 Constant_Present => True,
1396 Object_Definition => New_Reference_To (RTE (RE_Addr_Ptr), Loc),
1398 Unchecked_Convert_To
1400 New_Reference_To (Defining_Identifier (Decl_1), Loc)));
1402 Append_To (Decl, Decl_1);
1403 Append_To (Decl, Decl_2);
1405 -- Reference the new actual. Generate:
1406 -- Target_Formal (S2.all)
1409 Unchecked_Convert_To
1410 (Etype (Target_Formal),
1411 Make_Explicit_Dereference (Loc,
1412 New_Reference_To (Defining_Identifier (Decl_2), Loc))));
1414 -- No special management required for this actual
1418 New_Reference_To (Defining_Identifier (Formal), Loc));
1421 Next_Formal (Target_Formal);
1426 Make_Defining_Identifier (Loc,
1427 Chars => New_Internal_Name ('T'));
1429 Set_Is_Thunk (Thunk_Id);
1431 if Ekind (Target) = E_Procedure then
1433 Make_Subprogram_Body (Loc,
1435 Make_Procedure_Specification (Loc,
1436 Defining_Unit_Name => Thunk_Id,
1437 Parameter_Specifications => Formals),
1438 Declarations => Decl,
1439 Handled_Statement_Sequence =>
1440 Make_Handled_Sequence_Of_Statements (Loc,
1441 Statements => New_List (
1442 Make_Procedure_Call_Statement (Loc,
1443 Name => New_Occurrence_Of (Target, Loc),
1444 Parameter_Associations => Actuals))));
1446 else pragma Assert (Ekind (Target) = E_Function);
1449 Make_Subprogram_Body (Loc,
1451 Make_Function_Specification (Loc,
1452 Defining_Unit_Name => Thunk_Id,
1453 Parameter_Specifications => Formals,
1454 Result_Definition =>
1455 New_Copy (Result_Definition (Parent (Target)))),
1456 Declarations => Decl,
1457 Handled_Statement_Sequence =>
1458 Make_Handled_Sequence_Of_Statements (Loc,
1459 Statements => New_List (
1460 Make_Simple_Return_Statement (Loc,
1461 Make_Function_Call (Loc,
1462 Name => New_Occurrence_Of (Target, Loc),
1463 Parameter_Associations => Actuals)))));
1465 end Expand_Interface_Thunk;
1471 function Has_DT (Typ : Entity_Id) return Boolean is
1473 return not Is_Interface (Typ)
1474 and then not Restriction_Active (No_Dispatching_Calls);
1477 -----------------------------------------
1478 -- Is_Predefined_Dispatching_Operation --
1479 -----------------------------------------
1481 function Is_Predefined_Dispatching_Operation
1482 (E : Entity_Id) return Boolean
1484 TSS_Name : TSS_Name_Type;
1487 if not Is_Dispatching_Operation (E) then
1491 Get_Name_String (Chars (E));
1493 -- Most predefined primitives have internally generated names. Equality
1494 -- must be treated differently; the predefined operation is recognized
1495 -- as a homogeneous binary operator that returns Boolean.
1497 if Name_Len > TSS_Name_Type'Last then
1498 TSS_Name := TSS_Name_Type (Name_Buffer (Name_Len - TSS_Name'Length + 1
1500 if Chars (E) = Name_uSize
1501 or else Chars (E) = Name_uAlignment
1502 or else TSS_Name = TSS_Stream_Read
1503 or else TSS_Name = TSS_Stream_Write
1504 or else TSS_Name = TSS_Stream_Input
1505 or else TSS_Name = TSS_Stream_Output
1507 (Chars (E) = Name_Op_Eq
1508 and then Etype (First_Entity (E)) = Etype (Last_Entity (E)))
1509 or else Chars (E) = Name_uAssign
1510 or else TSS_Name = TSS_Deep_Adjust
1511 or else TSS_Name = TSS_Deep_Finalize
1512 or else Is_Predefined_Interface_Primitive (E)
1519 end Is_Predefined_Dispatching_Operation;
1521 -------------------------------------
1522 -- Is_Predefined_Dispatching_Alias --
1523 -------------------------------------
1525 function Is_Predefined_Dispatching_Alias (Prim : Entity_Id) return Boolean
1530 if not Is_Predefined_Dispatching_Operation (Prim)
1531 and then Present (Alias (Prim))
1534 while Present (Alias (E)) loop
1538 if Is_Predefined_Dispatching_Operation (E) then
1544 end Is_Predefined_Dispatching_Alias;
1546 ---------------------------------------
1547 -- Is_Predefined_Interface_Primitive --
1548 ---------------------------------------
1550 function Is_Predefined_Interface_Primitive (E : Entity_Id) return Boolean is
1552 return Ada_Version >= Ada_05
1553 and then (Chars (E) = Name_uDisp_Asynchronous_Select or else
1554 Chars (E) = Name_uDisp_Conditional_Select or else
1555 Chars (E) = Name_uDisp_Get_Prim_Op_Kind or else
1556 Chars (E) = Name_uDisp_Get_Task_Id or else
1557 Chars (E) = Name_uDisp_Requeue or else
1558 Chars (E) = Name_uDisp_Timed_Select);
1559 end Is_Predefined_Interface_Primitive;
1561 ----------------------------------------
1562 -- Make_Disp_Asynchronous_Select_Body --
1563 ----------------------------------------
1565 -- For interface types, generate:
1567 -- procedure _Disp_Asynchronous_Select
1568 -- (T : in out <Typ>;
1570 -- P : System.Address;
1571 -- B : out System.Storage_Elements.Dummy_Communication_Block;
1576 -- end _Disp_Asynchronous_Select;
1578 -- For protected types, generate:
1580 -- procedure _Disp_Asynchronous_Select
1581 -- (T : in out <Typ>;
1583 -- P : System.Address;
1584 -- B : out System.Storage_Elements.Dummy_Communication_Block;
1588 -- Ada.Tags.Get_Entry_Index (Ada.Tags.Tag (<Typ>VP, S));
1589 -- Bnn : System.Tasking.Protected_Objects.Operations.
1590 -- Communication_Block;
1592 -- System.Tasking.Protected_Objects.Operations.Protected_Entry_Call
1593 -- (T._object'Access,
1594 -- System.Tasking.Protected_Objects.Protected_Entry_Index (I),
1596 -- System.Tasking.Asynchronous_Call,
1598 -- B := System.Storage_Elements.Dummy_Communication_Block (Bnn);
1599 -- end _Disp_Asynchronous_Select;
1601 -- For task types, generate:
1603 -- procedure _Disp_Asynchronous_Select
1604 -- (T : in out <Typ>;
1606 -- P : System.Address;
1607 -- B : out System.Storage_Elements.Dummy_Communication_Block;
1611 -- Ada.Tags.Get_Entry_Index (Ada.Tags.Tag (<Typ>VP, S));
1613 -- System.Tasking.Rendezvous.Task_Entry_Call
1615 -- System.Tasking.Task_Entry_Index (I),
1617 -- System.Tasking.Asynchronous_Call,
1619 -- end _Disp_Asynchronous_Select;
1621 function Make_Disp_Asynchronous_Select_Body
1622 (Typ : Entity_Id) return Node_Id
1624 Com_Block : Entity_Id;
1625 Conc_Typ : Entity_Id := Empty;
1626 Decls : constant List_Id := New_List;
1628 Loc : constant Source_Ptr := Sloc (Typ);
1630 Stmts : constant List_Id := New_List;
1633 pragma Assert (not Restriction_Active (No_Dispatching_Calls));
1635 -- Null body is generated for interface types
1637 if Is_Interface (Typ) then
1639 Make_Subprogram_Body (Loc,
1641 Make_Disp_Asynchronous_Select_Spec (Typ),
1644 Handled_Statement_Sequence =>
1645 Make_Handled_Sequence_Of_Statements (Loc,
1646 New_List (Make_Null_Statement (Loc))));
1649 DT_Ptr := Node (First_Elmt (Access_Disp_Table (Typ)));
1651 if Is_Concurrent_Record_Type (Typ) then
1652 Conc_Typ := Corresponding_Concurrent_Type (Typ);
1656 -- Ada.Tags.Get_Entry_Index (Ada.Tags.Tag! (<type>VP), S);
1658 -- where I will be used to capture the entry index of the primitive
1659 -- wrapper at position S.
1662 Make_Object_Declaration (Loc,
1663 Defining_Identifier =>
1664 Make_Defining_Identifier (Loc, Name_uI),
1665 Object_Definition =>
1666 New_Reference_To (Standard_Integer, Loc),
1668 Make_Function_Call (Loc,
1670 New_Reference_To (RTE (RE_Get_Entry_Index), Loc),
1671 Parameter_Associations =>
1673 Unchecked_Convert_To (RTE (RE_Tag),
1674 New_Reference_To (DT_Ptr, Loc)),
1675 Make_Identifier (Loc, Name_uS)))));
1677 if Ekind (Conc_Typ) = E_Protected_Type then
1680 -- Bnn : Communication_Block;
1683 Make_Defining_Identifier (Loc, New_Internal_Name ('B'));
1686 Make_Object_Declaration (Loc,
1687 Defining_Identifier =>
1689 Object_Definition =>
1690 New_Reference_To (RTE (RE_Communication_Block), Loc)));
1692 -- Build T._object'Access for calls below
1695 Make_Attribute_Reference (Loc,
1696 Attribute_Name => Name_Unchecked_Access,
1698 Make_Selected_Component (Loc,
1699 Prefix => Make_Identifier (Loc, Name_uT),
1700 Selector_Name => Make_Identifier (Loc, Name_uObject)));
1702 case Corresponding_Runtime_Package (Conc_Typ) is
1703 when System_Tasking_Protected_Objects_Entries =>
1706 -- Protected_Entry_Call
1707 -- (T._object'Access, -- Object
1708 -- Protected_Entry_Index! (I), -- E
1709 -- P, -- Uninterpreted_Data
1710 -- Asynchronous_Call, -- Mode
1711 -- Bnn); -- Communication_Block
1713 -- where T is the protected object, I is the entry index, P
1714 -- is the wrapped parameters and B is the name of the
1715 -- communication block.
1718 Make_Procedure_Call_Statement (Loc,
1720 New_Reference_To (RTE (RE_Protected_Entry_Call), Loc),
1721 Parameter_Associations =>
1725 Make_Unchecked_Type_Conversion (Loc, -- entry index
1728 (RTE (RE_Protected_Entry_Index), Loc),
1729 Expression => Make_Identifier (Loc, Name_uI)),
1731 Make_Identifier (Loc, Name_uP), -- parameter block
1732 New_Reference_To ( -- Asynchronous_Call
1733 RTE (RE_Asynchronous_Call), Loc),
1735 New_Reference_To (Com_Block, Loc)))); -- comm block
1737 when System_Tasking_Protected_Objects_Single_Entry =>
1740 -- procedure Protected_Single_Entry_Call
1741 -- (Object : Protection_Entry_Access;
1742 -- Uninterpreted_Data : System.Address;
1743 -- Mode : Call_Modes);
1746 Make_Procedure_Call_Statement (Loc,
1749 (RTE (RE_Protected_Single_Entry_Call), Loc),
1750 Parameter_Associations =>
1754 Make_Attribute_Reference (Loc,
1755 Prefix => Make_Identifier (Loc, Name_uP),
1756 Attribute_Name => Name_Address),
1759 (RTE (RE_Asynchronous_Call), Loc))));
1762 raise Program_Error;
1766 -- B := Dummy_Communication_Block (Bnn);
1769 Make_Assignment_Statement (Loc,
1771 Make_Identifier (Loc, Name_uB),
1773 Make_Unchecked_Type_Conversion (Loc,
1776 RTE (RE_Dummy_Communication_Block), Loc),
1778 New_Reference_To (Com_Block, Loc))));
1781 pragma Assert (Ekind (Conc_Typ) = E_Task_Type);
1785 -- (T._task_id, -- Acceptor
1786 -- Task_Entry_Index! (I), -- E
1787 -- P, -- Uninterpreted_Data
1788 -- Asynchronous_Call, -- Mode
1789 -- F); -- Rendezvous_Successful
1791 -- where T is the task object, I is the entry index, P is the
1792 -- wrapped parameters and F is the status flag.
1795 Make_Procedure_Call_Statement (Loc,
1797 New_Reference_To (RTE (RE_Task_Entry_Call), Loc),
1798 Parameter_Associations =>
1800 Make_Selected_Component (Loc, -- T._task_id
1802 Make_Identifier (Loc, Name_uT),
1804 Make_Identifier (Loc, Name_uTask_Id)),
1806 Make_Unchecked_Type_Conversion (Loc, -- entry index
1808 New_Reference_To (RTE (RE_Task_Entry_Index), Loc),
1810 Make_Identifier (Loc, Name_uI)),
1812 Make_Identifier (Loc, Name_uP), -- parameter block
1813 New_Reference_To ( -- Asynchronous_Call
1814 RTE (RE_Asynchronous_Call), Loc),
1815 Make_Identifier (Loc, Name_uF)))); -- status flag
1820 Make_Subprogram_Body (Loc,
1822 Make_Disp_Asynchronous_Select_Spec (Typ),
1825 Handled_Statement_Sequence =>
1826 Make_Handled_Sequence_Of_Statements (Loc, Stmts));
1827 end Make_Disp_Asynchronous_Select_Body;
1829 ----------------------------------------
1830 -- Make_Disp_Asynchronous_Select_Spec --
1831 ----------------------------------------
1833 function Make_Disp_Asynchronous_Select_Spec
1834 (Typ : Entity_Id) return Node_Id
1836 Loc : constant Source_Ptr := Sloc (Typ);
1837 Def_Id : constant Node_Id :=
1838 Make_Defining_Identifier (Loc,
1839 Name_uDisp_Asynchronous_Select);
1840 Params : constant List_Id := New_List;
1843 pragma Assert (not Restriction_Active (No_Dispatching_Calls));
1845 -- T : in out Typ; -- Object parameter
1846 -- S : Integer; -- Primitive operation slot
1847 -- P : Address; -- Wrapped parameters
1848 -- B : out Dummy_Communication_Block; -- Communication block dummy
1849 -- F : out Boolean; -- Status flag
1851 Append_List_To (Params, New_List (
1853 Make_Parameter_Specification (Loc,
1854 Defining_Identifier =>
1855 Make_Defining_Identifier (Loc, Name_uT),
1857 New_Reference_To (Typ, Loc),
1859 Out_Present => True),
1861 Make_Parameter_Specification (Loc,
1862 Defining_Identifier =>
1863 Make_Defining_Identifier (Loc, Name_uS),
1865 New_Reference_To (Standard_Integer, Loc)),
1867 Make_Parameter_Specification (Loc,
1868 Defining_Identifier =>
1869 Make_Defining_Identifier (Loc, Name_uP),
1871 New_Reference_To (RTE (RE_Address), Loc)),
1873 Make_Parameter_Specification (Loc,
1874 Defining_Identifier =>
1875 Make_Defining_Identifier (Loc, Name_uB),
1877 New_Reference_To (RTE (RE_Dummy_Communication_Block), Loc),
1878 Out_Present => True),
1880 Make_Parameter_Specification (Loc,
1881 Defining_Identifier =>
1882 Make_Defining_Identifier (Loc, Name_uF),
1884 New_Reference_To (Standard_Boolean, Loc),
1885 Out_Present => True)));
1888 Make_Procedure_Specification (Loc,
1889 Defining_Unit_Name => Def_Id,
1890 Parameter_Specifications => Params);
1891 end Make_Disp_Asynchronous_Select_Spec;
1893 ---------------------------------------
1894 -- Make_Disp_Conditional_Select_Body --
1895 ---------------------------------------
1897 -- For interface types, generate:
1899 -- procedure _Disp_Conditional_Select
1900 -- (T : in out <Typ>;
1902 -- P : System.Address;
1903 -- C : out Ada.Tags.Prim_Op_Kind;
1908 -- end _Disp_Conditional_Select;
1910 -- For protected types, generate:
1912 -- procedure _Disp_Conditional_Select
1913 -- (T : in out <Typ>;
1915 -- P : System.Address;
1916 -- C : out Ada.Tags.Prim_Op_Kind;
1920 -- Bnn : System.Tasking.Protected_Objects.Operations.
1921 -- Communication_Block;
1924 -- C := Ada.Tags.Get_Prim_Op_Kind (Ada.Tags.Tag (<Typ>VP, S));
1926 -- if C = Ada.Tags.POK_Procedure
1927 -- or else C = Ada.Tags.POK_Protected_Procedure
1928 -- or else C = Ada.Tags.POK_Task_Procedure
1934 -- I := Ada.Tags.Get_Entry_Index (Ada.Tags.Tag (<Typ>VP, S));
1935 -- System.Tasking.Protected_Objects.Operations.Protected_Entry_Call
1936 -- (T.object'Access,
1937 -- System.Tasking.Protected_Objects.Protected_Entry_Index (I),
1939 -- System.Tasking.Conditional_Call,
1941 -- F := not Cancelled (Bnn);
1942 -- end _Disp_Conditional_Select;
1944 -- For task types, generate:
1946 -- procedure _Disp_Conditional_Select
1947 -- (T : in out <Typ>;
1949 -- P : System.Address;
1950 -- C : out Ada.Tags.Prim_Op_Kind;
1956 -- I := Ada.Tags.Get_Entry_Index (Ada.Tags.Tag (<Typ>VP, S));
1957 -- System.Tasking.Rendezvous.Task_Entry_Call
1959 -- System.Tasking.Task_Entry_Index (I),
1961 -- System.Tasking.Conditional_Call,
1963 -- end _Disp_Conditional_Select;
1965 function Make_Disp_Conditional_Select_Body
1966 (Typ : Entity_Id) return Node_Id
1968 Loc : constant Source_Ptr := Sloc (Typ);
1969 Blk_Nam : Entity_Id;
1970 Conc_Typ : Entity_Id := Empty;
1971 Decls : constant List_Id := New_List;
1974 Stmts : constant List_Id := New_List;
1977 pragma Assert (not Restriction_Active (No_Dispatching_Calls));
1979 -- Null body is generated for interface types
1981 if Is_Interface (Typ) then
1983 Make_Subprogram_Body (Loc,
1985 Make_Disp_Conditional_Select_Spec (Typ),
1988 Handled_Statement_Sequence =>
1989 Make_Handled_Sequence_Of_Statements (Loc,
1990 New_List (Make_Null_Statement (Loc))));
1993 DT_Ptr := Node (First_Elmt (Access_Disp_Table (Typ)));
1995 if Is_Concurrent_Record_Type (Typ) then
1996 Conc_Typ := Corresponding_Concurrent_Type (Typ);
2001 -- where I will be used to capture the entry index of the primitive
2002 -- wrapper at position S.
2005 Make_Object_Declaration (Loc,
2006 Defining_Identifier =>
2007 Make_Defining_Identifier (Loc, Name_uI),
2008 Object_Definition =>
2009 New_Reference_To (Standard_Integer, Loc)));
2012 -- C := Ada.Tags.Get_Prim_Op_Kind (Ada.Tags.Tag! (<type>VP), S);
2014 -- if C = POK_Procedure
2015 -- or else C = POK_Protected_Procedure
2016 -- or else C = POK_Task_Procedure;
2022 Build_Common_Dispatching_Select_Statements (Loc, DT_Ptr, Stmts);
2025 -- Bnn : Communication_Block;
2027 -- where Bnn is the name of the communication block used in the
2028 -- call to Protected_Entry_Call.
2030 Blk_Nam := Make_Defining_Identifier (Loc, New_Internal_Name ('B'));
2033 Make_Object_Declaration (Loc,
2034 Defining_Identifier =>
2036 Object_Definition =>
2037 New_Reference_To (RTE (RE_Communication_Block), Loc)));
2040 -- I := Ada.Tags.Get_Entry_Index (Ada.Tags.Tag! (<type>VP), S);
2042 -- I is the entry index and S is the dispatch table slot
2045 Make_Assignment_Statement (Loc,
2047 Make_Identifier (Loc, Name_uI),
2049 Make_Function_Call (Loc,
2051 New_Reference_To (RTE (RE_Get_Entry_Index), Loc),
2052 Parameter_Associations =>
2054 Unchecked_Convert_To (RTE (RE_Tag),
2055 New_Reference_To (DT_Ptr, Loc)),
2056 Make_Identifier (Loc, Name_uS)))));
2058 if Ekind (Conc_Typ) = E_Protected_Type then
2060 Obj_Ref := -- T._object'Access
2061 Make_Attribute_Reference (Loc,
2062 Attribute_Name => Name_Unchecked_Access,
2064 Make_Selected_Component (Loc,
2065 Prefix => Make_Identifier (Loc, Name_uT),
2066 Selector_Name => Make_Identifier (Loc, Name_uObject)));
2068 case Corresponding_Runtime_Package (Conc_Typ) is
2069 when System_Tasking_Protected_Objects_Entries =>
2072 -- Protected_Entry_Call
2073 -- (T._object'Access, -- Object
2074 -- Protected_Entry_Index! (I), -- E
2075 -- P, -- Uninterpreted_Data
2076 -- Conditional_Call, -- Mode
2079 -- where T is the protected object, I is the entry index, P
2080 -- are the wrapped parameters and Bnn is the name of the
2081 -- communication block.
2084 Make_Procedure_Call_Statement (Loc,
2086 New_Reference_To (RTE (RE_Protected_Entry_Call), Loc),
2087 Parameter_Associations =>
2091 Make_Unchecked_Type_Conversion (Loc, -- entry index
2094 (RTE (RE_Protected_Entry_Index), Loc),
2095 Expression => Make_Identifier (Loc, Name_uI)),
2097 Make_Identifier (Loc, Name_uP), -- parameter block
2099 New_Reference_To ( -- Conditional_Call
2100 RTE (RE_Conditional_Call), Loc),
2101 New_Reference_To ( -- Bnn
2104 when System_Tasking_Protected_Objects_Single_Entry =>
2106 -- If we are compiling for a restricted run-time, the call
2107 -- uses the simpler form.
2110 Make_Procedure_Call_Statement (Loc,
2113 (RTE (RE_Protected_Single_Entry_Call), Loc),
2114 Parameter_Associations =>
2118 Make_Attribute_Reference (Loc,
2119 Prefix => Make_Identifier (Loc, Name_uP),
2120 Attribute_Name => Name_Address),
2123 (RTE (RE_Conditional_Call), Loc))));
2125 raise Program_Error;
2129 -- F := not Cancelled (Bnn);
2131 -- where F is the success flag. The status of Cancelled is negated
2132 -- in order to match the behaviour of the version for task types.
2135 Make_Assignment_Statement (Loc,
2137 Make_Identifier (Loc, Name_uF),
2141 Make_Function_Call (Loc,
2143 New_Reference_To (RTE (RE_Cancelled), Loc),
2144 Parameter_Associations =>
2146 New_Reference_To (Blk_Nam, Loc))))));
2148 pragma Assert (Ekind (Conc_Typ) = E_Task_Type);
2152 -- (T._task_id, -- Acceptor
2153 -- Task_Entry_Index! (I), -- E
2154 -- P, -- Uninterpreted_Data
2155 -- Conditional_Call, -- Mode
2156 -- F); -- Rendezvous_Successful
2158 -- where T is the task object, I is the entry index, P are the
2159 -- wrapped parameters and F is the status flag.
2162 Make_Procedure_Call_Statement (Loc,
2164 New_Reference_To (RTE (RE_Task_Entry_Call), Loc),
2165 Parameter_Associations =>
2168 Make_Selected_Component (Loc, -- T._task_id
2170 Make_Identifier (Loc, Name_uT),
2172 Make_Identifier (Loc, Name_uTask_Id)),
2174 Make_Unchecked_Type_Conversion (Loc, -- entry index
2176 New_Reference_To (RTE (RE_Task_Entry_Index), Loc),
2178 Make_Identifier (Loc, Name_uI)),
2180 Make_Identifier (Loc, Name_uP), -- parameter block
2181 New_Reference_To ( -- Conditional_Call
2182 RTE (RE_Conditional_Call), Loc),
2183 Make_Identifier (Loc, Name_uF)))); -- status flag
2188 Make_Subprogram_Body (Loc,
2190 Make_Disp_Conditional_Select_Spec (Typ),
2193 Handled_Statement_Sequence =>
2194 Make_Handled_Sequence_Of_Statements (Loc, Stmts));
2195 end Make_Disp_Conditional_Select_Body;
2197 ---------------------------------------
2198 -- Make_Disp_Conditional_Select_Spec --
2199 ---------------------------------------
2201 function Make_Disp_Conditional_Select_Spec
2202 (Typ : Entity_Id) return Node_Id
2204 Loc : constant Source_Ptr := Sloc (Typ);
2205 Def_Id : constant Node_Id :=
2206 Make_Defining_Identifier (Loc,
2207 Name_uDisp_Conditional_Select);
2208 Params : constant List_Id := New_List;
2211 pragma Assert (not Restriction_Active (No_Dispatching_Calls));
2213 -- T : in out Typ; -- Object parameter
2214 -- S : Integer; -- Primitive operation slot
2215 -- P : Address; -- Wrapped parameters
2216 -- C : out Prim_Op_Kind; -- Call kind
2217 -- F : out Boolean; -- Status flag
2219 Append_List_To (Params, New_List (
2221 Make_Parameter_Specification (Loc,
2222 Defining_Identifier =>
2223 Make_Defining_Identifier (Loc, Name_uT),
2225 New_Reference_To (Typ, Loc),
2227 Out_Present => True),
2229 Make_Parameter_Specification (Loc,
2230 Defining_Identifier =>
2231 Make_Defining_Identifier (Loc, Name_uS),
2233 New_Reference_To (Standard_Integer, Loc)),
2235 Make_Parameter_Specification (Loc,
2236 Defining_Identifier =>
2237 Make_Defining_Identifier (Loc, Name_uP),
2239 New_Reference_To (RTE (RE_Address), Loc)),
2241 Make_Parameter_Specification (Loc,
2242 Defining_Identifier =>
2243 Make_Defining_Identifier (Loc, Name_uC),
2245 New_Reference_To (RTE (RE_Prim_Op_Kind), Loc),
2246 Out_Present => True),
2248 Make_Parameter_Specification (Loc,
2249 Defining_Identifier =>
2250 Make_Defining_Identifier (Loc, Name_uF),
2252 New_Reference_To (Standard_Boolean, Loc),
2253 Out_Present => True)));
2256 Make_Procedure_Specification (Loc,
2257 Defining_Unit_Name => Def_Id,
2258 Parameter_Specifications => Params);
2259 end Make_Disp_Conditional_Select_Spec;
2261 -------------------------------------
2262 -- Make_Disp_Get_Prim_Op_Kind_Body --
2263 -------------------------------------
2265 function Make_Disp_Get_Prim_Op_Kind_Body
2266 (Typ : Entity_Id) return Node_Id
2268 Loc : constant Source_Ptr := Sloc (Typ);
2272 pragma Assert (not Restriction_Active (No_Dispatching_Calls));
2274 if Is_Interface (Typ) then
2276 Make_Subprogram_Body (Loc,
2278 Make_Disp_Get_Prim_Op_Kind_Spec (Typ),
2281 Handled_Statement_Sequence =>
2282 Make_Handled_Sequence_Of_Statements (Loc,
2283 New_List (Make_Null_Statement (Loc))));
2286 DT_Ptr := Node (First_Elmt (Access_Disp_Table (Typ)));
2289 -- C := get_prim_op_kind (tag! (<type>VP), S);
2291 -- where C is the out parameter capturing the call kind and S is the
2292 -- dispatch table slot number.
2295 Make_Subprogram_Body (Loc,
2297 Make_Disp_Get_Prim_Op_Kind_Spec (Typ),
2300 Handled_Statement_Sequence =>
2301 Make_Handled_Sequence_Of_Statements (Loc,
2303 Make_Assignment_Statement (Loc,
2305 Make_Identifier (Loc, Name_uC),
2307 Make_Function_Call (Loc,
2309 New_Reference_To (RTE (RE_Get_Prim_Op_Kind), Loc),
2310 Parameter_Associations => New_List (
2311 Unchecked_Convert_To (RTE (RE_Tag),
2312 New_Reference_To (DT_Ptr, Loc)),
2313 Make_Identifier (Loc, Name_uS)))))));
2314 end Make_Disp_Get_Prim_Op_Kind_Body;
2316 -------------------------------------
2317 -- Make_Disp_Get_Prim_Op_Kind_Spec --
2318 -------------------------------------
2320 function Make_Disp_Get_Prim_Op_Kind_Spec
2321 (Typ : Entity_Id) return Node_Id
2323 Loc : constant Source_Ptr := Sloc (Typ);
2324 Def_Id : constant Node_Id :=
2325 Make_Defining_Identifier (Loc,
2326 Name_uDisp_Get_Prim_Op_Kind);
2327 Params : constant List_Id := New_List;
2330 pragma Assert (not Restriction_Active (No_Dispatching_Calls));
2332 -- T : in out Typ; -- Object parameter
2333 -- S : Integer; -- Primitive operation slot
2334 -- C : out Prim_Op_Kind; -- Call kind
2336 Append_List_To (Params, New_List (
2338 Make_Parameter_Specification (Loc,
2339 Defining_Identifier =>
2340 Make_Defining_Identifier (Loc, Name_uT),
2342 New_Reference_To (Typ, Loc),
2344 Out_Present => True),
2346 Make_Parameter_Specification (Loc,
2347 Defining_Identifier =>
2348 Make_Defining_Identifier (Loc, Name_uS),
2350 New_Reference_To (Standard_Integer, Loc)),
2352 Make_Parameter_Specification (Loc,
2353 Defining_Identifier =>
2354 Make_Defining_Identifier (Loc, Name_uC),
2356 New_Reference_To (RTE (RE_Prim_Op_Kind), Loc),
2357 Out_Present => True)));
2360 Make_Procedure_Specification (Loc,
2361 Defining_Unit_Name => Def_Id,
2362 Parameter_Specifications => Params);
2363 end Make_Disp_Get_Prim_Op_Kind_Spec;
2365 --------------------------------
2366 -- Make_Disp_Get_Task_Id_Body --
2367 --------------------------------
2369 function Make_Disp_Get_Task_Id_Body
2370 (Typ : Entity_Id) return Node_Id
2372 Loc : constant Source_Ptr := Sloc (Typ);
2376 pragma Assert (not Restriction_Active (No_Dispatching_Calls));
2378 if Is_Concurrent_Record_Type (Typ)
2379 and then Ekind (Corresponding_Concurrent_Type (Typ)) = E_Task_Type
2382 -- return To_Address (_T._task_id);
2385 Make_Simple_Return_Statement (Loc,
2387 Make_Unchecked_Type_Conversion (Loc,
2389 New_Reference_To (RTE (RE_Address), Loc),
2391 Make_Selected_Component (Loc,
2393 Make_Identifier (Loc, Name_uT),
2395 Make_Identifier (Loc, Name_uTask_Id))));
2397 -- A null body is constructed for non-task types
2401 -- return Null_Address;
2404 Make_Simple_Return_Statement (Loc,
2406 New_Reference_To (RTE (RE_Null_Address), Loc));
2410 Make_Subprogram_Body (Loc,
2412 Make_Disp_Get_Task_Id_Spec (Typ),
2415 Handled_Statement_Sequence =>
2416 Make_Handled_Sequence_Of_Statements (Loc,
2418 end Make_Disp_Get_Task_Id_Body;
2420 --------------------------------
2421 -- Make_Disp_Get_Task_Id_Spec --
2422 --------------------------------
2424 function Make_Disp_Get_Task_Id_Spec
2425 (Typ : Entity_Id) return Node_Id
2427 Loc : constant Source_Ptr := Sloc (Typ);
2430 pragma Assert (not Restriction_Active (No_Dispatching_Calls));
2433 Make_Function_Specification (Loc,
2434 Defining_Unit_Name =>
2435 Make_Defining_Identifier (Loc, Name_uDisp_Get_Task_Id),
2436 Parameter_Specifications => New_List (
2437 Make_Parameter_Specification (Loc,
2438 Defining_Identifier =>
2439 Make_Defining_Identifier (Loc, Name_uT),
2441 New_Reference_To (Typ, Loc))),
2442 Result_Definition =>
2443 New_Reference_To (RTE (RE_Address), Loc));
2444 end Make_Disp_Get_Task_Id_Spec;
2446 ----------------------------
2447 -- Make_Disp_Requeue_Body --
2448 ----------------------------
2450 function Make_Disp_Requeue_Body
2451 (Typ : Entity_Id) return Node_Id
2453 Loc : constant Source_Ptr := Sloc (Typ);
2454 Conc_Typ : Entity_Id := Empty;
2455 Stmts : constant List_Id := New_List;
2458 pragma Assert (not Restriction_Active (No_Dispatching_Calls));
2460 -- Null body is generated for interface types and non-concurrent
2463 if Is_Interface (Typ)
2464 or else not Is_Concurrent_Record_Type (Typ)
2467 Make_Subprogram_Body (Loc,
2469 Make_Disp_Requeue_Spec (Typ),
2472 Handled_Statement_Sequence =>
2473 Make_Handled_Sequence_Of_Statements (Loc,
2474 New_List (Make_Null_Statement (Loc))));
2477 Conc_Typ := Corresponding_Concurrent_Type (Typ);
2479 if Ekind (Conc_Typ) = E_Protected_Type then
2481 -- Generate statements:
2483 -- System.Tasking.Protected_Objects.Operations.
2484 -- Requeue_Protected_Entry
2485 -- (Protection_Entries_Access (P),
2486 -- O._object'Unchecked_Access,
2487 -- Protected_Entry_Index (I),
2490 -- System.Tasking.Protected_Objects.Operations.
2491 -- Requeue_Task_To_Protected_Entry
2492 -- (O._object'Unchecked_Access,
2493 -- Protected_Entry_Index (I),
2497 if Restriction_Active (No_Entry_Queue) then
2498 Append_To (Stmts, Make_Null_Statement (Loc));
2501 Make_If_Statement (Loc,
2503 Make_Identifier (Loc, Name_uF),
2508 -- Call to Requeue_Protected_Entry
2510 Make_Procedure_Call_Statement (Loc,
2513 RTE (RE_Requeue_Protected_Entry), Loc),
2514 Parameter_Associations =>
2517 Make_Unchecked_Type_Conversion (Loc, -- PEA (P)
2520 RTE (RE_Protection_Entries_Access), Loc),
2522 Make_Identifier (Loc, Name_uP)),
2524 Make_Attribute_Reference (Loc, -- O._object'Acc
2526 Name_Unchecked_Access,
2528 Make_Selected_Component (Loc,
2530 Make_Identifier (Loc, Name_uO),
2532 Make_Identifier (Loc, Name_uObject))),
2534 Make_Unchecked_Type_Conversion (Loc, -- entry index
2537 RTE (RE_Protected_Entry_Index), Loc),
2539 Make_Identifier (Loc, Name_uI)),
2541 Make_Identifier (Loc, Name_uA)))), -- abort status
2546 -- Call to Requeue_Task_To_Protected_Entry
2548 Make_Procedure_Call_Statement (Loc,
2551 RTE (RE_Requeue_Task_To_Protected_Entry), Loc),
2552 Parameter_Associations =>
2555 Make_Attribute_Reference (Loc, -- O._object'Acc
2557 Name_Unchecked_Access,
2559 Make_Selected_Component (Loc,
2561 Make_Identifier (Loc, Name_uO),
2563 Make_Identifier (Loc, Name_uObject))),
2565 Make_Unchecked_Type_Conversion (Loc, -- entry index
2568 RTE (RE_Protected_Entry_Index), Loc),
2570 Make_Identifier (Loc, Name_uI)),
2572 Make_Identifier (Loc, Name_uA)))))); -- abort status
2575 pragma Assert (Is_Task_Type (Conc_Typ));
2579 -- System.Tasking.Rendezvous.Requeue_Protected_To_Task_Entry
2580 -- (Protection_Entries_Access (P),
2582 -- Task_Entry_Index (I),
2585 -- System.Tasking.Rendezvous.Requeue_Task_Entry
2587 -- Task_Entry_Index (I),
2592 Make_If_Statement (Loc,
2594 Make_Identifier (Loc, Name_uF),
2599 -- Call to Requeue_Protected_To_Task_Entry
2601 Make_Procedure_Call_Statement (Loc,
2604 RTE (RE_Requeue_Protected_To_Task_Entry), Loc),
2606 Parameter_Associations =>
2609 Make_Unchecked_Type_Conversion (Loc, -- PEA (P)
2612 RTE (RE_Protection_Entries_Access), Loc),
2614 Make_Identifier (Loc, Name_uP)),
2616 Make_Selected_Component (Loc, -- O._task_id
2618 Make_Identifier (Loc, Name_uO),
2620 Make_Identifier (Loc, Name_uTask_Id)),
2622 Make_Unchecked_Type_Conversion (Loc, -- entry index
2625 RTE (RE_Task_Entry_Index), Loc),
2627 Make_Identifier (Loc, Name_uI)),
2629 Make_Identifier (Loc, Name_uA)))), -- abort status
2634 -- Call to Requeue_Task_Entry
2636 Make_Procedure_Call_Statement (Loc,
2638 New_Reference_To (RTE (RE_Requeue_Task_Entry), Loc),
2640 Parameter_Associations =>
2643 Make_Selected_Component (Loc, -- O._task_id
2645 Make_Identifier (Loc, Name_uO),
2647 Make_Identifier (Loc, Name_uTask_Id)),
2649 Make_Unchecked_Type_Conversion (Loc, -- entry index
2652 RTE (RE_Task_Entry_Index), Loc),
2654 Make_Identifier (Loc, Name_uI)),
2656 Make_Identifier (Loc, Name_uA)))))); -- abort status
2659 -- Even though no declarations are needed in both cases, we allocate
2660 -- a list for entities added by Freeze.
2663 Make_Subprogram_Body (Loc,
2665 Make_Disp_Requeue_Spec (Typ),
2668 Handled_Statement_Sequence =>
2669 Make_Handled_Sequence_Of_Statements (Loc, Stmts));
2670 end Make_Disp_Requeue_Body;
2672 ----------------------------
2673 -- Make_Disp_Requeue_Spec --
2674 ----------------------------
2676 function Make_Disp_Requeue_Spec
2677 (Typ : Entity_Id) return Node_Id
2679 Loc : constant Source_Ptr := Sloc (Typ);
2682 pragma Assert (not Restriction_Active (No_Dispatching_Calls));
2684 -- O : in out Typ; - Object parameter
2685 -- F : Boolean; - Protected (True) / task (False) flag
2686 -- P : Address; - Protection_Entries_Access value
2687 -- I : Entry_Index - Index of entry call
2688 -- A : Boolean - Abort flag
2690 -- Note that the Protection_Entries_Access value is represented as a
2691 -- System.Address in order to avoid dragging in the tasking runtime
2692 -- when compiling sources without tasking constructs.
2695 Make_Procedure_Specification (Loc,
2696 Defining_Unit_Name =>
2697 Make_Defining_Identifier (Loc, Name_uDisp_Requeue),
2699 Parameter_Specifications =>
2702 Make_Parameter_Specification (Loc, -- O
2703 Defining_Identifier =>
2704 Make_Defining_Identifier (Loc, Name_uO),
2706 New_Reference_To (Typ, Loc),
2708 Out_Present => True),
2710 Make_Parameter_Specification (Loc, -- F
2711 Defining_Identifier =>
2712 Make_Defining_Identifier (Loc, Name_uF),
2714 New_Reference_To (Standard_Boolean, Loc)),
2716 Make_Parameter_Specification (Loc, -- P
2717 Defining_Identifier =>
2718 Make_Defining_Identifier (Loc, Name_uP),
2720 New_Reference_To (RTE (RE_Address), Loc)),
2722 Make_Parameter_Specification (Loc, -- I
2723 Defining_Identifier =>
2724 Make_Defining_Identifier (Loc, Name_uI),
2726 New_Reference_To (Standard_Integer, Loc)),
2728 Make_Parameter_Specification (Loc, -- A
2729 Defining_Identifier =>
2730 Make_Defining_Identifier (Loc, Name_uA),
2732 New_Reference_To (Standard_Boolean, Loc))));
2733 end Make_Disp_Requeue_Spec;
2735 ---------------------------------
2736 -- Make_Disp_Timed_Select_Body --
2737 ---------------------------------
2739 -- For interface types, generate:
2741 -- procedure _Disp_Timed_Select
2742 -- (T : in out <Typ>;
2744 -- P : System.Address;
2747 -- C : out Ada.Tags.Prim_Op_Kind;
2752 -- end _Disp_Timed_Select;
2754 -- For protected types, generate:
2756 -- procedure _Disp_Timed_Select
2757 -- (T : in out <Typ>;
2759 -- P : System.Address;
2762 -- C : out Ada.Tags.Prim_Op_Kind;
2768 -- C := Ada.Tags.Get_Prim_Op_Kind (Ada.Tags.Tag (<Typ>VP), S);
2770 -- if C = Ada.Tags.POK_Procedure
2771 -- or else C = Ada.Tags.POK_Protected_Procedure
2772 -- or else C = Ada.Tags.POK_Task_Procedure
2778 -- I := Ada.Tags.Get_Entry_Index (Ada.Tags.Tag (<Typ>VP), S);
2779 -- System.Tasking.Protected_Objects.Operations.
2780 -- Timed_Protected_Entry_Call
2781 -- (T._object'Access,
2782 -- System.Tasking.Protected_Objects.Protected_Entry_Index (I),
2787 -- end _Disp_Timed_Select;
2789 -- For task types, generate:
2791 -- procedure _Disp_Timed_Select
2792 -- (T : in out <Typ>;
2794 -- P : System.Address;
2797 -- C : out Ada.Tags.Prim_Op_Kind;
2803 -- I := Ada.Tags.Get_Entry_Index (Ada.Tags.Tag (<Typ>VP), S);
2804 -- System.Tasking.Rendezvous.Timed_Task_Entry_Call
2806 -- System.Tasking.Task_Entry_Index (I),
2811 -- end _Disp_Time_Select;
2813 function Make_Disp_Timed_Select_Body
2814 (Typ : Entity_Id) return Node_Id
2816 Loc : constant Source_Ptr := Sloc (Typ);
2817 Conc_Typ : Entity_Id := Empty;
2818 Decls : constant List_Id := New_List;
2821 Stmts : constant List_Id := New_List;
2824 pragma Assert (not Restriction_Active (No_Dispatching_Calls));
2826 -- Null body is generated for interface types
2828 if Is_Interface (Typ) then
2830 Make_Subprogram_Body (Loc,
2832 Make_Disp_Timed_Select_Spec (Typ),
2835 Handled_Statement_Sequence =>
2836 Make_Handled_Sequence_Of_Statements (Loc,
2837 New_List (Make_Null_Statement (Loc))));
2840 DT_Ptr := Node (First_Elmt (Access_Disp_Table (Typ)));
2842 if Is_Concurrent_Record_Type (Typ) then
2843 Conc_Typ := Corresponding_Concurrent_Type (Typ);
2848 -- where I will be used to capture the entry index of the primitive
2849 -- wrapper at position S.
2852 Make_Object_Declaration (Loc,
2853 Defining_Identifier =>
2854 Make_Defining_Identifier (Loc, Name_uI),
2855 Object_Definition =>
2856 New_Reference_To (Standard_Integer, Loc)));
2859 -- C := Get_Prim_Op_Kind (tag! (<type>VP), S);
2861 -- if C = POK_Procedure
2862 -- or else C = POK_Protected_Procedure
2863 -- or else C = POK_Task_Procedure;
2869 Build_Common_Dispatching_Select_Statements (Loc, DT_Ptr, Stmts);
2872 -- I := Get_Entry_Index (tag! (<type>VP), S);
2874 -- I is the entry index and S is the dispatch table slot
2877 Make_Assignment_Statement (Loc,
2879 Make_Identifier (Loc, Name_uI),
2881 Make_Function_Call (Loc,
2883 New_Reference_To (RTE (RE_Get_Entry_Index), Loc),
2884 Parameter_Associations =>
2886 Unchecked_Convert_To (RTE (RE_Tag),
2887 New_Reference_To (DT_Ptr, Loc)),
2888 Make_Identifier (Loc, Name_uS)))));
2892 if Ekind (Conc_Typ) = E_Protected_Type then
2894 -- Build T._object'Access
2897 Make_Attribute_Reference (Loc,
2898 Attribute_Name => Name_Unchecked_Access,
2900 Make_Selected_Component (Loc,
2901 Prefix => Make_Identifier (Loc, Name_uT),
2902 Selector_Name => Make_Identifier (Loc, Name_uObject)));
2904 -- Normal case, No_Entry_Queue restriction not active. In this
2905 -- case we generate:
2907 -- Timed_Protected_Entry_Call
2908 -- (T._object'access,
2909 -- Protected_Entry_Index! (I),
2912 -- where T is the protected object, I is the entry index, P are
2913 -- the wrapped parameters, D is the delay amount, M is the delay
2914 -- mode and F is the status flag.
2916 case Corresponding_Runtime_Package (Conc_Typ) is
2917 when System_Tasking_Protected_Objects_Entries =>
2919 Make_Procedure_Call_Statement (Loc,
2922 (RTE (RE_Timed_Protected_Entry_Call), Loc),
2923 Parameter_Associations =>
2927 Make_Unchecked_Type_Conversion (Loc, -- entry index
2930 (RTE (RE_Protected_Entry_Index), Loc),
2932 Make_Identifier (Loc, Name_uI)),
2934 Make_Identifier (Loc, Name_uP), -- parameter block
2935 Make_Identifier (Loc, Name_uD), -- delay
2936 Make_Identifier (Loc, Name_uM), -- delay mode
2937 Make_Identifier (Loc, Name_uF)))); -- status flag
2939 when System_Tasking_Protected_Objects_Single_Entry =>
2942 -- Timed_Protected_Single_Entry_Call
2943 -- (T._object'access, P, D, M, F);
2945 -- where T is the protected object, P is the wrapped
2946 -- parameters, D is the delay amount, M is the delay mode, F
2947 -- is the status flag.
2950 Make_Procedure_Call_Statement (Loc,
2953 (RTE (RE_Timed_Protected_Single_Entry_Call), Loc),
2954 Parameter_Associations =>
2957 Make_Identifier (Loc, Name_uP), -- parameter block
2958 Make_Identifier (Loc, Name_uD), -- delay
2959 Make_Identifier (Loc, Name_uM), -- delay mode
2960 Make_Identifier (Loc, Name_uF)))); -- status flag
2963 raise Program_Error;
2969 pragma Assert (Ekind (Conc_Typ) = E_Task_Type);
2972 -- Timed_Task_Entry_Call (
2974 -- Task_Entry_Index! (I),
2980 -- where T is the task object, I is the entry index, P are the
2981 -- wrapped parameters, D is the delay amount, M is the delay
2982 -- mode and F is the status flag.
2985 Make_Procedure_Call_Statement (Loc,
2987 New_Reference_To (RTE (RE_Timed_Task_Entry_Call), Loc),
2988 Parameter_Associations =>
2991 Make_Selected_Component (Loc, -- T._task_id
2993 Make_Identifier (Loc, Name_uT),
2995 Make_Identifier (Loc, Name_uTask_Id)),
2997 Make_Unchecked_Type_Conversion (Loc, -- entry index
2999 New_Reference_To (RTE (RE_Task_Entry_Index), Loc),
3001 Make_Identifier (Loc, Name_uI)),
3003 Make_Identifier (Loc, Name_uP), -- parameter block
3004 Make_Identifier (Loc, Name_uD), -- delay
3005 Make_Identifier (Loc, Name_uM), -- delay mode
3006 Make_Identifier (Loc, Name_uF)))); -- status flag
3011 Make_Subprogram_Body (Loc,
3013 Make_Disp_Timed_Select_Spec (Typ),
3016 Handled_Statement_Sequence =>
3017 Make_Handled_Sequence_Of_Statements (Loc, Stmts));
3018 end Make_Disp_Timed_Select_Body;
3020 ---------------------------------
3021 -- Make_Disp_Timed_Select_Spec --
3022 ---------------------------------
3024 function Make_Disp_Timed_Select_Spec
3025 (Typ : Entity_Id) return Node_Id
3027 Loc : constant Source_Ptr := Sloc (Typ);
3028 Def_Id : constant Node_Id :=
3029 Make_Defining_Identifier (Loc,
3030 Name_uDisp_Timed_Select);
3031 Params : constant List_Id := New_List;
3034 pragma Assert (not Restriction_Active (No_Dispatching_Calls));
3036 -- T : in out Typ; -- Object parameter
3037 -- S : Integer; -- Primitive operation slot
3038 -- P : Address; -- Wrapped parameters
3039 -- D : Duration; -- Delay
3040 -- M : Integer; -- Delay Mode
3041 -- C : out Prim_Op_Kind; -- Call kind
3042 -- F : out Boolean; -- Status flag
3044 Append_List_To (Params, New_List (
3046 Make_Parameter_Specification (Loc,
3047 Defining_Identifier =>
3048 Make_Defining_Identifier (Loc, Name_uT),
3050 New_Reference_To (Typ, Loc),
3052 Out_Present => True),
3054 Make_Parameter_Specification (Loc,
3055 Defining_Identifier =>
3056 Make_Defining_Identifier (Loc, Name_uS),
3058 New_Reference_To (Standard_Integer, Loc)),
3060 Make_Parameter_Specification (Loc,
3061 Defining_Identifier =>
3062 Make_Defining_Identifier (Loc, Name_uP),
3064 New_Reference_To (RTE (RE_Address), Loc)),
3066 Make_Parameter_Specification (Loc,
3067 Defining_Identifier =>
3068 Make_Defining_Identifier (Loc, Name_uD),
3070 New_Reference_To (Standard_Duration, Loc)),
3072 Make_Parameter_Specification (Loc,
3073 Defining_Identifier =>
3074 Make_Defining_Identifier (Loc, Name_uM),
3076 New_Reference_To (Standard_Integer, Loc)),
3078 Make_Parameter_Specification (Loc,
3079 Defining_Identifier =>
3080 Make_Defining_Identifier (Loc, Name_uC),
3082 New_Reference_To (RTE (RE_Prim_Op_Kind), Loc),
3083 Out_Present => True)));
3086 Make_Parameter_Specification (Loc,
3087 Defining_Identifier =>
3088 Make_Defining_Identifier (Loc, Name_uF),
3090 New_Reference_To (Standard_Boolean, Loc),
3091 Out_Present => True));
3094 Make_Procedure_Specification (Loc,
3095 Defining_Unit_Name => Def_Id,
3096 Parameter_Specifications => Params);
3097 end Make_Disp_Timed_Select_Spec;
3103 -- The frontend supports two models for expanding dispatch tables
3104 -- associated with library-level defined tagged types: statically
3105 -- and non-statically allocated dispatch tables. In the former case
3106 -- the object containing the dispatch table is constant and it is
3107 -- initialized by means of a positional aggregate. In the latter case,
3108 -- the object containing the dispatch table is a variable which is
3109 -- initialized by means of assignments.
3111 -- In case of locally defined tagged types, the object containing the
3112 -- object containing the dispatch table is always a variable (instead
3113 -- of a constant). This is currently required to give support to late
3114 -- overriding of primitives. For example:
3116 -- procedure Example is
3118 -- type T1 is tagged null record;
3119 -- procedure Prim (O : T1);
3122 -- type T2 is new Pkg.T1 with null record;
3123 -- procedure Prim (X : T2) is -- late overriding
3129 function Make_DT (Typ : Entity_Id; N : Node_Id := Empty) return List_Id is
3130 Loc : constant Source_Ptr := Sloc (Typ);
3132 Max_Predef_Prims : constant Int :=
3136 (Parent (RTE (RE_Max_Predef_Prims)))));
3138 DT_Decl : constant Elist_Id := New_Elmt_List;
3139 DT_Aggr : constant Elist_Id := New_Elmt_List;
3140 -- Entities marked with attribute Is_Dispatch_Table_Entity
3142 procedure Check_Premature_Freezing (Subp : Entity_Id; Typ : Entity_Id);
3143 -- Verify that all non-tagged types in the profile of a subprogram
3144 -- are frozen at the point the subprogram is frozen. This enforces
3145 -- the rule on RM 13.14 (14) as modified by AI05-019. At the point a
3146 -- subprogram is frozen, enough must be known about it to build the
3147 -- activation record for it, which requires at least that the size of
3148 -- all parameters be known. Controlling arguments are by-reference,
3149 -- and therefore the rule only applies to non-tagged types.
3150 -- Typical violation of the rule involves an object declaration that
3151 -- freezes a tagged type, when one of its primitive operations has a
3152 -- type in its profile whose full view has not been analyzed yet.
3154 procedure Export_DT (Typ : Entity_Id; DT : Entity_Id; Index : Nat := 0);
3155 -- Export the dispatch table DT of tagged type Typ. Required to generate
3156 -- forward references and statically allocate the table. For primary
3157 -- dispatch tables Index is 0; for secondary dispatch tables the value
3158 -- of index must match the Suffix_Index value assigned to the table by
3159 -- Make_Tags when generating its unique external name, and it is used to
3160 -- retrieve from the Dispatch_Table_Wrappers list associated with Typ
3161 -- the external name generated by Import_DT.
3163 procedure Make_Secondary_DT
3167 Num_Iface_Prims : Nat;
3168 Iface_DT_Ptr : Entity_Id;
3169 Predef_Prims_Ptr : Entity_Id;
3170 Build_Thunks : Boolean;
3172 -- Ada 2005 (AI-251): Expand the declarations for a Secondary Dispatch
3173 -- Table of Typ associated with Iface. Each abstract interface of Typ
3174 -- has two secondary dispatch tables: one containing pointers to thunks
3175 -- and another containing pointers to the primitives covering the
3176 -- interface primitives. The former secondary table is generated when
3177 -- Build_Thunks is True, and provides common support for dispatching
3178 -- calls through interface types; the latter secondary table is
3179 -- generated when Build_Thunks is False, and provides support for
3180 -- Generic Dispatching Constructors that dispatch calls through
3181 -- interface types. When constructing this latter table the value
3182 -- of Suffix_Index is -1 to indicate that there is no need to export
3183 -- such table when building statically allocated dispatch tables; a
3184 -- positive value of Suffix_Index must match the Suffix_Index value
3185 -- assigned to this secondary dispatch table by Make_Tags when its
3186 -- unique external name was generated.
3188 ------------------------------
3189 -- Check_Premature_Freezing --
3190 ------------------------------
3192 procedure Check_Premature_Freezing (Subp : Entity_Id; Typ : Entity_Id) is
3195 and then Is_Private_Type (Typ)
3196 and then No (Full_View (Typ))
3197 and then not Is_Generic_Type (Typ)
3198 and then not Is_Tagged_Type (Typ)
3199 and then not Is_Frozen (Typ)
3201 Error_Msg_Sloc := Sloc (Subp);
3203 ("declaration must appear after completion of type &", N, Typ);
3205 ("\which is an untagged type in the profile of"
3206 & " primitive operation & declared#",
3209 end Check_Premature_Freezing;
3215 procedure Export_DT (Typ : Entity_Id; DT : Entity_Id; Index : Nat := 0)
3221 Set_Is_Statically_Allocated (DT);
3222 Set_Is_True_Constant (DT);
3223 Set_Is_Exported (DT);
3226 Elmt := First_Elmt (Dispatch_Table_Wrappers (Typ));
3227 while Count /= Index loop
3232 pragma Assert (Related_Type (Node (Elmt)) = Typ);
3235 (Entity => Node (Elmt),
3236 Has_Suffix => True);
3238 Set_Interface_Name (DT,
3239 Make_String_Literal (Loc,
3240 Strval => String_From_Name_Buffer));
3242 -- Ensure proper Sprint output of this implicit importation
3244 Set_Is_Internal (DT);
3248 -----------------------
3249 -- Make_Secondary_DT --
3250 -----------------------
3252 procedure Make_Secondary_DT
3256 Num_Iface_Prims : Nat;
3257 Iface_DT_Ptr : Entity_Id;
3258 Predef_Prims_Ptr : Entity_Id;
3259 Build_Thunks : Boolean;
3262 Loc : constant Source_Ptr := Sloc (Typ);
3263 Exporting_Table : constant Boolean :=
3264 Building_Static_DT (Typ)
3265 and then Suffix_Index > 0;
3266 Iface_DT : constant Entity_Id :=
3267 Make_Defining_Identifier (Loc,
3268 Chars => New_Internal_Name ('T'));
3269 Name_Predef_Prims : constant Name_Id := New_Internal_Name ('R');
3270 Predef_Prims : constant Entity_Id :=
3271 Make_Defining_Identifier (Loc,
3272 Chars => Name_Predef_Prims);
3273 DT_Constr_List : List_Id;
3274 DT_Aggr_List : List_Id;
3275 Empty_DT : Boolean := False;
3276 Nb_Predef_Prims : Nat := 0;
3280 OSD_Aggr_List : List_Id;
3283 Prim_Elmt : Elmt_Id;
3284 Prim_Ops_Aggr_List : List_Id;
3287 -- Handle cases in which we do not generate statically allocated
3290 if not Building_Static_DT (Typ) then
3291 Set_Ekind (Predef_Prims, E_Variable);
3292 Set_Ekind (Iface_DT, E_Variable);
3294 -- Statically allocated dispatch tables and related entities are
3298 Set_Ekind (Predef_Prims, E_Constant);
3299 Set_Is_Statically_Allocated (Predef_Prims);
3300 Set_Is_True_Constant (Predef_Prims);
3302 Set_Ekind (Iface_DT, E_Constant);
3303 Set_Is_Statically_Allocated (Iface_DT);
3304 Set_Is_True_Constant (Iface_DT);
3307 -- Calculate the number of slots of the dispatch table. If the number
3308 -- of primitives of Typ is 0 we reserve a dummy single entry for its
3309 -- DT because at run-time the pointer to this dummy entry will be
3312 if Num_Iface_Prims = 0 then
3316 Nb_Prim := Num_Iface_Prims;
3321 -- Predef_Prims : Address_Array (1 .. Default_Prim_Ops_Count) :=
3322 -- (predef-prim-op-thunk-1'address,
3323 -- predef-prim-op-thunk-2'address,
3325 -- predef-prim-op-thunk-n'address);
3326 -- for Predef_Prims'Alignment use Address'Alignment
3328 -- Stage 1: Calculate the number of predefined primitives
3330 if not Building_Static_DT (Typ) then
3331 Nb_Predef_Prims := Max_Predef_Prims;
3333 Prim_Elmt := First_Elmt (Primitive_Operations (Typ));
3334 while Present (Prim_Elmt) loop
3335 Prim := Node (Prim_Elmt);
3337 if Is_Predefined_Dispatching_Operation (Prim)
3338 and then not Is_Abstract_Subprogram (Prim)
3340 Pos := UI_To_Int (DT_Position (Prim));
3342 if Pos > Nb_Predef_Prims then
3343 Nb_Predef_Prims := Pos;
3347 Next_Elmt (Prim_Elmt);
3351 -- Stage 2: Create the thunks associated with the predefined
3352 -- primitives and save their entity to fill the aggregate.
3355 Prim_Table : array (Nat range 1 .. Nb_Predef_Prims) of Entity_Id;
3357 Thunk_Id : Entity_Id;
3358 Thunk_Code : Node_Id;
3361 Prim_Ops_Aggr_List := New_List;
3362 Prim_Table := (others => Empty);
3364 if Building_Static_DT (Typ) then
3365 Prim_Elmt := First_Elmt (Primitive_Operations (Typ));
3366 while Present (Prim_Elmt) loop
3367 Prim := Node (Prim_Elmt);
3369 if Is_Predefined_Dispatching_Operation (Prim)
3370 and then not Is_Abstract_Subprogram (Prim)
3371 and then not Present (Prim_Table
3372 (UI_To_Int (DT_Position (Prim))))
3374 if not Build_Thunks then
3375 Prim_Table (UI_To_Int (DT_Position (Prim))) :=
3379 while Present (Alias (Prim)) loop
3380 Prim := Alias (Prim);
3383 Expand_Interface_Thunk (Prim, Thunk_Id, Thunk_Code);
3385 if Present (Thunk_Id) then
3386 Append_To (Result, Thunk_Code);
3387 Prim_Table (UI_To_Int (DT_Position (Prim)))
3393 Next_Elmt (Prim_Elmt);
3397 for J in Prim_Table'Range loop
3398 if Present (Prim_Table (J)) then
3400 Unchecked_Convert_To (RTE (RE_Prim_Ptr),
3401 Make_Attribute_Reference (Loc,
3402 Prefix => New_Reference_To (Prim_Table (J), Loc),
3403 Attribute_Name => Name_Unrestricted_Access));
3405 New_Node := Make_Null (Loc);
3408 Append_To (Prim_Ops_Aggr_List, New_Node);
3412 Make_Aggregate (Loc,
3413 Expressions => Prim_Ops_Aggr_List);
3415 -- Remember aggregates initializing dispatch tables
3417 Append_Elmt (New_Node, DT_Aggr);
3420 Make_Subtype_Declaration (Loc,
3421 Defining_Identifier =>
3422 Make_Defining_Identifier (Loc,
3423 New_Internal_Name ('S')),
3424 Subtype_Indication =>
3425 New_Reference_To (RTE (RE_Address_Array), Loc));
3427 Append_To (Result, Decl);
3430 Make_Object_Declaration (Loc,
3431 Defining_Identifier => Predef_Prims,
3432 Constant_Present => Building_Static_DT (Typ),
3433 Aliased_Present => True,
3434 Object_Definition => New_Reference_To
3435 (Defining_Identifier (Decl), Loc),
3436 Expression => New_Node));
3439 Make_Attribute_Definition_Clause (Loc,
3440 Name => New_Reference_To (Predef_Prims, Loc),
3441 Chars => Name_Alignment,
3443 Make_Attribute_Reference (Loc,
3445 New_Reference_To (RTE (RE_Integer_Address), Loc),
3446 Attribute_Name => Name_Alignment)));
3451 -- OSD : Ada.Tags.Object_Specific_Data (Nb_Prims) :=
3452 -- (OSD_Table => (1 => <value>,
3456 -- Iface_DT : Dispatch_Table (Nb_Prims) :=
3457 -- ([ Signature => <sig-value> ],
3458 -- Tag_Kind => <tag_kind-value>,
3459 -- Predef_Prims => Predef_Prims'Address,
3460 -- Offset_To_Top => 0,
3461 -- OSD => OSD'Address,
3462 -- Prims_Ptr => (prim-op-1'address,
3463 -- prim-op-2'address,
3465 -- prim-op-n'address));
3466 -- for Iface_DT'Alignment use Address'Alignment;
3468 -- Stage 3: Initialize the discriminant and the record components
3470 DT_Constr_List := New_List;
3471 DT_Aggr_List := New_List;
3473 -- Nb_Prim. If the tagged type has no primitives we add a dummy
3474 -- slot whose address will be the tag of this type.
3477 New_Node := Make_Integer_Literal (Loc, 1);
3479 New_Node := Make_Integer_Literal (Loc, Nb_Prim);
3482 Append_To (DT_Constr_List, New_Node);
3483 Append_To (DT_Aggr_List, New_Copy (New_Node));
3487 if RTE_Record_Component_Available (RE_Signature) then
3488 Append_To (DT_Aggr_List,
3489 New_Reference_To (RTE (RE_Secondary_DT), Loc));
3494 if RTE_Record_Component_Available (RE_Tag_Kind) then
3495 Append_To (DT_Aggr_List, Tagged_Kind (Typ));
3500 Append_To (DT_Aggr_List,
3501 Make_Attribute_Reference (Loc,
3502 Prefix => New_Reference_To (Predef_Prims, Loc),
3503 Attribute_Name => Name_Address));
3505 -- Note: The correct value of Offset_To_Top will be set by the init
3508 Append_To (DT_Aggr_List, Make_Integer_Literal (Loc, 0));
3510 -- Generate the Object Specific Data table required to dispatch calls
3511 -- through synchronized interfaces.
3514 or else Is_Abstract_Type (Typ)
3515 or else Is_Controlled (Typ)
3516 or else Restriction_Active (No_Dispatching_Calls)
3517 or else not Is_Limited_Type (Typ)
3518 or else not Has_Interfaces (Typ)
3519 or else not Build_Thunks
3520 or else not RTE_Record_Component_Available (RE_OSD_Table)
3522 -- No OSD table required
3524 Append_To (DT_Aggr_List,
3525 New_Reference_To (RTE (RE_Null_Address), Loc));
3528 OSD_Aggr_List := New_List;
3531 Prim_Table : array (Nat range 1 .. Nb_Prim) of Entity_Id;
3533 Prim_Alias : Entity_Id;
3534 Prim_Elmt : Elmt_Id;
3540 Prim_Table := (others => Empty);
3541 Prim_Alias := Empty;
3543 Prim_Elmt := First_Elmt (Primitive_Operations (Typ));
3544 while Present (Prim_Elmt) loop
3545 Prim := Node (Prim_Elmt);
3547 if Present (Interface_Alias (Prim))
3548 and then Find_Dispatching_Type
3549 (Interface_Alias (Prim)) = Iface
3551 Prim_Alias := Interface_Alias (Prim);
3554 while Present (Alias (E)) loop
3558 Pos := UI_To_Int (DT_Position (Prim_Alias));
3560 if Present (Prim_Table (Pos)) then
3561 pragma Assert (Prim_Table (Pos) = E);
3565 Prim_Table (Pos) := E;
3567 Append_To (OSD_Aggr_List,
3568 Make_Component_Association (Loc,
3569 Choices => New_List (
3570 Make_Integer_Literal (Loc,
3571 DT_Position (Prim_Alias))),
3573 Make_Integer_Literal (Loc,
3574 DT_Position (Alias (Prim)))));
3580 Next_Elmt (Prim_Elmt);
3582 pragma Assert (Count = Nb_Prim);
3585 OSD := Make_Defining_Identifier (Loc, New_Internal_Name ('I'));
3588 Make_Object_Declaration (Loc,
3589 Defining_Identifier => OSD,
3590 Object_Definition =>
3591 Make_Subtype_Indication (Loc,
3593 New_Reference_To (RTE (RE_Object_Specific_Data), Loc),
3595 Make_Index_Or_Discriminant_Constraint (Loc,
3596 Constraints => New_List (
3597 Make_Integer_Literal (Loc, Nb_Prim)))),
3598 Expression => Make_Aggregate (Loc,
3599 Component_Associations => New_List (
3600 Make_Component_Association (Loc,
3601 Choices => New_List (
3603 (RTE_Record_Component (RE_OSD_Num_Prims), Loc)),
3605 Make_Integer_Literal (Loc, Nb_Prim)),
3607 Make_Component_Association (Loc,
3608 Choices => New_List (
3610 (RTE_Record_Component (RE_OSD_Table), Loc)),
3611 Expression => Make_Aggregate (Loc,
3612 Component_Associations => OSD_Aggr_List))))));
3615 Make_Attribute_Definition_Clause (Loc,
3616 Name => New_Reference_To (OSD, Loc),
3617 Chars => Name_Alignment,
3619 Make_Attribute_Reference (Loc,
3621 New_Reference_To (RTE (RE_Integer_Address), Loc),
3622 Attribute_Name => Name_Alignment)));
3624 -- In secondary dispatch tables the Typeinfo component contains
3625 -- the address of the Object Specific Data (see a-tags.ads)
3627 Append_To (DT_Aggr_List,
3628 Make_Attribute_Reference (Loc,
3629 Prefix => New_Reference_To (OSD, Loc),
3630 Attribute_Name => Name_Address));
3633 -- Initialize the table of primitive operations
3635 Prim_Ops_Aggr_List := New_List;
3638 Append_To (Prim_Ops_Aggr_List, Make_Null (Loc));
3640 elsif Is_Abstract_Type (Typ)
3641 or else not Building_Static_DT (Typ)
3643 for J in 1 .. Nb_Prim loop
3644 Append_To (Prim_Ops_Aggr_List, Make_Null (Loc));
3649 Prim_Table : array (Nat range 1 .. Nb_Prim) of Entity_Id;
3651 Thunk_Code : Node_Id;
3652 Thunk_Id : Entity_Id;
3655 Prim_Table := (others => Empty);
3657 Prim_Elmt := First_Elmt (Primitive_Operations (Typ));
3658 while Present (Prim_Elmt) loop
3659 Prim := Node (Prim_Elmt);
3661 if not Is_Predefined_Dispatching_Operation (Prim)
3662 and then Present (Interface_Alias (Prim))
3663 and then not Is_Abstract_Subprogram (Alias (Prim))
3664 and then not Is_Imported (Alias (Prim))
3665 and then Find_Dispatching_Type
3666 (Interface_Alias (Prim)) = Iface
3668 -- Generate the code of the thunk only if the abstract
3669 -- interface type is not an immediate ancestor of
3670 -- Tagged_Type; otherwise the DT associated with the
3671 -- interface is the primary DT.
3673 and then not Is_Ancestor (Iface, Typ)
3675 if not Build_Thunks then
3677 UI_To_Int (DT_Position (Interface_Alias (Prim)));
3678 Prim_Table (Pos) := Alias (Prim);
3680 Expand_Interface_Thunk (Prim, Thunk_Id, Thunk_Code);
3682 if Present (Thunk_Id) then
3684 UI_To_Int (DT_Position (Interface_Alias (Prim)));
3686 Prim_Table (Pos) := Thunk_Id;
3687 Append_To (Result, Thunk_Code);
3692 Next_Elmt (Prim_Elmt);
3695 for J in Prim_Table'Range loop
3696 if Present (Prim_Table (J)) then
3698 Unchecked_Convert_To (RTE (RE_Prim_Ptr),
3699 Make_Attribute_Reference (Loc,
3700 Prefix => New_Reference_To (Prim_Table (J), Loc),
3701 Attribute_Name => Name_Unrestricted_Access));
3703 New_Node := Make_Null (Loc);
3706 Append_To (Prim_Ops_Aggr_List, New_Node);
3712 Make_Aggregate (Loc,
3713 Expressions => Prim_Ops_Aggr_List);
3715 Append_To (DT_Aggr_List, New_Node);
3717 -- Remember aggregates initializing dispatch tables
3719 Append_Elmt (New_Node, DT_Aggr);
3721 -- Note: Secondary dispatch tables cannot be declared constant
3722 -- because the component Offset_To_Top is currently initialized
3723 -- by the IP routine.
3726 Make_Object_Declaration (Loc,
3727 Defining_Identifier => Iface_DT,
3728 Aliased_Present => True,
3729 Constant_Present => False,
3731 Object_Definition =>
3732 Make_Subtype_Indication (Loc,
3733 Subtype_Mark => New_Reference_To
3734 (RTE (RE_Dispatch_Table_Wrapper), Loc),
3735 Constraint => Make_Index_Or_Discriminant_Constraint (Loc,
3736 Constraints => DT_Constr_List)),
3739 Make_Aggregate (Loc,
3740 Expressions => DT_Aggr_List)));
3743 Make_Attribute_Definition_Clause (Loc,
3744 Name => New_Reference_To (Iface_DT, Loc),
3745 Chars => Name_Alignment,
3748 Make_Attribute_Reference (Loc,
3750 New_Reference_To (RTE (RE_Integer_Address), Loc),
3751 Attribute_Name => Name_Alignment)));
3753 if Exporting_Table then
3754 Export_DT (Typ, Iface_DT, Suffix_Index);
3756 -- Generate code to create the pointer to the dispatch table
3758 -- Iface_DT_Ptr : Tag := Tag!(DT.Prims_Ptr'Address);
3760 -- Note: This declaration is not added here if the table is exported
3761 -- because in such case Make_Tags has already added this declaration.
3765 Make_Object_Declaration (Loc,
3766 Defining_Identifier => Iface_DT_Ptr,
3767 Constant_Present => True,
3769 Object_Definition =>
3770 New_Reference_To (RTE (RE_Interface_Tag), Loc),
3773 Unchecked_Convert_To (RTE (RE_Interface_Tag),
3774 Make_Attribute_Reference (Loc,
3776 Make_Selected_Component (Loc,
3777 Prefix => New_Reference_To (Iface_DT, Loc),
3780 (RTE_Record_Component (RE_Prims_Ptr), Loc)),
3781 Attribute_Name => Name_Address))));
3785 Make_Object_Declaration (Loc,
3786 Defining_Identifier => Predef_Prims_Ptr,
3787 Constant_Present => True,
3789 Object_Definition =>
3790 New_Reference_To (RTE (RE_Address), Loc),
3793 Make_Attribute_Reference (Loc,
3795 Make_Selected_Component (Loc,
3796 Prefix => New_Reference_To (Iface_DT, Loc),
3799 (RTE_Record_Component (RE_Predef_Prims), Loc)),
3800 Attribute_Name => Name_Address)));
3802 -- Remember entities containing dispatch tables
3804 Append_Elmt (Predef_Prims, DT_Decl);
3805 Append_Elmt (Iface_DT, DT_Decl);
3806 end Make_Secondary_DT;
3810 Elab_Code : constant List_Id := New_List;
3811 Result : constant List_Id := New_List;
3812 Tname : constant Name_Id := Chars (Typ);
3814 AI_Tag_Elmt : Elmt_Id;
3815 AI_Tag_Comp : Elmt_Id;
3816 DT_Aggr_List : List_Id;
3817 DT_Constr_List : List_Id;
3821 Iface_Table_Node : Node_Id;
3822 Name_ITable : Name_Id;
3823 Nb_Predef_Prims : Nat := 0;
3826 Num_Ifaces : Nat := 0;
3827 Parent_Typ : Entity_Id;
3829 Prim_Elmt : Elmt_Id;
3830 Prim_Ops_Aggr_List : List_Id;
3832 Typ_Comps : Elist_Id;
3833 Typ_Ifaces : Elist_Id;
3834 TSD_Aggr_List : List_Id;
3835 TSD_Tags_List : List_Id;
3837 -- The following name entries are used by Make_DT to generate a number
3838 -- of entities related to a tagged type. These entities may be generated
3839 -- in a scope other than that of the tagged type declaration, and if
3840 -- the entities for two tagged types with the same name happen to be
3841 -- generated in the same scope, we have to take care to use different
3842 -- names. This is achieved by means of a unique serial number appended
3843 -- to each generated entity name.
3845 Name_DT : constant Name_Id :=
3846 New_External_Name (Tname, 'T', Suffix_Index => -1);
3847 Name_Exname : constant Name_Id :=
3848 New_External_Name (Tname, 'E', Suffix_Index => -1);
3849 Name_HT_Link : constant Name_Id :=
3850 New_External_Name (Tname, 'H', Suffix_Index => -1);
3851 Name_Predef_Prims : constant Name_Id :=
3852 New_External_Name (Tname, 'R', Suffix_Index => -1);
3853 Name_SSD : constant Name_Id :=
3854 New_External_Name (Tname, 'S', Suffix_Index => -1);
3855 Name_TSD : constant Name_Id :=
3856 New_External_Name (Tname, 'B', Suffix_Index => -1);
3858 -- Entities built with above names
3860 DT : constant Entity_Id :=
3861 Make_Defining_Identifier (Loc, Name_DT);
3862 Exname : constant Entity_Id :=
3863 Make_Defining_Identifier (Loc, Name_Exname);
3864 HT_Link : constant Entity_Id :=
3865 Make_Defining_Identifier (Loc, Name_HT_Link);
3866 Predef_Prims : constant Entity_Id :=
3867 Make_Defining_Identifier (Loc, Name_Predef_Prims);
3868 SSD : constant Entity_Id :=
3869 Make_Defining_Identifier (Loc, Name_SSD);
3870 TSD : constant Entity_Id :=
3871 Make_Defining_Identifier (Loc, Name_TSD);
3873 -- Start of processing for Make_DT
3876 pragma Assert (Is_Frozen (Typ));
3878 -- Handle cases in which there is no need to build the dispatch table
3880 if Has_Dispatch_Table (Typ)
3881 or else No (Access_Disp_Table (Typ))
3882 or else Is_CPP_Class (Typ)
3886 elsif No_Run_Time_Mode then
3887 Error_Msg_CRT ("tagged types", Typ);
3890 elsif not RTE_Available (RE_Tag) then
3892 Make_Object_Declaration (Loc,
3893 Defining_Identifier => Node (First_Elmt
3894 (Access_Disp_Table (Typ))),
3895 Object_Definition => New_Reference_To (RTE (RE_Tag), Loc),
3896 Constant_Present => True,
3898 Unchecked_Convert_To (RTE (RE_Tag),
3899 New_Reference_To (RTE (RE_Null_Address), Loc))));
3901 Analyze_List (Result, Suppress => All_Checks);
3902 Error_Msg_CRT ("tagged types", Typ);
3906 -- Ensure that the value of Max_Predef_Prims defined in a-tags is
3907 -- correct. Valid values are 10 under configurable runtime or 16
3908 -- with full runtime.
3910 if RTE_Available (RE_Interface_Data) then
3911 if Max_Predef_Prims /= 16 then
3912 Error_Msg_N ("run-time library configuration error", Typ);
3916 if Max_Predef_Prims /= 10 then
3917 Error_Msg_N ("run-time library configuration error", Typ);
3918 Error_Msg_CRT ("tagged types", Typ);
3923 -- Initialize Parent_Typ handling private types
3925 Parent_Typ := Etype (Typ);
3927 if Present (Full_View (Parent_Typ)) then
3928 Parent_Typ := Full_View (Parent_Typ);
3931 -- Ensure that all the primitives are frozen. This is only required when
3932 -- building static dispatch tables --- the primitives must be frozen to
3933 -- be referenced (otherwise we have problems with the backend). It is
3934 -- not a requirement with nonstatic dispatch tables because in this case
3935 -- we generate now an empty dispatch table; the extra code required to
3936 -- register the primitives in the slots will be generated later --- when
3937 -- each primitive is frozen (see Freeze_Subprogram).
3939 if Building_Static_DT (Typ)
3940 and then not Is_CPP_Class (Typ)
3943 Save : constant Boolean := Freezing_Library_Level_Tagged_Type;
3945 Prim_Elmt : Elmt_Id;
3949 Freezing_Library_Level_Tagged_Type := True;
3951 Prim_Elmt := First_Elmt (Primitive_Operations (Typ));
3952 while Present (Prim_Elmt) loop
3953 Prim := Node (Prim_Elmt);
3954 Frnodes := Freeze_Entity (Prim, Loc);
3960 F := First_Formal (Prim);
3961 while Present (F) loop
3962 Check_Premature_Freezing (Prim, Etype (F));
3966 Check_Premature_Freezing (Prim, Etype (Prim));
3969 if Present (Frnodes) then
3970 Append_List_To (Result, Frnodes);
3973 Next_Elmt (Prim_Elmt);
3976 Freezing_Library_Level_Tagged_Type := Save;
3980 -- Ada 2005 (AI-251): Build the secondary dispatch tables
3982 if Has_Interfaces (Typ) then
3983 Collect_Interface_Components (Typ, Typ_Comps);
3985 -- Each secondary dispatch table is assigned an unique positive
3986 -- suffix index; such value also corresponds with the location of
3987 -- its entity in the Dispatch_Table_Wrappers list (see Make_Tags).
3989 -- Note: This value must be kept sync with the Suffix_Index values
3990 -- generated by Make_Tags
3994 Next_Elmt (Next_Elmt (First_Elmt (Access_Disp_Table (Typ))));
3996 AI_Tag_Comp := First_Elmt (Typ_Comps);
3997 while Present (AI_Tag_Comp) loop
3999 -- Build the secondary table containing pointers to thunks
4003 Iface => Base_Type (Related_Type (Node (AI_Tag_Comp))),
4004 Suffix_Index => Suffix_Index,
4005 Num_Iface_Prims => UI_To_Int
4006 (DT_Entry_Count (Node (AI_Tag_Comp))),
4007 Iface_DT_Ptr => Node (AI_Tag_Elmt),
4008 Predef_Prims_Ptr => Node (Next_Elmt (AI_Tag_Elmt)),
4009 Build_Thunks => True,
4012 -- Skip secondary dispatch table and secondary dispatch table of
4013 -- predefined primitives
4015 Next_Elmt (AI_Tag_Elmt);
4016 Next_Elmt (AI_Tag_Elmt);
4018 -- Build the secondary table containing pointers to primitives
4019 -- (used to give support to Generic Dispatching Constructors).
4023 Iface => Base_Type (Related_Type (Node (AI_Tag_Comp))),
4025 Num_Iface_Prims => UI_To_Int
4026 (DT_Entry_Count (Node (AI_Tag_Comp))),
4027 Iface_DT_Ptr => Node (AI_Tag_Elmt),
4028 Predef_Prims_Ptr => Node (Next_Elmt (AI_Tag_Elmt)),
4029 Build_Thunks => False,
4032 -- Skip secondary dispatch table and secondary dispatch table of
4033 -- predefined primitives
4035 Next_Elmt (AI_Tag_Elmt);
4036 Next_Elmt (AI_Tag_Elmt);
4038 Suffix_Index := Suffix_Index + 1;
4039 Next_Elmt (AI_Tag_Comp);
4043 -- Get the _tag entity and the number of primitives of its dispatch
4046 DT_Ptr := Node (First_Elmt (Access_Disp_Table (Typ)));
4047 Nb_Prim := UI_To_Int (DT_Entry_Count (First_Tag_Component (Typ)));
4049 Set_Is_Statically_Allocated (DT, Is_Library_Level_Tagged_Type (Typ));
4050 Set_Is_Statically_Allocated (SSD, Is_Library_Level_Tagged_Type (Typ));
4051 Set_Is_Statically_Allocated (TSD, Is_Library_Level_Tagged_Type (Typ));
4052 Set_Is_Statically_Allocated (Predef_Prims,
4053 Is_Library_Level_Tagged_Type (Typ));
4055 -- In case of locally defined tagged type we declare the object
4056 -- containing the dispatch table by means of a variable. Its
4057 -- initialization is done later by means of an assignment. This is
4058 -- required to generate its External_Tag.
4060 if not Building_Static_DT (Typ) then
4063 -- DT : No_Dispatch_Table_Wrapper;
4064 -- for DT'Alignment use Address'Alignment;
4065 -- DT_Ptr : Tag := !Tag (DT.NDT_Prims_Ptr'Address);
4067 if not Has_DT (Typ) then
4069 Make_Object_Declaration (Loc,
4070 Defining_Identifier => DT,
4071 Aliased_Present => True,
4072 Constant_Present => False,
4073 Object_Definition =>
4075 (RTE (RE_No_Dispatch_Table_Wrapper), Loc)));
4078 Make_Attribute_Definition_Clause (Loc,
4079 Name => New_Reference_To (DT, Loc),
4080 Chars => Name_Alignment,
4082 Make_Attribute_Reference (Loc,
4084 New_Reference_To (RTE (RE_Integer_Address), Loc),
4085 Attribute_Name => Name_Alignment)));
4088 Make_Object_Declaration (Loc,
4089 Defining_Identifier => DT_Ptr,
4090 Object_Definition => New_Reference_To (RTE (RE_Tag), Loc),
4091 Constant_Present => True,
4093 Unchecked_Convert_To (RTE (RE_Tag),
4094 Make_Attribute_Reference (Loc,
4096 Make_Selected_Component (Loc,
4097 Prefix => New_Reference_To (DT, Loc),
4100 (RTE_Record_Component (RE_NDT_Prims_Ptr), Loc)),
4101 Attribute_Name => Name_Address))));
4104 -- DT : Dispatch_Table_Wrapper (Nb_Prim);
4105 -- for DT'Alignment use Address'Alignment;
4106 -- DT_Ptr : Tag := !Tag (DT.Prims_Ptr'Address);
4109 -- If the tagged type has no primitives we add a dummy slot
4110 -- whose address will be the tag of this type.
4114 New_List (Make_Integer_Literal (Loc, 1));
4117 New_List (Make_Integer_Literal (Loc, Nb_Prim));
4121 Make_Object_Declaration (Loc,
4122 Defining_Identifier => DT,
4123 Aliased_Present => True,
4124 Constant_Present => False,
4125 Object_Definition =>
4126 Make_Subtype_Indication (Loc,
4128 New_Reference_To (RTE (RE_Dispatch_Table_Wrapper), Loc),
4129 Constraint => Make_Index_Or_Discriminant_Constraint (Loc,
4130 Constraints => DT_Constr_List))));
4133 Make_Attribute_Definition_Clause (Loc,
4134 Name => New_Reference_To (DT, Loc),
4135 Chars => Name_Alignment,
4137 Make_Attribute_Reference (Loc,
4139 New_Reference_To (RTE (RE_Integer_Address), Loc),
4140 Attribute_Name => Name_Alignment)));
4143 Make_Object_Declaration (Loc,
4144 Defining_Identifier => DT_Ptr,
4145 Object_Definition => New_Reference_To (RTE (RE_Tag), Loc),
4146 Constant_Present => True,
4148 Unchecked_Convert_To (RTE (RE_Tag),
4149 Make_Attribute_Reference (Loc,
4151 Make_Selected_Component (Loc,
4152 Prefix => New_Reference_To (DT, Loc),
4155 (RTE_Record_Component (RE_Prims_Ptr), Loc)),
4156 Attribute_Name => Name_Address))));
4159 Make_Object_Declaration (Loc,
4160 Defining_Identifier =>
4161 Node (Next_Elmt (First_Elmt (Access_Disp_Table (Typ)))),
4162 Constant_Present => True,
4163 Object_Definition => New_Reference_To
4164 (RTE (RE_Address), Loc),
4166 Make_Attribute_Reference (Loc,
4168 Make_Selected_Component (Loc,
4169 Prefix => New_Reference_To (DT, Loc),
4172 (RTE_Record_Component (RE_Predef_Prims), Loc)),
4173 Attribute_Name => Name_Address)));
4177 -- Generate: Exname : constant String := full_qualified_name (typ);
4178 -- The type itself may be an anonymous parent type, so use the first
4179 -- subtype to have a user-recognizable name.
4182 Make_Object_Declaration (Loc,
4183 Defining_Identifier => Exname,
4184 Constant_Present => True,
4185 Object_Definition => New_Reference_To (Standard_String, Loc),
4187 Make_String_Literal (Loc,
4188 Full_Qualified_Name (First_Subtype (Typ)))));
4190 Set_Is_Statically_Allocated (Exname);
4191 Set_Is_True_Constant (Exname);
4193 -- Declare the object used by Ada.Tags.Register_Tag
4195 if RTE_Available (RE_Register_Tag) then
4197 Make_Object_Declaration (Loc,
4198 Defining_Identifier => HT_Link,
4199 Object_Definition => New_Reference_To (RTE (RE_Tag), Loc)));
4202 -- Generate code to create the storage for the type specific data object
4203 -- with enough space to store the tags of the ancestors plus the tags
4204 -- of all the implemented interfaces (as described in a-tags.adb).
4206 -- TSD : Type_Specific_Data (I_Depth) :=
4207 -- (Idepth => I_Depth,
4208 -- Access_Level => Type_Access_Level (Typ),
4209 -- Expanded_Name => Cstring_Ptr!(Exname'Address))
4210 -- External_Tag => Cstring_Ptr!(Exname'Address))
4211 -- HT_Link => HT_Link'Address,
4212 -- Transportable => <<boolean-value>>,
4213 -- RC_Offset => <<integer-value>>,
4214 -- [ Size_Func => Size_Prim'Access ]
4215 -- [ Interfaces_Table => <<access-value>> ]
4216 -- [ SSD => SSD_Table'Address ]
4217 -- Tags_Table => (0 => null,
4220 -- for TSD'Alignment use Address'Alignment
4222 TSD_Aggr_List := New_List;
4224 -- Idepth: Count ancestors to compute the inheritance depth. For private
4225 -- extensions, always go to the full view in order to compute the real
4226 -- inheritance depth.
4229 Current_Typ : Entity_Id;
4230 Parent_Typ : Entity_Id;
4236 Parent_Typ := Etype (Current_Typ);
4238 if Is_Private_Type (Parent_Typ) then
4239 Parent_Typ := Full_View (Base_Type (Parent_Typ));
4242 exit when Parent_Typ = Current_Typ;
4244 I_Depth := I_Depth + 1;
4245 Current_Typ := Parent_Typ;
4249 Append_To (TSD_Aggr_List,
4250 Make_Integer_Literal (Loc, I_Depth));
4254 Append_To (TSD_Aggr_List,
4255 Make_Integer_Literal (Loc, Type_Access_Level (Typ)));
4259 Append_To (TSD_Aggr_List,
4260 Unchecked_Convert_To (RTE (RE_Cstring_Ptr),
4261 Make_Attribute_Reference (Loc,
4262 Prefix => New_Reference_To (Exname, Loc),
4263 Attribute_Name => Name_Address)));
4265 -- External_Tag of a local tagged type
4267 -- <typ>A : constant String :=
4268 -- "Internal tag at 16#tag-addr#: <full-name-of-typ>";
4270 -- The reason we generate this strange name is that we do not want to
4271 -- enter local tagged types in the global hash table used to compute
4272 -- the Internal_Tag attribute for two reasons:
4274 -- 1. It is hard to avoid a tasking race condition for entering the
4275 -- entry into the hash table.
4277 -- 2. It would cause a storage leak, unless we rig up considerable
4278 -- mechanism to remove the entry from the hash table on exit.
4280 -- So what we do is to generate the above external tag name, where the
4281 -- hex address is the address of the local dispatch table (i.e. exactly
4282 -- the value we want if Internal_Tag is computed from this string).
4284 -- Of course this value will only be valid if the tagged type is still
4285 -- in scope, but it clearly must be erroneous to compute the internal
4286 -- tag of a tagged type that is out of scope!
4288 -- We don't do this processing if an explicit external tag has been
4289 -- specified. That's an odd case for which we have already issued a
4290 -- warning, where we will not be able to compute the internal tag.
4292 if not Is_Library_Level_Entity (Typ)
4293 and then not Has_External_Tag_Rep_Clause (Typ)
4296 Exname : constant Entity_Id :=
4297 Make_Defining_Identifier (Loc,
4298 New_External_Name (Tname, 'A'));
4300 Full_Name : constant String_Id :=
4301 Full_Qualified_Name (First_Subtype (Typ));
4302 Str1_Id : String_Id;
4303 Str2_Id : String_Id;
4307 -- Str1 = "Internal tag at 16#";
4310 Store_String_Chars ("Internal tag at 16#");
4311 Str1_Id := End_String;
4314 -- Str2 = "#: <type-full-name>";
4317 Store_String_Chars ("#: ");
4318 Store_String_Chars (Full_Name);
4319 Str2_Id := End_String;
4322 -- Exname : constant String :=
4323 -- Str1 & Address_Image (Tag) & Str2;
4325 if RTE_Available (RE_Address_Image) then
4327 Make_Object_Declaration (Loc,
4328 Defining_Identifier => Exname,
4329 Constant_Present => True,
4330 Object_Definition => New_Reference_To
4331 (Standard_String, Loc),
4333 Make_Op_Concat (Loc,
4335 Make_String_Literal (Loc, Str1_Id),
4337 Make_Op_Concat (Loc,
4339 Make_Function_Call (Loc,
4342 (RTE (RE_Address_Image), Loc),
4343 Parameter_Associations => New_List (
4344 Unchecked_Convert_To (RTE (RE_Address),
4345 New_Reference_To (DT_Ptr, Loc)))),
4347 Make_String_Literal (Loc, Str2_Id)))));
4351 Make_Object_Declaration (Loc,
4352 Defining_Identifier => Exname,
4353 Constant_Present => True,
4354 Object_Definition => New_Reference_To
4355 (Standard_String, Loc),
4357 Make_Op_Concat (Loc,
4359 Make_String_Literal (Loc, Str1_Id),
4361 Make_String_Literal (Loc, Str2_Id))));
4365 Unchecked_Convert_To (RTE (RE_Cstring_Ptr),
4366 Make_Attribute_Reference (Loc,
4367 Prefix => New_Reference_To (Exname, Loc),
4368 Attribute_Name => Name_Address));
4371 -- External tag of a library-level tagged type: Check for a definition
4372 -- of External_Tag. The clause is considered only if it applies to this
4373 -- specific tagged type, as opposed to one of its ancestors.
4374 -- If the type is an unconstrained type extension, we are building the
4375 -- dispatch table of its anonymous base type, so the external tag, if
4376 -- any was specified, must be retrieved from the first subtype.
4380 Def : constant Node_Id := Get_Attribute_Definition_Clause
4381 (First_Subtype (Typ),
4382 Attribute_External_Tag);
4384 Old_Val : String_Id;
4385 New_Val : String_Id;
4389 if not Present (Def)
4390 or else Entity (Name (Def)) /= First_Subtype (Typ)
4393 Unchecked_Convert_To (RTE (RE_Cstring_Ptr),
4394 Make_Attribute_Reference (Loc,
4395 Prefix => New_Reference_To (Exname, Loc),
4396 Attribute_Name => Name_Address));
4398 Old_Val := Strval (Expr_Value_S (Expression (Def)));
4400 -- For the rep clause "for <typ>'external_tag use y" generate:
4402 -- <typ>A : constant string := y;
4404 -- <typ>A'Address is used to set the External_Tag component
4407 -- Create a new nul terminated string if it is not already
4409 if String_Length (Old_Val) > 0
4411 Get_String_Char (Old_Val, String_Length (Old_Val)) = 0
4415 Start_String (Old_Val);
4416 Store_String_Char (Get_Char_Code (ASCII.NUL));
4417 New_Val := End_String;
4420 E := Make_Defining_Identifier (Loc,
4421 New_External_Name (Chars (Typ), 'A'));
4424 Make_Object_Declaration (Loc,
4425 Defining_Identifier => E,
4426 Constant_Present => True,
4427 Object_Definition =>
4428 New_Reference_To (Standard_String, Loc),
4430 Make_String_Literal (Loc, New_Val)));
4433 Unchecked_Convert_To (RTE (RE_Cstring_Ptr),
4434 Make_Attribute_Reference (Loc,
4435 Prefix => New_Reference_To (E, Loc),
4436 Attribute_Name => Name_Address));
4441 Append_To (TSD_Aggr_List, New_Node);
4445 if RTE_Available (RE_Register_Tag) then
4446 Append_To (TSD_Aggr_List,
4447 Unchecked_Convert_To (RTE (RE_Tag_Ptr),
4448 Make_Attribute_Reference (Loc,
4449 Prefix => New_Reference_To (HT_Link, Loc),
4450 Attribute_Name => Name_Address)));
4452 Append_To (TSD_Aggr_List,
4453 Unchecked_Convert_To (RTE (RE_Tag_Ptr),
4454 New_Reference_To (RTE (RE_Null_Address), Loc)));
4457 -- Transportable: Set for types that can be used in remote calls
4458 -- with respect to E.4(18) legality rules.
4461 Transportable : Entity_Id;
4467 or else Is_Shared_Passive (Typ)
4469 ((Is_Remote_Types (Typ)
4470 or else Is_Remote_Call_Interface (Typ))
4471 and then Original_View_In_Visible_Part (Typ))
4472 or else not Comes_From_Source (Typ));
4474 Append_To (TSD_Aggr_List,
4475 New_Occurrence_Of (Transportable, Loc));
4478 -- RC_Offset: These are the valid values and their meaning:
4480 -- >0: For simple types with controlled components is
4481 -- type._record_controller'position
4483 -- 0: For types with no controlled components
4485 -- -1: For complex types with controlled components where the position
4486 -- of the record controller is not statically computable but there
4487 -- are controlled components at this level. The _Controller field
4488 -- is available right after the _parent.
4490 -- -2: There are no controlled components at this level. We need to
4491 -- get the position from the parent.
4494 RC_Offset_Node : Node_Id;
4497 if not Has_Controlled_Component (Typ) then
4498 RC_Offset_Node := Make_Integer_Literal (Loc, 0);
4500 elsif Etype (Typ) /= Typ
4501 and then Has_Discriminants (Parent_Typ)
4503 if Has_New_Controlled_Component (Typ) then
4504 RC_Offset_Node := Make_Integer_Literal (Loc, -1);
4506 RC_Offset_Node := Make_Integer_Literal (Loc, -2);
4510 Make_Attribute_Reference (Loc,
4512 Make_Selected_Component (Loc,
4513 Prefix => New_Reference_To (Typ, Loc),
4515 New_Reference_To (Controller_Component (Typ), Loc)),
4516 Attribute_Name => Name_Position);
4518 -- This is not proper Ada code to use the attribute 'Position
4519 -- on something else than an object but this is supported by
4520 -- the back end (see comment on the Bit_Component attribute in
4521 -- sem_attr). So we avoid semantic checking here.
4523 -- Is this documented in sinfo.ads??? it should be!
4525 Set_Analyzed (RC_Offset_Node);
4526 Set_Etype (Prefix (RC_Offset_Node), RTE (RE_Record_Controller));
4527 Set_Etype (Prefix (Prefix (RC_Offset_Node)), Typ);
4528 Set_Etype (Selector_Name (Prefix (RC_Offset_Node)),
4529 RTE (RE_Record_Controller));
4530 Set_Etype (RC_Offset_Node, RTE (RE_Storage_Offset));
4533 Append_To (TSD_Aggr_List, RC_Offset_Node);
4538 if RTE_Record_Component_Available (RE_Size_Func) then
4539 if not Building_Static_DT (Typ)
4540 or else Is_Interface (Typ)
4542 Append_To (TSD_Aggr_List,
4543 Unchecked_Convert_To (RTE (RE_Size_Ptr),
4544 New_Reference_To (RTE (RE_Null_Address), Loc)));
4548 Prim_Elmt : Elmt_Id;
4552 Prim_Elmt := First_Elmt (Primitive_Operations (Typ));
4553 while Present (Prim_Elmt) loop
4554 Prim := Node (Prim_Elmt);
4556 if Chars (Prim) = Name_uSize then
4557 while Present (Alias (Prim)) loop
4558 Prim := Alias (Prim);
4561 if Is_Abstract_Subprogram (Prim) then
4562 Append_To (TSD_Aggr_List,
4563 Unchecked_Convert_To (RTE (RE_Size_Ptr),
4564 New_Reference_To (RTE (RE_Null_Address), Loc)));
4566 Append_To (TSD_Aggr_List,
4567 Unchecked_Convert_To (RTE (RE_Size_Ptr),
4568 Make_Attribute_Reference (Loc,
4569 Prefix => New_Reference_To (Prim, Loc),
4570 Attribute_Name => Name_Unrestricted_Access)));
4576 Next_Elmt (Prim_Elmt);
4582 -- Interfaces_Table (required for AI-405)
4584 if RTE_Record_Component_Available (RE_Interfaces_Table) then
4586 -- Count the number of interface types implemented by Typ
4588 Collect_Interfaces (Typ, Typ_Ifaces);
4590 AI := First_Elmt (Typ_Ifaces);
4591 while Present (AI) loop
4592 Num_Ifaces := Num_Ifaces + 1;
4596 if Num_Ifaces = 0 then
4597 Iface_Table_Node := Make_Null (Loc);
4599 -- Generate the Interface_Table object
4603 TSD_Ifaces_List : constant List_Id := New_List;
4605 Sec_DT_Tag : Node_Id;
4608 AI := First_Elmt (Typ_Ifaces);
4609 while Present (AI) loop
4610 if Is_Ancestor (Node (AI), Typ) then
4612 New_Reference_To (DT_Ptr, Loc);
4616 (Next_Elmt (First_Elmt (Access_Disp_Table (Typ))));
4617 pragma Assert (Has_Thunks (Node (Elmt)));
4619 while Ekind (Node (Elmt)) = E_Constant
4621 Is_Ancestor (Node (AI), Related_Type (Node (Elmt)))
4623 pragma Assert (Has_Thunks (Node (Elmt)));
4625 pragma Assert (Has_Thunks (Node (Elmt)));
4627 pragma Assert (not Has_Thunks (Node (Elmt)));
4629 pragma Assert (not Has_Thunks (Node (Elmt)));
4633 pragma Assert (Ekind (Node (Elmt)) = E_Constant
4635 Has_Thunks (Node (Next_Elmt (Next_Elmt (Elmt)))));
4637 New_Reference_To (Node (Next_Elmt (Next_Elmt (Elmt))),
4641 Append_To (TSD_Ifaces_List,
4642 Make_Aggregate (Loc,
4643 Expressions => New_List (
4647 Unchecked_Convert_To (RTE (RE_Tag),
4649 (Node (First_Elmt (Access_Disp_Table (Node (AI)))),
4652 -- Static_Offset_To_Top
4654 New_Reference_To (Standard_True, Loc),
4656 -- Offset_To_Top_Value
4658 Make_Integer_Literal (Loc, 0),
4660 -- Offset_To_Top_Func
4666 Unchecked_Convert_To (RTE (RE_Tag), Sec_DT_Tag)
4673 Name_ITable := New_External_Name (Tname, 'I');
4674 ITable := Make_Defining_Identifier (Loc, Name_ITable);
4675 Set_Is_Statically_Allocated (ITable,
4676 Is_Library_Level_Tagged_Type (Typ));
4678 -- The table of interfaces is not constant; its slots are
4679 -- filled at run-time by the IP routine using attribute
4680 -- 'Position to know the location of the tag components
4681 -- (and this attribute cannot be safely used before the
4682 -- object is initialized).
4685 Make_Object_Declaration (Loc,
4686 Defining_Identifier => ITable,
4687 Aliased_Present => True,
4688 Constant_Present => False,
4689 Object_Definition =>
4690 Make_Subtype_Indication (Loc,
4692 New_Reference_To (RTE (RE_Interface_Data), Loc),
4693 Constraint => Make_Index_Or_Discriminant_Constraint
4695 Constraints => New_List (
4696 Make_Integer_Literal (Loc, Num_Ifaces)))),
4698 Expression => Make_Aggregate (Loc,
4699 Expressions => New_List (
4700 Make_Integer_Literal (Loc, Num_Ifaces),
4701 Make_Aggregate (Loc,
4702 Expressions => TSD_Ifaces_List)))));
4705 Make_Attribute_Definition_Clause (Loc,
4706 Name => New_Reference_To (ITable, Loc),
4707 Chars => Name_Alignment,
4709 Make_Attribute_Reference (Loc,
4711 New_Reference_To (RTE (RE_Integer_Address), Loc),
4712 Attribute_Name => Name_Alignment)));
4715 Make_Attribute_Reference (Loc,
4716 Prefix => New_Reference_To (ITable, Loc),
4717 Attribute_Name => Name_Unchecked_Access);
4721 Append_To (TSD_Aggr_List, Iface_Table_Node);
4724 -- Generate the Select Specific Data table for synchronized types that
4725 -- implement synchronized interfaces. The size of the table is
4726 -- constrained by the number of non-predefined primitive operations.
4728 if RTE_Record_Component_Available (RE_SSD) then
4729 if Ada_Version >= Ada_05
4730 and then Has_DT (Typ)
4731 and then Is_Concurrent_Record_Type (Typ)
4732 and then Has_Interfaces (Typ)
4733 and then Nb_Prim > 0
4734 and then not Is_Abstract_Type (Typ)
4735 and then not Is_Controlled (Typ)
4736 and then not Restriction_Active (No_Dispatching_Calls)
4739 Make_Object_Declaration (Loc,
4740 Defining_Identifier => SSD,
4741 Aliased_Present => True,
4742 Object_Definition =>
4743 Make_Subtype_Indication (Loc,
4744 Subtype_Mark => New_Reference_To (
4745 RTE (RE_Select_Specific_Data), Loc),
4747 Make_Index_Or_Discriminant_Constraint (Loc,
4748 Constraints => New_List (
4749 Make_Integer_Literal (Loc, Nb_Prim))))));
4752 Make_Attribute_Definition_Clause (Loc,
4753 Name => New_Reference_To (SSD, Loc),
4754 Chars => Name_Alignment,
4756 Make_Attribute_Reference (Loc,
4758 New_Reference_To (RTE (RE_Integer_Address), Loc),
4759 Attribute_Name => Name_Alignment)));
4761 -- This table is initialized by Make_Select_Specific_Data_Table,
4762 -- which calls Set_Entry_Index and Set_Prim_Op_Kind.
4764 Append_To (TSD_Aggr_List,
4765 Make_Attribute_Reference (Loc,
4766 Prefix => New_Reference_To (SSD, Loc),
4767 Attribute_Name => Name_Unchecked_Access));
4769 Append_To (TSD_Aggr_List, Make_Null (Loc));
4773 -- Initialize the table of ancestor tags. In case of interface types
4774 -- this table is not needed.
4776 TSD_Tags_List := New_List;
4778 -- If we are not statically allocating the dispatch table then we must
4779 -- fill position 0 with null because we still have not generated the
4782 if not Building_Static_DT (Typ)
4783 or else Is_Interface (Typ)
4785 Append_To (TSD_Tags_List,
4786 Unchecked_Convert_To (RTE (RE_Tag),
4787 New_Reference_To (RTE (RE_Null_Address), Loc)));
4789 -- Otherwise we can safely reference the tag
4792 Append_To (TSD_Tags_List,
4793 New_Reference_To (DT_Ptr, Loc));
4796 -- Fill the rest of the table with the tags of the ancestors
4799 Current_Typ : Entity_Id;
4800 Parent_Typ : Entity_Id;
4808 Parent_Typ := Etype (Current_Typ);
4810 if Is_Private_Type (Parent_Typ) then
4811 Parent_Typ := Full_View (Base_Type (Parent_Typ));
4814 exit when Parent_Typ = Current_Typ;
4816 if Is_CPP_Class (Parent_Typ)
4817 or else Is_Interface (Typ)
4819 -- The tags defined in the C++ side will be inherited when
4820 -- the object is constructed (Exp_Ch3.Build_Init_Procedure)
4822 Append_To (TSD_Tags_List,
4823 Unchecked_Convert_To (RTE (RE_Tag),
4824 New_Reference_To (RTE (RE_Null_Address), Loc)));
4826 Append_To (TSD_Tags_List,
4828 (Node (First_Elmt (Access_Disp_Table (Parent_Typ))),
4833 Current_Typ := Parent_Typ;
4836 pragma Assert (Pos = I_Depth + 1);
4839 Append_To (TSD_Aggr_List,
4840 Make_Aggregate (Loc,
4841 Expressions => TSD_Tags_List));
4843 -- Build the TSD object
4846 Make_Object_Declaration (Loc,
4847 Defining_Identifier => TSD,
4848 Aliased_Present => True,
4849 Constant_Present => Building_Static_DT (Typ),
4850 Object_Definition =>
4851 Make_Subtype_Indication (Loc,
4852 Subtype_Mark => New_Reference_To (
4853 RTE (RE_Type_Specific_Data), Loc),
4855 Make_Index_Or_Discriminant_Constraint (Loc,
4856 Constraints => New_List (
4857 Make_Integer_Literal (Loc, I_Depth)))),
4859 Expression => Make_Aggregate (Loc,
4860 Expressions => TSD_Aggr_List)));
4862 Set_Is_True_Constant (TSD, Building_Static_DT (Typ));
4865 Make_Attribute_Definition_Clause (Loc,
4866 Name => New_Reference_To (TSD, Loc),
4867 Chars => Name_Alignment,
4869 Make_Attribute_Reference (Loc,
4870 Prefix => New_Reference_To (RTE (RE_Integer_Address), Loc),
4871 Attribute_Name => Name_Alignment)));
4873 -- Initialize or declare the dispatch table object
4875 if not Has_DT (Typ) then
4876 DT_Constr_List := New_List;
4877 DT_Aggr_List := New_List;
4882 Make_Attribute_Reference (Loc,
4883 Prefix => New_Reference_To (TSD, Loc),
4884 Attribute_Name => Name_Address);
4886 Append_To (DT_Constr_List, New_Node);
4887 Append_To (DT_Aggr_List, New_Copy (New_Node));
4888 Append_To (DT_Aggr_List, Make_Integer_Literal (Loc, 0));
4890 -- In case of locally defined tagged types we have already declared
4891 -- and uninitialized object for the dispatch table, which is now
4892 -- initialized by means of the following assignment:
4894 -- DT := (TSD'Address, 0);
4896 if not Building_Static_DT (Typ) then
4898 Make_Assignment_Statement (Loc,
4899 Name => New_Reference_To (DT, Loc),
4900 Expression => Make_Aggregate (Loc,
4901 Expressions => DT_Aggr_List)));
4903 -- In case of library level tagged types we declare and export now
4904 -- the constant object containing the dummy dispatch table. There
4905 -- is no need to declare the tag here because it has been previously
4906 -- declared by Make_Tags
4908 -- DT : aliased constant No_Dispatch_Table :=
4909 -- (NDT_TSD => TSD'Address;
4910 -- NDT_Prims_Ptr => 0);
4911 -- for DT'Alignment use Address'Alignment;
4915 Make_Object_Declaration (Loc,
4916 Defining_Identifier => DT,
4917 Aliased_Present => True,
4918 Constant_Present => True,
4919 Object_Definition =>
4920 New_Reference_To (RTE (RE_No_Dispatch_Table_Wrapper), Loc),
4921 Expression => Make_Aggregate (Loc,
4922 Expressions => DT_Aggr_List)));
4925 Make_Attribute_Definition_Clause (Loc,
4926 Name => New_Reference_To (DT, Loc),
4927 Chars => Name_Alignment,
4929 Make_Attribute_Reference (Loc,
4931 New_Reference_To (RTE (RE_Integer_Address), Loc),
4932 Attribute_Name => Name_Alignment)));
4934 Export_DT (Typ, DT);
4937 -- Common case: Typ has a dispatch table
4941 -- Predef_Prims : Address_Array (1 .. Default_Prim_Ops_Count) :=
4942 -- (predef-prim-op-1'address,
4943 -- predef-prim-op-2'address,
4945 -- predef-prim-op-n'address);
4946 -- for Predef_Prims'Alignment use Address'Alignment
4948 -- DT : Dispatch_Table (Nb_Prims) :=
4949 -- (Signature => <sig-value>,
4950 -- Tag_Kind => <tag_kind-value>,
4951 -- Predef_Prims => Predef_Prims'First'Address,
4952 -- Offset_To_Top => 0,
4953 -- TSD => TSD'Address;
4954 -- Prims_Ptr => (prim-op-1'address,
4955 -- prim-op-2'address,
4957 -- prim-op-n'address));
4958 -- for DT'Alignment use Address'Alignment
4965 if not Building_Static_DT (Typ) then
4966 Nb_Predef_Prims := Max_Predef_Prims;
4969 Prim_Elmt := First_Elmt (Primitive_Operations (Typ));
4970 while Present (Prim_Elmt) loop
4971 Prim := Node (Prim_Elmt);
4973 if Is_Predefined_Dispatching_Operation (Prim)
4974 and then not Is_Abstract_Subprogram (Prim)
4976 Pos := UI_To_Int (DT_Position (Prim));
4978 if Pos > Nb_Predef_Prims then
4979 Nb_Predef_Prims := Pos;
4983 Next_Elmt (Prim_Elmt);
4989 (Nat range 1 .. Nb_Predef_Prims) of Entity_Id;
4994 Prim_Ops_Aggr_List := New_List;
4996 Prim_Table := (others => Empty);
4998 if Building_Static_DT (Typ) then
4999 Prim_Elmt := First_Elmt (Primitive_Operations (Typ));
5000 while Present (Prim_Elmt) loop
5001 Prim := Node (Prim_Elmt);
5003 if Is_Predefined_Dispatching_Operation (Prim)
5004 and then not Is_Abstract_Subprogram (Prim)
5005 and then not Present (Prim_Table
5006 (UI_To_Int (DT_Position (Prim))))
5009 while Present (Alias (E)) loop
5013 pragma Assert (not Is_Abstract_Subprogram (E));
5014 Prim_Table (UI_To_Int (DT_Position (Prim))) := E;
5017 Next_Elmt (Prim_Elmt);
5021 for J in Prim_Table'Range loop
5022 if Present (Prim_Table (J)) then
5024 Unchecked_Convert_To (RTE (RE_Prim_Ptr),
5025 Make_Attribute_Reference (Loc,
5026 Prefix => New_Reference_To (Prim_Table (J), Loc),
5027 Attribute_Name => Name_Unrestricted_Access));
5029 New_Node := Make_Null (Loc);
5032 Append_To (Prim_Ops_Aggr_List, New_Node);
5036 Make_Aggregate (Loc,
5037 Expressions => Prim_Ops_Aggr_List);
5040 Make_Subtype_Declaration (Loc,
5041 Defining_Identifier =>
5042 Make_Defining_Identifier (Loc,
5043 New_Internal_Name ('S')),
5044 Subtype_Indication =>
5045 New_Reference_To (RTE (RE_Address_Array), Loc));
5047 Append_To (Result, Decl);
5050 Make_Object_Declaration (Loc,
5051 Defining_Identifier => Predef_Prims,
5052 Aliased_Present => True,
5053 Constant_Present => Building_Static_DT (Typ),
5054 Object_Definition => New_Reference_To
5055 (Defining_Identifier (Decl), Loc),
5056 Expression => New_Node));
5058 -- Remember aggregates initializing dispatch tables
5060 Append_Elmt (New_Node, DT_Aggr);
5063 Make_Attribute_Definition_Clause (Loc,
5064 Name => New_Reference_To (Predef_Prims, Loc),
5065 Chars => Name_Alignment,
5067 Make_Attribute_Reference (Loc,
5069 New_Reference_To (RTE (RE_Integer_Address), Loc),
5070 Attribute_Name => Name_Alignment)));
5074 -- Stage 1: Initialize the discriminant and the record components
5076 DT_Constr_List := New_List;
5077 DT_Aggr_List := New_List;
5079 -- Num_Prims. If the tagged type has no primitives we add a dummy
5080 -- slot whose address will be the tag of this type.
5083 New_Node := Make_Integer_Literal (Loc, 1);
5085 New_Node := Make_Integer_Literal (Loc, Nb_Prim);
5088 Append_To (DT_Constr_List, New_Node);
5089 Append_To (DT_Aggr_List, New_Copy (New_Node));
5093 if RTE_Record_Component_Available (RE_Signature) then
5094 Append_To (DT_Aggr_List,
5095 New_Reference_To (RTE (RE_Primary_DT), Loc));
5100 if RTE_Record_Component_Available (RE_Tag_Kind) then
5101 Append_To (DT_Aggr_List, Tagged_Kind (Typ));
5106 Append_To (DT_Aggr_List,
5107 Make_Attribute_Reference (Loc,
5108 Prefix => New_Reference_To (Predef_Prims, Loc),
5109 Attribute_Name => Name_Address));
5113 Append_To (DT_Aggr_List, Make_Integer_Literal (Loc, 0));
5117 Append_To (DT_Aggr_List,
5118 Make_Attribute_Reference (Loc,
5119 Prefix => New_Reference_To (TSD, Loc),
5120 Attribute_Name => Name_Address));
5122 -- Stage 2: Initialize the table of primitive operations
5124 Prim_Ops_Aggr_List := New_List;
5127 Append_To (Prim_Ops_Aggr_List, Make_Null (Loc));
5129 elsif not Building_Static_DT (Typ) then
5130 for J in 1 .. Nb_Prim loop
5131 Append_To (Prim_Ops_Aggr_List, Make_Null (Loc));
5136 Prim_Table : array (Nat range 1 .. Nb_Prim) of Entity_Id;
5139 Prim_Elmt : Elmt_Id;
5142 Prim_Table := (others => Empty);
5144 Prim_Elmt := First_Elmt (Primitive_Operations (Typ));
5145 while Present (Prim_Elmt) loop
5146 Prim := Node (Prim_Elmt);
5148 if Is_Imported (Prim)
5149 or else Present (Interface_Alias (Prim))
5150 or else Is_Predefined_Dispatching_Operation (Prim)
5151 or else Is_Eliminated (Prim)
5156 -- Traverse the list of aliased entities to handle
5157 -- renamings of predefined primitives.
5160 while Present (Alias (E)) loop
5164 if not Is_Predefined_Dispatching_Operation (E)
5165 and then not Is_Abstract_Subprogram (E)
5166 and then not Present (Interface_Alias (E))
5169 (UI_To_Int (DT_Position (Prim)) <= Nb_Prim);
5171 Prim_Table (UI_To_Int (DT_Position (Prim))) := E;
5175 Next_Elmt (Prim_Elmt);
5178 for J in Prim_Table'Range loop
5179 if Present (Prim_Table (J)) then
5181 Unchecked_Convert_To (RTE (RE_Prim_Ptr),
5182 Make_Attribute_Reference (Loc,
5183 Prefix => New_Reference_To (Prim_Table (J), Loc),
5184 Attribute_Name => Name_Unrestricted_Access));
5186 New_Node := Make_Null (Loc);
5189 Append_To (Prim_Ops_Aggr_List, New_Node);
5195 Make_Aggregate (Loc,
5196 Expressions => Prim_Ops_Aggr_List);
5198 Append_To (DT_Aggr_List, New_Node);
5200 -- Remember aggregates initializing dispatch tables
5202 Append_Elmt (New_Node, DT_Aggr);
5204 -- In case of locally defined tagged types we have already declared
5205 -- and uninitialized object for the dispatch table, which is now
5206 -- initialized by means of an assignment.
5208 if not Building_Static_DT (Typ) then
5210 Make_Assignment_Statement (Loc,
5211 Name => New_Reference_To (DT, Loc),
5212 Expression => Make_Aggregate (Loc,
5213 Expressions => DT_Aggr_List)));
5215 -- In case of library level tagged types we declare now and export
5216 -- the constant object containing the dispatch table.
5220 Make_Object_Declaration (Loc,
5221 Defining_Identifier => DT,
5222 Aliased_Present => True,
5223 Constant_Present => True,
5224 Object_Definition =>
5225 Make_Subtype_Indication (Loc,
5226 Subtype_Mark => New_Reference_To
5227 (RTE (RE_Dispatch_Table_Wrapper), Loc),
5228 Constraint => Make_Index_Or_Discriminant_Constraint (Loc,
5229 Constraints => DT_Constr_List)),
5230 Expression => Make_Aggregate (Loc,
5231 Expressions => DT_Aggr_List)));
5234 Make_Attribute_Definition_Clause (Loc,
5235 Name => New_Reference_To (DT, Loc),
5236 Chars => Name_Alignment,
5238 Make_Attribute_Reference (Loc,
5240 New_Reference_To (RTE (RE_Integer_Address), Loc),
5241 Attribute_Name => Name_Alignment)));
5243 Export_DT (Typ, DT);
5247 -- Initialize the table of ancestor tags if not building static
5250 if not Building_Static_DT (Typ)
5251 and then not Is_Interface (Typ)
5252 and then not Is_CPP_Class (Typ)
5255 Make_Assignment_Statement (Loc,
5257 Make_Indexed_Component (Loc,
5259 Make_Selected_Component (Loc,
5261 New_Reference_To (TSD, Loc),
5264 (RTE_Record_Component (RE_Tags_Table), Loc)),
5266 New_List (Make_Integer_Literal (Loc, 0))),
5270 (Node (First_Elmt (Access_Disp_Table (Typ))), Loc)));
5273 -- Inherit the dispatch tables of the parent. There is no need to
5274 -- inherit anything from the parent when building static dispatch tables
5275 -- because the whole dispatch table (including inherited primitives) has
5276 -- been already built.
5278 if Building_Static_DT (Typ) then
5281 -- If the ancestor is a CPP_Class type we inherit the dispatch tables
5282 -- in the init proc, and we don't need to fill them in here.
5284 elsif Is_CPP_Class (Parent_Typ) then
5287 -- Otherwise we fill in the dispatch tables here
5290 if Typ /= Parent_Typ
5291 and then not Is_Interface (Typ)
5292 and then not Restriction_Active (No_Dispatching_Calls)
5294 -- Inherit the dispatch table
5296 if not Is_Interface (Typ)
5297 and then not Is_Interface (Parent_Typ)
5298 and then not Is_CPP_Class (Parent_Typ)
5301 Nb_Prims : constant Int :=
5302 UI_To_Int (DT_Entry_Count
5303 (First_Tag_Component (Parent_Typ)));
5306 Append_To (Elab_Code,
5307 Build_Inherit_Predefined_Prims (Loc,
5313 (Access_Disp_Table (Parent_Typ)))), Loc),
5319 (Access_Disp_Table (Typ)))), Loc)));
5321 if Nb_Prims /= 0 then
5322 Append_To (Elab_Code,
5323 Build_Inherit_Prims (Loc,
5329 (Access_Disp_Table (Parent_Typ))), Loc),
5330 New_Tag_Node => New_Reference_To (DT_Ptr, Loc),
5331 Num_Prims => Nb_Prims));
5336 -- Inherit the secondary dispatch tables of the ancestor
5338 if not Is_CPP_Class (Parent_Typ) then
5340 Sec_DT_Ancestor : Elmt_Id :=
5344 (Access_Disp_Table (Parent_Typ))));
5345 Sec_DT_Typ : Elmt_Id :=
5349 (Access_Disp_Table (Typ))));
5351 procedure Copy_Secondary_DTs (Typ : Entity_Id);
5352 -- Local procedure required to climb through the ancestors
5353 -- and copy the contents of all their secondary dispatch
5356 ------------------------
5357 -- Copy_Secondary_DTs --
5358 ------------------------
5360 procedure Copy_Secondary_DTs (Typ : Entity_Id) is
5365 -- Climb to the ancestor (if any) handling private types
5367 if Present (Full_View (Etype (Typ))) then
5368 if Full_View (Etype (Typ)) /= Typ then
5369 Copy_Secondary_DTs (Full_View (Etype (Typ)));
5372 elsif Etype (Typ) /= Typ then
5373 Copy_Secondary_DTs (Etype (Typ));
5376 if Present (Interfaces (Typ))
5377 and then not Is_Empty_Elmt_List (Interfaces (Typ))
5379 Iface := First_Elmt (Interfaces (Typ));
5380 E := First_Entity (Typ);
5382 and then Present (Node (Sec_DT_Ancestor))
5383 and then Ekind (Node (Sec_DT_Ancestor)) = E_Constant
5385 if Is_Tag (E) and then Chars (E) /= Name_uTag then
5387 Num_Prims : constant Int :=
5388 UI_To_Int (DT_Entry_Count (E));
5391 if not Is_Interface (Etype (Typ)) then
5393 -- Inherit first secondary dispatch table
5395 Append_To (Elab_Code,
5396 Build_Inherit_Predefined_Prims (Loc,
5398 Unchecked_Convert_To (RTE (RE_Tag),
5401 (Next_Elmt (Sec_DT_Ancestor)),
5404 Unchecked_Convert_To (RTE (RE_Tag),
5406 (Node (Next_Elmt (Sec_DT_Typ)),
5409 if Num_Prims /= 0 then
5410 Append_To (Elab_Code,
5411 Build_Inherit_Prims (Loc,
5412 Typ => Node (Iface),
5414 Unchecked_Convert_To
5417 (Node (Sec_DT_Ancestor),
5420 Unchecked_Convert_To
5423 (Node (Sec_DT_Typ), Loc)),
5424 Num_Prims => Num_Prims));
5428 Next_Elmt (Sec_DT_Ancestor);
5429 Next_Elmt (Sec_DT_Typ);
5431 -- Skip the secondary dispatch table of
5432 -- predefined primitives
5434 Next_Elmt (Sec_DT_Ancestor);
5435 Next_Elmt (Sec_DT_Typ);
5437 if not Is_Interface (Etype (Typ)) then
5439 -- Inherit second secondary dispatch table
5441 Append_To (Elab_Code,
5442 Build_Inherit_Predefined_Prims (Loc,
5444 Unchecked_Convert_To (RTE (RE_Tag),
5447 (Next_Elmt (Sec_DT_Ancestor)),
5450 Unchecked_Convert_To (RTE (RE_Tag),
5452 (Node (Next_Elmt (Sec_DT_Typ)),
5455 if Num_Prims /= 0 then
5456 Append_To (Elab_Code,
5457 Build_Inherit_Prims (Loc,
5458 Typ => Node (Iface),
5460 Unchecked_Convert_To
5463 (Node (Sec_DT_Ancestor),
5466 Unchecked_Convert_To
5469 (Node (Sec_DT_Typ), Loc)),
5470 Num_Prims => Num_Prims));
5475 Next_Elmt (Sec_DT_Ancestor);
5476 Next_Elmt (Sec_DT_Typ);
5478 -- Skip the secondary dispatch table of
5479 -- predefined primitives
5481 Next_Elmt (Sec_DT_Ancestor);
5482 Next_Elmt (Sec_DT_Typ);
5490 end Copy_Secondary_DTs;
5493 if Present (Node (Sec_DT_Ancestor))
5494 and then Ekind (Node (Sec_DT_Ancestor)) = E_Constant
5496 -- Handle private types
5498 if Present (Full_View (Typ)) then
5499 Copy_Secondary_DTs (Full_View (Typ));
5501 Copy_Secondary_DTs (Typ);
5509 -- Generate code to register the Tag in the External_Tag hash table for
5510 -- the pure Ada type only.
5512 -- Register_Tag (Dt_Ptr);
5514 -- Skip this action in the following cases:
5515 -- 1) if Register_Tag is not available.
5516 -- 2) in No_Run_Time mode.
5517 -- 3) if Typ is not defined at the library level (this is required
5518 -- to avoid adding concurrency control to the hash table used
5519 -- by the run-time to register the tags).
5521 if not No_Run_Time_Mode
5522 and then Is_Library_Level_Entity (Typ)
5523 and then RTE_Available (RE_Register_Tag)
5525 Append_To (Elab_Code,
5526 Make_Procedure_Call_Statement (Loc,
5527 Name => New_Reference_To (RTE (RE_Register_Tag), Loc),
5528 Parameter_Associations =>
5529 New_List (New_Reference_To (DT_Ptr, Loc))));
5532 if not Is_Empty_List (Elab_Code) then
5533 Append_List_To (Result, Elab_Code);
5536 -- Populate the two auxiliary tables used for dispatching
5537 -- asynchronous, conditional and timed selects for synchronized
5538 -- types that implement a limited interface.
5540 if Ada_Version >= Ada_05
5541 and then Is_Concurrent_Record_Type (Typ)
5542 and then Has_Interfaces (Typ)
5544 Append_List_To (Result,
5545 Make_Select_Specific_Data_Table (Typ));
5548 -- Remember entities containing dispatch tables
5550 Append_Elmt (Predef_Prims, DT_Decl);
5551 Append_Elmt (DT, DT_Decl);
5553 Analyze_List (Result, Suppress => All_Checks);
5554 Set_Has_Dispatch_Table (Typ);
5556 -- Mark entities containing dispatch tables. Required by the backend to
5557 -- handle them properly.
5559 if not Is_Interface (Typ) then
5564 -- Ensure that entities Prim_Ptr and Predef_Prims_Table_Ptr have
5565 -- the decoration required by the backend
5567 Set_Is_Dispatch_Table_Entity (RTE (RE_Prim_Ptr));
5568 Set_Is_Dispatch_Table_Entity (RTE (RE_Predef_Prims_Table_Ptr));
5570 -- Object declarations
5572 Elmt := First_Elmt (DT_Decl);
5573 while Present (Elmt) loop
5574 Set_Is_Dispatch_Table_Entity (Node (Elmt));
5575 pragma Assert (Ekind (Etype (Node (Elmt))) = E_Array_Subtype
5576 or else Ekind (Etype (Node (Elmt))) = E_Record_Subtype);
5577 Set_Is_Dispatch_Table_Entity (Etype (Node (Elmt)));
5581 -- Aggregates initializing dispatch tables
5583 Elmt := First_Elmt (DT_Aggr);
5584 while Present (Elmt) loop
5585 Set_Is_Dispatch_Table_Entity (Etype (Node (Elmt)));
5594 -------------------------------------
5595 -- Make_Select_Specific_Data_Table --
5596 -------------------------------------
5598 function Make_Select_Specific_Data_Table
5599 (Typ : Entity_Id) return List_Id
5601 Assignments : constant List_Id := New_List;
5602 Loc : constant Source_Ptr := Sloc (Typ);
5604 Conc_Typ : Entity_Id;
5608 Prim_Als : Entity_Id;
5609 Prim_Elmt : Elmt_Id;
5613 type Examined_Array is array (Int range <>) of Boolean;
5615 function Find_Entry_Index (E : Entity_Id) return Uint;
5616 -- Given an entry, find its index in the visible declarations of the
5617 -- corresponding concurrent type of Typ.
5619 ----------------------
5620 -- Find_Entry_Index --
5621 ----------------------
5623 function Find_Entry_Index (E : Entity_Id) return Uint is
5624 Index : Uint := Uint_1;
5625 Subp_Decl : Entity_Id;
5629 and then not Is_Empty_List (Decls)
5631 Subp_Decl := First (Decls);
5632 while Present (Subp_Decl) loop
5633 if Nkind (Subp_Decl) = N_Entry_Declaration then
5634 if Defining_Identifier (Subp_Decl) = E then
5646 end Find_Entry_Index;
5648 -- Start of processing for Make_Select_Specific_Data_Table
5651 pragma Assert (not Restriction_Active (No_Dispatching_Calls));
5653 DT_Ptr := Node (First_Elmt (Access_Disp_Table (Typ)));
5655 if Present (Corresponding_Concurrent_Type (Typ)) then
5656 Conc_Typ := Corresponding_Concurrent_Type (Typ);
5658 if Present (Full_View (Conc_Typ)) then
5659 Conc_Typ := Full_View (Conc_Typ);
5662 if Ekind (Conc_Typ) = E_Protected_Type then
5663 Decls := Visible_Declarations (Protected_Definition (
5664 Parent (Conc_Typ)));
5666 pragma Assert (Ekind (Conc_Typ) = E_Task_Type);
5667 Decls := Visible_Declarations (Task_Definition (
5668 Parent (Conc_Typ)));
5672 -- Count the non-predefined primitive operations
5674 Prim_Elmt := First_Elmt (Primitive_Operations (Typ));
5675 while Present (Prim_Elmt) loop
5676 Prim := Node (Prim_Elmt);
5678 if not (Is_Predefined_Dispatching_Operation (Prim)
5679 or else Is_Predefined_Dispatching_Alias (Prim))
5681 Nb_Prim := Nb_Prim + 1;
5684 Next_Elmt (Prim_Elmt);
5688 Examined : Examined_Array (1 .. Nb_Prim) := (others => False);
5691 Prim_Elmt := First_Elmt (Primitive_Operations (Typ));
5692 while Present (Prim_Elmt) loop
5693 Prim := Node (Prim_Elmt);
5695 -- Look for primitive overriding an abstract interface subprogram
5697 if Present (Interface_Alias (Prim))
5698 and then not Examined (UI_To_Int (DT_Position (Alias (Prim))))
5700 Prim_Pos := DT_Position (Alias (Prim));
5701 pragma Assert (UI_To_Int (Prim_Pos) <= Nb_Prim);
5702 Examined (UI_To_Int (Prim_Pos)) := True;
5704 -- Set the primitive operation kind regardless of subprogram
5706 -- Ada.Tags.Set_Prim_Op_Kind (DT_Ptr, <position>, <kind>);
5708 Append_To (Assignments,
5709 Make_Procedure_Call_Statement (Loc,
5710 Name => New_Reference_To (RTE (RE_Set_Prim_Op_Kind), Loc),
5711 Parameter_Associations => New_List (
5712 New_Reference_To (DT_Ptr, Loc),
5713 Make_Integer_Literal (Loc, Prim_Pos),
5714 Prim_Op_Kind (Alias (Prim), Typ))));
5716 -- Retrieve the root of the alias chain
5719 while Present (Alias (Prim_Als)) loop
5720 Prim_Als := Alias (Prim_Als);
5723 -- In the case of an entry wrapper, set the entry index
5725 if Ekind (Prim) = E_Procedure
5726 and then Is_Primitive_Wrapper (Prim_Als)
5727 and then Ekind (Wrapped_Entity (Prim_Als)) = E_Entry
5730 -- Ada.Tags.Set_Entry_Index
5731 -- (DT_Ptr, <position>, <index>);
5733 Append_To (Assignments,
5734 Make_Procedure_Call_Statement (Loc,
5736 New_Reference_To (RTE (RE_Set_Entry_Index), Loc),
5737 Parameter_Associations => New_List (
5738 New_Reference_To (DT_Ptr, Loc),
5739 Make_Integer_Literal (Loc, Prim_Pos),
5740 Make_Integer_Literal (Loc,
5741 Find_Entry_Index (Wrapped_Entity (Prim_Als))))));
5745 Next_Elmt (Prim_Elmt);
5750 end Make_Select_Specific_Data_Table;
5756 function Make_Tags (Typ : Entity_Id) return List_Id is
5757 Loc : constant Source_Ptr := Sloc (Typ);
5758 Result : constant List_Id := New_List;
5761 (Tag_Typ : Entity_Id;
5763 Is_Secondary_DT : Boolean);
5764 -- Import the dispatch table DT of tagged type Tag_Typ. Required to
5765 -- generate forward references and statically allocate the table. For
5766 -- primary dispatch tables that require no dispatch table generate:
5767 -- DT : static aliased constant Non_Dispatch_Table_Wrapper;
5768 -- $pragma import (ada, DT);
5769 -- Otherwise generate:
5770 -- DT : static aliased constant Dispatch_Table_Wrapper (Nb_Prim);
5771 -- $pragma import (ada, DT);
5778 (Tag_Typ : Entity_Id;
5780 Is_Secondary_DT : Boolean)
5782 DT_Constr_List : List_Id;
5786 Set_Is_Imported (DT);
5787 Set_Ekind (DT, E_Constant);
5788 Set_Related_Type (DT, Typ);
5790 -- The scope must be set now to call Get_External_Name
5792 Set_Scope (DT, Current_Scope);
5794 Get_External_Name (DT, True);
5795 Set_Interface_Name (DT,
5796 Make_String_Literal (Loc,
5797 Strval => String_From_Name_Buffer));
5799 -- Ensure proper Sprint output of this implicit importation
5801 Set_Is_Internal (DT);
5803 -- Save this entity to allow Make_DT to generate its exportation
5805 Append_Elmt (DT, Dispatch_Table_Wrappers (Typ));
5807 -- No dispatch table required
5809 if not Is_Secondary_DT
5810 and then not Has_DT (Tag_Typ)
5813 Make_Object_Declaration (Loc,
5814 Defining_Identifier => DT,
5815 Aliased_Present => True,
5816 Constant_Present => True,
5817 Object_Definition =>
5818 New_Reference_To (RTE (RE_No_Dispatch_Table_Wrapper), Loc)));
5821 -- Calculate the number of primitives of the dispatch table and
5822 -- the size of the Type_Specific_Data record.
5825 UI_To_Int (DT_Entry_Count (First_Tag_Component (Tag_Typ)));
5827 -- If the tagged type has no primitives we add a dummy slot
5828 -- whose address will be the tag of this type.
5832 New_List (Make_Integer_Literal (Loc, 1));
5835 New_List (Make_Integer_Literal (Loc, Nb_Prim));
5839 Make_Object_Declaration (Loc,
5840 Defining_Identifier => DT,
5841 Aliased_Present => True,
5842 Constant_Present => True,
5843 Object_Definition =>
5844 Make_Subtype_Indication (Loc,
5846 New_Reference_To (RTE (RE_Dispatch_Table_Wrapper), Loc),
5847 Constraint => Make_Index_Or_Discriminant_Constraint (Loc,
5848 Constraints => DT_Constr_List))));
5854 Tname : constant Name_Id := Chars (Typ);
5855 AI_Tag_Comp : Elmt_Id;
5858 Predef_Prims_Ptr : Node_Id;
5860 Iface_DT_Ptr : Node_Id;
5863 Typ_Comps : Elist_Id;
5865 -- Start of processing for Make_Tags
5868 -- 1) Generate the primary and secondary tag entities
5870 -- Collect the components associated with secondary dispatch tables
5872 if Has_Interfaces (Typ) then
5873 Collect_Interface_Components (Typ, Typ_Comps);
5876 -- 1) Generate the primary tag entities
5878 -- Primary dispatch table containing user-defined primitives
5880 DT_Ptr := Make_Defining_Identifier (Loc,
5881 New_External_Name (Tname, 'P'));
5882 Set_Etype (DT_Ptr, RTE (RE_Tag));
5884 -- Primary dispatch table containing predefined primitives
5887 Make_Defining_Identifier (Loc,
5888 Chars => New_External_Name (Tname, 'Y'));
5889 Set_Etype (Predef_Prims_Ptr, RTE (RE_Address));
5891 -- Import the forward declaration of the Dispatch Table wrapper record
5892 -- (Make_DT will take care of its exportation)
5894 if Building_Static_DT (Typ) then
5895 Set_Dispatch_Table_Wrappers (Typ, New_Elmt_List);
5898 Make_Defining_Identifier (Loc,
5899 Chars => New_External_Name (Tname, 'T'));
5901 Import_DT (Typ, DT, Is_Secondary_DT => False);
5903 if Has_DT (Typ) then
5905 Make_Object_Declaration (Loc,
5906 Defining_Identifier => DT_Ptr,
5907 Constant_Present => True,
5908 Object_Definition => New_Reference_To (RTE (RE_Tag), Loc),
5910 Unchecked_Convert_To (RTE (RE_Tag),
5911 Make_Attribute_Reference (Loc,
5913 Make_Selected_Component (Loc,
5914 Prefix => New_Reference_To (DT, Loc),
5917 (RTE_Record_Component (RE_Prims_Ptr), Loc)),
5918 Attribute_Name => Name_Address))));
5921 Make_Object_Declaration (Loc,
5922 Defining_Identifier => Predef_Prims_Ptr,
5923 Constant_Present => True,
5924 Object_Definition => New_Reference_To
5925 (RTE (RE_Address), Loc),
5927 Make_Attribute_Reference (Loc,
5929 Make_Selected_Component (Loc,
5930 Prefix => New_Reference_To (DT, Loc),
5933 (RTE_Record_Component (RE_Predef_Prims), Loc)),
5934 Attribute_Name => Name_Address)));
5936 -- No dispatch table required
5940 Make_Object_Declaration (Loc,
5941 Defining_Identifier => DT_Ptr,
5942 Constant_Present => True,
5943 Object_Definition => New_Reference_To (RTE (RE_Tag), Loc),
5945 Unchecked_Convert_To (RTE (RE_Tag),
5946 Make_Attribute_Reference (Loc,
5948 Make_Selected_Component (Loc,
5949 Prefix => New_Reference_To (DT, Loc),
5952 (RTE_Record_Component (RE_NDT_Prims_Ptr), Loc)),
5953 Attribute_Name => Name_Address))));
5956 Set_Is_True_Constant (DT_Ptr);
5957 Set_Is_Statically_Allocated (DT_Ptr);
5960 pragma Assert (No (Access_Disp_Table (Typ)));
5961 Set_Access_Disp_Table (Typ, New_Elmt_List);
5962 Append_Elmt (DT_Ptr, Access_Disp_Table (Typ));
5963 Append_Elmt (Predef_Prims_Ptr, Access_Disp_Table (Typ));
5965 -- 2) Generate the secondary tag entities
5967 if Has_Interfaces (Typ) then
5969 -- Note: The following value of Suffix_Index must be in sync with
5970 -- the Suffix_Index values of secondary dispatch tables generated
5975 -- For each interface type we build an unique external name
5976 -- associated with its corresponding secondary dispatch table.
5977 -- This external name will be used to declare an object that
5978 -- references this secondary dispatch table, value that will be
5979 -- used for the elaboration of Typ's objects and also for the
5980 -- elaboration of objects of derivations of Typ that do not
5981 -- override the primitive operation of this interface type.
5983 AI_Tag_Comp := First_Elmt (Typ_Comps);
5984 while Present (AI_Tag_Comp) loop
5985 Get_Secondary_DT_External_Name
5986 (Typ, Related_Type (Node (AI_Tag_Comp)), Suffix_Index);
5987 Typ_Name := Name_Find;
5989 if Building_Static_DT (Typ) then
5991 Make_Defining_Identifier (Loc,
5992 Chars => New_External_Name
5993 (Typ_Name, 'T', Suffix_Index => -1));
5995 (Tag_Typ => Related_Type (Node (AI_Tag_Comp)),
5997 Is_Secondary_DT => True);
6000 -- Secondary dispatch table referencing thunks to user-defined
6001 -- primitives covered by this interface.
6004 Make_Defining_Identifier (Loc,
6005 Chars => New_External_Name (Typ_Name, 'P'));
6006 Set_Etype (Iface_DT_Ptr, RTE (RE_Interface_Tag));
6007 Set_Ekind (Iface_DT_Ptr, E_Constant);
6008 Set_Is_Tag (Iface_DT_Ptr);
6009 Set_Has_Thunks (Iface_DT_Ptr);
6010 Set_Is_Statically_Allocated (Iface_DT_Ptr,
6011 Is_Library_Level_Tagged_Type (Typ));
6012 Set_Is_True_Constant (Iface_DT_Ptr);
6014 (Iface_DT_Ptr, Related_Type (Node (AI_Tag_Comp)));
6015 Append_Elmt (Iface_DT_Ptr, Access_Disp_Table (Typ));
6017 if Building_Static_DT (Typ) then
6019 Make_Object_Declaration (Loc,
6020 Defining_Identifier => Iface_DT_Ptr,
6021 Constant_Present => True,
6022 Object_Definition => New_Reference_To
6023 (RTE (RE_Interface_Tag), Loc),
6025 Unchecked_Convert_To (RTE (RE_Interface_Tag),
6026 Make_Attribute_Reference (Loc,
6028 Make_Selected_Component (Loc,
6029 Prefix => New_Reference_To (Iface_DT, Loc),
6032 (RTE_Record_Component (RE_Prims_Ptr), Loc)),
6033 Attribute_Name => Name_Address))));
6036 -- Secondary dispatch table referencing thunks to predefined
6040 Make_Defining_Identifier (Loc,
6041 Chars => New_External_Name (Typ_Name, 'Y'));
6042 Set_Etype (Iface_DT_Ptr, RTE (RE_Address));
6043 Set_Ekind (Iface_DT_Ptr, E_Constant);
6044 Set_Is_Tag (Iface_DT_Ptr);
6045 Set_Has_Thunks (Iface_DT_Ptr);
6046 Set_Is_Statically_Allocated (Iface_DT_Ptr,
6047 Is_Library_Level_Tagged_Type (Typ));
6048 Set_Is_True_Constant (Iface_DT_Ptr);
6050 (Iface_DT_Ptr, Related_Type (Node (AI_Tag_Comp)));
6051 Append_Elmt (Iface_DT_Ptr, Access_Disp_Table (Typ));
6053 -- Secondary dispatch table referencing user-defined primitives
6054 -- covered by this interface.
6057 Make_Defining_Identifier (Loc,
6058 Chars => New_External_Name (Typ_Name, 'D'));
6059 Set_Etype (Iface_DT_Ptr, RTE (RE_Interface_Tag));
6060 Set_Ekind (Iface_DT_Ptr, E_Constant);
6061 Set_Is_Tag (Iface_DT_Ptr);
6062 Set_Is_Statically_Allocated (Iface_DT_Ptr,
6063 Is_Library_Level_Tagged_Type (Typ));
6064 Set_Is_True_Constant (Iface_DT_Ptr);
6066 (Iface_DT_Ptr, Related_Type (Node (AI_Tag_Comp)));
6067 Append_Elmt (Iface_DT_Ptr, Access_Disp_Table (Typ));
6069 -- Secondary dispatch table referencing predefined primitives
6072 Make_Defining_Identifier (Loc,
6073 Chars => New_External_Name (Typ_Name, 'Z'));
6074 Set_Etype (Iface_DT_Ptr, RTE (RE_Address));
6075 Set_Ekind (Iface_DT_Ptr, E_Constant);
6076 Set_Is_Tag (Iface_DT_Ptr);
6077 Set_Is_Statically_Allocated (Iface_DT_Ptr,
6078 Is_Library_Level_Tagged_Type (Typ));
6079 Set_Is_True_Constant (Iface_DT_Ptr);
6081 (Iface_DT_Ptr, Related_Type (Node (AI_Tag_Comp)));
6082 Append_Elmt (Iface_DT_Ptr, Access_Disp_Table (Typ));
6084 Next_Elmt (AI_Tag_Comp);
6088 -- 3) At the end of Access_Disp_Table we add the entity of an access
6089 -- type declaration. It is used by Build_Get_Prim_Op_Address to
6090 -- expand dispatching calls through the primary dispatch table.
6093 -- type Typ_DT is array (1 .. Nb_Prims) of Prim_Ptr;
6094 -- type Typ_DT_Acc is access Typ_DT;
6097 Name_DT_Prims : constant Name_Id :=
6098 New_External_Name (Tname, 'G');
6099 Name_DT_Prims_Acc : constant Name_Id :=
6100 New_External_Name (Tname, 'H');
6101 DT_Prims : constant Entity_Id :=
6102 Make_Defining_Identifier (Loc, Name_DT_Prims);
6103 DT_Prims_Acc : constant Entity_Id :=
6104 Make_Defining_Identifier (Loc,
6108 Make_Full_Type_Declaration (Loc,
6109 Defining_Identifier => DT_Prims,
6111 Make_Constrained_Array_Definition (Loc,
6112 Discrete_Subtype_Definitions => New_List (
6114 Low_Bound => Make_Integer_Literal (Loc, 1),
6115 High_Bound => Make_Integer_Literal (Loc,
6117 (First_Tag_Component (Typ))))),
6118 Component_Definition =>
6119 Make_Component_Definition (Loc,
6120 Subtype_Indication =>
6121 New_Reference_To (RTE (RE_Prim_Ptr), Loc)))));
6124 Make_Full_Type_Declaration (Loc,
6125 Defining_Identifier => DT_Prims_Acc,
6127 Make_Access_To_Object_Definition (Loc,
6128 Subtype_Indication =>
6129 New_Occurrence_Of (DT_Prims, Loc))));
6131 Append_Elmt (DT_Prims_Acc, Access_Disp_Table (Typ));
6133 -- Analyze the resulting list and suppress the generation of the
6134 -- Init_Proc associated with the above array declaration because
6135 -- we never use such type in object declarations; this type is only
6136 -- used to simplify the expansion associated with dispatching calls.
6138 Analyze_List (Result);
6139 Set_Suppress_Init_Proc (Base_Type (DT_Prims));
6141 -- Mark entity of dispatch table. Required by the backend to handle
6144 Set_Is_Dispatch_Table_Entity (DT_Prims);
6147 Set_Ekind (DT_Ptr, E_Constant);
6148 Set_Is_Tag (DT_Ptr);
6149 Set_Related_Type (DT_Ptr, Typ);
6154 -----------------------------------
6155 -- Original_View_In_Visible_Part --
6156 -----------------------------------
6158 function Original_View_In_Visible_Part (Typ : Entity_Id) return Boolean is
6159 Scop : constant Entity_Id := Scope (Typ);
6162 -- The scope must be a package
6164 if not Is_Package_Or_Generic_Package (Scop) then
6168 -- A type with a private declaration has a private view declared in
6169 -- the visible part.
6171 if Has_Private_Declaration (Typ) then
6175 return List_Containing (Parent (Typ)) =
6176 Visible_Declarations (Specification (Unit_Declaration_Node (Scop)));
6177 end Original_View_In_Visible_Part;
6183 function Prim_Op_Kind
6185 Typ : Entity_Id) return Node_Id
6187 Full_Typ : Entity_Id := Typ;
6188 Loc : constant Source_Ptr := Sloc (Prim);
6189 Prim_Op : Entity_Id;
6192 -- Retrieve the original primitive operation
6195 while Present (Alias (Prim_Op)) loop
6196 Prim_Op := Alias (Prim_Op);
6199 if Ekind (Typ) = E_Record_Type
6200 and then Present (Corresponding_Concurrent_Type (Typ))
6202 Full_Typ := Corresponding_Concurrent_Type (Typ);
6205 -- When a private tagged type is completed by a concurrent type,
6206 -- retrieve the full view.
6208 if Is_Private_Type (Full_Typ) then
6209 Full_Typ := Full_View (Full_Typ);
6212 if Ekind (Prim_Op) = E_Function then
6214 -- Protected function
6216 if Ekind (Full_Typ) = E_Protected_Type then
6217 return New_Reference_To (RTE (RE_POK_Protected_Function), Loc);
6221 elsif Ekind (Full_Typ) = E_Task_Type then
6222 return New_Reference_To (RTE (RE_POK_Task_Function), Loc);
6227 return New_Reference_To (RTE (RE_POK_Function), Loc);
6231 pragma Assert (Ekind (Prim_Op) = E_Procedure);
6233 if Ekind (Full_Typ) = E_Protected_Type then
6237 if Is_Primitive_Wrapper (Prim_Op)
6238 and then Ekind (Wrapped_Entity (Prim_Op)) = E_Entry
6240 return New_Reference_To (RTE (RE_POK_Protected_Entry), Loc);
6242 -- Protected procedure
6245 return New_Reference_To (RTE (RE_POK_Protected_Procedure), Loc);
6248 elsif Ekind (Full_Typ) = E_Task_Type then
6252 if Is_Primitive_Wrapper (Prim_Op)
6253 and then Ekind (Wrapped_Entity (Prim_Op)) = E_Entry
6255 return New_Reference_To (RTE (RE_POK_Task_Entry), Loc);
6257 -- Task "procedure". These are the internally Expander-generated
6258 -- procedures (task body for instance).
6261 return New_Reference_To (RTE (RE_POK_Task_Procedure), Loc);
6264 -- Regular procedure
6267 return New_Reference_To (RTE (RE_POK_Procedure), Loc);
6272 ------------------------
6273 -- Register_Primitive --
6274 ------------------------
6276 function Register_Primitive
6278 Prim : Entity_Id) return List_Id
6281 Iface_Prim : Entity_Id;
6282 Iface_Typ : Entity_Id;
6283 Iface_DT_Ptr : Entity_Id;
6284 Iface_DT_Elmt : Elmt_Id;
6285 L : constant List_Id := New_List;
6288 Tag_Typ : Entity_Id;
6289 Thunk_Id : Entity_Id;
6290 Thunk_Code : Node_Id;
6293 pragma Assert (not Restriction_Active (No_Dispatching_Calls));
6295 if not RTE_Available (RE_Tag) then
6299 if not Present (Interface_Alias (Prim)) then
6300 Tag_Typ := Scope (DTC_Entity (Prim));
6301 Pos := DT_Position (Prim);
6302 Tag := First_Tag_Component (Tag_Typ);
6304 if Is_Predefined_Dispatching_Operation (Prim)
6305 or else Is_Predefined_Dispatching_Alias (Prim)
6308 Node (Next_Elmt (First_Elmt (Access_Disp_Table (Tag_Typ))));
6311 Build_Set_Predefined_Prim_Op_Address (Loc,
6312 Tag_Node => New_Reference_To (DT_Ptr, Loc),
6315 Unchecked_Convert_To (RTE (RE_Prim_Ptr),
6316 Make_Attribute_Reference (Loc,
6317 Prefix => New_Reference_To (Prim, Loc),
6318 Attribute_Name => Name_Unrestricted_Access))));
6320 -- Register copy of the pointer to the 'size primitive in the TSD
6322 if Chars (Prim) = Name_uSize
6323 and then RTE_Record_Component_Available (RE_Size_Func)
6325 DT_Ptr := Node (First_Elmt (Access_Disp_Table (Tag_Typ)));
6327 Build_Set_Size_Function (Loc,
6328 Tag_Node => New_Reference_To (DT_Ptr, Loc),
6329 Size_Func => Prim));
6333 pragma Assert (Pos /= Uint_0 and then Pos <= DT_Entry_Count (Tag));
6335 DT_Ptr := Node (First_Elmt (Access_Disp_Table (Tag_Typ)));
6337 Build_Set_Prim_Op_Address (Loc,
6339 Tag_Node => New_Reference_To (DT_Ptr, Loc),
6342 Unchecked_Convert_To (RTE (RE_Prim_Ptr),
6343 Make_Attribute_Reference (Loc,
6344 Prefix => New_Reference_To (Prim, Loc),
6345 Attribute_Name => Name_Unrestricted_Access))));
6348 -- Ada 2005 (AI-251): Primitive associated with an interface type
6349 -- Generate the code of the thunk only if the interface type is not an
6350 -- immediate ancestor of Typ; otherwise the dispatch table associated
6351 -- with the interface is the primary dispatch table and we have nothing
6355 Tag_Typ := Find_Dispatching_Type (Alias (Prim));
6356 Iface_Typ := Find_Dispatching_Type (Interface_Alias (Prim));
6358 pragma Assert (Is_Interface (Iface_Typ));
6360 Expand_Interface_Thunk (Prim, Thunk_Id, Thunk_Code);
6362 if not Is_Ancestor (Iface_Typ, Tag_Typ)
6363 and then Present (Thunk_Code)
6365 -- Generate the code necessary to fill the appropriate entry of
6366 -- the secondary dispatch table of Prim's controlling type with
6367 -- Thunk_Id's address.
6369 Iface_DT_Elmt := Find_Interface_ADT (Tag_Typ, Iface_Typ);
6370 Iface_DT_Ptr := Node (Iface_DT_Elmt);
6371 pragma Assert (Has_Thunks (Iface_DT_Ptr));
6373 Iface_Prim := Interface_Alias (Prim);
6374 Pos := DT_Position (Iface_Prim);
6375 Tag := First_Tag_Component (Iface_Typ);
6377 Prepend_To (L, Thunk_Code);
6379 if Is_Predefined_Dispatching_Operation (Prim)
6380 or else Is_Predefined_Dispatching_Alias (Prim)
6383 Build_Set_Predefined_Prim_Op_Address (Loc,
6385 New_Reference_To (Node (Next_Elmt (Iface_DT_Elmt)), Loc),
6388 Unchecked_Convert_To (RTE (RE_Prim_Ptr),
6389 Make_Attribute_Reference (Loc,
6390 Prefix => New_Reference_To (Thunk_Id, Loc),
6391 Attribute_Name => Name_Unrestricted_Access))));
6393 Next_Elmt (Iface_DT_Elmt);
6394 Next_Elmt (Iface_DT_Elmt);
6395 Iface_DT_Ptr := Node (Iface_DT_Elmt);
6396 pragma Assert (not Has_Thunks (Iface_DT_Ptr));
6399 Build_Set_Predefined_Prim_Op_Address (Loc,
6401 New_Reference_To (Node (Next_Elmt (Iface_DT_Elmt)), Loc),
6404 Unchecked_Convert_To (RTE (RE_Prim_Ptr),
6405 Make_Attribute_Reference (Loc,
6406 Prefix => New_Reference_To (Alias (Prim), Loc),
6407 Attribute_Name => Name_Unrestricted_Access))));
6410 pragma Assert (Pos /= Uint_0
6411 and then Pos <= DT_Entry_Count (Tag));
6414 Build_Set_Prim_Op_Address (Loc,
6416 Tag_Node => New_Reference_To (Iface_DT_Ptr, Loc),
6419 Unchecked_Convert_To (RTE (RE_Prim_Ptr),
6420 Make_Attribute_Reference (Loc,
6421 Prefix => New_Reference_To (Thunk_Id, Loc),
6422 Attribute_Name => Name_Unrestricted_Access))));
6424 Next_Elmt (Iface_DT_Elmt);
6425 Next_Elmt (Iface_DT_Elmt);
6426 Iface_DT_Ptr := Node (Iface_DT_Elmt);
6427 pragma Assert (not Has_Thunks (Iface_DT_Ptr));
6430 Build_Set_Prim_Op_Address (Loc,
6432 Tag_Node => New_Reference_To (Iface_DT_Ptr, Loc),
6435 Unchecked_Convert_To (RTE (RE_Prim_Ptr),
6436 Make_Attribute_Reference (Loc,
6437 Prefix => New_Reference_To (Alias (Prim), Loc),
6438 Attribute_Name => Name_Unrestricted_Access))));
6445 end Register_Primitive;
6447 -------------------------
6448 -- Set_All_DT_Position --
6449 -------------------------
6451 procedure Set_All_DT_Position (Typ : Entity_Id) is
6453 procedure Validate_Position (Prim : Entity_Id);
6454 -- Check that the position assigned to Prim is completely safe
6455 -- (it has not been assigned to a previously defined primitive
6456 -- operation of Typ)
6458 -----------------------
6459 -- Validate_Position --
6460 -----------------------
6462 procedure Validate_Position (Prim : Entity_Id) is
6467 -- Aliased primitives are safe
6469 if Present (Alias (Prim)) then
6473 Op_Elmt := First_Elmt (Primitive_Operations (Typ));
6474 while Present (Op_Elmt) loop
6475 Op := Node (Op_Elmt);
6477 -- No need to check against itself
6482 -- Primitive operations covering abstract interfaces are
6485 elsif Present (Interface_Alias (Op)) then
6488 -- Predefined dispatching operations are completely safe. They
6489 -- are allocated at fixed positions in a separate table.
6491 elsif Is_Predefined_Dispatching_Operation (Op)
6492 or else Is_Predefined_Dispatching_Alias (Op)
6496 -- Aliased subprograms are safe
6498 elsif Present (Alias (Op)) then
6501 elsif DT_Position (Op) = DT_Position (Prim)
6502 and then not Is_Predefined_Dispatching_Operation (Op)
6503 and then not Is_Predefined_Dispatching_Operation (Prim)
6504 and then not Is_Predefined_Dispatching_Alias (Op)
6505 and then not Is_Predefined_Dispatching_Alias (Prim)
6508 -- Handle aliased subprograms
6517 if Present (Overridden_Operation (Op_1)) then
6518 Op_1 := Overridden_Operation (Op_1);
6519 elsif Present (Alias (Op_1)) then
6520 Op_1 := Alias (Op_1);
6528 if Present (Overridden_Operation (Op_2)) then
6529 Op_2 := Overridden_Operation (Op_2);
6530 elsif Present (Alias (Op_2)) then
6531 Op_2 := Alias (Op_2);
6537 if Op_1 /= Op_2 then
6538 raise Program_Error;
6543 Next_Elmt (Op_Elmt);
6545 end Validate_Position;
6549 Parent_Typ : constant Entity_Id := Etype (Typ);
6550 First_Prim : constant Elmt_Id := First_Elmt (Primitive_Operations (Typ));
6551 The_Tag : constant Entity_Id := First_Tag_Component (Typ);
6553 Adjusted : Boolean := False;
6554 Finalized : Boolean := False;
6560 Prim_Elmt : Elmt_Id;
6562 -- Start of processing for Set_All_DT_Position
6565 pragma Assert (Present (First_Tag_Component (Typ)));
6567 -- Set the DT_Position for each primitive operation. Perform some
6568 -- sanity checks to avoid to build completely inconsistent dispatch
6571 -- First stage: Set the DTC entity of all the primitive operations
6572 -- This is required to properly read the DT_Position attribute in
6573 -- the latter stages.
6575 Prim_Elmt := First_Prim;
6577 while Present (Prim_Elmt) loop
6578 Prim := Node (Prim_Elmt);
6580 -- Predefined primitives have a separate dispatch table
6582 if not (Is_Predefined_Dispatching_Operation (Prim)
6583 or else Is_Predefined_Dispatching_Alias (Prim))
6585 Count_Prim := Count_Prim + 1;
6588 Set_DTC_Entity_Value (Typ, Prim);
6590 -- Clear any previous value of the DT_Position attribute. In this
6591 -- way we ensure that the final position of all the primitives is
6592 -- established by the following stages of this algorithm.
6594 Set_DT_Position (Prim, No_Uint);
6596 Next_Elmt (Prim_Elmt);
6600 Fixed_Prim : array (Int range 0 .. Count_Prim) of Boolean :=
6605 procedure Handle_Inherited_Private_Subprograms (Typ : Entity_Id);
6606 -- Called if Typ is declared in a nested package or a public child
6607 -- package to handle inherited primitives that were inherited by Typ
6608 -- in the visible part, but whose declaration was deferred because
6609 -- the parent operation was private and not visible at that point.
6611 procedure Set_Fixed_Prim (Pos : Nat);
6612 -- Sets to true an element of the Fixed_Prim table to indicate
6613 -- that this entry of the dispatch table of Typ is occupied.
6615 ------------------------------------------
6616 -- Handle_Inherited_Private_Subprograms --
6617 ------------------------------------------
6619 procedure Handle_Inherited_Private_Subprograms (Typ : Entity_Id) is
6622 Op_Elmt_2 : Elmt_Id;
6623 Prim_Op : Entity_Id;
6624 Parent_Subp : Entity_Id;
6627 Op_List := Primitive_Operations (Typ);
6629 Op_Elmt := First_Elmt (Op_List);
6630 while Present (Op_Elmt) loop
6631 Prim_Op := Node (Op_Elmt);
6633 -- Search primitives that are implicit operations with an
6634 -- internal name whose parent operation has a normal name.
6636 if Present (Alias (Prim_Op))
6637 and then Find_Dispatching_Type (Alias (Prim_Op)) /= Typ
6638 and then not Comes_From_Source (Prim_Op)
6639 and then Is_Internal_Name (Chars (Prim_Op))
6640 and then not Is_Internal_Name (Chars (Alias (Prim_Op)))
6642 Parent_Subp := Alias (Prim_Op);
6644 -- Check if the type has an explicit overriding for this
6647 Op_Elmt_2 := Next_Elmt (Op_Elmt);
6648 while Present (Op_Elmt_2) loop
6649 if Chars (Node (Op_Elmt_2)) = Chars (Parent_Subp)
6650 and then Type_Conformant (Prim_Op, Node (Op_Elmt_2))
6652 Set_DT_Position (Prim_Op, DT_Position (Parent_Subp));
6653 Set_DT_Position (Node (Op_Elmt_2),
6654 DT_Position (Parent_Subp));
6655 Set_Fixed_Prim (UI_To_Int (DT_Position (Prim_Op)));
6657 goto Next_Primitive;
6660 Next_Elmt (Op_Elmt_2);
6665 Next_Elmt (Op_Elmt);
6667 end Handle_Inherited_Private_Subprograms;
6669 --------------------
6670 -- Set_Fixed_Prim --
6671 --------------------
6673 procedure Set_Fixed_Prim (Pos : Nat) is
6675 pragma Assert (Pos <= Count_Prim);
6676 Fixed_Prim (Pos) := True;
6678 when Constraint_Error =>
6679 raise Program_Error;
6683 -- In case of nested packages and public child package it may be
6684 -- necessary a special management on inherited subprograms so that
6685 -- the dispatch table is properly filled.
6687 if Ekind (Scope (Scope (Typ))) = E_Package
6688 and then Scope (Scope (Typ)) /= Standard_Standard
6689 and then ((Is_Derived_Type (Typ) and then not Is_Private_Type (Typ))
6691 (Nkind (Parent (Typ)) = N_Private_Extension_Declaration
6692 and then Is_Generic_Type (Typ)))
6693 and then In_Open_Scopes (Scope (Etype (Typ)))
6694 and then Typ = Base_Type (Typ)
6696 Handle_Inherited_Private_Subprograms (Typ);
6699 -- Second stage: Register fixed entries
6702 Prim_Elmt := First_Prim;
6703 while Present (Prim_Elmt) loop
6704 Prim := Node (Prim_Elmt);
6706 -- Predefined primitives have a separate table and all its
6707 -- entries are at predefined fixed positions.
6709 if Is_Predefined_Dispatching_Operation (Prim) then
6710 Set_DT_Position (Prim, Default_Prim_Op_Position (Prim));
6712 elsif Is_Predefined_Dispatching_Alias (Prim) then
6714 while Present (Alias (E)) loop
6718 Set_DT_Position (Prim, Default_Prim_Op_Position (E));
6720 -- Overriding primitives of ancestor abstract interfaces
6722 elsif Present (Interface_Alias (Prim))
6723 and then Is_Ancestor
6724 (Find_Dispatching_Type (Interface_Alias (Prim)), Typ)
6726 pragma Assert (DT_Position (Prim) = No_Uint
6727 and then Present (DTC_Entity (Interface_Alias (Prim))));
6729 E := Interface_Alias (Prim);
6730 Set_DT_Position (Prim, DT_Position (E));
6733 (DT_Position (Alias (Prim)) = No_Uint
6734 or else DT_Position (Alias (Prim)) = DT_Position (E));
6735 Set_DT_Position (Alias (Prim), DT_Position (E));
6736 Set_Fixed_Prim (UI_To_Int (DT_Position (Prim)));
6738 -- Overriding primitives must use the same entry as the
6739 -- overridden primitive.
6741 elsif not Present (Interface_Alias (Prim))
6742 and then Present (Alias (Prim))
6743 and then Chars (Prim) = Chars (Alias (Prim))
6744 and then Find_Dispatching_Type (Alias (Prim)) /= Typ
6745 and then Is_Ancestor
6746 (Find_Dispatching_Type (Alias (Prim)), Typ)
6747 and then Present (DTC_Entity (Alias (Prim)))
6750 Set_DT_Position (Prim, DT_Position (E));
6752 if not Is_Predefined_Dispatching_Alias (E) then
6753 Set_Fixed_Prim (UI_To_Int (DT_Position (E)));
6757 Next_Elmt (Prim_Elmt);
6760 -- Third stage: Fix the position of all the new primitives
6761 -- Entries associated with primitives covering interfaces
6762 -- are handled in a latter round.
6764 Prim_Elmt := First_Prim;
6765 while Present (Prim_Elmt) loop
6766 Prim := Node (Prim_Elmt);
6768 -- Skip primitives previously set entries
6770 if DT_Position (Prim) /= No_Uint then
6773 -- Primitives covering interface primitives are handled later
6775 elsif Present (Interface_Alias (Prim)) then
6779 -- Take the next available position in the DT
6782 Nb_Prim := Nb_Prim + 1;
6783 pragma Assert (Nb_Prim <= Count_Prim);
6784 exit when not Fixed_Prim (Nb_Prim);
6787 Set_DT_Position (Prim, UI_From_Int (Nb_Prim));
6788 Set_Fixed_Prim (Nb_Prim);
6791 Next_Elmt (Prim_Elmt);
6795 -- Fourth stage: Complete the decoration of primitives covering
6796 -- interfaces (that is, propagate the DT_Position attribute
6797 -- from the aliased primitive)
6799 Prim_Elmt := First_Prim;
6800 while Present (Prim_Elmt) loop
6801 Prim := Node (Prim_Elmt);
6803 if DT_Position (Prim) = No_Uint
6804 and then Present (Interface_Alias (Prim))
6806 pragma Assert (Present (Alias (Prim))
6807 and then Find_Dispatching_Type (Alias (Prim)) = Typ);
6809 -- Check if this entry will be placed in the primary DT
6812 (Find_Dispatching_Type (Interface_Alias (Prim)), Typ)
6814 pragma Assert (DT_Position (Alias (Prim)) /= No_Uint);
6815 Set_DT_Position (Prim, DT_Position (Alias (Prim)));
6817 -- Otherwise it will be placed in the secondary DT
6821 (DT_Position (Interface_Alias (Prim)) /= No_Uint);
6822 Set_DT_Position (Prim,
6823 DT_Position (Interface_Alias (Prim)));
6827 Next_Elmt (Prim_Elmt);
6830 -- Generate listing showing the contents of the dispatch tables.
6831 -- This action is done before some further static checks because
6832 -- in case of critical errors caused by a wrong dispatch table
6833 -- we need to see the contents of such table.
6835 if Debug_Flag_ZZ then
6839 -- Final stage: Ensure that the table is correct plus some further
6840 -- verifications concerning the primitives.
6842 Prim_Elmt := First_Prim;
6844 while Present (Prim_Elmt) loop
6845 Prim := Node (Prim_Elmt);
6847 -- At this point all the primitives MUST have a position
6848 -- in the dispatch table.
6850 if DT_Position (Prim) = No_Uint then
6851 raise Program_Error;
6854 -- Calculate real size of the dispatch table
6856 if not (Is_Predefined_Dispatching_Operation (Prim)
6857 or else Is_Predefined_Dispatching_Alias (Prim))
6858 and then UI_To_Int (DT_Position (Prim)) > DT_Length
6860 DT_Length := UI_To_Int (DT_Position (Prim));
6863 -- Ensure that the assigned position to non-predefined
6864 -- dispatching operations in the dispatch table is correct.
6866 if not (Is_Predefined_Dispatching_Operation (Prim)
6867 or else Is_Predefined_Dispatching_Alias (Prim))
6869 Validate_Position (Prim);
6872 if Chars (Prim) = Name_Finalize then
6876 if Chars (Prim) = Name_Adjust then
6880 -- An abstract operation cannot be declared in the private part
6881 -- for a visible abstract type, because it could never be over-
6882 -- ridden. For explicit declarations this is checked at the
6883 -- point of declaration, but for inherited operations it must
6884 -- be done when building the dispatch table.
6886 -- Ada 2005 (AI-251): Primitives associated with interfaces are
6887 -- excluded from this check because interfaces must be visible in
6888 -- the public and private part (RM 7.3 (7.3/2))
6890 if Is_Abstract_Type (Typ)
6891 and then Is_Abstract_Subprogram (Prim)
6892 and then Present (Alias (Prim))
6893 and then not Is_Interface
6894 (Find_Dispatching_Type (Ultimate_Alias (Prim)))
6895 and then not Present (Interface_Alias (Prim))
6896 and then Is_Derived_Type (Typ)
6897 and then In_Private_Part (Current_Scope)
6899 List_Containing (Parent (Prim)) =
6900 Private_Declarations
6901 (Specification (Unit_Declaration_Node (Current_Scope)))
6902 and then Original_View_In_Visible_Part (Typ)
6904 -- We exclude Input and Output stream operations because
6905 -- Limited_Controlled inherits useless Input and Output
6906 -- stream operations from Root_Controlled, which can
6907 -- never be overridden.
6909 if not Is_TSS (Prim, TSS_Stream_Input)
6911 not Is_TSS (Prim, TSS_Stream_Output)
6914 ("abstract inherited private operation&" &
6915 " must be overridden (RM 3.9.3(10))",
6916 Parent (Typ), Prim);
6920 Next_Elmt (Prim_Elmt);
6925 if Is_Controlled (Typ) then
6926 if not Finalized then
6928 ("controlled type has no explicit Finalize method?", Typ);
6930 elsif not Adjusted then
6932 ("controlled type has no explicit Adjust method?", Typ);
6936 -- Set the final size of the Dispatch Table
6938 Set_DT_Entry_Count (The_Tag, UI_From_Int (DT_Length));
6940 -- The derived type must have at least as many components as its parent
6941 -- (for root types Etype points to itself and the test cannot fail).
6943 if DT_Entry_Count (The_Tag) <
6944 DT_Entry_Count (First_Tag_Component (Parent_Typ))
6946 raise Program_Error;
6948 end Set_All_DT_Position;
6950 -----------------------------
6951 -- Set_Default_Constructor --
6952 -----------------------------
6954 procedure Set_Default_Constructor (Typ : Entity_Id) is
6961 -- Look for the default constructor entity. For now only the
6962 -- default constructor has the flag Is_Constructor.
6964 E := Next_Entity (Typ);
6966 and then (Ekind (E) /= E_Function or else not Is_Constructor (E))
6971 -- Create the init procedure
6975 Init := Make_Defining_Identifier (Loc, Make_Init_Proc_Name (Typ));
6976 Param := Make_Defining_Identifier (Loc, Name_X);
6979 Make_Subprogram_Declaration (Loc,
6980 Make_Procedure_Specification (Loc,
6981 Defining_Unit_Name => Init,
6982 Parameter_Specifications => New_List (
6983 Make_Parameter_Specification (Loc,
6984 Defining_Identifier => Param,
6985 Parameter_Type => New_Reference_To (Typ, Loc))))));
6987 Set_Init_Proc (Typ, Init);
6988 Set_Is_Imported (Init);
6989 Set_Interface_Name (Init, Interface_Name (E));
6990 Set_Convention (Init, Convention_C);
6991 Set_Is_Public (Init);
6992 Set_Has_Completion (Init);
6994 -- If there are no constructors, mark the type as abstract since we
6995 -- won't be able to declare objects of that type.
6998 Set_Is_Abstract_Type (Typ);
7000 end Set_Default_Constructor;
7002 --------------------------
7003 -- Set_DTC_Entity_Value --
7004 --------------------------
7006 procedure Set_DTC_Entity_Value
7007 (Tagged_Type : Entity_Id;
7011 if Present (Interface_Alias (Prim))
7012 and then Is_Interface
7013 (Find_Dispatching_Type (Interface_Alias (Prim)))
7015 Set_DTC_Entity (Prim,
7018 Iface => Find_Dispatching_Type (Interface_Alias (Prim))));
7020 Set_DTC_Entity (Prim,
7021 First_Tag_Component (Tagged_Type));
7023 end Set_DTC_Entity_Value;
7029 function Tagged_Kind (T : Entity_Id) return Node_Id is
7030 Conc_Typ : Entity_Id;
7031 Loc : constant Source_Ptr := Sloc (T);
7035 (Is_Tagged_Type (T) and then RTE_Available (RE_Tagged_Kind));
7039 if Is_Abstract_Type (T) then
7040 if Is_Limited_Record (T) then
7041 return New_Reference_To (RTE (RE_TK_Abstract_Limited_Tagged), Loc);
7043 return New_Reference_To (RTE (RE_TK_Abstract_Tagged), Loc);
7048 elsif Is_Concurrent_Record_Type (T) then
7049 Conc_Typ := Corresponding_Concurrent_Type (T);
7051 if Present (Full_View (Conc_Typ)) then
7052 Conc_Typ := Full_View (Conc_Typ);
7055 if Ekind (Conc_Typ) = E_Protected_Type then
7056 return New_Reference_To (RTE (RE_TK_Protected), Loc);
7058 pragma Assert (Ekind (Conc_Typ) = E_Task_Type);
7059 return New_Reference_To (RTE (RE_TK_Task), Loc);
7062 -- Regular tagged kinds
7065 if Is_Limited_Record (T) then
7066 return New_Reference_To (RTE (RE_TK_Limited_Tagged), Loc);
7068 return New_Reference_To (RTE (RE_TK_Tagged), Loc);
7077 procedure Write_DT (Typ : Entity_Id) is
7082 -- Protect this procedure against wrong usage. Required because it will
7083 -- be used directly from GDB
7085 if not (Typ <= Last_Node_Id)
7086 or else not Is_Tagged_Type (Typ)
7088 Write_Str ("wrong usage: Write_DT must be used with tagged types");
7093 Write_Int (Int (Typ));
7095 Write_Name (Chars (Typ));
7097 if Is_Interface (Typ) then
7098 Write_Str (" is interface");
7103 Elmt := First_Elmt (Primitive_Operations (Typ));
7104 while Present (Elmt) loop
7105 Prim := Node (Elmt);
7108 -- Indicate if this primitive will be allocated in the primary
7109 -- dispatch table or in a secondary dispatch table associated
7110 -- with an abstract interface type
7112 if Present (DTC_Entity (Prim)) then
7113 if Etype (DTC_Entity (Prim)) = RTE (RE_Tag) then
7120 -- Output the node of this primitive operation and its name
7122 Write_Int (Int (Prim));
7125 if Is_Predefined_Dispatching_Operation (Prim) then
7126 Write_Str ("(predefined) ");
7129 Write_Name (Chars (Prim));
7131 -- Indicate if this primitive has an aliased primitive
7133 if Present (Alias (Prim)) then
7134 Write_Str (" (alias = ");
7135 Write_Int (Int (Alias (Prim)));
7137 -- If the DTC_Entity attribute is already set we can also output
7138 -- the name of the interface covered by this primitive (if any)
7140 if Present (DTC_Entity (Alias (Prim)))
7141 and then Is_Interface (Scope (DTC_Entity (Alias (Prim))))
7143 Write_Str (" from interface ");
7144 Write_Name (Chars (Scope (DTC_Entity (Alias (Prim)))));
7147 if Present (Interface_Alias (Prim)) then
7148 Write_Str (", AI_Alias of ");
7150 (Chars (Find_Dispatching_Type (Interface_Alias (Prim))));
7152 Write_Int (Int (Interface_Alias (Prim)));
7158 -- Display the final position of this primitive in its associated
7159 -- (primary or secondary) dispatch table
7161 if Present (DTC_Entity (Prim))
7162 and then DT_Position (Prim) /= No_Uint
7164 Write_Str (" at #");
7165 Write_Int (UI_To_Int (DT_Position (Prim)));
7168 if Is_Abstract_Subprogram (Prim) then
7169 Write_Str (" is abstract;");
7171 -- Check if this is a null primitive
7173 elsif Comes_From_Source (Prim)
7174 and then Ekind (Prim) = E_Procedure
7175 and then Null_Present (Parent (Prim))
7177 Write_Str (" is null;");
7180 if Is_Eliminated (Ultimate_Alias (Prim)) then
7181 Write_Str (" (eliminated)");