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