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