Update LOCAL_PATCHES after libsanitizer merge.
[official-gcc.git] / gcc / ada / exp_disp.adb
blob79c08978071b446db09099f693eb13b2dee8e2ea
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 Entity_Id :=
2491 Make_Defining_Identifier (Loc,
2492 Name_uDisp_Asynchronous_Select);
2493 B_Id : constant Entity_Id := Make_Defining_Identifier (Loc, Name_uB);
2494 Params : constant List_Id := New_List;
2496 begin
2497 pragma Assert (not Restriction_Active (No_Dispatching_Calls));
2499 -- T : in out Typ; -- Object parameter
2500 -- S : Integer; -- Primitive operation slot
2501 -- P : Address; -- Wrapped parameters
2502 -- B : out Dummy_Communication_Block; -- Communication block dummy
2503 -- F : out Boolean; -- Status flag
2505 -- The B parameter may be left uninitialized
2506 Set_Warnings_Off (B_Id);
2508 Append_List_To (Params, New_List (
2510 Make_Parameter_Specification (Loc,
2511 Defining_Identifier => Make_Defining_Identifier (Loc, Name_uT),
2512 Parameter_Type => New_Occurrence_Of (Typ, Loc),
2513 In_Present => True,
2514 Out_Present => True),
2516 Make_Parameter_Specification (Loc,
2517 Defining_Identifier => Make_Defining_Identifier (Loc, Name_uS),
2518 Parameter_Type => New_Occurrence_Of (Standard_Integer, Loc)),
2520 Make_Parameter_Specification (Loc,
2521 Defining_Identifier => Make_Defining_Identifier (Loc, Name_uP),
2522 Parameter_Type => New_Occurrence_Of (RTE (RE_Address), Loc)),
2524 Make_Parameter_Specification (Loc,
2525 Defining_Identifier => B_Id,
2526 Parameter_Type =>
2527 New_Occurrence_Of (RTE (RE_Dummy_Communication_Block), Loc),
2528 Out_Present => True),
2530 Make_Parameter_Specification (Loc,
2531 Defining_Identifier => Make_Defining_Identifier (Loc, Name_uF),
2532 Parameter_Type => New_Occurrence_Of (Standard_Boolean, Loc),
2533 Out_Present => True)));
2535 return
2536 Make_Procedure_Specification (Loc,
2537 Defining_Unit_Name => Def_Id,
2538 Parameter_Specifications => Params);
2539 end Make_Disp_Asynchronous_Select_Spec;
2541 ---------------------------------------
2542 -- Make_Disp_Conditional_Select_Body --
2543 ---------------------------------------
2545 -- For interface types, generate:
2547 -- procedure _Disp_Conditional_Select
2548 -- (T : in out <Typ>;
2549 -- S : Integer;
2550 -- P : System.Address;
2551 -- C : out Ada.Tags.Prim_Op_Kind;
2552 -- F : out Boolean)
2553 -- is
2554 -- begin
2555 -- F := False;
2556 -- C := Ada.Tags.POK_Function;
2557 -- end _Disp_Conditional_Select;
2559 -- For protected types, generate:
2561 -- procedure _Disp_Conditional_Select
2562 -- (T : in out <Typ>;
2563 -- S : Integer;
2564 -- P : System.Address;
2565 -- C : out Ada.Tags.Prim_Op_Kind;
2566 -- F : out Boolean)
2567 -- is
2568 -- I : Integer;
2569 -- Bnn : System.Tasking.Protected_Objects.Operations.
2570 -- Communication_Block;
2572 -- begin
2573 -- C := Ada.Tags.Get_Prim_Op_Kind (Ada.Tags.Tag (<Typ>VP, S));
2575 -- if C = Ada.Tags.POK_Procedure
2576 -- or else C = Ada.Tags.POK_Protected_Procedure
2577 -- or else C = Ada.Tags.POK_Task_Procedure
2578 -- then
2579 -- F := True;
2580 -- return;
2581 -- end if;
2583 -- I := Ada.Tags.Get_Entry_Index (Ada.Tags.Tag (<Typ>VP, S));
2584 -- System.Tasking.Protected_Objects.Operations.Protected_Entry_Call
2585 -- (T.object'Access,
2586 -- System.Tasking.Protected_Objects.Protected_Entry_Index (I),
2587 -- P,
2588 -- System.Tasking.Conditional_Call,
2589 -- Bnn);
2590 -- F := not Cancelled (Bnn);
2591 -- end _Disp_Conditional_Select;
2593 -- For task types, generate:
2595 -- procedure _Disp_Conditional_Select
2596 -- (T : in out <Typ>;
2597 -- S : Integer;
2598 -- P : System.Address;
2599 -- C : out Ada.Tags.Prim_Op_Kind;
2600 -- F : out Boolean)
2601 -- is
2602 -- I : Integer;
2604 -- begin
2605 -- I := Ada.Tags.Get_Entry_Index (Ada.Tags.Tag (<Typ>VP, S));
2606 -- System.Tasking.Rendezvous.Task_Entry_Call
2607 -- (T._task_id,
2608 -- System.Tasking.Task_Entry_Index (I),
2609 -- P,
2610 -- System.Tasking.Conditional_Call,
2611 -- F);
2612 -- end _Disp_Conditional_Select;
2614 function Make_Disp_Conditional_Select_Body
2615 (Typ : Entity_Id) return Node_Id
2617 Loc : constant Source_Ptr := Sloc (Typ);
2618 Blk_Nam : Entity_Id;
2619 Conc_Typ : Entity_Id := Empty;
2620 Decls : constant List_Id := New_List;
2621 Obj_Ref : Node_Id;
2622 Stmts : constant List_Id := New_List;
2623 Tag_Node : Node_Id;
2625 begin
2626 pragma Assert (not Restriction_Active (No_Dispatching_Calls));
2628 -- Null body is generated for interface types
2630 if Is_Interface (Typ) then
2631 return
2632 Make_Subprogram_Body (Loc,
2633 Specification =>
2634 Make_Disp_Conditional_Select_Spec (Typ),
2635 Declarations => No_List,
2636 Handled_Statement_Sequence =>
2637 Make_Handled_Sequence_Of_Statements (Loc,
2638 New_List (Make_Assignment_Statement (Loc,
2639 Name => Make_Identifier (Loc, Name_uF),
2640 Expression => New_Occurrence_Of (Standard_False, Loc)))));
2641 end if;
2643 if Is_Concurrent_Record_Type (Typ) then
2644 Conc_Typ := Corresponding_Concurrent_Type (Typ);
2646 -- Generate:
2647 -- I : Integer;
2649 -- where I will be used to capture the entry index of the primitive
2650 -- wrapper at position S.
2652 Append_To (Decls,
2653 Make_Object_Declaration (Loc,
2654 Defining_Identifier => Make_Defining_Identifier (Loc, Name_uI),
2655 Object_Definition =>
2656 New_Occurrence_Of (Standard_Integer, Loc)));
2658 -- Generate:
2659 -- C := Ada.Tags.Get_Prim_Op_Kind (Ada.Tags.Tag! (<type>VP), S);
2661 -- if C = POK_Procedure
2662 -- or else C = POK_Protected_Procedure
2663 -- or else C = POK_Task_Procedure;
2664 -- then
2665 -- F := True;
2666 -- return;
2667 -- end if;
2669 Build_Common_Dispatching_Select_Statements (Typ, Stmts);
2671 -- Generate:
2672 -- Bnn : Communication_Block;
2674 -- where Bnn is the name of the communication block used in the
2675 -- call to Protected_Entry_Call.
2677 Blk_Nam := Make_Temporary (Loc, 'B');
2678 Append_To (Decls,
2679 Make_Object_Declaration (Loc,
2680 Defining_Identifier => Blk_Nam,
2681 Object_Definition =>
2682 New_Occurrence_Of (RTE (RE_Communication_Block), Loc)));
2684 -- Generate:
2685 -- I := Ada.Tags.Get_Entry_Index (Ada.Tags.Tag! (<type>VP), S);
2687 -- I is the entry index and S is the dispatch table slot
2689 if Tagged_Type_Expansion then
2690 Tag_Node :=
2691 Unchecked_Convert_To (RTE (RE_Tag),
2692 New_Occurrence_Of
2693 (Node (First_Elmt (Access_Disp_Table (Typ))), Loc));
2695 else
2696 Tag_Node :=
2697 Make_Attribute_Reference (Loc,
2698 Prefix => New_Occurrence_Of (Typ, Loc),
2699 Attribute_Name => Name_Tag);
2700 end if;
2702 Append_To (Stmts,
2703 Make_Assignment_Statement (Loc,
2704 Name => Make_Identifier (Loc, Name_uI),
2705 Expression =>
2706 Make_Function_Call (Loc,
2707 Name =>
2708 New_Occurrence_Of (RTE (RE_Get_Entry_Index), Loc),
2709 Parameter_Associations => New_List (
2710 Tag_Node,
2711 Make_Identifier (Loc, Name_uS)))));
2713 if Ekind (Conc_Typ) = E_Protected_Type then
2715 Obj_Ref := -- T._object'Access
2716 Make_Attribute_Reference (Loc,
2717 Attribute_Name => Name_Unchecked_Access,
2718 Prefix =>
2719 Make_Selected_Component (Loc,
2720 Prefix => Make_Identifier (Loc, Name_uT),
2721 Selector_Name => Make_Identifier (Loc, Name_uObject)));
2723 case Corresponding_Runtime_Package (Conc_Typ) is
2724 when System_Tasking_Protected_Objects_Entries =>
2725 -- Generate:
2727 -- Protected_Entry_Call
2728 -- (T._object'Access, -- Object
2729 -- Protected_Entry_Index! (I), -- E
2730 -- P, -- Uninterpreted_Data
2731 -- Conditional_Call, -- Mode
2732 -- Bnn); -- Block
2734 -- where T is the protected object, I is the entry index, P
2735 -- are the wrapped parameters and Bnn is the name of the
2736 -- communication block.
2738 Append_To (Stmts,
2739 Make_Procedure_Call_Statement (Loc,
2740 Name =>
2741 New_Occurrence_Of (RTE (RE_Protected_Entry_Call), Loc),
2742 Parameter_Associations => New_List (
2743 Obj_Ref,
2745 Make_Unchecked_Type_Conversion (Loc, -- entry index
2746 Subtype_Mark =>
2747 New_Occurrence_Of
2748 (RTE (RE_Protected_Entry_Index), Loc),
2749 Expression => Make_Identifier (Loc, Name_uI)),
2751 Make_Identifier (Loc, Name_uP), -- parameter block
2753 New_Occurrence_Of -- Conditional_Call
2754 (RTE (RE_Conditional_Call), Loc),
2755 New_Occurrence_Of -- Bnn
2756 (Blk_Nam, Loc))));
2758 when System_Tasking_Protected_Objects_Single_Entry =>
2760 -- If we are compiling for a restricted run-time, the call
2761 -- uses the simpler form.
2763 Append_To (Stmts,
2764 Make_Procedure_Call_Statement (Loc,
2765 Name =>
2766 New_Occurrence_Of
2767 (RTE (RE_Protected_Single_Entry_Call), Loc),
2768 Parameter_Associations => New_List (
2769 Obj_Ref,
2771 Make_Attribute_Reference (Loc,
2772 Prefix => Make_Identifier (Loc, Name_uP),
2773 Attribute_Name => Name_Address),
2775 New_Occurrence_Of
2776 (RTE (RE_Conditional_Call), Loc))));
2777 when others =>
2778 raise Program_Error;
2779 end case;
2781 -- Generate:
2782 -- F := not Cancelled (Bnn);
2784 -- where F is the success flag. The status of Cancelled is negated
2785 -- in order to match the behavior of the version for task types.
2787 Append_To (Stmts,
2788 Make_Assignment_Statement (Loc,
2789 Name => Make_Identifier (Loc, Name_uF),
2790 Expression =>
2791 Make_Op_Not (Loc,
2792 Right_Opnd =>
2793 Make_Function_Call (Loc,
2794 Name =>
2795 New_Occurrence_Of (RTE (RE_Cancelled), Loc),
2796 Parameter_Associations => New_List (
2797 New_Occurrence_Of (Blk_Nam, Loc))))));
2798 else
2799 pragma Assert (Ekind (Conc_Typ) = E_Task_Type);
2801 -- Generate:
2802 -- Task_Entry_Call
2803 -- (T._task_id, -- Acceptor
2804 -- Task_Entry_Index! (I), -- E
2805 -- P, -- Uninterpreted_Data
2806 -- Conditional_Call, -- Mode
2807 -- F); -- Rendezvous_Successful
2809 -- where T is the task object, I is the entry index, P are the
2810 -- wrapped parameters and F is the status flag.
2812 Append_To (Stmts,
2813 Make_Procedure_Call_Statement (Loc,
2814 Name =>
2815 New_Occurrence_Of (RTE (RE_Task_Entry_Call), Loc),
2816 Parameter_Associations => New_List (
2818 Make_Selected_Component (Loc, -- T._task_id
2819 Prefix => Make_Identifier (Loc, Name_uT),
2820 Selector_Name => Make_Identifier (Loc, Name_uTask_Id)),
2822 Make_Unchecked_Type_Conversion (Loc, -- entry index
2823 Subtype_Mark =>
2824 New_Occurrence_Of (RTE (RE_Task_Entry_Index), Loc),
2825 Expression => Make_Identifier (Loc, Name_uI)),
2827 Make_Identifier (Loc, Name_uP), -- parameter block
2828 New_Occurrence_Of -- Conditional_Call
2829 (RTE (RE_Conditional_Call), Loc),
2830 Make_Identifier (Loc, Name_uF)))); -- status flag
2831 end if;
2833 else
2834 -- Initialize out parameters
2836 Append_To (Stmts,
2837 Make_Assignment_Statement (Loc,
2838 Name => Make_Identifier (Loc, Name_uF),
2839 Expression => New_Occurrence_Of (Standard_False, Loc)));
2840 Append_To (Stmts,
2841 Make_Assignment_Statement (Loc,
2842 Name => Make_Identifier (Loc, Name_uC),
2843 Expression => New_Occurrence_Of (RTE (RE_POK_Function), Loc)));
2844 end if;
2846 return
2847 Make_Subprogram_Body (Loc,
2848 Specification =>
2849 Make_Disp_Conditional_Select_Spec (Typ),
2850 Declarations => Decls,
2851 Handled_Statement_Sequence =>
2852 Make_Handled_Sequence_Of_Statements (Loc, Stmts));
2853 end Make_Disp_Conditional_Select_Body;
2855 ---------------------------------------
2856 -- Make_Disp_Conditional_Select_Spec --
2857 ---------------------------------------
2859 function Make_Disp_Conditional_Select_Spec
2860 (Typ : Entity_Id) return Node_Id
2862 Loc : constant Source_Ptr := Sloc (Typ);
2863 Def_Id : constant Node_Id :=
2864 Make_Defining_Identifier (Loc,
2865 Name_uDisp_Conditional_Select);
2866 Params : constant List_Id := New_List;
2868 begin
2869 pragma Assert (not Restriction_Active (No_Dispatching_Calls));
2871 -- T : in out Typ; -- Object parameter
2872 -- S : Integer; -- Primitive operation slot
2873 -- P : Address; -- Wrapped parameters
2874 -- C : out Prim_Op_Kind; -- Call kind
2875 -- F : out Boolean; -- Status flag
2877 Append_List_To (Params, New_List (
2879 Make_Parameter_Specification (Loc,
2880 Defining_Identifier => Make_Defining_Identifier (Loc, Name_uT),
2881 Parameter_Type => New_Occurrence_Of (Typ, Loc),
2882 In_Present => True,
2883 Out_Present => True),
2885 Make_Parameter_Specification (Loc,
2886 Defining_Identifier => Make_Defining_Identifier (Loc, Name_uS),
2887 Parameter_Type => New_Occurrence_Of (Standard_Integer, Loc)),
2889 Make_Parameter_Specification (Loc,
2890 Defining_Identifier => Make_Defining_Identifier (Loc, Name_uP),
2891 Parameter_Type => New_Occurrence_Of (RTE (RE_Address), Loc)),
2893 Make_Parameter_Specification (Loc,
2894 Defining_Identifier => Make_Defining_Identifier (Loc, Name_uC),
2895 Parameter_Type =>
2896 New_Occurrence_Of (RTE (RE_Prim_Op_Kind), Loc),
2897 Out_Present => True),
2899 Make_Parameter_Specification (Loc,
2900 Defining_Identifier => Make_Defining_Identifier (Loc, Name_uF),
2901 Parameter_Type => New_Occurrence_Of (Standard_Boolean, Loc),
2902 Out_Present => True)));
2904 return
2905 Make_Procedure_Specification (Loc,
2906 Defining_Unit_Name => Def_Id,
2907 Parameter_Specifications => Params);
2908 end Make_Disp_Conditional_Select_Spec;
2910 -------------------------------------
2911 -- Make_Disp_Get_Prim_Op_Kind_Body --
2912 -------------------------------------
2914 function Make_Disp_Get_Prim_Op_Kind_Body (Typ : Entity_Id) return Node_Id is
2915 Loc : constant Source_Ptr := Sloc (Typ);
2916 Tag_Node : Node_Id;
2918 begin
2919 pragma Assert (not Restriction_Active (No_Dispatching_Calls));
2921 if Is_Interface (Typ) then
2922 return
2923 Make_Subprogram_Body (Loc,
2924 Specification =>
2925 Make_Disp_Get_Prim_Op_Kind_Spec (Typ),
2926 Declarations => New_List,
2927 Handled_Statement_Sequence =>
2928 Make_Handled_Sequence_Of_Statements (Loc,
2929 New_List (Make_Null_Statement (Loc))));
2930 end if;
2932 -- Generate:
2933 -- C := get_prim_op_kind (tag! (<type>VP), S);
2935 -- where C is the out parameter capturing the call kind and S is the
2936 -- dispatch table slot number.
2938 if Tagged_Type_Expansion then
2939 Tag_Node :=
2940 Unchecked_Convert_To (RTE (RE_Tag),
2941 New_Occurrence_Of
2942 (Node (First_Elmt (Access_Disp_Table (Typ))), Loc));
2944 else
2945 Tag_Node :=
2946 Make_Attribute_Reference (Loc,
2947 Prefix => New_Occurrence_Of (Typ, Loc),
2948 Attribute_Name => Name_Tag);
2949 end if;
2951 return
2952 Make_Subprogram_Body (Loc,
2953 Specification =>
2954 Make_Disp_Get_Prim_Op_Kind_Spec (Typ),
2955 Declarations => New_List,
2956 Handled_Statement_Sequence =>
2957 Make_Handled_Sequence_Of_Statements (Loc,
2958 New_List (
2959 Make_Assignment_Statement (Loc,
2960 Name => Make_Identifier (Loc, Name_uC),
2961 Expression =>
2962 Make_Function_Call (Loc,
2963 Name =>
2964 New_Occurrence_Of (RTE (RE_Get_Prim_Op_Kind), Loc),
2965 Parameter_Associations => New_List (
2966 Tag_Node,
2967 Make_Identifier (Loc, Name_uS)))))));
2968 end Make_Disp_Get_Prim_Op_Kind_Body;
2970 -------------------------------------
2971 -- Make_Disp_Get_Prim_Op_Kind_Spec --
2972 -------------------------------------
2974 function Make_Disp_Get_Prim_Op_Kind_Spec
2975 (Typ : Entity_Id) return Node_Id
2977 Loc : constant Source_Ptr := Sloc (Typ);
2978 Def_Id : constant Node_Id :=
2979 Make_Defining_Identifier (Loc, Name_uDisp_Get_Prim_Op_Kind);
2980 Params : constant List_Id := New_List;
2982 begin
2983 pragma Assert (not Restriction_Active (No_Dispatching_Calls));
2985 -- T : in out Typ; -- Object parameter
2986 -- S : Integer; -- Primitive operation slot
2987 -- C : out Prim_Op_Kind; -- Call kind
2989 Append_List_To (Params, New_List (
2991 Make_Parameter_Specification (Loc,
2992 Defining_Identifier => Make_Defining_Identifier (Loc, Name_uT),
2993 Parameter_Type => New_Occurrence_Of (Typ, Loc),
2994 In_Present => True,
2995 Out_Present => True),
2997 Make_Parameter_Specification (Loc,
2998 Defining_Identifier => Make_Defining_Identifier (Loc, Name_uS),
2999 Parameter_Type => New_Occurrence_Of (Standard_Integer, Loc)),
3001 Make_Parameter_Specification (Loc,
3002 Defining_Identifier => Make_Defining_Identifier (Loc, Name_uC),
3003 Parameter_Type =>
3004 New_Occurrence_Of (RTE (RE_Prim_Op_Kind), Loc),
3005 Out_Present => True)));
3007 return
3008 Make_Procedure_Specification (Loc,
3009 Defining_Unit_Name => Def_Id,
3010 Parameter_Specifications => Params);
3011 end Make_Disp_Get_Prim_Op_Kind_Spec;
3013 --------------------------------
3014 -- Make_Disp_Get_Task_Id_Body --
3015 --------------------------------
3017 function Make_Disp_Get_Task_Id_Body
3018 (Typ : Entity_Id) return Node_Id
3020 Loc : constant Source_Ptr := Sloc (Typ);
3021 Ret : Node_Id;
3023 begin
3024 pragma Assert (not Restriction_Active (No_Dispatching_Calls));
3026 if Is_Concurrent_Record_Type (Typ)
3027 and then Ekind (Corresponding_Concurrent_Type (Typ)) = E_Task_Type
3028 then
3029 -- Generate:
3030 -- return To_Address (_T._task_id);
3032 Ret :=
3033 Make_Simple_Return_Statement (Loc,
3034 Expression =>
3035 Make_Unchecked_Type_Conversion (Loc,
3036 Subtype_Mark => New_Occurrence_Of (RTE (RE_Address), Loc),
3037 Expression =>
3038 Make_Selected_Component (Loc,
3039 Prefix => Make_Identifier (Loc, Name_uT),
3040 Selector_Name => Make_Identifier (Loc, Name_uTask_Id))));
3042 -- A null body is constructed for non-task types
3044 else
3045 -- Generate:
3046 -- return Null_Address;
3048 Ret :=
3049 Make_Simple_Return_Statement (Loc,
3050 Expression => New_Occurrence_Of (RTE (RE_Null_Address), Loc));
3051 end if;
3053 return
3054 Make_Subprogram_Body (Loc,
3055 Specification => Make_Disp_Get_Task_Id_Spec (Typ),
3056 Declarations => New_List,
3057 Handled_Statement_Sequence =>
3058 Make_Handled_Sequence_Of_Statements (Loc, New_List (Ret)));
3059 end Make_Disp_Get_Task_Id_Body;
3061 --------------------------------
3062 -- Make_Disp_Get_Task_Id_Spec --
3063 --------------------------------
3065 function Make_Disp_Get_Task_Id_Spec
3066 (Typ : Entity_Id) return Node_Id
3068 Loc : constant Source_Ptr := Sloc (Typ);
3070 begin
3071 pragma Assert (not Restriction_Active (No_Dispatching_Calls));
3073 return
3074 Make_Function_Specification (Loc,
3075 Defining_Unit_Name =>
3076 Make_Defining_Identifier (Loc, Name_uDisp_Get_Task_Id),
3077 Parameter_Specifications => New_List (
3078 Make_Parameter_Specification (Loc,
3079 Defining_Identifier => Make_Defining_Identifier (Loc, Name_uT),
3080 Parameter_Type => New_Occurrence_Of (Typ, Loc))),
3081 Result_Definition =>
3082 New_Occurrence_Of (RTE (RE_Address), Loc));
3083 end Make_Disp_Get_Task_Id_Spec;
3085 ----------------------------
3086 -- Make_Disp_Requeue_Body --
3087 ----------------------------
3089 function Make_Disp_Requeue_Body
3090 (Typ : Entity_Id) return Node_Id
3092 Loc : constant Source_Ptr := Sloc (Typ);
3093 Conc_Typ : Entity_Id := Empty;
3094 Stmts : constant List_Id := New_List;
3096 begin
3097 pragma Assert (not Restriction_Active (No_Dispatching_Calls));
3099 -- Null body is generated for interface types and non-concurrent
3100 -- tagged types.
3102 if Is_Interface (Typ)
3103 or else not Is_Concurrent_Record_Type (Typ)
3104 then
3105 return
3106 Make_Subprogram_Body (Loc,
3107 Specification => Make_Disp_Requeue_Spec (Typ),
3108 Declarations => No_List,
3109 Handled_Statement_Sequence =>
3110 Make_Handled_Sequence_Of_Statements (Loc,
3111 New_List (Make_Null_Statement (Loc))));
3112 end if;
3114 Conc_Typ := Corresponding_Concurrent_Type (Typ);
3116 if Ekind (Conc_Typ) = E_Protected_Type then
3118 -- Generate statements:
3119 -- if F then
3120 -- System.Tasking.Protected_Objects.Operations.
3121 -- Requeue_Protected_Entry
3122 -- (Protection_Entries_Access (P),
3123 -- O._object'Unchecked_Access,
3124 -- Protected_Entry_Index (I),
3125 -- A);
3126 -- else
3127 -- System.Tasking.Protected_Objects.Operations.
3128 -- Requeue_Task_To_Protected_Entry
3129 -- (O._object'Unchecked_Access,
3130 -- Protected_Entry_Index (I),
3131 -- A);
3132 -- end if;
3134 if Restriction_Active (No_Entry_Queue) then
3135 Append_To (Stmts, Make_Null_Statement (Loc));
3136 else
3137 Append_To (Stmts,
3138 Make_If_Statement (Loc,
3139 Condition => Make_Identifier (Loc, Name_uF),
3141 Then_Statements =>
3142 New_List (
3144 -- Call to Requeue_Protected_Entry
3146 Make_Procedure_Call_Statement (Loc,
3147 Name =>
3148 New_Occurrence_Of
3149 (RTE (RE_Requeue_Protected_Entry), Loc),
3150 Parameter_Associations =>
3151 New_List (
3153 Make_Unchecked_Type_Conversion (Loc, -- PEA (P)
3154 Subtype_Mark =>
3155 New_Occurrence_Of (
3156 RTE (RE_Protection_Entries_Access), Loc),
3157 Expression =>
3158 Make_Identifier (Loc, Name_uP)),
3160 Make_Attribute_Reference (Loc, -- O._object'Acc
3161 Attribute_Name =>
3162 Name_Unchecked_Access,
3163 Prefix =>
3164 Make_Selected_Component (Loc,
3165 Prefix =>
3166 Make_Identifier (Loc, Name_uO),
3167 Selector_Name =>
3168 Make_Identifier (Loc, Name_uObject))),
3170 Make_Unchecked_Type_Conversion (Loc, -- entry index
3171 Subtype_Mark =>
3172 New_Occurrence_Of
3173 (RTE (RE_Protected_Entry_Index), Loc),
3174 Expression => Make_Identifier (Loc, Name_uI)),
3176 Make_Identifier (Loc, Name_uA)))), -- abort status
3178 Else_Statements =>
3179 New_List (
3181 -- Call to Requeue_Task_To_Protected_Entry
3183 Make_Procedure_Call_Statement (Loc,
3184 Name =>
3185 New_Occurrence_Of
3186 (RTE (RE_Requeue_Task_To_Protected_Entry), Loc),
3187 Parameter_Associations =>
3188 New_List (
3190 Make_Attribute_Reference (Loc, -- O._object'Acc
3191 Attribute_Name => Name_Unchecked_Access,
3192 Prefix =>
3193 Make_Selected_Component (Loc,
3194 Prefix =>
3195 Make_Identifier (Loc, Name_uO),
3196 Selector_Name =>
3197 Make_Identifier (Loc, Name_uObject))),
3199 Make_Unchecked_Type_Conversion (Loc, -- entry index
3200 Subtype_Mark =>
3201 New_Occurrence_Of
3202 (RTE (RE_Protected_Entry_Index), Loc),
3203 Expression => Make_Identifier (Loc, Name_uI)),
3205 Make_Identifier (Loc, Name_uA)))))); -- abort status
3206 end if;
3208 else
3209 pragma Assert (Is_Task_Type (Conc_Typ));
3211 -- Generate:
3212 -- if F then
3213 -- System.Tasking.Rendezvous.Requeue_Protected_To_Task_Entry
3214 -- (Protection_Entries_Access (P),
3215 -- O._task_id,
3216 -- Task_Entry_Index (I),
3217 -- A);
3218 -- else
3219 -- System.Tasking.Rendezvous.Requeue_Task_Entry
3220 -- (O._task_id,
3221 -- Task_Entry_Index (I),
3222 -- A);
3223 -- end if;
3225 Append_To (Stmts,
3226 Make_If_Statement (Loc,
3227 Condition => Make_Identifier (Loc, Name_uF),
3229 Then_Statements => New_List (
3231 -- Call to Requeue_Protected_To_Task_Entry
3233 Make_Procedure_Call_Statement (Loc,
3234 Name =>
3235 New_Occurrence_Of
3236 (RTE (RE_Requeue_Protected_To_Task_Entry), Loc),
3238 Parameter_Associations => New_List (
3240 Make_Unchecked_Type_Conversion (Loc, -- PEA (P)
3241 Subtype_Mark =>
3242 New_Occurrence_Of
3243 (RTE (RE_Protection_Entries_Access), Loc),
3244 Expression => Make_Identifier (Loc, Name_uP)),
3246 Make_Selected_Component (Loc, -- O._task_id
3247 Prefix => Make_Identifier (Loc, Name_uO),
3248 Selector_Name => Make_Identifier (Loc, Name_uTask_Id)),
3250 Make_Unchecked_Type_Conversion (Loc, -- entry index
3251 Subtype_Mark =>
3252 New_Occurrence_Of (RTE (RE_Task_Entry_Index), Loc),
3253 Expression => Make_Identifier (Loc, Name_uI)),
3255 Make_Identifier (Loc, Name_uA)))), -- abort status
3257 Else_Statements => New_List (
3259 -- Call to Requeue_Task_Entry
3261 Make_Procedure_Call_Statement (Loc,
3262 Name =>
3263 New_Occurrence_Of (RTE (RE_Requeue_Task_Entry), Loc),
3265 Parameter_Associations => New_List (
3267 Make_Selected_Component (Loc, -- O._task_id
3268 Prefix => Make_Identifier (Loc, Name_uO),
3269 Selector_Name => Make_Identifier (Loc, Name_uTask_Id)),
3271 Make_Unchecked_Type_Conversion (Loc, -- entry index
3272 Subtype_Mark =>
3273 New_Occurrence_Of (RTE (RE_Task_Entry_Index), Loc),
3274 Expression => Make_Identifier (Loc, Name_uI)),
3276 Make_Identifier (Loc, Name_uA)))))); -- abort status
3277 end if;
3279 -- Even though no declarations are needed in both cases, we allocate
3280 -- a list for entities added by Freeze.
3282 return
3283 Make_Subprogram_Body (Loc,
3284 Specification => Make_Disp_Requeue_Spec (Typ),
3285 Declarations => New_List,
3286 Handled_Statement_Sequence =>
3287 Make_Handled_Sequence_Of_Statements (Loc, Stmts));
3288 end Make_Disp_Requeue_Body;
3290 ----------------------------
3291 -- Make_Disp_Requeue_Spec --
3292 ----------------------------
3294 function Make_Disp_Requeue_Spec
3295 (Typ : Entity_Id) return Node_Id
3297 Loc : constant Source_Ptr := Sloc (Typ);
3299 begin
3300 pragma Assert (not Restriction_Active (No_Dispatching_Calls));
3302 -- O : in out Typ; - Object parameter
3303 -- F : Boolean; - Protected (True) / task (False) flag
3304 -- P : Address; - Protection_Entries_Access value
3305 -- I : Entry_Index - Index of entry call
3306 -- A : Boolean - Abort flag
3308 -- Note that the Protection_Entries_Access value is represented as a
3309 -- System.Address in order to avoid dragging in the tasking runtime
3310 -- when compiling sources without tasking constructs.
3312 return
3313 Make_Procedure_Specification (Loc,
3314 Defining_Unit_Name =>
3315 Make_Defining_Identifier (Loc, Name_uDisp_Requeue),
3317 Parameter_Specifications => New_List (
3319 Make_Parameter_Specification (Loc, -- O
3320 Defining_Identifier =>
3321 Make_Defining_Identifier (Loc, Name_uO),
3322 Parameter_Type =>
3323 New_Occurrence_Of (Typ, Loc),
3324 In_Present => True,
3325 Out_Present => True),
3327 Make_Parameter_Specification (Loc, -- F
3328 Defining_Identifier =>
3329 Make_Defining_Identifier (Loc, Name_uF),
3330 Parameter_Type =>
3331 New_Occurrence_Of (Standard_Boolean, Loc)),
3333 Make_Parameter_Specification (Loc, -- P
3334 Defining_Identifier =>
3335 Make_Defining_Identifier (Loc, Name_uP),
3336 Parameter_Type =>
3337 New_Occurrence_Of (RTE (RE_Address), Loc)),
3339 Make_Parameter_Specification (Loc, -- I
3340 Defining_Identifier =>
3341 Make_Defining_Identifier (Loc, Name_uI),
3342 Parameter_Type =>
3343 New_Occurrence_Of (Standard_Integer, Loc)),
3345 Make_Parameter_Specification (Loc, -- A
3346 Defining_Identifier =>
3347 Make_Defining_Identifier (Loc, Name_uA),
3348 Parameter_Type =>
3349 New_Occurrence_Of (Standard_Boolean, Loc))));
3350 end Make_Disp_Requeue_Spec;
3352 ---------------------------------
3353 -- Make_Disp_Timed_Select_Body --
3354 ---------------------------------
3356 -- For interface types, generate:
3358 -- procedure _Disp_Timed_Select
3359 -- (T : in out <Typ>;
3360 -- S : Integer;
3361 -- P : System.Address;
3362 -- D : Duration;
3363 -- M : Integer;
3364 -- C : out Ada.Tags.Prim_Op_Kind;
3365 -- F : out Boolean)
3366 -- is
3367 -- begin
3368 -- F := False;
3369 -- C := Ada.Tags.POK_Function;
3370 -- end _Disp_Timed_Select;
3372 -- For protected types, generate:
3374 -- procedure _Disp_Timed_Select
3375 -- (T : in out <Typ>;
3376 -- S : Integer;
3377 -- P : System.Address;
3378 -- D : Duration;
3379 -- M : Integer;
3380 -- C : out Ada.Tags.Prim_Op_Kind;
3381 -- F : out Boolean)
3382 -- is
3383 -- I : Integer;
3385 -- begin
3386 -- C := Ada.Tags.Get_Prim_Op_Kind (Ada.Tags.Tag (<Typ>VP), S);
3388 -- if C = Ada.Tags.POK_Procedure
3389 -- or else C = Ada.Tags.POK_Protected_Procedure
3390 -- or else C = Ada.Tags.POK_Task_Procedure
3391 -- then
3392 -- F := True;
3393 -- return;
3394 -- end if;
3396 -- I := Ada.Tags.Get_Entry_Index (Ada.Tags.Tag (<Typ>VP), S);
3397 -- System.Tasking.Protected_Objects.Operations.
3398 -- Timed_Protected_Entry_Call
3399 -- (T._object'Access,
3400 -- System.Tasking.Protected_Objects.Protected_Entry_Index (I),
3401 -- P,
3402 -- D,
3403 -- M,
3404 -- F);
3405 -- end _Disp_Timed_Select;
3407 -- For task types, generate:
3409 -- procedure _Disp_Timed_Select
3410 -- (T : in out <Typ>;
3411 -- S : Integer;
3412 -- P : System.Address;
3413 -- D : Duration;
3414 -- M : Integer;
3415 -- C : out Ada.Tags.Prim_Op_Kind;
3416 -- F : out Boolean)
3417 -- is
3418 -- I : Integer;
3420 -- begin
3421 -- I := Ada.Tags.Get_Entry_Index (Ada.Tags.Tag (<Typ>VP), S);
3422 -- System.Tasking.Rendezvous.Timed_Task_Entry_Call
3423 -- (T._task_id,
3424 -- System.Tasking.Task_Entry_Index (I),
3425 -- P,
3426 -- D,
3427 -- M,
3428 -- F);
3429 -- end _Disp_Time_Select;
3431 function Make_Disp_Timed_Select_Body
3432 (Typ : Entity_Id) return Node_Id
3434 Loc : constant Source_Ptr := Sloc (Typ);
3435 Conc_Typ : Entity_Id := Empty;
3436 Decls : constant List_Id := New_List;
3437 Obj_Ref : Node_Id;
3438 Stmts : constant List_Id := New_List;
3439 Tag_Node : Node_Id;
3441 begin
3442 pragma Assert (not Restriction_Active (No_Dispatching_Calls));
3444 -- Null body is generated for interface types
3446 if Is_Interface (Typ) then
3447 return
3448 Make_Subprogram_Body (Loc,
3449 Specification => Make_Disp_Timed_Select_Spec (Typ),
3450 Declarations => New_List,
3451 Handled_Statement_Sequence =>
3452 Make_Handled_Sequence_Of_Statements (Loc,
3453 New_List (
3454 Make_Assignment_Statement (Loc,
3455 Name => Make_Identifier (Loc, Name_uF),
3456 Expression => New_Occurrence_Of (Standard_False, Loc)))));
3457 end if;
3459 if Is_Concurrent_Record_Type (Typ) then
3460 Conc_Typ := Corresponding_Concurrent_Type (Typ);
3462 -- Generate:
3463 -- I : Integer;
3465 -- where I will be used to capture the entry index of the primitive
3466 -- wrapper at position S.
3468 Append_To (Decls,
3469 Make_Object_Declaration (Loc,
3470 Defining_Identifier => Make_Defining_Identifier (Loc, Name_uI),
3471 Object_Definition =>
3472 New_Occurrence_Of (Standard_Integer, Loc)));
3474 -- Generate:
3475 -- C := Get_Prim_Op_Kind (tag! (<type>VP), S);
3477 -- if C = POK_Procedure
3478 -- or else C = POK_Protected_Procedure
3479 -- or else C = POK_Task_Procedure;
3480 -- then
3481 -- F := True;
3482 -- return;
3483 -- end if;
3485 Build_Common_Dispatching_Select_Statements (Typ, Stmts);
3487 -- Generate:
3488 -- I := Get_Entry_Index (tag! (<type>VP), S);
3490 -- I is the entry index and S is the dispatch table slot
3492 if Tagged_Type_Expansion then
3493 Tag_Node :=
3494 Unchecked_Convert_To (RTE (RE_Tag),
3495 New_Occurrence_Of
3496 (Node (First_Elmt (Access_Disp_Table (Typ))), Loc));
3498 else
3499 Tag_Node :=
3500 Make_Attribute_Reference (Loc,
3501 Prefix => New_Occurrence_Of (Typ, Loc),
3502 Attribute_Name => Name_Tag);
3503 end if;
3505 Append_To (Stmts,
3506 Make_Assignment_Statement (Loc,
3507 Name => Make_Identifier (Loc, Name_uI),
3508 Expression =>
3509 Make_Function_Call (Loc,
3510 Name => New_Occurrence_Of (RTE (RE_Get_Entry_Index), Loc),
3511 Parameter_Associations => New_List (
3512 Tag_Node,
3513 Make_Identifier (Loc, Name_uS)))));
3515 -- Protected case
3517 if Ekind (Conc_Typ) = E_Protected_Type then
3519 -- Build T._object'Access
3521 Obj_Ref :=
3522 Make_Attribute_Reference (Loc,
3523 Attribute_Name => Name_Unchecked_Access,
3524 Prefix =>
3525 Make_Selected_Component (Loc,
3526 Prefix => Make_Identifier (Loc, Name_uT),
3527 Selector_Name => Make_Identifier (Loc, Name_uObject)));
3529 -- Normal case, No_Entry_Queue restriction not active. In this
3530 -- case we generate:
3532 -- Timed_Protected_Entry_Call
3533 -- (T._object'access,
3534 -- Protected_Entry_Index! (I),
3535 -- P, D, M, F);
3537 -- where T is the protected object, I is the entry index, P are
3538 -- the wrapped parameters, D is the delay amount, M is the delay
3539 -- mode and F is the status flag.
3541 -- Historically, there was also an implementation for single
3542 -- entry protected types (in s-tposen). However, it was removed
3543 -- by also testing for no No_Select_Statements restriction in
3544 -- Exp_Utils.Corresponding_Runtime_Package. This simplified the
3545 -- implementation of s-tposen.adb and provided consistency between
3546 -- all versions of System.Tasking.Protected_Objects.Single_Entry
3547 -- (s-tposen*.adb).
3549 case Corresponding_Runtime_Package (Conc_Typ) is
3550 when System_Tasking_Protected_Objects_Entries =>
3551 Append_To (Stmts,
3552 Make_Procedure_Call_Statement (Loc,
3553 Name =>
3554 New_Occurrence_Of
3555 (RTE (RE_Timed_Protected_Entry_Call), Loc),
3556 Parameter_Associations => New_List (
3557 Obj_Ref,
3559 Make_Unchecked_Type_Conversion (Loc, -- entry index
3560 Subtype_Mark =>
3561 New_Occurrence_Of
3562 (RTE (RE_Protected_Entry_Index), Loc),
3563 Expression => Make_Identifier (Loc, Name_uI)),
3565 Make_Identifier (Loc, Name_uP), -- parameter block
3566 Make_Identifier (Loc, Name_uD), -- delay
3567 Make_Identifier (Loc, Name_uM), -- delay mode
3568 Make_Identifier (Loc, Name_uF)))); -- status flag
3570 when others =>
3571 raise Program_Error;
3572 end case;
3574 -- Task case
3576 else
3577 pragma Assert (Ekind (Conc_Typ) = E_Task_Type);
3579 -- Generate:
3580 -- Timed_Task_Entry_Call (
3581 -- T._task_id,
3582 -- Task_Entry_Index! (I),
3583 -- P,
3584 -- D,
3585 -- M,
3586 -- F);
3588 -- where T is the task object, I is the entry index, P are the
3589 -- wrapped parameters, D is the delay amount, M is the delay
3590 -- mode and F is the status flag.
3592 Append_To (Stmts,
3593 Make_Procedure_Call_Statement (Loc,
3594 Name =>
3595 New_Occurrence_Of (RTE (RE_Timed_Task_Entry_Call), Loc),
3597 Parameter_Associations => New_List (
3598 Make_Selected_Component (Loc, -- T._task_id
3599 Prefix => Make_Identifier (Loc, Name_uT),
3600 Selector_Name => Make_Identifier (Loc, Name_uTask_Id)),
3602 Make_Unchecked_Type_Conversion (Loc, -- entry index
3603 Subtype_Mark =>
3604 New_Occurrence_Of (RTE (RE_Task_Entry_Index), Loc),
3605 Expression => Make_Identifier (Loc, Name_uI)),
3607 Make_Identifier (Loc, Name_uP), -- parameter block
3608 Make_Identifier (Loc, Name_uD), -- delay
3609 Make_Identifier (Loc, Name_uM), -- delay mode
3610 Make_Identifier (Loc, Name_uF)))); -- status flag
3611 end if;
3613 else
3614 -- Initialize out parameters
3616 Append_To (Stmts,
3617 Make_Assignment_Statement (Loc,
3618 Name => Make_Identifier (Loc, Name_uF),
3619 Expression => New_Occurrence_Of (Standard_False, Loc)));
3620 Append_To (Stmts,
3621 Make_Assignment_Statement (Loc,
3622 Name => Make_Identifier (Loc, Name_uC),
3623 Expression => New_Occurrence_Of (RTE (RE_POK_Function), Loc)));
3624 end if;
3626 return
3627 Make_Subprogram_Body (Loc,
3628 Specification => Make_Disp_Timed_Select_Spec (Typ),
3629 Declarations => Decls,
3630 Handled_Statement_Sequence =>
3631 Make_Handled_Sequence_Of_Statements (Loc, Stmts));
3632 end Make_Disp_Timed_Select_Body;
3634 ---------------------------------
3635 -- Make_Disp_Timed_Select_Spec --
3636 ---------------------------------
3638 function Make_Disp_Timed_Select_Spec
3639 (Typ : Entity_Id) return Node_Id
3641 Loc : constant Source_Ptr := Sloc (Typ);
3642 Def_Id : constant Node_Id :=
3643 Make_Defining_Identifier (Loc,
3644 Name_uDisp_Timed_Select);
3645 Params : constant List_Id := New_List;
3647 begin
3648 pragma Assert (not Restriction_Active (No_Dispatching_Calls));
3650 -- T : in out Typ; -- Object parameter
3651 -- S : Integer; -- Primitive operation slot
3652 -- P : Address; -- Wrapped parameters
3653 -- D : Duration; -- Delay
3654 -- M : Integer; -- Delay Mode
3655 -- C : out Prim_Op_Kind; -- Call kind
3656 -- F : out Boolean; -- Status flag
3658 Append_List_To (Params, New_List (
3660 Make_Parameter_Specification (Loc,
3661 Defining_Identifier => Make_Defining_Identifier (Loc, Name_uT),
3662 Parameter_Type => New_Occurrence_Of (Typ, Loc),
3663 In_Present => True,
3664 Out_Present => True),
3666 Make_Parameter_Specification (Loc,
3667 Defining_Identifier => Make_Defining_Identifier (Loc, Name_uS),
3668 Parameter_Type => New_Occurrence_Of (Standard_Integer, Loc)),
3670 Make_Parameter_Specification (Loc,
3671 Defining_Identifier => Make_Defining_Identifier (Loc, Name_uP),
3672 Parameter_Type => New_Occurrence_Of (RTE (RE_Address), Loc)),
3674 Make_Parameter_Specification (Loc,
3675 Defining_Identifier => Make_Defining_Identifier (Loc, Name_uD),
3676 Parameter_Type => New_Occurrence_Of (Standard_Duration, Loc)),
3678 Make_Parameter_Specification (Loc,
3679 Defining_Identifier => Make_Defining_Identifier (Loc, Name_uM),
3680 Parameter_Type => New_Occurrence_Of (Standard_Integer, Loc)),
3682 Make_Parameter_Specification (Loc,
3683 Defining_Identifier => Make_Defining_Identifier (Loc, Name_uC),
3684 Parameter_Type =>
3685 New_Occurrence_Of (RTE (RE_Prim_Op_Kind), Loc),
3686 Out_Present => True)));
3688 Append_To (Params,
3689 Make_Parameter_Specification (Loc,
3690 Defining_Identifier => Make_Defining_Identifier (Loc, Name_uF),
3691 Parameter_Type => New_Occurrence_Of (Standard_Boolean, Loc),
3692 Out_Present => True));
3694 return
3695 Make_Procedure_Specification (Loc,
3696 Defining_Unit_Name => Def_Id,
3697 Parameter_Specifications => Params);
3698 end Make_Disp_Timed_Select_Spec;
3700 -------------
3701 -- Make_DT --
3702 -------------
3704 -- The frontend supports two models for expanding dispatch tables
3705 -- associated with library-level defined tagged types: statically and
3706 -- non-statically allocated dispatch tables. In the former case the object
3707 -- containing the dispatch table is constant and it is initialized by means
3708 -- of a positional aggregate. In the latter case, the object containing
3709 -- the dispatch table is a variable which is initialized by means of
3710 -- assignments.
3712 -- In case of locally defined tagged types, the object containing the
3713 -- object containing the dispatch table is always a variable (instead of a
3714 -- constant). This is currently required to give support to late overriding
3715 -- of primitives. For example:
3717 -- procedure Example is
3718 -- package Pkg is
3719 -- type T1 is tagged null record;
3720 -- procedure Prim (O : T1);
3721 -- end Pkg;
3723 -- type T2 is new Pkg.T1 with null record;
3724 -- procedure Prim (X : T2) is -- late overriding
3725 -- begin
3726 -- ...
3727 -- ...
3728 -- end;
3730 -- WARNING: This routine manages Ghost regions. Return statements must be
3731 -- replaced by gotos which jump to the end of the routine and restore the
3732 -- Ghost mode.
3734 function Make_DT (Typ : Entity_Id; N : Node_Id := Empty) return List_Id is
3735 Loc : constant Source_Ptr := Sloc (Typ);
3737 Max_Predef_Prims : constant Int :=
3738 UI_To_Int
3739 (Intval
3740 (Expression
3741 (Parent (RTE (RE_Max_Predef_Prims)))));
3743 DT_Decl : constant Elist_Id := New_Elmt_List;
3744 DT_Aggr : constant Elist_Id := New_Elmt_List;
3745 -- Entities marked with attribute Is_Dispatch_Table_Entity
3747 Dummy_Object : Entity_Id := Empty;
3748 -- Extra nonexistent object of type Typ internally used to compute the
3749 -- offset to the components that reference secondary dispatch tables.
3750 -- Used to statically allocate secondary dispatch tables.
3752 procedure Check_Premature_Freezing
3753 (Subp : Entity_Id;
3754 Tagged_Type : Entity_Id;
3755 Typ : Entity_Id);
3756 -- Verify that all untagged types in the profile of a subprogram are
3757 -- frozen at the point the subprogram is frozen. This enforces the rule
3758 -- on RM 13.14 (14) as modified by AI05-019. At the point a subprogram
3759 -- is frozen, enough must be known about it to build the activation
3760 -- record for it, which requires at least that the size of all
3761 -- parameters be known. Controlling arguments are by-reference,
3762 -- and therefore the rule only applies to untagged types. Typical
3763 -- violation of the rule involves an object declaration that freezes a
3764 -- tagged type, when one of its primitive operations has a type in its
3765 -- profile whose full view has not been analyzed yet. More complex cases
3766 -- involve composite types that have one private unfrozen subcomponent.
3768 procedure Export_DT (Typ : Entity_Id; DT : Entity_Id; Index : Nat := 0);
3769 -- Export the dispatch table DT of tagged type Typ. Required to generate
3770 -- forward references and statically allocate the table. For primary
3771 -- dispatch tables Index is 0; for secondary dispatch tables the value
3772 -- of index must match the Suffix_Index value assigned to the table by
3773 -- Make_Tags when generating its unique external name, and it is used to
3774 -- retrieve from the Dispatch_Table_Wrappers list associated with Typ
3775 -- the external name generated by Import_DT.
3777 procedure Make_Secondary_DT
3778 (Typ : Entity_Id;
3779 Iface : Entity_Id;
3780 Iface_Comp : Node_Id;
3781 Suffix_Index : Int;
3782 Num_Iface_Prims : Nat;
3783 Iface_DT_Ptr : Entity_Id;
3784 Predef_Prims_Ptr : Entity_Id;
3785 Build_Thunks : Boolean;
3786 Result : List_Id);
3787 -- Ada 2005 (AI-251): Expand the declarations for a Secondary Dispatch
3788 -- Table of Typ associated with Iface. Each abstract interface of Typ
3789 -- has two secondary dispatch tables: one containing pointers to thunks
3790 -- and another containing pointers to the primitives covering the
3791 -- interface primitives. The former secondary table is generated when
3792 -- Build_Thunks is True, and provides common support for dispatching
3793 -- calls through interface types; the latter secondary table is
3794 -- generated when Build_Thunks is False, and provides support for
3795 -- Generic Dispatching Constructors that dispatch calls through
3796 -- interface types. When constructing this latter table the value of
3797 -- Suffix_Index is -1 to indicate that there is no need to export such
3798 -- table when building statically allocated dispatch tables; a positive
3799 -- value of Suffix_Index must match the Suffix_Index value assigned to
3800 -- this secondary dispatch table by Make_Tags when its unique external
3801 -- name was generated.
3803 ------------------------------
3804 -- Check_Premature_Freezing --
3805 ------------------------------
3807 procedure Check_Premature_Freezing
3808 (Subp : Entity_Id;
3809 Tagged_Type : Entity_Id;
3810 Typ : Entity_Id)
3812 Comp : Entity_Id;
3814 function Is_Actual_For_Formal_Incomplete_Type
3815 (T : Entity_Id) return Boolean;
3816 -- In Ada 2012, if a nested generic has an incomplete formal type,
3817 -- the actual may be (and usually is) a private type whose completion
3818 -- appears later. It is safe to build the dispatch table in this
3819 -- case, gigi will have full views available.
3821 ------------------------------------------
3822 -- Is_Actual_For_Formal_Incomplete_Type --
3823 ------------------------------------------
3825 function Is_Actual_For_Formal_Incomplete_Type
3826 (T : Entity_Id) return Boolean
3828 Gen_Par : Entity_Id;
3829 F : Node_Id;
3831 begin
3832 if not Is_Generic_Instance (Current_Scope)
3833 or else not Used_As_Generic_Actual (T)
3834 then
3835 return False;
3836 else
3837 Gen_Par := Generic_Parent (Parent (Current_Scope));
3838 end if;
3840 F :=
3841 First
3842 (Generic_Formal_Declarations
3843 (Unit_Declaration_Node (Gen_Par)));
3844 while Present (F) loop
3845 if Ekind (Defining_Identifier (F)) = E_Incomplete_Type then
3846 return True;
3847 end if;
3849 Next (F);
3850 end loop;
3852 return False;
3853 end Is_Actual_For_Formal_Incomplete_Type;
3855 -- Start of processing for Check_Premature_Freezing
3857 begin
3858 -- Note that if the type is a (subtype of) a generic actual, the
3859 -- actual will have been frozen by the instantiation.
3861 if Present (N)
3862 and then Is_Private_Type (Typ)
3863 and then No (Full_View (Typ))
3864 and then not Is_Generic_Type (Typ)
3865 and then not Is_Tagged_Type (Typ)
3866 and then not Is_Frozen (Typ)
3867 and then not Is_Generic_Actual_Type (Typ)
3868 then
3869 Error_Msg_Sloc := Sloc (Subp);
3870 Error_Msg_NE
3871 ("declaration must appear after completion of type &", N, Typ);
3872 Error_Msg_NE
3873 ("\which is an untagged type in the profile of "
3874 & "primitive operation & declared#", N, Subp);
3876 else
3877 Comp := Private_Component (Typ);
3879 if not Is_Tagged_Type (Typ)
3880 and then Present (Comp)
3881 and then not Is_Frozen (Comp)
3882 and then not Is_Actual_For_Formal_Incomplete_Type (Comp)
3883 then
3884 Error_Msg_Sloc := Sloc (Subp);
3885 Error_Msg_Node_2 := Subp;
3886 Error_Msg_Name_1 := Chars (Tagged_Type);
3887 Error_Msg_NE
3888 ("declaration must appear after completion of type &",
3889 N, Comp);
3890 Error_Msg_NE
3891 ("\which is a component of untagged type& in the profile "
3892 & "of primitive & of type % that is frozen by the "
3893 & "declaration ", N, Typ);
3894 end if;
3895 end if;
3896 end Check_Premature_Freezing;
3898 ---------------
3899 -- Export_DT --
3900 ---------------
3902 procedure Export_DT (Typ : Entity_Id; DT : Entity_Id; Index : Nat := 0)
3904 Count : Nat;
3905 Elmt : Elmt_Id;
3907 begin
3908 Set_Is_Statically_Allocated (DT);
3909 Set_Is_True_Constant (DT);
3910 Set_Is_Exported (DT);
3912 Count := 0;
3913 Elmt := First_Elmt (Dispatch_Table_Wrappers (Typ));
3914 while Count /= Index loop
3915 Next_Elmt (Elmt);
3916 Count := Count + 1;
3917 end loop;
3919 pragma Assert (Related_Type (Node (Elmt)) = Typ);
3921 Get_External_Name (Node (Elmt));
3922 Set_Interface_Name (DT,
3923 Make_String_Literal (Loc,
3924 Strval => String_From_Name_Buffer));
3926 -- Ensure proper Sprint output of this implicit importation
3928 Set_Is_Internal (DT);
3929 Set_Is_Public (DT);
3930 end Export_DT;
3932 -----------------------
3933 -- Make_Secondary_DT --
3934 -----------------------
3936 procedure Make_Secondary_DT
3937 (Typ : Entity_Id;
3938 Iface : Entity_Id;
3939 Iface_Comp : Node_Id;
3940 Suffix_Index : Int;
3941 Num_Iface_Prims : Nat;
3942 Iface_DT_Ptr : Entity_Id;
3943 Predef_Prims_Ptr : Entity_Id;
3944 Build_Thunks : Boolean;
3945 Result : List_Id)
3947 Loc : constant Source_Ptr := Sloc (Typ);
3948 Exporting_Table : constant Boolean :=
3949 Building_Static_DT (Typ)
3950 and then Suffix_Index > 0;
3951 Iface_DT : constant Entity_Id := Make_Temporary (Loc, 'T');
3952 Predef_Prims : constant Entity_Id := Make_Temporary (Loc, 'R');
3953 DT_Constr_List : List_Id;
3954 DT_Aggr_List : List_Id;
3955 Empty_DT : Boolean := False;
3956 Nb_Predef_Prims : Nat := 0;
3957 Nb_Prim : Nat;
3958 New_Node : Node_Id;
3959 OSD : Entity_Id;
3960 OSD_Aggr_List : List_Id;
3961 Pos : Nat;
3962 Prim : Entity_Id;
3963 Prim_Elmt : Elmt_Id;
3964 Prim_Ops_Aggr_List : List_Id;
3966 begin
3967 -- Handle cases in which we do not generate statically allocated
3968 -- dispatch tables.
3970 if not Building_Static_DT (Typ) then
3971 Set_Ekind (Predef_Prims, E_Variable);
3972 Set_Ekind (Iface_DT, E_Variable);
3974 -- Statically allocated dispatch tables and related entities are
3975 -- constants.
3977 else
3978 Set_Ekind (Predef_Prims, E_Constant);
3979 Set_Is_Statically_Allocated (Predef_Prims);
3980 Set_Is_True_Constant (Predef_Prims);
3982 Set_Ekind (Iface_DT, E_Constant);
3983 Set_Is_Statically_Allocated (Iface_DT);
3984 Set_Is_True_Constant (Iface_DT);
3985 end if;
3987 -- Calculate the number of slots of the dispatch table. If the number
3988 -- of primitives of Typ is 0 we reserve a dummy single entry for its
3989 -- DT because at run time the pointer to this dummy entry will be
3990 -- used as the tag.
3992 if Num_Iface_Prims = 0 then
3993 Empty_DT := True;
3994 Nb_Prim := 1;
3995 else
3996 Nb_Prim := Num_Iface_Prims;
3997 end if;
3999 -- Generate:
4001 -- Predef_Prims : Address_Array (1 .. Default_Prim_Ops_Count) :=
4002 -- (predef-prim-op-thunk-1'address,
4003 -- predef-prim-op-thunk-2'address,
4004 -- ...
4005 -- predef-prim-op-thunk-n'address);
4006 -- for Predef_Prims'Alignment use Address'Alignment
4008 -- Stage 1: Calculate the number of predefined primitives
4010 if not Building_Static_DT (Typ) then
4011 Nb_Predef_Prims := Max_Predef_Prims;
4012 else
4013 Prim_Elmt := First_Elmt (Primitive_Operations (Typ));
4014 while Present (Prim_Elmt) loop
4015 Prim := Node (Prim_Elmt);
4017 if Is_Predefined_Dispatching_Operation (Prim)
4018 and then not Is_Abstract_Subprogram (Prim)
4019 then
4020 Pos := UI_To_Int (DT_Position (Prim));
4022 if Pos > Nb_Predef_Prims then
4023 Nb_Predef_Prims := Pos;
4024 end if;
4025 end if;
4027 Next_Elmt (Prim_Elmt);
4028 end loop;
4029 end if;
4031 if Generate_SCIL then
4032 Nb_Predef_Prims := 0;
4033 end if;
4035 -- Stage 2: Create the thunks associated with the predefined
4036 -- primitives and save their entity to fill the aggregate.
4038 declare
4039 Prim_Table : array (Nat range 1 .. Nb_Predef_Prims) of Entity_Id;
4040 Decl : Node_Id;
4041 Thunk_Id : Entity_Id;
4042 Thunk_Code : Node_Id;
4044 begin
4045 Prim_Ops_Aggr_List := New_List;
4046 Prim_Table := (others => Empty);
4048 if Building_Static_DT (Typ) then
4049 Prim_Elmt := First_Elmt (Primitive_Operations (Typ));
4050 while Present (Prim_Elmt) loop
4051 Prim := Node (Prim_Elmt);
4053 if Is_Predefined_Dispatching_Operation (Prim)
4054 and then not Is_Abstract_Subprogram (Prim)
4055 and then not Is_Eliminated (Prim)
4056 and then not Generate_SCIL
4057 and then not Present (Prim_Table
4058 (UI_To_Int (DT_Position (Prim))))
4059 then
4060 if not Build_Thunks then
4061 Prim_Table (UI_To_Int (DT_Position (Prim))) :=
4062 Alias (Prim);
4064 else
4065 Expand_Interface_Thunk
4066 (Ultimate_Alias (Prim), Thunk_Id, Thunk_Code);
4068 if Present (Thunk_Id) then
4069 Append_To (Result, Thunk_Code);
4070 Prim_Table (UI_To_Int (DT_Position (Prim))) :=
4071 Thunk_Id;
4072 end if;
4073 end if;
4074 end if;
4076 Next_Elmt (Prim_Elmt);
4077 end loop;
4078 end if;
4080 for J in Prim_Table'Range loop
4081 if Present (Prim_Table (J)) then
4082 New_Node :=
4083 Unchecked_Convert_To (RTE (RE_Prim_Ptr),
4084 Make_Attribute_Reference (Loc,
4085 Prefix => New_Occurrence_Of (Prim_Table (J), Loc),
4086 Attribute_Name => Name_Unrestricted_Access));
4087 else
4088 New_Node := Make_Null (Loc);
4089 end if;
4091 Append_To (Prim_Ops_Aggr_List, New_Node);
4092 end loop;
4094 New_Node :=
4095 Make_Aggregate (Loc, Expressions => Prim_Ops_Aggr_List);
4097 -- Remember aggregates initializing dispatch tables
4099 Append_Elmt (New_Node, DT_Aggr);
4101 Decl :=
4102 Make_Subtype_Declaration (Loc,
4103 Defining_Identifier => Make_Temporary (Loc, 'S'),
4104 Subtype_Indication =>
4105 New_Occurrence_Of (RTE (RE_Address_Array), Loc));
4107 Append_To (Result, Decl);
4109 Append_To (Result,
4110 Make_Object_Declaration (Loc,
4111 Defining_Identifier => Predef_Prims,
4112 Constant_Present => Building_Static_DT (Typ),
4113 Aliased_Present => True,
4114 Object_Definition => New_Occurrence_Of
4115 (Defining_Identifier (Decl), Loc),
4116 Expression => New_Node));
4118 Append_To (Result,
4119 Make_Attribute_Definition_Clause (Loc,
4120 Name => New_Occurrence_Of (Predef_Prims, Loc),
4121 Chars => Name_Alignment,
4122 Expression =>
4123 Make_Attribute_Reference (Loc,
4124 Prefix =>
4125 New_Occurrence_Of (RTE (RE_Integer_Address), Loc),
4126 Attribute_Name => Name_Alignment)));
4127 end;
4129 -- Generate
4131 -- OSD : Ada.Tags.Object_Specific_Data (Nb_Prims) :=
4132 -- (OSD_Table => (1 => <value>,
4133 -- ...
4134 -- N => <value>));
4136 -- Iface_DT : Dispatch_Table (Nb_Prims) :=
4137 -- ([ Signature => <sig-value> ],
4138 -- Tag_Kind => <tag_kind-value>,
4139 -- Predef_Prims => Predef_Prims'Address,
4140 -- Offset_To_Top => 0,
4141 -- OSD => OSD'Address,
4142 -- Prims_Ptr => (prim-op-1'address,
4143 -- prim-op-2'address,
4144 -- ...
4145 -- prim-op-n'address));
4146 -- for Iface_DT'Alignment use Address'Alignment;
4148 -- Stage 3: Initialize the discriminant and the record components
4150 DT_Constr_List := New_List;
4151 DT_Aggr_List := New_List;
4153 -- Nb_Prim
4155 Append_To (DT_Constr_List, Make_Integer_Literal (Loc, Nb_Prim));
4156 Append_To (DT_Aggr_List, Make_Integer_Literal (Loc, Nb_Prim));
4158 -- Signature
4160 if RTE_Record_Component_Available (RE_Signature) then
4161 Append_To (DT_Aggr_List,
4162 New_Occurrence_Of (RTE (RE_Secondary_DT), Loc));
4163 end if;
4165 -- Tag_Kind
4167 if RTE_Record_Component_Available (RE_Tag_Kind) then
4168 Append_To (DT_Aggr_List, Tagged_Kind (Typ));
4169 end if;
4171 -- Predef_Prims
4173 Append_To (DT_Aggr_List,
4174 Make_Attribute_Reference (Loc,
4175 Prefix => New_Occurrence_Of (Predef_Prims, Loc),
4176 Attribute_Name => Name_Address));
4178 -- If the location of the component that references this secondary
4179 -- dispatch table is variable then we have not declared the internal
4180 -- dummy object; the value of Offset_To_Top will be set by the init
4181 -- subprogram.
4183 if No (Dummy_Object) then
4184 Append_To (DT_Aggr_List, Make_Integer_Literal (Loc, 0));
4186 else
4187 Append_To (DT_Aggr_List,
4188 Make_Op_Minus (Loc,
4189 Make_Attribute_Reference (Loc,
4190 Prefix =>
4191 Make_Selected_Component (Loc,
4192 Prefix =>
4193 New_Occurrence_Of (Dummy_Object, Loc),
4194 Selector_Name =>
4195 New_Occurrence_Of (Iface_Comp, Loc)),
4196 Attribute_Name => Name_Position)));
4197 end if;
4199 -- Generate the Object Specific Data table required to dispatch calls
4200 -- through synchronized interfaces.
4202 if Empty_DT
4203 or else Is_Abstract_Type (Typ)
4204 or else Is_Controlled (Typ)
4205 or else Restriction_Active (No_Dispatching_Calls)
4206 or else not Is_Limited_Type (Typ)
4207 or else not Has_Interfaces (Typ)
4208 or else not Build_Thunks
4209 or else not RTE_Record_Component_Available (RE_OSD_Table)
4210 then
4211 -- No OSD table required
4213 Append_To (DT_Aggr_List,
4214 New_Occurrence_Of (RTE (RE_Null_Address), Loc));
4216 else
4217 OSD_Aggr_List := New_List;
4219 declare
4220 Prim_Table : array (Nat range 1 .. Nb_Prim) of Entity_Id;
4221 Prim : Entity_Id;
4222 Prim_Alias : Entity_Id;
4223 Prim_Elmt : Elmt_Id;
4224 E : Entity_Id;
4225 Count : Nat := 0;
4226 Pos : Nat;
4228 begin
4229 Prim_Table := (others => Empty);
4230 Prim_Alias := Empty;
4232 Prim_Elmt := First_Elmt (Primitive_Operations (Typ));
4233 while Present (Prim_Elmt) loop
4234 Prim := Node (Prim_Elmt);
4236 if Present (Interface_Alias (Prim))
4237 and then Find_Dispatching_Type
4238 (Interface_Alias (Prim)) = Iface
4239 then
4240 Prim_Alias := Interface_Alias (Prim);
4241 E := Ultimate_Alias (Prim);
4242 Pos := UI_To_Int (DT_Position (Prim_Alias));
4244 if Present (Prim_Table (Pos)) then
4245 pragma Assert (Prim_Table (Pos) = E);
4246 null;
4248 else
4249 Prim_Table (Pos) := E;
4251 Append_To (OSD_Aggr_List,
4252 Make_Component_Association (Loc,
4253 Choices => New_List (
4254 Make_Integer_Literal (Loc,
4255 DT_Position (Prim_Alias))),
4256 Expression =>
4257 Make_Integer_Literal (Loc,
4258 DT_Position (Alias (Prim)))));
4260 Count := Count + 1;
4261 end if;
4262 end if;
4264 Next_Elmt (Prim_Elmt);
4265 end loop;
4266 pragma Assert (Count = Nb_Prim);
4267 end;
4269 OSD := Make_Temporary (Loc, 'I');
4271 Append_To (Result,
4272 Make_Object_Declaration (Loc,
4273 Defining_Identifier => OSD,
4274 Object_Definition =>
4275 Make_Subtype_Indication (Loc,
4276 Subtype_Mark =>
4277 New_Occurrence_Of (RTE (RE_Object_Specific_Data), Loc),
4278 Constraint =>
4279 Make_Index_Or_Discriminant_Constraint (Loc,
4280 Constraints => New_List (
4281 Make_Integer_Literal (Loc, Nb_Prim)))),
4283 Expression =>
4284 Make_Aggregate (Loc,
4285 Component_Associations => New_List (
4286 Make_Component_Association (Loc,
4287 Choices => New_List (
4288 New_Occurrence_Of
4289 (RTE_Record_Component (RE_OSD_Num_Prims), Loc)),
4290 Expression =>
4291 Make_Integer_Literal (Loc, Nb_Prim)),
4293 Make_Component_Association (Loc,
4294 Choices => New_List (
4295 New_Occurrence_Of
4296 (RTE_Record_Component (RE_OSD_Table), Loc)),
4297 Expression => Make_Aggregate (Loc,
4298 Component_Associations => OSD_Aggr_List))))));
4300 Append_To (Result,
4301 Make_Attribute_Definition_Clause (Loc,
4302 Name => New_Occurrence_Of (OSD, Loc),
4303 Chars => Name_Alignment,
4304 Expression =>
4305 Make_Attribute_Reference (Loc,
4306 Prefix =>
4307 New_Occurrence_Of (RTE (RE_Integer_Address), Loc),
4308 Attribute_Name => Name_Alignment)));
4310 -- In secondary dispatch tables the Typeinfo component contains
4311 -- the address of the Object Specific Data (see a-tags.ads)
4313 Append_To (DT_Aggr_List,
4314 Make_Attribute_Reference (Loc,
4315 Prefix => New_Occurrence_Of (OSD, Loc),
4316 Attribute_Name => Name_Address));
4317 end if;
4319 -- Initialize the table of primitive operations
4321 Prim_Ops_Aggr_List := New_List;
4323 if Empty_DT then
4324 Append_To (Prim_Ops_Aggr_List, Make_Null (Loc));
4326 elsif Is_Abstract_Type (Typ)
4327 or else not Building_Static_DT (Typ)
4328 then
4329 for J in 1 .. Nb_Prim loop
4330 Append_To (Prim_Ops_Aggr_List, Make_Null (Loc));
4331 end loop;
4333 else
4334 declare
4335 CPP_Nb_Prims : constant Nat := CPP_Num_Prims (Typ);
4336 E : Entity_Id;
4337 Prim_Pos : Nat;
4338 Prim_Table : array (Nat range 1 .. Nb_Prim) of Entity_Id;
4339 Thunk_Code : Node_Id;
4340 Thunk_Id : Entity_Id;
4342 begin
4343 Prim_Table := (others => Empty);
4345 Prim_Elmt := First_Elmt (Primitive_Operations (Typ));
4346 while Present (Prim_Elmt) loop
4347 Prim := Node (Prim_Elmt);
4348 E := Ultimate_Alias (Prim);
4349 Prim_Pos := UI_To_Int (DT_Position (E));
4351 -- Do not reference predefined primitives because they are
4352 -- located in a separate dispatch table; skip abstract and
4353 -- eliminated primitives; skip primitives located in the C++
4354 -- part of the dispatch table because their slot is set by
4355 -- the IC routine.
4357 if not Is_Predefined_Dispatching_Operation (Prim)
4358 and then Present (Interface_Alias (Prim))
4359 and then not Is_Abstract_Subprogram (Alias (Prim))
4360 and then not Is_Eliminated (Alias (Prim))
4361 and then (not Is_CPP_Class (Root_Type (Typ))
4362 or else Prim_Pos > CPP_Nb_Prims)
4363 and then Find_Dispatching_Type
4364 (Interface_Alias (Prim)) = Iface
4366 -- Generate the code of the thunk only if the abstract
4367 -- interface type is not an immediate ancestor of
4368 -- Tagged_Type. Otherwise the DT associated with the
4369 -- interface is the primary DT.
4371 and then not Is_Ancestor (Iface, Typ,
4372 Use_Full_View => True)
4373 then
4374 if not Build_Thunks then
4375 Prim_Pos :=
4376 UI_To_Int (DT_Position (Interface_Alias (Prim)));
4377 Prim_Table (Prim_Pos) := Alias (Prim);
4379 else
4380 Expand_Interface_Thunk (Prim, Thunk_Id, Thunk_Code);
4382 if Present (Thunk_Id) then
4383 Prim_Pos :=
4384 UI_To_Int (DT_Position (Interface_Alias (Prim)));
4386 Prim_Table (Prim_Pos) := Thunk_Id;
4387 Append_To (Result, Thunk_Code);
4388 end if;
4389 end if;
4390 end if;
4392 Next_Elmt (Prim_Elmt);
4393 end loop;
4395 for J in Prim_Table'Range loop
4396 if Present (Prim_Table (J)) then
4397 New_Node :=
4398 Unchecked_Convert_To (RTE (RE_Prim_Ptr),
4399 Make_Attribute_Reference (Loc,
4400 Prefix => New_Occurrence_Of (Prim_Table (J), Loc),
4401 Attribute_Name => Name_Unrestricted_Access));
4403 else
4404 New_Node := Make_Null (Loc);
4405 end if;
4407 Append_To (Prim_Ops_Aggr_List, New_Node);
4408 end loop;
4409 end;
4410 end if;
4412 New_Node :=
4413 Make_Aggregate (Loc,
4414 Expressions => Prim_Ops_Aggr_List);
4416 Append_To (DT_Aggr_List, New_Node);
4418 -- Remember aggregates initializing dispatch tables
4420 Append_Elmt (New_Node, DT_Aggr);
4422 -- Note: Secondary dispatch tables are declared constant only if
4423 -- we can compute their offset field by means of the extra dummy
4424 -- object; otherwise they cannot be declared constant and the
4425 -- Offset_To_Top component is initialized by the IP routine.
4427 Append_To (Result,
4428 Make_Object_Declaration (Loc,
4429 Defining_Identifier => Iface_DT,
4430 Aliased_Present => True,
4431 Constant_Present => Present (Dummy_Object),
4433 Object_Definition =>
4434 Make_Subtype_Indication (Loc,
4435 Subtype_Mark => New_Occurrence_Of
4436 (RTE (RE_Dispatch_Table_Wrapper), Loc),
4437 Constraint => Make_Index_Or_Discriminant_Constraint (Loc,
4438 Constraints => DT_Constr_List)),
4440 Expression =>
4441 Make_Aggregate (Loc,
4442 Expressions => DT_Aggr_List)));
4444 Append_To (Result,
4445 Make_Attribute_Definition_Clause (Loc,
4446 Name => New_Occurrence_Of (Iface_DT, Loc),
4447 Chars => Name_Alignment,
4449 Expression =>
4450 Make_Attribute_Reference (Loc,
4451 Prefix =>
4452 New_Occurrence_Of (RTE (RE_Integer_Address), Loc),
4453 Attribute_Name => Name_Alignment)));
4455 if Exporting_Table then
4456 Export_DT (Typ, Iface_DT, Suffix_Index);
4458 -- Generate code to create the pointer to the dispatch table
4460 -- Iface_DT_Ptr : Tag := Tag!(DT.Prims_Ptr'Address);
4462 -- Note: This declaration is not added here if the table is exported
4463 -- because in such case Make_Tags has already added this declaration.
4465 else
4466 Append_To (Result,
4467 Make_Object_Declaration (Loc,
4468 Defining_Identifier => Iface_DT_Ptr,
4469 Constant_Present => True,
4471 Object_Definition =>
4472 New_Occurrence_Of (RTE (RE_Interface_Tag), Loc),
4474 Expression =>
4475 Unchecked_Convert_To (RTE (RE_Interface_Tag),
4476 Make_Attribute_Reference (Loc,
4477 Prefix =>
4478 Make_Selected_Component (Loc,
4479 Prefix => New_Occurrence_Of (Iface_DT, Loc),
4480 Selector_Name =>
4481 New_Occurrence_Of
4482 (RTE_Record_Component (RE_Prims_Ptr), Loc)),
4483 Attribute_Name => Name_Address))));
4484 end if;
4486 Append_To (Result,
4487 Make_Object_Declaration (Loc,
4488 Defining_Identifier => Predef_Prims_Ptr,
4489 Constant_Present => True,
4491 Object_Definition =>
4492 New_Occurrence_Of (RTE (RE_Address), Loc),
4494 Expression =>
4495 Make_Attribute_Reference (Loc,
4496 Prefix =>
4497 Make_Selected_Component (Loc,
4498 Prefix => New_Occurrence_Of (Iface_DT, Loc),
4499 Selector_Name =>
4500 New_Occurrence_Of
4501 (RTE_Record_Component (RE_Predef_Prims), Loc)),
4502 Attribute_Name => Name_Address)));
4504 -- Remember entities containing dispatch tables
4506 Append_Elmt (Predef_Prims, DT_Decl);
4507 Append_Elmt (Iface_DT, DT_Decl);
4508 end Make_Secondary_DT;
4510 -- Local variables
4512 Elab_Code : constant List_Id := New_List;
4513 Result : constant List_Id := New_List;
4514 Tname : constant Name_Id := Chars (Typ);
4516 -- When pragmas Discard_Names and No_Tagged_Streams simultaneously apply
4517 -- we initialize the Expanded_Name and the External_Tag of this tagged
4518 -- type with an empty string. This is useful to avoid exposing entity
4519 -- names at binary level. It can be done when both pragmas apply because
4520 -- (1) Discard_Names allows initializing Expanded_Name with an
4521 -- implementation defined value (Ada RM Section C.5 (7/2)).
4522 -- (2) External_Tag (combined with Internal_Tag) is used for object
4523 -- streaming and No_Tagged_Streams inhibits the generation of
4524 -- streams.
4526 Discard_Names : constant Boolean :=
4527 Present (No_Tagged_Streams_Pragma (Typ))
4528 and then (Global_Discard_Names
4529 or else Einfo.Discard_Names (Typ));
4531 -- The following name entries are used by Make_DT to generate a number
4532 -- of entities related to a tagged type. These entities may be generated
4533 -- in a scope other than that of the tagged type declaration, and if
4534 -- the entities for two tagged types with the same name happen to be
4535 -- generated in the same scope, we have to take care to use different
4536 -- names. This is achieved by means of a unique serial number appended
4537 -- to each generated entity name.
4539 Name_DT : constant Name_Id :=
4540 New_External_Name (Tname, 'T', Suffix_Index => -1);
4541 Name_Exname : constant Name_Id :=
4542 New_External_Name (Tname, 'E', Suffix_Index => -1);
4543 Name_HT_Link : constant Name_Id :=
4544 New_External_Name (Tname, 'H', Suffix_Index => -1);
4545 Name_Predef_Prims : constant Name_Id :=
4546 New_External_Name (Tname, 'R', Suffix_Index => -1);
4547 Name_SSD : constant Name_Id :=
4548 New_External_Name (Tname, 'S', Suffix_Index => -1);
4549 Name_TSD : constant Name_Id :=
4550 New_External_Name (Tname, 'B', Suffix_Index => -1);
4552 Saved_GM : constant Ghost_Mode_Type := Ghost_Mode;
4553 Saved_IGR : constant Node_Id := Ignored_Ghost_Region;
4554 -- Save the Ghost-related attributes to restore on exit
4556 AI : Elmt_Id;
4557 AI_Tag_Elmt : Elmt_Id;
4558 AI_Tag_Comp : Elmt_Id;
4559 DT : Entity_Id;
4560 DT_Aggr_List : List_Id;
4561 DT_Constr_List : List_Id;
4562 DT_Ptr : Entity_Id;
4563 Exname : Entity_Id;
4564 HT_Link : Entity_Id;
4565 ITable : Node_Id;
4566 I_Depth : Nat := 0;
4567 Iface_Table_Node : Node_Id;
4568 Name_ITable : Name_Id;
4569 Nb_Predef_Prims : Nat := 0;
4570 Nb_Prim : Nat := 0;
4571 New_Node : Node_Id;
4572 Num_Ifaces : Nat := 0;
4573 Parent_Typ : Entity_Id;
4574 Predef_Prims : Entity_Id;
4575 Prim : Entity_Id;
4576 Prim_Elmt : Elmt_Id;
4577 Prim_Ops_Aggr_List : List_Id;
4578 SSD : Entity_Id;
4579 Suffix_Index : Int;
4580 Typ_Comps : Elist_Id;
4581 Typ_Ifaces : Elist_Id;
4582 TSD : Entity_Id;
4583 TSD_Aggr_List : List_Id;
4584 TSD_Tags_List : List_Id;
4586 -- Start of processing for Make_DT
4588 begin
4589 pragma Assert (Is_Frozen (Typ));
4591 -- The tagged type being processed may be subject to pragma Ghost. Set
4592 -- the mode now to ensure that any nodes generated during dispatch table
4593 -- creation are properly marked as Ghost.
4595 Set_Ghost_Mode (Typ);
4597 -- Handle cases in which there is no need to build the dispatch table
4599 if Has_Dispatch_Table (Typ)
4600 or else No (Access_Disp_Table (Typ))
4601 or else Is_CPP_Class (Typ)
4602 then
4603 goto Leave;
4605 elsif No_Run_Time_Mode then
4606 Error_Msg_CRT ("tagged types", Typ);
4607 goto Leave;
4609 elsif not RTE_Available (RE_Tag) then
4610 Append_To (Result,
4611 Make_Object_Declaration (Loc,
4612 Defining_Identifier =>
4613 Node (First_Elmt (Access_Disp_Table (Typ))),
4614 Object_Definition => New_Occurrence_Of (RTE (RE_Tag), Loc),
4615 Constant_Present => True,
4616 Expression =>
4617 Unchecked_Convert_To (RTE (RE_Tag),
4618 New_Occurrence_Of (RTE (RE_Null_Address), Loc))));
4620 Analyze_List (Result, Suppress => All_Checks);
4621 Error_Msg_CRT ("tagged types", Typ);
4622 goto Leave;
4623 end if;
4625 -- Ensure that the value of Max_Predef_Prims defined in a-tags is
4626 -- correct. Valid values are 9 under configurable runtime or 15
4627 -- with full runtime.
4629 if RTE_Available (RE_Interface_Data) then
4630 if Max_Predef_Prims /= 15 then
4631 Error_Msg_N ("run-time library configuration error", Typ);
4632 goto Leave;
4633 end if;
4634 else
4635 if Max_Predef_Prims /= 9 then
4636 Error_Msg_N ("run-time library configuration error", Typ);
4637 Error_Msg_CRT ("tagged types", Typ);
4638 goto Leave;
4639 end if;
4640 end if;
4642 DT := Make_Defining_Identifier (Loc, Name_DT);
4643 Exname := Make_Defining_Identifier (Loc, Name_Exname);
4644 HT_Link := Make_Defining_Identifier (Loc, Name_HT_Link);
4645 Predef_Prims := Make_Defining_Identifier (Loc, Name_Predef_Prims);
4646 SSD := Make_Defining_Identifier (Loc, Name_SSD);
4647 TSD := Make_Defining_Identifier (Loc, Name_TSD);
4649 -- Initialize Parent_Typ handling private types
4651 Parent_Typ := Etype (Typ);
4653 if Present (Full_View (Parent_Typ)) then
4654 Parent_Typ := Full_View (Parent_Typ);
4655 end if;
4657 -- Ensure that all the primitives are frozen. This is only required when
4658 -- building static dispatch tables --- the primitives must be frozen to
4659 -- be referenced (otherwise we have problems with the backend). It is
4660 -- not a requirement with nonstatic dispatch tables because in this case
4661 -- we generate now an empty dispatch table; the extra code required to
4662 -- register the primitives in the slots will be generated later --- when
4663 -- each primitive is frozen (see Freeze_Subprogram).
4665 if Building_Static_DT (Typ) then
4666 declare
4667 Saved_FLLTT : constant Boolean :=
4668 Freezing_Library_Level_Tagged_Type;
4670 Formal : Entity_Id;
4671 Frnodes : List_Id;
4672 Prim : Entity_Id;
4673 Prim_Elmt : Elmt_Id;
4675 begin
4676 Freezing_Library_Level_Tagged_Type := True;
4678 Prim_Elmt := First_Elmt (Primitive_Operations (Typ));
4679 while Present (Prim_Elmt) loop
4680 Prim := Node (Prim_Elmt);
4681 Frnodes := Freeze_Entity (Prim, Typ);
4683 -- We disable this check for abstract subprograms, given that
4684 -- they cannot be called directly and thus the state of their
4685 -- untagged formals is of no concern. The RM is unclear in any
4686 -- case concerning the need for this check, and this topic may
4687 -- go back to the ARG.
4689 if not Is_Abstract_Subprogram (Prim) then
4690 Formal := First_Formal (Prim);
4691 while Present (Formal) loop
4692 Check_Premature_Freezing (Prim, Typ, Etype (Formal));
4693 Next_Formal (Formal);
4694 end loop;
4696 Check_Premature_Freezing (Prim, Typ, Etype (Prim));
4697 end if;
4699 if Present (Frnodes) then
4700 Append_List_To (Result, Frnodes);
4701 end if;
4703 Next_Elmt (Prim_Elmt);
4704 end loop;
4706 Freezing_Library_Level_Tagged_Type := Saved_FLLTT;
4707 end;
4708 end if;
4710 if Building_Static_Secondary_DT (Typ) then
4711 declare
4712 Cannot_Have_Null_Disc : Boolean := False;
4713 Name_Dummy_Object : constant Name_Id :=
4714 New_External_Name (Tname,
4715 'P', Suffix_Index => -1);
4716 begin
4717 Dummy_Object := Make_Defining_Identifier (Loc, Name_Dummy_Object);
4719 -- Define the extra object imported and constant to avoid linker
4720 -- errors (since this object is never declared). Required because
4721 -- we implement RM 13.3(19) for exported and imported (variable)
4722 -- objects by making them volatile.
4724 Set_Is_Imported (Dummy_Object);
4725 Set_Ekind (Dummy_Object, E_Constant);
4726 Set_Is_True_Constant (Dummy_Object);
4727 Set_Related_Type (Dummy_Object, Typ);
4729 -- The scope must be set now to call Get_External_Name
4731 Set_Scope (Dummy_Object, Current_Scope);
4733 Get_External_Name (Dummy_Object);
4734 Set_Interface_Name (Dummy_Object,
4735 Make_String_Literal (Loc, Strval => String_From_Name_Buffer));
4737 -- Ensure proper Sprint output of this implicit importation
4739 Set_Is_Internal (Dummy_Object);
4741 if not Has_Discriminants (Typ) then
4742 Append_To (Result,
4743 Make_Object_Declaration (Loc,
4744 Defining_Identifier => Dummy_Object,
4745 Constant_Present => True,
4746 Object_Definition => New_Occurrence_Of (Typ, Loc)));
4747 else
4748 declare
4749 Constr_List : constant List_Id := New_List;
4750 Discrim : Node_Id;
4752 begin
4753 Discrim := First_Discriminant (Typ);
4754 while Present (Discrim) loop
4755 if Is_Discrete_Type (Etype (Discrim)) then
4756 Append_To (Constr_List,
4757 Make_Attribute_Reference (Loc,
4758 Prefix =>
4759 New_Occurrence_Of (Etype (Discrim), Loc),
4760 Attribute_Name => Name_First));
4762 else
4763 pragma Assert (Is_Access_Type (Etype (Discrim)));
4764 Cannot_Have_Null_Disc :=
4765 Cannot_Have_Null_Disc
4766 or else Can_Never_Be_Null (Etype (Discrim));
4767 Append_To (Constr_List, Make_Null (Loc));
4768 end if;
4770 Next_Discriminant (Discrim);
4771 end loop;
4773 Append_To (Result,
4774 Make_Object_Declaration (Loc,
4775 Defining_Identifier => Dummy_Object,
4776 Constant_Present => True,
4777 Object_Definition =>
4778 Make_Subtype_Indication (Loc,
4779 Subtype_Mark => New_Occurrence_Of (Typ, Loc),
4780 Constraint =>
4781 Make_Index_Or_Discriminant_Constraint (Loc,
4782 Constraints => Constr_List))));
4783 end;
4784 end if;
4786 -- Given that the dummy object will not be declared at run time,
4787 -- analyze its declaration with expansion disabled and warnings
4788 -- and error messages ignored.
4790 Expander_Mode_Save_And_Set (False);
4791 Ignore_Errors_Enable := Ignore_Errors_Enable + 1;
4792 Analyze (Last (Result), Suppress => All_Checks);
4793 Ignore_Errors_Enable := Ignore_Errors_Enable - 1;
4794 Expander_Mode_Restore;
4795 end;
4796 end if;
4798 -- Ada 2005 (AI-251): Build the secondary dispatch tables
4800 if Has_Interfaces (Typ) then
4801 Collect_Interface_Components (Typ, Typ_Comps);
4803 -- Each secondary dispatch table is assigned an unique positive
4804 -- suffix index; such value also corresponds with the location of
4805 -- its entity in the Dispatch_Table_Wrappers list (see Make_Tags).
4807 -- Note: This value must be kept sync with the Suffix_Index values
4808 -- generated by Make_Tags
4810 Suffix_Index := 1;
4811 AI_Tag_Elmt :=
4812 Next_Elmt (Next_Elmt (First_Elmt (Access_Disp_Table (Typ))));
4814 AI_Tag_Comp := First_Elmt (Typ_Comps);
4815 while Present (AI_Tag_Comp) loop
4816 pragma Assert (Has_Suffix (Node (AI_Tag_Elmt), 'P'));
4818 -- Build the secondary table containing pointers to thunks
4820 Make_Secondary_DT
4821 (Typ => Typ,
4822 Iface =>
4823 Base_Type (Related_Type (Node (AI_Tag_Comp))),
4824 Iface_Comp => Node (AI_Tag_Comp),
4825 Suffix_Index => Suffix_Index,
4826 Num_Iface_Prims =>
4827 UI_To_Int (DT_Entry_Count (Node (AI_Tag_Comp))),
4828 Iface_DT_Ptr => Node (AI_Tag_Elmt),
4829 Predef_Prims_Ptr => Node (Next_Elmt (AI_Tag_Elmt)),
4830 Build_Thunks => True,
4831 Result => Result);
4833 -- Skip secondary dispatch table referencing thunks to predefined
4834 -- primitives.
4836 Next_Elmt (AI_Tag_Elmt);
4837 pragma Assert (Has_Suffix (Node (AI_Tag_Elmt), 'Y'));
4839 -- Secondary dispatch table referencing user-defined primitives
4840 -- covered by this interface.
4842 Next_Elmt (AI_Tag_Elmt);
4843 pragma Assert (Has_Suffix (Node (AI_Tag_Elmt), 'D'));
4845 -- Build the secondary table containing pointers to primitives
4846 -- (used to give support to Generic Dispatching Constructors).
4848 Make_Secondary_DT
4849 (Typ => Typ,
4850 Iface => Base_Type
4851 (Related_Type (Node (AI_Tag_Comp))),
4852 Iface_Comp => Node (AI_Tag_Comp),
4853 Suffix_Index => -1,
4854 Num_Iface_Prims => UI_To_Int
4855 (DT_Entry_Count (Node (AI_Tag_Comp))),
4856 Iface_DT_Ptr => Node (AI_Tag_Elmt),
4857 Predef_Prims_Ptr => Node (Next_Elmt (AI_Tag_Elmt)),
4858 Build_Thunks => False,
4859 Result => Result);
4861 -- Skip secondary dispatch table referencing predefined primitives
4863 Next_Elmt (AI_Tag_Elmt);
4864 pragma Assert (Has_Suffix (Node (AI_Tag_Elmt), 'Z'));
4866 Suffix_Index := Suffix_Index + 1;
4867 Next_Elmt (AI_Tag_Elmt);
4868 Next_Elmt (AI_Tag_Comp);
4869 end loop;
4870 end if;
4872 -- Get the _tag entity and number of primitives of its dispatch table
4874 DT_Ptr := Node (First_Elmt (Access_Disp_Table (Typ)));
4875 Nb_Prim := UI_To_Int (DT_Entry_Count (First_Tag_Component (Typ)));
4877 if Generate_SCIL then
4878 Nb_Prim := 0;
4879 end if;
4881 Set_Is_Statically_Allocated (DT, Is_Library_Level_Tagged_Type (Typ));
4882 Set_Is_Statically_Allocated (SSD, Is_Library_Level_Tagged_Type (Typ));
4883 Set_Is_Statically_Allocated (TSD, Is_Library_Level_Tagged_Type (Typ));
4884 Set_Is_Statically_Allocated (Predef_Prims,
4885 Is_Library_Level_Tagged_Type (Typ));
4887 -- In case of locally defined tagged type we declare the object
4888 -- containing the dispatch table by means of a variable. Its
4889 -- initialization is done later by means of an assignment. This is
4890 -- required to generate its External_Tag.
4892 if not Building_Static_DT (Typ) then
4894 -- Generate:
4895 -- DT : No_Dispatch_Table_Wrapper;
4896 -- for DT'Alignment use Address'Alignment;
4897 -- DT_Ptr : Tag := !Tag (DT.NDT_Prims_Ptr'Address);
4899 if not Has_DT (Typ) then
4900 Append_To (Result,
4901 Make_Object_Declaration (Loc,
4902 Defining_Identifier => DT,
4903 Aliased_Present => True,
4904 Constant_Present => False,
4905 Object_Definition =>
4906 New_Occurrence_Of
4907 (RTE (RE_No_Dispatch_Table_Wrapper), Loc)));
4909 Append_To (Result,
4910 Make_Attribute_Definition_Clause (Loc,
4911 Name => New_Occurrence_Of (DT, Loc),
4912 Chars => Name_Alignment,
4913 Expression =>
4914 Make_Attribute_Reference (Loc,
4915 Prefix =>
4916 New_Occurrence_Of (RTE (RE_Integer_Address), Loc),
4917 Attribute_Name => Name_Alignment)));
4919 Append_To (Result,
4920 Make_Object_Declaration (Loc,
4921 Defining_Identifier => DT_Ptr,
4922 Object_Definition => New_Occurrence_Of (RTE (RE_Tag), Loc),
4923 Constant_Present => True,
4924 Expression =>
4925 Unchecked_Convert_To (RTE (RE_Tag),
4926 Make_Attribute_Reference (Loc,
4927 Prefix =>
4928 Make_Selected_Component (Loc,
4929 Prefix => New_Occurrence_Of (DT, Loc),
4930 Selector_Name =>
4931 New_Occurrence_Of
4932 (RTE_Record_Component (RE_NDT_Prims_Ptr), Loc)),
4933 Attribute_Name => Name_Address))));
4935 Set_Is_Statically_Allocated (DT_Ptr,
4936 Is_Library_Level_Tagged_Type (Typ));
4938 -- Generate the SCIL node for the previous object declaration
4939 -- because it has a tag initialization.
4941 if Generate_SCIL then
4942 New_Node :=
4943 Make_SCIL_Dispatch_Table_Tag_Init (Sloc (Last (Result)));
4944 Set_SCIL_Entity (New_Node, Typ);
4945 Set_SCIL_Node (Last (Result), New_Node);
4947 goto Leave_SCIL;
4949 -- Gnat2scil has its own implementation of dispatch tables,
4950 -- different than what is being implemented here. Generating
4951 -- further dispatch table initialization code would just
4952 -- cause gnat2scil to generate useless Scil which CodePeer
4953 -- would waste time and space analyzing, so we skip it.
4954 end if;
4956 -- Generate:
4957 -- DT : Dispatch_Table_Wrapper (Nb_Prim);
4958 -- for DT'Alignment use Address'Alignment;
4959 -- DT_Ptr : Tag := !Tag (DT.Prims_Ptr'Address);
4961 else
4962 -- If the tagged type has no primitives we add a dummy slot
4963 -- whose address will be the tag of this type.
4965 if Nb_Prim = 0 then
4966 DT_Constr_List :=
4967 New_List (Make_Integer_Literal (Loc, 1));
4968 else
4969 DT_Constr_List :=
4970 New_List (Make_Integer_Literal (Loc, Nb_Prim));
4971 end if;
4973 Append_To (Result,
4974 Make_Object_Declaration (Loc,
4975 Defining_Identifier => DT,
4976 Aliased_Present => True,
4977 Constant_Present => False,
4978 Object_Definition =>
4979 Make_Subtype_Indication (Loc,
4980 Subtype_Mark =>
4981 New_Occurrence_Of (RTE (RE_Dispatch_Table_Wrapper), Loc),
4982 Constraint =>
4983 Make_Index_Or_Discriminant_Constraint (Loc,
4984 Constraints => DT_Constr_List))));
4986 Append_To (Result,
4987 Make_Attribute_Definition_Clause (Loc,
4988 Name => New_Occurrence_Of (DT, Loc),
4989 Chars => Name_Alignment,
4990 Expression =>
4991 Make_Attribute_Reference (Loc,
4992 Prefix =>
4993 New_Occurrence_Of (RTE (RE_Integer_Address), Loc),
4994 Attribute_Name => Name_Alignment)));
4996 Append_To (Result,
4997 Make_Object_Declaration (Loc,
4998 Defining_Identifier => DT_Ptr,
4999 Object_Definition => New_Occurrence_Of (RTE (RE_Tag), Loc),
5000 Constant_Present => True,
5001 Expression =>
5002 Unchecked_Convert_To (RTE (RE_Tag),
5003 Make_Attribute_Reference (Loc,
5004 Prefix =>
5005 Make_Selected_Component (Loc,
5006 Prefix => New_Occurrence_Of (DT, Loc),
5007 Selector_Name =>
5008 New_Occurrence_Of
5009 (RTE_Record_Component (RE_Prims_Ptr), Loc)),
5010 Attribute_Name => Name_Address))));
5012 Set_Is_Statically_Allocated (DT_Ptr,
5013 Is_Library_Level_Tagged_Type (Typ));
5015 -- Generate the SCIL node for the previous object declaration
5016 -- because it has a tag initialization.
5018 if Generate_SCIL then
5019 New_Node :=
5020 Make_SCIL_Dispatch_Table_Tag_Init (Sloc (Last (Result)));
5021 Set_SCIL_Entity (New_Node, Typ);
5022 Set_SCIL_Node (Last (Result), New_Node);
5024 goto Leave_SCIL;
5026 -- Gnat2scil has its own implementation of dispatch tables,
5027 -- different than what is being implemented here. Generating
5028 -- further dispatch table initialization code would just
5029 -- cause gnat2scil to generate useless Scil which CodePeer
5030 -- would waste time and space analyzing, so we skip it.
5031 end if;
5033 Append_To (Result,
5034 Make_Object_Declaration (Loc,
5035 Defining_Identifier =>
5036 Node (Next_Elmt (First_Elmt (Access_Disp_Table (Typ)))),
5037 Constant_Present => True,
5038 Object_Definition =>
5039 New_Occurrence_Of (RTE (RE_Address), Loc),
5040 Expression =>
5041 Make_Attribute_Reference (Loc,
5042 Prefix =>
5043 Make_Selected_Component (Loc,
5044 Prefix => New_Occurrence_Of (DT, Loc),
5045 Selector_Name =>
5046 New_Occurrence_Of
5047 (RTE_Record_Component (RE_Predef_Prims), Loc)),
5048 Attribute_Name => Name_Address)));
5049 end if;
5050 end if;
5052 -- Generate: Expanded_Name : constant String := "";
5054 if Discard_Names then
5055 Append_To (Result,
5056 Make_Object_Declaration (Loc,
5057 Defining_Identifier => Exname,
5058 Constant_Present => True,
5059 Object_Definition => New_Occurrence_Of (Standard_String, Loc),
5060 Expression =>
5061 Make_String_Literal (Loc, "")));
5063 -- Generate: Exname : constant String := full_qualified_name (typ);
5064 -- The type itself may be an anonymous parent type, so use the first
5065 -- subtype to have a user-recognizable name.
5067 else
5068 Append_To (Result,
5069 Make_Object_Declaration (Loc,
5070 Defining_Identifier => Exname,
5071 Constant_Present => True,
5072 Object_Definition => New_Occurrence_Of (Standard_String, Loc),
5073 Expression =>
5074 Make_String_Literal (Loc,
5075 Fully_Qualified_Name_String (First_Subtype (Typ)))));
5076 end if;
5078 Set_Is_Statically_Allocated (Exname);
5079 Set_Is_True_Constant (Exname);
5081 -- Declare the object used by Ada.Tags.Register_Tag
5083 if RTE_Available (RE_Register_Tag) then
5084 Append_To (Result,
5085 Make_Object_Declaration (Loc,
5086 Defining_Identifier => HT_Link,
5087 Object_Definition => New_Occurrence_Of (RTE (RE_Tag), Loc),
5088 Expression => New_Occurrence_Of (RTE (RE_No_Tag), Loc)));
5089 end if;
5091 -- Generate code to create the storage for the type specific data object
5092 -- with enough space to store the tags of the ancestors plus the tags
5093 -- of all the implemented interfaces (as described in a-tags.adb).
5095 -- TSD : Type_Specific_Data (I_Depth) :=
5096 -- (Idepth => I_Depth,
5097 -- Access_Level => Type_Access_Level (Typ),
5098 -- Alignment => Typ'Alignment,
5099 -- Expanded_Name => Cstring_Ptr!(Exname'Address))
5100 -- External_Tag => Cstring_Ptr!(Exname'Address))
5101 -- HT_Link => HT_Link'Address,
5102 -- Transportable => <<boolean-value>>,
5103 -- Is_Abstract => <<boolean-value>>,
5104 -- Needs_Finalization => <<boolean-value>>,
5105 -- [ Size_Func => Size_Prim'Access, ]
5106 -- [ Interfaces_Table => <<access-value>>, ]
5107 -- [ SSD => SSD_Table'Address ]
5108 -- Tags_Table => (0 => null,
5109 -- 1 => Parent'Tag
5110 -- ...);
5111 -- for TSD'Alignment use Address'Alignment
5113 TSD_Aggr_List := New_List;
5115 -- Idepth: Count ancestors to compute the inheritance depth. For private
5116 -- extensions, always go to the full view in order to compute the real
5117 -- inheritance depth.
5119 declare
5120 Current_Typ : Entity_Id;
5121 Parent_Typ : Entity_Id;
5123 begin
5124 I_Depth := 0;
5125 Current_Typ := Typ;
5126 loop
5127 Parent_Typ := Etype (Current_Typ);
5129 if Is_Private_Type (Parent_Typ) then
5130 Parent_Typ := Full_View (Base_Type (Parent_Typ));
5131 end if;
5133 exit when Parent_Typ = Current_Typ;
5135 I_Depth := I_Depth + 1;
5136 Current_Typ := Parent_Typ;
5137 end loop;
5138 end;
5140 Append_To (TSD_Aggr_List,
5141 Make_Integer_Literal (Loc, I_Depth));
5143 -- Access_Level
5145 Append_To (TSD_Aggr_List,
5146 Make_Integer_Literal (Loc, Type_Access_Level (Typ)));
5148 -- Alignment
5150 -- For CPP types we cannot rely on the value of 'Alignment provided
5151 -- by the backend to initialize this TSD field.
5153 if Convention (Typ) = Convention_CPP
5154 or else Is_CPP_Class (Root_Type (Typ))
5155 then
5156 Append_To (TSD_Aggr_List,
5157 Make_Integer_Literal (Loc, 0));
5158 else
5159 Append_To (TSD_Aggr_List,
5160 Make_Attribute_Reference (Loc,
5161 Prefix => New_Occurrence_Of (Typ, Loc),
5162 Attribute_Name => Name_Alignment));
5163 end if;
5165 -- Expanded_Name
5167 Append_To (TSD_Aggr_List,
5168 Unchecked_Convert_To (RTE (RE_Cstring_Ptr),
5169 Make_Attribute_Reference (Loc,
5170 Prefix => New_Occurrence_Of (Exname, Loc),
5171 Attribute_Name => Name_Address)));
5173 -- External_Tag of a local tagged type
5175 -- <typ>A : constant String :=
5176 -- "Internal tag at 16#tag-addr#: <full-name-of-typ>";
5178 -- The reason we generate this strange name is that we do not want to
5179 -- enter local tagged types in the global hash table used to compute
5180 -- the Internal_Tag attribute for two reasons:
5182 -- 1. It is hard to avoid a tasking race condition for entering the
5183 -- entry into the hash table.
5185 -- 2. It would cause a storage leak, unless we rig up considerable
5186 -- mechanism to remove the entry from the hash table on exit.
5188 -- So what we do is to generate the above external tag name, where the
5189 -- hex address is the address of the local dispatch table (i.e. exactly
5190 -- the value we want if Internal_Tag is computed from this string).
5192 -- Of course this value will only be valid if the tagged type is still
5193 -- in scope, but it clearly must be erroneous to compute the internal
5194 -- tag of a tagged type that is out of scope.
5196 -- We don't do this processing if an explicit external tag has been
5197 -- specified. That's an odd case for which we have already issued a
5198 -- warning, where we will not be able to compute the internal tag.
5200 if not Discard_Names
5201 and then not Is_Library_Level_Entity (Typ)
5202 and then not Has_External_Tag_Rep_Clause (Typ)
5203 then
5204 declare
5205 Exname : constant Entity_Id :=
5206 Make_Defining_Identifier (Loc,
5207 Chars => New_External_Name (Tname, 'A'));
5208 Full_Name : constant String_Id :=
5209 Fully_Qualified_Name_String (First_Subtype (Typ));
5210 Str1_Id : String_Id;
5211 Str2_Id : String_Id;
5213 begin
5214 -- Generate:
5215 -- Str1 = "Internal tag at 16#";
5217 Start_String;
5218 Store_String_Chars ("Internal tag at 16#");
5219 Str1_Id := End_String;
5221 -- Generate:
5222 -- Str2 = "#: <type-full-name>";
5224 Start_String;
5225 Store_String_Chars ("#: ");
5226 Store_String_Chars (Full_Name);
5227 Str2_Id := End_String;
5229 -- Generate:
5230 -- Exname : constant String :=
5231 -- Str1 & Address_Image (Tag) & Str2;
5233 if RTE_Available (RE_Address_Image) then
5234 Append_To (Result,
5235 Make_Object_Declaration (Loc,
5236 Defining_Identifier => Exname,
5237 Constant_Present => True,
5238 Object_Definition => New_Occurrence_Of
5239 (Standard_String, Loc),
5240 Expression =>
5241 Make_Op_Concat (Loc,
5242 Left_Opnd => Make_String_Literal (Loc, Str1_Id),
5243 Right_Opnd =>
5244 Make_Op_Concat (Loc,
5245 Left_Opnd =>
5246 Make_Function_Call (Loc,
5247 Name =>
5248 New_Occurrence_Of
5249 (RTE (RE_Address_Image), Loc),
5250 Parameter_Associations => New_List (
5251 Unchecked_Convert_To (RTE (RE_Address),
5252 New_Occurrence_Of (DT_Ptr, Loc)))),
5253 Right_Opnd =>
5254 Make_String_Literal (Loc, Str2_Id)))));
5256 -- Generate:
5257 -- Exname : constant String := Str1 & Str2;
5259 else
5260 Append_To (Result,
5261 Make_Object_Declaration (Loc,
5262 Defining_Identifier => Exname,
5263 Constant_Present => True,
5264 Object_Definition =>
5265 New_Occurrence_Of (Standard_String, Loc),
5266 Expression =>
5267 Make_Op_Concat (Loc,
5268 Left_Opnd => Make_String_Literal (Loc, Str1_Id),
5269 Right_Opnd => Make_String_Literal (Loc, Str2_Id))));
5270 end if;
5272 New_Node :=
5273 Unchecked_Convert_To (RTE (RE_Cstring_Ptr),
5274 Make_Attribute_Reference (Loc,
5275 Prefix => New_Occurrence_Of (Exname, Loc),
5276 Attribute_Name => Name_Address));
5277 end;
5279 -- External tag of a library-level tagged type: Check for a definition
5280 -- of External_Tag. The clause is considered only if it applies to this
5281 -- specific tagged type, as opposed to one of its ancestors.
5282 -- If the type is an unconstrained type extension, we are building the
5283 -- dispatch table of its anonymous base type, so the external tag, if
5284 -- any was specified, must be retrieved from the first subtype. Go to
5285 -- the full view in case the clause is in the private part.
5287 else
5288 declare
5289 Def : constant Node_Id := Get_Attribute_Definition_Clause
5290 (Underlying_Type (First_Subtype (Typ)),
5291 Attribute_External_Tag);
5293 Old_Val : String_Id;
5294 New_Val : String_Id;
5295 E : Entity_Id;
5297 begin
5298 if not Present (Def)
5299 or else Entity (Name (Def)) /= First_Subtype (Typ)
5300 then
5301 New_Node :=
5302 Unchecked_Convert_To (RTE (RE_Cstring_Ptr),
5303 Make_Attribute_Reference (Loc,
5304 Prefix => New_Occurrence_Of (Exname, Loc),
5305 Attribute_Name => Name_Address));
5306 else
5307 Old_Val := Strval (Expr_Value_S (Expression (Def)));
5309 -- For the rep clause "for <typ>'external_tag use y" generate:
5311 -- <typ>A : constant string := y;
5313 -- <typ>A'Address is used to set the External_Tag component
5314 -- of the TSD
5316 -- Create a new nul terminated string if it is not already
5318 if String_Length (Old_Val) > 0
5319 and then
5320 Get_String_Char (Old_Val, String_Length (Old_Val)) = 0
5321 then
5322 New_Val := Old_Val;
5323 else
5324 Start_String (Old_Val);
5325 Store_String_Char (Get_Char_Code (ASCII.NUL));
5326 New_Val := End_String;
5327 end if;
5329 E := Make_Defining_Identifier (Loc,
5330 New_External_Name (Chars (Typ), 'A'));
5332 Append_To (Result,
5333 Make_Object_Declaration (Loc,
5334 Defining_Identifier => E,
5335 Constant_Present => True,
5336 Object_Definition =>
5337 New_Occurrence_Of (Standard_String, Loc),
5338 Expression =>
5339 Make_String_Literal (Loc, New_Val)));
5341 New_Node :=
5342 Unchecked_Convert_To (RTE (RE_Cstring_Ptr),
5343 Make_Attribute_Reference (Loc,
5344 Prefix => New_Occurrence_Of (E, Loc),
5345 Attribute_Name => Name_Address));
5346 end if;
5347 end;
5348 end if;
5350 Append_To (TSD_Aggr_List, New_Node);
5352 -- HT_Link
5354 if RTE_Available (RE_Register_Tag) then
5355 Append_To (TSD_Aggr_List,
5356 Unchecked_Convert_To (RTE (RE_Tag_Ptr),
5357 Make_Attribute_Reference (Loc,
5358 Prefix => New_Occurrence_Of (HT_Link, Loc),
5359 Attribute_Name => Name_Address)));
5361 elsif RTE_Record_Component_Available (RE_HT_Link) then
5362 Append_To (TSD_Aggr_List,
5363 Unchecked_Convert_To (RTE (RE_Tag_Ptr),
5364 New_Occurrence_Of (RTE (RE_Null_Address), Loc)));
5365 end if;
5367 -- Transportable: Set for types that can be used in remote calls
5368 -- with respect to E.4(18) legality rules.
5370 declare
5371 Transportable : Entity_Id;
5373 begin
5374 Transportable :=
5375 Boolean_Literals
5376 (Is_Pure (Typ)
5377 or else Is_Shared_Passive (Typ)
5378 or else
5379 ((Is_Remote_Types (Typ)
5380 or else Is_Remote_Call_Interface (Typ))
5381 and then Original_View_In_Visible_Part (Typ))
5382 or else not Comes_From_Source (Typ));
5384 Append_To (TSD_Aggr_List,
5385 New_Occurrence_Of (Transportable, Loc));
5386 end;
5388 -- Is_Abstract (Ada 2012: AI05-0173). This functionality is not
5389 -- available in the HIE runtime.
5391 if RTE_Record_Component_Available (RE_Is_Abstract) then
5392 declare
5393 Is_Abstract : Entity_Id;
5394 begin
5395 Is_Abstract := Boolean_Literals (Is_Abstract_Type (Typ));
5396 Append_To (TSD_Aggr_List,
5397 New_Occurrence_Of (Is_Abstract, Loc));
5398 end;
5399 end if;
5401 -- Needs_Finalization: Set if the type is controlled or has controlled
5402 -- components.
5404 declare
5405 Needs_Fin : Entity_Id;
5406 begin
5407 Needs_Fin := Boolean_Literals (Needs_Finalization (Typ));
5408 Append_To (TSD_Aggr_List, New_Occurrence_Of (Needs_Fin, Loc));
5409 end;
5411 -- Size_Func
5413 if RTE_Record_Component_Available (RE_Size_Func) then
5415 -- Initialize this field to Null_Address if we are not building
5416 -- static dispatch tables static or if the size function is not
5417 -- available. In the former case we cannot initialize this field
5418 -- until the function is frozen and registered in the dispatch
5419 -- table (see Register_Primitive).
5421 if not Building_Static_DT (Typ) or else not Has_DT (Typ) then
5422 Append_To (TSD_Aggr_List,
5423 Unchecked_Convert_To (RTE (RE_Size_Ptr),
5424 New_Occurrence_Of (RTE (RE_Null_Address), Loc)));
5426 else
5427 declare
5428 Prim_Elmt : Elmt_Id;
5429 Prim : Entity_Id;
5430 Size_Comp : Node_Id := Empty;
5432 begin
5433 Prim_Elmt := First_Elmt (Primitive_Operations (Typ));
5434 while Present (Prim_Elmt) loop
5435 Prim := Node (Prim_Elmt);
5437 if Chars (Prim) = Name_uSize then
5438 Prim := Ultimate_Alias (Prim);
5440 if Is_Abstract_Subprogram (Prim) then
5441 Size_Comp :=
5442 Unchecked_Convert_To (RTE (RE_Size_Ptr),
5443 New_Occurrence_Of (RTE (RE_Null_Address), Loc));
5444 else
5445 Size_Comp :=
5446 Unchecked_Convert_To (RTE (RE_Size_Ptr),
5447 Make_Attribute_Reference (Loc,
5448 Prefix => New_Occurrence_Of (Prim, Loc),
5449 Attribute_Name => Name_Unrestricted_Access));
5450 end if;
5452 exit;
5453 end if;
5455 Next_Elmt (Prim_Elmt);
5456 end loop;
5458 pragma Assert (Present (Size_Comp));
5459 Append_To (TSD_Aggr_List, Size_Comp);
5460 end;
5461 end if;
5462 end if;
5464 -- Interfaces_Table (required for AI-405)
5466 if RTE_Record_Component_Available (RE_Interfaces_Table) then
5468 -- Count the number of interface types implemented by Typ
5470 Collect_Interfaces (Typ, Typ_Ifaces);
5472 AI := First_Elmt (Typ_Ifaces);
5473 while Present (AI) loop
5474 Num_Ifaces := Num_Ifaces + 1;
5475 Next_Elmt (AI);
5476 end loop;
5478 if Num_Ifaces = 0 then
5479 Iface_Table_Node := Make_Null (Loc);
5481 -- Generate the Interface_Table object
5483 else
5484 declare
5485 TSD_Ifaces_List : constant List_Id := New_List;
5486 Elmt : Elmt_Id;
5487 Ifaces_List : Elist_Id := No_Elist;
5488 Ifaces_Comp_List : Elist_Id := No_Elist;
5489 Ifaces_Tag_List : Elist_Id;
5490 Offset_To_Top : Node_Id;
5491 Sec_DT_Tag : Node_Id;
5493 begin
5494 -- Collect interfaces information if we need to compute the
5495 -- offset to the top using the dummy object.
5497 if Present (Dummy_Object) then
5498 Collect_Interfaces_Info (Typ,
5499 Ifaces_List, Ifaces_Comp_List, Ifaces_Tag_List);
5500 end if;
5502 AI := First_Elmt (Typ_Ifaces);
5503 while Present (AI) loop
5504 if Is_Ancestor (Node (AI), Typ, Use_Full_View => True) then
5505 Sec_DT_Tag := New_Occurrence_Of (DT_Ptr, Loc);
5507 else
5508 Elmt :=
5509 Next_Elmt
5510 (Next_Elmt (First_Elmt (Access_Disp_Table (Typ))));
5511 pragma Assert (Has_Thunks (Node (Elmt)));
5513 while Is_Tag (Node (Elmt))
5514 and then not
5515 Is_Ancestor (Node (AI), Related_Type (Node (Elmt)),
5516 Use_Full_View => True)
5517 loop
5518 pragma Assert (Has_Thunks (Node (Elmt)));
5519 Next_Elmt (Elmt);
5520 pragma Assert (Has_Thunks (Node (Elmt)));
5521 Next_Elmt (Elmt);
5522 pragma Assert (not Has_Thunks (Node (Elmt)));
5523 Next_Elmt (Elmt);
5524 pragma Assert (not Has_Thunks (Node (Elmt)));
5525 Next_Elmt (Elmt);
5526 end loop;
5528 pragma Assert (Ekind (Node (Elmt)) = E_Constant
5529 and then not
5530 Has_Thunks (Node (Next_Elmt (Next_Elmt (Elmt)))));
5532 Sec_DT_Tag :=
5533 New_Occurrence_Of
5534 (Node (Next_Elmt (Next_Elmt (Elmt))), Loc);
5535 end if;
5537 -- For static dispatch tables compute Offset_To_Top using
5538 -- the dummy object.
5540 if Present (Dummy_Object) then
5541 declare
5542 Iface : constant Node_Id := Node (AI);
5543 Iface_Comp : Node_Id := Empty;
5544 Iface_Comp_Elmt : Elmt_Id;
5545 Iface_Elmt : Elmt_Id;
5547 begin
5548 Iface_Elmt := First_Elmt (Ifaces_List);
5549 Iface_Comp_Elmt := First_Elmt (Ifaces_Comp_List);
5551 while Present (Iface_Elmt) loop
5552 if Node (Iface_Elmt) = Iface then
5553 Iface_Comp := Node (Iface_Comp_Elmt);
5554 exit;
5555 end if;
5557 Next_Elmt (Iface_Elmt);
5558 Next_Elmt (Iface_Comp_Elmt);
5559 end loop;
5561 pragma Assert (Present (Iface_Comp));
5563 Offset_To_Top :=
5564 Make_Op_Minus (Loc,
5565 Make_Attribute_Reference (Loc,
5566 Prefix =>
5567 Make_Selected_Component (Loc,
5568 Prefix =>
5569 New_Occurrence_Of (Dummy_Object, Loc),
5570 Selector_Name =>
5571 New_Occurrence_Of (Iface_Comp, Loc)),
5572 Attribute_Name => Name_Position));
5573 end;
5574 else
5575 Offset_To_Top := Make_Integer_Literal (Loc, 0);
5576 end if;
5578 Append_To (TSD_Ifaces_List,
5579 Make_Aggregate (Loc,
5580 Expressions => New_List (
5582 -- Iface_Tag
5584 Unchecked_Convert_To (RTE (RE_Tag),
5585 New_Occurrence_Of
5586 (Node (First_Elmt (Access_Disp_Table (Node (AI)))),
5587 Loc)),
5589 -- Static_Offset_To_Top
5591 New_Occurrence_Of (Standard_True, Loc),
5593 -- Offset_To_Top_Value
5595 Offset_To_Top,
5597 -- Offset_To_Top_Func
5599 Make_Null (Loc),
5601 -- Secondary_DT
5603 Unchecked_Convert_To (RTE (RE_Tag), Sec_DT_Tag))));
5605 Next_Elmt (AI);
5606 end loop;
5608 Name_ITable := New_External_Name (Tname, 'I');
5609 ITable := Make_Defining_Identifier (Loc, Name_ITable);
5610 Set_Is_Statically_Allocated (ITable,
5611 Is_Library_Level_Tagged_Type (Typ));
5613 -- The table of interfaces is constant if we are building a
5614 -- static dispatch table; otherwise is not constant because
5615 -- its slots are filled at run time by the IP routine.
5617 Append_To (Result,
5618 Make_Object_Declaration (Loc,
5619 Defining_Identifier => ITable,
5620 Aliased_Present => True,
5621 Constant_Present => Present (Dummy_Object),
5622 Object_Definition =>
5623 Make_Subtype_Indication (Loc,
5624 Subtype_Mark =>
5625 New_Occurrence_Of (RTE (RE_Interface_Data), Loc),
5626 Constraint =>
5627 Make_Index_Or_Discriminant_Constraint (Loc,
5628 Constraints => New_List (
5629 Make_Integer_Literal (Loc, Num_Ifaces)))),
5631 Expression =>
5632 Make_Aggregate (Loc,
5633 Expressions => New_List (
5634 Make_Integer_Literal (Loc, Num_Ifaces),
5635 Make_Aggregate (Loc, TSD_Ifaces_List)))));
5637 Append_To (Result,
5638 Make_Attribute_Definition_Clause (Loc,
5639 Name => New_Occurrence_Of (ITable, Loc),
5640 Chars => Name_Alignment,
5641 Expression =>
5642 Make_Attribute_Reference (Loc,
5643 Prefix =>
5644 New_Occurrence_Of (RTE (RE_Integer_Address), Loc),
5645 Attribute_Name => Name_Alignment)));
5647 Iface_Table_Node :=
5648 Make_Attribute_Reference (Loc,
5649 Prefix => New_Occurrence_Of (ITable, Loc),
5650 Attribute_Name => Name_Unchecked_Access);
5651 end;
5652 end if;
5654 Append_To (TSD_Aggr_List, Iface_Table_Node);
5655 end if;
5657 -- Generate the Select Specific Data table for synchronized types that
5658 -- implement synchronized interfaces. The size of the table is
5659 -- constrained by the number of non-predefined primitive operations.
5661 if RTE_Record_Component_Available (RE_SSD) then
5662 if Ada_Version >= Ada_2005
5663 and then Has_DT (Typ)
5664 and then Is_Concurrent_Record_Type (Typ)
5665 and then Has_Interfaces (Typ)
5666 and then Nb_Prim > 0
5667 and then not Is_Abstract_Type (Typ)
5668 and then not Is_Controlled (Typ)
5669 and then not Restriction_Active (No_Dispatching_Calls)
5670 and then not Restriction_Active (No_Select_Statements)
5671 then
5672 Append_To (Result,
5673 Make_Object_Declaration (Loc,
5674 Defining_Identifier => SSD,
5675 Aliased_Present => True,
5676 Object_Definition =>
5677 Make_Subtype_Indication (Loc,
5678 Subtype_Mark => New_Occurrence_Of (
5679 RTE (RE_Select_Specific_Data), Loc),
5680 Constraint =>
5681 Make_Index_Or_Discriminant_Constraint (Loc,
5682 Constraints => New_List (
5683 Make_Integer_Literal (Loc, Nb_Prim))))));
5685 Append_To (Result,
5686 Make_Attribute_Definition_Clause (Loc,
5687 Name => New_Occurrence_Of (SSD, Loc),
5688 Chars => Name_Alignment,
5689 Expression =>
5690 Make_Attribute_Reference (Loc,
5691 Prefix =>
5692 New_Occurrence_Of (RTE (RE_Integer_Address), Loc),
5693 Attribute_Name => Name_Alignment)));
5695 -- This table is initialized by Make_Select_Specific_Data_Table,
5696 -- which calls Set_Entry_Index and Set_Prim_Op_Kind.
5698 Append_To (TSD_Aggr_List,
5699 Make_Attribute_Reference (Loc,
5700 Prefix => New_Occurrence_Of (SSD, Loc),
5701 Attribute_Name => Name_Unchecked_Access));
5702 else
5703 Append_To (TSD_Aggr_List, Make_Null (Loc));
5704 end if;
5705 end if;
5707 -- Initialize the table of ancestor tags. In case of interface types
5708 -- this table is not needed.
5710 TSD_Tags_List := New_List;
5712 -- If we are not statically allocating the dispatch table then we must
5713 -- fill position 0 with null because we still have not generated the
5714 -- tag of Typ.
5716 if not Building_Static_DT (Typ)
5717 or else Is_Interface (Typ)
5718 then
5719 Append_To (TSD_Tags_List,
5720 Unchecked_Convert_To (RTE (RE_Tag),
5721 New_Occurrence_Of (RTE (RE_Null_Address), Loc)));
5723 -- Otherwise we can safely reference the tag
5725 else
5726 Append_To (TSD_Tags_List,
5727 New_Occurrence_Of (DT_Ptr, Loc));
5728 end if;
5730 -- Fill the rest of the table with the tags of the ancestors
5732 declare
5733 Current_Typ : Entity_Id;
5734 Parent_Typ : Entity_Id;
5735 Pos : Nat;
5737 begin
5738 Pos := 1;
5739 Current_Typ := Typ;
5741 loop
5742 Parent_Typ := Etype (Current_Typ);
5744 if Is_Private_Type (Parent_Typ) then
5745 Parent_Typ := Full_View (Base_Type (Parent_Typ));
5746 end if;
5748 exit when Parent_Typ = Current_Typ;
5750 if Is_CPP_Class (Parent_Typ) then
5752 -- The tags defined in the C++ side will be inherited when
5753 -- the object is constructed (Exp_Ch3.Build_Init_Procedure)
5755 Append_To (TSD_Tags_List,
5756 Unchecked_Convert_To (RTE (RE_Tag),
5757 New_Occurrence_Of (RTE (RE_Null_Address), Loc)));
5758 else
5759 Append_To (TSD_Tags_List,
5760 New_Occurrence_Of
5761 (Node (First_Elmt (Access_Disp_Table (Parent_Typ))),
5762 Loc));
5763 end if;
5765 Pos := Pos + 1;
5766 Current_Typ := Parent_Typ;
5767 end loop;
5769 pragma Assert (Pos = I_Depth + 1);
5770 end;
5772 Append_To (TSD_Aggr_List,
5773 Make_Aggregate (Loc,
5774 Expressions => TSD_Tags_List));
5776 -- Build the TSD object
5778 Append_To (Result,
5779 Make_Object_Declaration (Loc,
5780 Defining_Identifier => TSD,
5781 Aliased_Present => True,
5782 Constant_Present => Building_Static_DT (Typ),
5783 Object_Definition =>
5784 Make_Subtype_Indication (Loc,
5785 Subtype_Mark => New_Occurrence_Of (
5786 RTE (RE_Type_Specific_Data), Loc),
5787 Constraint =>
5788 Make_Index_Or_Discriminant_Constraint (Loc,
5789 Constraints => New_List (
5790 Make_Integer_Literal (Loc, I_Depth)))),
5792 Expression => Make_Aggregate (Loc,
5793 Expressions => TSD_Aggr_List)));
5795 Set_Is_True_Constant (TSD, Building_Static_DT (Typ));
5797 Append_To (Result,
5798 Make_Attribute_Definition_Clause (Loc,
5799 Name => New_Occurrence_Of (TSD, Loc),
5800 Chars => Name_Alignment,
5801 Expression =>
5802 Make_Attribute_Reference (Loc,
5803 Prefix =>
5804 New_Occurrence_Of (RTE (RE_Integer_Address), Loc),
5805 Attribute_Name => Name_Alignment)));
5807 -- Initialize or declare the dispatch table object
5809 if not Has_DT (Typ) then
5810 DT_Constr_List := New_List;
5811 DT_Aggr_List := New_List;
5813 -- Typeinfo
5815 New_Node :=
5816 Make_Attribute_Reference (Loc,
5817 Prefix => New_Occurrence_Of (TSD, Loc),
5818 Attribute_Name => Name_Address);
5820 Append_To (DT_Constr_List, New_Node);
5821 Append_To (DT_Aggr_List, New_Copy (New_Node));
5822 Append_To (DT_Aggr_List, Make_Integer_Literal (Loc, 0));
5824 -- In case of locally defined tagged types we have already declared
5825 -- and uninitialized object for the dispatch table, which is now
5826 -- initialized by means of the following assignment:
5828 -- DT := (TSD'Address, 0);
5830 if not Building_Static_DT (Typ) then
5831 Append_To (Result,
5832 Make_Assignment_Statement (Loc,
5833 Name => New_Occurrence_Of (DT, Loc),
5834 Expression => Make_Aggregate (Loc, DT_Aggr_List)));
5836 -- In case of library level tagged types we declare and export now
5837 -- the constant object containing the dummy dispatch table. There
5838 -- is no need to declare the tag here because it has been previously
5839 -- declared by Make_Tags
5841 -- DT : aliased constant No_Dispatch_Table :=
5842 -- (NDT_TSD => TSD'Address;
5843 -- NDT_Prims_Ptr => 0);
5844 -- for DT'Alignment use Address'Alignment;
5846 else
5847 Append_To (Result,
5848 Make_Object_Declaration (Loc,
5849 Defining_Identifier => DT,
5850 Aliased_Present => True,
5851 Constant_Present => True,
5852 Object_Definition =>
5853 New_Occurrence_Of (RTE (RE_No_Dispatch_Table_Wrapper), Loc),
5854 Expression => Make_Aggregate (Loc, DT_Aggr_List)));
5856 Append_To (Result,
5857 Make_Attribute_Definition_Clause (Loc,
5858 Name => New_Occurrence_Of (DT, Loc),
5859 Chars => Name_Alignment,
5860 Expression =>
5861 Make_Attribute_Reference (Loc,
5862 Prefix =>
5863 New_Occurrence_Of (RTE (RE_Integer_Address), Loc),
5864 Attribute_Name => Name_Alignment)));
5866 Export_DT (Typ, DT);
5867 end if;
5869 -- Common case: Typ has a dispatch table
5871 -- Generate:
5873 -- Predef_Prims : Address_Array (1 .. Default_Prim_Ops_Count) :=
5874 -- (predef-prim-op-1'address,
5875 -- predef-prim-op-2'address,
5876 -- ...
5877 -- predef-prim-op-n'address);
5878 -- for Predef_Prims'Alignment use Address'Alignment
5880 -- DT : Dispatch_Table (Nb_Prims) :=
5881 -- (Signature => <sig-value>,
5882 -- Tag_Kind => <tag_kind-value>,
5883 -- Predef_Prims => Predef_Prims'First'Address,
5884 -- Offset_To_Top => 0,
5885 -- TSD => TSD'Address;
5886 -- Prims_Ptr => (prim-op-1'address,
5887 -- prim-op-2'address,
5888 -- ...
5889 -- prim-op-n'address));
5890 -- for DT'Alignment use Address'Alignment
5892 else
5893 declare
5894 Pos : Nat;
5896 begin
5897 if not Building_Static_DT (Typ) then
5898 Nb_Predef_Prims := Max_Predef_Prims;
5900 else
5901 Prim_Elmt := First_Elmt (Primitive_Operations (Typ));
5902 while Present (Prim_Elmt) loop
5903 Prim := Node (Prim_Elmt);
5905 if Is_Predefined_Dispatching_Operation (Prim)
5906 and then not Is_Abstract_Subprogram (Prim)
5907 then
5908 Pos := UI_To_Int (DT_Position (Prim));
5910 if Pos > Nb_Predef_Prims then
5911 Nb_Predef_Prims := Pos;
5912 end if;
5913 end if;
5915 Next_Elmt (Prim_Elmt);
5916 end loop;
5917 end if;
5919 declare
5920 Prim_Table : array
5921 (Nat range 1 .. Nb_Predef_Prims) of Entity_Id;
5922 Decl : Node_Id;
5923 E : Entity_Id;
5925 begin
5926 Prim_Ops_Aggr_List := New_List;
5928 Prim_Table := (others => Empty);
5930 if Building_Static_DT (Typ) then
5931 Prim_Elmt := First_Elmt (Primitive_Operations (Typ));
5932 while Present (Prim_Elmt) loop
5933 Prim := Node (Prim_Elmt);
5935 if Is_Predefined_Dispatching_Operation (Prim)
5936 and then not Is_Abstract_Subprogram (Prim)
5937 and then not Is_Eliminated (Prim)
5938 and then not Present (Prim_Table
5939 (UI_To_Int (DT_Position (Prim))))
5940 then
5941 E := Ultimate_Alias (Prim);
5942 pragma Assert (not Is_Abstract_Subprogram (E));
5943 Prim_Table (UI_To_Int (DT_Position (Prim))) := E;
5944 end if;
5946 Next_Elmt (Prim_Elmt);
5947 end loop;
5948 end if;
5950 for J in Prim_Table'Range loop
5951 if Present (Prim_Table (J)) then
5952 New_Node :=
5953 Unchecked_Convert_To (RTE (RE_Prim_Ptr),
5954 Make_Attribute_Reference (Loc,
5955 Prefix =>
5956 New_Occurrence_Of (Prim_Table (J), Loc),
5957 Attribute_Name => Name_Unrestricted_Access));
5958 else
5959 New_Node := Make_Null (Loc);
5960 end if;
5962 Append_To (Prim_Ops_Aggr_List, New_Node);
5963 end loop;
5965 New_Node :=
5966 Make_Aggregate (Loc,
5967 Expressions => Prim_Ops_Aggr_List);
5969 Decl :=
5970 Make_Subtype_Declaration (Loc,
5971 Defining_Identifier => Make_Temporary (Loc, 'S'),
5972 Subtype_Indication =>
5973 New_Occurrence_Of (RTE (RE_Address_Array), Loc));
5975 Append_To (Result, Decl);
5977 Append_To (Result,
5978 Make_Object_Declaration (Loc,
5979 Defining_Identifier => Predef_Prims,
5980 Aliased_Present => True,
5981 Constant_Present => Building_Static_DT (Typ),
5982 Object_Definition =>
5983 New_Occurrence_Of (Defining_Identifier (Decl), Loc),
5984 Expression => New_Node));
5986 -- Remember aggregates initializing dispatch tables
5988 Append_Elmt (New_Node, DT_Aggr);
5990 Append_To (Result,
5991 Make_Attribute_Definition_Clause (Loc,
5992 Name => New_Occurrence_Of (Predef_Prims, Loc),
5993 Chars => Name_Alignment,
5994 Expression =>
5995 Make_Attribute_Reference (Loc,
5996 Prefix =>
5997 New_Occurrence_Of (RTE (RE_Integer_Address), Loc),
5998 Attribute_Name => Name_Alignment)));
5999 end;
6000 end;
6002 -- Stage 1: Initialize the discriminant and the record components
6004 DT_Constr_List := New_List;
6005 DT_Aggr_List := New_List;
6007 -- Num_Prims. If the tagged type has no primitives we add a dummy
6008 -- slot whose address will be the tag of this type.
6010 if Nb_Prim = 0 then
6011 New_Node := Make_Integer_Literal (Loc, 1);
6012 else
6013 New_Node := Make_Integer_Literal (Loc, Nb_Prim);
6014 end if;
6016 Append_To (DT_Constr_List, New_Node);
6017 Append_To (DT_Aggr_List, New_Copy (New_Node));
6019 -- Signature
6021 if RTE_Record_Component_Available (RE_Signature) then
6022 Append_To (DT_Aggr_List,
6023 New_Occurrence_Of (RTE (RE_Primary_DT), Loc));
6024 end if;
6026 -- Tag_Kind
6028 if RTE_Record_Component_Available (RE_Tag_Kind) then
6029 Append_To (DT_Aggr_List, Tagged_Kind (Typ));
6030 end if;
6032 -- Predef_Prims
6034 Append_To (DT_Aggr_List,
6035 Make_Attribute_Reference (Loc,
6036 Prefix => New_Occurrence_Of (Predef_Prims, Loc),
6037 Attribute_Name => Name_Address));
6039 -- Offset_To_Top
6041 Append_To (DT_Aggr_List, Make_Integer_Literal (Loc, 0));
6043 -- Typeinfo
6045 Append_To (DT_Aggr_List,
6046 Make_Attribute_Reference (Loc,
6047 Prefix => New_Occurrence_Of (TSD, Loc),
6048 Attribute_Name => Name_Address));
6050 -- Stage 2: Initialize the table of user-defined primitive operations
6052 Prim_Ops_Aggr_List := New_List;
6054 if Nb_Prim = 0 then
6055 Append_To (Prim_Ops_Aggr_List, Make_Null (Loc));
6057 elsif not Building_Static_DT (Typ) then
6058 for J in 1 .. Nb_Prim loop
6059 Append_To (Prim_Ops_Aggr_List, Make_Null (Loc));
6060 end loop;
6062 else
6063 declare
6064 CPP_Nb_Prims : constant Nat := CPP_Num_Prims (Typ);
6065 E : Entity_Id;
6066 Prim : Entity_Id;
6067 Prim_Elmt : Elmt_Id;
6068 Prim_Pos : Nat;
6069 Prim_Table : array (Nat range 1 .. Nb_Prim) of Entity_Id;
6071 begin
6072 Prim_Table := (others => Empty);
6074 Prim_Elmt := First_Elmt (Primitive_Operations (Typ));
6075 while Present (Prim_Elmt) loop
6076 Prim := Node (Prim_Elmt);
6078 -- Retrieve the ultimate alias of the primitive for proper
6079 -- handling of renamings and eliminated primitives.
6081 E := Ultimate_Alias (Prim);
6083 -- If the alias is not a primitive operation then Prim does
6084 -- not rename another primitive, but rather an operation
6085 -- declared elsewhere (e.g. in another scope) and therefore
6086 -- Prim is a new primitive.
6088 if No (Find_Dispatching_Type (E)) then
6089 E := Prim;
6090 end if;
6092 Prim_Pos := UI_To_Int (DT_Position (E));
6094 -- Skip predefined primitives because they are located in a
6095 -- separate dispatch table.
6097 if not Is_Predefined_Dispatching_Operation (Prim)
6098 and then not Is_Predefined_Dispatching_Operation (E)
6100 -- Skip entities with attribute Interface_Alias because
6101 -- those are only required to build secondary dispatch
6102 -- tables.
6104 and then not Present (Interface_Alias (Prim))
6106 -- Skip abstract and eliminated primitives
6108 and then not Is_Abstract_Subprogram (E)
6109 and then not Is_Eliminated (E)
6111 -- For derivations of CPP types skip primitives located in
6112 -- the C++ part of the dispatch table because their slots
6113 -- are initialized by the IC routine.
6115 and then (not Is_CPP_Class (Root_Type (Typ))
6116 or else Prim_Pos > CPP_Nb_Prims)
6118 -- Skip ignored Ghost subprograms as those will be removed
6119 -- from the executable.
6121 and then not Is_Ignored_Ghost_Entity (E)
6122 then
6123 pragma Assert
6124 (UI_To_Int (DT_Position (Prim)) <= Nb_Prim);
6126 Prim_Table (UI_To_Int (DT_Position (Prim))) := E;
6127 end if;
6129 Next_Elmt (Prim_Elmt);
6130 end loop;
6132 for J in Prim_Table'Range loop
6133 if Present (Prim_Table (J)) then
6134 New_Node :=
6135 Unchecked_Convert_To (RTE (RE_Prim_Ptr),
6136 Make_Attribute_Reference (Loc,
6137 Prefix =>
6138 New_Occurrence_Of (Prim_Table (J), Loc),
6139 Attribute_Name => Name_Unrestricted_Access));
6140 else
6141 New_Node := Make_Null (Loc);
6142 end if;
6144 Append_To (Prim_Ops_Aggr_List, New_Node);
6145 end loop;
6146 end;
6147 end if;
6149 New_Node :=
6150 Make_Aggregate (Loc,
6151 Expressions => Prim_Ops_Aggr_List);
6153 Append_To (DT_Aggr_List, New_Node);
6155 -- Remember aggregates initializing dispatch tables
6157 Append_Elmt (New_Node, DT_Aggr);
6159 -- In case of locally defined tagged types we have already declared
6160 -- and uninitialized object for the dispatch table, which is now
6161 -- initialized by means of an assignment.
6163 if not Building_Static_DT (Typ) then
6164 Append_To (Result,
6165 Make_Assignment_Statement (Loc,
6166 Name => New_Occurrence_Of (DT, Loc),
6167 Expression => Make_Aggregate (Loc, DT_Aggr_List)));
6169 -- In case of library level tagged types we declare now and export
6170 -- the constant object containing the dispatch table.
6172 else
6173 Append_To (Result,
6174 Make_Object_Declaration (Loc,
6175 Defining_Identifier => DT,
6176 Aliased_Present => True,
6177 Constant_Present => True,
6178 Object_Definition =>
6179 Make_Subtype_Indication (Loc,
6180 Subtype_Mark => New_Occurrence_Of
6181 (RTE (RE_Dispatch_Table_Wrapper), Loc),
6182 Constraint => Make_Index_Or_Discriminant_Constraint (Loc,
6183 Constraints => DT_Constr_List)),
6184 Expression => Make_Aggregate (Loc, DT_Aggr_List)));
6186 Append_To (Result,
6187 Make_Attribute_Definition_Clause (Loc,
6188 Name => New_Occurrence_Of (DT, Loc),
6189 Chars => Name_Alignment,
6190 Expression =>
6191 Make_Attribute_Reference (Loc,
6192 Prefix =>
6193 New_Occurrence_Of (RTE (RE_Integer_Address), Loc),
6194 Attribute_Name => Name_Alignment)));
6196 Export_DT (Typ, DT);
6197 end if;
6198 end if;
6200 -- Initialize the table of ancestor tags if not building static
6201 -- dispatch table
6203 if not Building_Static_DT (Typ)
6204 and then not Is_Interface (Typ)
6205 and then not Is_CPP_Class (Typ)
6206 then
6207 Append_To (Result,
6208 Make_Assignment_Statement (Loc,
6209 Name =>
6210 Make_Indexed_Component (Loc,
6211 Prefix =>
6212 Make_Selected_Component (Loc,
6213 Prefix => New_Occurrence_Of (TSD, Loc),
6214 Selector_Name =>
6215 New_Occurrence_Of
6216 (RTE_Record_Component (RE_Tags_Table), Loc)),
6217 Expressions =>
6218 New_List (Make_Integer_Literal (Loc, 0))),
6220 Expression =>
6221 New_Occurrence_Of
6222 (Node (First_Elmt (Access_Disp_Table (Typ))), Loc)));
6223 end if;
6225 -- Inherit the dispatch tables of the parent. There is no need to
6226 -- inherit anything from the parent when building static dispatch tables
6227 -- because the whole dispatch table (including inherited primitives) has
6228 -- been already built.
6230 if Building_Static_DT (Typ) then
6231 null;
6233 -- If the ancestor is a CPP_Class type we inherit the dispatch tables
6234 -- in the init proc, and we don't need to fill them in here.
6236 elsif Is_CPP_Class (Parent_Typ) then
6237 null;
6239 -- Otherwise we fill in the dispatch tables here
6241 else
6242 if Typ /= Parent_Typ
6243 and then not Is_Interface (Typ)
6244 and then not Restriction_Active (No_Dispatching_Calls)
6245 then
6246 -- Inherit the dispatch table
6248 if not Is_Interface (Typ)
6249 and then not Is_Interface (Parent_Typ)
6250 and then not Is_CPP_Class (Parent_Typ)
6251 then
6252 declare
6253 Nb_Prims : constant Int :=
6254 UI_To_Int (DT_Entry_Count
6255 (First_Tag_Component (Parent_Typ)));
6257 begin
6258 Append_To (Elab_Code,
6259 Build_Inherit_Predefined_Prims (Loc,
6260 Old_Tag_Node =>
6261 New_Occurrence_Of
6262 (Node
6263 (Next_Elmt
6264 (First_Elmt
6265 (Access_Disp_Table (Parent_Typ)))), Loc),
6266 New_Tag_Node =>
6267 New_Occurrence_Of
6268 (Node
6269 (Next_Elmt
6270 (First_Elmt
6271 (Access_Disp_Table (Typ)))), Loc)));
6273 if Nb_Prims /= 0 then
6274 Append_To (Elab_Code,
6275 Build_Inherit_Prims (Loc,
6276 Typ => Typ,
6277 Old_Tag_Node =>
6278 New_Occurrence_Of
6279 (Node
6280 (First_Elmt
6281 (Access_Disp_Table (Parent_Typ))), Loc),
6282 New_Tag_Node => New_Occurrence_Of (DT_Ptr, Loc),
6283 Num_Prims => Nb_Prims));
6284 end if;
6285 end;
6286 end if;
6288 -- Inherit the secondary dispatch tables of the ancestor
6290 if not Is_CPP_Class (Parent_Typ) then
6291 declare
6292 Sec_DT_Ancestor : Elmt_Id :=
6293 Next_Elmt
6294 (Next_Elmt
6295 (First_Elmt
6296 (Access_Disp_Table
6297 (Parent_Typ))));
6298 Sec_DT_Typ : Elmt_Id :=
6299 Next_Elmt
6300 (Next_Elmt
6301 (First_Elmt
6302 (Access_Disp_Table (Typ))));
6304 procedure Copy_Secondary_DTs (Typ : Entity_Id);
6305 -- Local procedure required to climb through the ancestors
6306 -- and copy the contents of all their secondary dispatch
6307 -- tables.
6309 ------------------------
6310 -- Copy_Secondary_DTs --
6311 ------------------------
6313 procedure Copy_Secondary_DTs (Typ : Entity_Id) is
6314 E : Entity_Id;
6315 Iface : Elmt_Id;
6317 begin
6318 -- Climb to the ancestor (if any) handling private types
6320 if Present (Full_View (Etype (Typ))) then
6321 if Full_View (Etype (Typ)) /= Typ then
6322 Copy_Secondary_DTs (Full_View (Etype (Typ)));
6323 end if;
6325 elsif Etype (Typ) /= Typ then
6326 Copy_Secondary_DTs (Etype (Typ));
6327 end if;
6329 if Present (Interfaces (Typ))
6330 and then not Is_Empty_Elmt_List (Interfaces (Typ))
6331 then
6332 Iface := First_Elmt (Interfaces (Typ));
6333 E := First_Entity (Typ);
6334 while Present (E)
6335 and then Present (Node (Sec_DT_Ancestor))
6336 and then Ekind (Node (Sec_DT_Ancestor)) = E_Constant
6337 loop
6338 if Is_Tag (E) and then Chars (E) /= Name_uTag then
6339 declare
6340 Num_Prims : constant Int :=
6341 UI_To_Int (DT_Entry_Count (E));
6343 begin
6344 if not Is_Interface (Etype (Typ)) then
6346 -- Inherit first secondary dispatch table
6348 Append_To (Elab_Code,
6349 Build_Inherit_Predefined_Prims (Loc,
6350 Old_Tag_Node =>
6351 Unchecked_Convert_To (RTE (RE_Tag),
6352 New_Occurrence_Of
6353 (Node
6354 (Next_Elmt (Sec_DT_Ancestor)),
6355 Loc)),
6356 New_Tag_Node =>
6357 Unchecked_Convert_To (RTE (RE_Tag),
6358 New_Occurrence_Of
6359 (Node (Next_Elmt (Sec_DT_Typ)),
6360 Loc))));
6362 if Num_Prims /= 0 then
6363 Append_To (Elab_Code,
6364 Build_Inherit_Prims (Loc,
6365 Typ => Node (Iface),
6366 Old_Tag_Node =>
6367 Unchecked_Convert_To
6368 (RTE (RE_Tag),
6369 New_Occurrence_Of
6370 (Node (Sec_DT_Ancestor),
6371 Loc)),
6372 New_Tag_Node =>
6373 Unchecked_Convert_To
6374 (RTE (RE_Tag),
6375 New_Occurrence_Of
6376 (Node (Sec_DT_Typ), Loc)),
6377 Num_Prims => Num_Prims));
6378 end if;
6379 end if;
6381 Next_Elmt (Sec_DT_Ancestor);
6382 Next_Elmt (Sec_DT_Typ);
6384 -- Skip the secondary dispatch table of
6385 -- predefined primitives
6387 Next_Elmt (Sec_DT_Ancestor);
6388 Next_Elmt (Sec_DT_Typ);
6390 if not Is_Interface (Etype (Typ)) then
6392 -- Inherit second secondary dispatch table
6394 Append_To (Elab_Code,
6395 Build_Inherit_Predefined_Prims (Loc,
6396 Old_Tag_Node =>
6397 Unchecked_Convert_To (RTE (RE_Tag),
6398 New_Occurrence_Of
6399 (Node
6400 (Next_Elmt (Sec_DT_Ancestor)),
6401 Loc)),
6402 New_Tag_Node =>
6403 Unchecked_Convert_To (RTE (RE_Tag),
6404 New_Occurrence_Of
6405 (Node (Next_Elmt (Sec_DT_Typ)),
6406 Loc))));
6408 if Num_Prims /= 0 then
6409 Append_To (Elab_Code,
6410 Build_Inherit_Prims (Loc,
6411 Typ => Node (Iface),
6412 Old_Tag_Node =>
6413 Unchecked_Convert_To
6414 (RTE (RE_Tag),
6415 New_Occurrence_Of
6416 (Node (Sec_DT_Ancestor),
6417 Loc)),
6418 New_Tag_Node =>
6419 Unchecked_Convert_To
6420 (RTE (RE_Tag),
6421 New_Occurrence_Of
6422 (Node (Sec_DT_Typ), Loc)),
6423 Num_Prims => Num_Prims));
6424 end if;
6425 end if;
6426 end;
6428 Next_Elmt (Sec_DT_Ancestor);
6429 Next_Elmt (Sec_DT_Typ);
6431 -- Skip the secondary dispatch table of
6432 -- predefined primitives
6434 Next_Elmt (Sec_DT_Ancestor);
6435 Next_Elmt (Sec_DT_Typ);
6437 Next_Elmt (Iface);
6438 end if;
6440 Next_Entity (E);
6441 end loop;
6442 end if;
6443 end Copy_Secondary_DTs;
6445 begin
6446 if Present (Node (Sec_DT_Ancestor))
6447 and then Ekind (Node (Sec_DT_Ancestor)) = E_Constant
6448 then
6449 -- Handle private types
6451 if Present (Full_View (Typ)) then
6452 Copy_Secondary_DTs (Full_View (Typ));
6453 else
6454 Copy_Secondary_DTs (Typ);
6455 end if;
6456 end if;
6457 end;
6458 end if;
6459 end if;
6460 end if;
6462 -- Generate code to check if the external tag of this type is the same
6463 -- as the external tag of some other declaration.
6465 -- Check_TSD (TSD'Unrestricted_Access);
6467 -- This check is a consequence of AI05-0113-1/06, so it officially
6468 -- applies to Ada 2005 (and Ada 2012). It might be argued that it is
6469 -- a desirable check to add in Ada 95 mode, but we hesitate to make
6470 -- this change, as it would be incompatible, and could conceivably
6471 -- cause a problem in existing Ada 95 code.
6473 -- We check for No_Run_Time_Mode here, because we do not want to pick
6474 -- up the RE_Check_TSD entity and call it in No_Run_Time mode.
6476 -- We cannot perform this check if the generation of its expanded name
6477 -- was discarded.
6479 if not No_Run_Time_Mode
6480 and then not Discard_Names
6481 and then Ada_Version >= Ada_2005
6482 and then RTE_Available (RE_Check_TSD)
6483 and then not Duplicated_Tag_Checks_Suppressed (Typ)
6484 then
6485 Append_To (Elab_Code,
6486 Make_Procedure_Call_Statement (Loc,
6487 Name =>
6488 New_Occurrence_Of (RTE (RE_Check_TSD), Loc),
6489 Parameter_Associations => New_List (
6490 Make_Attribute_Reference (Loc,
6491 Prefix => New_Occurrence_Of (TSD, Loc),
6492 Attribute_Name => Name_Unchecked_Access))));
6493 end if;
6495 -- Generate code to register the Tag in the External_Tag hash table for
6496 -- the pure Ada type only.
6498 -- Register_Tag (Dt_Ptr);
6500 -- Skip this action in the following cases:
6501 -- 1) if Register_Tag is not available.
6502 -- 2) in No_Run_Time mode.
6503 -- 3) if Typ is not defined at the library level (this is required
6504 -- to avoid adding concurrency control to the hash table used
6505 -- by the run-time to register the tags).
6507 if not No_Run_Time_Mode
6508 and then Is_Library_Level_Entity (Typ)
6509 and then RTE_Available (RE_Register_Tag)
6510 then
6511 Append_To (Elab_Code,
6512 Make_Procedure_Call_Statement (Loc,
6513 Name =>
6514 New_Occurrence_Of (RTE (RE_Register_Tag), Loc),
6515 Parameter_Associations =>
6516 New_List (New_Occurrence_Of (DT_Ptr, Loc))));
6517 end if;
6519 if not Is_Empty_List (Elab_Code) then
6520 Append_List_To (Result, Elab_Code);
6521 end if;
6523 -- Populate the two auxiliary tables used for dispatching asynchronous,
6524 -- conditional and timed selects for synchronized types that implement
6525 -- a limited interface. Skip this step in Ravenscar profile or when
6526 -- general dispatching is forbidden.
6528 if Ada_Version >= Ada_2005
6529 and then Is_Concurrent_Record_Type (Typ)
6530 and then Has_Interfaces (Typ)
6531 and then not Restriction_Active (No_Dispatching_Calls)
6532 and then not Restriction_Active (No_Select_Statements)
6533 then
6534 Append_List_To (Result,
6535 Make_Select_Specific_Data_Table (Typ));
6536 end if;
6538 -- Remember entities containing dispatch tables
6540 Append_Elmt (Predef_Prims, DT_Decl);
6541 Append_Elmt (DT, DT_Decl);
6543 Analyze_List (Result, Suppress => All_Checks);
6544 Set_Has_Dispatch_Table (Typ);
6546 -- Mark entities containing dispatch tables. Required by the backend to
6547 -- handle them properly.
6549 if Has_DT (Typ) then
6550 declare
6551 Elmt : Elmt_Id;
6553 begin
6554 -- Object declarations
6556 Elmt := First_Elmt (DT_Decl);
6557 while Present (Elmt) loop
6558 Set_Is_Dispatch_Table_Entity (Node (Elmt));
6559 pragma Assert (Ekind (Etype (Node (Elmt))) = E_Array_Subtype
6560 or else Ekind (Etype (Node (Elmt))) = E_Record_Subtype);
6561 Set_Is_Dispatch_Table_Entity (Etype (Node (Elmt)));
6562 Next_Elmt (Elmt);
6563 end loop;
6565 -- Aggregates initializing dispatch tables
6567 Elmt := First_Elmt (DT_Aggr);
6568 while Present (Elmt) loop
6569 Set_Is_Dispatch_Table_Entity (Etype (Node (Elmt)));
6570 Next_Elmt (Elmt);
6571 end loop;
6572 end;
6573 end if;
6575 <<Leave_SCIL>>
6577 -- Register the tagged type in the call graph nodes table
6579 Register_CG_Node (Typ);
6581 <<Leave>>
6582 Restore_Ghost_Region (Saved_GM, Saved_IGR);
6584 return Result;
6585 end Make_DT;
6587 -------------------------------------
6588 -- Make_Select_Specific_Data_Table --
6589 -------------------------------------
6591 function Make_Select_Specific_Data_Table
6592 (Typ : Entity_Id) return List_Id
6594 Assignments : constant List_Id := New_List;
6595 Loc : constant Source_Ptr := Sloc (Typ);
6597 Conc_Typ : Entity_Id;
6598 Decls : List_Id := No_List;
6599 Prim : Entity_Id;
6600 Prim_Als : Entity_Id;
6601 Prim_Elmt : Elmt_Id;
6602 Prim_Pos : Uint;
6603 Nb_Prim : Nat := 0;
6605 type Examined_Array is array (Int range <>) of Boolean;
6607 function Find_Entry_Index (E : Entity_Id) return Uint;
6608 -- Given an entry, find its index in the visible declarations of the
6609 -- corresponding concurrent type of Typ.
6611 ----------------------
6612 -- Find_Entry_Index --
6613 ----------------------
6615 function Find_Entry_Index (E : Entity_Id) return Uint is
6616 Index : Uint := Uint_1;
6617 Subp_Decl : Entity_Id;
6619 begin
6620 if Present (Decls)
6621 and then not Is_Empty_List (Decls)
6622 then
6623 Subp_Decl := First (Decls);
6624 while Present (Subp_Decl) loop
6625 if Nkind (Subp_Decl) = N_Entry_Declaration then
6626 if Defining_Identifier (Subp_Decl) = E then
6627 return Index;
6628 end if;
6630 Index := Index + 1;
6631 end if;
6633 Next (Subp_Decl);
6634 end loop;
6635 end if;
6637 return Uint_0;
6638 end Find_Entry_Index;
6640 -- Local variables
6642 Tag_Node : Node_Id;
6644 -- Start of processing for Make_Select_Specific_Data_Table
6646 begin
6647 pragma Assert (not Restriction_Active (No_Dispatching_Calls));
6649 if Present (Corresponding_Concurrent_Type (Typ)) then
6650 Conc_Typ := Corresponding_Concurrent_Type (Typ);
6652 if Present (Full_View (Conc_Typ)) then
6653 Conc_Typ := Full_View (Conc_Typ);
6654 end if;
6656 if Ekind (Conc_Typ) = E_Protected_Type then
6657 Decls := Visible_Declarations (Protected_Definition (
6658 Parent (Conc_Typ)));
6659 else
6660 pragma Assert (Ekind (Conc_Typ) = E_Task_Type);
6661 Decls := Visible_Declarations (Task_Definition (
6662 Parent (Conc_Typ)));
6663 end if;
6664 end if;
6666 -- Count the non-predefined primitive operations
6668 Prim_Elmt := First_Elmt (Primitive_Operations (Typ));
6669 while Present (Prim_Elmt) loop
6670 Prim := Node (Prim_Elmt);
6672 if not (Is_Predefined_Dispatching_Operation (Prim)
6673 or else Is_Predefined_Dispatching_Alias (Prim))
6674 then
6675 Nb_Prim := Nb_Prim + 1;
6676 end if;
6678 Next_Elmt (Prim_Elmt);
6679 end loop;
6681 declare
6682 Examined : Examined_Array (1 .. Nb_Prim) := (others => False);
6684 begin
6685 Prim_Elmt := First_Elmt (Primitive_Operations (Typ));
6686 while Present (Prim_Elmt) loop
6687 Prim := Node (Prim_Elmt);
6689 -- Look for primitive overriding an abstract interface subprogram
6691 if Present (Interface_Alias (Prim))
6692 and then not
6693 Is_Ancestor
6694 (Find_Dispatching_Type (Interface_Alias (Prim)), Typ,
6695 Use_Full_View => True)
6696 and then not Examined (UI_To_Int (DT_Position (Alias (Prim))))
6697 then
6698 Prim_Pos := DT_Position (Alias (Prim));
6699 pragma Assert (UI_To_Int (Prim_Pos) <= Nb_Prim);
6700 Examined (UI_To_Int (Prim_Pos)) := True;
6702 -- Set the primitive operation kind regardless of subprogram
6703 -- type. Generate:
6704 -- Ada.Tags.Set_Prim_Op_Kind (DT_Ptr, <position>, <kind>);
6706 if Tagged_Type_Expansion then
6707 Tag_Node :=
6708 New_Occurrence_Of
6709 (Node (First_Elmt (Access_Disp_Table (Typ))), Loc);
6711 else
6712 Tag_Node :=
6713 Make_Attribute_Reference (Loc,
6714 Prefix => New_Occurrence_Of (Typ, Loc),
6715 Attribute_Name => Name_Tag);
6716 end if;
6718 Append_To (Assignments,
6719 Make_Procedure_Call_Statement (Loc,
6720 Name => New_Occurrence_Of (RTE (RE_Set_Prim_Op_Kind), Loc),
6721 Parameter_Associations => New_List (
6722 Tag_Node,
6723 Make_Integer_Literal (Loc, Prim_Pos),
6724 Prim_Op_Kind (Alias (Prim), Typ))));
6726 -- Retrieve the root of the alias chain
6728 Prim_Als := Ultimate_Alias (Prim);
6730 -- In the case of an entry wrapper, set the entry index
6732 if Ekind (Prim) = E_Procedure
6733 and then Is_Primitive_Wrapper (Prim_Als)
6734 and then Ekind (Wrapped_Entity (Prim_Als)) = E_Entry
6735 then
6736 -- Generate:
6737 -- Ada.Tags.Set_Entry_Index
6738 -- (DT_Ptr, <position>, <index>);
6740 if Tagged_Type_Expansion then
6741 Tag_Node :=
6742 New_Occurrence_Of
6743 (Node (First_Elmt (Access_Disp_Table (Typ))), Loc);
6744 else
6745 Tag_Node :=
6746 Make_Attribute_Reference (Loc,
6747 Prefix => New_Occurrence_Of (Typ, Loc),
6748 Attribute_Name => Name_Tag);
6749 end if;
6751 Append_To (Assignments,
6752 Make_Procedure_Call_Statement (Loc,
6753 Name =>
6754 New_Occurrence_Of (RTE (RE_Set_Entry_Index), Loc),
6755 Parameter_Associations => New_List (
6756 Tag_Node,
6757 Make_Integer_Literal (Loc, Prim_Pos),
6758 Make_Integer_Literal (Loc,
6759 Find_Entry_Index (Wrapped_Entity (Prim_Als))))));
6760 end if;
6761 end if;
6763 Next_Elmt (Prim_Elmt);
6764 end loop;
6765 end;
6767 return Assignments;
6768 end Make_Select_Specific_Data_Table;
6770 ---------------
6771 -- Make_Tags --
6772 ---------------
6774 function Make_Tags (Typ : Entity_Id) return List_Id is
6775 Loc : constant Source_Ptr := Sloc (Typ);
6776 Result : constant List_Id := New_List;
6778 procedure Import_DT
6779 (Tag_Typ : Entity_Id;
6780 DT : Entity_Id;
6781 Is_Secondary_DT : Boolean);
6782 -- Import the dispatch table DT of tagged type Tag_Typ. Required to
6783 -- generate forward references and statically allocate the table. For
6784 -- primary dispatch tables that require no dispatch table generate:
6786 -- DT : static aliased constant Non_Dispatch_Table_Wrapper;
6787 -- pragma Import (Ada, DT);
6789 -- Otherwise generate:
6791 -- DT : static aliased constant Dispatch_Table_Wrapper (Nb_Prim);
6792 -- pragma Import (Ada, DT);
6794 ---------------
6795 -- Import_DT --
6796 ---------------
6798 procedure Import_DT
6799 (Tag_Typ : Entity_Id;
6800 DT : Entity_Id;
6801 Is_Secondary_DT : Boolean)
6803 DT_Constr_List : List_Id;
6804 Nb_Prim : Nat;
6806 begin
6807 Set_Is_Imported (DT);
6808 Set_Ekind (DT, E_Constant);
6809 Set_Related_Type (DT, Typ);
6811 -- The scope must be set now to call Get_External_Name
6813 Set_Scope (DT, Current_Scope);
6815 Get_External_Name (DT);
6816 Set_Interface_Name (DT,
6817 Make_String_Literal (Loc, Strval => String_From_Name_Buffer));
6819 -- Ensure proper Sprint output of this implicit importation
6821 Set_Is_Internal (DT);
6823 -- Save this entity to allow Make_DT to generate its exportation
6825 Append_Elmt (DT, Dispatch_Table_Wrappers (Typ));
6827 -- No dispatch table required
6829 if not Is_Secondary_DT and then not Has_DT (Tag_Typ) then
6830 Append_To (Result,
6831 Make_Object_Declaration (Loc,
6832 Defining_Identifier => DT,
6833 Aliased_Present => True,
6834 Constant_Present => True,
6835 Object_Definition =>
6836 New_Occurrence_Of
6837 (RTE (RE_No_Dispatch_Table_Wrapper), Loc)));
6839 else
6840 -- Calculate the number of primitives of the dispatch table and
6841 -- the size of the Type_Specific_Data record.
6843 Nb_Prim :=
6844 UI_To_Int (DT_Entry_Count (First_Tag_Component (Tag_Typ)));
6846 -- If the tagged type has no primitives we add a dummy slot whose
6847 -- address will be the tag of this type.
6849 if Nb_Prim = 0 then
6850 DT_Constr_List :=
6851 New_List (Make_Integer_Literal (Loc, 1));
6852 else
6853 DT_Constr_List :=
6854 New_List (Make_Integer_Literal (Loc, Nb_Prim));
6855 end if;
6857 Append_To (Result,
6858 Make_Object_Declaration (Loc,
6859 Defining_Identifier => DT,
6860 Aliased_Present => True,
6861 Constant_Present => True,
6862 Object_Definition =>
6863 Make_Subtype_Indication (Loc,
6864 Subtype_Mark =>
6865 New_Occurrence_Of (RTE (RE_Dispatch_Table_Wrapper), Loc),
6866 Constraint => Make_Index_Or_Discriminant_Constraint (Loc,
6867 Constraints => DT_Constr_List))));
6868 end if;
6869 end Import_DT;
6871 -- Local variables
6873 Tname : constant Name_Id := Chars (Typ);
6874 AI_Tag_Comp : Elmt_Id;
6875 DT : Node_Id := Empty;
6876 DT_Ptr : Node_Id;
6877 Predef_Prims_Ptr : Node_Id;
6878 Iface_DT : Node_Id := Empty;
6879 Iface_DT_Ptr : Node_Id;
6880 New_Node : Node_Id;
6881 Suffix_Index : Int;
6882 Typ_Name : Name_Id;
6883 Typ_Comps : Elist_Id;
6885 -- Start of processing for Make_Tags
6887 begin
6888 pragma Assert (No (Access_Disp_Table (Typ)));
6889 Set_Access_Disp_Table (Typ, New_Elmt_List);
6891 -- If the elaboration of this tagged type needs a boolean flag then
6892 -- define now its entity. It is initialized to True to indicate that
6893 -- elaboration is still pending; set to False by the IP routine.
6895 -- TypFxx : boolean := True;
6897 if Elab_Flag_Needed (Typ) then
6898 Set_Access_Disp_Table_Elab_Flag (Typ,
6899 Make_Defining_Identifier (Loc,
6900 Chars => New_External_Name (Tname, 'F')));
6902 Append_To (Result,
6903 Make_Object_Declaration (Loc,
6904 Defining_Identifier => Access_Disp_Table_Elab_Flag (Typ),
6905 Object_Definition => New_Occurrence_Of (Standard_Boolean, Loc),
6906 Expression => New_Occurrence_Of (Standard_True, Loc)));
6907 end if;
6909 -- 1) Generate the primary tag entities
6911 -- Primary dispatch table containing user-defined primitives
6913 DT_Ptr := Make_Defining_Identifier (Loc, New_External_Name (Tname, 'P'));
6914 Set_Etype (DT_Ptr, RTE (RE_Tag));
6915 Append_Elmt (DT_Ptr, Access_Disp_Table (Typ));
6917 -- Minimum decoration
6919 Set_Ekind (DT_Ptr, E_Variable);
6920 Set_Related_Type (DT_Ptr, Typ);
6922 -- Notify back end that the types are associated with a dispatch table
6924 Set_Is_Dispatch_Table_Entity (RTE (RE_Prim_Ptr));
6925 Set_Is_Dispatch_Table_Entity (RTE (RE_Predef_Prims_Table_Ptr));
6927 -- For CPP types there is no need to build the dispatch tables since
6928 -- they are imported from the C++ side. If the CPP type has an IP then
6929 -- we declare now the variable that will store the copy of the C++ tag.
6930 -- If the CPP type is an interface, we need the variable as well because
6931 -- it becomes the pointer to the corresponding secondary table.
6933 if Is_CPP_Class (Typ) then
6934 if Has_CPP_Constructors (Typ) or else Is_Interface (Typ) then
6935 Append_To (Result,
6936 Make_Object_Declaration (Loc,
6937 Defining_Identifier => DT_Ptr,
6938 Object_Definition => New_Occurrence_Of (RTE (RE_Tag), Loc),
6939 Expression =>
6940 Unchecked_Convert_To (RTE (RE_Tag),
6941 New_Occurrence_Of (RTE (RE_Null_Address), Loc))));
6943 Set_Is_Statically_Allocated (DT_Ptr,
6944 Is_Library_Level_Tagged_Type (Typ));
6945 end if;
6947 -- Ada types
6949 else
6950 -- Primary dispatch table containing predefined primitives
6952 Predef_Prims_Ptr :=
6953 Make_Defining_Identifier (Loc,
6954 Chars => New_External_Name (Tname, 'Y'));
6955 Set_Etype (Predef_Prims_Ptr, RTE (RE_Address));
6956 Append_Elmt (Predef_Prims_Ptr, Access_Disp_Table (Typ));
6958 -- Import the forward declaration of the Dispatch Table wrapper
6959 -- record (Make_DT will take care of exporting it).
6961 if Building_Static_DT (Typ) then
6962 Set_Dispatch_Table_Wrappers (Typ, New_Elmt_List);
6964 DT :=
6965 Make_Defining_Identifier (Loc,
6966 Chars => New_External_Name (Tname, 'T'));
6968 Import_DT (Typ, DT, Is_Secondary_DT => False);
6970 if Has_DT (Typ) then
6971 Append_To (Result,
6972 Make_Object_Declaration (Loc,
6973 Defining_Identifier => DT_Ptr,
6974 Constant_Present => True,
6975 Object_Definition =>
6976 New_Occurrence_Of (RTE (RE_Tag), Loc),
6977 Expression =>
6978 Unchecked_Convert_To (RTE (RE_Tag),
6979 Make_Attribute_Reference (Loc,
6980 Prefix =>
6981 Make_Selected_Component (Loc,
6982 Prefix => New_Occurrence_Of (DT, Loc),
6983 Selector_Name =>
6984 New_Occurrence_Of
6985 (RTE_Record_Component (RE_Prims_Ptr), Loc)),
6986 Attribute_Name => Name_Address))));
6988 -- Generate the SCIL node for the previous object declaration
6989 -- because it has a tag initialization.
6991 if Generate_SCIL then
6992 New_Node :=
6993 Make_SCIL_Dispatch_Table_Tag_Init (Sloc (Last (Result)));
6994 Set_SCIL_Entity (New_Node, Typ);
6995 Set_SCIL_Node (Last (Result), New_Node);
6996 end if;
6998 Append_To (Result,
6999 Make_Object_Declaration (Loc,
7000 Defining_Identifier => Predef_Prims_Ptr,
7001 Constant_Present => True,
7002 Object_Definition =>
7003 New_Occurrence_Of (RTE (RE_Address), Loc),
7004 Expression =>
7005 Make_Attribute_Reference (Loc,
7006 Prefix =>
7007 Make_Selected_Component (Loc,
7008 Prefix => New_Occurrence_Of (DT, Loc),
7009 Selector_Name =>
7010 New_Occurrence_Of
7011 (RTE_Record_Component (RE_Predef_Prims), Loc)),
7012 Attribute_Name => Name_Address)));
7014 -- No dispatch table required
7016 else
7017 Append_To (Result,
7018 Make_Object_Declaration (Loc,
7019 Defining_Identifier => DT_Ptr,
7020 Constant_Present => True,
7021 Object_Definition =>
7022 New_Occurrence_Of (RTE (RE_Tag), Loc),
7023 Expression =>
7024 Unchecked_Convert_To (RTE (RE_Tag),
7025 Make_Attribute_Reference (Loc,
7026 Prefix =>
7027 Make_Selected_Component (Loc,
7028 Prefix => New_Occurrence_Of (DT, Loc),
7029 Selector_Name =>
7030 New_Occurrence_Of
7031 (RTE_Record_Component (RE_NDT_Prims_Ptr),
7032 Loc)),
7033 Attribute_Name => Name_Address))));
7034 end if;
7036 Set_Is_True_Constant (DT_Ptr);
7037 Set_Is_Statically_Allocated (DT_Ptr);
7038 end if;
7039 end if;
7041 -- 2) Generate the secondary tag entities
7043 -- Collect the components associated with secondary dispatch tables
7045 if Has_Interfaces (Typ) then
7046 Collect_Interface_Components (Typ, Typ_Comps);
7048 -- For each interface type we build a unique external name associated
7049 -- with its secondary dispatch table. This name is used to declare an
7050 -- object that references this secondary dispatch table, whose value
7051 -- will be used for the elaboration of Typ objects, and also for the
7052 -- elaboration of objects of types derived from Typ that do not
7053 -- override the primitives of this interface type.
7055 Suffix_Index := 1;
7057 -- Note: The value of Suffix_Index must be in sync with the values of
7058 -- Suffix_Index in secondary dispatch tables generated by Make_DT.
7060 if Is_CPP_Class (Typ) then
7061 AI_Tag_Comp := First_Elmt (Typ_Comps);
7062 while Present (AI_Tag_Comp) loop
7063 Get_Secondary_DT_External_Name
7064 (Typ, Related_Type (Node (AI_Tag_Comp)), Suffix_Index);
7065 Typ_Name := Name_Find;
7067 -- Declare variables to store copy of the C++ secondary tags
7069 Iface_DT_Ptr :=
7070 Make_Defining_Identifier (Loc,
7071 Chars => New_External_Name (Typ_Name, 'P'));
7072 Set_Etype (Iface_DT_Ptr, RTE (RE_Interface_Tag));
7073 Set_Ekind (Iface_DT_Ptr, E_Variable);
7074 Set_Is_Tag (Iface_DT_Ptr);
7076 Set_Has_Thunks (Iface_DT_Ptr);
7077 Set_Related_Type
7078 (Iface_DT_Ptr, Related_Type (Node (AI_Tag_Comp)));
7079 Append_Elmt (Iface_DT_Ptr, Access_Disp_Table (Typ));
7081 Append_To (Result,
7082 Make_Object_Declaration (Loc,
7083 Defining_Identifier => Iface_DT_Ptr,
7084 Object_Definition => New_Occurrence_Of
7085 (RTE (RE_Interface_Tag), Loc),
7086 Expression =>
7087 Unchecked_Convert_To (RTE (RE_Interface_Tag),
7088 New_Occurrence_Of (RTE (RE_Null_Address), Loc))));
7090 Set_Is_Statically_Allocated (Iface_DT_Ptr,
7091 Is_Library_Level_Tagged_Type (Typ));
7093 Next_Elmt (AI_Tag_Comp);
7094 end loop;
7096 -- This is not a CPP_Class type
7098 else
7099 AI_Tag_Comp := First_Elmt (Typ_Comps);
7100 while Present (AI_Tag_Comp) loop
7101 Get_Secondary_DT_External_Name
7102 (Typ, Related_Type (Node (AI_Tag_Comp)), Suffix_Index);
7103 Typ_Name := Name_Find;
7105 if Building_Static_DT (Typ) then
7106 Iface_DT :=
7107 Make_Defining_Identifier (Loc,
7108 Chars => New_External_Name (Typ_Name, 'T'));
7109 Import_DT
7110 (Tag_Typ => Related_Type (Node (AI_Tag_Comp)),
7111 DT => Iface_DT,
7112 Is_Secondary_DT => True);
7113 end if;
7115 -- Secondary dispatch table referencing thunks to user-defined
7116 -- primitives covered by this interface.
7118 Iface_DT_Ptr :=
7119 Make_Defining_Identifier (Loc,
7120 Chars => New_External_Name (Typ_Name, 'P'));
7121 Set_Etype (Iface_DT_Ptr, RTE (RE_Interface_Tag));
7122 Set_Ekind (Iface_DT_Ptr, E_Constant);
7123 Set_Is_Tag (Iface_DT_Ptr);
7124 Set_Has_Thunks (Iface_DT_Ptr);
7125 Set_Is_Statically_Allocated (Iface_DT_Ptr,
7126 Is_Library_Level_Tagged_Type (Typ));
7127 Set_Is_True_Constant (Iface_DT_Ptr);
7128 Set_Related_Type
7129 (Iface_DT_Ptr, Related_Type (Node (AI_Tag_Comp)));
7130 Append_Elmt (Iface_DT_Ptr, Access_Disp_Table (Typ));
7132 if Building_Static_DT (Typ) then
7133 Append_To (Result,
7134 Make_Object_Declaration (Loc,
7135 Defining_Identifier => Iface_DT_Ptr,
7136 Constant_Present => True,
7137 Object_Definition => New_Occurrence_Of
7138 (RTE (RE_Interface_Tag), Loc),
7139 Expression =>
7140 Unchecked_Convert_To (RTE (RE_Interface_Tag),
7141 Make_Attribute_Reference (Loc,
7142 Prefix =>
7143 Make_Selected_Component (Loc,
7144 Prefix =>
7145 New_Occurrence_Of (Iface_DT, Loc),
7146 Selector_Name =>
7147 New_Occurrence_Of
7148 (RTE_Record_Component (RE_Prims_Ptr),
7149 Loc)),
7150 Attribute_Name => Name_Address))));
7151 end if;
7153 -- Secondary dispatch table referencing thunks to predefined
7154 -- primitives.
7156 Iface_DT_Ptr :=
7157 Make_Defining_Identifier (Loc,
7158 Chars => New_External_Name (Typ_Name, 'Y'));
7159 Set_Etype (Iface_DT_Ptr, RTE (RE_Address));
7160 Set_Ekind (Iface_DT_Ptr, E_Constant);
7161 Set_Is_Tag (Iface_DT_Ptr);
7162 Set_Has_Thunks (Iface_DT_Ptr);
7163 Set_Is_Statically_Allocated (Iface_DT_Ptr,
7164 Is_Library_Level_Tagged_Type (Typ));
7165 Set_Is_True_Constant (Iface_DT_Ptr);
7166 Set_Related_Type
7167 (Iface_DT_Ptr, Related_Type (Node (AI_Tag_Comp)));
7168 Append_Elmt (Iface_DT_Ptr, Access_Disp_Table (Typ));
7170 -- Secondary dispatch table referencing user-defined primitives
7171 -- covered by this interface.
7173 Iface_DT_Ptr :=
7174 Make_Defining_Identifier (Loc,
7175 Chars => New_External_Name (Typ_Name, 'D'));
7176 Set_Etype (Iface_DT_Ptr, RTE (RE_Interface_Tag));
7177 Set_Ekind (Iface_DT_Ptr, E_Constant);
7178 Set_Is_Tag (Iface_DT_Ptr);
7179 Set_Is_Statically_Allocated (Iface_DT_Ptr,
7180 Is_Library_Level_Tagged_Type (Typ));
7181 Set_Is_True_Constant (Iface_DT_Ptr);
7182 Set_Related_Type
7183 (Iface_DT_Ptr, Related_Type (Node (AI_Tag_Comp)));
7184 Append_Elmt (Iface_DT_Ptr, Access_Disp_Table (Typ));
7186 -- Secondary dispatch table referencing predefined primitives
7188 Iface_DT_Ptr :=
7189 Make_Defining_Identifier (Loc,
7190 Chars => New_External_Name (Typ_Name, 'Z'));
7191 Set_Etype (Iface_DT_Ptr, RTE (RE_Address));
7192 Set_Ekind (Iface_DT_Ptr, E_Constant);
7193 Set_Is_Tag (Iface_DT_Ptr);
7194 Set_Is_Statically_Allocated (Iface_DT_Ptr,
7195 Is_Library_Level_Tagged_Type (Typ));
7196 Set_Is_True_Constant (Iface_DT_Ptr);
7197 Set_Related_Type
7198 (Iface_DT_Ptr, Related_Type (Node (AI_Tag_Comp)));
7199 Append_Elmt (Iface_DT_Ptr, Access_Disp_Table (Typ));
7201 Next_Elmt (AI_Tag_Comp);
7202 end loop;
7203 end if;
7204 end if;
7206 -- 3) At the end of Access_Disp_Table, if the type has user-defined
7207 -- primitives, we add the entity of an access type declaration that
7208 -- is used by Build_Get_Prim_Op_Address to expand dispatching calls
7209 -- through the primary dispatch table.
7211 if UI_To_Int (DT_Entry_Count (First_Tag_Component (Typ))) = 0 then
7212 Analyze_List (Result);
7214 -- Generate:
7215 -- subtype Typ_DT is Address_Array (1 .. Nb_Prims);
7216 -- type Typ_DT_Acc is access Typ_DT;
7218 else
7219 declare
7220 Name_DT_Prims : constant Name_Id :=
7221 New_External_Name (Tname, 'G');
7222 Name_DT_Prims_Acc : constant Name_Id :=
7223 New_External_Name (Tname, 'H');
7224 DT_Prims : constant Entity_Id :=
7225 Make_Defining_Identifier (Loc,
7226 Name_DT_Prims);
7227 DT_Prims_Acc : constant Entity_Id :=
7228 Make_Defining_Identifier (Loc,
7229 Name_DT_Prims_Acc);
7230 begin
7231 Append_To (Result,
7232 Make_Subtype_Declaration (Loc,
7233 Defining_Identifier => DT_Prims,
7234 Subtype_Indication =>
7235 Make_Subtype_Indication (Loc,
7236 Subtype_Mark =>
7237 New_Occurrence_Of (RTE (RE_Address_Array), Loc),
7238 Constraint =>
7239 Make_Index_Or_Discriminant_Constraint (Loc, New_List (
7240 Make_Range (Loc,
7241 Low_Bound => Make_Integer_Literal (Loc, 1),
7242 High_Bound =>
7243 Make_Integer_Literal (Loc,
7244 DT_Entry_Count
7245 (First_Tag_Component (Typ)))))))));
7247 Append_To (Result,
7248 Make_Full_Type_Declaration (Loc,
7249 Defining_Identifier => DT_Prims_Acc,
7250 Type_Definition =>
7251 Make_Access_To_Object_Definition (Loc,
7252 Subtype_Indication =>
7253 New_Occurrence_Of (DT_Prims, Loc))));
7255 Append_Elmt (DT_Prims_Acc, Access_Disp_Table (Typ));
7257 -- Analyze the resulting list and suppress the generation of the
7258 -- Init_Proc associated with the above array declaration because
7259 -- this type is never used in object declarations. It is only used
7260 -- to simplify the expansion associated with dispatching calls.
7262 Analyze_List (Result);
7263 Set_Suppress_Initialization (Base_Type (DT_Prims));
7265 -- Disable backend optimizations based on assumptions about the
7266 -- aliasing status of objects designated by the access to the
7267 -- dispatch table. Required to handle dispatch tables imported
7268 -- from C++.
7270 Set_No_Strict_Aliasing (Base_Type (DT_Prims_Acc));
7272 -- Add the freezing nodes of these declarations; required to avoid
7273 -- generating these freezing nodes in wrong scopes (for example in
7274 -- the IC routine of a derivation of Typ).
7276 -- What is an "IC routine"? Is "init_proc" meant here???
7278 Append_List_To (Result, Freeze_Entity (DT_Prims, Typ));
7279 Append_List_To (Result, Freeze_Entity (DT_Prims_Acc, Typ));
7281 -- Mark entity of dispatch table. Required by the back end to
7282 -- handle them properly.
7284 Set_Is_Dispatch_Table_Entity (DT_Prims);
7285 end;
7286 end if;
7288 -- Mark entities of dispatch table. Required by the back end to handle
7289 -- them properly.
7291 if Present (DT) then
7292 Set_Is_Dispatch_Table_Entity (DT);
7293 Set_Is_Dispatch_Table_Entity (Etype (DT));
7294 end if;
7296 if Present (Iface_DT) then
7297 Set_Is_Dispatch_Table_Entity (Iface_DT);
7298 Set_Is_Dispatch_Table_Entity (Etype (Iface_DT));
7299 end if;
7301 if Is_CPP_Class (Root_Type (Typ)) then
7302 Set_Ekind (DT_Ptr, E_Variable);
7303 else
7304 Set_Ekind (DT_Ptr, E_Constant);
7305 end if;
7307 Set_Is_Tag (DT_Ptr);
7308 Set_Related_Type (DT_Ptr, Typ);
7310 return Result;
7311 end Make_Tags;
7313 ---------------
7314 -- New_Value --
7315 ---------------
7317 function New_Value (From : Node_Id) return Node_Id is
7318 Res : constant Node_Id := Duplicate_Subexpr (From);
7319 begin
7320 if Is_Access_Type (Etype (From)) then
7321 return Make_Explicit_Dereference (Sloc (From), Prefix => Res);
7322 else
7323 return Res;
7324 end if;
7325 end New_Value;
7327 -----------------------------------
7328 -- Original_View_In_Visible_Part --
7329 -----------------------------------
7331 function Original_View_In_Visible_Part (Typ : Entity_Id) return Boolean is
7332 Scop : constant Entity_Id := Scope (Typ);
7334 begin
7335 -- The scope must be a package
7337 if not Is_Package_Or_Generic_Package (Scop) then
7338 return False;
7339 end if;
7341 -- A type with a private declaration has a private view declared in
7342 -- the visible part.
7344 if Has_Private_Declaration (Typ) then
7345 return True;
7346 end if;
7348 return List_Containing (Parent (Typ)) =
7349 Visible_Declarations (Package_Specification (Scop));
7350 end Original_View_In_Visible_Part;
7352 ------------------
7353 -- Prim_Op_Kind --
7354 ------------------
7356 function Prim_Op_Kind
7357 (Prim : Entity_Id;
7358 Typ : Entity_Id) return Node_Id
7360 Full_Typ : Entity_Id := Typ;
7361 Loc : constant Source_Ptr := Sloc (Prim);
7362 Prim_Op : Entity_Id;
7364 begin
7365 -- Retrieve the original primitive operation
7367 Prim_Op := Ultimate_Alias (Prim);
7369 if Ekind (Typ) = E_Record_Type
7370 and then Present (Corresponding_Concurrent_Type (Typ))
7371 then
7372 Full_Typ := Corresponding_Concurrent_Type (Typ);
7373 end if;
7375 -- When a private tagged type is completed by a concurrent type,
7376 -- retrieve the full view.
7378 if Is_Private_Type (Full_Typ) then
7379 Full_Typ := Full_View (Full_Typ);
7380 end if;
7382 if Ekind (Prim_Op) = E_Function then
7384 -- Protected function
7386 if Ekind (Full_Typ) = E_Protected_Type then
7387 return New_Occurrence_Of (RTE (RE_POK_Protected_Function), Loc);
7389 -- Task function
7391 elsif Ekind (Full_Typ) = E_Task_Type then
7392 return New_Occurrence_Of (RTE (RE_POK_Task_Function), Loc);
7394 -- Regular function
7396 else
7397 return New_Occurrence_Of (RTE (RE_POK_Function), Loc);
7398 end if;
7400 else
7401 pragma Assert (Ekind (Prim_Op) = E_Procedure);
7403 if Ekind (Full_Typ) = E_Protected_Type then
7405 -- Protected entry
7407 if Is_Primitive_Wrapper (Prim_Op)
7408 and then Ekind (Wrapped_Entity (Prim_Op)) = E_Entry
7409 then
7410 return New_Occurrence_Of (RTE (RE_POK_Protected_Entry), Loc);
7412 -- Protected procedure
7414 else
7415 return
7416 New_Occurrence_Of (RTE (RE_POK_Protected_Procedure), Loc);
7417 end if;
7419 elsif Ekind (Full_Typ) = E_Task_Type then
7421 -- Task entry
7423 if Is_Primitive_Wrapper (Prim_Op)
7424 and then Ekind (Wrapped_Entity (Prim_Op)) = E_Entry
7425 then
7426 return New_Occurrence_Of (RTE (RE_POK_Task_Entry), Loc);
7428 -- Task "procedure". These are the internally Expander-generated
7429 -- procedures (task body for instance).
7431 else
7432 return New_Occurrence_Of (RTE (RE_POK_Task_Procedure), Loc);
7433 end if;
7435 -- Regular procedure
7437 else
7438 return New_Occurrence_Of (RTE (RE_POK_Procedure), Loc);
7439 end if;
7440 end if;
7441 end Prim_Op_Kind;
7443 ------------------------
7444 -- Register_Primitive --
7445 ------------------------
7447 function Register_Primitive
7448 (Loc : Source_Ptr;
7449 Prim : Entity_Id) return List_Id
7451 DT_Ptr : Entity_Id;
7452 Iface_Prim : Entity_Id;
7453 Iface_Typ : Entity_Id;
7454 Iface_DT_Ptr : Entity_Id;
7455 Iface_DT_Elmt : Elmt_Id;
7456 L : constant List_Id := New_List;
7457 Pos : Uint;
7458 Tag : Entity_Id;
7459 Tag_Typ : Entity_Id;
7460 Thunk_Id : Entity_Id;
7461 Thunk_Code : Node_Id;
7463 begin
7464 pragma Assert (not Restriction_Active (No_Dispatching_Calls));
7466 -- Do not register in the dispatch table eliminated primitives
7468 if not RTE_Available (RE_Tag)
7469 or else Is_Eliminated (Ultimate_Alias (Prim))
7470 or else Generate_SCIL
7471 then
7472 return L;
7473 end if;
7475 if not Present (Interface_Alias (Prim)) then
7476 Tag_Typ := Scope (DTC_Entity (Prim));
7477 Pos := DT_Position (Prim);
7478 Tag := First_Tag_Component (Tag_Typ);
7480 if Is_Predefined_Dispatching_Operation (Prim)
7481 or else Is_Predefined_Dispatching_Alias (Prim)
7482 then
7483 DT_Ptr :=
7484 Node (Next_Elmt (First_Elmt (Access_Disp_Table (Tag_Typ))));
7486 Append_To (L,
7487 Build_Set_Predefined_Prim_Op_Address (Loc,
7488 Tag_Node => New_Occurrence_Of (DT_Ptr, Loc),
7489 Position => Pos,
7490 Address_Node =>
7491 Unchecked_Convert_To (RTE (RE_Prim_Ptr),
7492 Make_Attribute_Reference (Loc,
7493 Prefix => New_Occurrence_Of (Prim, Loc),
7494 Attribute_Name => Name_Unrestricted_Access))));
7496 -- Register copy of the pointer to the 'size primitive in the TSD
7498 if Chars (Prim) = Name_uSize
7499 and then RTE_Record_Component_Available (RE_Size_Func)
7500 then
7501 DT_Ptr := Node (First_Elmt (Access_Disp_Table (Tag_Typ)));
7502 Append_To (L,
7503 Build_Set_Size_Function (Loc,
7504 Tag_Node => New_Occurrence_Of (DT_Ptr, Loc),
7505 Size_Func => Prim));
7506 end if;
7508 else
7509 pragma Assert (Pos /= Uint_0 and then Pos <= DT_Entry_Count (Tag));
7511 -- Skip registration of primitives located in the C++ part of the
7512 -- dispatch table. Their slot is set by the IC routine.
7514 if not Is_CPP_Class (Root_Type (Tag_Typ))
7515 or else Pos > CPP_Num_Prims (Tag_Typ)
7516 then
7517 DT_Ptr := Node (First_Elmt (Access_Disp_Table (Tag_Typ)));
7518 Append_To (L,
7519 Build_Set_Prim_Op_Address (Loc,
7520 Typ => Tag_Typ,
7521 Tag_Node => New_Occurrence_Of (DT_Ptr, Loc),
7522 Position => Pos,
7523 Address_Node =>
7524 Unchecked_Convert_To (RTE (RE_Prim_Ptr),
7525 Make_Attribute_Reference (Loc,
7526 Prefix => New_Occurrence_Of (Prim, Loc),
7527 Attribute_Name => Name_Unrestricted_Access))));
7528 end if;
7529 end if;
7531 -- Ada 2005 (AI-251): Primitive associated with an interface type
7533 -- Generate the code of the thunk only if the interface type is not an
7534 -- immediate ancestor of Typ; otherwise the dispatch table associated
7535 -- with the interface is the primary dispatch table and we have nothing
7536 -- else to do here.
7538 else
7539 Tag_Typ := Find_Dispatching_Type (Alias (Prim));
7540 Iface_Typ := Find_Dispatching_Type (Interface_Alias (Prim));
7542 pragma Assert (Is_Interface (Iface_Typ));
7544 -- No action needed for interfaces that are ancestors of Typ because
7545 -- their primitives are located in the primary dispatch table.
7547 if Is_Ancestor (Iface_Typ, Tag_Typ, Use_Full_View => True) then
7548 return L;
7550 -- No action needed for primitives located in the C++ part of the
7551 -- dispatch table. Their slot is set by the IC routine.
7553 elsif Is_CPP_Class (Root_Type (Tag_Typ))
7554 and then DT_Position (Alias (Prim)) <= CPP_Num_Prims (Tag_Typ)
7555 and then not Is_Predefined_Dispatching_Operation (Prim)
7556 and then not Is_Predefined_Dispatching_Alias (Prim)
7557 then
7558 return L;
7559 end if;
7561 Expand_Interface_Thunk (Prim, Thunk_Id, Thunk_Code);
7563 if not Is_Ancestor (Iface_Typ, Tag_Typ, Use_Full_View => True)
7564 and then Present (Thunk_Code)
7565 then
7566 -- Generate the code necessary to fill the appropriate entry of
7567 -- the secondary dispatch table of Prim's controlling type with
7568 -- Thunk_Id's address.
7570 Iface_DT_Elmt := Find_Interface_ADT (Tag_Typ, Iface_Typ);
7571 Iface_DT_Ptr := Node (Iface_DT_Elmt);
7572 pragma Assert (Has_Thunks (Iface_DT_Ptr));
7574 Iface_Prim := Interface_Alias (Prim);
7575 Pos := DT_Position (Iface_Prim);
7576 Tag := First_Tag_Component (Iface_Typ);
7578 Prepend_To (L, Thunk_Code);
7580 if Is_Predefined_Dispatching_Operation (Prim)
7581 or else Is_Predefined_Dispatching_Alias (Prim)
7582 then
7583 Append_To (L,
7584 Build_Set_Predefined_Prim_Op_Address (Loc,
7585 Tag_Node =>
7586 New_Occurrence_Of (Node (Next_Elmt (Iface_DT_Elmt)), Loc),
7587 Position => Pos,
7588 Address_Node =>
7589 Unchecked_Convert_To (RTE (RE_Prim_Ptr),
7590 Make_Attribute_Reference (Loc,
7591 Prefix => New_Occurrence_Of (Thunk_Id, Loc),
7592 Attribute_Name => Name_Unrestricted_Access))));
7594 Next_Elmt (Iface_DT_Elmt);
7595 Next_Elmt (Iface_DT_Elmt);
7596 Iface_DT_Ptr := Node (Iface_DT_Elmt);
7597 pragma Assert (not Has_Thunks (Iface_DT_Ptr));
7599 Append_To (L,
7600 Build_Set_Predefined_Prim_Op_Address (Loc,
7601 Tag_Node =>
7602 New_Occurrence_Of (Node (Next_Elmt (Iface_DT_Elmt)), Loc),
7603 Position => Pos,
7604 Address_Node =>
7605 Unchecked_Convert_To (RTE (RE_Prim_Ptr),
7606 Make_Attribute_Reference (Loc,
7607 Prefix =>
7608 New_Occurrence_Of (Alias (Prim), Loc),
7609 Attribute_Name => Name_Unrestricted_Access))));
7611 else
7612 pragma Assert (Pos /= Uint_0
7613 and then Pos <= DT_Entry_Count (Tag));
7615 Append_To (L,
7616 Build_Set_Prim_Op_Address (Loc,
7617 Typ => Iface_Typ,
7618 Tag_Node => New_Occurrence_Of (Iface_DT_Ptr, Loc),
7619 Position => Pos,
7620 Address_Node =>
7621 Unchecked_Convert_To (RTE (RE_Prim_Ptr),
7622 Make_Attribute_Reference (Loc,
7623 Prefix => New_Occurrence_Of (Thunk_Id, Loc),
7624 Attribute_Name => Name_Unrestricted_Access))));
7626 Next_Elmt (Iface_DT_Elmt);
7627 Next_Elmt (Iface_DT_Elmt);
7628 Iface_DT_Ptr := Node (Iface_DT_Elmt);
7629 pragma Assert (not Has_Thunks (Iface_DT_Ptr));
7631 Append_To (L,
7632 Build_Set_Prim_Op_Address (Loc,
7633 Typ => Iface_Typ,
7634 Tag_Node => New_Occurrence_Of (Iface_DT_Ptr, Loc),
7635 Position => Pos,
7636 Address_Node =>
7637 Unchecked_Convert_To (RTE (RE_Prim_Ptr),
7638 Make_Attribute_Reference (Loc,
7639 Prefix =>
7640 New_Occurrence_Of (Alias (Prim), Loc),
7641 Attribute_Name => Name_Unrestricted_Access))));
7643 end if;
7644 end if;
7645 end if;
7647 return L;
7648 end Register_Primitive;
7650 -------------------------
7651 -- Set_All_DT_Position --
7652 -------------------------
7654 procedure Set_All_DT_Position (Typ : Entity_Id) is
7656 function In_Predef_Prims_DT (Prim : Entity_Id) return Boolean;
7657 -- Returns True if Prim is located in the dispatch table of
7658 -- predefined primitives
7660 procedure Validate_Position (Prim : Entity_Id);
7661 -- Check that position assigned to Prim is completely safe (it has not
7662 -- been assigned to a previously defined primitive operation of Typ).
7664 ------------------------
7665 -- In_Predef_Prims_DT --
7666 ------------------------
7668 function In_Predef_Prims_DT (Prim : Entity_Id) return Boolean is
7669 begin
7670 -- Predefined primitives
7672 if Is_Predefined_Dispatching_Operation (Prim) then
7673 return True;
7675 -- Renamings of predefined primitives
7677 elsif Present (Alias (Prim))
7678 and then Is_Predefined_Dispatching_Operation (Ultimate_Alias (Prim))
7679 then
7680 if Chars (Ultimate_Alias (Prim)) /= Name_Op_Eq then
7681 return True;
7683 -- An overriding operation that is a user-defined renaming of
7684 -- predefined equality inherits its slot from the overridden
7685 -- operation. Otherwise it is treated as a predefined op and
7686 -- occupies the same predefined slot as equality. A call to it is
7687 -- transformed into a call to its alias, which is the predefined
7688 -- equality op. A dispatching call thus uses the proper slot if
7689 -- operation is further inherited and called with class-wide
7690 -- arguments.
7692 else
7693 return
7694 not Comes_From_Source (Prim)
7695 or else No (Overridden_Operation (Prim));
7696 end if;
7698 -- User-defined primitives
7700 else
7701 return False;
7702 end if;
7703 end In_Predef_Prims_DT;
7705 -----------------------
7706 -- Validate_Position --
7707 -----------------------
7709 procedure Validate_Position (Prim : Entity_Id) is
7710 Op_Elmt : Elmt_Id;
7711 Op : Entity_Id;
7713 begin
7714 -- Aliased primitives are safe
7716 if Present (Alias (Prim)) then
7717 return;
7718 end if;
7720 Op_Elmt := First_Elmt (Primitive_Operations (Typ));
7721 while Present (Op_Elmt) loop
7722 Op := Node (Op_Elmt);
7724 -- No need to check against itself
7726 if Op = Prim then
7727 null;
7729 -- Primitive operations covering abstract interfaces are
7730 -- allocated later
7732 elsif Present (Interface_Alias (Op)) then
7733 null;
7735 -- Predefined dispatching operations are completely safe. They
7736 -- are allocated at fixed positions in a separate table.
7738 elsif Is_Predefined_Dispatching_Operation (Op)
7739 or else Is_Predefined_Dispatching_Alias (Op)
7740 then
7741 null;
7743 -- Aliased subprograms are safe
7745 elsif Present (Alias (Op)) then
7746 null;
7748 elsif DT_Position (Op) = DT_Position (Prim)
7749 and then not Is_Predefined_Dispatching_Operation (Op)
7750 and then not Is_Predefined_Dispatching_Operation (Prim)
7751 and then not Is_Predefined_Dispatching_Alias (Op)
7752 and then not Is_Predefined_Dispatching_Alias (Prim)
7753 then
7754 -- Handle aliased subprograms
7756 declare
7757 Op_1 : Entity_Id;
7758 Op_2 : Entity_Id;
7760 begin
7761 Op_1 := Op;
7762 loop
7763 if Present (Overridden_Operation (Op_1)) then
7764 Op_1 := Overridden_Operation (Op_1);
7765 elsif Present (Alias (Op_1)) then
7766 Op_1 := Alias (Op_1);
7767 else
7768 exit;
7769 end if;
7770 end loop;
7772 Op_2 := Prim;
7773 loop
7774 if Present (Overridden_Operation (Op_2)) then
7775 Op_2 := Overridden_Operation (Op_2);
7776 elsif Present (Alias (Op_2)) then
7777 Op_2 := Alias (Op_2);
7778 else
7779 exit;
7780 end if;
7781 end loop;
7783 if Op_1 /= Op_2 then
7784 raise Program_Error;
7785 end if;
7786 end;
7787 end if;
7789 Next_Elmt (Op_Elmt);
7790 end loop;
7791 end Validate_Position;
7793 -- Local variables
7795 Parent_Typ : constant Entity_Id := Etype (Typ);
7796 First_Prim : constant Elmt_Id := First_Elmt (Primitive_Operations (Typ));
7797 The_Tag : constant Entity_Id := First_Tag_Component (Typ);
7799 Adjusted : Boolean := False;
7800 Finalized : Boolean := False;
7802 Count_Prim : Nat;
7803 DT_Length : Nat;
7804 Nb_Prim : Nat;
7805 Prim : Entity_Id;
7806 Prim_Elmt : Elmt_Id;
7808 -- Start of processing for Set_All_DT_Position
7810 begin
7811 pragma Assert (Present (First_Tag_Component (Typ)));
7813 -- Set the DT_Position for each primitive operation. Perform some sanity
7814 -- checks to avoid building inconsistent dispatch tables.
7816 -- First stage: Set DTC entity of all the primitive operations. This is
7817 -- required to properly read the DT_Position attribute in latter stages.
7819 Prim_Elmt := First_Prim;
7820 Count_Prim := 0;
7821 while Present (Prim_Elmt) loop
7822 Prim := Node (Prim_Elmt);
7824 -- Predefined primitives have a separate dispatch table
7826 if not In_Predef_Prims_DT (Prim) then
7827 Count_Prim := Count_Prim + 1;
7828 end if;
7830 Set_DTC_Entity_Value (Typ, Prim);
7832 -- Clear any previous value of the DT_Position attribute. In this
7833 -- way we ensure that the final position of all the primitives is
7834 -- established by the following stages of this algorithm.
7836 Set_DT_Position_Value (Prim, No_Uint);
7838 Next_Elmt (Prim_Elmt);
7839 end loop;
7841 declare
7842 Fixed_Prim : array (Int range 0 .. Count_Prim) of Boolean :=
7843 (others => False);
7845 E : Entity_Id;
7847 procedure Handle_Inherited_Private_Subprograms (Typ : Entity_Id);
7848 -- Called if Typ is declared in a nested package or a public child
7849 -- package to handle inherited primitives that were inherited by Typ
7850 -- in the visible part, but whose declaration was deferred because
7851 -- the parent operation was private and not visible at that point.
7853 procedure Set_Fixed_Prim (Pos : Nat);
7854 -- Sets to true an element of the Fixed_Prim table to indicate
7855 -- that this entry of the dispatch table of Typ is occupied.
7857 ------------------------------------------
7858 -- Handle_Inherited_Private_Subprograms --
7859 ------------------------------------------
7861 procedure Handle_Inherited_Private_Subprograms (Typ : Entity_Id) is
7862 Op_List : Elist_Id;
7863 Op_Elmt : Elmt_Id;
7864 Op_Elmt_2 : Elmt_Id;
7865 Prim_Op : Entity_Id;
7866 Parent_Subp : Entity_Id;
7868 begin
7869 Op_List := Primitive_Operations (Typ);
7871 Op_Elmt := First_Elmt (Op_List);
7872 while Present (Op_Elmt) loop
7873 Prim_Op := Node (Op_Elmt);
7875 -- Search primitives that are implicit operations with an
7876 -- internal name whose parent operation has a normal name.
7878 if Present (Alias (Prim_Op))
7879 and then Find_Dispatching_Type (Alias (Prim_Op)) /= Typ
7880 and then not Comes_From_Source (Prim_Op)
7881 and then Is_Internal_Name (Chars (Prim_Op))
7882 and then not Is_Internal_Name (Chars (Alias (Prim_Op)))
7883 then
7884 Parent_Subp := Alias (Prim_Op);
7886 -- Check if the type has an explicit overriding for this
7887 -- primitive.
7889 Op_Elmt_2 := Next_Elmt (Op_Elmt);
7890 while Present (Op_Elmt_2) loop
7891 if Chars (Node (Op_Elmt_2)) = Chars (Parent_Subp)
7892 and then Type_Conformant (Prim_Op, Node (Op_Elmt_2))
7893 then
7894 Set_DT_Position_Value (Prim_Op,
7895 DT_Position (Parent_Subp));
7896 Set_DT_Position_Value (Node (Op_Elmt_2),
7897 DT_Position (Parent_Subp));
7898 Set_Fixed_Prim (UI_To_Int (DT_Position (Prim_Op)));
7900 goto Next_Primitive;
7901 end if;
7903 Next_Elmt (Op_Elmt_2);
7904 end loop;
7905 end if;
7907 <<Next_Primitive>>
7908 Next_Elmt (Op_Elmt);
7909 end loop;
7910 end Handle_Inherited_Private_Subprograms;
7912 --------------------
7913 -- Set_Fixed_Prim --
7914 --------------------
7916 procedure Set_Fixed_Prim (Pos : Nat) is
7917 begin
7918 pragma Assert (Pos <= Count_Prim);
7919 Fixed_Prim (Pos) := True;
7920 exception
7921 when Constraint_Error =>
7922 raise Program_Error;
7923 end Set_Fixed_Prim;
7925 begin
7926 -- In case of nested packages and public child package it may be
7927 -- necessary a special management on inherited subprograms so that
7928 -- the dispatch table is properly filled.
7930 if Ekind (Scope (Scope (Typ))) = E_Package
7931 and then Scope (Scope (Typ)) /= Standard_Standard
7932 and then ((Is_Derived_Type (Typ) and then not Is_Private_Type (Typ))
7933 or else
7934 (Nkind (Parent (Typ)) = N_Private_Extension_Declaration
7935 and then Is_Generic_Type (Typ)))
7936 and then In_Open_Scopes (Scope (Etype (Typ)))
7937 and then Is_Base_Type (Typ)
7938 then
7939 Handle_Inherited_Private_Subprograms (Typ);
7940 end if;
7942 -- Second stage: Register fixed entries
7944 Nb_Prim := 0;
7945 Prim_Elmt := First_Prim;
7946 while Present (Prim_Elmt) loop
7947 Prim := Node (Prim_Elmt);
7949 -- Predefined primitives have a separate table and all its
7950 -- entries are at predefined fixed positions.
7952 if In_Predef_Prims_DT (Prim) then
7953 if Is_Predefined_Dispatching_Operation (Prim) then
7954 Set_DT_Position_Value (Prim,
7955 Default_Prim_Op_Position (Prim));
7957 else pragma Assert (Present (Alias (Prim)));
7958 Set_DT_Position_Value (Prim,
7959 Default_Prim_Op_Position (Ultimate_Alias (Prim)));
7960 end if;
7962 -- Overriding primitives of ancestor abstract interfaces
7964 elsif Present (Interface_Alias (Prim))
7965 and then Is_Ancestor
7966 (Find_Dispatching_Type (Interface_Alias (Prim)), Typ,
7967 Use_Full_View => True)
7968 then
7969 pragma Assert (DT_Position (Prim) = No_Uint
7970 and then Present (DTC_Entity (Interface_Alias (Prim))));
7972 E := Interface_Alias (Prim);
7973 Set_DT_Position_Value (Prim, DT_Position (E));
7975 pragma Assert
7976 (DT_Position (Alias (Prim)) = No_Uint
7977 or else DT_Position (Alias (Prim)) = DT_Position (E));
7978 Set_DT_Position_Value (Alias (Prim), DT_Position (E));
7979 Set_Fixed_Prim (UI_To_Int (DT_Position (Prim)));
7981 -- Overriding primitives must use the same entry as the overridden
7982 -- primitive. Note that the Alias of the operation is set when the
7983 -- operation is declared by a renaming, in which case it is not
7984 -- overriding. If it renames another primitive it will use the
7985 -- same dispatch table slot, but if it renames an operation in a
7986 -- nested package it's a new primitive and will have its own slot.
7988 elsif not Present (Interface_Alias (Prim))
7989 and then Present (Alias (Prim))
7990 and then Chars (Prim) = Chars (Alias (Prim))
7991 and then Nkind (Unit_Declaration_Node (Prim)) /=
7992 N_Subprogram_Renaming_Declaration
7993 then
7994 declare
7995 Par_Type : constant Entity_Id :=
7996 Find_Dispatching_Type (Alias (Prim));
7998 begin
7999 if Present (Par_Type)
8000 and then Par_Type /= Typ
8001 and then Is_Ancestor (Par_Type, Typ, Use_Full_View => True)
8002 and then Present (DTC_Entity (Alias (Prim)))
8003 then
8004 E := Alias (Prim);
8005 Set_DT_Position_Value (Prim, DT_Position (E));
8007 if not Is_Predefined_Dispatching_Alias (E) then
8008 Set_Fixed_Prim (UI_To_Int (DT_Position (E)));
8009 end if;
8010 end if;
8011 end;
8012 end if;
8014 Next_Elmt (Prim_Elmt);
8015 end loop;
8017 -- Third stage: Fix the position of all the new primitives. Entries
8018 -- associated with primitives covering interfaces are handled in a
8019 -- latter round.
8021 Prim_Elmt := First_Prim;
8022 while Present (Prim_Elmt) loop
8023 Prim := Node (Prim_Elmt);
8025 -- Skip primitives previously set entries
8027 if DT_Position (Prim) /= No_Uint then
8028 null;
8030 -- Primitives covering interface primitives are handled later
8032 elsif Present (Interface_Alias (Prim)) then
8033 null;
8035 else
8036 -- Take the next available position in the DT
8038 loop
8039 Nb_Prim := Nb_Prim + 1;
8040 pragma Assert (Nb_Prim <= Count_Prim);
8041 exit when not Fixed_Prim (Nb_Prim);
8042 end loop;
8044 Set_DT_Position_Value (Prim, UI_From_Int (Nb_Prim));
8045 Set_Fixed_Prim (Nb_Prim);
8046 end if;
8048 Next_Elmt (Prim_Elmt);
8049 end loop;
8050 end;
8052 -- Fourth stage: Complete the decoration of primitives covering
8053 -- interfaces (that is, propagate the DT_Position attribute from
8054 -- the aliased primitive)
8056 Prim_Elmt := First_Prim;
8057 while Present (Prim_Elmt) loop
8058 Prim := Node (Prim_Elmt);
8060 if DT_Position (Prim) = No_Uint
8061 and then Present (Interface_Alias (Prim))
8062 then
8063 pragma Assert (Present (Alias (Prim))
8064 and then Find_Dispatching_Type (Alias (Prim)) = Typ);
8066 -- Check if this entry will be placed in the primary DT
8068 if Is_Ancestor
8069 (Find_Dispatching_Type (Interface_Alias (Prim)), Typ,
8070 Use_Full_View => True)
8071 then
8072 pragma Assert (DT_Position (Alias (Prim)) /= No_Uint);
8073 Set_DT_Position_Value (Prim, DT_Position (Alias (Prim)));
8075 -- Otherwise it will be placed in the secondary DT
8077 else
8078 pragma Assert
8079 (DT_Position (Interface_Alias (Prim)) /= No_Uint);
8080 Set_DT_Position_Value (Prim,
8081 DT_Position (Interface_Alias (Prim)));
8082 end if;
8083 end if;
8085 Next_Elmt (Prim_Elmt);
8086 end loop;
8088 -- Generate listing showing the contents of the dispatch tables. This
8089 -- action is done before some further static checks because in case of
8090 -- critical errors caused by a wrong dispatch table we need to see the
8091 -- contents of such table.
8093 if Debug_Flag_ZZ then
8094 Write_DT (Typ);
8095 end if;
8097 -- Final stage: Ensure that the table is correct plus some further
8098 -- verifications concerning the primitives.
8100 Prim_Elmt := First_Prim;
8101 DT_Length := 0;
8102 while Present (Prim_Elmt) loop
8103 Prim := Node (Prim_Elmt);
8105 -- At this point all the primitives MUST have a position in the
8106 -- dispatch table.
8108 if DT_Position (Prim) = No_Uint then
8109 raise Program_Error;
8110 end if;
8112 -- Calculate real size of the dispatch table
8114 if not In_Predef_Prims_DT (Prim)
8115 and then UI_To_Int (DT_Position (Prim)) > DT_Length
8116 then
8117 DT_Length := UI_To_Int (DT_Position (Prim));
8118 end if;
8120 -- Ensure that the assigned position to non-predefined dispatching
8121 -- operations in the dispatch table is correct.
8123 if not Is_Predefined_Dispatching_Operation (Prim)
8124 and then not Is_Predefined_Dispatching_Alias (Prim)
8125 then
8126 Validate_Position (Prim);
8127 end if;
8129 if Chars (Prim) = Name_Finalize then
8130 Finalized := True;
8131 end if;
8133 if Chars (Prim) = Name_Adjust then
8134 Adjusted := True;
8135 end if;
8137 -- An abstract operation cannot be declared in the private part for a
8138 -- visible abstract type, because it can't be overridden outside this
8139 -- package hierarchy. For explicit declarations this is checked at
8140 -- the point of declaration, but for inherited operations it must be
8141 -- done when building the dispatch table.
8143 -- Ada 2005 (AI-251): Primitives associated with interfaces are
8144 -- excluded from this check because interfaces must be visible in
8145 -- the public and private part (RM 7.3 (7.3/2))
8147 -- We disable this check in Relaxed_RM_Semantics mode, to accommodate
8148 -- legacy Ada code.
8150 if not Relaxed_RM_Semantics
8151 and then Is_Abstract_Type (Typ)
8152 and then Is_Abstract_Subprogram (Prim)
8153 and then Present (Alias (Prim))
8154 and then not Is_Interface
8155 (Find_Dispatching_Type (Ultimate_Alias (Prim)))
8156 and then not Present (Interface_Alias (Prim))
8157 and then Is_Derived_Type (Typ)
8158 and then In_Private_Part (Current_Scope)
8159 and then
8160 List_Containing (Parent (Prim)) =
8161 Private_Declarations (Package_Specification (Current_Scope))
8162 and then Original_View_In_Visible_Part (Typ)
8163 then
8164 -- We exclude Input and Output stream operations because
8165 -- Limited_Controlled inherits useless Input and Output stream
8166 -- operations from Root_Controlled, which can never be overridden.
8168 if not Is_TSS (Prim, TSS_Stream_Input)
8169 and then
8170 not Is_TSS (Prim, TSS_Stream_Output)
8171 then
8172 Error_Msg_NE
8173 ("abstract inherited private operation&" &
8174 " must be overridden (RM 3.9.3(10))",
8175 Parent (Typ), Prim);
8176 end if;
8177 end if;
8179 Next_Elmt (Prim_Elmt);
8180 end loop;
8182 -- Additional check
8184 if Is_Controlled (Typ) then
8185 if not Finalized then
8186 Error_Msg_N
8187 ("controlled type has no explicit Finalize method??", Typ);
8189 elsif not Adjusted then
8190 Error_Msg_N
8191 ("controlled type has no explicit Adjust method??", Typ);
8192 end if;
8193 end if;
8195 -- Set the final size of the Dispatch Table
8197 Set_DT_Entry_Count (The_Tag, UI_From_Int (DT_Length));
8199 -- The derived type must have at least as many components as its parent
8200 -- (for root types Etype points to itself and the test cannot fail).
8202 if DT_Entry_Count (The_Tag) <
8203 DT_Entry_Count (First_Tag_Component (Parent_Typ))
8204 then
8205 raise Program_Error;
8206 end if;
8207 end Set_All_DT_Position;
8209 --------------------------
8210 -- Set_CPP_Constructors --
8211 --------------------------
8213 procedure Set_CPP_Constructors (Typ : Entity_Id) is
8215 function Gen_Parameters_Profile (E : Entity_Id) return List_Id;
8216 -- Duplicate the parameters profile of the imported C++ constructor
8217 -- adding the "this" pointer to the object as the additional first
8218 -- parameter under the usual form _Init : in out Typ.
8220 ----------------------------
8221 -- Gen_Parameters_Profile --
8222 ----------------------------
8224 function Gen_Parameters_Profile (E : Entity_Id) return List_Id is
8225 Loc : constant Source_Ptr := Sloc (E);
8226 Parms : List_Id;
8227 P : Node_Id;
8229 begin
8230 Parms :=
8231 New_List (
8232 Make_Parameter_Specification (Loc,
8233 Defining_Identifier =>
8234 Make_Defining_Identifier (Loc, Name_uInit),
8235 In_Present => True,
8236 Out_Present => True,
8237 Parameter_Type => New_Occurrence_Of (Typ, Loc)));
8239 if Present (Parameter_Specifications (Parent (E))) then
8240 P := First (Parameter_Specifications (Parent (E)));
8241 while Present (P) loop
8242 Append_To (Parms,
8243 Make_Parameter_Specification (Loc,
8244 Defining_Identifier =>
8245 Make_Defining_Identifier (Loc,
8246 Chars => Chars (Defining_Identifier (P))),
8247 Parameter_Type => New_Copy_Tree (Parameter_Type (P)),
8248 Expression => New_Copy_Tree (Expression (P))));
8249 Next (P);
8250 end loop;
8251 end if;
8253 return Parms;
8254 end Gen_Parameters_Profile;
8256 -- Local variables
8258 Loc : Source_Ptr;
8259 E : Entity_Id;
8260 Found : Boolean := False;
8261 IP : Entity_Id;
8262 IP_Body : Node_Id;
8263 P : Node_Id;
8264 Parms : List_Id;
8266 Covers_Default_Constructor : Entity_Id := Empty;
8268 -- Start of processing for Set_CPP_Constructor
8270 begin
8271 pragma Assert (Is_CPP_Class (Typ));
8273 -- Look for the constructor entities
8275 E := Next_Entity (Typ);
8276 while Present (E) loop
8277 if Ekind (E) = E_Function
8278 and then Is_Constructor (E)
8279 then
8280 Found := True;
8281 Loc := Sloc (E);
8282 Parms := Gen_Parameters_Profile (E);
8283 IP := Make_Defining_Identifier (Loc, Make_Init_Proc_Name (Typ));
8285 -- Case 1: Constructor of untagged type
8287 -- If the C++ class has no virtual methods then the matching Ada
8288 -- type is an untagged record type. In such case there is no need
8289 -- to generate a wrapper of the C++ constructor because the _tag
8290 -- component is not available.
8292 if not Is_Tagged_Type (Typ) then
8293 Discard_Node
8294 (Make_Subprogram_Declaration (Loc,
8295 Specification =>
8296 Make_Procedure_Specification (Loc,
8297 Defining_Unit_Name => IP,
8298 Parameter_Specifications => Parms)));
8300 Set_Init_Proc (Typ, IP);
8301 Set_Is_Imported (IP);
8302 Set_Is_Constructor (IP);
8303 Set_Interface_Name (IP, Interface_Name (E));
8304 Set_Convention (IP, Convention_CPP);
8305 Set_Is_Public (IP);
8306 Set_Has_Completion (IP);
8308 -- Case 2: Constructor of a tagged type
8310 -- In this case we generate the IP routine as a wrapper of the
8311 -- C++ constructor because IP must also save a copy of the _tag
8312 -- generated in the C++ side. The copy of the _tag is used by
8313 -- Build_CPP_Init_Procedure to elaborate derivations of C++ types.
8315 -- Generate:
8316 -- procedure IP (_init : in out Typ; ...) is
8317 -- procedure ConstructorP (_init : in out Typ; ...);
8318 -- pragma Import (ConstructorP);
8319 -- begin
8320 -- ConstructorP (_init, ...);
8321 -- if Typ._tag = null then
8322 -- Typ._tag := _init._tag;
8323 -- end if;
8324 -- end IP;
8326 else
8327 declare
8328 Body_Stmts : constant List_Id := New_List;
8329 Constructor_Id : Entity_Id;
8330 Constructor_Decl_Node : Node_Id;
8331 Init_Tags_List : List_Id;
8333 begin
8334 Constructor_Id := Make_Temporary (Loc, 'P');
8336 Constructor_Decl_Node :=
8337 Make_Subprogram_Declaration (Loc,
8338 Make_Procedure_Specification (Loc,
8339 Defining_Unit_Name => Constructor_Id,
8340 Parameter_Specifications => Parms));
8342 Set_Is_Imported (Constructor_Id);
8343 Set_Is_Constructor (Constructor_Id);
8344 Set_Interface_Name (Constructor_Id, Interface_Name (E));
8345 Set_Convention (Constructor_Id, Convention_CPP);
8346 Set_Is_Public (Constructor_Id);
8347 Set_Has_Completion (Constructor_Id);
8349 -- Build the init procedure as a wrapper of this constructor
8351 Parms := Gen_Parameters_Profile (E);
8353 -- Invoke the C++ constructor
8355 declare
8356 Actuals : constant List_Id := New_List;
8358 begin
8359 P := First (Parms);
8360 while Present (P) loop
8361 Append_To (Actuals,
8362 New_Occurrence_Of (Defining_Identifier (P), Loc));
8363 Next (P);
8364 end loop;
8366 Append_To (Body_Stmts,
8367 Make_Procedure_Call_Statement (Loc,
8368 Name => New_Occurrence_Of (Constructor_Id, Loc),
8369 Parameter_Associations => Actuals));
8370 end;
8372 -- Initialize copies of C++ primary and secondary tags
8374 Init_Tags_List := New_List;
8376 declare
8377 Tag_Elmt : Elmt_Id;
8378 Tag_Comp : Node_Id;
8380 begin
8381 Tag_Elmt := First_Elmt (Access_Disp_Table (Typ));
8382 Tag_Comp := First_Tag_Component (Typ);
8384 while Present (Tag_Elmt)
8385 and then Is_Tag (Node (Tag_Elmt))
8386 loop
8387 -- Skip the following assertion with primary tags
8388 -- because Related_Type is not set on primary tag
8389 -- components.
8391 pragma Assert
8392 (Tag_Comp = First_Tag_Component (Typ)
8393 or else Related_Type (Node (Tag_Elmt))
8394 = Related_Type (Tag_Comp));
8396 Append_To (Init_Tags_List,
8397 Make_Assignment_Statement (Loc,
8398 Name =>
8399 New_Occurrence_Of (Node (Tag_Elmt), Loc),
8400 Expression =>
8401 Make_Selected_Component (Loc,
8402 Prefix =>
8403 Make_Identifier (Loc, Name_uInit),
8404 Selector_Name =>
8405 New_Occurrence_Of (Tag_Comp, Loc))));
8407 Tag_Comp := Next_Tag_Component (Tag_Comp);
8408 Next_Elmt (Tag_Elmt);
8409 end loop;
8410 end;
8412 Append_To (Body_Stmts,
8413 Make_If_Statement (Loc,
8414 Condition =>
8415 Make_Op_Eq (Loc,
8416 Left_Opnd =>
8417 New_Occurrence_Of
8418 (Node (First_Elmt (Access_Disp_Table (Typ))),
8419 Loc),
8420 Right_Opnd =>
8421 Unchecked_Convert_To (RTE (RE_Tag),
8422 New_Occurrence_Of (RTE (RE_Null_Address), Loc))),
8423 Then_Statements => Init_Tags_List));
8425 IP_Body :=
8426 Make_Subprogram_Body (Loc,
8427 Specification =>
8428 Make_Procedure_Specification (Loc,
8429 Defining_Unit_Name => IP,
8430 Parameter_Specifications => Parms),
8431 Declarations => New_List (Constructor_Decl_Node),
8432 Handled_Statement_Sequence =>
8433 Make_Handled_Sequence_Of_Statements (Loc,
8434 Statements => Body_Stmts,
8435 Exception_Handlers => No_List));
8437 Discard_Node (IP_Body);
8438 Set_Init_Proc (Typ, IP);
8439 end;
8440 end if;
8442 -- If this constructor has parameters and all its parameters have
8443 -- defaults then it covers the default constructor. The semantic
8444 -- analyzer ensures that only one constructor with defaults covers
8445 -- the default constructor.
8447 if Present (Parameter_Specifications (Parent (E)))
8448 and then Needs_No_Actuals (E)
8449 then
8450 Covers_Default_Constructor := IP;
8451 end if;
8452 end if;
8454 Next_Entity (E);
8455 end loop;
8457 -- If there are no constructors, mark the type as abstract since we
8458 -- won't be able to declare objects of that type.
8460 if not Found then
8461 Set_Is_Abstract_Type (Typ);
8462 end if;
8464 -- Handle constructor that has all its parameters with defaults and
8465 -- hence it covers the default constructor. We generate a wrapper IP
8466 -- which calls the covering constructor.
8468 if Present (Covers_Default_Constructor) then
8469 declare
8470 Body_Stmts : List_Id;
8472 begin
8473 Loc := Sloc (Covers_Default_Constructor);
8475 Body_Stmts := New_List (
8476 Make_Procedure_Call_Statement (Loc,
8477 Name =>
8478 New_Occurrence_Of (Covers_Default_Constructor, Loc),
8479 Parameter_Associations => New_List (
8480 Make_Identifier (Loc, Name_uInit))));
8482 IP := Make_Defining_Identifier (Loc, Make_Init_Proc_Name (Typ));
8484 IP_Body :=
8485 Make_Subprogram_Body (Loc,
8486 Specification =>
8487 Make_Procedure_Specification (Loc,
8488 Defining_Unit_Name => IP,
8489 Parameter_Specifications => New_List (
8490 Make_Parameter_Specification (Loc,
8491 Defining_Identifier =>
8492 Make_Defining_Identifier (Loc, Name_uInit),
8493 Parameter_Type => New_Occurrence_Of (Typ, Loc)))),
8495 Declarations => No_List,
8497 Handled_Statement_Sequence =>
8498 Make_Handled_Sequence_Of_Statements (Loc,
8499 Statements => Body_Stmts,
8500 Exception_Handlers => No_List));
8502 Discard_Node (IP_Body);
8503 Set_Init_Proc (Typ, IP);
8504 end;
8505 end if;
8507 -- If the CPP type has constructors then it must import also the default
8508 -- C++ constructor. It is required for default initialization of objects
8509 -- of the type. It is also required to elaborate objects of Ada types
8510 -- that are defined as derivations of this CPP type.
8512 if Has_CPP_Constructors (Typ)
8513 and then No (Init_Proc (Typ))
8514 then
8515 Error_Msg_N ("??default constructor must be imported from C++", Typ);
8516 end if;
8517 end Set_CPP_Constructors;
8519 ---------------------------
8520 -- Set_DT_Position_Value --
8521 ---------------------------
8523 procedure Set_DT_Position_Value (Prim : Entity_Id; Value : Uint) is
8524 begin
8525 Set_DT_Position (Prim, Value);
8527 -- Propagate the value to the wrapped subprogram (if one is present)
8529 if Ekind_In (Prim, E_Function, E_Procedure)
8530 and then Is_Primitive_Wrapper (Prim)
8531 and then Present (Wrapped_Entity (Prim))
8532 and then Is_Dispatching_Operation (Wrapped_Entity (Prim))
8533 then
8534 Set_DT_Position (Wrapped_Entity (Prim), Value);
8535 end if;
8536 end Set_DT_Position_Value;
8538 --------------------------
8539 -- Set_DTC_Entity_Value --
8540 --------------------------
8542 procedure Set_DTC_Entity_Value
8543 (Tagged_Type : Entity_Id;
8544 Prim : Entity_Id)
8546 begin
8547 if Present (Interface_Alias (Prim))
8548 and then Is_Interface
8549 (Find_Dispatching_Type (Interface_Alias (Prim)))
8550 then
8551 Set_DTC_Entity (Prim,
8552 Find_Interface_Tag
8553 (T => Tagged_Type,
8554 Iface => Find_Dispatching_Type (Interface_Alias (Prim))));
8555 else
8556 Set_DTC_Entity (Prim,
8557 First_Tag_Component (Tagged_Type));
8558 end if;
8560 -- Propagate the value to the wrapped subprogram (if one is present)
8562 if Ekind_In (Prim, E_Function, E_Procedure)
8563 and then Is_Primitive_Wrapper (Prim)
8564 and then Present (Wrapped_Entity (Prim))
8565 and then Is_Dispatching_Operation (Wrapped_Entity (Prim))
8566 then
8567 Set_DTC_Entity (Wrapped_Entity (Prim), DTC_Entity (Prim));
8568 end if;
8569 end Set_DTC_Entity_Value;
8571 -----------------
8572 -- Tagged_Kind --
8573 -----------------
8575 function Tagged_Kind (T : Entity_Id) return Node_Id is
8576 Conc_Typ : Entity_Id;
8577 Loc : constant Source_Ptr := Sloc (T);
8579 begin
8580 pragma Assert
8581 (Is_Tagged_Type (T) and then RTE_Available (RE_Tagged_Kind));
8583 -- Abstract kinds
8585 if Is_Abstract_Type (T) then
8586 if Is_Limited_Record (T) then
8587 return New_Occurrence_Of
8588 (RTE (RE_TK_Abstract_Limited_Tagged), Loc);
8589 else
8590 return New_Occurrence_Of
8591 (RTE (RE_TK_Abstract_Tagged), Loc);
8592 end if;
8594 -- Concurrent kinds
8596 elsif Is_Concurrent_Record_Type (T) then
8597 Conc_Typ := Corresponding_Concurrent_Type (T);
8599 if Present (Full_View (Conc_Typ)) then
8600 Conc_Typ := Full_View (Conc_Typ);
8601 end if;
8603 if Ekind (Conc_Typ) = E_Protected_Type then
8604 return New_Occurrence_Of (RTE (RE_TK_Protected), Loc);
8605 else
8606 pragma Assert (Ekind (Conc_Typ) = E_Task_Type);
8607 return New_Occurrence_Of (RTE (RE_TK_Task), Loc);
8608 end if;
8610 -- Regular tagged kinds
8612 else
8613 if Is_Limited_Record (T) then
8614 return New_Occurrence_Of (RTE (RE_TK_Limited_Tagged), Loc);
8615 else
8616 return New_Occurrence_Of (RTE (RE_TK_Tagged), Loc);
8617 end if;
8618 end if;
8619 end Tagged_Kind;
8621 --------------
8622 -- Write_DT --
8623 --------------
8625 procedure Write_DT (Typ : Entity_Id) is
8626 Elmt : Elmt_Id;
8627 Prim : Node_Id;
8629 begin
8630 -- Protect this procedure against wrong usage. Required because it will
8631 -- be used directly from GDB
8633 if not (Typ <= Last_Node_Id)
8634 or else not Is_Tagged_Type (Typ)
8635 then
8636 Write_Str ("wrong usage: Write_DT must be used with tagged types");
8637 Write_Eol;
8638 return;
8639 end if;
8641 Write_Int (Int (Typ));
8642 Write_Str (": ");
8643 Write_Name (Chars (Typ));
8645 if Is_Interface (Typ) then
8646 Write_Str (" is interface");
8647 end if;
8649 Write_Eol;
8651 Elmt := First_Elmt (Primitive_Operations (Typ));
8652 while Present (Elmt) loop
8653 Prim := Node (Elmt);
8654 Write_Str (" - ");
8656 -- Indicate if this primitive will be allocated in the primary
8657 -- dispatch table or in a secondary dispatch table associated
8658 -- with an abstract interface type
8660 if Present (DTC_Entity (Prim)) then
8661 if Etype (DTC_Entity (Prim)) = RTE (RE_Tag) then
8662 Write_Str ("[P] ");
8663 else
8664 Write_Str ("[s] ");
8665 end if;
8666 end if;
8668 -- Output the node of this primitive operation and its name
8670 Write_Int (Int (Prim));
8671 Write_Str (": ");
8673 if Is_Predefined_Dispatching_Operation (Prim) then
8674 Write_Str ("(predefined) ");
8675 end if;
8677 -- Prefix the name of the primitive with its corresponding tagged
8678 -- type to facilitate seeing inherited primitives.
8680 if Present (Alias (Prim)) then
8681 Write_Name
8682 (Chars (Find_Dispatching_Type (Ultimate_Alias (Prim))));
8683 else
8684 Write_Name (Chars (Typ));
8685 end if;
8687 Write_Str (".");
8688 Write_Name (Chars (Prim));
8690 -- Indicate if this primitive has an aliased primitive
8692 if Present (Alias (Prim)) then
8693 Write_Str (" (alias = ");
8694 Write_Int (Int (Alias (Prim)));
8696 -- If the DTC_Entity attribute is already set we can also output
8697 -- the name of the interface covered by this primitive (if any).
8699 if Ekind_In (Alias (Prim), E_Function, E_Procedure)
8700 and then Present (DTC_Entity (Alias (Prim)))
8701 and then Is_Interface (Scope (DTC_Entity (Alias (Prim))))
8702 then
8703 Write_Str (" from interface ");
8704 Write_Name (Chars (Scope (DTC_Entity (Alias (Prim)))));
8705 end if;
8707 if Present (Interface_Alias (Prim)) then
8708 Write_Str (", AI_Alias of ");
8710 if Is_Null_Interface_Primitive (Interface_Alias (Prim)) then
8711 Write_Str ("null primitive ");
8712 end if;
8714 Write_Name
8715 (Chars (Find_Dispatching_Type (Interface_Alias (Prim))));
8716 Write_Char (':');
8717 Write_Int (Int (Interface_Alias (Prim)));
8718 end if;
8720 Write_Str (")");
8721 end if;
8723 -- Display the final position of this primitive in its associated
8724 -- (primary or secondary) dispatch table.
8726 if Present (DTC_Entity (Prim))
8727 and then DT_Position (Prim) /= No_Uint
8728 then
8729 Write_Str (" at #");
8730 Write_Int (UI_To_Int (DT_Position (Prim)));
8731 end if;
8733 if Is_Abstract_Subprogram (Prim) then
8734 Write_Str (" is abstract;");
8736 -- Check if this is a null primitive
8738 elsif Comes_From_Source (Prim)
8739 and then Ekind (Prim) = E_Procedure
8740 and then Null_Present (Parent (Prim))
8741 then
8742 Write_Str (" is null;");
8743 end if;
8745 if Is_Eliminated (Ultimate_Alias (Prim)) then
8746 Write_Str (" (eliminated)");
8747 end if;
8749 if Is_Imported (Prim)
8750 and then Convention (Prim) = Convention_CPP
8751 then
8752 Write_Str (" (C++)");
8753 end if;
8755 Write_Eol;
8757 Next_Elmt (Elmt);
8758 end loop;
8759 end Write_DT;
8761 end Exp_Disp;