1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2005 Free Software Foundation, Inc. --
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 2, 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 COPYING. If not, write --
19 -- to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, --
20 -- MA 02111-1307, USA. --
22 -- GNAT was originally developed by the GNAT team at New York University. --
23 -- Extensive contributions were provided by Ada Core Technologies Inc. --
25 ------------------------------------------------------------------------------
27 with Atree; use Atree;
28 with Csets; use Csets;
29 with Debug; use Debug;
30 with Einfo; use Einfo;
31 with Layout; use Layout;
32 with Namet; use Namet;
33 with Nlists; use Nlists;
34 with Nmake; use Nmake;
36 with Output; use Output;
37 with Targparm; use Targparm;
38 with Tbuild; use Tbuild;
39 with Ttypes; use Ttypes;
40 with Ttypef; use Ttypef;
42 with Sem_Mech; use Sem_Mech;
43 with Sem_Util; use Sem_Util;
44 with Sinfo; use Sinfo;
45 with Snames; use Snames;
46 with Stand; use Stand;
47 with Uintp; use Uintp;
48 with Urealp; use Urealp;
50 package body CStand is
52 Stloc : constant Source_Ptr := Standard_Location;
53 Staloc : constant Source_Ptr := Standard_ASCII_Location;
54 -- Standard abbreviations used throughout this package
56 -----------------------
57 -- Local Subprograms --
58 -----------------------
60 procedure Build_Float_Type (E : Entity_Id; Siz : Int; Digs : Int);
61 -- Procedure to build standard predefined float base type. The first
62 -- parameter is the entity for the type, and the second parameter
63 -- is the size in bits. The third parameter is the digits value.
65 procedure Build_Signed_Integer_Type (E : Entity_Id; Siz : Int);
66 -- Procedure to build standard predefined signed integer subtype. The
67 -- first parameter is the entity for the subtype. The second parameter
68 -- is the size in bits. The corresponding base type is not built by
69 -- this routine but instead must be built by the caller where needed.
71 procedure Create_Operators;
72 -- Make entries for each of the predefined operators in Standard
74 procedure Create_Unconstrained_Base_Type
77 -- The predefined signed integer types are constrained subtypes which
78 -- must have a corresponding unconstrained base type. This type is almost
79 -- useless. The only place it has semantics is Subtypes_Statically_Match.
80 -- Consequently, we arrange for it to be identical apart from the setting
81 -- of the constrained bit. This routine takes an entity E for the Type,
82 -- copies it to estabish the base type, then resets the Ekind of the
83 -- original entity to K (the Ekind for the subtype). The Etype field of
84 -- E is set by the call (to point to the created base type entity), and
85 -- also the Is_Constrained flag of E is set.
87 -- To understand the exact requirement for this, see RM 3.5.4(11) which
88 -- makes it clear that Integer, for example, is constrained, with the
89 -- constraint bounds matching the bounds of the (unconstrained) base
90 -- type. The point is that Integer and Integer'Base have identical
91 -- bounds, but do not statically match, since a subtype with constraints
92 -- never matches a subtype with no constraints.
94 function Identifier_For (S : Standard_Entity_Type) return Node_Id;
95 -- Returns an identifier node with the same name as the defining
96 -- identifier corresponding to the given Standard_Entity_Type value
98 procedure Make_Component
102 -- Build a record component with the given type and name, and append to
103 -- the list of components of Rec.
107 Formal_Name : String) return Entity_Id;
108 -- Construct entity for subprogram formal with given name and type
110 function Make_Integer (V : Uint) return Node_Id;
111 -- Builds integer literal with given value
113 procedure Make_Name (Id : Entity_Id; Nam : String);
114 -- Make an entry in the names table for Nam, and set as Chars field of Id
116 function New_Operator (Op : Name_Id; Typ : Entity_Id) return Entity_Id;
117 -- Build entity for standard operator with given name and type.
119 function New_Standard_Entity
120 (New_Node_Kind : Node_Kind := N_Defining_Identifier) return Entity_Id;
121 -- Builds a new entity for Standard
123 procedure Print_Standard;
124 -- Print representation of package Standard if switch set
126 procedure Set_Integer_Bounds
131 -- Procedure to set bounds for integer type or subtype. Id is the entity
132 -- whose bounds and type are to be set. The Typ parameter is the Etype
133 -- value for the entity (which will be the same as Id for all predefined
134 -- integer base types. The third and fourth parameters are the bounds.
136 ----------------------
137 -- Build_Float_Type --
138 ----------------------
140 procedure Build_Float_Type (E : Entity_Id; Siz : Int; Digs : Int) is
142 Set_Type_Definition (Parent (E),
143 Make_Floating_Point_Definition (Stloc,
144 Digits_Expression => Make_Integer (UI_From_Int (Digs))));
145 Set_Ekind (E, E_Floating_Point_Type);
148 Set_Elem_Alignment (E);
149 Init_Digits_Value (E, Digs);
150 Set_Float_Bounds (E);
153 Set_Size_Known_At_Compile_Time (E);
154 end Build_Float_Type;
156 -------------------------------
157 -- Build_Signed_Integer_Type --
158 -------------------------------
160 procedure Build_Signed_Integer_Type (E : Entity_Id; Siz : Int) is
161 U2Siz1 : constant Uint := 2 ** (Siz - 1);
162 Lbound : constant Uint := -U2Siz1;
163 Ubound : constant Uint := U2Siz1 - 1;
166 Set_Type_Definition (Parent (E),
167 Make_Signed_Integer_Type_Definition (Stloc,
168 Low_Bound => Make_Integer (Lbound),
169 High_Bound => Make_Integer (Ubound)));
171 Set_Ekind (E, E_Signed_Integer_Type);
174 Set_Elem_Alignment (E);
175 Set_Integer_Bounds (E, E, Lbound, Ubound);
178 Set_Is_Known_Valid (E);
179 Set_Size_Known_At_Compile_Time (E);
180 end Build_Signed_Integer_Type;
182 ----------------------
183 -- Create_Operators --
184 ----------------------
186 -- Each operator has an abbreviated signature. The formals have the names
187 -- LEFT and RIGHT. Their types are not actually used for resolution.
189 procedure Create_Operators is
192 -- The following tables define the binary and unary operators and their
193 -- corresponding result type.
195 Binary_Ops : constant array (S_Binary_Ops) of Name_Id :=
197 -- There is one entry here for each binary operator, except for the
198 -- case of concatenation, where there are three entries, one for a
199 -- String result, one for Wide_String, and one for Wide_Wide_String.
221 Bin_Op_Types : constant array (S_Binary_Ops) of Entity_Id :=
223 -- This table has the corresponding result types. The entries are
224 -- ordered so they correspond to the Binary_Ops array above.
226 (Universal_Integer, -- Add
227 Standard_Boolean, -- And
228 Standard_String, -- Concat (String)
229 Standard_Wide_String, -- Concat (Wide_String)
230 Standard_Wide_Wide_String, -- Concat (Wide_Wide_String)
231 Universal_Integer, -- Divide
232 Standard_Boolean, -- Eq
233 Universal_Integer, -- Expon
234 Standard_Boolean, -- Ge
235 Standard_Boolean, -- Gt
236 Standard_Boolean, -- Le
237 Standard_Boolean, -- Lt
238 Universal_Integer, -- Mod
239 Universal_Integer, -- Multiply
240 Standard_Boolean, -- Ne
241 Standard_Boolean, -- Or
242 Universal_Integer, -- Rem
243 Universal_Integer, -- Subtract
244 Standard_Boolean); -- Xor
246 Unary_Ops : constant array (S_Unary_Ops) of Name_Id :=
248 -- There is one entry here for each unary operator
255 Unary_Op_Types : constant array (S_Unary_Ops) of Entity_Id :=
257 -- This table has the corresponding result types. The entries are
258 -- ordered so they correspond to the Unary_Ops array above.
260 (Universal_Integer, -- Abs
261 Universal_Integer, -- Subtract
262 Standard_Boolean, -- Not
263 Universal_Integer); -- Add
266 for J in S_Binary_Ops loop
267 Op_Node := New_Operator (Binary_Ops (J), Bin_Op_Types (J));
269 Append_Entity (Make_Formal (Any_Type, "LEFT"), Op_Node);
270 Append_Entity (Make_Formal (Any_Type, "RIGHT"), Op_Node);
273 for J in S_Unary_Ops loop
274 Op_Node := New_Operator (Unary_Ops (J), Unary_Op_Types (J));
276 Append_Entity (Make_Formal (Any_Type, "RIGHT"), Op_Node);
279 -- For concatenation, we create a separate operator for each
280 -- array type. This simplifies the resolution of the component-
281 -- component concatenation operation. In Standard, we set the types
282 -- of the formals for string, wide [wide]_string, concatenations.
284 Set_Etype (First_Entity (Standard_Op_Concat), Standard_String);
285 Set_Etype (Last_Entity (Standard_Op_Concat), Standard_String);
287 Set_Etype (First_Entity (Standard_Op_Concatw), Standard_Wide_String);
288 Set_Etype (Last_Entity (Standard_Op_Concatw), Standard_Wide_String);
290 Set_Etype (First_Entity (Standard_Op_Concatww),
291 Standard_Wide_Wide_String);
293 Set_Etype (Last_Entity (Standard_Op_Concatww),
294 Standard_Wide_Wide_String);
296 end Create_Operators;
298 ---------------------
299 -- Create_Standard --
300 ---------------------
302 -- The tree for the package Standard is prefixed to all compilations.
303 -- Several entities required by semantic analysis are denoted by global
304 -- variables that are initialized to point to the corresponding
305 -- occurrences in STANDARD. The visible entities of STANDARD are
306 -- created here. The private entities defined in STANDARD are created
307 -- by Initialize_Standard in the semantics module.
309 procedure Create_Standard is
310 Decl_S : constant List_Id := New_List;
311 -- List of declarations in Standard
313 Decl_A : constant List_Id := New_List;
314 -- List of declarations in ASCII
319 Ident_Node : Node_Id;
325 procedure Build_Exception (S : Standard_Entity_Type);
326 -- Procedure to declare given entity as an exception
328 ---------------------
329 -- Build_Exception --
330 ---------------------
332 procedure Build_Exception (S : Standard_Entity_Type) is
334 Set_Ekind (Standard_Entity (S), E_Exception);
335 Set_Etype (Standard_Entity (S), Standard_Exception_Type);
336 Set_Exception_Code (Standard_Entity (S), Uint_0);
337 Set_Is_Public (Standard_Entity (S), True);
340 Make_Exception_Declaration (Stloc,
341 Defining_Identifier => Standard_Entity (S));
342 Append (Decl, Decl_S);
345 -- Start of processing for Create_Standard
348 -- Initialize scanner for internal scans of literals
350 Scn.Initialize_Scanner (No_Unit, Internal_Source_File);
352 -- First step is to create defining identifiers for each entity
354 for S in Standard_Entity_Type loop
356 S_Name : constant String := Standard_Entity_Type'Image (S);
357 -- Name of entity (note we skip S_ at the start)
359 Ident_Node : Node_Id;
360 -- Defining identifier node
363 Ident_Node := New_Standard_Entity;
364 Make_Name (Ident_Node, S_Name (3 .. S_Name'Length));
365 Standard_Entity (S) := Ident_Node;
369 -- Create package declaration node for package Standard
371 Standard_Package_Node := New_Node (N_Package_Declaration, Stloc);
373 Pspec := New_Node (N_Package_Specification, Stloc);
374 Set_Specification (Standard_Package_Node, Pspec);
376 Set_Defining_Unit_Name (Pspec, Standard_Standard);
377 Set_Visible_Declarations (Pspec, Decl_S);
379 Set_Ekind (Standard_Standard, E_Package);
380 Set_Is_Pure (Standard_Standard);
381 Set_Is_Compilation_Unit (Standard_Standard);
383 -- Create type declaration nodes for standard types
385 for S in S_Types loop
386 Decl := New_Node (N_Full_Type_Declaration, Stloc);
387 Set_Defining_Identifier (Decl, Standard_Entity (S));
388 Set_Is_Frozen (Standard_Entity (S));
389 Set_Is_Public (Standard_Entity (S));
390 Append (Decl, Decl_S);
393 -- Create type definition node for type Boolean. The Size is set to
394 -- 1 as required by Ada 95 and current ARG interpretations for Ada/83.
396 -- Note: Object_Size of Boolean is 8. This means that we do NOT in
397 -- general know that Boolean variables have valid values, so we do
398 -- not set the Is_Known_Valid flag.
400 Tdef_Node := New_Node (N_Enumeration_Type_Definition, Stloc);
401 Set_Literals (Tdef_Node, New_List);
402 Append (Standard_False, Literals (Tdef_Node));
403 Append (Standard_True, Literals (Tdef_Node));
404 Set_Type_Definition (Parent (Standard_Boolean), Tdef_Node);
406 Set_Ekind (Standard_Boolean, E_Enumeration_Type);
407 Set_First_Literal (Standard_Boolean, Standard_False);
408 Set_Etype (Standard_Boolean, Standard_Boolean);
409 Init_Esize (Standard_Boolean, Standard_Character_Size);
410 Init_RM_Size (Standard_Boolean, 1);
411 Set_Elem_Alignment (Standard_Boolean);
413 Set_Is_Unsigned_Type (Standard_Boolean);
414 Set_Size_Known_At_Compile_Time (Standard_Boolean);
416 Set_Ekind (Standard_True, E_Enumeration_Literal);
417 Set_Etype (Standard_True, Standard_Boolean);
418 Set_Enumeration_Pos (Standard_True, Uint_1);
419 Set_Enumeration_Rep (Standard_True, Uint_1);
420 Set_Is_Known_Valid (Standard_True, True);
422 Set_Ekind (Standard_False, E_Enumeration_Literal);
423 Set_Etype (Standard_False, Standard_Boolean);
424 Set_Enumeration_Pos (Standard_False, Uint_0);
425 Set_Enumeration_Rep (Standard_False, Uint_0);
426 Set_Is_Known_Valid (Standard_False, True);
428 -- For the bounds of Boolean, we create a range node corresponding to
430 -- range False .. True
432 -- where the occurrences of the literals must point to the
433 -- corresponding definition.
435 R_Node := New_Node (N_Range, Stloc);
436 B_Node := New_Node (N_Identifier, Stloc);
437 Set_Chars (B_Node, Chars (Standard_False));
438 Set_Entity (B_Node, Standard_False);
439 Set_Etype (B_Node, Standard_Boolean);
440 Set_Is_Static_Expression (B_Node);
441 Set_Low_Bound (R_Node, B_Node);
443 B_Node := New_Node (N_Identifier, Stloc);
444 Set_Chars (B_Node, Chars (Standard_True));
445 Set_Entity (B_Node, Standard_True);
446 Set_Etype (B_Node, Standard_Boolean);
447 Set_Is_Static_Expression (B_Node);
448 Set_High_Bound (R_Node, B_Node);
450 Set_Scalar_Range (Standard_Boolean, R_Node);
451 Set_Etype (R_Node, Standard_Boolean);
452 Set_Parent (R_Node, Standard_Boolean);
454 -- Record entity identifiers for boolean literals in the
455 -- Boolean_Literals array, for easy reference during expansion.
457 Boolean_Literals := (False => Standard_False, True => Standard_True);
459 -- Create type definition nodes for predefined integer types
461 Build_Signed_Integer_Type
462 (Standard_Short_Short_Integer, Standard_Short_Short_Integer_Size);
464 Build_Signed_Integer_Type
465 (Standard_Short_Integer, Standard_Short_Integer_Size);
467 Build_Signed_Integer_Type
468 (Standard_Integer, Standard_Integer_Size);
476 LIS := Standard_Long_Integer_Size;
479 Build_Signed_Integer_Type (Standard_Long_Integer, LIS);
482 Build_Signed_Integer_Type
483 (Standard_Long_Long_Integer, Standard_Long_Long_Integer_Size);
485 Create_Unconstrained_Base_Type
486 (Standard_Short_Short_Integer, E_Signed_Integer_Subtype);
488 Create_Unconstrained_Base_Type
489 (Standard_Short_Integer, E_Signed_Integer_Subtype);
491 Create_Unconstrained_Base_Type
492 (Standard_Integer, E_Signed_Integer_Subtype);
494 Create_Unconstrained_Base_Type
495 (Standard_Long_Integer, E_Signed_Integer_Subtype);
497 Create_Unconstrained_Base_Type
498 (Standard_Long_Long_Integer, E_Signed_Integer_Subtype);
500 -- Create type definition nodes for predefined float types
503 (Standard_Short_Float,
504 Standard_Short_Float_Size,
505 Standard_Short_Float_Digits);
510 Standard_Float_Digits);
513 (Standard_Long_Float,
514 Standard_Long_Float_Size,
515 Standard_Long_Float_Digits);
518 (Standard_Long_Long_Float,
519 Standard_Long_Long_Float_Size,
520 Standard_Long_Long_Float_Digits);
522 -- Create type definition node for type Character. Note that we do not
523 -- set the Literals field, since type Character is handled with special
524 -- routine that do not need a literal list.
526 Tdef_Node := New_Node (N_Enumeration_Type_Definition, Stloc);
527 Set_Type_Definition (Parent (Standard_Character), Tdef_Node);
529 Set_Ekind (Standard_Character, E_Enumeration_Type);
530 Set_Etype (Standard_Character, Standard_Character);
531 Init_Esize (Standard_Character, Standard_Character_Size);
532 Init_RM_Size (Standard_Character, 8);
533 Set_Elem_Alignment (Standard_Character);
535 Set_Is_Unsigned_Type (Standard_Character);
536 Set_Is_Character_Type (Standard_Character);
537 Set_Is_Known_Valid (Standard_Character);
538 Set_Size_Known_At_Compile_Time (Standard_Character);
540 -- Create the bounds for type Character.
542 R_Node := New_Node (N_Range, Stloc);
544 -- Low bound for type Character (Standard.Nul)
546 B_Node := New_Node (N_Character_Literal, Stloc);
547 Set_Is_Static_Expression (B_Node);
548 Set_Chars (B_Node, No_Name);
549 Set_Char_Literal_Value (B_Node, Uint_0);
550 Set_Entity (B_Node, Empty);
551 Set_Etype (B_Node, Standard_Character);
552 Set_Low_Bound (R_Node, B_Node);
554 -- High bound for type Character
556 B_Node := New_Node (N_Character_Literal, Stloc);
557 Set_Is_Static_Expression (B_Node);
558 Set_Chars (B_Node, No_Name);
559 Set_Char_Literal_Value (B_Node, UI_From_Int (16#FF#));
560 Set_Entity (B_Node, Empty);
561 Set_Etype (B_Node, Standard_Character);
562 Set_High_Bound (R_Node, B_Node);
564 Set_Scalar_Range (Standard_Character, R_Node);
565 Set_Etype (R_Node, Standard_Character);
566 Set_Parent (R_Node, Standard_Character);
568 -- Create type definition for type Wide_Character. Note that we do not
569 -- set the Literals field, since type Wide_Character is handled with
570 -- special routines that do not need a literal list.
572 Tdef_Node := New_Node (N_Enumeration_Type_Definition, Stloc);
573 Set_Type_Definition (Parent (Standard_Wide_Character), Tdef_Node);
575 Set_Ekind (Standard_Wide_Character, E_Enumeration_Type);
576 Set_Etype (Standard_Wide_Character, Standard_Wide_Character);
577 Init_Size (Standard_Wide_Character, Standard_Wide_Character_Size);
579 Set_Elem_Alignment (Standard_Wide_Character);
580 Set_Is_Unsigned_Type (Standard_Wide_Character);
581 Set_Is_Character_Type (Standard_Wide_Character);
582 Set_Is_Known_Valid (Standard_Wide_Character);
583 Set_Size_Known_At_Compile_Time (Standard_Wide_Character);
585 -- Create the bounds for type Wide_Character.
587 R_Node := New_Node (N_Range, Stloc);
589 -- Low bound for type Wide_Character
591 B_Node := New_Node (N_Character_Literal, Stloc);
592 Set_Is_Static_Expression (B_Node);
593 Set_Chars (B_Node, No_Name); -- ???
594 Set_Char_Literal_Value (B_Node, Uint_0);
595 Set_Entity (B_Node, Empty);
596 Set_Etype (B_Node, Standard_Wide_Character);
597 Set_Low_Bound (R_Node, B_Node);
599 -- High bound for type Wide_Character
601 B_Node := New_Node (N_Character_Literal, Stloc);
602 Set_Is_Static_Expression (B_Node);
603 Set_Chars (B_Node, No_Name); -- ???
604 Set_Char_Literal_Value (B_Node, UI_From_Int (16#FFFF#));
605 Set_Entity (B_Node, Empty);
606 Set_Etype (B_Node, Standard_Wide_Character);
607 Set_High_Bound (R_Node, B_Node);
609 Set_Scalar_Range (Standard_Wide_Character, R_Node);
610 Set_Etype (R_Node, Standard_Wide_Character);
611 Set_Parent (R_Node, Standard_Wide_Character);
613 -- Create type definition for type Wide_Wide_Character. Note that we
614 -- do not set the Literals field, since type Wide_Wide_Character is
615 -- handled with special routines that do not need a literal list.
617 Tdef_Node := New_Node (N_Enumeration_Type_Definition, Stloc);
618 Set_Type_Definition (Parent (Standard_Wide_Wide_Character), Tdef_Node);
620 Set_Ekind (Standard_Wide_Wide_Character, E_Enumeration_Type);
621 Set_Etype (Standard_Wide_Wide_Character,
622 Standard_Wide_Wide_Character);
623 Init_Size (Standard_Wide_Wide_Character,
624 Standard_Wide_Wide_Character_Size);
626 Set_Elem_Alignment (Standard_Wide_Wide_Character);
627 Set_Is_Unsigned_Type (Standard_Wide_Wide_Character);
628 Set_Is_Character_Type (Standard_Wide_Wide_Character);
629 Set_Is_Known_Valid (Standard_Wide_Wide_Character);
630 Set_Size_Known_At_Compile_Time (Standard_Wide_Wide_Character);
631 Set_Is_Ada_2005 (Standard_Wide_Wide_Character);
633 -- Create the bounds for type Wide_Wide_Character
635 R_Node := New_Node (N_Range, Stloc);
637 -- Low bound for type Wide_Wide_Character
639 B_Node := New_Node (N_Character_Literal, Stloc);
640 Set_Is_Static_Expression (B_Node);
641 Set_Chars (B_Node, No_Name); -- ???
642 Set_Char_Literal_Value (B_Node, Uint_0);
643 Set_Entity (B_Node, Empty);
644 Set_Etype (B_Node, Standard_Wide_Wide_Character);
645 Set_Low_Bound (R_Node, B_Node);
647 -- High bound for type Wide_Wide_Character
649 B_Node := New_Node (N_Character_Literal, Stloc);
650 Set_Is_Static_Expression (B_Node);
651 Set_Chars (B_Node, No_Name); -- ???
652 Set_Char_Literal_Value (B_Node, UI_From_Int (16#7FFF_FFFF#));
653 Set_Entity (B_Node, Empty);
654 Set_Etype (B_Node, Standard_Wide_Wide_Character);
655 Set_High_Bound (R_Node, B_Node);
657 Set_Scalar_Range (Standard_Wide_Wide_Character, R_Node);
658 Set_Etype (R_Node, Standard_Wide_Wide_Character);
659 Set_Parent (R_Node, Standard_Wide_Wide_Character);
661 -- Create type definition node for type String
663 Tdef_Node := New_Node (N_Unconstrained_Array_Definition, Stloc);
666 CompDef_Node : Node_Id;
668 CompDef_Node := New_Node (N_Component_Definition, Stloc);
669 Set_Aliased_Present (CompDef_Node, False);
670 Set_Access_Definition (CompDef_Node, Empty);
671 Set_Subtype_Indication (CompDef_Node, Identifier_For (S_Character));
672 Set_Component_Definition (Tdef_Node, CompDef_Node);
675 Set_Subtype_Marks (Tdef_Node, New_List);
676 Append (Identifier_For (S_Positive), Subtype_Marks (Tdef_Node));
677 Set_Type_Definition (Parent (Standard_String), Tdef_Node);
679 Set_Ekind (Standard_String, E_String_Type);
680 Set_Etype (Standard_String, Standard_String);
681 Set_Component_Type (Standard_String, Standard_Character);
682 Set_Component_Size (Standard_String, Uint_8);
683 Init_Size_Align (Standard_String);
684 Set_Alignment (Standard_String, Uint_1);
686 -- Set index type of String
689 (Subtype_Marks (Type_Definition (Parent (Standard_String))));
690 Set_First_Index (Standard_String, E_Id);
691 Set_Entity (E_Id, Standard_Positive);
692 Set_Etype (E_Id, Standard_Positive);
694 -- Create type definition node for type Wide_String
696 Tdef_Node := New_Node (N_Unconstrained_Array_Definition, Stloc);
699 CompDef_Node : Node_Id;
701 CompDef_Node := New_Node (N_Component_Definition, Stloc);
702 Set_Aliased_Present (CompDef_Node, False);
703 Set_Access_Definition (CompDef_Node, Empty);
704 Set_Subtype_Indication (CompDef_Node,
705 Identifier_For (S_Wide_Character));
706 Set_Component_Definition (Tdef_Node, CompDef_Node);
709 Set_Subtype_Marks (Tdef_Node, New_List);
710 Append (Identifier_For (S_Positive), Subtype_Marks (Tdef_Node));
711 Set_Type_Definition (Parent (Standard_Wide_String), Tdef_Node);
713 Set_Ekind (Standard_Wide_String, E_String_Type);
714 Set_Etype (Standard_Wide_String, Standard_Wide_String);
715 Set_Component_Type (Standard_Wide_String, Standard_Wide_Character);
716 Set_Component_Size (Standard_Wide_String, Uint_16);
717 Init_Size_Align (Standard_Wide_String);
719 -- Set index type of Wide_String
722 (Subtype_Marks (Type_Definition (Parent (Standard_Wide_String))));
723 Set_First_Index (Standard_Wide_String, E_Id);
724 Set_Entity (E_Id, Standard_Positive);
725 Set_Etype (E_Id, Standard_Positive);
727 -- Create type definition node for type Wide_Wide_String
729 Tdef_Node := New_Node (N_Unconstrained_Array_Definition, Stloc);
732 CompDef_Node : Node_Id;
734 CompDef_Node := New_Node (N_Component_Definition, Stloc);
735 Set_Aliased_Present (CompDef_Node, False);
736 Set_Access_Definition (CompDef_Node, Empty);
737 Set_Subtype_Indication (CompDef_Node,
738 Identifier_For (S_Wide_Wide_Character));
739 Set_Component_Definition (Tdef_Node, CompDef_Node);
742 Set_Subtype_Marks (Tdef_Node, New_List);
743 Append (Identifier_For (S_Positive), Subtype_Marks (Tdef_Node));
744 Set_Type_Definition (Parent (Standard_Wide_Wide_String), Tdef_Node);
746 Set_Ekind (Standard_Wide_Wide_String, E_String_Type);
747 Set_Etype (Standard_Wide_Wide_String,
748 Standard_Wide_Wide_String);
749 Set_Component_Type (Standard_Wide_Wide_String,
750 Standard_Wide_Wide_Character);
751 Set_Component_Size (Standard_Wide_Wide_String, Uint_32);
752 Init_Size_Align (Standard_Wide_Wide_String);
753 Set_Is_Ada_2005 (Standard_Wide_Wide_String);
755 -- Set index type of Wide_Wide_String
758 (Subtype_Marks (Type_Definition (Parent (Standard_Wide_Wide_String))));
759 Set_First_Index (Standard_Wide_Wide_String, E_Id);
760 Set_Entity (E_Id, Standard_Positive);
761 Set_Etype (E_Id, Standard_Positive);
763 -- Create subtype declaration for Natural
765 Decl := New_Node (N_Subtype_Declaration, Stloc);
766 Set_Defining_Identifier (Decl, Standard_Natural);
767 Set_Subtype_Indication (Decl,
768 New_Occurrence_Of (Standard_Integer, Stloc));
769 Append (Decl, Decl_S);
771 Set_Ekind (Standard_Natural, E_Signed_Integer_Subtype);
772 Set_Etype (Standard_Natural, Base_Type (Standard_Integer));
773 Init_Esize (Standard_Natural, Standard_Integer_Size);
774 Init_RM_Size (Standard_Natural, Standard_Integer_Size - 1);
775 Set_Elem_Alignment (Standard_Natural);
776 Set_Size_Known_At_Compile_Time
778 Set_Integer_Bounds (Standard_Natural,
779 Typ => Base_Type (Standard_Integer),
781 Hb => Intval (High_Bound (Scalar_Range (Standard_Integer))));
782 Set_Is_Constrained (Standard_Natural);
783 Set_Is_Frozen (Standard_Natural);
784 Set_Is_Public (Standard_Natural);
786 -- Create subtype declaration for Positive
788 Decl := New_Node (N_Subtype_Declaration, Stloc);
789 Set_Defining_Identifier (Decl, Standard_Positive);
790 Set_Subtype_Indication (Decl,
791 New_Occurrence_Of (Standard_Integer, Stloc));
792 Append (Decl, Decl_S);
794 Set_Ekind (Standard_Positive, E_Signed_Integer_Subtype);
795 Set_Etype (Standard_Positive, Base_Type (Standard_Integer));
796 Init_Esize (Standard_Positive, Standard_Integer_Size);
797 Init_RM_Size (Standard_Positive, Standard_Integer_Size - 1);
798 Set_Elem_Alignment (Standard_Positive);
800 Set_Size_Known_At_Compile_Time (Standard_Positive);
802 Set_Integer_Bounds (Standard_Positive,
803 Typ => Base_Type (Standard_Integer),
805 Hb => Intval (High_Bound (Scalar_Range (Standard_Integer))));
806 Set_Is_Constrained (Standard_Positive);
807 Set_Is_Frozen (Standard_Positive);
808 Set_Is_Public (Standard_Positive);
810 -- Create declaration for package ASCII
812 Decl := New_Node (N_Package_Declaration, Stloc);
813 Append (Decl, Decl_S);
815 Pspec := New_Node (N_Package_Specification, Stloc);
816 Set_Specification (Decl, Pspec);
818 Set_Defining_Unit_Name (Pspec, Standard_Entity (S_ASCII));
819 Set_Ekind (Standard_Entity (S_ASCII), E_Package);
820 Set_Visible_Declarations (Pspec, Decl_A);
822 -- Create control character definitions in package ASCII. Note that
823 -- the character literal entries created here correspond to literal
824 -- values that are impossible in the source, but can be represented
825 -- internally with no difficulties.
829 for S in S_ASCII_Names loop
830 Decl := New_Node (N_Object_Declaration, Staloc);
831 Set_Constant_Present (Decl, True);
834 A_Char : constant Entity_Id := Standard_Entity (S);
838 Set_Sloc (A_Char, Staloc);
839 Set_Ekind (A_Char, E_Constant);
840 Set_Never_Set_In_Source (A_Char, True);
841 Set_Is_True_Constant (A_Char, True);
842 Set_Etype (A_Char, Standard_Character);
843 Set_Scope (A_Char, Standard_Entity (S_ASCII));
844 Set_Is_Immediately_Visible (A_Char, False);
845 Set_Is_Public (A_Char, True);
846 Set_Is_Known_Valid (A_Char, True);
848 Append_Entity (A_Char, Standard_Entity (S_ASCII));
849 Set_Defining_Identifier (Decl, A_Char);
851 Set_Object_Definition (Decl, Identifier_For (S_Character));
852 Expr_Decl := New_Node (N_Character_Literal, Staloc);
853 Set_Expression (Decl, Expr_Decl);
855 Set_Is_Static_Expression (Expr_Decl);
856 Set_Chars (Expr_Decl, No_Name);
857 Set_Etype (Expr_Decl, Standard_Character);
858 Set_Char_Literal_Value (Expr_Decl, UI_From_Int (Int (Ccode)));
861 Append (Decl, Decl_A);
863 -- Increment character code, dealing with non-contiguities
867 if Ccode = 16#20# then
869 elsif Ccode = 16#27# then
871 elsif Ccode = 16#3C# then
873 elsif Ccode = 16#41# then
878 -- Create semantic phase entities
880 Standard_Void_Type := New_Standard_Entity;
881 Set_Ekind (Standard_Void_Type, E_Void);
882 Set_Etype (Standard_Void_Type, Standard_Void_Type);
883 Set_Scope (Standard_Void_Type, Standard_Standard);
884 Make_Name (Standard_Void_Type, "_void_type");
886 -- The type field of packages is set to void
888 Set_Etype (Standard_Standard, Standard_Void_Type);
889 Set_Etype (Standard_ASCII, Standard_Void_Type);
891 -- Standard_A_String is actually used in generated code, so it has a
892 -- type name that is reasonable, but does not overlap any Ada name.
894 Standard_A_String := New_Standard_Entity;
895 Set_Ekind (Standard_A_String, E_Access_Type);
896 Set_Scope (Standard_A_String, Standard_Standard);
897 Set_Etype (Standard_A_String, Standard_A_String);
900 Init_Size (Standard_A_String, System_Address_Size);
902 Init_Size (Standard_A_String, System_Address_Size * 2);
905 Init_Alignment (Standard_A_String);
907 Set_Directly_Designated_Type
908 (Standard_A_String, Standard_String);
909 Make_Name (Standard_A_String, "access_string");
911 Standard_A_Char := New_Standard_Entity;
912 Set_Ekind (Standard_A_Char, E_Access_Type);
913 Set_Scope (Standard_A_Char, Standard_Standard);
914 Set_Etype (Standard_A_Char, Standard_A_String);
915 Init_Size (Standard_A_Char, System_Address_Size);
916 Set_Elem_Alignment (Standard_A_Char);
918 Set_Directly_Designated_Type (Standard_A_Char, Standard_Character);
919 Make_Name (Standard_A_Char, "access_character");
921 -- Note on type names. The type names for the following special types
922 -- are constructed so that they will look reasonable should they ever
923 -- appear in error messages etc, although in practice the use of the
924 -- special insertion character } for types results in special handling
925 -- of these type names in any case. The blanks in these names would
926 -- trouble in Gigi, but that's OK here, since none of these types
927 -- should ever get through to Gigi! Attributes of these types are
928 -- filled out to minimize problems with cascaded errors (for example,
929 -- Any_Integer is given reasonable and consistent type and size values)
931 Any_Type := New_Standard_Entity;
932 Decl := New_Node (N_Full_Type_Declaration, Stloc);
933 Set_Defining_Identifier (Decl, Any_Type);
934 Set_Scope (Any_Type, Standard_Standard);
935 Build_Signed_Integer_Type (Any_Type, Standard_Integer_Size);
936 Make_Name (Any_Type, "any type");
938 Any_Id := New_Standard_Entity;
939 Set_Ekind (Any_Id, E_Variable);
940 Set_Scope (Any_Id, Standard_Standard);
941 Set_Etype (Any_Id, Any_Type);
942 Init_Size_Align (Any_Id);
943 Make_Name (Any_Id, "any id");
945 Any_Access := New_Standard_Entity;
946 Set_Ekind (Any_Access, E_Access_Type);
947 Set_Scope (Any_Access, Standard_Standard);
948 Set_Etype (Any_Access, Any_Access);
949 Init_Size (Any_Access, System_Address_Size);
950 Set_Elem_Alignment (Any_Access);
951 Make_Name (Any_Access, "an access type");
953 Any_Character := New_Standard_Entity;
954 Set_Ekind (Any_Character, E_Enumeration_Type);
955 Set_Scope (Any_Character, Standard_Standard);
956 Set_Etype (Any_Character, Any_Character);
957 Set_Is_Unsigned_Type (Any_Character);
958 Set_Is_Character_Type (Any_Character);
959 Init_Esize (Any_Character, Standard_Character_Size);
960 Init_RM_Size (Any_Character, 8);
961 Set_Elem_Alignment (Any_Character);
962 Set_Scalar_Range (Any_Character, Scalar_Range (Standard_Character));
963 Make_Name (Any_Character, "a character type");
965 Any_Array := New_Standard_Entity;
966 Set_Ekind (Any_Array, E_String_Type);
967 Set_Scope (Any_Array, Standard_Standard);
968 Set_Etype (Any_Array, Any_Array);
969 Set_Component_Type (Any_Array, Any_Character);
970 Init_Size_Align (Any_Array);
971 Make_Name (Any_Array, "an array type");
973 Any_Boolean := New_Standard_Entity;
974 Set_Ekind (Any_Boolean, E_Enumeration_Type);
975 Set_Scope (Any_Boolean, Standard_Standard);
976 Set_Etype (Any_Boolean, Standard_Boolean);
977 Init_Esize (Any_Boolean, Standard_Character_Size);
978 Init_RM_Size (Any_Boolean, 1);
979 Set_Elem_Alignment (Any_Boolean);
980 Set_Is_Unsigned_Type (Any_Boolean);
981 Set_Scalar_Range (Any_Boolean, Scalar_Range (Standard_Boolean));
982 Make_Name (Any_Boolean, "a boolean type");
984 Any_Composite := New_Standard_Entity;
985 Set_Ekind (Any_Composite, E_Array_Type);
986 Set_Scope (Any_Composite, Standard_Standard);
987 Set_Etype (Any_Composite, Any_Composite);
988 Set_Component_Size (Any_Composite, Uint_0);
989 Set_Component_Type (Any_Composite, Standard_Integer);
990 Init_Size_Align (Any_Composite);
991 Make_Name (Any_Composite, "a composite type");
993 Any_Discrete := New_Standard_Entity;
994 Set_Ekind (Any_Discrete, E_Signed_Integer_Type);
995 Set_Scope (Any_Discrete, Standard_Standard);
996 Set_Etype (Any_Discrete, Any_Discrete);
997 Init_Size (Any_Discrete, Standard_Integer_Size);
998 Set_Elem_Alignment (Any_Discrete);
999 Make_Name (Any_Discrete, "a discrete type");
1001 Any_Fixed := New_Standard_Entity;
1002 Set_Ekind (Any_Fixed, E_Ordinary_Fixed_Point_Type);
1003 Set_Scope (Any_Fixed, Standard_Standard);
1004 Set_Etype (Any_Fixed, Any_Fixed);
1005 Init_Size (Any_Fixed, Standard_Integer_Size);
1006 Set_Elem_Alignment (Any_Fixed);
1007 Make_Name (Any_Fixed, "a fixed-point type");
1009 Any_Integer := New_Standard_Entity;
1010 Set_Ekind (Any_Integer, E_Signed_Integer_Type);
1011 Set_Scope (Any_Integer, Standard_Standard);
1012 Set_Etype (Any_Integer, Standard_Long_Long_Integer);
1013 Init_Size (Any_Integer, Standard_Long_Long_Integer_Size);
1014 Set_Elem_Alignment (Any_Integer);
1018 Typ => Base_Type (Standard_Integer),
1020 Hb => Intval (High_Bound (Scalar_Range (Standard_Integer))));
1021 Make_Name (Any_Integer, "an integer type");
1023 Any_Modular := New_Standard_Entity;
1024 Set_Ekind (Any_Modular, E_Modular_Integer_Type);
1025 Set_Scope (Any_Modular, Standard_Standard);
1026 Set_Etype (Any_Modular, Standard_Long_Long_Integer);
1027 Init_Size (Any_Modular, Standard_Long_Long_Integer_Size);
1028 Set_Elem_Alignment (Any_Modular);
1029 Set_Is_Unsigned_Type (Any_Modular);
1030 Make_Name (Any_Modular, "a modular type");
1032 Any_Numeric := New_Standard_Entity;
1033 Set_Ekind (Any_Numeric, E_Signed_Integer_Type);
1034 Set_Scope (Any_Numeric, Standard_Standard);
1035 Set_Etype (Any_Numeric, Standard_Long_Long_Integer);
1036 Init_Size (Any_Numeric, Standard_Long_Long_Integer_Size);
1037 Set_Elem_Alignment (Any_Numeric);
1038 Make_Name (Any_Numeric, "a numeric type");
1040 Any_Real := New_Standard_Entity;
1041 Set_Ekind (Any_Real, E_Floating_Point_Type);
1042 Set_Scope (Any_Real, Standard_Standard);
1043 Set_Etype (Any_Real, Standard_Long_Long_Float);
1044 Init_Size (Any_Real, Standard_Long_Long_Float_Size);
1045 Set_Elem_Alignment (Any_Real);
1046 Make_Name (Any_Real, "a real type");
1048 Any_Scalar := New_Standard_Entity;
1049 Set_Ekind (Any_Scalar, E_Signed_Integer_Type);
1050 Set_Scope (Any_Scalar, Standard_Standard);
1051 Set_Etype (Any_Scalar, Any_Scalar);
1052 Init_Size (Any_Scalar, Standard_Integer_Size);
1053 Set_Elem_Alignment (Any_Scalar);
1054 Make_Name (Any_Scalar, "a scalar type");
1056 Any_String := New_Standard_Entity;
1057 Set_Ekind (Any_String, E_String_Type);
1058 Set_Scope (Any_String, Standard_Standard);
1059 Set_Etype (Any_String, Any_String);
1060 Set_Component_Type (Any_String, Any_Character);
1061 Init_Size_Align (Any_String);
1062 Make_Name (Any_String, "a string type");
1070 Low_Bound => Make_Integer (Uint_0),
1071 High_Bound => Make_Integer (Uint_2 ** Standard_Integer_Size));
1072 Set_Etype (Index, Standard_Integer);
1073 Set_First_Index (Any_String, Index);
1076 Standard_Integer_8 := New_Standard_Entity;
1077 Decl := New_Node (N_Full_Type_Declaration, Stloc);
1078 Set_Defining_Identifier (Decl, Standard_Integer_8);
1079 Make_Name (Standard_Integer_8, "integer_8");
1080 Set_Scope (Standard_Integer_8, Standard_Standard);
1081 Build_Signed_Integer_Type (Standard_Integer_8, 8);
1083 Standard_Integer_16 := New_Standard_Entity;
1084 Decl := New_Node (N_Full_Type_Declaration, Stloc);
1085 Set_Defining_Identifier (Decl, Standard_Integer_16);
1086 Make_Name (Standard_Integer_16, "integer_16");
1087 Set_Scope (Standard_Integer_16, Standard_Standard);
1088 Build_Signed_Integer_Type (Standard_Integer_16, 16);
1090 Standard_Integer_32 := New_Standard_Entity;
1091 Decl := New_Node (N_Full_Type_Declaration, Stloc);
1092 Set_Defining_Identifier (Decl, Standard_Integer_32);
1093 Make_Name (Standard_Integer_32, "integer_32");
1094 Set_Scope (Standard_Integer_32, Standard_Standard);
1095 Build_Signed_Integer_Type (Standard_Integer_32, 32);
1097 Standard_Integer_64 := New_Standard_Entity;
1098 Decl := New_Node (N_Full_Type_Declaration, Stloc);
1099 Set_Defining_Identifier (Decl, Standard_Integer_64);
1100 Make_Name (Standard_Integer_64, "integer_64");
1101 Set_Scope (Standard_Integer_64, Standard_Standard);
1102 Build_Signed_Integer_Type (Standard_Integer_64, 64);
1104 Standard_Unsigned := New_Standard_Entity;
1105 Decl := New_Node (N_Full_Type_Declaration, Stloc);
1106 Set_Defining_Identifier (Decl, Standard_Unsigned);
1107 Make_Name (Standard_Unsigned, "unsigned");
1109 Set_Ekind (Standard_Unsigned, E_Modular_Integer_Type);
1110 Set_Scope (Standard_Unsigned, Standard_Standard);
1111 Set_Etype (Standard_Unsigned, Standard_Unsigned);
1112 Init_Size (Standard_Unsigned, Standard_Integer_Size);
1113 Set_Elem_Alignment (Standard_Unsigned);
1114 Set_Modulus (Standard_Unsigned,
1115 Uint_2 ** Standard_Integer_Size);
1116 Set_Is_Unsigned_Type (Standard_Unsigned);
1117 Set_Size_Known_At_Compile_Time
1118 (Standard_Unsigned);
1120 R_Node := New_Node (N_Range, Stloc);
1121 Set_Low_Bound (R_Node, Make_Integer (Uint_0));
1122 Set_High_Bound (R_Node, Make_Integer (Modulus (Standard_Unsigned) - 1));
1123 Set_Etype (Low_Bound (R_Node), Standard_Unsigned);
1124 Set_Etype (High_Bound (R_Node), Standard_Unsigned);
1125 Set_Scalar_Range (Standard_Unsigned, R_Node);
1127 -- Note: universal integer and universal real are constructed as fully
1128 -- formed signed numeric types, with parameters corresponding to the
1129 -- longest runtime types (Long_Long_Integer and Long_Long_Float). This
1130 -- allows Gigi to properly process references to universal types that
1131 -- are not folded at compile time.
1133 Universal_Integer := New_Standard_Entity;
1134 Decl := New_Node (N_Full_Type_Declaration, Stloc);
1135 Set_Defining_Identifier (Decl, Universal_Integer);
1136 Make_Name (Universal_Integer, "universal_integer");
1137 Set_Scope (Universal_Integer, Standard_Standard);
1138 Build_Signed_Integer_Type
1139 (Universal_Integer, Standard_Long_Long_Integer_Size);
1141 Universal_Real := New_Standard_Entity;
1142 Decl := New_Node (N_Full_Type_Declaration, Stloc);
1143 Set_Defining_Identifier (Decl, Universal_Real);
1144 Make_Name (Universal_Real, "universal_real");
1145 Set_Scope (Universal_Real, Standard_Standard);
1148 Standard_Long_Long_Float_Size,
1149 Standard_Long_Long_Float_Digits);
1151 -- Note: universal fixed, unlike universal integer and universal real,
1152 -- is never used at runtime, so it does not need to have bounds set.
1154 Universal_Fixed := New_Standard_Entity;
1155 Decl := New_Node (N_Full_Type_Declaration, Stloc);
1156 Set_Defining_Identifier (Decl, Universal_Fixed);
1157 Make_Name (Universal_Fixed, "universal_fixed");
1158 Set_Ekind (Universal_Fixed, E_Ordinary_Fixed_Point_Type);
1159 Set_Etype (Universal_Fixed, Universal_Fixed);
1160 Set_Scope (Universal_Fixed, Standard_Standard);
1161 Init_Size (Universal_Fixed, Standard_Long_Long_Integer_Size);
1162 Set_Elem_Alignment (Universal_Fixed);
1163 Set_Size_Known_At_Compile_Time
1166 -- Create type declaration for Duration, using a 64-bit size. The
1167 -- delta and size values depend on the mode set in system.ads.
1169 Build_Duration : declare
1175 -- In 32 bit mode, the size is 32 bits, and the delta and
1176 -- small values are set to 20 milliseconds (20.0**(10.0**(-3)).
1178 if Duration_32_Bits_On_Target then
1179 Dlo := Intval (Type_Low_Bound (Standard_Integer_32));
1180 Dhi := Intval (Type_High_Bound (Standard_Integer_32));
1181 Delta_Val := UR_From_Components (UI_From_Int (20), Uint_3, 10);
1183 -- In standard 64-bit mode, the size is 64-bits and the delta and
1184 -- small values are set to nanoseconds (1.0**(10.0**(-9))
1187 Dlo := Intval (Type_Low_Bound (Standard_Integer_64));
1188 Dhi := Intval (Type_High_Bound (Standard_Integer_64));
1189 Delta_Val := UR_From_Components (Uint_1, Uint_9, 10);
1192 Tdef_Node := Make_Ordinary_Fixed_Point_Definition (Stloc,
1193 Delta_Expression => Make_Real_Literal (Stloc, Delta_Val),
1194 Real_Range_Specification =>
1195 Make_Real_Range_Specification (Stloc,
1196 Low_Bound => Make_Real_Literal (Stloc,
1197 Realval => Dlo * Delta_Val),
1198 High_Bound => Make_Real_Literal (Stloc,
1199 Realval => Dhi * Delta_Val)));
1201 Set_Type_Definition (Parent (Standard_Duration), Tdef_Node);
1203 Set_Ekind (Standard_Duration, E_Ordinary_Fixed_Point_Type);
1204 Set_Etype (Standard_Duration, Standard_Duration);
1206 if Duration_32_Bits_On_Target then
1207 Init_Size (Standard_Duration, 32);
1209 Init_Size (Standard_Duration, 64);
1212 Set_Elem_Alignment (Standard_Duration);
1213 Set_Delta_Value (Standard_Duration, Delta_Val);
1214 Set_Small_Value (Standard_Duration, Delta_Val);
1215 Set_Scalar_Range (Standard_Duration,
1216 Real_Range_Specification
1217 (Type_Definition (Parent (Standard_Duration))));
1219 -- Normally it does not matter that nodes in package Standard are
1220 -- not marked as analyzed. The Scalar_Range of the fixed-point
1221 -- type Standard_Duration is an exception, because of the special
1222 -- test made in Freeze.Freeze_Fixed_Point_Type.
1224 Set_Analyzed (Scalar_Range (Standard_Duration));
1226 Set_Etype (Type_High_Bound (Standard_Duration), Standard_Duration);
1227 Set_Etype (Type_Low_Bound (Standard_Duration), Standard_Duration);
1229 Set_Is_Static_Expression (Type_High_Bound (Standard_Duration));
1230 Set_Is_Static_Expression (Type_Low_Bound (Standard_Duration));
1232 Set_Corresponding_Integer_Value
1233 (Type_High_Bound (Standard_Duration), Dhi);
1235 Set_Corresponding_Integer_Value
1236 (Type_Low_Bound (Standard_Duration), Dlo);
1238 Set_Size_Known_At_Compile_Time (Standard_Duration);
1241 -- Build standard exception type. Note that the type name here is
1242 -- actually used in the generated code, so it must be set correctly
1244 -- ??? Also note that the Import_Code component is now declared
1245 -- as a System.Standard_Library.Exception_Code to enforce run-time
1246 -- library implementation consistency. It's too early here to resort
1247 -- to rtsfind to get the proper node for that type, so we use the
1248 -- closest possible available type node at hand instead. We should
1249 -- probably be fixing this up at some point.
1251 Standard_Exception_Type := New_Standard_Entity;
1252 Set_Ekind (Standard_Exception_Type, E_Record_Type);
1253 Set_Etype (Standard_Exception_Type, Standard_Exception_Type);
1254 Set_Scope (Standard_Exception_Type, Standard_Standard);
1255 Set_Stored_Constraint
1256 (Standard_Exception_Type, No_Elist);
1257 Init_Size_Align (Standard_Exception_Type);
1258 Set_Size_Known_At_Compile_Time
1259 (Standard_Exception_Type, True);
1260 Make_Name (Standard_Exception_Type, "exception");
1262 Make_Component (Standard_Exception_Type, Standard_Boolean,
1263 "Not_Handled_By_Others");
1264 Make_Component (Standard_Exception_Type, Standard_Character, "Lang");
1265 Make_Component (Standard_Exception_Type, Standard_Natural,
1267 Make_Component (Standard_Exception_Type, Standard_A_Char,
1269 Make_Component (Standard_Exception_Type, Standard_A_Char,
1271 Make_Component (Standard_Exception_Type, Standard_Unsigned,
1273 Make_Component (Standard_Exception_Type, Standard_A_Char,
1275 -- Build tree for record declaration, for use by the back-end.
1278 Comp_List : List_Id;
1282 Comp := First_Entity (Standard_Exception_Type);
1283 Comp_List := New_List;
1285 while Present (Comp) loop
1287 Make_Component_Declaration (Stloc,
1288 Defining_Identifier => Comp,
1289 Component_Definition =>
1290 Make_Component_Definition (Stloc,
1291 Aliased_Present => False,
1292 Subtype_Indication => New_Occurrence_Of (Etype (Comp),
1299 Decl := Make_Full_Type_Declaration (Stloc,
1300 Defining_Identifier => Standard_Exception_Type,
1302 Make_Record_Definition (Stloc,
1305 Make_Component_List (Stloc,
1306 Component_Items => Comp_List)));
1309 Append (Decl, Decl_S);
1311 Layout_Type (Standard_Exception_Type);
1313 -- Create declarations of standard exceptions
1315 Build_Exception (S_Constraint_Error);
1316 Build_Exception (S_Program_Error);
1317 Build_Exception (S_Storage_Error);
1318 Build_Exception (S_Tasking_Error);
1320 -- Numeric_Error is a normal exception in Ada 83, but in Ada 95
1321 -- it is a renaming of Constraint_Error. Is this test too early???
1323 if Ada_Version = Ada_83 then
1324 Build_Exception (S_Numeric_Error);
1327 Decl := New_Node (N_Exception_Renaming_Declaration, Stloc);
1328 E_Id := Standard_Entity (S_Numeric_Error);
1330 Set_Ekind (E_Id, E_Exception);
1331 Set_Exception_Code (E_Id, Uint_0);
1332 Set_Etype (E_Id, Standard_Exception_Type);
1333 Set_Is_Public (E_Id);
1334 Set_Renamed_Entity (E_Id, Standard_Entity (S_Constraint_Error));
1336 Set_Defining_Identifier (Decl, E_Id);
1337 Append (Decl, Decl_S);
1339 Ident_Node := New_Node (N_Identifier, Stloc);
1340 Set_Chars (Ident_Node, Chars (Standard_Entity (S_Constraint_Error)));
1341 Set_Entity (Ident_Node, Standard_Entity (S_Constraint_Error));
1342 Set_Name (Decl, Ident_Node);
1345 -- Abort_Signal is an entity that does not get made visible
1347 Abort_Signal := New_Standard_Entity;
1348 Set_Chars (Abort_Signal, Name_uAbort_Signal);
1349 Set_Ekind (Abort_Signal, E_Exception);
1350 Set_Exception_Code (Abort_Signal, Uint_0);
1351 Set_Etype (Abort_Signal, Standard_Exception_Type);
1352 Set_Scope (Abort_Signal, Standard_Standard);
1353 Set_Is_Public (Abort_Signal, True);
1355 Make_Exception_Declaration (Stloc,
1356 Defining_Identifier => Abort_Signal);
1358 -- Create defining identifiers for shift operator entities. Note
1359 -- that these entities are used only for marking shift operators
1360 -- generated internally, and hence need no structure, just a name
1361 -- and a unique identity.
1363 Standard_Op_Rotate_Left := New_Standard_Entity;
1364 Set_Chars (Standard_Op_Rotate_Left, Name_Rotate_Left);
1365 Set_Ekind (Standard_Op_Rotate_Left, E_Operator);
1367 Standard_Op_Rotate_Right := New_Standard_Entity;
1368 Set_Chars (Standard_Op_Rotate_Right, Name_Rotate_Right);
1369 Set_Ekind (Standard_Op_Rotate_Right, E_Operator);
1371 Standard_Op_Shift_Left := New_Standard_Entity;
1372 Set_Chars (Standard_Op_Shift_Left, Name_Shift_Left);
1373 Set_Ekind (Standard_Op_Shift_Left, E_Operator);
1375 Standard_Op_Shift_Right := New_Standard_Entity;
1376 Set_Chars (Standard_Op_Shift_Right, Name_Shift_Right);
1377 Set_Ekind (Standard_Op_Shift_Right, E_Operator);
1379 Standard_Op_Shift_Right_Arithmetic := New_Standard_Entity;
1380 Set_Chars (Standard_Op_Shift_Right_Arithmetic,
1381 Name_Shift_Right_Arithmetic);
1382 Set_Ekind (Standard_Op_Shift_Right_Arithmetic,
1385 -- Create standard operator declarations
1389 -- Initialize visibility table with entities in Standard
1391 for E in Standard_Entity_Type loop
1392 if Ekind (Standard_Entity (E)) /= E_Operator then
1394 (Chars (Standard_Entity (E)), Standard_Entity (E));
1395 Set_Homonym (Standard_Entity (E), Empty);
1398 if E not in S_ASCII_Names then
1399 Set_Scope (Standard_Entity (E), Standard_Standard);
1400 Set_Is_Immediately_Visible (Standard_Entity (E));
1404 -- The predefined package Standard itself does not have a scope;
1405 -- it is the only entity in the system not to have one, and this
1406 -- is what identifies the package to Gigi.
1408 Set_Scope (Standard_Standard, Empty);
1410 -- Set global variables indicating last Id values and version
1412 Last_Standard_Node_Id := Last_Node_Id;
1413 Last_Standard_List_Id := Last_List_Id;
1415 -- The Error node has an Etype of Any_Type to help error recovery
1417 Set_Etype (Error, Any_Type);
1419 -- Print representation of standard if switch set
1421 if Opt.Print_Standard then
1424 end Create_Standard;
1426 ------------------------------------
1427 -- Create_Unconstrained_Base_Type --
1428 ------------------------------------
1430 procedure Create_Unconstrained_Base_Type
1434 New_Ent : constant Entity_Id := New_Copy (E);
1438 Set_Is_Constrained (E, True);
1439 Set_Is_First_Subtype (E, True);
1440 Set_Etype (E, New_Ent);
1442 Append_Entity (New_Ent, Standard_Standard);
1443 Set_Is_Constrained (New_Ent, False);
1444 Set_Etype (New_Ent, New_Ent);
1445 Set_Is_Known_Valid (New_Ent, True);
1447 if K = E_Signed_Integer_Subtype then
1448 Set_Etype (Low_Bound (Scalar_Range (E)), New_Ent);
1449 Set_Etype (High_Bound (Scalar_Range (E)), New_Ent);
1452 end Create_Unconstrained_Base_Type;
1454 --------------------
1455 -- Identifier_For --
1456 --------------------
1458 function Identifier_For (S : Standard_Entity_Type) return Node_Id is
1459 Ident_Node : Node_Id;
1462 Ident_Node := New_Node (N_Identifier, Stloc);
1463 Set_Chars (Ident_Node, Chars (Standard_Entity (S)));
1467 --------------------
1468 -- Make_Component --
1469 --------------------
1471 procedure Make_Component
1476 Id : constant Entity_Id := New_Standard_Entity;
1479 Set_Ekind (Id, E_Component);
1480 Set_Etype (Id, Typ);
1481 Set_Scope (Id, Rec);
1482 Init_Component_Location (Id);
1484 Set_Original_Record_Component (Id, Id);
1485 Make_Name (Id, Nam);
1486 Append_Entity (Id, Rec);
1493 function Make_Formal
1495 Formal_Name : String) return Entity_Id
1500 Formal := New_Standard_Entity;
1502 Set_Ekind (Formal, E_In_Parameter);
1503 Set_Mechanism (Formal, Default_Mechanism);
1504 Set_Scope (Formal, Standard_Standard);
1505 Set_Etype (Formal, Typ);
1506 Make_Name (Formal, Formal_Name);
1515 function Make_Integer (V : Uint) return Node_Id is
1516 N : constant Node_Id := Make_Integer_Literal (Stloc, V);
1518 Set_Is_Static_Expression (N);
1526 procedure Make_Name (Id : Entity_Id; Nam : String) is
1528 for J in 1 .. Nam'Length loop
1529 Name_Buffer (J) := Fold_Lower (Nam (Nam'First + (J - 1)));
1532 Name_Len := Nam'Length;
1533 Set_Chars (Id, Name_Find);
1540 function New_Operator (Op : Name_Id; Typ : Entity_Id) return Entity_Id is
1541 Ident_Node : Entity_Id;
1544 Ident_Node := Make_Defining_Identifier (Stloc, Op);
1546 Set_Is_Pure (Ident_Node, True);
1547 Set_Ekind (Ident_Node, E_Operator);
1548 Set_Etype (Ident_Node, Typ);
1549 Set_Scope (Ident_Node, Standard_Standard);
1550 Set_Homonym (Ident_Node, Get_Name_Entity_Id (Op));
1551 Set_Convention (Ident_Node, Convention_Intrinsic);
1553 Set_Is_Immediately_Visible (Ident_Node, True);
1554 Set_Is_Intrinsic_Subprogram (Ident_Node, True);
1556 Set_Name_Entity_Id (Op, Ident_Node);
1557 Append_Entity (Ident_Node, Standard_Standard);
1561 -------------------------
1562 -- New_Standard_Entity --
1563 -------------------------
1565 function New_Standard_Entity
1566 (New_Node_Kind : Node_Kind := N_Defining_Identifier) return Entity_Id
1568 E : constant Entity_Id := New_Entity (New_Node_Kind, Stloc);
1571 -- All standard entities are Pure and Public
1576 -- All standard entity names are analyzed manually, and are thus
1577 -- frozen as soon as they are created.
1581 -- Set debug information required for all standard types
1583 Set_Needs_Debug_Info (E);
1585 -- All standard entities are built with fully qualified names, so
1586 -- set the flag to prevent an abortive attempt at requalification!
1588 Set_Has_Qualified_Name (E);
1590 -- Return newly created entity to be completed by caller
1593 end New_Standard_Entity;
1595 --------------------
1596 -- Print_Standard --
1597 --------------------
1599 procedure Print_Standard is
1601 procedure P (Item : String) renames Output.Write_Line;
1602 -- Short-hand, since we do a lot of line writes here!
1604 procedure P_Int_Range (Size : Pos);
1605 -- Prints the range of an integer based on its Size
1607 procedure P_Float_Range (Id : Entity_Id);
1608 -- Prints the bounds range for the given float type entity
1614 procedure P_Float_Range (Id : Entity_Id) is
1615 Digs : constant Nat := UI_To_Int (Digits_Value (Id));
1618 Write_Str (" range ");
1620 if Vax_Float (Id) then
1621 if Digs = VAXFF_Digits then
1622 Write_Str (VAXFF_First'Universal_Literal_String);
1624 Write_Str (VAXFF_Last'Universal_Literal_String);
1626 elsif Digs = VAXDF_Digits then
1627 Write_Str (VAXDF_First'Universal_Literal_String);
1629 Write_Str (VAXDF_Last'Universal_Literal_String);
1632 pragma Assert (Digs = VAXGF_Digits);
1634 Write_Str (VAXGF_First'Universal_Literal_String);
1636 Write_Str (VAXGF_Last'Universal_Literal_String);
1639 elsif Is_AAMP_Float (Id) then
1640 if Digs = AAMPS_Digits then
1641 Write_Str (AAMPS_First'Universal_Literal_String);
1643 Write_Str (AAMPS_Last'Universal_Literal_String);
1646 pragma Assert (Digs = AAMPL_Digits);
1647 Write_Str (AAMPL_First'Universal_Literal_String);
1649 Write_Str (AAMPL_Last'Universal_Literal_String);
1652 elsif Digs = IEEES_Digits then
1653 Write_Str (IEEES_First'Universal_Literal_String);
1655 Write_Str (IEEES_Last'Universal_Literal_String);
1657 elsif Digs = IEEEL_Digits then
1658 Write_Str (IEEEL_First'Universal_Literal_String);
1660 Write_Str (IEEEL_Last'Universal_Literal_String);
1663 pragma Assert (Digs = IEEEX_Digits);
1665 Write_Str (IEEEX_First'Universal_Literal_String);
1667 Write_Str (IEEEX_Last'Universal_Literal_String);
1678 procedure P_Int_Range (Size : Pos) is
1680 Write_Str (" is range -(2 **");
1681 Write_Int (Size - 1);
1683 Write_Str (" .. +(2 **");
1684 Write_Int (Size - 1);
1685 Write_Str (" - 1);");
1689 -- Start of processing for Print_Standard
1692 P ("-- Representation of package Standard");
1694 P ("-- This is not accurate Ada, since new base types cannot be ");
1695 P ("-- created, but the listing shows the target dependent");
1696 P ("-- characteristics of the Standard types for this compiler");
1699 P ("package Standard is");
1700 P ("pragma Pure(Standard);");
1703 P (" type Boolean is (False, True);");
1704 P (" for Boolean'Size use 1;");
1705 P (" for Boolean use (False => 0, True => 1);");
1710 Write_Str (" type Integer");
1711 P_Int_Range (Standard_Integer_Size);
1712 Write_Str (" for Integer'Size use ");
1713 Write_Int (Standard_Integer_Size);
1717 P (" subtype Natural is Integer range 0 .. Integer'Last;");
1718 P (" subtype Positive is Integer range 1 .. Integer'Last;");
1721 Write_Str (" type Short_Short_Integer");
1722 P_Int_Range (Standard_Short_Short_Integer_Size);
1723 Write_Str (" for Short_Short_Integer'Size use ");
1724 Write_Int (Standard_Short_Short_Integer_Size);
1728 Write_Str (" type Short_Integer");
1729 P_Int_Range (Standard_Short_Integer_Size);
1730 Write_Str (" for Short_Integer'Size use ");
1731 Write_Int (Standard_Short_Integer_Size);
1735 Write_Str (" type Long_Integer");
1736 P_Int_Range (Standard_Long_Integer_Size);
1737 Write_Str (" for Long_Integer'Size use ");
1738 Write_Int (Standard_Long_Integer_Size);
1742 Write_Str (" type Long_Long_Integer");
1743 P_Int_Range (Standard_Long_Long_Integer_Size);
1744 Write_Str (" for Long_Long_Integer'Size use ");
1745 Write_Int (Standard_Long_Long_Integer_Size);
1749 -- Floating point types
1751 Write_Str (" type Short_Float is digits ");
1752 Write_Int (Standard_Short_Float_Digits);
1754 P_Float_Range (Standard_Short_Float);
1755 Write_Str (" for Short_Float'Size use ");
1756 Write_Int (Standard_Short_Float_Size);
1760 Write_Str (" type Float is digits ");
1761 Write_Int (Standard_Float_Digits);
1763 P_Float_Range (Standard_Float);
1764 Write_Str (" for Float'Size use ");
1765 Write_Int (Standard_Float_Size);
1769 Write_Str (" type Long_Float is digits ");
1770 Write_Int (Standard_Long_Float_Digits);
1772 P_Float_Range (Standard_Long_Float);
1773 Write_Str (" for Long_Float'Size use ");
1774 Write_Int (Standard_Long_Float_Size);
1778 Write_Str (" type Long_Long_Float is digits ");
1779 Write_Int (Standard_Long_Long_Float_Digits);
1781 P_Float_Range (Standard_Long_Long_Float);
1782 Write_Str (" for Long_Long_Float'Size use ");
1783 Write_Int (Standard_Long_Long_Float_Size);
1787 P (" type Character is (...)");
1788 Write_Str (" for Character'Size use ");
1789 Write_Int (Standard_Character_Size);
1791 P (" -- See RM A.1(35) for details of this type");
1794 P (" type Wide_Character is (...)");
1795 Write_Str (" for Wide_Character'Size use ");
1796 Write_Int (Standard_Wide_Character_Size);
1798 P (" -- See RM A.1(36) for details of this type");
1801 P (" type Wide_Wide_Character is (...)");
1802 Write_Str (" for Wide_Character'Size use ");
1803 Write_Int (Standard_Wide_Wide_Character_Size);
1805 P (" -- See RM A.1(36) for details of this type");
1807 P (" type String is array (Positive range <>) of Character;");
1808 P (" pragma Pack (String);");
1811 P (" type Wide_String is array (Positive range <>)" &
1812 " of Wide_Character;");
1813 P (" pragma Pack (Wide_String);");
1816 P (" type Wide_Wide_String is array (Positive range <>)" &
1817 " of Wide_Wide_Character;");
1818 P (" pragma Pack (Wide_Wide_String);");
1821 -- Here it's OK to use the Duration type of the host compiler since
1822 -- the implementation of Duration in GNAT is target independent.
1824 if Duration_32_Bits_On_Target then
1825 P (" type Duration is delta 0.020");
1826 P (" range -((2 ** 31 - 1) * 0.020) ..");
1827 P (" +((2 ** 31 - 1) * 0.020);");
1828 P (" for Duration'Small use 0.020;");
1830 P (" type Duration is delta 0.000000001");
1831 P (" range -((2 ** 63 - 1) * 0.000000001) ..");
1832 P (" +((2 ** 63 - 1) * 0.000000001);");
1833 P (" for Duration'Small use 0.000000001;");
1838 P (" Constraint_Error : exception;");
1839 P (" Program_Error : exception;");
1840 P (" Storage_Error : exception;");
1841 P (" Tasking_Error : exception;");
1842 P (" Numeric_Error : exception renames Constraint_Error;");
1845 P ("end Standard;");
1848 ----------------------
1849 -- Set_Float_Bounds --
1850 ----------------------
1852 procedure Set_Float_Bounds (Id : Entity_Id) is
1854 -- Low bound of literal value
1857 -- High bound of literal value
1860 -- Range specification
1862 Digs : constant Nat := UI_To_Int (Digits_Value (Id));
1863 -- Digits value, used to select bounds
1866 -- Note: for the call from Cstand to initially create the types in
1867 -- Standard, Vax_Float will always be False. Circuitry in Sem_Vfpt
1868 -- will adjust these types appropriately in the Vax_Float case if
1869 -- a pragma Float_Representation (VAX_Float) is used.
1871 if Vax_Float (Id) then
1872 if Digs = VAXFF_Digits then
1874 (VAXFF_First'Universal_Literal_String);
1876 (VAXFF_Last'Universal_Literal_String);
1878 elsif Digs = VAXDF_Digits then
1880 (VAXDF_First'Universal_Literal_String);
1882 (VAXDF_Last'Universal_Literal_String);
1885 pragma Assert (Digs = VAXGF_Digits);
1888 (VAXGF_First'Universal_Literal_String);
1890 (VAXGF_Last'Universal_Literal_String);
1893 elsif Is_AAMP_Float (Id) then
1894 if Digs = AAMPS_Digits then
1896 (AAMPS_First'Universal_Literal_String);
1898 (AAMPS_Last'Universal_Literal_String);
1901 pragma Assert (Digs = AAMPL_Digits);
1903 (AAMPL_First'Universal_Literal_String);
1905 (AAMPL_Last'Universal_Literal_String);
1908 elsif Digs = IEEES_Digits then
1910 (IEEES_First'Universal_Literal_String);
1912 (IEEES_Last'Universal_Literal_String);
1914 elsif Digs = IEEEL_Digits then
1916 (IEEEL_First'Universal_Literal_String);
1918 (IEEEL_Last'Universal_Literal_String);
1921 pragma Assert (Digs = IEEEX_Digits);
1924 (IEEEX_First'Universal_Literal_String);
1926 (IEEEX_Last'Universal_Literal_String);
1930 Set_Is_Static_Expression (L);
1933 Set_Is_Static_Expression (H);
1935 R := New_Node (N_Range, Stloc);
1936 Set_Low_Bound (R, L);
1937 Set_High_Bound (R, H);
1938 Set_Includes_Infinities (R, True);
1939 Set_Scalar_Range (Id, R);
1942 end Set_Float_Bounds;
1944 ------------------------
1945 -- Set_Integer_Bounds --
1946 ------------------------
1948 procedure Set_Integer_Bounds
1954 L : Node_Id; -- Low bound of literal value
1955 H : Node_Id; -- High bound of literal value
1956 R : Node_Id; -- Range specification
1959 L := Make_Integer (Lb);
1960 H := Make_Integer (Hb);
1965 R := New_Node (N_Range, Stloc);
1966 Set_Low_Bound (R, L);
1967 Set_High_Bound (R, H);
1968 Set_Scalar_Range (Id, R);
1971 Set_Is_Unsigned_Type (Id, Lb >= 0);
1972 end Set_Integer_Bounds;