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