* contrib-list.mk (LIST): Remove arm-freebsd6, arm-linux,
[official-gcc.git] / gcc / ada / exp_disp.adb
blobf2482826356006c5da69d8418493f4c9d8ce7eb7
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-2012, 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 Exp_Atag; use Exp_Atag;
33 with Exp_Ch6; use Exp_Ch6;
34 with Exp_CG; use Exp_CG;
35 with Exp_Dbug; use Exp_Dbug;
36 with Exp_Tss; use Exp_Tss;
37 with Exp_Util; use Exp_Util;
38 with Freeze; use Freeze;
39 with Itypes; use Itypes;
40 with Layout; use Layout;
41 with Nlists; use Nlists;
42 with Nmake; use Nmake;
43 with Namet; use Namet;
44 with Opt; use Opt;
45 with Output; use Output;
46 with Restrict; use Restrict;
47 with Rident; use Rident;
48 with Rtsfind; use Rtsfind;
49 with Sem; use Sem;
50 with Sem_Aux; use Sem_Aux;
51 with Sem_Ch6; use Sem_Ch6;
52 with Sem_Ch7; use Sem_Ch7;
53 with Sem_Ch8; use Sem_Ch8;
54 with Sem_Disp; use Sem_Disp;
55 with Sem_Eval; use Sem_Eval;
56 with Sem_Res; use Sem_Res;
57 with Sem_Type; use Sem_Type;
58 with Sem_Util; use Sem_Util;
59 with Sinfo; use Sinfo;
60 with Snames; use Snames;
61 with Stand; use Stand;
62 with Stringt; use Stringt;
63 with SCIL_LL; use SCIL_LL;
64 with Targparm; use Targparm;
65 with Tbuild; use Tbuild;
66 with Uintp; use Uintp;
68 package body Exp_Disp is
70 -----------------------
71 -- Local Subprograms --
72 -----------------------
74 function Default_Prim_Op_Position (E : Entity_Id) return Uint;
75 -- Ada 2005 (AI-251): Returns the fixed position in the dispatch table
76 -- of the default primitive operations.
78 function Find_Specific_Type (CW : Entity_Id) return Entity_Id;
79 -- Find specific type of a class-wide type, and handle the case of an
80 -- incomplete type coming either from a limited_with clause or from an
81 -- incomplete type declaration. Shouldn't this be in Sem_Util? It seems
82 -- like a general purpose semantic routine ???
84 function Has_DT (Typ : Entity_Id) return Boolean;
85 pragma Inline (Has_DT);
86 -- Returns true if we generate a dispatch table for tagged type Typ
88 function Is_Predefined_Dispatching_Alias (Prim : Entity_Id) return Boolean;
89 -- Returns true if Prim is not a predefined dispatching primitive but it is
90 -- an alias of a predefined dispatching primitive (i.e. through a renaming)
92 function New_Value (From : Node_Id) return Node_Id;
93 -- From is the original Expression. New_Value is equivalent to a call
94 -- to Duplicate_Subexpr with an explicit dereference when From is an
95 -- access parameter.
97 function Original_View_In_Visible_Part (Typ : Entity_Id) return Boolean;
98 -- Check if the type has a private view or if the public view appears
99 -- in the visible part of a package spec.
101 function Prim_Op_Kind
102 (Prim : Entity_Id;
103 Typ : Entity_Id) return Node_Id;
104 -- Ada 2005 (AI-345): Determine the primitive operation kind of Prim
105 -- according to its type Typ. Return a reference to an RE_Prim_Op_Kind
106 -- enumeration value.
108 function Tagged_Kind (T : Entity_Id) return Node_Id;
109 -- Ada 2005 (AI-345): Determine the tagged kind of T and return a reference
110 -- to an RE_Tagged_Kind enumeration value.
112 ----------------------
113 -- Apply_Tag_Checks --
114 ----------------------
116 procedure Apply_Tag_Checks (Call_Node : Node_Id) is
117 Loc : constant Source_Ptr := Sloc (Call_Node);
118 Ctrl_Arg : constant Node_Id := Controlling_Argument (Call_Node);
119 Ctrl_Typ : constant Entity_Id := Base_Type (Etype (Ctrl_Arg));
120 Param_List : constant List_Id := Parameter_Associations (Call_Node);
122 Subp : Entity_Id;
123 CW_Typ : Entity_Id;
124 Param : Node_Id;
125 Typ : Entity_Id;
126 Eq_Prim_Op : Entity_Id := Empty;
128 begin
129 if No_Run_Time_Mode then
130 Error_Msg_CRT ("tagged types", Call_Node);
131 return;
132 end if;
134 -- Apply_Tag_Checks is called directly from the semantics, so we need
135 -- a check to see whether expansion is active before proceeding. In
136 -- addition, there is no need to expand the call when compiling under
137 -- restriction No_Dispatching_Calls; the semantic analyzer has
138 -- previously notified the violation of this restriction.
140 if not Expander_Active
141 or else Restriction_Active (No_Dispatching_Calls)
142 then
143 return;
144 end if;
146 -- Set subprogram. If this is an inherited operation that was
147 -- overridden, the body that is being called is its alias.
149 Subp := Entity (Name (Call_Node));
151 if Present (Alias (Subp))
152 and then Is_Inherited_Operation (Subp)
153 and then No (DTC_Entity (Subp))
154 then
155 Subp := Alias (Subp);
156 end if;
158 -- Definition of the class-wide type and the tagged type
160 -- If the controlling argument is itself a tag rather than a tagged
161 -- object, then use the class-wide type associated with the subprogram's
162 -- controlling type. This case can occur when a call to an inherited
163 -- primitive has an actual that originated from a default parameter
164 -- given by a tag-indeterminate call and when there is no other
165 -- controlling argument providing the tag (AI-239 requires dispatching).
166 -- This capability of dispatching directly by tag is also needed by the
167 -- implementation of AI-260 (for the generic dispatching constructors).
169 if Ctrl_Typ = RTE (RE_Tag)
170 or else (RTE_Available (RE_Interface_Tag)
171 and then Ctrl_Typ = RTE (RE_Interface_Tag))
172 then
173 CW_Typ := Class_Wide_Type (Find_Dispatching_Type (Subp));
175 -- Class_Wide_Type is applied to the expressions used to initialize
176 -- CW_Typ, to ensure that CW_Typ always denotes a class-wide type, since
177 -- there are cases where the controlling type is resolved to a specific
178 -- type (such as for designated types of arguments such as CW'Access).
180 elsif Is_Access_Type (Ctrl_Typ) then
181 CW_Typ := Class_Wide_Type (Designated_Type (Ctrl_Typ));
183 else
184 CW_Typ := Class_Wide_Type (Ctrl_Typ);
185 end if;
187 Typ := Find_Specific_Type (CW_Typ);
189 if not Is_Limited_Type (Typ) then
190 Eq_Prim_Op := Find_Prim_Op (Typ, Name_Op_Eq);
191 end if;
193 -- Dispatching call to C++ primitive
195 if Is_CPP_Class (Typ) then
196 null;
198 -- Dispatching call to Ada primitive
200 elsif Present (Param_List) then
202 -- Generate the Tag checks when appropriate
204 Param := First_Actual (Call_Node);
205 while Present (Param) loop
207 -- No tag check with itself
209 if Param = Ctrl_Arg then
210 null;
212 -- No tag check for parameter whose type is neither tagged nor
213 -- access to tagged (for access parameters)
215 elsif No (Find_Controlling_Arg (Param)) then
216 null;
218 -- No tag check for function dispatching on result if the
219 -- Tag given by the context is this one
221 elsif Find_Controlling_Arg (Param) = Ctrl_Arg then
222 null;
224 -- "=" is the only dispatching operation allowed to get
225 -- operands with incompatible tags (it just returns false).
226 -- We use Duplicate_Subexpr_Move_Checks instead of calling
227 -- Relocate_Node because the value will be duplicated to
228 -- check the tags.
230 elsif Subp = Eq_Prim_Op then
231 null;
233 -- No check in presence of suppress flags
235 elsif Tag_Checks_Suppressed (Etype (Param))
236 or else (Is_Access_Type (Etype (Param))
237 and then Tag_Checks_Suppressed
238 (Designated_Type (Etype (Param))))
239 then
240 null;
242 -- Optimization: no tag checks if the parameters are identical
244 elsif Is_Entity_Name (Param)
245 and then Is_Entity_Name (Ctrl_Arg)
246 and then Entity (Param) = Entity (Ctrl_Arg)
247 then
248 null;
250 -- Now we need to generate the Tag check
252 else
253 -- Generate code for tag equality check
254 -- Perhaps should have Checks.Apply_Tag_Equality_Check???
256 Insert_Action (Ctrl_Arg,
257 Make_Implicit_If_Statement (Call_Node,
258 Condition =>
259 Make_Op_Ne (Loc,
260 Left_Opnd =>
261 Make_Selected_Component (Loc,
262 Prefix => New_Value (Ctrl_Arg),
263 Selector_Name =>
264 New_Reference_To
265 (First_Tag_Component (Typ), Loc)),
267 Right_Opnd =>
268 Make_Selected_Component (Loc,
269 Prefix =>
270 Unchecked_Convert_To (Typ, New_Value (Param)),
271 Selector_Name =>
272 New_Reference_To
273 (First_Tag_Component (Typ), Loc))),
275 Then_Statements =>
276 New_List (New_Constraint_Error (Loc))));
277 end if;
279 Next_Actual (Param);
280 end loop;
281 end if;
282 end Apply_Tag_Checks;
284 ------------------------
285 -- Building_Static_DT --
286 ------------------------
288 function Building_Static_DT (Typ : Entity_Id) return Boolean is
289 Root_Typ : Entity_Id := Root_Type (Typ);
291 begin
292 -- Handle private types
294 if Present (Full_View (Root_Typ)) then
295 Root_Typ := Full_View (Root_Typ);
296 end if;
298 return Static_Dispatch_Tables
299 and then Is_Library_Level_Tagged_Type (Typ)
300 and then VM_Target = No_VM
302 -- If the type is derived from a CPP class we cannot statically
303 -- build the dispatch tables because we must inherit primitives
304 -- from the CPP side.
306 and then not Is_CPP_Class (Root_Typ);
307 end Building_Static_DT;
309 ----------------------------------
310 -- Build_Static_Dispatch_Tables --
311 ----------------------------------
313 procedure Build_Static_Dispatch_Tables (N : Entity_Id) is
314 Target_List : List_Id;
316 procedure Build_Dispatch_Tables (List : List_Id);
317 -- Build the static dispatch table of tagged types found in the list of
318 -- declarations. The generated nodes are added at the end of Target_List
320 procedure Build_Package_Dispatch_Tables (N : Node_Id);
321 -- Build static dispatch tables associated with package declaration N
323 ---------------------------
324 -- Build_Dispatch_Tables --
325 ---------------------------
327 procedure Build_Dispatch_Tables (List : List_Id) is
328 D : Node_Id;
330 begin
331 D := First (List);
332 while Present (D) loop
334 -- Handle nested packages and package bodies recursively. The
335 -- generated code is placed on the Target_List established for
336 -- the enclosing compilation unit.
338 if Nkind (D) = N_Package_Declaration then
339 Build_Package_Dispatch_Tables (D);
341 elsif Nkind (D) = N_Package_Body then
342 Build_Dispatch_Tables (Declarations (D));
344 elsif Nkind (D) = N_Package_Body_Stub
345 and then Present (Library_Unit (D))
346 then
347 Build_Dispatch_Tables
348 (Declarations (Proper_Body (Unit (Library_Unit (D)))));
350 -- Handle full type declarations and derivations of library
351 -- level tagged types
353 elsif Nkind_In (D, N_Full_Type_Declaration,
354 N_Derived_Type_Definition)
355 and then Is_Library_Level_Tagged_Type (Defining_Entity (D))
356 and then Ekind (Defining_Entity (D)) /= E_Record_Subtype
357 and then not Is_Private_Type (Defining_Entity (D))
358 then
359 -- We do not generate dispatch tables for the internal types
360 -- created for a type extension with unknown discriminants
361 -- The needed information is shared with the source type,
362 -- See Expand_N_Record_Extension.
364 if Is_Underlying_Record_View (Defining_Entity (D))
365 or else
366 (not Comes_From_Source (Defining_Entity (D))
367 and then
368 Has_Unknown_Discriminants (Etype (Defining_Entity (D)))
369 and then
370 not Comes_From_Source
371 (First_Subtype (Defining_Entity (D))))
372 then
373 null;
374 else
375 Insert_List_After_And_Analyze (Last (Target_List),
376 Make_DT (Defining_Entity (D)));
377 end if;
379 -- Handle private types of library level tagged types. We must
380 -- exchange the private and full-view to ensure the correct
381 -- expansion. If the full view is a synchronized type ignore
382 -- the type because the table will be built for the corresponding
383 -- record type, that has its own declaration.
385 elsif (Nkind (D) = N_Private_Type_Declaration
386 or else Nkind (D) = N_Private_Extension_Declaration)
387 and then Present (Full_View (Defining_Entity (D)))
388 then
389 declare
390 E1 : constant Entity_Id := Defining_Entity (D);
391 E2 : constant Entity_Id := Full_View (E1);
393 begin
394 if Is_Library_Level_Tagged_Type (E2)
395 and then Ekind (E2) /= E_Record_Subtype
396 and then not Is_Concurrent_Type (E2)
397 then
398 Exchange_Declarations (E1);
399 Insert_List_After_And_Analyze (Last (Target_List),
400 Make_DT (E1));
401 Exchange_Declarations (E2);
402 end if;
403 end;
404 end if;
406 Next (D);
407 end loop;
408 end Build_Dispatch_Tables;
410 -----------------------------------
411 -- Build_Package_Dispatch_Tables --
412 -----------------------------------
414 procedure Build_Package_Dispatch_Tables (N : Node_Id) is
415 Spec : constant Node_Id := Specification (N);
416 Id : constant Entity_Id := Defining_Entity (N);
417 Vis_Decls : constant List_Id := Visible_Declarations (Spec);
418 Priv_Decls : constant List_Id := Private_Declarations (Spec);
420 begin
421 Push_Scope (Id);
423 if Present (Priv_Decls) then
424 Build_Dispatch_Tables (Vis_Decls);
425 Build_Dispatch_Tables (Priv_Decls);
427 elsif Present (Vis_Decls) then
428 Build_Dispatch_Tables (Vis_Decls);
429 end if;
431 Pop_Scope;
432 end Build_Package_Dispatch_Tables;
434 -- Start of processing for Build_Static_Dispatch_Tables
436 begin
437 if not Expander_Active
438 or else not Tagged_Type_Expansion
439 then
440 return;
441 end if;
443 if Nkind (N) = N_Package_Declaration then
444 declare
445 Spec : constant Node_Id := Specification (N);
446 Vis_Decls : constant List_Id := Visible_Declarations (Spec);
447 Priv_Decls : constant List_Id := Private_Declarations (Spec);
449 begin
450 if Present (Priv_Decls)
451 and then Is_Non_Empty_List (Priv_Decls)
452 then
453 Target_List := Priv_Decls;
455 elsif not Present (Vis_Decls) then
456 Target_List := New_List;
457 Set_Private_Declarations (Spec, Target_List);
458 else
459 Target_List := Vis_Decls;
460 end if;
462 Build_Package_Dispatch_Tables (N);
463 end;
465 else pragma Assert (Nkind (N) = N_Package_Body);
466 Target_List := Declarations (N);
467 Build_Dispatch_Tables (Target_List);
468 end if;
469 end Build_Static_Dispatch_Tables;
471 ------------------------------
472 -- Convert_Tag_To_Interface --
473 ------------------------------
475 function Convert_Tag_To_Interface
476 (Typ : Entity_Id;
477 Expr : Node_Id) return Node_Id
479 Loc : constant Source_Ptr := Sloc (Expr);
480 Anon_Type : Entity_Id;
481 Result : Node_Id;
483 begin
484 pragma Assert (Is_Class_Wide_Type (Typ)
485 and then Is_Interface (Typ)
486 and then
487 ((Nkind (Expr) = N_Selected_Component
488 and then Is_Tag (Entity (Selector_Name (Expr))))
489 or else
490 (Nkind (Expr) = N_Function_Call
491 and then RTE_Available (RE_Displace)
492 and then Entity (Name (Expr)) = RTE (RE_Displace))));
494 Anon_Type := Create_Itype (E_Anonymous_Access_Type, Expr);
495 Set_Directly_Designated_Type (Anon_Type, Typ);
496 Set_Etype (Anon_Type, Anon_Type);
497 Set_Can_Never_Be_Null (Anon_Type);
499 -- Decorate the size and alignment attributes of the anonymous access
500 -- type, as required by gigi.
502 Layout_Type (Anon_Type);
504 if Nkind (Expr) = N_Selected_Component
505 and then Is_Tag (Entity (Selector_Name (Expr)))
506 then
507 Result :=
508 Make_Explicit_Dereference (Loc,
509 Unchecked_Convert_To (Anon_Type,
510 Make_Attribute_Reference (Loc,
511 Prefix => Expr,
512 Attribute_Name => Name_Address)));
513 else
514 Result :=
515 Make_Explicit_Dereference (Loc,
516 Unchecked_Convert_To (Anon_Type, Expr));
517 end if;
519 return Result;
520 end Convert_Tag_To_Interface;
522 -------------------
523 -- CPP_Num_Prims --
524 -------------------
526 function CPP_Num_Prims (Typ : Entity_Id) return Nat is
527 CPP_Typ : Entity_Id;
528 Tag_Comp : Entity_Id;
530 begin
531 if not Is_Tagged_Type (Typ)
532 or else not Is_CPP_Class (Root_Type (Typ))
533 then
534 return 0;
536 else
537 CPP_Typ := Enclosing_CPP_Parent (Typ);
538 Tag_Comp := First_Tag_Component (CPP_Typ);
540 -- If the number of primitives is already set in the tag component
541 -- then use it
543 if Present (Tag_Comp)
544 and then DT_Entry_Count (Tag_Comp) /= No_Uint
545 then
546 return UI_To_Int (DT_Entry_Count (Tag_Comp));
548 -- Otherwise, count the primitives of the enclosing CPP type
550 else
551 declare
552 Count : Nat := 0;
553 Elmt : Elmt_Id;
555 begin
556 Elmt := First_Elmt (Primitive_Operations (CPP_Typ));
557 while Present (Elmt) loop
558 Count := Count + 1;
559 Next_Elmt (Elmt);
560 end loop;
562 return Count;
563 end;
564 end if;
565 end if;
566 end CPP_Num_Prims;
568 ------------------------------
569 -- Default_Prim_Op_Position --
570 ------------------------------
572 function Default_Prim_Op_Position (E : Entity_Id) return Uint is
573 TSS_Name : TSS_Name_Type;
575 begin
576 Get_Name_String (Chars (E));
577 TSS_Name :=
578 TSS_Name_Type
579 (Name_Buffer (Name_Len - TSS_Name'Length + 1 .. Name_Len));
581 if Chars (E) = Name_uSize then
582 return Uint_1;
584 elsif TSS_Name = TSS_Stream_Read then
585 return Uint_2;
587 elsif TSS_Name = TSS_Stream_Write then
588 return Uint_3;
590 elsif TSS_Name = TSS_Stream_Input then
591 return Uint_4;
593 elsif TSS_Name = TSS_Stream_Output then
594 return Uint_5;
596 elsif Chars (E) = Name_Op_Eq then
597 return Uint_6;
599 elsif Chars (E) = Name_uAssign then
600 return Uint_7;
602 elsif TSS_Name = TSS_Deep_Adjust then
603 return Uint_8;
605 elsif TSS_Name = TSS_Deep_Finalize then
606 return Uint_9;
608 -- In VM targets unconditionally allow obtaining the position associated
609 -- with predefined interface primitives since in these platforms any
610 -- tagged type has these primitives.
612 elsif Ada_Version >= Ada_2005 or else not Tagged_Type_Expansion then
613 if Chars (E) = Name_uDisp_Asynchronous_Select then
614 return Uint_10;
616 elsif Chars (E) = Name_uDisp_Conditional_Select then
617 return Uint_11;
619 elsif Chars (E) = Name_uDisp_Get_Prim_Op_Kind then
620 return Uint_12;
622 elsif Chars (E) = Name_uDisp_Get_Task_Id then
623 return Uint_13;
625 elsif Chars (E) = Name_uDisp_Requeue then
626 return Uint_14;
628 elsif Chars (E) = Name_uDisp_Timed_Select then
629 return Uint_15;
630 end if;
631 end if;
633 raise Program_Error;
634 end Default_Prim_Op_Position;
636 -----------------------------
637 -- Expand_Dispatching_Call --
638 -----------------------------
640 procedure Expand_Dispatching_Call (Call_Node : Node_Id) is
641 Loc : constant Source_Ptr := Sloc (Call_Node);
642 Call_Typ : constant Entity_Id := Etype (Call_Node);
644 Ctrl_Arg : constant Node_Id := Controlling_Argument (Call_Node);
645 Ctrl_Typ : constant Entity_Id := Base_Type (Etype (Ctrl_Arg));
646 Param_List : constant List_Id := Parameter_Associations (Call_Node);
648 Subp : Entity_Id;
649 CW_Typ : Entity_Id;
650 New_Call : Node_Id;
651 New_Call_Name : Node_Id;
652 New_Params : List_Id := No_List;
653 Param : Node_Id;
654 Res_Typ : Entity_Id;
655 Subp_Ptr_Typ : Entity_Id;
656 Subp_Typ : Entity_Id;
657 Typ : Entity_Id;
658 Eq_Prim_Op : Entity_Id := Empty;
659 Controlling_Tag : Node_Id;
661 function New_Value (From : Node_Id) return Node_Id;
662 -- From is the original Expression. New_Value is equivalent to a call
663 -- to Duplicate_Subexpr with an explicit dereference when From is an
664 -- access parameter.
666 ---------------
667 -- New_Value --
668 ---------------
670 function New_Value (From : Node_Id) return Node_Id is
671 Res : constant Node_Id := Duplicate_Subexpr (From);
672 begin
673 if Is_Access_Type (Etype (From)) then
674 return
675 Make_Explicit_Dereference (Sloc (From),
676 Prefix => Res);
677 else
678 return Res;
679 end if;
680 end New_Value;
682 -- Local variables
684 New_Node : Node_Id;
685 SCIL_Node : Node_Id;
686 SCIL_Related_Node : Node_Id := Call_Node;
688 -- Start of processing for Expand_Dispatching_Call
690 begin
691 if No_Run_Time_Mode then
692 Error_Msg_CRT ("tagged types", Call_Node);
693 return;
694 end if;
696 -- Expand_Dispatching_Call is called directly from the semantics,
697 -- so we only proceed if the expander is active.
699 if not Full_Expander_Active
701 -- And there is no need to expand the call if we are compiling under
702 -- restriction No_Dispatching_Calls; the semantic analyzer has
703 -- previously notified the violation of this restriction.
705 or else Restriction_Active (No_Dispatching_Calls)
706 then
707 return;
708 end if;
710 -- Set subprogram. If this is an inherited operation that was
711 -- overridden, the body that is being called is its alias.
713 Subp := Entity (Name (Call_Node));
715 if Present (Alias (Subp))
716 and then Is_Inherited_Operation (Subp)
717 and then No (DTC_Entity (Subp))
718 then
719 Subp := Alias (Subp);
720 end if;
722 -- Definition of the class-wide type and the tagged type
724 -- If the controlling argument is itself a tag rather than a tagged
725 -- object, then use the class-wide type associated with the subprogram's
726 -- controlling type. This case can occur when a call to an inherited
727 -- primitive has an actual that originated from a default parameter
728 -- given by a tag-indeterminate call and when there is no other
729 -- controlling argument providing the tag (AI-239 requires dispatching).
730 -- This capability of dispatching directly by tag is also needed by the
731 -- implementation of AI-260 (for the generic dispatching constructors).
733 if Ctrl_Typ = RTE (RE_Tag)
734 or else (RTE_Available (RE_Interface_Tag)
735 and then Ctrl_Typ = RTE (RE_Interface_Tag))
736 then
737 CW_Typ := Class_Wide_Type (Find_Dispatching_Type (Subp));
739 -- Class_Wide_Type is applied to the expressions used to initialize
740 -- CW_Typ, to ensure that CW_Typ always denotes a class-wide type, since
741 -- there are cases where the controlling type is resolved to a specific
742 -- type (such as for designated types of arguments such as CW'Access).
744 elsif Is_Access_Type (Ctrl_Typ) then
745 CW_Typ := Class_Wide_Type (Designated_Type (Ctrl_Typ));
747 else
748 CW_Typ := Class_Wide_Type (Ctrl_Typ);
749 end if;
751 Typ := Find_Specific_Type (CW_Typ);
753 if not Is_Limited_Type (Typ) then
754 Eq_Prim_Op := Find_Prim_Op (Typ, Name_Op_Eq);
755 end if;
757 -- Dispatching call to C++ primitive. Create a new parameter list
758 -- with no tag checks.
760 New_Params := New_List;
762 if Is_CPP_Class (Typ) then
763 Param := First_Actual (Call_Node);
764 while Present (Param) loop
765 Append_To (New_Params, Relocate_Node (Param));
766 Next_Actual (Param);
767 end loop;
769 -- Dispatching call to Ada primitive
771 elsif Present (Param_List) then
772 Apply_Tag_Checks (Call_Node);
774 Param := First_Actual (Call_Node);
775 while Present (Param) loop
776 -- Cases in which we may have generated runtime checks
778 if Param = Ctrl_Arg
779 or else Subp = Eq_Prim_Op
780 then
781 Append_To (New_Params,
782 Duplicate_Subexpr_Move_Checks (Param));
784 elsif Nkind (Parent (Param)) /= N_Parameter_Association
785 or else not Is_Accessibility_Actual (Parent (Param))
786 then
787 Append_To (New_Params, Relocate_Node (Param));
788 end if;
790 Next_Actual (Param);
791 end loop;
792 end if;
794 -- Generate the appropriate subprogram pointer type
796 if Etype (Subp) = Typ then
797 Res_Typ := CW_Typ;
798 else
799 Res_Typ := Etype (Subp);
800 end if;
802 Subp_Typ := Create_Itype (E_Subprogram_Type, Call_Node);
803 Subp_Ptr_Typ := Create_Itype (E_Access_Subprogram_Type, Call_Node);
804 Set_Etype (Subp_Typ, Res_Typ);
805 Set_Returns_By_Ref (Subp_Typ, Returns_By_Ref (Subp));
806 Set_Convention (Subp_Typ, Convention (Subp));
808 -- Notify gigi that the designated type is a dispatching primitive
810 Set_Is_Dispatch_Table_Entity (Subp_Typ);
812 -- Create a new list of parameters which is a copy of the old formal
813 -- list including the creation of a new set of matching entities.
815 declare
816 Old_Formal : Entity_Id := First_Formal (Subp);
817 New_Formal : Entity_Id;
818 Extra : Entity_Id := Empty;
820 begin
821 if Present (Old_Formal) then
822 New_Formal := New_Copy (Old_Formal);
823 Set_First_Entity (Subp_Typ, New_Formal);
824 Param := First_Actual (Call_Node);
826 loop
827 Set_Scope (New_Formal, Subp_Typ);
829 -- Change all the controlling argument types to be class-wide
830 -- to avoid a recursion in dispatching.
832 if Is_Controlling_Formal (New_Formal) then
833 Set_Etype (New_Formal, Etype (Param));
834 end if;
836 -- If the type of the formal is an itype, there was code here
837 -- introduced in 1998 in revision 1.46, to create a new itype
838 -- by copy. This seems useless, and in fact leads to semantic
839 -- errors when the itype is the completion of a type derived
840 -- from a private type.
842 Extra := New_Formal;
843 Next_Formal (Old_Formal);
844 exit when No (Old_Formal);
846 Set_Next_Entity (New_Formal, New_Copy (Old_Formal));
847 Next_Entity (New_Formal);
848 Next_Actual (Param);
849 end loop;
851 Set_Next_Entity (New_Formal, Empty);
852 Set_Last_Entity (Subp_Typ, Extra);
853 end if;
855 -- Now that the explicit formals have been duplicated, any extra
856 -- formals needed by the subprogram must be created.
858 if Present (Extra) then
859 Set_Extra_Formal (Extra, Empty);
860 end if;
862 Create_Extra_Formals (Subp_Typ);
863 end;
865 -- Complete description of pointer type, including size information, as
866 -- must be done with itypes to prevent order-of-elaboration anomalies
867 -- in gigi.
869 Set_Etype (Subp_Ptr_Typ, Subp_Ptr_Typ);
870 Set_Directly_Designated_Type (Subp_Ptr_Typ, Subp_Typ);
871 Set_Convention (Subp_Ptr_Typ, Convention (Subp_Typ));
872 Layout_Type (Subp_Ptr_Typ);
874 -- If the controlling argument is a value of type Ada.Tag or an abstract
875 -- interface class-wide type then use it directly. Otherwise, the tag
876 -- must be extracted from the controlling object.
878 if Ctrl_Typ = RTE (RE_Tag)
879 or else (RTE_Available (RE_Interface_Tag)
880 and then Ctrl_Typ = RTE (RE_Interface_Tag))
881 then
882 Controlling_Tag := Duplicate_Subexpr (Ctrl_Arg);
884 -- Extract the tag from an unchecked type conversion. Done to avoid
885 -- the expansion of additional code just to obtain the value of such
886 -- tag because the current management of interface type conversions
887 -- generates in some cases this unchecked type conversion with the
888 -- tag of the object (see Expand_Interface_Conversion).
890 elsif Nkind (Ctrl_Arg) = N_Unchecked_Type_Conversion
891 and then
892 (Etype (Expression (Ctrl_Arg)) = RTE (RE_Tag)
893 or else
894 (RTE_Available (RE_Interface_Tag)
895 and then
896 Etype (Expression (Ctrl_Arg)) = RTE (RE_Interface_Tag)))
897 then
898 Controlling_Tag := Duplicate_Subexpr (Expression (Ctrl_Arg));
900 -- Ada 2005 (AI-251): Abstract interface class-wide type
902 elsif Is_Interface (Ctrl_Typ)
903 and then Is_Class_Wide_Type (Ctrl_Typ)
904 then
905 Controlling_Tag := Duplicate_Subexpr (Ctrl_Arg);
907 else
908 Controlling_Tag :=
909 Make_Selected_Component (Loc,
910 Prefix => Duplicate_Subexpr_Move_Checks (Ctrl_Arg),
911 Selector_Name => New_Reference_To (DTC_Entity (Subp), Loc));
912 end if;
914 -- Handle dispatching calls to predefined primitives
916 if Is_Predefined_Dispatching_Operation (Subp)
917 or else Is_Predefined_Dispatching_Alias (Subp)
918 then
919 Build_Get_Predefined_Prim_Op_Address (Loc,
920 Tag_Node => Controlling_Tag,
921 Position => DT_Position (Subp),
922 New_Node => New_Node);
924 -- Handle dispatching calls to user-defined primitives
926 else
927 Build_Get_Prim_Op_Address (Loc,
928 Typ => Underlying_Type (Find_Dispatching_Type (Subp)),
929 Tag_Node => Controlling_Tag,
930 Position => DT_Position (Subp),
931 New_Node => New_Node);
932 end if;
934 New_Call_Name :=
935 Unchecked_Convert_To (Subp_Ptr_Typ, New_Node);
937 -- Generate the SCIL node for this dispatching call. Done now because
938 -- attribute SCIL_Controlling_Tag must be set after the new call name
939 -- is built to reference the nodes that will see the SCIL backend
940 -- (because Build_Get_Prim_Op_Address generates an unchecked type
941 -- conversion which relocates the controlling tag node).
943 if Generate_SCIL then
944 SCIL_Node := Make_SCIL_Dispatching_Call (Sloc (Call_Node));
945 Set_SCIL_Entity (SCIL_Node, Typ);
946 Set_SCIL_Target_Prim (SCIL_Node, Subp);
948 -- Common case: the controlling tag is the tag of an object
949 -- (for example, obj.tag)
951 if Nkind (Controlling_Tag) = N_Selected_Component then
952 Set_SCIL_Controlling_Tag (SCIL_Node, Controlling_Tag);
954 -- Handle renaming of selected component
956 elsif Nkind (Controlling_Tag) = N_Identifier
957 and then Nkind (Parent (Entity (Controlling_Tag))) =
958 N_Object_Renaming_Declaration
959 and then Nkind (Name (Parent (Entity (Controlling_Tag)))) =
960 N_Selected_Component
961 then
962 Set_SCIL_Controlling_Tag (SCIL_Node,
963 Name (Parent (Entity (Controlling_Tag))));
965 -- If the controlling tag is an identifier, the SCIL node references
966 -- the corresponding object or parameter declaration
968 elsif Nkind (Controlling_Tag) = N_Identifier
969 and then Nkind_In (Parent (Entity (Controlling_Tag)),
970 N_Object_Declaration,
971 N_Parameter_Specification)
972 then
973 Set_SCIL_Controlling_Tag (SCIL_Node,
974 Parent (Entity (Controlling_Tag)));
976 -- If the controlling tag is a dereference, the SCIL node references
977 -- the corresponding object or parameter declaration
979 elsif Nkind (Controlling_Tag) = N_Explicit_Dereference
980 and then Nkind (Prefix (Controlling_Tag)) = N_Identifier
981 and then Nkind_In (Parent (Entity (Prefix (Controlling_Tag))),
982 N_Object_Declaration,
983 N_Parameter_Specification)
984 then
985 Set_SCIL_Controlling_Tag (SCIL_Node,
986 Parent (Entity (Prefix (Controlling_Tag))));
988 -- For a direct reference of the tag of the type the SCIL node
989 -- references the internal object declaration containing the tag
990 -- of the type.
992 elsif Nkind (Controlling_Tag) = N_Attribute_Reference
993 and then Attribute_Name (Controlling_Tag) = Name_Tag
994 then
995 Set_SCIL_Controlling_Tag (SCIL_Node,
996 Parent
997 (Node
998 (First_Elmt
999 (Access_Disp_Table (Entity (Prefix (Controlling_Tag)))))));
1001 -- Interfaces are not supported. For now we leave the SCIL node
1002 -- decorated with the Controlling_Tag. More work needed here???
1004 elsif Is_Interface (Etype (Controlling_Tag)) then
1005 Set_SCIL_Controlling_Tag (SCIL_Node, Controlling_Tag);
1007 else
1008 pragma Assert (False);
1009 null;
1010 end if;
1011 end if;
1013 if Nkind (Call_Node) = N_Function_Call then
1014 New_Call :=
1015 Make_Function_Call (Loc,
1016 Name => New_Call_Name,
1017 Parameter_Associations => New_Params);
1019 -- If this is a dispatching "=", we must first compare the tags so
1020 -- we generate: x.tag = y.tag and then x = y
1022 if Subp = Eq_Prim_Op then
1023 Param := First_Actual (Call_Node);
1024 New_Call :=
1025 Make_And_Then (Loc,
1026 Left_Opnd =>
1027 Make_Op_Eq (Loc,
1028 Left_Opnd =>
1029 Make_Selected_Component (Loc,
1030 Prefix => New_Value (Param),
1031 Selector_Name =>
1032 New_Reference_To (First_Tag_Component (Typ),
1033 Loc)),
1035 Right_Opnd =>
1036 Make_Selected_Component (Loc,
1037 Prefix =>
1038 Unchecked_Convert_To (Typ,
1039 New_Value (Next_Actual (Param))),
1040 Selector_Name =>
1041 New_Reference_To
1042 (First_Tag_Component (Typ), Loc))),
1043 Right_Opnd => New_Call);
1045 SCIL_Related_Node := Right_Opnd (New_Call);
1046 end if;
1048 else
1049 New_Call :=
1050 Make_Procedure_Call_Statement (Loc,
1051 Name => New_Call_Name,
1052 Parameter_Associations => New_Params);
1053 end if;
1055 -- Register the dispatching call in the call graph nodes table
1057 Register_CG_Node (Call_Node);
1059 Rewrite (Call_Node, New_Call);
1061 -- Associate the SCIL node of this dispatching call
1063 if Generate_SCIL then
1064 Set_SCIL_Node (SCIL_Related_Node, SCIL_Node);
1065 end if;
1067 -- Suppress all checks during the analysis of the expanded code
1068 -- to avoid the generation of spurious warnings under ZFP run-time.
1070 Analyze_And_Resolve (Call_Node, Call_Typ, Suppress => All_Checks);
1071 end Expand_Dispatching_Call;
1073 ---------------------------------
1074 -- Expand_Interface_Conversion --
1075 ---------------------------------
1077 procedure Expand_Interface_Conversion
1078 (N : Node_Id;
1079 Is_Static : Boolean := True)
1081 Loc : constant Source_Ptr := Sloc (N);
1082 Etyp : constant Entity_Id := Etype (N);
1083 Operand : constant Node_Id := Expression (N);
1084 Operand_Typ : Entity_Id := Etype (Operand);
1085 Func : Node_Id;
1086 Iface_Typ : Entity_Id := Etype (N);
1087 Iface_Tag : Entity_Id;
1089 begin
1090 -- Ada 2005 (AI-345): Handle synchronized interface type derivations
1092 if Is_Concurrent_Type (Operand_Typ) then
1093 Operand_Typ := Base_Type (Corresponding_Record_Type (Operand_Typ));
1094 end if;
1096 -- Handle access to class-wide interface types
1098 if Is_Access_Type (Iface_Typ) then
1099 Iface_Typ := Etype (Directly_Designated_Type (Iface_Typ));
1100 end if;
1102 -- Handle class-wide interface types. This conversion can appear
1103 -- explicitly in the source code. Example: I'Class (Obj)
1105 if Is_Class_Wide_Type (Iface_Typ) then
1106 Iface_Typ := Root_Type (Iface_Typ);
1107 end if;
1109 -- If the target type is a tagged synchronized type, the dispatch table
1110 -- info is in the corresponding record type.
1112 if Is_Concurrent_Type (Iface_Typ) then
1113 Iface_Typ := Corresponding_Record_Type (Iface_Typ);
1114 end if;
1116 -- Handle private types
1118 Iface_Typ := Underlying_Type (Iface_Typ);
1120 -- Freeze the entity associated with the target interface to have
1121 -- available the attribute Access_Disp_Table.
1123 Freeze_Before (N, Iface_Typ);
1125 pragma Assert (not Is_Static
1126 or else (not Is_Class_Wide_Type (Iface_Typ)
1127 and then Is_Interface (Iface_Typ)));
1129 if not Tagged_Type_Expansion then
1130 if VM_Target /= No_VM then
1131 if Is_Access_Type (Operand_Typ) then
1132 Operand_Typ := Designated_Type (Operand_Typ);
1133 end if;
1135 if Is_Class_Wide_Type (Operand_Typ) then
1136 Operand_Typ := Root_Type (Operand_Typ);
1137 end if;
1139 if not Is_Static
1140 and then Operand_Typ /= Iface_Typ
1141 then
1142 Insert_Action (N,
1143 Make_Procedure_Call_Statement (Loc,
1144 Name => New_Occurrence_Of
1145 (RTE (RE_Check_Interface_Conversion), Loc),
1146 Parameter_Associations => New_List (
1147 Make_Attribute_Reference (Loc,
1148 Prefix => Duplicate_Subexpr (Expression (N)),
1149 Attribute_Name => Name_Tag),
1150 Make_Attribute_Reference (Loc,
1151 Prefix => New_Reference_To (Iface_Typ, Loc),
1152 Attribute_Name => Name_Tag))));
1153 end if;
1155 -- Just do a conversion ???
1157 Rewrite (N, Unchecked_Convert_To (Etype (N), N));
1158 Analyze (N);
1159 end if;
1161 return;
1162 end if;
1164 if not Is_Static then
1166 -- Give error if configurable run time and Displace not available
1168 if not RTE_Available (RE_Displace) then
1169 Error_Msg_CRT ("dynamic interface conversion", N);
1170 return;
1171 end if;
1173 -- Handle conversion of access-to-class-wide interface types. Target
1174 -- can be an access to an object or an access to another class-wide
1175 -- interface (see -1- and -2- in the following example):
1177 -- type Iface1_Ref is access all Iface1'Class;
1178 -- type Iface2_Ref is access all Iface1'Class;
1180 -- Acc1 : Iface1_Ref := new ...
1181 -- Obj : Obj_Ref := Obj_Ref (Acc); -- 1
1182 -- Acc2 : Iface2_Ref := Iface2_Ref (Acc); -- 2
1184 if Is_Access_Type (Operand_Typ) then
1185 Rewrite (N,
1186 Unchecked_Convert_To (Etype (N),
1187 Make_Function_Call (Loc,
1188 Name => New_Reference_To (RTE (RE_Displace), Loc),
1189 Parameter_Associations => New_List (
1191 Unchecked_Convert_To (RTE (RE_Address),
1192 Relocate_Node (Expression (N))),
1194 New_Occurrence_Of
1195 (Node (First_Elmt (Access_Disp_Table (Iface_Typ))),
1196 Loc)))));
1198 Analyze (N);
1199 return;
1200 end if;
1202 Rewrite (N,
1203 Make_Function_Call (Loc,
1204 Name => New_Reference_To (RTE (RE_Displace), Loc),
1205 Parameter_Associations => New_List (
1206 Make_Attribute_Reference (Loc,
1207 Prefix => Relocate_Node (Expression (N)),
1208 Attribute_Name => Name_Address),
1210 New_Occurrence_Of
1211 (Node (First_Elmt (Access_Disp_Table (Iface_Typ))),
1212 Loc))));
1214 Analyze (N);
1216 -- If the target is a class-wide interface we change the type of the
1217 -- data returned by IW_Convert to indicate that this is a dispatching
1218 -- call.
1220 declare
1221 New_Itype : Entity_Id;
1223 begin
1224 New_Itype := Create_Itype (E_Anonymous_Access_Type, N);
1225 Set_Etype (New_Itype, New_Itype);
1226 Set_Directly_Designated_Type (New_Itype, Etyp);
1228 Rewrite (N,
1229 Make_Explicit_Dereference (Loc,
1230 Prefix =>
1231 Unchecked_Convert_To (New_Itype, Relocate_Node (N))));
1232 Analyze (N);
1233 Freeze_Itype (New_Itype, N);
1235 return;
1236 end;
1237 end if;
1239 Iface_Tag := Find_Interface_Tag (Operand_Typ, Iface_Typ);
1240 pragma Assert (Iface_Tag /= Empty);
1242 -- Keep separate access types to interfaces because one internal
1243 -- function is used to handle the null value (see following comments)
1245 if not Is_Access_Type (Etype (N)) then
1247 -- Statically displace the pointer to the object to reference
1248 -- the component containing the secondary dispatch table.
1250 Rewrite (N,
1251 Convert_Tag_To_Interface (Class_Wide_Type (Iface_Typ),
1252 Make_Selected_Component (Loc,
1253 Prefix => Relocate_Node (Expression (N)),
1254 Selector_Name => New_Occurrence_Of (Iface_Tag, Loc))));
1256 else
1257 -- Build internal function to handle the case in which the
1258 -- actual is null. If the actual is null returns null because
1259 -- no displacement is required; otherwise performs a type
1260 -- conversion that will be expanded in the code that returns
1261 -- the value of the displaced actual. That is:
1263 -- function Func (O : Address) return Iface_Typ is
1264 -- type Op_Typ is access all Operand_Typ;
1265 -- Aux : Op_Typ := To_Op_Typ (O);
1266 -- begin
1267 -- if O = Null_Address then
1268 -- return null;
1269 -- else
1270 -- return Iface_Typ!(Aux.Iface_Tag'Address);
1271 -- end if;
1272 -- end Func;
1274 declare
1275 Desig_Typ : Entity_Id;
1276 Fent : Entity_Id;
1277 New_Typ_Decl : Node_Id;
1278 Stats : List_Id;
1280 begin
1281 Desig_Typ := Etype (Expression (N));
1283 if Is_Access_Type (Desig_Typ) then
1284 Desig_Typ :=
1285 Available_View (Directly_Designated_Type (Desig_Typ));
1286 end if;
1288 if Is_Concurrent_Type (Desig_Typ) then
1289 Desig_Typ := Base_Type (Corresponding_Record_Type (Desig_Typ));
1290 end if;
1292 New_Typ_Decl :=
1293 Make_Full_Type_Declaration (Loc,
1294 Defining_Identifier => Make_Temporary (Loc, 'T'),
1295 Type_Definition =>
1296 Make_Access_To_Object_Definition (Loc,
1297 All_Present => True,
1298 Null_Exclusion_Present => False,
1299 Constant_Present => False,
1300 Subtype_Indication =>
1301 New_Reference_To (Desig_Typ, Loc)));
1303 Stats := New_List (
1304 Make_Simple_Return_Statement (Loc,
1305 Unchecked_Convert_To (Etype (N),
1306 Make_Attribute_Reference (Loc,
1307 Prefix =>
1308 Make_Selected_Component (Loc,
1309 Prefix =>
1310 Unchecked_Convert_To
1311 (Defining_Identifier (New_Typ_Decl),
1312 Make_Identifier (Loc, Name_uO)),
1313 Selector_Name =>
1314 New_Occurrence_Of (Iface_Tag, Loc)),
1315 Attribute_Name => Name_Address))));
1317 -- If the type is null-excluding, no need for the null branch.
1318 -- Otherwise we need to check for it and return null.
1320 if not Can_Never_Be_Null (Etype (N)) then
1321 Stats := New_List (
1322 Make_If_Statement (Loc,
1323 Condition =>
1324 Make_Op_Eq (Loc,
1325 Left_Opnd => Make_Identifier (Loc, Name_uO),
1326 Right_Opnd => New_Reference_To
1327 (RTE (RE_Null_Address), Loc)),
1329 Then_Statements => New_List (
1330 Make_Simple_Return_Statement (Loc,
1331 Make_Null (Loc))),
1332 Else_Statements => Stats));
1333 end if;
1335 Fent := Make_Temporary (Loc, 'F');
1336 Func :=
1337 Make_Subprogram_Body (Loc,
1338 Specification =>
1339 Make_Function_Specification (Loc,
1340 Defining_Unit_Name => Fent,
1342 Parameter_Specifications => New_List (
1343 Make_Parameter_Specification (Loc,
1344 Defining_Identifier =>
1345 Make_Defining_Identifier (Loc, Name_uO),
1346 Parameter_Type =>
1347 New_Reference_To (RTE (RE_Address), Loc))),
1349 Result_Definition =>
1350 New_Reference_To (Etype (N), Loc)),
1352 Declarations => New_List (New_Typ_Decl),
1354 Handled_Statement_Sequence =>
1355 Make_Handled_Sequence_Of_Statements (Loc, Stats));
1357 -- Place function body before the expression containing the
1358 -- conversion. We suppress all checks because the body of the
1359 -- internally generated function already takes care of the case
1360 -- in which the actual is null; therefore there is no need to
1361 -- double check that the pointer is not null when the program
1362 -- executes the alternative that performs the type conversion).
1364 Insert_Action (N, Func, Suppress => All_Checks);
1366 if Is_Access_Type (Etype (Expression (N))) then
1368 -- Generate: Func (Address!(Expression))
1370 Rewrite (N,
1371 Make_Function_Call (Loc,
1372 Name => New_Reference_To (Fent, Loc),
1373 Parameter_Associations => New_List (
1374 Unchecked_Convert_To (RTE (RE_Address),
1375 Relocate_Node (Expression (N))))));
1377 else
1378 -- Generate: Func (Operand_Typ!(Expression)'Address)
1380 Rewrite (N,
1381 Make_Function_Call (Loc,
1382 Name => New_Reference_To (Fent, Loc),
1383 Parameter_Associations => New_List (
1384 Make_Attribute_Reference (Loc,
1385 Prefix => Unchecked_Convert_To (Operand_Typ,
1386 Relocate_Node (Expression (N))),
1387 Attribute_Name => Name_Address))));
1388 end if;
1389 end;
1390 end if;
1392 Analyze (N);
1393 end Expand_Interface_Conversion;
1395 ------------------------------
1396 -- Expand_Interface_Actuals --
1397 ------------------------------
1399 procedure Expand_Interface_Actuals (Call_Node : Node_Id) is
1400 Actual : Node_Id;
1401 Actual_Dup : Node_Id;
1402 Actual_Typ : Entity_Id;
1403 Anon : Entity_Id;
1404 Conversion : Node_Id;
1405 Formal : Entity_Id;
1406 Formal_Typ : Entity_Id;
1407 Subp : Entity_Id;
1408 Formal_DDT : Entity_Id;
1409 Actual_DDT : Entity_Id;
1411 begin
1412 -- This subprogram is called directly from the semantics, so we need a
1413 -- check to see whether expansion is active before proceeding.
1415 if not Expander_Active then
1416 return;
1417 end if;
1419 -- Call using access to subprogram with explicit dereference
1421 if Nkind (Name (Call_Node)) = N_Explicit_Dereference then
1422 Subp := Etype (Name (Call_Node));
1424 -- Call using selected component
1426 elsif Nkind (Name (Call_Node)) = N_Selected_Component then
1427 Subp := Entity (Selector_Name (Name (Call_Node)));
1429 -- Call using direct name
1431 else
1432 Subp := Entity (Name (Call_Node));
1433 end if;
1435 -- Ada 2005 (AI-251): Look for interface type formals to force "this"
1436 -- displacement
1438 Formal := First_Formal (Subp);
1439 Actual := First_Actual (Call_Node);
1440 while Present (Formal) loop
1441 Formal_Typ := Etype (Formal);
1443 if Ekind (Formal_Typ) = E_Record_Type_With_Private then
1444 Formal_Typ := Full_View (Formal_Typ);
1445 end if;
1447 if Is_Access_Type (Formal_Typ) then
1448 Formal_DDT := Directly_Designated_Type (Formal_Typ);
1449 end if;
1451 Actual_Typ := Etype (Actual);
1453 if Is_Access_Type (Actual_Typ) then
1454 Actual_DDT := Directly_Designated_Type (Actual_Typ);
1455 end if;
1457 if Is_Interface (Formal_Typ)
1458 and then Is_Class_Wide_Type (Formal_Typ)
1459 then
1460 -- No need to displace the pointer if the type of the actual
1461 -- coincides with the type of the formal.
1463 if Actual_Typ = Formal_Typ then
1464 null;
1466 -- No need to displace the pointer if the interface type is
1467 -- a parent of the type of the actual because in this case the
1468 -- interface primitives are located in the primary dispatch table.
1470 elsif Is_Ancestor (Formal_Typ, Actual_Typ,
1471 Use_Full_View => True)
1472 then
1473 null;
1475 -- Implicit conversion to the class-wide formal type to force
1476 -- the displacement of the pointer.
1478 else
1479 -- Normally, expansion of actuals for calls to build-in-place
1480 -- functions happens as part of Expand_Actuals, but in this
1481 -- case the call will be wrapped in a conversion and soon after
1482 -- expanded further to handle the displacement for a class-wide
1483 -- interface conversion, so if this is a BIP call then we need
1484 -- to handle it now.
1486 if Ada_Version >= Ada_2005
1487 and then Is_Build_In_Place_Function_Call (Actual)
1488 then
1489 Make_Build_In_Place_Call_In_Anonymous_Context (Actual);
1490 end if;
1492 Conversion := Convert_To (Formal_Typ, Relocate_Node (Actual));
1493 Rewrite (Actual, Conversion);
1494 Analyze_And_Resolve (Actual, Formal_Typ);
1495 end if;
1497 -- Access to class-wide interface type
1499 elsif Is_Access_Type (Formal_Typ)
1500 and then Is_Interface (Formal_DDT)
1501 and then Is_Class_Wide_Type (Formal_DDT)
1502 and then Interface_Present_In_Ancestor
1503 (Typ => Actual_DDT,
1504 Iface => Etype (Formal_DDT))
1505 then
1506 -- Handle attributes 'Access and 'Unchecked_Access
1508 if Nkind (Actual) = N_Attribute_Reference
1509 and then
1510 (Attribute_Name (Actual) = Name_Access
1511 or else Attribute_Name (Actual) = Name_Unchecked_Access)
1512 then
1513 -- This case must have been handled by the analysis and
1514 -- expansion of 'Access. The only exception is when types
1515 -- match and no further expansion is required.
1517 pragma Assert (Base_Type (Etype (Prefix (Actual)))
1518 = Base_Type (Formal_DDT));
1519 null;
1521 -- No need to displace the pointer if the type of the actual
1522 -- coincides with the type of the formal.
1524 elsif Actual_DDT = Formal_DDT then
1525 null;
1527 -- No need to displace the pointer if the interface type is
1528 -- a parent of the type of the actual because in this case the
1529 -- interface primitives are located in the primary dispatch table.
1531 elsif Is_Ancestor (Formal_DDT, Actual_DDT,
1532 Use_Full_View => True)
1533 then
1534 null;
1536 else
1537 Actual_Dup := Relocate_Node (Actual);
1539 if From_With_Type (Actual_Typ) then
1541 -- If the type of the actual parameter comes from a limited
1542 -- with-clause and the non-limited view is already available
1543 -- we replace the anonymous access type by a duplicate
1544 -- declaration whose designated type is the non-limited view
1546 if Ekind (Actual_DDT) = E_Incomplete_Type
1547 and then Present (Non_Limited_View (Actual_DDT))
1548 then
1549 Anon := New_Copy (Actual_Typ);
1551 if Is_Itype (Anon) then
1552 Set_Scope (Anon, Current_Scope);
1553 end if;
1555 Set_Directly_Designated_Type (Anon,
1556 Non_Limited_View (Actual_DDT));
1557 Set_Etype (Actual_Dup, Anon);
1559 elsif Is_Class_Wide_Type (Actual_DDT)
1560 and then Ekind (Etype (Actual_DDT)) = E_Incomplete_Type
1561 and then Present (Non_Limited_View (Etype (Actual_DDT)))
1562 then
1563 Anon := New_Copy (Actual_Typ);
1565 if Is_Itype (Anon) then
1566 Set_Scope (Anon, Current_Scope);
1567 end if;
1569 Set_Directly_Designated_Type (Anon,
1570 New_Copy (Actual_DDT));
1571 Set_Class_Wide_Type (Directly_Designated_Type (Anon),
1572 New_Copy (Class_Wide_Type (Actual_DDT)));
1573 Set_Etype (Directly_Designated_Type (Anon),
1574 Non_Limited_View (Etype (Actual_DDT)));
1575 Set_Etype (
1576 Class_Wide_Type (Directly_Designated_Type (Anon)),
1577 Non_Limited_View (Etype (Actual_DDT)));
1578 Set_Etype (Actual_Dup, Anon);
1579 end if;
1580 end if;
1582 Conversion := Convert_To (Formal_Typ, Actual_Dup);
1583 Rewrite (Actual, Conversion);
1584 Analyze_And_Resolve (Actual, Formal_Typ);
1585 end if;
1586 end if;
1588 Next_Actual (Actual);
1589 Next_Formal (Formal);
1590 end loop;
1591 end Expand_Interface_Actuals;
1593 ----------------------------
1594 -- Expand_Interface_Thunk --
1595 ----------------------------
1597 procedure Expand_Interface_Thunk
1598 (Prim : Node_Id;
1599 Thunk_Id : out Entity_Id;
1600 Thunk_Code : out Node_Id)
1602 Loc : constant Source_Ptr := Sloc (Prim);
1603 Actuals : constant List_Id := New_List;
1604 Decl : constant List_Id := New_List;
1605 Formals : constant List_Id := New_List;
1606 Target : constant Entity_Id := Ultimate_Alias (Prim);
1608 Controlling_Typ : Entity_Id;
1609 Decl_1 : Node_Id;
1610 Decl_2 : Node_Id;
1611 Expr : Node_Id;
1612 Formal : Node_Id;
1613 Ftyp : Entity_Id;
1614 Iface_Formal : Node_Id;
1615 New_Arg : Node_Id;
1616 Offset_To_Top : Node_Id;
1617 Target_Formal : Entity_Id;
1619 begin
1620 Thunk_Id := Empty;
1621 Thunk_Code := Empty;
1623 -- No thunk needed if the primitive has been eliminated
1625 if Is_Eliminated (Ultimate_Alias (Prim)) then
1626 return;
1628 -- In case of primitives that are functions without formals and a
1629 -- controlling result there is no need to build the thunk.
1631 elsif not Present (First_Formal (Target)) then
1632 pragma Assert (Ekind (Target) = E_Function
1633 and then Has_Controlling_Result (Target));
1634 return;
1635 end if;
1637 -- Duplicate the formals of the Target primitive. In the thunk, the type
1638 -- of the controlling formal is the covered interface type (instead of
1639 -- the target tagged type). Done to avoid problems with discriminated
1640 -- tagged types because, if the controlling type has discriminants with
1641 -- default values, then the type conversions done inside the body of
1642 -- the thunk (after the displacement of the pointer to the base of the
1643 -- actual object) generate code that modify its contents.
1645 -- Note: This special management is not done for predefined primitives
1646 -- because???
1648 if not Is_Predefined_Dispatching_Operation (Prim) then
1649 Iface_Formal := First_Formal (Interface_Alias (Prim));
1650 end if;
1652 Formal := First_Formal (Target);
1653 while Present (Formal) loop
1654 Ftyp := Etype (Formal);
1656 -- Use the interface type as the type of the controlling formal (see
1657 -- comment above).
1659 if not Is_Controlling_Formal (Formal)
1660 or else Is_Predefined_Dispatching_Operation (Prim)
1661 then
1662 Ftyp := Etype (Formal);
1663 Expr := New_Copy_Tree (Expression (Parent (Formal)));
1664 else
1665 Ftyp := Etype (Iface_Formal);
1666 Expr := Empty;
1667 end if;
1669 Append_To (Formals,
1670 Make_Parameter_Specification (Loc,
1671 Defining_Identifier =>
1672 Make_Defining_Identifier (Sloc (Formal),
1673 Chars => Chars (Formal)),
1674 In_Present => In_Present (Parent (Formal)),
1675 Out_Present => Out_Present (Parent (Formal)),
1676 Parameter_Type => New_Reference_To (Ftyp, Loc),
1677 Expression => Expr));
1679 if not Is_Predefined_Dispatching_Operation (Prim) then
1680 Next_Formal (Iface_Formal);
1681 end if;
1683 Next_Formal (Formal);
1684 end loop;
1686 Controlling_Typ := Find_Dispatching_Type (Target);
1688 Target_Formal := First_Formal (Target);
1689 Formal := First (Formals);
1690 while Present (Formal) loop
1692 -- If the parent is a constrained discriminated type, then the
1693 -- primitive operation will have been defined on a first subtype.
1694 -- For proper matching with controlling type, use base type.
1696 if Ekind (Target_Formal) = E_In_Parameter
1697 and then Ekind (Etype (Target_Formal)) = E_Anonymous_Access_Type
1698 then
1699 Ftyp :=
1700 Base_Type (Directly_Designated_Type (Etype (Target_Formal)));
1701 else
1702 Ftyp := Base_Type (Etype (Target_Formal));
1703 end if;
1705 -- For concurrent types, the relevant information is found in the
1706 -- Corresponding_Record_Type, rather than the type entity itself.
1708 if Is_Concurrent_Type (Ftyp) then
1709 Ftyp := Corresponding_Record_Type (Ftyp);
1710 end if;
1712 if Ekind (Target_Formal) = E_In_Parameter
1713 and then Ekind (Etype (Target_Formal)) = E_Anonymous_Access_Type
1714 and then Ftyp = Controlling_Typ
1715 then
1716 -- Generate:
1717 -- type T is access all <<type of the target formal>>
1718 -- S : Storage_Offset := Storage_Offset!(Formal)
1719 -- - Offset_To_Top (address!(Formal))
1721 Decl_2 :=
1722 Make_Full_Type_Declaration (Loc,
1723 Defining_Identifier => Make_Temporary (Loc, 'T'),
1724 Type_Definition =>
1725 Make_Access_To_Object_Definition (Loc,
1726 All_Present => True,
1727 Null_Exclusion_Present => False,
1728 Constant_Present => False,
1729 Subtype_Indication =>
1730 New_Reference_To (Ftyp, Loc)));
1732 New_Arg :=
1733 Unchecked_Convert_To (RTE (RE_Address),
1734 New_Reference_To (Defining_Identifier (Formal), Loc));
1736 if not RTE_Available (RE_Offset_To_Top) then
1737 Offset_To_Top :=
1738 Build_Offset_To_Top (Loc, New_Arg);
1739 else
1740 Offset_To_Top :=
1741 Make_Function_Call (Loc,
1742 Name => New_Reference_To (RTE (RE_Offset_To_Top), Loc),
1743 Parameter_Associations => New_List (New_Arg));
1744 end if;
1746 Decl_1 :=
1747 Make_Object_Declaration (Loc,
1748 Defining_Identifier => Make_Temporary (Loc, 'S'),
1749 Constant_Present => True,
1750 Object_Definition =>
1751 New_Reference_To (RTE (RE_Storage_Offset), Loc),
1752 Expression =>
1753 Make_Op_Subtract (Loc,
1754 Left_Opnd =>
1755 Unchecked_Convert_To
1756 (RTE (RE_Storage_Offset),
1757 New_Reference_To (Defining_Identifier (Formal), Loc)),
1758 Right_Opnd =>
1759 Offset_To_Top));
1761 Append_To (Decl, Decl_2);
1762 Append_To (Decl, Decl_1);
1764 -- Reference the new actual. Generate:
1765 -- T!(S)
1767 Append_To (Actuals,
1768 Unchecked_Convert_To
1769 (Defining_Identifier (Decl_2),
1770 New_Reference_To (Defining_Identifier (Decl_1), Loc)));
1772 elsif Ftyp = Controlling_Typ then
1774 -- Generate:
1775 -- S1 : Storage_Offset := Storage_Offset!(Formal'Address)
1776 -- - Offset_To_Top (Formal'Address)
1777 -- S2 : Addr_Ptr := Addr_Ptr!(S1)
1779 New_Arg :=
1780 Make_Attribute_Reference (Loc,
1781 Prefix =>
1782 New_Reference_To (Defining_Identifier (Formal), Loc),
1783 Attribute_Name =>
1784 Name_Address);
1786 if not RTE_Available (RE_Offset_To_Top) then
1787 Offset_To_Top :=
1788 Build_Offset_To_Top (Loc, New_Arg);
1789 else
1790 Offset_To_Top :=
1791 Make_Function_Call (Loc,
1792 Name => New_Reference_To (RTE (RE_Offset_To_Top), Loc),
1793 Parameter_Associations => New_List (New_Arg));
1794 end if;
1796 Decl_1 :=
1797 Make_Object_Declaration (Loc,
1798 Defining_Identifier => Make_Temporary (Loc, 'S'),
1799 Constant_Present => True,
1800 Object_Definition =>
1801 New_Reference_To (RTE (RE_Storage_Offset), Loc),
1802 Expression =>
1803 Make_Op_Subtract (Loc,
1804 Left_Opnd =>
1805 Unchecked_Convert_To
1806 (RTE (RE_Storage_Offset),
1807 Make_Attribute_Reference (Loc,
1808 Prefix =>
1809 New_Reference_To
1810 (Defining_Identifier (Formal), Loc),
1811 Attribute_Name => Name_Address)),
1812 Right_Opnd =>
1813 Offset_To_Top));
1815 Decl_2 :=
1816 Make_Object_Declaration (Loc,
1817 Defining_Identifier => Make_Temporary (Loc, 'S'),
1818 Constant_Present => True,
1819 Object_Definition =>
1820 New_Reference_To (RTE (RE_Addr_Ptr), Loc),
1821 Expression =>
1822 Unchecked_Convert_To
1823 (RTE (RE_Addr_Ptr),
1824 New_Reference_To (Defining_Identifier (Decl_1), Loc)));
1826 Append_To (Decl, Decl_1);
1827 Append_To (Decl, Decl_2);
1829 -- Reference the new actual, generate:
1830 -- Target_Formal (S2.all)
1832 Append_To (Actuals,
1833 Unchecked_Convert_To (Ftyp,
1834 Make_Explicit_Dereference (Loc,
1835 New_Reference_To (Defining_Identifier (Decl_2), Loc))));
1837 -- Ensure proper matching of access types. Required to avoid
1838 -- reporting spurious errors.
1840 elsif Is_Access_Type (Etype (Target_Formal)) then
1841 Append_To (Actuals,
1842 Unchecked_Convert_To (Base_Type (Etype (Target_Formal)),
1843 New_Reference_To (Defining_Identifier (Formal), Loc)));
1845 -- No special management required for this actual
1847 else
1848 Append_To (Actuals,
1849 New_Reference_To (Defining_Identifier (Formal), Loc));
1850 end if;
1852 Next_Formal (Target_Formal);
1853 Next (Formal);
1854 end loop;
1856 Thunk_Id := Make_Temporary (Loc, 'T');
1857 Set_Is_Thunk (Thunk_Id);
1858 Set_Convention (Thunk_Id, Convention (Prim));
1860 -- Procedure case
1862 if Ekind (Target) = E_Procedure then
1863 Thunk_Code :=
1864 Make_Subprogram_Body (Loc,
1865 Specification =>
1866 Make_Procedure_Specification (Loc,
1867 Defining_Unit_Name => Thunk_Id,
1868 Parameter_Specifications => Formals),
1869 Declarations => Decl,
1870 Handled_Statement_Sequence =>
1871 Make_Handled_Sequence_Of_Statements (Loc,
1872 Statements => New_List (
1873 Make_Procedure_Call_Statement (Loc,
1874 Name => New_Occurrence_Of (Target, Loc),
1875 Parameter_Associations => Actuals))));
1877 -- Function case
1879 else pragma Assert (Ekind (Target) = E_Function);
1880 Thunk_Code :=
1881 Make_Subprogram_Body (Loc,
1882 Specification =>
1883 Make_Function_Specification (Loc,
1884 Defining_Unit_Name => Thunk_Id,
1885 Parameter_Specifications => Formals,
1886 Result_Definition =>
1887 New_Copy (Result_Definition (Parent (Target)))),
1888 Declarations => Decl,
1889 Handled_Statement_Sequence =>
1890 Make_Handled_Sequence_Of_Statements (Loc,
1891 Statements => New_List (
1892 Make_Simple_Return_Statement (Loc,
1893 Make_Function_Call (Loc,
1894 Name => New_Occurrence_Of (Target, Loc),
1895 Parameter_Associations => Actuals)))));
1896 end if;
1897 end Expand_Interface_Thunk;
1899 ------------------------
1900 -- Find_Specific_Type --
1901 ------------------------
1903 function Find_Specific_Type (CW : Entity_Id) return Entity_Id is
1904 Typ : Entity_Id := Root_Type (CW);
1906 begin
1907 if Ekind (Typ) = E_Incomplete_Type then
1908 if From_With_Type (Typ) then
1909 Typ := Non_Limited_View (Typ);
1910 else
1911 Typ := Full_View (Typ);
1912 end if;
1913 end if;
1915 return Typ;
1916 end Find_Specific_Type;
1918 --------------------------
1919 -- Has_CPP_Constructors --
1920 --------------------------
1922 function Has_CPP_Constructors (Typ : Entity_Id) return Boolean is
1923 E : Entity_Id;
1925 begin
1926 -- Look for the constructor entities
1928 E := Next_Entity (Typ);
1929 while Present (E) loop
1930 if Ekind (E) = E_Function
1931 and then Is_Constructor (E)
1932 then
1933 return True;
1934 end if;
1936 Next_Entity (E);
1937 end loop;
1939 return False;
1940 end Has_CPP_Constructors;
1942 ------------
1943 -- Has_DT --
1944 ------------
1946 function Has_DT (Typ : Entity_Id) return Boolean is
1947 begin
1948 return not Is_Interface (Typ)
1949 and then not Restriction_Active (No_Dispatching_Calls);
1950 end Has_DT;
1952 -----------------------------------------
1953 -- Is_Predefined_Dispatching_Operation --
1954 -----------------------------------------
1956 function Is_Predefined_Dispatching_Operation
1957 (E : Entity_Id) return Boolean
1959 TSS_Name : TSS_Name_Type;
1961 begin
1962 if not Is_Dispatching_Operation (E) then
1963 return False;
1964 end if;
1966 Get_Name_String (Chars (E));
1968 -- Most predefined primitives have internally generated names. Equality
1969 -- must be treated differently; the predefined operation is recognized
1970 -- as a homogeneous binary operator that returns Boolean.
1972 if Name_Len > TSS_Name_Type'Last then
1973 TSS_Name := TSS_Name_Type (Name_Buffer (Name_Len - TSS_Name'Length + 1
1974 .. Name_Len));
1975 if Chars (E) = Name_uSize
1976 or else TSS_Name = TSS_Stream_Read
1977 or else TSS_Name = TSS_Stream_Write
1978 or else TSS_Name = TSS_Stream_Input
1979 or else TSS_Name = TSS_Stream_Output
1980 or else
1981 (Chars (E) = Name_Op_Eq
1982 and then Etype (First_Formal (E)) = Etype (Last_Formal (E)))
1983 or else Chars (E) = Name_uAssign
1984 or else TSS_Name = TSS_Deep_Adjust
1985 or else TSS_Name = TSS_Deep_Finalize
1986 or else Is_Predefined_Interface_Primitive (E)
1987 then
1988 return True;
1989 end if;
1990 end if;
1992 return False;
1993 end Is_Predefined_Dispatching_Operation;
1995 ---------------------------------------
1996 -- Is_Predefined_Internal_Operation --
1997 ---------------------------------------
1999 function Is_Predefined_Internal_Operation
2000 (E : Entity_Id) return Boolean
2002 TSS_Name : TSS_Name_Type;
2004 begin
2005 if not Is_Dispatching_Operation (E) then
2006 return False;
2007 end if;
2009 Get_Name_String (Chars (E));
2011 -- Most predefined primitives have internally generated names. Equality
2012 -- must be treated differently; the predefined operation is recognized
2013 -- as a homogeneous binary operator that returns Boolean.
2015 if Name_Len > TSS_Name_Type'Last then
2016 TSS_Name :=
2017 TSS_Name_Type
2018 (Name_Buffer (Name_Len - TSS_Name'Length + 1 .. Name_Len));
2020 if Chars (E) = Name_uSize
2021 or else
2022 (Chars (E) = Name_Op_Eq
2023 and then Etype (First_Formal (E)) = Etype (Last_Formal (E)))
2024 or else Chars (E) = Name_uAssign
2025 or else TSS_Name = TSS_Deep_Adjust
2026 or else TSS_Name = TSS_Deep_Finalize
2027 or else Is_Predefined_Interface_Primitive (E)
2028 then
2029 return True;
2030 end if;
2031 end if;
2033 return False;
2034 end Is_Predefined_Internal_Operation;
2036 -------------------------------------
2037 -- Is_Predefined_Dispatching_Alias --
2038 -------------------------------------
2040 function Is_Predefined_Dispatching_Alias (Prim : Entity_Id) return Boolean
2042 begin
2043 return not Is_Predefined_Dispatching_Operation (Prim)
2044 and then Present (Alias (Prim))
2045 and then Is_Predefined_Dispatching_Operation (Ultimate_Alias (Prim));
2046 end Is_Predefined_Dispatching_Alias;
2048 ---------------------------------------
2049 -- Is_Predefined_Interface_Primitive --
2050 ---------------------------------------
2052 function Is_Predefined_Interface_Primitive (E : Entity_Id) return Boolean is
2053 begin
2054 -- In VM targets we don't restrict the functionality of this test to
2055 -- compiling in Ada 2005 mode since in VM targets any tagged type has
2056 -- these primitives
2058 return (Ada_Version >= Ada_2005 or else not Tagged_Type_Expansion)
2059 and then (Chars (E) = Name_uDisp_Asynchronous_Select or else
2060 Chars (E) = Name_uDisp_Conditional_Select or else
2061 Chars (E) = Name_uDisp_Get_Prim_Op_Kind or else
2062 Chars (E) = Name_uDisp_Get_Task_Id or else
2063 Chars (E) = Name_uDisp_Requeue or else
2064 Chars (E) = Name_uDisp_Timed_Select);
2065 end Is_Predefined_Interface_Primitive;
2067 ----------------------------------------
2068 -- Make_Disp_Asynchronous_Select_Body --
2069 ----------------------------------------
2071 -- For interface types, generate:
2073 -- procedure _Disp_Asynchronous_Select
2074 -- (T : in out <Typ>;
2075 -- S : Integer;
2076 -- P : System.Address;
2077 -- B : out System.Storage_Elements.Dummy_Communication_Block;
2078 -- F : out Boolean)
2079 -- is
2080 -- begin
2081 -- F := False;
2082 -- C := Ada.Tags.POK_Function;
2083 -- end _Disp_Asynchronous_Select;
2085 -- For protected types, generate:
2087 -- procedure _Disp_Asynchronous_Select
2088 -- (T : in out <Typ>;
2089 -- S : Integer;
2090 -- P : System.Address;
2091 -- B : out System.Storage_Elements.Dummy_Communication_Block;
2092 -- F : out Boolean)
2093 -- is
2094 -- I : Integer :=
2095 -- Ada.Tags.Get_Entry_Index (Ada.Tags.Tag (<Typ>VP, S));
2096 -- Bnn : System.Tasking.Protected_Objects.Operations.
2097 -- Communication_Block;
2098 -- begin
2099 -- System.Tasking.Protected_Objects.Operations.Protected_Entry_Call
2100 -- (T._object'Access,
2101 -- System.Tasking.Protected_Objects.Protected_Entry_Index (I),
2102 -- P,
2103 -- System.Tasking.Asynchronous_Call,
2104 -- Bnn);
2105 -- B := System.Storage_Elements.Dummy_Communication_Block (Bnn);
2106 -- end _Disp_Asynchronous_Select;
2108 -- For task types, generate:
2110 -- procedure _Disp_Asynchronous_Select
2111 -- (T : in out <Typ>;
2112 -- S : Integer;
2113 -- P : System.Address;
2114 -- B : out System.Storage_Elements.Dummy_Communication_Block;
2115 -- F : out Boolean)
2116 -- is
2117 -- I : Integer :=
2118 -- Ada.Tags.Get_Entry_Index (Ada.Tags.Tag (<Typ>VP, S));
2119 -- begin
2120 -- System.Tasking.Rendezvous.Task_Entry_Call
2121 -- (T._task_id,
2122 -- System.Tasking.Task_Entry_Index (I),
2123 -- P,
2124 -- System.Tasking.Asynchronous_Call,
2125 -- F);
2126 -- end _Disp_Asynchronous_Select;
2128 function Make_Disp_Asynchronous_Select_Body
2129 (Typ : Entity_Id) return Node_Id
2131 Com_Block : Entity_Id;
2132 Conc_Typ : Entity_Id := Empty;
2133 Decls : constant List_Id := New_List;
2134 Loc : constant Source_Ptr := Sloc (Typ);
2135 Obj_Ref : Node_Id;
2136 Stmts : constant List_Id := New_List;
2137 Tag_Node : Node_Id;
2139 begin
2140 pragma Assert (not Restriction_Active (No_Dispatching_Calls));
2142 -- Null body is generated for interface types
2144 if Is_Interface (Typ) then
2145 return
2146 Make_Subprogram_Body (Loc,
2147 Specification => Make_Disp_Asynchronous_Select_Spec (Typ),
2148 Declarations => New_List,
2149 Handled_Statement_Sequence =>
2150 Make_Handled_Sequence_Of_Statements (Loc,
2151 New_List (Make_Assignment_Statement (Loc,
2152 Name => Make_Identifier (Loc, Name_uF),
2153 Expression => New_Reference_To (Standard_False, Loc)))));
2154 end if;
2156 if Is_Concurrent_Record_Type (Typ) then
2157 Conc_Typ := Corresponding_Concurrent_Type (Typ);
2159 -- Generate:
2160 -- I : Integer :=
2161 -- Ada.Tags.Get_Entry_Index (Ada.Tags.Tag! (<type>VP), S);
2163 -- where I will be used to capture the entry index of the primitive
2164 -- wrapper at position S.
2166 if Tagged_Type_Expansion then
2167 Tag_Node :=
2168 Unchecked_Convert_To (RTE (RE_Tag),
2169 New_Reference_To
2170 (Node (First_Elmt (Access_Disp_Table (Typ))), Loc));
2171 else
2172 Tag_Node :=
2173 Make_Attribute_Reference (Loc,
2174 Prefix => New_Reference_To (Typ, Loc),
2175 Attribute_Name => Name_Tag);
2176 end if;
2178 Append_To (Decls,
2179 Make_Object_Declaration (Loc,
2180 Defining_Identifier =>
2181 Make_Defining_Identifier (Loc, Name_uI),
2182 Object_Definition =>
2183 New_Reference_To (Standard_Integer, Loc),
2184 Expression =>
2185 Make_Function_Call (Loc,
2186 Name =>
2187 New_Reference_To (RTE (RE_Get_Entry_Index), Loc),
2188 Parameter_Associations =>
2189 New_List (
2190 Tag_Node,
2191 Make_Identifier (Loc, Name_uS)))));
2193 if Ekind (Conc_Typ) = E_Protected_Type then
2195 -- Generate:
2196 -- Bnn : Communication_Block;
2198 Com_Block := Make_Temporary (Loc, 'B');
2199 Append_To (Decls,
2200 Make_Object_Declaration (Loc,
2201 Defining_Identifier =>
2202 Com_Block,
2203 Object_Definition =>
2204 New_Reference_To (RTE (RE_Communication_Block), Loc)));
2206 -- Build T._object'Access for calls below
2208 Obj_Ref :=
2209 Make_Attribute_Reference (Loc,
2210 Attribute_Name => Name_Unchecked_Access,
2211 Prefix =>
2212 Make_Selected_Component (Loc,
2213 Prefix => Make_Identifier (Loc, Name_uT),
2214 Selector_Name => Make_Identifier (Loc, Name_uObject)));
2216 case Corresponding_Runtime_Package (Conc_Typ) is
2217 when System_Tasking_Protected_Objects_Entries =>
2219 -- Generate:
2220 -- Protected_Entry_Call
2221 -- (T._object'Access, -- Object
2222 -- Protected_Entry_Index! (I), -- E
2223 -- P, -- Uninterpreted_Data
2224 -- Asynchronous_Call, -- Mode
2225 -- Bnn); -- Communication_Block
2227 -- where T is the protected object, I is the entry index, P
2228 -- is the wrapped parameters and B is the name of the
2229 -- communication block.
2231 Append_To (Stmts,
2232 Make_Procedure_Call_Statement (Loc,
2233 Name =>
2234 New_Reference_To (RTE (RE_Protected_Entry_Call), Loc),
2235 Parameter_Associations =>
2236 New_List (
2237 Obj_Ref,
2239 Make_Unchecked_Type_Conversion (Loc, -- entry index
2240 Subtype_Mark =>
2241 New_Reference_To
2242 (RTE (RE_Protected_Entry_Index), Loc),
2243 Expression => Make_Identifier (Loc, Name_uI)),
2245 Make_Identifier (Loc, Name_uP), -- parameter block
2246 New_Reference_To -- Asynchronous_Call
2247 (RTE (RE_Asynchronous_Call), Loc),
2249 New_Reference_To (Com_Block, Loc)))); -- comm block
2251 when System_Tasking_Protected_Objects_Single_Entry =>
2253 -- Generate:
2254 -- procedure Protected_Single_Entry_Call
2255 -- (Object : Protection_Entry_Access;
2256 -- Uninterpreted_Data : System.Address;
2257 -- Mode : Call_Modes);
2259 Append_To (Stmts,
2260 Make_Procedure_Call_Statement (Loc,
2261 Name =>
2262 New_Reference_To
2263 (RTE (RE_Protected_Single_Entry_Call), Loc),
2264 Parameter_Associations =>
2265 New_List (
2266 Obj_Ref,
2268 Make_Attribute_Reference (Loc,
2269 Prefix => Make_Identifier (Loc, Name_uP),
2270 Attribute_Name => Name_Address),
2272 New_Reference_To
2273 (RTE (RE_Asynchronous_Call), Loc))));
2275 when others =>
2276 raise Program_Error;
2277 end case;
2279 -- Generate:
2280 -- B := Dummy_Communication_Block (Bnn);
2282 Append_To (Stmts,
2283 Make_Assignment_Statement (Loc,
2284 Name => Make_Identifier (Loc, Name_uB),
2285 Expression =>
2286 Make_Unchecked_Type_Conversion (Loc,
2287 Subtype_Mark =>
2288 New_Reference_To (
2289 RTE (RE_Dummy_Communication_Block), Loc),
2290 Expression =>
2291 New_Reference_To (Com_Block, Loc))));
2293 -- Generate:
2294 -- F := False;
2296 Append_To (Stmts,
2297 Make_Assignment_Statement (Loc,
2298 Name => Make_Identifier (Loc, Name_uF),
2299 Expression => New_Reference_To (Standard_False, Loc)));
2301 else
2302 pragma Assert (Ekind (Conc_Typ) = E_Task_Type);
2304 -- Generate:
2305 -- Task_Entry_Call
2306 -- (T._task_id, -- Acceptor
2307 -- Task_Entry_Index! (I), -- E
2308 -- P, -- Uninterpreted_Data
2309 -- Asynchronous_Call, -- Mode
2310 -- F); -- Rendezvous_Successful
2312 -- where T is the task object, I is the entry index, P is the
2313 -- wrapped parameters and F is the status flag.
2315 Append_To (Stmts,
2316 Make_Procedure_Call_Statement (Loc,
2317 Name =>
2318 New_Reference_To (RTE (RE_Task_Entry_Call), Loc),
2319 Parameter_Associations =>
2320 New_List (
2321 Make_Selected_Component (Loc, -- T._task_id
2322 Prefix => Make_Identifier (Loc, Name_uT),
2323 Selector_Name => Make_Identifier (Loc, Name_uTask_Id)),
2325 Make_Unchecked_Type_Conversion (Loc, -- entry index
2326 Subtype_Mark =>
2327 New_Reference_To (RTE (RE_Task_Entry_Index), Loc),
2328 Expression => Make_Identifier (Loc, Name_uI)),
2330 Make_Identifier (Loc, Name_uP), -- parameter block
2331 New_Reference_To -- Asynchronous_Call
2332 (RTE (RE_Asynchronous_Call), Loc),
2333 Make_Identifier (Loc, Name_uF)))); -- status flag
2334 end if;
2336 else
2337 -- Ensure that the statements list is non-empty
2339 Append_To (Stmts,
2340 Make_Assignment_Statement (Loc,
2341 Name => Make_Identifier (Loc, Name_uF),
2342 Expression => New_Reference_To (Standard_False, Loc)));
2343 end if;
2345 return
2346 Make_Subprogram_Body (Loc,
2347 Specification =>
2348 Make_Disp_Asynchronous_Select_Spec (Typ),
2349 Declarations => Decls,
2350 Handled_Statement_Sequence =>
2351 Make_Handled_Sequence_Of_Statements (Loc, Stmts));
2352 end Make_Disp_Asynchronous_Select_Body;
2354 ----------------------------------------
2355 -- Make_Disp_Asynchronous_Select_Spec --
2356 ----------------------------------------
2358 function Make_Disp_Asynchronous_Select_Spec
2359 (Typ : Entity_Id) return Node_Id
2361 Loc : constant Source_Ptr := Sloc (Typ);
2362 Def_Id : constant Node_Id :=
2363 Make_Defining_Identifier (Loc,
2364 Name_uDisp_Asynchronous_Select);
2365 Params : constant List_Id := New_List;
2367 begin
2368 pragma Assert (not Restriction_Active (No_Dispatching_Calls));
2370 -- T : in out Typ; -- Object parameter
2371 -- S : Integer; -- Primitive operation slot
2372 -- P : Address; -- Wrapped parameters
2373 -- B : out Dummy_Communication_Block; -- Communication block dummy
2374 -- F : out Boolean; -- Status flag
2376 Append_List_To (Params, New_List (
2378 Make_Parameter_Specification (Loc,
2379 Defining_Identifier =>
2380 Make_Defining_Identifier (Loc, Name_uT),
2381 Parameter_Type =>
2382 New_Reference_To (Typ, Loc),
2383 In_Present => True,
2384 Out_Present => True),
2386 Make_Parameter_Specification (Loc,
2387 Defining_Identifier =>
2388 Make_Defining_Identifier (Loc, Name_uS),
2389 Parameter_Type =>
2390 New_Reference_To (Standard_Integer, Loc)),
2392 Make_Parameter_Specification (Loc,
2393 Defining_Identifier =>
2394 Make_Defining_Identifier (Loc, Name_uP),
2395 Parameter_Type =>
2396 New_Reference_To (RTE (RE_Address), Loc)),
2398 Make_Parameter_Specification (Loc,
2399 Defining_Identifier =>
2400 Make_Defining_Identifier (Loc, Name_uB),
2401 Parameter_Type =>
2402 New_Reference_To (RTE (RE_Dummy_Communication_Block), Loc),
2403 Out_Present => True),
2405 Make_Parameter_Specification (Loc,
2406 Defining_Identifier =>
2407 Make_Defining_Identifier (Loc, Name_uF),
2408 Parameter_Type =>
2409 New_Reference_To (Standard_Boolean, Loc),
2410 Out_Present => True)));
2412 return
2413 Make_Procedure_Specification (Loc,
2414 Defining_Unit_Name => Def_Id,
2415 Parameter_Specifications => Params);
2416 end Make_Disp_Asynchronous_Select_Spec;
2418 ---------------------------------------
2419 -- Make_Disp_Conditional_Select_Body --
2420 ---------------------------------------
2422 -- For interface types, generate:
2424 -- procedure _Disp_Conditional_Select
2425 -- (T : in out <Typ>;
2426 -- S : Integer;
2427 -- P : System.Address;
2428 -- C : out Ada.Tags.Prim_Op_Kind;
2429 -- F : out Boolean)
2430 -- is
2431 -- begin
2432 -- F := False;
2433 -- C := Ada.Tags.POK_Function;
2434 -- end _Disp_Conditional_Select;
2436 -- For protected types, generate:
2438 -- procedure _Disp_Conditional_Select
2439 -- (T : in out <Typ>;
2440 -- S : Integer;
2441 -- P : System.Address;
2442 -- C : out Ada.Tags.Prim_Op_Kind;
2443 -- F : out Boolean)
2444 -- is
2445 -- I : Integer;
2446 -- Bnn : System.Tasking.Protected_Objects.Operations.
2447 -- Communication_Block;
2449 -- begin
2450 -- C := Ada.Tags.Get_Prim_Op_Kind (Ada.Tags.Tag (<Typ>VP, S));
2452 -- if C = Ada.Tags.POK_Procedure
2453 -- or else C = Ada.Tags.POK_Protected_Procedure
2454 -- or else C = Ada.Tags.POK_Task_Procedure
2455 -- then
2456 -- F := True;
2457 -- return;
2458 -- end if;
2460 -- I := Ada.Tags.Get_Entry_Index (Ada.Tags.Tag (<Typ>VP, S));
2461 -- System.Tasking.Protected_Objects.Operations.Protected_Entry_Call
2462 -- (T.object'Access,
2463 -- System.Tasking.Protected_Objects.Protected_Entry_Index (I),
2464 -- P,
2465 -- System.Tasking.Conditional_Call,
2466 -- Bnn);
2467 -- F := not Cancelled (Bnn);
2468 -- end _Disp_Conditional_Select;
2470 -- For task types, generate:
2472 -- procedure _Disp_Conditional_Select
2473 -- (T : in out <Typ>;
2474 -- S : Integer;
2475 -- P : System.Address;
2476 -- C : out Ada.Tags.Prim_Op_Kind;
2477 -- F : out Boolean)
2478 -- is
2479 -- I : Integer;
2481 -- begin
2482 -- I := Ada.Tags.Get_Entry_Index (Ada.Tags.Tag (<Typ>VP, S));
2483 -- System.Tasking.Rendezvous.Task_Entry_Call
2484 -- (T._task_id,
2485 -- System.Tasking.Task_Entry_Index (I),
2486 -- P,
2487 -- System.Tasking.Conditional_Call,
2488 -- F);
2489 -- end _Disp_Conditional_Select;
2491 function Make_Disp_Conditional_Select_Body
2492 (Typ : Entity_Id) return Node_Id
2494 Loc : constant Source_Ptr := Sloc (Typ);
2495 Blk_Nam : Entity_Id;
2496 Conc_Typ : Entity_Id := Empty;
2497 Decls : constant List_Id := New_List;
2498 Obj_Ref : Node_Id;
2499 Stmts : constant List_Id := New_List;
2500 Tag_Node : Node_Id;
2502 begin
2503 pragma Assert (not Restriction_Active (No_Dispatching_Calls));
2505 -- Null body is generated for interface types
2507 if Is_Interface (Typ) then
2508 return
2509 Make_Subprogram_Body (Loc,
2510 Specification =>
2511 Make_Disp_Conditional_Select_Spec (Typ),
2512 Declarations =>
2513 No_List,
2514 Handled_Statement_Sequence =>
2515 Make_Handled_Sequence_Of_Statements (Loc,
2516 New_List (Make_Assignment_Statement (Loc,
2517 Name => Make_Identifier (Loc, Name_uF),
2518 Expression => New_Reference_To (Standard_False, Loc)))));
2519 end if;
2521 if Is_Concurrent_Record_Type (Typ) then
2522 Conc_Typ := Corresponding_Concurrent_Type (Typ);
2524 -- Generate:
2525 -- I : Integer;
2527 -- where I will be used to capture the entry index of the primitive
2528 -- wrapper at position S.
2530 Append_To (Decls,
2531 Make_Object_Declaration (Loc,
2532 Defining_Identifier =>
2533 Make_Defining_Identifier (Loc, Name_uI),
2534 Object_Definition =>
2535 New_Reference_To (Standard_Integer, Loc)));
2537 -- Generate:
2538 -- C := Ada.Tags.Get_Prim_Op_Kind (Ada.Tags.Tag! (<type>VP), S);
2540 -- if C = POK_Procedure
2541 -- or else C = POK_Protected_Procedure
2542 -- or else C = POK_Task_Procedure;
2543 -- then
2544 -- F := True;
2545 -- return;
2546 -- end if;
2548 Build_Common_Dispatching_Select_Statements (Typ, Stmts);
2550 -- Generate:
2551 -- Bnn : Communication_Block;
2553 -- where Bnn is the name of the communication block used in the
2554 -- call to Protected_Entry_Call.
2556 Blk_Nam := Make_Temporary (Loc, 'B');
2557 Append_To (Decls,
2558 Make_Object_Declaration (Loc,
2559 Defining_Identifier =>
2560 Blk_Nam,
2561 Object_Definition =>
2562 New_Reference_To (RTE (RE_Communication_Block), Loc)));
2564 -- Generate:
2565 -- I := Ada.Tags.Get_Entry_Index (Ada.Tags.Tag! (<type>VP), S);
2567 -- I is the entry index and S is the dispatch table slot
2569 if Tagged_Type_Expansion then
2570 Tag_Node :=
2571 Unchecked_Convert_To (RTE (RE_Tag),
2572 New_Reference_To
2573 (Node (First_Elmt (Access_Disp_Table (Typ))), Loc));
2575 else
2576 Tag_Node :=
2577 Make_Attribute_Reference (Loc,
2578 Prefix => New_Reference_To (Typ, Loc),
2579 Attribute_Name => Name_Tag);
2580 end if;
2582 Append_To (Stmts,
2583 Make_Assignment_Statement (Loc,
2584 Name => Make_Identifier (Loc, Name_uI),
2585 Expression =>
2586 Make_Function_Call (Loc,
2587 Name =>
2588 New_Reference_To (RTE (RE_Get_Entry_Index), Loc),
2589 Parameter_Associations =>
2590 New_List (
2591 Tag_Node,
2592 Make_Identifier (Loc, Name_uS)))));
2594 if Ekind (Conc_Typ) = E_Protected_Type then
2596 Obj_Ref := -- T._object'Access
2597 Make_Attribute_Reference (Loc,
2598 Attribute_Name => Name_Unchecked_Access,
2599 Prefix =>
2600 Make_Selected_Component (Loc,
2601 Prefix => Make_Identifier (Loc, Name_uT),
2602 Selector_Name => Make_Identifier (Loc, Name_uObject)));
2604 case Corresponding_Runtime_Package (Conc_Typ) is
2605 when System_Tasking_Protected_Objects_Entries =>
2606 -- Generate:
2608 -- Protected_Entry_Call
2609 -- (T._object'Access, -- Object
2610 -- Protected_Entry_Index! (I), -- E
2611 -- P, -- Uninterpreted_Data
2612 -- Conditional_Call, -- Mode
2613 -- Bnn); -- Block
2615 -- where T is the protected object, I is the entry index, P
2616 -- are the wrapped parameters and Bnn is the name of the
2617 -- communication block.
2619 Append_To (Stmts,
2620 Make_Procedure_Call_Statement (Loc,
2621 Name =>
2622 New_Reference_To (RTE (RE_Protected_Entry_Call), Loc),
2623 Parameter_Associations =>
2624 New_List (
2625 Obj_Ref,
2627 Make_Unchecked_Type_Conversion (Loc, -- entry index
2628 Subtype_Mark =>
2629 New_Reference_To
2630 (RTE (RE_Protected_Entry_Index), Loc),
2631 Expression => Make_Identifier (Loc, Name_uI)),
2633 Make_Identifier (Loc, Name_uP), -- parameter block
2635 New_Reference_To ( -- Conditional_Call
2636 RTE (RE_Conditional_Call), Loc),
2637 New_Reference_To ( -- Bnn
2638 Blk_Nam, Loc))));
2640 when System_Tasking_Protected_Objects_Single_Entry =>
2642 -- If we are compiling for a restricted run-time, the call
2643 -- uses the simpler form.
2645 Append_To (Stmts,
2646 Make_Procedure_Call_Statement (Loc,
2647 Name =>
2648 New_Reference_To
2649 (RTE (RE_Protected_Single_Entry_Call), Loc),
2650 Parameter_Associations =>
2651 New_List (
2652 Obj_Ref,
2654 Make_Attribute_Reference (Loc,
2655 Prefix => Make_Identifier (Loc, Name_uP),
2656 Attribute_Name => Name_Address),
2658 New_Reference_To
2659 (RTE (RE_Conditional_Call), Loc))));
2660 when others =>
2661 raise Program_Error;
2662 end case;
2664 -- Generate:
2665 -- F := not Cancelled (Bnn);
2667 -- where F is the success flag. The status of Cancelled is negated
2668 -- in order to match the behaviour of the version for task types.
2670 Append_To (Stmts,
2671 Make_Assignment_Statement (Loc,
2672 Name => Make_Identifier (Loc, Name_uF),
2673 Expression =>
2674 Make_Op_Not (Loc,
2675 Right_Opnd =>
2676 Make_Function_Call (Loc,
2677 Name =>
2678 New_Reference_To (RTE (RE_Cancelled), Loc),
2679 Parameter_Associations =>
2680 New_List (
2681 New_Reference_To (Blk_Nam, Loc))))));
2682 else
2683 pragma Assert (Ekind (Conc_Typ) = E_Task_Type);
2685 -- Generate:
2686 -- Task_Entry_Call
2687 -- (T._task_id, -- Acceptor
2688 -- Task_Entry_Index! (I), -- E
2689 -- P, -- Uninterpreted_Data
2690 -- Conditional_Call, -- Mode
2691 -- F); -- Rendezvous_Successful
2693 -- where T is the task object, I is the entry index, P are the
2694 -- wrapped parameters and F is the status flag.
2696 Append_To (Stmts,
2697 Make_Procedure_Call_Statement (Loc,
2698 Name =>
2699 New_Reference_To (RTE (RE_Task_Entry_Call), Loc),
2700 Parameter_Associations =>
2701 New_List (
2703 Make_Selected_Component (Loc, -- T._task_id
2704 Prefix => Make_Identifier (Loc, Name_uT),
2705 Selector_Name => Make_Identifier (Loc, Name_uTask_Id)),
2707 Make_Unchecked_Type_Conversion (Loc, -- entry index
2708 Subtype_Mark =>
2709 New_Reference_To (RTE (RE_Task_Entry_Index), Loc),
2710 Expression => Make_Identifier (Loc, Name_uI)),
2712 Make_Identifier (Loc, Name_uP), -- parameter block
2713 New_Reference_To -- Conditional_Call
2714 (RTE (RE_Conditional_Call), Loc),
2715 Make_Identifier (Loc, Name_uF)))); -- status flag
2716 end if;
2718 else
2719 -- Initialize out parameters
2721 Append_To (Stmts,
2722 Make_Assignment_Statement (Loc,
2723 Name => Make_Identifier (Loc, Name_uF),
2724 Expression => New_Reference_To (Standard_False, Loc)));
2725 Append_To (Stmts,
2726 Make_Assignment_Statement (Loc,
2727 Name => Make_Identifier (Loc, Name_uC),
2728 Expression => New_Reference_To (RTE (RE_POK_Function), Loc)));
2729 end if;
2731 return
2732 Make_Subprogram_Body (Loc,
2733 Specification =>
2734 Make_Disp_Conditional_Select_Spec (Typ),
2735 Declarations => Decls,
2736 Handled_Statement_Sequence =>
2737 Make_Handled_Sequence_Of_Statements (Loc, Stmts));
2738 end Make_Disp_Conditional_Select_Body;
2740 ---------------------------------------
2741 -- Make_Disp_Conditional_Select_Spec --
2742 ---------------------------------------
2744 function Make_Disp_Conditional_Select_Spec
2745 (Typ : Entity_Id) return Node_Id
2747 Loc : constant Source_Ptr := Sloc (Typ);
2748 Def_Id : constant Node_Id :=
2749 Make_Defining_Identifier (Loc,
2750 Name_uDisp_Conditional_Select);
2751 Params : constant List_Id := New_List;
2753 begin
2754 pragma Assert (not Restriction_Active (No_Dispatching_Calls));
2756 -- T : in out Typ; -- Object parameter
2757 -- S : Integer; -- Primitive operation slot
2758 -- P : Address; -- Wrapped parameters
2759 -- C : out Prim_Op_Kind; -- Call kind
2760 -- F : out Boolean; -- Status flag
2762 Append_List_To (Params, New_List (
2764 Make_Parameter_Specification (Loc,
2765 Defining_Identifier =>
2766 Make_Defining_Identifier (Loc, Name_uT),
2767 Parameter_Type =>
2768 New_Reference_To (Typ, Loc),
2769 In_Present => True,
2770 Out_Present => True),
2772 Make_Parameter_Specification (Loc,
2773 Defining_Identifier =>
2774 Make_Defining_Identifier (Loc, Name_uS),
2775 Parameter_Type =>
2776 New_Reference_To (Standard_Integer, Loc)),
2778 Make_Parameter_Specification (Loc,
2779 Defining_Identifier =>
2780 Make_Defining_Identifier (Loc, Name_uP),
2781 Parameter_Type =>
2782 New_Reference_To (RTE (RE_Address), Loc)),
2784 Make_Parameter_Specification (Loc,
2785 Defining_Identifier =>
2786 Make_Defining_Identifier (Loc, Name_uC),
2787 Parameter_Type =>
2788 New_Reference_To (RTE (RE_Prim_Op_Kind), Loc),
2789 Out_Present => True),
2791 Make_Parameter_Specification (Loc,
2792 Defining_Identifier =>
2793 Make_Defining_Identifier (Loc, Name_uF),
2794 Parameter_Type =>
2795 New_Reference_To (Standard_Boolean, Loc),
2796 Out_Present => True)));
2798 return
2799 Make_Procedure_Specification (Loc,
2800 Defining_Unit_Name => Def_Id,
2801 Parameter_Specifications => Params);
2802 end Make_Disp_Conditional_Select_Spec;
2804 -------------------------------------
2805 -- Make_Disp_Get_Prim_Op_Kind_Body --
2806 -------------------------------------
2808 function Make_Disp_Get_Prim_Op_Kind_Body
2809 (Typ : Entity_Id) return Node_Id
2811 Loc : constant Source_Ptr := Sloc (Typ);
2812 Tag_Node : Node_Id;
2814 begin
2815 pragma Assert (not Restriction_Active (No_Dispatching_Calls));
2817 if Is_Interface (Typ) then
2818 return
2819 Make_Subprogram_Body (Loc,
2820 Specification =>
2821 Make_Disp_Get_Prim_Op_Kind_Spec (Typ),
2822 Declarations =>
2823 New_List,
2824 Handled_Statement_Sequence =>
2825 Make_Handled_Sequence_Of_Statements (Loc,
2826 New_List (Make_Null_Statement (Loc))));
2827 end if;
2829 -- Generate:
2830 -- C := get_prim_op_kind (tag! (<type>VP), S);
2832 -- where C is the out parameter capturing the call kind and S is the
2833 -- dispatch table slot number.
2835 if Tagged_Type_Expansion then
2836 Tag_Node :=
2837 Unchecked_Convert_To (RTE (RE_Tag),
2838 New_Reference_To
2839 (Node (First_Elmt (Access_Disp_Table (Typ))), Loc));
2841 else
2842 Tag_Node :=
2843 Make_Attribute_Reference (Loc,
2844 Prefix => New_Reference_To (Typ, Loc),
2845 Attribute_Name => Name_Tag);
2846 end if;
2848 return
2849 Make_Subprogram_Body (Loc,
2850 Specification =>
2851 Make_Disp_Get_Prim_Op_Kind_Spec (Typ),
2852 Declarations =>
2853 New_List,
2854 Handled_Statement_Sequence =>
2855 Make_Handled_Sequence_Of_Statements (Loc,
2856 New_List (
2857 Make_Assignment_Statement (Loc,
2858 Name =>
2859 Make_Identifier (Loc, Name_uC),
2860 Expression =>
2861 Make_Function_Call (Loc,
2862 Name =>
2863 New_Reference_To (RTE (RE_Get_Prim_Op_Kind), Loc),
2864 Parameter_Associations => New_List (
2865 Tag_Node,
2866 Make_Identifier (Loc, Name_uS)))))));
2867 end Make_Disp_Get_Prim_Op_Kind_Body;
2869 -------------------------------------
2870 -- Make_Disp_Get_Prim_Op_Kind_Spec --
2871 -------------------------------------
2873 function Make_Disp_Get_Prim_Op_Kind_Spec
2874 (Typ : Entity_Id) return Node_Id
2876 Loc : constant Source_Ptr := Sloc (Typ);
2877 Def_Id : constant Node_Id :=
2878 Make_Defining_Identifier (Loc,
2879 Name_uDisp_Get_Prim_Op_Kind);
2880 Params : constant List_Id := New_List;
2882 begin
2883 pragma Assert (not Restriction_Active (No_Dispatching_Calls));
2885 -- T : in out Typ; -- Object parameter
2886 -- S : Integer; -- Primitive operation slot
2887 -- C : out Prim_Op_Kind; -- Call kind
2889 Append_List_To (Params, New_List (
2891 Make_Parameter_Specification (Loc,
2892 Defining_Identifier =>
2893 Make_Defining_Identifier (Loc, Name_uT),
2894 Parameter_Type =>
2895 New_Reference_To (Typ, Loc),
2896 In_Present => True,
2897 Out_Present => True),
2899 Make_Parameter_Specification (Loc,
2900 Defining_Identifier =>
2901 Make_Defining_Identifier (Loc, Name_uS),
2902 Parameter_Type =>
2903 New_Reference_To (Standard_Integer, Loc)),
2905 Make_Parameter_Specification (Loc,
2906 Defining_Identifier =>
2907 Make_Defining_Identifier (Loc, Name_uC),
2908 Parameter_Type =>
2909 New_Reference_To (RTE (RE_Prim_Op_Kind), Loc),
2910 Out_Present => True)));
2912 return
2913 Make_Procedure_Specification (Loc,
2914 Defining_Unit_Name => Def_Id,
2915 Parameter_Specifications => Params);
2916 end Make_Disp_Get_Prim_Op_Kind_Spec;
2918 --------------------------------
2919 -- Make_Disp_Get_Task_Id_Body --
2920 --------------------------------
2922 function Make_Disp_Get_Task_Id_Body
2923 (Typ : Entity_Id) return Node_Id
2925 Loc : constant Source_Ptr := Sloc (Typ);
2926 Ret : Node_Id;
2928 begin
2929 pragma Assert (not Restriction_Active (No_Dispatching_Calls));
2931 if Is_Concurrent_Record_Type (Typ)
2932 and then Ekind (Corresponding_Concurrent_Type (Typ)) = E_Task_Type
2933 then
2934 -- Generate:
2935 -- return To_Address (_T._task_id);
2937 Ret :=
2938 Make_Simple_Return_Statement (Loc,
2939 Expression =>
2940 Make_Unchecked_Type_Conversion (Loc,
2941 Subtype_Mark =>
2942 New_Reference_To (RTE (RE_Address), Loc),
2943 Expression =>
2944 Make_Selected_Component (Loc,
2945 Prefix => Make_Identifier (Loc, Name_uT),
2946 Selector_Name => Make_Identifier (Loc, Name_uTask_Id))));
2948 -- A null body is constructed for non-task types
2950 else
2951 -- Generate:
2952 -- return Null_Address;
2954 Ret :=
2955 Make_Simple_Return_Statement (Loc,
2956 Expression =>
2957 New_Reference_To (RTE (RE_Null_Address), Loc));
2958 end if;
2960 return
2961 Make_Subprogram_Body (Loc,
2962 Specification =>
2963 Make_Disp_Get_Task_Id_Spec (Typ),
2964 Declarations =>
2965 New_List,
2966 Handled_Statement_Sequence =>
2967 Make_Handled_Sequence_Of_Statements (Loc,
2968 New_List (Ret)));
2969 end Make_Disp_Get_Task_Id_Body;
2971 --------------------------------
2972 -- Make_Disp_Get_Task_Id_Spec --
2973 --------------------------------
2975 function Make_Disp_Get_Task_Id_Spec
2976 (Typ : Entity_Id) return Node_Id
2978 Loc : constant Source_Ptr := Sloc (Typ);
2980 begin
2981 pragma Assert (not Restriction_Active (No_Dispatching_Calls));
2983 return
2984 Make_Function_Specification (Loc,
2985 Defining_Unit_Name =>
2986 Make_Defining_Identifier (Loc, Name_uDisp_Get_Task_Id),
2987 Parameter_Specifications => New_List (
2988 Make_Parameter_Specification (Loc,
2989 Defining_Identifier =>
2990 Make_Defining_Identifier (Loc, Name_uT),
2991 Parameter_Type =>
2992 New_Reference_To (Typ, Loc))),
2993 Result_Definition =>
2994 New_Reference_To (RTE (RE_Address), Loc));
2995 end Make_Disp_Get_Task_Id_Spec;
2997 ----------------------------
2998 -- Make_Disp_Requeue_Body --
2999 ----------------------------
3001 function Make_Disp_Requeue_Body
3002 (Typ : Entity_Id) return Node_Id
3004 Loc : constant Source_Ptr := Sloc (Typ);
3005 Conc_Typ : Entity_Id := Empty;
3006 Stmts : constant List_Id := New_List;
3008 begin
3009 pragma Assert (not Restriction_Active (No_Dispatching_Calls));
3011 -- Null body is generated for interface types and non-concurrent
3012 -- tagged types.
3014 if Is_Interface (Typ)
3015 or else not Is_Concurrent_Record_Type (Typ)
3016 then
3017 return
3018 Make_Subprogram_Body (Loc,
3019 Specification =>
3020 Make_Disp_Requeue_Spec (Typ),
3021 Declarations =>
3022 No_List,
3023 Handled_Statement_Sequence =>
3024 Make_Handled_Sequence_Of_Statements (Loc,
3025 New_List (Make_Null_Statement (Loc))));
3026 end if;
3028 Conc_Typ := Corresponding_Concurrent_Type (Typ);
3030 if Ekind (Conc_Typ) = E_Protected_Type then
3032 -- Generate statements:
3033 -- if F then
3034 -- System.Tasking.Protected_Objects.Operations.
3035 -- Requeue_Protected_Entry
3036 -- (Protection_Entries_Access (P),
3037 -- O._object'Unchecked_Access,
3038 -- Protected_Entry_Index (I),
3039 -- A);
3040 -- else
3041 -- System.Tasking.Protected_Objects.Operations.
3042 -- Requeue_Task_To_Protected_Entry
3043 -- (O._object'Unchecked_Access,
3044 -- Protected_Entry_Index (I),
3045 -- A);
3046 -- end if;
3048 if Restriction_Active (No_Entry_Queue) then
3049 Append_To (Stmts, Make_Null_Statement (Loc));
3050 else
3051 Append_To (Stmts,
3052 Make_If_Statement (Loc,
3053 Condition => Make_Identifier (Loc, Name_uF),
3055 Then_Statements =>
3056 New_List (
3058 -- Call to Requeue_Protected_Entry
3060 Make_Procedure_Call_Statement (Loc,
3061 Name =>
3062 New_Reference_To (
3063 RTE (RE_Requeue_Protected_Entry), Loc),
3064 Parameter_Associations =>
3065 New_List (
3067 Make_Unchecked_Type_Conversion (Loc, -- PEA (P)
3068 Subtype_Mark =>
3069 New_Reference_To (
3070 RTE (RE_Protection_Entries_Access), Loc),
3071 Expression =>
3072 Make_Identifier (Loc, Name_uP)),
3074 Make_Attribute_Reference (Loc, -- O._object'Acc
3075 Attribute_Name =>
3076 Name_Unchecked_Access,
3077 Prefix =>
3078 Make_Selected_Component (Loc,
3079 Prefix =>
3080 Make_Identifier (Loc, Name_uO),
3081 Selector_Name =>
3082 Make_Identifier (Loc, Name_uObject))),
3084 Make_Unchecked_Type_Conversion (Loc, -- entry index
3085 Subtype_Mark =>
3086 New_Reference_To (
3087 RTE (RE_Protected_Entry_Index), Loc),
3088 Expression => Make_Identifier (Loc, Name_uI)),
3090 Make_Identifier (Loc, Name_uA)))), -- abort status
3092 Else_Statements =>
3093 New_List (
3095 -- Call to Requeue_Task_To_Protected_Entry
3097 Make_Procedure_Call_Statement (Loc,
3098 Name =>
3099 New_Reference_To (
3100 RTE (RE_Requeue_Task_To_Protected_Entry), Loc),
3101 Parameter_Associations =>
3102 New_List (
3104 Make_Attribute_Reference (Loc, -- O._object'Acc
3105 Attribute_Name =>
3106 Name_Unchecked_Access,
3107 Prefix =>
3108 Make_Selected_Component (Loc,
3109 Prefix =>
3110 Make_Identifier (Loc, Name_uO),
3111 Selector_Name =>
3112 Make_Identifier (Loc, Name_uObject))),
3114 Make_Unchecked_Type_Conversion (Loc, -- entry index
3115 Subtype_Mark =>
3116 New_Reference_To (
3117 RTE (RE_Protected_Entry_Index), Loc),
3118 Expression =>
3119 Make_Identifier (Loc, Name_uI)),
3121 Make_Identifier (Loc, Name_uA)))))); -- abort status
3122 end if;
3123 else
3124 pragma Assert (Is_Task_Type (Conc_Typ));
3126 -- Generate:
3127 -- if F then
3128 -- System.Tasking.Rendezvous.Requeue_Protected_To_Task_Entry
3129 -- (Protection_Entries_Access (P),
3130 -- O._task_id,
3131 -- Task_Entry_Index (I),
3132 -- A);
3133 -- else
3134 -- System.Tasking.Rendezvous.Requeue_Task_Entry
3135 -- (O._task_id,
3136 -- Task_Entry_Index (I),
3137 -- A);
3138 -- end if;
3140 Append_To (Stmts,
3141 Make_If_Statement (Loc,
3142 Condition => Make_Identifier (Loc, Name_uF),
3144 Then_Statements => New_List (
3146 -- Call to Requeue_Protected_To_Task_Entry
3148 Make_Procedure_Call_Statement (Loc,
3149 Name =>
3150 New_Reference_To
3151 (RTE (RE_Requeue_Protected_To_Task_Entry), Loc),
3153 Parameter_Associations => New_List (
3155 Make_Unchecked_Type_Conversion (Loc, -- PEA (P)
3156 Subtype_Mark =>
3157 New_Reference_To
3158 (RTE (RE_Protection_Entries_Access), Loc),
3159 Expression => Make_Identifier (Loc, Name_uP)),
3161 Make_Selected_Component (Loc, -- O._task_id
3162 Prefix => Make_Identifier (Loc, Name_uO),
3163 Selector_Name => Make_Identifier (Loc, Name_uTask_Id)),
3165 Make_Unchecked_Type_Conversion (Loc, -- entry index
3166 Subtype_Mark =>
3167 New_Reference_To (RTE (RE_Task_Entry_Index), Loc),
3168 Expression => Make_Identifier (Loc, Name_uI)),
3170 Make_Identifier (Loc, Name_uA)))), -- abort status
3172 Else_Statements => New_List (
3174 -- Call to Requeue_Task_Entry
3176 Make_Procedure_Call_Statement (Loc,
3177 Name => New_Reference_To (RTE (RE_Requeue_Task_Entry), Loc),
3179 Parameter_Associations => New_List (
3181 Make_Selected_Component (Loc, -- O._task_id
3182 Prefix => Make_Identifier (Loc, Name_uO),
3183 Selector_Name => Make_Identifier (Loc, Name_uTask_Id)),
3185 Make_Unchecked_Type_Conversion (Loc, -- entry index
3186 Subtype_Mark =>
3187 New_Reference_To (RTE (RE_Task_Entry_Index), Loc),
3188 Expression => Make_Identifier (Loc, Name_uI)),
3190 Make_Identifier (Loc, Name_uA)))))); -- abort status
3191 end if;
3193 -- Even though no declarations are needed in both cases, we allocate
3194 -- a list for entities added by Freeze.
3196 return
3197 Make_Subprogram_Body (Loc,
3198 Specification =>
3199 Make_Disp_Requeue_Spec (Typ),
3200 Declarations =>
3201 New_List,
3202 Handled_Statement_Sequence =>
3203 Make_Handled_Sequence_Of_Statements (Loc, Stmts));
3204 end Make_Disp_Requeue_Body;
3206 ----------------------------
3207 -- Make_Disp_Requeue_Spec --
3208 ----------------------------
3210 function Make_Disp_Requeue_Spec
3211 (Typ : Entity_Id) return Node_Id
3213 Loc : constant Source_Ptr := Sloc (Typ);
3215 begin
3216 pragma Assert (not Restriction_Active (No_Dispatching_Calls));
3218 -- O : in out Typ; - Object parameter
3219 -- F : Boolean; - Protected (True) / task (False) flag
3220 -- P : Address; - Protection_Entries_Access value
3221 -- I : Entry_Index - Index of entry call
3222 -- A : Boolean - Abort flag
3224 -- Note that the Protection_Entries_Access value is represented as a
3225 -- System.Address in order to avoid dragging in the tasking runtime
3226 -- when compiling sources without tasking constructs.
3228 return
3229 Make_Procedure_Specification (Loc,
3230 Defining_Unit_Name =>
3231 Make_Defining_Identifier (Loc, Name_uDisp_Requeue),
3233 Parameter_Specifications =>
3234 New_List (
3236 Make_Parameter_Specification (Loc, -- O
3237 Defining_Identifier =>
3238 Make_Defining_Identifier (Loc, Name_uO),
3239 Parameter_Type =>
3240 New_Reference_To (Typ, Loc),
3241 In_Present => True,
3242 Out_Present => True),
3244 Make_Parameter_Specification (Loc, -- F
3245 Defining_Identifier =>
3246 Make_Defining_Identifier (Loc, Name_uF),
3247 Parameter_Type =>
3248 New_Reference_To (Standard_Boolean, Loc)),
3250 Make_Parameter_Specification (Loc, -- P
3251 Defining_Identifier =>
3252 Make_Defining_Identifier (Loc, Name_uP),
3253 Parameter_Type =>
3254 New_Reference_To (RTE (RE_Address), Loc)),
3256 Make_Parameter_Specification (Loc, -- I
3257 Defining_Identifier =>
3258 Make_Defining_Identifier (Loc, Name_uI),
3259 Parameter_Type =>
3260 New_Reference_To (Standard_Integer, Loc)),
3262 Make_Parameter_Specification (Loc, -- A
3263 Defining_Identifier =>
3264 Make_Defining_Identifier (Loc, Name_uA),
3265 Parameter_Type =>
3266 New_Reference_To (Standard_Boolean, Loc))));
3267 end Make_Disp_Requeue_Spec;
3269 ---------------------------------
3270 -- Make_Disp_Timed_Select_Body --
3271 ---------------------------------
3273 -- For interface types, generate:
3275 -- procedure _Disp_Timed_Select
3276 -- (T : in out <Typ>;
3277 -- S : Integer;
3278 -- P : System.Address;
3279 -- D : Duration;
3280 -- M : Integer;
3281 -- C : out Ada.Tags.Prim_Op_Kind;
3282 -- F : out Boolean)
3283 -- is
3284 -- begin
3285 -- F := False;
3286 -- C := Ada.Tags.POK_Function;
3287 -- end _Disp_Timed_Select;
3289 -- For protected types, generate:
3291 -- procedure _Disp_Timed_Select
3292 -- (T : in out <Typ>;
3293 -- S : Integer;
3294 -- P : System.Address;
3295 -- D : Duration;
3296 -- M : Integer;
3297 -- C : out Ada.Tags.Prim_Op_Kind;
3298 -- F : out Boolean)
3299 -- is
3300 -- I : Integer;
3302 -- begin
3303 -- C := Ada.Tags.Get_Prim_Op_Kind (Ada.Tags.Tag (<Typ>VP), S);
3305 -- if C = Ada.Tags.POK_Procedure
3306 -- or else C = Ada.Tags.POK_Protected_Procedure
3307 -- or else C = Ada.Tags.POK_Task_Procedure
3308 -- then
3309 -- F := True;
3310 -- return;
3311 -- end if;
3313 -- I := Ada.Tags.Get_Entry_Index (Ada.Tags.Tag (<Typ>VP), S);
3314 -- System.Tasking.Protected_Objects.Operations.
3315 -- Timed_Protected_Entry_Call
3316 -- (T._object'Access,
3317 -- System.Tasking.Protected_Objects.Protected_Entry_Index (I),
3318 -- P,
3319 -- D,
3320 -- M,
3321 -- F);
3322 -- end _Disp_Timed_Select;
3324 -- For task types, generate:
3326 -- procedure _Disp_Timed_Select
3327 -- (T : in out <Typ>;
3328 -- S : Integer;
3329 -- P : System.Address;
3330 -- D : Duration;
3331 -- M : Integer;
3332 -- C : out Ada.Tags.Prim_Op_Kind;
3333 -- F : out Boolean)
3334 -- is
3335 -- I : Integer;
3337 -- begin
3338 -- I := Ada.Tags.Get_Entry_Index (Ada.Tags.Tag (<Typ>VP), S);
3339 -- System.Tasking.Rendezvous.Timed_Task_Entry_Call
3340 -- (T._task_id,
3341 -- System.Tasking.Task_Entry_Index (I),
3342 -- P,
3343 -- D,
3344 -- M,
3345 -- F);
3346 -- end _Disp_Time_Select;
3348 function Make_Disp_Timed_Select_Body
3349 (Typ : Entity_Id) return Node_Id
3351 Loc : constant Source_Ptr := Sloc (Typ);
3352 Conc_Typ : Entity_Id := Empty;
3353 Decls : constant List_Id := New_List;
3354 Obj_Ref : Node_Id;
3355 Stmts : constant List_Id := New_List;
3356 Tag_Node : Node_Id;
3358 begin
3359 pragma Assert (not Restriction_Active (No_Dispatching_Calls));
3361 -- Null body is generated for interface types
3363 if Is_Interface (Typ) then
3364 return
3365 Make_Subprogram_Body (Loc,
3366 Specification =>
3367 Make_Disp_Timed_Select_Spec (Typ),
3368 Declarations =>
3369 New_List,
3370 Handled_Statement_Sequence =>
3371 Make_Handled_Sequence_Of_Statements (Loc,
3372 New_List (
3373 Make_Assignment_Statement (Loc,
3374 Name => Make_Identifier (Loc, Name_uF),
3375 Expression => New_Reference_To (Standard_False, Loc)))));
3376 end if;
3378 if Is_Concurrent_Record_Type (Typ) then
3379 Conc_Typ := Corresponding_Concurrent_Type (Typ);
3381 -- Generate:
3382 -- I : Integer;
3384 -- where I will be used to capture the entry index of the primitive
3385 -- wrapper at position S.
3387 Append_To (Decls,
3388 Make_Object_Declaration (Loc,
3389 Defining_Identifier => Make_Defining_Identifier (Loc, Name_uI),
3390 Object_Definition => New_Reference_To (Standard_Integer, Loc)));
3392 -- Generate:
3393 -- C := Get_Prim_Op_Kind (tag! (<type>VP), S);
3395 -- if C = POK_Procedure
3396 -- or else C = POK_Protected_Procedure
3397 -- or else C = POK_Task_Procedure;
3398 -- then
3399 -- F := True;
3400 -- return;
3401 -- end if;
3403 Build_Common_Dispatching_Select_Statements (Typ, Stmts);
3405 -- Generate:
3406 -- I := Get_Entry_Index (tag! (<type>VP), S);
3408 -- I is the entry index and S is the dispatch table slot
3410 if Tagged_Type_Expansion then
3411 Tag_Node :=
3412 Unchecked_Convert_To (RTE (RE_Tag),
3413 New_Reference_To
3414 (Node (First_Elmt (Access_Disp_Table (Typ))), Loc));
3416 else
3417 Tag_Node :=
3418 Make_Attribute_Reference (Loc,
3419 Prefix => New_Reference_To (Typ, Loc),
3420 Attribute_Name => Name_Tag);
3421 end if;
3423 Append_To (Stmts,
3424 Make_Assignment_Statement (Loc,
3425 Name => Make_Identifier (Loc, Name_uI),
3426 Expression =>
3427 Make_Function_Call (Loc,
3428 Name => New_Reference_To (RTE (RE_Get_Entry_Index), Loc),
3429 Parameter_Associations =>
3430 New_List (
3431 Tag_Node,
3432 Make_Identifier (Loc, Name_uS)))));
3434 -- Protected case
3436 if Ekind (Conc_Typ) = E_Protected_Type then
3438 -- Build T._object'Access
3440 Obj_Ref :=
3441 Make_Attribute_Reference (Loc,
3442 Attribute_Name => Name_Unchecked_Access,
3443 Prefix =>
3444 Make_Selected_Component (Loc,
3445 Prefix => Make_Identifier (Loc, Name_uT),
3446 Selector_Name => Make_Identifier (Loc, Name_uObject)));
3448 -- Normal case, No_Entry_Queue restriction not active. In this
3449 -- case we generate:
3451 -- Timed_Protected_Entry_Call
3452 -- (T._object'access,
3453 -- Protected_Entry_Index! (I),
3454 -- P, D, M, F);
3456 -- where T is the protected object, I is the entry index, P are
3457 -- the wrapped parameters, D is the delay amount, M is the delay
3458 -- mode and F is the status flag.
3460 case Corresponding_Runtime_Package (Conc_Typ) is
3461 when System_Tasking_Protected_Objects_Entries =>
3462 Append_To (Stmts,
3463 Make_Procedure_Call_Statement (Loc,
3464 Name =>
3465 New_Reference_To
3466 (RTE (RE_Timed_Protected_Entry_Call), Loc),
3467 Parameter_Associations =>
3468 New_List (
3469 Obj_Ref,
3471 Make_Unchecked_Type_Conversion (Loc, -- entry index
3472 Subtype_Mark =>
3473 New_Reference_To
3474 (RTE (RE_Protected_Entry_Index), Loc),
3475 Expression =>
3476 Make_Identifier (Loc, Name_uI)),
3478 Make_Identifier (Loc, Name_uP), -- parameter block
3479 Make_Identifier (Loc, Name_uD), -- delay
3480 Make_Identifier (Loc, Name_uM), -- delay mode
3481 Make_Identifier (Loc, Name_uF)))); -- status flag
3483 when System_Tasking_Protected_Objects_Single_Entry =>
3484 -- Generate:
3486 -- Timed_Protected_Single_Entry_Call
3487 -- (T._object'access, P, D, M, F);
3489 -- where T is the protected object, P is the wrapped
3490 -- parameters, D is the delay amount, M is the delay mode, F
3491 -- is the status flag.
3493 Append_To (Stmts,
3494 Make_Procedure_Call_Statement (Loc,
3495 Name =>
3496 New_Reference_To
3497 (RTE (RE_Timed_Protected_Single_Entry_Call), Loc),
3498 Parameter_Associations =>
3499 New_List (
3500 Obj_Ref,
3501 Make_Identifier (Loc, Name_uP), -- parameter block
3502 Make_Identifier (Loc, Name_uD), -- delay
3503 Make_Identifier (Loc, Name_uM), -- delay mode
3504 Make_Identifier (Loc, Name_uF)))); -- status flag
3506 when others =>
3507 raise Program_Error;
3508 end case;
3510 -- Task case
3512 else
3513 pragma Assert (Ekind (Conc_Typ) = E_Task_Type);
3515 -- Generate:
3516 -- Timed_Task_Entry_Call (
3517 -- T._task_id,
3518 -- Task_Entry_Index! (I),
3519 -- P,
3520 -- D,
3521 -- M,
3522 -- F);
3524 -- where T is the task object, I is the entry index, P are the
3525 -- wrapped parameters, D is the delay amount, M is the delay
3526 -- mode and F is the status flag.
3528 Append_To (Stmts,
3529 Make_Procedure_Call_Statement (Loc,
3530 Name =>
3531 New_Reference_To (RTE (RE_Timed_Task_Entry_Call), Loc),
3532 Parameter_Associations =>
3533 New_List (
3535 Make_Selected_Component (Loc, -- T._task_id
3536 Prefix => Make_Identifier (Loc, Name_uT),
3537 Selector_Name => Make_Identifier (Loc, Name_uTask_Id)),
3539 Make_Unchecked_Type_Conversion (Loc, -- entry index
3540 Subtype_Mark =>
3541 New_Reference_To (RTE (RE_Task_Entry_Index), Loc),
3542 Expression => Make_Identifier (Loc, Name_uI)),
3544 Make_Identifier (Loc, Name_uP), -- parameter block
3545 Make_Identifier (Loc, Name_uD), -- delay
3546 Make_Identifier (Loc, Name_uM), -- delay mode
3547 Make_Identifier (Loc, Name_uF)))); -- status flag
3548 end if;
3550 else
3551 -- Initialize out parameters
3553 Append_To (Stmts,
3554 Make_Assignment_Statement (Loc,
3555 Name => Make_Identifier (Loc, Name_uF),
3556 Expression => New_Reference_To (Standard_False, Loc)));
3557 Append_To (Stmts,
3558 Make_Assignment_Statement (Loc,
3559 Name => Make_Identifier (Loc, Name_uC),
3560 Expression => New_Reference_To (RTE (RE_POK_Function), Loc)));
3561 end if;
3563 return
3564 Make_Subprogram_Body (Loc,
3565 Specification => Make_Disp_Timed_Select_Spec (Typ),
3566 Declarations => Decls,
3567 Handled_Statement_Sequence =>
3568 Make_Handled_Sequence_Of_Statements (Loc, Stmts));
3569 end Make_Disp_Timed_Select_Body;
3571 ---------------------------------
3572 -- Make_Disp_Timed_Select_Spec --
3573 ---------------------------------
3575 function Make_Disp_Timed_Select_Spec
3576 (Typ : Entity_Id) return Node_Id
3578 Loc : constant Source_Ptr := Sloc (Typ);
3579 Def_Id : constant Node_Id :=
3580 Make_Defining_Identifier (Loc,
3581 Name_uDisp_Timed_Select);
3582 Params : constant List_Id := New_List;
3584 begin
3585 pragma Assert (not Restriction_Active (No_Dispatching_Calls));
3587 -- T : in out Typ; -- Object parameter
3588 -- S : Integer; -- Primitive operation slot
3589 -- P : Address; -- Wrapped parameters
3590 -- D : Duration; -- Delay
3591 -- M : Integer; -- Delay Mode
3592 -- C : out Prim_Op_Kind; -- Call kind
3593 -- F : out Boolean; -- Status flag
3595 Append_List_To (Params, New_List (
3597 Make_Parameter_Specification (Loc,
3598 Defining_Identifier =>
3599 Make_Defining_Identifier (Loc, Name_uT),
3600 Parameter_Type =>
3601 New_Reference_To (Typ, Loc),
3602 In_Present => True,
3603 Out_Present => True),
3605 Make_Parameter_Specification (Loc,
3606 Defining_Identifier =>
3607 Make_Defining_Identifier (Loc, Name_uS),
3608 Parameter_Type =>
3609 New_Reference_To (Standard_Integer, Loc)),
3611 Make_Parameter_Specification (Loc,
3612 Defining_Identifier =>
3613 Make_Defining_Identifier (Loc, Name_uP),
3614 Parameter_Type =>
3615 New_Reference_To (RTE (RE_Address), Loc)),
3617 Make_Parameter_Specification (Loc,
3618 Defining_Identifier =>
3619 Make_Defining_Identifier (Loc, Name_uD),
3620 Parameter_Type =>
3621 New_Reference_To (Standard_Duration, Loc)),
3623 Make_Parameter_Specification (Loc,
3624 Defining_Identifier =>
3625 Make_Defining_Identifier (Loc, Name_uM),
3626 Parameter_Type =>
3627 New_Reference_To (Standard_Integer, Loc)),
3629 Make_Parameter_Specification (Loc,
3630 Defining_Identifier =>
3631 Make_Defining_Identifier (Loc, Name_uC),
3632 Parameter_Type =>
3633 New_Reference_To (RTE (RE_Prim_Op_Kind), Loc),
3634 Out_Present => True)));
3636 Append_To (Params,
3637 Make_Parameter_Specification (Loc,
3638 Defining_Identifier =>
3639 Make_Defining_Identifier (Loc, Name_uF),
3640 Parameter_Type =>
3641 New_Reference_To (Standard_Boolean, Loc),
3642 Out_Present => True));
3644 return
3645 Make_Procedure_Specification (Loc,
3646 Defining_Unit_Name => Def_Id,
3647 Parameter_Specifications => Params);
3648 end Make_Disp_Timed_Select_Spec;
3650 -------------
3651 -- Make_DT --
3652 -------------
3654 -- The frontend supports two models for expanding dispatch tables
3655 -- associated with library-level defined tagged types: statically
3656 -- and non-statically allocated dispatch tables. In the former case
3657 -- the object containing the dispatch table is constant and it is
3658 -- initialized by means of a positional aggregate. In the latter case,
3659 -- the object containing the dispatch table is a variable which is
3660 -- initialized by means of assignments.
3662 -- In case of locally defined tagged types, the object containing the
3663 -- object containing the dispatch table is always a variable (instead
3664 -- of a constant). This is currently required to give support to late
3665 -- overriding of primitives. For example:
3667 -- procedure Example is
3668 -- package Pkg is
3669 -- type T1 is tagged null record;
3670 -- procedure Prim (O : T1);
3671 -- end Pkg;
3673 -- type T2 is new Pkg.T1 with null record;
3674 -- procedure Prim (X : T2) is -- late overriding
3675 -- begin
3676 -- ...
3677 -- ...
3678 -- end;
3680 function Make_DT (Typ : Entity_Id; N : Node_Id := Empty) return List_Id is
3681 Loc : constant Source_Ptr := Sloc (Typ);
3683 Max_Predef_Prims : constant Int :=
3684 UI_To_Int
3685 (Intval
3686 (Expression
3687 (Parent (RTE (RE_Max_Predef_Prims)))));
3689 DT_Decl : constant Elist_Id := New_Elmt_List;
3690 DT_Aggr : constant Elist_Id := New_Elmt_List;
3691 -- Entities marked with attribute Is_Dispatch_Table_Entity
3693 procedure Check_Premature_Freezing
3694 (Subp : Entity_Id;
3695 Tagged_Type : Entity_Id;
3696 Typ : Entity_Id);
3697 -- Verify that all non-tagged types in the profile of a subprogram
3698 -- are frozen at the point the subprogram is frozen. This enforces
3699 -- the rule on RM 13.14 (14) as modified by AI05-019. At the point a
3700 -- subprogram is frozen, enough must be known about it to build the
3701 -- activation record for it, which requires at least that the size of
3702 -- all parameters be known. Controlling arguments are by-reference,
3703 -- and therefore the rule only applies to non-tagged types.
3704 -- Typical violation of the rule involves an object declaration that
3705 -- freezes a tagged type, when one of its primitive operations has a
3706 -- type in its profile whose full view has not been analyzed yet.
3707 -- More complex cases involve composite types that have one private
3708 -- unfrozen subcomponent.
3710 procedure Export_DT (Typ : Entity_Id; DT : Entity_Id; Index : Nat := 0);
3711 -- Export the dispatch table DT of tagged type Typ. Required to generate
3712 -- forward references and statically allocate the table. For primary
3713 -- dispatch tables Index is 0; for secondary dispatch tables the value
3714 -- of index must match the Suffix_Index value assigned to the table by
3715 -- Make_Tags when generating its unique external name, and it is used to
3716 -- retrieve from the Dispatch_Table_Wrappers list associated with Typ
3717 -- the external name generated by Import_DT.
3719 procedure Make_Secondary_DT
3720 (Typ : Entity_Id;
3721 Iface : Entity_Id;
3722 Suffix_Index : Int;
3723 Num_Iface_Prims : Nat;
3724 Iface_DT_Ptr : Entity_Id;
3725 Predef_Prims_Ptr : Entity_Id;
3726 Build_Thunks : Boolean;
3727 Result : List_Id);
3728 -- Ada 2005 (AI-251): Expand the declarations for a Secondary Dispatch
3729 -- Table of Typ associated with Iface. Each abstract interface of Typ
3730 -- has two secondary dispatch tables: one containing pointers to thunks
3731 -- and another containing pointers to the primitives covering the
3732 -- interface primitives. The former secondary table is generated when
3733 -- Build_Thunks is True, and provides common support for dispatching
3734 -- calls through interface types; the latter secondary table is
3735 -- generated when Build_Thunks is False, and provides support for
3736 -- Generic Dispatching Constructors that dispatch calls through
3737 -- interface types. When constructing this latter table the value of
3738 -- Suffix_Index is -1 to indicate that there is no need to export such
3739 -- table when building statically allocated dispatch tables; a positive
3740 -- value of Suffix_Index must match the Suffix_Index value assigned to
3741 -- this secondary dispatch table by Make_Tags when its unique external
3742 -- name was generated.
3744 ------------------------------
3745 -- Check_Premature_Freezing --
3746 ------------------------------
3748 procedure Check_Premature_Freezing
3749 (Subp : Entity_Id;
3750 Tagged_Type : Entity_Id;
3751 Typ : Entity_Id)
3753 Comp : Entity_Id;
3755 function Is_Actual_For_Formal_Incomplete_Type
3756 (T : Entity_Id) return Boolean;
3757 -- In Ada 2012, if a nested generic has an incomplete formal type,
3758 -- the actual may be (and usually is) a private type whose completion
3759 -- appears later. It is safe to build the dispatch table in this
3760 -- case, gigi will have full views available.
3762 ------------------------------------------
3763 -- Is_Actual_For_Formal_Incomplete_Type --
3764 ------------------------------------------
3766 function Is_Actual_For_Formal_Incomplete_Type
3767 (T : Entity_Id) return Boolean
3769 Gen_Par : Entity_Id;
3770 F : Node_Id;
3772 begin
3773 if not Is_Generic_Instance (Current_Scope)
3774 or else not Used_As_Generic_Actual (T)
3775 then
3776 return False;
3778 else
3779 Gen_Par := Generic_Parent (Parent (Current_Scope));
3780 end if;
3782 F :=
3783 First
3784 (Generic_Formal_Declarations
3785 (Unit_Declaration_Node (Gen_Par)));
3786 while Present (F) loop
3787 if Ekind (Defining_Identifier (F)) = E_Incomplete_Type then
3788 return True;
3789 end if;
3791 Next (F);
3792 end loop;
3794 return False;
3795 end Is_Actual_For_Formal_Incomplete_Type;
3797 -- Start of processing for Check_Premature_Freezing
3799 begin
3800 -- Note that if the type is a (subtype of) a generic actual, the
3801 -- actual will have been frozen by the instantiation.
3803 if Present (N)
3804 and then Is_Private_Type (Typ)
3805 and then No (Full_View (Typ))
3806 and then not Is_Generic_Type (Typ)
3807 and then not Is_Tagged_Type (Typ)
3808 and then not Is_Frozen (Typ)
3809 and then not Is_Generic_Actual_Type (Typ)
3810 then
3811 Error_Msg_Sloc := Sloc (Subp);
3812 Error_Msg_NE
3813 ("declaration must appear after completion of type &", N, Typ);
3814 Error_Msg_NE
3815 ("\which is an untagged type in the profile of"
3816 & " primitive operation & declared#", N, Subp);
3818 else
3819 Comp := Private_Component (Typ);
3821 if not Is_Tagged_Type (Typ)
3822 and then Present (Comp)
3823 and then not Is_Frozen (Comp)
3824 and then
3825 not Is_Actual_For_Formal_Incomplete_Type (Comp)
3826 then
3827 Error_Msg_Sloc := Sloc (Subp);
3828 Error_Msg_Node_2 := Subp;
3829 Error_Msg_Name_1 := Chars (Tagged_Type);
3830 Error_Msg_NE
3831 ("declaration must appear after completion of type &",
3832 N, Comp);
3833 Error_Msg_NE
3834 ("\which is a component of untagged type& in the profile of"
3835 & " primitive & of type % that is frozen by the declaration ",
3836 N, Typ);
3837 end if;
3838 end if;
3839 end Check_Premature_Freezing;
3841 ---------------
3842 -- Export_DT --
3843 ---------------
3845 procedure Export_DT (Typ : Entity_Id; DT : Entity_Id; Index : Nat := 0)
3847 Count : Nat;
3848 Elmt : Elmt_Id;
3850 begin
3851 Set_Is_Statically_Allocated (DT);
3852 Set_Is_True_Constant (DT);
3853 Set_Is_Exported (DT);
3855 Count := 0;
3856 Elmt := First_Elmt (Dispatch_Table_Wrappers (Typ));
3857 while Count /= Index loop
3858 Next_Elmt (Elmt);
3859 Count := Count + 1;
3860 end loop;
3862 pragma Assert (Related_Type (Node (Elmt)) = Typ);
3864 Get_External_Name
3865 (Entity => Node (Elmt),
3866 Has_Suffix => True);
3868 Set_Interface_Name (DT,
3869 Make_String_Literal (Loc,
3870 Strval => String_From_Name_Buffer));
3872 -- Ensure proper Sprint output of this implicit importation
3874 Set_Is_Internal (DT);
3875 Set_Is_Public (DT);
3876 end Export_DT;
3878 -----------------------
3879 -- Make_Secondary_DT --
3880 -----------------------
3882 procedure Make_Secondary_DT
3883 (Typ : Entity_Id;
3884 Iface : Entity_Id;
3885 Suffix_Index : Int;
3886 Num_Iface_Prims : Nat;
3887 Iface_DT_Ptr : Entity_Id;
3888 Predef_Prims_Ptr : Entity_Id;
3889 Build_Thunks : Boolean;
3890 Result : List_Id)
3892 Loc : constant Source_Ptr := Sloc (Typ);
3893 Exporting_Table : constant Boolean :=
3894 Building_Static_DT (Typ)
3895 and then Suffix_Index > 0;
3896 Iface_DT : constant Entity_Id := Make_Temporary (Loc, 'T');
3897 Predef_Prims : constant Entity_Id := Make_Temporary (Loc, 'R');
3898 DT_Constr_List : List_Id;
3899 DT_Aggr_List : List_Id;
3900 Empty_DT : Boolean := False;
3901 Nb_Predef_Prims : Nat := 0;
3902 Nb_Prim : Nat;
3903 New_Node : Node_Id;
3904 OSD : Entity_Id;
3905 OSD_Aggr_List : List_Id;
3906 Pos : Nat;
3907 Prim : Entity_Id;
3908 Prim_Elmt : Elmt_Id;
3909 Prim_Ops_Aggr_List : List_Id;
3911 begin
3912 -- Handle cases in which we do not generate statically allocated
3913 -- dispatch tables.
3915 if not Building_Static_DT (Typ) then
3916 Set_Ekind (Predef_Prims, E_Variable);
3917 Set_Ekind (Iface_DT, E_Variable);
3919 -- Statically allocated dispatch tables and related entities are
3920 -- constants.
3922 else
3923 Set_Ekind (Predef_Prims, E_Constant);
3924 Set_Is_Statically_Allocated (Predef_Prims);
3925 Set_Is_True_Constant (Predef_Prims);
3927 Set_Ekind (Iface_DT, E_Constant);
3928 Set_Is_Statically_Allocated (Iface_DT);
3929 Set_Is_True_Constant (Iface_DT);
3930 end if;
3932 -- Calculate the number of slots of the dispatch table. If the number
3933 -- of primitives of Typ is 0 we reserve a dummy single entry for its
3934 -- DT because at run time the pointer to this dummy entry will be
3935 -- used as the tag.
3937 if Num_Iface_Prims = 0 then
3938 Empty_DT := True;
3939 Nb_Prim := 1;
3940 else
3941 Nb_Prim := Num_Iface_Prims;
3942 end if;
3944 -- Generate:
3946 -- Predef_Prims : Address_Array (1 .. Default_Prim_Ops_Count) :=
3947 -- (predef-prim-op-thunk-1'address,
3948 -- predef-prim-op-thunk-2'address,
3949 -- ...
3950 -- predef-prim-op-thunk-n'address);
3951 -- for Predef_Prims'Alignment use Address'Alignment
3953 -- Stage 1: Calculate the number of predefined primitives
3955 if not Building_Static_DT (Typ) then
3956 Nb_Predef_Prims := Max_Predef_Prims;
3957 else
3958 Prim_Elmt := First_Elmt (Primitive_Operations (Typ));
3959 while Present (Prim_Elmt) loop
3960 Prim := Node (Prim_Elmt);
3962 if Is_Predefined_Dispatching_Operation (Prim)
3963 and then not Is_Abstract_Subprogram (Prim)
3964 then
3965 Pos := UI_To_Int (DT_Position (Prim));
3967 if Pos > Nb_Predef_Prims then
3968 Nb_Predef_Prims := Pos;
3969 end if;
3970 end if;
3972 Next_Elmt (Prim_Elmt);
3973 end loop;
3974 end if;
3976 -- Stage 2: Create the thunks associated with the predefined
3977 -- primitives and save their entity to fill the aggregate.
3979 declare
3980 Prim_Table : array (Nat range 1 .. Nb_Predef_Prims) of Entity_Id;
3981 Decl : Node_Id;
3982 Thunk_Id : Entity_Id;
3983 Thunk_Code : Node_Id;
3985 begin
3986 Prim_Ops_Aggr_List := New_List;
3987 Prim_Table := (others => Empty);
3989 if Building_Static_DT (Typ) then
3990 Prim_Elmt := First_Elmt (Primitive_Operations (Typ));
3991 while Present (Prim_Elmt) loop
3992 Prim := Node (Prim_Elmt);
3994 if Is_Predefined_Dispatching_Operation (Prim)
3995 and then not Is_Abstract_Subprogram (Prim)
3996 and then not Is_Eliminated (Prim)
3997 and then not Present (Prim_Table
3998 (UI_To_Int (DT_Position (Prim))))
3999 then
4000 if not Build_Thunks then
4001 Prim_Table (UI_To_Int (DT_Position (Prim))) :=
4002 Alias (Prim);
4004 else
4005 Expand_Interface_Thunk
4006 (Ultimate_Alias (Prim), Thunk_Id, Thunk_Code);
4008 if Present (Thunk_Id) then
4009 Append_To (Result, Thunk_Code);
4010 Prim_Table (UI_To_Int (DT_Position (Prim)))
4011 := Thunk_Id;
4012 end if;
4013 end if;
4014 end if;
4016 Next_Elmt (Prim_Elmt);
4017 end loop;
4018 end if;
4020 for J in Prim_Table'Range loop
4021 if Present (Prim_Table (J)) then
4022 New_Node :=
4023 Unchecked_Convert_To (RTE (RE_Prim_Ptr),
4024 Make_Attribute_Reference (Loc,
4025 Prefix => New_Reference_To (Prim_Table (J), Loc),
4026 Attribute_Name => Name_Unrestricted_Access));
4027 else
4028 New_Node := Make_Null (Loc);
4029 end if;
4031 Append_To (Prim_Ops_Aggr_List, New_Node);
4032 end loop;
4034 New_Node :=
4035 Make_Aggregate (Loc,
4036 Expressions => Prim_Ops_Aggr_List);
4038 -- Remember aggregates initializing dispatch tables
4040 Append_Elmt (New_Node, DT_Aggr);
4042 Decl :=
4043 Make_Subtype_Declaration (Loc,
4044 Defining_Identifier => Make_Temporary (Loc, 'S'),
4045 Subtype_Indication =>
4046 New_Reference_To (RTE (RE_Address_Array), Loc));
4048 Append_To (Result, Decl);
4050 Append_To (Result,
4051 Make_Object_Declaration (Loc,
4052 Defining_Identifier => Predef_Prims,
4053 Constant_Present => Building_Static_DT (Typ),
4054 Aliased_Present => True,
4055 Object_Definition => New_Reference_To
4056 (Defining_Identifier (Decl), Loc),
4057 Expression => New_Node));
4059 Append_To (Result,
4060 Make_Attribute_Definition_Clause (Loc,
4061 Name => New_Reference_To (Predef_Prims, Loc),
4062 Chars => Name_Alignment,
4063 Expression =>
4064 Make_Attribute_Reference (Loc,
4065 Prefix =>
4066 New_Reference_To (RTE (RE_Integer_Address), Loc),
4067 Attribute_Name => Name_Alignment)));
4068 end;
4070 -- Generate
4072 -- OSD : Ada.Tags.Object_Specific_Data (Nb_Prims) :=
4073 -- (OSD_Table => (1 => <value>,
4074 -- ...
4075 -- N => <value>));
4077 -- Iface_DT : Dispatch_Table (Nb_Prims) :=
4078 -- ([ Signature => <sig-value> ],
4079 -- Tag_Kind => <tag_kind-value>,
4080 -- Predef_Prims => Predef_Prims'Address,
4081 -- Offset_To_Top => 0,
4082 -- OSD => OSD'Address,
4083 -- Prims_Ptr => (prim-op-1'address,
4084 -- prim-op-2'address,
4085 -- ...
4086 -- prim-op-n'address));
4087 -- for Iface_DT'Alignment use Address'Alignment;
4089 -- Stage 3: Initialize the discriminant and the record components
4091 DT_Constr_List := New_List;
4092 DT_Aggr_List := New_List;
4094 -- Nb_Prim. If the tagged type has no primitives we add a dummy
4095 -- slot whose address will be the tag of this type.
4097 if Nb_Prim = 0 then
4098 New_Node := Make_Integer_Literal (Loc, 1);
4099 else
4100 New_Node := Make_Integer_Literal (Loc, Nb_Prim);
4101 end if;
4103 Append_To (DT_Constr_List, New_Node);
4104 Append_To (DT_Aggr_List, New_Copy (New_Node));
4106 -- Signature
4108 if RTE_Record_Component_Available (RE_Signature) then
4109 Append_To (DT_Aggr_List,
4110 New_Reference_To (RTE (RE_Secondary_DT), Loc));
4111 end if;
4113 -- Tag_Kind
4115 if RTE_Record_Component_Available (RE_Tag_Kind) then
4116 Append_To (DT_Aggr_List, Tagged_Kind (Typ));
4117 end if;
4119 -- Predef_Prims
4121 Append_To (DT_Aggr_List,
4122 Make_Attribute_Reference (Loc,
4123 Prefix => New_Reference_To (Predef_Prims, Loc),
4124 Attribute_Name => Name_Address));
4126 -- Note: The correct value of Offset_To_Top will be set by the init
4127 -- subprogram
4129 Append_To (DT_Aggr_List, Make_Integer_Literal (Loc, 0));
4131 -- Generate the Object Specific Data table required to dispatch calls
4132 -- through synchronized interfaces.
4134 if Empty_DT
4135 or else Is_Abstract_Type (Typ)
4136 or else Is_Controlled (Typ)
4137 or else Restriction_Active (No_Dispatching_Calls)
4138 or else not Is_Limited_Type (Typ)
4139 or else not Has_Interfaces (Typ)
4140 or else not Build_Thunks
4141 or else not RTE_Record_Component_Available (RE_OSD_Table)
4142 then
4143 -- No OSD table required
4145 Append_To (DT_Aggr_List,
4146 New_Reference_To (RTE (RE_Null_Address), Loc));
4148 else
4149 OSD_Aggr_List := New_List;
4151 declare
4152 Prim_Table : array (Nat range 1 .. Nb_Prim) of Entity_Id;
4153 Prim : Entity_Id;
4154 Prim_Alias : Entity_Id;
4155 Prim_Elmt : Elmt_Id;
4156 E : Entity_Id;
4157 Count : Nat := 0;
4158 Pos : Nat;
4160 begin
4161 Prim_Table := (others => Empty);
4162 Prim_Alias := Empty;
4164 Prim_Elmt := First_Elmt (Primitive_Operations (Typ));
4165 while Present (Prim_Elmt) loop
4166 Prim := Node (Prim_Elmt);
4168 if Present (Interface_Alias (Prim))
4169 and then Find_Dispatching_Type
4170 (Interface_Alias (Prim)) = Iface
4171 then
4172 Prim_Alias := Interface_Alias (Prim);
4173 E := Ultimate_Alias (Prim);
4174 Pos := UI_To_Int (DT_Position (Prim_Alias));
4176 if Present (Prim_Table (Pos)) then
4177 pragma Assert (Prim_Table (Pos) = E);
4178 null;
4180 else
4181 Prim_Table (Pos) := E;
4183 Append_To (OSD_Aggr_List,
4184 Make_Component_Association (Loc,
4185 Choices => New_List (
4186 Make_Integer_Literal (Loc,
4187 DT_Position (Prim_Alias))),
4188 Expression =>
4189 Make_Integer_Literal (Loc,
4190 DT_Position (Alias (Prim)))));
4192 Count := Count + 1;
4193 end if;
4194 end if;
4196 Next_Elmt (Prim_Elmt);
4197 end loop;
4198 pragma Assert (Count = Nb_Prim);
4199 end;
4201 OSD := Make_Temporary (Loc, 'I');
4203 Append_To (Result,
4204 Make_Object_Declaration (Loc,
4205 Defining_Identifier => OSD,
4206 Object_Definition =>
4207 Make_Subtype_Indication (Loc,
4208 Subtype_Mark =>
4209 New_Reference_To (RTE (RE_Object_Specific_Data), Loc),
4210 Constraint =>
4211 Make_Index_Or_Discriminant_Constraint (Loc,
4212 Constraints => New_List (
4213 Make_Integer_Literal (Loc, Nb_Prim)))),
4215 Expression =>
4216 Make_Aggregate (Loc,
4217 Component_Associations => New_List (
4218 Make_Component_Association (Loc,
4219 Choices => New_List (
4220 New_Occurrence_Of
4221 (RTE_Record_Component (RE_OSD_Num_Prims), Loc)),
4222 Expression =>
4223 Make_Integer_Literal (Loc, Nb_Prim)),
4225 Make_Component_Association (Loc,
4226 Choices => New_List (
4227 New_Occurrence_Of
4228 (RTE_Record_Component (RE_OSD_Table), Loc)),
4229 Expression => Make_Aggregate (Loc,
4230 Component_Associations => OSD_Aggr_List))))));
4232 Append_To (Result,
4233 Make_Attribute_Definition_Clause (Loc,
4234 Name => New_Reference_To (OSD, Loc),
4235 Chars => Name_Alignment,
4236 Expression =>
4237 Make_Attribute_Reference (Loc,
4238 Prefix =>
4239 New_Reference_To (RTE (RE_Integer_Address), Loc),
4240 Attribute_Name => Name_Alignment)));
4242 -- In secondary dispatch tables the Typeinfo component contains
4243 -- the address of the Object Specific Data (see a-tags.ads)
4245 Append_To (DT_Aggr_List,
4246 Make_Attribute_Reference (Loc,
4247 Prefix => New_Reference_To (OSD, Loc),
4248 Attribute_Name => Name_Address));
4249 end if;
4251 -- Initialize the table of primitive operations
4253 Prim_Ops_Aggr_List := New_List;
4255 if Empty_DT then
4256 Append_To (Prim_Ops_Aggr_List, Make_Null (Loc));
4258 elsif Is_Abstract_Type (Typ)
4259 or else not Building_Static_DT (Typ)
4260 then
4261 for J in 1 .. Nb_Prim loop
4262 Append_To (Prim_Ops_Aggr_List, Make_Null (Loc));
4263 end loop;
4265 else
4266 declare
4267 CPP_Nb_Prims : constant Nat := CPP_Num_Prims (Typ);
4268 E : Entity_Id;
4269 Prim_Pos : Nat;
4270 Prim_Table : array (Nat range 1 .. Nb_Prim) of Entity_Id;
4271 Thunk_Code : Node_Id;
4272 Thunk_Id : Entity_Id;
4274 begin
4275 Prim_Table := (others => Empty);
4277 Prim_Elmt := First_Elmt (Primitive_Operations (Typ));
4278 while Present (Prim_Elmt) loop
4279 Prim := Node (Prim_Elmt);
4280 E := Ultimate_Alias (Prim);
4281 Prim_Pos := UI_To_Int (DT_Position (E));
4283 -- Do not reference predefined primitives because they are
4284 -- located in a separate dispatch table; skip abstract and
4285 -- eliminated primitives; skip primitives located in the C++
4286 -- part of the dispatch table because their slot is set by
4287 -- the IC routine.
4289 if not Is_Predefined_Dispatching_Operation (Prim)
4290 and then Present (Interface_Alias (Prim))
4291 and then not Is_Abstract_Subprogram (Alias (Prim))
4292 and then not Is_Eliminated (Alias (Prim))
4293 and then (not Is_CPP_Class (Root_Type (Typ))
4294 or else Prim_Pos > CPP_Nb_Prims)
4295 and then Find_Dispatching_Type
4296 (Interface_Alias (Prim)) = Iface
4298 -- Generate the code of the thunk only if the abstract
4299 -- interface type is not an immediate ancestor of
4300 -- Tagged_Type. Otherwise the DT associated with the
4301 -- interface is the primary DT.
4303 and then not Is_Ancestor (Iface, Typ,
4304 Use_Full_View => True)
4305 then
4306 if not Build_Thunks then
4307 Prim_Pos :=
4308 UI_To_Int (DT_Position (Interface_Alias (Prim)));
4309 Prim_Table (Prim_Pos) := Alias (Prim);
4311 else
4312 Expand_Interface_Thunk (Prim, Thunk_Id, Thunk_Code);
4314 if Present (Thunk_Id) then
4315 Prim_Pos :=
4316 UI_To_Int (DT_Position (Interface_Alias (Prim)));
4318 Prim_Table (Prim_Pos) := Thunk_Id;
4319 Append_To (Result, Thunk_Code);
4320 end if;
4321 end if;
4322 end if;
4324 Next_Elmt (Prim_Elmt);
4325 end loop;
4327 for J in Prim_Table'Range loop
4328 if Present (Prim_Table (J)) then
4329 New_Node :=
4330 Unchecked_Convert_To (RTE (RE_Prim_Ptr),
4331 Make_Attribute_Reference (Loc,
4332 Prefix => New_Reference_To (Prim_Table (J), Loc),
4333 Attribute_Name => Name_Unrestricted_Access));
4335 else
4336 New_Node := Make_Null (Loc);
4337 end if;
4339 Append_To (Prim_Ops_Aggr_List, New_Node);
4340 end loop;
4341 end;
4342 end if;
4344 New_Node :=
4345 Make_Aggregate (Loc,
4346 Expressions => Prim_Ops_Aggr_List);
4348 Append_To (DT_Aggr_List, New_Node);
4350 -- Remember aggregates initializing dispatch tables
4352 Append_Elmt (New_Node, DT_Aggr);
4354 -- Note: Secondary dispatch tables cannot be declared constant
4355 -- because the component Offset_To_Top is currently initialized
4356 -- by the IP routine.
4358 Append_To (Result,
4359 Make_Object_Declaration (Loc,
4360 Defining_Identifier => Iface_DT,
4361 Aliased_Present => True,
4362 Constant_Present => False,
4364 Object_Definition =>
4365 Make_Subtype_Indication (Loc,
4366 Subtype_Mark => New_Reference_To
4367 (RTE (RE_Dispatch_Table_Wrapper), Loc),
4368 Constraint => Make_Index_Or_Discriminant_Constraint (Loc,
4369 Constraints => DT_Constr_List)),
4371 Expression =>
4372 Make_Aggregate (Loc,
4373 Expressions => DT_Aggr_List)));
4375 Append_To (Result,
4376 Make_Attribute_Definition_Clause (Loc,
4377 Name => New_Reference_To (Iface_DT, Loc),
4378 Chars => Name_Alignment,
4380 Expression =>
4381 Make_Attribute_Reference (Loc,
4382 Prefix =>
4383 New_Reference_To (RTE (RE_Integer_Address), Loc),
4384 Attribute_Name => Name_Alignment)));
4386 if Exporting_Table then
4387 Export_DT (Typ, Iface_DT, Suffix_Index);
4389 -- Generate code to create the pointer to the dispatch table
4391 -- Iface_DT_Ptr : Tag := Tag!(DT.Prims_Ptr'Address);
4393 -- Note: This declaration is not added here if the table is exported
4394 -- because in such case Make_Tags has already added this declaration.
4396 else
4397 Append_To (Result,
4398 Make_Object_Declaration (Loc,
4399 Defining_Identifier => Iface_DT_Ptr,
4400 Constant_Present => True,
4402 Object_Definition =>
4403 New_Reference_To (RTE (RE_Interface_Tag), Loc),
4405 Expression =>
4406 Unchecked_Convert_To (RTE (RE_Interface_Tag),
4407 Make_Attribute_Reference (Loc,
4408 Prefix =>
4409 Make_Selected_Component (Loc,
4410 Prefix => New_Reference_To (Iface_DT, Loc),
4411 Selector_Name =>
4412 New_Occurrence_Of
4413 (RTE_Record_Component (RE_Prims_Ptr), Loc)),
4414 Attribute_Name => Name_Address))));
4415 end if;
4417 Append_To (Result,
4418 Make_Object_Declaration (Loc,
4419 Defining_Identifier => Predef_Prims_Ptr,
4420 Constant_Present => True,
4422 Object_Definition =>
4423 New_Reference_To (RTE (RE_Address), Loc),
4425 Expression =>
4426 Make_Attribute_Reference (Loc,
4427 Prefix =>
4428 Make_Selected_Component (Loc,
4429 Prefix => New_Reference_To (Iface_DT, Loc),
4430 Selector_Name =>
4431 New_Occurrence_Of
4432 (RTE_Record_Component (RE_Predef_Prims), Loc)),
4433 Attribute_Name => Name_Address)));
4435 -- Remember entities containing dispatch tables
4437 Append_Elmt (Predef_Prims, DT_Decl);
4438 Append_Elmt (Iface_DT, DT_Decl);
4439 end Make_Secondary_DT;
4441 -- Local variables
4443 Elab_Code : constant List_Id := New_List;
4444 Result : constant List_Id := New_List;
4445 Tname : constant Name_Id := Chars (Typ);
4446 AI : Elmt_Id;
4447 AI_Tag_Elmt : Elmt_Id;
4448 AI_Tag_Comp : Elmt_Id;
4449 DT_Aggr_List : List_Id;
4450 DT_Constr_List : List_Id;
4451 DT_Ptr : Entity_Id;
4452 ITable : Node_Id;
4453 I_Depth : Nat := 0;
4454 Iface_Table_Node : Node_Id;
4455 Name_ITable : Name_Id;
4456 Nb_Predef_Prims : Nat := 0;
4457 Nb_Prim : Nat := 0;
4458 New_Node : Node_Id;
4459 Num_Ifaces : Nat := 0;
4460 Parent_Typ : Entity_Id;
4461 Prim : Entity_Id;
4462 Prim_Elmt : Elmt_Id;
4463 Prim_Ops_Aggr_List : List_Id;
4464 Suffix_Index : Int;
4465 Typ_Comps : Elist_Id;
4466 Typ_Ifaces : Elist_Id;
4467 TSD_Aggr_List : List_Id;
4468 TSD_Tags_List : List_Id;
4470 -- The following name entries are used by Make_DT to generate a number
4471 -- of entities related to a tagged type. These entities may be generated
4472 -- in a scope other than that of the tagged type declaration, and if
4473 -- the entities for two tagged types with the same name happen to be
4474 -- generated in the same scope, we have to take care to use different
4475 -- names. This is achieved by means of a unique serial number appended
4476 -- to each generated entity name.
4478 Name_DT : constant Name_Id :=
4479 New_External_Name (Tname, 'T', Suffix_Index => -1);
4480 Name_Exname : constant Name_Id :=
4481 New_External_Name (Tname, 'E', Suffix_Index => -1);
4482 Name_HT_Link : constant Name_Id :=
4483 New_External_Name (Tname, 'H', Suffix_Index => -1);
4484 Name_Predef_Prims : constant Name_Id :=
4485 New_External_Name (Tname, 'R', Suffix_Index => -1);
4486 Name_SSD : constant Name_Id :=
4487 New_External_Name (Tname, 'S', Suffix_Index => -1);
4488 Name_TSD : constant Name_Id :=
4489 New_External_Name (Tname, 'B', Suffix_Index => -1);
4491 -- Entities built with above names
4493 DT : constant Entity_Id :=
4494 Make_Defining_Identifier (Loc, Name_DT);
4495 Exname : constant Entity_Id :=
4496 Make_Defining_Identifier (Loc, Name_Exname);
4497 HT_Link : constant Entity_Id :=
4498 Make_Defining_Identifier (Loc, Name_HT_Link);
4499 Predef_Prims : constant Entity_Id :=
4500 Make_Defining_Identifier (Loc, Name_Predef_Prims);
4501 SSD : constant Entity_Id :=
4502 Make_Defining_Identifier (Loc, Name_SSD);
4503 TSD : constant Entity_Id :=
4504 Make_Defining_Identifier (Loc, Name_TSD);
4506 -- Start of processing for Make_DT
4508 begin
4509 pragma Assert (Is_Frozen (Typ));
4511 -- Handle cases in which there is no need to build the dispatch table
4513 if Has_Dispatch_Table (Typ)
4514 or else No (Access_Disp_Table (Typ))
4515 or else Is_CPP_Class (Typ)
4516 or else Convention (Typ) = Convention_CIL
4517 or else Convention (Typ) = Convention_Java
4518 then
4519 return Result;
4521 elsif No_Run_Time_Mode then
4522 Error_Msg_CRT ("tagged types", Typ);
4523 return Result;
4525 elsif not RTE_Available (RE_Tag) then
4526 Append_To (Result,
4527 Make_Object_Declaration (Loc,
4528 Defining_Identifier => Node (First_Elmt
4529 (Access_Disp_Table (Typ))),
4530 Object_Definition => New_Reference_To (RTE (RE_Tag), Loc),
4531 Constant_Present => True,
4532 Expression =>
4533 Unchecked_Convert_To (RTE (RE_Tag),
4534 New_Reference_To (RTE (RE_Null_Address), Loc))));
4536 Analyze_List (Result, Suppress => All_Checks);
4537 Error_Msg_CRT ("tagged types", Typ);
4538 return Result;
4539 end if;
4541 -- Ensure that the value of Max_Predef_Prims defined in a-tags is
4542 -- correct. Valid values are 9 under configurable runtime or 15
4543 -- with full runtime.
4545 if RTE_Available (RE_Interface_Data) then
4546 if Max_Predef_Prims /= 15 then
4547 Error_Msg_N ("run-time library configuration error", Typ);
4548 return Result;
4549 end if;
4550 else
4551 if Max_Predef_Prims /= 9 then
4552 Error_Msg_N ("run-time library configuration error", Typ);
4553 Error_Msg_CRT ("tagged types", Typ);
4554 return Result;
4555 end if;
4556 end if;
4558 -- Initialize Parent_Typ handling private types
4560 Parent_Typ := Etype (Typ);
4562 if Present (Full_View (Parent_Typ)) then
4563 Parent_Typ := Full_View (Parent_Typ);
4564 end if;
4566 -- Ensure that all the primitives are frozen. This is only required when
4567 -- building static dispatch tables --- the primitives must be frozen to
4568 -- be referenced (otherwise we have problems with the backend). It is
4569 -- not a requirement with nonstatic dispatch tables because in this case
4570 -- we generate now an empty dispatch table; the extra code required to
4571 -- register the primitives in the slots will be generated later --- when
4572 -- each primitive is frozen (see Freeze_Subprogram).
4574 if Building_Static_DT (Typ) then
4575 declare
4576 Save : constant Boolean := Freezing_Library_Level_Tagged_Type;
4577 Prim : Entity_Id;
4578 Prim_Elmt : Elmt_Id;
4579 Frnodes : List_Id;
4581 begin
4582 Freezing_Library_Level_Tagged_Type := True;
4584 Prim_Elmt := First_Elmt (Primitive_Operations (Typ));
4585 while Present (Prim_Elmt) loop
4586 Prim := Node (Prim_Elmt);
4587 Frnodes := Freeze_Entity (Prim, Typ);
4589 declare
4590 F : Entity_Id;
4592 begin
4593 F := First_Formal (Prim);
4594 while Present (F) loop
4595 Check_Premature_Freezing (Prim, Typ, Etype (F));
4596 Next_Formal (F);
4597 end loop;
4599 Check_Premature_Freezing (Prim, Typ, Etype (Prim));
4600 end;
4602 if Present (Frnodes) then
4603 Append_List_To (Result, Frnodes);
4604 end if;
4606 Next_Elmt (Prim_Elmt);
4607 end loop;
4609 Freezing_Library_Level_Tagged_Type := Save;
4610 end;
4611 end if;
4613 -- Ada 2005 (AI-251): Build the secondary dispatch tables
4615 if Has_Interfaces (Typ) then
4616 Collect_Interface_Components (Typ, Typ_Comps);
4618 -- Each secondary dispatch table is assigned an unique positive
4619 -- suffix index; such value also corresponds with the location of
4620 -- its entity in the Dispatch_Table_Wrappers list (see Make_Tags).
4622 -- Note: This value must be kept sync with the Suffix_Index values
4623 -- generated by Make_Tags
4625 Suffix_Index := 1;
4626 AI_Tag_Elmt :=
4627 Next_Elmt (Next_Elmt (First_Elmt (Access_Disp_Table (Typ))));
4629 AI_Tag_Comp := First_Elmt (Typ_Comps);
4630 while Present (AI_Tag_Comp) loop
4631 pragma Assert (Has_Suffix (Node (AI_Tag_Elmt), 'P'));
4633 -- Build the secondary table containing pointers to thunks
4635 Make_Secondary_DT
4636 (Typ => Typ,
4637 Iface => Base_Type (Related_Type (Node (AI_Tag_Comp))),
4638 Suffix_Index => Suffix_Index,
4639 Num_Iface_Prims => UI_To_Int
4640 (DT_Entry_Count (Node (AI_Tag_Comp))),
4641 Iface_DT_Ptr => Node (AI_Tag_Elmt),
4642 Predef_Prims_Ptr => Node (Next_Elmt (AI_Tag_Elmt)),
4643 Build_Thunks => True,
4644 Result => Result);
4646 -- Skip secondary dispatch table referencing thunks to predefined
4647 -- primitives.
4649 Next_Elmt (AI_Tag_Elmt);
4650 pragma Assert (Has_Suffix (Node (AI_Tag_Elmt), 'Y'));
4652 -- Secondary dispatch table referencing user-defined primitives
4653 -- covered by this interface.
4655 Next_Elmt (AI_Tag_Elmt);
4656 pragma Assert (Has_Suffix (Node (AI_Tag_Elmt), 'D'));
4658 -- Build the secondary table containing pointers to primitives
4659 -- (used to give support to Generic Dispatching Constructors).
4661 Make_Secondary_DT
4662 (Typ => Typ,
4663 Iface => Base_Type
4664 (Related_Type (Node (AI_Tag_Comp))),
4665 Suffix_Index => -1,
4666 Num_Iface_Prims => UI_To_Int
4667 (DT_Entry_Count (Node (AI_Tag_Comp))),
4668 Iface_DT_Ptr => Node (AI_Tag_Elmt),
4669 Predef_Prims_Ptr => Node (Next_Elmt (AI_Tag_Elmt)),
4670 Build_Thunks => False,
4671 Result => Result);
4673 -- Skip secondary dispatch table referencing predefined primitives
4675 Next_Elmt (AI_Tag_Elmt);
4676 pragma Assert (Has_Suffix (Node (AI_Tag_Elmt), 'Z'));
4678 Suffix_Index := Suffix_Index + 1;
4679 Next_Elmt (AI_Tag_Elmt);
4680 Next_Elmt (AI_Tag_Comp);
4681 end loop;
4682 end if;
4684 -- Get the _tag entity and number of primitives of its dispatch table
4686 DT_Ptr := Node (First_Elmt (Access_Disp_Table (Typ)));
4687 Nb_Prim := UI_To_Int (DT_Entry_Count (First_Tag_Component (Typ)));
4689 Set_Is_Statically_Allocated (DT, Is_Library_Level_Tagged_Type (Typ));
4690 Set_Is_Statically_Allocated (SSD, Is_Library_Level_Tagged_Type (Typ));
4691 Set_Is_Statically_Allocated (TSD, Is_Library_Level_Tagged_Type (Typ));
4692 Set_Is_Statically_Allocated (Predef_Prims,
4693 Is_Library_Level_Tagged_Type (Typ));
4695 -- In case of locally defined tagged type we declare the object
4696 -- containing the dispatch table by means of a variable. Its
4697 -- initialization is done later by means of an assignment. This is
4698 -- required to generate its External_Tag.
4700 if not Building_Static_DT (Typ) then
4702 -- Generate:
4703 -- DT : No_Dispatch_Table_Wrapper;
4704 -- for DT'Alignment use Address'Alignment;
4705 -- DT_Ptr : Tag := !Tag (DT.NDT_Prims_Ptr'Address);
4707 if not Has_DT (Typ) then
4708 Append_To (Result,
4709 Make_Object_Declaration (Loc,
4710 Defining_Identifier => DT,
4711 Aliased_Present => True,
4712 Constant_Present => False,
4713 Object_Definition =>
4714 New_Reference_To
4715 (RTE (RE_No_Dispatch_Table_Wrapper), Loc)));
4717 Append_To (Result,
4718 Make_Attribute_Definition_Clause (Loc,
4719 Name => New_Reference_To (DT, Loc),
4720 Chars => Name_Alignment,
4721 Expression =>
4722 Make_Attribute_Reference (Loc,
4723 Prefix =>
4724 New_Reference_To (RTE (RE_Integer_Address), Loc),
4725 Attribute_Name => Name_Alignment)));
4727 Append_To (Result,
4728 Make_Object_Declaration (Loc,
4729 Defining_Identifier => DT_Ptr,
4730 Object_Definition => New_Reference_To (RTE (RE_Tag), Loc),
4731 Constant_Present => True,
4732 Expression =>
4733 Unchecked_Convert_To (RTE (RE_Tag),
4734 Make_Attribute_Reference (Loc,
4735 Prefix =>
4736 Make_Selected_Component (Loc,
4737 Prefix => New_Reference_To (DT, Loc),
4738 Selector_Name =>
4739 New_Occurrence_Of
4740 (RTE_Record_Component (RE_NDT_Prims_Ptr), Loc)),
4741 Attribute_Name => Name_Address))));
4743 Set_Is_Statically_Allocated (DT_Ptr,
4744 Is_Library_Level_Tagged_Type (Typ));
4746 -- Generate the SCIL node for the previous object declaration
4747 -- because it has a tag initialization.
4749 if Generate_SCIL then
4750 New_Node :=
4751 Make_SCIL_Dispatch_Table_Tag_Init (Sloc (Last (Result)));
4752 Set_SCIL_Entity (New_Node, Typ);
4753 Set_SCIL_Node (Last (Result), New_Node);
4754 end if;
4756 -- Generate:
4757 -- DT : Dispatch_Table_Wrapper (Nb_Prim);
4758 -- for DT'Alignment use Address'Alignment;
4759 -- DT_Ptr : Tag := !Tag (DT.Prims_Ptr'Address);
4761 else
4762 -- If the tagged type has no primitives we add a dummy slot
4763 -- whose address will be the tag of this type.
4765 if Nb_Prim = 0 then
4766 DT_Constr_List :=
4767 New_List (Make_Integer_Literal (Loc, 1));
4768 else
4769 DT_Constr_List :=
4770 New_List (Make_Integer_Literal (Loc, Nb_Prim));
4771 end if;
4773 Append_To (Result,
4774 Make_Object_Declaration (Loc,
4775 Defining_Identifier => DT,
4776 Aliased_Present => True,
4777 Constant_Present => False,
4778 Object_Definition =>
4779 Make_Subtype_Indication (Loc,
4780 Subtype_Mark =>
4781 New_Reference_To (RTE (RE_Dispatch_Table_Wrapper), Loc),
4782 Constraint => Make_Index_Or_Discriminant_Constraint (Loc,
4783 Constraints => DT_Constr_List))));
4785 Append_To (Result,
4786 Make_Attribute_Definition_Clause (Loc,
4787 Name => New_Reference_To (DT, Loc),
4788 Chars => Name_Alignment,
4789 Expression =>
4790 Make_Attribute_Reference (Loc,
4791 Prefix =>
4792 New_Reference_To (RTE (RE_Integer_Address), Loc),
4793 Attribute_Name => Name_Alignment)));
4795 Append_To (Result,
4796 Make_Object_Declaration (Loc,
4797 Defining_Identifier => DT_Ptr,
4798 Object_Definition => New_Reference_To (RTE (RE_Tag), Loc),
4799 Constant_Present => True,
4800 Expression =>
4801 Unchecked_Convert_To (RTE (RE_Tag),
4802 Make_Attribute_Reference (Loc,
4803 Prefix =>
4804 Make_Selected_Component (Loc,
4805 Prefix => New_Reference_To (DT, Loc),
4806 Selector_Name =>
4807 New_Occurrence_Of
4808 (RTE_Record_Component (RE_Prims_Ptr), Loc)),
4809 Attribute_Name => Name_Address))));
4811 Set_Is_Statically_Allocated (DT_Ptr,
4812 Is_Library_Level_Tagged_Type (Typ));
4814 -- Generate the SCIL node for the previous object declaration
4815 -- because it has a tag initialization.
4817 if Generate_SCIL then
4818 New_Node :=
4819 Make_SCIL_Dispatch_Table_Tag_Init (Sloc (Last (Result)));
4820 Set_SCIL_Entity (New_Node, Typ);
4821 Set_SCIL_Node (Last (Result), New_Node);
4822 end if;
4824 Append_To (Result,
4825 Make_Object_Declaration (Loc,
4826 Defining_Identifier =>
4827 Node (Next_Elmt (First_Elmt (Access_Disp_Table (Typ)))),
4828 Constant_Present => True,
4829 Object_Definition => New_Reference_To
4830 (RTE (RE_Address), Loc),
4831 Expression =>
4832 Make_Attribute_Reference (Loc,
4833 Prefix =>
4834 Make_Selected_Component (Loc,
4835 Prefix => New_Reference_To (DT, Loc),
4836 Selector_Name =>
4837 New_Occurrence_Of
4838 (RTE_Record_Component (RE_Predef_Prims), Loc)),
4839 Attribute_Name => Name_Address)));
4840 end if;
4841 end if;
4843 -- Generate: Exname : constant String := full_qualified_name (typ);
4844 -- The type itself may be an anonymous parent type, so use the first
4845 -- subtype to have a user-recognizable name.
4847 Append_To (Result,
4848 Make_Object_Declaration (Loc,
4849 Defining_Identifier => Exname,
4850 Constant_Present => True,
4851 Object_Definition => New_Reference_To (Standard_String, Loc),
4852 Expression =>
4853 Make_String_Literal (Loc,
4854 Fully_Qualified_Name_String (First_Subtype (Typ)))));
4856 Set_Is_Statically_Allocated (Exname);
4857 Set_Is_True_Constant (Exname);
4859 -- Declare the object used by Ada.Tags.Register_Tag
4861 if RTE_Available (RE_Register_Tag) then
4862 Append_To (Result,
4863 Make_Object_Declaration (Loc,
4864 Defining_Identifier => HT_Link,
4865 Object_Definition => New_Reference_To (RTE (RE_Tag), Loc)));
4866 end if;
4868 -- Generate code to create the storage for the type specific data object
4869 -- with enough space to store the tags of the ancestors plus the tags
4870 -- of all the implemented interfaces (as described in a-tags.adb).
4872 -- TSD : Type_Specific_Data (I_Depth) :=
4873 -- (Idepth => I_Depth,
4874 -- Access_Level => Type_Access_Level (Typ),
4875 -- Alignment => Typ'Alignment,
4876 -- Expanded_Name => Cstring_Ptr!(Exname'Address))
4877 -- External_Tag => Cstring_Ptr!(Exname'Address))
4878 -- HT_Link => HT_Link'Address,
4879 -- Transportable => <<boolean-value>>,
4880 -- Type_Is_Abstract => <<boolean-value>>,
4881 -- Needs_Finalization => <<boolean-value>>,
4882 -- [ Size_Func => Size_Prim'Access, ]
4883 -- [ Interfaces_Table => <<access-value>>, ]
4884 -- [ SSD => SSD_Table'Address ]
4885 -- Tags_Table => (0 => null,
4886 -- 1 => Parent'Tag
4887 -- ...);
4888 -- for TSD'Alignment use Address'Alignment
4890 TSD_Aggr_List := New_List;
4892 -- Idepth: Count ancestors to compute the inheritance depth. For private
4893 -- extensions, always go to the full view in order to compute the real
4894 -- inheritance depth.
4896 declare
4897 Current_Typ : Entity_Id;
4898 Parent_Typ : Entity_Id;
4900 begin
4901 I_Depth := 0;
4902 Current_Typ := Typ;
4903 loop
4904 Parent_Typ := Etype (Current_Typ);
4906 if Is_Private_Type (Parent_Typ) then
4907 Parent_Typ := Full_View (Base_Type (Parent_Typ));
4908 end if;
4910 exit when Parent_Typ = Current_Typ;
4912 I_Depth := I_Depth + 1;
4913 Current_Typ := Parent_Typ;
4914 end loop;
4915 end;
4917 Append_To (TSD_Aggr_List,
4918 Make_Integer_Literal (Loc, I_Depth));
4920 -- Access_Level
4922 Append_To (TSD_Aggr_List,
4923 Make_Integer_Literal (Loc, Type_Access_Level (Typ)));
4925 -- Alignment
4927 -- For CPP types we cannot rely on the value of 'Alignment provided
4928 -- by the backend to initialize this TSD field.
4930 if Convention (Typ) = Convention_CPP
4931 or else Is_CPP_Class (Root_Type (Typ))
4932 then
4933 Append_To (TSD_Aggr_List,
4934 Make_Integer_Literal (Loc, 0));
4935 else
4936 Append_To (TSD_Aggr_List,
4937 Make_Attribute_Reference (Loc,
4938 Prefix => New_Reference_To (Typ, Loc),
4939 Attribute_Name => Name_Alignment));
4940 end if;
4942 -- Expanded_Name
4944 Append_To (TSD_Aggr_List,
4945 Unchecked_Convert_To (RTE (RE_Cstring_Ptr),
4946 Make_Attribute_Reference (Loc,
4947 Prefix => New_Reference_To (Exname, Loc),
4948 Attribute_Name => Name_Address)));
4950 -- External_Tag of a local tagged type
4952 -- <typ>A : constant String :=
4953 -- "Internal tag at 16#tag-addr#: <full-name-of-typ>";
4955 -- The reason we generate this strange name is that we do not want to
4956 -- enter local tagged types in the global hash table used to compute
4957 -- the Internal_Tag attribute for two reasons:
4959 -- 1. It is hard to avoid a tasking race condition for entering the
4960 -- entry into the hash table.
4962 -- 2. It would cause a storage leak, unless we rig up considerable
4963 -- mechanism to remove the entry from the hash table on exit.
4965 -- So what we do is to generate the above external tag name, where the
4966 -- hex address is the address of the local dispatch table (i.e. exactly
4967 -- the value we want if Internal_Tag is computed from this string).
4969 -- Of course this value will only be valid if the tagged type is still
4970 -- in scope, but it clearly must be erroneous to compute the internal
4971 -- tag of a tagged type that is out of scope!
4973 -- We don't do this processing if an explicit external tag has been
4974 -- specified. That's an odd case for which we have already issued a
4975 -- warning, where we will not be able to compute the internal tag.
4977 if not Is_Library_Level_Entity (Typ)
4978 and then not Has_External_Tag_Rep_Clause (Typ)
4979 then
4980 declare
4981 Exname : constant Entity_Id :=
4982 Make_Defining_Identifier (Loc,
4983 New_External_Name (Tname, 'A'));
4985 Full_Name : constant String_Id :=
4986 Fully_Qualified_Name_String (First_Subtype (Typ));
4987 Str1_Id : String_Id;
4988 Str2_Id : String_Id;
4990 begin
4991 -- Generate:
4992 -- Str1 = "Internal tag at 16#";
4994 Start_String;
4995 Store_String_Chars ("Internal tag at 16#");
4996 Str1_Id := End_String;
4998 -- Generate:
4999 -- Str2 = "#: <type-full-name>";
5001 Start_String;
5002 Store_String_Chars ("#: ");
5003 Store_String_Chars (Full_Name);
5004 Str2_Id := End_String;
5006 -- Generate:
5007 -- Exname : constant String :=
5008 -- Str1 & Address_Image (Tag) & Str2;
5010 if RTE_Available (RE_Address_Image) then
5011 Append_To (Result,
5012 Make_Object_Declaration (Loc,
5013 Defining_Identifier => Exname,
5014 Constant_Present => True,
5015 Object_Definition => New_Reference_To
5016 (Standard_String, Loc),
5017 Expression =>
5018 Make_Op_Concat (Loc,
5019 Left_Opnd =>
5020 Make_String_Literal (Loc, Str1_Id),
5021 Right_Opnd =>
5022 Make_Op_Concat (Loc,
5023 Left_Opnd =>
5024 Make_Function_Call (Loc,
5025 Name =>
5026 New_Reference_To
5027 (RTE (RE_Address_Image), Loc),
5028 Parameter_Associations => New_List (
5029 Unchecked_Convert_To (RTE (RE_Address),
5030 New_Reference_To (DT_Ptr, Loc)))),
5031 Right_Opnd =>
5032 Make_String_Literal (Loc, Str2_Id)))));
5034 else
5035 Append_To (Result,
5036 Make_Object_Declaration (Loc,
5037 Defining_Identifier => Exname,
5038 Constant_Present => True,
5039 Object_Definition => New_Reference_To
5040 (Standard_String, Loc),
5041 Expression =>
5042 Make_Op_Concat (Loc,
5043 Left_Opnd =>
5044 Make_String_Literal (Loc, Str1_Id),
5045 Right_Opnd =>
5046 Make_String_Literal (Loc, Str2_Id))));
5047 end if;
5049 New_Node :=
5050 Unchecked_Convert_To (RTE (RE_Cstring_Ptr),
5051 Make_Attribute_Reference (Loc,
5052 Prefix => New_Reference_To (Exname, Loc),
5053 Attribute_Name => Name_Address));
5054 end;
5056 -- External tag of a library-level tagged type: Check for a definition
5057 -- of External_Tag. The clause is considered only if it applies to this
5058 -- specific tagged type, as opposed to one of its ancestors.
5059 -- If the type is an unconstrained type extension, we are building the
5060 -- dispatch table of its anonymous base type, so the external tag, if
5061 -- any was specified, must be retrieved from the first subtype. Go to
5062 -- the full view in case the clause is in the private part.
5064 else
5065 declare
5066 Def : constant Node_Id := Get_Attribute_Definition_Clause
5067 (Underlying_Type (First_Subtype (Typ)),
5068 Attribute_External_Tag);
5070 Old_Val : String_Id;
5071 New_Val : String_Id;
5072 E : Entity_Id;
5074 begin
5075 if not Present (Def)
5076 or else Entity (Name (Def)) /= First_Subtype (Typ)
5077 then
5078 New_Node :=
5079 Unchecked_Convert_To (RTE (RE_Cstring_Ptr),
5080 Make_Attribute_Reference (Loc,
5081 Prefix => New_Reference_To (Exname, Loc),
5082 Attribute_Name => Name_Address));
5083 else
5084 Old_Val := Strval (Expr_Value_S (Expression (Def)));
5086 -- For the rep clause "for <typ>'external_tag use y" generate:
5088 -- <typ>A : constant string := y;
5090 -- <typ>A'Address is used to set the External_Tag component
5091 -- of the TSD
5093 -- Create a new nul terminated string if it is not already
5095 if String_Length (Old_Val) > 0
5096 and then
5097 Get_String_Char (Old_Val, String_Length (Old_Val)) = 0
5098 then
5099 New_Val := Old_Val;
5100 else
5101 Start_String (Old_Val);
5102 Store_String_Char (Get_Char_Code (ASCII.NUL));
5103 New_Val := End_String;
5104 end if;
5106 E := Make_Defining_Identifier (Loc,
5107 New_External_Name (Chars (Typ), 'A'));
5109 Append_To (Result,
5110 Make_Object_Declaration (Loc,
5111 Defining_Identifier => E,
5112 Constant_Present => True,
5113 Object_Definition =>
5114 New_Reference_To (Standard_String, Loc),
5115 Expression =>
5116 Make_String_Literal (Loc, New_Val)));
5118 New_Node :=
5119 Unchecked_Convert_To (RTE (RE_Cstring_Ptr),
5120 Make_Attribute_Reference (Loc,
5121 Prefix => New_Reference_To (E, Loc),
5122 Attribute_Name => Name_Address));
5123 end if;
5124 end;
5125 end if;
5127 Append_To (TSD_Aggr_List, New_Node);
5129 -- HT_Link
5131 if RTE_Available (RE_Register_Tag) then
5132 Append_To (TSD_Aggr_List,
5133 Unchecked_Convert_To (RTE (RE_Tag_Ptr),
5134 Make_Attribute_Reference (Loc,
5135 Prefix => New_Reference_To (HT_Link, Loc),
5136 Attribute_Name => Name_Address)));
5137 else
5138 Append_To (TSD_Aggr_List,
5139 Unchecked_Convert_To (RTE (RE_Tag_Ptr),
5140 New_Reference_To (RTE (RE_Null_Address), Loc)));
5141 end if;
5143 -- Transportable: Set for types that can be used in remote calls
5144 -- with respect to E.4(18) legality rules.
5146 declare
5147 Transportable : Entity_Id;
5149 begin
5150 Transportable :=
5151 Boolean_Literals
5152 (Is_Pure (Typ)
5153 or else Is_Shared_Passive (Typ)
5154 or else
5155 ((Is_Remote_Types (Typ)
5156 or else Is_Remote_Call_Interface (Typ))
5157 and then Original_View_In_Visible_Part (Typ))
5158 or else not Comes_From_Source (Typ));
5160 Append_To (TSD_Aggr_List,
5161 New_Occurrence_Of (Transportable, Loc));
5162 end;
5164 -- Type_Is_Abstract (Ada 2012: AI05-0173). This functionality is
5165 -- not available in the HIE runtime.
5167 if RTE_Record_Component_Available (RE_Type_Is_Abstract) then
5168 declare
5169 Type_Is_Abstract : Entity_Id;
5171 begin
5172 Type_Is_Abstract :=
5173 Boolean_Literals (Is_Abstract_Type (Typ));
5175 Append_To (TSD_Aggr_List,
5176 New_Occurrence_Of (Type_Is_Abstract, Loc));
5177 end;
5178 end if;
5180 -- Needs_Finalization: Set if the type is controlled or has controlled
5181 -- components.
5183 declare
5184 Needs_Fin : Entity_Id;
5186 begin
5187 Needs_Fin := Boolean_Literals (Needs_Finalization (Typ));
5188 Append_To (TSD_Aggr_List, New_Occurrence_Of (Needs_Fin, Loc));
5189 end;
5191 -- Size_Func
5193 if RTE_Record_Component_Available (RE_Size_Func) then
5195 -- Initialize this field to Null_Address if we are not building
5196 -- static dispatch tables static or if the size function is not
5197 -- available. In the former case we cannot initialize this field
5198 -- until the function is frozen and registered in the dispatch
5199 -- table (see Register_Primitive).
5201 if not Building_Static_DT (Typ) or else not Has_DT (Typ) then
5202 Append_To (TSD_Aggr_List,
5203 Unchecked_Convert_To (RTE (RE_Size_Ptr),
5204 New_Reference_To (RTE (RE_Null_Address), Loc)));
5206 else
5207 declare
5208 Prim_Elmt : Elmt_Id;
5209 Prim : Entity_Id;
5210 Size_Comp : Node_Id;
5212 begin
5213 Prim_Elmt := First_Elmt (Primitive_Operations (Typ));
5214 while Present (Prim_Elmt) loop
5215 Prim := Node (Prim_Elmt);
5217 if Chars (Prim) = Name_uSize then
5218 Prim := Ultimate_Alias (Prim);
5220 if Is_Abstract_Subprogram (Prim) then
5221 Size_Comp :=
5222 Unchecked_Convert_To (RTE (RE_Size_Ptr),
5223 New_Reference_To (RTE (RE_Null_Address), Loc));
5224 else
5225 Size_Comp :=
5226 Unchecked_Convert_To (RTE (RE_Size_Ptr),
5227 Make_Attribute_Reference (Loc,
5228 Prefix => New_Reference_To (Prim, Loc),
5229 Attribute_Name => Name_Unrestricted_Access));
5230 end if;
5232 exit;
5233 end if;
5235 Next_Elmt (Prim_Elmt);
5236 end loop;
5238 pragma Assert (Present (Size_Comp));
5239 Append_To (TSD_Aggr_List, Size_Comp);
5240 end;
5241 end if;
5242 end if;
5244 -- Interfaces_Table (required for AI-405)
5246 if RTE_Record_Component_Available (RE_Interfaces_Table) then
5248 -- Count the number of interface types implemented by Typ
5250 Collect_Interfaces (Typ, Typ_Ifaces);
5252 AI := First_Elmt (Typ_Ifaces);
5253 while Present (AI) loop
5254 Num_Ifaces := Num_Ifaces + 1;
5255 Next_Elmt (AI);
5256 end loop;
5258 if Num_Ifaces = 0 then
5259 Iface_Table_Node := Make_Null (Loc);
5261 -- Generate the Interface_Table object
5263 else
5264 declare
5265 TSD_Ifaces_List : constant List_Id := New_List;
5266 Elmt : Elmt_Id;
5267 Sec_DT_Tag : Node_Id;
5269 begin
5270 AI := First_Elmt (Typ_Ifaces);
5271 while Present (AI) loop
5272 if Is_Ancestor (Node (AI), Typ, Use_Full_View => True) then
5273 Sec_DT_Tag :=
5274 New_Reference_To (DT_Ptr, Loc);
5275 else
5276 Elmt :=
5277 Next_Elmt
5278 (Next_Elmt (First_Elmt (Access_Disp_Table (Typ))));
5279 pragma Assert (Has_Thunks (Node (Elmt)));
5281 while Is_Tag (Node (Elmt))
5282 and then not
5283 Is_Ancestor (Node (AI), Related_Type (Node (Elmt)),
5284 Use_Full_View => True)
5285 loop
5286 pragma Assert (Has_Thunks (Node (Elmt)));
5287 Next_Elmt (Elmt);
5288 pragma Assert (Has_Thunks (Node (Elmt)));
5289 Next_Elmt (Elmt);
5290 pragma Assert (not Has_Thunks (Node (Elmt)));
5291 Next_Elmt (Elmt);
5292 pragma Assert (not Has_Thunks (Node (Elmt)));
5293 Next_Elmt (Elmt);
5294 end loop;
5296 pragma Assert (Ekind (Node (Elmt)) = E_Constant
5297 and then not
5298 Has_Thunks (Node (Next_Elmt (Next_Elmt (Elmt)))));
5299 Sec_DT_Tag :=
5300 New_Reference_To (Node (Next_Elmt (Next_Elmt (Elmt))),
5301 Loc);
5302 end if;
5304 Append_To (TSD_Ifaces_List,
5305 Make_Aggregate (Loc,
5306 Expressions => New_List (
5308 -- Iface_Tag
5310 Unchecked_Convert_To (RTE (RE_Tag),
5311 New_Reference_To
5312 (Node (First_Elmt (Access_Disp_Table (Node (AI)))),
5313 Loc)),
5315 -- Static_Offset_To_Top
5317 New_Reference_To (Standard_True, Loc),
5319 -- Offset_To_Top_Value
5321 Make_Integer_Literal (Loc, 0),
5323 -- Offset_To_Top_Func
5325 Make_Null (Loc),
5327 -- Secondary_DT
5329 Unchecked_Convert_To (RTE (RE_Tag), Sec_DT_Tag)
5331 )));
5333 Next_Elmt (AI);
5334 end loop;
5336 Name_ITable := New_External_Name (Tname, 'I');
5337 ITable := Make_Defining_Identifier (Loc, Name_ITable);
5338 Set_Is_Statically_Allocated (ITable,
5339 Is_Library_Level_Tagged_Type (Typ));
5341 -- The table of interfaces is not constant; its slots are
5342 -- filled at run time by the IP routine using attribute
5343 -- 'Position to know the location of the tag components
5344 -- (and this attribute cannot be safely used before the
5345 -- object is initialized).
5347 Append_To (Result,
5348 Make_Object_Declaration (Loc,
5349 Defining_Identifier => ITable,
5350 Aliased_Present => True,
5351 Constant_Present => False,
5352 Object_Definition =>
5353 Make_Subtype_Indication (Loc,
5354 Subtype_Mark =>
5355 New_Reference_To (RTE (RE_Interface_Data), Loc),
5356 Constraint => Make_Index_Or_Discriminant_Constraint
5357 (Loc,
5358 Constraints => New_List (
5359 Make_Integer_Literal (Loc, Num_Ifaces)))),
5361 Expression => Make_Aggregate (Loc,
5362 Expressions => New_List (
5363 Make_Integer_Literal (Loc, Num_Ifaces),
5364 Make_Aggregate (Loc,
5365 Expressions => TSD_Ifaces_List)))));
5367 Append_To (Result,
5368 Make_Attribute_Definition_Clause (Loc,
5369 Name => New_Reference_To (ITable, Loc),
5370 Chars => Name_Alignment,
5371 Expression =>
5372 Make_Attribute_Reference (Loc,
5373 Prefix =>
5374 New_Reference_To (RTE (RE_Integer_Address), Loc),
5375 Attribute_Name => Name_Alignment)));
5377 Iface_Table_Node :=
5378 Make_Attribute_Reference (Loc,
5379 Prefix => New_Reference_To (ITable, Loc),
5380 Attribute_Name => Name_Unchecked_Access);
5381 end;
5382 end if;
5384 Append_To (TSD_Aggr_List, Iface_Table_Node);
5385 end if;
5387 -- Generate the Select Specific Data table for synchronized types that
5388 -- implement synchronized interfaces. The size of the table is
5389 -- constrained by the number of non-predefined primitive operations.
5391 if RTE_Record_Component_Available (RE_SSD) then
5392 if Ada_Version >= Ada_2005
5393 and then Has_DT (Typ)
5394 and then Is_Concurrent_Record_Type (Typ)
5395 and then Has_Interfaces (Typ)
5396 and then Nb_Prim > 0
5397 and then not Is_Abstract_Type (Typ)
5398 and then not Is_Controlled (Typ)
5399 and then not Restriction_Active (No_Dispatching_Calls)
5400 and then not Restriction_Active (No_Select_Statements)
5401 then
5402 Append_To (Result,
5403 Make_Object_Declaration (Loc,
5404 Defining_Identifier => SSD,
5405 Aliased_Present => True,
5406 Object_Definition =>
5407 Make_Subtype_Indication (Loc,
5408 Subtype_Mark => New_Reference_To (
5409 RTE (RE_Select_Specific_Data), Loc),
5410 Constraint =>
5411 Make_Index_Or_Discriminant_Constraint (Loc,
5412 Constraints => New_List (
5413 Make_Integer_Literal (Loc, Nb_Prim))))));
5415 Append_To (Result,
5416 Make_Attribute_Definition_Clause (Loc,
5417 Name => New_Reference_To (SSD, Loc),
5418 Chars => Name_Alignment,
5419 Expression =>
5420 Make_Attribute_Reference (Loc,
5421 Prefix =>
5422 New_Reference_To (RTE (RE_Integer_Address), Loc),
5423 Attribute_Name => Name_Alignment)));
5425 -- This table is initialized by Make_Select_Specific_Data_Table,
5426 -- which calls Set_Entry_Index and Set_Prim_Op_Kind.
5428 Append_To (TSD_Aggr_List,
5429 Make_Attribute_Reference (Loc,
5430 Prefix => New_Reference_To (SSD, Loc),
5431 Attribute_Name => Name_Unchecked_Access));
5432 else
5433 Append_To (TSD_Aggr_List, Make_Null (Loc));
5434 end if;
5435 end if;
5437 -- Initialize the table of ancestor tags. In case of interface types
5438 -- this table is not needed.
5440 TSD_Tags_List := New_List;
5442 -- If we are not statically allocating the dispatch table then we must
5443 -- fill position 0 with null because we still have not generated the
5444 -- tag of Typ.
5446 if not Building_Static_DT (Typ)
5447 or else Is_Interface (Typ)
5448 then
5449 Append_To (TSD_Tags_List,
5450 Unchecked_Convert_To (RTE (RE_Tag),
5451 New_Reference_To (RTE (RE_Null_Address), Loc)));
5453 -- Otherwise we can safely reference the tag
5455 else
5456 Append_To (TSD_Tags_List,
5457 New_Reference_To (DT_Ptr, Loc));
5458 end if;
5460 -- Fill the rest of the table with the tags of the ancestors
5462 declare
5463 Current_Typ : Entity_Id;
5464 Parent_Typ : Entity_Id;
5465 Pos : Nat;
5467 begin
5468 Pos := 1;
5469 Current_Typ := Typ;
5471 loop
5472 Parent_Typ := Etype (Current_Typ);
5474 if Is_Private_Type (Parent_Typ) then
5475 Parent_Typ := Full_View (Base_Type (Parent_Typ));
5476 end if;
5478 exit when Parent_Typ = Current_Typ;
5480 if Is_CPP_Class (Parent_Typ) then
5482 -- The tags defined in the C++ side will be inherited when
5483 -- the object is constructed (Exp_Ch3.Build_Init_Procedure)
5485 Append_To (TSD_Tags_List,
5486 Unchecked_Convert_To (RTE (RE_Tag),
5487 New_Reference_To (RTE (RE_Null_Address), Loc)));
5488 else
5489 Append_To (TSD_Tags_List,
5490 New_Reference_To
5491 (Node (First_Elmt (Access_Disp_Table (Parent_Typ))),
5492 Loc));
5493 end if;
5495 Pos := Pos + 1;
5496 Current_Typ := Parent_Typ;
5497 end loop;
5499 pragma Assert (Pos = I_Depth + 1);
5500 end;
5502 Append_To (TSD_Aggr_List,
5503 Make_Aggregate (Loc,
5504 Expressions => TSD_Tags_List));
5506 -- Build the TSD object
5508 Append_To (Result,
5509 Make_Object_Declaration (Loc,
5510 Defining_Identifier => TSD,
5511 Aliased_Present => True,
5512 Constant_Present => Building_Static_DT (Typ),
5513 Object_Definition =>
5514 Make_Subtype_Indication (Loc,
5515 Subtype_Mark => New_Reference_To (
5516 RTE (RE_Type_Specific_Data), Loc),
5517 Constraint =>
5518 Make_Index_Or_Discriminant_Constraint (Loc,
5519 Constraints => New_List (
5520 Make_Integer_Literal (Loc, I_Depth)))),
5522 Expression => Make_Aggregate (Loc,
5523 Expressions => TSD_Aggr_List)));
5525 Set_Is_True_Constant (TSD, Building_Static_DT (Typ));
5527 Append_To (Result,
5528 Make_Attribute_Definition_Clause (Loc,
5529 Name => New_Reference_To (TSD, Loc),
5530 Chars => Name_Alignment,
5531 Expression =>
5532 Make_Attribute_Reference (Loc,
5533 Prefix => New_Reference_To (RTE (RE_Integer_Address), Loc),
5534 Attribute_Name => Name_Alignment)));
5536 -- Initialize or declare the dispatch table object
5538 if not Has_DT (Typ) then
5539 DT_Constr_List := New_List;
5540 DT_Aggr_List := New_List;
5542 -- Typeinfo
5544 New_Node :=
5545 Make_Attribute_Reference (Loc,
5546 Prefix => New_Reference_To (TSD, Loc),
5547 Attribute_Name => Name_Address);
5549 Append_To (DT_Constr_List, New_Node);
5550 Append_To (DT_Aggr_List, New_Copy (New_Node));
5551 Append_To (DT_Aggr_List, Make_Integer_Literal (Loc, 0));
5553 -- In case of locally defined tagged types we have already declared
5554 -- and uninitialized object for the dispatch table, which is now
5555 -- initialized by means of the following assignment:
5557 -- DT := (TSD'Address, 0);
5559 if not Building_Static_DT (Typ) then
5560 Append_To (Result,
5561 Make_Assignment_Statement (Loc,
5562 Name => New_Reference_To (DT, Loc),
5563 Expression => Make_Aggregate (Loc,
5564 Expressions => DT_Aggr_List)));
5566 -- In case of library level tagged types we declare and export now
5567 -- the constant object containing the dummy dispatch table. There
5568 -- is no need to declare the tag here because it has been previously
5569 -- declared by Make_Tags
5571 -- DT : aliased constant No_Dispatch_Table :=
5572 -- (NDT_TSD => TSD'Address;
5573 -- NDT_Prims_Ptr => 0);
5574 -- for DT'Alignment use Address'Alignment;
5576 else
5577 Append_To (Result,
5578 Make_Object_Declaration (Loc,
5579 Defining_Identifier => DT,
5580 Aliased_Present => True,
5581 Constant_Present => True,
5582 Object_Definition =>
5583 New_Reference_To (RTE (RE_No_Dispatch_Table_Wrapper), Loc),
5584 Expression => Make_Aggregate (Loc,
5585 Expressions => DT_Aggr_List)));
5587 Append_To (Result,
5588 Make_Attribute_Definition_Clause (Loc,
5589 Name => New_Reference_To (DT, Loc),
5590 Chars => Name_Alignment,
5591 Expression =>
5592 Make_Attribute_Reference (Loc,
5593 Prefix =>
5594 New_Reference_To (RTE (RE_Integer_Address), Loc),
5595 Attribute_Name => Name_Alignment)));
5597 Export_DT (Typ, DT);
5598 end if;
5600 -- Common case: Typ has a dispatch table
5602 -- Generate:
5604 -- Predef_Prims : Address_Array (1 .. Default_Prim_Ops_Count) :=
5605 -- (predef-prim-op-1'address,
5606 -- predef-prim-op-2'address,
5607 -- ...
5608 -- predef-prim-op-n'address);
5609 -- for Predef_Prims'Alignment use Address'Alignment
5611 -- DT : Dispatch_Table (Nb_Prims) :=
5612 -- (Signature => <sig-value>,
5613 -- Tag_Kind => <tag_kind-value>,
5614 -- Predef_Prims => Predef_Prims'First'Address,
5615 -- Offset_To_Top => 0,
5616 -- TSD => TSD'Address;
5617 -- Prims_Ptr => (prim-op-1'address,
5618 -- prim-op-2'address,
5619 -- ...
5620 -- prim-op-n'address));
5621 -- for DT'Alignment use Address'Alignment
5623 else
5624 declare
5625 Pos : Nat;
5627 begin
5628 if not Building_Static_DT (Typ) then
5629 Nb_Predef_Prims := Max_Predef_Prims;
5631 else
5632 Prim_Elmt := First_Elmt (Primitive_Operations (Typ));
5633 while Present (Prim_Elmt) loop
5634 Prim := Node (Prim_Elmt);
5636 if Is_Predefined_Dispatching_Operation (Prim)
5637 and then not Is_Abstract_Subprogram (Prim)
5638 then
5639 Pos := UI_To_Int (DT_Position (Prim));
5641 if Pos > Nb_Predef_Prims then
5642 Nb_Predef_Prims := Pos;
5643 end if;
5644 end if;
5646 Next_Elmt (Prim_Elmt);
5647 end loop;
5648 end if;
5650 declare
5651 Prim_Table : array
5652 (Nat range 1 .. Nb_Predef_Prims) of Entity_Id;
5653 Decl : Node_Id;
5654 E : Entity_Id;
5656 begin
5657 Prim_Ops_Aggr_List := New_List;
5659 Prim_Table := (others => Empty);
5661 if Building_Static_DT (Typ) then
5662 Prim_Elmt := First_Elmt (Primitive_Operations (Typ));
5663 while Present (Prim_Elmt) loop
5664 Prim := Node (Prim_Elmt);
5666 if Is_Predefined_Dispatching_Operation (Prim)
5667 and then not Is_Abstract_Subprogram (Prim)
5668 and then not Is_Eliminated (Prim)
5669 and then not Present (Prim_Table
5670 (UI_To_Int (DT_Position (Prim))))
5671 then
5672 E := Ultimate_Alias (Prim);
5673 pragma Assert (not Is_Abstract_Subprogram (E));
5674 Prim_Table (UI_To_Int (DT_Position (Prim))) := E;
5675 end if;
5677 Next_Elmt (Prim_Elmt);
5678 end loop;
5679 end if;
5681 for J in Prim_Table'Range loop
5682 if Present (Prim_Table (J)) then
5683 New_Node :=
5684 Unchecked_Convert_To (RTE (RE_Prim_Ptr),
5685 Make_Attribute_Reference (Loc,
5686 Prefix => New_Reference_To (Prim_Table (J), Loc),
5687 Attribute_Name => Name_Unrestricted_Access));
5688 else
5689 New_Node := Make_Null (Loc);
5690 end if;
5692 Append_To (Prim_Ops_Aggr_List, New_Node);
5693 end loop;
5695 New_Node :=
5696 Make_Aggregate (Loc,
5697 Expressions => Prim_Ops_Aggr_List);
5699 Decl :=
5700 Make_Subtype_Declaration (Loc,
5701 Defining_Identifier => Make_Temporary (Loc, 'S'),
5702 Subtype_Indication =>
5703 New_Reference_To (RTE (RE_Address_Array), Loc));
5705 Append_To (Result, Decl);
5707 Append_To (Result,
5708 Make_Object_Declaration (Loc,
5709 Defining_Identifier => Predef_Prims,
5710 Aliased_Present => True,
5711 Constant_Present => Building_Static_DT (Typ),
5712 Object_Definition => New_Reference_To
5713 (Defining_Identifier (Decl), Loc),
5714 Expression => New_Node));
5716 -- Remember aggregates initializing dispatch tables
5718 Append_Elmt (New_Node, DT_Aggr);
5720 Append_To (Result,
5721 Make_Attribute_Definition_Clause (Loc,
5722 Name => New_Reference_To (Predef_Prims, Loc),
5723 Chars => Name_Alignment,
5724 Expression =>
5725 Make_Attribute_Reference (Loc,
5726 Prefix =>
5727 New_Reference_To (RTE (RE_Integer_Address), Loc),
5728 Attribute_Name => Name_Alignment)));
5729 end;
5730 end;
5732 -- Stage 1: Initialize the discriminant and the record components
5734 DT_Constr_List := New_List;
5735 DT_Aggr_List := New_List;
5737 -- Num_Prims. If the tagged type has no primitives we add a dummy
5738 -- slot whose address will be the tag of this type.
5740 if Nb_Prim = 0 then
5741 New_Node := Make_Integer_Literal (Loc, 1);
5742 else
5743 New_Node := Make_Integer_Literal (Loc, Nb_Prim);
5744 end if;
5746 Append_To (DT_Constr_List, New_Node);
5747 Append_To (DT_Aggr_List, New_Copy (New_Node));
5749 -- Signature
5751 if RTE_Record_Component_Available (RE_Signature) then
5752 Append_To (DT_Aggr_List,
5753 New_Reference_To (RTE (RE_Primary_DT), Loc));
5754 end if;
5756 -- Tag_Kind
5758 if RTE_Record_Component_Available (RE_Tag_Kind) then
5759 Append_To (DT_Aggr_List, Tagged_Kind (Typ));
5760 end if;
5762 -- Predef_Prims
5764 Append_To (DT_Aggr_List,
5765 Make_Attribute_Reference (Loc,
5766 Prefix => New_Reference_To (Predef_Prims, Loc),
5767 Attribute_Name => Name_Address));
5769 -- Offset_To_Top
5771 Append_To (DT_Aggr_List, Make_Integer_Literal (Loc, 0));
5773 -- Typeinfo
5775 Append_To (DT_Aggr_List,
5776 Make_Attribute_Reference (Loc,
5777 Prefix => New_Reference_To (TSD, Loc),
5778 Attribute_Name => Name_Address));
5780 -- Stage 2: Initialize the table of user-defined primitive operations
5782 Prim_Ops_Aggr_List := New_List;
5784 if Nb_Prim = 0 then
5785 Append_To (Prim_Ops_Aggr_List, Make_Null (Loc));
5787 elsif not Building_Static_DT (Typ) then
5788 for J in 1 .. Nb_Prim loop
5789 Append_To (Prim_Ops_Aggr_List, Make_Null (Loc));
5790 end loop;
5792 else
5793 declare
5794 CPP_Nb_Prims : constant Nat := CPP_Num_Prims (Typ);
5795 E : Entity_Id;
5796 Prim : Entity_Id;
5797 Prim_Elmt : Elmt_Id;
5798 Prim_Pos : Nat;
5799 Prim_Table : array (Nat range 1 .. Nb_Prim) of Entity_Id;
5801 begin
5802 Prim_Table := (others => Empty);
5804 Prim_Elmt := First_Elmt (Primitive_Operations (Typ));
5805 while Present (Prim_Elmt) loop
5806 Prim := Node (Prim_Elmt);
5808 -- Retrieve the ultimate alias of the primitive for proper
5809 -- handling of renamings and eliminated primitives.
5811 E := Ultimate_Alias (Prim);
5812 Prim_Pos := UI_To_Int (DT_Position (E));
5814 -- Do not reference predefined primitives because they are
5815 -- located in a separate dispatch table; skip entities with
5816 -- attribute Interface_Alias because they are only required
5817 -- to build secondary dispatch tables; skip abstract and
5818 -- eliminated primitives; for derivations of CPP types skip
5819 -- primitives located in the C++ part of the dispatch table
5820 -- because their slot is initialized by the IC routine.
5822 if not Is_Predefined_Dispatching_Operation (Prim)
5823 and then not Is_Predefined_Dispatching_Operation (E)
5824 and then not Present (Interface_Alias (Prim))
5825 and then not Is_Abstract_Subprogram (E)
5826 and then not Is_Eliminated (E)
5827 and then (not Is_CPP_Class (Root_Type (Typ))
5828 or else Prim_Pos > CPP_Nb_Prims)
5829 then
5830 pragma Assert
5831 (UI_To_Int (DT_Position (Prim)) <= Nb_Prim);
5833 Prim_Table (UI_To_Int (DT_Position (Prim))) := E;
5834 end if;
5836 Next_Elmt (Prim_Elmt);
5837 end loop;
5839 for J in Prim_Table'Range loop
5840 if Present (Prim_Table (J)) then
5841 New_Node :=
5842 Unchecked_Convert_To (RTE (RE_Prim_Ptr),
5843 Make_Attribute_Reference (Loc,
5844 Prefix => New_Reference_To (Prim_Table (J), Loc),
5845 Attribute_Name => Name_Unrestricted_Access));
5846 else
5847 New_Node := Make_Null (Loc);
5848 end if;
5850 Append_To (Prim_Ops_Aggr_List, New_Node);
5851 end loop;
5852 end;
5853 end if;
5855 New_Node :=
5856 Make_Aggregate (Loc,
5857 Expressions => Prim_Ops_Aggr_List);
5859 Append_To (DT_Aggr_List, New_Node);
5861 -- Remember aggregates initializing dispatch tables
5863 Append_Elmt (New_Node, DT_Aggr);
5865 -- In case of locally defined tagged types we have already declared
5866 -- and uninitialized object for the dispatch table, which is now
5867 -- initialized by means of an assignment.
5869 if not Building_Static_DT (Typ) then
5870 Append_To (Result,
5871 Make_Assignment_Statement (Loc,
5872 Name => New_Reference_To (DT, Loc),
5873 Expression => Make_Aggregate (Loc,
5874 Expressions => DT_Aggr_List)));
5876 -- In case of library level tagged types we declare now and export
5877 -- the constant object containing the dispatch table.
5879 else
5880 Append_To (Result,
5881 Make_Object_Declaration (Loc,
5882 Defining_Identifier => DT,
5883 Aliased_Present => True,
5884 Constant_Present => True,
5885 Object_Definition =>
5886 Make_Subtype_Indication (Loc,
5887 Subtype_Mark => New_Reference_To
5888 (RTE (RE_Dispatch_Table_Wrapper), Loc),
5889 Constraint => Make_Index_Or_Discriminant_Constraint (Loc,
5890 Constraints => DT_Constr_List)),
5891 Expression => Make_Aggregate (Loc,
5892 Expressions => DT_Aggr_List)));
5894 Append_To (Result,
5895 Make_Attribute_Definition_Clause (Loc,
5896 Name => New_Reference_To (DT, Loc),
5897 Chars => Name_Alignment,
5898 Expression =>
5899 Make_Attribute_Reference (Loc,
5900 Prefix =>
5901 New_Reference_To (RTE (RE_Integer_Address), Loc),
5902 Attribute_Name => Name_Alignment)));
5904 Export_DT (Typ, DT);
5905 end if;
5906 end if;
5908 -- Initialize the table of ancestor tags if not building static
5909 -- dispatch table
5911 if not Building_Static_DT (Typ)
5912 and then not Is_Interface (Typ)
5913 and then not Is_CPP_Class (Typ)
5914 then
5915 Append_To (Result,
5916 Make_Assignment_Statement (Loc,
5917 Name =>
5918 Make_Indexed_Component (Loc,
5919 Prefix =>
5920 Make_Selected_Component (Loc,
5921 Prefix =>
5922 New_Reference_To (TSD, Loc),
5923 Selector_Name =>
5924 New_Reference_To
5925 (RTE_Record_Component (RE_Tags_Table), Loc)),
5926 Expressions =>
5927 New_List (Make_Integer_Literal (Loc, 0))),
5929 Expression =>
5930 New_Reference_To
5931 (Node (First_Elmt (Access_Disp_Table (Typ))), Loc)));
5932 end if;
5934 -- Inherit the dispatch tables of the parent. There is no need to
5935 -- inherit anything from the parent when building static dispatch tables
5936 -- because the whole dispatch table (including inherited primitives) has
5937 -- been already built.
5939 if Building_Static_DT (Typ) then
5940 null;
5942 -- If the ancestor is a CPP_Class type we inherit the dispatch tables
5943 -- in the init proc, and we don't need to fill them in here.
5945 elsif Is_CPP_Class (Parent_Typ) then
5946 null;
5948 -- Otherwise we fill in the dispatch tables here
5950 else
5951 if Typ /= Parent_Typ
5952 and then not Is_Interface (Typ)
5953 and then not Restriction_Active (No_Dispatching_Calls)
5954 then
5955 -- Inherit the dispatch table
5957 if not Is_Interface (Typ)
5958 and then not Is_Interface (Parent_Typ)
5959 and then not Is_CPP_Class (Parent_Typ)
5960 then
5961 declare
5962 Nb_Prims : constant Int :=
5963 UI_To_Int (DT_Entry_Count
5964 (First_Tag_Component (Parent_Typ)));
5966 begin
5967 Append_To (Elab_Code,
5968 Build_Inherit_Predefined_Prims (Loc,
5969 Old_Tag_Node =>
5970 New_Reference_To
5971 (Node
5972 (Next_Elmt
5973 (First_Elmt
5974 (Access_Disp_Table (Parent_Typ)))), Loc),
5975 New_Tag_Node =>
5976 New_Reference_To
5977 (Node
5978 (Next_Elmt
5979 (First_Elmt
5980 (Access_Disp_Table (Typ)))), Loc)));
5982 if Nb_Prims /= 0 then
5983 Append_To (Elab_Code,
5984 Build_Inherit_Prims (Loc,
5985 Typ => Typ,
5986 Old_Tag_Node =>
5987 New_Reference_To
5988 (Node
5989 (First_Elmt
5990 (Access_Disp_Table (Parent_Typ))), Loc),
5991 New_Tag_Node => New_Reference_To (DT_Ptr, Loc),
5992 Num_Prims => Nb_Prims));
5993 end if;
5994 end;
5995 end if;
5997 -- Inherit the secondary dispatch tables of the ancestor
5999 if not Is_CPP_Class (Parent_Typ) then
6000 declare
6001 Sec_DT_Ancestor : Elmt_Id :=
6002 Next_Elmt
6003 (Next_Elmt
6004 (First_Elmt
6005 (Access_Disp_Table (Parent_Typ))));
6006 Sec_DT_Typ : Elmt_Id :=
6007 Next_Elmt
6008 (Next_Elmt
6009 (First_Elmt
6010 (Access_Disp_Table (Typ))));
6012 procedure Copy_Secondary_DTs (Typ : Entity_Id);
6013 -- Local procedure required to climb through the ancestors
6014 -- and copy the contents of all their secondary dispatch
6015 -- tables.
6017 ------------------------
6018 -- Copy_Secondary_DTs --
6019 ------------------------
6021 procedure Copy_Secondary_DTs (Typ : Entity_Id) is
6022 E : Entity_Id;
6023 Iface : Elmt_Id;
6025 begin
6026 -- Climb to the ancestor (if any) handling private types
6028 if Present (Full_View (Etype (Typ))) then
6029 if Full_View (Etype (Typ)) /= Typ then
6030 Copy_Secondary_DTs (Full_View (Etype (Typ)));
6031 end if;
6033 elsif Etype (Typ) /= Typ then
6034 Copy_Secondary_DTs (Etype (Typ));
6035 end if;
6037 if Present (Interfaces (Typ))
6038 and then not Is_Empty_Elmt_List (Interfaces (Typ))
6039 then
6040 Iface := First_Elmt (Interfaces (Typ));
6041 E := First_Entity (Typ);
6042 while Present (E)
6043 and then Present (Node (Sec_DT_Ancestor))
6044 and then Ekind (Node (Sec_DT_Ancestor)) = E_Constant
6045 loop
6046 if Is_Tag (E) and then Chars (E) /= Name_uTag then
6047 declare
6048 Num_Prims : constant Int :=
6049 UI_To_Int (DT_Entry_Count (E));
6051 begin
6052 if not Is_Interface (Etype (Typ)) then
6054 -- Inherit first secondary dispatch table
6056 Append_To (Elab_Code,
6057 Build_Inherit_Predefined_Prims (Loc,
6058 Old_Tag_Node =>
6059 Unchecked_Convert_To (RTE (RE_Tag),
6060 New_Reference_To
6061 (Node
6062 (Next_Elmt (Sec_DT_Ancestor)),
6063 Loc)),
6064 New_Tag_Node =>
6065 Unchecked_Convert_To (RTE (RE_Tag),
6066 New_Reference_To
6067 (Node (Next_Elmt (Sec_DT_Typ)),
6068 Loc))));
6070 if Num_Prims /= 0 then
6071 Append_To (Elab_Code,
6072 Build_Inherit_Prims (Loc,
6073 Typ => Node (Iface),
6074 Old_Tag_Node =>
6075 Unchecked_Convert_To
6076 (RTE (RE_Tag),
6077 New_Reference_To
6078 (Node (Sec_DT_Ancestor),
6079 Loc)),
6080 New_Tag_Node =>
6081 Unchecked_Convert_To
6082 (RTE (RE_Tag),
6083 New_Reference_To
6084 (Node (Sec_DT_Typ), Loc)),
6085 Num_Prims => Num_Prims));
6086 end if;
6087 end if;
6089 Next_Elmt (Sec_DT_Ancestor);
6090 Next_Elmt (Sec_DT_Typ);
6092 -- Skip the secondary dispatch table of
6093 -- predefined primitives
6095 Next_Elmt (Sec_DT_Ancestor);
6096 Next_Elmt (Sec_DT_Typ);
6098 if not Is_Interface (Etype (Typ)) then
6100 -- Inherit second secondary dispatch table
6102 Append_To (Elab_Code,
6103 Build_Inherit_Predefined_Prims (Loc,
6104 Old_Tag_Node =>
6105 Unchecked_Convert_To (RTE (RE_Tag),
6106 New_Reference_To
6107 (Node
6108 (Next_Elmt (Sec_DT_Ancestor)),
6109 Loc)),
6110 New_Tag_Node =>
6111 Unchecked_Convert_To (RTE (RE_Tag),
6112 New_Reference_To
6113 (Node (Next_Elmt (Sec_DT_Typ)),
6114 Loc))));
6116 if Num_Prims /= 0 then
6117 Append_To (Elab_Code,
6118 Build_Inherit_Prims (Loc,
6119 Typ => Node (Iface),
6120 Old_Tag_Node =>
6121 Unchecked_Convert_To
6122 (RTE (RE_Tag),
6123 New_Reference_To
6124 (Node (Sec_DT_Ancestor),
6125 Loc)),
6126 New_Tag_Node =>
6127 Unchecked_Convert_To
6128 (RTE (RE_Tag),
6129 New_Reference_To
6130 (Node (Sec_DT_Typ), Loc)),
6131 Num_Prims => Num_Prims));
6132 end if;
6133 end if;
6134 end;
6136 Next_Elmt (Sec_DT_Ancestor);
6137 Next_Elmt (Sec_DT_Typ);
6139 -- Skip the secondary dispatch table of
6140 -- predefined primitives
6142 Next_Elmt (Sec_DT_Ancestor);
6143 Next_Elmt (Sec_DT_Typ);
6145 Next_Elmt (Iface);
6146 end if;
6148 Next_Entity (E);
6149 end loop;
6150 end if;
6151 end Copy_Secondary_DTs;
6153 begin
6154 if Present (Node (Sec_DT_Ancestor))
6155 and then Ekind (Node (Sec_DT_Ancestor)) = E_Constant
6156 then
6157 -- Handle private types
6159 if Present (Full_View (Typ)) then
6160 Copy_Secondary_DTs (Full_View (Typ));
6161 else
6162 Copy_Secondary_DTs (Typ);
6163 end if;
6164 end if;
6165 end;
6166 end if;
6167 end if;
6168 end if;
6170 -- If the type has a representation clause which specifies its external
6171 -- tag then generate code to check if the external tag of this type is
6172 -- the same as the external tag of some other declaration.
6174 -- Check_TSD (TSD'Unrestricted_Access);
6176 -- This check is a consequence of AI05-0113-1/06, so it officially
6177 -- applies to Ada 2005 (and Ada 2012). It might be argued that it is
6178 -- a desirable check to add in Ada 95 mode, but we hesitate to make
6179 -- this change, as it would be incompatible, and could conceivably
6180 -- cause a problem in existing Aa 95 code.
6182 -- We check for No_Run_Time_Mode here, because we do not want to pick
6183 -- up the RE_Check_TSD entity and call it in No_Run_Time mode.
6185 if not No_Run_Time_Mode
6186 and then Ada_Version >= Ada_2005
6187 and then Has_External_Tag_Rep_Clause (Typ)
6188 and then RTE_Available (RE_Check_TSD)
6189 and then not Debug_Flag_QQ
6190 then
6191 Append_To (Elab_Code,
6192 Make_Procedure_Call_Statement (Loc,
6193 Name => New_Reference_To (RTE (RE_Check_TSD), Loc),
6194 Parameter_Associations => New_List (
6195 Make_Attribute_Reference (Loc,
6196 Prefix => New_Reference_To (TSD, Loc),
6197 Attribute_Name => Name_Unchecked_Access))));
6198 end if;
6200 -- Generate code to register the Tag in the External_Tag hash table for
6201 -- the pure Ada type only.
6203 -- Register_Tag (Dt_Ptr);
6205 -- Skip this action in the following cases:
6206 -- 1) if Register_Tag is not available.
6207 -- 2) in No_Run_Time mode.
6208 -- 3) if Typ is not defined at the library level (this is required
6209 -- to avoid adding concurrency control to the hash table used
6210 -- by the run-time to register the tags).
6212 if not No_Run_Time_Mode
6213 and then Is_Library_Level_Entity (Typ)
6214 and then RTE_Available (RE_Register_Tag)
6215 then
6216 Append_To (Elab_Code,
6217 Make_Procedure_Call_Statement (Loc,
6218 Name => New_Reference_To (RTE (RE_Register_Tag), Loc),
6219 Parameter_Associations =>
6220 New_List (New_Reference_To (DT_Ptr, Loc))));
6221 end if;
6223 if not Is_Empty_List (Elab_Code) then
6224 Append_List_To (Result, Elab_Code);
6225 end if;
6227 -- Populate the two auxiliary tables used for dispatching asynchronous,
6228 -- conditional and timed selects for synchronized types that implement
6229 -- a limited interface. Skip this step in Ravenscar profile or when
6230 -- general dispatching is forbidden.
6232 if Ada_Version >= Ada_2005
6233 and then Is_Concurrent_Record_Type (Typ)
6234 and then Has_Interfaces (Typ)
6235 and then not Restriction_Active (No_Dispatching_Calls)
6236 and then not Restriction_Active (No_Select_Statements)
6237 then
6238 Append_List_To (Result,
6239 Make_Select_Specific_Data_Table (Typ));
6240 end if;
6242 -- Remember entities containing dispatch tables
6244 Append_Elmt (Predef_Prims, DT_Decl);
6245 Append_Elmt (DT, DT_Decl);
6247 Analyze_List (Result, Suppress => All_Checks);
6248 Set_Has_Dispatch_Table (Typ);
6250 -- Mark entities containing dispatch tables. Required by the backend to
6251 -- handle them properly.
6253 if Has_DT (Typ) then
6254 declare
6255 Elmt : Elmt_Id;
6257 begin
6258 -- Object declarations
6260 Elmt := First_Elmt (DT_Decl);
6261 while Present (Elmt) loop
6262 Set_Is_Dispatch_Table_Entity (Node (Elmt));
6263 pragma Assert (Ekind (Etype (Node (Elmt))) = E_Array_Subtype
6264 or else Ekind (Etype (Node (Elmt))) = E_Record_Subtype);
6265 Set_Is_Dispatch_Table_Entity (Etype (Node (Elmt)));
6266 Next_Elmt (Elmt);
6267 end loop;
6269 -- Aggregates initializing dispatch tables
6271 Elmt := First_Elmt (DT_Aggr);
6272 while Present (Elmt) loop
6273 Set_Is_Dispatch_Table_Entity (Etype (Node (Elmt)));
6274 Next_Elmt (Elmt);
6275 end loop;
6276 end;
6277 end if;
6279 -- Register the tagged type in the call graph nodes table
6281 Register_CG_Node (Typ);
6283 return Result;
6284 end Make_DT;
6286 -----------------
6287 -- Make_VM_TSD --
6288 -----------------
6290 function Make_VM_TSD (Typ : Entity_Id) return List_Id is
6291 Loc : constant Source_Ptr := Sloc (Typ);
6292 Result : constant List_Id := New_List;
6294 function Count_Primitives (Typ : Entity_Id) return Nat;
6295 -- Count the non-predefined primitive operations of Typ
6297 ----------------------
6298 -- Count_Primitives --
6299 ----------------------
6301 function Count_Primitives (Typ : Entity_Id) return Nat is
6302 Nb_Prim : Nat;
6303 Prim_Elmt : Elmt_Id;
6304 Prim : Entity_Id;
6306 begin
6307 Nb_Prim := 0;
6309 Prim_Elmt := First_Elmt (Primitive_Operations (Typ));
6310 while Present (Prim_Elmt) loop
6311 Prim := Node (Prim_Elmt);
6313 if Is_Predefined_Dispatching_Operation (Prim)
6314 or else Is_Predefined_Dispatching_Alias (Prim)
6315 then
6316 null;
6318 elsif Present (Interface_Alias (Prim)) then
6319 null;
6321 else
6322 Nb_Prim := Nb_Prim + 1;
6323 end if;
6325 Next_Elmt (Prim_Elmt);
6326 end loop;
6328 return Nb_Prim;
6329 end Count_Primitives;
6331 --------------
6332 -- Make_OSD --
6333 --------------
6335 function Make_OSD (Iface : Entity_Id) return Node_Id;
6336 -- Generate the Object Specific Data table required to dispatch calls
6337 -- through synchronized interfaces. Returns a node that references the
6338 -- generated OSD object.
6340 function Make_OSD (Iface : Entity_Id) return Node_Id is
6341 Nb_Prim : constant Nat := Count_Primitives (Iface);
6342 OSD : Entity_Id;
6343 OSD_Aggr_List : List_Id;
6345 begin
6346 -- Generate
6347 -- OSD : Ada.Tags.Object_Specific_Data (Nb_Prims) :=
6348 -- (OSD_Table => (1 => <value>,
6349 -- ...
6350 -- N => <value>));
6352 if Nb_Prim = 0
6353 or else Is_Abstract_Type (Typ)
6354 or else Is_Controlled (Typ)
6355 or else Restriction_Active (No_Dispatching_Calls)
6356 or else not Is_Limited_Type (Typ)
6357 or else not Has_Interfaces (Typ)
6358 or else not RTE_Record_Component_Available (RE_OSD_Table)
6359 then
6360 -- No OSD table required
6362 return Make_Null (Loc);
6364 else
6365 OSD_Aggr_List := New_List;
6367 declare
6368 Prim_Table : array (Nat range 1 .. Nb_Prim) of Entity_Id;
6369 Prim : Entity_Id;
6370 Prim_Alias : Entity_Id;
6371 Prim_Elmt : Elmt_Id;
6372 E : Entity_Id;
6373 Count : Nat := 0;
6374 Pos : Nat;
6376 begin
6377 Prim_Table := (others => Empty);
6378 Prim_Alias := Empty;
6380 Prim_Elmt := First_Elmt (Primitive_Operations (Typ));
6381 while Present (Prim_Elmt) loop
6382 Prim := Node (Prim_Elmt);
6384 if Present (Interface_Alias (Prim))
6385 and then Find_Dispatching_Type
6386 (Interface_Alias (Prim)) = Iface
6387 then
6388 Prim_Alias := Interface_Alias (Prim);
6389 E := Ultimate_Alias (Prim);
6390 Pos := UI_To_Int (DT_Position (Prim_Alias));
6392 if Present (Prim_Table (Pos)) then
6393 pragma Assert (Prim_Table (Pos) = E);
6394 null;
6396 else
6397 Prim_Table (Pos) := E;
6399 Append_To (OSD_Aggr_List,
6400 Make_Component_Association (Loc,
6401 Choices => New_List (
6402 Make_Integer_Literal (Loc,
6403 DT_Position (Prim_Alias))),
6404 Expression =>
6405 Make_Integer_Literal (Loc,
6406 DT_Position (Alias (Prim)))));
6408 Count := Count + 1;
6409 end if;
6410 end if;
6412 Next_Elmt (Prim_Elmt);
6413 end loop;
6414 pragma Assert (Count = Nb_Prim);
6415 end;
6417 OSD := Make_Temporary (Loc, 'I');
6419 Append_To (Result,
6420 Make_Object_Declaration (Loc,
6421 Defining_Identifier => OSD,
6422 Aliased_Present => True,
6423 Constant_Present => True,
6424 Object_Definition =>
6425 Make_Subtype_Indication (Loc,
6426 Subtype_Mark =>
6427 New_Reference_To (RTE (RE_Object_Specific_Data), Loc),
6428 Constraint =>
6429 Make_Index_Or_Discriminant_Constraint (Loc,
6430 Constraints => New_List (
6431 Make_Integer_Literal (Loc, Nb_Prim)))),
6433 Expression =>
6434 Make_Aggregate (Loc,
6435 Component_Associations => New_List (
6436 Make_Component_Association (Loc,
6437 Choices => New_List (
6438 New_Occurrence_Of
6439 (RTE_Record_Component (RE_OSD_Num_Prims), Loc)),
6440 Expression =>
6441 Make_Integer_Literal (Loc, Nb_Prim)),
6443 Make_Component_Association (Loc,
6444 Choices => New_List (
6445 New_Occurrence_Of
6446 (RTE_Record_Component (RE_OSD_Table), Loc)),
6447 Expression => Make_Aggregate (Loc,
6448 Component_Associations => OSD_Aggr_List))))));
6450 return
6451 Make_Attribute_Reference (Loc,
6452 Prefix => New_Reference_To (OSD, Loc),
6453 Attribute_Name => Name_Unchecked_Access);
6454 end if;
6455 end Make_OSD;
6457 -- Local variables
6459 Nb_Prim : constant Nat := Count_Primitives (Typ);
6460 AI : Elmt_Id;
6461 I_Depth : Nat;
6462 Iface_Table_Node : Node_Id;
6463 Num_Ifaces : Nat;
6464 TSD_Aggr_List : List_Id;
6465 Typ_Ifaces : Elist_Id;
6466 TSD_Tags_List : List_Id;
6468 Tname : constant Name_Id := Chars (Typ);
6469 Name_SSD : constant Name_Id :=
6470 New_External_Name (Tname, 'S', Suffix_Index => -1);
6471 Name_TSD : constant Name_Id :=
6472 New_External_Name (Tname, 'B', Suffix_Index => -1);
6473 SSD : constant Entity_Id :=
6474 Make_Defining_Identifier (Loc, Name_SSD);
6475 TSD : constant Entity_Id :=
6476 Make_Defining_Identifier (Loc, Name_TSD);
6477 begin
6478 -- Generate code to create the storage for the type specific data object
6479 -- with enough space to store the tags of the ancestors plus the tags
6480 -- of all the implemented interfaces (as described in a-tags.ads).
6482 -- TSD : Type_Specific_Data (I_Depth) :=
6483 -- (Idepth => I_Depth,
6484 -- Tag_Kind => <tag_kind-value>,
6485 -- Access_Level => Type_Access_Level (Typ),
6486 -- Alignment => Typ'Alignment,
6487 -- HT_Link => null,
6488 -- Type_Is_Abstract => <<boolean-value>>,
6489 -- Type_Is_Library_Level => <<boolean-value>>,
6490 -- Interfaces_Table => <<access-value>>
6491 -- SSD => SSD_Table'Address
6492 -- Tags_Table => (0 => Typ'Tag,
6493 -- 1 => Parent'Tag
6494 -- ...));
6496 TSD_Aggr_List := New_List;
6498 -- Idepth: Count ancestors to compute the inheritance depth. For private
6499 -- extensions, always go to the full view in order to compute the real
6500 -- inheritance depth.
6502 declare
6503 Current_Typ : Entity_Id;
6504 Parent_Typ : Entity_Id;
6506 begin
6507 I_Depth := 0;
6508 Current_Typ := Typ;
6509 loop
6510 Parent_Typ := Etype (Current_Typ);
6512 if Is_Private_Type (Parent_Typ) then
6513 Parent_Typ := Full_View (Base_Type (Parent_Typ));
6514 end if;
6516 exit when Parent_Typ = Current_Typ;
6518 I_Depth := I_Depth + 1;
6519 Current_Typ := Parent_Typ;
6520 end loop;
6521 end;
6523 -- I_Depth
6525 Append_To (TSD_Aggr_List,
6526 Make_Integer_Literal (Loc, I_Depth));
6528 -- Tag_Kind
6530 Append_To (TSD_Aggr_List, Tagged_Kind (Typ));
6532 -- Access_Level
6534 Append_To (TSD_Aggr_List,
6535 Make_Integer_Literal (Loc, Type_Access_Level (Typ)));
6537 -- Alignment
6539 -- For CPP types we cannot rely on the value of 'Alignment provided
6540 -- by the backend to initialize this TSD field. Why not???
6542 if Convention (Typ) = Convention_CPP
6543 or else Is_CPP_Class (Root_Type (Typ))
6544 then
6545 Append_To (TSD_Aggr_List,
6546 Make_Integer_Literal (Loc, 0));
6547 else
6548 Append_To (TSD_Aggr_List,
6549 Make_Attribute_Reference (Loc,
6550 Prefix => New_Reference_To (Typ, Loc),
6551 Attribute_Name => Name_Alignment));
6552 end if;
6554 -- HT_Link
6556 Append_To (TSD_Aggr_List,
6557 Make_Null (Loc));
6559 -- Type_Is_Abstract (Ada 2012: AI05-0173)
6561 declare
6562 Type_Is_Abstract : Entity_Id;
6564 begin
6565 Type_Is_Abstract :=
6566 Boolean_Literals (Is_Abstract_Type (Typ));
6568 Append_To (TSD_Aggr_List,
6569 New_Occurrence_Of (Type_Is_Abstract, Loc));
6570 end;
6572 -- Type_Is_Library_Level
6574 declare
6575 Type_Is_Library_Level : Entity_Id;
6576 begin
6577 Type_Is_Library_Level :=
6578 Boolean_Literals (Is_Library_Level_Entity (Typ));
6579 Append_To (TSD_Aggr_List,
6580 New_Occurrence_Of (Type_Is_Library_Level, Loc));
6581 end;
6583 -- Interfaces_Table (required for AI-405)
6585 if RTE_Record_Component_Available (RE_Interfaces_Table) then
6587 -- Count the number of interface types implemented by Typ
6589 Collect_Interfaces (Typ, Typ_Ifaces);
6591 Num_Ifaces := 0;
6592 AI := First_Elmt (Typ_Ifaces);
6593 while Present (AI) loop
6594 Num_Ifaces := Num_Ifaces + 1;
6595 Next_Elmt (AI);
6596 end loop;
6598 if Num_Ifaces = 0 then
6599 Iface_Table_Node := Make_Null (Loc);
6601 -- Generate the Interface_Table object
6603 else
6604 declare
6605 TSD_Ifaces_List : constant List_Id := New_List;
6606 Iface : Entity_Id;
6607 ITable : Node_Id;
6609 begin
6610 AI := First_Elmt (Typ_Ifaces);
6611 while Present (AI) loop
6612 Iface := Node (AI);
6614 Append_To (TSD_Ifaces_List,
6615 Make_Aggregate (Loc,
6616 Expressions => New_List (
6618 -- Iface_Tag
6620 Make_Attribute_Reference (Loc,
6621 Prefix => New_Reference_To (Iface, Loc),
6622 Attribute_Name => Name_Tag),
6624 -- OSD
6626 Make_OSD (Iface))));
6628 Next_Elmt (AI);
6629 end loop;
6631 ITable := Make_Temporary (Loc, 'I');
6633 Append_To (Result,
6634 Make_Object_Declaration (Loc,
6635 Defining_Identifier => ITable,
6636 Aliased_Present => True,
6637 Constant_Present => True,
6638 Object_Definition =>
6639 Make_Subtype_Indication (Loc,
6640 Subtype_Mark =>
6641 New_Reference_To (RTE (RE_Interface_Data), Loc),
6642 Constraint => Make_Index_Or_Discriminant_Constraint
6643 (Loc,
6644 Constraints => New_List (
6645 Make_Integer_Literal (Loc, Num_Ifaces)))),
6647 Expression => Make_Aggregate (Loc,
6648 Expressions => New_List (
6649 Make_Integer_Literal (Loc, Num_Ifaces),
6650 Make_Aggregate (Loc,
6651 Expressions => TSD_Ifaces_List)))));
6653 Iface_Table_Node :=
6654 Make_Attribute_Reference (Loc,
6655 Prefix => New_Reference_To (ITable, Loc),
6656 Attribute_Name => Name_Unchecked_Access);
6657 end;
6658 end if;
6660 Append_To (TSD_Aggr_List, Iface_Table_Node);
6661 end if;
6663 -- Generate the Select Specific Data table for synchronized types that
6664 -- implement synchronized interfaces. The size of the table is
6665 -- constrained by the number of non-predefined primitive operations.
6667 if RTE_Record_Component_Available (RE_SSD) then
6668 if Ada_Version >= Ada_2005
6669 and then Has_DT (Typ)
6670 and then Is_Concurrent_Record_Type (Typ)
6671 and then Has_Interfaces (Typ)
6672 and then Nb_Prim > 0
6673 and then not Is_Abstract_Type (Typ)
6674 and then not Is_Controlled (Typ)
6675 and then not Restriction_Active (No_Dispatching_Calls)
6676 and then not Restriction_Active (No_Select_Statements)
6677 then
6678 Append_To (Result,
6679 Make_Object_Declaration (Loc,
6680 Defining_Identifier => SSD,
6681 Aliased_Present => True,
6682 Object_Definition =>
6683 Make_Subtype_Indication (Loc,
6684 Subtype_Mark => New_Reference_To (
6685 RTE (RE_Select_Specific_Data), Loc),
6686 Constraint =>
6687 Make_Index_Or_Discriminant_Constraint (Loc,
6688 Constraints => New_List (
6689 Make_Integer_Literal (Loc, Nb_Prim))))));
6691 -- This table is initialized by Make_Select_Specific_Data_Table,
6692 -- which calls Set_Entry_Index and Set_Prim_Op_Kind.
6694 Append_To (TSD_Aggr_List,
6695 Make_Attribute_Reference (Loc,
6696 Prefix => New_Reference_To (SSD, Loc),
6697 Attribute_Name => Name_Unchecked_Access));
6698 else
6699 Append_To (TSD_Aggr_List, Make_Null (Loc));
6700 end if;
6701 end if;
6703 -- Initialize the table of ancestor tags. In case of interface types
6704 -- this table is not needed.
6706 TSD_Tags_List := New_List;
6708 -- Fill position 0 with Typ'Tag
6710 Append_To (TSD_Tags_List,
6711 Make_Attribute_Reference (Loc,
6712 Prefix => New_Reference_To (Typ, Loc),
6713 Attribute_Name => Name_Tag));
6715 -- Fill the rest of the table with the tags of the ancestors
6717 declare
6718 Current_Typ : Entity_Id;
6719 Parent_Typ : Entity_Id;
6720 Pos : Nat;
6722 begin
6723 Pos := 1;
6724 Current_Typ := Typ;
6726 loop
6727 Parent_Typ := Etype (Current_Typ);
6729 if Is_Private_Type (Parent_Typ) then
6730 Parent_Typ := Full_View (Base_Type (Parent_Typ));
6731 end if;
6733 exit when Parent_Typ = Current_Typ;
6735 Append_To (TSD_Tags_List,
6736 Make_Attribute_Reference (Loc,
6737 Prefix => New_Reference_To (Parent_Typ, Loc),
6738 Attribute_Name => Name_Tag));
6740 Pos := Pos + 1;
6741 Current_Typ := Parent_Typ;
6742 end loop;
6744 pragma Assert (Pos = I_Depth + 1);
6745 end;
6747 Append_To (TSD_Aggr_List,
6748 Make_Aggregate (Loc,
6749 Expressions => TSD_Tags_List));
6751 -- Build the TSD object
6753 Append_To (Result,
6754 Make_Object_Declaration (Loc,
6755 Defining_Identifier => TSD,
6756 Aliased_Present => True,
6757 Constant_Present => True,
6758 Object_Definition =>
6759 Make_Subtype_Indication (Loc,
6760 Subtype_Mark => New_Reference_To (
6761 RTE (RE_Type_Specific_Data), Loc),
6762 Constraint =>
6763 Make_Index_Or_Discriminant_Constraint (Loc,
6764 Constraints => New_List (
6765 Make_Integer_Literal (Loc, I_Depth)))),
6767 Expression => Make_Aggregate (Loc,
6768 Expressions => TSD_Aggr_List)));
6770 -- Generate:
6771 -- Check_TSD
6772 -- (TSD => TSD'Unrestricted_Access);
6774 if Ada_Version >= Ada_2005
6775 and then Is_Library_Level_Entity (Typ)
6776 and then Has_External_Tag_Rep_Clause (Typ)
6777 and then RTE_Available (RE_Check_TSD)
6778 and then not Debug_Flag_QQ
6779 then
6780 Append_To (Result,
6781 Make_Procedure_Call_Statement (Loc,
6782 Name => New_Reference_To (RTE (RE_Check_TSD), Loc),
6783 Parameter_Associations => New_List (
6784 Make_Attribute_Reference (Loc,
6785 Prefix => New_Reference_To (TSD, Loc),
6786 Attribute_Name => Name_Unrestricted_Access))));
6787 end if;
6789 -- Generate:
6790 -- Register_TSD (TSD'Unrestricted_Access);
6792 Append_To (Result,
6793 Make_Procedure_Call_Statement (Loc,
6794 Name => New_Reference_To (RTE (RE_Register_TSD), Loc),
6795 Parameter_Associations => New_List (
6796 Make_Attribute_Reference (Loc,
6797 Prefix => New_Reference_To (TSD, Loc),
6798 Attribute_Name => Name_Unrestricted_Access))));
6800 -- Populate the two auxiliary tables used for dispatching asynchronous,
6801 -- conditional and timed selects for synchronized types that implement
6802 -- a limited interface. Skip this step in Ravenscar profile or when
6803 -- general dispatching is forbidden.
6805 if Ada_Version >= Ada_2005
6806 and then Is_Concurrent_Record_Type (Typ)
6807 and then Has_Interfaces (Typ)
6808 and then not Restriction_Active (No_Dispatching_Calls)
6809 and then not Restriction_Active (No_Select_Statements)
6810 then
6811 Append_List_To (Result,
6812 Make_Select_Specific_Data_Table (Typ));
6813 end if;
6815 return Result;
6816 end Make_VM_TSD;
6818 -------------------------------------
6819 -- Make_Select_Specific_Data_Table --
6820 -------------------------------------
6822 function Make_Select_Specific_Data_Table
6823 (Typ : Entity_Id) return List_Id
6825 Assignments : constant List_Id := New_List;
6826 Loc : constant Source_Ptr := Sloc (Typ);
6828 Conc_Typ : Entity_Id;
6829 Decls : List_Id;
6830 Prim : Entity_Id;
6831 Prim_Als : Entity_Id;
6832 Prim_Elmt : Elmt_Id;
6833 Prim_Pos : Uint;
6834 Nb_Prim : Nat := 0;
6836 type Examined_Array is array (Int range <>) of Boolean;
6838 function Find_Entry_Index (E : Entity_Id) return Uint;
6839 -- Given an entry, find its index in the visible declarations of the
6840 -- corresponding concurrent type of Typ.
6842 ----------------------
6843 -- Find_Entry_Index --
6844 ----------------------
6846 function Find_Entry_Index (E : Entity_Id) return Uint is
6847 Index : Uint := Uint_1;
6848 Subp_Decl : Entity_Id;
6850 begin
6851 if Present (Decls)
6852 and then not Is_Empty_List (Decls)
6853 then
6854 Subp_Decl := First (Decls);
6855 while Present (Subp_Decl) loop
6856 if Nkind (Subp_Decl) = N_Entry_Declaration then
6857 if Defining_Identifier (Subp_Decl) = E then
6858 return Index;
6859 end if;
6861 Index := Index + 1;
6862 end if;
6864 Next (Subp_Decl);
6865 end loop;
6866 end if;
6868 return Uint_0;
6869 end Find_Entry_Index;
6871 -- Local variables
6873 Tag_Node : Node_Id;
6875 -- Start of processing for Make_Select_Specific_Data_Table
6877 begin
6878 pragma Assert (not Restriction_Active (No_Dispatching_Calls));
6880 if Present (Corresponding_Concurrent_Type (Typ)) then
6881 Conc_Typ := Corresponding_Concurrent_Type (Typ);
6883 if Present (Full_View (Conc_Typ)) then
6884 Conc_Typ := Full_View (Conc_Typ);
6885 end if;
6887 if Ekind (Conc_Typ) = E_Protected_Type then
6888 Decls := Visible_Declarations (Protected_Definition (
6889 Parent (Conc_Typ)));
6890 else
6891 pragma Assert (Ekind (Conc_Typ) = E_Task_Type);
6892 Decls := Visible_Declarations (Task_Definition (
6893 Parent (Conc_Typ)));
6894 end if;
6895 end if;
6897 -- Count the non-predefined primitive operations
6899 Prim_Elmt := First_Elmt (Primitive_Operations (Typ));
6900 while Present (Prim_Elmt) loop
6901 Prim := Node (Prim_Elmt);
6903 if not (Is_Predefined_Dispatching_Operation (Prim)
6904 or else Is_Predefined_Dispatching_Alias (Prim))
6905 then
6906 Nb_Prim := Nb_Prim + 1;
6907 end if;
6909 Next_Elmt (Prim_Elmt);
6910 end loop;
6912 declare
6913 Examined : Examined_Array (1 .. Nb_Prim) := (others => False);
6915 begin
6916 Prim_Elmt := First_Elmt (Primitive_Operations (Typ));
6917 while Present (Prim_Elmt) loop
6918 Prim := Node (Prim_Elmt);
6920 -- Look for primitive overriding an abstract interface subprogram
6922 if Present (Interface_Alias (Prim))
6923 and then not
6924 Is_Ancestor
6925 (Find_Dispatching_Type (Interface_Alias (Prim)), Typ,
6926 Use_Full_View => True)
6927 and then not Examined (UI_To_Int (DT_Position (Alias (Prim))))
6928 then
6929 Prim_Pos := DT_Position (Alias (Prim));
6930 pragma Assert (UI_To_Int (Prim_Pos) <= Nb_Prim);
6931 Examined (UI_To_Int (Prim_Pos)) := True;
6933 -- Set the primitive operation kind regardless of subprogram
6934 -- type. Generate:
6935 -- Ada.Tags.Set_Prim_Op_Kind (DT_Ptr, <position>, <kind>);
6937 if Tagged_Type_Expansion then
6938 Tag_Node :=
6939 New_Reference_To
6940 (Node (First_Elmt (Access_Disp_Table (Typ))), Loc);
6942 else
6943 Tag_Node :=
6944 Make_Attribute_Reference (Loc,
6945 Prefix => New_Reference_To (Typ, Loc),
6946 Attribute_Name => Name_Tag);
6947 end if;
6949 Append_To (Assignments,
6950 Make_Procedure_Call_Statement (Loc,
6951 Name => New_Reference_To (RTE (RE_Set_Prim_Op_Kind), Loc),
6952 Parameter_Associations => New_List (
6953 Tag_Node,
6954 Make_Integer_Literal (Loc, Prim_Pos),
6955 Prim_Op_Kind (Alias (Prim), Typ))));
6957 -- Retrieve the root of the alias chain
6959 Prim_Als := Ultimate_Alias (Prim);
6961 -- In the case of an entry wrapper, set the entry index
6963 if Ekind (Prim) = E_Procedure
6964 and then Is_Primitive_Wrapper (Prim_Als)
6965 and then Ekind (Wrapped_Entity (Prim_Als)) = E_Entry
6966 then
6967 -- Generate:
6968 -- Ada.Tags.Set_Entry_Index
6969 -- (DT_Ptr, <position>, <index>);
6971 if Tagged_Type_Expansion then
6972 Tag_Node :=
6973 New_Reference_To
6974 (Node (First_Elmt (Access_Disp_Table (Typ))), Loc);
6975 else
6976 Tag_Node :=
6977 Make_Attribute_Reference (Loc,
6978 Prefix => New_Reference_To (Typ, Loc),
6979 Attribute_Name => Name_Tag);
6980 end if;
6982 Append_To (Assignments,
6983 Make_Procedure_Call_Statement (Loc,
6984 Name =>
6985 New_Reference_To (RTE (RE_Set_Entry_Index), Loc),
6986 Parameter_Associations => New_List (
6987 Tag_Node,
6988 Make_Integer_Literal (Loc, Prim_Pos),
6989 Make_Integer_Literal (Loc,
6990 Find_Entry_Index (Wrapped_Entity (Prim_Als))))));
6991 end if;
6992 end if;
6994 Next_Elmt (Prim_Elmt);
6995 end loop;
6996 end;
6998 return Assignments;
6999 end Make_Select_Specific_Data_Table;
7001 ---------------
7002 -- Make_Tags --
7003 ---------------
7005 function Make_Tags (Typ : Entity_Id) return List_Id is
7006 Loc : constant Source_Ptr := Sloc (Typ);
7007 Result : constant List_Id := New_List;
7009 procedure Import_DT
7010 (Tag_Typ : Entity_Id;
7011 DT : Entity_Id;
7012 Is_Secondary_DT : Boolean);
7013 -- Import the dispatch table DT of tagged type Tag_Typ. Required to
7014 -- generate forward references and statically allocate the table. For
7015 -- primary dispatch tables that require no dispatch table generate:
7017 -- DT : static aliased constant Non_Dispatch_Table_Wrapper;
7018 -- pragma Import (Ada, DT);
7020 -- Otherwise generate:
7022 -- DT : static aliased constant Dispatch_Table_Wrapper (Nb_Prim);
7023 -- pragma Import (Ada, DT);
7025 ---------------
7026 -- Import_DT --
7027 ---------------
7029 procedure Import_DT
7030 (Tag_Typ : Entity_Id;
7031 DT : Entity_Id;
7032 Is_Secondary_DT : Boolean)
7034 DT_Constr_List : List_Id;
7035 Nb_Prim : Nat;
7037 begin
7038 Set_Is_Imported (DT);
7039 Set_Ekind (DT, E_Constant);
7040 Set_Related_Type (DT, Typ);
7042 -- The scope must be set now to call Get_External_Name
7044 Set_Scope (DT, Current_Scope);
7046 Get_External_Name (DT, True);
7047 Set_Interface_Name (DT,
7048 Make_String_Literal (Loc, Strval => String_From_Name_Buffer));
7050 -- Ensure proper Sprint output of this implicit importation
7052 Set_Is_Internal (DT);
7054 -- Save this entity to allow Make_DT to generate its exportation
7056 Append_Elmt (DT, Dispatch_Table_Wrappers (Typ));
7058 -- No dispatch table required
7060 if not Is_Secondary_DT and then not Has_DT (Tag_Typ) then
7061 Append_To (Result,
7062 Make_Object_Declaration (Loc,
7063 Defining_Identifier => DT,
7064 Aliased_Present => True,
7065 Constant_Present => True,
7066 Object_Definition =>
7067 New_Reference_To (RTE (RE_No_Dispatch_Table_Wrapper), Loc)));
7069 else
7070 -- Calculate the number of primitives of the dispatch table and
7071 -- the size of the Type_Specific_Data record.
7073 Nb_Prim :=
7074 UI_To_Int (DT_Entry_Count (First_Tag_Component (Tag_Typ)));
7076 -- If the tagged type has no primitives we add a dummy slot whose
7077 -- address will be the tag of this type.
7079 if Nb_Prim = 0 then
7080 DT_Constr_List :=
7081 New_List (Make_Integer_Literal (Loc, 1));
7082 else
7083 DT_Constr_List :=
7084 New_List (Make_Integer_Literal (Loc, Nb_Prim));
7085 end if;
7087 Append_To (Result,
7088 Make_Object_Declaration (Loc,
7089 Defining_Identifier => DT,
7090 Aliased_Present => True,
7091 Constant_Present => True,
7092 Object_Definition =>
7093 Make_Subtype_Indication (Loc,
7094 Subtype_Mark =>
7095 New_Reference_To (RTE (RE_Dispatch_Table_Wrapper), Loc),
7096 Constraint => Make_Index_Or_Discriminant_Constraint (Loc,
7097 Constraints => DT_Constr_List))));
7098 end if;
7099 end Import_DT;
7101 -- Local variables
7103 Tname : constant Name_Id := Chars (Typ);
7104 AI_Tag_Comp : Elmt_Id;
7105 DT : Node_Id := Empty;
7106 DT_Ptr : Node_Id;
7107 Predef_Prims_Ptr : Node_Id;
7108 Iface_DT : Node_Id := Empty;
7109 Iface_DT_Ptr : Node_Id;
7110 New_Node : Node_Id;
7111 Suffix_Index : Int;
7112 Typ_Name : Name_Id;
7113 Typ_Comps : Elist_Id;
7115 -- Start of processing for Make_Tags
7117 begin
7118 pragma Assert (No (Access_Disp_Table (Typ)));
7119 Set_Access_Disp_Table (Typ, New_Elmt_List);
7121 -- 1) Generate the primary tag entities
7123 -- Primary dispatch table containing user-defined primitives
7125 DT_Ptr := Make_Defining_Identifier (Loc, New_External_Name (Tname, 'P'));
7126 Set_Etype (DT_Ptr, RTE (RE_Tag));
7127 Append_Elmt (DT_Ptr, Access_Disp_Table (Typ));
7129 -- Minimum decoration
7131 Set_Ekind (DT_Ptr, E_Variable);
7132 Set_Related_Type (DT_Ptr, Typ);
7134 -- Ensure that entities Prim_Ptr and Predef_Prims_Table_Ptr have
7135 -- the decoration required by the backend.
7137 -- Odd comment, the back end cannot require anything not properly
7138 -- documented in einfo! ???
7140 Set_Is_Dispatch_Table_Entity (RTE (RE_Prim_Ptr));
7141 Set_Is_Dispatch_Table_Entity (RTE (RE_Predef_Prims_Table_Ptr));
7143 -- For CPP types there is no need to build the dispatch tables since
7144 -- they are imported from the C++ side. If the CPP type has an IP then
7145 -- we declare now the variable that will store the copy of the C++ tag.
7146 -- If the CPP type is an interface, we need the variable as well because
7147 -- it becomes the pointer to the corresponding secondary table.
7149 if Is_CPP_Class (Typ) then
7150 if Has_CPP_Constructors (Typ) or else Is_Interface (Typ) then
7151 Append_To (Result,
7152 Make_Object_Declaration (Loc,
7153 Defining_Identifier => DT_Ptr,
7154 Object_Definition => New_Reference_To (RTE (RE_Tag), Loc),
7155 Expression =>
7156 Unchecked_Convert_To (RTE (RE_Tag),
7157 New_Reference_To (RTE (RE_Null_Address), Loc))));
7159 Set_Is_Statically_Allocated (DT_Ptr,
7160 Is_Library_Level_Tagged_Type (Typ));
7161 end if;
7163 -- Ada types
7165 else
7166 -- Primary dispatch table containing predefined primitives
7168 Predef_Prims_Ptr :=
7169 Make_Defining_Identifier (Loc,
7170 Chars => New_External_Name (Tname, 'Y'));
7171 Set_Etype (Predef_Prims_Ptr, RTE (RE_Address));
7172 Append_Elmt (Predef_Prims_Ptr, Access_Disp_Table (Typ));
7174 -- Import the forward declaration of the Dispatch Table wrapper
7175 -- record (Make_DT will take care of exporting it).
7177 if Building_Static_DT (Typ) then
7178 Set_Dispatch_Table_Wrappers (Typ, New_Elmt_List);
7180 DT :=
7181 Make_Defining_Identifier (Loc,
7182 Chars => New_External_Name (Tname, 'T'));
7184 Import_DT (Typ, DT, Is_Secondary_DT => False);
7186 if Has_DT (Typ) then
7187 Append_To (Result,
7188 Make_Object_Declaration (Loc,
7189 Defining_Identifier => DT_Ptr,
7190 Constant_Present => True,
7191 Object_Definition => New_Reference_To (RTE (RE_Tag), Loc),
7192 Expression =>
7193 Unchecked_Convert_To (RTE (RE_Tag),
7194 Make_Attribute_Reference (Loc,
7195 Prefix =>
7196 Make_Selected_Component (Loc,
7197 Prefix => New_Reference_To (DT, Loc),
7198 Selector_Name =>
7199 New_Occurrence_Of
7200 (RTE_Record_Component (RE_Prims_Ptr), Loc)),
7201 Attribute_Name => Name_Address))));
7203 -- Generate the SCIL node for the previous object declaration
7204 -- because it has a tag initialization.
7206 if Generate_SCIL then
7207 New_Node :=
7208 Make_SCIL_Dispatch_Table_Tag_Init (Sloc (Last (Result)));
7209 Set_SCIL_Entity (New_Node, Typ);
7210 Set_SCIL_Node (Last (Result), New_Node);
7211 end if;
7213 Append_To (Result,
7214 Make_Object_Declaration (Loc,
7215 Defining_Identifier => Predef_Prims_Ptr,
7216 Constant_Present => True,
7217 Object_Definition =>
7218 New_Reference_To (RTE (RE_Address), Loc),
7219 Expression =>
7220 Make_Attribute_Reference (Loc,
7221 Prefix =>
7222 Make_Selected_Component (Loc,
7223 Prefix => New_Reference_To (DT, Loc),
7224 Selector_Name =>
7225 New_Occurrence_Of
7226 (RTE_Record_Component (RE_Predef_Prims), Loc)),
7227 Attribute_Name => Name_Address)));
7229 -- No dispatch table required
7231 else
7232 Append_To (Result,
7233 Make_Object_Declaration (Loc,
7234 Defining_Identifier => DT_Ptr,
7235 Constant_Present => True,
7236 Object_Definition => New_Reference_To (RTE (RE_Tag), Loc),
7237 Expression =>
7238 Unchecked_Convert_To (RTE (RE_Tag),
7239 Make_Attribute_Reference (Loc,
7240 Prefix =>
7241 Make_Selected_Component (Loc,
7242 Prefix => New_Reference_To (DT, Loc),
7243 Selector_Name =>
7244 New_Occurrence_Of
7245 (RTE_Record_Component (RE_NDT_Prims_Ptr),
7246 Loc)),
7247 Attribute_Name => Name_Address))));
7248 end if;
7250 Set_Is_True_Constant (DT_Ptr);
7251 Set_Is_Statically_Allocated (DT_Ptr);
7252 end if;
7253 end if;
7255 -- 2) Generate the secondary tag entities
7257 -- Collect the components associated with secondary dispatch tables
7259 if Has_Interfaces (Typ) then
7260 Collect_Interface_Components (Typ, Typ_Comps);
7262 -- For each interface type we build a unique external name associated
7263 -- with its secondary dispatch table. This name is used to declare an
7264 -- object that references this secondary dispatch table, whose value
7265 -- will be used for the elaboration of Typ objects, and also for the
7266 -- elaboration of objects of types derived from Typ that do not
7267 -- override the primitives of this interface type.
7269 Suffix_Index := 1;
7271 -- Note: The value of Suffix_Index must be in sync with the
7272 -- Suffix_Index values of secondary dispatch tables generated
7273 -- by Make_DT.
7275 if Is_CPP_Class (Typ) then
7276 AI_Tag_Comp := First_Elmt (Typ_Comps);
7277 while Present (AI_Tag_Comp) loop
7278 Get_Secondary_DT_External_Name
7279 (Typ, Related_Type (Node (AI_Tag_Comp)), Suffix_Index);
7280 Typ_Name := Name_Find;
7282 -- Declare variables that will store the copy of the C++
7283 -- secondary tags.
7285 Iface_DT_Ptr :=
7286 Make_Defining_Identifier (Loc,
7287 Chars => New_External_Name (Typ_Name, 'P'));
7288 Set_Etype (Iface_DT_Ptr, RTE (RE_Interface_Tag));
7289 Set_Ekind (Iface_DT_Ptr, E_Variable);
7290 Set_Is_Tag (Iface_DT_Ptr);
7292 Set_Has_Thunks (Iface_DT_Ptr);
7293 Set_Related_Type
7294 (Iface_DT_Ptr, Related_Type (Node (AI_Tag_Comp)));
7295 Append_Elmt (Iface_DT_Ptr, Access_Disp_Table (Typ));
7297 Append_To (Result,
7298 Make_Object_Declaration (Loc,
7299 Defining_Identifier => Iface_DT_Ptr,
7300 Object_Definition => New_Reference_To
7301 (RTE (RE_Interface_Tag), Loc),
7302 Expression =>
7303 Unchecked_Convert_To (RTE (RE_Interface_Tag),
7304 New_Reference_To (RTE (RE_Null_Address), Loc))));
7306 Set_Is_Statically_Allocated (Iface_DT_Ptr,
7307 Is_Library_Level_Tagged_Type (Typ));
7309 Next_Elmt (AI_Tag_Comp);
7310 end loop;
7312 -- This is not a CPP_Class type
7314 else
7315 AI_Tag_Comp := First_Elmt (Typ_Comps);
7316 while Present (AI_Tag_Comp) loop
7317 Get_Secondary_DT_External_Name
7318 (Typ, Related_Type (Node (AI_Tag_Comp)), Suffix_Index);
7319 Typ_Name := Name_Find;
7321 if Building_Static_DT (Typ) then
7322 Iface_DT :=
7323 Make_Defining_Identifier (Loc,
7324 Chars => New_External_Name
7325 (Typ_Name, 'T', Suffix_Index => -1));
7326 Import_DT
7327 (Tag_Typ => Related_Type (Node (AI_Tag_Comp)),
7328 DT => Iface_DT,
7329 Is_Secondary_DT => True);
7330 end if;
7332 -- Secondary dispatch table referencing thunks to user-defined
7333 -- primitives covered by this interface.
7335 Iface_DT_Ptr :=
7336 Make_Defining_Identifier (Loc,
7337 Chars => New_External_Name (Typ_Name, 'P'));
7338 Set_Etype (Iface_DT_Ptr, RTE (RE_Interface_Tag));
7339 Set_Ekind (Iface_DT_Ptr, E_Constant);
7340 Set_Is_Tag (Iface_DT_Ptr);
7341 Set_Has_Thunks (Iface_DT_Ptr);
7342 Set_Is_Statically_Allocated (Iface_DT_Ptr,
7343 Is_Library_Level_Tagged_Type (Typ));
7344 Set_Is_True_Constant (Iface_DT_Ptr);
7345 Set_Related_Type
7346 (Iface_DT_Ptr, Related_Type (Node (AI_Tag_Comp)));
7347 Append_Elmt (Iface_DT_Ptr, Access_Disp_Table (Typ));
7349 if Building_Static_DT (Typ) then
7350 Append_To (Result,
7351 Make_Object_Declaration (Loc,
7352 Defining_Identifier => Iface_DT_Ptr,
7353 Constant_Present => True,
7354 Object_Definition => New_Reference_To
7355 (RTE (RE_Interface_Tag), Loc),
7356 Expression =>
7357 Unchecked_Convert_To (RTE (RE_Interface_Tag),
7358 Make_Attribute_Reference (Loc,
7359 Prefix =>
7360 Make_Selected_Component (Loc,
7361 Prefix =>
7362 New_Reference_To (Iface_DT, Loc),
7363 Selector_Name =>
7364 New_Occurrence_Of
7365 (RTE_Record_Component (RE_Prims_Ptr),
7366 Loc)),
7367 Attribute_Name => Name_Address))));
7368 end if;
7370 -- Secondary dispatch table referencing thunks to predefined
7371 -- primitives.
7373 Iface_DT_Ptr :=
7374 Make_Defining_Identifier (Loc,
7375 Chars => New_External_Name (Typ_Name, 'Y'));
7376 Set_Etype (Iface_DT_Ptr, RTE (RE_Address));
7377 Set_Ekind (Iface_DT_Ptr, E_Constant);
7378 Set_Is_Tag (Iface_DT_Ptr);
7379 Set_Has_Thunks (Iface_DT_Ptr);
7380 Set_Is_Statically_Allocated (Iface_DT_Ptr,
7381 Is_Library_Level_Tagged_Type (Typ));
7382 Set_Is_True_Constant (Iface_DT_Ptr);
7383 Set_Related_Type
7384 (Iface_DT_Ptr, Related_Type (Node (AI_Tag_Comp)));
7385 Append_Elmt (Iface_DT_Ptr, Access_Disp_Table (Typ));
7387 -- Secondary dispatch table referencing user-defined primitives
7388 -- covered by this interface.
7390 Iface_DT_Ptr :=
7391 Make_Defining_Identifier (Loc,
7392 Chars => New_External_Name (Typ_Name, 'D'));
7393 Set_Etype (Iface_DT_Ptr, RTE (RE_Interface_Tag));
7394 Set_Ekind (Iface_DT_Ptr, E_Constant);
7395 Set_Is_Tag (Iface_DT_Ptr);
7396 Set_Is_Statically_Allocated (Iface_DT_Ptr,
7397 Is_Library_Level_Tagged_Type (Typ));
7398 Set_Is_True_Constant (Iface_DT_Ptr);
7399 Set_Related_Type
7400 (Iface_DT_Ptr, Related_Type (Node (AI_Tag_Comp)));
7401 Append_Elmt (Iface_DT_Ptr, Access_Disp_Table (Typ));
7403 -- Secondary dispatch table referencing predefined primitives
7405 Iface_DT_Ptr :=
7406 Make_Defining_Identifier (Loc,
7407 Chars => New_External_Name (Typ_Name, 'Z'));
7408 Set_Etype (Iface_DT_Ptr, RTE (RE_Address));
7409 Set_Ekind (Iface_DT_Ptr, E_Constant);
7410 Set_Is_Tag (Iface_DT_Ptr);
7411 Set_Is_Statically_Allocated (Iface_DT_Ptr,
7412 Is_Library_Level_Tagged_Type (Typ));
7413 Set_Is_True_Constant (Iface_DT_Ptr);
7414 Set_Related_Type
7415 (Iface_DT_Ptr, Related_Type (Node (AI_Tag_Comp)));
7416 Append_Elmt (Iface_DT_Ptr, Access_Disp_Table (Typ));
7418 Next_Elmt (AI_Tag_Comp);
7419 end loop;
7420 end if;
7421 end if;
7423 -- 3) At the end of Access_Disp_Table, if the type has user-defined
7424 -- primitives, we add the entity of an access type declaration that
7425 -- is used by Build_Get_Prim_Op_Address to expand dispatching calls
7426 -- through the primary dispatch table.
7428 if UI_To_Int (DT_Entry_Count (First_Tag_Component (Typ))) = 0 then
7429 Analyze_List (Result);
7431 -- Generate:
7432 -- type Typ_DT is array (1 .. Nb_Prims) of Prim_Ptr;
7433 -- type Typ_DT_Acc is access Typ_DT;
7435 else
7436 declare
7437 Name_DT_Prims : constant Name_Id :=
7438 New_External_Name (Tname, 'G');
7439 Name_DT_Prims_Acc : constant Name_Id :=
7440 New_External_Name (Tname, 'H');
7441 DT_Prims : constant Entity_Id :=
7442 Make_Defining_Identifier (Loc,
7443 Name_DT_Prims);
7444 DT_Prims_Acc : constant Entity_Id :=
7445 Make_Defining_Identifier (Loc,
7446 Name_DT_Prims_Acc);
7447 begin
7448 Append_To (Result,
7449 Make_Full_Type_Declaration (Loc,
7450 Defining_Identifier => DT_Prims,
7451 Type_Definition =>
7452 Make_Constrained_Array_Definition (Loc,
7453 Discrete_Subtype_Definitions => New_List (
7454 Make_Range (Loc,
7455 Low_Bound => Make_Integer_Literal (Loc, 1),
7456 High_Bound => Make_Integer_Literal (Loc,
7457 DT_Entry_Count
7458 (First_Tag_Component (Typ))))),
7459 Component_Definition =>
7460 Make_Component_Definition (Loc,
7461 Subtype_Indication =>
7462 New_Reference_To (RTE (RE_Prim_Ptr), Loc)))));
7464 Append_To (Result,
7465 Make_Full_Type_Declaration (Loc,
7466 Defining_Identifier => DT_Prims_Acc,
7467 Type_Definition =>
7468 Make_Access_To_Object_Definition (Loc,
7469 Subtype_Indication =>
7470 New_Occurrence_Of (DT_Prims, Loc))));
7472 Append_Elmt (DT_Prims_Acc, Access_Disp_Table (Typ));
7474 -- Analyze the resulting list and suppress the generation of the
7475 -- Init_Proc associated with the above array declaration because
7476 -- this type is never used in object declarations. It is only used
7477 -- to simplify the expansion associated with dispatching calls.
7479 Analyze_List (Result);
7480 Set_Suppress_Initialization (Base_Type (DT_Prims));
7482 -- Disable backend optimizations based on assumptions about the
7483 -- aliasing status of objects designated by the access to the
7484 -- dispatch table. Required to handle dispatch tables imported
7485 -- from C++.
7487 Set_No_Strict_Aliasing (Base_Type (DT_Prims_Acc));
7489 -- Add the freezing nodes of these declarations; required to avoid
7490 -- generating these freezing nodes in wrong scopes (for example in
7491 -- the IC routine of a derivation of Typ).
7492 -- What is an "IC routine"? Is "init_proc" meant here???
7494 Append_List_To (Result, Freeze_Entity (DT_Prims, Typ));
7495 Append_List_To (Result, Freeze_Entity (DT_Prims_Acc, Typ));
7497 -- Mark entity of dispatch table. Required by the back end to
7498 -- handle them properly.
7500 Set_Is_Dispatch_Table_Entity (DT_Prims);
7501 end;
7502 end if;
7504 -- Mark entities of dispatch table. Required by the back end to handle
7505 -- them properly.
7507 if Present (DT) then
7508 Set_Is_Dispatch_Table_Entity (DT);
7509 Set_Is_Dispatch_Table_Entity (Etype (DT));
7510 end if;
7512 if Present (Iface_DT) then
7513 Set_Is_Dispatch_Table_Entity (Iface_DT);
7514 Set_Is_Dispatch_Table_Entity (Etype (Iface_DT));
7515 end if;
7517 if Is_CPP_Class (Root_Type (Typ)) then
7518 Set_Ekind (DT_Ptr, E_Variable);
7519 else
7520 Set_Ekind (DT_Ptr, E_Constant);
7521 end if;
7523 Set_Is_Tag (DT_Ptr);
7524 Set_Related_Type (DT_Ptr, Typ);
7526 return Result;
7527 end Make_Tags;
7529 ---------------
7530 -- New_Value --
7531 ---------------
7533 function New_Value (From : Node_Id) return Node_Id is
7534 Res : constant Node_Id := Duplicate_Subexpr (From);
7535 begin
7536 if Is_Access_Type (Etype (From)) then
7537 return
7538 Make_Explicit_Dereference (Sloc (From),
7539 Prefix => Res);
7540 else
7541 return Res;
7542 end if;
7543 end New_Value;
7545 -----------------------------------
7546 -- Original_View_In_Visible_Part --
7547 -----------------------------------
7549 function Original_View_In_Visible_Part (Typ : Entity_Id) return Boolean is
7550 Scop : constant Entity_Id := Scope (Typ);
7552 begin
7553 -- The scope must be a package
7555 if not Is_Package_Or_Generic_Package (Scop) then
7556 return False;
7557 end if;
7559 -- A type with a private declaration has a private view declared in
7560 -- the visible part.
7562 if Has_Private_Declaration (Typ) then
7563 return True;
7564 end if;
7566 return List_Containing (Parent (Typ)) =
7567 Visible_Declarations (Specification (Unit_Declaration_Node (Scop)));
7568 end Original_View_In_Visible_Part;
7570 ------------------
7571 -- Prim_Op_Kind --
7572 ------------------
7574 function Prim_Op_Kind
7575 (Prim : Entity_Id;
7576 Typ : Entity_Id) return Node_Id
7578 Full_Typ : Entity_Id := Typ;
7579 Loc : constant Source_Ptr := Sloc (Prim);
7580 Prim_Op : Entity_Id;
7582 begin
7583 -- Retrieve the original primitive operation
7585 Prim_Op := Ultimate_Alias (Prim);
7587 if Ekind (Typ) = E_Record_Type
7588 and then Present (Corresponding_Concurrent_Type (Typ))
7589 then
7590 Full_Typ := Corresponding_Concurrent_Type (Typ);
7591 end if;
7593 -- When a private tagged type is completed by a concurrent type,
7594 -- retrieve the full view.
7596 if Is_Private_Type (Full_Typ) then
7597 Full_Typ := Full_View (Full_Typ);
7598 end if;
7600 if Ekind (Prim_Op) = E_Function then
7602 -- Protected function
7604 if Ekind (Full_Typ) = E_Protected_Type then
7605 return New_Reference_To (RTE (RE_POK_Protected_Function), Loc);
7607 -- Task function
7609 elsif Ekind (Full_Typ) = E_Task_Type then
7610 return New_Reference_To (RTE (RE_POK_Task_Function), Loc);
7612 -- Regular function
7614 else
7615 return New_Reference_To (RTE (RE_POK_Function), Loc);
7616 end if;
7618 else
7619 pragma Assert (Ekind (Prim_Op) = E_Procedure);
7621 if Ekind (Full_Typ) = E_Protected_Type then
7623 -- Protected entry
7625 if Is_Primitive_Wrapper (Prim_Op)
7626 and then Ekind (Wrapped_Entity (Prim_Op)) = E_Entry
7627 then
7628 return New_Reference_To (RTE (RE_POK_Protected_Entry), Loc);
7630 -- Protected procedure
7632 else
7633 return New_Reference_To (RTE (RE_POK_Protected_Procedure), Loc);
7634 end if;
7636 elsif Ekind (Full_Typ) = E_Task_Type then
7638 -- Task entry
7640 if Is_Primitive_Wrapper (Prim_Op)
7641 and then Ekind (Wrapped_Entity (Prim_Op)) = E_Entry
7642 then
7643 return New_Reference_To (RTE (RE_POK_Task_Entry), Loc);
7645 -- Task "procedure". These are the internally Expander-generated
7646 -- procedures (task body for instance).
7648 else
7649 return New_Reference_To (RTE (RE_POK_Task_Procedure), Loc);
7650 end if;
7652 -- Regular procedure
7654 else
7655 return New_Reference_To (RTE (RE_POK_Procedure), Loc);
7656 end if;
7657 end if;
7658 end Prim_Op_Kind;
7660 ------------------------
7661 -- Register_Primitive --
7662 ------------------------
7664 function Register_Primitive
7665 (Loc : Source_Ptr;
7666 Prim : Entity_Id) return List_Id
7668 DT_Ptr : Entity_Id;
7669 Iface_Prim : Entity_Id;
7670 Iface_Typ : Entity_Id;
7671 Iface_DT_Ptr : Entity_Id;
7672 Iface_DT_Elmt : Elmt_Id;
7673 L : constant List_Id := New_List;
7674 Pos : Uint;
7675 Tag : Entity_Id;
7676 Tag_Typ : Entity_Id;
7677 Thunk_Id : Entity_Id;
7678 Thunk_Code : Node_Id;
7680 begin
7681 pragma Assert (not Restriction_Active (No_Dispatching_Calls));
7682 pragma Assert (VM_Target = No_VM);
7684 -- Do not register in the dispatch table eliminated primitives
7686 if not RTE_Available (RE_Tag)
7687 or else Is_Eliminated (Ultimate_Alias (Prim))
7688 then
7689 return L;
7690 end if;
7692 if not Present (Interface_Alias (Prim)) then
7693 Tag_Typ := Scope (DTC_Entity (Prim));
7694 Pos := DT_Position (Prim);
7695 Tag := First_Tag_Component (Tag_Typ);
7697 if Is_Predefined_Dispatching_Operation (Prim)
7698 or else Is_Predefined_Dispatching_Alias (Prim)
7699 then
7700 DT_Ptr :=
7701 Node (Next_Elmt (First_Elmt (Access_Disp_Table (Tag_Typ))));
7703 Append_To (L,
7704 Build_Set_Predefined_Prim_Op_Address (Loc,
7705 Tag_Node => New_Reference_To (DT_Ptr, Loc),
7706 Position => Pos,
7707 Address_Node =>
7708 Unchecked_Convert_To (RTE (RE_Prim_Ptr),
7709 Make_Attribute_Reference (Loc,
7710 Prefix => New_Reference_To (Prim, Loc),
7711 Attribute_Name => Name_Unrestricted_Access))));
7713 -- Register copy of the pointer to the 'size primitive in the TSD
7715 if Chars (Prim) = Name_uSize
7716 and then RTE_Record_Component_Available (RE_Size_Func)
7717 then
7718 DT_Ptr := Node (First_Elmt (Access_Disp_Table (Tag_Typ)));
7719 Append_To (L,
7720 Build_Set_Size_Function (Loc,
7721 Tag_Node => New_Reference_To (DT_Ptr, Loc),
7722 Size_Func => Prim));
7723 end if;
7725 else
7726 pragma Assert (Pos /= Uint_0 and then Pos <= DT_Entry_Count (Tag));
7728 -- Skip registration of primitives located in the C++ part of the
7729 -- dispatch table. Their slot is set by the IC routine.
7731 if not Is_CPP_Class (Root_Type (Tag_Typ))
7732 or else Pos > CPP_Num_Prims (Tag_Typ)
7733 then
7734 DT_Ptr := Node (First_Elmt (Access_Disp_Table (Tag_Typ)));
7735 Append_To (L,
7736 Build_Set_Prim_Op_Address (Loc,
7737 Typ => Tag_Typ,
7738 Tag_Node => New_Reference_To (DT_Ptr, Loc),
7739 Position => Pos,
7740 Address_Node =>
7741 Unchecked_Convert_To (RTE (RE_Prim_Ptr),
7742 Make_Attribute_Reference (Loc,
7743 Prefix => New_Reference_To (Prim, Loc),
7744 Attribute_Name => Name_Unrestricted_Access))));
7745 end if;
7746 end if;
7748 -- Ada 2005 (AI-251): Primitive associated with an interface type
7749 -- Generate the code of the thunk only if the interface type is not an
7750 -- immediate ancestor of Typ; otherwise the dispatch table associated
7751 -- with the interface is the primary dispatch table and we have nothing
7752 -- else to do here.
7754 else
7755 Tag_Typ := Find_Dispatching_Type (Alias (Prim));
7756 Iface_Typ := Find_Dispatching_Type (Interface_Alias (Prim));
7758 pragma Assert (Is_Interface (Iface_Typ));
7760 -- No action needed for interfaces that are ancestors of Typ because
7761 -- their primitives are located in the primary dispatch table.
7763 if Is_Ancestor (Iface_Typ, Tag_Typ, Use_Full_View => True) then
7764 return L;
7766 -- No action needed for primitives located in the C++ part of the
7767 -- dispatch table. Their slot is set by the IC routine.
7769 elsif Is_CPP_Class (Root_Type (Tag_Typ))
7770 and then DT_Position (Alias (Prim)) <= CPP_Num_Prims (Tag_Typ)
7771 and then not Is_Predefined_Dispatching_Operation (Prim)
7772 and then not Is_Predefined_Dispatching_Alias (Prim)
7773 then
7774 return L;
7775 end if;
7777 Expand_Interface_Thunk (Prim, Thunk_Id, Thunk_Code);
7779 if not Is_Ancestor (Iface_Typ, Tag_Typ, Use_Full_View => True)
7780 and then Present (Thunk_Code)
7781 then
7782 -- Generate the code necessary to fill the appropriate entry of
7783 -- the secondary dispatch table of Prim's controlling type with
7784 -- Thunk_Id's address.
7786 Iface_DT_Elmt := Find_Interface_ADT (Tag_Typ, Iface_Typ);
7787 Iface_DT_Ptr := Node (Iface_DT_Elmt);
7788 pragma Assert (Has_Thunks (Iface_DT_Ptr));
7790 Iface_Prim := Interface_Alias (Prim);
7791 Pos := DT_Position (Iface_Prim);
7792 Tag := First_Tag_Component (Iface_Typ);
7794 Prepend_To (L, Thunk_Code);
7796 if Is_Predefined_Dispatching_Operation (Prim)
7797 or else Is_Predefined_Dispatching_Alias (Prim)
7798 then
7799 Append_To (L,
7800 Build_Set_Predefined_Prim_Op_Address (Loc,
7801 Tag_Node =>
7802 New_Reference_To (Node (Next_Elmt (Iface_DT_Elmt)), Loc),
7803 Position => Pos,
7804 Address_Node =>
7805 Unchecked_Convert_To (RTE (RE_Prim_Ptr),
7806 Make_Attribute_Reference (Loc,
7807 Prefix => New_Reference_To (Thunk_Id, Loc),
7808 Attribute_Name => Name_Unrestricted_Access))));
7810 Next_Elmt (Iface_DT_Elmt);
7811 Next_Elmt (Iface_DT_Elmt);
7812 Iface_DT_Ptr := Node (Iface_DT_Elmt);
7813 pragma Assert (not Has_Thunks (Iface_DT_Ptr));
7815 Append_To (L,
7816 Build_Set_Predefined_Prim_Op_Address (Loc,
7817 Tag_Node =>
7818 New_Reference_To (Node (Next_Elmt (Iface_DT_Elmt)), Loc),
7819 Position => Pos,
7820 Address_Node =>
7821 Unchecked_Convert_To (RTE (RE_Prim_Ptr),
7822 Make_Attribute_Reference (Loc,
7823 Prefix =>
7824 New_Reference_To (Alias (Prim), Loc),
7825 Attribute_Name => Name_Unrestricted_Access))));
7827 else
7828 pragma Assert (Pos /= Uint_0
7829 and then Pos <= DT_Entry_Count (Tag));
7831 Append_To (L,
7832 Build_Set_Prim_Op_Address (Loc,
7833 Typ => Iface_Typ,
7834 Tag_Node => New_Reference_To (Iface_DT_Ptr, Loc),
7835 Position => Pos,
7836 Address_Node =>
7837 Unchecked_Convert_To (RTE (RE_Prim_Ptr),
7838 Make_Attribute_Reference (Loc,
7839 Prefix => New_Reference_To (Thunk_Id, Loc),
7840 Attribute_Name => Name_Unrestricted_Access))));
7842 Next_Elmt (Iface_DT_Elmt);
7843 Next_Elmt (Iface_DT_Elmt);
7844 Iface_DT_Ptr := Node (Iface_DT_Elmt);
7845 pragma Assert (not Has_Thunks (Iface_DT_Ptr));
7847 Append_To (L,
7848 Build_Set_Prim_Op_Address (Loc,
7849 Typ => Iface_Typ,
7850 Tag_Node => New_Reference_To (Iface_DT_Ptr, Loc),
7851 Position => Pos,
7852 Address_Node =>
7853 Unchecked_Convert_To (RTE (RE_Prim_Ptr),
7854 Make_Attribute_Reference (Loc,
7855 Prefix =>
7856 New_Reference_To (Alias (Prim), Loc),
7857 Attribute_Name => Name_Unrestricted_Access))));
7859 end if;
7860 end if;
7861 end if;
7863 return L;
7864 end Register_Primitive;
7866 -------------------------
7867 -- Set_All_DT_Position --
7868 -------------------------
7870 procedure Set_All_DT_Position (Typ : Entity_Id) is
7872 function In_Predef_Prims_DT (Prim : Entity_Id) return Boolean;
7873 -- Returns True if Prim is located in the dispatch table of
7874 -- predefined primitives
7876 procedure Validate_Position (Prim : Entity_Id);
7877 -- Check that the position assigned to Prim is completely safe
7878 -- (it has not been assigned to a previously defined primitive
7879 -- operation of Typ)
7881 ------------------------
7882 -- In_Predef_Prims_DT --
7883 ------------------------
7885 function In_Predef_Prims_DT (Prim : Entity_Id) return Boolean is
7886 E : Entity_Id;
7888 begin
7889 -- Predefined primitives
7891 if Is_Predefined_Dispatching_Operation (Prim) then
7892 return True;
7894 -- Renamings of predefined primitives
7896 elsif Present (Alias (Prim))
7897 and then Is_Predefined_Dispatching_Operation (Ultimate_Alias (Prim))
7898 then
7899 if Chars (Ultimate_Alias (Prim)) /= Name_Op_Eq then
7900 return True;
7902 -- User-defined renamings of predefined equality have their own
7903 -- slot in the primary dispatch table
7905 else
7906 E := Prim;
7907 while Present (Alias (E)) loop
7908 if Comes_From_Source (E) then
7909 return False;
7910 end if;
7912 E := Alias (E);
7913 end loop;
7915 return not Comes_From_Source (E);
7916 end if;
7918 -- User-defined primitives
7920 else
7921 return False;
7922 end if;
7923 end In_Predef_Prims_DT;
7925 -----------------------
7926 -- Validate_Position --
7927 -----------------------
7929 procedure Validate_Position (Prim : Entity_Id) is
7930 Op_Elmt : Elmt_Id;
7931 Op : Entity_Id;
7933 begin
7934 -- Aliased primitives are safe
7936 if Present (Alias (Prim)) then
7937 return;
7938 end if;
7940 Op_Elmt := First_Elmt (Primitive_Operations (Typ));
7941 while Present (Op_Elmt) loop
7942 Op := Node (Op_Elmt);
7944 -- No need to check against itself
7946 if Op = Prim then
7947 null;
7949 -- Primitive operations covering abstract interfaces are
7950 -- allocated later
7952 elsif Present (Interface_Alias (Op)) then
7953 null;
7955 -- Predefined dispatching operations are completely safe. They
7956 -- are allocated at fixed positions in a separate table.
7958 elsif Is_Predefined_Dispatching_Operation (Op)
7959 or else Is_Predefined_Dispatching_Alias (Op)
7960 then
7961 null;
7963 -- Aliased subprograms are safe
7965 elsif Present (Alias (Op)) then
7966 null;
7968 elsif DT_Position (Op) = DT_Position (Prim)
7969 and then not Is_Predefined_Dispatching_Operation (Op)
7970 and then not Is_Predefined_Dispatching_Operation (Prim)
7971 and then not Is_Predefined_Dispatching_Alias (Op)
7972 and then not Is_Predefined_Dispatching_Alias (Prim)
7973 then
7975 -- Handle aliased subprograms
7977 declare
7978 Op_1 : Entity_Id;
7979 Op_2 : Entity_Id;
7981 begin
7982 Op_1 := Op;
7983 loop
7984 if Present (Overridden_Operation (Op_1)) then
7985 Op_1 := Overridden_Operation (Op_1);
7986 elsif Present (Alias (Op_1)) then
7987 Op_1 := Alias (Op_1);
7988 else
7989 exit;
7990 end if;
7991 end loop;
7993 Op_2 := Prim;
7994 loop
7995 if Present (Overridden_Operation (Op_2)) then
7996 Op_2 := Overridden_Operation (Op_2);
7997 elsif Present (Alias (Op_2)) then
7998 Op_2 := Alias (Op_2);
7999 else
8000 exit;
8001 end if;
8002 end loop;
8004 if Op_1 /= Op_2 then
8005 raise Program_Error;
8006 end if;
8007 end;
8008 end if;
8010 Next_Elmt (Op_Elmt);
8011 end loop;
8012 end Validate_Position;
8014 -- Local variables
8016 Parent_Typ : constant Entity_Id := Etype (Typ);
8017 First_Prim : constant Elmt_Id := First_Elmt (Primitive_Operations (Typ));
8018 The_Tag : constant Entity_Id := First_Tag_Component (Typ);
8020 Adjusted : Boolean := False;
8021 Finalized : Boolean := False;
8023 Count_Prim : Nat;
8024 DT_Length : Nat;
8025 Nb_Prim : Nat;
8026 Prim : Entity_Id;
8027 Prim_Elmt : Elmt_Id;
8029 -- Start of processing for Set_All_DT_Position
8031 begin
8032 pragma Assert (Present (First_Tag_Component (Typ)));
8034 -- Set the DT_Position for each primitive operation. Perform some sanity
8035 -- checks to avoid building inconsistent dispatch tables.
8037 -- First stage: Set the DTC entity of all the primitive operations. This
8038 -- is required to properly read the DT_Position attribute in the latter
8039 -- stages.
8041 Prim_Elmt := First_Prim;
8042 Count_Prim := 0;
8043 while Present (Prim_Elmt) loop
8044 Prim := Node (Prim_Elmt);
8046 -- Predefined primitives have a separate dispatch table
8048 if not In_Predef_Prims_DT (Prim) then
8049 Count_Prim := Count_Prim + 1;
8050 end if;
8052 Set_DTC_Entity_Value (Typ, Prim);
8054 -- Clear any previous value of the DT_Position attribute. In this
8055 -- way we ensure that the final position of all the primitives is
8056 -- established by the following stages of this algorithm.
8058 Set_DT_Position (Prim, No_Uint);
8060 Next_Elmt (Prim_Elmt);
8061 end loop;
8063 declare
8064 Fixed_Prim : array (Int range 0 .. Count_Prim) of Boolean :=
8065 (others => False);
8067 E : Entity_Id;
8069 procedure Handle_Inherited_Private_Subprograms (Typ : Entity_Id);
8070 -- Called if Typ is declared in a nested package or a public child
8071 -- package to handle inherited primitives that were inherited by Typ
8072 -- in the visible part, but whose declaration was deferred because
8073 -- the parent operation was private and not visible at that point.
8075 procedure Set_Fixed_Prim (Pos : Nat);
8076 -- Sets to true an element of the Fixed_Prim table to indicate
8077 -- that this entry of the dispatch table of Typ is occupied.
8079 ------------------------------------------
8080 -- Handle_Inherited_Private_Subprograms --
8081 ------------------------------------------
8083 procedure Handle_Inherited_Private_Subprograms (Typ : Entity_Id) is
8084 Op_List : Elist_Id;
8085 Op_Elmt : Elmt_Id;
8086 Op_Elmt_2 : Elmt_Id;
8087 Prim_Op : Entity_Id;
8088 Parent_Subp : Entity_Id;
8090 begin
8091 Op_List := Primitive_Operations (Typ);
8093 Op_Elmt := First_Elmt (Op_List);
8094 while Present (Op_Elmt) loop
8095 Prim_Op := Node (Op_Elmt);
8097 -- Search primitives that are implicit operations with an
8098 -- internal name whose parent operation has a normal name.
8100 if Present (Alias (Prim_Op))
8101 and then Find_Dispatching_Type (Alias (Prim_Op)) /= Typ
8102 and then not Comes_From_Source (Prim_Op)
8103 and then Is_Internal_Name (Chars (Prim_Op))
8104 and then not Is_Internal_Name (Chars (Alias (Prim_Op)))
8105 then
8106 Parent_Subp := Alias (Prim_Op);
8108 -- Check if the type has an explicit overriding for this
8109 -- primitive.
8111 Op_Elmt_2 := Next_Elmt (Op_Elmt);
8112 while Present (Op_Elmt_2) loop
8113 if Chars (Node (Op_Elmt_2)) = Chars (Parent_Subp)
8114 and then Type_Conformant (Prim_Op, Node (Op_Elmt_2))
8115 then
8116 Set_DT_Position (Prim_Op, DT_Position (Parent_Subp));
8117 Set_DT_Position (Node (Op_Elmt_2),
8118 DT_Position (Parent_Subp));
8119 Set_Fixed_Prim (UI_To_Int (DT_Position (Prim_Op)));
8121 goto Next_Primitive;
8122 end if;
8124 Next_Elmt (Op_Elmt_2);
8125 end loop;
8126 end if;
8128 <<Next_Primitive>>
8129 Next_Elmt (Op_Elmt);
8130 end loop;
8131 end Handle_Inherited_Private_Subprograms;
8133 --------------------
8134 -- Set_Fixed_Prim --
8135 --------------------
8137 procedure Set_Fixed_Prim (Pos : Nat) is
8138 begin
8139 pragma Assert (Pos <= Count_Prim);
8140 Fixed_Prim (Pos) := True;
8141 exception
8142 when Constraint_Error =>
8143 raise Program_Error;
8144 end Set_Fixed_Prim;
8146 begin
8147 -- In case of nested packages and public child package it may be
8148 -- necessary a special management on inherited subprograms so that
8149 -- the dispatch table is properly filled.
8151 if Ekind (Scope (Scope (Typ))) = E_Package
8152 and then Scope (Scope (Typ)) /= Standard_Standard
8153 and then ((Is_Derived_Type (Typ) and then not Is_Private_Type (Typ))
8154 or else
8155 (Nkind (Parent (Typ)) = N_Private_Extension_Declaration
8156 and then Is_Generic_Type (Typ)))
8157 and then In_Open_Scopes (Scope (Etype (Typ)))
8158 and then Is_Base_Type (Typ)
8159 then
8160 Handle_Inherited_Private_Subprograms (Typ);
8161 end if;
8163 -- Second stage: Register fixed entries
8165 Nb_Prim := 0;
8166 Prim_Elmt := First_Prim;
8167 while Present (Prim_Elmt) loop
8168 Prim := Node (Prim_Elmt);
8170 -- Predefined primitives have a separate table and all its
8171 -- entries are at predefined fixed positions.
8173 if In_Predef_Prims_DT (Prim) then
8174 if Is_Predefined_Dispatching_Operation (Prim) then
8175 Set_DT_Position (Prim, Default_Prim_Op_Position (Prim));
8177 else pragma Assert (Present (Alias (Prim)));
8178 Set_DT_Position (Prim,
8179 Default_Prim_Op_Position (Ultimate_Alias (Prim)));
8180 end if;
8182 -- Overriding primitives of ancestor abstract interfaces
8184 elsif Present (Interface_Alias (Prim))
8185 and then Is_Ancestor
8186 (Find_Dispatching_Type (Interface_Alias (Prim)), Typ,
8187 Use_Full_View => True)
8188 then
8189 pragma Assert (DT_Position (Prim) = No_Uint
8190 and then Present (DTC_Entity (Interface_Alias (Prim))));
8192 E := Interface_Alias (Prim);
8193 Set_DT_Position (Prim, DT_Position (E));
8195 pragma Assert
8196 (DT_Position (Alias (Prim)) = No_Uint
8197 or else DT_Position (Alias (Prim)) = DT_Position (E));
8198 Set_DT_Position (Alias (Prim), DT_Position (E));
8199 Set_Fixed_Prim (UI_To_Int (DT_Position (Prim)));
8201 -- Overriding primitives must use the same entry as the
8202 -- overridden primitive.
8204 elsif not Present (Interface_Alias (Prim))
8205 and then Present (Alias (Prim))
8206 and then Chars (Prim) = Chars (Alias (Prim))
8207 and then Find_Dispatching_Type (Alias (Prim)) /= Typ
8208 and then Is_Ancestor
8209 (Find_Dispatching_Type (Alias (Prim)), Typ,
8210 Use_Full_View => True)
8211 and then Present (DTC_Entity (Alias (Prim)))
8212 then
8213 E := Alias (Prim);
8214 Set_DT_Position (Prim, DT_Position (E));
8216 if not Is_Predefined_Dispatching_Alias (E) then
8217 Set_Fixed_Prim (UI_To_Int (DT_Position (E)));
8218 end if;
8219 end if;
8221 Next_Elmt (Prim_Elmt);
8222 end loop;
8224 -- Third stage: Fix the position of all the new primitives.
8225 -- Entries associated with primitives covering interfaces
8226 -- are handled in a latter round.
8228 Prim_Elmt := First_Prim;
8229 while Present (Prim_Elmt) loop
8230 Prim := Node (Prim_Elmt);
8232 -- Skip primitives previously set entries
8234 if DT_Position (Prim) /= No_Uint then
8235 null;
8237 -- Primitives covering interface primitives are handled later
8239 elsif Present (Interface_Alias (Prim)) then
8240 null;
8242 else
8243 -- Take the next available position in the DT
8245 loop
8246 Nb_Prim := Nb_Prim + 1;
8247 pragma Assert (Nb_Prim <= Count_Prim);
8248 exit when not Fixed_Prim (Nb_Prim);
8249 end loop;
8251 Set_DT_Position (Prim, UI_From_Int (Nb_Prim));
8252 Set_Fixed_Prim (Nb_Prim);
8253 end if;
8255 Next_Elmt (Prim_Elmt);
8256 end loop;
8257 end;
8259 -- Fourth stage: Complete the decoration of primitives covering
8260 -- interfaces (that is, propagate the DT_Position attribute
8261 -- from the aliased primitive)
8263 Prim_Elmt := First_Prim;
8264 while Present (Prim_Elmt) loop
8265 Prim := Node (Prim_Elmt);
8267 if DT_Position (Prim) = No_Uint
8268 and then Present (Interface_Alias (Prim))
8269 then
8270 pragma Assert (Present (Alias (Prim))
8271 and then Find_Dispatching_Type (Alias (Prim)) = Typ);
8273 -- Check if this entry will be placed in the primary DT
8275 if Is_Ancestor
8276 (Find_Dispatching_Type (Interface_Alias (Prim)), Typ,
8277 Use_Full_View => True)
8278 then
8279 pragma Assert (DT_Position (Alias (Prim)) /= No_Uint);
8280 Set_DT_Position (Prim, DT_Position (Alias (Prim)));
8282 -- Otherwise it will be placed in the secondary DT
8284 else
8285 pragma Assert
8286 (DT_Position (Interface_Alias (Prim)) /= No_Uint);
8287 Set_DT_Position (Prim,
8288 DT_Position (Interface_Alias (Prim)));
8289 end if;
8290 end if;
8292 Next_Elmt (Prim_Elmt);
8293 end loop;
8295 -- Generate listing showing the contents of the dispatch tables.
8296 -- This action is done before some further static checks because
8297 -- in case of critical errors caused by a wrong dispatch table
8298 -- we need to see the contents of such table.
8300 if Debug_Flag_ZZ then
8301 Write_DT (Typ);
8302 end if;
8304 -- Final stage: Ensure that the table is correct plus some further
8305 -- verifications concerning the primitives.
8307 Prim_Elmt := First_Prim;
8308 DT_Length := 0;
8309 while Present (Prim_Elmt) loop
8310 Prim := Node (Prim_Elmt);
8312 -- At this point all the primitives MUST have a position
8313 -- in the dispatch table.
8315 if DT_Position (Prim) = No_Uint then
8316 raise Program_Error;
8317 end if;
8319 -- Calculate real size of the dispatch table
8321 if not In_Predef_Prims_DT (Prim)
8322 and then UI_To_Int (DT_Position (Prim)) > DT_Length
8323 then
8324 DT_Length := UI_To_Int (DT_Position (Prim));
8325 end if;
8327 -- Ensure that the assigned position to non-predefined
8328 -- dispatching operations in the dispatch table is correct.
8330 if not Is_Predefined_Dispatching_Operation (Prim)
8331 and then not Is_Predefined_Dispatching_Alias (Prim)
8332 then
8333 Validate_Position (Prim);
8334 end if;
8336 if Chars (Prim) = Name_Finalize then
8337 Finalized := True;
8338 end if;
8340 if Chars (Prim) = Name_Adjust then
8341 Adjusted := True;
8342 end if;
8344 -- An abstract operation cannot be declared in the private part for a
8345 -- visible abstract type, because it can't be overridden outside this
8346 -- package hierarchy. For explicit declarations this is checked at
8347 -- the point of declaration, but for inherited operations it must be
8348 -- done when building the dispatch table.
8350 -- Ada 2005 (AI-251): Primitives associated with interfaces are
8351 -- excluded from this check because interfaces must be visible in
8352 -- the public and private part (RM 7.3 (7.3/2))
8354 -- We disable this check in CodePeer mode, to accommodate legacy
8355 -- Ada code.
8357 if not CodePeer_Mode
8358 and then Is_Abstract_Type (Typ)
8359 and then Is_Abstract_Subprogram (Prim)
8360 and then Present (Alias (Prim))
8361 and then not Is_Interface
8362 (Find_Dispatching_Type (Ultimate_Alias (Prim)))
8363 and then not Present (Interface_Alias (Prim))
8364 and then Is_Derived_Type (Typ)
8365 and then In_Private_Part (Current_Scope)
8366 and then
8367 List_Containing (Parent (Prim)) =
8368 Private_Declarations
8369 (Specification (Unit_Declaration_Node (Current_Scope)))
8370 and then Original_View_In_Visible_Part (Typ)
8371 then
8372 -- We exclude Input and Output stream operations because
8373 -- Limited_Controlled inherits useless Input and Output
8374 -- stream operations from Root_Controlled, which can
8375 -- never be overridden.
8377 if not Is_TSS (Prim, TSS_Stream_Input)
8378 and then
8379 not Is_TSS (Prim, TSS_Stream_Output)
8380 then
8381 Error_Msg_NE
8382 ("abstract inherited private operation&" &
8383 " must be overridden (RM 3.9.3(10))",
8384 Parent (Typ), Prim);
8385 end if;
8386 end if;
8388 Next_Elmt (Prim_Elmt);
8389 end loop;
8391 -- Additional check
8393 if Is_Controlled (Typ) then
8394 if not Finalized then
8395 Error_Msg_N
8396 ("controlled type has no explicit Finalize method?", Typ);
8398 elsif not Adjusted then
8399 Error_Msg_N
8400 ("controlled type has no explicit Adjust method?", Typ);
8401 end if;
8402 end if;
8404 -- Set the final size of the Dispatch Table
8406 Set_DT_Entry_Count (The_Tag, UI_From_Int (DT_Length));
8408 -- The derived type must have at least as many components as its parent
8409 -- (for root types Etype points to itself and the test cannot fail).
8411 if DT_Entry_Count (The_Tag) <
8412 DT_Entry_Count (First_Tag_Component (Parent_Typ))
8413 then
8414 raise Program_Error;
8415 end if;
8416 end Set_All_DT_Position;
8418 --------------------------
8419 -- Set_CPP_Constructors --
8420 --------------------------
8422 procedure Set_CPP_Constructors (Typ : Entity_Id) is
8424 procedure Set_CPP_Constructors_Old (Typ : Entity_Id);
8425 -- For backward compatibility this routine handles CPP constructors
8426 -- of non-tagged types.
8428 procedure Set_CPP_Constructors_Old (Typ : Entity_Id) is
8429 Loc : Source_Ptr;
8430 Init : Entity_Id;
8431 E : Entity_Id;
8432 Found : Boolean := False;
8433 P : Node_Id;
8434 Parms : List_Id;
8436 begin
8437 -- Look for the constructor entities
8439 E := Next_Entity (Typ);
8440 while Present (E) loop
8441 if Ekind (E) = E_Function
8442 and then Is_Constructor (E)
8443 then
8444 -- Create the init procedure
8446 Found := True;
8447 Loc := Sloc (E);
8448 Init := Make_Defining_Identifier (Loc,
8449 Make_Init_Proc_Name (Typ));
8450 Parms :=
8451 New_List (
8452 Make_Parameter_Specification (Loc,
8453 Defining_Identifier =>
8454 Make_Defining_Identifier (Loc, Name_X),
8455 Parameter_Type =>
8456 New_Reference_To (Typ, Loc)));
8458 if Present (Parameter_Specifications (Parent (E))) then
8459 P := First (Parameter_Specifications (Parent (E)));
8460 while Present (P) loop
8461 Append_To (Parms,
8462 Make_Parameter_Specification (Loc,
8463 Defining_Identifier =>
8464 Make_Defining_Identifier (Loc,
8465 Chars (Defining_Identifier (P))),
8466 Parameter_Type =>
8467 New_Copy_Tree (Parameter_Type (P))));
8468 Next (P);
8469 end loop;
8470 end if;
8472 Discard_Node (
8473 Make_Subprogram_Declaration (Loc,
8474 Make_Procedure_Specification (Loc,
8475 Defining_Unit_Name => Init,
8476 Parameter_Specifications => Parms)));
8478 Set_Init_Proc (Typ, Init);
8479 Set_Is_Imported (Init);
8480 Set_Is_Constructor (Init);
8481 Set_Interface_Name (Init, Interface_Name (E));
8482 Set_Convention (Init, Convention_CPP);
8483 Set_Is_Public (Init);
8484 Set_Has_Completion (Init);
8485 end if;
8487 Next_Entity (E);
8488 end loop;
8490 -- If there are no constructors, mark the type as abstract since we
8491 -- won't be able to declare objects of that type.
8493 if not Found then
8494 Set_Is_Abstract_Type (Typ);
8495 end if;
8496 end Set_CPP_Constructors_Old;
8498 -- Local variables
8500 Loc : Source_Ptr;
8501 E : Entity_Id;
8502 Found : Boolean := False;
8503 P : Node_Id;
8504 Parms : List_Id;
8506 Constructor_Decl_Node : Node_Id;
8507 Constructor_Id : Entity_Id;
8508 Wrapper_Id : Entity_Id;
8509 Wrapper_Body_Node : Node_Id;
8510 Actuals : List_Id;
8511 Body_Stmts : List_Id;
8512 Init_Tags_List : List_Id;
8514 begin
8515 pragma Assert (Is_CPP_Class (Typ));
8517 -- For backward compatibility the compiler accepts C++ classes
8518 -- imported through non-tagged record types. In such case the
8519 -- wrapper of the C++ constructor is useless because the _tag
8520 -- component is not available.
8522 -- Example:
8523 -- type Root is limited record ...
8524 -- pragma Import (CPP, Root);
8525 -- function New_Root return Root;
8526 -- pragma CPP_Constructor (New_Root, ... );
8528 if not Is_Tagged_Type (Typ) then
8529 Set_CPP_Constructors_Old (Typ);
8530 return;
8531 end if;
8533 -- Look for the constructor entities
8535 E := Next_Entity (Typ);
8536 while Present (E) loop
8537 if Ekind (E) = E_Function
8538 and then Is_Constructor (E)
8539 then
8540 Found := True;
8541 Loc := Sloc (E);
8543 -- Generate the declaration of the imported C++ constructor
8545 Parms :=
8546 New_List (
8547 Make_Parameter_Specification (Loc,
8548 Defining_Identifier =>
8549 Make_Defining_Identifier (Loc, Name_uInit),
8550 Parameter_Type =>
8551 New_Reference_To (Typ, Loc)));
8553 if Present (Parameter_Specifications (Parent (E))) then
8554 P := First (Parameter_Specifications (Parent (E)));
8555 while Present (P) loop
8556 Append_To (Parms,
8557 Make_Parameter_Specification (Loc,
8558 Defining_Identifier =>
8559 Make_Defining_Identifier (Loc,
8560 Chars (Defining_Identifier (P))),
8561 Parameter_Type => New_Copy_Tree (Parameter_Type (P))));
8562 Next (P);
8563 end loop;
8564 end if;
8566 Constructor_Id := Make_Temporary (Loc, 'P');
8568 Constructor_Decl_Node :=
8569 Make_Subprogram_Declaration (Loc,
8570 Make_Procedure_Specification (Loc,
8571 Defining_Unit_Name => Constructor_Id,
8572 Parameter_Specifications => Parms));
8574 Set_Is_Imported (Constructor_Id);
8575 Set_Is_Constructor (Constructor_Id);
8576 Set_Interface_Name (Constructor_Id, Interface_Name (E));
8577 Set_Convention (Constructor_Id, Convention_CPP);
8578 Set_Is_Public (Constructor_Id);
8579 Set_Has_Completion (Constructor_Id);
8581 -- Build the wrapper of this constructor
8583 Parms :=
8584 New_List (
8585 Make_Parameter_Specification (Loc,
8586 Defining_Identifier =>
8587 Make_Defining_Identifier (Loc, Name_uInit),
8588 Parameter_Type =>
8589 New_Reference_To (Typ, Loc)));
8591 if Present (Parameter_Specifications (Parent (E))) then
8592 P := First (Parameter_Specifications (Parent (E)));
8593 while Present (P) loop
8594 Append_To (Parms,
8595 Make_Parameter_Specification (Loc,
8596 Defining_Identifier =>
8597 Make_Defining_Identifier (Loc,
8598 Chars (Defining_Identifier (P))),
8599 Parameter_Type => New_Copy_Tree (Parameter_Type (P))));
8600 Next (P);
8601 end loop;
8602 end if;
8604 Body_Stmts := New_List;
8606 -- Invoke the C++ constructor
8608 Actuals := New_List;
8610 P := First (Parms);
8611 while Present (P) loop
8612 Append_To (Actuals,
8613 New_Reference_To (Defining_Identifier (P), Loc));
8614 Next (P);
8615 end loop;
8617 Append_To (Body_Stmts,
8618 Make_Procedure_Call_Statement (Loc,
8619 Name => New_Reference_To (Constructor_Id, Loc),
8620 Parameter_Associations => Actuals));
8622 -- Initialize copies of C++ primary and secondary tags
8624 Init_Tags_List := New_List;
8626 declare
8627 Tag_Elmt : Elmt_Id;
8628 Tag_Comp : Node_Id;
8630 begin
8631 Tag_Elmt := First_Elmt (Access_Disp_Table (Typ));
8632 Tag_Comp := First_Tag_Component (Typ);
8634 while Present (Tag_Elmt)
8635 and then Is_Tag (Node (Tag_Elmt))
8636 loop
8637 -- Skip the following assertion with primary tags because
8638 -- Related_Type is not set on primary tag components
8640 pragma Assert (Tag_Comp = First_Tag_Component (Typ)
8641 or else Related_Type (Node (Tag_Elmt))
8642 = Related_Type (Tag_Comp));
8644 Append_To (Init_Tags_List,
8645 Make_Assignment_Statement (Loc,
8646 Name =>
8647 New_Reference_To (Node (Tag_Elmt), Loc),
8648 Expression =>
8649 Make_Selected_Component (Loc,
8650 Prefix =>
8651 Make_Identifier (Loc, Name_uInit),
8652 Selector_Name =>
8653 New_Reference_To (Tag_Comp, Loc))));
8655 Tag_Comp := Next_Tag_Component (Tag_Comp);
8656 Next_Elmt (Tag_Elmt);
8657 end loop;
8658 end;
8660 Append_To (Body_Stmts,
8661 Make_If_Statement (Loc,
8662 Condition =>
8663 Make_Op_Eq (Loc,
8664 Left_Opnd =>
8665 New_Reference_To
8666 (Node (First_Elmt (Access_Disp_Table (Typ))),
8667 Loc),
8668 Right_Opnd =>
8669 Unchecked_Convert_To (RTE (RE_Tag),
8670 New_Reference_To (RTE (RE_Null_Address), Loc))),
8671 Then_Statements => Init_Tags_List));
8673 Wrapper_Id := Make_Defining_Identifier (Loc,
8674 Make_Init_Proc_Name (Typ));
8676 Wrapper_Body_Node :=
8677 Make_Subprogram_Body (Loc,
8678 Specification =>
8679 Make_Procedure_Specification (Loc,
8680 Defining_Unit_Name => Wrapper_Id,
8681 Parameter_Specifications => Parms),
8682 Declarations => New_List (Constructor_Decl_Node),
8683 Handled_Statement_Sequence =>
8684 Make_Handled_Sequence_Of_Statements (Loc,
8685 Statements => Body_Stmts,
8686 Exception_Handlers => No_List));
8688 Discard_Node (Wrapper_Body_Node);
8689 Set_Init_Proc (Typ, Wrapper_Id);
8690 end if;
8692 Next_Entity (E);
8693 end loop;
8695 -- If there are no constructors, mark the type as abstract since we
8696 -- won't be able to declare objects of that type.
8698 if not Found then
8699 Set_Is_Abstract_Type (Typ);
8700 end if;
8702 -- If the CPP type has constructors then it must import also the default
8703 -- C++ constructor. It is required for default initialization of objects
8704 -- of the type. It is also required to elaborate objects of Ada types
8705 -- that are defined as derivations of this CPP type.
8707 if Has_CPP_Constructors (Typ)
8708 and then No (Init_Proc (Typ))
8709 then
8710 Error_Msg_N ("?default constructor must be imported from C++", Typ);
8711 end if;
8712 end Set_CPP_Constructors;
8714 --------------------------
8715 -- Set_DTC_Entity_Value --
8716 --------------------------
8718 procedure Set_DTC_Entity_Value
8719 (Tagged_Type : Entity_Id;
8720 Prim : Entity_Id)
8722 begin
8723 if Present (Interface_Alias (Prim))
8724 and then Is_Interface
8725 (Find_Dispatching_Type (Interface_Alias (Prim)))
8726 then
8727 Set_DTC_Entity (Prim,
8728 Find_Interface_Tag
8729 (T => Tagged_Type,
8730 Iface => Find_Dispatching_Type (Interface_Alias (Prim))));
8731 else
8732 Set_DTC_Entity (Prim,
8733 First_Tag_Component (Tagged_Type));
8734 end if;
8735 end Set_DTC_Entity_Value;
8737 -----------------
8738 -- Tagged_Kind --
8739 -----------------
8741 function Tagged_Kind (T : Entity_Id) return Node_Id is
8742 Conc_Typ : Entity_Id;
8743 Loc : constant Source_Ptr := Sloc (T);
8745 begin
8746 pragma Assert
8747 (Is_Tagged_Type (T) and then RTE_Available (RE_Tagged_Kind));
8749 -- Abstract kinds
8751 if Is_Abstract_Type (T) then
8752 if Is_Limited_Record (T) then
8753 return New_Reference_To (RTE (RE_TK_Abstract_Limited_Tagged), Loc);
8754 else
8755 return New_Reference_To (RTE (RE_TK_Abstract_Tagged), Loc);
8756 end if;
8758 -- Concurrent kinds
8760 elsif Is_Concurrent_Record_Type (T) then
8761 Conc_Typ := Corresponding_Concurrent_Type (T);
8763 if Present (Full_View (Conc_Typ)) then
8764 Conc_Typ := Full_View (Conc_Typ);
8765 end if;
8767 if Ekind (Conc_Typ) = E_Protected_Type then
8768 return New_Reference_To (RTE (RE_TK_Protected), Loc);
8769 else
8770 pragma Assert (Ekind (Conc_Typ) = E_Task_Type);
8771 return New_Reference_To (RTE (RE_TK_Task), Loc);
8772 end if;
8774 -- Regular tagged kinds
8776 else
8777 if Is_Limited_Record (T) then
8778 return New_Reference_To (RTE (RE_TK_Limited_Tagged), Loc);
8779 else
8780 return New_Reference_To (RTE (RE_TK_Tagged), Loc);
8781 end if;
8782 end if;
8783 end Tagged_Kind;
8785 --------------
8786 -- Write_DT --
8787 --------------
8789 procedure Write_DT (Typ : Entity_Id) is
8790 Elmt : Elmt_Id;
8791 Prim : Node_Id;
8793 begin
8794 -- Protect this procedure against wrong usage. Required because it will
8795 -- be used directly from GDB
8797 if not (Typ <= Last_Node_Id)
8798 or else not Is_Tagged_Type (Typ)
8799 then
8800 Write_Str ("wrong usage: Write_DT must be used with tagged types");
8801 Write_Eol;
8802 return;
8803 end if;
8805 Write_Int (Int (Typ));
8806 Write_Str (": ");
8807 Write_Name (Chars (Typ));
8809 if Is_Interface (Typ) then
8810 Write_Str (" is interface");
8811 end if;
8813 Write_Eol;
8815 Elmt := First_Elmt (Primitive_Operations (Typ));
8816 while Present (Elmt) loop
8817 Prim := Node (Elmt);
8818 Write_Str (" - ");
8820 -- Indicate if this primitive will be allocated in the primary
8821 -- dispatch table or in a secondary dispatch table associated
8822 -- with an abstract interface type
8824 if Present (DTC_Entity (Prim)) then
8825 if Etype (DTC_Entity (Prim)) = RTE (RE_Tag) then
8826 Write_Str ("[P] ");
8827 else
8828 Write_Str ("[s] ");
8829 end if;
8830 end if;
8832 -- Output the node of this primitive operation and its name
8834 Write_Int (Int (Prim));
8835 Write_Str (": ");
8837 if Is_Predefined_Dispatching_Operation (Prim) then
8838 Write_Str ("(predefined) ");
8839 end if;
8841 -- Prefix the name of the primitive with its corresponding tagged
8842 -- type to facilitate seeing inherited primitives.
8844 if Present (Alias (Prim)) then
8845 Write_Name
8846 (Chars (Find_Dispatching_Type (Ultimate_Alias (Prim))));
8847 else
8848 Write_Name (Chars (Typ));
8849 end if;
8851 Write_Str (".");
8852 Write_Name (Chars (Prim));
8854 -- Indicate if this primitive has an aliased primitive
8856 if Present (Alias (Prim)) then
8857 Write_Str (" (alias = ");
8858 Write_Int (Int (Alias (Prim)));
8860 -- If the DTC_Entity attribute is already set we can also output
8861 -- the name of the interface covered by this primitive (if any).
8863 if Ekind_In (Alias (Prim), E_Function, E_Procedure)
8864 and then Present (DTC_Entity (Alias (Prim)))
8865 and then Is_Interface (Scope (DTC_Entity (Alias (Prim))))
8866 then
8867 Write_Str (" from interface ");
8868 Write_Name (Chars (Scope (DTC_Entity (Alias (Prim)))));
8869 end if;
8871 if Present (Interface_Alias (Prim)) then
8872 Write_Str (", AI_Alias of ");
8874 if Is_Null_Interface_Primitive (Interface_Alias (Prim)) then
8875 Write_Str ("null primitive ");
8876 end if;
8878 Write_Name
8879 (Chars (Find_Dispatching_Type (Interface_Alias (Prim))));
8880 Write_Char (':');
8881 Write_Int (Int (Interface_Alias (Prim)));
8882 end if;
8884 Write_Str (")");
8885 end if;
8887 -- Display the final position of this primitive in its associated
8888 -- (primary or secondary) dispatch table
8890 if Present (DTC_Entity (Prim))
8891 and then DT_Position (Prim) /= No_Uint
8892 then
8893 Write_Str (" at #");
8894 Write_Int (UI_To_Int (DT_Position (Prim)));
8895 end if;
8897 if Is_Abstract_Subprogram (Prim) then
8898 Write_Str (" is abstract;");
8900 -- Check if this is a null primitive
8902 elsif Comes_From_Source (Prim)
8903 and then Ekind (Prim) = E_Procedure
8904 and then Null_Present (Parent (Prim))
8905 then
8906 Write_Str (" is null;");
8907 end if;
8909 if Is_Eliminated (Ultimate_Alias (Prim)) then
8910 Write_Str (" (eliminated)");
8911 end if;
8913 if Is_Imported (Prim)
8914 and then Convention (Prim) = Convention_CPP
8915 then
8916 Write_Str (" (C++)");
8917 end if;
8919 Write_Eol;
8921 Next_Elmt (Elmt);
8922 end loop;
8923 end Write_DT;
8925 end Exp_Disp;