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