1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2006, 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, 51 Franklin Street, Fifth Floor, --
20 -- Boston, MA 02110-1301, 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 Exp_VFpt
; use Exp_VFpt
;
39 with Gnatvsn
; use Gnatvsn
;
40 with Hostparm
; use Hostparm
;
42 with Namet
; use Namet
;
43 with Nmake
; use Nmake
;
44 with Nlists
; use Nlists
;
46 with Restrict
; use Restrict
;
47 with Rident
; use Rident
;
48 with Rtsfind
; use Rtsfind
;
50 with Sem_Ch7
; use Sem_Ch7
;
51 with Sem_Ch8
; use Sem_Ch8
;
52 with Sem_Eval
; use Sem_Eval
;
53 with Sem_Res
; use Sem_Res
;
54 with Sem_Util
; use Sem_Util
;
55 with Sinfo
; use Sinfo
;
56 with Snames
; use Snames
;
57 with Stand
; use Stand
;
58 with Stringt
; use Stringt
;
59 with Tbuild
; use Tbuild
;
60 with Ttypes
; use Ttypes
;
61 with Uintp
; use Uintp
;
62 with Uname
; use Uname
;
63 with Validsw
; use Validsw
;
65 package body Exp_Attr
is
67 -----------------------
68 -- Local Subprograms --
69 -----------------------
71 procedure Compile_Stream_Body_In_Scope
76 -- The body for a stream subprogram may be generated outside of the scope
77 -- of the type. If the type is fully private, it may depend on the full
78 -- view of other types (e.g. indices) that are currently private as well.
79 -- We install the declarations of the package in which the type is declared
80 -- before compiling the body in what is its proper environment. The Check
81 -- parameter indicates if checks are to be suppressed for the stream body.
82 -- We suppress checks for array/record reads, since the rule is that these
83 -- are like assignments, out of range values due to uninitialized storage,
84 -- or other invalid values do NOT cause a Constraint_Error to be raised.
86 procedure Expand_Access_To_Protected_Op
91 -- An attribute reference to a protected subprogram is transformed into
92 -- a pair of pointers: one to the object, and one to the operations.
93 -- This expansion is performed for 'Access and for 'Unrestricted_Access.
95 procedure Expand_Fpt_Attribute
100 -- This procedure expands a call to a floating-point attribute function.
101 -- N is the attribute reference node, and Args is a list of arguments to
102 -- be passed to the function call. Pkg identifies the package containing
103 -- the appropriate instantiation of System.Fat_Gen. Float arguments in Args
104 -- have already been converted to the floating-point type for which Pkg was
105 -- instantiated. The Nam argument is the relevant attribute processing
106 -- routine to be called. This is the same as the attribute name, except in
107 -- the Unaligned_Valid case.
109 procedure Expand_Fpt_Attribute_R
(N
: Node_Id
);
110 -- This procedure expands a call to a floating-point attribute function
111 -- that takes a single floating-point argument. The function to be called
112 -- is always the same as the attribute name.
114 procedure Expand_Fpt_Attribute_RI
(N
: Node_Id
);
115 -- This procedure expands a call to a floating-point attribute function
116 -- that takes one floating-point argument and one integer argument. The
117 -- function to be called is always the same as the attribute name.
119 procedure Expand_Fpt_Attribute_RR
(N
: Node_Id
);
120 -- This procedure expands a call to a floating-point attribute function
121 -- that takes two floating-point arguments. The function to be called
122 -- is always the same as the attribute name.
124 procedure Expand_Pred_Succ
(N
: Node_Id
);
125 -- Handles expansion of Pred or Succ attributes for case of non-real
126 -- operand with overflow checking required.
128 function Get_Index_Subtype
(N
: Node_Id
) return Entity_Id
;
129 -- Used for Last, Last, and Length, when the prefix is an array type,
130 -- Obtains the corresponding index subtype.
132 procedure Expand_Access_To_Type
(N
: Node_Id
);
133 -- A reference to a type within its own scope is resolved to a reference
134 -- to the current instance of the type in its initialization procedure.
136 procedure Find_Fat_Info
138 Fat_Type
: out Entity_Id
;
139 Fat_Pkg
: out RE_Id
);
140 -- Given a floating-point type T, identifies the package containing the
141 -- attributes for this type (returned in Fat_Pkg), and the corresponding
142 -- type for which this package was instantiated from Fat_Gen. Error if T
143 -- is not a floating-point type.
145 function Find_Stream_Subprogram
147 Nam
: TSS_Name_Type
) return Entity_Id
;
148 -- Returns the stream-oriented subprogram attribute for Typ. For tagged
149 -- types, the corresponding primitive operation is looked up, else the
150 -- appropriate TSS from the type itself, or from its closest ancestor
151 -- defining it, is returned. In both cases, inheritance of representation
152 -- aspects is thus taken into account.
154 function Get_Stream_Convert_Pragma
(T
: Entity_Id
) return Node_Id
;
155 -- Given a type, find a corresponding stream convert pragma that applies to
156 -- the implementation base type of this type (Typ). If found, return the
157 -- pragma node, otherwise return Empty if no pragma is found.
159 function Is_Constrained_Packed_Array
(Typ
: Entity_Id
) return Boolean;
160 -- Utility for array attributes, returns true on packed constrained
161 -- arrays, and on access to same.
163 ----------------------------------
164 -- Compile_Stream_Body_In_Scope --
165 ----------------------------------
167 procedure Compile_Stream_Body_In_Scope
173 Installed
: Boolean := False;
174 Scop
: constant Entity_Id
:= Scope
(Arr
);
175 Curr
: constant Entity_Id
:= Current_Scope
;
179 and then not In_Open_Scopes
(Scop
)
180 and then Ekind
(Scop
) = E_Package
183 Install_Visible_Declarations
(Scop
);
184 Install_Private_Declarations
(Scop
);
187 -- The entities in the package are now visible, but the generated
188 -- stream entity must appear in the current scope (usually an
189 -- enclosing stream function) so that itypes all have their proper
196 Insert_Action
(N
, Decl
);
198 Insert_Action
(N
, Decl
, Suppress
=> All_Checks
);
203 -- Remove extra copy of current scope, and package itself
206 End_Package_Scope
(Scop
);
208 end Compile_Stream_Body_In_Scope
;
210 -----------------------------------
211 -- Expand_Access_To_Protected_Op --
212 -----------------------------------
214 procedure Expand_Access_To_Protected_Op
219 -- The value of the attribute_reference is a record containing two
220 -- fields: an access to the protected object, and an access to the
221 -- subprogram itself. The prefix is a selected component.
223 Loc
: constant Source_Ptr
:= Sloc
(N
);
225 Btyp
: constant Entity_Id
:= Base_Type
(Typ
);
227 E_T
: constant Entity_Id
:= Equivalent_Type
(Btyp
);
228 Acc
: constant Entity_Id
:=
229 Etype
(Next_Component
(First_Component
(E_T
)));
233 function May_Be_External_Call
return Boolean;
234 -- If the 'Access is to a local operation, but appears in a context
235 -- where it may lead to a call from outside the object, we must treat
236 -- this as an external call. Clearly we cannot tell without full
237 -- flow analysis, and a subsequent call that uses this 'Access may
238 -- lead to a bounded error (trying to seize locks twice, e.g.). For
239 -- now we treat 'Access as a potential external call if it is an actual
240 -- in a call to an outside subprogram.
242 --------------------------
243 -- May_Be_External_Call --
244 --------------------------
246 function May_Be_External_Call
return Boolean is
249 if (Nkind
(Parent
(N
)) = N_Procedure_Call_Statement
250 or else Nkind
(Parent
(N
)) = N_Function_Call
)
251 and then Is_Entity_Name
(Name
(Parent
(N
)))
253 Subp
:= Entity
(Name
(Parent
(N
)));
254 return not In_Open_Scopes
(Scope
(Subp
));
258 end May_Be_External_Call
;
260 -- Start of processing for Expand_Access_To_Protected_Op
263 -- Within the body of the protected type, the prefix
264 -- designates a local operation, and the object is the first
265 -- parameter of the corresponding protected body of the
266 -- current enclosing operation.
268 if Is_Entity_Name
(Pref
) then
269 pragma Assert
(In_Open_Scopes
(Scope
(Entity
(Pref
))));
271 if May_Be_External_Call
then
274 (External_Subprogram
(Entity
(Pref
)), Loc
);
278 (Protected_Body_Subprogram
(Entity
(Pref
)), Loc
);
281 Curr
:= Current_Scope
;
282 while Scope
(Curr
) /= Scope
(Entity
(Pref
)) loop
283 Curr
:= Scope
(Curr
);
286 -- In case of protected entries the first formal of its Protected_
287 -- Body_Subprogram is the address of the object.
289 if Ekind
(Curr
) = E_Entry
then
293 (Protected_Body_Subprogram
(Curr
)), Loc
);
295 -- In case of protected subprograms the first formal of its
296 -- Protected_Body_Subprogram is the object and we get its address.
300 Make_Attribute_Reference
(Loc
,
304 (Protected_Body_Subprogram
(Curr
)), Loc
),
305 Attribute_Name
=> Name_Address
);
308 -- Case where the prefix is not an entity name. Find the
309 -- version of the protected operation to be called from
310 -- outside the protected object.
316 (Entity
(Selector_Name
(Pref
))), Loc
);
319 Make_Attribute_Reference
(Loc
,
320 Prefix
=> Relocate_Node
(Prefix
(Pref
)),
321 Attribute_Name
=> Name_Address
);
329 Unchecked_Convert_To
(Acc
,
330 Make_Attribute_Reference
(Loc
,
332 Attribute_Name
=> Name_Address
))));
336 Analyze_And_Resolve
(N
, E_T
);
338 -- For subsequent analysis, the node must retain its type.
339 -- The backend will replace it with the equivalent type where
343 end Expand_Access_To_Protected_Op
;
345 ---------------------------
346 -- Expand_Access_To_Type --
347 ---------------------------
349 procedure Expand_Access_To_Type
(N
: Node_Id
) is
350 Loc
: constant Source_Ptr
:= Sloc
(N
);
351 Typ
: constant Entity_Id
:= Etype
(N
);
352 Pref
: constant Node_Id
:= Prefix
(N
);
357 if Is_Entity_Name
(Pref
)
358 and then Is_Type
(Entity
(Pref
))
360 -- If the current instance name denotes a task type,
361 -- then the access attribute is rewritten to be the
362 -- name of the "_task" parameter associated with the
363 -- task type's task body procedure. An unchecked
364 -- conversion is applied to ensure a type match in
365 -- cases of expander-generated calls (e.g., init procs).
367 if Is_Task_Type
(Entity
(Pref
)) then
369 First_Entity
(Get_Task_Body_Procedure
(Entity
(Pref
)));
371 while Present
(Formal
) loop
372 exit when Chars
(Formal
) = Name_uTask
;
373 Next_Entity
(Formal
);
376 pragma Assert
(Present
(Formal
));
379 Unchecked_Convert_To
(Typ
, New_Occurrence_Of
(Formal
, Loc
)));
382 -- The expression must appear in a default expression,
383 -- (which in the initialization procedure is the rhs of
384 -- an assignment), and not in a discriminant constraint.
389 while Present
(Par
) loop
390 exit when Nkind
(Par
) = N_Assignment_Statement
;
392 if Nkind
(Par
) = N_Component_Declaration
then
399 if Present
(Par
) then
401 Make_Attribute_Reference
(Loc
,
402 Prefix
=> Make_Identifier
(Loc
, Name_uInit
),
403 Attribute_Name
=> Attribute_Name
(N
)));
405 Analyze_And_Resolve
(N
, Typ
);
409 end Expand_Access_To_Type
;
411 --------------------------
412 -- Expand_Fpt_Attribute --
413 --------------------------
415 procedure Expand_Fpt_Attribute
421 Loc
: constant Source_Ptr
:= Sloc
(N
);
422 Typ
: constant Entity_Id
:= Etype
(N
);
426 -- The function name is the selected component Attr_xxx.yyy where
427 -- Attr_xxx is the package name, and yyy is the argument Nam.
429 -- Note: it would be more usual to have separate RE entries for each
430 -- of the entities in the Fat packages, but first they have identical
431 -- names (so we would have to have lots of renaming declarations to
432 -- meet the normal RE rule of separate names for all runtime entities),
433 -- and second there would be an awful lot of them!
436 Make_Selected_Component
(Loc
,
437 Prefix
=> New_Reference_To
(RTE
(Pkg
), Loc
),
438 Selector_Name
=> Make_Identifier
(Loc
, Nam
));
440 -- The generated call is given the provided set of parameters, and then
441 -- wrapped in a conversion which converts the result to the target type
442 -- We use the base type as the target because a range check may be
446 Unchecked_Convert_To
(Base_Type
(Etype
(N
)),
447 Make_Function_Call
(Loc
,
449 Parameter_Associations
=> Args
)));
451 Analyze_And_Resolve
(N
, Typ
);
452 end Expand_Fpt_Attribute
;
454 ----------------------------
455 -- Expand_Fpt_Attribute_R --
456 ----------------------------
458 -- The single argument is converted to its root type to call the
459 -- appropriate runtime function, with the actual call being built
460 -- by Expand_Fpt_Attribute
462 procedure Expand_Fpt_Attribute_R
(N
: Node_Id
) is
463 E1
: constant Node_Id
:= First
(Expressions
(N
));
467 Find_Fat_Info
(Etype
(E1
), Ftp
, Pkg
);
469 (N
, Pkg
, Attribute_Name
(N
),
470 New_List
(Unchecked_Convert_To
(Ftp
, Relocate_Node
(E1
))));
471 end Expand_Fpt_Attribute_R
;
473 -----------------------------
474 -- Expand_Fpt_Attribute_RI --
475 -----------------------------
477 -- The first argument is converted to its root type and the second
478 -- argument is converted to standard long long integer to call the
479 -- appropriate runtime function, with the actual call being built
480 -- by Expand_Fpt_Attribute
482 procedure Expand_Fpt_Attribute_RI
(N
: Node_Id
) is
483 E1
: constant Node_Id
:= First
(Expressions
(N
));
486 E2
: constant Node_Id
:= Next
(E1
);
488 Find_Fat_Info
(Etype
(E1
), Ftp
, Pkg
);
490 (N
, Pkg
, Attribute_Name
(N
),
492 Unchecked_Convert_To
(Ftp
, Relocate_Node
(E1
)),
493 Unchecked_Convert_To
(Standard_Integer
, Relocate_Node
(E2
))));
494 end Expand_Fpt_Attribute_RI
;
496 -----------------------------
497 -- Expand_Fpt_Attribute_RR --
498 -----------------------------
500 -- The two arguments is converted to their root types to call the
501 -- appropriate runtime function, with the actual call being built
502 -- by Expand_Fpt_Attribute
504 procedure Expand_Fpt_Attribute_RR
(N
: Node_Id
) is
505 E1
: constant Node_Id
:= First
(Expressions
(N
));
508 E2
: constant Node_Id
:= Next
(E1
);
510 Find_Fat_Info
(Etype
(E1
), Ftp
, Pkg
);
512 (N
, Pkg
, Attribute_Name
(N
),
514 Unchecked_Convert_To
(Ftp
, Relocate_Node
(E1
)),
515 Unchecked_Convert_To
(Ftp
, Relocate_Node
(E2
))));
516 end Expand_Fpt_Attribute_RR
;
518 ----------------------------------
519 -- Expand_N_Attribute_Reference --
520 ----------------------------------
522 procedure Expand_N_Attribute_Reference
(N
: Node_Id
) is
523 Loc
: constant Source_Ptr
:= Sloc
(N
);
524 Typ
: constant Entity_Id
:= Etype
(N
);
525 Btyp
: constant Entity_Id
:= Base_Type
(Typ
);
526 Pref
: constant Node_Id
:= Prefix
(N
);
527 Exprs
: constant List_Id
:= Expressions
(N
);
528 Id
: constant Attribute_Id
:= Get_Attribute_Id
(Attribute_Name
(N
));
530 procedure Rewrite_Stream_Proc_Call
(Pname
: Entity_Id
);
531 -- Rewrites a stream attribute for Read, Write or Output with the
532 -- procedure call. Pname is the entity for the procedure to call.
534 ------------------------------
535 -- Rewrite_Stream_Proc_Call --
536 ------------------------------
538 procedure Rewrite_Stream_Proc_Call
(Pname
: Entity_Id
) is
539 Item
: constant Node_Id
:= Next
(First
(Exprs
));
540 Formal
: constant Entity_Id
:= Next_Formal
(First_Formal
(Pname
));
541 Formal_Typ
: constant Entity_Id
:= Etype
(Formal
);
542 Is_Written
: constant Boolean := (Ekind
(Formal
) /= E_In_Parameter
);
545 -- The expansion depends on Item, the second actual, which is
546 -- the object being streamed in or out.
548 -- If the item is a component of a packed array type, and
549 -- a conversion is needed on exit, we introduce a temporary to
550 -- hold the value, because otherwise the packed reference will
551 -- not be properly expanded.
553 if Nkind
(Item
) = N_Indexed_Component
554 and then Is_Packed
(Base_Type
(Etype
(Prefix
(Item
))))
555 and then Base_Type
(Etype
(Item
)) /= Base_Type
(Formal_Typ
)
559 Temp
: constant Entity_Id
:=
560 Make_Defining_Identifier
561 (Loc
, New_Internal_Name
('V'));
567 Make_Object_Declaration
(Loc
,
568 Defining_Identifier
=> Temp
,
570 New_Occurrence_Of
(Formal_Typ
, Loc
));
571 Set_Etype
(Temp
, Formal_Typ
);
574 Make_Assignment_Statement
(Loc
,
575 Name
=> New_Copy_Tree
(Item
),
578 (Etype
(Item
), New_Occurrence_Of
(Temp
, Loc
)));
580 Rewrite
(Item
, New_Occurrence_Of
(Temp
, Loc
));
584 Make_Procedure_Call_Statement
(Loc
,
585 Name
=> New_Occurrence_Of
(Pname
, Loc
),
586 Parameter_Associations
=> Exprs
),
589 Rewrite
(N
, Make_Null_Statement
(Loc
));
594 -- For the class-wide dispatching cases, and for cases in which
595 -- the base type of the second argument matches the base type of
596 -- the corresponding formal parameter (that is to say the stream
597 -- operation is not inherited), we are all set, and can use the
598 -- argument unchanged.
600 -- For all other cases we do an unchecked conversion of the second
601 -- parameter to the type of the formal of the procedure we are
602 -- calling. This deals with the private type cases, and with going
603 -- to the root type as required in elementary type case.
605 if not Is_Class_Wide_Type
(Entity
(Pref
))
606 and then not Is_Class_Wide_Type
(Etype
(Item
))
607 and then Base_Type
(Etype
(Item
)) /= Base_Type
(Formal_Typ
)
610 Unchecked_Convert_To
(Formal_Typ
, Relocate_Node
(Item
)));
612 -- For untagged derived types set Assignment_OK, to prevent
613 -- copies from being created when the unchecked conversion
614 -- is expanded (which would happen in Remove_Side_Effects
615 -- if Expand_N_Unchecked_Conversion were allowed to call
616 -- Force_Evaluation). The copy could violate Ada semantics
617 -- in cases such as an actual that is an out parameter.
618 -- Note that this approach is also used in exp_ch7 for calls
619 -- to controlled type operations to prevent problems with
620 -- actuals wrapped in unchecked conversions.
622 if Is_Untagged_Derivation
(Etype
(Expression
(Item
))) then
623 Set_Assignment_OK
(Item
);
627 -- And now rewrite the call
630 Make_Procedure_Call_Statement
(Loc
,
631 Name
=> New_Occurrence_Of
(Pname
, Loc
),
632 Parameter_Associations
=> Exprs
));
635 end Rewrite_Stream_Proc_Call
;
637 -- Start of processing for Expand_N_Attribute_Reference
640 -- Do required validity checking, if enabled. Do not apply check to
641 -- output parameters of an Asm instruction, since the value of this
642 -- is not set till after the attribute has been elaborated.
644 if Validity_Checks_On
and then Validity_Check_Operands
645 and then Id
/= Attribute_Asm_Output
650 Expr
:= First
(Expressions
(N
));
651 while Present
(Expr
) loop
658 -- Remaining processing depends on specific attribute
666 when Attribute_Access
=>
668 if Ekind
(Btyp
) = E_Access_Protected_Subprogram_Type
then
669 Expand_Access_To_Protected_Op
(N
, Pref
, Typ
);
671 elsif Ekind
(Btyp
) = E_General_Access_Type
then
673 Ref_Object
: constant Node_Id
:= Get_Referenced_Object
(Pref
);
674 Parm_Ent
: Entity_Id
;
675 Conversion
: Node_Id
;
678 -- If the prefix of an Access attribute is a dereference of an
679 -- access parameter (or a renaming of such a dereference) and
680 -- the context is a general access type (but not an anonymous
681 -- access type), then rewrite the attribute as a conversion of
682 -- the access parameter to the context access type. This will
683 -- result in an accessibility check being performed, if needed.
685 -- (X.all'Access => Acc_Type (X))
687 if Nkind
(Ref_Object
) = N_Explicit_Dereference
688 and then Is_Entity_Name
(Prefix
(Ref_Object
))
690 Parm_Ent
:= Entity
(Prefix
(Ref_Object
));
692 if Ekind
(Parm_Ent
) in Formal_Kind
693 and then Ekind
(Etype
(Parm_Ent
)) = E_Anonymous_Access_Type
694 and then Present
(Extra_Accessibility
(Parm_Ent
))
697 Convert_To
(Typ
, New_Copy_Tree
(Prefix
(Ref_Object
)));
699 Rewrite
(N
, Conversion
);
700 Analyze_And_Resolve
(N
, Typ
);
703 -- Ada 2005 (AI-251): If the designated type is an interface,
704 -- then rewrite the referenced object as a conversion to force
705 -- the displacement of the pointer to the secondary dispatch
708 elsif Is_Interface
(Directly_Designated_Type
(Btyp
)) then
709 Conversion
:= Convert_To
(Typ
, New_Copy_Tree
(Ref_Object
));
710 Rewrite
(N
, Conversion
);
711 Analyze_And_Resolve
(N
, Typ
);
715 -- If the prefix is a type name, this is a reference to the current
716 -- instance of the type, within its initialization procedure.
719 Expand_Access_To_Type
(N
);
726 -- Transforms 'Adjacent into a call to the floating-point attribute
727 -- function Adjacent in Fat_xxx (where xxx is the root type)
729 when Attribute_Adjacent
=>
730 Expand_Fpt_Attribute_RR
(N
);
736 when Attribute_Address
=> Address
: declare
737 Task_Proc
: Entity_Id
;
740 -- If the prefix is a task or a task type, the useful address
741 -- is that of the procedure for the task body, i.e. the actual
742 -- program unit. We replace the original entity with that of
745 if Is_Entity_Name
(Pref
)
746 and then Is_Task_Type
(Entity
(Pref
))
748 Task_Proc
:= Next_Entity
(Root_Type
(Etype
(Pref
)));
750 while Present
(Task_Proc
) loop
751 exit when Ekind
(Task_Proc
) = E_Procedure
752 and then Etype
(First_Formal
(Task_Proc
)) =
753 Corresponding_Record_Type
(Etype
(Pref
));
754 Next_Entity
(Task_Proc
);
757 if Present
(Task_Proc
) then
758 Set_Entity
(Pref
, Task_Proc
);
759 Set_Etype
(Pref
, Etype
(Task_Proc
));
762 -- Similarly, the address of a protected operation is the address
763 -- of the corresponding protected body, regardless of the protected
764 -- object from which it is selected.
766 elsif Nkind
(Pref
) = N_Selected_Component
767 and then Is_Subprogram
(Entity
(Selector_Name
(Pref
)))
768 and then Is_Protected_Type
(Scope
(Entity
(Selector_Name
(Pref
))))
772 External_Subprogram
(Entity
(Selector_Name
(Pref
))), Loc
));
774 elsif Nkind
(Pref
) = N_Explicit_Dereference
775 and then Ekind
(Etype
(Pref
)) = E_Subprogram_Type
776 and then Convention
(Etype
(Pref
)) = Convention_Protected
778 -- The prefix is be a dereference of an access_to_protected_
779 -- subprogram. The desired address is the second component of
780 -- the record that represents the access.
783 Addr
: constant Entity_Id
:= Etype
(N
);
784 Ptr
: constant Node_Id
:= Prefix
(Pref
);
785 T
: constant Entity_Id
:=
786 Equivalent_Type
(Base_Type
(Etype
(Ptr
)));
790 Unchecked_Convert_To
(Addr
,
791 Make_Selected_Component
(Loc
,
792 Prefix
=> Unchecked_Convert_To
(T
, Ptr
),
793 Selector_Name
=> New_Occurrence_Of
(
794 Next_Entity
(First_Entity
(T
)), Loc
))));
796 Analyze_And_Resolve
(N
, Addr
);
800 -- Deal with packed array reference, other cases are handled by gigi
802 if Involves_Packed_Array_Reference
(Pref
) then
803 Expand_Packed_Address_Reference
(N
);
811 when Attribute_Alignment
=> Alignment
: declare
812 Ptyp
: constant Entity_Id
:= Etype
(Pref
);
816 -- For class-wide types, X'Class'Alignment is transformed into a
817 -- direct reference to the Alignment of the class type, so that the
818 -- back end does not have to deal with the X'Class'Alignment
821 if Is_Entity_Name
(Pref
)
822 and then Is_Class_Wide_Type
(Entity
(Pref
))
824 Rewrite
(Prefix
(N
), New_Occurrence_Of
(Entity
(Pref
), Loc
));
827 -- For x'Alignment applied to an object of a class wide type,
828 -- transform X'Alignment into a call to the predefined primitive
829 -- operation _Alignment applied to X.
831 elsif Is_Class_Wide_Type
(Ptyp
) then
833 Make_Function_Call
(Loc
,
834 Name
=> New_Reference_To
835 (Find_Prim_Op
(Ptyp
, Name_uAlignment
), Loc
),
836 Parameter_Associations
=> New_List
(Pref
));
838 if Typ
/= Standard_Integer
then
840 -- The context is a specific integer type with which the
841 -- original attribute was compatible. The function has a
842 -- specific type as well, so to preserve the compatibility
843 -- we must convert explicitly.
845 New_Node
:= Convert_To
(Typ
, New_Node
);
848 Rewrite
(N
, New_Node
);
849 Analyze_And_Resolve
(N
, Typ
);
852 -- For all other cases, we just have to deal with the case of
853 -- the fact that the result can be universal.
856 Apply_Universal_Integer_Attribute_Checks
(N
);
864 when Attribute_AST_Entry
=> AST_Entry
: declare
870 -- The reference to the entry or entry family
873 -- The index expression for an entry family reference, or
874 -- the Empty if Entry_Ref references a simple entry.
877 if Nkind
(Pref
) = N_Indexed_Component
then
878 Entry_Ref
:= Prefix
(Pref
);
879 Index
:= First
(Expressions
(Pref
));
885 -- Get expression for Task_Id and the entry entity
887 if Nkind
(Entry_Ref
) = N_Selected_Component
then
889 Make_Attribute_Reference
(Loc
,
890 Attribute_Name
=> Name_Identity
,
891 Prefix
=> Prefix
(Entry_Ref
));
893 Ttyp
:= Etype
(Prefix
(Entry_Ref
));
894 Eent
:= Entity
(Selector_Name
(Entry_Ref
));
898 Make_Function_Call
(Loc
,
899 Name
=> New_Occurrence_Of
(RTE
(RE_Current_Task
), Loc
));
901 Eent
:= Entity
(Entry_Ref
);
903 -- We have to find the enclosing task to get the task type
904 -- There must be one, since we already validated this earlier
906 Ttyp
:= Current_Scope
;
907 while not Is_Task_Type
(Ttyp
) loop
908 Ttyp
:= Scope
(Ttyp
);
912 -- Now rewrite the attribute with a call to Create_AST_Handler
915 Make_Function_Call
(Loc
,
916 Name
=> New_Occurrence_Of
(RTE
(RE_Create_AST_Handler
), Loc
),
917 Parameter_Associations
=> New_List
(
919 Entry_Index_Expression
(Loc
, Eent
, Index
, Ttyp
))));
921 Analyze_And_Resolve
(N
, RTE
(RE_AST_Handler
));
928 -- We compute this if a component clause was present, otherwise
929 -- we leave the computation up to Gigi, since we don't know what
930 -- layout will be chosen.
932 -- Note that the attribute can apply to a naked record component
933 -- in generated code (i.e. the prefix is an identifier that
934 -- references the component or discriminant entity).
936 when Attribute_Bit_Position
=> Bit_Position
:
941 if Nkind
(Pref
) = N_Identifier
then
944 CE
:= Entity
(Selector_Name
(Pref
));
947 if Known_Static_Component_Bit_Offset
(CE
) then
949 Make_Integer_Literal
(Loc
,
950 Intval
=> Component_Bit_Offset
(CE
)));
951 Analyze_And_Resolve
(N
, Typ
);
954 Apply_Universal_Integer_Attribute_Checks
(N
);
962 -- A reference to P'Body_Version or P'Version is expanded to
965 -- pragma Import (C, Vnn, "uuuuT";
967 -- Get_Version_String (Vnn)
969 -- where uuuu is the unit name (dots replaced by double underscore)
970 -- and T is B for the cases of Body_Version, or Version applied to a
971 -- subprogram acting as its own spec, and S for Version applied to a
972 -- subprogram spec or package. This sequence of code references the
973 -- the unsigned constant created in the main program by the binder.
975 -- A special exception occurs for Standard, where the string
976 -- returned is a copy of the library string in gnatvsn.ads.
978 when Attribute_Body_Version | Attribute_Version
=> Version
: declare
979 E
: constant Entity_Id
:=
980 Make_Defining_Identifier
(Loc
, New_Internal_Name
('V'));
981 Pent
: Entity_Id
:= Entity
(Pref
);
985 -- If not library unit, get to containing library unit
987 while Pent
/= Standard_Standard
988 and then Scope
(Pent
) /= Standard_Standard
990 Pent
:= Scope
(Pent
);
993 -- Special case Standard
995 if Pent
= Standard_Standard
996 or else Pent
= Standard_ASCII
999 Make_String_Literal
(Loc
,
1000 Strval
=> Verbose_Library_Version
));
1005 -- Build required string constant
1007 Get_Name_String
(Get_Unit_Name
(Pent
));
1010 for J
in 1 .. Name_Len
- 2 loop
1011 if Name_Buffer
(J
) = '.' then
1012 Store_String_Chars
("__");
1014 Store_String_Char
(Get_Char_Code
(Name_Buffer
(J
)));
1018 -- Case of subprogram acting as its own spec, always use body
1020 if Nkind
(Declaration_Node
(Pent
)) in N_Subprogram_Specification
1021 and then Nkind
(Parent
(Declaration_Node
(Pent
))) =
1023 and then Acts_As_Spec
(Parent
(Declaration_Node
(Pent
)))
1025 Store_String_Chars
("B");
1027 -- Case of no body present, always use spec
1029 elsif not Unit_Requires_Body
(Pent
) then
1030 Store_String_Chars
("S");
1032 -- Otherwise use B for Body_Version, S for spec
1034 elsif Id
= Attribute_Body_Version
then
1035 Store_String_Chars
("B");
1037 Store_String_Chars
("S");
1041 Lib
.Version_Referenced
(S
);
1043 -- Insert the object declaration
1045 Insert_Actions
(N
, New_List
(
1046 Make_Object_Declaration
(Loc
,
1047 Defining_Identifier
=> E
,
1048 Object_Definition
=>
1049 New_Occurrence_Of
(RTE
(RE_Unsigned
), Loc
))));
1051 -- Set entity as imported with correct external name
1053 Set_Is_Imported
(E
);
1054 Set_Interface_Name
(E
, Make_String_Literal
(Loc
, S
));
1056 -- And now rewrite original reference
1059 Make_Function_Call
(Loc
,
1060 Name
=> New_Reference_To
(RTE
(RE_Get_Version_String
), Loc
),
1061 Parameter_Associations
=> New_List
(
1062 New_Occurrence_Of
(E
, Loc
))));
1065 Analyze_And_Resolve
(N
, RTE
(RE_Version_String
));
1072 -- Transforms 'Ceiling into a call to the floating-point attribute
1073 -- function Ceiling in Fat_xxx (where xxx is the root type)
1075 when Attribute_Ceiling
=>
1076 Expand_Fpt_Attribute_R
(N
);
1082 -- Transforms 'Callable attribute into a call to the Callable function
1084 when Attribute_Callable
=> Callable
:
1086 -- We have an object of a task interface class-wide type as a prefix
1087 -- to Callable. Generate:
1089 -- callable (Pref._disp_get_task_id);
1091 if Ada_Version
>= Ada_05
1092 and then Ekind
(Etype
(Pref
)) = E_Class_Wide_Type
1093 and then Is_Interface
(Etype
(Pref
))
1094 and then Is_Task_Interface
(Etype
(Pref
))
1097 Make_Function_Call
(Loc
,
1099 New_Reference_To
(RTE
(RE_Callable
), Loc
),
1100 Parameter_Associations
=> New_List
(
1101 Make_Selected_Component
(Loc
,
1103 New_Copy_Tree
(Pref
),
1105 Make_Identifier
(Loc
, Name_uDisp_Get_Task_Id
)))));
1108 Build_Call_With_Task
(Pref
, RTE
(RE_Callable
)));
1111 Analyze_And_Resolve
(N
, Standard_Boolean
);
1118 -- Transforms 'Caller attribute into a call to either the
1119 -- Task_Entry_Caller or the Protected_Entry_Caller function.
1121 when Attribute_Caller
=> Caller
: declare
1122 Id_Kind
: constant Entity_Id
:= RTE
(RO_AT_Task_Id
);
1123 Ent
: constant Entity_Id
:= Entity
(Pref
);
1124 Conctype
: constant Entity_Id
:= Scope
(Ent
);
1125 Nest_Depth
: Integer := 0;
1132 if Is_Protected_Type
(Conctype
) then
1134 or else Restriction_Active
(No_Entry_Queue
) = False
1135 or else Number_Entries
(Conctype
) > 1
1139 (RTE
(RE_Protected_Entry_Caller
), Loc
);
1143 (RTE
(RE_Protected_Single_Entry_Caller
), Loc
);
1147 Unchecked_Convert_To
(Id_Kind
,
1148 Make_Function_Call
(Loc
,
1150 Parameter_Associations
=> New_List
1153 (Corresponding_Body
(Parent
(Conctype
))), Loc
)))));
1158 -- Determine the nesting depth of the E'Caller attribute, that
1159 -- is, how many accept statements are nested within the accept
1160 -- statement for E at the point of E'Caller. The runtime uses
1161 -- this depth to find the specified entry call.
1163 for J
in reverse 0 .. Scope_Stack
.Last
loop
1164 S
:= Scope_Stack
.Table
(J
).Entity
;
1166 -- We should not reach the scope of the entry, as it should
1167 -- already have been checked in Sem_Attr that this attribute
1168 -- reference is within a matching accept statement.
1170 pragma Assert
(S
/= Conctype
);
1175 elsif Is_Entry
(S
) then
1176 Nest_Depth
:= Nest_Depth
+ 1;
1181 Unchecked_Convert_To
(Id_Kind
,
1182 Make_Function_Call
(Loc
,
1183 Name
=> New_Reference_To
(
1184 RTE
(RE_Task_Entry_Caller
), Loc
),
1185 Parameter_Associations
=> New_List
(
1186 Make_Integer_Literal
(Loc
,
1187 Intval
=> Int
(Nest_Depth
))))));
1190 Analyze_And_Resolve
(N
, Id_Kind
);
1197 -- Transforms 'Compose into a call to the floating-point attribute
1198 -- function Compose in Fat_xxx (where xxx is the root type)
1200 -- Note: we strictly should have special code here to deal with the
1201 -- case of absurdly negative arguments (less than Integer'First)
1202 -- which will return a (signed) zero value, but it hardly seems
1203 -- worth the effort. Absurdly large positive arguments will raise
1204 -- constraint error which is fine.
1206 when Attribute_Compose
=>
1207 Expand_Fpt_Attribute_RI
(N
);
1213 when Attribute_Constrained
=> Constrained
: declare
1214 Formal_Ent
: constant Entity_Id
:= Param_Entity
(Pref
);
1215 Typ
: constant Entity_Id
:= Etype
(Pref
);
1217 function Is_Constrained_Aliased_View
(Obj
: Node_Id
) return Boolean;
1218 -- Ada 2005 (AI-363): Returns True if the object name Obj denotes a
1219 -- view of an aliased object whose subtype is constrained.
1221 ---------------------------------
1222 -- Is_Constrained_Aliased_View --
1223 ---------------------------------
1225 function Is_Constrained_Aliased_View
(Obj
: Node_Id
) return Boolean is
1229 if Is_Entity_Name
(Obj
) then
1232 if Present
(Renamed_Object
(E
)) then
1233 return Is_Constrained_Aliased_View
(Renamed_Object
(E
));
1236 return Is_Aliased
(E
) and then Is_Constrained
(Etype
(E
));
1240 return Is_Aliased_View
(Obj
)
1242 (Is_Constrained
(Etype
(Obj
))
1243 or else (Nkind
(Obj
) = N_Explicit_Dereference
1245 not Has_Constrained_Partial_View
1246 (Base_Type
(Etype
(Obj
)))));
1248 end Is_Constrained_Aliased_View
;
1250 -- Start of processing for Constrained
1253 -- Reference to a parameter where the value is passed as an extra
1254 -- actual, corresponding to the extra formal referenced by the
1255 -- Extra_Constrained field of the corresponding formal. If this
1256 -- is an entry in-parameter, it is replaced by a constant renaming
1257 -- for which Extra_Constrained is never created.
1259 if Present
(Formal_Ent
)
1260 and then Ekind
(Formal_Ent
) /= E_Constant
1261 and then Present
(Extra_Constrained
(Formal_Ent
))
1265 (Extra_Constrained
(Formal_Ent
), Sloc
(N
)));
1267 -- For variables with a Extra_Constrained field, we use the
1268 -- corresponding entity.
1270 elsif Nkind
(Pref
) = N_Identifier
1271 and then Ekind
(Entity
(Pref
)) = E_Variable
1272 and then Present
(Extra_Constrained
(Entity
(Pref
)))
1276 (Extra_Constrained
(Entity
(Pref
)), Sloc
(N
)));
1278 -- For all other entity names, we can tell at compile time
1280 elsif Is_Entity_Name
(Pref
) then
1282 Ent
: constant Entity_Id
:= Entity
(Pref
);
1286 -- (RM J.4) obsolescent cases
1288 if Is_Type
(Ent
) then
1292 if Is_Private_Type
(Ent
) then
1293 Res
:= not Has_Discriminants
(Ent
)
1294 or else Is_Constrained
(Ent
);
1296 -- It not a private type, must be a generic actual type
1297 -- that corresponded to a private type. We know that this
1298 -- correspondence holds, since otherwise the reference
1299 -- within the generic template would have been illegal.
1302 if Is_Composite_Type
(Underlying_Type
(Ent
)) then
1303 Res
:= Is_Constrained
(Ent
);
1309 -- If the prefix is not a variable or is aliased, then
1310 -- definitely true; if it's a formal parameter without
1311 -- an associated extra formal, then treat it as constrained.
1313 -- Ada 2005 (AI-363): An aliased prefix must be known to be
1314 -- constrained in order to set the attribute to True.
1316 elsif not Is_Variable
(Pref
)
1317 or else Present
(Formal_Ent
)
1318 or else (Ada_Version
< Ada_05
1319 and then Is_Aliased_View
(Pref
))
1320 or else (Ada_Version
>= Ada_05
1321 and then Is_Constrained_Aliased_View
(Pref
))
1325 -- Variable case, just look at type to see if it is
1326 -- constrained. Note that the one case where this is
1327 -- not accurate (the procedure formal case), has been
1331 Res
:= Is_Constrained
(Etype
(Ent
));
1335 New_Reference_To
(Boolean_Literals
(Res
), Loc
));
1338 -- Prefix is not an entity name. These are also cases where
1339 -- we can always tell at compile time by looking at the form
1340 -- and type of the prefix. If an explicit dereference of an
1341 -- object with constrained partial view, this is unconstrained
1342 -- (Ada 2005 AI-363).
1348 not Is_Variable
(Pref
)
1350 (Nkind
(Pref
) = N_Explicit_Dereference
1352 not Has_Constrained_Partial_View
(Base_Type
(Typ
)))
1353 or else Is_Constrained
(Typ
)),
1357 Analyze_And_Resolve
(N
, Standard_Boolean
);
1364 -- Transforms 'Copy_Sign into a call to the floating-point attribute
1365 -- function Copy_Sign in Fat_xxx (where xxx is the root type)
1367 when Attribute_Copy_Sign
=>
1368 Expand_Fpt_Attribute_RR
(N
);
1374 -- Transforms 'Count attribute into a call to the Count function
1376 when Attribute_Count
=> Count
:
1382 Conctyp
: Entity_Id
;
1385 -- If the prefix is a member of an entry family, retrieve both
1386 -- entry name and index. For a simple entry there is no index.
1388 if Nkind
(Pref
) = N_Indexed_Component
then
1389 Entnam
:= Prefix
(Pref
);
1390 Index
:= First
(Expressions
(Pref
));
1396 -- Find the concurrent type in which this attribute is referenced
1397 -- (there had better be one).
1399 Conctyp
:= Current_Scope
;
1400 while not Is_Concurrent_Type
(Conctyp
) loop
1401 Conctyp
:= Scope
(Conctyp
);
1406 if Is_Protected_Type
(Conctyp
) then
1409 or else Restriction_Active
(No_Entry_Queue
) = False
1410 or else Number_Entries
(Conctyp
) > 1
1412 Name
:= New_Reference_To
(RTE
(RE_Protected_Count
), Loc
);
1415 Make_Function_Call
(Loc
,
1417 Parameter_Associations
=> New_List
(
1420 Corresponding_Body
(Parent
(Conctyp
))), Loc
),
1421 Entry_Index_Expression
(
1422 Loc
, Entity
(Entnam
), Index
, Scope
(Entity
(Entnam
)))));
1424 Name
:= New_Reference_To
(RTE
(RE_Protected_Count_Entry
), Loc
);
1426 Call
:= Make_Function_Call
(Loc
,
1428 Parameter_Associations
=> New_List
(
1431 Corresponding_Body
(Parent
(Conctyp
))), Loc
)));
1438 Make_Function_Call
(Loc
,
1439 Name
=> New_Reference_To
(RTE
(RE_Task_Count
), Loc
),
1440 Parameter_Associations
=> New_List
(
1441 Entry_Index_Expression
1442 (Loc
, Entity
(Entnam
), Index
, Scope
(Entity
(Entnam
)))));
1445 -- The call returns type Natural but the context is universal integer
1446 -- so any integer type is allowed. The attribute was already resolved
1447 -- so its Etype is the required result type. If the base type of the
1448 -- context type is other than Standard.Integer we put in a conversion
1449 -- to the required type. This can be a normal typed conversion since
1450 -- both input and output types of the conversion are integer types
1452 if Base_Type
(Typ
) /= Base_Type
(Standard_Integer
) then
1453 Rewrite
(N
, Convert_To
(Typ
, Call
));
1458 Analyze_And_Resolve
(N
, Typ
);
1465 -- This processing is shared by Elab_Spec
1467 -- What we do is to insert the following declarations
1470 -- pragma Import (C, enn, "name___elabb/s");
1472 -- and then the Elab_Body/Spec attribute is replaced by a reference
1473 -- to this defining identifier.
1475 when Attribute_Elab_Body |
1476 Attribute_Elab_Spec
=>
1479 Ent
: constant Entity_Id
:=
1480 Make_Defining_Identifier
(Loc
,
1481 New_Internal_Name
('E'));
1485 procedure Make_Elab_String
(Nod
: Node_Id
);
1486 -- Given Nod, an identifier, or a selected component, put the
1487 -- image into the current string literal, with double underline
1488 -- between components.
1490 ----------------------
1491 -- Make_Elab_String --
1492 ----------------------
1494 procedure Make_Elab_String
(Nod
: Node_Id
) is
1496 if Nkind
(Nod
) = N_Selected_Component
then
1497 Make_Elab_String
(Prefix
(Nod
));
1500 Store_String_Char
('$');
1502 Store_String_Char
('_');
1503 Store_String_Char
('_');
1506 Get_Name_String
(Chars
(Selector_Name
(Nod
)));
1509 pragma Assert
(Nkind
(Nod
) = N_Identifier
);
1510 Get_Name_String
(Chars
(Nod
));
1513 Store_String_Chars
(Name_Buffer
(1 .. Name_Len
));
1514 end Make_Elab_String
;
1516 -- Start of processing for Elab_Body/Elab_Spec
1519 -- First we need to prepare the string literal for the name of
1520 -- the elaboration routine to be referenced.
1523 Make_Elab_String
(Pref
);
1526 Store_String_Chars
("._elab");
1527 Lang
:= Make_Identifier
(Loc
, Name_Ada
);
1529 Store_String_Chars
("___elab");
1530 Lang
:= Make_Identifier
(Loc
, Name_C
);
1533 if Id
= Attribute_Elab_Body
then
1534 Store_String_Char
('b');
1536 Store_String_Char
('s');
1541 Insert_Actions
(N
, New_List
(
1542 Make_Subprogram_Declaration
(Loc
,
1544 Make_Procedure_Specification
(Loc
,
1545 Defining_Unit_Name
=> Ent
)),
1548 Chars
=> Name_Import
,
1549 Pragma_Argument_Associations
=> New_List
(
1550 Make_Pragma_Argument_Association
(Loc
,
1551 Expression
=> Lang
),
1553 Make_Pragma_Argument_Association
(Loc
,
1555 Make_Identifier
(Loc
, Chars
(Ent
))),
1557 Make_Pragma_Argument_Association
(Loc
,
1559 Make_String_Literal
(Loc
, Str
))))));
1561 Set_Entity
(N
, Ent
);
1562 Rewrite
(N
, New_Occurrence_Of
(Ent
, Loc
));
1569 -- Elaborated is always True for preelaborated units, predefined
1570 -- units, pure units and units which have Elaborate_Body pragmas.
1571 -- These units have no elaboration entity.
1573 -- Note: The Elaborated attribute is never passed through to Gigi
1575 when Attribute_Elaborated
=> Elaborated
: declare
1576 Ent
: constant Entity_Id
:= Entity
(Pref
);
1579 if Present
(Elaboration_Entity
(Ent
)) then
1581 New_Occurrence_Of
(Elaboration_Entity
(Ent
), Loc
));
1583 Rewrite
(N
, New_Occurrence_Of
(Standard_True
, Loc
));
1591 when Attribute_Enum_Rep
=> Enum_Rep
:
1593 -- X'Enum_Rep (Y) expands to
1597 -- This is simply a direct conversion from the enumeration type
1598 -- to the target integer type, which is treated by Gigi as a normal
1599 -- integer conversion, treating the enumeration type as an integer,
1600 -- which is exactly what we want! We set Conversion_OK to make sure
1601 -- that the analyzer does not complain about what otherwise might
1602 -- be an illegal conversion.
1604 if Is_Non_Empty_List
(Exprs
) then
1606 OK_Convert_To
(Typ
, Relocate_Node
(First
(Exprs
))));
1608 -- X'Enum_Rep where X is an enumeration literal is replaced by
1609 -- the literal value.
1611 elsif Ekind
(Entity
(Pref
)) = E_Enumeration_Literal
then
1613 Make_Integer_Literal
(Loc
, Enumeration_Rep
(Entity
(Pref
))));
1615 -- If this is a renaming of a literal, recover the representation
1618 elsif Ekind
(Entity
(Pref
)) = E_Constant
1619 and then Present
(Renamed_Object
(Entity
(Pref
)))
1621 Ekind
(Entity
(Renamed_Object
(Entity
(Pref
))))
1622 = E_Enumeration_Literal
1625 Make_Integer_Literal
(Loc
,
1626 Enumeration_Rep
(Entity
(Renamed_Object
(Entity
(Pref
))))));
1628 -- X'Enum_Rep where X is an object does a direct unchecked conversion
1629 -- of the object value, as described for the type case above.
1633 OK_Convert_To
(Typ
, Relocate_Node
(Pref
)));
1637 Analyze_And_Resolve
(N
, Typ
);
1645 -- Transforms 'Exponent into a call to the floating-point attribute
1646 -- function Exponent in Fat_xxx (where xxx is the root type)
1648 when Attribute_Exponent
=>
1649 Expand_Fpt_Attribute_R
(N
);
1655 -- transforme X'External_Tag into Ada.Tags.External_Tag (X'tag)
1657 when Attribute_External_Tag
=> External_Tag
:
1660 Make_Function_Call
(Loc
,
1661 Name
=> New_Reference_To
(RTE
(RE_External_Tag
), Loc
),
1662 Parameter_Associations
=> New_List
(
1663 Make_Attribute_Reference
(Loc
,
1664 Attribute_Name
=> Name_Tag
,
1665 Prefix
=> Prefix
(N
)))));
1667 Analyze_And_Resolve
(N
, Standard_String
);
1674 when Attribute_First
=> declare
1675 Ptyp
: constant Entity_Id
:= Etype
(Pref
);
1678 -- If the prefix type is a constrained packed array type which
1679 -- already has a Packed_Array_Type representation defined, then
1680 -- replace this attribute with a direct reference to 'First of the
1681 -- appropriate index subtype (since otherwise Gigi will try to give
1682 -- us the value of 'First for this implementation type).
1684 if Is_Constrained_Packed_Array
(Ptyp
) then
1686 Make_Attribute_Reference
(Loc
,
1687 Attribute_Name
=> Name_First
,
1688 Prefix
=> New_Reference_To
(Get_Index_Subtype
(N
), Loc
)));
1689 Analyze_And_Resolve
(N
, Typ
);
1691 elsif Is_Access_Type
(Ptyp
) then
1692 Apply_Access_Check
(N
);
1700 -- We compute this if a component clause was present, otherwise
1701 -- we leave the computation up to Gigi, since we don't know what
1702 -- layout will be chosen.
1704 when Attribute_First_Bit
=> First_Bit
:
1706 CE
: constant Entity_Id
:= Entity
(Selector_Name
(Pref
));
1709 if Known_Static_Component_Bit_Offset
(CE
) then
1711 Make_Integer_Literal
(Loc
,
1712 Component_Bit_Offset
(CE
) mod System_Storage_Unit
));
1714 Analyze_And_Resolve
(N
, Typ
);
1717 Apply_Universal_Integer_Attribute_Checks
(N
);
1727 -- fixtype'Fixed_Value (integer-value)
1731 -- fixtype(integer-value)
1733 -- we do all the required analysis of the conversion here, because
1734 -- we do not want this to go through the fixed-point conversion
1735 -- circuits. Note that gigi always treats fixed-point as equivalent
1736 -- to the corresponding integer type anyway.
1738 when Attribute_Fixed_Value
=> Fixed_Value
:
1741 Make_Type_Conversion
(Loc
,
1742 Subtype_Mark
=> New_Occurrence_Of
(Entity
(Pref
), Loc
),
1743 Expression
=> Relocate_Node
(First
(Exprs
))));
1744 Set_Etype
(N
, Entity
(Pref
));
1747 -- Note: it might appear that a properly analyzed unchecked conversion
1748 -- would be just fine here, but that's not the case, since the full
1749 -- range checks performed by the following call are critical!
1751 Apply_Type_Conversion_Checks
(N
);
1758 -- Transforms 'Floor into a call to the floating-point attribute
1759 -- function Floor in Fat_xxx (where xxx is the root type)
1761 when Attribute_Floor
=>
1762 Expand_Fpt_Attribute_R
(N
);
1768 -- For the fixed-point type Typ:
1774 -- Result_Type (System.Fore (Universal_Real (Type'First)),
1775 -- Universal_Real (Type'Last))
1777 -- Note that we know that the type is a non-static subtype, or Fore
1778 -- would have itself been computed dynamically in Eval_Attribute.
1780 when Attribute_Fore
=> Fore
:
1782 Ptyp
: constant Entity_Id
:= Etype
(Pref
);
1787 Make_Function_Call
(Loc
,
1788 Name
=> New_Reference_To
(RTE
(RE_Fore
), Loc
),
1790 Parameter_Associations
=> New_List
(
1791 Convert_To
(Universal_Real
,
1792 Make_Attribute_Reference
(Loc
,
1793 Prefix
=> New_Reference_To
(Ptyp
, Loc
),
1794 Attribute_Name
=> Name_First
)),
1796 Convert_To
(Universal_Real
,
1797 Make_Attribute_Reference
(Loc
,
1798 Prefix
=> New_Reference_To
(Ptyp
, Loc
),
1799 Attribute_Name
=> Name_Last
))))));
1801 Analyze_And_Resolve
(N
, Typ
);
1808 -- Transforms 'Fraction into a call to the floating-point attribute
1809 -- function Fraction in Fat_xxx (where xxx is the root type)
1811 when Attribute_Fraction
=>
1812 Expand_Fpt_Attribute_R
(N
);
1818 -- For an exception returns a reference to the exception data:
1819 -- Exception_Id!(Prefix'Reference)
1821 -- For a task it returns a reference to the _task_id component of
1822 -- corresponding record:
1824 -- taskV!(Prefix)._Task_Id, converted to the type Task_Id defined
1826 -- in Ada.Task_Identification
1828 when Attribute_Identity
=> Identity
: declare
1829 Id_Kind
: Entity_Id
;
1832 if Etype
(Pref
) = Standard_Exception_Type
then
1833 Id_Kind
:= RTE
(RE_Exception_Id
);
1835 if Present
(Renamed_Object
(Entity
(Pref
))) then
1836 Set_Entity
(Pref
, Renamed_Object
(Entity
(Pref
)));
1840 Unchecked_Convert_To
(Id_Kind
, Make_Reference
(Loc
, Pref
)));
1842 Id_Kind
:= RTE
(RO_AT_Task_Id
);
1845 Unchecked_Convert_To
(Id_Kind
, Concurrent_Ref
(Pref
)));
1848 Analyze_And_Resolve
(N
, Id_Kind
);
1855 -- Image attribute is handled in separate unit Exp_Imgv
1857 when Attribute_Image
=>
1858 Exp_Imgv
.Expand_Image_Attribute
(N
);
1864 -- X'Img is expanded to typ'Image (X), where typ is the type of X
1866 when Attribute_Img
=> Img
:
1869 Make_Attribute_Reference
(Loc
,
1870 Prefix
=> New_Reference_To
(Etype
(Pref
), Loc
),
1871 Attribute_Name
=> Name_Image
,
1872 Expressions
=> New_List
(Relocate_Node
(Pref
))));
1874 Analyze_And_Resolve
(N
, Standard_String
);
1881 when Attribute_Input
=> Input
: declare
1882 P_Type
: constant Entity_Id
:= Entity
(Pref
);
1883 B_Type
: constant Entity_Id
:= Base_Type
(P_Type
);
1884 U_Type
: constant Entity_Id
:= Underlying_Type
(P_Type
);
1885 Strm
: constant Node_Id
:= First
(Exprs
);
1893 Cntrl
: Node_Id
:= Empty
;
1894 -- Value for controlling argument in call. Always Empty except in
1895 -- the dispatching (class-wide type) case, where it is a reference
1896 -- to the dummy object initialized to the right internal tag.
1898 procedure Freeze_Stream_Subprogram
(F
: Entity_Id
);
1899 -- The expansion of the attribute reference may generate a call to
1900 -- a user-defined stream subprogram that is frozen by the call. This
1901 -- can lead to access-before-elaboration problem if the reference
1902 -- appears in an object declaration and the subprogram body has not
1903 -- been seen. The freezing of the subprogram requires special code
1904 -- because it appears in an expanded context where expressions do
1905 -- not freeze their constituents.
1907 ------------------------------
1908 -- Freeze_Stream_Subprogram --
1909 ------------------------------
1911 procedure Freeze_Stream_Subprogram
(F
: Entity_Id
) is
1912 Decl
: constant Node_Id
:= Unit_Declaration_Node
(F
);
1916 -- If this is user-defined subprogram, the corresponding
1917 -- stream function appears as a renaming-as-body, and the
1918 -- user subprogram must be retrieved by tree traversal.
1921 and then Nkind
(Decl
) = N_Subprogram_Declaration
1922 and then Present
(Corresponding_Body
(Decl
))
1924 Bod
:= Corresponding_Body
(Decl
);
1926 if Nkind
(Unit_Declaration_Node
(Bod
)) =
1927 N_Subprogram_Renaming_Declaration
1929 Set_Is_Frozen
(Entity
(Name
(Unit_Declaration_Node
(Bod
))));
1932 end Freeze_Stream_Subprogram
;
1934 -- Start of processing for Input
1937 -- If no underlying type, we have an error that will be diagnosed
1938 -- elsewhere, so here we just completely ignore the expansion.
1944 -- If there is a TSS for Input, just call it
1946 Fname
:= Find_Stream_Subprogram
(P_Type
, TSS_Stream_Input
);
1948 if Present
(Fname
) then
1952 -- If there is a Stream_Convert pragma, use it, we rewrite
1954 -- sourcetyp'Input (stream)
1958 -- sourcetyp (streamread (strmtyp'Input (stream)));
1960 -- where stmrearead is the given Read function that converts
1961 -- an argument of type strmtyp to type sourcetyp or a type
1962 -- from which it is derived. The extra conversion is required
1963 -- for the derived case.
1965 Prag
:= Get_Stream_Convert_Pragma
(P_Type
);
1967 if Present
(Prag
) then
1968 Arg2
:= Next
(First
(Pragma_Argument_Associations
(Prag
)));
1969 Rfunc
:= Entity
(Expression
(Arg2
));
1973 Make_Function_Call
(Loc
,
1974 Name
=> New_Occurrence_Of
(Rfunc
, Loc
),
1975 Parameter_Associations
=> New_List
(
1976 Make_Attribute_Reference
(Loc
,
1979 (Etype
(First_Formal
(Rfunc
)), Loc
),
1980 Attribute_Name
=> Name_Input
,
1981 Expressions
=> Exprs
)))));
1983 Analyze_And_Resolve
(N
, B_Type
);
1988 elsif Is_Elementary_Type
(U_Type
) then
1990 -- A special case arises if we have a defined _Read routine,
1991 -- since in this case we are required to call this routine.
1993 if Present
(TSS
(Base_Type
(U_Type
), TSS_Stream_Read
)) then
1994 Build_Record_Or_Elementary_Input_Function
1995 (Loc
, U_Type
, Decl
, Fname
);
1996 Insert_Action
(N
, Decl
);
1998 -- For normal cases, we call the I_xxx routine directly
2001 Rewrite
(N
, Build_Elementary_Input_Call
(N
));
2002 Analyze_And_Resolve
(N
, P_Type
);
2008 elsif Is_Array_Type
(U_Type
) then
2009 Build_Array_Input_Function
(Loc
, U_Type
, Decl
, Fname
);
2010 Compile_Stream_Body_In_Scope
(N
, Decl
, U_Type
, Check
=> False);
2012 -- Dispatching case with class-wide type
2014 elsif Is_Class_Wide_Type
(P_Type
) then
2017 Rtyp
: constant Entity_Id
:= Root_Type
(P_Type
);
2022 -- Read the internal tag (RM 13.13.2(34)) and use it to
2023 -- initialize a dummy tag object:
2025 -- Dnn : Ada.Tags.Tag
2026 -- := Descendant_Tag (String'Input (Strm), P_Type);
2028 -- This dummy object is used only to provide a controlling
2029 -- argument for the eventual _Input call. Descendant_Tag is
2030 -- called rather than Internal_Tag to ensure that we have a
2031 -- tag for a type that is descended from the prefix type and
2032 -- declared at the same accessibility level (the exception
2033 -- Tag_Error will be raised otherwise). The level check is
2034 -- required for Ada 2005 because tagged types can be
2035 -- extended in nested scopes (AI-344).
2038 Make_Defining_Identifier
(Loc
,
2039 Chars
=> New_Internal_Name
('D'));
2042 Make_Object_Declaration
(Loc
,
2043 Defining_Identifier
=> Dnn
,
2044 Object_Definition
=>
2045 New_Occurrence_Of
(RTE
(RE_Tag
), Loc
),
2047 Make_Function_Call
(Loc
,
2049 New_Occurrence_Of
(RTE
(RE_Descendant_Tag
), Loc
),
2050 Parameter_Associations
=> New_List
(
2051 Make_Attribute_Reference
(Loc
,
2053 New_Occurrence_Of
(Standard_String
, Loc
),
2054 Attribute_Name
=> Name_Input
,
2055 Expressions
=> New_List
(
2057 (Duplicate_Subexpr
(Strm
)))),
2058 Make_Attribute_Reference
(Loc
,
2059 Prefix
=> New_Reference_To
(P_Type
, Loc
),
2060 Attribute_Name
=> Name_Tag
))));
2062 Insert_Action
(N
, Decl
);
2064 -- Now we need to get the entity for the call, and construct
2065 -- a function call node, where we preset a reference to Dnn
2066 -- as the controlling argument (doing an unchecked convert
2067 -- to the class-wide tagged type to make it look like a real
2070 Fname
:= Find_Prim_Op
(Rtyp
, TSS_Stream_Input
);
2071 Cntrl
:= Unchecked_Convert_To
(P_Type
,
2072 New_Occurrence_Of
(Dnn
, Loc
));
2073 Set_Etype
(Cntrl
, P_Type
);
2074 Set_Parent
(Cntrl
, N
);
2077 -- For tagged types, use the primitive Input function
2079 elsif Is_Tagged_Type
(U_Type
) then
2080 Fname
:= Find_Prim_Op
(U_Type
, TSS_Stream_Input
);
2082 -- All other record type cases, including protected records. The
2083 -- latter only arise for expander generated code for handling
2084 -- shared passive partition access.
2088 (Is_Record_Type
(U_Type
) or else Is_Protected_Type
(U_Type
));
2090 -- Ada 2005 (AI-216): Program_Error is raised when executing
2091 -- the default implementation of the Input attribute of an
2092 -- unchecked union type if the type lacks default discriminant
2095 if Is_Unchecked_Union
(Base_Type
(U_Type
))
2096 and then No
(Discriminant_Constraint
(U_Type
))
2099 Make_Raise_Program_Error
(Loc
,
2100 Reason
=> PE_Unchecked_Union_Restriction
));
2105 Build_Record_Or_Elementary_Input_Function
2106 (Loc
, Base_Type
(U_Type
), Decl
, Fname
);
2107 Insert_Action
(N
, Decl
);
2109 if Nkind
(Parent
(N
)) = N_Object_Declaration
2110 and then Is_Record_Type
(U_Type
)
2112 -- The stream function may contain calls to user-defined
2113 -- Read procedures for individual components.
2120 Comp
:= First_Component
(U_Type
);
2121 while Present
(Comp
) loop
2123 Find_Stream_Subprogram
2124 (Etype
(Comp
), TSS_Stream_Read
);
2126 if Present
(Func
) then
2127 Freeze_Stream_Subprogram
(Func
);
2130 Next_Component
(Comp
);
2137 -- If we fall through, Fname is the function to be called. The result
2138 -- is obtained by calling the appropriate function, then converting
2139 -- the result. The conversion does a subtype check.
2142 Make_Function_Call
(Loc
,
2143 Name
=> New_Occurrence_Of
(Fname
, Loc
),
2144 Parameter_Associations
=> New_List
(
2145 Relocate_Node
(Strm
)));
2147 Set_Controlling_Argument
(Call
, Cntrl
);
2148 Rewrite
(N
, Unchecked_Convert_To
(P_Type
, Call
));
2149 Analyze_And_Resolve
(N
, P_Type
);
2151 if Nkind
(Parent
(N
)) = N_Object_Declaration
then
2152 Freeze_Stream_Subprogram
(Fname
);
2162 -- inttype'Fixed_Value (fixed-value)
2166 -- inttype(integer-value))
2168 -- we do all the required analysis of the conversion here, because
2169 -- we do not want this to go through the fixed-point conversion
2170 -- circuits. Note that gigi always treats fixed-point as equivalent
2171 -- to the corresponding integer type anyway.
2173 when Attribute_Integer_Value
=> Integer_Value
:
2176 Make_Type_Conversion
(Loc
,
2177 Subtype_Mark
=> New_Occurrence_Of
(Entity
(Pref
), Loc
),
2178 Expression
=> Relocate_Node
(First
(Exprs
))));
2179 Set_Etype
(N
, Entity
(Pref
));
2182 -- Note: it might appear that a properly analyzed unchecked conversion
2183 -- would be just fine here, but that's not the case, since the full
2184 -- range checks performed by the following call are critical!
2186 Apply_Type_Conversion_Checks
(N
);
2193 when Attribute_Last
=> declare
2194 Ptyp
: constant Entity_Id
:= Etype
(Pref
);
2197 -- If the prefix type is a constrained packed array type which
2198 -- already has a Packed_Array_Type representation defined, then
2199 -- replace this attribute with a direct reference to 'Last of the
2200 -- appropriate index subtype (since otherwise Gigi will try to give
2201 -- us the value of 'Last for this implementation type).
2203 if Is_Constrained_Packed_Array
(Ptyp
) then
2205 Make_Attribute_Reference
(Loc
,
2206 Attribute_Name
=> Name_Last
,
2207 Prefix
=> New_Reference_To
(Get_Index_Subtype
(N
), Loc
)));
2208 Analyze_And_Resolve
(N
, Typ
);
2210 elsif Is_Access_Type
(Ptyp
) then
2211 Apply_Access_Check
(N
);
2219 -- We compute this if a component clause was present, otherwise
2220 -- we leave the computation up to Gigi, since we don't know what
2221 -- layout will be chosen.
2223 when Attribute_Last_Bit
=> Last_Bit
:
2225 CE
: constant Entity_Id
:= Entity
(Selector_Name
(Pref
));
2228 if Known_Static_Component_Bit_Offset
(CE
)
2229 and then Known_Static_Esize
(CE
)
2232 Make_Integer_Literal
(Loc
,
2233 Intval
=> (Component_Bit_Offset
(CE
) mod System_Storage_Unit
)
2236 Analyze_And_Resolve
(N
, Typ
);
2239 Apply_Universal_Integer_Attribute_Checks
(N
);
2247 -- Transforms 'Leading_Part into a call to the floating-point attribute
2248 -- function Leading_Part in Fat_xxx (where xxx is the root type)
2250 -- Note: strictly, we should have special case code to deal with
2251 -- absurdly large positive arguments (greater than Integer'Last), which
2252 -- result in returning the first argument unchanged, but it hardly seems
2253 -- worth the effort. We raise constraint error for absurdly negative
2254 -- arguments which is fine.
2256 when Attribute_Leading_Part
=>
2257 Expand_Fpt_Attribute_RI
(N
);
2263 when Attribute_Length
=> declare
2264 Ptyp
: constant Entity_Id
:= Etype
(Pref
);
2269 -- Processing for packed array types
2271 if Is_Array_Type
(Ptyp
) and then Is_Packed
(Ptyp
) then
2272 Ityp
:= Get_Index_Subtype
(N
);
2274 -- If the index type, Ityp, is an enumeration type with
2275 -- holes, then we calculate X'Length explicitly using
2278 -- (0, Ityp'Pos (X'Last (N)) -
2279 -- Ityp'Pos (X'First (N)) + 1);
2281 -- Since the bounds in the template are the representation
2282 -- values and gigi would get the wrong value.
2284 if Is_Enumeration_Type
(Ityp
)
2285 and then Present
(Enum_Pos_To_Rep
(Base_Type
(Ityp
)))
2290 Xnum
:= Expr_Value
(First
(Expressions
(N
)));
2294 Make_Attribute_Reference
(Loc
,
2295 Prefix
=> New_Occurrence_Of
(Typ
, Loc
),
2296 Attribute_Name
=> Name_Max
,
2297 Expressions
=> New_List
2298 (Make_Integer_Literal
(Loc
, 0),
2302 Make_Op_Subtract
(Loc
,
2304 Make_Attribute_Reference
(Loc
,
2305 Prefix
=> New_Occurrence_Of
(Ityp
, Loc
),
2306 Attribute_Name
=> Name_Pos
,
2308 Expressions
=> New_List
(
2309 Make_Attribute_Reference
(Loc
,
2310 Prefix
=> Duplicate_Subexpr
(Pref
),
2311 Attribute_Name
=> Name_Last
,
2312 Expressions
=> New_List
(
2313 Make_Integer_Literal
(Loc
, Xnum
))))),
2316 Make_Attribute_Reference
(Loc
,
2317 Prefix
=> New_Occurrence_Of
(Ityp
, Loc
),
2318 Attribute_Name
=> Name_Pos
,
2320 Expressions
=> New_List
(
2321 Make_Attribute_Reference
(Loc
,
2323 Duplicate_Subexpr_No_Checks
(Pref
),
2324 Attribute_Name
=> Name_First
,
2325 Expressions
=> New_List
(
2326 Make_Integer_Literal
(Loc
, Xnum
)))))),
2328 Right_Opnd
=> Make_Integer_Literal
(Loc
, 1)))));
2330 Analyze_And_Resolve
(N
, Typ
, Suppress
=> All_Checks
);
2333 -- If the prefix type is a constrained packed array type which
2334 -- already has a Packed_Array_Type representation defined, then
2335 -- replace this attribute with a direct reference to 'Range_Length
2336 -- of the appropriate index subtype (since otherwise Gigi will try
2337 -- to give us the value of 'Length for this implementation type).
2339 elsif Is_Constrained
(Ptyp
) then
2341 Make_Attribute_Reference
(Loc
,
2342 Attribute_Name
=> Name_Range_Length
,
2343 Prefix
=> New_Reference_To
(Ityp
, Loc
)));
2344 Analyze_And_Resolve
(N
, Typ
);
2347 -- If we have a packed array that is not bit packed, which was
2351 elsif Is_Access_Type
(Ptyp
) then
2352 Apply_Access_Check
(N
);
2354 -- If the designated type is a packed array type, then we
2355 -- convert the reference to:
2358 -- xtyp'Pos (Pref'Last (Expr)) -
2359 -- xtyp'Pos (Pref'First (Expr)));
2361 -- This is a bit complex, but it is the easiest thing to do
2362 -- that works in all cases including enum types with holes
2363 -- xtyp here is the appropriate index type.
2366 Dtyp
: constant Entity_Id
:= Designated_Type
(Ptyp
);
2370 if Is_Array_Type
(Dtyp
) and then Is_Packed
(Dtyp
) then
2371 Xtyp
:= Get_Index_Subtype
(N
);
2374 Make_Attribute_Reference
(Loc
,
2375 Prefix
=> New_Occurrence_Of
(Typ
, Loc
),
2376 Attribute_Name
=> Name_Max
,
2377 Expressions
=> New_List
(
2378 Make_Integer_Literal
(Loc
, 0),
2381 Make_Integer_Literal
(Loc
, 1),
2382 Make_Op_Subtract
(Loc
,
2384 Make_Attribute_Reference
(Loc
,
2385 Prefix
=> New_Occurrence_Of
(Xtyp
, Loc
),
2386 Attribute_Name
=> Name_Pos
,
2387 Expressions
=> New_List
(
2388 Make_Attribute_Reference
(Loc
,
2389 Prefix
=> Duplicate_Subexpr
(Pref
),
2390 Attribute_Name
=> Name_Last
,
2392 New_Copy_List
(Exprs
)))),
2395 Make_Attribute_Reference
(Loc
,
2396 Prefix
=> New_Occurrence_Of
(Xtyp
, Loc
),
2397 Attribute_Name
=> Name_Pos
,
2398 Expressions
=> New_List
(
2399 Make_Attribute_Reference
(Loc
,
2401 Duplicate_Subexpr_No_Checks
(Pref
),
2402 Attribute_Name
=> Name_First
,
2404 New_Copy_List
(Exprs
)))))))));
2406 Analyze_And_Resolve
(N
, Typ
);
2410 -- Otherwise leave it to gigi
2413 Apply_Universal_Integer_Attribute_Checks
(N
);
2421 -- Transforms 'Machine into a call to the floating-point attribute
2422 -- function Machine in Fat_xxx (where xxx is the root type)
2424 when Attribute_Machine
=>
2425 Expand_Fpt_Attribute_R
(N
);
2427 ----------------------
2428 -- Machine_Rounding --
2429 ----------------------
2431 -- Transforms 'Machine_Rounding into a call to the floating-point
2432 -- attribute function Machine_Rounding in Fat_xxx (where xxx is the root
2435 when Attribute_Machine_Rounding
=>
2436 Expand_Fpt_Attribute_R
(N
);
2442 -- Machine_Size is equivalent to Object_Size, so transform it into
2443 -- Object_Size and that way Gigi never sees Machine_Size.
2445 when Attribute_Machine_Size
=>
2447 Make_Attribute_Reference
(Loc
,
2448 Prefix
=> Prefix
(N
),
2449 Attribute_Name
=> Name_Object_Size
));
2451 Analyze_And_Resolve
(N
, Typ
);
2457 -- The only case that can get this far is the dynamic case of the old
2458 -- Ada 83 Mantissa attribute for the fixed-point case. For this case, we
2465 -- ityp (System.Mantissa.Mantissa_Value
2466 -- (Integer'Integer_Value (typ'First),
2467 -- Integer'Integer_Value (typ'Last)));
2469 when Attribute_Mantissa
=> Mantissa
: declare
2470 Ptyp
: constant Entity_Id
:= Etype
(Pref
);
2475 Make_Function_Call
(Loc
,
2476 Name
=> New_Occurrence_Of
(RTE
(RE_Mantissa_Value
), Loc
),
2478 Parameter_Associations
=> New_List
(
2480 Make_Attribute_Reference
(Loc
,
2481 Prefix
=> New_Occurrence_Of
(Standard_Integer
, Loc
),
2482 Attribute_Name
=> Name_Integer_Value
,
2483 Expressions
=> New_List
(
2485 Make_Attribute_Reference
(Loc
,
2486 Prefix
=> New_Occurrence_Of
(Ptyp
, Loc
),
2487 Attribute_Name
=> Name_First
))),
2489 Make_Attribute_Reference
(Loc
,
2490 Prefix
=> New_Occurrence_Of
(Standard_Integer
, Loc
),
2491 Attribute_Name
=> Name_Integer_Value
,
2492 Expressions
=> New_List
(
2494 Make_Attribute_Reference
(Loc
,
2495 Prefix
=> New_Occurrence_Of
(Ptyp
, Loc
),
2496 Attribute_Name
=> Name_Last
)))))));
2498 Analyze_And_Resolve
(N
, Typ
);
2501 --------------------
2502 -- Mechanism_Code --
2503 --------------------
2505 when Attribute_Mechanism_Code
=>
2507 -- We must replace the prefix in the renamed case
2509 if Is_Entity_Name
(Pref
)
2510 and then Present
(Alias
(Entity
(Pref
)))
2512 Set_Renamed_Subprogram
(Pref
, Alias
(Entity
(Pref
)));
2519 when Attribute_Mod
=> Mod_Case
: declare
2520 Arg
: constant Node_Id
:= Relocate_Node
(First
(Exprs
));
2521 Hi
: constant Node_Id
:= Type_High_Bound
(Etype
(Arg
));
2522 Modv
: constant Uint
:= Modulus
(Btyp
);
2526 -- This is not so simple. The issue is what type to use for the
2527 -- computation of the modular value.
2529 -- The easy case is when the modulus value is within the bounds
2530 -- of the signed integer type of the argument. In this case we can
2531 -- just do the computation in that signed integer type, and then
2532 -- do an ordinary conversion to the target type.
2534 if Modv
<= Expr_Value
(Hi
) then
2539 Right_Opnd
=> Make_Integer_Literal
(Loc
, Modv
))));
2541 -- Here we know that the modulus is larger than type'Last of the
2542 -- integer type. There are two cases to consider:
2544 -- a) The integer value is non-negative. In this case, it is
2545 -- returned as the result (since it is less than the modulus).
2547 -- b) The integer value is negative. In this case, we know that the
2548 -- result is modulus + value, where the value might be as small as
2549 -- -modulus. The trouble is what type do we use to do the subtract.
2550 -- No type will do, since modulus can be as big as 2**64, and no
2551 -- integer type accomodates this value. Let's do bit of algebra
2554 -- = modulus - (-value)
2555 -- = (modulus - 1) - (-value - 1)
2557 -- Now modulus - 1 is certainly in range of the modular type.
2558 -- -value is in the range 1 .. modulus, so -value -1 is in the
2559 -- range 0 .. modulus-1 which is in range of the modular type.
2560 -- Furthermore, (-value - 1) can be expressed as -(value + 1)
2561 -- which we can compute using the integer base type.
2563 -- Once this is done we analyze the conditional expression without
2564 -- range checks, because we know everything is in range, and we
2565 -- want to prevent spurious warnings on either branch.
2569 Make_Conditional_Expression
(Loc
,
2570 Expressions
=> New_List
(
2572 Left_Opnd
=> Duplicate_Subexpr
(Arg
),
2573 Right_Opnd
=> Make_Integer_Literal
(Loc
, 0)),
2576 Duplicate_Subexpr_No_Checks
(Arg
)),
2578 Make_Op_Subtract
(Loc
,
2580 Make_Integer_Literal
(Loc
,
2581 Intval
=> Modv
- 1),
2587 Left_Opnd
=> Duplicate_Subexpr_No_Checks
(Arg
),
2589 Make_Integer_Literal
(Loc
,
2590 Intval
=> 1))))))));
2594 Analyze_And_Resolve
(N
, Btyp
, Suppress
=> All_Checks
);
2601 -- Transforms 'Model into a call to the floating-point attribute
2602 -- function Model in Fat_xxx (where xxx is the root type)
2604 when Attribute_Model
=>
2605 Expand_Fpt_Attribute_R
(N
);
2611 -- The processing for Object_Size shares the processing for Size
2617 when Attribute_Output
=> Output
: declare
2618 P_Type
: constant Entity_Id
:= Entity
(Pref
);
2619 U_Type
: constant Entity_Id
:= Underlying_Type
(P_Type
);
2627 -- If no underlying type, we have an error that will be diagnosed
2628 -- elsewhere, so here we just completely ignore the expansion.
2634 -- If TSS for Output is present, just call it
2636 Pname
:= Find_Stream_Subprogram
(P_Type
, TSS_Stream_Output
);
2638 if Present
(Pname
) then
2642 -- If there is a Stream_Convert pragma, use it, we rewrite
2644 -- sourcetyp'Output (stream, Item)
2648 -- strmtyp'Output (Stream, strmwrite (acttyp (Item)));
2650 -- where strmwrite is the given Write function that converts an
2651 -- argument of type sourcetyp or a type acctyp, from which it is
2652 -- derived to type strmtyp. The conversion to acttyp is required
2653 -- for the derived case.
2655 Prag
:= Get_Stream_Convert_Pragma
(P_Type
);
2657 if Present
(Prag
) then
2659 Next
(Next
(First
(Pragma_Argument_Associations
(Prag
))));
2660 Wfunc
:= Entity
(Expression
(Arg3
));
2663 Make_Attribute_Reference
(Loc
,
2664 Prefix
=> New_Occurrence_Of
(Etype
(Wfunc
), Loc
),
2665 Attribute_Name
=> Name_Output
,
2666 Expressions
=> New_List
(
2667 Relocate_Node
(First
(Exprs
)),
2668 Make_Function_Call
(Loc
,
2669 Name
=> New_Occurrence_Of
(Wfunc
, Loc
),
2670 Parameter_Associations
=> New_List
(
2671 Convert_To
(Etype
(First_Formal
(Wfunc
)),
2672 Relocate_Node
(Next
(First
(Exprs
)))))))));
2677 -- For elementary types, we call the W_xxx routine directly.
2678 -- Note that the effect of Write and Output is identical for
2679 -- the case of an elementary type, since there are no
2680 -- discriminants or bounds.
2682 elsif Is_Elementary_Type
(U_Type
) then
2684 -- A special case arises if we have a defined _Write routine,
2685 -- since in this case we are required to call this routine.
2687 if Present
(TSS
(Base_Type
(U_Type
), TSS_Stream_Write
)) then
2688 Build_Record_Or_Elementary_Output_Procedure
2689 (Loc
, U_Type
, Decl
, Pname
);
2690 Insert_Action
(N
, Decl
);
2692 -- For normal cases, we call the W_xxx routine directly
2695 Rewrite
(N
, Build_Elementary_Write_Call
(N
));
2702 elsif Is_Array_Type
(U_Type
) then
2703 Build_Array_Output_Procedure
(Loc
, U_Type
, Decl
, Pname
);
2704 Compile_Stream_Body_In_Scope
(N
, Decl
, U_Type
, Check
=> False);
2706 -- Class-wide case, first output external tag, then dispatch
2707 -- to the appropriate primitive Output function (RM 13.13.2(31)).
2709 elsif Is_Class_Wide_Type
(P_Type
) then
2711 Strm
: constant Node_Id
:= First
(Exprs
);
2712 Item
: constant Node_Id
:= Next
(Strm
);
2716 -- if Get_Access_Level (Item'Tag)
2717 -- /= Get_Access_Level (P_Type'Tag)
2721 -- String'Output (Strm, External_Tag (Item'Tag));
2723 -- Ada 2005 (AI-344): Check that the accessibility level
2724 -- of the type of the output object is not deeper than
2725 -- that of the attribute's prefix type.
2727 if Ada_Version
>= Ada_05
then
2729 Make_Implicit_If_Statement
(N
,
2733 Make_Function_Call
(Loc
,
2736 (RTE
(RE_Get_Access_Level
), Loc
),
2737 Parameter_Associations
=>
2738 New_List
(Make_Attribute_Reference
(Loc
,
2741 Duplicate_Subexpr
(Item
,
2746 Make_Integer_Literal
2747 (Loc
, Type_Access_Level
(P_Type
))),
2749 New_List
(Make_Raise_Statement
(Loc
,
2751 RTE
(RE_Tag_Error
), Loc
)))));
2755 Make_Attribute_Reference
(Loc
,
2756 Prefix
=> New_Occurrence_Of
(Standard_String
, Loc
),
2757 Attribute_Name
=> Name_Output
,
2758 Expressions
=> New_List
(
2759 Relocate_Node
(Duplicate_Subexpr
(Strm
)),
2760 Make_Function_Call
(Loc
,
2762 New_Occurrence_Of
(RTE
(RE_External_Tag
), Loc
),
2763 Parameter_Associations
=> New_List
(
2764 Make_Attribute_Reference
(Loc
,
2767 (Duplicate_Subexpr
(Item
, Name_Req
=> True)),
2768 Attribute_Name
=> Name_Tag
))))));
2771 Pname
:= Find_Prim_Op
(U_Type
, TSS_Stream_Output
);
2773 -- Tagged type case, use the primitive Output function
2775 elsif Is_Tagged_Type
(U_Type
) then
2776 Pname
:= Find_Prim_Op
(U_Type
, TSS_Stream_Output
);
2778 -- -- All other record type cases, including protected records.
2779 -- -- The latter only arise for expander generated code for
2780 -- -- handling shared passive partition access.
2784 (Is_Record_Type
(U_Type
) or else Is_Protected_Type
(U_Type
));
2786 -- Ada 2005 (AI-216): Program_Error is raised when executing
2787 -- the default implementation of the Output attribute of an
2788 -- unchecked union type if the type lacks default discriminant
2791 if Is_Unchecked_Union
(Base_Type
(U_Type
))
2792 and then No
(Discriminant_Constraint
(U_Type
))
2795 Make_Raise_Program_Error
(Loc
,
2796 Reason
=> PE_Unchecked_Union_Restriction
));
2801 Build_Record_Or_Elementary_Output_Procedure
2802 (Loc
, Base_Type
(U_Type
), Decl
, Pname
);
2803 Insert_Action
(N
, Decl
);
2807 -- If we fall through, Pname is the name of the procedure to call
2809 Rewrite_Stream_Proc_Call
(Pname
);
2816 -- For enumeration types with a standard representation, Pos is
2819 -- For enumeration types, with a non-standard representation we
2820 -- generate a call to the _Rep_To_Pos function created when the
2821 -- type was frozen. The call has the form
2823 -- _rep_to_pos (expr, flag)
2825 -- The parameter flag is True if range checks are enabled, causing
2826 -- Program_Error to be raised if the expression has an invalid
2827 -- representation, and False if range checks are suppressed.
2829 -- For integer types, Pos is equivalent to a simple integer
2830 -- conversion and we rewrite it as such
2832 when Attribute_Pos
=> Pos
:
2834 Etyp
: Entity_Id
:= Base_Type
(Entity
(Pref
));
2837 -- Deal with zero/non-zero boolean values
2839 if Is_Boolean_Type
(Etyp
) then
2840 Adjust_Condition
(First
(Exprs
));
2841 Etyp
:= Standard_Boolean
;
2842 Set_Prefix
(N
, New_Occurrence_Of
(Standard_Boolean
, Loc
));
2845 -- Case of enumeration type
2847 if Is_Enumeration_Type
(Etyp
) then
2849 -- Non-standard enumeration type (generate call)
2851 if Present
(Enum_Pos_To_Rep
(Etyp
)) then
2852 Append_To
(Exprs
, Rep_To_Pos_Flag
(Etyp
, Loc
));
2855 Make_Function_Call
(Loc
,
2857 New_Reference_To
(TSS
(Etyp
, TSS_Rep_To_Pos
), Loc
),
2858 Parameter_Associations
=> Exprs
)));
2860 Analyze_And_Resolve
(N
, Typ
);
2862 -- Standard enumeration type (do universal integer check)
2865 Apply_Universal_Integer_Attribute_Checks
(N
);
2868 -- Deal with integer types (replace by conversion)
2870 elsif Is_Integer_Type
(Etyp
) then
2871 Rewrite
(N
, Convert_To
(Typ
, First
(Exprs
)));
2872 Analyze_And_Resolve
(N
, Typ
);
2881 -- We compute this if a component clause was present, otherwise
2882 -- we leave the computation up to Gigi, since we don't know what
2883 -- layout will be chosen.
2885 when Attribute_Position
=> Position
:
2887 CE
: constant Entity_Id
:= Entity
(Selector_Name
(Pref
));
2890 if Present
(Component_Clause
(CE
)) then
2892 Make_Integer_Literal
(Loc
,
2893 Intval
=> Component_Bit_Offset
(CE
) / System_Storage_Unit
));
2894 Analyze_And_Resolve
(N
, Typ
);
2897 Apply_Universal_Integer_Attribute_Checks
(N
);
2905 -- 1. Deal with enumeration types with holes
2906 -- 2. For floating-point, generate call to attribute function
2907 -- 3. For other cases, deal with constraint checking
2909 when Attribute_Pred
=> Pred
:
2911 Ptyp
: constant Entity_Id
:= Base_Type
(Etype
(Pref
));
2914 -- For enumeration types with non-standard representations, we
2915 -- expand typ'Pred (x) into
2917 -- Pos_To_Rep (Rep_To_Pos (x) - 1)
2919 -- If the representation is contiguous, we compute instead
2920 -- Lit1 + Rep_to_Pos (x -1), to catch invalid representations.
2922 if Is_Enumeration_Type
(Ptyp
)
2923 and then Present
(Enum_Pos_To_Rep
(Ptyp
))
2925 if Has_Contiguous_Rep
(Ptyp
) then
2927 Unchecked_Convert_To
(Ptyp
,
2930 Make_Integer_Literal
(Loc
,
2931 Enumeration_Rep
(First_Literal
(Ptyp
))),
2933 Make_Function_Call
(Loc
,
2936 (TSS
(Ptyp
, TSS_Rep_To_Pos
), Loc
),
2938 Parameter_Associations
=>
2940 Unchecked_Convert_To
(Ptyp
,
2941 Make_Op_Subtract
(Loc
,
2943 Unchecked_Convert_To
(Standard_Integer
,
2944 Relocate_Node
(First
(Exprs
))),
2946 Make_Integer_Literal
(Loc
, 1))),
2947 Rep_To_Pos_Flag
(Ptyp
, Loc
))))));
2950 -- Add Boolean parameter True, to request program errror if
2951 -- we have a bad representation on our hands. If checks are
2952 -- suppressed, then add False instead
2954 Append_To
(Exprs
, Rep_To_Pos_Flag
(Ptyp
, Loc
));
2956 Make_Indexed_Component
(Loc
,
2957 Prefix
=> New_Reference_To
(Enum_Pos_To_Rep
(Ptyp
), Loc
),
2958 Expressions
=> New_List
(
2959 Make_Op_Subtract
(Loc
,
2961 Make_Function_Call
(Loc
,
2963 New_Reference_To
(TSS
(Ptyp
, TSS_Rep_To_Pos
), Loc
),
2964 Parameter_Associations
=> Exprs
),
2965 Right_Opnd
=> Make_Integer_Literal
(Loc
, 1)))));
2968 Analyze_And_Resolve
(N
, Typ
);
2970 -- For floating-point, we transform 'Pred into a call to the Pred
2971 -- floating-point attribute function in Fat_xxx (xxx is root type)
2973 elsif Is_Floating_Point_Type
(Ptyp
) then
2974 Expand_Fpt_Attribute_R
(N
);
2975 Analyze_And_Resolve
(N
, Typ
);
2977 -- For modular types, nothing to do (no overflow, since wraps)
2979 elsif Is_Modular_Integer_Type
(Ptyp
) then
2982 -- For other types, if range checking is enabled, we must generate
2983 -- a check if overflow checking is enabled.
2985 elsif not Overflow_Checks_Suppressed
(Ptyp
) then
2986 Expand_Pred_Succ
(N
);
2994 -- Ada 2005 (AI-327): Dynamic ceiling priorities
2996 -- We rewrite X'Priority as the following run-time call:
2998 -- Get_Ceiling (X._Object)
3000 -- Note that although X'Priority is notionally an object, it is quite
3001 -- deliberately not defined as an aliased object in the RM. This means
3002 -- that it works fine to rewrite it as a call, without having to worry
3003 -- about complications that would other arise from X'Priority'Access,
3004 -- which is illegal, because of the lack of aliasing.
3006 when Attribute_Priority
=>
3009 Conctyp
: Entity_Id
;
3010 Object_Parm
: Node_Id
;
3012 RT_Subprg_Name
: Node_Id
;
3015 -- Look for the enclosing concurrent type
3017 Conctyp
:= Current_Scope
;
3018 while not Is_Concurrent_Type
(Conctyp
) loop
3019 Conctyp
:= Scope
(Conctyp
);
3022 pragma Assert
(Is_Protected_Type
(Conctyp
));
3024 -- Generate the actual of the call
3026 Subprg
:= Current_Scope
;
3027 while not Present
(Protected_Body_Subprogram
(Subprg
)) loop
3028 Subprg
:= Scope
(Subprg
);
3032 Make_Attribute_Reference
(Loc
,
3034 Make_Selected_Component
(Loc
,
3035 Prefix
=> New_Reference_To
3037 (Protected_Body_Subprogram
(Subprg
)), Loc
),
3039 Make_Identifier
(Loc
, Name_uObject
)),
3040 Attribute_Name
=> Name_Unchecked_Access
);
3042 -- Select the appropriate run-time subprogram
3044 if Number_Entries
(Conctyp
) = 0 then
3046 New_Reference_To
(RTE
(RE_Get_Ceiling
), Loc
);
3049 New_Reference_To
(RTE
(RO_PE_Get_Ceiling
), Loc
);
3053 Make_Function_Call
(Loc
,
3054 Name
=> RT_Subprg_Name
,
3055 Parameter_Associations
=> New_List
(Object_Parm
));
3058 Analyze_And_Resolve
(N
, Typ
);
3065 when Attribute_Range_Length
=> Range_Length
: declare
3066 P_Type
: constant Entity_Id
:= Etype
(Pref
);
3069 -- The only special processing required is for the case where
3070 -- Range_Length is applied to an enumeration type with holes.
3071 -- In this case we transform
3077 -- X'Pos (X'Last) - X'Pos (X'First) + 1
3079 -- So that the result reflects the proper Pos values instead
3080 -- of the underlying representations.
3082 if Is_Enumeration_Type
(P_Type
)
3083 and then Has_Non_Standard_Rep
(P_Type
)
3088 Make_Op_Subtract
(Loc
,
3090 Make_Attribute_Reference
(Loc
,
3091 Attribute_Name
=> Name_Pos
,
3092 Prefix
=> New_Occurrence_Of
(P_Type
, Loc
),
3093 Expressions
=> New_List
(
3094 Make_Attribute_Reference
(Loc
,
3095 Attribute_Name
=> Name_Last
,
3096 Prefix
=> New_Occurrence_Of
(P_Type
, Loc
)))),
3099 Make_Attribute_Reference
(Loc
,
3100 Attribute_Name
=> Name_Pos
,
3101 Prefix
=> New_Occurrence_Of
(P_Type
, Loc
),
3102 Expressions
=> New_List
(
3103 Make_Attribute_Reference
(Loc
,
3104 Attribute_Name
=> Name_First
,
3105 Prefix
=> New_Occurrence_Of
(P_Type
, Loc
))))),
3108 Make_Integer_Literal
(Loc
, 1)));
3110 Analyze_And_Resolve
(N
, Typ
);
3112 -- For all other cases, attribute is handled by Gigi, but we need
3113 -- to deal with the case of the range check on a universal integer.
3116 Apply_Universal_Integer_Attribute_Checks
(N
);
3124 when Attribute_Read
=> Read
: declare
3125 P_Type
: constant Entity_Id
:= Entity
(Pref
);
3126 B_Type
: constant Entity_Id
:= Base_Type
(P_Type
);
3127 U_Type
: constant Entity_Id
:= Underlying_Type
(P_Type
);
3137 -- If no underlying type, we have an error that will be diagnosed
3138 -- elsewhere, so here we just completely ignore the expansion.
3144 -- The simple case, if there is a TSS for Read, just call it
3146 Pname
:= Find_Stream_Subprogram
(P_Type
, TSS_Stream_Read
);
3148 if Present
(Pname
) then
3152 -- If there is a Stream_Convert pragma, use it, we rewrite
3154 -- sourcetyp'Read (stream, Item)
3158 -- Item := sourcetyp (strmread (strmtyp'Input (Stream)));
3160 -- where strmread is the given Read function that converts an
3161 -- argument of type strmtyp to type sourcetyp or a type from which
3162 -- it is derived. The conversion to sourcetyp is required in the
3165 -- A special case arises if Item is a type conversion in which
3166 -- case, we have to expand to:
3168 -- Itemx := typex (strmread (strmtyp'Input (Stream)));
3170 -- where Itemx is the expression of the type conversion (i.e.
3171 -- the actual object), and typex is the type of Itemx.
3173 Prag
:= Get_Stream_Convert_Pragma
(P_Type
);
3175 if Present
(Prag
) then
3176 Arg2
:= Next
(First
(Pragma_Argument_Associations
(Prag
)));
3177 Rfunc
:= Entity
(Expression
(Arg2
));
3178 Lhs
:= Relocate_Node
(Next
(First
(Exprs
)));
3181 Make_Function_Call
(Loc
,
3182 Name
=> New_Occurrence_Of
(Rfunc
, Loc
),
3183 Parameter_Associations
=> New_List
(
3184 Make_Attribute_Reference
(Loc
,
3187 (Etype
(First_Formal
(Rfunc
)), Loc
),
3188 Attribute_Name
=> Name_Input
,
3189 Expressions
=> New_List
(
3190 Relocate_Node
(First
(Exprs
)))))));
3192 if Nkind
(Lhs
) = N_Type_Conversion
then
3193 Lhs
:= Expression
(Lhs
);
3194 Rhs
:= Convert_To
(Etype
(Lhs
), Rhs
);
3198 Make_Assignment_Statement
(Loc
,
3200 Expression
=> Rhs
));
3201 Set_Assignment_OK
(Lhs
);
3205 -- For elementary types, we call the I_xxx routine using the first
3206 -- parameter and then assign the result into the second parameter.
3207 -- We set Assignment_OK to deal with the conversion case.
3209 elsif Is_Elementary_Type
(U_Type
) then
3215 Lhs
:= Relocate_Node
(Next
(First
(Exprs
)));
3216 Rhs
:= Build_Elementary_Input_Call
(N
);
3218 if Nkind
(Lhs
) = N_Type_Conversion
then
3219 Lhs
:= Expression
(Lhs
);
3220 Rhs
:= Convert_To
(Etype
(Lhs
), Rhs
);
3223 Set_Assignment_OK
(Lhs
);
3226 Make_Assignment_Statement
(Loc
,
3228 Expression
=> Rhs
));
3236 elsif Is_Array_Type
(U_Type
) then
3237 Build_Array_Read_Procedure
(N
, U_Type
, Decl
, Pname
);
3238 Compile_Stream_Body_In_Scope
(N
, Decl
, U_Type
, Check
=> False);
3240 -- Tagged type case, use the primitive Read function. Note that
3241 -- this will dispatch in the class-wide case which is what we want
3243 elsif Is_Tagged_Type
(U_Type
) then
3244 Pname
:= Find_Prim_Op
(U_Type
, TSS_Stream_Read
);
3246 -- All other record type cases, including protected records. The
3247 -- latter only arise for expander generated code for handling
3248 -- shared passive partition access.
3252 (Is_Record_Type
(U_Type
) or else Is_Protected_Type
(U_Type
));
3254 -- Ada 2005 (AI-216): Program_Error is raised when executing
3255 -- the default implementation of the Read attribute of an
3256 -- Unchecked_Union type.
3258 if Is_Unchecked_Union
(Base_Type
(U_Type
)) then
3260 Make_Raise_Program_Error
(Loc
,
3261 Reason
=> PE_Unchecked_Union_Restriction
));
3264 if Has_Discriminants
(U_Type
)
3266 (Discriminant_Default_Value
(First_Discriminant
(U_Type
)))
3268 Build_Mutable_Record_Read_Procedure
3269 (Loc
, Base_Type
(U_Type
), Decl
, Pname
);
3271 Build_Record_Read_Procedure
3272 (Loc
, Base_Type
(U_Type
), Decl
, Pname
);
3275 -- Suppress checks, uninitialized or otherwise invalid
3276 -- data does not cause constraint errors to be raised for
3277 -- a complete record read.
3279 Insert_Action
(N
, Decl
, All_Checks
);
3283 Rewrite_Stream_Proc_Call
(Pname
);
3290 -- Transforms 'Remainder into a call to the floating-point attribute
3291 -- function Remainder in Fat_xxx (where xxx is the root type)
3293 when Attribute_Remainder
=>
3294 Expand_Fpt_Attribute_RR
(N
);
3300 -- The handling of the Round attribute is quite delicate. The processing
3301 -- in Sem_Attr introduced a conversion to universal real, reflecting the
3302 -- semantics of Round, but we do not want anything to do with universal
3303 -- real at runtime, since this corresponds to using floating-point
3306 -- What we have now is that the Etype of the Round attribute correctly
3307 -- indicates the final result type. The operand of the Round is the
3308 -- conversion to universal real, described above, and the operand of
3309 -- this conversion is the actual operand of Round, which may be the
3310 -- special case of a fixed point multiplication or division (Etype =
3313 -- The exapander will expand first the operand of the conversion, then
3314 -- the conversion, and finally the round attribute itself, since we
3315 -- always work inside out. But we cannot simply process naively in this
3316 -- order. In the semantic world where universal fixed and real really
3317 -- exist and have infinite precision, there is no problem, but in the
3318 -- implementation world, where universal real is a floating-point type,
3319 -- we would get the wrong result.
3321 -- So the approach is as follows. First, when expanding a multiply or
3322 -- divide whose type is universal fixed, we do nothing at all, instead
3323 -- deferring the operation till later.
3325 -- The actual processing is done in Expand_N_Type_Conversion which
3326 -- handles the special case of Round by looking at its parent to see if
3327 -- it is a Round attribute, and if it is, handling the conversion (or
3328 -- its fixed multiply/divide child) in an appropriate manner.
3330 -- This means that by the time we get to expanding the Round attribute
3331 -- itself, the Round is nothing more than a type conversion (and will
3332 -- often be a null type conversion), so we just replace it with the
3333 -- appropriate conversion operation.
3335 when Attribute_Round
=>
3337 Convert_To
(Etype
(N
), Relocate_Node
(First
(Exprs
))));
3338 Analyze_And_Resolve
(N
);
3344 -- Transforms 'Rounding into a call to the floating-point attribute
3345 -- function Rounding in Fat_xxx (where xxx is the root type)
3347 when Attribute_Rounding
=>
3348 Expand_Fpt_Attribute_R
(N
);
3354 -- Transforms 'Scaling into a call to the floating-point attribute
3355 -- function Scaling in Fat_xxx (where xxx is the root type)
3357 when Attribute_Scaling
=>
3358 Expand_Fpt_Attribute_RI
(N
);
3364 when Attribute_Size |
3365 Attribute_Object_Size |
3366 Attribute_Value_Size |
3367 Attribute_VADS_Size
=> Size
:
3370 Ptyp
: constant Entity_Id
:= Etype
(Pref
);
3375 -- Processing for VADS_Size case. Note that this processing removes
3376 -- all traces of VADS_Size from the tree, and completes all required
3377 -- processing for VADS_Size by translating the attribute reference
3378 -- to an appropriate Size or Object_Size reference.
3380 if Id
= Attribute_VADS_Size
3381 or else (Use_VADS_Size
and then Id
= Attribute_Size
)
3383 -- If the size is specified, then we simply use the specified
3384 -- size. This applies to both types and objects. The size of an
3385 -- object can be specified in the following ways:
3387 -- An explicit size object is given for an object
3388 -- A component size is specified for an indexed component
3389 -- A component clause is specified for a selected component
3390 -- The object is a component of a packed composite object
3392 -- If the size is specified, then VADS_Size of an object
3394 if (Is_Entity_Name
(Pref
)
3395 and then Present
(Size_Clause
(Entity
(Pref
))))
3397 (Nkind
(Pref
) = N_Component_Clause
3398 and then (Present
(Component_Clause
3399 (Entity
(Selector_Name
(Pref
))))
3400 or else Is_Packed
(Etype
(Prefix
(Pref
)))))
3402 (Nkind
(Pref
) = N_Indexed_Component
3403 and then (Component_Size
(Etype
(Prefix
(Pref
))) /= 0
3404 or else Is_Packed
(Etype
(Prefix
(Pref
)))))
3406 Set_Attribute_Name
(N
, Name_Size
);
3408 -- Otherwise if we have an object rather than a type, then the
3409 -- VADS_Size attribute applies to the type of the object, rather
3410 -- than the object itself. This is one of the respects in which
3411 -- VADS_Size differs from Size.
3414 if (not Is_Entity_Name
(Pref
)
3415 or else not Is_Type
(Entity
(Pref
)))
3416 and then (Is_Scalar_Type
(Etype
(Pref
))
3417 or else Is_Constrained
(Etype
(Pref
)))
3419 Rewrite
(Pref
, New_Occurrence_Of
(Etype
(Pref
), Loc
));
3422 -- For a scalar type for which no size was explicitly given,
3423 -- VADS_Size means Object_Size. This is the other respect in
3424 -- which VADS_Size differs from Size.
3426 if Is_Scalar_Type
(Etype
(Pref
))
3427 and then No
(Size_Clause
(Etype
(Pref
)))
3429 Set_Attribute_Name
(N
, Name_Object_Size
);
3431 -- In all other cases, Size and VADS_Size are the sane
3434 Set_Attribute_Name
(N
, Name_Size
);
3439 -- For class-wide types, X'Class'Size is transformed into a
3440 -- direct reference to the Size of the class type, so that gigi
3441 -- does not have to deal with the X'Class'Size reference.
3443 if Is_Entity_Name
(Pref
)
3444 and then Is_Class_Wide_Type
(Entity
(Pref
))
3446 Rewrite
(Prefix
(N
), New_Occurrence_Of
(Entity
(Pref
), Loc
));
3449 -- For X'Size applied to an object of a class-wide type, transform
3450 -- X'Size into a call to the primitive operation _Size applied to X.
3452 elsif Is_Class_Wide_Type
(Ptyp
) then
3454 Make_Function_Call
(Loc
,
3455 Name
=> New_Reference_To
3456 (Find_Prim_Op
(Ptyp
, Name_uSize
), Loc
),
3457 Parameter_Associations
=> New_List
(Pref
));
3459 if Typ
/= Standard_Long_Long_Integer
then
3461 -- The context is a specific integer type with which the
3462 -- original attribute was compatible. The function has a
3463 -- specific type as well, so to preserve the compatibility
3464 -- we must convert explicitly.
3466 New_Node
:= Convert_To
(Typ
, New_Node
);
3469 Rewrite
(N
, New_Node
);
3470 Analyze_And_Resolve
(N
, Typ
);
3473 -- For an array component, we can do Size in the front end
3474 -- if the component_size of the array is set.
3476 elsif Nkind
(Pref
) = N_Indexed_Component
then
3477 Siz
:= Component_Size
(Etype
(Prefix
(Pref
)));
3479 -- For a record component, we can do Size in the front end if there
3480 -- is a component clause, or if the record is packed and the
3481 -- component's size is known at compile time.
3483 elsif Nkind
(Pref
) = N_Selected_Component
then
3485 Rec
: constant Entity_Id
:= Etype
(Prefix
(Pref
));
3486 Comp
: constant Entity_Id
:= Entity
(Selector_Name
(Pref
));
3489 if Present
(Component_Clause
(Comp
)) then
3490 Siz
:= Esize
(Comp
);
3492 elsif Is_Packed
(Rec
) then
3493 Siz
:= RM_Size
(Ptyp
);
3496 Apply_Universal_Integer_Attribute_Checks
(N
);
3501 -- All other cases are handled by Gigi
3504 Apply_Universal_Integer_Attribute_Checks
(N
);
3506 -- If Size is applied to a formal parameter that is of a packed
3507 -- array subtype, then apply Size to the actual subtype.
3509 if Is_Entity_Name
(Pref
)
3510 and then Is_Formal
(Entity
(Pref
))
3511 and then Is_Array_Type
(Etype
(Pref
))
3512 and then Is_Packed
(Etype
(Pref
))
3515 Make_Attribute_Reference
(Loc
,
3517 New_Occurrence_Of
(Get_Actual_Subtype
(Pref
), Loc
),
3518 Attribute_Name
=> Name_Size
));
3519 Analyze_And_Resolve
(N
, Typ
);
3522 -- If Size is applied to a dereference of an access to
3523 -- unconstrained packed array, GIGI needs to see its
3524 -- unconstrained nominal type, but also a hint to the actual
3525 -- constrained type.
3527 if Nkind
(Pref
) = N_Explicit_Dereference
3528 and then Is_Array_Type
(Etype
(Pref
))
3529 and then not Is_Constrained
(Etype
(Pref
))
3530 and then Is_Packed
(Etype
(Pref
))
3532 Set_Actual_Designated_Subtype
(Pref
,
3533 Get_Actual_Subtype
(Pref
));
3539 -- Common processing for record and array component case
3542 Rewrite
(N
, Make_Integer_Literal
(Loc
, Siz
));
3544 Analyze_And_Resolve
(N
, Typ
);
3546 -- The result is not a static expression
3548 Set_Is_Static_Expression
(N
, False);
3556 when Attribute_Storage_Pool
=>
3558 Make_Type_Conversion
(Loc
,
3559 Subtype_Mark
=> New_Reference_To
(Etype
(N
), Loc
),
3560 Expression
=> New_Reference_To
(Entity
(N
), Loc
)));
3561 Analyze_And_Resolve
(N
, Typ
);
3567 when Attribute_Storage_Size
=> Storage_Size
:
3569 Ptyp
: constant Entity_Id
:= Etype
(Pref
);
3572 -- Access type case, always go to the root type
3574 -- The case of access types results in a value of zero for the case
3575 -- where no storage size attribute clause has been given. If a
3576 -- storage size has been given, then the attribute is converted
3577 -- to a reference to the variable used to hold this value.
3579 if Is_Access_Type
(Ptyp
) then
3580 if Present
(Storage_Size_Variable
(Root_Type
(Ptyp
))) then
3582 Make_Attribute_Reference
(Loc
,
3583 Prefix
=> New_Reference_To
(Typ
, Loc
),
3584 Attribute_Name
=> Name_Max
,
3585 Expressions
=> New_List
(
3586 Make_Integer_Literal
(Loc
, 0),
3589 (Storage_Size_Variable
(Root_Type
(Ptyp
)), Loc
)))));
3591 elsif Present
(Associated_Storage_Pool
(Root_Type
(Ptyp
))) then
3594 Make_Function_Call
(Loc
,
3598 (Etype
(Associated_Storage_Pool
(Root_Type
(Ptyp
))),
3599 Attribute_Name
(N
)),
3602 Parameter_Associations
=> New_List
(
3604 (Associated_Storage_Pool
(Root_Type
(Ptyp
)), Loc
)))));
3607 Rewrite
(N
, Make_Integer_Literal
(Loc
, 0));
3610 Analyze_And_Resolve
(N
, Typ
);
3612 -- For tasks, we retrieve the size directly from the TCB. The
3613 -- size may depend on a discriminant of the type, and therefore
3614 -- can be a per-object expression, so type-level information is
3615 -- not sufficient in general. There are four cases to consider:
3617 -- a) If the attribute appears within a task body, the designated
3618 -- TCB is obtained by a call to Self.
3620 -- b) If the prefix of the attribute is the name of a task object,
3621 -- the designated TCB is the one stored in the corresponding record.
3623 -- c) If the prefix is a task type, the size is obtained from the
3624 -- size variable created for each task type
3626 -- d) If no storage_size was specified for the type , there is no
3627 -- size variable, and the value is a system-specific default.
3630 if In_Open_Scopes
(Ptyp
) then
3632 -- Storage_Size (Self)
3636 Make_Function_Call
(Loc
,
3638 New_Occurrence_Of
(RTE
(RE_Storage_Size
), Loc
),
3639 Parameter_Associations
=>
3641 Make_Function_Call
(Loc
,
3643 New_Reference_To
(RTE
(RE_Self
), Loc
))))));
3645 elsif not Is_Entity_Name
(Pref
)
3646 or else not Is_Type
(Entity
(Pref
))
3648 -- Storage_Size (Rec (Obj).Size)
3652 Make_Function_Call
(Loc
,
3654 New_Occurrence_Of
(RTE
(RE_Storage_Size
), Loc
),
3655 Parameter_Associations
=>
3657 Make_Selected_Component
(Loc
,
3659 Unchecked_Convert_To
(
3660 Corresponding_Record_Type
(Ptyp
),
3661 New_Copy_Tree
(Pref
)),
3663 Make_Identifier
(Loc
, Name_uTask_Id
))))));
3665 elsif Present
(Storage_Size_Variable
(Ptyp
)) then
3667 -- Static storage size pragma given for type: retrieve value
3668 -- from its allocated storage variable.
3672 Make_Function_Call
(Loc
,
3673 Name
=> New_Occurrence_Of
(
3674 RTE
(RE_Adjust_Storage_Size
), Loc
),
3675 Parameter_Associations
=>
3678 Storage_Size_Variable
(Ptyp
), Loc
)))));
3680 -- Get system default
3684 Make_Function_Call
(Loc
,
3687 RTE
(RE_Default_Stack_Size
), Loc
))));
3690 Analyze_And_Resolve
(N
, Typ
);
3698 when Attribute_Stream_Size
=> Stream_Size
: declare
3699 Ptyp
: constant Entity_Id
:= Etype
(Pref
);
3703 -- If we have a Stream_Size clause for this type use it, otherwise
3704 -- the Stream_Size if the size of the type.
3706 if Has_Stream_Size_Clause
(Ptyp
) then
3709 (Static_Integer
(Expression
(Stream_Size_Clause
(Ptyp
))));
3711 Size
:= UI_To_Int
(Esize
(Ptyp
));
3714 Rewrite
(N
, Make_Integer_Literal
(Loc
, Intval
=> Size
));
3715 Analyze_And_Resolve
(N
, Typ
);
3722 -- 1. Deal with enumeration types with holes
3723 -- 2. For floating-point, generate call to attribute function
3724 -- 3. For other cases, deal with constraint checking
3726 when Attribute_Succ
=> Succ
:
3728 Ptyp
: constant Entity_Id
:= Base_Type
(Etype
(Pref
));
3731 -- For enumeration types with non-standard representations, we
3732 -- expand typ'Succ (x) into
3734 -- Pos_To_Rep (Rep_To_Pos (x) + 1)
3736 -- If the representation is contiguous, we compute instead
3737 -- Lit1 + Rep_to_Pos (x+1), to catch invalid representations.
3739 if Is_Enumeration_Type
(Ptyp
)
3740 and then Present
(Enum_Pos_To_Rep
(Ptyp
))
3742 if Has_Contiguous_Rep
(Ptyp
) then
3744 Unchecked_Convert_To
(Ptyp
,
3747 Make_Integer_Literal
(Loc
,
3748 Enumeration_Rep
(First_Literal
(Ptyp
))),
3750 Make_Function_Call
(Loc
,
3753 (TSS
(Ptyp
, TSS_Rep_To_Pos
), Loc
),
3755 Parameter_Associations
=>
3757 Unchecked_Convert_To
(Ptyp
,
3760 Unchecked_Convert_To
(Standard_Integer
,
3761 Relocate_Node
(First
(Exprs
))),
3763 Make_Integer_Literal
(Loc
, 1))),
3764 Rep_To_Pos_Flag
(Ptyp
, Loc
))))));
3766 -- Add Boolean parameter True, to request program errror if
3767 -- we have a bad representation on our hands. Add False if
3768 -- checks are suppressed.
3770 Append_To
(Exprs
, Rep_To_Pos_Flag
(Ptyp
, Loc
));
3772 Make_Indexed_Component
(Loc
,
3773 Prefix
=> New_Reference_To
(Enum_Pos_To_Rep
(Ptyp
), Loc
),
3774 Expressions
=> New_List
(
3777 Make_Function_Call
(Loc
,
3780 (TSS
(Ptyp
, TSS_Rep_To_Pos
), Loc
),
3781 Parameter_Associations
=> Exprs
),
3782 Right_Opnd
=> Make_Integer_Literal
(Loc
, 1)))));
3785 Analyze_And_Resolve
(N
, Typ
);
3787 -- For floating-point, we transform 'Succ into a call to the Succ
3788 -- floating-point attribute function in Fat_xxx (xxx is root type)
3790 elsif Is_Floating_Point_Type
(Ptyp
) then
3791 Expand_Fpt_Attribute_R
(N
);
3792 Analyze_And_Resolve
(N
, Typ
);
3794 -- For modular types, nothing to do (no overflow, since wraps)
3796 elsif Is_Modular_Integer_Type
(Ptyp
) then
3799 -- For other types, if range checking is enabled, we must generate
3800 -- a check if overflow checking is enabled.
3802 elsif not Overflow_Checks_Suppressed
(Ptyp
) then
3803 Expand_Pred_Succ
(N
);
3811 -- Transforms X'Tag into a direct reference to the tag of X
3813 when Attribute_Tag
=> Tag
:
3816 Prefix_Is_Type
: Boolean;
3819 if Is_Entity_Name
(Pref
) and then Is_Type
(Entity
(Pref
)) then
3820 Ttyp
:= Entity
(Pref
);
3821 Prefix_Is_Type
:= True;
3823 Ttyp
:= Etype
(Pref
);
3824 Prefix_Is_Type
:= False;
3827 if Is_Class_Wide_Type
(Ttyp
) then
3828 Ttyp
:= Root_Type
(Ttyp
);
3831 Ttyp
:= Underlying_Type
(Ttyp
);
3833 if Prefix_Is_Type
then
3835 -- For JGNAT we leave the type attribute unexpanded because
3836 -- there's not a dispatching table to reference.
3840 Unchecked_Convert_To
(RTE
(RE_Tag
),
3842 (Node
(First_Elmt
(Access_Disp_Table
(Ttyp
))), Loc
)));
3843 Analyze_And_Resolve
(N
, RTE
(RE_Tag
));
3848 Make_Selected_Component
(Loc
,
3849 Prefix
=> Relocate_Node
(Pref
),
3851 New_Reference_To
(First_Tag_Component
(Ttyp
), Loc
)));
3852 Analyze_And_Resolve
(N
, RTE
(RE_Tag
));
3860 -- Transforms 'Terminated attribute into a call to Terminated function
3862 when Attribute_Terminated
=> Terminated
:
3864 -- The prefix of Terminated is of a task interface class-wide type.
3867 -- terminated (Pref._disp_get_task_id);
3869 if Ada_Version
>= Ada_05
3870 and then Ekind
(Etype
(Pref
)) = E_Class_Wide_Type
3871 and then Is_Interface
(Etype
(Pref
))
3872 and then Is_Task_Interface
(Etype
(Pref
))
3875 Make_Function_Call
(Loc
,
3877 New_Reference_To
(RTE
(RE_Terminated
), Loc
),
3878 Parameter_Associations
=> New_List
(
3879 Make_Selected_Component
(Loc
,
3881 New_Copy_Tree
(Pref
),
3883 Make_Identifier
(Loc
, Name_uDisp_Get_Task_Id
)))));
3885 elsif Restricted_Profile
then
3887 Build_Call_With_Task
(Pref
, RTE
(RE_Restricted_Terminated
)));
3891 Build_Call_With_Task
(Pref
, RTE
(RE_Terminated
)));
3894 Analyze_And_Resolve
(N
, Standard_Boolean
);
3901 -- Transforms System'To_Address (X) into unchecked conversion
3902 -- from (integral) type of X to type address.
3904 when Attribute_To_Address
=>
3906 Unchecked_Convert_To
(RTE
(RE_Address
),
3907 Relocate_Node
(First
(Exprs
))));
3908 Analyze_And_Resolve
(N
, RTE
(RE_Address
));
3914 -- Transforms 'Truncation into a call to the floating-point attribute
3915 -- function Truncation in Fat_xxx (where xxx is the root type)
3917 when Attribute_Truncation
=>
3918 Expand_Fpt_Attribute_R
(N
);
3920 -----------------------
3921 -- Unbiased_Rounding --
3922 -----------------------
3924 -- Transforms 'Unbiased_Rounding into a call to the floating-point
3925 -- attribute function Unbiased_Rounding in Fat_xxx (where xxx is the
3928 when Attribute_Unbiased_Rounding
=>
3929 Expand_Fpt_Attribute_R
(N
);
3931 ----------------------
3932 -- Unchecked_Access --
3933 ----------------------
3935 when Attribute_Unchecked_Access
=>
3937 -- Ada 2005 (AI-251): If the designated type is an interface, then
3938 -- rewrite the referenced object as a conversion to force the
3939 -- displacement of the pointer to the secondary dispatch table.
3941 if Is_Interface
(Directly_Designated_Type
(Btyp
)) then
3943 Ref_Object
: constant Node_Id
:= Get_Referenced_Object
(Pref
);
3944 Conversion
: Node_Id
;
3946 Conversion
:= Convert_To
(Typ
, New_Copy_Tree
(Ref_Object
));
3947 Rewrite
(N
, Conversion
);
3948 Analyze_And_Resolve
(N
, Typ
);
3951 -- Otherwise this is like normal Access without a check
3954 Expand_Access_To_Type
(N
);
3961 when Attribute_UET_Address
=> UET_Address
: declare
3962 Ent
: constant Entity_Id
:=
3963 Make_Defining_Identifier
(Loc
, New_Internal_Name
('T'));
3967 Make_Object_Declaration
(Loc
,
3968 Defining_Identifier
=> Ent
,
3969 Aliased_Present
=> True,
3970 Object_Definition
=>
3971 New_Occurrence_Of
(RTE
(RE_Address
), Loc
)));
3973 -- Construct name __gnat_xxx__SDP, where xxx is the unit name
3974 -- in normal external form.
3976 Get_External_Unit_Name_String
(Get_Unit_Name
(Pref
));
3977 Name_Buffer
(1 + 7 .. Name_Len
+ 7) := Name_Buffer
(1 .. Name_Len
);
3978 Name_Len
:= Name_Len
+ 7;
3979 Name_Buffer
(1 .. 7) := "__gnat_";
3980 Name_Buffer
(Name_Len
+ 1 .. Name_Len
+ 5) := "__SDP";
3981 Name_Len
:= Name_Len
+ 5;
3983 Set_Is_Imported
(Ent
);
3984 Set_Interface_Name
(Ent
,
3985 Make_String_Literal
(Loc
,
3986 Strval
=> String_From_Name_Buffer
));
3989 Make_Attribute_Reference
(Loc
,
3990 Prefix
=> New_Occurrence_Of
(Ent
, Loc
),
3991 Attribute_Name
=> Name_Address
));
3993 Analyze_And_Resolve
(N
, Typ
);
3996 -------------------------
3997 -- Unrestricted_Access --
3998 -------------------------
4000 when Attribute_Unrestricted_Access
=>
4002 if Ekind
(Btyp
) = E_Access_Protected_Subprogram_Type
then
4003 Expand_Access_To_Protected_Op
(N
, Pref
, Typ
);
4005 -- Ada 2005 (AI-251): If the designated type is an interface, then
4006 -- rewrite the referenced object as a conversion to force the
4007 -- displacement of the pointer to the secondary dispatch table.
4009 elsif Is_Interface
(Directly_Designated_Type
(Btyp
)) then
4011 Ref_Object
: constant Node_Id
:= Get_Referenced_Object
(Pref
);
4012 Conversion
: Node_Id
;
4014 Conversion
:= Convert_To
(Typ
, New_Copy_Tree
(Ref_Object
));
4015 Rewrite
(N
, Conversion
);
4016 Analyze_And_Resolve
(N
, Typ
);
4019 -- Otherwise this is like Access without a check
4022 Expand_Access_To_Type
(N
);
4029 -- The processing for VADS_Size is shared with Size
4035 -- For enumeration types with a standard representation, and for all
4036 -- other types, Val is handled by Gigi. For enumeration types with
4037 -- a non-standard representation we use the _Pos_To_Rep array that
4038 -- was created when the type was frozen.
4040 when Attribute_Val
=> Val
:
4042 Etyp
: constant Entity_Id
:= Base_Type
(Entity
(Pref
));
4045 if Is_Enumeration_Type
(Etyp
)
4046 and then Present
(Enum_Pos_To_Rep
(Etyp
))
4048 if Has_Contiguous_Rep
(Etyp
) then
4050 Rep_Node
: constant Node_Id
:=
4051 Unchecked_Convert_To
(Etyp
,
4054 Make_Integer_Literal
(Loc
,
4055 Enumeration_Rep
(First_Literal
(Etyp
))),
4057 (Convert_To
(Standard_Integer
,
4058 Relocate_Node
(First
(Exprs
))))));
4062 Unchecked_Convert_To
(Etyp
,
4065 Make_Integer_Literal
(Loc
,
4066 Enumeration_Rep
(First_Literal
(Etyp
))),
4068 Make_Function_Call
(Loc
,
4071 (TSS
(Etyp
, TSS_Rep_To_Pos
), Loc
),
4072 Parameter_Associations
=> New_List
(
4074 Rep_To_Pos_Flag
(Etyp
, Loc
))))));
4079 Make_Indexed_Component
(Loc
,
4080 Prefix
=> New_Reference_To
(Enum_Pos_To_Rep
(Etyp
), Loc
),
4081 Expressions
=> New_List
(
4082 Convert_To
(Standard_Integer
,
4083 Relocate_Node
(First
(Exprs
))))));
4086 Analyze_And_Resolve
(N
, Typ
);
4094 -- The code for valid is dependent on the particular types involved.
4095 -- See separate sections below for the generated code in each case.
4097 when Attribute_Valid
=> Valid
:
4099 Ptyp
: constant Entity_Id
:= Etype
(Pref
);
4100 Btyp
: Entity_Id
:= Base_Type
(Ptyp
);
4103 Save_Validity_Checks_On
: constant Boolean := Validity_Checks_On
;
4104 -- Save the validity checking mode. We always turn off validity
4105 -- checking during process of 'Valid since this is one place
4106 -- where we do not want the implicit validity checks to intefere
4107 -- with the explicit validity check that the programmer is doing.
4109 function Make_Range_Test
return Node_Id
;
4110 -- Build the code for a range test of the form
4111 -- Btyp!(Pref) >= Btyp!(Ptyp'First)
4113 -- Btyp!(Pref) <= Btyp!(Ptyp'Last)
4115 ---------------------
4116 -- Make_Range_Test --
4117 ---------------------
4119 function Make_Range_Test
return Node_Id
is
4126 Unchecked_Convert_To
(Btyp
, Duplicate_Subexpr
(Pref
)),
4129 Unchecked_Convert_To
(Btyp
,
4130 Make_Attribute_Reference
(Loc
,
4131 Prefix
=> New_Occurrence_Of
(Ptyp
, Loc
),
4132 Attribute_Name
=> Name_First
))),
4137 Unchecked_Convert_To
(Btyp
,
4138 Duplicate_Subexpr_No_Checks
(Pref
)),
4141 Unchecked_Convert_To
(Btyp
,
4142 Make_Attribute_Reference
(Loc
,
4143 Prefix
=> New_Occurrence_Of
(Ptyp
, Loc
),
4144 Attribute_Name
=> Name_Last
))));
4145 end Make_Range_Test
;
4147 -- Start of processing for Attribute_Valid
4150 -- Turn off validity checks. We do not want any implicit validity
4151 -- checks to intefere with the explicit check from the attribute
4153 Validity_Checks_On
:= False;
4155 -- Floating-point case. This case is handled by the Valid attribute
4156 -- code in the floating-point attribute run-time library.
4158 if Is_Floating_Point_Type
(Ptyp
) then
4164 -- For vax fpt types, call appropriate routine in special vax
4165 -- floating point unit. We do not have to worry about loads in
4166 -- this case, since these types have no signalling NaN's.
4168 if Vax_Float
(Btyp
) then
4169 Expand_Vax_Valid
(N
);
4171 -- The AAMP back end handles Valid for floating-point types
4173 elsif Is_AAMP_Float
(Btyp
) then
4174 Analyze_And_Resolve
(Pref
, Ptyp
);
4175 Set_Etype
(N
, Standard_Boolean
);
4178 -- Non VAX float case
4181 Find_Fat_Info
(Etype
(Pref
), Ftp
, Pkg
);
4183 -- If the floating-point object might be unaligned, we need
4184 -- to call the special routine Unaligned_Valid, which makes
4185 -- the needed copy, being careful not to load the value into
4186 -- any floating-point register. The argument in this case is
4187 -- obj'Address (see Unchecked_Valid routine in Fat_Gen).
4189 if Is_Possibly_Unaligned_Object
(Pref
) then
4190 Set_Attribute_Name
(N
, Name_Unaligned_Valid
);
4191 Expand_Fpt_Attribute
4192 (N
, Pkg
, Name_Unaligned_Valid
,
4194 Make_Attribute_Reference
(Loc
,
4195 Prefix
=> Relocate_Node
(Pref
),
4196 Attribute_Name
=> Name_Address
)));
4198 -- In the normal case where we are sure the object is
4199 -- aligned, we generate a call to Valid, and the argument in
4200 -- this case is obj'Unrestricted_Access (after converting
4201 -- obj to the right floating-point type).
4204 Expand_Fpt_Attribute
4205 (N
, Pkg
, Name_Valid
,
4207 Make_Attribute_Reference
(Loc
,
4208 Prefix
=> Unchecked_Convert_To
(Ftp
, Pref
),
4209 Attribute_Name
=> Name_Unrestricted_Access
)));
4213 -- One more task, we still need a range check. Required
4214 -- only if we have a constraint, since the Valid routine
4215 -- catches infinities properly (infinities are never valid).
4217 -- The way we do the range check is simply to create the
4218 -- expression: Valid (N) and then Base_Type(Pref) in Typ.
4220 if not Subtypes_Statically_Match
(Ptyp
, Btyp
) then
4223 Left_Opnd
=> Relocate_Node
(N
),
4226 Left_Opnd
=> Convert_To
(Btyp
, Pref
),
4227 Right_Opnd
=> New_Occurrence_Of
(Ptyp
, Loc
))));
4231 -- Enumeration type with holes
4233 -- For enumeration types with holes, the Pos value constructed by
4234 -- the Enum_Rep_To_Pos function built in Exp_Ch3 called with a
4235 -- second argument of False returns minus one for an invalid value,
4236 -- and the non-negative pos value for a valid value, so the
4237 -- expansion of X'Valid is simply:
4239 -- type(X)'Pos (X) >= 0
4241 -- We can't quite generate it that way because of the requirement
4242 -- for the non-standard second argument of False in the resulting
4243 -- rep_to_pos call, so we have to explicitly create:
4245 -- _rep_to_pos (X, False) >= 0
4247 -- If we have an enumeration subtype, we also check that the
4248 -- value is in range:
4250 -- _rep_to_pos (X, False) >= 0
4252 -- (X >= type(X)'First and then type(X)'Last <= X)
4254 elsif Is_Enumeration_Type
(Ptyp
)
4255 and then Present
(Enum_Pos_To_Rep
(Base_Type
(Ptyp
)))
4260 Make_Function_Call
(Loc
,
4263 (TSS
(Base_Type
(Ptyp
), TSS_Rep_To_Pos
), Loc
),
4264 Parameter_Associations
=> New_List
(
4266 New_Occurrence_Of
(Standard_False
, Loc
))),
4267 Right_Opnd
=> Make_Integer_Literal
(Loc
, 0));
4271 (Type_Low_Bound
(Ptyp
) /= Type_Low_Bound
(Btyp
)
4273 Type_High_Bound
(Ptyp
) /= Type_High_Bound
(Btyp
))
4275 -- The call to Make_Range_Test will create declarations
4276 -- that need a proper insertion point, but Pref is now
4277 -- attached to a node with no ancestor. Attach to tree
4278 -- even if it is to be rewritten below.
4280 Set_Parent
(Tst
, Parent
(N
));
4284 Left_Opnd
=> Make_Range_Test
,
4290 -- Fortran convention booleans
4292 -- For the very special case of Fortran convention booleans, the
4293 -- value is always valid, since it is an integer with the semantics
4294 -- that non-zero is true, and any value is permissible.
4296 elsif Is_Boolean_Type
(Ptyp
)
4297 and then Convention
(Ptyp
) = Convention_Fortran
4299 Rewrite
(N
, New_Occurrence_Of
(Standard_True
, Loc
));
4301 -- For biased representations, we will be doing an unchecked
4302 -- conversion without unbiasing the result. That means that the range
4303 -- test has to take this into account, and the proper form of the
4306 -- Btyp!(Pref) < Btyp!(Ptyp'Range_Length)
4308 elsif Has_Biased_Representation
(Ptyp
) then
4309 Btyp
:= RTE
(RE_Unsigned_32
);
4313 Unchecked_Convert_To
(Btyp
, Duplicate_Subexpr
(Pref
)),
4315 Unchecked_Convert_To
(Btyp
,
4316 Make_Attribute_Reference
(Loc
,
4317 Prefix
=> New_Occurrence_Of
(Ptyp
, Loc
),
4318 Attribute_Name
=> Name_Range_Length
))));
4320 -- For all other scalar types, what we want logically is a
4323 -- X in type(X)'First .. type(X)'Last
4325 -- But that's precisely what won't work because of possible
4326 -- unwanted optimization (and indeed the basic motivation for
4327 -- the Valid attribute is exactly that this test does not work!)
4328 -- What will work is:
4330 -- Btyp!(X) >= Btyp!(type(X)'First)
4332 -- Btyp!(X) <= Btyp!(type(X)'Last)
4334 -- where Btyp is an integer type large enough to cover the full
4335 -- range of possible stored values (i.e. it is chosen on the basis
4336 -- of the size of the type, not the range of the values). We write
4337 -- this as two tests, rather than a range check, so that static
4338 -- evaluation will easily remove either or both of the checks if
4339 -- they can be -statically determined to be true (this happens
4340 -- when the type of X is static and the range extends to the full
4341 -- range of stored values).
4343 -- Unsigned types. Note: it is safe to consider only whether the
4344 -- subtype is unsigned, since we will in that case be doing all
4345 -- unsigned comparisons based on the subtype range. Since we use the
4346 -- actual subtype object size, this is appropriate.
4348 -- For example, if we have
4350 -- subtype x is integer range 1 .. 200;
4351 -- for x'Object_Size use 8;
4353 -- Now the base type is signed, but objects of this type are bits
4354 -- unsigned, and doing an unsigned test of the range 1 to 200 is
4355 -- correct, even though a value greater than 127 looks signed to a
4356 -- signed comparison.
4358 elsif Is_Unsigned_Type
(Ptyp
) then
4359 if Esize
(Ptyp
) <= 32 then
4360 Btyp
:= RTE
(RE_Unsigned_32
);
4362 Btyp
:= RTE
(RE_Unsigned_64
);
4365 Rewrite
(N
, Make_Range_Test
);
4370 if Esize
(Ptyp
) <= Esize
(Standard_Integer
) then
4371 Btyp
:= Standard_Integer
;
4373 Btyp
:= Universal_Integer
;
4376 Rewrite
(N
, Make_Range_Test
);
4379 Analyze_And_Resolve
(N
, Standard_Boolean
);
4380 Validity_Checks_On
:= Save_Validity_Checks_On
;
4387 -- Value attribute is handled in separate unti Exp_Imgv
4389 when Attribute_Value
=>
4390 Exp_Imgv
.Expand_Value_Attribute
(N
);
4396 -- The processing for Value_Size shares the processing for Size
4402 -- The processing for Version shares the processing for Body_Version
4408 -- We expand typ'Wide_Image (X) into
4410 -- String_To_Wide_String
4411 -- (typ'Image (X), Wide_Character_Encoding_Method)
4413 -- This works in all cases because String_To_Wide_String converts any
4414 -- wide character escape sequences resulting from the Image call to the
4415 -- proper Wide_Character equivalent
4417 -- not quite right for typ = Wide_Character ???
4419 when Attribute_Wide_Image
=> Wide_Image
:
4422 Make_Function_Call
(Loc
,
4423 Name
=> New_Reference_To
(RTE
(RE_String_To_Wide_String
), Loc
),
4424 Parameter_Associations
=> New_List
(
4425 Make_Attribute_Reference
(Loc
,
4427 Attribute_Name
=> Name_Image
,
4428 Expressions
=> Exprs
),
4430 Make_Integer_Literal
(Loc
,
4431 Intval
=> Int
(Wide_Character_Encoding_Method
)))));
4433 Analyze_And_Resolve
(N
, Standard_Wide_String
);
4436 ---------------------
4437 -- Wide_Wide_Image --
4438 ---------------------
4440 -- We expand typ'Wide_Wide_Image (X) into
4442 -- String_To_Wide_Wide_String
4443 -- (typ'Image (X), Wide_Character_Encoding_Method)
4445 -- This works in all cases because String_To_Wide_Wide_String converts
4446 -- any wide character escape sequences resulting from the Image call to
4447 -- the proper Wide_Character equivalent
4449 -- not quite right for typ = Wide_Wide_Character ???
4451 when Attribute_Wide_Wide_Image
=> Wide_Wide_Image
:
4454 Make_Function_Call
(Loc
,
4455 Name
=> New_Reference_To
4456 (RTE
(RE_String_To_Wide_Wide_String
), Loc
),
4457 Parameter_Associations
=> New_List
(
4458 Make_Attribute_Reference
(Loc
,
4460 Attribute_Name
=> Name_Image
,
4461 Expressions
=> Exprs
),
4463 Make_Integer_Literal
(Loc
,
4464 Intval
=> Int
(Wide_Character_Encoding_Method
)))));
4466 Analyze_And_Resolve
(N
, Standard_Wide_Wide_String
);
4467 end Wide_Wide_Image
;
4473 -- We expand typ'Wide_Value (X) into
4476 -- (Wide_String_To_String (X, Wide_Character_Encoding_Method))
4478 -- Wide_String_To_String is a runtime function that converts its wide
4479 -- string argument to String, converting any non-translatable characters
4480 -- into appropriate escape sequences. This preserves the required
4481 -- semantics of Wide_Value in all cases, and results in a very simple
4482 -- implementation approach.
4484 -- Note: for this approach to be fully standard compliant for the cases
4485 -- where typ is Wide_Character and Wide_Wide_Character, the encoding
4486 -- method must cover the entire character range (e.g. UTF-8). But that
4487 -- is a reasonable requirement when dealing with encoded character
4488 -- sequences. Presumably if one of the restrictive encoding mechanisms
4489 -- is in use such as Shift-JIS, then characters that cannot be
4490 -- represented using this encoding will not appear in any case.
4492 when Attribute_Wide_Value
=> Wide_Value
:
4495 Make_Attribute_Reference
(Loc
,
4497 Attribute_Name
=> Name_Value
,
4499 Expressions
=> New_List
(
4500 Make_Function_Call
(Loc
,
4502 New_Reference_To
(RTE
(RE_Wide_String_To_String
), Loc
),
4504 Parameter_Associations
=> New_List
(
4505 Relocate_Node
(First
(Exprs
)),
4506 Make_Integer_Literal
(Loc
,
4507 Intval
=> Int
(Wide_Character_Encoding_Method
)))))));
4509 Analyze_And_Resolve
(N
, Typ
);
4512 ---------------------
4513 -- Wide_Wide_Value --
4514 ---------------------
4516 -- We expand typ'Wide_Value_Value (X) into
4519 -- (Wide_Wide_String_To_String (X, Wide_Character_Encoding_Method))
4521 -- Wide_Wide_String_To_String is a runtime function that converts its
4522 -- wide string argument to String, converting any non-translatable
4523 -- characters into appropriate escape sequences. This preserves the
4524 -- required semantics of Wide_Wide_Value in all cases, and results in a
4525 -- very simple implementation approach.
4527 -- It's not quite right where typ = Wide_Wide_Character, because the
4528 -- encoding method may not cover the whole character type ???
4530 when Attribute_Wide_Wide_Value
=> Wide_Wide_Value
:
4533 Make_Attribute_Reference
(Loc
,
4535 Attribute_Name
=> Name_Value
,
4537 Expressions
=> New_List
(
4538 Make_Function_Call
(Loc
,
4540 New_Reference_To
(RTE
(RE_Wide_Wide_String_To_String
), Loc
),
4542 Parameter_Associations
=> New_List
(
4543 Relocate_Node
(First
(Exprs
)),
4544 Make_Integer_Literal
(Loc
,
4545 Intval
=> Int
(Wide_Character_Encoding_Method
)))))));
4547 Analyze_And_Resolve
(N
, Typ
);
4548 end Wide_Wide_Value
;
4550 ---------------------
4551 -- Wide_Wide_Width --
4552 ---------------------
4554 -- Wide_Wide_Width attribute is handled in separate unit Exp_Imgv
4556 when Attribute_Wide_Wide_Width
=>
4557 Exp_Imgv
.Expand_Width_Attribute
(N
, Wide_Wide
);
4563 -- Wide_Width attribute is handled in separate unit Exp_Imgv
4565 when Attribute_Wide_Width
=>
4566 Exp_Imgv
.Expand_Width_Attribute
(N
, Wide
);
4572 -- Width attribute is handled in separate unit Exp_Imgv
4574 when Attribute_Width
=>
4575 Exp_Imgv
.Expand_Width_Attribute
(N
, Normal
);
4581 when Attribute_Write
=> Write
: declare
4582 P_Type
: constant Entity_Id
:= Entity
(Pref
);
4583 U_Type
: constant Entity_Id
:= Underlying_Type
(P_Type
);
4591 -- If no underlying type, we have an error that will be diagnosed
4592 -- elsewhere, so here we just completely ignore the expansion.
4598 -- The simple case, if there is a TSS for Write, just call it
4600 Pname
:= Find_Stream_Subprogram
(P_Type
, TSS_Stream_Write
);
4602 if Present
(Pname
) then
4606 -- If there is a Stream_Convert pragma, use it, we rewrite
4608 -- sourcetyp'Output (stream, Item)
4612 -- strmtyp'Output (Stream, strmwrite (acttyp (Item)));
4614 -- where strmwrite is the given Write function that converts an
4615 -- argument of type sourcetyp or a type acctyp, from which it is
4616 -- derived to type strmtyp. The conversion to acttyp is required
4617 -- for the derived case.
4619 Prag
:= Get_Stream_Convert_Pragma
(P_Type
);
4621 if Present
(Prag
) then
4623 Next
(Next
(First
(Pragma_Argument_Associations
(Prag
))));
4624 Wfunc
:= Entity
(Expression
(Arg3
));
4627 Make_Attribute_Reference
(Loc
,
4628 Prefix
=> New_Occurrence_Of
(Etype
(Wfunc
), Loc
),
4629 Attribute_Name
=> Name_Output
,
4630 Expressions
=> New_List
(
4631 Relocate_Node
(First
(Exprs
)),
4632 Make_Function_Call
(Loc
,
4633 Name
=> New_Occurrence_Of
(Wfunc
, Loc
),
4634 Parameter_Associations
=> New_List
(
4635 Convert_To
(Etype
(First_Formal
(Wfunc
)),
4636 Relocate_Node
(Next
(First
(Exprs
)))))))));
4641 -- For elementary types, we call the W_xxx routine directly
4643 elsif Is_Elementary_Type
(U_Type
) then
4644 Rewrite
(N
, Build_Elementary_Write_Call
(N
));
4650 elsif Is_Array_Type
(U_Type
) then
4651 Build_Array_Write_Procedure
(N
, U_Type
, Decl
, Pname
);
4652 Compile_Stream_Body_In_Scope
(N
, Decl
, U_Type
, Check
=> False);
4654 -- Tagged type case, use the primitive Write function. Note that
4655 -- this will dispatch in the class-wide case which is what we want
4657 elsif Is_Tagged_Type
(U_Type
) then
4658 Pname
:= Find_Prim_Op
(U_Type
, TSS_Stream_Write
);
4660 -- All other record type cases, including protected records.
4661 -- The latter only arise for expander generated code for
4662 -- handling shared passive partition access.
4666 (Is_Record_Type
(U_Type
) or else Is_Protected_Type
(U_Type
));
4668 -- Ada 2005 (AI-216): Program_Error is raised when executing
4669 -- the default implementation of the Write attribute of an
4670 -- Unchecked_Union type.
4672 if Is_Unchecked_Union
(Base_Type
(U_Type
)) then
4674 Make_Raise_Program_Error
(Loc
,
4675 Reason
=> PE_Unchecked_Union_Restriction
));
4678 if Has_Discriminants
(U_Type
)
4680 (Discriminant_Default_Value
(First_Discriminant
(U_Type
)))
4682 Build_Mutable_Record_Write_Procedure
4683 (Loc
, Base_Type
(U_Type
), Decl
, Pname
);
4685 Build_Record_Write_Procedure
4686 (Loc
, Base_Type
(U_Type
), Decl
, Pname
);
4689 Insert_Action
(N
, Decl
);
4693 -- If we fall through, Pname is the procedure to be called
4695 Rewrite_Stream_Proc_Call
(Pname
);
4698 -- Component_Size is handled by Gigi, unless the component size is known
4699 -- at compile time, which is always true in the packed array case. It is
4700 -- important that the packed array case is handled in the front end (see
4701 -- Eval_Attribute) since Gigi would otherwise get confused by the
4702 -- equivalent packed array type.
4704 when Attribute_Component_Size
=>
4707 -- The following attributes are handled by the back end (except that
4708 -- static cases have already been evaluated during semantic processing,
4709 -- but in any case the back end should not count on this). The one bit
4710 -- of special processing required is that these attributes typically
4711 -- generate conditionals in the code, so we need to check the relevant
4714 when Attribute_Max |
4716 Check_Restriction
(No_Implicit_Conditionals
, N
);
4718 -- The following attributes are handled by the back end (except that
4719 -- static cases have already been evaluated during semantic processing,
4720 -- but in any case the back end should not count on this).
4722 -- Gigi also handles the non-class-wide cases of Size
4724 when Attribute_Bit_Order |
4725 Attribute_Code_Address |
4726 Attribute_Definite |
4727 Attribute_Null_Parameter |
4728 Attribute_Passed_By_Reference |
4729 Attribute_Pool_Address
=>
4732 -- The following attributes are also handled by Gigi, but return a
4733 -- universal integer result, so may need a conversion for checking
4734 -- that the result is in range.
4736 when Attribute_Aft |
4738 Attribute_Max_Size_In_Storage_Elements
4740 Apply_Universal_Integer_Attribute_Checks
(N
);
4742 -- The following attributes should not appear at this stage, since they
4743 -- have already been handled by the analyzer (and properly rewritten
4744 -- with corresponding values or entities to represent the right values)
4746 when Attribute_Abort_Signal |
4747 Attribute_Address_Size |
4750 Attribute_Default_Bit_Order |
4756 Attribute_Has_Access_Values |
4757 Attribute_Has_Discriminants |
4759 Attribute_Machine_Emax |
4760 Attribute_Machine_Emin |
4761 Attribute_Machine_Mantissa |
4762 Attribute_Machine_Overflows |
4763 Attribute_Machine_Radix |
4764 Attribute_Machine_Rounds |
4765 Attribute_Maximum_Alignment |
4766 Attribute_Model_Emin |
4767 Attribute_Model_Epsilon |
4768 Attribute_Model_Mantissa |
4769 Attribute_Model_Small |
4771 Attribute_Partition_ID |
4773 Attribute_Safe_Emax |
4774 Attribute_Safe_First |
4775 Attribute_Safe_Large |
4776 Attribute_Safe_Last |
4777 Attribute_Safe_Small |
4779 Attribute_Signed_Zeros |
4781 Attribute_Storage_Unit |
4782 Attribute_Stub_Type |
4783 Attribute_Target_Name |
4784 Attribute_Type_Class |
4785 Attribute_Unconstrained_Array |
4786 Attribute_Universal_Literal_String |
4787 Attribute_Wchar_T_Size |
4788 Attribute_Word_Size
=>
4790 raise Program_Error
;
4792 -- The Asm_Input and Asm_Output attributes are not expanded at this
4793 -- stage, but will be eliminated in the expansion of the Asm call,
4794 -- see Exp_Intr for details. So Gigi will never see these either.
4796 when Attribute_Asm_Input |
4797 Attribute_Asm_Output
=>
4804 when RE_Not_Available
=>
4806 end Expand_N_Attribute_Reference
;
4808 ----------------------
4809 -- Expand_Pred_Succ --
4810 ----------------------
4812 -- For typ'Pred (exp), we generate the check
4814 -- [constraint_error when exp = typ'Base'First]
4816 -- Similarly, for typ'Succ (exp), we generate the check
4818 -- [constraint_error when exp = typ'Base'Last]
4820 -- These checks are not generated for modular types, since the proper
4821 -- semantics for Succ and Pred on modular types is to wrap, not raise CE.
4823 procedure Expand_Pred_Succ
(N
: Node_Id
) is
4824 Loc
: constant Source_Ptr
:= Sloc
(N
);
4828 if Attribute_Name
(N
) = Name_Pred
then
4835 Make_Raise_Constraint_Error
(Loc
,
4839 Duplicate_Subexpr_Move_Checks
(First
(Expressions
(N
))),
4841 Make_Attribute_Reference
(Loc
,
4843 New_Reference_To
(Base_Type
(Etype
(Prefix
(N
))), Loc
),
4844 Attribute_Name
=> Cnam
)),
4845 Reason
=> CE_Overflow_Check_Failed
));
4846 end Expand_Pred_Succ
;
4852 procedure Find_Fat_Info
4854 Fat_Type
: out Entity_Id
;
4855 Fat_Pkg
: out RE_Id
)
4857 Btyp
: constant Entity_Id
:= Base_Type
(T
);
4858 Rtyp
: constant Entity_Id
:= Root_Type
(T
);
4859 Digs
: constant Nat
:= UI_To_Int
(Digits_Value
(Btyp
));
4862 -- If the base type is VAX float, then get appropriate VAX float type
4864 if Vax_Float
(Btyp
) then
4867 Fat_Type
:= RTE
(RE_Fat_VAX_F
);
4868 Fat_Pkg
:= RE_Attr_VAX_F_Float
;
4871 Fat_Type
:= RTE
(RE_Fat_VAX_D
);
4872 Fat_Pkg
:= RE_Attr_VAX_D_Float
;
4875 Fat_Type
:= RTE
(RE_Fat_VAX_G
);
4876 Fat_Pkg
:= RE_Attr_VAX_G_Float
;
4879 raise Program_Error
;
4882 -- If root type is VAX float, this is the case where the library has
4883 -- been recompiled in VAX float mode, and we have an IEEE float type.
4884 -- This is when we use the special IEEE Fat packages.
4886 elsif Vax_Float
(Rtyp
) then
4889 Fat_Type
:= RTE
(RE_Fat_IEEE_Short
);
4890 Fat_Pkg
:= RE_Attr_IEEE_Short
;
4893 Fat_Type
:= RTE
(RE_Fat_IEEE_Long
);
4894 Fat_Pkg
:= RE_Attr_IEEE_Long
;
4897 raise Program_Error
;
4900 -- If neither the base type nor the root type is VAX_Float then VAX
4901 -- float is out of the picture, and we can just use the root type.
4906 if Fat_Type
= Standard_Short_Float
then
4907 Fat_Pkg
:= RE_Attr_Short_Float
;
4909 elsif Fat_Type
= Standard_Float
then
4910 Fat_Pkg
:= RE_Attr_Float
;
4912 elsif Fat_Type
= Standard_Long_Float
then
4913 Fat_Pkg
:= RE_Attr_Long_Float
;
4915 elsif Fat_Type
= Standard_Long_Long_Float
then
4916 Fat_Pkg
:= RE_Attr_Long_Long_Float
;
4918 -- Universal real (which is its own root type) is treated as being
4919 -- equivalent to Standard.Long_Long_Float, since it is defined to
4920 -- have the same precision as the longest Float type.
4922 elsif Fat_Type
= Universal_Real
then
4923 Fat_Type
:= Standard_Long_Long_Float
;
4924 Fat_Pkg
:= RE_Attr_Long_Long_Float
;
4927 raise Program_Error
;
4932 ----------------------------
4933 -- Find_Stream_Subprogram --
4934 ----------------------------
4936 function Find_Stream_Subprogram
4938 Nam
: TSS_Name_Type
) return Entity_Id
4940 Ent
: constant Entity_Id
:= TSS
(Typ
, Nam
);
4942 if Present
(Ent
) then
4946 if Is_Tagged_Type
(Typ
)
4947 and then Is_Derived_Type
(Typ
)
4949 return Find_Prim_Op
(Typ
, Nam
);
4951 return Find_Inherited_TSS
(Typ
, Nam
);
4953 end Find_Stream_Subprogram
;
4955 -----------------------
4956 -- Get_Index_Subtype --
4957 -----------------------
4959 function Get_Index_Subtype
(N
: Node_Id
) return Node_Id
is
4960 P_Type
: Entity_Id
:= Etype
(Prefix
(N
));
4965 if Is_Access_Type
(P_Type
) then
4966 P_Type
:= Designated_Type
(P_Type
);
4969 if No
(Expressions
(N
)) then
4972 J
:= UI_To_Int
(Expr_Value
(First
(Expressions
(N
))));
4975 Indx
:= First_Index
(P_Type
);
4981 return Etype
(Indx
);
4982 end Get_Index_Subtype
;
4984 -------------------------------
4985 -- Get_Stream_Convert_Pragma --
4986 -------------------------------
4988 function Get_Stream_Convert_Pragma
(T
: Entity_Id
) return Node_Id
is
4993 -- Note: we cannot use Get_Rep_Pragma here because of the peculiarity
4994 -- that a stream convert pragma for a tagged type is not inherited from
4995 -- its parent. Probably what is wrong here is that it is basically
4996 -- incorrect to consider a stream convert pragma to be a representation
4997 -- pragma at all ???
4999 N
:= First_Rep_Item
(Implementation_Base_Type
(T
));
5000 while Present
(N
) loop
5001 if Nkind
(N
) = N_Pragma
and then Chars
(N
) = Name_Stream_Convert
then
5003 -- For tagged types this pragma is not inherited, so we
5004 -- must verify that it is defined for the given type and
5008 Entity
(Expression
(First
(Pragma_Argument_Associations
(N
))));
5010 if not Is_Tagged_Type
(T
)
5012 or else (Is_Private_Type
(Typ
) and then T
= Full_View
(Typ
))
5022 end Get_Stream_Convert_Pragma
;
5024 ---------------------------------
5025 -- Is_Constrained_Packed_Array --
5026 ---------------------------------
5028 function Is_Constrained_Packed_Array
(Typ
: Entity_Id
) return Boolean is
5029 Arr
: Entity_Id
:= Typ
;
5032 if Is_Access_Type
(Arr
) then
5033 Arr
:= Designated_Type
(Arr
);
5036 return Is_Array_Type
(Arr
)
5037 and then Is_Constrained
(Arr
)
5038 and then Present
(Packed_Array_Type
(Arr
));
5039 end Is_Constrained_Packed_Array
;