]> git.ipfire.org Git - thirdparty/gcc.git/blame - gcc/ada/exp_disp.adb
2012-07-09 Robert Dewar <dewar@adacore.com>
[thirdparty/gcc.git] / gcc / ada / exp_disp.adb
CommitLineData
ee6ba406 1------------------------------------------------------------------------------
2-- --
3-- GNAT COMPILER COMPONENTS --
4-- --
5-- E X P _ D I S P --
6-- --
7-- B o d y --
8-- --
bb5dfacc 9-- Copyright (C) 1992-2012, Free Software Foundation, Inc. --
ee6ba406 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- --
24971415 13-- ware Foundation; either version 3, or (at your option) any later ver- --
ee6ba406 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 --
24971415 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. --
ee6ba406 20-- --
21-- GNAT was originally developed by the GNAT team at New York University. --
e78e8c8e 22-- Extensive contributions were provided by Ada Core Technologies Inc. --
ee6ba406 23-- --
24------------------------------------------------------------------------------
25
26with Atree; use Atree;
27with Checks; use Checks;
aad6babd 28with Debug; use Debug;
ee6ba406 29with Einfo; use Einfo;
30with Elists; use Elists;
31with Errout; use Errout;
343d35dc 32with Exp_Atag; use Exp_Atag;
8a8d9086 33with Exp_Ch6; use Exp_Ch6;
e00e091c 34with Exp_CG; use Exp_CG;
76a1c25b 35with Exp_Dbug; use Exp_Dbug;
ee6ba406 36with Exp_Tss; use Exp_Tss;
37with Exp_Util; use Exp_Util;
af647dc7 38with Freeze; use Freeze;
ee6ba406 39with Itypes; use Itypes;
b6b96867 40with Layout; use Layout;
ee6ba406 41with Nlists; use Nlists;
42with Nmake; use Nmake;
aad6babd 43with Namet; use Namet;
ee6ba406 44with Opt; use Opt;
aad6babd 45with Output; use Output;
68f95949 46with Restrict; use Restrict;
47with Rident; use Rident;
ee6ba406 48with Rtsfind; use Rtsfind;
aad6babd 49with Sem; use Sem;
d60c9ff7 50with Sem_Aux; use Sem_Aux;
725a69d2 51with Sem_Ch6; use Sem_Ch6;
acf97c11 52with Sem_Ch7; use Sem_Ch7;
725a69d2 53with Sem_Ch8; use Sem_Ch8;
ee6ba406 54with Sem_Disp; use Sem_Disp;
725a69d2 55with Sem_Eval; use Sem_Eval;
ee6ba406 56with Sem_Res; use Sem_Res;
aad6babd 57with Sem_Type; use Sem_Type;
ee6ba406 58with Sem_Util; use Sem_Util;
59with Sinfo; use Sinfo;
60with Snames; use Snames;
61with Stand; use Stand;
725a69d2 62with Stringt; use Stringt;
5a44b136 63with SCIL_LL; use SCIL_LL;
79500ea0 64with Targparm; use Targparm;
ee6ba406 65with Tbuild; use Tbuild;
66with Uintp; use Uintp;
67
68package body Exp_Disp is
69
725a69d2 70 -----------------------
71 -- Local Subprograms --
72 -----------------------
ee6ba406 73
68f95949 74 function Default_Prim_Op_Position (E : Entity_Id) return Uint;
aad6babd 75 -- Ada 2005 (AI-251): Returns the fixed position in the dispatch table
76 -- of the default primitive operations.
77
bb5dfacc 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
ad6b44d8 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 ???
bb5dfacc 83
24971415 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
87
af647dc7 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
36b938a3 90 -- an alias of a predefined dispatching primitive (i.e. through a renaming)
af647dc7 91
cd534f03 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.
96
ee6ba406 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.
100
d62940bf 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
952af0b9 105 -- according to its type Typ. Return a reference to an RE_Prim_Op_Kind
d62940bf 106 -- enumeration value.
aad6babd 107
952af0b9 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.
111
cd534f03 112 ----------------------
113 -- Apply_Tag_Checks --
114 ----------------------
115
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);
121
122 Subp : Entity_Id;
123 CW_Typ : Entity_Id;
124 Param : Node_Id;
125 Typ : Entity_Id;
126 Eq_Prim_Op : Entity_Id := Empty;
127
128 begin
129 if No_Run_Time_Mode then
130 Error_Msg_CRT ("tagged types", Call_Node);
131 return;
132 end if;
133
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.
139
140 if not Expander_Active
141 or else Restriction_Active (No_Dispatching_Calls)
142 then
143 return;
144 end if;
145
146 -- Set subprogram. If this is an inherited operation that was
147 -- overridden, the body that is being called is its alias.
148
149 Subp := Entity (Name (Call_Node));
150
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;
157
158 -- Definition of the class-wide type and the tagged type
159
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).
168
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));
174
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).
179
180 elsif Is_Access_Type (Ctrl_Typ) then
181 CW_Typ := Class_Wide_Type (Designated_Type (Ctrl_Typ));
182
183 else
184 CW_Typ := Class_Wide_Type (Ctrl_Typ);
185 end if;
186
bb5dfacc 187 Typ := Find_Specific_Type (CW_Typ);
cd534f03 188
189 if not Is_Limited_Type (Typ) then
190 Eq_Prim_Op := Find_Prim_Op (Typ, Name_Op_Eq);
191 end if;
192
193 -- Dispatching call to C++ primitive
194
195 if Is_CPP_Class (Typ) then
196 null;
197
198 -- Dispatching call to Ada primitive
199
200 elsif Present (Param_List) then
201
202 -- Generate the Tag checks when appropriate
203
204 Param := First_Actual (Call_Node);
205 while Present (Param) loop
206
207 -- No tag check with itself
208
209 if Param = Ctrl_Arg then
210 null;
211
212 -- No tag check for parameter whose type is neither tagged nor
213 -- access to tagged (for access parameters)
214
215 elsif No (Find_Controlling_Arg (Param)) then
216 null;
217
218 -- No tag check for function dispatching on result if the
219 -- Tag given by the context is this one
220
221 elsif Find_Controlling_Arg (Param) = Ctrl_Arg then
222 null;
223
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.
229
230 elsif Subp = Eq_Prim_Op then
231 null;
232
233 -- No check in presence of suppress flags
234
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;
241
242 -- Optimization: no tag checks if the parameters are identical
243
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;
249
250 -- Now we need to generate the Tag check
251
252 else
253 -- Generate code for tag equality check
254 -- Perhaps should have Checks.Apply_Tag_Equality_Check???
255
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)),
266
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))),
274
275 Then_Statements =>
276 New_List (New_Constraint_Error (Loc))));
277 end if;
278
279 Next_Actual (Param);
280 end loop;
281 end if;
282 end Apply_Tag_Checks;
283
24971415 284 ------------------------
285 -- Building_Static_DT --
286 ------------------------
287
288 function Building_Static_DT (Typ : Entity_Id) return Boolean is
cc60bd16 289 Root_Typ : Entity_Id := Root_Type (Typ);
290
24971415 291 begin
cc60bd16 292 -- Handle private types
293
294 if Present (Full_View (Root_Typ)) then
295 Root_Typ := Full_View (Root_Typ);
296 end if;
297
24971415 298 return Static_Dispatch_Tables
e7e688dd 299 and then Is_Library_Level_Tagged_Type (Typ)
79500ea0 300 and then VM_Target = No_VM
e7e688dd 301
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.
305
cc60bd16 306 and then not Is_CPP_Class (Root_Typ);
24971415 307 end Building_Static_DT;
308
17e14451 309 ----------------------------------
310 -- Build_Static_Dispatch_Tables --
311 ----------------------------------
312
313 procedure Build_Static_Dispatch_Tables (N : Entity_Id) is
314 Target_List : List_Id;
315
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
319
320 procedure Build_Package_Dispatch_Tables (N : Node_Id);
321 -- Build static dispatch tables associated with package declaration N
322
323 ---------------------------
324 -- Build_Dispatch_Tables --
325 ---------------------------
326
327 procedure Build_Dispatch_Tables (List : List_Id) is
328 D : Node_Id;
329
330 begin
331 D := First (List);
332 while Present (D) loop
333
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.
337
338 if Nkind (D) = N_Package_Declaration then
339 Build_Package_Dispatch_Tables (D);
340
341 elsif Nkind (D) = N_Package_Body then
342 Build_Dispatch_Tables (Declarations (D));
343
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)))));
349
350 -- Handle full type declarations and derivations of library
351 -- level tagged types
352
3164ed99 353 elsif Nkind_In (D, N_Full_Type_Declaration,
354 N_Derived_Type_Definition)
17e14451 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
442049cc 359 -- We do not generate dispatch tables for the internal types
d9fac90e 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.
363
442049cc 364 if Is_Underlying_Record_View (Defining_Entity (D))
365 or else
366 (not Comes_From_Source (Defining_Entity (D))
367 and then
2f29393f 368 Has_Unknown_Discriminants (Etype (Defining_Entity (D)))
442049cc 369 and then
2f29393f 370 not Comes_From_Source
371 (First_Subtype (Defining_Entity (D))))
d9fac90e 372 then
373 null;
d9fac90e 374 else
375 Insert_List_After_And_Analyze (Last (Target_List),
376 Make_DT (Defining_Entity (D)));
377 end if;
17e14451 378
379 -- Handle private types of library level tagged types. We must
380 -- exchange the private and full-view to ensure the correct
a735d663 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.
17e14451 384
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)))
17e14451 388 then
389 declare
acf97c11 390 E1 : constant Entity_Id := Defining_Entity (D);
a735d663 391 E2 : constant Entity_Id := Full_View (E1);
acf97c11 392
17e14451 393 begin
a735d663 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;
17e14451 403 end;
404 end if;
405
406 Next (D);
407 end loop;
408 end Build_Dispatch_Tables;
409
410 -----------------------------------
411 -- Build_Package_Dispatch_Tables --
412 -----------------------------------
413
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);
419
420 begin
421 Push_Scope (Id);
422
423 if Present (Priv_Decls) then
424 Build_Dispatch_Tables (Vis_Decls);
425 Build_Dispatch_Tables (Priv_Decls);
426
427 elsif Present (Vis_Decls) then
428 Build_Dispatch_Tables (Vis_Decls);
429 end if;
430
431 Pop_Scope;
432 end Build_Package_Dispatch_Tables;
433
434 -- Start of processing for Build_Static_Dispatch_Tables
435
436 begin
437 if not Expander_Active
662256db 438 or else not Tagged_Type_Expansion
17e14451 439 then
440 return;
441 end if;
442
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);
448
449 begin
450 if Present (Priv_Decls)
451 and then Is_Non_Empty_List (Priv_Decls)
452 then
453 Target_List := Priv_Decls;
454
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;
461
462 Build_Package_Dispatch_Tables (N);
463 end;
464
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;
470
f235fede 471 ------------------------------
472 -- Convert_Tag_To_Interface --
473 ------------------------------
474
475 function Convert_Tag_To_Interface
476 (Typ : Entity_Id;
477 Expr : Node_Id) return Node_Id
478 is
479 Loc : constant Source_Ptr := Sloc (Expr);
480 Anon_Type : Entity_Id;
481 Result : Node_Id;
482
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
4c58ddd7 488 and then Is_Tag (Entity (Selector_Name (Expr))))
f235fede 489 or else
490 (Nkind (Expr) = N_Function_Call
4c58ddd7 491 and then RTE_Available (RE_Displace)
492 and then Entity (Name (Expr)) = RTE (RE_Displace))));
f235fede 493
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);
498
499 -- Decorate the size and alignment attributes of the anonymous access
500 -- type, as required by gigi.
501
502 Layout_Type (Anon_Type);
503
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;
518
519 return Result;
520 end Convert_Tag_To_Interface;
521
d00681a7 522 -------------------
523 -- CPP_Num_Prims --
524 -------------------
525
526 function CPP_Num_Prims (Typ : Entity_Id) return Nat is
527 CPP_Typ : Entity_Id;
528 Tag_Comp : Entity_Id;
529
530 begin
531 if not Is_Tagged_Type (Typ)
532 or else not Is_CPP_Class (Root_Type (Typ))
533 then
534 return 0;
535
536 else
537 CPP_Typ := Enclosing_CPP_Parent (Typ);
538 Tag_Comp := First_Tag_Component (CPP_Typ);
539
540 -- If the number of primitives is already set in the tag component
541 -- then use it
542
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));
547
548 -- Otherwise, count the primitives of the enclosing CPP type
549
550 else
551 declare
552 Count : Nat := 0;
553 Elmt : Elmt_Id;
554
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;
561
562 return Count;
563 end;
564 end if;
565 end if;
566 end CPP_Num_Prims;
567
aad6babd 568 ------------------------------
569 -- Default_Prim_Op_Position --
570 ------------------------------
571
68f95949 572 function Default_Prim_Op_Position (E : Entity_Id) return Uint is
aad6babd 573 TSS_Name : TSS_Name_Type;
aad6babd 574
575 begin
aad6babd 576 Get_Name_String (Chars (E));
577 TSS_Name :=
578 TSS_Name_Type
579 (Name_Buffer (Name_Len - TSS_Name'Length + 1 .. Name_Len));
580
581 if Chars (E) = Name_uSize then
582 return Uint_1;
583
aad6babd 584 elsif TSS_Name = TSS_Stream_Read then
208fd589 585 return Uint_2;
aad6babd 586
587 elsif TSS_Name = TSS_Stream_Write then
208fd589 588 return Uint_3;
aad6babd 589
590 elsif TSS_Name = TSS_Stream_Input then
208fd589 591 return Uint_4;
aad6babd 592
593 elsif TSS_Name = TSS_Stream_Output then
208fd589 594 return Uint_5;
aad6babd 595
596 elsif Chars (E) = Name_Op_Eq then
208fd589 597 return Uint_6;
aad6babd 598
599 elsif Chars (E) = Name_uAssign then
208fd589 600 return Uint_7;
aad6babd 601
602 elsif TSS_Name = TSS_Deep_Adjust then
208fd589 603 return Uint_8;
aad6babd 604
605 elsif TSS_Name = TSS_Deep_Finalize then
208fd589 606 return Uint_9;
aad6babd 607
6cb4b973 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.
611
612 elsif Ada_Version >= Ada_2005 or else not Tagged_Type_Expansion then
76a1c25b 613 if Chars (E) = Name_uDisp_Asynchronous_Select then
208fd589 614 return Uint_10;
d62940bf 615
76a1c25b 616 elsif Chars (E) = Name_uDisp_Conditional_Select then
208fd589 617 return Uint_11;
d62940bf 618
76a1c25b 619 elsif Chars (E) = Name_uDisp_Get_Prim_Op_Kind then
208fd589 620 return Uint_12;
d62940bf 621
76a1c25b 622 elsif Chars (E) = Name_uDisp_Get_Task_Id then
208fd589 623 return Uint_13;
d62940bf 624
cdb1c38f 625 elsif Chars (E) = Name_uDisp_Requeue then
208fd589 626 return Uint_14;
cdb1c38f 627
628 elsif Chars (E) = Name_uDisp_Timed_Select then
208fd589 629 return Uint_15;
76a1c25b 630 end if;
aad6babd 631 end if;
76a1c25b 632
633 raise Program_Error;
aad6babd 634 end Default_Prim_Op_Position;
635
7189d17f 636 -----------------------------
637 -- Expand_Dispatching_Call --
638 -----------------------------
ee6ba406 639
7189d17f 640 procedure Expand_Dispatching_Call (Call_Node : Node_Id) is
ee6ba406 641 Loc : constant Source_Ptr := Sloc (Call_Node);
642 Call_Typ : constant Entity_Id := Etype (Call_Node);
643
2ea346ac 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);
ee6ba406 647
af647dc7 648 Subp : Entity_Id;
7189d17f 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;
ee6ba406 660
661 function New_Value (From : Node_Id) return Node_Id;
9dfe12ae 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
7189d17f 664 -- access parameter.
665
9dfe12ae 666 ---------------
667 -- New_Value --
668 ---------------
669
ee6ba406 670 function New_Value (From : Node_Id) return Node_Id is
671 Res : constant Node_Id := Duplicate_Subexpr (From);
ee6ba406 672 begin
673 if Is_Access_Type (Etype (From)) then
af647dc7 674 return
675 Make_Explicit_Dereference (Sloc (From),
676 Prefix => Res);
ee6ba406 677 else
678 return Res;
679 end if;
680 end New_Value;
681
d215f619 682 -- Local variables
683
5a44b136 684 New_Node : Node_Id;
685 SCIL_Node : Node_Id;
686 SCIL_Related_Node : Node_Id := Call_Node;
d215f619 687
7189d17f 688 -- Start of processing for Expand_Dispatching_Call
ee6ba406 689
690 begin
725a69d2 691 if No_Run_Time_Mode then
692 Error_Msg_CRT ("tagged types", Call_Node);
693 return;
694 end if;
695
343d35dc 696 -- Expand_Dispatching_Call is called directly from the semantics,
0f3b1f49 697 -- so we only proceed if the expander is active.
343d35dc 698
b6242b97 699 if not Full_Expander_Active
0f3b1f49 700
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.
704
343d35dc 705 or else Restriction_Active (No_Dispatching_Calls)
706 then
707 return;
708 end if;
68f95949 709
af647dc7 710 -- Set subprogram. If this is an inherited operation that was
711 -- overridden, the body that is being called is its alias.
712
713 Subp := Entity (Name (Call_Node));
ee6ba406 714
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;
721
7189d17f 722 -- Definition of the class-wide type and the tagged type
ee6ba406 723
7189d17f 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).
732
2ea346ac 733 if Ctrl_Typ = RTE (RE_Tag)
68f95949 734 or else (RTE_Available (RE_Interface_Tag)
2ea346ac 735 and then Ctrl_Typ = RTE (RE_Interface_Tag))
aad6babd 736 then
af647dc7 737 CW_Typ := Class_Wide_Type (Find_Dispatching_Type (Subp));
7189d17f 738
725a69d2 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).
743
2ea346ac 744 elsif Is_Access_Type (Ctrl_Typ) then
745 CW_Typ := Class_Wide_Type (Designated_Type (Ctrl_Typ));
7189d17f 746
ee6ba406 747 else
2ea346ac 748 CW_Typ := Class_Wide_Type (Ctrl_Typ);
ee6ba406 749 end if;
750
bb5dfacc 751 Typ := Find_Specific_Type (CW_Typ);
d62940bf 752
ee6ba406 753 if not Is_Limited_Type (Typ) then
754 Eq_Prim_Op := Find_Prim_Op (Typ, Name_Op_Eq);
755 end if;
756
343d35dc 757 -- Dispatching call to C++ primitive. Create a new parameter list
758 -- with no tag checks.
ee6ba406 759
cd534f03 760 New_Params := New_List;
761
343d35dc 762 if Is_CPP_Class (Typ) then
ee6ba406 763 Param := First_Actual (Call_Node);
764 while Present (Param) loop
aad6babd 765 Append_To (New_Params, Relocate_Node (Param));
ee6ba406 766 Next_Actual (Param);
767 end loop;
768
343d35dc 769 -- Dispatching call to Ada primitive
770
ee6ba406 771 elsif Present (Param_List) then
cd534f03 772 Apply_Tag_Checks (Call_Node);
ee6ba406 773
ee6ba406 774 Param := First_Actual (Call_Node);
775 while Present (Param) loop
cd534f03 776 -- Cases in which we may have generated runtime checks
ee6ba406 777
cd534f03 778 if Param = Ctrl_Arg
779 or else Subp = Eq_Prim_Op
780 then
9dfe12ae 781 Append_To (New_Params,
782 Duplicate_Subexpr_Move_Checks (Param));
ee6ba406 783
0429d533 784 elsif Nkind (Parent (Param)) /= N_Parameter_Association
785 or else not Is_Accessibility_Actual (Parent (Param))
786 then
ee6ba406 787 Append_To (New_Params, Relocate_Node (Param));
788 end if;
789
790 Next_Actual (Param);
791 end loop;
792 end if;
793
794 -- Generate the appropriate subprogram pointer type
795
68f95949 796 if Etype (Subp) = Typ then
ee6ba406 797 Res_Typ := CW_Typ;
798 else
7189d17f 799 Res_Typ := Etype (Subp);
ee6ba406 800 end if;
801
b6b96867 802 Subp_Typ := Create_Itype (E_Subprogram_Type, Call_Node);
ee6ba406 803 Subp_Ptr_Typ := Create_Itype (E_Access_Subprogram_Type, Call_Node);
804 Set_Etype (Subp_Typ, Res_Typ);
ee6ba406 805 Set_Returns_By_Ref (Subp_Typ, Returns_By_Ref (Subp));
265200d0 806 Set_Convention (Subp_Typ, Convention (Subp));
807
808 -- Notify gigi that the designated type is a dispatching primitive
809
810 Set_Is_Dispatch_Table_Entity (Subp_Typ);
ee6ba406 811
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.
814
815 declare
816 Old_Formal : Entity_Id := First_Formal (Subp);
817 New_Formal : Entity_Id;
725a69d2 818 Extra : Entity_Id := Empty;
ee6ba406 819
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);
825
826 loop
827 Set_Scope (New_Formal, Subp_Typ);
828
829 -- Change all the controlling argument types to be class-wide
7189d17f 830 -- to avoid a recursion in dispatching.
ee6ba406 831
7189d17f 832 if Is_Controlling_Formal (New_Formal) then
ee6ba406 833 Set_Etype (New_Formal, Etype (Param));
834 end if;
835
cc60bd16 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.
ee6ba406 841
842 Extra := New_Formal;
843 Next_Formal (Old_Formal);
844 exit when No (Old_Formal);
845
846 Set_Next_Entity (New_Formal, New_Copy (Old_Formal));
847 Next_Entity (New_Formal);
848 Next_Actual (Param);
849 end loop;
af647dc7 850
851 Set_Next_Entity (New_Formal, Empty);
ee6ba406 852 Set_Last_Entity (Subp_Typ, Extra);
725a69d2 853 end if;
ee6ba406 854
725a69d2 855 -- Now that the explicit formals have been duplicated, any extra
856 -- formals needed by the subprogram must be created.
ee6ba406 857
725a69d2 858 if Present (Extra) then
859 Set_Extra_Formal (Extra, Empty);
ee6ba406 860 end if;
725a69d2 861
862 Create_Extra_Formals (Subp_Typ);
ee6ba406 863 end;
864
b6b96867 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.
868
ee6ba406 869 Set_Etype (Subp_Ptr_Typ, Subp_Ptr_Typ);
870 Set_Directly_Designated_Type (Subp_Ptr_Typ, Subp_Typ);
acf97c11 871 Set_Convention (Subp_Ptr_Typ, Convention (Subp_Typ));
b6b96867 872 Layout_Type (Subp_Ptr_Typ);
ee6ba406 873
68f95949 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.
7189d17f 877
2ea346ac 878 if Ctrl_Typ = RTE (RE_Tag)
68f95949 879 or else (RTE_Available (RE_Interface_Tag)
2ea346ac 880 and then Ctrl_Typ = RTE (RE_Interface_Tag))
68f95949 881 then
882 Controlling_Tag := Duplicate_Subexpr (Ctrl_Arg);
883
343d35dc 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).
889
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));
899
68f95949 900 -- Ada 2005 (AI-251): Abstract interface class-wide type
901
2ea346ac 902 elsif Is_Interface (Ctrl_Typ)
903 and then Is_Class_Wide_Type (Ctrl_Typ)
aad6babd 904 then
7189d17f 905 Controlling_Tag := Duplicate_Subexpr (Ctrl_Arg);
906
907 else
908 Controlling_Tag :=
909 Make_Selected_Component (Loc,
1ea4332a 910 Prefix => Duplicate_Subexpr_Move_Checks (Ctrl_Arg),
7189d17f 911 Selector_Name => New_Reference_To (DTC_Entity (Subp), Loc));
912 end if;
913
1ea4332a 914 -- Handle dispatching calls to predefined primitives
ee6ba406 915
af647dc7 916 if Is_Predefined_Dispatching_Operation (Subp)
917 or else Is_Predefined_Dispatching_Alias (Subp)
918 then
ef40be71 919 Build_Get_Predefined_Prim_Op_Address (Loc,
920 Tag_Node => Controlling_Tag,
921 Position => DT_Position (Subp),
922 New_Node => New_Node);
ee6ba406 923
343d35dc 924 -- Handle dispatching calls to user-defined primitives
68f95949 925
926 else
ef40be71 927 Build_Get_Prim_Op_Address (Loc,
23197014 928 Typ => Underlying_Type (Find_Dispatching_Type (Subp)),
ef40be71 929 Tag_Node => Controlling_Tag,
930 Position => DT_Position (Subp),
931 New_Node => New_Node);
68f95949 932 end if;
ee6ba406 933
ef40be71 934 New_Call_Name :=
935 Unchecked_Convert_To (Subp_Ptr_Typ, New_Node);
936
5a44b136 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).
ee6ba406 942
ef40be71 943 if Generate_SCIL then
5a44b136 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);
ef40be71 947
948 -- Common case: the controlling tag is the tag of an object
949 -- (for example, obj.tag)
950
951 if Nkind (Controlling_Tag) = N_Selected_Component then
952 Set_SCIL_Controlling_Tag (SCIL_Node, Controlling_Tag);
953
954 -- Handle renaming of selected component
955
956 elsif Nkind (Controlling_Tag) = N_Identifier
1ea4332a 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
ef40be71 961 then
962 Set_SCIL_Controlling_Tag (SCIL_Node,
963 Name (Parent (Entity (Controlling_Tag))));
964
965 -- If the controlling tag is an identifier, the SCIL node references
966 -- the corresponding object or parameter declaration
967
968 elsif Nkind (Controlling_Tag) = N_Identifier
969 and then Nkind_In (Parent (Entity (Controlling_Tag)),
1ea4332a 970 N_Object_Declaration,
971 N_Parameter_Specification)
ef40be71 972 then
973 Set_SCIL_Controlling_Tag (SCIL_Node,
974 Parent (Entity (Controlling_Tag)));
975
976 -- If the controlling tag is a dereference, the SCIL node references
977 -- the corresponding object or parameter declaration
978
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))),
1ea4332a 982 N_Object_Declaration,
983 N_Parameter_Specification)
ef40be71 984 then
985 Set_SCIL_Controlling_Tag (SCIL_Node,
986 Parent (Entity (Prefix (Controlling_Tag))));
987
988 -- For a direct reference of the tag of the type the SCIL node
6fb3c314 989 -- references the internal object declaration containing the tag
ef40be71 990 -- of the type.
991
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
1ea4332a 997 (Node
998 (First_Elmt
999 (Access_Disp_Table (Entity (Prefix (Controlling_Tag)))))));
ef40be71 1000
1001 -- Interfaces are not supported. For now we leave the SCIL node
1002 -- decorated with the Controlling_Tag. More work needed here???
1003
1004 elsif Is_Interface (Etype (Controlling_Tag)) then
1005 Set_SCIL_Controlling_Tag (SCIL_Node, Controlling_Tag);
1006
1007 else
1008 pragma Assert (False);
1009 null;
1010 end if;
1011 end if;
1012
1013 if Nkind (Call_Node) = N_Function_Call then
725a69d2 1014 New_Call :=
1015 Make_Function_Call (Loc,
1ea4332a 1016 Name => New_Call_Name,
725a69d2 1017 Parameter_Associations => New_Params);
ee6ba406 1018
725a69d2 1019 -- If this is a dispatching "=", we must first compare the tags so
1020 -- we generate: x.tag = y.tag and then x = y
ee6ba406 1021
725a69d2 1022 if Subp = Eq_Prim_Op then
1023 Param := First_Actual (Call_Node);
aad6babd 1024 New_Call :=
725a69d2 1025 Make_And_Then (Loc,
1026 Left_Opnd =>
1027 Make_Op_Eq (Loc,
1028 Left_Opnd =>
1029 Make_Selected_Component (Loc,
1ea4332a 1030 Prefix => New_Value (Param),
725a69d2 1031 Selector_Name =>
1032 New_Reference_To (First_Tag_Component (Typ),
1033 Loc)),
ee6ba406 1034
725a69d2 1035 Right_Opnd =>
1036 Make_Selected_Component (Loc,
1ea4332a 1037 Prefix =>
725a69d2 1038 Unchecked_Convert_To (Typ,
1039 New_Value (Next_Actual (Param))),
1040 Selector_Name =>
1ea4332a 1041 New_Reference_To
1042 (First_Tag_Component (Typ), Loc))),
725a69d2 1043 Right_Opnd => New_Call);
5a44b136 1044
1045 SCIL_Related_Node := Right_Opnd (New_Call);
ee6ba406 1046 end if;
1047
1048 else
1049 New_Call :=
1050 Make_Procedure_Call_Statement (Loc,
1ea4332a 1051 Name => New_Call_Name,
ee6ba406 1052 Parameter_Associations => New_Params);
1053 end if;
1054
e00e091c 1055 -- Register the dispatching call in the call graph nodes table
1056
1057 Register_CG_Node (Call_Node);
1058
ee6ba406 1059 Rewrite (Call_Node, New_Call);
725a69d2 1060
5a44b136 1061 -- Associate the SCIL node of this dispatching call
1062
1063 if Generate_SCIL then
1064 Set_SCIL_Node (SCIL_Related_Node, SCIL_Node);
1065 end if;
1066
725a69d2 1067 -- Suppress all checks during the analysis of the expanded code
36b938a3 1068 -- to avoid the generation of spurious warnings under ZFP run-time.
725a69d2 1069
1070 Analyze_And_Resolve (Call_Node, Call_Typ, Suppress => All_Checks);
7189d17f 1071 end Expand_Dispatching_Call;
ee6ba406 1072
aad6babd 1073 ---------------------------------
1074 -- Expand_Interface_Conversion --
1075 ---------------------------------
1076
952af0b9 1077 procedure Expand_Interface_Conversion
1078 (N : Node_Id;
1079 Is_Static : Boolean := True)
1080 is
aad6babd 1081 Loc : constant Source_Ptr := Sloc (N);
af647dc7 1082 Etyp : constant Entity_Id := Etype (N);
aad6babd 1083 Operand : constant Node_Id := Expression (N);
1084 Operand_Typ : Entity_Id := Etype (Operand);
d62940bf 1085 Func : Node_Id;
af647dc7 1086 Iface_Typ : Entity_Id := Etype (N);
1087 Iface_Tag : Entity_Id;
aad6babd 1088
1089 begin
343d35dc 1090 -- Ada 2005 (AI-345): Handle synchronized interface type derivations
aad6babd 1091
343d35dc 1092 if Is_Concurrent_Type (Operand_Typ) then
1093 Operand_Typ := Base_Type (Corresponding_Record_Type (Operand_Typ));
aad6babd 1094 end if;
1095
e7e688dd 1096 -- Handle access to class-wide interface types
aad6babd 1097
d62940bf 1098 if Is_Access_Type (Iface_Typ) then
1099 Iface_Typ := Etype (Directly_Designated_Type (Iface_Typ));
aad6babd 1100 end if;
1101
d62940bf 1102 -- Handle class-wide interface types. This conversion can appear
1103 -- explicitly in the source code. Example: I'Class (Obj)
aad6babd 1104
d62940bf 1105 if Is_Class_Wide_Type (Iface_Typ) then
725a69d2 1106 Iface_Typ := Root_Type (Iface_Typ);
d62940bf 1107 end if;
1108
79a72728 1109 -- If the target type is a tagged synchronized type, the dispatch table
bf3e1520 1110 -- info is in the corresponding record type.
79a72728 1111
1112 if Is_Concurrent_Type (Iface_Typ) then
1113 Iface_Typ := Corresponding_Record_Type (Iface_Typ);
1114 end if;
1115
23197014 1116 -- Handle private types
1117
1118 Iface_Typ := Underlying_Type (Iface_Typ);
1119
a17cc77d 1120 -- Freeze the entity associated with the target interface to have
1121 -- available the attribute Access_Disp_Table.
1122
1123 Freeze_Before (N, Iface_Typ);
1124
af647dc7 1125 pragma Assert (not Is_Static
1126 or else (not Is_Class_Wide_Type (Iface_Typ)
1127 and then Is_Interface (Iface_Typ)));
aad6babd 1128
662256db 1129 if not Tagged_Type_Expansion then
79500ea0 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;
725a69d2 1134
79500ea0 1135 if Is_Class_Wide_Type (Operand_Typ) then
1136 Operand_Typ := Root_Type (Operand_Typ);
1137 end if;
1138
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;
1154
1155 -- Just do a conversion ???
1156
1157 Rewrite (N, Unchecked_Convert_To (Etype (N), N));
1158 Analyze (N);
1159 end if;
725a69d2 1160
725a69d2 1161 return;
1162 end if;
1163
952af0b9 1164 if not Is_Static then
68f95949 1165
1166 -- Give error if configurable run time and Displace not available
1167
1168 if not RTE_Available (RE_Displace) then
cc60bd16 1169 Error_Msg_CRT ("dynamic interface conversion", N);
68f95949 1170 return;
1171 end if;
1172
725a69d2 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):
af647dc7 1176
1177 -- type Iface1_Ref is access all Iface1'Class;
1178 -- type Iface2_Ref is access all Iface1'Class;
1179
1180 -- Acc1 : Iface1_Ref := new ...
1181 -- Obj : Obj_Ref := Obj_Ref (Acc); -- 1
1182 -- Acc2 : Iface2_Ref := Iface2_Ref (Acc); -- 2
1183
1184 if Is_Access_Type (Operand_Typ) then
af647dc7 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 (
1190
1191 Unchecked_Convert_To (RTE (RE_Address),
1192 Relocate_Node (Expression (N))),
1193
1194 New_Occurrence_Of
1195 (Node (First_Elmt (Access_Disp_Table (Iface_Typ))),
1196 Loc)))));
1197
1198 Analyze (N);
1199 return;
1200 end if;
1201
952af0b9 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),
af647dc7 1209
952af0b9 1210 New_Occurrence_Of
1211 (Node (First_Elmt (Access_Disp_Table (Iface_Typ))),
1212 Loc))));
1213
1214 Analyze (N);
1215
af647dc7 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.
952af0b9 1219
17e14451 1220 declare
1221 New_Itype : Entity_Id;
952af0b9 1222
17e14451 1223 begin
1224 New_Itype := Create_Itype (E_Anonymous_Access_Type, N);
cc60bd16 1225 Set_Etype (New_Itype, New_Itype);
17e14451 1226 Set_Directly_Designated_Type (New_Itype, Etyp);
952af0b9 1227
17e14451 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);
1234
1235 return;
1236 end;
952af0b9 1237 end if;
1238
d62940bf 1239 Iface_Tag := Find_Interface_Tag (Operand_Typ, Iface_Typ);
aad6babd 1240 pragma Assert (Iface_Tag /= Empty);
1241
d62940bf 1242 -- Keep separate access types to interfaces because one internal
f235fede 1243 -- function is used to handle the null value (see following comments)
d62940bf 1244
1245 if not Is_Access_Type (Etype (N)) then
f235fede 1246
1247 -- Statically displace the pointer to the object to reference
1248 -- the component containing the secondary dispatch table.
1249
d62940bf 1250 Rewrite (N,
f235fede 1251 Convert_Tag_To_Interface (Class_Wide_Type (Iface_Typ),
d62940bf 1252 Make_Selected_Component (Loc,
1253 Prefix => Relocate_Node (Expression (N)),
f235fede 1254 Selector_Name => New_Occurrence_Of (Iface_Tag, Loc))));
d62940bf 1255
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:
1262
af647dc7 1263 -- function Func (O : Address) return Iface_Typ is
17e14451 1264 -- type Op_Typ is access all Operand_Typ;
1265 -- Aux : Op_Typ := To_Op_Typ (O);
d62940bf 1266 -- begin
af647dc7 1267 -- if O = Null_Address then
d62940bf 1268 -- return null;
1269 -- else
17e14451 1270 -- return Iface_Typ!(Aux.Iface_Tag'Address);
d62940bf 1271 -- end if;
1272 -- end Func;
1273
af647dc7 1274 declare
17e14451 1275 Desig_Typ : Entity_Id;
1276 Fent : Entity_Id;
1277 New_Typ_Decl : Node_Id;
17e14451 1278 Stats : List_Id;
1279
af647dc7 1280 begin
1281 Desig_Typ := Etype (Expression (N));
d62940bf 1282
af647dc7 1283 if Is_Access_Type (Desig_Typ) then
865909d3 1284 Desig_Typ :=
1285 Available_View (Directly_Designated_Type (Desig_Typ));
af647dc7 1286 end if;
d62940bf 1287
e7e688dd 1288 if Is_Concurrent_Type (Desig_Typ) then
1289 Desig_Typ := Base_Type (Corresponding_Record_Type (Desig_Typ));
1290 end if;
1291
17e14451 1292 New_Typ_Decl :=
1293 Make_Full_Type_Declaration (Loc,
ec97ce79 1294 Defining_Identifier => Make_Temporary (Loc, 'T'),
17e14451 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)));
d62940bf 1302
725a69d2 1303 Stats := New_List (
17e14451 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 =>
e7e688dd 1310 Unchecked_Convert_To
1311 (Defining_Identifier (New_Typ_Decl),
1312 Make_Identifier (Loc, Name_uO)),
17e14451 1313 Selector_Name =>
1314 New_Occurrence_Of (Iface_Tag, Loc)),
1315 Attribute_Name => Name_Address))));
725a69d2 1316
17e14451 1317 -- If the type is null-excluding, no need for the null branch.
1318 -- Otherwise we need to check for it and return null.
1319
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)),
1328
1329 Then_Statements => New_List (
1330 Make_Simple_Return_Statement (Loc,
1331 Make_Null (Loc))),
1332 Else_Statements => Stats));
1333 end if;
d62940bf 1334
ec97ce79 1335 Fent := Make_Temporary (Loc, 'F');
17e14451 1336 Func :=
1337 Make_Subprogram_Body (Loc,
1338 Specification =>
1339 Make_Function_Specification (Loc,
1340 Defining_Unit_Name => Fent,
d62940bf 1341
17e14451 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))),
d62940bf 1348
17e14451 1349 Result_Definition =>
1350 New_Reference_To (Etype (N), Loc)),
d62940bf 1351
e7e688dd 1352 Declarations => New_List (New_Typ_Decl),
d62940bf 1353
17e14451 1354 Handled_Statement_Sequence =>
1355 Make_Handled_Sequence_Of_Statements (Loc, Stats));
d62940bf 1356
17e14451 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).
af647dc7 1363
17e14451 1364 Insert_Action (N, Func, Suppress => All_Checks);
af647dc7 1365
17e14451 1366 if Is_Access_Type (Etype (Expression (N))) then
af647dc7 1367
e7e688dd 1368 -- Generate: Func (Address!(Expression))
af647dc7 1369
17e14451 1370 Rewrite (N,
1371 Make_Function_Call (Loc,
1372 Name => New_Reference_To (Fent, Loc),
1373 Parameter_Associations => New_List (
e7e688dd 1374 Unchecked_Convert_To (RTE (RE_Address),
1375 Relocate_Node (Expression (N))))));
17e14451 1376
1377 else
e7e688dd 1378 -- Generate: Func (Operand_Typ!(Expression)'Address)
17e14451 1379
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;
d62940bf 1390 end if;
aad6babd 1391
1392 Analyze (N);
1393 end Expand_Interface_Conversion;
1394
1395 ------------------------------
1396 -- Expand_Interface_Actuals --
1397 ------------------------------
1398
1399 procedure Expand_Interface_Actuals (Call_Node : Node_Id) is
aad6babd 1400 Actual : Node_Id;
d62940bf 1401 Actual_Dup : Node_Id;
aad6babd 1402 Actual_Typ : Entity_Id;
d62940bf 1403 Anon : Entity_Id;
aad6babd 1404 Conversion : Node_Id;
1405 Formal : Entity_Id;
1406 Formal_Typ : Entity_Id;
1407 Subp : Entity_Id;
d62940bf 1408 Formal_DDT : Entity_Id;
1409 Actual_DDT : Entity_Id;
aad6babd 1410
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.
1414
1415 if not Expander_Active then
1416 return;
1417 end if;
1418
1419 -- Call using access to subprogram with explicit dereference
1420
1421 if Nkind (Name (Call_Node)) = N_Explicit_Dereference then
1422 Subp := Etype (Name (Call_Node));
1423
4e5db562 1424 -- Call using selected component
1425
1426 elsif Nkind (Name (Call_Node)) = N_Selected_Component then
1427 Subp := Entity (Selector_Name (Name (Call_Node)));
1428
1429 -- Call using direct name
aad6babd 1430
1431 else
1432 Subp := Entity (Name (Call_Node));
1433 end if;
1434
725a69d2 1435 -- Ada 2005 (AI-251): Look for interface type formals to force "this"
1436 -- displacement
1437
aad6babd 1438 Formal := First_Formal (Subp);
1439 Actual := First_Actual (Call_Node);
aad6babd 1440 while Present (Formal) loop
725a69d2 1441 Formal_Typ := Etype (Formal);
d62940bf 1442
1443 if Ekind (Formal_Typ) = E_Record_Type_With_Private then
1444 Formal_Typ := Full_View (Formal_Typ);
1445 end if;
1446
1447 if Is_Access_Type (Formal_Typ) then
1448 Formal_DDT := Directly_Designated_Type (Formal_Typ);
1449 end if;
1450
aad6babd 1451 Actual_Typ := Etype (Actual);
1452
d62940bf 1453 if Is_Access_Type (Actual_Typ) then
1454 Actual_DDT := Directly_Designated_Type (Actual_Typ);
1455 end if;
1456
725a69d2 1457 if Is_Interface (Formal_Typ)
1458 and then Is_Class_Wide_Type (Formal_Typ)
1459 then
d62940bf 1460 -- No need to displace the pointer if the type of the actual
1d00a8ce 1461 -- coincides with the type of the formal.
aad6babd 1462
725a69d2 1463 if Actual_Typ = Formal_Typ then
d62940bf 1464 null;
1465
725a69d2 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.
aad6babd 1469
cb4af01d 1470 elsif Is_Ancestor (Formal_Typ, Actual_Typ,
1471 Use_Full_View => True)
1472 then
d62940bf 1473 null;
1474
725a69d2 1475 -- Implicit conversion to the class-wide formal type to force
1476 -- the displacement of the pointer.
1477
d62940bf 1478 else
8a8d9086 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.
1485
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;
1491
d62940bf 1492 Conversion := Convert_To (Formal_Typ, Relocate_Node (Actual));
725a69d2 1493 Rewrite (Actual, Conversion);
d62940bf 1494 Analyze_And_Resolve (Actual, Formal_Typ);
1495 end if;
aad6babd 1496
725a69d2 1497 -- Access to class-wide interface type
aad6babd 1498
1499 elsif Is_Access_Type (Formal_Typ)
725a69d2 1500 and then Is_Interface (Formal_DDT)
1501 and then Is_Class_Wide_Type (Formal_DDT)
aad6babd 1502 and then Interface_Present_In_Ancestor
d62940bf 1503 (Typ => Actual_DDT,
1504 Iface => Etype (Formal_DDT))
aad6babd 1505 then
725a69d2 1506 -- Handle attributes 'Access and 'Unchecked_Access
1507
aad6babd 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
5e82d8fe 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.
aad6babd 1516
5e82d8fe 1517 pragma Assert (Base_Type (Etype (Prefix (Actual)))
1518 = Base_Type (Formal_DDT));
1519 null;
aad6babd 1520
725a69d2 1521 -- No need to displace the pointer if the type of the actual
1522 -- coincides with the type of the formal.
d62940bf 1523
725a69d2 1524 elsif Actual_DDT = Formal_DDT then
d62940bf 1525 null;
1526
725a69d2 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.
d62940bf 1530
cb4af01d 1531 elsif Is_Ancestor (Formal_DDT, Actual_DDT,
1532 Use_Full_View => True)
1533 then
d62940bf 1534 null;
1535
aad6babd 1536 else
d62940bf 1537 Actual_Dup := Relocate_Node (Actual);
1538
1539 if From_With_Type (Actual_Typ) then
1540
1541 -- If the type of the actual parameter comes from a limited
1542 -- with-clause and the non-limited view is already available
9ced80be 1543 -- we replace the anonymous access type by a duplicate
1544 -- declaration whose designated type is the non-limited view
d62940bf 1545
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);
1550
1551 if Is_Itype (Anon) then
1552 Set_Scope (Anon, Current_Scope);
1553 end if;
1554
1555 Set_Directly_Designated_Type (Anon,
1556 Non_Limited_View (Actual_DDT));
1557 Set_Etype (Actual_Dup, Anon);
1558
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);
1564
1565 if Is_Itype (Anon) then
1566 Set_Scope (Anon, Current_Scope);
1567 end if;
1568
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;
1581
1582 Conversion := Convert_To (Formal_Typ, Actual_Dup);
1583 Rewrite (Actual, Conversion);
aad6babd 1584 Analyze_And_Resolve (Actual, Formal_Typ);
1585 end if;
1586 end if;
1587
1588 Next_Actual (Actual);
1589 Next_Formal (Formal);
1590 end loop;
1591 end Expand_Interface_Actuals;
1592
1593 ----------------------------
1594 -- Expand_Interface_Thunk --
1595 ----------------------------
1596
725a69d2 1597 procedure Expand_Interface_Thunk
17e14451 1598 (Prim : Node_Id;
1599 Thunk_Id : out Entity_Id;
1600 Thunk_Code : out Node_Id)
aad6babd 1601 is
e8376947 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);
725a69d2 1607
1608 Controlling_Typ : Entity_Id;
1609 Decl_1 : Node_Id;
1610 Decl_2 : Node_Id;
04c6d723 1611 Expr : Node_Id;
725a69d2 1612 Formal : Node_Id;
04c6d723 1613 Ftyp : Entity_Id;
1614 Iface_Formal : Node_Id;
cc60bd16 1615 New_Arg : Node_Id;
1616 Offset_To_Top : Node_Id;
725a69d2 1617 Target_Formal : Entity_Id;
aad6babd 1618
1619 begin
725a69d2 1620 Thunk_Id := Empty;
1621 Thunk_Code := Empty;
1622
3f8cf2d2 1623 -- No thunk needed if the primitive has been eliminated
1624
1625 if Is_Eliminated (Ultimate_Alias (Prim)) then
1626 return;
1627
e8376947 1628 -- In case of primitives that are functions without formals and a
1629 -- controlling result there is no need to build the thunk.
725a69d2 1630
3f8cf2d2 1631 elsif not Present (First_Formal (Target)) then
725a69d2 1632 pragma Assert (Ekind (Target) = E_Function
1633 and then Has_Controlling_Result (Target));
1634 return;
1635 end if;
1636
04c6d723 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
e8376947 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
04c6d723 1643 -- actual object) generate code that modify its contents.
1644
1645 -- Note: This special management is not done for predefined primitives
1646 -- because???
1647
1648 if not Is_Predefined_Dispatching_Operation (Prim) then
1649 Iface_Formal := First_Formal (Interface_Alias (Prim));
1650 end if;
aad6babd 1651
d62940bf 1652 Formal := First_Formal (Target);
aad6babd 1653 while Present (Formal) loop
04c6d723 1654 Ftyp := Etype (Formal);
1655
1656 -- Use the interface type as the type of the controlling formal (see
e8376947 1657 -- comment above).
04c6d723 1658
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;
1668
725a69d2 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)),
04c6d723 1676 Parameter_Type => New_Reference_To (Ftyp, Loc),
1677 Expression => Expr));
1678
1679 if not Is_Predefined_Dispatching_Operation (Prim) then
1680 Next_Formal (Iface_Formal);
1681 end if;
d62940bf 1682
aad6babd 1683 Next_Formal (Formal);
1684 end loop;
1685
17e14451 1686 Controlling_Typ := Find_Dispatching_Type (Target);
aad6babd 1687
725a69d2 1688 Target_Formal := First_Formal (Target);
1689 Formal := First (Formals);
1690 while Present (Formal) loop
04c6d723 1691
6cd460aa 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.
04c6d723 1695
1696 if Ekind (Target_Formal) = E_In_Parameter
1697 and then Ekind (Etype (Target_Formal)) = E_Anonymous_Access_Type
1698 then
6cd460aa 1699 Ftyp :=
1700 Base_Type (Directly_Designated_Type (Etype (Target_Formal)));
04c6d723 1701 else
ca12fde2 1702 Ftyp := Base_Type (Etype (Target_Formal));
04c6d723 1703 end if;
1704
232a63ed 1705 -- For concurrent types, the relevant information is found in the
1706 -- Corresponding_Record_Type, rather than the type entity itself.
6cd460aa 1707
04c6d723 1708 if Is_Concurrent_Type (Ftyp) then
1709 Ftyp := Corresponding_Record_Type (Ftyp);
1710 end if;
1711
725a69d2 1712 if Ekind (Target_Formal) = E_In_Parameter
1713 and then Ekind (Etype (Target_Formal)) = E_Anonymous_Access_Type
04c6d723 1714 and then Ftyp = Controlling_Typ
725a69d2 1715 then
1716 -- Generate:
17e14451 1717 -- type T is access all <<type of the target formal>>
1718 -- S : Storage_Offset := Storage_Offset!(Formal)
1719 -- - Offset_To_Top (address!(Formal))
725a69d2 1720
1721 Decl_2 :=
1722 Make_Full_Type_Declaration (Loc,
ec97ce79 1723 Defining_Identifier => Make_Temporary (Loc, 'T'),
725a69d2 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 =>
04c6d723 1730 New_Reference_To (Ftyp, Loc)));
725a69d2 1731
cc60bd16 1732 New_Arg :=
1733 Unchecked_Convert_To (RTE (RE_Address),
1734 New_Reference_To (Defining_Identifier (Formal), Loc));
1735
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;
1745
725a69d2 1746 Decl_1 :=
1747 Make_Object_Declaration (Loc,
ec97ce79 1748 Defining_Identifier => Make_Temporary (Loc, 'S'),
725a69d2 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 =>
cc60bd16 1759 Offset_To_Top));
725a69d2 1760
1761 Append_To (Decl, Decl_2);
1762 Append_To (Decl, Decl_1);
1763
17e14451 1764 -- Reference the new actual. Generate:
1765 -- T!(S)
725a69d2 1766
1767 Append_To (Actuals,
1768 Unchecked_Convert_To
1769 (Defining_Identifier (Decl_2),
1770 New_Reference_To (Defining_Identifier (Decl_1), Loc)));
1771
04c6d723 1772 elsif Ftyp = Controlling_Typ then
aad6babd 1773
e8376947 1774 -- Generate:
17e14451 1775 -- S1 : Storage_Offset := Storage_Offset!(Formal'Address)
1776 -- - Offset_To_Top (Formal'Address)
1777 -- S2 : Addr_Ptr := Addr_Ptr!(S1)
aad6babd 1778
cc60bd16 1779 New_Arg :=
1780 Make_Attribute_Reference (Loc,
1781 Prefix =>
1782 New_Reference_To (Defining_Identifier (Formal), Loc),
1783 Attribute_Name =>
1784 Name_Address);
1785
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;
1795
725a69d2 1796 Decl_1 :=
1797 Make_Object_Declaration (Loc,
ec97ce79 1798 Defining_Identifier => Make_Temporary (Loc, 'S'),
725a69d2 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 =>
cc60bd16 1813 Offset_To_Top));
aad6babd 1814
725a69d2 1815 Decl_2 :=
1816 Make_Object_Declaration (Loc,
ec97ce79 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 =>
725a69d2 1822 Unchecked_Convert_To
1823 (RTE (RE_Addr_Ptr),
1824 New_Reference_To (Defining_Identifier (Decl_1), Loc)));
aad6babd 1825
725a69d2 1826 Append_To (Decl, Decl_1);
1827 Append_To (Decl, Decl_2);
952af0b9 1828
ec97ce79 1829 -- Reference the new actual, generate:
17e14451 1830 -- Target_Formal (S2.all)
aad6babd 1831
725a69d2 1832 Append_To (Actuals,
04c6d723 1833 Unchecked_Convert_To (Ftyp,
725a69d2 1834 Make_Explicit_Dereference (Loc,
1835 New_Reference_To (Defining_Identifier (Decl_2), Loc))));
aad6babd 1836
984d005d 1837 -- Ensure proper matching of access types. Required to avoid
1838 -- reporting spurious errors.
1839
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)));
1844
725a69d2 1845 -- No special management required for this actual
aad6babd 1846
725a69d2 1847 else
1848 Append_To (Actuals,
1849 New_Reference_To (Defining_Identifier (Formal), Loc));
1850 end if;
1851
1852 Next_Formal (Target_Formal);
aad6babd 1853 Next (Formal);
1854 end loop;
1855
ec97ce79 1856 Thunk_Id := Make_Temporary (Loc, 'T');
e7e688dd 1857 Set_Is_Thunk (Thunk_Id);
265200d0 1858 Set_Convention (Thunk_Id, Convention (Prim));
e7e688dd 1859
e8376947 1860 -- Procedure case
1861
d62940bf 1862 if Ekind (Target) = E_Procedure then
725a69d2 1863 Thunk_Code :=
aad6babd 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,
725a69d2 1874 Name => New_Occurrence_Of (Target, Loc),
1875 Parameter_Associations => Actuals))));
aad6babd 1876
e8376947 1877 -- Function case
aad6babd 1878
e8376947 1879 else pragma Assert (Ekind (Target) = E_Function);
725a69d2 1880 Thunk_Code :=
aad6babd 1881 Make_Subprogram_Body (Loc,
1882 Specification =>
1883 Make_Function_Specification (Loc,
1884 Defining_Unit_Name => Thunk_Id,
1885 Parameter_Specifications => Formals,
d62940bf 1886 Result_Definition =>
1887 New_Copy (Result_Definition (Parent (Target)))),
aad6babd 1888 Declarations => Decl,
1889 Handled_Statement_Sequence =>
1890 Make_Handled_Sequence_Of_Statements (Loc,
1891 Statements => New_List (
17e14451 1892 Make_Simple_Return_Statement (Loc,
aad6babd 1893 Make_Function_Call (Loc,
1894 Name => New_Occurrence_Of (Target, Loc),
1895 Parameter_Associations => Actuals)))));
1896 end if;
aad6babd 1897 end Expand_Interface_Thunk;
1898
bb5dfacc 1899 ------------------------
1900 -- Find_Specific_Type --
1901 ------------------------
1902
1903 function Find_Specific_Type (CW : Entity_Id) return Entity_Id is
1904 Typ : Entity_Id := Root_Type (CW);
1905
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;
1914
1915 return Typ;
1916 end Find_Specific_Type;
1917
d00681a7 1918 --------------------------
1919 -- Has_CPP_Constructors --
1920 --------------------------
1921
1922 function Has_CPP_Constructors (Typ : Entity_Id) return Boolean is
1923 E : Entity_Id;
1924
1925 begin
1926 -- Look for the constructor entities
1927
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;
1935
1936 Next_Entity (E);
1937 end loop;
1938
1939 return False;
1940 end Has_CPP_Constructors;
1941
24971415 1942 ------------
1943 -- Has_DT --
1944 ------------
1945
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;
1951
a652dd51 1952 -----------------------------------------
1953 -- Is_Predefined_Dispatching_Operation --
1954 -----------------------------------------
1955
1956 function Is_Predefined_Dispatching_Operation
1957 (E : Entity_Id) return Boolean
1958 is
1959 TSS_Name : TSS_Name_Type;
1960
1961 begin
1962 if not Is_Dispatching_Operation (E) then
1963 return False;
1964 end if;
1965
1966 Get_Name_String (Chars (E));
1967
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.
1971
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
a652dd51 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
30592778 1982 and then Etype (First_Formal (E)) = Etype (Last_Formal (E)))
a652dd51 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;
1991
1992 return False;
1993 end Is_Predefined_Dispatching_Operation;
1994
d1458a07 1995 ---------------------------------------
1996 -- Is_Predefined_Internal_Operation --
1997 ---------------------------------------
1998
1999 function Is_Predefined_Internal_Operation
2000 (E : Entity_Id) return Boolean
2001 is
2002 TSS_Name : TSS_Name_Type;
2003
2004 begin
2005 if not Is_Dispatching_Operation (E) then
2006 return False;
2007 end if;
2008
2009 Get_Name_String (Chars (E));
2010
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.
2014
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));
2019
2020 if Chars (E) = Name_uSize
d1458a07 2021 or else
2022 (Chars (E) = Name_Op_Eq
30592778 2023 and then Etype (First_Formal (E)) = Etype (Last_Formal (E)))
d1458a07 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;
2032
2033 return False;
2034 end Is_Predefined_Internal_Operation;
2035
af647dc7 2036 -------------------------------------
2037 -- Is_Predefined_Dispatching_Alias --
2038 -------------------------------------
2039
2040 function Is_Predefined_Dispatching_Alias (Prim : Entity_Id) return Boolean
2041 is
af647dc7 2042 begin
fc2907f6 2043 return not Is_Predefined_Dispatching_Operation (Prim)
af647dc7 2044 and then Present (Alias (Prim))
fc2907f6 2045 and then Is_Predefined_Dispatching_Operation (Ultimate_Alias (Prim));
af647dc7 2046 end Is_Predefined_Dispatching_Alias;
2047
a652dd51 2048 ---------------------------------------
2049 -- Is_Predefined_Interface_Primitive --
2050 ---------------------------------------
2051
2052 function Is_Predefined_Interface_Primitive (E : Entity_Id) return Boolean is
2053 begin
6cb4b973 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
2057
2058 return (Ada_Version >= Ada_2005 or else not Tagged_Type_Expansion)
a652dd51 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;
2066
76a1c25b 2067 ----------------------------------------
2068 -- Make_Disp_Asynchronous_Select_Body --
2069 ----------------------------------------
ee6ba406 2070
cdb1c38f 2071 -- For interface types, generate:
2072
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
a053db0d 2081 -- F := False;
2082 -- C := Ada.Tags.POK_Function;
cdb1c38f 2083 -- end _Disp_Asynchronous_Select;
2084
2085 -- For protected types, generate:
2086
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;
2107
2108 -- For task types, generate:
2109
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;
2127
76a1c25b 2128 function Make_Disp_Asynchronous_Select_Body
2129 (Typ : Entity_Id) return Node_Id
2130 is
725a69d2 2131 Com_Block : Entity_Id;
2132 Conc_Typ : Entity_Id := Empty;
2133 Decls : constant List_Id := New_List;
725a69d2 2134 Loc : constant Source_Ptr := Sloc (Typ);
acf97c11 2135 Obj_Ref : Node_Id;
725a69d2 2136 Stmts : constant List_Id := New_List;
bf7f5966 2137 Tag_Node : Node_Id;
ee6ba406 2138
2139 begin
68f95949 2140 pragma Assert (not Restriction_Active (No_Dispatching_Calls));
2141
952af0b9 2142 -- Null body is generated for interface types
2143
76a1c25b 2144 if Is_Interface (Typ) then
2145 return
2146 Make_Subprogram_Body (Loc,
aabafdc2 2147 Specification => Make_Disp_Asynchronous_Select_Spec (Typ),
2148 Declarations => New_List,
76a1c25b 2149 Handled_Statement_Sequence =>
2150 Make_Handled_Sequence_Of_Statements (Loc,
a053db0d 2151 New_List (Make_Assignment_Statement (Loc,
aabafdc2 2152 Name => Make_Identifier (Loc, Name_uF),
a053db0d 2153 Expression => New_Reference_To (Standard_False, Loc)))));
9dfe12ae 2154 end if;
2155
952af0b9 2156 if Is_Concurrent_Record_Type (Typ) then
2157 Conc_Typ := Corresponding_Concurrent_Type (Typ);
aad6babd 2158
76a1c25b 2159 -- Generate:
cdb1c38f 2160 -- I : Integer :=
2161 -- Ada.Tags.Get_Entry_Index (Ada.Tags.Tag! (<type>VP), S);
aad6babd 2162
76a1c25b 2163 -- where I will be used to capture the entry index of the primitive
2164 -- wrapper at position S.
aad6babd 2165
bf7f5966 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;
2177
76a1c25b 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 =>
725a69d2 2185 Make_Function_Call (Loc,
cdb1c38f 2186 Name =>
2187 New_Reference_To (RTE (RE_Get_Entry_Index), Loc),
2188 Parameter_Associations =>
2189 New_List (
bf7f5966 2190 Tag_Node,
cdb1c38f 2191 Make_Identifier (Loc, Name_uS)))));
aad6babd 2192
76a1c25b 2193 if Ekind (Conc_Typ) = E_Protected_Type then
aad6babd 2194
725a69d2 2195 -- Generate:
cdb1c38f 2196 -- Bnn : Communication_Block;
725a69d2 2197
ec97ce79 2198 Com_Block := Make_Temporary (Loc, 'B');
725a69d2 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)));
2205
acf97c11 2206 -- Build T._object'Access for calls below
aad6babd 2207
acf97c11 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)));
aad6babd 2215
acf97c11 2216 case Corresponding_Runtime_Package (Conc_Typ) is
2217 when System_Tasking_Protected_Objects_Entries =>
aad6babd 2218
acf97c11 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
2226
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.
2230
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,
aad6babd 2238
acf97c11 2239 Make_Unchecked_Type_Conversion (Loc, -- entry index
2240 Subtype_Mark =>
2241 New_Reference_To
55868293 2242 (RTE (RE_Protected_Entry_Index), Loc),
acf97c11 2243 Expression => Make_Identifier (Loc, Name_uI)),
d62940bf 2244
acf97c11 2245 Make_Identifier (Loc, Name_uP), -- parameter block
55868293 2246 New_Reference_To -- Asynchronous_Call
2247 (RTE (RE_Asynchronous_Call), Loc),
acf97c11 2248
2249 New_Reference_To (Com_Block, Loc)))); -- comm block
2250
2251 when System_Tasking_Protected_Objects_Single_Entry =>
2252
2253 -- Generate:
2254 -- procedure Protected_Single_Entry_Call
2255 -- (Object : Protection_Entry_Access;
2256 -- Uninterpreted_Data : System.Address;
2257 -- Mode : Call_Modes);
725a69d2 2258
acf97c11 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,
2267
2268 Make_Attribute_Reference (Loc,
55868293 2269 Prefix => Make_Identifier (Loc, Name_uP),
acf97c11 2270 Attribute_Name => Name_Address),
2271
2272 New_Reference_To
2273 (RTE (RE_Asynchronous_Call), Loc))));
2274
2275 when others =>
2276 raise Program_Error;
2277 end case;
725a69d2 2278
2279 -- Generate:
cdb1c38f 2280 -- B := Dummy_Communication_Block (Bnn);
725a69d2 2281
2282 Append_To (Stmts,
2283 Make_Assignment_Statement (Loc,
55868293 2284 Name => Make_Identifier (Loc, Name_uB),
725a69d2 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))));
2292
a053db0d 2293 -- Generate:
2294 -- F := False;
2295
2296 Append_To (Stmts,
2297 Make_Assignment_Statement (Loc,
aabafdc2 2298 Name => Make_Identifier (Loc, Name_uF),
a053db0d 2299 Expression => New_Reference_To (Standard_False, Loc)));
2300
76a1c25b 2301 else
2302 pragma Assert (Ekind (Conc_Typ) = E_Task_Type);
d62940bf 2303
76a1c25b 2304 -- Generate:
cdb1c38f 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
ee6ba406 2311
acf97c11 2312 -- where T is the task object, I is the entry index, P is the
76a1c25b 2313 -- wrapped parameters and F is the status flag.
ee6ba406 2314
76a1c25b 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 (
76a1c25b 2321 Make_Selected_Component (Loc, -- T._task_id
55868293 2322 Prefix => Make_Identifier (Loc, Name_uT),
2323 Selector_Name => Make_Identifier (Loc, Name_uTask_Id)),
ee6ba406 2324
76a1c25b 2325 Make_Unchecked_Type_Conversion (Loc, -- entry index
2326 Subtype_Mark =>
2327 New_Reference_To (RTE (RE_Task_Entry_Index), Loc),
55868293 2328 Expression => Make_Identifier (Loc, Name_uI)),
ee6ba406 2329
76a1c25b 2330 Make_Identifier (Loc, Name_uP), -- parameter block
55868293 2331 New_Reference_To -- Asynchronous_Call
2332 (RTE (RE_Asynchronous_Call), Loc),
76a1c25b 2333 Make_Identifier (Loc, Name_uF)))); -- status flag
2334 end if;
7c949aad 2335
2336 else
2337 -- Ensure that the statements list is non-empty
2338
a053db0d 2339 Append_To (Stmts,
2340 Make_Assignment_Statement (Loc,
aabafdc2 2341 Name => Make_Identifier (Loc, Name_uF),
a053db0d 2342 Expression => New_Reference_To (Standard_False, Loc)));
76a1c25b 2343 end if;
ee6ba406 2344
76a1c25b 2345 return
2346 Make_Subprogram_Body (Loc,
aabafdc2 2347 Specification =>
76a1c25b 2348 Make_Disp_Asynchronous_Select_Spec (Typ),
aabafdc2 2349 Declarations => Decls,
76a1c25b 2350 Handled_Statement_Sequence =>
2351 Make_Handled_Sequence_Of_Statements (Loc, Stmts));
2352 end Make_Disp_Asynchronous_Select_Body;
ee6ba406 2353
76a1c25b 2354 ----------------------------------------
2355 -- Make_Disp_Asynchronous_Select_Spec --
2356 ----------------------------------------
ee6ba406 2357
76a1c25b 2358 function Make_Disp_Asynchronous_Select_Spec
2359 (Typ : Entity_Id) return Node_Id
2360 is
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;
ee6ba406 2366
76a1c25b 2367 begin
68f95949 2368 pragma Assert (not Restriction_Active (No_Dispatching_Calls));
2369
725a69d2 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
ee6ba406 2375
725a69d2 2376 Append_List_To (Params, New_List (
2377
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),
2385
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)),
2391
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)),
2397
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),
ee6ba406 2404
725a69d2 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)));
7189d17f 2411
76a1c25b 2412 return
725a69d2 2413 Make_Procedure_Specification (Loc,
2414 Defining_Unit_Name => Def_Id,
2415 Parameter_Specifications => Params);
76a1c25b 2416 end Make_Disp_Asynchronous_Select_Spec;
ee6ba406 2417
76a1c25b 2418 ---------------------------------------
2419 -- Make_Disp_Conditional_Select_Body --
2420 ---------------------------------------
ee6ba406 2421
cdb1c38f 2422 -- For interface types, generate:
2423
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
a053db0d 2432 -- F := False;
2433 -- C := Ada.Tags.POK_Function;
cdb1c38f 2434 -- end _Disp_Conditional_Select;
2435
2436 -- For protected types, generate:
2437
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;
2448
2449 -- begin
2450 -- C := Ada.Tags.Get_Prim_Op_Kind (Ada.Tags.Tag (<Typ>VP, S));
2451
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;
2459
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;
2469
2470 -- For task types, generate:
2471
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;
2480
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;
2490
76a1c25b 2491 function Make_Disp_Conditional_Select_Body
2492 (Typ : Entity_Id) return Node_Id
2493 is
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;
acf97c11 2498 Obj_Ref : Node_Id;
76a1c25b 2499 Stmts : constant List_Id := New_List;
bf7f5966 2500 Tag_Node : Node_Id;
ee6ba406 2501
76a1c25b 2502 begin
68f95949 2503 pragma Assert (not Restriction_Active (No_Dispatching_Calls));
2504
952af0b9 2505 -- Null body is generated for interface types
2506
76a1c25b 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,
a053db0d 2516 New_List (Make_Assignment_Statement (Loc,
aabafdc2 2517 Name => Make_Identifier (Loc, Name_uF),
a053db0d 2518 Expression => New_Reference_To (Standard_False, Loc)))));
76a1c25b 2519 end if;
ee6ba406 2520
952af0b9 2521 if Is_Concurrent_Record_Type (Typ) then
2522 Conc_Typ := Corresponding_Concurrent_Type (Typ);
ee6ba406 2523
76a1c25b 2524 -- Generate:
2525 -- I : Integer;
ee6ba406 2526
76a1c25b 2527 -- where I will be used to capture the entry index of the primitive
2528 -- wrapper at position S.
ee6ba406 2529
76a1c25b 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)));
ee6ba406 2536
952af0b9 2537 -- Generate:
cdb1c38f 2538 -- C := Ada.Tags.Get_Prim_Op_Kind (Ada.Tags.Tag! (<type>VP), S);
ee6ba406 2539
952af0b9 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;
aad6babd 2547
e58ae6f1 2548 Build_Common_Dispatching_Select_Statements (Typ, Stmts);
aad6babd 2549
76a1c25b 2550 -- Generate:
2551 -- Bnn : Communication_Block;
aad6babd 2552
cdb1c38f 2553 -- where Bnn is the name of the communication block used in the
2554 -- call to Protected_Entry_Call.
aad6babd 2555
ec97ce79 2556 Blk_Nam := Make_Temporary (Loc, 'B');
76a1c25b 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)));
aad6babd 2563
76a1c25b 2564 -- Generate:
cdb1c38f 2565 -- I := Ada.Tags.Get_Entry_Index (Ada.Tags.Tag! (<type>VP), S);
aad6babd 2566
76a1c25b 2567 -- I is the entry index and S is the dispatch table slot
aad6babd 2568
bf7f5966 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));
2574
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;
2581
76a1c25b 2582 Append_To (Stmts,
2583 Make_Assignment_Statement (Loc,
55868293 2584 Name => Make_Identifier (Loc, Name_uI),
76a1c25b 2585 Expression =>
725a69d2 2586 Make_Function_Call (Loc,
cdb1c38f 2587 Name =>
2588 New_Reference_To (RTE (RE_Get_Entry_Index), Loc),
2589 Parameter_Associations =>
2590 New_List (
bf7f5966 2591 Tag_Node,
cdb1c38f 2592 Make_Identifier (Loc, Name_uS)))));
ee6ba406 2593
76a1c25b 2594 if Ekind (Conc_Typ) = E_Protected_Type then
ee6ba406 2595
acf97c11 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)));
ee6ba406 2603
acf97c11 2604 case Corresponding_Runtime_Package (Conc_Typ) is
2605 when System_Tasking_Protected_Objects_Entries =>
2606 -- Generate:
e1c20931 2607
acf97c11 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
e1c20931 2614
acf97c11 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.
d62940bf 2618
acf97c11 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,
d62940bf 2626
acf97c11 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)),
2632
2633 Make_Identifier (Loc, Name_uP), -- parameter block
2634
2635 New_Reference_To ( -- Conditional_Call
2636 RTE (RE_Conditional_Call), Loc),
2637 New_Reference_To ( -- Bnn
2638 Blk_Nam, Loc))));
2639
2640 when System_Tasking_Protected_Objects_Single_Entry =>
2641
2642 -- If we are compiling for a restricted run-time, the call
2643 -- uses the simpler form.
2644
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,
2653
2654 Make_Attribute_Reference (Loc,
55868293 2655 Prefix => Make_Identifier (Loc, Name_uP),
acf97c11 2656 Attribute_Name => Name_Address),
2657
2658 New_Reference_To
2659 (RTE (RE_Conditional_Call), Loc))));
2660 when others =>
2661 raise Program_Error;
2662 end case;
d62940bf 2663
76a1c25b 2664 -- Generate:
2665 -- F := not Cancelled (Bnn);
e1c20931 2666
76a1c25b 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.
e1c20931 2669
76a1c25b 2670 Append_To (Stmts,
2671 Make_Assignment_Statement (Loc,
55868293 2672 Name => Make_Identifier (Loc, Name_uF),
76a1c25b 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);
d62940bf 2684
76a1c25b 2685 -- Generate:
cdb1c38f 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
d62940bf 2692
76a1c25b 2693 -- where T is the task object, I is the entry index, P are the
2694 -- wrapped parameters and F is the status flag.
e1c20931 2695
76a1c25b 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 (
2702
2703 Make_Selected_Component (Loc, -- T._task_id
55868293 2704 Prefix => Make_Identifier (Loc, Name_uT),
2705 Selector_Name => Make_Identifier (Loc, Name_uTask_Id)),
76a1c25b 2706
2707 Make_Unchecked_Type_Conversion (Loc, -- entry index
2708 Subtype_Mark =>
2709 New_Reference_To (RTE (RE_Task_Entry_Index), Loc),
55868293 2710 Expression => Make_Identifier (Loc, Name_uI)),
76a1c25b 2711
2712 Make_Identifier (Loc, Name_uP), -- parameter block
55868293 2713 New_Reference_To -- Conditional_Call
2714 (RTE (RE_Conditional_Call), Loc),
76a1c25b 2715 Make_Identifier (Loc, Name_uF)))); -- status flag
d62940bf 2716 end if;
7c949aad 2717
2718 else
a053db0d 2719 -- Initialize out parameters
7c949aad 2720
a053db0d 2721 Append_To (Stmts,
2722 Make_Assignment_Statement (Loc,
aabafdc2 2723 Name => Make_Identifier (Loc, Name_uF),
a053db0d 2724 Expression => New_Reference_To (Standard_False, Loc)));
2725 Append_To (Stmts,
2726 Make_Assignment_Statement (Loc,
aabafdc2 2727 Name => Make_Identifier (Loc, Name_uC),
a053db0d 2728 Expression => New_Reference_To (RTE (RE_POK_Function), Loc)));
76a1c25b 2729 end if;
2730
2731 return
2732 Make_Subprogram_Body (Loc,
aabafdc2 2733 Specification =>
76a1c25b 2734 Make_Disp_Conditional_Select_Spec (Typ),
aabafdc2 2735 Declarations => Decls,
76a1c25b 2736 Handled_Statement_Sequence =>
2737 Make_Handled_Sequence_Of_Statements (Loc, Stmts));
2738 end Make_Disp_Conditional_Select_Body;
2739
2740 ---------------------------------------
2741 -- Make_Disp_Conditional_Select_Spec --
2742 ---------------------------------------
2743
2744 function Make_Disp_Conditional_Select_Spec
2745 (Typ : Entity_Id) return Node_Id
2746 is
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;
2752
2753 begin
68f95949 2754 pragma Assert (not Restriction_Active (No_Dispatching_Calls));
2755
725a69d2 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
2761
2762 Append_List_To (Params, New_List (
2763
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),
2771
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)),
2777
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)),
76a1c25b 2783
725a69d2 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),
76a1c25b 2790
725a69d2 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)));
76a1c25b 2797
2798 return
2799 Make_Procedure_Specification (Loc,
2800 Defining_Unit_Name => Def_Id,
2801 Parameter_Specifications => Params);
2802 end Make_Disp_Conditional_Select_Spec;
2803
2804 -------------------------------------
2805 -- Make_Disp_Get_Prim_Op_Kind_Body --
2806 -------------------------------------
2807
2808 function Make_Disp_Get_Prim_Op_Kind_Body
2809 (Typ : Entity_Id) return Node_Id
2810 is
bf7f5966 2811 Loc : constant Source_Ptr := Sloc (Typ);
2812 Tag_Node : Node_Id;
76a1c25b 2813
2814 begin
68f95949 2815 pragma Assert (not Restriction_Active (No_Dispatching_Calls));
2816
76a1c25b 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))));
e1c20931 2827 end if;
2828
d62940bf 2829 -- Generate:
76a1c25b 2830 -- C := get_prim_op_kind (tag! (<type>VP), S);
ee6ba406 2831
76a1c25b 2832 -- where C is the out parameter capturing the call kind and S is the
2833 -- dispatch table slot number.
ee6ba406 2834
bf7f5966 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));
2840
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;
2847
76a1c25b 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 =>
725a69d2 2861 Make_Function_Call (Loc,
2862 Name =>
2863 New_Reference_To (RTE (RE_Get_Prim_Op_Kind), Loc),
2864 Parameter_Associations => New_List (
bf7f5966 2865 Tag_Node,
2866 Make_Identifier (Loc, Name_uS)))))));
76a1c25b 2867 end Make_Disp_Get_Prim_Op_Kind_Body;
e1c20931 2868
76a1c25b 2869 -------------------------------------
2870 -- Make_Disp_Get_Prim_Op_Kind_Spec --
2871 -------------------------------------
e1c20931 2872
76a1c25b 2873 function Make_Disp_Get_Prim_Op_Kind_Spec
2874 (Typ : Entity_Id) return Node_Id
2875 is
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;
e1c20931 2881
76a1c25b 2882 begin
68f95949 2883 pragma Assert (not Restriction_Active (No_Dispatching_Calls));
2884
725a69d2 2885 -- T : in out Typ; -- Object parameter
2886 -- S : Integer; -- Primitive operation slot
2887 -- C : out Prim_Op_Kind; -- Call kind
2888
2889 Append_List_To (Params, New_List (
2890
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),
ee6ba406 2898
725a69d2 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)),
ee6ba406 2904
725a69d2 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)));
76a1c25b 2911
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;
2917
2918 --------------------------------
2919 -- Make_Disp_Get_Task_Id_Body --
2920 --------------------------------
2921
2922 function Make_Disp_Get_Task_Id_Body
2923 (Typ : Entity_Id) return Node_Id
2924 is
2925 Loc : constant Source_Ptr := Sloc (Typ);
2926 Ret : Node_Id;
2927
2928 begin
68f95949 2929 pragma Assert (not Restriction_Active (No_Dispatching_Calls));
2930
76a1c25b 2931 if Is_Concurrent_Record_Type (Typ)
2932 and then Ekind (Corresponding_Concurrent_Type (Typ)) = E_Task_Type
2933 then
725a69d2 2934 -- Generate:
2935 -- return To_Address (_T._task_id);
2936
76a1c25b 2937 Ret :=
17e14451 2938 Make_Simple_Return_Statement (Loc,
76a1c25b 2939 Expression =>
725a69d2 2940 Make_Unchecked_Type_Conversion (Loc,
2941 Subtype_Mark =>
2942 New_Reference_To (RTE (RE_Address), Loc),
2943 Expression =>
2944 Make_Selected_Component (Loc,
55868293 2945 Prefix => Make_Identifier (Loc, Name_uT),
2946 Selector_Name => Make_Identifier (Loc, Name_uTask_Id))));
76a1c25b 2947
2948 -- A null body is constructed for non-task types
2949
2950 else
725a69d2 2951 -- Generate:
2952 -- return Null_Address;
2953
76a1c25b 2954 Ret :=
17e14451 2955 Make_Simple_Return_Statement (Loc,
76a1c25b 2956 Expression =>
725a69d2 2957 New_Reference_To (RTE (RE_Null_Address), Loc));
76a1c25b 2958 end if;
2959
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;
2970
2971 --------------------------------
2972 -- Make_Disp_Get_Task_Id_Spec --
2973 --------------------------------
2974
2975 function Make_Disp_Get_Task_Id_Spec
2976 (Typ : Entity_Id) return Node_Id
2977 is
725a69d2 2978 Loc : constant Source_Ptr := Sloc (Typ);
76a1c25b 2979
2980 begin
68f95949 2981 pragma Assert (not Restriction_Active (No_Dispatching_Calls));
2982
76a1c25b 2983 return
2984 Make_Function_Specification (Loc,
725a69d2 2985 Defining_Unit_Name =>
2986 Make_Defining_Identifier (Loc, Name_uDisp_Get_Task_Id),
76a1c25b 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 =>
725a69d2 2994 New_Reference_To (RTE (RE_Address), Loc));
76a1c25b 2995 end Make_Disp_Get_Task_Id_Spec;
2996
cdb1c38f 2997 ----------------------------
2998 -- Make_Disp_Requeue_Body --
2999 ----------------------------
3000
3001 function Make_Disp_Requeue_Body
3002 (Typ : Entity_Id) return Node_Id
3003 is
3004 Loc : constant Source_Ptr := Sloc (Typ);
3005 Conc_Typ : Entity_Id := Empty;
3006 Stmts : constant List_Id := New_List;
3007
3008 begin
3009 pragma Assert (not Restriction_Active (No_Dispatching_Calls));
3010
3011 -- Null body is generated for interface types and non-concurrent
3012 -- tagged types.
3013
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;
3027
3028 Conc_Typ := Corresponding_Concurrent_Type (Typ);
3029
3030 if Ekind (Conc_Typ) = E_Protected_Type then
3031
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;
3047
acf97c11 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,
55868293 3053 Condition => Make_Identifier (Loc, Name_uF),
cdb1c38f 3054
acf97c11 3055 Then_Statements =>
3056 New_List (
cdb1c38f 3057
acf97c11 3058 -- Call to Requeue_Protected_Entry
cdb1c38f 3059
acf97c11 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 (
3066
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)),
3073
3074 Make_Attribute_Reference (Loc, -- O._object'Acc
3075 Attribute_Name =>
3076 Name_Unchecked_Access,
3077 Prefix =>
3078 Make_Selected_Component (Loc,
55868293 3079 Prefix =>
acf97c11 3080 Make_Identifier (Loc, Name_uO),
3081 Selector_Name =>
3082 Make_Identifier (Loc, Name_uObject))),
3083
3084 Make_Unchecked_Type_Conversion (Loc, -- entry index
3085 Subtype_Mark =>
3086 New_Reference_To (
3087 RTE (RE_Protected_Entry_Index), Loc),
55868293 3088 Expression => Make_Identifier (Loc, Name_uI)),
cdb1c38f 3089
acf97c11 3090 Make_Identifier (Loc, Name_uA)))), -- abort status
cdb1c38f 3091
acf97c11 3092 Else_Statements =>
3093 New_List (
cdb1c38f 3094
acf97c11 3095 -- Call to Requeue_Task_To_Protected_Entry
cdb1c38f 3096
acf97c11 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 (
3103
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))),
3113
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)),
cdb1c38f 3120
acf97c11 3121 Make_Identifier (Loc, Name_uA)))))); -- abort status
3122 end if;
cdb1c38f 3123 else
3124 pragma Assert (Is_Task_Type (Conc_Typ));
3125
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;
3139
3140 Append_To (Stmts,
3141 Make_If_Statement (Loc,
55868293 3142 Condition => Make_Identifier (Loc, Name_uF),
cdb1c38f 3143
55868293 3144 Then_Statements => New_List (
cdb1c38f 3145
55868293 3146 -- Call to Requeue_Protected_To_Task_Entry
cdb1c38f 3147
55868293 3148 Make_Procedure_Call_Statement (Loc,
3149 Name =>
3150 New_Reference_To
3151 (RTE (RE_Requeue_Protected_To_Task_Entry), Loc),
cdb1c38f 3152
55868293 3153 Parameter_Associations => New_List (
cdb1c38f 3154
55868293 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)),
cdb1c38f 3160
55868293 3161 Make_Selected_Component (Loc, -- O._task_id
3162 Prefix => Make_Identifier (Loc, Name_uO),
3163 Selector_Name => Make_Identifier (Loc, Name_uTask_Id)),
cdb1c38f 3164
55868293 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)),
cdb1c38f 3169
55868293 3170 Make_Identifier (Loc, Name_uA)))), -- abort status
cdb1c38f 3171
55868293 3172 Else_Statements => New_List (
cdb1c38f 3173
55868293 3174 -- Call to Requeue_Task_Entry
cdb1c38f 3175
55868293 3176 Make_Procedure_Call_Statement (Loc,
3177 Name => New_Reference_To (RTE (RE_Requeue_Task_Entry), Loc),
cdb1c38f 3178
55868293 3179 Parameter_Associations => New_List (
cdb1c38f 3180
55868293 3181 Make_Selected_Component (Loc, -- O._task_id
3182 Prefix => Make_Identifier (Loc, Name_uO),
3183 Selector_Name => Make_Identifier (Loc, Name_uTask_Id)),
cdb1c38f 3184
55868293 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)),
cdb1c38f 3189
55868293 3190 Make_Identifier (Loc, Name_uA)))))); -- abort status
cdb1c38f 3191 end if;
3192
3193 -- Even though no declarations are needed in both cases, we allocate
3194 -- a list for entities added by Freeze.
3195
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;
3205
3206 ----------------------------
3207 -- Make_Disp_Requeue_Spec --
3208 ----------------------------
3209
3210 function Make_Disp_Requeue_Spec
3211 (Typ : Entity_Id) return Node_Id
3212 is
3213 Loc : constant Source_Ptr := Sloc (Typ);
3214
3215 begin
3216 pragma Assert (not Restriction_Active (No_Dispatching_Calls));
3217
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
3223
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.
3227
3228 return
3229 Make_Procedure_Specification (Loc,
3230 Defining_Unit_Name =>
3231 Make_Defining_Identifier (Loc, Name_uDisp_Requeue),
3232
3233 Parameter_Specifications =>
3234 New_List (
3235
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),
3243
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)),
3249
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)),
3255
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)),
3261
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;
3268
76a1c25b 3269 ---------------------------------
3270 -- Make_Disp_Timed_Select_Body --
3271 ---------------------------------
3272
cdb1c38f 3273 -- For interface types, generate:
3274
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
a053db0d 3285 -- F := False;
3286 -- C := Ada.Tags.POK_Function;
cdb1c38f 3287 -- end _Disp_Timed_Select;
3288
3289 -- For protected types, generate:
3290
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;
3301
3302 -- begin
3303 -- C := Ada.Tags.Get_Prim_Op_Kind (Ada.Tags.Tag (<Typ>VP), S);
3304
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;
3312
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;
3323
3324 -- For task types, generate:
3325
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;
3336
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,
a053db0d 3345 -- F);
cdb1c38f 3346 -- end _Disp_Time_Select;
3347
76a1c25b 3348 function Make_Disp_Timed_Select_Body
3349 (Typ : Entity_Id) return Node_Id
3350 is
3351 Loc : constant Source_Ptr := Sloc (Typ);
3352 Conc_Typ : Entity_Id := Empty;
3353 Decls : constant List_Id := New_List;
acf97c11 3354 Obj_Ref : Node_Id;
76a1c25b 3355 Stmts : constant List_Id := New_List;
bf7f5966 3356 Tag_Node : Node_Id;
76a1c25b 3357
3358 begin
68f95949 3359 pragma Assert (not Restriction_Active (No_Dispatching_Calls));
3360
952af0b9 3361 -- Null body is generated for interface types
3362
76a1c25b 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,
aabafdc2 3372 New_List (
3373 Make_Assignment_Statement (Loc,
3374 Name => Make_Identifier (Loc, Name_uF),
3375 Expression => New_Reference_To (Standard_False, Loc)))));
76a1c25b 3376 end if;
3377
952af0b9 3378 if Is_Concurrent_Record_Type (Typ) then
3379 Conc_Typ := Corresponding_Concurrent_Type (Typ);
76a1c25b 3380
3381 -- Generate:
3382 -- I : Integer;
3383
3384 -- where I will be used to capture the entry index of the primitive
3385 -- wrapper at position S.
3386
3387 Append_To (Decls,
3388 Make_Object_Declaration (Loc,
aabafdc2 3389 Defining_Identifier => Make_Defining_Identifier (Loc, Name_uI),
3390 Object_Definition => New_Reference_To (Standard_Integer, Loc)));
76a1c25b 3391
952af0b9 3392 -- Generate:
3393 -- C := Get_Prim_Op_Kind (tag! (<type>VP), S);
76a1c25b 3394
952af0b9 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;
76a1c25b 3402
e58ae6f1 3403 Build_Common_Dispatching_Select_Statements (Typ, Stmts);
76a1c25b 3404
3405 -- Generate:
952af0b9 3406 -- I := Get_Entry_Index (tag! (<type>VP), S);
76a1c25b 3407
3408 -- I is the entry index and S is the dispatch table slot
3409
bf7f5966 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));
3415
3416 else
3417 Tag_Node :=
3418 Make_Attribute_Reference (Loc,
aabafdc2 3419 Prefix => New_Reference_To (Typ, Loc),
bf7f5966 3420 Attribute_Name => Name_Tag);
3421 end if;
3422
76a1c25b 3423 Append_To (Stmts,
3424 Make_Assignment_Statement (Loc,
55868293 3425 Name => Make_Identifier (Loc, Name_uI),
76a1c25b 3426 Expression =>
725a69d2 3427 Make_Function_Call (Loc,
aabafdc2 3428 Name => New_Reference_To (RTE (RE_Get_Entry_Index), Loc),
cdb1c38f 3429 Parameter_Associations =>
3430 New_List (
bf7f5966 3431 Tag_Node,
cdb1c38f 3432 Make_Identifier (Loc, Name_uS)))));
76a1c25b 3433
acf97c11 3434 -- Protected case
3435
76a1c25b 3436 if Ekind (Conc_Typ) = E_Protected_Type then
3437
acf97c11 3438 -- Build T._object'Access
3439
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)));
3447
3448 -- Normal case, No_Entry_Queue restriction not active. In this
3449 -- case we generate:
3450
3451 -- Timed_Protected_Entry_Call
3452 -- (T._object'access,
cdb1c38f 3453 -- Protected_Entry_Index! (I),
acf97c11 3454 -- P, D, M, F);
76a1c25b 3455
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.
3459
acf97c11 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,
3470
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)),
76a1c25b 3477
acf97c11 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
76a1c25b 3482
acf97c11 3483 when System_Tasking_Protected_Objects_Single_Entry =>
3484 -- Generate:
76a1c25b 3485
acf97c11 3486 -- Timed_Protected_Single_Entry_Call
3487 -- (T._object'access, P, D, M, F);
3488
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.
3492
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
3505
3506 when others =>
3507 raise Program_Error;
3508 end case;
3509
3510 -- Task case
ee6ba406 3511
ee6ba406 3512 else
76a1c25b 3513 pragma Assert (Ekind (Conc_Typ) = E_Task_Type);
3514
3515 -- Generate:
3516 -- Timed_Task_Entry_Call (
3517 -- T._task_id,
cdb1c38f 3518 -- Task_Entry_Index! (I),
76a1c25b 3519 -- P,
3520 -- D,
3521 -- M,
3522 -- F);
3523
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.
3527
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 (
3534
3535 Make_Selected_Component (Loc, -- T._task_id
55868293 3536 Prefix => Make_Identifier (Loc, Name_uT),
3537 Selector_Name => Make_Identifier (Loc, Name_uTask_Id)),
76a1c25b 3538
3539 Make_Unchecked_Type_Conversion (Loc, -- entry index
3540 Subtype_Mark =>
3541 New_Reference_To (RTE (RE_Task_Entry_Index), Loc),
55868293 3542 Expression => Make_Identifier (Loc, Name_uI)),
76a1c25b 3543
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
ee6ba406 3548 end if;
7c949aad 3549
3550 else
a053db0d 3551 -- Initialize out parameters
7c949aad 3552
a053db0d 3553 Append_To (Stmts,
3554 Make_Assignment_Statement (Loc,
aabafdc2 3555 Name => Make_Identifier (Loc, Name_uF),
a053db0d 3556 Expression => New_Reference_To (Standard_False, Loc)));
3557 Append_To (Stmts,
3558 Make_Assignment_Statement (Loc,
aabafdc2 3559 Name => Make_Identifier (Loc, Name_uC),
a053db0d 3560 Expression => New_Reference_To (RTE (RE_POK_Function), Loc)));
76a1c25b 3561 end if;
3562
3563 return
3564 Make_Subprogram_Body (Loc,
aabafdc2 3565 Specification => Make_Disp_Timed_Select_Spec (Typ),
3566 Declarations => Decls,
76a1c25b 3567 Handled_Statement_Sequence =>
3568 Make_Handled_Sequence_Of_Statements (Loc, Stmts));
3569 end Make_Disp_Timed_Select_Body;
3570
3571 ---------------------------------
3572 -- Make_Disp_Timed_Select_Spec --
3573 ---------------------------------
3574
3575 function Make_Disp_Timed_Select_Spec
3576 (Typ : Entity_Id) return Node_Id
3577 is
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;
ee6ba406 3583
76a1c25b 3584 begin
68f95949 3585 pragma Assert (not Restriction_Active (No_Dispatching_Calls));
3586
725a69d2 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
76a1c25b 3594
725a69d2 3595 Append_List_To (Params, New_List (
3596
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),
3604
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)),
3610
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)),
76a1c25b 3616
76a1c25b 3617 Make_Parameter_Specification (Loc,
3618 Defining_Identifier =>
3619 Make_Defining_Identifier (Loc, Name_uD),
3620 Parameter_Type =>
725a69d2 3621 New_Reference_To (Standard_Duration, Loc)),
76a1c25b 3622
76a1c25b 3623 Make_Parameter_Specification (Loc,
3624 Defining_Identifier =>
3625 Make_Defining_Identifier (Loc, Name_uM),
3626 Parameter_Type =>
725a69d2 3627 New_Reference_To (Standard_Integer, Loc)),
ee6ba406 3628
725a69d2 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)));
ee6ba406 3635
725a69d2 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));
ee6ba406 3643
76a1c25b 3644 return
3645 Make_Procedure_Specification (Loc,
3646 Defining_Unit_Name => Def_Id,
3647 Parameter_Specifications => Params);
3648 end Make_Disp_Timed_Select_Spec;
ee6ba406 3649
76a1c25b 3650 -------------
3651 -- Make_DT --
3652 -------------
ee6ba406 3653
725a69d2 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.
3661
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:
3666
3667 -- procedure Example is
3668 -- package Pkg is
3669 -- type T1 is tagged null record;
3670 -- procedure Prim (O : T1);
3671 -- end Pkg;
3672
3673 -- type T2 is new Pkg.T1 with null record;
3674 -- procedure Prim (X : T2) is -- late overriding
3675 -- begin
3676 -- ...
3677 -- ...
3678 -- end;
952af0b9 3679
17e14451 3680 function Make_DT (Typ : Entity_Id; N : Node_Id := Empty) return List_Id is
3681 Loc : constant Source_Ptr := Sloc (Typ);
3682
725a69d2 3683 Max_Predef_Prims : constant Int :=
3684 UI_To_Int
3685 (Intval
3686 (Expression
17e14451 3687 (Parent (RTE (RE_Max_Predef_Prims)))));
3688
cc60bd16 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
3692
349db231 3693 procedure Check_Premature_Freezing
3694 (Subp : Entity_Id;
3695 Tagged_Type : Entity_Id;
3696 Typ : Entity_Id);
17e14451 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.
349db231 3707 -- More complex cases involve composite types that have one private
3708 -- unfrozen subcomponent.
725a69d2 3709
f301a57b 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.
24971415 3718
725a69d2 3719 procedure Make_Secondary_DT
acf97c11 3720 (Typ : Entity_Id;
3721 Iface : Entity_Id;
f301a57b 3722 Suffix_Index : Int;
acf97c11 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);
cdb1c38f 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
278c67dc 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.
9dfe12ae 3743
17e14451 3744 ------------------------------
3745 -- Check_Premature_Freezing --
3746 ------------------------------
3747
349db231 3748 procedure Check_Premature_Freezing
3749 (Subp : Entity_Id;
3750 Tagged_Type : Entity_Id;
3751 Typ : Entity_Id)
3752 is
3753 Comp : Entity_Id;
aada9bb5 3754
3755 function Is_Actual_For_Formal_Incomplete_Type
3756 (T : Entity_Id) return Boolean;
65a805b2 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
5f8e1c78 3759 -- appears later. It is safe to build the dispatch table in this
3760 -- case, gigi will have full views available.
3761
3762 ------------------------------------------
3763 -- Is_Actual_For_Formal_Incomplete_Type --
3764 ------------------------------------------
3765
aada9bb5 3766 function Is_Actual_For_Formal_Incomplete_Type
3767 (T : Entity_Id) return Boolean
5f8e1c78 3768 is
3769 Gen_Par : Entity_Id;
3770 F : Node_Id;
aada9bb5 3771
5f8e1c78 3772 begin
3773 if not Is_Generic_Instance (Current_Scope)
3774 or else not Used_As_Generic_Actual (T)
3775 then
3776 return False;
3777
3778 else
3779 Gen_Par := Generic_Parent (Parent (Current_Scope));
3780 end if;
3781
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;
3790
3791 Next (F);
3792 end loop;
3793
3794 return False;
3795 end Is_Actual_For_Formal_Incomplete_Type;
278c67dc 3796
aada9bb5 3797 -- Start of processing for Check_Premature_Freezing
3798
17e14451 3799 begin
496b8337 3800 -- Note that if the type is a (subtype of) a generic actual, the
3801 -- actual will have been frozen by the instantiation.
3802
17e14451 3803 if Present (N)
349db231 3804 and then Is_Private_Type (Typ)
17e14451 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)
496b8337 3809 and then not Is_Generic_Actual_Type (Typ)
17e14451 3810 then
3811 Error_Msg_Sloc := Sloc (Subp);
503f7fd3 3812 Error_Msg_NE
17e14451 3813 ("declaration must appear after completion of type &", N, Typ);
3814 Error_Msg_NE
3815 ("\which is an untagged type in the profile of"
349db231 3816 & " primitive operation & declared#", N, Subp);
3817
3818 else
3819 Comp := Private_Component (Typ);
3820
3821 if not Is_Tagged_Type (Typ)
3822 and then Present (Comp)
3823 and then not Is_Frozen (Comp)
5f8e1c78 3824 and then
aada9bb5 3825 not Is_Actual_For_Formal_Incomplete_Type (Comp)
349db231 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;
17e14451 3838 end if;
3839 end Check_Premature_Freezing;
3840
24971415 3841 ---------------
3842 -- Export_DT --
3843 ---------------
3844
f301a57b 3845 procedure Export_DT (Typ : Entity_Id; DT : Entity_Id; Index : Nat := 0)
3846 is
3847 Count : Nat;
3848 Elmt : Elmt_Id;
3849
24971415 3850 begin
3851 Set_Is_Statically_Allocated (DT);
3852 Set_Is_True_Constant (DT);
3853 Set_Is_Exported (DT);
3854
f301a57b 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;
3861
3862 pragma Assert (Related_Type (Node (Elmt)) = Typ);
3863
3864 Get_External_Name
3865 (Entity => Node (Elmt),
3866 Has_Suffix => True);
3867
24971415 3868 Set_Interface_Name (DT,
3869 Make_String_Literal (Loc,
3870 Strval => String_From_Name_Buffer));
3871
3872 -- Ensure proper Sprint output of this implicit importation
3873
3874 Set_Is_Internal (DT);
3875 Set_Is_Public (DT);
3876 end Export_DT;
3877
725a69d2 3878 -----------------------
3879 -- Make_Secondary_DT --
3880 -----------------------
ee6ba406 3881
725a69d2 3882 procedure Make_Secondary_DT
acf97c11 3883 (Typ : Entity_Id;
3884 Iface : Entity_Id;
f301a57b 3885 Suffix_Index : Int;
acf97c11 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)
725a69d2 3891 is
3892 Loc : constant Source_Ptr := Sloc (Typ);
f301a57b 3893 Exporting_Table : constant Boolean :=
3894 Building_Static_DT (Typ)
3895 and then Suffix_Index > 0;
ec97ce79 3896 Iface_DT : constant Entity_Id := Make_Temporary (Loc, 'T');
3897 Predef_Prims : constant Entity_Id := Make_Temporary (Loc, 'R');
725a69d2 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;
343d35dc 3910
725a69d2 3911 begin
17e14451 3912 -- Handle cases in which we do not generate statically allocated
3913 -- dispatch tables.
343d35dc 3914
24971415 3915 if not Building_Static_DT (Typ) then
725a69d2 3916 Set_Ekind (Predef_Prims, E_Variable);
725a69d2 3917 Set_Ekind (Iface_DT, E_Variable);
343d35dc 3918
725a69d2 3919 -- Statically allocated dispatch tables and related entities are
3920 -- constants.
343d35dc 3921
725a69d2 3922 else
3923 Set_Ekind (Predef_Prims, E_Constant);
3924 Set_Is_Statically_Allocated (Predef_Prims);
3925 Set_Is_True_Constant (Predef_Prims);
343d35dc 3926
725a69d2 3927 Set_Ekind (Iface_DT, E_Constant);
3928 Set_Is_Statically_Allocated (Iface_DT);
3929 Set_Is_True_Constant (Iface_DT);
343d35dc 3930 end if;
3931
f301a57b 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
0c826ed4 3934 -- DT because at run time the pointer to this dummy entry will be
f301a57b 3935 -- used as the tag.
68f95949 3936
cdb1c38f 3937 if Num_Iface_Prims = 0 then
725a69d2 3938 Empty_DT := True;
3939 Nb_Prim := 1;
cdb1c38f 3940 else
3941 Nb_Prim := Num_Iface_Prims;
725a69d2 3942 end if;
76a1c25b 3943
725a69d2 3944 -- Generate:
952af0b9 3945
725a69d2 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
952af0b9 3952
725a69d2 3953 -- Stage 1: Calculate the number of predefined primitives
76a1c25b 3954
24971415 3955 if not Building_Static_DT (Typ) then
725a69d2 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);
aad6babd 3961
725a69d2 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));
aad6babd 3966
725a69d2 3967 if Pos > Nb_Predef_Prims then
3968 Nb_Predef_Prims := Pos;
3969 end if;
3970 end if;
aad6babd 3971
725a69d2 3972 Next_Elmt (Prim_Elmt);
3973 end loop;
3974 end if;
aad6babd 3975
725a69d2 3976 -- Stage 2: Create the thunks associated with the predefined
3977 -- primitives and save their entity to fill the aggregate.
ee6ba406 3978
725a69d2 3979 declare
3980 Prim_Table : array (Nat range 1 .. Nb_Predef_Prims) of Entity_Id;
cc60bd16 3981 Decl : Node_Id;
725a69d2 3982 Thunk_Id : Entity_Id;
3983 Thunk_Code : Node_Id;
aad6babd 3984
725a69d2 3985 begin
3986 Prim_Ops_Aggr_List := New_List;
3987 Prim_Table := (others => Empty);
aad6babd 3988
cdb1c38f 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);
aad6babd 3993
cdb1c38f 3994 if Is_Predefined_Dispatching_Operation (Prim)
3995 and then not Is_Abstract_Subprogram (Prim)
3f8cf2d2 3996 and then not Is_Eliminated (Prim)
cdb1c38f 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);
aad6babd 4003
cdb1c38f 4004 else
fc2907f6 4005 Expand_Interface_Thunk
4006 (Ultimate_Alias (Prim), Thunk_Id, Thunk_Code);
aad6babd 4007
cdb1c38f 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;
725a69d2 4014 end if;
aad6babd 4015
cdb1c38f 4016 Next_Elmt (Prim_Elmt);
4017 end loop;
4018 end if;
aad6babd 4019
725a69d2 4020 for J in Prim_Table'Range loop
4021 if Present (Prim_Table (J)) then
4022 New_Node :=
cc60bd16 4023 Unchecked_Convert_To (RTE (RE_Prim_Ptr),
acf97c11 4024 Make_Attribute_Reference (Loc,
4025 Prefix => New_Reference_To (Prim_Table (J), Loc),
4026 Attribute_Name => Name_Unrestricted_Access));
725a69d2 4027 else
cc60bd16 4028 New_Node := Make_Null (Loc);
725a69d2 4029 end if;
952af0b9 4030
725a69d2 4031 Append_To (Prim_Ops_Aggr_List, New_Node);
4032 end loop;
952af0b9 4033
cc60bd16 4034 New_Node :=
4035 Make_Aggregate (Loc,
4036 Expressions => Prim_Ops_Aggr_List);
4037
4038 -- Remember aggregates initializing dispatch tables
4039
4040 Append_Elmt (New_Node, DT_Aggr);
4041
4042 Decl :=
4043 Make_Subtype_Declaration (Loc,
ec97ce79 4044 Defining_Identifier => Make_Temporary (Loc, 'S'),
4045 Subtype_Indication =>
cc60bd16 4046 New_Reference_To (RTE (RE_Address_Array), Loc));
4047
4048 Append_To (Result, Decl);
4049
725a69d2 4050 Append_To (Result,
4051 Make_Object_Declaration (Loc,
4052 Defining_Identifier => Predef_Prims,
24971415 4053 Constant_Present => Building_Static_DT (Typ),
725a69d2 4054 Aliased_Present => True,
cc60bd16 4055 Object_Definition => New_Reference_To
4056 (Defining_Identifier (Decl), Loc),
4057 Expression => New_Node));
aad6babd 4058
725a69d2 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;
aad6babd 4069
725a69d2 4070 -- Generate
76a1c25b 4071
725a69d2 4072 -- OSD : Ada.Tags.Object_Specific_Data (Nb_Prims) :=
4073 -- (OSD_Table => (1 => <value>,
4074 -- ...
4075 -- N => <value>));
76a1c25b 4076
725a69d2 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));
f301a57b 4087 -- for Iface_DT'Alignment use Address'Alignment;
76a1c25b 4088
725a69d2 4089 -- Stage 3: Initialize the discriminant and the record components
aad6babd 4090
725a69d2 4091 DT_Constr_List := New_List;
4092 DT_Aggr_List := New_List;
343d35dc 4093
725a69d2 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.
343d35dc 4096
725a69d2 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;
343d35dc 4102
725a69d2 4103 Append_To (DT_Constr_List, New_Node);
4104 Append_To (DT_Aggr_List, New_Copy (New_Node));
343d35dc 4105
725a69d2 4106 -- Signature
343d35dc 4107
725a69d2 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;
343d35dc 4112
725a69d2 4113 -- Tag_Kind
343d35dc 4114
725a69d2 4115 if RTE_Record_Component_Available (RE_Tag_Kind) then
4116 Append_To (DT_Aggr_List, Tagged_Kind (Typ));
4117 end if;
aad6babd 4118
725a69d2 4119 -- Predef_Prims
aad6babd 4120
725a69d2 4121 Append_To (DT_Aggr_List,
4122 Make_Attribute_Reference (Loc,
4123 Prefix => New_Reference_To (Predef_Prims, Loc),
4124 Attribute_Name => Name_Address));
aad6babd 4125
725a69d2 4126 -- Note: The correct value of Offset_To_Top will be set by the init
4127 -- subprogram
aad6babd 4128
725a69d2 4129 Append_To (DT_Aggr_List, Make_Integer_Literal (Loc, 0));
aad6babd 4130
725a69d2 4131 -- Generate the Object Specific Data table required to dispatch calls
4132 -- through synchronized interfaces.
aad6babd 4133
725a69d2 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)
a652dd51 4139 or else not Has_Interfaces (Typ)
cdb1c38f 4140 or else not Build_Thunks
38d2fa31 4141 or else not RTE_Record_Component_Available (RE_OSD_Table)
725a69d2 4142 then
4143 -- No OSD table required
ee6ba406 4144
725a69d2 4145 Append_To (DT_Aggr_List,
4146 New_Reference_To (RTE (RE_Null_Address), Loc));
d62940bf 4147
725a69d2 4148 else
4149 OSD_Aggr_List := New_List;
d62940bf 4150
725a69d2 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;
d62940bf 4159
725a69d2 4160 begin
4161 Prim_Table := (others => Empty);
4162 Prim_Alias := Empty;
d62940bf 4163
725a69d2 4164 Prim_Elmt := First_Elmt (Primitive_Operations (Typ));
4165 while Present (Prim_Elmt) loop
4166 Prim := Node (Prim_Elmt);
d62940bf 4167
a652dd51 4168 if Present (Interface_Alias (Prim))
725a69d2 4169 and then Find_Dispatching_Type
a652dd51 4170 (Interface_Alias (Prim)) = Iface
725a69d2 4171 then
a652dd51 4172 Prim_Alias := Interface_Alias (Prim);
fc2907f6 4173 E := Ultimate_Alias (Prim);
725a69d2 4174 Pos := UI_To_Int (DT_Position (Prim_Alias));
68f95949 4175
725a69d2 4176 if Present (Prim_Table (Pos)) then
4177 pragma Assert (Prim_Table (Pos) = E);
4178 null;
68f95949 4179
725a69d2 4180 else
4181 Prim_Table (Pos) := E;
4182
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)))));
4191
4192 Count := Count + 1;
4193 end if;
4194 end if;
4195
4196 Next_Elmt (Prim_Elmt);
4197 end loop;
4198 pragma Assert (Count = Nb_Prim);
4199 end;
4200
ec97ce79 4201 OSD := Make_Temporary (Loc, 'I');
725a69d2 4202
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)))),
725a69d2 4214
ec97ce79 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)),
4224
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))))));
725a69d2 4231
17e14451 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)));
4241
725a69d2 4242 -- In secondary dispatch tables the Typeinfo component contains
4243 -- the address of the Object Specific Data (see a-tags.ads)
4244
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;
4250
4251 -- Initialize the table of primitive operations
4252
4253 Prim_Ops_Aggr_List := New_List;
4254
4255 if Empty_DT then
cc60bd16 4256 Append_To (Prim_Ops_Aggr_List, Make_Null (Loc));
725a69d2 4257
4258 elsif Is_Abstract_Type (Typ)
9a479e51 4259 or else not Building_Static_DT (Typ)
725a69d2 4260 then
4261 for J in 1 .. Nb_Prim loop
cc60bd16 4262 Append_To (Prim_Ops_Aggr_List, Make_Null (Loc));
725a69d2 4263 end loop;
4264
4265 else
4266 declare
d00681a7 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;
725a69d2 4273
4274 begin
4275 Prim_Table := (others => Empty);
4276
4277 Prim_Elmt := First_Elmt (Primitive_Operations (Typ));
4278 while Present (Prim_Elmt) loop
d00681a7 4279 Prim := Node (Prim_Elmt);
4280 E := Ultimate_Alias (Prim);
4281 Prim_Pos := UI_To_Int (DT_Position (E));
725a69d2 4282
d00681a7 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.
3f8cf2d2 4288
725a69d2 4289 if not Is_Predefined_Dispatching_Operation (Prim)
a652dd51 4290 and then Present (Interface_Alias (Prim))
725a69d2 4291 and then not Is_Abstract_Subprogram (Alias (Prim))
3f8cf2d2 4292 and then not Is_Eliminated (Alias (Prim))
d00681a7 4293 and then (not Is_CPP_Class (Root_Type (Typ))
4294 or else Prim_Pos > CPP_Nb_Prims)
725a69d2 4295 and then Find_Dispatching_Type
a652dd51 4296 (Interface_Alias (Prim)) = Iface
725a69d2 4297
4298 -- Generate the code of the thunk only if the abstract
4299 -- interface type is not an immediate ancestor of
d00681a7 4300 -- Tagged_Type. Otherwise the DT associated with the
725a69d2 4301 -- interface is the primary DT.
4302
cb4af01d 4303 and then not Is_Ancestor (Iface, Typ,
4304 Use_Full_View => True)
725a69d2 4305 then
cdb1c38f 4306 if not Build_Thunks then
d00681a7 4307 Prim_Pos :=
a652dd51 4308 UI_To_Int (DT_Position (Interface_Alias (Prim)));
d00681a7 4309 Prim_Table (Prim_Pos) := Alias (Prim);
4310
cdb1c38f 4311 else
4312 Expand_Interface_Thunk (Prim, Thunk_Id, Thunk_Code);
725a69d2 4313
cdb1c38f 4314 if Present (Thunk_Id) then
d00681a7 4315 Prim_Pos :=
a652dd51 4316 UI_To_Int (DT_Position (Interface_Alias (Prim)));
cdb1c38f 4317
d00681a7 4318 Prim_Table (Prim_Pos) := Thunk_Id;
cdb1c38f 4319 Append_To (Result, Thunk_Code);
4320 end if;
725a69d2 4321 end if;
4322 end if;
4323
4324 Next_Elmt (Prim_Elmt);
4325 end loop;
4326
4327 for J in Prim_Table'Range loop
4328 if Present (Prim_Table (J)) then
4329 New_Node :=
cc60bd16 4330 Unchecked_Convert_To (RTE (RE_Prim_Ptr),
acf97c11 4331 Make_Attribute_Reference (Loc,
4332 Prefix => New_Reference_To (Prim_Table (J), Loc),
4333 Attribute_Name => Name_Unrestricted_Access));
d00681a7 4334
725a69d2 4335 else
cc60bd16 4336 New_Node := Make_Null (Loc);
725a69d2 4337 end if;
4338
4339 Append_To (Prim_Ops_Aggr_List, New_Node);
4340 end loop;
4341 end;
4342 end if;
4343
cc60bd16 4344 New_Node :=
725a69d2 4345 Make_Aggregate (Loc,
cc60bd16 4346 Expressions => Prim_Ops_Aggr_List);
4347
4348 Append_To (DT_Aggr_List, New_Node);
4349
4350 -- Remember aggregates initializing dispatch tables
4351
4352 Append_Elmt (New_Node, DT_Aggr);
725a69d2 4353
f301a57b 4354 -- Note: Secondary dispatch tables cannot be declared constant
4355 -- because the component Offset_To_Top is currently initialized
4356 -- by the IP routine.
4357
725a69d2 4358 Append_To (Result,
4359 Make_Object_Declaration (Loc,
4360 Defining_Identifier => Iface_DT,
4361 Aliased_Present => True,
f301a57b 4362 Constant_Present => False,
4363
725a69d2 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)),
4370
f301a57b 4371 Expression =>
4372 Make_Aggregate (Loc,
4373 Expressions => DT_Aggr_List)));
725a69d2 4374
17e14451 4375 Append_To (Result,
4376 Make_Attribute_Definition_Clause (Loc,
4377 Name => New_Reference_To (Iface_DT, Loc),
4378 Chars => Name_Alignment,
f301a57b 4379
17e14451 4380 Expression =>
4381 Make_Attribute_Reference (Loc,
f301a57b 4382 Prefix =>
17e14451 4383 New_Reference_To (RTE (RE_Integer_Address), Loc),
4384 Attribute_Name => Name_Alignment)));
4385
f301a57b 4386 if Exporting_Table then
4387 Export_DT (Typ, Iface_DT, Suffix_Index);
4388
725a69d2 4389 -- Generate code to create the pointer to the dispatch table
4390
f301a57b 4391 -- Iface_DT_Ptr : Tag := Tag!(DT.Prims_Ptr'Address);
725a69d2 4392
f301a57b 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.
4395
4396 else
4397 Append_To (Result,
4398 Make_Object_Declaration (Loc,
4399 Defining_Identifier => Iface_DT_Ptr,
4400 Constant_Present => True,
4401
4402 Object_Definition =>
4403 New_Reference_To (RTE (RE_Interface_Tag), Loc),
4404
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;
725a69d2 4416
acf97c11 4417 Append_To (Result,
4418 Make_Object_Declaration (Loc,
4419 Defining_Identifier => Predef_Prims_Ptr,
4420 Constant_Present => True,
f301a57b 4421
4422 Object_Definition =>
acf97c11 4423 New_Reference_To (RTE (RE_Address), Loc),
f301a57b 4424
4425 Expression =>
acf97c11 4426 Make_Attribute_Reference (Loc,
f301a57b 4427 Prefix =>
acf97c11 4428 Make_Selected_Component (Loc,
f301a57b 4429 Prefix => New_Reference_To (Iface_DT, Loc),
4430 Selector_Name =>
4431 New_Occurrence_Of
4432 (RTE_Record_Component (RE_Predef_Prims), Loc)),
acf97c11 4433 Attribute_Name => Name_Address)));
4434
cc60bd16 4435 -- Remember entities containing dispatch tables
acf97c11 4436
cc60bd16 4437 Append_Elmt (Predef_Prims, DT_Decl);
4438 Append_Elmt (Iface_DT, DT_Decl);
725a69d2 4439 end Make_Secondary_DT;
4440
4441 -- Local variables
4442
2ea346ac 4443 Elab_Code : constant List_Id := New_List;
4444 Result : constant List_Id := New_List;
4445 Tname : constant Name_Id := Chars (Typ);
725a69d2 4446 AI : Elmt_Id;
cdb1c38f 4447 AI_Tag_Elmt : Elmt_Id;
24971415 4448 AI_Tag_Comp : Elmt_Id;
f9162257 4449 DT_Aggr_List : List_Id;
24971415 4450 DT_Constr_List : List_Id;
725a69d2 4451 DT_Ptr : Entity_Id;
725a69d2 4452 ITable : Node_Id;
4453 I_Depth : Nat := 0;
4454 Iface_Table_Node : Node_Id;
4455 Name_ITable : Name_Id;
725a69d2 4456 Nb_Predef_Prims : Nat := 0;
4457 Nb_Prim : Nat := 0;
4458 New_Node : Node_Id;
725a69d2 4459 Num_Ifaces : Nat := 0;
cc60bd16 4460 Parent_Typ : Entity_Id;
725a69d2 4461 Prim : Entity_Id;
4462 Prim_Elmt : Elmt_Id;
4463 Prim_Ops_Aggr_List : List_Id;
725a69d2 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;
17e14451 4469
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.
4477
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);
e7e688dd 4482 Name_HT_Link : constant Name_Id :=
4483 New_External_Name (Tname, 'H', Suffix_Index => -1);
17e14451 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);
4490
4491 -- Entities built with above names
4492
4493 DT : constant Entity_Id :=
4494 Make_Defining_Identifier (Loc, Name_DT);
4495 Exname : constant Entity_Id :=
4496 Make_Defining_Identifier (Loc, Name_Exname);
e7e688dd 4497 HT_Link : constant Entity_Id :=
4498 Make_Defining_Identifier (Loc, Name_HT_Link);
17e14451 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);
725a69d2 4505
4506 -- Start of processing for Make_DT
4507
4508 begin
17e14451 4509 pragma Assert (Is_Frozen (Typ));
725a69d2 4510
17e14451 4511 -- Handle cases in which there is no need to build the dispatch table
725a69d2 4512
17e14451 4513 if Has_Dispatch_Table (Typ)
4514 or else No (Access_Disp_Table (Typ))
4515 or else Is_CPP_Class (Typ)
b46aca2b 4516 or else Convention (Typ) = Convention_CIL
4517 or else Convention (Typ) = Convention_Java
17e14451 4518 then
725a69d2 4519 return Result;
725a69d2 4520
17e14451 4521 elsif No_Run_Time_Mode then
4522 Error_Msg_CRT ("tagged types", Typ);
4523 return Result;
725a69d2 4524
17e14451 4525 elsif not RTE_Available (RE_Tag) then
725a69d2 4526 Append_To (Result,
4527 Make_Object_Declaration (Loc,
17e14451 4528 Defining_Identifier => Node (First_Elmt
4529 (Access_Disp_Table (Typ))),
725a69d2 4530 Object_Definition => New_Reference_To (RTE (RE_Tag), Loc),
4531 Constant_Present => True,
4532 Expression =>
24971415 4533 Unchecked_Convert_To (RTE (RE_Tag),
725a69d2 4534 New_Reference_To (RTE (RE_Null_Address), Loc))));
4535
4536 Analyze_List (Result, Suppress => All_Checks);
4537 Error_Msg_CRT ("tagged types", Typ);
4538 return Result;
4539 end if;
4540
17e14451 4541 -- Ensure that the value of Max_Predef_Prims defined in a-tags is
208fd589 4542 -- correct. Valid values are 9 under configurable runtime or 15
17e14451 4543 -- with full runtime.
4544
4545 if RTE_Available (RE_Interface_Data) then
208fd589 4546 if Max_Predef_Prims /= 15 then
17e14451 4547 Error_Msg_N ("run-time library configuration error", Typ);
4548 return Result;
4549 end if;
725a69d2 4550 else
208fd589 4551 if Max_Predef_Prims /= 9 then
17e14451 4552 Error_Msg_N ("run-time library configuration error", Typ);
4553 Error_Msg_CRT ("tagged types", Typ);
4554 return Result;
4555 end if;
725a69d2 4556 end if;
4557
cc60bd16 4558 -- Initialize Parent_Typ handling private types
4559
4560 Parent_Typ := Etype (Typ);
4561
4562 if Present (Full_View (Parent_Typ)) then
4563 Parent_Typ := Full_View (Parent_Typ);
4564 end if;
4565
17e14451 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
24971415 4571 -- register the primitives in the slots will be generated later --- when
17e14451 4572 -- each primitive is frozen (see Freeze_Subprogram).
725a69d2 4573
d00681a7 4574 if Building_Static_DT (Typ) then
17e14451 4575 declare
4576 Save : constant Boolean := Freezing_Library_Level_Tagged_Type;
555c63a6 4577 Prim : Entity_Id;
17e14451 4578 Prim_Elmt : Elmt_Id;
4579 Frnodes : List_Id;
725a69d2 4580
17e14451 4581 begin
4582 Freezing_Library_Level_Tagged_Type := True;
555c63a6 4583
17e14451 4584 Prim_Elmt := First_Elmt (Primitive_Operations (Typ));
4585 while Present (Prim_Elmt) loop
555c63a6 4586 Prim := Node (Prim_Elmt);
d74fc39a 4587 Frnodes := Freeze_Entity (Prim, Typ);
725a69d2 4588
17e14451 4589 declare
17e14451 4590 F : Entity_Id;
725a69d2 4591
17e14451 4592 begin
555c63a6 4593 F := First_Formal (Prim);
17e14451 4594 while Present (F) loop
349db231 4595 Check_Premature_Freezing (Prim, Typ, Etype (F));
17e14451 4596 Next_Formal (F);
4597 end loop;
4598
349db231 4599 Check_Premature_Freezing (Prim, Typ, Etype (Prim));
17e14451 4600 end;
4601
4602 if Present (Frnodes) then
4603 Append_List_To (Result, Frnodes);
4604 end if;
4605
4606 Next_Elmt (Prim_Elmt);
4607 end loop;
555c63a6 4608
17e14451 4609 Freezing_Library_Level_Tagged_Type := Save;
4610 end;
4611 end if;
725a69d2 4612
17e14451 4613 -- Ada 2005 (AI-251): Build the secondary dispatch tables
4614
a652dd51 4615 if Has_Interfaces (Typ) then
17e14451 4616 Collect_Interface_Components (Typ, Typ_Comps);
4617
f301a57b 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).
4621
4622 -- Note: This value must be kept sync with the Suffix_Index values
4623 -- generated by Make_Tags
4624
4625 Suffix_Index := 1;
acf97c11 4626 AI_Tag_Elmt :=
4627 Next_Elmt (Next_Elmt (First_Elmt (Access_Disp_Table (Typ))));
17e14451 4628
4629 AI_Tag_Comp := First_Elmt (Typ_Comps);
4630 while Present (AI_Tag_Comp) loop
d00681a7 4631 pragma Assert (Has_Suffix (Node (AI_Tag_Elmt), 'P'));
cdb1c38f 4632
4633 -- Build the secondary table containing pointers to thunks
4634
17e14451 4635 Make_Secondary_DT
cdb1c38f 4636 (Typ => Typ,
4637 Iface => Base_Type (Related_Type (Node (AI_Tag_Comp))),
f301a57b 4638 Suffix_Index => Suffix_Index,
cdb1c38f 4639 Num_Iface_Prims => UI_To_Int
4640 (DT_Entry_Count (Node (AI_Tag_Comp))),
4641 Iface_DT_Ptr => Node (AI_Tag_Elmt),
acf97c11 4642 Predef_Prims_Ptr => Node (Next_Elmt (AI_Tag_Elmt)),
cdb1c38f 4643 Build_Thunks => True,
4644 Result => Result);
cdb1c38f 4645
d00681a7 4646 -- Skip secondary dispatch table referencing thunks to predefined
4647 -- primitives.
acf97c11 4648
f301a57b 4649 Next_Elmt (AI_Tag_Elmt);
d00681a7 4650 pragma Assert (Has_Suffix (Node (AI_Tag_Elmt), 'Y'));
4651
4652 -- Secondary dispatch table referencing user-defined primitives
4653 -- covered by this interface.
4654
acf97c11 4655 Next_Elmt (AI_Tag_Elmt);
d00681a7 4656 pragma Assert (Has_Suffix (Node (AI_Tag_Elmt), 'D'));
acf97c11 4657
36b938a3 4658 -- Build the secondary table containing pointers to primitives
cdb1c38f 4659 -- (used to give support to Generic Dispatching Constructors).
4660
4661 Make_Secondary_DT
d00681a7 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);
4672
4673 -- Skip secondary dispatch table referencing predefined primitives
acf97c11 4674
f301a57b 4675 Next_Elmt (AI_Tag_Elmt);
d00681a7 4676 pragma Assert (Has_Suffix (Node (AI_Tag_Elmt), 'Z'));
acf97c11 4677
17e14451 4678 Suffix_Index := Suffix_Index + 1;
d00681a7 4679 Next_Elmt (AI_Tag_Elmt);
17e14451 4680 Next_Elmt (AI_Tag_Comp);
4681 end loop;
4682 end if;
725a69d2 4683
c6a30f24 4684 -- Get the _tag entity and number of primitives of its dispatch table
725a69d2 4685
24971415 4686 DT_Ptr := Node (First_Elmt (Access_Disp_Table (Typ)));
4687 Nb_Prim := UI_To_Int (DT_Entry_Count (First_Tag_Component (Typ)));
725a69d2 4688
2ea346ac 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));
725a69d2 4694
4695 -- In case of locally defined tagged type we declare the object
36b938a3 4696 -- containing the dispatch table by means of a variable. Its
725a69d2 4697 -- initialization is done later by means of an assignment. This is
4698 -- required to generate its External_Tag.
4699
24971415 4700 if not Building_Static_DT (Typ) then
725a69d2 4701
4702 -- Generate:
4703 -- DT : No_Dispatch_Table_Wrapper;
17e14451 4704 -- for DT'Alignment use Address'Alignment;
725a69d2 4705 -- DT_Ptr : Tag := !Tag (DT.NDT_Prims_Ptr'Address);
4706
24971415 4707 if not Has_DT (Typ) then
725a69d2 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)));
4716
17e14451 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)));
4726
725a69d2 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 =>
24971415 4733 Unchecked_Convert_To (RTE (RE_Tag),
725a69d2 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))));
4742
ff6293ec 4743 Set_Is_Statically_Allocated (DT_Ptr,
4744 Is_Library_Level_Tagged_Type (Typ));
4745
98045ff0 4746 -- Generate the SCIL node for the previous object declaration
4747 -- because it has a tag initialization.
4748
3dbca0d5 4749 if Generate_SCIL then
d215f619 4750 New_Node :=
4751 Make_SCIL_Dispatch_Table_Tag_Init (Sloc (Last (Result)));
d215f619 4752 Set_SCIL_Entity (New_Node, Typ);
5a44b136 4753 Set_SCIL_Node (Last (Result), New_Node);
3dbca0d5 4754 end if;
4755
725a69d2 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);
4760
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.
4764
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;
4772
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))));
4784
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)));
4794
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 =>
24971415 4801 Unchecked_Convert_To (RTE (RE_Tag),
725a69d2 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))));
acf97c11 4810
ff6293ec 4811 Set_Is_Statically_Allocated (DT_Ptr,
4812 Is_Library_Level_Tagged_Type (Typ));
4813
98045ff0 4814 -- Generate the SCIL node for the previous object declaration
4815 -- because it has a tag initialization.
9af28f61 4816
3dbca0d5 4817 if Generate_SCIL then
d215f619 4818 New_Node :=
4819 Make_SCIL_Dispatch_Table_Tag_Init (Sloc (Last (Result)));
d215f619 4820 Set_SCIL_Entity (New_Node, Typ);
5a44b136 4821 Set_SCIL_Node (Last (Result), New_Node);
3dbca0d5 4822 end if;
4823
acf97c11 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)));
725a69d2 4840 end if;
4841 end if;
4842
4843 -- Generate: Exname : constant String := full_qualified_name (typ);
343d35dc 4844 -- The type itself may be an anonymous parent type, so use the first
4845 -- subtype to have a user-recognizable name.
d62940bf 4846
343d35dc 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,
c6a30f24 4854 Fully_Qualified_Name_String (First_Subtype (Typ)))));
d62940bf 4855
24971415 4856 Set_Is_Statically_Allocated (Exname);
4857 Set_Is_True_Constant (Exname);
4858
e7e688dd 4859 -- Declare the object used by Ada.Tags.Register_Tag
4860
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;
4867
725a69d2 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).
4871
4872 -- TSD : Type_Specific_Data (I_Depth) :=
4873 -- (Idepth => I_Depth,
4874 -- Access_Level => Type_Access_Level (Typ),
208fd589 4875 -- Alignment => Typ'Alignment,
725a69d2 4876 -- Expanded_Name => Cstring_Ptr!(Exname'Address))
4877 -- External_Tag => Cstring_Ptr!(Exname'Address))
e7e688dd 4878 -- HT_Link => HT_Link'Address,
725a69d2 4879 -- Transportable => <<boolean-value>>,
3568e554 4880 -- Type_Is_Abstract => <<boolean-value>>,
bb3b440a 4881 -- Needs_Finalization => <<boolean-value>>,
693b0822 4882 -- [ Size_Func => Size_Prim'Access, ]
4883 -- [ Interfaces_Table => <<access-value>>, ]
24971415 4884 -- [ SSD => SSD_Table'Address ]
725a69d2 4885 -- Tags_Table => (0 => null,
4886 -- 1 => Parent'Tag
4887 -- ...);
4888 -- for TSD'Alignment use Address'Alignment
4889
4890 TSD_Aggr_List := New_List;
4891
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.
4895
4896 declare
4897 Current_Typ : Entity_Id;
4898 Parent_Typ : Entity_Id;
4899
4900 begin
4901 I_Depth := 0;
4902 Current_Typ := Typ;
4903 loop
4904 Parent_Typ := Etype (Current_Typ);
4905
4906 if Is_Private_Type (Parent_Typ) then
4907 Parent_Typ := Full_View (Base_Type (Parent_Typ));
4908 end if;
4909
4910 exit when Parent_Typ = Current_Typ;
4911
4912 I_Depth := I_Depth + 1;
4913 Current_Typ := Parent_Typ;
4914 end loop;
4915 end;
4916
4917 Append_To (TSD_Aggr_List,
17e14451 4918 Make_Integer_Literal (Loc, I_Depth));
725a69d2 4919
4920 -- Access_Level
4921
4922 Append_To (TSD_Aggr_List,
17e14451 4923 Make_Integer_Literal (Loc, Type_Access_Level (Typ)));
725a69d2 4924
208fd589 4925 -- Alignment
4926
4927 -- For CPP types we cannot rely on the value of 'Alignment provided
4928 -- by the backend to initialize this TSD field.
4929
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;
4941
725a69d2 4942 -- Expanded_Name
4943
4944 Append_To (TSD_Aggr_List,
17e14451 4945 Unchecked_Convert_To (RTE (RE_Cstring_Ptr),
4946 Make_Attribute_Reference (Loc,
693b0822 4947 Prefix => New_Reference_To (Exname, Loc),
17e14451 4948 Attribute_Name => Name_Address)));
725a69d2 4949
4950 -- External_Tag of a local tagged type
4951
17e14451 4952 -- <typ>A : constant String :=
725a69d2 4953 -- "Internal tag at 16#tag-addr#: <full-name-of-typ>";
4954
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:
4958
4959 -- 1. It is hard to avoid a tasking race condition for entering the
4960 -- entry into the hash table.
4961
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.
4964
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).
4968
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!
4972
17e14451 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.
4976
4977 if not Is_Library_Level_Entity (Typ)
4978 and then not Has_External_Tag_Rep_Clause (Typ)
4979 then
725a69d2 4980 declare
725a69d2 4981 Exname : constant Entity_Id :=
17e14451 4982 Make_Defining_Identifier (Loc,
4983 New_External_Name (Tname, 'A'));
4984
725a69d2 4985 Full_Name : constant String_Id :=
c6a30f24 4986 Fully_Qualified_Name_String (First_Subtype (Typ));
725a69d2 4987 Str1_Id : String_Id;
4988 Str2_Id : String_Id;
725a69d2 4989
4990 begin
4991 -- Generate:
17e14451 4992 -- Str1 = "Internal tag at 16#";
725a69d2 4993
4994 Start_String;
4995 Store_String_Chars ("Internal tag at 16#");
4996 Str1_Id := End_String;
4997
4998 -- Generate:
17e14451 4999 -- Str2 = "#: <type-full-name>";
725a69d2 5000
5001 Start_String;
5002 Store_String_Chars ("#: ");
725a69d2 5003 Store_String_Chars (Full_Name);
17e14451 5004 Str2_Id := End_String;
725a69d2 5005
5006 -- Generate:
5007 -- Exname : constant String :=
17e14451 5008 -- Str1 & Address_Image (Tag) & Str2;
725a69d2 5009
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 =>
17e14451 5032 Make_String_Literal (Loc, Str2_Id)))));
5033
725a69d2 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 =>
17e14451 5046 Make_String_Literal (Loc, Str2_Id))));
725a69d2 5047 end if;
5048
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;
5055
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.
cc60bd16 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
34fd8639 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.
725a69d2 5063
5064 else
5065 declare
cc60bd16 5066 Def : constant Node_Id := Get_Attribute_Definition_Clause
34fd8639 5067 (Underlying_Type (First_Subtype (Typ)),
cc60bd16 5068 Attribute_External_Tag);
5069
725a69d2 5070 Old_Val : String_Id;
5071 New_Val : String_Id;
5072 E : Entity_Id;
5073
5074 begin
5075 if not Present (Def)
cc60bd16 5076 or else Entity (Name (Def)) /= First_Subtype (Typ)
725a69d2 5077 then
5078 New_Node :=
5079 Unchecked_Convert_To (RTE (RE_Cstring_Ptr),
5080 Make_Attribute_Reference (Loc,
cc60bd16 5081 Prefix => New_Reference_To (Exname, Loc),
725a69d2 5082 Attribute_Name => Name_Address));
5083 else
5084 Old_Val := Strval (Expr_Value_S (Expression (Def)));
5085
17e14451 5086 -- For the rep clause "for <typ>'external_tag use y" generate:
725a69d2 5087
17e14451 5088 -- <typ>A : constant string := y;
5089 --
5090 -- <typ>A'Address is used to set the External_Tag component
5091 -- of the TSD
725a69d2 5092
5093 -- Create a new nul terminated string if it is not already
5094
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;
5105
5106 E := Make_Defining_Identifier (Loc,
5107 New_External_Name (Chars (Typ), 'A'));
5108
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)));
5117
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;
5126
17e14451 5127 Append_To (TSD_Aggr_List, New_Node);
725a69d2 5128
5129 -- HT_Link
5130
e7e688dd 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;
725a69d2 5142
5143 -- Transportable: Set for types that can be used in remote calls
5144 -- with respect to E.4(18) legality rules.
5145
17e14451 5146 declare
5147 Transportable : Entity_Id;
725a69d2 5148
17e14451 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));
5159
5160 Append_To (TSD_Aggr_List,
5161 New_Occurrence_Of (Transportable, Loc));
5162 end;
725a69d2 5163
3568e554 5164 -- Type_Is_Abstract (Ada 2012: AI05-0173). This functionality is
5165 -- not available in the HIE runtime.
5166
5167 if RTE_Record_Component_Available (RE_Type_Is_Abstract) then
5168 declare
5169 Type_Is_Abstract : Entity_Id;
5170
5171 begin
5172 Type_Is_Abstract :=
5173 Boolean_Literals (Is_Abstract_Type (Typ));
5174
5175 Append_To (TSD_Aggr_List,
5176 New_Occurrence_Of (Type_Is_Abstract, Loc));
5177 end;
5178 end if;
5179
bb3b440a 5180 -- Needs_Finalization: Set if the type is controlled or has controlled
5181 -- components.
952af0b9 5182
17e14451 5183 declare
bb3b440a 5184 Needs_Fin : Entity_Id;
343d35dc 5185
17e14451 5186 begin
bb3b440a 5187 Needs_Fin := Boolean_Literals (Needs_Finalization (Typ));
5188 Append_To (TSD_Aggr_List, New_Occurrence_Of (Needs_Fin, Loc));
17e14451 5189 end;
725a69d2 5190
cc60bd16 5191 -- Size_Func
5192
5193 if RTE_Record_Component_Available (RE_Size_Func) then
925c2ba1 5194
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).
5200
5201 if not Building_Static_DT (Typ) or else not Has_DT (Typ) then
cc60bd16 5202 Append_To (TSD_Aggr_List,
5203 Unchecked_Convert_To (RTE (RE_Size_Ptr),
5204 New_Reference_To (RTE (RE_Null_Address), Loc)));
5205
5206 else
5207 declare
5208 Prim_Elmt : Elmt_Id;
5209 Prim : Entity_Id;
fa6a6949 5210 Size_Comp : Node_Id;
cc60bd16 5211
5212 begin
5213 Prim_Elmt := First_Elmt (Primitive_Operations (Typ));
5214 while Present (Prim_Elmt) loop
5215 Prim := Node (Prim_Elmt);
5216
5217 if Chars (Prim) = Name_uSize then
fc2907f6 5218 Prim := Ultimate_Alias (Prim);
cc60bd16 5219
5220 if Is_Abstract_Subprogram (Prim) then
fa6a6949 5221 Size_Comp :=
cc60bd16 5222 Unchecked_Convert_To (RTE (RE_Size_Ptr),
fa6a6949 5223 New_Reference_To (RTE (RE_Null_Address), Loc));
cc60bd16 5224 else
fa6a6949 5225 Size_Comp :=
cc60bd16 5226 Unchecked_Convert_To (RTE (RE_Size_Ptr),
5227 Make_Attribute_Reference (Loc,
5228 Prefix => New_Reference_To (Prim, Loc),
fa6a6949 5229 Attribute_Name => Name_Unrestricted_Access));
cc60bd16 5230 end if;
5231
5232 exit;
5233 end if;
5234
5235 Next_Elmt (Prim_Elmt);
5236 end loop;
fa6a6949 5237
5238 pragma Assert (Present (Size_Comp));
5239 Append_To (TSD_Aggr_List, Size_Comp);
cc60bd16 5240 end;
5241 end if;
5242 end if;
5243
725a69d2 5244 -- Interfaces_Table (required for AI-405)
5245
5246 if RTE_Record_Component_Available (RE_Interfaces_Table) then
5247
5248 -- Count the number of interface types implemented by Typ
5249
a652dd51 5250 Collect_Interfaces (Typ, Typ_Ifaces);
725a69d2 5251
5252 AI := First_Elmt (Typ_Ifaces);
5253 while Present (AI) loop
5254 Num_Ifaces := Num_Ifaces + 1;
5255 Next_Elmt (AI);
5256 end loop;
952af0b9 5257
343d35dc 5258 if Num_Ifaces = 0 then
725a69d2 5259 Iface_Table_Node := Make_Null (Loc);
952af0b9 5260
725a69d2 5261 -- Generate the Interface_Table object
343d35dc 5262
5263 else
725a69d2 5264 declare
17e14451 5265 TSD_Ifaces_List : constant List_Id := New_List;
cdb1c38f 5266 Elmt : Elmt_Id;
5267 Sec_DT_Tag : Node_Id;
725a69d2 5268
5269 begin
5270 AI := First_Elmt (Typ_Ifaces);
5271 while Present (AI) loop
cb4af01d 5272 if Is_Ancestor (Node (AI), Typ, Use_Full_View => True) then
cdb1c38f 5273 Sec_DT_Tag :=
5274 New_Reference_To (DT_Ptr, Loc);
5275 else
acf97c11 5276 Elmt :=
5277 Next_Elmt
5278 (Next_Elmt (First_Elmt (Access_Disp_Table (Typ))));
cdb1c38f 5279 pragma Assert (Has_Thunks (Node (Elmt)));
5280
d00681a7 5281 while Is_Tag (Node (Elmt))
cdb1c38f 5282 and then not
cb4af01d 5283 Is_Ancestor (Node (AI), Related_Type (Node (Elmt)),
5284 Use_Full_View => True)
cdb1c38f 5285 loop
5286 pragma Assert (Has_Thunks (Node (Elmt)));
5287 Next_Elmt (Elmt);
acf97c11 5288 pragma Assert (Has_Thunks (Node (Elmt)));
5289 Next_Elmt (Elmt);
5290 pragma Assert (not Has_Thunks (Node (Elmt)));
5291 Next_Elmt (Elmt);
cdb1c38f 5292 pragma Assert (not Has_Thunks (Node (Elmt)));
5293 Next_Elmt (Elmt);
5294 end loop;
5295
5296 pragma Assert (Ekind (Node (Elmt)) = E_Constant
acf97c11 5297 and then not
5298 Has_Thunks (Node (Next_Elmt (Next_Elmt (Elmt)))));
cdb1c38f 5299 Sec_DT_Tag :=
acf97c11 5300 New_Reference_To (Node (Next_Elmt (Next_Elmt (Elmt))),
5301 Loc);
cdb1c38f 5302 end if;
5303
17e14451 5304 Append_To (TSD_Ifaces_List,
5305 Make_Aggregate (Loc,
5306 Expressions => New_List (
5307
5308 -- Iface_Tag
5309
24971415 5310 Unchecked_Convert_To (RTE (RE_Tag),
725a69d2 5311 New_Reference_To
5312 (Node (First_Elmt (Access_Disp_Table (Node (AI)))),
17e14451 5313 Loc)),
725a69d2 5314
17e14451 5315 -- Static_Offset_To_Top
725a69d2 5316
17e14451 5317 New_Reference_To (Standard_True, Loc),
725a69d2 5318
17e14451 5319 -- Offset_To_Top_Value
5320
5321 Make_Integer_Literal (Loc, 0),
5322
5323 -- Offset_To_Top_Func
5324
cdb1c38f 5325 Make_Null (Loc),
5326
5327 -- Secondary_DT
5328
5329 Unchecked_Convert_To (RTE (RE_Tag), Sec_DT_Tag)
5330
5331 )));
725a69d2 5332
725a69d2 5333 Next_Elmt (AI);
5334 end loop;
725a69d2 5335
17e14451 5336 Name_ITable := New_External_Name (Tname, 'I');
5337 ITable := Make_Defining_Identifier (Loc, Name_ITable);
2ea346ac 5338 Set_Is_Statically_Allocated (ITable,
5339 Is_Library_Level_Tagged_Type (Typ));
725a69d2 5340
17e14451 5341 -- The table of interfaces is not constant; its slots are
0c826ed4 5342 -- filled at run time by the IP routine using attribute
17e14451 5343 -- 'Position to know the location of the tag components
5344 -- (and this attribute cannot be safely used before the
5345 -- object is initialized).
725a69d2 5346
17e14451 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)))),
725a69d2 5360
17e14451 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)))));
725a69d2 5366
17e14451 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)));
725a69d2 5376
17e14451 5377 Iface_Table_Node :=
5378 Make_Attribute_Reference (Loc,
5379 Prefix => New_Reference_To (ITable, Loc),
5380 Attribute_Name => Name_Unchecked_Access);
5381 end;
725a69d2 5382 end if;
5383
17e14451 5384 Append_To (TSD_Aggr_List, Iface_Table_Node);
725a69d2 5385 end if;
5386
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.
5390
5391 if RTE_Record_Component_Available (RE_SSD) then
de54c5ab 5392 if Ada_Version >= Ada_2005
24971415 5393 and then Has_DT (Typ)
725a69d2 5394 and then Is_Concurrent_Record_Type (Typ)
a652dd51 5395 and then Has_Interfaces (Typ)
725a69d2 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)
f38c8084 5400 and then not Restriction_Active (No_Select_Statements)
725a69d2 5401 then
343d35dc 5402 Append_To (Result,
5403 Make_Object_Declaration (Loc,
725a69d2 5404 Defining_Identifier => SSD,
343d35dc 5405 Aliased_Present => True,
5406 Object_Definition =>
5407 Make_Subtype_Indication (Loc,
725a69d2 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))))));
5414
17e14451 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)));
5424
725a69d2 5425 -- This table is initialized by Make_Select_Specific_Data_Table,
5426 -- which calls Set_Entry_Index and Set_Prim_Op_Kind.
5427
5428 Append_To (TSD_Aggr_List,
17e14451 5429 Make_Attribute_Reference (Loc,
5430 Prefix => New_Reference_To (SSD, Loc),
5431 Attribute_Name => Name_Unchecked_Access));
725a69d2 5432 else
17e14451 5433 Append_To (TSD_Aggr_List, Make_Null (Loc));
343d35dc 5434 end if;
952af0b9 5435 end if;
5436
725a69d2 5437 -- Initialize the table of ancestor tags. In case of interface types
5438 -- this table is not needed.
d62940bf 5439
cc60bd16 5440 TSD_Tags_List := New_List;
952af0b9 5441
cc60bd16 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.
343d35dc 5445
cc60bd16 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)));
343d35dc 5452
cc60bd16 5453 -- Otherwise we can safely reference the tag
343d35dc 5454
cc60bd16 5455 else
5456 Append_To (TSD_Tags_List,
5457 New_Reference_To (DT_Ptr, Loc));
5458 end if;
343d35dc 5459
cc60bd16 5460 -- Fill the rest of the table with the tags of the ancestors
343d35dc 5461
cc60bd16 5462 declare
5463 Current_Typ : Entity_Id;
5464 Parent_Typ : Entity_Id;
5465 Pos : Nat;
725a69d2 5466
cc60bd16 5467 begin
17e14451 5468 Pos := 1;
5469 Current_Typ := Typ;
725a69d2 5470
17e14451 5471 loop
5472 Parent_Typ := Etype (Current_Typ);
343d35dc 5473
17e14451 5474 if Is_Private_Type (Parent_Typ) then
5475 Parent_Typ := Full_View (Base_Type (Parent_Typ));
5476 end if;
5477
5478 exit when Parent_Typ = Current_Typ;
5479
7ac0f4a5 5480 if Is_CPP_Class (Parent_Typ) then
5481
17e14451 5482 -- The tags defined in the C++ side will be inherited when
5483 -- the object is constructed (Exp_Ch3.Build_Init_Procedure)
5484
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;
5494
5495 Pos := Pos + 1;
5496 Current_Typ := Parent_Typ;
5497 end loop;
5498
5499 pragma Assert (Pos = I_Depth + 1);
5500 end;
5501
5502 Append_To (TSD_Aggr_List,
5503 Make_Aggregate (Loc,
5504 Expressions => TSD_Tags_List));
343d35dc 5505
725a69d2 5506 -- Build the TSD object
343d35dc 5507
5508 Append_To (Result,
5509 Make_Object_Declaration (Loc,
5510 Defining_Identifier => TSD,
5511 Aliased_Present => True,
24971415 5512 Constant_Present => Building_Static_DT (Typ),
343d35dc 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)))),
725a69d2 5521
343d35dc 5522 Expression => Make_Aggregate (Loc,
17e14451 5523 Expressions => TSD_Aggr_List)));
343d35dc 5524
24971415 5525 Set_Is_True_Constant (TSD, Building_Static_DT (Typ));
5526
343d35dc 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)));
5535
24971415 5536 -- Initialize or declare the dispatch table object
343d35dc 5537
24971415 5538 if not Has_DT (Typ) then
725a69d2 5539 DT_Constr_List := New_List;
5540 DT_Aggr_List := New_List;
343d35dc 5541
725a69d2 5542 -- Typeinfo
952af0b9 5543
725a69d2 5544 New_Node :=
5545 Make_Attribute_Reference (Loc,
5546 Prefix => New_Reference_To (TSD, Loc),
5547 Attribute_Name => Name_Address);
5548
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));
5552
5553 -- In case of locally defined tagged types we have already declared
5554 -- and uninitialized object for the dispatch table, which is now
24971415 5555 -- initialized by means of the following assignment:
5556
5557 -- DT := (TSD'Address, 0);
725a69d2 5558
24971415 5559 if not Building_Static_DT (Typ) then
725a69d2 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)));
5565
24971415 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
5570
5571 -- DT : aliased constant No_Dispatch_Table :=
5572 -- (NDT_TSD => TSD'Address;
5573 -- NDT_Prims_Ptr => 0);
5574 -- for DT'Alignment use Address'Alignment;
725a69d2 5575
5576 else
5577 Append_To (Result,
5578 Make_Object_Declaration (Loc,
5579 Defining_Identifier => DT,
5580 Aliased_Present => True,
17e14451 5581 Constant_Present => True,
725a69d2 5582 Object_Definition =>
5583 New_Reference_To (RTE (RE_No_Dispatch_Table_Wrapper), Loc),
5584 Expression => Make_Aggregate (Loc,
5585 Expressions => DT_Aggr_List)));
5586
17e14451 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)));
5596
24971415 5597 Export_DT (Typ, DT);
725a69d2 5598 end if;
5599
5600 -- Common case: Typ has a dispatch table
5601
5602 -- Generate:
5603
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
5610
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));
17e14451 5621 -- for DT'Alignment use Address'Alignment
725a69d2 5622
5623 else
5624 declare
5625 Pos : Nat;
5626
5627 begin
24971415 5628 if not Building_Static_DT (Typ) then
725a69d2 5629 Nb_Predef_Prims := Max_Predef_Prims;
5630
5631 else
5632 Prim_Elmt := First_Elmt (Primitive_Operations (Typ));
5633 while Present (Prim_Elmt) loop
5634 Prim := Node (Prim_Elmt);
5635
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));
5640
5641 if Pos > Nb_Predef_Prims then
5642 Nb_Predef_Prims := Pos;
5643 end if;
5644 end if;
5645
5646 Next_Elmt (Prim_Elmt);
5647 end loop;
5648 end if;
5649
5650 declare
5651 Prim_Table : array
5652 (Nat range 1 .. Nb_Predef_Prims) of Entity_Id;
cc60bd16 5653 Decl : Node_Id;
725a69d2 5654 E : Entity_Id;
5655
5656 begin
5657 Prim_Ops_Aggr_List := New_List;
5658
5659 Prim_Table := (others => Empty);
17e14451 5660
cdb1c38f 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);
725a69d2 5665
cdb1c38f 5666 if Is_Predefined_Dispatching_Operation (Prim)
5667 and then not Is_Abstract_Subprogram (Prim)
3f8cf2d2 5668 and then not Is_Eliminated (Prim)
cdb1c38f 5669 and then not Present (Prim_Table
5670 (UI_To_Int (DT_Position (Prim))))
5671 then
fc2907f6 5672 E := Ultimate_Alias (Prim);
cdb1c38f 5673 pragma Assert (not Is_Abstract_Subprogram (E));
5674 Prim_Table (UI_To_Int (DT_Position (Prim))) := E;
5675 end if;
725a69d2 5676
cdb1c38f 5677 Next_Elmt (Prim_Elmt);
5678 end loop;
5679 end if;
725a69d2 5680
5681 for J in Prim_Table'Range loop
5682 if Present (Prim_Table (J)) then
5683 New_Node :=
cc60bd16 5684 Unchecked_Convert_To (RTE (RE_Prim_Ptr),
acf97c11 5685 Make_Attribute_Reference (Loc,
5686 Prefix => New_Reference_To (Prim_Table (J), Loc),
5687 Attribute_Name => Name_Unrestricted_Access));
725a69d2 5688 else
cc60bd16 5689 New_Node := Make_Null (Loc);
725a69d2 5690 end if;
5691
5692 Append_To (Prim_Ops_Aggr_List, New_Node);
5693 end loop;
343d35dc 5694
cc60bd16 5695 New_Node :=
5696 Make_Aggregate (Loc,
5697 Expressions => Prim_Ops_Aggr_List);
5698
5699 Decl :=
5700 Make_Subtype_Declaration (Loc,
ec97ce79 5701 Defining_Identifier => Make_Temporary (Loc, 'S'),
5702 Subtype_Indication =>
cc60bd16 5703 New_Reference_To (RTE (RE_Address_Array), Loc));
5704
5705 Append_To (Result, Decl);
5706
68f95949 5707 Append_To (Result,
5708 Make_Object_Declaration (Loc,
725a69d2 5709 Defining_Identifier => Predef_Prims,
68f95949 5710 Aliased_Present => True,
24971415 5711 Constant_Present => Building_Static_DT (Typ),
cc60bd16 5712 Object_Definition => New_Reference_To
5713 (Defining_Identifier (Decl), Loc),
5714 Expression => New_Node));
5715
5716 -- Remember aggregates initializing dispatch tables
5717
5718 Append_Elmt (New_Node, DT_Aggr);
725a69d2 5719
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;
5731
5732 -- Stage 1: Initialize the discriminant and the record components
5733
5734 DT_Constr_List := New_List;
5735 DT_Aggr_List := New_List;
5736
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.
5739
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;
5745
5746 Append_To (DT_Constr_List, New_Node);
5747 Append_To (DT_Aggr_List, New_Copy (New_Node));
5748
5749 -- Signature
5750
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;
5755
5756 -- Tag_Kind
5757
5758 if RTE_Record_Component_Available (RE_Tag_Kind) then
5759 Append_To (DT_Aggr_List, Tagged_Kind (Typ));
5760 end if;
5761
5762 -- Predef_Prims
5763
5764 Append_To (DT_Aggr_List,
5765 Make_Attribute_Reference (Loc,
5766 Prefix => New_Reference_To (Predef_Prims, Loc),
5767 Attribute_Name => Name_Address));
5768
5769 -- Offset_To_Top
5770
cc60bd16 5771 Append_To (DT_Aggr_List, Make_Integer_Literal (Loc, 0));
725a69d2 5772
5773 -- Typeinfo
5774
5775 Append_To (DT_Aggr_List,
5776 Make_Attribute_Reference (Loc,
5777 Prefix => New_Reference_To (TSD, Loc),
5778 Attribute_Name => Name_Address));
5779
5780 -- Stage 2: Initialize the table of primitive operations
5781
5782 Prim_Ops_Aggr_List := New_List;
5783
5784 if Nb_Prim = 0 then
cc60bd16 5785 Append_To (Prim_Ops_Aggr_List, Make_Null (Loc));
725a69d2 5786
9a479e51 5787 elsif not Building_Static_DT (Typ) then
725a69d2 5788 for J in 1 .. Nb_Prim loop
cc60bd16 5789 Append_To (Prim_Ops_Aggr_List, Make_Null (Loc));
725a69d2 5790 end loop;
5791
5792 else
5793 declare
d00681a7 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;
725a69d2 5800
5801 begin
5802 Prim_Table := (others => Empty);
cdb1c38f 5803
5804 Prim_Elmt := First_Elmt (Primitive_Operations (Typ));
725a69d2 5805 while Present (Prim_Elmt) loop
5806 Prim := Node (Prim_Elmt);
5807
9429b6e9 5808 -- Retrieve the ultimate alias of the primitive for proper
5809 -- handling of renamings and eliminated primitives.
5810
d00681a7 5811 E := Ultimate_Alias (Prim);
5812 Prim_Pos := UI_To_Int (DT_Position (E));
9429b6e9 5813
3f8cf2d2 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
d00681a7 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.
725a69d2 5821
3f8cf2d2 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)
3f8cf2d2 5826 and then not Is_Eliminated (E)
d00681a7 5827 and then (not Is_CPP_Class (Root_Type (Typ))
5828 or else Prim_Pos > CPP_Nb_Prims)
3f8cf2d2 5829 then
5830 pragma Assert
5831 (UI_To_Int (DT_Position (Prim)) <= Nb_Prim);
5832
5833 Prim_Table (UI_To_Int (DT_Position (Prim))) := E;
725a69d2 5834 end if;
5835
5836 Next_Elmt (Prim_Elmt);
5837 end loop;
5838
5839 for J in Prim_Table'Range loop
5840 if Present (Prim_Table (J)) then
5841 New_Node :=
cc60bd16 5842 Unchecked_Convert_To (RTE (RE_Prim_Ptr),
acf97c11 5843 Make_Attribute_Reference (Loc,
5844 Prefix => New_Reference_To (Prim_Table (J), Loc),
5845 Attribute_Name => Name_Unrestricted_Access));
725a69d2 5846 else
cc60bd16 5847 New_Node := Make_Null (Loc);
725a69d2 5848 end if;
5849
5850 Append_To (Prim_Ops_Aggr_List, New_Node);
5851 end loop;
5852 end;
5853 end if;
5854
cc60bd16 5855 New_Node :=
725a69d2 5856 Make_Aggregate (Loc,
cc60bd16 5857 Expressions => Prim_Ops_Aggr_List);
5858
5859 Append_To (DT_Aggr_List, New_Node);
5860
5861 -- Remember aggregates initializing dispatch tables
5862
5863 Append_Elmt (New_Node, DT_Aggr);
725a69d2 5864
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.
5868
24971415 5869 if not Building_Static_DT (Typ) then
725a69d2 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)));
5875
24971415 5876 -- In case of library level tagged types we declare now and export
5877 -- the constant object containing the dispatch table.
725a69d2 5878
5879 else
5880 Append_To (Result,
5881 Make_Object_Declaration (Loc,
5882 Defining_Identifier => DT,
5883 Aliased_Present => True,
17e14451 5884 Constant_Present => True,
725a69d2 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)));
5893
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)));
5903
24971415 5904 Export_DT (Typ, DT);
952af0b9 5905 end if;
76a1c25b 5906 end if;
d62940bf 5907
f301a57b 5908 -- Initialize the table of ancestor tags if not building static
5909 -- dispatch table
725a69d2 5910
24971415 5911 if not Building_Static_DT (Typ)
17e14451 5912 and then not Is_Interface (Typ)
725a69d2 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))),
5928
5929 Expression =>
5930 New_Reference_To
5931 (Node (First_Elmt (Access_Disp_Table (Typ))), Loc)));
5932 end if;
5933
f301a57b 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.
acf97c11 5938
9a479e51 5939 if Building_Static_DT (Typ) then
725a69d2 5940 null;
5941
af647dc7 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.
d62940bf 5944
cc60bd16 5945 elsif Is_CPP_Class (Parent_Typ) then
af647dc7 5946 null;
d62940bf 5947
acf97c11 5948 -- Otherwise we fill in the dispatch tables here
d62940bf 5949
af647dc7 5950 else
cc60bd16 5951 if Typ /= Parent_Typ
af647dc7 5952 and then not Is_Interface (Typ)
5953 and then not Restriction_Active (No_Dispatching_Calls)
68f95949 5954 then
343d35dc 5955 -- Inherit the dispatch table
d62940bf 5956
acf97c11 5957 if not Is_Interface (Typ)
cc60bd16 5958 and then not Is_Interface (Parent_Typ)
5959 and then not Is_CPP_Class (Parent_Typ)
acf97c11 5960 then
5961 declare
5962 Nb_Prims : constant Int :=
5963 UI_To_Int (DT_Entry_Count
cc60bd16 5964 (First_Tag_Component (Parent_Typ)));
5965
acf97c11 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
cc60bd16 5974 (Access_Disp_Table (Parent_Typ)))), Loc),
acf97c11 5975 New_Tag_Node =>
5976 New_Reference_To
5977 (Node
5978 (Next_Elmt
5979 (First_Elmt
5980 (Access_Disp_Table (Typ)))), Loc)));
5981
5982 if Nb_Prims /= 0 then
725a69d2 5983 Append_To (Elab_Code,
acf97c11 5984 Build_Inherit_Prims (Loc,
5985 Typ => Typ,
5986 Old_Tag_Node =>
5987 New_Reference_To
5988 (Node
5989 (First_Elmt
cc60bd16 5990 (Access_Disp_Table (Parent_Typ))), Loc),
acf97c11 5991 New_Tag_Node => New_Reference_To (DT_Ptr, Loc),
5992 Num_Prims => Nb_Prims));
5993 end if;
5994 end;
af647dc7 5995 end if;
d62940bf 5996
af647dc7 5997 -- Inherit the secondary dispatch tables of the ancestor
d62940bf 5998
cc60bd16 5999 if not Is_CPP_Class (Parent_Typ) then
af647dc7 6000 declare
6001 Sec_DT_Ancestor : Elmt_Id :=
6002 Next_Elmt
acf97c11 6003 (Next_Elmt
af647dc7 6004 (First_Elmt
cc60bd16 6005 (Access_Disp_Table (Parent_Typ))));
af647dc7 6006 Sec_DT_Typ : Elmt_Id :=
6007 Next_Elmt
acf97c11 6008 (Next_Elmt
6009 (First_Elmt
6010 (Access_Disp_Table (Typ))));
af647dc7 6011
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.
6016
6017 ------------------------
6018 -- Copy_Secondary_DTs --
6019 ------------------------
6020
6021 procedure Copy_Secondary_DTs (Typ : Entity_Id) is
6022 E : Entity_Id;
6023 Iface : Elmt_Id;
6024
6025 begin
6026 -- Climb to the ancestor (if any) handling private types
6027
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;
d62940bf 6032
af647dc7 6033 elsif Etype (Typ) /= Typ then
6034 Copy_Secondary_DTs (Etype (Typ));
6035 end if;
d62940bf 6036
a652dd51 6037 if Present (Interfaces (Typ))
6038 and then not Is_Empty_Elmt_List (Interfaces (Typ))
af647dc7 6039 then
a652dd51 6040 Iface := First_Elmt (Interfaces (Typ));
af647dc7 6041 E := First_Entity (Typ);
6042 while Present (E)
6043 and then Present (Node (Sec_DT_Ancestor))
725a69d2 6044 and then Ekind (Node (Sec_DT_Ancestor)) = E_Constant
af647dc7 6045 loop
6046 if Is_Tag (E) and then Chars (E) /= Name_uTag then
cdb1c38f 6047 declare
6048 Num_Prims : constant Int :=
6049 UI_To_Int (DT_Entry_Count (E));
6050
6051 begin
6052 if not Is_Interface (Etype (Typ)) then
6053
6054 -- Inherit first secondary dispatch table
6055
6056 Append_To (Elab_Code,
6057 Build_Inherit_Predefined_Prims (Loc,
6058 Old_Tag_Node =>
6059 Unchecked_Convert_To (RTE (RE_Tag),
acf97c11 6060 New_Reference_To
6061 (Node
6062 (Next_Elmt (Sec_DT_Ancestor)),
6063 Loc)),
cdb1c38f 6064 New_Tag_Node =>
6065 Unchecked_Convert_To (RTE (RE_Tag),
6066 New_Reference_To
acf97c11 6067 (Node (Next_Elmt (Sec_DT_Typ)),
6068 Loc))));
cdb1c38f 6069
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;
6088
6089 Next_Elmt (Sec_DT_Ancestor);
6090 Next_Elmt (Sec_DT_Typ);
343d35dc 6091
acf97c11 6092 -- Skip the secondary dispatch table of
6093 -- predefined primitives
6094
6095 Next_Elmt (Sec_DT_Ancestor);
6096 Next_Elmt (Sec_DT_Typ);
6097
cdb1c38f 6098 if not Is_Interface (Etype (Typ)) then
6099
6100 -- Inherit second secondary dispatch table
343d35dc 6101
343d35dc 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
acf97c11 6107 (Node
6108 (Next_Elmt (Sec_DT_Ancestor)),
6109 Loc)),
343d35dc 6110 New_Tag_Node =>
6111 Unchecked_Convert_To (RTE (RE_Tag),
6112 New_Reference_To
acf97c11 6113 (Node (Next_Elmt (Sec_DT_Typ)),
6114 Loc))));
343d35dc 6115
6116 if Num_Prims /= 0 then
6117 Append_To (Elab_Code,
6118 Build_Inherit_Prims (Loc,
17e14451 6119 Typ => Node (Iface),
343d35dc 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)),
17e14451 6131 Num_Prims => Num_Prims));
343d35dc 6132 end if;
cdb1c38f 6133 end if;
6134 end;
af647dc7 6135
6136 Next_Elmt (Sec_DT_Ancestor);
6137 Next_Elmt (Sec_DT_Typ);
acf97c11 6138
6139 -- Skip the secondary dispatch table of
6140 -- predefined primitives
6141
6142 Next_Elmt (Sec_DT_Ancestor);
6143 Next_Elmt (Sec_DT_Typ);
6144
af647dc7 6145 Next_Elmt (Iface);
6146 end if;
d62940bf 6147
af647dc7 6148 Next_Entity (E);
6149 end loop;
6150 end if;
6151 end Copy_Secondary_DTs;
d62940bf 6152
af647dc7 6153 begin
725a69d2 6154 if Present (Node (Sec_DT_Ancestor))
6155 and then Ekind (Node (Sec_DT_Ancestor)) = E_Constant
6156 then
af647dc7 6157 -- Handle private types
76a1c25b 6158
af647dc7 6159 if Present (Full_View (Typ)) then
6160 Copy_Secondary_DTs (Full_View (Typ));
6161 else
6162 Copy_Secondary_DTs (Typ);
6163 end if;
76a1c25b 6164 end if;
af647dc7 6165 end;
6166 end if;
76a1c25b 6167 end if;
343d35dc 6168 end if;
d62940bf 6169
fd68eaab 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.
354540f3 6173
6174 -- Check_TSD (TSD'Unrestricted_Access);
6175
4a473cb9 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.
6181
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.
52b9debb 6184
354540f3 6185 if not No_Run_Time_Mode
4a473cb9 6186 and then Ada_Version >= Ada_2005
fd68eaab 6187 and then Has_External_Tag_Rep_Clause (Typ)
354540f3 6188 and then RTE_Available (RE_Check_TSD)
008ad845 6189 and then not Debug_Flag_QQ
354540f3 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;
6199
343d35dc 6200 -- Generate code to register the Tag in the External_Tag hash table for
6201 -- the pure Ada type only.
d62940bf 6202
343d35dc 6203 -- Register_Tag (Dt_Ptr);
d62940bf 6204
725a69d2 6205 -- Skip this action in the following cases:
6206 -- 1) if Register_Tag is not available.
6207 -- 2) in No_Run_Time mode.
2ea346ac 6208 -- 3) if Typ is not defined at the library level (this is required
725a69d2 6209 -- to avoid adding concurrency control to the hash table used
6210 -- by the run-time to register the tags).
d62940bf 6211
cdb1c38f 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
725a69d2 6216 Append_To (Elab_Code,
cdb1c38f 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))));
d62940bf 6221 end if;
6222
2ea346ac 6223 if not Is_Empty_List (Elab_Code) then
6224 Append_List_To (Result, Elab_Code);
6225 end if;
cdb1c38f 6226
f38c8084 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.
17e14451 6231
de54c5ab 6232 if Ada_Version >= Ada_2005
17e14451 6233 and then Is_Concurrent_Record_Type (Typ)
a652dd51 6234 and then Has_Interfaces (Typ)
f38c8084 6235 and then not Restriction_Active (No_Dispatching_Calls)
6236 and then not Restriction_Active (No_Select_Statements)
17e14451 6237 then
6238 Append_List_To (Result,
6239 Make_Select_Specific_Data_Table (Typ));
6240 end if;
6241
cc60bd16 6242 -- Remember entities containing dispatch tables
acf97c11 6243
cc60bd16 6244 Append_Elmt (Predef_Prims, DT_Decl);
6245 Append_Elmt (DT, DT_Decl);
acf97c11 6246
725a69d2 6247 Analyze_List (Result, Suppress => All_Checks);
17e14451 6248 Set_Has_Dispatch_Table (Typ);
6249
f301a57b 6250 -- Mark entities containing dispatch tables. Required by the backend to
6251 -- handle them properly.
cc60bd16 6252
925c2ba1 6253 if Has_DT (Typ) then
cc60bd16 6254 declare
6255 Elmt : Elmt_Id;
6256
6257 begin
6258 -- Ensure that entities Prim_Ptr and Predef_Prims_Table_Ptr have
6259 -- the decoration required by the backend
6260
6261 Set_Is_Dispatch_Table_Entity (RTE (RE_Prim_Ptr));
6262 Set_Is_Dispatch_Table_Entity (RTE (RE_Predef_Prims_Table_Ptr));
6263
6264 -- Object declarations
6265
6266 Elmt := First_Elmt (DT_Decl);
6267 while Present (Elmt) loop
6268 Set_Is_Dispatch_Table_Entity (Node (Elmt));
6269 pragma Assert (Ekind (Etype (Node (Elmt))) = E_Array_Subtype
6270 or else Ekind (Etype (Node (Elmt))) = E_Record_Subtype);
6271 Set_Is_Dispatch_Table_Entity (Etype (Node (Elmt)));
6272 Next_Elmt (Elmt);
6273 end loop;
6274
6275 -- Aggregates initializing dispatch tables
6276
6277 Elmt := First_Elmt (DT_Aggr);
6278 while Present (Elmt) loop
6279 Set_Is_Dispatch_Table_Entity (Etype (Node (Elmt)));
6280 Next_Elmt (Elmt);
6281 end loop;
6282 end;
6283 end if;
6284
e00e091c 6285 -- Register the tagged type in the call graph nodes table
6286
6287 Register_CG_Node (Typ);
6288
76a1c25b 6289 return Result;
6290 end Make_DT;
d62940bf 6291
87d6f1a4 6292 -----------------
6293 -- Make_VM_TSD --
6294 -----------------
6295
6296 function Make_VM_TSD (Typ : Entity_Id) return List_Id is
6cb4b973 6297 Loc : constant Source_Ptr := Sloc (Typ);
6298 Result : constant List_Id := New_List;
6299
6300 function Count_Primitives (Typ : Entity_Id) return Nat;
6301 -- Count the non-predefined primitive operations of Typ
6302
6303 ----------------------
6304 -- Count_Primitives --
6305 ----------------------
6306
6307 function Count_Primitives (Typ : Entity_Id) return Nat is
6308 Nb_Prim : Nat;
6309 Prim_Elmt : Elmt_Id;
6310 Prim : Entity_Id;
6311
6312 begin
6313 Nb_Prim := 0;
6314
6315 Prim_Elmt := First_Elmt (Primitive_Operations (Typ));
6316 while Present (Prim_Elmt) loop
6317 Prim := Node (Prim_Elmt);
6318
6319 if Is_Predefined_Dispatching_Operation (Prim)
6320 or else Is_Predefined_Dispatching_Alias (Prim)
6321 then
6322 null;
6323
6324 elsif Present (Interface_Alias (Prim)) then
6325 null;
6326
6327 else
6328 Nb_Prim := Nb_Prim + 1;
6329 end if;
6330
6331 Next_Elmt (Prim_Elmt);
6332 end loop;
6333
6334 return Nb_Prim;
6335 end Count_Primitives;
6336
6337 --------------
6338 -- Make_OSD --
6339 --------------
6340
6341 function Make_OSD (Iface : Entity_Id) return Node_Id;
6342 -- Generate the Object Specific Data table required to dispatch calls
6343 -- through synchronized interfaces. Returns a node that references the
6344 -- generated OSD object.
6345
6346 function Make_OSD (Iface : Entity_Id) return Node_Id is
6347 Nb_Prim : constant Nat := Count_Primitives (Iface);
6348 OSD : Entity_Id;
6349 OSD_Aggr_List : List_Id;
6350
6351 begin
6352 -- Generate
6353 -- OSD : Ada.Tags.Object_Specific_Data (Nb_Prims) :=
6354 -- (OSD_Table => (1 => <value>,
6355 -- ...
6356 -- N => <value>));
6357
6358 if Nb_Prim = 0
6359 or else Is_Abstract_Type (Typ)
6360 or else Is_Controlled (Typ)
6361 or else Restriction_Active (No_Dispatching_Calls)
6362 or else not Is_Limited_Type (Typ)
6363 or else not Has_Interfaces (Typ)
6364 or else not RTE_Record_Component_Available (RE_OSD_Table)
6365 then
6366 -- No OSD table required
6367
6368 return Make_Null (Loc);
6369
6370 else
6371 OSD_Aggr_List := New_List;
6372
6373 declare
6374 Prim_Table : array (Nat range 1 .. Nb_Prim) of Entity_Id;
6375 Prim : Entity_Id;
6376 Prim_Alias : Entity_Id;
6377 Prim_Elmt : Elmt_Id;
6378 E : Entity_Id;
6379 Count : Nat := 0;
6380 Pos : Nat;
6381
6382 begin
6383 Prim_Table := (others => Empty);
6384 Prim_Alias := Empty;
6385
6386 Prim_Elmt := First_Elmt (Primitive_Operations (Typ));
6387 while Present (Prim_Elmt) loop
6388 Prim := Node (Prim_Elmt);
6389
6390 if Present (Interface_Alias (Prim))
6391 and then Find_Dispatching_Type
6392 (Interface_Alias (Prim)) = Iface
6393 then
6394 Prim_Alias := Interface_Alias (Prim);
6395 E := Ultimate_Alias (Prim);
6396 Pos := UI_To_Int (DT_Position (Prim_Alias));
6397
6398 if Present (Prim_Table (Pos)) then
6399 pragma Assert (Prim_Table (Pos) = E);
6400 null;
6401
6402 else
6403 Prim_Table (Pos) := E;
6404
6405 Append_To (OSD_Aggr_List,
6406 Make_Component_Association (Loc,
6407 Choices => New_List (
6408 Make_Integer_Literal (Loc,
6409 DT_Position (Prim_Alias))),
6410 Expression =>
6411 Make_Integer_Literal (Loc,
6412 DT_Position (Alias (Prim)))));
6413
6414 Count := Count + 1;
6415 end if;
6416 end if;
6417
6418 Next_Elmt (Prim_Elmt);
6419 end loop;
6420 pragma Assert (Count = Nb_Prim);
6421 end;
6422
6423 OSD := Make_Temporary (Loc, 'I');
6424
6425 Append_To (Result,
6426 Make_Object_Declaration (Loc,
6427 Defining_Identifier => OSD,
6428 Aliased_Present => True,
6429 Constant_Present => True,
6430 Object_Definition =>
6431 Make_Subtype_Indication (Loc,
6432 Subtype_Mark =>
6433 New_Reference_To (RTE (RE_Object_Specific_Data), Loc),
6434 Constraint =>
6435 Make_Index_Or_Discriminant_Constraint (Loc,
6436 Constraints => New_List (
6437 Make_Integer_Literal (Loc, Nb_Prim)))),
6438
6439 Expression =>
6440 Make_Aggregate (Loc,
6441 Component_Associations => New_List (
6442 Make_Component_Association (Loc,
6443 Choices => New_List (
6444 New_Occurrence_Of
6445 (RTE_Record_Component (RE_OSD_Num_Prims), Loc)),
6446 Expression =>
6447 Make_Integer_Literal (Loc, Nb_Prim)),
6448
6449 Make_Component_Association (Loc,
6450 Choices => New_List (
6451 New_Occurrence_Of
6452 (RTE_Record_Component (RE_OSD_Table), Loc)),
6453 Expression => Make_Aggregate (Loc,
6454 Component_Associations => OSD_Aggr_List))))));
6455
6456 return
6457 Make_Attribute_Reference (Loc,
6458 Prefix => New_Reference_To (OSD, Loc),
6459 Attribute_Name => Name_Unchecked_Access);
6460 end if;
6461 end Make_OSD;
6462
6463 -- Local variables
6464
6465 Nb_Prim : constant Nat := Count_Primitives (Typ);
87d6f1a4 6466 AI : Elmt_Id;
bf7f5966 6467 I_Depth : Nat;
87d6f1a4 6468 Iface_Table_Node : Node_Id;
bf7f5966 6469 Num_Ifaces : Nat;
87d6f1a4 6470 TSD_Aggr_List : List_Id;
6471 Typ_Ifaces : Elist_Id;
6472 TSD_Tags_List : List_Id;
6473
6474 Tname : constant Name_Id := Chars (Typ);
bf7f5966 6475 Name_SSD : constant Name_Id :=
6476 New_External_Name (Tname, 'S', Suffix_Index => -1);
87d6f1a4 6477 Name_TSD : constant Name_Id :=
6478 New_External_Name (Tname, 'B', Suffix_Index => -1);
bf7f5966 6479 SSD : constant Entity_Id :=
6480 Make_Defining_Identifier (Loc, Name_SSD);
87d6f1a4 6481 TSD : constant Entity_Id :=
6482 Make_Defining_Identifier (Loc, Name_TSD);
6483 begin
6484 -- Generate code to create the storage for the type specific data object
6485 -- with enough space to store the tags of the ancestors plus the tags
6486 -- of all the implemented interfaces (as described in a-tags.ads).
6487
6488 -- TSD : Type_Specific_Data (I_Depth) :=
6489 -- (Idepth => I_Depth,
6cb4b973 6490 -- Tag_Kind => <tag_kind-value>,
87d6f1a4 6491 -- Access_Level => Type_Access_Level (Typ),
d67a83fe 6492 -- Alignment => Typ'Alignment,
87d6f1a4 6493 -- HT_Link => null,
6494 -- Type_Is_Abstract => <<boolean-value>>,
6495 -- Type_Is_Library_Level => <<boolean-value>>,
6496 -- Interfaces_Table => <<access-value>>
6cb4b973 6497 -- SSD => SSD_Table'Address
87d6f1a4 6498 -- Tags_Table => (0 => Typ'Tag,
6499 -- 1 => Parent'Tag
6500 -- ...));
6501
6502 TSD_Aggr_List := New_List;
6503
6504 -- Idepth: Count ancestors to compute the inheritance depth. For private
6505 -- extensions, always go to the full view in order to compute the real
6506 -- inheritance depth.
6507
6508 declare
6509 Current_Typ : Entity_Id;
6510 Parent_Typ : Entity_Id;
6511
6512 begin
6513 I_Depth := 0;
6514 Current_Typ := Typ;
6515 loop
6516 Parent_Typ := Etype (Current_Typ);
6517
6518 if Is_Private_Type (Parent_Typ) then
6519 Parent_Typ := Full_View (Base_Type (Parent_Typ));
6520 end if;
6521
6522 exit when Parent_Typ = Current_Typ;
6523
6524 I_Depth := I_Depth + 1;
6525 Current_Typ := Parent_Typ;
6526 end loop;
6527 end;
6528
6cb4b973 6529 -- I_Depth
6530
87d6f1a4 6531 Append_To (TSD_Aggr_List,
6532 Make_Integer_Literal (Loc, I_Depth));
6533
6cb4b973 6534 -- Tag_Kind
6535
6536 Append_To (TSD_Aggr_List, Tagged_Kind (Typ));
6537
87d6f1a4 6538 -- Access_Level
6539
6540 Append_To (TSD_Aggr_List,
6541 Make_Integer_Literal (Loc, Type_Access_Level (Typ)));
6542
d67a83fe 6543 -- Alignment
6544
6fc3e7ad 6545 -- For CPP types we cannot rely on the value of 'Alignment provided
44705307 6546 -- by the backend to initialize this TSD field. Why not???
6fc3e7ad 6547
6548 if Convention (Typ) = Convention_CPP
6549 or else Is_CPP_Class (Root_Type (Typ))
6550 then
6551 Append_To (TSD_Aggr_List,
6552 Make_Integer_Literal (Loc, 0));
6553 else
6554 Append_To (TSD_Aggr_List,
6555 Make_Attribute_Reference (Loc,
6556 Prefix => New_Reference_To (Typ, Loc),
6557 Attribute_Name => Name_Alignment));
6558 end if;
d67a83fe 6559
87d6f1a4 6560 -- HT_Link
6561
6562 Append_To (TSD_Aggr_List,
6563 Make_Null (Loc));
6564
6565 -- Type_Is_Abstract (Ada 2012: AI05-0173)
6566
6567 declare
6568 Type_Is_Abstract : Entity_Id;
6569
6570 begin
6571 Type_Is_Abstract :=
6572 Boolean_Literals (Is_Abstract_Type (Typ));
6573
6574 Append_To (TSD_Aggr_List,
6575 New_Occurrence_Of (Type_Is_Abstract, Loc));
6576 end;
6577
6578 -- Type_Is_Library_Level
6579
6580 declare
6581 Type_Is_Library_Level : Entity_Id;
87d6f1a4 6582 begin
6583 Type_Is_Library_Level :=
6584 Boolean_Literals (Is_Library_Level_Entity (Typ));
87d6f1a4 6585 Append_To (TSD_Aggr_List,
6586 New_Occurrence_Of (Type_Is_Library_Level, Loc));
6587 end;
6588
6589 -- Interfaces_Table (required for AI-405)
6590
6591 if RTE_Record_Component_Available (RE_Interfaces_Table) then
6592
6593 -- Count the number of interface types implemented by Typ
6594
6595 Collect_Interfaces (Typ, Typ_Ifaces);
6596
bf7f5966 6597 Num_Ifaces := 0;
87d6f1a4 6598 AI := First_Elmt (Typ_Ifaces);
6599 while Present (AI) loop
6600 Num_Ifaces := Num_Ifaces + 1;
6601 Next_Elmt (AI);
6602 end loop;
6603
6604 if Num_Ifaces = 0 then
6605 Iface_Table_Node := Make_Null (Loc);
6606
6607 -- Generate the Interface_Table object
6608
6609 else
6610 declare
6611 TSD_Ifaces_List : constant List_Id := New_List;
6cb4b973 6612 Iface : Entity_Id;
87d6f1a4 6613 ITable : Node_Id;
6614
6615 begin
6616 AI := First_Elmt (Typ_Ifaces);
6617 while Present (AI) loop
6cb4b973 6618 Iface := Node (AI);
6619
87d6f1a4 6620 Append_To (TSD_Ifaces_List,
6621 Make_Aggregate (Loc,
6622 Expressions => New_List (
6cb4b973 6623
4055a532 6624 -- Iface_Tag
6cb4b973 6625
87d6f1a4 6626 Make_Attribute_Reference (Loc,
b860aaec 6627 Prefix => New_Reference_To (Iface, Loc),
6cb4b973 6628 Attribute_Name => Name_Tag),
6629
4055a532 6630 -- OSD
6cb4b973 6631
6632 Make_OSD (Iface))));
87d6f1a4 6633
6634 Next_Elmt (AI);
6635 end loop;
6636
6637 ITable := Make_Temporary (Loc, 'I');
6638
6639 Append_To (Result,
6640 Make_Object_Declaration (Loc,
6641 Defining_Identifier => ITable,
6642 Aliased_Present => True,
6643 Constant_Present => True,
6644 Object_Definition =>
6645 Make_Subtype_Indication (Loc,
6646 Subtype_Mark =>
6647 New_Reference_To (RTE (RE_Interface_Data), Loc),
b860aaec 6648 Constraint => Make_Index_Or_Discriminant_Constraint
87d6f1a4 6649 (Loc,
6650 Constraints => New_List (
6651 Make_Integer_Literal (Loc, Num_Ifaces)))),
6652
6653 Expression => Make_Aggregate (Loc,
6654 Expressions => New_List (
6655 Make_Integer_Literal (Loc, Num_Ifaces),
6656 Make_Aggregate (Loc,
6657 Expressions => TSD_Ifaces_List)))));
6658
6659 Iface_Table_Node :=
6660 Make_Attribute_Reference (Loc,
6661 Prefix => New_Reference_To (ITable, Loc),
6662 Attribute_Name => Name_Unchecked_Access);
6663 end;
6664 end if;
6665
6666 Append_To (TSD_Aggr_List, Iface_Table_Node);
6667 end if;
6668
bf7f5966 6669 -- Generate the Select Specific Data table for synchronized types that
6670 -- implement synchronized interfaces. The size of the table is
6671 -- constrained by the number of non-predefined primitive operations.
6672
bf7f5966 6673 if RTE_Record_Component_Available (RE_SSD) then
6674 if Ada_Version >= Ada_2005
6675 and then Has_DT (Typ)
6676 and then Is_Concurrent_Record_Type (Typ)
6677 and then Has_Interfaces (Typ)
6678 and then Nb_Prim > 0
6679 and then not Is_Abstract_Type (Typ)
6680 and then not Is_Controlled (Typ)
6681 and then not Restriction_Active (No_Dispatching_Calls)
6682 and then not Restriction_Active (No_Select_Statements)
6683 then
6684 Append_To (Result,
6685 Make_Object_Declaration (Loc,
6686 Defining_Identifier => SSD,
6687 Aliased_Present => True,
6688 Object_Definition =>
6689 Make_Subtype_Indication (Loc,
6690 Subtype_Mark => New_Reference_To (
6691 RTE (RE_Select_Specific_Data), Loc),
6692 Constraint =>
6693 Make_Index_Or_Discriminant_Constraint (Loc,
6694 Constraints => New_List (
6695 Make_Integer_Literal (Loc, Nb_Prim))))));
6696
6697 -- This table is initialized by Make_Select_Specific_Data_Table,
6698 -- which calls Set_Entry_Index and Set_Prim_Op_Kind.
6699
6700 Append_To (TSD_Aggr_List,
6701 Make_Attribute_Reference (Loc,
4055a532 6702 Prefix => New_Reference_To (SSD, Loc),
bf7f5966 6703 Attribute_Name => Name_Unchecked_Access));
6704 else
6705 Append_To (TSD_Aggr_List, Make_Null (Loc));
6706 end if;
6707 end if;
6708
87d6f1a4 6709 -- Initialize the table of ancestor tags. In case of interface types
6710 -- this table is not needed.
6711
6712 TSD_Tags_List := New_List;
6713
6714 -- Fill position 0 with Typ'Tag
6715
6716 Append_To (TSD_Tags_List,
6717 Make_Attribute_Reference (Loc,
4055a532 6718 Prefix => New_Reference_To (Typ, Loc),
87d6f1a4 6719 Attribute_Name => Name_Tag));
6720
6721 -- Fill the rest of the table with the tags of the ancestors
6722
6723 declare
6724 Current_Typ : Entity_Id;
6725 Parent_Typ : Entity_Id;
6726 Pos : Nat;
6727
6728 begin
6729 Pos := 1;
6730 Current_Typ := Typ;
6731
6732 loop
6733 Parent_Typ := Etype (Current_Typ);
6734
6735 if Is_Private_Type (Parent_Typ) then
6736 Parent_Typ := Full_View (Base_Type (Parent_Typ));
6737 end if;
6738
6739 exit when Parent_Typ = Current_Typ;
6740
6741 Append_To (TSD_Tags_List,
6742 Make_Attribute_Reference (Loc,
4055a532 6743 Prefix => New_Reference_To (Parent_Typ, Loc),
87d6f1a4 6744 Attribute_Name => Name_Tag));
6745
6746 Pos := Pos + 1;
6747 Current_Typ := Parent_Typ;
6748 end loop;
6749
6750 pragma Assert (Pos = I_Depth + 1);
6751 end;
6752
6753 Append_To (TSD_Aggr_List,
6754 Make_Aggregate (Loc,
6755 Expressions => TSD_Tags_List));
6756
6757 -- Build the TSD object
6758
6759 Append_To (Result,
6760 Make_Object_Declaration (Loc,
6761 Defining_Identifier => TSD,
6762 Aliased_Present => True,
6763 Constant_Present => True,
6764 Object_Definition =>
6765 Make_Subtype_Indication (Loc,
6766 Subtype_Mark => New_Reference_To (
6767 RTE (RE_Type_Specific_Data), Loc),
6768 Constraint =>
6769 Make_Index_Or_Discriminant_Constraint (Loc,
6770 Constraints => New_List (
6771 Make_Integer_Literal (Loc, I_Depth)))),
6772
6773 Expression => Make_Aggregate (Loc,
6774 Expressions => TSD_Aggr_List)));
6775
6776 -- Generate:
6777 -- Check_TSD
6778 -- (TSD => TSD'Unrestricted_Access);
6779
79500ea0 6780 if Ada_Version >= Ada_2005
6781 and then Is_Library_Level_Entity (Typ)
6782 and then Has_External_Tag_Rep_Clause (Typ)
6783 and then RTE_Available (RE_Check_TSD)
6784 and then not Debug_Flag_QQ
6785 then
6786 Append_To (Result,
6787 Make_Procedure_Call_Statement (Loc,
6788 Name => New_Reference_To (RTE (RE_Check_TSD), Loc),
6789 Parameter_Associations => New_List (
6790 Make_Attribute_Reference (Loc,
f53dda32 6791 Prefix => New_Reference_To (TSD, Loc),
79500ea0 6792 Attribute_Name => Name_Unrestricted_Access))));
6793 end if;
87d6f1a4 6794
6795 -- Generate:
6796 -- Register_TSD (TSD'Unrestricted_Access);
6797
6798 Append_To (Result,
6799 Make_Procedure_Call_Statement (Loc,
6800 Name => New_Reference_To (RTE (RE_Register_TSD), Loc),
6801 Parameter_Associations => New_List (
6802 Make_Attribute_Reference (Loc,
f53dda32 6803 Prefix => New_Reference_To (TSD, Loc),
87d6f1a4 6804 Attribute_Name => Name_Unrestricted_Access))));
6805
bf7f5966 6806 -- Populate the two auxiliary tables used for dispatching asynchronous,
6807 -- conditional and timed selects for synchronized types that implement
6808 -- a limited interface. Skip this step in Ravenscar profile or when
6809 -- general dispatching is forbidden.
6810
6811 if Ada_Version >= Ada_2005
6812 and then Is_Concurrent_Record_Type (Typ)
6813 and then Has_Interfaces (Typ)
6814 and then not Restriction_Active (No_Dispatching_Calls)
6815 and then not Restriction_Active (No_Select_Statements)
6816 then
6817 Append_List_To (Result,
6818 Make_Select_Specific_Data_Table (Typ));
6819 end if;
6820
87d6f1a4 6821 return Result;
6822 end Make_VM_TSD;
6823
76a1c25b 6824 -------------------------------------
6825 -- Make_Select_Specific_Data_Table --
6826 -------------------------------------
d62940bf 6827
76a1c25b 6828 function Make_Select_Specific_Data_Table
6829 (Typ : Entity_Id) return List_Id
6830 is
6831 Assignments : constant List_Id := New_List;
6832 Loc : constant Source_Ptr := Sloc (Typ);
d62940bf 6833
68f95949 6834 Conc_Typ : Entity_Id;
6835 Decls : List_Id;
68f95949 6836 Prim : Entity_Id;
6837 Prim_Als : Entity_Id;
6838 Prim_Elmt : Elmt_Id;
6839 Prim_Pos : Uint;
343d35dc 6840 Nb_Prim : Nat := 0;
d62940bf 6841
76a1c25b 6842 type Examined_Array is array (Int range <>) of Boolean;
d62940bf 6843
76a1c25b 6844 function Find_Entry_Index (E : Entity_Id) return Uint;
6845 -- Given an entry, find its index in the visible declarations of the
6846 -- corresponding concurrent type of Typ.
d62940bf 6847
76a1c25b 6848 ----------------------
6849 -- Find_Entry_Index --
6850 ----------------------
d62940bf 6851
76a1c25b 6852 function Find_Entry_Index (E : Entity_Id) return Uint is
6853 Index : Uint := Uint_1;
6854 Subp_Decl : Entity_Id;
d62940bf 6855
76a1c25b 6856 begin
6857 if Present (Decls)
6858 and then not Is_Empty_List (Decls)
6859 then
6860 Subp_Decl := First (Decls);
6861 while Present (Subp_Decl) loop
6862 if Nkind (Subp_Decl) = N_Entry_Declaration then
6863 if Defining_Identifier (Subp_Decl) = E then
6864 return Index;
6865 end if;
d62940bf 6866
76a1c25b 6867 Index := Index + 1;
6868 end if;
d62940bf 6869
76a1c25b 6870 Next (Subp_Decl);
6871 end loop;
6872 end if;
d62940bf 6873
76a1c25b 6874 return Uint_0;
6875 end Find_Entry_Index;
6876
bf7f5966 6877 -- Local variables
6878
6879 Tag_Node : Node_Id;
6880
76a1c25b 6881 -- Start of processing for Make_Select_Specific_Data_Table
6882
6883 begin
68f95949 6884 pragma Assert (not Restriction_Active (No_Dispatching_Calls));
6885
76a1c25b 6886 if Present (Corresponding_Concurrent_Type (Typ)) then
6887 Conc_Typ := Corresponding_Concurrent_Type (Typ);
6888
17e14451 6889 if Present (Full_View (Conc_Typ)) then
6890 Conc_Typ := Full_View (Conc_Typ);
6891 end if;
6892
76a1c25b 6893 if Ekind (Conc_Typ) = E_Protected_Type then
6894 Decls := Visible_Declarations (Protected_Definition (
6895 Parent (Conc_Typ)));
d62940bf 6896 else
6897 pragma Assert (Ekind (Conc_Typ) = E_Task_Type);
76a1c25b 6898 Decls := Visible_Declarations (Task_Definition (
6899 Parent (Conc_Typ)));
6900 end if;
6901 end if;
d62940bf 6902
76a1c25b 6903 -- Count the non-predefined primitive operations
d62940bf 6904
76a1c25b 6905 Prim_Elmt := First_Elmt (Primitive_Operations (Typ));
6906 while Present (Prim_Elmt) loop
af647dc7 6907 Prim := Node (Prim_Elmt);
6908
6909 if not (Is_Predefined_Dispatching_Operation (Prim)
6910 or else Is_Predefined_Dispatching_Alias (Prim))
6911 then
76a1c25b 6912 Nb_Prim := Nb_Prim + 1;
6913 end if;
d62940bf 6914
76a1c25b 6915 Next_Elmt (Prim_Elmt);
6916 end loop;
d62940bf 6917
76a1c25b 6918 declare
68f95949 6919 Examined : Examined_Array (1 .. Nb_Prim) := (others => False);
d62940bf 6920
76a1c25b 6921 begin
6922 Prim_Elmt := First_Elmt (Primitive_Operations (Typ));
6923 while Present (Prim_Elmt) loop
6924 Prim := Node (Prim_Elmt);
d62940bf 6925
af647dc7 6926 -- Look for primitive overriding an abstract interface subprogram
d62940bf 6927
a652dd51 6928 if Present (Interface_Alias (Prim))
c8da6114 6929 and then not
6930 Is_Ancestor
cb4af01d 6931 (Find_Dispatching_Type (Interface_Alias (Prim)), Typ,
6932 Use_Full_View => True)
af647dc7 6933 and then not Examined (UI_To_Int (DT_Position (Alias (Prim))))
6934 then
6935 Prim_Pos := DT_Position (Alias (Prim));
6936 pragma Assert (UI_To_Int (Prim_Pos) <= Nb_Prim);
6937 Examined (UI_To_Int (Prim_Pos)) := True;
d62940bf 6938
af647dc7 6939 -- Set the primitive operation kind regardless of subprogram
6940 -- type. Generate:
6941 -- Ada.Tags.Set_Prim_Op_Kind (DT_Ptr, <position>, <kind>);
d62940bf 6942
bf7f5966 6943 if Tagged_Type_Expansion then
6944 Tag_Node :=
6945 New_Reference_To
6946 (Node (First_Elmt (Access_Disp_Table (Typ))), Loc);
6947
6948 else
6949 Tag_Node :=
6950 Make_Attribute_Reference (Loc,
4055a532 6951 Prefix => New_Reference_To (Typ, Loc),
bf7f5966 6952 Attribute_Name => Name_Tag);
6953 end if;
6954
af647dc7 6955 Append_To (Assignments,
725a69d2 6956 Make_Procedure_Call_Statement (Loc,
6957 Name => New_Reference_To (RTE (RE_Set_Prim_Op_Kind), Loc),
6958 Parameter_Associations => New_List (
bf7f5966 6959 Tag_Node,
725a69d2 6960 Make_Integer_Literal (Loc, Prim_Pos),
6961 Prim_Op_Kind (Alias (Prim), Typ))));
68f95949 6962
af647dc7 6963 -- Retrieve the root of the alias chain
68f95949 6964
fc2907f6 6965 Prim_Als := Ultimate_Alias (Prim);
68f95949 6966
af647dc7 6967 -- In the case of an entry wrapper, set the entry index
68f95949 6968
af647dc7 6969 if Ekind (Prim) = E_Procedure
6970 and then Is_Primitive_Wrapper (Prim_Als)
6971 and then Ekind (Wrapped_Entity (Prim_Als)) = E_Entry
6972 then
6973 -- Generate:
6974 -- Ada.Tags.Set_Entry_Index
6975 -- (DT_Ptr, <position>, <index>);
68f95949 6976
bf7f5966 6977 if Tagged_Type_Expansion then
6978 Tag_Node :=
6979 New_Reference_To
96dc081d 6980 (Node (First_Elmt (Access_Disp_Table (Typ))), Loc);
bf7f5966 6981 else
6982 Tag_Node :=
6983 Make_Attribute_Reference (Loc,
4055a532 6984 Prefix => New_Reference_To (Typ, Loc),
bf7f5966 6985 Attribute_Name => Name_Tag);
6986 end if;
6987
af647dc7 6988 Append_To (Assignments,
725a69d2 6989 Make_Procedure_Call_Statement (Loc,
6990 Name =>
6991 New_Reference_To (RTE (RE_Set_Entry_Index), Loc),
6992 Parameter_Associations => New_List (
bf7f5966 6993 Tag_Node,
725a69d2 6994 Make_Integer_Literal (Loc, Prim_Pos),
6995 Make_Integer_Literal (Loc,
6996 Find_Entry_Index (Wrapped_Entity (Prim_Als))))));
76a1c25b 6997 end if;
6998 end if;
6999
76a1c25b 7000 Next_Elmt (Prim_Elmt);
7001 end loop;
7002 end;
7003
7004 return Assignments;
7005 end Make_Select_Specific_Data_Table;
d62940bf 7006
17e14451 7007 ---------------
7008 -- Make_Tags --
7009 ---------------
7010
7011 function Make_Tags (Typ : Entity_Id) return List_Id is
f301a57b 7012 Loc : constant Source_Ptr := Sloc (Typ);
7013 Result : constant List_Id := New_List;
7014
7015 procedure Import_DT
7016 (Tag_Typ : Entity_Id;
7017 DT : Entity_Id;
7018 Is_Secondary_DT : Boolean);
7019 -- Import the dispatch table DT of tagged type Tag_Typ. Required to
7020 -- generate forward references and statically allocate the table. For
7021 -- primary dispatch tables that require no dispatch table generate:
d03ada96 7022
f301a57b 7023 -- DT : static aliased constant Non_Dispatch_Table_Wrapper;
d03ada96 7024 -- pragma Import (Ada, DT);
7025
f301a57b 7026 -- Otherwise generate:
d03ada96 7027
f301a57b 7028 -- DT : static aliased constant Dispatch_Table_Wrapper (Nb_Prim);
d03ada96 7029 -- pragma Import (Ada, DT);
7854e190 7030
f301a57b 7031 ---------------
7032 -- Import_DT --
7033 ---------------
24971415 7034
f301a57b 7035 procedure Import_DT
7036 (Tag_Typ : Entity_Id;
7037 DT : Entity_Id;
7038 Is_Secondary_DT : Boolean)
7039 is
7040 DT_Constr_List : List_Id;
7041 Nb_Prim : Nat;
24971415 7042
f301a57b 7043 begin
7044 Set_Is_Imported (DT);
7045 Set_Ekind (DT, E_Constant);
7046 Set_Related_Type (DT, Typ);
24971415 7047
24971415 7048 -- The scope must be set now to call Get_External_Name
7049
7050 Set_Scope (DT, Current_Scope);
7051
7052 Get_External_Name (DT, True);
7053 Set_Interface_Name (DT,
d03ada96 7054 Make_String_Literal (Loc, Strval => String_From_Name_Buffer));
17e14451 7055
24971415 7056 -- Ensure proper Sprint output of this implicit importation
17e14451 7057
24971415 7058 Set_Is_Internal (DT);
17e14451 7059
24971415 7060 -- Save this entity to allow Make_DT to generate its exportation
7061
f301a57b 7062 Append_Elmt (DT, Dispatch_Table_Wrappers (Typ));
24971415 7063
f301a57b 7064 -- No dispatch table required
acf97c11 7065
d03ada96 7066 if not Is_Secondary_DT and then not Has_DT (Tag_Typ) then
f301a57b 7067 Append_To (Result,
7068 Make_Object_Declaration (Loc,
7069 Defining_Identifier => DT,
7070 Aliased_Present => True,
7071 Constant_Present => True,
7072 Object_Definition =>
7073 New_Reference_To (RTE (RE_No_Dispatch_Table_Wrapper), Loc)));
7074
7075 else
24971415 7076 -- Calculate the number of primitives of the dispatch table and
7077 -- the size of the Type_Specific_Data record.
7078
f301a57b 7079 Nb_Prim :=
7080 UI_To_Int (DT_Entry_Count (First_Tag_Component (Tag_Typ)));
24971415 7081
d03ada96 7082 -- If the tagged type has no primitives we add a dummy slot whose
7083 -- address will be the tag of this type.
24971415 7084
7085 if Nb_Prim = 0 then
7086 DT_Constr_List :=
7087 New_List (Make_Integer_Literal (Loc, 1));
7088 else
7089 DT_Constr_List :=
7090 New_List (Make_Integer_Literal (Loc, Nb_Prim));
7091 end if;
7092
7093 Append_To (Result,
7094 Make_Object_Declaration (Loc,
7095 Defining_Identifier => DT,
7096 Aliased_Present => True,
7097 Constant_Present => True,
7098 Object_Definition =>
7099 Make_Subtype_Indication (Loc,
7100 Subtype_Mark =>
7101 New_Reference_To (RTE (RE_Dispatch_Table_Wrapper), Loc),
7102 Constraint => Make_Index_Or_Discriminant_Constraint (Loc,
7103 Constraints => DT_Constr_List))));
f301a57b 7104 end if;
7105 end Import_DT;
7106
7107 -- Local variables
7108
7109 Tname : constant Name_Id := Chars (Typ);
7110 AI_Tag_Comp : Elmt_Id;
7640ed3d 7111 DT : Node_Id := Empty;
f301a57b 7112 DT_Ptr : Node_Id;
7113 Predef_Prims_Ptr : Node_Id;
d04be62f 7114 Iface_DT : Node_Id := Empty;
f301a57b 7115 Iface_DT_Ptr : Node_Id;
d215f619 7116 New_Node : Node_Id;
f301a57b 7117 Suffix_Index : Int;
7118 Typ_Name : Name_Id;
7119 Typ_Comps : Elist_Id;
7120
7121 -- Start of processing for Make_Tags
7122
7123 begin
d00681a7 7124 pragma Assert (No (Access_Disp_Table (Typ)));
7125 Set_Access_Disp_Table (Typ, New_Elmt_List);
f301a57b 7126
7127 -- 1) Generate the primary tag entities
7128
7129 -- Primary dispatch table containing user-defined primitives
7130
d00681a7 7131 DT_Ptr := Make_Defining_Identifier (Loc, New_External_Name (Tname, 'P'));
7132 Set_Etype (DT_Ptr, RTE (RE_Tag));
7133 Append_Elmt (DT_Ptr, Access_Disp_Table (Typ));
f301a57b 7134
d00681a7 7135 -- Minimum decoration
f301a57b 7136
d00681a7 7137 Set_Ekind (DT_Ptr, E_Variable);
7138 Set_Related_Type (DT_Ptr, Typ);
f301a57b 7139
d00681a7 7140 -- For CPP types there is no need to build the dispatch tables since
5682f43c 7141 -- they are imported from the C++ side. If the CPP type has an IP then
7142 -- we declare now the variable that will store the copy of the C++ tag.
d03ada96 7143 -- If the CPP type is an interface, we need the variable as well because
7144 -- it becomes the pointer to the corresponding secondary table.
f301a57b 7145
d00681a7 7146 if Is_CPP_Class (Typ) then
5682f43c 7147 if Has_CPP_Constructors (Typ) or else Is_Interface (Typ) then
24971415 7148 Append_To (Result,
7149 Make_Object_Declaration (Loc,
7150 Defining_Identifier => DT_Ptr,
24971415 7151 Object_Definition => New_Reference_To (RTE (RE_Tag), Loc),
7152 Expression =>
7153 Unchecked_Convert_To (RTE (RE_Tag),
d00681a7 7154 New_Reference_To (RTE (RE_Null_Address), Loc))));
24971415 7155
d00681a7 7156 Set_Is_Statically_Allocated (DT_Ptr,
7157 Is_Library_Level_Tagged_Type (Typ));
7158 end if;
9af28f61 7159
d00681a7 7160 -- Ada types
3dbca0d5 7161
d00681a7 7162 else
7163 -- Primary dispatch table containing predefined primitives
acf97c11 7164
d00681a7 7165 Predef_Prims_Ptr :=
7166 Make_Defining_Identifier (Loc,
7167 Chars => New_External_Name (Tname, 'Y'));
7168 Set_Etype (Predef_Prims_Ptr, RTE (RE_Address));
7169 Append_Elmt (Predef_Prims_Ptr, Access_Disp_Table (Typ));
24971415 7170
d00681a7 7171 -- Import the forward declaration of the Dispatch Table wrapper
d03ada96 7172 -- record (Make_DT will take care of exporting it).
24971415 7173
d00681a7 7174 if Building_Static_DT (Typ) then
7175 Set_Dispatch_Table_Wrappers (Typ, New_Elmt_List);
17e14451 7176
d00681a7 7177 DT :=
7178 Make_Defining_Identifier (Loc,
7179 Chars => New_External_Name (Tname, 'T'));
7180
7181 Import_DT (Typ, DT, Is_Secondary_DT => False);
7182
7183 if Has_DT (Typ) then
7184 Append_To (Result,
7185 Make_Object_Declaration (Loc,
7186 Defining_Identifier => DT_Ptr,
7187 Constant_Present => True,
7188 Object_Definition => New_Reference_To (RTE (RE_Tag), Loc),
4055a532 7189 Expression =>
d00681a7 7190 Unchecked_Convert_To (RTE (RE_Tag),
7191 Make_Attribute_Reference (Loc,
4055a532 7192 Prefix =>
d00681a7 7193 Make_Selected_Component (Loc,
4055a532 7194 Prefix => New_Reference_To (DT, Loc),
7195 Selector_Name =>
7196 New_Occurrence_Of
7197 (RTE_Record_Component (RE_Prims_Ptr), Loc)),
d00681a7 7198 Attribute_Name => Name_Address))));
7199
7200 -- Generate the SCIL node for the previous object declaration
7201 -- because it has a tag initialization.
7202
7203 if Generate_SCIL then
7204 New_Node :=
7205 Make_SCIL_Dispatch_Table_Tag_Init (Sloc (Last (Result)));
7206 Set_SCIL_Entity (New_Node, Typ);
7207 Set_SCIL_Node (Last (Result), New_Node);
7208 end if;
7209
7210 Append_To (Result,
7211 Make_Object_Declaration (Loc,
7212 Defining_Identifier => Predef_Prims_Ptr,
7213 Constant_Present => True,
4055a532 7214 Object_Definition =>
7215 New_Reference_To (RTE (RE_Address), Loc),
7216 Expression =>
d00681a7 7217 Make_Attribute_Reference (Loc,
4055a532 7218 Prefix =>
d00681a7 7219 Make_Selected_Component (Loc,
4055a532 7220 Prefix => New_Reference_To (DT, Loc),
7221 Selector_Name =>
7222 New_Occurrence_Of
7223 (RTE_Record_Component (RE_Predef_Prims), Loc)),
d00681a7 7224 Attribute_Name => Name_Address)));
7225
7226 -- No dispatch table required
7227
7228 else
7229 Append_To (Result,
7230 Make_Object_Declaration (Loc,
7231 Defining_Identifier => DT_Ptr,
7232 Constant_Present => True,
7233 Object_Definition => New_Reference_To (RTE (RE_Tag), Loc),
4055a532 7234 Expression =>
d00681a7 7235 Unchecked_Convert_To (RTE (RE_Tag),
7236 Make_Attribute_Reference (Loc,
4055a532 7237 Prefix =>
d00681a7 7238 Make_Selected_Component (Loc,
7239 Prefix => New_Reference_To (DT, Loc),
4055a532 7240 Selector_Name =>
7241 New_Occurrence_Of
7242 (RTE_Record_Component (RE_NDT_Prims_Ptr),
7243 Loc)),
d00681a7 7244 Attribute_Name => Name_Address))));
7245 end if;
7246
7247 Set_Is_True_Constant (DT_Ptr);
7248 Set_Is_Statically_Allocated (DT_Ptr);
7249 end if;
7250 end if;
17e14451 7251
7252 -- 2) Generate the secondary tag entities
7253
d00681a7 7254 -- Collect the components associated with secondary dispatch tables
7255
a652dd51 7256 if Has_Interfaces (Typ) then
d00681a7 7257 Collect_Interface_Components (Typ, Typ_Comps);
f301a57b 7258
d03ada96 7259 -- For each interface type we build a unique external name associated
7260 -- with its secondary dispatch table. This name is used to declare an
7261 -- object that references this secondary dispatch table, whose value
7262 -- will be used for the elaboration of Typ objects, and also for the
7263 -- elaboration of objects of types derived from Typ that do not
7264 -- override the primitives of this interface type.
f301a57b 7265
7266 Suffix_Index := 1;
17e14451 7267
d00681a7 7268 -- Note: The value of Suffix_Index must be in sync with the
7269 -- Suffix_Index values of secondary dispatch tables generated
7270 -- by Make_DT.
17e14451 7271
d00681a7 7272 if Is_CPP_Class (Typ) then
7273 AI_Tag_Comp := First_Elmt (Typ_Comps);
7274 while Present (AI_Tag_Comp) loop
7275 Get_Secondary_DT_External_Name
7276 (Typ, Related_Type (Node (AI_Tag_Comp)), Suffix_Index);
7277 Typ_Name := Name_Find;
17e14451 7278
d00681a7 7279 -- Declare variables that will store the copy of the C++
d03ada96 7280 -- secondary tags.
f301a57b 7281
d00681a7 7282 Iface_DT_Ptr :=
7283 Make_Defining_Identifier (Loc,
7284 Chars => New_External_Name (Typ_Name, 'P'));
7285 Set_Etype (Iface_DT_Ptr, RTE (RE_Interface_Tag));
7286 Set_Ekind (Iface_DT_Ptr, E_Variable);
7287 Set_Is_Tag (Iface_DT_Ptr);
acf97c11 7288
d00681a7 7289 Set_Has_Thunks (Iface_DT_Ptr);
7290 Set_Related_Type
7291 (Iface_DT_Ptr, Related_Type (Node (AI_Tag_Comp)));
7292 Append_Elmt (Iface_DT_Ptr, Access_Disp_Table (Typ));
cdb1c38f 7293
f301a57b 7294 Append_To (Result,
7295 Make_Object_Declaration (Loc,
7296 Defining_Identifier => Iface_DT_Ptr,
f301a57b 7297 Object_Definition => New_Reference_To
7298 (RTE (RE_Interface_Tag), Loc),
7299 Expression =>
7300 Unchecked_Convert_To (RTE (RE_Interface_Tag),
d00681a7 7301 New_Reference_To (RTE (RE_Null_Address), Loc))));
f301a57b 7302
d00681a7 7303 Set_Is_Statically_Allocated (Iface_DT_Ptr,
7304 Is_Library_Level_Tagged_Type (Typ));
acf97c11 7305
d00681a7 7306 Next_Elmt (AI_Tag_Comp);
7307 end loop;
acf97c11 7308
d00681a7 7309 -- This is not a CPP_Class type
acf97c11 7310
d00681a7 7311 else
7312 AI_Tag_Comp := First_Elmt (Typ_Comps);
7313 while Present (AI_Tag_Comp) loop
7314 Get_Secondary_DT_External_Name
7315 (Typ, Related_Type (Node (AI_Tag_Comp)), Suffix_Index);
7316 Typ_Name := Name_Find;
17e14451 7317
d00681a7 7318 if Building_Static_DT (Typ) then
7319 Iface_DT :=
7320 Make_Defining_Identifier (Loc,
7321 Chars => New_External_Name
7322 (Typ_Name, 'T', Suffix_Index => -1));
7323 Import_DT
7324 (Tag_Typ => Related_Type (Node (AI_Tag_Comp)),
7325 DT => Iface_DT,
7326 Is_Secondary_DT => True);
7327 end if;
acf97c11 7328
d00681a7 7329 -- Secondary dispatch table referencing thunks to user-defined
7330 -- primitives covered by this interface.
acf97c11 7331
d00681a7 7332 Iface_DT_Ptr :=
7333 Make_Defining_Identifier (Loc,
7334 Chars => New_External_Name (Typ_Name, 'P'));
7335 Set_Etype (Iface_DT_Ptr, RTE (RE_Interface_Tag));
7336 Set_Ekind (Iface_DT_Ptr, E_Constant);
7337 Set_Is_Tag (Iface_DT_Ptr);
7338 Set_Has_Thunks (Iface_DT_Ptr);
7339 Set_Is_Statically_Allocated (Iface_DT_Ptr,
7340 Is_Library_Level_Tagged_Type (Typ));
7341 Set_Is_True_Constant (Iface_DT_Ptr);
7342 Set_Related_Type
7343 (Iface_DT_Ptr, Related_Type (Node (AI_Tag_Comp)));
7344 Append_Elmt (Iface_DT_Ptr, Access_Disp_Table (Typ));
7345
7346 if Building_Static_DT (Typ) then
7347 Append_To (Result,
7348 Make_Object_Declaration (Loc,
7349 Defining_Identifier => Iface_DT_Ptr,
7350 Constant_Present => True,
7351 Object_Definition => New_Reference_To
7352 (RTE (RE_Interface_Tag), Loc),
4055a532 7353 Expression =>
d00681a7 7354 Unchecked_Convert_To (RTE (RE_Interface_Tag),
7355 Make_Attribute_Reference (Loc,
4055a532 7356 Prefix =>
d00681a7 7357 Make_Selected_Component (Loc,
4055a532 7358 Prefix =>
7359 New_Reference_To (Iface_DT, Loc),
7360 Selector_Name =>
7361 New_Occurrence_Of
7362 (RTE_Record_Component (RE_Prims_Ptr),
7363 Loc)),
d00681a7 7364 Attribute_Name => Name_Address))));
7365 end if;
7366
7367 -- Secondary dispatch table referencing thunks to predefined
7368 -- primitives.
7369
7370 Iface_DT_Ptr :=
7371 Make_Defining_Identifier (Loc,
7372 Chars => New_External_Name (Typ_Name, 'Y'));
7373 Set_Etype (Iface_DT_Ptr, RTE (RE_Address));
7374 Set_Ekind (Iface_DT_Ptr, E_Constant);
7375 Set_Is_Tag (Iface_DT_Ptr);
7376 Set_Has_Thunks (Iface_DT_Ptr);
7377 Set_Is_Statically_Allocated (Iface_DT_Ptr,
7378 Is_Library_Level_Tagged_Type (Typ));
7379 Set_Is_True_Constant (Iface_DT_Ptr);
7380 Set_Related_Type
7381 (Iface_DT_Ptr, Related_Type (Node (AI_Tag_Comp)));
7382 Append_Elmt (Iface_DT_Ptr, Access_Disp_Table (Typ));
7383
7384 -- Secondary dispatch table referencing user-defined primitives
7385 -- covered by this interface.
7386
7387 Iface_DT_Ptr :=
7388 Make_Defining_Identifier (Loc,
7389 Chars => New_External_Name (Typ_Name, 'D'));
7390 Set_Etype (Iface_DT_Ptr, RTE (RE_Interface_Tag));
7391 Set_Ekind (Iface_DT_Ptr, E_Constant);
7392 Set_Is_Tag (Iface_DT_Ptr);
7393 Set_Is_Statically_Allocated (Iface_DT_Ptr,
7394 Is_Library_Level_Tagged_Type (Typ));
7395 Set_Is_True_Constant (Iface_DT_Ptr);
7396 Set_Related_Type
7397 (Iface_DT_Ptr, Related_Type (Node (AI_Tag_Comp)));
7398 Append_Elmt (Iface_DT_Ptr, Access_Disp_Table (Typ));
7399
7400 -- Secondary dispatch table referencing predefined primitives
7401
7402 Iface_DT_Ptr :=
7403 Make_Defining_Identifier (Loc,
7404 Chars => New_External_Name (Typ_Name, 'Z'));
7405 Set_Etype (Iface_DT_Ptr, RTE (RE_Address));
7406 Set_Ekind (Iface_DT_Ptr, E_Constant);
7407 Set_Is_Tag (Iface_DT_Ptr);
7408 Set_Is_Statically_Allocated (Iface_DT_Ptr,
7409 Is_Library_Level_Tagged_Type (Typ));
7410 Set_Is_True_Constant (Iface_DT_Ptr);
7411 Set_Related_Type
7412 (Iface_DT_Ptr, Related_Type (Node (AI_Tag_Comp)));
7413 Append_Elmt (Iface_DT_Ptr, Access_Disp_Table (Typ));
7414
7415 Next_Elmt (AI_Tag_Comp);
7416 end loop;
7417 end if;
17e14451 7418 end if;
7419
dffd0a90 7420 -- 3) At the end of Access_Disp_Table, if the type has user-defined
7421 -- primitives, we add the entity of an access type declaration that
7422 -- is used by Build_Get_Prim_Op_Address to expand dispatching calls
7423 -- through the primary dispatch table.
7424
7425 if UI_To_Int (DT_Entry_Count (First_Tag_Component (Typ))) = 0 then
7426 Analyze_List (Result);
17e14451 7427
7428 -- Generate:
cc60bd16 7429 -- type Typ_DT is array (1 .. Nb_Prims) of Prim_Ptr;
17e14451 7430 -- type Typ_DT_Acc is access Typ_DT;
7431
dffd0a90 7432 else
7433 declare
7434 Name_DT_Prims : constant Name_Id :=
7435 New_External_Name (Tname, 'G');
7436 Name_DT_Prims_Acc : constant Name_Id :=
7437 New_External_Name (Tname, 'H');
7438 DT_Prims : constant Entity_Id :=
7439 Make_Defining_Identifier (Loc,
7440 Name_DT_Prims);
7441 DT_Prims_Acc : constant Entity_Id :=
7442 Make_Defining_Identifier (Loc,
7443 Name_DT_Prims_Acc);
7444 begin
7445 Append_To (Result,
7446 Make_Full_Type_Declaration (Loc,
7447 Defining_Identifier => DT_Prims,
7448 Type_Definition =>
7449 Make_Constrained_Array_Definition (Loc,
7450 Discrete_Subtype_Definitions => New_List (
7451 Make_Range (Loc,
7452 Low_Bound => Make_Integer_Literal (Loc, 1),
7453 High_Bound => Make_Integer_Literal (Loc,
7454 DT_Entry_Count
7455 (First_Tag_Component (Typ))))),
7456 Component_Definition =>
7457 Make_Component_Definition (Loc,
7458 Subtype_Indication =>
7459 New_Reference_To (RTE (RE_Prim_Ptr), Loc)))));
17e14451 7460
dffd0a90 7461 Append_To (Result,
7462 Make_Full_Type_Declaration (Loc,
7463 Defining_Identifier => DT_Prims_Acc,
7464 Type_Definition =>
7465 Make_Access_To_Object_Definition (Loc,
7466 Subtype_Indication =>
7467 New_Occurrence_Of (DT_Prims, Loc))));
17e14451 7468
dffd0a90 7469 Append_Elmt (DT_Prims_Acc, Access_Disp_Table (Typ));
17e14451 7470
dffd0a90 7471 -- Analyze the resulting list and suppress the generation of the
7472 -- Init_Proc associated with the above array declaration because
7473 -- this type is never used in object declarations. It is only used
7474 -- to simplify the expansion associated with dispatching calls.
17e14451 7475
dffd0a90 7476 Analyze_List (Result);
649455a4 7477 Set_Suppress_Initialization (Base_Type (DT_Prims));
cc60bd16 7478
ff6293ec 7479 -- Disable backend optimizations based on assumptions about the
7480 -- aliasing status of objects designated by the access to the
7481 -- dispatch table. Required to handle dispatch tables imported
7482 -- from C++.
7483
7484 Set_No_Strict_Aliasing (Base_Type (DT_Prims_Acc));
7485
d00681a7 7486 -- Add the freezing nodes of these declarations; required to avoid
7487 -- generating these freezing nodes in wrong scopes (for example in
7488 -- the IC routine of a derivation of Typ).
d03ada96 7489 -- What is an "IC routine"? Is "init_proc" meant here???
d00681a7 7490
d74fc39a 7491 Append_List_To (Result, Freeze_Entity (DT_Prims, Typ));
7492 Append_List_To (Result, Freeze_Entity (DT_Prims_Acc, Typ));
d00681a7 7493
dffd0a90 7494 -- Mark entity of dispatch table. Required by the back end to
7495 -- handle them properly.
cc60bd16 7496
dffd0a90 7497 Set_Is_Dispatch_Table_Entity (DT_Prims);
7498 end;
7499 end if;
17e14451 7500
11bd2f46 7501 -- Mark entities of dispatch table. Required by the back end to handle
7502 -- them properly.
7640ed3d 7503
7504 if Present (DT) then
7505 Set_Is_Dispatch_Table_Entity (DT);
7506 Set_Is_Dispatch_Table_Entity (Etype (DT));
7507 end if;
7508
d04be62f 7509 if Present (Iface_DT) then
7510 Set_Is_Dispatch_Table_Entity (Iface_DT);
7511 Set_Is_Dispatch_Table_Entity (Etype (Iface_DT));
7512 end if;
7513
d00681a7 7514 if Is_CPP_Class (Root_Type (Typ)) then
7515 Set_Ekind (DT_Ptr, E_Variable);
7516 else
7517 Set_Ekind (DT_Ptr, E_Constant);
7518 end if;
7519
cdb1c38f 7520 Set_Is_Tag (DT_Ptr);
7521 Set_Related_Type (DT_Ptr, Typ);
7522
17e14451 7523 return Result;
7524 end Make_Tags;
7525
cd534f03 7526 ---------------
7527 -- New_Value --
7528 ---------------
7529
7530 function New_Value (From : Node_Id) return Node_Id is
7531 Res : constant Node_Id := Duplicate_Subexpr (From);
7532 begin
7533 if Is_Access_Type (Etype (From)) then
9af28f61 7534 return
7535 Make_Explicit_Dereference (Sloc (From),
7536 Prefix => Res);
cd534f03 7537 else
7538 return Res;
7539 end if;
7540 end New_Value;
7541
ee6ba406 7542 -----------------------------------
7543 -- Original_View_In_Visible_Part --
7544 -----------------------------------
7545
7546 function Original_View_In_Visible_Part (Typ : Entity_Id) return Boolean is
7547 Scop : constant Entity_Id := Scope (Typ);
7548
7549 begin
7550 -- The scope must be a package
7551
65149aa0 7552 if not Is_Package_Or_Generic_Package (Scop) then
ee6ba406 7553 return False;
7554 end if;
7555
7556 -- A type with a private declaration has a private view declared in
7557 -- the visible part.
7558
7559 if Has_Private_Declaration (Typ) then
7560 return True;
7561 end if;
7562
7563 return List_Containing (Parent (Typ)) =
7564 Visible_Declarations (Specification (Unit_Declaration_Node (Scop)));
7565 end Original_View_In_Visible_Part;
7566
d62940bf 7567 ------------------
7568 -- Prim_Op_Kind --
7569 ------------------
7570
7571 function Prim_Op_Kind
7572 (Prim : Entity_Id;
7573 Typ : Entity_Id) return Node_Id
7574 is
7575 Full_Typ : Entity_Id := Typ;
7576 Loc : constant Source_Ptr := Sloc (Prim);
68f95949 7577 Prim_Op : Entity_Id;
d62940bf 7578
7579 begin
7580 -- Retrieve the original primitive operation
7581
fc2907f6 7582 Prim_Op := Ultimate_Alias (Prim);
d62940bf 7583
7584 if Ekind (Typ) = E_Record_Type
7585 and then Present (Corresponding_Concurrent_Type (Typ))
7586 then
7587 Full_Typ := Corresponding_Concurrent_Type (Typ);
7588 end if;
7589
d77e048b 7590 -- When a private tagged type is completed by a concurrent type,
7591 -- retrieve the full view.
7592
7593 if Is_Private_Type (Full_Typ) then
7594 Full_Typ := Full_View (Full_Typ);
7595 end if;
7596
d62940bf 7597 if Ekind (Prim_Op) = E_Function then
7598
7599 -- Protected function
7600
7601 if Ekind (Full_Typ) = E_Protected_Type then
7602 return New_Reference_To (RTE (RE_POK_Protected_Function), Loc);
7603
76a1c25b 7604 -- Task function
7605
7606 elsif Ekind (Full_Typ) = E_Task_Type then
7607 return New_Reference_To (RTE (RE_POK_Task_Function), Loc);
7608
d62940bf 7609 -- Regular function
7610
7611 else
7612 return New_Reference_To (RTE (RE_POK_Function), Loc);
7613 end if;
7614
7615 else
7616 pragma Assert (Ekind (Prim_Op) = E_Procedure);
7617
7618 if Ekind (Full_Typ) = E_Protected_Type then
7619
7620 -- Protected entry
7621
7622 if Is_Primitive_Wrapper (Prim_Op)
7623 and then Ekind (Wrapped_Entity (Prim_Op)) = E_Entry
7624 then
7625 return New_Reference_To (RTE (RE_POK_Protected_Entry), Loc);
7626
7627 -- Protected procedure
7628
7629 else
7630 return New_Reference_To (RTE (RE_POK_Protected_Procedure), Loc);
7631 end if;
7632
7633 elsif Ekind (Full_Typ) = E_Task_Type then
7634
7635 -- Task entry
7636
7637 if Is_Primitive_Wrapper (Prim_Op)
7638 and then Ekind (Wrapped_Entity (Prim_Op)) = E_Entry
7639 then
7640 return New_Reference_To (RTE (RE_POK_Task_Entry), Loc);
7641
7642 -- Task "procedure". These are the internally Expander-generated
7643 -- procedures (task body for instance).
7644
7645 else
7646 return New_Reference_To (RTE (RE_POK_Task_Procedure), Loc);
7647 end if;
7648
7649 -- Regular procedure
7650
7651 else
7652 return New_Reference_To (RTE (RE_POK_Procedure), Loc);
7653 end if;
7654 end if;
7655 end Prim_Op_Kind;
7656
725a69d2 7657 ------------------------
7658 -- Register_Primitive --
7659 ------------------------
7660
49260fa5 7661 function Register_Primitive
725a69d2 7662 (Loc : Source_Ptr;
49260fa5 7663 Prim : Entity_Id) return List_Id
725a69d2 7664 is
cdb1c38f 7665 DT_Ptr : Entity_Id;
7666 Iface_Prim : Entity_Id;
7667 Iface_Typ : Entity_Id;
7668 Iface_DT_Ptr : Entity_Id;
7669 Iface_DT_Elmt : Elmt_Id;
49260fa5 7670 L : constant List_Id := New_List;
cdb1c38f 7671 Pos : Uint;
7672 Tag : Entity_Id;
cc60bd16 7673 Tag_Typ : Entity_Id;
cdb1c38f 7674 Thunk_Id : Entity_Id;
7675 Thunk_Code : Node_Id;
725a69d2 7676
7677 begin
7678 pragma Assert (not Restriction_Active (No_Dispatching_Calls));
79500ea0 7679 pragma Assert (VM_Target = No_VM);
725a69d2 7680
3f8cf2d2 7681 -- Do not register in the dispatch table eliminated primitives
7682
7683 if not RTE_Available (RE_Tag)
7684 or else Is_Eliminated (Ultimate_Alias (Prim))
7685 then
49260fa5 7686 return L;
725a69d2 7687 end if;
7688
a652dd51 7689 if not Present (Interface_Alias (Prim)) then
cc60bd16 7690 Tag_Typ := Scope (DTC_Entity (Prim));
acf97c11 7691 Pos := DT_Position (Prim);
cc60bd16 7692 Tag := First_Tag_Component (Tag_Typ);
725a69d2 7693
7694 if Is_Predefined_Dispatching_Operation (Prim)
7695 or else Is_Predefined_Dispatching_Alias (Prim)
7696 then
cc60bd16 7697 DT_Ptr :=
7698 Node (Next_Elmt (First_Elmt (Access_Disp_Table (Tag_Typ))));
7699
49260fa5 7700 Append_To (L,
725a69d2 7701 Build_Set_Predefined_Prim_Op_Address (Loc,
7702 Tag_Node => New_Reference_To (DT_Ptr, Loc),
7703 Position => Pos,
acf97c11 7704 Address_Node =>
cc60bd16 7705 Unchecked_Convert_To (RTE (RE_Prim_Ptr),
acf97c11 7706 Make_Attribute_Reference (Loc,
4055a532 7707 Prefix => New_Reference_To (Prim, Loc),
acf97c11 7708 Attribute_Name => Name_Unrestricted_Access))));
725a69d2 7709
9e7de1e1 7710 -- Register copy of the pointer to the 'size primitive in the TSD
cc60bd16 7711
7712 if Chars (Prim) = Name_uSize
7713 and then RTE_Record_Component_Available (RE_Size_Func)
7714 then
7715 DT_Ptr := Node (First_Elmt (Access_Disp_Table (Tag_Typ)));
49260fa5 7716 Append_To (L,
cc60bd16 7717 Build_Set_Size_Function (Loc,
7718 Tag_Node => New_Reference_To (DT_Ptr, Loc),
7719 Size_Func => Prim));
7720 end if;
7721
725a69d2 7722 else
7723 pragma Assert (Pos /= Uint_0 and then Pos <= DT_Entry_Count (Tag));
7724
d00681a7 7725 -- Skip registration of primitives located in the C++ part of the
7726 -- dispatch table. Their slot is set by the IC routine.
7727
7728 if not Is_CPP_Class (Root_Type (Tag_Typ))
7729 or else Pos > CPP_Num_Prims (Tag_Typ)
7730 then
7731 DT_Ptr := Node (First_Elmt (Access_Disp_Table (Tag_Typ)));
7732 Append_To (L,
7733 Build_Set_Prim_Op_Address (Loc,
7734 Typ => Tag_Typ,
7735 Tag_Node => New_Reference_To (DT_Ptr, Loc),
7736 Position => Pos,
7737 Address_Node =>
7738 Unchecked_Convert_To (RTE (RE_Prim_Ptr),
7739 Make_Attribute_Reference (Loc,
4055a532 7740 Prefix => New_Reference_To (Prim, Loc),
d00681a7 7741 Attribute_Name => Name_Unrestricted_Access))));
7742 end if;
725a69d2 7743 end if;
7744
7745 -- Ada 2005 (AI-251): Primitive associated with an interface type
7746 -- Generate the code of the thunk only if the interface type is not an
7747 -- immediate ancestor of Typ; otherwise the dispatch table associated
7748 -- with the interface is the primary dispatch table and we have nothing
7749 -- else to do here.
7750
7751 else
cc60bd16 7752 Tag_Typ := Find_Dispatching_Type (Alias (Prim));
a652dd51 7753 Iface_Typ := Find_Dispatching_Type (Interface_Alias (Prim));
725a69d2 7754
7755 pragma Assert (Is_Interface (Iface_Typ));
7756
c8da6114 7757 -- No action needed for interfaces that are ancestors of Typ because
7758 -- their primitives are located in the primary dispatch table.
7759
cb4af01d 7760 if Is_Ancestor (Iface_Typ, Tag_Typ, Use_Full_View => True) then
c8da6114 7761 return L;
d00681a7 7762
7763 -- No action needed for primitives located in the C++ part of the
7764 -- dispatch table. Their slot is set by the IC routine.
7765
7766 elsif Is_CPP_Class (Root_Type (Tag_Typ))
7767 and then DT_Position (Alias (Prim)) <= CPP_Num_Prims (Tag_Typ)
7768 and then not Is_Predefined_Dispatching_Operation (Prim)
7769 and then not Is_Predefined_Dispatching_Alias (Prim)
7770 then
7771 return L;
c8da6114 7772 end if;
7773
17e14451 7774 Expand_Interface_Thunk (Prim, Thunk_Id, Thunk_Code);
725a69d2 7775
cb4af01d 7776 if not Is_Ancestor (Iface_Typ, Tag_Typ, Use_Full_View => True)
725a69d2 7777 and then Present (Thunk_Code)
7778 then
725a69d2 7779 -- Generate the code necessary to fill the appropriate entry of
7780 -- the secondary dispatch table of Prim's controlling type with
7781 -- Thunk_Id's address.
7782
cc60bd16 7783 Iface_DT_Elmt := Find_Interface_ADT (Tag_Typ, Iface_Typ);
cdb1c38f 7784 Iface_DT_Ptr := Node (Iface_DT_Elmt);
7785 pragma Assert (Has_Thunks (Iface_DT_Ptr));
7786
a652dd51 7787 Iface_Prim := Interface_Alias (Prim);
acf97c11 7788 Pos := DT_Position (Iface_Prim);
7789 Tag := First_Tag_Component (Iface_Typ);
49260fa5 7790
7791 Prepend_To (L, Thunk_Code);
725a69d2 7792
7793 if Is_Predefined_Dispatching_Operation (Prim)
7794 or else Is_Predefined_Dispatching_Alias (Prim)
7795 then
cdb1c38f 7796 Append_To (L,
725a69d2 7797 Build_Set_Predefined_Prim_Op_Address (Loc,
acf97c11 7798 Tag_Node =>
7799 New_Reference_To (Node (Next_Elmt (Iface_DT_Elmt)), Loc),
725a69d2 7800 Position => Pos,
7801 Address_Node =>
cc60bd16 7802 Unchecked_Convert_To (RTE (RE_Prim_Ptr),
acf97c11 7803 Make_Attribute_Reference (Loc,
7804 Prefix => New_Reference_To (Thunk_Id, Loc),
7805 Attribute_Name => Name_Unrestricted_Access))));
cdb1c38f 7806
acf97c11 7807 Next_Elmt (Iface_DT_Elmt);
cdb1c38f 7808 Next_Elmt (Iface_DT_Elmt);
7809 Iface_DT_Ptr := Node (Iface_DT_Elmt);
7810 pragma Assert (not Has_Thunks (Iface_DT_Ptr));
7811
7812 Append_To (L,
7813 Build_Set_Predefined_Prim_Op_Address (Loc,
acf97c11 7814 Tag_Node =>
7815 New_Reference_To (Node (Next_Elmt (Iface_DT_Elmt)), Loc),
cdb1c38f 7816 Position => Pos,
7817 Address_Node =>
cc60bd16 7818 Unchecked_Convert_To (RTE (RE_Prim_Ptr),
acf97c11 7819 Make_Attribute_Reference (Loc,
4055a532 7820 Prefix =>
7821 New_Reference_To (Alias (Prim), Loc),
acf97c11 7822 Attribute_Name => Name_Unrestricted_Access))));
cdb1c38f 7823
725a69d2 7824 else
7825 pragma Assert (Pos /= Uint_0
7826 and then Pos <= DT_Entry_Count (Tag));
7827
cdb1c38f 7828 Append_To (L,
7829 Build_Set_Prim_Op_Address (Loc,
7830 Typ => Iface_Typ,
7831 Tag_Node => New_Reference_To (Iface_DT_Ptr, Loc),
7832 Position => Pos,
acf97c11 7833 Address_Node =>
cc60bd16 7834 Unchecked_Convert_To (RTE (RE_Prim_Ptr),
acf97c11 7835 Make_Attribute_Reference (Loc,
7836 Prefix => New_Reference_To (Thunk_Id, Loc),
7837 Attribute_Name => Name_Unrestricted_Access))));
cdb1c38f 7838
acf97c11 7839 Next_Elmt (Iface_DT_Elmt);
cdb1c38f 7840 Next_Elmt (Iface_DT_Elmt);
7841 Iface_DT_Ptr := Node (Iface_DT_Elmt);
7842 pragma Assert (not Has_Thunks (Iface_DT_Ptr));
7843
7844 Append_To (L,
725a69d2 7845 Build_Set_Prim_Op_Address (Loc,
7846 Typ => Iface_Typ,
7847 Tag_Node => New_Reference_To (Iface_DT_Ptr, Loc),
7848 Position => Pos,
acf97c11 7849 Address_Node =>
cc60bd16 7850 Unchecked_Convert_To (RTE (RE_Prim_Ptr),
acf97c11 7851 Make_Attribute_Reference (Loc,
4055a532 7852 Prefix =>
7853 New_Reference_To (Alias (Prim), Loc),
acf97c11 7854 Attribute_Name => Name_Unrestricted_Access))));
cdb1c38f 7855
725a69d2 7856 end if;
7857 end if;
7858 end if;
49260fa5 7859
7860 return L;
725a69d2 7861 end Register_Primitive;
7862
ee6ba406 7863 -------------------------
7864 -- Set_All_DT_Position --
7865 -------------------------
7866
7867 procedure Set_All_DT_Position (Typ : Entity_Id) is
ee6ba406 7868
cf365b48 7869 function In_Predef_Prims_DT (Prim : Entity_Id) return Boolean;
7870 -- Returns True if Prim is located in the dispatch table of
7871 -- predefined primitives
7872
aad6babd 7873 procedure Validate_Position (Prim : Entity_Id);
36b938a3 7874 -- Check that the position assigned to Prim is completely safe
aad6babd 7875 -- (it has not been assigned to a previously defined primitive
7876 -- operation of Typ)
7877
cf365b48 7878 ------------------------
7879 -- In_Predef_Prims_DT --
7880 ------------------------
7881
7882 function In_Predef_Prims_DT (Prim : Entity_Id) return Boolean is
7883 E : Entity_Id;
7884
7885 begin
7886 -- Predefined primitives
7887
7888 if Is_Predefined_Dispatching_Operation (Prim) then
7889 return True;
7890
7891 -- Renamings of predefined primitives
7892
7893 elsif Present (Alias (Prim))
7894 and then Is_Predefined_Dispatching_Operation (Ultimate_Alias (Prim))
7895 then
7896 if Chars (Ultimate_Alias (Prim)) /= Name_Op_Eq then
7897 return True;
7898
7899 -- User-defined renamings of predefined equality have their own
7900 -- slot in the primary dispatch table
7901
7902 else
7903 E := Prim;
7904 while Present (Alias (E)) loop
7905 if Comes_From_Source (E) then
7906 return False;
7907 end if;
7908
7909 E := Alias (E);
7910 end loop;
7911
7912 return not Comes_From_Source (E);
7913 end if;
7914
7915 -- User-defined primitives
7916
7917 else
7918 return False;
7919 end if;
7920 end In_Predef_Prims_DT;
7921
aad6babd 7922 -----------------------
7923 -- Validate_Position --
7924 -----------------------
7925
7926 procedure Validate_Position (Prim : Entity_Id) is
af647dc7 7927 Op_Elmt : Elmt_Id;
7928 Op : Entity_Id;
d62940bf 7929
aad6babd 7930 begin
af647dc7 7931 -- Aliased primitives are safe
7932
7933 if Present (Alias (Prim)) then
7934 return;
7935 end if;
7936
7937 Op_Elmt := First_Elmt (Primitive_Operations (Typ));
7938 while Present (Op_Elmt) loop
7939 Op := Node (Op_Elmt);
7940
7941 -- No need to check against itself
7942
7943 if Op = Prim then
7944 null;
7945
aad6babd 7946 -- Primitive operations covering abstract interfaces are
7947 -- allocated later
7948
a652dd51 7949 elsif Present (Interface_Alias (Op)) then
aad6babd 7950 null;
7951
68f95949 7952 -- Predefined dispatching operations are completely safe. They
7953 -- are allocated at fixed positions in a separate table.
aad6babd 7954
af647dc7 7955 elsif Is_Predefined_Dispatching_Operation (Op)
7956 or else Is_Predefined_Dispatching_Alias (Op)
7957 then
aad6babd 7958 null;
ee6ba406 7959
aad6babd 7960 -- Aliased subprograms are safe
7961
af647dc7 7962 elsif Present (Alias (Op)) then
aad6babd 7963 null;
7964
af647dc7 7965 elsif DT_Position (Op) = DT_Position (Prim)
7966 and then not Is_Predefined_Dispatching_Operation (Op)
7967 and then not Is_Predefined_Dispatching_Operation (Prim)
7968 and then not Is_Predefined_Dispatching_Alias (Op)
7969 and then not Is_Predefined_Dispatching_Alias (Prim)
7970 then
d62940bf 7971
7972 -- Handle aliased subprograms
7973
7974 declare
7975 Op_1 : Entity_Id;
7976 Op_2 : Entity_Id;
7977
7978 begin
af647dc7 7979 Op_1 := Op;
d62940bf 7980 loop
7981 if Present (Overridden_Operation (Op_1)) then
7982 Op_1 := Overridden_Operation (Op_1);
7983 elsif Present (Alias (Op_1)) then
7984 Op_1 := Alias (Op_1);
7985 else
7986 exit;
7987 end if;
7988 end loop;
7989
7990 Op_2 := Prim;
7991 loop
7992 if Present (Overridden_Operation (Op_2)) then
7993 Op_2 := Overridden_Operation (Op_2);
7994 elsif Present (Alias (Op_2)) then
7995 Op_2 := Alias (Op_2);
7996 else
7997 exit;
7998 end if;
7999 end loop;
8000
8001 if Op_1 /= Op_2 then
8002 raise Program_Error;
8003 end if;
8004 end;
aad6babd 8005 end if;
8006
af647dc7 8007 Next_Elmt (Op_Elmt);
aad6babd 8008 end loop;
8009 end Validate_Position;
8010
af647dc7 8011 -- Local variables
8012
8013 Parent_Typ : constant Entity_Id := Etype (Typ);
af647dc7 8014 First_Prim : constant Elmt_Id := First_Elmt (Primitive_Operations (Typ));
8015 The_Tag : constant Entity_Id := First_Tag_Component (Typ);
8016
651a38ec 8017 Adjusted : Boolean := False;
8018 Finalized : Boolean := False;
af647dc7 8019
343d35dc 8020 Count_Prim : Nat;
8021 DT_Length : Nat;
8022 Nb_Prim : Nat;
af647dc7 8023 Prim : Entity_Id;
8024 Prim_Elmt : Elmt_Id;
8025
aad6babd 8026 -- Start of processing for Set_All_DT_Position
8027
8028 begin
a652dd51 8029 pragma Assert (Present (First_Tag_Component (Typ)));
8030
b3dd22b3 8031 -- Set the DT_Position for each primitive operation. Perform some sanity
8032 -- checks to avoid building inconsistent dispatch tables.
ee6ba406 8033
b3dd22b3 8034 -- First stage: Set the DTC entity of all the primitive operations. This
8035 -- is required to properly read the DT_Position attribute in the latter
8036 -- stages.
ee6ba406 8037
343d35dc 8038 Prim_Elmt := First_Prim;
8039 Count_Prim := 0;
8040 while Present (Prim_Elmt) loop
8041 Prim := Node (Prim_Elmt);
ee6ba406 8042
343d35dc 8043 -- Predefined primitives have a separate dispatch table
ee6ba406 8044
cf365b48 8045 if not In_Predef_Prims_DT (Prim) then
343d35dc 8046 Count_Prim := Count_Prim + 1;
8047 end if;
ee6ba406 8048
725a69d2 8049 Set_DTC_Entity_Value (Typ, Prim);
ee6ba406 8050
343d35dc 8051 -- Clear any previous value of the DT_Position attribute. In this
8052 -- way we ensure that the final position of all the primitives is
36b938a3 8053 -- established by the following stages of this algorithm.
ee6ba406 8054
343d35dc 8055 Set_DT_Position (Prim, No_Uint);
ee6ba406 8056
343d35dc 8057 Next_Elmt (Prim_Elmt);
8058 end loop;
ee6ba406 8059
343d35dc 8060 declare
acf97c11 8061 Fixed_Prim : array (Int range 0 .. Count_Prim) of Boolean :=
8062 (others => False);
8063
343d35dc 8064 E : Entity_Id;
ee6ba406 8065
725a69d2 8066 procedure Handle_Inherited_Private_Subprograms (Typ : Entity_Id);
8067 -- Called if Typ is declared in a nested package or a public child
8068 -- package to handle inherited primitives that were inherited by Typ
8069 -- in the visible part, but whose declaration was deferred because
8070 -- the parent operation was private and not visible at that point.
8071
343d35dc 8072 procedure Set_Fixed_Prim (Pos : Nat);
8073 -- Sets to true an element of the Fixed_Prim table to indicate
8074 -- that this entry of the dispatch table of Typ is occupied.
ee6ba406 8075
725a69d2 8076 ------------------------------------------
8077 -- Handle_Inherited_Private_Subprograms --
8078 ------------------------------------------
8079
8080 procedure Handle_Inherited_Private_Subprograms (Typ : Entity_Id) is
8081 Op_List : Elist_Id;
8082 Op_Elmt : Elmt_Id;
8083 Op_Elmt_2 : Elmt_Id;
8084 Prim_Op : Entity_Id;
8085 Parent_Subp : Entity_Id;
8086
8087 begin
8088 Op_List := Primitive_Operations (Typ);
8089
8090 Op_Elmt := First_Elmt (Op_List);
8091 while Present (Op_Elmt) loop
8092 Prim_Op := Node (Op_Elmt);
8093
8094 -- Search primitives that are implicit operations with an
8095 -- internal name whose parent operation has a normal name.
8096
8097 if Present (Alias (Prim_Op))
8098 and then Find_Dispatching_Type (Alias (Prim_Op)) /= Typ
8099 and then not Comes_From_Source (Prim_Op)
8100 and then Is_Internal_Name (Chars (Prim_Op))
8101 and then not Is_Internal_Name (Chars (Alias (Prim_Op)))
8102 then
8103 Parent_Subp := Alias (Prim_Op);
8104
8105 -- Check if the type has an explicit overriding for this
8106 -- primitive.
8107
8108 Op_Elmt_2 := Next_Elmt (Op_Elmt);
8109 while Present (Op_Elmt_2) loop
8110 if Chars (Node (Op_Elmt_2)) = Chars (Parent_Subp)
8111 and then Type_Conformant (Prim_Op, Node (Op_Elmt_2))
8112 then
8113 Set_DT_Position (Prim_Op, DT_Position (Parent_Subp));
8114 Set_DT_Position (Node (Op_Elmt_2),
8115 DT_Position (Parent_Subp));
8116 Set_Fixed_Prim (UI_To_Int (DT_Position (Prim_Op)));
8117
8118 goto Next_Primitive;
8119 end if;
8120
8121 Next_Elmt (Op_Elmt_2);
8122 end loop;
8123 end if;
8124
8125 <<Next_Primitive>>
8126 Next_Elmt (Op_Elmt);
8127 end loop;
8128 end Handle_Inherited_Private_Subprograms;
8129
343d35dc 8130 --------------------
8131 -- Set_Fixed_Prim --
8132 --------------------
ee6ba406 8133
343d35dc 8134 procedure Set_Fixed_Prim (Pos : Nat) is
ee6ba406 8135 begin
9e7de1e1 8136 pragma Assert (Pos <= Count_Prim);
343d35dc 8137 Fixed_Prim (Pos) := True;
8138 exception
8139 when Constraint_Error =>
8140 raise Program_Error;
8141 end Set_Fixed_Prim;
ee6ba406 8142
343d35dc 8143 begin
725a69d2 8144 -- In case of nested packages and public child package it may be
8145 -- necessary a special management on inherited subprograms so that
8146 -- the dispatch table is properly filled.
8147
8148 if Ekind (Scope (Scope (Typ))) = E_Package
8149 and then Scope (Scope (Typ)) /= Standard_Standard
8150 and then ((Is_Derived_Type (Typ) and then not Is_Private_Type (Typ))
8151 or else
8152 (Nkind (Parent (Typ)) = N_Private_Extension_Declaration
8153 and then Is_Generic_Type (Typ)))
8154 and then In_Open_Scopes (Scope (Etype (Typ)))
5b990e08 8155 and then Is_Base_Type (Typ)
725a69d2 8156 then
8157 Handle_Inherited_Private_Subprograms (Typ);
8158 end if;
8159
343d35dc 8160 -- Second stage: Register fixed entries
ee6ba406 8161
343d35dc 8162 Nb_Prim := 0;
8163 Prim_Elmt := First_Prim;
8164 while Present (Prim_Elmt) loop
8165 Prim := Node (Prim_Elmt);
ee6ba406 8166
343d35dc 8167 -- Predefined primitives have a separate table and all its
8168 -- entries are at predefined fixed positions.
ee6ba406 8169
cf365b48 8170 if In_Predef_Prims_DT (Prim) then
8171 if Is_Predefined_Dispatching_Operation (Prim) then
8172 Set_DT_Position (Prim, Default_Prim_Op_Position (Prim));
ee6ba406 8173
cf365b48 8174 else pragma Assert (Present (Alias (Prim)));
8175 Set_DT_Position (Prim,
8176 Default_Prim_Op_Position (Ultimate_Alias (Prim)));
8177 end if;
d62940bf 8178
343d35dc 8179 -- Overriding primitives of ancestor abstract interfaces
ee6ba406 8180
a652dd51 8181 elsif Present (Interface_Alias (Prim))
8182 and then Is_Ancestor
cb4af01d 8183 (Find_Dispatching_Type (Interface_Alias (Prim)), Typ,
8184 Use_Full_View => True)
343d35dc 8185 then
8186 pragma Assert (DT_Position (Prim) = No_Uint
a652dd51 8187 and then Present (DTC_Entity (Interface_Alias (Prim))));
ee6ba406 8188
a652dd51 8189 E := Interface_Alias (Prim);
343d35dc 8190 Set_DT_Position (Prim, DT_Position (E));
aad6babd 8191
343d35dc 8192 pragma Assert
8193 (DT_Position (Alias (Prim)) = No_Uint
8194 or else DT_Position (Alias (Prim)) = DT_Position (E));
8195 Set_DT_Position (Alias (Prim), DT_Position (E));
8196 Set_Fixed_Prim (UI_To_Int (DT_Position (Prim)));
af647dc7 8197
343d35dc 8198 -- Overriding primitives must use the same entry as the
36b938a3 8199 -- overridden primitive.
af647dc7 8200
a652dd51 8201 elsif not Present (Interface_Alias (Prim))
343d35dc 8202 and then Present (Alias (Prim))
17e14451 8203 and then Chars (Prim) = Chars (Alias (Prim))
343d35dc 8204 and then Find_Dispatching_Type (Alias (Prim)) /= Typ
a652dd51 8205 and then Is_Ancestor
cb4af01d 8206 (Find_Dispatching_Type (Alias (Prim)), Typ,
8207 Use_Full_View => True)
343d35dc 8208 and then Present (DTC_Entity (Alias (Prim)))
af647dc7 8209 then
343d35dc 8210 E := Alias (Prim);
8211 Set_DT_Position (Prim, DT_Position (E));
aad6babd 8212
343d35dc 8213 if not Is_Predefined_Dispatching_Alias (E) then
8214 Set_Fixed_Prim (UI_To_Int (DT_Position (E)));
8215 end if;
9dfe12ae 8216 end if;
ee6ba406 8217
aad6babd 8218 Next_Elmt (Prim_Elmt);
8219 end loop;
8220
b381b314 8221 -- Third stage: Fix the position of all the new primitives.
343d35dc 8222 -- Entries associated with primitives covering interfaces
8223 -- are handled in a latter round.
aad6babd 8224
343d35dc 8225 Prim_Elmt := First_Prim;
8226 while Present (Prim_Elmt) loop
8227 Prim := Node (Prim_Elmt);
aad6babd 8228
343d35dc 8229 -- Skip primitives previously set entries
aad6babd 8230
343d35dc 8231 if DT_Position (Prim) /= No_Uint then
8232 null;
aad6babd 8233
343d35dc 8234 -- Primitives covering interface primitives are handled later
aad6babd 8235
a652dd51 8236 elsif Present (Interface_Alias (Prim)) then
343d35dc 8237 null;
aad6babd 8238
343d35dc 8239 else
8240 -- Take the next available position in the DT
aad6babd 8241
343d35dc 8242 loop
8243 Nb_Prim := Nb_Prim + 1;
8244 pragma Assert (Nb_Prim <= Count_Prim);
8245 exit when not Fixed_Prim (Nb_Prim);
8246 end loop;
aad6babd 8247
343d35dc 8248 Set_DT_Position (Prim, UI_From_Int (Nb_Prim));
8249 Set_Fixed_Prim (Nb_Prim);
8250 end if;
aad6babd 8251
343d35dc 8252 Next_Elmt (Prim_Elmt);
8253 end loop;
8254 end;
aad6babd 8255
343d35dc 8256 -- Fourth stage: Complete the decoration of primitives covering
8257 -- interfaces (that is, propagate the DT_Position attribute
8258 -- from the aliased primitive)
aad6babd 8259
343d35dc 8260 Prim_Elmt := First_Prim;
8261 while Present (Prim_Elmt) loop
8262 Prim := Node (Prim_Elmt);
aad6babd 8263
343d35dc 8264 if DT_Position (Prim) = No_Uint
a652dd51 8265 and then Present (Interface_Alias (Prim))
343d35dc 8266 then
8267 pragma Assert (Present (Alias (Prim))
8268 and then Find_Dispatching_Type (Alias (Prim)) = Typ);
aad6babd 8269
343d35dc 8270 -- Check if this entry will be placed in the primary DT
aad6babd 8271
a652dd51 8272 if Is_Ancestor
cb4af01d 8273 (Find_Dispatching_Type (Interface_Alias (Prim)), Typ,
8274 Use_Full_View => True)
ee6ba406 8275 then
343d35dc 8276 pragma Assert (DT_Position (Alias (Prim)) /= No_Uint);
8277 Set_DT_Position (Prim, DT_Position (Alias (Prim)));
aad6babd 8278
343d35dc 8279 -- Otherwise it will be placed in the secondary DT
aad6babd 8280
343d35dc 8281 else
8282 pragma Assert
a652dd51 8283 (DT_Position (Interface_Alias (Prim)) /= No_Uint);
343d35dc 8284 Set_DT_Position (Prim,
a652dd51 8285 DT_Position (Interface_Alias (Prim)));
aad6babd 8286 end if;
343d35dc 8287 end if;
aad6babd 8288
343d35dc 8289 Next_Elmt (Prim_Elmt);
8290 end loop;
d62940bf 8291
343d35dc 8292 -- Generate listing showing the contents of the dispatch tables.
8293 -- This action is done before some further static checks because
8294 -- in case of critical errors caused by a wrong dispatch table
8295 -- we need to see the contents of such table.
d62940bf 8296
343d35dc 8297 if Debug_Flag_ZZ then
8298 Write_DT (Typ);
8299 end if;
aad6babd 8300
343d35dc 8301 -- Final stage: Ensure that the table is correct plus some further
8302 -- verifications concerning the primitives.
aad6babd 8303
343d35dc 8304 Prim_Elmt := First_Prim;
8305 DT_Length := 0;
8306 while Present (Prim_Elmt) loop
8307 Prim := Node (Prim_Elmt);
aad6babd 8308
343d35dc 8309 -- At this point all the primitives MUST have a position
acf97c11 8310 -- in the dispatch table.
aad6babd 8311
343d35dc 8312 if DT_Position (Prim) = No_Uint then
8313 raise Program_Error;
8314 end if;
aad6babd 8315
343d35dc 8316 -- Calculate real size of the dispatch table
aad6babd 8317
cf365b48 8318 if not In_Predef_Prims_DT (Prim)
343d35dc 8319 and then UI_To_Int (DT_Position (Prim)) > DT_Length
8320 then
8321 DT_Length := UI_To_Int (DT_Position (Prim));
8322 end if;
aad6babd 8323
36b938a3 8324 -- Ensure that the assigned position to non-predefined
343d35dc 8325 -- dispatching operations in the dispatch table is correct.
aad6babd 8326
cf365b48 8327 if not Is_Predefined_Dispatching_Operation (Prim)
8328 and then not Is_Predefined_Dispatching_Alias (Prim)
343d35dc 8329 then
8330 Validate_Position (Prim);
8331 end if;
ee6ba406 8332
343d35dc 8333 if Chars (Prim) = Name_Finalize then
8334 Finalized := True;
8335 end if;
ee6ba406 8336
343d35dc 8337 if Chars (Prim) = Name_Adjust then
8338 Adjusted := True;
8339 end if;
af647dc7 8340
503f7fd3 8341 -- An abstract operation cannot be declared in the private part for a
8342 -- visible abstract type, because it can't be overridden outside this
8343 -- package hierarchy. For explicit declarations this is checked at
8344 -- the point of declaration, but for inherited operations it must be
8345 -- done when building the dispatch table.
343d35dc 8346
a652dd51 8347 -- Ada 2005 (AI-251): Primitives associated with interfaces are
8348 -- excluded from this check because interfaces must be visible in
8349 -- the public and private part (RM 7.3 (7.3/2))
343d35dc 8350
6fb3c314 8351 -- We disable this check in CodePeer mode, to accommodate legacy
6da4d289 8352 -- Ada code.
8353
8354 if not CodePeer_Mode
8355 and then Is_Abstract_Type (Typ)
343d35dc 8356 and then Is_Abstract_Subprogram (Prim)
8357 and then Present (Alias (Prim))
a652dd51 8358 and then not Is_Interface
8359 (Find_Dispatching_Type (Ultimate_Alias (Prim)))
8360 and then not Present (Interface_Alias (Prim))
343d35dc 8361 and then Is_Derived_Type (Typ)
8362 and then In_Private_Part (Current_Scope)
8363 and then
8364 List_Containing (Parent (Prim)) =
8365 Private_Declarations
8366 (Specification (Unit_Declaration_Node (Current_Scope)))
8367 and then Original_View_In_Visible_Part (Typ)
8368 then
8369 -- We exclude Input and Output stream operations because
8370 -- Limited_Controlled inherits useless Input and Output
8371 -- stream operations from Root_Controlled, which can
8372 -- never be overridden.
ee6ba406 8373
343d35dc 8374 if not Is_TSS (Prim, TSS_Stream_Input)
8375 and then
8376 not Is_TSS (Prim, TSS_Stream_Output)
ee6ba406 8377 then
503f7fd3 8378 Error_Msg_NE
343d35dc 8379 ("abstract inherited private operation&" &
17e14451 8380 " must be overridden (RM 3.9.3(10))",
343d35dc 8381 Parent (Typ), Prim);
ee6ba406 8382 end if;
343d35dc 8383 end if;
aad6babd 8384
343d35dc 8385 Next_Elmt (Prim_Elmt);
8386 end loop;
ee6ba406 8387
343d35dc 8388 -- Additional check
aad6babd 8389
343d35dc 8390 if Is_Controlled (Typ) then
8391 if not Finalized then
503f7fd3 8392 Error_Msg_N
343d35dc 8393 ("controlled type has no explicit Finalize method?", Typ);
ee6ba406 8394
343d35dc 8395 elsif not Adjusted then
503f7fd3 8396 Error_Msg_N
343d35dc 8397 ("controlled type has no explicit Adjust method?", Typ);
ee6ba406 8398 end if;
343d35dc 8399 end if;
ee6ba406 8400
343d35dc 8401 -- Set the final size of the Dispatch Table
aad6babd 8402
343d35dc 8403 Set_DT_Entry_Count (The_Tag, UI_From_Int (DT_Length));
ee6ba406 8404
725a69d2 8405 -- The derived type must have at least as many components as its parent
acf97c11 8406 -- (for root types Etype points to itself and the test cannot fail).
aad6babd 8407
725a69d2 8408 if DT_Entry_Count (The_Tag) <
8409 DT_Entry_Count (First_Tag_Component (Parent_Typ))
8410 then
8411 raise Program_Error;
aad6babd 8412 end if;
ee6ba406 8413 end Set_All_DT_Position;
8414
294b942d 8415 --------------------------
8416 -- Set_CPP_Constructors --
8417 --------------------------
ee6ba406 8418
294b942d 8419 procedure Set_CPP_Constructors (Typ : Entity_Id) is
d00681a7 8420
8421 procedure Set_CPP_Constructors_Old (Typ : Entity_Id);
8422 -- For backward compatibility this routine handles CPP constructors
8423 -- of non-tagged types.
8424
8425 procedure Set_CPP_Constructors_Old (Typ : Entity_Id) is
8426 Loc : Source_Ptr;
8427 Init : Entity_Id;
8428 E : Entity_Id;
8429 Found : Boolean := False;
8430 P : Node_Id;
8431 Parms : List_Id;
8432
8433 begin
8434 -- Look for the constructor entities
8435
8436 E := Next_Entity (Typ);
8437 while Present (E) loop
8438 if Ekind (E) = E_Function
8439 and then Is_Constructor (E)
8440 then
8441 -- Create the init procedure
8442
8443 Found := True;
8444 Loc := Sloc (E);
8445 Init := Make_Defining_Identifier (Loc,
8446 Make_Init_Proc_Name (Typ));
8447 Parms :=
8448 New_List (
8449 Make_Parameter_Specification (Loc,
8450 Defining_Identifier =>
8451 Make_Defining_Identifier (Loc, Name_X),
8452 Parameter_Type =>
8453 New_Reference_To (Typ, Loc)));
8454
8455 if Present (Parameter_Specifications (Parent (E))) then
8456 P := First (Parameter_Specifications (Parent (E)));
8457 while Present (P) loop
8458 Append_To (Parms,
8459 Make_Parameter_Specification (Loc,
8460 Defining_Identifier =>
8461 Make_Defining_Identifier (Loc,
8462 Chars (Defining_Identifier (P))),
8463 Parameter_Type =>
8464 New_Copy_Tree (Parameter_Type (P))));
8465 Next (P);
8466 end loop;
8467 end if;
8468
8469 Discard_Node (
8470 Make_Subprogram_Declaration (Loc,
8471 Make_Procedure_Specification (Loc,
8472 Defining_Unit_Name => Init,
8473 Parameter_Specifications => Parms)));
8474
8475 Set_Init_Proc (Typ, Init);
8476 Set_Is_Imported (Init);
265200d0 8477 Set_Is_Constructor (Init);
d00681a7 8478 Set_Interface_Name (Init, Interface_Name (E));
265200d0 8479 Set_Convention (Init, Convention_CPP);
d00681a7 8480 Set_Is_Public (Init);
8481 Set_Has_Completion (Init);
8482 end if;
8483
8484 Next_Entity (E);
8485 end loop;
8486
8487 -- If there are no constructors, mark the type as abstract since we
8488 -- won't be able to declare objects of that type.
8489
8490 if not Found then
8491 Set_Is_Abstract_Type (Typ);
8492 end if;
8493 end Set_CPP_Constructors_Old;
8494
8495 -- Local variables
8496
ee6ba406 8497 Loc : Source_Ptr;
ee6ba406 8498 E : Entity_Id;
294b942d 8499 Found : Boolean := False;
8500 P : Node_Id;
8501 Parms : List_Id;
ee6ba406 8502
d00681a7 8503 Constructor_Decl_Node : Node_Id;
8504 Constructor_Id : Entity_Id;
8505 Wrapper_Id : Entity_Id;
8506 Wrapper_Body_Node : Node_Id;
8507 Actuals : List_Id;
8508 Body_Stmts : List_Id;
8509 Init_Tags_List : List_Id;
8510
ee6ba406 8511 begin
d00681a7 8512 pragma Assert (Is_CPP_Class (Typ));
8513
8514 -- For backward compatibility the compiler accepts C++ classes
8515 -- imported through non-tagged record types. In such case the
8516 -- wrapper of the C++ constructor is useless because the _tag
8517 -- component is not available.
8518
8519 -- Example:
8520 -- type Root is limited record ...
8521 -- pragma Import (CPP, Root);
8522 -- function New_Root return Root;
8523 -- pragma CPP_Constructor (New_Root, ... );
8524
8525 if not Is_Tagged_Type (Typ) then
8526 Set_CPP_Constructors_Old (Typ);
8527 return;
8528 end if;
8529
294b942d 8530 -- Look for the constructor entities
ee6ba406 8531
8532 E := Next_Entity (Typ);
294b942d 8533 while Present (E) loop
8534 if Ekind (E) = E_Function
8535 and then Is_Constructor (E)
8536 then
294b942d 8537 Found := True;
8538 Loc := Sloc (E);
d00681a7 8539
8540 -- Generate the declaration of the imported C++ constructor
8541
294b942d 8542 Parms :=
8543 New_List (
8544 Make_Parameter_Specification (Loc,
8545 Defining_Identifier =>
d00681a7 8546 Make_Defining_Identifier (Loc, Name_uInit),
294b942d 8547 Parameter_Type =>
8548 New_Reference_To (Typ, Loc)));
8549
8550 if Present (Parameter_Specifications (Parent (E))) then
8551 P := First (Parameter_Specifications (Parent (E)));
8552 while Present (P) loop
8553 Append_To (Parms,
8554 Make_Parameter_Specification (Loc,
8555 Defining_Identifier =>
8556 Make_Defining_Identifier (Loc,
8557 Chars (Defining_Identifier (P))),
8558 Parameter_Type => New_Copy_Tree (Parameter_Type (P))));
8559 Next (P);
8560 end loop;
8561 end if;
8562
d00681a7 8563 Constructor_Id := Make_Temporary (Loc, 'P');
8564
8565 Constructor_Decl_Node :=
294b942d 8566 Make_Subprogram_Declaration (Loc,
8567 Make_Procedure_Specification (Loc,
d00681a7 8568 Defining_Unit_Name => Constructor_Id,
8569 Parameter_Specifications => Parms));
8570
8571 Set_Is_Imported (Constructor_Id);
265200d0 8572 Set_Is_Constructor (Constructor_Id);
d00681a7 8573 Set_Interface_Name (Constructor_Id, Interface_Name (E));
265200d0 8574 Set_Convention (Constructor_Id, Convention_CPP);
d00681a7 8575 Set_Is_Public (Constructor_Id);
8576 Set_Has_Completion (Constructor_Id);
8577
8578 -- Build the wrapper of this constructor
8579
8580 Parms :=
8581 New_List (
8582 Make_Parameter_Specification (Loc,
8583 Defining_Identifier =>
8584 Make_Defining_Identifier (Loc, Name_uInit),
8585 Parameter_Type =>
8586 New_Reference_To (Typ, Loc)));
8587
8588 if Present (Parameter_Specifications (Parent (E))) then
8589 P := First (Parameter_Specifications (Parent (E)));
8590 while Present (P) loop
8591 Append_To (Parms,
8592 Make_Parameter_Specification (Loc,
8593 Defining_Identifier =>
8594 Make_Defining_Identifier (Loc,
8595 Chars (Defining_Identifier (P))),
8596 Parameter_Type => New_Copy_Tree (Parameter_Type (P))));
8597 Next (P);
8598 end loop;
8599 end if;
8600
8601 Body_Stmts := New_List;
8602
8603 -- Invoke the C++ constructor
8604
8605 Actuals := New_List;
8606
8607 P := First (Parms);
8608 while Present (P) loop
8609 Append_To (Actuals,
8610 New_Reference_To (Defining_Identifier (P), Loc));
8611 Next (P);
8612 end loop;
8613
8614 Append_To (Body_Stmts,
8615 Make_Procedure_Call_Statement (Loc,
8616 Name => New_Reference_To (Constructor_Id, Loc),
8617 Parameter_Associations => Actuals));
8618
8619 -- Initialize copies of C++ primary and secondary tags
8620
8621 Init_Tags_List := New_List;
8622
8623 declare
8624 Tag_Elmt : Elmt_Id;
8625 Tag_Comp : Node_Id;
8626
8627 begin
8628 Tag_Elmt := First_Elmt (Access_Disp_Table (Typ));
8629 Tag_Comp := First_Tag_Component (Typ);
8630
8631 while Present (Tag_Elmt)
8632 and then Is_Tag (Node (Tag_Elmt))
8633 loop
8634 -- Skip the following assertion with primary tags because
8635 -- Related_Type is not set on primary tag components
8636
8637 pragma Assert (Tag_Comp = First_Tag_Component (Typ)
8638 or else Related_Type (Node (Tag_Elmt))
8639 = Related_Type (Tag_Comp));
8640
8641 Append_To (Init_Tags_List,
8642 Make_Assignment_Statement (Loc,
8643 Name =>
8644 New_Reference_To (Node (Tag_Elmt), Loc),
8645 Expression =>
8646 Make_Selected_Component (Loc,
55868293 8647 Prefix =>
8648 Make_Identifier (Loc, Name_uInit),
d00681a7 8649 Selector_Name =>
8650 New_Reference_To (Tag_Comp, Loc))));
8651
8652 Tag_Comp := Next_Tag_Component (Tag_Comp);
8653 Next_Elmt (Tag_Elmt);
8654 end loop;
8655 end;
8656
8657 Append_To (Body_Stmts,
8658 Make_If_Statement (Loc,
8659 Condition =>
8660 Make_Op_Eq (Loc,
8661 Left_Opnd =>
8662 New_Reference_To
8663 (Node (First_Elmt (Access_Disp_Table (Typ))),
8664 Loc),
8665 Right_Opnd =>
8666 Unchecked_Convert_To (RTE (RE_Tag),
8667 New_Reference_To (RTE (RE_Null_Address), Loc))),
8668 Then_Statements => Init_Tags_List));
8669
8670 Wrapper_Id := Make_Defining_Identifier (Loc,
8671 Make_Init_Proc_Name (Typ));
8672
8673 Wrapper_Body_Node :=
8674 Make_Subprogram_Body (Loc,
8675 Specification =>
8676 Make_Procedure_Specification (Loc,
8677 Defining_Unit_Name => Wrapper_Id,
8678 Parameter_Specifications => Parms),
8679 Declarations => New_List (Constructor_Decl_Node),
8680 Handled_Statement_Sequence =>
8681 Make_Handled_Sequence_Of_Statements (Loc,
8682 Statements => Body_Stmts,
8683 Exception_Handlers => No_List));
8684
8685 Discard_Node (Wrapper_Body_Node);
8686 Set_Init_Proc (Typ, Wrapper_Id);
294b942d 8687 end if;
8688
ee6ba406 8689 Next_Entity (E);
8690 end loop;
8691
9dfe12ae 8692 -- If there are no constructors, mark the type as abstract since we
ee6ba406 8693 -- won't be able to declare objects of that type.
8694
294b942d 8695 if not Found then
343d35dc 8696 Set_Is_Abstract_Type (Typ);
ee6ba406 8697 end if;
d00681a7 8698
8699 -- If the CPP type has constructors then it must import also the default
8700 -- C++ constructor. It is required for default initialization of objects
8701 -- of the type. It is also required to elaborate objects of Ada types
8702 -- that are defined as derivations of this CPP type.
8703
8704 if Has_CPP_Constructors (Typ)
8705 and then No (Init_Proc (Typ))
8706 then
8707 Error_Msg_N ("?default constructor must be imported from C++", Typ);
8708 end if;
294b942d 8709 end Set_CPP_Constructors;
ee6ba406 8710
725a69d2 8711 --------------------------
8712 -- Set_DTC_Entity_Value --
8713 --------------------------
8714
8715 procedure Set_DTC_Entity_Value
8716 (Tagged_Type : Entity_Id;
8717 Prim : Entity_Id)
8718 is
8719 begin
a652dd51 8720 if Present (Interface_Alias (Prim))
725a69d2 8721 and then Is_Interface
a652dd51 8722 (Find_Dispatching_Type (Interface_Alias (Prim)))
725a69d2 8723 then
8724 Set_DTC_Entity (Prim,
8725 Find_Interface_Tag
8726 (T => Tagged_Type,
a652dd51 8727 Iface => Find_Dispatching_Type (Interface_Alias (Prim))));
725a69d2 8728 else
8729 Set_DTC_Entity (Prim,
8730 First_Tag_Component (Tagged_Type));
8731 end if;
8732 end Set_DTC_Entity_Value;
8733
952af0b9 8734 -----------------
8735 -- Tagged_Kind --
8736 -----------------
8737
8738 function Tagged_Kind (T : Entity_Id) return Node_Id is
8739 Conc_Typ : Entity_Id;
8740 Loc : constant Source_Ptr := Sloc (T);
8741
8742 begin
68f95949 8743 pragma Assert
8744 (Is_Tagged_Type (T) and then RTE_Available (RE_Tagged_Kind));
952af0b9 8745
8746 -- Abstract kinds
8747
343d35dc 8748 if Is_Abstract_Type (T) then
952af0b9 8749 if Is_Limited_Record (T) then
8750 return New_Reference_To (RTE (RE_TK_Abstract_Limited_Tagged), Loc);
8751 else
8752 return New_Reference_To (RTE (RE_TK_Abstract_Tagged), Loc);
8753 end if;
8754
8755 -- Concurrent kinds
8756
8757 elsif Is_Concurrent_Record_Type (T) then
8758 Conc_Typ := Corresponding_Concurrent_Type (T);
8759
17e14451 8760 if Present (Full_View (Conc_Typ)) then
8761 Conc_Typ := Full_View (Conc_Typ);
8762 end if;
8763
952af0b9 8764 if Ekind (Conc_Typ) = E_Protected_Type then
8765 return New_Reference_To (RTE (RE_TK_Protected), Loc);
8766 else
8767 pragma Assert (Ekind (Conc_Typ) = E_Task_Type);
8768 return New_Reference_To (RTE (RE_TK_Task), Loc);
8769 end if;
8770
8771 -- Regular tagged kinds
8772
8773 else
8774 if Is_Limited_Record (T) then
8775 return New_Reference_To (RTE (RE_TK_Limited_Tagged), Loc);
8776 else
8777 return New_Reference_To (RTE (RE_TK_Tagged), Loc);
8778 end if;
8779 end if;
8780 end Tagged_Kind;
8781
aad6babd 8782 --------------
8783 -- Write_DT --
8784 --------------
8785
8786 procedure Write_DT (Typ : Entity_Id) is
8787 Elmt : Elmt_Id;
8788 Prim : Node_Id;
8789
8790 begin
8791 -- Protect this procedure against wrong usage. Required because it will
8792 -- be used directly from GDB
8793
17e14451 8794 if not (Typ <= Last_Node_Id)
aad6babd 8795 or else not Is_Tagged_Type (Typ)
8796 then
d62940bf 8797 Write_Str ("wrong usage: Write_DT must be used with tagged types");
aad6babd 8798 Write_Eol;
8799 return;
8800 end if;
8801
8802 Write_Int (Int (Typ));
8803 Write_Str (": ");
8804 Write_Name (Chars (Typ));
8805
8806 if Is_Interface (Typ) then
8807 Write_Str (" is interface");
8808 end if;
8809
8810 Write_Eol;
8811
8812 Elmt := First_Elmt (Primitive_Operations (Typ));
8813 while Present (Elmt) loop
8814 Prim := Node (Elmt);
8815 Write_Str (" - ");
8816
8817 -- Indicate if this primitive will be allocated in the primary
8818 -- dispatch table or in a secondary dispatch table associated
8819 -- with an abstract interface type
8820
8821 if Present (DTC_Entity (Prim)) then
8822 if Etype (DTC_Entity (Prim)) = RTE (RE_Tag) then
8823 Write_Str ("[P] ");
8824 else
8825 Write_Str ("[s] ");
8826 end if;
8827 end if;
8828
8829 -- Output the node of this primitive operation and its name
8830
8831 Write_Int (Int (Prim));
8832 Write_Str (": ");
68f95949 8833
8834 if Is_Predefined_Dispatching_Operation (Prim) then
8835 Write_Str ("(predefined) ");
8836 end if;
8837
b381b314 8838 -- Prefix the name of the primitive with its corresponding tagged
8839 -- type to facilitate seeing inherited primitives.
8840
8841 if Present (Alias (Prim)) then
8842 Write_Name
8843 (Chars (Find_Dispatching_Type (Ultimate_Alias (Prim))));
8844 else
8845 Write_Name (Chars (Typ));
8846 end if;
8847
8848 Write_Str (".");
aad6babd 8849 Write_Name (Chars (Prim));
8850
8851 -- Indicate if this primitive has an aliased primitive
8852
8853 if Present (Alias (Prim)) then
8854 Write_Str (" (alias = ");
8855 Write_Int (Int (Alias (Prim)));
8856
8857 -- If the DTC_Entity attribute is already set we can also output
4c58ddd7 8858 -- the name of the interface covered by this primitive (if any).
aad6babd 8859
8860 if Present (DTC_Entity (Alias (Prim)))
8861 and then Is_Interface (Scope (DTC_Entity (Alias (Prim))))
8862 then
8863 Write_Str (" from interface ");
8864 Write_Name (Chars (Scope (DTC_Entity (Alias (Prim)))));
8865 end if;
8866
a652dd51 8867 if Present (Interface_Alias (Prim)) then
aad6babd 8868 Write_Str (", AI_Alias of ");
f235fede 8869
8870 if Is_Null_Interface_Primitive (Interface_Alias (Prim)) then
8871 Write_Str ("null primitive ");
8872 end if;
8873
a652dd51 8874 Write_Name
8875 (Chars (Find_Dispatching_Type (Interface_Alias (Prim))));
aad6babd 8876 Write_Char (':');
a652dd51 8877 Write_Int (Int (Interface_Alias (Prim)));
aad6babd 8878 end if;
8879
8880 Write_Str (")");
8881 end if;
8882
8883 -- Display the final position of this primitive in its associated
8884 -- (primary or secondary) dispatch table
8885
8886 if Present (DTC_Entity (Prim))
8887 and then DT_Position (Prim) /= No_Uint
8888 then
8889 Write_Str (" at #");
8890 Write_Int (UI_To_Int (DT_Position (Prim)));
8891 end if;
8892
343d35dc 8893 if Is_Abstract_Subprogram (Prim) then
aad6babd 8894 Write_Str (" is abstract;");
af647dc7 8895
8896 -- Check if this is a null primitive
8897
8898 elsif Comes_From_Source (Prim)
8899 and then Ekind (Prim) = E_Procedure
8900 and then Null_Present (Parent (Prim))
8901 then
8902 Write_Str (" is null;");
aad6babd 8903 end if;
8904
555c63a6 8905 if Is_Eliminated (Ultimate_Alias (Prim)) then
8906 Write_Str (" (eliminated)");
8907 end if;
8908
d00681a7 8909 if Is_Imported (Prim)
8910 and then Convention (Prim) = Convention_CPP
8911 then
8912 Write_Str (" (C++)");
8913 end if;
8914
aad6babd 8915 Write_Eol;
8916
8917 Next_Elmt (Elmt);
8918 end loop;
8919 end Write_DT;
8920
ee6ba406 8921end Exp_Disp;