Rebase.
[official-gcc.git] / gcc / ada / cstand.adb
blob2fe357666da40e417c452a783779274ea6e21c45
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);
739 Build_Signed_Integer_Type
740 (Standard_Integer, Standard_Integer_Size);
742 Build_Signed_Integer_Type
743 (Standard_Long_Integer, Standard_Long_Integer_Size);
745 Build_Signed_Integer_Type
746 (Standard_Long_Long_Integer, Standard_Long_Long_Integer_Size);
747 Set_Is_Implementation_Defined (Standard_Long_Long_Integer);
749 Create_Unconstrained_Base_Type
750 (Standard_Short_Short_Integer, E_Signed_Integer_Subtype);
751 Set_Is_Implementation_Defined (Standard_Short_Short_Integer);
753 Create_Unconstrained_Base_Type
754 (Standard_Short_Integer, E_Signed_Integer_Subtype);
756 Create_Unconstrained_Base_Type
757 (Standard_Integer, E_Signed_Integer_Subtype);
759 Create_Unconstrained_Base_Type
760 (Standard_Long_Integer, E_Signed_Integer_Subtype);
762 Create_Unconstrained_Base_Type
763 (Standard_Long_Long_Integer, E_Signed_Integer_Subtype);
764 Set_Is_Implementation_Defined (Standard_Short_Short_Integer);
766 Create_Float_Types;
768 -- Create type definition node for type Character. Note that we do not
769 -- set the Literals field, since type Character is handled with special
770 -- routine that do not need a literal list.
772 Tdef_Node := New_Node (N_Enumeration_Type_Definition, Stloc);
773 Set_Type_Definition (Parent (Standard_Character), Tdef_Node);
775 Set_Ekind (Standard_Character, E_Enumeration_Type);
776 Set_Etype (Standard_Character, Standard_Character);
777 Init_Esize (Standard_Character, Standard_Character_Size);
778 Init_RM_Size (Standard_Character, 8);
779 Set_Elem_Alignment (Standard_Character);
781 Set_Has_Pragma_Ordered (Standard_Character);
782 Set_Is_Unsigned_Type (Standard_Character);
783 Set_Is_Character_Type (Standard_Character);
784 Set_Is_Known_Valid (Standard_Character);
785 Set_Size_Known_At_Compile_Time (Standard_Character);
787 -- Create the bounds for type Character
789 R_Node := New_Node (N_Range, Stloc);
791 -- Low bound for type Character (Standard.Nul)
793 B_Node := New_Node (N_Character_Literal, Stloc);
794 Set_Is_Static_Expression (B_Node);
795 Set_Chars (B_Node, No_Name);
796 Set_Char_Literal_Value (B_Node, Uint_0);
797 Set_Entity (B_Node, Empty);
798 Set_Etype (B_Node, Standard_Character);
799 Set_Low_Bound (R_Node, B_Node);
801 -- High bound for type Character
803 B_Node := New_Node (N_Character_Literal, Stloc);
804 Set_Is_Static_Expression (B_Node);
805 Set_Chars (B_Node, No_Name);
806 Set_Char_Literal_Value (B_Node, UI_From_Int (16#FF#));
807 Set_Entity (B_Node, Empty);
808 Set_Etype (B_Node, Standard_Character);
809 Set_High_Bound (R_Node, B_Node);
811 Set_Scalar_Range (Standard_Character, R_Node);
812 Set_Etype (R_Node, Standard_Character);
813 Set_Parent (R_Node, Standard_Character);
815 -- Create type definition for type Wide_Character. Note that we do not
816 -- set the Literals field, since type Wide_Character is handled with
817 -- special routines that do not need a literal list.
819 Tdef_Node := New_Node (N_Enumeration_Type_Definition, Stloc);
820 Set_Type_Definition (Parent (Standard_Wide_Character), Tdef_Node);
822 Set_Ekind (Standard_Wide_Character, E_Enumeration_Type);
823 Set_Etype (Standard_Wide_Character, Standard_Wide_Character);
824 Init_Size (Standard_Wide_Character, Standard_Wide_Character_Size);
826 Set_Elem_Alignment (Standard_Wide_Character);
827 Set_Has_Pragma_Ordered (Standard_Wide_Character);
828 Set_Is_Unsigned_Type (Standard_Wide_Character);
829 Set_Is_Character_Type (Standard_Wide_Character);
830 Set_Is_Known_Valid (Standard_Wide_Character);
831 Set_Size_Known_At_Compile_Time (Standard_Wide_Character);
833 -- Create the bounds for type Wide_Character
835 R_Node := New_Node (N_Range, Stloc);
837 -- Low bound for type Wide_Character
839 B_Node := New_Node (N_Character_Literal, Stloc);
840 Set_Is_Static_Expression (B_Node);
841 Set_Chars (B_Node, No_Name); -- ???
842 Set_Char_Literal_Value (B_Node, Uint_0);
843 Set_Entity (B_Node, Empty);
844 Set_Etype (B_Node, Standard_Wide_Character);
845 Set_Low_Bound (R_Node, B_Node);
847 -- High bound for type Wide_Character
849 B_Node := New_Node (N_Character_Literal, Stloc);
850 Set_Is_Static_Expression (B_Node);
851 Set_Chars (B_Node, No_Name); -- ???
852 Set_Char_Literal_Value (B_Node, UI_From_Int (16#FFFF#));
853 Set_Entity (B_Node, Empty);
854 Set_Etype (B_Node, Standard_Wide_Character);
855 Set_High_Bound (R_Node, B_Node);
857 Set_Scalar_Range (Standard_Wide_Character, R_Node);
858 Set_Etype (R_Node, Standard_Wide_Character);
859 Set_Parent (R_Node, Standard_Wide_Character);
861 -- Create type definition for type Wide_Wide_Character. Note that we
862 -- do not set the Literals field, since type Wide_Wide_Character is
863 -- handled with special routines that do not need a literal list.
865 Tdef_Node := New_Node (N_Enumeration_Type_Definition, Stloc);
866 Set_Type_Definition (Parent (Standard_Wide_Wide_Character), Tdef_Node);
868 Set_Ekind (Standard_Wide_Wide_Character, E_Enumeration_Type);
869 Set_Etype (Standard_Wide_Wide_Character,
870 Standard_Wide_Wide_Character);
871 Init_Size (Standard_Wide_Wide_Character,
872 Standard_Wide_Wide_Character_Size);
874 Set_Elem_Alignment (Standard_Wide_Wide_Character);
875 Set_Has_Pragma_Ordered (Standard_Wide_Wide_Character);
876 Set_Is_Unsigned_Type (Standard_Wide_Wide_Character);
877 Set_Is_Character_Type (Standard_Wide_Wide_Character);
878 Set_Is_Known_Valid (Standard_Wide_Wide_Character);
879 Set_Size_Known_At_Compile_Time (Standard_Wide_Wide_Character);
880 Set_Is_Ada_2005_Only (Standard_Wide_Wide_Character);
882 -- Create the bounds for type Wide_Wide_Character
884 R_Node := New_Node (N_Range, Stloc);
886 -- Low bound for type Wide_Wide_Character
888 B_Node := New_Node (N_Character_Literal, Stloc);
889 Set_Is_Static_Expression (B_Node);
890 Set_Chars (B_Node, No_Name); -- ???
891 Set_Char_Literal_Value (B_Node, Uint_0);
892 Set_Entity (B_Node, Empty);
893 Set_Etype (B_Node, Standard_Wide_Wide_Character);
894 Set_Low_Bound (R_Node, B_Node);
896 -- High bound for type Wide_Wide_Character
898 B_Node := New_Node (N_Character_Literal, Stloc);
899 Set_Is_Static_Expression (B_Node);
900 Set_Chars (B_Node, No_Name); -- ???
901 Set_Char_Literal_Value (B_Node, UI_From_Int (16#7FFF_FFFF#));
902 Set_Entity (B_Node, Empty);
903 Set_Etype (B_Node, Standard_Wide_Wide_Character);
904 Set_High_Bound (R_Node, B_Node);
906 Set_Scalar_Range (Standard_Wide_Wide_Character, R_Node);
907 Set_Etype (R_Node, Standard_Wide_Wide_Character);
908 Set_Parent (R_Node, Standard_Wide_Wide_Character);
910 -- Create type definition node for type String
912 Tdef_Node := New_Node (N_Unconstrained_Array_Definition, Stloc);
914 declare
915 CompDef_Node : Node_Id;
916 begin
917 CompDef_Node := New_Node (N_Component_Definition, Stloc);
918 Set_Aliased_Present (CompDef_Node, False);
919 Set_Access_Definition (CompDef_Node, Empty);
920 Set_Subtype_Indication (CompDef_Node, Identifier_For (S_Character));
921 Set_Component_Definition (Tdef_Node, CompDef_Node);
922 end;
924 Set_Subtype_Marks (Tdef_Node, New_List);
925 Append (Identifier_For (S_Positive), Subtype_Marks (Tdef_Node));
926 Set_Type_Definition (Parent (Standard_String), Tdef_Node);
928 Set_Ekind (Standard_String, E_Array_Type);
929 Set_Etype (Standard_String, Standard_String);
930 Set_Component_Type (Standard_String, Standard_Character);
931 Set_Component_Size (Standard_String, Uint_8);
932 Init_Size_Align (Standard_String);
933 Set_Alignment (Standard_String, Uint_1);
934 Pack_String_Type (Standard_String);
936 -- On targets where a storage unit is larger than a byte (such as AAMP),
937 -- pragma Pack has a real effect on the representation of type String,
938 -- and the type must be marked as having a nonstandard representation.
940 if System_Storage_Unit > Uint_8 then
941 Set_Has_Non_Standard_Rep (Standard_String);
942 Set_Has_Pragma_Pack (Standard_String);
943 end if;
945 -- Set index type of String
947 E_Id :=
948 First (Subtype_Marks (Type_Definition (Parent (Standard_String))));
949 Set_First_Index (Standard_String, E_Id);
950 Set_Entity (E_Id, Standard_Positive);
951 Set_Etype (E_Id, Standard_Positive);
953 -- Create type definition node for type Wide_String
955 Tdef_Node := New_Node (N_Unconstrained_Array_Definition, Stloc);
957 declare
958 CompDef_Node : Node_Id;
959 begin
960 CompDef_Node := New_Node (N_Component_Definition, Stloc);
961 Set_Aliased_Present (CompDef_Node, False);
962 Set_Access_Definition (CompDef_Node, Empty);
963 Set_Subtype_Indication (CompDef_Node,
964 Identifier_For (S_Wide_Character));
965 Set_Component_Definition (Tdef_Node, CompDef_Node);
966 end;
968 Set_Subtype_Marks (Tdef_Node, New_List);
969 Append (Identifier_For (S_Positive), Subtype_Marks (Tdef_Node));
970 Set_Type_Definition (Parent (Standard_Wide_String), Tdef_Node);
972 Set_Ekind (Standard_Wide_String, E_Array_Type);
973 Set_Etype (Standard_Wide_String, Standard_Wide_String);
974 Set_Component_Type (Standard_Wide_String, Standard_Wide_Character);
975 Set_Component_Size (Standard_Wide_String, Uint_16);
976 Init_Size_Align (Standard_Wide_String);
977 Pack_String_Type (Standard_Wide_String);
979 -- Set index type of Wide_String
981 E_Id :=
982 First
983 (Subtype_Marks (Type_Definition (Parent (Standard_Wide_String))));
984 Set_First_Index (Standard_Wide_String, E_Id);
985 Set_Entity (E_Id, Standard_Positive);
986 Set_Etype (E_Id, Standard_Positive);
988 -- Create type definition node for type Wide_Wide_String
990 Tdef_Node := New_Node (N_Unconstrained_Array_Definition, Stloc);
992 declare
993 CompDef_Node : Node_Id;
994 begin
995 CompDef_Node := New_Node (N_Component_Definition, Stloc);
996 Set_Aliased_Present (CompDef_Node, False);
997 Set_Access_Definition (CompDef_Node, Empty);
998 Set_Subtype_Indication (CompDef_Node,
999 Identifier_For (S_Wide_Wide_Character));
1000 Set_Component_Definition (Tdef_Node, CompDef_Node);
1001 end;
1003 Set_Subtype_Marks (Tdef_Node, New_List);
1004 Append (Identifier_For (S_Positive), Subtype_Marks (Tdef_Node));
1005 Set_Type_Definition (Parent (Standard_Wide_Wide_String), Tdef_Node);
1007 Set_Ekind (Standard_Wide_Wide_String, E_Array_Type);
1008 Set_Etype (Standard_Wide_Wide_String,
1009 Standard_Wide_Wide_String);
1010 Set_Component_Type (Standard_Wide_Wide_String,
1011 Standard_Wide_Wide_Character);
1012 Set_Component_Size (Standard_Wide_Wide_String, Uint_32);
1013 Init_Size_Align (Standard_Wide_Wide_String);
1014 Set_Is_Ada_2005_Only (Standard_Wide_Wide_String);
1015 Pack_String_Type (Standard_Wide_Wide_String);
1017 -- Set index type of Wide_Wide_String
1019 E_Id :=
1020 First
1021 (Subtype_Marks
1022 (Type_Definition (Parent (Standard_Wide_Wide_String))));
1023 Set_First_Index (Standard_Wide_Wide_String, E_Id);
1024 Set_Entity (E_Id, Standard_Positive);
1025 Set_Etype (E_Id, Standard_Positive);
1027 -- Setup entity for Natural
1029 Set_Ekind (Standard_Natural, E_Signed_Integer_Subtype);
1030 Set_Etype (Standard_Natural, Base_Type (Standard_Integer));
1031 Init_Esize (Standard_Natural, Standard_Integer_Size);
1032 Init_RM_Size (Standard_Natural, Standard_Integer_Size - 1);
1033 Set_Elem_Alignment (Standard_Natural);
1034 Set_Size_Known_At_Compile_Time
1035 (Standard_Natural);
1036 Set_Integer_Bounds (Standard_Natural,
1037 Typ => Base_Type (Standard_Integer),
1038 Lb => Uint_0,
1039 Hb => Intval (High_Bound (Scalar_Range (Standard_Integer))));
1040 Set_Is_Constrained (Standard_Natural);
1042 -- Setup entity for Positive
1044 Set_Ekind (Standard_Positive, E_Signed_Integer_Subtype);
1045 Set_Etype (Standard_Positive, Base_Type (Standard_Integer));
1046 Init_Esize (Standard_Positive, Standard_Integer_Size);
1047 Init_RM_Size (Standard_Positive, Standard_Integer_Size - 1);
1048 Set_Elem_Alignment (Standard_Positive);
1050 Set_Size_Known_At_Compile_Time (Standard_Positive);
1052 Set_Integer_Bounds (Standard_Positive,
1053 Typ => Base_Type (Standard_Integer),
1054 Lb => Uint_1,
1055 Hb => Intval (High_Bound (Scalar_Range (Standard_Integer))));
1056 Set_Is_Constrained (Standard_Positive);
1058 -- Create declaration for package ASCII
1060 Decl := New_Node (N_Package_Declaration, Stloc);
1061 Append (Decl, Decl_S);
1063 Pspec := New_Node (N_Package_Specification, Stloc);
1064 Set_Specification (Decl, Pspec);
1066 Set_Defining_Unit_Name (Pspec, Standard_Entity (S_ASCII));
1067 Set_Ekind (Standard_Entity (S_ASCII), E_Package);
1068 Set_Visible_Declarations (Pspec, Decl_A);
1070 -- Create control character definitions in package ASCII. Note that
1071 -- the character literal entries created here correspond to literal
1072 -- values that are impossible in the source, but can be represented
1073 -- internally with no difficulties.
1075 Ccode := 16#00#;
1077 for S in S_ASCII_Names loop
1078 Decl := New_Node (N_Object_Declaration, Staloc);
1079 Set_Constant_Present (Decl, True);
1081 declare
1082 A_Char : constant Entity_Id := Standard_Entity (S);
1083 Expr_Decl : Node_Id;
1085 begin
1086 Set_Sloc (A_Char, Staloc);
1087 Set_Ekind (A_Char, E_Constant);
1088 Set_Never_Set_In_Source (A_Char, True);
1089 Set_Is_True_Constant (A_Char, True);
1090 Set_Etype (A_Char, Standard_Character);
1091 Set_Scope (A_Char, Standard_Entity (S_ASCII));
1092 Set_Is_Immediately_Visible (A_Char, False);
1093 Set_Is_Public (A_Char, True);
1094 Set_Is_Known_Valid (A_Char, True);
1096 Append_Entity (A_Char, Standard_Entity (S_ASCII));
1097 Set_Defining_Identifier (Decl, A_Char);
1099 Set_Object_Definition (Decl, Identifier_For (S_Character));
1100 Expr_Decl := New_Node (N_Character_Literal, Staloc);
1101 Set_Expression (Decl, Expr_Decl);
1103 Set_Is_Static_Expression (Expr_Decl);
1104 Set_Chars (Expr_Decl, No_Name);
1105 Set_Etype (Expr_Decl, Standard_Character);
1106 Set_Char_Literal_Value (Expr_Decl, UI_From_Int (Int (Ccode)));
1107 end;
1109 Append (Decl, Decl_A);
1111 -- Increment character code, dealing with non-contiguities
1113 Ccode := Ccode + 1;
1115 if Ccode = 16#20# then
1116 Ccode := 16#21#;
1117 elsif Ccode = 16#27# then
1118 Ccode := 16#3A#;
1119 elsif Ccode = 16#3C# then
1120 Ccode := 16#3F#;
1121 elsif Ccode = 16#41# then
1122 Ccode := 16#5B#;
1123 end if;
1124 end loop;
1126 -- Create semantic phase entities
1128 Standard_Void_Type := New_Standard_Entity;
1129 Set_Ekind (Standard_Void_Type, E_Void);
1130 Set_Etype (Standard_Void_Type, Standard_Void_Type);
1131 Set_Scope (Standard_Void_Type, Standard_Standard);
1132 Make_Name (Standard_Void_Type, "_void_type");
1134 -- The type field of packages is set to void
1136 Set_Etype (Standard_Standard, Standard_Void_Type);
1137 Set_Etype (Standard_ASCII, Standard_Void_Type);
1139 -- Standard_A_String is actually used in generated code, so it has a
1140 -- type name that is reasonable, but does not overlap any Ada name.
1142 Standard_A_String := New_Standard_Entity;
1143 Set_Ekind (Standard_A_String, E_Access_Type);
1144 Set_Scope (Standard_A_String, Standard_Standard);
1145 Set_Etype (Standard_A_String, Standard_A_String);
1147 if Debug_Flag_6 then
1148 Init_Size (Standard_A_String, System_Address_Size);
1149 else
1150 Init_Size (Standard_A_String, System_Address_Size * 2);
1151 end if;
1153 Init_Alignment (Standard_A_String);
1155 Set_Directly_Designated_Type
1156 (Standard_A_String, Standard_String);
1157 Make_Name (Standard_A_String, "access_string");
1159 Standard_A_Char := New_Standard_Entity;
1160 Set_Ekind (Standard_A_Char, E_Access_Type);
1161 Set_Scope (Standard_A_Char, Standard_Standard);
1162 Set_Etype (Standard_A_Char, Standard_A_String);
1163 Init_Size (Standard_A_Char, System_Address_Size);
1164 Set_Elem_Alignment (Standard_A_Char);
1166 Set_Directly_Designated_Type (Standard_A_Char, Standard_Character);
1167 Make_Name (Standard_A_Char, "access_character");
1169 -- Standard_Debug_Renaming_Type is used for the special objects created
1170 -- to encode the names occurring in renaming declarations for use by the
1171 -- debugger (see exp_dbug.adb). The type is a zero-sized subtype of
1172 -- Standard.Integer.
1174 Standard_Debug_Renaming_Type := New_Standard_Entity;
1176 Set_Ekind (Standard_Debug_Renaming_Type, E_Signed_Integer_Subtype);
1177 Set_Scope (Standard_Debug_Renaming_Type, Standard_Standard);
1178 Set_Etype (Standard_Debug_Renaming_Type, Base_Type (Standard_Integer));
1179 Init_Esize (Standard_Debug_Renaming_Type, 0);
1180 Init_RM_Size (Standard_Debug_Renaming_Type, 0);
1181 Set_Size_Known_At_Compile_Time (Standard_Debug_Renaming_Type);
1182 Set_Integer_Bounds (Standard_Debug_Renaming_Type,
1183 Typ => Base_Type (Standard_Debug_Renaming_Type),
1184 Lb => Uint_1,
1185 Hb => Uint_0);
1186 Set_Is_Constrained (Standard_Debug_Renaming_Type);
1187 Set_Has_Size_Clause (Standard_Debug_Renaming_Type);
1189 Make_Name (Standard_Debug_Renaming_Type, "_renaming_type");
1191 -- Note on type names. The type names for the following special types
1192 -- are constructed so that they will look reasonable should they ever
1193 -- appear in error messages etc, although in practice the use of the
1194 -- special insertion character } for types results in special handling
1195 -- of these type names in any case. The blanks in these names would
1196 -- trouble in Gigi, but that's OK here, since none of these types
1197 -- should ever get through to Gigi. Attributes of these types are
1198 -- filled out to minimize problems with cascaded errors (for example,
1199 -- Any_Integer is given reasonable and consistent type and size values)
1201 Any_Type := New_Standard_Entity ("any type");
1202 Decl := New_Node (N_Full_Type_Declaration, Stloc);
1203 Set_Defining_Identifier (Decl, Any_Type);
1204 Set_Scope (Any_Type, Standard_Standard);
1205 Build_Signed_Integer_Type (Any_Type, Standard_Integer_Size);
1207 Any_Id := New_Standard_Entity ("any id");
1208 Set_Ekind (Any_Id, E_Variable);
1209 Set_Scope (Any_Id, Standard_Standard);
1210 Set_Etype (Any_Id, Any_Type);
1211 Init_Esize (Any_Id);
1212 Init_Alignment (Any_Id);
1214 Any_Access := New_Standard_Entity ("an access type");
1215 Set_Ekind (Any_Access, E_Access_Type);
1216 Set_Scope (Any_Access, Standard_Standard);
1217 Set_Etype (Any_Access, Any_Access);
1218 Init_Size (Any_Access, System_Address_Size);
1219 Set_Elem_Alignment (Any_Access);
1221 Any_Character := New_Standard_Entity ("a character type");
1222 Set_Ekind (Any_Character, E_Enumeration_Type);
1223 Set_Scope (Any_Character, Standard_Standard);
1224 Set_Etype (Any_Character, Any_Character);
1225 Set_Is_Unsigned_Type (Any_Character);
1226 Set_Is_Character_Type (Any_Character);
1227 Init_Esize (Any_Character, Standard_Character_Size);
1228 Init_RM_Size (Any_Character, 8);
1229 Set_Elem_Alignment (Any_Character);
1230 Set_Scalar_Range (Any_Character, Scalar_Range (Standard_Character));
1232 Any_Array := New_Standard_Entity ("an array type");
1233 Set_Ekind (Any_Array, E_Array_Type);
1234 Set_Scope (Any_Array, Standard_Standard);
1235 Set_Etype (Any_Array, Any_Array);
1236 Set_Component_Type (Any_Array, Any_Character);
1237 Init_Size_Align (Any_Array);
1238 Make_Dummy_Index (Any_Array);
1240 Any_Boolean := New_Standard_Entity ("a boolean type");
1241 Set_Ekind (Any_Boolean, E_Enumeration_Type);
1242 Set_Scope (Any_Boolean, Standard_Standard);
1243 Set_Etype (Any_Boolean, Standard_Boolean);
1244 Init_Esize (Any_Boolean, Standard_Character_Size);
1245 Init_RM_Size (Any_Boolean, 1);
1246 Set_Elem_Alignment (Any_Boolean);
1247 Set_Is_Unsigned_Type (Any_Boolean);
1248 Set_Scalar_Range (Any_Boolean, Scalar_Range (Standard_Boolean));
1250 Any_Composite := New_Standard_Entity ("a composite type");
1251 Set_Ekind (Any_Composite, E_Array_Type);
1252 Set_Scope (Any_Composite, Standard_Standard);
1253 Set_Etype (Any_Composite, Any_Composite);
1254 Set_Component_Size (Any_Composite, Uint_0);
1255 Set_Component_Type (Any_Composite, Standard_Integer);
1256 Init_Size_Align (Any_Composite);
1258 Any_Discrete := New_Standard_Entity ("a discrete type");
1259 Set_Ekind (Any_Discrete, E_Signed_Integer_Type);
1260 Set_Scope (Any_Discrete, Standard_Standard);
1261 Set_Etype (Any_Discrete, Any_Discrete);
1262 Init_Size (Any_Discrete, Standard_Integer_Size);
1263 Set_Elem_Alignment (Any_Discrete);
1265 Any_Fixed := New_Standard_Entity ("a fixed-point type");
1266 Set_Ekind (Any_Fixed, E_Ordinary_Fixed_Point_Type);
1267 Set_Scope (Any_Fixed, Standard_Standard);
1268 Set_Etype (Any_Fixed, Any_Fixed);
1269 Init_Size (Any_Fixed, Standard_Integer_Size);
1270 Set_Elem_Alignment (Any_Fixed);
1272 Any_Integer := New_Standard_Entity ("an integer type");
1273 Set_Ekind (Any_Integer, E_Signed_Integer_Type);
1274 Set_Scope (Any_Integer, Standard_Standard);
1275 Set_Etype (Any_Integer, Standard_Long_Long_Integer);
1276 Init_Size (Any_Integer, Standard_Long_Long_Integer_Size);
1277 Set_Elem_Alignment (Any_Integer);
1279 Set_Integer_Bounds
1280 (Any_Integer,
1281 Typ => Base_Type (Standard_Integer),
1282 Lb => Uint_0,
1283 Hb => Intval (High_Bound (Scalar_Range (Standard_Integer))));
1285 Any_Modular := New_Standard_Entity ("a modular type");
1286 Set_Ekind (Any_Modular, E_Modular_Integer_Type);
1287 Set_Scope (Any_Modular, Standard_Standard);
1288 Set_Etype (Any_Modular, Standard_Long_Long_Integer);
1289 Init_Size (Any_Modular, Standard_Long_Long_Integer_Size);
1290 Set_Elem_Alignment (Any_Modular);
1291 Set_Is_Unsigned_Type (Any_Modular);
1293 Any_Numeric := New_Standard_Entity ("a numeric type");
1294 Set_Ekind (Any_Numeric, E_Signed_Integer_Type);
1295 Set_Scope (Any_Numeric, Standard_Standard);
1296 Set_Etype (Any_Numeric, Standard_Long_Long_Integer);
1297 Init_Size (Any_Numeric, Standard_Long_Long_Integer_Size);
1298 Set_Elem_Alignment (Any_Numeric);
1300 Any_Real := New_Standard_Entity ("a real type");
1301 Set_Ekind (Any_Real, E_Floating_Point_Type);
1302 Set_Scope (Any_Real, Standard_Standard);
1303 Set_Etype (Any_Real, Standard_Long_Long_Float);
1304 Init_Size (Any_Real,
1305 UI_To_Int (Esize (Standard_Long_Long_Float)));
1306 Set_Elem_Alignment (Any_Real);
1308 Any_Scalar := New_Standard_Entity ("a scalar type");
1309 Set_Ekind (Any_Scalar, E_Signed_Integer_Type);
1310 Set_Scope (Any_Scalar, Standard_Standard);
1311 Set_Etype (Any_Scalar, Any_Scalar);
1312 Init_Size (Any_Scalar, Standard_Integer_Size);
1313 Set_Elem_Alignment (Any_Scalar);
1315 Any_String := New_Standard_Entity ("a string type");
1316 Set_Ekind (Any_String, E_Array_Type);
1317 Set_Scope (Any_String, Standard_Standard);
1318 Set_Etype (Any_String, Any_String);
1319 Set_Component_Type (Any_String, Any_Character);
1320 Init_Size_Align (Any_String);
1321 Make_Dummy_Index (Any_String);
1323 Raise_Type := New_Standard_Entity ("raise type");
1324 Decl := New_Node (N_Full_Type_Declaration, Stloc);
1325 Set_Defining_Identifier (Decl, Raise_Type);
1326 Set_Scope (Raise_Type, Standard_Standard);
1327 Build_Signed_Integer_Type (Raise_Type, Standard_Integer_Size);
1329 Standard_Integer_8 := New_Standard_Entity ("integer_8");
1330 Decl := New_Node (N_Full_Type_Declaration, Stloc);
1331 Set_Defining_Identifier (Decl, Standard_Integer_8);
1332 Set_Scope (Standard_Integer_8, Standard_Standard);
1333 Build_Signed_Integer_Type (Standard_Integer_8, 8);
1335 Standard_Integer_16 := New_Standard_Entity ("integer_16");
1336 Decl := New_Node (N_Full_Type_Declaration, Stloc);
1337 Set_Defining_Identifier (Decl, Standard_Integer_16);
1338 Set_Scope (Standard_Integer_16, Standard_Standard);
1339 Build_Signed_Integer_Type (Standard_Integer_16, 16);
1341 Standard_Integer_32 := New_Standard_Entity ("integer_32");
1342 Decl := New_Node (N_Full_Type_Declaration, Stloc);
1343 Set_Defining_Identifier (Decl, Standard_Integer_32);
1344 Set_Scope (Standard_Integer_32, Standard_Standard);
1345 Build_Signed_Integer_Type (Standard_Integer_32, 32);
1347 Standard_Integer_64 := New_Standard_Entity ("integer_64");
1348 Decl := New_Node (N_Full_Type_Declaration, Stloc);
1349 Set_Defining_Identifier (Decl, Standard_Integer_64);
1350 Set_Scope (Standard_Integer_64, Standard_Standard);
1351 Build_Signed_Integer_Type (Standard_Integer_64, 64);
1353 -- Standard_*_Unsigned subtypes are not user visible, but they are
1354 -- used internally. They are unsigned types with the same length as
1355 -- the correspondingly named signed integer types.
1357 Standard_Short_Short_Unsigned := New_Standard_Entity;
1358 Build_Unsigned_Integer_Type
1359 (Standard_Short_Short_Unsigned,
1360 Standard_Short_Short_Integer_Size,
1361 "short_short_unsigned");
1363 Standard_Short_Unsigned := New_Standard_Entity;
1364 Build_Unsigned_Integer_Type
1365 (Standard_Short_Unsigned,
1366 Standard_Short_Integer_Size,
1367 "short_unsigned");
1369 Standard_Unsigned := New_Standard_Entity;
1370 Build_Unsigned_Integer_Type
1371 (Standard_Unsigned,
1372 Standard_Integer_Size,
1373 "unsigned");
1375 Standard_Long_Unsigned := New_Standard_Entity;
1376 Build_Unsigned_Integer_Type
1377 (Standard_Long_Unsigned,
1378 Standard_Long_Integer_Size,
1379 "long_unsigned");
1381 Standard_Long_Long_Unsigned := New_Standard_Entity;
1382 Build_Unsigned_Integer_Type
1383 (Standard_Long_Long_Unsigned,
1384 Standard_Long_Long_Integer_Size,
1385 "long_long_unsigned");
1387 -- Standard_Unsigned_64 is not user visible, but is used internally. It
1388 -- is an unsigned type mod 2**64, 64-bits unsigned, size is 64.
1390 Standard_Unsigned_64 := New_Standard_Entity;
1391 Build_Unsigned_Integer_Type (Standard_Unsigned_64, 64, "unsigned_64");
1393 -- Note: universal integer and universal real are constructed as fully
1394 -- formed signed numeric types, with parameters corresponding to the
1395 -- longest runtime types (Long_Long_Integer and Long_Long_Float). This
1396 -- allows Gigi to properly process references to universal types that
1397 -- are not folded at compile time.
1399 Universal_Integer := New_Standard_Entity;
1400 Decl := New_Node (N_Full_Type_Declaration, Stloc);
1401 Set_Defining_Identifier (Decl, Universal_Integer);
1402 Make_Name (Universal_Integer, "universal_integer");
1403 Set_Scope (Universal_Integer, Standard_Standard);
1404 Build_Signed_Integer_Type
1405 (Universal_Integer, Standard_Long_Long_Integer_Size);
1407 Universal_Real := New_Standard_Entity;
1408 Decl := New_Node (N_Full_Type_Declaration, Stloc);
1409 Set_Defining_Identifier (Decl, Universal_Real);
1410 Make_Name (Universal_Real, "universal_real");
1411 Set_Scope (Universal_Real, Standard_Standard);
1412 Copy_Float_Type (Universal_Real, Standard_Long_Long_Float);
1414 -- Note: universal fixed, unlike universal integer and universal real,
1415 -- is never used at runtime, so it does not need to have bounds set.
1417 Universal_Fixed := New_Standard_Entity;
1418 Decl := New_Node (N_Full_Type_Declaration, Stloc);
1419 Set_Defining_Identifier (Decl, Universal_Fixed);
1420 Make_Name (Universal_Fixed, "universal_fixed");
1421 Set_Ekind (Universal_Fixed, E_Ordinary_Fixed_Point_Type);
1422 Set_Etype (Universal_Fixed, Universal_Fixed);
1423 Set_Scope (Universal_Fixed, Standard_Standard);
1424 Init_Size (Universal_Fixed, Standard_Long_Long_Integer_Size);
1425 Set_Elem_Alignment (Universal_Fixed);
1426 Set_Size_Known_At_Compile_Time
1427 (Universal_Fixed);
1429 -- Create type declaration for Duration, using a 64-bit size. The
1430 -- delta and size values depend on the mode set in system.ads.
1432 Build_Duration : declare
1433 Dlo : Uint;
1434 Dhi : Uint;
1435 Delta_Val : Ureal;
1437 begin
1438 -- In 32 bit mode, the size is 32 bits, and the delta and
1439 -- small values are set to 20 milliseconds (20.0*(10.0**(-3)).
1441 if Duration_32_Bits_On_Target then
1442 Dlo := Intval (Type_Low_Bound (Standard_Integer_32));
1443 Dhi := Intval (Type_High_Bound (Standard_Integer_32));
1444 Delta_Val := UR_From_Components (UI_From_Int (20), Uint_3, 10);
1446 -- In standard 64-bit mode, the size is 64-bits and the delta and
1447 -- small values are set to nanoseconds (1.0*(10.0**(-9))
1449 else
1450 Dlo := Intval (Type_Low_Bound (Standard_Integer_64));
1451 Dhi := Intval (Type_High_Bound (Standard_Integer_64));
1452 Delta_Val := UR_From_Components (Uint_1, Uint_9, 10);
1453 end if;
1455 Tdef_Node := Make_Ordinary_Fixed_Point_Definition (Stloc,
1456 Delta_Expression => Make_Real_Literal (Stloc, Delta_Val),
1457 Real_Range_Specification =>
1458 Make_Real_Range_Specification (Stloc,
1459 Low_Bound => Make_Real_Literal (Stloc,
1460 Realval => Dlo * Delta_Val),
1461 High_Bound => Make_Real_Literal (Stloc,
1462 Realval => Dhi * Delta_Val)));
1464 Set_Type_Definition (Parent (Standard_Duration), Tdef_Node);
1466 Set_Ekind (Standard_Duration, E_Ordinary_Fixed_Point_Type);
1467 Set_Etype (Standard_Duration, Standard_Duration);
1469 if Duration_32_Bits_On_Target then
1470 Init_Size (Standard_Duration, 32);
1471 else
1472 Init_Size (Standard_Duration, 64);
1473 end if;
1475 Set_Elem_Alignment (Standard_Duration);
1476 Set_Delta_Value (Standard_Duration, Delta_Val);
1477 Set_Small_Value (Standard_Duration, Delta_Val);
1478 Set_Scalar_Range (Standard_Duration,
1479 Real_Range_Specification
1480 (Type_Definition (Parent (Standard_Duration))));
1482 -- Normally it does not matter that nodes in package Standard are
1483 -- not marked as analyzed. The Scalar_Range of the fixed-point type
1484 -- Standard_Duration is an exception, because of the special test
1485 -- made in Freeze.Freeze_Fixed_Point_Type.
1487 Set_Analyzed (Scalar_Range (Standard_Duration));
1489 Set_Etype (Type_High_Bound (Standard_Duration), Standard_Duration);
1490 Set_Etype (Type_Low_Bound (Standard_Duration), Standard_Duration);
1492 Set_Is_Static_Expression (Type_High_Bound (Standard_Duration));
1493 Set_Is_Static_Expression (Type_Low_Bound (Standard_Duration));
1495 Set_Corresponding_Integer_Value
1496 (Type_High_Bound (Standard_Duration), Dhi);
1498 Set_Corresponding_Integer_Value
1499 (Type_Low_Bound (Standard_Duration), Dlo);
1501 Set_Size_Known_At_Compile_Time (Standard_Duration);
1502 end Build_Duration;
1504 -- Build standard exception type. Note that the type name here is
1505 -- actually used in the generated code, so it must be set correctly.
1506 -- The type Standard_Exception_Type must be consistent with the type
1507 -- System.Standard_Library.Exception_Data, as the latter is what is
1508 -- known by the run-time. Components of the record are documented in
1509 -- the declaration in System.Standard_Library.
1511 Standard_Exception_Type := New_Standard_Entity;
1512 Set_Ekind (Standard_Exception_Type, E_Record_Type);
1513 Set_Etype (Standard_Exception_Type, Standard_Exception_Type);
1514 Set_Scope (Standard_Exception_Type, Standard_Standard);
1515 Set_Stored_Constraint
1516 (Standard_Exception_Type, No_Elist);
1517 Init_Size_Align (Standard_Exception_Type);
1518 Set_Size_Known_At_Compile_Time
1519 (Standard_Exception_Type, True);
1520 Make_Name (Standard_Exception_Type, "exception");
1522 Make_Component
1523 (Standard_Exception_Type, Standard_Boolean, "Not_Handled_By_Others");
1524 Make_Component
1525 (Standard_Exception_Type, Standard_Character, "Lang");
1526 Make_Component
1527 (Standard_Exception_Type, Standard_Natural, "Name_Length");
1528 Make_Component
1529 (Standard_Exception_Type, Standard_A_Char, "Full_Name");
1530 Make_Component
1531 (Standard_Exception_Type, Standard_A_Char, "HTable_Ptr");
1532 Make_Component
1533 (Standard_Exception_Type, Standard_A_Char, "Foreign_Data");
1534 Make_Component
1535 (Standard_Exception_Type, Standard_A_Char, "Raise_Hook");
1537 -- Build tree for record declaration, for use by the back-end
1539 declare
1540 Comp_List : List_Id;
1541 Comp : Entity_Id;
1543 begin
1544 Comp := First_Entity (Standard_Exception_Type);
1545 Comp_List := New_List;
1546 while Present (Comp) loop
1547 Append (
1548 Make_Component_Declaration (Stloc,
1549 Defining_Identifier => Comp,
1550 Component_Definition =>
1551 Make_Component_Definition (Stloc,
1552 Aliased_Present => False,
1553 Subtype_Indication => New_Occurrence_Of (Etype (Comp),
1554 Stloc))),
1555 Comp_List);
1557 Next_Entity (Comp);
1558 end loop;
1560 Decl := Make_Full_Type_Declaration (Stloc,
1561 Defining_Identifier => Standard_Exception_Type,
1562 Type_Definition =>
1563 Make_Record_Definition (Stloc,
1564 End_Label => Empty,
1565 Component_List =>
1566 Make_Component_List (Stloc,
1567 Component_Items => Comp_List)));
1568 end;
1570 Append (Decl, Decl_S);
1572 Layout_Type (Standard_Exception_Type);
1574 -- Create declarations of standard exceptions
1576 Build_Exception (S_Constraint_Error);
1577 Build_Exception (S_Program_Error);
1578 Build_Exception (S_Storage_Error);
1579 Build_Exception (S_Tasking_Error);
1581 -- Numeric_Error is a normal exception in Ada 83, but in Ada 95
1582 -- it is a renaming of Constraint_Error. Is this test too early???
1584 if Ada_Version = Ada_83 then
1585 Build_Exception (S_Numeric_Error);
1587 else
1588 Decl := New_Node (N_Exception_Renaming_Declaration, Stloc);
1589 E_Id := Standard_Entity (S_Numeric_Error);
1591 Set_Ekind (E_Id, E_Exception);
1592 Set_Etype (E_Id, Standard_Exception_Type);
1593 Set_Is_Public (E_Id);
1594 Set_Renamed_Entity (E_Id, Standard_Entity (S_Constraint_Error));
1596 Set_Defining_Identifier (Decl, E_Id);
1597 Append (Decl, Decl_S);
1599 Ident_Node := New_Node (N_Identifier, Stloc);
1600 Set_Chars (Ident_Node, Chars (Standard_Entity (S_Constraint_Error)));
1601 Set_Entity (Ident_Node, Standard_Entity (S_Constraint_Error));
1602 Set_Name (Decl, Ident_Node);
1603 end if;
1605 -- Abort_Signal is an entity that does not get made visible
1607 Abort_Signal := New_Standard_Entity;
1608 Set_Chars (Abort_Signal, Name_uAbort_Signal);
1609 Set_Ekind (Abort_Signal, E_Exception);
1610 Set_Etype (Abort_Signal, Standard_Exception_Type);
1611 Set_Scope (Abort_Signal, Standard_Standard);
1612 Set_Is_Public (Abort_Signal, True);
1613 Decl :=
1614 Make_Exception_Declaration (Stloc,
1615 Defining_Identifier => Abort_Signal);
1617 -- Create defining identifiers for shift operator entities. Note
1618 -- that these entities are used only for marking shift operators
1619 -- generated internally, and hence need no structure, just a name
1620 -- and a unique identity.
1622 Standard_Op_Rotate_Left := New_Standard_Entity;
1623 Set_Chars (Standard_Op_Rotate_Left, Name_Rotate_Left);
1624 Set_Ekind (Standard_Op_Rotate_Left, E_Operator);
1626 Standard_Op_Rotate_Right := New_Standard_Entity;
1627 Set_Chars (Standard_Op_Rotate_Right, Name_Rotate_Right);
1628 Set_Ekind (Standard_Op_Rotate_Right, E_Operator);
1630 Standard_Op_Shift_Left := New_Standard_Entity;
1631 Set_Chars (Standard_Op_Shift_Left, Name_Shift_Left);
1632 Set_Ekind (Standard_Op_Shift_Left, E_Operator);
1634 Standard_Op_Shift_Right := New_Standard_Entity;
1635 Set_Chars (Standard_Op_Shift_Right, Name_Shift_Right);
1636 Set_Ekind (Standard_Op_Shift_Right, E_Operator);
1638 Standard_Op_Shift_Right_Arithmetic := New_Standard_Entity;
1639 Set_Chars (Standard_Op_Shift_Right_Arithmetic,
1640 Name_Shift_Right_Arithmetic);
1641 Set_Ekind (Standard_Op_Shift_Right_Arithmetic,
1642 E_Operator);
1644 -- Create standard operator declarations
1646 Create_Operators;
1648 -- Initialize visibility table with entities in Standard
1650 for E in Standard_Entity_Type loop
1651 if Ekind (Standard_Entity (E)) /= E_Operator then
1652 Set_Name_Entity_Id
1653 (Chars (Standard_Entity (E)), Standard_Entity (E));
1654 Set_Homonym (Standard_Entity (E), Empty);
1655 end if;
1657 if E not in S_ASCII_Names then
1658 Set_Scope (Standard_Entity (E), Standard_Standard);
1659 Set_Is_Immediately_Visible (Standard_Entity (E));
1660 end if;
1661 end loop;
1663 -- The predefined package Standard itself does not have a scope;
1664 -- it is the only entity in the system not to have one, and this
1665 -- is what identifies the package to Gigi.
1667 Set_Scope (Standard_Standard, Empty);
1669 -- Set global variables indicating last Id values and version
1671 Last_Standard_Node_Id := Last_Node_Id;
1672 Last_Standard_List_Id := Last_List_Id;
1674 -- The Error node has an Etype of Any_Type to help error recovery
1676 Set_Etype (Error, Any_Type);
1678 -- Print representation of standard if switch set
1680 if Opt.Print_Standard then
1681 Print_Standard;
1682 end if;
1683 end Create_Standard;
1685 ------------------------------------
1686 -- Create_Unconstrained_Base_Type --
1687 ------------------------------------
1689 procedure Create_Unconstrained_Base_Type
1690 (E : Entity_Id;
1691 K : Entity_Kind)
1693 New_Ent : constant Entity_Id := New_Copy (E);
1695 begin
1696 Set_Ekind (E, K);
1697 Set_Is_Constrained (E, True);
1698 Set_Is_First_Subtype (E, True);
1699 Set_Etype (E, New_Ent);
1701 Append_Entity (New_Ent, Standard_Standard);
1702 Set_Is_Constrained (New_Ent, False);
1703 Set_Etype (New_Ent, New_Ent);
1704 Set_Is_Known_Valid (New_Ent, True);
1706 if K = E_Signed_Integer_Subtype then
1707 Set_Etype (Low_Bound (Scalar_Range (E)), New_Ent);
1708 Set_Etype (High_Bound (Scalar_Range (E)), New_Ent);
1709 end if;
1711 end Create_Unconstrained_Base_Type;
1713 --------------------
1714 -- Identifier_For --
1715 --------------------
1717 function Identifier_For (S : Standard_Entity_Type) return Node_Id is
1718 Ident_Node : Node_Id;
1719 begin
1720 Ident_Node := New_Node (N_Identifier, Stloc);
1721 Set_Chars (Ident_Node, Chars (Standard_Entity (S)));
1722 Set_Entity (Ident_Node, Standard_Entity (S));
1723 return Ident_Node;
1724 end Identifier_For;
1726 --------------------
1727 -- Make_Component --
1728 --------------------
1730 procedure Make_Component
1731 (Rec : Entity_Id;
1732 Typ : Entity_Id;
1733 Nam : String)
1735 Id : constant Entity_Id := New_Standard_Entity;
1737 begin
1738 Set_Ekind (Id, E_Component);
1739 Set_Etype (Id, Typ);
1740 Set_Scope (Id, Rec);
1741 Init_Component_Location (Id);
1743 Set_Original_Record_Component (Id, Id);
1744 Make_Name (Id, Nam);
1745 Append_Entity (Id, Rec);
1746 end Make_Component;
1748 -----------------
1749 -- Make_Formal --
1750 -----------------
1752 function Make_Formal
1753 (Typ : Entity_Id;
1754 Formal_Name : String) return Entity_Id
1756 Formal : Entity_Id;
1758 begin
1759 Formal := New_Standard_Entity;
1761 Set_Ekind (Formal, E_In_Parameter);
1762 Set_Mechanism (Formal, Default_Mechanism);
1763 Set_Scope (Formal, Standard_Standard);
1764 Set_Etype (Formal, Typ);
1765 Make_Name (Formal, Formal_Name);
1767 return Formal;
1768 end Make_Formal;
1770 ------------------
1771 -- Make_Integer --
1772 ------------------
1774 function Make_Integer (V : Uint) return Node_Id is
1775 N : constant Node_Id := Make_Integer_Literal (Stloc, V);
1776 begin
1777 Set_Is_Static_Expression (N);
1778 return N;
1779 end Make_Integer;
1781 ---------------
1782 -- Make_Name --
1783 ---------------
1785 procedure Make_Name (Id : Entity_Id; Nam : String) is
1786 begin
1787 for J in 1 .. Nam'Length loop
1788 Name_Buffer (J) := Fold_Lower (Nam (Nam'First + (J - 1)));
1789 end loop;
1791 Name_Len := Nam'Length;
1792 Set_Chars (Id, Name_Find);
1793 end Make_Name;
1795 ------------------
1796 -- New_Operator --
1797 ------------------
1799 function New_Operator (Op : Name_Id; Typ : Entity_Id) return Entity_Id is
1800 Ident_Node : Entity_Id;
1802 begin
1803 Ident_Node := Make_Defining_Identifier (Stloc, Op);
1805 Set_Is_Pure (Ident_Node, True);
1806 Set_Ekind (Ident_Node, E_Operator);
1807 Set_Etype (Ident_Node, Typ);
1808 Set_Scope (Ident_Node, Standard_Standard);
1809 Set_Homonym (Ident_Node, Get_Name_Entity_Id (Op));
1810 Set_Convention (Ident_Node, Convention_Intrinsic);
1812 Set_Is_Immediately_Visible (Ident_Node, True);
1813 Set_Is_Intrinsic_Subprogram (Ident_Node, True);
1815 Set_Name_Entity_Id (Op, Ident_Node);
1816 Append_Entity (Ident_Node, Standard_Standard);
1817 return Ident_Node;
1818 end New_Operator;
1820 -------------------------
1821 -- New_Standard_Entity --
1822 -------------------------
1824 function New_Standard_Entity
1825 (New_Node_Kind : Node_Kind := N_Defining_Identifier) return Entity_Id
1827 E : constant Entity_Id := New_Entity (New_Node_Kind, Stloc);
1829 begin
1830 -- All standard entities are Pure and Public
1832 Set_Is_Pure (E);
1833 Set_Is_Public (E);
1835 -- All standard entity names are analyzed manually, and are thus
1836 -- frozen as soon as they are created.
1838 Set_Is_Frozen (E);
1840 -- Set debug information required for all standard types
1842 Set_Needs_Debug_Info (E);
1844 -- All standard entities are built with fully qualified names, so
1845 -- set the flag to prevent an abortive attempt at requalification.
1847 Set_Has_Qualified_Name (E);
1849 -- Return newly created entity to be completed by caller
1851 return E;
1852 end New_Standard_Entity;
1854 function New_Standard_Entity (S : String) return Entity_Id is
1855 Ent : constant Entity_Id := New_Standard_Entity;
1856 begin
1857 Make_Name (Ent, S);
1858 return Ent;
1859 end New_Standard_Entity;
1861 --------------------
1862 -- Print_Standard --
1863 --------------------
1865 procedure Print_Standard is
1867 procedure P (Item : String) renames Output.Write_Line;
1868 -- Short-hand, since we do a lot of line writes here
1870 procedure P_Int_Range (Size : Pos);
1871 -- Prints the range of an integer based on its Size
1873 procedure P_Float_Range (Id : Entity_Id);
1874 -- Prints the bounds range for the given float type entity
1876 procedure P_Float_Type (Id : Entity_Id);
1877 -- Prints the type declaration of the given float type entity
1879 procedure P_Mixed_Name (Id : Name_Id);
1880 -- Prints Id in mixed case
1882 -------------------
1883 -- P_Float_Range --
1884 -------------------
1886 procedure P_Float_Range (Id : Entity_Id) is
1887 begin
1888 Write_Str (" range ");
1889 UR_Write (Realval (Type_Low_Bound (Id)));
1890 Write_Str (" .. ");
1891 UR_Write (Realval (Type_High_Bound (Id)));
1892 Write_Str (";");
1893 Write_Eol;
1894 end P_Float_Range;
1896 ------------------
1897 -- P_Float_Type --
1898 ------------------
1900 procedure P_Float_Type (Id : Entity_Id) is
1901 begin
1902 Write_Str (" type ");
1903 P_Mixed_Name (Chars (Id));
1904 Write_Str (" is digits ");
1905 Write_Int (UI_To_Int (Digits_Value (Id)));
1906 Write_Eol;
1907 P_Float_Range (Id);
1908 Write_Str (" for ");
1909 P_Mixed_Name (Chars (Id));
1910 Write_Str ("'Size use ");
1911 Write_Int (UI_To_Int (RM_Size (Id)));
1912 Write_Line (";");
1913 Write_Eol;
1914 end P_Float_Type;
1916 -----------------
1917 -- P_Int_Range --
1918 -----------------
1920 procedure P_Int_Range (Size : Pos) is
1921 begin
1922 Write_Str (" is range -(2 **");
1923 Write_Int (Size - 1);
1924 Write_Str (")");
1925 Write_Str (" .. +(2 **");
1926 Write_Int (Size - 1);
1927 Write_Str (" - 1);");
1928 Write_Eol;
1929 end P_Int_Range;
1931 ------------------
1932 -- P_Mixed_Name --
1933 ------------------
1935 procedure P_Mixed_Name (Id : Name_Id) is
1936 begin
1937 Get_Name_String (Id);
1939 for J in 1 .. Name_Len loop
1940 if J = 1 or else Name_Buffer (J - 1) = '_' then
1941 Name_Buffer (J) := Fold_Upper (Name_Buffer (J));
1942 end if;
1943 end loop;
1945 Write_Str (Name_Buffer (1 .. Name_Len));
1946 end P_Mixed_Name;
1948 -- Start of processing for Print_Standard
1950 begin
1951 P ("-- Representation of package Standard");
1952 Write_Eol;
1953 P ("-- This is not accurate Ada, since new base types cannot be ");
1954 P ("-- created, but the listing shows the target dependent");
1955 P ("-- characteristics of the Standard types for this compiler");
1956 Write_Eol;
1958 P ("package Standard is");
1959 P ("pragma Pure (Standard);");
1960 Write_Eol;
1962 P (" type Boolean is (False, True);");
1963 P (" for Boolean'Size use 1;");
1964 P (" for Boolean use (False => 0, True => 1);");
1965 Write_Eol;
1967 -- Integer types
1969 Write_Str (" type Integer");
1970 P_Int_Range (Standard_Integer_Size);
1971 Write_Str (" for Integer'Size use ");
1972 Write_Int (Standard_Integer_Size);
1973 P (";");
1974 Write_Eol;
1976 P (" subtype Natural is Integer range 0 .. Integer'Last;");
1977 P (" subtype Positive is Integer range 1 .. Integer'Last;");
1978 Write_Eol;
1980 Write_Str (" type Short_Short_Integer");
1981 P_Int_Range (Standard_Short_Short_Integer_Size);
1982 Write_Str (" for Short_Short_Integer'Size use ");
1983 Write_Int (Standard_Short_Short_Integer_Size);
1984 P (";");
1985 Write_Eol;
1987 Write_Str (" type Short_Integer");
1988 P_Int_Range (Standard_Short_Integer_Size);
1989 Write_Str (" for Short_Integer'Size use ");
1990 Write_Int (Standard_Short_Integer_Size);
1991 P (";");
1992 Write_Eol;
1994 Write_Str (" type Long_Integer");
1995 P_Int_Range (Standard_Long_Integer_Size);
1996 Write_Str (" for Long_Integer'Size use ");
1997 Write_Int (Standard_Long_Integer_Size);
1998 P (";");
1999 Write_Eol;
2001 Write_Str (" type Long_Long_Integer");
2002 P_Int_Range (Standard_Long_Long_Integer_Size);
2003 Write_Str (" for Long_Long_Integer'Size use ");
2004 Write_Int (Standard_Long_Long_Integer_Size);
2005 P (";");
2006 Write_Eol;
2008 -- Floating point types
2010 P_Float_Type (Standard_Short_Float);
2011 P_Float_Type (Standard_Float);
2012 P_Float_Type (Standard_Long_Float);
2013 P_Float_Type (Standard_Long_Long_Float);
2015 P (" type Character is (...)");
2016 Write_Str (" for Character'Size use ");
2017 Write_Int (Standard_Character_Size);
2018 P (";");
2019 P (" -- See RM A.1(35) for details of this type");
2020 Write_Eol;
2022 P (" type Wide_Character is (...)");
2023 Write_Str (" for Wide_Character'Size use ");
2024 Write_Int (Standard_Wide_Character_Size);
2025 P (";");
2026 P (" -- See RM A.1(36) for details of this type");
2027 Write_Eol;
2029 P (" type Wide_Wide_Character is (...)");
2030 Write_Str (" for Wide_Wide_Character'Size use ");
2031 Write_Int (Standard_Wide_Wide_Character_Size);
2032 P (";");
2033 P (" -- See RM A.1(36) for details of this type");
2035 P (" type String is array (Positive range <>) of Character;");
2036 P (" pragma Pack (String);");
2037 Write_Eol;
2039 P (" type Wide_String is array (Positive range <>)" &
2040 " of Wide_Character;");
2041 P (" pragma Pack (Wide_String);");
2042 Write_Eol;
2044 P (" type Wide_Wide_String is array (Positive range <>)" &
2045 " of Wide_Wide_Character;");
2046 P (" pragma Pack (Wide_Wide_String);");
2047 Write_Eol;
2049 -- We only have one representation each for 32-bit and 64-bit sizes,
2050 -- so select the right one based on Duration_32_Bits_On_Target.
2052 if Duration_32_Bits_On_Target then
2053 P (" type Duration is delta 0.020");
2054 P (" range -((2 ** 31 - 1) * 0.020) ..");
2055 P (" +((2 ** 31 - 1) * 0.020);");
2056 P (" for Duration'Small use 0.020;");
2058 else
2059 P (" type Duration is delta 0.000000001");
2060 P (" range -((2 ** 63 - 1) * 0.000000001) ..");
2061 P (" +((2 ** 63 - 1) * 0.000000001);");
2062 P (" for Duration'Small use 0.000000001;");
2063 end if;
2065 Write_Eol;
2067 P (" Constraint_Error : exception;");
2068 P (" Program_Error : exception;");
2069 P (" Storage_Error : exception;");
2070 P (" Tasking_Error : exception;");
2071 P (" Numeric_Error : exception renames Constraint_Error;");
2072 Write_Eol;
2074 P ("end Standard;");
2075 end Print_Standard;
2077 -------------------------
2078 -- Register_Float_Type --
2079 -------------------------
2081 procedure Register_Float_Type
2082 (Name : String;
2083 Digs : Positive;
2084 Float_Rep : Float_Rep_Kind;
2085 Precision : Positive;
2086 Size : Positive;
2087 Alignment : Natural)
2089 Ent : constant Entity_Id := New_Standard_Entity;
2091 begin
2092 Set_Defining_Identifier (New_Node (N_Full_Type_Declaration, Stloc), Ent);
2093 Make_Name (Ent, Name);
2094 Set_Scope (Ent, Standard_Standard);
2095 Build_Float_Type (Ent, Int (Size), Float_Rep, Pos (Digs));
2096 Set_RM_Size (Ent, UI_From_Int (Int (Precision)));
2097 Set_Alignment (Ent, UI_From_Int (Int (Alignment / 8)));
2099 if No (Back_End_Float_Types) then
2100 Back_End_Float_Types := New_Elmt_List;
2101 end if;
2103 Append_Elmt (Ent, Back_End_Float_Types);
2104 end Register_Float_Type;
2106 ----------------------
2107 -- Set_Float_Bounds --
2108 ----------------------
2110 procedure Set_Float_Bounds (Id : Entity_Id) is
2111 L : Node_Id;
2112 H : Node_Id;
2113 -- Low and high bounds of literal value
2115 R : Node_Id;
2116 -- Range specification
2118 Radix : constant Uint := Machine_Radix_Value (Id);
2119 Mantissa : constant Uint := Machine_Mantissa_Value (Id);
2120 Emax : constant Uint := Machine_Emax_Value (Id);
2121 Significand : constant Uint := Radix ** Mantissa - 1;
2122 Exponent : constant Uint := Emax - Mantissa;
2124 begin
2125 H := Make_Float_Literal (Stloc, Radix, Significand, Exponent);
2126 L := Make_Float_Literal (Stloc, Radix, -Significand, Exponent);
2128 Set_Etype (L, Id);
2129 Set_Is_Static_Expression (L);
2131 Set_Etype (H, Id);
2132 Set_Is_Static_Expression (H);
2134 R := New_Node (N_Range, Stloc);
2135 Set_Low_Bound (R, L);
2136 Set_High_Bound (R, H);
2137 Set_Includes_Infinities (R, True);
2138 Set_Scalar_Range (Id, R);
2139 Set_Etype (R, Id);
2140 Set_Parent (R, Id);
2141 end Set_Float_Bounds;
2143 ------------------------
2144 -- Set_Integer_Bounds --
2145 ------------------------
2147 procedure Set_Integer_Bounds
2148 (Id : Entity_Id;
2149 Typ : Entity_Id;
2150 Lb : Uint;
2151 Hb : Uint)
2153 L : Node_Id;
2154 H : Node_Id;
2155 -- Low and high bounds of literal value
2157 R : Node_Id;
2158 -- Range specification
2160 begin
2161 L := Make_Integer (Lb);
2162 H := Make_Integer (Hb);
2164 Set_Etype (L, Typ);
2165 Set_Etype (H, Typ);
2167 R := New_Node (N_Range, Stloc);
2168 Set_Low_Bound (R, L);
2169 Set_High_Bound (R, H);
2170 Set_Scalar_Range (Id, R);
2171 Set_Etype (R, Typ);
2172 Set_Parent (R, Id);
2173 Set_Is_Unsigned_Type (Id, Lb >= 0);
2174 end Set_Integer_Bounds;
2176 end CStand;