1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2007, Free Software Foundation, Inc. --
11 -- GNAT is free software; you can redistribute it and/or modify it under --
12 -- terms of the GNU General Public License as published by the Free Soft- --
13 -- ware Foundation; either version 2, 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 COPYING. If not, write --
19 -- to the Free Software Foundation, 51 Franklin Street, Fifth Floor, --
20 -- Boston, MA 02110-1301, USA. --
22 -- GNAT was originally developed by the GNAT team at New York University. --
23 -- Extensive contributions were provided by Ada Core Technologies Inc. --
25 ------------------------------------------------------------------------------
27 with Atree; use Atree;
28 with Checks; use Checks;
29 with Debug; use Debug;
30 with Einfo; use Einfo;
31 with Elists; use Elists;
32 with Errout; use Errout;
33 with Exp_Atag; use Exp_Atag;
34 with Exp_Ch7; use Exp_Ch7;
35 with Exp_Dbug; use Exp_Dbug;
36 with Exp_Tss; use Exp_Tss;
37 with Exp_Util; use Exp_Util;
38 with Freeze; use Freeze;
39 with Itypes; use Itypes;
40 with 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_Ch6; use Sem_Ch6;
50 with Sem_Ch8; use Sem_Ch8;
51 with Sem_Disp; use Sem_Disp;
52 with Sem_Eval; use Sem_Eval;
53 with Sem_Res; use Sem_Res;
54 with Sem_Type; use Sem_Type;
55 with Sem_Util; use Sem_Util;
56 with Sinfo; use Sinfo;
57 with Snames; use Snames;
58 with Stand; use Stand;
59 with Stringt; use Stringt;
60 with Targparm; use Targparm;
61 with Tbuild; use Tbuild;
62 with Uintp; use Uintp;
64 package body Exp_Disp is
66 -----------------------
67 -- Local Subprograms --
68 -----------------------
70 function Default_Prim_Op_Position (E : Entity_Id) return Uint;
71 -- Ada 2005 (AI-251): Returns the fixed position in the dispatch table
72 -- of the default primitive operations.
74 function Is_Predefined_Dispatching_Alias (Prim : Entity_Id) return Boolean;
75 -- Returns true if Prim is not a predefined dispatching primitive but it is
76 -- an alias of a predefined dispatching primitive (ie. through a renaming)
78 function Original_View_In_Visible_Part (Typ : Entity_Id) return Boolean;
79 -- Check if the type has a private view or if the public view appears
80 -- in the visible part of a package spec.
84 Typ : Entity_Id) return Node_Id;
85 -- Ada 2005 (AI-345): Determine the primitive operation kind of Prim
86 -- according to its type Typ. Return a reference to an RE_Prim_Op_Kind
89 function Tagged_Kind (T : Entity_Id) return Node_Id;
90 -- Ada 2005 (AI-345): Determine the tagged kind of T and return a reference
91 -- to an RE_Tagged_Kind enumeration value.
93 ----------------------------------
94 -- Build_Static_Dispatch_Tables --
95 ----------------------------------
97 procedure Build_Static_Dispatch_Tables (N : Entity_Id) is
98 Target_List : List_Id;
100 procedure Build_Dispatch_Tables (List : List_Id);
101 -- Build the static dispatch table of tagged types found in the list of
102 -- declarations. The generated nodes are added at the end of Target_List
104 procedure Build_Package_Dispatch_Tables (N : Node_Id);
105 -- Build static dispatch tables associated with package declaration N
107 ---------------------------
108 -- Build_Dispatch_Tables --
109 ---------------------------
111 procedure Build_Dispatch_Tables (List : List_Id) is
116 while Present (D) loop
118 -- Handle nested packages and package bodies recursively. The
119 -- generated code is placed on the Target_List established for
120 -- the enclosing compilation unit.
122 if Nkind (D) = N_Package_Declaration then
123 Build_Package_Dispatch_Tables (D);
125 elsif Nkind (D) = N_Package_Body then
126 Build_Dispatch_Tables (Declarations (D));
128 elsif Nkind (D) = N_Package_Body_Stub
129 and then Present (Library_Unit (D))
131 Build_Dispatch_Tables
132 (Declarations (Proper_Body (Unit (Library_Unit (D)))));
134 -- Handle full type declarations and derivations of library
135 -- level tagged types
137 elsif (Nkind (D) = N_Full_Type_Declaration
138 or else Nkind (D) = N_Derived_Type_Definition)
139 and then Is_Library_Level_Tagged_Type (Defining_Entity (D))
140 and then Ekind (Defining_Entity (D)) /= E_Record_Subtype
141 and then not Is_Private_Type (Defining_Entity (D))
143 Insert_List_After_And_Analyze (Last (Target_List),
144 Make_DT (Defining_Entity (D)));
146 -- Handle private types of library level tagged types. We must
147 -- exchange the private and full-view to ensure the correct
150 elsif (Nkind (D) = N_Private_Type_Declaration
151 or else Nkind (D) = N_Private_Extension_Declaration)
152 and then Present (Full_View (Defining_Entity (D)))
153 and then Is_Library_Level_Tagged_Type
154 (Full_View (Defining_Entity (D)))
155 and then Ekind (Full_View (Defining_Entity (D)))
161 E1 := Defining_Entity (D);
162 E2 := Full_View (Defining_Entity (D));
163 Exchange_Entities (E1, E2);
164 Insert_List_After_And_Analyze (Last (Target_List),
166 Exchange_Entities (E1, E2);
172 end Build_Dispatch_Tables;
174 -----------------------------------
175 -- Build_Package_Dispatch_Tables --
176 -----------------------------------
178 procedure Build_Package_Dispatch_Tables (N : Node_Id) is
179 Spec : constant Node_Id := Specification (N);
180 Id : constant Entity_Id := Defining_Entity (N);
181 Vis_Decls : constant List_Id := Visible_Declarations (Spec);
182 Priv_Decls : constant List_Id := Private_Declarations (Spec);
187 if Present (Priv_Decls) then
188 Build_Dispatch_Tables (Vis_Decls);
189 Build_Dispatch_Tables (Priv_Decls);
191 elsif Present (Vis_Decls) then
192 Build_Dispatch_Tables (Vis_Decls);
196 end Build_Package_Dispatch_Tables;
198 -- Start of processing for Build_Static_Dispatch_Tables
201 if not Expander_Active
202 or else VM_Target /= No_VM
207 if Nkind (N) = N_Package_Declaration then
209 Spec : constant Node_Id := Specification (N);
210 Vis_Decls : constant List_Id := Visible_Declarations (Spec);
211 Priv_Decls : constant List_Id := Private_Declarations (Spec);
214 if Present (Priv_Decls)
215 and then Is_Non_Empty_List (Priv_Decls)
217 Target_List := Priv_Decls;
219 elsif not Present (Vis_Decls) then
220 Target_List := New_List;
221 Set_Private_Declarations (Spec, Target_List);
223 Target_List := Vis_Decls;
226 Build_Package_Dispatch_Tables (N);
229 else pragma Assert (Nkind (N) = N_Package_Body);
230 Target_List := Declarations (N);
231 Build_Dispatch_Tables (Target_List);
233 end Build_Static_Dispatch_Tables;
235 ------------------------------
236 -- Default_Prim_Op_Position --
237 ------------------------------
239 function Default_Prim_Op_Position (E : Entity_Id) return Uint is
240 TSS_Name : TSS_Name_Type;
243 Get_Name_String (Chars (E));
246 (Name_Buffer (Name_Len - TSS_Name'Length + 1 .. Name_Len));
248 if Chars (E) = Name_uSize then
251 elsif Chars (E) = Name_uAlignment then
254 elsif TSS_Name = TSS_Stream_Read then
257 elsif TSS_Name = TSS_Stream_Write then
260 elsif TSS_Name = TSS_Stream_Input then
263 elsif TSS_Name = TSS_Stream_Output then
266 elsif Chars (E) = Name_Op_Eq then
269 elsif Chars (E) = Name_uAssign then
272 elsif TSS_Name = TSS_Deep_Adjust then
275 elsif TSS_Name = TSS_Deep_Finalize then
278 elsif Ada_Version >= Ada_05 then
279 if Chars (E) = Name_uDisp_Asynchronous_Select then
282 elsif Chars (E) = Name_uDisp_Conditional_Select then
285 elsif Chars (E) = Name_uDisp_Get_Prim_Op_Kind then
288 elsif Chars (E) = Name_uDisp_Get_Task_Id then
291 elsif Chars (E) = Name_uDisp_Timed_Select then
297 end Default_Prim_Op_Position;
299 -----------------------------
300 -- Expand_Dispatching_Call --
301 -----------------------------
303 procedure Expand_Dispatching_Call (Call_Node : Node_Id) is
304 Loc : constant Source_Ptr := Sloc (Call_Node);
305 Call_Typ : constant Entity_Id := Etype (Call_Node);
307 Ctrl_Arg : constant Node_Id := Controlling_Argument (Call_Node);
308 Param_List : constant List_Id := Parameter_Associations (Call_Node);
313 New_Call_Name : Node_Id;
314 New_Params : List_Id := No_List;
317 Subp_Ptr_Typ : Entity_Id;
318 Subp_Typ : Entity_Id;
320 Eq_Prim_Op : Entity_Id := Empty;
321 Controlling_Tag : Node_Id;
323 function New_Value (From : Node_Id) return Node_Id;
324 -- From is the original Expression. New_Value is equivalent to a call
325 -- to Duplicate_Subexpr with an explicit dereference when From is an
332 function New_Value (From : Node_Id) return Node_Id is
333 Res : constant Node_Id := Duplicate_Subexpr (From);
335 if Is_Access_Type (Etype (From)) then
337 Make_Explicit_Dereference (Sloc (From),
344 -- Start of processing for Expand_Dispatching_Call
347 if No_Run_Time_Mode then
348 Error_Msg_CRT ("tagged types", Call_Node);
352 -- Expand_Dispatching_Call is called directly from the semantics,
353 -- so we need a check to see whether expansion is active before
354 -- proceeding. In addition, there is no need to expand the call
355 -- if we are compiling under restriction No_Dispatching_Calls;
356 -- the semantic analyzer has previously notified the violation
357 -- of this restriction.
359 if not Expander_Active
360 or else Restriction_Active (No_Dispatching_Calls)
365 -- Set subprogram. If this is an inherited operation that was
366 -- overridden, the body that is being called is its alias.
368 Subp := Entity (Name (Call_Node));
370 if Present (Alias (Subp))
371 and then Is_Inherited_Operation (Subp)
372 and then No (DTC_Entity (Subp))
374 Subp := Alias (Subp);
377 -- Definition of the class-wide type and the tagged type
379 -- If the controlling argument is itself a tag rather than a tagged
380 -- object, then use the class-wide type associated with the subprogram's
381 -- controlling type. This case can occur when a call to an inherited
382 -- primitive has an actual that originated from a default parameter
383 -- given by a tag-indeterminate call and when there is no other
384 -- controlling argument providing the tag (AI-239 requires dispatching).
385 -- This capability of dispatching directly by tag is also needed by the
386 -- implementation of AI-260 (for the generic dispatching constructors).
388 if Etype (Ctrl_Arg) = RTE (RE_Tag)
389 or else (RTE_Available (RE_Interface_Tag)
390 and then Etype (Ctrl_Arg) = RTE (RE_Interface_Tag))
392 CW_Typ := Class_Wide_Type (Find_Dispatching_Type (Subp));
394 -- Class_Wide_Type is applied to the expressions used to initialize
395 -- CW_Typ, to ensure that CW_Typ always denotes a class-wide type, since
396 -- there are cases where the controlling type is resolved to a specific
397 -- type (such as for designated types of arguments such as CW'Access).
399 elsif Is_Access_Type (Etype (Ctrl_Arg)) then
400 CW_Typ := Class_Wide_Type (Designated_Type (Etype (Ctrl_Arg)));
403 CW_Typ := Class_Wide_Type (Etype (Ctrl_Arg));
406 Typ := Root_Type (CW_Typ);
408 if Ekind (Typ) = E_Incomplete_Type then
409 Typ := Non_Limited_View (Typ);
412 if not Is_Limited_Type (Typ) then
413 Eq_Prim_Op := Find_Prim_Op (Typ, Name_Op_Eq);
416 -- Dispatching call to C++ primitive. Create a new parameter list
417 -- with no tag checks.
419 if Is_CPP_Class (Typ) then
420 New_Params := New_List;
421 Param := First_Actual (Call_Node);
422 while Present (Param) loop
423 Append_To (New_Params, Relocate_Node (Param));
427 -- Dispatching call to Ada primitive
429 elsif Present (Param_List) then
431 -- Generate the Tag checks when appropriate
433 New_Params := New_List;
434 Param := First_Actual (Call_Node);
435 while Present (Param) loop
437 -- No tag check with itself
439 if Param = Ctrl_Arg then
440 Append_To (New_Params,
441 Duplicate_Subexpr_Move_Checks (Param));
443 -- No tag check for parameter whose type is neither tagged nor
444 -- access to tagged (for access parameters)
446 elsif No (Find_Controlling_Arg (Param)) then
447 Append_To (New_Params, Relocate_Node (Param));
449 -- No tag check for function dispatching on result if the
450 -- Tag given by the context is this one
452 elsif Find_Controlling_Arg (Param) = Ctrl_Arg then
453 Append_To (New_Params, Relocate_Node (Param));
455 -- "=" is the only dispatching operation allowed to get
456 -- operands with incompatible tags (it just returns false).
457 -- We use Duplicate_Subexpr_Move_Checks instead of calling
458 -- Relocate_Node because the value will be duplicated to
461 elsif Subp = Eq_Prim_Op then
462 Append_To (New_Params,
463 Duplicate_Subexpr_Move_Checks (Param));
465 -- No check in presence of suppress flags
467 elsif Tag_Checks_Suppressed (Etype (Param))
468 or else (Is_Access_Type (Etype (Param))
469 and then Tag_Checks_Suppressed
470 (Designated_Type (Etype (Param))))
472 Append_To (New_Params, Relocate_Node (Param));
474 -- Optimization: no tag checks if the parameters are identical
476 elsif Is_Entity_Name (Param)
477 and then Is_Entity_Name (Ctrl_Arg)
478 and then Entity (Param) = Entity (Ctrl_Arg)
480 Append_To (New_Params, Relocate_Node (Param));
482 -- Now we need to generate the Tag check
485 -- Generate code for tag equality check
486 -- Perhaps should have Checks.Apply_Tag_Equality_Check???
488 Insert_Action (Ctrl_Arg,
489 Make_Implicit_If_Statement (Call_Node,
493 Make_Selected_Component (Loc,
494 Prefix => New_Value (Ctrl_Arg),
497 (First_Tag_Component (Typ), Loc)),
500 Make_Selected_Component (Loc,
502 Unchecked_Convert_To (Typ, New_Value (Param)),
505 (First_Tag_Component (Typ), Loc))),
508 New_List (New_Constraint_Error (Loc))));
510 Append_To (New_Params, Relocate_Node (Param));
517 -- Generate the appropriate subprogram pointer type
519 if Etype (Subp) = Typ then
522 Res_Typ := Etype (Subp);
525 Subp_Typ := Create_Itype (E_Subprogram_Type, Call_Node);
526 Subp_Ptr_Typ := Create_Itype (E_Access_Subprogram_Type, Call_Node);
527 Set_Etype (Subp_Typ, Res_Typ);
528 Init_Size_Align (Subp_Ptr_Typ);
529 Set_Returns_By_Ref (Subp_Typ, Returns_By_Ref (Subp));
531 -- Create a new list of parameters which is a copy of the old formal
532 -- list including the creation of a new set of matching entities.
535 Old_Formal : Entity_Id := First_Formal (Subp);
536 New_Formal : Entity_Id;
537 Extra : Entity_Id := Empty;
540 if Present (Old_Formal) then
541 New_Formal := New_Copy (Old_Formal);
542 Set_First_Entity (Subp_Typ, New_Formal);
543 Param := First_Actual (Call_Node);
546 Set_Scope (New_Formal, Subp_Typ);
548 -- Change all the controlling argument types to be class-wide
549 -- to avoid a recursion in dispatching.
551 if Is_Controlling_Formal (New_Formal) then
552 Set_Etype (New_Formal, Etype (Param));
555 if Is_Itype (Etype (New_Formal)) then
556 Extra := New_Copy (Etype (New_Formal));
558 if Ekind (Extra) = E_Record_Subtype
559 or else Ekind (Extra) = E_Class_Wide_Subtype
561 Set_Cloned_Subtype (Extra, Etype (New_Formal));
564 Set_Etype (New_Formal, Extra);
565 Set_Scope (Etype (New_Formal), Subp_Typ);
569 Next_Formal (Old_Formal);
570 exit when No (Old_Formal);
572 Set_Next_Entity (New_Formal, New_Copy (Old_Formal));
573 Next_Entity (New_Formal);
577 Set_Next_Entity (New_Formal, Empty);
578 Set_Last_Entity (Subp_Typ, Extra);
581 -- Now that the explicit formals have been duplicated, any extra
582 -- formals needed by the subprogram must be created.
584 if Present (Extra) then
585 Set_Extra_Formal (Extra, Empty);
588 Create_Extra_Formals (Subp_Typ);
591 Set_Etype (Subp_Ptr_Typ, Subp_Ptr_Typ);
592 Set_Directly_Designated_Type (Subp_Ptr_Typ, Subp_Typ);
594 -- If the controlling argument is a value of type Ada.Tag or an abstract
595 -- interface class-wide type then use it directly. Otherwise, the tag
596 -- must be extracted from the controlling object.
598 if Etype (Ctrl_Arg) = RTE (RE_Tag)
599 or else (RTE_Available (RE_Interface_Tag)
600 and then Etype (Ctrl_Arg) = RTE (RE_Interface_Tag))
602 Controlling_Tag := Duplicate_Subexpr (Ctrl_Arg);
604 -- Extract the tag from an unchecked type conversion. Done to avoid
605 -- the expansion of additional code just to obtain the value of such
606 -- tag because the current management of interface type conversions
607 -- generates in some cases this unchecked type conversion with the
608 -- tag of the object (see Expand_Interface_Conversion).
610 elsif Nkind (Ctrl_Arg) = N_Unchecked_Type_Conversion
612 (Etype (Expression (Ctrl_Arg)) = RTE (RE_Tag)
614 (RTE_Available (RE_Interface_Tag)
616 Etype (Expression (Ctrl_Arg)) = RTE (RE_Interface_Tag)))
618 Controlling_Tag := Duplicate_Subexpr (Expression (Ctrl_Arg));
620 -- Ada 2005 (AI-251): Abstract interface class-wide type
622 elsif Is_Interface (Etype (Ctrl_Arg))
623 and then Is_Class_Wide_Type (Etype (Ctrl_Arg))
625 Controlling_Tag := Duplicate_Subexpr (Ctrl_Arg);
629 Make_Selected_Component (Loc,
630 Prefix => Duplicate_Subexpr_Move_Checks (Ctrl_Arg),
631 Selector_Name => New_Reference_To (DTC_Entity (Subp), Loc));
634 -- Handle dispatching calls to predefined primitives
636 if Is_Predefined_Dispatching_Operation (Subp)
637 or else Is_Predefined_Dispatching_Alias (Subp)
640 Unchecked_Convert_To (Subp_Ptr_Typ,
641 Build_Get_Predefined_Prim_Op_Address (Loc,
642 Tag_Node => Controlling_Tag,
643 Position => DT_Position (Subp)));
645 -- Handle dispatching calls to user-defined primitives
649 Unchecked_Convert_To (Subp_Ptr_Typ,
650 Build_Get_Prim_Op_Address (Loc,
651 Typ => Find_Dispatching_Type (Subp),
652 Tag_Node => Controlling_Tag,
653 Position => DT_Position (Subp)));
656 if Nkind (Call_Node) = N_Function_Call then
659 Make_Function_Call (Loc,
660 Name => New_Call_Name,
661 Parameter_Associations => New_Params);
663 -- If this is a dispatching "=", we must first compare the tags so
664 -- we generate: x.tag = y.tag and then x = y
666 if Subp = Eq_Prim_Op then
667 Param := First_Actual (Call_Node);
673 Make_Selected_Component (Loc,
674 Prefix => New_Value (Param),
676 New_Reference_To (First_Tag_Component (Typ),
680 Make_Selected_Component (Loc,
682 Unchecked_Convert_To (Typ,
683 New_Value (Next_Actual (Param))),
685 New_Reference_To (First_Tag_Component (Typ),
687 Right_Opnd => New_Call);
692 Make_Procedure_Call_Statement (Loc,
693 Name => New_Call_Name,
694 Parameter_Associations => New_Params);
697 Rewrite (Call_Node, New_Call);
699 -- Suppress all checks during the analysis of the expanded code
700 -- to avoid the generation of spureous warnings under ZFP run-time.
702 Analyze_And_Resolve (Call_Node, Call_Typ, Suppress => All_Checks);
703 end Expand_Dispatching_Call;
705 ---------------------------------
706 -- Expand_Interface_Conversion --
707 ---------------------------------
709 procedure Expand_Interface_Conversion
711 Is_Static : Boolean := True)
713 Loc : constant Source_Ptr := Sloc (N);
714 Etyp : constant Entity_Id := Etype (N);
715 Operand : constant Node_Id := Expression (N);
716 Operand_Typ : Entity_Id := Etype (Operand);
718 Iface_Typ : Entity_Id := Etype (N);
719 Iface_Tag : Entity_Id;
722 -- Ada 2005 (AI-345): Handle synchronized interface type derivations
724 if Is_Concurrent_Type (Operand_Typ) then
725 Operand_Typ := Base_Type (Corresponding_Record_Type (Operand_Typ));
728 -- Handle access types to interfaces
730 if Is_Access_Type (Iface_Typ) then
731 Iface_Typ := Etype (Directly_Designated_Type (Iface_Typ));
734 -- Handle class-wide interface types. This conversion can appear
735 -- explicitly in the source code. Example: I'Class (Obj)
737 if Is_Class_Wide_Type (Iface_Typ) then
738 Iface_Typ := Root_Type (Iface_Typ);
741 pragma Assert (not Is_Static
742 or else (not Is_Class_Wide_Type (Iface_Typ)
743 and then Is_Interface (Iface_Typ)));
745 if VM_Target /= No_VM then
747 -- For VM, just do a conversion ???
749 Rewrite (N, Unchecked_Convert_To (Etype (N), N));
754 if not Is_Static then
756 -- Give error if configurable run time and Displace not available
758 if not RTE_Available (RE_Displace) then
759 Error_Msg_CRT ("abstract interface types", N);
763 -- Handle conversion of access-to-class-wide interface types. Target
764 -- can be an access to an object or an access to another class-wide
765 -- interface (see -1- and -2- in the following example):
767 -- type Iface1_Ref is access all Iface1'Class;
768 -- type Iface2_Ref is access all Iface1'Class;
770 -- Acc1 : Iface1_Ref := new ...
771 -- Obj : Obj_Ref := Obj_Ref (Acc); -- 1
772 -- Acc2 : Iface2_Ref := Iface2_Ref (Acc); -- 2
774 if Is_Access_Type (Operand_Typ) then
776 (Is_Interface (Directly_Designated_Type (Operand_Typ)));
779 Unchecked_Convert_To (Etype (N),
780 Make_Function_Call (Loc,
781 Name => New_Reference_To (RTE (RE_Displace), Loc),
782 Parameter_Associations => New_List (
784 Unchecked_Convert_To (RTE (RE_Address),
785 Relocate_Node (Expression (N))),
788 (Node (First_Elmt (Access_Disp_Table (Iface_Typ))),
796 Make_Function_Call (Loc,
797 Name => New_Reference_To (RTE (RE_Displace), Loc),
798 Parameter_Associations => New_List (
799 Make_Attribute_Reference (Loc,
800 Prefix => Relocate_Node (Expression (N)),
801 Attribute_Name => Name_Address),
804 (Node (First_Elmt (Access_Disp_Table (Iface_Typ))),
809 -- If the target is a class-wide interface we change the type of the
810 -- data returned by IW_Convert to indicate that this is a dispatching
814 New_Itype : Entity_Id;
817 New_Itype := Create_Itype (E_Anonymous_Access_Type, N);
818 Set_Etype (New_Itype, New_Itype);
819 Init_Esize (New_Itype);
820 Init_Size_Align (New_Itype);
821 Set_Directly_Designated_Type (New_Itype, Etyp);
824 Make_Explicit_Dereference (Loc,
826 Unchecked_Convert_To (New_Itype, Relocate_Node (N))));
828 Freeze_Itype (New_Itype, N);
834 Iface_Tag := Find_Interface_Tag (Operand_Typ, Iface_Typ);
835 pragma Assert (Iface_Tag /= Empty);
837 -- Keep separate access types to interfaces because one internal
838 -- function is used to handle the null value (see following comment)
840 if not Is_Access_Type (Etype (N)) then
842 Unchecked_Convert_To (Etype (N),
843 Make_Selected_Component (Loc,
844 Prefix => Relocate_Node (Expression (N)),
846 New_Occurrence_Of (Iface_Tag, Loc))));
849 -- Build internal function to handle the case in which the
850 -- actual is null. If the actual is null returns null because
851 -- no displacement is required; otherwise performs a type
852 -- conversion that will be expanded in the code that returns
853 -- the value of the displaced actual. That is:
855 -- function Func (O : Address) return Iface_Typ is
856 -- type Op_Typ is access all Operand_Typ;
857 -- Aux : Op_Typ := To_Op_Typ (O);
859 -- if O = Null_Address then
862 -- return Iface_Typ!(Aux.Iface_Tag'Address);
868 Desig_Typ : Entity_Id;
870 New_Typ_Decl : Node_Id;
871 New_Obj_Decl : Node_Id;
875 Desig_Typ := Etype (Expression (N));
877 if Is_Access_Type (Desig_Typ) then
878 Desig_Typ := Directly_Designated_Type (Desig_Typ);
882 Make_Full_Type_Declaration (Loc,
883 Defining_Identifier =>
884 Make_Defining_Identifier (Loc, New_Internal_Name ('T')),
886 Make_Access_To_Object_Definition (Loc,
888 Null_Exclusion_Present => False,
889 Constant_Present => False,
890 Subtype_Indication =>
891 New_Reference_To (Desig_Typ, Loc)));
894 Make_Object_Declaration (Loc,
895 Defining_Identifier =>
896 Make_Defining_Identifier (Loc,
897 New_Internal_Name ('S')),
898 Constant_Present => True,
900 New_Reference_To (Defining_Identifier (New_Typ_Decl), Loc),
902 Unchecked_Convert_To (Defining_Identifier (New_Typ_Decl),
903 Make_Identifier (Loc, Name_uO)));
910 Make_Simple_Return_Statement (Loc,
911 Unchecked_Convert_To (Etype (N),
912 Make_Attribute_Reference (Loc,
914 Make_Selected_Component (Loc,
917 (Defining_Identifier (New_Obj_Decl),
920 New_Occurrence_Of (Iface_Tag, Loc)),
921 Attribute_Name => Name_Address))));
923 -- If the type is null-excluding, no need for the null branch.
924 -- Otherwise we need to check for it and return null.
926 if not Can_Never_Be_Null (Etype (N)) then
928 Make_If_Statement (Loc,
931 Left_Opnd => Make_Identifier (Loc, Name_uO),
932 Right_Opnd => New_Reference_To
933 (RTE (RE_Null_Address), Loc)),
935 Then_Statements => New_List (
936 Make_Simple_Return_Statement (Loc,
938 Else_Statements => Stats));
942 Make_Defining_Identifier (Loc,
943 New_Internal_Name ('F'));
946 Make_Subprogram_Body (Loc,
948 Make_Function_Specification (Loc,
949 Defining_Unit_Name => Fent,
951 Parameter_Specifications => New_List (
952 Make_Parameter_Specification (Loc,
953 Defining_Identifier =>
954 Make_Defining_Identifier (Loc, Name_uO),
956 New_Reference_To (RTE (RE_Address), Loc))),
959 New_Reference_To (Etype (N), Loc)),
961 Declarations => Decls,
963 Handled_Statement_Sequence =>
964 Make_Handled_Sequence_Of_Statements (Loc, Stats));
966 -- Place function body before the expression containing the
967 -- conversion. We suppress all checks because the body of the
968 -- internally generated function already takes care of the case
969 -- in which the actual is null; therefore there is no need to
970 -- double check that the pointer is not null when the program
971 -- executes the alternative that performs the type conversion).
973 Insert_Action (N, Func, Suppress => All_Checks);
975 if Is_Access_Type (Etype (Expression (N))) then
977 -- Generate: Operand_Typ!(Expression.all)'Address
980 Make_Function_Call (Loc,
981 Name => New_Reference_To (Fent, Loc),
982 Parameter_Associations => New_List (
983 Make_Attribute_Reference (Loc,
984 Prefix => Unchecked_Convert_To (Operand_Typ,
985 Make_Explicit_Dereference (Loc,
986 Relocate_Node (Expression (N)))),
987 Attribute_Name => Name_Address))));
990 -- Generate: Operand_Typ!(Expression)'Address
993 Make_Function_Call (Loc,
994 Name => New_Reference_To (Fent, Loc),
995 Parameter_Associations => New_List (
996 Make_Attribute_Reference (Loc,
997 Prefix => Unchecked_Convert_To (Operand_Typ,
998 Relocate_Node (Expression (N))),
999 Attribute_Name => Name_Address))));
1005 end Expand_Interface_Conversion;
1007 ------------------------------
1008 -- Expand_Interface_Actuals --
1009 ------------------------------
1011 procedure Expand_Interface_Actuals (Call_Node : Node_Id) is
1012 Loc : constant Source_Ptr := Sloc (Call_Node);
1014 Actual_Dup : Node_Id;
1015 Actual_Typ : Entity_Id;
1017 Conversion : Node_Id;
1019 Formal_Typ : Entity_Id;
1022 Formal_DDT : Entity_Id;
1023 Actual_DDT : Entity_Id;
1026 -- This subprogram is called directly from the semantics, so we need a
1027 -- check to see whether expansion is active before proceeding.
1029 if not Expander_Active then
1033 -- Call using access to subprogram with explicit dereference
1035 if Nkind (Name (Call_Node)) = N_Explicit_Dereference then
1036 Subp := Etype (Name (Call_Node));
1041 Subp := Entity (Name (Call_Node));
1044 -- Ada 2005 (AI-251): Look for interface type formals to force "this"
1047 Formal := First_Formal (Subp);
1048 Actual := First_Actual (Call_Node);
1049 while Present (Formal) loop
1050 Formal_Typ := Etype (Formal);
1052 if Ekind (Formal_Typ) = E_Record_Type_With_Private then
1053 Formal_Typ := Full_View (Formal_Typ);
1056 if Is_Access_Type (Formal_Typ) then
1057 Formal_DDT := Directly_Designated_Type (Formal_Typ);
1060 Actual_Typ := Etype (Actual);
1062 if Is_Access_Type (Actual_Typ) then
1063 Actual_DDT := Directly_Designated_Type (Actual_Typ);
1066 if Is_Interface (Formal_Typ)
1067 and then Is_Class_Wide_Type (Formal_Typ)
1069 -- No need to displace the pointer if the type of the actual
1070 -- coindices with the type of the formal.
1072 if Actual_Typ = Formal_Typ then
1075 -- No need to displace the pointer if the interface type is
1076 -- a parent of the type of the actual because in this case the
1077 -- interface primitives are located in the primary dispatch table.
1079 elsif Is_Parent (Formal_Typ, Actual_Typ) then
1082 -- Implicit conversion to the class-wide formal type to force
1083 -- the displacement of the pointer.
1086 Conversion := Convert_To (Formal_Typ, Relocate_Node (Actual));
1087 Rewrite (Actual, Conversion);
1088 Analyze_And_Resolve (Actual, Formal_Typ);
1091 -- Access to class-wide interface type
1093 elsif Is_Access_Type (Formal_Typ)
1094 and then Is_Interface (Formal_DDT)
1095 and then Is_Class_Wide_Type (Formal_DDT)
1096 and then Interface_Present_In_Ancestor
1098 Iface => Etype (Formal_DDT))
1100 -- Handle attributes 'Access and 'Unchecked_Access
1102 if Nkind (Actual) = N_Attribute_Reference
1104 (Attribute_Name (Actual) = Name_Access
1105 or else Attribute_Name (Actual) = Name_Unchecked_Access)
1107 Nam := Attribute_Name (Actual);
1109 Conversion := Convert_To (Formal_DDT, Prefix (Actual));
1110 Rewrite (Actual, Conversion);
1111 Analyze_And_Resolve (Actual, Formal_DDT);
1114 Unchecked_Convert_To (Formal_Typ,
1115 Make_Attribute_Reference (Loc,
1116 Prefix => Relocate_Node (Actual),
1117 Attribute_Name => Nam)));
1118 Analyze_And_Resolve (Actual, Formal_Typ);
1120 -- No need to displace the pointer if the type of the actual
1121 -- coincides with the type of the formal.
1123 elsif Actual_DDT = Formal_DDT then
1126 -- No need to displace the pointer if the interface type is
1127 -- a parent of the type of the actual because in this case the
1128 -- interface primitives are located in the primary dispatch table.
1130 elsif Is_Parent (Formal_DDT, Actual_DDT) then
1134 Actual_Dup := Relocate_Node (Actual);
1136 if From_With_Type (Actual_Typ) then
1138 -- If the type of the actual parameter comes from a limited
1139 -- with-clause and the non-limited view is already available
1140 -- we replace the anonymous access type by a duplicate decla
1141 -- ration whose designated type is the non-limited view
1143 if Ekind (Actual_DDT) = E_Incomplete_Type
1144 and then Present (Non_Limited_View (Actual_DDT))
1146 Anon := New_Copy (Actual_Typ);
1148 if Is_Itype (Anon) then
1149 Set_Scope (Anon, Current_Scope);
1152 Set_Directly_Designated_Type (Anon,
1153 Non_Limited_View (Actual_DDT));
1154 Set_Etype (Actual_Dup, Anon);
1156 elsif Is_Class_Wide_Type (Actual_DDT)
1157 and then Ekind (Etype (Actual_DDT)) = E_Incomplete_Type
1158 and then Present (Non_Limited_View (Etype (Actual_DDT)))
1160 Anon := New_Copy (Actual_Typ);
1162 if Is_Itype (Anon) then
1163 Set_Scope (Anon, Current_Scope);
1166 Set_Directly_Designated_Type (Anon,
1167 New_Copy (Actual_DDT));
1168 Set_Class_Wide_Type (Directly_Designated_Type (Anon),
1169 New_Copy (Class_Wide_Type (Actual_DDT)));
1170 Set_Etype (Directly_Designated_Type (Anon),
1171 Non_Limited_View (Etype (Actual_DDT)));
1173 Class_Wide_Type (Directly_Designated_Type (Anon)),
1174 Non_Limited_View (Etype (Actual_DDT)));
1175 Set_Etype (Actual_Dup, Anon);
1179 Conversion := Convert_To (Formal_Typ, Actual_Dup);
1180 Rewrite (Actual, Conversion);
1181 Analyze_And_Resolve (Actual, Formal_Typ);
1185 Next_Actual (Actual);
1186 Next_Formal (Formal);
1188 end Expand_Interface_Actuals;
1190 ----------------------------
1191 -- Expand_Interface_Thunk --
1192 ----------------------------
1194 procedure Expand_Interface_Thunk
1196 Thunk_Id : out Entity_Id;
1197 Thunk_Code : out Node_Id)
1199 Loc : constant Source_Ptr := Sloc (Prim);
1200 Actuals : constant List_Id := New_List;
1201 Decl : constant List_Id := New_List;
1202 Formals : constant List_Id := New_List;
1204 Controlling_Typ : Entity_Id;
1209 Target_Formal : Entity_Id;
1213 Thunk_Code := Empty;
1215 -- Give message if configurable run-time and Offset_To_Top unavailable
1217 if not RTE_Available (RE_Offset_To_Top) then
1218 Error_Msg_CRT ("abstract interface types", Prim);
1222 -- Traverse the list of alias to find the final target
1225 while Present (Alias (Target)) loop
1226 Target := Alias (Target);
1229 -- In case of primitives that are functions without formals and
1230 -- a controlling result there is no need to build the thunk.
1232 if not Present (First_Formal (Target)) then
1233 pragma Assert (Ekind (Target) = E_Function
1234 and then Has_Controlling_Result (Target));
1238 -- Duplicate the formals
1240 Formal := First_Formal (Target);
1241 while Present (Formal) loop
1243 Make_Parameter_Specification (Loc,
1244 Defining_Identifier =>
1245 Make_Defining_Identifier (Sloc (Formal),
1246 Chars => Chars (Formal)),
1247 In_Present => In_Present (Parent (Formal)),
1248 Out_Present => Out_Present (Parent (Formal)),
1250 New_Reference_To (Etype (Formal), Loc),
1251 Expression => New_Copy_Tree (Expression (Parent (Formal)))));
1253 Next_Formal (Formal);
1256 Controlling_Typ := Find_Dispatching_Type (Target);
1258 Target_Formal := First_Formal (Target);
1259 Formal := First (Formals);
1260 while Present (Formal) loop
1261 if Ekind (Target_Formal) = E_In_Parameter
1262 and then Ekind (Etype (Target_Formal)) = E_Anonymous_Access_Type
1263 and then Directly_Designated_Type (Etype (Target_Formal))
1268 -- type T is access all <<type of the target formal>>
1269 -- S : Storage_Offset := Storage_Offset!(Formal)
1270 -- - Offset_To_Top (address!(Formal))
1273 Make_Full_Type_Declaration (Loc,
1274 Defining_Identifier =>
1275 Make_Defining_Identifier (Loc,
1276 New_Internal_Name ('T')),
1278 Make_Access_To_Object_Definition (Loc,
1279 All_Present => True,
1280 Null_Exclusion_Present => False,
1281 Constant_Present => False,
1282 Subtype_Indication =>
1284 (Directly_Designated_Type
1285 (Etype (Target_Formal)), Loc)));
1288 Make_Object_Declaration (Loc,
1289 Defining_Identifier =>
1290 Make_Defining_Identifier (Loc,
1291 New_Internal_Name ('S')),
1292 Constant_Present => True,
1293 Object_Definition =>
1294 New_Reference_To (RTE (RE_Storage_Offset), Loc),
1296 Make_Op_Subtract (Loc,
1298 Unchecked_Convert_To
1299 (RTE (RE_Storage_Offset),
1300 New_Reference_To (Defining_Identifier (Formal), Loc)),
1302 Make_Function_Call (Loc,
1304 New_Reference_To (RTE (RE_Offset_To_Top), Loc),
1305 Parameter_Associations => New_List (
1306 Unchecked_Convert_To
1309 (Defining_Identifier (Formal), Loc))))));
1311 Append_To (Decl, Decl_2);
1312 Append_To (Decl, Decl_1);
1314 -- Reference the new actual. Generate:
1318 Unchecked_Convert_To
1319 (Defining_Identifier (Decl_2),
1320 New_Reference_To (Defining_Identifier (Decl_1), Loc)));
1322 elsif Etype (Target_Formal) = Controlling_Typ then
1325 -- S1 : Storage_Offset := Storage_Offset!(Formal'Address)
1326 -- - Offset_To_Top (Formal'Address)
1327 -- S2 : Addr_Ptr := Addr_Ptr!(S1)
1330 Make_Object_Declaration (Loc,
1331 Defining_Identifier =>
1332 Make_Defining_Identifier (Loc, New_Internal_Name ('S')),
1333 Constant_Present => True,
1334 Object_Definition =>
1335 New_Reference_To (RTE (RE_Storage_Offset), Loc),
1337 Make_Op_Subtract (Loc,
1339 Unchecked_Convert_To
1340 (RTE (RE_Storage_Offset),
1341 Make_Attribute_Reference (Loc,
1344 (Defining_Identifier (Formal), Loc),
1345 Attribute_Name => Name_Address)),
1347 Make_Function_Call (Loc,
1349 New_Reference_To (RTE (RE_Offset_To_Top), Loc),
1350 Parameter_Associations => New_List (
1351 Make_Attribute_Reference (Loc,
1354 (Defining_Identifier (Formal), Loc),
1355 Attribute_Name => Name_Address)))));
1358 Make_Object_Declaration (Loc,
1359 Defining_Identifier =>
1360 Make_Defining_Identifier (Loc, New_Internal_Name ('S')),
1361 Constant_Present => True,
1362 Object_Definition => New_Reference_To (RTE (RE_Addr_Ptr), Loc),
1364 Unchecked_Convert_To
1366 New_Reference_To (Defining_Identifier (Decl_1), Loc)));
1368 Append_To (Decl, Decl_1);
1369 Append_To (Decl, Decl_2);
1371 -- Reference the new actual. Generate:
1372 -- Target_Formal (S2.all)
1375 Unchecked_Convert_To
1376 (Etype (Target_Formal),
1377 Make_Explicit_Dereference (Loc,
1378 New_Reference_To (Defining_Identifier (Decl_2), Loc))));
1380 -- No special management required for this actual
1384 New_Reference_To (Defining_Identifier (Formal), Loc));
1387 Next_Formal (Target_Formal);
1392 Make_Defining_Identifier (Loc,
1393 Chars => New_Internal_Name ('T'));
1395 if Ekind (Target) = E_Procedure then
1397 Make_Subprogram_Body (Loc,
1399 Make_Procedure_Specification (Loc,
1400 Defining_Unit_Name => Thunk_Id,
1401 Parameter_Specifications => Formals),
1402 Declarations => Decl,
1403 Handled_Statement_Sequence =>
1404 Make_Handled_Sequence_Of_Statements (Loc,
1405 Statements => New_List (
1406 Make_Procedure_Call_Statement (Loc,
1407 Name => New_Occurrence_Of (Target, Loc),
1408 Parameter_Associations => Actuals))));
1410 else pragma Assert (Ekind (Target) = E_Function);
1413 Make_Subprogram_Body (Loc,
1415 Make_Function_Specification (Loc,
1416 Defining_Unit_Name => Thunk_Id,
1417 Parameter_Specifications => Formals,
1418 Result_Definition =>
1419 New_Copy (Result_Definition (Parent (Target)))),
1420 Declarations => Decl,
1421 Handled_Statement_Sequence =>
1422 Make_Handled_Sequence_Of_Statements (Loc,
1423 Statements => New_List (
1424 Make_Simple_Return_Statement (Loc,
1425 Make_Function_Call (Loc,
1426 Name => New_Occurrence_Of (Target, Loc),
1427 Parameter_Associations => Actuals)))));
1429 end Expand_Interface_Thunk;
1431 -------------------------------------
1432 -- Is_Predefined_Dispatching_Alias --
1433 -------------------------------------
1435 function Is_Predefined_Dispatching_Alias (Prim : Entity_Id) return Boolean
1440 if not Is_Predefined_Dispatching_Operation (Prim)
1441 and then Present (Alias (Prim))
1444 while Present (Alias (E)) loop
1448 if Is_Predefined_Dispatching_Operation (E) then
1454 end Is_Predefined_Dispatching_Alias;
1456 ----------------------------------------
1457 -- Make_Disp_Asynchronous_Select_Body --
1458 ----------------------------------------
1460 function Make_Disp_Asynchronous_Select_Body
1461 (Typ : Entity_Id) return Node_Id
1463 Com_Block : Entity_Id;
1464 Conc_Typ : Entity_Id := Empty;
1465 Decls : constant List_Id := New_List;
1467 Loc : constant Source_Ptr := Sloc (Typ);
1468 Stmts : constant List_Id := New_List;
1471 pragma Assert (not Restriction_Active (No_Dispatching_Calls));
1473 -- Null body is generated for interface types
1475 if Is_Interface (Typ) then
1477 Make_Subprogram_Body (Loc,
1479 Make_Disp_Asynchronous_Select_Spec (Typ),
1482 Handled_Statement_Sequence =>
1483 Make_Handled_Sequence_Of_Statements (Loc,
1484 New_List (Make_Null_Statement (Loc))));
1487 DT_Ptr := Node (First_Elmt (Access_Disp_Table (Typ)));
1489 if Is_Concurrent_Record_Type (Typ) then
1490 Conc_Typ := Corresponding_Concurrent_Type (Typ);
1493 -- I : Integer := Get_Entry_Index (tag! (<type>VP), S);
1495 -- where I will be used to capture the entry index of the primitive
1496 -- wrapper at position S.
1499 Make_Object_Declaration (Loc,
1500 Defining_Identifier =>
1501 Make_Defining_Identifier (Loc, Name_uI),
1502 Object_Definition =>
1503 New_Reference_To (Standard_Integer, Loc),
1505 Make_Function_Call (Loc,
1506 Name => New_Reference_To (RTE (RE_Get_Entry_Index), Loc),
1507 Parameter_Associations => New_List (
1508 Unchecked_Convert_To (RTE (RE_Tag),
1509 New_Reference_To (DT_Ptr, Loc)),
1510 Make_Identifier (Loc, Name_uS)))));
1512 if Ekind (Conc_Typ) = E_Protected_Type then
1515 -- Com_Block : Communication_Block;
1518 Make_Defining_Identifier (Loc, New_Internal_Name ('B'));
1521 Make_Object_Declaration (Loc,
1522 Defining_Identifier =>
1524 Object_Definition =>
1525 New_Reference_To (RTE (RE_Communication_Block), Loc)));
1528 -- Protected_Entry_Call (
1529 -- T._object'access,
1530 -- protected_entry_index! (I),
1532 -- Asynchronous_Call,
1535 -- where T is the protected object, I is the entry index, P are
1536 -- the wrapped parameters and B is the name of the communication
1540 Make_Procedure_Call_Statement (Loc,
1542 New_Reference_To (RTE (RE_Protected_Entry_Call), Loc),
1543 Parameter_Associations =>
1546 Make_Attribute_Reference (Loc, -- T._object'access
1548 Name_Unchecked_Access,
1550 Make_Selected_Component (Loc,
1552 Make_Identifier (Loc, Name_uT),
1554 Make_Identifier (Loc, Name_uObject))),
1556 Make_Unchecked_Type_Conversion (Loc, -- entry index
1558 New_Reference_To (RTE (RE_Protected_Entry_Index), Loc),
1560 Make_Identifier (Loc, Name_uI)),
1562 Make_Identifier (Loc, Name_uP), -- parameter block
1563 New_Reference_To ( -- Asynchronous_Call
1564 RTE (RE_Asynchronous_Call), Loc),
1566 New_Reference_To (Com_Block, Loc)))); -- comm block
1569 -- B := Dummy_Communication_Bloc (Com_Block);
1572 Make_Assignment_Statement (Loc,
1574 Make_Identifier (Loc, Name_uB),
1576 Make_Unchecked_Type_Conversion (Loc,
1579 RTE (RE_Dummy_Communication_Block), Loc),
1581 New_Reference_To (Com_Block, Loc))));
1584 pragma Assert (Ekind (Conc_Typ) = E_Task_Type);
1587 -- Protected_Entry_Call (
1589 -- task_entry_index! (I),
1591 -- Conditional_Call,
1594 -- where T is the task object, I is the entry index, P are the
1595 -- wrapped parameters and F is the status flag.
1598 Make_Procedure_Call_Statement (Loc,
1600 New_Reference_To (RTE (RE_Task_Entry_Call), Loc),
1601 Parameter_Associations =>
1604 Make_Selected_Component (Loc, -- T._task_id
1606 Make_Identifier (Loc, Name_uT),
1608 Make_Identifier (Loc, Name_uTask_Id)),
1610 Make_Unchecked_Type_Conversion (Loc, -- entry index
1612 New_Reference_To (RTE (RE_Task_Entry_Index), Loc),
1614 Make_Identifier (Loc, Name_uI)),
1616 Make_Identifier (Loc, Name_uP), -- parameter block
1617 New_Reference_To ( -- Asynchronous_Call
1618 RTE (RE_Asynchronous_Call), Loc),
1619 Make_Identifier (Loc, Name_uF)))); -- status flag
1624 Make_Subprogram_Body (Loc,
1626 Make_Disp_Asynchronous_Select_Spec (Typ),
1629 Handled_Statement_Sequence =>
1630 Make_Handled_Sequence_Of_Statements (Loc, Stmts));
1631 end Make_Disp_Asynchronous_Select_Body;
1633 ----------------------------------------
1634 -- Make_Disp_Asynchronous_Select_Spec --
1635 ----------------------------------------
1637 function Make_Disp_Asynchronous_Select_Spec
1638 (Typ : Entity_Id) return Node_Id
1640 Loc : constant Source_Ptr := Sloc (Typ);
1641 Def_Id : constant Node_Id :=
1642 Make_Defining_Identifier (Loc,
1643 Name_uDisp_Asynchronous_Select);
1644 Params : constant List_Id := New_List;
1647 pragma Assert (not Restriction_Active (No_Dispatching_Calls));
1649 -- T : in out Typ; -- Object parameter
1650 -- S : Integer; -- Primitive operation slot
1651 -- P : Address; -- Wrapped parameters
1652 -- B : out Dummy_Communication_Block; -- Communication block dummy
1653 -- F : out Boolean; -- Status flag
1655 Append_List_To (Params, New_List (
1657 Make_Parameter_Specification (Loc,
1658 Defining_Identifier =>
1659 Make_Defining_Identifier (Loc, Name_uT),
1661 New_Reference_To (Typ, Loc),
1663 Out_Present => True),
1665 Make_Parameter_Specification (Loc,
1666 Defining_Identifier =>
1667 Make_Defining_Identifier (Loc, Name_uS),
1669 New_Reference_To (Standard_Integer, Loc)),
1671 Make_Parameter_Specification (Loc,
1672 Defining_Identifier =>
1673 Make_Defining_Identifier (Loc, Name_uP),
1675 New_Reference_To (RTE (RE_Address), Loc)),
1677 Make_Parameter_Specification (Loc,
1678 Defining_Identifier =>
1679 Make_Defining_Identifier (Loc, Name_uB),
1681 New_Reference_To (RTE (RE_Dummy_Communication_Block), Loc),
1682 Out_Present => True),
1684 Make_Parameter_Specification (Loc,
1685 Defining_Identifier =>
1686 Make_Defining_Identifier (Loc, Name_uF),
1688 New_Reference_To (Standard_Boolean, Loc),
1689 Out_Present => True)));
1692 Make_Procedure_Specification (Loc,
1693 Defining_Unit_Name => Def_Id,
1694 Parameter_Specifications => Params);
1695 end Make_Disp_Asynchronous_Select_Spec;
1697 ---------------------------------------
1698 -- Make_Disp_Conditional_Select_Body --
1699 ---------------------------------------
1701 function Make_Disp_Conditional_Select_Body
1702 (Typ : Entity_Id) return Node_Id
1704 Loc : constant Source_Ptr := Sloc (Typ);
1705 Blk_Nam : Entity_Id;
1706 Conc_Typ : Entity_Id := Empty;
1707 Decls : constant List_Id := New_List;
1709 Stmts : constant List_Id := New_List;
1712 pragma Assert (not Restriction_Active (No_Dispatching_Calls));
1714 -- Null body is generated for interface types
1716 if Is_Interface (Typ) then
1718 Make_Subprogram_Body (Loc,
1720 Make_Disp_Conditional_Select_Spec (Typ),
1723 Handled_Statement_Sequence =>
1724 Make_Handled_Sequence_Of_Statements (Loc,
1725 New_List (Make_Null_Statement (Loc))));
1728 DT_Ptr := Node (First_Elmt (Access_Disp_Table (Typ)));
1730 if Is_Concurrent_Record_Type (Typ) then
1731 Conc_Typ := Corresponding_Concurrent_Type (Typ);
1736 -- where I will be used to capture the entry index of the primitive
1737 -- wrapper at position S.
1740 Make_Object_Declaration (Loc,
1741 Defining_Identifier =>
1742 Make_Defining_Identifier (Loc, Name_uI),
1743 Object_Definition =>
1744 New_Reference_To (Standard_Integer, Loc)));
1747 -- C := Get_Prim_Op_Kind (tag! (<type>VP), S);
1749 -- if C = POK_Procedure
1750 -- or else C = POK_Protected_Procedure
1751 -- or else C = POK_Task_Procedure;
1757 Build_Common_Dispatching_Select_Statements (Loc, DT_Ptr, Stmts);
1760 -- Bnn : Communication_Block;
1762 -- where Bnn is the name of the communication block used in
1763 -- the call to Protected_Entry_Call.
1765 Blk_Nam := Make_Defining_Identifier (Loc, New_Internal_Name ('B'));
1768 Make_Object_Declaration (Loc,
1769 Defining_Identifier =>
1771 Object_Definition =>
1772 New_Reference_To (RTE (RE_Communication_Block), Loc)));
1775 -- I := Get_Entry_Index (tag! (<type>VP), S);
1777 -- I is the entry index and S is the dispatch table slot
1780 Make_Assignment_Statement (Loc,
1782 Make_Identifier (Loc, Name_uI),
1784 Make_Function_Call (Loc,
1785 Name => New_Reference_To (RTE (RE_Get_Entry_Index), Loc),
1786 Parameter_Associations => New_List (
1787 Unchecked_Convert_To (RTE (RE_Tag),
1788 New_Reference_To (DT_Ptr, Loc)),
1789 Make_Identifier (Loc, Name_uS)))));
1791 if Ekind (Conc_Typ) = E_Protected_Type then
1794 -- Protected_Entry_Call (
1795 -- T._object'access,
1796 -- protected_entry_index! (I),
1798 -- Conditional_Call,
1801 -- where T is the protected object, I is the entry index, P are
1802 -- the wrapped parameters and Bnn is the name of the communication
1806 Make_Procedure_Call_Statement (Loc,
1808 New_Reference_To (RTE (RE_Protected_Entry_Call), Loc),
1809 Parameter_Associations =>
1812 Make_Attribute_Reference (Loc, -- T._object'access
1814 Name_Unchecked_Access,
1816 Make_Selected_Component (Loc,
1818 Make_Identifier (Loc, Name_uT),
1820 Make_Identifier (Loc, Name_uObject))),
1822 Make_Unchecked_Type_Conversion (Loc, -- entry index
1824 New_Reference_To (RTE (RE_Protected_Entry_Index), Loc),
1826 Make_Identifier (Loc, Name_uI)),
1828 Make_Identifier (Loc, Name_uP), -- parameter block
1829 New_Reference_To ( -- Conditional_Call
1830 RTE (RE_Conditional_Call), Loc),
1831 New_Reference_To ( -- Bnn
1835 -- F := not Cancelled (Bnn);
1837 -- where F is the success flag. The status of Cancelled is negated
1838 -- in order to match the behaviour of the version for task types.
1841 Make_Assignment_Statement (Loc,
1843 Make_Identifier (Loc, Name_uF),
1847 Make_Function_Call (Loc,
1849 New_Reference_To (RTE (RE_Cancelled), Loc),
1850 Parameter_Associations =>
1852 New_Reference_To (Blk_Nam, Loc))))));
1854 pragma Assert (Ekind (Conc_Typ) = E_Task_Type);
1857 -- Protected_Entry_Call (
1859 -- task_entry_index! (I),
1861 -- Conditional_Call,
1864 -- where T is the task object, I is the entry index, P are the
1865 -- wrapped parameters and F is the status flag.
1868 Make_Procedure_Call_Statement (Loc,
1870 New_Reference_To (RTE (RE_Task_Entry_Call), Loc),
1871 Parameter_Associations =>
1874 Make_Selected_Component (Loc, -- T._task_id
1876 Make_Identifier (Loc, Name_uT),
1878 Make_Identifier (Loc, Name_uTask_Id)),
1880 Make_Unchecked_Type_Conversion (Loc, -- entry index
1882 New_Reference_To (RTE (RE_Task_Entry_Index), Loc),
1884 Make_Identifier (Loc, Name_uI)),
1886 Make_Identifier (Loc, Name_uP), -- parameter block
1887 New_Reference_To ( -- Conditional_Call
1888 RTE (RE_Conditional_Call), Loc),
1889 Make_Identifier (Loc, Name_uF)))); -- status flag
1894 Make_Subprogram_Body (Loc,
1896 Make_Disp_Conditional_Select_Spec (Typ),
1899 Handled_Statement_Sequence =>
1900 Make_Handled_Sequence_Of_Statements (Loc, Stmts));
1901 end Make_Disp_Conditional_Select_Body;
1903 ---------------------------------------
1904 -- Make_Disp_Conditional_Select_Spec --
1905 ---------------------------------------
1907 function Make_Disp_Conditional_Select_Spec
1908 (Typ : Entity_Id) return Node_Id
1910 Loc : constant Source_Ptr := Sloc (Typ);
1911 Def_Id : constant Node_Id :=
1912 Make_Defining_Identifier (Loc,
1913 Name_uDisp_Conditional_Select);
1914 Params : constant List_Id := New_List;
1917 pragma Assert (not Restriction_Active (No_Dispatching_Calls));
1919 -- T : in out Typ; -- Object parameter
1920 -- S : Integer; -- Primitive operation slot
1921 -- P : Address; -- Wrapped parameters
1922 -- C : out Prim_Op_Kind; -- Call kind
1923 -- F : out Boolean; -- Status flag
1925 Append_List_To (Params, New_List (
1927 Make_Parameter_Specification (Loc,
1928 Defining_Identifier =>
1929 Make_Defining_Identifier (Loc, Name_uT),
1931 New_Reference_To (Typ, Loc),
1933 Out_Present => True),
1935 Make_Parameter_Specification (Loc,
1936 Defining_Identifier =>
1937 Make_Defining_Identifier (Loc, Name_uS),
1939 New_Reference_To (Standard_Integer, Loc)),
1941 Make_Parameter_Specification (Loc,
1942 Defining_Identifier =>
1943 Make_Defining_Identifier (Loc, Name_uP),
1945 New_Reference_To (RTE (RE_Address), Loc)),
1947 Make_Parameter_Specification (Loc,
1948 Defining_Identifier =>
1949 Make_Defining_Identifier (Loc, Name_uC),
1951 New_Reference_To (RTE (RE_Prim_Op_Kind), Loc),
1952 Out_Present => True),
1954 Make_Parameter_Specification (Loc,
1955 Defining_Identifier =>
1956 Make_Defining_Identifier (Loc, Name_uF),
1958 New_Reference_To (Standard_Boolean, Loc),
1959 Out_Present => True)));
1962 Make_Procedure_Specification (Loc,
1963 Defining_Unit_Name => Def_Id,
1964 Parameter_Specifications => Params);
1965 end Make_Disp_Conditional_Select_Spec;
1967 -------------------------------------
1968 -- Make_Disp_Get_Prim_Op_Kind_Body --
1969 -------------------------------------
1971 function Make_Disp_Get_Prim_Op_Kind_Body
1972 (Typ : Entity_Id) return Node_Id
1974 Loc : constant Source_Ptr := Sloc (Typ);
1978 pragma Assert (not Restriction_Active (No_Dispatching_Calls));
1980 if Is_Interface (Typ) then
1982 Make_Subprogram_Body (Loc,
1984 Make_Disp_Get_Prim_Op_Kind_Spec (Typ),
1987 Handled_Statement_Sequence =>
1988 Make_Handled_Sequence_Of_Statements (Loc,
1989 New_List (Make_Null_Statement (Loc))));
1992 DT_Ptr := Node (First_Elmt (Access_Disp_Table (Typ)));
1995 -- C := get_prim_op_kind (tag! (<type>VP), S);
1997 -- where C is the out parameter capturing the call kind and S is the
1998 -- dispatch table slot number.
2001 Make_Subprogram_Body (Loc,
2003 Make_Disp_Get_Prim_Op_Kind_Spec (Typ),
2006 Handled_Statement_Sequence =>
2007 Make_Handled_Sequence_Of_Statements (Loc,
2009 Make_Assignment_Statement (Loc,
2011 Make_Identifier (Loc, Name_uC),
2013 Make_Function_Call (Loc,
2015 New_Reference_To (RTE (RE_Get_Prim_Op_Kind), Loc),
2016 Parameter_Associations => New_List (
2017 Unchecked_Convert_To (RTE (RE_Tag),
2018 New_Reference_To (DT_Ptr, Loc)),
2019 Make_Identifier (Loc, Name_uS)))))));
2020 end Make_Disp_Get_Prim_Op_Kind_Body;
2022 -------------------------------------
2023 -- Make_Disp_Get_Prim_Op_Kind_Spec --
2024 -------------------------------------
2026 function Make_Disp_Get_Prim_Op_Kind_Spec
2027 (Typ : Entity_Id) return Node_Id
2029 Loc : constant Source_Ptr := Sloc (Typ);
2030 Def_Id : constant Node_Id :=
2031 Make_Defining_Identifier (Loc,
2032 Name_uDisp_Get_Prim_Op_Kind);
2033 Params : constant List_Id := New_List;
2036 pragma Assert (not Restriction_Active (No_Dispatching_Calls));
2038 -- T : in out Typ; -- Object parameter
2039 -- S : Integer; -- Primitive operation slot
2040 -- C : out Prim_Op_Kind; -- Call kind
2042 Append_List_To (Params, New_List (
2044 Make_Parameter_Specification (Loc,
2045 Defining_Identifier =>
2046 Make_Defining_Identifier (Loc, Name_uT),
2048 New_Reference_To (Typ, Loc),
2050 Out_Present => True),
2052 Make_Parameter_Specification (Loc,
2053 Defining_Identifier =>
2054 Make_Defining_Identifier (Loc, Name_uS),
2056 New_Reference_To (Standard_Integer, Loc)),
2058 Make_Parameter_Specification (Loc,
2059 Defining_Identifier =>
2060 Make_Defining_Identifier (Loc, Name_uC),
2062 New_Reference_To (RTE (RE_Prim_Op_Kind), Loc),
2063 Out_Present => True)));
2066 Make_Procedure_Specification (Loc,
2067 Defining_Unit_Name => Def_Id,
2068 Parameter_Specifications => Params);
2069 end Make_Disp_Get_Prim_Op_Kind_Spec;
2071 --------------------------------
2072 -- Make_Disp_Get_Task_Id_Body --
2073 --------------------------------
2075 function Make_Disp_Get_Task_Id_Body
2076 (Typ : Entity_Id) return Node_Id
2078 Loc : constant Source_Ptr := Sloc (Typ);
2082 pragma Assert (not Restriction_Active (No_Dispatching_Calls));
2084 if Is_Concurrent_Record_Type (Typ)
2085 and then Ekind (Corresponding_Concurrent_Type (Typ)) = E_Task_Type
2088 -- return To_Address (_T._task_id);
2091 Make_Simple_Return_Statement (Loc,
2093 Make_Unchecked_Type_Conversion (Loc,
2095 New_Reference_To (RTE (RE_Address), Loc),
2097 Make_Selected_Component (Loc,
2099 Make_Identifier (Loc, Name_uT),
2101 Make_Identifier (Loc, Name_uTask_Id))));
2103 -- A null body is constructed for non-task types
2107 -- return Null_Address;
2110 Make_Simple_Return_Statement (Loc,
2112 New_Reference_To (RTE (RE_Null_Address), Loc));
2116 Make_Subprogram_Body (Loc,
2118 Make_Disp_Get_Task_Id_Spec (Typ),
2121 Handled_Statement_Sequence =>
2122 Make_Handled_Sequence_Of_Statements (Loc,
2124 end Make_Disp_Get_Task_Id_Body;
2126 --------------------------------
2127 -- Make_Disp_Get_Task_Id_Spec --
2128 --------------------------------
2130 function Make_Disp_Get_Task_Id_Spec
2131 (Typ : Entity_Id) return Node_Id
2133 Loc : constant Source_Ptr := Sloc (Typ);
2136 pragma Assert (not Restriction_Active (No_Dispatching_Calls));
2139 Make_Function_Specification (Loc,
2140 Defining_Unit_Name =>
2141 Make_Defining_Identifier (Loc, Name_uDisp_Get_Task_Id),
2142 Parameter_Specifications => New_List (
2143 Make_Parameter_Specification (Loc,
2144 Defining_Identifier =>
2145 Make_Defining_Identifier (Loc, Name_uT),
2147 New_Reference_To (Typ, Loc))),
2148 Result_Definition =>
2149 New_Reference_To (RTE (RE_Address), Loc));
2150 end Make_Disp_Get_Task_Id_Spec;
2152 ---------------------------------
2153 -- Make_Disp_Timed_Select_Body --
2154 ---------------------------------
2156 function Make_Disp_Timed_Select_Body
2157 (Typ : Entity_Id) return Node_Id
2159 Loc : constant Source_Ptr := Sloc (Typ);
2160 Conc_Typ : Entity_Id := Empty;
2161 Decls : constant List_Id := New_List;
2163 Stmts : constant List_Id := New_List;
2166 pragma Assert (not Restriction_Active (No_Dispatching_Calls));
2168 -- Null body is generated for interface types
2170 if Is_Interface (Typ) then
2172 Make_Subprogram_Body (Loc,
2174 Make_Disp_Timed_Select_Spec (Typ),
2177 Handled_Statement_Sequence =>
2178 Make_Handled_Sequence_Of_Statements (Loc,
2179 New_List (Make_Null_Statement (Loc))));
2182 DT_Ptr := Node (First_Elmt (Access_Disp_Table (Typ)));
2184 if Is_Concurrent_Record_Type (Typ) then
2185 Conc_Typ := Corresponding_Concurrent_Type (Typ);
2190 -- where I will be used to capture the entry index of the primitive
2191 -- wrapper at position S.
2194 Make_Object_Declaration (Loc,
2195 Defining_Identifier =>
2196 Make_Defining_Identifier (Loc, Name_uI),
2197 Object_Definition =>
2198 New_Reference_To (Standard_Integer, Loc)));
2201 -- C := Get_Prim_Op_Kind (tag! (<type>VP), S);
2203 -- if C = POK_Procedure
2204 -- or else C = POK_Protected_Procedure
2205 -- or else C = POK_Task_Procedure;
2211 Build_Common_Dispatching_Select_Statements (Loc, DT_Ptr, Stmts);
2214 -- I := Get_Entry_Index (tag! (<type>VP), S);
2216 -- I is the entry index and S is the dispatch table slot
2219 Make_Assignment_Statement (Loc,
2221 Make_Identifier (Loc, Name_uI),
2223 Make_Function_Call (Loc,
2224 Name => New_Reference_To (RTE (RE_Get_Entry_Index), Loc),
2225 Parameter_Associations => New_List (
2226 Unchecked_Convert_To (RTE (RE_Tag),
2227 New_Reference_To (DT_Ptr, Loc)),
2228 Make_Identifier (Loc, Name_uS)))));
2230 if Ekind (Conc_Typ) = E_Protected_Type then
2233 -- Timed_Protected_Entry_Call (
2234 -- T._object'access,
2235 -- protected_entry_index! (I),
2241 -- where T is the protected object, I is the entry index, P are
2242 -- the wrapped parameters, D is the delay amount, M is the delay
2243 -- mode and F is the status flag.
2246 Make_Procedure_Call_Statement (Loc,
2248 New_Reference_To (RTE (RE_Timed_Protected_Entry_Call), Loc),
2249 Parameter_Associations =>
2252 Make_Attribute_Reference (Loc, -- T._object'access
2254 Name_Unchecked_Access,
2256 Make_Selected_Component (Loc,
2258 Make_Identifier (Loc, Name_uT),
2260 Make_Identifier (Loc, Name_uObject))),
2262 Make_Unchecked_Type_Conversion (Loc, -- entry index
2264 New_Reference_To (RTE (RE_Protected_Entry_Index), Loc),
2266 Make_Identifier (Loc, Name_uI)),
2268 Make_Identifier (Loc, Name_uP), -- parameter block
2269 Make_Identifier (Loc, Name_uD), -- delay
2270 Make_Identifier (Loc, Name_uM), -- delay mode
2271 Make_Identifier (Loc, Name_uF)))); -- status flag
2274 pragma Assert (Ekind (Conc_Typ) = E_Task_Type);
2277 -- Timed_Task_Entry_Call (
2279 -- task_entry_index! (I),
2285 -- where T is the task object, I is the entry index, P are the
2286 -- wrapped parameters, D is the delay amount, M is the delay
2287 -- mode and F is the status flag.
2290 Make_Procedure_Call_Statement (Loc,
2292 New_Reference_To (RTE (RE_Timed_Task_Entry_Call), Loc),
2293 Parameter_Associations =>
2296 Make_Selected_Component (Loc, -- T._task_id
2298 Make_Identifier (Loc, Name_uT),
2300 Make_Identifier (Loc, Name_uTask_Id)),
2302 Make_Unchecked_Type_Conversion (Loc, -- entry index
2304 New_Reference_To (RTE (RE_Task_Entry_Index), Loc),
2306 Make_Identifier (Loc, Name_uI)),
2308 Make_Identifier (Loc, Name_uP), -- parameter block
2309 Make_Identifier (Loc, Name_uD), -- delay
2310 Make_Identifier (Loc, Name_uM), -- delay mode
2311 Make_Identifier (Loc, Name_uF)))); -- status flag
2316 Make_Subprogram_Body (Loc,
2318 Make_Disp_Timed_Select_Spec (Typ),
2321 Handled_Statement_Sequence =>
2322 Make_Handled_Sequence_Of_Statements (Loc, Stmts));
2323 end Make_Disp_Timed_Select_Body;
2325 ---------------------------------
2326 -- Make_Disp_Timed_Select_Spec --
2327 ---------------------------------
2329 function Make_Disp_Timed_Select_Spec
2330 (Typ : Entity_Id) return Node_Id
2332 Loc : constant Source_Ptr := Sloc (Typ);
2333 Def_Id : constant Node_Id :=
2334 Make_Defining_Identifier (Loc,
2335 Name_uDisp_Timed_Select);
2336 Params : constant List_Id := New_List;
2339 pragma Assert (not Restriction_Active (No_Dispatching_Calls));
2341 -- T : in out Typ; -- Object parameter
2342 -- S : Integer; -- Primitive operation slot
2343 -- P : Address; -- Wrapped parameters
2344 -- D : Duration; -- Delay
2345 -- M : Integer; -- Delay Mode
2346 -- C : out Prim_Op_Kind; -- Call kind
2347 -- F : out Boolean; -- Status flag
2349 Append_List_To (Params, New_List (
2351 Make_Parameter_Specification (Loc,
2352 Defining_Identifier =>
2353 Make_Defining_Identifier (Loc, Name_uT),
2355 New_Reference_To (Typ, Loc),
2357 Out_Present => True),
2359 Make_Parameter_Specification (Loc,
2360 Defining_Identifier =>
2361 Make_Defining_Identifier (Loc, Name_uS),
2363 New_Reference_To (Standard_Integer, Loc)),
2365 Make_Parameter_Specification (Loc,
2366 Defining_Identifier =>
2367 Make_Defining_Identifier (Loc, Name_uP),
2369 New_Reference_To (RTE (RE_Address), Loc)),
2371 Make_Parameter_Specification (Loc,
2372 Defining_Identifier =>
2373 Make_Defining_Identifier (Loc, Name_uD),
2375 New_Reference_To (Standard_Duration, Loc)),
2377 Make_Parameter_Specification (Loc,
2378 Defining_Identifier =>
2379 Make_Defining_Identifier (Loc, Name_uM),
2381 New_Reference_To (Standard_Integer, Loc)),
2383 Make_Parameter_Specification (Loc,
2384 Defining_Identifier =>
2385 Make_Defining_Identifier (Loc, Name_uC),
2387 New_Reference_To (RTE (RE_Prim_Op_Kind), Loc),
2388 Out_Present => True)));
2391 Make_Parameter_Specification (Loc,
2392 Defining_Identifier =>
2393 Make_Defining_Identifier (Loc, Name_uF),
2395 New_Reference_To (Standard_Boolean, Loc),
2396 Out_Present => True));
2399 Make_Procedure_Specification (Loc,
2400 Defining_Unit_Name => Def_Id,
2401 Parameter_Specifications => Params);
2402 end Make_Disp_Timed_Select_Spec;
2408 -- The frontend supports two models for expanding dispatch tables
2409 -- associated with library-level defined tagged types: statically
2410 -- and non-statically allocated dispatch tables. In the former case
2411 -- the object containing the dispatch table is constant and it is
2412 -- initialized by means of a positional aggregate. In the latter case,
2413 -- the object containing the dispatch table is a variable which is
2414 -- initialized by means of assignments.
2416 -- In case of locally defined tagged types, the object containing the
2417 -- object containing the dispatch table is always a variable (instead
2418 -- of a constant). This is currently required to give support to late
2419 -- overriding of primitives. For example:
2421 -- procedure Example is
2423 -- type T1 is tagged null record;
2424 -- procedure Prim (O : T1);
2427 -- type T2 is new Pkg.T1 with null record;
2428 -- procedure Prim (X : T2) is -- late overriding
2434 function Make_DT (Typ : Entity_Id; N : Node_Id := Empty) return List_Id is
2435 Loc : constant Source_Ptr := Sloc (Typ);
2437 Has_DT : constant Boolean :=
2438 not Is_Interface (Typ)
2439 and then not Restriction_Active (No_Dispatching_Calls);
2441 Build_Static_DT : constant Boolean :=
2442 Static_Dispatch_Tables
2443 and then Is_Library_Level_Tagged_Type (Typ);
2445 Max_Predef_Prims : constant Int :=
2449 (Parent (RTE (RE_Max_Predef_Prims)))));
2451 procedure Check_Premature_Freezing (Subp : Entity_Id; Typ : Entity_Id);
2452 -- Verify that all non-tagged types in the profile of a subprogram
2453 -- are frozen at the point the subprogram is frozen. This enforces
2454 -- the rule on RM 13.14 (14) as modified by AI05-019. At the point a
2455 -- subprogram is frozen, enough must be known about it to build the
2456 -- activation record for it, which requires at least that the size of
2457 -- all parameters be known. Controlling arguments are by-reference,
2458 -- and therefore the rule only applies to non-tagged types.
2459 -- Typical violation of the rule involves an object declaration that
2460 -- freezes a tagged type, when one of its primitive operations has a
2461 -- type in its profile whose full view has not been analyzed yet.
2463 procedure Make_Secondary_DT
2467 Iface_DT_Ptr : Entity_Id;
2469 -- Ada 2005 (AI-251): Expand the declarations for the Secondary Dispatch
2470 -- Table of Typ associated with Iface (each abstract interface of Typ
2471 -- has a secondary dispatch table). The arguments Typ, Ancestor_Typ
2472 -- and Suffix_Index are used to generate an unique external name which
2473 -- is added at the end of Acc_Disp_Tables; this external name will be
2474 -- used later by the subprogram Exp_Ch3.Build_Init_Procedure.
2476 ------------------------------
2477 -- Check_Premature_Freezing --
2478 ------------------------------
2480 procedure Check_Premature_Freezing (Subp : Entity_Id; Typ : Entity_Id) is
2483 and then Is_Private_Type (Typ)
2484 and then No (Full_View (Typ))
2485 and then not Is_Generic_Type (Typ)
2486 and then not Is_Tagged_Type (Typ)
2487 and then not Is_Frozen (Typ)
2489 Error_Msg_Sloc := Sloc (Subp);
2491 ("declaration must appear after completion of type &", N, Typ);
2493 ("\which is an untagged type in the profile of"
2494 & " primitive operation & declared#",
2497 end Check_Premature_Freezing;
2499 -----------------------
2500 -- Make_Secondary_DT --
2501 -----------------------
2503 procedure Make_Secondary_DT
2507 Iface_DT_Ptr : Entity_Id;
2510 Loc : constant Source_Ptr := Sloc (Typ);
2511 Generalized_Tag : constant Entity_Id := RTE (RE_Interface_Tag);
2512 Name_DT : constant Name_Id := New_Internal_Name ('T');
2513 Iface_DT : constant Entity_Id :=
2514 Make_Defining_Identifier (Loc, Name_DT);
2515 Name_Predef_Prims : constant Name_Id := New_Internal_Name ('R');
2516 Predef_Prims : constant Entity_Id :=
2517 Make_Defining_Identifier (Loc,
2519 DT_Constr_List : List_Id;
2520 DT_Aggr_List : List_Id;
2521 Empty_DT : Boolean := False;
2522 Nb_Predef_Prims : Nat := 0;
2526 OSD_Aggr_List : List_Id;
2529 Prim_Elmt : Elmt_Id;
2530 Prim_Ops_Aggr_List : List_Id;
2533 -- Handle cases in which we do not generate statically allocated
2536 if not Build_Static_DT then
2537 Set_Ekind (Predef_Prims, E_Variable);
2538 Set_Is_Statically_Allocated (Predef_Prims);
2540 Set_Ekind (Iface_DT, E_Variable);
2541 Set_Is_Statically_Allocated (Iface_DT);
2543 -- Statically allocated dispatch tables and related entities are
2547 Set_Ekind (Predef_Prims, E_Constant);
2548 Set_Is_Statically_Allocated (Predef_Prims);
2549 Set_Is_True_Constant (Predef_Prims);
2551 Set_Ekind (Iface_DT, E_Constant);
2552 Set_Is_Statically_Allocated (Iface_DT);
2553 Set_Is_True_Constant (Iface_DT);
2556 -- Generate code to create the storage for the Dispatch_Table object.
2557 -- If the number of primitives of Typ is 0 we reserve a dummy single
2558 -- entry for its DT because at run-time the pointer to this dummy
2559 -- entry will be used as the tag.
2561 Nb_Prim := UI_To_Int (DT_Entry_Count (AI_Tag));
2570 -- Predef_Prims : Address_Array (1 .. Default_Prim_Ops_Count) :=
2571 -- (predef-prim-op-thunk-1'address,
2572 -- predef-prim-op-thunk-2'address,
2574 -- predef-prim-op-thunk-n'address);
2575 -- for Predef_Prims'Alignment use Address'Alignment
2577 -- Stage 1: Calculate the number of predefined primitives
2579 if not Build_Static_DT then
2580 Nb_Predef_Prims := Max_Predef_Prims;
2582 Prim_Elmt := First_Elmt (Primitive_Operations (Typ));
2583 while Present (Prim_Elmt) loop
2584 Prim := Node (Prim_Elmt);
2586 if Is_Predefined_Dispatching_Operation (Prim)
2587 and then not Is_Abstract_Subprogram (Prim)
2589 Pos := UI_To_Int (DT_Position (Prim));
2591 if Pos > Nb_Predef_Prims then
2592 Nb_Predef_Prims := Pos;
2596 Next_Elmt (Prim_Elmt);
2600 -- Stage 2: Create the thunks associated with the predefined
2601 -- primitives and save their entity to fill the aggregate.
2604 Prim_Table : array (Nat range 1 .. Nb_Predef_Prims) of Entity_Id;
2605 Thunk_Id : Entity_Id;
2606 Thunk_Code : Node_Id;
2609 Prim_Ops_Aggr_List := New_List;
2610 Prim_Table := (others => Empty);
2612 Prim_Elmt := First_Elmt (Primitive_Operations (Typ));
2613 while Present (Prim_Elmt) loop
2614 Prim := Node (Prim_Elmt);
2616 if Is_Predefined_Dispatching_Operation (Prim)
2617 and then not Is_Abstract_Subprogram (Prim)
2618 and then not Present (Prim_Table
2619 (UI_To_Int (DT_Position (Prim))))
2621 while Present (Alias (Prim)) loop
2622 Prim := Alias (Prim);
2625 Expand_Interface_Thunk (Prim, Thunk_Id, Thunk_Code);
2627 if Present (Thunk_Id) then
2628 Append_To (Result, Thunk_Code);
2629 Prim_Table (UI_To_Int (DT_Position (Prim))) := Thunk_Id;
2633 Next_Elmt (Prim_Elmt);
2636 for J in Prim_Table'Range loop
2637 if Present (Prim_Table (J)) then
2639 Make_Attribute_Reference (Loc,
2640 Prefix => New_Reference_To (Prim_Table (J), Loc),
2641 Attribute_Name => Name_Address);
2644 New_Reference_To (RTE (RE_Null_Address), Loc);
2647 Append_To (Prim_Ops_Aggr_List, New_Node);
2651 Make_Object_Declaration (Loc,
2652 Defining_Identifier => Predef_Prims,
2653 Constant_Present => Build_Static_DT,
2654 Aliased_Present => True,
2655 Object_Definition =>
2656 New_Reference_To (RTE (RE_Address_Array), Loc),
2657 Expression => Make_Aggregate (Loc,
2658 Expressions => Prim_Ops_Aggr_List)));
2661 Make_Attribute_Definition_Clause (Loc,
2662 Name => New_Reference_To (Predef_Prims, Loc),
2663 Chars => Name_Alignment,
2665 Make_Attribute_Reference (Loc,
2667 New_Reference_To (RTE (RE_Integer_Address), Loc),
2668 Attribute_Name => Name_Alignment)));
2673 -- OSD : Ada.Tags.Object_Specific_Data (Nb_Prims) :=
2674 -- (OSD_Table => (1 => <value>,
2678 -- Iface_DT : Dispatch_Table (Nb_Prims) :=
2679 -- ([ Signature => <sig-value> ],
2680 -- Tag_Kind => <tag_kind-value>,
2681 -- Predef_Prims => Predef_Prims'Address,
2682 -- Offset_To_Top => 0,
2683 -- OSD => OSD'Address,
2684 -- Prims_Ptr => (prim-op-1'address,
2685 -- prim-op-2'address,
2687 -- prim-op-n'address));
2689 -- Stage 3: Initialize the discriminant and the record components
2691 DT_Constr_List := New_List;
2692 DT_Aggr_List := New_List;
2694 -- Nb_Prim. If the tagged type has no primitives we add a dummy
2695 -- slot whose address will be the tag of this type.
2698 New_Node := Make_Integer_Literal (Loc, 1);
2700 New_Node := Make_Integer_Literal (Loc, Nb_Prim);
2703 Append_To (DT_Constr_List, New_Node);
2704 Append_To (DT_Aggr_List, New_Copy (New_Node));
2708 if RTE_Record_Component_Available (RE_Signature) then
2709 Append_To (DT_Aggr_List,
2710 New_Reference_To (RTE (RE_Secondary_DT), Loc));
2715 if RTE_Record_Component_Available (RE_Tag_Kind) then
2716 Append_To (DT_Aggr_List, Tagged_Kind (Typ));
2721 Append_To (DT_Aggr_List,
2722 Make_Attribute_Reference (Loc,
2723 Prefix => New_Reference_To (Predef_Prims, Loc),
2724 Attribute_Name => Name_Address));
2726 -- Note: The correct value of Offset_To_Top will be set by the init
2729 Append_To (DT_Aggr_List, Make_Integer_Literal (Loc, 0));
2731 -- Generate the Object Specific Data table required to dispatch calls
2732 -- through synchronized interfaces.
2735 or else Is_Abstract_Type (Typ)
2736 or else Is_Controlled (Typ)
2737 or else Restriction_Active (No_Dispatching_Calls)
2738 or else not Is_Limited_Type (Typ)
2739 or else not Has_Abstract_Interfaces (Typ)
2741 -- No OSD table required
2743 Append_To (DT_Aggr_List,
2744 New_Reference_To (RTE (RE_Null_Address), Loc));
2747 OSD_Aggr_List := New_List;
2750 Prim_Table : array (Nat range 1 .. Nb_Prim) of Entity_Id;
2752 Prim_Alias : Entity_Id;
2753 Prim_Elmt : Elmt_Id;
2759 Prim_Table := (others => Empty);
2760 Prim_Alias := Empty;
2762 Prim_Elmt := First_Elmt (Primitive_Operations (Typ));
2763 while Present (Prim_Elmt) loop
2764 Prim := Node (Prim_Elmt);
2766 if Present (Abstract_Interface_Alias (Prim))
2767 and then Find_Dispatching_Type
2768 (Abstract_Interface_Alias (Prim)) = Iface
2770 Prim_Alias := Abstract_Interface_Alias (Prim);
2773 while Present (Alias (E)) loop
2777 Pos := UI_To_Int (DT_Position (Prim_Alias));
2779 if Present (Prim_Table (Pos)) then
2780 pragma Assert (Prim_Table (Pos) = E);
2784 Prim_Table (Pos) := E;
2786 Append_To (OSD_Aggr_List,
2787 Make_Component_Association (Loc,
2788 Choices => New_List (
2789 Make_Integer_Literal (Loc,
2790 DT_Position (Prim_Alias))),
2792 Make_Integer_Literal (Loc,
2793 DT_Position (Alias (Prim)))));
2799 Next_Elmt (Prim_Elmt);
2801 pragma Assert (Count = Nb_Prim);
2804 OSD := Make_Defining_Identifier (Loc, New_Internal_Name ('I'));
2807 Make_Object_Declaration (Loc,
2808 Defining_Identifier => OSD,
2809 Object_Definition =>
2810 Make_Subtype_Indication (Loc,
2812 New_Reference_To (RTE (RE_Object_Specific_Data), Loc),
2814 Make_Index_Or_Discriminant_Constraint (Loc,
2815 Constraints => New_List (
2816 Make_Integer_Literal (Loc, Nb_Prim)))),
2817 Expression => Make_Aggregate (Loc,
2818 Component_Associations => New_List (
2819 Make_Component_Association (Loc,
2820 Choices => New_List (
2822 (RTE_Record_Component (RE_OSD_Num_Prims), Loc)),
2824 Make_Integer_Literal (Loc, Nb_Prim)),
2826 Make_Component_Association (Loc,
2827 Choices => New_List (
2829 (RTE_Record_Component (RE_OSD_Table), Loc)),
2830 Expression => Make_Aggregate (Loc,
2831 Component_Associations => OSD_Aggr_List))))));
2834 Make_Attribute_Definition_Clause (Loc,
2835 Name => New_Reference_To (OSD, Loc),
2836 Chars => Name_Alignment,
2838 Make_Attribute_Reference (Loc,
2840 New_Reference_To (RTE (RE_Integer_Address), Loc),
2841 Attribute_Name => Name_Alignment)));
2843 -- In secondary dispatch tables the Typeinfo component contains
2844 -- the address of the Object Specific Data (see a-tags.ads)
2846 Append_To (DT_Aggr_List,
2847 Make_Attribute_Reference (Loc,
2848 Prefix => New_Reference_To (OSD, Loc),
2849 Attribute_Name => Name_Address));
2852 -- Initialize the table of primitive operations
2854 Prim_Ops_Aggr_List := New_List;
2857 Append_To (Prim_Ops_Aggr_List,
2858 New_Reference_To (RTE (RE_Null_Address), Loc));
2860 elsif Is_Abstract_Type (Typ)
2861 or else not Build_Static_DT
2863 for J in 1 .. Nb_Prim loop
2864 Append_To (Prim_Ops_Aggr_List,
2865 New_Reference_To (RTE (RE_Null_Address), Loc));
2870 Prim_Table : array (Nat range 1 .. Nb_Prim) of Entity_Id;
2872 Thunk_Code : Node_Id;
2873 Thunk_Id : Entity_Id;
2876 Prim_Table := (others => Empty);
2878 Prim_Elmt := First_Elmt (Primitive_Operations (Typ));
2879 while Present (Prim_Elmt) loop
2880 Prim := Node (Prim_Elmt);
2882 if not Is_Predefined_Dispatching_Operation (Prim)
2883 and then Present (Abstract_Interface_Alias (Prim))
2884 and then not Is_Abstract_Subprogram (Alias (Prim))
2885 and then not Is_Imported (Alias (Prim))
2886 and then Find_Dispatching_Type
2887 (Abstract_Interface_Alias (Prim)) = Iface
2889 -- Generate the code of the thunk only if the abstract
2890 -- interface type is not an immediate ancestor of
2891 -- Tagged_Type; otherwise the DT associated with the
2892 -- interface is the primary DT.
2894 and then not Is_Parent (Iface, Typ)
2896 Expand_Interface_Thunk (Prim, Thunk_Id, Thunk_Code);
2898 if Present (Thunk_Id) then
2901 (DT_Position (Abstract_Interface_Alias (Prim)));
2903 Prim_Table (Pos) := Thunk_Id;
2904 Append_To (Result, Thunk_Code);
2908 Next_Elmt (Prim_Elmt);
2911 for J in Prim_Table'Range loop
2912 if Present (Prim_Table (J)) then
2914 Make_Attribute_Reference (Loc,
2915 Prefix => New_Reference_To (Prim_Table (J), Loc),
2916 Attribute_Name => Name_Address);
2919 New_Reference_To (RTE (RE_Null_Address), Loc);
2922 Append_To (Prim_Ops_Aggr_List, New_Node);
2927 Append_To (DT_Aggr_List,
2928 Make_Aggregate (Loc,
2929 Expressions => Prim_Ops_Aggr_List));
2932 Make_Object_Declaration (Loc,
2933 Defining_Identifier => Iface_DT,
2934 Aliased_Present => True,
2935 Object_Definition =>
2936 Make_Subtype_Indication (Loc,
2937 Subtype_Mark => New_Reference_To
2938 (RTE (RE_Dispatch_Table_Wrapper), Loc),
2939 Constraint => Make_Index_Or_Discriminant_Constraint (Loc,
2940 Constraints => DT_Constr_List)),
2942 Expression => Make_Aggregate (Loc,
2943 Expressions => DT_Aggr_List)));
2946 Make_Attribute_Definition_Clause (Loc,
2947 Name => New_Reference_To (Iface_DT, Loc),
2948 Chars => Name_Alignment,
2950 Make_Attribute_Reference (Loc,
2952 New_Reference_To (RTE (RE_Integer_Address), Loc),
2953 Attribute_Name => Name_Alignment)));
2955 -- Generate code to create the pointer to the dispatch table
2957 -- Iface_DT_Ptr : Tag := Tag!(DT'Address);
2960 Make_Object_Declaration (Loc,
2961 Defining_Identifier => Iface_DT_Ptr,
2962 Constant_Present => True,
2963 Object_Definition =>
2964 New_Reference_To (RTE (RE_Interface_Tag), Loc),
2966 Unchecked_Convert_To (Generalized_Tag,
2967 Make_Attribute_Reference (Loc,
2969 Make_Selected_Component (Loc,
2970 Prefix => New_Reference_To (Iface_DT, Loc),
2973 (RTE_Record_Component (RE_Prims_Ptr), Loc)),
2974 Attribute_Name => Name_Address))));
2976 end Make_Secondary_DT;
2980 Elab_Code : constant List_Id := New_List;
2981 Generalized_Tag : constant Entity_Id := RTE (RE_Tag);
2982 Result : constant List_Id := New_List;
2983 Tname : constant Name_Id := Chars (Typ);
2985 AI_Tag_Comp : Elmt_Id;
2986 AI_Ptr_Elmt : Elmt_Id;
2987 DT_Constr_List : List_Id;
2988 DT_Aggr_List : List_Id;
2992 Iface_Table_Node : Node_Id;
2993 Name_ITable : Name_Id;
2994 Name_No_Reg : Name_Id;
2995 Nb_Predef_Prims : Nat := 0;
2999 Null_Parent_Tag : Boolean := False;
3000 Num_Ifaces : Nat := 0;
3004 Prim_Elmt : Elmt_Id;
3005 Prim_Ops_Aggr_List : List_Id;
3007 Typ_Comps : Elist_Id;
3008 Typ_Ifaces : Elist_Id;
3009 TSD_Aggr_List : List_Id;
3010 TSD_Tags_List : List_Id;
3012 -- The following name entries are used by Make_DT to generate a number
3013 -- of entities related to a tagged type. These entities may be generated
3014 -- in a scope other than that of the tagged type declaration, and if
3015 -- the entities for two tagged types with the same name happen to be
3016 -- generated in the same scope, we have to take care to use different
3017 -- names. This is achieved by means of a unique serial number appended
3018 -- to each generated entity name.
3020 Name_DT : constant Name_Id :=
3021 New_External_Name (Tname, 'T', Suffix_Index => -1);
3022 Name_Exname : constant Name_Id :=
3023 New_External_Name (Tname, 'E', Suffix_Index => -1);
3024 Name_Predef_Prims : constant Name_Id :=
3025 New_External_Name (Tname, 'R', Suffix_Index => -1);
3026 Name_SSD : constant Name_Id :=
3027 New_External_Name (Tname, 'S', Suffix_Index => -1);
3028 Name_TSD : constant Name_Id :=
3029 New_External_Name (Tname, 'B', Suffix_Index => -1);
3031 -- Entities built with above names
3033 DT : constant Entity_Id :=
3034 Make_Defining_Identifier (Loc, Name_DT);
3035 Exname : constant Entity_Id :=
3036 Make_Defining_Identifier (Loc, Name_Exname);
3037 Predef_Prims : constant Entity_Id :=
3038 Make_Defining_Identifier (Loc, Name_Predef_Prims);
3039 SSD : constant Entity_Id :=
3040 Make_Defining_Identifier (Loc, Name_SSD);
3041 TSD : constant Entity_Id :=
3042 Make_Defining_Identifier (Loc, Name_TSD);
3044 -- Start of processing for Make_DT
3047 pragma Assert (Is_Frozen (Typ));
3049 -- Handle cases in which there is no need to build the dispatch table
3051 if Has_Dispatch_Table (Typ)
3052 or else No (Access_Disp_Table (Typ))
3053 or else Is_CPP_Class (Typ)
3057 elsif No_Run_Time_Mode then
3058 Error_Msg_CRT ("tagged types", Typ);
3061 elsif not RTE_Available (RE_Tag) then
3063 Make_Object_Declaration (Loc,
3064 Defining_Identifier => Node (First_Elmt
3065 (Access_Disp_Table (Typ))),
3066 Object_Definition => New_Reference_To (RTE (RE_Tag), Loc),
3067 Constant_Present => True,
3069 Unchecked_Convert_To (Generalized_Tag,
3070 New_Reference_To (RTE (RE_Null_Address), Loc))));
3072 Analyze_List (Result, Suppress => All_Checks);
3073 Error_Msg_CRT ("tagged types", Typ);
3077 -- Ensure that the value of Max_Predef_Prims defined in a-tags is
3078 -- correct. Valid values are 10 under configurable runtime or 15
3079 -- with full runtime.
3081 if RTE_Available (RE_Interface_Data) then
3082 if Max_Predef_Prims /= 15 then
3083 Error_Msg_N ("run-time library configuration error", Typ);
3087 if Max_Predef_Prims /= 10 then
3088 Error_Msg_N ("run-time library configuration error", Typ);
3089 Error_Msg_CRT ("tagged types", Typ);
3094 -- Ensure that all the primitives are frozen. This is only required when
3095 -- building static dispatch tables --- the primitives must be frozen to
3096 -- be referenced (otherwise we have problems with the backend). It is
3097 -- not a requirement with nonstatic dispatch tables because in this case
3098 -- we generate now an empty dispatch table; the extra code required to
3099 -- register the primitive in the slot will be generated later --- when
3100 -- each primitive is frozen (see Freeze_Subprogram).
3103 and then not Is_CPP_Class (Typ)
3106 Save : constant Boolean := Freezing_Library_Level_Tagged_Type;
3107 Prim_Elmt : Elmt_Id;
3111 Freezing_Library_Level_Tagged_Type := True;
3112 Prim_Elmt := First_Elmt (Primitive_Operations (Typ));
3113 while Present (Prim_Elmt) loop
3114 Frnodes := Freeze_Entity (Node (Prim_Elmt), Loc);
3117 Subp : constant Entity_Id := Node (Prim_Elmt);
3121 F := First_Formal (Subp);
3122 while Present (F) loop
3123 Check_Premature_Freezing (Subp, Etype (F));
3127 Check_Premature_Freezing (Subp, Etype (Subp));
3130 if Present (Frnodes) then
3131 Append_List_To (Result, Frnodes);
3134 Next_Elmt (Prim_Elmt);
3136 Freezing_Library_Level_Tagged_Type := Save;
3140 -- In case of locally defined tagged type we declare the object
3141 -- contanining the dispatch table by means of a variable. Its
3142 -- initialization is done later by means of an assignment. This is
3143 -- required to generate its External_Tag.
3145 if not Build_Static_DT then
3146 DT_Ptr := Node (First_Elmt (Access_Disp_Table (Typ)));
3147 Set_Ekind (DT, E_Variable);
3149 -- Export the declaration of the tag previously generated and imported
3154 Make_Defining_Identifier (Loc,
3155 Chars => New_External_Name (Tname, 'C', Suffix_Index => -1));
3156 Set_Ekind (DT_Ptr, E_Constant);
3157 Set_Is_Statically_Allocated (DT_Ptr);
3158 Set_Is_True_Constant (DT_Ptr);
3160 Set_Is_Exported (DT_Ptr);
3161 Get_External_Name (Node (First_Elmt (Access_Disp_Table (Typ))), True);
3162 Set_Interface_Name (DT_Ptr,
3163 Make_String_Literal (Loc,
3164 Strval => String_From_Name_Buffer));
3166 -- Set tag as internal to ensure proper Sprint output of its implicit
3169 Set_Is_Internal (DT_Ptr);
3171 Set_Ekind (DT, E_Constant);
3172 Set_Is_True_Constant (DT);
3174 -- The tag is made public to ensure its availability to the linker
3175 -- (to handle the forward reference). This is required to handle
3176 -- tagged types defined in library level package bodies.
3178 Set_Is_Public (DT_Ptr);
3181 Set_Is_Statically_Allocated (DT);
3183 -- Ada 2005 (AI-251): Build the secondary dispatch tables
3185 if Has_Abstract_Interfaces (Typ) then
3186 Collect_Interface_Components (Typ, Typ_Comps);
3189 AI_Ptr_Elmt := Next_Elmt (First_Elmt (Access_Disp_Table (Typ)));
3191 AI_Tag_Comp := First_Elmt (Typ_Comps);
3192 while Present (AI_Tag_Comp) loop
3196 (Related_Interface (Node (AI_Tag_Comp))),
3197 AI_Tag => Node (AI_Tag_Comp),
3198 Iface_DT_Ptr => Node (AI_Ptr_Elmt),
3201 Suffix_Index := Suffix_Index + 1;
3202 Next_Elmt (AI_Ptr_Elmt);
3203 Next_Elmt (AI_Tag_Comp);
3207 -- Calculate the number of primitives of the dispatch table and the
3208 -- size of the Type_Specific_Data record.
3211 Nb_Prim := UI_To_Int (DT_Entry_Count (First_Tag_Component (Typ)));
3214 Set_Ekind (SSD, E_Constant);
3215 Set_Is_Statically_Allocated (SSD);
3216 Set_Is_True_Constant (SSD);
3218 Set_Ekind (TSD, E_Constant);
3219 Set_Is_Statically_Allocated (TSD);
3220 Set_Is_True_Constant (TSD);
3222 Set_Ekind (Exname, E_Constant);
3223 Set_Is_Statically_Allocated (Exname);
3224 Set_Is_True_Constant (Exname);
3226 -- Generate code to define the boolean that controls registration, in
3227 -- order to avoid multiple registrations for tagged types defined in
3228 -- multiple-called scopes.
3230 if not Is_Interface (Typ) then
3231 Name_No_Reg := New_External_Name (Tname, 'F', Suffix_Index => -1);
3232 No_Reg := Make_Defining_Identifier (Loc, Name_No_Reg);
3234 Set_Ekind (No_Reg, E_Variable);
3235 Set_Is_Statically_Allocated (No_Reg);
3238 Make_Object_Declaration (Loc,
3239 Defining_Identifier => No_Reg,
3240 Object_Definition => New_Reference_To (Standard_Boolean, Loc),
3241 Expression => New_Reference_To (Standard_True, Loc)));
3244 -- In case of locally defined tagged type we declare the object
3245 -- contanining the dispatch table by means of a variable. Its
3246 -- initialization is done later by means of an assignment. This is
3247 -- required to generate its External_Tag.
3249 if not Build_Static_DT then
3252 -- DT : No_Dispatch_Table_Wrapper;
3253 -- for DT'Alignment use Address'Alignment;
3254 -- DT_Ptr : Tag := !Tag (DT.NDT_Prims_Ptr'Address);
3258 Make_Object_Declaration (Loc,
3259 Defining_Identifier => DT,
3260 Aliased_Present => True,
3261 Constant_Present => False,
3262 Object_Definition =>
3264 (RTE (RE_No_Dispatch_Table_Wrapper), Loc)));
3267 Make_Attribute_Definition_Clause (Loc,
3268 Name => New_Reference_To (DT, Loc),
3269 Chars => Name_Alignment,
3271 Make_Attribute_Reference (Loc,
3273 New_Reference_To (RTE (RE_Integer_Address), Loc),
3274 Attribute_Name => Name_Alignment)));
3277 Make_Object_Declaration (Loc,
3278 Defining_Identifier => DT_Ptr,
3279 Object_Definition => New_Reference_To (RTE (RE_Tag), Loc),
3280 Constant_Present => True,
3282 Unchecked_Convert_To (Generalized_Tag,
3283 Make_Attribute_Reference (Loc,
3285 Make_Selected_Component (Loc,
3286 Prefix => New_Reference_To (DT, Loc),
3289 (RTE_Record_Component (RE_NDT_Prims_Ptr), Loc)),
3290 Attribute_Name => Name_Address))));
3293 -- DT : Dispatch_Table_Wrapper (Nb_Prim);
3294 -- for DT'Alignment use Address'Alignment;
3295 -- DT_Ptr : Tag := !Tag (DT.Prims_Ptr'Address);
3298 -- If the tagged type has no primitives we add a dummy slot
3299 -- whose address will be the tag of this type.
3303 New_List (Make_Integer_Literal (Loc, 1));
3306 New_List (Make_Integer_Literal (Loc, Nb_Prim));
3310 Make_Object_Declaration (Loc,
3311 Defining_Identifier => DT,
3312 Aliased_Present => True,
3313 Constant_Present => False,
3314 Object_Definition =>
3315 Make_Subtype_Indication (Loc,
3317 New_Reference_To (RTE (RE_Dispatch_Table_Wrapper), Loc),
3318 Constraint => Make_Index_Or_Discriminant_Constraint (Loc,
3319 Constraints => DT_Constr_List))));
3322 Make_Attribute_Definition_Clause (Loc,
3323 Name => New_Reference_To (DT, Loc),
3324 Chars => Name_Alignment,
3326 Make_Attribute_Reference (Loc,
3328 New_Reference_To (RTE (RE_Integer_Address), Loc),
3329 Attribute_Name => Name_Alignment)));
3332 Make_Object_Declaration (Loc,
3333 Defining_Identifier => DT_Ptr,
3334 Object_Definition => New_Reference_To (RTE (RE_Tag), Loc),
3335 Constant_Present => True,
3337 Unchecked_Convert_To (Generalized_Tag,
3338 Make_Attribute_Reference (Loc,
3340 Make_Selected_Component (Loc,
3341 Prefix => New_Reference_To (DT, Loc),
3344 (RTE_Record_Component (RE_Prims_Ptr), Loc)),
3345 Attribute_Name => Name_Address))));
3349 -- Generate: Exname : constant String := full_qualified_name (typ);
3350 -- The type itself may be an anonymous parent type, so use the first
3351 -- subtype to have a user-recognizable name.
3354 Make_Object_Declaration (Loc,
3355 Defining_Identifier => Exname,
3356 Constant_Present => True,
3357 Object_Definition => New_Reference_To (Standard_String, Loc),
3359 Make_String_Literal (Loc,
3360 Full_Qualified_Name (First_Subtype (Typ)))));
3362 -- Generate code to create the storage for the type specific data object
3363 -- with enough space to store the tags of the ancestors plus the tags
3364 -- of all the implemented interfaces (as described in a-tags.adb).
3366 -- TSD : Type_Specific_Data (I_Depth) :=
3367 -- (Idepth => I_Depth,
3368 -- Access_Level => Type_Access_Level (Typ),
3369 -- Expanded_Name => Cstring_Ptr!(Exname'Address))
3370 -- External_Tag => Cstring_Ptr!(Exname'Address))
3372 -- Transportable => <<boolean-value>>,
3373 -- RC_Offset => <<integer-value>>,
3374 -- [ Interfaces_Table => <<access-value>> ]
3375 -- [ SSD => SSD_Table'Address ]
3376 -- Tags_Table => (0 => null,
3379 -- for TSD'Alignment use Address'Alignment
3381 TSD_Aggr_List := New_List;
3383 -- Idepth: Count ancestors to compute the inheritance depth. For private
3384 -- extensions, always go to the full view in order to compute the real
3385 -- inheritance depth.
3388 Current_Typ : Entity_Id;
3389 Parent_Typ : Entity_Id;
3395 Parent_Typ := Etype (Current_Typ);
3397 if Is_Private_Type (Parent_Typ) then
3398 Parent_Typ := Full_View (Base_Type (Parent_Typ));
3401 exit when Parent_Typ = Current_Typ;
3403 I_Depth := I_Depth + 1;
3404 Current_Typ := Parent_Typ;
3408 Append_To (TSD_Aggr_List,
3409 Make_Integer_Literal (Loc, I_Depth));
3413 Append_To (TSD_Aggr_List,
3414 Make_Integer_Literal (Loc, Type_Access_Level (Typ)));
3418 Append_To (TSD_Aggr_List,
3419 Unchecked_Convert_To (RTE (RE_Cstring_Ptr),
3420 Make_Attribute_Reference (Loc,
3421 Prefix => New_Reference_To (Exname, Loc),
3422 Attribute_Name => Name_Address)));
3424 -- External_Tag of a local tagged type
3426 -- <typ>A : constant String :=
3427 -- "Internal tag at 16#tag-addr#: <full-name-of-typ>";
3429 -- The reason we generate this strange name is that we do not want to
3430 -- enter local tagged types in the global hash table used to compute
3431 -- the Internal_Tag attribute for two reasons:
3433 -- 1. It is hard to avoid a tasking race condition for entering the
3434 -- entry into the hash table.
3436 -- 2. It would cause a storage leak, unless we rig up considerable
3437 -- mechanism to remove the entry from the hash table on exit.
3439 -- So what we do is to generate the above external tag name, where the
3440 -- hex address is the address of the local dispatch table (i.e. exactly
3441 -- the value we want if Internal_Tag is computed from this string).
3443 -- Of course this value will only be valid if the tagged type is still
3444 -- in scope, but it clearly must be erroneous to compute the internal
3445 -- tag of a tagged type that is out of scope!
3447 -- We don't do this processing if an explicit external tag has been
3448 -- specified. That's an odd case for which we have already issued a
3449 -- warning, where we will not be able to compute the internal tag.
3451 if not Is_Library_Level_Entity (Typ)
3452 and then not Has_External_Tag_Rep_Clause (Typ)
3455 Exname : constant Entity_Id :=
3456 Make_Defining_Identifier (Loc,
3457 New_External_Name (Tname, 'A'));
3459 Full_Name : constant String_Id :=
3460 Full_Qualified_Name (First_Subtype (Typ));
3461 Str1_Id : String_Id;
3462 Str2_Id : String_Id;
3466 -- Str1 = "Internal tag at 16#";
3469 Store_String_Chars ("Internal tag at 16#");
3470 Str1_Id := End_String;
3473 -- Str2 = "#: <type-full-name>";
3476 Store_String_Chars ("#: ");
3477 Store_String_Chars (Full_Name);
3478 Str2_Id := End_String;
3481 -- Exname : constant String :=
3482 -- Str1 & Address_Image (Tag) & Str2;
3484 if RTE_Available (RE_Address_Image) then
3486 Make_Object_Declaration (Loc,
3487 Defining_Identifier => Exname,
3488 Constant_Present => True,
3489 Object_Definition => New_Reference_To
3490 (Standard_String, Loc),
3492 Make_Op_Concat (Loc,
3494 Make_String_Literal (Loc, Str1_Id),
3496 Make_Op_Concat (Loc,
3498 Make_Function_Call (Loc,
3501 (RTE (RE_Address_Image), Loc),
3502 Parameter_Associations => New_List (
3503 Unchecked_Convert_To (RTE (RE_Address),
3504 New_Reference_To (DT_Ptr, Loc)))),
3506 Make_String_Literal (Loc, Str2_Id)))));
3510 Make_Object_Declaration (Loc,
3511 Defining_Identifier => Exname,
3512 Constant_Present => True,
3513 Object_Definition => New_Reference_To
3514 (Standard_String, Loc),
3516 Make_Op_Concat (Loc,
3518 Make_String_Literal (Loc, Str1_Id),
3520 Make_String_Literal (Loc, Str2_Id))));
3524 Unchecked_Convert_To (RTE (RE_Cstring_Ptr),
3525 Make_Attribute_Reference (Loc,
3526 Prefix => New_Reference_To (Exname, Loc),
3527 Attribute_Name => Name_Address));
3530 -- External tag of a library-level tagged type: Check for a definition
3531 -- of External_Tag. The clause is considered only if it applies to this
3532 -- specific tagged type, as opposed to one of its ancestors.
3536 Def : constant Node_Id := Get_Attribute_Definition_Clause (Typ,
3537 Attribute_External_Tag);
3538 Old_Val : String_Id;
3539 New_Val : String_Id;
3543 if not Present (Def)
3544 or else Entity (Name (Def)) /= Typ
3547 Unchecked_Convert_To (RTE (RE_Cstring_Ptr),
3548 Make_Attribute_Reference (Loc,
3549 Prefix => New_Reference_To (Exname, Loc),
3550 Attribute_Name => Name_Address));
3552 Old_Val := Strval (Expr_Value_S (Expression (Def)));
3554 -- For the rep clause "for <typ>'external_tag use y" generate:
3556 -- <typ>A : constant string := y;
3558 -- <typ>A'Address is used to set the External_Tag component
3561 -- Create a new nul terminated string if it is not already
3563 if String_Length (Old_Val) > 0
3565 Get_String_Char (Old_Val, String_Length (Old_Val)) = 0
3569 Start_String (Old_Val);
3570 Store_String_Char (Get_Char_Code (ASCII.NUL));
3571 New_Val := End_String;
3574 E := Make_Defining_Identifier (Loc,
3575 New_External_Name (Chars (Typ), 'A'));
3578 Make_Object_Declaration (Loc,
3579 Defining_Identifier => E,
3580 Constant_Present => True,
3581 Object_Definition =>
3582 New_Reference_To (Standard_String, Loc),
3584 Make_String_Literal (Loc, New_Val)));
3587 Unchecked_Convert_To (RTE (RE_Cstring_Ptr),
3588 Make_Attribute_Reference (Loc,
3589 Prefix => New_Reference_To (E, Loc),
3590 Attribute_Name => Name_Address));
3595 Append_To (TSD_Aggr_List, New_Node);
3599 Append_To (TSD_Aggr_List,
3600 Unchecked_Convert_To (RTE (RE_Tag),
3601 New_Reference_To (RTE (RE_Null_Address), Loc)));
3603 -- Transportable: Set for types that can be used in remote calls
3604 -- with respect to E.4(18) legality rules.
3607 Transportable : Entity_Id;
3613 or else Is_Shared_Passive (Typ)
3615 ((Is_Remote_Types (Typ)
3616 or else Is_Remote_Call_Interface (Typ))
3617 and then Original_View_In_Visible_Part (Typ))
3618 or else not Comes_From_Source (Typ));
3620 Append_To (TSD_Aggr_List,
3621 New_Occurrence_Of (Transportable, Loc));
3624 -- RC_Offset: These are the valid values and their meaning:
3626 -- >0: For simple types with controlled components is
3627 -- type._record_controller'position
3629 -- 0: For types with no controlled components
3631 -- -1: For complex types with controlled components where the position
3632 -- of the record controller is not statically computable but there
3633 -- are controlled components at this level. The _Controller field
3634 -- is available right after the _parent.
3636 -- -2: There are no controlled components at this level. We need to
3637 -- get the position from the parent.
3640 RC_Offset_Node : Node_Id;
3643 if not Has_Controlled_Component (Typ) then
3644 RC_Offset_Node := Make_Integer_Literal (Loc, 0);
3646 elsif Etype (Typ) /= Typ
3647 and then Has_Discriminants (Etype (Typ))
3649 if Has_New_Controlled_Component (Typ) then
3650 RC_Offset_Node := Make_Integer_Literal (Loc, -1);
3652 RC_Offset_Node := Make_Integer_Literal (Loc, -2);
3656 Make_Attribute_Reference (Loc,
3658 Make_Selected_Component (Loc,
3659 Prefix => New_Reference_To (Typ, Loc),
3661 New_Reference_To (Controller_Component (Typ), Loc)),
3662 Attribute_Name => Name_Position);
3664 -- This is not proper Ada code to use the attribute 'Position
3665 -- on something else than an object but this is supported by
3666 -- the back end (see comment on the Bit_Component attribute in
3667 -- sem_attr). So we avoid semantic checking here.
3669 -- Is this documented in sinfo.ads??? it should be!
3671 Set_Analyzed (RC_Offset_Node);
3672 Set_Etype (Prefix (RC_Offset_Node), RTE (RE_Record_Controller));
3673 Set_Etype (Prefix (Prefix (RC_Offset_Node)), Typ);
3674 Set_Etype (Selector_Name (Prefix (RC_Offset_Node)),
3675 RTE (RE_Record_Controller));
3676 Set_Etype (RC_Offset_Node, RTE (RE_Storage_Offset));
3679 Append_To (TSD_Aggr_List, RC_Offset_Node);
3682 -- Interfaces_Table (required for AI-405)
3684 if RTE_Record_Component_Available (RE_Interfaces_Table) then
3686 -- Count the number of interface types implemented by Typ
3688 Collect_Abstract_Interfaces (Typ, Typ_Ifaces);
3690 AI := First_Elmt (Typ_Ifaces);
3691 while Present (AI) loop
3692 Num_Ifaces := Num_Ifaces + 1;
3696 if Num_Ifaces = 0 then
3697 Iface_Table_Node := Make_Null (Loc);
3699 -- Generate the Interface_Table object
3703 TSD_Ifaces_List : constant List_Id := New_List;
3706 AI := First_Elmt (Typ_Ifaces);
3707 while Present (AI) loop
3708 Append_To (TSD_Ifaces_List,
3709 Make_Aggregate (Loc,
3710 Expressions => New_List (
3714 Unchecked_Convert_To (Generalized_Tag,
3716 (Node (First_Elmt (Access_Disp_Table (Node (AI)))),
3719 -- Static_Offset_To_Top
3721 New_Reference_To (Standard_True, Loc),
3723 -- Offset_To_Top_Value
3725 Make_Integer_Literal (Loc, 0),
3727 -- Offset_To_Top_Func
3734 Name_ITable := New_External_Name (Tname, 'I');
3735 ITable := Make_Defining_Identifier (Loc, Name_ITable);
3736 Set_Is_Statically_Allocated (ITable);
3738 -- The table of interfaces is not constant; its slots are
3739 -- filled at run-time by the IP routine using attribute
3740 -- 'Position to know the location of the tag components
3741 -- (and this attribute cannot be safely used before the
3742 -- object is initialized).
3745 Make_Object_Declaration (Loc,
3746 Defining_Identifier => ITable,
3747 Aliased_Present => True,
3748 Constant_Present => False,
3749 Object_Definition =>
3750 Make_Subtype_Indication (Loc,
3752 New_Reference_To (RTE (RE_Interface_Data), Loc),
3753 Constraint => Make_Index_Or_Discriminant_Constraint
3755 Constraints => New_List (
3756 Make_Integer_Literal (Loc, Num_Ifaces)))),
3758 Expression => Make_Aggregate (Loc,
3759 Expressions => New_List (
3760 Make_Integer_Literal (Loc, Num_Ifaces),
3761 Make_Aggregate (Loc,
3762 Expressions => TSD_Ifaces_List)))));
3765 Make_Attribute_Definition_Clause (Loc,
3766 Name => New_Reference_To (ITable, Loc),
3767 Chars => Name_Alignment,
3769 Make_Attribute_Reference (Loc,
3771 New_Reference_To (RTE (RE_Integer_Address), Loc),
3772 Attribute_Name => Name_Alignment)));
3775 Make_Attribute_Reference (Loc,
3776 Prefix => New_Reference_To (ITable, Loc),
3777 Attribute_Name => Name_Unchecked_Access);
3781 Append_To (TSD_Aggr_List, Iface_Table_Node);
3784 -- Generate the Select Specific Data table for synchronized types that
3785 -- implement synchronized interfaces. The size of the table is
3786 -- constrained by the number of non-predefined primitive operations.
3788 if RTE_Record_Component_Available (RE_SSD) then
3789 if Ada_Version >= Ada_05
3791 and then Is_Concurrent_Record_Type (Typ)
3792 and then Has_Abstract_Interfaces (Typ)
3793 and then Nb_Prim > 0
3794 and then not Is_Abstract_Type (Typ)
3795 and then not Is_Controlled (Typ)
3796 and then not Restriction_Active (No_Dispatching_Calls)
3799 Make_Object_Declaration (Loc,
3800 Defining_Identifier => SSD,
3801 Aliased_Present => True,
3802 Object_Definition =>
3803 Make_Subtype_Indication (Loc,
3804 Subtype_Mark => New_Reference_To (
3805 RTE (RE_Select_Specific_Data), Loc),
3807 Make_Index_Or_Discriminant_Constraint (Loc,
3808 Constraints => New_List (
3809 Make_Integer_Literal (Loc, Nb_Prim))))));
3812 Make_Attribute_Definition_Clause (Loc,
3813 Name => New_Reference_To (SSD, Loc),
3814 Chars => Name_Alignment,
3816 Make_Attribute_Reference (Loc,
3818 New_Reference_To (RTE (RE_Integer_Address), Loc),
3819 Attribute_Name => Name_Alignment)));
3821 -- This table is initialized by Make_Select_Specific_Data_Table,
3822 -- which calls Set_Entry_Index and Set_Prim_Op_Kind.
3824 Append_To (TSD_Aggr_List,
3825 Make_Attribute_Reference (Loc,
3826 Prefix => New_Reference_To (SSD, Loc),
3827 Attribute_Name => Name_Unchecked_Access));
3829 Append_To (TSD_Aggr_List, Make_Null (Loc));
3833 -- Initialize the table of ancestor tags. In case of interface types
3834 -- this table is not needed.
3837 Current_Typ : Entity_Id;
3838 Parent_Typ : Entity_Id;
3842 TSD_Tags_List := New_List;
3844 -- If we are not statically allocating the dispatch table then we
3845 -- must fill position 0 with null because we still have not
3846 -- generated the tag of Typ.
3848 if not Build_Static_DT
3849 or else Is_Interface (Typ)
3851 Append_To (TSD_Tags_List,
3852 Unchecked_Convert_To (RTE (RE_Tag),
3853 New_Reference_To (RTE (RE_Null_Address), Loc)));
3855 -- Otherwise we can safely import the tag. The name must be unique
3856 -- over the compilation unit, to avoid conflicts when types of the
3857 -- same name appear in different nested packages. We don't need to
3858 -- use an external name because this name is only locally used.
3862 Imported_DT_Ptr : constant Entity_Id :=
3863 Make_Defining_Identifier (Loc,
3864 Chars => New_Internal_Name ('D'));
3867 Set_Is_Imported (Imported_DT_Ptr);
3868 Set_Is_Statically_Allocated (Imported_DT_Ptr);
3869 Set_Is_True_Constant (Imported_DT_Ptr);
3871 (Node (First_Elmt (Access_Disp_Table (Typ))), True);
3872 Set_Interface_Name (Imported_DT_Ptr,
3873 Make_String_Literal (Loc, String_From_Name_Buffer));
3875 -- Set tag as internal to ensure proper Sprint output of its
3876 -- implicit importation.
3878 Set_Is_Internal (Imported_DT_Ptr);
3881 Make_Object_Declaration (Loc,
3882 Defining_Identifier => Imported_DT_Ptr,
3883 Constant_Present => True,
3884 Object_Definition => New_Reference_To (RTE (RE_Tag),
3887 Append_To (TSD_Tags_List,
3888 New_Reference_To (Imported_DT_Ptr, Loc));
3892 -- Fill the rest of the table with the tags of the ancestors
3898 Parent_Typ := Etype (Current_Typ);
3900 if Is_Private_Type (Parent_Typ) then
3901 Parent_Typ := Full_View (Base_Type (Parent_Typ));
3904 exit when Parent_Typ = Current_Typ;
3906 if Is_CPP_Class (Parent_Typ)
3907 or else Is_Interface (Typ)
3909 -- The tags defined in the C++ side will be inherited when
3910 -- the object is constructed (Exp_Ch3.Build_Init_Procedure)
3912 Append_To (TSD_Tags_List,
3913 Unchecked_Convert_To (RTE (RE_Tag),
3914 New_Reference_To (RTE (RE_Null_Address), Loc)));
3916 Append_To (TSD_Tags_List,
3918 (Node (First_Elmt (Access_Disp_Table (Parent_Typ))),
3923 Current_Typ := Parent_Typ;
3926 pragma Assert (Pos = I_Depth + 1);
3929 Append_To (TSD_Aggr_List,
3930 Make_Aggregate (Loc,
3931 Expressions => TSD_Tags_List));
3933 -- Build the TSD object
3936 Make_Object_Declaration (Loc,
3937 Defining_Identifier => TSD,
3938 Aliased_Present => True,
3939 Constant_Present => Build_Static_DT,
3940 Object_Definition =>
3941 Make_Subtype_Indication (Loc,
3942 Subtype_Mark => New_Reference_To (
3943 RTE (RE_Type_Specific_Data), Loc),
3945 Make_Index_Or_Discriminant_Constraint (Loc,
3946 Constraints => New_List (
3947 Make_Integer_Literal (Loc, I_Depth)))),
3949 Expression => Make_Aggregate (Loc,
3950 Expressions => TSD_Aggr_List)));
3953 Make_Attribute_Definition_Clause (Loc,
3954 Name => New_Reference_To (TSD, Loc),
3955 Chars => Name_Alignment,
3957 Make_Attribute_Reference (Loc,
3958 Prefix => New_Reference_To (RTE (RE_Integer_Address), Loc),
3959 Attribute_Name => Name_Alignment)));
3961 -- Generate the dummy Dispatch_Table object associated with tagged
3962 -- types that have no dispatch table.
3964 -- DT : No_Dispatch_Table :=
3965 -- (NDT_TSD => TSD'Address;
3966 -- NDT_Prims_Ptr => 0);
3967 -- for DT'Alignment use Address'Alignment
3970 DT_Constr_List := New_List;
3971 DT_Aggr_List := New_List;
3976 Make_Attribute_Reference (Loc,
3977 Prefix => New_Reference_To (TSD, Loc),
3978 Attribute_Name => Name_Address);
3980 Append_To (DT_Constr_List, New_Node);
3981 Append_To (DT_Aggr_List, New_Copy (New_Node));
3982 Append_To (DT_Aggr_List, Make_Integer_Literal (Loc, 0));
3984 -- In case of locally defined tagged types we have already declared
3985 -- and uninitialized object for the dispatch table, which is now
3986 -- initialized by means of an assignment.
3988 if not Build_Static_DT then
3990 Make_Assignment_Statement (Loc,
3991 Name => New_Reference_To (DT, Loc),
3992 Expression => Make_Aggregate (Loc,
3993 Expressions => DT_Aggr_List)));
3995 -- In case of library level tagged types we declare now the constant
3996 -- object containing the dispatch table.
4000 Make_Object_Declaration (Loc,
4001 Defining_Identifier => DT,
4002 Aliased_Present => True,
4003 Constant_Present => True,
4004 Object_Definition =>
4005 New_Reference_To (RTE (RE_No_Dispatch_Table_Wrapper), Loc),
4006 Expression => Make_Aggregate (Loc,
4007 Expressions => DT_Aggr_List)));
4010 Make_Attribute_Definition_Clause (Loc,
4011 Name => New_Reference_To (DT, Loc),
4012 Chars => Name_Alignment,
4014 Make_Attribute_Reference (Loc,
4016 New_Reference_To (RTE (RE_Integer_Address), Loc),
4017 Attribute_Name => Name_Alignment)));
4020 Make_Object_Declaration (Loc,
4021 Defining_Identifier => DT_Ptr,
4022 Object_Definition => New_Reference_To (RTE (RE_Tag), Loc),
4023 Constant_Present => True,
4025 Unchecked_Convert_To (Generalized_Tag,
4026 Make_Attribute_Reference (Loc,
4028 Make_Selected_Component (Loc,
4029 Prefix => New_Reference_To (DT, Loc),
4032 (RTE_Record_Component (RE_NDT_Prims_Ptr), Loc)),
4033 Attribute_Name => Name_Address))));
4036 -- Common case: Typ has a dispatch table
4040 -- Predef_Prims : Address_Array (1 .. Default_Prim_Ops_Count) :=
4041 -- (predef-prim-op-1'address,
4042 -- predef-prim-op-2'address,
4044 -- predef-prim-op-n'address);
4045 -- for Predef_Prims'Alignment use Address'Alignment
4047 -- DT : Dispatch_Table (Nb_Prims) :=
4048 -- (Signature => <sig-value>,
4049 -- Tag_Kind => <tag_kind-value>,
4050 -- Predef_Prims => Predef_Prims'First'Address,
4051 -- Offset_To_Top => 0,
4052 -- TSD => TSD'Address;
4053 -- Prims_Ptr => (prim-op-1'address,
4054 -- prim-op-2'address,
4056 -- prim-op-n'address));
4057 -- for DT'Alignment use Address'Alignment
4064 if not Build_Static_DT then
4065 Nb_Predef_Prims := Max_Predef_Prims;
4068 Prim_Elmt := First_Elmt (Primitive_Operations (Typ));
4069 while Present (Prim_Elmt) loop
4070 Prim := Node (Prim_Elmt);
4072 if Is_Predefined_Dispatching_Operation (Prim)
4073 and then not Is_Abstract_Subprogram (Prim)
4075 Pos := UI_To_Int (DT_Position (Prim));
4077 if Pos > Nb_Predef_Prims then
4078 Nb_Predef_Prims := Pos;
4082 Next_Elmt (Prim_Elmt);
4088 (Nat range 1 .. Nb_Predef_Prims) of Entity_Id;
4092 Prim_Ops_Aggr_List := New_List;
4094 Prim_Table := (others => Empty);
4096 Prim_Elmt := First_Elmt (Primitive_Operations (Typ));
4097 while Present (Prim_Elmt) loop
4098 Prim := Node (Prim_Elmt);
4101 and then Is_Predefined_Dispatching_Operation (Prim)
4102 and then not Is_Abstract_Subprogram (Prim)
4103 and then not Present (Prim_Table
4104 (UI_To_Int (DT_Position (Prim))))
4107 while Present (Alias (E)) loop
4111 pragma Assert (not Is_Abstract_Subprogram (E));
4112 Prim_Table (UI_To_Int (DT_Position (Prim))) := E;
4115 Next_Elmt (Prim_Elmt);
4118 for J in Prim_Table'Range loop
4119 if Present (Prim_Table (J)) then
4121 Make_Attribute_Reference (Loc,
4122 Prefix => New_Reference_To (Prim_Table (J), Loc),
4123 Attribute_Name => Name_Address);
4125 New_Node := New_Reference_To (RTE (RE_Null_Address), Loc);
4128 Append_To (Prim_Ops_Aggr_List, New_Node);
4132 Make_Object_Declaration (Loc,
4133 Defining_Identifier => Predef_Prims,
4134 Aliased_Present => True,
4135 Constant_Present => Build_Static_DT,
4136 Object_Definition =>
4137 New_Reference_To (RTE (RE_Address_Array), Loc),
4138 Expression => Make_Aggregate (Loc,
4139 Expressions => Prim_Ops_Aggr_List)));
4142 Make_Attribute_Definition_Clause (Loc,
4143 Name => New_Reference_To (Predef_Prims, Loc),
4144 Chars => Name_Alignment,
4146 Make_Attribute_Reference (Loc,
4148 New_Reference_To (RTE (RE_Integer_Address), Loc),
4149 Attribute_Name => Name_Alignment)));
4153 -- Stage 1: Initialize the discriminant and the record components
4155 DT_Constr_List := New_List;
4156 DT_Aggr_List := New_List;
4158 -- Num_Prims. If the tagged type has no primitives we add a dummy
4159 -- slot whose address will be the tag of this type.
4162 New_Node := Make_Integer_Literal (Loc, 1);
4164 New_Node := Make_Integer_Literal (Loc, Nb_Prim);
4167 Append_To (DT_Constr_List, New_Node);
4168 Append_To (DT_Aggr_List, New_Copy (New_Node));
4172 if RTE_Record_Component_Available (RE_Signature) then
4173 Append_To (DT_Aggr_List,
4174 New_Reference_To (RTE (RE_Primary_DT), Loc));
4179 if RTE_Record_Component_Available (RE_Tag_Kind) then
4180 Append_To (DT_Aggr_List, Tagged_Kind (Typ));
4185 Append_To (DT_Aggr_List,
4186 Make_Attribute_Reference (Loc,
4187 Prefix => New_Reference_To (Predef_Prims, Loc),
4188 Attribute_Name => Name_Address));
4192 if RTE_Record_Component_Available (RE_Offset_To_Top) then
4193 Append_To (DT_Aggr_List, Make_Integer_Literal (Loc, 0));
4198 Append_To (DT_Aggr_List,
4199 Make_Attribute_Reference (Loc,
4200 Prefix => New_Reference_To (TSD, Loc),
4201 Attribute_Name => Name_Address));
4203 -- Stage 2: Initialize the table of primitive operations
4205 Prim_Ops_Aggr_List := New_List;
4208 Append_To (Prim_Ops_Aggr_List,
4209 New_Reference_To (RTE (RE_Null_Address), Loc));
4211 elsif not Build_Static_DT then
4212 for J in 1 .. Nb_Prim loop
4213 Append_To (Prim_Ops_Aggr_List,
4214 New_Reference_To (RTE (RE_Null_Address), Loc));
4219 Prim_Table : array (Nat range 1 .. Nb_Prim) of Entity_Id;
4222 Prim_Elmt : Elmt_Id;
4225 Prim_Table := (others => Empty);
4226 Prim_Elmt := First_Elmt (Primitive_Operations (Typ));
4227 while Present (Prim_Elmt) loop
4228 Prim := Node (Prim_Elmt);
4230 if Is_Imported (Prim)
4231 or else Present (Abstract_Interface_Alias (Prim))
4232 or else Is_Predefined_Dispatching_Operation (Prim)
4237 -- Traverse the list of aliased entities to handle
4238 -- renamings of predefined primitives.
4241 while Present (Alias (E)) loop
4245 if not Is_Predefined_Dispatching_Operation (E)
4246 and then not Is_Abstract_Subprogram (E)
4247 and then not Present (Abstract_Interface_Alias (E))
4250 (UI_To_Int (DT_Position (Prim)) <= Nb_Prim);
4252 Prim_Table (UI_To_Int (DT_Position (Prim))) := E;
4256 Next_Elmt (Prim_Elmt);
4259 for J in Prim_Table'Range loop
4260 if Present (Prim_Table (J)) then
4262 Make_Attribute_Reference (Loc,
4263 Prefix => New_Reference_To (Prim_Table (J), Loc),
4264 Attribute_Name => Name_Address);
4266 New_Node := New_Reference_To (RTE (RE_Null_Address), Loc);
4269 Append_To (Prim_Ops_Aggr_List, New_Node);
4274 Append_To (DT_Aggr_List,
4275 Make_Aggregate (Loc,
4276 Expressions => Prim_Ops_Aggr_List));
4278 -- In case of locally defined tagged types we have already declared
4279 -- and uninitialized object for the dispatch table, which is now
4280 -- initialized by means of an assignment.
4282 if not Build_Static_DT then
4284 Make_Assignment_Statement (Loc,
4285 Name => New_Reference_To (DT, Loc),
4286 Expression => Make_Aggregate (Loc,
4287 Expressions => DT_Aggr_List)));
4289 -- In case of library level tagged types we declare now the constant
4290 -- object containing the dispatch table.
4294 Make_Object_Declaration (Loc,
4295 Defining_Identifier => DT,
4296 Aliased_Present => True,
4297 Constant_Present => True,
4298 Object_Definition =>
4299 Make_Subtype_Indication (Loc,
4300 Subtype_Mark => New_Reference_To
4301 (RTE (RE_Dispatch_Table_Wrapper), Loc),
4302 Constraint => Make_Index_Or_Discriminant_Constraint (Loc,
4303 Constraints => DT_Constr_List)),
4304 Expression => Make_Aggregate (Loc,
4305 Expressions => DT_Aggr_List)));
4308 Make_Attribute_Definition_Clause (Loc,
4309 Name => New_Reference_To (DT, Loc),
4310 Chars => Name_Alignment,
4312 Make_Attribute_Reference (Loc,
4314 New_Reference_To (RTE (RE_Integer_Address), Loc),
4315 Attribute_Name => Name_Alignment)));
4318 Make_Object_Declaration (Loc,
4319 Defining_Identifier => DT_Ptr,
4320 Object_Definition => New_Reference_To (RTE (RE_Tag), Loc),
4321 Constant_Present => True,
4323 Unchecked_Convert_To (Generalized_Tag,
4324 Make_Attribute_Reference (Loc,
4326 Make_Selected_Component (Loc,
4327 Prefix => New_Reference_To (DT, Loc),
4330 (RTE_Record_Component (RE_Prims_Ptr), Loc)),
4331 Attribute_Name => Name_Address))));
4335 -- Initialize the table of ancestor tags
4337 if not Build_Static_DT
4338 and then not Is_Interface (Typ)
4339 and then not Is_CPP_Class (Typ)
4342 Make_Assignment_Statement (Loc,
4344 Make_Indexed_Component (Loc,
4346 Make_Selected_Component (Loc,
4348 New_Reference_To (TSD, Loc),
4351 (RTE_Record_Component (RE_Tags_Table), Loc)),
4353 New_List (Make_Integer_Literal (Loc, 0))),
4357 (Node (First_Elmt (Access_Disp_Table (Typ))), Loc)));
4360 if Build_Static_DT then
4363 -- If the ancestor is a CPP_Class type we inherit the dispatch tables
4364 -- in the init proc, and we don't need to fill them in here.
4366 elsif Is_CPP_Class (Etype (Typ)) then
4369 -- Otherwise we fill in the dispatch tables here
4372 if Typ = Etype (Typ)
4373 or else Is_CPP_Class (Etype (Typ))
4374 or else Is_Interface (Typ)
4376 Null_Parent_Tag := True;
4379 Unchecked_Convert_To (Generalized_Tag,
4380 Make_Integer_Literal (Loc, 0));
4382 Unchecked_Convert_To (Generalized_Tag,
4383 Make_Integer_Literal (Loc, 0));
4388 (Node (First_Elmt (Access_Disp_Table (Etype (Typ)))), Loc);
4391 (Node (First_Elmt (Access_Disp_Table (Etype (Typ)))), Loc);
4394 if Typ /= Etype (Typ)
4395 and then not Is_Interface (Typ)
4396 and then not Restriction_Active (No_Dispatching_Calls)
4398 -- Inherit the dispatch table
4400 if not Is_Interface (Etype (Typ)) then
4401 if not Null_Parent_Tag then
4403 Nb_Prims : constant Int :=
4404 UI_To_Int (DT_Entry_Count
4405 (First_Tag_Component (Etype (Typ))));
4407 Append_To (Elab_Code,
4408 Build_Inherit_Predefined_Prims (Loc,
4409 Old_Tag_Node => Old_Tag1,
4411 New_Reference_To (DT_Ptr, Loc)));
4413 if Nb_Prims /= 0 then
4414 Append_To (Elab_Code,
4415 Build_Inherit_Prims (Loc,
4417 Old_Tag_Node => Old_Tag2,
4418 New_Tag_Node => New_Reference_To (DT_Ptr, Loc),
4419 Num_Prims => Nb_Prims));
4425 -- Inherit the secondary dispatch tables of the ancestor
4427 if not Is_CPP_Class (Etype (Typ)) then
4429 Sec_DT_Ancestor : Elmt_Id :=
4432 (Access_Disp_Table (Etype (Typ))));
4433 Sec_DT_Typ : Elmt_Id :=
4436 (Access_Disp_Table (Typ)));
4438 procedure Copy_Secondary_DTs (Typ : Entity_Id);
4439 -- Local procedure required to climb through the ancestors
4440 -- and copy the contents of all their secondary dispatch
4443 ------------------------
4444 -- Copy_Secondary_DTs --
4445 ------------------------
4447 procedure Copy_Secondary_DTs (Typ : Entity_Id) is
4452 -- Climb to the ancestor (if any) handling private types
4454 if Present (Full_View (Etype (Typ))) then
4455 if Full_View (Etype (Typ)) /= Typ then
4456 Copy_Secondary_DTs (Full_View (Etype (Typ)));
4459 elsif Etype (Typ) /= Typ then
4460 Copy_Secondary_DTs (Etype (Typ));
4463 if Present (Abstract_Interfaces (Typ))
4464 and then not Is_Empty_Elmt_List
4465 (Abstract_Interfaces (Typ))
4467 Iface := First_Elmt (Abstract_Interfaces (Typ));
4468 E := First_Entity (Typ);
4470 and then Present (Node (Sec_DT_Ancestor))
4471 and then Ekind (Node (Sec_DT_Ancestor)) = E_Constant
4473 if Is_Tag (E) and then Chars (E) /= Name_uTag then
4474 if not Is_Interface (Etype (Typ)) then
4476 -- Inherit the dispatch table
4479 Num_Prims : constant Int :=
4480 UI_To_Int (DT_Entry_Count (E));
4482 Append_To (Elab_Code,
4483 Build_Inherit_Predefined_Prims (Loc,
4485 Unchecked_Convert_To (RTE (RE_Tag),
4487 (Node (Sec_DT_Ancestor), Loc)),
4489 Unchecked_Convert_To (RTE (RE_Tag),
4491 (Node (Sec_DT_Typ), Loc))));
4493 if Num_Prims /= 0 then
4494 Append_To (Elab_Code,
4495 Build_Inherit_Prims (Loc,
4496 Typ => Node (Iface),
4498 Unchecked_Convert_To
4501 (Node (Sec_DT_Ancestor),
4504 Unchecked_Convert_To
4507 (Node (Sec_DT_Typ), Loc)),
4508 Num_Prims => Num_Prims));
4513 Next_Elmt (Sec_DT_Ancestor);
4514 Next_Elmt (Sec_DT_Typ);
4521 end Copy_Secondary_DTs;
4524 if Present (Node (Sec_DT_Ancestor))
4525 and then Ekind (Node (Sec_DT_Ancestor)) = E_Constant
4527 -- Handle private types
4529 if Present (Full_View (Typ)) then
4530 Copy_Secondary_DTs (Full_View (Typ));
4532 Copy_Secondary_DTs (Typ);
4540 -- Generate code to register the Tag in the External_Tag hash table for
4541 -- the pure Ada type only.
4543 -- Register_Tag (Dt_Ptr);
4545 -- Skip this action in the following cases:
4546 -- 1) if Register_Tag is not available.
4547 -- 2) in No_Run_Time mode.
4548 -- 3) if Typ is an abstract interface type (the secondary tags will
4549 -- be registered later in types implementing this interface type).
4550 -- 4) if Typ is not defined at the library level (this is required
4551 -- to avoid adding concurrency control to the hash table used
4552 -- by the run-time to register the tags).
4557 -- [ Register_Tag (Dt_Ptr); ]
4561 if not Is_Interface (Typ) then
4562 if not No_Run_Time_Mode
4563 and then Is_Library_Level_Entity (Typ)
4564 and then RTE_Available (RE_Register_Tag)
4566 Append_To (Elab_Code,
4567 Make_Procedure_Call_Statement (Loc,
4568 Name => New_Reference_To (RTE (RE_Register_Tag), Loc),
4569 Parameter_Associations =>
4570 New_List (New_Reference_To (DT_Ptr, Loc))));
4573 Append_To (Elab_Code,
4574 Make_Assignment_Statement (Loc,
4575 Name => New_Reference_To (No_Reg, Loc),
4576 Expression => New_Reference_To (Standard_False, Loc)));
4579 Make_Implicit_If_Statement (Typ,
4580 Condition => New_Reference_To (No_Reg, Loc),
4581 Then_Statements => Elab_Code));
4584 -- Populate the two auxiliary tables used for dispatching
4585 -- asynchronous, conditional and timed selects for synchronized
4586 -- types that implement a limited interface.
4588 if Ada_Version >= Ada_05
4589 and then Is_Concurrent_Record_Type (Typ)
4590 and then Has_Abstract_Interfaces (Typ)
4592 Append_List_To (Result,
4593 Make_Select_Specific_Data_Table (Typ));
4596 Analyze_List (Result, Suppress => All_Checks);
4597 Set_Has_Dispatch_Table (Typ);
4602 -------------------------------------
4603 -- Make_Select_Specific_Data_Table --
4604 -------------------------------------
4606 function Make_Select_Specific_Data_Table
4607 (Typ : Entity_Id) return List_Id
4609 Assignments : constant List_Id := New_List;
4610 Loc : constant Source_Ptr := Sloc (Typ);
4612 Conc_Typ : Entity_Id;
4616 Prim_Als : Entity_Id;
4617 Prim_Elmt : Elmt_Id;
4621 type Examined_Array is array (Int range <>) of Boolean;
4623 function Find_Entry_Index (E : Entity_Id) return Uint;
4624 -- Given an entry, find its index in the visible declarations of the
4625 -- corresponding concurrent type of Typ.
4627 ----------------------
4628 -- Find_Entry_Index --
4629 ----------------------
4631 function Find_Entry_Index (E : Entity_Id) return Uint is
4632 Index : Uint := Uint_1;
4633 Subp_Decl : Entity_Id;
4637 and then not Is_Empty_List (Decls)
4639 Subp_Decl := First (Decls);
4640 while Present (Subp_Decl) loop
4641 if Nkind (Subp_Decl) = N_Entry_Declaration then
4642 if Defining_Identifier (Subp_Decl) = E then
4654 end Find_Entry_Index;
4656 -- Start of processing for Make_Select_Specific_Data_Table
4659 pragma Assert (not Restriction_Active (No_Dispatching_Calls));
4661 DT_Ptr := Node (First_Elmt (Access_Disp_Table (Typ)));
4663 if Present (Corresponding_Concurrent_Type (Typ)) then
4664 Conc_Typ := Corresponding_Concurrent_Type (Typ);
4666 if Present (Full_View (Conc_Typ)) then
4667 Conc_Typ := Full_View (Conc_Typ);
4670 if Ekind (Conc_Typ) = E_Protected_Type then
4671 Decls := Visible_Declarations (Protected_Definition (
4672 Parent (Conc_Typ)));
4674 pragma Assert (Ekind (Conc_Typ) = E_Task_Type);
4675 Decls := Visible_Declarations (Task_Definition (
4676 Parent (Conc_Typ)));
4680 -- Count the non-predefined primitive operations
4682 Prim_Elmt := First_Elmt (Primitive_Operations (Typ));
4683 while Present (Prim_Elmt) loop
4684 Prim := Node (Prim_Elmt);
4686 if not (Is_Predefined_Dispatching_Operation (Prim)
4687 or else Is_Predefined_Dispatching_Alias (Prim))
4689 Nb_Prim := Nb_Prim + 1;
4692 Next_Elmt (Prim_Elmt);
4696 Examined : Examined_Array (1 .. Nb_Prim) := (others => False);
4699 Prim_Elmt := First_Elmt (Primitive_Operations (Typ));
4700 while Present (Prim_Elmt) loop
4701 Prim := Node (Prim_Elmt);
4703 -- Look for primitive overriding an abstract interface subprogram
4705 if Present (Abstract_Interface_Alias (Prim))
4706 and then not Examined (UI_To_Int (DT_Position (Alias (Prim))))
4708 Prim_Pos := DT_Position (Alias (Prim));
4709 pragma Assert (UI_To_Int (Prim_Pos) <= Nb_Prim);
4710 Examined (UI_To_Int (Prim_Pos)) := True;
4712 -- Set the primitive operation kind regardless of subprogram
4714 -- Ada.Tags.Set_Prim_Op_Kind (DT_Ptr, <position>, <kind>);
4716 Append_To (Assignments,
4717 Make_Procedure_Call_Statement (Loc,
4718 Name => New_Reference_To (RTE (RE_Set_Prim_Op_Kind), Loc),
4719 Parameter_Associations => New_List (
4720 New_Reference_To (DT_Ptr, Loc),
4721 Make_Integer_Literal (Loc, Prim_Pos),
4722 Prim_Op_Kind (Alias (Prim), Typ))));
4724 -- Retrieve the root of the alias chain
4727 while Present (Alias (Prim_Als)) loop
4728 Prim_Als := Alias (Prim_Als);
4731 -- In the case of an entry wrapper, set the entry index
4733 if Ekind (Prim) = E_Procedure
4734 and then Is_Primitive_Wrapper (Prim_Als)
4735 and then Ekind (Wrapped_Entity (Prim_Als)) = E_Entry
4738 -- Ada.Tags.Set_Entry_Index
4739 -- (DT_Ptr, <position>, <index>);
4741 Append_To (Assignments,
4742 Make_Procedure_Call_Statement (Loc,
4744 New_Reference_To (RTE (RE_Set_Entry_Index), Loc),
4745 Parameter_Associations => New_List (
4746 New_Reference_To (DT_Ptr, Loc),
4747 Make_Integer_Literal (Loc, Prim_Pos),
4748 Make_Integer_Literal (Loc,
4749 Find_Entry_Index (Wrapped_Entity (Prim_Als))))));
4753 Next_Elmt (Prim_Elmt);
4758 end Make_Select_Specific_Data_Table;
4764 function Make_Tags (Typ : Entity_Id) return List_Id is
4765 Loc : constant Source_Ptr := Sloc (Typ);
4766 Build_Static_DT : constant Boolean :=
4767 Static_Dispatch_Tables
4768 and then Is_Library_Level_Tagged_Type (Typ);
4769 Tname : constant Name_Id := Chars (Typ);
4770 Result : constant List_Id := New_List;
4771 AI_Tag_Comp : Elmt_Id;
4773 Iface_DT_Ptr : Node_Id;
4776 Typ_Comps : Elist_Id;
4779 -- 1) Generate the primary and secondary tag entities
4781 -- Collect the components associated with secondary dispatch tables
4783 if Has_Abstract_Interfaces (Typ) then
4784 Collect_Interface_Components (Typ, Typ_Comps);
4787 -- 1) Generate the primary tag entity
4789 DT_Ptr := Make_Defining_Identifier (Loc,
4790 New_External_Name (Tname, 'P'));
4791 Set_Etype (DT_Ptr, RTE (RE_Tag));
4792 Set_Ekind (DT_Ptr, E_Variable);
4794 -- Import the forward declaration of the tag (Make_DT will take care of
4797 if Build_Static_DT then
4798 Set_Is_Imported (DT_Ptr);
4799 Set_Is_True_Constant (DT_Ptr);
4800 Set_Scope (DT_Ptr, Current_Scope);
4801 Get_External_Name (DT_Ptr, True);
4802 Set_Interface_Name (DT_Ptr,
4803 Make_String_Literal (Loc,
4804 Strval => String_From_Name_Buffer));
4806 -- Set tag entity as internal to ensure proper Sprint output of its
4807 -- implicit importation.
4809 Set_Is_Internal (DT_Ptr);
4812 Make_Object_Declaration (Loc,
4813 Defining_Identifier => DT_Ptr,
4814 Constant_Present => True,
4815 Object_Definition => New_Reference_To (RTE (RE_Tag), Loc)));
4818 pragma Assert (No (Access_Disp_Table (Typ)));
4819 Set_Access_Disp_Table (Typ, New_Elmt_List);
4820 Append_Elmt (DT_Ptr, Access_Disp_Table (Typ));
4822 -- 2) Generate the secondary tag entities
4824 if Has_Abstract_Interfaces (Typ) then
4827 -- For each interface type we build an unique external name
4828 -- associated with its corresponding secondary dispatch table.
4829 -- This external name will be used to declare an object that
4830 -- references this secondary dispatch table, value that will be
4831 -- used for the elaboration of Typ's objects and also for the
4832 -- elaboration of objects of derivations of Typ that do not
4833 -- override the primitive operation of this interface type.
4835 AI_Tag_Comp := First_Elmt (Typ_Comps);
4836 while Present (AI_Tag_Comp) loop
4837 Get_Secondary_DT_External_Name
4838 (Typ, Related_Interface (Node (AI_Tag_Comp)), Suffix_Index);
4840 Typ_Name := Name_Find;
4842 Make_Defining_Identifier (Loc,
4843 Chars => New_External_Name (Typ_Name, 'P'));
4844 Set_Etype (Iface_DT_Ptr, RTE (RE_Interface_Tag));
4845 Set_Ekind (Iface_DT_Ptr, E_Constant);
4846 Set_Is_Statically_Allocated (Iface_DT_Ptr);
4847 Set_Is_True_Constant (Iface_DT_Ptr);
4848 Set_Related_Interface
4849 (Iface_DT_Ptr, Related_Interface (Node (AI_Tag_Comp)));
4850 Append_Elmt (Iface_DT_Ptr, Access_Disp_Table (Typ));
4852 Next_Elmt (AI_Tag_Comp);
4856 -- 3) At the end of Access_Disp_Table we add the entity of an access
4857 -- type declaration. It is used by Build_Get_Prim_Op_Address to
4858 -- expand dispatching calls through the primary dispatch table.
4861 -- type Typ_DT is array (1 .. Nb_Prims) of Address;
4862 -- type Typ_DT_Acc is access Typ_DT;
4865 Name_DT_Prims : constant Name_Id :=
4866 New_External_Name (Tname, 'G');
4867 Name_DT_Prims_Acc : constant Name_Id :=
4868 New_External_Name (Tname, 'H');
4869 DT_Prims : constant Entity_Id :=
4870 Make_Defining_Identifier (Loc, Name_DT_Prims);
4871 DT_Prims_Acc : constant Entity_Id :=
4872 Make_Defining_Identifier (Loc,
4876 Make_Full_Type_Declaration (Loc,
4877 Defining_Identifier => DT_Prims,
4879 Make_Constrained_Array_Definition (Loc,
4880 Discrete_Subtype_Definitions => New_List (
4882 Low_Bound => Make_Integer_Literal (Loc, 1),
4883 High_Bound => Make_Integer_Literal (Loc,
4885 (First_Tag_Component (Typ))))),
4886 Component_Definition =>
4887 Make_Component_Definition (Loc,
4888 Subtype_Indication =>
4889 New_Reference_To (RTE (RE_Address), Loc)))));
4892 Make_Full_Type_Declaration (Loc,
4893 Defining_Identifier => DT_Prims_Acc,
4895 Make_Access_To_Object_Definition (Loc,
4896 Subtype_Indication =>
4897 New_Occurrence_Of (DT_Prims, Loc))));
4899 Append_Elmt (DT_Prims_Acc, Access_Disp_Table (Typ));
4901 -- Analyze the resulting list and suppress the generation of the
4902 -- Init_Proc associated with the above array declaration because
4903 -- we never use such type in object declarations; this type is only
4904 -- used to simplify the expansion associated with dispatching calls.
4906 Analyze_List (Result);
4907 Set_Suppress_Init_Proc (Base_Type (DT_Prims));
4913 -----------------------------------
4914 -- Original_View_In_Visible_Part --
4915 -----------------------------------
4917 function Original_View_In_Visible_Part (Typ : Entity_Id) return Boolean is
4918 Scop : constant Entity_Id := Scope (Typ);
4921 -- The scope must be a package
4923 if Ekind (Scop) /= E_Package
4924 and then Ekind (Scop) /= E_Generic_Package
4929 -- A type with a private declaration has a private view declared in
4930 -- the visible part.
4932 if Has_Private_Declaration (Typ) then
4936 return List_Containing (Parent (Typ)) =
4937 Visible_Declarations (Specification (Unit_Declaration_Node (Scop)));
4938 end Original_View_In_Visible_Part;
4944 function Prim_Op_Kind
4946 Typ : Entity_Id) return Node_Id
4948 Full_Typ : Entity_Id := Typ;
4949 Loc : constant Source_Ptr := Sloc (Prim);
4950 Prim_Op : Entity_Id;
4953 -- Retrieve the original primitive operation
4956 while Present (Alias (Prim_Op)) loop
4957 Prim_Op := Alias (Prim_Op);
4960 if Ekind (Typ) = E_Record_Type
4961 and then Present (Corresponding_Concurrent_Type (Typ))
4963 Full_Typ := Corresponding_Concurrent_Type (Typ);
4966 if Ekind (Prim_Op) = E_Function then
4968 -- Protected function
4970 if Ekind (Full_Typ) = E_Protected_Type then
4971 return New_Reference_To (RTE (RE_POK_Protected_Function), Loc);
4975 elsif Ekind (Full_Typ) = E_Task_Type then
4976 return New_Reference_To (RTE (RE_POK_Task_Function), Loc);
4981 return New_Reference_To (RTE (RE_POK_Function), Loc);
4985 pragma Assert (Ekind (Prim_Op) = E_Procedure);
4987 if Ekind (Full_Typ) = E_Protected_Type then
4991 if Is_Primitive_Wrapper (Prim_Op)
4992 and then Ekind (Wrapped_Entity (Prim_Op)) = E_Entry
4994 return New_Reference_To (RTE (RE_POK_Protected_Entry), Loc);
4996 -- Protected procedure
4999 return New_Reference_To (RTE (RE_POK_Protected_Procedure), Loc);
5002 elsif Ekind (Full_Typ) = E_Task_Type then
5006 if Is_Primitive_Wrapper (Prim_Op)
5007 and then Ekind (Wrapped_Entity (Prim_Op)) = E_Entry
5009 return New_Reference_To (RTE (RE_POK_Task_Entry), Loc);
5011 -- Task "procedure". These are the internally Expander-generated
5012 -- procedures (task body for instance).
5015 return New_Reference_To (RTE (RE_POK_Task_Procedure), Loc);
5018 -- Regular procedure
5021 return New_Reference_To (RTE (RE_POK_Procedure), Loc);
5026 ------------------------
5027 -- Register_Primitive --
5028 ------------------------
5030 procedure Register_Primitive
5036 Iface_Prim : Entity_Id;
5037 Iface_Typ : Entity_Id;
5038 Iface_DT_Ptr : Entity_Id;
5041 Thunk_Id : Entity_Id;
5042 Thunk_Code : Node_Id;
5046 pragma Assert (not Restriction_Active (No_Dispatching_Calls));
5048 if not RTE_Available (RE_Tag) then
5052 if not Present (Abstract_Interface_Alias (Prim)) then
5053 Typ := Scope (DTC_Entity (Prim));
5054 DT_Ptr := Node (First_Elmt (Access_Disp_Table (Typ)));
5055 Pos := DT_Position (Prim);
5056 Tag := First_Tag_Component (Typ);
5058 if Is_Predefined_Dispatching_Operation (Prim)
5059 or else Is_Predefined_Dispatching_Alias (Prim)
5061 Insert_After (Ins_Nod,
5062 Build_Set_Predefined_Prim_Op_Address (Loc,
5063 Tag_Node => New_Reference_To (DT_Ptr, Loc),
5065 Address_Node => Make_Attribute_Reference (Loc,
5066 Prefix => New_Reference_To (Prim, Loc),
5067 Attribute_Name => Name_Address)));
5070 pragma Assert (Pos /= Uint_0 and then Pos <= DT_Entry_Count (Tag));
5072 Insert_After (Ins_Nod,
5073 Build_Set_Prim_Op_Address (Loc,
5075 Tag_Node => New_Reference_To (DT_Ptr, Loc),
5077 Address_Node => Make_Attribute_Reference (Loc,
5078 Prefix => New_Reference_To (Prim, Loc),
5079 Attribute_Name => Name_Address)));
5082 -- Ada 2005 (AI-251): Primitive associated with an interface type
5083 -- Generate the code of the thunk only if the interface type is not an
5084 -- immediate ancestor of Typ; otherwise the dispatch table associated
5085 -- with the interface is the primary dispatch table and we have nothing
5089 Typ := Find_Dispatching_Type (Alias (Prim));
5090 Iface_Typ := Find_Dispatching_Type (Abstract_Interface_Alias (Prim));
5092 pragma Assert (Is_Interface (Iface_Typ));
5094 Expand_Interface_Thunk (Prim, Thunk_Id, Thunk_Code);
5096 if not Is_Parent (Iface_Typ, Typ)
5097 and then Present (Thunk_Code)
5099 -- Comment needed on why checks are suppressed. This is not just
5100 -- efficiency, but fundamental functionality (see 1.295 RH, which
5101 -- still does not answer this question) ???
5103 Insert_Action (Ins_Nod, Thunk_Code, Suppress => All_Checks);
5105 -- Generate the code necessary to fill the appropriate entry of
5106 -- the secondary dispatch table of Prim's controlling type with
5107 -- Thunk_Id's address.
5109 Iface_DT_Ptr := Find_Interface_ADT (Typ, Iface_Typ);
5110 Iface_Prim := Abstract_Interface_Alias (Prim);
5111 Pos := DT_Position (Iface_Prim);
5112 Tag := First_Tag_Component (Iface_Typ);
5114 if Is_Predefined_Dispatching_Operation (Prim)
5115 or else Is_Predefined_Dispatching_Alias (Prim)
5117 Insert_Action (Ins_Nod,
5118 Build_Set_Predefined_Prim_Op_Address (Loc,
5119 Tag_Node => New_Reference_To (Iface_DT_Ptr, Loc),
5122 Make_Attribute_Reference (Loc,
5123 Prefix => New_Reference_To (Thunk_Id, Loc),
5124 Attribute_Name => Name_Address)));
5126 pragma Assert (Pos /= Uint_0
5127 and then Pos <= DT_Entry_Count (Tag));
5129 Insert_Action (Ins_Nod,
5130 Build_Set_Prim_Op_Address (Loc,
5132 Tag_Node => New_Reference_To (Iface_DT_Ptr, Loc),
5134 Address_Node => Make_Attribute_Reference (Loc,
5136 New_Reference_To (Thunk_Id, Loc),
5137 Attribute_Name => Name_Address)));
5141 end Register_Primitive;
5143 -------------------------
5144 -- Set_All_DT_Position --
5145 -------------------------
5147 procedure Set_All_DT_Position (Typ : Entity_Id) is
5149 procedure Validate_Position (Prim : Entity_Id);
5150 -- Check that the position assignated to Prim is completely safe
5151 -- (it has not been assigned to a previously defined primitive
5152 -- operation of Typ)
5154 -----------------------
5155 -- Validate_Position --
5156 -----------------------
5158 procedure Validate_Position (Prim : Entity_Id) is
5163 -- Aliased primitives are safe
5165 if Present (Alias (Prim)) then
5169 Op_Elmt := First_Elmt (Primitive_Operations (Typ));
5170 while Present (Op_Elmt) loop
5171 Op := Node (Op_Elmt);
5173 -- No need to check against itself
5178 -- Primitive operations covering abstract interfaces are
5181 elsif Present (Abstract_Interface_Alias (Op)) then
5184 -- Predefined dispatching operations are completely safe. They
5185 -- are allocated at fixed positions in a separate table.
5187 elsif Is_Predefined_Dispatching_Operation (Op)
5188 or else Is_Predefined_Dispatching_Alias (Op)
5192 -- Aliased subprograms are safe
5194 elsif Present (Alias (Op)) then
5197 elsif DT_Position (Op) = DT_Position (Prim)
5198 and then not Is_Predefined_Dispatching_Operation (Op)
5199 and then not Is_Predefined_Dispatching_Operation (Prim)
5200 and then not Is_Predefined_Dispatching_Alias (Op)
5201 and then not Is_Predefined_Dispatching_Alias (Prim)
5204 -- Handle aliased subprograms
5213 if Present (Overridden_Operation (Op_1)) then
5214 Op_1 := Overridden_Operation (Op_1);
5215 elsif Present (Alias (Op_1)) then
5216 Op_1 := Alias (Op_1);
5224 if Present (Overridden_Operation (Op_2)) then
5225 Op_2 := Overridden_Operation (Op_2);
5226 elsif Present (Alias (Op_2)) then
5227 Op_2 := Alias (Op_2);
5233 if Op_1 /= Op_2 then
5234 raise Program_Error;
5239 Next_Elmt (Op_Elmt);
5241 end Validate_Position;
5245 Parent_Typ : constant Entity_Id := Etype (Typ);
5246 First_Prim : constant Elmt_Id := First_Elmt (Primitive_Operations (Typ));
5247 The_Tag : constant Entity_Id := First_Tag_Component (Typ);
5249 Adjusted : Boolean := False;
5250 Finalized : Boolean := False;
5256 Prim_Elmt : Elmt_Id;
5258 -- Start of processing for Set_All_DT_Position
5261 -- Set the DT_Position for each primitive operation. Perform some
5262 -- sanity checks to avoid to build completely inconsistant dispatch
5265 -- First stage: Set the DTC entity of all the primitive operations
5266 -- This is required to properly read the DT_Position attribute in
5267 -- the latter stages.
5269 Prim_Elmt := First_Prim;
5271 while Present (Prim_Elmt) loop
5272 Prim := Node (Prim_Elmt);
5274 -- Predefined primitives have a separate dispatch table
5276 if not (Is_Predefined_Dispatching_Operation (Prim)
5277 or else Is_Predefined_Dispatching_Alias (Prim))
5279 Count_Prim := Count_Prim + 1;
5282 Set_DTC_Entity_Value (Typ, Prim);
5284 -- Clear any previous value of the DT_Position attribute. In this
5285 -- way we ensure that the final position of all the primitives is
5286 -- stablished by the following stages of this algorithm.
5288 Set_DT_Position (Prim, No_Uint);
5290 Next_Elmt (Prim_Elmt);
5294 Fixed_Prim : array (Int range 0 .. Count_Prim) of Boolean
5295 := (others => False);
5298 procedure Handle_Inherited_Private_Subprograms (Typ : Entity_Id);
5299 -- Called if Typ is declared in a nested package or a public child
5300 -- package to handle inherited primitives that were inherited by Typ
5301 -- in the visible part, but whose declaration was deferred because
5302 -- the parent operation was private and not visible at that point.
5304 procedure Set_Fixed_Prim (Pos : Nat);
5305 -- Sets to true an element of the Fixed_Prim table to indicate
5306 -- that this entry of the dispatch table of Typ is occupied.
5308 ------------------------------------------
5309 -- Handle_Inherited_Private_Subprograms --
5310 ------------------------------------------
5312 procedure Handle_Inherited_Private_Subprograms (Typ : Entity_Id) is
5315 Op_Elmt_2 : Elmt_Id;
5316 Prim_Op : Entity_Id;
5317 Parent_Subp : Entity_Id;
5320 Op_List := Primitive_Operations (Typ);
5322 Op_Elmt := First_Elmt (Op_List);
5323 while Present (Op_Elmt) loop
5324 Prim_Op := Node (Op_Elmt);
5326 -- Search primitives that are implicit operations with an
5327 -- internal name whose parent operation has a normal name.
5329 if Present (Alias (Prim_Op))
5330 and then Find_Dispatching_Type (Alias (Prim_Op)) /= Typ
5331 and then not Comes_From_Source (Prim_Op)
5332 and then Is_Internal_Name (Chars (Prim_Op))
5333 and then not Is_Internal_Name (Chars (Alias (Prim_Op)))
5335 Parent_Subp := Alias (Prim_Op);
5337 -- Check if the type has an explicit overriding for this
5340 Op_Elmt_2 := Next_Elmt (Op_Elmt);
5341 while Present (Op_Elmt_2) loop
5342 if Chars (Node (Op_Elmt_2)) = Chars (Parent_Subp)
5343 and then Type_Conformant (Prim_Op, Node (Op_Elmt_2))
5345 Set_DT_Position (Prim_Op, DT_Position (Parent_Subp));
5346 Set_DT_Position (Node (Op_Elmt_2),
5347 DT_Position (Parent_Subp));
5348 Set_Fixed_Prim (UI_To_Int (DT_Position (Prim_Op)));
5350 goto Next_Primitive;
5353 Next_Elmt (Op_Elmt_2);
5358 Next_Elmt (Op_Elmt);
5360 end Handle_Inherited_Private_Subprograms;
5362 --------------------
5363 -- Set_Fixed_Prim --
5364 --------------------
5366 procedure Set_Fixed_Prim (Pos : Nat) is
5368 pragma Assert (Pos >= 0 and then Pos <= Count_Prim);
5369 Fixed_Prim (Pos) := True;
5371 when Constraint_Error =>
5372 raise Program_Error;
5376 -- In case of nested packages and public child package it may be
5377 -- necessary a special management on inherited subprograms so that
5378 -- the dispatch table is properly filled.
5380 if Ekind (Scope (Scope (Typ))) = E_Package
5381 and then Scope (Scope (Typ)) /= Standard_Standard
5382 and then ((Is_Derived_Type (Typ) and then not Is_Private_Type (Typ))
5384 (Nkind (Parent (Typ)) = N_Private_Extension_Declaration
5385 and then Is_Generic_Type (Typ)))
5386 and then In_Open_Scopes (Scope (Etype (Typ)))
5387 and then Typ = Base_Type (Typ)
5389 Handle_Inherited_Private_Subprograms (Typ);
5392 -- Second stage: Register fixed entries
5395 Prim_Elmt := First_Prim;
5396 while Present (Prim_Elmt) loop
5397 Prim := Node (Prim_Elmt);
5399 -- Predefined primitives have a separate table and all its
5400 -- entries are at predefined fixed positions.
5402 if Is_Predefined_Dispatching_Operation (Prim) then
5403 Set_DT_Position (Prim, Default_Prim_Op_Position (Prim));
5405 elsif Is_Predefined_Dispatching_Alias (Prim) then
5407 while Present (Alias (E)) loop
5411 Set_DT_Position (Prim, Default_Prim_Op_Position (E));
5413 -- Overriding primitives of ancestor abstract interfaces
5415 elsif Present (Abstract_Interface_Alias (Prim))
5417 (Find_Dispatching_Type
5418 (Abstract_Interface_Alias (Prim)),
5421 pragma Assert (DT_Position (Prim) = No_Uint
5422 and then Present (DTC_Entity
5423 (Abstract_Interface_Alias (Prim))));
5425 E := Abstract_Interface_Alias (Prim);
5426 Set_DT_Position (Prim, DT_Position (E));
5429 (DT_Position (Alias (Prim)) = No_Uint
5430 or else DT_Position (Alias (Prim)) = DT_Position (E));
5431 Set_DT_Position (Alias (Prim), DT_Position (E));
5432 Set_Fixed_Prim (UI_To_Int (DT_Position (Prim)));
5434 -- Overriding primitives must use the same entry as the
5435 -- overriden primitive.
5437 elsif not Present (Abstract_Interface_Alias (Prim))
5438 and then Present (Alias (Prim))
5439 and then Chars (Prim) = Chars (Alias (Prim))
5440 and then Find_Dispatching_Type (Alias (Prim)) /= Typ
5442 (Find_Dispatching_Type (Alias (Prim)), Typ)
5443 and then Present (DTC_Entity (Alias (Prim)))
5446 Set_DT_Position (Prim, DT_Position (E));
5448 if not Is_Predefined_Dispatching_Alias (E) then
5449 Set_Fixed_Prim (UI_To_Int (DT_Position (E)));
5453 Next_Elmt (Prim_Elmt);
5456 -- Third stage: Fix the position of all the new primitives
5457 -- Entries associated with primitives covering interfaces
5458 -- are handled in a latter round.
5460 Prim_Elmt := First_Prim;
5461 while Present (Prim_Elmt) loop
5462 Prim := Node (Prim_Elmt);
5464 -- Skip primitives previously set entries
5466 if DT_Position (Prim) /= No_Uint then
5469 -- Primitives covering interface primitives are handled later
5471 elsif Present (Abstract_Interface_Alias (Prim)) then
5475 -- Take the next available position in the DT
5478 Nb_Prim := Nb_Prim + 1;
5479 pragma Assert (Nb_Prim <= Count_Prim);
5480 exit when not Fixed_Prim (Nb_Prim);
5483 Set_DT_Position (Prim, UI_From_Int (Nb_Prim));
5484 Set_Fixed_Prim (Nb_Prim);
5487 Next_Elmt (Prim_Elmt);
5491 -- Fourth stage: Complete the decoration of primitives covering
5492 -- interfaces (that is, propagate the DT_Position attribute
5493 -- from the aliased primitive)
5495 Prim_Elmt := First_Prim;
5496 while Present (Prim_Elmt) loop
5497 Prim := Node (Prim_Elmt);
5499 if DT_Position (Prim) = No_Uint
5500 and then Present (Abstract_Interface_Alias (Prim))
5502 pragma Assert (Present (Alias (Prim))
5503 and then Find_Dispatching_Type (Alias (Prim)) = Typ);
5505 -- Check if this entry will be placed in the primary DT
5507 if Is_Parent (Find_Dispatching_Type
5508 (Abstract_Interface_Alias (Prim)),
5511 pragma Assert (DT_Position (Alias (Prim)) /= No_Uint);
5512 Set_DT_Position (Prim, DT_Position (Alias (Prim)));
5514 -- Otherwise it will be placed in the secondary DT
5518 (DT_Position (Abstract_Interface_Alias (Prim)) /= No_Uint);
5519 Set_DT_Position (Prim,
5520 DT_Position (Abstract_Interface_Alias (Prim)));
5524 Next_Elmt (Prim_Elmt);
5527 -- Generate listing showing the contents of the dispatch tables.
5528 -- This action is done before some further static checks because
5529 -- in case of critical errors caused by a wrong dispatch table
5530 -- we need to see the contents of such table.
5532 if Debug_Flag_ZZ then
5536 -- Final stage: Ensure that the table is correct plus some further
5537 -- verifications concerning the primitives.
5539 Prim_Elmt := First_Prim;
5541 while Present (Prim_Elmt) loop
5542 Prim := Node (Prim_Elmt);
5544 -- At this point all the primitives MUST have a position
5545 -- in the dispatch table
5547 if DT_Position (Prim) = No_Uint then
5548 raise Program_Error;
5551 -- Calculate real size of the dispatch table
5553 if not (Is_Predefined_Dispatching_Operation (Prim)
5554 or else Is_Predefined_Dispatching_Alias (Prim))
5555 and then UI_To_Int (DT_Position (Prim)) > DT_Length
5557 DT_Length := UI_To_Int (DT_Position (Prim));
5560 -- Ensure that the asignated position to non-predefined
5561 -- dispatching operations in the dispatch table is correct.
5563 if not (Is_Predefined_Dispatching_Operation (Prim)
5564 or else Is_Predefined_Dispatching_Alias (Prim))
5566 Validate_Position (Prim);
5569 if Chars (Prim) = Name_Finalize then
5573 if Chars (Prim) = Name_Adjust then
5577 -- An abstract operation cannot be declared in the private part
5578 -- for a visible abstract type, because it could never be over-
5579 -- ridden. For explicit declarations this is checked at the
5580 -- point of declaration, but for inherited operations it must
5581 -- be done when building the dispatch table.
5583 -- Ada 2005 (AI-251): Hidden entities associated with abstract
5584 -- interface primitives are not taken into account because the
5585 -- check is done with the aliased primitive.
5587 if Is_Abstract_Type (Typ)
5588 and then Is_Abstract_Subprogram (Prim)
5589 and then Present (Alias (Prim))
5590 and then not Present (Abstract_Interface_Alias (Prim))
5591 and then Is_Derived_Type (Typ)
5592 and then In_Private_Part (Current_Scope)
5594 List_Containing (Parent (Prim)) =
5595 Private_Declarations
5596 (Specification (Unit_Declaration_Node (Current_Scope)))
5597 and then Original_View_In_Visible_Part (Typ)
5599 -- We exclude Input and Output stream operations because
5600 -- Limited_Controlled inherits useless Input and Output
5601 -- stream operations from Root_Controlled, which can
5602 -- never be overridden.
5604 if not Is_TSS (Prim, TSS_Stream_Input)
5606 not Is_TSS (Prim, TSS_Stream_Output)
5609 ("abstract inherited private operation&" &
5610 " must be overridden (RM 3.9.3(10))",
5611 Parent (Typ), Prim);
5615 Next_Elmt (Prim_Elmt);
5620 if Is_Controlled (Typ) then
5621 if not Finalized then
5623 ("controlled type has no explicit Finalize method?", Typ);
5625 elsif not Adjusted then
5627 ("controlled type has no explicit Adjust method?", Typ);
5631 -- Set the final size of the Dispatch Table
5633 Set_DT_Entry_Count (The_Tag, UI_From_Int (DT_Length));
5635 -- The derived type must have at least as many components as its parent
5636 -- (for root types, the Etype points back to itself and the test cannot
5639 if DT_Entry_Count (The_Tag) <
5640 DT_Entry_Count (First_Tag_Component (Parent_Typ))
5642 raise Program_Error;
5644 end Set_All_DT_Position;
5646 -----------------------------
5647 -- Set_Default_Constructor --
5648 -----------------------------
5650 procedure Set_Default_Constructor (Typ : Entity_Id) is
5657 -- Look for the default constructor entity. For now only the
5658 -- default constructor has the flag Is_Constructor.
5660 E := Next_Entity (Typ);
5662 and then (Ekind (E) /= E_Function or else not Is_Constructor (E))
5667 -- Create the init procedure
5671 Init := Make_Defining_Identifier (Loc, Make_Init_Proc_Name (Typ));
5672 Param := Make_Defining_Identifier (Loc, Name_X);
5675 Make_Subprogram_Declaration (Loc,
5676 Make_Procedure_Specification (Loc,
5677 Defining_Unit_Name => Init,
5678 Parameter_Specifications => New_List (
5679 Make_Parameter_Specification (Loc,
5680 Defining_Identifier => Param,
5681 Parameter_Type => New_Reference_To (Typ, Loc))))));
5683 Set_Init_Proc (Typ, Init);
5684 Set_Is_Imported (Init);
5685 Set_Interface_Name (Init, Interface_Name (E));
5686 Set_Convention (Init, Convention_C);
5687 Set_Is_Public (Init);
5688 Set_Has_Completion (Init);
5690 -- If there are no constructors, mark the type as abstract since we
5691 -- won't be able to declare objects of that type.
5694 Set_Is_Abstract_Type (Typ);
5696 end Set_Default_Constructor;
5698 --------------------------
5699 -- Set_DTC_Entity_Value --
5700 --------------------------
5702 procedure Set_DTC_Entity_Value
5703 (Tagged_Type : Entity_Id;
5707 if Present (Abstract_Interface_Alias (Prim))
5708 and then Is_Interface
5709 (Find_Dispatching_Type
5710 (Abstract_Interface_Alias (Prim)))
5712 Set_DTC_Entity (Prim,
5715 Iface => Find_Dispatching_Type
5716 (Abstract_Interface_Alias (Prim))));
5718 Set_DTC_Entity (Prim,
5719 First_Tag_Component (Tagged_Type));
5721 end Set_DTC_Entity_Value;
5727 function Tagged_Kind (T : Entity_Id) return Node_Id is
5728 Conc_Typ : Entity_Id;
5729 Loc : constant Source_Ptr := Sloc (T);
5733 (Is_Tagged_Type (T) and then RTE_Available (RE_Tagged_Kind));
5737 if Is_Abstract_Type (T) then
5738 if Is_Limited_Record (T) then
5739 return New_Reference_To (RTE (RE_TK_Abstract_Limited_Tagged), Loc);
5741 return New_Reference_To (RTE (RE_TK_Abstract_Tagged), Loc);
5746 elsif Is_Concurrent_Record_Type (T) then
5747 Conc_Typ := Corresponding_Concurrent_Type (T);
5749 if Present (Full_View (Conc_Typ)) then
5750 Conc_Typ := Full_View (Conc_Typ);
5753 if Ekind (Conc_Typ) = E_Protected_Type then
5754 return New_Reference_To (RTE (RE_TK_Protected), Loc);
5756 pragma Assert (Ekind (Conc_Typ) = E_Task_Type);
5757 return New_Reference_To (RTE (RE_TK_Task), Loc);
5760 -- Regular tagged kinds
5763 if Is_Limited_Record (T) then
5764 return New_Reference_To (RTE (RE_TK_Limited_Tagged), Loc);
5766 return New_Reference_To (RTE (RE_TK_Tagged), Loc);
5775 procedure Write_DT (Typ : Entity_Id) is
5780 -- Protect this procedure against wrong usage. Required because it will
5781 -- be used directly from GDB
5783 if not (Typ <= Last_Node_Id)
5784 or else not Is_Tagged_Type (Typ)
5786 Write_Str ("wrong usage: Write_DT must be used with tagged types");
5791 Write_Int (Int (Typ));
5793 Write_Name (Chars (Typ));
5795 if Is_Interface (Typ) then
5796 Write_Str (" is interface");
5801 Elmt := First_Elmt (Primitive_Operations (Typ));
5802 while Present (Elmt) loop
5803 Prim := Node (Elmt);
5806 -- Indicate if this primitive will be allocated in the primary
5807 -- dispatch table or in a secondary dispatch table associated
5808 -- with an abstract interface type
5810 if Present (DTC_Entity (Prim)) then
5811 if Etype (DTC_Entity (Prim)) = RTE (RE_Tag) then
5818 -- Output the node of this primitive operation and its name
5820 Write_Int (Int (Prim));
5823 if Is_Predefined_Dispatching_Operation (Prim) then
5824 Write_Str ("(predefined) ");
5827 Write_Name (Chars (Prim));
5829 -- Indicate if this primitive has an aliased primitive
5831 if Present (Alias (Prim)) then
5832 Write_Str (" (alias = ");
5833 Write_Int (Int (Alias (Prim)));
5835 -- If the DTC_Entity attribute is already set we can also output
5836 -- the name of the interface covered by this primitive (if any)
5838 if Present (DTC_Entity (Alias (Prim)))
5839 and then Is_Interface (Scope (DTC_Entity (Alias (Prim))))
5841 Write_Str (" from interface ");
5842 Write_Name (Chars (Scope (DTC_Entity (Alias (Prim)))));
5845 if Present (Abstract_Interface_Alias (Prim)) then
5846 Write_Str (", AI_Alias of ");
5847 Write_Name (Chars (Scope (DTC_Entity
5848 (Abstract_Interface_Alias (Prim)))));
5850 Write_Int (Int (Abstract_Interface_Alias (Prim)));
5856 -- Display the final position of this primitive in its associated
5857 -- (primary or secondary) dispatch table
5859 if Present (DTC_Entity (Prim))
5860 and then DT_Position (Prim) /= No_Uint
5862 Write_Str (" at #");
5863 Write_Int (UI_To_Int (DT_Position (Prim)));
5866 if Is_Abstract_Subprogram (Prim) then
5867 Write_Str (" is abstract;");
5869 -- Check if this is a null primitive
5871 elsif Comes_From_Source (Prim)
5872 and then Ekind (Prim) = E_Procedure
5873 and then Null_Present (Parent (Prim))
5875 Write_Str (" is null;");