| 1 |
------------------------------------------------------------------------------ |
| 2 |
-- -- |
| 3 |
-- GNAT COMPILER COMPONENTS -- |
| 4 |
-- -- |
| 5 |
-- E X P _ A T A G -- |
| 6 |
-- -- |
| 7 |
-- B o d y -- |
| 8 |
-- -- |
| 9 |
-- Copyright (C) 2006-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 Atree; use Atree; |
| 27 |
with Einfo; use Einfo; |
| 28 |
with Einfo.Entities; use Einfo.Entities; |
| 29 |
with Einfo.Utils; use Einfo.Utils; |
| 30 |
with Elists; use Elists; |
| 31 |
with Exp_Disp; use Exp_Disp; |
| 32 |
with Namet; use Namet; |
| 33 |
with Nlists; use Nlists; |
| 34 |
with Nmake; use Nmake; |
| 35 |
with Opt; use Opt; |
| 36 |
with Rtsfind; use Rtsfind; |
| 37 |
with Sinfo; use Sinfo; |
| 38 |
with Sinfo.Nodes; use Sinfo.Nodes; |
| 39 |
with Sinfo.Utils; use Sinfo.Utils; |
| 40 |
with Sem_Aux; use Sem_Aux; |
| 41 |
with Sem_Disp; use Sem_Disp; |
| 42 |
with Sem_Util; use Sem_Util; |
| 43 |
with Stand; use Stand; |
| 44 |
with Snames; use Snames; |
| 45 |
with Tbuild; use Tbuild; |
| 46 |
|
| 47 |
package body Exp_Atag is |
| 48 |
|
| 49 |
----------------------- |
| 50 |
-- Local Subprograms -- |
| 51 |
----------------------- |
| 52 |
|
| 53 |
function Build_DT |
| 54 |
(Loc : Source_Ptr; |
| 55 |
Tag_Node : Node_Id) return Node_Id; |
| 56 |
-- Build code that displaces the Tag to reference the base of the wrapper |
| 57 |
-- record |
| 58 |
-- |
| 59 |
-- Generates: |
| 60 |
-- To_Dispatch_Table_Ptr |
| 61 |
-- (To_Address (Tag_Node) - Tag_Node.Prims_Ptr'Position); |
| 62 |
|
| 63 |
function Build_Range (Loc : Source_Ptr; Lo, Hi : Nat) return Node_Id; |
| 64 |
-- Build an N_Range node for [Lo; Hi] with Standard.Natural type |
| 65 |
|
| 66 |
function Build_TSD |
| 67 |
(Loc : Source_Ptr; |
| 68 |
Tag_Node_Addr : Node_Id) return Node_Id; |
| 69 |
-- Build code that retrieves the address of the record containing the Type |
| 70 |
-- Specific Data generated by GNAT. |
| 71 |
-- |
| 72 |
-- Generate: To_Type_Specific_Data_Ptr |
| 73 |
-- (To_Addr_Ptr (Tag_Node_Addr - Typeinfo_Offset).all); |
| 74 |
|
| 75 |
function Build_Val (Loc : Source_Ptr; V : Uint) return Node_Id; |
| 76 |
-- Build an N_Integer_Literal node for V with Standard.Natural type |
| 77 |
|
| 78 |
------------------------------------------------ |
| 79 |
-- Build_Common_Dispatching_Select_Statements -- |
| 80 |
------------------------------------------------ |
| 81 |
|
| 82 |
procedure Build_Common_Dispatching_Select_Statements |
| 83 |
(Typ : Entity_Id; |
| 84 |
Stmts : List_Id) |
| 85 |
is |
| 86 |
Loc : constant Source_Ptr := Sloc (Typ); |
| 87 |
Tag_Node : Node_Id; |
| 88 |
|
| 89 |
begin |
| 90 |
-- Generate: |
| 91 |
-- C := get_prim_op_kind (tag! (<type>VP), S); |
| 92 |
|
| 93 |
-- where C is the out parameter capturing the call kind and S is the |
| 94 |
-- dispatch table slot number. |
| 95 |
|
| 96 |
if Tagged_Type_Expansion then |
| 97 |
Tag_Node := |
| 98 |
Unchecked_Convert_To (RTE (RE_Tag), |
| 99 |
New_Occurrence_Of |
| 100 |
(Node (First_Elmt (Access_Disp_Table (Typ))), Loc)); |
| 101 |
|
| 102 |
else |
| 103 |
Tag_Node := |
| 104 |
Make_Attribute_Reference (Loc, |
| 105 |
Prefix => New_Occurrence_Of (Typ, Loc), |
| 106 |
Attribute_Name => Name_Tag); |
| 107 |
end if; |
| 108 |
|
| 109 |
Append_To (Stmts, |
| 110 |
Make_Assignment_Statement (Loc, |
| 111 |
Name => Make_Identifier (Loc, Name_uC), |
| 112 |
Expression => |
| 113 |
Make_Function_Call (Loc, |
| 114 |
Name => |
| 115 |
New_Occurrence_Of (RTE (RE_Get_Prim_Op_Kind), Loc), |
| 116 |
Parameter_Associations => New_List ( |
| 117 |
Tag_Node, |
| 118 |
Make_Identifier (Loc, Name_uS))))); |
| 119 |
|
| 120 |
-- Generate: |
| 121 |
|
| 122 |
-- if C = POK_Procedure |
| 123 |
-- or else C = POK_Protected_Procedure |
| 124 |
-- or else C = POK_Task_Procedure; |
| 125 |
-- then |
| 126 |
-- F := True; |
| 127 |
-- return; |
| 128 |
|
| 129 |
-- where F is the out parameter capturing the status of a potential |
| 130 |
-- entry call. |
| 131 |
|
| 132 |
Append_To (Stmts, |
| 133 |
Make_If_Statement (Loc, |
| 134 |
|
| 135 |
Condition => |
| 136 |
Make_Or_Else (Loc, |
| 137 |
Left_Opnd => |
| 138 |
Make_Op_Eq (Loc, |
| 139 |
Left_Opnd => Make_Identifier (Loc, Name_uC), |
| 140 |
Right_Opnd => |
| 141 |
New_Occurrence_Of (RTE (RE_POK_Procedure), Loc)), |
| 142 |
Right_Opnd => |
| 143 |
Make_Or_Else (Loc, |
| 144 |
Left_Opnd => |
| 145 |
Make_Op_Eq (Loc, |
| 146 |
Left_Opnd => Make_Identifier (Loc, Name_uC), |
| 147 |
Right_Opnd => |
| 148 |
New_Occurrence_Of |
| 149 |
(RTE (RE_POK_Protected_Procedure), Loc)), |
| 150 |
Right_Opnd => |
| 151 |
Make_Op_Eq (Loc, |
| 152 |
Left_Opnd => Make_Identifier (Loc, Name_uC), |
| 153 |
Right_Opnd => |
| 154 |
New_Occurrence_Of |
| 155 |
(RTE (RE_POK_Task_Procedure), Loc)))), |
| 156 |
|
| 157 |
Then_Statements => |
| 158 |
New_List ( |
| 159 |
Make_Assignment_Statement (Loc, |
| 160 |
Name => Make_Identifier (Loc, Name_uF), |
| 161 |
Expression => New_Occurrence_Of (Standard_True, Loc)), |
| 162 |
Make_Simple_Return_Statement (Loc)))); |
| 163 |
end Build_Common_Dispatching_Select_Statements; |
| 164 |
|
| 165 |
-------------- |
| 166 |
-- Build_DT -- |
| 167 |
-------------- |
| 168 |
|
| 169 |
function Build_DT |
| 170 |
(Loc : Source_Ptr; |
| 171 |
Tag_Node : Node_Id) return Node_Id |
| 172 |
is |
| 173 |
begin |
| 174 |
return |
| 175 |
Make_Function_Call (Loc, |
| 176 |
Name => New_Occurrence_Of (RTE (RE_DT), Loc), |
| 177 |
Parameter_Associations => New_List ( |
| 178 |
Unchecked_Convert_To (RTE (RE_Tag), Tag_Node))); |
| 179 |
end Build_DT; |
| 180 |
|
| 181 |
---------------------------- |
| 182 |
-- Build_Get_Access_Level -- |
| 183 |
---------------------------- |
| 184 |
|
| 185 |
function Build_Get_Access_Level |
| 186 |
(Loc : Source_Ptr; |
| 187 |
Tag_Node : Node_Id) return Node_Id |
| 188 |
is |
| 189 |
begin |
| 190 |
return |
| 191 |
Make_Selected_Component (Loc, |
| 192 |
Prefix => |
| 193 |
Make_Explicit_Dereference (Loc, |
| 194 |
Build_TSD (Loc, |
| 195 |
Unchecked_Convert_To (RTE (RE_Address), Tag_Node))), |
| 196 |
Selector_Name => |
| 197 |
New_Occurrence_Of |
| 198 |
(RTE_Record_Component (RE_Access_Level), Loc)); |
| 199 |
end Build_Get_Access_Level; |
| 200 |
|
| 201 |
------------------------- |
| 202 |
-- Build_Get_Alignment -- |
| 203 |
------------------------- |
| 204 |
|
| 205 |
function Build_Get_Alignment |
| 206 |
(Loc : Source_Ptr; |
| 207 |
Tag_Node : Node_Id) return Node_Id |
| 208 |
is |
| 209 |
begin |
| 210 |
return |
| 211 |
Make_Selected_Component (Loc, |
| 212 |
Prefix => |
| 213 |
Make_Explicit_Dereference (Loc, |
| 214 |
Build_TSD (Loc, |
| 215 |
Unchecked_Convert_To (RTE (RE_Address), Tag_Node))), |
| 216 |
Selector_Name => |
| 217 |
New_Occurrence_Of (RTE_Record_Component (RE_Alignment), Loc)); |
| 218 |
end Build_Get_Alignment; |
| 219 |
|
| 220 |
------------------------------------------ |
| 221 |
-- Build_Get_Predefined_Prim_Op_Address -- |
| 222 |
------------------------------------------ |
| 223 |
|
| 224 |
procedure Build_Get_Predefined_Prim_Op_Address |
| 225 |
(Loc : Source_Ptr; |
| 226 |
Position : Uint; |
| 227 |
Tag_Node : in out Node_Id; |
| 228 |
New_Node : out Node_Id) |
| 229 |
is |
| 230 |
Ctrl_Tag : Node_Id; |
| 231 |
|
| 232 |
begin |
| 233 |
Ctrl_Tag := Unchecked_Convert_To (RTE (RE_Address), Tag_Node); |
| 234 |
|
| 235 |
-- Unchecked_Convert_To relocates the controlling tag node and therefore |
| 236 |
-- we must update it. |
| 237 |
|
| 238 |
Tag_Node := Expression (Ctrl_Tag); |
| 239 |
|
| 240 |
-- Build code that retrieves the address of the dispatch table |
| 241 |
-- containing the predefined Ada primitives: |
| 242 |
-- |
| 243 |
-- Generate: |
| 244 |
-- To_Predef_Prims_Table_Ptr |
| 245 |
-- (To_Addr_Ptr (To_Address (Tag) - Predef_Prims_Offset).all); |
| 246 |
|
| 247 |
New_Node := |
| 248 |
Make_Indexed_Component (Loc, |
| 249 |
Prefix => |
| 250 |
Unchecked_Convert_To (RTE (RE_Predef_Prims_Table_Ptr), |
| 251 |
Make_Explicit_Dereference (Loc, |
| 252 |
Unchecked_Convert_To (RTE (RE_Addr_Ptr), |
| 253 |
Make_Function_Call (Loc, |
| 254 |
Name => |
| 255 |
Make_Expanded_Name (Loc, |
| 256 |
Chars => Name_Op_Subtract, |
| 257 |
Prefix => |
| 258 |
New_Occurrence_Of |
| 259 |
(RTU_Entity (System_Storage_Elements), Loc), |
| 260 |
Selector_Name => |
| 261 |
Make_Identifier (Loc, Name_Op_Subtract)), |
| 262 |
Parameter_Associations => New_List ( |
| 263 |
Ctrl_Tag, |
| 264 |
New_Occurrence_Of |
| 265 |
(RTE (RE_DT_Predef_Prims_Offset), Loc)))))), |
| 266 |
Expressions => |
| 267 |
New_List (Build_Val (Loc, Position))); |
| 268 |
end Build_Get_Predefined_Prim_Op_Address; |
| 269 |
|
| 270 |
----------------------------- |
| 271 |
-- Build_Inherit_CPP_Prims -- |
| 272 |
----------------------------- |
| 273 |
|
| 274 |
function Build_Inherit_CPP_Prims (Typ : Entity_Id) return List_Id is |
| 275 |
Loc : constant Source_Ptr := Sloc (Typ); |
| 276 |
CPP_Nb_Prims : constant Nat := CPP_Num_Prims (Typ); |
| 277 |
CPP_Table : array (1 .. CPP_Nb_Prims) of Boolean := (others => False); |
| 278 |
CPP_Typ : constant Entity_Id := Enclosing_CPP_Parent (Typ); |
| 279 |
Result : constant List_Id := New_List; |
| 280 |
Parent_Typ : constant Entity_Id := Etype (Typ); |
| 281 |
E : Entity_Id; |
| 282 |
Elmt : Elmt_Id; |
| 283 |
Parent_Tag : Entity_Id; |
| 284 |
Prim : Entity_Id; |
| 285 |
Prim_Pos : Nat; |
| 286 |
Typ_Tag : Entity_Id; |
| 287 |
|
| 288 |
begin |
| 289 |
pragma Assert (not Is_CPP_Class (Typ)); |
| 290 |
|
| 291 |
-- No code needed if this type has no primitives inherited from C++ |
| 292 |
|
| 293 |
if CPP_Nb_Prims = 0 then |
| 294 |
return Result; |
| 295 |
end if; |
| 296 |
|
| 297 |
-- Stage 1: Inherit and override C++ slots of the primary dispatch table |
| 298 |
|
| 299 |
-- Generate: |
| 300 |
-- Typ'Tag (Prim_Pos) := Prim'Unrestricted_Access; |
| 301 |
|
| 302 |
Parent_Tag := Node (First_Elmt (Access_Disp_Table (Parent_Typ))); |
| 303 |
Typ_Tag := Node (First_Elmt (Access_Disp_Table (Typ))); |
| 304 |
|
| 305 |
Elmt := First_Elmt (Primitive_Operations (Typ)); |
| 306 |
while Present (Elmt) loop |
| 307 |
Prim := Node (Elmt); |
| 308 |
E := Ultimate_Alias (Prim); |
| 309 |
Prim_Pos := UI_To_Int (DT_Position (E)); |
| 310 |
|
| 311 |
-- Skip predefined, abstract, and eliminated primitives. Skip also |
| 312 |
-- primitives not located in the C++ part of the dispatch table. |
| 313 |
|
| 314 |
if not Is_Predefined_Dispatching_Operation (Prim) |
| 315 |
and then not Is_Predefined_Dispatching_Operation (E) |
| 316 |
and then No (Interface_Alias (Prim)) |
| 317 |
and then not Is_Abstract_Subprogram (E) |
| 318 |
and then not Is_Eliminated (E) |
| 319 |
and then Prim_Pos <= CPP_Nb_Prims |
| 320 |
and then Find_Dispatching_Type (E) = Typ |
| 321 |
then |
| 322 |
-- Remember that this slot is used |
| 323 |
|
| 324 |
pragma Assert (CPP_Table (Prim_Pos) = False); |
| 325 |
CPP_Table (Prim_Pos) := True; |
| 326 |
|
| 327 |
Append_To (Result, |
| 328 |
Make_Assignment_Statement (Loc, |
| 329 |
Name => |
| 330 |
Make_Indexed_Component (Loc, |
| 331 |
Prefix => |
| 332 |
Make_Explicit_Dereference (Loc, |
| 333 |
Unchecked_Convert_To |
| 334 |
(Node (Last_Elmt (Access_Disp_Table (Typ))), |
| 335 |
New_Occurrence_Of (Typ_Tag, Loc))), |
| 336 |
Expressions => |
| 337 |
New_List (Build_Val (Loc, UI_From_Int (Prim_Pos)))), |
| 338 |
|
| 339 |
Expression => |
| 340 |
Unchecked_Convert_To (RTE (RE_Prim_Ptr), |
| 341 |
Make_Attribute_Reference (Loc, |
| 342 |
Prefix => New_Occurrence_Of (E, Loc), |
| 343 |
Attribute_Name => Name_Unrestricted_Access)))); |
| 344 |
end if; |
| 345 |
|
| 346 |
Next_Elmt (Elmt); |
| 347 |
end loop; |
| 348 |
|
| 349 |
-- If all primitives have been overridden then there is no need to copy |
| 350 |
-- from Typ's parent its dispatch table. Otherwise, if some primitive is |
| 351 |
-- inherited from the parent we copy only the C++ part of the dispatch |
| 352 |
-- table from the parent before the assignments that initialize the |
| 353 |
-- overridden primitives. |
| 354 |
|
| 355 |
-- Generate: |
| 356 |
|
| 357 |
-- type CPP_TypG is array (1 .. CPP_Nb_Prims) ofd Prim_Ptr; |
| 358 |
-- type CPP_TypH is access CPP_TypG; |
| 359 |
-- CPP_TypG!(Typ_Tag).all := CPP_TypG!(Parent_Tag).all; |
| 360 |
|
| 361 |
-- Note: There is no need to duplicate the declarations of CPP_TypG and |
| 362 |
-- CPP_TypH because, for expansion of dispatching calls, these |
| 363 |
-- entities are stored in the last elements of Access_Disp_Table. |
| 364 |
|
| 365 |
for J in CPP_Table'Range loop |
| 366 |
if not CPP_Table (J) then |
| 367 |
Prepend_To (Result, |
| 368 |
Make_Assignment_Statement (Loc, |
| 369 |
Name => |
| 370 |
Make_Explicit_Dereference (Loc, |
| 371 |
Unchecked_Convert_To |
| 372 |
(Node (Last_Elmt (Access_Disp_Table (CPP_Typ))), |
| 373 |
New_Occurrence_Of (Typ_Tag, Loc))), |
| 374 |
Expression => |
| 375 |
Make_Explicit_Dereference (Loc, |
| 376 |
Unchecked_Convert_To |
| 377 |
(Node (Last_Elmt (Access_Disp_Table (CPP_Typ))), |
| 378 |
New_Occurrence_Of (Parent_Tag, Loc))))); |
| 379 |
exit; |
| 380 |
end if; |
| 381 |
end loop; |
| 382 |
|
| 383 |
-- Stage 2: Inherit and override C++ slots of secondary dispatch tables |
| 384 |
|
| 385 |
declare |
| 386 |
Iface : Entity_Id; |
| 387 |
Iface_Nb_Prims : Nat; |
| 388 |
Parent_Ifaces_List : Elist_Id; |
| 389 |
Parent_Ifaces_Comp_List : Elist_Id; |
| 390 |
Parent_Ifaces_Tag_List : Elist_Id; |
| 391 |
Parent_Iface_Tag_Elmt : Elmt_Id; |
| 392 |
Typ_Ifaces_List : Elist_Id; |
| 393 |
Typ_Ifaces_Comp_List : Elist_Id; |
| 394 |
Typ_Ifaces_Tag_List : Elist_Id; |
| 395 |
Typ_Iface_Tag_Elmt : Elmt_Id; |
| 396 |
|
| 397 |
begin |
| 398 |
Collect_Interfaces_Info |
| 399 |
(T => Parent_Typ, |
| 400 |
Ifaces_List => Parent_Ifaces_List, |
| 401 |
Components_List => Parent_Ifaces_Comp_List, |
| 402 |
Tags_List => Parent_Ifaces_Tag_List); |
| 403 |
|
| 404 |
Collect_Interfaces_Info |
| 405 |
(T => Typ, |
| 406 |
Ifaces_List => Typ_Ifaces_List, |
| 407 |
Components_List => Typ_Ifaces_Comp_List, |
| 408 |
Tags_List => Typ_Ifaces_Tag_List); |
| 409 |
|
| 410 |
Parent_Iface_Tag_Elmt := First_Elmt (Parent_Ifaces_Tag_List); |
| 411 |
Typ_Iface_Tag_Elmt := First_Elmt (Typ_Ifaces_Tag_List); |
| 412 |
while Present (Parent_Iface_Tag_Elmt) loop |
| 413 |
Parent_Tag := Node (Parent_Iface_Tag_Elmt); |
| 414 |
Typ_Tag := Node (Typ_Iface_Tag_Elmt); |
| 415 |
|
| 416 |
pragma Assert |
| 417 |
(Related_Type (Parent_Tag) = Related_Type (Typ_Tag)); |
| 418 |
Iface := Related_Type (Parent_Tag); |
| 419 |
|
| 420 |
Iface_Nb_Prims := |
| 421 |
UI_To_Int (DT_Entry_Count (First_Tag_Component (Iface))); |
| 422 |
|
| 423 |
if Iface_Nb_Prims > 0 then |
| 424 |
|
| 425 |
-- Update slots of overridden primitives |
| 426 |
|
| 427 |
declare |
| 428 |
Last_Nod : constant Node_Id := Last (Result); |
| 429 |
Nb_Prims : constant Nat := UI_To_Int |
| 430 |
(DT_Entry_Count |
| 431 |
(First_Tag_Component (Iface))); |
| 432 |
Elmt : Elmt_Id; |
| 433 |
Prim : Entity_Id; |
| 434 |
E : Entity_Id; |
| 435 |
Prim_Pos : Nat; |
| 436 |
|
| 437 |
Prims_Table : array (1 .. Nb_Prims) of Boolean; |
| 438 |
|
| 439 |
begin |
| 440 |
Prims_Table := (others => False); |
| 441 |
|
| 442 |
Elmt := First_Elmt (Primitive_Operations (Typ)); |
| 443 |
while Present (Elmt) loop |
| 444 |
Prim := Node (Elmt); |
| 445 |
E := Ultimate_Alias (Prim); |
| 446 |
|
| 447 |
if not Is_Predefined_Dispatching_Operation (Prim) |
| 448 |
and then Present (Interface_Alias (Prim)) |
| 449 |
and then Find_Dispatching_Type (Interface_Alias (Prim)) |
| 450 |
= Iface |
| 451 |
and then not Is_Abstract_Subprogram (E) |
| 452 |
and then not Is_Eliminated (E) |
| 453 |
and then Find_Dispatching_Type (E) = Typ |
| 454 |
then |
| 455 |
Prim_Pos := UI_To_Int (DT_Position (Prim)); |
| 456 |
|
| 457 |
-- Remember that this slot is already initialized |
| 458 |
|
| 459 |
pragma Assert (Prims_Table (Prim_Pos) = False); |
| 460 |
Prims_Table (Prim_Pos) := True; |
| 461 |
|
| 462 |
Append_To (Result, |
| 463 |
Make_Assignment_Statement (Loc, |
| 464 |
Name => |
| 465 |
Make_Indexed_Component (Loc, |
| 466 |
Prefix => |
| 467 |
Make_Explicit_Dereference (Loc, |
| 468 |
Unchecked_Convert_To |
| 469 |
(Node |
| 470 |
(Last_Elmt |
| 471 |
(Access_Disp_Table (Iface))), |
| 472 |
New_Occurrence_Of (Typ_Tag, Loc))), |
| 473 |
Expressions => |
| 474 |
New_List |
| 475 |
(Build_Val (Loc, UI_From_Int (Prim_Pos)))), |
| 476 |
|
| 477 |
Expression => |
| 478 |
Unchecked_Convert_To (RTE (RE_Prim_Ptr), |
| 479 |
Make_Attribute_Reference (Loc, |
| 480 |
Prefix => New_Occurrence_Of (E, Loc), |
| 481 |
Attribute_Name => |
| 482 |
Name_Unrestricted_Access)))); |
| 483 |
end if; |
| 484 |
|
| 485 |
Next_Elmt (Elmt); |
| 486 |
end loop; |
| 487 |
|
| 488 |
-- Check if all primitives from the parent have been |
| 489 |
-- overridden (to avoid copying the whole secondary |
| 490 |
-- table from the parent). |
| 491 |
|
| 492 |
-- IfaceG!(Typ_Sec_Tag).all := IfaceG!(Parent_Sec_Tag).all; |
| 493 |
|
| 494 |
for J in Prims_Table'Range loop |
| 495 |
if not Prims_Table (J) then |
| 496 |
Insert_After (Last_Nod, |
| 497 |
Make_Assignment_Statement (Loc, |
| 498 |
Name => |
| 499 |
Make_Explicit_Dereference (Loc, |
| 500 |
Unchecked_Convert_To |
| 501 |
(Node (Last_Elmt (Access_Disp_Table (Iface))), |
| 502 |
New_Occurrence_Of (Typ_Tag, Loc))), |
| 503 |
Expression => |
| 504 |
Make_Explicit_Dereference (Loc, |
| 505 |
Unchecked_Convert_To |
| 506 |
(Node (Last_Elmt (Access_Disp_Table (Iface))), |
| 507 |
New_Occurrence_Of (Parent_Tag, Loc))))); |
| 508 |
exit; |
| 509 |
end if; |
| 510 |
end loop; |
| 511 |
end; |
| 512 |
end if; |
| 513 |
|
| 514 |
Next_Elmt (Typ_Iface_Tag_Elmt); |
| 515 |
Next_Elmt (Parent_Iface_Tag_Elmt); |
| 516 |
end loop; |
| 517 |
end; |
| 518 |
|
| 519 |
return Result; |
| 520 |
end Build_Inherit_CPP_Prims; |
| 521 |
|
| 522 |
------------------------- |
| 523 |
-- Build_Inherit_Prims -- |
| 524 |
------------------------- |
| 525 |
|
| 526 |
function Build_Inherit_Prims |
| 527 |
(Loc : Source_Ptr; |
| 528 |
Typ : Entity_Id; |
| 529 |
Old_Tag_Node : Node_Id; |
| 530 |
New_Tag_Node : Node_Id; |
| 531 |
Num_Prims : Nat) return Node_Id |
| 532 |
is |
| 533 |
begin |
| 534 |
if RTE_Available (RE_DT) then |
| 535 |
return |
| 536 |
Make_Assignment_Statement (Loc, |
| 537 |
Name => |
| 538 |
Make_Slice (Loc, |
| 539 |
Prefix => |
| 540 |
Make_Selected_Component (Loc, |
| 541 |
Prefix => |
| 542 |
Make_Explicit_Dereference (Loc, |
| 543 |
Build_DT (Loc, New_Tag_Node)), |
| 544 |
Selector_Name => |
| 545 |
New_Occurrence_Of |
| 546 |
(RTE_Record_Component (RE_Prims_Ptr), Loc)), |
| 547 |
Discrete_Range => |
| 548 |
Build_Range (Loc, 1, Num_Prims)), |
| 549 |
|
| 550 |
Expression => |
| 551 |
Make_Slice (Loc, |
| 552 |
Prefix => |
| 553 |
Make_Selected_Component (Loc, |
| 554 |
Prefix => |
| 555 |
Make_Explicit_Dereference (Loc, |
| 556 |
Build_DT (Loc, Old_Tag_Node)), |
| 557 |
Selector_Name => |
| 558 |
New_Occurrence_Of |
| 559 |
(RTE_Record_Component (RE_Prims_Ptr), Loc)), |
| 560 |
Discrete_Range => |
| 561 |
Build_Range (Loc, 1, Num_Prims))); |
| 562 |
else |
| 563 |
return |
| 564 |
Make_Assignment_Statement (Loc, |
| 565 |
Name => |
| 566 |
Make_Slice (Loc, |
| 567 |
Prefix => |
| 568 |
Unchecked_Convert_To |
| 569 |
(Node (Last_Elmt (Access_Disp_Table (Typ))), |
| 570 |
New_Tag_Node), |
| 571 |
Discrete_Range => |
| 572 |
Build_Range (Loc, 1, Num_Prims)), |
| 573 |
|
| 574 |
Expression => |
| 575 |
Make_Slice (Loc, |
| 576 |
Prefix => |
| 577 |
Unchecked_Convert_To |
| 578 |
(Node (Last_Elmt (Access_Disp_Table (Typ))), |
| 579 |
Old_Tag_Node), |
| 580 |
Discrete_Range => |
| 581 |
Build_Range (Loc, 1, Num_Prims))); |
| 582 |
end if; |
| 583 |
end Build_Inherit_Prims; |
| 584 |
|
| 585 |
------------------------------- |
| 586 |
-- Build_Get_Prim_Op_Address -- |
| 587 |
------------------------------- |
| 588 |
|
| 589 |
procedure Build_Get_Prim_Op_Address |
| 590 |
(Loc : Source_Ptr; |
| 591 |
Typ : Entity_Id; |
| 592 |
Position : Uint; |
| 593 |
Tag_Node : in out Node_Id; |
| 594 |
New_Node : out Node_Id) |
| 595 |
is |
| 596 |
New_Prefix : Node_Id; |
| 597 |
|
| 598 |
begin |
| 599 |
pragma Assert |
| 600 |
(Position <= DT_Entry_Count (First_Tag_Component (Typ))); |
| 601 |
|
| 602 |
-- At the end of the Access_Disp_Table list we have the type |
| 603 |
-- declaration required to convert the tag into a pointer to |
| 604 |
-- the prims_ptr table (see Freeze_Record_Type). |
| 605 |
|
| 606 |
New_Prefix := |
| 607 |
Unchecked_Convert_To |
| 608 |
(Node (Last_Elmt (Access_Disp_Table (Typ))), Tag_Node); |
| 609 |
|
| 610 |
-- Unchecked_Convert_To relocates the controlling tag node and therefore |
| 611 |
-- we must update it. |
| 612 |
|
| 613 |
Tag_Node := Expression (New_Prefix); |
| 614 |
|
| 615 |
New_Node := |
| 616 |
Make_Indexed_Component (Loc, |
| 617 |
Prefix => New_Prefix, |
| 618 |
Expressions => New_List (Build_Val (Loc, Position))); |
| 619 |
end Build_Get_Prim_Op_Address; |
| 620 |
|
| 621 |
----------------------------- |
| 622 |
-- Build_Get_Transportable -- |
| 623 |
----------------------------- |
| 624 |
|
| 625 |
function Build_Get_Transportable |
| 626 |
(Loc : Source_Ptr; |
| 627 |
Tag_Node : Node_Id) return Node_Id |
| 628 |
is |
| 629 |
begin |
| 630 |
return |
| 631 |
Make_Selected_Component (Loc, |
| 632 |
Prefix => |
| 633 |
Make_Explicit_Dereference (Loc, |
| 634 |
Build_TSD (Loc, |
| 635 |
Unchecked_Convert_To (RTE (RE_Address), Tag_Node))), |
| 636 |
Selector_Name => |
| 637 |
New_Occurrence_Of |
| 638 |
(RTE_Record_Component (RE_Transportable), Loc)); |
| 639 |
end Build_Get_Transportable; |
| 640 |
|
| 641 |
------------------------------------ |
| 642 |
-- Build_Inherit_Predefined_Prims -- |
| 643 |
------------------------------------ |
| 644 |
|
| 645 |
function Build_Inherit_Predefined_Prims |
| 646 |
(Loc : Source_Ptr; |
| 647 |
Old_Tag_Node : Node_Id; |
| 648 |
New_Tag_Node : Node_Id; |
| 649 |
Num_Predef_Prims : Nat) return Node_Id |
| 650 |
is |
| 651 |
begin |
| 652 |
return |
| 653 |
Make_Assignment_Statement (Loc, |
| 654 |
Name => |
| 655 |
Make_Slice (Loc, |
| 656 |
Prefix => |
| 657 |
Make_Explicit_Dereference (Loc, |
| 658 |
Unchecked_Convert_To (RTE (RE_Predef_Prims_Table_Ptr), |
| 659 |
Make_Explicit_Dereference (Loc, |
| 660 |
Unchecked_Convert_To (RTE (RE_Addr_Ptr), |
| 661 |
New_Tag_Node)))), |
| 662 |
Discrete_Range => |
| 663 |
Build_Range (Loc, 1, Num_Predef_Prims)), |
| 664 |
|
| 665 |
Expression => |
| 666 |
Make_Slice (Loc, |
| 667 |
Prefix => |
| 668 |
Make_Explicit_Dereference (Loc, |
| 669 |
Unchecked_Convert_To (RTE (RE_Predef_Prims_Table_Ptr), |
| 670 |
Make_Explicit_Dereference (Loc, |
| 671 |
Unchecked_Convert_To (RTE (RE_Addr_Ptr), |
| 672 |
Old_Tag_Node)))), |
| 673 |
Discrete_Range => |
| 674 |
Build_Range (Loc, 1, Num_Predef_Prims))); |
| 675 |
end Build_Inherit_Predefined_Prims; |
| 676 |
|
| 677 |
------------------------- |
| 678 |
-- Build_Offset_To_Top -- |
| 679 |
------------------------- |
| 680 |
|
| 681 |
function Build_Offset_To_Top |
| 682 |
(Loc : Source_Ptr; |
| 683 |
This_Node : Node_Id) return Node_Id |
| 684 |
is |
| 685 |
Tag_Node : Node_Id; |
| 686 |
|
| 687 |
begin |
| 688 |
Tag_Node := |
| 689 |
Make_Explicit_Dereference (Loc, |
| 690 |
Unchecked_Convert_To (RTE (RE_Tag_Ptr), This_Node)); |
| 691 |
|
| 692 |
return |
| 693 |
Make_Explicit_Dereference (Loc, |
| 694 |
Unchecked_Convert_To (RTE (RE_Offset_To_Top_Ptr), |
| 695 |
Make_Function_Call (Loc, |
| 696 |
Name => |
| 697 |
Make_Expanded_Name (Loc, |
| 698 |
Chars => Name_Op_Subtract, |
| 699 |
Prefix => |
| 700 |
New_Occurrence_Of |
| 701 |
(RTU_Entity (System_Storage_Elements), Loc), |
| 702 |
Selector_Name => Make_Identifier (Loc, Name_Op_Subtract)), |
| 703 |
Parameter_Associations => New_List ( |
| 704 |
Unchecked_Convert_To (RTE (RE_Address), Tag_Node), |
| 705 |
New_Occurrence_Of |
| 706 |
(RTE (RE_DT_Offset_To_Top_Offset), Loc))))); |
| 707 |
end Build_Offset_To_Top; |
| 708 |
|
| 709 |
----------------- |
| 710 |
-- Build_Range -- |
| 711 |
----------------- |
| 712 |
|
| 713 |
function Build_Range (Loc : Source_Ptr; Lo, Hi : Nat) return Node_Id is |
| 714 |
Result : Node_Id; |
| 715 |
|
| 716 |
begin |
| 717 |
Result := |
| 718 |
Make_Range (Loc, |
| 719 |
Low_Bound => Build_Val (Loc, UI_From_Int (Lo)), |
| 720 |
High_Bound => Build_Val (Loc, UI_From_Int (Hi))); |
| 721 |
Set_Etype (Result, Standard_Natural); |
| 722 |
Set_Analyzed (Result); |
| 723 |
return Result; |
| 724 |
end Build_Range; |
| 725 |
|
| 726 |
------------------------------------------ |
| 727 |
-- Build_Set_Predefined_Prim_Op_Address -- |
| 728 |
------------------------------------------ |
| 729 |
|
| 730 |
function Build_Set_Predefined_Prim_Op_Address |
| 731 |
(Loc : Source_Ptr; |
| 732 |
Tag_Node : Node_Id; |
| 733 |
Position : Uint; |
| 734 |
Address_Node : Node_Id) return Node_Id |
| 735 |
is |
| 736 |
begin |
| 737 |
return |
| 738 |
Make_Assignment_Statement (Loc, |
| 739 |
Name => |
| 740 |
Make_Indexed_Component (Loc, |
| 741 |
Prefix => |
| 742 |
Unchecked_Convert_To (RTE (RE_Predef_Prims_Table_Ptr), |
| 743 |
Make_Explicit_Dereference (Loc, |
| 744 |
Unchecked_Convert_To (RTE (RE_Addr_Ptr), Tag_Node))), |
| 745 |
Expressions => |
| 746 |
New_List (Build_Val (Loc, Position))), |
| 747 |
|
| 748 |
Expression => Address_Node); |
| 749 |
end Build_Set_Predefined_Prim_Op_Address; |
| 750 |
|
| 751 |
------------------------------- |
| 752 |
-- Build_Set_Prim_Op_Address -- |
| 753 |
------------------------------- |
| 754 |
|
| 755 |
function Build_Set_Prim_Op_Address |
| 756 |
(Loc : Source_Ptr; |
| 757 |
Typ : Entity_Id; |
| 758 |
Tag_Node : Node_Id; |
| 759 |
Position : Uint; |
| 760 |
Address_Node : Node_Id) return Node_Id |
| 761 |
is |
| 762 |
Ctrl_Tag : Node_Id := Tag_Node; |
| 763 |
New_Node : Node_Id; |
| 764 |
|
| 765 |
begin |
| 766 |
Build_Get_Prim_Op_Address (Loc, Typ, Position, Ctrl_Tag, New_Node); |
| 767 |
|
| 768 |
return |
| 769 |
Make_Assignment_Statement (Loc, |
| 770 |
Name => New_Node, |
| 771 |
Expression => Address_Node); |
| 772 |
end Build_Set_Prim_Op_Address; |
| 773 |
|
| 774 |
----------------------------- |
| 775 |
-- Build_Set_Size_Function -- |
| 776 |
----------------------------- |
| 777 |
|
| 778 |
function Build_Set_Size_Function |
| 779 |
(Loc : Source_Ptr; |
| 780 |
Typ : Entity_Id; |
| 781 |
Size_Func : Entity_Id) return Node_Id |
| 782 |
is |
| 783 |
F_Nod : constant Node_Id := Freeze_Node (Typ); |
| 784 |
|
| 785 |
Act : Node_Id; |
| 786 |
|
| 787 |
begin |
| 788 |
pragma Assert (Chars (Size_Func) = Name_uSize |
| 789 |
and then RTE_Record_Component_Available (RE_Size_Func) |
| 790 |
and then Present (F_Nod)); |
| 791 |
|
| 792 |
-- Find the declaration of the TSD object in the freeze actions |
| 793 |
|
| 794 |
Act := First (Actions (F_Nod)); |
| 795 |
while Present (Act) loop |
| 796 |
if Nkind (Act) = N_Object_Declaration |
| 797 |
and then Nkind (Object_Definition (Act)) = N_Subtype_Indication |
| 798 |
and then Is_Entity_Name (Subtype_Mark (Object_Definition (Act))) |
| 799 |
and then Is_RTE (Entity (Subtype_Mark (Object_Definition (Act))), |
| 800 |
RE_Type_Specific_Data) |
| 801 |
then |
| 802 |
exit; |
| 803 |
end if; |
| 804 |
|
| 805 |
Next (Act); |
| 806 |
end loop; |
| 807 |
|
| 808 |
pragma Assert (Present (Act)); |
| 809 |
|
| 810 |
-- Generate: |
| 811 |
-- TSD.Size_Func := Size_Ptr!(Size_Func'Unrestricted_Access); |
| 812 |
|
| 813 |
return |
| 814 |
Make_Assignment_Statement (Loc, |
| 815 |
Name => |
| 816 |
Make_Selected_Component (Loc, |
| 817 |
Prefix => |
| 818 |
New_Occurrence_Of (Defining_Identifier (Act), Loc), |
| 819 |
Selector_Name => |
| 820 |
New_Occurrence_Of |
| 821 |
(RTE_Record_Component (RE_Size_Func), Loc)), |
| 822 |
Expression => |
| 823 |
Unchecked_Convert_To (RTE (RE_Size_Ptr), |
| 824 |
Make_Attribute_Reference (Loc, |
| 825 |
Prefix => New_Occurrence_Of (Size_Func, Loc), |
| 826 |
Attribute_Name => Name_Unrestricted_Access))); |
| 827 |
end Build_Set_Size_Function; |
| 828 |
|
| 829 |
------------------------------------ |
| 830 |
-- Build_Set_Static_Offset_To_Top -- |
| 831 |
------------------------------------ |
| 832 |
|
| 833 |
function Build_Set_Static_Offset_To_Top |
| 834 |
(Loc : Source_Ptr; |
| 835 |
Iface_Tag : Node_Id; |
| 836 |
Offset_Value : Node_Id) return Node_Id is |
| 837 |
begin |
| 838 |
return |
| 839 |
Make_Assignment_Statement (Loc, |
| 840 |
Make_Explicit_Dereference (Loc, |
| 841 |
Unchecked_Convert_To (RTE (RE_Offset_To_Top_Ptr), |
| 842 |
Make_Function_Call (Loc, |
| 843 |
Name => |
| 844 |
Make_Expanded_Name (Loc, |
| 845 |
Chars => Name_Op_Subtract, |
| 846 |
Prefix => |
| 847 |
New_Occurrence_Of |
| 848 |
(RTU_Entity (System_Storage_Elements), Loc), |
| 849 |
Selector_Name => Make_Identifier (Loc, Name_Op_Subtract)), |
| 850 |
Parameter_Associations => New_List ( |
| 851 |
Unchecked_Convert_To (RTE (RE_Address), Iface_Tag), |
| 852 |
New_Occurrence_Of |
| 853 |
(RTE (RE_DT_Offset_To_Top_Offset), Loc))))), |
| 854 |
Offset_Value); |
| 855 |
end Build_Set_Static_Offset_To_Top; |
| 856 |
|
| 857 |
--------------- |
| 858 |
-- Build_TSD -- |
| 859 |
--------------- |
| 860 |
|
| 861 |
function Build_TSD |
| 862 |
(Loc : Source_Ptr; |
| 863 |
Tag_Node_Addr : Node_Id) return Node_Id is |
| 864 |
begin |
| 865 |
return |
| 866 |
Unchecked_Convert_To (RTE (RE_Type_Specific_Data_Ptr), |
| 867 |
Make_Explicit_Dereference (Loc, |
| 868 |
Prefix => Unchecked_Convert_To (RTE (RE_Addr_Ptr), |
| 869 |
Make_Function_Call (Loc, |
| 870 |
Name => |
| 871 |
Make_Expanded_Name (Loc, |
| 872 |
Chars => Name_Op_Subtract, |
| 873 |
Prefix => |
| 874 |
New_Occurrence_Of |
| 875 |
(RTU_Entity (System_Storage_Elements), Loc), |
| 876 |
Selector_Name => Make_Identifier (Loc, Name_Op_Subtract)), |
| 877 |
|
| 878 |
Parameter_Associations => New_List ( |
| 879 |
Tag_Node_Addr, |
| 880 |
New_Occurrence_Of |
| 881 |
(RTE (RE_DT_Typeinfo_Ptr_Size), Loc)))))); |
| 882 |
end Build_TSD; |
| 883 |
|
| 884 |
--------------- |
| 885 |
-- Build_Val -- |
| 886 |
--------------- |
| 887 |
|
| 888 |
function Build_Val (Loc : Source_Ptr; V : Uint) return Node_Id is |
| 889 |
Result : Node_Id; |
| 890 |
|
| 891 |
begin |
| 892 |
Result := Make_Integer_Literal (Loc, V); |
| 893 |
Set_Etype (Result, Standard_Natural); |
| 894 |
Set_Is_Static_Expression (Result); |
| 895 |
Set_Analyzed (Result); |
| 896 |
return Result; |
| 897 |
end Build_Val; |
| 898 |
|
| 899 |
end Exp_Atag; |