]>
Commit | Line | Data |
---|---|---|
ee6ba406 | 1 | ------------------------------------------------------------------------------ |
2 | -- -- | |
3 | -- GNAT COMPILER COMPONENTS -- | |
4 | -- -- | |
5 | -- E X P _ D I S P -- | |
6 | -- -- | |
7 | -- B o d y -- | |
8 | -- -- | |
294b942d | 9 | -- Copyright (C) 1992-2009, 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 | ||
26 | with Atree; use Atree; | |
27 | with Checks; use Checks; | |
aad6babd | 28 | with Debug; use Debug; |
ee6ba406 | 29 | with Einfo; use Einfo; |
30 | with Elists; use Elists; | |
31 | with Errout; use Errout; | |
343d35dc | 32 | with Exp_Atag; use Exp_Atag; |
ee6ba406 | 33 | with Exp_Ch7; use Exp_Ch7; |
76a1c25b | 34 | with Exp_Dbug; use Exp_Dbug; |
ee6ba406 | 35 | with Exp_Tss; use Exp_Tss; |
36 | with Exp_Util; use Exp_Util; | |
af647dc7 | 37 | with Freeze; use Freeze; |
ee6ba406 | 38 | with Itypes; use Itypes; |
b6b96867 | 39 | with Layout; use Layout; |
ee6ba406 | 40 | with Nlists; use Nlists; |
41 | with Nmake; use Nmake; | |
aad6babd | 42 | with Namet; use Namet; |
ee6ba406 | 43 | with Opt; use Opt; |
aad6babd | 44 | with Output; use Output; |
68f95949 | 45 | with Restrict; use Restrict; |
46 | with Rident; use Rident; | |
ee6ba406 | 47 | with Rtsfind; use Rtsfind; |
aad6babd | 48 | with Sem; use Sem; |
d60c9ff7 | 49 | with Sem_Aux; use Sem_Aux; |
725a69d2 | 50 | with Sem_Ch6; use Sem_Ch6; |
acf97c11 | 51 | with Sem_Ch7; use Sem_Ch7; |
725a69d2 | 52 | with Sem_Ch8; use Sem_Ch8; |
ee6ba406 | 53 | with Sem_Disp; use Sem_Disp; |
725a69d2 | 54 | with Sem_Eval; use Sem_Eval; |
ee6ba406 | 55 | with Sem_Res; use Sem_Res; |
aad6babd | 56 | with Sem_Type; use Sem_Type; |
ee6ba406 | 57 | with Sem_Util; use Sem_Util; |
58 | with Sinfo; use Sinfo; | |
59 | with Snames; use Snames; | |
60 | with Stand; use Stand; | |
725a69d2 | 61 | with Stringt; use Stringt; |
ee6ba406 | 62 | with Tbuild; use Tbuild; |
63 | with Uintp; use Uintp; | |
64 | ||
65 | package body Exp_Disp is | |
66 | ||
725a69d2 | 67 | ----------------------- |
68 | -- Local Subprograms -- | |
69 | ----------------------- | |
ee6ba406 | 70 | |
68f95949 | 71 | function Default_Prim_Op_Position (E : Entity_Id) return Uint; |
aad6babd | 72 | -- Ada 2005 (AI-251): Returns the fixed position in the dispatch table |
73 | -- of the default primitive operations. | |
74 | ||
24971415 | 75 | function Has_DT (Typ : Entity_Id) return Boolean; |
76 | pragma Inline (Has_DT); | |
77 | -- Returns true if we generate a dispatch table for tagged type Typ | |
78 | ||
af647dc7 | 79 | function Is_Predefined_Dispatching_Alias (Prim : Entity_Id) return Boolean; |
80 | -- Returns true if Prim is not a predefined dispatching primitive but it is | |
36b938a3 | 81 | -- an alias of a predefined dispatching primitive (i.e. through a renaming) |
af647dc7 | 82 | |
cd534f03 | 83 | function New_Value (From : Node_Id) return Node_Id; |
84 | -- From is the original Expression. New_Value is equivalent to a call | |
85 | -- to Duplicate_Subexpr with an explicit dereference when From is an | |
86 | -- access parameter. | |
87 | ||
ee6ba406 | 88 | function Original_View_In_Visible_Part (Typ : Entity_Id) return Boolean; |
89 | -- Check if the type has a private view or if the public view appears | |
90 | -- in the visible part of a package spec. | |
91 | ||
d62940bf | 92 | function Prim_Op_Kind |
93 | (Prim : Entity_Id; | |
94 | Typ : Entity_Id) return Node_Id; | |
95 | -- Ada 2005 (AI-345): Determine the primitive operation kind of Prim | |
952af0b9 | 96 | -- according to its type Typ. Return a reference to an RE_Prim_Op_Kind |
d62940bf | 97 | -- enumeration value. |
aad6babd | 98 | |
952af0b9 | 99 | function Tagged_Kind (T : Entity_Id) return Node_Id; |
100 | -- Ada 2005 (AI-345): Determine the tagged kind of T and return a reference | |
101 | -- to an RE_Tagged_Kind enumeration value. | |
102 | ||
d215f619 | 103 | ---------------------- |
104 | -- Adjust_SCIL_Node -- | |
105 | ---------------------- | |
106 | ||
107 | procedure Adjust_SCIL_Node (Old_Node : Node_Id; New_Node : Node_Id) is | |
108 | SCIL_Node : Node_Id; | |
109 | ||
110 | begin | |
111 | pragma Assert (Generate_SCIL); | |
112 | ||
113 | -- Check cases in which no action is required. Currently the only SCIL | |
114 | -- nodes that may require adjustment are those of dispatching calls | |
115 | -- internally generated by the frontend. | |
116 | ||
117 | if Comes_From_Source (Old_Node) | |
118 | or else not | |
119 | Nkind_In (New_Node, N_Function_Call, N_Procedure_Call_Statement) | |
120 | then | |
121 | return; | |
122 | ||
123 | -- Conditional expression associated with equality operator. Old_Node | |
124 | -- may be part of the expansion of the predefined equality operator of | |
125 | -- a tagged type and hence we need to check if it has a SCIL dispatching | |
126 | -- node that needs adjustment. | |
127 | ||
128 | elsif Nkind (Old_Node) = N_Conditional_Expression | |
129 | and then (Nkind (Original_Node (Old_Node)) = N_Op_Eq | |
130 | or else | |
131 | (Nkind (Original_Node (Old_Node)) = N_Function_Call | |
132 | and then Chars (Name (Original_Node (Old_Node))) | |
133 | = Name_Op_Eq)) | |
134 | then | |
135 | null; | |
136 | ||
137 | -- Type conversions may involve dispatching calls to functions whose | |
138 | -- associated SCIL dispatching node needs adjustment. | |
139 | ||
140 | elsif Nkind (Old_Node) = N_Type_Conversion then | |
141 | null; | |
142 | ||
143 | -- Relocated subprogram call | |
144 | ||
145 | elsif Nkind (Old_Node) = Nkind (New_Node) | |
146 | and then Original_Node (Old_Node) = Original_Node (New_Node) | |
147 | then | |
148 | null; | |
149 | ||
150 | else | |
151 | return; | |
152 | end if; | |
153 | ||
154 | -- Search for the SCIL node and update it (if found) | |
155 | ||
156 | SCIL_Node := Find_SCIL_Node (Old_Node); | |
157 | ||
158 | if Present (SCIL_Node) then | |
159 | Set_SCIL_Related_Node (SCIL_Node, New_Node); | |
160 | end if; | |
161 | end Adjust_SCIL_Node; | |
162 | ||
cd534f03 | 163 | ---------------------- |
164 | -- Apply_Tag_Checks -- | |
165 | ---------------------- | |
166 | ||
167 | procedure Apply_Tag_Checks (Call_Node : Node_Id) is | |
168 | Loc : constant Source_Ptr := Sloc (Call_Node); | |
169 | Ctrl_Arg : constant Node_Id := Controlling_Argument (Call_Node); | |
170 | Ctrl_Typ : constant Entity_Id := Base_Type (Etype (Ctrl_Arg)); | |
171 | Param_List : constant List_Id := Parameter_Associations (Call_Node); | |
172 | ||
173 | Subp : Entity_Id; | |
174 | CW_Typ : Entity_Id; | |
175 | Param : Node_Id; | |
176 | Typ : Entity_Id; | |
177 | Eq_Prim_Op : Entity_Id := Empty; | |
178 | ||
179 | begin | |
180 | if No_Run_Time_Mode then | |
181 | Error_Msg_CRT ("tagged types", Call_Node); | |
182 | return; | |
183 | end if; | |
184 | ||
185 | -- Apply_Tag_Checks is called directly from the semantics, so we need | |
186 | -- a check to see whether expansion is active before proceeding. In | |
187 | -- addition, there is no need to expand the call when compiling under | |
188 | -- restriction No_Dispatching_Calls; the semantic analyzer has | |
189 | -- previously notified the violation of this restriction. | |
190 | ||
191 | if not Expander_Active | |
192 | or else Restriction_Active (No_Dispatching_Calls) | |
193 | then | |
194 | return; | |
195 | end if; | |
196 | ||
197 | -- Set subprogram. If this is an inherited operation that was | |
198 | -- overridden, the body that is being called is its alias. | |
199 | ||
200 | Subp := Entity (Name (Call_Node)); | |
201 | ||
202 | if Present (Alias (Subp)) | |
203 | and then Is_Inherited_Operation (Subp) | |
204 | and then No (DTC_Entity (Subp)) | |
205 | then | |
206 | Subp := Alias (Subp); | |
207 | end if; | |
208 | ||
209 | -- Definition of the class-wide type and the tagged type | |
210 | ||
211 | -- If the controlling argument is itself a tag rather than a tagged | |
212 | -- object, then use the class-wide type associated with the subprogram's | |
213 | -- controlling type. This case can occur when a call to an inherited | |
214 | -- primitive has an actual that originated from a default parameter | |
215 | -- given by a tag-indeterminate call and when there is no other | |
216 | -- controlling argument providing the tag (AI-239 requires dispatching). | |
217 | -- This capability of dispatching directly by tag is also needed by the | |
218 | -- implementation of AI-260 (for the generic dispatching constructors). | |
219 | ||
220 | if Ctrl_Typ = RTE (RE_Tag) | |
221 | or else (RTE_Available (RE_Interface_Tag) | |
222 | and then Ctrl_Typ = RTE (RE_Interface_Tag)) | |
223 | then | |
224 | CW_Typ := Class_Wide_Type (Find_Dispatching_Type (Subp)); | |
225 | ||
226 | -- Class_Wide_Type is applied to the expressions used to initialize | |
227 | -- CW_Typ, to ensure that CW_Typ always denotes a class-wide type, since | |
228 | -- there are cases where the controlling type is resolved to a specific | |
229 | -- type (such as for designated types of arguments such as CW'Access). | |
230 | ||
231 | elsif Is_Access_Type (Ctrl_Typ) then | |
232 | CW_Typ := Class_Wide_Type (Designated_Type (Ctrl_Typ)); | |
233 | ||
234 | else | |
235 | CW_Typ := Class_Wide_Type (Ctrl_Typ); | |
236 | end if; | |
237 | ||
238 | Typ := Root_Type (CW_Typ); | |
239 | ||
240 | if Ekind (Typ) = E_Incomplete_Type then | |
241 | Typ := Non_Limited_View (Typ); | |
242 | end if; | |
243 | ||
244 | if not Is_Limited_Type (Typ) then | |
245 | Eq_Prim_Op := Find_Prim_Op (Typ, Name_Op_Eq); | |
246 | end if; | |
247 | ||
248 | -- Dispatching call to C++ primitive | |
249 | ||
250 | if Is_CPP_Class (Typ) then | |
251 | null; | |
252 | ||
253 | -- Dispatching call to Ada primitive | |
254 | ||
255 | elsif Present (Param_List) then | |
256 | ||
257 | -- Generate the Tag checks when appropriate | |
258 | ||
259 | Param := First_Actual (Call_Node); | |
260 | while Present (Param) loop | |
261 | ||
262 | -- No tag check with itself | |
263 | ||
264 | if Param = Ctrl_Arg then | |
265 | null; | |
266 | ||
267 | -- No tag check for parameter whose type is neither tagged nor | |
268 | -- access to tagged (for access parameters) | |
269 | ||
270 | elsif No (Find_Controlling_Arg (Param)) then | |
271 | null; | |
272 | ||
273 | -- No tag check for function dispatching on result if the | |
274 | -- Tag given by the context is this one | |
275 | ||
276 | elsif Find_Controlling_Arg (Param) = Ctrl_Arg then | |
277 | null; | |
278 | ||
279 | -- "=" is the only dispatching operation allowed to get | |
280 | -- operands with incompatible tags (it just returns false). | |
281 | -- We use Duplicate_Subexpr_Move_Checks instead of calling | |
282 | -- Relocate_Node because the value will be duplicated to | |
283 | -- check the tags. | |
284 | ||
285 | elsif Subp = Eq_Prim_Op then | |
286 | null; | |
287 | ||
288 | -- No check in presence of suppress flags | |
289 | ||
290 | elsif Tag_Checks_Suppressed (Etype (Param)) | |
291 | or else (Is_Access_Type (Etype (Param)) | |
292 | and then Tag_Checks_Suppressed | |
293 | (Designated_Type (Etype (Param)))) | |
294 | then | |
295 | null; | |
296 | ||
297 | -- Optimization: no tag checks if the parameters are identical | |
298 | ||
299 | elsif Is_Entity_Name (Param) | |
300 | and then Is_Entity_Name (Ctrl_Arg) | |
301 | and then Entity (Param) = Entity (Ctrl_Arg) | |
302 | then | |
303 | null; | |
304 | ||
305 | -- Now we need to generate the Tag check | |
306 | ||
307 | else | |
308 | -- Generate code for tag equality check | |
309 | -- Perhaps should have Checks.Apply_Tag_Equality_Check??? | |
310 | ||
311 | Insert_Action (Ctrl_Arg, | |
312 | Make_Implicit_If_Statement (Call_Node, | |
313 | Condition => | |
314 | Make_Op_Ne (Loc, | |
315 | Left_Opnd => | |
316 | Make_Selected_Component (Loc, | |
317 | Prefix => New_Value (Ctrl_Arg), | |
318 | Selector_Name => | |
319 | New_Reference_To | |
320 | (First_Tag_Component (Typ), Loc)), | |
321 | ||
322 | Right_Opnd => | |
323 | Make_Selected_Component (Loc, | |
324 | Prefix => | |
325 | Unchecked_Convert_To (Typ, New_Value (Param)), | |
326 | Selector_Name => | |
327 | New_Reference_To | |
328 | (First_Tag_Component (Typ), Loc))), | |
329 | ||
330 | Then_Statements => | |
331 | New_List (New_Constraint_Error (Loc)))); | |
332 | end if; | |
333 | ||
334 | Next_Actual (Param); | |
335 | end loop; | |
336 | end if; | |
337 | end Apply_Tag_Checks; | |
338 | ||
24971415 | 339 | ------------------------ |
340 | -- Building_Static_DT -- | |
341 | ------------------------ | |
342 | ||
343 | function Building_Static_DT (Typ : Entity_Id) return Boolean is | |
cc60bd16 | 344 | Root_Typ : Entity_Id := Root_Type (Typ); |
345 | ||
24971415 | 346 | begin |
cc60bd16 | 347 | -- Handle private types |
348 | ||
349 | if Present (Full_View (Root_Typ)) then | |
350 | Root_Typ := Full_View (Root_Typ); | |
351 | end if; | |
352 | ||
24971415 | 353 | return Static_Dispatch_Tables |
e7e688dd | 354 | and then Is_Library_Level_Tagged_Type (Typ) |
355 | ||
356 | -- If the type is derived from a CPP class we cannot statically | |
357 | -- build the dispatch tables because we must inherit primitives | |
358 | -- from the CPP side. | |
359 | ||
cc60bd16 | 360 | and then not Is_CPP_Class (Root_Typ); |
24971415 | 361 | end Building_Static_DT; |
362 | ||
17e14451 | 363 | ---------------------------------- |
364 | -- Build_Static_Dispatch_Tables -- | |
365 | ---------------------------------- | |
366 | ||
367 | procedure Build_Static_Dispatch_Tables (N : Entity_Id) is | |
368 | Target_List : List_Id; | |
369 | ||
370 | procedure Build_Dispatch_Tables (List : List_Id); | |
371 | -- Build the static dispatch table of tagged types found in the list of | |
372 | -- declarations. The generated nodes are added at the end of Target_List | |
373 | ||
374 | procedure Build_Package_Dispatch_Tables (N : Node_Id); | |
375 | -- Build static dispatch tables associated with package declaration N | |
376 | ||
377 | --------------------------- | |
378 | -- Build_Dispatch_Tables -- | |
379 | --------------------------- | |
380 | ||
381 | procedure Build_Dispatch_Tables (List : List_Id) is | |
382 | D : Node_Id; | |
383 | ||
384 | begin | |
385 | D := First (List); | |
386 | while Present (D) loop | |
387 | ||
388 | -- Handle nested packages and package bodies recursively. The | |
389 | -- generated code is placed on the Target_List established for | |
390 | -- the enclosing compilation unit. | |
391 | ||
392 | if Nkind (D) = N_Package_Declaration then | |
393 | Build_Package_Dispatch_Tables (D); | |
394 | ||
395 | elsif Nkind (D) = N_Package_Body then | |
396 | Build_Dispatch_Tables (Declarations (D)); | |
397 | ||
398 | elsif Nkind (D) = N_Package_Body_Stub | |
399 | and then Present (Library_Unit (D)) | |
400 | then | |
401 | Build_Dispatch_Tables | |
402 | (Declarations (Proper_Body (Unit (Library_Unit (D))))); | |
403 | ||
404 | -- Handle full type declarations and derivations of library | |
405 | -- level tagged types | |
406 | ||
3164ed99 | 407 | elsif Nkind_In (D, N_Full_Type_Declaration, |
408 | N_Derived_Type_Definition) | |
17e14451 | 409 | and then Is_Library_Level_Tagged_Type (Defining_Entity (D)) |
410 | and then Ekind (Defining_Entity (D)) /= E_Record_Subtype | |
411 | and then not Is_Private_Type (Defining_Entity (D)) | |
412 | then | |
442049cc | 413 | -- We do not generate dispatch tables for the internal types |
d9fac90e | 414 | -- created for a type extension with unknown discriminants |
415 | -- The needed information is shared with the source type, | |
416 | -- See Expand_N_Record_Extension. | |
417 | ||
442049cc | 418 | if Is_Underlying_Record_View (Defining_Entity (D)) |
419 | or else | |
420 | (not Comes_From_Source (Defining_Entity (D)) | |
421 | and then | |
2f29393f | 422 | Has_Unknown_Discriminants (Etype (Defining_Entity (D))) |
442049cc | 423 | and then |
2f29393f | 424 | not Comes_From_Source |
425 | (First_Subtype (Defining_Entity (D)))) | |
d9fac90e | 426 | then |
427 | null; | |
d9fac90e | 428 | else |
429 | Insert_List_After_And_Analyze (Last (Target_List), | |
430 | Make_DT (Defining_Entity (D))); | |
431 | end if; | |
17e14451 | 432 | |
433 | -- Handle private types of library level tagged types. We must | |
434 | -- exchange the private and full-view to ensure the correct | |
a735d663 | 435 | -- expansion. If the full view is a synchronized type ignore |
436 | -- the type because the table will be built for the corresponding | |
437 | -- record type, that has its own declaration. | |
17e14451 | 438 | |
439 | elsif (Nkind (D) = N_Private_Type_Declaration | |
440 | or else Nkind (D) = N_Private_Extension_Declaration) | |
441 | and then Present (Full_View (Defining_Entity (D))) | |
17e14451 | 442 | then |
443 | declare | |
acf97c11 | 444 | E1 : constant Entity_Id := Defining_Entity (D); |
a735d663 | 445 | E2 : constant Entity_Id := Full_View (E1); |
acf97c11 | 446 | |
17e14451 | 447 | begin |
a735d663 | 448 | if Is_Library_Level_Tagged_Type (E2) |
449 | and then Ekind (E2) /= E_Record_Subtype | |
450 | and then not Is_Concurrent_Type (E2) | |
451 | then | |
452 | Exchange_Declarations (E1); | |
453 | Insert_List_After_And_Analyze (Last (Target_List), | |
454 | Make_DT (E1)); | |
455 | Exchange_Declarations (E2); | |
456 | end if; | |
17e14451 | 457 | end; |
458 | end if; | |
459 | ||
460 | Next (D); | |
461 | end loop; | |
462 | end Build_Dispatch_Tables; | |
463 | ||
464 | ----------------------------------- | |
465 | -- Build_Package_Dispatch_Tables -- | |
466 | ----------------------------------- | |
467 | ||
468 | procedure Build_Package_Dispatch_Tables (N : Node_Id) is | |
469 | Spec : constant Node_Id := Specification (N); | |
470 | Id : constant Entity_Id := Defining_Entity (N); | |
471 | Vis_Decls : constant List_Id := Visible_Declarations (Spec); | |
472 | Priv_Decls : constant List_Id := Private_Declarations (Spec); | |
473 | ||
474 | begin | |
475 | Push_Scope (Id); | |
476 | ||
477 | if Present (Priv_Decls) then | |
478 | Build_Dispatch_Tables (Vis_Decls); | |
479 | Build_Dispatch_Tables (Priv_Decls); | |
480 | ||
481 | elsif Present (Vis_Decls) then | |
482 | Build_Dispatch_Tables (Vis_Decls); | |
483 | end if; | |
484 | ||
485 | Pop_Scope; | |
486 | end Build_Package_Dispatch_Tables; | |
487 | ||
488 | -- Start of processing for Build_Static_Dispatch_Tables | |
489 | ||
490 | begin | |
491 | if not Expander_Active | |
662256db | 492 | or else not Tagged_Type_Expansion |
17e14451 | 493 | then |
494 | return; | |
495 | end if; | |
496 | ||
497 | if Nkind (N) = N_Package_Declaration then | |
498 | declare | |
499 | Spec : constant Node_Id := Specification (N); | |
500 | Vis_Decls : constant List_Id := Visible_Declarations (Spec); | |
501 | Priv_Decls : constant List_Id := Private_Declarations (Spec); | |
502 | ||
503 | begin | |
504 | if Present (Priv_Decls) | |
505 | and then Is_Non_Empty_List (Priv_Decls) | |
506 | then | |
507 | Target_List := Priv_Decls; | |
508 | ||
509 | elsif not Present (Vis_Decls) then | |
510 | Target_List := New_List; | |
511 | Set_Private_Declarations (Spec, Target_List); | |
512 | else | |
513 | Target_List := Vis_Decls; | |
514 | end if; | |
515 | ||
516 | Build_Package_Dispatch_Tables (N); | |
517 | end; | |
518 | ||
519 | else pragma Assert (Nkind (N) = N_Package_Body); | |
520 | Target_List := Declarations (N); | |
521 | Build_Dispatch_Tables (Target_List); | |
522 | end if; | |
523 | end Build_Static_Dispatch_Tables; | |
524 | ||
aad6babd | 525 | ------------------------------ |
526 | -- Default_Prim_Op_Position -- | |
527 | ------------------------------ | |
528 | ||
68f95949 | 529 | function Default_Prim_Op_Position (E : Entity_Id) return Uint is |
aad6babd | 530 | TSS_Name : TSS_Name_Type; |
aad6babd | 531 | |
532 | begin | |
aad6babd | 533 | Get_Name_String (Chars (E)); |
534 | TSS_Name := | |
535 | TSS_Name_Type | |
536 | (Name_Buffer (Name_Len - TSS_Name'Length + 1 .. Name_Len)); | |
537 | ||
538 | if Chars (E) = Name_uSize then | |
539 | return Uint_1; | |
540 | ||
541 | elsif Chars (E) = Name_uAlignment then | |
542 | return Uint_2; | |
543 | ||
544 | elsif TSS_Name = TSS_Stream_Read then | |
545 | return Uint_3; | |
546 | ||
547 | elsif TSS_Name = TSS_Stream_Write then | |
548 | return Uint_4; | |
549 | ||
550 | elsif TSS_Name = TSS_Stream_Input then | |
551 | return Uint_5; | |
552 | ||
553 | elsif TSS_Name = TSS_Stream_Output then | |
554 | return Uint_6; | |
555 | ||
556 | elsif Chars (E) = Name_Op_Eq then | |
557 | return Uint_7; | |
558 | ||
559 | elsif Chars (E) = Name_uAssign then | |
560 | return Uint_8; | |
561 | ||
562 | elsif TSS_Name = TSS_Deep_Adjust then | |
563 | return Uint_9; | |
564 | ||
565 | elsif TSS_Name = TSS_Deep_Finalize then | |
566 | return Uint_10; | |
567 | ||
76a1c25b | 568 | elsif Ada_Version >= Ada_05 then |
569 | if Chars (E) = Name_uDisp_Asynchronous_Select then | |
570 | return Uint_11; | |
d62940bf | 571 | |
76a1c25b | 572 | elsif Chars (E) = Name_uDisp_Conditional_Select then |
573 | return Uint_12; | |
d62940bf | 574 | |
76a1c25b | 575 | elsif Chars (E) = Name_uDisp_Get_Prim_Op_Kind then |
576 | return Uint_13; | |
d62940bf | 577 | |
76a1c25b | 578 | elsif Chars (E) = Name_uDisp_Get_Task_Id then |
579 | return Uint_14; | |
d62940bf | 580 | |
cdb1c38f | 581 | elsif Chars (E) = Name_uDisp_Requeue then |
76a1c25b | 582 | return Uint_15; |
cdb1c38f | 583 | |
584 | elsif Chars (E) = Name_uDisp_Timed_Select then | |
585 | return Uint_16; | |
76a1c25b | 586 | end if; |
aad6babd | 587 | end if; |
76a1c25b | 588 | |
589 | raise Program_Error; | |
aad6babd | 590 | end Default_Prim_Op_Position; |
591 | ||
7189d17f | 592 | ----------------------------- |
593 | -- Expand_Dispatching_Call -- | |
594 | ----------------------------- | |
ee6ba406 | 595 | |
7189d17f | 596 | procedure Expand_Dispatching_Call (Call_Node : Node_Id) is |
ee6ba406 | 597 | Loc : constant Source_Ptr := Sloc (Call_Node); |
598 | Call_Typ : constant Entity_Id := Etype (Call_Node); | |
599 | ||
2ea346ac | 600 | Ctrl_Arg : constant Node_Id := Controlling_Argument (Call_Node); |
601 | Ctrl_Typ : constant Entity_Id := Base_Type (Etype (Ctrl_Arg)); | |
602 | Param_List : constant List_Id := Parameter_Associations (Call_Node); | |
ee6ba406 | 603 | |
af647dc7 | 604 | Subp : Entity_Id; |
7189d17f | 605 | CW_Typ : Entity_Id; |
606 | New_Call : Node_Id; | |
607 | New_Call_Name : Node_Id; | |
608 | New_Params : List_Id := No_List; | |
609 | Param : Node_Id; | |
610 | Res_Typ : Entity_Id; | |
611 | Subp_Ptr_Typ : Entity_Id; | |
612 | Subp_Typ : Entity_Id; | |
613 | Typ : Entity_Id; | |
614 | Eq_Prim_Op : Entity_Id := Empty; | |
615 | Controlling_Tag : Node_Id; | |
ee6ba406 | 616 | |
617 | function New_Value (From : Node_Id) return Node_Id; | |
9dfe12ae | 618 | -- From is the original Expression. New_Value is equivalent to a call |
619 | -- to Duplicate_Subexpr with an explicit dereference when From is an | |
7189d17f | 620 | -- access parameter. |
621 | ||
9dfe12ae | 622 | --------------- |
623 | -- New_Value -- | |
624 | --------------- | |
625 | ||
ee6ba406 | 626 | function New_Value (From : Node_Id) return Node_Id is |
627 | Res : constant Node_Id := Duplicate_Subexpr (From); | |
ee6ba406 | 628 | begin |
629 | if Is_Access_Type (Etype (From)) then | |
af647dc7 | 630 | return |
631 | Make_Explicit_Dereference (Sloc (From), | |
632 | Prefix => Res); | |
ee6ba406 | 633 | else |
634 | return Res; | |
635 | end if; | |
636 | end New_Value; | |
637 | ||
d215f619 | 638 | -- Local variables |
639 | ||
640 | SCIL_Node : Node_Id; | |
641 | ||
7189d17f | 642 | -- Start of processing for Expand_Dispatching_Call |
ee6ba406 | 643 | |
644 | begin | |
725a69d2 | 645 | if No_Run_Time_Mode then |
646 | Error_Msg_CRT ("tagged types", Call_Node); | |
647 | return; | |
648 | end if; | |
649 | ||
343d35dc | 650 | -- Expand_Dispatching_Call is called directly from the semantics, |
651 | -- so we need a check to see whether expansion is active before | |
652 | -- proceeding. In addition, there is no need to expand the call | |
653 | -- if we are compiling under restriction No_Dispatching_Calls; | |
654 | -- the semantic analyzer has previously notified the violation | |
655 | -- of this restriction. | |
656 | ||
657 | if not Expander_Active | |
658 | or else Restriction_Active (No_Dispatching_Calls) | |
659 | then | |
660 | return; | |
661 | end if; | |
68f95949 | 662 | |
af647dc7 | 663 | -- Set subprogram. If this is an inherited operation that was |
664 | -- overridden, the body that is being called is its alias. | |
665 | ||
666 | Subp := Entity (Name (Call_Node)); | |
ee6ba406 | 667 | |
668 | if Present (Alias (Subp)) | |
669 | and then Is_Inherited_Operation (Subp) | |
670 | and then No (DTC_Entity (Subp)) | |
671 | then | |
672 | Subp := Alias (Subp); | |
673 | end if; | |
674 | ||
7189d17f | 675 | -- Definition of the class-wide type and the tagged type |
ee6ba406 | 676 | |
7189d17f | 677 | -- If the controlling argument is itself a tag rather than a tagged |
678 | -- object, then use the class-wide type associated with the subprogram's | |
679 | -- controlling type. This case can occur when a call to an inherited | |
680 | -- primitive has an actual that originated from a default parameter | |
681 | -- given by a tag-indeterminate call and when there is no other | |
682 | -- controlling argument providing the tag (AI-239 requires dispatching). | |
683 | -- This capability of dispatching directly by tag is also needed by the | |
684 | -- implementation of AI-260 (for the generic dispatching constructors). | |
685 | ||
2ea346ac | 686 | if Ctrl_Typ = RTE (RE_Tag) |
68f95949 | 687 | or else (RTE_Available (RE_Interface_Tag) |
2ea346ac | 688 | and then Ctrl_Typ = RTE (RE_Interface_Tag)) |
aad6babd | 689 | then |
af647dc7 | 690 | CW_Typ := Class_Wide_Type (Find_Dispatching_Type (Subp)); |
7189d17f | 691 | |
725a69d2 | 692 | -- Class_Wide_Type is applied to the expressions used to initialize |
693 | -- CW_Typ, to ensure that CW_Typ always denotes a class-wide type, since | |
694 | -- there are cases where the controlling type is resolved to a specific | |
695 | -- type (such as for designated types of arguments such as CW'Access). | |
696 | ||
2ea346ac | 697 | elsif Is_Access_Type (Ctrl_Typ) then |
698 | CW_Typ := Class_Wide_Type (Designated_Type (Ctrl_Typ)); | |
7189d17f | 699 | |
ee6ba406 | 700 | else |
2ea346ac | 701 | CW_Typ := Class_Wide_Type (Ctrl_Typ); |
ee6ba406 | 702 | end if; |
703 | ||
704 | Typ := Root_Type (CW_Typ); | |
705 | ||
d62940bf | 706 | if Ekind (Typ) = E_Incomplete_Type then |
707 | Typ := Non_Limited_View (Typ); | |
708 | end if; | |
709 | ||
ad003cee | 710 | -- Generate the SCIL node for this dispatching call. The SCIL node for a |
711 | -- dispatching call is inserted in the tree before the call is rewriten | |
712 | -- and expanded because the SCIL node must be found by the SCIL backend | |
713 | -- BEFORE the expanded nodes associated with the call node are found. | |
714 | ||
715 | if Generate_SCIL then | |
d215f619 | 716 | SCIL_Node := Make_SCIL_Dispatching_Call (Sloc (Call_Node)); |
717 | Set_SCIL_Related_Node (SCIL_Node, Call_Node); | |
718 | Set_SCIL_Entity (SCIL_Node, Typ); | |
719 | Set_SCIL_Target_Prim (SCIL_Node, Subp); | |
720 | Insert_Action (Call_Node, SCIL_Node); | |
ad003cee | 721 | end if; |
722 | ||
ee6ba406 | 723 | if not Is_Limited_Type (Typ) then |
724 | Eq_Prim_Op := Find_Prim_Op (Typ, Name_Op_Eq); | |
725 | end if; | |
726 | ||
343d35dc | 727 | -- Dispatching call to C++ primitive. Create a new parameter list |
728 | -- with no tag checks. | |
ee6ba406 | 729 | |
cd534f03 | 730 | New_Params := New_List; |
731 | ||
343d35dc | 732 | if Is_CPP_Class (Typ) then |
ee6ba406 | 733 | Param := First_Actual (Call_Node); |
734 | while Present (Param) loop | |
aad6babd | 735 | Append_To (New_Params, Relocate_Node (Param)); |
ee6ba406 | 736 | Next_Actual (Param); |
737 | end loop; | |
738 | ||
343d35dc | 739 | -- Dispatching call to Ada primitive |
740 | ||
ee6ba406 | 741 | elsif Present (Param_List) then |
cd534f03 | 742 | Apply_Tag_Checks (Call_Node); |
ee6ba406 | 743 | |
ee6ba406 | 744 | Param := First_Actual (Call_Node); |
745 | while Present (Param) loop | |
cd534f03 | 746 | -- Cases in which we may have generated runtime checks |
ee6ba406 | 747 | |
cd534f03 | 748 | if Param = Ctrl_Arg |
749 | or else Subp = Eq_Prim_Op | |
750 | then | |
9dfe12ae | 751 | Append_To (New_Params, |
752 | Duplicate_Subexpr_Move_Checks (Param)); | |
ee6ba406 | 753 | |
ee6ba406 | 754 | else |
ee6ba406 | 755 | Append_To (New_Params, Relocate_Node (Param)); |
756 | end if; | |
757 | ||
758 | Next_Actual (Param); | |
759 | end loop; | |
760 | end if; | |
761 | ||
762 | -- Generate the appropriate subprogram pointer type | |
763 | ||
68f95949 | 764 | if Etype (Subp) = Typ then |
ee6ba406 | 765 | Res_Typ := CW_Typ; |
766 | else | |
7189d17f | 767 | Res_Typ := Etype (Subp); |
ee6ba406 | 768 | end if; |
769 | ||
b6b96867 | 770 | Subp_Typ := Create_Itype (E_Subprogram_Type, Call_Node); |
ee6ba406 | 771 | Subp_Ptr_Typ := Create_Itype (E_Access_Subprogram_Type, Call_Node); |
772 | Set_Etype (Subp_Typ, Res_Typ); | |
ee6ba406 | 773 | Set_Returns_By_Ref (Subp_Typ, Returns_By_Ref (Subp)); |
774 | ||
775 | -- Create a new list of parameters which is a copy of the old formal | |
776 | -- list including the creation of a new set of matching entities. | |
777 | ||
778 | declare | |
779 | Old_Formal : Entity_Id := First_Formal (Subp); | |
780 | New_Formal : Entity_Id; | |
725a69d2 | 781 | Extra : Entity_Id := Empty; |
ee6ba406 | 782 | |
783 | begin | |
784 | if Present (Old_Formal) then | |
785 | New_Formal := New_Copy (Old_Formal); | |
786 | Set_First_Entity (Subp_Typ, New_Formal); | |
787 | Param := First_Actual (Call_Node); | |
788 | ||
789 | loop | |
790 | Set_Scope (New_Formal, Subp_Typ); | |
791 | ||
792 | -- Change all the controlling argument types to be class-wide | |
7189d17f | 793 | -- to avoid a recursion in dispatching. |
ee6ba406 | 794 | |
7189d17f | 795 | if Is_Controlling_Formal (New_Formal) then |
ee6ba406 | 796 | Set_Etype (New_Formal, Etype (Param)); |
797 | end if; | |
798 | ||
cc60bd16 | 799 | -- If the type of the formal is an itype, there was code here |
800 | -- introduced in 1998 in revision 1.46, to create a new itype | |
801 | -- by copy. This seems useless, and in fact leads to semantic | |
802 | -- errors when the itype is the completion of a type derived | |
803 | -- from a private type. | |
ee6ba406 | 804 | |
805 | Extra := New_Formal; | |
806 | Next_Formal (Old_Formal); | |
807 | exit when No (Old_Formal); | |
808 | ||
809 | Set_Next_Entity (New_Formal, New_Copy (Old_Formal)); | |
810 | Next_Entity (New_Formal); | |
811 | Next_Actual (Param); | |
812 | end loop; | |
af647dc7 | 813 | |
814 | Set_Next_Entity (New_Formal, Empty); | |
ee6ba406 | 815 | Set_Last_Entity (Subp_Typ, Extra); |
725a69d2 | 816 | end if; |
ee6ba406 | 817 | |
725a69d2 | 818 | -- Now that the explicit formals have been duplicated, any extra |
819 | -- formals needed by the subprogram must be created. | |
ee6ba406 | 820 | |
725a69d2 | 821 | if Present (Extra) then |
822 | Set_Extra_Formal (Extra, Empty); | |
ee6ba406 | 823 | end if; |
725a69d2 | 824 | |
825 | Create_Extra_Formals (Subp_Typ); | |
ee6ba406 | 826 | end; |
827 | ||
b6b96867 | 828 | -- Complete description of pointer type, including size information, as |
829 | -- must be done with itypes to prevent order-of-elaboration anomalies | |
830 | -- in gigi. | |
831 | ||
ee6ba406 | 832 | Set_Etype (Subp_Ptr_Typ, Subp_Ptr_Typ); |
833 | Set_Directly_Designated_Type (Subp_Ptr_Typ, Subp_Typ); | |
acf97c11 | 834 | Set_Convention (Subp_Ptr_Typ, Convention (Subp_Typ)); |
b6b96867 | 835 | Layout_Type (Subp_Ptr_Typ); |
ee6ba406 | 836 | |
68f95949 | 837 | -- If the controlling argument is a value of type Ada.Tag or an abstract |
838 | -- interface class-wide type then use it directly. Otherwise, the tag | |
839 | -- must be extracted from the controlling object. | |
7189d17f | 840 | |
2ea346ac | 841 | if Ctrl_Typ = RTE (RE_Tag) |
68f95949 | 842 | or else (RTE_Available (RE_Interface_Tag) |
2ea346ac | 843 | and then Ctrl_Typ = RTE (RE_Interface_Tag)) |
68f95949 | 844 | then |
845 | Controlling_Tag := Duplicate_Subexpr (Ctrl_Arg); | |
846 | ||
343d35dc | 847 | -- Extract the tag from an unchecked type conversion. Done to avoid |
848 | -- the expansion of additional code just to obtain the value of such | |
849 | -- tag because the current management of interface type conversions | |
850 | -- generates in some cases this unchecked type conversion with the | |
851 | -- tag of the object (see Expand_Interface_Conversion). | |
852 | ||
853 | elsif Nkind (Ctrl_Arg) = N_Unchecked_Type_Conversion | |
854 | and then | |
855 | (Etype (Expression (Ctrl_Arg)) = RTE (RE_Tag) | |
856 | or else | |
857 | (RTE_Available (RE_Interface_Tag) | |
858 | and then | |
859 | Etype (Expression (Ctrl_Arg)) = RTE (RE_Interface_Tag))) | |
860 | then | |
861 | Controlling_Tag := Duplicate_Subexpr (Expression (Ctrl_Arg)); | |
862 | ||
68f95949 | 863 | -- Ada 2005 (AI-251): Abstract interface class-wide type |
864 | ||
2ea346ac | 865 | elsif Is_Interface (Ctrl_Typ) |
866 | and then Is_Class_Wide_Type (Ctrl_Typ) | |
aad6babd | 867 | then |
7189d17f | 868 | Controlling_Tag := Duplicate_Subexpr (Ctrl_Arg); |
869 | ||
870 | else | |
871 | Controlling_Tag := | |
872 | Make_Selected_Component (Loc, | |
873 | Prefix => Duplicate_Subexpr_Move_Checks (Ctrl_Arg), | |
874 | Selector_Name => New_Reference_To (DTC_Entity (Subp), Loc)); | |
875 | end if; | |
876 | ||
d215f619 | 877 | -- Complete decoration of SCIL dispatching node |
878 | ||
879 | if Generate_SCIL then | |
880 | Set_SCIL_Controlling_Tag (SCIL_Node, Controlling_Tag); | |
881 | end if; | |
882 | ||
343d35dc | 883 | -- Handle dispatching calls to predefined primitives |
ee6ba406 | 884 | |
af647dc7 | 885 | if Is_Predefined_Dispatching_Operation (Subp) |
886 | or else Is_Predefined_Dispatching_Alias (Subp) | |
887 | then | |
68f95949 | 888 | New_Call_Name := |
889 | Unchecked_Convert_To (Subp_Ptr_Typ, | |
343d35dc | 890 | Build_Get_Predefined_Prim_Op_Address (Loc, |
891 | Tag_Node => Controlling_Tag, | |
725a69d2 | 892 | Position => DT_Position (Subp))); |
ee6ba406 | 893 | |
343d35dc | 894 | -- Handle dispatching calls to user-defined primitives |
68f95949 | 895 | |
896 | else | |
897 | New_Call_Name := | |
898 | Unchecked_Convert_To (Subp_Ptr_Typ, | |
343d35dc | 899 | Build_Get_Prim_Op_Address (Loc, |
725a69d2 | 900 | Typ => Find_Dispatching_Type (Subp), |
901 | Tag_Node => Controlling_Tag, | |
902 | Position => DT_Position (Subp))); | |
68f95949 | 903 | end if; |
ee6ba406 | 904 | |
905 | if Nkind (Call_Node) = N_Function_Call then | |
ee6ba406 | 906 | |
725a69d2 | 907 | New_Call := |
908 | Make_Function_Call (Loc, | |
909 | Name => New_Call_Name, | |
910 | Parameter_Associations => New_Params); | |
ee6ba406 | 911 | |
725a69d2 | 912 | -- If this is a dispatching "=", we must first compare the tags so |
913 | -- we generate: x.tag = y.tag and then x = y | |
ee6ba406 | 914 | |
725a69d2 | 915 | if Subp = Eq_Prim_Op then |
916 | Param := First_Actual (Call_Node); | |
aad6babd | 917 | New_Call := |
725a69d2 | 918 | Make_And_Then (Loc, |
919 | Left_Opnd => | |
920 | Make_Op_Eq (Loc, | |
921 | Left_Opnd => | |
922 | Make_Selected_Component (Loc, | |
923 | Prefix => New_Value (Param), | |
924 | Selector_Name => | |
925 | New_Reference_To (First_Tag_Component (Typ), | |
926 | Loc)), | |
ee6ba406 | 927 | |
725a69d2 | 928 | Right_Opnd => |
929 | Make_Selected_Component (Loc, | |
930 | Prefix => | |
931 | Unchecked_Convert_To (Typ, | |
932 | New_Value (Next_Actual (Param))), | |
933 | Selector_Name => | |
934 | New_Reference_To (First_Tag_Component (Typ), | |
935 | Loc))), | |
936 | Right_Opnd => New_Call); | |
ee6ba406 | 937 | end if; |
938 | ||
939 | else | |
940 | New_Call := | |
941 | Make_Procedure_Call_Statement (Loc, | |
942 | Name => New_Call_Name, | |
943 | Parameter_Associations => New_Params); | |
944 | end if; | |
945 | ||
946 | Rewrite (Call_Node, New_Call); | |
725a69d2 | 947 | |
948 | -- Suppress all checks during the analysis of the expanded code | |
36b938a3 | 949 | -- to avoid the generation of spurious warnings under ZFP run-time. |
725a69d2 | 950 | |
951 | Analyze_And_Resolve (Call_Node, Call_Typ, Suppress => All_Checks); | |
7189d17f | 952 | end Expand_Dispatching_Call; |
ee6ba406 | 953 | |
aad6babd | 954 | --------------------------------- |
955 | -- Expand_Interface_Conversion -- | |
956 | --------------------------------- | |
957 | ||
952af0b9 | 958 | procedure Expand_Interface_Conversion |
959 | (N : Node_Id; | |
960 | Is_Static : Boolean := True) | |
961 | is | |
aad6babd | 962 | Loc : constant Source_Ptr := Sloc (N); |
af647dc7 | 963 | Etyp : constant Entity_Id := Etype (N); |
aad6babd | 964 | Operand : constant Node_Id := Expression (N); |
965 | Operand_Typ : Entity_Id := Etype (Operand); | |
d62940bf | 966 | Func : Node_Id; |
af647dc7 | 967 | Iface_Typ : Entity_Id := Etype (N); |
968 | Iface_Tag : Entity_Id; | |
aad6babd | 969 | |
970 | begin | |
343d35dc | 971 | -- Ada 2005 (AI-345): Handle synchronized interface type derivations |
aad6babd | 972 | |
343d35dc | 973 | if Is_Concurrent_Type (Operand_Typ) then |
974 | Operand_Typ := Base_Type (Corresponding_Record_Type (Operand_Typ)); | |
aad6babd | 975 | end if; |
976 | ||
e7e688dd | 977 | -- Handle access to class-wide interface types |
aad6babd | 978 | |
d62940bf | 979 | if Is_Access_Type (Iface_Typ) then |
980 | Iface_Typ := Etype (Directly_Designated_Type (Iface_Typ)); | |
aad6babd | 981 | end if; |
982 | ||
d62940bf | 983 | -- Handle class-wide interface types. This conversion can appear |
984 | -- explicitly in the source code. Example: I'Class (Obj) | |
aad6babd | 985 | |
d62940bf | 986 | if Is_Class_Wide_Type (Iface_Typ) then |
725a69d2 | 987 | Iface_Typ := Root_Type (Iface_Typ); |
d62940bf | 988 | end if; |
989 | ||
79a72728 | 990 | -- If the target type is a tagged synchronized type, the dispatch table |
bf3e1520 | 991 | -- info is in the corresponding record type. |
79a72728 | 992 | |
993 | if Is_Concurrent_Type (Iface_Typ) then | |
994 | Iface_Typ := Corresponding_Record_Type (Iface_Typ); | |
995 | end if; | |
996 | ||
a17cc77d | 997 | -- Freeze the entity associated with the target interface to have |
998 | -- available the attribute Access_Disp_Table. | |
999 | ||
1000 | Freeze_Before (N, Iface_Typ); | |
1001 | ||
af647dc7 | 1002 | pragma Assert (not Is_Static |
1003 | or else (not Is_Class_Wide_Type (Iface_Typ) | |
1004 | and then Is_Interface (Iface_Typ))); | |
aad6babd | 1005 | |
662256db | 1006 | if not Tagged_Type_Expansion then |
725a69d2 | 1007 | |
1008 | -- For VM, just do a conversion ??? | |
1009 | ||
1010 | Rewrite (N, Unchecked_Convert_To (Etype (N), N)); | |
1011 | Analyze (N); | |
1012 | return; | |
1013 | end if; | |
1014 | ||
952af0b9 | 1015 | if not Is_Static then |
68f95949 | 1016 | |
1017 | -- Give error if configurable run time and Displace not available | |
1018 | ||
1019 | if not RTE_Available (RE_Displace) then | |
cc60bd16 | 1020 | Error_Msg_CRT ("dynamic interface conversion", N); |
68f95949 | 1021 | return; |
1022 | end if; | |
1023 | ||
725a69d2 | 1024 | -- Handle conversion of access-to-class-wide interface types. Target |
1025 | -- can be an access to an object or an access to another class-wide | |
1026 | -- interface (see -1- and -2- in the following example): | |
af647dc7 | 1027 | |
1028 | -- type Iface1_Ref is access all Iface1'Class; | |
1029 | -- type Iface2_Ref is access all Iface1'Class; | |
1030 | ||
1031 | -- Acc1 : Iface1_Ref := new ... | |
1032 | -- Obj : Obj_Ref := Obj_Ref (Acc); -- 1 | |
1033 | -- Acc2 : Iface2_Ref := Iface2_Ref (Acc); -- 2 | |
1034 | ||
1035 | if Is_Access_Type (Operand_Typ) then | |
af647dc7 | 1036 | Rewrite (N, |
1037 | Unchecked_Convert_To (Etype (N), | |
1038 | Make_Function_Call (Loc, | |
1039 | Name => New_Reference_To (RTE (RE_Displace), Loc), | |
1040 | Parameter_Associations => New_List ( | |
1041 | ||
1042 | Unchecked_Convert_To (RTE (RE_Address), | |
1043 | Relocate_Node (Expression (N))), | |
1044 | ||
1045 | New_Occurrence_Of | |
1046 | (Node (First_Elmt (Access_Disp_Table (Iface_Typ))), | |
1047 | Loc))))); | |
1048 | ||
1049 | Analyze (N); | |
1050 | return; | |
1051 | end if; | |
1052 | ||
952af0b9 | 1053 | Rewrite (N, |
1054 | Make_Function_Call (Loc, | |
1055 | Name => New_Reference_To (RTE (RE_Displace), Loc), | |
1056 | Parameter_Associations => New_List ( | |
1057 | Make_Attribute_Reference (Loc, | |
1058 | Prefix => Relocate_Node (Expression (N)), | |
1059 | Attribute_Name => Name_Address), | |
af647dc7 | 1060 | |
952af0b9 | 1061 | New_Occurrence_Of |
1062 | (Node (First_Elmt (Access_Disp_Table (Iface_Typ))), | |
1063 | Loc)))); | |
1064 | ||
1065 | Analyze (N); | |
1066 | ||
af647dc7 | 1067 | -- If the target is a class-wide interface we change the type of the |
1068 | -- data returned by IW_Convert to indicate that this is a dispatching | |
1069 | -- call. | |
952af0b9 | 1070 | |
17e14451 | 1071 | declare |
1072 | New_Itype : Entity_Id; | |
952af0b9 | 1073 | |
17e14451 | 1074 | begin |
1075 | New_Itype := Create_Itype (E_Anonymous_Access_Type, N); | |
cc60bd16 | 1076 | Set_Etype (New_Itype, New_Itype); |
17e14451 | 1077 | Set_Directly_Designated_Type (New_Itype, Etyp); |
952af0b9 | 1078 | |
17e14451 | 1079 | Rewrite (N, |
1080 | Make_Explicit_Dereference (Loc, | |
1081 | Prefix => | |
1082 | Unchecked_Convert_To (New_Itype, Relocate_Node (N)))); | |
1083 | Analyze (N); | |
1084 | Freeze_Itype (New_Itype, N); | |
1085 | ||
1086 | return; | |
1087 | end; | |
952af0b9 | 1088 | end if; |
1089 | ||
d62940bf | 1090 | Iface_Tag := Find_Interface_Tag (Operand_Typ, Iface_Typ); |
aad6babd | 1091 | pragma Assert (Iface_Tag /= Empty); |
1092 | ||
d62940bf | 1093 | -- Keep separate access types to interfaces because one internal |
1094 | -- function is used to handle the null value (see following comment) | |
1095 | ||
1096 | if not Is_Access_Type (Etype (N)) then | |
1097 | Rewrite (N, | |
1098 | Unchecked_Convert_To (Etype (N), | |
1099 | Make_Selected_Component (Loc, | |
1100 | Prefix => Relocate_Node (Expression (N)), | |
1101 | Selector_Name => | |
1102 | New_Occurrence_Of (Iface_Tag, Loc)))); | |
1103 | ||
1104 | else | |
1105 | -- Build internal function to handle the case in which the | |
1106 | -- actual is null. If the actual is null returns null because | |
1107 | -- no displacement is required; otherwise performs a type | |
1108 | -- conversion that will be expanded in the code that returns | |
1109 | -- the value of the displaced actual. That is: | |
1110 | ||
af647dc7 | 1111 | -- function Func (O : Address) return Iface_Typ is |
17e14451 | 1112 | -- type Op_Typ is access all Operand_Typ; |
1113 | -- Aux : Op_Typ := To_Op_Typ (O); | |
d62940bf | 1114 | -- begin |
af647dc7 | 1115 | -- if O = Null_Address then |
d62940bf | 1116 | -- return null; |
1117 | -- else | |
17e14451 | 1118 | -- return Iface_Typ!(Aux.Iface_Tag'Address); |
d62940bf | 1119 | -- end if; |
1120 | -- end Func; | |
1121 | ||
af647dc7 | 1122 | declare |
17e14451 | 1123 | Desig_Typ : Entity_Id; |
1124 | Fent : Entity_Id; | |
1125 | New_Typ_Decl : Node_Id; | |
17e14451 | 1126 | Stats : List_Id; |
1127 | ||
af647dc7 | 1128 | begin |
1129 | Desig_Typ := Etype (Expression (N)); | |
d62940bf | 1130 | |
af647dc7 | 1131 | if Is_Access_Type (Desig_Typ) then |
865909d3 | 1132 | Desig_Typ := |
1133 | Available_View (Directly_Designated_Type (Desig_Typ)); | |
af647dc7 | 1134 | end if; |
d62940bf | 1135 | |
e7e688dd | 1136 | if Is_Concurrent_Type (Desig_Typ) then |
1137 | Desig_Typ := Base_Type (Corresponding_Record_Type (Desig_Typ)); | |
1138 | end if; | |
1139 | ||
17e14451 | 1140 | New_Typ_Decl := |
1141 | Make_Full_Type_Declaration (Loc, | |
1142 | Defining_Identifier => | |
1143 | Make_Defining_Identifier (Loc, New_Internal_Name ('T')), | |
1144 | Type_Definition => | |
1145 | Make_Access_To_Object_Definition (Loc, | |
1146 | All_Present => True, | |
1147 | Null_Exclusion_Present => False, | |
1148 | Constant_Present => False, | |
1149 | Subtype_Indication => | |
1150 | New_Reference_To (Desig_Typ, Loc))); | |
d62940bf | 1151 | |
725a69d2 | 1152 | Stats := New_List ( |
17e14451 | 1153 | Make_Simple_Return_Statement (Loc, |
1154 | Unchecked_Convert_To (Etype (N), | |
1155 | Make_Attribute_Reference (Loc, | |
1156 | Prefix => | |
1157 | Make_Selected_Component (Loc, | |
1158 | Prefix => | |
e7e688dd | 1159 | Unchecked_Convert_To |
1160 | (Defining_Identifier (New_Typ_Decl), | |
1161 | Make_Identifier (Loc, Name_uO)), | |
17e14451 | 1162 | Selector_Name => |
1163 | New_Occurrence_Of (Iface_Tag, Loc)), | |
1164 | Attribute_Name => Name_Address)))); | |
725a69d2 | 1165 | |
17e14451 | 1166 | -- If the type is null-excluding, no need for the null branch. |
1167 | -- Otherwise we need to check for it and return null. | |
1168 | ||
1169 | if not Can_Never_Be_Null (Etype (N)) then | |
1170 | Stats := New_List ( | |
1171 | Make_If_Statement (Loc, | |
1172 | Condition => | |
1173 | Make_Op_Eq (Loc, | |
1174 | Left_Opnd => Make_Identifier (Loc, Name_uO), | |
1175 | Right_Opnd => New_Reference_To | |
1176 | (RTE (RE_Null_Address), Loc)), | |
1177 | ||
1178 | Then_Statements => New_List ( | |
1179 | Make_Simple_Return_Statement (Loc, | |
1180 | Make_Null (Loc))), | |
1181 | Else_Statements => Stats)); | |
1182 | end if; | |
d62940bf | 1183 | |
17e14451 | 1184 | Fent := |
1185 | Make_Defining_Identifier (Loc, | |
1186 | New_Internal_Name ('F')); | |
af647dc7 | 1187 | |
17e14451 | 1188 | Func := |
1189 | Make_Subprogram_Body (Loc, | |
1190 | Specification => | |
1191 | Make_Function_Specification (Loc, | |
1192 | Defining_Unit_Name => Fent, | |
d62940bf | 1193 | |
17e14451 | 1194 | Parameter_Specifications => New_List ( |
1195 | Make_Parameter_Specification (Loc, | |
1196 | Defining_Identifier => | |
1197 | Make_Defining_Identifier (Loc, Name_uO), | |
1198 | Parameter_Type => | |
1199 | New_Reference_To (RTE (RE_Address), Loc))), | |
d62940bf | 1200 | |
17e14451 | 1201 | Result_Definition => |
1202 | New_Reference_To (Etype (N), Loc)), | |
d62940bf | 1203 | |
e7e688dd | 1204 | Declarations => New_List (New_Typ_Decl), |
d62940bf | 1205 | |
17e14451 | 1206 | Handled_Statement_Sequence => |
1207 | Make_Handled_Sequence_Of_Statements (Loc, Stats)); | |
d62940bf | 1208 | |
17e14451 | 1209 | -- Place function body before the expression containing the |
1210 | -- conversion. We suppress all checks because the body of the | |
1211 | -- internally generated function already takes care of the case | |
1212 | -- in which the actual is null; therefore there is no need to | |
1213 | -- double check that the pointer is not null when the program | |
1214 | -- executes the alternative that performs the type conversion). | |
af647dc7 | 1215 | |
17e14451 | 1216 | Insert_Action (N, Func, Suppress => All_Checks); |
af647dc7 | 1217 | |
17e14451 | 1218 | if Is_Access_Type (Etype (Expression (N))) then |
af647dc7 | 1219 | |
e7e688dd | 1220 | -- Generate: Func (Address!(Expression)) |
af647dc7 | 1221 | |
17e14451 | 1222 | Rewrite (N, |
1223 | Make_Function_Call (Loc, | |
1224 | Name => New_Reference_To (Fent, Loc), | |
1225 | Parameter_Associations => New_List ( | |
e7e688dd | 1226 | Unchecked_Convert_To (RTE (RE_Address), |
1227 | Relocate_Node (Expression (N)))))); | |
17e14451 | 1228 | |
1229 | else | |
e7e688dd | 1230 | -- Generate: Func (Operand_Typ!(Expression)'Address) |
17e14451 | 1231 | |
1232 | Rewrite (N, | |
1233 | Make_Function_Call (Loc, | |
1234 | Name => New_Reference_To (Fent, Loc), | |
1235 | Parameter_Associations => New_List ( | |
1236 | Make_Attribute_Reference (Loc, | |
1237 | Prefix => Unchecked_Convert_To (Operand_Typ, | |
1238 | Relocate_Node (Expression (N))), | |
1239 | Attribute_Name => Name_Address)))); | |
1240 | end if; | |
1241 | end; | |
d62940bf | 1242 | end if; |
aad6babd | 1243 | |
1244 | Analyze (N); | |
1245 | end Expand_Interface_Conversion; | |
1246 | ||
1247 | ------------------------------ | |
1248 | -- Expand_Interface_Actuals -- | |
1249 | ------------------------------ | |
1250 | ||
1251 | procedure Expand_Interface_Actuals (Call_Node : Node_Id) is | |
aad6babd | 1252 | Actual : Node_Id; |
d62940bf | 1253 | Actual_Dup : Node_Id; |
aad6babd | 1254 | Actual_Typ : Entity_Id; |
d62940bf | 1255 | Anon : Entity_Id; |
aad6babd | 1256 | Conversion : Node_Id; |
1257 | Formal : Entity_Id; | |
1258 | Formal_Typ : Entity_Id; | |
1259 | Subp : Entity_Id; | |
d62940bf | 1260 | Formal_DDT : Entity_Id; |
1261 | Actual_DDT : Entity_Id; | |
aad6babd | 1262 | |
1263 | begin | |
1264 | -- This subprogram is called directly from the semantics, so we need a | |
1265 | -- check to see whether expansion is active before proceeding. | |
1266 | ||
1267 | if not Expander_Active then | |
1268 | return; | |
1269 | end if; | |
1270 | ||
1271 | -- Call using access to subprogram with explicit dereference | |
1272 | ||
1273 | if Nkind (Name (Call_Node)) = N_Explicit_Dereference then | |
1274 | Subp := Etype (Name (Call_Node)); | |
1275 | ||
4e5db562 | 1276 | -- Call using selected component |
1277 | ||
1278 | elsif Nkind (Name (Call_Node)) = N_Selected_Component then | |
1279 | Subp := Entity (Selector_Name (Name (Call_Node))); | |
1280 | ||
1281 | -- Call using direct name | |
aad6babd | 1282 | |
1283 | else | |
1284 | Subp := Entity (Name (Call_Node)); | |
1285 | end if; | |
1286 | ||
725a69d2 | 1287 | -- Ada 2005 (AI-251): Look for interface type formals to force "this" |
1288 | -- displacement | |
1289 | ||
aad6babd | 1290 | Formal := First_Formal (Subp); |
1291 | Actual := First_Actual (Call_Node); | |
aad6babd | 1292 | while Present (Formal) loop |
725a69d2 | 1293 | Formal_Typ := Etype (Formal); |
d62940bf | 1294 | |
1295 | if Ekind (Formal_Typ) = E_Record_Type_With_Private then | |
1296 | Formal_Typ := Full_View (Formal_Typ); | |
1297 | end if; | |
1298 | ||
1299 | if Is_Access_Type (Formal_Typ) then | |
1300 | Formal_DDT := Directly_Designated_Type (Formal_Typ); | |
1301 | end if; | |
1302 | ||
aad6babd | 1303 | Actual_Typ := Etype (Actual); |
1304 | ||
d62940bf | 1305 | if Is_Access_Type (Actual_Typ) then |
1306 | Actual_DDT := Directly_Designated_Type (Actual_Typ); | |
1307 | end if; | |
1308 | ||
725a69d2 | 1309 | if Is_Interface (Formal_Typ) |
1310 | and then Is_Class_Wide_Type (Formal_Typ) | |
1311 | then | |
d62940bf | 1312 | -- No need to displace the pointer if the type of the actual |
725a69d2 | 1313 | -- coindices with the type of the formal. |
aad6babd | 1314 | |
725a69d2 | 1315 | if Actual_Typ = Formal_Typ then |
d62940bf | 1316 | null; |
1317 | ||
725a69d2 | 1318 | -- No need to displace the pointer if the interface type is |
1319 | -- a parent of the type of the actual because in this case the | |
1320 | -- interface primitives are located in the primary dispatch table. | |
aad6babd | 1321 | |
a652dd51 | 1322 | elsif Is_Ancestor (Formal_Typ, Actual_Typ) then |
d62940bf | 1323 | null; |
1324 | ||
725a69d2 | 1325 | -- Implicit conversion to the class-wide formal type to force |
1326 | -- the displacement of the pointer. | |
1327 | ||
d62940bf | 1328 | else |
1329 | Conversion := Convert_To (Formal_Typ, Relocate_Node (Actual)); | |
725a69d2 | 1330 | Rewrite (Actual, Conversion); |
d62940bf | 1331 | Analyze_And_Resolve (Actual, Formal_Typ); |
1332 | end if; | |
aad6babd | 1333 | |
725a69d2 | 1334 | -- Access to class-wide interface type |
aad6babd | 1335 | |
1336 | elsif Is_Access_Type (Formal_Typ) | |
725a69d2 | 1337 | and then Is_Interface (Formal_DDT) |
1338 | and then Is_Class_Wide_Type (Formal_DDT) | |
aad6babd | 1339 | and then Interface_Present_In_Ancestor |
d62940bf | 1340 | (Typ => Actual_DDT, |
1341 | Iface => Etype (Formal_DDT)) | |
aad6babd | 1342 | then |
725a69d2 | 1343 | -- Handle attributes 'Access and 'Unchecked_Access |
1344 | ||
aad6babd | 1345 | if Nkind (Actual) = N_Attribute_Reference |
1346 | and then | |
1347 | (Attribute_Name (Actual) = Name_Access | |
1348 | or else Attribute_Name (Actual) = Name_Unchecked_Access) | |
1349 | then | |
5e82d8fe | 1350 | -- This case must have been handled by the analysis and |
1351 | -- expansion of 'Access. The only exception is when types | |
1352 | -- match and no further expansion is required. | |
aad6babd | 1353 | |
5e82d8fe | 1354 | pragma Assert (Base_Type (Etype (Prefix (Actual))) |
1355 | = Base_Type (Formal_DDT)); | |
1356 | null; | |
aad6babd | 1357 | |
725a69d2 | 1358 | -- No need to displace the pointer if the type of the actual |
1359 | -- coincides with the type of the formal. | |
d62940bf | 1360 | |
725a69d2 | 1361 | elsif Actual_DDT = Formal_DDT then |
d62940bf | 1362 | null; |
1363 | ||
725a69d2 | 1364 | -- No need to displace the pointer if the interface type is |
1365 | -- a parent of the type of the actual because in this case the | |
1366 | -- interface primitives are located in the primary dispatch table. | |
d62940bf | 1367 | |
a652dd51 | 1368 | elsif Is_Ancestor (Formal_DDT, Actual_DDT) then |
d62940bf | 1369 | null; |
1370 | ||
aad6babd | 1371 | else |
d62940bf | 1372 | Actual_Dup := Relocate_Node (Actual); |
1373 | ||
1374 | if From_With_Type (Actual_Typ) then | |
1375 | ||
1376 | -- If the type of the actual parameter comes from a limited | |
1377 | -- with-clause and the non-limited view is already available | |
9ced80be | 1378 | -- we replace the anonymous access type by a duplicate |
1379 | -- declaration whose designated type is the non-limited view | |
d62940bf | 1380 | |
1381 | if Ekind (Actual_DDT) = E_Incomplete_Type | |
1382 | and then Present (Non_Limited_View (Actual_DDT)) | |
1383 | then | |
1384 | Anon := New_Copy (Actual_Typ); | |
1385 | ||
1386 | if Is_Itype (Anon) then | |
1387 | Set_Scope (Anon, Current_Scope); | |
1388 | end if; | |
1389 | ||
1390 | Set_Directly_Designated_Type (Anon, | |
1391 | Non_Limited_View (Actual_DDT)); | |
1392 | Set_Etype (Actual_Dup, Anon); | |
1393 | ||
1394 | elsif Is_Class_Wide_Type (Actual_DDT) | |
1395 | and then Ekind (Etype (Actual_DDT)) = E_Incomplete_Type | |
1396 | and then Present (Non_Limited_View (Etype (Actual_DDT))) | |
1397 | then | |
1398 | Anon := New_Copy (Actual_Typ); | |
1399 | ||
1400 | if Is_Itype (Anon) then | |
1401 | Set_Scope (Anon, Current_Scope); | |
1402 | end if; | |
1403 | ||
1404 | Set_Directly_Designated_Type (Anon, | |
1405 | New_Copy (Actual_DDT)); | |
1406 | Set_Class_Wide_Type (Directly_Designated_Type (Anon), | |
1407 | New_Copy (Class_Wide_Type (Actual_DDT))); | |
1408 | Set_Etype (Directly_Designated_Type (Anon), | |
1409 | Non_Limited_View (Etype (Actual_DDT))); | |
1410 | Set_Etype ( | |
1411 | Class_Wide_Type (Directly_Designated_Type (Anon)), | |
1412 | Non_Limited_View (Etype (Actual_DDT))); | |
1413 | Set_Etype (Actual_Dup, Anon); | |
1414 | end if; | |
1415 | end if; | |
1416 | ||
1417 | Conversion := Convert_To (Formal_Typ, Actual_Dup); | |
1418 | Rewrite (Actual, Conversion); | |
aad6babd | 1419 | Analyze_And_Resolve (Actual, Formal_Typ); |
1420 | end if; | |
1421 | end if; | |
1422 | ||
1423 | Next_Actual (Actual); | |
1424 | Next_Formal (Formal); | |
1425 | end loop; | |
1426 | end Expand_Interface_Actuals; | |
1427 | ||
1428 | ---------------------------- | |
1429 | -- Expand_Interface_Thunk -- | |
1430 | ---------------------------- | |
1431 | ||
725a69d2 | 1432 | procedure Expand_Interface_Thunk |
17e14451 | 1433 | (Prim : Node_Id; |
1434 | Thunk_Id : out Entity_Id; | |
1435 | Thunk_Code : out Node_Id) | |
aad6babd | 1436 | is |
17e14451 | 1437 | Loc : constant Source_Ptr := Sloc (Prim); |
725a69d2 | 1438 | Actuals : constant List_Id := New_List; |
1439 | Decl : constant List_Id := New_List; | |
1440 | Formals : constant List_Id := New_List; | |
1441 | ||
1442 | Controlling_Typ : Entity_Id; | |
1443 | Decl_1 : Node_Id; | |
1444 | Decl_2 : Node_Id; | |
1445 | Formal : Node_Id; | |
cc60bd16 | 1446 | New_Arg : Node_Id; |
1447 | Offset_To_Top : Node_Id; | |
725a69d2 | 1448 | Target : Entity_Id; |
1449 | Target_Formal : Entity_Id; | |
aad6babd | 1450 | |
1451 | begin | |
725a69d2 | 1452 | Thunk_Id := Empty; |
1453 | Thunk_Code := Empty; | |
1454 | ||
aad6babd | 1455 | -- Traverse the list of alias to find the final target |
1456 | ||
17e14451 | 1457 | Target := Prim; |
aad6babd | 1458 | while Present (Alias (Target)) loop |
1459 | Target := Alias (Target); | |
1460 | end loop; | |
1461 | ||
725a69d2 | 1462 | -- In case of primitives that are functions without formals and |
1463 | -- a controlling result there is no need to build the thunk. | |
1464 | ||
1465 | if not Present (First_Formal (Target)) then | |
1466 | pragma Assert (Ekind (Target) = E_Function | |
1467 | and then Has_Controlling_Result (Target)); | |
1468 | return; | |
1469 | end if; | |
1470 | ||
aad6babd | 1471 | -- Duplicate the formals |
1472 | ||
d62940bf | 1473 | Formal := First_Formal (Target); |
aad6babd | 1474 | while Present (Formal) loop |
725a69d2 | 1475 | Append_To (Formals, |
1476 | Make_Parameter_Specification (Loc, | |
1477 | Defining_Identifier => | |
1478 | Make_Defining_Identifier (Sloc (Formal), | |
1479 | Chars => Chars (Formal)), | |
1480 | In_Present => In_Present (Parent (Formal)), | |
1481 | Out_Present => Out_Present (Parent (Formal)), | |
1482 | Parameter_Type => | |
1483 | New_Reference_To (Etype (Formal), Loc), | |
1484 | Expression => New_Copy_Tree (Expression (Parent (Formal))))); | |
d62940bf | 1485 | |
aad6babd | 1486 | Next_Formal (Formal); |
1487 | end loop; | |
1488 | ||
17e14451 | 1489 | Controlling_Typ := Find_Dispatching_Type (Target); |
aad6babd | 1490 | |
725a69d2 | 1491 | Target_Formal := First_Formal (Target); |
1492 | Formal := First (Formals); | |
1493 | while Present (Formal) loop | |
1494 | if Ekind (Target_Formal) = E_In_Parameter | |
1495 | and then Ekind (Etype (Target_Formal)) = E_Anonymous_Access_Type | |
1496 | and then Directly_Designated_Type (Etype (Target_Formal)) | |
1497 | = Controlling_Typ | |
1498 | then | |
1499 | -- Generate: | |
aad6babd | 1500 | |
17e14451 | 1501 | -- type T is access all <<type of the target formal>> |
1502 | -- S : Storage_Offset := Storage_Offset!(Formal) | |
1503 | -- - Offset_To_Top (address!(Formal)) | |
725a69d2 | 1504 | |
1505 | Decl_2 := | |
1506 | Make_Full_Type_Declaration (Loc, | |
1507 | Defining_Identifier => | |
1508 | Make_Defining_Identifier (Loc, | |
1509 | New_Internal_Name ('T')), | |
1510 | Type_Definition => | |
1511 | Make_Access_To_Object_Definition (Loc, | |
1512 | All_Present => True, | |
1513 | Null_Exclusion_Present => False, | |
1514 | Constant_Present => False, | |
1515 | Subtype_Indication => | |
aad6babd | 1516 | New_Reference_To |
725a69d2 | 1517 | (Directly_Designated_Type |
1518 | (Etype (Target_Formal)), Loc))); | |
1519 | ||
cc60bd16 | 1520 | New_Arg := |
1521 | Unchecked_Convert_To (RTE (RE_Address), | |
1522 | New_Reference_To (Defining_Identifier (Formal), Loc)); | |
1523 | ||
1524 | if not RTE_Available (RE_Offset_To_Top) then | |
1525 | Offset_To_Top := | |
1526 | Build_Offset_To_Top (Loc, New_Arg); | |
1527 | else | |
1528 | Offset_To_Top := | |
1529 | Make_Function_Call (Loc, | |
1530 | Name => New_Reference_To (RTE (RE_Offset_To_Top), Loc), | |
1531 | Parameter_Associations => New_List (New_Arg)); | |
1532 | end if; | |
1533 | ||
725a69d2 | 1534 | Decl_1 := |
1535 | Make_Object_Declaration (Loc, | |
1536 | Defining_Identifier => | |
1537 | Make_Defining_Identifier (Loc, | |
1538 | New_Internal_Name ('S')), | |
1539 | Constant_Present => True, | |
1540 | Object_Definition => | |
1541 | New_Reference_To (RTE (RE_Storage_Offset), Loc), | |
1542 | Expression => | |
1543 | Make_Op_Subtract (Loc, | |
1544 | Left_Opnd => | |
1545 | Unchecked_Convert_To | |
1546 | (RTE (RE_Storage_Offset), | |
1547 | New_Reference_To (Defining_Identifier (Formal), Loc)), | |
1548 | Right_Opnd => | |
cc60bd16 | 1549 | Offset_To_Top)); |
725a69d2 | 1550 | |
1551 | Append_To (Decl, Decl_2); | |
1552 | Append_To (Decl, Decl_1); | |
1553 | ||
17e14451 | 1554 | -- Reference the new actual. Generate: |
1555 | -- T!(S) | |
725a69d2 | 1556 | |
1557 | Append_To (Actuals, | |
1558 | Unchecked_Convert_To | |
1559 | (Defining_Identifier (Decl_2), | |
1560 | New_Reference_To (Defining_Identifier (Decl_1), Loc))); | |
1561 | ||
1562 | elsif Etype (Target_Formal) = Controlling_Typ then | |
1563 | -- Generate: | |
aad6babd | 1564 | |
17e14451 | 1565 | -- S1 : Storage_Offset := Storage_Offset!(Formal'Address) |
1566 | -- - Offset_To_Top (Formal'Address) | |
1567 | -- S2 : Addr_Ptr := Addr_Ptr!(S1) | |
aad6babd | 1568 | |
cc60bd16 | 1569 | New_Arg := |
1570 | Make_Attribute_Reference (Loc, | |
1571 | Prefix => | |
1572 | New_Reference_To (Defining_Identifier (Formal), Loc), | |
1573 | Attribute_Name => | |
1574 | Name_Address); | |
1575 | ||
1576 | if not RTE_Available (RE_Offset_To_Top) then | |
1577 | Offset_To_Top := | |
1578 | Build_Offset_To_Top (Loc, New_Arg); | |
1579 | else | |
1580 | Offset_To_Top := | |
1581 | Make_Function_Call (Loc, | |
1582 | Name => New_Reference_To (RTE (RE_Offset_To_Top), Loc), | |
1583 | Parameter_Associations => New_List (New_Arg)); | |
1584 | end if; | |
1585 | ||
725a69d2 | 1586 | Decl_1 := |
1587 | Make_Object_Declaration (Loc, | |
1588 | Defining_Identifier => | |
1589 | Make_Defining_Identifier (Loc, New_Internal_Name ('S')), | |
1590 | Constant_Present => True, | |
1591 | Object_Definition => | |
1592 | New_Reference_To (RTE (RE_Storage_Offset), Loc), | |
1593 | Expression => | |
1594 | Make_Op_Subtract (Loc, | |
1595 | Left_Opnd => | |
1596 | Unchecked_Convert_To | |
1597 | (RTE (RE_Storage_Offset), | |
1598 | Make_Attribute_Reference (Loc, | |
1599 | Prefix => | |
1600 | New_Reference_To | |
1601 | (Defining_Identifier (Formal), Loc), | |
1602 | Attribute_Name => Name_Address)), | |
1603 | Right_Opnd => | |
cc60bd16 | 1604 | Offset_To_Top)); |
aad6babd | 1605 | |
725a69d2 | 1606 | Decl_2 := |
1607 | Make_Object_Declaration (Loc, | |
1608 | Defining_Identifier => | |
1609 | Make_Defining_Identifier (Loc, New_Internal_Name ('S')), | |
1610 | Constant_Present => True, | |
1611 | Object_Definition => New_Reference_To (RTE (RE_Addr_Ptr), Loc), | |
1612 | Expression => | |
1613 | Unchecked_Convert_To | |
1614 | (RTE (RE_Addr_Ptr), | |
1615 | New_Reference_To (Defining_Identifier (Decl_1), Loc))); | |
aad6babd | 1616 | |
725a69d2 | 1617 | Append_To (Decl, Decl_1); |
1618 | Append_To (Decl, Decl_2); | |
952af0b9 | 1619 | |
17e14451 | 1620 | -- Reference the new actual. Generate: |
1621 | -- Target_Formal (S2.all) | |
aad6babd | 1622 | |
725a69d2 | 1623 | Append_To (Actuals, |
1624 | Unchecked_Convert_To | |
17e14451 | 1625 | (Etype (Target_Formal), |
725a69d2 | 1626 | Make_Explicit_Dereference (Loc, |
1627 | New_Reference_To (Defining_Identifier (Decl_2), Loc)))); | |
aad6babd | 1628 | |
725a69d2 | 1629 | -- No special management required for this actual |
aad6babd | 1630 | |
725a69d2 | 1631 | else |
1632 | Append_To (Actuals, | |
1633 | New_Reference_To (Defining_Identifier (Formal), Loc)); | |
1634 | end if; | |
1635 | ||
1636 | Next_Formal (Target_Formal); | |
aad6babd | 1637 | Next (Formal); |
1638 | end loop; | |
1639 | ||
725a69d2 | 1640 | Thunk_Id := |
1641 | Make_Defining_Identifier (Loc, | |
1642 | Chars => New_Internal_Name ('T')); | |
1643 | ||
e7e688dd | 1644 | Set_Is_Thunk (Thunk_Id); |
1645 | ||
d62940bf | 1646 | if Ekind (Target) = E_Procedure then |
725a69d2 | 1647 | Thunk_Code := |
aad6babd | 1648 | Make_Subprogram_Body (Loc, |
1649 | Specification => | |
1650 | Make_Procedure_Specification (Loc, | |
1651 | Defining_Unit_Name => Thunk_Id, | |
1652 | Parameter_Specifications => Formals), | |
1653 | Declarations => Decl, | |
1654 | Handled_Statement_Sequence => | |
1655 | Make_Handled_Sequence_Of_Statements (Loc, | |
1656 | Statements => New_List ( | |
1657 | Make_Procedure_Call_Statement (Loc, | |
725a69d2 | 1658 | Name => New_Occurrence_Of (Target, Loc), |
1659 | Parameter_Associations => Actuals)))); | |
aad6babd | 1660 | |
d62940bf | 1661 | else pragma Assert (Ekind (Target) = E_Function); |
aad6babd | 1662 | |
725a69d2 | 1663 | Thunk_Code := |
aad6babd | 1664 | Make_Subprogram_Body (Loc, |
1665 | Specification => | |
1666 | Make_Function_Specification (Loc, | |
1667 | Defining_Unit_Name => Thunk_Id, | |
1668 | Parameter_Specifications => Formals, | |
d62940bf | 1669 | Result_Definition => |
1670 | New_Copy (Result_Definition (Parent (Target)))), | |
aad6babd | 1671 | Declarations => Decl, |
1672 | Handled_Statement_Sequence => | |
1673 | Make_Handled_Sequence_Of_Statements (Loc, | |
1674 | Statements => New_List ( | |
17e14451 | 1675 | Make_Simple_Return_Statement (Loc, |
aad6babd | 1676 | Make_Function_Call (Loc, |
1677 | Name => New_Occurrence_Of (Target, Loc), | |
1678 | Parameter_Associations => Actuals))))); | |
1679 | end if; | |
aad6babd | 1680 | end Expand_Interface_Thunk; |
1681 | ||
d215f619 | 1682 | -------------------- |
1683 | -- Find_SCIL_Node -- | |
1684 | -------------------- | |
1685 | ||
1686 | function Find_SCIL_Node (Node : Node_Id) return Node_Id is | |
1687 | Found_Node : Node_Id; | |
1688 | -- This variable stores the last node found by the nested subprogram | |
1689 | -- Find_SCIL_Node. | |
1690 | ||
1691 | function Find_SCIL_Node (L : List_Id) return Boolean; | |
1692 | -- Searches in list L for a SCIL node associated with a dispatching call | |
1693 | -- whose SCIL_Related_Node is Node. If found returns true and stores the | |
1694 | -- SCIL node in Found_Node; otherwise returns False and sets Found_Node | |
1695 | -- to Empty. | |
1696 | ||
1697 | function Find_SCIL_Node (L : List_Id) return Boolean is | |
1698 | N : Node_Id; | |
1699 | ||
1700 | begin | |
1701 | N := First (L); | |
1702 | while Present (N) loop | |
1703 | if Nkind (N) in N_SCIL_Node | |
1704 | and then SCIL_Related_Node (N) = Node | |
1705 | then | |
1706 | Found_Node := N; | |
1707 | return True; | |
1708 | end if; | |
1709 | ||
1710 | Next (N); | |
1711 | end loop; | |
1712 | ||
1713 | Found_Node := Empty; | |
1714 | return False; | |
1715 | end Find_SCIL_Node; | |
1716 | ||
1717 | -- Local variables | |
1718 | ||
1719 | P : Node_Id; | |
1720 | ||
1721 | -- Start of processing for Find_SCIL_Node | |
3dbca0d5 | 1722 | |
3dbca0d5 | 1723 | begin |
d215f619 | 1724 | pragma Assert (Generate_SCIL); |
1725 | ||
1726 | -- Search for the SCIL node in the list associated with a transient | |
1727 | -- scope | |
1728 | ||
1729 | if Scope_Is_Transient then | |
1730 | declare | |
1731 | SE : Scope_Stack_Entry | |
1732 | renames Scope_Stack.Table (Scope_Stack.Last); | |
1733 | begin | |
1734 | if SE.Is_Transient | |
1735 | and then Present (SE.Actions_To_Be_Wrapped_Before) | |
1736 | and then Find_SCIL_Node (SE.Actions_To_Be_Wrapped_Before) | |
1737 | then | |
1738 | return Found_Node; | |
1739 | end if; | |
1740 | end; | |
1741 | end if; | |
1742 | ||
1743 | -- Otherwise climb up the tree searching for the SCIL node analyzing | |
1744 | -- all the lists in which Insert_Actions may have inserted it | |
1745 | ||
1746 | P := Node; | |
1747 | while Present (P) loop | |
1748 | case Nkind (P) is | |
1749 | ||
1750 | -- Actions associated with AND THEN or OR ELSE | |
1751 | ||
1752 | when N_Short_Circuit => | |
1753 | if Present (Actions (P)) | |
1754 | and then Find_SCIL_Node (Actions (P)) | |
1755 | then | |
1756 | return Found_Node; | |
1757 | end if; | |
1758 | ||
1759 | -- Actions of conditional expressions | |
1760 | ||
1761 | when N_Conditional_Expression => | |
1762 | if (Present (Then_Actions (P)) | |
1763 | and then Find_SCIL_Node (Actions (P))) | |
1764 | or else | |
1765 | (Present (Else_Actions (P)) | |
1766 | and then Find_SCIL_Node (Else_Actions (P))) | |
1767 | then | |
1768 | return Found_Node; | |
1769 | end if; | |
1770 | ||
1771 | -- Conditions of while expression or elsif. | |
1772 | ||
1773 | when N_Iteration_Scheme | | |
1774 | N_Elsif_Part | |
1775 | => | |
1776 | if Present (Condition_Actions (P)) | |
1777 | and then Find_SCIL_Node (Condition_Actions (P)) | |
1778 | then | |
1779 | return Found_Node; | |
1780 | end if; | |
1781 | ||
1782 | -- Statements, declarations, pragmas, representation clauses | |
1783 | ||
1784 | when | |
1785 | -- Statements | |
1786 | ||
1787 | N_Procedure_Call_Statement | | |
1788 | N_Statement_Other_Than_Procedure_Call | | |
1789 | ||
1790 | -- Pragmas | |
1791 | ||
1792 | N_Pragma | | |
1793 | ||
1794 | -- Representation_Clause | |
1795 | ||
1796 | N_At_Clause | | |
1797 | N_Attribute_Definition_Clause | | |
1798 | N_Enumeration_Representation_Clause | | |
1799 | N_Record_Representation_Clause | | |
1800 | ||
1801 | -- Declarations | |
1802 | ||
1803 | N_Abstract_Subprogram_Declaration | | |
1804 | N_Entry_Body | | |
1805 | N_Exception_Declaration | | |
1806 | N_Exception_Renaming_Declaration | | |
1807 | N_Formal_Abstract_Subprogram_Declaration | | |
1808 | N_Formal_Concrete_Subprogram_Declaration | | |
1809 | N_Formal_Object_Declaration | | |
1810 | N_Formal_Type_Declaration | | |
1811 | N_Full_Type_Declaration | | |
1812 | N_Function_Instantiation | | |
1813 | N_Generic_Function_Renaming_Declaration | | |
1814 | N_Generic_Package_Declaration | | |
1815 | N_Generic_Package_Renaming_Declaration | | |
1816 | N_Generic_Procedure_Renaming_Declaration | | |
1817 | N_Generic_Subprogram_Declaration | | |
1818 | N_Implicit_Label_Declaration | | |
1819 | N_Incomplete_Type_Declaration | | |
1820 | N_Number_Declaration | | |
1821 | N_Object_Declaration | | |
1822 | N_Object_Renaming_Declaration | | |
1823 | N_Package_Body | | |
1824 | N_Package_Body_Stub | | |
1825 | N_Package_Declaration | | |
1826 | N_Package_Instantiation | | |
1827 | N_Package_Renaming_Declaration | | |
1828 | N_Private_Extension_Declaration | | |
1829 | N_Private_Type_Declaration | | |
1830 | N_Procedure_Instantiation | | |
1831 | N_Protected_Body | | |
1832 | N_Protected_Body_Stub | | |
1833 | N_Protected_Type_Declaration | | |
1834 | N_Single_Task_Declaration | | |
1835 | N_Subprogram_Body | | |
1836 | N_Subprogram_Body_Stub | | |
1837 | N_Subprogram_Declaration | | |
1838 | N_Subprogram_Renaming_Declaration | | |
1839 | N_Subtype_Declaration | | |
1840 | N_Task_Body | | |
1841 | N_Task_Body_Stub | | |
1842 | N_Task_Type_Declaration | | |
1843 | ||
1844 | -- Freeze entity behaves like a declaration or statement | |
1845 | ||
1846 | N_Freeze_Entity | |
1847 | => | |
1848 | -- Do not search here if the item is not a list member | |
1849 | ||
1850 | if not Is_List_Member (P) then | |
1851 | null; | |
1852 | ||
1853 | -- Do not search if parent of P is an N_Component_Association | |
1854 | -- node (i.e. we are in the context of an N_Aggregate or | |
1855 | -- N_Extension_Aggregate node). In this case the node should | |
1856 | -- have been added before the entire aggregate. | |
1857 | ||
1858 | elsif Nkind (Parent (P)) = N_Component_Association then | |
1859 | null; | |
1860 | ||
1861 | -- Do not search if the parent of P is either an N_Variant | |
1862 | -- node or an N_Record_Definition node. In this case the node | |
1863 | -- should have been added before the entire record. | |
1864 | ||
1865 | elsif Nkind (Parent (P)) = N_Variant | |
1866 | or else Nkind (Parent (P)) = N_Record_Definition | |
1867 | then | |
1868 | null; | |
1869 | ||
1870 | -- Otherwise search it in the list containing this node | |
1871 | ||
1872 | elsif Find_SCIL_Node (List_Containing (P)) then | |
1873 | return Found_Node; | |
1874 | end if; | |
1875 | ||
1876 | -- A special case, N_Raise_xxx_Error can act either as a | |
1877 | -- statement or a subexpression. We diferentiate them by | |
1878 | -- looking at the Etype. It is set to Standard_Void_Type | |
1879 | -- in the statement case. | |
1880 | ||
1881 | when | |
1882 | N_Raise_xxx_Error => | |
1883 | if Etype (P) = Standard_Void_Type then | |
1884 | if Is_List_Member (P) | |
1885 | and then Find_SCIL_Node (List_Containing (P)) | |
1886 | then | |
1887 | return Found_Node; | |
1888 | end if; | |
1889 | ||
1890 | -- In the subexpression case, keep climbing | |
1891 | ||
1892 | else | |
1893 | null; | |
1894 | end if; | |
1895 | ||
1896 | -- If a component association appears within a loop created for | |
1897 | -- an array aggregate, check if the SCIL node was added to the | |
1898 | -- the list of nodes attached to the association. | |
1899 | ||
1900 | when | |
1901 | N_Component_Association => | |
1902 | if Nkind (Parent (P)) = N_Aggregate | |
1903 | and then Present (Loop_Actions (P)) | |
1904 | and then Find_SCIL_Node (Loop_Actions (P)) | |
1905 | then | |
1906 | return Found_Node; | |
1907 | end if; | |
1908 | ||
1909 | -- Another special case, an attribute denoting a procedure call | |
1910 | ||
1911 | when | |
1912 | N_Attribute_Reference => | |
1913 | if Is_Procedure_Attribute_Name (Attribute_Name (P)) | |
1914 | and then Find_SCIL_Node (List_Containing (P)) | |
1915 | then | |
1916 | return Found_Node; | |
1917 | ||
1918 | -- In the subexpression case, keep climbing | |
1919 | ||
1920 | else | |
1921 | null; | |
1922 | end if; | |
1923 | ||
1924 | -- SCIL nodes do not have subtrees and hence they can never be | |
1925 | -- found climbing tree | |
1926 | ||
1927 | when | |
1928 | N_SCIL_Dispatch_Table_Object_Init | | |
1929 | N_SCIL_Dispatch_Table_Tag_Init | | |
1930 | N_SCIL_Dispatching_Call | | |
1931 | N_SCIL_Tag_Init | |
1932 | => | |
1933 | pragma Assert (False); | |
1934 | raise Program_Error; | |
1935 | ||
1936 | -- For all other node types, keep climbing tree | |
1937 | ||
1938 | when | |
1939 | N_Abortable_Part | | |
1940 | N_Accept_Alternative | | |
1941 | N_Access_Definition | | |
1942 | N_Access_Function_Definition | | |
1943 | N_Access_Procedure_Definition | | |
1944 | N_Access_To_Object_Definition | | |
1945 | N_Aggregate | | |
1946 | N_Allocator | | |
1947 | N_Case_Statement_Alternative | | |
1948 | N_Character_Literal | | |
1949 | N_Compilation_Unit | | |
1950 | N_Compilation_Unit_Aux | | |
1951 | N_Component_Clause | | |
1952 | N_Component_Declaration | | |
1953 | N_Component_Definition | | |
1954 | N_Component_List | | |
1955 | N_Constrained_Array_Definition | | |
1956 | N_Decimal_Fixed_Point_Definition | | |
1957 | N_Defining_Character_Literal | | |
1958 | N_Defining_Identifier | | |
1959 | N_Defining_Operator_Symbol | | |
1960 | N_Defining_Program_Unit_Name | | |
1961 | N_Delay_Alternative | | |
1962 | N_Delta_Constraint | | |
1963 | N_Derived_Type_Definition | | |
1964 | N_Designator | | |
1965 | N_Digits_Constraint | | |
1966 | N_Discriminant_Association | | |
1967 | N_Discriminant_Specification | | |
1968 | N_Empty | | |
1969 | N_Entry_Body_Formal_Part | | |
1970 | N_Entry_Call_Alternative | | |
1971 | N_Entry_Declaration | | |
1972 | N_Entry_Index_Specification | | |
1973 | N_Enumeration_Type_Definition | | |
1974 | N_Error | | |
1975 | N_Exception_Handler | | |
1976 | N_Expanded_Name | | |
1977 | N_Explicit_Dereference | | |
1978 | N_Extension_Aggregate | | |
1979 | N_Floating_Point_Definition | | |
1980 | N_Formal_Decimal_Fixed_Point_Definition | | |
1981 | N_Formal_Derived_Type_Definition | | |
1982 | N_Formal_Discrete_Type_Definition | | |
1983 | N_Formal_Floating_Point_Definition | | |
1984 | N_Formal_Modular_Type_Definition | | |
1985 | N_Formal_Ordinary_Fixed_Point_Definition | | |
1986 | N_Formal_Package_Declaration | | |
1987 | N_Formal_Private_Type_Definition | | |
1988 | N_Formal_Signed_Integer_Type_Definition | | |
1989 | N_Function_Call | | |
1990 | N_Function_Specification | | |
1991 | N_Generic_Association | | |
1992 | N_Handled_Sequence_Of_Statements | | |
1993 | N_Identifier | | |
1994 | N_In | | |
1995 | N_Index_Or_Discriminant_Constraint | | |
1996 | N_Indexed_Component | | |
1997 | N_Integer_Literal | | |
1998 | N_Itype_Reference | | |
1999 | N_Label | | |
2000 | N_Loop_Parameter_Specification | | |
2001 | N_Mod_Clause | | |
2002 | N_Modular_Type_Definition | | |
2003 | N_Not_In | | |
2004 | N_Null | | |
2005 | N_Op_Abs | | |
2006 | N_Op_Add | | |
2007 | N_Op_And | | |
2008 | N_Op_Concat | | |
2009 | N_Op_Divide | | |
2010 | N_Op_Eq | | |
2011 | N_Op_Expon | | |
2012 | N_Op_Ge | | |
2013 | N_Op_Gt | | |
2014 | N_Op_Le | | |
2015 | N_Op_Lt | | |
2016 | N_Op_Minus | | |
2017 | N_Op_Mod | | |
2018 | N_Op_Multiply | | |
2019 | N_Op_Ne | | |
2020 | N_Op_Not | | |
2021 | N_Op_Or | | |
2022 | N_Op_Plus | | |
2023 | N_Op_Rem | | |
2024 | N_Op_Rotate_Left | | |
2025 | N_Op_Rotate_Right | | |
2026 | N_Op_Shift_Left | | |
2027 | N_Op_Shift_Right | | |
2028 | N_Op_Shift_Right_Arithmetic | | |
2029 | N_Op_Subtract | | |
2030 | N_Op_Xor | | |
2031 | N_Operator_Symbol | | |
2032 | N_Ordinary_Fixed_Point_Definition | | |
2033 | N_Others_Choice | | |
2034 | N_Package_Specification | | |
2035 | N_Parameter_Association | | |
2036 | N_Parameter_Specification | | |
2037 | N_Pop_Constraint_Error_Label | | |
2038 | N_Pop_Program_Error_Label | | |
2039 | N_Pop_Storage_Error_Label | | |
2040 | N_Pragma_Argument_Association | | |
2041 | N_Procedure_Specification | | |
2042 | N_Protected_Definition | | |
2043 | N_Push_Constraint_Error_Label | | |
2044 | N_Push_Program_Error_Label | | |
2045 | N_Push_Storage_Error_Label | | |
2046 | N_Qualified_Expression | | |
2047 | N_Range | | |
2048 | N_Range_Constraint | | |
2049 | N_Real_Literal | | |
2050 | N_Real_Range_Specification | | |
2051 | N_Record_Definition | | |
2052 | N_Reference | | |
2053 | N_Selected_Component | | |
2054 | N_Signed_Integer_Type_Definition | | |
2055 | N_Single_Protected_Declaration | | |
2056 | N_Slice | | |
2057 | N_String_Literal | | |
2058 | N_Subprogram_Info | | |
2059 | N_Subtype_Indication | | |
2060 | N_Subunit | | |
2061 | N_Task_Definition | | |
2062 | N_Terminate_Alternative | | |
2063 | N_Triggering_Alternative | | |
2064 | N_Type_Conversion | | |
2065 | N_Unchecked_Expression | | |
2066 | N_Unchecked_Type_Conversion | | |
2067 | N_Unconstrained_Array_Definition | | |
2068 | N_Unused_At_End | | |
2069 | N_Unused_At_Start | | |
2070 | N_Use_Package_Clause | | |
2071 | N_Use_Type_Clause | | |
2072 | N_Variant | | |
2073 | N_Variant_Part | | |
2074 | N_Validate_Unchecked_Conversion | | |
2075 | N_With_Clause | |
2076 | => | |
2077 | null; | |
2078 | ||
2079 | end case; | |
2080 | ||
2081 | -- If we fall through above tests, keep climbing tree | |
2082 | ||
2083 | if Nkind (Parent (P)) = N_Subunit then | |
2084 | ||
2085 | -- This is the proper body corresponding to a stub. Insertion | |
2086 | -- done at the point of the stub, which is in the declarative | |
2087 | -- part of the parent unit. | |
2088 | ||
2089 | P := Corresponding_Stub (Parent (P)); | |
2090 | ||
2091 | else | |
2092 | P := Parent (P); | |
2093 | end if; | |
2094 | end loop; | |
2095 | ||
2096 | -- SCIL node not found | |
2097 | ||
2098 | return Empty; | |
2099 | end Find_SCIL_Node; | |
3dbca0d5 | 2100 | |
24971415 | 2101 | ------------ |
2102 | -- Has_DT -- | |
2103 | ------------ | |
2104 | ||
2105 | function Has_DT (Typ : Entity_Id) return Boolean is | |
2106 | begin | |
2107 | return not Is_Interface (Typ) | |
2108 | and then not Restriction_Active (No_Dispatching_Calls); | |
2109 | end Has_DT; | |
2110 | ||
a652dd51 | 2111 | ----------------------------------------- |
2112 | -- Is_Predefined_Dispatching_Operation -- | |
2113 | ----------------------------------------- | |
2114 | ||
2115 | function Is_Predefined_Dispatching_Operation | |
2116 | (E : Entity_Id) return Boolean | |
2117 | is | |
2118 | TSS_Name : TSS_Name_Type; | |
2119 | ||
2120 | begin | |
2121 | if not Is_Dispatching_Operation (E) then | |
2122 | return False; | |
2123 | end if; | |
2124 | ||
2125 | Get_Name_String (Chars (E)); | |
2126 | ||
2127 | -- Most predefined primitives have internally generated names. Equality | |
2128 | -- must be treated differently; the predefined operation is recognized | |
2129 | -- as a homogeneous binary operator that returns Boolean. | |
2130 | ||
2131 | if Name_Len > TSS_Name_Type'Last then | |
2132 | TSS_Name := TSS_Name_Type (Name_Buffer (Name_Len - TSS_Name'Length + 1 | |
2133 | .. Name_Len)); | |
2134 | if Chars (E) = Name_uSize | |
2135 | or else Chars (E) = Name_uAlignment | |
2136 | or else TSS_Name = TSS_Stream_Read | |
2137 | or else TSS_Name = TSS_Stream_Write | |
2138 | or else TSS_Name = TSS_Stream_Input | |
2139 | or else TSS_Name = TSS_Stream_Output | |
2140 | or else | |
2141 | (Chars (E) = Name_Op_Eq | |
2142 | and then Etype (First_Entity (E)) = Etype (Last_Entity (E))) | |
2143 | or else Chars (E) = Name_uAssign | |
2144 | or else TSS_Name = TSS_Deep_Adjust | |
2145 | or else TSS_Name = TSS_Deep_Finalize | |
2146 | or else Is_Predefined_Interface_Primitive (E) | |
2147 | then | |
2148 | return True; | |
2149 | end if; | |
2150 | end if; | |
2151 | ||
2152 | return False; | |
2153 | end Is_Predefined_Dispatching_Operation; | |
2154 | ||
af647dc7 | 2155 | ------------------------------------- |
2156 | -- Is_Predefined_Dispatching_Alias -- | |
2157 | ------------------------------------- | |
2158 | ||
2159 | function Is_Predefined_Dispatching_Alias (Prim : Entity_Id) return Boolean | |
2160 | is | |
2161 | E : Entity_Id; | |
2162 | ||
2163 | begin | |
2164 | if not Is_Predefined_Dispatching_Operation (Prim) | |
2165 | and then Present (Alias (Prim)) | |
2166 | then | |
2167 | E := Prim; | |
2168 | while Present (Alias (E)) loop | |
2169 | E := Alias (E); | |
2170 | end loop; | |
2171 | ||
2172 | if Is_Predefined_Dispatching_Operation (E) then | |
2173 | return True; | |
2174 | end if; | |
2175 | end if; | |
2176 | ||
2177 | return False; | |
2178 | end Is_Predefined_Dispatching_Alias; | |
2179 | ||
a652dd51 | 2180 | --------------------------------------- |
2181 | -- Is_Predefined_Interface_Primitive -- | |
2182 | --------------------------------------- | |
2183 | ||
2184 | function Is_Predefined_Interface_Primitive (E : Entity_Id) return Boolean is | |
2185 | begin | |
2186 | return Ada_Version >= Ada_05 | |
2187 | and then (Chars (E) = Name_uDisp_Asynchronous_Select or else | |
2188 | Chars (E) = Name_uDisp_Conditional_Select or else | |
2189 | Chars (E) = Name_uDisp_Get_Prim_Op_Kind or else | |
2190 | Chars (E) = Name_uDisp_Get_Task_Id or else | |
2191 | Chars (E) = Name_uDisp_Requeue or else | |
2192 | Chars (E) = Name_uDisp_Timed_Select); | |
2193 | end Is_Predefined_Interface_Primitive; | |
2194 | ||
76a1c25b | 2195 | ---------------------------------------- |
2196 | -- Make_Disp_Asynchronous_Select_Body -- | |
2197 | ---------------------------------------- | |
ee6ba406 | 2198 | |
cdb1c38f | 2199 | -- For interface types, generate: |
2200 | ||
2201 | -- procedure _Disp_Asynchronous_Select | |
2202 | -- (T : in out <Typ>; | |
2203 | -- S : Integer; | |
2204 | -- P : System.Address; | |
2205 | -- B : out System.Storage_Elements.Dummy_Communication_Block; | |
2206 | -- F : out Boolean) | |
2207 | -- is | |
2208 | -- begin | |
2209 | -- null; | |
2210 | -- end _Disp_Asynchronous_Select; | |
2211 | ||
2212 | -- For protected types, generate: | |
2213 | ||
2214 | -- procedure _Disp_Asynchronous_Select | |
2215 | -- (T : in out <Typ>; | |
2216 | -- S : Integer; | |
2217 | -- P : System.Address; | |
2218 | -- B : out System.Storage_Elements.Dummy_Communication_Block; | |
2219 | -- F : out Boolean) | |
2220 | -- is | |
2221 | -- I : Integer := | |
2222 | -- Ada.Tags.Get_Entry_Index (Ada.Tags.Tag (<Typ>VP, S)); | |
2223 | -- Bnn : System.Tasking.Protected_Objects.Operations. | |
2224 | -- Communication_Block; | |
2225 | -- begin | |
2226 | -- System.Tasking.Protected_Objects.Operations.Protected_Entry_Call | |
2227 | -- (T._object'Access, | |
2228 | -- System.Tasking.Protected_Objects.Protected_Entry_Index (I), | |
2229 | -- P, | |
2230 | -- System.Tasking.Asynchronous_Call, | |
2231 | -- Bnn); | |
2232 | -- B := System.Storage_Elements.Dummy_Communication_Block (Bnn); | |
2233 | -- end _Disp_Asynchronous_Select; | |
2234 | ||
2235 | -- For task types, generate: | |
2236 | ||
2237 | -- procedure _Disp_Asynchronous_Select | |
2238 | -- (T : in out <Typ>; | |
2239 | -- S : Integer; | |
2240 | -- P : System.Address; | |
2241 | -- B : out System.Storage_Elements.Dummy_Communication_Block; | |
2242 | -- F : out Boolean) | |
2243 | -- is | |
2244 | -- I : Integer := | |
2245 | -- Ada.Tags.Get_Entry_Index (Ada.Tags.Tag (<Typ>VP, S)); | |
2246 | -- begin | |
2247 | -- System.Tasking.Rendezvous.Task_Entry_Call | |
2248 | -- (T._task_id, | |
2249 | -- System.Tasking.Task_Entry_Index (I), | |
2250 | -- P, | |
2251 | -- System.Tasking.Asynchronous_Call, | |
2252 | -- F); | |
2253 | -- end _Disp_Asynchronous_Select; | |
2254 | ||
76a1c25b | 2255 | function Make_Disp_Asynchronous_Select_Body |
2256 | (Typ : Entity_Id) return Node_Id | |
2257 | is | |
725a69d2 | 2258 | Com_Block : Entity_Id; |
2259 | Conc_Typ : Entity_Id := Empty; | |
2260 | Decls : constant List_Id := New_List; | |
2261 | DT_Ptr : Entity_Id; | |
2262 | Loc : constant Source_Ptr := Sloc (Typ); | |
acf97c11 | 2263 | Obj_Ref : Node_Id; |
725a69d2 | 2264 | Stmts : constant List_Id := New_List; |
ee6ba406 | 2265 | |
2266 | begin | |
68f95949 | 2267 | pragma Assert (not Restriction_Active (No_Dispatching_Calls)); |
2268 | ||
952af0b9 | 2269 | -- Null body is generated for interface types |
2270 | ||
76a1c25b | 2271 | if Is_Interface (Typ) then |
2272 | return | |
2273 | Make_Subprogram_Body (Loc, | |
2274 | Specification => | |
2275 | Make_Disp_Asynchronous_Select_Spec (Typ), | |
2276 | Declarations => | |
2277 | New_List, | |
2278 | Handled_Statement_Sequence => | |
2279 | Make_Handled_Sequence_Of_Statements (Loc, | |
2280 | New_List (Make_Null_Statement (Loc)))); | |
9dfe12ae | 2281 | end if; |
2282 | ||
76a1c25b | 2283 | DT_Ptr := Node (First_Elmt (Access_Disp_Table (Typ))); |
aad6babd | 2284 | |
952af0b9 | 2285 | if Is_Concurrent_Record_Type (Typ) then |
2286 | Conc_Typ := Corresponding_Concurrent_Type (Typ); | |
aad6babd | 2287 | |
76a1c25b | 2288 | -- Generate: |
cdb1c38f | 2289 | -- I : Integer := |
2290 | -- Ada.Tags.Get_Entry_Index (Ada.Tags.Tag! (<type>VP), S); | |
aad6babd | 2291 | |
76a1c25b | 2292 | -- where I will be used to capture the entry index of the primitive |
2293 | -- wrapper at position S. | |
aad6babd | 2294 | |
76a1c25b | 2295 | Append_To (Decls, |
2296 | Make_Object_Declaration (Loc, | |
2297 | Defining_Identifier => | |
2298 | Make_Defining_Identifier (Loc, Name_uI), | |
2299 | Object_Definition => | |
2300 | New_Reference_To (Standard_Integer, Loc), | |
2301 | Expression => | |
725a69d2 | 2302 | Make_Function_Call (Loc, |
cdb1c38f | 2303 | Name => |
2304 | New_Reference_To (RTE (RE_Get_Entry_Index), Loc), | |
2305 | Parameter_Associations => | |
2306 | New_List ( | |
2307 | Unchecked_Convert_To (RTE (RE_Tag), | |
2308 | New_Reference_To (DT_Ptr, Loc)), | |
2309 | Make_Identifier (Loc, Name_uS))))); | |
aad6babd | 2310 | |
76a1c25b | 2311 | if Ekind (Conc_Typ) = E_Protected_Type then |
aad6babd | 2312 | |
725a69d2 | 2313 | -- Generate: |
cdb1c38f | 2314 | -- Bnn : Communication_Block; |
725a69d2 | 2315 | |
2316 | Com_Block := | |
2317 | Make_Defining_Identifier (Loc, New_Internal_Name ('B')); | |
2318 | ||
2319 | Append_To (Decls, | |
2320 | Make_Object_Declaration (Loc, | |
2321 | Defining_Identifier => | |
2322 | Com_Block, | |
2323 | Object_Definition => | |
2324 | New_Reference_To (RTE (RE_Communication_Block), Loc))); | |
2325 | ||
acf97c11 | 2326 | -- Build T._object'Access for calls below |
aad6babd | 2327 | |
acf97c11 | 2328 | Obj_Ref := |
2329 | Make_Attribute_Reference (Loc, | |
2330 | Attribute_Name => Name_Unchecked_Access, | |
2331 | Prefix => | |
2332 | Make_Selected_Component (Loc, | |
2333 | Prefix => Make_Identifier (Loc, Name_uT), | |
2334 | Selector_Name => Make_Identifier (Loc, Name_uObject))); | |
aad6babd | 2335 | |
acf97c11 | 2336 | case Corresponding_Runtime_Package (Conc_Typ) is |
2337 | when System_Tasking_Protected_Objects_Entries => | |
aad6babd | 2338 | |
acf97c11 | 2339 | -- Generate: |
2340 | -- Protected_Entry_Call | |
2341 | -- (T._object'Access, -- Object | |
2342 | -- Protected_Entry_Index! (I), -- E | |
2343 | -- P, -- Uninterpreted_Data | |
2344 | -- Asynchronous_Call, -- Mode | |
2345 | -- Bnn); -- Communication_Block | |
2346 | ||
2347 | -- where T is the protected object, I is the entry index, P | |
2348 | -- is the wrapped parameters and B is the name of the | |
2349 | -- communication block. | |
2350 | ||
2351 | Append_To (Stmts, | |
2352 | Make_Procedure_Call_Statement (Loc, | |
2353 | Name => | |
2354 | New_Reference_To (RTE (RE_Protected_Entry_Call), Loc), | |
2355 | Parameter_Associations => | |
2356 | New_List ( | |
2357 | Obj_Ref, | |
aad6babd | 2358 | |
acf97c11 | 2359 | Make_Unchecked_Type_Conversion (Loc, -- entry index |
2360 | Subtype_Mark => | |
2361 | New_Reference_To | |
2362 | (RTE (RE_Protected_Entry_Index), Loc), | |
2363 | Expression => Make_Identifier (Loc, Name_uI)), | |
d62940bf | 2364 | |
acf97c11 | 2365 | Make_Identifier (Loc, Name_uP), -- parameter block |
2366 | New_Reference_To ( -- Asynchronous_Call | |
2367 | RTE (RE_Asynchronous_Call), Loc), | |
2368 | ||
2369 | New_Reference_To (Com_Block, Loc)))); -- comm block | |
2370 | ||
2371 | when System_Tasking_Protected_Objects_Single_Entry => | |
2372 | ||
2373 | -- Generate: | |
2374 | -- procedure Protected_Single_Entry_Call | |
2375 | -- (Object : Protection_Entry_Access; | |
2376 | -- Uninterpreted_Data : System.Address; | |
2377 | -- Mode : Call_Modes); | |
725a69d2 | 2378 | |
acf97c11 | 2379 | Append_To (Stmts, |
2380 | Make_Procedure_Call_Statement (Loc, | |
2381 | Name => | |
2382 | New_Reference_To | |
2383 | (RTE (RE_Protected_Single_Entry_Call), Loc), | |
2384 | Parameter_Associations => | |
2385 | New_List ( | |
2386 | Obj_Ref, | |
2387 | ||
2388 | Make_Attribute_Reference (Loc, | |
2389 | Prefix => Make_Identifier (Loc, Name_uP), | |
2390 | Attribute_Name => Name_Address), | |
2391 | ||
2392 | New_Reference_To | |
2393 | (RTE (RE_Asynchronous_Call), Loc)))); | |
2394 | ||
2395 | when others => | |
2396 | raise Program_Error; | |
2397 | end case; | |
725a69d2 | 2398 | |
2399 | -- Generate: | |
cdb1c38f | 2400 | -- B := Dummy_Communication_Block (Bnn); |
725a69d2 | 2401 | |
2402 | Append_To (Stmts, | |
2403 | Make_Assignment_Statement (Loc, | |
2404 | Name => | |
2405 | Make_Identifier (Loc, Name_uB), | |
2406 | Expression => | |
2407 | Make_Unchecked_Type_Conversion (Loc, | |
2408 | Subtype_Mark => | |
2409 | New_Reference_To ( | |
2410 | RTE (RE_Dummy_Communication_Block), Loc), | |
2411 | Expression => | |
2412 | New_Reference_To (Com_Block, Loc)))); | |
2413 | ||
76a1c25b | 2414 | else |
2415 | pragma Assert (Ekind (Conc_Typ) = E_Task_Type); | |
d62940bf | 2416 | |
76a1c25b | 2417 | -- Generate: |
cdb1c38f | 2418 | -- Task_Entry_Call |
2419 | -- (T._task_id, -- Acceptor | |
2420 | -- Task_Entry_Index! (I), -- E | |
2421 | -- P, -- Uninterpreted_Data | |
2422 | -- Asynchronous_Call, -- Mode | |
2423 | -- F); -- Rendezvous_Successful | |
ee6ba406 | 2424 | |
acf97c11 | 2425 | -- where T is the task object, I is the entry index, P is the |
76a1c25b | 2426 | -- wrapped parameters and F is the status flag. |
ee6ba406 | 2427 | |
76a1c25b | 2428 | Append_To (Stmts, |
2429 | Make_Procedure_Call_Statement (Loc, | |
2430 | Name => | |
2431 | New_Reference_To (RTE (RE_Task_Entry_Call), Loc), | |
2432 | Parameter_Associations => | |
2433 | New_List ( | |
76a1c25b | 2434 | Make_Selected_Component (Loc, -- T._task_id |
2435 | Prefix => | |
2436 | Make_Identifier (Loc, Name_uT), | |
2437 | Selector_Name => | |
2438 | Make_Identifier (Loc, Name_uTask_Id)), | |
ee6ba406 | 2439 | |
76a1c25b | 2440 | Make_Unchecked_Type_Conversion (Loc, -- entry index |
2441 | Subtype_Mark => | |
2442 | New_Reference_To (RTE (RE_Task_Entry_Index), Loc), | |
2443 | Expression => | |
2444 | Make_Identifier (Loc, Name_uI)), | |
ee6ba406 | 2445 | |
76a1c25b | 2446 | Make_Identifier (Loc, Name_uP), -- parameter block |
2447 | New_Reference_To ( -- Asynchronous_Call | |
2448 | RTE (RE_Asynchronous_Call), Loc), | |
2449 | Make_Identifier (Loc, Name_uF)))); -- status flag | |
2450 | end if; | |
7c949aad | 2451 | |
2452 | else | |
2453 | -- Ensure that the statements list is non-empty | |
2454 | ||
2455 | Append_To (Stmts, Make_Null_Statement (Loc)); | |
76a1c25b | 2456 | end if; |
ee6ba406 | 2457 | |
76a1c25b | 2458 | return |
2459 | Make_Subprogram_Body (Loc, | |
2460 | Specification => | |
2461 | Make_Disp_Asynchronous_Select_Spec (Typ), | |
2462 | Declarations => | |
2463 | Decls, | |
2464 | Handled_Statement_Sequence => | |
2465 | Make_Handled_Sequence_Of_Statements (Loc, Stmts)); | |
2466 | end Make_Disp_Asynchronous_Select_Body; | |
ee6ba406 | 2467 | |
76a1c25b | 2468 | ---------------------------------------- |
2469 | -- Make_Disp_Asynchronous_Select_Spec -- | |
2470 | ---------------------------------------- | |
ee6ba406 | 2471 | |
76a1c25b | 2472 | function Make_Disp_Asynchronous_Select_Spec |
2473 | (Typ : Entity_Id) return Node_Id | |
2474 | is | |
2475 | Loc : constant Source_Ptr := Sloc (Typ); | |
2476 | Def_Id : constant Node_Id := | |
2477 | Make_Defining_Identifier (Loc, | |
2478 | Name_uDisp_Asynchronous_Select); | |
2479 | Params : constant List_Id := New_List; | |
ee6ba406 | 2480 | |
76a1c25b | 2481 | begin |
68f95949 | 2482 | pragma Assert (not Restriction_Active (No_Dispatching_Calls)); |
2483 | ||
725a69d2 | 2484 | -- T : in out Typ; -- Object parameter |
2485 | -- S : Integer; -- Primitive operation slot | |
2486 | -- P : Address; -- Wrapped parameters | |
2487 | -- B : out Dummy_Communication_Block; -- Communication block dummy | |
2488 | -- F : out Boolean; -- Status flag | |
ee6ba406 | 2489 | |
725a69d2 | 2490 | Append_List_To (Params, New_List ( |
2491 | ||
2492 | Make_Parameter_Specification (Loc, | |
2493 | Defining_Identifier => | |
2494 | Make_Defining_Identifier (Loc, Name_uT), | |
2495 | Parameter_Type => | |
2496 | New_Reference_To (Typ, Loc), | |
2497 | In_Present => True, | |
2498 | Out_Present => True), | |
2499 | ||
2500 | Make_Parameter_Specification (Loc, | |
2501 | Defining_Identifier => | |
2502 | Make_Defining_Identifier (Loc, Name_uS), | |
2503 | Parameter_Type => | |
2504 | New_Reference_To (Standard_Integer, Loc)), | |
2505 | ||
2506 | Make_Parameter_Specification (Loc, | |
2507 | Defining_Identifier => | |
2508 | Make_Defining_Identifier (Loc, Name_uP), | |
2509 | Parameter_Type => | |
2510 | New_Reference_To (RTE (RE_Address), Loc)), | |
2511 | ||
2512 | Make_Parameter_Specification (Loc, | |
2513 | Defining_Identifier => | |
2514 | Make_Defining_Identifier (Loc, Name_uB), | |
2515 | Parameter_Type => | |
2516 | New_Reference_To (RTE (RE_Dummy_Communication_Block), Loc), | |
2517 | Out_Present => True), | |
ee6ba406 | 2518 | |
725a69d2 | 2519 | Make_Parameter_Specification (Loc, |
2520 | Defining_Identifier => | |
2521 | Make_Defining_Identifier (Loc, Name_uF), | |
2522 | Parameter_Type => | |
2523 | New_Reference_To (Standard_Boolean, Loc), | |
2524 | Out_Present => True))); | |
7189d17f | 2525 | |
76a1c25b | 2526 | return |
725a69d2 | 2527 | Make_Procedure_Specification (Loc, |
2528 | Defining_Unit_Name => Def_Id, | |
2529 | Parameter_Specifications => Params); | |
76a1c25b | 2530 | end Make_Disp_Asynchronous_Select_Spec; |
ee6ba406 | 2531 | |
76a1c25b | 2532 | --------------------------------------- |
2533 | -- Make_Disp_Conditional_Select_Body -- | |
2534 | --------------------------------------- | |
ee6ba406 | 2535 | |
cdb1c38f | 2536 | -- For interface types, generate: |
2537 | ||
2538 | -- procedure _Disp_Conditional_Select | |
2539 | -- (T : in out <Typ>; | |
2540 | -- S : Integer; | |
2541 | -- P : System.Address; | |
2542 | -- C : out Ada.Tags.Prim_Op_Kind; | |
2543 | -- F : out Boolean) | |
2544 | -- is | |
2545 | -- begin | |
2546 | -- null; | |
2547 | -- end _Disp_Conditional_Select; | |
2548 | ||
2549 | -- For protected types, generate: | |
2550 | ||
2551 | -- procedure _Disp_Conditional_Select | |
2552 | -- (T : in out <Typ>; | |
2553 | -- S : Integer; | |
2554 | -- P : System.Address; | |
2555 | -- C : out Ada.Tags.Prim_Op_Kind; | |
2556 | -- F : out Boolean) | |
2557 | -- is | |
2558 | -- I : Integer; | |
2559 | -- Bnn : System.Tasking.Protected_Objects.Operations. | |
2560 | -- Communication_Block; | |
2561 | ||
2562 | -- begin | |
2563 | -- C := Ada.Tags.Get_Prim_Op_Kind (Ada.Tags.Tag (<Typ>VP, S)); | |
2564 | ||
2565 | -- if C = Ada.Tags.POK_Procedure | |
2566 | -- or else C = Ada.Tags.POK_Protected_Procedure | |
2567 | -- or else C = Ada.Tags.POK_Task_Procedure | |
2568 | -- then | |
2569 | -- F := True; | |
2570 | -- return; | |
2571 | -- end if; | |
2572 | ||
2573 | -- I := Ada.Tags.Get_Entry_Index (Ada.Tags.Tag (<Typ>VP, S)); | |
2574 | -- System.Tasking.Protected_Objects.Operations.Protected_Entry_Call | |
2575 | -- (T.object'Access, | |
2576 | -- System.Tasking.Protected_Objects.Protected_Entry_Index (I), | |
2577 | -- P, | |
2578 | -- System.Tasking.Conditional_Call, | |
2579 | -- Bnn); | |
2580 | -- F := not Cancelled (Bnn); | |
2581 | -- end _Disp_Conditional_Select; | |
2582 | ||
2583 | -- For task types, generate: | |
2584 | ||
2585 | -- procedure _Disp_Conditional_Select | |
2586 | -- (T : in out <Typ>; | |
2587 | -- S : Integer; | |
2588 | -- P : System.Address; | |
2589 | -- C : out Ada.Tags.Prim_Op_Kind; | |
2590 | -- F : out Boolean) | |
2591 | -- is | |
2592 | -- I : Integer; | |
2593 | ||
2594 | -- begin | |
2595 | -- I := Ada.Tags.Get_Entry_Index (Ada.Tags.Tag (<Typ>VP, S)); | |
2596 | -- System.Tasking.Rendezvous.Task_Entry_Call | |
2597 | -- (T._task_id, | |
2598 | -- System.Tasking.Task_Entry_Index (I), | |
2599 | -- P, | |
2600 | -- System.Tasking.Conditional_Call, | |
2601 | -- F); | |
2602 | -- end _Disp_Conditional_Select; | |
2603 | ||
76a1c25b | 2604 | function Make_Disp_Conditional_Select_Body |
2605 | (Typ : Entity_Id) return Node_Id | |
2606 | is | |
2607 | Loc : constant Source_Ptr := Sloc (Typ); | |
2608 | Blk_Nam : Entity_Id; | |
2609 | Conc_Typ : Entity_Id := Empty; | |
2610 | Decls : constant List_Id := New_List; | |
2611 | DT_Ptr : Entity_Id; | |
acf97c11 | 2612 | Obj_Ref : Node_Id; |
76a1c25b | 2613 | Stmts : constant List_Id := New_List; |
ee6ba406 | 2614 | |
76a1c25b | 2615 | begin |
68f95949 | 2616 | pragma Assert (not Restriction_Active (No_Dispatching_Calls)); |
2617 | ||
952af0b9 | 2618 | -- Null body is generated for interface types |
2619 | ||
76a1c25b | 2620 | if Is_Interface (Typ) then |
2621 | return | |
2622 | Make_Subprogram_Body (Loc, | |
2623 | Specification => | |
2624 | Make_Disp_Conditional_Select_Spec (Typ), | |
2625 | Declarations => | |
2626 | No_List, | |
2627 | Handled_Statement_Sequence => | |
2628 | Make_Handled_Sequence_Of_Statements (Loc, | |
2629 | New_List (Make_Null_Statement (Loc)))); | |
2630 | end if; | |
ee6ba406 | 2631 | |
76a1c25b | 2632 | DT_Ptr := Node (First_Elmt (Access_Disp_Table (Typ))); |
ee6ba406 | 2633 | |
952af0b9 | 2634 | if Is_Concurrent_Record_Type (Typ) then |
2635 | Conc_Typ := Corresponding_Concurrent_Type (Typ); | |
ee6ba406 | 2636 | |
76a1c25b | 2637 | -- Generate: |
2638 | -- I : Integer; | |
ee6ba406 | 2639 | |
76a1c25b | 2640 | -- where I will be used to capture the entry index of the primitive |
2641 | -- wrapper at position S. | |
ee6ba406 | 2642 | |
76a1c25b | 2643 | Append_To (Decls, |
2644 | Make_Object_Declaration (Loc, | |
2645 | Defining_Identifier => | |
2646 | Make_Defining_Identifier (Loc, Name_uI), | |
2647 | Object_Definition => | |
2648 | New_Reference_To (Standard_Integer, Loc))); | |
ee6ba406 | 2649 | |
952af0b9 | 2650 | -- Generate: |
cdb1c38f | 2651 | -- C := Ada.Tags.Get_Prim_Op_Kind (Ada.Tags.Tag! (<type>VP), S); |
ee6ba406 | 2652 | |
952af0b9 | 2653 | -- if C = POK_Procedure |
2654 | -- or else C = POK_Protected_Procedure | |
2655 | -- or else C = POK_Task_Procedure; | |
2656 | -- then | |
2657 | -- F := True; | |
2658 | -- return; | |
2659 | -- end if; | |
aad6babd | 2660 | |
725a69d2 | 2661 | Build_Common_Dispatching_Select_Statements (Loc, DT_Ptr, Stmts); |
aad6babd | 2662 | |
76a1c25b | 2663 | -- Generate: |
2664 | -- Bnn : Communication_Block; | |
aad6babd | 2665 | |
cdb1c38f | 2666 | -- where Bnn is the name of the communication block used in the |
2667 | -- call to Protected_Entry_Call. | |
aad6babd | 2668 | |
76a1c25b | 2669 | Blk_Nam := Make_Defining_Identifier (Loc, New_Internal_Name ('B')); |
aad6babd | 2670 | |
76a1c25b | 2671 | Append_To (Decls, |
2672 | Make_Object_Declaration (Loc, | |
2673 | Defining_Identifier => | |
2674 | Blk_Nam, | |
2675 | Object_Definition => | |
2676 | New_Reference_To (RTE (RE_Communication_Block), Loc))); | |
aad6babd | 2677 | |
76a1c25b | 2678 | -- Generate: |
cdb1c38f | 2679 | -- I := Ada.Tags.Get_Entry_Index (Ada.Tags.Tag! (<type>VP), S); |
aad6babd | 2680 | |
76a1c25b | 2681 | -- I is the entry index and S is the dispatch table slot |
aad6babd | 2682 | |
76a1c25b | 2683 | Append_To (Stmts, |
2684 | Make_Assignment_Statement (Loc, | |
2685 | Name => | |
2686 | Make_Identifier (Loc, Name_uI), | |
2687 | Expression => | |
725a69d2 | 2688 | Make_Function_Call (Loc, |
cdb1c38f | 2689 | Name => |
2690 | New_Reference_To (RTE (RE_Get_Entry_Index), Loc), | |
2691 | Parameter_Associations => | |
2692 | New_List ( | |
2693 | Unchecked_Convert_To (RTE (RE_Tag), | |
2694 | New_Reference_To (DT_Ptr, Loc)), | |
2695 | Make_Identifier (Loc, Name_uS))))); | |
ee6ba406 | 2696 | |
76a1c25b | 2697 | if Ekind (Conc_Typ) = E_Protected_Type then |
ee6ba406 | 2698 | |
acf97c11 | 2699 | Obj_Ref := -- T._object'Access |
2700 | Make_Attribute_Reference (Loc, | |
2701 | Attribute_Name => Name_Unchecked_Access, | |
2702 | Prefix => | |
2703 | Make_Selected_Component (Loc, | |
2704 | Prefix => Make_Identifier (Loc, Name_uT), | |
2705 | Selector_Name => Make_Identifier (Loc, Name_uObject))); | |
ee6ba406 | 2706 | |
acf97c11 | 2707 | case Corresponding_Runtime_Package (Conc_Typ) is |
2708 | when System_Tasking_Protected_Objects_Entries => | |
2709 | -- Generate: | |
e1c20931 | 2710 | |
acf97c11 | 2711 | -- Protected_Entry_Call |
2712 | -- (T._object'Access, -- Object | |
2713 | -- Protected_Entry_Index! (I), -- E | |
2714 | -- P, -- Uninterpreted_Data | |
2715 | -- Conditional_Call, -- Mode | |
2716 | -- Bnn); -- Block | |
e1c20931 | 2717 | |
acf97c11 | 2718 | -- where T is the protected object, I is the entry index, P |
2719 | -- are the wrapped parameters and Bnn is the name of the | |
2720 | -- communication block. | |
d62940bf | 2721 | |
acf97c11 | 2722 | Append_To (Stmts, |
2723 | Make_Procedure_Call_Statement (Loc, | |
2724 | Name => | |
2725 | New_Reference_To (RTE (RE_Protected_Entry_Call), Loc), | |
2726 | Parameter_Associations => | |
2727 | New_List ( | |
2728 | Obj_Ref, | |
d62940bf | 2729 | |
acf97c11 | 2730 | Make_Unchecked_Type_Conversion (Loc, -- entry index |
2731 | Subtype_Mark => | |
2732 | New_Reference_To | |
2733 | (RTE (RE_Protected_Entry_Index), Loc), | |
2734 | Expression => Make_Identifier (Loc, Name_uI)), | |
2735 | ||
2736 | Make_Identifier (Loc, Name_uP), -- parameter block | |
2737 | ||
2738 | New_Reference_To ( -- Conditional_Call | |
2739 | RTE (RE_Conditional_Call), Loc), | |
2740 | New_Reference_To ( -- Bnn | |
2741 | Blk_Nam, Loc)))); | |
2742 | ||
2743 | when System_Tasking_Protected_Objects_Single_Entry => | |
2744 | ||
2745 | -- If we are compiling for a restricted run-time, the call | |
2746 | -- uses the simpler form. | |
2747 | ||
2748 | Append_To (Stmts, | |
2749 | Make_Procedure_Call_Statement (Loc, | |
2750 | Name => | |
2751 | New_Reference_To | |
2752 | (RTE (RE_Protected_Single_Entry_Call), Loc), | |
2753 | Parameter_Associations => | |
2754 | New_List ( | |
2755 | Obj_Ref, | |
2756 | ||
2757 | Make_Attribute_Reference (Loc, | |
2758 | Prefix => Make_Identifier (Loc, Name_uP), | |
2759 | Attribute_Name => Name_Address), | |
2760 | ||
2761 | New_Reference_To | |
2762 | (RTE (RE_Conditional_Call), Loc)))); | |
2763 | when others => | |
2764 | raise Program_Error; | |
2765 | end case; | |
d62940bf | 2766 | |
76a1c25b | 2767 | -- Generate: |
2768 | -- F := not Cancelled (Bnn); | |
e1c20931 | 2769 | |
76a1c25b | 2770 | -- where F is the success flag. The status of Cancelled is negated |
2771 | -- in order to match the behaviour of the version for task types. | |
e1c20931 | 2772 | |
76a1c25b | 2773 | Append_To (Stmts, |
2774 | Make_Assignment_Statement (Loc, | |
2775 | Name => | |
2776 | Make_Identifier (Loc, Name_uF), | |
2777 | Expression => | |
2778 | Make_Op_Not (Loc, | |
2779 | Right_Opnd => | |
2780 | Make_Function_Call (Loc, | |
2781 | Name => | |
2782 | New_Reference_To (RTE (RE_Cancelled), Loc), | |
2783 | Parameter_Associations => | |
2784 | New_List ( | |
2785 | New_Reference_To (Blk_Nam, Loc)))))); | |
2786 | else | |
2787 | pragma Assert (Ekind (Conc_Typ) = E_Task_Type); | |
d62940bf | 2788 | |
76a1c25b | 2789 | -- Generate: |
cdb1c38f | 2790 | -- Task_Entry_Call |
2791 | -- (T._task_id, -- Acceptor | |
2792 | -- Task_Entry_Index! (I), -- E | |
2793 | -- P, -- Uninterpreted_Data | |
2794 | -- Conditional_Call, -- Mode | |
2795 | -- F); -- Rendezvous_Successful | |
d62940bf | 2796 | |
76a1c25b | 2797 | -- where T is the task object, I is the entry index, P are the |
2798 | -- wrapped parameters and F is the status flag. | |
e1c20931 | 2799 | |
76a1c25b | 2800 | Append_To (Stmts, |
2801 | Make_Procedure_Call_Statement (Loc, | |
2802 | Name => | |
2803 | New_Reference_To (RTE (RE_Task_Entry_Call), Loc), | |
2804 | Parameter_Associations => | |
2805 | New_List ( | |
2806 | ||
2807 | Make_Selected_Component (Loc, -- T._task_id | |
2808 | Prefix => | |
2809 | Make_Identifier (Loc, Name_uT), | |
2810 | Selector_Name => | |
2811 | Make_Identifier (Loc, Name_uTask_Id)), | |
2812 | ||
2813 | Make_Unchecked_Type_Conversion (Loc, -- entry index | |
2814 | Subtype_Mark => | |
2815 | New_Reference_To (RTE (RE_Task_Entry_Index), Loc), | |
2816 | Expression => | |
2817 | Make_Identifier (Loc, Name_uI)), | |
2818 | ||
2819 | Make_Identifier (Loc, Name_uP), -- parameter block | |
2820 | New_Reference_To ( -- Conditional_Call | |
2821 | RTE (RE_Conditional_Call), Loc), | |
2822 | Make_Identifier (Loc, Name_uF)))); -- status flag | |
d62940bf | 2823 | end if; |
7c949aad | 2824 | |
2825 | else | |
2826 | -- Ensure that the statements list is non-empty | |
2827 | ||
2828 | Append_To (Stmts, Make_Null_Statement (Loc)); | |
76a1c25b | 2829 | end if; |
2830 | ||
2831 | return | |
2832 | Make_Subprogram_Body (Loc, | |
2833 | Specification => | |
2834 | Make_Disp_Conditional_Select_Spec (Typ), | |
2835 | Declarations => | |
2836 | Decls, | |
2837 | Handled_Statement_Sequence => | |
2838 | Make_Handled_Sequence_Of_Statements (Loc, Stmts)); | |
2839 | end Make_Disp_Conditional_Select_Body; | |
2840 | ||
2841 | --------------------------------------- | |
2842 | -- Make_Disp_Conditional_Select_Spec -- | |
2843 | --------------------------------------- | |
2844 | ||
2845 | function Make_Disp_Conditional_Select_Spec | |
2846 | (Typ : Entity_Id) return Node_Id | |
2847 | is | |
2848 | Loc : constant Source_Ptr := Sloc (Typ); | |
2849 | Def_Id : constant Node_Id := | |
2850 | Make_Defining_Identifier (Loc, | |
2851 | Name_uDisp_Conditional_Select); | |
2852 | Params : constant List_Id := New_List; | |
2853 | ||
2854 | begin | |
68f95949 | 2855 | pragma Assert (not Restriction_Active (No_Dispatching_Calls)); |
2856 | ||
725a69d2 | 2857 | -- T : in out Typ; -- Object parameter |
2858 | -- S : Integer; -- Primitive operation slot | |
2859 | -- P : Address; -- Wrapped parameters | |
2860 | -- C : out Prim_Op_Kind; -- Call kind | |
2861 | -- F : out Boolean; -- Status flag | |
2862 | ||
2863 | Append_List_To (Params, New_List ( | |
2864 | ||
2865 | Make_Parameter_Specification (Loc, | |
2866 | Defining_Identifier => | |
2867 | Make_Defining_Identifier (Loc, Name_uT), | |
2868 | Parameter_Type => | |
2869 | New_Reference_To (Typ, Loc), | |
2870 | In_Present => True, | |
2871 | Out_Present => True), | |
2872 | ||
2873 | Make_Parameter_Specification (Loc, | |
2874 | Defining_Identifier => | |
2875 | Make_Defining_Identifier (Loc, Name_uS), | |
2876 | Parameter_Type => | |
2877 | New_Reference_To (Standard_Integer, Loc)), | |
2878 | ||
2879 | Make_Parameter_Specification (Loc, | |
2880 | Defining_Identifier => | |
2881 | Make_Defining_Identifier (Loc, Name_uP), | |
2882 | Parameter_Type => | |
2883 | New_Reference_To (RTE (RE_Address), Loc)), | |
76a1c25b | 2884 | |
725a69d2 | 2885 | Make_Parameter_Specification (Loc, |
2886 | Defining_Identifier => | |
2887 | Make_Defining_Identifier (Loc, Name_uC), | |
2888 | Parameter_Type => | |
2889 | New_Reference_To (RTE (RE_Prim_Op_Kind), Loc), | |
2890 | Out_Present => True), | |
76a1c25b | 2891 | |
725a69d2 | 2892 | Make_Parameter_Specification (Loc, |
2893 | Defining_Identifier => | |
2894 | Make_Defining_Identifier (Loc, Name_uF), | |
2895 | Parameter_Type => | |
2896 | New_Reference_To (Standard_Boolean, Loc), | |
2897 | Out_Present => True))); | |
76a1c25b | 2898 | |
2899 | return | |
2900 | Make_Procedure_Specification (Loc, | |
2901 | Defining_Unit_Name => Def_Id, | |
2902 | Parameter_Specifications => Params); | |
2903 | end Make_Disp_Conditional_Select_Spec; | |
2904 | ||
2905 | ------------------------------------- | |
2906 | -- Make_Disp_Get_Prim_Op_Kind_Body -- | |
2907 | ------------------------------------- | |
2908 | ||
2909 | function Make_Disp_Get_Prim_Op_Kind_Body | |
2910 | (Typ : Entity_Id) return Node_Id | |
2911 | is | |
2912 | Loc : constant Source_Ptr := Sloc (Typ); | |
2913 | DT_Ptr : Entity_Id; | |
2914 | ||
2915 | begin | |
68f95949 | 2916 | pragma Assert (not Restriction_Active (No_Dispatching_Calls)); |
2917 | ||
76a1c25b | 2918 | if Is_Interface (Typ) then |
2919 | return | |
2920 | Make_Subprogram_Body (Loc, | |
2921 | Specification => | |
2922 | Make_Disp_Get_Prim_Op_Kind_Spec (Typ), | |
2923 | Declarations => | |
2924 | New_List, | |
2925 | Handled_Statement_Sequence => | |
2926 | Make_Handled_Sequence_Of_Statements (Loc, | |
2927 | New_List (Make_Null_Statement (Loc)))); | |
e1c20931 | 2928 | end if; |
2929 | ||
76a1c25b | 2930 | DT_Ptr := Node (First_Elmt (Access_Disp_Table (Typ))); |
2931 | ||
d62940bf | 2932 | -- Generate: |
76a1c25b | 2933 | -- C := get_prim_op_kind (tag! (<type>VP), S); |
ee6ba406 | 2934 | |
76a1c25b | 2935 | -- where C is the out parameter capturing the call kind and S is the |
2936 | -- dispatch table slot number. | |
ee6ba406 | 2937 | |
76a1c25b | 2938 | return |
2939 | Make_Subprogram_Body (Loc, | |
2940 | Specification => | |
2941 | Make_Disp_Get_Prim_Op_Kind_Spec (Typ), | |
2942 | Declarations => | |
2943 | New_List, | |
2944 | Handled_Statement_Sequence => | |
2945 | Make_Handled_Sequence_Of_Statements (Loc, | |
2946 | New_List ( | |
2947 | Make_Assignment_Statement (Loc, | |
2948 | Name => | |
2949 | Make_Identifier (Loc, Name_uC), | |
2950 | Expression => | |
725a69d2 | 2951 | Make_Function_Call (Loc, |
2952 | Name => | |
2953 | New_Reference_To (RTE (RE_Get_Prim_Op_Kind), Loc), | |
2954 | Parameter_Associations => New_List ( | |
2955 | Unchecked_Convert_To (RTE (RE_Tag), | |
2956 | New_Reference_To (DT_Ptr, Loc)), | |
2957 | Make_Identifier (Loc, Name_uS))))))); | |
76a1c25b | 2958 | end Make_Disp_Get_Prim_Op_Kind_Body; |
e1c20931 | 2959 | |
76a1c25b | 2960 | ------------------------------------- |
2961 | -- Make_Disp_Get_Prim_Op_Kind_Spec -- | |
2962 | ------------------------------------- | |
e1c20931 | 2963 | |
76a1c25b | 2964 | function Make_Disp_Get_Prim_Op_Kind_Spec |
2965 | (Typ : Entity_Id) return Node_Id | |
2966 | is | |
2967 | Loc : constant Source_Ptr := Sloc (Typ); | |
2968 | Def_Id : constant Node_Id := | |
2969 | Make_Defining_Identifier (Loc, | |
2970 | Name_uDisp_Get_Prim_Op_Kind); | |
2971 | Params : constant List_Id := New_List; | |
e1c20931 | 2972 | |
76a1c25b | 2973 | begin |
68f95949 | 2974 | pragma Assert (not Restriction_Active (No_Dispatching_Calls)); |
2975 | ||
725a69d2 | 2976 | -- T : in out Typ; -- Object parameter |
2977 | -- S : Integer; -- Primitive operation slot | |
2978 | -- C : out Prim_Op_Kind; -- Call kind | |
2979 | ||
2980 | Append_List_To (Params, New_List ( | |
2981 | ||
2982 | Make_Parameter_Specification (Loc, | |
2983 | Defining_Identifier => | |
2984 | Make_Defining_Identifier (Loc, Name_uT), | |
2985 | Parameter_Type => | |
2986 | New_Reference_To (Typ, Loc), | |
2987 | In_Present => True, | |
2988 | Out_Present => True), | |
ee6ba406 | 2989 | |
725a69d2 | 2990 | Make_Parameter_Specification (Loc, |
2991 | Defining_Identifier => | |
2992 | Make_Defining_Identifier (Loc, Name_uS), | |
2993 | Parameter_Type => | |
2994 | New_Reference_To (Standard_Integer, Loc)), | |
ee6ba406 | 2995 | |
725a69d2 | 2996 | Make_Parameter_Specification (Loc, |
2997 | Defining_Identifier => | |
2998 | Make_Defining_Identifier (Loc, Name_uC), | |
2999 | Parameter_Type => | |
3000 | New_Reference_To (RTE (RE_Prim_Op_Kind), Loc), | |
3001 | Out_Present => True))); | |
76a1c25b | 3002 | |
3003 | return | |
3004 | Make_Procedure_Specification (Loc, | |
3005 | Defining_Unit_Name => Def_Id, | |
3006 | Parameter_Specifications => Params); | |
3007 | end Make_Disp_Get_Prim_Op_Kind_Spec; | |
3008 | ||
3009 | -------------------------------- | |
3010 | -- Make_Disp_Get_Task_Id_Body -- | |
3011 | -------------------------------- | |
3012 | ||
3013 | function Make_Disp_Get_Task_Id_Body | |
3014 | (Typ : Entity_Id) return Node_Id | |
3015 | is | |
3016 | Loc : constant Source_Ptr := Sloc (Typ); | |
3017 | Ret : Node_Id; | |
3018 | ||
3019 | begin | |
68f95949 | 3020 | pragma Assert (not Restriction_Active (No_Dispatching_Calls)); |
3021 | ||
76a1c25b | 3022 | if Is_Concurrent_Record_Type (Typ) |
3023 | and then Ekind (Corresponding_Concurrent_Type (Typ)) = E_Task_Type | |
3024 | then | |
725a69d2 | 3025 | -- Generate: |
3026 | -- return To_Address (_T._task_id); | |
3027 | ||
76a1c25b | 3028 | Ret := |
17e14451 | 3029 | Make_Simple_Return_Statement (Loc, |
76a1c25b | 3030 | Expression => |
725a69d2 | 3031 | Make_Unchecked_Type_Conversion (Loc, |
3032 | Subtype_Mark => | |
3033 | New_Reference_To (RTE (RE_Address), Loc), | |
3034 | Expression => | |
3035 | Make_Selected_Component (Loc, | |
3036 | Prefix => | |
3037 | Make_Identifier (Loc, Name_uT), | |
3038 | Selector_Name => | |
3039 | Make_Identifier (Loc, Name_uTask_Id)))); | |
76a1c25b | 3040 | |
3041 | -- A null body is constructed for non-task types | |
3042 | ||
3043 | else | |
725a69d2 | 3044 | -- Generate: |
3045 | -- return Null_Address; | |
3046 | ||
76a1c25b | 3047 | Ret := |
17e14451 | 3048 | Make_Simple_Return_Statement (Loc, |
76a1c25b | 3049 | Expression => |
725a69d2 | 3050 | New_Reference_To (RTE (RE_Null_Address), Loc)); |
76a1c25b | 3051 | end if; |
3052 | ||
3053 | return | |
3054 | Make_Subprogram_Body (Loc, | |
3055 | Specification => | |
3056 | Make_Disp_Get_Task_Id_Spec (Typ), | |
3057 | Declarations => | |
3058 | New_List, | |
3059 | Handled_Statement_Sequence => | |
3060 | Make_Handled_Sequence_Of_Statements (Loc, | |
3061 | New_List (Ret))); | |
3062 | end Make_Disp_Get_Task_Id_Body; | |
3063 | ||
3064 | -------------------------------- | |
3065 | -- Make_Disp_Get_Task_Id_Spec -- | |
3066 | -------------------------------- | |
3067 | ||
3068 | function Make_Disp_Get_Task_Id_Spec | |
3069 | (Typ : Entity_Id) return Node_Id | |
3070 | is | |
725a69d2 | 3071 | Loc : constant Source_Ptr := Sloc (Typ); |
76a1c25b | 3072 | |
3073 | begin | |
68f95949 | 3074 | pragma Assert (not Restriction_Active (No_Dispatching_Calls)); |
3075 | ||
76a1c25b | 3076 | return |
3077 | Make_Function_Specification (Loc, | |
725a69d2 | 3078 | Defining_Unit_Name => |
3079 | Make_Defining_Identifier (Loc, Name_uDisp_Get_Task_Id), | |
76a1c25b | 3080 | Parameter_Specifications => New_List ( |
3081 | Make_Parameter_Specification (Loc, | |
3082 | Defining_Identifier => | |
3083 | Make_Defining_Identifier (Loc, Name_uT), | |
3084 | Parameter_Type => | |
3085 | New_Reference_To (Typ, Loc))), | |
3086 | Result_Definition => | |
725a69d2 | 3087 | New_Reference_To (RTE (RE_Address), Loc)); |
76a1c25b | 3088 | end Make_Disp_Get_Task_Id_Spec; |
3089 | ||
cdb1c38f | 3090 | ---------------------------- |
3091 | -- Make_Disp_Requeue_Body -- | |
3092 | ---------------------------- | |
3093 | ||
3094 | function Make_Disp_Requeue_Body | |
3095 | (Typ : Entity_Id) return Node_Id | |
3096 | is | |
3097 | Loc : constant Source_Ptr := Sloc (Typ); | |
3098 | Conc_Typ : Entity_Id := Empty; | |
3099 | Stmts : constant List_Id := New_List; | |
3100 | ||
3101 | begin | |
3102 | pragma Assert (not Restriction_Active (No_Dispatching_Calls)); | |
3103 | ||
3104 | -- Null body is generated for interface types and non-concurrent | |
3105 | -- tagged types. | |
3106 | ||
3107 | if Is_Interface (Typ) | |
3108 | or else not Is_Concurrent_Record_Type (Typ) | |
3109 | then | |
3110 | return | |
3111 | Make_Subprogram_Body (Loc, | |
3112 | Specification => | |
3113 | Make_Disp_Requeue_Spec (Typ), | |
3114 | Declarations => | |
3115 | No_List, | |
3116 | Handled_Statement_Sequence => | |
3117 | Make_Handled_Sequence_Of_Statements (Loc, | |
3118 | New_List (Make_Null_Statement (Loc)))); | |
3119 | end if; | |
3120 | ||
3121 | Conc_Typ := Corresponding_Concurrent_Type (Typ); | |
3122 | ||
3123 | if Ekind (Conc_Typ) = E_Protected_Type then | |
3124 | ||
3125 | -- Generate statements: | |
3126 | -- if F then | |
3127 | -- System.Tasking.Protected_Objects.Operations. | |
3128 | -- Requeue_Protected_Entry | |
3129 | -- (Protection_Entries_Access (P), | |
3130 | -- O._object'Unchecked_Access, | |
3131 | -- Protected_Entry_Index (I), | |
3132 | -- A); | |
3133 | -- else | |
3134 | -- System.Tasking.Protected_Objects.Operations. | |
3135 | -- Requeue_Task_To_Protected_Entry | |
3136 | -- (O._object'Unchecked_Access, | |
3137 | -- Protected_Entry_Index (I), | |
3138 | -- A); | |
3139 | -- end if; | |
3140 | ||
acf97c11 | 3141 | if Restriction_Active (No_Entry_Queue) then |
3142 | Append_To (Stmts, Make_Null_Statement (Loc)); | |
3143 | else | |
3144 | Append_To (Stmts, | |
3145 | Make_If_Statement (Loc, | |
3146 | Condition => | |
3147 | Make_Identifier (Loc, Name_uF), | |
cdb1c38f | 3148 | |
acf97c11 | 3149 | Then_Statements => |
3150 | New_List ( | |
cdb1c38f | 3151 | |
acf97c11 | 3152 | -- Call to Requeue_Protected_Entry |
cdb1c38f | 3153 | |
acf97c11 | 3154 | Make_Procedure_Call_Statement (Loc, |
3155 | Name => | |
3156 | New_Reference_To ( | |
3157 | RTE (RE_Requeue_Protected_Entry), Loc), | |
3158 | Parameter_Associations => | |
3159 | New_List ( | |
3160 | ||
3161 | Make_Unchecked_Type_Conversion (Loc, -- PEA (P) | |
3162 | Subtype_Mark => | |
3163 | New_Reference_To ( | |
3164 | RTE (RE_Protection_Entries_Access), Loc), | |
3165 | Expression => | |
3166 | Make_Identifier (Loc, Name_uP)), | |
3167 | ||
3168 | Make_Attribute_Reference (Loc, -- O._object'Acc | |
3169 | Attribute_Name => | |
3170 | Name_Unchecked_Access, | |
3171 | Prefix => | |
3172 | Make_Selected_Component (Loc, | |
3173 | Prefix => | |
3174 | Make_Identifier (Loc, Name_uO), | |
3175 | Selector_Name => | |
3176 | Make_Identifier (Loc, Name_uObject))), | |
3177 | ||
3178 | Make_Unchecked_Type_Conversion (Loc, -- entry index | |
3179 | Subtype_Mark => | |
3180 | New_Reference_To ( | |
3181 | RTE (RE_Protected_Entry_Index), Loc), | |
3182 | Expression => | |
3183 | Make_Identifier (Loc, Name_uI)), | |
cdb1c38f | 3184 | |
acf97c11 | 3185 | Make_Identifier (Loc, Name_uA)))), -- abort status |
cdb1c38f | 3186 | |
acf97c11 | 3187 | Else_Statements => |
3188 | New_List ( | |
cdb1c38f | 3189 | |
acf97c11 | 3190 | -- Call to Requeue_Task_To_Protected_Entry |
cdb1c38f | 3191 | |
acf97c11 | 3192 | Make_Procedure_Call_Statement (Loc, |
3193 | Name => | |
3194 | New_Reference_To ( | |
3195 | RTE (RE_Requeue_Task_To_Protected_Entry), Loc), | |
3196 | Parameter_Associations => | |
3197 | New_List ( | |
3198 | ||
3199 | Make_Attribute_Reference (Loc, -- O._object'Acc | |
3200 | Attribute_Name => | |
3201 | Name_Unchecked_Access, | |
3202 | Prefix => | |
3203 | Make_Selected_Component (Loc, | |
3204 | Prefix => | |
3205 | Make_Identifier (Loc, Name_uO), | |
3206 | Selector_Name => | |
3207 | Make_Identifier (Loc, Name_uObject))), | |
3208 | ||
3209 | Make_Unchecked_Type_Conversion (Loc, -- entry index | |
3210 | Subtype_Mark => | |
3211 | New_Reference_To ( | |
3212 | RTE (RE_Protected_Entry_Index), Loc), | |
3213 | Expression => | |
3214 | Make_Identifier (Loc, Name_uI)), | |
cdb1c38f | 3215 | |
acf97c11 | 3216 | Make_Identifier (Loc, Name_uA)))))); -- abort status |
3217 | end if; | |
cdb1c38f | 3218 | else |
3219 | pragma Assert (Is_Task_Type (Conc_Typ)); | |
3220 | ||
3221 | -- Generate: | |
3222 | -- if F then | |
3223 | -- System.Tasking.Rendezvous.Requeue_Protected_To_Task_Entry | |
3224 | -- (Protection_Entries_Access (P), | |
3225 | -- O._task_id, | |
3226 | -- Task_Entry_Index (I), | |
3227 | -- A); | |
3228 | -- else | |
3229 | -- System.Tasking.Rendezvous.Requeue_Task_Entry | |
3230 | -- (O._task_id, | |
3231 | -- Task_Entry_Index (I), | |
3232 | -- A); | |
3233 | -- end if; | |
3234 | ||
3235 | Append_To (Stmts, | |
3236 | Make_If_Statement (Loc, | |
3237 | Condition => | |
3238 | Make_Identifier (Loc, Name_uF), | |
3239 | ||
3240 | Then_Statements => | |
3241 | New_List ( | |
3242 | ||
3243 | -- Call to Requeue_Protected_To_Task_Entry | |
3244 | ||
3245 | Make_Procedure_Call_Statement (Loc, | |
3246 | Name => | |
3247 | New_Reference_To ( | |
3248 | RTE (RE_Requeue_Protected_To_Task_Entry), Loc), | |
3249 | ||
3250 | Parameter_Associations => | |
3251 | New_List ( | |
3252 | ||
3253 | Make_Unchecked_Type_Conversion (Loc, -- PEA (P) | |
3254 | Subtype_Mark => | |
3255 | New_Reference_To ( | |
3256 | RTE (RE_Protection_Entries_Access), Loc), | |
3257 | Expression => | |
3258 | Make_Identifier (Loc, Name_uP)), | |
3259 | ||
3260 | Make_Selected_Component (Loc, -- O._task_id | |
3261 | Prefix => | |
3262 | Make_Identifier (Loc, Name_uO), | |
3263 | Selector_Name => | |
3264 | Make_Identifier (Loc, Name_uTask_Id)), | |
3265 | ||
3266 | Make_Unchecked_Type_Conversion (Loc, -- entry index | |
3267 | Subtype_Mark => | |
3268 | New_Reference_To ( | |
3269 | RTE (RE_Task_Entry_Index), Loc), | |
3270 | Expression => | |
3271 | Make_Identifier (Loc, Name_uI)), | |
3272 | ||
3273 | Make_Identifier (Loc, Name_uA)))), -- abort status | |
3274 | ||
3275 | Else_Statements => | |
3276 | New_List ( | |
3277 | ||
3278 | -- Call to Requeue_Task_Entry | |
3279 | ||
3280 | Make_Procedure_Call_Statement (Loc, | |
3281 | Name => | |
3282 | New_Reference_To (RTE (RE_Requeue_Task_Entry), Loc), | |
3283 | ||
3284 | Parameter_Associations => | |
3285 | New_List ( | |
3286 | ||
3287 | Make_Selected_Component (Loc, -- O._task_id | |
3288 | Prefix => | |
3289 | Make_Identifier (Loc, Name_uO), | |
3290 | Selector_Name => | |
3291 | Make_Identifier (Loc, Name_uTask_Id)), | |
3292 | ||
3293 | Make_Unchecked_Type_Conversion (Loc, -- entry index | |
3294 | Subtype_Mark => | |
3295 | New_Reference_To ( | |
3296 | RTE (RE_Task_Entry_Index), Loc), | |
3297 | Expression => | |
3298 | Make_Identifier (Loc, Name_uI)), | |
3299 | ||
3300 | Make_Identifier (Loc, Name_uA)))))); -- abort status | |
3301 | end if; | |
3302 | ||
3303 | -- Even though no declarations are needed in both cases, we allocate | |
3304 | -- a list for entities added by Freeze. | |
3305 | ||
3306 | return | |
3307 | Make_Subprogram_Body (Loc, | |
3308 | Specification => | |
3309 | Make_Disp_Requeue_Spec (Typ), | |
3310 | Declarations => | |
3311 | New_List, | |
3312 | Handled_Statement_Sequence => | |
3313 | Make_Handled_Sequence_Of_Statements (Loc, Stmts)); | |
3314 | end Make_Disp_Requeue_Body; | |
3315 | ||
3316 | ---------------------------- | |
3317 | -- Make_Disp_Requeue_Spec -- | |
3318 | ---------------------------- | |
3319 | ||
3320 | function Make_Disp_Requeue_Spec | |
3321 | (Typ : Entity_Id) return Node_Id | |
3322 | is | |
3323 | Loc : constant Source_Ptr := Sloc (Typ); | |
3324 | ||
3325 | begin | |
3326 | pragma Assert (not Restriction_Active (No_Dispatching_Calls)); | |
3327 | ||
3328 | -- O : in out Typ; - Object parameter | |
3329 | -- F : Boolean; - Protected (True) / task (False) flag | |
3330 | -- P : Address; - Protection_Entries_Access value | |
3331 | -- I : Entry_Index - Index of entry call | |
3332 | -- A : Boolean - Abort flag | |
3333 | ||
3334 | -- Note that the Protection_Entries_Access value is represented as a | |
3335 | -- System.Address in order to avoid dragging in the tasking runtime | |
3336 | -- when compiling sources without tasking constructs. | |
3337 | ||
3338 | return | |
3339 | Make_Procedure_Specification (Loc, | |
3340 | Defining_Unit_Name => | |
3341 | Make_Defining_Identifier (Loc, Name_uDisp_Requeue), | |
3342 | ||
3343 | Parameter_Specifications => | |
3344 | New_List ( | |
3345 | ||
3346 | Make_Parameter_Specification (Loc, -- O | |
3347 | Defining_Identifier => | |
3348 | Make_Defining_Identifier (Loc, Name_uO), | |
3349 | Parameter_Type => | |
3350 | New_Reference_To (Typ, Loc), | |
3351 | In_Present => True, | |
3352 | Out_Present => True), | |
3353 | ||
3354 | Make_Parameter_Specification (Loc, -- F | |
3355 | Defining_Identifier => | |
3356 | Make_Defining_Identifier (Loc, Name_uF), | |
3357 | Parameter_Type => | |
3358 | New_Reference_To (Standard_Boolean, Loc)), | |
3359 | ||
3360 | Make_Parameter_Specification (Loc, -- P | |
3361 | Defining_Identifier => | |
3362 | Make_Defining_Identifier (Loc, Name_uP), | |
3363 | Parameter_Type => | |
3364 | New_Reference_To (RTE (RE_Address), Loc)), | |
3365 | ||
3366 | Make_Parameter_Specification (Loc, -- I | |
3367 | Defining_Identifier => | |
3368 | Make_Defining_Identifier (Loc, Name_uI), | |
3369 | Parameter_Type => | |
3370 | New_Reference_To (Standard_Integer, Loc)), | |
3371 | ||
3372 | Make_Parameter_Specification (Loc, -- A | |
3373 | Defining_Identifier => | |
3374 | Make_Defining_Identifier (Loc, Name_uA), | |
3375 | Parameter_Type => | |
3376 | New_Reference_To (Standard_Boolean, Loc)))); | |
3377 | end Make_Disp_Requeue_Spec; | |
3378 | ||
76a1c25b | 3379 | --------------------------------- |
3380 | -- Make_Disp_Timed_Select_Body -- | |
3381 | --------------------------------- | |
3382 | ||
cdb1c38f | 3383 | -- For interface types, generate: |
3384 | ||
3385 | -- procedure _Disp_Timed_Select | |
3386 | -- (T : in out <Typ>; | |
3387 | -- S : Integer; | |
3388 | -- P : System.Address; | |
3389 | -- D : Duration; | |
3390 | -- M : Integer; | |
3391 | -- C : out Ada.Tags.Prim_Op_Kind; | |
3392 | -- F : out Boolean) | |
3393 | -- is | |
3394 | -- begin | |
3395 | -- null; | |
3396 | -- end _Disp_Timed_Select; | |
3397 | ||
3398 | -- For protected types, generate: | |
3399 | ||
3400 | -- procedure _Disp_Timed_Select | |
3401 | -- (T : in out <Typ>; | |
3402 | -- S : Integer; | |
3403 | -- P : System.Address; | |
3404 | -- D : Duration; | |
3405 | -- M : Integer; | |
3406 | -- C : out Ada.Tags.Prim_Op_Kind; | |
3407 | -- F : out Boolean) | |
3408 | -- is | |
3409 | -- I : Integer; | |
3410 | ||
3411 | -- begin | |
3412 | -- C := Ada.Tags.Get_Prim_Op_Kind (Ada.Tags.Tag (<Typ>VP), S); | |
3413 | ||
3414 | -- if C = Ada.Tags.POK_Procedure | |
3415 | -- or else C = Ada.Tags.POK_Protected_Procedure | |
3416 | -- or else C = Ada.Tags.POK_Task_Procedure | |
3417 | -- then | |
3418 | -- F := True; | |
3419 | -- return; | |
3420 | -- end if; | |
3421 | ||
3422 | -- I := Ada.Tags.Get_Entry_Index (Ada.Tags.Tag (<Typ>VP), S); | |
3423 | -- System.Tasking.Protected_Objects.Operations. | |
3424 | -- Timed_Protected_Entry_Call | |
3425 | -- (T._object'Access, | |
3426 | -- System.Tasking.Protected_Objects.Protected_Entry_Index (I), | |
3427 | -- P, | |
3428 | -- D, | |
3429 | -- M, | |
3430 | -- F); | |
3431 | -- end _Disp_Timed_Select; | |
3432 | ||
3433 | -- For task types, generate: | |
3434 | ||
3435 | -- procedure _Disp_Timed_Select | |
3436 | -- (T : in out <Typ>; | |
3437 | -- S : Integer; | |
3438 | -- P : System.Address; | |
3439 | -- D : Duration; | |
3440 | -- M : Integer; | |
3441 | -- C : out Ada.Tags.Prim_Op_Kind; | |
3442 | -- F : out Boolean) | |
3443 | -- is | |
3444 | -- I : Integer; | |
3445 | ||
3446 | -- begin | |
3447 | -- I := Ada.Tags.Get_Entry_Index (Ada.Tags.Tag (<Typ>VP), S); | |
3448 | -- System.Tasking.Rendezvous.Timed_Task_Entry_Call | |
3449 | -- (T._task_id, | |
3450 | -- System.Tasking.Task_Entry_Index (I), | |
3451 | -- P, | |
3452 | -- D, | |
3453 | -- M, | |
3454 | -- D); | |
3455 | -- end _Disp_Time_Select; | |
3456 | ||
76a1c25b | 3457 | function Make_Disp_Timed_Select_Body |
3458 | (Typ : Entity_Id) return Node_Id | |
3459 | is | |
3460 | Loc : constant Source_Ptr := Sloc (Typ); | |
3461 | Conc_Typ : Entity_Id := Empty; | |
3462 | Decls : constant List_Id := New_List; | |
3463 | DT_Ptr : Entity_Id; | |
acf97c11 | 3464 | Obj_Ref : Node_Id; |
76a1c25b | 3465 | Stmts : constant List_Id := New_List; |
3466 | ||
3467 | begin | |
68f95949 | 3468 | pragma Assert (not Restriction_Active (No_Dispatching_Calls)); |
3469 | ||
952af0b9 | 3470 | -- Null body is generated for interface types |
3471 | ||
76a1c25b | 3472 | if Is_Interface (Typ) then |
3473 | return | |
3474 | Make_Subprogram_Body (Loc, | |
3475 | Specification => | |
3476 | Make_Disp_Timed_Select_Spec (Typ), | |
3477 | Declarations => | |
3478 | New_List, | |
3479 | Handled_Statement_Sequence => | |
3480 | Make_Handled_Sequence_Of_Statements (Loc, | |
3481 | New_List (Make_Null_Statement (Loc)))); | |
3482 | end if; | |
3483 | ||
76a1c25b | 3484 | DT_Ptr := Node (First_Elmt (Access_Disp_Table (Typ))); |
3485 | ||
952af0b9 | 3486 | if Is_Concurrent_Record_Type (Typ) then |
3487 | Conc_Typ := Corresponding_Concurrent_Type (Typ); | |
76a1c25b | 3488 | |
3489 | -- Generate: | |
3490 | -- I : Integer; | |
3491 | ||
3492 | -- where I will be used to capture the entry index of the primitive | |
3493 | -- wrapper at position S. | |
3494 | ||
3495 | Append_To (Decls, | |
3496 | Make_Object_Declaration (Loc, | |
3497 | Defining_Identifier => | |
3498 | Make_Defining_Identifier (Loc, Name_uI), | |
3499 | Object_Definition => | |
3500 | New_Reference_To (Standard_Integer, Loc))); | |
76a1c25b | 3501 | |
952af0b9 | 3502 | -- Generate: |
3503 | -- C := Get_Prim_Op_Kind (tag! (<type>VP), S); | |
76a1c25b | 3504 | |
952af0b9 | 3505 | -- if C = POK_Procedure |
3506 | -- or else C = POK_Protected_Procedure | |
3507 | -- or else C = POK_Task_Procedure; | |
3508 | -- then | |
3509 | -- F := True; | |
3510 | -- return; | |
3511 | -- end if; | |
76a1c25b | 3512 | |
725a69d2 | 3513 | Build_Common_Dispatching_Select_Statements (Loc, DT_Ptr, Stmts); |
76a1c25b | 3514 | |
3515 | -- Generate: | |
952af0b9 | 3516 | -- I := Get_Entry_Index (tag! (<type>VP), S); |
76a1c25b | 3517 | |
3518 | -- I is the entry index and S is the dispatch table slot | |
3519 | ||
3520 | Append_To (Stmts, | |
3521 | Make_Assignment_Statement (Loc, | |
3522 | Name => | |
3523 | Make_Identifier (Loc, Name_uI), | |
3524 | Expression => | |
725a69d2 | 3525 | Make_Function_Call (Loc, |
cdb1c38f | 3526 | Name => |
3527 | New_Reference_To (RTE (RE_Get_Entry_Index), Loc), | |
3528 | Parameter_Associations => | |
3529 | New_List ( | |
3530 | Unchecked_Convert_To (RTE (RE_Tag), | |
3531 | New_Reference_To (DT_Ptr, Loc)), | |
3532 | Make_Identifier (Loc, Name_uS))))); | |
76a1c25b | 3533 | |
acf97c11 | 3534 | -- Protected case |
3535 | ||
76a1c25b | 3536 | if Ekind (Conc_Typ) = E_Protected_Type then |
3537 | ||
acf97c11 | 3538 | -- Build T._object'Access |
3539 | ||
3540 | Obj_Ref := | |
3541 | Make_Attribute_Reference (Loc, | |
3542 | Attribute_Name => Name_Unchecked_Access, | |
3543 | Prefix => | |
3544 | Make_Selected_Component (Loc, | |
3545 | Prefix => Make_Identifier (Loc, Name_uT), | |
3546 | Selector_Name => Make_Identifier (Loc, Name_uObject))); | |
3547 | ||
3548 | -- Normal case, No_Entry_Queue restriction not active. In this | |
3549 | -- case we generate: | |
3550 | ||
3551 | -- Timed_Protected_Entry_Call | |
3552 | -- (T._object'access, | |
cdb1c38f | 3553 | -- Protected_Entry_Index! (I), |
acf97c11 | 3554 | -- P, D, M, F); |
76a1c25b | 3555 | |
3556 | -- where T is the protected object, I is the entry index, P are | |
3557 | -- the wrapped parameters, D is the delay amount, M is the delay | |
3558 | -- mode and F is the status flag. | |
3559 | ||
acf97c11 | 3560 | case Corresponding_Runtime_Package (Conc_Typ) is |
3561 | when System_Tasking_Protected_Objects_Entries => | |
3562 | Append_To (Stmts, | |
3563 | Make_Procedure_Call_Statement (Loc, | |
3564 | Name => | |
3565 | New_Reference_To | |
3566 | (RTE (RE_Timed_Protected_Entry_Call), Loc), | |
3567 | Parameter_Associations => | |
3568 | New_List ( | |
3569 | Obj_Ref, | |
3570 | ||
3571 | Make_Unchecked_Type_Conversion (Loc, -- entry index | |
3572 | Subtype_Mark => | |
3573 | New_Reference_To | |
3574 | (RTE (RE_Protected_Entry_Index), Loc), | |
3575 | Expression => | |
3576 | Make_Identifier (Loc, Name_uI)), | |
76a1c25b | 3577 | |
acf97c11 | 3578 | Make_Identifier (Loc, Name_uP), -- parameter block |
3579 | Make_Identifier (Loc, Name_uD), -- delay | |
3580 | Make_Identifier (Loc, Name_uM), -- delay mode | |
3581 | Make_Identifier (Loc, Name_uF)))); -- status flag | |
76a1c25b | 3582 | |
acf97c11 | 3583 | when System_Tasking_Protected_Objects_Single_Entry => |
3584 | -- Generate: | |
76a1c25b | 3585 | |
acf97c11 | 3586 | -- Timed_Protected_Single_Entry_Call |
3587 | -- (T._object'access, P, D, M, F); | |
3588 | ||
3589 | -- where T is the protected object, P is the wrapped | |
3590 | -- parameters, D is the delay amount, M is the delay mode, F | |
3591 | -- is the status flag. | |
3592 | ||
3593 | Append_To (Stmts, | |
3594 | Make_Procedure_Call_Statement (Loc, | |
3595 | Name => | |
3596 | New_Reference_To | |
3597 | (RTE (RE_Timed_Protected_Single_Entry_Call), Loc), | |
3598 | Parameter_Associations => | |
3599 | New_List ( | |
3600 | Obj_Ref, | |
3601 | Make_Identifier (Loc, Name_uP), -- parameter block | |
3602 | Make_Identifier (Loc, Name_uD), -- delay | |
3603 | Make_Identifier (Loc, Name_uM), -- delay mode | |
3604 | Make_Identifier (Loc, Name_uF)))); -- status flag | |
3605 | ||
3606 | when others => | |
3607 | raise Program_Error; | |
3608 | end case; | |
3609 | ||
3610 | -- Task case | |
ee6ba406 | 3611 | |
ee6ba406 | 3612 | else |
76a1c25b | 3613 | pragma Assert (Ekind (Conc_Typ) = E_Task_Type); |
3614 | ||
3615 | -- Generate: | |
3616 | -- Timed_Task_Entry_Call ( | |
3617 | -- T._task_id, | |
cdb1c38f | 3618 | -- Task_Entry_Index! (I), |
76a1c25b | 3619 | -- P, |
3620 | -- D, | |
3621 | -- M, | |
3622 | -- F); | |
3623 | ||
3624 | -- where T is the task object, I is the entry index, P are the | |
3625 | -- wrapped parameters, D is the delay amount, M is the delay | |
3626 | -- mode and F is the status flag. | |
3627 | ||
3628 | Append_To (Stmts, | |
3629 | Make_Procedure_Call_Statement (Loc, | |
3630 | Name => | |
3631 | New_Reference_To (RTE (RE_Timed_Task_Entry_Call), Loc), | |
3632 | Parameter_Associations => | |
3633 | New_List ( | |
3634 | ||
3635 | Make_Selected_Component (Loc, -- T._task_id | |
3636 | Prefix => | |
3637 | Make_Identifier (Loc, Name_uT), | |
3638 | Selector_Name => | |
3639 | Make_Identifier (Loc, Name_uTask_Id)), | |
3640 | ||
3641 | Make_Unchecked_Type_Conversion (Loc, -- entry index | |
3642 | Subtype_Mark => | |
3643 | New_Reference_To (RTE (RE_Task_Entry_Index), Loc), | |
3644 | Expression => | |
3645 | Make_Identifier (Loc, Name_uI)), | |
3646 | ||
3647 | Make_Identifier (Loc, Name_uP), -- parameter block | |
3648 | Make_Identifier (Loc, Name_uD), -- delay | |
3649 | Make_Identifier (Loc, Name_uM), -- delay mode | |
3650 | Make_Identifier (Loc, Name_uF)))); -- status flag | |
ee6ba406 | 3651 | end if; |
7c949aad | 3652 | |
3653 | else | |
3654 | -- Ensure that the statements list is non-empty | |
3655 | ||
3656 | Append_To (Stmts, Make_Null_Statement (Loc)); | |
76a1c25b | 3657 | end if; |
3658 | ||
3659 | return | |
3660 | Make_Subprogram_Body (Loc, | |
3661 | Specification => | |
3662 | Make_Disp_Timed_Select_Spec (Typ), | |
3663 | Declarations => | |
3664 | Decls, | |
3665 | Handled_Statement_Sequence => | |
3666 | Make_Handled_Sequence_Of_Statements (Loc, Stmts)); | |
3667 | end Make_Disp_Timed_Select_Body; | |
3668 | ||
3669 | --------------------------------- | |
3670 | -- Make_Disp_Timed_Select_Spec -- | |
3671 | --------------------------------- | |
3672 | ||
3673 | function Make_Disp_Timed_Select_Spec | |
3674 | (Typ : Entity_Id) return Node_Id | |
3675 | is | |
3676 | Loc : constant Source_Ptr := Sloc (Typ); | |
3677 | Def_Id : constant Node_Id := | |
3678 | Make_Defining_Identifier (Loc, | |
3679 | Name_uDisp_Timed_Select); | |
3680 | Params : constant List_Id := New_List; | |
ee6ba406 | 3681 | |
76a1c25b | 3682 | begin |
68f95949 | 3683 | pragma Assert (not Restriction_Active (No_Dispatching_Calls)); |
3684 | ||
725a69d2 | 3685 | -- T : in out Typ; -- Object parameter |
3686 | -- S : Integer; -- Primitive operation slot | |
3687 | -- P : Address; -- Wrapped parameters | |
3688 | -- D : Duration; -- Delay | |
3689 | -- M : Integer; -- Delay Mode | |
3690 | -- C : out Prim_Op_Kind; -- Call kind | |
3691 | -- F : out Boolean; -- Status flag | |
76a1c25b | 3692 | |
725a69d2 | 3693 | Append_List_To (Params, New_List ( |
3694 | ||
3695 | Make_Parameter_Specification (Loc, | |
3696 | Defining_Identifier => | |
3697 | Make_Defining_Identifier (Loc, Name_uT), | |
3698 | Parameter_Type => | |
3699 | New_Reference_To (Typ, Loc), | |
3700 | In_Present => True, | |
3701 | Out_Present => True), | |
3702 | ||
3703 | Make_Parameter_Specification (Loc, | |
3704 | Defining_Identifier => | |
3705 | Make_Defining_Identifier (Loc, Name_uS), | |
3706 | Parameter_Type => | |
3707 | New_Reference_To (Standard_Integer, Loc)), | |
3708 | ||
3709 | Make_Parameter_Specification (Loc, | |
3710 | Defining_Identifier => | |
3711 | Make_Defining_Identifier (Loc, Name_uP), | |
3712 | Parameter_Type => | |
3713 | New_Reference_To (RTE (RE_Address), Loc)), | |
76a1c25b | 3714 | |
76a1c25b | 3715 | Make_Parameter_Specification (Loc, |
3716 | Defining_Identifier => | |
3717 | Make_Defining_Identifier (Loc, Name_uD), | |
3718 | Parameter_Type => | |
725a69d2 | 3719 | New_Reference_To (Standard_Duration, Loc)), |
76a1c25b | 3720 | |
76a1c25b | 3721 | Make_Parameter_Specification (Loc, |
3722 | Defining_Identifier => | |
3723 | Make_Defining_Identifier (Loc, Name_uM), | |
3724 | Parameter_Type => | |
725a69d2 | 3725 | New_Reference_To (Standard_Integer, Loc)), |
ee6ba406 | 3726 | |
725a69d2 | 3727 | Make_Parameter_Specification (Loc, |
3728 | Defining_Identifier => | |
3729 | Make_Defining_Identifier (Loc, Name_uC), | |
3730 | Parameter_Type => | |
3731 | New_Reference_To (RTE (RE_Prim_Op_Kind), Loc), | |
3732 | Out_Present => True))); | |
ee6ba406 | 3733 | |
725a69d2 | 3734 | Append_To (Params, |
3735 | Make_Parameter_Specification (Loc, | |
3736 | Defining_Identifier => | |
3737 | Make_Defining_Identifier (Loc, Name_uF), | |
3738 | Parameter_Type => | |
3739 | New_Reference_To (Standard_Boolean, Loc), | |
3740 | Out_Present => True)); | |
ee6ba406 | 3741 | |
76a1c25b | 3742 | return |
3743 | Make_Procedure_Specification (Loc, | |
3744 | Defining_Unit_Name => Def_Id, | |
3745 | Parameter_Specifications => Params); | |
3746 | end Make_Disp_Timed_Select_Spec; | |
ee6ba406 | 3747 | |
76a1c25b | 3748 | ------------- |
3749 | -- Make_DT -- | |
3750 | ------------- | |
ee6ba406 | 3751 | |
725a69d2 | 3752 | -- The frontend supports two models for expanding dispatch tables |
3753 | -- associated with library-level defined tagged types: statically | |
3754 | -- and non-statically allocated dispatch tables. In the former case | |
3755 | -- the object containing the dispatch table is constant and it is | |
3756 | -- initialized by means of a positional aggregate. In the latter case, | |
3757 | -- the object containing the dispatch table is a variable which is | |
3758 | -- initialized by means of assignments. | |
3759 | ||
3760 | -- In case of locally defined tagged types, the object containing the | |
3761 | -- object containing the dispatch table is always a variable (instead | |
3762 | -- of a constant). This is currently required to give support to late | |
3763 | -- overriding of primitives. For example: | |
3764 | ||
3765 | -- procedure Example is | |
3766 | -- package Pkg is | |
3767 | -- type T1 is tagged null record; | |
3768 | -- procedure Prim (O : T1); | |
3769 | -- end Pkg; | |
3770 | ||
3771 | -- type T2 is new Pkg.T1 with null record; | |
3772 | -- procedure Prim (X : T2) is -- late overriding | |
3773 | -- begin | |
3774 | -- ... | |
3775 | -- ... | |
3776 | -- end; | |
952af0b9 | 3777 | |
17e14451 | 3778 | function Make_DT (Typ : Entity_Id; N : Node_Id := Empty) return List_Id is |
3779 | Loc : constant Source_Ptr := Sloc (Typ); | |
3780 | ||
725a69d2 | 3781 | Max_Predef_Prims : constant Int := |
3782 | UI_To_Int | |
3783 | (Intval | |
3784 | (Expression | |
17e14451 | 3785 | (Parent (RTE (RE_Max_Predef_Prims))))); |
3786 | ||
cc60bd16 | 3787 | DT_Decl : constant Elist_Id := New_Elmt_List; |
3788 | DT_Aggr : constant Elist_Id := New_Elmt_List; | |
3789 | -- Entities marked with attribute Is_Dispatch_Table_Entity | |
3790 | ||
17e14451 | 3791 | procedure Check_Premature_Freezing (Subp : Entity_Id; Typ : Entity_Id); |
3792 | -- Verify that all non-tagged types in the profile of a subprogram | |
3793 | -- are frozen at the point the subprogram is frozen. This enforces | |
3794 | -- the rule on RM 13.14 (14) as modified by AI05-019. At the point a | |
3795 | -- subprogram is frozen, enough must be known about it to build the | |
3796 | -- activation record for it, which requires at least that the size of | |
3797 | -- all parameters be known. Controlling arguments are by-reference, | |
3798 | -- and therefore the rule only applies to non-tagged types. | |
3799 | -- Typical violation of the rule involves an object declaration that | |
3800 | -- freezes a tagged type, when one of its primitive operations has a | |
3801 | -- type in its profile whose full view has not been analyzed yet. | |
725a69d2 | 3802 | |
f301a57b | 3803 | procedure Export_DT (Typ : Entity_Id; DT : Entity_Id; Index : Nat := 0); |
3804 | -- Export the dispatch table DT of tagged type Typ. Required to generate | |
3805 | -- forward references and statically allocate the table. For primary | |
3806 | -- dispatch tables Index is 0; for secondary dispatch tables the value | |
3807 | -- of index must match the Suffix_Index value assigned to the table by | |
3808 | -- Make_Tags when generating its unique external name, and it is used to | |
3809 | -- retrieve from the Dispatch_Table_Wrappers list associated with Typ | |
3810 | -- the external name generated by Import_DT. | |
24971415 | 3811 | |
725a69d2 | 3812 | procedure Make_Secondary_DT |
acf97c11 | 3813 | (Typ : Entity_Id; |
3814 | Iface : Entity_Id; | |
f301a57b | 3815 | Suffix_Index : Int; |
acf97c11 | 3816 | Num_Iface_Prims : Nat; |
3817 | Iface_DT_Ptr : Entity_Id; | |
3818 | Predef_Prims_Ptr : Entity_Id; | |
3819 | Build_Thunks : Boolean; | |
3820 | Result : List_Id); | |
cdb1c38f | 3821 | -- Ada 2005 (AI-251): Expand the declarations for a Secondary Dispatch |
3822 | -- Table of Typ associated with Iface. Each abstract interface of Typ | |
3823 | -- has two secondary dispatch tables: one containing pointers to thunks | |
3824 | -- and another containing pointers to the primitives covering the | |
3825 | -- interface primitives. The former secondary table is generated when | |
3826 | -- Build_Thunks is True, and provides common support for dispatching | |
3827 | -- calls through interface types; the latter secondary table is | |
3828 | -- generated when Build_Thunks is False, and provides support for | |
3829 | -- Generic Dispatching Constructors that dispatch calls through | |
f301a57b | 3830 | -- interface types. When constructing this latter table the value |
3831 | -- of Suffix_Index is -1 to indicate that there is no need to export | |
3832 | -- such table when building statically allocated dispatch tables; a | |
3833 | -- positive value of Suffix_Index must match the Suffix_Index value | |
3834 | -- assigned to this secondary dispatch table by Make_Tags when its | |
3835 | -- unique external name was generated. | |
9dfe12ae | 3836 | |
17e14451 | 3837 | ------------------------------ |
3838 | -- Check_Premature_Freezing -- | |
3839 | ------------------------------ | |
3840 | ||
3841 | procedure Check_Premature_Freezing (Subp : Entity_Id; Typ : Entity_Id) is | |
3842 | begin | |
3843 | if Present (N) | |
3844 | and then Is_Private_Type (Typ) | |
3845 | and then No (Full_View (Typ)) | |
3846 | and then not Is_Generic_Type (Typ) | |
3847 | and then not Is_Tagged_Type (Typ) | |
3848 | and then not Is_Frozen (Typ) | |
3849 | then | |
3850 | Error_Msg_Sloc := Sloc (Subp); | |
3851 | Error_Msg_NE | |
3852 | ("declaration must appear after completion of type &", N, Typ); | |
3853 | Error_Msg_NE | |
3854 | ("\which is an untagged type in the profile of" | |
3855 | & " primitive operation & declared#", | |
3856 | N, Subp); | |
3857 | end if; | |
3858 | end Check_Premature_Freezing; | |
3859 | ||
24971415 | 3860 | --------------- |
3861 | -- Export_DT -- | |
3862 | --------------- | |
3863 | ||
f301a57b | 3864 | procedure Export_DT (Typ : Entity_Id; DT : Entity_Id; Index : Nat := 0) |
3865 | is | |
3866 | Count : Nat; | |
3867 | Elmt : Elmt_Id; | |
3868 | ||
24971415 | 3869 | begin |
3870 | Set_Is_Statically_Allocated (DT); | |
3871 | Set_Is_True_Constant (DT); | |
3872 | Set_Is_Exported (DT); | |
3873 | ||
f301a57b | 3874 | Count := 0; |
3875 | Elmt := First_Elmt (Dispatch_Table_Wrappers (Typ)); | |
3876 | while Count /= Index loop | |
3877 | Next_Elmt (Elmt); | |
3878 | Count := Count + 1; | |
3879 | end loop; | |
3880 | ||
3881 | pragma Assert (Related_Type (Node (Elmt)) = Typ); | |
3882 | ||
3883 | Get_External_Name | |
3884 | (Entity => Node (Elmt), | |
3885 | Has_Suffix => True); | |
3886 | ||
24971415 | 3887 | Set_Interface_Name (DT, |
3888 | Make_String_Literal (Loc, | |
3889 | Strval => String_From_Name_Buffer)); | |
3890 | ||
3891 | -- Ensure proper Sprint output of this implicit importation | |
3892 | ||
3893 | Set_Is_Internal (DT); | |
3894 | Set_Is_Public (DT); | |
3895 | end Export_DT; | |
3896 | ||
725a69d2 | 3897 | ----------------------- |
3898 | -- Make_Secondary_DT -- | |
3899 | ----------------------- | |
ee6ba406 | 3900 | |
725a69d2 | 3901 | procedure Make_Secondary_DT |
acf97c11 | 3902 | (Typ : Entity_Id; |
3903 | Iface : Entity_Id; | |
f301a57b | 3904 | Suffix_Index : Int; |
acf97c11 | 3905 | Num_Iface_Prims : Nat; |
3906 | Iface_DT_Ptr : Entity_Id; | |
3907 | Predef_Prims_Ptr : Entity_Id; | |
3908 | Build_Thunks : Boolean; | |
3909 | Result : List_Id) | |
725a69d2 | 3910 | is |
3911 | Loc : constant Source_Ptr := Sloc (Typ); | |
f301a57b | 3912 | Exporting_Table : constant Boolean := |
3913 | Building_Static_DT (Typ) | |
3914 | and then Suffix_Index > 0; | |
725a69d2 | 3915 | Iface_DT : constant Entity_Id := |
f301a57b | 3916 | Make_Defining_Identifier (Loc, |
3917 | Chars => New_Internal_Name ('T')); | |
725a69d2 | 3918 | Name_Predef_Prims : constant Name_Id := New_Internal_Name ('R'); |
3919 | Predef_Prims : constant Entity_Id := | |
3920 | Make_Defining_Identifier (Loc, | |
f301a57b | 3921 | Chars => Name_Predef_Prims); |
725a69d2 | 3922 | DT_Constr_List : List_Id; |
3923 | DT_Aggr_List : List_Id; | |
3924 | Empty_DT : Boolean := False; | |
3925 | Nb_Predef_Prims : Nat := 0; | |
3926 | Nb_Prim : Nat; | |
3927 | New_Node : Node_Id; | |
3928 | OSD : Entity_Id; | |
3929 | OSD_Aggr_List : List_Id; | |
3930 | Pos : Nat; | |
3931 | Prim : Entity_Id; | |
3932 | Prim_Elmt : Elmt_Id; | |
3933 | Prim_Ops_Aggr_List : List_Id; | |
343d35dc | 3934 | |
725a69d2 | 3935 | begin |
17e14451 | 3936 | -- Handle cases in which we do not generate statically allocated |
3937 | -- dispatch tables. | |
343d35dc | 3938 | |
24971415 | 3939 | if not Building_Static_DT (Typ) then |
725a69d2 | 3940 | Set_Ekind (Predef_Prims, E_Variable); |
725a69d2 | 3941 | Set_Ekind (Iface_DT, E_Variable); |
343d35dc | 3942 | |
725a69d2 | 3943 | -- Statically allocated dispatch tables and related entities are |
3944 | -- constants. | |
343d35dc | 3945 | |
725a69d2 | 3946 | else |
3947 | Set_Ekind (Predef_Prims, E_Constant); | |
3948 | Set_Is_Statically_Allocated (Predef_Prims); | |
3949 | Set_Is_True_Constant (Predef_Prims); | |
343d35dc | 3950 | |
725a69d2 | 3951 | Set_Ekind (Iface_DT, E_Constant); |
3952 | Set_Is_Statically_Allocated (Iface_DT); | |
3953 | Set_Is_True_Constant (Iface_DT); | |
343d35dc | 3954 | end if; |
3955 | ||
f301a57b | 3956 | -- Calculate the number of slots of the dispatch table. If the number |
3957 | -- of primitives of Typ is 0 we reserve a dummy single entry for its | |
3958 | -- DT because at run-time the pointer to this dummy entry will be | |
3959 | -- used as the tag. | |
68f95949 | 3960 | |
cdb1c38f | 3961 | if Num_Iface_Prims = 0 then |
725a69d2 | 3962 | Empty_DT := True; |
3963 | Nb_Prim := 1; | |
cdb1c38f | 3964 | else |
3965 | Nb_Prim := Num_Iface_Prims; | |
725a69d2 | 3966 | end if; |
76a1c25b | 3967 | |
725a69d2 | 3968 | -- Generate: |
952af0b9 | 3969 | |
725a69d2 | 3970 | -- Predef_Prims : Address_Array (1 .. Default_Prim_Ops_Count) := |
3971 | -- (predef-prim-op-thunk-1'address, | |
3972 | -- predef-prim-op-thunk-2'address, | |
3973 | -- ... | |
3974 | -- predef-prim-op-thunk-n'address); | |
3975 | -- for Predef_Prims'Alignment use Address'Alignment | |
952af0b9 | 3976 | |
725a69d2 | 3977 | -- Stage 1: Calculate the number of predefined primitives |
76a1c25b | 3978 | |
24971415 | 3979 | if not Building_Static_DT (Typ) then |
725a69d2 | 3980 | Nb_Predef_Prims := Max_Predef_Prims; |
3981 | else | |
3982 | Prim_Elmt := First_Elmt (Primitive_Operations (Typ)); | |
3983 | while Present (Prim_Elmt) loop | |
3984 | Prim := Node (Prim_Elmt); | |
aad6babd | 3985 | |
725a69d2 | 3986 | if Is_Predefined_Dispatching_Operation (Prim) |
3987 | and then not Is_Abstract_Subprogram (Prim) | |
3988 | then | |
3989 | Pos := UI_To_Int (DT_Position (Prim)); | |
aad6babd | 3990 | |
725a69d2 | 3991 | if Pos > Nb_Predef_Prims then |
3992 | Nb_Predef_Prims := Pos; | |
3993 | end if; | |
3994 | end if; | |
aad6babd | 3995 | |
725a69d2 | 3996 | Next_Elmt (Prim_Elmt); |
3997 | end loop; | |
3998 | end if; | |
aad6babd | 3999 | |
725a69d2 | 4000 | -- Stage 2: Create the thunks associated with the predefined |
4001 | -- primitives and save their entity to fill the aggregate. | |
ee6ba406 | 4002 | |
725a69d2 | 4003 | declare |
4004 | Prim_Table : array (Nat range 1 .. Nb_Predef_Prims) of Entity_Id; | |
cc60bd16 | 4005 | Decl : Node_Id; |
725a69d2 | 4006 | Thunk_Id : Entity_Id; |
4007 | Thunk_Code : Node_Id; | |
aad6babd | 4008 | |
725a69d2 | 4009 | begin |
4010 | Prim_Ops_Aggr_List := New_List; | |
4011 | Prim_Table := (others => Empty); | |
aad6babd | 4012 | |
cdb1c38f | 4013 | if Building_Static_DT (Typ) then |
4014 | Prim_Elmt := First_Elmt (Primitive_Operations (Typ)); | |
4015 | while Present (Prim_Elmt) loop | |
4016 | Prim := Node (Prim_Elmt); | |
aad6babd | 4017 | |
cdb1c38f | 4018 | if Is_Predefined_Dispatching_Operation (Prim) |
4019 | and then not Is_Abstract_Subprogram (Prim) | |
4020 | and then not Present (Prim_Table | |
4021 | (UI_To_Int (DT_Position (Prim)))) | |
4022 | then | |
4023 | if not Build_Thunks then | |
4024 | Prim_Table (UI_To_Int (DT_Position (Prim))) := | |
4025 | Alias (Prim); | |
aad6babd | 4026 | |
cdb1c38f | 4027 | else |
4028 | while Present (Alias (Prim)) loop | |
4029 | Prim := Alias (Prim); | |
4030 | end loop; | |
4031 | ||
4032 | Expand_Interface_Thunk (Prim, Thunk_Id, Thunk_Code); | |
aad6babd | 4033 | |
cdb1c38f | 4034 | if Present (Thunk_Id) then |
4035 | Append_To (Result, Thunk_Code); | |
4036 | Prim_Table (UI_To_Int (DT_Position (Prim))) | |
4037 | := Thunk_Id; | |
4038 | end if; | |
4039 | end if; | |
725a69d2 | 4040 | end if; |
aad6babd | 4041 | |
cdb1c38f | 4042 | Next_Elmt (Prim_Elmt); |
4043 | end loop; | |
4044 | end if; | |
aad6babd | 4045 | |
725a69d2 | 4046 | for J in Prim_Table'Range loop |
4047 | if Present (Prim_Table (J)) then | |
4048 | New_Node := | |
cc60bd16 | 4049 | Unchecked_Convert_To (RTE (RE_Prim_Ptr), |
acf97c11 | 4050 | Make_Attribute_Reference (Loc, |
4051 | Prefix => New_Reference_To (Prim_Table (J), Loc), | |
4052 | Attribute_Name => Name_Unrestricted_Access)); | |
725a69d2 | 4053 | else |
cc60bd16 | 4054 | New_Node := Make_Null (Loc); |
725a69d2 | 4055 | end if; |
952af0b9 | 4056 | |
725a69d2 | 4057 | Append_To (Prim_Ops_Aggr_List, New_Node); |
4058 | end loop; | |
952af0b9 | 4059 | |
cc60bd16 | 4060 | New_Node := |
4061 | Make_Aggregate (Loc, | |
4062 | Expressions => Prim_Ops_Aggr_List); | |
4063 | ||
4064 | -- Remember aggregates initializing dispatch tables | |
4065 | ||
4066 | Append_Elmt (New_Node, DT_Aggr); | |
4067 | ||
4068 | Decl := | |
4069 | Make_Subtype_Declaration (Loc, | |
4070 | Defining_Identifier => | |
4071 | Make_Defining_Identifier (Loc, | |
4072 | New_Internal_Name ('S')), | |
4073 | Subtype_Indication => | |
4074 | New_Reference_To (RTE (RE_Address_Array), Loc)); | |
4075 | ||
4076 | Append_To (Result, Decl); | |
4077 | ||
725a69d2 | 4078 | Append_To (Result, |
4079 | Make_Object_Declaration (Loc, | |
4080 | Defining_Identifier => Predef_Prims, | |
24971415 | 4081 | Constant_Present => Building_Static_DT (Typ), |
725a69d2 | 4082 | Aliased_Present => True, |
cc60bd16 | 4083 | Object_Definition => New_Reference_To |
4084 | (Defining_Identifier (Decl), Loc), | |
4085 | Expression => New_Node)); | |
aad6babd | 4086 | |
725a69d2 | 4087 | Append_To (Result, |
4088 | Make_Attribute_Definition_Clause (Loc, | |
4089 | Name => New_Reference_To (Predef_Prims, Loc), | |
4090 | Chars => Name_Alignment, | |
4091 | Expression => | |
4092 | Make_Attribute_Reference (Loc, | |
4093 | Prefix => | |
4094 | New_Reference_To (RTE (RE_Integer_Address), Loc), | |
4095 | Attribute_Name => Name_Alignment))); | |
4096 | end; | |
aad6babd | 4097 | |
725a69d2 | 4098 | -- Generate |
76a1c25b | 4099 | |
725a69d2 | 4100 | -- OSD : Ada.Tags.Object_Specific_Data (Nb_Prims) := |
4101 | -- (OSD_Table => (1 => <value>, | |
4102 | -- ... | |
4103 | -- N => <value>)); | |
76a1c25b | 4104 | |
725a69d2 | 4105 | -- Iface_DT : Dispatch_Table (Nb_Prims) := |
4106 | -- ([ Signature => <sig-value> ], | |
4107 | -- Tag_Kind => <tag_kind-value>, | |
4108 | -- Predef_Prims => Predef_Prims'Address, | |
4109 | -- Offset_To_Top => 0, | |
4110 | -- OSD => OSD'Address, | |
4111 | -- Prims_Ptr => (prim-op-1'address, | |
4112 | -- prim-op-2'address, | |
4113 | -- ... | |
4114 | -- prim-op-n'address)); | |
f301a57b | 4115 | -- for Iface_DT'Alignment use Address'Alignment; |
76a1c25b | 4116 | |
725a69d2 | 4117 | -- Stage 3: Initialize the discriminant and the record components |
aad6babd | 4118 | |
725a69d2 | 4119 | DT_Constr_List := New_List; |
4120 | DT_Aggr_List := New_List; | |
343d35dc | 4121 | |
725a69d2 | 4122 | -- Nb_Prim. If the tagged type has no primitives we add a dummy |
4123 | -- slot whose address will be the tag of this type. | |
343d35dc | 4124 | |
725a69d2 | 4125 | if Nb_Prim = 0 then |
4126 | New_Node := Make_Integer_Literal (Loc, 1); | |
4127 | else | |
4128 | New_Node := Make_Integer_Literal (Loc, Nb_Prim); | |
4129 | end if; | |
343d35dc | 4130 | |
725a69d2 | 4131 | Append_To (DT_Constr_List, New_Node); |
4132 | Append_To (DT_Aggr_List, New_Copy (New_Node)); | |
343d35dc | 4133 | |
725a69d2 | 4134 | -- Signature |
343d35dc | 4135 | |
725a69d2 | 4136 | if RTE_Record_Component_Available (RE_Signature) then |
4137 | Append_To (DT_Aggr_List, | |
4138 | New_Reference_To (RTE (RE_Secondary_DT), Loc)); | |
4139 | end if; | |
343d35dc | 4140 | |
725a69d2 | 4141 | -- Tag_Kind |
343d35dc | 4142 | |
725a69d2 | 4143 | if RTE_Record_Component_Available (RE_Tag_Kind) then |
4144 | Append_To (DT_Aggr_List, Tagged_Kind (Typ)); | |
4145 | end if; | |
aad6babd | 4146 | |
725a69d2 | 4147 | -- Predef_Prims |
aad6babd | 4148 | |
725a69d2 | 4149 | Append_To (DT_Aggr_List, |
4150 | Make_Attribute_Reference (Loc, | |
4151 | Prefix => New_Reference_To (Predef_Prims, Loc), | |
4152 | Attribute_Name => Name_Address)); | |
aad6babd | 4153 | |
725a69d2 | 4154 | -- Note: The correct value of Offset_To_Top will be set by the init |
4155 | -- subprogram | |
aad6babd | 4156 | |
725a69d2 | 4157 | Append_To (DT_Aggr_List, Make_Integer_Literal (Loc, 0)); |
aad6babd | 4158 | |
725a69d2 | 4159 | -- Generate the Object Specific Data table required to dispatch calls |
4160 | -- through synchronized interfaces. | |
aad6babd | 4161 | |
725a69d2 | 4162 | if Empty_DT |
4163 | or else Is_Abstract_Type (Typ) | |
4164 | or else Is_Controlled (Typ) | |
4165 | or else Restriction_Active (No_Dispatching_Calls) | |
4166 | or else not Is_Limited_Type (Typ) | |
a652dd51 | 4167 | or else not Has_Interfaces (Typ) |
cdb1c38f | 4168 | or else not Build_Thunks |
38d2fa31 | 4169 | or else not RTE_Record_Component_Available (RE_OSD_Table) |
725a69d2 | 4170 | then |
4171 | -- No OSD table required | |
ee6ba406 | 4172 | |
725a69d2 | 4173 | Append_To (DT_Aggr_List, |
4174 | New_Reference_To (RTE (RE_Null_Address), Loc)); | |
d62940bf | 4175 | |
725a69d2 | 4176 | else |
4177 | OSD_Aggr_List := New_List; | |
d62940bf | 4178 | |
725a69d2 | 4179 | declare |
4180 | Prim_Table : array (Nat range 1 .. Nb_Prim) of Entity_Id; | |
4181 | Prim : Entity_Id; | |
4182 | Prim_Alias : Entity_Id; | |
4183 | Prim_Elmt : Elmt_Id; | |
4184 | E : Entity_Id; | |
4185 | Count : Nat := 0; | |
4186 | Pos : Nat; | |
d62940bf | 4187 | |
725a69d2 | 4188 | begin |
4189 | Prim_Table := (others => Empty); | |
4190 | Prim_Alias := Empty; | |
d62940bf | 4191 | |
725a69d2 | 4192 | Prim_Elmt := First_Elmt (Primitive_Operations (Typ)); |
4193 | while Present (Prim_Elmt) loop | |
4194 | Prim := Node (Prim_Elmt); | |
d62940bf | 4195 | |
a652dd51 | 4196 | if Present (Interface_Alias (Prim)) |
725a69d2 | 4197 | and then Find_Dispatching_Type |
a652dd51 | 4198 | (Interface_Alias (Prim)) = Iface |
725a69d2 | 4199 | then |
a652dd51 | 4200 | Prim_Alias := Interface_Alias (Prim); |
d62940bf | 4201 | |
725a69d2 | 4202 | E := Prim; |
4203 | while Present (Alias (E)) loop | |
4204 | E := Alias (E); | |
4205 | end loop; | |
68f95949 | 4206 | |
725a69d2 | 4207 | Pos := UI_To_Int (DT_Position (Prim_Alias)); |
68f95949 | 4208 | |
725a69d2 | 4209 | if Present (Prim_Table (Pos)) then |
4210 | pragma Assert (Prim_Table (Pos) = E); | |
4211 | null; | |
68f95949 | 4212 | |
725a69d2 | 4213 | else |
4214 | Prim_Table (Pos) := E; | |
4215 | ||
4216 | Append_To (OSD_Aggr_List, | |
4217 | Make_Component_Association (Loc, | |
4218 | Choices => New_List ( | |
4219 | Make_Integer_Literal (Loc, | |
4220 | DT_Position (Prim_Alias))), | |
4221 | Expression => | |
4222 | Make_Integer_Literal (Loc, | |
4223 | DT_Position (Alias (Prim))))); | |
4224 | ||
4225 | Count := Count + 1; | |
4226 | end if; | |
4227 | end if; | |
4228 | ||
4229 | Next_Elmt (Prim_Elmt); | |
4230 | end loop; | |
4231 | pragma Assert (Count = Nb_Prim); | |
4232 | end; | |
4233 | ||
4234 | OSD := Make_Defining_Identifier (Loc, New_Internal_Name ('I')); | |
4235 | ||
4236 | Append_To (Result, | |
4237 | Make_Object_Declaration (Loc, | |
4238 | Defining_Identifier => OSD, | |
4239 | Object_Definition => | |
4240 | Make_Subtype_Indication (Loc, | |
4241 | Subtype_Mark => | |
4242 | New_Reference_To (RTE (RE_Object_Specific_Data), Loc), | |
4243 | Constraint => | |
4244 | Make_Index_Or_Discriminant_Constraint (Loc, | |
4245 | Constraints => New_List ( | |
4246 | Make_Integer_Literal (Loc, Nb_Prim)))), | |
4247 | Expression => Make_Aggregate (Loc, | |
4248 | Component_Associations => New_List ( | |
4249 | Make_Component_Association (Loc, | |
4250 | Choices => New_List ( | |
4251 | New_Occurrence_Of | |
4252 | (RTE_Record_Component (RE_OSD_Num_Prims), Loc)), | |
4253 | Expression => | |
4254 | Make_Integer_Literal (Loc, Nb_Prim)), | |
4255 | ||
4256 | Make_Component_Association (Loc, | |
4257 | Choices => New_List ( | |
4258 | New_Occurrence_Of | |
4259 | (RTE_Record_Component (RE_OSD_Table), Loc)), | |
4260 | Expression => Make_Aggregate (Loc, | |
4261 | Component_Associations => OSD_Aggr_List)))))); | |
4262 | ||
17e14451 | 4263 | Append_To (Result, |
4264 | Make_Attribute_Definition_Clause (Loc, | |
4265 | Name => New_Reference_To (OSD, Loc), | |
4266 | Chars => Name_Alignment, | |
4267 | Expression => | |
4268 | Make_Attribute_Reference (Loc, | |
4269 | Prefix => | |
4270 | New_Reference_To (RTE (RE_Integer_Address), Loc), | |
4271 | Attribute_Name => Name_Alignment))); | |
4272 | ||
725a69d2 | 4273 | -- In secondary dispatch tables the Typeinfo component contains |
4274 | -- the address of the Object Specific Data (see a-tags.ads) | |
4275 | ||
4276 | Append_To (DT_Aggr_List, | |
4277 | Make_Attribute_Reference (Loc, | |
4278 | Prefix => New_Reference_To (OSD, Loc), | |
4279 | Attribute_Name => Name_Address)); | |
4280 | end if; | |
4281 | ||
4282 | -- Initialize the table of primitive operations | |
4283 | ||
4284 | Prim_Ops_Aggr_List := New_List; | |
4285 | ||
4286 | if Empty_DT then | |
cc60bd16 | 4287 | Append_To (Prim_Ops_Aggr_List, Make_Null (Loc)); |
725a69d2 | 4288 | |
4289 | elsif Is_Abstract_Type (Typ) | |
24971415 | 4290 | or else not Building_Static_DT (Typ) |
725a69d2 | 4291 | then |
4292 | for J in 1 .. Nb_Prim loop | |
cc60bd16 | 4293 | Append_To (Prim_Ops_Aggr_List, Make_Null (Loc)); |
725a69d2 | 4294 | end loop; |
4295 | ||
4296 | else | |
4297 | declare | |
4298 | Prim_Table : array (Nat range 1 .. Nb_Prim) of Entity_Id; | |
4299 | Pos : Nat; | |
4300 | Thunk_Code : Node_Id; | |
4301 | Thunk_Id : Entity_Id; | |
4302 | ||
4303 | begin | |
4304 | Prim_Table := (others => Empty); | |
4305 | ||
4306 | Prim_Elmt := First_Elmt (Primitive_Operations (Typ)); | |
4307 | while Present (Prim_Elmt) loop | |
4308 | Prim := Node (Prim_Elmt); | |
4309 | ||
4310 | if not Is_Predefined_Dispatching_Operation (Prim) | |
a652dd51 | 4311 | and then Present (Interface_Alias (Prim)) |
725a69d2 | 4312 | and then not Is_Abstract_Subprogram (Alias (Prim)) |
4313 | and then not Is_Imported (Alias (Prim)) | |
4314 | and then Find_Dispatching_Type | |
a652dd51 | 4315 | (Interface_Alias (Prim)) = Iface |
725a69d2 | 4316 | |
4317 | -- Generate the code of the thunk only if the abstract | |
4318 | -- interface type is not an immediate ancestor of | |
4319 | -- Tagged_Type; otherwise the DT associated with the | |
4320 | -- interface is the primary DT. | |
4321 | ||
a652dd51 | 4322 | and then not Is_Ancestor (Iface, Typ) |
725a69d2 | 4323 | then |
cdb1c38f | 4324 | if not Build_Thunks then |
725a69d2 | 4325 | Pos := |
a652dd51 | 4326 | UI_To_Int (DT_Position (Interface_Alias (Prim))); |
cdb1c38f | 4327 | Prim_Table (Pos) := Alias (Prim); |
4328 | else | |
4329 | Expand_Interface_Thunk (Prim, Thunk_Id, Thunk_Code); | |
725a69d2 | 4330 | |
cdb1c38f | 4331 | if Present (Thunk_Id) then |
4332 | Pos := | |
a652dd51 | 4333 | UI_To_Int (DT_Position (Interface_Alias (Prim))); |
cdb1c38f | 4334 | |
4335 | Prim_Table (Pos) := Thunk_Id; | |
4336 | Append_To (Result, Thunk_Code); | |
4337 | end if; | |
725a69d2 | 4338 | end if; |
4339 | end if; | |
4340 | ||
4341 | Next_Elmt (Prim_Elmt); | |
4342 | end loop; | |
4343 | ||
4344 | for J in Prim_Table'Range loop | |
4345 | if Present (Prim_Table (J)) then | |
4346 | New_Node := | |
cc60bd16 | 4347 | Unchecked_Convert_To (RTE (RE_Prim_Ptr), |
acf97c11 | 4348 | Make_Attribute_Reference (Loc, |
4349 | Prefix => New_Reference_To (Prim_Table (J), Loc), | |
4350 | Attribute_Name => Name_Unrestricted_Access)); | |
725a69d2 | 4351 | else |
cc60bd16 | 4352 | New_Node := Make_Null (Loc); |
725a69d2 | 4353 | end if; |
4354 | ||
4355 | Append_To (Prim_Ops_Aggr_List, New_Node); | |
4356 | end loop; | |
4357 | end; | |
4358 | end if; | |
4359 | ||
cc60bd16 | 4360 | New_Node := |
725a69d2 | 4361 | Make_Aggregate (Loc, |
cc60bd16 | 4362 | Expressions => Prim_Ops_Aggr_List); |
4363 | ||
4364 | Append_To (DT_Aggr_List, New_Node); | |
4365 | ||
4366 | -- Remember aggregates initializing dispatch tables | |
4367 | ||
4368 | Append_Elmt (New_Node, DT_Aggr); | |
725a69d2 | 4369 | |
f301a57b | 4370 | -- Note: Secondary dispatch tables cannot be declared constant |
4371 | -- because the component Offset_To_Top is currently initialized | |
4372 | -- by the IP routine. | |
4373 | ||
725a69d2 | 4374 | Append_To (Result, |
4375 | Make_Object_Declaration (Loc, | |
4376 | Defining_Identifier => Iface_DT, | |
4377 | Aliased_Present => True, | |
f301a57b | 4378 | Constant_Present => False, |
4379 | ||
725a69d2 | 4380 | Object_Definition => |
4381 | Make_Subtype_Indication (Loc, | |
4382 | Subtype_Mark => New_Reference_To | |
4383 | (RTE (RE_Dispatch_Table_Wrapper), Loc), | |
4384 | Constraint => Make_Index_Or_Discriminant_Constraint (Loc, | |
4385 | Constraints => DT_Constr_List)), | |
4386 | ||
f301a57b | 4387 | Expression => |
4388 | Make_Aggregate (Loc, | |
4389 | Expressions => DT_Aggr_List))); | |
725a69d2 | 4390 | |
17e14451 | 4391 | Append_To (Result, |
4392 | Make_Attribute_Definition_Clause (Loc, | |
4393 | Name => New_Reference_To (Iface_DT, Loc), | |
4394 | Chars => Name_Alignment, | |
f301a57b | 4395 | |
17e14451 | 4396 | Expression => |
4397 | Make_Attribute_Reference (Loc, | |
f301a57b | 4398 | Prefix => |
17e14451 | 4399 | New_Reference_To (RTE (RE_Integer_Address), Loc), |
4400 | Attribute_Name => Name_Alignment))); | |
4401 | ||
f301a57b | 4402 | if Exporting_Table then |
4403 | Export_DT (Typ, Iface_DT, Suffix_Index); | |
4404 | ||
725a69d2 | 4405 | -- Generate code to create the pointer to the dispatch table |
4406 | ||
f301a57b | 4407 | -- Iface_DT_Ptr : Tag := Tag!(DT.Prims_Ptr'Address); |
725a69d2 | 4408 | |
f301a57b | 4409 | -- Note: This declaration is not added here if the table is exported |
4410 | -- because in such case Make_Tags has already added this declaration. | |
4411 | ||
4412 | else | |
4413 | Append_To (Result, | |
4414 | Make_Object_Declaration (Loc, | |
4415 | Defining_Identifier => Iface_DT_Ptr, | |
4416 | Constant_Present => True, | |
4417 | ||
4418 | Object_Definition => | |
4419 | New_Reference_To (RTE (RE_Interface_Tag), Loc), | |
4420 | ||
4421 | Expression => | |
4422 | Unchecked_Convert_To (RTE (RE_Interface_Tag), | |
4423 | Make_Attribute_Reference (Loc, | |
4424 | Prefix => | |
4425 | Make_Selected_Component (Loc, | |
4426 | Prefix => New_Reference_To (Iface_DT, Loc), | |
4427 | Selector_Name => | |
4428 | New_Occurrence_Of | |
4429 | (RTE_Record_Component (RE_Prims_Ptr), Loc)), | |
4430 | Attribute_Name => Name_Address)))); | |
4431 | end if; | |
725a69d2 | 4432 | |
acf97c11 | 4433 | Append_To (Result, |
4434 | Make_Object_Declaration (Loc, | |
4435 | Defining_Identifier => Predef_Prims_Ptr, | |
4436 | Constant_Present => True, | |
f301a57b | 4437 | |
4438 | Object_Definition => | |
acf97c11 | 4439 | New_Reference_To (RTE (RE_Address), Loc), |
f301a57b | 4440 | |
4441 | Expression => | |
acf97c11 | 4442 | Make_Attribute_Reference (Loc, |
f301a57b | 4443 | Prefix => |
acf97c11 | 4444 | Make_Selected_Component (Loc, |
f301a57b | 4445 | Prefix => New_Reference_To (Iface_DT, Loc), |
4446 | Selector_Name => | |
4447 | New_Occurrence_Of | |
4448 | (RTE_Record_Component (RE_Predef_Prims), Loc)), | |
acf97c11 | 4449 | Attribute_Name => Name_Address))); |
4450 | ||
cc60bd16 | 4451 | -- Remember entities containing dispatch tables |
acf97c11 | 4452 | |
cc60bd16 | 4453 | Append_Elmt (Predef_Prims, DT_Decl); |
4454 | Append_Elmt (Iface_DT, DT_Decl); | |
725a69d2 | 4455 | end Make_Secondary_DT; |
4456 | ||
4457 | -- Local variables | |
4458 | ||
2ea346ac | 4459 | Elab_Code : constant List_Id := New_List; |
4460 | Result : constant List_Id := New_List; | |
4461 | Tname : constant Name_Id := Chars (Typ); | |
725a69d2 | 4462 | AI : Elmt_Id; |
cdb1c38f | 4463 | AI_Tag_Elmt : Elmt_Id; |
24971415 | 4464 | AI_Tag_Comp : Elmt_Id; |
f9162257 | 4465 | DT_Aggr_List : List_Id; |
24971415 | 4466 | DT_Constr_List : List_Id; |
725a69d2 | 4467 | DT_Ptr : Entity_Id; |
725a69d2 | 4468 | ITable : Node_Id; |
4469 | I_Depth : Nat := 0; | |
4470 | Iface_Table_Node : Node_Id; | |
4471 | Name_ITable : Name_Id; | |
725a69d2 | 4472 | Nb_Predef_Prims : Nat := 0; |
4473 | Nb_Prim : Nat := 0; | |
4474 | New_Node : Node_Id; | |
725a69d2 | 4475 | Num_Ifaces : Nat := 0; |
cc60bd16 | 4476 | Parent_Typ : Entity_Id; |
725a69d2 | 4477 | Prim : Entity_Id; |
4478 | Prim_Elmt : Elmt_Id; | |
4479 | Prim_Ops_Aggr_List : List_Id; | |
725a69d2 | 4480 | Suffix_Index : Int; |
4481 | Typ_Comps : Elist_Id; | |
4482 | Typ_Ifaces : Elist_Id; | |
4483 | TSD_Aggr_List : List_Id; | |
4484 | TSD_Tags_List : List_Id; | |
17e14451 | 4485 | |
4486 | -- The following name entries are used by Make_DT to generate a number | |
4487 | -- of entities related to a tagged type. These entities may be generated | |
4488 | -- in a scope other than that of the tagged type declaration, and if | |
4489 | -- the entities for two tagged types with the same name happen to be | |
4490 | -- generated in the same scope, we have to take care to use different | |
4491 | -- names. This is achieved by means of a unique serial number appended | |
4492 | -- to each generated entity name. | |
4493 | ||
4494 | Name_DT : constant Name_Id := | |
4495 | New_External_Name (Tname, 'T', Suffix_Index => -1); | |
4496 | Name_Exname : constant Name_Id := | |
4497 | New_External_Name (Tname, 'E', Suffix_Index => -1); | |
e7e688dd | 4498 | Name_HT_Link : constant Name_Id := |
4499 | New_External_Name (Tname, 'H', Suffix_Index => -1); | |
17e14451 | 4500 | Name_Predef_Prims : constant Name_Id := |
4501 | New_External_Name (Tname, 'R', Suffix_Index => -1); | |
4502 | Name_SSD : constant Name_Id := | |
4503 | New_External_Name (Tname, 'S', Suffix_Index => -1); | |
4504 | Name_TSD : constant Name_Id := | |
4505 | New_External_Name (Tname, 'B', Suffix_Index => -1); | |
4506 | ||
4507 | -- Entities built with above names | |
4508 | ||
4509 | DT : constant Entity_Id := | |
4510 | Make_Defining_Identifier (Loc, Name_DT); | |
4511 | Exname : constant Entity_Id := | |
4512 | Make_Defining_Identifier (Loc, Name_Exname); | |
e7e688dd | 4513 | HT_Link : constant Entity_Id := |
4514 | Make_Defining_Identifier (Loc, Name_HT_Link); | |
17e14451 | 4515 | Predef_Prims : constant Entity_Id := |
4516 | Make_Defining_Identifier (Loc, Name_Predef_Prims); | |
4517 | SSD : constant Entity_Id := | |
4518 | Make_Defining_Identifier (Loc, Name_SSD); | |
4519 | TSD : constant Entity_Id := | |
4520 | Make_Defining_Identifier (Loc, Name_TSD); | |
725a69d2 | 4521 | |
4522 | -- Start of processing for Make_DT | |
4523 | ||
4524 | begin | |
17e14451 | 4525 | pragma Assert (Is_Frozen (Typ)); |
725a69d2 | 4526 | |
17e14451 | 4527 | -- Handle cases in which there is no need to build the dispatch table |
725a69d2 | 4528 | |
17e14451 | 4529 | if Has_Dispatch_Table (Typ) |
4530 | or else No (Access_Disp_Table (Typ)) | |
4531 | or else Is_CPP_Class (Typ) | |
4532 | then | |
725a69d2 | 4533 | return Result; |
725a69d2 | 4534 | |
17e14451 | 4535 | elsif No_Run_Time_Mode then |
4536 | Error_Msg_CRT ("tagged types", Typ); | |
4537 | return Result; | |
725a69d2 | 4538 | |
17e14451 | 4539 | elsif not RTE_Available (RE_Tag) then |
725a69d2 | 4540 | Append_To (Result, |
4541 | Make_Object_Declaration (Loc, | |
17e14451 | 4542 | Defining_Identifier => Node (First_Elmt |
4543 | (Access_Disp_Table (Typ))), | |
725a69d2 | 4544 | Object_Definition => New_Reference_To (RTE (RE_Tag), Loc), |
4545 | Constant_Present => True, | |
4546 | Expression => | |
24971415 | 4547 | Unchecked_Convert_To (RTE (RE_Tag), |
725a69d2 | 4548 | New_Reference_To (RTE (RE_Null_Address), Loc)))); |
4549 | ||
4550 | Analyze_List (Result, Suppress => All_Checks); | |
4551 | Error_Msg_CRT ("tagged types", Typ); | |
4552 | return Result; | |
4553 | end if; | |
4554 | ||
17e14451 | 4555 | -- Ensure that the value of Max_Predef_Prims defined in a-tags is |
cdb1c38f | 4556 | -- correct. Valid values are 10 under configurable runtime or 16 |
17e14451 | 4557 | -- with full runtime. |
4558 | ||
4559 | if RTE_Available (RE_Interface_Data) then | |
cdb1c38f | 4560 | if Max_Predef_Prims /= 16 then |
17e14451 | 4561 | Error_Msg_N ("run-time library configuration error", Typ); |
4562 | return Result; | |
4563 | end if; | |
725a69d2 | 4564 | else |
17e14451 | 4565 | if Max_Predef_Prims /= 10 then |
4566 | Error_Msg_N ("run-time library configuration error", Typ); | |
4567 | Error_Msg_CRT ("tagged types", Typ); | |
4568 | return Result; | |
4569 | end if; | |
725a69d2 | 4570 | end if; |
4571 | ||
cc60bd16 | 4572 | -- Initialize Parent_Typ handling private types |
4573 | ||
4574 | Parent_Typ := Etype (Typ); | |
4575 | ||
4576 | if Present (Full_View (Parent_Typ)) then | |
4577 | Parent_Typ := Full_View (Parent_Typ); | |
4578 | end if; | |
4579 | ||
17e14451 | 4580 | -- Ensure that all the primitives are frozen. This is only required when |
4581 | -- building static dispatch tables --- the primitives must be frozen to | |
4582 | -- be referenced (otherwise we have problems with the backend). It is | |
4583 | -- not a requirement with nonstatic dispatch tables because in this case | |
4584 | -- we generate now an empty dispatch table; the extra code required to | |
24971415 | 4585 | -- register the primitives in the slots will be generated later --- when |
17e14451 | 4586 | -- each primitive is frozen (see Freeze_Subprogram). |
725a69d2 | 4587 | |
24971415 | 4588 | if Building_Static_DT (Typ) |
17e14451 | 4589 | and then not Is_CPP_Class (Typ) |
4590 | then | |
4591 | declare | |
4592 | Save : constant Boolean := Freezing_Library_Level_Tagged_Type; | |
555c63a6 | 4593 | Prim : Entity_Id; |
17e14451 | 4594 | Prim_Elmt : Elmt_Id; |
4595 | Frnodes : List_Id; | |
725a69d2 | 4596 | |
17e14451 | 4597 | begin |
4598 | Freezing_Library_Level_Tagged_Type := True; | |
555c63a6 | 4599 | |
17e14451 | 4600 | Prim_Elmt := First_Elmt (Primitive_Operations (Typ)); |
4601 | while Present (Prim_Elmt) loop | |
555c63a6 | 4602 | Prim := Node (Prim_Elmt); |
4603 | Frnodes := Freeze_Entity (Prim, Loc); | |
725a69d2 | 4604 | |
17e14451 | 4605 | declare |
17e14451 | 4606 | F : Entity_Id; |
725a69d2 | 4607 | |
17e14451 | 4608 | begin |
555c63a6 | 4609 | F := First_Formal (Prim); |
17e14451 | 4610 | while Present (F) loop |
555c63a6 | 4611 | Check_Premature_Freezing (Prim, Etype (F)); |
17e14451 | 4612 | Next_Formal (F); |
4613 | end loop; | |
4614 | ||
555c63a6 | 4615 | Check_Premature_Freezing (Prim, Etype (Prim)); |
17e14451 | 4616 | end; |
4617 | ||
4618 | if Present (Frnodes) then | |
4619 | Append_List_To (Result, Frnodes); | |
4620 | end if; | |
4621 | ||
4622 | Next_Elmt (Prim_Elmt); | |
4623 | end loop; | |
555c63a6 | 4624 | |
17e14451 | 4625 | Freezing_Library_Level_Tagged_Type := Save; |
4626 | end; | |
4627 | end if; | |
725a69d2 | 4628 | |
17e14451 | 4629 | -- Ada 2005 (AI-251): Build the secondary dispatch tables |
4630 | ||
a652dd51 | 4631 | if Has_Interfaces (Typ) then |
17e14451 | 4632 | Collect_Interface_Components (Typ, Typ_Comps); |
4633 | ||
f301a57b | 4634 | -- Each secondary dispatch table is assigned an unique positive |
4635 | -- suffix index; such value also corresponds with the location of | |
4636 | -- its entity in the Dispatch_Table_Wrappers list (see Make_Tags). | |
4637 | ||
4638 | -- Note: This value must be kept sync with the Suffix_Index values | |
4639 | -- generated by Make_Tags | |
4640 | ||
4641 | Suffix_Index := 1; | |
acf97c11 | 4642 | AI_Tag_Elmt := |
4643 | Next_Elmt (Next_Elmt (First_Elmt (Access_Disp_Table (Typ)))); | |
17e14451 | 4644 | |
4645 | AI_Tag_Comp := First_Elmt (Typ_Comps); | |
4646 | while Present (AI_Tag_Comp) loop | |
cdb1c38f | 4647 | |
4648 | -- Build the secondary table containing pointers to thunks | |
4649 | ||
17e14451 | 4650 | Make_Secondary_DT |
cdb1c38f | 4651 | (Typ => Typ, |
4652 | Iface => Base_Type (Related_Type (Node (AI_Tag_Comp))), | |
f301a57b | 4653 | Suffix_Index => Suffix_Index, |
cdb1c38f | 4654 | Num_Iface_Prims => UI_To_Int |
4655 | (DT_Entry_Count (Node (AI_Tag_Comp))), | |
4656 | Iface_DT_Ptr => Node (AI_Tag_Elmt), | |
acf97c11 | 4657 | Predef_Prims_Ptr => Node (Next_Elmt (AI_Tag_Elmt)), |
cdb1c38f | 4658 | Build_Thunks => True, |
4659 | Result => Result); | |
cdb1c38f | 4660 | |
f301a57b | 4661 | -- Skip secondary dispatch table and secondary dispatch table of |
4662 | -- predefined primitives | |
acf97c11 | 4663 | |
f301a57b | 4664 | Next_Elmt (AI_Tag_Elmt); |
acf97c11 | 4665 | Next_Elmt (AI_Tag_Elmt); |
4666 | ||
36b938a3 | 4667 | -- Build the secondary table containing pointers to primitives |
cdb1c38f | 4668 | -- (used to give support to Generic Dispatching Constructors). |
4669 | ||
4670 | Make_Secondary_DT | |
4671 | (Typ => Typ, | |
4672 | Iface => Base_Type (Related_Type (Node (AI_Tag_Comp))), | |
f301a57b | 4673 | Suffix_Index => -1, |
cdb1c38f | 4674 | Num_Iface_Prims => UI_To_Int |
4675 | (DT_Entry_Count (Node (AI_Tag_Comp))), | |
4676 | Iface_DT_Ptr => Node (AI_Tag_Elmt), | |
acf97c11 | 4677 | Predef_Prims_Ptr => Node (Next_Elmt (AI_Tag_Elmt)), |
cdb1c38f | 4678 | Build_Thunks => False, |
4679 | Result => Result); | |
725a69d2 | 4680 | |
f301a57b | 4681 | -- Skip secondary dispatch table and secondary dispatch table of |
4682 | -- predefined primitives | |
acf97c11 | 4683 | |
f301a57b | 4684 | Next_Elmt (AI_Tag_Elmt); |
acf97c11 | 4685 | Next_Elmt (AI_Tag_Elmt); |
4686 | ||
17e14451 | 4687 | Suffix_Index := Suffix_Index + 1; |
17e14451 | 4688 | Next_Elmt (AI_Tag_Comp); |
4689 | end loop; | |
4690 | end if; | |
725a69d2 | 4691 | |
24971415 | 4692 | -- Get the _tag entity and the number of primitives of its dispatch |
4693 | -- table. | |
725a69d2 | 4694 | |
24971415 | 4695 | DT_Ptr := Node (First_Elmt (Access_Disp_Table (Typ))); |
4696 | Nb_Prim := UI_To_Int (DT_Entry_Count (First_Tag_Component (Typ))); | |
725a69d2 | 4697 | |
2ea346ac | 4698 | Set_Is_Statically_Allocated (DT, Is_Library_Level_Tagged_Type (Typ)); |
4699 | Set_Is_Statically_Allocated (SSD, Is_Library_Level_Tagged_Type (Typ)); | |
4700 | Set_Is_Statically_Allocated (TSD, Is_Library_Level_Tagged_Type (Typ)); | |
4701 | Set_Is_Statically_Allocated (Predef_Prims, | |
4702 | Is_Library_Level_Tagged_Type (Typ)); | |
725a69d2 | 4703 | |
4704 | -- In case of locally defined tagged type we declare the object | |
36b938a3 | 4705 | -- containing the dispatch table by means of a variable. Its |
725a69d2 | 4706 | -- initialization is done later by means of an assignment. This is |
4707 | -- required to generate its External_Tag. | |
4708 | ||
24971415 | 4709 | if not Building_Static_DT (Typ) then |
725a69d2 | 4710 | |
4711 | -- Generate: | |
4712 | -- DT : No_Dispatch_Table_Wrapper; | |
17e14451 | 4713 | -- for DT'Alignment use Address'Alignment; |
725a69d2 | 4714 | -- DT_Ptr : Tag := !Tag (DT.NDT_Prims_Ptr'Address); |
4715 | ||
24971415 | 4716 | if not Has_DT (Typ) then |
725a69d2 | 4717 | Append_To (Result, |
4718 | Make_Object_Declaration (Loc, | |
4719 | Defining_Identifier => DT, | |
4720 | Aliased_Present => True, | |
4721 | Constant_Present => False, | |
4722 | Object_Definition => | |
4723 | New_Reference_To | |
4724 | (RTE (RE_No_Dispatch_Table_Wrapper), Loc))); | |
4725 | ||
98045ff0 | 4726 | -- Generate a SCIL node for the previous object declaration |
4727 | -- because it has a null dispatch table. | |
9af28f61 | 4728 | |
3dbca0d5 | 4729 | if Generate_SCIL then |
d215f619 | 4730 | New_Node := |
4731 | Make_SCIL_Dispatch_Table_Object_Init (Sloc (Last (Result))); | |
4732 | Set_SCIL_Related_Node (New_Node, Last (Result)); | |
4733 | Set_SCIL_Entity (New_Node, Typ); | |
4734 | Insert_Before (Last (Result), New_Node); | |
3dbca0d5 | 4735 | end if; |
4736 | ||
17e14451 | 4737 | Append_To (Result, |
4738 | Make_Attribute_Definition_Clause (Loc, | |
4739 | Name => New_Reference_To (DT, Loc), | |
4740 | Chars => Name_Alignment, | |
4741 | Expression => | |
4742 | Make_Attribute_Reference (Loc, | |
4743 | Prefix => | |
4744 | New_Reference_To (RTE (RE_Integer_Address), Loc), | |
4745 | Attribute_Name => Name_Alignment))); | |
4746 | ||
725a69d2 | 4747 | Append_To (Result, |
4748 | Make_Object_Declaration (Loc, | |
4749 | Defining_Identifier => DT_Ptr, | |
4750 | Object_Definition => New_Reference_To (RTE (RE_Tag), Loc), | |
4751 | Constant_Present => True, | |
4752 | Expression => | |
24971415 | 4753 | Unchecked_Convert_To (RTE (RE_Tag), |
725a69d2 | 4754 | Make_Attribute_Reference (Loc, |
4755 | Prefix => | |
4756 | Make_Selected_Component (Loc, | |
4757 | Prefix => New_Reference_To (DT, Loc), | |
4758 | Selector_Name => | |
4759 | New_Occurrence_Of | |
4760 | (RTE_Record_Component (RE_NDT_Prims_Ptr), Loc)), | |
4761 | Attribute_Name => Name_Address)))); | |
4762 | ||
98045ff0 | 4763 | -- Generate the SCIL node for the previous object declaration |
4764 | -- because it has a tag initialization. | |
4765 | ||
3dbca0d5 | 4766 | if Generate_SCIL then |
d215f619 | 4767 | New_Node := |
4768 | Make_SCIL_Dispatch_Table_Tag_Init (Sloc (Last (Result))); | |
4769 | Set_SCIL_Related_Node (New_Node, Last (Result)); | |
4770 | Set_SCIL_Entity (New_Node, Typ); | |
4771 | Insert_Before (Last (Result), New_Node); | |
3dbca0d5 | 4772 | end if; |
4773 | ||
725a69d2 | 4774 | -- Generate: |
4775 | -- DT : Dispatch_Table_Wrapper (Nb_Prim); | |
4776 | -- for DT'Alignment use Address'Alignment; | |
4777 | -- DT_Ptr : Tag := !Tag (DT.Prims_Ptr'Address); | |
4778 | ||
4779 | else | |
4780 | -- If the tagged type has no primitives we add a dummy slot | |
4781 | -- whose address will be the tag of this type. | |
4782 | ||
4783 | if Nb_Prim = 0 then | |
4784 | DT_Constr_List := | |
4785 | New_List (Make_Integer_Literal (Loc, 1)); | |
4786 | else | |
4787 | DT_Constr_List := | |
4788 | New_List (Make_Integer_Literal (Loc, Nb_Prim)); | |
4789 | end if; | |
4790 | ||
4791 | Append_To (Result, | |
4792 | Make_Object_Declaration (Loc, | |
4793 | Defining_Identifier => DT, | |
4794 | Aliased_Present => True, | |
4795 | Constant_Present => False, | |
4796 | Object_Definition => | |
4797 | Make_Subtype_Indication (Loc, | |
4798 | Subtype_Mark => | |
4799 | New_Reference_To (RTE (RE_Dispatch_Table_Wrapper), Loc), | |
4800 | Constraint => Make_Index_Or_Discriminant_Constraint (Loc, | |
4801 | Constraints => DT_Constr_List)))); | |
4802 | ||
98045ff0 | 4803 | -- Generate the SCIL node for the previous object declaration |
4804 | -- because it contains a dispatch table. | |
9af28f61 | 4805 | |
3dbca0d5 | 4806 | if Generate_SCIL then |
d215f619 | 4807 | New_Node := |
4808 | Make_SCIL_Dispatch_Table_Object_Init (Sloc (Last (Result))); | |
4809 | Set_SCIL_Related_Node (New_Node, Last (Result)); | |
4810 | Set_SCIL_Entity (New_Node, Typ); | |
4811 | Insert_Before (Last (Result), New_Node); | |
3dbca0d5 | 4812 | end if; |
4813 | ||
725a69d2 | 4814 | Append_To (Result, |
4815 | Make_Attribute_Definition_Clause (Loc, | |
4816 | Name => New_Reference_To (DT, Loc), | |
4817 | Chars => Name_Alignment, | |
4818 | Expression => | |
4819 | Make_Attribute_Reference (Loc, | |
4820 | Prefix => | |
4821 | New_Reference_To (RTE (RE_Integer_Address), Loc), | |
4822 | Attribute_Name => Name_Alignment))); | |
4823 | ||
4824 | Append_To (Result, | |
4825 | Make_Object_Declaration (Loc, | |
4826 | Defining_Identifier => DT_Ptr, | |
4827 | Object_Definition => New_Reference_To (RTE (RE_Tag), Loc), | |
4828 | Constant_Present => True, | |
4829 | Expression => | |
24971415 | 4830 | Unchecked_Convert_To (RTE (RE_Tag), |
725a69d2 | 4831 | Make_Attribute_Reference (Loc, |
4832 | Prefix => | |
4833 | Make_Selected_Component (Loc, | |
4834 | Prefix => New_Reference_To (DT, Loc), | |
4835 | Selector_Name => | |
4836 | New_Occurrence_Of | |
4837 | (RTE_Record_Component (RE_Prims_Ptr), Loc)), | |
4838 | Attribute_Name => Name_Address)))); | |
acf97c11 | 4839 | |
98045ff0 | 4840 | -- Generate the SCIL node for the previous object declaration |
4841 | -- because it has a tag initialization. | |
9af28f61 | 4842 | |
3dbca0d5 | 4843 | if Generate_SCIL then |
d215f619 | 4844 | New_Node := |
4845 | Make_SCIL_Dispatch_Table_Tag_Init (Sloc (Last (Result))); | |
4846 | Set_SCIL_Related_Node (New_Node, Last (Result)); | |
4847 | Set_SCIL_Entity (New_Node, Typ); | |
4848 | Insert_Before (Last (Result), New_Node); | |
3dbca0d5 | 4849 | end if; |
4850 | ||
acf97c11 | 4851 | Append_To (Result, |
4852 | Make_Object_Declaration (Loc, | |
4853 | Defining_Identifier => | |
4854 | Node (Next_Elmt (First_Elmt (Access_Disp_Table (Typ)))), | |
4855 | Constant_Present => True, | |
4856 | Object_Definition => New_Reference_To | |
4857 | (RTE (RE_Address), Loc), | |
4858 | Expression => | |
4859 | Make_Attribute_Reference (Loc, | |
4860 | Prefix => | |
4861 | Make_Selected_Component (Loc, | |
4862 | Prefix => New_Reference_To (DT, Loc), | |
4863 | Selector_Name => | |
4864 | New_Occurrence_Of | |
4865 | (RTE_Record_Component (RE_Predef_Prims), Loc)), | |
4866 | Attribute_Name => Name_Address))); | |
725a69d2 | 4867 | end if; |
4868 | end if; | |
4869 | ||
4870 | -- Generate: Exname : constant String := full_qualified_name (typ); | |
343d35dc | 4871 | -- The type itself may be an anonymous parent type, so use the first |
4872 | -- subtype to have a user-recognizable name. | |
d62940bf | 4873 | |
343d35dc | 4874 | Append_To (Result, |
4875 | Make_Object_Declaration (Loc, | |
4876 | Defining_Identifier => Exname, | |
4877 | Constant_Present => True, | |
4878 | Object_Definition => New_Reference_To (Standard_String, Loc), | |
4879 | Expression => | |
4880 | Make_String_Literal (Loc, | |
4881 | Full_Qualified_Name (First_Subtype (Typ))))); | |
d62940bf | 4882 | |
24971415 | 4883 | Set_Is_Statically_Allocated (Exname); |
4884 | Set_Is_True_Constant (Exname); | |
4885 | ||
e7e688dd | 4886 | -- Declare the object used by Ada.Tags.Register_Tag |
4887 | ||
4888 | if RTE_Available (RE_Register_Tag) then | |
4889 | Append_To (Result, | |
4890 | Make_Object_Declaration (Loc, | |
4891 | Defining_Identifier => HT_Link, | |
4892 | Object_Definition => New_Reference_To (RTE (RE_Tag), Loc))); | |
4893 | end if; | |
4894 | ||
725a69d2 | 4895 | -- Generate code to create the storage for the type specific data object |
4896 | -- with enough space to store the tags of the ancestors plus the tags | |
4897 | -- of all the implemented interfaces (as described in a-tags.adb). | |
4898 | ||
4899 | -- TSD : Type_Specific_Data (I_Depth) := | |
4900 | -- (Idepth => I_Depth, | |
4901 | -- Access_Level => Type_Access_Level (Typ), | |
4902 | -- Expanded_Name => Cstring_Ptr!(Exname'Address)) | |
4903 | -- External_Tag => Cstring_Ptr!(Exname'Address)) | |
e7e688dd | 4904 | -- HT_Link => HT_Link'Address, |
725a69d2 | 4905 | -- Transportable => <<boolean-value>>, |
4906 | -- RC_Offset => <<integer-value>>, | |
cc60bd16 | 4907 | -- [ Size_Func => Size_Prim'Access ] |
725a69d2 | 4908 | -- [ Interfaces_Table => <<access-value>> ] |
24971415 | 4909 | -- [ SSD => SSD_Table'Address ] |
725a69d2 | 4910 | -- Tags_Table => (0 => null, |
4911 | -- 1 => Parent'Tag | |
4912 | -- ...); | |
4913 | -- for TSD'Alignment use Address'Alignment | |
4914 | ||
4915 | TSD_Aggr_List := New_List; | |
4916 | ||
4917 | -- Idepth: Count ancestors to compute the inheritance depth. For private | |
4918 | -- extensions, always go to the full view in order to compute the real | |
4919 | -- inheritance depth. | |
4920 | ||
4921 | declare | |
4922 | Current_Typ : Entity_Id; | |
4923 | Parent_Typ : Entity_Id; | |
4924 | ||
4925 | begin | |
4926 | I_Depth := 0; | |
4927 | Current_Typ := Typ; | |
4928 | loop | |
4929 | Parent_Typ := Etype (Current_Typ); | |
4930 | ||
4931 | if Is_Private_Type (Parent_Typ) then | |
4932 | Parent_Typ := Full_View (Base_Type (Parent_Typ)); | |
4933 | end if; | |
4934 | ||
4935 | exit when Parent_Typ = Current_Typ; | |
4936 | ||
4937 | I_Depth := I_Depth + 1; | |
4938 | Current_Typ := Parent_Typ; | |
4939 | end loop; | |
4940 | end; | |
4941 | ||
4942 | Append_To (TSD_Aggr_List, | |
17e14451 | 4943 | Make_Integer_Literal (Loc, I_Depth)); |
725a69d2 | 4944 | |
4945 | -- Access_Level | |
4946 | ||
4947 | Append_To (TSD_Aggr_List, | |
17e14451 | 4948 | Make_Integer_Literal (Loc, Type_Access_Level (Typ))); |
725a69d2 | 4949 | |
4950 | -- Expanded_Name | |
4951 | ||
4952 | Append_To (TSD_Aggr_List, | |
17e14451 | 4953 | Unchecked_Convert_To (RTE (RE_Cstring_Ptr), |
4954 | Make_Attribute_Reference (Loc, | |
4955 | Prefix => New_Reference_To (Exname, Loc), | |
4956 | Attribute_Name => Name_Address))); | |
725a69d2 | 4957 | |
4958 | -- External_Tag of a local tagged type | |
4959 | ||
17e14451 | 4960 | -- <typ>A : constant String := |
725a69d2 | 4961 | -- "Internal tag at 16#tag-addr#: <full-name-of-typ>"; |
4962 | ||
4963 | -- The reason we generate this strange name is that we do not want to | |
4964 | -- enter local tagged types in the global hash table used to compute | |
4965 | -- the Internal_Tag attribute for two reasons: | |
4966 | ||
4967 | -- 1. It is hard to avoid a tasking race condition for entering the | |
4968 | -- entry into the hash table. | |
4969 | ||
4970 | -- 2. It would cause a storage leak, unless we rig up considerable | |
4971 | -- mechanism to remove the entry from the hash table on exit. | |
4972 | ||
4973 | -- So what we do is to generate the above external tag name, where the | |
4974 | -- hex address is the address of the local dispatch table (i.e. exactly | |
4975 | -- the value we want if Internal_Tag is computed from this string). | |
4976 | ||
4977 | -- Of course this value will only be valid if the tagged type is still | |
4978 | -- in scope, but it clearly must be erroneous to compute the internal | |
4979 | -- tag of a tagged type that is out of scope! | |
4980 | ||
17e14451 | 4981 | -- We don't do this processing if an explicit external tag has been |
4982 | -- specified. That's an odd case for which we have already issued a | |
4983 | -- warning, where we will not be able to compute the internal tag. | |
4984 | ||
4985 | if not Is_Library_Level_Entity (Typ) | |
4986 | and then not Has_External_Tag_Rep_Clause (Typ) | |
4987 | then | |
725a69d2 | 4988 | declare |
725a69d2 | 4989 | Exname : constant Entity_Id := |
17e14451 | 4990 | Make_Defining_Identifier (Loc, |
4991 | New_External_Name (Tname, 'A')); | |
4992 | ||
725a69d2 | 4993 | Full_Name : constant String_Id := |
4994 | Full_Qualified_Name (First_Subtype (Typ)); | |
4995 | Str1_Id : String_Id; | |
4996 | Str2_Id : String_Id; | |
725a69d2 | 4997 | |
4998 | begin | |
4999 | -- Generate: | |
17e14451 | 5000 | -- Str1 = "Internal tag at 16#"; |
725a69d2 | 5001 | |
5002 | Start_String; | |
5003 | Store_String_Chars ("Internal tag at 16#"); | |
5004 | Str1_Id := End_String; | |
5005 | ||
5006 | -- Generate: | |
17e14451 | 5007 | -- Str2 = "#: <type-full-name>"; |
725a69d2 | 5008 | |
5009 | Start_String; | |
5010 | Store_String_Chars ("#: "); | |
725a69d2 | 5011 | Store_String_Chars (Full_Name); |
17e14451 | 5012 | Str2_Id := End_String; |
725a69d2 | 5013 | |
5014 | -- Generate: | |
5015 | -- Exname : constant String := | |
17e14451 | 5016 | -- Str1 & Address_Image (Tag) & Str2; |
725a69d2 | 5017 | |
5018 | if RTE_Available (RE_Address_Image) then | |
5019 | Append_To (Result, | |
5020 | Make_Object_Declaration (Loc, | |
5021 | Defining_Identifier => Exname, | |
5022 | Constant_Present => True, | |
5023 | Object_Definition => New_Reference_To | |
5024 | (Standard_String, Loc), | |
5025 | Expression => | |
5026 | Make_Op_Concat (Loc, | |
5027 | Left_Opnd => | |
5028 | Make_String_Literal (Loc, Str1_Id), | |
5029 | Right_Opnd => | |
5030 | Make_Op_Concat (Loc, | |
5031 | Left_Opnd => | |
5032 | Make_Function_Call (Loc, | |
5033 | Name => | |
5034 | New_Reference_To | |
5035 | (RTE (RE_Address_Image), Loc), | |
5036 | Parameter_Associations => New_List ( | |
5037 | Unchecked_Convert_To (RTE (RE_Address), | |
5038 | New_Reference_To (DT_Ptr, Loc)))), | |
5039 | Right_Opnd => | |
17e14451 | 5040 | Make_String_Literal (Loc, Str2_Id))))); |
5041 | ||
725a69d2 | 5042 | else |
5043 | Append_To (Result, | |
5044 | Make_Object_Declaration (Loc, | |
5045 | Defining_Identifier => Exname, | |
5046 | Constant_Present => True, | |
5047 | Object_Definition => New_Reference_To | |
5048 | (Standard_String, Loc), | |
5049 | Expression => | |
5050 | Make_Op_Concat (Loc, | |
5051 | Left_Opnd => | |
5052 | Make_String_Literal (Loc, Str1_Id), | |
5053 | Right_Opnd => | |
17e14451 | 5054 | Make_String_Literal (Loc, Str2_Id)))); |
725a69d2 | 5055 | end if; |
5056 | ||
5057 | New_Node := | |
5058 | Unchecked_Convert_To (RTE (RE_Cstring_Ptr), | |
5059 | Make_Attribute_Reference (Loc, | |
5060 | Prefix => New_Reference_To (Exname, Loc), | |
5061 | Attribute_Name => Name_Address)); | |
5062 | end; | |
5063 | ||
5064 | -- External tag of a library-level tagged type: Check for a definition | |
5065 | -- of External_Tag. The clause is considered only if it applies to this | |
5066 | -- specific tagged type, as opposed to one of its ancestors. | |
cc60bd16 | 5067 | -- If the type is an unconstrained type extension, we are building the |
5068 | -- dispatch table of its anonymous base type, so the external tag, if | |
34fd8639 | 5069 | -- any was specified, must be retrieved from the first subtype. Go to |
5070 | -- the full view in case the clause is in the private part. | |
725a69d2 | 5071 | |
5072 | else | |
5073 | declare | |
cc60bd16 | 5074 | Def : constant Node_Id := Get_Attribute_Definition_Clause |
34fd8639 | 5075 | (Underlying_Type (First_Subtype (Typ)), |
cc60bd16 | 5076 | Attribute_External_Tag); |
5077 | ||
725a69d2 | 5078 | Old_Val : String_Id; |
5079 | New_Val : String_Id; | |
5080 | E : Entity_Id; | |
5081 | ||
5082 | begin | |
5083 | if not Present (Def) | |
cc60bd16 | 5084 | or else Entity (Name (Def)) /= First_Subtype (Typ) |
725a69d2 | 5085 | then |
5086 | New_Node := | |
5087 | Unchecked_Convert_To (RTE (RE_Cstring_Ptr), | |
5088 | Make_Attribute_Reference (Loc, | |
cc60bd16 | 5089 | Prefix => New_Reference_To (Exname, Loc), |
725a69d2 | 5090 | Attribute_Name => Name_Address)); |
5091 | else | |
5092 | Old_Val := Strval (Expr_Value_S (Expression (Def))); | |
5093 | ||
17e14451 | 5094 | -- For the rep clause "for <typ>'external_tag use y" generate: |
725a69d2 | 5095 | |
17e14451 | 5096 | -- <typ>A : constant string := y; |
5097 | -- | |
5098 | -- <typ>A'Address is used to set the External_Tag component | |
5099 | -- of the TSD | |
725a69d2 | 5100 | |
5101 | -- Create a new nul terminated string if it is not already | |
5102 | ||
5103 | if String_Length (Old_Val) > 0 | |
5104 | and then | |
5105 | Get_String_Char (Old_Val, String_Length (Old_Val)) = 0 | |
5106 | then | |
5107 | New_Val := Old_Val; | |
5108 | else | |
5109 | Start_String (Old_Val); | |
5110 | Store_String_Char (Get_Char_Code (ASCII.NUL)); | |
5111 | New_Val := End_String; | |
5112 | end if; | |
5113 | ||
5114 | E := Make_Defining_Identifier (Loc, | |
5115 | New_External_Name (Chars (Typ), 'A')); | |
5116 | ||
5117 | Append_To (Result, | |
5118 | Make_Object_Declaration (Loc, | |
5119 | Defining_Identifier => E, | |
5120 | Constant_Present => True, | |
5121 | Object_Definition => | |
5122 | New_Reference_To (Standard_String, Loc), | |
5123 | Expression => | |
5124 | Make_String_Literal (Loc, New_Val))); | |
5125 | ||
5126 | New_Node := | |
5127 | Unchecked_Convert_To (RTE (RE_Cstring_Ptr), | |
5128 | Make_Attribute_Reference (Loc, | |
5129 | Prefix => New_Reference_To (E, Loc), | |
5130 | Attribute_Name => Name_Address)); | |
5131 | end if; | |
5132 | end; | |
5133 | end if; | |
5134 | ||
17e14451 | 5135 | Append_To (TSD_Aggr_List, New_Node); |
725a69d2 | 5136 | |
5137 | -- HT_Link | |
5138 | ||
e7e688dd | 5139 | if RTE_Available (RE_Register_Tag) then |
5140 | Append_To (TSD_Aggr_List, | |
5141 | Unchecked_Convert_To (RTE (RE_Tag_Ptr), | |
5142 | Make_Attribute_Reference (Loc, | |
5143 | Prefix => New_Reference_To (HT_Link, Loc), | |
5144 | Attribute_Name => Name_Address))); | |
5145 | else | |
5146 | Append_To (TSD_Aggr_List, | |
5147 | Unchecked_Convert_To (RTE (RE_Tag_Ptr), | |
5148 | New_Reference_To (RTE (RE_Null_Address), Loc))); | |
5149 | end if; | |
725a69d2 | 5150 | |
5151 | -- Transportable: Set for types that can be used in remote calls | |
5152 | -- with respect to E.4(18) legality rules. | |
5153 | ||
17e14451 | 5154 | declare |
5155 | Transportable : Entity_Id; | |
725a69d2 | 5156 | |
17e14451 | 5157 | begin |
5158 | Transportable := | |
5159 | Boolean_Literals | |
5160 | (Is_Pure (Typ) | |
5161 | or else Is_Shared_Passive (Typ) | |
5162 | or else | |
5163 | ((Is_Remote_Types (Typ) | |
5164 | or else Is_Remote_Call_Interface (Typ)) | |
5165 | and then Original_View_In_Visible_Part (Typ)) | |
5166 | or else not Comes_From_Source (Typ)); | |
5167 | ||
5168 | Append_To (TSD_Aggr_List, | |
5169 | New_Occurrence_Of (Transportable, Loc)); | |
5170 | end; | |
725a69d2 | 5171 | |
5172 | -- RC_Offset: These are the valid values and their meaning: | |
5173 | ||
343d35dc | 5174 | -- >0: For simple types with controlled components is |
5175 | -- type._record_controller'position | |
725a69d2 | 5176 | |
343d35dc | 5177 | -- 0: For types with no controlled components |
725a69d2 | 5178 | |
343d35dc | 5179 | -- -1: For complex types with controlled components where the position |
5180 | -- of the record controller is not statically computable but there | |
5181 | -- are controlled components at this level. The _Controller field | |
5182 | -- is available right after the _parent. | |
725a69d2 | 5183 | |
343d35dc | 5184 | -- -2: There are no controlled components at this level. We need to |
5185 | -- get the position from the parent. | |
952af0b9 | 5186 | |
17e14451 | 5187 | declare |
5188 | RC_Offset_Node : Node_Id; | |
343d35dc | 5189 | |
17e14451 | 5190 | begin |
5191 | if not Has_Controlled_Component (Typ) then | |
5192 | RC_Offset_Node := Make_Integer_Literal (Loc, 0); | |
5193 | ||
5194 | elsif Etype (Typ) /= Typ | |
cdb1c38f | 5195 | and then Has_Discriminants (Parent_Typ) |
17e14451 | 5196 | then |
5197 | if Has_New_Controlled_Component (Typ) then | |
5198 | RC_Offset_Node := Make_Integer_Literal (Loc, -1); | |
5199 | else | |
5200 | RC_Offset_Node := Make_Integer_Literal (Loc, -2); | |
5201 | end if; | |
343d35dc | 5202 | else |
17e14451 | 5203 | RC_Offset_Node := |
5204 | Make_Attribute_Reference (Loc, | |
5205 | Prefix => | |
5206 | Make_Selected_Component (Loc, | |
5207 | Prefix => New_Reference_To (Typ, Loc), | |
5208 | Selector_Name => | |
5209 | New_Reference_To (Controller_Component (Typ), Loc)), | |
5210 | Attribute_Name => Name_Position); | |
5211 | ||
5212 | -- This is not proper Ada code to use the attribute 'Position | |
5213 | -- on something else than an object but this is supported by | |
5214 | -- the back end (see comment on the Bit_Component attribute in | |
5215 | -- sem_attr). So we avoid semantic checking here. | |
5216 | ||
5217 | -- Is this documented in sinfo.ads??? it should be! | |
5218 | ||
5219 | Set_Analyzed (RC_Offset_Node); | |
5220 | Set_Etype (Prefix (RC_Offset_Node), RTE (RE_Record_Controller)); | |
5221 | Set_Etype (Prefix (Prefix (RC_Offset_Node)), Typ); | |
5222 | Set_Etype (Selector_Name (Prefix (RC_Offset_Node)), | |
5223 | RTE (RE_Record_Controller)); | |
5224 | Set_Etype (RC_Offset_Node, RTE (RE_Storage_Offset)); | |
68f95949 | 5225 | end if; |
952af0b9 | 5226 | |
17e14451 | 5227 | Append_To (TSD_Aggr_List, RC_Offset_Node); |
5228 | end; | |
725a69d2 | 5229 | |
cc60bd16 | 5230 | -- Size_Func |
5231 | ||
5232 | if RTE_Record_Component_Available (RE_Size_Func) then | |
5233 | if not Building_Static_DT (Typ) | |
5234 | or else Is_Interface (Typ) | |
5235 | then | |
5236 | Append_To (TSD_Aggr_List, | |
5237 | Unchecked_Convert_To (RTE (RE_Size_Ptr), | |
5238 | New_Reference_To (RTE (RE_Null_Address), Loc))); | |
5239 | ||
5240 | else | |
5241 | declare | |
5242 | Prim_Elmt : Elmt_Id; | |
5243 | Prim : Entity_Id; | |
5244 | ||
5245 | begin | |
5246 | Prim_Elmt := First_Elmt (Primitive_Operations (Typ)); | |
5247 | while Present (Prim_Elmt) loop | |
5248 | Prim := Node (Prim_Elmt); | |
5249 | ||
5250 | if Chars (Prim) = Name_uSize then | |
5251 | while Present (Alias (Prim)) loop | |
5252 | Prim := Alias (Prim); | |
5253 | end loop; | |
5254 | ||
5255 | if Is_Abstract_Subprogram (Prim) then | |
5256 | Append_To (TSD_Aggr_List, | |
5257 | Unchecked_Convert_To (RTE (RE_Size_Ptr), | |
5258 | New_Reference_To (RTE (RE_Null_Address), Loc))); | |
5259 | else | |
5260 | Append_To (TSD_Aggr_List, | |
5261 | Unchecked_Convert_To (RTE (RE_Size_Ptr), | |
5262 | Make_Attribute_Reference (Loc, | |
5263 | Prefix => New_Reference_To (Prim, Loc), | |
5264 | Attribute_Name => Name_Unrestricted_Access))); | |
5265 | end if; | |
5266 | ||
5267 | exit; | |
5268 | end if; | |
5269 | ||
5270 | Next_Elmt (Prim_Elmt); | |
5271 | end loop; | |
5272 | end; | |
5273 | end if; | |
5274 | end if; | |
5275 | ||
725a69d2 | 5276 | -- Interfaces_Table (required for AI-405) |
5277 | ||
5278 | if RTE_Record_Component_Available (RE_Interfaces_Table) then | |
5279 | ||
5280 | -- Count the number of interface types implemented by Typ | |
5281 | ||
a652dd51 | 5282 | Collect_Interfaces (Typ, Typ_Ifaces); |
725a69d2 | 5283 | |
5284 | AI := First_Elmt (Typ_Ifaces); | |
5285 | while Present (AI) loop | |
5286 | Num_Ifaces := Num_Ifaces + 1; | |
5287 | Next_Elmt (AI); | |
5288 | end loop; | |
952af0b9 | 5289 | |
343d35dc | 5290 | if Num_Ifaces = 0 then |
725a69d2 | 5291 | Iface_Table_Node := Make_Null (Loc); |
952af0b9 | 5292 | |
725a69d2 | 5293 | -- Generate the Interface_Table object |
343d35dc | 5294 | |
5295 | else | |
725a69d2 | 5296 | declare |
17e14451 | 5297 | TSD_Ifaces_List : constant List_Id := New_List; |
cdb1c38f | 5298 | Elmt : Elmt_Id; |
5299 | Sec_DT_Tag : Node_Id; | |
725a69d2 | 5300 | |
5301 | begin | |
5302 | AI := First_Elmt (Typ_Ifaces); | |
5303 | while Present (AI) loop | |
a652dd51 | 5304 | if Is_Ancestor (Node (AI), Typ) then |
cdb1c38f | 5305 | Sec_DT_Tag := |
5306 | New_Reference_To (DT_Ptr, Loc); | |
5307 | else | |
acf97c11 | 5308 | Elmt := |
5309 | Next_Elmt | |
5310 | (Next_Elmt (First_Elmt (Access_Disp_Table (Typ)))); | |
cdb1c38f | 5311 | pragma Assert (Has_Thunks (Node (Elmt))); |
5312 | ||
5313 | while Ekind (Node (Elmt)) = E_Constant | |
5314 | and then not | |
a652dd51 | 5315 | Is_Ancestor (Node (AI), Related_Type (Node (Elmt))) |
cdb1c38f | 5316 | loop |
5317 | pragma Assert (Has_Thunks (Node (Elmt))); | |
5318 | Next_Elmt (Elmt); | |
acf97c11 | 5319 | pragma Assert (Has_Thunks (Node (Elmt))); |
5320 | Next_Elmt (Elmt); | |
5321 | pragma Assert (not Has_Thunks (Node (Elmt))); | |
5322 | Next_Elmt (Elmt); | |
cdb1c38f | 5323 | pragma Assert (not Has_Thunks (Node (Elmt))); |
5324 | Next_Elmt (Elmt); | |
5325 | end loop; | |
5326 | ||
5327 | pragma Assert (Ekind (Node (Elmt)) = E_Constant | |
acf97c11 | 5328 | and then not |
5329 | Has_Thunks (Node (Next_Elmt (Next_Elmt (Elmt))))); | |
cdb1c38f | 5330 | Sec_DT_Tag := |
acf97c11 | 5331 | New_Reference_To (Node (Next_Elmt (Next_Elmt (Elmt))), |
5332 | Loc); | |
cdb1c38f | 5333 | end if; |
5334 | ||
17e14451 | 5335 | Append_To (TSD_Ifaces_List, |
5336 | Make_Aggregate (Loc, | |
5337 | Expressions => New_List ( | |
5338 | ||
5339 | -- Iface_Tag | |
5340 | ||
24971415 | 5341 | Unchecked_Convert_To (RTE (RE_Tag), |
725a69d2 | 5342 | New_Reference_To |
5343 | (Node (First_Elmt (Access_Disp_Table (Node (AI)))), | |
17e14451 | 5344 | Loc)), |
725a69d2 | 5345 | |
17e14451 | 5346 | -- Static_Offset_To_Top |
725a69d2 | 5347 | |
17e14451 | 5348 | New_Reference_To (Standard_True, Loc), |
725a69d2 | 5349 | |
17e14451 | 5350 | -- Offset_To_Top_Value |
5351 | ||
5352 | Make_Integer_Literal (Loc, 0), | |
5353 | ||
5354 | -- Offset_To_Top_Func | |
5355 | ||
cdb1c38f | 5356 | Make_Null (Loc), |
5357 | ||
5358 | -- Secondary_DT | |
5359 | ||
5360 | Unchecked_Convert_To (RTE (RE_Tag), Sec_DT_Tag) | |
5361 | ||
5362 | ))); | |
725a69d2 | 5363 | |
725a69d2 | 5364 | Next_Elmt (AI); |
5365 | end loop; | |
725a69d2 | 5366 | |
17e14451 | 5367 | Name_ITable := New_External_Name (Tname, 'I'); |
5368 | ITable := Make_Defining_Identifier (Loc, Name_ITable); | |
2ea346ac | 5369 | Set_Is_Statically_Allocated (ITable, |
5370 | Is_Library_Level_Tagged_Type (Typ)); | |
725a69d2 | 5371 | |
17e14451 | 5372 | -- The table of interfaces is not constant; its slots are |
5373 | -- filled at run-time by the IP routine using attribute | |
5374 | -- 'Position to know the location of the tag components | |
5375 | -- (and this attribute cannot be safely used before the | |
5376 | -- object is initialized). | |
725a69d2 | 5377 | |
17e14451 | 5378 | Append_To (Result, |
5379 | Make_Object_Declaration (Loc, | |
5380 | Defining_Identifier => ITable, | |
5381 | Aliased_Present => True, | |
5382 | Constant_Present => False, | |
5383 | Object_Definition => | |
5384 | Make_Subtype_Indication (Loc, | |
5385 | Subtype_Mark => | |
5386 | New_Reference_To (RTE (RE_Interface_Data), Loc), | |
5387 | Constraint => Make_Index_Or_Discriminant_Constraint | |
5388 | (Loc, | |
5389 | Constraints => New_List ( | |
5390 | Make_Integer_Literal (Loc, Num_Ifaces)))), | |
725a69d2 | 5391 | |
17e14451 | 5392 | Expression => Make_Aggregate (Loc, |
5393 | Expressions => New_List ( | |
5394 | Make_Integer_Literal (Loc, Num_Ifaces), | |
5395 | Make_Aggregate (Loc, | |
5396 | Expressions => TSD_Ifaces_List))))); | |
725a69d2 | 5397 | |
17e14451 | 5398 | Append_To (Result, |
5399 | Make_Attribute_Definition_Clause (Loc, | |
5400 | Name => New_Reference_To (ITable, Loc), | |
5401 | Chars => Name_Alignment, | |
5402 | Expression => | |
5403 | Make_Attribute_Reference (Loc, | |
5404 | Prefix => | |
5405 | New_Reference_To (RTE (RE_Integer_Address), Loc), | |
5406 | Attribute_Name => Name_Alignment))); | |
725a69d2 | 5407 | |
17e14451 | 5408 | Iface_Table_Node := |
5409 | Make_Attribute_Reference (Loc, | |
5410 | Prefix => New_Reference_To (ITable, Loc), | |
5411 | Attribute_Name => Name_Unchecked_Access); | |
5412 | end; | |
725a69d2 | 5413 | end if; |
5414 | ||
17e14451 | 5415 | Append_To (TSD_Aggr_List, Iface_Table_Node); |
725a69d2 | 5416 | end if; |
5417 | ||
5418 | -- Generate the Select Specific Data table for synchronized types that | |
5419 | -- implement synchronized interfaces. The size of the table is | |
5420 | -- constrained by the number of non-predefined primitive operations. | |
5421 | ||
5422 | if RTE_Record_Component_Available (RE_SSD) then | |
5423 | if Ada_Version >= Ada_05 | |
24971415 | 5424 | and then Has_DT (Typ) |
725a69d2 | 5425 | and then Is_Concurrent_Record_Type (Typ) |
a652dd51 | 5426 | and then Has_Interfaces (Typ) |
725a69d2 | 5427 | and then Nb_Prim > 0 |
5428 | and then not Is_Abstract_Type (Typ) | |
5429 | and then not Is_Controlled (Typ) | |
5430 | and then not Restriction_Active (No_Dispatching_Calls) | |
f38c8084 | 5431 | and then not Restriction_Active (No_Select_Statements) |
725a69d2 | 5432 | then |
343d35dc | 5433 | Append_To (Result, |
5434 | Make_Object_Declaration (Loc, | |
725a69d2 | 5435 | Defining_Identifier => SSD, |
343d35dc | 5436 | Aliased_Present => True, |
5437 | Object_Definition => | |
5438 | Make_Subtype_Indication (Loc, | |
725a69d2 | 5439 | Subtype_Mark => New_Reference_To ( |
5440 | RTE (RE_Select_Specific_Data), Loc), | |
5441 | Constraint => | |
5442 | Make_Index_Or_Discriminant_Constraint (Loc, | |
5443 | Constraints => New_List ( | |
5444 | Make_Integer_Literal (Loc, Nb_Prim)))))); | |
5445 | ||
17e14451 | 5446 | Append_To (Result, |
5447 | Make_Attribute_Definition_Clause (Loc, | |
5448 | Name => New_Reference_To (SSD, Loc), | |
5449 | Chars => Name_Alignment, | |
5450 | Expression => | |
5451 | Make_Attribute_Reference (Loc, | |
5452 | Prefix => | |
5453 | New_Reference_To (RTE (RE_Integer_Address), Loc), | |
5454 | Attribute_Name => Name_Alignment))); | |
5455 | ||
725a69d2 | 5456 | -- This table is initialized by Make_Select_Specific_Data_Table, |
5457 | -- which calls Set_Entry_Index and Set_Prim_Op_Kind. | |
5458 | ||
5459 | Append_To (TSD_Aggr_List, | |
17e14451 | 5460 | Make_Attribute_Reference (Loc, |
5461 | Prefix => New_Reference_To (SSD, Loc), | |
5462 | Attribute_Name => Name_Unchecked_Access)); | |
725a69d2 | 5463 | else |
17e14451 | 5464 | Append_To (TSD_Aggr_List, Make_Null (Loc)); |
343d35dc | 5465 | end if; |
952af0b9 | 5466 | end if; |
5467 | ||
725a69d2 | 5468 | -- Initialize the table of ancestor tags. In case of interface types |
5469 | -- this table is not needed. | |
d62940bf | 5470 | |
cc60bd16 | 5471 | TSD_Tags_List := New_List; |
952af0b9 | 5472 | |
cc60bd16 | 5473 | -- If we are not statically allocating the dispatch table then we must |
5474 | -- fill position 0 with null because we still have not generated the | |
5475 | -- tag of Typ. | |
343d35dc | 5476 | |
cc60bd16 | 5477 | if not Building_Static_DT (Typ) |
5478 | or else Is_Interface (Typ) | |
5479 | then | |
5480 | Append_To (TSD_Tags_List, | |
5481 | Unchecked_Convert_To (RTE (RE_Tag), | |
5482 | New_Reference_To (RTE (RE_Null_Address), Loc))); | |
343d35dc | 5483 | |
cc60bd16 | 5484 | -- Otherwise we can safely reference the tag |
343d35dc | 5485 | |
cc60bd16 | 5486 | else |
5487 | Append_To (TSD_Tags_List, | |
5488 | New_Reference_To (DT_Ptr, Loc)); | |
5489 | end if; | |
343d35dc | 5490 | |
cc60bd16 | 5491 | -- Fill the rest of the table with the tags of the ancestors |
343d35dc | 5492 | |
cc60bd16 | 5493 | declare |
5494 | Current_Typ : Entity_Id; | |
5495 | Parent_Typ : Entity_Id; | |
5496 | Pos : Nat; | |
725a69d2 | 5497 | |
cc60bd16 | 5498 | begin |
17e14451 | 5499 | Pos := 1; |
5500 | Current_Typ := Typ; | |
725a69d2 | 5501 | |
17e14451 | 5502 | loop |
5503 | Parent_Typ := Etype (Current_Typ); | |
343d35dc | 5504 | |
17e14451 | 5505 | if Is_Private_Type (Parent_Typ) then |
5506 | Parent_Typ := Full_View (Base_Type (Parent_Typ)); | |
5507 | end if; | |
5508 | ||
5509 | exit when Parent_Typ = Current_Typ; | |
5510 | ||
5511 | if Is_CPP_Class (Parent_Typ) | |
5512 | or else Is_Interface (Typ) | |
5513 | then | |
5514 | -- The tags defined in the C++ side will be inherited when | |
5515 | -- the object is constructed (Exp_Ch3.Build_Init_Procedure) | |
5516 | ||
5517 | Append_To (TSD_Tags_List, | |
5518 | Unchecked_Convert_To (RTE (RE_Tag), | |
5519 | New_Reference_To (RTE (RE_Null_Address), Loc))); | |
5520 | else | |
5521 | Append_To (TSD_Tags_List, | |
5522 | New_Reference_To | |
5523 | (Node (First_Elmt (Access_Disp_Table (Parent_Typ))), | |
5524 | Loc)); | |
5525 | end if; | |
5526 | ||
5527 | Pos := Pos + 1; | |
5528 | Current_Typ := Parent_Typ; | |
5529 | end loop; | |
5530 | ||
5531 | pragma Assert (Pos = I_Depth + 1); | |
5532 | end; | |
5533 | ||
5534 | Append_To (TSD_Aggr_List, | |
5535 | Make_Aggregate (Loc, | |
5536 | Expressions => TSD_Tags_List)); | |
343d35dc | 5537 | |
725a69d2 | 5538 | -- Build the TSD object |
343d35dc | 5539 | |
5540 | Append_To (Result, | |
5541 | Make_Object_Declaration (Loc, | |
5542 | Defining_Identifier => TSD, | |
5543 | Aliased_Present => True, | |
24971415 | 5544 | Constant_Present => Building_Static_DT (Typ), |
343d35dc | 5545 | Object_Definition => |
5546 | Make_Subtype_Indication (Loc, | |
5547 | Subtype_Mark => New_Reference_To ( | |
5548 | RTE (RE_Type_Specific_Data), Loc), | |
5549 | Constraint => | |
5550 | Make_Index_Or_Discriminant_Constraint (Loc, | |
5551 | Constraints => New_List ( | |
5552 | Make_Integer_Literal (Loc, I_Depth)))), | |
725a69d2 | 5553 | |
343d35dc | 5554 | Expression => Make_Aggregate (Loc, |
17e14451 | 5555 | Expressions => TSD_Aggr_List))); |
343d35dc | 5556 | |
24971415 | 5557 | Set_Is_True_Constant (TSD, Building_Static_DT (Typ)); |
5558 | ||
343d35dc | 5559 | Append_To (Result, |
5560 | Make_Attribute_Definition_Clause (Loc, | |
5561 | Name => New_Reference_To (TSD, Loc), | |
5562 | Chars => Name_Alignment, | |
5563 | Expression => | |
5564 | Make_Attribute_Reference (Loc, | |
5565 | Prefix => New_Reference_To (RTE (RE_Integer_Address), Loc), | |
5566 | Attribute_Name => Name_Alignment))); | |
5567 | ||
24971415 | 5568 | -- Initialize or declare the dispatch table object |
343d35dc | 5569 | |
24971415 | 5570 | if not Has_DT (Typ) then |
725a69d2 | 5571 | DT_Constr_List := New_List; |
5572 | DT_Aggr_List := New_List; | |
343d35dc | 5573 | |
725a69d2 | 5574 | -- Typeinfo |
952af0b9 | 5575 | |
725a69d2 | 5576 | New_Node := |
5577 | Make_Attribute_Reference (Loc, | |
5578 | Prefix => New_Reference_To (TSD, Loc), | |
5579 | Attribute_Name => Name_Address); | |
5580 | ||
5581 | Append_To (DT_Constr_List, New_Node); | |
5582 | Append_To (DT_Aggr_List, New_Copy (New_Node)); | |
5583 | Append_To (DT_Aggr_List, Make_Integer_Literal (Loc, 0)); | |
5584 | ||
5585 | -- In case of locally defined tagged types we have already declared | |
5586 | -- and uninitialized object for the dispatch table, which is now | |
24971415 | 5587 | -- initialized by means of the following assignment: |
5588 | ||
5589 | -- DT := (TSD'Address, 0); | |
725a69d2 | 5590 | |
24971415 | 5591 | if not Building_Static_DT (Typ) then |
725a69d2 | 5592 | Append_To (Result, |
5593 | Make_Assignment_Statement (Loc, | |
5594 | Name => New_Reference_To (DT, Loc), | |
5595 | Expression => Make_Aggregate (Loc, | |
5596 | Expressions => DT_Aggr_List))); | |
5597 | ||
24971415 | 5598 | -- In case of library level tagged types we declare and export now |
5599 | -- the constant object containing the dummy dispatch table. There | |
5600 | -- is no need to declare the tag here because it has been previously | |
5601 | -- declared by Make_Tags | |
5602 | ||
5603 | -- DT : aliased constant No_Dispatch_Table := | |
5604 | -- (NDT_TSD => TSD'Address; | |
5605 | -- NDT_Prims_Ptr => 0); | |
5606 | -- for DT'Alignment use Address'Alignment; | |
725a69d2 | 5607 | |
5608 | else | |
5609 | Append_To (Result, | |
5610 | Make_Object_Declaration (Loc, | |
5611 | Defining_Identifier => DT, | |
5612 | Aliased_Present => True, | |
17e14451 | 5613 | Constant_Present => True, |
725a69d2 | 5614 | Object_Definition => |
5615 | New_Reference_To (RTE (RE_No_Dispatch_Table_Wrapper), Loc), | |
5616 | Expression => Make_Aggregate (Loc, | |
5617 | Expressions => DT_Aggr_List))); | |
5618 | ||
98045ff0 | 5619 | -- Generate the SCIL node for the previous object declaration |
5620 | -- because it has a null dispatch table. | |
9af28f61 | 5621 | |
3dbca0d5 | 5622 | if Generate_SCIL then |
d215f619 | 5623 | New_Node := |
5624 | Make_SCIL_Dispatch_Table_Object_Init (Sloc (Last (Result))); | |
5625 | Set_SCIL_Related_Node (New_Node, Last (Result)); | |
5626 | Set_SCIL_Entity (New_Node, Typ); | |
5627 | Insert_Before (Last (Result), New_Node); | |
3dbca0d5 | 5628 | end if; |
5629 | ||
17e14451 | 5630 | Append_To (Result, |
5631 | Make_Attribute_Definition_Clause (Loc, | |
5632 | Name => New_Reference_To (DT, Loc), | |
5633 | Chars => Name_Alignment, | |
5634 | Expression => | |
5635 | Make_Attribute_Reference (Loc, | |
5636 | Prefix => | |
5637 | New_Reference_To (RTE (RE_Integer_Address), Loc), | |
5638 | Attribute_Name => Name_Alignment))); | |
5639 | ||
24971415 | 5640 | Export_DT (Typ, DT); |
725a69d2 | 5641 | end if; |
5642 | ||
5643 | -- Common case: Typ has a dispatch table | |
5644 | ||
5645 | -- Generate: | |
5646 | ||
5647 | -- Predef_Prims : Address_Array (1 .. Default_Prim_Ops_Count) := | |
5648 | -- (predef-prim-op-1'address, | |
5649 | -- predef-prim-op-2'address, | |
5650 | -- ... | |
5651 | -- predef-prim-op-n'address); | |
5652 | -- for Predef_Prims'Alignment use Address'Alignment | |
5653 | ||
5654 | -- DT : Dispatch_Table (Nb_Prims) := | |
5655 | -- (Signature => <sig-value>, | |
5656 | -- Tag_Kind => <tag_kind-value>, | |
5657 | -- Predef_Prims => Predef_Prims'First'Address, | |
5658 | -- Offset_To_Top => 0, | |
5659 | -- TSD => TSD'Address; | |
5660 | -- Prims_Ptr => (prim-op-1'address, | |
5661 | -- prim-op-2'address, | |
5662 | -- ... | |
5663 | -- prim-op-n'address)); | |
17e14451 | 5664 | -- for DT'Alignment use Address'Alignment |
725a69d2 | 5665 | |
5666 | else | |
5667 | declare | |
5668 | Pos : Nat; | |
5669 | ||
5670 | begin | |
24971415 | 5671 | if not Building_Static_DT (Typ) then |
725a69d2 | 5672 | Nb_Predef_Prims := Max_Predef_Prims; |
5673 | ||
5674 | else | |
5675 | Prim_Elmt := First_Elmt (Primitive_Operations (Typ)); | |
5676 | while Present (Prim_Elmt) loop | |
5677 | Prim := Node (Prim_Elmt); | |
5678 | ||
5679 | if Is_Predefined_Dispatching_Operation (Prim) | |
5680 | and then not Is_Abstract_Subprogram (Prim) | |
5681 | then | |
5682 | Pos := UI_To_Int (DT_Position (Prim)); | |
5683 | ||
5684 | if Pos > Nb_Predef_Prims then | |
5685 | Nb_Predef_Prims := Pos; | |
5686 | end if; | |
5687 | end if; | |
5688 | ||
5689 | Next_Elmt (Prim_Elmt); | |
5690 | end loop; | |
5691 | end if; | |
5692 | ||
5693 | declare | |
5694 | Prim_Table : array | |
5695 | (Nat range 1 .. Nb_Predef_Prims) of Entity_Id; | |
cc60bd16 | 5696 | Decl : Node_Id; |
725a69d2 | 5697 | E : Entity_Id; |
5698 | ||
5699 | begin | |
5700 | Prim_Ops_Aggr_List := New_List; | |
5701 | ||
5702 | Prim_Table := (others => Empty); | |
17e14451 | 5703 | |
cdb1c38f | 5704 | if Building_Static_DT (Typ) then |
5705 | Prim_Elmt := First_Elmt (Primitive_Operations (Typ)); | |
5706 | while Present (Prim_Elmt) loop | |
5707 | Prim := Node (Prim_Elmt); | |
725a69d2 | 5708 | |
cdb1c38f | 5709 | if Is_Predefined_Dispatching_Operation (Prim) |
5710 | and then not Is_Abstract_Subprogram (Prim) | |
5711 | and then not Present (Prim_Table | |
5712 | (UI_To_Int (DT_Position (Prim)))) | |
5713 | then | |
5714 | E := Prim; | |
5715 | while Present (Alias (E)) loop | |
5716 | E := Alias (E); | |
5717 | end loop; | |
725a69d2 | 5718 | |
cdb1c38f | 5719 | pragma Assert (not Is_Abstract_Subprogram (E)); |
5720 | Prim_Table (UI_To_Int (DT_Position (Prim))) := E; | |
5721 | end if; | |
725a69d2 | 5722 | |
cdb1c38f | 5723 | Next_Elmt (Prim_Elmt); |
5724 | end loop; | |
5725 | end if; | |
725a69d2 | 5726 | |
5727 | for J in Prim_Table'Range loop | |
5728 | if Present (Prim_Table (J)) then | |
5729 | New_Node := | |
cc60bd16 | 5730 | Unchecked_Convert_To (RTE (RE_Prim_Ptr), |
acf97c11 | 5731 | Make_Attribute_Reference (Loc, |
5732 | Prefix => New_Reference_To (Prim_Table (J), Loc), | |
5733 | Attribute_Name => Name_Unrestricted_Access)); | |
725a69d2 | 5734 | else |
cc60bd16 | 5735 | New_Node := Make_Null (Loc); |
725a69d2 | 5736 | end if; |
5737 | ||
5738 | Append_To (Prim_Ops_Aggr_List, New_Node); | |
5739 | end loop; | |
343d35dc | 5740 | |
cc60bd16 | 5741 | New_Node := |
5742 | Make_Aggregate (Loc, | |
5743 | Expressions => Prim_Ops_Aggr_List); | |
5744 | ||
5745 | Decl := | |
5746 | Make_Subtype_Declaration (Loc, | |
5747 | Defining_Identifier => | |
5748 | Make_Defining_Identifier (Loc, | |
5749 | New_Internal_Name ('S')), | |
5750 | Subtype_Indication => | |
5751 | New_Reference_To (RTE (RE_Address_Array), Loc)); | |
5752 | ||
5753 | Append_To (Result, Decl); | |
5754 | ||
68f95949 | 5755 | Append_To (Result, |
5756 | Make_Object_Declaration (Loc, | |
725a69d2 | 5757 | Defining_Identifier => Predef_Prims, |
68f95949 | 5758 | Aliased_Present => True, |
24971415 | 5759 | Constant_Present => Building_Static_DT (Typ), |
cc60bd16 | 5760 | Object_Definition => New_Reference_To |
5761 | (Defining_Identifier (Decl), Loc), | |
5762 | Expression => New_Node)); | |
5763 | ||
5764 | -- Remember aggregates initializing dispatch tables | |
5765 | ||
5766 | Append_Elmt (New_Node, DT_Aggr); | |
725a69d2 | 5767 | |
5768 | Append_To (Result, | |
5769 | Make_Attribute_Definition_Clause (Loc, | |
5770 | Name => New_Reference_To (Predef_Prims, Loc), | |
5771 | Chars => Name_Alignment, | |
5772 | Expression => | |
5773 | Make_Attribute_Reference (Loc, | |
5774 | Prefix => | |
5775 | New_Reference_To (RTE (RE_Integer_Address), Loc), | |
5776 | Attribute_Name => Name_Alignment))); | |
5777 | end; | |
5778 | end; | |
5779 | ||
5780 | -- Stage 1: Initialize the discriminant and the record components | |
5781 | ||
5782 | DT_Constr_List := New_List; | |
5783 | DT_Aggr_List := New_List; | |
5784 | ||
5785 | -- Num_Prims. If the tagged type has no primitives we add a dummy | |
5786 | -- slot whose address will be the tag of this type. | |
5787 | ||
5788 | if Nb_Prim = 0 then | |
5789 | New_Node := Make_Integer_Literal (Loc, 1); | |
5790 | else | |
5791 | New_Node := Make_Integer_Literal (Loc, Nb_Prim); | |
5792 | end if; | |
5793 | ||
5794 | Append_To (DT_Constr_List, New_Node); | |
5795 | Append_To (DT_Aggr_List, New_Copy (New_Node)); | |
5796 | ||
5797 | -- Signature | |
5798 | ||
5799 | if RTE_Record_Component_Available (RE_Signature) then | |
5800 | Append_To (DT_Aggr_List, | |
5801 | New_Reference_To (RTE (RE_Primary_DT), Loc)); | |
5802 | end if; | |
5803 | ||
5804 | -- Tag_Kind | |
5805 | ||
5806 | if RTE_Record_Component_Available (RE_Tag_Kind) then | |
5807 | Append_To (DT_Aggr_List, Tagged_Kind (Typ)); | |
5808 | end if; | |
5809 | ||
5810 | -- Predef_Prims | |
5811 | ||
5812 | Append_To (DT_Aggr_List, | |
5813 | Make_Attribute_Reference (Loc, | |
5814 | Prefix => New_Reference_To (Predef_Prims, Loc), | |
5815 | Attribute_Name => Name_Address)); | |
5816 | ||
5817 | -- Offset_To_Top | |
5818 | ||
cc60bd16 | 5819 | Append_To (DT_Aggr_List, Make_Integer_Literal (Loc, 0)); |
725a69d2 | 5820 | |
5821 | -- Typeinfo | |
5822 | ||
5823 | Append_To (DT_Aggr_List, | |
5824 | Make_Attribute_Reference (Loc, | |
5825 | Prefix => New_Reference_To (TSD, Loc), | |
5826 | Attribute_Name => Name_Address)); | |
5827 | ||
5828 | -- Stage 2: Initialize the table of primitive operations | |
5829 | ||
5830 | Prim_Ops_Aggr_List := New_List; | |
5831 | ||
5832 | if Nb_Prim = 0 then | |
cc60bd16 | 5833 | Append_To (Prim_Ops_Aggr_List, Make_Null (Loc)); |
725a69d2 | 5834 | |
24971415 | 5835 | elsif not Building_Static_DT (Typ) then |
725a69d2 | 5836 | for J in 1 .. Nb_Prim loop |
cc60bd16 | 5837 | Append_To (Prim_Ops_Aggr_List, Make_Null (Loc)); |
725a69d2 | 5838 | end loop; |
5839 | ||
5840 | else | |
5841 | declare | |
5842 | Prim_Table : array (Nat range 1 .. Nb_Prim) of Entity_Id; | |
5843 | E : Entity_Id; | |
5844 | Prim : Entity_Id; | |
5845 | Prim_Elmt : Elmt_Id; | |
5846 | ||
5847 | begin | |
5848 | Prim_Table := (others => Empty); | |
cdb1c38f | 5849 | |
5850 | Prim_Elmt := First_Elmt (Primitive_Operations (Typ)); | |
725a69d2 | 5851 | while Present (Prim_Elmt) loop |
5852 | Prim := Node (Prim_Elmt); | |
5853 | ||
9429b6e9 | 5854 | -- Retrieve the ultimate alias of the primitive for proper |
5855 | -- handling of renamings and eliminated primitives. | |
5856 | ||
5857 | E := Ultimate_Alias (Prim); | |
5858 | ||
725a69d2 | 5859 | if Is_Imported (Prim) |
a652dd51 | 5860 | or else Present (Interface_Alias (Prim)) |
725a69d2 | 5861 | or else Is_Predefined_Dispatching_Operation (Prim) |
9429b6e9 | 5862 | or else Is_Eliminated (E) |
725a69d2 | 5863 | then |
5864 | null; | |
5865 | ||
5866 | else | |
725a69d2 | 5867 | if not Is_Predefined_Dispatching_Operation (E) |
5868 | and then not Is_Abstract_Subprogram (E) | |
a652dd51 | 5869 | and then not Present (Interface_Alias (E)) |
725a69d2 | 5870 | then |
5871 | pragma Assert | |
5872 | (UI_To_Int (DT_Position (Prim)) <= Nb_Prim); | |
5873 | ||
5874 | Prim_Table (UI_To_Int (DT_Position (Prim))) := E; | |
725a69d2 | 5875 | end if; |
5876 | end if; | |
5877 | ||
5878 | Next_Elmt (Prim_Elmt); | |
5879 | end loop; | |
5880 | ||
5881 | for J in Prim_Table'Range loop | |
5882 | if Present (Prim_Table (J)) then | |
5883 | New_Node := | |
cc60bd16 | 5884 | Unchecked_Convert_To (RTE (RE_Prim_Ptr), |
acf97c11 | 5885 | Make_Attribute_Reference (Loc, |
5886 | Prefix => New_Reference_To (Prim_Table (J), Loc), | |
5887 | Attribute_Name => Name_Unrestricted_Access)); | |
725a69d2 | 5888 | else |
cc60bd16 | 5889 | New_Node := Make_Null (Loc); |
725a69d2 | 5890 | end if; |
5891 | ||
5892 | Append_To (Prim_Ops_Aggr_List, New_Node); | |
5893 | end loop; | |
5894 | end; | |
5895 | end if; | |
5896 | ||
cc60bd16 | 5897 | New_Node := |
725a69d2 | 5898 | Make_Aggregate (Loc, |
cc60bd16 | 5899 | Expressions => Prim_Ops_Aggr_List); |
5900 | ||
5901 | Append_To (DT_Aggr_List, New_Node); | |
5902 | ||
5903 | -- Remember aggregates initializing dispatch tables | |
5904 | ||
5905 | Append_Elmt (New_Node, DT_Aggr); | |
725a69d2 | 5906 | |
5907 | -- In case of locally defined tagged types we have already declared | |
5908 | -- and uninitialized object for the dispatch table, which is now | |
5909 | -- initialized by means of an assignment. | |
5910 | ||
24971415 | 5911 | if not Building_Static_DT (Typ) then |
725a69d2 | 5912 | Append_To (Result, |
5913 | Make_Assignment_Statement (Loc, | |
5914 | Name => New_Reference_To (DT, Loc), | |
5915 | Expression => Make_Aggregate (Loc, | |
5916 | Expressions => DT_Aggr_List))); | |
5917 | ||
24971415 | 5918 | -- In case of library level tagged types we declare now and export |
5919 | -- the constant object containing the dispatch table. | |
725a69d2 | 5920 | |
5921 | else | |
5922 | Append_To (Result, | |
5923 | Make_Object_Declaration (Loc, | |
5924 | Defining_Identifier => DT, | |
5925 | Aliased_Present => True, | |
17e14451 | 5926 | Constant_Present => True, |
725a69d2 | 5927 | Object_Definition => |
5928 | Make_Subtype_Indication (Loc, | |
5929 | Subtype_Mark => New_Reference_To | |
5930 | (RTE (RE_Dispatch_Table_Wrapper), Loc), | |
5931 | Constraint => Make_Index_Or_Discriminant_Constraint (Loc, | |
5932 | Constraints => DT_Constr_List)), | |
5933 | Expression => Make_Aggregate (Loc, | |
5934 | Expressions => DT_Aggr_List))); | |
5935 | ||
98045ff0 | 5936 | -- Generate the SCIL node for the previous object declaration |
5937 | -- because it contains a dispatch table. | |
9af28f61 | 5938 | |
3dbca0d5 | 5939 | if Generate_SCIL then |
d215f619 | 5940 | New_Node := |
5941 | Make_SCIL_Dispatch_Table_Object_Init (Sloc (Last (Result))); | |
5942 | Set_SCIL_Related_Node (New_Node, Last (Result)); | |
5943 | Set_SCIL_Entity (New_Node, Typ); | |
5944 | Insert_Before (Last (Result), New_Node); | |
3dbca0d5 | 5945 | end if; |
5946 | ||
725a69d2 | 5947 | Append_To (Result, |
5948 | Make_Attribute_Definition_Clause (Loc, | |
5949 | Name => New_Reference_To (DT, Loc), | |
5950 | Chars => Name_Alignment, | |
5951 | Expression => | |
5952 | Make_Attribute_Reference (Loc, | |
5953 | Prefix => | |
5954 | New_Reference_To (RTE (RE_Integer_Address), Loc), | |
5955 | Attribute_Name => Name_Alignment))); | |
5956 | ||
24971415 | 5957 | Export_DT (Typ, DT); |
952af0b9 | 5958 | end if; |
76a1c25b | 5959 | end if; |
d62940bf | 5960 | |
f301a57b | 5961 | -- Initialize the table of ancestor tags if not building static |
5962 | -- dispatch table | |
725a69d2 | 5963 | |
24971415 | 5964 | if not Building_Static_DT (Typ) |
17e14451 | 5965 | and then not Is_Interface (Typ) |
725a69d2 | 5966 | and then not Is_CPP_Class (Typ) |
5967 | then | |
5968 | Append_To (Result, | |
5969 | Make_Assignment_Statement (Loc, | |
5970 | Name => | |
5971 | Make_Indexed_Component (Loc, | |
5972 | Prefix => | |
5973 | Make_Selected_Component (Loc, | |
5974 | Prefix => | |
5975 | New_Reference_To (TSD, Loc), | |
5976 | Selector_Name => | |
5977 | New_Reference_To | |
5978 | (RTE_Record_Component (RE_Tags_Table), Loc)), | |
5979 | Expressions => | |
5980 | New_List (Make_Integer_Literal (Loc, 0))), | |
5981 | ||
5982 | Expression => | |
5983 | New_Reference_To | |
5984 | (Node (First_Elmt (Access_Disp_Table (Typ))), Loc))); | |
5985 | end if; | |
5986 | ||
f301a57b | 5987 | -- Inherit the dispatch tables of the parent. There is no need to |
5988 | -- inherit anything from the parent when building static dispatch tables | |
5989 | -- because the whole dispatch table (including inherited primitives) has | |
5990 | -- been already built. | |
acf97c11 | 5991 | |
24971415 | 5992 | if Building_Static_DT (Typ) then |
725a69d2 | 5993 | null; |
5994 | ||
af647dc7 | 5995 | -- If the ancestor is a CPP_Class type we inherit the dispatch tables |
5996 | -- in the init proc, and we don't need to fill them in here. | |
d62940bf | 5997 | |
cc60bd16 | 5998 | elsif Is_CPP_Class (Parent_Typ) then |
af647dc7 | 5999 | null; |
d62940bf | 6000 | |
acf97c11 | 6001 | -- Otherwise we fill in the dispatch tables here |
d62940bf | 6002 | |
af647dc7 | 6003 | else |
cc60bd16 | 6004 | if Typ /= Parent_Typ |
af647dc7 | 6005 | and then not Is_Interface (Typ) |
6006 | and then not Restriction_Active (No_Dispatching_Calls) | |
68f95949 | 6007 | then |
343d35dc | 6008 | -- Inherit the dispatch table |
d62940bf | 6009 | |
acf97c11 | 6010 | if not Is_Interface (Typ) |
cc60bd16 | 6011 | and then not Is_Interface (Parent_Typ) |
6012 | and then not Is_CPP_Class (Parent_Typ) | |
acf97c11 | 6013 | then |
6014 | declare | |
6015 | Nb_Prims : constant Int := | |
6016 | UI_To_Int (DT_Entry_Count | |
cc60bd16 | 6017 | (First_Tag_Component (Parent_Typ))); |
6018 | ||
acf97c11 | 6019 | begin |
6020 | Append_To (Elab_Code, | |
6021 | Build_Inherit_Predefined_Prims (Loc, | |
6022 | Old_Tag_Node => | |
6023 | New_Reference_To | |
6024 | (Node | |
6025 | (Next_Elmt | |
6026 | (First_Elmt | |
cc60bd16 | 6027 | (Access_Disp_Table (Parent_Typ)))), Loc), |
acf97c11 | 6028 | New_Tag_Node => |
6029 | New_Reference_To | |
6030 | (Node | |
6031 | (Next_Elmt | |
6032 | (First_Elmt | |
6033 | (Access_Disp_Table (Typ)))), Loc))); | |
6034 | ||
6035 | if Nb_Prims /= 0 then | |
725a69d2 | 6036 | Append_To (Elab_Code, |
acf97c11 | 6037 | Build_Inherit_Prims (Loc, |
6038 | Typ => Typ, | |
6039 | Old_Tag_Node => | |
6040 | New_Reference_To | |
6041 | (Node | |
6042 | (First_Elmt | |
cc60bd16 | 6043 | (Access_Disp_Table (Parent_Typ))), Loc), |
acf97c11 | 6044 | New_Tag_Node => New_Reference_To (DT_Ptr, Loc), |
6045 | Num_Prims => Nb_Prims)); | |
6046 | end if; | |
6047 | end; | |
af647dc7 | 6048 | end if; |
d62940bf | 6049 | |
af647dc7 | 6050 | -- Inherit the secondary dispatch tables of the ancestor |
d62940bf | 6051 | |
cc60bd16 | 6052 | if not Is_CPP_Class (Parent_Typ) then |
af647dc7 | 6053 | declare |
6054 | Sec_DT_Ancestor : Elmt_Id := | |
6055 | Next_Elmt | |
acf97c11 | 6056 | (Next_Elmt |
af647dc7 | 6057 | (First_Elmt |
cc60bd16 | 6058 | (Access_Disp_Table (Parent_Typ)))); |
af647dc7 | 6059 | Sec_DT_Typ : Elmt_Id := |
6060 | Next_Elmt | |
acf97c11 | 6061 | (Next_Elmt |
6062 | (First_Elmt | |
6063 | (Access_Disp_Table (Typ)))); | |
af647dc7 | 6064 | |
6065 | procedure Copy_Secondary_DTs (Typ : Entity_Id); | |
6066 | -- Local procedure required to climb through the ancestors | |
6067 | -- and copy the contents of all their secondary dispatch | |
6068 | -- tables. | |
6069 | ||
6070 | ------------------------ | |
6071 | -- Copy_Secondary_DTs -- | |
6072 | ------------------------ | |
6073 | ||
6074 | procedure Copy_Secondary_DTs (Typ : Entity_Id) is | |
6075 | E : Entity_Id; | |
6076 | Iface : Elmt_Id; | |
6077 | ||
6078 | begin | |
6079 | -- Climb to the ancestor (if any) handling private types | |
6080 | ||
6081 | if Present (Full_View (Etype (Typ))) then | |
6082 | if Full_View (Etype (Typ)) /= Typ then | |
6083 | Copy_Secondary_DTs (Full_View (Etype (Typ))); | |
6084 | end if; | |
d62940bf | 6085 | |
af647dc7 | 6086 | elsif Etype (Typ) /= Typ then |
6087 | Copy_Secondary_DTs (Etype (Typ)); | |
6088 | end if; | |
d62940bf | 6089 | |
a652dd51 | 6090 | if Present (Interfaces (Typ)) |
6091 | and then not Is_Empty_Elmt_List (Interfaces (Typ)) | |
af647dc7 | 6092 | then |
a652dd51 | 6093 | Iface := First_Elmt (Interfaces (Typ)); |
af647dc7 | 6094 | E := First_Entity (Typ); |
6095 | while Present (E) | |
6096 | and then Present (Node (Sec_DT_Ancestor)) | |
725a69d2 | 6097 | and then Ekind (Node (Sec_DT_Ancestor)) = E_Constant |
af647dc7 | 6098 | loop |
6099 | if Is_Tag (E) and then Chars (E) /= Name_uTag then | |
cdb1c38f | 6100 | declare |
6101 | Num_Prims : constant Int := | |
6102 | UI_To_Int (DT_Entry_Count (E)); | |
6103 | ||
6104 | begin | |
6105 | if not Is_Interface (Etype (Typ)) then | |
6106 | ||
6107 | -- Inherit first secondary dispatch table | |
6108 | ||
6109 | Append_To (Elab_Code, | |
6110 | Build_Inherit_Predefined_Prims (Loc, | |
6111 | Old_Tag_Node => | |
6112 | Unchecked_Convert_To (RTE (RE_Tag), | |
acf97c11 | 6113 | New_Reference_To |
6114 | (Node | |
6115 | (Next_Elmt (Sec_DT_Ancestor)), | |
6116 | Loc)), | |
cdb1c38f | 6117 | New_Tag_Node => |
6118 | Unchecked_Convert_To (RTE (RE_Tag), | |
6119 | New_Reference_To | |
acf97c11 | 6120 | (Node (Next_Elmt (Sec_DT_Typ)), |
6121 | Loc)))); | |
cdb1c38f | 6122 | |
6123 | if Num_Prims /= 0 then | |
6124 | Append_To (Elab_Code, | |
6125 | Build_Inherit_Prims (Loc, | |
6126 | Typ => Node (Iface), | |
6127 | Old_Tag_Node => | |
6128 | Unchecked_Convert_To | |
6129 | (RTE (RE_Tag), | |
6130 | New_Reference_To | |
6131 | (Node (Sec_DT_Ancestor), | |
6132 | Loc)), | |
6133 | New_Tag_Node => | |
6134 | Unchecked_Convert_To | |
6135 | (RTE (RE_Tag), | |
6136 | New_Reference_To | |
6137 | (Node (Sec_DT_Typ), Loc)), | |
6138 | Num_Prims => Num_Prims)); | |
6139 | end if; | |
6140 | end if; | |
6141 | ||
6142 | Next_Elmt (Sec_DT_Ancestor); | |
6143 | Next_Elmt (Sec_DT_Typ); | |
343d35dc | 6144 | |
acf97c11 | 6145 | -- Skip the secondary dispatch table of |
6146 | -- predefined primitives | |
6147 | ||
6148 | Next_Elmt (Sec_DT_Ancestor); | |
6149 | Next_Elmt (Sec_DT_Typ); | |
6150 | ||
cdb1c38f | 6151 | if not Is_Interface (Etype (Typ)) then |
6152 | ||
6153 | -- Inherit second secondary dispatch table | |
343d35dc | 6154 | |
343d35dc | 6155 | Append_To (Elab_Code, |
6156 | Build_Inherit_Predefined_Prims (Loc, | |
6157 | Old_Tag_Node => | |
6158 | Unchecked_Convert_To (RTE (RE_Tag), | |
6159 | New_Reference_To | |
acf97c11 | 6160 | (Node |
6161 | (Next_Elmt (Sec_DT_Ancestor)), | |
6162 | Loc)), | |
343d35dc | 6163 | New_Tag_Node => |
6164 | Unchecked_Convert_To (RTE (RE_Tag), | |
6165 | New_Reference_To | |
acf97c11 | 6166 | (Node (Next_Elmt (Sec_DT_Typ)), |
6167 | Loc)))); | |
343d35dc | 6168 | |
6169 | if Num_Prims /= 0 then | |
6170 | Append_To (Elab_Code, | |
6171 | Build_Inherit_Prims (Loc, | |
17e14451 | 6172 | Typ => Node (Iface), |
343d35dc | 6173 | Old_Tag_Node => |
6174 | Unchecked_Convert_To | |
6175 | (RTE (RE_Tag), | |
6176 | New_Reference_To | |
6177 | (Node (Sec_DT_Ancestor), | |
6178 | Loc)), | |
6179 | New_Tag_Node => | |
6180 | Unchecked_Convert_To | |
6181 | (RTE (RE_Tag), | |
6182 | New_Reference_To | |
6183 | (Node (Sec_DT_Typ), Loc)), | |
17e14451 | 6184 | Num_Prims => Num_Prims)); |
343d35dc | 6185 | end if; |
cdb1c38f | 6186 | end if; |
6187 | end; | |
af647dc7 | 6188 | |
6189 | Next_Elmt (Sec_DT_Ancestor); | |
6190 | Next_Elmt (Sec_DT_Typ); | |
acf97c11 | 6191 | |
6192 | -- Skip the secondary dispatch table of | |
6193 | -- predefined primitives | |
6194 | ||
6195 | Next_Elmt (Sec_DT_Ancestor); | |
6196 | Next_Elmt (Sec_DT_Typ); | |
6197 | ||
af647dc7 | 6198 | Next_Elmt (Iface); |
6199 | end if; | |
d62940bf | 6200 | |
af647dc7 | 6201 | Next_Entity (E); |
6202 | end loop; | |
6203 | end if; | |
6204 | end Copy_Secondary_DTs; | |
d62940bf | 6205 | |
af647dc7 | 6206 | begin |
725a69d2 | 6207 | if Present (Node (Sec_DT_Ancestor)) |
6208 | and then Ekind (Node (Sec_DT_Ancestor)) = E_Constant | |
6209 | then | |
af647dc7 | 6210 | -- Handle private types |
76a1c25b | 6211 | |
af647dc7 | 6212 | if Present (Full_View (Typ)) then |
6213 | Copy_Secondary_DTs (Full_View (Typ)); | |
6214 | else | |
6215 | Copy_Secondary_DTs (Typ); | |
6216 | end if; | |
76a1c25b | 6217 | end if; |
af647dc7 | 6218 | end; |
6219 | end if; | |
76a1c25b | 6220 | end if; |
343d35dc | 6221 | end if; |
d62940bf | 6222 | |
343d35dc | 6223 | -- Generate code to register the Tag in the External_Tag hash table for |
6224 | -- the pure Ada type only. | |
d62940bf | 6225 | |
343d35dc | 6226 | -- Register_Tag (Dt_Ptr); |
d62940bf | 6227 | |
725a69d2 | 6228 | -- Skip this action in the following cases: |
6229 | -- 1) if Register_Tag is not available. | |
6230 | -- 2) in No_Run_Time mode. | |
2ea346ac | 6231 | -- 3) if Typ is not defined at the library level (this is required |
725a69d2 | 6232 | -- to avoid adding concurrency control to the hash table used |
6233 | -- by the run-time to register the tags). | |
d62940bf | 6234 | |
cdb1c38f | 6235 | if not No_Run_Time_Mode |
6236 | and then Is_Library_Level_Entity (Typ) | |
6237 | and then RTE_Available (RE_Register_Tag) | |
6238 | then | |
725a69d2 | 6239 | Append_To (Elab_Code, |
cdb1c38f | 6240 | Make_Procedure_Call_Statement (Loc, |
6241 | Name => New_Reference_To (RTE (RE_Register_Tag), Loc), | |
6242 | Parameter_Associations => | |
6243 | New_List (New_Reference_To (DT_Ptr, Loc)))); | |
d62940bf | 6244 | end if; |
6245 | ||
2ea346ac | 6246 | if not Is_Empty_List (Elab_Code) then |
6247 | Append_List_To (Result, Elab_Code); | |
6248 | end if; | |
cdb1c38f | 6249 | |
f38c8084 | 6250 | -- Populate the two auxiliary tables used for dispatching asynchronous, |
6251 | -- conditional and timed selects for synchronized types that implement | |
6252 | -- a limited interface. Skip this step in Ravenscar profile or when | |
6253 | -- general dispatching is forbidden. | |
17e14451 | 6254 | |
6255 | if Ada_Version >= Ada_05 | |
6256 | and then Is_Concurrent_Record_Type (Typ) | |
a652dd51 | 6257 | and then Has_Interfaces (Typ) |
f38c8084 | 6258 | and then not Restriction_Active (No_Dispatching_Calls) |
6259 | and then not Restriction_Active (No_Select_Statements) | |
17e14451 | 6260 | then |
6261 | Append_List_To (Result, | |
6262 | Make_Select_Specific_Data_Table (Typ)); | |
6263 | end if; | |
6264 | ||
cc60bd16 | 6265 | -- Remember entities containing dispatch tables |
acf97c11 | 6266 | |
cc60bd16 | 6267 | Append_Elmt (Predef_Prims, DT_Decl); |
6268 | Append_Elmt (DT, DT_Decl); | |
acf97c11 | 6269 | |
725a69d2 | 6270 | Analyze_List (Result, Suppress => All_Checks); |
17e14451 | 6271 | Set_Has_Dispatch_Table (Typ); |
6272 | ||
f301a57b | 6273 | -- Mark entities containing dispatch tables. Required by the backend to |
6274 | -- handle them properly. | |
cc60bd16 | 6275 | |
6276 | if not Is_Interface (Typ) then | |
6277 | declare | |
6278 | Elmt : Elmt_Id; | |
6279 | ||
6280 | begin | |
6281 | -- Ensure that entities Prim_Ptr and Predef_Prims_Table_Ptr have | |
6282 | -- the decoration required by the backend | |
6283 | ||
6284 | Set_Is_Dispatch_Table_Entity (RTE (RE_Prim_Ptr)); | |
6285 | Set_Is_Dispatch_Table_Entity (RTE (RE_Predef_Prims_Table_Ptr)); | |
6286 | ||
6287 | -- Object declarations | |
6288 | ||
6289 | Elmt := First_Elmt (DT_Decl); | |
6290 | while Present (Elmt) loop | |
6291 | Set_Is_Dispatch_Table_Entity (Node (Elmt)); | |
6292 | pragma Assert (Ekind (Etype (Node (Elmt))) = E_Array_Subtype | |
6293 | or else Ekind (Etype (Node (Elmt))) = E_Record_Subtype); | |
6294 | Set_Is_Dispatch_Table_Entity (Etype (Node (Elmt))); | |
6295 | Next_Elmt (Elmt); | |
6296 | end loop; | |
6297 | ||
6298 | -- Aggregates initializing dispatch tables | |
6299 | ||
6300 | Elmt := First_Elmt (DT_Aggr); | |
6301 | while Present (Elmt) loop | |
6302 | Set_Is_Dispatch_Table_Entity (Etype (Node (Elmt))); | |
6303 | Next_Elmt (Elmt); | |
6304 | end loop; | |
6305 | end; | |
6306 | end if; | |
6307 | ||
76a1c25b | 6308 | return Result; |
6309 | end Make_DT; | |
d62940bf | 6310 | |
76a1c25b | 6311 | ------------------------------------- |
6312 | -- Make_Select_Specific_Data_Table -- | |
6313 | ------------------------------------- | |
d62940bf | 6314 | |
76a1c25b | 6315 | function Make_Select_Specific_Data_Table |
6316 | (Typ : Entity_Id) return List_Id | |
6317 | is | |
6318 | Assignments : constant List_Id := New_List; | |
6319 | Loc : constant Source_Ptr := Sloc (Typ); | |
d62940bf | 6320 | |
68f95949 | 6321 | Conc_Typ : Entity_Id; |
6322 | Decls : List_Id; | |
6323 | DT_Ptr : Entity_Id; | |
6324 | Prim : Entity_Id; | |
6325 | Prim_Als : Entity_Id; | |
6326 | Prim_Elmt : Elmt_Id; | |
6327 | Prim_Pos : Uint; | |
343d35dc | 6328 | Nb_Prim : Nat := 0; |
d62940bf | 6329 | |
76a1c25b | 6330 | type Examined_Array is array (Int range <>) of Boolean; |
d62940bf | 6331 | |
76a1c25b | 6332 | function Find_Entry_Index (E : Entity_Id) return Uint; |
6333 | -- Given an entry, find its index in the visible declarations of the | |
6334 | -- corresponding concurrent type of Typ. | |
d62940bf | 6335 | |
76a1c25b | 6336 | ---------------------- |
6337 | -- Find_Entry_Index -- | |
6338 | ---------------------- | |
d62940bf | 6339 | |
76a1c25b | 6340 | function Find_Entry_Index (E : Entity_Id) return Uint is |
6341 | Index : Uint := Uint_1; | |
6342 | Subp_Decl : Entity_Id; | |
d62940bf | 6343 | |
76a1c25b | 6344 | begin |
6345 | if Present (Decls) | |
6346 | and then not Is_Empty_List (Decls) | |
6347 | then | |
6348 | Subp_Decl := First (Decls); | |
6349 | while Present (Subp_Decl) loop | |
6350 | if Nkind (Subp_Decl) = N_Entry_Declaration then | |
6351 | if Defining_Identifier (Subp_Decl) = E then | |
6352 | return Index; | |
6353 | end if; | |
d62940bf | 6354 | |
76a1c25b | 6355 | Index := Index + 1; |
6356 | end if; | |
d62940bf | 6357 | |
76a1c25b | 6358 | Next (Subp_Decl); |
6359 | end loop; | |
6360 | end if; | |
d62940bf | 6361 | |
76a1c25b | 6362 | return Uint_0; |
6363 | end Find_Entry_Index; | |
6364 | ||
6365 | -- Start of processing for Make_Select_Specific_Data_Table | |
6366 | ||
6367 | begin | |
68f95949 | 6368 | pragma Assert (not Restriction_Active (No_Dispatching_Calls)); |
6369 | ||
76a1c25b | 6370 | DT_Ptr := Node (First_Elmt (Access_Disp_Table (Typ))); |
d62940bf | 6371 | |
76a1c25b | 6372 | if Present (Corresponding_Concurrent_Type (Typ)) then |
6373 | Conc_Typ := Corresponding_Concurrent_Type (Typ); | |
6374 | ||
17e14451 | 6375 | if Present (Full_View (Conc_Typ)) then |
6376 | Conc_Typ := Full_View (Conc_Typ); | |
6377 | end if; | |
6378 | ||
76a1c25b | 6379 | if Ekind (Conc_Typ) = E_Protected_Type then |
6380 | Decls := Visible_Declarations (Protected_Definition ( | |
6381 | Parent (Conc_Typ))); | |
d62940bf | 6382 | else |
6383 | pragma Assert (Ekind (Conc_Typ) = E_Task_Type); | |
76a1c25b | 6384 | Decls := Visible_Declarations (Task_Definition ( |
6385 | Parent (Conc_Typ))); | |
6386 | end if; | |
6387 | end if; | |
d62940bf | 6388 | |
76a1c25b | 6389 | -- Count the non-predefined primitive operations |
d62940bf | 6390 | |
76a1c25b | 6391 | Prim_Elmt := First_Elmt (Primitive_Operations (Typ)); |
6392 | while Present (Prim_Elmt) loop | |
af647dc7 | 6393 | Prim := Node (Prim_Elmt); |
6394 | ||
6395 | if not (Is_Predefined_Dispatching_Operation (Prim) | |
6396 | or else Is_Predefined_Dispatching_Alias (Prim)) | |
6397 | then | |
76a1c25b | 6398 | Nb_Prim := Nb_Prim + 1; |
6399 | end if; | |
d62940bf | 6400 | |
76a1c25b | 6401 | Next_Elmt (Prim_Elmt); |
6402 | end loop; | |
d62940bf | 6403 | |
76a1c25b | 6404 | declare |
68f95949 | 6405 | Examined : Examined_Array (1 .. Nb_Prim) := (others => False); |
d62940bf | 6406 | |
76a1c25b | 6407 | begin |
6408 | Prim_Elmt := First_Elmt (Primitive_Operations (Typ)); | |
6409 | while Present (Prim_Elmt) loop | |
6410 | Prim := Node (Prim_Elmt); | |
d62940bf | 6411 | |
af647dc7 | 6412 | -- Look for primitive overriding an abstract interface subprogram |
d62940bf | 6413 | |
a652dd51 | 6414 | if Present (Interface_Alias (Prim)) |
af647dc7 | 6415 | and then not Examined (UI_To_Int (DT_Position (Alias (Prim)))) |
6416 | then | |
6417 | Prim_Pos := DT_Position (Alias (Prim)); | |
6418 | pragma Assert (UI_To_Int (Prim_Pos) <= Nb_Prim); | |
6419 | Examined (UI_To_Int (Prim_Pos)) := True; | |
d62940bf | 6420 | |
af647dc7 | 6421 | -- Set the primitive operation kind regardless of subprogram |
6422 | -- type. Generate: | |
6423 | -- Ada.Tags.Set_Prim_Op_Kind (DT_Ptr, <position>, <kind>); | |
d62940bf | 6424 | |
af647dc7 | 6425 | Append_To (Assignments, |
725a69d2 | 6426 | Make_Procedure_Call_Statement (Loc, |
6427 | Name => New_Reference_To (RTE (RE_Set_Prim_Op_Kind), Loc), | |
6428 | Parameter_Associations => New_List ( | |
6429 | New_Reference_To (DT_Ptr, Loc), | |
6430 | Make_Integer_Literal (Loc, Prim_Pos), | |
6431 | Prim_Op_Kind (Alias (Prim), Typ)))); | |
68f95949 | 6432 | |
af647dc7 | 6433 | -- Retrieve the root of the alias chain |
68f95949 | 6434 | |
af647dc7 | 6435 | Prim_Als := Prim; |
6436 | while Present (Alias (Prim_Als)) loop | |
6437 | Prim_Als := Alias (Prim_Als); | |
6438 | end loop; | |
68f95949 | 6439 | |
af647dc7 | 6440 | -- In the case of an entry wrapper, set the entry index |
68f95949 | 6441 | |
af647dc7 | 6442 | if Ekind (Prim) = E_Procedure |
6443 | and then Is_Primitive_Wrapper (Prim_Als) | |
6444 | and then Ekind (Wrapped_Entity (Prim_Als)) = E_Entry | |
6445 | then | |
6446 | -- Generate: | |
6447 | -- Ada.Tags.Set_Entry_Index | |
6448 | -- (DT_Ptr, <position>, <index>); | |
68f95949 | 6449 | |
af647dc7 | 6450 | Append_To (Assignments, |
725a69d2 | 6451 | Make_Procedure_Call_Statement (Loc, |
6452 | Name => | |
6453 | New_Reference_To (RTE (RE_Set_Entry_Index), Loc), | |
6454 | Parameter_Associations => New_List ( | |
6455 | New_Reference_To (DT_Ptr, Loc), | |
6456 | Make_Integer_Literal (Loc, Prim_Pos), | |
6457 | Make_Integer_Literal (Loc, | |
6458 | Find_Entry_Index (Wrapped_Entity (Prim_Als)))))); | |
76a1c25b | 6459 | end if; |
6460 | end if; | |
6461 | ||
76a1c25b | 6462 | Next_Elmt (Prim_Elmt); |
6463 | end loop; | |
6464 | end; | |
6465 | ||
6466 | return Assignments; | |
6467 | end Make_Select_Specific_Data_Table; | |
d62940bf | 6468 | |
17e14451 | 6469 | --------------- |
6470 | -- Make_Tags -- | |
6471 | --------------- | |
6472 | ||
6473 | function Make_Tags (Typ : Entity_Id) return List_Id is | |
f301a57b | 6474 | Loc : constant Source_Ptr := Sloc (Typ); |
6475 | Result : constant List_Id := New_List; | |
6476 | ||
6477 | procedure Import_DT | |
6478 | (Tag_Typ : Entity_Id; | |
6479 | DT : Entity_Id; | |
6480 | Is_Secondary_DT : Boolean); | |
6481 | -- Import the dispatch table DT of tagged type Tag_Typ. Required to | |
6482 | -- generate forward references and statically allocate the table. For | |
6483 | -- primary dispatch tables that require no dispatch table generate: | |
6484 | -- DT : static aliased constant Non_Dispatch_Table_Wrapper; | |
6485 | -- $pragma import (ada, DT); | |
6486 | -- Otherwise generate: | |
6487 | -- DT : static aliased constant Dispatch_Table_Wrapper (Nb_Prim); | |
6488 | -- $pragma import (ada, DT); | |
7854e190 | 6489 | |
f301a57b | 6490 | --------------- |
6491 | -- Import_DT -- | |
6492 | --------------- | |
24971415 | 6493 | |
f301a57b | 6494 | procedure Import_DT |
6495 | (Tag_Typ : Entity_Id; | |
6496 | DT : Entity_Id; | |
6497 | Is_Secondary_DT : Boolean) | |
6498 | is | |
6499 | DT_Constr_List : List_Id; | |
6500 | Nb_Prim : Nat; | |
24971415 | 6501 | |
f301a57b | 6502 | begin |
6503 | Set_Is_Imported (DT); | |
6504 | Set_Ekind (DT, E_Constant); | |
6505 | Set_Related_Type (DT, Typ); | |
24971415 | 6506 | |
24971415 | 6507 | -- The scope must be set now to call Get_External_Name |
6508 | ||
6509 | Set_Scope (DT, Current_Scope); | |
6510 | ||
6511 | Get_External_Name (DT, True); | |
6512 | Set_Interface_Name (DT, | |
17e14451 | 6513 | Make_String_Literal (Loc, |
6514 | Strval => String_From_Name_Buffer)); | |
6515 | ||
24971415 | 6516 | -- Ensure proper Sprint output of this implicit importation |
17e14451 | 6517 | |
24971415 | 6518 | Set_Is_Internal (DT); |
17e14451 | 6519 | |
24971415 | 6520 | -- Save this entity to allow Make_DT to generate its exportation |
6521 | ||
f301a57b | 6522 | Append_Elmt (DT, Dispatch_Table_Wrappers (Typ)); |
24971415 | 6523 | |
f301a57b | 6524 | -- No dispatch table required |
acf97c11 | 6525 | |
f301a57b | 6526 | if not Is_Secondary_DT |
6527 | and then not Has_DT (Tag_Typ) | |
6528 | then | |
6529 | Append_To (Result, | |
6530 | Make_Object_Declaration (Loc, | |
6531 | Defining_Identifier => DT, | |
6532 | Aliased_Present => True, | |
6533 | Constant_Present => True, | |
6534 | Object_Definition => | |
6535 | New_Reference_To (RTE (RE_No_Dispatch_Table_Wrapper), Loc))); | |
6536 | ||
6537 | else | |
24971415 | 6538 | -- Calculate the number of primitives of the dispatch table and |
6539 | -- the size of the Type_Specific_Data record. | |
6540 | ||
f301a57b | 6541 | Nb_Prim := |
6542 | UI_To_Int (DT_Entry_Count (First_Tag_Component (Tag_Typ))); | |
24971415 | 6543 | |
6544 | -- If the tagged type has no primitives we add a dummy slot | |
6545 | -- whose address will be the tag of this type. | |
6546 | ||
6547 | if Nb_Prim = 0 then | |
6548 | DT_Constr_List := | |
6549 | New_List (Make_Integer_Literal (Loc, 1)); | |
6550 | else | |
6551 | DT_Constr_List := | |
6552 | New_List (Make_Integer_Literal (Loc, Nb_Prim)); | |
6553 | end if; | |
6554 | ||
6555 | Append_To (Result, | |
6556 | Make_Object_Declaration (Loc, | |
6557 | Defining_Identifier => DT, | |
6558 | Aliased_Present => True, | |
6559 | Constant_Present => True, | |
6560 | Object_Definition => | |
6561 | Make_Subtype_Indication (Loc, | |
6562 | Subtype_Mark => | |
6563 | New_Reference_To (RTE (RE_Dispatch_Table_Wrapper), Loc), | |
6564 | Constraint => Make_Index_Or_Discriminant_Constraint (Loc, | |
6565 | Constraints => DT_Constr_List)))); | |
f301a57b | 6566 | end if; |
6567 | end Import_DT; | |
6568 | ||
6569 | -- Local variables | |
6570 | ||
6571 | Tname : constant Name_Id := Chars (Typ); | |
6572 | AI_Tag_Comp : Elmt_Id; | |
6573 | DT : Node_Id; | |
6574 | DT_Ptr : Node_Id; | |
6575 | Predef_Prims_Ptr : Node_Id; | |
6576 | Iface_DT : Node_Id; | |
6577 | Iface_DT_Ptr : Node_Id; | |
d215f619 | 6578 | New_Node : Node_Id; |
f301a57b | 6579 | Suffix_Index : Int; |
6580 | Typ_Name : Name_Id; | |
6581 | Typ_Comps : Elist_Id; | |
6582 | ||
6583 | -- Start of processing for Make_Tags | |
6584 | ||
6585 | begin | |
6586 | -- 1) Generate the primary and secondary tag entities | |
24971415 | 6587 | |
f301a57b | 6588 | -- Collect the components associated with secondary dispatch tables |
6589 | ||
6590 | if Has_Interfaces (Typ) then | |
6591 | Collect_Interface_Components (Typ, Typ_Comps); | |
6592 | end if; | |
6593 | ||
6594 | -- 1) Generate the primary tag entities | |
6595 | ||
6596 | -- Primary dispatch table containing user-defined primitives | |
6597 | ||
6598 | DT_Ptr := Make_Defining_Identifier (Loc, | |
6599 | New_External_Name (Tname, 'P')); | |
6600 | Set_Etype (DT_Ptr, RTE (RE_Tag)); | |
6601 | ||
6602 | -- Primary dispatch table containing predefined primitives | |
6603 | ||
6604 | Predef_Prims_Ptr := | |
6605 | Make_Defining_Identifier (Loc, | |
6606 | Chars => New_External_Name (Tname, 'Y')); | |
6607 | Set_Etype (Predef_Prims_Ptr, RTE (RE_Address)); | |
6608 | ||
6609 | -- Import the forward declaration of the Dispatch Table wrapper record | |
6610 | -- (Make_DT will take care of its exportation) | |
6611 | ||
6612 | if Building_Static_DT (Typ) then | |
6613 | Set_Dispatch_Table_Wrappers (Typ, New_Elmt_List); | |
6614 | ||
6615 | DT := | |
6616 | Make_Defining_Identifier (Loc, | |
6617 | Chars => New_External_Name (Tname, 'T')); | |
6618 | ||
6619 | Import_DT (Typ, DT, Is_Secondary_DT => False); | |
6620 | ||
6621 | if Has_DT (Typ) then | |
24971415 | 6622 | Append_To (Result, |
6623 | Make_Object_Declaration (Loc, | |
6624 | Defining_Identifier => DT_Ptr, | |
6625 | Constant_Present => True, | |
6626 | Object_Definition => New_Reference_To (RTE (RE_Tag), Loc), | |
6627 | Expression => | |
6628 | Unchecked_Convert_To (RTE (RE_Tag), | |
6629 | Make_Attribute_Reference (Loc, | |
6630 | Prefix => | |
6631 | Make_Selected_Component (Loc, | |
6632 | Prefix => New_Reference_To (DT, Loc), | |
6633 | Selector_Name => | |
6634 | New_Occurrence_Of | |
6635 | (RTE_Record_Component (RE_Prims_Ptr), Loc)), | |
6636 | Attribute_Name => Name_Address)))); | |
6637 | ||
98045ff0 | 6638 | -- Generate the SCIL node for the previous object declaration |
6639 | -- because it has a tag initialization. | |
9af28f61 | 6640 | |
3dbca0d5 | 6641 | if Generate_SCIL then |
d215f619 | 6642 | New_Node := |
6643 | Make_SCIL_Dispatch_Table_Tag_Init (Sloc (Last (Result))); | |
6644 | Set_SCIL_Related_Node (New_Node, Last (Result)); | |
6645 | Set_SCIL_Entity (New_Node, Typ); | |
6646 | Insert_Before (Last (Result), New_Node); | |
3dbca0d5 | 6647 | end if; |
6648 | ||
acf97c11 | 6649 | Append_To (Result, |
6650 | Make_Object_Declaration (Loc, | |
6651 | Defining_Identifier => Predef_Prims_Ptr, | |
6652 | Constant_Present => True, | |
6653 | Object_Definition => New_Reference_To | |
6654 | (RTE (RE_Address), Loc), | |
6655 | Expression => | |
6656 | Make_Attribute_Reference (Loc, | |
6657 | Prefix => | |
6658 | Make_Selected_Component (Loc, | |
6659 | Prefix => New_Reference_To (DT, Loc), | |
6660 | Selector_Name => | |
6661 | New_Occurrence_Of | |
6662 | (RTE_Record_Component (RE_Predef_Prims), Loc)), | |
6663 | Attribute_Name => Name_Address))); | |
6664 | ||
24971415 | 6665 | -- No dispatch table required |
6666 | ||
6667 | else | |
24971415 | 6668 | Append_To (Result, |
6669 | Make_Object_Declaration (Loc, | |
6670 | Defining_Identifier => DT_Ptr, | |
6671 | Constant_Present => True, | |
6672 | Object_Definition => New_Reference_To (RTE (RE_Tag), Loc), | |
6673 | Expression => | |
6674 | Unchecked_Convert_To (RTE (RE_Tag), | |
6675 | Make_Attribute_Reference (Loc, | |
6676 | Prefix => | |
6677 | Make_Selected_Component (Loc, | |
6678 | Prefix => New_Reference_To (DT, Loc), | |
6679 | Selector_Name => | |
6680 | New_Occurrence_Of | |
6681 | (RTE_Record_Component (RE_NDT_Prims_Ptr), Loc)), | |
6682 | Attribute_Name => Name_Address)))); | |
3dbca0d5 | 6683 | |
98045ff0 | 6684 | -- Generate the SCIL node for the previous object declaration |
6685 | -- because it has a tag initialization. | |
9af28f61 | 6686 | |
3dbca0d5 | 6687 | if Generate_SCIL then |
d215f619 | 6688 | New_Node := |
6689 | Make_SCIL_Dispatch_Table_Object_Init (Sloc (Last (Result))); | |
6690 | Set_SCIL_Related_Node (New_Node, Last (Result)); | |
6691 | Set_SCIL_Entity (New_Node, Typ); | |
6692 | Insert_Before (Last (Result), New_Node); | |
3dbca0d5 | 6693 | end if; |
24971415 | 6694 | end if; |
6695 | ||
6696 | Set_Is_True_Constant (DT_Ptr); | |
e7e688dd | 6697 | Set_Is_Statically_Allocated (DT_Ptr); |
17e14451 | 6698 | end if; |
6699 | ||
6700 | pragma Assert (No (Access_Disp_Table (Typ))); | |
6701 | Set_Access_Disp_Table (Typ, New_Elmt_List); | |
6702 | Append_Elmt (DT_Ptr, Access_Disp_Table (Typ)); | |
acf97c11 | 6703 | Append_Elmt (Predef_Prims_Ptr, Access_Disp_Table (Typ)); |
17e14451 | 6704 | |
6705 | -- 2) Generate the secondary tag entities | |
6706 | ||
a652dd51 | 6707 | if Has_Interfaces (Typ) then |
f301a57b | 6708 | |
6709 | -- Note: The following value of Suffix_Index must be in sync with | |
6710 | -- the Suffix_Index values of secondary dispatch tables generated | |
6711 | -- by Make_DT. | |
6712 | ||
6713 | Suffix_Index := 1; | |
17e14451 | 6714 | |
6715 | -- For each interface type we build an unique external name | |
6716 | -- associated with its corresponding secondary dispatch table. | |
6717 | -- This external name will be used to declare an object that | |
6718 | -- references this secondary dispatch table, value that will be | |
6719 | -- used for the elaboration of Typ's objects and also for the | |
6720 | -- elaboration of objects of derivations of Typ that do not | |
6721 | -- override the primitive operation of this interface type. | |
6722 | ||
6723 | AI_Tag_Comp := First_Elmt (Typ_Comps); | |
6724 | while Present (AI_Tag_Comp) loop | |
6725 | Get_Secondary_DT_External_Name | |
cdb1c38f | 6726 | (Typ, Related_Type (Node (AI_Tag_Comp)), Suffix_Index); |
cdb1c38f | 6727 | Typ_Name := Name_Find; |
17e14451 | 6728 | |
f301a57b | 6729 | if Building_Static_DT (Typ) then |
6730 | Iface_DT := | |
6731 | Make_Defining_Identifier (Loc, | |
6732 | Chars => New_External_Name | |
6733 | (Typ_Name, 'T', Suffix_Index => -1)); | |
6734 | Import_DT | |
6735 | (Tag_Typ => Related_Type (Node (AI_Tag_Comp)), | |
6736 | DT => Iface_DT, | |
6737 | Is_Secondary_DT => True); | |
6738 | end if; | |
6739 | ||
acf97c11 | 6740 | -- Secondary dispatch table referencing thunks to user-defined |
6741 | -- primitives covered by this interface. | |
6742 | ||
17e14451 | 6743 | Iface_DT_Ptr := |
6744 | Make_Defining_Identifier (Loc, | |
6745 | Chars => New_External_Name (Typ_Name, 'P')); | |
6746 | Set_Etype (Iface_DT_Ptr, RTE (RE_Interface_Tag)); | |
6747 | Set_Ekind (Iface_DT_Ptr, E_Constant); | |
cdb1c38f | 6748 | Set_Is_Tag (Iface_DT_Ptr); |
6749 | Set_Has_Thunks (Iface_DT_Ptr); | |
2ea346ac | 6750 | Set_Is_Statically_Allocated (Iface_DT_Ptr, |
6751 | Is_Library_Level_Tagged_Type (Typ)); | |
17e14451 | 6752 | Set_Is_True_Constant (Iface_DT_Ptr); |
cdb1c38f | 6753 | Set_Related_Type |
6754 | (Iface_DT_Ptr, Related_Type (Node (AI_Tag_Comp))); | |
6755 | Append_Elmt (Iface_DT_Ptr, Access_Disp_Table (Typ)); | |
6756 | ||
f301a57b | 6757 | if Building_Static_DT (Typ) then |
6758 | Append_To (Result, | |
6759 | Make_Object_Declaration (Loc, | |
6760 | Defining_Identifier => Iface_DT_Ptr, | |
6761 | Constant_Present => True, | |
6762 | Object_Definition => New_Reference_To | |
6763 | (RTE (RE_Interface_Tag), Loc), | |
6764 | Expression => | |
6765 | Unchecked_Convert_To (RTE (RE_Interface_Tag), | |
6766 | Make_Attribute_Reference (Loc, | |
6767 | Prefix => | |
6768 | Make_Selected_Component (Loc, | |
6769 | Prefix => New_Reference_To (Iface_DT, Loc), | |
6770 | Selector_Name => | |
6771 | New_Occurrence_Of | |
6772 | (RTE_Record_Component (RE_Prims_Ptr), Loc)), | |
6773 | Attribute_Name => Name_Address)))); | |
6774 | end if; | |
6775 | ||
acf97c11 | 6776 | -- Secondary dispatch table referencing thunks to predefined |
6777 | -- primitives. | |
6778 | ||
6779 | Iface_DT_Ptr := | |
6780 | Make_Defining_Identifier (Loc, | |
6781 | Chars => New_External_Name (Typ_Name, 'Y')); | |
6782 | Set_Etype (Iface_DT_Ptr, RTE (RE_Address)); | |
6783 | Set_Ekind (Iface_DT_Ptr, E_Constant); | |
6784 | Set_Is_Tag (Iface_DT_Ptr); | |
6785 | Set_Has_Thunks (Iface_DT_Ptr); | |
2ea346ac | 6786 | Set_Is_Statically_Allocated (Iface_DT_Ptr, |
6787 | Is_Library_Level_Tagged_Type (Typ)); | |
acf97c11 | 6788 | Set_Is_True_Constant (Iface_DT_Ptr); |
6789 | Set_Related_Type | |
6790 | (Iface_DT_Ptr, Related_Type (Node (AI_Tag_Comp))); | |
6791 | Append_Elmt (Iface_DT_Ptr, Access_Disp_Table (Typ)); | |
6792 | ||
6793 | -- Secondary dispatch table referencing user-defined primitives | |
6794 | -- covered by this interface. | |
6795 | ||
cdb1c38f | 6796 | Iface_DT_Ptr := |
6797 | Make_Defining_Identifier (Loc, | |
6798 | Chars => New_External_Name (Typ_Name, 'D')); | |
6799 | Set_Etype (Iface_DT_Ptr, RTE (RE_Interface_Tag)); | |
6800 | Set_Ekind (Iface_DT_Ptr, E_Constant); | |
6801 | Set_Is_Tag (Iface_DT_Ptr); | |
2ea346ac | 6802 | Set_Is_Statically_Allocated (Iface_DT_Ptr, |
6803 | Is_Library_Level_Tagged_Type (Typ)); | |
cdb1c38f | 6804 | Set_Is_True_Constant (Iface_DT_Ptr); |
6805 | Set_Related_Type | |
6806 | (Iface_DT_Ptr, Related_Type (Node (AI_Tag_Comp))); | |
17e14451 | 6807 | Append_Elmt (Iface_DT_Ptr, Access_Disp_Table (Typ)); |
6808 | ||
acf97c11 | 6809 | -- Secondary dispatch table referencing predefined primitives |
6810 | ||
6811 | Iface_DT_Ptr := | |
6812 | Make_Defining_Identifier (Loc, | |
6813 | Chars => New_External_Name (Typ_Name, 'Z')); | |
6814 | Set_Etype (Iface_DT_Ptr, RTE (RE_Address)); | |
6815 | Set_Ekind (Iface_DT_Ptr, E_Constant); | |
6816 | Set_Is_Tag (Iface_DT_Ptr); | |
2ea346ac | 6817 | Set_Is_Statically_Allocated (Iface_DT_Ptr, |
6818 | Is_Library_Level_Tagged_Type (Typ)); | |
acf97c11 | 6819 | Set_Is_True_Constant (Iface_DT_Ptr); |
6820 | Set_Related_Type | |
6821 | (Iface_DT_Ptr, Related_Type (Node (AI_Tag_Comp))); | |
6822 | Append_Elmt (Iface_DT_Ptr, Access_Disp_Table (Typ)); | |
6823 | ||
17e14451 | 6824 | Next_Elmt (AI_Tag_Comp); |
6825 | end loop; | |
6826 | end if; | |
6827 | ||
dffd0a90 | 6828 | -- 3) At the end of Access_Disp_Table, if the type has user-defined |
6829 | -- primitives, we add the entity of an access type declaration that | |
6830 | -- is used by Build_Get_Prim_Op_Address to expand dispatching calls | |
6831 | -- through the primary dispatch table. | |
6832 | ||
6833 | if UI_To_Int (DT_Entry_Count (First_Tag_Component (Typ))) = 0 then | |
6834 | Analyze_List (Result); | |
17e14451 | 6835 | |
6836 | -- Generate: | |
cc60bd16 | 6837 | -- type Typ_DT is array (1 .. Nb_Prims) of Prim_Ptr; |
17e14451 | 6838 | -- type Typ_DT_Acc is access Typ_DT; |
6839 | ||
dffd0a90 | 6840 | else |
6841 | declare | |
6842 | Name_DT_Prims : constant Name_Id := | |
6843 | New_External_Name (Tname, 'G'); | |
6844 | Name_DT_Prims_Acc : constant Name_Id := | |
6845 | New_External_Name (Tname, 'H'); | |
6846 | DT_Prims : constant Entity_Id := | |
6847 | Make_Defining_Identifier (Loc, | |
6848 | Name_DT_Prims); | |
6849 | DT_Prims_Acc : constant Entity_Id := | |
6850 | Make_Defining_Identifier (Loc, | |
6851 | Name_DT_Prims_Acc); | |
6852 | begin | |
6853 | Append_To (Result, | |
6854 | Make_Full_Type_Declaration (Loc, | |
6855 | Defining_Identifier => DT_Prims, | |
6856 | Type_Definition => | |
6857 | Make_Constrained_Array_Definition (Loc, | |
6858 | Discrete_Subtype_Definitions => New_List ( | |
6859 | Make_Range (Loc, | |
6860 | Low_Bound => Make_Integer_Literal (Loc, 1), | |
6861 | High_Bound => Make_Integer_Literal (Loc, | |
6862 | DT_Entry_Count | |
6863 | (First_Tag_Component (Typ))))), | |
6864 | Component_Definition => | |
6865 | Make_Component_Definition (Loc, | |
6866 | Subtype_Indication => | |
6867 | New_Reference_To (RTE (RE_Prim_Ptr), Loc))))); | |
17e14451 | 6868 | |
dffd0a90 | 6869 | Append_To (Result, |
6870 | Make_Full_Type_Declaration (Loc, | |
6871 | Defining_Identifier => DT_Prims_Acc, | |
6872 | Type_Definition => | |
6873 | Make_Access_To_Object_Definition (Loc, | |
6874 | Subtype_Indication => | |
6875 | New_Occurrence_Of (DT_Prims, Loc)))); | |
17e14451 | 6876 | |
dffd0a90 | 6877 | Append_Elmt (DT_Prims_Acc, Access_Disp_Table (Typ)); |
17e14451 | 6878 | |
dffd0a90 | 6879 | -- Analyze the resulting list and suppress the generation of the |
6880 | -- Init_Proc associated with the above array declaration because | |
6881 | -- this type is never used in object declarations. It is only used | |
6882 | -- to simplify the expansion associated with dispatching calls. | |
17e14451 | 6883 | |
dffd0a90 | 6884 | Analyze_List (Result); |
6885 | Set_Suppress_Init_Proc (Base_Type (DT_Prims)); | |
cc60bd16 | 6886 | |
dffd0a90 | 6887 | -- Mark entity of dispatch table. Required by the back end to |
6888 | -- handle them properly. | |
cc60bd16 | 6889 | |
dffd0a90 | 6890 | Set_Is_Dispatch_Table_Entity (DT_Prims); |
6891 | end; | |
6892 | end if; | |
17e14451 | 6893 | |
cdb1c38f | 6894 | Set_Ekind (DT_Ptr, E_Constant); |
6895 | Set_Is_Tag (DT_Ptr); | |
6896 | Set_Related_Type (DT_Ptr, Typ); | |
6897 | ||
17e14451 | 6898 | return Result; |
6899 | end Make_Tags; | |
6900 | ||
cd534f03 | 6901 | --------------- |
6902 | -- New_Value -- | |
6903 | --------------- | |
6904 | ||
6905 | function New_Value (From : Node_Id) return Node_Id is | |
6906 | Res : constant Node_Id := Duplicate_Subexpr (From); | |
6907 | begin | |
6908 | if Is_Access_Type (Etype (From)) then | |
9af28f61 | 6909 | return |
6910 | Make_Explicit_Dereference (Sloc (From), | |
6911 | Prefix => Res); | |
cd534f03 | 6912 | else |
6913 | return Res; | |
6914 | end if; | |
6915 | end New_Value; | |
6916 | ||
ee6ba406 | 6917 | ----------------------------------- |
6918 | -- Original_View_In_Visible_Part -- | |
6919 | ----------------------------------- | |
6920 | ||
6921 | function Original_View_In_Visible_Part (Typ : Entity_Id) return Boolean is | |
6922 | Scop : constant Entity_Id := Scope (Typ); | |
6923 | ||
6924 | begin | |
6925 | -- The scope must be a package | |
6926 | ||
65149aa0 | 6927 | if not Is_Package_Or_Generic_Package (Scop) then |
ee6ba406 | 6928 | return False; |
6929 | end if; | |
6930 | ||
6931 | -- A type with a private declaration has a private view declared in | |
6932 | -- the visible part. | |
6933 | ||
6934 | if Has_Private_Declaration (Typ) then | |
6935 | return True; | |
6936 | end if; | |
6937 | ||
6938 | return List_Containing (Parent (Typ)) = | |
6939 | Visible_Declarations (Specification (Unit_Declaration_Node (Scop))); | |
6940 | end Original_View_In_Visible_Part; | |
6941 | ||
d62940bf | 6942 | ------------------ |
6943 | -- Prim_Op_Kind -- | |
6944 | ------------------ | |
6945 | ||
6946 | function Prim_Op_Kind | |
6947 | (Prim : Entity_Id; | |
6948 | Typ : Entity_Id) return Node_Id | |
6949 | is | |
6950 | Full_Typ : Entity_Id := Typ; | |
6951 | Loc : constant Source_Ptr := Sloc (Prim); | |
68f95949 | 6952 | Prim_Op : Entity_Id; |
d62940bf | 6953 | |
6954 | begin | |
6955 | -- Retrieve the original primitive operation | |
6956 | ||
68f95949 | 6957 | Prim_Op := Prim; |
d62940bf | 6958 | while Present (Alias (Prim_Op)) loop |
6959 | Prim_Op := Alias (Prim_Op); | |
6960 | end loop; | |
6961 | ||
6962 | if Ekind (Typ) = E_Record_Type | |
6963 | and then Present (Corresponding_Concurrent_Type (Typ)) | |
6964 | then | |
6965 | Full_Typ := Corresponding_Concurrent_Type (Typ); | |
6966 | end if; | |
6967 | ||
d77e048b | 6968 | -- When a private tagged type is completed by a concurrent type, |
6969 | -- retrieve the full view. | |
6970 | ||
6971 | if Is_Private_Type (Full_Typ) then | |
6972 | Full_Typ := Full_View (Full_Typ); | |
6973 | end if; | |
6974 | ||
d62940bf | 6975 | if Ekind (Prim_Op) = E_Function then |
6976 | ||
6977 | -- Protected function | |
6978 | ||
6979 | if Ekind (Full_Typ) = E_Protected_Type then | |
6980 | return New_Reference_To (RTE (RE_POK_Protected_Function), Loc); | |
6981 | ||
76a1c25b | 6982 | -- Task function |
6983 | ||
6984 | elsif Ekind (Full_Typ) = E_Task_Type then | |
6985 | return New_Reference_To (RTE (RE_POK_Task_Function), Loc); | |
6986 | ||
d62940bf | 6987 | -- Regular function |
6988 | ||
6989 | else | |
6990 | return New_Reference_To (RTE (RE_POK_Function), Loc); | |
6991 | end if; | |
6992 | ||
6993 | else | |
6994 | pragma Assert (Ekind (Prim_Op) = E_Procedure); | |
6995 | ||
6996 | if Ekind (Full_Typ) = E_Protected_Type then | |
6997 | ||
6998 | -- Protected entry | |
6999 | ||
7000 | if Is_Primitive_Wrapper (Prim_Op) | |
7001 | and then Ekind (Wrapped_Entity (Prim_Op)) = E_Entry | |
7002 | then | |
7003 | return New_Reference_To (RTE (RE_POK_Protected_Entry), Loc); | |
7004 | ||
7005 | -- Protected procedure | |
7006 | ||
7007 | else | |
7008 | return New_Reference_To (RTE (RE_POK_Protected_Procedure), Loc); | |
7009 | end if; | |
7010 | ||
7011 | elsif Ekind (Full_Typ) = E_Task_Type then | |
7012 | ||
7013 | -- Task entry | |
7014 | ||
7015 | if Is_Primitive_Wrapper (Prim_Op) | |
7016 | and then Ekind (Wrapped_Entity (Prim_Op)) = E_Entry | |
7017 | then | |
7018 | return New_Reference_To (RTE (RE_POK_Task_Entry), Loc); | |
7019 | ||
7020 | -- Task "procedure". These are the internally Expander-generated | |
7021 | -- procedures (task body for instance). | |
7022 | ||
7023 | else | |
7024 | return New_Reference_To (RTE (RE_POK_Task_Procedure), Loc); | |
7025 | end if; | |
7026 | ||
7027 | -- Regular procedure | |
7028 | ||
7029 | else | |
7030 | return New_Reference_To (RTE (RE_POK_Procedure), Loc); | |
7031 | end if; | |
7032 | end if; | |
7033 | end Prim_Op_Kind; | |
7034 | ||
725a69d2 | 7035 | ------------------------ |
7036 | -- Register_Primitive -- | |
7037 | ------------------------ | |
7038 | ||
49260fa5 | 7039 | function Register_Primitive |
725a69d2 | 7040 | (Loc : Source_Ptr; |
49260fa5 | 7041 | Prim : Entity_Id) return List_Id |
725a69d2 | 7042 | is |
cdb1c38f | 7043 | DT_Ptr : Entity_Id; |
7044 | Iface_Prim : Entity_Id; | |
7045 | Iface_Typ : Entity_Id; | |
7046 | Iface_DT_Ptr : Entity_Id; | |
7047 | Iface_DT_Elmt : Elmt_Id; | |
49260fa5 | 7048 | L : constant List_Id := New_List; |
cdb1c38f | 7049 | Pos : Uint; |
7050 | Tag : Entity_Id; | |
cc60bd16 | 7051 | Tag_Typ : Entity_Id; |
cdb1c38f | 7052 | Thunk_Id : Entity_Id; |
7053 | Thunk_Code : Node_Id; | |
725a69d2 | 7054 | |
7055 | begin | |
7056 | pragma Assert (not Restriction_Active (No_Dispatching_Calls)); | |
7057 | ||
7058 | if not RTE_Available (RE_Tag) then | |
49260fa5 | 7059 | return L; |
725a69d2 | 7060 | end if; |
7061 | ||
a652dd51 | 7062 | if not Present (Interface_Alias (Prim)) then |
cc60bd16 | 7063 | Tag_Typ := Scope (DTC_Entity (Prim)); |
acf97c11 | 7064 | Pos := DT_Position (Prim); |
cc60bd16 | 7065 | Tag := First_Tag_Component (Tag_Typ); |
725a69d2 | 7066 | |
7067 | if Is_Predefined_Dispatching_Operation (Prim) | |
7068 | or else Is_Predefined_Dispatching_Alias (Prim) | |
7069 | then | |
cc60bd16 | 7070 | DT_Ptr := |
7071 | Node (Next_Elmt (First_Elmt (Access_Disp_Table (Tag_Typ)))); | |
7072 | ||
49260fa5 | 7073 | Append_To (L, |
725a69d2 | 7074 | Build_Set_Predefined_Prim_Op_Address (Loc, |
7075 | Tag_Node => New_Reference_To (DT_Ptr, Loc), | |
7076 | Position => Pos, | |
acf97c11 | 7077 | Address_Node => |
cc60bd16 | 7078 | Unchecked_Convert_To (RTE (RE_Prim_Ptr), |
acf97c11 | 7079 | Make_Attribute_Reference (Loc, |
7080 | Prefix => New_Reference_To (Prim, Loc), | |
7081 | Attribute_Name => Name_Unrestricted_Access)))); | |
725a69d2 | 7082 | |
9e7de1e1 | 7083 | -- Register copy of the pointer to the 'size primitive in the TSD |
cc60bd16 | 7084 | |
7085 | if Chars (Prim) = Name_uSize | |
7086 | and then RTE_Record_Component_Available (RE_Size_Func) | |
7087 | then | |
7088 | DT_Ptr := Node (First_Elmt (Access_Disp_Table (Tag_Typ))); | |
49260fa5 | 7089 | Append_To (L, |
cc60bd16 | 7090 | Build_Set_Size_Function (Loc, |
7091 | Tag_Node => New_Reference_To (DT_Ptr, Loc), | |
7092 | Size_Func => Prim)); | |
7093 | end if; | |
7094 | ||
725a69d2 | 7095 | else |
7096 | pragma Assert (Pos /= Uint_0 and then Pos <= DT_Entry_Count (Tag)); | |
7097 | ||
cc60bd16 | 7098 | DT_Ptr := Node (First_Elmt (Access_Disp_Table (Tag_Typ))); |
49260fa5 | 7099 | Append_To (L, |
725a69d2 | 7100 | Build_Set_Prim_Op_Address (Loc, |
cc60bd16 | 7101 | Typ => Tag_Typ, |
725a69d2 | 7102 | Tag_Node => New_Reference_To (DT_Ptr, Loc), |
7103 | Position => Pos, | |
acf97c11 | 7104 | Address_Node => |
cc60bd16 | 7105 | Unchecked_Convert_To (RTE (RE_Prim_Ptr), |
acf97c11 | 7106 | Make_Attribute_Reference (Loc, |
7107 | Prefix => New_Reference_To (Prim, Loc), | |
7108 | Attribute_Name => Name_Unrestricted_Access)))); | |
725a69d2 | 7109 | end if; |
7110 | ||
7111 | -- Ada 2005 (AI-251): Primitive associated with an interface type | |
7112 | -- Generate the code of the thunk only if the interface type is not an | |
7113 | -- immediate ancestor of Typ; otherwise the dispatch table associated | |
7114 | -- with the interface is the primary dispatch table and we have nothing | |
7115 | -- else to do here. | |
7116 | ||
7117 | else | |
cc60bd16 | 7118 | Tag_Typ := Find_Dispatching_Type (Alias (Prim)); |
a652dd51 | 7119 | Iface_Typ := Find_Dispatching_Type (Interface_Alias (Prim)); |
725a69d2 | 7120 | |
7121 | pragma Assert (Is_Interface (Iface_Typ)); | |
7122 | ||
17e14451 | 7123 | Expand_Interface_Thunk (Prim, Thunk_Id, Thunk_Code); |
725a69d2 | 7124 | |
a652dd51 | 7125 | if not Is_Ancestor (Iface_Typ, Tag_Typ) |
725a69d2 | 7126 | and then Present (Thunk_Code) |
7127 | then | |
725a69d2 | 7128 | -- Generate the code necessary to fill the appropriate entry of |
7129 | -- the secondary dispatch table of Prim's controlling type with | |
7130 | -- Thunk_Id's address. | |
7131 | ||
cc60bd16 | 7132 | Iface_DT_Elmt := Find_Interface_ADT (Tag_Typ, Iface_Typ); |
cdb1c38f | 7133 | Iface_DT_Ptr := Node (Iface_DT_Elmt); |
7134 | pragma Assert (Has_Thunks (Iface_DT_Ptr)); | |
7135 | ||
a652dd51 | 7136 | Iface_Prim := Interface_Alias (Prim); |
acf97c11 | 7137 | Pos := DT_Position (Iface_Prim); |
7138 | Tag := First_Tag_Component (Iface_Typ); | |
49260fa5 | 7139 | |
7140 | Prepend_To (L, Thunk_Code); | |
725a69d2 | 7141 | |
7142 | if Is_Predefined_Dispatching_Operation (Prim) | |
7143 | or else Is_Predefined_Dispatching_Alias (Prim) | |
7144 | then | |
cdb1c38f | 7145 | Append_To (L, |
725a69d2 | 7146 | Build_Set_Predefined_Prim_Op_Address (Loc, |
acf97c11 | 7147 | Tag_Node => |
7148 | New_Reference_To (Node (Next_Elmt (Iface_DT_Elmt)), Loc), | |
725a69d2 | 7149 | Position => Pos, |
7150 | Address_Node => | |
cc60bd16 | 7151 | Unchecked_Convert_To (RTE (RE_Prim_Ptr), |
acf97c11 | 7152 | Make_Attribute_Reference (Loc, |
7153 | Prefix => New_Reference_To (Thunk_Id, Loc), | |
7154 | Attribute_Name => Name_Unrestricted_Access)))); | |
cdb1c38f | 7155 | |
acf97c11 | 7156 | Next_Elmt (Iface_DT_Elmt); |
cdb1c38f | 7157 | Next_Elmt (Iface_DT_Elmt); |
7158 | Iface_DT_Ptr := Node (Iface_DT_Elmt); | |
7159 | pragma Assert (not Has_Thunks (Iface_DT_Ptr)); | |
7160 | ||
7161 | Append_To (L, | |
7162 | Build_Set_Predefined_Prim_Op_Address (Loc, | |
acf97c11 | 7163 | Tag_Node => |
7164 | New_Reference_To (Node (Next_Elmt (Iface_DT_Elmt)), Loc), | |
cdb1c38f | 7165 | Position => Pos, |
7166 | Address_Node => | |
cc60bd16 | 7167 | Unchecked_Convert_To (RTE (RE_Prim_Ptr), |
acf97c11 | 7168 | Make_Attribute_Reference (Loc, |
7169 | Prefix => New_Reference_To (Alias (Prim), Loc), | |
7170 | Attribute_Name => Name_Unrestricted_Access)))); | |
cdb1c38f | 7171 | |
725a69d2 | 7172 | else |
7173 | pragma Assert (Pos /= Uint_0 | |
7174 | and then Pos <= DT_Entry_Count (Tag)); | |
7175 | ||
cdb1c38f | 7176 | Append_To (L, |
7177 | Build_Set_Prim_Op_Address (Loc, | |
7178 | Typ => Iface_Typ, | |
7179 | Tag_Node => New_Reference_To (Iface_DT_Ptr, Loc), | |
7180 | Position => Pos, | |
acf97c11 | 7181 | Address_Node => |
cc60bd16 | 7182 | Unchecked_Convert_To (RTE (RE_Prim_Ptr), |
acf97c11 | 7183 | Make_Attribute_Reference (Loc, |
7184 | Prefix => New_Reference_To (Thunk_Id, Loc), | |
7185 | Attribute_Name => Name_Unrestricted_Access)))); | |
cdb1c38f | 7186 | |
acf97c11 | 7187 | Next_Elmt (Iface_DT_Elmt); |
cdb1c38f | 7188 | Next_Elmt (Iface_DT_Elmt); |
7189 | Iface_DT_Ptr := Node (Iface_DT_Elmt); | |
7190 | pragma Assert (not Has_Thunks (Iface_DT_Ptr)); | |
7191 | ||
7192 | Append_To (L, | |
725a69d2 | 7193 | Build_Set_Prim_Op_Address (Loc, |
7194 | Typ => Iface_Typ, | |
7195 | Tag_Node => New_Reference_To (Iface_DT_Ptr, Loc), | |
7196 | Position => Pos, | |
acf97c11 | 7197 | Address_Node => |
cc60bd16 | 7198 | Unchecked_Convert_To (RTE (RE_Prim_Ptr), |
acf97c11 | 7199 | Make_Attribute_Reference (Loc, |
7200 | Prefix => New_Reference_To (Alias (Prim), Loc), | |
7201 | Attribute_Name => Name_Unrestricted_Access)))); | |
cdb1c38f | 7202 | |
725a69d2 | 7203 | end if; |
7204 | end if; | |
7205 | end if; | |
49260fa5 | 7206 | |
7207 | return L; | |
725a69d2 | 7208 | end Register_Primitive; |
7209 | ||
ee6ba406 | 7210 | ------------------------- |
7211 | -- Set_All_DT_Position -- | |
7212 | ------------------------- | |
7213 | ||
7214 | procedure Set_All_DT_Position (Typ : Entity_Id) is | |
ee6ba406 | 7215 | |
aad6babd | 7216 | procedure Validate_Position (Prim : Entity_Id); |
36b938a3 | 7217 | -- Check that the position assigned to Prim is completely safe |
aad6babd | 7218 | -- (it has not been assigned to a previously defined primitive |
7219 | -- operation of Typ) | |
7220 | ||
7221 | ----------------------- | |
7222 | -- Validate_Position -- | |
7223 | ----------------------- | |
7224 | ||
7225 | procedure Validate_Position (Prim : Entity_Id) is | |
af647dc7 | 7226 | Op_Elmt : Elmt_Id; |
7227 | Op : Entity_Id; | |
d62940bf | 7228 | |
aad6babd | 7229 | begin |
af647dc7 | 7230 | -- Aliased primitives are safe |
7231 | ||
7232 | if Present (Alias (Prim)) then | |
7233 | return; | |
7234 | end if; | |
7235 | ||
7236 | Op_Elmt := First_Elmt (Primitive_Operations (Typ)); | |
7237 | while Present (Op_Elmt) loop | |
7238 | Op := Node (Op_Elmt); | |
7239 | ||
7240 | -- No need to check against itself | |
7241 | ||
7242 | if Op = Prim then | |
7243 | null; | |
7244 | ||
aad6babd | 7245 | -- Primitive operations covering abstract interfaces are |
7246 | -- allocated later | |
7247 | ||
a652dd51 | 7248 | elsif Present (Interface_Alias (Op)) then |
aad6babd | 7249 | null; |
7250 | ||
68f95949 | 7251 | -- Predefined dispatching operations are completely safe. They |
7252 | -- are allocated at fixed positions in a separate table. | |
aad6babd | 7253 | |
af647dc7 | 7254 | elsif Is_Predefined_Dispatching_Operation (Op) |
7255 | or else Is_Predefined_Dispatching_Alias (Op) | |
7256 | then | |
aad6babd | 7257 | null; |
ee6ba406 | 7258 | |
aad6babd | 7259 | -- Aliased subprograms are safe |
7260 | ||
af647dc7 | 7261 | elsif Present (Alias (Op)) then |
aad6babd | 7262 | null; |
7263 | ||
af647dc7 | 7264 | elsif DT_Position (Op) = DT_Position (Prim) |
7265 | and then not Is_Predefined_Dispatching_Operation (Op) | |
7266 | and then not Is_Predefined_Dispatching_Operation (Prim) | |
7267 | and then not Is_Predefined_Dispatching_Alias (Op) | |
7268 | and then not Is_Predefined_Dispatching_Alias (Prim) | |
7269 | then | |
d62940bf | 7270 | |
7271 | -- Handle aliased subprograms | |
7272 | ||
7273 | declare | |
7274 | Op_1 : Entity_Id; | |
7275 | Op_2 : Entity_Id; | |
7276 | ||
7277 | begin | |
af647dc7 | 7278 | Op_1 := Op; |
d62940bf | 7279 | loop |
7280 | if Present (Overridden_Operation (Op_1)) then | |
7281 | Op_1 := Overridden_Operation (Op_1); | |
7282 | elsif Present (Alias (Op_1)) then | |
7283 | Op_1 := Alias (Op_1); | |
7284 | else | |
7285 | exit; | |
7286 | end if; | |
7287 | end loop; | |
7288 | ||
7289 | Op_2 := Prim; | |
7290 | loop | |
7291 | if Present (Overridden_Operation (Op_2)) then | |
7292 | Op_2 := Overridden_Operation (Op_2); | |
7293 | elsif Present (Alias (Op_2)) then | |
7294 | Op_2 := Alias (Op_2); | |
7295 | else | |
7296 | exit; | |
7297 | end if; | |
7298 | end loop; | |
7299 | ||
7300 | if Op_1 /= Op_2 then | |
7301 | raise Program_Error; | |
7302 | end if; | |
7303 | end; | |
aad6babd | 7304 | end if; |
7305 | ||
af647dc7 | 7306 | Next_Elmt (Op_Elmt); |
aad6babd | 7307 | end loop; |
7308 | end Validate_Position; | |
7309 | ||
af647dc7 | 7310 | -- Local variables |
7311 | ||
7312 | Parent_Typ : constant Entity_Id := Etype (Typ); | |
af647dc7 | 7313 | First_Prim : constant Elmt_Id := First_Elmt (Primitive_Operations (Typ)); |
7314 | The_Tag : constant Entity_Id := First_Tag_Component (Typ); | |
7315 | ||
7316 | Adjusted : Boolean := False; | |
7317 | Finalized : Boolean := False; | |
7318 | ||
343d35dc | 7319 | Count_Prim : Nat; |
7320 | DT_Length : Nat; | |
7321 | Nb_Prim : Nat; | |
af647dc7 | 7322 | Prim : Entity_Id; |
7323 | Prim_Elmt : Elmt_Id; | |
7324 | ||
aad6babd | 7325 | -- Start of processing for Set_All_DT_Position |
7326 | ||
7327 | begin | |
a652dd51 | 7328 | pragma Assert (Present (First_Tag_Component (Typ))); |
7329 | ||
343d35dc | 7330 | -- Set the DT_Position for each primitive operation. Perform some |
36b938a3 | 7331 | -- sanity checks to avoid to build completely inconsistent dispatch |
343d35dc | 7332 | -- tables. |
ee6ba406 | 7333 | |
343d35dc | 7334 | -- First stage: Set the DTC entity of all the primitive operations |
7335 | -- This is required to properly read the DT_Position attribute in | |
7336 | -- the latter stages. | |
ee6ba406 | 7337 | |
343d35dc | 7338 | Prim_Elmt := First_Prim; |
7339 | Count_Prim := 0; | |
7340 | while Present (Prim_Elmt) loop | |
7341 | Prim := Node (Prim_Elmt); | |
ee6ba406 | 7342 | |
343d35dc | 7343 | -- Predefined primitives have a separate dispatch table |
ee6ba406 | 7344 | |
343d35dc | 7345 | if not (Is_Predefined_Dispatching_Operation (Prim) |
7346 | or else Is_Predefined_Dispatching_Alias (Prim)) | |
7347 | then | |
7348 | Count_Prim := Count_Prim + 1; | |
7349 | end if; | |
ee6ba406 | 7350 | |
725a69d2 | 7351 | Set_DTC_Entity_Value (Typ, Prim); |
ee6ba406 | 7352 | |
343d35dc | 7353 | -- Clear any previous value of the DT_Position attribute. In this |
7354 | -- way we ensure that the final position of all the primitives is | |
36b938a3 | 7355 | -- established by the following stages of this algorithm. |
ee6ba406 | 7356 | |
343d35dc | 7357 | Set_DT_Position (Prim, No_Uint); |
ee6ba406 | 7358 | |
343d35dc | 7359 | Next_Elmt (Prim_Elmt); |
7360 | end loop; | |
ee6ba406 | 7361 | |
343d35dc | 7362 | declare |
acf97c11 | 7363 | Fixed_Prim : array (Int range 0 .. Count_Prim) of Boolean := |
7364 | (others => False); | |
7365 | ||
343d35dc | 7366 | E : Entity_Id; |
ee6ba406 | 7367 | |
725a69d2 | 7368 | procedure Handle_Inherited_Private_Subprograms (Typ : Entity_Id); |
7369 | -- Called if Typ is declared in a nested package or a public child | |
7370 | -- package to handle inherited primitives that were inherited by Typ | |
7371 | -- in the visible part, but whose declaration was deferred because | |
7372 | -- the parent operation was private and not visible at that point. | |
7373 | ||
343d35dc | 7374 | procedure Set_Fixed_Prim (Pos : Nat); |
7375 | -- Sets to true an element of the Fixed_Prim table to indicate | |
7376 | -- that this entry of the dispatch table of Typ is occupied. | |
ee6ba406 | 7377 | |
725a69d2 | 7378 | ------------------------------------------ |
7379 | -- Handle_Inherited_Private_Subprograms -- | |
7380 | ------------------------------------------ | |
7381 | ||
7382 | procedure Handle_Inherited_Private_Subprograms (Typ : Entity_Id) is | |
7383 | Op_List : Elist_Id; | |
7384 | Op_Elmt : Elmt_Id; | |
7385 | Op_Elmt_2 : Elmt_Id; | |
7386 | Prim_Op : Entity_Id; | |
7387 | Parent_Subp : Entity_Id; | |
7388 | ||
7389 | begin | |
7390 | Op_List := Primitive_Operations (Typ); | |
7391 | ||
7392 | Op_Elmt := First_Elmt (Op_List); | |
7393 | while Present (Op_Elmt) loop | |
7394 | Prim_Op := Node (Op_Elmt); | |
7395 | ||
7396 | -- Search primitives that are implicit operations with an | |
7397 | -- internal name whose parent operation has a normal name. | |
7398 | ||
7399 | if Present (Alias (Prim_Op)) | |
7400 | and then Find_Dispatching_Type (Alias (Prim_Op)) /= Typ | |
7401 | and then not Comes_From_Source (Prim_Op) | |
7402 | and then Is_Internal_Name (Chars (Prim_Op)) | |
7403 | and then not Is_Internal_Name (Chars (Alias (Prim_Op))) | |
7404 | then | |
7405 | Parent_Subp := Alias (Prim_Op); | |
7406 | ||
7407 | -- Check if the type has an explicit overriding for this | |
7408 | -- primitive. | |
7409 | ||
7410 | Op_Elmt_2 := Next_Elmt (Op_Elmt); | |
7411 | while Present (Op_Elmt_2) loop | |
7412 | if Chars (Node (Op_Elmt_2)) = Chars (Parent_Subp) | |
7413 | and then Type_Conformant (Prim_Op, Node (Op_Elmt_2)) | |
7414 | then | |
7415 | Set_DT_Position (Prim_Op, DT_Position (Parent_Subp)); | |
7416 | Set_DT_Position (Node (Op_Elmt_2), | |
7417 | DT_Position (Parent_Subp)); | |
7418 | Set_Fixed_Prim (UI_To_Int (DT_Position (Prim_Op))); | |
7419 | ||
7420 | goto Next_Primitive; | |
7421 | end if; | |
7422 | ||
7423 | Next_Elmt (Op_Elmt_2); | |
7424 | end loop; | |
7425 | end if; | |
7426 | ||
7427 | <<Next_Primitive>> | |
7428 | Next_Elmt (Op_Elmt); | |
7429 | end loop; | |
7430 | end Handle_Inherited_Private_Subprograms; | |
7431 | ||
343d35dc | 7432 | -------------------- |
7433 | -- Set_Fixed_Prim -- | |
7434 | -------------------- | |
ee6ba406 | 7435 | |
343d35dc | 7436 | procedure Set_Fixed_Prim (Pos : Nat) is |
ee6ba406 | 7437 | begin |
9e7de1e1 | 7438 | pragma Assert (Pos <= Count_Prim); |
343d35dc | 7439 | Fixed_Prim (Pos) := True; |
7440 | exception | |
7441 | when Constraint_Error => | |
7442 | raise Program_Error; | |
7443 | end Set_Fixed_Prim; | |
ee6ba406 | 7444 | |
343d35dc | 7445 | begin |
725a69d2 | 7446 | -- In case of nested packages and public child package it may be |
7447 | -- necessary a special management on inherited subprograms so that | |
7448 | -- the dispatch table is properly filled. | |
7449 | ||
7450 | if Ekind (Scope (Scope (Typ))) = E_Package | |
7451 | and then Scope (Scope (Typ)) /= Standard_Standard | |
7452 | and then ((Is_Derived_Type (Typ) and then not Is_Private_Type (Typ)) | |
7453 | or else | |
7454 | (Nkind (Parent (Typ)) = N_Private_Extension_Declaration | |
7455 | and then Is_Generic_Type (Typ))) | |
7456 | and then In_Open_Scopes (Scope (Etype (Typ))) | |
7457 | and then Typ = Base_Type (Typ) | |
7458 | then | |
7459 | Handle_Inherited_Private_Subprograms (Typ); | |
7460 | end if; | |
7461 | ||
343d35dc | 7462 | -- Second stage: Register fixed entries |
ee6ba406 | 7463 | |
343d35dc | 7464 | Nb_Prim := 0; |
7465 | Prim_Elmt := First_Prim; | |
7466 | while Present (Prim_Elmt) loop | |
7467 | Prim := Node (Prim_Elmt); | |
ee6ba406 | 7468 | |
343d35dc | 7469 | -- Predefined primitives have a separate table and all its |
7470 | -- entries are at predefined fixed positions. | |
ee6ba406 | 7471 | |
343d35dc | 7472 | if Is_Predefined_Dispatching_Operation (Prim) then |
7473 | Set_DT_Position (Prim, Default_Prim_Op_Position (Prim)); | |
ee6ba406 | 7474 | |
343d35dc | 7475 | elsif Is_Predefined_Dispatching_Alias (Prim) then |
7476 | E := Alias (Prim); | |
7477 | while Present (Alias (E)) loop | |
7478 | E := Alias (E); | |
7479 | end loop; | |
d62940bf | 7480 | |
343d35dc | 7481 | Set_DT_Position (Prim, Default_Prim_Op_Position (E)); |
d62940bf | 7482 | |
343d35dc | 7483 | -- Overriding primitives of ancestor abstract interfaces |
ee6ba406 | 7484 | |
a652dd51 | 7485 | elsif Present (Interface_Alias (Prim)) |
7486 | and then Is_Ancestor | |
7487 | (Find_Dispatching_Type (Interface_Alias (Prim)), Typ) | |
343d35dc | 7488 | then |
7489 | pragma Assert (DT_Position (Prim) = No_Uint | |
a652dd51 | 7490 | and then Present (DTC_Entity (Interface_Alias (Prim)))); |
ee6ba406 | 7491 | |
a652dd51 | 7492 | E := Interface_Alias (Prim); |
343d35dc | 7493 | Set_DT_Position (Prim, DT_Position (E)); |
aad6babd | 7494 | |
343d35dc | 7495 | pragma Assert |
7496 | (DT_Position (Alias (Prim)) = No_Uint | |
7497 | or else DT_Position (Alias (Prim)) = DT_Position (E)); | |
7498 | Set_DT_Position (Alias (Prim), DT_Position (E)); | |
7499 | Set_Fixed_Prim (UI_To_Int (DT_Position (Prim))); | |
af647dc7 | 7500 | |
343d35dc | 7501 | -- Overriding primitives must use the same entry as the |
36b938a3 | 7502 | -- overridden primitive. |
af647dc7 | 7503 | |
a652dd51 | 7504 | elsif not Present (Interface_Alias (Prim)) |
343d35dc | 7505 | and then Present (Alias (Prim)) |
17e14451 | 7506 | and then Chars (Prim) = Chars (Alias (Prim)) |
343d35dc | 7507 | and then Find_Dispatching_Type (Alias (Prim)) /= Typ |
a652dd51 | 7508 | and then Is_Ancestor |
343d35dc | 7509 | (Find_Dispatching_Type (Alias (Prim)), Typ) |
7510 | and then Present (DTC_Entity (Alias (Prim))) | |
af647dc7 | 7511 | then |
343d35dc | 7512 | E := Alias (Prim); |
7513 | Set_DT_Position (Prim, DT_Position (E)); | |
aad6babd | 7514 | |
343d35dc | 7515 | if not Is_Predefined_Dispatching_Alias (E) then |
7516 | Set_Fixed_Prim (UI_To_Int (DT_Position (E))); | |
7517 | end if; | |
9dfe12ae | 7518 | end if; |
ee6ba406 | 7519 | |
aad6babd | 7520 | Next_Elmt (Prim_Elmt); |
7521 | end loop; | |
7522 | ||
343d35dc | 7523 | -- Third stage: Fix the position of all the new primitives |
7524 | -- Entries associated with primitives covering interfaces | |
7525 | -- are handled in a latter round. | |
aad6babd | 7526 | |
343d35dc | 7527 | Prim_Elmt := First_Prim; |
7528 | while Present (Prim_Elmt) loop | |
7529 | Prim := Node (Prim_Elmt); | |
aad6babd | 7530 | |
343d35dc | 7531 | -- Skip primitives previously set entries |
aad6babd | 7532 | |
343d35dc | 7533 | if DT_Position (Prim) /= No_Uint then |
7534 | null; | |
aad6babd | 7535 | |
343d35dc | 7536 | -- Primitives covering interface primitives are handled later |
aad6babd | 7537 | |
a652dd51 | 7538 | elsif Present (Interface_Alias (Prim)) then |
343d35dc | 7539 | null; |
aad6babd | 7540 | |
343d35dc | 7541 | else |
7542 | -- Take the next available position in the DT | |
aad6babd | 7543 | |
343d35dc | 7544 | loop |
7545 | Nb_Prim := Nb_Prim + 1; | |
7546 | pragma Assert (Nb_Prim <= Count_Prim); | |
7547 | exit when not Fixed_Prim (Nb_Prim); | |
7548 | end loop; | |
aad6babd | 7549 | |
343d35dc | 7550 | Set_DT_Position (Prim, UI_From_Int (Nb_Prim)); |
7551 | Set_Fixed_Prim (Nb_Prim); | |
7552 | end if; | |
aad6babd | 7553 | |
343d35dc | 7554 | Next_Elmt (Prim_Elmt); |
7555 | end loop; | |
7556 | end; | |
aad6babd | 7557 | |
343d35dc | 7558 | -- Fourth stage: Complete the decoration of primitives covering |
7559 | -- interfaces (that is, propagate the DT_Position attribute | |
7560 | -- from the aliased primitive) | |
aad6babd | 7561 | |
343d35dc | 7562 | Prim_Elmt := First_Prim; |
7563 | while Present (Prim_Elmt) loop | |
7564 | Prim := Node (Prim_Elmt); | |
aad6babd | 7565 | |
343d35dc | 7566 | if DT_Position (Prim) = No_Uint |
a652dd51 | 7567 | and then Present (Interface_Alias (Prim)) |
343d35dc | 7568 | then |
7569 | pragma Assert (Present (Alias (Prim)) | |
7570 | and then Find_Dispatching_Type (Alias (Prim)) = Typ); | |
aad6babd | 7571 | |
343d35dc | 7572 | -- Check if this entry will be placed in the primary DT |
aad6babd | 7573 | |
a652dd51 | 7574 | if Is_Ancestor |
7575 | (Find_Dispatching_Type (Interface_Alias (Prim)), Typ) | |
ee6ba406 | 7576 | then |
343d35dc | 7577 | pragma Assert (DT_Position (Alias (Prim)) /= No_Uint); |
7578 | Set_DT_Position (Prim, DT_Position (Alias (Prim))); | |
aad6babd | 7579 | |
343d35dc | 7580 | -- Otherwise it will be placed in the secondary DT |
aad6babd | 7581 | |
343d35dc | 7582 | else |
7583 | pragma Assert | |
a652dd51 | 7584 | (DT_Position (Interface_Alias (Prim)) /= No_Uint); |
343d35dc | 7585 | Set_DT_Position (Prim, |
a652dd51 | 7586 | DT_Position (Interface_Alias (Prim))); |
aad6babd | 7587 | end if; |
343d35dc | 7588 | end if; |
aad6babd | 7589 | |
343d35dc | 7590 | Next_Elmt (Prim_Elmt); |
7591 | end loop; | |
d62940bf | 7592 | |
343d35dc | 7593 | -- Generate listing showing the contents of the dispatch tables. |
7594 | -- This action is done before some further static checks because | |
7595 | -- in case of critical errors caused by a wrong dispatch table | |
7596 | -- we need to see the contents of such table. | |
d62940bf | 7597 | |
343d35dc | 7598 | if Debug_Flag_ZZ then |
7599 | Write_DT (Typ); | |
7600 | end if; | |
aad6babd | 7601 | |
343d35dc | 7602 | -- Final stage: Ensure that the table is correct plus some further |
7603 | -- verifications concerning the primitives. | |
aad6babd | 7604 | |
343d35dc | 7605 | Prim_Elmt := First_Prim; |
7606 | DT_Length := 0; | |
7607 | while Present (Prim_Elmt) loop | |
7608 | Prim := Node (Prim_Elmt); | |
aad6babd | 7609 | |
343d35dc | 7610 | -- At this point all the primitives MUST have a position |
acf97c11 | 7611 | -- in the dispatch table. |
aad6babd | 7612 | |
343d35dc | 7613 | if DT_Position (Prim) = No_Uint then |
7614 | raise Program_Error; | |
7615 | end if; | |
aad6babd | 7616 | |
343d35dc | 7617 | -- Calculate real size of the dispatch table |
aad6babd | 7618 | |
343d35dc | 7619 | if not (Is_Predefined_Dispatching_Operation (Prim) |
7620 | or else Is_Predefined_Dispatching_Alias (Prim)) | |
7621 | and then UI_To_Int (DT_Position (Prim)) > DT_Length | |
7622 | then | |
7623 | DT_Length := UI_To_Int (DT_Position (Prim)); | |
7624 | end if; | |
aad6babd | 7625 | |
36b938a3 | 7626 | -- Ensure that the assigned position to non-predefined |
343d35dc | 7627 | -- dispatching operations in the dispatch table is correct. |
aad6babd | 7628 | |
343d35dc | 7629 | if not (Is_Predefined_Dispatching_Operation (Prim) |
7630 | or else Is_Predefined_Dispatching_Alias (Prim)) | |
7631 | then | |
7632 | Validate_Position (Prim); | |
7633 | end if; | |
ee6ba406 | 7634 | |
343d35dc | 7635 | if Chars (Prim) = Name_Finalize then |
7636 | Finalized := True; | |
7637 | end if; | |
ee6ba406 | 7638 | |
343d35dc | 7639 | if Chars (Prim) = Name_Adjust then |
7640 | Adjusted := True; | |
7641 | end if; | |
af647dc7 | 7642 | |
343d35dc | 7643 | -- An abstract operation cannot be declared in the private part |
7644 | -- for a visible abstract type, because it could never be over- | |
7645 | -- ridden. For explicit declarations this is checked at the | |
7646 | -- point of declaration, but for inherited operations it must | |
7647 | -- be done when building the dispatch table. | |
7648 | ||
a652dd51 | 7649 | -- Ada 2005 (AI-251): Primitives associated with interfaces are |
7650 | -- excluded from this check because interfaces must be visible in | |
7651 | -- the public and private part (RM 7.3 (7.3/2)) | |
343d35dc | 7652 | |
7653 | if Is_Abstract_Type (Typ) | |
7654 | and then Is_Abstract_Subprogram (Prim) | |
7655 | and then Present (Alias (Prim)) | |
a652dd51 | 7656 | and then not Is_Interface |
7657 | (Find_Dispatching_Type (Ultimate_Alias (Prim))) | |
7658 | and then not Present (Interface_Alias (Prim)) | |
343d35dc | 7659 | and then Is_Derived_Type (Typ) |
7660 | and then In_Private_Part (Current_Scope) | |
7661 | and then | |
7662 | List_Containing (Parent (Prim)) = | |
7663 | Private_Declarations | |
7664 | (Specification (Unit_Declaration_Node (Current_Scope))) | |
7665 | and then Original_View_In_Visible_Part (Typ) | |
7666 | then | |
7667 | -- We exclude Input and Output stream operations because | |
7668 | -- Limited_Controlled inherits useless Input and Output | |
7669 | -- stream operations from Root_Controlled, which can | |
7670 | -- never be overridden. | |
ee6ba406 | 7671 | |
343d35dc | 7672 | if not Is_TSS (Prim, TSS_Stream_Input) |
7673 | and then | |
7674 | not Is_TSS (Prim, TSS_Stream_Output) | |
ee6ba406 | 7675 | then |
343d35dc | 7676 | Error_Msg_NE |
7677 | ("abstract inherited private operation&" & | |
17e14451 | 7678 | " must be overridden (RM 3.9.3(10))", |
343d35dc | 7679 | Parent (Typ), Prim); |
ee6ba406 | 7680 | end if; |
343d35dc | 7681 | end if; |
aad6babd | 7682 | |
343d35dc | 7683 | Next_Elmt (Prim_Elmt); |
7684 | end loop; | |
ee6ba406 | 7685 | |
343d35dc | 7686 | -- Additional check |
aad6babd | 7687 | |
343d35dc | 7688 | if Is_Controlled (Typ) then |
7689 | if not Finalized then | |
7690 | Error_Msg_N | |
7691 | ("controlled type has no explicit Finalize method?", Typ); | |
ee6ba406 | 7692 | |
343d35dc | 7693 | elsif not Adjusted then |
7694 | Error_Msg_N | |
7695 | ("controlled type has no explicit Adjust method?", Typ); | |
ee6ba406 | 7696 | end if; |
343d35dc | 7697 | end if; |
ee6ba406 | 7698 | |
343d35dc | 7699 | -- Set the final size of the Dispatch Table |
aad6babd | 7700 | |
343d35dc | 7701 | Set_DT_Entry_Count (The_Tag, UI_From_Int (DT_Length)); |
ee6ba406 | 7702 | |
725a69d2 | 7703 | -- The derived type must have at least as many components as its parent |
acf97c11 | 7704 | -- (for root types Etype points to itself and the test cannot fail). |
aad6babd | 7705 | |
725a69d2 | 7706 | if DT_Entry_Count (The_Tag) < |
7707 | DT_Entry_Count (First_Tag_Component (Parent_Typ)) | |
7708 | then | |
7709 | raise Program_Error; | |
aad6babd | 7710 | end if; |
ee6ba406 | 7711 | end Set_All_DT_Position; |
7712 | ||
294b942d | 7713 | -------------------------- |
7714 | -- Set_CPP_Constructors -- | |
7715 | -------------------------- | |
ee6ba406 | 7716 | |
294b942d | 7717 | procedure Set_CPP_Constructors (Typ : Entity_Id) is |
ee6ba406 | 7718 | Loc : Source_Ptr; |
7719 | Init : Entity_Id; | |
ee6ba406 | 7720 | E : Entity_Id; |
294b942d | 7721 | Found : Boolean := False; |
7722 | P : Node_Id; | |
7723 | Parms : List_Id; | |
ee6ba406 | 7724 | |
7725 | begin | |
294b942d | 7726 | -- Look for the constructor entities |
ee6ba406 | 7727 | |
7728 | E := Next_Entity (Typ); | |
294b942d | 7729 | while Present (E) loop |
7730 | if Ekind (E) = E_Function | |
7731 | and then Is_Constructor (E) | |
7732 | then | |
7733 | -- Create the init procedure | |
7734 | ||
7735 | Found := True; | |
7736 | Loc := Sloc (E); | |
7737 | Init := Make_Defining_Identifier (Loc, Make_Init_Proc_Name (Typ)); | |
7738 | Parms := | |
7739 | New_List ( | |
7740 | Make_Parameter_Specification (Loc, | |
7741 | Defining_Identifier => | |
7742 | Make_Defining_Identifier (Loc, Name_X), | |
7743 | Parameter_Type => | |
7744 | New_Reference_To (Typ, Loc))); | |
7745 | ||
7746 | if Present (Parameter_Specifications (Parent (E))) then | |
7747 | P := First (Parameter_Specifications (Parent (E))); | |
7748 | while Present (P) loop | |
7749 | Append_To (Parms, | |
7750 | Make_Parameter_Specification (Loc, | |
7751 | Defining_Identifier => | |
7752 | Make_Defining_Identifier (Loc, | |
7753 | Chars (Defining_Identifier (P))), | |
7754 | Parameter_Type => New_Copy_Tree (Parameter_Type (P)))); | |
7755 | Next (P); | |
7756 | end loop; | |
7757 | end if; | |
7758 | ||
7759 | Discard_Node ( | |
7760 | Make_Subprogram_Declaration (Loc, | |
7761 | Make_Procedure_Specification (Loc, | |
7762 | Defining_Unit_Name => Init, | |
7763 | Parameter_Specifications => Parms))); | |
7764 | ||
7765 | Set_Init_Proc (Typ, Init); | |
7766 | Set_Is_Imported (Init); | |
7767 | Set_Interface_Name (Init, Interface_Name (E)); | |
7768 | Set_Convention (Init, Convention_C); | |
7769 | Set_Is_Public (Init); | |
7770 | Set_Has_Completion (Init); | |
7771 | end if; | |
7772 | ||
ee6ba406 | 7773 | Next_Entity (E); |
7774 | end loop; | |
7775 | ||
9dfe12ae | 7776 | -- If there are no constructors, mark the type as abstract since we |
ee6ba406 | 7777 | -- won't be able to declare objects of that type. |
7778 | ||
294b942d | 7779 | if not Found then |
343d35dc | 7780 | Set_Is_Abstract_Type (Typ); |
ee6ba406 | 7781 | end if; |
294b942d | 7782 | end Set_CPP_Constructors; |
ee6ba406 | 7783 | |
725a69d2 | 7784 | -------------------------- |
7785 | -- Set_DTC_Entity_Value -- | |
7786 | -------------------------- | |
7787 | ||
7788 | procedure Set_DTC_Entity_Value | |
7789 | (Tagged_Type : Entity_Id; | |
7790 | Prim : Entity_Id) | |
7791 | is | |
7792 | begin | |
a652dd51 | 7793 | if Present (Interface_Alias (Prim)) |
725a69d2 | 7794 | and then Is_Interface |
a652dd51 | 7795 | (Find_Dispatching_Type (Interface_Alias (Prim))) |
725a69d2 | 7796 | then |
7797 | Set_DTC_Entity (Prim, | |
7798 | Find_Interface_Tag | |
7799 | (T => Tagged_Type, | |
a652dd51 | 7800 | Iface => Find_Dispatching_Type (Interface_Alias (Prim)))); |
725a69d2 | 7801 | else |
7802 | Set_DTC_Entity (Prim, | |
7803 | First_Tag_Component (Tagged_Type)); | |
7804 | end if; | |
7805 | end Set_DTC_Entity_Value; | |
7806 | ||
952af0b9 | 7807 | ----------------- |
7808 | -- Tagged_Kind -- | |
7809 | ----------------- | |
7810 | ||
7811 | function Tagged_Kind (T : Entity_Id) return Node_Id is | |
7812 | Conc_Typ : Entity_Id; | |
7813 | Loc : constant Source_Ptr := Sloc (T); | |
7814 | ||
7815 | begin | |
68f95949 | 7816 | pragma Assert |
7817 | (Is_Tagged_Type (T) and then RTE_Available (RE_Tagged_Kind)); | |
952af0b9 | 7818 | |
7819 | -- Abstract kinds | |
7820 | ||
343d35dc | 7821 | if Is_Abstract_Type (T) then |
952af0b9 | 7822 | if Is_Limited_Record (T) then |
7823 | return New_Reference_To (RTE (RE_TK_Abstract_Limited_Tagged), Loc); | |
7824 | else | |
7825 | return New_Reference_To (RTE (RE_TK_Abstract_Tagged), Loc); | |
7826 | end if; | |
7827 | ||
7828 | -- Concurrent kinds | |
7829 | ||
7830 | elsif Is_Concurrent_Record_Type (T) then | |
7831 | Conc_Typ := Corresponding_Concurrent_Type (T); | |
7832 | ||
17e14451 | 7833 | if Present (Full_View (Conc_Typ)) then |
7834 | Conc_Typ := Full_View (Conc_Typ); | |
7835 | end if; | |
7836 | ||
952af0b9 | 7837 | if Ekind (Conc_Typ) = E_Protected_Type then |
7838 | return New_Reference_To (RTE (RE_TK_Protected), Loc); | |
7839 | else | |
7840 | pragma Assert (Ekind (Conc_Typ) = E_Task_Type); | |
7841 | return New_Reference_To (RTE (RE_TK_Task), Loc); | |
7842 | end if; | |
7843 | ||
7844 | -- Regular tagged kinds | |
7845 | ||
7846 | else | |
7847 | if Is_Limited_Record (T) then | |
7848 | return New_Reference_To (RTE (RE_TK_Limited_Tagged), Loc); | |
7849 | else | |
7850 | return New_Reference_To (RTE (RE_TK_Tagged), Loc); | |
7851 | end if; | |
7852 | end if; | |
7853 | end Tagged_Kind; | |
7854 | ||
aad6babd | 7855 | -------------- |
7856 | -- Write_DT -- | |
7857 | -------------- | |
7858 | ||
7859 | procedure Write_DT (Typ : Entity_Id) is | |
7860 | Elmt : Elmt_Id; | |
7861 | Prim : Node_Id; | |
7862 | ||
7863 | begin | |
7864 | -- Protect this procedure against wrong usage. Required because it will | |
7865 | -- be used directly from GDB | |
7866 | ||
17e14451 | 7867 | if not (Typ <= Last_Node_Id) |
aad6babd | 7868 | or else not Is_Tagged_Type (Typ) |
7869 | then | |
d62940bf | 7870 | Write_Str ("wrong usage: Write_DT must be used with tagged types"); |
aad6babd | 7871 | Write_Eol; |
7872 | return; | |
7873 | end if; | |
7874 | ||
7875 | Write_Int (Int (Typ)); | |
7876 | Write_Str (": "); | |
7877 | Write_Name (Chars (Typ)); | |
7878 | ||
7879 | if Is_Interface (Typ) then | |
7880 | Write_Str (" is interface"); | |
7881 | end if; | |
7882 | ||
7883 | Write_Eol; | |
7884 | ||
7885 | Elmt := First_Elmt (Primitive_Operations (Typ)); | |
7886 | while Present (Elmt) loop | |
7887 | Prim := Node (Elmt); | |
7888 | Write_Str (" - "); | |
7889 | ||
7890 | -- Indicate if this primitive will be allocated in the primary | |
7891 | -- dispatch table or in a secondary dispatch table associated | |
7892 | -- with an abstract interface type | |
7893 | ||
7894 | if Present (DTC_Entity (Prim)) then | |
7895 | if Etype (DTC_Entity (Prim)) = RTE (RE_Tag) then | |
7896 | Write_Str ("[P] "); | |
7897 | else | |
7898 | Write_Str ("[s] "); | |
7899 | end if; | |
7900 | end if; | |
7901 | ||
7902 | -- Output the node of this primitive operation and its name | |
7903 | ||
7904 | Write_Int (Int (Prim)); | |
7905 | Write_Str (": "); | |
68f95949 | 7906 | |
7907 | if Is_Predefined_Dispatching_Operation (Prim) then | |
7908 | Write_Str ("(predefined) "); | |
7909 | end if; | |
7910 | ||
aad6babd | 7911 | Write_Name (Chars (Prim)); |
7912 | ||
7913 | -- Indicate if this primitive has an aliased primitive | |
7914 | ||
7915 | if Present (Alias (Prim)) then | |
7916 | Write_Str (" (alias = "); | |
7917 | Write_Int (Int (Alias (Prim))); | |
7918 | ||
7919 | -- If the DTC_Entity attribute is already set we can also output | |
7920 | -- the name of the interface covered by this primitive (if any) | |
7921 | ||
7922 | if Present (DTC_Entity (Alias (Prim))) | |
7923 | and then Is_Interface (Scope (DTC_Entity (Alias (Prim)))) | |
7924 | then | |
7925 | Write_Str (" from interface "); | |
7926 | Write_Name (Chars (Scope (DTC_Entity (Alias (Prim))))); | |
7927 | end if; | |
7928 | ||
a652dd51 | 7929 | if Present (Interface_Alias (Prim)) then |
aad6babd | 7930 | Write_Str (", AI_Alias of "); |
a652dd51 | 7931 | Write_Name |
7932 | (Chars (Find_Dispatching_Type (Interface_Alias (Prim)))); | |
aad6babd | 7933 | Write_Char (':'); |
a652dd51 | 7934 | Write_Int (Int (Interface_Alias (Prim))); |
aad6babd | 7935 | end if; |
7936 | ||
7937 | Write_Str (")"); | |
7938 | end if; | |
7939 | ||
7940 | -- Display the final position of this primitive in its associated | |
7941 | -- (primary or secondary) dispatch table | |
7942 | ||
7943 | if Present (DTC_Entity (Prim)) | |
7944 | and then DT_Position (Prim) /= No_Uint | |
7945 | then | |
7946 | Write_Str (" at #"); | |
7947 | Write_Int (UI_To_Int (DT_Position (Prim))); | |
7948 | end if; | |
7949 | ||
343d35dc | 7950 | if Is_Abstract_Subprogram (Prim) then |
aad6babd | 7951 | Write_Str (" is abstract;"); |
af647dc7 | 7952 | |
7953 | -- Check if this is a null primitive | |
7954 | ||
7955 | elsif Comes_From_Source (Prim) | |
7956 | and then Ekind (Prim) = E_Procedure | |
7957 | and then Null_Present (Parent (Prim)) | |
7958 | then | |
7959 | Write_Str (" is null;"); | |
aad6babd | 7960 | end if; |
7961 | ||
555c63a6 | 7962 | if Is_Eliminated (Ultimate_Alias (Prim)) then |
7963 | Write_Str (" (eliminated)"); | |
7964 | end if; | |
7965 | ||
aad6babd | 7966 | Write_Eol; |
7967 | ||
7968 | Next_Elmt (Elmt); | |
7969 | end loop; | |
7970 | end Write_DT; | |
7971 | ||
ee6ba406 | 7972 | end Exp_Disp; |