[Ada] Spurious error on interface conversion under ZFP
[official-gcc.git] / gcc / ada / exp_disp.adb
blob2169b67419a2aed5e9916b67ed9f1c1394abcc35
1 ------------------------------------------------------------------------------
2 -- --
3 -- GNAT COMPILER COMPONENTS --
4 -- --
5 -- E X P _ D I S P --
6 -- --
7 -- B o d y --
8 -- --
9 -- Copyright (C) 1992-2018, Free Software Foundation, Inc. --
10 -- --
11 -- GNAT is free software; you can redistribute it and/or modify it under --
12 -- terms of the GNU General Public License as published by the Free Soft- --
13 -- ware Foundation; either version 3, or (at your option) any later ver- --
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
16 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
17 -- for more details. You should have received a copy of the GNU General --
18 -- Public License distributed with GNAT; see file COPYING3. If not, go to --
19 -- http://www.gnu.org/licenses for a complete copy of the license. --
20 -- --
21 -- GNAT was originally developed by the GNAT team at New York University. --
22 -- Extensive contributions were provided by Ada Core Technologies Inc. --
23 -- --
24 ------------------------------------------------------------------------------
26 with Atree; use Atree;
27 with Checks; use Checks;
28 with Debug; use Debug;
29 with Einfo; use Einfo;
30 with Elists; use Elists;
31 with Errout; use Errout;
32 with Expander; use Expander;
33 with Exp_Atag; use Exp_Atag;
34 with Exp_Ch6; use Exp_Ch6;
35 with Exp_CG; use Exp_CG;
36 with Exp_Dbug; use Exp_Dbug;
37 with Exp_Tss; use Exp_Tss;
38 with Exp_Util; use Exp_Util;
39 with Freeze; use Freeze;
40 with Ghost; use Ghost;
41 with Itypes; use Itypes;
42 with Layout; use Layout;
43 with Nlists; use Nlists;
44 with Nmake; use Nmake;
45 with Namet; use Namet;
46 with Opt; use Opt;
47 with Output; use Output;
48 with Restrict; use Restrict;
49 with Rident; use Rident;
50 with Rtsfind; use Rtsfind;
51 with Sem; use Sem;
52 with Sem_Aux; use Sem_Aux;
53 with Sem_Ch6; use Sem_Ch6;
54 with Sem_Ch7; use Sem_Ch7;
55 with Sem_Ch8; use Sem_Ch8;
56 with Sem_Disp; use Sem_Disp;
57 with Sem_Eval; use Sem_Eval;
58 with Sem_Res; use Sem_Res;
59 with Sem_Type; use Sem_Type;
60 with Sem_Util; use Sem_Util;
61 with Sinfo; use Sinfo;
62 with Sinput; use Sinput;
63 with Snames; use Snames;
64 with Stand; use Stand;
65 with Stringt; use Stringt;
66 with SCIL_LL; use SCIL_LL;
67 with Tbuild; use Tbuild;
69 package body Exp_Disp is
71 -----------------------
72 -- Local Subprograms --
73 -----------------------
75 function Default_Prim_Op_Position (E : Entity_Id) return Uint;
76 -- Ada 2005 (AI-251): Returns the fixed position in the dispatch table
77 -- of the default primitive operations.
79 function Has_DT (Typ : Entity_Id) return Boolean;
80 pragma Inline (Has_DT);
81 -- Returns true if we generate a dispatch table for tagged type Typ
83 function Is_Predefined_Dispatching_Alias (Prim : Entity_Id) return Boolean;
84 -- Returns true if Prim is not a predefined dispatching primitive but it is
85 -- an alias of a predefined dispatching primitive (i.e. through a renaming)
87 function New_Value (From : Node_Id) return Node_Id;
88 -- From is the original Expression. New_Value is equivalent to a call to
89 -- Duplicate_Subexpr with an explicit dereference when From is an access
90 -- parameter.
92 function Original_View_In_Visible_Part (Typ : Entity_Id) return Boolean;
93 -- Check if the type has a private view or if the public view appears in
94 -- the visible part of a package spec.
96 function Prim_Op_Kind
97 (Prim : Entity_Id;
98 Typ : Entity_Id) return Node_Id;
99 -- Ada 2005 (AI-345): Determine the primitive operation kind of Prim
100 -- according to its type Typ. Return a reference to an RE_Prim_Op_Kind
101 -- enumeration value.
103 function Tagged_Kind (T : Entity_Id) return Node_Id;
104 -- Ada 2005 (AI-345): Determine the tagged kind of T and return a reference
105 -- to an RE_Tagged_Kind enumeration value.
107 ----------------------
108 -- Apply_Tag_Checks --
109 ----------------------
111 procedure Apply_Tag_Checks (Call_Node : Node_Id) is
112 Loc : constant Source_Ptr := Sloc (Call_Node);
113 Ctrl_Arg : constant Node_Id := Controlling_Argument (Call_Node);
114 Ctrl_Typ : constant Entity_Id := Base_Type (Etype (Ctrl_Arg));
115 Param_List : constant List_Id := Parameter_Associations (Call_Node);
117 Subp : Entity_Id;
118 CW_Typ : Entity_Id;
119 Param : Node_Id;
120 Typ : Entity_Id;
121 Eq_Prim_Op : Entity_Id := Empty;
123 begin
124 if No_Run_Time_Mode then
125 Error_Msg_CRT ("tagged types", Call_Node);
126 return;
127 end if;
129 -- Apply_Tag_Checks is called directly from the semantics, so we
130 -- need a check to see whether expansion is active before proceeding.
131 -- In addition, there is no need to expand the call when compiling
132 -- under restriction No_Dispatching_Calls; the semantic analyzer has
133 -- previously notified the violation of this restriction.
135 if not Expander_Active
136 or else Restriction_Active (No_Dispatching_Calls)
137 then
138 return;
139 end if;
141 -- Set subprogram. If this is an inherited operation that was
142 -- overridden, the body that is being called is its alias.
144 Subp := Entity (Name (Call_Node));
146 if Present (Alias (Subp))
147 and then Is_Inherited_Operation (Subp)
148 and then No (DTC_Entity (Subp))
149 then
150 Subp := Alias (Subp);
151 end if;
153 -- Definition of the class-wide type and the tagged type
155 -- If the controlling argument is itself a tag rather than a tagged
156 -- object, then use the class-wide type associated with the subprogram's
157 -- controlling type. This case can occur when a call to an inherited
158 -- primitive has an actual that originated from a default parameter
159 -- given by a tag-indeterminate call and when there is no other
160 -- controlling argument providing the tag (AI-239 requires dispatching).
161 -- This capability of dispatching directly by tag is also needed by the
162 -- implementation of AI-260 (for the generic dispatching constructors).
164 if Ctrl_Typ = RTE (RE_Tag)
165 or else (RTE_Available (RE_Interface_Tag)
166 and then Ctrl_Typ = RTE (RE_Interface_Tag))
167 then
168 CW_Typ := Class_Wide_Type (Find_Dispatching_Type (Subp));
170 -- Class_Wide_Type is applied to the expressions used to initialize
171 -- CW_Typ, to ensure that CW_Typ always denotes a class-wide type, since
172 -- there are cases where the controlling type is resolved to a specific
173 -- type (such as for designated types of arguments such as CW'Access).
175 elsif Is_Access_Type (Ctrl_Typ) then
176 CW_Typ := Class_Wide_Type (Designated_Type (Ctrl_Typ));
178 else
179 CW_Typ := Class_Wide_Type (Ctrl_Typ);
180 end if;
182 Typ := Find_Specific_Type (CW_Typ);
184 if not Is_Limited_Type (Typ) then
185 Eq_Prim_Op := Find_Prim_Op (Typ, Name_Op_Eq);
186 end if;
188 -- Dispatching call to C++ primitive
190 if Is_CPP_Class (Typ) then
191 null;
193 -- Dispatching call to Ada primitive
195 elsif Present (Param_List) then
197 -- Generate the Tag checks when appropriate
199 Param := First_Actual (Call_Node);
200 while Present (Param) loop
202 -- No tag check with itself
204 if Param = Ctrl_Arg then
205 null;
207 -- No tag check for parameter whose type is neither tagged nor
208 -- access to tagged (for access parameters)
210 elsif No (Find_Controlling_Arg (Param)) then
211 null;
213 -- No tag check for function dispatching on result if the
214 -- Tag given by the context is this one
216 elsif Find_Controlling_Arg (Param) = Ctrl_Arg then
217 null;
219 -- "=" is the only dispatching operation allowed to get operands
220 -- with incompatible tags (it just returns false). We use
221 -- Duplicate_Subexpr_Move_Checks instead of calling Relocate_Node
222 -- because the value will be duplicated to check the tags.
224 elsif Subp = Eq_Prim_Op then
225 null;
227 -- No check in presence of suppress flags
229 elsif Tag_Checks_Suppressed (Etype (Param))
230 or else (Is_Access_Type (Etype (Param))
231 and then Tag_Checks_Suppressed
232 (Designated_Type (Etype (Param))))
233 then
234 null;
236 -- Optimization: no tag checks if the parameters are identical
238 elsif Is_Entity_Name (Param)
239 and then Is_Entity_Name (Ctrl_Arg)
240 and then Entity (Param) = Entity (Ctrl_Arg)
241 then
242 null;
244 -- Now we need to generate the Tag check
246 else
247 -- Generate code for tag equality check
249 -- Perhaps should have Checks.Apply_Tag_Equality_Check???
251 Insert_Action (Ctrl_Arg,
252 Make_Implicit_If_Statement (Call_Node,
253 Condition =>
254 Make_Op_Ne (Loc,
255 Left_Opnd =>
256 Make_Selected_Component (Loc,
257 Prefix => New_Value (Ctrl_Arg),
258 Selector_Name =>
259 New_Occurrence_Of
260 (First_Tag_Component (Typ), Loc)),
262 Right_Opnd =>
263 Make_Selected_Component (Loc,
264 Prefix =>
265 Unchecked_Convert_To (Typ, New_Value (Param)),
266 Selector_Name =>
267 New_Occurrence_Of
268 (First_Tag_Component (Typ), Loc))),
270 Then_Statements =>
271 New_List (New_Constraint_Error (Loc))));
272 end if;
274 Next_Actual (Param);
275 end loop;
276 end if;
277 end Apply_Tag_Checks;
279 ------------------------
280 -- Building_Static_DT --
281 ------------------------
283 function Building_Static_DT (Typ : Entity_Id) return Boolean is
284 Root_Typ : Entity_Id := Root_Type (Typ);
285 Static_DT : Boolean;
287 begin
288 -- Handle private types
290 if Present (Full_View (Root_Typ)) then
291 Root_Typ := Full_View (Root_Typ);
292 end if;
294 Static_DT :=
295 Building_Static_Dispatch_Tables
296 and then Is_Library_Level_Tagged_Type (Typ)
298 -- If the type is derived from a CPP class we cannot statically
299 -- build the dispatch tables because we must inherit primitives
300 -- from the CPP side.
302 and then not Is_CPP_Class (Root_Typ);
304 if not Static_DT then
305 Check_Restriction (Static_Dispatch_Tables, Typ);
306 end if;
308 return Static_DT;
309 end Building_Static_DT;
311 ----------------------------------
312 -- Building_Static_Secondary_DT --
313 ----------------------------------
315 function Building_Static_Secondary_DT (Typ : Entity_Id) return Boolean is
316 Full_Typ : Entity_Id := Typ;
317 Root_Typ : Entity_Id := Root_Type (Typ);
318 Static_DT : Boolean;
320 begin
321 -- Handle private types
323 if Present (Full_View (Typ)) then
324 Full_Typ := Full_View (Typ);
325 end if;
327 if Present (Full_View (Root_Typ)) then
328 Root_Typ := Full_View (Root_Typ);
329 end if;
331 Static_DT :=
332 Building_Static_DT (Full_Typ)
333 and then not Is_Interface (Full_Typ)
334 and then Has_Interfaces (Full_Typ)
335 and then (Full_Typ = Root_Typ
336 or else not Is_Variable_Size_Record (Etype (Full_Typ)));
338 if not Static_DT
339 and then not Is_Interface (Full_Typ)
340 and then Has_Interfaces (Full_Typ)
341 then
342 Check_Restriction (Static_Dispatch_Tables, Typ);
343 end if;
345 return Static_DT;
346 end Building_Static_Secondary_DT;
348 ----------------------------------
349 -- Build_Static_Dispatch_Tables --
350 ----------------------------------
352 procedure Build_Static_Dispatch_Tables (N : Entity_Id) is
353 Target_List : List_Id;
355 procedure Build_Dispatch_Tables (List : List_Id);
356 -- Build the static dispatch table of tagged types found in the list of
357 -- declarations. The generated nodes are added at the end of Target_List
359 procedure Build_Package_Dispatch_Tables (N : Node_Id);
360 -- Build static dispatch tables associated with package declaration N
362 ---------------------------
363 -- Build_Dispatch_Tables --
364 ---------------------------
366 procedure Build_Dispatch_Tables (List : List_Id) is
367 D : Node_Id;
369 begin
370 D := First (List);
371 while Present (D) loop
373 -- Handle nested packages and package bodies recursively. The
374 -- generated code is placed on the Target_List established for
375 -- the enclosing compilation unit.
377 if Nkind (D) = N_Package_Declaration then
378 Build_Package_Dispatch_Tables (D);
380 elsif Nkind (D) = N_Package_Body then
381 Build_Dispatch_Tables (Declarations (D));
383 elsif Nkind (D) = N_Package_Body_Stub
384 and then Present (Library_Unit (D))
385 then
386 Build_Dispatch_Tables
387 (Declarations (Proper_Body (Unit (Library_Unit (D)))));
389 -- Handle full type declarations and derivations of library level
390 -- tagged types
392 elsif Nkind_In (D, N_Full_Type_Declaration,
393 N_Derived_Type_Definition)
394 and then Is_Library_Level_Tagged_Type (Defining_Entity (D))
395 and then Ekind (Defining_Entity (D)) /= E_Record_Subtype
396 and then not Is_Private_Type (Defining_Entity (D))
397 then
398 -- We do not generate dispatch tables for the internal types
399 -- created for a type extension with unknown discriminants
400 -- The needed information is shared with the source type,
401 -- See Expand_N_Record_Extension.
403 if Is_Underlying_Record_View (Defining_Entity (D))
404 or else
405 (not Comes_From_Source (Defining_Entity (D))
406 and then
407 Has_Unknown_Discriminants (Etype (Defining_Entity (D)))
408 and then
409 not Comes_From_Source
410 (First_Subtype (Defining_Entity (D))))
411 then
412 null;
413 else
414 Insert_List_After_And_Analyze (Last (Target_List),
415 Make_DT (Defining_Entity (D)));
416 end if;
418 -- Handle private types of library level tagged types. We must
419 -- exchange the private and full-view to ensure the correct
420 -- expansion. If the full view is a synchronized type ignore
421 -- the type because the table will be built for the corresponding
422 -- record type, that has its own declaration.
424 elsif (Nkind (D) = N_Private_Type_Declaration
425 or else Nkind (D) = N_Private_Extension_Declaration)
426 and then Present (Full_View (Defining_Entity (D)))
427 then
428 declare
429 E1 : constant Entity_Id := Defining_Entity (D);
430 E2 : constant Entity_Id := Full_View (E1);
432 begin
433 if Is_Library_Level_Tagged_Type (E2)
434 and then Ekind (E2) /= E_Record_Subtype
435 and then not Is_Concurrent_Type (E2)
436 then
437 Exchange_Declarations (E1);
438 Insert_List_After_And_Analyze (Last (Target_List),
439 Make_DT (E1));
440 Exchange_Declarations (E2);
441 end if;
442 end;
443 end if;
445 Next (D);
446 end loop;
447 end Build_Dispatch_Tables;
449 -----------------------------------
450 -- Build_Package_Dispatch_Tables --
451 -----------------------------------
453 procedure Build_Package_Dispatch_Tables (N : Node_Id) is
454 Spec : constant Node_Id := Specification (N);
455 Id : constant Entity_Id := Defining_Entity (N);
456 Vis_Decls : constant List_Id := Visible_Declarations (Spec);
457 Priv_Decls : constant List_Id := Private_Declarations (Spec);
459 begin
460 Push_Scope (Id);
462 if Present (Priv_Decls) then
463 Build_Dispatch_Tables (Vis_Decls);
464 Build_Dispatch_Tables (Priv_Decls);
466 elsif Present (Vis_Decls) then
467 Build_Dispatch_Tables (Vis_Decls);
468 end if;
470 Pop_Scope;
471 end Build_Package_Dispatch_Tables;
473 -- Start of processing for Build_Static_Dispatch_Tables
475 begin
476 if not Expander_Active
477 or else not Tagged_Type_Expansion
478 then
479 return;
480 end if;
482 if Nkind (N) = N_Package_Declaration then
483 declare
484 Spec : constant Node_Id := Specification (N);
485 Vis_Decls : constant List_Id := Visible_Declarations (Spec);
486 Priv_Decls : constant List_Id := Private_Declarations (Spec);
488 begin
489 if Present (Priv_Decls)
490 and then Is_Non_Empty_List (Priv_Decls)
491 then
492 Target_List := Priv_Decls;
494 elsif not Present (Vis_Decls) then
495 Target_List := New_List;
496 Set_Private_Declarations (Spec, Target_List);
497 else
498 Target_List := Vis_Decls;
499 end if;
501 Build_Package_Dispatch_Tables (N);
502 end;
504 else pragma Assert (Nkind (N) = N_Package_Body);
505 Target_List := Declarations (N);
506 Build_Dispatch_Tables (Target_List);
507 end if;
508 end Build_Static_Dispatch_Tables;
510 ------------------------------
511 -- Convert_Tag_To_Interface --
512 ------------------------------
514 function Convert_Tag_To_Interface
515 (Typ : Entity_Id;
516 Expr : Node_Id) return Node_Id
518 Loc : constant Source_Ptr := Sloc (Expr);
519 Anon_Type : Entity_Id;
520 Result : Node_Id;
522 begin
523 pragma Assert (Is_Class_Wide_Type (Typ)
524 and then Is_Interface (Typ)
525 and then
526 ((Nkind (Expr) = N_Selected_Component
527 and then Is_Tag (Entity (Selector_Name (Expr))))
528 or else
529 (Nkind (Expr) = N_Function_Call
530 and then RTE_Available (RE_Displace)
531 and then Entity (Name (Expr)) = RTE (RE_Displace))));
533 Anon_Type := Create_Itype (E_Anonymous_Access_Type, Expr);
534 Set_Directly_Designated_Type (Anon_Type, Typ);
535 Set_Etype (Anon_Type, Anon_Type);
536 Set_Can_Never_Be_Null (Anon_Type);
538 -- Decorate the size and alignment attributes of the anonymous access
539 -- type, as required by the back end.
541 Layout_Type (Anon_Type);
543 if Nkind (Expr) = N_Selected_Component
544 and then Is_Tag (Entity (Selector_Name (Expr)))
545 then
546 Result :=
547 Make_Explicit_Dereference (Loc,
548 Unchecked_Convert_To (Anon_Type,
549 Make_Attribute_Reference (Loc,
550 Prefix => Expr,
551 Attribute_Name => Name_Address)));
552 else
553 Result :=
554 Make_Explicit_Dereference (Loc,
555 Unchecked_Convert_To (Anon_Type, Expr));
556 end if;
558 return Result;
559 end Convert_Tag_To_Interface;
561 -------------------
562 -- CPP_Num_Prims --
563 -------------------
565 function CPP_Num_Prims (Typ : Entity_Id) return Nat is
566 CPP_Typ : Entity_Id;
567 Tag_Comp : Entity_Id;
569 begin
570 if not Is_Tagged_Type (Typ)
571 or else not Is_CPP_Class (Root_Type (Typ))
572 then
573 return 0;
575 else
576 CPP_Typ := Enclosing_CPP_Parent (Typ);
577 Tag_Comp := First_Tag_Component (CPP_Typ);
579 -- If number of primitives already set in the tag component, use it
581 if Present (Tag_Comp)
582 and then DT_Entry_Count (Tag_Comp) /= No_Uint
583 then
584 return UI_To_Int (DT_Entry_Count (Tag_Comp));
586 -- Otherwise, count the primitives of the enclosing CPP type
588 else
589 declare
590 Count : Nat := 0;
591 Elmt : Elmt_Id;
593 begin
594 Elmt := First_Elmt (Primitive_Operations (CPP_Typ));
595 while Present (Elmt) loop
596 Count := Count + 1;
597 Next_Elmt (Elmt);
598 end loop;
600 return Count;
601 end;
602 end if;
603 end if;
604 end CPP_Num_Prims;
606 ------------------------------
607 -- Default_Prim_Op_Position --
608 ------------------------------
610 function Default_Prim_Op_Position (E : Entity_Id) return Uint is
611 TSS_Name : TSS_Name_Type;
613 begin
614 Get_Name_String (Chars (E));
615 TSS_Name :=
616 TSS_Name_Type
617 (Name_Buffer (Name_Len - TSS_Name'Length + 1 .. Name_Len));
619 if Chars (E) = Name_uSize then
620 return Uint_1;
622 elsif TSS_Name = TSS_Stream_Read then
623 return Uint_2;
625 elsif TSS_Name = TSS_Stream_Write then
626 return Uint_3;
628 elsif TSS_Name = TSS_Stream_Input then
629 return Uint_4;
631 elsif TSS_Name = TSS_Stream_Output then
632 return Uint_5;
634 elsif Chars (E) = Name_Op_Eq then
635 return Uint_6;
637 elsif Chars (E) = Name_uAssign then
638 return Uint_7;
640 elsif TSS_Name = TSS_Deep_Adjust then
641 return Uint_8;
643 elsif TSS_Name = TSS_Deep_Finalize then
644 return Uint_9;
646 -- In VM targets unconditionally allow obtaining the position associated
647 -- with predefined interface primitives since in these platforms any
648 -- tagged type has these primitives.
650 elsif Ada_Version >= Ada_2005 or else not Tagged_Type_Expansion then
651 if Chars (E) = Name_uDisp_Asynchronous_Select then
652 return Uint_10;
654 elsif Chars (E) = Name_uDisp_Conditional_Select then
655 return Uint_11;
657 elsif Chars (E) = Name_uDisp_Get_Prim_Op_Kind then
658 return Uint_12;
660 elsif Chars (E) = Name_uDisp_Get_Task_Id then
661 return Uint_13;
663 elsif Chars (E) = Name_uDisp_Requeue then
664 return Uint_14;
666 elsif Chars (E) = Name_uDisp_Timed_Select then
667 return Uint_15;
668 end if;
669 end if;
671 raise Program_Error;
672 end Default_Prim_Op_Position;
674 ----------------------
675 -- Elab_Flag_Needed --
676 ----------------------
678 function Elab_Flag_Needed (Typ : Entity_Id) return Boolean is
679 begin
680 return Ada_Version >= Ada_2005
681 and then not Is_Interface (Typ)
682 and then Has_Interfaces (Typ)
683 and then not Building_Static_DT (Typ);
684 end Elab_Flag_Needed;
686 -----------------------------
687 -- Expand_Dispatching_Call --
688 -----------------------------
690 procedure Expand_Dispatching_Call (Call_Node : Node_Id) is
691 Loc : constant Source_Ptr := Sloc (Call_Node);
692 Call_Typ : constant Entity_Id := Etype (Call_Node);
694 Ctrl_Arg : constant Node_Id := Controlling_Argument (Call_Node);
695 Ctrl_Typ : constant Entity_Id := Base_Type (Etype (Ctrl_Arg));
696 Param_List : constant List_Id := Parameter_Associations (Call_Node);
698 Subp : Entity_Id;
699 CW_Typ : Entity_Id;
700 New_Call : Node_Id;
701 New_Call_Name : Node_Id;
702 New_Params : List_Id := No_List;
703 Param : Node_Id;
704 Res_Typ : Entity_Id;
705 Subp_Ptr_Typ : Entity_Id;
706 Subp_Typ : Entity_Id;
707 Typ : Entity_Id;
708 Eq_Prim_Op : Entity_Id := Empty;
709 Controlling_Tag : Node_Id;
711 procedure Build_Class_Wide_Check;
712 -- If the denoted subprogram has a class-wide precondition, generate a
713 -- check using that precondition before the dispatching call, because
714 -- this is the only class-wide precondition that applies to the call.
716 function New_Value (From : Node_Id) return Node_Id;
717 -- From is the original Expression. New_Value is equivalent to a call
718 -- to Duplicate_Subexpr with an explicit dereference when From is an
719 -- access parameter.
721 ----------------------------
722 -- Build_Class_Wide_Check --
723 ----------------------------
725 procedure Build_Class_Wide_Check is
726 function Replace_Formals (N : Node_Id) return Traverse_Result;
727 -- Replace occurrences of the formals of the subprogram by the
728 -- corresponding actuals in the call, given that this check is
729 -- performed outside of the body of the subprogram.
731 ---------------------
732 -- Replace_Formals --
733 ---------------------
735 function Replace_Formals (N : Node_Id) return Traverse_Result is
736 begin
737 if Is_Entity_Name (N)
738 and then Present (Entity (N))
739 and then Is_Formal (Entity (N))
740 then
741 declare
742 A : Node_Id;
743 F : Entity_Id;
745 begin
746 F := First_Formal (Subp);
747 A := First_Actual (Call_Node);
748 while Present (F) loop
749 if F = Entity (N) then
750 Rewrite (N, New_Copy_Tree (A));
752 -- If the formal is class-wide, and thus not a
753 -- controlling argument, preserve its type because
754 -- it may appear in a nested call with a class-wide
755 -- parameter.
757 if Is_Class_Wide_Type (Etype (F)) then
758 Set_Etype (N, Etype (F));
760 -- Conversely, if this is a controlling argument
761 -- (in a dispatching call in the condition) that is a
762 -- dereference, the source is an access-to-class-wide
763 -- type, so preserve the dispatching nature of the
764 -- call in the rewritten condition.
766 elsif Nkind (Parent (N)) = N_Explicit_Dereference
767 and then Is_Controlling_Actual (Parent (N))
768 then
769 Set_Controlling_Argument (Parent (Parent (N)),
770 Parent (N));
771 end if;
773 exit;
774 end if;
776 Next_Formal (F);
777 Next_Actual (A);
778 end loop;
779 end;
780 end if;
782 return OK;
783 end Replace_Formals;
785 procedure Update is new Traverse_Proc (Replace_Formals);
787 -- Local variables
789 Str_Loc : constant String := Build_Location_String (Loc);
791 Cond : Node_Id;
792 Msg : Node_Id;
793 Prec : Node_Id;
795 -- Start of processing for Build_Class_Wide_Check
797 begin
799 -- Locate class-wide precondition, if any
801 if Present (Contract (Subp))
802 and then Present (Pre_Post_Conditions (Contract (Subp)))
803 then
804 Prec := Pre_Post_Conditions (Contract (Subp));
806 while Present (Prec) loop
807 exit when Pragma_Name (Prec) = Name_Precondition
808 and then Class_Present (Prec);
809 Prec := Next_Pragma (Prec);
810 end loop;
812 if No (Prec) or else Is_Ignored (Prec) then
813 return;
814 end if;
816 -- The expression for the precondition is analyzed within the
817 -- generated pragma. The message text is the last parameter of
818 -- the generated pragma, indicating source of precondition.
820 Cond :=
821 New_Copy_Tree
822 (Expression (First (Pragma_Argument_Associations (Prec))));
823 Update (Cond);
825 -- Build message indicating the failed precondition and the
826 -- dispatching call that caused it.
828 Msg := Expression (Last (Pragma_Argument_Associations (Prec)));
829 Name_Len := 0;
830 Append (Global_Name_Buffer, Strval (Msg));
831 Append (Global_Name_Buffer, " in dispatching call at ");
832 Append (Global_Name_Buffer, Str_Loc);
833 Msg := Make_String_Literal (Loc, Name_Buffer (1 .. Name_Len));
835 Insert_Action (Call_Node,
836 Make_If_Statement (Loc,
837 Condition => Make_Op_Not (Loc, Cond),
838 Then_Statements => New_List (
839 Make_Procedure_Call_Statement (Loc,
840 Name =>
841 New_Occurrence_Of (RTE (RE_Raise_Assert_Failure), Loc),
842 Parameter_Associations => New_List (Msg)))));
843 end if;
844 end Build_Class_Wide_Check;
846 ---------------
847 -- New_Value --
848 ---------------
850 function New_Value (From : Node_Id) return Node_Id is
851 Res : constant Node_Id := Duplicate_Subexpr (From);
852 begin
853 if Is_Access_Type (Etype (From)) then
854 return
855 Make_Explicit_Dereference (Sloc (From),
856 Prefix => Res);
857 else
858 return Res;
859 end if;
860 end New_Value;
862 -- Local variables
864 New_Node : Node_Id;
865 SCIL_Node : Node_Id := Empty;
866 SCIL_Related_Node : Node_Id := Call_Node;
868 -- Start of processing for Expand_Dispatching_Call
870 begin
871 if No_Run_Time_Mode then
872 Error_Msg_CRT ("tagged types", Call_Node);
873 return;
874 end if;
876 -- Expand_Dispatching_Call is called directly from the semantics, so we
877 -- only proceed if the expander is active.
879 if not Expander_Active
881 -- And there is no need to expand the call if we are compiling under
882 -- restriction No_Dispatching_Calls; the semantic analyzer has
883 -- previously notified the violation of this restriction.
885 or else Restriction_Active (No_Dispatching_Calls)
887 -- No action needed if the dispatching call has been already expanded
889 or else Is_Expanded_Dispatching_Call (Name (Call_Node))
890 then
891 return;
892 end if;
894 -- Set subprogram. If this is an inherited operation that was
895 -- overridden, the body that is being called is its alias.
897 Subp := Entity (Name (Call_Node));
899 if Present (Alias (Subp))
900 and then Is_Inherited_Operation (Subp)
901 and then No (DTC_Entity (Subp))
902 then
903 Subp := Alias (Subp);
904 end if;
906 Build_Class_Wide_Check;
908 -- Definition of the class-wide type and the tagged type
910 -- If the controlling argument is itself a tag rather than a tagged
911 -- object, then use the class-wide type associated with the subprogram's
912 -- controlling type. This case can occur when a call to an inherited
913 -- primitive has an actual that originated from a default parameter
914 -- given by a tag-indeterminate call and when there is no other
915 -- controlling argument providing the tag (AI-239 requires dispatching).
916 -- This capability of dispatching directly by tag is also needed by the
917 -- implementation of AI-260 (for the generic dispatching constructors).
919 if Ctrl_Typ = RTE (RE_Tag)
920 or else (RTE_Available (RE_Interface_Tag)
921 and then Ctrl_Typ = RTE (RE_Interface_Tag))
922 then
923 CW_Typ := Class_Wide_Type (Find_Dispatching_Type (Subp));
925 -- Class_Wide_Type is applied to the expressions used to initialize
926 -- CW_Typ, to ensure that CW_Typ always denotes a class-wide type, since
927 -- there are cases where the controlling type is resolved to a specific
928 -- type (such as for designated types of arguments such as CW'Access).
930 elsif Is_Access_Type (Ctrl_Typ) then
931 CW_Typ := Class_Wide_Type (Designated_Type (Ctrl_Typ));
933 else
934 CW_Typ := Class_Wide_Type (Ctrl_Typ);
935 end if;
937 Typ := Find_Specific_Type (CW_Typ);
939 if not Is_Limited_Type (Typ) then
940 Eq_Prim_Op := Find_Prim_Op (Typ, Name_Op_Eq);
941 end if;
943 -- Dispatching call to C++ primitive. Create a new parameter list
944 -- with no tag checks.
946 New_Params := New_List;
948 if Is_CPP_Class (Typ) then
949 Param := First_Actual (Call_Node);
950 while Present (Param) loop
951 Append_To (New_Params, Relocate_Node (Param));
952 Next_Actual (Param);
953 end loop;
955 -- Dispatching call to Ada primitive
957 elsif Present (Param_List) then
958 Apply_Tag_Checks (Call_Node);
960 Param := First_Actual (Call_Node);
961 while Present (Param) loop
963 -- Cases in which we may have generated run-time checks. Note that
964 -- we strip any qualification from Param before comparing with the
965 -- already-stripped controlling argument.
967 if Unqualify (Param) = Ctrl_Arg or else Subp = Eq_Prim_Op then
968 Append_To (New_Params,
969 Duplicate_Subexpr_Move_Checks (Param));
971 elsif Nkind (Parent (Param)) /= N_Parameter_Association
972 or else not Is_Accessibility_Actual (Parent (Param))
973 then
974 Append_To (New_Params, Relocate_Node (Param));
975 end if;
977 Next_Actual (Param);
978 end loop;
979 end if;
981 -- Generate the appropriate subprogram pointer type
983 if Etype (Subp) = Typ then
984 Res_Typ := CW_Typ;
985 else
986 Res_Typ := Etype (Subp);
987 end if;
989 Subp_Typ := Create_Itype (E_Subprogram_Type, Call_Node);
990 Subp_Ptr_Typ := Create_Itype (E_Access_Subprogram_Type, Call_Node);
991 Set_Etype (Subp_Typ, Res_Typ);
992 Set_Returns_By_Ref (Subp_Typ, Returns_By_Ref (Subp));
993 Set_Convention (Subp_Typ, Convention (Subp));
995 -- Notify gigi that the designated type is a dispatching primitive
997 Set_Is_Dispatch_Table_Entity (Subp_Typ);
999 -- Create a new list of parameters which is a copy of the old formal
1000 -- list including the creation of a new set of matching entities.
1002 declare
1003 Old_Formal : Entity_Id := First_Formal (Subp);
1004 New_Formal : Entity_Id;
1005 Extra : Entity_Id := Empty;
1007 begin
1008 if Present (Old_Formal) then
1009 New_Formal := New_Copy (Old_Formal);
1010 Set_First_Entity (Subp_Typ, New_Formal);
1011 Param := First_Actual (Call_Node);
1013 loop
1014 Set_Scope (New_Formal, Subp_Typ);
1016 -- Change all the controlling argument types to be class-wide
1017 -- to avoid a recursion in dispatching.
1019 if Is_Controlling_Formal (New_Formal) then
1020 Set_Etype (New_Formal, Etype (Param));
1021 end if;
1023 -- If the type of the formal is an itype, there was code here
1024 -- introduced in 1998 in revision 1.46, to create a new itype
1025 -- by copy. This seems useless, and in fact leads to semantic
1026 -- errors when the itype is the completion of a type derived
1027 -- from a private type.
1029 Extra := New_Formal;
1030 Next_Formal (Old_Formal);
1031 exit when No (Old_Formal);
1033 Link_Entities (New_Formal, New_Copy (Old_Formal));
1034 Next_Entity (New_Formal);
1035 Next_Actual (Param);
1036 end loop;
1038 Unlink_Next_Entity (New_Formal);
1039 Set_Last_Entity (Subp_Typ, Extra);
1040 end if;
1042 -- Now that the explicit formals have been duplicated, any extra
1043 -- formals needed by the subprogram must be created.
1045 if Present (Extra) then
1046 Set_Extra_Formal (Extra, Empty);
1047 end if;
1049 Create_Extra_Formals (Subp_Typ);
1050 end;
1052 -- Complete description of pointer type, including size information, as
1053 -- must be done with itypes to prevent order-of-elaboration anomalies
1054 -- in gigi.
1056 Set_Etype (Subp_Ptr_Typ, Subp_Ptr_Typ);
1057 Set_Directly_Designated_Type (Subp_Ptr_Typ, Subp_Typ);
1058 Set_Convention (Subp_Ptr_Typ, Convention (Subp_Typ));
1059 Layout_Type (Subp_Ptr_Typ);
1061 -- If the controlling argument is a value of type Ada.Tag or an abstract
1062 -- interface class-wide type then use it directly. Otherwise, the tag
1063 -- must be extracted from the controlling object.
1065 if Ctrl_Typ = RTE (RE_Tag)
1066 or else (RTE_Available (RE_Interface_Tag)
1067 and then Ctrl_Typ = RTE (RE_Interface_Tag))
1068 then
1069 Controlling_Tag := Duplicate_Subexpr (Ctrl_Arg);
1071 -- Extract the tag from an unchecked type conversion. Done to avoid
1072 -- the expansion of additional code just to obtain the value of such
1073 -- tag because the current management of interface type conversions
1074 -- generates in some cases this unchecked type conversion with the
1075 -- tag of the object (see Expand_Interface_Conversion).
1077 elsif Nkind (Ctrl_Arg) = N_Unchecked_Type_Conversion
1078 and then
1079 (Etype (Expression (Ctrl_Arg)) = RTE (RE_Tag)
1080 or else
1081 (RTE_Available (RE_Interface_Tag)
1082 and then
1083 Etype (Expression (Ctrl_Arg)) = RTE (RE_Interface_Tag)))
1084 then
1085 Controlling_Tag := Duplicate_Subexpr (Expression (Ctrl_Arg));
1087 -- Ada 2005 (AI-251): Abstract interface class-wide type
1089 elsif Is_Interface (Ctrl_Typ)
1090 and then Is_Class_Wide_Type (Ctrl_Typ)
1091 then
1092 Controlling_Tag := Duplicate_Subexpr (Ctrl_Arg);
1094 else
1095 Controlling_Tag :=
1096 Make_Selected_Component (Loc,
1097 Prefix => Duplicate_Subexpr_Move_Checks (Ctrl_Arg),
1098 Selector_Name => New_Occurrence_Of (DTC_Entity (Subp), Loc));
1099 end if;
1101 -- Handle dispatching calls to predefined primitives
1103 if Is_Predefined_Dispatching_Operation (Subp)
1104 or else Is_Predefined_Dispatching_Alias (Subp)
1105 then
1106 Build_Get_Predefined_Prim_Op_Address (Loc,
1107 Tag_Node => Controlling_Tag,
1108 Position => DT_Position (Subp),
1109 New_Node => New_Node);
1111 -- Handle dispatching calls to user-defined primitives
1113 else
1114 Build_Get_Prim_Op_Address (Loc,
1115 Typ => Underlying_Type (Find_Dispatching_Type (Subp)),
1116 Tag_Node => Controlling_Tag,
1117 Position => DT_Position (Subp),
1118 New_Node => New_Node);
1119 end if;
1121 New_Call_Name :=
1122 Unchecked_Convert_To (Subp_Ptr_Typ, New_Node);
1124 -- Generate the SCIL node for this dispatching call. Done now because
1125 -- attribute SCIL_Controlling_Tag must be set after the new call name
1126 -- is built to reference the nodes that will see the SCIL backend
1127 -- (because Build_Get_Prim_Op_Address generates an unchecked type
1128 -- conversion which relocates the controlling tag node).
1130 if Generate_SCIL then
1131 SCIL_Node := Make_SCIL_Dispatching_Call (Sloc (Call_Node));
1132 Set_SCIL_Entity (SCIL_Node, Typ);
1133 Set_SCIL_Target_Prim (SCIL_Node, Subp);
1135 -- Common case: the controlling tag is the tag of an object
1136 -- (for example, obj.tag)
1138 if Nkind (Controlling_Tag) = N_Selected_Component then
1139 Set_SCIL_Controlling_Tag (SCIL_Node, Controlling_Tag);
1141 -- Handle renaming of selected component
1143 elsif Nkind (Controlling_Tag) = N_Identifier
1144 and then Nkind (Parent (Entity (Controlling_Tag))) =
1145 N_Object_Renaming_Declaration
1146 and then Nkind (Name (Parent (Entity (Controlling_Tag)))) =
1147 N_Selected_Component
1148 then
1149 Set_SCIL_Controlling_Tag (SCIL_Node,
1150 Name (Parent (Entity (Controlling_Tag))));
1152 -- If the controlling tag is an identifier, the SCIL node references
1153 -- the corresponding object or parameter declaration
1155 elsif Nkind (Controlling_Tag) = N_Identifier
1156 and then Nkind_In (Parent (Entity (Controlling_Tag)),
1157 N_Object_Declaration,
1158 N_Parameter_Specification)
1159 then
1160 Set_SCIL_Controlling_Tag (SCIL_Node,
1161 Parent (Entity (Controlling_Tag)));
1163 -- If the controlling tag is a dereference, the SCIL node references
1164 -- the corresponding object or parameter declaration
1166 elsif Nkind (Controlling_Tag) = N_Explicit_Dereference
1167 and then Nkind (Prefix (Controlling_Tag)) = N_Identifier
1168 and then Nkind_In (Parent (Entity (Prefix (Controlling_Tag))),
1169 N_Object_Declaration,
1170 N_Parameter_Specification)
1171 then
1172 Set_SCIL_Controlling_Tag (SCIL_Node,
1173 Parent (Entity (Prefix (Controlling_Tag))));
1175 -- For a direct reference of the tag of the type the SCIL node
1176 -- references the internal object declaration containing the tag
1177 -- of the type.
1179 elsif Nkind (Controlling_Tag) = N_Attribute_Reference
1180 and then Attribute_Name (Controlling_Tag) = Name_Tag
1181 then
1182 Set_SCIL_Controlling_Tag (SCIL_Node,
1183 Parent
1184 (Node
1185 (First_Elmt
1186 (Access_Disp_Table (Entity (Prefix (Controlling_Tag)))))));
1188 -- Interfaces are not supported. For now we leave the SCIL node
1189 -- decorated with the Controlling_Tag. More work needed here???
1191 elsif Is_Interface (Etype (Controlling_Tag)) then
1192 Set_SCIL_Controlling_Tag (SCIL_Node, Controlling_Tag);
1194 else
1195 pragma Assert (False);
1196 null;
1197 end if;
1198 end if;
1200 if Nkind (Call_Node) = N_Function_Call then
1201 New_Call :=
1202 Make_Function_Call (Loc,
1203 Name => New_Call_Name,
1204 Parameter_Associations => New_Params);
1206 -- If this is a dispatching "=", we must first compare the tags so
1207 -- we generate: x.tag = y.tag and then x = y
1209 if Subp = Eq_Prim_Op then
1210 Param := First_Actual (Call_Node);
1211 New_Call :=
1212 Make_And_Then (Loc,
1213 Left_Opnd =>
1214 Make_Op_Eq (Loc,
1215 Left_Opnd =>
1216 Make_Selected_Component (Loc,
1217 Prefix => New_Value (Param),
1218 Selector_Name =>
1219 New_Occurrence_Of (First_Tag_Component (Typ),
1220 Loc)),
1222 Right_Opnd =>
1223 Make_Selected_Component (Loc,
1224 Prefix =>
1225 Unchecked_Convert_To (Typ,
1226 New_Value (Next_Actual (Param))),
1227 Selector_Name =>
1228 New_Occurrence_Of
1229 (First_Tag_Component (Typ), Loc))),
1230 Right_Opnd => New_Call);
1232 SCIL_Related_Node := Right_Opnd (New_Call);
1233 end if;
1235 else
1236 New_Call :=
1237 Make_Procedure_Call_Statement (Loc,
1238 Name => New_Call_Name,
1239 Parameter_Associations => New_Params);
1240 end if;
1242 -- Register the dispatching call in the call graph nodes table
1244 Register_CG_Node (Call_Node);
1246 Rewrite (Call_Node, New_Call);
1248 -- Associate the SCIL node of this dispatching call
1250 if Generate_SCIL then
1251 Set_SCIL_Node (SCIL_Related_Node, SCIL_Node);
1252 end if;
1254 -- Suppress all checks during the analysis of the expanded code to avoid
1255 -- the generation of spurious warnings under ZFP run-time.
1257 Analyze_And_Resolve (Call_Node, Call_Typ, Suppress => All_Checks);
1258 end Expand_Dispatching_Call;
1260 ---------------------------------
1261 -- Expand_Interface_Conversion --
1262 ---------------------------------
1264 procedure Expand_Interface_Conversion (N : Node_Id) is
1265 function Underlying_Record_Type (Typ : Entity_Id) return Entity_Id;
1266 -- Return the underlying record type of Typ
1268 ----------------------------
1269 -- Underlying_Record_Type --
1270 ----------------------------
1272 function Underlying_Record_Type (Typ : Entity_Id) return Entity_Id is
1273 E : Entity_Id := Typ;
1275 begin
1276 -- Handle access types
1278 if Is_Access_Type (E) then
1279 E := Directly_Designated_Type (E);
1280 end if;
1282 -- Handle class-wide types. This conversion can appear explicitly in
1283 -- the source code. Example: I'Class (Obj)
1285 if Is_Class_Wide_Type (E) then
1286 E := Root_Type (E);
1287 end if;
1289 -- If the target type is a tagged synchronized type, the dispatch
1290 -- table info is in the corresponding record type.
1292 if Is_Concurrent_Type (E) then
1293 E := Corresponding_Record_Type (E);
1294 end if;
1296 -- Handle private types
1298 E := Underlying_Type (E);
1300 -- Handle subtypes
1302 return Base_Type (E);
1303 end Underlying_Record_Type;
1305 -- Local variables
1307 Loc : constant Source_Ptr := Sloc (N);
1308 Etyp : constant Entity_Id := Etype (N);
1309 Operand : constant Node_Id := Expression (N);
1310 Operand_Typ : Entity_Id := Etype (Operand);
1311 Func : Node_Id;
1312 Iface_Typ : constant Entity_Id := Underlying_Record_Type (Etype (N));
1313 Iface_Tag : Entity_Id;
1314 Is_Static : Boolean;
1316 -- Start of processing for Expand_Interface_Conversion
1318 begin
1319 -- Freeze the entity associated with the target interface to have
1320 -- available the attribute Access_Disp_Table.
1322 Freeze_Before (N, Iface_Typ);
1324 -- Ada 2005 (AI-345): Handle synchronized interface type derivations
1326 if Is_Concurrent_Type (Operand_Typ) then
1327 Operand_Typ := Base_Type (Corresponding_Record_Type (Operand_Typ));
1328 end if;
1330 -- No displacement of the pointer to the object needed when the type of
1331 -- the operand is not an interface type and the interface is one of
1332 -- its parent types (since they share the primary dispatch table).
1334 declare
1335 Opnd : Entity_Id := Operand_Typ;
1337 begin
1338 if Is_Access_Type (Opnd) then
1339 Opnd := Designated_Type (Opnd);
1340 end if;
1342 Opnd := Underlying_Record_Type (Opnd);
1344 if not Is_Interface (Opnd)
1345 and then Is_Ancestor (Iface_Typ, Opnd, Use_Full_View => True)
1346 then
1347 return;
1348 end if;
1350 -- When the type of the operand and the target interface type match,
1351 -- it is generally safe to skip generating code to displace the
1352 -- pointer to the object to reference the secondary dispatch table
1353 -- associated with the target interface type. The exception to this
1354 -- general rule is when the underlying object of the type conversion
1355 -- is an object built by means of a dispatching constructor (since in
1356 -- such case the expansion of the constructor call is a direct call
1357 -- to an object primitive, i.e. without thunks, and the expansion of
1358 -- the constructor call adds an explicit conversion to the target
1359 -- interface type to force the displacement of the pointer to the
1360 -- object to reference the corresponding secondary dispatch table
1361 -- (cf. Make_DT and Expand_Dispatching_Constructor_Call)).
1363 -- At this stage we cannot identify whether the underlying object is
1364 -- a BIP object and hence we cannot skip generating the code to try
1365 -- displacing the pointer to the object. However, under configurable
1366 -- runtime it is safe to skip generating code to displace the pointer
1367 -- to the object, because generic dispatching constructors are not
1368 -- supported.
1370 if Opnd = Iface_Typ
1371 and then not RTE_Available (RE_Displace)
1372 then
1373 return;
1374 end if;
1375 end;
1377 -- Evaluate if we can statically displace the pointer to the object
1379 declare
1380 Opnd_Typ : constant Node_Id := Underlying_Record_Type (Operand_Typ);
1382 begin
1383 Is_Static :=
1384 not Is_Interface (Opnd_Typ)
1385 and then Interface_Present_In_Ancestor
1386 (Typ => Opnd_Typ,
1387 Iface => Iface_Typ)
1388 and then (Etype (Opnd_Typ) = Opnd_Typ
1389 or else not
1390 Is_Variable_Size_Record (Etype (Opnd_Typ)));
1391 end;
1393 if not Tagged_Type_Expansion then
1394 return;
1396 -- A static conversion to an interface type that is not class-wide is
1397 -- curious but legal if the interface operation is a null procedure.
1398 -- If the operation is abstract it will be rejected later.
1400 elsif Is_Static
1401 and then Is_Interface (Etype (N))
1402 and then not Is_Class_Wide_Type (Etype (N))
1403 and then Comes_From_Source (N)
1404 then
1405 Rewrite (N, Unchecked_Convert_To (Etype (N), N));
1406 Analyze (N);
1407 return;
1408 end if;
1410 if not Is_Static then
1412 -- Give error if configurable run-time and Displace not available
1414 if not RTE_Available (RE_Displace) then
1415 Error_Msg_CRT ("dynamic interface conversion", N);
1416 return;
1417 end if;
1419 -- Handle conversion of access-to-class-wide interface types. Target
1420 -- can be an access to an object or an access to another class-wide
1421 -- interface (see -1- and -2- in the following example):
1423 -- type Iface1_Ref is access all Iface1'Class;
1424 -- type Iface2_Ref is access all Iface1'Class;
1426 -- Acc1 : Iface1_Ref := new ...
1427 -- Obj : Obj_Ref := Obj_Ref (Acc); -- 1
1428 -- Acc2 : Iface2_Ref := Iface2_Ref (Acc); -- 2
1430 if Is_Access_Type (Operand_Typ) then
1431 Rewrite (N,
1432 Unchecked_Convert_To (Etype (N),
1433 Make_Function_Call (Loc,
1434 Name => New_Occurrence_Of (RTE (RE_Displace), Loc),
1435 Parameter_Associations => New_List (
1437 Unchecked_Convert_To (RTE (RE_Address),
1438 Relocate_Node (Expression (N))),
1440 New_Occurrence_Of
1441 (Node (First_Elmt (Access_Disp_Table (Iface_Typ))),
1442 Loc)))));
1444 Analyze (N);
1445 return;
1446 end if;
1448 Rewrite (N,
1449 Make_Function_Call (Loc,
1450 Name => New_Occurrence_Of (RTE (RE_Displace), Loc),
1451 Parameter_Associations => New_List (
1452 Make_Attribute_Reference (Loc,
1453 Prefix => Relocate_Node (Expression (N)),
1454 Attribute_Name => Name_Address),
1456 New_Occurrence_Of
1457 (Node (First_Elmt (Access_Disp_Table (Iface_Typ))),
1458 Loc))));
1460 Analyze (N);
1462 -- If target is a class-wide interface, change the type of the data
1463 -- returned by IW_Convert to indicate this is a dispatching call.
1465 declare
1466 New_Itype : Entity_Id;
1468 begin
1469 New_Itype := Create_Itype (E_Anonymous_Access_Type, N);
1470 Set_Etype (New_Itype, New_Itype);
1471 Set_Directly_Designated_Type (New_Itype, Etyp);
1473 Rewrite (N,
1474 Make_Explicit_Dereference (Loc,
1475 Prefix =>
1476 Unchecked_Convert_To (New_Itype, Relocate_Node (N))));
1477 Analyze (N);
1478 Freeze_Itype (New_Itype, N);
1480 return;
1481 end;
1482 end if;
1484 Iface_Tag := Find_Interface_Tag (Operand_Typ, Iface_Typ);
1485 pragma Assert (Present (Iface_Tag));
1487 -- Keep separate access types to interfaces because one internal
1488 -- function is used to handle the null value (see following comments)
1490 if not Is_Access_Type (Etype (N)) then
1492 -- Statically displace the pointer to the object to reference the
1493 -- component containing the secondary dispatch table.
1495 Rewrite (N,
1496 Convert_Tag_To_Interface (Class_Wide_Type (Iface_Typ),
1497 Make_Selected_Component (Loc,
1498 Prefix => Relocate_Node (Expression (N)),
1499 Selector_Name => New_Occurrence_Of (Iface_Tag, Loc))));
1501 else
1502 -- Build internal function to handle the case in which the actual is
1503 -- null. If the actual is null returns null because no displacement
1504 -- is required; otherwise performs a type conversion that will be
1505 -- expanded in the code that returns the value of the displaced
1506 -- actual. That is:
1508 -- function Func (O : Address) return Iface_Typ is
1509 -- type Op_Typ is access all Operand_Typ;
1510 -- Aux : Op_Typ := To_Op_Typ (O);
1511 -- begin
1512 -- if O = Null_Address then
1513 -- return null;
1514 -- else
1515 -- return Iface_Typ!(Aux.Iface_Tag'Address);
1516 -- end if;
1517 -- end Func;
1519 declare
1520 Desig_Typ : Entity_Id;
1521 Fent : Entity_Id;
1522 New_Typ_Decl : Node_Id;
1523 Stats : List_Id;
1525 begin
1526 Desig_Typ := Etype (Expression (N));
1528 if Is_Access_Type (Desig_Typ) then
1529 Desig_Typ :=
1530 Available_View (Directly_Designated_Type (Desig_Typ));
1531 end if;
1533 if Is_Concurrent_Type (Desig_Typ) then
1534 Desig_Typ := Base_Type (Corresponding_Record_Type (Desig_Typ));
1535 end if;
1537 New_Typ_Decl :=
1538 Make_Full_Type_Declaration (Loc,
1539 Defining_Identifier => Make_Temporary (Loc, 'T'),
1540 Type_Definition =>
1541 Make_Access_To_Object_Definition (Loc,
1542 All_Present => True,
1543 Null_Exclusion_Present => False,
1544 Constant_Present => False,
1545 Subtype_Indication =>
1546 New_Occurrence_Of (Desig_Typ, Loc)));
1548 Stats := New_List (
1549 Make_Simple_Return_Statement (Loc,
1550 Unchecked_Convert_To (Etype (N),
1551 Make_Attribute_Reference (Loc,
1552 Prefix =>
1553 Make_Selected_Component (Loc,
1554 Prefix =>
1555 Unchecked_Convert_To
1556 (Defining_Identifier (New_Typ_Decl),
1557 Make_Identifier (Loc, Name_uO)),
1558 Selector_Name =>
1559 New_Occurrence_Of (Iface_Tag, Loc)),
1560 Attribute_Name => Name_Address))));
1562 -- If the type is null-excluding, no need for the null branch.
1563 -- Otherwise we need to check for it and return null.
1565 if not Can_Never_Be_Null (Etype (N)) then
1566 Stats := New_List (
1567 Make_If_Statement (Loc,
1568 Condition =>
1569 Make_Op_Eq (Loc,
1570 Left_Opnd => Make_Identifier (Loc, Name_uO),
1571 Right_Opnd => New_Occurrence_Of
1572 (RTE (RE_Null_Address), Loc)),
1574 Then_Statements => New_List (
1575 Make_Simple_Return_Statement (Loc, Make_Null (Loc))),
1576 Else_Statements => Stats));
1577 end if;
1579 Fent := Make_Temporary (Loc, 'F');
1580 Func :=
1581 Make_Subprogram_Body (Loc,
1582 Specification =>
1583 Make_Function_Specification (Loc,
1584 Defining_Unit_Name => Fent,
1586 Parameter_Specifications => New_List (
1587 Make_Parameter_Specification (Loc,
1588 Defining_Identifier =>
1589 Make_Defining_Identifier (Loc, Name_uO),
1590 Parameter_Type =>
1591 New_Occurrence_Of (RTE (RE_Address), Loc))),
1593 Result_Definition =>
1594 New_Occurrence_Of (Etype (N), Loc)),
1596 Declarations => New_List (New_Typ_Decl),
1598 Handled_Statement_Sequence =>
1599 Make_Handled_Sequence_Of_Statements (Loc, Stats));
1601 -- Place function body before the expression containing the
1602 -- conversion. We suppress all checks because the body of the
1603 -- internally generated function already takes care of the case
1604 -- in which the actual is null; therefore there is no need to
1605 -- double check that the pointer is not null when the program
1606 -- executes the alternative that performs the type conversion).
1608 Insert_Action (N, Func, Suppress => All_Checks);
1610 if Is_Access_Type (Etype (Expression (N))) then
1612 -- Generate: Func (Address!(Expression))
1614 Rewrite (N,
1615 Make_Function_Call (Loc,
1616 Name => New_Occurrence_Of (Fent, Loc),
1617 Parameter_Associations => New_List (
1618 Unchecked_Convert_To (RTE (RE_Address),
1619 Relocate_Node (Expression (N))))));
1621 else
1622 -- Generate: Func (Operand_Typ!(Expression)'Address)
1624 Rewrite (N,
1625 Make_Function_Call (Loc,
1626 Name => New_Occurrence_Of (Fent, Loc),
1627 Parameter_Associations => New_List (
1628 Make_Attribute_Reference (Loc,
1629 Prefix => Unchecked_Convert_To (Operand_Typ,
1630 Relocate_Node (Expression (N))),
1631 Attribute_Name => Name_Address))));
1632 end if;
1633 end;
1634 end if;
1636 Analyze (N);
1637 end Expand_Interface_Conversion;
1639 ------------------------------
1640 -- Expand_Interface_Actuals --
1641 ------------------------------
1643 procedure Expand_Interface_Actuals (Call_Node : Node_Id) is
1644 Actual : Node_Id;
1645 Actual_Dup : Node_Id;
1646 Actual_Typ : Entity_Id;
1647 Anon : Entity_Id;
1648 Conversion : Node_Id;
1649 Formal : Entity_Id;
1650 Formal_Typ : Entity_Id;
1651 Subp : Entity_Id;
1652 Formal_DDT : Entity_Id := Empty; -- initialize to prevent warning
1653 Actual_DDT : Entity_Id := Empty; -- initialize to prevent warning
1655 begin
1656 -- This subprogram is called directly from the semantics, so we need a
1657 -- check to see whether expansion is active before proceeding.
1659 if not Expander_Active then
1660 return;
1661 end if;
1663 -- Call using access to subprogram with explicit dereference
1665 if Nkind (Name (Call_Node)) = N_Explicit_Dereference then
1666 Subp := Etype (Name (Call_Node));
1668 -- Call using selected component
1670 elsif Nkind (Name (Call_Node)) = N_Selected_Component then
1671 Subp := Entity (Selector_Name (Name (Call_Node)));
1673 -- Call using direct name
1675 else
1676 Subp := Entity (Name (Call_Node));
1677 end if;
1679 -- Ada 2005 (AI-251): Look for interface type formals to force "this"
1680 -- displacement
1682 Formal := First_Formal (Subp);
1683 Actual := First_Actual (Call_Node);
1684 while Present (Formal) loop
1685 Formal_Typ := Etype (Formal);
1687 if Ekind (Formal_Typ) = E_Record_Type_With_Private then
1688 Formal_Typ := Full_View (Formal_Typ);
1689 end if;
1691 if Is_Access_Type (Formal_Typ) then
1692 Formal_DDT := Directly_Designated_Type (Formal_Typ);
1693 end if;
1695 Actual_Typ := Etype (Actual);
1697 if Is_Access_Type (Actual_Typ) then
1698 Actual_DDT := Directly_Designated_Type (Actual_Typ);
1699 end if;
1701 if Is_Interface (Formal_Typ)
1702 and then Is_Class_Wide_Type (Formal_Typ)
1703 then
1704 -- No need to displace the pointer if the type of the actual
1705 -- coincides with the type of the formal.
1707 if Actual_Typ = Formal_Typ then
1708 null;
1710 -- No need to displace the pointer if the interface type is a
1711 -- parent of the type of the actual because in this case the
1712 -- interface primitives are located in the primary dispatch table.
1714 elsif Is_Ancestor (Formal_Typ, Actual_Typ,
1715 Use_Full_View => True)
1716 then
1717 null;
1719 -- Implicit conversion to the class-wide formal type to force the
1720 -- displacement of the pointer.
1722 else
1723 -- Normally, expansion of actuals for calls to build-in-place
1724 -- functions happens as part of Expand_Actuals, but in this
1725 -- case the call will be wrapped in a conversion and soon after
1726 -- expanded further to handle the displacement for a class-wide
1727 -- interface conversion, so if this is a BIP call then we need
1728 -- to handle it now.
1730 if Is_Build_In_Place_Function_Call (Actual) then
1731 Make_Build_In_Place_Call_In_Anonymous_Context (Actual);
1732 end if;
1734 Conversion := Convert_To (Formal_Typ, Relocate_Node (Actual));
1735 Rewrite (Actual, Conversion);
1736 Analyze_And_Resolve (Actual, Formal_Typ);
1737 end if;
1739 -- Access to class-wide interface type
1741 elsif Is_Access_Type (Formal_Typ)
1742 and then Is_Interface (Formal_DDT)
1743 and then Is_Class_Wide_Type (Formal_DDT)
1744 and then Interface_Present_In_Ancestor
1745 (Typ => Actual_DDT,
1746 Iface => Etype (Formal_DDT))
1747 then
1748 -- Handle attributes 'Access and 'Unchecked_Access
1750 if Nkind (Actual) = N_Attribute_Reference
1751 and then
1752 (Attribute_Name (Actual) = Name_Access
1753 or else Attribute_Name (Actual) = Name_Unchecked_Access)
1754 then
1755 -- This case must have been handled by the analysis and
1756 -- expansion of 'Access. The only exception is when types
1757 -- match and no further expansion is required.
1759 pragma Assert (Base_Type (Etype (Prefix (Actual)))
1760 = Base_Type (Formal_DDT));
1761 null;
1763 -- No need to displace the pointer if the type of the actual
1764 -- coincides with the type of the formal.
1766 elsif Actual_DDT = Formal_DDT then
1767 null;
1769 -- No need to displace the pointer if the interface type is
1770 -- a parent of the type of the actual because in this case the
1771 -- interface primitives are located in the primary dispatch table.
1773 elsif Is_Ancestor (Formal_DDT, Actual_DDT,
1774 Use_Full_View => True)
1775 then
1776 null;
1778 else
1779 Actual_Dup := Relocate_Node (Actual);
1781 if From_Limited_With (Actual_Typ) then
1783 -- If the type of the actual parameter comes from a limited
1784 -- with_clause and the nonlimited view is already available,
1785 -- we replace the anonymous access type by a duplicate
1786 -- declaration whose designated type is the nonlimited view.
1788 if Has_Non_Limited_View (Actual_DDT) then
1789 Anon := New_Copy (Actual_Typ);
1791 if Is_Itype (Anon) then
1792 Set_Scope (Anon, Current_Scope);
1793 end if;
1795 Set_Directly_Designated_Type
1796 (Anon, Non_Limited_View (Actual_DDT));
1797 Set_Etype (Actual_Dup, Anon);
1798 end if;
1799 end if;
1801 Conversion := Convert_To (Formal_Typ, Actual_Dup);
1802 Rewrite (Actual, Conversion);
1803 Analyze_And_Resolve (Actual, Formal_Typ);
1804 end if;
1805 end if;
1807 Next_Actual (Actual);
1808 Next_Formal (Formal);
1809 end loop;
1810 end Expand_Interface_Actuals;
1812 ----------------------------
1813 -- Expand_Interface_Thunk --
1814 ----------------------------
1816 procedure Expand_Interface_Thunk
1817 (Prim : Node_Id;
1818 Thunk_Id : out Entity_Id;
1819 Thunk_Code : out Node_Id)
1821 Loc : constant Source_Ptr := Sloc (Prim);
1822 Actuals : constant List_Id := New_List;
1823 Decl : constant List_Id := New_List;
1824 Formals : constant List_Id := New_List;
1825 Target : constant Entity_Id := Ultimate_Alias (Prim);
1827 Decl_1 : Node_Id;
1828 Decl_2 : Node_Id;
1829 Expr : Node_Id;
1830 Formal : Node_Id;
1831 Ftyp : Entity_Id;
1832 Iface_Formal : Node_Id := Empty; -- initialize to prevent warning
1833 New_Arg : Node_Id;
1834 Offset_To_Top : Node_Id;
1835 Target_Formal : Entity_Id;
1837 begin
1838 Thunk_Id := Empty;
1839 Thunk_Code := Empty;
1841 -- No thunk needed if the primitive has been eliminated
1843 if Is_Eliminated (Ultimate_Alias (Prim)) then
1844 return;
1846 -- In case of primitives that are functions without formals and a
1847 -- controlling result there is no need to build the thunk.
1849 elsif not Present (First_Formal (Target)) then
1850 pragma Assert (Ekind (Target) = E_Function
1851 and then Has_Controlling_Result (Target));
1852 return;
1853 end if;
1855 -- Duplicate the formals of the Target primitive. In the thunk, the type
1856 -- of the controlling formal is the covered interface type (instead of
1857 -- the target tagged type). Done to avoid problems with discriminated
1858 -- tagged types because, if the controlling type has discriminants with
1859 -- default values, then the type conversions done inside the body of
1860 -- the thunk (after the displacement of the pointer to the base of the
1861 -- actual object) generate code that modify its contents.
1863 -- Note: This special management is not done for predefined primitives
1864 -- because???
1866 if not Is_Predefined_Dispatching_Operation (Prim) then
1867 Iface_Formal := First_Formal (Interface_Alias (Prim));
1868 end if;
1870 Formal := First_Formal (Target);
1871 while Present (Formal) loop
1872 Ftyp := Etype (Formal);
1874 -- Use the interface type as the type of the controlling formal (see
1875 -- comment above).
1877 if not Is_Controlling_Formal (Formal)
1878 or else Is_Predefined_Dispatching_Operation (Prim)
1879 then
1880 Ftyp := Etype (Formal);
1881 Expr := New_Copy_Tree (Expression (Parent (Formal)));
1882 else
1883 Ftyp := Etype (Iface_Formal);
1884 Expr := Empty;
1885 end if;
1887 Append_To (Formals,
1888 Make_Parameter_Specification (Loc,
1889 Defining_Identifier =>
1890 Make_Defining_Identifier (Sloc (Formal),
1891 Chars => Chars (Formal)),
1892 In_Present => In_Present (Parent (Formal)),
1893 Out_Present => Out_Present (Parent (Formal)),
1894 Parameter_Type => New_Occurrence_Of (Ftyp, Loc),
1895 Expression => Expr));
1897 if not Is_Predefined_Dispatching_Operation (Prim) then
1898 Next_Formal (Iface_Formal);
1899 end if;
1901 Next_Formal (Formal);
1902 end loop;
1904 Target_Formal := First_Formal (Target);
1905 Formal := First (Formals);
1906 while Present (Formal) loop
1908 -- If the parent is a constrained discriminated type, then the
1909 -- primitive operation will have been defined on a first subtype.
1910 -- For proper matching with controlling type, use base type.
1912 if Ekind (Target_Formal) = E_In_Parameter
1913 and then Ekind (Etype (Target_Formal)) = E_Anonymous_Access_Type
1914 then
1915 Ftyp :=
1916 Base_Type (Directly_Designated_Type (Etype (Target_Formal)));
1917 else
1918 Ftyp := Base_Type (Etype (Target_Formal));
1919 end if;
1921 -- For concurrent types, the relevant information is found in the
1922 -- Corresponding_Record_Type, rather than the type entity itself.
1924 if Is_Concurrent_Type (Ftyp) then
1925 Ftyp := Corresponding_Record_Type (Ftyp);
1926 end if;
1928 if Ekind (Target_Formal) = E_In_Parameter
1929 and then Ekind (Etype (Target_Formal)) = E_Anonymous_Access_Type
1930 and then Is_Controlling_Formal (Target_Formal)
1931 then
1932 -- Generate:
1933 -- type T is access all <<type of the target formal>>
1934 -- S : Storage_Offset := Storage_Offset!(Formal)
1935 -- + Offset_To_Top (address!(Formal))
1937 Decl_2 :=
1938 Make_Full_Type_Declaration (Loc,
1939 Defining_Identifier => Make_Temporary (Loc, 'T'),
1940 Type_Definition =>
1941 Make_Access_To_Object_Definition (Loc,
1942 All_Present => True,
1943 Null_Exclusion_Present => False,
1944 Constant_Present => False,
1945 Subtype_Indication =>
1946 New_Occurrence_Of (Ftyp, Loc)));
1948 New_Arg :=
1949 Unchecked_Convert_To (RTE (RE_Address),
1950 New_Occurrence_Of (Defining_Identifier (Formal), Loc));
1952 if not RTE_Available (RE_Offset_To_Top) then
1953 Offset_To_Top :=
1954 Build_Offset_To_Top (Loc, New_Arg);
1955 else
1956 Offset_To_Top :=
1957 Make_Function_Call (Loc,
1958 Name => New_Occurrence_Of (RTE (RE_Offset_To_Top), Loc),
1959 Parameter_Associations => New_List (New_Arg));
1960 end if;
1962 Decl_1 :=
1963 Make_Object_Declaration (Loc,
1964 Defining_Identifier => Make_Temporary (Loc, 'S'),
1965 Constant_Present => True,
1966 Object_Definition =>
1967 New_Occurrence_Of (RTE (RE_Storage_Offset), Loc),
1968 Expression =>
1969 Make_Op_Add (Loc,
1970 Left_Opnd =>
1971 Unchecked_Convert_To
1972 (RTE (RE_Storage_Offset),
1973 New_Occurrence_Of
1974 (Defining_Identifier (Formal), Loc)),
1975 Right_Opnd =>
1976 Offset_To_Top));
1978 Append_To (Decl, Decl_2);
1979 Append_To (Decl, Decl_1);
1981 -- Reference the new actual. Generate:
1982 -- T!(S)
1984 Append_To (Actuals,
1985 Unchecked_Convert_To
1986 (Defining_Identifier (Decl_2),
1987 New_Occurrence_Of (Defining_Identifier (Decl_1), Loc)));
1989 elsif Is_Controlling_Formal (Target_Formal) then
1991 -- Generate:
1992 -- S1 : Storage_Offset := Storage_Offset!(Formal'Address)
1993 -- + Offset_To_Top (Formal'Address)
1994 -- S2 : Addr_Ptr := Addr_Ptr!(S1)
1996 New_Arg :=
1997 Make_Attribute_Reference (Loc,
1998 Prefix =>
1999 New_Occurrence_Of (Defining_Identifier (Formal), Loc),
2000 Attribute_Name =>
2001 Name_Address);
2003 if not RTE_Available (RE_Offset_To_Top) then
2004 Offset_To_Top :=
2005 Build_Offset_To_Top (Loc, New_Arg);
2006 else
2007 Offset_To_Top :=
2008 Make_Function_Call (Loc,
2009 Name => New_Occurrence_Of (RTE (RE_Offset_To_Top), Loc),
2010 Parameter_Associations => New_List (New_Arg));
2011 end if;
2013 Decl_1 :=
2014 Make_Object_Declaration (Loc,
2015 Defining_Identifier => Make_Temporary (Loc, 'S'),
2016 Constant_Present => True,
2017 Object_Definition =>
2018 New_Occurrence_Of (RTE (RE_Storage_Offset), Loc),
2019 Expression =>
2020 Make_Op_Add (Loc,
2021 Left_Opnd =>
2022 Unchecked_Convert_To
2023 (RTE (RE_Storage_Offset),
2024 Make_Attribute_Reference (Loc,
2025 Prefix =>
2026 New_Occurrence_Of
2027 (Defining_Identifier (Formal), Loc),
2028 Attribute_Name => Name_Address)),
2029 Right_Opnd =>
2030 Offset_To_Top));
2032 Decl_2 :=
2033 Make_Object_Declaration (Loc,
2034 Defining_Identifier => Make_Temporary (Loc, 'S'),
2035 Constant_Present => True,
2036 Object_Definition =>
2037 New_Occurrence_Of (RTE (RE_Addr_Ptr), Loc),
2038 Expression =>
2039 Unchecked_Convert_To
2040 (RTE (RE_Addr_Ptr),
2041 New_Occurrence_Of (Defining_Identifier (Decl_1), Loc)));
2043 Append_To (Decl, Decl_1);
2044 Append_To (Decl, Decl_2);
2046 -- Reference the new actual, generate:
2047 -- Target_Formal (S2.all)
2049 Append_To (Actuals,
2050 Unchecked_Convert_To (Ftyp,
2051 Make_Explicit_Dereference (Loc,
2052 New_Occurrence_Of (Defining_Identifier (Decl_2), Loc))));
2054 -- Ensure proper matching of access types. Required to avoid
2055 -- reporting spurious errors.
2057 elsif Is_Access_Type (Etype (Target_Formal)) then
2058 Append_To (Actuals,
2059 Unchecked_Convert_To (Base_Type (Etype (Target_Formal)),
2060 New_Occurrence_Of (Defining_Identifier (Formal), Loc)));
2062 -- No special management required for this actual
2064 else
2065 Append_To (Actuals,
2066 New_Occurrence_Of (Defining_Identifier (Formal), Loc));
2067 end if;
2069 Next_Formal (Target_Formal);
2070 Next (Formal);
2071 end loop;
2073 Thunk_Id := Make_Temporary (Loc, 'T');
2074 Set_Ekind (Thunk_Id, Ekind (Prim));
2075 Set_Is_Thunk (Thunk_Id);
2076 Set_Convention (Thunk_Id, Convention (Prim));
2077 Set_Needs_Debug_Info (Thunk_Id, Needs_Debug_Info (Target));
2078 Set_Thunk_Entity (Thunk_Id, Target);
2080 -- Procedure case
2082 if Ekind (Target) = E_Procedure then
2083 Thunk_Code :=
2084 Make_Subprogram_Body (Loc,
2085 Specification =>
2086 Make_Procedure_Specification (Loc,
2087 Defining_Unit_Name => Thunk_Id,
2088 Parameter_Specifications => Formals),
2089 Declarations => Decl,
2090 Handled_Statement_Sequence =>
2091 Make_Handled_Sequence_Of_Statements (Loc,
2092 Statements => New_List (
2093 Make_Procedure_Call_Statement (Loc,
2094 Name => New_Occurrence_Of (Target, Loc),
2095 Parameter_Associations => Actuals))));
2097 -- Function case
2099 else pragma Assert (Ekind (Target) = E_Function);
2100 declare
2101 Result_Def : Node_Id;
2102 Call_Node : Node_Id;
2104 begin
2105 Call_Node :=
2106 Make_Function_Call (Loc,
2107 Name => New_Occurrence_Of (Target, Loc),
2108 Parameter_Associations => Actuals);
2110 if not Is_Interface (Etype (Prim)) then
2111 Result_Def := New_Copy (Result_Definition (Parent (Target)));
2113 -- Thunk of function returning a class-wide interface object. No
2114 -- extra displacement needed since the displacement is generated
2115 -- in the return statement of Prim. Example:
2117 -- type Iface is interface ...
2118 -- function F (O : Iface) return Iface'Class;
2120 -- type T is new ... and Iface with ...
2121 -- function F (O : T) return Iface'Class;
2123 elsif Is_Class_Wide_Type (Etype (Prim)) then
2124 Result_Def := New_Occurrence_Of (Etype (Prim), Loc);
2126 -- Thunk of function returning an interface object. Displacement
2127 -- needed. Example:
2129 -- type Iface is interface ...
2130 -- function F (O : Iface) return Iface;
2132 -- type T is new ... and Iface with ...
2133 -- function F (O : T) return T;
2135 else
2136 Result_Def :=
2137 New_Occurrence_Of (Class_Wide_Type (Etype (Prim)), Loc);
2139 -- Adding implicit conversion to force the displacement of
2140 -- the pointer to the object to reference the corresponding
2141 -- secondary dispatch table.
2143 Call_Node :=
2144 Make_Type_Conversion (Loc,
2145 Subtype_Mark =>
2146 New_Occurrence_Of (Class_Wide_Type (Etype (Prim)), Loc),
2147 Expression => Relocate_Node (Call_Node));
2148 end if;
2150 Thunk_Code :=
2151 Make_Subprogram_Body (Loc,
2152 Specification =>
2153 Make_Function_Specification (Loc,
2154 Defining_Unit_Name => Thunk_Id,
2155 Parameter_Specifications => Formals,
2156 Result_Definition => Result_Def),
2157 Declarations => Decl,
2158 Handled_Statement_Sequence =>
2159 Make_Handled_Sequence_Of_Statements (Loc,
2160 Statements => New_List (
2161 Make_Simple_Return_Statement (Loc, Call_Node))));
2162 end;
2163 end if;
2164 end Expand_Interface_Thunk;
2166 --------------------------
2167 -- Has_CPP_Constructors --
2168 --------------------------
2170 function Has_CPP_Constructors (Typ : Entity_Id) return Boolean is
2171 E : Entity_Id;
2173 begin
2174 -- Look for the constructor entities
2176 E := Next_Entity (Typ);
2177 while Present (E) loop
2178 if Ekind (E) = E_Function and then Is_Constructor (E) then
2179 return True;
2180 end if;
2182 Next_Entity (E);
2183 end loop;
2185 return False;
2186 end Has_CPP_Constructors;
2188 ------------
2189 -- Has_DT --
2190 ------------
2192 function Has_DT (Typ : Entity_Id) return Boolean is
2193 begin
2194 return not Is_Interface (Typ)
2195 and then not Restriction_Active (No_Dispatching_Calls);
2196 end Has_DT;
2198 ----------------------------------
2199 -- Is_Expanded_Dispatching_Call --
2200 ----------------------------------
2202 function Is_Expanded_Dispatching_Call (N : Node_Id) return Boolean is
2203 begin
2204 return Nkind (N) in N_Subprogram_Call
2205 and then Nkind (Name (N)) = N_Explicit_Dereference
2206 and then Is_Dispatch_Table_Entity (Etype (Name (N)));
2207 end Is_Expanded_Dispatching_Call;
2209 -------------------------------------
2210 -- Is_Predefined_Dispatching_Alias --
2211 -------------------------------------
2213 function Is_Predefined_Dispatching_Alias (Prim : Entity_Id) return Boolean
2215 begin
2216 return not Is_Predefined_Dispatching_Operation (Prim)
2217 and then Present (Alias (Prim))
2218 and then Is_Predefined_Dispatching_Operation (Ultimate_Alias (Prim));
2219 end Is_Predefined_Dispatching_Alias;
2221 ----------------------------------------
2222 -- Make_Disp_Asynchronous_Select_Body --
2223 ----------------------------------------
2225 -- For interface types, generate:
2227 -- procedure _Disp_Asynchronous_Select
2228 -- (T : in out <Typ>;
2229 -- S : Integer;
2230 -- P : System.Address;
2231 -- B : out System.Storage_Elements.Dummy_Communication_Block;
2232 -- F : out Boolean)
2233 -- is
2234 -- begin
2235 -- F := False;
2236 -- C := Ada.Tags.POK_Function;
2237 -- end _Disp_Asynchronous_Select;
2239 -- For protected types, generate:
2241 -- procedure _Disp_Asynchronous_Select
2242 -- (T : in out <Typ>;
2243 -- S : Integer;
2244 -- P : System.Address;
2245 -- B : out System.Storage_Elements.Dummy_Communication_Block;
2246 -- F : out Boolean)
2247 -- is
2248 -- I : Integer :=
2249 -- Ada.Tags.Get_Entry_Index (Ada.Tags.Tag (<Typ>VP, S));
2250 -- Bnn : System.Tasking.Protected_Objects.Operations.
2251 -- Communication_Block;
2252 -- begin
2253 -- System.Tasking.Protected_Objects.Operations.Protected_Entry_Call
2254 -- (T._object'Access,
2255 -- System.Tasking.Protected_Objects.Protected_Entry_Index (I),
2256 -- P,
2257 -- System.Tasking.Asynchronous_Call,
2258 -- Bnn);
2259 -- B := System.Storage_Elements.Dummy_Communication_Block (Bnn);
2260 -- end _Disp_Asynchronous_Select;
2262 -- For task types, generate:
2264 -- procedure _Disp_Asynchronous_Select
2265 -- (T : in out <Typ>;
2266 -- S : Integer;
2267 -- P : System.Address;
2268 -- B : out System.Storage_Elements.Dummy_Communication_Block;
2269 -- F : out Boolean)
2270 -- is
2271 -- I : Integer :=
2272 -- Ada.Tags.Get_Entry_Index (Ada.Tags.Tag (<Typ>VP, S));
2273 -- begin
2274 -- System.Tasking.Rendezvous.Task_Entry_Call
2275 -- (T._task_id,
2276 -- System.Tasking.Task_Entry_Index (I),
2277 -- P,
2278 -- System.Tasking.Asynchronous_Call,
2279 -- F);
2280 -- end _Disp_Asynchronous_Select;
2282 function Make_Disp_Asynchronous_Select_Body
2283 (Typ : Entity_Id) return Node_Id
2285 Com_Block : Entity_Id;
2286 Conc_Typ : Entity_Id := Empty;
2287 Decls : constant List_Id := New_List;
2288 Loc : constant Source_Ptr := Sloc (Typ);
2289 Obj_Ref : Node_Id;
2290 Stmts : constant List_Id := New_List;
2291 Tag_Node : Node_Id;
2293 begin
2294 pragma Assert (not Restriction_Active (No_Dispatching_Calls));
2296 -- Null body is generated for interface types
2298 if Is_Interface (Typ) then
2299 return
2300 Make_Subprogram_Body (Loc,
2301 Specification =>
2302 Make_Disp_Asynchronous_Select_Spec (Typ),
2303 Declarations => New_List,
2304 Handled_Statement_Sequence =>
2305 Make_Handled_Sequence_Of_Statements (Loc,
2306 New_List (
2307 Make_Assignment_Statement (Loc,
2308 Name => Make_Identifier (Loc, Name_uF),
2309 Expression => New_Occurrence_Of (Standard_False, Loc)))));
2310 end if;
2312 if Is_Concurrent_Record_Type (Typ) then
2313 Conc_Typ := Corresponding_Concurrent_Type (Typ);
2315 -- Generate:
2316 -- I : Integer :=
2317 -- Ada.Tags.Get_Entry_Index (Ada.Tags.Tag! (<type>VP), S);
2319 -- where I will be used to capture the entry index of the primitive
2320 -- wrapper at position S.
2322 if Tagged_Type_Expansion then
2323 Tag_Node :=
2324 Unchecked_Convert_To (RTE (RE_Tag),
2325 New_Occurrence_Of
2326 (Node (First_Elmt (Access_Disp_Table (Typ))), Loc));
2327 else
2328 Tag_Node :=
2329 Make_Attribute_Reference (Loc,
2330 Prefix => New_Occurrence_Of (Typ, Loc),
2331 Attribute_Name => Name_Tag);
2332 end if;
2334 Append_To (Decls,
2335 Make_Object_Declaration (Loc,
2336 Defining_Identifier =>
2337 Make_Defining_Identifier (Loc, Name_uI),
2338 Object_Definition =>
2339 New_Occurrence_Of (Standard_Integer, Loc),
2340 Expression =>
2341 Make_Function_Call (Loc,
2342 Name =>
2343 New_Occurrence_Of (RTE (RE_Get_Entry_Index), Loc),
2344 Parameter_Associations =>
2345 New_List (Tag_Node, Make_Identifier (Loc, Name_uS)))));
2347 if Ekind (Conc_Typ) = E_Protected_Type then
2349 -- Generate:
2350 -- Bnn : Communication_Block;
2352 Com_Block := Make_Temporary (Loc, 'B');
2353 Append_To (Decls,
2354 Make_Object_Declaration (Loc,
2355 Defining_Identifier => Com_Block,
2356 Object_Definition =>
2357 New_Occurrence_Of (RTE (RE_Communication_Block), Loc)));
2359 -- Build T._object'Access for calls below
2361 Obj_Ref :=
2362 Make_Attribute_Reference (Loc,
2363 Attribute_Name => Name_Unchecked_Access,
2364 Prefix =>
2365 Make_Selected_Component (Loc,
2366 Prefix => Make_Identifier (Loc, Name_uT),
2367 Selector_Name => Make_Identifier (Loc, Name_uObject)));
2369 case Corresponding_Runtime_Package (Conc_Typ) is
2370 when System_Tasking_Protected_Objects_Entries =>
2372 -- Generate:
2373 -- Protected_Entry_Call
2374 -- (T._object'Access, -- Object
2375 -- Protected_Entry_Index! (I), -- E
2376 -- P, -- Uninterpreted_Data
2377 -- Asynchronous_Call, -- Mode
2378 -- Bnn); -- Communication_Block
2380 -- where T is the protected object, I is the entry index, P
2381 -- is the wrapped parameters and B is the name of the
2382 -- communication block.
2384 Append_To (Stmts,
2385 Make_Procedure_Call_Statement (Loc,
2386 Name =>
2387 New_Occurrence_Of (RTE (RE_Protected_Entry_Call), Loc),
2388 Parameter_Associations =>
2389 New_List (
2390 Obj_Ref,
2392 Make_Unchecked_Type_Conversion (Loc, -- entry index
2393 Subtype_Mark =>
2394 New_Occurrence_Of
2395 (RTE (RE_Protected_Entry_Index), Loc),
2396 Expression => Make_Identifier (Loc, Name_uI)),
2398 Make_Identifier (Loc, Name_uP), -- parameter block
2399 New_Occurrence_Of -- Asynchronous_Call
2400 (RTE (RE_Asynchronous_Call), Loc),
2401 New_Occurrence_Of -- comm block
2402 (Com_Block, Loc))));
2404 when others =>
2405 raise Program_Error;
2406 end case;
2408 -- Generate:
2409 -- B := Dummy_Communication_Block (Bnn);
2411 Append_To (Stmts,
2412 Make_Assignment_Statement (Loc,
2413 Name => Make_Identifier (Loc, Name_uB),
2414 Expression =>
2415 Make_Unchecked_Type_Conversion (Loc,
2416 Subtype_Mark =>
2417 New_Occurrence_Of
2418 (RTE (RE_Dummy_Communication_Block), Loc),
2419 Expression => New_Occurrence_Of (Com_Block, Loc))));
2421 -- Generate:
2422 -- F := False;
2424 Append_To (Stmts,
2425 Make_Assignment_Statement (Loc,
2426 Name => Make_Identifier (Loc, Name_uF),
2427 Expression => New_Occurrence_Of (Standard_False, Loc)));
2429 else
2430 pragma Assert (Ekind (Conc_Typ) = E_Task_Type);
2432 -- Generate:
2433 -- Task_Entry_Call
2434 -- (T._task_id, -- Acceptor
2435 -- Task_Entry_Index! (I), -- E
2436 -- P, -- Uninterpreted_Data
2437 -- Asynchronous_Call, -- Mode
2438 -- F); -- Rendezvous_Successful
2440 -- where T is the task object, I is the entry index, P is the
2441 -- wrapped parameters and F is the status flag.
2443 Append_To (Stmts,
2444 Make_Procedure_Call_Statement (Loc,
2445 Name =>
2446 New_Occurrence_Of (RTE (RE_Task_Entry_Call), Loc),
2447 Parameter_Associations =>
2448 New_List (
2449 Make_Selected_Component (Loc, -- T._task_id
2450 Prefix => Make_Identifier (Loc, Name_uT),
2451 Selector_Name => Make_Identifier (Loc, Name_uTask_Id)),
2453 Make_Unchecked_Type_Conversion (Loc, -- entry index
2454 Subtype_Mark =>
2455 New_Occurrence_Of (RTE (RE_Task_Entry_Index), Loc),
2456 Expression => Make_Identifier (Loc, Name_uI)),
2458 Make_Identifier (Loc, Name_uP), -- parameter block
2459 New_Occurrence_Of -- Asynchronous_Call
2460 (RTE (RE_Asynchronous_Call), Loc),
2461 Make_Identifier (Loc, Name_uF)))); -- status flag
2462 end if;
2464 else
2465 -- Ensure that the statements list is non-empty
2467 Append_To (Stmts,
2468 Make_Assignment_Statement (Loc,
2469 Name => Make_Identifier (Loc, Name_uF),
2470 Expression => New_Occurrence_Of (Standard_False, Loc)));
2471 end if;
2473 return
2474 Make_Subprogram_Body (Loc,
2475 Specification =>
2476 Make_Disp_Asynchronous_Select_Spec (Typ),
2477 Declarations => Decls,
2478 Handled_Statement_Sequence =>
2479 Make_Handled_Sequence_Of_Statements (Loc, Stmts));
2480 end Make_Disp_Asynchronous_Select_Body;
2482 ----------------------------------------
2483 -- Make_Disp_Asynchronous_Select_Spec --
2484 ----------------------------------------
2486 function Make_Disp_Asynchronous_Select_Spec
2487 (Typ : Entity_Id) return Node_Id
2489 Loc : constant Source_Ptr := Sloc (Typ);
2490 Def_Id : constant Node_Id :=
2491 Make_Defining_Identifier (Loc,
2492 Name_uDisp_Asynchronous_Select);
2493 Params : constant List_Id := New_List;
2495 begin
2496 pragma Assert (not Restriction_Active (No_Dispatching_Calls));
2498 -- T : in out Typ; -- Object parameter
2499 -- S : Integer; -- Primitive operation slot
2500 -- P : Address; -- Wrapped parameters
2501 -- B : out Dummy_Communication_Block; -- Communication block dummy
2502 -- F : out Boolean; -- Status flag
2504 Append_List_To (Params, New_List (
2506 Make_Parameter_Specification (Loc,
2507 Defining_Identifier => Make_Defining_Identifier (Loc, Name_uT),
2508 Parameter_Type => New_Occurrence_Of (Typ, Loc),
2509 In_Present => True,
2510 Out_Present => True),
2512 Make_Parameter_Specification (Loc,
2513 Defining_Identifier => Make_Defining_Identifier (Loc, Name_uS),
2514 Parameter_Type => New_Occurrence_Of (Standard_Integer, Loc)),
2516 Make_Parameter_Specification (Loc,
2517 Defining_Identifier => Make_Defining_Identifier (Loc, Name_uP),
2518 Parameter_Type => New_Occurrence_Of (RTE (RE_Address), Loc)),
2520 Make_Parameter_Specification (Loc,
2521 Defining_Identifier => Make_Defining_Identifier (Loc, Name_uB),
2522 Parameter_Type =>
2523 New_Occurrence_Of (RTE (RE_Dummy_Communication_Block), Loc),
2524 Out_Present => True),
2526 Make_Parameter_Specification (Loc,
2527 Defining_Identifier => Make_Defining_Identifier (Loc, Name_uF),
2528 Parameter_Type => New_Occurrence_Of (Standard_Boolean, Loc),
2529 Out_Present => True)));
2531 return
2532 Make_Procedure_Specification (Loc,
2533 Defining_Unit_Name => Def_Id,
2534 Parameter_Specifications => Params);
2535 end Make_Disp_Asynchronous_Select_Spec;
2537 ---------------------------------------
2538 -- Make_Disp_Conditional_Select_Body --
2539 ---------------------------------------
2541 -- For interface types, generate:
2543 -- procedure _Disp_Conditional_Select
2544 -- (T : in out <Typ>;
2545 -- S : Integer;
2546 -- P : System.Address;
2547 -- C : out Ada.Tags.Prim_Op_Kind;
2548 -- F : out Boolean)
2549 -- is
2550 -- begin
2551 -- F := False;
2552 -- C := Ada.Tags.POK_Function;
2553 -- end _Disp_Conditional_Select;
2555 -- For protected types, generate:
2557 -- procedure _Disp_Conditional_Select
2558 -- (T : in out <Typ>;
2559 -- S : Integer;
2560 -- P : System.Address;
2561 -- C : out Ada.Tags.Prim_Op_Kind;
2562 -- F : out Boolean)
2563 -- is
2564 -- I : Integer;
2565 -- Bnn : System.Tasking.Protected_Objects.Operations.
2566 -- Communication_Block;
2568 -- begin
2569 -- C := Ada.Tags.Get_Prim_Op_Kind (Ada.Tags.Tag (<Typ>VP, S));
2571 -- if C = Ada.Tags.POK_Procedure
2572 -- or else C = Ada.Tags.POK_Protected_Procedure
2573 -- or else C = Ada.Tags.POK_Task_Procedure
2574 -- then
2575 -- F := True;
2576 -- return;
2577 -- end if;
2579 -- I := Ada.Tags.Get_Entry_Index (Ada.Tags.Tag (<Typ>VP, S));
2580 -- System.Tasking.Protected_Objects.Operations.Protected_Entry_Call
2581 -- (T.object'Access,
2582 -- System.Tasking.Protected_Objects.Protected_Entry_Index (I),
2583 -- P,
2584 -- System.Tasking.Conditional_Call,
2585 -- Bnn);
2586 -- F := not Cancelled (Bnn);
2587 -- end _Disp_Conditional_Select;
2589 -- For task types, generate:
2591 -- procedure _Disp_Conditional_Select
2592 -- (T : in out <Typ>;
2593 -- S : Integer;
2594 -- P : System.Address;
2595 -- C : out Ada.Tags.Prim_Op_Kind;
2596 -- F : out Boolean)
2597 -- is
2598 -- I : Integer;
2600 -- begin
2601 -- I := Ada.Tags.Get_Entry_Index (Ada.Tags.Tag (<Typ>VP, S));
2602 -- System.Tasking.Rendezvous.Task_Entry_Call
2603 -- (T._task_id,
2604 -- System.Tasking.Task_Entry_Index (I),
2605 -- P,
2606 -- System.Tasking.Conditional_Call,
2607 -- F);
2608 -- end _Disp_Conditional_Select;
2610 function Make_Disp_Conditional_Select_Body
2611 (Typ : Entity_Id) return Node_Id
2613 Loc : constant Source_Ptr := Sloc (Typ);
2614 Blk_Nam : Entity_Id;
2615 Conc_Typ : Entity_Id := Empty;
2616 Decls : constant List_Id := New_List;
2617 Obj_Ref : Node_Id;
2618 Stmts : constant List_Id := New_List;
2619 Tag_Node : Node_Id;
2621 begin
2622 pragma Assert (not Restriction_Active (No_Dispatching_Calls));
2624 -- Null body is generated for interface types
2626 if Is_Interface (Typ) then
2627 return
2628 Make_Subprogram_Body (Loc,
2629 Specification =>
2630 Make_Disp_Conditional_Select_Spec (Typ),
2631 Declarations => No_List,
2632 Handled_Statement_Sequence =>
2633 Make_Handled_Sequence_Of_Statements (Loc,
2634 New_List (Make_Assignment_Statement (Loc,
2635 Name => Make_Identifier (Loc, Name_uF),
2636 Expression => New_Occurrence_Of (Standard_False, Loc)))));
2637 end if;
2639 if Is_Concurrent_Record_Type (Typ) then
2640 Conc_Typ := Corresponding_Concurrent_Type (Typ);
2642 -- Generate:
2643 -- I : Integer;
2645 -- where I will be used to capture the entry index of the primitive
2646 -- wrapper at position S.
2648 Append_To (Decls,
2649 Make_Object_Declaration (Loc,
2650 Defining_Identifier => Make_Defining_Identifier (Loc, Name_uI),
2651 Object_Definition =>
2652 New_Occurrence_Of (Standard_Integer, Loc)));
2654 -- Generate:
2655 -- C := Ada.Tags.Get_Prim_Op_Kind (Ada.Tags.Tag! (<type>VP), S);
2657 -- if C = POK_Procedure
2658 -- or else C = POK_Protected_Procedure
2659 -- or else C = POK_Task_Procedure;
2660 -- then
2661 -- F := True;
2662 -- return;
2663 -- end if;
2665 Build_Common_Dispatching_Select_Statements (Typ, Stmts);
2667 -- Generate:
2668 -- Bnn : Communication_Block;
2670 -- where Bnn is the name of the communication block used in the
2671 -- call to Protected_Entry_Call.
2673 Blk_Nam := Make_Temporary (Loc, 'B');
2674 Append_To (Decls,
2675 Make_Object_Declaration (Loc,
2676 Defining_Identifier => Blk_Nam,
2677 Object_Definition =>
2678 New_Occurrence_Of (RTE (RE_Communication_Block), Loc)));
2680 -- Generate:
2681 -- I := Ada.Tags.Get_Entry_Index (Ada.Tags.Tag! (<type>VP), S);
2683 -- I is the entry index and S is the dispatch table slot
2685 if Tagged_Type_Expansion then
2686 Tag_Node :=
2687 Unchecked_Convert_To (RTE (RE_Tag),
2688 New_Occurrence_Of
2689 (Node (First_Elmt (Access_Disp_Table (Typ))), Loc));
2691 else
2692 Tag_Node :=
2693 Make_Attribute_Reference (Loc,
2694 Prefix => New_Occurrence_Of (Typ, Loc),
2695 Attribute_Name => Name_Tag);
2696 end if;
2698 Append_To (Stmts,
2699 Make_Assignment_Statement (Loc,
2700 Name => Make_Identifier (Loc, Name_uI),
2701 Expression =>
2702 Make_Function_Call (Loc,
2703 Name =>
2704 New_Occurrence_Of (RTE (RE_Get_Entry_Index), Loc),
2705 Parameter_Associations => New_List (
2706 Tag_Node,
2707 Make_Identifier (Loc, Name_uS)))));
2709 if Ekind (Conc_Typ) = E_Protected_Type then
2711 Obj_Ref := -- T._object'Access
2712 Make_Attribute_Reference (Loc,
2713 Attribute_Name => Name_Unchecked_Access,
2714 Prefix =>
2715 Make_Selected_Component (Loc,
2716 Prefix => Make_Identifier (Loc, Name_uT),
2717 Selector_Name => Make_Identifier (Loc, Name_uObject)));
2719 case Corresponding_Runtime_Package (Conc_Typ) is
2720 when System_Tasking_Protected_Objects_Entries =>
2721 -- Generate:
2723 -- Protected_Entry_Call
2724 -- (T._object'Access, -- Object
2725 -- Protected_Entry_Index! (I), -- E
2726 -- P, -- Uninterpreted_Data
2727 -- Conditional_Call, -- Mode
2728 -- Bnn); -- Block
2730 -- where T is the protected object, I is the entry index, P
2731 -- are the wrapped parameters and Bnn is the name of the
2732 -- communication block.
2734 Append_To (Stmts,
2735 Make_Procedure_Call_Statement (Loc,
2736 Name =>
2737 New_Occurrence_Of (RTE (RE_Protected_Entry_Call), Loc),
2738 Parameter_Associations => New_List (
2739 Obj_Ref,
2741 Make_Unchecked_Type_Conversion (Loc, -- entry index
2742 Subtype_Mark =>
2743 New_Occurrence_Of
2744 (RTE (RE_Protected_Entry_Index), Loc),
2745 Expression => Make_Identifier (Loc, Name_uI)),
2747 Make_Identifier (Loc, Name_uP), -- parameter block
2749 New_Occurrence_Of -- Conditional_Call
2750 (RTE (RE_Conditional_Call), Loc),
2751 New_Occurrence_Of -- Bnn
2752 (Blk_Nam, Loc))));
2754 when System_Tasking_Protected_Objects_Single_Entry =>
2756 -- If we are compiling for a restricted run-time, the call
2757 -- uses the simpler form.
2759 Append_To (Stmts,
2760 Make_Procedure_Call_Statement (Loc,
2761 Name =>
2762 New_Occurrence_Of
2763 (RTE (RE_Protected_Single_Entry_Call), Loc),
2764 Parameter_Associations => New_List (
2765 Obj_Ref,
2767 Make_Attribute_Reference (Loc,
2768 Prefix => Make_Identifier (Loc, Name_uP),
2769 Attribute_Name => Name_Address),
2771 New_Occurrence_Of
2772 (RTE (RE_Conditional_Call), Loc))));
2773 when others =>
2774 raise Program_Error;
2775 end case;
2777 -- Generate:
2778 -- F := not Cancelled (Bnn);
2780 -- where F is the success flag. The status of Cancelled is negated
2781 -- in order to match the behavior of the version for task types.
2783 Append_To (Stmts,
2784 Make_Assignment_Statement (Loc,
2785 Name => Make_Identifier (Loc, Name_uF),
2786 Expression =>
2787 Make_Op_Not (Loc,
2788 Right_Opnd =>
2789 Make_Function_Call (Loc,
2790 Name =>
2791 New_Occurrence_Of (RTE (RE_Cancelled), Loc),
2792 Parameter_Associations => New_List (
2793 New_Occurrence_Of (Blk_Nam, Loc))))));
2794 else
2795 pragma Assert (Ekind (Conc_Typ) = E_Task_Type);
2797 -- Generate:
2798 -- Task_Entry_Call
2799 -- (T._task_id, -- Acceptor
2800 -- Task_Entry_Index! (I), -- E
2801 -- P, -- Uninterpreted_Data
2802 -- Conditional_Call, -- Mode
2803 -- F); -- Rendezvous_Successful
2805 -- where T is the task object, I is the entry index, P are the
2806 -- wrapped parameters and F is the status flag.
2808 Append_To (Stmts,
2809 Make_Procedure_Call_Statement (Loc,
2810 Name =>
2811 New_Occurrence_Of (RTE (RE_Task_Entry_Call), Loc),
2812 Parameter_Associations => New_List (
2814 Make_Selected_Component (Loc, -- T._task_id
2815 Prefix => Make_Identifier (Loc, Name_uT),
2816 Selector_Name => Make_Identifier (Loc, Name_uTask_Id)),
2818 Make_Unchecked_Type_Conversion (Loc, -- entry index
2819 Subtype_Mark =>
2820 New_Occurrence_Of (RTE (RE_Task_Entry_Index), Loc),
2821 Expression => Make_Identifier (Loc, Name_uI)),
2823 Make_Identifier (Loc, Name_uP), -- parameter block
2824 New_Occurrence_Of -- Conditional_Call
2825 (RTE (RE_Conditional_Call), Loc),
2826 Make_Identifier (Loc, Name_uF)))); -- status flag
2827 end if;
2829 else
2830 -- Initialize out parameters
2832 Append_To (Stmts,
2833 Make_Assignment_Statement (Loc,
2834 Name => Make_Identifier (Loc, Name_uF),
2835 Expression => New_Occurrence_Of (Standard_False, Loc)));
2836 Append_To (Stmts,
2837 Make_Assignment_Statement (Loc,
2838 Name => Make_Identifier (Loc, Name_uC),
2839 Expression => New_Occurrence_Of (RTE (RE_POK_Function), Loc)));
2840 end if;
2842 return
2843 Make_Subprogram_Body (Loc,
2844 Specification =>
2845 Make_Disp_Conditional_Select_Spec (Typ),
2846 Declarations => Decls,
2847 Handled_Statement_Sequence =>
2848 Make_Handled_Sequence_Of_Statements (Loc, Stmts));
2849 end Make_Disp_Conditional_Select_Body;
2851 ---------------------------------------
2852 -- Make_Disp_Conditional_Select_Spec --
2853 ---------------------------------------
2855 function Make_Disp_Conditional_Select_Spec
2856 (Typ : Entity_Id) return Node_Id
2858 Loc : constant Source_Ptr := Sloc (Typ);
2859 Def_Id : constant Node_Id :=
2860 Make_Defining_Identifier (Loc,
2861 Name_uDisp_Conditional_Select);
2862 Params : constant List_Id := New_List;
2864 begin
2865 pragma Assert (not Restriction_Active (No_Dispatching_Calls));
2867 -- T : in out Typ; -- Object parameter
2868 -- S : Integer; -- Primitive operation slot
2869 -- P : Address; -- Wrapped parameters
2870 -- C : out Prim_Op_Kind; -- Call kind
2871 -- F : out Boolean; -- Status flag
2873 Append_List_To (Params, New_List (
2875 Make_Parameter_Specification (Loc,
2876 Defining_Identifier => Make_Defining_Identifier (Loc, Name_uT),
2877 Parameter_Type => New_Occurrence_Of (Typ, Loc),
2878 In_Present => True,
2879 Out_Present => True),
2881 Make_Parameter_Specification (Loc,
2882 Defining_Identifier => Make_Defining_Identifier (Loc, Name_uS),
2883 Parameter_Type => New_Occurrence_Of (Standard_Integer, Loc)),
2885 Make_Parameter_Specification (Loc,
2886 Defining_Identifier => Make_Defining_Identifier (Loc, Name_uP),
2887 Parameter_Type => New_Occurrence_Of (RTE (RE_Address), Loc)),
2889 Make_Parameter_Specification (Loc,
2890 Defining_Identifier => Make_Defining_Identifier (Loc, Name_uC),
2891 Parameter_Type =>
2892 New_Occurrence_Of (RTE (RE_Prim_Op_Kind), Loc),
2893 Out_Present => True),
2895 Make_Parameter_Specification (Loc,
2896 Defining_Identifier => Make_Defining_Identifier (Loc, Name_uF),
2897 Parameter_Type => New_Occurrence_Of (Standard_Boolean, Loc),
2898 Out_Present => True)));
2900 return
2901 Make_Procedure_Specification (Loc,
2902 Defining_Unit_Name => Def_Id,
2903 Parameter_Specifications => Params);
2904 end Make_Disp_Conditional_Select_Spec;
2906 -------------------------------------
2907 -- Make_Disp_Get_Prim_Op_Kind_Body --
2908 -------------------------------------
2910 function Make_Disp_Get_Prim_Op_Kind_Body (Typ : Entity_Id) return Node_Id is
2911 Loc : constant Source_Ptr := Sloc (Typ);
2912 Tag_Node : Node_Id;
2914 begin
2915 pragma Assert (not Restriction_Active (No_Dispatching_Calls));
2917 if Is_Interface (Typ) then
2918 return
2919 Make_Subprogram_Body (Loc,
2920 Specification =>
2921 Make_Disp_Get_Prim_Op_Kind_Spec (Typ),
2922 Declarations => New_List,
2923 Handled_Statement_Sequence =>
2924 Make_Handled_Sequence_Of_Statements (Loc,
2925 New_List (Make_Null_Statement (Loc))));
2926 end if;
2928 -- Generate:
2929 -- C := get_prim_op_kind (tag! (<type>VP), S);
2931 -- where C is the out parameter capturing the call kind and S is the
2932 -- dispatch table slot number.
2934 if Tagged_Type_Expansion then
2935 Tag_Node :=
2936 Unchecked_Convert_To (RTE (RE_Tag),
2937 New_Occurrence_Of
2938 (Node (First_Elmt (Access_Disp_Table (Typ))), Loc));
2940 else
2941 Tag_Node :=
2942 Make_Attribute_Reference (Loc,
2943 Prefix => New_Occurrence_Of (Typ, Loc),
2944 Attribute_Name => Name_Tag);
2945 end if;
2947 return
2948 Make_Subprogram_Body (Loc,
2949 Specification =>
2950 Make_Disp_Get_Prim_Op_Kind_Spec (Typ),
2951 Declarations => New_List,
2952 Handled_Statement_Sequence =>
2953 Make_Handled_Sequence_Of_Statements (Loc,
2954 New_List (
2955 Make_Assignment_Statement (Loc,
2956 Name => Make_Identifier (Loc, Name_uC),
2957 Expression =>
2958 Make_Function_Call (Loc,
2959 Name =>
2960 New_Occurrence_Of (RTE (RE_Get_Prim_Op_Kind), Loc),
2961 Parameter_Associations => New_List (
2962 Tag_Node,
2963 Make_Identifier (Loc, Name_uS)))))));
2964 end Make_Disp_Get_Prim_Op_Kind_Body;
2966 -------------------------------------
2967 -- Make_Disp_Get_Prim_Op_Kind_Spec --
2968 -------------------------------------
2970 function Make_Disp_Get_Prim_Op_Kind_Spec
2971 (Typ : Entity_Id) return Node_Id
2973 Loc : constant Source_Ptr := Sloc (Typ);
2974 Def_Id : constant Node_Id :=
2975 Make_Defining_Identifier (Loc, Name_uDisp_Get_Prim_Op_Kind);
2976 Params : constant List_Id := New_List;
2978 begin
2979 pragma Assert (not Restriction_Active (No_Dispatching_Calls));
2981 -- T : in out Typ; -- Object parameter
2982 -- S : Integer; -- Primitive operation slot
2983 -- C : out Prim_Op_Kind; -- Call kind
2985 Append_List_To (Params, New_List (
2987 Make_Parameter_Specification (Loc,
2988 Defining_Identifier => Make_Defining_Identifier (Loc, Name_uT),
2989 Parameter_Type => New_Occurrence_Of (Typ, Loc),
2990 In_Present => True,
2991 Out_Present => True),
2993 Make_Parameter_Specification (Loc,
2994 Defining_Identifier => Make_Defining_Identifier (Loc, Name_uS),
2995 Parameter_Type => New_Occurrence_Of (Standard_Integer, Loc)),
2997 Make_Parameter_Specification (Loc,
2998 Defining_Identifier => Make_Defining_Identifier (Loc, Name_uC),
2999 Parameter_Type =>
3000 New_Occurrence_Of (RTE (RE_Prim_Op_Kind), Loc),
3001 Out_Present => True)));
3003 return
3004 Make_Procedure_Specification (Loc,
3005 Defining_Unit_Name => Def_Id,
3006 Parameter_Specifications => Params);
3007 end Make_Disp_Get_Prim_Op_Kind_Spec;
3009 --------------------------------
3010 -- Make_Disp_Get_Task_Id_Body --
3011 --------------------------------
3013 function Make_Disp_Get_Task_Id_Body
3014 (Typ : Entity_Id) return Node_Id
3016 Loc : constant Source_Ptr := Sloc (Typ);
3017 Ret : Node_Id;
3019 begin
3020 pragma Assert (not Restriction_Active (No_Dispatching_Calls));
3022 if Is_Concurrent_Record_Type (Typ)
3023 and then Ekind (Corresponding_Concurrent_Type (Typ)) = E_Task_Type
3024 then
3025 -- Generate:
3026 -- return To_Address (_T._task_id);
3028 Ret :=
3029 Make_Simple_Return_Statement (Loc,
3030 Expression =>
3031 Make_Unchecked_Type_Conversion (Loc,
3032 Subtype_Mark => New_Occurrence_Of (RTE (RE_Address), Loc),
3033 Expression =>
3034 Make_Selected_Component (Loc,
3035 Prefix => Make_Identifier (Loc, Name_uT),
3036 Selector_Name => Make_Identifier (Loc, Name_uTask_Id))));
3038 -- A null body is constructed for non-task types
3040 else
3041 -- Generate:
3042 -- return Null_Address;
3044 Ret :=
3045 Make_Simple_Return_Statement (Loc,
3046 Expression => New_Occurrence_Of (RTE (RE_Null_Address), Loc));
3047 end if;
3049 return
3050 Make_Subprogram_Body (Loc,
3051 Specification => Make_Disp_Get_Task_Id_Spec (Typ),
3052 Declarations => New_List,
3053 Handled_Statement_Sequence =>
3054 Make_Handled_Sequence_Of_Statements (Loc, New_List (Ret)));
3055 end Make_Disp_Get_Task_Id_Body;
3057 --------------------------------
3058 -- Make_Disp_Get_Task_Id_Spec --
3059 --------------------------------
3061 function Make_Disp_Get_Task_Id_Spec
3062 (Typ : Entity_Id) return Node_Id
3064 Loc : constant Source_Ptr := Sloc (Typ);
3066 begin
3067 pragma Assert (not Restriction_Active (No_Dispatching_Calls));
3069 return
3070 Make_Function_Specification (Loc,
3071 Defining_Unit_Name =>
3072 Make_Defining_Identifier (Loc, Name_uDisp_Get_Task_Id),
3073 Parameter_Specifications => New_List (
3074 Make_Parameter_Specification (Loc,
3075 Defining_Identifier => Make_Defining_Identifier (Loc, Name_uT),
3076 Parameter_Type => New_Occurrence_Of (Typ, Loc))),
3077 Result_Definition =>
3078 New_Occurrence_Of (RTE (RE_Address), Loc));
3079 end Make_Disp_Get_Task_Id_Spec;
3081 ----------------------------
3082 -- Make_Disp_Requeue_Body --
3083 ----------------------------
3085 function Make_Disp_Requeue_Body
3086 (Typ : Entity_Id) return Node_Id
3088 Loc : constant Source_Ptr := Sloc (Typ);
3089 Conc_Typ : Entity_Id := Empty;
3090 Stmts : constant List_Id := New_List;
3092 begin
3093 pragma Assert (not Restriction_Active (No_Dispatching_Calls));
3095 -- Null body is generated for interface types and non-concurrent
3096 -- tagged types.
3098 if Is_Interface (Typ)
3099 or else not Is_Concurrent_Record_Type (Typ)
3100 then
3101 return
3102 Make_Subprogram_Body (Loc,
3103 Specification => Make_Disp_Requeue_Spec (Typ),
3104 Declarations => No_List,
3105 Handled_Statement_Sequence =>
3106 Make_Handled_Sequence_Of_Statements (Loc,
3107 New_List (Make_Null_Statement (Loc))));
3108 end if;
3110 Conc_Typ := Corresponding_Concurrent_Type (Typ);
3112 if Ekind (Conc_Typ) = E_Protected_Type then
3114 -- Generate statements:
3115 -- if F then
3116 -- System.Tasking.Protected_Objects.Operations.
3117 -- Requeue_Protected_Entry
3118 -- (Protection_Entries_Access (P),
3119 -- O._object'Unchecked_Access,
3120 -- Protected_Entry_Index (I),
3121 -- A);
3122 -- else
3123 -- System.Tasking.Protected_Objects.Operations.
3124 -- Requeue_Task_To_Protected_Entry
3125 -- (O._object'Unchecked_Access,
3126 -- Protected_Entry_Index (I),
3127 -- A);
3128 -- end if;
3130 if Restriction_Active (No_Entry_Queue) then
3131 Append_To (Stmts, Make_Null_Statement (Loc));
3132 else
3133 Append_To (Stmts,
3134 Make_If_Statement (Loc,
3135 Condition => Make_Identifier (Loc, Name_uF),
3137 Then_Statements =>
3138 New_List (
3140 -- Call to Requeue_Protected_Entry
3142 Make_Procedure_Call_Statement (Loc,
3143 Name =>
3144 New_Occurrence_Of
3145 (RTE (RE_Requeue_Protected_Entry), Loc),
3146 Parameter_Associations =>
3147 New_List (
3149 Make_Unchecked_Type_Conversion (Loc, -- PEA (P)
3150 Subtype_Mark =>
3151 New_Occurrence_Of (
3152 RTE (RE_Protection_Entries_Access), Loc),
3153 Expression =>
3154 Make_Identifier (Loc, Name_uP)),
3156 Make_Attribute_Reference (Loc, -- O._object'Acc
3157 Attribute_Name =>
3158 Name_Unchecked_Access,
3159 Prefix =>
3160 Make_Selected_Component (Loc,
3161 Prefix =>
3162 Make_Identifier (Loc, Name_uO),
3163 Selector_Name =>
3164 Make_Identifier (Loc, Name_uObject))),
3166 Make_Unchecked_Type_Conversion (Loc, -- entry index
3167 Subtype_Mark =>
3168 New_Occurrence_Of
3169 (RTE (RE_Protected_Entry_Index), Loc),
3170 Expression => Make_Identifier (Loc, Name_uI)),
3172 Make_Identifier (Loc, Name_uA)))), -- abort status
3174 Else_Statements =>
3175 New_List (
3177 -- Call to Requeue_Task_To_Protected_Entry
3179 Make_Procedure_Call_Statement (Loc,
3180 Name =>
3181 New_Occurrence_Of
3182 (RTE (RE_Requeue_Task_To_Protected_Entry), Loc),
3183 Parameter_Associations =>
3184 New_List (
3186 Make_Attribute_Reference (Loc, -- O._object'Acc
3187 Attribute_Name => Name_Unchecked_Access,
3188 Prefix =>
3189 Make_Selected_Component (Loc,
3190 Prefix =>
3191 Make_Identifier (Loc, Name_uO),
3192 Selector_Name =>
3193 Make_Identifier (Loc, Name_uObject))),
3195 Make_Unchecked_Type_Conversion (Loc, -- entry index
3196 Subtype_Mark =>
3197 New_Occurrence_Of
3198 (RTE (RE_Protected_Entry_Index), Loc),
3199 Expression => Make_Identifier (Loc, Name_uI)),
3201 Make_Identifier (Loc, Name_uA)))))); -- abort status
3202 end if;
3204 else
3205 pragma Assert (Is_Task_Type (Conc_Typ));
3207 -- Generate:
3208 -- if F then
3209 -- System.Tasking.Rendezvous.Requeue_Protected_To_Task_Entry
3210 -- (Protection_Entries_Access (P),
3211 -- O._task_id,
3212 -- Task_Entry_Index (I),
3213 -- A);
3214 -- else
3215 -- System.Tasking.Rendezvous.Requeue_Task_Entry
3216 -- (O._task_id,
3217 -- Task_Entry_Index (I),
3218 -- A);
3219 -- end if;
3221 Append_To (Stmts,
3222 Make_If_Statement (Loc,
3223 Condition => Make_Identifier (Loc, Name_uF),
3225 Then_Statements => New_List (
3227 -- Call to Requeue_Protected_To_Task_Entry
3229 Make_Procedure_Call_Statement (Loc,
3230 Name =>
3231 New_Occurrence_Of
3232 (RTE (RE_Requeue_Protected_To_Task_Entry), Loc),
3234 Parameter_Associations => New_List (
3236 Make_Unchecked_Type_Conversion (Loc, -- PEA (P)
3237 Subtype_Mark =>
3238 New_Occurrence_Of
3239 (RTE (RE_Protection_Entries_Access), Loc),
3240 Expression => Make_Identifier (Loc, Name_uP)),
3242 Make_Selected_Component (Loc, -- O._task_id
3243 Prefix => Make_Identifier (Loc, Name_uO),
3244 Selector_Name => Make_Identifier (Loc, Name_uTask_Id)),
3246 Make_Unchecked_Type_Conversion (Loc, -- entry index
3247 Subtype_Mark =>
3248 New_Occurrence_Of (RTE (RE_Task_Entry_Index), Loc),
3249 Expression => Make_Identifier (Loc, Name_uI)),
3251 Make_Identifier (Loc, Name_uA)))), -- abort status
3253 Else_Statements => New_List (
3255 -- Call to Requeue_Task_Entry
3257 Make_Procedure_Call_Statement (Loc,
3258 Name =>
3259 New_Occurrence_Of (RTE (RE_Requeue_Task_Entry), Loc),
3261 Parameter_Associations => New_List (
3263 Make_Selected_Component (Loc, -- O._task_id
3264 Prefix => Make_Identifier (Loc, Name_uO),
3265 Selector_Name => Make_Identifier (Loc, Name_uTask_Id)),
3267 Make_Unchecked_Type_Conversion (Loc, -- entry index
3268 Subtype_Mark =>
3269 New_Occurrence_Of (RTE (RE_Task_Entry_Index), Loc),
3270 Expression => Make_Identifier (Loc, Name_uI)),
3272 Make_Identifier (Loc, Name_uA)))))); -- abort status
3273 end if;
3275 -- Even though no declarations are needed in both cases, we allocate
3276 -- a list for entities added by Freeze.
3278 return
3279 Make_Subprogram_Body (Loc,
3280 Specification => Make_Disp_Requeue_Spec (Typ),
3281 Declarations => New_List,
3282 Handled_Statement_Sequence =>
3283 Make_Handled_Sequence_Of_Statements (Loc, Stmts));
3284 end Make_Disp_Requeue_Body;
3286 ----------------------------
3287 -- Make_Disp_Requeue_Spec --
3288 ----------------------------
3290 function Make_Disp_Requeue_Spec
3291 (Typ : Entity_Id) return Node_Id
3293 Loc : constant Source_Ptr := Sloc (Typ);
3295 begin
3296 pragma Assert (not Restriction_Active (No_Dispatching_Calls));
3298 -- O : in out Typ; - Object parameter
3299 -- F : Boolean; - Protected (True) / task (False) flag
3300 -- P : Address; - Protection_Entries_Access value
3301 -- I : Entry_Index - Index of entry call
3302 -- A : Boolean - Abort flag
3304 -- Note that the Protection_Entries_Access value is represented as a
3305 -- System.Address in order to avoid dragging in the tasking runtime
3306 -- when compiling sources without tasking constructs.
3308 return
3309 Make_Procedure_Specification (Loc,
3310 Defining_Unit_Name =>
3311 Make_Defining_Identifier (Loc, Name_uDisp_Requeue),
3313 Parameter_Specifications => New_List (
3315 Make_Parameter_Specification (Loc, -- O
3316 Defining_Identifier =>
3317 Make_Defining_Identifier (Loc, Name_uO),
3318 Parameter_Type =>
3319 New_Occurrence_Of (Typ, Loc),
3320 In_Present => True,
3321 Out_Present => True),
3323 Make_Parameter_Specification (Loc, -- F
3324 Defining_Identifier =>
3325 Make_Defining_Identifier (Loc, Name_uF),
3326 Parameter_Type =>
3327 New_Occurrence_Of (Standard_Boolean, Loc)),
3329 Make_Parameter_Specification (Loc, -- P
3330 Defining_Identifier =>
3331 Make_Defining_Identifier (Loc, Name_uP),
3332 Parameter_Type =>
3333 New_Occurrence_Of (RTE (RE_Address), Loc)),
3335 Make_Parameter_Specification (Loc, -- I
3336 Defining_Identifier =>
3337 Make_Defining_Identifier (Loc, Name_uI),
3338 Parameter_Type =>
3339 New_Occurrence_Of (Standard_Integer, Loc)),
3341 Make_Parameter_Specification (Loc, -- A
3342 Defining_Identifier =>
3343 Make_Defining_Identifier (Loc, Name_uA),
3344 Parameter_Type =>
3345 New_Occurrence_Of (Standard_Boolean, Loc))));
3346 end Make_Disp_Requeue_Spec;
3348 ---------------------------------
3349 -- Make_Disp_Timed_Select_Body --
3350 ---------------------------------
3352 -- For interface types, generate:
3354 -- procedure _Disp_Timed_Select
3355 -- (T : in out <Typ>;
3356 -- S : Integer;
3357 -- P : System.Address;
3358 -- D : Duration;
3359 -- M : Integer;
3360 -- C : out Ada.Tags.Prim_Op_Kind;
3361 -- F : out Boolean)
3362 -- is
3363 -- begin
3364 -- F := False;
3365 -- C := Ada.Tags.POK_Function;
3366 -- end _Disp_Timed_Select;
3368 -- For protected types, generate:
3370 -- procedure _Disp_Timed_Select
3371 -- (T : in out <Typ>;
3372 -- S : Integer;
3373 -- P : System.Address;
3374 -- D : Duration;
3375 -- M : Integer;
3376 -- C : out Ada.Tags.Prim_Op_Kind;
3377 -- F : out Boolean)
3378 -- is
3379 -- I : Integer;
3381 -- begin
3382 -- C := Ada.Tags.Get_Prim_Op_Kind (Ada.Tags.Tag (<Typ>VP), S);
3384 -- if C = Ada.Tags.POK_Procedure
3385 -- or else C = Ada.Tags.POK_Protected_Procedure
3386 -- or else C = Ada.Tags.POK_Task_Procedure
3387 -- then
3388 -- F := True;
3389 -- return;
3390 -- end if;
3392 -- I := Ada.Tags.Get_Entry_Index (Ada.Tags.Tag (<Typ>VP), S);
3393 -- System.Tasking.Protected_Objects.Operations.
3394 -- Timed_Protected_Entry_Call
3395 -- (T._object'Access,
3396 -- System.Tasking.Protected_Objects.Protected_Entry_Index (I),
3397 -- P,
3398 -- D,
3399 -- M,
3400 -- F);
3401 -- end _Disp_Timed_Select;
3403 -- For task types, generate:
3405 -- procedure _Disp_Timed_Select
3406 -- (T : in out <Typ>;
3407 -- S : Integer;
3408 -- P : System.Address;
3409 -- D : Duration;
3410 -- M : Integer;
3411 -- C : out Ada.Tags.Prim_Op_Kind;
3412 -- F : out Boolean)
3413 -- is
3414 -- I : Integer;
3416 -- begin
3417 -- I := Ada.Tags.Get_Entry_Index (Ada.Tags.Tag (<Typ>VP), S);
3418 -- System.Tasking.Rendezvous.Timed_Task_Entry_Call
3419 -- (T._task_id,
3420 -- System.Tasking.Task_Entry_Index (I),
3421 -- P,
3422 -- D,
3423 -- M,
3424 -- F);
3425 -- end _Disp_Time_Select;
3427 function Make_Disp_Timed_Select_Body
3428 (Typ : Entity_Id) return Node_Id
3430 Loc : constant Source_Ptr := Sloc (Typ);
3431 Conc_Typ : Entity_Id := Empty;
3432 Decls : constant List_Id := New_List;
3433 Obj_Ref : Node_Id;
3434 Stmts : constant List_Id := New_List;
3435 Tag_Node : Node_Id;
3437 begin
3438 pragma Assert (not Restriction_Active (No_Dispatching_Calls));
3440 -- Null body is generated for interface types
3442 if Is_Interface (Typ) then
3443 return
3444 Make_Subprogram_Body (Loc,
3445 Specification => Make_Disp_Timed_Select_Spec (Typ),
3446 Declarations => New_List,
3447 Handled_Statement_Sequence =>
3448 Make_Handled_Sequence_Of_Statements (Loc,
3449 New_List (
3450 Make_Assignment_Statement (Loc,
3451 Name => Make_Identifier (Loc, Name_uF),
3452 Expression => New_Occurrence_Of (Standard_False, Loc)))));
3453 end if;
3455 if Is_Concurrent_Record_Type (Typ) then
3456 Conc_Typ := Corresponding_Concurrent_Type (Typ);
3458 -- Generate:
3459 -- I : Integer;
3461 -- where I will be used to capture the entry index of the primitive
3462 -- wrapper at position S.
3464 Append_To (Decls,
3465 Make_Object_Declaration (Loc,
3466 Defining_Identifier => Make_Defining_Identifier (Loc, Name_uI),
3467 Object_Definition =>
3468 New_Occurrence_Of (Standard_Integer, Loc)));
3470 -- Generate:
3471 -- C := Get_Prim_Op_Kind (tag! (<type>VP), S);
3473 -- if C = POK_Procedure
3474 -- or else C = POK_Protected_Procedure
3475 -- or else C = POK_Task_Procedure;
3476 -- then
3477 -- F := True;
3478 -- return;
3479 -- end if;
3481 Build_Common_Dispatching_Select_Statements (Typ, Stmts);
3483 -- Generate:
3484 -- I := Get_Entry_Index (tag! (<type>VP), S);
3486 -- I is the entry index and S is the dispatch table slot
3488 if Tagged_Type_Expansion then
3489 Tag_Node :=
3490 Unchecked_Convert_To (RTE (RE_Tag),
3491 New_Occurrence_Of
3492 (Node (First_Elmt (Access_Disp_Table (Typ))), Loc));
3494 else
3495 Tag_Node :=
3496 Make_Attribute_Reference (Loc,
3497 Prefix => New_Occurrence_Of (Typ, Loc),
3498 Attribute_Name => Name_Tag);
3499 end if;
3501 Append_To (Stmts,
3502 Make_Assignment_Statement (Loc,
3503 Name => Make_Identifier (Loc, Name_uI),
3504 Expression =>
3505 Make_Function_Call (Loc,
3506 Name => New_Occurrence_Of (RTE (RE_Get_Entry_Index), Loc),
3507 Parameter_Associations => New_List (
3508 Tag_Node,
3509 Make_Identifier (Loc, Name_uS)))));
3511 -- Protected case
3513 if Ekind (Conc_Typ) = E_Protected_Type then
3515 -- Build T._object'Access
3517 Obj_Ref :=
3518 Make_Attribute_Reference (Loc,
3519 Attribute_Name => Name_Unchecked_Access,
3520 Prefix =>
3521 Make_Selected_Component (Loc,
3522 Prefix => Make_Identifier (Loc, Name_uT),
3523 Selector_Name => Make_Identifier (Loc, Name_uObject)));
3525 -- Normal case, No_Entry_Queue restriction not active. In this
3526 -- case we generate:
3528 -- Timed_Protected_Entry_Call
3529 -- (T._object'access,
3530 -- Protected_Entry_Index! (I),
3531 -- P, D, M, F);
3533 -- where T is the protected object, I is the entry index, P are
3534 -- the wrapped parameters, D is the delay amount, M is the delay
3535 -- mode and F is the status flag.
3537 -- Historically, there was also an implementation for single
3538 -- entry protected types (in s-tposen). However, it was removed
3539 -- by also testing for no No_Select_Statements restriction in
3540 -- Exp_Utils.Corresponding_Runtime_Package. This simplified the
3541 -- implementation of s-tposen.adb and provided consistency between
3542 -- all versions of System.Tasking.Protected_Objects.Single_Entry
3543 -- (s-tposen*.adb).
3545 case Corresponding_Runtime_Package (Conc_Typ) is
3546 when System_Tasking_Protected_Objects_Entries =>
3547 Append_To (Stmts,
3548 Make_Procedure_Call_Statement (Loc,
3549 Name =>
3550 New_Occurrence_Of
3551 (RTE (RE_Timed_Protected_Entry_Call), Loc),
3552 Parameter_Associations => New_List (
3553 Obj_Ref,
3555 Make_Unchecked_Type_Conversion (Loc, -- entry index
3556 Subtype_Mark =>
3557 New_Occurrence_Of
3558 (RTE (RE_Protected_Entry_Index), Loc),
3559 Expression => Make_Identifier (Loc, Name_uI)),
3561 Make_Identifier (Loc, Name_uP), -- parameter block
3562 Make_Identifier (Loc, Name_uD), -- delay
3563 Make_Identifier (Loc, Name_uM), -- delay mode
3564 Make_Identifier (Loc, Name_uF)))); -- status flag
3566 when others =>
3567 raise Program_Error;
3568 end case;
3570 -- Task case
3572 else
3573 pragma Assert (Ekind (Conc_Typ) = E_Task_Type);
3575 -- Generate:
3576 -- Timed_Task_Entry_Call (
3577 -- T._task_id,
3578 -- Task_Entry_Index! (I),
3579 -- P,
3580 -- D,
3581 -- M,
3582 -- F);
3584 -- where T is the task object, I is the entry index, P are the
3585 -- wrapped parameters, D is the delay amount, M is the delay
3586 -- mode and F is the status flag.
3588 Append_To (Stmts,
3589 Make_Procedure_Call_Statement (Loc,
3590 Name =>
3591 New_Occurrence_Of (RTE (RE_Timed_Task_Entry_Call), Loc),
3593 Parameter_Associations => New_List (
3594 Make_Selected_Component (Loc, -- T._task_id
3595 Prefix => Make_Identifier (Loc, Name_uT),
3596 Selector_Name => Make_Identifier (Loc, Name_uTask_Id)),
3598 Make_Unchecked_Type_Conversion (Loc, -- entry index
3599 Subtype_Mark =>
3600 New_Occurrence_Of (RTE (RE_Task_Entry_Index), Loc),
3601 Expression => Make_Identifier (Loc, Name_uI)),
3603 Make_Identifier (Loc, Name_uP), -- parameter block
3604 Make_Identifier (Loc, Name_uD), -- delay
3605 Make_Identifier (Loc, Name_uM), -- delay mode
3606 Make_Identifier (Loc, Name_uF)))); -- status flag
3607 end if;
3609 else
3610 -- Initialize out parameters
3612 Append_To (Stmts,
3613 Make_Assignment_Statement (Loc,
3614 Name => Make_Identifier (Loc, Name_uF),
3615 Expression => New_Occurrence_Of (Standard_False, Loc)));
3616 Append_To (Stmts,
3617 Make_Assignment_Statement (Loc,
3618 Name => Make_Identifier (Loc, Name_uC),
3619 Expression => New_Occurrence_Of (RTE (RE_POK_Function), Loc)));
3620 end if;
3622 return
3623 Make_Subprogram_Body (Loc,
3624 Specification => Make_Disp_Timed_Select_Spec (Typ),
3625 Declarations => Decls,
3626 Handled_Statement_Sequence =>
3627 Make_Handled_Sequence_Of_Statements (Loc, Stmts));
3628 end Make_Disp_Timed_Select_Body;
3630 ---------------------------------
3631 -- Make_Disp_Timed_Select_Spec --
3632 ---------------------------------
3634 function Make_Disp_Timed_Select_Spec
3635 (Typ : Entity_Id) return Node_Id
3637 Loc : constant Source_Ptr := Sloc (Typ);
3638 Def_Id : constant Node_Id :=
3639 Make_Defining_Identifier (Loc,
3640 Name_uDisp_Timed_Select);
3641 Params : constant List_Id := New_List;
3643 begin
3644 pragma Assert (not Restriction_Active (No_Dispatching_Calls));
3646 -- T : in out Typ; -- Object parameter
3647 -- S : Integer; -- Primitive operation slot
3648 -- P : Address; -- Wrapped parameters
3649 -- D : Duration; -- Delay
3650 -- M : Integer; -- Delay Mode
3651 -- C : out Prim_Op_Kind; -- Call kind
3652 -- F : out Boolean; -- Status flag
3654 Append_List_To (Params, New_List (
3656 Make_Parameter_Specification (Loc,
3657 Defining_Identifier => Make_Defining_Identifier (Loc, Name_uT),
3658 Parameter_Type => New_Occurrence_Of (Typ, Loc),
3659 In_Present => True,
3660 Out_Present => True),
3662 Make_Parameter_Specification (Loc,
3663 Defining_Identifier => Make_Defining_Identifier (Loc, Name_uS),
3664 Parameter_Type => New_Occurrence_Of (Standard_Integer, Loc)),
3666 Make_Parameter_Specification (Loc,
3667 Defining_Identifier => Make_Defining_Identifier (Loc, Name_uP),
3668 Parameter_Type => New_Occurrence_Of (RTE (RE_Address), Loc)),
3670 Make_Parameter_Specification (Loc,
3671 Defining_Identifier => Make_Defining_Identifier (Loc, Name_uD),
3672 Parameter_Type => New_Occurrence_Of (Standard_Duration, Loc)),
3674 Make_Parameter_Specification (Loc,
3675 Defining_Identifier => Make_Defining_Identifier (Loc, Name_uM),
3676 Parameter_Type => New_Occurrence_Of (Standard_Integer, Loc)),
3678 Make_Parameter_Specification (Loc,
3679 Defining_Identifier => Make_Defining_Identifier (Loc, Name_uC),
3680 Parameter_Type =>
3681 New_Occurrence_Of (RTE (RE_Prim_Op_Kind), Loc),
3682 Out_Present => True)));
3684 Append_To (Params,
3685 Make_Parameter_Specification (Loc,
3686 Defining_Identifier => Make_Defining_Identifier (Loc, Name_uF),
3687 Parameter_Type => New_Occurrence_Of (Standard_Boolean, Loc),
3688 Out_Present => True));
3690 return
3691 Make_Procedure_Specification (Loc,
3692 Defining_Unit_Name => Def_Id,
3693 Parameter_Specifications => Params);
3694 end Make_Disp_Timed_Select_Spec;
3696 -------------
3697 -- Make_DT --
3698 -------------
3700 -- The frontend supports two models for expanding dispatch tables
3701 -- associated with library-level defined tagged types: statically and
3702 -- non-statically allocated dispatch tables. In the former case the object
3703 -- containing the dispatch table is constant and it is initialized by means
3704 -- of a positional aggregate. In the latter case, the object containing
3705 -- the dispatch table is a variable which is initialized by means of
3706 -- assignments.
3708 -- In case of locally defined tagged types, the object containing the
3709 -- object containing the dispatch table is always a variable (instead of a
3710 -- constant). This is currently required to give support to late overriding
3711 -- of primitives. For example:
3713 -- procedure Example is
3714 -- package Pkg is
3715 -- type T1 is tagged null record;
3716 -- procedure Prim (O : T1);
3717 -- end Pkg;
3719 -- type T2 is new Pkg.T1 with null record;
3720 -- procedure Prim (X : T2) is -- late overriding
3721 -- begin
3722 -- ...
3723 -- ...
3724 -- end;
3726 -- WARNING: This routine manages Ghost regions. Return statements must be
3727 -- replaced by gotos which jump to the end of the routine and restore the
3728 -- Ghost mode.
3730 function Make_DT (Typ : Entity_Id; N : Node_Id := Empty) return List_Id is
3731 Loc : constant Source_Ptr := Sloc (Typ);
3733 Max_Predef_Prims : constant Int :=
3734 UI_To_Int
3735 (Intval
3736 (Expression
3737 (Parent (RTE (RE_Max_Predef_Prims)))));
3739 DT_Decl : constant Elist_Id := New_Elmt_List;
3740 DT_Aggr : constant Elist_Id := New_Elmt_List;
3741 -- Entities marked with attribute Is_Dispatch_Table_Entity
3743 Dummy_Object : Entity_Id := Empty;
3744 -- Extra nonexistent object of type Typ internally used to compute the
3745 -- offset to the components that reference secondary dispatch tables.
3746 -- Used to statically allocate secondary dispatch tables.
3748 procedure Check_Premature_Freezing
3749 (Subp : Entity_Id;
3750 Tagged_Type : Entity_Id;
3751 Typ : Entity_Id);
3752 -- Verify that all untagged types in the profile of a subprogram are
3753 -- frozen at the point the subprogram is frozen. This enforces the rule
3754 -- on RM 13.14 (14) as modified by AI05-019. At the point a subprogram
3755 -- is frozen, enough must be known about it to build the activation
3756 -- record for it, which requires at least that the size of all
3757 -- parameters be known. Controlling arguments are by-reference,
3758 -- and therefore the rule only applies to untagged types. Typical
3759 -- violation of the rule involves an object declaration that freezes a
3760 -- tagged type, when one of its primitive operations has a type in its
3761 -- profile whose full view has not been analyzed yet. More complex cases
3762 -- involve composite types that have one private unfrozen subcomponent.
3764 procedure Export_DT (Typ : Entity_Id; DT : Entity_Id; Index : Nat := 0);
3765 -- Export the dispatch table DT of tagged type Typ. Required to generate
3766 -- forward references and statically allocate the table. For primary
3767 -- dispatch tables Index is 0; for secondary dispatch tables the value
3768 -- of index must match the Suffix_Index value assigned to the table by
3769 -- Make_Tags when generating its unique external name, and it is used to
3770 -- retrieve from the Dispatch_Table_Wrappers list associated with Typ
3771 -- the external name generated by Import_DT.
3773 procedure Make_Secondary_DT
3774 (Typ : Entity_Id;
3775 Iface : Entity_Id;
3776 Iface_Comp : Node_Id;
3777 Suffix_Index : Int;
3778 Num_Iface_Prims : Nat;
3779 Iface_DT_Ptr : Entity_Id;
3780 Predef_Prims_Ptr : Entity_Id;
3781 Build_Thunks : Boolean;
3782 Result : List_Id);
3783 -- Ada 2005 (AI-251): Expand the declarations for a Secondary Dispatch
3784 -- Table of Typ associated with Iface. Each abstract interface of Typ
3785 -- has two secondary dispatch tables: one containing pointers to thunks
3786 -- and another containing pointers to the primitives covering the
3787 -- interface primitives. The former secondary table is generated when
3788 -- Build_Thunks is True, and provides common support for dispatching
3789 -- calls through interface types; the latter secondary table is
3790 -- generated when Build_Thunks is False, and provides support for
3791 -- Generic Dispatching Constructors that dispatch calls through
3792 -- interface types. When constructing this latter table the value of
3793 -- Suffix_Index is -1 to indicate that there is no need to export such
3794 -- table when building statically allocated dispatch tables; a positive
3795 -- value of Suffix_Index must match the Suffix_Index value assigned to
3796 -- this secondary dispatch table by Make_Tags when its unique external
3797 -- name was generated.
3799 ------------------------------
3800 -- Check_Premature_Freezing --
3801 ------------------------------
3803 procedure Check_Premature_Freezing
3804 (Subp : Entity_Id;
3805 Tagged_Type : Entity_Id;
3806 Typ : Entity_Id)
3808 Comp : Entity_Id;
3810 function Is_Actual_For_Formal_Incomplete_Type
3811 (T : Entity_Id) return Boolean;
3812 -- In Ada 2012, if a nested generic has an incomplete formal type,
3813 -- the actual may be (and usually is) a private type whose completion
3814 -- appears later. It is safe to build the dispatch table in this
3815 -- case, gigi will have full views available.
3817 ------------------------------------------
3818 -- Is_Actual_For_Formal_Incomplete_Type --
3819 ------------------------------------------
3821 function Is_Actual_For_Formal_Incomplete_Type
3822 (T : Entity_Id) return Boolean
3824 Gen_Par : Entity_Id;
3825 F : Node_Id;
3827 begin
3828 if not Is_Generic_Instance (Current_Scope)
3829 or else not Used_As_Generic_Actual (T)
3830 then
3831 return False;
3832 else
3833 Gen_Par := Generic_Parent (Parent (Current_Scope));
3834 end if;
3836 F :=
3837 First
3838 (Generic_Formal_Declarations
3839 (Unit_Declaration_Node (Gen_Par)));
3840 while Present (F) loop
3841 if Ekind (Defining_Identifier (F)) = E_Incomplete_Type then
3842 return True;
3843 end if;
3845 Next (F);
3846 end loop;
3848 return False;
3849 end Is_Actual_For_Formal_Incomplete_Type;
3851 -- Start of processing for Check_Premature_Freezing
3853 begin
3854 -- Note that if the type is a (subtype of) a generic actual, the
3855 -- actual will have been frozen by the instantiation.
3857 if Present (N)
3858 and then Is_Private_Type (Typ)
3859 and then No (Full_View (Typ))
3860 and then not Is_Generic_Type (Typ)
3861 and then not Is_Tagged_Type (Typ)
3862 and then not Is_Frozen (Typ)
3863 and then not Is_Generic_Actual_Type (Typ)
3864 then
3865 Error_Msg_Sloc := Sloc (Subp);
3866 Error_Msg_NE
3867 ("declaration must appear after completion of type &", N, Typ);
3868 Error_Msg_NE
3869 ("\which is an untagged type in the profile of "
3870 & "primitive operation & declared#", N, Subp);
3872 else
3873 Comp := Private_Component (Typ);
3875 if not Is_Tagged_Type (Typ)
3876 and then Present (Comp)
3877 and then not Is_Frozen (Comp)
3878 and then not Is_Actual_For_Formal_Incomplete_Type (Comp)
3879 then
3880 Error_Msg_Sloc := Sloc (Subp);
3881 Error_Msg_Node_2 := Subp;
3882 Error_Msg_Name_1 := Chars (Tagged_Type);
3883 Error_Msg_NE
3884 ("declaration must appear after completion of type &",
3885 N, Comp);
3886 Error_Msg_NE
3887 ("\which is a component of untagged type& in the profile "
3888 & "of primitive & of type % that is frozen by the "
3889 & "declaration ", N, Typ);
3890 end if;
3891 end if;
3892 end Check_Premature_Freezing;
3894 ---------------
3895 -- Export_DT --
3896 ---------------
3898 procedure Export_DT (Typ : Entity_Id; DT : Entity_Id; Index : Nat := 0)
3900 Count : Nat;
3901 Elmt : Elmt_Id;
3903 begin
3904 Set_Is_Statically_Allocated (DT);
3905 Set_Is_True_Constant (DT);
3906 Set_Is_Exported (DT);
3908 Count := 0;
3909 Elmt := First_Elmt (Dispatch_Table_Wrappers (Typ));
3910 while Count /= Index loop
3911 Next_Elmt (Elmt);
3912 Count := Count + 1;
3913 end loop;
3915 pragma Assert (Related_Type (Node (Elmt)) = Typ);
3917 Get_External_Name (Node (Elmt));
3918 Set_Interface_Name (DT,
3919 Make_String_Literal (Loc,
3920 Strval => String_From_Name_Buffer));
3922 -- Ensure proper Sprint output of this implicit importation
3924 Set_Is_Internal (DT);
3925 Set_Is_Public (DT);
3926 end Export_DT;
3928 -----------------------
3929 -- Make_Secondary_DT --
3930 -----------------------
3932 procedure Make_Secondary_DT
3933 (Typ : Entity_Id;
3934 Iface : Entity_Id;
3935 Iface_Comp : Node_Id;
3936 Suffix_Index : Int;
3937 Num_Iface_Prims : Nat;
3938 Iface_DT_Ptr : Entity_Id;
3939 Predef_Prims_Ptr : Entity_Id;
3940 Build_Thunks : Boolean;
3941 Result : List_Id)
3943 Loc : constant Source_Ptr := Sloc (Typ);
3944 Exporting_Table : constant Boolean :=
3945 Building_Static_DT (Typ)
3946 and then Suffix_Index > 0;
3947 Iface_DT : constant Entity_Id := Make_Temporary (Loc, 'T');
3948 Predef_Prims : constant Entity_Id := Make_Temporary (Loc, 'R');
3949 DT_Constr_List : List_Id;
3950 DT_Aggr_List : List_Id;
3951 Empty_DT : Boolean := False;
3952 Nb_Predef_Prims : Nat := 0;
3953 Nb_Prim : Nat;
3954 New_Node : Node_Id;
3955 OSD : Entity_Id;
3956 OSD_Aggr_List : List_Id;
3957 Pos : Nat;
3958 Prim : Entity_Id;
3959 Prim_Elmt : Elmt_Id;
3960 Prim_Ops_Aggr_List : List_Id;
3962 begin
3963 -- Handle cases in which we do not generate statically allocated
3964 -- dispatch tables.
3966 if not Building_Static_DT (Typ) then
3967 Set_Ekind (Predef_Prims, E_Variable);
3968 Set_Ekind (Iface_DT, E_Variable);
3970 -- Statically allocated dispatch tables and related entities are
3971 -- constants.
3973 else
3974 Set_Ekind (Predef_Prims, E_Constant);
3975 Set_Is_Statically_Allocated (Predef_Prims);
3976 Set_Is_True_Constant (Predef_Prims);
3978 Set_Ekind (Iface_DT, E_Constant);
3979 Set_Is_Statically_Allocated (Iface_DT);
3980 Set_Is_True_Constant (Iface_DT);
3981 end if;
3983 -- Calculate the number of slots of the dispatch table. If the number
3984 -- of primitives of Typ is 0 we reserve a dummy single entry for its
3985 -- DT because at run time the pointer to this dummy entry will be
3986 -- used as the tag.
3988 if Num_Iface_Prims = 0 then
3989 Empty_DT := True;
3990 Nb_Prim := 1;
3991 else
3992 Nb_Prim := Num_Iface_Prims;
3993 end if;
3995 -- Generate:
3997 -- Predef_Prims : Address_Array (1 .. Default_Prim_Ops_Count) :=
3998 -- (predef-prim-op-thunk-1'address,
3999 -- predef-prim-op-thunk-2'address,
4000 -- ...
4001 -- predef-prim-op-thunk-n'address);
4002 -- for Predef_Prims'Alignment use Address'Alignment
4004 -- Stage 1: Calculate the number of predefined primitives
4006 if not Building_Static_DT (Typ) then
4007 Nb_Predef_Prims := Max_Predef_Prims;
4008 else
4009 Prim_Elmt := First_Elmt (Primitive_Operations (Typ));
4010 while Present (Prim_Elmt) loop
4011 Prim := Node (Prim_Elmt);
4013 if Is_Predefined_Dispatching_Operation (Prim)
4014 and then not Is_Abstract_Subprogram (Prim)
4015 then
4016 Pos := UI_To_Int (DT_Position (Prim));
4018 if Pos > Nb_Predef_Prims then
4019 Nb_Predef_Prims := Pos;
4020 end if;
4021 end if;
4023 Next_Elmt (Prim_Elmt);
4024 end loop;
4025 end if;
4027 if Generate_SCIL then
4028 Nb_Predef_Prims := 0;
4029 end if;
4031 -- Stage 2: Create the thunks associated with the predefined
4032 -- primitives and save their entity to fill the aggregate.
4034 declare
4035 Prim_Table : array (Nat range 1 .. Nb_Predef_Prims) of Entity_Id;
4036 Decl : Node_Id;
4037 Thunk_Id : Entity_Id;
4038 Thunk_Code : Node_Id;
4040 begin
4041 Prim_Ops_Aggr_List := New_List;
4042 Prim_Table := (others => Empty);
4044 if Building_Static_DT (Typ) then
4045 Prim_Elmt := First_Elmt (Primitive_Operations (Typ));
4046 while Present (Prim_Elmt) loop
4047 Prim := Node (Prim_Elmt);
4049 if Is_Predefined_Dispatching_Operation (Prim)
4050 and then not Is_Abstract_Subprogram (Prim)
4051 and then not Is_Eliminated (Prim)
4052 and then not Generate_SCIL
4053 and then not Present (Prim_Table
4054 (UI_To_Int (DT_Position (Prim))))
4055 then
4056 if not Build_Thunks then
4057 Prim_Table (UI_To_Int (DT_Position (Prim))) :=
4058 Alias (Prim);
4060 else
4061 Expand_Interface_Thunk
4062 (Ultimate_Alias (Prim), Thunk_Id, Thunk_Code);
4064 if Present (Thunk_Id) then
4065 Append_To (Result, Thunk_Code);
4066 Prim_Table (UI_To_Int (DT_Position (Prim))) :=
4067 Thunk_Id;
4068 end if;
4069 end if;
4070 end if;
4072 Next_Elmt (Prim_Elmt);
4073 end loop;
4074 end if;
4076 for J in Prim_Table'Range loop
4077 if Present (Prim_Table (J)) then
4078 New_Node :=
4079 Unchecked_Convert_To (RTE (RE_Prim_Ptr),
4080 Make_Attribute_Reference (Loc,
4081 Prefix => New_Occurrence_Of (Prim_Table (J), Loc),
4082 Attribute_Name => Name_Unrestricted_Access));
4083 else
4084 New_Node := Make_Null (Loc);
4085 end if;
4087 Append_To (Prim_Ops_Aggr_List, New_Node);
4088 end loop;
4090 New_Node :=
4091 Make_Aggregate (Loc, Expressions => Prim_Ops_Aggr_List);
4093 -- Remember aggregates initializing dispatch tables
4095 Append_Elmt (New_Node, DT_Aggr);
4097 Decl :=
4098 Make_Subtype_Declaration (Loc,
4099 Defining_Identifier => Make_Temporary (Loc, 'S'),
4100 Subtype_Indication =>
4101 New_Occurrence_Of (RTE (RE_Address_Array), Loc));
4103 Append_To (Result, Decl);
4105 Append_To (Result,
4106 Make_Object_Declaration (Loc,
4107 Defining_Identifier => Predef_Prims,
4108 Constant_Present => Building_Static_DT (Typ),
4109 Aliased_Present => True,
4110 Object_Definition => New_Occurrence_Of
4111 (Defining_Identifier (Decl), Loc),
4112 Expression => New_Node));
4114 Append_To (Result,
4115 Make_Attribute_Definition_Clause (Loc,
4116 Name => New_Occurrence_Of (Predef_Prims, Loc),
4117 Chars => Name_Alignment,
4118 Expression =>
4119 Make_Attribute_Reference (Loc,
4120 Prefix =>
4121 New_Occurrence_Of (RTE (RE_Integer_Address), Loc),
4122 Attribute_Name => Name_Alignment)));
4123 end;
4125 -- Generate
4127 -- OSD : Ada.Tags.Object_Specific_Data (Nb_Prims) :=
4128 -- (OSD_Table => (1 => <value>,
4129 -- ...
4130 -- N => <value>));
4132 -- Iface_DT : Dispatch_Table (Nb_Prims) :=
4133 -- ([ Signature => <sig-value> ],
4134 -- Tag_Kind => <tag_kind-value>,
4135 -- Predef_Prims => Predef_Prims'Address,
4136 -- Offset_To_Top => 0,
4137 -- OSD => OSD'Address,
4138 -- Prims_Ptr => (prim-op-1'address,
4139 -- prim-op-2'address,
4140 -- ...
4141 -- prim-op-n'address));
4142 -- for Iface_DT'Alignment use Address'Alignment;
4144 -- Stage 3: Initialize the discriminant and the record components
4146 DT_Constr_List := New_List;
4147 DT_Aggr_List := New_List;
4149 -- Nb_Prim
4151 Append_To (DT_Constr_List, Make_Integer_Literal (Loc, Nb_Prim));
4152 Append_To (DT_Aggr_List, Make_Integer_Literal (Loc, Nb_Prim));
4154 -- Signature
4156 if RTE_Record_Component_Available (RE_Signature) then
4157 Append_To (DT_Aggr_List,
4158 New_Occurrence_Of (RTE (RE_Secondary_DT), Loc));
4159 end if;
4161 -- Tag_Kind
4163 if RTE_Record_Component_Available (RE_Tag_Kind) then
4164 Append_To (DT_Aggr_List, Tagged_Kind (Typ));
4165 end if;
4167 -- Predef_Prims
4169 Append_To (DT_Aggr_List,
4170 Make_Attribute_Reference (Loc,
4171 Prefix => New_Occurrence_Of (Predef_Prims, Loc),
4172 Attribute_Name => Name_Address));
4174 -- If the location of the component that references this secondary
4175 -- dispatch table is variable then we have not declared the internal
4176 -- dummy object; the value of Offset_To_Top will be set by the init
4177 -- subprogram.
4179 if No (Dummy_Object) then
4180 Append_To (DT_Aggr_List, Make_Integer_Literal (Loc, 0));
4182 else
4183 Append_To (DT_Aggr_List,
4184 Make_Op_Minus (Loc,
4185 Make_Attribute_Reference (Loc,
4186 Prefix =>
4187 Make_Selected_Component (Loc,
4188 Prefix =>
4189 New_Occurrence_Of (Dummy_Object, Loc),
4190 Selector_Name =>
4191 New_Occurrence_Of (Iface_Comp, Loc)),
4192 Attribute_Name => Name_Position)));
4193 end if;
4195 -- Generate the Object Specific Data table required to dispatch calls
4196 -- through synchronized interfaces.
4198 if Empty_DT
4199 or else Is_Abstract_Type (Typ)
4200 or else Is_Controlled (Typ)
4201 or else Restriction_Active (No_Dispatching_Calls)
4202 or else not Is_Limited_Type (Typ)
4203 or else not Has_Interfaces (Typ)
4204 or else not Build_Thunks
4205 or else not RTE_Record_Component_Available (RE_OSD_Table)
4206 then
4207 -- No OSD table required
4209 Append_To (DT_Aggr_List,
4210 New_Occurrence_Of (RTE (RE_Null_Address), Loc));
4212 else
4213 OSD_Aggr_List := New_List;
4215 declare
4216 Prim_Table : array (Nat range 1 .. Nb_Prim) of Entity_Id;
4217 Prim : Entity_Id;
4218 Prim_Alias : Entity_Id;
4219 Prim_Elmt : Elmt_Id;
4220 E : Entity_Id;
4221 Count : Nat := 0;
4222 Pos : Nat;
4224 begin
4225 Prim_Table := (others => Empty);
4226 Prim_Alias := Empty;
4228 Prim_Elmt := First_Elmt (Primitive_Operations (Typ));
4229 while Present (Prim_Elmt) loop
4230 Prim := Node (Prim_Elmt);
4232 if Present (Interface_Alias (Prim))
4233 and then Find_Dispatching_Type
4234 (Interface_Alias (Prim)) = Iface
4235 then
4236 Prim_Alias := Interface_Alias (Prim);
4237 E := Ultimate_Alias (Prim);
4238 Pos := UI_To_Int (DT_Position (Prim_Alias));
4240 if Present (Prim_Table (Pos)) then
4241 pragma Assert (Prim_Table (Pos) = E);
4242 null;
4244 else
4245 Prim_Table (Pos) := E;
4247 Append_To (OSD_Aggr_List,
4248 Make_Component_Association (Loc,
4249 Choices => New_List (
4250 Make_Integer_Literal (Loc,
4251 DT_Position (Prim_Alias))),
4252 Expression =>
4253 Make_Integer_Literal (Loc,
4254 DT_Position (Alias (Prim)))));
4256 Count := Count + 1;
4257 end if;
4258 end if;
4260 Next_Elmt (Prim_Elmt);
4261 end loop;
4262 pragma Assert (Count = Nb_Prim);
4263 end;
4265 OSD := Make_Temporary (Loc, 'I');
4267 Append_To (Result,
4268 Make_Object_Declaration (Loc,
4269 Defining_Identifier => OSD,
4270 Object_Definition =>
4271 Make_Subtype_Indication (Loc,
4272 Subtype_Mark =>
4273 New_Occurrence_Of (RTE (RE_Object_Specific_Data), Loc),
4274 Constraint =>
4275 Make_Index_Or_Discriminant_Constraint (Loc,
4276 Constraints => New_List (
4277 Make_Integer_Literal (Loc, Nb_Prim)))),
4279 Expression =>
4280 Make_Aggregate (Loc,
4281 Component_Associations => New_List (
4282 Make_Component_Association (Loc,
4283 Choices => New_List (
4284 New_Occurrence_Of
4285 (RTE_Record_Component (RE_OSD_Num_Prims), Loc)),
4286 Expression =>
4287 Make_Integer_Literal (Loc, Nb_Prim)),
4289 Make_Component_Association (Loc,
4290 Choices => New_List (
4291 New_Occurrence_Of
4292 (RTE_Record_Component (RE_OSD_Table), Loc)),
4293 Expression => Make_Aggregate (Loc,
4294 Component_Associations => OSD_Aggr_List))))));
4296 Append_To (Result,
4297 Make_Attribute_Definition_Clause (Loc,
4298 Name => New_Occurrence_Of (OSD, Loc),
4299 Chars => Name_Alignment,
4300 Expression =>
4301 Make_Attribute_Reference (Loc,
4302 Prefix =>
4303 New_Occurrence_Of (RTE (RE_Integer_Address), Loc),
4304 Attribute_Name => Name_Alignment)));
4306 -- In secondary dispatch tables the Typeinfo component contains
4307 -- the address of the Object Specific Data (see a-tags.ads)
4309 Append_To (DT_Aggr_List,
4310 Make_Attribute_Reference (Loc,
4311 Prefix => New_Occurrence_Of (OSD, Loc),
4312 Attribute_Name => Name_Address));
4313 end if;
4315 -- Initialize the table of primitive operations
4317 Prim_Ops_Aggr_List := New_List;
4319 if Empty_DT then
4320 Append_To (Prim_Ops_Aggr_List, Make_Null (Loc));
4322 elsif Is_Abstract_Type (Typ)
4323 or else not Building_Static_DT (Typ)
4324 then
4325 for J in 1 .. Nb_Prim loop
4326 Append_To (Prim_Ops_Aggr_List, Make_Null (Loc));
4327 end loop;
4329 else
4330 declare
4331 CPP_Nb_Prims : constant Nat := CPP_Num_Prims (Typ);
4332 E : Entity_Id;
4333 Prim_Pos : Nat;
4334 Prim_Table : array (Nat range 1 .. Nb_Prim) of Entity_Id;
4335 Thunk_Code : Node_Id;
4336 Thunk_Id : Entity_Id;
4338 begin
4339 Prim_Table := (others => Empty);
4341 Prim_Elmt := First_Elmt (Primitive_Operations (Typ));
4342 while Present (Prim_Elmt) loop
4343 Prim := Node (Prim_Elmt);
4344 E := Ultimate_Alias (Prim);
4345 Prim_Pos := UI_To_Int (DT_Position (E));
4347 -- Do not reference predefined primitives because they are
4348 -- located in a separate dispatch table; skip abstract and
4349 -- eliminated primitives; skip primitives located in the C++
4350 -- part of the dispatch table because their slot is set by
4351 -- the IC routine.
4353 if not Is_Predefined_Dispatching_Operation (Prim)
4354 and then Present (Interface_Alias (Prim))
4355 and then not Is_Abstract_Subprogram (Alias (Prim))
4356 and then not Is_Eliminated (Alias (Prim))
4357 and then (not Is_CPP_Class (Root_Type (Typ))
4358 or else Prim_Pos > CPP_Nb_Prims)
4359 and then Find_Dispatching_Type
4360 (Interface_Alias (Prim)) = Iface
4362 -- Generate the code of the thunk only if the abstract
4363 -- interface type is not an immediate ancestor of
4364 -- Tagged_Type. Otherwise the DT associated with the
4365 -- interface is the primary DT.
4367 and then not Is_Ancestor (Iface, Typ,
4368 Use_Full_View => True)
4369 then
4370 if not Build_Thunks then
4371 Prim_Pos :=
4372 UI_To_Int (DT_Position (Interface_Alias (Prim)));
4373 Prim_Table (Prim_Pos) := Alias (Prim);
4375 else
4376 Expand_Interface_Thunk (Prim, Thunk_Id, Thunk_Code);
4378 if Present (Thunk_Id) then
4379 Prim_Pos :=
4380 UI_To_Int (DT_Position (Interface_Alias (Prim)));
4382 Prim_Table (Prim_Pos) := Thunk_Id;
4383 Append_To (Result, Thunk_Code);
4384 end if;
4385 end if;
4386 end if;
4388 Next_Elmt (Prim_Elmt);
4389 end loop;
4391 for J in Prim_Table'Range loop
4392 if Present (Prim_Table (J)) then
4393 New_Node :=
4394 Unchecked_Convert_To (RTE (RE_Prim_Ptr),
4395 Make_Attribute_Reference (Loc,
4396 Prefix => New_Occurrence_Of (Prim_Table (J), Loc),
4397 Attribute_Name => Name_Unrestricted_Access));
4399 else
4400 New_Node := Make_Null (Loc);
4401 end if;
4403 Append_To (Prim_Ops_Aggr_List, New_Node);
4404 end loop;
4405 end;
4406 end if;
4408 New_Node :=
4409 Make_Aggregate (Loc,
4410 Expressions => Prim_Ops_Aggr_List);
4412 Append_To (DT_Aggr_List, New_Node);
4414 -- Remember aggregates initializing dispatch tables
4416 Append_Elmt (New_Node, DT_Aggr);
4418 -- Note: Secondary dispatch tables are declared constant only if
4419 -- we can compute their offset field by means of the extra dummy
4420 -- object; otherwise they cannot be declared constant and the
4421 -- Offset_To_Top component is initialized by the IP routine.
4423 Append_To (Result,
4424 Make_Object_Declaration (Loc,
4425 Defining_Identifier => Iface_DT,
4426 Aliased_Present => True,
4427 Constant_Present => Present (Dummy_Object),
4429 Object_Definition =>
4430 Make_Subtype_Indication (Loc,
4431 Subtype_Mark => New_Occurrence_Of
4432 (RTE (RE_Dispatch_Table_Wrapper), Loc),
4433 Constraint => Make_Index_Or_Discriminant_Constraint (Loc,
4434 Constraints => DT_Constr_List)),
4436 Expression =>
4437 Make_Aggregate (Loc,
4438 Expressions => DT_Aggr_List)));
4440 Append_To (Result,
4441 Make_Attribute_Definition_Clause (Loc,
4442 Name => New_Occurrence_Of (Iface_DT, Loc),
4443 Chars => Name_Alignment,
4445 Expression =>
4446 Make_Attribute_Reference (Loc,
4447 Prefix =>
4448 New_Occurrence_Of (RTE (RE_Integer_Address), Loc),
4449 Attribute_Name => Name_Alignment)));
4451 if Exporting_Table then
4452 Export_DT (Typ, Iface_DT, Suffix_Index);
4454 -- Generate code to create the pointer to the dispatch table
4456 -- Iface_DT_Ptr : Tag := Tag!(DT.Prims_Ptr'Address);
4458 -- Note: This declaration is not added here if the table is exported
4459 -- because in such case Make_Tags has already added this declaration.
4461 else
4462 Append_To (Result,
4463 Make_Object_Declaration (Loc,
4464 Defining_Identifier => Iface_DT_Ptr,
4465 Constant_Present => True,
4467 Object_Definition =>
4468 New_Occurrence_Of (RTE (RE_Interface_Tag), Loc),
4470 Expression =>
4471 Unchecked_Convert_To (RTE (RE_Interface_Tag),
4472 Make_Attribute_Reference (Loc,
4473 Prefix =>
4474 Make_Selected_Component (Loc,
4475 Prefix => New_Occurrence_Of (Iface_DT, Loc),
4476 Selector_Name =>
4477 New_Occurrence_Of
4478 (RTE_Record_Component (RE_Prims_Ptr), Loc)),
4479 Attribute_Name => Name_Address))));
4480 end if;
4482 Append_To (Result,
4483 Make_Object_Declaration (Loc,
4484 Defining_Identifier => Predef_Prims_Ptr,
4485 Constant_Present => True,
4487 Object_Definition =>
4488 New_Occurrence_Of (RTE (RE_Address), Loc),
4490 Expression =>
4491 Make_Attribute_Reference (Loc,
4492 Prefix =>
4493 Make_Selected_Component (Loc,
4494 Prefix => New_Occurrence_Of (Iface_DT, Loc),
4495 Selector_Name =>
4496 New_Occurrence_Of
4497 (RTE_Record_Component (RE_Predef_Prims), Loc)),
4498 Attribute_Name => Name_Address)));
4500 -- Remember entities containing dispatch tables
4502 Append_Elmt (Predef_Prims, DT_Decl);
4503 Append_Elmt (Iface_DT, DT_Decl);
4504 end Make_Secondary_DT;
4506 -- Local variables
4508 Elab_Code : constant List_Id := New_List;
4509 Result : constant List_Id := New_List;
4510 Tname : constant Name_Id := Chars (Typ);
4512 -- When pragmas Discard_Names and No_Tagged_Streams simultaneously apply
4513 -- we initialize the Expanded_Name and the External_Tag of this tagged
4514 -- type with an empty string. This is useful to avoid exposing entity
4515 -- names at binary level. It can be done when both pragmas apply because
4516 -- (1) Discard_Names allows initializing Expanded_Name with an
4517 -- implementation defined value (Ada RM Section C.5 (7/2)).
4518 -- (2) External_Tag (combined with Internal_Tag) is used for object
4519 -- streaming and No_Tagged_Streams inhibits the generation of
4520 -- streams.
4522 Discard_Names : constant Boolean :=
4523 Present (No_Tagged_Streams_Pragma (Typ))
4524 and then (Global_Discard_Names
4525 or else Einfo.Discard_Names (Typ));
4527 -- The following name entries are used by Make_DT to generate a number
4528 -- of entities related to a tagged type. These entities may be generated
4529 -- in a scope other than that of the tagged type declaration, and if
4530 -- the entities for two tagged types with the same name happen to be
4531 -- generated in the same scope, we have to take care to use different
4532 -- names. This is achieved by means of a unique serial number appended
4533 -- to each generated entity name.
4535 Name_DT : constant Name_Id :=
4536 New_External_Name (Tname, 'T', Suffix_Index => -1);
4537 Name_Exname : constant Name_Id :=
4538 New_External_Name (Tname, 'E', Suffix_Index => -1);
4539 Name_HT_Link : constant Name_Id :=
4540 New_External_Name (Tname, 'H', Suffix_Index => -1);
4541 Name_Predef_Prims : constant Name_Id :=
4542 New_External_Name (Tname, 'R', Suffix_Index => -1);
4543 Name_SSD : constant Name_Id :=
4544 New_External_Name (Tname, 'S', Suffix_Index => -1);
4545 Name_TSD : constant Name_Id :=
4546 New_External_Name (Tname, 'B', Suffix_Index => -1);
4548 Saved_GM : constant Ghost_Mode_Type := Ghost_Mode;
4549 Saved_IGR : constant Node_Id := Ignored_Ghost_Region;
4550 -- Save the Ghost-related attributes to restore on exit
4552 AI : Elmt_Id;
4553 AI_Tag_Elmt : Elmt_Id;
4554 AI_Tag_Comp : Elmt_Id;
4555 DT : Entity_Id;
4556 DT_Aggr_List : List_Id;
4557 DT_Constr_List : List_Id;
4558 DT_Ptr : Entity_Id;
4559 Exname : Entity_Id;
4560 HT_Link : Entity_Id;
4561 ITable : Node_Id;
4562 I_Depth : Nat := 0;
4563 Iface_Table_Node : Node_Id;
4564 Name_ITable : Name_Id;
4565 Nb_Predef_Prims : Nat := 0;
4566 Nb_Prim : Nat := 0;
4567 New_Node : Node_Id;
4568 Num_Ifaces : Nat := 0;
4569 Parent_Typ : Entity_Id;
4570 Predef_Prims : Entity_Id;
4571 Prim : Entity_Id;
4572 Prim_Elmt : Elmt_Id;
4573 Prim_Ops_Aggr_List : List_Id;
4574 SSD : Entity_Id;
4575 Suffix_Index : Int;
4576 Typ_Comps : Elist_Id;
4577 Typ_Ifaces : Elist_Id;
4578 TSD : Entity_Id;
4579 TSD_Aggr_List : List_Id;
4580 TSD_Tags_List : List_Id;
4582 -- Start of processing for Make_DT
4584 begin
4585 pragma Assert (Is_Frozen (Typ));
4587 -- The tagged type being processed may be subject to pragma Ghost. Set
4588 -- the mode now to ensure that any nodes generated during dispatch table
4589 -- creation are properly marked as Ghost.
4591 Set_Ghost_Mode (Typ);
4593 -- Handle cases in which there is no need to build the dispatch table
4595 if Has_Dispatch_Table (Typ)
4596 or else No (Access_Disp_Table (Typ))
4597 or else Is_CPP_Class (Typ)
4598 then
4599 goto Leave;
4601 elsif No_Run_Time_Mode then
4602 Error_Msg_CRT ("tagged types", Typ);
4603 goto Leave;
4605 elsif not RTE_Available (RE_Tag) then
4606 Append_To (Result,
4607 Make_Object_Declaration (Loc,
4608 Defining_Identifier =>
4609 Node (First_Elmt (Access_Disp_Table (Typ))),
4610 Object_Definition => New_Occurrence_Of (RTE (RE_Tag), Loc),
4611 Constant_Present => True,
4612 Expression =>
4613 Unchecked_Convert_To (RTE (RE_Tag),
4614 New_Occurrence_Of (RTE (RE_Null_Address), Loc))));
4616 Analyze_List (Result, Suppress => All_Checks);
4617 Error_Msg_CRT ("tagged types", Typ);
4618 goto Leave;
4619 end if;
4621 -- Ensure that the value of Max_Predef_Prims defined in a-tags is
4622 -- correct. Valid values are 9 under configurable runtime or 15
4623 -- with full runtime.
4625 if RTE_Available (RE_Interface_Data) then
4626 if Max_Predef_Prims /= 15 then
4627 Error_Msg_N ("run-time library configuration error", Typ);
4628 goto Leave;
4629 end if;
4630 else
4631 if Max_Predef_Prims /= 9 then
4632 Error_Msg_N ("run-time library configuration error", Typ);
4633 Error_Msg_CRT ("tagged types", Typ);
4634 goto Leave;
4635 end if;
4636 end if;
4638 DT := Make_Defining_Identifier (Loc, Name_DT);
4639 Exname := Make_Defining_Identifier (Loc, Name_Exname);
4640 HT_Link := Make_Defining_Identifier (Loc, Name_HT_Link);
4641 Predef_Prims := Make_Defining_Identifier (Loc, Name_Predef_Prims);
4642 SSD := Make_Defining_Identifier (Loc, Name_SSD);
4643 TSD := Make_Defining_Identifier (Loc, Name_TSD);
4645 -- Initialize Parent_Typ handling private types
4647 Parent_Typ := Etype (Typ);
4649 if Present (Full_View (Parent_Typ)) then
4650 Parent_Typ := Full_View (Parent_Typ);
4651 end if;
4653 -- Ensure that all the primitives are frozen. This is only required when
4654 -- building static dispatch tables --- the primitives must be frozen to
4655 -- be referenced (otherwise we have problems with the backend). It is
4656 -- not a requirement with nonstatic dispatch tables because in this case
4657 -- we generate now an empty dispatch table; the extra code required to
4658 -- register the primitives in the slots will be generated later --- when
4659 -- each primitive is frozen (see Freeze_Subprogram).
4661 if Building_Static_DT (Typ) then
4662 declare
4663 Saved_FLLTT : constant Boolean :=
4664 Freezing_Library_Level_Tagged_Type;
4666 Formal : Entity_Id;
4667 Frnodes : List_Id;
4668 Prim : Entity_Id;
4669 Prim_Elmt : Elmt_Id;
4671 begin
4672 Freezing_Library_Level_Tagged_Type := True;
4674 Prim_Elmt := First_Elmt (Primitive_Operations (Typ));
4675 while Present (Prim_Elmt) loop
4676 Prim := Node (Prim_Elmt);
4677 Frnodes := Freeze_Entity (Prim, Typ);
4679 -- We disable this check for abstract subprograms, given that
4680 -- they cannot be called directly and thus the state of their
4681 -- untagged formals is of no concern. The RM is unclear in any
4682 -- case concerning the need for this check, and this topic may
4683 -- go back to the ARG.
4685 if not Is_Abstract_Subprogram (Prim) then
4686 Formal := First_Formal (Prim);
4687 while Present (Formal) loop
4688 Check_Premature_Freezing (Prim, Typ, Etype (Formal));
4689 Next_Formal (Formal);
4690 end loop;
4692 Check_Premature_Freezing (Prim, Typ, Etype (Prim));
4693 end if;
4695 if Present (Frnodes) then
4696 Append_List_To (Result, Frnodes);
4697 end if;
4699 Next_Elmt (Prim_Elmt);
4700 end loop;
4702 Freezing_Library_Level_Tagged_Type := Saved_FLLTT;
4703 end;
4704 end if;
4706 if Building_Static_Secondary_DT (Typ) then
4707 declare
4708 Cannot_Have_Null_Disc : Boolean := False;
4709 Name_Dummy_Object : constant Name_Id :=
4710 New_External_Name (Tname,
4711 'P', Suffix_Index => -1);
4712 begin
4713 Dummy_Object := Make_Defining_Identifier (Loc, Name_Dummy_Object);
4715 -- Define the extra object imported and constant to avoid linker
4716 -- errors (since this object is never declared). Required because
4717 -- we implement RM 13.3(19) for exported and imported (variable)
4718 -- objects by making them volatile.
4720 Set_Is_Imported (Dummy_Object);
4721 Set_Ekind (Dummy_Object, E_Constant);
4722 Set_Is_True_Constant (Dummy_Object);
4723 Set_Related_Type (Dummy_Object, Typ);
4725 -- The scope must be set now to call Get_External_Name
4727 Set_Scope (Dummy_Object, Current_Scope);
4729 Get_External_Name (Dummy_Object);
4730 Set_Interface_Name (Dummy_Object,
4731 Make_String_Literal (Loc, Strval => String_From_Name_Buffer));
4733 -- Ensure proper Sprint output of this implicit importation
4735 Set_Is_Internal (Dummy_Object);
4737 if not Has_Discriminants (Typ) then
4738 Append_To (Result,
4739 Make_Object_Declaration (Loc,
4740 Defining_Identifier => Dummy_Object,
4741 Constant_Present => True,
4742 Object_Definition => New_Occurrence_Of (Typ, Loc)));
4743 else
4744 declare
4745 Constr_List : constant List_Id := New_List;
4746 Discrim : Node_Id;
4748 begin
4749 Discrim := First_Discriminant (Typ);
4750 while Present (Discrim) loop
4751 if Is_Discrete_Type (Etype (Discrim)) then
4752 Append_To (Constr_List,
4753 Make_Attribute_Reference (Loc,
4754 Prefix =>
4755 New_Occurrence_Of (Etype (Discrim), Loc),
4756 Attribute_Name => Name_First));
4758 else
4759 pragma Assert (Is_Access_Type (Etype (Discrim)));
4760 Cannot_Have_Null_Disc :=
4761 Cannot_Have_Null_Disc
4762 or else Can_Never_Be_Null (Etype (Discrim));
4763 Append_To (Constr_List, Make_Null (Loc));
4764 end if;
4766 Next_Discriminant (Discrim);
4767 end loop;
4769 Append_To (Result,
4770 Make_Object_Declaration (Loc,
4771 Defining_Identifier => Dummy_Object,
4772 Constant_Present => True,
4773 Object_Definition =>
4774 Make_Subtype_Indication (Loc,
4775 Subtype_Mark => New_Occurrence_Of (Typ, Loc),
4776 Constraint =>
4777 Make_Index_Or_Discriminant_Constraint (Loc,
4778 Constraints => Constr_List))));
4779 end;
4780 end if;
4782 -- Given that the dummy object will not be declared at run time,
4783 -- analyze its declaration with expansion disabled and warnings
4784 -- and error messages ignored.
4786 Expander_Mode_Save_And_Set (False);
4787 Ignore_Errors_Enable := Ignore_Errors_Enable + 1;
4788 Analyze (Last (Result), Suppress => All_Checks);
4789 Ignore_Errors_Enable := Ignore_Errors_Enable - 1;
4790 Expander_Mode_Restore;
4791 end;
4792 end if;
4794 -- Ada 2005 (AI-251): Build the secondary dispatch tables
4796 if Has_Interfaces (Typ) then
4797 Collect_Interface_Components (Typ, Typ_Comps);
4799 -- Each secondary dispatch table is assigned an unique positive
4800 -- suffix index; such value also corresponds with the location of
4801 -- its entity in the Dispatch_Table_Wrappers list (see Make_Tags).
4803 -- Note: This value must be kept sync with the Suffix_Index values
4804 -- generated by Make_Tags
4806 Suffix_Index := 1;
4807 AI_Tag_Elmt :=
4808 Next_Elmt (Next_Elmt (First_Elmt (Access_Disp_Table (Typ))));
4810 AI_Tag_Comp := First_Elmt (Typ_Comps);
4811 while Present (AI_Tag_Comp) loop
4812 pragma Assert (Has_Suffix (Node (AI_Tag_Elmt), 'P'));
4814 -- Build the secondary table containing pointers to thunks
4816 Make_Secondary_DT
4817 (Typ => Typ,
4818 Iface =>
4819 Base_Type (Related_Type (Node (AI_Tag_Comp))),
4820 Iface_Comp => Node (AI_Tag_Comp),
4821 Suffix_Index => Suffix_Index,
4822 Num_Iface_Prims =>
4823 UI_To_Int (DT_Entry_Count (Node (AI_Tag_Comp))),
4824 Iface_DT_Ptr => Node (AI_Tag_Elmt),
4825 Predef_Prims_Ptr => Node (Next_Elmt (AI_Tag_Elmt)),
4826 Build_Thunks => True,
4827 Result => Result);
4829 -- Skip secondary dispatch table referencing thunks to predefined
4830 -- primitives.
4832 Next_Elmt (AI_Tag_Elmt);
4833 pragma Assert (Has_Suffix (Node (AI_Tag_Elmt), 'Y'));
4835 -- Secondary dispatch table referencing user-defined primitives
4836 -- covered by this interface.
4838 Next_Elmt (AI_Tag_Elmt);
4839 pragma Assert (Has_Suffix (Node (AI_Tag_Elmt), 'D'));
4841 -- Build the secondary table containing pointers to primitives
4842 -- (used to give support to Generic Dispatching Constructors).
4844 Make_Secondary_DT
4845 (Typ => Typ,
4846 Iface => Base_Type
4847 (Related_Type (Node (AI_Tag_Comp))),
4848 Iface_Comp => Node (AI_Tag_Comp),
4849 Suffix_Index => -1,
4850 Num_Iface_Prims => UI_To_Int
4851 (DT_Entry_Count (Node (AI_Tag_Comp))),
4852 Iface_DT_Ptr => Node (AI_Tag_Elmt),
4853 Predef_Prims_Ptr => Node (Next_Elmt (AI_Tag_Elmt)),
4854 Build_Thunks => False,
4855 Result => Result);
4857 -- Skip secondary dispatch table referencing predefined primitives
4859 Next_Elmt (AI_Tag_Elmt);
4860 pragma Assert (Has_Suffix (Node (AI_Tag_Elmt), 'Z'));
4862 Suffix_Index := Suffix_Index + 1;
4863 Next_Elmt (AI_Tag_Elmt);
4864 Next_Elmt (AI_Tag_Comp);
4865 end loop;
4866 end if;
4868 -- Get the _tag entity and number of primitives of its dispatch table
4870 DT_Ptr := Node (First_Elmt (Access_Disp_Table (Typ)));
4871 Nb_Prim := UI_To_Int (DT_Entry_Count (First_Tag_Component (Typ)));
4873 if Generate_SCIL then
4874 Nb_Prim := 0;
4875 end if;
4877 Set_Is_Statically_Allocated (DT, Is_Library_Level_Tagged_Type (Typ));
4878 Set_Is_Statically_Allocated (SSD, Is_Library_Level_Tagged_Type (Typ));
4879 Set_Is_Statically_Allocated (TSD, Is_Library_Level_Tagged_Type (Typ));
4880 Set_Is_Statically_Allocated (Predef_Prims,
4881 Is_Library_Level_Tagged_Type (Typ));
4883 -- In case of locally defined tagged type we declare the object
4884 -- containing the dispatch table by means of a variable. Its
4885 -- initialization is done later by means of an assignment. This is
4886 -- required to generate its External_Tag.
4888 if not Building_Static_DT (Typ) then
4890 -- Generate:
4891 -- DT : No_Dispatch_Table_Wrapper;
4892 -- for DT'Alignment use Address'Alignment;
4893 -- DT_Ptr : Tag := !Tag (DT.NDT_Prims_Ptr'Address);
4895 if not Has_DT (Typ) then
4896 Append_To (Result,
4897 Make_Object_Declaration (Loc,
4898 Defining_Identifier => DT,
4899 Aliased_Present => True,
4900 Constant_Present => False,
4901 Object_Definition =>
4902 New_Occurrence_Of
4903 (RTE (RE_No_Dispatch_Table_Wrapper), Loc)));
4905 Append_To (Result,
4906 Make_Attribute_Definition_Clause (Loc,
4907 Name => New_Occurrence_Of (DT, Loc),
4908 Chars => Name_Alignment,
4909 Expression =>
4910 Make_Attribute_Reference (Loc,
4911 Prefix =>
4912 New_Occurrence_Of (RTE (RE_Integer_Address), Loc),
4913 Attribute_Name => Name_Alignment)));
4915 Append_To (Result,
4916 Make_Object_Declaration (Loc,
4917 Defining_Identifier => DT_Ptr,
4918 Object_Definition => New_Occurrence_Of (RTE (RE_Tag), Loc),
4919 Constant_Present => True,
4920 Expression =>
4921 Unchecked_Convert_To (RTE (RE_Tag),
4922 Make_Attribute_Reference (Loc,
4923 Prefix =>
4924 Make_Selected_Component (Loc,
4925 Prefix => New_Occurrence_Of (DT, Loc),
4926 Selector_Name =>
4927 New_Occurrence_Of
4928 (RTE_Record_Component (RE_NDT_Prims_Ptr), Loc)),
4929 Attribute_Name => Name_Address))));
4931 Set_Is_Statically_Allocated (DT_Ptr,
4932 Is_Library_Level_Tagged_Type (Typ));
4934 -- Generate the SCIL node for the previous object declaration
4935 -- because it has a tag initialization.
4937 if Generate_SCIL then
4938 New_Node :=
4939 Make_SCIL_Dispatch_Table_Tag_Init (Sloc (Last (Result)));
4940 Set_SCIL_Entity (New_Node, Typ);
4941 Set_SCIL_Node (Last (Result), New_Node);
4943 goto Leave_SCIL;
4945 -- Gnat2scil has its own implementation of dispatch tables,
4946 -- different than what is being implemented here. Generating
4947 -- further dispatch table initialization code would just
4948 -- cause gnat2scil to generate useless Scil which CodePeer
4949 -- would waste time and space analyzing, so we skip it.
4950 end if;
4952 -- Generate:
4953 -- DT : Dispatch_Table_Wrapper (Nb_Prim);
4954 -- for DT'Alignment use Address'Alignment;
4955 -- DT_Ptr : Tag := !Tag (DT.Prims_Ptr'Address);
4957 else
4958 -- If the tagged type has no primitives we add a dummy slot
4959 -- whose address will be the tag of this type.
4961 if Nb_Prim = 0 then
4962 DT_Constr_List :=
4963 New_List (Make_Integer_Literal (Loc, 1));
4964 else
4965 DT_Constr_List :=
4966 New_List (Make_Integer_Literal (Loc, Nb_Prim));
4967 end if;
4969 Append_To (Result,
4970 Make_Object_Declaration (Loc,
4971 Defining_Identifier => DT,
4972 Aliased_Present => True,
4973 Constant_Present => False,
4974 Object_Definition =>
4975 Make_Subtype_Indication (Loc,
4976 Subtype_Mark =>
4977 New_Occurrence_Of (RTE (RE_Dispatch_Table_Wrapper), Loc),
4978 Constraint =>
4979 Make_Index_Or_Discriminant_Constraint (Loc,
4980 Constraints => DT_Constr_List))));
4982 Append_To (Result,
4983 Make_Attribute_Definition_Clause (Loc,
4984 Name => New_Occurrence_Of (DT, Loc),
4985 Chars => Name_Alignment,
4986 Expression =>
4987 Make_Attribute_Reference (Loc,
4988 Prefix =>
4989 New_Occurrence_Of (RTE (RE_Integer_Address), Loc),
4990 Attribute_Name => Name_Alignment)));
4992 Append_To (Result,
4993 Make_Object_Declaration (Loc,
4994 Defining_Identifier => DT_Ptr,
4995 Object_Definition => New_Occurrence_Of (RTE (RE_Tag), Loc),
4996 Constant_Present => True,
4997 Expression =>
4998 Unchecked_Convert_To (RTE (RE_Tag),
4999 Make_Attribute_Reference (Loc,
5000 Prefix =>
5001 Make_Selected_Component (Loc,
5002 Prefix => New_Occurrence_Of (DT, Loc),
5003 Selector_Name =>
5004 New_Occurrence_Of
5005 (RTE_Record_Component (RE_Prims_Ptr), Loc)),
5006 Attribute_Name => Name_Address))));
5008 Set_Is_Statically_Allocated (DT_Ptr,
5009 Is_Library_Level_Tagged_Type (Typ));
5011 -- Generate the SCIL node for the previous object declaration
5012 -- because it has a tag initialization.
5014 if Generate_SCIL then
5015 New_Node :=
5016 Make_SCIL_Dispatch_Table_Tag_Init (Sloc (Last (Result)));
5017 Set_SCIL_Entity (New_Node, Typ);
5018 Set_SCIL_Node (Last (Result), New_Node);
5020 goto Leave_SCIL;
5022 -- Gnat2scil has its own implementation of dispatch tables,
5023 -- different than what is being implemented here. Generating
5024 -- further dispatch table initialization code would just
5025 -- cause gnat2scil to generate useless Scil which CodePeer
5026 -- would waste time and space analyzing, so we skip it.
5027 end if;
5029 Append_To (Result,
5030 Make_Object_Declaration (Loc,
5031 Defining_Identifier =>
5032 Node (Next_Elmt (First_Elmt (Access_Disp_Table (Typ)))),
5033 Constant_Present => True,
5034 Object_Definition =>
5035 New_Occurrence_Of (RTE (RE_Address), Loc),
5036 Expression =>
5037 Make_Attribute_Reference (Loc,
5038 Prefix =>
5039 Make_Selected_Component (Loc,
5040 Prefix => New_Occurrence_Of (DT, Loc),
5041 Selector_Name =>
5042 New_Occurrence_Of
5043 (RTE_Record_Component (RE_Predef_Prims), Loc)),
5044 Attribute_Name => Name_Address)));
5045 end if;
5046 end if;
5048 -- Generate: Expanded_Name : constant String := "";
5050 if Discard_Names then
5051 Append_To (Result,
5052 Make_Object_Declaration (Loc,
5053 Defining_Identifier => Exname,
5054 Constant_Present => True,
5055 Object_Definition => New_Occurrence_Of (Standard_String, Loc),
5056 Expression =>
5057 Make_String_Literal (Loc, "")));
5059 -- Generate: Exname : constant String := full_qualified_name (typ);
5060 -- The type itself may be an anonymous parent type, so use the first
5061 -- subtype to have a user-recognizable name.
5063 else
5064 Append_To (Result,
5065 Make_Object_Declaration (Loc,
5066 Defining_Identifier => Exname,
5067 Constant_Present => True,
5068 Object_Definition => New_Occurrence_Of (Standard_String, Loc),
5069 Expression =>
5070 Make_String_Literal (Loc,
5071 Fully_Qualified_Name_String (First_Subtype (Typ)))));
5072 end if;
5074 Set_Is_Statically_Allocated (Exname);
5075 Set_Is_True_Constant (Exname);
5077 -- Declare the object used by Ada.Tags.Register_Tag
5079 if RTE_Available (RE_Register_Tag) then
5080 Append_To (Result,
5081 Make_Object_Declaration (Loc,
5082 Defining_Identifier => HT_Link,
5083 Object_Definition => New_Occurrence_Of (RTE (RE_Tag), Loc),
5084 Expression => New_Occurrence_Of (RTE (RE_No_Tag), Loc)));
5085 end if;
5087 -- Generate code to create the storage for the type specific data object
5088 -- with enough space to store the tags of the ancestors plus the tags
5089 -- of all the implemented interfaces (as described in a-tags.adb).
5091 -- TSD : Type_Specific_Data (I_Depth) :=
5092 -- (Idepth => I_Depth,
5093 -- Access_Level => Type_Access_Level (Typ),
5094 -- Alignment => Typ'Alignment,
5095 -- Expanded_Name => Cstring_Ptr!(Exname'Address))
5096 -- External_Tag => Cstring_Ptr!(Exname'Address))
5097 -- HT_Link => HT_Link'Address,
5098 -- Transportable => <<boolean-value>>,
5099 -- Is_Abstract => <<boolean-value>>,
5100 -- Needs_Finalization => <<boolean-value>>,
5101 -- [ Size_Func => Size_Prim'Access, ]
5102 -- [ Interfaces_Table => <<access-value>>, ]
5103 -- [ SSD => SSD_Table'Address ]
5104 -- Tags_Table => (0 => null,
5105 -- 1 => Parent'Tag
5106 -- ...);
5107 -- for TSD'Alignment use Address'Alignment
5109 TSD_Aggr_List := New_List;
5111 -- Idepth: Count ancestors to compute the inheritance depth. For private
5112 -- extensions, always go to the full view in order to compute the real
5113 -- inheritance depth.
5115 declare
5116 Current_Typ : Entity_Id;
5117 Parent_Typ : Entity_Id;
5119 begin
5120 I_Depth := 0;
5121 Current_Typ := Typ;
5122 loop
5123 Parent_Typ := Etype (Current_Typ);
5125 if Is_Private_Type (Parent_Typ) then
5126 Parent_Typ := Full_View (Base_Type (Parent_Typ));
5127 end if;
5129 exit when Parent_Typ = Current_Typ;
5131 I_Depth := I_Depth + 1;
5132 Current_Typ := Parent_Typ;
5133 end loop;
5134 end;
5136 Append_To (TSD_Aggr_List,
5137 Make_Integer_Literal (Loc, I_Depth));
5139 -- Access_Level
5141 Append_To (TSD_Aggr_List,
5142 Make_Integer_Literal (Loc, Type_Access_Level (Typ)));
5144 -- Alignment
5146 -- For CPP types we cannot rely on the value of 'Alignment provided
5147 -- by the backend to initialize this TSD field.
5149 if Convention (Typ) = Convention_CPP
5150 or else Is_CPP_Class (Root_Type (Typ))
5151 then
5152 Append_To (TSD_Aggr_List,
5153 Make_Integer_Literal (Loc, 0));
5154 else
5155 Append_To (TSD_Aggr_List,
5156 Make_Attribute_Reference (Loc,
5157 Prefix => New_Occurrence_Of (Typ, Loc),
5158 Attribute_Name => Name_Alignment));
5159 end if;
5161 -- Expanded_Name
5163 Append_To (TSD_Aggr_List,
5164 Unchecked_Convert_To (RTE (RE_Cstring_Ptr),
5165 Make_Attribute_Reference (Loc,
5166 Prefix => New_Occurrence_Of (Exname, Loc),
5167 Attribute_Name => Name_Address)));
5169 -- External_Tag of a local tagged type
5171 -- <typ>A : constant String :=
5172 -- "Internal tag at 16#tag-addr#: <full-name-of-typ>";
5174 -- The reason we generate this strange name is that we do not want to
5175 -- enter local tagged types in the global hash table used to compute
5176 -- the Internal_Tag attribute for two reasons:
5178 -- 1. It is hard to avoid a tasking race condition for entering the
5179 -- entry into the hash table.
5181 -- 2. It would cause a storage leak, unless we rig up considerable
5182 -- mechanism to remove the entry from the hash table on exit.
5184 -- So what we do is to generate the above external tag name, where the
5185 -- hex address is the address of the local dispatch table (i.e. exactly
5186 -- the value we want if Internal_Tag is computed from this string).
5188 -- Of course this value will only be valid if the tagged type is still
5189 -- in scope, but it clearly must be erroneous to compute the internal
5190 -- tag of a tagged type that is out of scope.
5192 -- We don't do this processing if an explicit external tag has been
5193 -- specified. That's an odd case for which we have already issued a
5194 -- warning, where we will not be able to compute the internal tag.
5196 if not Discard_Names
5197 and then not Is_Library_Level_Entity (Typ)
5198 and then not Has_External_Tag_Rep_Clause (Typ)
5199 then
5200 declare
5201 Exname : constant Entity_Id :=
5202 Make_Defining_Identifier (Loc,
5203 Chars => New_External_Name (Tname, 'A'));
5204 Full_Name : constant String_Id :=
5205 Fully_Qualified_Name_String (First_Subtype (Typ));
5206 Str1_Id : String_Id;
5207 Str2_Id : String_Id;
5209 begin
5210 -- Generate:
5211 -- Str1 = "Internal tag at 16#";
5213 Start_String;
5214 Store_String_Chars ("Internal tag at 16#");
5215 Str1_Id := End_String;
5217 -- Generate:
5218 -- Str2 = "#: <type-full-name>";
5220 Start_String;
5221 Store_String_Chars ("#: ");
5222 Store_String_Chars (Full_Name);
5223 Str2_Id := End_String;
5225 -- Generate:
5226 -- Exname : constant String :=
5227 -- Str1 & Address_Image (Tag) & Str2;
5229 if RTE_Available (RE_Address_Image) then
5230 Append_To (Result,
5231 Make_Object_Declaration (Loc,
5232 Defining_Identifier => Exname,
5233 Constant_Present => True,
5234 Object_Definition => New_Occurrence_Of
5235 (Standard_String, Loc),
5236 Expression =>
5237 Make_Op_Concat (Loc,
5238 Left_Opnd => Make_String_Literal (Loc, Str1_Id),
5239 Right_Opnd =>
5240 Make_Op_Concat (Loc,
5241 Left_Opnd =>
5242 Make_Function_Call (Loc,
5243 Name =>
5244 New_Occurrence_Of
5245 (RTE (RE_Address_Image), Loc),
5246 Parameter_Associations => New_List (
5247 Unchecked_Convert_To (RTE (RE_Address),
5248 New_Occurrence_Of (DT_Ptr, Loc)))),
5249 Right_Opnd =>
5250 Make_String_Literal (Loc, Str2_Id)))));
5252 -- Generate:
5253 -- Exname : constant String := Str1 & Str2;
5255 else
5256 Append_To (Result,
5257 Make_Object_Declaration (Loc,
5258 Defining_Identifier => Exname,
5259 Constant_Present => True,
5260 Object_Definition =>
5261 New_Occurrence_Of (Standard_String, Loc),
5262 Expression =>
5263 Make_Op_Concat (Loc,
5264 Left_Opnd => Make_String_Literal (Loc, Str1_Id),
5265 Right_Opnd => Make_String_Literal (Loc, Str2_Id))));
5266 end if;
5268 New_Node :=
5269 Unchecked_Convert_To (RTE (RE_Cstring_Ptr),
5270 Make_Attribute_Reference (Loc,
5271 Prefix => New_Occurrence_Of (Exname, Loc),
5272 Attribute_Name => Name_Address));
5273 end;
5275 -- External tag of a library-level tagged type: Check for a definition
5276 -- of External_Tag. The clause is considered only if it applies to this
5277 -- specific tagged type, as opposed to one of its ancestors.
5278 -- If the type is an unconstrained type extension, we are building the
5279 -- dispatch table of its anonymous base type, so the external tag, if
5280 -- any was specified, must be retrieved from the first subtype. Go to
5281 -- the full view in case the clause is in the private part.
5283 else
5284 declare
5285 Def : constant Node_Id := Get_Attribute_Definition_Clause
5286 (Underlying_Type (First_Subtype (Typ)),
5287 Attribute_External_Tag);
5289 Old_Val : String_Id;
5290 New_Val : String_Id;
5291 E : Entity_Id;
5293 begin
5294 if not Present (Def)
5295 or else Entity (Name (Def)) /= First_Subtype (Typ)
5296 then
5297 New_Node :=
5298 Unchecked_Convert_To (RTE (RE_Cstring_Ptr),
5299 Make_Attribute_Reference (Loc,
5300 Prefix => New_Occurrence_Of (Exname, Loc),
5301 Attribute_Name => Name_Address));
5302 else
5303 Old_Val := Strval (Expr_Value_S (Expression (Def)));
5305 -- For the rep clause "for <typ>'external_tag use y" generate:
5307 -- <typ>A : constant string := y;
5309 -- <typ>A'Address is used to set the External_Tag component
5310 -- of the TSD
5312 -- Create a new nul terminated string if it is not already
5314 if String_Length (Old_Val) > 0
5315 and then
5316 Get_String_Char (Old_Val, String_Length (Old_Val)) = 0
5317 then
5318 New_Val := Old_Val;
5319 else
5320 Start_String (Old_Val);
5321 Store_String_Char (Get_Char_Code (ASCII.NUL));
5322 New_Val := End_String;
5323 end if;
5325 E := Make_Defining_Identifier (Loc,
5326 New_External_Name (Chars (Typ), 'A'));
5328 Append_To (Result,
5329 Make_Object_Declaration (Loc,
5330 Defining_Identifier => E,
5331 Constant_Present => True,
5332 Object_Definition =>
5333 New_Occurrence_Of (Standard_String, Loc),
5334 Expression =>
5335 Make_String_Literal (Loc, New_Val)));
5337 New_Node :=
5338 Unchecked_Convert_To (RTE (RE_Cstring_Ptr),
5339 Make_Attribute_Reference (Loc,
5340 Prefix => New_Occurrence_Of (E, Loc),
5341 Attribute_Name => Name_Address));
5342 end if;
5343 end;
5344 end if;
5346 Append_To (TSD_Aggr_List, New_Node);
5348 -- HT_Link
5350 if RTE_Available (RE_Register_Tag) then
5351 Append_To (TSD_Aggr_List,
5352 Unchecked_Convert_To (RTE (RE_Tag_Ptr),
5353 Make_Attribute_Reference (Loc,
5354 Prefix => New_Occurrence_Of (HT_Link, Loc),
5355 Attribute_Name => Name_Address)));
5357 elsif RTE_Record_Component_Available (RE_HT_Link) then
5358 Append_To (TSD_Aggr_List,
5359 Unchecked_Convert_To (RTE (RE_Tag_Ptr),
5360 New_Occurrence_Of (RTE (RE_Null_Address), Loc)));
5361 end if;
5363 -- Transportable: Set for types that can be used in remote calls
5364 -- with respect to E.4(18) legality rules.
5366 declare
5367 Transportable : Entity_Id;
5369 begin
5370 Transportable :=
5371 Boolean_Literals
5372 (Is_Pure (Typ)
5373 or else Is_Shared_Passive (Typ)
5374 or else
5375 ((Is_Remote_Types (Typ)
5376 or else Is_Remote_Call_Interface (Typ))
5377 and then Original_View_In_Visible_Part (Typ))
5378 or else not Comes_From_Source (Typ));
5380 Append_To (TSD_Aggr_List,
5381 New_Occurrence_Of (Transportable, Loc));
5382 end;
5384 -- Is_Abstract (Ada 2012: AI05-0173). This functionality is not
5385 -- available in the HIE runtime.
5387 if RTE_Record_Component_Available (RE_Is_Abstract) then
5388 declare
5389 Is_Abstract : Entity_Id;
5390 begin
5391 Is_Abstract := Boolean_Literals (Is_Abstract_Type (Typ));
5392 Append_To (TSD_Aggr_List,
5393 New_Occurrence_Of (Is_Abstract, Loc));
5394 end;
5395 end if;
5397 -- Needs_Finalization: Set if the type is controlled or has controlled
5398 -- components.
5400 declare
5401 Needs_Fin : Entity_Id;
5402 begin
5403 Needs_Fin := Boolean_Literals (Needs_Finalization (Typ));
5404 Append_To (TSD_Aggr_List, New_Occurrence_Of (Needs_Fin, Loc));
5405 end;
5407 -- Size_Func
5409 if RTE_Record_Component_Available (RE_Size_Func) then
5411 -- Initialize this field to Null_Address if we are not building
5412 -- static dispatch tables static or if the size function is not
5413 -- available. In the former case we cannot initialize this field
5414 -- until the function is frozen and registered in the dispatch
5415 -- table (see Register_Primitive).
5417 if not Building_Static_DT (Typ) or else not Has_DT (Typ) then
5418 Append_To (TSD_Aggr_List,
5419 Unchecked_Convert_To (RTE (RE_Size_Ptr),
5420 New_Occurrence_Of (RTE (RE_Null_Address), Loc)));
5422 else
5423 declare
5424 Prim_Elmt : Elmt_Id;
5425 Prim : Entity_Id;
5426 Size_Comp : Node_Id := Empty;
5428 begin
5429 Prim_Elmt := First_Elmt (Primitive_Operations (Typ));
5430 while Present (Prim_Elmt) loop
5431 Prim := Node (Prim_Elmt);
5433 if Chars (Prim) = Name_uSize then
5434 Prim := Ultimate_Alias (Prim);
5436 if Is_Abstract_Subprogram (Prim) then
5437 Size_Comp :=
5438 Unchecked_Convert_To (RTE (RE_Size_Ptr),
5439 New_Occurrence_Of (RTE (RE_Null_Address), Loc));
5440 else
5441 Size_Comp :=
5442 Unchecked_Convert_To (RTE (RE_Size_Ptr),
5443 Make_Attribute_Reference (Loc,
5444 Prefix => New_Occurrence_Of (Prim, Loc),
5445 Attribute_Name => Name_Unrestricted_Access));
5446 end if;
5448 exit;
5449 end if;
5451 Next_Elmt (Prim_Elmt);
5452 end loop;
5454 pragma Assert (Present (Size_Comp));
5455 Append_To (TSD_Aggr_List, Size_Comp);
5456 end;
5457 end if;
5458 end if;
5460 -- Interfaces_Table (required for AI-405)
5462 if RTE_Record_Component_Available (RE_Interfaces_Table) then
5464 -- Count the number of interface types implemented by Typ
5466 Collect_Interfaces (Typ, Typ_Ifaces);
5468 AI := First_Elmt (Typ_Ifaces);
5469 while Present (AI) loop
5470 Num_Ifaces := Num_Ifaces + 1;
5471 Next_Elmt (AI);
5472 end loop;
5474 if Num_Ifaces = 0 then
5475 Iface_Table_Node := Make_Null (Loc);
5477 -- Generate the Interface_Table object
5479 else
5480 declare
5481 TSD_Ifaces_List : constant List_Id := New_List;
5482 Elmt : Elmt_Id;
5483 Ifaces_List : Elist_Id := No_Elist;
5484 Ifaces_Comp_List : Elist_Id := No_Elist;
5485 Ifaces_Tag_List : Elist_Id;
5486 Offset_To_Top : Node_Id;
5487 Sec_DT_Tag : Node_Id;
5489 begin
5490 -- Collect interfaces information if we need to compute the
5491 -- offset to the top using the dummy object.
5493 if Present (Dummy_Object) then
5494 Collect_Interfaces_Info (Typ,
5495 Ifaces_List, Ifaces_Comp_List, Ifaces_Tag_List);
5496 end if;
5498 AI := First_Elmt (Typ_Ifaces);
5499 while Present (AI) loop
5500 if Is_Ancestor (Node (AI), Typ, Use_Full_View => True) then
5501 Sec_DT_Tag := New_Occurrence_Of (DT_Ptr, Loc);
5503 else
5504 Elmt :=
5505 Next_Elmt
5506 (Next_Elmt (First_Elmt (Access_Disp_Table (Typ))));
5507 pragma Assert (Has_Thunks (Node (Elmt)));
5509 while Is_Tag (Node (Elmt))
5510 and then not
5511 Is_Ancestor (Node (AI), Related_Type (Node (Elmt)),
5512 Use_Full_View => True)
5513 loop
5514 pragma Assert (Has_Thunks (Node (Elmt)));
5515 Next_Elmt (Elmt);
5516 pragma Assert (Has_Thunks (Node (Elmt)));
5517 Next_Elmt (Elmt);
5518 pragma Assert (not Has_Thunks (Node (Elmt)));
5519 Next_Elmt (Elmt);
5520 pragma Assert (not Has_Thunks (Node (Elmt)));
5521 Next_Elmt (Elmt);
5522 end loop;
5524 pragma Assert (Ekind (Node (Elmt)) = E_Constant
5525 and then not
5526 Has_Thunks (Node (Next_Elmt (Next_Elmt (Elmt)))));
5528 Sec_DT_Tag :=
5529 New_Occurrence_Of
5530 (Node (Next_Elmt (Next_Elmt (Elmt))), Loc);
5531 end if;
5533 -- For static dispatch tables compute Offset_To_Top using
5534 -- the dummy object.
5536 if Present (Dummy_Object) then
5537 declare
5538 Iface : constant Node_Id := Node (AI);
5539 Iface_Comp : Node_Id := Empty;
5540 Iface_Comp_Elmt : Elmt_Id;
5541 Iface_Elmt : Elmt_Id;
5543 begin
5544 Iface_Elmt := First_Elmt (Ifaces_List);
5545 Iface_Comp_Elmt := First_Elmt (Ifaces_Comp_List);
5547 while Present (Iface_Elmt) loop
5548 if Node (Iface_Elmt) = Iface then
5549 Iface_Comp := Node (Iface_Comp_Elmt);
5550 exit;
5551 end if;
5553 Next_Elmt (Iface_Elmt);
5554 Next_Elmt (Iface_Comp_Elmt);
5555 end loop;
5557 pragma Assert (Present (Iface_Comp));
5559 Offset_To_Top :=
5560 Make_Op_Minus (Loc,
5561 Make_Attribute_Reference (Loc,
5562 Prefix =>
5563 Make_Selected_Component (Loc,
5564 Prefix =>
5565 New_Occurrence_Of (Dummy_Object, Loc),
5566 Selector_Name =>
5567 New_Occurrence_Of (Iface_Comp, Loc)),
5568 Attribute_Name => Name_Position));
5569 end;
5570 else
5571 Offset_To_Top := Make_Integer_Literal (Loc, 0);
5572 end if;
5574 Append_To (TSD_Ifaces_List,
5575 Make_Aggregate (Loc,
5576 Expressions => New_List (
5578 -- Iface_Tag
5580 Unchecked_Convert_To (RTE (RE_Tag),
5581 New_Occurrence_Of
5582 (Node (First_Elmt (Access_Disp_Table (Node (AI)))),
5583 Loc)),
5585 -- Static_Offset_To_Top
5587 New_Occurrence_Of (Standard_True, Loc),
5589 -- Offset_To_Top_Value
5591 Offset_To_Top,
5593 -- Offset_To_Top_Func
5595 Make_Null (Loc),
5597 -- Secondary_DT
5599 Unchecked_Convert_To (RTE (RE_Tag), Sec_DT_Tag))));
5601 Next_Elmt (AI);
5602 end loop;
5604 Name_ITable := New_External_Name (Tname, 'I');
5605 ITable := Make_Defining_Identifier (Loc, Name_ITable);
5606 Set_Is_Statically_Allocated (ITable,
5607 Is_Library_Level_Tagged_Type (Typ));
5609 -- The table of interfaces is constant if we are building a
5610 -- static dispatch table; otherwise is not constant because
5611 -- its slots are filled at run time by the IP routine.
5613 Append_To (Result,
5614 Make_Object_Declaration (Loc,
5615 Defining_Identifier => ITable,
5616 Aliased_Present => True,
5617 Constant_Present => Present (Dummy_Object),
5618 Object_Definition =>
5619 Make_Subtype_Indication (Loc,
5620 Subtype_Mark =>
5621 New_Occurrence_Of (RTE (RE_Interface_Data), Loc),
5622 Constraint =>
5623 Make_Index_Or_Discriminant_Constraint (Loc,
5624 Constraints => New_List (
5625 Make_Integer_Literal (Loc, Num_Ifaces)))),
5627 Expression =>
5628 Make_Aggregate (Loc,
5629 Expressions => New_List (
5630 Make_Integer_Literal (Loc, Num_Ifaces),
5631 Make_Aggregate (Loc, TSD_Ifaces_List)))));
5633 Append_To (Result,
5634 Make_Attribute_Definition_Clause (Loc,
5635 Name => New_Occurrence_Of (ITable, Loc),
5636 Chars => Name_Alignment,
5637 Expression =>
5638 Make_Attribute_Reference (Loc,
5639 Prefix =>
5640 New_Occurrence_Of (RTE (RE_Integer_Address), Loc),
5641 Attribute_Name => Name_Alignment)));
5643 Iface_Table_Node :=
5644 Make_Attribute_Reference (Loc,
5645 Prefix => New_Occurrence_Of (ITable, Loc),
5646 Attribute_Name => Name_Unchecked_Access);
5647 end;
5648 end if;
5650 Append_To (TSD_Aggr_List, Iface_Table_Node);
5651 end if;
5653 -- Generate the Select Specific Data table for synchronized types that
5654 -- implement synchronized interfaces. The size of the table is
5655 -- constrained by the number of non-predefined primitive operations.
5657 if RTE_Record_Component_Available (RE_SSD) then
5658 if Ada_Version >= Ada_2005
5659 and then Has_DT (Typ)
5660 and then Is_Concurrent_Record_Type (Typ)
5661 and then Has_Interfaces (Typ)
5662 and then Nb_Prim > 0
5663 and then not Is_Abstract_Type (Typ)
5664 and then not Is_Controlled (Typ)
5665 and then not Restriction_Active (No_Dispatching_Calls)
5666 and then not Restriction_Active (No_Select_Statements)
5667 then
5668 Append_To (Result,
5669 Make_Object_Declaration (Loc,
5670 Defining_Identifier => SSD,
5671 Aliased_Present => True,
5672 Object_Definition =>
5673 Make_Subtype_Indication (Loc,
5674 Subtype_Mark => New_Occurrence_Of (
5675 RTE (RE_Select_Specific_Data), Loc),
5676 Constraint =>
5677 Make_Index_Or_Discriminant_Constraint (Loc,
5678 Constraints => New_List (
5679 Make_Integer_Literal (Loc, Nb_Prim))))));
5681 Append_To (Result,
5682 Make_Attribute_Definition_Clause (Loc,
5683 Name => New_Occurrence_Of (SSD, Loc),
5684 Chars => Name_Alignment,
5685 Expression =>
5686 Make_Attribute_Reference (Loc,
5687 Prefix =>
5688 New_Occurrence_Of (RTE (RE_Integer_Address), Loc),
5689 Attribute_Name => Name_Alignment)));
5691 -- This table is initialized by Make_Select_Specific_Data_Table,
5692 -- which calls Set_Entry_Index and Set_Prim_Op_Kind.
5694 Append_To (TSD_Aggr_List,
5695 Make_Attribute_Reference (Loc,
5696 Prefix => New_Occurrence_Of (SSD, Loc),
5697 Attribute_Name => Name_Unchecked_Access));
5698 else
5699 Append_To (TSD_Aggr_List, Make_Null (Loc));
5700 end if;
5701 end if;
5703 -- Initialize the table of ancestor tags. In case of interface types
5704 -- this table is not needed.
5706 TSD_Tags_List := New_List;
5708 -- If we are not statically allocating the dispatch table then we must
5709 -- fill position 0 with null because we still have not generated the
5710 -- tag of Typ.
5712 if not Building_Static_DT (Typ)
5713 or else Is_Interface (Typ)
5714 then
5715 Append_To (TSD_Tags_List,
5716 Unchecked_Convert_To (RTE (RE_Tag),
5717 New_Occurrence_Of (RTE (RE_Null_Address), Loc)));
5719 -- Otherwise we can safely reference the tag
5721 else
5722 Append_To (TSD_Tags_List,
5723 New_Occurrence_Of (DT_Ptr, Loc));
5724 end if;
5726 -- Fill the rest of the table with the tags of the ancestors
5728 declare
5729 Current_Typ : Entity_Id;
5730 Parent_Typ : Entity_Id;
5731 Pos : Nat;
5733 begin
5734 Pos := 1;
5735 Current_Typ := Typ;
5737 loop
5738 Parent_Typ := Etype (Current_Typ);
5740 if Is_Private_Type (Parent_Typ) then
5741 Parent_Typ := Full_View (Base_Type (Parent_Typ));
5742 end if;
5744 exit when Parent_Typ = Current_Typ;
5746 if Is_CPP_Class (Parent_Typ) then
5748 -- The tags defined in the C++ side will be inherited when
5749 -- the object is constructed (Exp_Ch3.Build_Init_Procedure)
5751 Append_To (TSD_Tags_List,
5752 Unchecked_Convert_To (RTE (RE_Tag),
5753 New_Occurrence_Of (RTE (RE_Null_Address), Loc)));
5754 else
5755 Append_To (TSD_Tags_List,
5756 New_Occurrence_Of
5757 (Node (First_Elmt (Access_Disp_Table (Parent_Typ))),
5758 Loc));
5759 end if;
5761 Pos := Pos + 1;
5762 Current_Typ := Parent_Typ;
5763 end loop;
5765 pragma Assert (Pos = I_Depth + 1);
5766 end;
5768 Append_To (TSD_Aggr_List,
5769 Make_Aggregate (Loc,
5770 Expressions => TSD_Tags_List));
5772 -- Build the TSD object
5774 Append_To (Result,
5775 Make_Object_Declaration (Loc,
5776 Defining_Identifier => TSD,
5777 Aliased_Present => True,
5778 Constant_Present => Building_Static_DT (Typ),
5779 Object_Definition =>
5780 Make_Subtype_Indication (Loc,
5781 Subtype_Mark => New_Occurrence_Of (
5782 RTE (RE_Type_Specific_Data), Loc),
5783 Constraint =>
5784 Make_Index_Or_Discriminant_Constraint (Loc,
5785 Constraints => New_List (
5786 Make_Integer_Literal (Loc, I_Depth)))),
5788 Expression => Make_Aggregate (Loc,
5789 Expressions => TSD_Aggr_List)));
5791 Set_Is_True_Constant (TSD, Building_Static_DT (Typ));
5793 Append_To (Result,
5794 Make_Attribute_Definition_Clause (Loc,
5795 Name => New_Occurrence_Of (TSD, Loc),
5796 Chars => Name_Alignment,
5797 Expression =>
5798 Make_Attribute_Reference (Loc,
5799 Prefix =>
5800 New_Occurrence_Of (RTE (RE_Integer_Address), Loc),
5801 Attribute_Name => Name_Alignment)));
5803 -- Initialize or declare the dispatch table object
5805 if not Has_DT (Typ) then
5806 DT_Constr_List := New_List;
5807 DT_Aggr_List := New_List;
5809 -- Typeinfo
5811 New_Node :=
5812 Make_Attribute_Reference (Loc,
5813 Prefix => New_Occurrence_Of (TSD, Loc),
5814 Attribute_Name => Name_Address);
5816 Append_To (DT_Constr_List, New_Node);
5817 Append_To (DT_Aggr_List, New_Copy (New_Node));
5818 Append_To (DT_Aggr_List, Make_Integer_Literal (Loc, 0));
5820 -- In case of locally defined tagged types we have already declared
5821 -- and uninitialized object for the dispatch table, which is now
5822 -- initialized by means of the following assignment:
5824 -- DT := (TSD'Address, 0);
5826 if not Building_Static_DT (Typ) then
5827 Append_To (Result,
5828 Make_Assignment_Statement (Loc,
5829 Name => New_Occurrence_Of (DT, Loc),
5830 Expression => Make_Aggregate (Loc, DT_Aggr_List)));
5832 -- In case of library level tagged types we declare and export now
5833 -- the constant object containing the dummy dispatch table. There
5834 -- is no need to declare the tag here because it has been previously
5835 -- declared by Make_Tags
5837 -- DT : aliased constant No_Dispatch_Table :=
5838 -- (NDT_TSD => TSD'Address;
5839 -- NDT_Prims_Ptr => 0);
5840 -- for DT'Alignment use Address'Alignment;
5842 else
5843 Append_To (Result,
5844 Make_Object_Declaration (Loc,
5845 Defining_Identifier => DT,
5846 Aliased_Present => True,
5847 Constant_Present => True,
5848 Object_Definition =>
5849 New_Occurrence_Of (RTE (RE_No_Dispatch_Table_Wrapper), Loc),
5850 Expression => Make_Aggregate (Loc, DT_Aggr_List)));
5852 Append_To (Result,
5853 Make_Attribute_Definition_Clause (Loc,
5854 Name => New_Occurrence_Of (DT, Loc),
5855 Chars => Name_Alignment,
5856 Expression =>
5857 Make_Attribute_Reference (Loc,
5858 Prefix =>
5859 New_Occurrence_Of (RTE (RE_Integer_Address), Loc),
5860 Attribute_Name => Name_Alignment)));
5862 Export_DT (Typ, DT);
5863 end if;
5865 -- Common case: Typ has a dispatch table
5867 -- Generate:
5869 -- Predef_Prims : Address_Array (1 .. Default_Prim_Ops_Count) :=
5870 -- (predef-prim-op-1'address,
5871 -- predef-prim-op-2'address,
5872 -- ...
5873 -- predef-prim-op-n'address);
5874 -- for Predef_Prims'Alignment use Address'Alignment
5876 -- DT : Dispatch_Table (Nb_Prims) :=
5877 -- (Signature => <sig-value>,
5878 -- Tag_Kind => <tag_kind-value>,
5879 -- Predef_Prims => Predef_Prims'First'Address,
5880 -- Offset_To_Top => 0,
5881 -- TSD => TSD'Address;
5882 -- Prims_Ptr => (prim-op-1'address,
5883 -- prim-op-2'address,
5884 -- ...
5885 -- prim-op-n'address));
5886 -- for DT'Alignment use Address'Alignment
5888 else
5889 declare
5890 Pos : Nat;
5892 begin
5893 if not Building_Static_DT (Typ) then
5894 Nb_Predef_Prims := Max_Predef_Prims;
5896 else
5897 Prim_Elmt := First_Elmt (Primitive_Operations (Typ));
5898 while Present (Prim_Elmt) loop
5899 Prim := Node (Prim_Elmt);
5901 if Is_Predefined_Dispatching_Operation (Prim)
5902 and then not Is_Abstract_Subprogram (Prim)
5903 then
5904 Pos := UI_To_Int (DT_Position (Prim));
5906 if Pos > Nb_Predef_Prims then
5907 Nb_Predef_Prims := Pos;
5908 end if;
5909 end if;
5911 Next_Elmt (Prim_Elmt);
5912 end loop;
5913 end if;
5915 declare
5916 Prim_Table : array
5917 (Nat range 1 .. Nb_Predef_Prims) of Entity_Id;
5918 Decl : Node_Id;
5919 E : Entity_Id;
5921 begin
5922 Prim_Ops_Aggr_List := New_List;
5924 Prim_Table := (others => Empty);
5926 if Building_Static_DT (Typ) then
5927 Prim_Elmt := First_Elmt (Primitive_Operations (Typ));
5928 while Present (Prim_Elmt) loop
5929 Prim := Node (Prim_Elmt);
5931 if Is_Predefined_Dispatching_Operation (Prim)
5932 and then not Is_Abstract_Subprogram (Prim)
5933 and then not Is_Eliminated (Prim)
5934 and then not Present (Prim_Table
5935 (UI_To_Int (DT_Position (Prim))))
5936 then
5937 E := Ultimate_Alias (Prim);
5938 pragma Assert (not Is_Abstract_Subprogram (E));
5939 Prim_Table (UI_To_Int (DT_Position (Prim))) := E;
5940 end if;
5942 Next_Elmt (Prim_Elmt);
5943 end loop;
5944 end if;
5946 for J in Prim_Table'Range loop
5947 if Present (Prim_Table (J)) then
5948 New_Node :=
5949 Unchecked_Convert_To (RTE (RE_Prim_Ptr),
5950 Make_Attribute_Reference (Loc,
5951 Prefix =>
5952 New_Occurrence_Of (Prim_Table (J), Loc),
5953 Attribute_Name => Name_Unrestricted_Access));
5954 else
5955 New_Node := Make_Null (Loc);
5956 end if;
5958 Append_To (Prim_Ops_Aggr_List, New_Node);
5959 end loop;
5961 New_Node :=
5962 Make_Aggregate (Loc,
5963 Expressions => Prim_Ops_Aggr_List);
5965 Decl :=
5966 Make_Subtype_Declaration (Loc,
5967 Defining_Identifier => Make_Temporary (Loc, 'S'),
5968 Subtype_Indication =>
5969 New_Occurrence_Of (RTE (RE_Address_Array), Loc));
5971 Append_To (Result, Decl);
5973 Append_To (Result,
5974 Make_Object_Declaration (Loc,
5975 Defining_Identifier => Predef_Prims,
5976 Aliased_Present => True,
5977 Constant_Present => Building_Static_DT (Typ),
5978 Object_Definition =>
5979 New_Occurrence_Of (Defining_Identifier (Decl), Loc),
5980 Expression => New_Node));
5982 -- Remember aggregates initializing dispatch tables
5984 Append_Elmt (New_Node, DT_Aggr);
5986 Append_To (Result,
5987 Make_Attribute_Definition_Clause (Loc,
5988 Name => New_Occurrence_Of (Predef_Prims, Loc),
5989 Chars => Name_Alignment,
5990 Expression =>
5991 Make_Attribute_Reference (Loc,
5992 Prefix =>
5993 New_Occurrence_Of (RTE (RE_Integer_Address), Loc),
5994 Attribute_Name => Name_Alignment)));
5995 end;
5996 end;
5998 -- Stage 1: Initialize the discriminant and the record components
6000 DT_Constr_List := New_List;
6001 DT_Aggr_List := New_List;
6003 -- Num_Prims. If the tagged type has no primitives we add a dummy
6004 -- slot whose address will be the tag of this type.
6006 if Nb_Prim = 0 then
6007 New_Node := Make_Integer_Literal (Loc, 1);
6008 else
6009 New_Node := Make_Integer_Literal (Loc, Nb_Prim);
6010 end if;
6012 Append_To (DT_Constr_List, New_Node);
6013 Append_To (DT_Aggr_List, New_Copy (New_Node));
6015 -- Signature
6017 if RTE_Record_Component_Available (RE_Signature) then
6018 Append_To (DT_Aggr_List,
6019 New_Occurrence_Of (RTE (RE_Primary_DT), Loc));
6020 end if;
6022 -- Tag_Kind
6024 if RTE_Record_Component_Available (RE_Tag_Kind) then
6025 Append_To (DT_Aggr_List, Tagged_Kind (Typ));
6026 end if;
6028 -- Predef_Prims
6030 Append_To (DT_Aggr_List,
6031 Make_Attribute_Reference (Loc,
6032 Prefix => New_Occurrence_Of (Predef_Prims, Loc),
6033 Attribute_Name => Name_Address));
6035 -- Offset_To_Top
6037 Append_To (DT_Aggr_List, Make_Integer_Literal (Loc, 0));
6039 -- Typeinfo
6041 Append_To (DT_Aggr_List,
6042 Make_Attribute_Reference (Loc,
6043 Prefix => New_Occurrence_Of (TSD, Loc),
6044 Attribute_Name => Name_Address));
6046 -- Stage 2: Initialize the table of user-defined primitive operations
6048 Prim_Ops_Aggr_List := New_List;
6050 if Nb_Prim = 0 then
6051 Append_To (Prim_Ops_Aggr_List, Make_Null (Loc));
6053 elsif not Building_Static_DT (Typ) then
6054 for J in 1 .. Nb_Prim loop
6055 Append_To (Prim_Ops_Aggr_List, Make_Null (Loc));
6056 end loop;
6058 else
6059 declare
6060 CPP_Nb_Prims : constant Nat := CPP_Num_Prims (Typ);
6061 E : Entity_Id;
6062 Prim : Entity_Id;
6063 Prim_Elmt : Elmt_Id;
6064 Prim_Pos : Nat;
6065 Prim_Table : array (Nat range 1 .. Nb_Prim) of Entity_Id;
6067 begin
6068 Prim_Table := (others => Empty);
6070 Prim_Elmt := First_Elmt (Primitive_Operations (Typ));
6071 while Present (Prim_Elmt) loop
6072 Prim := Node (Prim_Elmt);
6074 -- Retrieve the ultimate alias of the primitive for proper
6075 -- handling of renamings and eliminated primitives.
6077 E := Ultimate_Alias (Prim);
6079 -- If the alias is not a primitive operation then Prim does
6080 -- not rename another primitive, but rather an operation
6081 -- declared elsewhere (e.g. in another scope) and therefore
6082 -- Prim is a new primitive.
6084 if No (Find_Dispatching_Type (E)) then
6085 E := Prim;
6086 end if;
6088 Prim_Pos := UI_To_Int (DT_Position (E));
6090 -- Skip predefined primitives because they are located in a
6091 -- separate dispatch table.
6093 if not Is_Predefined_Dispatching_Operation (Prim)
6094 and then not Is_Predefined_Dispatching_Operation (E)
6096 -- Skip entities with attribute Interface_Alias because
6097 -- those are only required to build secondary dispatch
6098 -- tables.
6100 and then not Present (Interface_Alias (Prim))
6102 -- Skip abstract and eliminated primitives
6104 and then not Is_Abstract_Subprogram (E)
6105 and then not Is_Eliminated (E)
6107 -- For derivations of CPP types skip primitives located in
6108 -- the C++ part of the dispatch table because their slots
6109 -- are initialized by the IC routine.
6111 and then (not Is_CPP_Class (Root_Type (Typ))
6112 or else Prim_Pos > CPP_Nb_Prims)
6114 -- Skip ignored Ghost subprograms as those will be removed
6115 -- from the executable.
6117 and then not Is_Ignored_Ghost_Entity (E)
6118 then
6119 pragma Assert
6120 (UI_To_Int (DT_Position (Prim)) <= Nb_Prim);
6122 Prim_Table (UI_To_Int (DT_Position (Prim))) := E;
6123 end if;
6125 Next_Elmt (Prim_Elmt);
6126 end loop;
6128 for J in Prim_Table'Range loop
6129 if Present (Prim_Table (J)) then
6130 New_Node :=
6131 Unchecked_Convert_To (RTE (RE_Prim_Ptr),
6132 Make_Attribute_Reference (Loc,
6133 Prefix =>
6134 New_Occurrence_Of (Prim_Table (J), Loc),
6135 Attribute_Name => Name_Unrestricted_Access));
6136 else
6137 New_Node := Make_Null (Loc);
6138 end if;
6140 Append_To (Prim_Ops_Aggr_List, New_Node);
6141 end loop;
6142 end;
6143 end if;
6145 New_Node :=
6146 Make_Aggregate (Loc,
6147 Expressions => Prim_Ops_Aggr_List);
6149 Append_To (DT_Aggr_List, New_Node);
6151 -- Remember aggregates initializing dispatch tables
6153 Append_Elmt (New_Node, DT_Aggr);
6155 -- In case of locally defined tagged types we have already declared
6156 -- and uninitialized object for the dispatch table, which is now
6157 -- initialized by means of an assignment.
6159 if not Building_Static_DT (Typ) then
6160 Append_To (Result,
6161 Make_Assignment_Statement (Loc,
6162 Name => New_Occurrence_Of (DT, Loc),
6163 Expression => Make_Aggregate (Loc, DT_Aggr_List)));
6165 -- In case of library level tagged types we declare now and export
6166 -- the constant object containing the dispatch table.
6168 else
6169 Append_To (Result,
6170 Make_Object_Declaration (Loc,
6171 Defining_Identifier => DT,
6172 Aliased_Present => True,
6173 Constant_Present => True,
6174 Object_Definition =>
6175 Make_Subtype_Indication (Loc,
6176 Subtype_Mark => New_Occurrence_Of
6177 (RTE (RE_Dispatch_Table_Wrapper), Loc),
6178 Constraint => Make_Index_Or_Discriminant_Constraint (Loc,
6179 Constraints => DT_Constr_List)),
6180 Expression => Make_Aggregate (Loc, DT_Aggr_List)));
6182 Append_To (Result,
6183 Make_Attribute_Definition_Clause (Loc,
6184 Name => New_Occurrence_Of (DT, Loc),
6185 Chars => Name_Alignment,
6186 Expression =>
6187 Make_Attribute_Reference (Loc,
6188 Prefix =>
6189 New_Occurrence_Of (RTE (RE_Integer_Address), Loc),
6190 Attribute_Name => Name_Alignment)));
6192 Export_DT (Typ, DT);
6193 end if;
6194 end if;
6196 -- Initialize the table of ancestor tags if not building static
6197 -- dispatch table
6199 if not Building_Static_DT (Typ)
6200 and then not Is_Interface (Typ)
6201 and then not Is_CPP_Class (Typ)
6202 then
6203 Append_To (Result,
6204 Make_Assignment_Statement (Loc,
6205 Name =>
6206 Make_Indexed_Component (Loc,
6207 Prefix =>
6208 Make_Selected_Component (Loc,
6209 Prefix => New_Occurrence_Of (TSD, Loc),
6210 Selector_Name =>
6211 New_Occurrence_Of
6212 (RTE_Record_Component (RE_Tags_Table), Loc)),
6213 Expressions =>
6214 New_List (Make_Integer_Literal (Loc, 0))),
6216 Expression =>
6217 New_Occurrence_Of
6218 (Node (First_Elmt (Access_Disp_Table (Typ))), Loc)));
6219 end if;
6221 -- Inherit the dispatch tables of the parent. There is no need to
6222 -- inherit anything from the parent when building static dispatch tables
6223 -- because the whole dispatch table (including inherited primitives) has
6224 -- been already built.
6226 if Building_Static_DT (Typ) then
6227 null;
6229 -- If the ancestor is a CPP_Class type we inherit the dispatch tables
6230 -- in the init proc, and we don't need to fill them in here.
6232 elsif Is_CPP_Class (Parent_Typ) then
6233 null;
6235 -- Otherwise we fill in the dispatch tables here
6237 else
6238 if Typ /= Parent_Typ
6239 and then not Is_Interface (Typ)
6240 and then not Restriction_Active (No_Dispatching_Calls)
6241 then
6242 -- Inherit the dispatch table
6244 if not Is_Interface (Typ)
6245 and then not Is_Interface (Parent_Typ)
6246 and then not Is_CPP_Class (Parent_Typ)
6247 then
6248 declare
6249 Nb_Prims : constant Int :=
6250 UI_To_Int (DT_Entry_Count
6251 (First_Tag_Component (Parent_Typ)));
6253 begin
6254 Append_To (Elab_Code,
6255 Build_Inherit_Predefined_Prims (Loc,
6256 Old_Tag_Node =>
6257 New_Occurrence_Of
6258 (Node
6259 (Next_Elmt
6260 (First_Elmt
6261 (Access_Disp_Table (Parent_Typ)))), Loc),
6262 New_Tag_Node =>
6263 New_Occurrence_Of
6264 (Node
6265 (Next_Elmt
6266 (First_Elmt
6267 (Access_Disp_Table (Typ)))), Loc)));
6269 if Nb_Prims /= 0 then
6270 Append_To (Elab_Code,
6271 Build_Inherit_Prims (Loc,
6272 Typ => Typ,
6273 Old_Tag_Node =>
6274 New_Occurrence_Of
6275 (Node
6276 (First_Elmt
6277 (Access_Disp_Table (Parent_Typ))), Loc),
6278 New_Tag_Node => New_Occurrence_Of (DT_Ptr, Loc),
6279 Num_Prims => Nb_Prims));
6280 end if;
6281 end;
6282 end if;
6284 -- Inherit the secondary dispatch tables of the ancestor
6286 if not Is_CPP_Class (Parent_Typ) then
6287 declare
6288 Sec_DT_Ancestor : Elmt_Id :=
6289 Next_Elmt
6290 (Next_Elmt
6291 (First_Elmt
6292 (Access_Disp_Table
6293 (Parent_Typ))));
6294 Sec_DT_Typ : Elmt_Id :=
6295 Next_Elmt
6296 (Next_Elmt
6297 (First_Elmt
6298 (Access_Disp_Table (Typ))));
6300 procedure Copy_Secondary_DTs (Typ : Entity_Id);
6301 -- Local procedure required to climb through the ancestors
6302 -- and copy the contents of all their secondary dispatch
6303 -- tables.
6305 ------------------------
6306 -- Copy_Secondary_DTs --
6307 ------------------------
6309 procedure Copy_Secondary_DTs (Typ : Entity_Id) is
6310 E : Entity_Id;
6311 Iface : Elmt_Id;
6313 begin
6314 -- Climb to the ancestor (if any) handling private types
6316 if Present (Full_View (Etype (Typ))) then
6317 if Full_View (Etype (Typ)) /= Typ then
6318 Copy_Secondary_DTs (Full_View (Etype (Typ)));
6319 end if;
6321 elsif Etype (Typ) /= Typ then
6322 Copy_Secondary_DTs (Etype (Typ));
6323 end if;
6325 if Present (Interfaces (Typ))
6326 and then not Is_Empty_Elmt_List (Interfaces (Typ))
6327 then
6328 Iface := First_Elmt (Interfaces (Typ));
6329 E := First_Entity (Typ);
6330 while Present (E)
6331 and then Present (Node (Sec_DT_Ancestor))
6332 and then Ekind (Node (Sec_DT_Ancestor)) = E_Constant
6333 loop
6334 if Is_Tag (E) and then Chars (E) /= Name_uTag then
6335 declare
6336 Num_Prims : constant Int :=
6337 UI_To_Int (DT_Entry_Count (E));
6339 begin
6340 if not Is_Interface (Etype (Typ)) then
6342 -- Inherit first secondary dispatch table
6344 Append_To (Elab_Code,
6345 Build_Inherit_Predefined_Prims (Loc,
6346 Old_Tag_Node =>
6347 Unchecked_Convert_To (RTE (RE_Tag),
6348 New_Occurrence_Of
6349 (Node
6350 (Next_Elmt (Sec_DT_Ancestor)),
6351 Loc)),
6352 New_Tag_Node =>
6353 Unchecked_Convert_To (RTE (RE_Tag),
6354 New_Occurrence_Of
6355 (Node (Next_Elmt (Sec_DT_Typ)),
6356 Loc))));
6358 if Num_Prims /= 0 then
6359 Append_To (Elab_Code,
6360 Build_Inherit_Prims (Loc,
6361 Typ => Node (Iface),
6362 Old_Tag_Node =>
6363 Unchecked_Convert_To
6364 (RTE (RE_Tag),
6365 New_Occurrence_Of
6366 (Node (Sec_DT_Ancestor),
6367 Loc)),
6368 New_Tag_Node =>
6369 Unchecked_Convert_To
6370 (RTE (RE_Tag),
6371 New_Occurrence_Of
6372 (Node (Sec_DT_Typ), Loc)),
6373 Num_Prims => Num_Prims));
6374 end if;
6375 end if;
6377 Next_Elmt (Sec_DT_Ancestor);
6378 Next_Elmt (Sec_DT_Typ);
6380 -- Skip the secondary dispatch table of
6381 -- predefined primitives
6383 Next_Elmt (Sec_DT_Ancestor);
6384 Next_Elmt (Sec_DT_Typ);
6386 if not Is_Interface (Etype (Typ)) then
6388 -- Inherit second secondary dispatch table
6390 Append_To (Elab_Code,
6391 Build_Inherit_Predefined_Prims (Loc,
6392 Old_Tag_Node =>
6393 Unchecked_Convert_To (RTE (RE_Tag),
6394 New_Occurrence_Of
6395 (Node
6396 (Next_Elmt (Sec_DT_Ancestor)),
6397 Loc)),
6398 New_Tag_Node =>
6399 Unchecked_Convert_To (RTE (RE_Tag),
6400 New_Occurrence_Of
6401 (Node (Next_Elmt (Sec_DT_Typ)),
6402 Loc))));
6404 if Num_Prims /= 0 then
6405 Append_To (Elab_Code,
6406 Build_Inherit_Prims (Loc,
6407 Typ => Node (Iface),
6408 Old_Tag_Node =>
6409 Unchecked_Convert_To
6410 (RTE (RE_Tag),
6411 New_Occurrence_Of
6412 (Node (Sec_DT_Ancestor),
6413 Loc)),
6414 New_Tag_Node =>
6415 Unchecked_Convert_To
6416 (RTE (RE_Tag),
6417 New_Occurrence_Of
6418 (Node (Sec_DT_Typ), Loc)),
6419 Num_Prims => Num_Prims));
6420 end if;
6421 end if;
6422 end;
6424 Next_Elmt (Sec_DT_Ancestor);
6425 Next_Elmt (Sec_DT_Typ);
6427 -- Skip the secondary dispatch table of
6428 -- predefined primitives
6430 Next_Elmt (Sec_DT_Ancestor);
6431 Next_Elmt (Sec_DT_Typ);
6433 Next_Elmt (Iface);
6434 end if;
6436 Next_Entity (E);
6437 end loop;
6438 end if;
6439 end Copy_Secondary_DTs;
6441 begin
6442 if Present (Node (Sec_DT_Ancestor))
6443 and then Ekind (Node (Sec_DT_Ancestor)) = E_Constant
6444 then
6445 -- Handle private types
6447 if Present (Full_View (Typ)) then
6448 Copy_Secondary_DTs (Full_View (Typ));
6449 else
6450 Copy_Secondary_DTs (Typ);
6451 end if;
6452 end if;
6453 end;
6454 end if;
6455 end if;
6456 end if;
6458 -- Generate code to check if the external tag of this type is the same
6459 -- as the external tag of some other declaration.
6461 -- Check_TSD (TSD'Unrestricted_Access);
6463 -- This check is a consequence of AI05-0113-1/06, so it officially
6464 -- applies to Ada 2005 (and Ada 2012). It might be argued that it is
6465 -- a desirable check to add in Ada 95 mode, but we hesitate to make
6466 -- this change, as it would be incompatible, and could conceivably
6467 -- cause a problem in existing Ada 95 code.
6469 -- We check for No_Run_Time_Mode here, because we do not want to pick
6470 -- up the RE_Check_TSD entity and call it in No_Run_Time mode.
6472 -- We cannot perform this check if the generation of its expanded name
6473 -- was discarded.
6475 if not No_Run_Time_Mode
6476 and then not Discard_Names
6477 and then Ada_Version >= Ada_2005
6478 and then RTE_Available (RE_Check_TSD)
6479 and then not Duplicated_Tag_Checks_Suppressed (Typ)
6480 then
6481 Append_To (Elab_Code,
6482 Make_Procedure_Call_Statement (Loc,
6483 Name =>
6484 New_Occurrence_Of (RTE (RE_Check_TSD), Loc),
6485 Parameter_Associations => New_List (
6486 Make_Attribute_Reference (Loc,
6487 Prefix => New_Occurrence_Of (TSD, Loc),
6488 Attribute_Name => Name_Unchecked_Access))));
6489 end if;
6491 -- Generate code to register the Tag in the External_Tag hash table for
6492 -- the pure Ada type only.
6494 -- Register_Tag (Dt_Ptr);
6496 -- Skip this action in the following cases:
6497 -- 1) if Register_Tag is not available.
6498 -- 2) in No_Run_Time mode.
6499 -- 3) if Typ is not defined at the library level (this is required
6500 -- to avoid adding concurrency control to the hash table used
6501 -- by the run-time to register the tags).
6503 if not No_Run_Time_Mode
6504 and then Is_Library_Level_Entity (Typ)
6505 and then RTE_Available (RE_Register_Tag)
6506 then
6507 Append_To (Elab_Code,
6508 Make_Procedure_Call_Statement (Loc,
6509 Name =>
6510 New_Occurrence_Of (RTE (RE_Register_Tag), Loc),
6511 Parameter_Associations =>
6512 New_List (New_Occurrence_Of (DT_Ptr, Loc))));
6513 end if;
6515 if not Is_Empty_List (Elab_Code) then
6516 Append_List_To (Result, Elab_Code);
6517 end if;
6519 -- Populate the two auxiliary tables used for dispatching asynchronous,
6520 -- conditional and timed selects for synchronized types that implement
6521 -- a limited interface. Skip this step in Ravenscar profile or when
6522 -- general dispatching is forbidden.
6524 if Ada_Version >= Ada_2005
6525 and then Is_Concurrent_Record_Type (Typ)
6526 and then Has_Interfaces (Typ)
6527 and then not Restriction_Active (No_Dispatching_Calls)
6528 and then not Restriction_Active (No_Select_Statements)
6529 then
6530 Append_List_To (Result,
6531 Make_Select_Specific_Data_Table (Typ));
6532 end if;
6534 -- Remember entities containing dispatch tables
6536 Append_Elmt (Predef_Prims, DT_Decl);
6537 Append_Elmt (DT, DT_Decl);
6539 Analyze_List (Result, Suppress => All_Checks);
6540 Set_Has_Dispatch_Table (Typ);
6542 -- Mark entities containing dispatch tables. Required by the backend to
6543 -- handle them properly.
6545 if Has_DT (Typ) then
6546 declare
6547 Elmt : Elmt_Id;
6549 begin
6550 -- Object declarations
6552 Elmt := First_Elmt (DT_Decl);
6553 while Present (Elmt) loop
6554 Set_Is_Dispatch_Table_Entity (Node (Elmt));
6555 pragma Assert (Ekind (Etype (Node (Elmt))) = E_Array_Subtype
6556 or else Ekind (Etype (Node (Elmt))) = E_Record_Subtype);
6557 Set_Is_Dispatch_Table_Entity (Etype (Node (Elmt)));
6558 Next_Elmt (Elmt);
6559 end loop;
6561 -- Aggregates initializing dispatch tables
6563 Elmt := First_Elmt (DT_Aggr);
6564 while Present (Elmt) loop
6565 Set_Is_Dispatch_Table_Entity (Etype (Node (Elmt)));
6566 Next_Elmt (Elmt);
6567 end loop;
6568 end;
6569 end if;
6571 <<Leave_SCIL>>
6573 -- Register the tagged type in the call graph nodes table
6575 Register_CG_Node (Typ);
6577 <<Leave>>
6578 Restore_Ghost_Region (Saved_GM, Saved_IGR);
6580 return Result;
6581 end Make_DT;
6583 -------------------------------------
6584 -- Make_Select_Specific_Data_Table --
6585 -------------------------------------
6587 function Make_Select_Specific_Data_Table
6588 (Typ : Entity_Id) return List_Id
6590 Assignments : constant List_Id := New_List;
6591 Loc : constant Source_Ptr := Sloc (Typ);
6593 Conc_Typ : Entity_Id;
6594 Decls : List_Id := No_List;
6595 Prim : Entity_Id;
6596 Prim_Als : Entity_Id;
6597 Prim_Elmt : Elmt_Id;
6598 Prim_Pos : Uint;
6599 Nb_Prim : Nat := 0;
6601 type Examined_Array is array (Int range <>) of Boolean;
6603 function Find_Entry_Index (E : Entity_Id) return Uint;
6604 -- Given an entry, find its index in the visible declarations of the
6605 -- corresponding concurrent type of Typ.
6607 ----------------------
6608 -- Find_Entry_Index --
6609 ----------------------
6611 function Find_Entry_Index (E : Entity_Id) return Uint is
6612 Index : Uint := Uint_1;
6613 Subp_Decl : Entity_Id;
6615 begin
6616 if Present (Decls)
6617 and then not Is_Empty_List (Decls)
6618 then
6619 Subp_Decl := First (Decls);
6620 while Present (Subp_Decl) loop
6621 if Nkind (Subp_Decl) = N_Entry_Declaration then
6622 if Defining_Identifier (Subp_Decl) = E then
6623 return Index;
6624 end if;
6626 Index := Index + 1;
6627 end if;
6629 Next (Subp_Decl);
6630 end loop;
6631 end if;
6633 return Uint_0;
6634 end Find_Entry_Index;
6636 -- Local variables
6638 Tag_Node : Node_Id;
6640 -- Start of processing for Make_Select_Specific_Data_Table
6642 begin
6643 pragma Assert (not Restriction_Active (No_Dispatching_Calls));
6645 if Present (Corresponding_Concurrent_Type (Typ)) then
6646 Conc_Typ := Corresponding_Concurrent_Type (Typ);
6648 if Present (Full_View (Conc_Typ)) then
6649 Conc_Typ := Full_View (Conc_Typ);
6650 end if;
6652 if Ekind (Conc_Typ) = E_Protected_Type then
6653 Decls := Visible_Declarations (Protected_Definition (
6654 Parent (Conc_Typ)));
6655 else
6656 pragma Assert (Ekind (Conc_Typ) = E_Task_Type);
6657 Decls := Visible_Declarations (Task_Definition (
6658 Parent (Conc_Typ)));
6659 end if;
6660 end if;
6662 -- Count the non-predefined primitive operations
6664 Prim_Elmt := First_Elmt (Primitive_Operations (Typ));
6665 while Present (Prim_Elmt) loop
6666 Prim := Node (Prim_Elmt);
6668 if not (Is_Predefined_Dispatching_Operation (Prim)
6669 or else Is_Predefined_Dispatching_Alias (Prim))
6670 then
6671 Nb_Prim := Nb_Prim + 1;
6672 end if;
6674 Next_Elmt (Prim_Elmt);
6675 end loop;
6677 declare
6678 Examined : Examined_Array (1 .. Nb_Prim) := (others => False);
6680 begin
6681 Prim_Elmt := First_Elmt (Primitive_Operations (Typ));
6682 while Present (Prim_Elmt) loop
6683 Prim := Node (Prim_Elmt);
6685 -- Look for primitive overriding an abstract interface subprogram
6687 if Present (Interface_Alias (Prim))
6688 and then not
6689 Is_Ancestor
6690 (Find_Dispatching_Type (Interface_Alias (Prim)), Typ,
6691 Use_Full_View => True)
6692 and then not Examined (UI_To_Int (DT_Position (Alias (Prim))))
6693 then
6694 Prim_Pos := DT_Position (Alias (Prim));
6695 pragma Assert (UI_To_Int (Prim_Pos) <= Nb_Prim);
6696 Examined (UI_To_Int (Prim_Pos)) := True;
6698 -- Set the primitive operation kind regardless of subprogram
6699 -- type. Generate:
6700 -- Ada.Tags.Set_Prim_Op_Kind (DT_Ptr, <position>, <kind>);
6702 if Tagged_Type_Expansion then
6703 Tag_Node :=
6704 New_Occurrence_Of
6705 (Node (First_Elmt (Access_Disp_Table (Typ))), Loc);
6707 else
6708 Tag_Node :=
6709 Make_Attribute_Reference (Loc,
6710 Prefix => New_Occurrence_Of (Typ, Loc),
6711 Attribute_Name => Name_Tag);
6712 end if;
6714 Append_To (Assignments,
6715 Make_Procedure_Call_Statement (Loc,
6716 Name => New_Occurrence_Of (RTE (RE_Set_Prim_Op_Kind), Loc),
6717 Parameter_Associations => New_List (
6718 Tag_Node,
6719 Make_Integer_Literal (Loc, Prim_Pos),
6720 Prim_Op_Kind (Alias (Prim), Typ))));
6722 -- Retrieve the root of the alias chain
6724 Prim_Als := Ultimate_Alias (Prim);
6726 -- In the case of an entry wrapper, set the entry index
6728 if Ekind (Prim) = E_Procedure
6729 and then Is_Primitive_Wrapper (Prim_Als)
6730 and then Ekind (Wrapped_Entity (Prim_Als)) = E_Entry
6731 then
6732 -- Generate:
6733 -- Ada.Tags.Set_Entry_Index
6734 -- (DT_Ptr, <position>, <index>);
6736 if Tagged_Type_Expansion then
6737 Tag_Node :=
6738 New_Occurrence_Of
6739 (Node (First_Elmt (Access_Disp_Table (Typ))), Loc);
6740 else
6741 Tag_Node :=
6742 Make_Attribute_Reference (Loc,
6743 Prefix => New_Occurrence_Of (Typ, Loc),
6744 Attribute_Name => Name_Tag);
6745 end if;
6747 Append_To (Assignments,
6748 Make_Procedure_Call_Statement (Loc,
6749 Name =>
6750 New_Occurrence_Of (RTE (RE_Set_Entry_Index), Loc),
6751 Parameter_Associations => New_List (
6752 Tag_Node,
6753 Make_Integer_Literal (Loc, Prim_Pos),
6754 Make_Integer_Literal (Loc,
6755 Find_Entry_Index (Wrapped_Entity (Prim_Als))))));
6756 end if;
6757 end if;
6759 Next_Elmt (Prim_Elmt);
6760 end loop;
6761 end;
6763 return Assignments;
6764 end Make_Select_Specific_Data_Table;
6766 ---------------
6767 -- Make_Tags --
6768 ---------------
6770 function Make_Tags (Typ : Entity_Id) return List_Id is
6771 Loc : constant Source_Ptr := Sloc (Typ);
6772 Result : constant List_Id := New_List;
6774 procedure Import_DT
6775 (Tag_Typ : Entity_Id;
6776 DT : Entity_Id;
6777 Is_Secondary_DT : Boolean);
6778 -- Import the dispatch table DT of tagged type Tag_Typ. Required to
6779 -- generate forward references and statically allocate the table. For
6780 -- primary dispatch tables that require no dispatch table generate:
6782 -- DT : static aliased constant Non_Dispatch_Table_Wrapper;
6783 -- pragma Import (Ada, DT);
6785 -- Otherwise generate:
6787 -- DT : static aliased constant Dispatch_Table_Wrapper (Nb_Prim);
6788 -- pragma Import (Ada, DT);
6790 ---------------
6791 -- Import_DT --
6792 ---------------
6794 procedure Import_DT
6795 (Tag_Typ : Entity_Id;
6796 DT : Entity_Id;
6797 Is_Secondary_DT : Boolean)
6799 DT_Constr_List : List_Id;
6800 Nb_Prim : Nat;
6802 begin
6803 Set_Is_Imported (DT);
6804 Set_Ekind (DT, E_Constant);
6805 Set_Related_Type (DT, Typ);
6807 -- The scope must be set now to call Get_External_Name
6809 Set_Scope (DT, Current_Scope);
6811 Get_External_Name (DT);
6812 Set_Interface_Name (DT,
6813 Make_String_Literal (Loc, Strval => String_From_Name_Buffer));
6815 -- Ensure proper Sprint output of this implicit importation
6817 Set_Is_Internal (DT);
6819 -- Save this entity to allow Make_DT to generate its exportation
6821 Append_Elmt (DT, Dispatch_Table_Wrappers (Typ));
6823 -- No dispatch table required
6825 if not Is_Secondary_DT and then not Has_DT (Tag_Typ) then
6826 Append_To (Result,
6827 Make_Object_Declaration (Loc,
6828 Defining_Identifier => DT,
6829 Aliased_Present => True,
6830 Constant_Present => True,
6831 Object_Definition =>
6832 New_Occurrence_Of
6833 (RTE (RE_No_Dispatch_Table_Wrapper), Loc)));
6835 else
6836 -- Calculate the number of primitives of the dispatch table and
6837 -- the size of the Type_Specific_Data record.
6839 Nb_Prim :=
6840 UI_To_Int (DT_Entry_Count (First_Tag_Component (Tag_Typ)));
6842 -- If the tagged type has no primitives we add a dummy slot whose
6843 -- address will be the tag of this type.
6845 if Nb_Prim = 0 then
6846 DT_Constr_List :=
6847 New_List (Make_Integer_Literal (Loc, 1));
6848 else
6849 DT_Constr_List :=
6850 New_List (Make_Integer_Literal (Loc, Nb_Prim));
6851 end if;
6853 Append_To (Result,
6854 Make_Object_Declaration (Loc,
6855 Defining_Identifier => DT,
6856 Aliased_Present => True,
6857 Constant_Present => True,
6858 Object_Definition =>
6859 Make_Subtype_Indication (Loc,
6860 Subtype_Mark =>
6861 New_Occurrence_Of (RTE (RE_Dispatch_Table_Wrapper), Loc),
6862 Constraint => Make_Index_Or_Discriminant_Constraint (Loc,
6863 Constraints => DT_Constr_List))));
6864 end if;
6865 end Import_DT;
6867 -- Local variables
6869 Tname : constant Name_Id := Chars (Typ);
6870 AI_Tag_Comp : Elmt_Id;
6871 DT : Node_Id := Empty;
6872 DT_Ptr : Node_Id;
6873 Predef_Prims_Ptr : Node_Id;
6874 Iface_DT : Node_Id := Empty;
6875 Iface_DT_Ptr : Node_Id;
6876 New_Node : Node_Id;
6877 Suffix_Index : Int;
6878 Typ_Name : Name_Id;
6879 Typ_Comps : Elist_Id;
6881 -- Start of processing for Make_Tags
6883 begin
6884 pragma Assert (No (Access_Disp_Table (Typ)));
6885 Set_Access_Disp_Table (Typ, New_Elmt_List);
6887 -- If the elaboration of this tagged type needs a boolean flag then
6888 -- define now its entity. It is initialized to True to indicate that
6889 -- elaboration is still pending; set to False by the IP routine.
6891 -- TypFxx : boolean := True;
6893 if Elab_Flag_Needed (Typ) then
6894 Set_Access_Disp_Table_Elab_Flag (Typ,
6895 Make_Defining_Identifier (Loc,
6896 Chars => New_External_Name (Tname, 'F')));
6898 Append_To (Result,
6899 Make_Object_Declaration (Loc,
6900 Defining_Identifier => Access_Disp_Table_Elab_Flag (Typ),
6901 Object_Definition => New_Occurrence_Of (Standard_Boolean, Loc),
6902 Expression => New_Occurrence_Of (Standard_True, Loc)));
6903 end if;
6905 -- 1) Generate the primary tag entities
6907 -- Primary dispatch table containing user-defined primitives
6909 DT_Ptr := Make_Defining_Identifier (Loc, New_External_Name (Tname, 'P'));
6910 Set_Etype (DT_Ptr, RTE (RE_Tag));
6911 Append_Elmt (DT_Ptr, Access_Disp_Table (Typ));
6913 -- Minimum decoration
6915 Set_Ekind (DT_Ptr, E_Variable);
6916 Set_Related_Type (DT_Ptr, Typ);
6918 -- Notify back end that the types are associated with a dispatch table
6920 Set_Is_Dispatch_Table_Entity (RTE (RE_Prim_Ptr));
6921 Set_Is_Dispatch_Table_Entity (RTE (RE_Predef_Prims_Table_Ptr));
6923 -- For CPP types there is no need to build the dispatch tables since
6924 -- they are imported from the C++ side. If the CPP type has an IP then
6925 -- we declare now the variable that will store the copy of the C++ tag.
6926 -- If the CPP type is an interface, we need the variable as well because
6927 -- it becomes the pointer to the corresponding secondary table.
6929 if Is_CPP_Class (Typ) then
6930 if Has_CPP_Constructors (Typ) or else Is_Interface (Typ) then
6931 Append_To (Result,
6932 Make_Object_Declaration (Loc,
6933 Defining_Identifier => DT_Ptr,
6934 Object_Definition => New_Occurrence_Of (RTE (RE_Tag), Loc),
6935 Expression =>
6936 Unchecked_Convert_To (RTE (RE_Tag),
6937 New_Occurrence_Of (RTE (RE_Null_Address), Loc))));
6939 Set_Is_Statically_Allocated (DT_Ptr,
6940 Is_Library_Level_Tagged_Type (Typ));
6941 end if;
6943 -- Ada types
6945 else
6946 -- Primary dispatch table containing predefined primitives
6948 Predef_Prims_Ptr :=
6949 Make_Defining_Identifier (Loc,
6950 Chars => New_External_Name (Tname, 'Y'));
6951 Set_Etype (Predef_Prims_Ptr, RTE (RE_Address));
6952 Append_Elmt (Predef_Prims_Ptr, Access_Disp_Table (Typ));
6954 -- Import the forward declaration of the Dispatch Table wrapper
6955 -- record (Make_DT will take care of exporting it).
6957 if Building_Static_DT (Typ) then
6958 Set_Dispatch_Table_Wrappers (Typ, New_Elmt_List);
6960 DT :=
6961 Make_Defining_Identifier (Loc,
6962 Chars => New_External_Name (Tname, 'T'));
6964 Import_DT (Typ, DT, Is_Secondary_DT => False);
6966 if Has_DT (Typ) then
6967 Append_To (Result,
6968 Make_Object_Declaration (Loc,
6969 Defining_Identifier => DT_Ptr,
6970 Constant_Present => True,
6971 Object_Definition =>
6972 New_Occurrence_Of (RTE (RE_Tag), Loc),
6973 Expression =>
6974 Unchecked_Convert_To (RTE (RE_Tag),
6975 Make_Attribute_Reference (Loc,
6976 Prefix =>
6977 Make_Selected_Component (Loc,
6978 Prefix => New_Occurrence_Of (DT, Loc),
6979 Selector_Name =>
6980 New_Occurrence_Of
6981 (RTE_Record_Component (RE_Prims_Ptr), Loc)),
6982 Attribute_Name => Name_Address))));
6984 -- Generate the SCIL node for the previous object declaration
6985 -- because it has a tag initialization.
6987 if Generate_SCIL then
6988 New_Node :=
6989 Make_SCIL_Dispatch_Table_Tag_Init (Sloc (Last (Result)));
6990 Set_SCIL_Entity (New_Node, Typ);
6991 Set_SCIL_Node (Last (Result), New_Node);
6992 end if;
6994 Append_To (Result,
6995 Make_Object_Declaration (Loc,
6996 Defining_Identifier => Predef_Prims_Ptr,
6997 Constant_Present => True,
6998 Object_Definition =>
6999 New_Occurrence_Of (RTE (RE_Address), Loc),
7000 Expression =>
7001 Make_Attribute_Reference (Loc,
7002 Prefix =>
7003 Make_Selected_Component (Loc,
7004 Prefix => New_Occurrence_Of (DT, Loc),
7005 Selector_Name =>
7006 New_Occurrence_Of
7007 (RTE_Record_Component (RE_Predef_Prims), Loc)),
7008 Attribute_Name => Name_Address)));
7010 -- No dispatch table required
7012 else
7013 Append_To (Result,
7014 Make_Object_Declaration (Loc,
7015 Defining_Identifier => DT_Ptr,
7016 Constant_Present => True,
7017 Object_Definition =>
7018 New_Occurrence_Of (RTE (RE_Tag), Loc),
7019 Expression =>
7020 Unchecked_Convert_To (RTE (RE_Tag),
7021 Make_Attribute_Reference (Loc,
7022 Prefix =>
7023 Make_Selected_Component (Loc,
7024 Prefix => New_Occurrence_Of (DT, Loc),
7025 Selector_Name =>
7026 New_Occurrence_Of
7027 (RTE_Record_Component (RE_NDT_Prims_Ptr),
7028 Loc)),
7029 Attribute_Name => Name_Address))));
7030 end if;
7032 Set_Is_True_Constant (DT_Ptr);
7033 Set_Is_Statically_Allocated (DT_Ptr);
7034 end if;
7035 end if;
7037 -- 2) Generate the secondary tag entities
7039 -- Collect the components associated with secondary dispatch tables
7041 if Has_Interfaces (Typ) then
7042 Collect_Interface_Components (Typ, Typ_Comps);
7044 -- For each interface type we build a unique external name associated
7045 -- with its secondary dispatch table. This name is used to declare an
7046 -- object that references this secondary dispatch table, whose value
7047 -- will be used for the elaboration of Typ objects, and also for the
7048 -- elaboration of objects of types derived from Typ that do not
7049 -- override the primitives of this interface type.
7051 Suffix_Index := 1;
7053 -- Note: The value of Suffix_Index must be in sync with the values of
7054 -- Suffix_Index in secondary dispatch tables generated by Make_DT.
7056 if Is_CPP_Class (Typ) then
7057 AI_Tag_Comp := First_Elmt (Typ_Comps);
7058 while Present (AI_Tag_Comp) loop
7059 Get_Secondary_DT_External_Name
7060 (Typ, Related_Type (Node (AI_Tag_Comp)), Suffix_Index);
7061 Typ_Name := Name_Find;
7063 -- Declare variables to store copy of the C++ secondary tags
7065 Iface_DT_Ptr :=
7066 Make_Defining_Identifier (Loc,
7067 Chars => New_External_Name (Typ_Name, 'P'));
7068 Set_Etype (Iface_DT_Ptr, RTE (RE_Interface_Tag));
7069 Set_Ekind (Iface_DT_Ptr, E_Variable);
7070 Set_Is_Tag (Iface_DT_Ptr);
7072 Set_Has_Thunks (Iface_DT_Ptr);
7073 Set_Related_Type
7074 (Iface_DT_Ptr, Related_Type (Node (AI_Tag_Comp)));
7075 Append_Elmt (Iface_DT_Ptr, Access_Disp_Table (Typ));
7077 Append_To (Result,
7078 Make_Object_Declaration (Loc,
7079 Defining_Identifier => Iface_DT_Ptr,
7080 Object_Definition => New_Occurrence_Of
7081 (RTE (RE_Interface_Tag), Loc),
7082 Expression =>
7083 Unchecked_Convert_To (RTE (RE_Interface_Tag),
7084 New_Occurrence_Of (RTE (RE_Null_Address), Loc))));
7086 Set_Is_Statically_Allocated (Iface_DT_Ptr,
7087 Is_Library_Level_Tagged_Type (Typ));
7089 Next_Elmt (AI_Tag_Comp);
7090 end loop;
7092 -- This is not a CPP_Class type
7094 else
7095 AI_Tag_Comp := First_Elmt (Typ_Comps);
7096 while Present (AI_Tag_Comp) loop
7097 Get_Secondary_DT_External_Name
7098 (Typ, Related_Type (Node (AI_Tag_Comp)), Suffix_Index);
7099 Typ_Name := Name_Find;
7101 if Building_Static_DT (Typ) then
7102 Iface_DT :=
7103 Make_Defining_Identifier (Loc,
7104 Chars => New_External_Name (Typ_Name, 'T'));
7105 Import_DT
7106 (Tag_Typ => Related_Type (Node (AI_Tag_Comp)),
7107 DT => Iface_DT,
7108 Is_Secondary_DT => True);
7109 end if;
7111 -- Secondary dispatch table referencing thunks to user-defined
7112 -- primitives covered by this interface.
7114 Iface_DT_Ptr :=
7115 Make_Defining_Identifier (Loc,
7116 Chars => New_External_Name (Typ_Name, 'P'));
7117 Set_Etype (Iface_DT_Ptr, RTE (RE_Interface_Tag));
7118 Set_Ekind (Iface_DT_Ptr, E_Constant);
7119 Set_Is_Tag (Iface_DT_Ptr);
7120 Set_Has_Thunks (Iface_DT_Ptr);
7121 Set_Is_Statically_Allocated (Iface_DT_Ptr,
7122 Is_Library_Level_Tagged_Type (Typ));
7123 Set_Is_True_Constant (Iface_DT_Ptr);
7124 Set_Related_Type
7125 (Iface_DT_Ptr, Related_Type (Node (AI_Tag_Comp)));
7126 Append_Elmt (Iface_DT_Ptr, Access_Disp_Table (Typ));
7128 if Building_Static_DT (Typ) then
7129 Append_To (Result,
7130 Make_Object_Declaration (Loc,
7131 Defining_Identifier => Iface_DT_Ptr,
7132 Constant_Present => True,
7133 Object_Definition => New_Occurrence_Of
7134 (RTE (RE_Interface_Tag), Loc),
7135 Expression =>
7136 Unchecked_Convert_To (RTE (RE_Interface_Tag),
7137 Make_Attribute_Reference (Loc,
7138 Prefix =>
7139 Make_Selected_Component (Loc,
7140 Prefix =>
7141 New_Occurrence_Of (Iface_DT, Loc),
7142 Selector_Name =>
7143 New_Occurrence_Of
7144 (RTE_Record_Component (RE_Prims_Ptr),
7145 Loc)),
7146 Attribute_Name => Name_Address))));
7147 end if;
7149 -- Secondary dispatch table referencing thunks to predefined
7150 -- primitives.
7152 Iface_DT_Ptr :=
7153 Make_Defining_Identifier (Loc,
7154 Chars => New_External_Name (Typ_Name, 'Y'));
7155 Set_Etype (Iface_DT_Ptr, RTE (RE_Address));
7156 Set_Ekind (Iface_DT_Ptr, E_Constant);
7157 Set_Is_Tag (Iface_DT_Ptr);
7158 Set_Has_Thunks (Iface_DT_Ptr);
7159 Set_Is_Statically_Allocated (Iface_DT_Ptr,
7160 Is_Library_Level_Tagged_Type (Typ));
7161 Set_Is_True_Constant (Iface_DT_Ptr);
7162 Set_Related_Type
7163 (Iface_DT_Ptr, Related_Type (Node (AI_Tag_Comp)));
7164 Append_Elmt (Iface_DT_Ptr, Access_Disp_Table (Typ));
7166 -- Secondary dispatch table referencing user-defined primitives
7167 -- covered by this interface.
7169 Iface_DT_Ptr :=
7170 Make_Defining_Identifier (Loc,
7171 Chars => New_External_Name (Typ_Name, 'D'));
7172 Set_Etype (Iface_DT_Ptr, RTE (RE_Interface_Tag));
7173 Set_Ekind (Iface_DT_Ptr, E_Constant);
7174 Set_Is_Tag (Iface_DT_Ptr);
7175 Set_Is_Statically_Allocated (Iface_DT_Ptr,
7176 Is_Library_Level_Tagged_Type (Typ));
7177 Set_Is_True_Constant (Iface_DT_Ptr);
7178 Set_Related_Type
7179 (Iface_DT_Ptr, Related_Type (Node (AI_Tag_Comp)));
7180 Append_Elmt (Iface_DT_Ptr, Access_Disp_Table (Typ));
7182 -- Secondary dispatch table referencing predefined primitives
7184 Iface_DT_Ptr :=
7185 Make_Defining_Identifier (Loc,
7186 Chars => New_External_Name (Typ_Name, 'Z'));
7187 Set_Etype (Iface_DT_Ptr, RTE (RE_Address));
7188 Set_Ekind (Iface_DT_Ptr, E_Constant);
7189 Set_Is_Tag (Iface_DT_Ptr);
7190 Set_Is_Statically_Allocated (Iface_DT_Ptr,
7191 Is_Library_Level_Tagged_Type (Typ));
7192 Set_Is_True_Constant (Iface_DT_Ptr);
7193 Set_Related_Type
7194 (Iface_DT_Ptr, Related_Type (Node (AI_Tag_Comp)));
7195 Append_Elmt (Iface_DT_Ptr, Access_Disp_Table (Typ));
7197 Next_Elmt (AI_Tag_Comp);
7198 end loop;
7199 end if;
7200 end if;
7202 -- 3) At the end of Access_Disp_Table, if the type has user-defined
7203 -- primitives, we add the entity of an access type declaration that
7204 -- is used by Build_Get_Prim_Op_Address to expand dispatching calls
7205 -- through the primary dispatch table.
7207 if UI_To_Int (DT_Entry_Count (First_Tag_Component (Typ))) = 0 then
7208 Analyze_List (Result);
7210 -- Generate:
7211 -- subtype Typ_DT is Address_Array (1 .. Nb_Prims);
7212 -- type Typ_DT_Acc is access Typ_DT;
7214 else
7215 declare
7216 Name_DT_Prims : constant Name_Id :=
7217 New_External_Name (Tname, 'G');
7218 Name_DT_Prims_Acc : constant Name_Id :=
7219 New_External_Name (Tname, 'H');
7220 DT_Prims : constant Entity_Id :=
7221 Make_Defining_Identifier (Loc,
7222 Name_DT_Prims);
7223 DT_Prims_Acc : constant Entity_Id :=
7224 Make_Defining_Identifier (Loc,
7225 Name_DT_Prims_Acc);
7226 begin
7227 Append_To (Result,
7228 Make_Subtype_Declaration (Loc,
7229 Defining_Identifier => DT_Prims,
7230 Subtype_Indication =>
7231 Make_Subtype_Indication (Loc,
7232 Subtype_Mark =>
7233 New_Occurrence_Of (RTE (RE_Address_Array), Loc),
7234 Constraint =>
7235 Make_Index_Or_Discriminant_Constraint (Loc, New_List (
7236 Make_Range (Loc,
7237 Low_Bound => Make_Integer_Literal (Loc, 1),
7238 High_Bound =>
7239 Make_Integer_Literal (Loc,
7240 DT_Entry_Count
7241 (First_Tag_Component (Typ)))))))));
7243 Append_To (Result,
7244 Make_Full_Type_Declaration (Loc,
7245 Defining_Identifier => DT_Prims_Acc,
7246 Type_Definition =>
7247 Make_Access_To_Object_Definition (Loc,
7248 Subtype_Indication =>
7249 New_Occurrence_Of (DT_Prims, Loc))));
7251 Append_Elmt (DT_Prims_Acc, Access_Disp_Table (Typ));
7253 -- Analyze the resulting list and suppress the generation of the
7254 -- Init_Proc associated with the above array declaration because
7255 -- this type is never used in object declarations. It is only used
7256 -- to simplify the expansion associated with dispatching calls.
7258 Analyze_List (Result);
7259 Set_Suppress_Initialization (Base_Type (DT_Prims));
7261 -- Disable backend optimizations based on assumptions about the
7262 -- aliasing status of objects designated by the access to the
7263 -- dispatch table. Required to handle dispatch tables imported
7264 -- from C++.
7266 Set_No_Strict_Aliasing (Base_Type (DT_Prims_Acc));
7268 -- Add the freezing nodes of these declarations; required to avoid
7269 -- generating these freezing nodes in wrong scopes (for example in
7270 -- the IC routine of a derivation of Typ).
7272 -- What is an "IC routine"? Is "init_proc" meant here???
7274 Append_List_To (Result, Freeze_Entity (DT_Prims, Typ));
7275 Append_List_To (Result, Freeze_Entity (DT_Prims_Acc, Typ));
7277 -- Mark entity of dispatch table. Required by the back end to
7278 -- handle them properly.
7280 Set_Is_Dispatch_Table_Entity (DT_Prims);
7281 end;
7282 end if;
7284 -- Mark entities of dispatch table. Required by the back end to handle
7285 -- them properly.
7287 if Present (DT) then
7288 Set_Is_Dispatch_Table_Entity (DT);
7289 Set_Is_Dispatch_Table_Entity (Etype (DT));
7290 end if;
7292 if Present (Iface_DT) then
7293 Set_Is_Dispatch_Table_Entity (Iface_DT);
7294 Set_Is_Dispatch_Table_Entity (Etype (Iface_DT));
7295 end if;
7297 if Is_CPP_Class (Root_Type (Typ)) then
7298 Set_Ekind (DT_Ptr, E_Variable);
7299 else
7300 Set_Ekind (DT_Ptr, E_Constant);
7301 end if;
7303 Set_Is_Tag (DT_Ptr);
7304 Set_Related_Type (DT_Ptr, Typ);
7306 return Result;
7307 end Make_Tags;
7309 ---------------
7310 -- New_Value --
7311 ---------------
7313 function New_Value (From : Node_Id) return Node_Id is
7314 Res : constant Node_Id := Duplicate_Subexpr (From);
7315 begin
7316 if Is_Access_Type (Etype (From)) then
7317 return Make_Explicit_Dereference (Sloc (From), Prefix => Res);
7318 else
7319 return Res;
7320 end if;
7321 end New_Value;
7323 -----------------------------------
7324 -- Original_View_In_Visible_Part --
7325 -----------------------------------
7327 function Original_View_In_Visible_Part (Typ : Entity_Id) return Boolean is
7328 Scop : constant Entity_Id := Scope (Typ);
7330 begin
7331 -- The scope must be a package
7333 if not Is_Package_Or_Generic_Package (Scop) then
7334 return False;
7335 end if;
7337 -- A type with a private declaration has a private view declared in
7338 -- the visible part.
7340 if Has_Private_Declaration (Typ) then
7341 return True;
7342 end if;
7344 return List_Containing (Parent (Typ)) =
7345 Visible_Declarations (Package_Specification (Scop));
7346 end Original_View_In_Visible_Part;
7348 ------------------
7349 -- Prim_Op_Kind --
7350 ------------------
7352 function Prim_Op_Kind
7353 (Prim : Entity_Id;
7354 Typ : Entity_Id) return Node_Id
7356 Full_Typ : Entity_Id := Typ;
7357 Loc : constant Source_Ptr := Sloc (Prim);
7358 Prim_Op : Entity_Id;
7360 begin
7361 -- Retrieve the original primitive operation
7363 Prim_Op := Ultimate_Alias (Prim);
7365 if Ekind (Typ) = E_Record_Type
7366 and then Present (Corresponding_Concurrent_Type (Typ))
7367 then
7368 Full_Typ := Corresponding_Concurrent_Type (Typ);
7369 end if;
7371 -- When a private tagged type is completed by a concurrent type,
7372 -- retrieve the full view.
7374 if Is_Private_Type (Full_Typ) then
7375 Full_Typ := Full_View (Full_Typ);
7376 end if;
7378 if Ekind (Prim_Op) = E_Function then
7380 -- Protected function
7382 if Ekind (Full_Typ) = E_Protected_Type then
7383 return New_Occurrence_Of (RTE (RE_POK_Protected_Function), Loc);
7385 -- Task function
7387 elsif Ekind (Full_Typ) = E_Task_Type then
7388 return New_Occurrence_Of (RTE (RE_POK_Task_Function), Loc);
7390 -- Regular function
7392 else
7393 return New_Occurrence_Of (RTE (RE_POK_Function), Loc);
7394 end if;
7396 else
7397 pragma Assert (Ekind (Prim_Op) = E_Procedure);
7399 if Ekind (Full_Typ) = E_Protected_Type then
7401 -- Protected entry
7403 if Is_Primitive_Wrapper (Prim_Op)
7404 and then Ekind (Wrapped_Entity (Prim_Op)) = E_Entry
7405 then
7406 return New_Occurrence_Of (RTE (RE_POK_Protected_Entry), Loc);
7408 -- Protected procedure
7410 else
7411 return
7412 New_Occurrence_Of (RTE (RE_POK_Protected_Procedure), Loc);
7413 end if;
7415 elsif Ekind (Full_Typ) = E_Task_Type then
7417 -- Task entry
7419 if Is_Primitive_Wrapper (Prim_Op)
7420 and then Ekind (Wrapped_Entity (Prim_Op)) = E_Entry
7421 then
7422 return New_Occurrence_Of (RTE (RE_POK_Task_Entry), Loc);
7424 -- Task "procedure". These are the internally Expander-generated
7425 -- procedures (task body for instance).
7427 else
7428 return New_Occurrence_Of (RTE (RE_POK_Task_Procedure), Loc);
7429 end if;
7431 -- Regular procedure
7433 else
7434 return New_Occurrence_Of (RTE (RE_POK_Procedure), Loc);
7435 end if;
7436 end if;
7437 end Prim_Op_Kind;
7439 ------------------------
7440 -- Register_Primitive --
7441 ------------------------
7443 function Register_Primitive
7444 (Loc : Source_Ptr;
7445 Prim : Entity_Id) return List_Id
7447 DT_Ptr : Entity_Id;
7448 Iface_Prim : Entity_Id;
7449 Iface_Typ : Entity_Id;
7450 Iface_DT_Ptr : Entity_Id;
7451 Iface_DT_Elmt : Elmt_Id;
7452 L : constant List_Id := New_List;
7453 Pos : Uint;
7454 Tag : Entity_Id;
7455 Tag_Typ : Entity_Id;
7456 Thunk_Id : Entity_Id;
7457 Thunk_Code : Node_Id;
7459 begin
7460 pragma Assert (not Restriction_Active (No_Dispatching_Calls));
7462 -- Do not register in the dispatch table eliminated primitives
7464 if not RTE_Available (RE_Tag)
7465 or else Is_Eliminated (Ultimate_Alias (Prim))
7466 or else Generate_SCIL
7467 then
7468 return L;
7469 end if;
7471 if not Present (Interface_Alias (Prim)) then
7472 Tag_Typ := Scope (DTC_Entity (Prim));
7473 Pos := DT_Position (Prim);
7474 Tag := First_Tag_Component (Tag_Typ);
7476 if Is_Predefined_Dispatching_Operation (Prim)
7477 or else Is_Predefined_Dispatching_Alias (Prim)
7478 then
7479 DT_Ptr :=
7480 Node (Next_Elmt (First_Elmt (Access_Disp_Table (Tag_Typ))));
7482 Append_To (L,
7483 Build_Set_Predefined_Prim_Op_Address (Loc,
7484 Tag_Node => New_Occurrence_Of (DT_Ptr, Loc),
7485 Position => Pos,
7486 Address_Node =>
7487 Unchecked_Convert_To (RTE (RE_Prim_Ptr),
7488 Make_Attribute_Reference (Loc,
7489 Prefix => New_Occurrence_Of (Prim, Loc),
7490 Attribute_Name => Name_Unrestricted_Access))));
7492 -- Register copy of the pointer to the 'size primitive in the TSD
7494 if Chars (Prim) = Name_uSize
7495 and then RTE_Record_Component_Available (RE_Size_Func)
7496 then
7497 DT_Ptr := Node (First_Elmt (Access_Disp_Table (Tag_Typ)));
7498 Append_To (L,
7499 Build_Set_Size_Function (Loc,
7500 Tag_Node => New_Occurrence_Of (DT_Ptr, Loc),
7501 Size_Func => Prim));
7502 end if;
7504 else
7505 pragma Assert (Pos /= Uint_0 and then Pos <= DT_Entry_Count (Tag));
7507 -- Skip registration of primitives located in the C++ part of the
7508 -- dispatch table. Their slot is set by the IC routine.
7510 if not Is_CPP_Class (Root_Type (Tag_Typ))
7511 or else Pos > CPP_Num_Prims (Tag_Typ)
7512 then
7513 DT_Ptr := Node (First_Elmt (Access_Disp_Table (Tag_Typ)));
7514 Append_To (L,
7515 Build_Set_Prim_Op_Address (Loc,
7516 Typ => Tag_Typ,
7517 Tag_Node => New_Occurrence_Of (DT_Ptr, Loc),
7518 Position => Pos,
7519 Address_Node =>
7520 Unchecked_Convert_To (RTE (RE_Prim_Ptr),
7521 Make_Attribute_Reference (Loc,
7522 Prefix => New_Occurrence_Of (Prim, Loc),
7523 Attribute_Name => Name_Unrestricted_Access))));
7524 end if;
7525 end if;
7527 -- Ada 2005 (AI-251): Primitive associated with an interface type
7529 -- Generate the code of the thunk only if the interface type is not an
7530 -- immediate ancestor of Typ; otherwise the dispatch table associated
7531 -- with the interface is the primary dispatch table and we have nothing
7532 -- else to do here.
7534 else
7535 Tag_Typ := Find_Dispatching_Type (Alias (Prim));
7536 Iface_Typ := Find_Dispatching_Type (Interface_Alias (Prim));
7538 pragma Assert (Is_Interface (Iface_Typ));
7540 -- No action needed for interfaces that are ancestors of Typ because
7541 -- their primitives are located in the primary dispatch table.
7543 if Is_Ancestor (Iface_Typ, Tag_Typ, Use_Full_View => True) then
7544 return L;
7546 -- No action needed for primitives located in the C++ part of the
7547 -- dispatch table. Their slot is set by the IC routine.
7549 elsif Is_CPP_Class (Root_Type (Tag_Typ))
7550 and then DT_Position (Alias (Prim)) <= CPP_Num_Prims (Tag_Typ)
7551 and then not Is_Predefined_Dispatching_Operation (Prim)
7552 and then not Is_Predefined_Dispatching_Alias (Prim)
7553 then
7554 return L;
7555 end if;
7557 Expand_Interface_Thunk (Prim, Thunk_Id, Thunk_Code);
7559 if not Is_Ancestor (Iface_Typ, Tag_Typ, Use_Full_View => True)
7560 and then Present (Thunk_Code)
7561 then
7562 -- Generate the code necessary to fill the appropriate entry of
7563 -- the secondary dispatch table of Prim's controlling type with
7564 -- Thunk_Id's address.
7566 Iface_DT_Elmt := Find_Interface_ADT (Tag_Typ, Iface_Typ);
7567 Iface_DT_Ptr := Node (Iface_DT_Elmt);
7568 pragma Assert (Has_Thunks (Iface_DT_Ptr));
7570 Iface_Prim := Interface_Alias (Prim);
7571 Pos := DT_Position (Iface_Prim);
7572 Tag := First_Tag_Component (Iface_Typ);
7574 Prepend_To (L, Thunk_Code);
7576 if Is_Predefined_Dispatching_Operation (Prim)
7577 or else Is_Predefined_Dispatching_Alias (Prim)
7578 then
7579 Append_To (L,
7580 Build_Set_Predefined_Prim_Op_Address (Loc,
7581 Tag_Node =>
7582 New_Occurrence_Of (Node (Next_Elmt (Iface_DT_Elmt)), Loc),
7583 Position => Pos,
7584 Address_Node =>
7585 Unchecked_Convert_To (RTE (RE_Prim_Ptr),
7586 Make_Attribute_Reference (Loc,
7587 Prefix => New_Occurrence_Of (Thunk_Id, Loc),
7588 Attribute_Name => Name_Unrestricted_Access))));
7590 Next_Elmt (Iface_DT_Elmt);
7591 Next_Elmt (Iface_DT_Elmt);
7592 Iface_DT_Ptr := Node (Iface_DT_Elmt);
7593 pragma Assert (not Has_Thunks (Iface_DT_Ptr));
7595 Append_To (L,
7596 Build_Set_Predefined_Prim_Op_Address (Loc,
7597 Tag_Node =>
7598 New_Occurrence_Of (Node (Next_Elmt (Iface_DT_Elmt)), Loc),
7599 Position => Pos,
7600 Address_Node =>
7601 Unchecked_Convert_To (RTE (RE_Prim_Ptr),
7602 Make_Attribute_Reference (Loc,
7603 Prefix =>
7604 New_Occurrence_Of (Alias (Prim), Loc),
7605 Attribute_Name => Name_Unrestricted_Access))));
7607 else
7608 pragma Assert (Pos /= Uint_0
7609 and then Pos <= DT_Entry_Count (Tag));
7611 Append_To (L,
7612 Build_Set_Prim_Op_Address (Loc,
7613 Typ => Iface_Typ,
7614 Tag_Node => New_Occurrence_Of (Iface_DT_Ptr, Loc),
7615 Position => Pos,
7616 Address_Node =>
7617 Unchecked_Convert_To (RTE (RE_Prim_Ptr),
7618 Make_Attribute_Reference (Loc,
7619 Prefix => New_Occurrence_Of (Thunk_Id, Loc),
7620 Attribute_Name => Name_Unrestricted_Access))));
7622 Next_Elmt (Iface_DT_Elmt);
7623 Next_Elmt (Iface_DT_Elmt);
7624 Iface_DT_Ptr := Node (Iface_DT_Elmt);
7625 pragma Assert (not Has_Thunks (Iface_DT_Ptr));
7627 Append_To (L,
7628 Build_Set_Prim_Op_Address (Loc,
7629 Typ => Iface_Typ,
7630 Tag_Node => New_Occurrence_Of (Iface_DT_Ptr, Loc),
7631 Position => Pos,
7632 Address_Node =>
7633 Unchecked_Convert_To (RTE (RE_Prim_Ptr),
7634 Make_Attribute_Reference (Loc,
7635 Prefix =>
7636 New_Occurrence_Of (Alias (Prim), Loc),
7637 Attribute_Name => Name_Unrestricted_Access))));
7639 end if;
7640 end if;
7641 end if;
7643 return L;
7644 end Register_Primitive;
7646 -------------------------
7647 -- Set_All_DT_Position --
7648 -------------------------
7650 procedure Set_All_DT_Position (Typ : Entity_Id) is
7652 function In_Predef_Prims_DT (Prim : Entity_Id) return Boolean;
7653 -- Returns True if Prim is located in the dispatch table of
7654 -- predefined primitives
7656 procedure Validate_Position (Prim : Entity_Id);
7657 -- Check that position assigned to Prim is completely safe (it has not
7658 -- been assigned to a previously defined primitive operation of Typ).
7660 ------------------------
7661 -- In_Predef_Prims_DT --
7662 ------------------------
7664 function In_Predef_Prims_DT (Prim : Entity_Id) return Boolean is
7665 begin
7666 -- Predefined primitives
7668 if Is_Predefined_Dispatching_Operation (Prim) then
7669 return True;
7671 -- Renamings of predefined primitives
7673 elsif Present (Alias (Prim))
7674 and then Is_Predefined_Dispatching_Operation (Ultimate_Alias (Prim))
7675 then
7676 if Chars (Ultimate_Alias (Prim)) /= Name_Op_Eq then
7677 return True;
7679 -- An overriding operation that is a user-defined renaming of
7680 -- predefined equality inherits its slot from the overridden
7681 -- operation. Otherwise it is treated as a predefined op and
7682 -- occupies the same predefined slot as equality. A call to it is
7683 -- transformed into a call to its alias, which is the predefined
7684 -- equality op. A dispatching call thus uses the proper slot if
7685 -- operation is further inherited and called with class-wide
7686 -- arguments.
7688 else
7689 return
7690 not Comes_From_Source (Prim)
7691 or else No (Overridden_Operation (Prim));
7692 end if;
7694 -- User-defined primitives
7696 else
7697 return False;
7698 end if;
7699 end In_Predef_Prims_DT;
7701 -----------------------
7702 -- Validate_Position --
7703 -----------------------
7705 procedure Validate_Position (Prim : Entity_Id) is
7706 Op_Elmt : Elmt_Id;
7707 Op : Entity_Id;
7709 begin
7710 -- Aliased primitives are safe
7712 if Present (Alias (Prim)) then
7713 return;
7714 end if;
7716 Op_Elmt := First_Elmt (Primitive_Operations (Typ));
7717 while Present (Op_Elmt) loop
7718 Op := Node (Op_Elmt);
7720 -- No need to check against itself
7722 if Op = Prim then
7723 null;
7725 -- Primitive operations covering abstract interfaces are
7726 -- allocated later
7728 elsif Present (Interface_Alias (Op)) then
7729 null;
7731 -- Predefined dispatching operations are completely safe. They
7732 -- are allocated at fixed positions in a separate table.
7734 elsif Is_Predefined_Dispatching_Operation (Op)
7735 or else Is_Predefined_Dispatching_Alias (Op)
7736 then
7737 null;
7739 -- Aliased subprograms are safe
7741 elsif Present (Alias (Op)) then
7742 null;
7744 elsif DT_Position (Op) = DT_Position (Prim)
7745 and then not Is_Predefined_Dispatching_Operation (Op)
7746 and then not Is_Predefined_Dispatching_Operation (Prim)
7747 and then not Is_Predefined_Dispatching_Alias (Op)
7748 and then not Is_Predefined_Dispatching_Alias (Prim)
7749 then
7750 -- Handle aliased subprograms
7752 declare
7753 Op_1 : Entity_Id;
7754 Op_2 : Entity_Id;
7756 begin
7757 Op_1 := Op;
7758 loop
7759 if Present (Overridden_Operation (Op_1)) then
7760 Op_1 := Overridden_Operation (Op_1);
7761 elsif Present (Alias (Op_1)) then
7762 Op_1 := Alias (Op_1);
7763 else
7764 exit;
7765 end if;
7766 end loop;
7768 Op_2 := Prim;
7769 loop
7770 if Present (Overridden_Operation (Op_2)) then
7771 Op_2 := Overridden_Operation (Op_2);
7772 elsif Present (Alias (Op_2)) then
7773 Op_2 := Alias (Op_2);
7774 else
7775 exit;
7776 end if;
7777 end loop;
7779 if Op_1 /= Op_2 then
7780 raise Program_Error;
7781 end if;
7782 end;
7783 end if;
7785 Next_Elmt (Op_Elmt);
7786 end loop;
7787 end Validate_Position;
7789 -- Local variables
7791 Parent_Typ : constant Entity_Id := Etype (Typ);
7792 First_Prim : constant Elmt_Id := First_Elmt (Primitive_Operations (Typ));
7793 The_Tag : constant Entity_Id := First_Tag_Component (Typ);
7795 Adjusted : Boolean := False;
7796 Finalized : Boolean := False;
7798 Count_Prim : Nat;
7799 DT_Length : Nat;
7800 Nb_Prim : Nat;
7801 Prim : Entity_Id;
7802 Prim_Elmt : Elmt_Id;
7804 -- Start of processing for Set_All_DT_Position
7806 begin
7807 pragma Assert (Present (First_Tag_Component (Typ)));
7809 -- Set the DT_Position for each primitive operation. Perform some sanity
7810 -- checks to avoid building inconsistent dispatch tables.
7812 -- First stage: Set DTC entity of all the primitive operations. This is
7813 -- required to properly read the DT_Position attribute in latter stages.
7815 Prim_Elmt := First_Prim;
7816 Count_Prim := 0;
7817 while Present (Prim_Elmt) loop
7818 Prim := Node (Prim_Elmt);
7820 -- Predefined primitives have a separate dispatch table
7822 if not In_Predef_Prims_DT (Prim) then
7823 Count_Prim := Count_Prim + 1;
7824 end if;
7826 Set_DTC_Entity_Value (Typ, Prim);
7828 -- Clear any previous value of the DT_Position attribute. In this
7829 -- way we ensure that the final position of all the primitives is
7830 -- established by the following stages of this algorithm.
7832 Set_DT_Position_Value (Prim, No_Uint);
7834 Next_Elmt (Prim_Elmt);
7835 end loop;
7837 declare
7838 Fixed_Prim : array (Int range 0 .. Count_Prim) of Boolean :=
7839 (others => False);
7841 E : Entity_Id;
7843 procedure Handle_Inherited_Private_Subprograms (Typ : Entity_Id);
7844 -- Called if Typ is declared in a nested package or a public child
7845 -- package to handle inherited primitives that were inherited by Typ
7846 -- in the visible part, but whose declaration was deferred because
7847 -- the parent operation was private and not visible at that point.
7849 procedure Set_Fixed_Prim (Pos : Nat);
7850 -- Sets to true an element of the Fixed_Prim table to indicate
7851 -- that this entry of the dispatch table of Typ is occupied.
7853 ------------------------------------------
7854 -- Handle_Inherited_Private_Subprograms --
7855 ------------------------------------------
7857 procedure Handle_Inherited_Private_Subprograms (Typ : Entity_Id) is
7858 Op_List : Elist_Id;
7859 Op_Elmt : Elmt_Id;
7860 Op_Elmt_2 : Elmt_Id;
7861 Prim_Op : Entity_Id;
7862 Parent_Subp : Entity_Id;
7864 begin
7865 Op_List := Primitive_Operations (Typ);
7867 Op_Elmt := First_Elmt (Op_List);
7868 while Present (Op_Elmt) loop
7869 Prim_Op := Node (Op_Elmt);
7871 -- Search primitives that are implicit operations with an
7872 -- internal name whose parent operation has a normal name.
7874 if Present (Alias (Prim_Op))
7875 and then Find_Dispatching_Type (Alias (Prim_Op)) /= Typ
7876 and then not Comes_From_Source (Prim_Op)
7877 and then Is_Internal_Name (Chars (Prim_Op))
7878 and then not Is_Internal_Name (Chars (Alias (Prim_Op)))
7879 then
7880 Parent_Subp := Alias (Prim_Op);
7882 -- Check if the type has an explicit overriding for this
7883 -- primitive.
7885 Op_Elmt_2 := Next_Elmt (Op_Elmt);
7886 while Present (Op_Elmt_2) loop
7887 if Chars (Node (Op_Elmt_2)) = Chars (Parent_Subp)
7888 and then Type_Conformant (Prim_Op, Node (Op_Elmt_2))
7889 then
7890 Set_DT_Position_Value (Prim_Op,
7891 DT_Position (Parent_Subp));
7892 Set_DT_Position_Value (Node (Op_Elmt_2),
7893 DT_Position (Parent_Subp));
7894 Set_Fixed_Prim (UI_To_Int (DT_Position (Prim_Op)));
7896 goto Next_Primitive;
7897 end if;
7899 Next_Elmt (Op_Elmt_2);
7900 end loop;
7901 end if;
7903 <<Next_Primitive>>
7904 Next_Elmt (Op_Elmt);
7905 end loop;
7906 end Handle_Inherited_Private_Subprograms;
7908 --------------------
7909 -- Set_Fixed_Prim --
7910 --------------------
7912 procedure Set_Fixed_Prim (Pos : Nat) is
7913 begin
7914 pragma Assert (Pos <= Count_Prim);
7915 Fixed_Prim (Pos) := True;
7916 exception
7917 when Constraint_Error =>
7918 raise Program_Error;
7919 end Set_Fixed_Prim;
7921 begin
7922 -- In case of nested packages and public child package it may be
7923 -- necessary a special management on inherited subprograms so that
7924 -- the dispatch table is properly filled.
7926 if Ekind (Scope (Scope (Typ))) = E_Package
7927 and then Scope (Scope (Typ)) /= Standard_Standard
7928 and then ((Is_Derived_Type (Typ) and then not Is_Private_Type (Typ))
7929 or else
7930 (Nkind (Parent (Typ)) = N_Private_Extension_Declaration
7931 and then Is_Generic_Type (Typ)))
7932 and then In_Open_Scopes (Scope (Etype (Typ)))
7933 and then Is_Base_Type (Typ)
7934 then
7935 Handle_Inherited_Private_Subprograms (Typ);
7936 end if;
7938 -- Second stage: Register fixed entries
7940 Nb_Prim := 0;
7941 Prim_Elmt := First_Prim;
7942 while Present (Prim_Elmt) loop
7943 Prim := Node (Prim_Elmt);
7945 -- Predefined primitives have a separate table and all its
7946 -- entries are at predefined fixed positions.
7948 if In_Predef_Prims_DT (Prim) then
7949 if Is_Predefined_Dispatching_Operation (Prim) then
7950 Set_DT_Position_Value (Prim,
7951 Default_Prim_Op_Position (Prim));
7953 else pragma Assert (Present (Alias (Prim)));
7954 Set_DT_Position_Value (Prim,
7955 Default_Prim_Op_Position (Ultimate_Alias (Prim)));
7956 end if;
7958 -- Overriding primitives of ancestor abstract interfaces
7960 elsif Present (Interface_Alias (Prim))
7961 and then Is_Ancestor
7962 (Find_Dispatching_Type (Interface_Alias (Prim)), Typ,
7963 Use_Full_View => True)
7964 then
7965 pragma Assert (DT_Position (Prim) = No_Uint
7966 and then Present (DTC_Entity (Interface_Alias (Prim))));
7968 E := Interface_Alias (Prim);
7969 Set_DT_Position_Value (Prim, DT_Position (E));
7971 pragma Assert
7972 (DT_Position (Alias (Prim)) = No_Uint
7973 or else DT_Position (Alias (Prim)) = DT_Position (E));
7974 Set_DT_Position_Value (Alias (Prim), DT_Position (E));
7975 Set_Fixed_Prim (UI_To_Int (DT_Position (Prim)));
7977 -- Overriding primitives must use the same entry as the overridden
7978 -- primitive. Note that the Alias of the operation is set when the
7979 -- operation is declared by a renaming, in which case it is not
7980 -- overriding. If it renames another primitive it will use the
7981 -- same dispatch table slot, but if it renames an operation in a
7982 -- nested package it's a new primitive and will have its own slot.
7984 elsif not Present (Interface_Alias (Prim))
7985 and then Present (Alias (Prim))
7986 and then Chars (Prim) = Chars (Alias (Prim))
7987 and then Nkind (Unit_Declaration_Node (Prim)) /=
7988 N_Subprogram_Renaming_Declaration
7989 then
7990 declare
7991 Par_Type : constant Entity_Id :=
7992 Find_Dispatching_Type (Alias (Prim));
7994 begin
7995 if Present (Par_Type)
7996 and then Par_Type /= Typ
7997 and then Is_Ancestor (Par_Type, Typ, Use_Full_View => True)
7998 and then Present (DTC_Entity (Alias (Prim)))
7999 then
8000 E := Alias (Prim);
8001 Set_DT_Position_Value (Prim, DT_Position (E));
8003 if not Is_Predefined_Dispatching_Alias (E) then
8004 Set_Fixed_Prim (UI_To_Int (DT_Position (E)));
8005 end if;
8006 end if;
8007 end;
8008 end if;
8010 Next_Elmt (Prim_Elmt);
8011 end loop;
8013 -- Third stage: Fix the position of all the new primitives. Entries
8014 -- associated with primitives covering interfaces are handled in a
8015 -- latter round.
8017 Prim_Elmt := First_Prim;
8018 while Present (Prim_Elmt) loop
8019 Prim := Node (Prim_Elmt);
8021 -- Skip primitives previously set entries
8023 if DT_Position (Prim) /= No_Uint then
8024 null;
8026 -- Primitives covering interface primitives are handled later
8028 elsif Present (Interface_Alias (Prim)) then
8029 null;
8031 else
8032 -- Take the next available position in the DT
8034 loop
8035 Nb_Prim := Nb_Prim + 1;
8036 pragma Assert (Nb_Prim <= Count_Prim);
8037 exit when not Fixed_Prim (Nb_Prim);
8038 end loop;
8040 Set_DT_Position_Value (Prim, UI_From_Int (Nb_Prim));
8041 Set_Fixed_Prim (Nb_Prim);
8042 end if;
8044 Next_Elmt (Prim_Elmt);
8045 end loop;
8046 end;
8048 -- Fourth stage: Complete the decoration of primitives covering
8049 -- interfaces (that is, propagate the DT_Position attribute from
8050 -- the aliased primitive)
8052 Prim_Elmt := First_Prim;
8053 while Present (Prim_Elmt) loop
8054 Prim := Node (Prim_Elmt);
8056 if DT_Position (Prim) = No_Uint
8057 and then Present (Interface_Alias (Prim))
8058 then
8059 pragma Assert (Present (Alias (Prim))
8060 and then Find_Dispatching_Type (Alias (Prim)) = Typ);
8062 -- Check if this entry will be placed in the primary DT
8064 if Is_Ancestor
8065 (Find_Dispatching_Type (Interface_Alias (Prim)), Typ,
8066 Use_Full_View => True)
8067 then
8068 pragma Assert (DT_Position (Alias (Prim)) /= No_Uint);
8069 Set_DT_Position_Value (Prim, DT_Position (Alias (Prim)));
8071 -- Otherwise it will be placed in the secondary DT
8073 else
8074 pragma Assert
8075 (DT_Position (Interface_Alias (Prim)) /= No_Uint);
8076 Set_DT_Position_Value (Prim,
8077 DT_Position (Interface_Alias (Prim)));
8078 end if;
8079 end if;
8081 Next_Elmt (Prim_Elmt);
8082 end loop;
8084 -- Generate listing showing the contents of the dispatch tables. This
8085 -- action is done before some further static checks because in case of
8086 -- critical errors caused by a wrong dispatch table we need to see the
8087 -- contents of such table.
8089 if Debug_Flag_ZZ then
8090 Write_DT (Typ);
8091 end if;
8093 -- Final stage: Ensure that the table is correct plus some further
8094 -- verifications concerning the primitives.
8096 Prim_Elmt := First_Prim;
8097 DT_Length := 0;
8098 while Present (Prim_Elmt) loop
8099 Prim := Node (Prim_Elmt);
8101 -- At this point all the primitives MUST have a position in the
8102 -- dispatch table.
8104 if DT_Position (Prim) = No_Uint then
8105 raise Program_Error;
8106 end if;
8108 -- Calculate real size of the dispatch table
8110 if not In_Predef_Prims_DT (Prim)
8111 and then UI_To_Int (DT_Position (Prim)) > DT_Length
8112 then
8113 DT_Length := UI_To_Int (DT_Position (Prim));
8114 end if;
8116 -- Ensure that the assigned position to non-predefined dispatching
8117 -- operations in the dispatch table is correct.
8119 if not Is_Predefined_Dispatching_Operation (Prim)
8120 and then not Is_Predefined_Dispatching_Alias (Prim)
8121 then
8122 Validate_Position (Prim);
8123 end if;
8125 if Chars (Prim) = Name_Finalize then
8126 Finalized := True;
8127 end if;
8129 if Chars (Prim) = Name_Adjust then
8130 Adjusted := True;
8131 end if;
8133 -- An abstract operation cannot be declared in the private part for a
8134 -- visible abstract type, because it can't be overridden outside this
8135 -- package hierarchy. For explicit declarations this is checked at
8136 -- the point of declaration, but for inherited operations it must be
8137 -- done when building the dispatch table.
8139 -- Ada 2005 (AI-251): Primitives associated with interfaces are
8140 -- excluded from this check because interfaces must be visible in
8141 -- the public and private part (RM 7.3 (7.3/2))
8143 -- We disable this check in Relaxed_RM_Semantics mode, to accommodate
8144 -- legacy Ada code.
8146 if not Relaxed_RM_Semantics
8147 and then Is_Abstract_Type (Typ)
8148 and then Is_Abstract_Subprogram (Prim)
8149 and then Present (Alias (Prim))
8150 and then not Is_Interface
8151 (Find_Dispatching_Type (Ultimate_Alias (Prim)))
8152 and then not Present (Interface_Alias (Prim))
8153 and then Is_Derived_Type (Typ)
8154 and then In_Private_Part (Current_Scope)
8155 and then
8156 List_Containing (Parent (Prim)) =
8157 Private_Declarations (Package_Specification (Current_Scope))
8158 and then Original_View_In_Visible_Part (Typ)
8159 then
8160 -- We exclude Input and Output stream operations because
8161 -- Limited_Controlled inherits useless Input and Output stream
8162 -- operations from Root_Controlled, which can never be overridden.
8164 if not Is_TSS (Prim, TSS_Stream_Input)
8165 and then
8166 not Is_TSS (Prim, TSS_Stream_Output)
8167 then
8168 Error_Msg_NE
8169 ("abstract inherited private operation&" &
8170 " must be overridden (RM 3.9.3(10))",
8171 Parent (Typ), Prim);
8172 end if;
8173 end if;
8175 Next_Elmt (Prim_Elmt);
8176 end loop;
8178 -- Additional check
8180 if Is_Controlled (Typ) then
8181 if not Finalized then
8182 Error_Msg_N
8183 ("controlled type has no explicit Finalize method??", Typ);
8185 elsif not Adjusted then
8186 Error_Msg_N
8187 ("controlled type has no explicit Adjust method??", Typ);
8188 end if;
8189 end if;
8191 -- Set the final size of the Dispatch Table
8193 Set_DT_Entry_Count (The_Tag, UI_From_Int (DT_Length));
8195 -- The derived type must have at least as many components as its parent
8196 -- (for root types Etype points to itself and the test cannot fail).
8198 if DT_Entry_Count (The_Tag) <
8199 DT_Entry_Count (First_Tag_Component (Parent_Typ))
8200 then
8201 raise Program_Error;
8202 end if;
8203 end Set_All_DT_Position;
8205 --------------------------
8206 -- Set_CPP_Constructors --
8207 --------------------------
8209 procedure Set_CPP_Constructors (Typ : Entity_Id) is
8211 function Gen_Parameters_Profile (E : Entity_Id) return List_Id;
8212 -- Duplicate the parameters profile of the imported C++ constructor
8213 -- adding the "this" pointer to the object as the additional first
8214 -- parameter under the usual form _Init : in out Typ.
8216 ----------------------------
8217 -- Gen_Parameters_Profile --
8218 ----------------------------
8220 function Gen_Parameters_Profile (E : Entity_Id) return List_Id is
8221 Loc : constant Source_Ptr := Sloc (E);
8222 Parms : List_Id;
8223 P : Node_Id;
8225 begin
8226 Parms :=
8227 New_List (
8228 Make_Parameter_Specification (Loc,
8229 Defining_Identifier =>
8230 Make_Defining_Identifier (Loc, Name_uInit),
8231 In_Present => True,
8232 Out_Present => True,
8233 Parameter_Type => New_Occurrence_Of (Typ, Loc)));
8235 if Present (Parameter_Specifications (Parent (E))) then
8236 P := First (Parameter_Specifications (Parent (E)));
8237 while Present (P) loop
8238 Append_To (Parms,
8239 Make_Parameter_Specification (Loc,
8240 Defining_Identifier =>
8241 Make_Defining_Identifier (Loc,
8242 Chars => Chars (Defining_Identifier (P))),
8243 Parameter_Type => New_Copy_Tree (Parameter_Type (P)),
8244 Expression => New_Copy_Tree (Expression (P))));
8245 Next (P);
8246 end loop;
8247 end if;
8249 return Parms;
8250 end Gen_Parameters_Profile;
8252 -- Local variables
8254 Loc : Source_Ptr;
8255 E : Entity_Id;
8256 Found : Boolean := False;
8257 IP : Entity_Id;
8258 IP_Body : Node_Id;
8259 P : Node_Id;
8260 Parms : List_Id;
8262 Covers_Default_Constructor : Entity_Id := Empty;
8264 -- Start of processing for Set_CPP_Constructor
8266 begin
8267 pragma Assert (Is_CPP_Class (Typ));
8269 -- Look for the constructor entities
8271 E := Next_Entity (Typ);
8272 while Present (E) loop
8273 if Ekind (E) = E_Function
8274 and then Is_Constructor (E)
8275 then
8276 Found := True;
8277 Loc := Sloc (E);
8278 Parms := Gen_Parameters_Profile (E);
8279 IP := Make_Defining_Identifier (Loc, Make_Init_Proc_Name (Typ));
8281 -- Case 1: Constructor of untagged type
8283 -- If the C++ class has no virtual methods then the matching Ada
8284 -- type is an untagged record type. In such case there is no need
8285 -- to generate a wrapper of the C++ constructor because the _tag
8286 -- component is not available.
8288 if not Is_Tagged_Type (Typ) then
8289 Discard_Node
8290 (Make_Subprogram_Declaration (Loc,
8291 Specification =>
8292 Make_Procedure_Specification (Loc,
8293 Defining_Unit_Name => IP,
8294 Parameter_Specifications => Parms)));
8296 Set_Init_Proc (Typ, IP);
8297 Set_Is_Imported (IP);
8298 Set_Is_Constructor (IP);
8299 Set_Interface_Name (IP, Interface_Name (E));
8300 Set_Convention (IP, Convention_CPP);
8301 Set_Is_Public (IP);
8302 Set_Has_Completion (IP);
8304 -- Case 2: Constructor of a tagged type
8306 -- In this case we generate the IP routine as a wrapper of the
8307 -- C++ constructor because IP must also save a copy of the _tag
8308 -- generated in the C++ side. The copy of the _tag is used by
8309 -- Build_CPP_Init_Procedure to elaborate derivations of C++ types.
8311 -- Generate:
8312 -- procedure IP (_init : in out Typ; ...) is
8313 -- procedure ConstructorP (_init : in out Typ; ...);
8314 -- pragma Import (ConstructorP);
8315 -- begin
8316 -- ConstructorP (_init, ...);
8317 -- if Typ._tag = null then
8318 -- Typ._tag := _init._tag;
8319 -- end if;
8320 -- end IP;
8322 else
8323 declare
8324 Body_Stmts : constant List_Id := New_List;
8325 Constructor_Id : Entity_Id;
8326 Constructor_Decl_Node : Node_Id;
8327 Init_Tags_List : List_Id;
8329 begin
8330 Constructor_Id := Make_Temporary (Loc, 'P');
8332 Constructor_Decl_Node :=
8333 Make_Subprogram_Declaration (Loc,
8334 Make_Procedure_Specification (Loc,
8335 Defining_Unit_Name => Constructor_Id,
8336 Parameter_Specifications => Parms));
8338 Set_Is_Imported (Constructor_Id);
8339 Set_Is_Constructor (Constructor_Id);
8340 Set_Interface_Name (Constructor_Id, Interface_Name (E));
8341 Set_Convention (Constructor_Id, Convention_CPP);
8342 Set_Is_Public (Constructor_Id);
8343 Set_Has_Completion (Constructor_Id);
8345 -- Build the init procedure as a wrapper of this constructor
8347 Parms := Gen_Parameters_Profile (E);
8349 -- Invoke the C++ constructor
8351 declare
8352 Actuals : constant List_Id := New_List;
8354 begin
8355 P := First (Parms);
8356 while Present (P) loop
8357 Append_To (Actuals,
8358 New_Occurrence_Of (Defining_Identifier (P), Loc));
8359 Next (P);
8360 end loop;
8362 Append_To (Body_Stmts,
8363 Make_Procedure_Call_Statement (Loc,
8364 Name => New_Occurrence_Of (Constructor_Id, Loc),
8365 Parameter_Associations => Actuals));
8366 end;
8368 -- Initialize copies of C++ primary and secondary tags
8370 Init_Tags_List := New_List;
8372 declare
8373 Tag_Elmt : Elmt_Id;
8374 Tag_Comp : Node_Id;
8376 begin
8377 Tag_Elmt := First_Elmt (Access_Disp_Table (Typ));
8378 Tag_Comp := First_Tag_Component (Typ);
8380 while Present (Tag_Elmt)
8381 and then Is_Tag (Node (Tag_Elmt))
8382 loop
8383 -- Skip the following assertion with primary tags
8384 -- because Related_Type is not set on primary tag
8385 -- components.
8387 pragma Assert
8388 (Tag_Comp = First_Tag_Component (Typ)
8389 or else Related_Type (Node (Tag_Elmt))
8390 = Related_Type (Tag_Comp));
8392 Append_To (Init_Tags_List,
8393 Make_Assignment_Statement (Loc,
8394 Name =>
8395 New_Occurrence_Of (Node (Tag_Elmt), Loc),
8396 Expression =>
8397 Make_Selected_Component (Loc,
8398 Prefix =>
8399 Make_Identifier (Loc, Name_uInit),
8400 Selector_Name =>
8401 New_Occurrence_Of (Tag_Comp, Loc))));
8403 Tag_Comp := Next_Tag_Component (Tag_Comp);
8404 Next_Elmt (Tag_Elmt);
8405 end loop;
8406 end;
8408 Append_To (Body_Stmts,
8409 Make_If_Statement (Loc,
8410 Condition =>
8411 Make_Op_Eq (Loc,
8412 Left_Opnd =>
8413 New_Occurrence_Of
8414 (Node (First_Elmt (Access_Disp_Table (Typ))),
8415 Loc),
8416 Right_Opnd =>
8417 Unchecked_Convert_To (RTE (RE_Tag),
8418 New_Occurrence_Of (RTE (RE_Null_Address), Loc))),
8419 Then_Statements => Init_Tags_List));
8421 IP_Body :=
8422 Make_Subprogram_Body (Loc,
8423 Specification =>
8424 Make_Procedure_Specification (Loc,
8425 Defining_Unit_Name => IP,
8426 Parameter_Specifications => Parms),
8427 Declarations => New_List (Constructor_Decl_Node),
8428 Handled_Statement_Sequence =>
8429 Make_Handled_Sequence_Of_Statements (Loc,
8430 Statements => Body_Stmts,
8431 Exception_Handlers => No_List));
8433 Discard_Node (IP_Body);
8434 Set_Init_Proc (Typ, IP);
8435 end;
8436 end if;
8438 -- If this constructor has parameters and all its parameters have
8439 -- defaults then it covers the default constructor. The semantic
8440 -- analyzer ensures that only one constructor with defaults covers
8441 -- the default constructor.
8443 if Present (Parameter_Specifications (Parent (E)))
8444 and then Needs_No_Actuals (E)
8445 then
8446 Covers_Default_Constructor := IP;
8447 end if;
8448 end if;
8450 Next_Entity (E);
8451 end loop;
8453 -- If there are no constructors, mark the type as abstract since we
8454 -- won't be able to declare objects of that type.
8456 if not Found then
8457 Set_Is_Abstract_Type (Typ);
8458 end if;
8460 -- Handle constructor that has all its parameters with defaults and
8461 -- hence it covers the default constructor. We generate a wrapper IP
8462 -- which calls the covering constructor.
8464 if Present (Covers_Default_Constructor) then
8465 declare
8466 Body_Stmts : List_Id;
8468 begin
8469 Loc := Sloc (Covers_Default_Constructor);
8471 Body_Stmts := New_List (
8472 Make_Procedure_Call_Statement (Loc,
8473 Name =>
8474 New_Occurrence_Of (Covers_Default_Constructor, Loc),
8475 Parameter_Associations => New_List (
8476 Make_Identifier (Loc, Name_uInit))));
8478 IP := Make_Defining_Identifier (Loc, Make_Init_Proc_Name (Typ));
8480 IP_Body :=
8481 Make_Subprogram_Body (Loc,
8482 Specification =>
8483 Make_Procedure_Specification (Loc,
8484 Defining_Unit_Name => IP,
8485 Parameter_Specifications => New_List (
8486 Make_Parameter_Specification (Loc,
8487 Defining_Identifier =>
8488 Make_Defining_Identifier (Loc, Name_uInit),
8489 Parameter_Type => New_Occurrence_Of (Typ, Loc)))),
8491 Declarations => No_List,
8493 Handled_Statement_Sequence =>
8494 Make_Handled_Sequence_Of_Statements (Loc,
8495 Statements => Body_Stmts,
8496 Exception_Handlers => No_List));
8498 Discard_Node (IP_Body);
8499 Set_Init_Proc (Typ, IP);
8500 end;
8501 end if;
8503 -- If the CPP type has constructors then it must import also the default
8504 -- C++ constructor. It is required for default initialization of objects
8505 -- of the type. It is also required to elaborate objects of Ada types
8506 -- that are defined as derivations of this CPP type.
8508 if Has_CPP_Constructors (Typ)
8509 and then No (Init_Proc (Typ))
8510 then
8511 Error_Msg_N ("??default constructor must be imported from C++", Typ);
8512 end if;
8513 end Set_CPP_Constructors;
8515 ---------------------------
8516 -- Set_DT_Position_Value --
8517 ---------------------------
8519 procedure Set_DT_Position_Value (Prim : Entity_Id; Value : Uint) is
8520 begin
8521 Set_DT_Position (Prim, Value);
8523 -- Propagate the value to the wrapped subprogram (if one is present)
8525 if Ekind_In (Prim, E_Function, E_Procedure)
8526 and then Is_Primitive_Wrapper (Prim)
8527 and then Present (Wrapped_Entity (Prim))
8528 and then Is_Dispatching_Operation (Wrapped_Entity (Prim))
8529 then
8530 Set_DT_Position (Wrapped_Entity (Prim), Value);
8531 end if;
8532 end Set_DT_Position_Value;
8534 --------------------------
8535 -- Set_DTC_Entity_Value --
8536 --------------------------
8538 procedure Set_DTC_Entity_Value
8539 (Tagged_Type : Entity_Id;
8540 Prim : Entity_Id)
8542 begin
8543 if Present (Interface_Alias (Prim))
8544 and then Is_Interface
8545 (Find_Dispatching_Type (Interface_Alias (Prim)))
8546 then
8547 Set_DTC_Entity (Prim,
8548 Find_Interface_Tag
8549 (T => Tagged_Type,
8550 Iface => Find_Dispatching_Type (Interface_Alias (Prim))));
8551 else
8552 Set_DTC_Entity (Prim,
8553 First_Tag_Component (Tagged_Type));
8554 end if;
8556 -- Propagate the value to the wrapped subprogram (if one is present)
8558 if Ekind_In (Prim, E_Function, E_Procedure)
8559 and then Is_Primitive_Wrapper (Prim)
8560 and then Present (Wrapped_Entity (Prim))
8561 and then Is_Dispatching_Operation (Wrapped_Entity (Prim))
8562 then
8563 Set_DTC_Entity (Wrapped_Entity (Prim), DTC_Entity (Prim));
8564 end if;
8565 end Set_DTC_Entity_Value;
8567 -----------------
8568 -- Tagged_Kind --
8569 -----------------
8571 function Tagged_Kind (T : Entity_Id) return Node_Id is
8572 Conc_Typ : Entity_Id;
8573 Loc : constant Source_Ptr := Sloc (T);
8575 begin
8576 pragma Assert
8577 (Is_Tagged_Type (T) and then RTE_Available (RE_Tagged_Kind));
8579 -- Abstract kinds
8581 if Is_Abstract_Type (T) then
8582 if Is_Limited_Record (T) then
8583 return New_Occurrence_Of
8584 (RTE (RE_TK_Abstract_Limited_Tagged), Loc);
8585 else
8586 return New_Occurrence_Of
8587 (RTE (RE_TK_Abstract_Tagged), Loc);
8588 end if;
8590 -- Concurrent kinds
8592 elsif Is_Concurrent_Record_Type (T) then
8593 Conc_Typ := Corresponding_Concurrent_Type (T);
8595 if Present (Full_View (Conc_Typ)) then
8596 Conc_Typ := Full_View (Conc_Typ);
8597 end if;
8599 if Ekind (Conc_Typ) = E_Protected_Type then
8600 return New_Occurrence_Of (RTE (RE_TK_Protected), Loc);
8601 else
8602 pragma Assert (Ekind (Conc_Typ) = E_Task_Type);
8603 return New_Occurrence_Of (RTE (RE_TK_Task), Loc);
8604 end if;
8606 -- Regular tagged kinds
8608 else
8609 if Is_Limited_Record (T) then
8610 return New_Occurrence_Of (RTE (RE_TK_Limited_Tagged), Loc);
8611 else
8612 return New_Occurrence_Of (RTE (RE_TK_Tagged), Loc);
8613 end if;
8614 end if;
8615 end Tagged_Kind;
8617 --------------
8618 -- Write_DT --
8619 --------------
8621 procedure Write_DT (Typ : Entity_Id) is
8622 Elmt : Elmt_Id;
8623 Prim : Node_Id;
8625 begin
8626 -- Protect this procedure against wrong usage. Required because it will
8627 -- be used directly from GDB
8629 if not (Typ <= Last_Node_Id)
8630 or else not Is_Tagged_Type (Typ)
8631 then
8632 Write_Str ("wrong usage: Write_DT must be used with tagged types");
8633 Write_Eol;
8634 return;
8635 end if;
8637 Write_Int (Int (Typ));
8638 Write_Str (": ");
8639 Write_Name (Chars (Typ));
8641 if Is_Interface (Typ) then
8642 Write_Str (" is interface");
8643 end if;
8645 Write_Eol;
8647 Elmt := First_Elmt (Primitive_Operations (Typ));
8648 while Present (Elmt) loop
8649 Prim := Node (Elmt);
8650 Write_Str (" - ");
8652 -- Indicate if this primitive will be allocated in the primary
8653 -- dispatch table or in a secondary dispatch table associated
8654 -- with an abstract interface type
8656 if Present (DTC_Entity (Prim)) then
8657 if Etype (DTC_Entity (Prim)) = RTE (RE_Tag) then
8658 Write_Str ("[P] ");
8659 else
8660 Write_Str ("[s] ");
8661 end if;
8662 end if;
8664 -- Output the node of this primitive operation and its name
8666 Write_Int (Int (Prim));
8667 Write_Str (": ");
8669 if Is_Predefined_Dispatching_Operation (Prim) then
8670 Write_Str ("(predefined) ");
8671 end if;
8673 -- Prefix the name of the primitive with its corresponding tagged
8674 -- type to facilitate seeing inherited primitives.
8676 if Present (Alias (Prim)) then
8677 Write_Name
8678 (Chars (Find_Dispatching_Type (Ultimate_Alias (Prim))));
8679 else
8680 Write_Name (Chars (Typ));
8681 end if;
8683 Write_Str (".");
8684 Write_Name (Chars (Prim));
8686 -- Indicate if this primitive has an aliased primitive
8688 if Present (Alias (Prim)) then
8689 Write_Str (" (alias = ");
8690 Write_Int (Int (Alias (Prim)));
8692 -- If the DTC_Entity attribute is already set we can also output
8693 -- the name of the interface covered by this primitive (if any).
8695 if Ekind_In (Alias (Prim), E_Function, E_Procedure)
8696 and then Present (DTC_Entity (Alias (Prim)))
8697 and then Is_Interface (Scope (DTC_Entity (Alias (Prim))))
8698 then
8699 Write_Str (" from interface ");
8700 Write_Name (Chars (Scope (DTC_Entity (Alias (Prim)))));
8701 end if;
8703 if Present (Interface_Alias (Prim)) then
8704 Write_Str (", AI_Alias of ");
8706 if Is_Null_Interface_Primitive (Interface_Alias (Prim)) then
8707 Write_Str ("null primitive ");
8708 end if;
8710 Write_Name
8711 (Chars (Find_Dispatching_Type (Interface_Alias (Prim))));
8712 Write_Char (':');
8713 Write_Int (Int (Interface_Alias (Prim)));
8714 end if;
8716 Write_Str (")");
8717 end if;
8719 -- Display the final position of this primitive in its associated
8720 -- (primary or secondary) dispatch table.
8722 if Present (DTC_Entity (Prim))
8723 and then DT_Position (Prim) /= No_Uint
8724 then
8725 Write_Str (" at #");
8726 Write_Int (UI_To_Int (DT_Position (Prim)));
8727 end if;
8729 if Is_Abstract_Subprogram (Prim) then
8730 Write_Str (" is abstract;");
8732 -- Check if this is a null primitive
8734 elsif Comes_From_Source (Prim)
8735 and then Ekind (Prim) = E_Procedure
8736 and then Null_Present (Parent (Prim))
8737 then
8738 Write_Str (" is null;");
8739 end if;
8741 if Is_Eliminated (Ultimate_Alias (Prim)) then
8742 Write_Str (" (eliminated)");
8743 end if;
8745 if Is_Imported (Prim)
8746 and then Convention (Prim) = Convention_CPP
8747 then
8748 Write_Str (" (C++)");
8749 end if;
8751 Write_Eol;
8753 Next_Elmt (Elmt);
8754 end loop;
8755 end Write_DT;
8757 end Exp_Disp;