1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2005 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_Ch7; use Exp_Ch7;
34 with Exp_Tss; use Exp_Tss;
35 with Exp_Util; use Exp_Util;
36 with Itypes; use Itypes;
37 with Nlists; use Nlists;
38 with Nmake; use Nmake;
39 with Namet; use Namet;
41 with Output; use Output;
42 with Rtsfind; use Rtsfind;
44 with Sem_Disp; use Sem_Disp;
45 with Sem_Res; use Sem_Res;
46 with Sem_Type; use Sem_Type;
47 with Sem_Util; use Sem_Util;
48 with Sinfo; use Sinfo;
49 with Snames; use Snames;
50 with Stand; use Stand;
51 with Tbuild; use Tbuild;
52 with Ttypes; use Ttypes;
53 with Uintp; use Uintp;
55 package body Exp_Disp is
57 Ada_Actions : constant array (DT_Access_Action) of RE_Id :=
58 (CW_Membership => RE_CW_Membership,
59 IW_Membership => RE_IW_Membership,
60 DT_Entry_Size => RE_DT_Entry_Size,
61 DT_Prologue_Size => RE_DT_Prologue_Size,
62 Get_Access_Level => RE_Get_Access_Level,
63 Get_External_Tag => RE_Get_External_Tag,
64 Get_Prim_Op_Address => RE_Get_Prim_Op_Address,
65 Get_RC_Offset => RE_Get_RC_Offset,
66 Get_Remotely_Callable => RE_Get_Remotely_Callable,
67 Inherit_DT => RE_Inherit_DT,
68 Inherit_TSD => RE_Inherit_TSD,
69 Register_Interface_Tag => RE_Register_Interface_Tag,
70 Register_Tag => RE_Register_Tag,
71 Set_Access_Level => RE_Set_Access_Level,
72 Set_Expanded_Name => RE_Set_Expanded_Name,
73 Set_External_Tag => RE_Set_External_Tag,
74 Set_Prim_Op_Address => RE_Set_Prim_Op_Address,
75 Set_RC_Offset => RE_Set_RC_Offset,
76 Set_Remotely_Callable => RE_Set_Remotely_Callable,
77 Set_TSD => RE_Set_TSD,
78 TSD_Entry_Size => RE_TSD_Entry_Size,
79 TSD_Prologue_Size => RE_TSD_Prologue_Size);
81 Action_Is_Proc : constant array (DT_Access_Action) of Boolean :=
82 (CW_Membership => False,
83 IW_Membership => False,
84 DT_Entry_Size => False,
85 DT_Prologue_Size => False,
86 Get_Access_Level => False,
87 Get_External_Tag => False,
88 Get_Prim_Op_Address => False,
89 Get_Remotely_Callable => False,
90 Get_RC_Offset => False,
93 Register_Interface_Tag => True,
95 Set_Access_Level => True,
96 Set_Expanded_Name => True,
97 Set_External_Tag => True,
98 Set_Prim_Op_Address => True,
99 Set_RC_Offset => True,
100 Set_Remotely_Callable => True,
102 TSD_Entry_Size => False,
103 TSD_Prologue_Size => False);
105 Action_Nb_Arg : constant array (DT_Access_Action) of Int :=
109 DT_Prologue_Size => 0,
110 Get_Access_Level => 1,
111 Get_External_Tag => 1,
112 Get_Prim_Op_Address => 2,
114 Get_Remotely_Callable => 1,
117 Register_Interface_Tag => 2,
119 Set_Access_Level => 2,
120 Set_Expanded_Name => 2,
121 Set_External_Tag => 2,
122 Set_Prim_Op_Address => 3,
124 Set_Remotely_Callable => 2,
127 TSD_Prologue_Size => 0);
129 function Build_Anonymous_Access_Type
130 (Directly_Designated_Type : Entity_Id;
131 Related_Nod : Node_Id) return Entity_Id;
132 -- Returns a decorated entity corresponding with an anonymous access type.
133 -- Used to generate unchecked type conversion of an address.
135 procedure Collect_All_Interfaces (T : Entity_Id);
136 -- Ada 2005 (AI-251): Collect the whole list of interfaces that are
137 -- directly or indirectly implemented by T. Used to compute the size
138 -- of the table of interfaces.
140 function Default_Prim_Op_Position (Subp : Entity_Id) return Uint;
141 -- Ada 2005 (AI-251): Returns the fixed position in the dispatch table
142 -- of the default primitive operations.
144 function Original_View_In_Visible_Part (Typ : Entity_Id) return Boolean;
145 -- Check if the type has a private view or if the public view appears
146 -- in the visible part of a package spec.
148 ----------------------------------
149 -- Build_Anonymous_Access_Type --
150 ----------------------------------
152 function Build_Anonymous_Access_Type
153 (Directly_Designated_Type : Entity_Id;
154 Related_Nod : Node_Id) return Entity_Id
159 New_E := Create_Itype (Ekind => E_Anonymous_Access_Type,
160 Related_Nod => Related_Nod,
161 Scope_Id => Current_Scope);
163 Set_Etype (New_E, New_E);
164 Init_Size_Align (New_E);
165 Init_Size (New_E, System_Address_Size);
166 Set_Directly_Designated_Type (New_E, Directly_Designated_Type);
167 Set_Is_First_Subtype (New_E);
170 end Build_Anonymous_Access_Type;
172 ----------------------------
173 -- Collect_All_Interfaces --
174 ----------------------------
176 procedure Collect_All_Interfaces (T : Entity_Id) is
178 procedure Add_Interface (Iface : Entity_Id);
179 -- Add the interface it if is not already in the list
181 procedure Collect (Typ : Entity_Id);
182 -- Subsidiary subprogram used to traverse the whole list
183 -- of directly and indirectly implemented interfaces
189 procedure Add_Interface (Iface : Entity_Id) is
190 Elmt : Elmt_Id := First_Elmt (Abstract_Interfaces (T));
193 while Present (Elmt) and then Node (Elmt) /= Iface loop
197 if not Present (Elmt) then
198 Append_Elmt (Iface, Abstract_Interfaces (T));
206 procedure Collect (Typ : Entity_Id) is
207 Nod : constant Node_Id := Type_Definition (Parent (Typ));
210 Ancestor : Entity_Id;
214 or else Nkind (Nod) = N_Derived_Type_Definition
215 or else Nkind (Nod) = N_Record_Definition);
217 if Nkind (Nod) = N_Record_Definition then
221 -- Include the ancestor if we are generating the whole list
222 -- of interfaces. This is used to know the size of the table
223 -- that stores the tag of all the ancestor interfaces.
225 Ancestor := Etype (Typ);
227 if Is_Interface (Ancestor) then
228 Add_Interface (Ancestor);
232 and then Ekind (Ancestor) /= E_Record_Type_With_Private
237 -- Traverse the graph of ancestor interfaces
239 if Is_Non_Empty_List (Interface_List (Nod)) then
240 Id := First (Interface_List (Nod));
242 while Present (Id) loop
246 if Is_Interface (Iface) then
247 Add_Interface (Iface);
256 -- Start of processing for Collect_All_Interfaces
260 end Collect_All_Interfaces;
262 ------------------------------
263 -- Default_Prim_Op_Position --
264 ------------------------------
266 function Default_Prim_Op_Position (Subp : Entity_Id) return Uint is
267 TSS_Name : TSS_Name_Type;
268 E : Entity_Id := Subp;
271 -- Handle overriden subprograms
273 while Present (Alias (E)) loop
277 Get_Name_String (Chars (E));
280 (Name_Buffer (Name_Len - TSS_Name'Length + 1 .. Name_Len));
282 if Chars (E) = Name_uSize then
285 elsif Chars (E) = Name_uAlignment then
288 elsif TSS_Name = TSS_Stream_Read then
291 elsif TSS_Name = TSS_Stream_Write then
294 elsif TSS_Name = TSS_Stream_Input then
297 elsif TSS_Name = TSS_Stream_Output then
300 elsif Chars (E) = Name_Op_Eq then
303 elsif Chars (E) = Name_uAssign then
306 elsif TSS_Name = TSS_Deep_Adjust then
309 elsif TSS_Name = TSS_Deep_Finalize then
315 end Default_Prim_Op_Position;
317 -----------------------------
318 -- Expand_Dispatching_Call --
319 -----------------------------
321 procedure Expand_Dispatching_Call (Call_Node : Node_Id) is
322 Loc : constant Source_Ptr := Sloc (Call_Node);
323 Call_Typ : constant Entity_Id := Etype (Call_Node);
325 Ctrl_Arg : constant Node_Id := Controlling_Argument (Call_Node);
326 Param_List : constant List_Id := Parameter_Associations (Call_Node);
327 Subp : Entity_Id := Entity (Name (Call_Node));
331 New_Call_Name : Node_Id;
332 New_Params : List_Id := No_List;
335 Subp_Ptr_Typ : Entity_Id;
336 Subp_Typ : Entity_Id;
338 Eq_Prim_Op : Entity_Id := Empty;
339 Controlling_Tag : Node_Id;
341 function New_Value (From : Node_Id) return Node_Id;
342 -- From is the original Expression. New_Value is equivalent to a call
343 -- to Duplicate_Subexpr with an explicit dereference when From is an
346 function Controlling_Type (Subp : Entity_Id) return Entity_Id;
347 -- Returns the tagged type for which Subp is a primitive subprogram
353 function New_Value (From : Node_Id) return Node_Id is
354 Res : constant Node_Id := Duplicate_Subexpr (From);
356 if Is_Access_Type (Etype (From)) then
357 return Make_Explicit_Dereference (Sloc (From), Res);
363 ----------------------
364 -- Controlling_Type --
365 ----------------------
367 function Controlling_Type (Subp : Entity_Id) return Entity_Id is
369 if Ekind (Subp) = E_Function
370 and then Has_Controlling_Result (Subp)
372 return Base_Type (Etype (Subp));
376 Formal : Entity_Id := First_Formal (Subp);
379 while Present (Formal) loop
380 if Is_Controlling_Formal (Formal) then
381 if Is_Access_Type (Etype (Formal)) then
382 return Base_Type (Designated_Type (Etype (Formal)));
384 return Base_Type (Etype (Formal));
388 Next_Formal (Formal);
393 -- Controlling type not found (should never happen)
396 end Controlling_Type;
398 -- Start of processing for Expand_Dispatching_Call
401 -- If this is an inherited operation that was overridden, the body
402 -- that is being called is its alias.
404 if Present (Alias (Subp))
405 and then Is_Inherited_Operation (Subp)
406 and then No (DTC_Entity (Subp))
408 Subp := Alias (Subp);
411 -- Expand_Dispatching_Call is called directly from the semantics,
412 -- so we need a check to see whether expansion is active before
415 if not Expander_Active then
419 -- Definition of the class-wide type and the tagged type
421 -- If the controlling argument is itself a tag rather than a tagged
422 -- object, then use the class-wide type associated with the subprogram's
423 -- controlling type. This case can occur when a call to an inherited
424 -- primitive has an actual that originated from a default parameter
425 -- given by a tag-indeterminate call and when there is no other
426 -- controlling argument providing the tag (AI-239 requires dispatching).
427 -- This capability of dispatching directly by tag is also needed by the
428 -- implementation of AI-260 (for the generic dispatching constructors).
430 if Etype (Ctrl_Arg) = RTE (RE_Tag)
431 or else Etype (Ctrl_Arg) = RTE (RE_Interface_Tag)
433 CW_Typ := Class_Wide_Type (Controlling_Type (Subp));
435 elsif Is_Access_Type (Etype (Ctrl_Arg)) then
436 CW_Typ := Designated_Type (Etype (Ctrl_Arg));
439 CW_Typ := Etype (Ctrl_Arg);
442 Typ := Root_Type (CW_Typ);
444 if not Is_Limited_Type (Typ) then
445 Eq_Prim_Op := Find_Prim_Op (Typ, Name_Op_Eq);
448 if Is_CPP_Class (Root_Type (Typ)) then
450 -- Create a new parameter list with the displaced 'this'
452 New_Params := New_List;
453 Param := First_Actual (Call_Node);
454 while Present (Param) loop
455 Append_To (New_Params, Relocate_Node (Param));
459 elsif Present (Param_List) then
461 -- Generate the Tag checks when appropriate
463 New_Params := New_List;
465 Param := First_Actual (Call_Node);
466 while Present (Param) loop
468 -- No tag check with itself
470 if Param = Ctrl_Arg then
471 Append_To (New_Params,
472 Duplicate_Subexpr_Move_Checks (Param));
474 -- No tag check for parameter whose type is neither tagged nor
475 -- access to tagged (for access parameters)
477 elsif No (Find_Controlling_Arg (Param)) then
478 Append_To (New_Params, Relocate_Node (Param));
480 -- No tag check for function dispatching on result if the
481 -- Tag given by the context is this one
483 elsif Find_Controlling_Arg (Param) = Ctrl_Arg then
484 Append_To (New_Params, Relocate_Node (Param));
486 -- "=" is the only dispatching operation allowed to get
487 -- operands with incompatible tags (it just returns false).
488 -- We use Duplicate_Subexpr_Move_Checks instead of calling
489 -- Relocate_Node because the value will be duplicated to
492 elsif Subp = Eq_Prim_Op then
493 Append_To (New_Params,
494 Duplicate_Subexpr_Move_Checks (Param));
496 -- No check in presence of suppress flags
498 elsif Tag_Checks_Suppressed (Etype (Param))
499 or else (Is_Access_Type (Etype (Param))
500 and then Tag_Checks_Suppressed
501 (Designated_Type (Etype (Param))))
503 Append_To (New_Params, Relocate_Node (Param));
505 -- Optimization: no tag checks if the parameters are identical
507 elsif Is_Entity_Name (Param)
508 and then Is_Entity_Name (Ctrl_Arg)
509 and then Entity (Param) = Entity (Ctrl_Arg)
511 Append_To (New_Params, Relocate_Node (Param));
513 -- Now we need to generate the Tag check
516 -- Generate code for tag equality check
517 -- Perhaps should have Checks.Apply_Tag_Equality_Check???
519 Insert_Action (Ctrl_Arg,
520 Make_Implicit_If_Statement (Call_Node,
524 Make_Selected_Component (Loc,
525 Prefix => New_Value (Ctrl_Arg),
528 (First_Tag_Component (Typ), Loc)),
531 Make_Selected_Component (Loc,
533 Unchecked_Convert_To (Typ, New_Value (Param)),
536 (First_Tag_Component (Typ), Loc))),
539 New_List (New_Constraint_Error (Loc))));
541 Append_To (New_Params, Relocate_Node (Param));
548 -- Generate the appropriate subprogram pointer type
550 if Etype (Subp) = Typ then
553 Res_Typ := Etype (Subp);
556 Subp_Typ := Create_Itype (E_Subprogram_Type, Call_Node);
557 Subp_Ptr_Typ := Create_Itype (E_Access_Subprogram_Type, Call_Node);
558 Set_Etype (Subp_Typ, Res_Typ);
559 Init_Size_Align (Subp_Ptr_Typ);
560 Set_Returns_By_Ref (Subp_Typ, Returns_By_Ref (Subp));
562 -- Create a new list of parameters which is a copy of the old formal
563 -- list including the creation of a new set of matching entities.
566 Old_Formal : Entity_Id := First_Formal (Subp);
567 New_Formal : Entity_Id;
571 if Present (Old_Formal) then
572 New_Formal := New_Copy (Old_Formal);
573 Set_First_Entity (Subp_Typ, New_Formal);
574 Param := First_Actual (Call_Node);
577 Set_Scope (New_Formal, Subp_Typ);
579 -- Change all the controlling argument types to be class-wide
580 -- to avoid a recursion in dispatching.
582 if Is_Controlling_Formal (New_Formal) then
583 Set_Etype (New_Formal, Etype (Param));
586 if Is_Itype (Etype (New_Formal)) then
587 Extra := New_Copy (Etype (New_Formal));
589 if Ekind (Extra) = E_Record_Subtype
590 or else Ekind (Extra) = E_Class_Wide_Subtype
592 Set_Cloned_Subtype (Extra, Etype (New_Formal));
595 Set_Etype (New_Formal, Extra);
596 Set_Scope (Etype (New_Formal), Subp_Typ);
600 Next_Formal (Old_Formal);
601 exit when No (Old_Formal);
603 Set_Next_Entity (New_Formal, New_Copy (Old_Formal));
604 Next_Entity (New_Formal);
607 Set_Last_Entity (Subp_Typ, Extra);
609 -- Copy extra formals
611 New_Formal := First_Entity (Subp_Typ);
612 while Present (New_Formal) loop
613 if Present (Extra_Constrained (New_Formal)) then
614 Set_Extra_Formal (Extra,
615 New_Copy (Extra_Constrained (New_Formal)));
616 Extra := Extra_Formal (Extra);
617 Set_Extra_Constrained (New_Formal, Extra);
619 elsif Present (Extra_Accessibility (New_Formal)) then
620 Set_Extra_Formal (Extra,
621 New_Copy (Extra_Accessibility (New_Formal)));
622 Extra := Extra_Formal (Extra);
623 Set_Extra_Accessibility (New_Formal, Extra);
626 Next_Formal (New_Formal);
631 Set_Etype (Subp_Ptr_Typ, Subp_Ptr_Typ);
632 Set_Directly_Designated_Type (Subp_Ptr_Typ, Subp_Typ);
634 -- If the controlling argument is a value of type Ada.Tag then
635 -- use it directly. Otherwise, the tag must be extracted from
636 -- the controlling object.
638 if Etype (Ctrl_Arg) = RTE (RE_Tag)
639 or else Etype (Ctrl_Arg) = RTE (RE_Interface_Tag)
641 Controlling_Tag := Duplicate_Subexpr (Ctrl_Arg);
645 Make_Selected_Component (Loc,
646 Prefix => Duplicate_Subexpr_Move_Checks (Ctrl_Arg),
647 Selector_Name => New_Reference_To (DTC_Entity (Subp), Loc));
651 -- Subp_Ptr_Typ!(Get_Prim_Op_Address (Ctrl._Tag, pos));
654 Unchecked_Convert_To (Subp_Ptr_Typ,
655 Make_DT_Access_Action (Typ,
656 Action => Get_Prim_Op_Address,
665 Make_Integer_Literal (Loc, DT_Position (Subp)))));
667 if Nkind (Call_Node) = N_Function_Call then
669 -- Ada 2005 (AI-251): A dispatching "=" with an abstract interface
670 -- just requires the comparison of the tags.
672 if Ekind (Etype (Ctrl_Arg)) = E_Class_Wide_Type
673 and then Is_Interface (Etype (Ctrl_Arg))
674 and then Subp = Eq_Prim_Op
676 Param := First_Actual (Call_Node);
681 Make_Selected_Component (Loc,
682 Prefix => New_Value (Param),
684 New_Reference_To (First_Tag_Component (Typ), Loc)),
687 Make_Selected_Component (Loc,
689 Unchecked_Convert_To (Typ,
690 New_Value (Next_Actual (Param))),
692 New_Reference_To (First_Tag_Component (Typ), Loc)));
696 Make_Function_Call (Loc,
697 Name => New_Call_Name,
698 Parameter_Associations => New_Params);
700 -- If this is a dispatching "=", we must first compare the tags so
701 -- we generate: x.tag = y.tag and then x = y
703 if Subp = Eq_Prim_Op then
704 Param := First_Actual (Call_Node);
710 Make_Selected_Component (Loc,
711 Prefix => New_Value (Param),
713 New_Reference_To (First_Tag_Component (Typ),
717 Make_Selected_Component (Loc,
719 Unchecked_Convert_To (Typ,
720 New_Value (Next_Actual (Param))),
722 New_Reference_To (First_Tag_Component (Typ),
724 Right_Opnd => New_Call);
730 Make_Procedure_Call_Statement (Loc,
731 Name => New_Call_Name,
732 Parameter_Associations => New_Params);
735 Rewrite (Call_Node, New_Call);
736 Analyze_And_Resolve (Call_Node, Call_Typ);
737 end Expand_Dispatching_Call;
739 ---------------------------------
740 -- Expand_Interface_Conversion --
741 ---------------------------------
743 procedure Expand_Interface_Conversion (N : Node_Id) is
744 Loc : constant Source_Ptr := Sloc (N);
745 Operand : constant Node_Id := Expression (N);
746 Operand_Typ : Entity_Id := Etype (Operand);
747 Target_Type : Entity_Id := Etype (N);
748 Iface_Tag : Entity_Id;
751 pragma Assert (Nkind (Operand) /= N_Attribute_Reference);
753 -- Ada 2005 (AI-345): Set Operand_Typ and Handle task interfaces
755 if Ekind (Operand_Typ) = E_Task_Type
756 or else Ekind (Operand_Typ) = E_Protected_Type
758 Operand_Typ := Corresponding_Record_Type (Operand_Typ);
761 if Is_Access_Type (Target_Type) then
762 Target_Type := Etype (Directly_Designated_Type (Target_Type));
764 elsif Is_Class_Wide_Type (Target_Type) then
765 Target_Type := Etype (Target_Type);
768 pragma Assert (not Is_Class_Wide_Type (Target_Type)
769 and then Is_Interface (Target_Type));
771 Iface_Tag := Find_Interface_Tag (Operand_Typ, Target_Type);
773 pragma Assert (Iface_Tag /= Empty);
776 Unchecked_Convert_To (Etype (N),
777 Make_Attribute_Reference (Loc,
778 Prefix => Make_Selected_Component (Loc,
779 Prefix => Relocate_Node (Expression (N)),
780 Selector_Name => New_Occurrence_Of (Iface_Tag, Loc)),
781 Attribute_Name => Name_Address)));
784 end Expand_Interface_Conversion;
786 ------------------------------
787 -- Expand_Interface_Actuals --
788 ------------------------------
790 procedure Expand_Interface_Actuals (Call_Node : Node_Id) is
791 Loc : constant Source_Ptr := Sloc (Call_Node);
793 Actual_Typ : Entity_Id;
794 Conversion : Node_Id;
796 Formal_Typ : Entity_Id;
801 -- This subprogram is called directly from the semantics, so we need a
802 -- check to see whether expansion is active before proceeding.
804 if not Expander_Active then
808 -- Call using access to subprogram with explicit dereference
810 if Nkind (Name (Call_Node)) = N_Explicit_Dereference then
811 Subp := Etype (Name (Call_Node));
816 Subp := Entity (Name (Call_Node));
819 Formal := First_Formal (Subp);
820 Actual := First_Actual (Call_Node);
822 while Present (Formal) loop
824 pragma Assert (Ekind (Etype (Etype (Formal)))
825 /= E_Record_Type_With_Private);
827 -- Ada 2005 (AI-251): Conversion to interface to force "this"
830 Formal_Typ := Etype (Etype (Formal));
831 Actual_Typ := Etype (Actual);
833 if Is_Interface (Formal_Typ) then
835 Conversion := Convert_To (Formal_Typ, New_Copy_Tree (Actual));
836 Rewrite (Actual, Conversion);
837 Analyze_And_Resolve (Actual, Formal_Typ);
840 Make_Explicit_Dereference (Loc,
842 (Build_Anonymous_Access_Type (Formal_Typ, Call_Node),
843 Relocate_Node (Expression (Actual)))));
845 Analyze_And_Resolve (Actual, Formal_Typ);
847 -- Anonymous access type
849 elsif Is_Access_Type (Formal_Typ)
850 and then Is_Interface (Etype
851 (Directly_Designated_Type
853 and then Interface_Present_In_Ancestor
854 (Typ => Etype (Directly_Designated_Type
856 Iface => Etype (Directly_Designated_Type
860 if Nkind (Actual) = N_Attribute_Reference
862 (Attribute_Name (Actual) = Name_Access
863 or else Attribute_Name (Actual) = Name_Unchecked_Access)
865 Nam := Attribute_Name (Actual);
869 (Etype (Directly_Designated_Type (Formal_Typ)),
872 Rewrite (Actual, Conversion);
874 Analyze_And_Resolve (Actual,
875 Etype (Directly_Designated_Type (Formal_Typ)));
878 Unchecked_Convert_To (Formal_Typ,
879 Make_Attribute_Reference (Loc,
881 Relocate_Node (Prefix (Expression (Actual))),
882 Attribute_Name => Nam)));
884 Analyze_And_Resolve (Actual, Formal_Typ);
888 Convert_To (Formal_Typ, New_Copy_Tree (Actual));
889 Rewrite (Actual, Conversion);
890 Analyze_And_Resolve (Actual, Formal_Typ);
894 Next_Actual (Actual);
895 Next_Formal (Formal);
897 end Expand_Interface_Actuals;
899 ----------------------------
900 -- Expand_Interface_Thunk --
901 ----------------------------
903 function Expand_Interface_Thunk
905 Thunk_Id : Entity_Id;
906 Iface_Tag : Entity_Id) return Node_Id
908 Loc : constant Source_Ptr := Sloc (N);
909 Actuals : constant List_Id := New_List;
910 Decl : constant List_Id := New_List;
911 Formals : constant List_Id := New_List;
912 Thunk_Tag : constant Node_Id := Iface_Tag;
913 Thunk_Alias : constant Entity_Id := Alias (Entity (N));
917 New_Formal : Node_Id;
920 Subtyp_Mark : Node_Id;
924 -- Traverse the list of alias to find the final target
926 Target := Thunk_Alias;
928 while Present (Alias (Target)) loop
929 Target := Alias (Target);
932 -- Duplicate the formals
934 Formal := First_Formal (Thunk_Alias);
936 while Present (Formal) loop
937 New_Formal := Copy_Separate_Tree (Parent (Formal));
939 -- Handle the case in which the subprogram covering
940 -- the interface has been inherited:
943 -- type I is interface;
944 -- procedure P (X : in I) is abstract;
946 -- type T is tagged null record;
947 -- procedure P (X : T);
949 -- type DT is new T and I with ...
951 if Is_Controlling_Formal (Formal) then
952 Set_Parameter_Type (New_Formal,
953 New_Reference_To (Etype (First_Entity (Entity (N))), Loc));
955 -- Why is this line silently commented out ???
957 -- New_Reference_To (Etype (Formal), Loc));
960 Append_To (Formals, New_Formal);
961 Next_Formal (Formal);
964 if Ekind (First_Formal (Thunk_Alias)) = E_In_Parameter
965 and then Ekind (Etype (First_Formal (Thunk_Alias)))
966 = E_Anonymous_Access_Type
971 -- type T is access all <<type of the first formal>>
972 -- S1 := Storage_Offset!(First_formal)
973 -- - Storage_Offset!(First_Formal.Thunk_Tag'Position)
975 -- ... and the first actual of the call is generated as T!(S1)
978 Make_Full_Type_Declaration (Loc,
979 Defining_Identifier =>
980 Make_Defining_Identifier (Loc,
981 New_Internal_Name ('T')),
983 Make_Access_To_Object_Definition (Loc,
985 Null_Exclusion_Present => False,
986 Constant_Present => False,
987 Subtype_Indication =>
989 (Directly_Designated_Type
990 (Etype (First_Formal (Thunk_Alias))), Loc)
994 Make_Object_Declaration (Loc,
995 Defining_Identifier =>
996 Make_Defining_Identifier (Loc,
997 New_Internal_Name ('S')),
998 Constant_Present => True,
1000 New_Reference_To (RTE (RE_Storage_Offset), Loc),
1002 Make_Op_Subtract (Loc,
1004 Unchecked_Convert_To
1005 (RTE (RE_Storage_Offset),
1007 (Defining_Identifier (First (Formals)), Loc)),
1009 Unchecked_Convert_To
1010 (RTE (RE_Storage_Offset),
1011 Make_Attribute_Reference (Loc,
1013 Make_Selected_Component (Loc,
1016 (Defining_Identifier (First (Formals)), Loc),
1018 New_Occurrence_Of (Thunk_Tag, Loc)),
1019 Attribute_Name => Name_Position))));
1021 Append_To (Decl, Decl_2);
1022 Append_To (Decl, Decl_1);
1024 -- Reference the new first actual
1027 Unchecked_Convert_To
1028 (Defining_Identifier (Decl_2),
1029 New_Reference_To (Defining_Identifier (Decl_1), Loc)));
1031 -- Side note: The reverse order of declarations is just to ensure
1032 -- that the call to RE_Print is correct.
1037 -- S1 := Storage_Offset!(First_formal'Address)
1038 -- - Storage_Offset!(First_Formal.Thunk_Tag'Position)
1039 -- S2 := Tag_Ptr!(S3)
1042 Make_Object_Declaration (Loc,
1043 Defining_Identifier =>
1044 Make_Defining_Identifier (Loc, New_Internal_Name ('S')),
1045 Constant_Present => True,
1046 Object_Definition =>
1047 New_Reference_To (RTE (RE_Storage_Offset), Loc),
1049 Make_Op_Subtract (Loc,
1051 Unchecked_Convert_To
1052 (RTE (RE_Storage_Offset),
1053 Make_Attribute_Reference (Loc,
1056 (Defining_Identifier (First (Formals)), Loc),
1057 Attribute_Name => Name_Address)),
1059 Unchecked_Convert_To
1060 (RTE (RE_Storage_Offset),
1061 Make_Attribute_Reference (Loc,
1063 Make_Selected_Component (Loc,
1066 (Defining_Identifier (First (Formals)), Loc),
1068 New_Occurrence_Of (Thunk_Tag, Loc)),
1069 Attribute_Name => Name_Position))));
1072 Make_Object_Declaration (Loc,
1073 Defining_Identifier =>
1074 Make_Defining_Identifier (Loc, New_Internal_Name ('S')),
1075 Constant_Present => True,
1076 Object_Definition => New_Reference_To (RTE (RE_Addr_Ptr), Loc),
1078 Unchecked_Convert_To
1080 New_Reference_To (Defining_Identifier (Decl_1), Loc)));
1082 Append_To (Decl, Decl_1);
1083 Append_To (Decl, Decl_2);
1085 -- Reference the new first actual
1088 Unchecked_Convert_To
1089 (Etype (First_Entity (Target)),
1090 Make_Explicit_Dereference (Loc,
1091 New_Reference_To (Defining_Identifier (Decl_2), Loc))));
1095 Formal := Next (First (Formals));
1096 while Present (Formal) loop
1098 New_Reference_To (Defining_Identifier (Formal), Loc));
1102 if Ekind (Thunk_Alias) = E_Procedure then
1104 Make_Subprogram_Body (Loc,
1106 Make_Procedure_Specification (Loc,
1107 Defining_Unit_Name => Thunk_Id,
1108 Parameter_Specifications => Formals),
1109 Declarations => Decl,
1110 Handled_Statement_Sequence =>
1111 Make_Handled_Sequence_Of_Statements (Loc,
1112 Statements => New_List (
1113 Make_Procedure_Call_Statement (Loc,
1114 Name => New_Occurrence_Of (Target, Loc),
1115 Parameter_Associations => Actuals))));
1117 else pragma Assert (Ekind (Thunk_Alias) = E_Function);
1119 if not Present (Alias (Thunk_Alias)) then
1120 Subtyp_Mark := Subtype_Mark (Parent (Thunk_Alias));
1122 -- The last element in the alias list has the correct subtype_mark
1123 -- of the function result
1126 E : Entity_Id := Alias (Thunk_Alias);
1128 while Present (Alias (E)) loop
1131 Subtyp_Mark := Subtype_Mark (Parent (E));
1136 Make_Subprogram_Body (Loc,
1138 Make_Function_Specification (Loc,
1139 Defining_Unit_Name => Thunk_Id,
1140 Parameter_Specifications => Formals,
1141 Subtype_Mark => New_Copy (Subtyp_Mark)),
1142 Declarations => Decl,
1143 Handled_Statement_Sequence =>
1144 Make_Handled_Sequence_Of_Statements (Loc,
1145 Statements => New_List (
1146 Make_Return_Statement (Loc,
1147 Make_Function_Call (Loc,
1148 Name => New_Occurrence_Of (Target, Loc),
1149 Parameter_Associations => Actuals)))));
1153 Insert_After (N, New_Code);
1155 end Expand_Interface_Thunk;
1161 function Fill_DT_Entry
1164 Thunk_Id : Entity_Id := Empty) return Node_Id
1166 Typ : constant Entity_Id := Scope (DTC_Entity (Prim));
1167 DT_Ptr : Entity_Id := Node (First_Elmt (Access_Disp_Table (Typ)));
1169 Tag : Entity_Id := First_Tag_Component (Typ);
1170 Prim_Op : Entity_Id := Prim;
1173 -- Ada 2005 (AI-251): If we have a thunk available then generate code
1174 -- that saves its address in the secondary dispatch table of its
1175 -- abstract interface; otherwise save the address of the primitive
1176 -- subprogram in the main virtual table.
1178 if Thunk_Id /= Empty then
1184 -- Ada 2005 (AI-251): If the subprogram is the alias of an abstract
1185 -- interface subprogram then find the correct dispatch table pointer
1187 if Present (Abstract_Interface_Alias (Prim)) then
1188 Prim_Op := Abstract_Interface_Alias (Prim);
1190 DT_Ptr := Find_Interface_ADT
1192 Iface => Scope (DTC_Entity (Prim_Op)));
1194 Tag := First_Tag_Component (Scope (DTC_Entity (Prim_Op)));
1197 pragma Assert (DT_Position (Prim_Op) <= DT_Entry_Count (Tag));
1198 pragma Assert (DT_Position (Prim_Op) > Uint_0);
1201 Make_DT_Access_Action (Typ,
1202 Action => Set_Prim_Op_Address,
1204 Unchecked_Convert_To (RTE (RE_Tag),
1205 New_Reference_To (DT_Ptr, Loc)), -- DTptr
1207 Make_Integer_Literal (Loc, DT_Position (Prim_Op)), -- Position
1209 Make_Attribute_Reference (Loc, -- Value
1210 Prefix => New_Reference_To (Target, Loc),
1211 Attribute_Name => Name_Address)));
1214 ---------------------------
1215 -- Get_Remotely_Callable --
1216 ---------------------------
1218 function Get_Remotely_Callable (Obj : Node_Id) return Node_Id is
1219 Loc : constant Source_Ptr := Sloc (Obj);
1222 return Make_DT_Access_Action
1223 (Typ => Etype (Obj),
1224 Action => Get_Remotely_Callable,
1226 Make_Selected_Component (Loc,
1228 Selector_Name => Make_Identifier (Loc, Name_uTag))));
1229 end Get_Remotely_Callable;
1235 function Make_DT (Typ : Entity_Id) return List_Id is
1236 Loc : constant Source_Ptr := Sloc (Typ);
1237 Result : constant List_Id := New_List;
1238 Elab_Code : constant List_Id := New_List;
1240 Tname : constant Name_Id := Chars (Typ);
1241 Name_DT : constant Name_Id := New_External_Name (Tname, 'T');
1242 Name_DT_Ptr : constant Name_Id := New_External_Name (Tname, 'P');
1243 Name_TSD : constant Name_Id := New_External_Name (Tname, 'B');
1244 Name_Exname : constant Name_Id := New_External_Name (Tname, 'E');
1245 Name_No_Reg : constant Name_Id := New_External_Name (Tname, 'F');
1247 DT : constant Node_Id := Make_Defining_Identifier (Loc, Name_DT);
1248 DT_Ptr : constant Node_Id := Make_Defining_Identifier (Loc, Name_DT_Ptr);
1249 TSD : constant Node_Id := Make_Defining_Identifier (Loc, Name_TSD);
1250 Exname : constant Node_Id := Make_Defining_Identifier (Loc, Name_Exname);
1251 No_Reg : constant Node_Id := Make_Defining_Identifier (Loc, Name_No_Reg);
1253 Generalized_Tag : constant Entity_Id := RTE (RE_Tag);
1255 Size_Expr_Node : Node_Id;
1260 TSD_Num_Entries : Int;
1261 Typ_Copy : constant Entity_Id := New_Copy (Typ);
1265 if not RTE_Available (RE_Tag) then
1266 Error_Msg_CRT ("tagged types", Typ);
1270 -- Collect the full list of directly and indirectly implemented
1273 Set_Parent (Typ_Copy, Parent (Typ));
1274 Set_Abstract_Interfaces (Typ_Copy, New_Elmt_List);
1275 Collect_All_Interfaces (Typ_Copy);
1277 -- Calculate the number of entries required in the table of interfaces
1280 AI := First_Elmt (Abstract_Interfaces (Typ_Copy));
1282 while Present (AI) loop
1283 Num_Ifaces := Num_Ifaces + 1;
1287 -- Count ancestors to compute the inheritance depth. For private
1288 -- extensions, always go to the full view in order to compute the real
1289 -- inheritance depth.
1292 Parent_Type : Entity_Id := Typ;
1299 P := Etype (Parent_Type);
1301 if Is_Private_Type (P) then
1302 P := Full_View (Base_Type (P));
1305 exit when P = Parent_Type;
1307 I_Depth := I_Depth + 1;
1312 TSD_Num_Entries := I_Depth + Num_Ifaces + 1;
1313 Nb_Prim := UI_To_Int (DT_Entry_Count (First_Tag_Component (Typ)));
1315 -- ----------------------------------------------------------------
1317 -- Dispatch table and related entities are allocated statically
1319 Set_Ekind (DT, E_Variable);
1320 Set_Is_Statically_Allocated (DT);
1322 Set_Ekind (DT_Ptr, E_Variable);
1323 Set_Is_Statically_Allocated (DT_Ptr);
1325 Set_Ekind (TSD, E_Variable);
1326 Set_Is_Statically_Allocated (TSD);
1328 Set_Ekind (Exname, E_Variable);
1329 Set_Is_Statically_Allocated (Exname);
1331 Set_Ekind (No_Reg, E_Variable);
1332 Set_Is_Statically_Allocated (No_Reg);
1334 -- Generate code to create the storage for the Dispatch_Table object:
1336 -- DT : Storage_Array (1..DT_Prologue_Size+nb_prim*DT_Entry_Size);
1337 -- for DT'Alignment use Address'Alignment
1341 Left_Opnd => Make_DT_Access_Action (Typ, DT_Prologue_Size, No_List),
1343 Make_Op_Multiply (Loc,
1345 Make_DT_Access_Action (Typ, DT_Entry_Size, No_List),
1347 Make_Integer_Literal (Loc, Nb_Prim)));
1350 Make_Object_Declaration (Loc,
1351 Defining_Identifier => DT,
1352 Aliased_Present => True,
1353 Object_Definition =>
1354 Make_Subtype_Indication (Loc,
1355 Subtype_Mark => New_Reference_To (RTE (RE_Storage_Array), Loc),
1356 Constraint => Make_Index_Or_Discriminant_Constraint (Loc,
1357 Constraints => New_List (
1359 Low_Bound => Make_Integer_Literal (Loc, 1),
1360 High_Bound => Size_Expr_Node))))));
1363 Make_Attribute_Definition_Clause (Loc,
1364 Name => New_Reference_To (DT, Loc),
1365 Chars => Name_Alignment,
1367 Make_Attribute_Reference (Loc,
1368 Prefix => New_Reference_To (RTE (RE_Integer_Address), Loc),
1369 Attribute_Name => Name_Alignment)));
1371 -- Generate code to create the pointer to the dispatch table
1373 -- DT_Ptr : Tag := Tag!(DT'Address);
1375 -- According to the C++ ABI, the base of the vtable is located after a
1376 -- prologue containing Offset_To_Top, and Typeinfo_Ptr. Hence, we move
1377 -- down the pointer to the real base of the vtable
1380 Make_Object_Declaration (Loc,
1381 Defining_Identifier => DT_Ptr,
1382 Constant_Present => True,
1383 Object_Definition => New_Reference_To (Generalized_Tag, Loc),
1385 Unchecked_Convert_To (Generalized_Tag,
1388 Unchecked_Convert_To (RTE (RE_Storage_Offset),
1389 Make_Attribute_Reference (Loc,
1390 Prefix => New_Reference_To (DT, Loc),
1391 Attribute_Name => Name_Address)),
1393 Make_DT_Access_Action (Typ,
1394 DT_Prologue_Size, No_List)))));
1396 -- Generate code to define the boolean that controls registration, in
1397 -- order to avoid multiple registrations for tagged types defined in
1398 -- multiple-called scopes
1401 Make_Object_Declaration (Loc,
1402 Defining_Identifier => No_Reg,
1403 Object_Definition => New_Reference_To (Standard_Boolean, Loc),
1404 Expression => New_Reference_To (Standard_True, Loc)));
1406 -- Set Access_Disp_Table field to be the dispatch table pointer
1408 if not Present (Access_Disp_Table (Typ)) then
1409 Set_Access_Disp_Table (Typ, New_Elmt_List);
1412 Prepend_Elmt (DT_Ptr, Access_Disp_Table (Typ));
1414 -- Generate code to create the storage for the type specific data object
1415 -- with enough space to store the tags of the ancestors plus the tags
1416 -- of all the implemented interfaces (as described in a-tags.adb)
1418 -- TSD: Storage_Array
1419 -- (1..TSD_Prologue_Size+TSD_Num_Entries*TSD_Entry_Size);
1420 -- for TSD'Alignment use Address'Alignment
1425 Make_DT_Access_Action (Typ, TSD_Prologue_Size, No_List),
1427 Make_Op_Multiply (Loc,
1429 Make_DT_Access_Action (Typ, TSD_Entry_Size, No_List),
1431 Make_Integer_Literal (Loc, TSD_Num_Entries)));
1434 Make_Object_Declaration (Loc,
1435 Defining_Identifier => TSD,
1436 Aliased_Present => True,
1437 Object_Definition =>
1438 Make_Subtype_Indication (Loc,
1439 Subtype_Mark => New_Reference_To (RTE (RE_Storage_Array), Loc),
1440 Constraint => Make_Index_Or_Discriminant_Constraint (Loc,
1441 Constraints => New_List (
1443 Low_Bound => Make_Integer_Literal (Loc, 1),
1444 High_Bound => Size_Expr_Node))))));
1447 Make_Attribute_Definition_Clause (Loc,
1448 Name => New_Reference_To (TSD, Loc),
1449 Chars => Name_Alignment,
1451 Make_Attribute_Reference (Loc,
1452 Prefix => New_Reference_To (RTE (RE_Integer_Address), Loc),
1453 Attribute_Name => Name_Alignment)));
1455 -- Generate code to put the Address of the TSD in the dispatch table
1456 -- Set_TSD (DT_Ptr, TSD);
1458 Append_To (Elab_Code,
1459 Make_DT_Access_Action (Typ,
1462 New_Reference_To (DT_Ptr, Loc), -- DTptr
1463 Make_Attribute_Reference (Loc, -- Value
1464 Prefix => New_Reference_To (TSD, Loc),
1465 Attribute_Name => Name_Address))));
1467 -- Generate: Exname : constant String := full_qualified_name (typ);
1468 -- The type itself may be an anonymous parent type, so use the first
1469 -- subtype to have a user-recognizable name.
1472 Make_Object_Declaration (Loc,
1473 Defining_Identifier => Exname,
1474 Constant_Present => True,
1475 Object_Definition => New_Reference_To (Standard_String, Loc),
1477 Make_String_Literal (Loc,
1478 Full_Qualified_Name (First_Subtype (Typ)))));
1480 -- Generate: Set_Expanded_Name (DT_Ptr, exname'Address);
1482 Append_To (Elab_Code,
1483 Make_DT_Access_Action (Typ,
1484 Action => Set_Expanded_Name,
1486 Node1 => New_Reference_To (DT_Ptr, Loc),
1488 Make_Attribute_Reference (Loc,
1489 Prefix => New_Reference_To (Exname, Loc),
1490 Attribute_Name => Name_Address))));
1492 -- Generate: Set_Access_Level (DT_Ptr, <type's accessibility level>);
1494 Append_To (Elab_Code,
1495 Make_DT_Access_Action (Typ,
1496 Action => Set_Access_Level,
1498 Node1 => New_Reference_To (DT_Ptr, Loc),
1499 Node2 => Make_Integer_Literal (Loc, Type_Access_Level (Typ)))));
1502 -- Set_Offset_To_Top (DT_Ptr, 0);
1504 Append_To (Elab_Code,
1505 Make_Procedure_Call_Statement (Loc,
1506 Name => New_Reference_To (RTE (RE_Set_Offset_To_Top), Loc),
1507 Parameter_Associations => New_List (
1508 New_Reference_To (DT_Ptr, Loc),
1509 Make_Integer_Literal (Loc, Uint_0))));
1511 if Typ = Etype (Typ)
1512 or else Is_CPP_Class (Etype (Typ))
1515 Unchecked_Convert_To (Generalized_Tag,
1516 Make_Integer_Literal (Loc, 0));
1518 Unchecked_Convert_To (Generalized_Tag,
1519 Make_Integer_Literal (Loc, 0));
1524 (Node (First_Elmt (Access_Disp_Table (Etype (Typ)))), Loc);
1527 (Node (First_Elmt (Access_Disp_Table (Etype (Typ)))), Loc);
1530 -- Generate: Inherit_DT (parent'tag, DT_Ptr, nb_prim of parent);
1532 Append_To (Elab_Code,
1533 Make_DT_Access_Action (Typ,
1534 Action => Inherit_DT,
1537 Node2 => New_Reference_To (DT_Ptr, Loc),
1538 Node3 => Make_Integer_Literal (Loc,
1539 DT_Entry_Count (First_Tag_Component (Etype (Typ)))))));
1541 -- Generate: Inherit_TSD (parent'tag, DT_Ptr);
1543 Append_To (Elab_Code,
1544 Make_DT_Access_Action (Typ,
1545 Action => Inherit_TSD,
1548 Node2 => New_Reference_To (DT_Ptr, Loc))));
1550 -- for types with no controlled components
1551 -- Generate: Set_RC_Offset (DT_Ptr, 0);
1552 -- for simple types with controlled components
1553 -- Generate: Set_RC_Offset (DT_Ptr, type._record_controller'position);
1554 -- for complex types with controlled components where the position
1555 -- of the record controller is not statically computable, if there are
1556 -- controlled components at this level
1557 -- Generate: Set_RC_Offset (DT_Ptr, -1);
1558 -- to indicate that the _controller field is right after the _parent or
1559 -- if there are no controlled components at this level,
1560 -- Generate: Set_RC_Offset (DT_Ptr, -2);
1561 -- to indicate that we need to get the position from the parent.
1567 if not Has_Controlled_Component (Typ) then
1568 Position := Make_Integer_Literal (Loc, 0);
1570 elsif Etype (Typ) /= Typ and then Has_Discriminants (Etype (Typ)) then
1571 if Has_New_Controlled_Component (Typ) then
1572 Position := Make_Integer_Literal (Loc, -1);
1574 Position := Make_Integer_Literal (Loc, -2);
1578 Make_Attribute_Reference (Loc,
1580 Make_Selected_Component (Loc,
1581 Prefix => New_Reference_To (Typ, Loc),
1583 New_Reference_To (Controller_Component (Typ), Loc)),
1584 Attribute_Name => Name_Position);
1586 -- This is not proper Ada code to use the attribute 'Position
1587 -- on something else than an object but this is supported by
1588 -- the back end (see comment on the Bit_Component attribute in
1589 -- sem_attr). So we avoid semantic checking here.
1591 Set_Analyzed (Position);
1592 Set_Etype (Prefix (Position), RTE (RE_Record_Controller));
1593 Set_Etype (Prefix (Prefix (Position)), Typ);
1594 Set_Etype (Selector_Name (Prefix (Position)),
1595 RTE (RE_Record_Controller));
1596 Set_Etype (Position, RTE (RE_Storage_Offset));
1599 Append_To (Elab_Code,
1600 Make_DT_Access_Action (Typ,
1601 Action => Set_RC_Offset,
1603 Node1 => New_Reference_To (DT_Ptr, Loc),
1604 Node2 => Position)));
1607 -- Generate: Set_Remotely_Callable (DT_Ptr, Status);
1608 -- where Status is described in E.4 (18)
1617 or else Is_Shared_Passive (Typ)
1619 ((Is_Remote_Types (Typ)
1620 or else Is_Remote_Call_Interface (Typ))
1621 and then Original_View_In_Visible_Part (Typ))
1622 or else not Comes_From_Source (Typ));
1624 Append_To (Elab_Code,
1625 Make_DT_Access_Action (Typ,
1626 Action => Set_Remotely_Callable,
1628 New_Occurrence_Of (DT_Ptr, Loc),
1629 New_Occurrence_Of (Status, Loc))));
1632 -- Generate: Set_External_Tag (DT_Ptr, exname'Address);
1633 -- Should be the external name not the qualified name???
1635 if not Has_External_Tag_Rep_Clause (Typ) then
1636 Append_To (Elab_Code,
1637 Make_DT_Access_Action (Typ,
1638 Action => Set_External_Tag,
1640 Node1 => New_Reference_To (DT_Ptr, Loc),
1642 Make_Attribute_Reference (Loc,
1643 Prefix => New_Reference_To (Exname, Loc),
1644 Attribute_Name => Name_Address))));
1646 -- Generate code to register the Tag in the External_Tag hash
1647 -- table for the pure Ada type only.
1649 -- Register_Tag (Dt_Ptr);
1651 -- Skip this if routine not available, or in No_Run_Time mode
1653 if RTE_Available (RE_Register_Tag)
1654 and then Is_RTE (Generalized_Tag, RE_Tag)
1655 and then not No_Run_Time_Mode
1657 Append_To (Elab_Code,
1658 Make_Procedure_Call_Statement (Loc,
1659 Name => New_Reference_To (RTE (RE_Register_Tag), Loc),
1660 Parameter_Associations =>
1661 New_List (New_Reference_To (DT_Ptr, Loc))));
1671 Append_To (Elab_Code,
1672 Make_Assignment_Statement (Loc,
1673 Name => New_Reference_To (No_Reg, Loc),
1674 Expression => New_Reference_To (Standard_False, Loc)));
1677 Make_Implicit_If_Statement (Typ,
1678 Condition => New_Reference_To (No_Reg, Loc),
1679 Then_Statements => Elab_Code));
1681 -- Ada 2005 (AI-251): Register the tag of the interfaces into
1682 -- the table of implemented interfaces
1684 if Present (Abstract_Interfaces (Typ))
1685 and then not Is_Empty_Elmt_List (Abstract_Interfaces (Typ))
1687 AI := First_Elmt (Abstract_Interfaces (Typ_Copy));
1688 while Present (AI) loop
1691 -- Register_Interface (DT_Ptr, Interface'Tag);
1694 Make_DT_Access_Action (Typ,
1695 Action => Register_Interface_Tag,
1697 Node1 => New_Reference_To (DT_Ptr, Loc),
1698 Node2 => New_Reference_To
1701 (Access_Disp_Table (Node (AI)))),
1711 --------------------------------
1712 -- Make_Abstract_Interface_DT --
1713 --------------------------------
1715 procedure Make_Abstract_Interface_DT
1716 (AI_Tag : Entity_Id;
1717 Acc_Disp_Tables : in out Elist_Id;
1718 Result : out List_Id)
1720 Loc : constant Source_Ptr := Sloc (AI_Tag);
1721 Tname : constant Name_Id := Chars (AI_Tag);
1722 Name_DT : constant Name_Id := New_External_Name (Tname, 'T');
1723 Name_DT_Ptr : constant Name_Id := New_External_Name (Tname, 'P');
1725 Iface_DT : constant Node_Id :=
1726 Make_Defining_Identifier (Loc, Name_DT);
1727 Iface_DT_Ptr : constant Node_Id :=
1728 Make_Defining_Identifier (Loc, Name_DT_Ptr);
1730 Generalized_Tag : constant Entity_Id := RTE (RE_Interface_Tag);
1731 Size_Expr_Node : Node_Id;
1737 -- Dispatch table and related entities are allocated statically
1739 Set_Ekind (Iface_DT, E_Variable);
1740 Set_Is_Statically_Allocated (Iface_DT);
1742 Set_Ekind (Iface_DT_Ptr, E_Variable);
1743 Set_Is_Statically_Allocated (Iface_DT_Ptr);
1745 -- Generate code to create the storage for the Dispatch_Table object
1747 -- DT : Storage_Array (1..DT_Prologue_Size+nb_prim*DT_Entry_Size);
1748 -- for DT'Alignment use Address'Alignment
1750 Nb_Prim := UI_To_Int (DT_Entry_Count (AI_Tag));
1754 Left_Opnd => Make_DT_Access_Action (Etype (AI_Tag),
1758 Make_Op_Multiply (Loc,
1760 Make_DT_Access_Action (Etype (AI_Tag),
1764 Make_Integer_Literal (Loc, Nb_Prim)));
1767 Make_Object_Declaration (Loc,
1768 Defining_Identifier => Iface_DT,
1769 Aliased_Present => True,
1770 Object_Definition =>
1771 Make_Subtype_Indication (Loc,
1772 Subtype_Mark => New_Reference_To (RTE (RE_Storage_Array), Loc),
1773 Constraint => Make_Index_Or_Discriminant_Constraint (Loc,
1774 Constraints => New_List (
1776 Low_Bound => Make_Integer_Literal (Loc, 1),
1777 High_Bound => Size_Expr_Node)))),
1779 -- Initialize the signature of the interface tag. It is currently
1780 -- a sequence of four bytes located in the unused Typeinfo_Ptr
1781 -- field of the prologue). Its current value is the following
1782 -- sequence: (80, Nb_Prim, 0, 80)
1785 Make_Aggregate (Loc,
1786 Component_Associations => New_List (
1787 Make_Component_Association (Loc,
1791 Choices => New_List (
1792 Make_Integer_Literal (Loc, Uint_5),
1793 Make_Integer_Literal (Loc, Uint_8)),
1795 Make_Integer_Literal (Loc, Uint_80)),
1797 Make_Component_Association (Loc,
1798 Choices => New_List (
1799 Make_Integer_Literal (Loc, Uint_2)),
1801 Make_Integer_Literal (Loc, Nb_Prim)),
1803 Make_Component_Association (Loc,
1804 Choices => New_List (
1805 Make_Others_Choice (Loc)),
1806 Expression => Make_Integer_Literal (Loc, Uint_0))))));
1809 Make_Attribute_Definition_Clause (Loc,
1810 Name => New_Reference_To (Iface_DT, Loc),
1811 Chars => Name_Alignment,
1813 Make_Attribute_Reference (Loc,
1814 Prefix => New_Reference_To (RTE (RE_Integer_Address), Loc),
1815 Attribute_Name => Name_Alignment)));
1817 -- Generate code to create the pointer to the dispatch table
1819 -- Iface_DT_Ptr : Tag := Tag!(DT'Address);
1821 -- According to the C++ ABI, the base of the vtable is located
1822 -- after the following prologue: Offset_To_Top, and Typeinfo_Ptr.
1823 -- Hence, move the pointer down to the real base of the vtable.
1826 Make_Object_Declaration (Loc,
1827 Defining_Identifier => Iface_DT_Ptr,
1828 Constant_Present => True,
1829 Object_Definition => New_Reference_To (Generalized_Tag, Loc),
1831 Unchecked_Convert_To (Generalized_Tag,
1834 Unchecked_Convert_To (RTE (RE_Storage_Offset),
1835 Make_Attribute_Reference (Loc,
1836 Prefix => New_Reference_To (Iface_DT, Loc),
1837 Attribute_Name => Name_Address)),
1839 Make_DT_Access_Action (Etype (AI_Tag),
1840 DT_Prologue_Size, No_List)))));
1842 -- Note: Offset_To_Top will be initialized by the init subprogram
1844 -- Set Access_Disp_Table field to be the dispatch table pointer
1846 if not (Present (Acc_Disp_Tables)) then
1847 Acc_Disp_Tables := New_Elmt_List;
1850 Append_Elmt (Iface_DT_Ptr, Acc_Disp_Tables);
1852 end Make_Abstract_Interface_DT;
1854 ---------------------------
1855 -- Make_DT_Access_Action --
1856 ---------------------------
1858 function Make_DT_Access_Action
1860 Action : DT_Access_Action;
1861 Args : List_Id) return Node_Id
1863 Action_Name : constant Entity_Id := RTE (Ada_Actions (Action));
1869 -- This is a constant
1871 return New_Reference_To (Action_Name, Sloc (Typ));
1874 pragma Assert (List_Length (Args) = Action_Nb_Arg (Action));
1876 Loc := Sloc (First (Args));
1878 if Action_Is_Proc (Action) then
1880 Make_Procedure_Call_Statement (Loc,
1881 Name => New_Reference_To (Action_Name, Loc),
1882 Parameter_Associations => Args);
1886 Make_Function_Call (Loc,
1887 Name => New_Reference_To (Action_Name, Loc),
1888 Parameter_Associations => Args);
1890 end Make_DT_Access_Action;
1892 -----------------------------------
1893 -- Original_View_In_Visible_Part --
1894 -----------------------------------
1896 function Original_View_In_Visible_Part (Typ : Entity_Id) return Boolean is
1897 Scop : constant Entity_Id := Scope (Typ);
1900 -- The scope must be a package
1902 if Ekind (Scop) /= E_Package
1903 and then Ekind (Scop) /= E_Generic_Package
1908 -- A type with a private declaration has a private view declared in
1909 -- the visible part.
1911 if Has_Private_Declaration (Typ) then
1915 return List_Containing (Parent (Typ)) =
1916 Visible_Declarations (Specification (Unit_Declaration_Node (Scop)));
1917 end Original_View_In_Visible_Part;
1919 -------------------------
1920 -- Set_All_DT_Position --
1921 -------------------------
1923 procedure Set_All_DT_Position (Typ : Entity_Id) is
1924 Parent_Typ : constant Entity_Id := Etype (Typ);
1925 Root_Typ : constant Entity_Id := Root_Type (Typ);
1926 First_Prim : constant Elmt_Id := First_Elmt (Primitive_Operations (Typ));
1927 The_Tag : constant Entity_Id := First_Tag_Component (Typ);
1929 Adjusted : Boolean := False;
1930 Finalized : Boolean := False;
1937 Prim_Elmt : Elmt_Id;
1939 procedure Validate_Position (Prim : Entity_Id);
1940 -- Check that the position assignated to Prim is completely safe
1941 -- (it has not been assigned to a previously defined primitive
1942 -- operation of Typ)
1944 -----------------------
1945 -- Validate_Position --
1946 -----------------------
1948 procedure Validate_Position (Prim : Entity_Id) is
1949 Prim_Elmt : Elmt_Id;
1951 Prim_Elmt := First_Elmt (Primitive_Operations (Typ));
1952 while Present (Prim_Elmt)
1953 and then Node (Prim_Elmt) /= Prim
1955 -- Primitive operations covering abstract interfaces are
1958 if Present (Abstract_Interface_Alias (Node (Prim_Elmt))) then
1961 -- Predefined dispatching operations are completely safe.
1962 -- They are allocated at fixed positions.
1964 elsif Is_Predefined_Dispatching_Operation (Node (Prim_Elmt)) then
1967 -- Aliased subprograms are safe
1969 elsif Present (Alias (Prim)) then
1972 elsif DT_Position (Node (Prim_Elmt)) = DT_Position (Prim) then
1973 raise Program_Error;
1976 Next_Elmt (Prim_Elmt);
1978 end Validate_Position;
1980 -- Start of processing for Set_All_DT_Position
1983 -- Get Entry_Count of the parent
1985 if Parent_Typ /= Typ
1986 and then DT_Entry_Count (First_Tag_Component (Parent_Typ)) /= No_Uint
1988 Parent_EC := UI_To_Int (DT_Entry_Count
1989 (First_Tag_Component (Parent_Typ)));
1994 -- C++ Case, check that pragma CPP_Class, CPP_Virtual and CPP_Vtable
1995 -- give a coherent set of information
1997 if Is_CPP_Class (Root_Typ) then
1999 -- Compute the number of primitive operations in the main Vtable
2000 -- Set their position:
2001 -- - where it was set if overriden or inherited
2002 -- - after the end of the parent vtable otherwise
2004 Prim_Elmt := First_Prim;
2006 while Present (Prim_Elmt) loop
2007 Prim := Node (Prim_Elmt);
2009 if not Is_CPP_Class (Typ) then
2010 Set_DTC_Entity (Prim, The_Tag);
2012 elsif Present (Alias (Prim)) then
2013 Set_DTC_Entity (Prim, DTC_Entity (Alias (Prim)));
2014 Set_DT_Position (Prim, DT_Position (Alias (Prim)));
2016 elsif No (DTC_Entity (Prim)) and then Is_CPP_Class (Typ) then
2017 Error_Msg_NE ("is a primitive operation of&," &
2018 " pragma Cpp_Virtual required", Prim, Typ);
2021 if DTC_Entity (Prim) = The_Tag then
2023 -- Get the slot from the parent subprogram if any
2026 H : Entity_Id := Homonym (Prim);
2029 while Present (H) loop
2030 if Present (DTC_Entity (H))
2031 and then Root_Type (Scope (DTC_Entity (H))) = Root_Typ
2033 Set_DT_Position (Prim, DT_Position (H));
2041 -- Otherwise take the canonical slot after the end of the
2044 if DT_Position (Prim) = No_Uint then
2045 Nb_Prim := Nb_Prim + 1;
2046 Set_DT_Position (Prim, UI_From_Int (Parent_EC + Nb_Prim));
2048 elsif UI_To_Int (DT_Position (Prim)) > Parent_EC then
2049 Nb_Prim := Nb_Prim + 1;
2053 Next_Elmt (Prim_Elmt);
2056 -- Check that the declared size of the Vtable is bigger or equal
2057 -- than the number of primitive operations (if bigger it means that
2058 -- some of the c++ virtual functions were not imported, that is
2061 if DT_Entry_Count (The_Tag) = No_Uint
2062 or else not Is_CPP_Class (Typ)
2064 Set_DT_Entry_Count (The_Tag, UI_From_Int (Parent_EC + Nb_Prim));
2066 elsif UI_To_Int (DT_Entry_Count (The_Tag)) < Parent_EC + Nb_Prim then
2067 Error_Msg_N ("not enough room in the Vtable for all virtual"
2068 & " functions", The_Tag);
2071 -- Check that Positions are not duplicate nor outside the range of
2075 Size : constant Int := UI_To_Int (DT_Entry_Count (The_Tag));
2077 Prim_Pos_Table : array (1 .. Size) of Entity_Id :=
2081 Prim_Elmt := First_Prim;
2082 while Present (Prim_Elmt) loop
2083 Prim := Node (Prim_Elmt);
2085 if DTC_Entity (Prim) = The_Tag then
2086 Pos := UI_To_Int (DT_Position (Prim));
2088 if Pos not in Prim_Pos_Table'Range then
2090 ("position not in range of virtual table", Prim);
2092 elsif Present (Prim_Pos_Table (Pos)) then
2093 Error_Msg_NE ("cannot be at the same position in the"
2094 & " vtable than&", Prim, Prim_Pos_Table (Pos));
2097 Prim_Pos_Table (Pos) := Prim;
2101 Next_Elmt (Prim_Elmt);
2105 -- For regular Ada tagged types, just set the DT_Position for
2106 -- each primitive operation. Perform some sanity checks to avoid
2107 -- to build completely inconsistant dispatch tables.
2109 -- Note that the _Size primitive is always set at position 1 in order
2110 -- to comply with the needs of Ada.Tags.Parent_Size (see documentation
2114 -- First stage: Set the DTC entity of all the primitive operations
2115 -- This is required to properly read the DT_Position attribute in
2116 -- the latter stages.
2118 Prim_Elmt := First_Prim;
2120 while Present (Prim_Elmt) loop
2121 Count_Prim := Count_Prim + 1;
2122 Prim := Node (Prim_Elmt);
2124 -- Ada 2005 (AI-251)
2126 if Present (Abstract_Interface_Alias (Prim)) then
2127 Set_DTC_Entity (Prim,
2130 Iface => Scope (DTC_Entity
2131 (Abstract_Interface_Alias (Prim)))));
2134 Set_DTC_Entity (Prim, The_Tag);
2137 -- Clear any previous value of the DT_Position attribute. In this
2138 -- way we ensure that the final position of all the primitives is
2139 -- stablished by the following stages of this algorithm.
2141 Set_DT_Position (Prim, No_Uint);
2143 Next_Elmt (Prim_Elmt);
2147 Fixed_Prim : array (Int range 0 .. 10 + Parent_EC + Count_Prim)
2148 of Boolean := (others => False);
2152 -- Second stage: Register fixed entries
2155 Prim_Elmt := First_Prim;
2157 while Present (Prim_Elmt) loop
2158 Prim := Node (Prim_Elmt);
2160 -- Predefined primitives have a fixed position in all the
2163 if Is_Predefined_Dispatching_Operation (Prim) then
2164 Set_DT_Position (Prim, Default_Prim_Op_Position (Prim));
2165 Fixed_Prim (UI_To_Int (DT_Position (Prim))) := True;
2167 -- Overriding interface primitives of an ancestor
2169 elsif DT_Position (Prim) = No_Uint
2170 and then Present (Abstract_Interface_Alias (Prim))
2171 and then Present (DTC_Entity
2172 (Abstract_Interface_Alias (Prim)))
2173 and then DT_Position (Abstract_Interface_Alias (Prim))
2175 and then Is_Inherited_Operation (Prim)
2176 and then Is_Ancestor (Scope
2178 (Abstract_Interface_Alias (Prim))),
2181 Set_DT_Position (Prim,
2182 DT_Position (Abstract_Interface_Alias (Prim)));
2183 Set_DT_Position (Alias (Prim),
2184 DT_Position (Abstract_Interface_Alias (Prim)));
2185 Fixed_Prim (UI_To_Int (DT_Position (Prim))) := True;
2187 -- Overriding primitives must use the same entry as the
2188 -- overriden primitive
2190 elsif DT_Position (Prim) = No_Uint
2191 and then Present (Alias (Prim))
2192 and then Present (DTC_Entity (Alias (Prim)))
2193 and then DT_Position (Alias (Prim)) /= No_Uint
2194 and then Is_Inherited_Operation (Prim)
2195 and then Is_Ancestor (Scope (DTC_Entity (Alias (Prim))), Typ)
2198 while not (Present (DTC_Entity (E))
2199 or else DT_Position (E) = No_Uint)
2200 and then Present (Alias (E))
2205 pragma Assert (Present (DTC_Entity (E))
2207 DT_Position (E) /= No_Uint);
2209 Set_DT_Position (Prim, DT_Position (E));
2210 Fixed_Prim (UI_To_Int (DT_Position (E))) := True;
2212 -- If this is not the last element in the chain continue
2213 -- traversing the chain. This is required to properly
2214 -- handling renamed primitives
2216 if Present (Alias (E)) then
2217 while Present (Alias (E)) loop
2219 Fixed_Prim (UI_To_Int (DT_Position (E))) := True;
2224 Next_Elmt (Prim_Elmt);
2227 -- Third stage: Fix the position of all the new primitives
2228 -- Entries associated with primitives covering interfaces
2229 -- are handled in a latter round.
2231 Prim_Elmt := First_Prim;
2232 while Present (Prim_Elmt) loop
2233 Prim := Node (Prim_Elmt);
2235 -- Skip primitives previously set entries
2237 if DT_Position (Prim) /= No_Uint then
2240 elsif Etype (DTC_Entity (Prim)) /= RTE (RE_Tag) then
2243 -- Primitives covering interface primitives are
2246 elsif Present (Abstract_Interface_Alias (Prim)) then
2250 -- Take the next available position in the DT
2253 Nb_Prim := Nb_Prim + 1;
2254 exit when not Fixed_Prim (Nb_Prim);
2257 Set_DT_Position (Prim, UI_From_Int (Nb_Prim));
2258 Fixed_Prim (Nb_Prim) := True;
2261 Next_Elmt (Prim_Elmt);
2265 -- Fourth stage: Complete the decoration of primitives covering
2266 -- interfaces (that is, propagate the DT_Position attribute
2267 -- from the aliased primitive)
2269 Prim_Elmt := First_Prim;
2270 while Present (Prim_Elmt) loop
2271 Prim := Node (Prim_Elmt);
2273 if DT_Position (Prim) = No_Uint
2274 and then Present (Abstract_Interface_Alias (Prim))
2276 -- Check if this entry will be placed in the primary DT
2278 if Etype (DTC_Entity (Abstract_Interface_Alias (Prim)))
2281 pragma Assert (DT_Position (Alias (Prim)) /= No_Uint);
2282 Set_DT_Position (Prim, DT_Position (Alias (Prim)));
2284 -- Otherwise it will be placed in the secondary DT
2288 (DT_Position (Abstract_Interface_Alias (Prim)) /= No_Uint);
2290 Set_DT_Position (Prim,
2291 DT_Position (Abstract_Interface_Alias (Prim)));
2295 Next_Elmt (Prim_Elmt);
2298 -- Final stage: Ensure that the table is correct plus some further
2299 -- verifications concerning the primitives.
2301 Prim_Elmt := First_Prim;
2304 while Present (Prim_Elmt) loop
2305 Prim := Node (Prim_Elmt);
2307 -- At this point all the primitives MUST have a position
2308 -- in the dispatch table
2310 if DT_Position (Prim) = No_Uint then
2311 raise Program_Error;
2314 -- Calculate real size of the dispatch table
2316 if UI_To_Int (DT_Position (Prim)) > DT_Length then
2317 DT_Length := UI_To_Int (DT_Position (Prim));
2320 -- Ensure that the asignated position in the dispatch
2323 Validate_Position (Prim);
2325 if Chars (Prim) = Name_Finalize then
2329 if Chars (Prim) = Name_Adjust then
2333 -- An abstract operation cannot be declared in the private part
2334 -- for a visible abstract type, because it could never be over-
2335 -- ridden. For explicit declarations this is checked at the
2336 -- point of declaration, but for inherited operations it must
2337 -- be done when building the dispatch table. Input is excluded
2340 if Is_Abstract (Typ)
2341 and then Is_Abstract (Prim)
2342 and then Present (Alias (Prim))
2343 and then Is_Derived_Type (Typ)
2344 and then In_Private_Part (Current_Scope)
2346 List_Containing (Parent (Prim)) =
2347 Private_Declarations
2348 (Specification (Unit_Declaration_Node (Current_Scope)))
2349 and then Original_View_In_Visible_Part (Typ)
2351 -- We exclude Input and Output stream operations because
2352 -- Limited_Controlled inherits useless Input and Output
2353 -- stream operations from Root_Controlled, which can
2354 -- never be overridden.
2356 if not Is_TSS (Prim, TSS_Stream_Input)
2358 not Is_TSS (Prim, TSS_Stream_Output)
2361 ("abstract inherited private operation&" &
2362 " must be overridden ('R'M 3.9.3(10))",
2363 Parent (Typ), Prim);
2367 Next_Elmt (Prim_Elmt);
2372 if Is_Controlled (Typ) then
2373 if not Finalized then
2375 ("controlled type has no explicit Finalize method?", Typ);
2377 elsif not Adjusted then
2379 ("controlled type has no explicit Adjust method?", Typ);
2383 -- Set the final size of the Dispatch Table
2385 Set_DT_Entry_Count (The_Tag, UI_From_Int (DT_Length));
2387 -- The derived type must have at least as many components as its
2388 -- parent (for root types, the Etype points back to itself
2389 -- and the test should not fail)
2391 -- This test fails compiling the partial view of a tagged type
2392 -- derived from an interface which defines the overriding subprogram
2393 -- in the private part. This needs further investigation???
2395 if not Has_Private_Declaration (Typ) then
2397 DT_Entry_Count (The_Tag) >=
2398 DT_Entry_Count (First_Tag_Component (Parent_Typ)));
2403 if Debug_Flag_ZZ then
2406 end Set_All_DT_Position;
2408 -----------------------------
2409 -- Set_Default_Constructor --
2410 -----------------------------
2412 procedure Set_Default_Constructor (Typ : Entity_Id) is
2419 -- Look for the default constructor entity. For now only the
2420 -- default constructor has the flag Is_Constructor.
2422 E := Next_Entity (Typ);
2424 and then (Ekind (E) /= E_Function or else not Is_Constructor (E))
2429 -- Create the init procedure
2433 Init := Make_Defining_Identifier (Loc, Make_Init_Proc_Name (Typ));
2434 Param := Make_Defining_Identifier (Loc, Name_X);
2437 Make_Subprogram_Declaration (Loc,
2438 Make_Procedure_Specification (Loc,
2439 Defining_Unit_Name => Init,
2440 Parameter_Specifications => New_List (
2441 Make_Parameter_Specification (Loc,
2442 Defining_Identifier => Param,
2443 Parameter_Type => New_Reference_To (Typ, Loc))))));
2445 Set_Init_Proc (Typ, Init);
2446 Set_Is_Imported (Init);
2447 Set_Interface_Name (Init, Interface_Name (E));
2448 Set_Convention (Init, Convention_C);
2449 Set_Is_Public (Init);
2450 Set_Has_Completion (Init);
2452 -- If there are no constructors, mark the type as abstract since we
2453 -- won't be able to declare objects of that type.
2456 Set_Is_Abstract (Typ);
2458 end Set_Default_Constructor;
2464 procedure Write_DT (Typ : Entity_Id) is
2469 -- Protect this procedure against wrong usage. Required because it will
2470 -- be used directly from GDB
2472 if not (Typ in First_Node_Id .. Last_Node_Id)
2473 or else not Is_Tagged_Type (Typ)
2475 Write_Str ("wrong usage: write_dt must be used with tagged types");
2480 Write_Int (Int (Typ));
2482 Write_Name (Chars (Typ));
2484 if Is_Interface (Typ) then
2485 Write_Str (" is interface");
2490 Elmt := First_Elmt (Primitive_Operations (Typ));
2491 while Present (Elmt) loop
2492 Prim := Node (Elmt);
2495 -- Indicate if this primitive will be allocated in the primary
2496 -- dispatch table or in a secondary dispatch table associated
2497 -- with an abstract interface type
2499 if Present (DTC_Entity (Prim)) then
2500 if Etype (DTC_Entity (Prim)) = RTE (RE_Tag) then
2507 -- Output the node of this primitive operation and its name
2509 Write_Int (Int (Prim));
2511 Write_Name (Chars (Prim));
2513 -- Indicate if this primitive has an aliased primitive
2515 if Present (Alias (Prim)) then
2516 Write_Str (" (alias = ");
2517 Write_Int (Int (Alias (Prim)));
2519 -- If the DTC_Entity attribute is already set we can also output
2520 -- the name of the interface covered by this primitive (if any)
2522 if Present (DTC_Entity (Alias (Prim)))
2523 and then Is_Interface (Scope (DTC_Entity (Alias (Prim))))
2525 Write_Str (" from interface ");
2526 Write_Name (Chars (Scope (DTC_Entity (Alias (Prim)))));
2529 if Present (Abstract_Interface_Alias (Prim)) then
2530 Write_Str (", AI_Alias of ");
2531 Write_Name (Chars (Scope (DTC_Entity
2532 (Abstract_Interface_Alias (Prim)))));
2534 Write_Int (Int (Abstract_Interface_Alias (Prim)));
2540 -- Display the final position of this primitive in its associated
2541 -- (primary or secondary) dispatch table
2543 if Present (DTC_Entity (Prim))
2544 and then DT_Position (Prim) /= No_Uint
2546 Write_Str (" at #");
2547 Write_Int (UI_To_Int (DT_Position (Prim)));
2550 if Is_Abstract (Prim) then
2551 Write_Str (" is abstract;");