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