1------------------------------------------------------------------------------ 2-- -- 3-- GNAT COMPILER COMPONENTS -- 4-- -- 5-- C S T A N D -- 6-- -- 7-- B o d y -- 8-- -- 9-- Copyright (C) 1992-2020, 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 26with Atree; use Atree; 27with Csets; use Csets; 28with Debug; use Debug; 29with Einfo; use Einfo; 30with Elists; use Elists; 31with Layout; use Layout; 32with Namet; use Namet; 33with Nlists; use Nlists; 34with Nmake; use Nmake; 35with Opt; use Opt; 36with Output; use Output; 37with Set_Targ; use Set_Targ; 38with Targparm; use Targparm; 39with Tbuild; use Tbuild; 40with Ttypes; use Ttypes; 41with Sem_Mech; use Sem_Mech; 42with Sem_Util; use Sem_Util; 43with Sinfo; use Sinfo; 44with Snames; use Snames; 45with Stand; use Stand; 46with Uintp; use Uintp; 47with Urealp; use Urealp; 48 49package body CStand is 50 51 Stloc : Source_Ptr renames Standard_Location; 52 Staloc : Source_Ptr renames Standard_ASCII_Location; 53 -- Standard abbreviations used throughout this package 54 55 Back_End_Float_Types : Elist_Id := No_Elist; 56 -- List used for any floating point supported by the back end. This needs 57 -- to be at the library level, because the call back procedures retrieving 58 -- this information are at that level. 59 60 ----------------------- 61 -- Local Subprograms -- 62 ----------------------- 63 64 procedure Build_Float_Type 65 (E : Entity_Id; 66 Digs : Int; 67 Rep : Float_Rep_Kind; 68 Siz : Int; 69 Align : Int); 70 -- Procedure to build standard predefined float base type. The first 71 -- parameter is the entity for the type. The second parameter is the 72 -- digits value. The third parameter indicates the representation to 73 -- be used for the type. The fourth parameter is the size in bits. 74 -- The fifth parameter is the alignment in storage units. Each type 75 -- is added to the list of predefined floating point types. 76 -- 77 -- Note that both RM_Size and Esize are set to the specified size, i.e. 78 -- we do not set the RM_Size to the precision passed by the back end. 79 -- This is consistent with the semantics of 'Size specified in the RM 80 -- because we cannot pack components of the type tighter than this size. 81 82 procedure Build_Signed_Integer_Type (E : Entity_Id; Siz : Nat); 83 -- Procedure to build standard predefined signed integer subtype. The 84 -- first parameter is the entity for the subtype. The second parameter 85 -- is the size in bits. The corresponding base type is not built by 86 -- this routine but instead must be built by the caller where needed. 87 88 procedure Build_Unsigned_Integer_Type (Uns : Entity_Id; Siz : Nat); 89 -- Procedure to build standard predefined unsigned integer subtype. These 90 -- subtypes are not user visible, but they are used internally. The first 91 -- parameter is the entity for the subtype. The second parameter is the 92 -- size in bits. 93 94 procedure Copy_Float_Type (To : Entity_Id; From : Entity_Id); 95 -- Build a floating point type, copying representation details from From. 96 -- This is used to create predefined floating point types based on 97 -- available types in the back end. 98 99 procedure Create_Operators; 100 -- Make entries for each of the predefined operators in Standard 101 102 procedure Create_Unconstrained_Base_Type 103 (E : Entity_Id; 104 K : Entity_Kind); 105 -- The predefined signed integer types are constrained subtypes which 106 -- must have a corresponding unconstrained base type. This type is almost 107 -- useless. The only place it has semantics is Subtypes_Statically_Match. 108 -- Consequently, we arrange for it to be identical apart from the setting 109 -- of the constrained bit. This routine takes an entity E for the Type, 110 -- copies it to estabish the base type, then resets the Ekind of the 111 -- original entity to K (the Ekind for the subtype). The Etype field of 112 -- E is set by the call (to point to the created base type entity), and 113 -- also the Is_Constrained flag of E is set. 114 -- 115 -- To understand the exact requirement for this, see RM 3.5.4(11) which 116 -- makes it clear that Integer, for example, is constrained, with the 117 -- constraint bounds matching the bounds of the (unconstrained) base 118 -- type. The point is that Integer and Integer'Base have identical 119 -- bounds, but do not statically match, since a subtype with constraints 120 -- never matches a subtype with no constraints. 121 122 function Find_Back_End_Float_Type (Name : String) return Entity_Id; 123 -- Return the first float type in Back_End_Float_Types with the given name. 124 -- Names of entities in back end types, are either type names of C 125 -- predefined types (all lower case), or mode names (upper case). 126 -- These are not generally valid identifier names. 127 128 function Identifier_For (S : Standard_Entity_Type) return Node_Id; 129 -- Returns an identifier node with the same name as the defining identifier 130 -- corresponding to the given Standard_Entity_Type value. 131 132 procedure Make_Component 133 (Rec : Entity_Id; 134 Typ : Entity_Id; 135 Nam : String); 136 -- Build a record component with the given type and name, and append to 137 -- the list of components of Rec. 138 139 function Make_Formal (Typ : Entity_Id; Nam : String) return Entity_Id; 140 -- Construct entity for subprogram formal with given name and type 141 142 function Make_Integer (V : Uint) return Node_Id; 143 -- Builds integer literal with given value 144 145 function New_Operator (Op : Name_Id; Typ : Entity_Id) return Entity_Id; 146 -- Build entity for standard operator with given name and type 147 148 function New_Standard_Entity 149 (New_Node_Kind : Node_Kind := N_Defining_Identifier) return Entity_Id; 150 -- Builds a new entity for Standard 151 152 function New_Standard_Entity (Nam : String) return Entity_Id; 153 -- Builds a new entity for Standard with Nkind = N_Defining_Identifier, 154 -- and Chars of this defining identifier set to the given string Nam. 155 156 procedure Print_Standard; 157 -- Print representation of package Standard if switch set 158 159 procedure Register_Float_Type 160 (Name : String; 161 Digs : Positive; 162 Float_Rep : Float_Rep_Kind; 163 Precision : Positive; 164 Size : Positive; 165 Alignment : Natural); 166 -- Registers a single back end floating-point type (from FPT_Mode_Table in 167 -- Set_Targ). This will create a predefined floating-point base type for 168 -- one of the floating point types reported by the back end, and add it 169 -- to the list of predefined float types. Name is the name of the type 170 -- as a normal format (non-null-terminated) string. Digs is the number of 171 -- digits, which is always non-zero, since non-floating-point types were 172 -- filtered out earlier. Float_Rep indicates the kind of floating-point 173 -- type, and Precision, Size and Alignment are the precision, size and 174 -- alignment in bits. 175 176 procedure Set_Integer_Bounds 177 (Id : Entity_Id; 178 Typ : Entity_Id; 179 Lb : Uint; 180 Hb : Uint); 181 -- Procedure to set bounds for integer type or subtype. Id is the entity 182 -- whose bounds and type are to be set. The Typ parameter is the Etype 183 -- value for the entity (which will be the same as Id for all predefined 184 -- integer base types. The third and fourth parameters are the bounds. 185 186 ---------------------- 187 -- Build_Float_Type -- 188 ---------------------- 189 190 procedure Build_Float_Type 191 (E : Entity_Id; 192 Digs : Int; 193 Rep : Float_Rep_Kind; 194 Siz : Int; 195 Align : Int) 196 is 197 begin 198 Set_Type_Definition (Parent (E), 199 Make_Floating_Point_Definition (Stloc, 200 Digits_Expression => Make_Integer (UI_From_Int (Digs)))); 201 202 Set_Ekind (E, E_Floating_Point_Type); 203 Set_Etype (E, E); 204 Init_Digits_Value (E, Digs); 205 Set_Float_Rep (E, Rep); 206 Init_Size (E, Siz); 207 Set_Elem_Alignment (E, Align); 208 Set_Float_Bounds (E); 209 Set_Is_Frozen (E); 210 Set_Is_Public (E); 211 Set_Size_Known_At_Compile_Time (E); 212 end Build_Float_Type; 213 214 ------------------------------ 215 -- Find_Back_End_Float_Type -- 216 ------------------------------ 217 218 function Find_Back_End_Float_Type (Name : String) return Entity_Id is 219 N : Elmt_Id; 220 221 begin 222 N := First_Elmt (Back_End_Float_Types); 223 while Present (N) and then Get_Name_String (Chars (Node (N))) /= Name 224 loop 225 Next_Elmt (N); 226 end loop; 227 228 return Node (N); 229 end Find_Back_End_Float_Type; 230 231 ------------------------------- 232 -- Build_Signed_Integer_Type -- 233 ------------------------------- 234 235 procedure Build_Signed_Integer_Type (E : Entity_Id; Siz : Nat) is 236 U2Siz1 : constant Uint := 2 ** (Siz - 1); 237 Lbound : constant Uint := -U2Siz1; 238 Ubound : constant Uint := U2Siz1 - 1; 239 240 begin 241 Set_Type_Definition (Parent (E), 242 Make_Signed_Integer_Type_Definition (Stloc, 243 Low_Bound => Make_Integer (Lbound), 244 High_Bound => Make_Integer (Ubound))); 245 246 Set_Ekind (E, E_Signed_Integer_Type); 247 Set_Etype (E, E); 248 Init_Size (E, Siz); 249 Set_Elem_Alignment (E); 250 Set_Integer_Bounds (E, E, Lbound, Ubound); 251 Set_Is_Frozen (E); 252 Set_Is_Public (E); 253 Set_Is_Known_Valid (E); 254 Set_Size_Known_At_Compile_Time (E); 255 end Build_Signed_Integer_Type; 256 257 --------------------------------- 258 -- Build_Unsigned_Integer_Type -- 259 --------------------------------- 260 261 procedure Build_Unsigned_Integer_Type 262 (Uns : Entity_Id; 263 Siz : Nat) 264 is 265 Decl : constant Node_Id := New_Node (N_Full_Type_Declaration, Stloc); 266 R_Node : constant Node_Id := New_Node (N_Range, Stloc); 267 268 begin 269 Set_Defining_Identifier (Decl, Uns); 270 271 Set_Ekind (Uns, E_Modular_Integer_Type); 272 Set_Scope (Uns, Standard_Standard); 273 Set_Etype (Uns, Uns); 274 Init_Size (Uns, Siz); 275 Set_Elem_Alignment (Uns); 276 Set_Modulus (Uns, Uint_2 ** Siz); 277 Set_Is_Unsigned_Type (Uns); 278 Set_Size_Known_At_Compile_Time (Uns); 279 Set_Is_Known_Valid (Uns, True); 280 281 Set_Low_Bound (R_Node, Make_Integer (Uint_0)); 282 Set_High_Bound (R_Node, Make_Integer (Modulus (Uns) - 1)); 283 Set_Etype (Low_Bound (R_Node), Uns); 284 Set_Etype (High_Bound (R_Node), Uns); 285 Set_Scalar_Range (Uns, R_Node); 286 end Build_Unsigned_Integer_Type; 287 288 --------------------- 289 -- Copy_Float_Type -- 290 --------------------- 291 292 procedure Copy_Float_Type (To : Entity_Id; From : Entity_Id) is 293 begin 294 Build_Float_Type 295 (To, UI_To_Int (Digits_Value (From)), Float_Rep (From), 296 UI_To_Int (Esize (From)), UI_To_Int (Alignment (From))); 297 end Copy_Float_Type; 298 299 ---------------------- 300 -- Create_Operators -- 301 ---------------------- 302 303 -- Each operator has an abbreviated signature. The formals have the names 304 -- LEFT and RIGHT. Their types are not actually used for resolution. 305 306 procedure Create_Operators is 307 Op_Node : Entity_Id; 308 309 -- The following tables define the binary and unary operators and their 310 -- corresponding result type. 311 312 Binary_Ops : constant array (S_Binary_Ops) of Name_Id := 313 314 -- There is one entry here for each binary operator, except for the 315 -- case of concatenation, where there are three entries, one for a 316 -- String result, one for Wide_String, and one for Wide_Wide_String. 317 318 (Name_Op_Add, 319 Name_Op_And, 320 Name_Op_Concat, 321 Name_Op_Concat, 322 Name_Op_Concat, 323 Name_Op_Divide, 324 Name_Op_Eq, 325 Name_Op_Expon, 326 Name_Op_Ge, 327 Name_Op_Gt, 328 Name_Op_Le, 329 Name_Op_Lt, 330 Name_Op_Mod, 331 Name_Op_Multiply, 332 Name_Op_Ne, 333 Name_Op_Or, 334 Name_Op_Rem, 335 Name_Op_Subtract, 336 Name_Op_Xor); 337 338 Bin_Op_Types : constant array (S_Binary_Ops) of Entity_Id := 339 340 -- This table has the corresponding result types. The entries are 341 -- ordered so they correspond to the Binary_Ops array above. 342 343 (Universal_Integer, -- Add 344 Standard_Boolean, -- And 345 Standard_String, -- Concat (String) 346 Standard_Wide_String, -- Concat (Wide_String) 347 Standard_Wide_Wide_String, -- Concat (Wide_Wide_String) 348 Universal_Integer, -- Divide 349 Standard_Boolean, -- Eq 350 Universal_Integer, -- Expon 351 Standard_Boolean, -- Ge 352 Standard_Boolean, -- Gt 353 Standard_Boolean, -- Le 354 Standard_Boolean, -- Lt 355 Universal_Integer, -- Mod 356 Universal_Integer, -- Multiply 357 Standard_Boolean, -- Ne 358 Standard_Boolean, -- Or 359 Universal_Integer, -- Rem 360 Universal_Integer, -- Subtract 361 Standard_Boolean); -- Xor 362 363 Unary_Ops : constant array (S_Unary_Ops) of Name_Id := 364 365 -- There is one entry here for each unary operator 366 367 (Name_Op_Abs, 368 Name_Op_Subtract, 369 Name_Op_Not, 370 Name_Op_Add); 371 372 Unary_Op_Types : constant array (S_Unary_Ops) of Entity_Id := 373 374 -- This table has the corresponding result types. The entries are 375 -- ordered so they correspond to the Unary_Ops array above. 376 377 (Universal_Integer, -- Abs 378 Universal_Integer, -- Subtract 379 Standard_Boolean, -- Not 380 Universal_Integer); -- Add 381 382 begin 383 for J in S_Binary_Ops loop 384 Op_Node := New_Operator (Binary_Ops (J), Bin_Op_Types (J)); 385 SE (J) := Op_Node; 386 Append_Entity (Make_Formal (Any_Type, "LEFT"), Op_Node); 387 Append_Entity (Make_Formal (Any_Type, "RIGHT"), Op_Node); 388 end loop; 389 390 for J in S_Unary_Ops loop 391 Op_Node := New_Operator (Unary_Ops (J), Unary_Op_Types (J)); 392 SE (J) := Op_Node; 393 Append_Entity (Make_Formal (Any_Type, "RIGHT"), Op_Node); 394 end loop; 395 396 -- For concatenation, we create a separate operator for each 397 -- array type. This simplifies the resolution of the component- 398 -- component concatenation operation. In Standard, we set the types 399 -- of the formals for string, wide [wide]_string, concatenations. 400 401 Set_Etype (First_Entity (Standard_Op_Concat), Standard_String); 402 Set_Etype (Last_Entity (Standard_Op_Concat), Standard_String); 403 404 Set_Etype (First_Entity (Standard_Op_Concatw), Standard_Wide_String); 405 Set_Etype (Last_Entity (Standard_Op_Concatw), Standard_Wide_String); 406 407 Set_Etype (First_Entity (Standard_Op_Concatww), 408 Standard_Wide_Wide_String); 409 410 Set_Etype (Last_Entity (Standard_Op_Concatww), 411 Standard_Wide_Wide_String); 412 end Create_Operators; 413 414 --------------------- 415 -- Create_Standard -- 416 --------------------- 417 418 -- The tree for the package Standard is prefixed to all compilations. 419 -- Several entities required by semantic analysis are denoted by global 420 -- variables that are initialized to point to the corresponding occurrences 421 -- in Standard. The visible entities of Standard are created here. Special 422 -- entities maybe created here as well or may be created from the semantics 423 -- module. By not adding them to the Decls list of Standard they will not 424 -- be visible to Ada programs. 425 426 procedure Create_Standard is 427 Decl_S : constant List_Id := New_List; 428 -- List of declarations in Standard 429 430 Decl_A : constant List_Id := New_List; 431 -- List of declarations in ASCII 432 433 Decl : Node_Id; 434 Pspec : Node_Id; 435 Tdef_Node : Node_Id; 436 Ident_Node : Node_Id; 437 Ccode : Char_Code; 438 E_Id : Entity_Id; 439 R_Node : Node_Id; 440 B_Node : Node_Id; 441 442 procedure Build_Exception (S : Standard_Entity_Type); 443 -- Procedure to declare given entity as an exception 444 445 procedure Create_Back_End_Float_Types; 446 -- Initialize the Back_End_Float_Types list by having the back end 447 -- enumerate all available types and building type entities for them. 448 449 procedure Create_Float_Types; 450 -- Creates entities for all predefined floating point types, and 451 -- adds these to the Predefined_Float_Types list in package Standard. 452 453 procedure Make_Dummy_Index (E : Entity_Id); 454 -- Called to provide a dummy index field value for Any_Array/Any_String 455 456 procedure Pack_String_Type (String_Type : Entity_Id); 457 -- Generate proper tree for pragma Pack that applies to given type, and 458 -- mark type as having the pragma. 459 460 --------------------- 461 -- Build_Exception -- 462 --------------------- 463 464 procedure Build_Exception (S : Standard_Entity_Type) is 465 begin 466 Set_Ekind (Standard_Entity (S), E_Exception); 467 Set_Etype (Standard_Entity (S), Standard_Exception_Type); 468 Set_Is_Public (Standard_Entity (S), True); 469 470 Decl := 471 Make_Exception_Declaration (Stloc, 472 Defining_Identifier => Standard_Entity (S)); 473 Append (Decl, Decl_S); 474 end Build_Exception; 475 476 --------------------------------- 477 -- Create_Back_End_Float_Types -- 478 --------------------------------- 479 480 procedure Create_Back_End_Float_Types is 481 begin 482 for J in 1 .. Num_FPT_Modes loop 483 declare 484 E : FPT_Mode_Entry renames FPT_Mode_Table (J); 485 begin 486 Register_Float_Type 487 (E.NAME.all, E.DIGS, E.FLOAT_REP, E.PRECISION, E.SIZE, 488 E.ALIGNMENT); 489 end; 490 end loop; 491 end Create_Back_End_Float_Types; 492 493 ------------------------ 494 -- Create_Float_Types -- 495 ------------------------ 496 497 procedure Create_Float_Types is 498 begin 499 -- Create type definition nodes for predefined float types 500 501 Copy_Float_Type 502 (Standard_Short_Float, 503 Find_Back_End_Float_Type (C_Type_For (S_Short_Float))); 504 Set_Is_Implementation_Defined (Standard_Short_Float); 505 506 Copy_Float_Type (Standard_Float, Standard_Short_Float); 507 508 Copy_Float_Type 509 (Standard_Long_Float, 510 Find_Back_End_Float_Type (C_Type_For (S_Long_Float))); 511 512 Copy_Float_Type 513 (Standard_Long_Long_Float, 514 Find_Back_End_Float_Type (C_Type_For (S_Long_Long_Float))); 515 Set_Is_Implementation_Defined (Standard_Long_Long_Float); 516 517 Predefined_Float_Types := New_Elmt_List; 518 519 Append_Elmt (Standard_Short_Float, Predefined_Float_Types); 520 Append_Elmt (Standard_Float, Predefined_Float_Types); 521 Append_Elmt (Standard_Long_Float, Predefined_Float_Types); 522 Append_Elmt (Standard_Long_Long_Float, Predefined_Float_Types); 523 524 -- Any other back end types are appended at the end of the list of 525 -- predefined float types, and will only be selected if the none of 526 -- the types in Standard is suitable, or if a specific named type is 527 -- requested through a pragma Import. 528 529 while not Is_Empty_Elmt_List (Back_End_Float_Types) loop 530 declare 531 E : constant Elmt_Id := First_Elmt (Back_End_Float_Types); 532 begin 533 Append_Elmt (Node (E), To => Predefined_Float_Types); 534 Remove_Elmt (Back_End_Float_Types, E); 535 end; 536 end loop; 537 end Create_Float_Types; 538 539 ---------------------- 540 -- Make_Dummy_Index -- 541 ---------------------- 542 543 procedure Make_Dummy_Index (E : Entity_Id) is 544 Index : constant Node_Id := 545 Make_Range (Sloc (E), 546 Low_Bound => Make_Integer (Uint_0), 547 High_Bound => Make_Integer (Uint_2 ** Standard_Integer_Size)); 548 549 -- Make sure Index is a list as required, so Next_Index is Empty 550 551 Dummy : constant List_Id := New_List (Index); 552 553 begin 554 Set_Etype (Index, Standard_Integer); 555 Set_First_Index (E, Index); 556 end Make_Dummy_Index; 557 558 ---------------------- 559 -- Pack_String_Type -- 560 ---------------------- 561 562 procedure Pack_String_Type (String_Type : Entity_Id) is 563 Prag : constant Node_Id := 564 Make_Pragma (Stloc, 565 Chars => Name_Pack, 566 Pragma_Argument_Associations => 567 New_List ( 568 Make_Pragma_Argument_Association (Stloc, 569 Expression => New_Occurrence_Of (String_Type, Stloc)))); 570 571 begin 572 Append (Prag, Decl_S); 573 Record_Rep_Item (String_Type, Prag); 574 Set_Has_Pragma_Pack (String_Type, True); 575 end Pack_String_Type; 576 577 -- Start of processing for Create_Standard 578 579 begin 580 -- First step is to create defining identifiers for each entity 581 582 for S in Standard_Entity_Type loop 583 declare 584 S_Name : constant String := Standard_Entity_Type'Image (S); 585 -- Name of entity (note we skip S_ at the start) 586 587 Ident_Node : Node_Id; 588 -- Defining identifier node 589 590 begin 591 Ident_Node := New_Standard_Entity (S_Name (3 .. S_Name'Length)); 592 Standard_Entity (S) := Ident_Node; 593 end; 594 end loop; 595 596 -- Create package declaration node for package Standard 597 598 Standard_Package_Node := New_Node (N_Package_Declaration, Stloc); 599 600 Pspec := New_Node (N_Package_Specification, Stloc); 601 Set_Specification (Standard_Package_Node, Pspec); 602 603 Set_Defining_Unit_Name (Pspec, Standard_Standard); 604 Set_Visible_Declarations (Pspec, Decl_S); 605 606 Set_Ekind (Standard_Standard, E_Package); 607 Set_Is_Pure (Standard_Standard); 608 Set_Is_Compilation_Unit (Standard_Standard); 609 610 -- Create type/subtype declaration nodes for standard types 611 612 for S in S_Types loop 613 614 -- Subtype declaration case 615 616 if S = S_Natural or else S = S_Positive then 617 Decl := New_Node (N_Subtype_Declaration, Stloc); 618 Set_Subtype_Indication (Decl, 619 New_Occurrence_Of (Standard_Integer, Stloc)); 620 621 -- Full type declaration case 622 623 else 624 Decl := New_Node (N_Full_Type_Declaration, Stloc); 625 end if; 626 627 Set_Is_Frozen (Standard_Entity (S)); 628 Set_Is_Public (Standard_Entity (S)); 629 Set_Defining_Identifier (Decl, Standard_Entity (S)); 630 Append (Decl, Decl_S); 631 end loop; 632 633 Create_Back_End_Float_Types; 634 635 -- Create type definition node for type Boolean. The Size is set to 636 -- 1 as required by Ada 95 and current ARG interpretations for Ada/83. 637 638 -- Note: Object_Size of Boolean is 8. This means that we do NOT in 639 -- general know that Boolean variables have valid values, so we do 640 -- not set the Is_Known_Valid flag. 641 642 Tdef_Node := New_Node (N_Enumeration_Type_Definition, Stloc); 643 Set_Literals (Tdef_Node, New_List); 644 Append (Standard_False, Literals (Tdef_Node)); 645 Append (Standard_True, Literals (Tdef_Node)); 646 Set_Type_Definition (Parent (Standard_Boolean), Tdef_Node); 647 648 Set_Ekind (Standard_Boolean, E_Enumeration_Type); 649 Set_First_Literal (Standard_Boolean, Standard_False); 650 Set_Etype (Standard_Boolean, Standard_Boolean); 651 Init_Esize (Standard_Boolean, Standard_Character_Size); 652 Init_RM_Size (Standard_Boolean, 1); 653 Set_Elem_Alignment (Standard_Boolean); 654 655 Set_Is_Unsigned_Type (Standard_Boolean); 656 Set_Size_Known_At_Compile_Time (Standard_Boolean); 657 Set_Has_Pragma_Ordered (Standard_Boolean); 658 659 Set_Ekind (Standard_True, E_Enumeration_Literal); 660 Set_Etype (Standard_True, Standard_Boolean); 661 Set_Enumeration_Pos (Standard_True, Uint_1); 662 Set_Enumeration_Rep (Standard_True, Uint_1); 663 Set_Is_Known_Valid (Standard_True, True); 664 665 Set_Ekind (Standard_False, E_Enumeration_Literal); 666 Set_Etype (Standard_False, Standard_Boolean); 667 Set_Enumeration_Pos (Standard_False, Uint_0); 668 Set_Enumeration_Rep (Standard_False, Uint_0); 669 Set_Is_Known_Valid (Standard_False, True); 670 671 -- For the bounds of Boolean, we create a range node corresponding to 672 673 -- range False .. True 674 675 -- where the occurrences of the literals must point to the 676 -- corresponding definition. 677 678 R_Node := New_Node (N_Range, Stloc); 679 B_Node := New_Node (N_Identifier, Stloc); 680 Set_Chars (B_Node, Chars (Standard_False)); 681 Set_Entity (B_Node, Standard_False); 682 Set_Etype (B_Node, Standard_Boolean); 683 Set_Is_Static_Expression (B_Node); 684 Set_Low_Bound (R_Node, B_Node); 685 686 B_Node := New_Node (N_Identifier, Stloc); 687 Set_Chars (B_Node, Chars (Standard_True)); 688 Set_Entity (B_Node, Standard_True); 689 Set_Etype (B_Node, Standard_Boolean); 690 Set_Is_Static_Expression (B_Node); 691 Set_High_Bound (R_Node, B_Node); 692 693 Set_Scalar_Range (Standard_Boolean, R_Node); 694 Set_Etype (R_Node, Standard_Boolean); 695 Set_Parent (R_Node, Standard_Boolean); 696 697 -- Record entity identifiers for boolean literals in the 698 -- Boolean_Literals array, for easy reference during expansion. 699 700 Boolean_Literals := (False => Standard_False, True => Standard_True); 701 702 -- Create type definition nodes for predefined integer types 703 704 Build_Signed_Integer_Type 705 (Standard_Short_Short_Integer, Standard_Short_Short_Integer_Size); 706 Set_Is_Implementation_Defined (Standard_Short_Short_Integer); 707 708 Build_Signed_Integer_Type 709 (Standard_Short_Integer, Standard_Short_Integer_Size); 710 Set_Is_Implementation_Defined (Standard_Short_Integer); 711 712 Build_Signed_Integer_Type 713 (Standard_Integer, Standard_Integer_Size); 714 715 Build_Signed_Integer_Type 716 (Standard_Long_Integer, Standard_Long_Integer_Size); 717 718 Build_Signed_Integer_Type 719 (Standard_Long_Long_Integer, Standard_Long_Long_Integer_Size); 720 Set_Is_Implementation_Defined (Standard_Long_Long_Integer); 721 722 Build_Signed_Integer_Type 723 (Standard_Long_Long_Long_Integer, 724 Standard_Long_Long_Long_Integer_Size); 725 Set_Is_Implementation_Defined (Standard_Long_Long_Long_Integer); 726 727 Create_Unconstrained_Base_Type 728 (Standard_Short_Short_Integer, E_Signed_Integer_Subtype); 729 730 Create_Unconstrained_Base_Type 731 (Standard_Short_Integer, E_Signed_Integer_Subtype); 732 733 Create_Unconstrained_Base_Type 734 (Standard_Integer, E_Signed_Integer_Subtype); 735 736 Create_Unconstrained_Base_Type 737 (Standard_Long_Integer, E_Signed_Integer_Subtype); 738 739 Create_Unconstrained_Base_Type 740 (Standard_Long_Long_Integer, E_Signed_Integer_Subtype); 741 742 Create_Unconstrained_Base_Type 743 (Standard_Long_Long_Long_Integer, E_Signed_Integer_Subtype); 744 745 Create_Float_Types; 746 747 -- Create type definition node for type Character. Note that we do not 748 -- set the Literals field, since type Character is handled with special 749 -- routine that do not need a literal list. 750 751 Tdef_Node := New_Node (N_Enumeration_Type_Definition, Stloc); 752 Set_Type_Definition (Parent (Standard_Character), Tdef_Node); 753 754 Set_Ekind (Standard_Character, E_Enumeration_Type); 755 Set_Etype (Standard_Character, Standard_Character); 756 Init_Esize (Standard_Character, Standard_Character_Size); 757 Init_RM_Size (Standard_Character, 8); 758 Set_Elem_Alignment (Standard_Character); 759 760 Set_Has_Pragma_Ordered (Standard_Character); 761 Set_Is_Unsigned_Type (Standard_Character); 762 Set_Is_Character_Type (Standard_Character); 763 Set_Is_Known_Valid (Standard_Character); 764 Set_Size_Known_At_Compile_Time (Standard_Character); 765 766 -- Create the bounds for type Character 767 768 R_Node := New_Node (N_Range, Stloc); 769 770 -- Low bound for type Character (Standard.Nul) 771 772 B_Node := New_Node (N_Character_Literal, Stloc); 773 Set_Is_Static_Expression (B_Node); 774 Set_Chars (B_Node, No_Name); 775 Set_Char_Literal_Value (B_Node, Uint_0); 776 Set_Entity (B_Node, Empty); 777 Set_Etype (B_Node, Standard_Character); 778 Set_Low_Bound (R_Node, B_Node); 779 780 -- High bound for type Character 781 782 B_Node := New_Node (N_Character_Literal, Stloc); 783 Set_Is_Static_Expression (B_Node); 784 Set_Chars (B_Node, No_Name); 785 Set_Char_Literal_Value (B_Node, UI_From_Int (16#FF#)); 786 Set_Entity (B_Node, Empty); 787 Set_Etype (B_Node, Standard_Character); 788 Set_High_Bound (R_Node, B_Node); 789 790 Set_Scalar_Range (Standard_Character, R_Node); 791 Set_Etype (R_Node, Standard_Character); 792 Set_Parent (R_Node, Standard_Character); 793 794 -- Create type definition for type Wide_Character. Note that we do not 795 -- set the Literals field, since type Wide_Character is handled with 796 -- special routines that do not need a literal list. 797 798 Tdef_Node := New_Node (N_Enumeration_Type_Definition, Stloc); 799 Set_Type_Definition (Parent (Standard_Wide_Character), Tdef_Node); 800 801 Set_Ekind (Standard_Wide_Character, E_Enumeration_Type); 802 Set_Etype (Standard_Wide_Character, Standard_Wide_Character); 803 Init_Size (Standard_Wide_Character, Standard_Wide_Character_Size); 804 805 Set_Elem_Alignment (Standard_Wide_Character); 806 Set_Has_Pragma_Ordered (Standard_Wide_Character); 807 Set_Is_Unsigned_Type (Standard_Wide_Character); 808 Set_Is_Character_Type (Standard_Wide_Character); 809 Set_Is_Known_Valid (Standard_Wide_Character); 810 Set_Size_Known_At_Compile_Time (Standard_Wide_Character); 811 812 -- Create the bounds for type Wide_Character 813 814 R_Node := New_Node (N_Range, Stloc); 815 816 -- Low bound for type Wide_Character 817 818 B_Node := New_Node (N_Character_Literal, Stloc); 819 Set_Is_Static_Expression (B_Node); 820 Set_Chars (B_Node, No_Name); -- ??? 821 Set_Char_Literal_Value (B_Node, Uint_0); 822 Set_Entity (B_Node, Empty); 823 Set_Etype (B_Node, Standard_Wide_Character); 824 Set_Low_Bound (R_Node, B_Node); 825 826 -- High bound for type Wide_Character 827 828 B_Node := New_Node (N_Character_Literal, Stloc); 829 Set_Is_Static_Expression (B_Node); 830 Set_Chars (B_Node, No_Name); -- ??? 831 Set_Char_Literal_Value (B_Node, UI_From_Int (16#FFFF#)); 832 Set_Entity (B_Node, Empty); 833 Set_Etype (B_Node, Standard_Wide_Character); 834 Set_High_Bound (R_Node, B_Node); 835 836 Set_Scalar_Range (Standard_Wide_Character, R_Node); 837 Set_Etype (R_Node, Standard_Wide_Character); 838 Set_Parent (R_Node, Standard_Wide_Character); 839 840 -- Create type definition for type Wide_Wide_Character. Note that we 841 -- do not set the Literals field, since type Wide_Wide_Character is 842 -- handled with special routines that do not need a literal list. 843 844 Tdef_Node := New_Node (N_Enumeration_Type_Definition, Stloc); 845 Set_Type_Definition (Parent (Standard_Wide_Wide_Character), Tdef_Node); 846 847 Set_Ekind (Standard_Wide_Wide_Character, E_Enumeration_Type); 848 Set_Etype (Standard_Wide_Wide_Character, 849 Standard_Wide_Wide_Character); 850 Init_Size (Standard_Wide_Wide_Character, 851 Standard_Wide_Wide_Character_Size); 852 853 Set_Elem_Alignment (Standard_Wide_Wide_Character); 854 Set_Has_Pragma_Ordered (Standard_Wide_Wide_Character); 855 Set_Is_Unsigned_Type (Standard_Wide_Wide_Character); 856 Set_Is_Character_Type (Standard_Wide_Wide_Character); 857 Set_Is_Known_Valid (Standard_Wide_Wide_Character); 858 Set_Size_Known_At_Compile_Time (Standard_Wide_Wide_Character); 859 Set_Is_Ada_2005_Only (Standard_Wide_Wide_Character); 860 861 -- Create the bounds for type Wide_Wide_Character 862 863 R_Node := New_Node (N_Range, Stloc); 864 865 -- Low bound for type Wide_Wide_Character 866 867 B_Node := New_Node (N_Character_Literal, Stloc); 868 Set_Is_Static_Expression (B_Node); 869 Set_Chars (B_Node, No_Name); -- ??? 870 Set_Char_Literal_Value (B_Node, Uint_0); 871 Set_Entity (B_Node, Empty); 872 Set_Etype (B_Node, Standard_Wide_Wide_Character); 873 Set_Low_Bound (R_Node, B_Node); 874 875 -- High bound for type Wide_Wide_Character 876 877 B_Node := New_Node (N_Character_Literal, Stloc); 878 Set_Is_Static_Expression (B_Node); 879 Set_Chars (B_Node, No_Name); -- ??? 880 Set_Char_Literal_Value (B_Node, UI_From_Int (16#7FFF_FFFF#)); 881 Set_Entity (B_Node, Empty); 882 Set_Etype (B_Node, Standard_Wide_Wide_Character); 883 Set_High_Bound (R_Node, B_Node); 884 885 Set_Scalar_Range (Standard_Wide_Wide_Character, R_Node); 886 Set_Etype (R_Node, Standard_Wide_Wide_Character); 887 Set_Parent (R_Node, Standard_Wide_Wide_Character); 888 889 -- Create type definition node for type String 890 891 Tdef_Node := New_Node (N_Unconstrained_Array_Definition, Stloc); 892 893 declare 894 CompDef_Node : Node_Id; 895 begin 896 CompDef_Node := New_Node (N_Component_Definition, Stloc); 897 Set_Aliased_Present (CompDef_Node, False); 898 Set_Access_Definition (CompDef_Node, Empty); 899 Set_Subtype_Indication (CompDef_Node, Identifier_For (S_Character)); 900 Set_Component_Definition (Tdef_Node, CompDef_Node); 901 end; 902 903 Set_Subtype_Marks (Tdef_Node, New_List); 904 Append (Identifier_For (S_Positive), Subtype_Marks (Tdef_Node)); 905 Set_Type_Definition (Parent (Standard_String), Tdef_Node); 906 907 Set_Ekind (Standard_String, E_Array_Type); 908 Set_Etype (Standard_String, Standard_String); 909 Set_Component_Type (Standard_String, Standard_Character); 910 Set_Component_Size (Standard_String, Uint_8); 911 Init_Size_Align (Standard_String); 912 Set_Alignment (Standard_String, Uint_1); 913 Pack_String_Type (Standard_String); 914 915 -- On targets where a storage unit is larger than a byte (such as AAMP), 916 -- pragma Pack has a real effect on the representation of type String, 917 -- and the type must be marked as having a nonstandard representation. 918 919 if System_Storage_Unit > Uint_8 then 920 Set_Has_Non_Standard_Rep (Standard_String); 921 Set_Has_Pragma_Pack (Standard_String); 922 end if; 923 924 -- Set index type of String 925 926 E_Id := 927 First (Subtype_Marks (Type_Definition (Parent (Standard_String)))); 928 Set_First_Index (Standard_String, E_Id); 929 Set_Entity (E_Id, Standard_Positive); 930 Set_Etype (E_Id, Standard_Positive); 931 932 -- Create type definition node for type Wide_String 933 934 Tdef_Node := New_Node (N_Unconstrained_Array_Definition, Stloc); 935 936 declare 937 CompDef_Node : Node_Id; 938 begin 939 CompDef_Node := New_Node (N_Component_Definition, Stloc); 940 Set_Aliased_Present (CompDef_Node, False); 941 Set_Access_Definition (CompDef_Node, Empty); 942 Set_Subtype_Indication (CompDef_Node, 943 Identifier_For (S_Wide_Character)); 944 Set_Component_Definition (Tdef_Node, CompDef_Node); 945 end; 946 947 Set_Subtype_Marks (Tdef_Node, New_List); 948 Append (Identifier_For (S_Positive), Subtype_Marks (Tdef_Node)); 949 Set_Type_Definition (Parent (Standard_Wide_String), Tdef_Node); 950 951 Set_Ekind (Standard_Wide_String, E_Array_Type); 952 Set_Etype (Standard_Wide_String, Standard_Wide_String); 953 Set_Component_Type (Standard_Wide_String, Standard_Wide_Character); 954 Set_Component_Size (Standard_Wide_String, Uint_16); 955 Init_Size_Align (Standard_Wide_String); 956 Pack_String_Type (Standard_Wide_String); 957 958 -- Set index type of Wide_String 959 960 E_Id := 961 First 962 (Subtype_Marks (Type_Definition (Parent (Standard_Wide_String)))); 963 Set_First_Index (Standard_Wide_String, E_Id); 964 Set_Entity (E_Id, Standard_Positive); 965 Set_Etype (E_Id, Standard_Positive); 966 967 -- Create type definition node for type Wide_Wide_String 968 969 Tdef_Node := New_Node (N_Unconstrained_Array_Definition, Stloc); 970 971 declare 972 CompDef_Node : Node_Id; 973 begin 974 CompDef_Node := New_Node (N_Component_Definition, Stloc); 975 Set_Aliased_Present (CompDef_Node, False); 976 Set_Access_Definition (CompDef_Node, Empty); 977 Set_Subtype_Indication (CompDef_Node, 978 Identifier_For (S_Wide_Wide_Character)); 979 Set_Component_Definition (Tdef_Node, CompDef_Node); 980 end; 981 982 Set_Subtype_Marks (Tdef_Node, New_List); 983 Append (Identifier_For (S_Positive), Subtype_Marks (Tdef_Node)); 984 Set_Type_Definition (Parent (Standard_Wide_Wide_String), Tdef_Node); 985 986 Set_Ekind (Standard_Wide_Wide_String, E_Array_Type); 987 Set_Etype (Standard_Wide_Wide_String, 988 Standard_Wide_Wide_String); 989 Set_Component_Type (Standard_Wide_Wide_String, 990 Standard_Wide_Wide_Character); 991 Set_Component_Size (Standard_Wide_Wide_String, Uint_32); 992 Init_Size_Align (Standard_Wide_Wide_String); 993 Set_Is_Ada_2005_Only (Standard_Wide_Wide_String); 994 Pack_String_Type (Standard_Wide_Wide_String); 995 996 -- Set index type of Wide_Wide_String 997 998 E_Id := 999 First 1000 (Subtype_Marks 1001 (Type_Definition (Parent (Standard_Wide_Wide_String)))); 1002 Set_First_Index (Standard_Wide_Wide_String, E_Id); 1003 Set_Entity (E_Id, Standard_Positive); 1004 Set_Etype (E_Id, Standard_Positive); 1005 1006 -- Setup entity for Natural 1007 1008 Set_Ekind (Standard_Natural, E_Signed_Integer_Subtype); 1009 Set_Etype (Standard_Natural, Base_Type (Standard_Integer)); 1010 Init_Esize (Standard_Natural, Standard_Integer_Size); 1011 Init_RM_Size (Standard_Natural, Standard_Integer_Size - 1); 1012 Set_Elem_Alignment (Standard_Natural); 1013 Set_Size_Known_At_Compile_Time 1014 (Standard_Natural); 1015 Set_Integer_Bounds (Standard_Natural, 1016 Typ => Base_Type (Standard_Integer), 1017 Lb => Uint_0, 1018 Hb => Intval (High_Bound (Scalar_Range (Standard_Integer)))); 1019 Set_Is_Constrained (Standard_Natural); 1020 1021 -- Setup entity for Positive 1022 1023 Set_Ekind (Standard_Positive, E_Signed_Integer_Subtype); 1024 Set_Etype (Standard_Positive, Base_Type (Standard_Integer)); 1025 Init_Esize (Standard_Positive, Standard_Integer_Size); 1026 Init_RM_Size (Standard_Positive, Standard_Integer_Size - 1); 1027 Set_Elem_Alignment (Standard_Positive); 1028 1029 Set_Size_Known_At_Compile_Time (Standard_Positive); 1030 1031 Set_Integer_Bounds (Standard_Positive, 1032 Typ => Base_Type (Standard_Integer), 1033 Lb => Uint_1, 1034 Hb => Intval (High_Bound (Scalar_Range (Standard_Integer)))); 1035 Set_Is_Constrained (Standard_Positive); 1036 1037 -- Create declaration for package ASCII 1038 1039 Decl := New_Node (N_Package_Declaration, Stloc); 1040 Append (Decl, Decl_S); 1041 1042 Pspec := New_Node (N_Package_Specification, Stloc); 1043 Set_Specification (Decl, Pspec); 1044 1045 Set_Defining_Unit_Name (Pspec, Standard_Entity (S_ASCII)); 1046 Set_Ekind (Standard_Entity (S_ASCII), E_Package); 1047 Set_Visible_Declarations (Pspec, Decl_A); 1048 1049 -- Create control character definitions in package ASCII. Note that 1050 -- the character literal entries created here correspond to literal 1051 -- values that are impossible in the source, but can be represented 1052 -- internally with no difficulties. 1053 1054 Ccode := 16#00#; 1055 1056 for S in S_ASCII_Names loop 1057 Decl := New_Node (N_Object_Declaration, Staloc); 1058 Set_Constant_Present (Decl, True); 1059 1060 declare 1061 A_Char : constant Entity_Id := Standard_Entity (S); 1062 Expr_Decl : Node_Id; 1063 1064 begin 1065 Set_Sloc (A_Char, Staloc); 1066 Set_Ekind (A_Char, E_Constant); 1067 Set_Never_Set_In_Source (A_Char, True); 1068 Set_Is_True_Constant (A_Char, True); 1069 Set_Etype (A_Char, Standard_Character); 1070 Set_Scope (A_Char, Standard_Entity (S_ASCII)); 1071 Set_Is_Immediately_Visible (A_Char, False); 1072 Set_Is_Public (A_Char, True); 1073 Set_Is_Known_Valid (A_Char, True); 1074 1075 Append_Entity (A_Char, Standard_Entity (S_ASCII)); 1076 Set_Defining_Identifier (Decl, A_Char); 1077 1078 Set_Object_Definition (Decl, Identifier_For (S_Character)); 1079 Expr_Decl := New_Node (N_Character_Literal, Staloc); 1080 Set_Expression (Decl, Expr_Decl); 1081 1082 Set_Is_Static_Expression (Expr_Decl); 1083 Set_Chars (Expr_Decl, No_Name); 1084 Set_Etype (Expr_Decl, Standard_Character); 1085 Set_Char_Literal_Value (Expr_Decl, UI_From_Int (Int (Ccode))); 1086 end; 1087 1088 Append (Decl, Decl_A); 1089 1090 -- Increment character code, dealing with non-contiguities 1091 1092 Ccode := Ccode + 1; 1093 1094 if Ccode = 16#20# then 1095 Ccode := 16#21#; 1096 elsif Ccode = 16#27# then 1097 Ccode := 16#3A#; 1098 elsif Ccode = 16#3C# then 1099 Ccode := 16#3F#; 1100 elsif Ccode = 16#41# then 1101 Ccode := 16#5B#; 1102 end if; 1103 end loop; 1104 1105 -- Create semantic phase entities 1106 1107 Standard_Void_Type := New_Standard_Entity ("_void_type"); 1108 Set_Ekind (Standard_Void_Type, E_Void); 1109 Set_Etype (Standard_Void_Type, Standard_Void_Type); 1110 Set_Scope (Standard_Void_Type, Standard_Standard); 1111 1112 -- The type field of packages is set to void 1113 1114 Set_Etype (Standard_Standard, Standard_Void_Type); 1115 Set_Etype (Standard_ASCII, Standard_Void_Type); 1116 1117 -- Standard_A_String is actually used in generated code, so it has a 1118 -- type name that is reasonable, but does not overlap any Ada name. 1119 1120 Standard_A_String := New_Standard_Entity ("access_string"); 1121 Set_Ekind (Standard_A_String, E_Access_Type); 1122 Set_Scope (Standard_A_String, Standard_Standard); 1123 Set_Etype (Standard_A_String, Standard_A_String); 1124 1125 if Debug_Flag_6 then 1126 Init_Size (Standard_A_String, System_Address_Size); 1127 else 1128 Init_Size (Standard_A_String, System_Address_Size * 2); 1129 end if; 1130 1131 Init_Alignment (Standard_A_String); 1132 1133 Set_Directly_Designated_Type 1134 (Standard_A_String, Standard_String); 1135 1136 Standard_A_Char := New_Standard_Entity ("access_character"); 1137 Set_Ekind (Standard_A_Char, E_Access_Type); 1138 Set_Scope (Standard_A_Char, Standard_Standard); 1139 Set_Etype (Standard_A_Char, Standard_A_String); 1140 Init_Size (Standard_A_Char, System_Address_Size); 1141 Set_Elem_Alignment (Standard_A_Char); 1142 1143 Set_Directly_Designated_Type (Standard_A_Char, Standard_Character); 1144 1145 -- Standard_Debug_Renaming_Type is used for the special objects created 1146 -- to encode the names occurring in renaming declarations for use by the 1147 -- debugger (see exp_dbug.adb). The type is a zero-sized subtype of 1148 -- Standard.Integer. 1149 1150 Standard_Debug_Renaming_Type := New_Standard_Entity ("_renaming_type"); 1151 1152 Set_Ekind (Standard_Debug_Renaming_Type, E_Signed_Integer_Subtype); 1153 Set_Scope (Standard_Debug_Renaming_Type, Standard_Standard); 1154 Set_Etype (Standard_Debug_Renaming_Type, Base_Type (Standard_Integer)); 1155 Init_Esize (Standard_Debug_Renaming_Type, 0); 1156 Init_RM_Size (Standard_Debug_Renaming_Type, 0); 1157 Set_Size_Known_At_Compile_Time (Standard_Debug_Renaming_Type); 1158 Set_Integer_Bounds (Standard_Debug_Renaming_Type, 1159 Typ => Base_Type (Standard_Debug_Renaming_Type), 1160 Lb => Uint_1, 1161 Hb => Uint_0); 1162 Set_Is_Constrained (Standard_Debug_Renaming_Type); 1163 Set_Has_Size_Clause (Standard_Debug_Renaming_Type); 1164 1165 -- Note on type names. The type names for the following special types 1166 -- are constructed so that they will look reasonable should they ever 1167 -- appear in error messages etc, although in practice the use of the 1168 -- special insertion character } for types results in special handling 1169 -- of these type names in any case. The blanks in these names would 1170 -- trouble in Gigi, but that's OK here, since none of these types 1171 -- should ever get through to Gigi. Attributes of these types are 1172 -- filled out to minimize problems with cascaded errors (for example, 1173 -- Any_Integer is given reasonable and consistent type and size values) 1174 1175 Any_Type := New_Standard_Entity ("any type"); 1176 Decl := New_Node (N_Full_Type_Declaration, Stloc); 1177 Set_Defining_Identifier (Decl, Any_Type); 1178 Set_Scope (Any_Type, Standard_Standard); 1179 Build_Signed_Integer_Type (Any_Type, Standard_Integer_Size); 1180 1181 Any_Id := New_Standard_Entity ("any id"); 1182 Set_Ekind (Any_Id, E_Variable); 1183 Set_Scope (Any_Id, Standard_Standard); 1184 Set_Etype (Any_Id, Any_Type); 1185 Init_Esize (Any_Id); 1186 Init_Alignment (Any_Id); 1187 1188 Any_Access := New_Standard_Entity ("an access type"); 1189 Set_Ekind (Any_Access, E_Access_Type); 1190 Set_Scope (Any_Access, Standard_Standard); 1191 Set_Etype (Any_Access, Any_Access); 1192 Init_Size (Any_Access, System_Address_Size); 1193 Set_Elem_Alignment (Any_Access); 1194 Set_Directly_Designated_Type 1195 (Any_Access, Any_Type); 1196 1197 Any_Character := New_Standard_Entity ("a character type"); 1198 Set_Ekind (Any_Character, E_Enumeration_Type); 1199 Set_Scope (Any_Character, Standard_Standard); 1200 Set_Etype (Any_Character, Any_Character); 1201 Set_Is_Unsigned_Type (Any_Character); 1202 Set_Is_Character_Type (Any_Character); 1203 Init_Esize (Any_Character, Standard_Character_Size); 1204 Init_RM_Size (Any_Character, 8); 1205 Set_Elem_Alignment (Any_Character); 1206 Set_Scalar_Range (Any_Character, Scalar_Range (Standard_Character)); 1207 1208 Any_Array := New_Standard_Entity ("an array type"); 1209 Set_Ekind (Any_Array, E_Array_Type); 1210 Set_Scope (Any_Array, Standard_Standard); 1211 Set_Etype (Any_Array, Any_Array); 1212 Set_Component_Type (Any_Array, Any_Character); 1213 Init_Size_Align (Any_Array); 1214 Make_Dummy_Index (Any_Array); 1215 1216 Any_Boolean := New_Standard_Entity ("a boolean type"); 1217 Set_Ekind (Any_Boolean, E_Enumeration_Type); 1218 Set_Scope (Any_Boolean, Standard_Standard); 1219 Set_Etype (Any_Boolean, Standard_Boolean); 1220 Init_Esize (Any_Boolean, Standard_Character_Size); 1221 Init_RM_Size (Any_Boolean, 1); 1222 Set_Elem_Alignment (Any_Boolean); 1223 Set_Is_Unsigned_Type (Any_Boolean); 1224 Set_Scalar_Range (Any_Boolean, Scalar_Range (Standard_Boolean)); 1225 1226 Any_Composite := New_Standard_Entity ("a composite type"); 1227 Set_Ekind (Any_Composite, E_Array_Type); 1228 Set_Scope (Any_Composite, Standard_Standard); 1229 Set_Etype (Any_Composite, Any_Composite); 1230 Set_Component_Size (Any_Composite, Uint_0); 1231 Set_Component_Type (Any_Composite, Standard_Integer); 1232 Init_Size_Align (Any_Composite); 1233 1234 Any_Discrete := New_Standard_Entity ("a discrete type"); 1235 Set_Ekind (Any_Discrete, E_Signed_Integer_Type); 1236 Set_Scope (Any_Discrete, Standard_Standard); 1237 Set_Etype (Any_Discrete, Any_Discrete); 1238 Init_Size (Any_Discrete, Standard_Integer_Size); 1239 Set_Elem_Alignment (Any_Discrete); 1240 1241 Any_Fixed := New_Standard_Entity ("a fixed-point type"); 1242 Set_Ekind (Any_Fixed, E_Ordinary_Fixed_Point_Type); 1243 Set_Scope (Any_Fixed, Standard_Standard); 1244 Set_Etype (Any_Fixed, Any_Fixed); 1245 Init_Size (Any_Fixed, Standard_Integer_Size); 1246 Set_Elem_Alignment (Any_Fixed); 1247 1248 Any_Integer := New_Standard_Entity ("an integer type"); 1249 Set_Ekind (Any_Integer, E_Signed_Integer_Type); 1250 Set_Scope (Any_Integer, Standard_Standard); 1251 Set_Etype (Any_Integer, Standard_Long_Long_Long_Integer); 1252 Init_Size (Any_Integer, Standard_Long_Long_Long_Integer_Size); 1253 Set_Elem_Alignment (Any_Integer); 1254 1255 Set_Integer_Bounds 1256 (Any_Integer, 1257 Typ => Base_Type (Standard_Integer), 1258 Lb => Uint_0, 1259 Hb => Intval (High_Bound (Scalar_Range (Standard_Integer)))); 1260 1261 Any_Modular := New_Standard_Entity ("a modular type"); 1262 Set_Ekind (Any_Modular, E_Modular_Integer_Type); 1263 Set_Scope (Any_Modular, Standard_Standard); 1264 Set_Etype (Any_Modular, Standard_Long_Long_Long_Integer); 1265 Init_Size (Any_Modular, Standard_Long_Long_Long_Integer_Size); 1266 Set_Elem_Alignment (Any_Modular); 1267 Set_Is_Unsigned_Type (Any_Modular); 1268 1269 Any_Numeric := New_Standard_Entity ("a numeric type"); 1270 Set_Ekind (Any_Numeric, E_Signed_Integer_Type); 1271 Set_Scope (Any_Numeric, Standard_Standard); 1272 Set_Etype (Any_Numeric, Standard_Long_Long_Long_Integer); 1273 Init_Size (Any_Numeric, Standard_Long_Long_Long_Integer_Size); 1274 Set_Elem_Alignment (Any_Numeric); 1275 1276 Any_Real := New_Standard_Entity ("a real type"); 1277 Set_Ekind (Any_Real, E_Floating_Point_Type); 1278 Set_Scope (Any_Real, Standard_Standard); 1279 Set_Etype (Any_Real, Standard_Long_Long_Float); 1280 Init_Size (Any_Real, 1281 UI_To_Int (Esize (Standard_Long_Long_Float))); 1282 Set_Elem_Alignment (Any_Real); 1283 1284 Any_Scalar := New_Standard_Entity ("a scalar type"); 1285 Set_Ekind (Any_Scalar, E_Signed_Integer_Type); 1286 Set_Scope (Any_Scalar, Standard_Standard); 1287 Set_Etype (Any_Scalar, Any_Scalar); 1288 Init_Size (Any_Scalar, Standard_Integer_Size); 1289 Set_Elem_Alignment (Any_Scalar); 1290 1291 Any_String := New_Standard_Entity ("a string type"); 1292 Set_Ekind (Any_String, E_Array_Type); 1293 Set_Scope (Any_String, Standard_Standard); 1294 Set_Etype (Any_String, Any_String); 1295 Set_Component_Type (Any_String, Any_Character); 1296 Init_Size_Align (Any_String); 1297 Make_Dummy_Index (Any_String); 1298 1299 Raise_Type := New_Standard_Entity ("raise type"); 1300 Decl := New_Node (N_Full_Type_Declaration, Stloc); 1301 Set_Defining_Identifier (Decl, Raise_Type); 1302 Set_Scope (Raise_Type, Standard_Standard); 1303 Build_Signed_Integer_Type (Raise_Type, Standard_Integer_Size); 1304 1305 Standard_Integer_8 := New_Standard_Entity ("integer_8"); 1306 Decl := New_Node (N_Full_Type_Declaration, Stloc); 1307 Set_Defining_Identifier (Decl, Standard_Integer_8); 1308 Set_Scope (Standard_Integer_8, Standard_Standard); 1309 Build_Signed_Integer_Type (Standard_Integer_8, 8); 1310 1311 Standard_Integer_16 := New_Standard_Entity ("integer_16"); 1312 Decl := New_Node (N_Full_Type_Declaration, Stloc); 1313 Set_Defining_Identifier (Decl, Standard_Integer_16); 1314 Set_Scope (Standard_Integer_16, Standard_Standard); 1315 Build_Signed_Integer_Type (Standard_Integer_16, 16); 1316 1317 Standard_Integer_32 := New_Standard_Entity ("integer_32"); 1318 Decl := New_Node (N_Full_Type_Declaration, Stloc); 1319 Set_Defining_Identifier (Decl, Standard_Integer_32); 1320 Set_Scope (Standard_Integer_32, Standard_Standard); 1321 Build_Signed_Integer_Type (Standard_Integer_32, 32); 1322 1323 Standard_Integer_64 := New_Standard_Entity ("integer_64"); 1324 Decl := New_Node (N_Full_Type_Declaration, Stloc); 1325 Set_Defining_Identifier (Decl, Standard_Integer_64); 1326 Set_Scope (Standard_Integer_64, Standard_Standard); 1327 Build_Signed_Integer_Type (Standard_Integer_64, 64); 1328 1329 Standard_Integer_128 := New_Standard_Entity ("integer_128"); 1330 Decl := New_Node (N_Full_Type_Declaration, Stloc); 1331 Set_Defining_Identifier (Decl, Standard_Integer_128); 1332 Set_Scope (Standard_Integer_128, Standard_Standard); 1333 Build_Signed_Integer_Type (Standard_Integer_128, 128); 1334 1335 -- Standard_*_Unsigned subtypes are not user visible, but they are 1336 -- used internally. They are unsigned types with the same length as 1337 -- the correspondingly named signed integer types. 1338 1339 Standard_Short_Short_Unsigned 1340 := New_Standard_Entity ("short_short_unsigned"); 1341 Build_Unsigned_Integer_Type 1342 (Standard_Short_Short_Unsigned, Standard_Short_Short_Integer_Size); 1343 1344 Standard_Short_Unsigned := New_Standard_Entity ("short_unsigned"); 1345 Build_Unsigned_Integer_Type 1346 (Standard_Short_Unsigned, Standard_Short_Integer_Size); 1347 1348 Standard_Unsigned := New_Standard_Entity ("unsigned"); 1349 Build_Unsigned_Integer_Type 1350 (Standard_Unsigned, Standard_Integer_Size); 1351 1352 Standard_Long_Unsigned := New_Standard_Entity ("long_unsigned"); 1353 Build_Unsigned_Integer_Type 1354 (Standard_Long_Unsigned, Standard_Long_Integer_Size); 1355 1356 Standard_Long_Long_Unsigned := 1357 New_Standard_Entity ("long_long_unsigned"); 1358 Build_Unsigned_Integer_Type 1359 (Standard_Long_Long_Unsigned, Standard_Long_Long_Integer_Size); 1360 1361 Standard_Long_Long_Long_Unsigned := 1362 New_Standard_Entity ("long_long_long_unsigned"); 1363 Build_Unsigned_Integer_Type 1364 (Standard_Long_Long_Long_Unsigned, 1365 Standard_Long_Long_Long_Integer_Size); 1366 1367 -- Standard_Unsigned_64 is not user visible, but is used internally. It 1368 -- is an unsigned type mod 2**64 with 64 bits size. 1369 1370 Standard_Unsigned_64 := New_Standard_Entity ("unsigned_64"); 1371 Build_Unsigned_Integer_Type (Standard_Unsigned_64, 64); 1372 1373 -- Standard_Address is not user visible, but is used internally. It is 1374 -- an unsigned type mod 2**System_Address_Size with System.Address size. 1375 1376 Standard_Address := New_Standard_Entity ("standard_address"); 1377 Build_Unsigned_Integer_Type (Standard_Address, System_Address_Size); 1378 1379 -- Note: universal integer and universal real are constructed as fully 1380 -- formed signed numeric types, with parameters corresponding to the 1381 -- longest runtime types (Long_Long_Long_Integer and Long_Long_Float). 1382 -- This allows Gigi to properly process references to universal types 1383 -- that are not folded at compile time. 1384 1385 Universal_Integer := New_Standard_Entity ("universal_integer"); 1386 Decl := New_Node (N_Full_Type_Declaration, Stloc); 1387 Set_Defining_Identifier (Decl, Universal_Integer); 1388 Set_Scope (Universal_Integer, Standard_Standard); 1389 Build_Signed_Integer_Type 1390 (Universal_Integer, Standard_Long_Long_Long_Integer_Size); 1391 1392 Universal_Real := New_Standard_Entity ("universal_real"); 1393 Decl := New_Node (N_Full_Type_Declaration, Stloc); 1394 Set_Defining_Identifier (Decl, Universal_Real); 1395 Set_Scope (Universal_Real, Standard_Standard); 1396 Copy_Float_Type (Universal_Real, Standard_Long_Long_Float); 1397 1398 -- Note: universal fixed, unlike universal integer and universal real, 1399 -- is never used at runtime, so it does not need to have bounds set. 1400 1401 Universal_Fixed := New_Standard_Entity ("universal_fixed"); 1402 Decl := New_Node (N_Full_Type_Declaration, Stloc); 1403 Set_Defining_Identifier (Decl, Universal_Fixed); 1404 Set_Ekind (Universal_Fixed, E_Ordinary_Fixed_Point_Type); 1405 Set_Etype (Universal_Fixed, Universal_Fixed); 1406 Set_Scope (Universal_Fixed, Standard_Standard); 1407 Init_Size (Universal_Fixed, Standard_Long_Long_Integer_Size); 1408 Set_Elem_Alignment (Universal_Fixed); 1409 Set_Size_Known_At_Compile_Time 1410 (Universal_Fixed); 1411 1412 -- Create type declaration for Duration, using a 64-bit size. The 1413 -- delta and size values depend on the mode set in system.ads. 1414 1415 Build_Duration : declare 1416 Dlo : Uint; 1417 Dhi : Uint; 1418 Delta_Val : Ureal; 1419 1420 begin 1421 -- In 32 bit mode, the size is 32 bits, and the delta and 1422 -- small values are set to 20 milliseconds (20.0*(10.0**(-3)). 1423 1424 if Duration_32_Bits_On_Target then 1425 Dlo := Intval (Type_Low_Bound (Standard_Integer_32)); 1426 Dhi := Intval (Type_High_Bound (Standard_Integer_32)); 1427 Delta_Val := UR_From_Components (UI_From_Int (20), Uint_3, 10); 1428 1429 -- In 64-bit mode, the size is 64-bits and the delta and 1430 -- small values are set to nanoseconds (1.0*(10.0**(-9)). 1431 1432 else 1433 Dlo := Intval (Type_Low_Bound (Standard_Integer_64)); 1434 Dhi := Intval (Type_High_Bound (Standard_Integer_64)); 1435 Delta_Val := UR_From_Components (Uint_1, Uint_9, 10); 1436 end if; 1437 1438 Tdef_Node := Make_Ordinary_Fixed_Point_Definition (Stloc, 1439 Delta_Expression => Make_Real_Literal (Stloc, Delta_Val), 1440 Real_Range_Specification => 1441 Make_Real_Range_Specification (Stloc, 1442 Low_Bound => Make_Real_Literal (Stloc, 1443 Realval => Dlo * Delta_Val), 1444 High_Bound => Make_Real_Literal (Stloc, 1445 Realval => Dhi * Delta_Val))); 1446 1447 Set_Type_Definition (Parent (Standard_Duration), Tdef_Node); 1448 1449 Set_Ekind (Standard_Duration, E_Ordinary_Fixed_Point_Type); 1450 Set_Etype (Standard_Duration, Standard_Duration); 1451 1452 if Duration_32_Bits_On_Target then 1453 Init_Size (Standard_Duration, 32); 1454 else 1455 Init_Size (Standard_Duration, 64); 1456 end if; 1457 1458 Set_Elem_Alignment (Standard_Duration); 1459 Set_Delta_Value (Standard_Duration, Delta_Val); 1460 Set_Small_Value (Standard_Duration, Delta_Val); 1461 Set_Scalar_Range (Standard_Duration, 1462 Real_Range_Specification 1463 (Type_Definition (Parent (Standard_Duration)))); 1464 1465 -- Normally it does not matter that nodes in package Standard are 1466 -- not marked as analyzed. The Scalar_Range of the fixed-point type 1467 -- Standard_Duration is an exception, because of the special test 1468 -- made in Freeze.Freeze_Fixed_Point_Type. 1469 1470 Set_Analyzed (Scalar_Range (Standard_Duration)); 1471 1472 Set_Etype (Type_High_Bound (Standard_Duration), Standard_Duration); 1473 Set_Etype (Type_Low_Bound (Standard_Duration), Standard_Duration); 1474 1475 Set_Is_Static_Expression (Type_High_Bound (Standard_Duration)); 1476 Set_Is_Static_Expression (Type_Low_Bound (Standard_Duration)); 1477 1478 Set_Corresponding_Integer_Value 1479 (Type_High_Bound (Standard_Duration), Dhi); 1480 1481 Set_Corresponding_Integer_Value 1482 (Type_Low_Bound (Standard_Duration), Dlo); 1483 1484 Set_Size_Known_At_Compile_Time (Standard_Duration); 1485 end Build_Duration; 1486 1487 -- Build standard exception type. Note that the type name here is 1488 -- actually used in the generated code, so it must be set correctly. 1489 -- The type Standard_Exception_Type must be consistent with the type 1490 -- System.Standard_Library.Exception_Data, as the latter is what is 1491 -- known by the run-time. Components of the record are documented in 1492 -- the declaration in System.Standard_Library. 1493 1494 Standard_Exception_Type := New_Standard_Entity ("exception"); 1495 Set_Ekind (Standard_Exception_Type, E_Record_Type); 1496 Set_Etype (Standard_Exception_Type, Standard_Exception_Type); 1497 Set_Scope (Standard_Exception_Type, Standard_Standard); 1498 Set_Stored_Constraint 1499 (Standard_Exception_Type, No_Elist); 1500 Init_Size_Align (Standard_Exception_Type); 1501 Set_Size_Known_At_Compile_Time 1502 (Standard_Exception_Type, True); 1503 1504 Make_Component 1505 (Standard_Exception_Type, Standard_Boolean, "Not_Handled_By_Others"); 1506 Make_Component 1507 (Standard_Exception_Type, Standard_Character, "Lang"); 1508 Make_Component 1509 (Standard_Exception_Type, Standard_Natural, "Name_Length"); 1510 Make_Component 1511 (Standard_Exception_Type, Standard_A_Char, "Full_Name"); 1512 Make_Component 1513 (Standard_Exception_Type, Standard_A_Char, "HTable_Ptr"); 1514 Make_Component 1515 (Standard_Exception_Type, Standard_A_Char, "Foreign_Data"); 1516 Make_Component 1517 (Standard_Exception_Type, Standard_A_Char, "Raise_Hook"); 1518 1519 -- Build tree for record declaration, for use by the back-end 1520 1521 declare 1522 Comp_List : List_Id; 1523 Comp : Entity_Id; 1524 1525 begin 1526 Comp := First_Entity (Standard_Exception_Type); 1527 Comp_List := New_List; 1528 while Present (Comp) loop 1529 Append ( 1530 Make_Component_Declaration (Stloc, 1531 Defining_Identifier => Comp, 1532 Component_Definition => 1533 Make_Component_Definition (Stloc, 1534 Aliased_Present => False, 1535 Subtype_Indication => New_Occurrence_Of (Etype (Comp), 1536 Stloc))), 1537 Comp_List); 1538 1539 Next_Entity (Comp); 1540 end loop; 1541 1542 Decl := Make_Full_Type_Declaration (Stloc, 1543 Defining_Identifier => Standard_Exception_Type, 1544 Type_Definition => 1545 Make_Record_Definition (Stloc, 1546 End_Label => Empty, 1547 Component_List => 1548 Make_Component_List (Stloc, 1549 Component_Items => Comp_List))); 1550 end; 1551 1552 Append (Decl, Decl_S); 1553 1554 Layout_Type (Standard_Exception_Type); 1555 1556 -- Create declarations of standard exceptions 1557 1558 Build_Exception (S_Constraint_Error); 1559 Build_Exception (S_Program_Error); 1560 Build_Exception (S_Storage_Error); 1561 Build_Exception (S_Tasking_Error); 1562 1563 -- Numeric_Error is a normal exception in Ada 83, but in Ada 95 1564 -- it is a renaming of Constraint_Error. This test is too early since 1565 -- it doesn't handle pragma Ada_83. But it's not worth the trouble of 1566 -- fixing this. 1567 1568 if Ada_Version = Ada_83 then 1569 Build_Exception (S_Numeric_Error); 1570 1571 else 1572 Decl := New_Node (N_Exception_Renaming_Declaration, Stloc); 1573 E_Id := Standard_Entity (S_Numeric_Error); 1574 1575 Set_Ekind (E_Id, E_Exception); 1576 Set_Etype (E_Id, Standard_Exception_Type); 1577 Set_Is_Public (E_Id); 1578 Set_Renamed_Entity (E_Id, Standard_Entity (S_Constraint_Error)); 1579 1580 Set_Defining_Identifier (Decl, E_Id); 1581 Append (Decl, Decl_S); 1582 1583 Ident_Node := New_Node (N_Identifier, Stloc); 1584 Set_Chars (Ident_Node, Chars (Standard_Entity (S_Constraint_Error))); 1585 Set_Entity (Ident_Node, Standard_Entity (S_Constraint_Error)); 1586 Set_Name (Decl, Ident_Node); 1587 end if; 1588 1589 -- Abort_Signal is an entity that does not get made visible 1590 1591 Abort_Signal := New_Standard_Entity; 1592 Set_Chars (Abort_Signal, Name_uAbort_Signal); 1593 Set_Ekind (Abort_Signal, E_Exception); 1594 Set_Etype (Abort_Signal, Standard_Exception_Type); 1595 Set_Scope (Abort_Signal, Standard_Standard); 1596 Set_Is_Public (Abort_Signal, True); 1597 Decl := 1598 Make_Exception_Declaration (Stloc, 1599 Defining_Identifier => Abort_Signal); 1600 1601 -- Create defining identifiers for shift operator entities. Note 1602 -- that these entities are used only for marking shift operators 1603 -- generated internally, and hence need no structure, just a name 1604 -- and a unique identity. 1605 1606 Standard_Op_Rotate_Left := New_Standard_Entity; 1607 Set_Chars (Standard_Op_Rotate_Left, Name_Rotate_Left); 1608 Set_Ekind (Standard_Op_Rotate_Left, E_Operator); 1609 1610 Standard_Op_Rotate_Right := New_Standard_Entity; 1611 Set_Chars (Standard_Op_Rotate_Right, Name_Rotate_Right); 1612 Set_Ekind (Standard_Op_Rotate_Right, E_Operator); 1613 1614 Standard_Op_Shift_Left := New_Standard_Entity; 1615 Set_Chars (Standard_Op_Shift_Left, Name_Shift_Left); 1616 Set_Ekind (Standard_Op_Shift_Left, E_Operator); 1617 1618 Standard_Op_Shift_Right := New_Standard_Entity; 1619 Set_Chars (Standard_Op_Shift_Right, Name_Shift_Right); 1620 Set_Ekind (Standard_Op_Shift_Right, E_Operator); 1621 1622 Standard_Op_Shift_Right_Arithmetic := New_Standard_Entity; 1623 Set_Chars (Standard_Op_Shift_Right_Arithmetic, 1624 Name_Shift_Right_Arithmetic); 1625 Set_Ekind (Standard_Op_Shift_Right_Arithmetic, 1626 E_Operator); 1627 1628 -- Create standard operator declarations 1629 1630 Create_Operators; 1631 1632 -- Initialize visibility table with entities in Standard 1633 1634 for E in Standard_Entity_Type loop 1635 if Ekind (Standard_Entity (E)) /= E_Operator then 1636 Set_Name_Entity_Id 1637 (Chars (Standard_Entity (E)), Standard_Entity (E)); 1638 Set_Homonym (Standard_Entity (E), Empty); 1639 end if; 1640 1641 if E not in S_ASCII_Names then 1642 Set_Scope (Standard_Entity (E), Standard_Standard); 1643 Set_Is_Immediately_Visible (Standard_Entity (E)); 1644 end if; 1645 end loop; 1646 1647 -- The predefined package Standard itself does not have a scope; 1648 -- it is the only entity in the system not to have one, and this 1649 -- is what identifies the package to Gigi. 1650 1651 Set_Scope (Standard_Standard, Empty); 1652 1653 -- Set global variables indicating last Id values and version 1654 1655 Last_Standard_Node_Id := Last_Node_Id; 1656 Last_Standard_List_Id := Last_List_Id; 1657 1658 -- The Error node has an Etype of Any_Type to help error recovery 1659 1660 Set_Etype (Error, Any_Type); 1661 1662 -- Print representation of standard if switch set 1663 1664 if Opt.Print_Standard then 1665 Print_Standard; 1666 end if; 1667 end Create_Standard; 1668 1669 ------------------------------------ 1670 -- Create_Unconstrained_Base_Type -- 1671 ------------------------------------ 1672 1673 procedure Create_Unconstrained_Base_Type 1674 (E : Entity_Id; 1675 K : Entity_Kind) 1676 is 1677 New_Ent : constant Entity_Id := New_Copy (E); 1678 1679 begin 1680 Set_Ekind (E, K); 1681 Set_Is_Constrained (E, True); 1682 Set_Is_First_Subtype (E, True); 1683 Set_Etype (E, New_Ent); 1684 1685 Append_Entity (New_Ent, Standard_Standard); 1686 Set_Is_Constrained (New_Ent, False); 1687 Set_Etype (New_Ent, New_Ent); 1688 Set_Is_Known_Valid (New_Ent, True); 1689 1690 if K = E_Signed_Integer_Subtype then 1691 Set_Etype (Low_Bound (Scalar_Range (E)), New_Ent); 1692 Set_Etype (High_Bound (Scalar_Range (E)), New_Ent); 1693 end if; 1694 end Create_Unconstrained_Base_Type; 1695 1696 -------------------- 1697 -- Identifier_For -- 1698 -------------------- 1699 1700 function Identifier_For (S : Standard_Entity_Type) return Node_Id is 1701 Ident_Node : constant Node_Id := New_Node (N_Identifier, Stloc); 1702 1703 begin 1704 Set_Chars (Ident_Node, Chars (Standard_Entity (S))); 1705 Set_Entity (Ident_Node, Standard_Entity (S)); 1706 1707 return Ident_Node; 1708 end Identifier_For; 1709 1710 -------------------- 1711 -- Make_Component -- 1712 -------------------- 1713 1714 procedure Make_Component 1715 (Rec : Entity_Id; 1716 Typ : Entity_Id; 1717 Nam : String) 1718 is 1719 Id : constant Entity_Id := New_Standard_Entity (Nam); 1720 1721 begin 1722 Set_Ekind (Id, E_Component); 1723 Set_Etype (Id, Typ); 1724 Set_Scope (Id, Rec); 1725 Init_Component_Location (Id); 1726 Set_Original_Record_Component (Id, Id); 1727 Append_Entity (Id, Rec); 1728 end Make_Component; 1729 1730 ----------------- 1731 -- Make_Formal -- 1732 ----------------- 1733 1734 function Make_Formal (Typ : Entity_Id; Nam : String) return Entity_Id is 1735 Formal : constant Entity_Id := New_Standard_Entity (Nam); 1736 1737 begin 1738 Set_Ekind (Formal, E_In_Parameter); 1739 Set_Mechanism (Formal, Default_Mechanism); 1740 Set_Scope (Formal, Standard_Standard); 1741 Set_Etype (Formal, Typ); 1742 1743 return Formal; 1744 end Make_Formal; 1745 1746 ------------------ 1747 -- Make_Integer -- 1748 ------------------ 1749 1750 function Make_Integer (V : Uint) return Node_Id is 1751 N : constant Node_Id := Make_Integer_Literal (Stloc, V); 1752 1753 begin 1754 Set_Is_Static_Expression (N); 1755 1756 return N; 1757 end Make_Integer; 1758 1759 ------------------ 1760 -- New_Operator -- 1761 ------------------ 1762 1763 function New_Operator (Op : Name_Id; Typ : Entity_Id) return Entity_Id is 1764 Ident_Node : constant Entity_Id := Make_Defining_Identifier (Stloc, Op); 1765 1766 begin 1767 Set_Is_Pure (Ident_Node, True); 1768 Set_Ekind (Ident_Node, E_Operator); 1769 Set_Etype (Ident_Node, Typ); 1770 Set_Scope (Ident_Node, Standard_Standard); 1771 Set_Homonym (Ident_Node, Get_Name_Entity_Id (Op)); 1772 Set_Convention (Ident_Node, Convention_Intrinsic); 1773 1774 Set_Is_Immediately_Visible (Ident_Node, True); 1775 Set_Is_Intrinsic_Subprogram (Ident_Node, True); 1776 1777 Set_Name_Entity_Id (Op, Ident_Node); 1778 Append_Entity (Ident_Node, Standard_Standard); 1779 1780 return Ident_Node; 1781 end New_Operator; 1782 1783 ------------------------- 1784 -- New_Standard_Entity -- 1785 ------------------------- 1786 1787 function New_Standard_Entity 1788 (New_Node_Kind : Node_Kind := N_Defining_Identifier) return Entity_Id 1789 is 1790 E : constant Entity_Id := New_Entity (New_Node_Kind, Stloc); 1791 1792 begin 1793 -- All standard entities are Pure and Public 1794 1795 Set_Is_Pure (E); 1796 Set_Is_Public (E); 1797 1798 -- All standard entity names are analyzed manually, and are thus 1799 -- frozen as soon as they are created. 1800 1801 Set_Is_Frozen (E); 1802 1803 -- Set debug information required for all standard types 1804 1805 Set_Needs_Debug_Info (E); 1806 1807 -- All standard entities are built with fully qualified names, so 1808 -- set the flag to prevent an abortive attempt at requalification. 1809 1810 Set_Has_Qualified_Name (E); 1811 1812 -- Return newly created entity to be completed by caller 1813 1814 return E; 1815 end New_Standard_Entity; 1816 1817 function New_Standard_Entity (Nam : String) return Entity_Id is 1818 Ent : constant Entity_Id := New_Standard_Entity; 1819 1820 begin 1821 for J in 1 .. Nam'Length loop 1822 Name_Buffer (J) := Fold_Lower (Nam (Nam'First + (J - 1))); 1823 end loop; 1824 1825 Name_Len := Nam'Length; 1826 Set_Chars (Ent, Name_Find); 1827 1828 return Ent; 1829 end New_Standard_Entity; 1830 1831 -------------------- 1832 -- Print_Standard -- 1833 -------------------- 1834 1835 procedure Print_Standard is 1836 1837 procedure P (Item : String) renames Output.Write_Line; 1838 -- Short-hand, since we do a lot of line writes here 1839 1840 procedure P_Int_Range (Size : Pos); 1841 -- Prints the range of an integer based on its Size 1842 1843 procedure P_Float_Range (Id : Entity_Id); 1844 -- Prints the bounds range for the given float type entity 1845 1846 procedure P_Float_Type (Id : Entity_Id); 1847 -- Prints the type declaration of the given float type entity 1848 1849 procedure P_Mixed_Name (Id : Name_Id); 1850 -- Prints Id in mixed case 1851 1852 ------------------- 1853 -- P_Float_Range -- 1854 ------------------- 1855 1856 procedure P_Float_Range (Id : Entity_Id) is 1857 begin 1858 Write_Str (" range "); 1859 UR_Write (Realval (Type_Low_Bound (Id))); 1860 Write_Str (" .. "); 1861 UR_Write (Realval (Type_High_Bound (Id))); 1862 Write_Str (";"); 1863 Write_Eol; 1864 end P_Float_Range; 1865 1866 ------------------ 1867 -- P_Float_Type -- 1868 ------------------ 1869 1870 procedure P_Float_Type (Id : Entity_Id) is 1871 begin 1872 Write_Str (" type "); 1873 P_Mixed_Name (Chars (Id)); 1874 Write_Str (" is digits "); 1875 Write_Int (UI_To_Int (Digits_Value (Id))); 1876 Write_Eol; 1877 P_Float_Range (Id); 1878 Write_Str (" for "); 1879 P_Mixed_Name (Chars (Id)); 1880 Write_Str ("'Size use "); 1881 Write_Int (UI_To_Int (RM_Size (Id))); 1882 Write_Line (";"); 1883 Write_Eol; 1884 end P_Float_Type; 1885 1886 ----------------- 1887 -- P_Int_Range -- 1888 ----------------- 1889 1890 procedure P_Int_Range (Size : Pos) is 1891 begin 1892 Write_Str (" is range -(2 **"); 1893 Write_Int (Size - 1); 1894 Write_Str (")"); 1895 Write_Str (" .. +(2 **"); 1896 Write_Int (Size - 1); 1897 Write_Str (" - 1);"); 1898 Write_Eol; 1899 end P_Int_Range; 1900 1901 ------------------ 1902 -- P_Mixed_Name -- 1903 ------------------ 1904 1905 procedure P_Mixed_Name (Id : Name_Id) is 1906 begin 1907 Get_Name_String (Id); 1908 1909 for J in 1 .. Name_Len loop 1910 if J = 1 or else Name_Buffer (J - 1) = '_' then 1911 Name_Buffer (J) := Fold_Upper (Name_Buffer (J)); 1912 end if; 1913 end loop; 1914 1915 Write_Str (Name_Buffer (1 .. Name_Len)); 1916 end P_Mixed_Name; 1917 1918 -- Start of processing for Print_Standard 1919 1920 begin 1921 P ("-- Representation of package Standard"); 1922 Write_Eol; 1923 P ("-- This is not accurate Ada, since new base types cannot be "); 1924 P ("-- created, but the listing shows the target dependent"); 1925 P ("-- characteristics of the Standard types for this compiler"); 1926 Write_Eol; 1927 1928 P ("package Standard is"); 1929 P ("pragma Pure (Standard);"); 1930 Write_Eol; 1931 1932 P (" type Boolean is (False, True);"); 1933 P (" for Boolean'Size use 1;"); 1934 P (" for Boolean use (False => 0, True => 1);"); 1935 Write_Eol; 1936 1937 -- Integer types 1938 1939 Write_Str (" type Integer"); 1940 P_Int_Range (Standard_Integer_Size); 1941 Write_Str (" for Integer'Size use "); 1942 Write_Int (Standard_Integer_Size); 1943 P (";"); 1944 Write_Eol; 1945 1946 P (" subtype Natural is Integer range 0 .. Integer'Last;"); 1947 P (" subtype Positive is Integer range 1 .. Integer'Last;"); 1948 Write_Eol; 1949 1950 Write_Str (" type Short_Short_Integer"); 1951 P_Int_Range (Standard_Short_Short_Integer_Size); 1952 Write_Str (" for Short_Short_Integer'Size use "); 1953 Write_Int (Standard_Short_Short_Integer_Size); 1954 P (";"); 1955 Write_Eol; 1956 1957 Write_Str (" type Short_Integer"); 1958 P_Int_Range (Standard_Short_Integer_Size); 1959 Write_Str (" for Short_Integer'Size use "); 1960 Write_Int (Standard_Short_Integer_Size); 1961 P (";"); 1962 Write_Eol; 1963 1964 Write_Str (" type Long_Integer"); 1965 P_Int_Range (Standard_Long_Integer_Size); 1966 Write_Str (" for Long_Integer'Size use "); 1967 Write_Int (Standard_Long_Integer_Size); 1968 P (";"); 1969 Write_Eol; 1970 1971 Write_Str (" type Long_Long_Integer"); 1972 P_Int_Range (Standard_Long_Long_Integer_Size); 1973 Write_Str (" for Long_Long_Integer'Size use "); 1974 Write_Int (Standard_Long_Long_Integer_Size); 1975 P (";"); 1976 Write_Eol; 1977 1978 Write_Str (" type Long_Long_Long_Integer"); 1979 P_Int_Range (Standard_Long_Long_Long_Integer_Size); 1980 Write_Str (" for Long_Long_Long_Integer'Size use "); 1981 Write_Int (Standard_Long_Long_Long_Integer_Size); 1982 P (";"); 1983 Write_Eol; 1984 1985 -- Floating point types 1986 1987 P_Float_Type (Standard_Short_Float); 1988 P_Float_Type (Standard_Float); 1989 P_Float_Type (Standard_Long_Float); 1990 P_Float_Type (Standard_Long_Long_Float); 1991 1992 P (" type Character is (...)"); 1993 Write_Str (" for Character'Size use "); 1994 Write_Int (Standard_Character_Size); 1995 P (";"); 1996 P (" -- See RM A.1(35) for details of this type"); 1997 Write_Eol; 1998 1999 P (" type Wide_Character is (...)"); 2000 Write_Str (" for Wide_Character'Size use "); 2001 Write_Int (Standard_Wide_Character_Size); 2002 P (";"); 2003 P (" -- See RM A.1(36) for details of this type"); 2004 Write_Eol; 2005 2006 P (" type Wide_Wide_Character is (...)"); 2007 Write_Str (" for Wide_Wide_Character'Size use "); 2008 Write_Int (Standard_Wide_Wide_Character_Size); 2009 P (";"); 2010 P (" -- See RM A.1(36) for details of this type"); 2011 2012 P (" type String is array (Positive range <>) of Character;"); 2013 P (" pragma Pack (String);"); 2014 Write_Eol; 2015 2016 P (" type Wide_String is array (Positive range <>)" & 2017 " of Wide_Character;"); 2018 P (" pragma Pack (Wide_String);"); 2019 Write_Eol; 2020 2021 P (" type Wide_Wide_String is array (Positive range <>)" & 2022 " of Wide_Wide_Character;"); 2023 P (" pragma Pack (Wide_Wide_String);"); 2024 Write_Eol; 2025 2026 -- We only have one representation each for 32-bit and 64-bit sizes, 2027 -- so select the right one based on Duration_32_Bits_On_Target. 2028 2029 if Duration_32_Bits_On_Target then 2030 P (" type Duration is delta 0.020"); 2031 P (" range -((2 ** 31) * 0.020) .."); 2032 P (" +((2 ** 31 - 1) * 0.020);"); 2033 P (" for Duration'Small use 0.020;"); 2034 2035 else 2036 P (" type Duration is delta 0.000000001"); 2037 P (" range -((2 ** 63) * 0.000000001) .."); 2038 P (" +((2 ** 63 - 1) * 0.000000001);"); 2039 P (" for Duration'Small use 0.000000001;"); 2040 end if; 2041 2042 Write_Eol; 2043 2044 P (" Constraint_Error : exception;"); 2045 P (" Program_Error : exception;"); 2046 P (" Storage_Error : exception;"); 2047 P (" Tasking_Error : exception;"); 2048 P (" Numeric_Error : exception renames Constraint_Error;"); 2049 Write_Eol; 2050 2051 P ("end Standard;"); 2052 end Print_Standard; 2053 2054 ------------------------- 2055 -- Register_Float_Type -- 2056 ------------------------- 2057 2058 procedure Register_Float_Type 2059 (Name : String; 2060 Digs : Positive; 2061 Float_Rep : Float_Rep_Kind; 2062 Precision : Positive; 2063 Size : Positive; 2064 Alignment : Natural) 2065 is 2066 pragma Unreferenced (Precision); 2067 -- See Build_Float_Type for the rationale 2068 2069 Ent : constant Entity_Id := New_Standard_Entity (Name); 2070 2071 begin 2072 Set_Defining_Identifier (New_Node (N_Full_Type_Declaration, Stloc), Ent); 2073 Set_Scope (Ent, Standard_Standard); 2074 Build_Float_Type 2075 (Ent, Pos (Digs), Float_Rep, Int (Size), Int (Alignment / 8)); 2076 2077 Append_New_Elmt (Ent, Back_End_Float_Types); 2078 end Register_Float_Type; 2079 2080 ---------------------- 2081 -- Set_Float_Bounds -- 2082 ---------------------- 2083 2084 procedure Set_Float_Bounds (Id : Entity_Id) is 2085 L : Node_Id; 2086 H : Node_Id; 2087 -- Low and high bounds of literal value 2088 2089 R : Node_Id; 2090 -- Range specification 2091 2092 Radix : constant Uint := Machine_Radix_Value (Id); 2093 Mantissa : constant Uint := Machine_Mantissa_Value (Id); 2094 Emax : constant Uint := Machine_Emax_Value (Id); 2095 Significand : constant Uint := Radix ** Mantissa - 1; 2096 Exponent : constant Uint := Emax - Mantissa; 2097 2098 begin 2099 H := Make_Float_Literal (Stloc, Radix, Significand, Exponent); 2100 L := Make_Float_Literal (Stloc, Radix, -Significand, Exponent); 2101 2102 Set_Etype (L, Id); 2103 Set_Is_Static_Expression (L); 2104 2105 Set_Etype (H, Id); 2106 Set_Is_Static_Expression (H); 2107 2108 R := New_Node (N_Range, Stloc); 2109 Set_Low_Bound (R, L); 2110 Set_High_Bound (R, H); 2111 Set_Includes_Infinities (R, True); 2112 Set_Scalar_Range (Id, R); 2113 Set_Etype (R, Id); 2114 Set_Parent (R, Id); 2115 end Set_Float_Bounds; 2116 2117 ------------------------ 2118 -- Set_Integer_Bounds -- 2119 ------------------------ 2120 2121 procedure Set_Integer_Bounds 2122 (Id : Entity_Id; 2123 Typ : Entity_Id; 2124 Lb : Uint; 2125 Hb : Uint) 2126 is 2127 L : Node_Id; 2128 H : Node_Id; 2129 -- Low and high bounds of literal value 2130 2131 R : Node_Id; 2132 -- Range specification 2133 2134 begin 2135 L := Make_Integer (Lb); 2136 H := Make_Integer (Hb); 2137 2138 Set_Etype (L, Typ); 2139 Set_Etype (H, Typ); 2140 2141 R := New_Node (N_Range, Stloc); 2142 Set_Low_Bound (R, L); 2143 Set_High_Bound (R, H); 2144 Set_Scalar_Range (Id, R); 2145 Set_Etype (R, Typ); 2146 Set_Parent (R, Id); 2147 Set_Is_Unsigned_Type (Id, Lb >= 0); 2148 end Set_Integer_Bounds; 2149 2150end CStand; 2151