1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2004 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) return Entity_Id
;
108 -- Construct entity for subprogram formal with given name and type
110 function Make_Integer
(V
: Uint
) return Node_Id
;
111 -- Builds integer literal with given value
113 procedure Make_Name
(Id
: Entity_Id
; Nam
: String);
114 -- Make an entry in the names table for Nam, and set as Chars field of Id
116 function New_Operator
(Op
: Name_Id
; Typ
: Entity_Id
) return Entity_Id
;
117 -- Build entity for standard operator with given name and type.
119 function New_Standard_Entity
120 (New_Node_Kind
: Node_Kind
:= N_Defining_Identifier
) return Entity_Id
;
121 -- Builds a new entity for Standard
123 procedure Print_Standard
;
124 -- Print representation of package Standard if switch set
126 procedure Set_Integer_Bounds
131 -- Procedure to set bounds for integer type or subtype. Id is the entity
132 -- whose bounds and type are to be set. The Typ parameter is the Etype
133 -- value for the entity (which will be the same as Id for all predefined
134 -- integer base types. The third and fourth parameters are the bounds.
136 ----------------------
137 -- Build_Float_Type --
138 ----------------------
140 procedure Build_Float_Type
(E
: Entity_Id
; Siz
: Int
; Digs
: Int
) is
142 Set_Type_Definition
(Parent
(E
),
143 Make_Floating_Point_Definition
(Stloc
,
144 Digits_Expression
=> Make_Integer
(UI_From_Int
(Digs
))));
145 Set_Ekind
(E
, E_Floating_Point_Type
);
148 Set_Elem_Alignment
(E
);
149 Init_Digits_Value
(E
, Digs
);
150 Set_Float_Bounds
(E
);
153 Set_Size_Known_At_Compile_Time
(E
);
154 end Build_Float_Type
;
156 -------------------------------
157 -- Build_Signed_Integer_Type --
158 -------------------------------
160 procedure Build_Signed_Integer_Type
(E
: Entity_Id
; Siz
: Int
) is
161 U2Siz1
: constant Uint
:= 2 ** (Siz
- 1);
162 Lbound
: constant Uint
:= -U2Siz1
;
163 Ubound
: constant Uint
:= U2Siz1
- 1;
166 Set_Type_Definition
(Parent
(E
),
167 Make_Signed_Integer_Type_Definition
(Stloc
,
168 Low_Bound
=> Make_Integer
(Lbound
),
169 High_Bound
=> Make_Integer
(Ubound
)));
171 Set_Ekind
(E
, E_Signed_Integer_Type
);
174 Set_Elem_Alignment
(E
);
175 Set_Integer_Bounds
(E
, E
, Lbound
, Ubound
);
178 Set_Is_Known_Valid
(E
);
179 Set_Size_Known_At_Compile_Time
(E
);
180 end Build_Signed_Integer_Type
;
182 ----------------------
183 -- Create_Operators --
184 ----------------------
186 -- Each operator has an abbreviated signature. The formals have the names
187 -- LEFT and RIGHT. Their types are not actually used for resolution.
189 procedure Create_Operators
is
192 -- The following tables define the binary and unary operators and their
193 -- corresponding result type.
195 Binary_Ops
: constant array (S_Binary_Ops
) of Name_Id
:=
197 -- There is one entry here for each binary operator, except for the
198 -- case of concatenation, where there are two entries, one for a
199 -- String result, and one for a Wide_String result.
220 Bin_Op_Types
: constant array (S_Binary_Ops
) of Entity_Id
:=
222 -- This table has the corresponding result types. The entries are
223 -- ordered so they correspond to the Binary_Ops array above.
225 (Universal_Integer
, -- Add
226 Standard_Boolean
, -- And
227 Standard_String
, -- Concat (String)
228 Standard_Wide_String
, -- Concat (Wide_String)
229 Universal_Integer
, -- Divide
230 Standard_Boolean
, -- Eq
231 Universal_Integer
, -- Expon
232 Standard_Boolean
, -- Ge
233 Standard_Boolean
, -- Gt
234 Standard_Boolean
, -- Le
235 Standard_Boolean
, -- Lt
236 Universal_Integer
, -- Mod
237 Universal_Integer
, -- Multiply
238 Standard_Boolean
, -- Ne
239 Standard_Boolean
, -- Or
240 Universal_Integer
, -- Rem
241 Universal_Integer
, -- Subtract
242 Standard_Boolean
); -- Xor
244 Unary_Ops
: constant array (S_Unary_Ops
) of Name_Id
:=
246 -- There is one entry here for each unary operator
253 Unary_Op_Types
: constant array (S_Unary_Ops
) of Entity_Id
:=
255 -- This table has the corresponding result types. The entries are
256 -- ordered so they correspond to the Unary_Ops array above.
258 (Universal_Integer
, -- Abs
259 Universal_Integer
, -- Subtract
260 Standard_Boolean
, -- Not
261 Universal_Integer
); -- Add
264 for J
in S_Binary_Ops
loop
265 Op_Node
:= New_Operator
(Binary_Ops
(J
), Bin_Op_Types
(J
));
267 Append_Entity
(Make_Formal
(Any_Type
, "LEFT"), Op_Node
);
268 Append_Entity
(Make_Formal
(Any_Type
, "RIGHT"), Op_Node
);
271 for J
in S_Unary_Ops
loop
272 Op_Node
:= New_Operator
(Unary_Ops
(J
), Unary_Op_Types
(J
));
274 Append_Entity
(Make_Formal
(Any_Type
, "RIGHT"), Op_Node
);
277 -- For concatenation, we create a separate operator for each
278 -- array type. This simplifies the resolution of the component-
279 -- component concatenation operation. In Standard, we set the types
280 -- of the formals for string and wide string concatenation.
282 Set_Etype
(First_Entity
(Standard_Op_Concat
), Standard_String
);
283 Set_Etype
(Last_Entity
(Standard_Op_Concat
), Standard_String
);
285 Set_Etype
(First_Entity
(Standard_Op_Concatw
), Standard_Wide_String
);
286 Set_Etype
(Last_Entity
(Standard_Op_Concatw
), Standard_Wide_String
);
287 end Create_Operators
;
289 ---------------------
290 -- Create_Standard --
291 ---------------------
293 -- The tree for the package Standard is prefixed to all compilations.
294 -- Several entities required by semantic analysis are denoted by global
295 -- variables that are initialized to point to the corresponding
296 -- occurrences in STANDARD. The visible entities of STANDARD are
297 -- created here. The private entities defined in STANDARD are created
298 -- by Initialize_Standard in the semantics module.
300 procedure Create_Standard
is
301 Decl_S
: constant List_Id
:= New_List
;
302 -- List of declarations in Standard
304 Decl_A
: constant List_Id
:= New_List
;
305 -- List of declarations in ASCII
310 Ident_Node
: Node_Id
;
316 procedure Build_Exception
(S
: Standard_Entity_Type
);
317 -- Procedure to declare given entity as an exception
319 ---------------------
320 -- Build_Exception --
321 ---------------------
323 procedure Build_Exception
(S
: Standard_Entity_Type
) is
325 Set_Ekind
(Standard_Entity
(S
), E_Exception
);
326 Set_Etype
(Standard_Entity
(S
), Standard_Exception_Type
);
327 Set_Exception_Code
(Standard_Entity
(S
), Uint_0
);
328 Set_Is_Public
(Standard_Entity
(S
), True);
331 Make_Exception_Declaration
(Stloc
,
332 Defining_Identifier
=> Standard_Entity
(S
));
333 Append
(Decl
, Decl_S
);
336 -- Start of processing for Create_Standard
339 -- Initialize scanner for internal scans of literals
341 Scn
.Initialize_Scanner
(No_Unit
, Internal_Source_File
);
343 -- First step is to create defining identifiers for each entity
345 for S
in Standard_Entity_Type
loop
347 S_Name
: constant String := Standard_Entity_Type
'Image (S
);
348 -- Name of entity (note we skip S_ at the start)
350 Ident_Node
: Node_Id
;
351 -- Defining identifier node
354 Ident_Node
:= New_Standard_Entity
;
355 Make_Name
(Ident_Node
, S_Name
(3 .. S_Name
'Length));
356 Standard_Entity
(S
) := Ident_Node
;
360 -- Create package declaration node for package Standard
362 Standard_Package_Node
:= New_Node
(N_Package_Declaration
, Stloc
);
364 Pspec
:= New_Node
(N_Package_Specification
, Stloc
);
365 Set_Specification
(Standard_Package_Node
, Pspec
);
367 Set_Defining_Unit_Name
(Pspec
, Standard_Standard
);
368 Set_Visible_Declarations
(Pspec
, Decl_S
);
370 Set_Ekind
(Standard_Standard
, E_Package
);
371 Set_Is_Pure
(Standard_Standard
);
372 Set_Is_Compilation_Unit
(Standard_Standard
);
374 -- Create type declaration nodes for standard types
376 for S
in S_Types
loop
377 Decl
:= New_Node
(N_Full_Type_Declaration
, Stloc
);
378 Set_Defining_Identifier
(Decl
, Standard_Entity
(S
));
379 Set_Is_Frozen
(Standard_Entity
(S
));
380 Set_Is_Public
(Standard_Entity
(S
));
381 Append
(Decl
, Decl_S
);
384 -- Create type definition node for type Boolean. The Size is set to
385 -- 1 as required by Ada 95 and current ARG interpretations for Ada/83.
387 -- Note: Object_Size of Boolean is 8. This means that we do NOT in
388 -- general know that Boolean variables have valid values, so we do
389 -- not set the Is_Known_Valid flag.
391 Tdef_Node
:= New_Node
(N_Enumeration_Type_Definition
, Stloc
);
392 Set_Literals
(Tdef_Node
, New_List
);
393 Append
(Standard_False
, Literals
(Tdef_Node
));
394 Append
(Standard_True
, Literals
(Tdef_Node
));
395 Set_Type_Definition
(Parent
(Standard_Boolean
), Tdef_Node
);
397 Set_Ekind
(Standard_Boolean
, E_Enumeration_Type
);
398 Set_First_Literal
(Standard_Boolean
, Standard_False
);
399 Set_Etype
(Standard_Boolean
, Standard_Boolean
);
400 Init_Esize
(Standard_Boolean
, Standard_Character_Size
);
401 Init_RM_Size
(Standard_Boolean
, 1);
402 Set_Elem_Alignment
(Standard_Boolean
);
404 Set_Is_Unsigned_Type
(Standard_Boolean
);
405 Set_Size_Known_At_Compile_Time
(Standard_Boolean
);
407 Set_Ekind
(Standard_True
, E_Enumeration_Literal
);
408 Set_Etype
(Standard_True
, Standard_Boolean
);
409 Set_Enumeration_Pos
(Standard_True
, Uint_1
);
410 Set_Enumeration_Rep
(Standard_True
, Uint_1
);
411 Set_Is_Known_Valid
(Standard_True
, True);
413 Set_Ekind
(Standard_False
, E_Enumeration_Literal
);
414 Set_Etype
(Standard_False
, Standard_Boolean
);
415 Set_Enumeration_Pos
(Standard_False
, Uint_0
);
416 Set_Enumeration_Rep
(Standard_False
, Uint_0
);
417 Set_Is_Known_Valid
(Standard_False
, True);
419 -- For the bounds of Boolean, we create a range node corresponding to
421 -- range False .. True
423 -- where the occurrences of the literals must point to the
424 -- corresponding definition.
426 R_Node
:= New_Node
(N_Range
, Stloc
);
427 B_Node
:= New_Node
(N_Identifier
, Stloc
);
428 Set_Chars
(B_Node
, Chars
(Standard_False
));
429 Set_Entity
(B_Node
, Standard_False
);
430 Set_Etype
(B_Node
, Standard_Boolean
);
431 Set_Is_Static_Expression
(B_Node
);
432 Set_Low_Bound
(R_Node
, B_Node
);
434 B_Node
:= New_Node
(N_Identifier
, Stloc
);
435 Set_Chars
(B_Node
, Chars
(Standard_True
));
436 Set_Entity
(B_Node
, Standard_True
);
437 Set_Etype
(B_Node
, Standard_Boolean
);
438 Set_Is_Static_Expression
(B_Node
);
439 Set_High_Bound
(R_Node
, B_Node
);
441 Set_Scalar_Range
(Standard_Boolean
, R_Node
);
442 Set_Etype
(R_Node
, Standard_Boolean
);
443 Set_Parent
(R_Node
, Standard_Boolean
);
445 -- Record entity identifiers for boolean literals in the
446 -- Boolean_Literals array, for easy reference during expansion.
448 Boolean_Literals
:= (False => Standard_False
, True => Standard_True
);
450 -- Create type definition nodes for predefined integer types
452 Build_Signed_Integer_Type
453 (Standard_Short_Short_Integer
, Standard_Short_Short_Integer_Size
);
455 Build_Signed_Integer_Type
456 (Standard_Short_Integer
, Standard_Short_Integer_Size
);
458 Build_Signed_Integer_Type
459 (Standard_Integer
, Standard_Integer_Size
);
467 LIS
:= Standard_Long_Integer_Size
;
470 Build_Signed_Integer_Type
(Standard_Long_Integer
, LIS
);
473 Build_Signed_Integer_Type
474 (Standard_Long_Long_Integer
, Standard_Long_Long_Integer_Size
);
476 Create_Unconstrained_Base_Type
477 (Standard_Short_Short_Integer
, E_Signed_Integer_Subtype
);
479 Create_Unconstrained_Base_Type
480 (Standard_Short_Integer
, E_Signed_Integer_Subtype
);
482 Create_Unconstrained_Base_Type
483 (Standard_Integer
, E_Signed_Integer_Subtype
);
485 Create_Unconstrained_Base_Type
486 (Standard_Long_Integer
, E_Signed_Integer_Subtype
);
488 Create_Unconstrained_Base_Type
489 (Standard_Long_Long_Integer
, E_Signed_Integer_Subtype
);
491 -- Create type definition nodes for predefined float types
494 (Standard_Short_Float
,
495 Standard_Short_Float_Size
,
496 Standard_Short_Float_Digits
);
501 Standard_Float_Digits
);
504 (Standard_Long_Float
,
505 Standard_Long_Float_Size
,
506 Standard_Long_Float_Digits
);
509 (Standard_Long_Long_Float
,
510 Standard_Long_Long_Float_Size
,
511 Standard_Long_Long_Float_Digits
);
513 -- Create type definition node for type Character. Note that we do not
514 -- set the Literals field, since type Character is handled with special
515 -- routine that do not need a literal list.
517 Tdef_Node
:= New_Node
(N_Enumeration_Type_Definition
, Stloc
);
518 Set_Type_Definition
(Parent
(Standard_Character
), Tdef_Node
);
520 Set_Ekind
(Standard_Character
, E_Enumeration_Type
);
521 Set_Etype
(Standard_Character
, Standard_Character
);
522 Init_Esize
(Standard_Character
, Standard_Character_Size
);
523 Init_RM_Size
(Standard_Character
, 8);
524 Set_Elem_Alignment
(Standard_Character
);
526 Set_Is_Unsigned_Type
(Standard_Character
);
527 Set_Is_Character_Type
(Standard_Character
);
528 Set_Is_Known_Valid
(Standard_Character
);
529 Set_Size_Known_At_Compile_Time
(Standard_Character
);
531 -- Create the bounds for type Character.
533 R_Node
:= New_Node
(N_Range
, Stloc
);
535 -- Low bound for type Character (Standard.Nul)
537 B_Node
:= New_Node
(N_Character_Literal
, Stloc
);
538 Set_Is_Static_Expression
(B_Node
);
539 Set_Chars
(B_Node
, No_Name
);
540 Set_Char_Literal_Value
(B_Node
, 16#
00#
);
541 Set_Entity
(B_Node
, Empty
);
542 Set_Etype
(B_Node
, Standard_Character
);
543 Set_Low_Bound
(R_Node
, B_Node
);
545 -- High bound for type Character
547 B_Node
:= New_Node
(N_Character_Literal
, Stloc
);
548 Set_Is_Static_Expression
(B_Node
);
549 Set_Chars
(B_Node
, No_Name
);
550 Set_Char_Literal_Value
(B_Node
, 16#FF#
);
551 Set_Entity
(B_Node
, Empty
);
552 Set_Etype
(B_Node
, Standard_Character
);
553 Set_High_Bound
(R_Node
, B_Node
);
555 Set_Scalar_Range
(Standard_Character
, R_Node
);
556 Set_Etype
(R_Node
, Standard_Character
);
557 Set_Parent
(R_Node
, Standard_Character
);
559 -- Create type definition for type Wide_Character. Note that we do not
560 -- set the Literals field, since type Wide_Character is handled with
561 -- special routines that do not need a literal list.
563 Tdef_Node
:= New_Node
(N_Enumeration_Type_Definition
, Stloc
);
564 Set_Type_Definition
(Parent
(Standard_Wide_Character
), Tdef_Node
);
566 Set_Ekind
(Standard_Wide_Character
, E_Enumeration_Type
);
567 Set_Etype
(Standard_Wide_Character
, Standard_Wide_Character
);
568 Init_Size
(Standard_Wide_Character
, Standard_Wide_Character_Size
);
570 Set_Elem_Alignment
(Standard_Wide_Character
);
571 Set_Is_Unsigned_Type
(Standard_Wide_Character
);
572 Set_Is_Character_Type
(Standard_Wide_Character
);
573 Set_Is_Known_Valid
(Standard_Wide_Character
);
574 Set_Size_Known_At_Compile_Time
(Standard_Wide_Character
);
576 -- Create the bounds for type Wide_Character.
578 R_Node
:= New_Node
(N_Range
, Stloc
);
580 -- Low bound for type Wide_Character
582 B_Node
:= New_Node
(N_Character_Literal
, Stloc
);
583 Set_Is_Static_Expression
(B_Node
);
584 Set_Chars
(B_Node
, No_Name
); -- ???
585 Set_Char_Literal_Value
(B_Node
, 16#
0000#
);
586 Set_Entity
(B_Node
, Empty
);
587 Set_Etype
(B_Node
, Standard_Wide_Character
);
588 Set_Low_Bound
(R_Node
, B_Node
);
590 -- High bound for type Wide_Character
592 B_Node
:= New_Node
(N_Character_Literal
, Stloc
);
593 Set_Is_Static_Expression
(B_Node
);
594 Set_Chars
(B_Node
, No_Name
); -- ???
595 Set_Char_Literal_Value
(B_Node
, 16#FFFF#
);
596 Set_Entity
(B_Node
, Empty
);
597 Set_Etype
(B_Node
, Standard_Wide_Character
);
598 Set_High_Bound
(R_Node
, B_Node
);
600 Set_Scalar_Range
(Standard_Wide_Character
, R_Node
);
601 Set_Etype
(R_Node
, Standard_Wide_Character
);
602 Set_Parent
(R_Node
, Standard_Wide_Character
);
604 -- Create type definition node for type String
606 Tdef_Node
:= New_Node
(N_Unconstrained_Array_Definition
, Stloc
);
609 CompDef_Node
: Node_Id
;
611 CompDef_Node
:= New_Node
(N_Component_Definition
, Stloc
);
612 Set_Aliased_Present
(CompDef_Node
, False);
613 Set_Access_Definition
(CompDef_Node
, Empty
);
614 Set_Subtype_Indication
(CompDef_Node
, Identifier_For
(S_Character
));
615 Set_Component_Definition
(Tdef_Node
, CompDef_Node
);
618 Set_Subtype_Marks
(Tdef_Node
, New_List
);
619 Append
(Identifier_For
(S_Positive
), Subtype_Marks
(Tdef_Node
));
620 Set_Type_Definition
(Parent
(Standard_String
), Tdef_Node
);
622 Set_Ekind
(Standard_String
, E_String_Type
);
623 Set_Etype
(Standard_String
, Standard_String
);
624 Set_Component_Type
(Standard_String
, Standard_Character
);
625 Set_Component_Size
(Standard_String
, Uint_8
);
626 Init_Size_Align
(Standard_String
);
627 Set_Alignment
(Standard_String
, Uint_1
);
629 -- Set index type of String
632 (Subtype_Marks
(Type_Definition
(Parent
(Standard_String
))));
633 Set_First_Index
(Standard_String
, E_Id
);
634 Set_Entity
(E_Id
, Standard_Positive
);
635 Set_Etype
(E_Id
, Standard_Positive
);
637 -- Create type definition node for type Wide_String
639 Tdef_Node
:= New_Node
(N_Unconstrained_Array_Definition
, Stloc
);
641 CompDef_Node
: Node_Id
;
643 CompDef_Node
:= New_Node
(N_Component_Definition
, Stloc
);
644 Set_Aliased_Present
(CompDef_Node
, False);
645 Set_Access_Definition
(CompDef_Node
, Empty
);
646 Set_Subtype_Indication
(CompDef_Node
,
647 Identifier_For
(S_Wide_Character
));
648 Set_Component_Definition
(Tdef_Node
, CompDef_Node
);
650 Set_Subtype_Marks
(Tdef_Node
, New_List
);
651 Append
(Identifier_For
(S_Positive
), Subtype_Marks
(Tdef_Node
));
652 Set_Type_Definition
(Parent
(Standard_Wide_String
), Tdef_Node
);
654 Set_Ekind
(Standard_Wide_String
, E_String_Type
);
655 Set_Etype
(Standard_Wide_String
, Standard_Wide_String
);
656 Set_Component_Type
(Standard_Wide_String
, Standard_Wide_Character
);
657 Set_Component_Size
(Standard_Wide_String
, Uint_16
);
658 Init_Size_Align
(Standard_Wide_String
);
660 -- Set index type of Wide_String
663 (Subtype_Marks
(Type_Definition
(Parent
(Standard_Wide_String
))));
664 Set_First_Index
(Standard_Wide_String
, E_Id
);
665 Set_Entity
(E_Id
, Standard_Positive
);
666 Set_Etype
(E_Id
, Standard_Positive
);
668 -- Create subtype declaration for Natural
670 Decl
:= New_Node
(N_Subtype_Declaration
, Stloc
);
671 Set_Defining_Identifier
(Decl
, Standard_Natural
);
672 Set_Subtype_Indication
(Decl
,
673 New_Occurrence_Of
(Standard_Integer
, Stloc
));
674 Append
(Decl
, Decl_S
);
676 Set_Ekind
(Standard_Natural
, E_Signed_Integer_Subtype
);
677 Set_Etype
(Standard_Natural
, Base_Type
(Standard_Integer
));
678 Init_Esize
(Standard_Natural
, Standard_Integer_Size
);
679 Init_RM_Size
(Standard_Natural
, Standard_Integer_Size
- 1);
680 Set_Elem_Alignment
(Standard_Natural
);
681 Set_Size_Known_At_Compile_Time
683 Set_Integer_Bounds
(Standard_Natural
,
684 Typ
=> Base_Type
(Standard_Integer
),
686 Hb
=> Intval
(High_Bound
(Scalar_Range
(Standard_Integer
))));
687 Set_Is_Constrained
(Standard_Natural
);
688 Set_Is_Frozen
(Standard_Natural
);
689 Set_Is_Public
(Standard_Natural
);
691 -- Create subtype declaration for Positive
693 Decl
:= New_Node
(N_Subtype_Declaration
, Stloc
);
694 Set_Defining_Identifier
(Decl
, Standard_Positive
);
695 Set_Subtype_Indication
(Decl
,
696 New_Occurrence_Of
(Standard_Integer
, Stloc
));
697 Append
(Decl
, Decl_S
);
699 Set_Ekind
(Standard_Positive
, E_Signed_Integer_Subtype
);
700 Set_Etype
(Standard_Positive
, Base_Type
(Standard_Integer
));
701 Init_Esize
(Standard_Positive
, Standard_Integer_Size
);
702 Init_RM_Size
(Standard_Positive
, Standard_Integer_Size
- 1);
703 Set_Elem_Alignment
(Standard_Positive
);
705 Set_Size_Known_At_Compile_Time
(Standard_Positive
);
707 Set_Integer_Bounds
(Standard_Positive
,
708 Typ
=> Base_Type
(Standard_Integer
),
710 Hb
=> Intval
(High_Bound
(Scalar_Range
(Standard_Integer
))));
711 Set_Is_Constrained
(Standard_Positive
);
712 Set_Is_Frozen
(Standard_Positive
);
713 Set_Is_Public
(Standard_Positive
);
715 -- Create declaration for package ASCII
717 Decl
:= New_Node
(N_Package_Declaration
, Stloc
);
718 Append
(Decl
, Decl_S
);
720 Pspec
:= New_Node
(N_Package_Specification
, Stloc
);
721 Set_Specification
(Decl
, Pspec
);
723 Set_Defining_Unit_Name
(Pspec
, Standard_Entity
(S_ASCII
));
724 Set_Ekind
(Standard_Entity
(S_ASCII
), E_Package
);
725 Set_Visible_Declarations
(Pspec
, Decl_A
);
727 -- Create control character definitions in package ASCII. Note that
728 -- the character literal entries created here correspond to literal
729 -- values that are impossible in the source, but can be represented
730 -- internally with no difficulties.
734 for S
in S_ASCII_Names
loop
735 Decl
:= New_Node
(N_Object_Declaration
, Staloc
);
736 Set_Constant_Present
(Decl
, True);
739 A_Char
: constant Entity_Id
:= Standard_Entity
(S
);
743 Set_Sloc
(A_Char
, Staloc
);
744 Set_Ekind
(A_Char
, E_Constant
);
745 Set_Never_Set_In_Source
(A_Char
, True);
746 Set_Is_True_Constant
(A_Char
, True);
747 Set_Etype
(A_Char
, Standard_Character
);
748 Set_Scope
(A_Char
, Standard_Entity
(S_ASCII
));
749 Set_Is_Immediately_Visible
(A_Char
, False);
750 Set_Is_Public
(A_Char
, True);
751 Set_Is_Known_Valid
(A_Char
, True);
753 Append_Entity
(A_Char
, Standard_Entity
(S_ASCII
));
754 Set_Defining_Identifier
(Decl
, A_Char
);
756 Set_Object_Definition
(Decl
, Identifier_For
(S_Character
));
757 Expr_Decl
:= New_Node
(N_Character_Literal
, Staloc
);
758 Set_Expression
(Decl
, Expr_Decl
);
760 Set_Is_Static_Expression
(Expr_Decl
);
761 Set_Chars
(Expr_Decl
, No_Name
);
762 Set_Etype
(Expr_Decl
, Standard_Character
);
763 Set_Char_Literal_Value
(Expr_Decl
, Ccode
);
766 Append
(Decl
, Decl_A
);
768 -- Increment character code, dealing with non-contiguities
772 if Ccode
= 16#
20#
then
774 elsif Ccode
= 16#
27#
then
776 elsif Ccode
= 16#
3C#
then
778 elsif Ccode
= 16#
41#
then
783 -- Create semantic phase entities
785 Standard_Void_Type
:= New_Standard_Entity
;
786 Set_Ekind
(Standard_Void_Type
, E_Void
);
787 Set_Etype
(Standard_Void_Type
, Standard_Void_Type
);
788 Set_Scope
(Standard_Void_Type
, Standard_Standard
);
789 Make_Name
(Standard_Void_Type
, "_void_type");
791 -- The type field of packages is set to void
793 Set_Etype
(Standard_Standard
, Standard_Void_Type
);
794 Set_Etype
(Standard_ASCII
, Standard_Void_Type
);
796 -- Standard_A_String is actually used in generated code, so it has a
797 -- type name that is reasonable, but does not overlap any Ada name.
799 Standard_A_String
:= New_Standard_Entity
;
800 Set_Ekind
(Standard_A_String
, E_Access_Type
);
801 Set_Scope
(Standard_A_String
, Standard_Standard
);
802 Set_Etype
(Standard_A_String
, Standard_A_String
);
805 Init_Size
(Standard_A_String
, System_Address_Size
);
807 Init_Size
(Standard_A_String
, System_Address_Size
* 2);
810 Init_Alignment
(Standard_A_String
);
812 Set_Directly_Designated_Type
813 (Standard_A_String
, Standard_String
);
814 Make_Name
(Standard_A_String
, "access_string");
816 Standard_A_Char
:= New_Standard_Entity
;
817 Set_Ekind
(Standard_A_Char
, E_Access_Type
);
818 Set_Scope
(Standard_A_Char
, Standard_Standard
);
819 Set_Etype
(Standard_A_Char
, Standard_A_String
);
820 Init_Size
(Standard_A_Char
, System_Address_Size
);
821 Set_Elem_Alignment
(Standard_A_Char
);
823 Set_Directly_Designated_Type
(Standard_A_Char
, Standard_Character
);
824 Make_Name
(Standard_A_Char
, "access_character");
826 -- Note on type names. The type names for the following special types
827 -- are constructed so that they will look reasonable should they ever
828 -- appear in error messages etc, although in practice the use of the
829 -- special insertion character } for types results in special handling
830 -- of these type names in any case. The blanks in these names would
831 -- trouble in Gigi, but that's OK here, since none of these types
832 -- should ever get through to Gigi! Attributes of these types are
833 -- filled out to minimize problems with cascaded errors (for example,
834 -- Any_Integer is given reasonable and consistent type and size values)
836 Any_Type
:= New_Standard_Entity
;
837 Decl
:= New_Node
(N_Full_Type_Declaration
, Stloc
);
838 Set_Defining_Identifier
(Decl
, Any_Type
);
839 Set_Scope
(Any_Type
, Standard_Standard
);
840 Build_Signed_Integer_Type
(Any_Type
, Standard_Integer_Size
);
841 Make_Name
(Any_Type
, "any type");
843 Any_Id
:= New_Standard_Entity
;
844 Set_Ekind
(Any_Id
, E_Variable
);
845 Set_Scope
(Any_Id
, Standard_Standard
);
846 Set_Etype
(Any_Id
, Any_Type
);
847 Init_Size_Align
(Any_Id
);
848 Make_Name
(Any_Id
, "any id");
850 Any_Access
:= New_Standard_Entity
;
851 Set_Ekind
(Any_Access
, E_Access_Type
);
852 Set_Scope
(Any_Access
, Standard_Standard
);
853 Set_Etype
(Any_Access
, Any_Access
);
854 Init_Size
(Any_Access
, System_Address_Size
);
855 Set_Elem_Alignment
(Any_Access
);
856 Make_Name
(Any_Access
, "an access type");
858 Any_Character
:= New_Standard_Entity
;
859 Set_Ekind
(Any_Character
, E_Enumeration_Type
);
860 Set_Scope
(Any_Character
, Standard_Standard
);
861 Set_Etype
(Any_Character
, Any_Character
);
862 Set_Is_Unsigned_Type
(Any_Character
);
863 Set_Is_Character_Type
(Any_Character
);
864 Init_Esize
(Any_Character
, Standard_Character_Size
);
865 Init_RM_Size
(Any_Character
, 8);
866 Set_Elem_Alignment
(Any_Character
);
867 Set_Scalar_Range
(Any_Character
, Scalar_Range
(Standard_Character
));
868 Make_Name
(Any_Character
, "a character type");
870 Any_Array
:= New_Standard_Entity
;
871 Set_Ekind
(Any_Array
, E_String_Type
);
872 Set_Scope
(Any_Array
, Standard_Standard
);
873 Set_Etype
(Any_Array
, Any_Array
);
874 Set_Component_Type
(Any_Array
, Any_Character
);
875 Init_Size_Align
(Any_Array
);
876 Make_Name
(Any_Array
, "an array type");
878 Any_Boolean
:= New_Standard_Entity
;
879 Set_Ekind
(Any_Boolean
, E_Enumeration_Type
);
880 Set_Scope
(Any_Boolean
, Standard_Standard
);
881 Set_Etype
(Any_Boolean
, Standard_Boolean
);
882 Init_Esize
(Any_Boolean
, Standard_Character_Size
);
883 Init_RM_Size
(Any_Boolean
, 1);
884 Set_Elem_Alignment
(Any_Boolean
);
885 Set_Is_Unsigned_Type
(Any_Boolean
);
886 Set_Scalar_Range
(Any_Boolean
, Scalar_Range
(Standard_Boolean
));
887 Make_Name
(Any_Boolean
, "a boolean type");
889 Any_Composite
:= New_Standard_Entity
;
890 Set_Ekind
(Any_Composite
, E_Array_Type
);
891 Set_Scope
(Any_Composite
, Standard_Standard
);
892 Set_Etype
(Any_Composite
, Any_Composite
);
893 Set_Component_Size
(Any_Composite
, Uint_0
);
894 Set_Component_Type
(Any_Composite
, Standard_Integer
);
895 Init_Size_Align
(Any_Composite
);
896 Make_Name
(Any_Composite
, "a composite type");
898 Any_Discrete
:= New_Standard_Entity
;
899 Set_Ekind
(Any_Discrete
, E_Signed_Integer_Type
);
900 Set_Scope
(Any_Discrete
, Standard_Standard
);
901 Set_Etype
(Any_Discrete
, Any_Discrete
);
902 Init_Size
(Any_Discrete
, Standard_Integer_Size
);
903 Set_Elem_Alignment
(Any_Discrete
);
904 Make_Name
(Any_Discrete
, "a discrete type");
906 Any_Fixed
:= New_Standard_Entity
;
907 Set_Ekind
(Any_Fixed
, E_Ordinary_Fixed_Point_Type
);
908 Set_Scope
(Any_Fixed
, Standard_Standard
);
909 Set_Etype
(Any_Fixed
, Any_Fixed
);
910 Init_Size
(Any_Fixed
, Standard_Integer_Size
);
911 Set_Elem_Alignment
(Any_Fixed
);
912 Make_Name
(Any_Fixed
, "a fixed-point type");
914 Any_Integer
:= New_Standard_Entity
;
915 Set_Ekind
(Any_Integer
, E_Signed_Integer_Type
);
916 Set_Scope
(Any_Integer
, Standard_Standard
);
917 Set_Etype
(Any_Integer
, Standard_Long_Long_Integer
);
918 Init_Size
(Any_Integer
, Standard_Long_Long_Integer_Size
);
919 Set_Elem_Alignment
(Any_Integer
);
923 Typ
=> Base_Type
(Standard_Integer
),
925 Hb
=> Intval
(High_Bound
(Scalar_Range
(Standard_Integer
))));
926 Make_Name
(Any_Integer
, "an integer type");
928 Any_Modular
:= New_Standard_Entity
;
929 Set_Ekind
(Any_Modular
, E_Modular_Integer_Type
);
930 Set_Scope
(Any_Modular
, Standard_Standard
);
931 Set_Etype
(Any_Modular
, Standard_Long_Long_Integer
);
932 Init_Size
(Any_Modular
, Standard_Long_Long_Integer_Size
);
933 Set_Elem_Alignment
(Any_Modular
);
934 Set_Is_Unsigned_Type
(Any_Modular
);
935 Make_Name
(Any_Modular
, "a modular type");
937 Any_Numeric
:= New_Standard_Entity
;
938 Set_Ekind
(Any_Numeric
, E_Signed_Integer_Type
);
939 Set_Scope
(Any_Numeric
, Standard_Standard
);
940 Set_Etype
(Any_Numeric
, Standard_Long_Long_Integer
);
941 Init_Size
(Any_Numeric
, Standard_Long_Long_Integer_Size
);
942 Set_Elem_Alignment
(Any_Numeric
);
943 Make_Name
(Any_Numeric
, "a numeric type");
945 Any_Real
:= New_Standard_Entity
;
946 Set_Ekind
(Any_Real
, E_Floating_Point_Type
);
947 Set_Scope
(Any_Real
, Standard_Standard
);
948 Set_Etype
(Any_Real
, Standard_Long_Long_Float
);
949 Init_Size
(Any_Real
, Standard_Long_Long_Float_Size
);
950 Set_Elem_Alignment
(Any_Real
);
951 Make_Name
(Any_Real
, "a real type");
953 Any_Scalar
:= New_Standard_Entity
;
954 Set_Ekind
(Any_Scalar
, E_Signed_Integer_Type
);
955 Set_Scope
(Any_Scalar
, Standard_Standard
);
956 Set_Etype
(Any_Scalar
, Any_Scalar
);
957 Init_Size
(Any_Scalar
, Standard_Integer_Size
);
958 Set_Elem_Alignment
(Any_Scalar
);
959 Make_Name
(Any_Scalar
, "a scalar type");
961 Any_String
:= New_Standard_Entity
;
962 Set_Ekind
(Any_String
, E_String_Type
);
963 Set_Scope
(Any_String
, Standard_Standard
);
964 Set_Etype
(Any_String
, Any_String
);
965 Set_Component_Type
(Any_String
, Any_Character
);
966 Init_Size_Align
(Any_String
);
967 Make_Name
(Any_String
, "a string type");
975 Low_Bound
=> Make_Integer
(Uint_0
),
976 High_Bound
=> Make_Integer
(Uint_2
** Standard_Integer_Size
));
977 Set_Etype
(Index
, Standard_Integer
);
978 Set_First_Index
(Any_String
, Index
);
981 Standard_Integer_8
:= New_Standard_Entity
;
982 Decl
:= New_Node
(N_Full_Type_Declaration
, Stloc
);
983 Set_Defining_Identifier
(Decl
, Standard_Integer_8
);
984 Make_Name
(Standard_Integer_8
, "integer_8");
985 Set_Scope
(Standard_Integer_8
, Standard_Standard
);
986 Build_Signed_Integer_Type
(Standard_Integer_8
, 8);
988 Standard_Integer_16
:= New_Standard_Entity
;
989 Decl
:= New_Node
(N_Full_Type_Declaration
, Stloc
);
990 Set_Defining_Identifier
(Decl
, Standard_Integer_16
);
991 Make_Name
(Standard_Integer_16
, "integer_16");
992 Set_Scope
(Standard_Integer_16
, Standard_Standard
);
993 Build_Signed_Integer_Type
(Standard_Integer_16
, 16);
995 Standard_Integer_32
:= New_Standard_Entity
;
996 Decl
:= New_Node
(N_Full_Type_Declaration
, Stloc
);
997 Set_Defining_Identifier
(Decl
, Standard_Integer_32
);
998 Make_Name
(Standard_Integer_32
, "integer_32");
999 Set_Scope
(Standard_Integer_32
, Standard_Standard
);
1000 Build_Signed_Integer_Type
(Standard_Integer_32
, 32);
1002 Standard_Integer_64
:= New_Standard_Entity
;
1003 Decl
:= New_Node
(N_Full_Type_Declaration
, Stloc
);
1004 Set_Defining_Identifier
(Decl
, Standard_Integer_64
);
1005 Make_Name
(Standard_Integer_64
, "integer_64");
1006 Set_Scope
(Standard_Integer_64
, Standard_Standard
);
1007 Build_Signed_Integer_Type
(Standard_Integer_64
, 64);
1009 Standard_Unsigned
:= New_Standard_Entity
;
1010 Decl
:= New_Node
(N_Full_Type_Declaration
, Stloc
);
1011 Set_Defining_Identifier
(Decl
, Standard_Unsigned
);
1012 Make_Name
(Standard_Unsigned
, "unsigned");
1014 Set_Ekind
(Standard_Unsigned
, E_Modular_Integer_Type
);
1015 Set_Scope
(Standard_Unsigned
, Standard_Standard
);
1016 Set_Etype
(Standard_Unsigned
, Standard_Unsigned
);
1017 Init_Size
(Standard_Unsigned
, Standard_Integer_Size
);
1018 Set_Elem_Alignment
(Standard_Unsigned
);
1019 Set_Modulus
(Standard_Unsigned
,
1020 Uint_2
** Standard_Integer_Size
);
1021 Set_Is_Unsigned_Type
(Standard_Unsigned
);
1022 Set_Size_Known_At_Compile_Time
1023 (Standard_Unsigned
);
1025 R_Node
:= New_Node
(N_Range
, Stloc
);
1026 Set_Low_Bound
(R_Node
, Make_Integer
(Uint_0
));
1027 Set_High_Bound
(R_Node
, Make_Integer
(Modulus
(Standard_Unsigned
) - 1));
1028 Set_Etype
(Low_Bound
(R_Node
), Standard_Unsigned
);
1029 Set_Etype
(High_Bound
(R_Node
), Standard_Unsigned
);
1030 Set_Scalar_Range
(Standard_Unsigned
, R_Node
);
1032 -- Note: universal integer and universal real are constructed as fully
1033 -- formed signed numeric types, with parameters corresponding to the
1034 -- longest runtime types (Long_Long_Integer and Long_Long_Float). This
1035 -- allows Gigi to properly process references to universal types that
1036 -- are not folded at compile time.
1038 Universal_Integer
:= New_Standard_Entity
;
1039 Decl
:= New_Node
(N_Full_Type_Declaration
, Stloc
);
1040 Set_Defining_Identifier
(Decl
, Universal_Integer
);
1041 Make_Name
(Universal_Integer
, "universal_integer");
1042 Set_Scope
(Universal_Integer
, Standard_Standard
);
1043 Build_Signed_Integer_Type
1044 (Universal_Integer
, Standard_Long_Long_Integer_Size
);
1046 Universal_Real
:= New_Standard_Entity
;
1047 Decl
:= New_Node
(N_Full_Type_Declaration
, Stloc
);
1048 Set_Defining_Identifier
(Decl
, Universal_Real
);
1049 Make_Name
(Universal_Real
, "universal_real");
1050 Set_Scope
(Universal_Real
, Standard_Standard
);
1053 Standard_Long_Long_Float_Size
,
1054 Standard_Long_Long_Float_Digits
);
1056 -- Note: universal fixed, unlike universal integer and universal real,
1057 -- is never used at runtime, so it does not need to have bounds set.
1059 Universal_Fixed
:= New_Standard_Entity
;
1060 Decl
:= New_Node
(N_Full_Type_Declaration
, Stloc
);
1061 Set_Defining_Identifier
(Decl
, Universal_Fixed
);
1062 Make_Name
(Universal_Fixed
, "universal_fixed");
1063 Set_Ekind
(Universal_Fixed
, E_Ordinary_Fixed_Point_Type
);
1064 Set_Etype
(Universal_Fixed
, Universal_Fixed
);
1065 Set_Scope
(Universal_Fixed
, Standard_Standard
);
1066 Init_Size
(Universal_Fixed
, Standard_Long_Long_Integer_Size
);
1067 Set_Elem_Alignment
(Universal_Fixed
);
1068 Set_Size_Known_At_Compile_Time
1071 -- Create type declaration for Duration, using a 64-bit size. The
1072 -- delta and size values depend on the mode set in system.ads.
1074 Build_Duration
: declare
1080 -- In 32 bit mode, the size is 32 bits, and the delta and
1081 -- small values are set to 20 milliseconds (20.0**(10.0**(-3)).
1083 if Duration_32_Bits_On_Target
then
1084 Dlo
:= Intval
(Type_Low_Bound
(Standard_Integer_32
));
1085 Dhi
:= Intval
(Type_High_Bound
(Standard_Integer_32
));
1086 Delta_Val
:= UR_From_Components
(UI_From_Int
(20), Uint_3
, 10);
1088 -- In standard 64-bit mode, the size is 64-bits and the delta and
1089 -- small values are set to nanoseconds (1.0**(10.0**(-9))
1092 Dlo
:= Intval
(Type_Low_Bound
(Standard_Integer_64
));
1093 Dhi
:= Intval
(Type_High_Bound
(Standard_Integer_64
));
1094 Delta_Val
:= UR_From_Components
(Uint_1
, Uint_9
, 10);
1097 Tdef_Node
:= Make_Ordinary_Fixed_Point_Definition
(Stloc
,
1098 Delta_Expression
=> Make_Real_Literal
(Stloc
, Delta_Val
),
1099 Real_Range_Specification
=>
1100 Make_Real_Range_Specification
(Stloc
,
1101 Low_Bound
=> Make_Real_Literal
(Stloc
,
1102 Realval
=> Dlo
* Delta_Val
),
1103 High_Bound
=> Make_Real_Literal
(Stloc
,
1104 Realval
=> Dhi
* Delta_Val
)));
1106 Set_Type_Definition
(Parent
(Standard_Duration
), Tdef_Node
);
1108 Set_Ekind
(Standard_Duration
, E_Ordinary_Fixed_Point_Type
);
1109 Set_Etype
(Standard_Duration
, Standard_Duration
);
1111 if Duration_32_Bits_On_Target
then
1112 Init_Size
(Standard_Duration
, 32);
1114 Init_Size
(Standard_Duration
, 64);
1117 Set_Elem_Alignment
(Standard_Duration
);
1118 Set_Delta_Value
(Standard_Duration
, Delta_Val
);
1119 Set_Small_Value
(Standard_Duration
, Delta_Val
);
1120 Set_Scalar_Range
(Standard_Duration
,
1121 Real_Range_Specification
1122 (Type_Definition
(Parent
(Standard_Duration
))));
1124 -- Normally it does not matter that nodes in package Standard are
1125 -- not marked as analyzed. The Scalar_Range of the fixed-point
1126 -- type Standard_Duration is an exception, because of the special
1127 -- test made in Freeze.Freeze_Fixed_Point_Type.
1129 Set_Analyzed
(Scalar_Range
(Standard_Duration
));
1131 Set_Etype
(Type_High_Bound
(Standard_Duration
), Standard_Duration
);
1132 Set_Etype
(Type_Low_Bound
(Standard_Duration
), Standard_Duration
);
1134 Set_Is_Static_Expression
(Type_High_Bound
(Standard_Duration
));
1135 Set_Is_Static_Expression
(Type_Low_Bound
(Standard_Duration
));
1137 Set_Corresponding_Integer_Value
1138 (Type_High_Bound
(Standard_Duration
), Dhi
);
1140 Set_Corresponding_Integer_Value
1141 (Type_Low_Bound
(Standard_Duration
), Dlo
);
1143 Set_Size_Known_At_Compile_Time
(Standard_Duration
);
1146 -- Build standard exception type. Note that the type name here is
1147 -- actually used in the generated code, so it must be set correctly
1149 -- ??? Also note that the Import_Code component is now declared
1150 -- as a System.Standard_Library.Exception_Code to enforce run-time
1151 -- library implementation consistency. It's too early here to resort
1152 -- to rtsfind to get the proper node for that type, so we use the
1153 -- closest possible available type node at hand instead. We should
1154 -- probably be fixing this up at some point.
1156 Standard_Exception_Type
:= New_Standard_Entity
;
1157 Set_Ekind
(Standard_Exception_Type
, E_Record_Type
);
1158 Set_Etype
(Standard_Exception_Type
, Standard_Exception_Type
);
1159 Set_Scope
(Standard_Exception_Type
, Standard_Standard
);
1160 Set_Stored_Constraint
1161 (Standard_Exception_Type
, No_Elist
);
1162 Init_Size_Align
(Standard_Exception_Type
);
1163 Set_Size_Known_At_Compile_Time
1164 (Standard_Exception_Type
, True);
1165 Make_Name
(Standard_Exception_Type
, "exception");
1167 Make_Component
(Standard_Exception_Type
, Standard_Boolean
,
1168 "Not_Handled_By_Others");
1169 Make_Component
(Standard_Exception_Type
, Standard_Character
, "Lang");
1170 Make_Component
(Standard_Exception_Type
, Standard_Natural
,
1172 Make_Component
(Standard_Exception_Type
, Standard_A_Char
,
1174 Make_Component
(Standard_Exception_Type
, Standard_A_Char
,
1176 Make_Component
(Standard_Exception_Type
, Standard_Unsigned
,
1178 Make_Component
(Standard_Exception_Type
, Standard_A_Char
,
1180 -- Build tree for record declaration, for use by the back-end.
1183 Comp_List
: List_Id
;
1187 Comp
:= First_Entity
(Standard_Exception_Type
);
1188 Comp_List
:= New_List
;
1190 while Present
(Comp
) loop
1192 Make_Component_Declaration
(Stloc
,
1193 Defining_Identifier
=> Comp
,
1194 Component_Definition
=>
1195 Make_Component_Definition
(Stloc
,
1196 Aliased_Present
=> False,
1197 Subtype_Indication
=> New_Occurrence_Of
(Etype
(Comp
),
1204 Decl
:= Make_Full_Type_Declaration
(Stloc
,
1205 Defining_Identifier
=> Standard_Exception_Type
,
1207 Make_Record_Definition
(Stloc
,
1210 Make_Component_List
(Stloc
,
1211 Component_Items
=> Comp_List
)));
1214 Append
(Decl
, Decl_S
);
1216 Layout_Type
(Standard_Exception_Type
);
1218 -- Create declarations of standard exceptions
1220 Build_Exception
(S_Constraint_Error
);
1221 Build_Exception
(S_Program_Error
);
1222 Build_Exception
(S_Storage_Error
);
1223 Build_Exception
(S_Tasking_Error
);
1225 -- Numeric_Error is a normal exception in Ada 83, but in Ada 95
1226 -- it is a renaming of Constraint_Error. Is this test too early???
1228 if Ada_Version
= Ada_83
then
1229 Build_Exception
(S_Numeric_Error
);
1232 Decl
:= New_Node
(N_Exception_Renaming_Declaration
, Stloc
);
1233 E_Id
:= Standard_Entity
(S_Numeric_Error
);
1235 Set_Ekind
(E_Id
, E_Exception
);
1236 Set_Exception_Code
(E_Id
, Uint_0
);
1237 Set_Etype
(E_Id
, Standard_Exception_Type
);
1238 Set_Is_Public
(E_Id
);
1239 Set_Renamed_Entity
(E_Id
, Standard_Entity
(S_Constraint_Error
));
1241 Set_Defining_Identifier
(Decl
, E_Id
);
1242 Append
(Decl
, Decl_S
);
1244 Ident_Node
:= New_Node
(N_Identifier
, Stloc
);
1245 Set_Chars
(Ident_Node
, Chars
(Standard_Entity
(S_Constraint_Error
)));
1246 Set_Entity
(Ident_Node
, Standard_Entity
(S_Constraint_Error
));
1247 Set_Name
(Decl
, Ident_Node
);
1250 -- Abort_Signal is an entity that does not get made visible
1252 Abort_Signal
:= New_Standard_Entity
;
1253 Set_Chars
(Abort_Signal
, Name_uAbort_Signal
);
1254 Set_Ekind
(Abort_Signal
, E_Exception
);
1255 Set_Exception_Code
(Abort_Signal
, Uint_0
);
1256 Set_Etype
(Abort_Signal
, Standard_Exception_Type
);
1257 Set_Scope
(Abort_Signal
, Standard_Standard
);
1258 Set_Is_Public
(Abort_Signal
, True);
1260 Make_Exception_Declaration
(Stloc
,
1261 Defining_Identifier
=> Abort_Signal
);
1263 -- Create defining identifiers for shift operator entities. Note
1264 -- that these entities are used only for marking shift operators
1265 -- generated internally, and hence need no structure, just a name
1266 -- and a unique identity.
1268 Standard_Op_Rotate_Left
:= New_Standard_Entity
;
1269 Set_Chars
(Standard_Op_Rotate_Left
, Name_Rotate_Left
);
1270 Set_Ekind
(Standard_Op_Rotate_Left
, E_Operator
);
1272 Standard_Op_Rotate_Right
:= New_Standard_Entity
;
1273 Set_Chars
(Standard_Op_Rotate_Right
, Name_Rotate_Right
);
1274 Set_Ekind
(Standard_Op_Rotate_Right
, E_Operator
);
1276 Standard_Op_Shift_Left
:= New_Standard_Entity
;
1277 Set_Chars
(Standard_Op_Shift_Left
, Name_Shift_Left
);
1278 Set_Ekind
(Standard_Op_Shift_Left
, E_Operator
);
1280 Standard_Op_Shift_Right
:= New_Standard_Entity
;
1281 Set_Chars
(Standard_Op_Shift_Right
, Name_Shift_Right
);
1282 Set_Ekind
(Standard_Op_Shift_Right
, E_Operator
);
1284 Standard_Op_Shift_Right_Arithmetic
:= New_Standard_Entity
;
1285 Set_Chars
(Standard_Op_Shift_Right_Arithmetic
,
1286 Name_Shift_Right_Arithmetic
);
1287 Set_Ekind
(Standard_Op_Shift_Right_Arithmetic
,
1290 -- Create standard operator declarations
1294 -- Initialize visibility table with entities in Standard
1296 for E
in Standard_Entity_Type
loop
1297 if Ekind
(Standard_Entity
(E
)) /= E_Operator
then
1299 (Chars
(Standard_Entity
(E
)), Standard_Entity
(E
));
1300 Set_Homonym
(Standard_Entity
(E
), Empty
);
1303 if E
not in S_ASCII_Names
then
1304 Set_Scope
(Standard_Entity
(E
), Standard_Standard
);
1305 Set_Is_Immediately_Visible
(Standard_Entity
(E
));
1309 -- The predefined package Standard itself does not have a scope;
1310 -- it is the only entity in the system not to have one, and this
1311 -- is what identifies the package to Gigi.
1313 Set_Scope
(Standard_Standard
, Empty
);
1315 -- Set global variables indicating last Id values and version
1317 Last_Standard_Node_Id
:= Last_Node_Id
;
1318 Last_Standard_List_Id
:= Last_List_Id
;
1320 -- The Error node has an Etype of Any_Type to help error recovery
1322 Set_Etype
(Error
, Any_Type
);
1324 -- Print representation of standard if switch set
1326 if Opt
.Print_Standard
then
1329 end Create_Standard
;
1331 ------------------------------------
1332 -- Create_Unconstrained_Base_Type --
1333 ------------------------------------
1335 procedure Create_Unconstrained_Base_Type
1339 New_Ent
: constant Entity_Id
:= New_Copy
(E
);
1343 Set_Is_Constrained
(E
, True);
1344 Set_Is_First_Subtype
(E
, True);
1345 Set_Etype
(E
, New_Ent
);
1347 Append_Entity
(New_Ent
, Standard_Standard
);
1348 Set_Is_Constrained
(New_Ent
, False);
1349 Set_Etype
(New_Ent
, New_Ent
);
1350 Set_Is_Known_Valid
(New_Ent
, True);
1352 if K
= E_Signed_Integer_Subtype
then
1353 Set_Etype
(Low_Bound
(Scalar_Range
(E
)), New_Ent
);
1354 Set_Etype
(High_Bound
(Scalar_Range
(E
)), New_Ent
);
1357 end Create_Unconstrained_Base_Type
;
1359 --------------------
1360 -- Identifier_For --
1361 --------------------
1363 function Identifier_For
(S
: Standard_Entity_Type
) return Node_Id
is
1364 Ident_Node
: Node_Id
;
1367 Ident_Node
:= New_Node
(N_Identifier
, Stloc
);
1368 Set_Chars
(Ident_Node
, Chars
(Standard_Entity
(S
)));
1372 --------------------
1373 -- Make_Component --
1374 --------------------
1376 procedure Make_Component
1381 Id
: constant Entity_Id
:= New_Standard_Entity
;
1384 Set_Ekind
(Id
, E_Component
);
1385 Set_Etype
(Id
, Typ
);
1386 Set_Scope
(Id
, Rec
);
1387 Init_Component_Location
(Id
);
1389 Set_Original_Record_Component
(Id
, Id
);
1390 Make_Name
(Id
, Nam
);
1391 Append_Entity
(Id
, Rec
);
1398 function Make_Formal
1400 Formal_Name
: String) return Entity_Id
1405 Formal
:= New_Standard_Entity
;
1407 Set_Ekind
(Formal
, E_In_Parameter
);
1408 Set_Mechanism
(Formal
, Default_Mechanism
);
1409 Set_Scope
(Formal
, Standard_Standard
);
1410 Set_Etype
(Formal
, Typ
);
1411 Make_Name
(Formal
, Formal_Name
);
1420 function Make_Integer
(V
: Uint
) return Node_Id
is
1421 N
: constant Node_Id
:= Make_Integer_Literal
(Stloc
, V
);
1423 Set_Is_Static_Expression
(N
);
1431 procedure Make_Name
(Id
: Entity_Id
; Nam
: String) is
1433 for J
in 1 .. Nam
'Length loop
1434 Name_Buffer
(J
) := Fold_Lower
(Nam
(Nam
'First + (J
- 1)));
1437 Name_Len
:= Nam
'Length;
1438 Set_Chars
(Id
, Name_Find
);
1445 function New_Operator
(Op
: Name_Id
; Typ
: Entity_Id
) return Entity_Id
is
1446 Ident_Node
: Entity_Id
;
1449 Ident_Node
:= Make_Defining_Identifier
(Stloc
, Op
);
1451 Set_Is_Pure
(Ident_Node
, True);
1452 Set_Ekind
(Ident_Node
, E_Operator
);
1453 Set_Etype
(Ident_Node
, Typ
);
1454 Set_Scope
(Ident_Node
, Standard_Standard
);
1455 Set_Homonym
(Ident_Node
, Get_Name_Entity_Id
(Op
));
1456 Set_Convention
(Ident_Node
, Convention_Intrinsic
);
1458 Set_Is_Immediately_Visible
(Ident_Node
, True);
1459 Set_Is_Intrinsic_Subprogram
(Ident_Node
, True);
1461 Set_Name_Entity_Id
(Op
, Ident_Node
);
1462 Append_Entity
(Ident_Node
, Standard_Standard
);
1466 -------------------------
1467 -- New_Standard_Entity --
1468 -------------------------
1470 function New_Standard_Entity
1471 (New_Node_Kind
: Node_Kind
:= N_Defining_Identifier
) return Entity_Id
1473 E
: constant Entity_Id
:= New_Entity
(New_Node_Kind
, Stloc
);
1476 -- All standard entities are Pure and Public
1481 -- All standard entity names are analyzed manually, and are thus
1482 -- frozen as soon as they are created.
1486 -- Set debug information required for all standard types
1488 Set_Needs_Debug_Info
(E
);
1490 -- All standard entities are built with fully qualified names, so
1491 -- set the flag to prevent an abortive attempt at requalification!
1493 Set_Has_Qualified_Name
(E
);
1495 -- Return newly created entity to be completed by caller
1498 end New_Standard_Entity
;
1500 --------------------
1501 -- Print_Standard --
1502 --------------------
1504 procedure Print_Standard
is
1506 procedure P
(Item
: String) renames Output
.Write_Line
;
1507 -- Short-hand, since we do a lot of line writes here!
1509 procedure P_Int_Range
(Size
: Pos
);
1510 -- Prints the range of an integer based on its Size
1512 procedure P_Float_Range
(Id
: Entity_Id
);
1513 -- Prints the bounds range for the given float type entity
1519 procedure P_Float_Range
(Id
: Entity_Id
) is
1520 Digs
: constant Nat
:= UI_To_Int
(Digits_Value
(Id
));
1523 Write_Str
(" range ");
1525 if Vax_Float
(Id
) then
1526 if Digs
= VAXFF_Digits
then
1527 Write_Str
(VAXFF_First
'Universal_Literal_String);
1529 Write_Str
(VAXFF_Last
'Universal_Literal_String);
1531 elsif Digs
= VAXDF_Digits
then
1532 Write_Str
(VAXDF_First
'Universal_Literal_String);
1534 Write_Str
(VAXDF_Last
'Universal_Literal_String);
1537 pragma Assert
(Digs
= VAXGF_Digits
);
1539 Write_Str
(VAXGF_First
'Universal_Literal_String);
1541 Write_Str
(VAXGF_Last
'Universal_Literal_String);
1544 elsif Is_AAMP_Float
(Id
) then
1545 if Digs
= AAMPS_Digits
then
1546 Write_Str
(AAMPS_First
'Universal_Literal_String);
1548 Write_Str
(AAMPS_Last
'Universal_Literal_String);
1551 pragma Assert
(Digs
= AAMPL_Digits
);
1552 Write_Str
(AAMPL_First
'Universal_Literal_String);
1554 Write_Str
(AAMPL_Last
'Universal_Literal_String);
1557 elsif Digs
= IEEES_Digits
then
1558 Write_Str
(IEEES_First
'Universal_Literal_String);
1560 Write_Str
(IEEES_Last
'Universal_Literal_String);
1562 elsif Digs
= IEEEL_Digits
then
1563 Write_Str
(IEEEL_First
'Universal_Literal_String);
1565 Write_Str
(IEEEL_Last
'Universal_Literal_String);
1568 pragma Assert
(Digs
= IEEEX_Digits
);
1570 Write_Str
(IEEEX_First
'Universal_Literal_String);
1572 Write_Str
(IEEEX_Last
'Universal_Literal_String);
1583 procedure P_Int_Range
(Size
: Pos
) is
1585 Write_Str
(" is range -(2 **");
1586 Write_Int
(Size
- 1);
1588 Write_Str
(" .. +(2 **");
1589 Write_Int
(Size
- 1);
1590 Write_Str
(" - 1);");
1594 -- Start of processing for Print_Standard
1597 P
("-- Representation of package Standard");
1599 P
("-- This is not accurate Ada, since new base types cannot be ");
1600 P
("-- created, but the listing shows the target dependent");
1601 P
("-- characteristics of the Standard types for this compiler");
1604 P
("package Standard is");
1605 P
("pragma Pure(Standard);");
1608 P
(" type Boolean is (False, True);");
1609 P
(" for Boolean'Size use 1;");
1610 P
(" for Boolean use (False => 0, True => 1);");
1615 Write_Str
(" type Integer");
1616 P_Int_Range
(Standard_Integer_Size
);
1617 Write_Str
(" for Integer'Size use ");
1618 Write_Int
(Standard_Integer_Size
);
1622 P
(" subtype Natural is Integer range 0 .. Integer'Last;");
1623 P
(" subtype Positive is Integer range 1 .. Integer'Last;");
1626 Write_Str
(" type Short_Short_Integer");
1627 P_Int_Range
(Standard_Short_Short_Integer_Size
);
1628 Write_Str
(" for Short_Short_Integer'Size use ");
1629 Write_Int
(Standard_Short_Short_Integer_Size
);
1633 Write_Str
(" type Short_Integer");
1634 P_Int_Range
(Standard_Short_Integer_Size
);
1635 Write_Str
(" for Short_Integer'Size use ");
1636 Write_Int
(Standard_Short_Integer_Size
);
1640 Write_Str
(" type Long_Integer");
1641 P_Int_Range
(Standard_Long_Integer_Size
);
1642 Write_Str
(" for Long_Integer'Size use ");
1643 Write_Int
(Standard_Long_Integer_Size
);
1647 Write_Str
(" type Long_Long_Integer");
1648 P_Int_Range
(Standard_Long_Long_Integer_Size
);
1649 Write_Str
(" for Long_Long_Integer'Size use ");
1650 Write_Int
(Standard_Long_Long_Integer_Size
);
1654 -- Floating point types
1656 Write_Str
(" type Short_Float is digits ");
1657 Write_Int
(Standard_Short_Float_Digits
);
1659 P_Float_Range
(Standard_Short_Float
);
1660 Write_Str
(" for Short_Float'Size use ");
1661 Write_Int
(Standard_Short_Float_Size
);
1665 Write_Str
(" type Float is digits ");
1666 Write_Int
(Standard_Float_Digits
);
1668 P_Float_Range
(Standard_Float
);
1669 Write_Str
(" for Float'Size use ");
1670 Write_Int
(Standard_Float_Size
);
1674 Write_Str
(" type Long_Float is digits ");
1675 Write_Int
(Standard_Long_Float_Digits
);
1677 P_Float_Range
(Standard_Long_Float
);
1678 Write_Str
(" for Long_Float'Size use ");
1679 Write_Int
(Standard_Long_Float_Size
);
1683 Write_Str
(" type Long_Long_Float is digits ");
1684 Write_Int
(Standard_Long_Long_Float_Digits
);
1686 P_Float_Range
(Standard_Long_Long_Float
);
1687 Write_Str
(" for Long_Long_Float'Size use ");
1688 Write_Int
(Standard_Long_Long_Float_Size
);
1692 P
(" type Character is (...)");
1693 Write_Str
(" for Character'Size use ");
1694 Write_Int
(Standard_Character_Size
);
1696 P
(" -- See RM A.1(35) for details of this type");
1699 P
(" type Wide_Character is (...)");
1700 Write_Str
(" for Wide_Character'Size use ");
1701 Write_Int
(Standard_Wide_Character_Size
);
1703 P
(" -- See RM A.1(36) for details of this type");
1706 P
(" type String is array (Positive range <>) of Character;");
1707 P
(" pragma Pack (String);");
1710 P
(" type Wide_String is array (Positive range <>)" &
1711 " of Wide_Character;");
1712 P
(" pragma Pack (Wide_String);");
1715 -- Here it's OK to use the Duration type of the host compiler since
1716 -- the implementation of Duration in GNAT is target independent.
1718 if Duration_32_Bits_On_Target
then
1719 P
(" type Duration is delta 0.020");
1720 P
(" range -((2 ** 31 - 1) * 0.020) ..");
1721 P
(" +((2 ** 31 - 1) * 0.020);");
1722 P
(" for Duration'Small use 0.020;");
1724 P
(" type Duration is delta 0.000000001");
1725 P
(" range -((2 ** 63 - 1) * 0.000000001) ..");
1726 P
(" +((2 ** 63 - 1) * 0.000000001);");
1727 P
(" for Duration'Small use 0.000000001;");
1732 P
(" Constraint_Error : exception;");
1733 P
(" Program_Error : exception;");
1734 P
(" Storage_Error : exception;");
1735 P
(" Tasking_Error : exception;");
1736 P
(" Numeric_Error : exception renames Constraint_Error;");
1739 P
("end Standard;");
1742 ----------------------
1743 -- Set_Float_Bounds --
1744 ----------------------
1746 procedure Set_Float_Bounds
(Id
: Entity_Id
) is
1748 -- Low bound of literal value
1751 -- High bound of literal value
1754 -- Range specification
1756 Digs
: constant Nat
:= UI_To_Int
(Digits_Value
(Id
));
1757 -- Digits value, used to select bounds
1760 -- Note: for the call from Cstand to initially create the types in
1761 -- Standard, Vax_Float will always be False. Circuitry in Sem_Vfpt
1762 -- will adjust these types appropriately in the Vax_Float case if
1763 -- a pragma Float_Representation (VAX_Float) is used.
1765 if Vax_Float
(Id
) then
1766 if Digs
= VAXFF_Digits
then
1768 (VAXFF_First
'Universal_Literal_String);
1770 (VAXFF_Last
'Universal_Literal_String);
1772 elsif Digs
= VAXDF_Digits
then
1774 (VAXDF_First
'Universal_Literal_String);
1776 (VAXDF_Last
'Universal_Literal_String);
1779 pragma Assert
(Digs
= VAXGF_Digits
);
1782 (VAXGF_First
'Universal_Literal_String);
1784 (VAXGF_Last
'Universal_Literal_String);
1787 elsif Is_AAMP_Float
(Id
) then
1788 if Digs
= AAMPS_Digits
then
1790 (AAMPS_First
'Universal_Literal_String);
1792 (AAMPS_Last
'Universal_Literal_String);
1795 pragma Assert
(Digs
= AAMPL_Digits
);
1797 (AAMPL_First
'Universal_Literal_String);
1799 (AAMPL_Last
'Universal_Literal_String);
1802 elsif Digs
= IEEES_Digits
then
1804 (IEEES_First
'Universal_Literal_String);
1806 (IEEES_Last
'Universal_Literal_String);
1808 elsif Digs
= IEEEL_Digits
then
1810 (IEEEL_First
'Universal_Literal_String);
1812 (IEEEL_Last
'Universal_Literal_String);
1815 pragma Assert
(Digs
= IEEEX_Digits
);
1818 (IEEEX_First
'Universal_Literal_String);
1820 (IEEEX_Last
'Universal_Literal_String);
1824 Set_Is_Static_Expression
(L
);
1827 Set_Is_Static_Expression
(H
);
1829 R
:= New_Node
(N_Range
, Stloc
);
1830 Set_Low_Bound
(R
, L
);
1831 Set_High_Bound
(R
, H
);
1832 Set_Includes_Infinities
(R
, True);
1833 Set_Scalar_Range
(Id
, R
);
1836 end Set_Float_Bounds
;
1838 ------------------------
1839 -- Set_Integer_Bounds --
1840 ------------------------
1842 procedure Set_Integer_Bounds
1848 L
: Node_Id
; -- Low bound of literal value
1849 H
: Node_Id
; -- High bound of literal value
1850 R
: Node_Id
; -- Range specification
1853 L
:= Make_Integer
(Lb
);
1854 H
:= Make_Integer
(Hb
);
1859 R
:= New_Node
(N_Range
, Stloc
);
1860 Set_Low_Bound
(R
, L
);
1861 Set_High_Bound
(R
, H
);
1862 Set_Scalar_Range
(Id
, R
);
1865 Set_Is_Unsigned_Type
(Id
, Lb
>= 0);
1866 end Set_Integer_Bounds
;