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