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_Prim_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_Prim_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 -- Following list has two entries for concatenation, to include
193 -- explicitly the operation on wide strings.
195 Binary_Ops
: constant array (S_Binary_Ops
) of Name_Id
:=
196 (Name_Op_Add
, Name_Op_And
, Name_Op_Concat
, Name_Op_Concat
,
197 Name_Op_Divide
, Name_Op_Eq
, Name_Op_Expon
, Name_Op_Ge
,
198 Name_Op_Gt
, Name_Op_Le
, Name_Op_Lt
, Name_Op_Mod
,
199 Name_Op_Multiply
, Name_Op_Ne
, Name_Op_Or
, Name_Op_Rem
,
200 Name_Op_Subtract
, Name_Op_Xor
);
202 Bin_Op_Types
: constant array (S_Binary_Ops
) of Entity_Id
:=
203 (Universal_Integer
, Standard_Boolean
,
204 Standard_String
, Standard_Wide_String
,
205 Universal_Integer
, Standard_Boolean
,
206 Universal_Integer
, Standard_Boolean
,
207 Standard_Boolean
, Standard_Boolean
,
208 Standard_Boolean
, Universal_Integer
,
209 Universal_Integer
, Standard_Boolean
,
210 Standard_Boolean
, Universal_Integer
,
211 Universal_Integer
, Standard_Boolean
);
213 Unary_Ops
: constant array (S_Unary_Ops
) of Name_Id
:=
214 (Name_Op_Abs
, Name_Op_Subtract
, Name_Op_Not
, Name_Op_Add
);
216 Unary_Op_Types
: constant array (S_Unary_Ops
) of Entity_Id
:=
217 (Universal_Integer
, Universal_Integer
,
218 Standard_Boolean
, Universal_Integer
);
220 -- Corresponding to Abs, Minus, Not, and Plus.
223 for J
in S_Binary_Ops
loop
224 Op_Node
:= New_Operator
(Binary_Ops
(J
), Bin_Op_Types
(J
));
226 Append_Entity
(Make_Formal
(Any_Type
, "LEFT"), Op_Node
);
227 Append_Entity
(Make_Formal
(Any_Type
, "RIGHT"), Op_Node
);
230 for J
in S_Unary_Ops
loop
231 Op_Node
:= New_Operator
(Unary_Ops
(J
), Unary_Op_Types
(J
));
233 Append_Entity
(Make_Formal
(Any_Type
, "RIGHT"), Op_Node
);
236 -- For concatenation, we create a separate operator for each
237 -- array type. This simplifies the resolution of the component-
238 -- component concatenation operation. In Standard, we set the types
239 -- of the formals for string and wide string concatenation.
241 Set_Etype
(First_Entity
(Standard_Op_Concat
), Standard_String
);
242 Set_Etype
(Last_Entity
(Standard_Op_Concat
), Standard_String
);
244 Set_Etype
(First_Entity
(Standard_Op_Concatw
), Standard_Wide_String
);
245 Set_Etype
(Last_Entity
(Standard_Op_Concatw
), Standard_Wide_String
);
247 end Create_Operators
;
249 ---------------------
250 -- Create_Standard --
251 ---------------------
253 -- The tree for the package Standard is prefixed to all compilations.
254 -- Several entities required by semantic analysis are denoted by global
255 -- variables that are initialized to point to the corresponding
256 -- occurrences in STANDARD. The visible entities of STANDARD are
257 -- created here. The private entities defined in STANDARD are created
258 -- by Initialize_Standard in the semantics module.
260 procedure Create_Standard
is
261 Decl_S
: constant List_Id
:= New_List
;
262 -- List of declarations in Standard
264 Decl_A
: constant List_Id
:= New_List
;
265 -- List of declarations in ASCII
270 Ident_Node
: Node_Id
;
276 procedure Build_Exception
(S
: Standard_Entity_Type
);
277 -- Procedure to declare given entity as an exception
279 ---------------------
280 -- Build_Exception --
281 ---------------------
283 procedure Build_Exception
(S
: Standard_Entity_Type
) is
285 Set_Ekind
(Standard_Entity
(S
), E_Exception
);
286 Set_Etype
(Standard_Entity
(S
), Standard_Exception_Type
);
287 Set_Exception_Code
(Standard_Entity
(S
), Uint_0
);
288 Set_Is_Public
(Standard_Entity
(S
), True);
291 Make_Exception_Declaration
(Stloc
,
292 Defining_Identifier
=> Standard_Entity
(S
));
293 Append
(Decl
, Decl_S
);
296 -- Start of processing for Create_Standard
299 -- Initialize scanner for internal scans of literals
301 Scn
.Initialize_Scanner
(No_Unit
, Internal_Source_File
);
303 -- First step is to create defining identifiers for each entity
305 for S
in Standard_Entity_Type
loop
307 S_Name
: constant String := Standard_Entity_Type
'Image (S
);
308 -- Name of entity (note we skip S_ at the start)
310 Ident_Node
: Node_Id
;
311 -- Defining identifier node
314 Ident_Node
:= New_Standard_Entity
;
315 Make_Name
(Ident_Node
, S_Name
(3 .. S_Name
'Length));
316 Standard_Entity
(S
) := Ident_Node
;
320 -- Create package declaration node for package Standard
322 Standard_Package_Node
:= New_Node
(N_Package_Declaration
, Stloc
);
324 Pspec
:= New_Node
(N_Package_Specification
, Stloc
);
325 Set_Specification
(Standard_Package_Node
, Pspec
);
327 Set_Defining_Unit_Name
(Pspec
, Standard_Standard
);
328 Set_Visible_Declarations
(Pspec
, Decl_S
);
330 Set_Ekind
(Standard_Standard
, E_Package
);
331 Set_Is_Pure
(Standard_Standard
);
332 Set_Is_Compilation_Unit
(Standard_Standard
);
334 -- Create type declaration nodes for standard types
336 for S
in S_Types
loop
337 Decl
:= New_Node
(N_Full_Type_Declaration
, Stloc
);
338 Set_Defining_Identifier
(Decl
, Standard_Entity
(S
));
339 Set_Is_Frozen
(Standard_Entity
(S
));
340 Set_Is_Public
(Standard_Entity
(S
));
341 Append
(Decl
, Decl_S
);
344 -- Create type definition node for type Boolean. The Size is set to
345 -- 1 as required by Ada 95 and current ARG interpretations for Ada/83.
347 -- Note: Object_Size of Boolean is 8. This means that we do NOT in
348 -- general know that Boolean variables have valid values, so we do
349 -- not set the Is_Known_Valid flag.
351 Tdef_Node
:= New_Node
(N_Enumeration_Type_Definition
, Stloc
);
352 Set_Literals
(Tdef_Node
, New_List
);
353 Append
(Standard_False
, Literals
(Tdef_Node
));
354 Append
(Standard_True
, Literals
(Tdef_Node
));
355 Set_Type_Definition
(Parent
(Standard_Boolean
), Tdef_Node
);
357 Set_Ekind
(Standard_Boolean
, E_Enumeration_Type
);
358 Set_First_Literal
(Standard_Boolean
, Standard_False
);
359 Set_Etype
(Standard_Boolean
, Standard_Boolean
);
360 Init_Esize
(Standard_Boolean
, Standard_Character_Size
);
361 Init_RM_Size
(Standard_Boolean
, 1);
362 Set_Prim_Alignment
(Standard_Boolean
);
364 Set_Is_Unsigned_Type
(Standard_Boolean
);
365 Set_Size_Known_At_Compile_Time
(Standard_Boolean
);
367 Set_Ekind
(Standard_True
, E_Enumeration_Literal
);
368 Set_Etype
(Standard_True
, Standard_Boolean
);
369 Set_Enumeration_Pos
(Standard_True
, Uint_1
);
370 Set_Enumeration_Rep
(Standard_True
, Uint_1
);
371 Set_Is_Known_Valid
(Standard_True
, True);
373 Set_Ekind
(Standard_False
, E_Enumeration_Literal
);
374 Set_Etype
(Standard_False
, Standard_Boolean
);
375 Set_Enumeration_Pos
(Standard_False
, Uint_0
);
376 Set_Enumeration_Rep
(Standard_False
, Uint_0
);
377 Set_Is_Known_Valid
(Standard_False
, True);
379 -- For the bounds of Boolean, we create a range node corresponding to
381 -- range False .. True
383 -- where the occurrences of the literals must point to the
384 -- corresponding definition.
386 R_Node
:= New_Node
(N_Range
, Stloc
);
387 B_Node
:= New_Node
(N_Identifier
, Stloc
);
388 Set_Chars
(B_Node
, Chars
(Standard_False
));
389 Set_Entity
(B_Node
, Standard_False
);
390 Set_Etype
(B_Node
, Standard_Boolean
);
391 Set_Is_Static_Expression
(B_Node
);
392 Set_Low_Bound
(R_Node
, B_Node
);
394 B_Node
:= New_Node
(N_Identifier
, Stloc
);
395 Set_Chars
(B_Node
, Chars
(Standard_True
));
396 Set_Entity
(B_Node
, Standard_True
);
397 Set_Etype
(B_Node
, Standard_Boolean
);
398 Set_Is_Static_Expression
(B_Node
);
399 Set_High_Bound
(R_Node
, B_Node
);
401 Set_Scalar_Range
(Standard_Boolean
, R_Node
);
402 Set_Etype
(R_Node
, Standard_Boolean
);
403 Set_Parent
(R_Node
, Standard_Boolean
);
405 -- Record entity identifiers for boolean literals in the
406 -- Boolean_Literals array, for easy reference during expansion.
408 Boolean_Literals
:= (False => Standard_False
, True => Standard_True
);
410 -- Create type definition nodes for predefined integer types
412 Build_Signed_Integer_Type
413 (Standard_Short_Short_Integer
, Standard_Short_Short_Integer_Size
);
415 Build_Signed_Integer_Type
416 (Standard_Short_Integer
, Standard_Short_Integer_Size
);
418 Build_Signed_Integer_Type
419 (Standard_Integer
, Standard_Integer_Size
);
427 LIS
:= Standard_Long_Integer_Size
;
430 Build_Signed_Integer_Type
(Standard_Long_Integer
, LIS
);
433 Build_Signed_Integer_Type
434 (Standard_Long_Long_Integer
, Standard_Long_Long_Integer_Size
);
436 Create_Unconstrained_Base_Type
437 (Standard_Short_Short_Integer
, E_Signed_Integer_Subtype
);
439 Create_Unconstrained_Base_Type
440 (Standard_Short_Integer
, E_Signed_Integer_Subtype
);
442 Create_Unconstrained_Base_Type
443 (Standard_Integer
, E_Signed_Integer_Subtype
);
445 Create_Unconstrained_Base_Type
446 (Standard_Long_Integer
, E_Signed_Integer_Subtype
);
448 Create_Unconstrained_Base_Type
449 (Standard_Long_Long_Integer
, E_Signed_Integer_Subtype
);
451 -- Create type definition nodes for predefined float types
454 (Standard_Short_Float
,
455 Standard_Short_Float_Size
,
456 Standard_Short_Float_Digits
);
461 Standard_Float_Digits
);
464 (Standard_Long_Float
,
465 Standard_Long_Float_Size
,
466 Standard_Long_Float_Digits
);
469 (Standard_Long_Long_Float
,
470 Standard_Long_Long_Float_Size
,
471 Standard_Long_Long_Float_Digits
);
473 -- Create type definition node for type Character. Note that we do not
474 -- set the Literals field, since type Character is handled with special
475 -- routine that do not need a literal list.
477 Tdef_Node
:= New_Node
(N_Enumeration_Type_Definition
, Stloc
);
478 Set_Type_Definition
(Parent
(Standard_Character
), Tdef_Node
);
480 Set_Ekind
(Standard_Character
, E_Enumeration_Type
);
481 Set_Etype
(Standard_Character
, Standard_Character
);
482 Init_Esize
(Standard_Character
, Standard_Character_Size
);
483 Init_RM_Size
(Standard_Character
, 8);
484 Set_Prim_Alignment
(Standard_Character
);
486 Set_Is_Unsigned_Type
(Standard_Character
);
487 Set_Is_Character_Type
(Standard_Character
);
488 Set_Is_Known_Valid
(Standard_Character
);
489 Set_Size_Known_At_Compile_Time
(Standard_Character
);
491 -- Create the bounds for type Character.
493 R_Node
:= New_Node
(N_Range
, Stloc
);
495 -- Low bound for type Character (Standard.Nul)
497 B_Node
:= New_Node
(N_Character_Literal
, Stloc
);
498 Set_Is_Static_Expression
(B_Node
);
499 Set_Chars
(B_Node
, No_Name
);
500 Set_Char_Literal_Value
(B_Node
, 16#
00#
);
501 Set_Entity
(B_Node
, Empty
);
502 Set_Etype
(B_Node
, Standard_Character
);
503 Set_Low_Bound
(R_Node
, B_Node
);
505 -- High bound for type Character
507 B_Node
:= New_Node
(N_Character_Literal
, Stloc
);
508 Set_Is_Static_Expression
(B_Node
);
509 Set_Chars
(B_Node
, No_Name
);
510 Set_Char_Literal_Value
(B_Node
, 16#FF#
);
511 Set_Entity
(B_Node
, Empty
);
512 Set_Etype
(B_Node
, Standard_Character
);
513 Set_High_Bound
(R_Node
, B_Node
);
515 Set_Scalar_Range
(Standard_Character
, R_Node
);
516 Set_Etype
(R_Node
, Standard_Character
);
517 Set_Parent
(R_Node
, Standard_Character
);
519 -- Create type definition for type Wide_Character. Note that we do not
520 -- set the Literals field, since type Wide_Character is handled with
521 -- special routines that do not need a literal list.
523 Tdef_Node
:= New_Node
(N_Enumeration_Type_Definition
, Stloc
);
524 Set_Type_Definition
(Parent
(Standard_Wide_Character
), Tdef_Node
);
526 Set_Ekind
(Standard_Wide_Character
, E_Enumeration_Type
);
527 Set_Etype
(Standard_Wide_Character
, Standard_Wide_Character
);
528 Init_Size
(Standard_Wide_Character
, Standard_Wide_Character_Size
);
530 Set_Prim_Alignment
(Standard_Wide_Character
);
531 Set_Is_Unsigned_Type
(Standard_Wide_Character
);
532 Set_Is_Character_Type
(Standard_Wide_Character
);
533 Set_Is_Known_Valid
(Standard_Wide_Character
);
534 Set_Size_Known_At_Compile_Time
(Standard_Wide_Character
);
536 -- Create the bounds for type Wide_Character.
538 R_Node
:= New_Node
(N_Range
, Stloc
);
540 -- Low bound for type Wide_Character
542 B_Node
:= New_Node
(N_Character_Literal
, Stloc
);
543 Set_Is_Static_Expression
(B_Node
);
544 Set_Chars
(B_Node
, No_Name
); -- ???
545 Set_Char_Literal_Value
(B_Node
, 16#
0000#
);
546 Set_Entity
(B_Node
, Empty
);
547 Set_Etype
(B_Node
, Standard_Wide_Character
);
548 Set_Low_Bound
(R_Node
, B_Node
);
550 -- High bound for type Wide_Character
552 B_Node
:= New_Node
(N_Character_Literal
, Stloc
);
553 Set_Is_Static_Expression
(B_Node
);
554 Set_Chars
(B_Node
, No_Name
); -- ???
555 Set_Char_Literal_Value
(B_Node
, 16#FFFF#
);
556 Set_Entity
(B_Node
, Empty
);
557 Set_Etype
(B_Node
, Standard_Wide_Character
);
558 Set_High_Bound
(R_Node
, B_Node
);
560 Set_Scalar_Range
(Standard_Wide_Character
, R_Node
);
561 Set_Etype
(R_Node
, Standard_Wide_Character
);
562 Set_Parent
(R_Node
, Standard_Wide_Character
);
564 -- Create type definition node for type String
566 Tdef_Node
:= New_Node
(N_Unconstrained_Array_Definition
, Stloc
);
569 CompDef_Node
: Node_Id
;
571 CompDef_Node
:= New_Node
(N_Component_Definition
, Stloc
);
572 Set_Aliased_Present
(CompDef_Node
, False);
573 Set_Access_Definition
(CompDef_Node
, Empty
);
574 Set_Subtype_Indication
(CompDef_Node
, Identifier_For
(S_Character
));
575 Set_Component_Definition
(Tdef_Node
, CompDef_Node
);
578 Set_Subtype_Marks
(Tdef_Node
, New_List
);
579 Append
(Identifier_For
(S_Positive
), Subtype_Marks
(Tdef_Node
));
580 Set_Type_Definition
(Parent
(Standard_String
), Tdef_Node
);
582 Set_Ekind
(Standard_String
, E_String_Type
);
583 Set_Etype
(Standard_String
, Standard_String
);
584 Set_Component_Type
(Standard_String
, Standard_Character
);
585 Set_Component_Size
(Standard_String
, Uint_8
);
586 Init_Size_Align
(Standard_String
);
588 -- Set index type of String
591 (Subtype_Marks
(Type_Definition
(Parent
(Standard_String
))));
592 Set_First_Index
(Standard_String
, E_Id
);
593 Set_Entity
(E_Id
, Standard_Positive
);
594 Set_Etype
(E_Id
, Standard_Positive
);
596 -- Create type definition node for type Wide_String
598 Tdef_Node
:= New_Node
(N_Unconstrained_Array_Definition
, Stloc
);
600 CompDef_Node
: Node_Id
;
602 CompDef_Node
:= New_Node
(N_Component_Definition
, Stloc
);
603 Set_Aliased_Present
(CompDef_Node
, False);
604 Set_Access_Definition
(CompDef_Node
, Empty
);
605 Set_Subtype_Indication
(CompDef_Node
,
606 Identifier_For
(S_Wide_Character
));
607 Set_Component_Definition
(Tdef_Node
, CompDef_Node
);
609 Set_Subtype_Marks
(Tdef_Node
, New_List
);
610 Append
(Identifier_For
(S_Positive
), Subtype_Marks
(Tdef_Node
));
611 Set_Type_Definition
(Parent
(Standard_Wide_String
), Tdef_Node
);
613 Set_Ekind
(Standard_Wide_String
, E_String_Type
);
614 Set_Etype
(Standard_Wide_String
, Standard_Wide_String
);
615 Set_Component_Type
(Standard_Wide_String
, Standard_Wide_Character
);
616 Set_Component_Size
(Standard_Wide_String
, Uint_16
);
617 Init_Size_Align
(Standard_Wide_String
);
619 -- Set index type of Wide_String
622 (Subtype_Marks
(Type_Definition
(Parent
(Standard_Wide_String
))));
623 Set_First_Index
(Standard_Wide_String
, E_Id
);
624 Set_Entity
(E_Id
, Standard_Positive
);
625 Set_Etype
(E_Id
, Standard_Positive
);
627 -- Create subtype declaration for Natural
629 Decl
:= New_Node
(N_Subtype_Declaration
, Stloc
);
630 Set_Defining_Identifier
(Decl
, Standard_Natural
);
631 Set_Subtype_Indication
(Decl
,
632 New_Occurrence_Of
(Standard_Integer
, Stloc
));
633 Append
(Decl
, Decl_S
);
635 Set_Ekind
(Standard_Natural
, E_Signed_Integer_Subtype
);
636 Set_Etype
(Standard_Natural
, Base_Type
(Standard_Integer
));
637 Init_Esize
(Standard_Natural
, Standard_Integer_Size
);
638 Init_RM_Size
(Standard_Natural
, Standard_Integer_Size
- 1);
639 Set_Prim_Alignment
(Standard_Natural
);
640 Set_Size_Known_At_Compile_Time
642 Set_Integer_Bounds
(Standard_Natural
,
643 Typ
=> Base_Type
(Standard_Integer
),
645 Hb
=> Intval
(High_Bound
(Scalar_Range
(Standard_Integer
))));
646 Set_Is_Constrained
(Standard_Natural
);
647 Set_Is_Frozen
(Standard_Natural
);
648 Set_Is_Public
(Standard_Natural
);
650 -- Create subtype declaration for Positive
652 Decl
:= New_Node
(N_Subtype_Declaration
, Stloc
);
653 Set_Defining_Identifier
(Decl
, Standard_Positive
);
654 Set_Subtype_Indication
(Decl
,
655 New_Occurrence_Of
(Standard_Integer
, Stloc
));
656 Append
(Decl
, Decl_S
);
658 Set_Ekind
(Standard_Positive
, E_Signed_Integer_Subtype
);
659 Set_Etype
(Standard_Positive
, Base_Type
(Standard_Integer
));
660 Init_Esize
(Standard_Positive
, Standard_Integer_Size
);
661 Init_RM_Size
(Standard_Positive
, Standard_Integer_Size
- 1);
662 Set_Prim_Alignment
(Standard_Positive
);
664 Set_Size_Known_At_Compile_Time
(Standard_Positive
);
666 Set_Integer_Bounds
(Standard_Positive
,
667 Typ
=> Base_Type
(Standard_Integer
),
669 Hb
=> Intval
(High_Bound
(Scalar_Range
(Standard_Integer
))));
670 Set_Is_Constrained
(Standard_Positive
);
671 Set_Is_Frozen
(Standard_Positive
);
672 Set_Is_Public
(Standard_Positive
);
674 -- Create declaration for package ASCII
676 Decl
:= New_Node
(N_Package_Declaration
, Stloc
);
677 Append
(Decl
, Decl_S
);
679 Pspec
:= New_Node
(N_Package_Specification
, Stloc
);
680 Set_Specification
(Decl
, Pspec
);
682 Set_Defining_Unit_Name
(Pspec
, Standard_Entity
(S_ASCII
));
683 Set_Ekind
(Standard_Entity
(S_ASCII
), E_Package
);
684 Set_Visible_Declarations
(Pspec
, Decl_A
);
686 -- Create control character definitions in package ASCII. Note that
687 -- the character literal entries created here correspond to literal
688 -- values that are impossible in the source, but can be represented
689 -- internally with no difficulties.
693 for S
in S_ASCII_Names
loop
694 Decl
:= New_Node
(N_Object_Declaration
, Staloc
);
695 Set_Constant_Present
(Decl
, True);
698 A_Char
: constant Entity_Id
:= Standard_Entity
(S
);
702 Set_Sloc
(A_Char
, Staloc
);
703 Set_Ekind
(A_Char
, E_Constant
);
704 Set_Never_Set_In_Source
(A_Char
, True);
705 Set_Is_True_Constant
(A_Char
, True);
706 Set_Etype
(A_Char
, Standard_Character
);
707 Set_Scope
(A_Char
, Standard_Entity
(S_ASCII
));
708 Set_Is_Immediately_Visible
(A_Char
, False);
709 Set_Is_Public
(A_Char
, True);
710 Set_Is_Known_Valid
(A_Char
, True);
712 Append_Entity
(A_Char
, Standard_Entity
(S_ASCII
));
713 Set_Defining_Identifier
(Decl
, A_Char
);
715 Set_Object_Definition
(Decl
, Identifier_For
(S_Character
));
716 Expr_Decl
:= New_Node
(N_Character_Literal
, Staloc
);
717 Set_Expression
(Decl
, Expr_Decl
);
719 Set_Is_Static_Expression
(Expr_Decl
);
720 Set_Chars
(Expr_Decl
, No_Name
);
721 Set_Etype
(Expr_Decl
, Standard_Character
);
722 Set_Char_Literal_Value
(Expr_Decl
, Ccode
);
725 Append
(Decl
, Decl_A
);
727 -- Increment character code, dealing with non-contiguities
731 if Ccode
= 16#
20#
then
733 elsif Ccode
= 16#
27#
then
735 elsif Ccode
= 16#
3C#
then
737 elsif Ccode
= 16#
41#
then
742 -- Create semantic phase entities
744 Standard_Void_Type
:= New_Standard_Entity
;
745 Set_Ekind
(Standard_Void_Type
, E_Void
);
746 Set_Etype
(Standard_Void_Type
, Standard_Void_Type
);
747 Set_Scope
(Standard_Void_Type
, Standard_Standard
);
748 Make_Name
(Standard_Void_Type
, "_void_type");
750 -- The type field of packages is set to void
752 Set_Etype
(Standard_Standard
, Standard_Void_Type
);
753 Set_Etype
(Standard_ASCII
, Standard_Void_Type
);
755 -- Standard_A_String is actually used in generated code, so it has a
756 -- type name that is reasonable, but does not overlap any Ada name.
758 Standard_A_String
:= New_Standard_Entity
;
759 Set_Ekind
(Standard_A_String
, E_Access_Type
);
760 Set_Scope
(Standard_A_String
, Standard_Standard
);
761 Set_Etype
(Standard_A_String
, Standard_A_String
);
764 Init_Size
(Standard_A_String
, System_Address_Size
);
766 Init_Size
(Standard_A_String
, System_Address_Size
* 2);
769 Init_Alignment
(Standard_A_String
);
771 Set_Directly_Designated_Type
772 (Standard_A_String
, Standard_String
);
773 Make_Name
(Standard_A_String
, "access_string");
775 Standard_A_Char
:= New_Standard_Entity
;
776 Set_Ekind
(Standard_A_Char
, E_Access_Type
);
777 Set_Scope
(Standard_A_Char
, Standard_Standard
);
778 Set_Etype
(Standard_A_Char
, Standard_A_String
);
779 Init_Size
(Standard_A_Char
, System_Address_Size
);
780 Set_Prim_Alignment
(Standard_A_Char
);
782 Set_Directly_Designated_Type
(Standard_A_Char
, Standard_Character
);
783 Make_Name
(Standard_A_Char
, "access_character");
785 -- Note on type names. The type names for the following special types
786 -- are constructed so that they will look reasonable should they ever
787 -- appear in error messages etc, although in practice the use of the
788 -- special insertion character } for types results in special handling
789 -- of these type names in any case. The blanks in these names would
790 -- trouble in Gigi, but that's OK here, since none of these types
791 -- should ever get through to Gigi! Attributes of these types are
792 -- filled out to minimize problems with cascaded errors (for example,
793 -- Any_Integer is given reasonable and consistent type and size values)
795 Any_Type
:= New_Standard_Entity
;
796 Decl
:= New_Node
(N_Full_Type_Declaration
, Stloc
);
797 Set_Defining_Identifier
(Decl
, Any_Type
);
798 Set_Scope
(Any_Type
, Standard_Standard
);
799 Build_Signed_Integer_Type
(Any_Type
, Standard_Integer_Size
);
800 Make_Name
(Any_Type
, "any type");
802 Any_Id
:= New_Standard_Entity
;
803 Set_Ekind
(Any_Id
, E_Variable
);
804 Set_Scope
(Any_Id
, Standard_Standard
);
805 Set_Etype
(Any_Id
, Any_Type
);
806 Init_Size_Align
(Any_Id
);
807 Make_Name
(Any_Id
, "any id");
809 Any_Access
:= New_Standard_Entity
;
810 Set_Ekind
(Any_Access
, E_Access_Type
);
811 Set_Scope
(Any_Access
, Standard_Standard
);
812 Set_Etype
(Any_Access
, Any_Access
);
813 Init_Size
(Any_Access
, System_Address_Size
);
814 Set_Prim_Alignment
(Any_Access
);
815 Make_Name
(Any_Access
, "an access type");
817 Any_Character
:= New_Standard_Entity
;
818 Set_Ekind
(Any_Character
, E_Enumeration_Type
);
819 Set_Scope
(Any_Character
, Standard_Standard
);
820 Set_Etype
(Any_Character
, Any_Character
);
821 Set_Is_Unsigned_Type
(Any_Character
);
822 Set_Is_Character_Type
(Any_Character
);
823 Init_Esize
(Any_Character
, Standard_Character_Size
);
824 Init_RM_Size
(Any_Character
, 8);
825 Set_Prim_Alignment
(Any_Character
);
826 Set_Scalar_Range
(Any_Character
, Scalar_Range
(Standard_Character
));
827 Make_Name
(Any_Character
, "a character type");
829 Any_Array
:= New_Standard_Entity
;
830 Set_Ekind
(Any_Array
, E_String_Type
);
831 Set_Scope
(Any_Array
, Standard_Standard
);
832 Set_Etype
(Any_Array
, Any_Array
);
833 Set_Component_Type
(Any_Array
, Any_Character
);
834 Init_Size_Align
(Any_Array
);
835 Make_Name
(Any_Array
, "an array type");
837 Any_Boolean
:= New_Standard_Entity
;
838 Set_Ekind
(Any_Boolean
, E_Enumeration_Type
);
839 Set_Scope
(Any_Boolean
, Standard_Standard
);
840 Set_Etype
(Any_Boolean
, Standard_Boolean
);
841 Init_Esize
(Any_Boolean
, Standard_Character_Size
);
842 Init_RM_Size
(Any_Boolean
, 1);
843 Set_Prim_Alignment
(Any_Boolean
);
844 Set_Is_Unsigned_Type
(Any_Boolean
);
845 Set_Scalar_Range
(Any_Boolean
, Scalar_Range
(Standard_Boolean
));
846 Make_Name
(Any_Boolean
, "a boolean type");
848 Any_Composite
:= New_Standard_Entity
;
849 Set_Ekind
(Any_Composite
, E_Array_Type
);
850 Set_Scope
(Any_Composite
, Standard_Standard
);
851 Set_Etype
(Any_Composite
, Any_Composite
);
852 Set_Component_Size
(Any_Composite
, Uint_0
);
853 Set_Component_Type
(Any_Composite
, Standard_Integer
);
854 Init_Size_Align
(Any_Composite
);
855 Make_Name
(Any_Composite
, "a composite type");
857 Any_Discrete
:= New_Standard_Entity
;
858 Set_Ekind
(Any_Discrete
, E_Signed_Integer_Type
);
859 Set_Scope
(Any_Discrete
, Standard_Standard
);
860 Set_Etype
(Any_Discrete
, Any_Discrete
);
861 Init_Size
(Any_Discrete
, Standard_Integer_Size
);
862 Set_Prim_Alignment
(Any_Discrete
);
863 Make_Name
(Any_Discrete
, "a discrete type");
865 Any_Fixed
:= New_Standard_Entity
;
866 Set_Ekind
(Any_Fixed
, E_Ordinary_Fixed_Point_Type
);
867 Set_Scope
(Any_Fixed
, Standard_Standard
);
868 Set_Etype
(Any_Fixed
, Any_Fixed
);
869 Init_Size
(Any_Fixed
, Standard_Integer_Size
);
870 Set_Prim_Alignment
(Any_Fixed
);
871 Make_Name
(Any_Fixed
, "a fixed-point type");
873 Any_Integer
:= New_Standard_Entity
;
874 Set_Ekind
(Any_Integer
, E_Signed_Integer_Type
);
875 Set_Scope
(Any_Integer
, Standard_Standard
);
876 Set_Etype
(Any_Integer
, Standard_Long_Long_Integer
);
877 Init_Size
(Any_Integer
, Standard_Long_Long_Integer_Size
);
878 Set_Prim_Alignment
(Any_Integer
);
882 Typ
=> Base_Type
(Standard_Integer
),
884 Hb
=> Intval
(High_Bound
(Scalar_Range
(Standard_Integer
))));
885 Make_Name
(Any_Integer
, "an integer type");
887 Any_Modular
:= New_Standard_Entity
;
888 Set_Ekind
(Any_Modular
, E_Modular_Integer_Type
);
889 Set_Scope
(Any_Modular
, Standard_Standard
);
890 Set_Etype
(Any_Modular
, Standard_Long_Long_Integer
);
891 Init_Size
(Any_Modular
, Standard_Long_Long_Integer_Size
);
892 Set_Prim_Alignment
(Any_Modular
);
893 Set_Is_Unsigned_Type
(Any_Modular
);
894 Make_Name
(Any_Modular
, "a modular type");
896 Any_Numeric
:= New_Standard_Entity
;
897 Set_Ekind
(Any_Numeric
, E_Signed_Integer_Type
);
898 Set_Scope
(Any_Numeric
, Standard_Standard
);
899 Set_Etype
(Any_Numeric
, Standard_Long_Long_Integer
);
900 Init_Size
(Any_Numeric
, Standard_Long_Long_Integer_Size
);
901 Set_Prim_Alignment
(Any_Numeric
);
902 Make_Name
(Any_Numeric
, "a numeric type");
904 Any_Real
:= New_Standard_Entity
;
905 Set_Ekind
(Any_Real
, E_Floating_Point_Type
);
906 Set_Scope
(Any_Real
, Standard_Standard
);
907 Set_Etype
(Any_Real
, Standard_Long_Long_Float
);
908 Init_Size
(Any_Real
, Standard_Long_Long_Float_Size
);
909 Set_Prim_Alignment
(Any_Real
);
910 Make_Name
(Any_Real
, "a real type");
912 Any_Scalar
:= New_Standard_Entity
;
913 Set_Ekind
(Any_Scalar
, E_Signed_Integer_Type
);
914 Set_Scope
(Any_Scalar
, Standard_Standard
);
915 Set_Etype
(Any_Scalar
, Any_Scalar
);
916 Init_Size
(Any_Scalar
, Standard_Integer_Size
);
917 Set_Prim_Alignment
(Any_Scalar
);
918 Make_Name
(Any_Scalar
, "a scalar type");
920 Any_String
:= New_Standard_Entity
;
921 Set_Ekind
(Any_String
, E_String_Type
);
922 Set_Scope
(Any_String
, Standard_Standard
);
923 Set_Etype
(Any_String
, Any_String
);
924 Set_Component_Type
(Any_String
, Any_Character
);
925 Init_Size_Align
(Any_String
);
926 Make_Name
(Any_String
, "a string type");
934 Low_Bound
=> Make_Integer
(Uint_0
),
935 High_Bound
=> Make_Integer
(Uint_2
** Standard_Integer_Size
));
936 Set_Etype
(Index
, Standard_Integer
);
937 Set_First_Index
(Any_String
, Index
);
940 Standard_Integer_8
:= New_Standard_Entity
;
941 Decl
:= New_Node
(N_Full_Type_Declaration
, Stloc
);
942 Set_Defining_Identifier
(Decl
, Standard_Integer_8
);
943 Make_Name
(Standard_Integer_8
, "integer_8");
944 Set_Scope
(Standard_Integer_8
, Standard_Standard
);
945 Build_Signed_Integer_Type
(Standard_Integer_8
, 8);
947 Standard_Integer_16
:= New_Standard_Entity
;
948 Decl
:= New_Node
(N_Full_Type_Declaration
, Stloc
);
949 Set_Defining_Identifier
(Decl
, Standard_Integer_16
);
950 Make_Name
(Standard_Integer_16
, "integer_16");
951 Set_Scope
(Standard_Integer_16
, Standard_Standard
);
952 Build_Signed_Integer_Type
(Standard_Integer_16
, 16);
954 Standard_Integer_32
:= New_Standard_Entity
;
955 Decl
:= New_Node
(N_Full_Type_Declaration
, Stloc
);
956 Set_Defining_Identifier
(Decl
, Standard_Integer_32
);
957 Make_Name
(Standard_Integer_32
, "integer_32");
958 Set_Scope
(Standard_Integer_32
, Standard_Standard
);
959 Build_Signed_Integer_Type
(Standard_Integer_32
, 32);
961 Standard_Integer_64
:= New_Standard_Entity
;
962 Decl
:= New_Node
(N_Full_Type_Declaration
, Stloc
);
963 Set_Defining_Identifier
(Decl
, Standard_Integer_64
);
964 Make_Name
(Standard_Integer_64
, "integer_64");
965 Set_Scope
(Standard_Integer_64
, Standard_Standard
);
966 Build_Signed_Integer_Type
(Standard_Integer_64
, 64);
968 Standard_Unsigned
:= New_Standard_Entity
;
969 Decl
:= New_Node
(N_Full_Type_Declaration
, Stloc
);
970 Set_Defining_Identifier
(Decl
, Standard_Unsigned
);
971 Make_Name
(Standard_Unsigned
, "unsigned");
973 Set_Ekind
(Standard_Unsigned
, E_Modular_Integer_Type
);
974 Set_Scope
(Standard_Unsigned
, Standard_Standard
);
975 Set_Etype
(Standard_Unsigned
, Standard_Unsigned
);
976 Init_Size
(Standard_Unsigned
, Standard_Integer_Size
);
977 Set_Prim_Alignment
(Standard_Unsigned
);
978 Set_Modulus
(Standard_Unsigned
,
979 Uint_2
** Standard_Integer_Size
);
980 Set_Is_Unsigned_Type
(Standard_Unsigned
);
981 Set_Size_Known_At_Compile_Time
984 R_Node
:= New_Node
(N_Range
, Stloc
);
985 Set_Low_Bound
(R_Node
, Make_Integer
(Uint_0
));
986 Set_High_Bound
(R_Node
, Make_Integer
(Modulus
(Standard_Unsigned
) - 1));
987 Set_Etype
(Low_Bound
(R_Node
), Standard_Unsigned
);
988 Set_Etype
(High_Bound
(R_Node
), Standard_Unsigned
);
989 Set_Scalar_Range
(Standard_Unsigned
, R_Node
);
991 -- Note: universal integer and universal real are constructed as fully
992 -- formed signed numeric types, with parameters corresponding to the
993 -- longest runtime types (Long_Long_Integer and Long_Long_Float). This
994 -- allows Gigi to properly process references to universal types that
995 -- are not folded at compile time.
997 Universal_Integer
:= New_Standard_Entity
;
998 Decl
:= New_Node
(N_Full_Type_Declaration
, Stloc
);
999 Set_Defining_Identifier
(Decl
, Universal_Integer
);
1000 Make_Name
(Universal_Integer
, "universal_integer");
1001 Set_Scope
(Universal_Integer
, Standard_Standard
);
1002 Build_Signed_Integer_Type
1003 (Universal_Integer
, Standard_Long_Long_Integer_Size
);
1005 Universal_Real
:= New_Standard_Entity
;
1006 Decl
:= New_Node
(N_Full_Type_Declaration
, Stloc
);
1007 Set_Defining_Identifier
(Decl
, Universal_Real
);
1008 Make_Name
(Universal_Real
, "universal_real");
1009 Set_Scope
(Universal_Real
, Standard_Standard
);
1012 Standard_Long_Long_Float_Size
,
1013 Standard_Long_Long_Float_Digits
);
1015 -- Note: universal fixed, unlike universal integer and universal real,
1016 -- is never used at runtime, so it does not need to have bounds set.
1018 Universal_Fixed
:= New_Standard_Entity
;
1019 Decl
:= New_Node
(N_Full_Type_Declaration
, Stloc
);
1020 Set_Defining_Identifier
(Decl
, Universal_Fixed
);
1021 Make_Name
(Universal_Fixed
, "universal_fixed");
1022 Set_Ekind
(Universal_Fixed
, E_Ordinary_Fixed_Point_Type
);
1023 Set_Etype
(Universal_Fixed
, Universal_Fixed
);
1024 Set_Scope
(Universal_Fixed
, Standard_Standard
);
1025 Init_Size
(Universal_Fixed
, Standard_Long_Long_Integer_Size
);
1026 Set_Prim_Alignment
(Universal_Fixed
);
1027 Set_Size_Known_At_Compile_Time
1030 -- Create type declaration for Duration, using a 64-bit size. The
1031 -- delta and size values depend on the mode set in system.ads.
1033 Build_Duration
: declare
1039 -- In 32 bit mode, the size is 32 bits, and the delta and
1040 -- small values are set to 20 milliseconds (20.0**(10.0**(-3)).
1042 if Duration_32_Bits_On_Target
then
1043 Dlo
:= Intval
(Type_Low_Bound
(Standard_Integer_32
));
1044 Dhi
:= Intval
(Type_High_Bound
(Standard_Integer_32
));
1045 Delta_Val
:= UR_From_Components
(UI_From_Int
(20), Uint_3
, 10);
1047 -- In standard 64-bit mode, the size is 64-bits and the delta and
1048 -- amll values are set to nanoseconds (1.0**(10.0**(-9))
1051 Dlo
:= Intval
(Type_Low_Bound
(Standard_Integer_64
));
1052 Dhi
:= Intval
(Type_High_Bound
(Standard_Integer_64
));
1053 Delta_Val
:= UR_From_Components
(Uint_1
, Uint_9
, 10);
1056 Tdef_Node
:= Make_Ordinary_Fixed_Point_Definition
(Stloc
,
1057 Delta_Expression
=> Make_Real_Literal
(Stloc
, Delta_Val
),
1058 Real_Range_Specification
=>
1059 Make_Real_Range_Specification
(Stloc
,
1060 Low_Bound
=> Make_Real_Literal
(Stloc
,
1061 Realval
=> Dlo
* Delta_Val
),
1062 High_Bound
=> Make_Real_Literal
(Stloc
,
1063 Realval
=> Dhi
* Delta_Val
)));
1065 Set_Type_Definition
(Parent
(Standard_Duration
), Tdef_Node
);
1067 Set_Ekind
(Standard_Duration
, E_Ordinary_Fixed_Point_Type
);
1068 Set_Etype
(Standard_Duration
, Standard_Duration
);
1070 if Duration_32_Bits_On_Target
then
1071 Init_Size
(Standard_Duration
, 32);
1073 Init_Size
(Standard_Duration
, 64);
1076 Set_Prim_Alignment
(Standard_Duration
);
1077 Set_Delta_Value
(Standard_Duration
, Delta_Val
);
1078 Set_Small_Value
(Standard_Duration
, Delta_Val
);
1079 Set_Scalar_Range
(Standard_Duration
,
1080 Real_Range_Specification
1081 (Type_Definition
(Parent
(Standard_Duration
))));
1083 -- Normally it does not matter that nodes in package Standard are
1084 -- not marked as analyzed. The Scalar_Range of the fixed-point
1085 -- type Standard_Duration is an exception, because of the special
1086 -- test made in Freeze.Freeze_Fixed_Point_Type.
1088 Set_Analyzed
(Scalar_Range
(Standard_Duration
));
1090 Set_Etype
(Type_High_Bound
(Standard_Duration
), Standard_Duration
);
1091 Set_Etype
(Type_Low_Bound
(Standard_Duration
), Standard_Duration
);
1093 Set_Is_Static_Expression
(Type_High_Bound
(Standard_Duration
));
1094 Set_Is_Static_Expression
(Type_Low_Bound
(Standard_Duration
));
1096 Set_Corresponding_Integer_Value
1097 (Type_High_Bound
(Standard_Duration
), Dhi
);
1099 Set_Corresponding_Integer_Value
1100 (Type_Low_Bound
(Standard_Duration
), Dlo
);
1102 Set_Size_Known_At_Compile_Time
(Standard_Duration
);
1105 -- Build standard exception type. Note that the type name here is
1106 -- actually used in the generated code, so it must be set correctly
1108 -- ??? Also note that the Import_Code component is now declared
1109 -- as a System.Standard_Library.Exception_Code to enforce run-time
1110 -- library implementation consistency. It's too early here to resort
1111 -- to rtsfind to get the proper node for that type, so we use the
1112 -- closest possible available type node at hand instead. We should
1113 -- probably be fixing this up at some point.
1115 Standard_Exception_Type
:= New_Standard_Entity
;
1116 Set_Ekind
(Standard_Exception_Type
, E_Record_Type
);
1117 Set_Etype
(Standard_Exception_Type
, Standard_Exception_Type
);
1118 Set_Scope
(Standard_Exception_Type
, Standard_Standard
);
1119 Set_Stored_Constraint
1120 (Standard_Exception_Type
, No_Elist
);
1121 Init_Size_Align
(Standard_Exception_Type
);
1122 Set_Size_Known_At_Compile_Time
1123 (Standard_Exception_Type
, True);
1124 Make_Name
(Standard_Exception_Type
, "exception");
1126 Make_Component
(Standard_Exception_Type
, Standard_Boolean
,
1127 "Not_Handled_By_Others");
1128 Make_Component
(Standard_Exception_Type
, Standard_Character
, "Lang");
1129 Make_Component
(Standard_Exception_Type
, Standard_Natural
,
1131 Make_Component
(Standard_Exception_Type
, Standard_A_Char
,
1133 Make_Component
(Standard_Exception_Type
, Standard_A_Char
,
1135 Make_Component
(Standard_Exception_Type
, Standard_Unsigned
,
1137 Make_Component
(Standard_Exception_Type
, Standard_A_Char
,
1139 -- Build tree for record declaration, for use by the back-end.
1142 Comp_List
: List_Id
;
1146 Comp
:= First_Entity
(Standard_Exception_Type
);
1147 Comp_List
:= New_List
;
1149 while Present
(Comp
) loop
1151 Make_Component_Declaration
(Stloc
,
1152 Defining_Identifier
=> Comp
,
1153 Component_Definition
=>
1154 Make_Component_Definition
(Stloc
,
1155 Aliased_Present
=> False,
1156 Subtype_Indication
=> New_Occurrence_Of
(Etype
(Comp
),
1163 Decl
:= Make_Full_Type_Declaration
(Stloc
,
1164 Defining_Identifier
=> Standard_Exception_Type
,
1166 Make_Record_Definition
(Stloc
,
1169 Make_Component_List
(Stloc
,
1170 Component_Items
=> Comp_List
)));
1173 Append
(Decl
, Decl_S
);
1175 Layout_Type
(Standard_Exception_Type
);
1177 -- Create declarations of standard exceptions
1179 Build_Exception
(S_Constraint_Error
);
1180 Build_Exception
(S_Program_Error
);
1181 Build_Exception
(S_Storage_Error
);
1182 Build_Exception
(S_Tasking_Error
);
1184 -- Numeric_Error is a normal exception in Ada 83, but in Ada 95
1185 -- it is a renaming of Constraint_Error
1188 Build_Exception
(S_Numeric_Error
);
1191 Decl
:= New_Node
(N_Exception_Renaming_Declaration
, Stloc
);
1192 E_Id
:= Standard_Entity
(S_Numeric_Error
);
1194 Set_Ekind
(E_Id
, E_Exception
);
1195 Set_Exception_Code
(E_Id
, Uint_0
);
1196 Set_Etype
(E_Id
, Standard_Exception_Type
);
1197 Set_Is_Public
(E_Id
);
1198 Set_Renamed_Entity
(E_Id
, Standard_Entity
(S_Constraint_Error
));
1200 Set_Defining_Identifier
(Decl
, E_Id
);
1201 Append
(Decl
, Decl_S
);
1203 Ident_Node
:= New_Node
(N_Identifier
, Stloc
);
1204 Set_Chars
(Ident_Node
, Chars
(Standard_Entity
(S_Constraint_Error
)));
1205 Set_Entity
(Ident_Node
, Standard_Entity
(S_Constraint_Error
));
1206 Set_Name
(Decl
, Ident_Node
);
1209 -- Abort_Signal is an entity that does not get made visible
1211 Abort_Signal
:= New_Standard_Entity
;
1212 Set_Chars
(Abort_Signal
, Name_uAbort_Signal
);
1213 Set_Ekind
(Abort_Signal
, E_Exception
);
1214 Set_Exception_Code
(Abort_Signal
, Uint_0
);
1215 Set_Etype
(Abort_Signal
, Standard_Exception_Type
);
1216 Set_Scope
(Abort_Signal
, Standard_Standard
);
1217 Set_Is_Public
(Abort_Signal
, True);
1219 Make_Exception_Declaration
(Stloc
,
1220 Defining_Identifier
=> Abort_Signal
);
1222 -- Create defining identifiers for shift operator entities. Note
1223 -- that these entities are used only for marking shift operators
1224 -- generated internally, and hence need no structure, just a name
1225 -- and a unique identity.
1227 Standard_Op_Rotate_Left
:= New_Standard_Entity
;
1228 Set_Chars
(Standard_Op_Rotate_Left
, Name_Rotate_Left
);
1229 Set_Ekind
(Standard_Op_Rotate_Left
, E_Operator
);
1231 Standard_Op_Rotate_Right
:= New_Standard_Entity
;
1232 Set_Chars
(Standard_Op_Rotate_Right
, Name_Rotate_Right
);
1233 Set_Ekind
(Standard_Op_Rotate_Right
, E_Operator
);
1235 Standard_Op_Shift_Left
:= New_Standard_Entity
;
1236 Set_Chars
(Standard_Op_Shift_Left
, Name_Shift_Left
);
1237 Set_Ekind
(Standard_Op_Shift_Left
, E_Operator
);
1239 Standard_Op_Shift_Right
:= New_Standard_Entity
;
1240 Set_Chars
(Standard_Op_Shift_Right
, Name_Shift_Right
);
1241 Set_Ekind
(Standard_Op_Shift_Right
, E_Operator
);
1243 Standard_Op_Shift_Right_Arithmetic
:= New_Standard_Entity
;
1244 Set_Chars
(Standard_Op_Shift_Right_Arithmetic
,
1245 Name_Shift_Right_Arithmetic
);
1246 Set_Ekind
(Standard_Op_Shift_Right_Arithmetic
,
1249 -- Create standard operator declarations
1253 -- Initialize visibility table with entities in Standard
1255 for E
in Standard_Entity_Type
loop
1256 if Ekind
(Standard_Entity
(E
)) /= E_Operator
then
1258 (Chars
(Standard_Entity
(E
)), Standard_Entity
(E
));
1259 Set_Homonym
(Standard_Entity
(E
), Empty
);
1262 if E
not in S_ASCII_Names
then
1263 Set_Scope
(Standard_Entity
(E
), Standard_Standard
);
1264 Set_Is_Immediately_Visible
(Standard_Entity
(E
));
1268 -- The predefined package Standard itself does not have a scope;
1269 -- it is the only entity in the system not to have one, and this
1270 -- is what identifies the package to Gigi.
1272 Set_Scope
(Standard_Standard
, Empty
);
1274 -- Set global variables indicating last Id values and version
1276 Last_Standard_Node_Id
:= Last_Node_Id
;
1277 Last_Standard_List_Id
:= Last_List_Id
;
1279 -- The Error node has an Etype of Any_Type to help error recovery
1281 Set_Etype
(Error
, Any_Type
);
1283 -- Print representation of standard if switch set
1285 if Opt
.Print_Standard
then
1288 end Create_Standard
;
1290 ------------------------------------
1291 -- Create_Unconstrained_Base_Type --
1292 ------------------------------------
1294 procedure Create_Unconstrained_Base_Type
1298 New_Ent
: constant Entity_Id
:= New_Copy
(E
);
1302 Set_Is_Constrained
(E
, True);
1303 Set_Is_First_Subtype
(E
, True);
1304 Set_Etype
(E
, New_Ent
);
1306 Append_Entity
(New_Ent
, Standard_Standard
);
1307 Set_Is_Constrained
(New_Ent
, False);
1308 Set_Etype
(New_Ent
, New_Ent
);
1309 Set_Is_Known_Valid
(New_Ent
, True);
1311 if K
= E_Signed_Integer_Subtype
then
1312 Set_Etype
(Low_Bound
(Scalar_Range
(E
)), New_Ent
);
1313 Set_Etype
(High_Bound
(Scalar_Range
(E
)), New_Ent
);
1316 end Create_Unconstrained_Base_Type
;
1318 --------------------
1319 -- Identifier_For --
1320 --------------------
1322 function Identifier_For
(S
: Standard_Entity_Type
) return Node_Id
is
1323 Ident_Node
: Node_Id
;
1326 Ident_Node
:= New_Node
(N_Identifier
, Stloc
);
1327 Set_Chars
(Ident_Node
, Chars
(Standard_Entity
(S
)));
1331 --------------------
1332 -- Make_Component --
1333 --------------------
1335 procedure Make_Component
1340 Id
: constant Entity_Id
:= New_Standard_Entity
;
1343 Set_Ekind
(Id
, E_Component
);
1344 Set_Etype
(Id
, Typ
);
1345 Set_Scope
(Id
, Rec
);
1346 Init_Component_Location
(Id
);
1348 Set_Original_Record_Component
(Id
, Id
);
1349 Make_Name
(Id
, Nam
);
1350 Append_Entity
(Id
, Rec
);
1357 function Make_Formal
1359 Formal_Name
: String) return Entity_Id
1364 Formal
:= New_Standard_Entity
;
1366 Set_Ekind
(Formal
, E_In_Parameter
);
1367 Set_Mechanism
(Formal
, Default_Mechanism
);
1368 Set_Scope
(Formal
, Standard_Standard
);
1369 Set_Etype
(Formal
, Typ
);
1370 Make_Name
(Formal
, Formal_Name
);
1379 function Make_Integer
(V
: Uint
) return Node_Id
is
1380 N
: constant Node_Id
:= Make_Integer_Literal
(Stloc
, V
);
1382 Set_Is_Static_Expression
(N
);
1390 procedure Make_Name
(Id
: Entity_Id
; Nam
: String) is
1392 for J
in 1 .. Nam
'Length loop
1393 Name_Buffer
(J
) := Fold_Lower
(Nam
(Nam
'First + (J
- 1)));
1396 Name_Len
:= Nam
'Length;
1397 Set_Chars
(Id
, Name_Find
);
1404 function New_Operator
(Op
: Name_Id
; Typ
: Entity_Id
) return Entity_Id
is
1405 Ident_Node
: Entity_Id
;
1408 Ident_Node
:= Make_Defining_Identifier
(Stloc
, Op
);
1410 Set_Is_Pure
(Ident_Node
, True);
1411 Set_Ekind
(Ident_Node
, E_Operator
);
1412 Set_Etype
(Ident_Node
, Typ
);
1413 Set_Scope
(Ident_Node
, Standard_Standard
);
1414 Set_Homonym
(Ident_Node
, Get_Name_Entity_Id
(Op
));
1415 Set_Convention
(Ident_Node
, Convention_Intrinsic
);
1417 Set_Is_Immediately_Visible
(Ident_Node
, True);
1418 Set_Is_Intrinsic_Subprogram
(Ident_Node
, True);
1420 Set_Name_Entity_Id
(Op
, Ident_Node
);
1421 Append_Entity
(Ident_Node
, Standard_Standard
);
1425 -------------------------
1426 -- New_Standard_Entity --
1427 -------------------------
1429 function New_Standard_Entity
1430 (New_Node_Kind
: Node_Kind
:= N_Defining_Identifier
) return Entity_Id
1432 E
: constant Entity_Id
:= New_Entity
(New_Node_Kind
, Stloc
);
1435 -- All standard entities are Pure and Public
1440 -- All standard entity names are analyzed manually, and are thus
1441 -- frozen as soon as they are created.
1445 -- Set debug information required for all standard types
1447 Set_Needs_Debug_Info
(E
);
1449 -- All standard entities are built with fully qualified names, so
1450 -- set the flag to prevent an abortive attempt at requalification!
1452 Set_Has_Qualified_Name
(E
);
1454 -- Return newly created entity to be completed by caller
1457 end New_Standard_Entity
;
1459 --------------------
1460 -- Print_Standard --
1461 --------------------
1463 procedure Print_Standard
is
1465 procedure P
(Item
: String) renames Output
.Write_Line
;
1466 -- Short-hand, since we do a lot of line writes here!
1468 procedure P_Int_Range
(Size
: Pos
);
1469 -- Prints the range of an integer based on its Size
1471 procedure P_Float_Range
(Id
: Entity_Id
);
1472 -- Prints the bounds range for the given float type entity
1478 procedure P_Float_Range
(Id
: Entity_Id
) is
1479 Digs
: constant Nat
:= UI_To_Int
(Digits_Value
(Id
));
1482 Write_Str
(" range ");
1484 if Vax_Float
(Id
) then
1485 if Digs
= VAXFF_Digits
then
1486 Write_Str
(VAXFF_First
'Universal_Literal_String);
1488 Write_Str
(VAXFF_Last
'Universal_Literal_String);
1490 elsif Digs
= VAXDF_Digits
then
1491 Write_Str
(VAXDF_First
'Universal_Literal_String);
1493 Write_Str
(VAXDF_Last
'Universal_Literal_String);
1496 pragma Assert
(Digs
= VAXGF_Digits
);
1498 Write_Str
(VAXGF_First
'Universal_Literal_String);
1500 Write_Str
(VAXGF_Last
'Universal_Literal_String);
1503 elsif Is_AAMP_Float
(Id
) then
1504 if Digs
= AAMPS_Digits
then
1505 Write_Str
(AAMPS_First
'Universal_Literal_String);
1507 Write_Str
(AAMPS_Last
'Universal_Literal_String);
1510 pragma Assert
(Digs
= AAMPL_Digits
);
1511 Write_Str
(AAMPL_First
'Universal_Literal_String);
1513 Write_Str
(AAMPL_Last
'Universal_Literal_String);
1516 elsif Digs
= IEEES_Digits
then
1517 Write_Str
(IEEES_First
'Universal_Literal_String);
1519 Write_Str
(IEEES_Last
'Universal_Literal_String);
1521 elsif Digs
= IEEEL_Digits
then
1522 Write_Str
(IEEEL_First
'Universal_Literal_String);
1524 Write_Str
(IEEEL_Last
'Universal_Literal_String);
1527 pragma Assert
(Digs
= IEEEX_Digits
);
1529 Write_Str
(IEEEX_First
'Universal_Literal_String);
1531 Write_Str
(IEEEX_Last
'Universal_Literal_String);
1542 procedure P_Int_Range
(Size
: Pos
) is
1544 Write_Str
(" is range -(2 **");
1545 Write_Int
(Size
- 1);
1547 Write_Str
(" .. +(2 **");
1548 Write_Int
(Size
- 1);
1549 Write_Str
(" - 1);");
1553 -- Start of processing for Print_Standard
1556 P
("-- Representation of package Standard");
1558 P
("-- This is not accurate Ada, since new base types cannot be ");
1559 P
("-- created, but the listing shows the target dependent");
1560 P
("-- characteristics of the Standard types for this compiler");
1563 P
("package Standard is");
1564 P
("pragma Pure(Standard);");
1567 P
(" type Boolean is (False, True);");
1568 P
(" for Boolean'Size use 1;");
1569 P
(" for Boolean use (False => 0, True => 1);");
1574 Write_Str
(" type Integer");
1575 P_Int_Range
(Standard_Integer_Size
);
1576 Write_Str
(" for Integer'Size use ");
1577 Write_Int
(Standard_Integer_Size
);
1581 P
(" subtype Natural is Integer range 0 .. Integer'Last;");
1582 P
(" subtype Positive is Integer range 1 .. Integer'Last;");
1585 Write_Str
(" type Short_Short_Integer");
1586 P_Int_Range
(Standard_Short_Short_Integer_Size
);
1587 Write_Str
(" for Short_Short_Integer'Size use ");
1588 Write_Int
(Standard_Short_Short_Integer_Size
);
1592 Write_Str
(" type Short_Integer");
1593 P_Int_Range
(Standard_Short_Integer_Size
);
1594 Write_Str
(" for Short_Integer'Size use ");
1595 Write_Int
(Standard_Short_Integer_Size
);
1599 Write_Str
(" type Long_Integer");
1600 P_Int_Range
(Standard_Long_Integer_Size
);
1601 Write_Str
(" for Long_Integer'Size use ");
1602 Write_Int
(Standard_Long_Integer_Size
);
1606 Write_Str
(" type Long_Long_Integer");
1607 P_Int_Range
(Standard_Long_Long_Integer_Size
);
1608 Write_Str
(" for Long_Long_Integer'Size use ");
1609 Write_Int
(Standard_Long_Long_Integer_Size
);
1613 -- Floating point types
1615 Write_Str
(" type Short_Float is digits ");
1616 Write_Int
(Standard_Short_Float_Digits
);
1618 P_Float_Range
(Standard_Short_Float
);
1619 Write_Str
(" for Short_Float'Size use ");
1620 Write_Int
(Standard_Short_Float_Size
);
1624 Write_Str
(" type Float is digits ");
1625 Write_Int
(Standard_Float_Digits
);
1627 P_Float_Range
(Standard_Float
);
1628 Write_Str
(" for Float'Size use ");
1629 Write_Int
(Standard_Float_Size
);
1633 Write_Str
(" type Long_Float is digits ");
1634 Write_Int
(Standard_Long_Float_Digits
);
1636 P_Float_Range
(Standard_Long_Float
);
1637 Write_Str
(" for Long_Float'Size use ");
1638 Write_Int
(Standard_Long_Float_Size
);
1642 Write_Str
(" type Long_Long_Float is digits ");
1643 Write_Int
(Standard_Long_Long_Float_Digits
);
1645 P_Float_Range
(Standard_Long_Long_Float
);
1646 Write_Str
(" for Long_Long_Float'Size use ");
1647 Write_Int
(Standard_Long_Long_Float_Size
);
1651 P
(" type Character is (...)");
1652 Write_Str
(" for Character'Size use ");
1653 Write_Int
(Standard_Character_Size
);
1655 P
(" -- See RM A.1(35) for details of this type");
1658 P
(" type Wide_Character is (...)");
1659 Write_Str
(" for Wide_Character'Size use ");
1660 Write_Int
(Standard_Wide_Character_Size
);
1662 P
(" -- See RM A.1(36) for details of this type");
1665 P
(" type String is array (Positive range <>) of Character;");
1666 P
(" pragma Pack (String);");
1669 P
(" type Wide_String is array (Positive range <>)" &
1670 " of Wide_Character;");
1671 P
(" pragma Pack (Wide_String);");
1674 -- Here it's OK to use the Duration type of the host compiler since
1675 -- the implementation of Duration in GNAT is target independent.
1677 if Duration_32_Bits_On_Target
then
1678 P
(" type Duration is delta 0.020");
1679 P
(" range -((2 ** 31 - 1) * 0.020) ..");
1680 P
(" +((2 ** 31 - 1) * 0.020);");
1681 P
(" for Duration'Small use 0.020;");
1683 P
(" type Duration is delta 0.000000001");
1684 P
(" range -((2 ** 63 - 1) * 0.000000001) ..");
1685 P
(" +((2 ** 63 - 1) * 0.000000001);");
1686 P
(" for Duration'Small use 0.000000001;");
1691 P
(" Constraint_Error : exception;");
1692 P
(" Program_Error : exception;");
1693 P
(" Storage_Error : exception;");
1694 P
(" Tasking_Error : exception;");
1695 P
(" Numeric_Error : exception renames Constraint_Error;");
1698 P
("end Standard;");
1701 ----------------------
1702 -- Set_Float_Bounds --
1703 ----------------------
1705 procedure Set_Float_Bounds
(Id
: Entity_Id
) is
1707 -- Low bound of literal value
1710 -- High bound of literal value
1713 -- Range specification
1715 Digs
: constant Nat
:= UI_To_Int
(Digits_Value
(Id
));
1716 -- Digits value, used to select bounds
1719 -- Note: for the call from Cstand to initially create the types in
1720 -- Standard, Vax_Float will always be False. Circuitry in Sem_Vfpt
1721 -- will adjust these types appropriately in the Vax_Float case if
1722 -- a pragma Float_Representation (VAX_Float) is used.
1724 if Vax_Float
(Id
) then
1725 if Digs
= VAXFF_Digits
then
1727 (VAXFF_First
'Universal_Literal_String);
1729 (VAXFF_Last
'Universal_Literal_String);
1731 elsif Digs
= VAXDF_Digits
then
1733 (VAXDF_First
'Universal_Literal_String);
1735 (VAXDF_Last
'Universal_Literal_String);
1738 pragma Assert
(Digs
= VAXGF_Digits
);
1741 (VAXGF_First
'Universal_Literal_String);
1743 (VAXGF_Last
'Universal_Literal_String);
1746 elsif Is_AAMP_Float
(Id
) then
1747 if Digs
= AAMPS_Digits
then
1749 (AAMPS_First
'Universal_Literal_String);
1751 (AAMPS_Last
'Universal_Literal_String);
1754 pragma Assert
(Digs
= AAMPL_Digits
);
1756 (AAMPL_First
'Universal_Literal_String);
1758 (AAMPL_Last
'Universal_Literal_String);
1761 elsif Digs
= IEEES_Digits
then
1763 (IEEES_First
'Universal_Literal_String);
1765 (IEEES_Last
'Universal_Literal_String);
1767 elsif Digs
= IEEEL_Digits
then
1769 (IEEEL_First
'Universal_Literal_String);
1771 (IEEEL_Last
'Universal_Literal_String);
1774 pragma Assert
(Digs
= IEEEX_Digits
);
1777 (IEEEX_First
'Universal_Literal_String);
1779 (IEEEX_Last
'Universal_Literal_String);
1783 Set_Is_Static_Expression
(L
);
1786 Set_Is_Static_Expression
(H
);
1788 R
:= New_Node
(N_Range
, Stloc
);
1789 Set_Low_Bound
(R
, L
);
1790 Set_High_Bound
(R
, H
);
1791 Set_Includes_Infinities
(R
, True);
1792 Set_Scalar_Range
(Id
, R
);
1795 end Set_Float_Bounds
;
1797 ------------------------
1798 -- Set_Integer_Bounds --
1799 ------------------------
1801 procedure Set_Integer_Bounds
1807 L
: Node_Id
; -- Low bound of literal value
1808 H
: Node_Id
; -- High bound of literal value
1809 R
: Node_Id
; -- Range specification
1812 L
:= Make_Integer
(Lb
);
1813 H
:= Make_Integer
(Hb
);
1818 R
:= New_Node
(N_Range
, Stloc
);
1819 Set_Low_Bound
(R
, L
);
1820 Set_High_Bound
(R
, H
);
1821 Set_Scalar_Range
(Id
, R
);
1824 Set_Is_Unsigned_Type
(Id
, Lb
>= 0);
1825 end Set_Integer_Bounds
;