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