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 Checks
; use Checks
;
29 with Einfo
; use Einfo
;
30 with Elists
; use Elists
;
31 with Exp_Ch2
; use Exp_Ch2
;
32 with Exp_Ch9
; use Exp_Ch9
;
33 with Exp_Imgv
; use Exp_Imgv
;
34 with Exp_Pakd
; use Exp_Pakd
;
35 with Exp_Strm
; use Exp_Strm
;
36 with Exp_Tss
; use Exp_Tss
;
37 with Exp_Util
; use Exp_Util
;
38 with Gnatvsn
; use Gnatvsn
;
39 with Hostparm
; use Hostparm
;
41 with Namet
; use Namet
;
42 with Nmake
; use Nmake
;
43 with Nlists
; use Nlists
;
45 with Restrict
; use Restrict
;
46 with Rident
; use Rident
;
47 with Rtsfind
; use Rtsfind
;
49 with Sem_Ch7
; use Sem_Ch7
;
50 with Sem_Ch8
; use Sem_Ch8
;
51 with Sem_Eval
; use Sem_Eval
;
52 with Sem_Res
; use Sem_Res
;
53 with Sem_Util
; use Sem_Util
;
54 with Sinfo
; use Sinfo
;
55 with Snames
; use Snames
;
56 with Stand
; use Stand
;
57 with Stringt
; use Stringt
;
58 with Tbuild
; use Tbuild
;
59 with Ttypes
; use Ttypes
;
60 with Uintp
; use Uintp
;
61 with Uname
; use Uname
;
62 with Validsw
; use Validsw
;
64 package body Exp_Attr
is
66 -----------------------
67 -- Local Subprograms --
68 -----------------------
70 procedure Compile_Stream_Body_In_Scope
75 -- The body for a stream subprogram may be generated outside of the scope
76 -- of the type. If the type is fully private, it may depend on the full
77 -- view of other types (e.g. indices) that are currently private as well.
78 -- We install the declarations of the package in which the type is declared
79 -- before compiling the body in what is its proper environment. The Check
80 -- parameter indicates if checks are to be suppressed for the stream body.
81 -- We suppress checks for array/record reads, since the rule is that these
82 -- are like assignments, out of range values due to uninitialized storage,
83 -- or other invalid values do NOT cause a Constraint_Error to be raised.
85 procedure Expand_Fpt_Attribute
90 -- This procedure expands a call to a floating-point attribute function.
91 -- N is the attribute reference node, and Args is a list of arguments to
92 -- be passed to the function call. Rtp is the root type of the floating
93 -- point type involved (used to select the proper generic instantiation
94 -- of the package containing the attribute routines). The Nam argument
95 -- is the attribute processing routine to be called. This is normally
96 -- the same as the attribute name, except in the Unaligned_Valid case.
98 procedure Expand_Fpt_Attribute_R
(N
: Node_Id
);
99 -- This procedure expands a call to a floating-point attribute function
100 -- that takes a single floating-point argument. The function to be called
101 -- is always the same as the attribute name.
103 procedure Expand_Fpt_Attribute_RI
(N
: Node_Id
);
104 -- This procedure expands a call to a floating-point attribute function
105 -- that takes one floating-point argument and one integer argument. The
106 -- function to be called is always the same as the attribute name.
108 procedure Expand_Fpt_Attribute_RR
(N
: Node_Id
);
109 -- This procedure expands a call to a floating-point attribute function
110 -- that takes two floating-point arguments. The function to be called
111 -- is always the same as the attribute name.
113 procedure Expand_Pred_Succ
(N
: Node_Id
);
114 -- Handles expansion of Pred or Succ attributes for case of non-real
115 -- operand with overflow checking required.
117 function Get_Index_Subtype
(N
: Node_Id
) return Entity_Id
;
118 -- Used for Last, Last, and Length, when the prefix is an array type,
119 -- Obtains the corresponding index subtype.
121 procedure Expand_Access_To_Type
(N
: Node_Id
);
122 -- A reference to a type within its own scope is resolved to a reference
123 -- to the current instance of the type in its initialization procedure.
125 function Find_Inherited_TSS
127 Nam
: TSS_Name_Type
) return Entity_Id
;
128 -- Returns the TSS of name Nam of Typ, or of its closest ancestor defining
129 -- such a TSS. Empty is returned is neither Typ nor any of its ancestors
132 function Find_Stream_Subprogram
134 Nam
: TSS_Name_Type
) return Entity_Id
;
135 -- Returns the stream-oriented subprogram attribute for Typ. For tagged
136 -- types, the corresponding primitive operation is looked up, else the
137 -- appropriate TSS from the type itself, or from its closest ancestor
138 -- defining it, is returned. In both cases, inheritance of representation
139 -- aspects is thus taken into account.
141 function Is_Constrained_Packed_Array
(Typ
: Entity_Id
) return Boolean;
142 -- Utility for array attributes, returns true on packed constrained
143 -- arrays, and on access to same.
145 ----------------------------------
146 -- Compile_Stream_Body_In_Scope --
147 ----------------------------------
149 procedure Compile_Stream_Body_In_Scope
155 Installed
: Boolean := False;
156 Scop
: constant Entity_Id
:= Scope
(Arr
);
157 Curr
: constant Entity_Id
:= Current_Scope
;
161 and then not In_Open_Scopes
(Scop
)
162 and then Ekind
(Scop
) = E_Package
165 Install_Visible_Declarations
(Scop
);
166 Install_Private_Declarations
(Scop
);
169 -- The entities in the package are now visible, but the generated
170 -- stream entity must appear in the current scope (usually an
171 -- enclosing stream function) so that itypes all have their proper
178 Insert_Action
(N
, Decl
);
180 Insert_Action
(N
, Decl
, All_Checks
);
185 -- Remove extra copy of current scope, and package itself
188 End_Package_Scope
(Scop
);
190 end Compile_Stream_Body_In_Scope
;
192 ---------------------------
193 -- Expand_Access_To_Type --
194 ---------------------------
196 procedure Expand_Access_To_Type
(N
: Node_Id
) is
197 Loc
: constant Source_Ptr
:= Sloc
(N
);
198 Typ
: constant Entity_Id
:= Etype
(N
);
199 Pref
: constant Node_Id
:= Prefix
(N
);
204 if Is_Entity_Name
(Pref
)
205 and then Is_Type
(Entity
(Pref
))
207 -- If the current instance name denotes a task type,
208 -- then the access attribute is rewritten to be the
209 -- name of the "_task" parameter associated with the
210 -- task type's task body procedure. An unchecked
211 -- conversion is applied to ensure a type match in
212 -- cases of expander-generated calls (e.g., init procs).
214 if Is_Task_Type
(Entity
(Pref
)) then
216 First_Entity
(Get_Task_Body_Procedure
(Entity
(Pref
)));
218 while Present
(Formal
) loop
219 exit when Chars
(Formal
) = Name_uTask
;
220 Next_Entity
(Formal
);
223 pragma Assert
(Present
(Formal
));
226 Unchecked_Convert_To
(Typ
, New_Occurrence_Of
(Formal
, Loc
)));
229 -- The expression must appear in a default expression,
230 -- (which in the initialization procedure is the rhs of
231 -- an assignment), and not in a discriminant constraint.
236 while Present
(Par
) loop
237 exit when Nkind
(Par
) = N_Assignment_Statement
;
239 if Nkind
(Par
) = N_Component_Declaration
then
246 if Present
(Par
) then
248 Make_Attribute_Reference
(Loc
,
249 Prefix
=> Make_Identifier
(Loc
, Name_uInit
),
250 Attribute_Name
=> Attribute_Name
(N
)));
252 Analyze_And_Resolve
(N
, Typ
);
256 end Expand_Access_To_Type
;
258 --------------------------
259 -- Expand_Fpt_Attribute --
260 --------------------------
262 procedure Expand_Fpt_Attribute
268 Loc
: constant Source_Ptr
:= Sloc
(N
);
269 Typ
: constant Entity_Id
:= Etype
(N
);
274 -- The function name is the selected component Fat_xxx.yyy where xxx
275 -- is the floating-point root type, and yyy is the argument Nam.
277 -- Note: it would be more usual to have separate RE entries for each
278 -- of the entities in the Fat packages, but first they have identical
279 -- names (so we would have to have lots of renaming declarations to
280 -- meet the normal RE rule of separate names for all runtime entities),
281 -- and second there would be an awful lot of them!
283 if Rtp
= Standard_Short_Float
then
284 Pkg
:= RE_Fat_Short_Float
;
285 elsif Rtp
= Standard_Float
then
287 elsif Rtp
= Standard_Long_Float
then
288 Pkg
:= RE_Fat_Long_Float
;
290 Pkg
:= RE_Fat_Long_Long_Float
;
294 Make_Selected_Component
(Loc
,
295 Prefix
=> New_Reference_To
(RTE
(Pkg
), Loc
),
296 Selector_Name
=> Make_Identifier
(Loc
, Nam
));
298 -- The generated call is given the provided set of parameters, and then
299 -- wrapped in a conversion which converts the result to the target type
302 Unchecked_Convert_To
(Etype
(N
),
303 Make_Function_Call
(Loc
,
305 Parameter_Associations
=> Args
)));
307 Analyze_And_Resolve
(N
, Typ
);
308 end Expand_Fpt_Attribute
;
310 ----------------------------
311 -- Expand_Fpt_Attribute_R --
312 ----------------------------
314 -- The single argument is converted to its root type to call the
315 -- appropriate runtime function, with the actual call being built
316 -- by Expand_Fpt_Attribute
318 procedure Expand_Fpt_Attribute_R
(N
: Node_Id
) is
319 E1
: constant Node_Id
:= First
(Expressions
(N
));
320 Rtp
: constant Entity_Id
:= Root_Type
(Etype
(E1
));
324 (N
, Rtp
, Attribute_Name
(N
),
325 New_List
(Unchecked_Convert_To
(Rtp
, Relocate_Node
(E1
))));
326 end Expand_Fpt_Attribute_R
;
328 -----------------------------
329 -- Expand_Fpt_Attribute_RI --
330 -----------------------------
332 -- The first argument is converted to its root type and the second
333 -- argument is converted to standard long long integer to call the
334 -- appropriate runtime function, with the actual call being built
335 -- by Expand_Fpt_Attribute
337 procedure Expand_Fpt_Attribute_RI
(N
: Node_Id
) is
338 E1
: constant Node_Id
:= First
(Expressions
(N
));
339 Rtp
: constant Entity_Id
:= Root_Type
(Etype
(E1
));
340 E2
: constant Node_Id
:= Next
(E1
);
344 (N
, Rtp
, Attribute_Name
(N
),
346 Unchecked_Convert_To
(Rtp
, Relocate_Node
(E1
)),
347 Unchecked_Convert_To
(Standard_Integer
, Relocate_Node
(E2
))));
348 end Expand_Fpt_Attribute_RI
;
350 -----------------------------
351 -- Expand_Fpt_Attribute_RR --
352 -----------------------------
354 -- The two arguments is converted to their root types to call the
355 -- appropriate runtime function, with the actual call being built
356 -- by Expand_Fpt_Attribute
358 procedure Expand_Fpt_Attribute_RR
(N
: Node_Id
) is
359 E1
: constant Node_Id
:= First
(Expressions
(N
));
360 Rtp
: constant Entity_Id
:= Root_Type
(Etype
(E1
));
361 E2
: constant Node_Id
:= Next
(E1
);
365 (N
, Rtp
, Attribute_Name
(N
),
367 Unchecked_Convert_To
(Rtp
, Relocate_Node
(E1
)),
368 Unchecked_Convert_To
(Rtp
, Relocate_Node
(E2
))));
369 end Expand_Fpt_Attribute_RR
;
371 ----------------------------------
372 -- Expand_N_Attribute_Reference --
373 ----------------------------------
375 procedure Expand_N_Attribute_Reference
(N
: Node_Id
) is
376 Loc
: constant Source_Ptr
:= Sloc
(N
);
377 Typ
: constant Entity_Id
:= Etype
(N
);
378 Btyp
: constant Entity_Id
:= Base_Type
(Typ
);
379 Pref
: constant Node_Id
:= Prefix
(N
);
380 Exprs
: constant List_Id
:= Expressions
(N
);
381 Id
: constant Attribute_Id
:= Get_Attribute_Id
(Attribute_Name
(N
));
383 procedure Rewrite_Stream_Proc_Call
(Pname
: Entity_Id
);
384 -- Rewrites a stream attribute for Read, Write or Output with the
385 -- procedure call. Pname is the entity for the procedure to call.
387 ------------------------------
388 -- Rewrite_Stream_Proc_Call --
389 ------------------------------
391 procedure Rewrite_Stream_Proc_Call
(Pname
: Entity_Id
) is
392 Item
: constant Node_Id
:= Next
(First
(Exprs
));
393 Formal
: constant Entity_Id
:= Next_Formal
(First_Formal
(Pname
));
394 Formal_Typ
: constant Entity_Id
:= Etype
(Formal
);
395 Is_Written
: constant Boolean := (Ekind
(Formal
) /= E_In_Parameter
);
398 -- The expansion depends on Item, the second actual, which is
399 -- the object being streamed in or out.
401 -- If the item is a component of a packed array type, and
402 -- a conversion is needed on exit, we introduce a temporary to
403 -- hold the value, because otherwise the packed reference will
404 -- not be properly expanded.
406 if Nkind
(Item
) = N_Indexed_Component
407 and then Is_Packed
(Base_Type
(Etype
(Prefix
(Item
))))
408 and then Base_Type
(Etype
(Item
)) /= Base_Type
(Formal_Typ
)
412 Temp
: constant Entity_Id
:=
413 Make_Defining_Identifier
414 (Loc
, New_Internal_Name
('V'));
420 Make_Object_Declaration
(Loc
,
421 Defining_Identifier
=> Temp
,
423 New_Occurrence_Of
(Formal_Typ
, Loc
));
424 Set_Etype
(Temp
, Formal_Typ
);
427 Make_Assignment_Statement
(Loc
,
428 Name
=> New_Copy_Tree
(Item
),
431 (Etype
(Item
), New_Occurrence_Of
(Temp
, Loc
)));
433 Rewrite
(Item
, New_Occurrence_Of
(Temp
, Loc
));
437 Make_Procedure_Call_Statement
(Loc
,
438 Name
=> New_Occurrence_Of
(Pname
, Loc
),
439 Parameter_Associations
=> Exprs
),
442 Rewrite
(N
, Make_Null_Statement
(Loc
));
447 -- For the class-wide dispatching cases, and for cases in which
448 -- the base type of the second argument matches the base type of
449 -- the corresponding formal parameter (that is to say the stream
450 -- operation is not inherited), we are all set, and can use the
451 -- argument unchanged.
453 -- For all other cases we do an unchecked conversion of the second
454 -- parameter to the type of the formal of the procedure we are
455 -- calling. This deals with the private type cases, and with going
456 -- to the root type as required in elementary type case.
458 if not Is_Class_Wide_Type
(Entity
(Pref
))
459 and then not Is_Class_Wide_Type
(Etype
(Item
))
460 and then Base_Type
(Etype
(Item
)) /= Base_Type
(Formal_Typ
)
463 Unchecked_Convert_To
(Formal_Typ
, Relocate_Node
(Item
)));
465 -- For untagged derived types set Assignment_OK, to prevent
466 -- copies from being created when the unchecked conversion
467 -- is expanded (which would happen in Remove_Side_Effects
468 -- if Expand_N_Unchecked_Conversion were allowed to call
469 -- Force_Evaluation). The copy could violate Ada semantics
470 -- in cases such as an actual that is an out parameter.
471 -- Note that this approach is also used in exp_ch7 for calls
472 -- to controlled type operations to prevent problems with
473 -- actuals wrapped in unchecked conversions.
475 if Is_Untagged_Derivation
(Etype
(Expression
(Item
))) then
476 Set_Assignment_OK
(Item
);
480 -- And now rewrite the call
483 Make_Procedure_Call_Statement
(Loc
,
484 Name
=> New_Occurrence_Of
(Pname
, Loc
),
485 Parameter_Associations
=> Exprs
));
488 end Rewrite_Stream_Proc_Call
;
490 -- Start of processing for Expand_N_Attribute_Reference
493 -- Do required validity checking
495 if Validity_Checks_On
and Validity_Check_Operands
then
500 Expr
:= First
(Expressions
(N
));
501 while Present
(Expr
) loop
508 -- Remaining processing depends on specific attribute
516 when Attribute_Access
=>
518 if Ekind
(Btyp
) = E_Access_Protected_Subprogram_Type
then
520 -- The value of the attribute_reference is a record containing
521 -- two fields: an access to the protected object, and an access
522 -- to the subprogram itself. The prefix is a selected component.
527 E_T
: constant Entity_Id
:= Equivalent_Type
(Btyp
);
528 Acc
: constant Entity_Id
:=
529 Etype
(Next_Component
(First_Component
(E_T
)));
534 -- Within the body of the protected type, the prefix
535 -- designates a local operation, and the object is the first
536 -- parameter of the corresponding protected body of the
537 -- current enclosing operation.
539 if Is_Entity_Name
(Pref
) then
540 pragma Assert
(In_Open_Scopes
(Scope
(Entity
(Pref
))));
543 (Protected_Body_Subprogram
(Entity
(Pref
)), Loc
);
544 Curr
:= Current_Scope
;
546 while Scope
(Curr
) /= Scope
(Entity
(Pref
)) loop
547 Curr
:= Scope
(Curr
);
551 Make_Attribute_Reference
(Loc
,
555 (Protected_Body_Subprogram
(Curr
)), Loc
),
556 Attribute_Name
=> Name_Address
);
558 -- Case where the prefix is not an entity name. Find the
559 -- version of the protected operation to be called from
560 -- outside the protected object.
566 (Entity
(Selector_Name
(Pref
))), Loc
);
569 Make_Attribute_Reference
(Loc
,
570 Prefix
=> Relocate_Node
(Prefix
(Pref
)),
571 Attribute_Name
=> Name_Address
);
579 Unchecked_Convert_To
(Acc
,
580 Make_Attribute_Reference
(Loc
,
582 Attribute_Name
=> Name_Address
))));
586 Analyze_And_Resolve
(N
, E_T
);
588 -- For subsequent analysis, the node must retain its type.
589 -- The backend will replace it with the equivalent type where
595 elsif Ekind
(Btyp
) = E_General_Access_Type
then
597 Ref_Object
: constant Node_Id
:= Get_Referenced_Object
(Pref
);
598 Parm_Ent
: Entity_Id
;
599 Conversion
: Node_Id
;
602 -- If the prefix of an Access attribute is a dereference of an
603 -- access parameter (or a renaming of such a dereference) and
604 -- the context is a general access type (but not an anonymous
605 -- access type), then rewrite the attribute as a conversion of
606 -- the access parameter to the context access type. This will
607 -- result in an accessibility check being performed, if needed.
609 -- (X.all'Access => Acc_Type (X))
611 if Nkind
(Ref_Object
) = N_Explicit_Dereference
612 and then Is_Entity_Name
(Prefix
(Ref_Object
))
614 Parm_Ent
:= Entity
(Prefix
(Ref_Object
));
616 if Ekind
(Parm_Ent
) in Formal_Kind
617 and then Ekind
(Etype
(Parm_Ent
)) = E_Anonymous_Access_Type
618 and then Present
(Extra_Accessibility
(Parm_Ent
))
621 Convert_To
(Typ
, New_Copy_Tree
(Prefix
(Ref_Object
)));
623 Rewrite
(N
, Conversion
);
624 Analyze_And_Resolve
(N
, Typ
);
629 -- If the prefix is a type name, this is a reference to the current
630 -- instance of the type, within its initialization procedure.
633 Expand_Access_To_Type
(N
);
640 -- Transforms 'Adjacent into a call to the floating-point attribute
641 -- function Adjacent in Fat_xxx (where xxx is the root type)
643 when Attribute_Adjacent
=>
644 Expand_Fpt_Attribute_RR
(N
);
650 when Attribute_Address
=> Address
: declare
651 Task_Proc
: Entity_Id
;
654 -- If the prefix is a task or a task type, the useful address
655 -- is that of the procedure for the task body, i.e. the actual
656 -- program unit. We replace the original entity with that of
659 if Is_Entity_Name
(Pref
)
660 and then Is_Task_Type
(Entity
(Pref
))
662 Task_Proc
:= Next_Entity
(Root_Type
(Etype
(Pref
)));
664 while Present
(Task_Proc
) loop
665 exit when Ekind
(Task_Proc
) = E_Procedure
666 and then Etype
(First_Formal
(Task_Proc
)) =
667 Corresponding_Record_Type
(Etype
(Pref
));
668 Next_Entity
(Task_Proc
);
671 if Present
(Task_Proc
) then
672 Set_Entity
(Pref
, Task_Proc
);
673 Set_Etype
(Pref
, Etype
(Task_Proc
));
676 -- Similarly, the address of a protected operation is the address
677 -- of the corresponding protected body, regardless of the protected
678 -- object from which it is selected.
680 elsif Nkind
(Pref
) = N_Selected_Component
681 and then Is_Subprogram
(Entity
(Selector_Name
(Pref
)))
682 and then Is_Protected_Type
(Scope
(Entity
(Selector_Name
(Pref
))))
686 External_Subprogram
(Entity
(Selector_Name
(Pref
))), Loc
));
688 elsif Nkind
(Pref
) = N_Explicit_Dereference
689 and then Ekind
(Etype
(Pref
)) = E_Subprogram_Type
690 and then Convention
(Etype
(Pref
)) = Convention_Protected
692 -- The prefix is be a dereference of an access_to_protected_
693 -- subprogram. The desired address is the second component of
694 -- the record that represents the access.
697 Addr
: constant Entity_Id
:= Etype
(N
);
698 Ptr
: constant Node_Id
:= Prefix
(Pref
);
699 T
: constant Entity_Id
:=
700 Equivalent_Type
(Base_Type
(Etype
(Ptr
)));
704 Unchecked_Convert_To
(Addr
,
705 Make_Selected_Component
(Loc
,
706 Prefix
=> Unchecked_Convert_To
(T
, Ptr
),
707 Selector_Name
=> New_Occurrence_Of
(
708 Next_Entity
(First_Entity
(T
)), Loc
))));
710 Analyze_And_Resolve
(N
, Addr
);
714 -- Deal with packed array reference, other cases are handled by gigi
716 if Involves_Packed_Array_Reference
(Pref
) then
717 Expand_Packed_Address_Reference
(N
);
725 when Attribute_Alignment
=> Alignment
: declare
726 Ptyp
: constant Entity_Id
:= Etype
(Pref
);
730 -- For class-wide types, X'Class'Alignment is transformed into a
731 -- direct reference to the Alignment of the class type, so that the
732 -- back end does not have to deal with the X'Class'Alignment
735 if Is_Entity_Name
(Pref
)
736 and then Is_Class_Wide_Type
(Entity
(Pref
))
738 Rewrite
(Prefix
(N
), New_Occurrence_Of
(Entity
(Pref
), Loc
));
741 -- For x'Alignment applied to an object of a class wide type,
742 -- transform X'Alignment into a call to the predefined primitive
743 -- operation _Alignment applied to X.
745 elsif Is_Class_Wide_Type
(Ptyp
) then
747 Make_Function_Call
(Loc
,
748 Name
=> New_Reference_To
749 (Find_Prim_Op
(Ptyp
, Name_uAlignment
), Loc
),
750 Parameter_Associations
=> New_List
(Pref
));
752 if Typ
/= Standard_Integer
then
754 -- The context is a specific integer type with which the
755 -- original attribute was compatible. The function has a
756 -- specific type as well, so to preserve the compatibility
757 -- we must convert explicitly.
759 New_Node
:= Convert_To
(Typ
, New_Node
);
762 Rewrite
(N
, New_Node
);
763 Analyze_And_Resolve
(N
, Typ
);
766 -- For all other cases, we just have to deal with the case of
767 -- the fact that the result can be universal.
770 Apply_Universal_Integer_Attribute_Checks
(N
);
778 when Attribute_AST_Entry
=> AST_Entry
: declare
784 -- The reference to the entry or entry family
787 -- The index expression for an entry family reference, or
788 -- the Empty if Entry_Ref references a simple entry.
791 if Nkind
(Pref
) = N_Indexed_Component
then
792 Entry_Ref
:= Prefix
(Pref
);
793 Index
:= First
(Expressions
(Pref
));
799 -- Get expression for Task_Id and the entry entity
801 if Nkind
(Entry_Ref
) = N_Selected_Component
then
803 Make_Attribute_Reference
(Loc
,
804 Attribute_Name
=> Name_Identity
,
805 Prefix
=> Prefix
(Entry_Ref
));
807 Ttyp
:= Etype
(Prefix
(Entry_Ref
));
808 Eent
:= Entity
(Selector_Name
(Entry_Ref
));
812 Make_Function_Call
(Loc
,
813 Name
=> New_Occurrence_Of
(RTE
(RE_Current_Task
), Loc
));
815 Eent
:= Entity
(Entry_Ref
);
817 -- We have to find the enclosing task to get the task type
818 -- There must be one, since we already validated this earlier
820 Ttyp
:= Current_Scope
;
821 while not Is_Task_Type
(Ttyp
) loop
822 Ttyp
:= Scope
(Ttyp
);
826 -- Now rewrite the attribute with a call to Create_AST_Handler
829 Make_Function_Call
(Loc
,
830 Name
=> New_Occurrence_Of
(RTE
(RE_Create_AST_Handler
), Loc
),
831 Parameter_Associations
=> New_List
(
833 Entry_Index_Expression
(Loc
, Eent
, Index
, Ttyp
))));
835 Analyze_And_Resolve
(N
, RTE
(RE_AST_Handler
));
842 -- We compute this if a component clause was present, otherwise
843 -- we leave the computation up to Gigi, since we don't know what
844 -- layout will be chosen.
846 -- Note that the attribute can apply to a naked record component
847 -- in generated code (i.e. the prefix is an identifier that
848 -- references the component or discriminant entity).
850 when Attribute_Bit_Position
=> Bit_Position
:
855 if Nkind
(Pref
) = N_Identifier
then
858 CE
:= Entity
(Selector_Name
(Pref
));
861 if Known_Static_Component_Bit_Offset
(CE
) then
863 Make_Integer_Literal
(Loc
,
864 Intval
=> Component_Bit_Offset
(CE
)));
865 Analyze_And_Resolve
(N
, Typ
);
868 Apply_Universal_Integer_Attribute_Checks
(N
);
876 -- A reference to P'Body_Version or P'Version is expanded to
879 -- pragma Import (C, Vnn, "uuuuT";
881 -- Get_Version_String (Vnn)
883 -- where uuuu is the unit name (dots replaced by double underscore)
884 -- and T is B for the cases of Body_Version, or Version applied to a
885 -- subprogram acting as its own spec, and S for Version applied to a
886 -- subprogram spec or package. This sequence of code references the
887 -- the unsigned constant created in the main program by the binder.
889 -- A special exception occurs for Standard, where the string
890 -- returned is a copy of the library string in gnatvsn.ads.
892 when Attribute_Body_Version | Attribute_Version
=> Version
: declare
893 E
: constant Entity_Id
:=
894 Make_Defining_Identifier
(Loc
, New_Internal_Name
('V'));
895 Pent
: Entity_Id
:= Entity
(Pref
);
899 -- If not library unit, get to containing library unit
901 while Pent
/= Standard_Standard
902 and then Scope
(Pent
) /= Standard_Standard
904 Pent
:= Scope
(Pent
);
907 -- Special case Standard
909 if Pent
= Standard_Standard
910 or else Pent
= Standard_ASCII
912 Name_Buffer
(1 .. Verbose_Library_Version
'Length) :=
913 Verbose_Library_Version
;
914 Name_Len
:= Verbose_Library_Version
'Length;
916 Make_String_Literal
(Loc
,
917 Strval
=> String_From_Name_Buffer
));
922 -- Build required string constant
924 Get_Name_String
(Get_Unit_Name
(Pent
));
927 for J
in 1 .. Name_Len
- 2 loop
928 if Name_Buffer
(J
) = '.' then
929 Store_String_Chars
("__");
931 Store_String_Char
(Get_Char_Code
(Name_Buffer
(J
)));
935 -- Case of subprogram acting as its own spec, always use body
937 if Nkind
(Declaration_Node
(Pent
)) in N_Subprogram_Specification
938 and then Nkind
(Parent
(Declaration_Node
(Pent
))) =
940 and then Acts_As_Spec
(Parent
(Declaration_Node
(Pent
)))
942 Store_String_Chars
("B");
944 -- Case of no body present, always use spec
946 elsif not Unit_Requires_Body
(Pent
) then
947 Store_String_Chars
("S");
949 -- Otherwise use B for Body_Version, S for spec
951 elsif Id
= Attribute_Body_Version
then
952 Store_String_Chars
("B");
954 Store_String_Chars
("S");
958 Lib
.Version_Referenced
(S
);
960 -- Insert the object declaration
962 Insert_Actions
(N
, New_List
(
963 Make_Object_Declaration
(Loc
,
964 Defining_Identifier
=> E
,
966 New_Occurrence_Of
(RTE
(RE_Unsigned
), Loc
))));
968 -- Set entity as imported with correct external name
971 Set_Interface_Name
(E
, Make_String_Literal
(Loc
, S
));
973 -- And now rewrite original reference
976 Make_Function_Call
(Loc
,
977 Name
=> New_Reference_To
(RTE
(RE_Get_Version_String
), Loc
),
978 Parameter_Associations
=> New_List
(
979 New_Occurrence_Of
(E
, Loc
))));
982 Analyze_And_Resolve
(N
, RTE
(RE_Version_String
));
989 -- Transforms 'Ceiling into a call to the floating-point attribute
990 -- function Ceiling in Fat_xxx (where xxx is the root type)
992 when Attribute_Ceiling
=>
993 Expand_Fpt_Attribute_R
(N
);
999 -- Transforms 'Callable attribute into a call to the Callable function.
1001 when Attribute_Callable
=> Callable
:
1004 Build_Call_With_Task
(Pref
, RTE
(RE_Callable
)));
1005 Analyze_And_Resolve
(N
, Standard_Boolean
);
1012 -- Transforms 'Caller attribute into a call to either the
1013 -- Task_Entry_Caller or the Protected_Entry_Caller function.
1015 when Attribute_Caller
=> Caller
: declare
1016 Id_Kind
: constant Entity_Id
:= RTE
(RO_AT_Task_Id
);
1017 Ent
: constant Entity_Id
:= Entity
(Pref
);
1018 Conctype
: constant Entity_Id
:= Scope
(Ent
);
1019 Nest_Depth
: Integer := 0;
1026 if Is_Protected_Type
(Conctype
) then
1028 or else Restriction_Active
(No_Entry_Queue
) = False
1029 or else Number_Entries
(Conctype
) > 1
1033 (RTE
(RE_Protected_Entry_Caller
), Loc
);
1037 (RTE
(RE_Protected_Single_Entry_Caller
), Loc
);
1041 Unchecked_Convert_To
(Id_Kind
,
1042 Make_Function_Call
(Loc
,
1044 Parameter_Associations
=> New_List
1047 (Corresponding_Body
(Parent
(Conctype
))), Loc
)))));
1052 -- Determine the nesting depth of the E'Caller attribute, that
1053 -- is, how many accept statements are nested within the accept
1054 -- statement for E at the point of E'Caller. The runtime uses
1055 -- this depth to find the specified entry call.
1057 for J
in reverse 0 .. Scope_Stack
.Last
loop
1058 S
:= Scope_Stack
.Table
(J
).Entity
;
1060 -- We should not reach the scope of the entry, as it should
1061 -- already have been checked in Sem_Attr that this attribute
1062 -- reference is within a matching accept statement.
1064 pragma Assert
(S
/= Conctype
);
1069 elsif Is_Entry
(S
) then
1070 Nest_Depth
:= Nest_Depth
+ 1;
1075 Unchecked_Convert_To
(Id_Kind
,
1076 Make_Function_Call
(Loc
,
1077 Name
=> New_Reference_To
(
1078 RTE
(RE_Task_Entry_Caller
), Loc
),
1079 Parameter_Associations
=> New_List
(
1080 Make_Integer_Literal
(Loc
,
1081 Intval
=> Int
(Nest_Depth
))))));
1084 Analyze_And_Resolve
(N
, Id_Kind
);
1091 -- Transforms 'Compose into a call to the floating-point attribute
1092 -- function Compose in Fat_xxx (where xxx is the root type)
1094 -- Note: we strictly should have special code here to deal with the
1095 -- case of absurdly negative arguments (less than Integer'First)
1096 -- which will return a (signed) zero value, but it hardly seems
1097 -- worth the effort. Absurdly large positive arguments will raise
1098 -- constraint error which is fine.
1100 when Attribute_Compose
=>
1101 Expand_Fpt_Attribute_RI
(N
);
1107 when Attribute_Constrained
=> Constrained
: declare
1108 Formal_Ent
: constant Entity_Id
:= Param_Entity
(Pref
);
1111 -- Reference to a parameter where the value is passed as an extra
1112 -- actual, corresponding to the extra formal referenced by the
1113 -- Extra_Constrained field of the corresponding formal. If this
1114 -- is an entry in-parameter, it is replaced by a constant renaming
1115 -- for which Extra_Constrained is never created.
1117 if Present
(Formal_Ent
)
1118 and then Ekind
(Formal_Ent
) /= E_Constant
1119 and then Present
(Extra_Constrained
(Formal_Ent
))
1123 (Extra_Constrained
(Formal_Ent
), Sloc
(N
)));
1125 -- For variables with a Extra_Constrained field, we use the
1126 -- corresponding entity.
1128 elsif Nkind
(Pref
) = N_Identifier
1129 and then Ekind
(Entity
(Pref
)) = E_Variable
1130 and then Present
(Extra_Constrained
(Entity
(Pref
)))
1134 (Extra_Constrained
(Entity
(Pref
)), Sloc
(N
)));
1136 -- For all other entity names, we can tell at compile time
1138 elsif Is_Entity_Name
(Pref
) then
1140 Ent
: constant Entity_Id
:= Entity
(Pref
);
1144 -- (RM J.4) obsolescent cases
1146 if Is_Type
(Ent
) then
1150 if Is_Private_Type
(Ent
) then
1151 Res
:= not Has_Discriminants
(Ent
)
1152 or else Is_Constrained
(Ent
);
1154 -- It not a private type, must be a generic actual type
1155 -- that corresponded to a private type. We know that this
1156 -- correspondence holds, since otherwise the reference
1157 -- within the generic template would have been illegal.
1160 if Is_Composite_Type
(Underlying_Type
(Ent
)) then
1161 Res
:= Is_Constrained
(Ent
);
1167 -- If the prefix is not a variable or is aliased, then
1168 -- definitely true; if it's a formal parameter without
1169 -- an associated extra formal, then treat it as constrained.
1171 elsif not Is_Variable
(Pref
)
1172 or else Present
(Formal_Ent
)
1173 or else Is_Aliased_View
(Pref
)
1177 -- Variable case, just look at type to see if it is
1178 -- constrained. Note that the one case where this is
1179 -- not accurate (the procedure formal case), has been
1183 Res
:= Is_Constrained
(Etype
(Ent
));
1187 New_Reference_To
(Boolean_Literals
(Res
), Loc
));
1190 -- Prefix is not an entity name. These are also cases where
1191 -- we can always tell at compile time by looking at the form
1192 -- and type of the prefix.
1198 not Is_Variable
(Pref
)
1199 or else Nkind
(Pref
) = N_Explicit_Dereference
1200 or else Is_Constrained
(Etype
(Pref
))),
1204 Analyze_And_Resolve
(N
, Standard_Boolean
);
1211 -- Transforms 'Copy_Sign into a call to the floating-point attribute
1212 -- function Copy_Sign in Fat_xxx (where xxx is the root type)
1214 when Attribute_Copy_Sign
=>
1215 Expand_Fpt_Attribute_RR
(N
);
1221 -- Transforms 'Count attribute into a call to the Count function
1223 when Attribute_Count
=> Count
:
1229 Conctyp
: Entity_Id
;
1232 -- If the prefix is a member of an entry family, retrieve both
1233 -- entry name and index. For a simple entry there is no index.
1235 if Nkind
(Pref
) = N_Indexed_Component
then
1236 Entnam
:= Prefix
(Pref
);
1237 Index
:= First
(Expressions
(Pref
));
1243 -- Find the concurrent type in which this attribute is referenced
1244 -- (there had better be one).
1246 Conctyp
:= Current_Scope
;
1247 while not Is_Concurrent_Type
(Conctyp
) loop
1248 Conctyp
:= Scope
(Conctyp
);
1253 if Is_Protected_Type
(Conctyp
) then
1256 or else Restriction_Active
(No_Entry_Queue
) = False
1257 or else Number_Entries
(Conctyp
) > 1
1259 Name
:= New_Reference_To
(RTE
(RE_Protected_Count
), Loc
);
1262 Make_Function_Call
(Loc
,
1264 Parameter_Associations
=> New_List
(
1267 Corresponding_Body
(Parent
(Conctyp
))), Loc
),
1268 Entry_Index_Expression
(
1269 Loc
, Entity
(Entnam
), Index
, Scope
(Entity
(Entnam
)))));
1271 Name
:= New_Reference_To
(RTE
(RE_Protected_Count_Entry
), Loc
);
1273 Call
:= Make_Function_Call
(Loc
,
1275 Parameter_Associations
=> New_List
(
1278 Corresponding_Body
(Parent
(Conctyp
))), Loc
)));
1285 Make_Function_Call
(Loc
,
1286 Name
=> New_Reference_To
(RTE
(RE_Task_Count
), Loc
),
1287 Parameter_Associations
=> New_List
(
1288 Entry_Index_Expression
1289 (Loc
, Entity
(Entnam
), Index
, Scope
(Entity
(Entnam
)))));
1292 -- The call returns type Natural but the context is universal integer
1293 -- so any integer type is allowed. The attribute was already resolved
1294 -- so its Etype is the required result type. If the base type of the
1295 -- context type is other than Standard.Integer we put in a conversion
1296 -- to the required type. This can be a normal typed conversion since
1297 -- both input and output types of the conversion are integer types
1299 if Base_Type
(Typ
) /= Base_Type
(Standard_Integer
) then
1300 Rewrite
(N
, Convert_To
(Typ
, Call
));
1305 Analyze_And_Resolve
(N
, Typ
);
1312 -- This processing is shared by Elab_Spec
1314 -- What we do is to insert the following declarations
1317 -- pragma Import (C, enn, "name___elabb/s");
1319 -- and then the Elab_Body/Spec attribute is replaced by a reference
1320 -- to this defining identifier.
1322 when Attribute_Elab_Body |
1323 Attribute_Elab_Spec
=>
1326 Ent
: constant Entity_Id
:=
1327 Make_Defining_Identifier
(Loc
,
1328 New_Internal_Name
('E'));
1332 procedure Make_Elab_String
(Nod
: Node_Id
);
1333 -- Given Nod, an identifier, or a selected component, put the
1334 -- image into the current string literal, with double underline
1335 -- between components.
1337 procedure Make_Elab_String
(Nod
: Node_Id
) is
1339 if Nkind
(Nod
) = N_Selected_Component
then
1340 Make_Elab_String
(Prefix
(Nod
));
1342 Store_String_Char
('$');
1344 Store_String_Char
('_');
1345 Store_String_Char
('_');
1348 Get_Name_String
(Chars
(Selector_Name
(Nod
)));
1351 pragma Assert
(Nkind
(Nod
) = N_Identifier
);
1352 Get_Name_String
(Chars
(Nod
));
1355 Store_String_Chars
(Name_Buffer
(1 .. Name_Len
));
1356 end Make_Elab_String
;
1358 -- Start of processing for Elab_Body/Elab_Spec
1361 -- First we need to prepare the string literal for the name of
1362 -- the elaboration routine to be referenced.
1365 Make_Elab_String
(Pref
);
1368 Store_String_Chars
("._elab");
1369 Lang
:= Make_Identifier
(Loc
, Name_Ada
);
1371 Store_String_Chars
("___elab");
1372 Lang
:= Make_Identifier
(Loc
, Name_C
);
1375 if Id
= Attribute_Elab_Body
then
1376 Store_String_Char
('b');
1378 Store_String_Char
('s');
1383 Insert_Actions
(N
, New_List
(
1384 Make_Subprogram_Declaration
(Loc
,
1386 Make_Procedure_Specification
(Loc
,
1387 Defining_Unit_Name
=> Ent
)),
1390 Chars
=> Name_Import
,
1391 Pragma_Argument_Associations
=> New_List
(
1392 Make_Pragma_Argument_Association
(Loc
,
1393 Expression
=> Lang
),
1395 Make_Pragma_Argument_Association
(Loc
,
1397 Make_Identifier
(Loc
, Chars
(Ent
))),
1399 Make_Pragma_Argument_Association
(Loc
,
1401 Make_String_Literal
(Loc
, Str
))))));
1403 Set_Entity
(N
, Ent
);
1404 Rewrite
(N
, New_Occurrence_Of
(Ent
, Loc
));
1411 -- Elaborated is always True for preelaborated units, predefined
1412 -- units, pure units and units which have Elaborate_Body pragmas.
1413 -- These units have no elaboration entity.
1415 -- Note: The Elaborated attribute is never passed through to Gigi
1417 when Attribute_Elaborated
=> Elaborated
: declare
1418 Ent
: constant Entity_Id
:= Entity
(Pref
);
1421 if Present
(Elaboration_Entity
(Ent
)) then
1423 New_Occurrence_Of
(Elaboration_Entity
(Ent
), Loc
));
1425 Rewrite
(N
, New_Occurrence_Of
(Standard_True
, Loc
));
1433 when Attribute_Enum_Rep
=> Enum_Rep
:
1435 -- X'Enum_Rep (Y) expands to
1439 -- This is simply a direct conversion from the enumeration type
1440 -- to the target integer type, which is treated by Gigi as a normal
1441 -- integer conversion, treating the enumeration type as an integer,
1442 -- which is exactly what we want! We set Conversion_OK to make sure
1443 -- that the analyzer does not complain about what otherwise might
1444 -- be an illegal conversion.
1446 if Is_Non_Empty_List
(Exprs
) then
1448 OK_Convert_To
(Typ
, Relocate_Node
(First
(Exprs
))));
1450 -- X'Enum_Rep where X is an enumeration literal is replaced by
1451 -- the literal value.
1453 elsif Ekind
(Entity
(Pref
)) = E_Enumeration_Literal
then
1455 Make_Integer_Literal
(Loc
, Enumeration_Rep
(Entity
(Pref
))));
1457 -- If this is a renaming of a literal, recover the representation
1460 elsif Ekind
(Entity
(Pref
)) = E_Constant
1461 and then Present
(Renamed_Object
(Entity
(Pref
)))
1463 Ekind
(Entity
(Renamed_Object
(Entity
(Pref
))))
1464 = E_Enumeration_Literal
1467 Make_Integer_Literal
(Loc
,
1468 Enumeration_Rep
(Entity
(Renamed_Object
(Entity
(Pref
))))));
1470 -- X'Enum_Rep where X is an object does a direct unchecked conversion
1471 -- of the object value, as described for the type case above.
1475 OK_Convert_To
(Typ
, Relocate_Node
(Pref
)));
1479 Analyze_And_Resolve
(N
, Typ
);
1487 -- Transforms 'Exponent into a call to the floating-point attribute
1488 -- function Exponent in Fat_xxx (where xxx is the root type)
1490 when Attribute_Exponent
=>
1491 Expand_Fpt_Attribute_R
(N
);
1497 -- transforme X'External_Tag into Ada.Tags.External_Tag (X'tag)
1499 when Attribute_External_Tag
=> External_Tag
:
1502 Make_Function_Call
(Loc
,
1503 Name
=> New_Reference_To
(RTE
(RE_External_Tag
), Loc
),
1504 Parameter_Associations
=> New_List
(
1505 Make_Attribute_Reference
(Loc
,
1506 Attribute_Name
=> Name_Tag
,
1507 Prefix
=> Prefix
(N
)))));
1509 Analyze_And_Resolve
(N
, Standard_String
);
1516 when Attribute_First
=> declare
1517 Ptyp
: constant Entity_Id
:= Etype
(Pref
);
1520 -- If the prefix type is a constrained packed array type which
1521 -- already has a Packed_Array_Type representation defined, then
1522 -- replace this attribute with a direct reference to 'First of the
1523 -- appropriate index subtype (since otherwise Gigi will try to give
1524 -- us the value of 'First for this implementation type).
1526 if Is_Constrained_Packed_Array
(Ptyp
) then
1528 Make_Attribute_Reference
(Loc
,
1529 Attribute_Name
=> Name_First
,
1530 Prefix
=> New_Reference_To
(Get_Index_Subtype
(N
), Loc
)));
1531 Analyze_And_Resolve
(N
, Typ
);
1533 elsif Is_Access_Type
(Ptyp
) then
1534 Apply_Access_Check
(N
);
1542 -- We compute this if a component clause was present, otherwise
1543 -- we leave the computation up to Gigi, since we don't know what
1544 -- layout will be chosen.
1546 when Attribute_First_Bit
=> First_Bit
:
1548 CE
: constant Entity_Id
:= Entity
(Selector_Name
(Pref
));
1551 if Known_Static_Component_Bit_Offset
(CE
) then
1553 Make_Integer_Literal
(Loc
,
1554 Component_Bit_Offset
(CE
) mod System_Storage_Unit
));
1556 Analyze_And_Resolve
(N
, Typ
);
1559 Apply_Universal_Integer_Attribute_Checks
(N
);
1569 -- fixtype'Fixed_Value (integer-value)
1573 -- fixtype(integer-value)
1575 -- we do all the required analysis of the conversion here, because
1576 -- we do not want this to go through the fixed-point conversion
1577 -- circuits. Note that gigi always treats fixed-point as equivalent
1578 -- to the corresponding integer type anyway.
1580 when Attribute_Fixed_Value
=> Fixed_Value
:
1583 Make_Type_Conversion
(Loc
,
1584 Subtype_Mark
=> New_Occurrence_Of
(Entity
(Pref
), Loc
),
1585 Expression
=> Relocate_Node
(First
(Exprs
))));
1586 Set_Etype
(N
, Entity
(Pref
));
1589 -- Note: it might appear that a properly analyzed unchecked conversion
1590 -- would be just fine here, but that's not the case, since the full
1591 -- range checks performed by the following call are critical!
1593 Apply_Type_Conversion_Checks
(N
);
1600 -- Transforms 'Floor into a call to the floating-point attribute
1601 -- function Floor in Fat_xxx (where xxx is the root type)
1603 when Attribute_Floor
=>
1604 Expand_Fpt_Attribute_R
(N
);
1610 -- For the fixed-point type Typ:
1616 -- Result_Type (System.Fore (Long_Long_Float (Type'First)),
1617 -- Long_Long_Float (Type'Last))
1619 -- Note that we know that the type is a non-static subtype, or Fore
1620 -- would have itself been computed dynamically in Eval_Attribute.
1622 when Attribute_Fore
=> Fore
:
1624 Ptyp
: constant Entity_Id
:= Etype
(Pref
);
1629 Make_Function_Call
(Loc
,
1630 Name
=> New_Reference_To
(RTE
(RE_Fore
), Loc
),
1632 Parameter_Associations
=> New_List
(
1633 Convert_To
(Standard_Long_Long_Float
,
1634 Make_Attribute_Reference
(Loc
,
1635 Prefix
=> New_Reference_To
(Ptyp
, Loc
),
1636 Attribute_Name
=> Name_First
)),
1638 Convert_To
(Standard_Long_Long_Float
,
1639 Make_Attribute_Reference
(Loc
,
1640 Prefix
=> New_Reference_To
(Ptyp
, Loc
),
1641 Attribute_Name
=> Name_Last
))))));
1643 Analyze_And_Resolve
(N
, Typ
);
1650 -- Transforms 'Fraction into a call to the floating-point attribute
1651 -- function Fraction in Fat_xxx (where xxx is the root type)
1653 when Attribute_Fraction
=>
1654 Expand_Fpt_Attribute_R
(N
);
1660 -- For an exception returns a reference to the exception data:
1661 -- Exception_Id!(Prefix'Reference)
1663 -- For a task it returns a reference to the _task_id component of
1664 -- corresponding record:
1666 -- taskV!(Prefix)._Task_Id, converted to the type Task_Id defined
1668 -- in Ada.Task_Identification.
1670 when Attribute_Identity
=> Identity
: declare
1671 Id_Kind
: Entity_Id
;
1674 if Etype
(Pref
) = Standard_Exception_Type
then
1675 Id_Kind
:= RTE
(RE_Exception_Id
);
1677 if Present
(Renamed_Object
(Entity
(Pref
))) then
1678 Set_Entity
(Pref
, Renamed_Object
(Entity
(Pref
)));
1682 Unchecked_Convert_To
(Id_Kind
, Make_Reference
(Loc
, Pref
)));
1684 Id_Kind
:= RTE
(RO_AT_Task_Id
);
1687 Unchecked_Convert_To
(Id_Kind
, Concurrent_Ref
(Pref
)));
1690 Analyze_And_Resolve
(N
, Id_Kind
);
1697 -- Image attribute is handled in separate unit Exp_Imgv
1699 when Attribute_Image
=>
1700 Exp_Imgv
.Expand_Image_Attribute
(N
);
1706 -- X'Img is expanded to typ'Image (X), where typ is the type of X
1708 when Attribute_Img
=> Img
:
1711 Make_Attribute_Reference
(Loc
,
1712 Prefix
=> New_Reference_To
(Etype
(Pref
), Loc
),
1713 Attribute_Name
=> Name_Image
,
1714 Expressions
=> New_List
(Relocate_Node
(Pref
))));
1716 Analyze_And_Resolve
(N
, Standard_String
);
1723 when Attribute_Input
=> Input
: declare
1724 P_Type
: constant Entity_Id
:= Entity
(Pref
);
1725 B_Type
: constant Entity_Id
:= Base_Type
(P_Type
);
1726 U_Type
: constant Entity_Id
:= Underlying_Type
(P_Type
);
1727 Strm
: constant Node_Id
:= First
(Exprs
);
1735 Cntrl
: Node_Id
:= Empty
;
1736 -- Value for controlling argument in call. Always Empty except in
1737 -- the dispatching (class-wide type) case, where it is a reference
1738 -- to the dummy object initialized to the right internal tag.
1741 -- If no underlying type, we have an error that will be diagnosed
1742 -- elsewhere, so here we just completely ignore the expansion.
1748 -- If there is a TSS for Input, just call it
1750 Fname
:= Find_Stream_Subprogram
(P_Type
, TSS_Stream_Input
);
1752 if Present
(Fname
) then
1756 -- If there is a Stream_Convert pragma, use it, we rewrite
1758 -- sourcetyp'Input (stream)
1762 -- sourcetyp (streamread (strmtyp'Input (stream)));
1764 -- where stmrearead is the given Read function that converts
1765 -- an argument of type strmtyp to type sourcetyp or a type
1766 -- from which it is derived. The extra conversion is required
1767 -- for the derived case.
1771 (Implementation_Base_Type
(P_Type
), Name_Stream_Convert
);
1773 if Present
(Prag
) then
1774 Arg2
:= Next
(First
(Pragma_Argument_Associations
(Prag
)));
1775 Rfunc
:= Entity
(Expression
(Arg2
));
1779 Make_Function_Call
(Loc
,
1780 Name
=> New_Occurrence_Of
(Rfunc
, Loc
),
1781 Parameter_Associations
=> New_List
(
1782 Make_Attribute_Reference
(Loc
,
1785 (Etype
(First_Formal
(Rfunc
)), Loc
),
1786 Attribute_Name
=> Name_Input
,
1787 Expressions
=> Exprs
)))));
1789 Analyze_And_Resolve
(N
, B_Type
);
1794 elsif Is_Elementary_Type
(U_Type
) then
1796 -- A special case arises if we have a defined _Read routine,
1797 -- since in this case we are required to call this routine.
1799 if Present
(TSS
(Base_Type
(U_Type
), TSS_Stream_Read
)) then
1800 Build_Record_Or_Elementary_Input_Function
1801 (Loc
, U_Type
, Decl
, Fname
);
1802 Insert_Action
(N
, Decl
);
1804 -- For normal cases, we call the I_xxx routine directly
1807 Rewrite
(N
, Build_Elementary_Input_Call
(N
));
1808 Analyze_And_Resolve
(N
, P_Type
);
1814 elsif Is_Array_Type
(U_Type
) then
1815 Build_Array_Input_Function
(Loc
, U_Type
, Decl
, Fname
);
1816 Compile_Stream_Body_In_Scope
(N
, Decl
, U_Type
, Check
=> False);
1818 -- Dispatching case with class-wide type
1820 elsif Is_Class_Wide_Type
(P_Type
) then
1823 Rtyp
: constant Entity_Id
:= Root_Type
(P_Type
);
1828 -- Read the internal tag (RM 13.13.2(34)) and use it to
1829 -- initialize a dummy tag object:
1831 -- Dnn : Ada.Tags.Tag
1832 -- := Internal_Tag (String'Input (Strm));
1834 -- This dummy object is used only to provide a controlling
1835 -- argument for the eventual _Input call.
1838 Make_Defining_Identifier
(Loc
,
1839 Chars
=> New_Internal_Name
('D'));
1842 Make_Object_Declaration
(Loc
,
1843 Defining_Identifier
=> Dnn
,
1844 Object_Definition
=>
1845 New_Occurrence_Of
(RTE
(RE_Tag
), Loc
),
1847 Make_Function_Call
(Loc
,
1849 New_Occurrence_Of
(RTE
(RE_Internal_Tag
), Loc
),
1850 Parameter_Associations
=> New_List
(
1851 Make_Attribute_Reference
(Loc
,
1853 New_Occurrence_Of
(Standard_String
, Loc
),
1854 Attribute_Name
=> Name_Input
,
1855 Expressions
=> New_List
(
1857 (Duplicate_Subexpr
(Strm
)))))));
1859 Insert_Action
(N
, Decl
);
1861 -- Now we need to get the entity for the call, and construct
1862 -- a function call node, where we preset a reference to Dnn
1863 -- as the controlling argument (doing an unchecked
1864 -- conversion to the classwide tagged type to make it
1865 -- look like a real tagged object).
1867 Fname
:= Find_Prim_Op
(Rtyp
, TSS_Stream_Input
);
1868 Cntrl
:= Unchecked_Convert_To
(P_Type
,
1869 New_Occurrence_Of
(Dnn
, Loc
));
1870 Set_Etype
(Cntrl
, P_Type
);
1871 Set_Parent
(Cntrl
, N
);
1874 -- For tagged types, use the primitive Input function
1876 elsif Is_Tagged_Type
(U_Type
) then
1877 Fname
:= Find_Prim_Op
(U_Type
, TSS_Stream_Input
);
1879 -- All other record type cases, including protected records.
1880 -- The latter only arise for expander generated code for
1881 -- handling shared passive partition access.
1885 (Is_Record_Type
(U_Type
) or else Is_Protected_Type
(U_Type
));
1887 -- Ada 2005 (AI-216): Program_Error is raised when executing
1888 -- the default implementation of the Input attribute of an
1889 -- unchecked union type if the type lacks default discriminant
1892 if Is_Unchecked_Union
(Base_Type
(U_Type
))
1893 and then not Present
(Discriminant_Constraint
(U_Type
))
1896 Make_Raise_Program_Error
(Loc
,
1897 Reason
=> PE_Unchecked_Union_Restriction
));
1902 Build_Record_Or_Elementary_Input_Function
1903 (Loc
, Base_Type
(U_Type
), Decl
, Fname
);
1904 Insert_Action
(N
, Decl
);
1908 -- If we fall through, Fname is the function to be called. The
1909 -- result is obtained by calling the appropriate function, then
1910 -- converting the result. The conversion does a subtype check.
1913 Make_Function_Call
(Loc
,
1914 Name
=> New_Occurrence_Of
(Fname
, Loc
),
1915 Parameter_Associations
=> New_List
(
1916 Relocate_Node
(Strm
)));
1918 Set_Controlling_Argument
(Call
, Cntrl
);
1919 Rewrite
(N
, Unchecked_Convert_To
(P_Type
, Call
));
1920 Analyze_And_Resolve
(N
, P_Type
);
1929 -- inttype'Fixed_Value (fixed-value)
1933 -- inttype(integer-value))
1935 -- we do all the required analysis of the conversion here, because
1936 -- we do not want this to go through the fixed-point conversion
1937 -- circuits. Note that gigi always treats fixed-point as equivalent
1938 -- to the corresponding integer type anyway.
1940 when Attribute_Integer_Value
=> Integer_Value
:
1943 Make_Type_Conversion
(Loc
,
1944 Subtype_Mark
=> New_Occurrence_Of
(Entity
(Pref
), Loc
),
1945 Expression
=> Relocate_Node
(First
(Exprs
))));
1946 Set_Etype
(N
, Entity
(Pref
));
1949 -- Note: it might appear that a properly analyzed unchecked conversion
1950 -- would be just fine here, but that's not the case, since the full
1951 -- range checks performed by the following call are critical!
1953 Apply_Type_Conversion_Checks
(N
);
1960 when Attribute_Last
=> declare
1961 Ptyp
: constant Entity_Id
:= Etype
(Pref
);
1964 -- If the prefix type is a constrained packed array type which
1965 -- already has a Packed_Array_Type representation defined, then
1966 -- replace this attribute with a direct reference to 'Last of the
1967 -- appropriate index subtype (since otherwise Gigi will try to give
1968 -- us the value of 'Last for this implementation type).
1970 if Is_Constrained_Packed_Array
(Ptyp
) then
1972 Make_Attribute_Reference
(Loc
,
1973 Attribute_Name
=> Name_Last
,
1974 Prefix
=> New_Reference_To
(Get_Index_Subtype
(N
), Loc
)));
1975 Analyze_And_Resolve
(N
, Typ
);
1977 elsif Is_Access_Type
(Ptyp
) then
1978 Apply_Access_Check
(N
);
1986 -- We compute this if a component clause was present, otherwise
1987 -- we leave the computation up to Gigi, since we don't know what
1988 -- layout will be chosen.
1990 when Attribute_Last_Bit
=> Last_Bit
:
1992 CE
: constant Entity_Id
:= Entity
(Selector_Name
(Pref
));
1995 if Known_Static_Component_Bit_Offset
(CE
)
1996 and then Known_Static_Esize
(CE
)
1999 Make_Integer_Literal
(Loc
,
2000 Intval
=> (Component_Bit_Offset
(CE
) mod System_Storage_Unit
)
2003 Analyze_And_Resolve
(N
, Typ
);
2006 Apply_Universal_Integer_Attribute_Checks
(N
);
2014 -- Transforms 'Leading_Part into a call to the floating-point attribute
2015 -- function Leading_Part in Fat_xxx (where xxx is the root type)
2017 -- Note: strictly, we should have special case code to deal with
2018 -- absurdly large positive arguments (greater than Integer'Last),
2019 -- which result in returning the first argument unchanged, but it
2020 -- hardly seems worth the effort. We raise constraint error for
2021 -- absurdly negative arguments which is fine.
2023 when Attribute_Leading_Part
=>
2024 Expand_Fpt_Attribute_RI
(N
);
2030 when Attribute_Length
=> declare
2031 Ptyp
: constant Entity_Id
:= Etype
(Pref
);
2036 -- Processing for packed array types
2038 if Is_Array_Type
(Ptyp
) and then Is_Packed
(Ptyp
) then
2039 Ityp
:= Get_Index_Subtype
(N
);
2041 -- If the index type, Ityp, is an enumeration type with
2042 -- holes, then we calculate X'Length explicitly using
2045 -- (0, Ityp'Pos (X'Last (N)) -
2046 -- Ityp'Pos (X'First (N)) + 1);
2048 -- Since the bounds in the template are the representation
2049 -- values and gigi would get the wrong value.
2051 if Is_Enumeration_Type
(Ityp
)
2052 and then Present
(Enum_Pos_To_Rep
(Base_Type
(Ityp
)))
2057 Xnum
:= Expr_Value
(First
(Expressions
(N
)));
2061 Make_Attribute_Reference
(Loc
,
2062 Prefix
=> New_Occurrence_Of
(Typ
, Loc
),
2063 Attribute_Name
=> Name_Max
,
2064 Expressions
=> New_List
2065 (Make_Integer_Literal
(Loc
, 0),
2069 Make_Op_Subtract
(Loc
,
2071 Make_Attribute_Reference
(Loc
,
2072 Prefix
=> New_Occurrence_Of
(Ityp
, Loc
),
2073 Attribute_Name
=> Name_Pos
,
2075 Expressions
=> New_List
(
2076 Make_Attribute_Reference
(Loc
,
2077 Prefix
=> Duplicate_Subexpr
(Pref
),
2078 Attribute_Name
=> Name_Last
,
2079 Expressions
=> New_List
(
2080 Make_Integer_Literal
(Loc
, Xnum
))))),
2083 Make_Attribute_Reference
(Loc
,
2084 Prefix
=> New_Occurrence_Of
(Ityp
, Loc
),
2085 Attribute_Name
=> Name_Pos
,
2087 Expressions
=> New_List
(
2088 Make_Attribute_Reference
(Loc
,
2090 Duplicate_Subexpr_No_Checks
(Pref
),
2091 Attribute_Name
=> Name_First
,
2092 Expressions
=> New_List
(
2093 Make_Integer_Literal
(Loc
, Xnum
)))))),
2095 Right_Opnd
=> Make_Integer_Literal
(Loc
, 1)))));
2097 Analyze_And_Resolve
(N
, Typ
, Suppress
=> All_Checks
);
2100 -- If the prefix type is a constrained packed array type which
2101 -- already has a Packed_Array_Type representation defined, then
2102 -- replace this attribute with a direct reference to 'Range_Length
2103 -- of the appropriate index subtype (since otherwise Gigi will try
2104 -- to give us the value of 'Length for this implementation type).
2106 elsif Is_Constrained
(Ptyp
) then
2108 Make_Attribute_Reference
(Loc
,
2109 Attribute_Name
=> Name_Range_Length
,
2110 Prefix
=> New_Reference_To
(Ityp
, Loc
)));
2111 Analyze_And_Resolve
(N
, Typ
);
2114 -- If we have a packed array that is not bit packed, which was
2118 elsif Is_Access_Type
(Ptyp
) then
2119 Apply_Access_Check
(N
);
2121 -- If the designated type is a packed array type, then we
2122 -- convert the reference to:
2125 -- xtyp'Pos (Pref'Last (Expr)) -
2126 -- xtyp'Pos (Pref'First (Expr)));
2128 -- This is a bit complex, but it is the easiest thing to do
2129 -- that works in all cases including enum types with holes
2130 -- xtyp here is the appropriate index type.
2133 Dtyp
: constant Entity_Id
:= Designated_Type
(Ptyp
);
2137 if Is_Array_Type
(Dtyp
) and then Is_Packed
(Dtyp
) then
2138 Xtyp
:= Get_Index_Subtype
(N
);
2141 Make_Attribute_Reference
(Loc
,
2142 Prefix
=> New_Occurrence_Of
(Typ
, Loc
),
2143 Attribute_Name
=> Name_Max
,
2144 Expressions
=> New_List
(
2145 Make_Integer_Literal
(Loc
, 0),
2148 Make_Integer_Literal
(Loc
, 1),
2149 Make_Op_Subtract
(Loc
,
2151 Make_Attribute_Reference
(Loc
,
2152 Prefix
=> New_Occurrence_Of
(Xtyp
, Loc
),
2153 Attribute_Name
=> Name_Pos
,
2154 Expressions
=> New_List
(
2155 Make_Attribute_Reference
(Loc
,
2156 Prefix
=> Duplicate_Subexpr
(Pref
),
2157 Attribute_Name
=> Name_Last
,
2159 New_Copy_List
(Exprs
)))),
2162 Make_Attribute_Reference
(Loc
,
2163 Prefix
=> New_Occurrence_Of
(Xtyp
, Loc
),
2164 Attribute_Name
=> Name_Pos
,
2165 Expressions
=> New_List
(
2166 Make_Attribute_Reference
(Loc
,
2168 Duplicate_Subexpr_No_Checks
(Pref
),
2169 Attribute_Name
=> Name_First
,
2171 New_Copy_List
(Exprs
)))))))));
2173 Analyze_And_Resolve
(N
, Typ
);
2177 -- Otherwise leave it to gigi
2180 Apply_Universal_Integer_Attribute_Checks
(N
);
2188 -- Transforms 'Machine into a call to the floating-point attribute
2189 -- function Machine in Fat_xxx (where xxx is the root type)
2191 when Attribute_Machine
=>
2192 Expand_Fpt_Attribute_R
(N
);
2198 -- Machine_Size is equivalent to Object_Size, so transform it into
2199 -- Object_Size and that way Gigi never sees Machine_Size.
2201 when Attribute_Machine_Size
=>
2203 Make_Attribute_Reference
(Loc
,
2204 Prefix
=> Prefix
(N
),
2205 Attribute_Name
=> Name_Object_Size
));
2207 Analyze_And_Resolve
(N
, Typ
);
2213 -- The only case that can get this far is the dynamic case of the
2214 -- old Ada 83 Mantissa attribute for the fixed-point case. For this
2221 -- ityp (System.Mantissa.Mantissa_Value
2222 -- (Integer'Integer_Value (typ'First),
2223 -- Integer'Integer_Value (typ'Last)));
2225 when Attribute_Mantissa
=> Mantissa
: declare
2226 Ptyp
: constant Entity_Id
:= Etype
(Pref
);
2231 Make_Function_Call
(Loc
,
2232 Name
=> New_Occurrence_Of
(RTE
(RE_Mantissa_Value
), Loc
),
2234 Parameter_Associations
=> New_List
(
2236 Make_Attribute_Reference
(Loc
,
2237 Prefix
=> New_Occurrence_Of
(Standard_Integer
, Loc
),
2238 Attribute_Name
=> Name_Integer_Value
,
2239 Expressions
=> New_List
(
2241 Make_Attribute_Reference
(Loc
,
2242 Prefix
=> New_Occurrence_Of
(Ptyp
, Loc
),
2243 Attribute_Name
=> Name_First
))),
2245 Make_Attribute_Reference
(Loc
,
2246 Prefix
=> New_Occurrence_Of
(Standard_Integer
, Loc
),
2247 Attribute_Name
=> Name_Integer_Value
,
2248 Expressions
=> New_List
(
2250 Make_Attribute_Reference
(Loc
,
2251 Prefix
=> New_Occurrence_Of
(Ptyp
, Loc
),
2252 Attribute_Name
=> Name_Last
)))))));
2254 Analyze_And_Resolve
(N
, Typ
);
2261 -- Transforms 'Model into a call to the floating-point attribute
2262 -- function Model in Fat_xxx (where xxx is the root type)
2264 when Attribute_Model
=>
2265 Expand_Fpt_Attribute_R
(N
);
2271 -- The processing for Object_Size shares the processing for Size
2277 when Attribute_Output
=> Output
: declare
2278 P_Type
: constant Entity_Id
:= Entity
(Pref
);
2279 U_Type
: constant Entity_Id
:= Underlying_Type
(P_Type
);
2287 -- If no underlying type, we have an error that will be diagnosed
2288 -- elsewhere, so here we just completely ignore the expansion.
2294 -- If TSS for Output is present, just call it
2296 Pname
:= Find_Stream_Subprogram
(P_Type
, TSS_Stream_Output
);
2298 if Present
(Pname
) then
2302 -- If there is a Stream_Convert pragma, use it, we rewrite
2304 -- sourcetyp'Output (stream, Item)
2308 -- strmtyp'Output (Stream, strmwrite (acttyp (Item)));
2310 -- where strmwrite is the given Write function that converts
2311 -- an argument of type sourcetyp or a type acctyp, from which
2312 -- it is derived to type strmtyp. The conversion to acttyp is
2313 -- required for the derived case.
2317 (Implementation_Base_Type
(P_Type
), Name_Stream_Convert
);
2319 if Present
(Prag
) then
2321 Next
(Next
(First
(Pragma_Argument_Associations
(Prag
))));
2322 Wfunc
:= Entity
(Expression
(Arg3
));
2325 Make_Attribute_Reference
(Loc
,
2326 Prefix
=> New_Occurrence_Of
(Etype
(Wfunc
), Loc
),
2327 Attribute_Name
=> Name_Output
,
2328 Expressions
=> New_List
(
2329 Relocate_Node
(First
(Exprs
)),
2330 Make_Function_Call
(Loc
,
2331 Name
=> New_Occurrence_Of
(Wfunc
, Loc
),
2332 Parameter_Associations
=> New_List
(
2333 Convert_To
(Etype
(First_Formal
(Wfunc
)),
2334 Relocate_Node
(Next
(First
(Exprs
)))))))));
2339 -- For elementary types, we call the W_xxx routine directly.
2340 -- Note that the effect of Write and Output is identical for
2341 -- the case of an elementary type, since there are no
2342 -- discriminants or bounds.
2344 elsif Is_Elementary_Type
(U_Type
) then
2346 -- A special case arises if we have a defined _Write routine,
2347 -- since in this case we are required to call this routine.
2349 if Present
(TSS
(Base_Type
(U_Type
), TSS_Stream_Write
)) then
2350 Build_Record_Or_Elementary_Output_Procedure
2351 (Loc
, U_Type
, Decl
, Pname
);
2352 Insert_Action
(N
, Decl
);
2354 -- For normal cases, we call the W_xxx routine directly
2357 Rewrite
(N
, Build_Elementary_Write_Call
(N
));
2364 elsif Is_Array_Type
(U_Type
) then
2365 Build_Array_Output_Procedure
(Loc
, U_Type
, Decl
, Pname
);
2366 Compile_Stream_Body_In_Scope
(N
, Decl
, U_Type
, Check
=> False);
2368 -- Class-wide case, first output external tag, then dispatch
2369 -- to the appropriate primitive Output function (RM 13.13.2(31)).
2371 elsif Is_Class_Wide_Type
(P_Type
) then
2373 Strm
: constant Node_Id
:= First
(Exprs
);
2374 Item
: constant Node_Id
:= Next
(Strm
);
2378 -- String'Output (Strm, External_Tag (Item'Tag))
2381 Make_Attribute_Reference
(Loc
,
2382 Prefix
=> New_Occurrence_Of
(Standard_String
, Loc
),
2383 Attribute_Name
=> Name_Output
,
2384 Expressions
=> New_List
(
2385 Relocate_Node
(Duplicate_Subexpr
(Strm
)),
2386 Make_Function_Call
(Loc
,
2388 New_Occurrence_Of
(RTE
(RE_External_Tag
), Loc
),
2389 Parameter_Associations
=> New_List
(
2390 Make_Attribute_Reference
(Loc
,
2393 (Duplicate_Subexpr
(Item
, Name_Req
=> True)),
2394 Attribute_Name
=> Name_Tag
))))));
2397 Pname
:= Find_Prim_Op
(U_Type
, TSS_Stream_Output
);
2399 -- Tagged type case, use the primitive Output function
2401 elsif Is_Tagged_Type
(U_Type
) then
2402 Pname
:= Find_Prim_Op
(U_Type
, TSS_Stream_Output
);
2404 -- All other record type cases, including protected records.
2405 -- The latter only arise for expander generated code for
2406 -- handling shared passive partition access.
2410 (Is_Record_Type
(U_Type
) or else Is_Protected_Type
(U_Type
));
2412 -- Ada 2005 (AI-216): Program_Error is raised when executing
2413 -- the default implementation of the Output attribute of an
2414 -- unchecked union type if the type lacks default discriminant
2417 if Is_Unchecked_Union
(Base_Type
(U_Type
))
2418 and then not Present
(Discriminant_Constraint
(U_Type
))
2421 Make_Raise_Program_Error
(Loc
,
2422 Reason
=> PE_Unchecked_Union_Restriction
));
2427 Build_Record_Or_Elementary_Output_Procedure
2428 (Loc
, Base_Type
(U_Type
), Decl
, Pname
);
2429 Insert_Action
(N
, Decl
);
2433 -- If we fall through, Pname is the name of the procedure to call
2435 Rewrite_Stream_Proc_Call
(Pname
);
2442 -- For enumeration types with a standard representation, Pos is
2445 -- For enumeration types, with a non-standard representation we
2446 -- generate a call to the _Rep_To_Pos function created when the
2447 -- type was frozen. The call has the form
2449 -- _rep_to_pos (expr, flag)
2451 -- The parameter flag is True if range checks are enabled, causing
2452 -- Program_Error to be raised if the expression has an invalid
2453 -- representation, and False if range checks are suppressed.
2455 -- For integer types, Pos is equivalent to a simple integer
2456 -- conversion and we rewrite it as such
2458 when Attribute_Pos
=> Pos
:
2460 Etyp
: Entity_Id
:= Base_Type
(Entity
(Pref
));
2463 -- Deal with zero/non-zero boolean values
2465 if Is_Boolean_Type
(Etyp
) then
2466 Adjust_Condition
(First
(Exprs
));
2467 Etyp
:= Standard_Boolean
;
2468 Set_Prefix
(N
, New_Occurrence_Of
(Standard_Boolean
, Loc
));
2471 -- Case of enumeration type
2473 if Is_Enumeration_Type
(Etyp
) then
2475 -- Non-standard enumeration type (generate call)
2477 if Present
(Enum_Pos_To_Rep
(Etyp
)) then
2478 Append_To
(Exprs
, Rep_To_Pos_Flag
(Etyp
, Loc
));
2481 Make_Function_Call
(Loc
,
2483 New_Reference_To
(TSS
(Etyp
, TSS_Rep_To_Pos
), Loc
),
2484 Parameter_Associations
=> Exprs
)));
2486 Analyze_And_Resolve
(N
, Typ
);
2488 -- Standard enumeration type (do universal integer check)
2491 Apply_Universal_Integer_Attribute_Checks
(N
);
2494 -- Deal with integer types (replace by conversion)
2496 elsif Is_Integer_Type
(Etyp
) then
2497 Rewrite
(N
, Convert_To
(Typ
, First
(Exprs
)));
2498 Analyze_And_Resolve
(N
, Typ
);
2507 -- We compute this if a component clause was present, otherwise
2508 -- we leave the computation up to Gigi, since we don't know what
2509 -- layout will be chosen.
2511 when Attribute_Position
=> Position
:
2513 CE
: constant Entity_Id
:= Entity
(Selector_Name
(Pref
));
2516 if Present
(Component_Clause
(CE
)) then
2518 Make_Integer_Literal
(Loc
,
2519 Intval
=> Component_Bit_Offset
(CE
) / System_Storage_Unit
));
2520 Analyze_And_Resolve
(N
, Typ
);
2523 Apply_Universal_Integer_Attribute_Checks
(N
);
2531 -- 1. Deal with enumeration types with holes
2532 -- 2. For floating-point, generate call to attribute function
2533 -- 3. For other cases, deal with constraint checking
2535 when Attribute_Pred
=> Pred
:
2537 Ptyp
: constant Entity_Id
:= Base_Type
(Etype
(Pref
));
2540 -- For enumeration types with non-standard representations, we
2541 -- expand typ'Pred (x) into
2543 -- Pos_To_Rep (Rep_To_Pos (x) - 1)
2545 -- If the representation is contiguous, we compute instead
2546 -- Lit1 + Rep_to_Pos (x -1), to catch invalid representations.
2548 if Is_Enumeration_Type
(Ptyp
)
2549 and then Present
(Enum_Pos_To_Rep
(Ptyp
))
2551 if Has_Contiguous_Rep
(Ptyp
) then
2553 Unchecked_Convert_To
(Ptyp
,
2556 Make_Integer_Literal
(Loc
,
2557 Enumeration_Rep
(First_Literal
(Ptyp
))),
2559 Make_Function_Call
(Loc
,
2562 (TSS
(Ptyp
, TSS_Rep_To_Pos
), Loc
),
2564 Parameter_Associations
=>
2566 Unchecked_Convert_To
(Ptyp
,
2567 Make_Op_Subtract
(Loc
,
2569 Unchecked_Convert_To
(Standard_Integer
,
2570 Relocate_Node
(First
(Exprs
))),
2572 Make_Integer_Literal
(Loc
, 1))),
2573 Rep_To_Pos_Flag
(Ptyp
, Loc
))))));
2576 -- Add Boolean parameter True, to request program errror if
2577 -- we have a bad representation on our hands. If checks are
2578 -- suppressed, then add False instead
2580 Append_To
(Exprs
, Rep_To_Pos_Flag
(Ptyp
, Loc
));
2582 Make_Indexed_Component
(Loc
,
2583 Prefix
=> New_Reference_To
(Enum_Pos_To_Rep
(Ptyp
), Loc
),
2584 Expressions
=> New_List
(
2585 Make_Op_Subtract
(Loc
,
2587 Make_Function_Call
(Loc
,
2589 New_Reference_To
(TSS
(Ptyp
, TSS_Rep_To_Pos
), Loc
),
2590 Parameter_Associations
=> Exprs
),
2591 Right_Opnd
=> Make_Integer_Literal
(Loc
, 1)))));
2594 Analyze_And_Resolve
(N
, Typ
);
2596 -- For floating-point, we transform 'Pred into a call to the Pred
2597 -- floating-point attribute function in Fat_xxx (xxx is root type)
2599 elsif Is_Floating_Point_Type
(Ptyp
) then
2600 Expand_Fpt_Attribute_R
(N
);
2601 Analyze_And_Resolve
(N
, Typ
);
2603 -- For modular types, nothing to do (no overflow, since wraps)
2605 elsif Is_Modular_Integer_Type
(Ptyp
) then
2608 -- For other types, if range checking is enabled, we must generate
2609 -- a check if overflow checking is enabled.
2611 elsif not Overflow_Checks_Suppressed
(Ptyp
) then
2612 Expand_Pred_Succ
(N
);
2621 when Attribute_Range_Length
=> Range_Length
: declare
2622 P_Type
: constant Entity_Id
:= Etype
(Pref
);
2625 -- The only special processing required is for the case where
2626 -- Range_Length is applied to an enumeration type with holes.
2627 -- In this case we transform
2633 -- X'Pos (X'Last) - X'Pos (X'First) + 1
2635 -- So that the result reflects the proper Pos values instead
2636 -- of the underlying representations.
2638 if Is_Enumeration_Type
(P_Type
)
2639 and then Has_Non_Standard_Rep
(P_Type
)
2644 Make_Op_Subtract
(Loc
,
2646 Make_Attribute_Reference
(Loc
,
2647 Attribute_Name
=> Name_Pos
,
2648 Prefix
=> New_Occurrence_Of
(P_Type
, Loc
),
2649 Expressions
=> New_List
(
2650 Make_Attribute_Reference
(Loc
,
2651 Attribute_Name
=> Name_Last
,
2652 Prefix
=> New_Occurrence_Of
(P_Type
, Loc
)))),
2655 Make_Attribute_Reference
(Loc
,
2656 Attribute_Name
=> Name_Pos
,
2657 Prefix
=> New_Occurrence_Of
(P_Type
, Loc
),
2658 Expressions
=> New_List
(
2659 Make_Attribute_Reference
(Loc
,
2660 Attribute_Name
=> Name_First
,
2661 Prefix
=> New_Occurrence_Of
(P_Type
, Loc
))))),
2664 Make_Integer_Literal
(Loc
, 1)));
2666 Analyze_And_Resolve
(N
, Typ
);
2668 -- For all other cases, attribute is handled by Gigi, but we need
2669 -- to deal with the case of the range check on a universal integer.
2672 Apply_Universal_Integer_Attribute_Checks
(N
);
2681 when Attribute_Read
=> Read
: declare
2682 P_Type
: constant Entity_Id
:= Entity
(Pref
);
2683 B_Type
: constant Entity_Id
:= Base_Type
(P_Type
);
2684 U_Type
: constant Entity_Id
:= Underlying_Type
(P_Type
);
2694 -- If no underlying type, we have an error that will be diagnosed
2695 -- elsewhere, so here we just completely ignore the expansion.
2701 -- The simple case, if there is a TSS for Read, just call it
2703 Pname
:= Find_Stream_Subprogram
(P_Type
, TSS_Stream_Read
);
2705 if Present
(Pname
) then
2709 -- If there is a Stream_Convert pragma, use it, we rewrite
2711 -- sourcetyp'Read (stream, Item)
2715 -- Item := sourcetyp (strmread (strmtyp'Input (Stream)));
2717 -- where strmread is the given Read function that converts
2718 -- an argument of type strmtyp to type sourcetyp or a type
2719 -- from which it is derived. The conversion to sourcetyp
2720 -- is required in the latter case.
2722 -- A special case arises if Item is a type conversion in which
2723 -- case, we have to expand to:
2725 -- Itemx := typex (strmread (strmtyp'Input (Stream)));
2727 -- where Itemx is the expression of the type conversion (i.e.
2728 -- the actual object), and typex is the type of Itemx.
2732 (Implementation_Base_Type
(P_Type
), Name_Stream_Convert
);
2734 if Present
(Prag
) then
2735 Arg2
:= Next
(First
(Pragma_Argument_Associations
(Prag
)));
2736 Rfunc
:= Entity
(Expression
(Arg2
));
2737 Lhs
:= Relocate_Node
(Next
(First
(Exprs
)));
2740 Make_Function_Call
(Loc
,
2741 Name
=> New_Occurrence_Of
(Rfunc
, Loc
),
2742 Parameter_Associations
=> New_List
(
2743 Make_Attribute_Reference
(Loc
,
2746 (Etype
(First_Formal
(Rfunc
)), Loc
),
2747 Attribute_Name
=> Name_Input
,
2748 Expressions
=> New_List
(
2749 Relocate_Node
(First
(Exprs
)))))));
2751 if Nkind
(Lhs
) = N_Type_Conversion
then
2752 Lhs
:= Expression
(Lhs
);
2753 Rhs
:= Convert_To
(Etype
(Lhs
), Rhs
);
2757 Make_Assignment_Statement
(Loc
,
2759 Expression
=> Rhs
));
2760 Set_Assignment_OK
(Lhs
);
2764 -- For elementary types, we call the I_xxx routine using the first
2765 -- parameter and then assign the result into the second parameter.
2766 -- We set Assignment_OK to deal with the conversion case.
2768 elsif Is_Elementary_Type
(U_Type
) then
2774 Lhs
:= Relocate_Node
(Next
(First
(Exprs
)));
2775 Rhs
:= Build_Elementary_Input_Call
(N
);
2777 if Nkind
(Lhs
) = N_Type_Conversion
then
2778 Lhs
:= Expression
(Lhs
);
2779 Rhs
:= Convert_To
(Etype
(Lhs
), Rhs
);
2782 Set_Assignment_OK
(Lhs
);
2785 Make_Assignment_Statement
(Loc
,
2787 Expression
=> Rhs
));
2795 elsif Is_Array_Type
(U_Type
) then
2796 Build_Array_Read_Procedure
(N
, U_Type
, Decl
, Pname
);
2797 Compile_Stream_Body_In_Scope
(N
, Decl
, U_Type
, Check
=> False);
2799 -- Tagged type case, use the primitive Read function. Note that
2800 -- this will dispatch in the class-wide case which is what we want
2802 elsif Is_Tagged_Type
(U_Type
) then
2803 Pname
:= Find_Prim_Op
(U_Type
, TSS_Stream_Read
);
2805 -- All other record type cases, including protected records.
2806 -- The latter only arise for expander generated code for
2807 -- handling shared passive partition access.
2811 (Is_Record_Type
(U_Type
) or else Is_Protected_Type
(U_Type
));
2813 -- Ada 2005 (AI-216): Program_Error is raised when executing
2814 -- the default implementation of the Read attribute of an
2815 -- Unchecked_Union type.
2817 if Is_Unchecked_Union
(Base_Type
(U_Type
)) then
2819 Make_Raise_Program_Error
(Loc
,
2820 Reason
=> PE_Unchecked_Union_Restriction
));
2823 if Has_Discriminants
(U_Type
)
2825 (Discriminant_Default_Value
(First_Discriminant
(U_Type
)))
2827 Build_Mutable_Record_Read_Procedure
2828 (Loc
, Base_Type
(U_Type
), Decl
, Pname
);
2830 Build_Record_Read_Procedure
2831 (Loc
, Base_Type
(U_Type
), Decl
, Pname
);
2834 -- Suppress checks, uninitialized or otherwise invalid
2835 -- data does not cause constraint errors to be raised for
2836 -- a complete record read.
2838 Insert_Action
(N
, Decl
, All_Checks
);
2842 Rewrite_Stream_Proc_Call
(Pname
);
2849 -- Transforms 'Remainder into a call to the floating-point attribute
2850 -- function Remainder in Fat_xxx (where xxx is the root type)
2852 when Attribute_Remainder
=>
2853 Expand_Fpt_Attribute_RR
(N
);
2859 -- The handling of the Round attribute is quite delicate. The
2860 -- processing in Sem_Attr introduced a conversion to universal
2861 -- real, reflecting the semantics of Round, but we do not want
2862 -- anything to do with universal real at runtime, since this
2863 -- corresponds to using floating-point arithmetic.
2865 -- What we have now is that the Etype of the Round attribute
2866 -- correctly indicates the final result type. The operand of
2867 -- the Round is the conversion to universal real, described
2868 -- above, and the operand of this conversion is the actual
2869 -- operand of Round, which may be the special case of a fixed
2870 -- point multiplication or division (Etype = universal fixed)
2872 -- The exapander will expand first the operand of the conversion,
2873 -- then the conversion, and finally the round attribute itself,
2874 -- since we always work inside out. But we cannot simply process
2875 -- naively in this order. In the semantic world where universal
2876 -- fixed and real really exist and have infinite precision, there
2877 -- is no problem, but in the implementation world, where universal
2878 -- real is a floating-point type, we would get the wrong result.
2880 -- So the approach is as follows. First, when expanding a multiply
2881 -- or divide whose type is universal fixed, we do nothing at all,
2882 -- instead deferring the operation till later.
2884 -- The actual processing is done in Expand_N_Type_Conversion which
2885 -- handles the special case of Round by looking at its parent to
2886 -- see if it is a Round attribute, and if it is, handling the
2887 -- conversion (or its fixed multiply/divide child) in an appropriate
2890 -- This means that by the time we get to expanding the Round attribute
2891 -- itself, the Round is nothing more than a type conversion (and will
2892 -- often be a null type conversion), so we just replace it with the
2893 -- appropriate conversion operation.
2895 when Attribute_Round
=>
2897 Convert_To
(Etype
(N
), Relocate_Node
(First
(Exprs
))));
2898 Analyze_And_Resolve
(N
);
2904 -- Transforms 'Rounding into a call to the floating-point attribute
2905 -- function Rounding in Fat_xxx (where xxx is the root type)
2907 when Attribute_Rounding
=>
2908 Expand_Fpt_Attribute_R
(N
);
2914 -- Transforms 'Scaling into a call to the floating-point attribute
2915 -- function Scaling in Fat_xxx (where xxx is the root type)
2917 when Attribute_Scaling
=>
2918 Expand_Fpt_Attribute_RI
(N
);
2924 when Attribute_Size |
2925 Attribute_Object_Size |
2926 Attribute_Value_Size |
2927 Attribute_VADS_Size
=> Size
:
2930 Ptyp
: constant Entity_Id
:= Etype
(Pref
);
2935 -- Processing for VADS_Size case. Note that this processing removes
2936 -- all traces of VADS_Size from the tree, and completes all required
2937 -- processing for VADS_Size by translating the attribute reference
2938 -- to an appropriate Size or Object_Size reference.
2940 if Id
= Attribute_VADS_Size
2941 or else (Use_VADS_Size
and then Id
= Attribute_Size
)
2943 -- If the size is specified, then we simply use the specified
2944 -- size. This applies to both types and objects. The size of an
2945 -- object can be specified in the following ways:
2947 -- An explicit size object is given for an object
2948 -- A component size is specified for an indexed component
2949 -- A component clause is specified for a selected component
2950 -- The object is a component of a packed composite object
2952 -- If the size is specified, then VADS_Size of an object
2954 if (Is_Entity_Name
(Pref
)
2955 and then Present
(Size_Clause
(Entity
(Pref
))))
2957 (Nkind
(Pref
) = N_Component_Clause
2958 and then (Present
(Component_Clause
2959 (Entity
(Selector_Name
(Pref
))))
2960 or else Is_Packed
(Etype
(Prefix
(Pref
)))))
2962 (Nkind
(Pref
) = N_Indexed_Component
2963 and then (Component_Size
(Etype
(Prefix
(Pref
))) /= 0
2964 or else Is_Packed
(Etype
(Prefix
(Pref
)))))
2966 Set_Attribute_Name
(N
, Name_Size
);
2968 -- Otherwise if we have an object rather than a type, then the
2969 -- VADS_Size attribute applies to the type of the object, rather
2970 -- than the object itself. This is one of the respects in which
2971 -- VADS_Size differs from Size.
2974 if (not Is_Entity_Name
(Pref
)
2975 or else not Is_Type
(Entity
(Pref
)))
2976 and then (Is_Scalar_Type
(Etype
(Pref
))
2977 or else Is_Constrained
(Etype
(Pref
)))
2979 Rewrite
(Pref
, New_Occurrence_Of
(Etype
(Pref
), Loc
));
2982 -- For a scalar type for which no size was
2983 -- explicitly given, VADS_Size means Object_Size. This is the
2984 -- other respect in which VADS_Size differs from Size.
2986 if Is_Scalar_Type
(Etype
(Pref
))
2987 and then No
(Size_Clause
(Etype
(Pref
)))
2989 Set_Attribute_Name
(N
, Name_Object_Size
);
2991 -- In all other cases, Size and VADS_Size are the sane
2994 Set_Attribute_Name
(N
, Name_Size
);
2999 -- For class-wide types, X'Class'Size is transformed into a
3000 -- direct reference to the Size of the class type, so that gigi
3001 -- does not have to deal with the X'Class'Size reference.
3003 if Is_Entity_Name
(Pref
)
3004 and then Is_Class_Wide_Type
(Entity
(Pref
))
3006 Rewrite
(Prefix
(N
), New_Occurrence_Of
(Entity
(Pref
), Loc
));
3009 -- For x'Size applied to an object of a class wide type, transform
3010 -- X'Size into a call to the primitive operation _Size applied to X.
3012 elsif Is_Class_Wide_Type
(Ptyp
) then
3014 Make_Function_Call
(Loc
,
3015 Name
=> New_Reference_To
3016 (Find_Prim_Op
(Ptyp
, Name_uSize
), Loc
),
3017 Parameter_Associations
=> New_List
(Pref
));
3019 if Typ
/= Standard_Long_Long_Integer
then
3021 -- The context is a specific integer type with which the
3022 -- original attribute was compatible. The function has a
3023 -- specific type as well, so to preserve the compatibility
3024 -- we must convert explicitly.
3026 New_Node
:= Convert_To
(Typ
, New_Node
);
3029 Rewrite
(N
, New_Node
);
3030 Analyze_And_Resolve
(N
, Typ
);
3033 -- For an array component, we can do Size in the front end
3034 -- if the component_size of the array is set.
3036 elsif Nkind
(Pref
) = N_Indexed_Component
then
3037 Siz
:= Component_Size
(Etype
(Prefix
(Pref
)));
3039 -- For a record component, we can do Size in the front end
3040 -- if there is a component clause, or if the record is packed
3041 -- and the component's size is known at compile time.
3043 elsif Nkind
(Pref
) = N_Selected_Component
then
3045 Rec
: constant Entity_Id
:= Etype
(Prefix
(Pref
));
3046 Comp
: constant Entity_Id
:= Entity
(Selector_Name
(Pref
));
3049 if Present
(Component_Clause
(Comp
)) then
3050 Siz
:= Esize
(Comp
);
3052 elsif Is_Packed
(Rec
) then
3053 Siz
:= RM_Size
(Ptyp
);
3056 Apply_Universal_Integer_Attribute_Checks
(N
);
3061 -- All other cases are handled by Gigi
3064 Apply_Universal_Integer_Attribute_Checks
(N
);
3066 -- If we have Size applied to a formal parameter, that is a
3067 -- packed array subtype, then apply size to the actual subtype.
3069 if Is_Entity_Name
(Pref
)
3070 and then Is_Formal
(Entity
(Pref
))
3071 and then Is_Array_Type
(Etype
(Pref
))
3072 and then Is_Packed
(Etype
(Pref
))
3075 Make_Attribute_Reference
(Loc
,
3077 New_Occurrence_Of
(Get_Actual_Subtype
(Pref
), Loc
),
3078 Attribute_Name
=> Name_Size
));
3079 Analyze_And_Resolve
(N
, Typ
);
3085 -- Common processing for record and array component case
3089 Make_Integer_Literal
(Loc
, Siz
));
3091 Analyze_And_Resolve
(N
, Typ
);
3093 -- The result is not a static expression
3095 Set_Is_Static_Expression
(N
, False);
3103 when Attribute_Storage_Pool
=>
3105 Make_Type_Conversion
(Loc
,
3106 Subtype_Mark
=> New_Reference_To
(Etype
(N
), Loc
),
3107 Expression
=> New_Reference_To
(Entity
(N
), Loc
)));
3108 Analyze_And_Resolve
(N
, Typ
);
3114 when Attribute_Storage_Size
=> Storage_Size
:
3116 Ptyp
: constant Entity_Id
:= Etype
(Pref
);
3119 -- Access type case, always go to the root type
3121 -- The case of access types results in a value of zero for the case
3122 -- where no storage size attribute clause has been given. If a
3123 -- storage size has been given, then the attribute is converted
3124 -- to a reference to the variable used to hold this value.
3126 if Is_Access_Type
(Ptyp
) then
3127 if Present
(Storage_Size_Variable
(Root_Type
(Ptyp
))) then
3129 Make_Attribute_Reference
(Loc
,
3130 Prefix
=> New_Reference_To
(Typ
, Loc
),
3131 Attribute_Name
=> Name_Max
,
3132 Expressions
=> New_List
(
3133 Make_Integer_Literal
(Loc
, 0),
3136 (Storage_Size_Variable
(Root_Type
(Ptyp
)), Loc
)))));
3138 elsif Present
(Associated_Storage_Pool
(Root_Type
(Ptyp
))) then
3141 Make_Function_Call
(Loc
,
3145 (Etype
(Associated_Storage_Pool
(Root_Type
(Ptyp
))),
3146 Attribute_Name
(N
)),
3149 Parameter_Associations
=> New_List
(New_Reference_To
(
3150 Associated_Storage_Pool
(Root_Type
(Ptyp
)), Loc
)))));
3152 Rewrite
(N
, Make_Integer_Literal
(Loc
, 0));
3155 Analyze_And_Resolve
(N
, Typ
);
3157 -- The case of a task type (an obsolescent feature) is handled the
3158 -- same way, seems as reasonable as anything, and it is what the
3159 -- ACVC tests (e.g. CD1009K) seem to expect.
3161 -- If there is no Storage_Size variable, then we return the default
3162 -- task stack size, otherwise, expand a Storage_Size attribute as
3165 -- Typ (Adjust_Storage_Size (taskZ))
3167 -- except for the case of a task object which has a Storage_Size
3170 -- Typ (Adjust_Storage_Size (taskV!(name)._Size))
3173 if not Present
(Storage_Size_Variable
(Ptyp
)) then
3176 Make_Function_Call
(Loc
,
3178 New_Occurrence_Of
(RTE
(RE_Default_Stack_Size
), Loc
))));
3181 if not (Is_Entity_Name
(Pref
) and then
3182 Is_Task_Type
(Entity
(Pref
))) and then
3183 Chars
(Last_Entity
(Corresponding_Record_Type
(Ptyp
))) =
3188 Make_Function_Call
(Loc
,
3189 Name
=> New_Occurrence_Of
(
3190 RTE
(RE_Adjust_Storage_Size
), Loc
),
3191 Parameter_Associations
=>
3193 Make_Selected_Component
(Loc
,
3195 Unchecked_Convert_To
(
3196 Corresponding_Record_Type
(Ptyp
),
3197 New_Copy_Tree
(Pref
)),
3199 Make_Identifier
(Loc
, Name_uSize
))))));
3201 -- Task not having Storage_Size pragma
3206 Make_Function_Call
(Loc
,
3207 Name
=> New_Occurrence_Of
(
3208 RTE
(RE_Adjust_Storage_Size
), Loc
),
3209 Parameter_Associations
=>
3212 Storage_Size_Variable
(Ptyp
), Loc
)))));
3215 Analyze_And_Resolve
(N
, Typ
);
3224 -- 1. Deal with enumeration types with holes
3225 -- 2. For floating-point, generate call to attribute function
3226 -- 3. For other cases, deal with constraint checking
3228 when Attribute_Succ
=> Succ
:
3230 Ptyp
: constant Entity_Id
:= Base_Type
(Etype
(Pref
));
3233 -- For enumeration types with non-standard representations, we
3234 -- expand typ'Succ (x) into
3236 -- Pos_To_Rep (Rep_To_Pos (x) + 1)
3238 -- If the representation is contiguous, we compute instead
3239 -- Lit1 + Rep_to_Pos (x+1), to catch invalid representations.
3241 if Is_Enumeration_Type
(Ptyp
)
3242 and then Present
(Enum_Pos_To_Rep
(Ptyp
))
3244 if Has_Contiguous_Rep
(Ptyp
) then
3246 Unchecked_Convert_To
(Ptyp
,
3249 Make_Integer_Literal
(Loc
,
3250 Enumeration_Rep
(First_Literal
(Ptyp
))),
3252 Make_Function_Call
(Loc
,
3255 (TSS
(Ptyp
, TSS_Rep_To_Pos
), Loc
),
3257 Parameter_Associations
=>
3259 Unchecked_Convert_To
(Ptyp
,
3262 Unchecked_Convert_To
(Standard_Integer
,
3263 Relocate_Node
(First
(Exprs
))),
3265 Make_Integer_Literal
(Loc
, 1))),
3266 Rep_To_Pos_Flag
(Ptyp
, Loc
))))));
3268 -- Add Boolean parameter True, to request program errror if
3269 -- we have a bad representation on our hands. Add False if
3270 -- checks are suppressed.
3272 Append_To
(Exprs
, Rep_To_Pos_Flag
(Ptyp
, Loc
));
3274 Make_Indexed_Component
(Loc
,
3275 Prefix
=> New_Reference_To
(Enum_Pos_To_Rep
(Ptyp
), Loc
),
3276 Expressions
=> New_List
(
3279 Make_Function_Call
(Loc
,
3282 (TSS
(Ptyp
, TSS_Rep_To_Pos
), Loc
),
3283 Parameter_Associations
=> Exprs
),
3284 Right_Opnd
=> Make_Integer_Literal
(Loc
, 1)))));
3287 Analyze_And_Resolve
(N
, Typ
);
3289 -- For floating-point, we transform 'Succ into a call to the Succ
3290 -- floating-point attribute function in Fat_xxx (xxx is root type)
3292 elsif Is_Floating_Point_Type
(Ptyp
) then
3293 Expand_Fpt_Attribute_R
(N
);
3294 Analyze_And_Resolve
(N
, Typ
);
3296 -- For modular types, nothing to do (no overflow, since wraps)
3298 elsif Is_Modular_Integer_Type
(Ptyp
) then
3301 -- For other types, if range checking is enabled, we must generate
3302 -- a check if overflow checking is enabled.
3304 elsif not Overflow_Checks_Suppressed
(Ptyp
) then
3305 Expand_Pred_Succ
(N
);
3313 -- Transforms X'Tag into a direct reference to the tag of X
3315 when Attribute_Tag
=> Tag
:
3318 Prefix_Is_Type
: Boolean;
3321 if Is_Entity_Name
(Pref
) and then Is_Type
(Entity
(Pref
)) then
3322 Ttyp
:= Entity
(Pref
);
3323 Prefix_Is_Type
:= True;
3325 Ttyp
:= Etype
(Pref
);
3326 Prefix_Is_Type
:= False;
3329 if Is_Class_Wide_Type
(Ttyp
) then
3330 Ttyp
:= Root_Type
(Ttyp
);
3333 Ttyp
:= Underlying_Type
(Ttyp
);
3335 if Prefix_Is_Type
then
3337 -- For JGNAT we leave the type attribute unexpanded because
3338 -- there's not a dispatching table to reference.
3342 Unchecked_Convert_To
(RTE
(RE_Tag
),
3343 New_Reference_To
(Access_Disp_Table
(Ttyp
), Loc
)));
3344 Analyze_And_Resolve
(N
, RTE
(RE_Tag
));
3349 Make_Selected_Component
(Loc
,
3350 Prefix
=> Relocate_Node
(Pref
),
3352 New_Reference_To
(Tag_Component
(Ttyp
), Loc
)));
3353 Analyze_And_Resolve
(N
, RTE
(RE_Tag
));
3361 -- Transforms 'Terminated attribute into a call to Terminated function.
3363 when Attribute_Terminated
=> Terminated
:
3365 if Restricted_Profile
then
3367 Build_Call_With_Task
(Pref
, RTE
(RE_Restricted_Terminated
)));
3371 Build_Call_With_Task
(Pref
, RTE
(RE_Terminated
)));
3374 Analyze_And_Resolve
(N
, Standard_Boolean
);
3381 -- Transforms System'To_Address (X) into unchecked conversion
3382 -- from (integral) type of X to type address.
3384 when Attribute_To_Address
=>
3386 Unchecked_Convert_To
(RTE
(RE_Address
),
3387 Relocate_Node
(First
(Exprs
))));
3388 Analyze_And_Resolve
(N
, RTE
(RE_Address
));
3394 -- Transforms 'Truncation into a call to the floating-point attribute
3395 -- function Truncation in Fat_xxx (where xxx is the root type)
3397 when Attribute_Truncation
=>
3398 Expand_Fpt_Attribute_R
(N
);
3400 -----------------------
3401 -- Unbiased_Rounding --
3402 -----------------------
3404 -- Transforms 'Unbiased_Rounding into a call to the floating-point
3405 -- attribute function Unbiased_Rounding in Fat_xxx (where xxx is the
3408 when Attribute_Unbiased_Rounding
=>
3409 Expand_Fpt_Attribute_R
(N
);
3411 ----------------------
3412 -- Unchecked_Access --
3413 ----------------------
3415 when Attribute_Unchecked_Access
=>
3416 Expand_Access_To_Type
(N
);
3422 when Attribute_UET_Address
=> UET_Address
: declare
3423 Ent
: constant Entity_Id
:=
3424 Make_Defining_Identifier
(Loc
, New_Internal_Name
('T'));
3428 Make_Object_Declaration
(Loc
,
3429 Defining_Identifier
=> Ent
,
3430 Aliased_Present
=> True,
3431 Object_Definition
=>
3432 New_Occurrence_Of
(RTE
(RE_Address
), Loc
)));
3434 -- Construct name __gnat_xxx__SDP, where xxx is the unit name
3435 -- in normal external form.
3437 Get_External_Unit_Name_String
(Get_Unit_Name
(Pref
));
3438 Name_Buffer
(1 + 7 .. Name_Len
+ 7) := Name_Buffer
(1 .. Name_Len
);
3439 Name_Len
:= Name_Len
+ 7;
3440 Name_Buffer
(1 .. 7) := "__gnat_";
3441 Name_Buffer
(Name_Len
+ 1 .. Name_Len
+ 5) := "__SDP";
3442 Name_Len
:= Name_Len
+ 5;
3444 Set_Is_Imported
(Ent
);
3445 Set_Interface_Name
(Ent
,
3446 Make_String_Literal
(Loc
,
3447 Strval
=> String_From_Name_Buffer
));
3450 Make_Attribute_Reference
(Loc
,
3451 Prefix
=> New_Occurrence_Of
(Ent
, Loc
),
3452 Attribute_Name
=> Name_Address
));
3454 Analyze_And_Resolve
(N
, Typ
);
3457 -------------------------
3458 -- Unrestricted_Access --
3459 -------------------------
3461 when Attribute_Unrestricted_Access
=>
3462 Expand_Access_To_Type
(N
);
3468 -- The processing for VADS_Size is shared with Size
3474 -- For enumeration types with a standard representation, and for all
3475 -- other types, Val is handled by Gigi. For enumeration types with
3476 -- a non-standard representation we use the _Pos_To_Rep array that
3477 -- was created when the type was frozen.
3479 when Attribute_Val
=> Val
:
3481 Etyp
: constant Entity_Id
:= Base_Type
(Entity
(Pref
));
3484 if Is_Enumeration_Type
(Etyp
)
3485 and then Present
(Enum_Pos_To_Rep
(Etyp
))
3487 if Has_Contiguous_Rep
(Etyp
) then
3489 Rep_Node
: constant Node_Id
:=
3490 Unchecked_Convert_To
(Etyp
,
3493 Make_Integer_Literal
(Loc
,
3494 Enumeration_Rep
(First_Literal
(Etyp
))),
3496 (Convert_To
(Standard_Integer
,
3497 Relocate_Node
(First
(Exprs
))))));
3501 Unchecked_Convert_To
(Etyp
,
3504 Make_Integer_Literal
(Loc
,
3505 Enumeration_Rep
(First_Literal
(Etyp
))),
3507 Make_Function_Call
(Loc
,
3510 (TSS
(Etyp
, TSS_Rep_To_Pos
), Loc
),
3511 Parameter_Associations
=> New_List
(
3513 Rep_To_Pos_Flag
(Etyp
, Loc
))))));
3518 Make_Indexed_Component
(Loc
,
3519 Prefix
=> New_Reference_To
(Enum_Pos_To_Rep
(Etyp
), Loc
),
3520 Expressions
=> New_List
(
3521 Convert_To
(Standard_Integer
,
3522 Relocate_Node
(First
(Exprs
))))));
3525 Analyze_And_Resolve
(N
, Typ
);
3533 -- The code for valid is dependent on the particular types involved.
3534 -- See separate sections below for the generated code in each case.
3536 when Attribute_Valid
=> Valid
:
3538 Ptyp
: constant Entity_Id
:= Etype
(Pref
);
3539 Btyp
: Entity_Id
:= Base_Type
(Ptyp
);
3542 Save_Validity_Checks_On
: constant Boolean := Validity_Checks_On
;
3543 -- Save the validity checking mode. We always turn off validity
3544 -- checking during process of 'Valid since this is one place
3545 -- where we do not want the implicit validity checks to intefere
3546 -- with the explicit validity check that the programmer is doing.
3548 function Make_Range_Test
return Node_Id
;
3549 -- Build the code for a range test of the form
3550 -- Btyp!(Pref) >= Btyp!(Ptyp'First)
3552 -- Btyp!(Pref) <= Btyp!(Ptyp'Last)
3554 ---------------------
3555 -- Make_Range_Test --
3556 ---------------------
3558 function Make_Range_Test
return Node_Id
is
3565 Unchecked_Convert_To
(Btyp
, Duplicate_Subexpr
(Pref
)),
3568 Unchecked_Convert_To
(Btyp
,
3569 Make_Attribute_Reference
(Loc
,
3570 Prefix
=> New_Occurrence_Of
(Ptyp
, Loc
),
3571 Attribute_Name
=> Name_First
))),
3576 Unchecked_Convert_To
(Btyp
,
3577 Duplicate_Subexpr_No_Checks
(Pref
)),
3580 Unchecked_Convert_To
(Btyp
,
3581 Make_Attribute_Reference
(Loc
,
3582 Prefix
=> New_Occurrence_Of
(Ptyp
, Loc
),
3583 Attribute_Name
=> Name_Last
))));
3584 end Make_Range_Test
;
3586 -- Start of processing for Attribute_Valid
3589 -- Turn off validity checks. We do not want any implicit validity
3590 -- checks to intefere with the explicit check from the attribute
3592 Validity_Checks_On
:= False;
3594 -- Floating-point case. This case is handled by the Valid attribute
3595 -- code in the floating-point attribute run-time library.
3597 if Is_Floating_Point_Type
(Ptyp
) then
3599 Rtp
: constant Entity_Id
:= Root_Type
(Etype
(Pref
));
3602 -- If the floating-point object might be unaligned, we need
3603 -- to call the special routine Unaligned_Valid, which makes
3604 -- the needed copy, being careful not to load the value into
3605 -- any floating-point register. The argument in this case is
3606 -- obj'Address (see Unchecked_Valid routine in s-fatgen.ads).
3608 if Is_Possibly_Unaligned_Object
(Pref
) then
3609 Set_Attribute_Name
(N
, Name_Unaligned_Valid
);
3610 Expand_Fpt_Attribute
3611 (N
, Rtp
, Name_Unaligned_Valid
,
3613 Make_Attribute_Reference
(Loc
,
3614 Prefix
=> Relocate_Node
(Pref
),
3615 Attribute_Name
=> Name_Address
)));
3617 -- In the normal case where we are sure the object is aligned,
3618 -- we generate a caqll to Valid, and the argument in this case
3619 -- is obj'Unrestricted_Access (after converting obj to the
3620 -- right floating-point type).
3623 Expand_Fpt_Attribute
3624 (N
, Rtp
, Name_Valid
,
3626 Make_Attribute_Reference
(Loc
,
3627 Prefix
=> Unchecked_Convert_To
(Rtp
, Pref
),
3628 Attribute_Name
=> Name_Unrestricted_Access
)));
3631 -- One more task, we still need a range check. Required
3632 -- only if we have a constraint, since the Valid routine
3633 -- catches infinities properly (infinities are never valid).
3635 -- The way we do the range check is simply to create the
3636 -- expression: Valid (N) and then Base_Type(Pref) in Typ.
3638 if not Subtypes_Statically_Match
(Ptyp
, Btyp
) then
3641 Left_Opnd
=> Relocate_Node
(N
),
3644 Left_Opnd
=> Convert_To
(Btyp
, Pref
),
3645 Right_Opnd
=> New_Occurrence_Of
(Ptyp
, Loc
))));
3649 -- Enumeration type with holes
3651 -- For enumeration types with holes, the Pos value constructed by
3652 -- the Enum_Rep_To_Pos function built in Exp_Ch3 called with a
3653 -- second argument of False returns minus one for an invalid value,
3654 -- and the non-negative pos value for a valid value, so the
3655 -- expansion of X'Valid is simply:
3657 -- type(X)'Pos (X) >= 0
3659 -- We can't quite generate it that way because of the requirement
3660 -- for the non-standard second argument of False in the resulting
3661 -- rep_to_pos call, so we have to explicitly create:
3663 -- _rep_to_pos (X, False) >= 0
3665 -- If we have an enumeration subtype, we also check that the
3666 -- value is in range:
3668 -- _rep_to_pos (X, False) >= 0
3670 -- (X >= type(X)'First and then type(X)'Last <= X)
3672 elsif Is_Enumeration_Type
(Ptyp
)
3673 and then Present
(Enum_Pos_To_Rep
(Base_Type
(Ptyp
)))
3678 Make_Function_Call
(Loc
,
3681 (TSS
(Base_Type
(Ptyp
), TSS_Rep_To_Pos
), Loc
),
3682 Parameter_Associations
=> New_List
(
3684 New_Occurrence_Of
(Standard_False
, Loc
))),
3685 Right_Opnd
=> Make_Integer_Literal
(Loc
, 0));
3689 (Type_Low_Bound
(Ptyp
) /= Type_Low_Bound
(Btyp
)
3691 Type_High_Bound
(Ptyp
) /= Type_High_Bound
(Btyp
))
3693 -- The call to Make_Range_Test will create declarations
3694 -- that need a proper insertion point, but Pref is now
3695 -- attached to a node with no ancestor. Attach to tree
3696 -- even if it is to be rewritten below.
3698 Set_Parent
(Tst
, Parent
(N
));
3702 Left_Opnd
=> Make_Range_Test
,
3708 -- Fortran convention booleans
3710 -- For the very special case of Fortran convention booleans, the
3711 -- value is always valid, since it is an integer with the semantics
3712 -- that non-zero is true, and any value is permissible.
3714 elsif Is_Boolean_Type
(Ptyp
)
3715 and then Convention
(Ptyp
) = Convention_Fortran
3717 Rewrite
(N
, New_Occurrence_Of
(Standard_True
, Loc
));
3719 -- For biased representations, we will be doing an unchecked
3720 -- conversion without unbiasing the result. That means that
3721 -- the range test has to take this into account, and the
3722 -- proper form of the test is:
3724 -- Btyp!(Pref) < Btyp!(Ptyp'Range_Length)
3726 elsif Has_Biased_Representation
(Ptyp
) then
3727 Btyp
:= RTE
(RE_Unsigned_32
);
3731 Unchecked_Convert_To
(Btyp
, Duplicate_Subexpr
(Pref
)),
3733 Unchecked_Convert_To
(Btyp
,
3734 Make_Attribute_Reference
(Loc
,
3735 Prefix
=> New_Occurrence_Of
(Ptyp
, Loc
),
3736 Attribute_Name
=> Name_Range_Length
))));
3738 -- For all other scalar types, what we want logically is a
3741 -- X in type(X)'First .. type(X)'Last
3743 -- But that's precisely what won't work because of possible
3744 -- unwanted optimization (and indeed the basic motivation for
3745 -- the Valid attribute is exactly that this test does not work!)
3746 -- What will work is:
3748 -- Btyp!(X) >= Btyp!(type(X)'First)
3750 -- Btyp!(X) <= Btyp!(type(X)'Last)
3752 -- where Btyp is an integer type large enough to cover the full
3753 -- range of possible stored values (i.e. it is chosen on the basis
3754 -- of the size of the type, not the range of the values). We write
3755 -- this as two tests, rather than a range check, so that static
3756 -- evaluation will easily remove either or both of the checks if
3757 -- they can be -statically determined to be true (this happens
3758 -- when the type of X is static and the range extends to the full
3759 -- range of stored values).
3761 -- Unsigned types. Note: it is safe to consider only whether the
3762 -- subtype is unsigned, since we will in that case be doing all
3763 -- unsigned comparisons based on the subtype range. Since we use
3764 -- the actual subtype object size, this is appropriate.
3766 -- For example, if we have
3768 -- subtype x is integer range 1 .. 200;
3769 -- for x'Object_Size use 8;
3771 -- Now the base type is signed, but objects of this type are 8
3772 -- bits unsigned, and doing an unsigned test of the range 1 to
3773 -- 200 is correct, even though a value greater than 127 looks
3774 -- signed to a signed comparison.
3776 elsif Is_Unsigned_Type
(Ptyp
) then
3777 if Esize
(Ptyp
) <= 32 then
3778 Btyp
:= RTE
(RE_Unsigned_32
);
3780 Btyp
:= RTE
(RE_Unsigned_64
);
3783 Rewrite
(N
, Make_Range_Test
);
3788 if Esize
(Ptyp
) <= Esize
(Standard_Integer
) then
3789 Btyp
:= Standard_Integer
;
3791 Btyp
:= Universal_Integer
;
3794 Rewrite
(N
, Make_Range_Test
);
3797 Analyze_And_Resolve
(N
, Standard_Boolean
);
3798 Validity_Checks_On
:= Save_Validity_Checks_On
;
3805 -- Value attribute is handled in separate unti Exp_Imgv
3807 when Attribute_Value
=>
3808 Exp_Imgv
.Expand_Value_Attribute
(N
);
3814 -- The processing for Value_Size shares the processing for Size
3820 -- The processing for Version shares the processing for Body_Version
3826 -- We expand typ'Wide_Image (X) into
3828 -- String_To_Wide_String
3829 -- (typ'Image (X), Wide_Character_Encoding_Method)
3831 -- This works in all cases because String_To_Wide_String converts any
3832 -- wide character escape sequences resulting from the Image call to the
3833 -- proper Wide_Character equivalent
3835 -- not quite right for typ = Wide_Character ???
3837 when Attribute_Wide_Image
=> Wide_Image
:
3840 Make_Function_Call
(Loc
,
3841 Name
=> New_Reference_To
(RTE
(RE_String_To_Wide_String
), Loc
),
3842 Parameter_Associations
=> New_List
(
3843 Make_Attribute_Reference
(Loc
,
3845 Attribute_Name
=> Name_Image
,
3846 Expressions
=> Exprs
),
3848 Make_Integer_Literal
(Loc
,
3849 Intval
=> Int
(Wide_Character_Encoding_Method
)))));
3851 Analyze_And_Resolve
(N
, Standard_Wide_String
);
3858 -- We expand typ'Wide_Value (X) into
3861 -- (Wide_String_To_String (X, Wide_Character_Encoding_Method))
3863 -- Wide_String_To_String is a runtime function that converts its wide
3864 -- string argument to String, converting any non-translatable characters
3865 -- into appropriate escape sequences. This preserves the required
3866 -- semantics of Wide_Value in all cases, and results in a very simple
3867 -- implementation approach.
3869 -- It's not quite right where typ = Wide_Character, because the encoding
3870 -- method may not cover the whole character type ???
3872 when Attribute_Wide_Value
=> Wide_Value
:
3875 Make_Attribute_Reference
(Loc
,
3877 Attribute_Name
=> Name_Value
,
3879 Expressions
=> New_List
(
3880 Make_Function_Call
(Loc
,
3882 New_Reference_To
(RTE
(RE_Wide_String_To_String
), Loc
),
3884 Parameter_Associations
=> New_List
(
3885 Relocate_Node
(First
(Exprs
)),
3886 Make_Integer_Literal
(Loc
,
3887 Intval
=> Int
(Wide_Character_Encoding_Method
)))))));
3889 Analyze_And_Resolve
(N
, Typ
);
3896 -- Wide_Width attribute is handled in separate unit Exp_Imgv
3898 when Attribute_Wide_Width
=>
3899 Exp_Imgv
.Expand_Width_Attribute
(N
, Wide
=> True);
3905 -- Width attribute is handled in separate unit Exp_Imgv
3907 when Attribute_Width
=>
3908 Exp_Imgv
.Expand_Width_Attribute
(N
, Wide
=> False);
3914 when Attribute_Write
=> Write
: declare
3915 P_Type
: constant Entity_Id
:= Entity
(Pref
);
3916 U_Type
: constant Entity_Id
:= Underlying_Type
(P_Type
);
3924 -- If no underlying type, we have an error that will be diagnosed
3925 -- elsewhere, so here we just completely ignore the expansion.
3931 -- The simple case, if there is a TSS for Write, just call it
3933 Pname
:= Find_Stream_Subprogram
(P_Type
, TSS_Stream_Write
);
3935 if Present
(Pname
) then
3939 -- If there is a Stream_Convert pragma, use it, we rewrite
3941 -- sourcetyp'Output (stream, Item)
3945 -- strmtyp'Output (Stream, strmwrite (acttyp (Item)));
3947 -- where strmwrite is the given Write function that converts
3948 -- an argument of type sourcetyp or a type acctyp, from which
3949 -- it is derived to type strmtyp. The conversion to acttyp is
3950 -- required for the derived case.
3954 (Implementation_Base_Type
(P_Type
), Name_Stream_Convert
);
3956 if Present
(Prag
) then
3958 Next
(Next
(First
(Pragma_Argument_Associations
(Prag
))));
3959 Wfunc
:= Entity
(Expression
(Arg3
));
3962 Make_Attribute_Reference
(Loc
,
3963 Prefix
=> New_Occurrence_Of
(Etype
(Wfunc
), Loc
),
3964 Attribute_Name
=> Name_Output
,
3965 Expressions
=> New_List
(
3966 Relocate_Node
(First
(Exprs
)),
3967 Make_Function_Call
(Loc
,
3968 Name
=> New_Occurrence_Of
(Wfunc
, Loc
),
3969 Parameter_Associations
=> New_List
(
3970 Convert_To
(Etype
(First_Formal
(Wfunc
)),
3971 Relocate_Node
(Next
(First
(Exprs
)))))))));
3976 -- For elementary types, we call the W_xxx routine directly
3978 elsif Is_Elementary_Type
(U_Type
) then
3979 Rewrite
(N
, Build_Elementary_Write_Call
(N
));
3985 elsif Is_Array_Type
(U_Type
) then
3986 Build_Array_Write_Procedure
(N
, U_Type
, Decl
, Pname
);
3987 Compile_Stream_Body_In_Scope
(N
, Decl
, U_Type
, Check
=> False);
3989 -- Tagged type case, use the primitive Write function. Note that
3990 -- this will dispatch in the class-wide case which is what we want
3992 elsif Is_Tagged_Type
(U_Type
) then
3993 Pname
:= Find_Prim_Op
(U_Type
, TSS_Stream_Write
);
3995 -- All other record type cases, including protected records.
3996 -- The latter only arise for expander generated code for
3997 -- handling shared passive partition access.
4001 (Is_Record_Type
(U_Type
) or else Is_Protected_Type
(U_Type
));
4003 -- Ada 2005 (AI-216): Program_Error is raised when executing
4004 -- the default implementation of the Write attribute of an
4005 -- Unchecked_Union type.
4007 if Is_Unchecked_Union
(Base_Type
(U_Type
)) then
4009 Make_Raise_Program_Error
(Loc
,
4010 Reason
=> PE_Unchecked_Union_Restriction
));
4013 if Has_Discriminants
(U_Type
)
4015 (Discriminant_Default_Value
(First_Discriminant
(U_Type
)))
4017 Build_Mutable_Record_Write_Procedure
4018 (Loc
, Base_Type
(U_Type
), Decl
, Pname
);
4020 Build_Record_Write_Procedure
4021 (Loc
, Base_Type
(U_Type
), Decl
, Pname
);
4024 Insert_Action
(N
, Decl
);
4028 -- If we fall through, Pname is the procedure to be called
4030 Rewrite_Stream_Proc_Call
(Pname
);
4033 -- Component_Size is handled by Gigi, unless the component size is
4034 -- known at compile time, which is always true in the packed array
4035 -- case. It is important that the packed array case is handled in
4036 -- the front end (see Eval_Attribute) since Gigi would otherwise
4037 -- get confused by the equivalent packed array type.
4039 when Attribute_Component_Size
=>
4042 -- The following attributes are handled by Gigi (except that static
4043 -- cases have already been evaluated by the semantics, but in any
4044 -- case Gigi should not count on that).
4046 -- In addition Gigi handles the non-floating-point cases of Pred
4047 -- and Succ (including the fixed-point cases, which can just be
4048 -- treated as integer increment/decrement operations)
4050 -- Gigi also handles the non-class-wide cases of Size
4052 when Attribute_Bit_Order |
4053 Attribute_Code_Address |
4054 Attribute_Definite |
4056 Attribute_Mechanism_Code |
4058 Attribute_Null_Parameter |
4059 Attribute_Passed_By_Reference |
4060 Attribute_Pool_Address
=>
4063 -- The following attributes are also handled by Gigi, but return a
4064 -- universal integer result, so may need a conversion for checking
4065 -- that the result is in range.
4067 when Attribute_Aft |
4069 Attribute_Max_Size_In_Storage_Elements
4071 Apply_Universal_Integer_Attribute_Checks
(N
);
4073 -- The following attributes should not appear at this stage, since they
4074 -- have already been handled by the analyzer (and properly rewritten
4075 -- with corresponding values or entities to represent the right values)
4077 when Attribute_Abort_Signal |
4078 Attribute_Address_Size |
4081 Attribute_Default_Bit_Order |
4087 Attribute_Has_Access_Values |
4088 Attribute_Has_Discriminants |
4090 Attribute_Machine_Emax |
4091 Attribute_Machine_Emin |
4092 Attribute_Machine_Mantissa |
4093 Attribute_Machine_Overflows |
4094 Attribute_Machine_Radix |
4095 Attribute_Machine_Rounds |
4096 Attribute_Maximum_Alignment |
4097 Attribute_Model_Emin |
4098 Attribute_Model_Epsilon |
4099 Attribute_Model_Mantissa |
4100 Attribute_Model_Small |
4102 Attribute_Partition_ID |
4104 Attribute_Safe_Emax |
4105 Attribute_Safe_First |
4106 Attribute_Safe_Large |
4107 Attribute_Safe_Last |
4108 Attribute_Safe_Small |
4110 Attribute_Signed_Zeros |
4112 Attribute_Storage_Unit |
4113 Attribute_Target_Name |
4114 Attribute_Type_Class |
4115 Attribute_Unconstrained_Array |
4116 Attribute_Universal_Literal_String |
4117 Attribute_Wchar_T_Size |
4118 Attribute_Word_Size
=>
4120 raise Program_Error
;
4122 -- The Asm_Input and Asm_Output attributes are not expanded at this
4123 -- stage, but will be eliminated in the expansion of the Asm call,
4124 -- see Exp_Intr for details. So Gigi will never see these either.
4126 when Attribute_Asm_Input |
4127 Attribute_Asm_Output
=>
4134 when RE_Not_Available
=>
4136 end Expand_N_Attribute_Reference
;
4138 ----------------------
4139 -- Expand_Pred_Succ --
4140 ----------------------
4142 -- For typ'Pred (exp), we generate the check
4144 -- [constraint_error when exp = typ'Base'First]
4146 -- Similarly, for typ'Succ (exp), we generate the check
4148 -- [constraint_error when exp = typ'Base'Last]
4150 -- These checks are not generated for modular types, since the proper
4151 -- semantics for Succ and Pred on modular types is to wrap, not raise CE.
4153 procedure Expand_Pred_Succ
(N
: Node_Id
) is
4154 Loc
: constant Source_Ptr
:= Sloc
(N
);
4158 if Attribute_Name
(N
) = Name_Pred
then
4165 Make_Raise_Constraint_Error
(Loc
,
4169 Duplicate_Subexpr_Move_Checks
(First
(Expressions
(N
))),
4171 Make_Attribute_Reference
(Loc
,
4173 New_Reference_To
(Base_Type
(Etype
(Prefix
(N
))), Loc
),
4174 Attribute_Name
=> Cnam
)),
4175 Reason
=> CE_Overflow_Check_Failed
));
4177 end Expand_Pred_Succ
;
4179 ------------------------
4180 -- Find_Inherited_TSS --
4181 ------------------------
4183 function Find_Inherited_TSS
4185 Nam
: TSS_Name_Type
) return Entity_Id
4187 Btyp
: Entity_Id
:= Typ
;
4192 Btyp
:= Base_Type
(Btyp
);
4193 Proc
:= TSS
(Btyp
, Nam
);
4195 exit when Present
(Proc
)
4196 or else not Is_Derived_Type
(Btyp
);
4198 -- If Typ is a derived type, it may inherit attributes from
4201 Btyp
:= Etype
(Btyp
);
4206 -- If nothing else, use the TSS of the root type
4208 Proc
:= TSS
(Base_Type
(Underlying_Type
(Typ
)), Nam
);
4213 end Find_Inherited_TSS
;
4215 ----------------------------
4216 -- Find_Stream_Subprogram --
4217 ----------------------------
4219 function Find_Stream_Subprogram
4221 Nam
: TSS_Name_Type
) return Entity_Id
is
4223 if Is_Tagged_Type
(Typ
)
4224 and then Is_Derived_Type
(Typ
)
4226 return Find_Prim_Op
(Typ
, Nam
);
4228 return Find_Inherited_TSS
(Typ
, Nam
);
4230 end Find_Stream_Subprogram
;
4232 -----------------------
4233 -- Get_Index_Subtype --
4234 -----------------------
4236 function Get_Index_Subtype
(N
: Node_Id
) return Node_Id
is
4237 P_Type
: Entity_Id
:= Etype
(Prefix
(N
));
4242 if Is_Access_Type
(P_Type
) then
4243 P_Type
:= Designated_Type
(P_Type
);
4246 if No
(Expressions
(N
)) then
4249 J
:= UI_To_Int
(Expr_Value
(First
(Expressions
(N
))));
4252 Indx
:= First_Index
(P_Type
);
4258 return Etype
(Indx
);
4259 end Get_Index_Subtype
;
4261 ---------------------------------
4262 -- Is_Constrained_Packed_Array --
4263 ---------------------------------
4265 function Is_Constrained_Packed_Array
(Typ
: Entity_Id
) return Boolean is
4266 Arr
: Entity_Id
:= Typ
;
4269 if Is_Access_Type
(Arr
) then
4270 Arr
:= Designated_Type
(Arr
);
4273 return Is_Array_Type
(Arr
)
4274 and then Is_Constrained
(Arr
)
4275 and then Present
(Packed_Array_Type
(Arr
));
4276 end Is_Constrained_Packed_Array
;