| 1 |
------------------------------------------------------------------------------ |
| 2 |
-- -- |
| 3 |
-- GNAT COMPILER COMPONENTS -- |
| 4 |
-- -- |
| 5 |
-- T B U I L D -- |
| 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 Aspects; use Aspects; |
| 28 |
with Csets; use Csets; |
| 29 |
with Einfo; use Einfo; |
| 30 |
with Einfo.Entities; use Einfo.Entities; |
| 31 |
with Einfo.Utils; use Einfo.Utils; |
| 32 |
with Lib; use Lib; |
| 33 |
with Nlists; use Nlists; |
| 34 |
with Nmake; use Nmake; |
| 35 |
with Opt; use Opt; |
| 36 |
with Restrict; use Restrict; |
| 37 |
with Rident; use Rident; |
| 38 |
with Sinfo.Utils; use Sinfo.Utils; |
| 39 |
with Sem_Util; use Sem_Util; |
| 40 |
with Snames; use Snames; |
| 41 |
with Stand; use Stand; |
| 42 |
with Stringt; use Stringt; |
| 43 |
with Urealp; use Urealp; |
| 44 |
|
| 45 |
package body Tbuild is |
| 46 |
|
| 47 |
----------------------- |
| 48 |
-- Local Subprograms -- |
| 49 |
----------------------- |
| 50 |
|
| 51 |
procedure Add_Unique_Serial_Number; |
| 52 |
-- Add a unique serialization to the string in the Name_Buffer. This |
| 53 |
-- consists of a unit specific serial number, and b/s for body/spec. |
| 54 |
|
| 55 |
------------------------------ |
| 56 |
-- Add_Unique_Serial_Number -- |
| 57 |
------------------------------ |
| 58 |
|
| 59 |
Config_Serial_Number : Nat := 0; |
| 60 |
-- Counter for use in config pragmas, see comment below |
| 61 |
|
| 62 |
procedure Add_Unique_Serial_Number is |
| 63 |
begin |
| 64 |
-- If we are analyzing configuration pragmas, Cunit (Main_Unit) will |
| 65 |
-- not be set yet. This happens for example when analyzing static |
| 66 |
-- string expressions in configuration pragmas. For this case, we |
| 67 |
-- just maintain a local counter, defined above and we do not need |
| 68 |
-- to add a b or s indication in this case. |
| 69 |
|
| 70 |
if No (Cunit (Current_Sem_Unit)) then |
| 71 |
Config_Serial_Number := Config_Serial_Number + 1; |
| 72 |
Add_Nat_To_Name_Buffer (Config_Serial_Number); |
| 73 |
return; |
| 74 |
|
| 75 |
-- Normal case, within a unit |
| 76 |
|
| 77 |
else |
| 78 |
declare |
| 79 |
Unit_Node : constant Node_Id := Unit (Cunit (Current_Sem_Unit)); |
| 80 |
|
| 81 |
begin |
| 82 |
Add_Nat_To_Name_Buffer (Increment_Serial_Number); |
| 83 |
|
| 84 |
-- Add either b or s, depending on whether current unit is a spec |
| 85 |
-- or a body. This is needed because we may generate the same name |
| 86 |
-- in a spec and a body otherwise. |
| 87 |
|
| 88 |
Name_Len := Name_Len + 1; |
| 89 |
|
| 90 |
if Nkind (Unit_Node) = N_Package_Declaration |
| 91 |
or else Nkind (Unit_Node) = N_Subprogram_Declaration |
| 92 |
or else Nkind (Unit_Node) in N_Generic_Declaration |
| 93 |
then |
| 94 |
Name_Buffer (Name_Len) := 's'; |
| 95 |
else |
| 96 |
Name_Buffer (Name_Len) := 'b'; |
| 97 |
end if; |
| 98 |
end; |
| 99 |
end if; |
| 100 |
end Add_Unique_Serial_Number; |
| 101 |
|
| 102 |
---------------- |
| 103 |
-- Convert_To -- |
| 104 |
---------------- |
| 105 |
|
| 106 |
function Convert_To (Typ : Entity_Id; Expr : Node_Id) return Node_Id is |
| 107 |
pragma Assert (Is_Type (Typ)); |
| 108 |
Result : Node_Id; |
| 109 |
|
| 110 |
begin |
| 111 |
if Present (Etype (Expr)) and then Etype (Expr) = Typ then |
| 112 |
return Relocate_Node (Expr); |
| 113 |
|
| 114 |
else |
| 115 |
Result := |
| 116 |
Make_Type_Conversion (Sloc (Expr), |
| 117 |
Subtype_Mark => New_Occurrence_Of (Typ, Sloc (Expr)), |
| 118 |
Expression => Relocate_Node (Expr)); |
| 119 |
|
| 120 |
Set_Etype (Result, Typ); |
| 121 |
return Result; |
| 122 |
end if; |
| 123 |
end Convert_To; |
| 124 |
|
| 125 |
---------------------------- |
| 126 |
-- Convert_To_And_Rewrite -- |
| 127 |
---------------------------- |
| 128 |
|
| 129 |
procedure Convert_To_And_Rewrite (Typ : Entity_Id; Expr : Node_Id) is |
| 130 |
begin |
| 131 |
Rewrite (Expr, Convert_To (Typ, Expr)); |
| 132 |
end Convert_To_And_Rewrite; |
| 133 |
|
| 134 |
------------------ |
| 135 |
-- Discard_List -- |
| 136 |
------------------ |
| 137 |
|
| 138 |
procedure Discard_List (L : List_Id) is |
| 139 |
pragma Warnings (Off, L); |
| 140 |
begin |
| 141 |
null; |
| 142 |
end Discard_List; |
| 143 |
|
| 144 |
------------------ |
| 145 |
-- Discard_Node -- |
| 146 |
------------------ |
| 147 |
|
| 148 |
procedure Discard_Node (N : Node_Or_Entity_Id) is |
| 149 |
pragma Warnings (Off, N); |
| 150 |
begin |
| 151 |
null; |
| 152 |
end Discard_Node; |
| 153 |
|
| 154 |
------------------------------------------- |
| 155 |
-- Make_Byte_Aligned_Attribute_Reference -- |
| 156 |
------------------------------------------- |
| 157 |
|
| 158 |
function Make_Byte_Aligned_Attribute_Reference |
| 159 |
(Sloc : Source_Ptr; |
| 160 |
Prefix : Node_Id; |
| 161 |
Attribute_Name : Name_Id) |
| 162 |
return Node_Id |
| 163 |
is |
| 164 |
N : constant Node_Id := |
| 165 |
Make_Attribute_Reference (Sloc, |
| 166 |
Prefix => Prefix, |
| 167 |
Attribute_Name => Attribute_Name); |
| 168 |
|
| 169 |
begin |
| 170 |
pragma Assert |
| 171 |
(Attribute_Name in Name_Address | Name_Unrestricted_Access); |
| 172 |
Set_Must_Be_Byte_Aligned (N, True); |
| 173 |
return N; |
| 174 |
end Make_Byte_Aligned_Attribute_Reference; |
| 175 |
|
| 176 |
------------------------ |
| 177 |
-- Make_Float_Literal -- |
| 178 |
------------------------ |
| 179 |
|
| 180 |
function Make_Float_Literal |
| 181 |
(Loc : Source_Ptr; |
| 182 |
Radix : Uint; |
| 183 |
Significand : Uint; |
| 184 |
Exponent : Uint) return Node_Id |
| 185 |
is |
| 186 |
begin |
| 187 |
if Radix = 2 and then abs Significand /= 1 then |
| 188 |
return |
| 189 |
Make_Float_Literal |
| 190 |
(Loc, Uint_16, |
| 191 |
Significand * Radix**(Exponent mod 4), |
| 192 |
Exponent / 4); |
| 193 |
|
| 194 |
else |
| 195 |
declare |
| 196 |
N : constant Node_Id := New_Node (N_Real_Literal, Loc); |
| 197 |
|
| 198 |
begin |
| 199 |
Set_Realval (N, |
| 200 |
UR_From_Components |
| 201 |
(Num => abs Significand, |
| 202 |
Den => -Exponent, |
| 203 |
Rbase => UI_To_Int (Radix), |
| 204 |
Negative => Significand < 0)); |
| 205 |
return N; |
| 206 |
end; |
| 207 |
end if; |
| 208 |
end Make_Float_Literal; |
| 209 |
|
| 210 |
------------- |
| 211 |
-- Make_Id -- |
| 212 |
------------- |
| 213 |
|
| 214 |
function Make_Id (Str : Text_Buffer) return Node_Id is |
| 215 |
begin |
| 216 |
Name_Len := 0; |
| 217 |
|
| 218 |
for J in Str'Range loop |
| 219 |
Name_Len := Name_Len + 1; |
| 220 |
Name_Buffer (Name_Len) := Fold_Lower (Str (J)); |
| 221 |
end loop; |
| 222 |
|
| 223 |
return |
| 224 |
Make_Identifier (System_Location, |
| 225 |
Chars => Name_Find); |
| 226 |
end Make_Id; |
| 227 |
|
| 228 |
------------------------------------- |
| 229 |
-- Make_Implicit_Exception_Handler -- |
| 230 |
------------------------------------- |
| 231 |
|
| 232 |
function Make_Implicit_Exception_Handler |
| 233 |
(Sloc : Source_Ptr; |
| 234 |
Choice_Parameter : Node_Id := Empty; |
| 235 |
Exception_Choices : List_Id; |
| 236 |
Statements : List_Id) return Node_Id |
| 237 |
is |
| 238 |
Handler : Node_Id; |
| 239 |
Loc : Source_Ptr; |
| 240 |
|
| 241 |
begin |
| 242 |
-- Set the source location only when debugging the expanded code |
| 243 |
|
| 244 |
-- When debugging the source code directly, we do not want the compiler |
| 245 |
-- to associate this implicit exception handler with any specific source |
| 246 |
-- line, because it can potentially confuse the debugger. The most |
| 247 |
-- damaging situation would arise when the debugger tries to insert a |
| 248 |
-- breakpoint at a certain line. If the code of the associated implicit |
| 249 |
-- exception handler is generated before the code of that line, then the |
| 250 |
-- debugger will end up inserting the breakpoint inside the exception |
| 251 |
-- handler, rather than the code the user intended to break on. As a |
| 252 |
-- result, it is likely that the program will not hit the breakpoint |
| 253 |
-- as expected. |
| 254 |
|
| 255 |
if Debug_Generated_Code then |
| 256 |
Loc := Sloc; |
| 257 |
else |
| 258 |
Loc := No_Location; |
| 259 |
end if; |
| 260 |
|
| 261 |
Handler := |
| 262 |
Make_Exception_Handler |
| 263 |
(Loc, Choice_Parameter, Exception_Choices, Statements); |
| 264 |
Set_Local_Raise_Statements (Handler, No_Elist); |
| 265 |
return Handler; |
| 266 |
end Make_Implicit_Exception_Handler; |
| 267 |
|
| 268 |
-------------------------------- |
| 269 |
-- Make_Implicit_If_Statement -- |
| 270 |
-------------------------------- |
| 271 |
|
| 272 |
function Make_Implicit_If_Statement |
| 273 |
(Node : Node_Id; |
| 274 |
Condition : Node_Id; |
| 275 |
Then_Statements : List_Id; |
| 276 |
Elsif_Parts : List_Id := No_List; |
| 277 |
Else_Statements : List_Id := No_List) return Node_Id |
| 278 |
is |
| 279 |
begin |
| 280 |
Check_Restriction (No_Implicit_Conditionals, Node); |
| 281 |
|
| 282 |
return Make_If_Statement (Sloc (Node), |
| 283 |
Condition, |
| 284 |
Then_Statements, |
| 285 |
Elsif_Parts, |
| 286 |
Else_Statements); |
| 287 |
end Make_Implicit_If_Statement; |
| 288 |
|
| 289 |
------------------------------------- |
| 290 |
-- Make_Implicit_Label_Declaration -- |
| 291 |
------------------------------------- |
| 292 |
|
| 293 |
function Make_Implicit_Label_Declaration |
| 294 |
(Loc : Source_Ptr; |
| 295 |
Defining_Identifier : Node_Id; |
| 296 |
Label_Construct : Node_Id) return Node_Id |
| 297 |
is |
| 298 |
N : constant Node_Id := |
| 299 |
Make_Implicit_Label_Declaration (Loc, Defining_Identifier); |
| 300 |
begin |
| 301 |
Set_Label_Construct (N, Label_Construct); |
| 302 |
return N; |
| 303 |
end Make_Implicit_Label_Declaration; |
| 304 |
|
| 305 |
---------------------------------- |
| 306 |
-- Make_Implicit_Loop_Statement -- |
| 307 |
---------------------------------- |
| 308 |
|
| 309 |
function Make_Implicit_Loop_Statement |
| 310 |
(Node : Node_Id; |
| 311 |
Statements : List_Id; |
| 312 |
Identifier : Node_Id := Empty; |
| 313 |
Iteration_Scheme : Node_Id := Empty; |
| 314 |
Has_Created_Identifier : Boolean := False; |
| 315 |
End_Label : Node_Id := Empty) return Node_Id |
| 316 |
is |
| 317 |
P : Node_Id; |
| 318 |
Check_Restrictions : Boolean := True; |
| 319 |
begin |
| 320 |
-- Do not check restrictions if the implicit loop statement is part |
| 321 |
-- of a dead branch: False and then ... |
| 322 |
-- This will occur in particular as part of the expansion of pragma |
| 323 |
-- Assert when assertions are disabled. |
| 324 |
|
| 325 |
P := Parent (Node); |
| 326 |
while Present (P) loop |
| 327 |
if Nkind (P) = N_And_Then then |
| 328 |
if Nkind (Left_Opnd (P)) = N_Identifier |
| 329 |
and then Entity (Left_Opnd (P)) = Standard_False |
| 330 |
then |
| 331 |
Check_Restrictions := False; |
| 332 |
exit; |
| 333 |
end if; |
| 334 |
|
| 335 |
-- Prevent the search from going too far |
| 336 |
|
| 337 |
elsif Is_Body_Or_Package_Declaration (P) then |
| 338 |
exit; |
| 339 |
end if; |
| 340 |
|
| 341 |
P := Parent (P); |
| 342 |
end loop; |
| 343 |
|
| 344 |
if Check_Restrictions then |
| 345 |
Check_Restriction (No_Implicit_Loops, Node); |
| 346 |
|
| 347 |
if Present (Iteration_Scheme) |
| 348 |
and then Nkind (Iteration_Scheme) /= N_Iterator_Specification |
| 349 |
and then Present (Condition (Iteration_Scheme)) |
| 350 |
then |
| 351 |
Check_Restriction (No_Implicit_Conditionals, Node); |
| 352 |
end if; |
| 353 |
end if; |
| 354 |
|
| 355 |
return Make_Loop_Statement (Sloc (Node), |
| 356 |
Identifier => Identifier, |
| 357 |
Iteration_Scheme => Iteration_Scheme, |
| 358 |
Statements => Statements, |
| 359 |
Has_Created_Identifier => Has_Created_Identifier, |
| 360 |
End_Label => End_Label); |
| 361 |
end Make_Implicit_Loop_Statement; |
| 362 |
|
| 363 |
-------------------- |
| 364 |
-- Make_Increment -- |
| 365 |
-------------------- |
| 366 |
|
| 367 |
function Make_Increment |
| 368 |
(Loc : Source_Ptr; Index : Entity_Id; Typ : Entity_Id) return Node_Id is |
| 369 |
begin |
| 370 |
return Make_Assignment_Statement (Loc, |
| 371 |
Name => New_Occurrence_Of (Index, Loc), |
| 372 |
Expression => |
| 373 |
Make_Attribute_Reference (Loc, |
| 374 |
Prefix => |
| 375 |
New_Occurrence_Of (Typ, Loc), |
| 376 |
Attribute_Name => Name_Succ, |
| 377 |
Expressions => New_List ( |
| 378 |
New_Occurrence_Of (Index, Loc)))); |
| 379 |
end Make_Increment; |
| 380 |
|
| 381 |
-------------------------- |
| 382 |
-- Make_Integer_Literal -- |
| 383 |
--------------------------- |
| 384 |
|
| 385 |
function Make_Integer_Literal |
| 386 |
(Loc : Source_Ptr; |
| 387 |
Intval : Int) return Node_Id |
| 388 |
is |
| 389 |
begin |
| 390 |
return Make_Integer_Literal (Loc, UI_From_Int (Intval)); |
| 391 |
end Make_Integer_Literal; |
| 392 |
|
| 393 |
-------------------------------- |
| 394 |
-- Make_Linker_Section_Pragma -- |
| 395 |
-------------------------------- |
| 396 |
|
| 397 |
function Make_Linker_Section_Pragma |
| 398 |
(Ent : Entity_Id; |
| 399 |
Loc : Source_Ptr; |
| 400 |
Sec : String) return Node_Id |
| 401 |
is |
| 402 |
LS : Node_Id; |
| 403 |
|
| 404 |
begin |
| 405 |
LS := |
| 406 |
Make_Pragma |
| 407 |
(Loc, |
| 408 |
Name_Linker_Section, |
| 409 |
New_List |
| 410 |
(Make_Pragma_Argument_Association |
| 411 |
(Sloc => Loc, |
| 412 |
Expression => New_Occurrence_Of (Ent, Loc)), |
| 413 |
Make_Pragma_Argument_Association |
| 414 |
(Sloc => Loc, |
| 415 |
Expression => |
| 416 |
Make_String_Literal |
| 417 |
(Sloc => Loc, |
| 418 |
Strval => Sec)))); |
| 419 |
|
| 420 |
Set_Has_Gigi_Rep_Item (Ent); |
| 421 |
return LS; |
| 422 |
end Make_Linker_Section_Pragma; |
| 423 |
|
| 424 |
----------------- |
| 425 |
-- Make_Pragma -- |
| 426 |
----------------- |
| 427 |
|
| 428 |
function Make_Pragma |
| 429 |
(Sloc : Source_Ptr; |
| 430 |
Chars : Name_Id; |
| 431 |
Pragma_Argument_Associations : List_Id := No_List) return Node_Id |
| 432 |
is |
| 433 |
begin |
| 434 |
return |
| 435 |
Make_Pragma (Sloc, |
| 436 |
Pragma_Argument_Associations => Pragma_Argument_Associations, |
| 437 |
Pragma_Identifier => Make_Identifier (Sloc, Chars)); |
| 438 |
end Make_Pragma; |
| 439 |
|
| 440 |
--------------------------------- |
| 441 |
-- Make_Raise_Constraint_Error -- |
| 442 |
--------------------------------- |
| 443 |
|
| 444 |
function Make_Raise_Constraint_Error |
| 445 |
(Sloc : Source_Ptr; |
| 446 |
Condition : Node_Id := Empty; |
| 447 |
Reason : RT_Exception_Code) return Node_Id |
| 448 |
is |
| 449 |
begin |
| 450 |
pragma Assert (Rkind (Reason) = CE_Reason); |
| 451 |
return |
| 452 |
Make_Raise_Constraint_Error (Sloc, |
| 453 |
Condition => Condition, |
| 454 |
Reason => UI_From_Int (RT_Exception_Code'Pos (Reason))); |
| 455 |
end Make_Raise_Constraint_Error; |
| 456 |
|
| 457 |
------------------------------ |
| 458 |
-- Make_Raise_Program_Error -- |
| 459 |
------------------------------ |
| 460 |
|
| 461 |
function Make_Raise_Program_Error |
| 462 |
(Sloc : Source_Ptr; |
| 463 |
Condition : Node_Id := Empty; |
| 464 |
Reason : RT_Exception_Code) return Node_Id |
| 465 |
is |
| 466 |
begin |
| 467 |
pragma Assert (Rkind (Reason) = PE_Reason); |
| 468 |
return |
| 469 |
Make_Raise_Program_Error (Sloc, |
| 470 |
Condition => Condition, |
| 471 |
Reason => UI_From_Int (RT_Exception_Code'Pos (Reason))); |
| 472 |
end Make_Raise_Program_Error; |
| 473 |
|
| 474 |
------------------------------ |
| 475 |
-- Make_Raise_Storage_Error -- |
| 476 |
------------------------------ |
| 477 |
|
| 478 |
function Make_Raise_Storage_Error |
| 479 |
(Sloc : Source_Ptr; |
| 480 |
Condition : Node_Id := Empty; |
| 481 |
Reason : RT_Exception_Code) return Node_Id |
| 482 |
is |
| 483 |
begin |
| 484 |
pragma Assert (Rkind (Reason) = SE_Reason); |
| 485 |
return |
| 486 |
Make_Raise_Storage_Error (Sloc, |
| 487 |
Condition => Condition, |
| 488 |
Reason => UI_From_Int (RT_Exception_Code'Pos (Reason))); |
| 489 |
end Make_Raise_Storage_Error; |
| 490 |
|
| 491 |
------------- |
| 492 |
-- Make_SC -- |
| 493 |
------------- |
| 494 |
|
| 495 |
function Make_SC (Pre, Sel : Node_Id) return Node_Id is |
| 496 |
begin |
| 497 |
return |
| 498 |
Make_Selected_Component (System_Location, |
| 499 |
Prefix => Pre, |
| 500 |
Selector_Name => Sel); |
| 501 |
end Make_SC; |
| 502 |
|
| 503 |
------------------------- |
| 504 |
-- Make_String_Literal -- |
| 505 |
------------------------- |
| 506 |
|
| 507 |
function Make_String_Literal |
| 508 |
(Sloc : Source_Ptr; |
| 509 |
Strval : String) return Node_Id |
| 510 |
is |
| 511 |
begin |
| 512 |
Start_String; |
| 513 |
Store_String_Chars (Strval); |
| 514 |
return Make_String_Literal (Sloc, Strval => End_String); |
| 515 |
end Make_String_Literal; |
| 516 |
|
| 517 |
------------------------- |
| 518 |
-- Make_Suppress_Block -- |
| 519 |
------------------------- |
| 520 |
|
| 521 |
-- Generates the following expansion: |
| 522 |
|
| 523 |
-- declare |
| 524 |
-- pragma Suppress (<check>); |
| 525 |
-- begin |
| 526 |
-- <stmts> |
| 527 |
-- end; |
| 528 |
|
| 529 |
function Make_Suppress_Block |
| 530 |
(Loc : Source_Ptr; |
| 531 |
Check : Name_Id; |
| 532 |
Stmts : List_Id) return Node_Id |
| 533 |
is |
| 534 |
begin |
| 535 |
return |
| 536 |
Make_Block_Statement (Loc, |
| 537 |
Declarations => New_List ( |
| 538 |
Make_Pragma (Loc, |
| 539 |
Chars => Name_Suppress, |
| 540 |
Pragma_Argument_Associations => New_List ( |
| 541 |
Make_Pragma_Argument_Association (Loc, |
| 542 |
Expression => Make_Identifier (Loc, Check))))), |
| 543 |
|
| 544 |
Handled_Statement_Sequence => |
| 545 |
Make_Handled_Sequence_Of_Statements (Loc, |
| 546 |
Statements => Stmts)); |
| 547 |
end Make_Suppress_Block; |
| 548 |
|
| 549 |
-------------------- |
| 550 |
-- Make_Temporary -- |
| 551 |
-------------------- |
| 552 |
|
| 553 |
function Make_Temporary |
| 554 |
(Loc : Source_Ptr; |
| 555 |
Id : Character; |
| 556 |
Related_Node : Node_Id := Empty) return Entity_Id |
| 557 |
is |
| 558 |
Temp : constant Entity_Id := |
| 559 |
Make_Defining_Identifier (Loc, Chars => New_Internal_Name (Id)); |
| 560 |
begin |
| 561 |
Set_Related_Expression (Temp, Related_Node); |
| 562 |
return Temp; |
| 563 |
end Make_Temporary; |
| 564 |
|
| 565 |
--------------------------- |
| 566 |
-- Make_Unsuppress_Block -- |
| 567 |
--------------------------- |
| 568 |
|
| 569 |
-- Generates the following expansion: |
| 570 |
|
| 571 |
-- declare |
| 572 |
-- pragma Unsuppress (<check>); |
| 573 |
-- begin |
| 574 |
-- <stmts> |
| 575 |
-- end; |
| 576 |
|
| 577 |
function Make_Unsuppress_Block |
| 578 |
(Loc : Source_Ptr; |
| 579 |
Check : Name_Id; |
| 580 |
Stmts : List_Id) return Node_Id |
| 581 |
is |
| 582 |
begin |
| 583 |
return |
| 584 |
Make_Block_Statement (Loc, |
| 585 |
Declarations => New_List ( |
| 586 |
Make_Pragma (Loc, |
| 587 |
Chars => Name_Unsuppress, |
| 588 |
Pragma_Argument_Associations => New_List ( |
| 589 |
Make_Pragma_Argument_Association (Loc, |
| 590 |
Expression => Make_Identifier (Loc, Check))))), |
| 591 |
|
| 592 |
Handled_Statement_Sequence => |
| 593 |
Make_Handled_Sequence_Of_Statements (Loc, |
| 594 |
Statements => Stmts)); |
| 595 |
end Make_Unsuppress_Block; |
| 596 |
|
| 597 |
-------------------------- |
| 598 |
-- New_Constraint_Error -- |
| 599 |
-------------------------- |
| 600 |
|
| 601 |
function New_Constraint_Error (Loc : Source_Ptr) return Node_Id is |
| 602 |
Ident_Node : Node_Id; |
| 603 |
Raise_Node : Node_Id; |
| 604 |
|
| 605 |
begin |
| 606 |
Ident_Node := New_Node (N_Identifier, Loc); |
| 607 |
Set_Chars (Ident_Node, Chars (Standard_Entity (S_Constraint_Error))); |
| 608 |
Set_Entity (Ident_Node, Standard_Entity (S_Constraint_Error)); |
| 609 |
Raise_Node := New_Node (N_Raise_Statement, Loc); |
| 610 |
Set_Name (Raise_Node, Ident_Node); |
| 611 |
return Raise_Node; |
| 612 |
end New_Constraint_Error; |
| 613 |
|
| 614 |
----------------------- |
| 615 |
-- New_External_Name -- |
| 616 |
----------------------- |
| 617 |
|
| 618 |
function New_External_Name |
| 619 |
(Related_Id : Name_Id; |
| 620 |
Suffix : Character := ' '; |
| 621 |
Suffix_Index : Int := 0; |
| 622 |
Prefix : Character := ' ') return Name_Id |
| 623 |
is |
| 624 |
begin |
| 625 |
Get_Name_String (Related_Id); |
| 626 |
|
| 627 |
if Prefix /= ' ' then |
| 628 |
pragma Assert (Is_OK_Internal_Letter (Prefix) or else Prefix = '_'); |
| 629 |
|
| 630 |
for J in reverse 1 .. Name_Len loop |
| 631 |
Name_Buffer (J + 1) := Name_Buffer (J); |
| 632 |
end loop; |
| 633 |
|
| 634 |
Name_Len := Name_Len + 1; |
| 635 |
Name_Buffer (1) := Prefix; |
| 636 |
end if; |
| 637 |
|
| 638 |
if Suffix /= ' ' then |
| 639 |
pragma Assert (Is_OK_Internal_Letter (Suffix)); |
| 640 |
Add_Char_To_Name_Buffer (Suffix); |
| 641 |
end if; |
| 642 |
|
| 643 |
if Suffix_Index /= 0 then |
| 644 |
if Suffix_Index < 0 then |
| 645 |
Add_Unique_Serial_Number; |
| 646 |
else |
| 647 |
Add_Nat_To_Name_Buffer (Suffix_Index); |
| 648 |
end if; |
| 649 |
end if; |
| 650 |
|
| 651 |
return Name_Find; |
| 652 |
end New_External_Name; |
| 653 |
|
| 654 |
function New_External_Name |
| 655 |
(Related_Id : Name_Id; |
| 656 |
Suffix : String; |
| 657 |
Suffix_Index : Int := 0; |
| 658 |
Prefix : Character := ' ') return Name_Id |
| 659 |
is |
| 660 |
begin |
| 661 |
Get_Name_String (Related_Id); |
| 662 |
|
| 663 |
if Prefix /= ' ' then |
| 664 |
pragma Assert (Is_OK_Internal_Letter (Prefix)); |
| 665 |
|
| 666 |
for J in reverse 1 .. Name_Len loop |
| 667 |
Name_Buffer (J + 1) := Name_Buffer (J); |
| 668 |
end loop; |
| 669 |
|
| 670 |
Name_Len := Name_Len + 1; |
| 671 |
Name_Buffer (1) := Prefix; |
| 672 |
end if; |
| 673 |
|
| 674 |
if Suffix /= "" then |
| 675 |
Name_Buffer (Name_Len + 1 .. Name_Len + Suffix'Length) := Suffix; |
| 676 |
Name_Len := Name_Len + Suffix'Length; |
| 677 |
end if; |
| 678 |
|
| 679 |
if Suffix_Index /= 0 then |
| 680 |
if Suffix_Index < 0 then |
| 681 |
Add_Unique_Serial_Number; |
| 682 |
else |
| 683 |
Add_Nat_To_Name_Buffer (Suffix_Index); |
| 684 |
end if; |
| 685 |
end if; |
| 686 |
|
| 687 |
return Name_Find; |
| 688 |
end New_External_Name; |
| 689 |
|
| 690 |
function New_External_Name |
| 691 |
(Suffix : Character; |
| 692 |
Suffix_Index : Nat) return Name_Id |
| 693 |
is |
| 694 |
begin |
| 695 |
Name_Buffer (1) := Suffix; |
| 696 |
Name_Len := 1; |
| 697 |
Add_Nat_To_Name_Buffer (Suffix_Index); |
| 698 |
return Name_Find; |
| 699 |
end New_External_Name; |
| 700 |
|
| 701 |
----------------------- |
| 702 |
-- New_Internal_Name -- |
| 703 |
----------------------- |
| 704 |
|
| 705 |
function New_Internal_Name (Id_Char : Character) return Name_Id is |
| 706 |
begin |
| 707 |
pragma Assert (Is_OK_Internal_Letter (Id_Char)); |
| 708 |
Name_Buffer (1) := Id_Char; |
| 709 |
Name_Len := 1; |
| 710 |
Add_Unique_Serial_Number; |
| 711 |
return Name_Enter; |
| 712 |
end New_Internal_Name; |
| 713 |
|
| 714 |
----------------------- |
| 715 |
-- New_Occurrence_Of -- |
| 716 |
----------------------- |
| 717 |
|
| 718 |
function New_Occurrence_Of |
| 719 |
(Def_Id : Entity_Id; |
| 720 |
Loc : Source_Ptr) return Node_Id |
| 721 |
is |
| 722 |
pragma Assert (Present (Def_Id) and then Nkind (Def_Id) in N_Entity); |
| 723 |
Occurrence : constant Node_Id := |
| 724 |
Make_Identifier (Loc, Chars (Def_Id)); |
| 725 |
|
| 726 |
begin |
| 727 |
Set_Entity (Occurrence, Def_Id); |
| 728 |
|
| 729 |
if Is_Type (Def_Id) then |
| 730 |
Set_Etype (Occurrence, Def_Id); |
| 731 |
else |
| 732 |
Set_Etype (Occurrence, Etype (Def_Id)); |
| 733 |
end if; |
| 734 |
|
| 735 |
if Ekind (Def_Id) = E_Enumeration_Literal then |
| 736 |
Set_Is_Static_Expression (Occurrence, True); |
| 737 |
end if; |
| 738 |
|
| 739 |
return Occurrence; |
| 740 |
end New_Occurrence_Of; |
| 741 |
|
| 742 |
----------------- |
| 743 |
-- New_Op_Node -- |
| 744 |
----------------- |
| 745 |
|
| 746 |
function New_Op_Node |
| 747 |
(New_Node_Kind : Node_Kind; |
| 748 |
New_Sloc : Source_Ptr) return Node_Id |
| 749 |
is |
| 750 |
type Name_Of_Type is array (N_Op) of Name_Id; |
| 751 |
Name_Of : constant Name_Of_Type := Name_Of_Type'( |
| 752 |
N_Op_And => Name_Op_And, |
| 753 |
N_Op_Or => Name_Op_Or, |
| 754 |
N_Op_Xor => Name_Op_Xor, |
| 755 |
N_Op_Eq => Name_Op_Eq, |
| 756 |
N_Op_Ne => Name_Op_Ne, |
| 757 |
N_Op_Lt => Name_Op_Lt, |
| 758 |
N_Op_Le => Name_Op_Le, |
| 759 |
N_Op_Gt => Name_Op_Gt, |
| 760 |
N_Op_Ge => Name_Op_Ge, |
| 761 |
N_Op_Add => Name_Op_Add, |
| 762 |
N_Op_Subtract => Name_Op_Subtract, |
| 763 |
N_Op_Concat => Name_Op_Concat, |
| 764 |
N_Op_Multiply => Name_Op_Multiply, |
| 765 |
N_Op_Divide => Name_Op_Divide, |
| 766 |
N_Op_Mod => Name_Op_Mod, |
| 767 |
N_Op_Rem => Name_Op_Rem, |
| 768 |
N_Op_Expon => Name_Op_Expon, |
| 769 |
N_Op_Plus => Name_Op_Add, |
| 770 |
N_Op_Minus => Name_Op_Subtract, |
| 771 |
N_Op_Abs => Name_Op_Abs, |
| 772 |
N_Op_Not => Name_Op_Not, |
| 773 |
|
| 774 |
-- We don't really need these shift operators, since they never |
| 775 |
-- appear as operators in the source, but the path of least |
| 776 |
-- resistance is to put them in (the aggregate must be complete). |
| 777 |
|
| 778 |
N_Op_Rotate_Left => Name_Rotate_Left, |
| 779 |
N_Op_Rotate_Right => Name_Rotate_Right, |
| 780 |
N_Op_Shift_Left => Name_Shift_Left, |
| 781 |
N_Op_Shift_Right => Name_Shift_Right, |
| 782 |
N_Op_Shift_Right_Arithmetic => Name_Shift_Right_Arithmetic); |
| 783 |
|
| 784 |
Nod : constant Node_Id := New_Node (New_Node_Kind, New_Sloc); |
| 785 |
|
| 786 |
begin |
| 787 |
if New_Node_Kind in Name_Of'Range then |
| 788 |
Set_Chars (Nod, Name_Of (New_Node_Kind)); |
| 789 |
end if; |
| 790 |
|
| 791 |
return Nod; |
| 792 |
end New_Op_Node; |
| 793 |
|
| 794 |
----------------------- |
| 795 |
-- New_Suffixed_Name -- |
| 796 |
----------------------- |
| 797 |
|
| 798 |
function New_Suffixed_Name |
| 799 |
(Related_Id : Name_Id; |
| 800 |
Suffix : String) return Name_Id |
| 801 |
is |
| 802 |
begin |
| 803 |
Get_Name_String (Related_Id); |
| 804 |
Add_Char_To_Name_Buffer ('_'); |
| 805 |
Add_Str_To_Name_Buffer (Suffix); |
| 806 |
return Name_Find; |
| 807 |
end New_Suffixed_Name; |
| 808 |
|
| 809 |
------------------- |
| 810 |
-- OK_Convert_To -- |
| 811 |
------------------- |
| 812 |
|
| 813 |
function OK_Convert_To (Typ : Entity_Id; Expr : Node_Id) return Node_Id is |
| 814 |
Result : Node_Id; |
| 815 |
begin |
| 816 |
Result := |
| 817 |
Make_Type_Conversion (Sloc (Expr), |
| 818 |
Subtype_Mark => New_Occurrence_Of (Typ, Sloc (Expr)), |
| 819 |
Expression => Relocate_Node (Expr)); |
| 820 |
Set_Conversion_OK (Result, True); |
| 821 |
Set_Etype (Result, Typ); |
| 822 |
return Result; |
| 823 |
end OK_Convert_To; |
| 824 |
|
| 825 |
-------------- |
| 826 |
-- Sel_Comp -- |
| 827 |
-------------- |
| 828 |
|
| 829 |
function Sel_Comp (Pre : Node_Id; Sel : String) return Node_Id is |
| 830 |
begin |
| 831 |
return Make_Selected_Component |
| 832 |
(Sloc => Sloc (Pre), |
| 833 |
Prefix => Pre, |
| 834 |
Selector_Name => Make_Identifier (Sloc (Pre), Name_Find (Sel))); |
| 835 |
end Sel_Comp; |
| 836 |
|
| 837 |
function Sel_Comp (Pre, Sel : String; Loc : Source_Ptr) return Node_Id is |
| 838 |
begin |
| 839 |
return Sel_Comp (Make_Identifier (Loc, Name_Find (Pre)), Sel); |
| 840 |
end Sel_Comp; |
| 841 |
|
| 842 |
------------- |
| 843 |
-- Set_NOD -- |
| 844 |
------------- |
| 845 |
|
| 846 |
procedure Set_NOD (Unit : Node_Id) is |
| 847 |
begin |
| 848 |
Set_Restriction_No_Dependence (Unit, Warn => False); |
| 849 |
end Set_NOD; |
| 850 |
|
| 851 |
------------- |
| 852 |
-- Set_NSA -- |
| 853 |
------------- |
| 854 |
|
| 855 |
procedure Set_NSA (Asp : Name_Id; OK : out Boolean) is |
| 856 |
Asp_Id : constant Aspect_Id := Get_Aspect_Id (Asp); |
| 857 |
begin |
| 858 |
if Asp_Id = No_Aspect then |
| 859 |
OK := False; |
| 860 |
else |
| 861 |
OK := True; |
| 862 |
Set_Restriction_No_Specification_Of_Aspect (Asp_Id); |
| 863 |
end if; |
| 864 |
end Set_NSA; |
| 865 |
|
| 866 |
------------- |
| 867 |
-- Set_NUA -- |
| 868 |
------------- |
| 869 |
|
| 870 |
procedure Set_NUA (Attr : Name_Id; OK : out Boolean) is |
| 871 |
begin |
| 872 |
if Is_Attribute_Name (Attr) then |
| 873 |
OK := True; |
| 874 |
Set_Restriction_No_Use_Of_Attribute (Get_Attribute_Id (Attr)); |
| 875 |
else |
| 876 |
OK := False; |
| 877 |
end if; |
| 878 |
end Set_NUA; |
| 879 |
|
| 880 |
------------- |
| 881 |
-- Set_NUP -- |
| 882 |
------------- |
| 883 |
|
| 884 |
procedure Set_NUP (Prag : Name_Id; OK : out Boolean) is |
| 885 |
begin |
| 886 |
if Is_Pragma_Name (Prag) then |
| 887 |
OK := True; |
| 888 |
Set_Restriction_No_Use_Of_Pragma (Get_Pragma_Id (Prag)); |
| 889 |
else |
| 890 |
OK := False; |
| 891 |
end if; |
| 892 |
end Set_NUP; |
| 893 |
|
| 894 |
-------------------------- |
| 895 |
-- Unchecked_Convert_To -- |
| 896 |
-------------------------- |
| 897 |
|
| 898 |
function Unchecked_Convert_To |
| 899 |
(Typ : Entity_Id; |
| 900 |
Expr : Node_Id) return Node_Id |
| 901 |
is |
| 902 |
pragma Assert (Ekind (Typ) in E_Void | Type_Kind); |
| 903 |
-- We don't really want to allow E_Void here, but existing code passes |
| 904 |
-- it. |
| 905 |
|
| 906 |
Loc : constant Source_Ptr := Sloc (Expr); |
| 907 |
Result : Node_Id; |
| 908 |
|
| 909 |
begin |
| 910 |
-- If the expression is already of the correct type, then nothing to do, |
| 911 |
-- except for relocating the node. If Typ is an array type with fixed |
| 912 |
-- lower bound, the expression might be of a subtype that does not |
| 913 |
-- have this lower bound (on a slice), hence the conversion needs to |
| 914 |
-- be preserved for sliding. |
| 915 |
|
| 916 |
if Present (Etype (Expr)) |
| 917 |
and then |
| 918 |
((Base_Type (Etype (Expr)) = Typ |
| 919 |
and then not Is_Fixed_Lower_Bound_Array_Subtype (Typ)) |
| 920 |
or else Etype (Expr) = Typ) |
| 921 |
then |
| 922 |
return Relocate_Node (Expr); |
| 923 |
|
| 924 |
-- Case where the expression is already an unchecked conversion. We |
| 925 |
-- replace the type being converted to, to avoid creating an unchecked |
| 926 |
-- conversion of an unchecked conversion. Extra unchecked conversions |
| 927 |
-- make the .dg output less readable. We can't do this in cases |
| 928 |
-- involving bitfields, because the sizes might not match. The |
| 929 |
-- Is_Composite_Type checks avoid such cases. |
| 930 |
|
| 931 |
elsif Nkind (Expr) = N_Unchecked_Type_Conversion |
| 932 |
and then Is_Composite_Type (Etype (Expr)) |
| 933 |
and then Is_Composite_Type (Typ) |
| 934 |
then |
| 935 |
Set_Subtype_Mark (Expr, New_Occurrence_Of (Typ, Loc)); |
| 936 |
Result := Relocate_Node (Expr); |
| 937 |
|
| 938 |
elsif Nkind (Expr) = N_Null |
| 939 |
and then Is_Access_Type (Typ) |
| 940 |
then |
| 941 |
-- No need for a conversion |
| 942 |
|
| 943 |
Result := Relocate_Node (Expr); |
| 944 |
|
| 945 |
-- All other cases |
| 946 |
|
| 947 |
else |
| 948 |
declare |
| 949 |
Expr_Parent : constant Node_Id := Parent (Expr); |
| 950 |
begin |
| 951 |
Result := |
| 952 |
Make_Unchecked_Type_Conversion (Loc, |
| 953 |
Subtype_Mark => New_Occurrence_Of (Typ, Loc), |
| 954 |
Expression => Relocate_Node (Expr)); |
| 955 |
Set_Parent (Result, Expr_Parent); |
| 956 |
end; |
| 957 |
end if; |
| 958 |
|
| 959 |
Set_Etype (Result, Typ); |
| 960 |
return Result; |
| 961 |
end Unchecked_Convert_To; |
| 962 |
|
| 963 |
end Tbuild; |