| 1 |
------------------------------------------------------------------------------ |
| 2 |
-- -- |
| 3 |
-- GNAT COMPILER COMPONENTS -- |
| 4 |
-- -- |
| 5 |
-- S E M _ D I S T -- |
| 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 Atree; use Atree; |
| 27 |
with Casing; use Casing; |
| 28 |
with Einfo; use Einfo; |
| 29 |
with Einfo.Entities; use Einfo.Entities; |
| 30 |
with Einfo.Utils; use Einfo.Utils; |
| 31 |
with Errout; use Errout; |
| 32 |
with Exp_Dist; use Exp_Dist; |
| 33 |
with Exp_Tss; use Exp_Tss; |
| 34 |
with Nlists; use Nlists; |
| 35 |
with Nmake; use Nmake; |
| 36 |
with Namet; use Namet; |
| 37 |
with Opt; use Opt; |
| 38 |
with Rtsfind; use Rtsfind; |
| 39 |
with Sem; use Sem; |
| 40 |
with Sem_Aux; use Sem_Aux; |
| 41 |
with Sem_Disp; use Sem_Disp; |
| 42 |
with Sem_Eval; use Sem_Eval; |
| 43 |
with Sem_Res; use Sem_Res; |
| 44 |
with Sem_Util; use Sem_Util; |
| 45 |
with Sinfo; use Sinfo; |
| 46 |
with Sinfo.Nodes; use Sinfo.Nodes; |
| 47 |
with Sinfo.Utils; use Sinfo.Utils; |
| 48 |
with Stand; use Stand; |
| 49 |
with Stringt; use Stringt; |
| 50 |
with Tbuild; use Tbuild; |
| 51 |
with Uintp; use Uintp; |
| 52 |
|
| 53 |
package body Sem_Dist is |
| 54 |
|
| 55 |
----------------------- |
| 56 |
-- Local Subprograms -- |
| 57 |
----------------------- |
| 58 |
|
| 59 |
procedure RAS_E_Dereference (Pref : Node_Id); |
| 60 |
-- Handles explicit dereference of Remote Access to Subprograms |
| 61 |
|
| 62 |
function Full_Qualified_Name (E : Entity_Id) return String_Id; |
| 63 |
-- returns the full qualified name of the entity in lower case |
| 64 |
|
| 65 |
------------------------- |
| 66 |
-- Add_Stub_Constructs -- |
| 67 |
------------------------- |
| 68 |
|
| 69 |
procedure Add_Stub_Constructs (N : Node_Id) is |
| 70 |
U : constant Node_Id := Unit (N); |
| 71 |
Spec : Entity_Id := Empty; |
| 72 |
|
| 73 |
Exp : Node_Id := U; |
| 74 |
-- Unit that will be expanded |
| 75 |
|
| 76 |
begin |
| 77 |
pragma Assert (Distribution_Stub_Mode /= No_Stubs); |
| 78 |
|
| 79 |
if Nkind (U) = N_Package_Declaration then |
| 80 |
Spec := Defining_Entity (Specification (U)); |
| 81 |
|
| 82 |
elsif Nkind (U) = N_Package_Body then |
| 83 |
Spec := Corresponding_Spec (U); |
| 84 |
|
| 85 |
else pragma Assert (Nkind (U) = N_Package_Instantiation); |
| 86 |
Exp := Instance_Spec (U); |
| 87 |
Spec := Defining_Entity (Specification (Exp)); |
| 88 |
end if; |
| 89 |
|
| 90 |
pragma Assert (Is_Shared_Passive (Spec) |
| 91 |
or else Is_Remote_Call_Interface (Spec)); |
| 92 |
|
| 93 |
if Distribution_Stub_Mode = Generate_Caller_Stub_Body then |
| 94 |
if Is_Shared_Passive (Spec) then |
| 95 |
null; |
| 96 |
elsif Nkind (U) = N_Package_Body then |
| 97 |
Error_Msg_N |
| 98 |
("Specification file expected from command line", U); |
| 99 |
else |
| 100 |
Expand_Calling_Stubs_Bodies (Exp); |
| 101 |
end if; |
| 102 |
|
| 103 |
else |
| 104 |
if Is_Shared_Passive (Spec) then |
| 105 |
Build_Passive_Partition_Stub (Exp); |
| 106 |
else |
| 107 |
Expand_Receiving_Stubs_Bodies (Exp); |
| 108 |
end if; |
| 109 |
|
| 110 |
end if; |
| 111 |
end Add_Stub_Constructs; |
| 112 |
|
| 113 |
--------------------------------------- |
| 114 |
-- Build_RAS_Primitive_Specification -- |
| 115 |
--------------------------------------- |
| 116 |
|
| 117 |
function Build_RAS_Primitive_Specification |
| 118 |
(Subp_Spec : Node_Id; |
| 119 |
Remote_Object_Type : Node_Id) return Node_Id |
| 120 |
is |
| 121 |
Loc : constant Source_Ptr := Sloc (Subp_Spec); |
| 122 |
|
| 123 |
Primitive_Spec : constant Node_Id := |
| 124 |
Copy_Specification (Loc, |
| 125 |
Spec => Subp_Spec, |
| 126 |
New_Name => Name_uCall); |
| 127 |
|
| 128 |
Subtype_Mark_For_Self : Node_Id; |
| 129 |
|
| 130 |
begin |
| 131 |
if No (Parameter_Specifications (Primitive_Spec)) then |
| 132 |
Set_Parameter_Specifications (Primitive_Spec, New_List); |
| 133 |
end if; |
| 134 |
|
| 135 |
if Nkind (Remote_Object_Type) in N_Entity then |
| 136 |
Subtype_Mark_For_Self := |
| 137 |
New_Occurrence_Of (Remote_Object_Type, Loc); |
| 138 |
else |
| 139 |
Subtype_Mark_For_Self := Remote_Object_Type; |
| 140 |
end if; |
| 141 |
|
| 142 |
Prepend_To ( |
| 143 |
Parameter_Specifications (Primitive_Spec), |
| 144 |
Make_Parameter_Specification (Loc, |
| 145 |
Defining_Identifier => |
| 146 |
Make_Defining_Identifier (Loc, Name_uS), |
| 147 |
Parameter_Type => |
| 148 |
Make_Access_Definition (Loc, |
| 149 |
Subtype_Mark => |
| 150 |
Subtype_Mark_For_Self))); |
| 151 |
|
| 152 |
-- Trick later semantic analysis into considering this operation as a |
| 153 |
-- primitive (dispatching) operation of tagged type Obj_Type. |
| 154 |
|
| 155 |
Set_Comes_From_Source ( |
| 156 |
Defining_Unit_Name (Primitive_Spec), True); |
| 157 |
|
| 158 |
return Primitive_Spec; |
| 159 |
end Build_RAS_Primitive_Specification; |
| 160 |
|
| 161 |
------------------------- |
| 162 |
-- Full_Qualified_Name -- |
| 163 |
------------------------- |
| 164 |
|
| 165 |
function Full_Qualified_Name (E : Entity_Id) return String_Id is |
| 166 |
Ent : Entity_Id := E; |
| 167 |
Parent_Name : String_Id := No_String; |
| 168 |
|
| 169 |
begin |
| 170 |
-- Deals properly with child units |
| 171 |
|
| 172 |
if Nkind (Ent) = N_Defining_Program_Unit_Name then |
| 173 |
Ent := Defining_Identifier (Ent); |
| 174 |
end if; |
| 175 |
|
| 176 |
-- Compute recursively the qualification (only "Standard" has no scope) |
| 177 |
|
| 178 |
if Present (Scope (Scope (Ent))) then |
| 179 |
Parent_Name := Full_Qualified_Name (Scope (Ent)); |
| 180 |
end if; |
| 181 |
|
| 182 |
-- Every entity should have a name except some expanded blocks. Do not |
| 183 |
-- bother about those. |
| 184 |
|
| 185 |
if Chars (Ent) = No_Name then |
| 186 |
return Parent_Name; |
| 187 |
end if; |
| 188 |
|
| 189 |
-- Add a period between Name and qualification |
| 190 |
|
| 191 |
if Parent_Name /= No_String then |
| 192 |
Start_String (Parent_Name); |
| 193 |
Store_String_Char (Get_Char_Code ('.')); |
| 194 |
else |
| 195 |
Start_String; |
| 196 |
end if; |
| 197 |
|
| 198 |
-- Generates the entity name in upper case |
| 199 |
|
| 200 |
Get_Name_String (Chars (Ent)); |
| 201 |
Set_Casing (All_Lower_Case); |
| 202 |
Store_String_Chars (Name_Buffer (1 .. Name_Len)); |
| 203 |
return End_String; |
| 204 |
end Full_Qualified_Name; |
| 205 |
|
| 206 |
------------------ |
| 207 |
-- Get_PCS_Name -- |
| 208 |
------------------ |
| 209 |
|
| 210 |
function Get_PCS_Name return PCS_Names is |
| 211 |
begin |
| 212 |
return |
| 213 |
Chars (Entity (Expression (Parent (RTE (RE_DSA_Implementation))))); |
| 214 |
end Get_PCS_Name; |
| 215 |
|
| 216 |
--------------------- |
| 217 |
-- Get_PCS_Version -- |
| 218 |
--------------------- |
| 219 |
|
| 220 |
function Get_PCS_Version return Int is |
| 221 |
PCS_Version_Entity : Entity_Id; |
| 222 |
PCS_Version : Int; |
| 223 |
|
| 224 |
begin |
| 225 |
if RTE_Available (RE_PCS_Version) then |
| 226 |
PCS_Version_Entity := RTE (RE_PCS_Version); |
| 227 |
pragma Assert (Ekind (PCS_Version_Entity) = E_Named_Integer); |
| 228 |
PCS_Version := |
| 229 |
UI_To_Int (Expr_Value (Constant_Value (PCS_Version_Entity))); |
| 230 |
|
| 231 |
else |
| 232 |
-- Case of System.Partition_Interface.PCS_Version not found: |
| 233 |
-- return a null version. |
| 234 |
|
| 235 |
PCS_Version := 0; |
| 236 |
end if; |
| 237 |
|
| 238 |
return PCS_Version; |
| 239 |
end Get_PCS_Version; |
| 240 |
|
| 241 |
------------------------ |
| 242 |
-- Is_All_Remote_Call -- |
| 243 |
------------------------ |
| 244 |
|
| 245 |
function Is_All_Remote_Call (N : Node_Id) return Boolean is |
| 246 |
Par : Node_Id; |
| 247 |
|
| 248 |
begin |
| 249 |
if Nkind (N) in N_Subprogram_Call |
| 250 |
and then Nkind (Name (N)) in N_Has_Entity |
| 251 |
and then Is_Remote_Call_Interface (Entity (Name (N))) |
| 252 |
and then Has_All_Calls_Remote (Scope (Entity (Name (N)))) |
| 253 |
and then Comes_From_Source (N) |
| 254 |
then |
| 255 |
Par := Parent (Entity (Name (N))); |
| 256 |
while Present (Par) |
| 257 |
and then (Nkind (Par) /= N_Package_Specification |
| 258 |
or else Is_Wrapper_Package (Defining_Entity (Par))) |
| 259 |
loop |
| 260 |
Par := Parent (Par); |
| 261 |
end loop; |
| 262 |
|
| 263 |
if Present (Par) then |
| 264 |
return |
| 265 |
not Scope_Within_Or_Same (Current_Scope, Defining_Entity (Par)); |
| 266 |
else |
| 267 |
return False; |
| 268 |
end if; |
| 269 |
else |
| 270 |
return False; |
| 271 |
end if; |
| 272 |
end Is_All_Remote_Call; |
| 273 |
|
| 274 |
--------------------------------- |
| 275 |
-- Is_RACW_Stub_Type_Operation -- |
| 276 |
--------------------------------- |
| 277 |
|
| 278 |
function Is_RACW_Stub_Type_Operation (Op : Entity_Id) return Boolean is |
| 279 |
Typ : Entity_Id; |
| 280 |
|
| 281 |
begin |
| 282 |
case Ekind (Op) is |
| 283 |
when E_Function |
| 284 |
| E_Procedure |
| 285 |
=> |
| 286 |
Typ := Find_Dispatching_Type (Op); |
| 287 |
|
| 288 |
return |
| 289 |
Present (Typ) |
| 290 |
and then Is_RACW_Stub_Type (Typ) |
| 291 |
and then not Is_Internal (Op); |
| 292 |
|
| 293 |
when others => |
| 294 |
return False; |
| 295 |
end case; |
| 296 |
end Is_RACW_Stub_Type_Operation; |
| 297 |
|
| 298 |
--------------------------------- |
| 299 |
-- Is_Valid_Remote_Object_Type -- |
| 300 |
--------------------------------- |
| 301 |
|
| 302 |
function Is_Valid_Remote_Object_Type (E : Entity_Id) return Boolean is |
| 303 |
P : constant Node_Id := Parent (E); |
| 304 |
|
| 305 |
begin |
| 306 |
pragma Assert (Is_Tagged_Type (E)); |
| 307 |
|
| 308 |
-- Simple case: a limited private type |
| 309 |
|
| 310 |
if Nkind (P) = N_Private_Type_Declaration |
| 311 |
and then Is_Limited_Record (E) |
| 312 |
then |
| 313 |
return True; |
| 314 |
|
| 315 |
-- AI05-0060 (Binding Interpretation): A limited interface is a legal |
| 316 |
-- ancestor for the designated type of an RACW type. |
| 317 |
|
| 318 |
elsif Is_Limited_Record (E) and then Is_Limited_Interface (E) then |
| 319 |
return True; |
| 320 |
|
| 321 |
-- A generic tagged limited type is a valid candidate. Limitedness will |
| 322 |
-- be checked again on the actual at instantiation point. |
| 323 |
|
| 324 |
elsif Nkind (P) = N_Formal_Type_Declaration |
| 325 |
and then Ekind (E) = E_Record_Type_With_Private |
| 326 |
and then Is_Generic_Type (E) |
| 327 |
and then Is_Limited_Record (E) |
| 328 |
then |
| 329 |
return True; |
| 330 |
|
| 331 |
-- A private extension declaration is a valid candidate if its parent |
| 332 |
-- type is. |
| 333 |
|
| 334 |
elsif Nkind (P) = N_Private_Extension_Declaration then |
| 335 |
return Is_Valid_Remote_Object_Type (Etype (E)); |
| 336 |
|
| 337 |
else |
| 338 |
return False; |
| 339 |
end if; |
| 340 |
end Is_Valid_Remote_Object_Type; |
| 341 |
|
| 342 |
------------------------------------ |
| 343 |
-- Package_Specification_Of_Scope -- |
| 344 |
------------------------------------ |
| 345 |
|
| 346 |
function Package_Specification_Of_Scope (E : Entity_Id) return Node_Id is |
| 347 |
N : Node_Id; |
| 348 |
|
| 349 |
begin |
| 350 |
N := Parent (E); |
| 351 |
while Nkind (N) /= N_Package_Specification loop |
| 352 |
N := Parent (N); |
| 353 |
end loop; |
| 354 |
|
| 355 |
return N; |
| 356 |
end Package_Specification_Of_Scope; |
| 357 |
|
| 358 |
-------------------------- |
| 359 |
-- Process_Partition_Id -- |
| 360 |
-------------------------- |
| 361 |
|
| 362 |
procedure Process_Partition_Id (N : Node_Id) is |
| 363 |
Loc : constant Source_Ptr := Sloc (N); |
| 364 |
Ety : Entity_Id; |
| 365 |
Get_Pt_Id : Node_Id; |
| 366 |
Get_Pt_Id_Call : Node_Id; |
| 367 |
Prefix_String : String_Id; |
| 368 |
Typ : constant Entity_Id := Etype (N); |
| 369 |
|
| 370 |
begin |
| 371 |
-- In case prefix is not a library unit entity, get the entity |
| 372 |
-- of library unit. |
| 373 |
|
| 374 |
Ety := Entity (Prefix (N)); |
| 375 |
while (Present (Scope (Ety)) |
| 376 |
and then Scope (Ety) /= Standard_Standard) |
| 377 |
and not Is_Child_Unit (Ety) |
| 378 |
loop |
| 379 |
Ety := Scope (Ety); |
| 380 |
end loop; |
| 381 |
|
| 382 |
-- Retrieve the proper function to call |
| 383 |
|
| 384 |
if Is_Remote_Call_Interface (Ety) then |
| 385 |
Get_Pt_Id := New_Occurrence_Of |
| 386 |
(RTE (RE_Get_Active_Partition_Id), Loc); |
| 387 |
|
| 388 |
elsif Is_Shared_Passive (Ety) then |
| 389 |
Get_Pt_Id := New_Occurrence_Of |
| 390 |
(RTE (RE_Get_Passive_Partition_Id), Loc); |
| 391 |
|
| 392 |
else |
| 393 |
Get_Pt_Id := New_Occurrence_Of |
| 394 |
(RTE (RE_Get_Local_Partition_Id), Loc); |
| 395 |
end if; |
| 396 |
|
| 397 |
-- Get the String_Id corresponding to the name of the library unit whose |
| 398 |
-- Partition_Id is needed. |
| 399 |
|
| 400 |
Prefix_String := Get_Library_Unit_Name (Unit_Declaration_Node (Ety)); |
| 401 |
|
| 402 |
-- Build the function call which will replace the attribute |
| 403 |
|
| 404 |
if Is_Remote_Call_Interface (Ety) or else Is_Shared_Passive (Ety) then |
| 405 |
Get_Pt_Id_Call := |
| 406 |
Make_Function_Call (Loc, |
| 407 |
Name => Get_Pt_Id, |
| 408 |
Parameter_Associations => |
| 409 |
New_List (Make_String_Literal (Loc, Prefix_String))); |
| 410 |
|
| 411 |
else |
| 412 |
Get_Pt_Id_Call := Make_Function_Call (Loc, Get_Pt_Id); |
| 413 |
end if; |
| 414 |
|
| 415 |
-- Replace the attribute node by a conversion of the function call |
| 416 |
-- to the target type. |
| 417 |
|
| 418 |
Rewrite (N, Convert_To (Typ, Get_Pt_Id_Call)); |
| 419 |
Analyze_And_Resolve (N, Typ); |
| 420 |
end Process_Partition_Id; |
| 421 |
|
| 422 |
---------------------------------- |
| 423 |
-- Process_Remote_AST_Attribute -- |
| 424 |
---------------------------------- |
| 425 |
|
| 426 |
procedure Process_Remote_AST_Attribute |
| 427 |
(N : Node_Id; |
| 428 |
New_Type : Entity_Id) |
| 429 |
is |
| 430 |
Loc : constant Source_Ptr := Sloc (N); |
| 431 |
Remote_Subp : Entity_Id; |
| 432 |
Tick_Access_Conv_Call : Node_Id; |
| 433 |
Remote_Subp_Decl : Node_Id; |
| 434 |
RS_Pkg_Specif : Node_Id; |
| 435 |
RS_Pkg_E : Entity_Id; |
| 436 |
RAS_Type : Entity_Id := New_Type; |
| 437 |
Async_E : Entity_Id; |
| 438 |
All_Calls_Remote_E : Entity_Id; |
| 439 |
Attribute_Subp : Entity_Id; |
| 440 |
|
| 441 |
begin |
| 442 |
-- Check if we have to expand the access attribute |
| 443 |
|
| 444 |
Remote_Subp := Entity (Prefix (N)); |
| 445 |
|
| 446 |
if not Expander_Active or else Get_PCS_Name = Name_No_DSA then |
| 447 |
return; |
| 448 |
end if; |
| 449 |
|
| 450 |
if Ekind (RAS_Type) /= E_Record_Type then |
| 451 |
RAS_Type := Equivalent_Type (RAS_Type); |
| 452 |
end if; |
| 453 |
|
| 454 |
Attribute_Subp := TSS (RAS_Type, TSS_RAS_Access); |
| 455 |
pragma Assert (Present (Attribute_Subp)); |
| 456 |
Remote_Subp_Decl := Unit_Declaration_Node (Remote_Subp); |
| 457 |
|
| 458 |
if Nkind (Remote_Subp_Decl) = N_Subprogram_Body then |
| 459 |
Remote_Subp := Corresponding_Spec (Remote_Subp_Decl); |
| 460 |
Remote_Subp_Decl := Unit_Declaration_Node (Remote_Subp); |
| 461 |
end if; |
| 462 |
|
| 463 |
RS_Pkg_Specif := Parent (Remote_Subp_Decl); |
| 464 |
RS_Pkg_E := Defining_Entity (RS_Pkg_Specif); |
| 465 |
|
| 466 |
Async_E := |
| 467 |
Boolean_Literals (Ekind (Remote_Subp) = E_Procedure |
| 468 |
and then Is_Asynchronous (Remote_Subp)); |
| 469 |
|
| 470 |
All_Calls_Remote_E := |
| 471 |
Boolean_Literals (Has_All_Calls_Remote (RS_Pkg_E)); |
| 472 |
|
| 473 |
Tick_Access_Conv_Call := |
| 474 |
Make_Function_Call (Loc, |
| 475 |
Name => New_Occurrence_Of (Attribute_Subp, Loc), |
| 476 |
Parameter_Associations => |
| 477 |
New_List ( |
| 478 |
Make_String_Literal (Loc, |
| 479 |
Strval => Full_Qualified_Name (RS_Pkg_E)), |
| 480 |
Build_Subprogram_Id (Loc, Remote_Subp), |
| 481 |
New_Occurrence_Of (Async_E, Loc), |
| 482 |
New_Occurrence_Of (All_Calls_Remote_E, Loc))); |
| 483 |
|
| 484 |
Rewrite (N, Tick_Access_Conv_Call); |
| 485 |
Analyze_And_Resolve (N, RAS_Type); |
| 486 |
end Process_Remote_AST_Attribute; |
| 487 |
|
| 488 |
------------------------------------ |
| 489 |
-- Process_Remote_AST_Declaration -- |
| 490 |
------------------------------------ |
| 491 |
|
| 492 |
procedure Process_Remote_AST_Declaration (N : Node_Id) is |
| 493 |
Loc : constant Source_Ptr := Sloc (N); |
| 494 |
User_Type : constant Node_Id := Defining_Identifier (N); |
| 495 |
Scop : constant Entity_Id := Scope (User_Type); |
| 496 |
Is_RCI : constant Boolean := Is_Remote_Call_Interface (Scop); |
| 497 |
Is_RT : constant Boolean := Is_Remote_Types (Scop); |
| 498 |
Type_Def : constant Node_Id := Type_Definition (N); |
| 499 |
Parameter : Node_Id; |
| 500 |
|
| 501 |
Is_Degenerate : Boolean; |
| 502 |
-- True iff this RAS has an access formal parameter (see |
| 503 |
-- Exp_Dist.Add_RAS_Dereference_TSS for details). |
| 504 |
|
| 505 |
Subpkg : constant Entity_Id := Make_Temporary (Loc, 'S'); |
| 506 |
Subpkg_Decl : Node_Id; |
| 507 |
Subpkg_Body : Node_Id; |
| 508 |
Vis_Decls : constant List_Id := New_List; |
| 509 |
Priv_Decls : constant List_Id := New_List; |
| 510 |
|
| 511 |
Obj_Type : constant Entity_Id := |
| 512 |
Make_Defining_Identifier (Loc, |
| 513 |
New_External_Name (Chars (User_Type), 'R')); |
| 514 |
|
| 515 |
Full_Obj_Type : constant Entity_Id := |
| 516 |
Make_Defining_Identifier (Loc, Chars (Obj_Type)); |
| 517 |
|
| 518 |
RACW_Type : constant Entity_Id := |
| 519 |
Make_Defining_Identifier (Loc, |
| 520 |
New_External_Name (Chars (User_Type), 'P')); |
| 521 |
|
| 522 |
Fat_Type : constant Entity_Id := |
| 523 |
Make_Defining_Identifier (Loc, Chars (User_Type)); |
| 524 |
|
| 525 |
Fat_Type_Decl : Node_Id; |
| 526 |
|
| 527 |
begin |
| 528 |
Is_Degenerate := False; |
| 529 |
Parameter := First (Parameter_Specifications (Type_Def)); |
| 530 |
while Present (Parameter) loop |
| 531 |
if Nkind (Parameter_Type (Parameter)) = N_Access_Definition then |
| 532 |
Error_Msg_N |
| 533 |
("formal parameter& has anonymous access type??", |
| 534 |
Defining_Identifier (Parameter)); |
| 535 |
Is_Degenerate := True; |
| 536 |
exit; |
| 537 |
end if; |
| 538 |
|
| 539 |
Next (Parameter); |
| 540 |
end loop; |
| 541 |
|
| 542 |
if Is_Degenerate then |
| 543 |
Error_Msg_NE |
| 544 |
("remote access-to-subprogram type& can only be null??", |
| 545 |
Defining_Identifier (Parameter), User_Type); |
| 546 |
|
| 547 |
-- The only legal value for a RAS with a formal parameter of an |
| 548 |
-- anonymous access type is null, because it cannot be subtype- |
| 549 |
-- conformant with any legal remote subprogram declaration. In this |
| 550 |
-- case, we cannot generate a corresponding primitive operation. |
| 551 |
|
| 552 |
end if; |
| 553 |
|
| 554 |
if Get_PCS_Name = Name_No_DSA then |
| 555 |
return; |
| 556 |
end if; |
| 557 |
|
| 558 |
-- The tagged private type, primitive operation and RACW type associated |
| 559 |
-- with a RAS need to all be declared in a subpackage of the one that |
| 560 |
-- contains the RAS declaration, because the primitive of the object |
| 561 |
-- type, and the associated primitive of the stub type, need to be |
| 562 |
-- dispatching operations of these types, and the profile of the RAS |
| 563 |
-- might contain tagged types declared in the same scope. |
| 564 |
|
| 565 |
Append_To (Vis_Decls, |
| 566 |
Make_Private_Type_Declaration (Loc, |
| 567 |
Defining_Identifier => Obj_Type, |
| 568 |
Abstract_Present => True, |
| 569 |
Tagged_Present => True, |
| 570 |
Limited_Present => True)); |
| 571 |
|
| 572 |
Append_To (Priv_Decls, |
| 573 |
Make_Full_Type_Declaration (Loc, |
| 574 |
Defining_Identifier => Full_Obj_Type, |
| 575 |
Type_Definition => |
| 576 |
Make_Record_Definition (Loc, |
| 577 |
Abstract_Present => True, |
| 578 |
Tagged_Present => True, |
| 579 |
Limited_Present => True, |
| 580 |
Null_Present => True, |
| 581 |
Component_List => Empty))); |
| 582 |
|
| 583 |
-- Trick semantic analysis into swapping the public and full view when |
| 584 |
-- freezing the public view. |
| 585 |
|
| 586 |
Set_Comes_From_Source (Full_Obj_Type, True); |
| 587 |
|
| 588 |
if not Is_Degenerate then |
| 589 |
Append_To (Vis_Decls, |
| 590 |
Make_Abstract_Subprogram_Declaration (Loc, |
| 591 |
Specification => Build_RAS_Primitive_Specification ( |
| 592 |
Subp_Spec => Type_Def, |
| 593 |
Remote_Object_Type => Obj_Type))); |
| 594 |
end if; |
| 595 |
|
| 596 |
Append_To (Vis_Decls, |
| 597 |
Make_Full_Type_Declaration (Loc, |
| 598 |
Defining_Identifier => RACW_Type, |
| 599 |
Type_Definition => |
| 600 |
Make_Access_To_Object_Definition (Loc, |
| 601 |
All_Present => True, |
| 602 |
Subtype_Indication => |
| 603 |
Make_Attribute_Reference (Loc, |
| 604 |
Prefix => New_Occurrence_Of (Obj_Type, Loc), |
| 605 |
Attribute_Name => Name_Class)))); |
| 606 |
|
| 607 |
Set_Is_Remote_Call_Interface (RACW_Type, Is_RCI); |
| 608 |
Set_Is_Remote_Types (RACW_Type, Is_RT); |
| 609 |
|
| 610 |
Subpkg_Decl := |
| 611 |
Make_Package_Declaration (Loc, |
| 612 |
Make_Package_Specification (Loc, |
| 613 |
Defining_Unit_Name => Subpkg, |
| 614 |
Visible_Declarations => Vis_Decls, |
| 615 |
Private_Declarations => Priv_Decls, |
| 616 |
End_Label => New_Occurrence_Of (Subpkg, Loc))); |
| 617 |
|
| 618 |
Set_Is_Remote_Call_Interface (Subpkg, Is_RCI); |
| 619 |
Set_Is_Remote_Types (Subpkg, Is_RT); |
| 620 |
Insert_After_And_Analyze (N, Subpkg_Decl); |
| 621 |
|
| 622 |
-- Generate package body to receive RACW calling stubs |
| 623 |
|
| 624 |
-- Note: Analyze_Declarations has an absolute requirement that the |
| 625 |
-- declaration list be non-empty, so provide dummy null statement here. |
| 626 |
|
| 627 |
Subpkg_Body := |
| 628 |
Make_Package_Body (Loc, |
| 629 |
Defining_Unit_Name => Make_Defining_Identifier (Loc, Chars (Subpkg)), |
| 630 |
Declarations => New_List (Make_Null_Statement (Loc))); |
| 631 |
Insert_After_And_Analyze (Subpkg_Decl, Subpkg_Body); |
| 632 |
|
| 633 |
-- Many parts of the analyzer and expander expect |
| 634 |
-- that the fat pointer type used to implement remote |
| 635 |
-- access to subprogram types be a record. |
| 636 |
-- Note: The structure of this type must be kept consistent |
| 637 |
-- with the code generated by Remote_AST_Null_Value for the |
| 638 |
-- corresponding 'null' expression. |
| 639 |
|
| 640 |
Fat_Type_Decl := Make_Full_Type_Declaration (Loc, |
| 641 |
Defining_Identifier => Fat_Type, |
| 642 |
Type_Definition => |
| 643 |
Make_Record_Definition (Loc, |
| 644 |
Component_List => |
| 645 |
Make_Component_List (Loc, |
| 646 |
Component_Items => New_List ( |
| 647 |
Make_Component_Declaration (Loc, |
| 648 |
Defining_Identifier => |
| 649 |
Make_Defining_Identifier (Loc, Name_Ras), |
| 650 |
Component_Definition => |
| 651 |
Make_Component_Definition (Loc, |
| 652 |
Subtype_Indication => |
| 653 |
New_Occurrence_Of (RACW_Type, Loc))))))); |
| 654 |
|
| 655 |
Set_Equivalent_Type (User_Type, Fat_Type); |
| 656 |
|
| 657 |
-- Set Fat_Type's Etype early so that we can use its |
| 658 |
-- Corresponding_Remote_Type attribute, whose presence indicates that |
| 659 |
-- this is the record type used to implement a RAS. |
| 660 |
|
| 661 |
Mutate_Ekind (Fat_Type, E_Record_Type); |
| 662 |
Set_Corresponding_Remote_Type (Fat_Type, User_Type); |
| 663 |
|
| 664 |
Insert_After_And_Analyze (Subpkg_Body, Fat_Type_Decl); |
| 665 |
|
| 666 |
-- The reason we suppress the initialization procedure is that we know |
| 667 |
-- that no initialization is required (even if Initialize_Scalars mode |
| 668 |
-- is active), and there are order of elaboration problems if we do try |
| 669 |
-- to generate an init proc for this created record type. |
| 670 |
|
| 671 |
Set_Suppress_Initialization (Fat_Type); |
| 672 |
|
| 673 |
if Expander_Active then |
| 674 |
Add_RAST_Features (Parent (User_Type)); |
| 675 |
end if; |
| 676 |
end Process_Remote_AST_Declaration; |
| 677 |
|
| 678 |
----------------------- |
| 679 |
-- RAS_E_Dereference -- |
| 680 |
----------------------- |
| 681 |
|
| 682 |
procedure RAS_E_Dereference (Pref : Node_Id) is |
| 683 |
Loc : constant Source_Ptr := Sloc (Pref); |
| 684 |
Call_Node : Node_Id; |
| 685 |
New_Type : constant Entity_Id := Etype (Pref); |
| 686 |
Explicit_Deref : constant Node_Id := Parent (Pref); |
| 687 |
Deref_Subp_Call : constant Node_Id := Parent (Explicit_Deref); |
| 688 |
Deref_Proc : Entity_Id; |
| 689 |
Params : List_Id; |
| 690 |
|
| 691 |
begin |
| 692 |
if Nkind (Deref_Subp_Call) = N_Procedure_Call_Statement then |
| 693 |
Params := Parameter_Associations (Deref_Subp_Call); |
| 694 |
|
| 695 |
if Present (Params) then |
| 696 |
Prepend (Pref, Params); |
| 697 |
else |
| 698 |
Params := New_List (Pref); |
| 699 |
end if; |
| 700 |
|
| 701 |
elsif Nkind (Deref_Subp_Call) = N_Indexed_Component then |
| 702 |
Params := Expressions (Deref_Subp_Call); |
| 703 |
|
| 704 |
if Present (Params) then |
| 705 |
Prepend (Pref, Params); |
| 706 |
else |
| 707 |
Params := New_List (Pref); |
| 708 |
end if; |
| 709 |
|
| 710 |
else |
| 711 |
-- Context is not a call |
| 712 |
|
| 713 |
return; |
| 714 |
end if; |
| 715 |
|
| 716 |
if not Expander_Active or else Get_PCS_Name = Name_No_DSA then |
| 717 |
return; |
| 718 |
end if; |
| 719 |
|
| 720 |
Deref_Proc := TSS (New_Type, TSS_RAS_Dereference); |
| 721 |
pragma Assert (Present (Deref_Proc)); |
| 722 |
|
| 723 |
if Ekind (Deref_Proc) = E_Function then |
| 724 |
Call_Node := |
| 725 |
Make_Function_Call (Loc, |
| 726 |
Name => New_Occurrence_Of (Deref_Proc, Loc), |
| 727 |
Parameter_Associations => Params); |
| 728 |
else |
| 729 |
Call_Node := |
| 730 |
Make_Procedure_Call_Statement (Loc, |
| 731 |
Name => New_Occurrence_Of (Deref_Proc, Loc), |
| 732 |
Parameter_Associations => Params); |
| 733 |
end if; |
| 734 |
|
| 735 |
Rewrite (Deref_Subp_Call, Call_Node); |
| 736 |
Analyze (Deref_Subp_Call); |
| 737 |
end RAS_E_Dereference; |
| 738 |
|
| 739 |
------------------------------ |
| 740 |
-- Remote_AST_E_Dereference -- |
| 741 |
------------------------------ |
| 742 |
|
| 743 |
function Remote_AST_E_Dereference (P : Node_Id) return Boolean is |
| 744 |
ET : constant Entity_Id := Etype (P); |
| 745 |
|
| 746 |
begin |
| 747 |
-- Perform the changes only on original dereferences, and only if |
| 748 |
-- we are generating code. |
| 749 |
|
| 750 |
if Comes_From_Source (P) |
| 751 |
and then Expander_Active |
| 752 |
and then Is_Record_Type (ET) |
| 753 |
and then (Is_Remote_Call_Interface (ET) or else Is_Remote_Types (ET)) |
| 754 |
and then Present (Corresponding_Remote_Type (ET)) |
| 755 |
and then Nkind (Parent (Parent (P))) in |
| 756 |
N_Procedure_Call_Statement | N_Indexed_Component |
| 757 |
then |
| 758 |
RAS_E_Dereference (P); |
| 759 |
return True; |
| 760 |
else |
| 761 |
return False; |
| 762 |
end if; |
| 763 |
end Remote_AST_E_Dereference; |
| 764 |
|
| 765 |
------------------------------ |
| 766 |
-- Remote_AST_I_Dereference -- |
| 767 |
------------------------------ |
| 768 |
|
| 769 |
function Remote_AST_I_Dereference (P : Node_Id) return Boolean is |
| 770 |
ET : constant Entity_Id := Etype (P); |
| 771 |
Deref : Node_Id; |
| 772 |
|
| 773 |
begin |
| 774 |
if Comes_From_Source (P) |
| 775 |
and then (Is_Remote_Call_Interface (ET) |
| 776 |
or else Is_Remote_Types (ET)) |
| 777 |
and then Present (Corresponding_Remote_Type (ET)) |
| 778 |
and then Ekind (Entity (P)) /= E_Function |
| 779 |
then |
| 780 |
Deref := |
| 781 |
Make_Explicit_Dereference (Sloc (P), |
| 782 |
Prefix => Relocate_Node (P)); |
| 783 |
Rewrite (P, Deref); |
| 784 |
Set_Etype (P, ET); |
| 785 |
RAS_E_Dereference (Prefix (P)); |
| 786 |
return True; |
| 787 |
end if; |
| 788 |
|
| 789 |
return False; |
| 790 |
end Remote_AST_I_Dereference; |
| 791 |
|
| 792 |
--------------------------- |
| 793 |
-- Remote_AST_Null_Value -- |
| 794 |
--------------------------- |
| 795 |
|
| 796 |
function Remote_AST_Null_Value |
| 797 |
(N : Node_Id; |
| 798 |
Typ : Entity_Id) return Boolean |
| 799 |
is |
| 800 |
Loc : constant Source_Ptr := Sloc (N); |
| 801 |
Target_Type : Entity_Id; |
| 802 |
|
| 803 |
begin |
| 804 |
if not Expander_Active or else Get_PCS_Name = Name_No_DSA then |
| 805 |
return False; |
| 806 |
|
| 807 |
elsif Ekind (Typ) = E_Access_Subprogram_Type |
| 808 |
and then (Is_Remote_Call_Interface (Typ) |
| 809 |
or else Is_Remote_Types (Typ)) |
| 810 |
and then Comes_From_Source (N) |
| 811 |
and then Expander_Active |
| 812 |
then |
| 813 |
-- Any null that comes from source and is of the RAS type must |
| 814 |
-- be expanded, except if expansion is not active (nothing |
| 815 |
-- gets expanded into the equivalent record type). |
| 816 |
|
| 817 |
Target_Type := Equivalent_Type (Typ); |
| 818 |
|
| 819 |
elsif Ekind (Typ) = E_Record_Type |
| 820 |
and then Present (Corresponding_Remote_Type (Typ)) |
| 821 |
then |
| 822 |
-- This is a record type representing a RAS type, this must be |
| 823 |
-- expanded. |
| 824 |
|
| 825 |
Target_Type := Typ; |
| 826 |
|
| 827 |
else |
| 828 |
-- We do not have to handle this case |
| 829 |
|
| 830 |
return False; |
| 831 |
end if; |
| 832 |
|
| 833 |
Rewrite (N, |
| 834 |
Make_Aggregate (Loc, |
| 835 |
Component_Associations => New_List ( |
| 836 |
Make_Component_Association (Loc, |
| 837 |
Choices => New_List (Make_Identifier (Loc, Name_Ras)), |
| 838 |
Expression => Make_Null (Loc))))); |
| 839 |
Analyze_And_Resolve (N, Target_Type); |
| 840 |
return True; |
| 841 |
end Remote_AST_Null_Value; |
| 842 |
|
| 843 |
end Sem_Dist; |