1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
10 -- Copyright (C) 2001 Free Software Foundation, Inc. --
12 -- GNAT is free software; you can redistribute it and/or modify it under --
13 -- terms of the GNU General Public License as published by the Free Soft- --
14 -- ware Foundation; either version 2, or (at your option) any later ver- --
15 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
16 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
17 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
18 -- for more details. You should have received a copy of the GNU General --
19 -- Public License distributed with GNAT; see file COPYING. If not, write --
20 -- to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, --
21 -- MA 02111-1307, USA. --
23 -- GNAT was originally developed by the GNAT team at New York University. --
24 -- Extensive contributions were provided by Ada Core Technologies Inc. --
26 ------------------------------------------------------------------------------
28 with Atree
; use Atree
;
29 with Casing
; use Casing
;
30 with Checks
; use Checks
;
31 with Einfo
; use Einfo
;
32 with Exp_Util
; use Exp_Util
;
33 with Namet
; use Namet
;
34 with Nmake
; use Nmake
;
35 with Nlists
; use Nlists
;
37 with Rtsfind
; use Rtsfind
;
38 with Sem_Res
; use Sem_Res
;
39 with Sinfo
; use Sinfo
;
40 with Snames
; use Snames
;
41 with Stand
; use Stand
;
42 with Stringt
; use Stringt
;
43 with Tbuild
; use Tbuild
;
44 with Ttypes
; use Ttypes
;
45 with Uintp
; use Uintp
;
47 package body Exp_Imgv
is
49 ------------------------------------
50 -- Build_Enumeration_Image_Tables --
51 ------------------------------------
53 procedure Build_Enumeration_Image_Tables
(E
: Entity_Id
; N
: Node_Id
) is
54 Loc
: constant Source_Ptr
:= Sloc
(E
);
65 -- Nothing to do for other than a root enumeration type
67 if E
/= Root_Type
(E
) then
70 -- Nothing to do if pragma Discard_Names applies
72 elsif Discard_Names
(E
) then
76 -- Otherwise tables need constructing
80 Lit
:= First_Literal
(E
);
86 Make_Integer_Literal
(Loc
, UI_From_Int
(Len
)));
91 Get_Unqualified_Decoded_Name_String
(Chars
(Lit
));
93 if Name_Buffer
(1) /= ''' then
94 Set_Casing
(All_Upper_Case
);
97 Store_String_Chars
(Name_Buffer
(1 .. Name_Len
));
98 Len
:= Len
+ Int
(Name_Len
);
102 if Len
< Int
(2 ** (8 - 1)) then
103 Ityp
:= Standard_Integer_8
;
104 elsif Len
< Int
(2 ** (16 - 1)) then
105 Ityp
:= Standard_Integer_16
;
107 Ityp
:= Standard_Integer_32
;
113 Make_Defining_Identifier
(Loc
,
114 Chars
=> New_External_Name
(Chars
(E
), 'S'));
117 Make_Defining_Identifier
(Loc
,
118 Chars
=> New_External_Name
(Chars
(E
), 'I'));
120 Set_Lit_Strings
(E
, Estr
);
121 Set_Lit_Indexes
(E
, Eind
);
125 Make_Object_Declaration
(Loc
,
126 Defining_Identifier
=> Estr
,
127 Constant_Present
=> True,
129 New_Occurrence_Of
(Standard_String
, Loc
),
131 Make_String_Literal
(Loc
,
134 Make_Object_Declaration
(Loc
,
135 Defining_Identifier
=> Eind
,
136 Constant_Present
=> True,
139 Make_Constrained_Array_Definition
(Loc
,
140 Discrete_Subtype_Definitions
=> New_List
(
142 Low_Bound
=> Make_Integer_Literal
(Loc
, 0),
143 High_Bound
=> Make_Integer_Literal
(Loc
, Nlit
))),
144 Subtype_Indication
=> New_Occurrence_Of
(Ityp
, Loc
)),
148 Expressions
=> Ind
))),
149 Suppress
=> All_Checks
);
151 end Build_Enumeration_Image_Tables
;
153 ----------------------------
154 -- Expand_Image_Attribute --
155 ----------------------------
157 -- For all non-enumeration types, and for enumeration types declared
158 -- in packages Standard or System, typ'Image (Val) expands into:
160 -- Image_xx (tp (Expr) [, pm])
162 -- The name xx and type conversion tp (Expr) (called tv below) depend on
163 -- the root type of Expr. The argument pm is an extra type dependent
164 -- parameter only used in some cases as follows:
166 -- For types whose root type is Character
168 -- tv = Character (Expr)
170 -- For types whose root type is Boolean
172 -- tv = Boolean (Expr)
174 -- For signed integer types with size <= Integer'Size
176 -- tv = Integer (Expr)
178 -- For other signed integer types
179 -- xx = Long_Long_Integer
180 -- tv = Long_Long_Integer (Expr)
182 -- For modular types with modulus <= System.Unsigned_Types.Unsigned
184 -- tv = System.Unsigned_Types.Unsigned (Expr)
186 -- For other modular integer types
187 -- xx = Long_Long_Unsigned
188 -- tv = System.Unsigned_Types.Long_Long_Unsigned (Expr)
190 -- For types whose root type is Wide_Character
191 -- xx = Wide_Character
192 -- tv = Wide_Character (Expr)
193 -- pm = Wide_Character_Encoding_Method
195 -- For floating-point types
196 -- xx = Floating_Point
197 -- tv = Long_Long_Float (Expr)
200 -- For ordinary fixed-point types
201 -- xx = Ordinary_Fixed_Point
202 -- tv = Long_Long_Float (Expr)
205 -- For decimal fixed-point types with size = Integer'Size
207 -- tv = Integer (Expr)
210 -- For decimal fixed-point types with size > Integer'Size
211 -- xx = Long_Long_Decimal
212 -- tv = Long_Long_Integer (Expr)
215 -- Note: for the decimal fixed-point type cases, the conversion is
216 -- done literally without scaling (i.e. the actual expression that
217 -- is generated is Image_xx (tp?(Expr) [, pm])
219 -- For enumeration types other than those declared packages Standard
220 -- or System, typ'Image (X) expands into:
222 -- Image_Enumeration_NN (typ'Pos (X), typS, typI'Address)
224 -- where typS and typI are the entities constructed as described in
225 -- the spec for the procedure Build_Enumeration_Image_Tables and NN
226 -- is 32/16/8 depending on the element type of Lit_Indexes.
228 procedure Expand_Image_Attribute
(N
: Node_Id
) is
229 Loc
: constant Source_Ptr
:= Sloc
(N
);
230 Exprs
: constant List_Id
:= Expressions
(N
);
231 Pref
: constant Node_Id
:= Prefix
(N
);
232 Ptyp
: constant Entity_Id
:= Entity
(Pref
);
233 Rtyp
: constant Entity_Id
:= Root_Type
(Ptyp
);
234 Expr
: constant Node_Id
:= Relocate_Node
(First
(Exprs
));
240 Func_Ent
: Entity_Id
;
243 if Rtyp
= Standard_Boolean
then
244 Imid
:= RE_Image_Boolean
;
247 elsif Rtyp
= Standard_Character
then
248 Imid
:= RE_Image_Character
;
251 elsif Rtyp
= Standard_Wide_Character
then
252 Imid
:= RE_Image_Wide_Character
;
255 elsif Is_Signed_Integer_Type
(Rtyp
) then
256 if Esize
(Rtyp
) <= Esize
(Standard_Integer
) then
257 Imid
:= RE_Image_Integer
;
258 Tent
:= Standard_Integer
;
260 Imid
:= RE_Image_Long_Long_Integer
;
261 Tent
:= Standard_Long_Long_Integer
;
264 elsif Is_Modular_Integer_Type
(Rtyp
) then
265 if Modulus
(Rtyp
) <= Modulus
(RTE
(RE_Unsigned
)) then
266 Imid
:= RE_Image_Unsigned
;
267 Tent
:= RTE
(RE_Unsigned
);
269 Imid
:= RE_Image_Long_Long_Unsigned
;
270 Tent
:= RTE
(RE_Long_Long_Unsigned
);
273 elsif Is_Decimal_Fixed_Point_Type
(Rtyp
) then
274 if UI_To_Int
(Esize
(Rtyp
)) <= Standard_Integer_Size
then
275 Imid
:= RE_Image_Decimal
;
276 Tent
:= Standard_Integer
;
278 Imid
:= RE_Image_Long_Long_Decimal
;
279 Tent
:= Standard_Long_Long_Integer
;
282 elsif Is_Ordinary_Fixed_Point_Type
(Rtyp
) then
283 Imid
:= RE_Image_Ordinary_Fixed_Point
;
284 Tent
:= Standard_Long_Long_Float
;
286 elsif Is_Floating_Point_Type
(Rtyp
) then
287 Imid
:= RE_Image_Floating_Point
;
288 Tent
:= Standard_Long_Long_Float
;
290 -- Only other possibility is user defined enumeration type
293 if Discard_Names
(First_Subtype
(Ptyp
))
294 or else No
(Lit_Strings
(Root_Type
(Ptyp
)))
296 -- When pragma Discard_Names applies to the first subtype,
297 -- then build (Pref'Pos)'Img.
300 Make_Attribute_Reference
(Loc
,
302 Make_Attribute_Reference
(Loc
,
304 Attribute_Name
=> Name_Pos
,
305 Expressions
=> New_List
(Expr
)),
308 Analyze_And_Resolve
(N
, Standard_String
);
311 -- Here we get the Image of an enumeration type
313 Ttyp
:= Component_Type
(Etype
(Lit_Indexes
(Rtyp
)));
315 if Ttyp
= Standard_Integer_8
then
316 Func
:= RE_Image_Enumeration_8
;
317 elsif Ttyp
= Standard_Integer_16
then
318 Func
:= RE_Image_Enumeration_16
;
320 Func
:= RE_Image_Enumeration_32
;
323 -- Apply a validity check, since it is a bit drastic to
324 -- get a completely junk image value for an invalid value.
326 if not Expr_Known_Valid
(Expr
) then
327 Insert_Valid_Check
(Expr
);
331 Make_Function_Call
(Loc
,
332 Name
=> New_Occurrence_Of
(RTE
(Func
), Loc
),
333 Parameter_Associations
=> New_List
(
334 Make_Attribute_Reference
(Loc
,
335 Attribute_Name
=> Name_Pos
,
336 Prefix
=> New_Occurrence_Of
(Ptyp
, Loc
),
337 Expressions
=> New_List
(Expr
)),
338 New_Occurrence_Of
(Lit_Strings
(Rtyp
), Loc
),
339 Make_Attribute_Reference
(Loc
,
340 Prefix
=> New_Occurrence_Of
(Lit_Indexes
(Rtyp
), Loc
),
341 Attribute_Name
=> Name_Address
))));
343 Analyze_And_Resolve
(N
, Standard_String
);
349 -- If we fall through, we have one of the cases that is handled by
350 -- calling one of the System.Img_xx routines and Imid is set to the
351 -- RE_Id for the function to be called.
353 Func_Ent
:= RTE
(Imid
);
355 -- If the function entity is empty, that means we have a case in
356 -- no run time mode where the operation is not allowed, and an
357 -- appropriate diagnostic has already been issued.
359 if No
(Func_Ent
) then
363 -- Otherwise prepare arguments for run-time call
365 Arglist
:= New_List
(Convert_To
(Tent
, Relocate_Node
(Expr
)));
367 -- For floating-point types, append Digits argument
369 if Is_Floating_Point_Type
(Rtyp
) then
371 Make_Attribute_Reference
(Loc
,
372 Prefix
=> New_Reference_To
(Ptyp
, Loc
),
373 Attribute_Name
=> Name_Digits
));
375 -- For ordinary fixed-point types, append Aft parameter
377 elsif Is_Ordinary_Fixed_Point_Type
(Rtyp
) then
379 Make_Attribute_Reference
(Loc
,
380 Prefix
=> New_Reference_To
(Ptyp
, Loc
),
381 Attribute_Name
=> Name_Aft
));
383 -- For wide character, append encoding method
385 elsif Rtyp
= Standard_Wide_Character
then
387 Make_Integer_Literal
(Loc
,
388 Intval
=> Int
(Wide_Character_Encoding_Method
)));
390 -- For decimal, append Scale and also set to do literal conversion
392 elsif Is_Decimal_Fixed_Point_Type
(Rtyp
) then
394 Make_Attribute_Reference
(Loc
,
395 Prefix
=> New_Reference_To
(Ptyp
, Loc
),
396 Attribute_Name
=> Name_Scale
));
398 Set_Conversion_OK
(First
(Arglist
));
399 Set_Etype
(First
(Arglist
), Tent
);
403 Make_Function_Call
(Loc
,
404 Name
=> New_Reference_To
(Func_Ent
, Loc
),
405 Parameter_Associations
=> Arglist
));
407 Analyze_And_Resolve
(N
, Standard_String
);
408 end Expand_Image_Attribute
;
410 ----------------------------
411 -- Expand_Value_Attribute --
412 ----------------------------
414 -- For scalar types derived from Boolean, Character and integer types
415 -- in package Standard, typ'Value (X) expands into:
417 -- btyp (Value_xx (X))
419 -- where btyp is he base type of the prefix, and
421 -- For types whose root type is Character
424 -- For types whose root type is Boolean
427 -- For signed integer types with size <= Integer'Size
430 -- For other signed integer types
431 -- xx = Long_Long_Integer
433 -- For modular types with modulus <= System.Unsigned_Types.Unsigned
436 -- For other modular integer types
437 -- xx = Long_Long_Unsigned
439 -- For floating-point types and ordinary fixed-point types
442 -- For types derived from Wide_Character, typ'Value (X) expands into
444 -- Value_Wide_Character (X, Wide_Character_Encoding_Method)
446 -- For decimal types with size <= Integer'Size, typ'Value (X)
449 -- btyp?(Value_Decimal (X, typ'Scale));
451 -- For all other decimal types, typ'Value (X) expands into
453 -- btyp?(Value_Long_Long_Decimal (X, typ'Scale))
455 -- For enumeration types other than those derived from types Boolean,
456 -- Character, and Wide_Character in Standard, typ'Value (X) expands to:
458 -- Enum'Val (Value_Enumeration_NN (typS, typI'Address, Num, X))
460 -- where typS and typI and the Lit_Strings and Lit_Indexes entities
461 -- from T's root type entitym and Num is Enum'Pos (Enum'Last). The
462 -- Value_Enumeration_NN function will search the tables looking for
463 -- X and return the position number in the table if found which is
464 -- used to provide the result of 'Value (using Enum'Val). If the
465 -- value is not found Constraint_Error is raised. The suffix _NN
466 -- depends on the element type of typI.
468 procedure Expand_Value_Attribute
(N
: Node_Id
) is
469 Loc
: constant Source_Ptr
:= Sloc
(N
);
470 Typ
: constant Entity_Id
:= Etype
(N
);
471 Btyp
: constant Entity_Id
:= Base_Type
(Typ
);
472 Rtyp
: constant Entity_Id
:= Root_Type
(Typ
);
473 Exprs
: constant List_Id
:= Expressions
(N
);
482 if Rtyp
= Standard_Character
then
483 Vid
:= RE_Value_Character
;
485 elsif Rtyp
= Standard_Boolean
then
486 Vid
:= RE_Value_Boolean
;
488 elsif Rtyp
= Standard_Wide_Character
then
489 Vid
:= RE_Value_Wide_Character
;
491 Make_Integer_Literal
(Loc
,
492 Intval
=> Int
(Wide_Character_Encoding_Method
)));
494 elsif Rtyp
= Base_Type
(Standard_Short_Short_Integer
)
495 or else Rtyp
= Base_Type
(Standard_Short_Integer
)
496 or else Rtyp
= Base_Type
(Standard_Integer
)
498 Vid
:= RE_Value_Integer
;
500 elsif Is_Signed_Integer_Type
(Rtyp
) then
501 Vid
:= RE_Value_Long_Long_Integer
;
503 elsif Is_Modular_Integer_Type
(Rtyp
) then
504 if Modulus
(Rtyp
) <= Modulus
(RTE
(RE_Unsigned
)) then
505 Vid
:= RE_Value_Unsigned
;
507 Vid
:= RE_Value_Long_Long_Unsigned
;
510 elsif Is_Decimal_Fixed_Point_Type
(Rtyp
) then
511 if UI_To_Int
(Esize
(Rtyp
)) <= Standard_Integer_Size
then
512 Vid
:= RE_Value_Decimal
;
514 Vid
:= RE_Value_Long_Long_Decimal
;
518 Make_Attribute_Reference
(Loc
,
519 Prefix
=> New_Reference_To
(Typ
, Loc
),
520 Attribute_Name
=> Name_Scale
));
524 Make_Function_Call
(Loc
,
525 Name
=> New_Reference_To
(RTE
(Vid
), Loc
),
526 Parameter_Associations
=> Args
)));
529 Analyze_And_Resolve
(N
, Btyp
);
532 elsif Is_Real_Type
(Rtyp
) then
533 Vid
:= RE_Value_Real
;
535 -- Only other possibility is user defined enumeration type
538 pragma Assert
(Is_Enumeration_Type
(Rtyp
));
540 -- Case of pragma Discard_Names, transform the Value
541 -- attribute to Btyp'Val (Long_Long_Integer'Value (Args))
543 if Discard_Names
(First_Subtype
(Typ
))
544 or else No
(Lit_Strings
(Rtyp
))
547 Make_Attribute_Reference
(Loc
,
548 Prefix
=> New_Reference_To
(Btyp
, Loc
),
549 Attribute_Name
=> Name_Val
,
550 Expressions
=> New_List
(
551 Make_Attribute_Reference
(Loc
,
553 New_Occurrence_Of
(Standard_Long_Long_Integer
, Loc
),
554 Attribute_Name
=> Name_Value
,
555 Expressions
=> Args
))));
557 Analyze_And_Resolve
(N
, Btyp
);
559 -- Here for normal case where we have enumeration tables, this
562 -- T'Val (Value_Enumeration_NN (typS, typI'Address, Num, X))
565 Ttyp
:= Component_Type
(Etype
(Lit_Indexes
(Rtyp
)));
567 if Ttyp
= Standard_Integer_8
then
568 Func
:= RE_Value_Enumeration_8
;
569 elsif Ttyp
= Standard_Integer_16
then
570 Func
:= RE_Value_Enumeration_16
;
572 Func
:= RE_Value_Enumeration_32
;
576 Make_Attribute_Reference
(Loc
,
577 Prefix
=> New_Occurrence_Of
(Rtyp
, Loc
),
578 Attribute_Name
=> Name_Pos
,
579 Expressions
=> New_List
(
580 Make_Attribute_Reference
(Loc
,
581 Prefix
=> New_Occurrence_Of
(Rtyp
, Loc
),
582 Attribute_Name
=> Name_Last
))));
585 Make_Attribute_Reference
(Loc
,
586 Prefix
=> New_Occurrence_Of
(Lit_Indexes
(Rtyp
), Loc
),
587 Attribute_Name
=> Name_Address
));
590 New_Occurrence_Of
(Lit_Strings
(Rtyp
), Loc
));
593 Make_Attribute_Reference
(Loc
,
594 Prefix
=> New_Reference_To
(Typ
, Loc
),
595 Attribute_Name
=> Name_Val
,
596 Expressions
=> New_List
(
597 Make_Function_Call
(Loc
,
599 New_Reference_To
(RTE
(Func
), Loc
),
600 Parameter_Associations
=> Args
))));
602 Analyze_And_Resolve
(N
, Btyp
);
608 -- Fall through for all cases except user defined enumeration type
609 -- and decimal types, with Vid set to the Id of the entity for the
610 -- Value routine and Args set to the list of parameters for the call.
614 Make_Function_Call
(Loc
,
615 Name
=> New_Reference_To
(RTE
(Vid
), Loc
),
616 Parameter_Associations
=> Args
)));
618 Analyze_And_Resolve
(N
, Btyp
);
619 end Expand_Value_Attribute
;
621 ----------------------------
622 -- Expand_Width_Attribute --
623 ----------------------------
625 -- The processing here also handles the case of Wide_Width. With the
626 -- exceptions noted, the processing is identical
628 -- For scalar types derived from Boolean, character and integer types
629 -- in package Standard. Note that the Width attribute is computed at
630 -- compile time for all cases except those involving non-static sub-
631 -- types. For such subtypes, typ'Width and typ'Wide_Width expands into:
633 -- Result_Type (xx (yy (Ptyp'First), yy (Ptyp'Last)))
637 -- For types whose root type is Character
638 -- xx = Width_Character (Wide_Width_Character for Wide_Width case)
641 -- For types whose root type is Boolean
642 -- xx = Width_Boolean
645 -- For signed integer types
646 -- xx = Width_Long_Long_Integer
647 -- yy = Long_Long_Integer
649 -- For modular integer types
650 -- xx = Width_Long_Long_Unsigned
651 -- yy = Long_Long_Unsigned
653 -- For types derived from Wide_Character, typ'Width expands into
655 -- Result_Type (Width_Wide_Character (
656 -- Wide_Character (typ'First),
657 -- Wide_Character (typ'Last),
658 -- Wide_Character_Encoding_Method);
660 -- and typ'Wide_Width expands into:
662 -- Result_Type (Wide_Width_Wide_Character (
663 -- Wide_Character (typ'First),
664 -- Wide_Character (typ'Last));
666 -- For real types, typ'Width and typ'Wide_Width expand into
668 -- if Ptyp'First > Ptyp'Last then 0 else btyp'Width end if
670 -- where btyp is the base type. This looks recursive but it isn't
671 -- because the base type is always static, and hence the expression
672 -- in the else is reduced to an integer literal.
674 -- For user defined enumeration types, typ'Width expands into
676 -- Result_Type (Width_Enumeration_NN
679 -- typ'Pos (typ'First),
680 -- typ'Pos (Typ'Last)));
682 -- and typ'Wide_Width expands into:
684 -- Result_Type (Wide_Width_Enumeration_NN
687 -- typ'Pos (typ'First),
688 -- typ'Pos (Typ'Last))
689 -- Wide_Character_Encoding_Method);
691 -- where typS and typI are the enumeration image strings and
692 -- indexes table, as described in Build_Enumeration_Image_Tables.
693 -- NN is 8/16/32 for depending on the element type for typI.
695 procedure Expand_Width_Attribute
(N
: Node_Id
; Wide
: Boolean) is
696 Loc
: constant Source_Ptr
:= Sloc
(N
);
697 Typ
: constant Entity_Id
:= Etype
(N
);
698 Pref
: constant Node_Id
:= Prefix
(N
);
699 Ptyp
: constant Entity_Id
:= Etype
(Pref
);
700 Rtyp
: constant Entity_Id
:= Root_Type
(Ptyp
);
707 -- Types derived from Standard.Boolean
709 if Rtyp
= Standard_Boolean
then
710 XX
:= RE_Width_Boolean
;
713 -- Types derived from Standard.Character
715 elsif Rtyp
= Standard_Character
then
717 XX
:= RE_Width_Character
;
719 XX
:= RE_Wide_Width_Character
;
724 -- Types derived from Standard.Wide_Character
726 elsif Rtyp
= Standard_Wide_Character
then
728 XX
:= RE_Width_Wide_Character
;
730 XX
:= RE_Wide_Width_Wide_Character
;
735 -- Signed integer types
737 elsif Is_Signed_Integer_Type
(Rtyp
) then
738 XX
:= RE_Width_Long_Long_Integer
;
739 YY
:= Standard_Long_Long_Integer
;
741 -- Modular integer types
743 elsif Is_Modular_Integer_Type
(Rtyp
) then
744 XX
:= RE_Width_Long_Long_Unsigned
;
745 YY
:= RTE
(RE_Long_Long_Unsigned
);
749 elsif Is_Real_Type
(Rtyp
) then
752 Make_Conditional_Expression
(Loc
,
753 Expressions
=> New_List
(
757 Make_Attribute_Reference
(Loc
,
758 Prefix
=> New_Reference_To
(Ptyp
, Loc
),
759 Attribute_Name
=> Name_First
),
762 Make_Attribute_Reference
(Loc
,
763 Prefix
=> New_Reference_To
(Ptyp
, Loc
),
764 Attribute_Name
=> Name_Last
)),
766 Make_Integer_Literal
(Loc
, 0),
768 Make_Attribute_Reference
(Loc
,
769 Prefix
=> New_Reference_To
(Base_Type
(Ptyp
), Loc
),
770 Attribute_Name
=> Name_Width
))));
772 Analyze_And_Resolve
(N
, Typ
);
775 -- User defined enumeration types
778 pragma Assert
(Is_Enumeration_Type
(Rtyp
));
780 Ttyp
:= Component_Type
(Etype
(Lit_Indexes
(Rtyp
)));
783 if Ttyp
= Standard_Integer_8
then
784 XX
:= RE_Width_Enumeration_8
;
785 elsif Ttyp
= Standard_Integer_16
then
786 XX
:= RE_Width_Enumeration_16
;
788 XX
:= RE_Width_Enumeration_32
;
792 if Ttyp
= Standard_Integer_8
then
793 XX
:= RE_Wide_Width_Enumeration_8
;
794 elsif Ttyp
= Standard_Integer_16
then
795 XX
:= RE_Wide_Width_Enumeration_16
;
797 XX
:= RE_Wide_Width_Enumeration_32
;
803 New_Occurrence_Of
(Lit_Strings
(Rtyp
), Loc
),
805 Make_Attribute_Reference
(Loc
,
806 Prefix
=> New_Occurrence_Of
(Lit_Indexes
(Rtyp
), Loc
),
807 Attribute_Name
=> Name_Address
),
809 Make_Attribute_Reference
(Loc
,
810 Prefix
=> New_Reference_To
(Ptyp
, Loc
),
811 Attribute_Name
=> Name_Pos
,
813 Expressions
=> New_List
(
814 Make_Attribute_Reference
(Loc
,
815 Prefix
=> New_Reference_To
(Ptyp
, Loc
),
816 Attribute_Name
=> Name_First
))),
818 Make_Attribute_Reference
(Loc
,
819 Prefix
=> New_Reference_To
(Ptyp
, Loc
),
820 Attribute_Name
=> Name_Pos
,
822 Expressions
=> New_List
(
823 Make_Attribute_Reference
(Loc
,
824 Prefix
=> New_Reference_To
(Ptyp
, Loc
),
825 Attribute_Name
=> Name_Last
))));
827 -- For enumeration'Wide_Width, add encoding method parameter
831 Make_Integer_Literal
(Loc
,
832 Intval
=> Int
(Wide_Character_Encoding_Method
)));
837 Make_Function_Call
(Loc
,
838 Name
=> New_Reference_To
(RTE
(XX
), Loc
),
839 Parameter_Associations
=> Arglist
)));
841 Analyze_And_Resolve
(N
, Typ
);
845 -- If we fall through XX and YY are set
847 Arglist
:= New_List
(
849 Make_Attribute_Reference
(Loc
,
850 Prefix
=> New_Reference_To
(Ptyp
, Loc
),
851 Attribute_Name
=> Name_First
)),
854 Make_Attribute_Reference
(Loc
,
855 Prefix
=> New_Reference_To
(Ptyp
, Loc
),
856 Attribute_Name
=> Name_Last
)));
858 -- For Wide_Character'Width, add encoding method parameter
860 if Rtyp
= Standard_Wide_Character
and then Wide
then
862 Make_Integer_Literal
(Loc
,
863 Intval
=> Int
(Wide_Character_Encoding_Method
)));
868 Make_Function_Call
(Loc
,
869 Name
=> New_Reference_To
(RTE
(XX
), Loc
),
870 Parameter_Associations
=> Arglist
)));
872 Analyze_And_Resolve
(N
, Typ
);
873 end Expand_Width_Attribute
;