1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2003 Free Software Foundation, Inc. --
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 2, 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 COPYING. If not, write --
19 -- to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, --
20 -- MA 02111-1307, USA. --
22 -- GNAT was originally developed by the GNAT team at New York University. --
23 -- Extensive contributions were provided by Ada Core Technologies Inc. --
25 ------------------------------------------------------------------------------
27 with Atree; use Atree;
28 with Csets; use Csets;
29 with Debug; use Debug;
30 with Einfo; use Einfo;
31 with Layout; use Layout;
32 with Namet; use Namet;
33 with Nlists; use Nlists;
34 with Nmake; use Nmake;
36 with Output; use Output;
37 with Targparm; use Targparm;
38 with Tbuild; use Tbuild;
39 with Ttypes; use Ttypes;
40 with Ttypef; use Ttypef;
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 -----------------------
57 -- Local Subprograms --
58 -----------------------
60 procedure Build_Float_Type (E : Entity_Id; Siz : Int; Digs : Int);
61 -- Procedure to build standard predefined float base type. The first
62 -- parameter is the entity for the type, and the second parameter
63 -- is the size in bits. The third parameter is the digits value.
65 procedure Build_Signed_Integer_Type (E : Entity_Id; Siz : Int);
66 -- Procedure to build standard predefined signed integer subtype. The
67 -- first parameter is the entity for the subtype. The second parameter
68 -- is the size in bits. The corresponding base type is not built by
69 -- this routine but instead must be built by the caller where needed.
71 procedure Create_Operators;
72 -- Make entries for each of the predefined operators in Standard
74 procedure Create_Unconstrained_Base_Type
77 -- The predefined signed integer types are constrained subtypes which
78 -- must have a corresponding unconstrained base type. This type is almost
79 -- useless. The only place it has semantics is Subtypes_Statically_Match.
80 -- Consequently, we arrange for it to be identical apart from the setting
81 -- of the constrained bit. This routine takes an entity E for the Type,
82 -- copies it to estabish the base type, then resets the Ekind of the
83 -- original entity to K (the Ekind for the subtype). The Etype field of
84 -- E is set by the call (to point to the created base type entity), and
85 -- also the Is_Constrained flag of E is set.
87 -- To understand the exact requirement for this, see RM 3.5.4(11) which
88 -- makes it clear that Integer, for example, is constrained, with the
89 -- constraint bounds matching the bounds of the (unconstrained) base
90 -- type. The point is that Integer and Integer'Base have identical
91 -- bounds, but do not statically match, since a subtype with constraints
92 -- never matches a subtype with no constraints.
94 function Identifier_For (S : Standard_Entity_Type) return Node_Id;
95 -- Returns an identifier node with the same name as the defining
96 -- identifier corresponding to the given Standard_Entity_Type value
98 procedure Make_Component
102 -- Build a record component with the given type and name, and append to
103 -- the list of components of Rec.
107 Formal_Name : String)
109 -- Construct entity for subprogram formal with given name and type
111 function Make_Integer (V : Uint) return Node_Id;
112 -- Builds integer literal with given value
114 procedure Make_Name (Id : Entity_Id; Nam : String);
115 -- Make an entry in the names table for Nam, and set as Chars field of Id
117 function New_Operator (Op : Name_Id; Typ : Entity_Id) return Entity_Id;
118 -- Build entity for standard operator with given name and type.
120 function New_Standard_Entity
121 (New_Node_Kind : Node_Kind := N_Defining_Identifier)
123 -- Builds a new entity for Standard
125 procedure Print_Standard;
126 -- Print representation of package Standard if switch set
128 procedure Set_Integer_Bounds
133 -- Procedure to set bounds for integer type or subtype. Id is the entity
134 -- whose bounds and type are to be set. The Typ parameter is the Etype
135 -- value for the entity (which will be the same as Id for all predefined
136 -- integer base types. The third and fourth parameters are the bounds.
138 ----------------------
139 -- Build_Float_Type --
140 ----------------------
142 procedure Build_Float_Type (E : Entity_Id; Siz : Int; Digs : Int) is
144 Set_Type_Definition (Parent (E),
145 Make_Floating_Point_Definition (Stloc,
146 Digits_Expression => Make_Integer (UI_From_Int (Digs))));
147 Set_Ekind (E, E_Floating_Point_Type);
150 Set_Prim_Alignment (E);
151 Init_Digits_Value (E, Digs);
152 Set_Float_Bounds (E);
155 Set_Size_Known_At_Compile_Time (E);
156 end Build_Float_Type;
158 -------------------------------
159 -- Build_Signed_Integer_Type --
160 -------------------------------
162 procedure Build_Signed_Integer_Type (E : Entity_Id; Siz : Int) is
163 U2Siz1 : constant Uint := 2 ** (Siz - 1);
164 Lbound : constant Uint := -U2Siz1;
165 Ubound : constant Uint := U2Siz1 - 1;
168 Set_Type_Definition (Parent (E),
169 Make_Signed_Integer_Type_Definition (Stloc,
170 Low_Bound => Make_Integer (Lbound),
171 High_Bound => Make_Integer (Ubound)));
173 Set_Ekind (E, E_Signed_Integer_Type);
176 Set_Prim_Alignment (E);
177 Set_Integer_Bounds (E, E, Lbound, Ubound);
180 Set_Is_Known_Valid (E);
181 Set_Size_Known_At_Compile_Time (E);
182 end Build_Signed_Integer_Type;
184 ----------------------
185 -- Create_Operators --
186 ----------------------
188 -- Each operator has an abbreviated signature. The formals have the names
189 -- LEFT and RIGHT. Their types are not actually used for resolution.
191 procedure Create_Operators is
194 -- Following list has two entries for concatenation, to include
195 -- explicitly the operation on wide strings.
197 Binary_Ops : constant array (S_Binary_Ops) of Name_Id :=
198 (Name_Op_Add, Name_Op_And, Name_Op_Concat, Name_Op_Concat,
199 Name_Op_Divide, Name_Op_Eq, Name_Op_Expon, Name_Op_Ge,
200 Name_Op_Gt, Name_Op_Le, Name_Op_Lt, Name_Op_Mod,
201 Name_Op_Multiply, Name_Op_Ne, Name_Op_Or, Name_Op_Rem,
202 Name_Op_Subtract, Name_Op_Xor);
204 Bin_Op_Types : constant array (S_Binary_Ops) of Entity_Id :=
205 (Universal_Integer, Standard_Boolean,
206 Standard_String, Standard_Wide_String,
207 Universal_Integer, Standard_Boolean,
208 Universal_Integer, Standard_Boolean,
209 Standard_Boolean, Standard_Boolean,
210 Standard_Boolean, Universal_Integer,
211 Universal_Integer, Standard_Boolean,
212 Standard_Boolean, Universal_Integer,
213 Universal_Integer, Standard_Boolean);
215 Unary_Ops : constant array (S_Unary_Ops) of Name_Id :=
216 (Name_Op_Abs, Name_Op_Subtract, Name_Op_Not, Name_Op_Add);
218 Unary_Op_Types : constant array (S_Unary_Ops) of Entity_Id :=
219 (Universal_Integer, Universal_Integer,
220 Standard_Boolean, Universal_Integer);
222 -- Corresponding to Abs, Minus, Not, and Plus.
225 for J in S_Binary_Ops loop
226 Op_Node := New_Operator (Binary_Ops (J), Bin_Op_Types (J));
228 Append_Entity (Make_Formal (Any_Type, "LEFT"), Op_Node);
229 Append_Entity (Make_Formal (Any_Type, "RIGHT"), Op_Node);
232 for J in S_Unary_Ops loop
233 Op_Node := New_Operator (Unary_Ops (J), Unary_Op_Types (J));
235 Append_Entity (Make_Formal (Any_Type, "RIGHT"), Op_Node);
238 -- For concatenation, we create a separate operator for each
239 -- array type. This simplifies the resolution of the component-
240 -- component concatenation operation. In Standard, we set the types
241 -- of the formals for string and wide string concatenation.
243 Set_Etype (First_Entity (Standard_Op_Concat), Standard_String);
244 Set_Etype (Last_Entity (Standard_Op_Concat), Standard_String);
246 Set_Etype (First_Entity (Standard_Op_Concatw), Standard_Wide_String);
247 Set_Etype (Last_Entity (Standard_Op_Concatw), Standard_Wide_String);
249 end Create_Operators;
251 ---------------------
252 -- Create_Standard --
253 ---------------------
255 -- The tree for the package Standard is prefixed to all compilations.
256 -- Several entities required by semantic analysis are denoted by global
257 -- variables that are initialized to point to the corresponding
258 -- occurrences in STANDARD. The visible entities of STANDARD are
259 -- created here. The private entities defined in STANDARD are created
260 -- by Initialize_Standard in the semantics module.
262 procedure Create_Standard is
263 Decl_S : List_Id := New_List;
264 -- List of declarations in Standard
266 Decl_A : List_Id := New_List;
267 -- List of declarations in ASCII
272 Ident_Node : Node_Id;
278 procedure Build_Exception (S : Standard_Entity_Type);
279 -- Procedure to declare given entity as an exception
281 ---------------------
282 -- Build_Exception --
283 ---------------------
285 procedure Build_Exception (S : Standard_Entity_Type) is
287 Set_Ekind (Standard_Entity (S), E_Exception);
288 Set_Etype (Standard_Entity (S), Standard_Exception_Type);
289 Set_Exception_Code (Standard_Entity (S), Uint_0);
290 Set_Is_Public (Standard_Entity (S), True);
293 Make_Exception_Declaration (Stloc,
294 Defining_Identifier => Standard_Entity (S));
295 Append (Decl, Decl_S);
298 -- Start of processing for Create_Standard
301 -- Initialize scanner for internal scans of literals
303 Scn.Initialize_Scanner (No_Unit, Internal_Source_File);
305 -- First step is to create defining identifiers for each entity
307 for S in Standard_Entity_Type loop
309 S_Name : constant String := Standard_Entity_Type'Image (S);
310 -- Name of entity (note we skip S_ at the start)
312 Ident_Node : Node_Id;
313 -- Defining identifier node
316 Ident_Node := New_Standard_Entity;
317 Make_Name (Ident_Node, S_Name (3 .. S_Name'Length));
318 Standard_Entity (S) := Ident_Node;
322 -- Create package declaration node for package Standard
324 Standard_Package_Node := New_Node (N_Package_Declaration, Stloc);
326 Pspec := New_Node (N_Package_Specification, Stloc);
327 Set_Specification (Standard_Package_Node, Pspec);
329 Set_Defining_Unit_Name (Pspec, Standard_Standard);
330 Set_Visible_Declarations (Pspec, Decl_S);
332 Set_Ekind (Standard_Standard, E_Package);
333 Set_Is_Pure (Standard_Standard);
334 Set_Is_Compilation_Unit (Standard_Standard);
336 -- Create type declaration nodes for standard types
338 for S in S_Types loop
339 Decl := New_Node (N_Full_Type_Declaration, Stloc);
340 Set_Defining_Identifier (Decl, Standard_Entity (S));
341 Set_Is_Frozen (Standard_Entity (S));
342 Set_Is_Public (Standard_Entity (S));
343 Append (Decl, Decl_S);
346 -- Create type definition node for type Boolean. The Size is set to
347 -- 1 as required by Ada 95 and current ARG interpretations for Ada/83.
349 -- Note: Object_Size of Boolean is 8. This means that we do NOT in
350 -- general know that Boolean variables have valid values, so we do
351 -- not set the Is_Known_Valid flag.
353 Tdef_Node := New_Node (N_Enumeration_Type_Definition, Stloc);
354 Set_Literals (Tdef_Node, New_List);
355 Append (Standard_False, Literals (Tdef_Node));
356 Append (Standard_True, Literals (Tdef_Node));
357 Set_Type_Definition (Parent (Standard_Boolean), Tdef_Node);
359 Set_Ekind (Standard_Boolean, E_Enumeration_Type);
360 Set_First_Literal (Standard_Boolean, Standard_False);
361 Set_Etype (Standard_Boolean, Standard_Boolean);
362 Init_Esize (Standard_Boolean, Standard_Character_Size);
363 Init_RM_Size (Standard_Boolean, 1);
364 Set_Prim_Alignment (Standard_Boolean);
366 Set_Is_Unsigned_Type (Standard_Boolean);
367 Set_Size_Known_At_Compile_Time (Standard_Boolean);
369 Set_Ekind (Standard_True, E_Enumeration_Literal);
370 Set_Etype (Standard_True, Standard_Boolean);
371 Set_Enumeration_Pos (Standard_True, Uint_1);
372 Set_Enumeration_Rep (Standard_True, Uint_1);
373 Set_Is_Known_Valid (Standard_True, True);
375 Set_Ekind (Standard_False, E_Enumeration_Literal);
376 Set_Etype (Standard_False, Standard_Boolean);
377 Set_Enumeration_Pos (Standard_False, Uint_0);
378 Set_Enumeration_Rep (Standard_False, Uint_0);
379 Set_Is_Known_Valid (Standard_False, True);
381 -- For the bounds of Boolean, we create a range node corresponding to
383 -- range False .. True
385 -- where the occurrences of the literals must point to the
386 -- corresponding definition.
388 R_Node := New_Node (N_Range, Stloc);
389 B_Node := New_Node (N_Identifier, Stloc);
390 Set_Chars (B_Node, Chars (Standard_False));
391 Set_Entity (B_Node, Standard_False);
392 Set_Etype (B_Node, Standard_Boolean);
393 Set_Is_Static_Expression (B_Node);
394 Set_Low_Bound (R_Node, B_Node);
396 B_Node := New_Node (N_Identifier, Stloc);
397 Set_Chars (B_Node, Chars (Standard_True));
398 Set_Entity (B_Node, Standard_True);
399 Set_Etype (B_Node, Standard_Boolean);
400 Set_Is_Static_Expression (B_Node);
401 Set_High_Bound (R_Node, B_Node);
403 Set_Scalar_Range (Standard_Boolean, R_Node);
404 Set_Etype (R_Node, Standard_Boolean);
405 Set_Parent (R_Node, Standard_Boolean);
407 -- Create type definition nodes for predefined integer types
409 Build_Signed_Integer_Type
410 (Standard_Short_Short_Integer, Standard_Short_Short_Integer_Size);
412 Build_Signed_Integer_Type
413 (Standard_Short_Integer, Standard_Short_Integer_Size);
415 Build_Signed_Integer_Type
416 (Standard_Integer, Standard_Integer_Size);
424 LIS := Standard_Long_Integer_Size;
427 Build_Signed_Integer_Type (Standard_Long_Integer, LIS);
430 Build_Signed_Integer_Type
431 (Standard_Long_Long_Integer, Standard_Long_Long_Integer_Size);
433 Create_Unconstrained_Base_Type
434 (Standard_Short_Short_Integer, E_Signed_Integer_Subtype);
436 Create_Unconstrained_Base_Type
437 (Standard_Short_Integer, E_Signed_Integer_Subtype);
439 Create_Unconstrained_Base_Type
440 (Standard_Integer, E_Signed_Integer_Subtype);
442 Create_Unconstrained_Base_Type
443 (Standard_Long_Integer, E_Signed_Integer_Subtype);
445 Create_Unconstrained_Base_Type
446 (Standard_Long_Long_Integer, E_Signed_Integer_Subtype);
448 -- Create type definition nodes for predefined float types
451 (Standard_Short_Float,
452 Standard_Short_Float_Size,
453 Standard_Short_Float_Digits);
458 Standard_Float_Digits);
461 (Standard_Long_Float,
462 Standard_Long_Float_Size,
463 Standard_Long_Float_Digits);
466 (Standard_Long_Long_Float,
467 Standard_Long_Long_Float_Size,
468 Standard_Long_Long_Float_Digits);
470 -- Create type definition node for type Character. Note that we do not
471 -- set the Literals field, since type Character is handled with special
472 -- routine that do not need a literal list.
474 Tdef_Node := New_Node (N_Enumeration_Type_Definition, Stloc);
475 Set_Type_Definition (Parent (Standard_Character), Tdef_Node);
477 Set_Ekind (Standard_Character, E_Enumeration_Type);
478 Set_Etype (Standard_Character, Standard_Character);
479 Init_Esize (Standard_Character, Standard_Character_Size);
480 Init_RM_Size (Standard_Character, 8);
481 Set_Prim_Alignment (Standard_Character);
483 Set_Is_Unsigned_Type (Standard_Character);
484 Set_Is_Character_Type (Standard_Character);
485 Set_Is_Known_Valid (Standard_Character);
486 Set_Size_Known_At_Compile_Time (Standard_Character);
488 -- Create the bounds for type Character.
490 R_Node := New_Node (N_Range, Stloc);
492 -- Low bound for type Character (Standard.Nul)
494 B_Node := New_Node (N_Character_Literal, Stloc);
495 Set_Is_Static_Expression (B_Node);
496 Set_Chars (B_Node, No_Name);
497 Set_Char_Literal_Value (B_Node, 16#00#);
498 Set_Entity (B_Node, Empty);
499 Set_Etype (B_Node, Standard_Character);
500 Set_Low_Bound (R_Node, B_Node);
502 -- High bound for type Character
504 B_Node := New_Node (N_Character_Literal, Stloc);
505 Set_Is_Static_Expression (B_Node);
506 Set_Chars (B_Node, No_Name);
507 Set_Char_Literal_Value (B_Node, 16#FF#);
508 Set_Entity (B_Node, Empty);
509 Set_Etype (B_Node, Standard_Character);
510 Set_High_Bound (R_Node, B_Node);
512 Set_Scalar_Range (Standard_Character, R_Node);
513 Set_Etype (R_Node, Standard_Character);
514 Set_Parent (R_Node, Standard_Character);
516 -- Create type definition for type Wide_Character. Note that we do not
517 -- set the Literals field, since type Wide_Character is handled with
518 -- special routines that do not need a literal list.
520 Tdef_Node := New_Node (N_Enumeration_Type_Definition, Stloc);
521 Set_Type_Definition (Parent (Standard_Wide_Character), Tdef_Node);
523 Set_Ekind (Standard_Wide_Character, E_Enumeration_Type);
524 Set_Etype (Standard_Wide_Character, Standard_Wide_Character);
525 Init_Size (Standard_Wide_Character, Standard_Wide_Character_Size);
527 Set_Prim_Alignment (Standard_Wide_Character);
528 Set_Is_Unsigned_Type (Standard_Wide_Character);
529 Set_Is_Character_Type (Standard_Wide_Character);
530 Set_Is_Known_Valid (Standard_Wide_Character);
531 Set_Size_Known_At_Compile_Time (Standard_Wide_Character);
533 -- Create the bounds for type Wide_Character.
535 R_Node := New_Node (N_Range, Stloc);
537 -- Low bound for type Wide_Character
539 B_Node := New_Node (N_Character_Literal, Stloc);
540 Set_Is_Static_Expression (B_Node);
541 Set_Chars (B_Node, No_Name); -- ???
542 Set_Char_Literal_Value (B_Node, 16#0000#);
543 Set_Entity (B_Node, Empty);
544 Set_Etype (B_Node, Standard_Wide_Character);
545 Set_Low_Bound (R_Node, B_Node);
547 -- High bound for type Wide_Character
549 B_Node := New_Node (N_Character_Literal, Stloc);
550 Set_Is_Static_Expression (B_Node);
551 Set_Chars (B_Node, No_Name); -- ???
552 Set_Char_Literal_Value (B_Node, 16#FFFF#);
553 Set_Entity (B_Node, Empty);
554 Set_Etype (B_Node, Standard_Wide_Character);
555 Set_High_Bound (R_Node, B_Node);
557 Set_Scalar_Range (Standard_Wide_Character, R_Node);
558 Set_Etype (R_Node, Standard_Wide_Character);
559 Set_Parent (R_Node, Standard_Wide_Character);
561 -- Create type definition node for type String
563 Tdef_Node := New_Node (N_Unconstrained_Array_Definition, Stloc);
564 Set_Subtype_Indication (Tdef_Node, Identifier_For (S_Character));
565 Set_Subtype_Marks (Tdef_Node, New_List);
566 Append (Identifier_For (S_Positive), Subtype_Marks (Tdef_Node));
567 Set_Type_Definition (Parent (Standard_String), Tdef_Node);
569 Set_Ekind (Standard_String, E_String_Type);
570 Set_Etype (Standard_String, Standard_String);
571 Set_Component_Type (Standard_String, Standard_Character);
572 Set_Component_Size (Standard_String, Uint_8);
573 Init_Size_Align (Standard_String);
575 -- Set index type of String
578 (Subtype_Marks (Type_Definition (Parent (Standard_String))));
579 Set_First_Index (Standard_String, E_Id);
580 Set_Entity (E_Id, Standard_Positive);
581 Set_Etype (E_Id, Standard_Positive);
583 -- Create type definition node for type Wide_String
585 Tdef_Node := New_Node (N_Unconstrained_Array_Definition, Stloc);
586 Set_Subtype_Indication (Tdef_Node, Identifier_For (S_Wide_Character));
587 Set_Subtype_Marks (Tdef_Node, New_List);
588 Append (Identifier_For (S_Positive), Subtype_Marks (Tdef_Node));
589 Set_Type_Definition (Parent (Standard_Wide_String), Tdef_Node);
591 Set_Ekind (Standard_Wide_String, E_String_Type);
592 Set_Etype (Standard_Wide_String, Standard_Wide_String);
593 Set_Component_Type (Standard_Wide_String, Standard_Wide_Character);
594 Set_Component_Size (Standard_Wide_String, Uint_16);
595 Init_Size_Align (Standard_Wide_String);
597 -- Set index type of Wide_String
600 (Subtype_Marks (Type_Definition (Parent (Standard_Wide_String))));
601 Set_First_Index (Standard_Wide_String, E_Id);
602 Set_Entity (E_Id, Standard_Positive);
603 Set_Etype (E_Id, Standard_Positive);
605 -- Create subtype declaration for Natural
607 Decl := New_Node (N_Subtype_Declaration, Stloc);
608 Set_Defining_Identifier (Decl, Standard_Natural);
609 Set_Subtype_Indication (Decl,
610 New_Occurrence_Of (Standard_Integer, Stloc));
611 Append (Decl, Decl_S);
613 Set_Ekind (Standard_Natural, E_Signed_Integer_Subtype);
614 Set_Etype (Standard_Natural, Base_Type (Standard_Integer));
615 Init_Esize (Standard_Natural, Standard_Integer_Size);
616 Init_RM_Size (Standard_Natural, Standard_Integer_Size - 1);
617 Set_Prim_Alignment (Standard_Natural);
618 Set_Size_Known_At_Compile_Time
620 Set_Integer_Bounds (Standard_Natural,
621 Typ => Base_Type (Standard_Integer),
623 Hb => Intval (High_Bound (Scalar_Range (Standard_Integer))));
624 Set_Is_Constrained (Standard_Natural);
625 Set_Is_Frozen (Standard_Natural);
626 Set_Is_Public (Standard_Natural);
628 -- Create subtype declaration for Positive
630 Decl := New_Node (N_Subtype_Declaration, Stloc);
631 Set_Defining_Identifier (Decl, Standard_Positive);
632 Set_Subtype_Indication (Decl,
633 New_Occurrence_Of (Standard_Integer, Stloc));
634 Append (Decl, Decl_S);
636 Set_Ekind (Standard_Positive, E_Signed_Integer_Subtype);
637 Set_Etype (Standard_Positive, Base_Type (Standard_Integer));
638 Init_Esize (Standard_Positive, Standard_Integer_Size);
639 Init_RM_Size (Standard_Positive, Standard_Integer_Size - 1);
640 Set_Prim_Alignment (Standard_Positive);
642 Set_Size_Known_At_Compile_Time (Standard_Positive);
644 Set_Integer_Bounds (Standard_Positive,
645 Typ => Base_Type (Standard_Integer),
647 Hb => Intval (High_Bound (Scalar_Range (Standard_Integer))));
648 Set_Is_Constrained (Standard_Positive);
649 Set_Is_Frozen (Standard_Positive);
650 Set_Is_Public (Standard_Positive);
652 -- Create declaration for package ASCII
654 Decl := New_Node (N_Package_Declaration, Stloc);
655 Append (Decl, Decl_S);
657 Pspec := New_Node (N_Package_Specification, Stloc);
658 Set_Specification (Decl, Pspec);
660 Set_Defining_Unit_Name (Pspec, Standard_Entity (S_ASCII));
661 Set_Ekind (Standard_Entity (S_ASCII), E_Package);
662 Set_Visible_Declarations (Pspec, Decl_A);
664 -- Create control character definitions in package ASCII. Note that
665 -- the character literal entries created here correspond to literal
666 -- values that are impossible in the source, but can be represented
667 -- internally with no difficulties.
671 for S in S_ASCII_Names loop
672 Decl := New_Node (N_Object_Declaration, Staloc);
673 Set_Constant_Present (Decl, True);
676 A_Char : constant Entity_Id := Standard_Entity (S);
680 Set_Sloc (A_Char, Staloc);
681 Set_Ekind (A_Char, E_Constant);
682 Set_Never_Set_In_Source (A_Char, True);
683 Set_Is_True_Constant (A_Char, True);
684 Set_Etype (A_Char, Standard_Character);
685 Set_Scope (A_Char, Standard_Entity (S_ASCII));
686 Set_Is_Immediately_Visible (A_Char, False);
687 Set_Is_Public (A_Char, True);
688 Set_Is_Known_Valid (A_Char, True);
690 Append_Entity (A_Char, Standard_Entity (S_ASCII));
691 Set_Defining_Identifier (Decl, A_Char);
693 Set_Object_Definition (Decl, Identifier_For (S_Character));
694 Expr_Decl := New_Node (N_Character_Literal, Staloc);
695 Set_Expression (Decl, Expr_Decl);
697 Set_Is_Static_Expression (Expr_Decl);
698 Set_Chars (Expr_Decl, No_Name);
699 Set_Etype (Expr_Decl, Standard_Character);
700 Set_Char_Literal_Value (Expr_Decl, Ccode);
703 Append (Decl, Decl_A);
705 -- Increment character code, dealing with non-contiguities
709 if Ccode = 16#20# then
711 elsif Ccode = 16#27# then
713 elsif Ccode = 16#3C# then
715 elsif Ccode = 16#41# then
720 -- Create semantic phase entities
722 Standard_Void_Type := New_Standard_Entity;
723 Set_Ekind (Standard_Void_Type, E_Void);
724 Set_Etype (Standard_Void_Type, Standard_Void_Type);
725 Set_Scope (Standard_Void_Type, Standard_Standard);
726 Make_Name (Standard_Void_Type, "_void_type");
728 -- The type field of packages is set to void
730 Set_Etype (Standard_Standard, Standard_Void_Type);
731 Set_Etype (Standard_ASCII, Standard_Void_Type);
733 -- Standard_A_String is actually used in generated code, so it has a
734 -- type name that is reasonable, but does not overlap any Ada name.
736 Standard_A_String := New_Standard_Entity;
737 Set_Ekind (Standard_A_String, E_Access_Type);
738 Set_Scope (Standard_A_String, Standard_Standard);
739 Set_Etype (Standard_A_String, Standard_A_String);
742 Init_Size (Standard_A_String, System_Address_Size);
744 Init_Size (Standard_A_String, System_Address_Size * 2);
747 Init_Alignment (Standard_A_String);
749 Set_Directly_Designated_Type
750 (Standard_A_String, Standard_String);
751 Make_Name (Standard_A_String, "access_string");
753 Standard_A_Char := New_Standard_Entity;
754 Set_Ekind (Standard_A_Char, E_Access_Type);
755 Set_Scope (Standard_A_Char, Standard_Standard);
756 Set_Etype (Standard_A_Char, Standard_A_String);
757 Init_Size (Standard_A_Char, System_Address_Size);
758 Set_Prim_Alignment (Standard_A_Char);
760 Set_Directly_Designated_Type (Standard_A_Char, Standard_Character);
761 Make_Name (Standard_A_Char, "access_character");
763 -- Note on type names. The type names for the following special types
764 -- are constructed so that they will look reasonable should they ever
765 -- appear in error messages etc, although in practice the use of the
766 -- special insertion character } for types results in special handling
767 -- of these type names in any case. The blanks in these names would
768 -- trouble in Gigi, but that's OK here, since none of these types
769 -- should ever get through to Gigi! Attributes of these types are
770 -- filled out to minimize problems with cascaded errors (for example,
771 -- Any_Integer is given reasonable and consistent type and size values)
773 Any_Type := New_Standard_Entity;
774 Decl := New_Node (N_Full_Type_Declaration, Stloc);
775 Set_Defining_Identifier (Decl, Any_Type);
776 Set_Scope (Any_Type, Standard_Standard);
777 Build_Signed_Integer_Type (Any_Type, Standard_Integer_Size);
778 Make_Name (Any_Type, "any type");
780 Any_Id := New_Standard_Entity;
781 Set_Ekind (Any_Id, E_Variable);
782 Set_Scope (Any_Id, Standard_Standard);
783 Set_Etype (Any_Id, Any_Type);
784 Init_Size_Align (Any_Id);
785 Make_Name (Any_Id, "any id");
787 Any_Access := New_Standard_Entity;
788 Set_Ekind (Any_Access, E_Access_Type);
789 Set_Scope (Any_Access, Standard_Standard);
790 Set_Etype (Any_Access, Any_Access);
791 Init_Size (Any_Access, System_Address_Size);
792 Set_Prim_Alignment (Any_Access);
793 Make_Name (Any_Access, "an access type");
795 Any_Character := New_Standard_Entity;
796 Set_Ekind (Any_Character, E_Enumeration_Type);
797 Set_Scope (Any_Character, Standard_Standard);
798 Set_Etype (Any_Character, Any_Character);
799 Set_Is_Unsigned_Type (Any_Character);
800 Set_Is_Character_Type (Any_Character);
801 Init_Esize (Any_Character, Standard_Character_Size);
802 Init_RM_Size (Any_Character, 8);
803 Set_Prim_Alignment (Any_Character);
804 Set_Scalar_Range (Any_Character, Scalar_Range (Standard_Character));
805 Make_Name (Any_Character, "a character type");
807 Any_Array := New_Standard_Entity;
808 Set_Ekind (Any_Array, E_String_Type);
809 Set_Scope (Any_Array, Standard_Standard);
810 Set_Etype (Any_Array, Any_Array);
811 Set_Component_Type (Any_Array, Any_Character);
812 Init_Size_Align (Any_Array);
813 Make_Name (Any_Array, "an array type");
815 Any_Boolean := New_Standard_Entity;
816 Set_Ekind (Any_Boolean, E_Enumeration_Type);
817 Set_Scope (Any_Boolean, Standard_Standard);
818 Set_Etype (Any_Boolean, Standard_Boolean);
819 Init_Esize (Any_Boolean, Standard_Character_Size);
820 Init_RM_Size (Any_Boolean, 1);
821 Set_Prim_Alignment (Any_Boolean);
822 Set_Is_Unsigned_Type (Any_Boolean);
823 Set_Scalar_Range (Any_Boolean, Scalar_Range (Standard_Boolean));
824 Make_Name (Any_Boolean, "a boolean type");
826 Any_Composite := New_Standard_Entity;
827 Set_Ekind (Any_Composite, E_Array_Type);
828 Set_Scope (Any_Composite, Standard_Standard);
829 Set_Etype (Any_Composite, Any_Composite);
830 Set_Component_Size (Any_Composite, Uint_0);
831 Set_Component_Type (Any_Composite, Standard_Integer);
832 Init_Size_Align (Any_Composite);
833 Make_Name (Any_Composite, "a composite type");
835 Any_Discrete := New_Standard_Entity;
836 Set_Ekind (Any_Discrete, E_Signed_Integer_Type);
837 Set_Scope (Any_Discrete, Standard_Standard);
838 Set_Etype (Any_Discrete, Any_Discrete);
839 Init_Size (Any_Discrete, Standard_Integer_Size);
840 Set_Prim_Alignment (Any_Discrete);
841 Make_Name (Any_Discrete, "a discrete type");
843 Any_Fixed := New_Standard_Entity;
844 Set_Ekind (Any_Fixed, E_Ordinary_Fixed_Point_Type);
845 Set_Scope (Any_Fixed, Standard_Standard);
846 Set_Etype (Any_Fixed, Any_Fixed);
847 Init_Size (Any_Fixed, Standard_Integer_Size);
848 Set_Prim_Alignment (Any_Fixed);
849 Make_Name (Any_Fixed, "a fixed-point type");
851 Any_Integer := New_Standard_Entity;
852 Set_Ekind (Any_Integer, E_Signed_Integer_Type);
853 Set_Scope (Any_Integer, Standard_Standard);
854 Set_Etype (Any_Integer, Standard_Long_Long_Integer);
855 Init_Size (Any_Integer, Standard_Long_Long_Integer_Size);
856 Set_Prim_Alignment (Any_Integer);
860 Typ => Base_Type (Standard_Integer),
862 Hb => Intval (High_Bound (Scalar_Range (Standard_Integer))));
863 Make_Name (Any_Integer, "an integer type");
865 Any_Modular := New_Standard_Entity;
866 Set_Ekind (Any_Modular, E_Modular_Integer_Type);
867 Set_Scope (Any_Modular, Standard_Standard);
868 Set_Etype (Any_Modular, Standard_Long_Long_Integer);
869 Init_Size (Any_Modular, Standard_Long_Long_Integer_Size);
870 Set_Prim_Alignment (Any_Modular);
871 Set_Is_Unsigned_Type (Any_Modular);
872 Make_Name (Any_Modular, "a modular type");
874 Any_Numeric := New_Standard_Entity;
875 Set_Ekind (Any_Numeric, E_Signed_Integer_Type);
876 Set_Scope (Any_Numeric, Standard_Standard);
877 Set_Etype (Any_Numeric, Standard_Long_Long_Integer);
878 Init_Size (Any_Numeric, Standard_Long_Long_Integer_Size);
879 Set_Prim_Alignment (Any_Numeric);
880 Make_Name (Any_Numeric, "a numeric type");
882 Any_Real := New_Standard_Entity;
883 Set_Ekind (Any_Real, E_Floating_Point_Type);
884 Set_Scope (Any_Real, Standard_Standard);
885 Set_Etype (Any_Real, Standard_Long_Long_Float);
886 Init_Size (Any_Real, Standard_Long_Long_Float_Size);
887 Set_Prim_Alignment (Any_Real);
888 Make_Name (Any_Real, "a real type");
890 Any_Scalar := New_Standard_Entity;
891 Set_Ekind (Any_Scalar, E_Signed_Integer_Type);
892 Set_Scope (Any_Scalar, Standard_Standard);
893 Set_Etype (Any_Scalar, Any_Scalar);
894 Init_Size (Any_Scalar, Standard_Integer_Size);
895 Set_Prim_Alignment (Any_Scalar);
896 Make_Name (Any_Scalar, "a scalar type");
898 Any_String := New_Standard_Entity;
899 Set_Ekind (Any_String, E_String_Type);
900 Set_Scope (Any_String, Standard_Standard);
901 Set_Etype (Any_String, Any_String);
902 Set_Component_Type (Any_String, Any_Character);
903 Init_Size_Align (Any_String);
904 Make_Name (Any_String, "a string type");
912 Low_Bound => Make_Integer (Uint_0),
913 High_Bound => Make_Integer (Uint_2 ** Standard_Integer_Size));
914 Set_Etype (Index, Standard_Integer);
915 Set_First_Index (Any_String, Index);
918 Standard_Integer_8 := New_Standard_Entity;
919 Decl := New_Node (N_Full_Type_Declaration, Stloc);
920 Set_Defining_Identifier (Decl, Standard_Integer_8);
921 Make_Name (Standard_Integer_8, "integer_8");
922 Set_Scope (Standard_Integer_8, Standard_Standard);
923 Build_Signed_Integer_Type (Standard_Integer_8, 8);
925 Standard_Integer_16 := New_Standard_Entity;
926 Decl := New_Node (N_Full_Type_Declaration, Stloc);
927 Set_Defining_Identifier (Decl, Standard_Integer_16);
928 Make_Name (Standard_Integer_16, "integer_16");
929 Set_Scope (Standard_Integer_16, Standard_Standard);
930 Build_Signed_Integer_Type (Standard_Integer_16, 16);
932 Standard_Integer_32 := New_Standard_Entity;
933 Decl := New_Node (N_Full_Type_Declaration, Stloc);
934 Set_Defining_Identifier (Decl, Standard_Integer_32);
935 Make_Name (Standard_Integer_32, "integer_32");
936 Set_Scope (Standard_Integer_32, Standard_Standard);
937 Build_Signed_Integer_Type (Standard_Integer_32, 32);
939 Standard_Integer_64 := New_Standard_Entity;
940 Decl := New_Node (N_Full_Type_Declaration, Stloc);
941 Set_Defining_Identifier (Decl, Standard_Integer_64);
942 Make_Name (Standard_Integer_64, "integer_64");
943 Set_Scope (Standard_Integer_64, Standard_Standard);
944 Build_Signed_Integer_Type (Standard_Integer_64, 64);
946 Standard_Unsigned := New_Standard_Entity;
947 Decl := New_Node (N_Full_Type_Declaration, Stloc);
948 Set_Defining_Identifier (Decl, Standard_Unsigned);
949 Make_Name (Standard_Unsigned, "unsigned");
951 Set_Ekind (Standard_Unsigned, E_Modular_Integer_Type);
952 Set_Scope (Standard_Unsigned, Standard_Standard);
953 Set_Etype (Standard_Unsigned, Standard_Unsigned);
954 Init_Size (Standard_Unsigned, Standard_Integer_Size);
955 Set_Prim_Alignment (Standard_Unsigned);
956 Set_Modulus (Standard_Unsigned,
957 Uint_2 ** Standard_Integer_Size);
958 Set_Is_Unsigned_Type (Standard_Unsigned);
959 Set_Size_Known_At_Compile_Time
962 R_Node := New_Node (N_Range, Stloc);
963 Set_Low_Bound (R_Node, Make_Integer (Uint_0));
964 Set_High_Bound (R_Node, Make_Integer (Modulus (Standard_Unsigned) - 1));
965 Set_Etype (Low_Bound (R_Node), Standard_Unsigned);
966 Set_Etype (High_Bound (R_Node), Standard_Unsigned);
967 Set_Scalar_Range (Standard_Unsigned, R_Node);
969 -- Note: universal integer and universal real are constructed as fully
970 -- formed signed numeric types, with parameters corresponding to the
971 -- longest runtime types (Long_Long_Integer and Long_Long_Float). This
972 -- allows Gigi to properly process references to universal types that
973 -- are not folded at compile time.
975 Universal_Integer := New_Standard_Entity;
976 Decl := New_Node (N_Full_Type_Declaration, Stloc);
977 Set_Defining_Identifier (Decl, Universal_Integer);
978 Make_Name (Universal_Integer, "universal_integer");
979 Set_Scope (Universal_Integer, Standard_Standard);
980 Build_Signed_Integer_Type
981 (Universal_Integer, Standard_Long_Long_Integer_Size);
983 Universal_Real := New_Standard_Entity;
984 Decl := New_Node (N_Full_Type_Declaration, Stloc);
985 Set_Defining_Identifier (Decl, Universal_Real);
986 Make_Name (Universal_Real, "universal_real");
987 Set_Scope (Universal_Real, Standard_Standard);
990 Standard_Long_Long_Float_Size,
991 Standard_Long_Long_Float_Digits);
993 -- Note: universal fixed, unlike universal integer and universal real,
994 -- is never used at runtime, so it does not need to have bounds set.
996 Universal_Fixed := New_Standard_Entity;
997 Decl := New_Node (N_Full_Type_Declaration, Stloc);
998 Set_Defining_Identifier (Decl, Universal_Fixed);
999 Make_Name (Universal_Fixed, "universal_fixed");
1000 Set_Ekind (Universal_Fixed, E_Ordinary_Fixed_Point_Type);
1001 Set_Etype (Universal_Fixed, Universal_Fixed);
1002 Set_Scope (Universal_Fixed, Standard_Standard);
1003 Init_Size (Universal_Fixed, Standard_Long_Long_Integer_Size);
1004 Set_Prim_Alignment (Universal_Fixed);
1005 Set_Size_Known_At_Compile_Time
1008 -- Create type declaration for Duration, using a 64-bit size. The
1009 -- delta and size values depend on the mode set in system.ads.
1011 Build_Duration : declare
1017 -- In 32 bit mode, the size is 32 bits, and the delta and
1018 -- small values are set to 20 milliseconds (20.0**(10.0**(-3)).
1020 if Duration_32_Bits_On_Target then
1021 Dlo := Intval (Type_Low_Bound (Standard_Integer_32));
1022 Dhi := Intval (Type_High_Bound (Standard_Integer_32));
1023 Delta_Val := UR_From_Components (UI_From_Int (20), Uint_3, 10);
1025 -- In standard 64-bit mode, the size is 64-bits and the delta and
1026 -- amll values are set to nanoseconds (1.0**(10.0**(-9))
1029 Dlo := Intval (Type_Low_Bound (Standard_Integer_64));
1030 Dhi := Intval (Type_High_Bound (Standard_Integer_64));
1031 Delta_Val := UR_From_Components (Uint_1, Uint_9, 10);
1035 Make_Full_Type_Declaration (Stloc,
1036 Defining_Identifier => Standard_Duration,
1038 Make_Ordinary_Fixed_Point_Definition (Stloc,
1039 Delta_Expression => Make_Real_Literal (Stloc, Delta_Val),
1040 Real_Range_Specification =>
1041 Make_Real_Range_Specification (Stloc,
1042 Low_Bound => Make_Real_Literal (Stloc,
1043 Realval => Dlo * Delta_Val),
1044 High_Bound => Make_Real_Literal (Stloc,
1045 Realval => Dhi * Delta_Val))));
1047 Set_Ekind (Standard_Duration, E_Ordinary_Fixed_Point_Type);
1048 Set_Etype (Standard_Duration, Standard_Duration);
1050 if Duration_32_Bits_On_Target then
1051 Init_Size (Standard_Duration, 32);
1053 Init_Size (Standard_Duration, 64);
1056 Set_Prim_Alignment (Standard_Duration);
1057 Set_Delta_Value (Standard_Duration, Delta_Val);
1058 Set_Small_Value (Standard_Duration, Delta_Val);
1059 Set_Scalar_Range (Standard_Duration,
1060 Real_Range_Specification
1061 (Type_Definition (Decl)));
1063 -- Normally it does not matter that nodes in package Standard are
1064 -- not marked as analyzed. The Scalar_Range of the fixed-point
1065 -- type Standard_Duration is an exception, because of the special
1066 -- test made in Freeze.Freeze_Fixed_Point_Type.
1068 Set_Analyzed (Scalar_Range (Standard_Duration));
1070 Set_Etype (Type_High_Bound (Standard_Duration), Standard_Duration);
1071 Set_Etype (Type_Low_Bound (Standard_Duration), Standard_Duration);
1073 Set_Is_Static_Expression (Type_High_Bound (Standard_Duration));
1074 Set_Is_Static_Expression (Type_Low_Bound (Standard_Duration));
1076 Set_Corresponding_Integer_Value
1077 (Type_High_Bound (Standard_Duration), Dhi);
1079 Set_Corresponding_Integer_Value
1080 (Type_Low_Bound (Standard_Duration), Dlo);
1082 Set_Size_Known_At_Compile_Time (Standard_Duration);
1085 -- Build standard exception type. Note that the type name here is
1086 -- actually used in the generated code, so it must be set correctly
1088 Standard_Exception_Type := New_Standard_Entity;
1089 Set_Ekind (Standard_Exception_Type, E_Record_Type);
1090 Set_Etype (Standard_Exception_Type, Standard_Exception_Type);
1091 Set_Scope (Standard_Exception_Type, Standard_Standard);
1092 Set_Stored_Constraint
1093 (Standard_Exception_Type, No_Elist);
1094 Init_Size_Align (Standard_Exception_Type);
1095 Set_Size_Known_At_Compile_Time
1096 (Standard_Exception_Type, True);
1097 Make_Name (Standard_Exception_Type, "exception");
1099 Make_Component (Standard_Exception_Type, Standard_Boolean,
1100 "Not_Handled_By_Others");
1101 Make_Component (Standard_Exception_Type, Standard_Character, "Lang");
1102 Make_Component (Standard_Exception_Type, Standard_Natural,
1104 Make_Component (Standard_Exception_Type, Standard_A_Char,
1106 Make_Component (Standard_Exception_Type, Standard_A_Char,
1108 Make_Component (Standard_Exception_Type, Standard_Integer,
1110 Make_Component (Standard_Exception_Type, Standard_A_Char,
1112 -- Build tree for record declaration, for use by the back-end.
1115 Comp_List : List_Id;
1119 Comp := First_Entity (Standard_Exception_Type);
1120 Comp_List := New_List;
1122 while Present (Comp) loop
1124 Make_Component_Declaration (Stloc,
1125 Defining_Identifier => Comp,
1126 Subtype_Indication => New_Occurrence_Of (Etype (Comp), Stloc)),
1132 Decl := Make_Full_Type_Declaration (Stloc,
1133 Defining_Identifier => Standard_Exception_Type,
1135 Make_Record_Definition (Stloc,
1138 Make_Component_List (Stloc,
1139 Component_Items => Comp_List)));
1142 Append (Decl, Decl_S);
1144 Layout_Type (Standard_Exception_Type);
1146 -- Create declarations of standard exceptions
1148 Build_Exception (S_Constraint_Error);
1149 Build_Exception (S_Program_Error);
1150 Build_Exception (S_Storage_Error);
1151 Build_Exception (S_Tasking_Error);
1153 -- Numeric_Error is a normal exception in Ada 83, but in Ada 95
1154 -- it is a renaming of Constraint_Error
1157 Build_Exception (S_Numeric_Error);
1160 Decl := New_Node (N_Exception_Renaming_Declaration, Stloc);
1161 E_Id := Standard_Entity (S_Numeric_Error);
1163 Set_Ekind (E_Id, E_Exception);
1164 Set_Exception_Code (E_Id, Uint_0);
1165 Set_Etype (E_Id, Standard_Exception_Type);
1166 Set_Is_Public (E_Id);
1167 Set_Renamed_Entity (E_Id, Standard_Entity (S_Constraint_Error));
1169 Set_Defining_Identifier (Decl, E_Id);
1170 Append (Decl, Decl_S);
1172 Ident_Node := New_Node (N_Identifier, Stloc);
1173 Set_Chars (Ident_Node, Chars (Standard_Entity (S_Constraint_Error)));
1174 Set_Entity (Ident_Node, Standard_Entity (S_Constraint_Error));
1175 Set_Name (Decl, Ident_Node);
1178 -- Abort_Signal is an entity that does not get made visible
1180 Abort_Signal := New_Standard_Entity;
1181 Set_Chars (Abort_Signal, Name_uAbort_Signal);
1182 Set_Ekind (Abort_Signal, E_Exception);
1183 Set_Exception_Code (Abort_Signal, Uint_0);
1184 Set_Etype (Abort_Signal, Standard_Exception_Type);
1185 Set_Scope (Abort_Signal, Standard_Standard);
1186 Set_Is_Public (Abort_Signal, True);
1188 Make_Exception_Declaration (Stloc,
1189 Defining_Identifier => Abort_Signal);
1191 -- Create defining identifiers for shift operator entities. Note
1192 -- that these entities are used only for marking shift operators
1193 -- generated internally, and hence need no structure, just a name
1194 -- and a unique identity.
1196 Standard_Op_Rotate_Left := New_Standard_Entity;
1197 Set_Chars (Standard_Op_Rotate_Left, Name_Rotate_Left);
1198 Set_Ekind (Standard_Op_Rotate_Left, E_Operator);
1200 Standard_Op_Rotate_Right := New_Standard_Entity;
1201 Set_Chars (Standard_Op_Rotate_Right, Name_Rotate_Right);
1202 Set_Ekind (Standard_Op_Rotate_Right, E_Operator);
1204 Standard_Op_Shift_Left := New_Standard_Entity;
1205 Set_Chars (Standard_Op_Shift_Left, Name_Shift_Left);
1206 Set_Ekind (Standard_Op_Shift_Left, E_Operator);
1208 Standard_Op_Shift_Right := New_Standard_Entity;
1209 Set_Chars (Standard_Op_Shift_Right, Name_Shift_Right);
1210 Set_Ekind (Standard_Op_Shift_Right, E_Operator);
1212 Standard_Op_Shift_Right_Arithmetic := New_Standard_Entity;
1213 Set_Chars (Standard_Op_Shift_Right_Arithmetic,
1214 Name_Shift_Right_Arithmetic);
1215 Set_Ekind (Standard_Op_Shift_Right_Arithmetic,
1218 -- Create standard operator declarations
1222 -- Initialize visibility table with entities in Standard
1224 for E in Standard_Entity_Type loop
1225 if Ekind (Standard_Entity (E)) /= E_Operator then
1227 (Chars (Standard_Entity (E)), Standard_Entity (E));
1228 Set_Homonym (Standard_Entity (E), Empty);
1231 if E not in S_ASCII_Names then
1232 Set_Scope (Standard_Entity (E), Standard_Standard);
1233 Set_Is_Immediately_Visible (Standard_Entity (E));
1237 -- The predefined package Standard itself does not have a scope;
1238 -- it is the only entity in the system not to have one, and this
1239 -- is what identifies the package to Gigi.
1241 Set_Scope (Standard_Standard, Empty);
1243 -- Set global variables indicating last Id values and version
1245 Last_Standard_Node_Id := Last_Node_Id;
1246 Last_Standard_List_Id := Last_List_Id;
1248 -- The Error node has an Etype of Any_Type to help error recovery
1250 Set_Etype (Error, Any_Type);
1252 -- Print representation of standard if switch set
1254 if Opt.Print_Standard then
1257 end Create_Standard;
1259 ------------------------------------
1260 -- Create_Unconstrained_Base_Type --
1261 ------------------------------------
1263 procedure Create_Unconstrained_Base_Type
1267 New_Ent : constant Entity_Id := New_Copy (E);
1271 Set_Is_Constrained (E, True);
1272 Set_Is_First_Subtype (E, True);
1273 Set_Etype (E, New_Ent);
1275 Append_Entity (New_Ent, Standard_Standard);
1276 Set_Is_Constrained (New_Ent, False);
1277 Set_Etype (New_Ent, New_Ent);
1278 Set_Is_Known_Valid (New_Ent, True);
1280 if K = E_Signed_Integer_Subtype then
1281 Set_Etype (Low_Bound (Scalar_Range (E)), New_Ent);
1282 Set_Etype (High_Bound (Scalar_Range (E)), New_Ent);
1285 end Create_Unconstrained_Base_Type;
1287 --------------------
1288 -- Identifier_For --
1289 --------------------
1291 function Identifier_For (S : Standard_Entity_Type) return Node_Id is
1292 Ident_Node : Node_Id;
1295 Ident_Node := New_Node (N_Identifier, Stloc);
1296 Set_Chars (Ident_Node, Chars (Standard_Entity (S)));
1300 --------------------
1301 -- Make_Component --
1302 --------------------
1304 procedure Make_Component
1309 Id : constant Entity_Id := New_Standard_Entity;
1312 Set_Ekind (Id, E_Component);
1313 Set_Etype (Id, Typ);
1314 Set_Scope (Id, Rec);
1315 Init_Component_Location (Id);
1317 Set_Original_Record_Component (Id, Id);
1318 Make_Name (Id, Nam);
1319 Append_Entity (Id, Rec);
1326 function Make_Formal
1328 Formal_Name : String)
1334 Formal := New_Standard_Entity;
1336 Set_Ekind (Formal, E_In_Parameter);
1337 Set_Mechanism (Formal, Default_Mechanism);
1338 Set_Scope (Formal, Standard_Standard);
1339 Set_Etype (Formal, Typ);
1340 Make_Name (Formal, Formal_Name);
1349 function Make_Integer (V : Uint) return Node_Id is
1350 N : constant Node_Id := Make_Integer_Literal (Stloc, V);
1353 Set_Is_Static_Expression (N);
1361 procedure Make_Name (Id : Entity_Id; Nam : String) is
1363 for J in 1 .. Nam'Length loop
1364 Name_Buffer (J) := Fold_Lower (Nam (Nam'First + (J - 1)));
1367 Name_Len := Nam'Length;
1368 Set_Chars (Id, Name_Find);
1375 function New_Operator (Op : Name_Id; Typ : Entity_Id) return Entity_Id is
1376 Ident_Node : Entity_Id;
1379 Ident_Node := Make_Defining_Identifier (Stloc, Op);
1381 Set_Is_Pure (Ident_Node, True);
1382 Set_Ekind (Ident_Node, E_Operator);
1383 Set_Etype (Ident_Node, Typ);
1384 Set_Scope (Ident_Node, Standard_Standard);
1385 Set_Homonym (Ident_Node, Get_Name_Entity_Id (Op));
1386 Set_Convention (Ident_Node, Convention_Intrinsic);
1388 Set_Is_Immediately_Visible (Ident_Node, True);
1389 Set_Is_Intrinsic_Subprogram (Ident_Node, True);
1391 Set_Name_Entity_Id (Op, Ident_Node);
1392 Append_Entity (Ident_Node, Standard_Standard);
1396 -------------------------
1397 -- New_Standard_Entity --
1398 -------------------------
1400 function New_Standard_Entity
1401 (New_Node_Kind : Node_Kind := N_Defining_Identifier)
1404 E : constant Entity_Id := New_Entity (New_Node_Kind, Stloc);
1407 -- All standard entities are Pure and Public
1412 -- All standard entity names are analyzed manually, and are thus
1413 -- frozen as soon as they are created.
1417 -- Set debug information required for all standard types
1419 Set_Needs_Debug_Info (E);
1421 -- All standard entities are built with fully qualified names, so
1422 -- set the flag to prevent an abortive attempt at requalification!
1424 Set_Has_Qualified_Name (E);
1426 -- Return newly created entity to be completed by caller
1429 end New_Standard_Entity;
1431 --------------------
1432 -- Print_Standard --
1433 --------------------
1435 procedure Print_Standard is
1437 procedure P (Item : String) renames Output.Write_Line;
1438 -- Short-hand, since we do a lot of line writes here!
1440 procedure P_Int_Range (Size : Pos);
1441 -- Prints the range of an integer based on its Size
1443 procedure P_Float_Range (Id : Entity_Id);
1444 -- Prints the bounds range for the given float type entity
1450 procedure P_Float_Range (Id : Entity_Id) is
1451 Digs : constant Nat := UI_To_Int (Digits_Value (Id));
1454 Write_Str (" range ");
1456 if Vax_Float (Id) then
1457 if Digs = VAXFF_Digits then
1458 Write_Str (VAXFF_First'Universal_Literal_String);
1460 Write_Str (VAXFF_Last'Universal_Literal_String);
1462 elsif Digs = VAXDF_Digits then
1463 Write_Str (VAXDF_First'Universal_Literal_String);
1465 Write_Str (VAXDF_Last'Universal_Literal_String);
1468 pragma Assert (Digs = VAXGF_Digits);
1470 Write_Str (VAXGF_First'Universal_Literal_String);
1472 Write_Str (VAXGF_Last'Universal_Literal_String);
1475 elsif Is_AAMP_Float (Id) then
1476 if Digs = AAMPS_Digits then
1477 Write_Str (AAMPS_First'Universal_Literal_String);
1479 Write_Str (AAMPS_Last'Universal_Literal_String);
1482 pragma Assert (Digs = AAMPL_Digits);
1483 Write_Str (AAMPL_First'Universal_Literal_String);
1485 Write_Str (AAMPL_Last'Universal_Literal_String);
1488 elsif Digs = IEEES_Digits then
1489 Write_Str (IEEES_First'Universal_Literal_String);
1491 Write_Str (IEEES_Last'Universal_Literal_String);
1494 elsif Digs = IEEEL_Digits then
1495 Write_Str (IEEEL_First'Universal_Literal_String);
1497 Write_Str (IEEEL_Last'Universal_Literal_String);
1500 pragma Assert (Digs = IEEEX_Digits);
1502 Write_Str (IEEEX_First'Universal_Literal_String);
1504 Write_Str (IEEEX_Last'Universal_Literal_String);
1515 procedure P_Int_Range (Size : Pos) is
1517 Write_Str (" is range -(2 **");
1518 Write_Int (Size - 1);
1520 Write_Str (" .. +(2 **");
1521 Write_Int (Size - 1);
1522 Write_Str (" - 1);");
1526 -- Start of processing for Print_Standard
1529 P ("-- Representation of package Standard");
1531 P ("-- This is not accurate Ada, since new base types cannot be ");
1532 P ("-- created, but the listing shows the target dependent");
1533 P ("-- characteristics of the Standard types for this compiler");
1536 P ("package Standard is");
1537 P ("pragma Pure(Standard);");
1540 P (" type Boolean is (False, True);");
1541 P (" for Boolean'Size use 1;");
1542 P (" for Boolean use (False => 0, True => 1);");
1547 Write_Str (" type Integer");
1548 P_Int_Range (Standard_Integer_Size);
1549 Write_Str (" for Integer'Size use ");
1550 Write_Int (Standard_Integer_Size);
1554 P (" subtype Natural is Integer range 0 .. Integer'Last;");
1555 P (" subtype Positive is Integer range 1 .. Integer'Last;");
1558 Write_Str (" type Short_Short_Integer");
1559 P_Int_Range (Standard_Short_Short_Integer_Size);
1560 Write_Str (" for Short_Short_Integer'Size use ");
1561 Write_Int (Standard_Short_Short_Integer_Size);
1565 Write_Str (" type Short_Integer");
1566 P_Int_Range (Standard_Short_Integer_Size);
1567 Write_Str (" for Short_Integer'Size use ");
1568 Write_Int (Standard_Short_Integer_Size);
1572 Write_Str (" type Long_Integer");
1573 P_Int_Range (Standard_Long_Integer_Size);
1574 Write_Str (" for Long_Integer'Size use ");
1575 Write_Int (Standard_Long_Integer_Size);
1579 Write_Str (" type Long_Long_Integer");
1580 P_Int_Range (Standard_Long_Long_Integer_Size);
1581 Write_Str (" for Long_Long_Integer'Size use ");
1582 Write_Int (Standard_Long_Long_Integer_Size);
1586 -- Floating point types
1588 Write_Str (" type Short_Float is digits ");
1589 Write_Int (Standard_Short_Float_Digits);
1591 P_Float_Range (Standard_Short_Float);
1592 Write_Str (" for Short_Float'Size use ");
1593 Write_Int (Standard_Short_Float_Size);
1597 Write_Str (" type Float is digits ");
1598 Write_Int (Standard_Float_Digits);
1600 P_Float_Range (Standard_Float);
1601 Write_Str (" for Float'Size use ");
1602 Write_Int (Standard_Float_Size);
1606 Write_Str (" type Long_Float is digits ");
1607 Write_Int (Standard_Long_Float_Digits);
1609 P_Float_Range (Standard_Long_Float);
1610 Write_Str (" for Long_Float'Size use ");
1611 Write_Int (Standard_Long_Float_Size);
1615 Write_Str (" type Long_Long_Float is digits ");
1616 Write_Int (Standard_Long_Long_Float_Digits);
1618 P_Float_Range (Standard_Long_Long_Float);
1619 Write_Str (" for Long_Long_Float'Size use ");
1620 Write_Int (Standard_Long_Long_Float_Size);
1624 P (" type Character is (...)");
1625 Write_Str (" for Character'Size use ");
1626 Write_Int (Standard_Character_Size);
1628 P (" -- See RM A.1(35) for details of this type");
1631 P (" type Wide_Character is (...)");
1632 Write_Str (" for Wide_Character'Size use ");
1633 Write_Int (Standard_Wide_Character_Size);
1635 P (" -- See RM A.1(36) for details of this type");
1638 P (" type String is array (Positive range <>) of Character;");
1639 P (" pragma Pack (String);");
1642 P (" type Wide_String is array (Positive range <>)" &
1643 " of Wide_Character;");
1644 P (" pragma Pack (Wide_String);");
1647 -- Here it's OK to use the Duration type of the host compiler since
1648 -- the implementation of Duration in GNAT is target independent.
1650 if Duration_32_Bits_On_Target then
1651 P (" type Duration is delta 0.020");
1652 P (" range -((2 ** 31 - 1) * 0.020) ..");
1653 P (" +((2 ** 31 - 1) * 0.020);");
1654 P (" for Duration'Small use 0.020;");
1656 P (" type Duration is delta 0.000000001");
1657 P (" range -((2 ** 63 - 1) * 0.000000001) ..");
1658 P (" +((2 ** 63 - 1) * 0.000000001);");
1659 P (" for Duration'Small use 0.000000001;");
1664 P (" Constraint_Error : exception;");
1665 P (" Program_Error : exception;");
1666 P (" Storage_Error : exception;");
1667 P (" Tasking_Error : exception;");
1668 P (" Numeric_Error : exception renames Constraint_Error;");
1671 P ("end Standard;");
1674 ----------------------
1675 -- Set_Float_Bounds --
1676 ----------------------
1678 procedure Set_Float_Bounds (Id : Entity_Id) is
1680 -- Low bound of literal value
1683 -- High bound of literal value
1686 -- Range specification
1688 Digs : constant Nat := UI_To_Int (Digits_Value (Id));
1689 -- Digits value, used to select bounds
1692 -- Note: for the call from Cstand to initially create the types in
1693 -- Standard, Vax_Float will always be False. Circuitry in Sem_Vfpt
1694 -- will adjust these types appropriately in the Vax_Float case if
1695 -- a pragma Float_Representation (VAX_Float) is used.
1697 if Vax_Float (Id) then
1698 if Digs = VAXFF_Digits then
1700 (VAXFF_First'Universal_Literal_String);
1702 (VAXFF_Last'Universal_Literal_String);
1704 elsif Digs = VAXDF_Digits then
1706 (VAXDF_First'Universal_Literal_String);
1708 (VAXDF_Last'Universal_Literal_String);
1711 pragma Assert (Digs = VAXGF_Digits);
1714 (VAXGF_First'Universal_Literal_String);
1716 (VAXGF_Last'Universal_Literal_String);
1719 elsif Is_AAMP_Float (Id) then
1720 if Digs = AAMPS_Digits then
1722 (AAMPS_First'Universal_Literal_String);
1724 (AAMPS_Last'Universal_Literal_String);
1727 pragma Assert (Digs = AAMPL_Digits);
1729 (AAMPL_First'Universal_Literal_String);
1731 (AAMPL_Last'Universal_Literal_String);
1734 elsif Digs = IEEES_Digits then
1736 (IEEES_First'Universal_Literal_String);
1738 (IEEES_Last'Universal_Literal_String);
1740 elsif Digs = IEEEL_Digits then
1742 (IEEEL_First'Universal_Literal_String);
1744 (IEEEL_Last'Universal_Literal_String);
1747 pragma Assert (Digs = IEEEX_Digits);
1750 (IEEEX_First'Universal_Literal_String);
1752 (IEEEX_Last'Universal_Literal_String);
1756 Set_Is_Static_Expression (L);
1759 Set_Is_Static_Expression (H);
1761 R := New_Node (N_Range, Stloc);
1762 Set_Low_Bound (R, L);
1763 Set_High_Bound (R, H);
1764 Set_Includes_Infinities (R, True);
1765 Set_Scalar_Range (Id, R);
1768 end Set_Float_Bounds;
1770 ------------------------
1771 -- Set_Integer_Bounds --
1772 ------------------------
1774 procedure Set_Integer_Bounds
1780 L : Node_Id; -- Low bound of literal value
1781 H : Node_Id; -- High bound of literal value
1782 R : Node_Id; -- Range specification
1785 L := Make_Integer (Lb);
1786 H := Make_Integer (Hb);
1791 R := New_Node (N_Range, Stloc);
1792 Set_Low_Bound (R, L);
1793 Set_High_Bound (R, H);
1794 Set_Scalar_Range (Id, R);
1797 Set_Is_Unsigned_Type (Id, Lb >= 0);
1798 end Set_Integer_Bounds;