1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2008, 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_Atag; use Exp_Atag;
32 with Exp_Ch2; use Exp_Ch2;
33 with Exp_Ch9; use Exp_Ch9;
34 with Exp_Imgv; use Exp_Imgv;
35 with Exp_Pakd; use Exp_Pakd;
36 with Exp_Strm; use Exp_Strm;
37 with Exp_Tss; use Exp_Tss;
38 with Exp_Util; use Exp_Util;
39 with Exp_VFpt; use Exp_VFpt;
40 with Freeze; use Freeze;
41 with Gnatvsn; use Gnatvsn;
42 with Itypes; use Itypes;
44 with Namet; use Namet;
45 with Nmake; use Nmake;
46 with Nlists; use Nlists;
48 with Restrict; use Restrict;
49 with Rident; use Rident;
50 with Rtsfind; use Rtsfind;
52 with Sem_Ch6; use Sem_Ch6;
53 with Sem_Ch7; use Sem_Ch7;
54 with Sem_Ch8; use Sem_Ch8;
55 with Sem_Eval; use Sem_Eval;
56 with Sem_Res; use Sem_Res;
57 with Sem_Util; use Sem_Util;
58 with Sinfo; use Sinfo;
59 with Snames; use Snames;
60 with Stand; use Stand;
61 with Stringt; use Stringt;
62 with Targparm; use Targparm;
63 with Tbuild; use Tbuild;
64 with Ttypes; use Ttypes;
65 with Uintp; use Uintp;
66 with Uname; use Uname;
67 with Validsw; use Validsw;
69 package body Exp_Attr is
71 -----------------------
72 -- Local Subprograms --
73 -----------------------
75 procedure Compile_Stream_Body_In_Scope
80 -- The body for a stream subprogram may be generated outside of the scope
81 -- of the type. If the type is fully private, it may depend on the full
82 -- view of other types (e.g. indices) that are currently private as well.
83 -- We install the declarations of the package in which the type is declared
84 -- before compiling the body in what is its proper environment. The Check
85 -- parameter indicates if checks are to be suppressed for the stream body.
86 -- We suppress checks for array/record reads, since the rule is that these
87 -- are like assignments, out of range values due to uninitialized storage,
88 -- or other invalid values do NOT cause a Constraint_Error to be raised.
90 procedure Expand_Access_To_Protected_Op
95 -- An attribute reference to a protected subprogram is transformed into
96 -- a pair of pointers: one to the object, and one to the operations.
97 -- This expansion is performed for 'Access and for 'Unrestricted_Access.
99 procedure Expand_Fpt_Attribute
104 -- This procedure expands a call to a floating-point attribute function.
105 -- N is the attribute reference node, and Args is a list of arguments to
106 -- be passed to the function call. Pkg identifies the package containing
107 -- the appropriate instantiation of System.Fat_Gen. Float arguments in Args
108 -- have already been converted to the floating-point type for which Pkg was
109 -- instantiated. The Nam argument is the relevant attribute processing
110 -- routine to be called. This is the same as the attribute name, except in
111 -- the Unaligned_Valid case.
113 procedure Expand_Fpt_Attribute_R (N : Node_Id);
114 -- This procedure expands a call to a floating-point attribute function
115 -- that takes a single floating-point argument. The function to be called
116 -- is always the same as the attribute name.
118 procedure Expand_Fpt_Attribute_RI (N : Node_Id);
119 -- This procedure expands a call to a floating-point attribute function
120 -- that takes one floating-point argument and one integer argument. The
121 -- function to be called is always the same as the attribute name.
123 procedure Expand_Fpt_Attribute_RR (N : Node_Id);
124 -- This procedure expands a call to a floating-point attribute function
125 -- that takes two floating-point arguments. The function to be called
126 -- is always the same as the attribute name.
128 procedure Expand_Pred_Succ (N : Node_Id);
129 -- Handles expansion of Pred or Succ attributes for case of non-real
130 -- operand with overflow checking required.
132 function Get_Index_Subtype (N : Node_Id) return Entity_Id;
133 -- Used for Last, Last, and Length, when the prefix is an array type.
134 -- Obtains the corresponding index subtype.
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 function Is_Inline_Floating_Point_Attribute (N : Node_Id) return Boolean;
164 -- Returns true iff the given node refers to an attribute call that
165 -- can be expanded directly by the back end and does not need front end
166 -- expansion. Typically used for rounding and truncation attributes that
167 -- appear directly inside a conversion to integer.
169 ----------------------------------
170 -- Compile_Stream_Body_In_Scope --
171 ----------------------------------
173 procedure Compile_Stream_Body_In_Scope
179 Installed : Boolean := False;
180 Scop : constant Entity_Id := Scope (Arr);
181 Curr : constant Entity_Id := Current_Scope;
185 and then not In_Open_Scopes (Scop)
186 and then Ekind (Scop) = E_Package
189 Install_Visible_Declarations (Scop);
190 Install_Private_Declarations (Scop);
193 -- The entities in the package are now visible, but the generated
194 -- stream entity must appear in the current scope (usually an
195 -- enclosing stream function) so that itypes all have their proper
202 Insert_Action (N, Decl);
204 Insert_Action (N, Decl, Suppress => All_Checks);
209 -- Remove extra copy of current scope, and package itself
212 End_Package_Scope (Scop);
214 end Compile_Stream_Body_In_Scope;
216 -----------------------------------
217 -- Expand_Access_To_Protected_Op --
218 -----------------------------------
220 procedure Expand_Access_To_Protected_Op
225 -- The value of the attribute_reference is a record containing two
226 -- fields: an access to the protected object, and an access to the
227 -- subprogram itself. The prefix is a selected component.
229 Loc : constant Source_Ptr := Sloc (N);
231 Btyp : constant Entity_Id := Base_Type (Typ);
233 E_T : constant Entity_Id := Equivalent_Type (Btyp);
234 Acc : constant Entity_Id :=
235 Etype (Next_Component (First_Component (E_T)));
239 function May_Be_External_Call return Boolean;
240 -- If the 'Access is to a local operation, but appears in a context
241 -- where it may lead to a call from outside the object, we must treat
242 -- this as an external call. Clearly we cannot tell without full
243 -- flow analysis, and a subsequent call that uses this 'Access may
244 -- lead to a bounded error (trying to seize locks twice, e.g.). For
245 -- now we treat 'Access as a potential external call if it is an actual
246 -- in a call to an outside subprogram.
248 --------------------------
249 -- May_Be_External_Call --
250 --------------------------
252 function May_Be_External_Call return Boolean is
255 if (Nkind (Parent (N)) = N_Procedure_Call_Statement
256 or else Nkind (Parent (N)) = N_Function_Call)
257 and then Is_Entity_Name (Name (Parent (N)))
259 Subp := Entity (Name (Parent (N)));
260 return not In_Open_Scopes (Scope (Subp));
264 end May_Be_External_Call;
266 -- Start of processing for Expand_Access_To_Protected_Op
269 -- Within the body of the protected type, the prefix
270 -- designates a local operation, and the object is the first
271 -- parameter of the corresponding protected body of the
272 -- current enclosing operation.
274 if Is_Entity_Name (Pref) then
275 pragma Assert (In_Open_Scopes (Scope (Entity (Pref))));
277 if May_Be_External_Call then
280 (External_Subprogram (Entity (Pref)), Loc);
284 (Protected_Body_Subprogram (Entity (Pref)), Loc);
287 Curr := Current_Scope;
288 while Scope (Curr) /= Scope (Entity (Pref)) loop
289 Curr := Scope (Curr);
292 -- In case of protected entries the first formal of its Protected_
293 -- Body_Subprogram is the address of the object.
295 if Ekind (Curr) = E_Entry then
299 (Protected_Body_Subprogram (Curr)), Loc);
301 -- In case of protected subprograms the first formal of its
302 -- Protected_Body_Subprogram is the object and we get its address.
306 Make_Attribute_Reference (Loc,
310 (Protected_Body_Subprogram (Curr)), Loc),
311 Attribute_Name => Name_Address);
314 -- Case where the prefix is not an entity name. Find the
315 -- version of the protected operation to be called from
316 -- outside the protected object.
322 (Entity (Selector_Name (Pref))), Loc);
325 Make_Attribute_Reference (Loc,
326 Prefix => Relocate_Node (Prefix (Pref)),
327 Attribute_Name => Name_Address);
335 Unchecked_Convert_To (Acc,
336 Make_Attribute_Reference (Loc,
338 Attribute_Name => Name_Address))));
342 Analyze_And_Resolve (N, E_T);
344 -- For subsequent analysis, the node must retain its type.
345 -- The backend will replace it with the equivalent type where
349 end Expand_Access_To_Protected_Op;
351 --------------------------
352 -- Expand_Fpt_Attribute --
353 --------------------------
355 procedure Expand_Fpt_Attribute
361 Loc : constant Source_Ptr := Sloc (N);
362 Typ : constant Entity_Id := Etype (N);
366 -- The function name is the selected component Attr_xxx.yyy where
367 -- Attr_xxx is the package name, and yyy is the argument Nam.
369 -- Note: it would be more usual to have separate RE entries for each
370 -- of the entities in the Fat packages, but first they have identical
371 -- names (so we would have to have lots of renaming declarations to
372 -- meet the normal RE rule of separate names for all runtime entities),
373 -- and second there would be an awful lot of them!
376 Make_Selected_Component (Loc,
377 Prefix => New_Reference_To (RTE (Pkg), Loc),
378 Selector_Name => Make_Identifier (Loc, Nam));
380 -- The generated call is given the provided set of parameters, and then
381 -- wrapped in a conversion which converts the result to the target type
382 -- We use the base type as the target because a range check may be
386 Unchecked_Convert_To (Base_Type (Etype (N)),
387 Make_Function_Call (Loc,
389 Parameter_Associations => Args)));
391 Analyze_And_Resolve (N, Typ);
392 end Expand_Fpt_Attribute;
394 ----------------------------
395 -- Expand_Fpt_Attribute_R --
396 ----------------------------
398 -- The single argument is converted to its root type to call the
399 -- appropriate runtime function, with the actual call being built
400 -- by Expand_Fpt_Attribute
402 procedure Expand_Fpt_Attribute_R (N : Node_Id) is
403 E1 : constant Node_Id := First (Expressions (N));
407 Find_Fat_Info (Etype (E1), Ftp, Pkg);
409 (N, Pkg, Attribute_Name (N),
410 New_List (Unchecked_Convert_To (Ftp, Relocate_Node (E1))));
411 end Expand_Fpt_Attribute_R;
413 -----------------------------
414 -- Expand_Fpt_Attribute_RI --
415 -----------------------------
417 -- The first argument is converted to its root type and the second
418 -- argument is converted to standard long long integer to call the
419 -- appropriate runtime function, with the actual call being built
420 -- by Expand_Fpt_Attribute
422 procedure Expand_Fpt_Attribute_RI (N : Node_Id) is
423 E1 : constant Node_Id := First (Expressions (N));
426 E2 : constant Node_Id := Next (E1);
428 Find_Fat_Info (Etype (E1), Ftp, Pkg);
430 (N, Pkg, Attribute_Name (N),
432 Unchecked_Convert_To (Ftp, Relocate_Node (E1)),
433 Unchecked_Convert_To (Standard_Integer, Relocate_Node (E2))));
434 end Expand_Fpt_Attribute_RI;
436 -----------------------------
437 -- Expand_Fpt_Attribute_RR --
438 -----------------------------
440 -- The two arguments are converted to their root types to call the
441 -- appropriate runtime function, with the actual call being built
442 -- by Expand_Fpt_Attribute
444 procedure Expand_Fpt_Attribute_RR (N : Node_Id) is
445 E1 : constant Node_Id := First (Expressions (N));
448 E2 : constant Node_Id := Next (E1);
450 Find_Fat_Info (Etype (E1), Ftp, Pkg);
452 (N, Pkg, Attribute_Name (N),
454 Unchecked_Convert_To (Ftp, Relocate_Node (E1)),
455 Unchecked_Convert_To (Ftp, Relocate_Node (E2))));
456 end Expand_Fpt_Attribute_RR;
458 ----------------------------------
459 -- Expand_N_Attribute_Reference --
460 ----------------------------------
462 procedure Expand_N_Attribute_Reference (N : Node_Id) is
463 Loc : constant Source_Ptr := Sloc (N);
464 Typ : constant Entity_Id := Etype (N);
465 Btyp : constant Entity_Id := Base_Type (Typ);
466 Pref : constant Node_Id := Prefix (N);
467 Exprs : constant List_Id := Expressions (N);
468 Id : constant Attribute_Id := Get_Attribute_Id (Attribute_Name (N));
470 procedure Rewrite_Stream_Proc_Call (Pname : Entity_Id);
471 -- Rewrites a stream attribute for Read, Write or Output with the
472 -- procedure call. Pname is the entity for the procedure to call.
474 ------------------------------
475 -- Rewrite_Stream_Proc_Call --
476 ------------------------------
478 procedure Rewrite_Stream_Proc_Call (Pname : Entity_Id) is
479 Item : constant Node_Id := Next (First (Exprs));
480 Formal : constant Entity_Id := Next_Formal (First_Formal (Pname));
481 Formal_Typ : constant Entity_Id := Etype (Formal);
482 Is_Written : constant Boolean := (Ekind (Formal) /= E_In_Parameter);
485 -- The expansion depends on Item, the second actual, which is
486 -- the object being streamed in or out.
488 -- If the item is a component of a packed array type, and
489 -- a conversion is needed on exit, we introduce a temporary to
490 -- hold the value, because otherwise the packed reference will
491 -- not be properly expanded.
493 if Nkind (Item) = N_Indexed_Component
494 and then Is_Packed (Base_Type (Etype (Prefix (Item))))
495 and then Base_Type (Etype (Item)) /= Base_Type (Formal_Typ)
499 Temp : constant Entity_Id :=
500 Make_Defining_Identifier
501 (Loc, New_Internal_Name ('V'));
507 Make_Object_Declaration (Loc,
508 Defining_Identifier => Temp,
510 New_Occurrence_Of (Formal_Typ, Loc));
511 Set_Etype (Temp, Formal_Typ);
514 Make_Assignment_Statement (Loc,
515 Name => New_Copy_Tree (Item),
518 (Etype (Item), New_Occurrence_Of (Temp, Loc)));
520 Rewrite (Item, New_Occurrence_Of (Temp, Loc));
524 Make_Procedure_Call_Statement (Loc,
525 Name => New_Occurrence_Of (Pname, Loc),
526 Parameter_Associations => Exprs),
529 Rewrite (N, Make_Null_Statement (Loc));
534 -- For the class-wide dispatching cases, and for cases in which
535 -- the base type of the second argument matches the base type of
536 -- the corresponding formal parameter (that is to say the stream
537 -- operation is not inherited), we are all set, and can use the
538 -- argument unchanged.
540 -- For all other cases we do an unchecked conversion of the second
541 -- parameter to the type of the formal of the procedure we are
542 -- calling. This deals with the private type cases, and with going
543 -- to the root type as required in elementary type case.
545 if not Is_Class_Wide_Type (Entity (Pref))
546 and then not Is_Class_Wide_Type (Etype (Item))
547 and then Base_Type (Etype (Item)) /= Base_Type (Formal_Typ)
550 Unchecked_Convert_To (Formal_Typ, Relocate_Node (Item)));
552 -- For untagged derived types set Assignment_OK, to prevent
553 -- copies from being created when the unchecked conversion
554 -- is expanded (which would happen in Remove_Side_Effects
555 -- if Expand_N_Unchecked_Conversion were allowed to call
556 -- Force_Evaluation). The copy could violate Ada semantics
557 -- in cases such as an actual that is an out parameter.
558 -- Note that this approach is also used in exp_ch7 for calls
559 -- to controlled type operations to prevent problems with
560 -- actuals wrapped in unchecked conversions.
562 if Is_Untagged_Derivation (Etype (Expression (Item))) then
563 Set_Assignment_OK (Item);
567 -- And now rewrite the call
570 Make_Procedure_Call_Statement (Loc,
571 Name => New_Occurrence_Of (Pname, Loc),
572 Parameter_Associations => Exprs));
575 end Rewrite_Stream_Proc_Call;
577 -- Start of processing for Expand_N_Attribute_Reference
580 -- Do required validity checking, if enabled. Do not apply check to
581 -- output parameters of an Asm instruction, since the value of this
582 -- is not set till after the attribute has been elaborated.
584 if Validity_Checks_On and then Validity_Check_Operands
585 and then Id /= Attribute_Asm_Output
590 Expr := First (Expressions (N));
591 while Present (Expr) loop
598 -- Remaining processing depends on specific attribute
606 when Attribute_Access |
607 Attribute_Unchecked_Access |
608 Attribute_Unrestricted_Access =>
610 Access_Cases : declare
611 Btyp_DDT : constant Entity_Id := Directly_Designated_Type (Btyp);
612 Ref_Object : constant Node_Id := Get_Referenced_Object (Pref);
615 -- In order to improve the text of error messages, the designated
616 -- type of access-to-subprogram itypes is set by the semantics as
617 -- the associated subprogram entity (see sem_attr). Now we replace
618 -- such node with the proper E_Subprogram_Type itype.
620 if Id = Attribute_Unrestricted_Access
621 and then Is_Subprogram (Directly_Designated_Type (Typ))
623 -- The following assertion ensures that this special management
624 -- is done only for "Address!(Prim'Unrestricted_Access)" nodes.
625 -- At this stage other cases in which the designated type is
626 -- still a subprogram (instead of an E_Subprogram_Type) are
627 -- wrong because the semantics must have overriden the type of
628 -- the node with the type imposed by the context.
630 pragma Assert (Nkind (Parent (N)) = N_Unchecked_Type_Conversion
631 and then Etype (Parent (N)) = RTE (RE_Address));
634 Subp : constant Entity_Id := Directly_Designated_Type (Typ);
636 Extra : Entity_Id := Empty;
637 New_Formal : Entity_Id;
638 Old_Formal : Entity_Id := First_Formal (Subp);
639 Subp_Typ : Entity_Id;
642 Subp_Typ := Create_Itype (E_Subprogram_Type, N);
643 Set_Etype (Subp_Typ, Etype (Subp));
644 Set_Returns_By_Ref (Subp_Typ, Returns_By_Ref (Subp));
646 if Present (Old_Formal) then
647 New_Formal := New_Copy (Old_Formal);
648 Set_First_Entity (Subp_Typ, New_Formal);
651 Set_Scope (New_Formal, Subp_Typ);
655 if Is_Itype (Etype (New_Formal)) then
656 Extra := New_Copy (Etype (New_Formal));
658 if Ekind (Extra) = E_Record_Subtype
659 or else Ekind (Extra) = E_Class_Wide_Subtype
661 Set_Cloned_Subtype (Extra,
665 Set_Etype (New_Formal, Extra);
666 Set_Scope (Etype (New_Formal), Subp_Typ);
670 Next_Formal (Old_Formal);
671 exit when No (Old_Formal);
673 Set_Next_Entity (New_Formal,
674 New_Copy (Old_Formal));
675 Next_Entity (New_Formal);
678 Set_Next_Entity (New_Formal, Empty);
679 Set_Last_Entity (Subp_Typ, Extra);
682 -- Now that the explicit formals have been duplicated,
683 -- any extra formals needed by the subprogram must be
686 if Present (Extra) then
687 Set_Extra_Formal (Extra, Empty);
690 Create_Extra_Formals (Subp_Typ);
691 Set_Directly_Designated_Type (Typ, Subp_Typ);
693 -- Complete decoration of access-to-subprogram itype to
694 -- indicate to the backend that this itype corresponds to
695 -- a statically allocated dispatch table.
697 -- ??? more comments on structure here, three level parent
698 -- references are worrisome!
700 if Nkind (Ref_Object) in N_Has_Entity
701 and then Is_Dispatching_Operation (Entity (Ref_Object))
702 and then Present (Parent (Parent (N)))
703 and then Nkind (Parent (Parent (N))) = N_Aggregate
704 and then Present (Parent (Parent (Parent (N))))
707 P : constant Node_Id :=
708 Parent (Parent (Parent (N)));
709 Prim : constant Entity_Id := Entity (Ref_Object);
712 Set_Is_Static_Dispatch_Table_Entity (Typ,
713 (Is_Predefined_Dispatching_Operation (Prim)
714 and then Nkind (P) = N_Object_Declaration
715 and then Is_Static_Dispatch_Table_Entity
716 (Defining_Identifier (P)))
718 (not Is_Predefined_Dispatching_Operation (Prim)
719 and then Nkind (P) = N_Aggregate
720 and then Present (Parent (P))
721 and then Nkind (Parent (P))
722 = N_Object_Declaration
723 and then Is_Static_Dispatch_Table_Entity
724 (Defining_Identifier (Parent (P)))));
730 if Is_Access_Protected_Subprogram_Type (Btyp) then
731 Expand_Access_To_Protected_Op (N, Pref, Typ);
733 -- If prefix is a type name, this is a reference to the current
734 -- instance of the type, within its initialization procedure.
736 elsif Is_Entity_Name (Pref)
737 and then Is_Type (Entity (Pref))
744 -- If the current instance name denotes a task type, then
745 -- the access attribute is rewritten to be the name of the
746 -- "_task" parameter associated with the task type's task
747 -- procedure. An unchecked conversion is applied to ensure
748 -- a type match in cases of expander-generated calls (e.g.
751 if Is_Task_Type (Entity (Pref)) then
753 First_Entity (Get_Task_Body_Procedure (Entity (Pref)));
754 while Present (Formal) loop
755 exit when Chars (Formal) = Name_uTask;
756 Next_Entity (Formal);
759 pragma Assert (Present (Formal));
762 Unchecked_Convert_To (Typ,
763 New_Occurrence_Of (Formal, Loc)));
766 -- The expression must appear in a default expression,
767 -- (which in the initialization procedure is the
768 -- right-hand side of an assignment), and not in a
769 -- discriminant constraint.
773 while Present (Par) loop
774 exit when Nkind (Par) = N_Assignment_Statement;
776 if Nkind (Par) = N_Component_Declaration then
783 if Present (Par) then
785 Make_Attribute_Reference (Loc,
786 Prefix => Make_Identifier (Loc, Name_uInit),
787 Attribute_Name => Attribute_Name (N)));
789 Analyze_And_Resolve (N, Typ);
794 -- If the prefix of an Access attribute is a dereference of an
795 -- access parameter (or a renaming of such a dereference) and
796 -- the context is a general access type (but not an anonymous
797 -- access type), then rewrite the attribute as a conversion of
798 -- the access parameter to the context access type. This will
799 -- result in an accessibility check being performed, if needed.
801 -- (X.all'Access => Acc_Type (X))
803 -- Note: Limit the expansion of an attribute applied to a
804 -- dereference of an access parameter so that it's only done
805 -- for 'Access. This fixes a problem with 'Unrestricted_Access
806 -- that leads to errors in the case where the attribute type
807 -- is access-to-variable and the access parameter is
808 -- access-to-constant. The conversion is only done to get
809 -- accessibility checks, so it makes sense to limit it to
812 elsif Nkind (Ref_Object) = N_Explicit_Dereference
813 and then Is_Entity_Name (Prefix (Ref_Object))
814 and then Ekind (Btyp) = E_General_Access_Type
815 and then Ekind (Entity (Prefix (Ref_Object))) in Formal_Kind
816 and then Ekind (Etype (Entity (Prefix (Ref_Object))))
817 = E_Anonymous_Access_Type
818 and then Present (Extra_Accessibility
819 (Entity (Prefix (Ref_Object))))
822 Convert_To (Typ, New_Copy_Tree (Prefix (Ref_Object))));
823 Analyze_And_Resolve (N, Typ);
825 -- Ada 2005 (AI-251): If the designated type is an interface we
826 -- add an implicit conversion to force the displacement of the
827 -- pointer to reference the secondary dispatch table.
829 elsif Is_Interface (Btyp_DDT)
830 and then (Comes_From_Source (N)
831 or else Comes_From_Source (Ref_Object)
832 or else (Nkind (Ref_Object) in N_Has_Chars
833 and then Chars (Ref_Object) = Name_uInit))
835 if Nkind (Ref_Object) /= N_Explicit_Dereference then
837 -- No implicit conversion required if types match
839 if Btyp_DDT /= Etype (Ref_Object) then
841 Convert_To (Directly_Designated_Type (Typ),
842 New_Copy_Tree (Prefix (N))));
844 Analyze_And_Resolve (Prefix (N),
845 Directly_Designated_Type (Typ));
848 -- When the object is an explicit dereference, convert the
849 -- dereference's prefix.
853 Obj_DDT : constant Entity_Id :=
855 (Directly_Designated_Type
856 (Etype (Prefix (Ref_Object))));
858 -- No implicit conversion required if designated types
861 if Obj_DDT /= Btyp_DDT
862 and then not (Is_Class_Wide_Type (Obj_DDT)
863 and then Etype (Obj_DDT) = Btyp_DDT)
867 New_Copy_Tree (Prefix (Ref_Object))));
868 Analyze_And_Resolve (N, Typ);
879 -- Transforms 'Adjacent into a call to the floating-point attribute
880 -- function Adjacent in Fat_xxx (where xxx is the root type)
882 when Attribute_Adjacent =>
883 Expand_Fpt_Attribute_RR (N);
889 when Attribute_Address => Address : declare
890 Task_Proc : Entity_Id;
893 -- If the prefix is a task or a task type, the useful address is that
894 -- of the procedure for the task body, i.e. the actual program unit.
895 -- We replace the original entity with that of the procedure.
897 if Is_Entity_Name (Pref)
898 and then Is_Task_Type (Entity (Pref))
900 Task_Proc := Next_Entity (Root_Type (Etype (Pref)));
902 while Present (Task_Proc) loop
903 exit when Ekind (Task_Proc) = E_Procedure
904 and then Etype (First_Formal (Task_Proc)) =
905 Corresponding_Record_Type (Etype (Pref));
906 Next_Entity (Task_Proc);
909 if Present (Task_Proc) then
910 Set_Entity (Pref, Task_Proc);
911 Set_Etype (Pref, Etype (Task_Proc));
914 -- Similarly, the address of a protected operation is the address
915 -- of the corresponding protected body, regardless of the protected
916 -- object from which it is selected.
918 elsif Nkind (Pref) = N_Selected_Component
919 and then Is_Subprogram (Entity (Selector_Name (Pref)))
920 and then Is_Protected_Type (Scope (Entity (Selector_Name (Pref))))
924 External_Subprogram (Entity (Selector_Name (Pref))), Loc));
926 elsif Nkind (Pref) = N_Explicit_Dereference
927 and then Ekind (Etype (Pref)) = E_Subprogram_Type
928 and then Convention (Etype (Pref)) = Convention_Protected
930 -- The prefix is be a dereference of an access_to_protected_
931 -- subprogram. The desired address is the second component of
932 -- the record that represents the access.
935 Addr : constant Entity_Id := Etype (N);
936 Ptr : constant Node_Id := Prefix (Pref);
937 T : constant Entity_Id :=
938 Equivalent_Type (Base_Type (Etype (Ptr)));
942 Unchecked_Convert_To (Addr,
943 Make_Selected_Component (Loc,
944 Prefix => Unchecked_Convert_To (T, Ptr),
945 Selector_Name => New_Occurrence_Of (
946 Next_Entity (First_Entity (T)), Loc))));
948 Analyze_And_Resolve (N, Addr);
951 -- Ada 2005 (AI-251): Class-wide interface objects are always
952 -- "displaced" to reference the tag associated with the interface
953 -- type. In order to obtain the real address of such objects we
954 -- generate a call to a run-time subprogram that returns the base
955 -- address of the object.
957 -- This processing is not needed in the VM case, where dispatching
958 -- issues are taken care of by the virtual machine.
960 elsif Is_Class_Wide_Type (Etype (Pref))
961 and then Is_Interface (Etype (Pref))
962 and then VM_Target = No_VM
963 and then not (Nkind (Pref) in N_Has_Entity
964 and then Is_Subprogram (Entity (Pref)))
967 Make_Function_Call (Loc,
968 Name => New_Reference_To (RTE (RE_Base_Address), Loc),
969 Parameter_Associations => New_List (
970 Relocate_Node (N))));
975 -- Deal with packed array reference, other cases are handled by gigi
977 if Involves_Packed_Array_Reference (Pref) then
978 Expand_Packed_Address_Reference (N);
986 when Attribute_Alignment => Alignment : declare
987 Ptyp : constant Entity_Id := Etype (Pref);
991 -- For class-wide types, X'Class'Alignment is transformed into a
992 -- direct reference to the Alignment of the class type, so that the
993 -- back end does not have to deal with the X'Class'Alignment
996 if Is_Entity_Name (Pref)
997 and then Is_Class_Wide_Type (Entity (Pref))
999 Rewrite (Prefix (N), New_Occurrence_Of (Entity (Pref), Loc));
1002 -- For x'Alignment applied to an object of a class wide type,
1003 -- transform X'Alignment into a call to the predefined primitive
1004 -- operation _Alignment applied to X.
1006 elsif Is_Class_Wide_Type (Ptyp) then
1008 -- No need to do anything else compiling under restriction
1009 -- No_Dispatching_Calls. During the semantic analysis we
1010 -- already notified such violation.
1012 if Restriction_Active (No_Dispatching_Calls) then
1017 Make_Function_Call (Loc,
1018 Name => New_Reference_To
1019 (Find_Prim_Op (Ptyp, Name_uAlignment), Loc),
1020 Parameter_Associations => New_List (Pref));
1022 if Typ /= Standard_Integer then
1024 -- The context is a specific integer type with which the
1025 -- original attribute was compatible. The function has a
1026 -- specific type as well, so to preserve the compatibility
1027 -- we must convert explicitly.
1029 New_Node := Convert_To (Typ, New_Node);
1032 Rewrite (N, New_Node);
1033 Analyze_And_Resolve (N, Typ);
1036 -- For all other cases, we just have to deal with the case of
1037 -- the fact that the result can be universal.
1040 Apply_Universal_Integer_Attribute_Checks (N);
1048 when Attribute_AST_Entry => AST_Entry : declare
1053 Entry_Ref : Node_Id;
1054 -- The reference to the entry or entry family
1057 -- The index expression for an entry family reference, or
1058 -- the Empty if Entry_Ref references a simple entry.
1061 if Nkind (Pref) = N_Indexed_Component then
1062 Entry_Ref := Prefix (Pref);
1063 Index := First (Expressions (Pref));
1069 -- Get expression for Task_Id and the entry entity
1071 if Nkind (Entry_Ref) = N_Selected_Component then
1073 Make_Attribute_Reference (Loc,
1074 Attribute_Name => Name_Identity,
1075 Prefix => Prefix (Entry_Ref));
1077 Ttyp := Etype (Prefix (Entry_Ref));
1078 Eent := Entity (Selector_Name (Entry_Ref));
1082 Make_Function_Call (Loc,
1083 Name => New_Occurrence_Of (RTE (RE_Current_Task), Loc));
1085 Eent := Entity (Entry_Ref);
1087 -- We have to find the enclosing task to get the task type
1088 -- There must be one, since we already validated this earlier
1090 Ttyp := Current_Scope;
1091 while not Is_Task_Type (Ttyp) loop
1092 Ttyp := Scope (Ttyp);
1096 -- Now rewrite the attribute with a call to Create_AST_Handler
1099 Make_Function_Call (Loc,
1100 Name => New_Occurrence_Of (RTE (RE_Create_AST_Handler), Loc),
1101 Parameter_Associations => New_List (
1103 Entry_Index_Expression (Loc, Eent, Index, Ttyp))));
1105 Analyze_And_Resolve (N, RTE (RE_AST_Handler));
1112 -- We compute this if a component clause was present, otherwise
1113 -- we leave the computation up to Gigi, since we don't know what
1114 -- layout will be chosen.
1116 -- Note that the attribute can apply to a naked record component
1117 -- in generated code (i.e. the prefix is an identifier that
1118 -- references the component or discriminant entity).
1120 when Attribute_Bit_Position => Bit_Position :
1125 if Nkind (Pref) = N_Identifier then
1126 CE := Entity (Pref);
1128 CE := Entity (Selector_Name (Pref));
1131 if Known_Static_Component_Bit_Offset (CE) then
1133 Make_Integer_Literal (Loc,
1134 Intval => Component_Bit_Offset (CE)));
1135 Analyze_And_Resolve (N, Typ);
1138 Apply_Universal_Integer_Attribute_Checks (N);
1146 -- A reference to P'Body_Version or P'Version is expanded to
1149 -- pragma Import (C, Vnn, "uuuuT";
1151 -- Get_Version_String (Vnn)
1153 -- where uuuu is the unit name (dots replaced by double underscore)
1154 -- and T is B for the cases of Body_Version, or Version applied to a
1155 -- subprogram acting as its own spec, and S for Version applied to a
1156 -- subprogram spec or package. This sequence of code references the
1157 -- the unsigned constant created in the main program by the binder.
1159 -- A special exception occurs for Standard, where the string
1160 -- returned is a copy of the library string in gnatvsn.ads.
1162 when Attribute_Body_Version | Attribute_Version => Version : declare
1163 E : constant Entity_Id :=
1164 Make_Defining_Identifier (Loc, New_Internal_Name ('V'));
1169 -- If not library unit, get to containing library unit
1171 Pent := Entity (Pref);
1172 while Pent /= Standard_Standard
1173 and then Scope (Pent) /= Standard_Standard
1174 and then not Is_Child_Unit (Pent)
1176 Pent := Scope (Pent);
1179 -- Special case Standard and Standard.ASCII
1181 if Pent = Standard_Standard or else Pent = Standard_ASCII then
1183 Make_String_Literal (Loc,
1184 Strval => Verbose_Library_Version));
1189 -- Build required string constant
1191 Get_Name_String (Get_Unit_Name (Pent));
1194 for J in 1 .. Name_Len - 2 loop
1195 if Name_Buffer (J) = '.' then
1196 Store_String_Chars ("__");
1198 Store_String_Char (Get_Char_Code (Name_Buffer (J)));
1202 -- Case of subprogram acting as its own spec, always use body
1204 if Nkind (Declaration_Node (Pent)) in N_Subprogram_Specification
1205 and then Nkind (Parent (Declaration_Node (Pent))) =
1207 and then Acts_As_Spec (Parent (Declaration_Node (Pent)))
1209 Store_String_Chars ("B");
1211 -- Case of no body present, always use spec
1213 elsif not Unit_Requires_Body (Pent) then
1214 Store_String_Chars ("S");
1216 -- Otherwise use B for Body_Version, S for spec
1218 elsif Id = Attribute_Body_Version then
1219 Store_String_Chars ("B");
1221 Store_String_Chars ("S");
1225 Lib.Version_Referenced (S);
1227 -- Insert the object declaration
1229 Insert_Actions (N, New_List (
1230 Make_Object_Declaration (Loc,
1231 Defining_Identifier => E,
1232 Object_Definition =>
1233 New_Occurrence_Of (RTE (RE_Unsigned), Loc))));
1235 -- Set entity as imported with correct external name
1237 Set_Is_Imported (E);
1238 Set_Interface_Name (E, Make_String_Literal (Loc, S));
1240 -- Set entity as internal to ensure proper Sprint output of its
1241 -- implicit importation.
1243 Set_Is_Internal (E);
1245 -- And now rewrite original reference
1248 Make_Function_Call (Loc,
1249 Name => New_Reference_To (RTE (RE_Get_Version_String), Loc),
1250 Parameter_Associations => New_List (
1251 New_Occurrence_Of (E, Loc))));
1254 Analyze_And_Resolve (N, RTE (RE_Version_String));
1261 -- Transforms 'Ceiling into a call to the floating-point attribute
1262 -- function Ceiling in Fat_xxx (where xxx is the root type)
1264 when Attribute_Ceiling =>
1265 Expand_Fpt_Attribute_R (N);
1271 -- Transforms 'Callable attribute into a call to the Callable function
1273 when Attribute_Callable => Callable :
1275 -- We have an object of a task interface class-wide type as a prefix
1276 -- to Callable. Generate:
1278 -- callable (Task_Id (Pref._disp_get_task_id));
1280 if Ada_Version >= Ada_05
1281 and then Ekind (Etype (Pref)) = E_Class_Wide_Type
1282 and then Is_Interface (Etype (Pref))
1283 and then Is_Task_Interface (Etype (Pref))
1286 Make_Function_Call (Loc,
1288 New_Reference_To (RTE (RE_Callable), Loc),
1289 Parameter_Associations => New_List (
1290 Make_Unchecked_Type_Conversion (Loc,
1292 New_Reference_To (RTE (RO_ST_Task_Id), Loc),
1294 Make_Selected_Component (Loc,
1296 New_Copy_Tree (Pref),
1298 Make_Identifier (Loc, Name_uDisp_Get_Task_Id))))));
1302 Build_Call_With_Task (Pref, RTE (RE_Callable)));
1305 Analyze_And_Resolve (N, Standard_Boolean);
1312 -- Transforms 'Caller attribute into a call to either the
1313 -- Task_Entry_Caller or the Protected_Entry_Caller function.
1315 when Attribute_Caller => Caller : declare
1316 Id_Kind : constant Entity_Id := RTE (RO_AT_Task_Id);
1317 Ent : constant Entity_Id := Entity (Pref);
1318 Conctype : constant Entity_Id := Scope (Ent);
1319 Nest_Depth : Integer := 0;
1326 if Is_Protected_Type (Conctype) then
1327 case Corresponding_Runtime_Package (Conctype) is
1328 when System_Tasking_Protected_Objects_Entries =>
1331 (RTE (RE_Protected_Entry_Caller), Loc);
1333 when System_Tasking_Protected_Objects_Single_Entry =>
1336 (RTE (RE_Protected_Single_Entry_Caller), Loc);
1339 raise Program_Error;
1343 Unchecked_Convert_To (Id_Kind,
1344 Make_Function_Call (Loc,
1346 Parameter_Associations => New_List
1349 (Corresponding_Body (Parent (Conctype))), Loc)))));
1354 -- Determine the nesting depth of the E'Caller attribute, that
1355 -- is, how many accept statements are nested within the accept
1356 -- statement for E at the point of E'Caller. The runtime uses
1357 -- this depth to find the specified entry call.
1359 for J in reverse 0 .. Scope_Stack.Last loop
1360 S := Scope_Stack.Table (J).Entity;
1362 -- We should not reach the scope of the entry, as it should
1363 -- already have been checked in Sem_Attr that this attribute
1364 -- reference is within a matching accept statement.
1366 pragma Assert (S /= Conctype);
1371 elsif Is_Entry (S) then
1372 Nest_Depth := Nest_Depth + 1;
1377 Unchecked_Convert_To (Id_Kind,
1378 Make_Function_Call (Loc,
1379 Name => New_Reference_To (
1380 RTE (RE_Task_Entry_Caller), Loc),
1381 Parameter_Associations => New_List (
1382 Make_Integer_Literal (Loc,
1383 Intval => Int (Nest_Depth))))));
1386 Analyze_And_Resolve (N, Id_Kind);
1393 -- Transforms 'Compose into a call to the floating-point attribute
1394 -- function Compose in Fat_xxx (where xxx is the root type)
1396 -- Note: we strictly should have special code here to deal with the
1397 -- case of absurdly negative arguments (less than Integer'First)
1398 -- which will return a (signed) zero value, but it hardly seems
1399 -- worth the effort. Absurdly large positive arguments will raise
1400 -- constraint error which is fine.
1402 when Attribute_Compose =>
1403 Expand_Fpt_Attribute_RI (N);
1409 when Attribute_Constrained => Constrained : declare
1410 Formal_Ent : constant Entity_Id := Param_Entity (Pref);
1411 Typ : constant Entity_Id := Etype (Pref);
1413 function Is_Constrained_Aliased_View (Obj : Node_Id) return Boolean;
1414 -- Ada 2005 (AI-363): Returns True if the object name Obj denotes a
1415 -- view of an aliased object whose subtype is constrained.
1417 ---------------------------------
1418 -- Is_Constrained_Aliased_View --
1419 ---------------------------------
1421 function Is_Constrained_Aliased_View (Obj : Node_Id) return Boolean is
1425 if Is_Entity_Name (Obj) then
1428 if Present (Renamed_Object (E)) then
1429 return Is_Constrained_Aliased_View (Renamed_Object (E));
1432 return Is_Aliased (E) and then Is_Constrained (Etype (E));
1436 return Is_Aliased_View (Obj)
1438 (Is_Constrained (Etype (Obj))
1439 or else (Nkind (Obj) = N_Explicit_Dereference
1441 not Has_Constrained_Partial_View
1442 (Base_Type (Etype (Obj)))));
1444 end Is_Constrained_Aliased_View;
1446 -- Start of processing for Constrained
1449 -- Reference to a parameter where the value is passed as an extra
1450 -- actual, corresponding to the extra formal referenced by the
1451 -- Extra_Constrained field of the corresponding formal. If this
1452 -- is an entry in-parameter, it is replaced by a constant renaming
1453 -- for which Extra_Constrained is never created.
1455 if Present (Formal_Ent)
1456 and then Ekind (Formal_Ent) /= E_Constant
1457 and then Present (Extra_Constrained (Formal_Ent))
1461 (Extra_Constrained (Formal_Ent), Sloc (N)));
1463 -- For variables with a Extra_Constrained field, we use the
1464 -- corresponding entity.
1466 elsif Nkind (Pref) = N_Identifier
1467 and then Ekind (Entity (Pref)) = E_Variable
1468 and then Present (Extra_Constrained (Entity (Pref)))
1472 (Extra_Constrained (Entity (Pref)), Sloc (N)));
1474 -- For all other entity names, we can tell at compile time
1476 elsif Is_Entity_Name (Pref) then
1478 Ent : constant Entity_Id := Entity (Pref);
1482 -- (RM J.4) obsolescent cases
1484 if Is_Type (Ent) then
1488 if Is_Private_Type (Ent) then
1489 Res := not Has_Discriminants (Ent)
1490 or else Is_Constrained (Ent);
1492 -- It not a private type, must be a generic actual type
1493 -- that corresponded to a private type. We know that this
1494 -- correspondence holds, since otherwise the reference
1495 -- within the generic template would have been illegal.
1498 if Is_Composite_Type (Underlying_Type (Ent)) then
1499 Res := Is_Constrained (Ent);
1505 -- If the prefix is not a variable or is aliased, then
1506 -- definitely true; if it's a formal parameter without
1507 -- an associated extra formal, then treat it as constrained.
1509 -- Ada 2005 (AI-363): An aliased prefix must be known to be
1510 -- constrained in order to set the attribute to True.
1512 elsif not Is_Variable (Pref)
1513 or else Present (Formal_Ent)
1514 or else (Ada_Version < Ada_05
1515 and then Is_Aliased_View (Pref))
1516 or else (Ada_Version >= Ada_05
1517 and then Is_Constrained_Aliased_View (Pref))
1521 -- Variable case, just look at type to see if it is
1522 -- constrained. Note that the one case where this is
1523 -- not accurate (the procedure formal case), has been
1526 -- We use the Underlying_Type here (and below) in case the
1527 -- type is private without discriminants, but the full type
1528 -- has discriminants. This case is illegal, but we generate it
1529 -- internally for passing to the Extra_Constrained parameter.
1532 Res := Is_Constrained (Underlying_Type (Etype (Ent)));
1536 New_Reference_To (Boolean_Literals (Res), Loc));
1539 -- Prefix is not an entity name. These are also cases where
1540 -- we can always tell at compile time by looking at the form
1541 -- and type of the prefix. If an explicit dereference of an
1542 -- object with constrained partial view, this is unconstrained
1543 -- (Ada 2005 AI-363).
1549 not Is_Variable (Pref)
1551 (Nkind (Pref) = N_Explicit_Dereference
1553 not Has_Constrained_Partial_View (Base_Type (Typ)))
1554 or else Is_Constrained (Underlying_Type (Typ))),
1558 Analyze_And_Resolve (N, Standard_Boolean);
1565 -- Transforms 'Copy_Sign into a call to the floating-point attribute
1566 -- function Copy_Sign in Fat_xxx (where xxx is the root type)
1568 when Attribute_Copy_Sign =>
1569 Expand_Fpt_Attribute_RR (N);
1575 -- Transforms 'Count attribute into a call to the Count function
1577 when Attribute_Count => Count :
1583 Conctyp : Entity_Id;
1586 -- If the prefix is a member of an entry family, retrieve both
1587 -- entry name and index. For a simple entry there is no index.
1589 if Nkind (Pref) = N_Indexed_Component then
1590 Entnam := Prefix (Pref);
1591 Index := First (Expressions (Pref));
1597 -- Find the concurrent type in which this attribute is referenced
1598 -- (there had better be one).
1600 Conctyp := Current_Scope;
1601 while not Is_Concurrent_Type (Conctyp) loop
1602 Conctyp := Scope (Conctyp);
1607 if Is_Protected_Type (Conctyp) then
1609 case Corresponding_Runtime_Package (Conctyp) is
1610 when System_Tasking_Protected_Objects_Entries =>
1611 Name := New_Reference_To (RTE (RE_Protected_Count), Loc);
1614 Make_Function_Call (Loc,
1616 Parameter_Associations => New_List (
1619 Corresponding_Body (Parent (Conctyp))), Loc),
1620 Entry_Index_Expression (Loc,
1621 Entity (Entnam), Index, Scope (Entity (Entnam)))));
1623 when System_Tasking_Protected_Objects_Single_Entry =>
1624 Name := New_Reference_To
1625 (RTE (RE_Protected_Count_Entry), Loc);
1628 Make_Function_Call (Loc,
1630 Parameter_Associations => New_List (
1633 Corresponding_Body (Parent (Conctyp))), Loc)));
1635 raise Program_Error;
1643 Make_Function_Call (Loc,
1644 Name => New_Reference_To (RTE (RE_Task_Count), Loc),
1645 Parameter_Associations => New_List (
1646 Entry_Index_Expression
1647 (Loc, Entity (Entnam), Index, Scope (Entity (Entnam)))));
1650 -- The call returns type Natural but the context is universal integer
1651 -- so any integer type is allowed. The attribute was already resolved
1652 -- so its Etype is the required result type. If the base type of the
1653 -- context type is other than Standard.Integer we put in a conversion
1654 -- to the required type. This can be a normal typed conversion since
1655 -- both input and output types of the conversion are integer types
1657 if Base_Type (Typ) /= Base_Type (Standard_Integer) then
1658 Rewrite (N, Convert_To (Typ, Call));
1663 Analyze_And_Resolve (N, Typ);
1670 -- This processing is shared by Elab_Spec
1672 -- What we do is to insert the following declarations
1675 -- pragma Import (C, enn, "name___elabb/s");
1677 -- and then the Elab_Body/Spec attribute is replaced by a reference
1678 -- to this defining identifier.
1680 when Attribute_Elab_Body |
1681 Attribute_Elab_Spec =>
1684 Ent : constant Entity_Id :=
1685 Make_Defining_Identifier (Loc,
1686 New_Internal_Name ('E'));
1690 procedure Make_Elab_String (Nod : Node_Id);
1691 -- Given Nod, an identifier, or a selected component, put the
1692 -- image into the current string literal, with double underline
1693 -- between components.
1695 ----------------------
1696 -- Make_Elab_String --
1697 ----------------------
1699 procedure Make_Elab_String (Nod : Node_Id) is
1701 if Nkind (Nod) = N_Selected_Component then
1702 Make_Elab_String (Prefix (Nod));
1706 Store_String_Char ('$');
1708 Store_String_Char ('.');
1710 Store_String_Char ('_');
1711 Store_String_Char ('_');
1714 Get_Name_String (Chars (Selector_Name (Nod)));
1717 pragma Assert (Nkind (Nod) = N_Identifier);
1718 Get_Name_String (Chars (Nod));
1721 Store_String_Chars (Name_Buffer (1 .. Name_Len));
1722 end Make_Elab_String;
1724 -- Start of processing for Elab_Body/Elab_Spec
1727 -- First we need to prepare the string literal for the name of
1728 -- the elaboration routine to be referenced.
1731 Make_Elab_String (Pref);
1733 if VM_Target = No_VM then
1734 Store_String_Chars ("___elab");
1735 Lang := Make_Identifier (Loc, Name_C);
1737 Store_String_Chars ("._elab");
1738 Lang := Make_Identifier (Loc, Name_Ada);
1741 if Id = Attribute_Elab_Body then
1742 Store_String_Char ('b');
1744 Store_String_Char ('s');
1749 Insert_Actions (N, New_List (
1750 Make_Subprogram_Declaration (Loc,
1752 Make_Procedure_Specification (Loc,
1753 Defining_Unit_Name => Ent)),
1756 Chars => Name_Import,
1757 Pragma_Argument_Associations => New_List (
1758 Make_Pragma_Argument_Association (Loc,
1759 Expression => Lang),
1761 Make_Pragma_Argument_Association (Loc,
1763 Make_Identifier (Loc, Chars (Ent))),
1765 Make_Pragma_Argument_Association (Loc,
1767 Make_String_Literal (Loc, Str))))));
1769 Set_Entity (N, Ent);
1770 Rewrite (N, New_Occurrence_Of (Ent, Loc));
1777 -- Elaborated is always True for preelaborated units, predefined
1778 -- units, pure units and units which have Elaborate_Body pragmas.
1779 -- These units have no elaboration entity.
1781 -- Note: The Elaborated attribute is never passed through to Gigi
1783 when Attribute_Elaborated => Elaborated : declare
1784 Ent : constant Entity_Id := Entity (Pref);
1787 if Present (Elaboration_Entity (Ent)) then
1789 New_Occurrence_Of (Elaboration_Entity (Ent), Loc));
1791 Rewrite (N, New_Occurrence_Of (Standard_True, Loc));
1799 when Attribute_Enum_Rep => Enum_Rep :
1801 -- X'Enum_Rep (Y) expands to
1805 -- This is simply a direct conversion from the enumeration type
1806 -- to the target integer type, which is treated by Gigi as a normal
1807 -- integer conversion, treating the enumeration type as an integer,
1808 -- which is exactly what we want! We set Conversion_OK to make sure
1809 -- that the analyzer does not complain about what otherwise might
1810 -- be an illegal conversion.
1812 if Is_Non_Empty_List (Exprs) then
1814 OK_Convert_To (Typ, Relocate_Node (First (Exprs))));
1816 -- X'Enum_Rep where X is an enumeration literal is replaced by
1817 -- the literal value.
1819 elsif Ekind (Entity (Pref)) = E_Enumeration_Literal then
1821 Make_Integer_Literal (Loc, Enumeration_Rep (Entity (Pref))));
1823 -- If this is a renaming of a literal, recover the representation
1826 elsif Ekind (Entity (Pref)) = E_Constant
1827 and then Present (Renamed_Object (Entity (Pref)))
1829 Ekind (Entity (Renamed_Object (Entity (Pref))))
1830 = E_Enumeration_Literal
1833 Make_Integer_Literal (Loc,
1834 Enumeration_Rep (Entity (Renamed_Object (Entity (Pref))))));
1836 -- X'Enum_Rep where X is an object does a direct unchecked conversion
1837 -- of the object value, as described for the type case above.
1841 OK_Convert_To (Typ, Relocate_Node (Pref)));
1845 Analyze_And_Resolve (N, Typ);
1853 -- Transforms 'Exponent into a call to the floating-point attribute
1854 -- function Exponent in Fat_xxx (where xxx is the root type)
1856 when Attribute_Exponent =>
1857 Expand_Fpt_Attribute_R (N);
1863 -- transforme X'External_Tag into Ada.Tags.External_Tag (X'tag)
1865 when Attribute_External_Tag => External_Tag :
1868 Make_Function_Call (Loc,
1869 Name => New_Reference_To (RTE (RE_External_Tag), Loc),
1870 Parameter_Associations => New_List (
1871 Make_Attribute_Reference (Loc,
1872 Attribute_Name => Name_Tag,
1873 Prefix => Prefix (N)))));
1875 Analyze_And_Resolve (N, Standard_String);
1882 when Attribute_First => declare
1883 Ptyp : constant Entity_Id := Etype (Pref);
1886 -- If the prefix type is a constrained packed array type which
1887 -- already has a Packed_Array_Type representation defined, then
1888 -- replace this attribute with a direct reference to 'First of the
1889 -- appropriate index subtype (since otherwise Gigi will try to give
1890 -- us the value of 'First for this implementation type).
1892 if Is_Constrained_Packed_Array (Ptyp) then
1894 Make_Attribute_Reference (Loc,
1895 Attribute_Name => Name_First,
1896 Prefix => New_Reference_To (Get_Index_Subtype (N), Loc)));
1897 Analyze_And_Resolve (N, Typ);
1899 elsif Is_Access_Type (Ptyp) then
1900 Apply_Access_Check (N);
1908 -- We compute this if a component clause was present, otherwise
1909 -- we leave the computation up to Gigi, since we don't know what
1910 -- layout will be chosen.
1912 when Attribute_First_Bit => First_Bit :
1914 CE : constant Entity_Id := Entity (Selector_Name (Pref));
1917 if Known_Static_Component_Bit_Offset (CE) then
1919 Make_Integer_Literal (Loc,
1920 Component_Bit_Offset (CE) mod System_Storage_Unit));
1922 Analyze_And_Resolve (N, Typ);
1925 Apply_Universal_Integer_Attribute_Checks (N);
1935 -- fixtype'Fixed_Value (integer-value)
1939 -- fixtype(integer-value)
1941 -- we do all the required analysis of the conversion here, because
1942 -- we do not want this to go through the fixed-point conversion
1943 -- circuits. Note that gigi always treats fixed-point as equivalent
1944 -- to the corresponding integer type anyway.
1946 when Attribute_Fixed_Value => Fixed_Value :
1949 Make_Type_Conversion (Loc,
1950 Subtype_Mark => New_Occurrence_Of (Entity (Pref), Loc),
1951 Expression => Relocate_Node (First (Exprs))));
1952 Set_Etype (N, Entity (Pref));
1955 -- Note: it might appear that a properly analyzed unchecked conversion
1956 -- would be just fine here, but that's not the case, since the full
1957 -- range checks performed by the following call are critical!
1959 Apply_Type_Conversion_Checks (N);
1966 -- Transforms 'Floor into a call to the floating-point attribute
1967 -- function Floor in Fat_xxx (where xxx is the root type)
1969 when Attribute_Floor =>
1970 Expand_Fpt_Attribute_R (N);
1976 -- For the fixed-point type Typ:
1982 -- Result_Type (System.Fore (Universal_Real (Type'First)),
1983 -- Universal_Real (Type'Last))
1985 -- Note that we know that the type is a non-static subtype, or Fore
1986 -- would have itself been computed dynamically in Eval_Attribute.
1988 when Attribute_Fore => Fore :
1990 Ptyp : constant Entity_Id := Etype (Pref);
1995 Make_Function_Call (Loc,
1996 Name => New_Reference_To (RTE (RE_Fore), Loc),
1998 Parameter_Associations => New_List (
1999 Convert_To (Universal_Real,
2000 Make_Attribute_Reference (Loc,
2001 Prefix => New_Reference_To (Ptyp, Loc),
2002 Attribute_Name => Name_First)),
2004 Convert_To (Universal_Real,
2005 Make_Attribute_Reference (Loc,
2006 Prefix => New_Reference_To (Ptyp, Loc),
2007 Attribute_Name => Name_Last))))));
2009 Analyze_And_Resolve (N, Typ);
2016 -- Transforms 'Fraction into a call to the floating-point attribute
2017 -- function Fraction in Fat_xxx (where xxx is the root type)
2019 when Attribute_Fraction =>
2020 Expand_Fpt_Attribute_R (N);
2026 -- For an exception returns a reference to the exception data:
2027 -- Exception_Id!(Prefix'Reference)
2029 -- For a task it returns a reference to the _task_id component of
2030 -- corresponding record:
2032 -- taskV!(Prefix)._Task_Id, converted to the type Task_Id defined
2034 -- in Ada.Task_Identification
2036 when Attribute_Identity => Identity : declare
2037 Id_Kind : Entity_Id;
2040 if Etype (Pref) = Standard_Exception_Type then
2041 Id_Kind := RTE (RE_Exception_Id);
2043 if Present (Renamed_Object (Entity (Pref))) then
2044 Set_Entity (Pref, Renamed_Object (Entity (Pref)));
2048 Unchecked_Convert_To (Id_Kind, Make_Reference (Loc, Pref)));
2050 Id_Kind := RTE (RO_AT_Task_Id);
2052 -- If the prefix is a task interface, the Task_Id is obtained
2053 -- dynamically through a dispatching call, as for other task
2054 -- attributes applied to interfaces.
2056 if Ada_Version >= Ada_05
2057 and then Ekind (Etype (Pref)) = E_Class_Wide_Type
2058 and then Is_Interface (Etype (Pref))
2059 and then Is_Task_Interface (Etype (Pref))
2062 Unchecked_Convert_To (Id_Kind,
2063 Make_Selected_Component (Loc,
2065 New_Copy_Tree (Pref),
2067 Make_Identifier (Loc, Name_uDisp_Get_Task_Id))));
2071 Unchecked_Convert_To (Id_Kind, Concurrent_Ref (Pref)));
2075 Analyze_And_Resolve (N, Id_Kind);
2082 -- Image attribute is handled in separate unit Exp_Imgv
2084 when Attribute_Image =>
2085 Exp_Imgv.Expand_Image_Attribute (N);
2091 -- X'Img is expanded to typ'Image (X), where typ is the type of X
2093 when Attribute_Img => Img :
2096 Make_Attribute_Reference (Loc,
2097 Prefix => New_Reference_To (Etype (Pref), Loc),
2098 Attribute_Name => Name_Image,
2099 Expressions => New_List (Relocate_Node (Pref))));
2101 Analyze_And_Resolve (N, Standard_String);
2108 when Attribute_Input => Input : declare
2109 P_Type : constant Entity_Id := Entity (Pref);
2110 B_Type : constant Entity_Id := Base_Type (P_Type);
2111 U_Type : constant Entity_Id := Underlying_Type (P_Type);
2112 Strm : constant Node_Id := First (Exprs);
2120 Cntrl : Node_Id := Empty;
2121 -- Value for controlling argument in call. Always Empty except in
2122 -- the dispatching (class-wide type) case, where it is a reference
2123 -- to the dummy object initialized to the right internal tag.
2125 procedure Freeze_Stream_Subprogram (F : Entity_Id);
2126 -- The expansion of the attribute reference may generate a call to
2127 -- a user-defined stream subprogram that is frozen by the call. This
2128 -- can lead to access-before-elaboration problem if the reference
2129 -- appears in an object declaration and the subprogram body has not
2130 -- been seen. The freezing of the subprogram requires special code
2131 -- because it appears in an expanded context where expressions do
2132 -- not freeze their constituents.
2134 ------------------------------
2135 -- Freeze_Stream_Subprogram --
2136 ------------------------------
2138 procedure Freeze_Stream_Subprogram (F : Entity_Id) is
2139 Decl : constant Node_Id := Unit_Declaration_Node (F);
2143 -- If this is user-defined subprogram, the corresponding
2144 -- stream function appears as a renaming-as-body, and the
2145 -- user subprogram must be retrieved by tree traversal.
2148 and then Nkind (Decl) = N_Subprogram_Declaration
2149 and then Present (Corresponding_Body (Decl))
2151 Bod := Corresponding_Body (Decl);
2153 if Nkind (Unit_Declaration_Node (Bod)) =
2154 N_Subprogram_Renaming_Declaration
2156 Set_Is_Frozen (Entity (Name (Unit_Declaration_Node (Bod))));
2159 end Freeze_Stream_Subprogram;
2161 -- Start of processing for Input
2164 -- If no underlying type, we have an error that will be diagnosed
2165 -- elsewhere, so here we just completely ignore the expansion.
2171 -- If there is a TSS for Input, just call it
2173 Fname := Find_Stream_Subprogram (P_Type, TSS_Stream_Input);
2175 if Present (Fname) then
2179 -- If there is a Stream_Convert pragma, use it, we rewrite
2181 -- sourcetyp'Input (stream)
2185 -- sourcetyp (streamread (strmtyp'Input (stream)));
2187 -- where stmrearead is the given Read function that converts
2188 -- an argument of type strmtyp to type sourcetyp or a type
2189 -- from which it is derived. The extra conversion is required
2190 -- for the derived case.
2192 Prag := Get_Stream_Convert_Pragma (P_Type);
2194 if Present (Prag) then
2195 Arg2 := Next (First (Pragma_Argument_Associations (Prag)));
2196 Rfunc := Entity (Expression (Arg2));
2200 Make_Function_Call (Loc,
2201 Name => New_Occurrence_Of (Rfunc, Loc),
2202 Parameter_Associations => New_List (
2203 Make_Attribute_Reference (Loc,
2206 (Etype (First_Formal (Rfunc)), Loc),
2207 Attribute_Name => Name_Input,
2208 Expressions => Exprs)))));
2210 Analyze_And_Resolve (N, B_Type);
2215 elsif Is_Elementary_Type (U_Type) then
2217 -- A special case arises if we have a defined _Read routine,
2218 -- since in this case we are required to call this routine.
2220 if Present (TSS (Base_Type (U_Type), TSS_Stream_Read)) then
2221 Build_Record_Or_Elementary_Input_Function
2222 (Loc, U_Type, Decl, Fname);
2223 Insert_Action (N, Decl);
2225 -- For normal cases, we call the I_xxx routine directly
2228 Rewrite (N, Build_Elementary_Input_Call (N));
2229 Analyze_And_Resolve (N, P_Type);
2235 elsif Is_Array_Type (U_Type) then
2236 Build_Array_Input_Function (Loc, U_Type, Decl, Fname);
2237 Compile_Stream_Body_In_Scope (N, Decl, U_Type, Check => False);
2239 -- Dispatching case with class-wide type
2241 elsif Is_Class_Wide_Type (P_Type) then
2243 -- No need to do anything else compiling under restriction
2244 -- No_Dispatching_Calls. During the semantic analysis we
2245 -- already notified such violation.
2247 if Restriction_Active (No_Dispatching_Calls) then
2252 Rtyp : constant Entity_Id := Root_Type (P_Type);
2257 -- Read the internal tag (RM 13.13.2(34)) and use it to
2258 -- initialize a dummy tag object:
2260 -- Dnn : Ada.Tags.Tag
2261 -- := Descendant_Tag (String'Input (Strm), P_Type);
2263 -- This dummy object is used only to provide a controlling
2264 -- argument for the eventual _Input call. Descendant_Tag is
2265 -- called rather than Internal_Tag to ensure that we have a
2266 -- tag for a type that is descended from the prefix type and
2267 -- declared at the same accessibility level (the exception
2268 -- Tag_Error will be raised otherwise). The level check is
2269 -- required for Ada 2005 because tagged types can be
2270 -- extended in nested scopes (AI-344).
2273 Make_Defining_Identifier (Loc,
2274 Chars => New_Internal_Name ('D'));
2277 Make_Object_Declaration (Loc,
2278 Defining_Identifier => Dnn,
2279 Object_Definition =>
2280 New_Occurrence_Of (RTE (RE_Tag), Loc),
2282 Make_Function_Call (Loc,
2284 New_Occurrence_Of (RTE (RE_Descendant_Tag), Loc),
2285 Parameter_Associations => New_List (
2286 Make_Attribute_Reference (Loc,
2288 New_Occurrence_Of (Standard_String, Loc),
2289 Attribute_Name => Name_Input,
2290 Expressions => New_List (
2292 (Duplicate_Subexpr (Strm)))),
2293 Make_Attribute_Reference (Loc,
2294 Prefix => New_Reference_To (P_Type, Loc),
2295 Attribute_Name => Name_Tag))));
2297 Insert_Action (N, Decl);
2299 -- Now we need to get the entity for the call, and construct
2300 -- a function call node, where we preset a reference to Dnn
2301 -- as the controlling argument (doing an unchecked convert
2302 -- to the class-wide tagged type to make it look like a real
2305 Fname := Find_Prim_Op (Rtyp, TSS_Stream_Input);
2306 Cntrl := Unchecked_Convert_To (P_Type,
2307 New_Occurrence_Of (Dnn, Loc));
2308 Set_Etype (Cntrl, P_Type);
2309 Set_Parent (Cntrl, N);
2312 -- For tagged types, use the primitive Input function
2314 elsif Is_Tagged_Type (U_Type) then
2315 Fname := Find_Prim_Op (U_Type, TSS_Stream_Input);
2317 -- All other record type cases, including protected records. The
2318 -- latter only arise for expander generated code for handling
2319 -- shared passive partition access.
2323 (Is_Record_Type (U_Type) or else Is_Protected_Type (U_Type));
2325 -- Ada 2005 (AI-216): Program_Error is raised when executing
2326 -- the default implementation of the Input attribute of an
2327 -- unchecked union type if the type lacks default discriminant
2330 if Is_Unchecked_Union (Base_Type (U_Type))
2331 and then No (Discriminant_Constraint (U_Type))
2334 Make_Raise_Program_Error (Loc,
2335 Reason => PE_Unchecked_Union_Restriction));
2340 Build_Record_Or_Elementary_Input_Function
2341 (Loc, Base_Type (U_Type), Decl, Fname);
2342 Insert_Action (N, Decl);
2344 if Nkind (Parent (N)) = N_Object_Declaration
2345 and then Is_Record_Type (U_Type)
2347 -- The stream function may contain calls to user-defined
2348 -- Read procedures for individual components.
2355 Comp := First_Component (U_Type);
2356 while Present (Comp) loop
2358 Find_Stream_Subprogram
2359 (Etype (Comp), TSS_Stream_Read);
2361 if Present (Func) then
2362 Freeze_Stream_Subprogram (Func);
2365 Next_Component (Comp);
2372 -- If we fall through, Fname is the function to be called. The result
2373 -- is obtained by calling the appropriate function, then converting
2374 -- the result. The conversion does a subtype check.
2377 Make_Function_Call (Loc,
2378 Name => New_Occurrence_Of (Fname, Loc),
2379 Parameter_Associations => New_List (
2380 Relocate_Node (Strm)));
2382 Set_Controlling_Argument (Call, Cntrl);
2383 Rewrite (N, Unchecked_Convert_To (P_Type, Call));
2384 Analyze_And_Resolve (N, P_Type);
2386 if Nkind (Parent (N)) = N_Object_Declaration then
2387 Freeze_Stream_Subprogram (Fname);
2397 -- inttype'Fixed_Value (fixed-value)
2401 -- inttype(integer-value))
2403 -- we do all the required analysis of the conversion here, because
2404 -- we do not want this to go through the fixed-point conversion
2405 -- circuits. Note that gigi always treats fixed-point as equivalent
2406 -- to the corresponding integer type anyway.
2408 when Attribute_Integer_Value => Integer_Value :
2411 Make_Type_Conversion (Loc,
2412 Subtype_Mark => New_Occurrence_Of (Entity (Pref), Loc),
2413 Expression => Relocate_Node (First (Exprs))));
2414 Set_Etype (N, Entity (Pref));
2417 -- Note: it might appear that a properly analyzed unchecked conversion
2418 -- would be just fine here, but that's not the case, since the full
2419 -- range checks performed by the following call are critical!
2421 Apply_Type_Conversion_Checks (N);
2428 when Attribute_Last => declare
2429 Ptyp : constant Entity_Id := Etype (Pref);
2432 -- If the prefix type is a constrained packed array type which
2433 -- already has a Packed_Array_Type representation defined, then
2434 -- replace this attribute with a direct reference to 'Last of the
2435 -- appropriate index subtype (since otherwise Gigi will try to give
2436 -- us the value of 'Last for this implementation type).
2438 if Is_Constrained_Packed_Array (Ptyp) then
2440 Make_Attribute_Reference (Loc,
2441 Attribute_Name => Name_Last,
2442 Prefix => New_Reference_To (Get_Index_Subtype (N), Loc)));
2443 Analyze_And_Resolve (N, Typ);
2445 elsif Is_Access_Type (Ptyp) then
2446 Apply_Access_Check (N);
2454 -- We compute this if a component clause was present, otherwise
2455 -- we leave the computation up to Gigi, since we don't know what
2456 -- layout will be chosen.
2458 when Attribute_Last_Bit => Last_Bit :
2460 CE : constant Entity_Id := Entity (Selector_Name (Pref));
2463 if Known_Static_Component_Bit_Offset (CE)
2464 and then Known_Static_Esize (CE)
2467 Make_Integer_Literal (Loc,
2468 Intval => (Component_Bit_Offset (CE) mod System_Storage_Unit)
2471 Analyze_And_Resolve (N, Typ);
2474 Apply_Universal_Integer_Attribute_Checks (N);
2482 -- Transforms 'Leading_Part into a call to the floating-point attribute
2483 -- function Leading_Part in Fat_xxx (where xxx is the root type)
2485 -- Note: strictly, we should have special case code to deal with
2486 -- absurdly large positive arguments (greater than Integer'Last), which
2487 -- result in returning the first argument unchanged, but it hardly seems
2488 -- worth the effort. We raise constraint error for absurdly negative
2489 -- arguments which is fine.
2491 when Attribute_Leading_Part =>
2492 Expand_Fpt_Attribute_RI (N);
2498 when Attribute_Length => declare
2499 Ptyp : constant Entity_Id := Etype (Pref);
2504 -- Processing for packed array types
2506 if Is_Array_Type (Ptyp) and then Is_Packed (Ptyp) then
2507 Ityp := Get_Index_Subtype (N);
2509 -- If the index type, Ityp, is an enumeration type with
2510 -- holes, then we calculate X'Length explicitly using
2513 -- (0, Ityp'Pos (X'Last (N)) -
2514 -- Ityp'Pos (X'First (N)) + 1);
2516 -- Since the bounds in the template are the representation
2517 -- values and gigi would get the wrong value.
2519 if Is_Enumeration_Type (Ityp)
2520 and then Present (Enum_Pos_To_Rep (Base_Type (Ityp)))
2525 Xnum := Expr_Value (First (Expressions (N)));
2529 Make_Attribute_Reference (Loc,
2530 Prefix => New_Occurrence_Of (Typ, Loc),
2531 Attribute_Name => Name_Max,
2532 Expressions => New_List
2533 (Make_Integer_Literal (Loc, 0),
2537 Make_Op_Subtract (Loc,
2539 Make_Attribute_Reference (Loc,
2540 Prefix => New_Occurrence_Of (Ityp, Loc),
2541 Attribute_Name => Name_Pos,
2543 Expressions => New_List (
2544 Make_Attribute_Reference (Loc,
2545 Prefix => Duplicate_Subexpr (Pref),
2546 Attribute_Name => Name_Last,
2547 Expressions => New_List (
2548 Make_Integer_Literal (Loc, Xnum))))),
2551 Make_Attribute_Reference (Loc,
2552 Prefix => New_Occurrence_Of (Ityp, Loc),
2553 Attribute_Name => Name_Pos,
2555 Expressions => New_List (
2556 Make_Attribute_Reference (Loc,
2558 Duplicate_Subexpr_No_Checks (Pref),
2559 Attribute_Name => Name_First,
2560 Expressions => New_List (
2561 Make_Integer_Literal (Loc, Xnum)))))),
2563 Right_Opnd => Make_Integer_Literal (Loc, 1)))));
2565 Analyze_And_Resolve (N, Typ, Suppress => All_Checks);
2568 -- If the prefix type is a constrained packed array type which
2569 -- already has a Packed_Array_Type representation defined, then
2570 -- replace this attribute with a direct reference to 'Range_Length
2571 -- of the appropriate index subtype (since otherwise Gigi will try
2572 -- to give us the value of 'Length for this implementation type).
2574 elsif Is_Constrained (Ptyp) then
2576 Make_Attribute_Reference (Loc,
2577 Attribute_Name => Name_Range_Length,
2578 Prefix => New_Reference_To (Ityp, Loc)));
2579 Analyze_And_Resolve (N, Typ);
2582 -- If we have a packed array that is not bit packed, which was
2586 elsif Is_Access_Type (Ptyp) then
2587 Apply_Access_Check (N);
2589 -- If the designated type is a packed array type, then we
2590 -- convert the reference to:
2593 -- xtyp'Pos (Pref'Last (Expr)) -
2594 -- xtyp'Pos (Pref'First (Expr)));
2596 -- This is a bit complex, but it is the easiest thing to do
2597 -- that works in all cases including enum types with holes
2598 -- xtyp here is the appropriate index type.
2601 Dtyp : constant Entity_Id := Designated_Type (Ptyp);
2605 if Is_Array_Type (Dtyp) and then Is_Packed (Dtyp) then
2606 Xtyp := Get_Index_Subtype (N);
2609 Make_Attribute_Reference (Loc,
2610 Prefix => New_Occurrence_Of (Typ, Loc),
2611 Attribute_Name => Name_Max,
2612 Expressions => New_List (
2613 Make_Integer_Literal (Loc, 0),
2616 Make_Integer_Literal (Loc, 1),
2617 Make_Op_Subtract (Loc,
2619 Make_Attribute_Reference (Loc,
2620 Prefix => New_Occurrence_Of (Xtyp, Loc),
2621 Attribute_Name => Name_Pos,
2622 Expressions => New_List (
2623 Make_Attribute_Reference (Loc,
2624 Prefix => Duplicate_Subexpr (Pref),
2625 Attribute_Name => Name_Last,
2627 New_Copy_List (Exprs)))),
2630 Make_Attribute_Reference (Loc,
2631 Prefix => New_Occurrence_Of (Xtyp, Loc),
2632 Attribute_Name => Name_Pos,
2633 Expressions => New_List (
2634 Make_Attribute_Reference (Loc,
2636 Duplicate_Subexpr_No_Checks (Pref),
2637 Attribute_Name => Name_First,
2639 New_Copy_List (Exprs)))))))));
2641 Analyze_And_Resolve (N, Typ);
2645 -- Otherwise leave it to gigi
2648 Apply_Universal_Integer_Attribute_Checks (N);
2656 -- Transforms 'Machine into a call to the floating-point attribute
2657 -- function Machine in Fat_xxx (where xxx is the root type)
2659 when Attribute_Machine =>
2660 Expand_Fpt_Attribute_R (N);
2662 ----------------------
2663 -- Machine_Rounding --
2664 ----------------------
2666 -- Transforms 'Machine_Rounding into a call to the floating-point
2667 -- attribute function Machine_Rounding in Fat_xxx (where xxx is the root
2668 -- type). Expansion is avoided for cases the back end can handle
2671 when Attribute_Machine_Rounding =>
2672 if not Is_Inline_Floating_Point_Attribute (N) then
2673 Expand_Fpt_Attribute_R (N);
2680 -- Machine_Size is equivalent to Object_Size, so transform it into
2681 -- Object_Size and that way Gigi never sees Machine_Size.
2683 when Attribute_Machine_Size =>
2685 Make_Attribute_Reference (Loc,
2686 Prefix => Prefix (N),
2687 Attribute_Name => Name_Object_Size));
2689 Analyze_And_Resolve (N, Typ);
2695 -- The only case that can get this far is the dynamic case of the old
2696 -- Ada 83 Mantissa attribute for the fixed-point case. For this case, we
2703 -- ityp (System.Mantissa.Mantissa_Value
2704 -- (Integer'Integer_Value (typ'First),
2705 -- Integer'Integer_Value (typ'Last)));
2707 when Attribute_Mantissa => Mantissa : declare
2708 Ptyp : constant Entity_Id := Etype (Pref);
2713 Make_Function_Call (Loc,
2714 Name => New_Occurrence_Of (RTE (RE_Mantissa_Value), Loc),
2716 Parameter_Associations => New_List (
2718 Make_Attribute_Reference (Loc,
2719 Prefix => New_Occurrence_Of (Standard_Integer, Loc),
2720 Attribute_Name => Name_Integer_Value,
2721 Expressions => New_List (
2723 Make_Attribute_Reference (Loc,
2724 Prefix => New_Occurrence_Of (Ptyp, Loc),
2725 Attribute_Name => Name_First))),
2727 Make_Attribute_Reference (Loc,
2728 Prefix => New_Occurrence_Of (Standard_Integer, Loc),
2729 Attribute_Name => Name_Integer_Value,
2730 Expressions => New_List (
2732 Make_Attribute_Reference (Loc,
2733 Prefix => New_Occurrence_Of (Ptyp, Loc),
2734 Attribute_Name => Name_Last)))))));
2736 Analyze_And_Resolve (N, Typ);
2739 --------------------
2740 -- Mechanism_Code --
2741 --------------------
2743 when Attribute_Mechanism_Code =>
2745 -- We must replace the prefix in the renamed case
2747 if Is_Entity_Name (Pref)
2748 and then Present (Alias (Entity (Pref)))
2750 Set_Renamed_Subprogram (Pref, Alias (Entity (Pref)));
2757 when Attribute_Mod => Mod_Case : declare
2758 Arg : constant Node_Id := Relocate_Node (First (Exprs));
2759 Hi : constant Node_Id := Type_High_Bound (Etype (Arg));
2760 Modv : constant Uint := Modulus (Btyp);
2764 -- This is not so simple. The issue is what type to use for the
2765 -- computation of the modular value.
2767 -- The easy case is when the modulus value is within the bounds
2768 -- of the signed integer type of the argument. In this case we can
2769 -- just do the computation in that signed integer type, and then
2770 -- do an ordinary conversion to the target type.
2772 if Modv <= Expr_Value (Hi) then
2777 Right_Opnd => Make_Integer_Literal (Loc, Modv))));
2779 -- Here we know that the modulus is larger than type'Last of the
2780 -- integer type. There are two cases to consider:
2782 -- a) The integer value is non-negative. In this case, it is
2783 -- returned as the result (since it is less than the modulus).
2785 -- b) The integer value is negative. In this case, we know that the
2786 -- result is modulus + value, where the value might be as small as
2787 -- -modulus. The trouble is what type do we use to do the subtract.
2788 -- No type will do, since modulus can be as big as 2**64, and no
2789 -- integer type accomodates this value. Let's do bit of algebra
2792 -- = modulus - (-value)
2793 -- = (modulus - 1) - (-value - 1)
2795 -- Now modulus - 1 is certainly in range of the modular type.
2796 -- -value is in the range 1 .. modulus, so -value -1 is in the
2797 -- range 0 .. modulus-1 which is in range of the modular type.
2798 -- Furthermore, (-value - 1) can be expressed as -(value + 1)
2799 -- which we can compute using the integer base type.
2801 -- Once this is done we analyze the conditional expression without
2802 -- range checks, because we know everything is in range, and we
2803 -- want to prevent spurious warnings on either branch.
2807 Make_Conditional_Expression (Loc,
2808 Expressions => New_List (
2810 Left_Opnd => Duplicate_Subexpr (Arg),
2811 Right_Opnd => Make_Integer_Literal (Loc, 0)),
2814 Duplicate_Subexpr_No_Checks (Arg)),
2816 Make_Op_Subtract (Loc,
2818 Make_Integer_Literal (Loc,
2819 Intval => Modv - 1),
2825 Left_Opnd => Duplicate_Subexpr_No_Checks (Arg),
2827 Make_Integer_Literal (Loc,
2828 Intval => 1))))))));
2832 Analyze_And_Resolve (N, Btyp, Suppress => All_Checks);
2839 -- Transforms 'Model into a call to the floating-point attribute
2840 -- function Model in Fat_xxx (where xxx is the root type)
2842 when Attribute_Model =>
2843 Expand_Fpt_Attribute_R (N);
2849 -- The processing for Object_Size shares the processing for Size
2855 when Attribute_Old => Old : declare
2856 Tnn : constant Entity_Id :=
2857 Make_Defining_Identifier (Loc,
2858 Chars => New_Internal_Name ('T'));
2865 Subp := Parent (Subp);
2866 exit when Nkind (Subp) = N_Subprogram_Body;
2870 Make_Object_Declaration (Loc,
2871 Defining_Identifier => Tnn,
2872 Constant_Present => True,
2873 Object_Definition => New_Occurrence_Of (Etype (N), Loc),
2874 Expression => Pref);
2876 if Is_Empty_List (Declarations (Subp)) then
2877 Set_Declarations (Subp, New_List (Asn_Stm));
2880 Insert_Action (First (Declarations (Subp)), Asn_Stm);
2883 Rewrite (N, New_Occurrence_Of (Tnn, Loc));
2890 when Attribute_Output => Output : declare
2891 P_Type : constant Entity_Id := Entity (Pref);
2892 U_Type : constant Entity_Id := Underlying_Type (P_Type);
2900 -- If no underlying type, we have an error that will be diagnosed
2901 -- elsewhere, so here we just completely ignore the expansion.
2907 -- If TSS for Output is present, just call it
2909 Pname := Find_Stream_Subprogram (P_Type, TSS_Stream_Output);
2911 if Present (Pname) then
2915 -- If there is a Stream_Convert pragma, use it, we rewrite
2917 -- sourcetyp'Output (stream, Item)
2921 -- strmtyp'Output (Stream, strmwrite (acttyp (Item)));
2923 -- where strmwrite is the given Write function that converts an
2924 -- argument of type sourcetyp or a type acctyp, from which it is
2925 -- derived to type strmtyp. The conversion to acttyp is required
2926 -- for the derived case.
2928 Prag := Get_Stream_Convert_Pragma (P_Type);
2930 if Present (Prag) then
2932 Next (Next (First (Pragma_Argument_Associations (Prag))));
2933 Wfunc := Entity (Expression (Arg3));
2936 Make_Attribute_Reference (Loc,
2937 Prefix => New_Occurrence_Of (Etype (Wfunc), Loc),
2938 Attribute_Name => Name_Output,
2939 Expressions => New_List (
2940 Relocate_Node (First (Exprs)),
2941 Make_Function_Call (Loc,
2942 Name => New_Occurrence_Of (Wfunc, Loc),
2943 Parameter_Associations => New_List (
2944 OK_Convert_To (Etype (First_Formal (Wfunc)),
2945 Relocate_Node (Next (First (Exprs)))))))));
2950 -- For elementary types, we call the W_xxx routine directly.
2951 -- Note that the effect of Write and Output is identical for
2952 -- the case of an elementary type, since there are no
2953 -- discriminants or bounds.
2955 elsif Is_Elementary_Type (U_Type) then
2957 -- A special case arises if we have a defined _Write routine,
2958 -- since in this case we are required to call this routine.
2960 if Present (TSS (Base_Type (U_Type), TSS_Stream_Write)) then
2961 Build_Record_Or_Elementary_Output_Procedure
2962 (Loc, U_Type, Decl, Pname);
2963 Insert_Action (N, Decl);
2965 -- For normal cases, we call the W_xxx routine directly
2968 Rewrite (N, Build_Elementary_Write_Call (N));
2975 elsif Is_Array_Type (U_Type) then
2976 Build_Array_Output_Procedure (Loc, U_Type, Decl, Pname);
2977 Compile_Stream_Body_In_Scope (N, Decl, U_Type, Check => False);
2979 -- Class-wide case, first output external tag, then dispatch
2980 -- to the appropriate primitive Output function (RM 13.13.2(31)).
2982 elsif Is_Class_Wide_Type (P_Type) then
2984 -- No need to do anything else compiling under restriction
2985 -- No_Dispatching_Calls. During the semantic analysis we
2986 -- already notified such violation.
2988 if Restriction_Active (No_Dispatching_Calls) then
2993 Strm : constant Node_Id := First (Exprs);
2994 Item : constant Node_Id := Next (Strm);
2997 -- Ada 2005 (AI-344): Check that the accessibility level
2998 -- of the type of the output object is not deeper than
2999 -- that of the attribute's prefix type.
3001 -- if Get_Access_Level (Item'Tag)
3002 -- /= Get_Access_Level (P_Type'Tag)
3007 -- String'Output (Strm, External_Tag (Item'Tag));
3009 -- We cannot figure out a practical way to implement this
3010 -- accessibility check on virtual machines, so we omit it.
3012 if Ada_Version >= Ada_05
3013 and then VM_Target = No_VM
3016 Make_Implicit_If_Statement (N,
3020 Build_Get_Access_Level (Loc,
3021 Make_Attribute_Reference (Loc,
3024 Duplicate_Subexpr (Item,
3026 Attribute_Name => Name_Tag)),
3029 Make_Integer_Literal (Loc,
3030 Type_Access_Level (P_Type))),
3033 New_List (Make_Raise_Statement (Loc,
3035 RTE (RE_Tag_Error), Loc)))));
3039 Make_Attribute_Reference (Loc,
3040 Prefix => New_Occurrence_Of (Standard_String, Loc),
3041 Attribute_Name => Name_Output,
3042 Expressions => New_List (
3043 Relocate_Node (Duplicate_Subexpr (Strm)),
3044 Make_Function_Call (Loc,
3046 New_Occurrence_Of (RTE (RE_External_Tag), Loc),
3047 Parameter_Associations => New_List (
3048 Make_Attribute_Reference (Loc,
3051 (Duplicate_Subexpr (Item, Name_Req => True)),
3052 Attribute_Name => Name_Tag))))));
3055 Pname := Find_Prim_Op (U_Type, TSS_Stream_Output);
3057 -- Tagged type case, use the primitive Output function
3059 elsif Is_Tagged_Type (U_Type) then
3060 Pname := Find_Prim_Op (U_Type, TSS_Stream_Output);
3062 -- All other record type cases, including protected records.
3063 -- The latter only arise for expander generated code for
3064 -- handling shared passive partition access.
3068 (Is_Record_Type (U_Type) or else Is_Protected_Type (U_Type));
3070 -- Ada 2005 (AI-216): Program_Error is raised when executing
3071 -- the default implementation of the Output attribute of an
3072 -- unchecked union type if the type lacks default discriminant
3075 if Is_Unchecked_Union (Base_Type (U_Type))
3076 and then No (Discriminant_Constraint (U_Type))
3079 Make_Raise_Program_Error (Loc,
3080 Reason => PE_Unchecked_Union_Restriction));
3085 Build_Record_Or_Elementary_Output_Procedure
3086 (Loc, Base_Type (U_Type), Decl, Pname);
3087 Insert_Action (N, Decl);
3091 -- If we fall through, Pname is the name of the procedure to call
3093 Rewrite_Stream_Proc_Call (Pname);
3100 -- For enumeration types with a standard representation, Pos is
3103 -- For enumeration types, with a non-standard representation we
3104 -- generate a call to the _Rep_To_Pos function created when the
3105 -- type was frozen. The call has the form
3107 -- _rep_to_pos (expr, flag)
3109 -- The parameter flag is True if range checks are enabled, causing
3110 -- Program_Error to be raised if the expression has an invalid
3111 -- representation, and False if range checks are suppressed.
3113 -- For integer types, Pos is equivalent to a simple integer
3114 -- conversion and we rewrite it as such
3116 when Attribute_Pos => Pos :
3118 Etyp : Entity_Id := Base_Type (Entity (Pref));
3121 -- Deal with zero/non-zero boolean values
3123 if Is_Boolean_Type (Etyp) then
3124 Adjust_Condition (First (Exprs));
3125 Etyp := Standard_Boolean;
3126 Set_Prefix (N, New_Occurrence_Of (Standard_Boolean, Loc));
3129 -- Case of enumeration type
3131 if Is_Enumeration_Type (Etyp) then
3133 -- Non-standard enumeration type (generate call)
3135 if Present (Enum_Pos_To_Rep (Etyp)) then
3136 Append_To (Exprs, Rep_To_Pos_Flag (Etyp, Loc));
3139 Make_Function_Call (Loc,
3141 New_Reference_To (TSS (Etyp, TSS_Rep_To_Pos), Loc),
3142 Parameter_Associations => Exprs)));
3144 Analyze_And_Resolve (N, Typ);
3146 -- Standard enumeration type (do universal integer check)
3149 Apply_Universal_Integer_Attribute_Checks (N);
3152 -- Deal with integer types (replace by conversion)
3154 elsif Is_Integer_Type (Etyp) then
3155 Rewrite (N, Convert_To (Typ, First (Exprs)));
3156 Analyze_And_Resolve (N, Typ);
3165 -- We compute this if a component clause was present, otherwise
3166 -- we leave the computation up to Gigi, since we don't know what
3167 -- layout will be chosen.
3169 when Attribute_Position => Position :
3171 CE : constant Entity_Id := Entity (Selector_Name (Pref));
3174 if Present (Component_Clause (CE)) then
3176 Make_Integer_Literal (Loc,
3177 Intval => Component_Bit_Offset (CE) / System_Storage_Unit));
3178 Analyze_And_Resolve (N, Typ);
3181 Apply_Universal_Integer_Attribute_Checks (N);
3189 -- 1. Deal with enumeration types with holes
3190 -- 2. For floating-point, generate call to attribute function
3191 -- 3. For other cases, deal with constraint checking
3193 when Attribute_Pred => Pred :
3195 Ptyp : constant Entity_Id := Base_Type (Etype (Pref));
3198 -- For enumeration types with non-standard representations, we
3199 -- expand typ'Pred (x) into
3201 -- Pos_To_Rep (Rep_To_Pos (x) - 1)
3203 -- If the representation is contiguous, we compute instead
3204 -- Lit1 + Rep_to_Pos (x -1), to catch invalid representations.
3206 if Is_Enumeration_Type (Ptyp)
3207 and then Present (Enum_Pos_To_Rep (Ptyp))
3209 if Has_Contiguous_Rep (Ptyp) then
3211 Unchecked_Convert_To (Ptyp,
3214 Make_Integer_Literal (Loc,
3215 Enumeration_Rep (First_Literal (Ptyp))),
3217 Make_Function_Call (Loc,
3220 (TSS (Ptyp, TSS_Rep_To_Pos), Loc),
3222 Parameter_Associations =>
3224 Unchecked_Convert_To (Ptyp,
3225 Make_Op_Subtract (Loc,
3227 Unchecked_Convert_To (Standard_Integer,
3228 Relocate_Node (First (Exprs))),
3230 Make_Integer_Literal (Loc, 1))),
3231 Rep_To_Pos_Flag (Ptyp, Loc))))));
3234 -- Add Boolean parameter True, to request program errror if
3235 -- we have a bad representation on our hands. If checks are
3236 -- suppressed, then add False instead
3238 Append_To (Exprs, Rep_To_Pos_Flag (Ptyp, Loc));
3240 Make_Indexed_Component (Loc,
3241 Prefix => New_Reference_To (Enum_Pos_To_Rep (Ptyp), Loc),
3242 Expressions => New_List (
3243 Make_Op_Subtract (Loc,
3245 Make_Function_Call (Loc,
3247 New_Reference_To (TSS (Ptyp, TSS_Rep_To_Pos), Loc),
3248 Parameter_Associations => Exprs),
3249 Right_Opnd => Make_Integer_Literal (Loc, 1)))));
3252 Analyze_And_Resolve (N, Typ);
3254 -- For floating-point, we transform 'Pred into a call to the Pred
3255 -- floating-point attribute function in Fat_xxx (xxx is root type)
3257 elsif Is_Floating_Point_Type (Ptyp) then
3258 Expand_Fpt_Attribute_R (N);
3259 Analyze_And_Resolve (N, Typ);
3261 -- For modular types, nothing to do (no overflow, since wraps)
3263 elsif Is_Modular_Integer_Type (Ptyp) then
3266 -- For other types, if range checking is enabled, we must generate
3267 -- a check if overflow checking is enabled.
3269 elsif not Overflow_Checks_Suppressed (Ptyp) then
3270 Expand_Pred_Succ (N);
3278 -- Ada 2005 (AI-327): Dynamic ceiling priorities
3280 -- We rewrite X'Priority as the following run-time call:
3282 -- Get_Ceiling (X._Object)
3284 -- Note that although X'Priority is notionally an object, it is quite
3285 -- deliberately not defined as an aliased object in the RM. This means
3286 -- that it works fine to rewrite it as a call, without having to worry
3287 -- about complications that would other arise from X'Priority'Access,
3288 -- which is illegal, because of the lack of aliasing.
3290 when Attribute_Priority =>
3293 Conctyp : Entity_Id;
3294 Object_Parm : Node_Id;
3296 RT_Subprg_Name : Node_Id;
3299 -- Look for the enclosing concurrent type
3301 Conctyp := Current_Scope;
3302 while not Is_Concurrent_Type (Conctyp) loop
3303 Conctyp := Scope (Conctyp);
3306 pragma Assert (Is_Protected_Type (Conctyp));
3308 -- Generate the actual of the call
3310 Subprg := Current_Scope;
3311 while not Present (Protected_Body_Subprogram (Subprg)) loop
3312 Subprg := Scope (Subprg);
3315 -- Use of 'Priority inside protected entries and barriers (in
3316 -- both cases the type of the first formal of their expanded
3317 -- subprogram is Address)
3319 if Etype (First_Entity (Protected_Body_Subprogram (Subprg)))
3323 New_Itype : Entity_Id;
3326 -- In the expansion of protected entries the type of the
3327 -- first formal of the Protected_Body_Subprogram is an
3328 -- Address. In order to reference the _object component
3331 -- type T is access p__ptTV;
3334 New_Itype := Create_Itype (E_Access_Type, N);
3335 Set_Etype (New_Itype, New_Itype);
3336 Init_Esize (New_Itype);
3337 Init_Size_Align (New_Itype);
3338 Set_Directly_Designated_Type (New_Itype,
3339 Corresponding_Record_Type (Conctyp));
3340 Freeze_Itype (New_Itype, N);
3343 -- T!(O)._object'unchecked_access
3346 Make_Attribute_Reference (Loc,
3348 Make_Selected_Component (Loc,
3350 Unchecked_Convert_To (New_Itype,
3353 (Protected_Body_Subprogram (Subprg)),
3356 Make_Identifier (Loc, Name_uObject)),
3357 Attribute_Name => Name_Unchecked_Access);
3360 -- Use of 'Priority inside a protected subprogram
3364 Make_Attribute_Reference (Loc,
3366 Make_Selected_Component (Loc,
3367 Prefix => New_Reference_To
3369 (Protected_Body_Subprogram (Subprg)),
3372 Make_Identifier (Loc, Name_uObject)),
3373 Attribute_Name => Name_Unchecked_Access);
3376 -- Select the appropriate run-time subprogram
3378 if Number_Entries (Conctyp) = 0 then
3380 New_Reference_To (RTE (RE_Get_Ceiling), Loc);
3383 New_Reference_To (RTE (RO_PE_Get_Ceiling), Loc);
3387 Make_Function_Call (Loc,
3388 Name => RT_Subprg_Name,
3389 Parameter_Associations => New_List (Object_Parm));
3393 -- Avoid the generation of extra checks on the pointer to the
3394 -- protected object.
3396 Analyze_And_Resolve (N, Typ, Suppress => Access_Check);
3403 when Attribute_Range_Length => Range_Length : declare
3404 P_Type : constant Entity_Id := Etype (Pref);
3407 -- The only special processing required is for the case where
3408 -- Range_Length is applied to an enumeration type with holes.
3409 -- In this case we transform
3415 -- X'Pos (X'Last) - X'Pos (X'First) + 1
3417 -- So that the result reflects the proper Pos values instead
3418 -- of the underlying representations.
3420 if Is_Enumeration_Type (P_Type)
3421 and then Has_Non_Standard_Rep (P_Type)
3426 Make_Op_Subtract (Loc,
3428 Make_Attribute_Reference (Loc,
3429 Attribute_Name => Name_Pos,
3430 Prefix => New_Occurrence_Of (P_Type, Loc),
3431 Expressions => New_List (
3432 Make_Attribute_Reference (Loc,
3433 Attribute_Name => Name_Last,
3434 Prefix => New_Occurrence_Of (P_Type, Loc)))),
3437 Make_Attribute_Reference (Loc,
3438 Attribute_Name => Name_Pos,
3439 Prefix => New_Occurrence_Of (P_Type, Loc),
3440 Expressions => New_List (
3441 Make_Attribute_Reference (Loc,
3442 Attribute_Name => Name_First,
3443 Prefix => New_Occurrence_Of (P_Type, Loc))))),
3446 Make_Integer_Literal (Loc, 1)));
3448 Analyze_And_Resolve (N, Typ);
3450 -- For all other cases, attribute is handled by Gigi, but we need
3451 -- to deal with the case of the range check on a universal integer.
3454 Apply_Universal_Integer_Attribute_Checks (N);
3462 when Attribute_Read => Read : declare
3463 P_Type : constant Entity_Id := Entity (Pref);
3464 B_Type : constant Entity_Id := Base_Type (P_Type);
3465 U_Type : constant Entity_Id := Underlying_Type (P_Type);
3475 -- If no underlying type, we have an error that will be diagnosed
3476 -- elsewhere, so here we just completely ignore the expansion.
3482 -- The simple case, if there is a TSS for Read, just call it
3484 Pname := Find_Stream_Subprogram (P_Type, TSS_Stream_Read);
3486 if Present (Pname) then
3490 -- If there is a Stream_Convert pragma, use it, we rewrite
3492 -- sourcetyp'Read (stream, Item)
3496 -- Item := sourcetyp (strmread (strmtyp'Input (Stream)));
3498 -- where strmread is the given Read function that converts an
3499 -- argument of type strmtyp to type sourcetyp or a type from which
3500 -- it is derived. The conversion to sourcetyp is required in the
3503 -- A special case arises if Item is a type conversion in which
3504 -- case, we have to expand to:
3506 -- Itemx := typex (strmread (strmtyp'Input (Stream)));
3508 -- where Itemx is the expression of the type conversion (i.e.
3509 -- the actual object), and typex is the type of Itemx.
3511 Prag := Get_Stream_Convert_Pragma (P_Type);
3513 if Present (Prag) then
3514 Arg2 := Next (First (Pragma_Argument_Associations (Prag)));
3515 Rfunc := Entity (Expression (Arg2));
3516 Lhs := Relocate_Node (Next (First (Exprs)));
3518 OK_Convert_To (B_Type,
3519 Make_Function_Call (Loc,
3520 Name => New_Occurrence_Of (Rfunc, Loc),
3521 Parameter_Associations => New_List (
3522 Make_Attribute_Reference (Loc,
3525 (Etype (First_Formal (Rfunc)), Loc),
3526 Attribute_Name => Name_Input,
3527 Expressions => New_List (
3528 Relocate_Node (First (Exprs)))))));
3530 if Nkind (Lhs) = N_Type_Conversion then
3531 Lhs := Expression (Lhs);
3532 Rhs := Convert_To (Etype (Lhs), Rhs);
3536 Make_Assignment_Statement (Loc,
3538 Expression => Rhs));
3539 Set_Assignment_OK (Lhs);
3543 -- For elementary types, we call the I_xxx routine using the first
3544 -- parameter and then assign the result into the second parameter.
3545 -- We set Assignment_OK to deal with the conversion case.
3547 elsif Is_Elementary_Type (U_Type) then
3553 Lhs := Relocate_Node (Next (First (Exprs)));
3554 Rhs := Build_Elementary_Input_Call (N);
3556 if Nkind (Lhs) = N_Type_Conversion then
3557 Lhs := Expression (Lhs);
3558 Rhs := Convert_To (Etype (Lhs), Rhs);
3561 Set_Assignment_OK (Lhs);
3564 Make_Assignment_Statement (Loc,
3566 Expression => Rhs));
3574 elsif Is_Array_Type (U_Type) then
3575 Build_Array_Read_Procedure (N, U_Type, Decl, Pname);
3576 Compile_Stream_Body_In_Scope (N, Decl, U_Type, Check => False);
3578 -- Tagged type case, use the primitive Read function. Note that
3579 -- this will dispatch in the class-wide case which is what we want
3581 elsif Is_Tagged_Type (U_Type) then
3582 Pname := Find_Prim_Op (U_Type, TSS_Stream_Read);
3584 -- All other record type cases, including protected records. The
3585 -- latter only arise for expander generated code for handling
3586 -- shared passive partition access.
3590 (Is_Record_Type (U_Type) or else Is_Protected_Type (U_Type));
3592 -- Ada 2005 (AI-216): Program_Error is raised when executing
3593 -- the default implementation of the Read attribute of an
3594 -- Unchecked_Union type.
3596 if Is_Unchecked_Union (Base_Type (U_Type)) then
3598 Make_Raise_Program_Error (Loc,
3599 Reason => PE_Unchecked_Union_Restriction));
3602 if Has_Discriminants (U_Type)
3604 (Discriminant_Default_Value (First_Discriminant (U_Type)))
3606 Build_Mutable_Record_Read_Procedure
3607 (Loc, Base_Type (U_Type), Decl, Pname);
3609 Build_Record_Read_Procedure
3610 (Loc, Base_Type (U_Type), Decl, Pname);
3613 -- Suppress checks, uninitialized or otherwise invalid
3614 -- data does not cause constraint errors to be raised for
3615 -- a complete record read.
3617 Insert_Action (N, Decl, All_Checks);
3621 Rewrite_Stream_Proc_Call (Pname);
3628 -- Transforms 'Remainder into a call to the floating-point attribute
3629 -- function Remainder in Fat_xxx (where xxx is the root type)
3631 when Attribute_Remainder =>
3632 Expand_Fpt_Attribute_RR (N);
3638 -- The handling of the Round attribute is quite delicate. The processing
3639 -- in Sem_Attr introduced a conversion to universal real, reflecting the
3640 -- semantics of Round, but we do not want anything to do with universal
3641 -- real at runtime, since this corresponds to using floating-point
3644 -- What we have now is that the Etype of the Round attribute correctly
3645 -- indicates the final result type. The operand of the Round is the
3646 -- conversion to universal real, described above, and the operand of
3647 -- this conversion is the actual operand of Round, which may be the
3648 -- special case of a fixed point multiplication or division (Etype =
3651 -- The exapander will expand first the operand of the conversion, then
3652 -- the conversion, and finally the round attribute itself, since we
3653 -- always work inside out. But we cannot simply process naively in this
3654 -- order. In the semantic world where universal fixed and real really
3655 -- exist and have infinite precision, there is no problem, but in the
3656 -- implementation world, where universal real is a floating-point type,
3657 -- we would get the wrong result.
3659 -- So the approach is as follows. First, when expanding a multiply or
3660 -- divide whose type is universal fixed, we do nothing at all, instead
3661 -- deferring the operation till later.
3663 -- The actual processing is done in Expand_N_Type_Conversion which
3664 -- handles the special case of Round by looking at its parent to see if
3665 -- it is a Round attribute, and if it is, handling the conversion (or
3666 -- its fixed multiply/divide child) in an appropriate manner.
3668 -- This means that by the time we get to expanding the Round attribute
3669 -- itself, the Round is nothing more than a type conversion (and will
3670 -- often be a null type conversion), so we just replace it with the
3671 -- appropriate conversion operation.
3673 when Attribute_Round =>
3675 Convert_To (Etype (N), Relocate_Node (First (Exprs))));
3676 Analyze_And_Resolve (N);
3682 -- Transforms 'Rounding into a call to the floating-point attribute
3683 -- function Rounding in Fat_xxx (where xxx is the root type)
3685 when Attribute_Rounding =>
3686 Expand_Fpt_Attribute_R (N);
3692 -- Transforms 'Scaling into a call to the floating-point attribute
3693 -- function Scaling in Fat_xxx (where xxx is the root type)
3695 when Attribute_Scaling =>
3696 Expand_Fpt_Attribute_RI (N);
3702 when Attribute_Size |
3703 Attribute_Object_Size |
3704 Attribute_Value_Size |
3705 Attribute_VADS_Size => Size :
3708 Ptyp : constant Entity_Id := Etype (Pref);
3713 -- Processing for VADS_Size case. Note that this processing removes
3714 -- all traces of VADS_Size from the tree, and completes all required
3715 -- processing for VADS_Size by translating the attribute reference
3716 -- to an appropriate Size or Object_Size reference.
3718 if Id = Attribute_VADS_Size
3719 or else (Use_VADS_Size and then Id = Attribute_Size)
3721 -- If the size is specified, then we simply use the specified
3722 -- size. This applies to both types and objects. The size of an
3723 -- object can be specified in the following ways:
3725 -- An explicit size object is given for an object
3726 -- A component size is specified for an indexed component
3727 -- A component clause is specified for a selected component
3728 -- The object is a component of a packed composite object
3730 -- If the size is specified, then VADS_Size of an object
3732 if (Is_Entity_Name (Pref)
3733 and then Present (Size_Clause (Entity (Pref))))
3735 (Nkind (Pref) = N_Component_Clause
3736 and then (Present (Component_Clause
3737 (Entity (Selector_Name (Pref))))
3738 or else Is_Packed (Etype (Prefix (Pref)))))
3740 (Nkind (Pref) = N_Indexed_Component
3741 and then (Component_Size (Etype (Prefix (Pref))) /= 0
3742 or else Is_Packed (Etype (Prefix (Pref)))))
3744 Set_Attribute_Name (N, Name_Size);
3746 -- Otherwise if we have an object rather than a type, then the
3747 -- VADS_Size attribute applies to the type of the object, rather
3748 -- than the object itself. This is one of the respects in which
3749 -- VADS_Size differs from Size.
3752 if (not Is_Entity_Name (Pref)
3753 or else not Is_Type (Entity (Pref)))
3754 and then (Is_Scalar_Type (Etype (Pref))
3755 or else Is_Constrained (Etype (Pref)))
3757 Rewrite (Pref, New_Occurrence_Of (Etype (Pref), Loc));
3760 -- For a scalar type for which no size was explicitly given,
3761 -- VADS_Size means Object_Size. This is the other respect in
3762 -- which VADS_Size differs from Size.
3764 if Is_Scalar_Type (Etype (Pref))
3765 and then No (Size_Clause (Etype (Pref)))
3767 Set_Attribute_Name (N, Name_Object_Size);
3769 -- In all other cases, Size and VADS_Size are the sane
3772 Set_Attribute_Name (N, Name_Size);
3777 -- For class-wide types, X'Class'Size is transformed into a
3778 -- direct reference to the Size of the class type, so that gigi
3779 -- does not have to deal with the X'Class'Size reference.
3781 if Is_Entity_Name (Pref)
3782 and then Is_Class_Wide_Type (Entity (Pref))
3784 Rewrite (Prefix (N), New_Occurrence_Of (Entity (Pref), Loc));
3787 -- For X'Size applied to an object of a class-wide type, transform
3788 -- X'Size into a call to the primitive operation _Size applied to X.
3790 elsif Is_Class_Wide_Type (Ptyp) then
3792 -- No need to do anything else compiling under restriction
3793 -- No_Dispatching_Calls. During the semantic analysis we
3794 -- already notified such violation.
3796 if Restriction_Active (No_Dispatching_Calls) then
3801 Make_Function_Call (Loc,
3802 Name => New_Reference_To
3803 (Find_Prim_Op (Ptyp, Name_uSize), Loc),
3804 Parameter_Associations => New_List (Pref));
3806 if Typ /= Standard_Long_Long_Integer then
3808 -- The context is a specific integer type with which the
3809 -- original attribute was compatible. The function has a
3810 -- specific type as well, so to preserve the compatibility
3811 -- we must convert explicitly.
3813 New_Node := Convert_To (Typ, New_Node);
3816 Rewrite (N, New_Node);
3817 Analyze_And_Resolve (N, Typ);
3820 -- Case of known RM_Size of a type
3822 elsif (Id = Attribute_Size or else Id = Attribute_Value_Size)
3823 and then Is_Entity_Name (Pref)
3824 and then Is_Type (Entity (Pref))
3825 and then Known_Static_RM_Size (Entity (Pref))
3827 Siz := RM_Size (Entity (Pref));
3829 -- Case of known Esize of a type
3831 elsif Id = Attribute_Object_Size
3832 and then Is_Entity_Name (Pref)
3833 and then Is_Type (Entity (Pref))
3834 and then Known_Static_Esize (Entity (Pref))
3836 Siz := Esize (Entity (Pref));
3838 -- Case of known size of object
3840 elsif Id = Attribute_Size
3841 and then Is_Entity_Name (Pref)
3842 and then Is_Object (Entity (Pref))
3843 and then Known_Esize (Entity (Pref))
3844 and then Known_Static_Esize (Entity (Pref))
3846 Siz := Esize (Entity (Pref));
3848 -- For an array component, we can do Size in the front end
3849 -- if the component_size of the array is set.
3851 elsif Nkind (Pref) = N_Indexed_Component then
3852 Siz := Component_Size (Etype (Prefix (Pref)));
3854 -- For a record component, we can do Size in the front end if there
3855 -- is a component clause, or if the record is packed and the
3856 -- component's size is known at compile time.
3858 elsif Nkind (Pref) = N_Selected_Component then
3860 Rec : constant Entity_Id := Etype (Prefix (Pref));
3861 Comp : constant Entity_Id := Entity (Selector_Name (Pref));
3864 if Present (Component_Clause (Comp)) then
3865 Siz := Esize (Comp);
3867 elsif Is_Packed (Rec) then
3868 Siz := RM_Size (Ptyp);
3871 Apply_Universal_Integer_Attribute_Checks (N);
3876 -- All other cases are handled by Gigi
3879 Apply_Universal_Integer_Attribute_Checks (N);
3881 -- If Size is applied to a formal parameter that is of a packed
3882 -- array subtype, then apply Size to the actual subtype.
3884 if Is_Entity_Name (Pref)
3885 and then Is_Formal (Entity (Pref))
3886 and then Is_Array_Type (Etype (Pref))
3887 and then Is_Packed (Etype (Pref))
3890 Make_Attribute_Reference (Loc,
3892 New_Occurrence_Of (Get_Actual_Subtype (Pref), Loc),
3893 Attribute_Name => Name_Size));
3894 Analyze_And_Resolve (N, Typ);
3897 -- If Size applies to a dereference of an access to unconstrained
3898 -- packed array, GIGI needs to see its unconstrained nominal type,
3899 -- but also a hint to the actual constrained type.
3901 if Nkind (Pref) = N_Explicit_Dereference
3902 and then Is_Array_Type (Etype (Pref))
3903 and then not Is_Constrained (Etype (Pref))
3904 and then Is_Packed (Etype (Pref))
3906 Set_Actual_Designated_Subtype (Pref,
3907 Get_Actual_Subtype (Pref));
3913 -- Common processing for record and array component case
3915 if Siz /= No_Uint and then Siz /= 0 then
3917 CS : constant Boolean := Comes_From_Source (N);
3920 Rewrite (N, Make_Integer_Literal (Loc, Siz));
3922 -- This integer literal is not a static expression. We do not
3923 -- call Analyze_And_Resolve here, because this would activate
3924 -- the circuit for deciding that a static value was out of
3925 -- range, and we don't want that.
3927 -- So just manually set the type, mark the expression as non-
3928 -- static, and then ensure that the result is checked properly
3929 -- if the attribute comes from source (if it was internally
3930 -- generated, we never need a constraint check).
3933 Set_Is_Static_Expression (N, False);
3936 Apply_Constraint_Check (N, Typ);
3946 when Attribute_Storage_Pool =>
3948 Make_Type_Conversion (Loc,
3949 Subtype_Mark => New_Reference_To (Etype (N), Loc),
3950 Expression => New_Reference_To (Entity (N), Loc)));
3951 Analyze_And_Resolve (N, Typ);
3957 when Attribute_Storage_Size => Storage_Size :
3959 Ptyp : constant Entity_Id := Etype (Pref);
3962 -- Access type case, always go to the root type
3964 -- The case of access types results in a value of zero for the case
3965 -- where no storage size attribute clause has been given. If a
3966 -- storage size has been given, then the attribute is converted
3967 -- to a reference to the variable used to hold this value.
3969 if Is_Access_Type (Ptyp) then
3970 if Present (Storage_Size_Variable (Root_Type (Ptyp))) then
3972 Make_Attribute_Reference (Loc,
3973 Prefix => New_Reference_To (Typ, Loc),
3974 Attribute_Name => Name_Max,
3975 Expressions => New_List (
3976 Make_Integer_Literal (Loc, 0),
3979 (Storage_Size_Variable (Root_Type (Ptyp)), Loc)))));
3981 elsif Present (Associated_Storage_Pool (Root_Type (Ptyp))) then
3984 Make_Function_Call (Loc,
3988 (Etype (Associated_Storage_Pool (Root_Type (Ptyp))),
3989 Attribute_Name (N)),
3992 Parameter_Associations => New_List (
3994 (Associated_Storage_Pool (Root_Type (Ptyp)), Loc)))));
3997 Rewrite (N, Make_Integer_Literal (Loc, 0));
4000 Analyze_And_Resolve (N, Typ);
4002 -- For tasks, we retrieve the size directly from the TCB. The
4003 -- size may depend on a discriminant of the type, and therefore
4004 -- can be a per-object expression, so type-level information is
4005 -- not sufficient in general. There are four cases to consider:
4007 -- a) If the attribute appears within a task body, the designated
4008 -- TCB is obtained by a call to Self.
4010 -- b) If the prefix of the attribute is the name of a task object,
4011 -- the designated TCB is the one stored in the corresponding record.
4013 -- c) If the prefix is a task type, the size is obtained from the
4014 -- size variable created for each task type
4016 -- d) If no storage_size was specified for the type , there is no
4017 -- size variable, and the value is a system-specific default.
4020 if In_Open_Scopes (Ptyp) then
4022 -- Storage_Size (Self)
4026 Make_Function_Call (Loc,
4028 New_Occurrence_Of (RTE (RE_Storage_Size), Loc),
4029 Parameter_Associations =>
4031 Make_Function_Call (Loc,
4033 New_Reference_To (RTE (RE_Self), Loc))))));
4035 elsif not Is_Entity_Name (Pref)
4036 or else not Is_Type (Entity (Pref))
4038 -- Storage_Size (Rec (Obj).Size)
4042 Make_Function_Call (Loc,
4044 New_Occurrence_Of (RTE (RE_Storage_Size), Loc),
4045 Parameter_Associations =>
4047 Make_Selected_Component (Loc,
4049 Unchecked_Convert_To (
4050 Corresponding_Record_Type (Ptyp),
4051 New_Copy_Tree (Pref)),
4053 Make_Identifier (Loc, Name_uTask_Id))))));
4055 elsif Present (Storage_Size_Variable (Ptyp)) then
4057 -- Static storage size pragma given for type: retrieve value
4058 -- from its allocated storage variable.
4062 Make_Function_Call (Loc,
4063 Name => New_Occurrence_Of (
4064 RTE (RE_Adjust_Storage_Size), Loc),
4065 Parameter_Associations =>
4068 Storage_Size_Variable (Ptyp), Loc)))));
4070 -- Get system default
4074 Make_Function_Call (Loc,
4077 RTE (RE_Default_Stack_Size), Loc))));
4080 Analyze_And_Resolve (N, Typ);
4088 when Attribute_Stream_Size => Stream_Size : declare
4089 Ptyp : constant Entity_Id := Etype (Pref);
4093 -- If we have a Stream_Size clause for this type use it, otherwise
4094 -- the Stream_Size if the size of the type.
4096 if Has_Stream_Size_Clause (Ptyp) then
4099 (Static_Integer (Expression (Stream_Size_Clause (Ptyp))));
4101 Size := UI_To_Int (Esize (Ptyp));
4104 Rewrite (N, Make_Integer_Literal (Loc, Intval => Size));
4105 Analyze_And_Resolve (N, Typ);
4112 -- 1. Deal with enumeration types with holes
4113 -- 2. For floating-point, generate call to attribute function
4114 -- 3. For other cases, deal with constraint checking
4116 when Attribute_Succ => Succ :
4118 Ptyp : constant Entity_Id := Base_Type (Etype (Pref));
4121 -- For enumeration types with non-standard representations, we
4122 -- expand typ'Succ (x) into
4124 -- Pos_To_Rep (Rep_To_Pos (x) + 1)
4126 -- If the representation is contiguous, we compute instead
4127 -- Lit1 + Rep_to_Pos (x+1), to catch invalid representations.
4129 if Is_Enumeration_Type (Ptyp)
4130 and then Present (Enum_Pos_To_Rep (Ptyp))
4132 if Has_Contiguous_Rep (Ptyp) then
4134 Unchecked_Convert_To (Ptyp,
4137 Make_Integer_Literal (Loc,
4138 Enumeration_Rep (First_Literal (Ptyp))),
4140 Make_Function_Call (Loc,
4143 (TSS (Ptyp, TSS_Rep_To_Pos), Loc),
4145 Parameter_Associations =>
4147 Unchecked_Convert_To (Ptyp,
4150 Unchecked_Convert_To (Standard_Integer,
4151 Relocate_Node (First (Exprs))),
4153 Make_Integer_Literal (Loc, 1))),
4154 Rep_To_Pos_Flag (Ptyp, Loc))))));
4156 -- Add Boolean parameter True, to request program errror if
4157 -- we have a bad representation on our hands. Add False if
4158 -- checks are suppressed.
4160 Append_To (Exprs, Rep_To_Pos_Flag (Ptyp, Loc));
4162 Make_Indexed_Component (Loc,
4163 Prefix => New_Reference_To (Enum_Pos_To_Rep (Ptyp), Loc),
4164 Expressions => New_List (
4167 Make_Function_Call (Loc,
4170 (TSS (Ptyp, TSS_Rep_To_Pos), Loc),
4171 Parameter_Associations => Exprs),
4172 Right_Opnd => Make_Integer_Literal (Loc, 1)))));
4175 Analyze_And_Resolve (N, Typ);
4177 -- For floating-point, we transform 'Succ into a call to the Succ
4178 -- floating-point attribute function in Fat_xxx (xxx is root type)
4180 elsif Is_Floating_Point_Type (Ptyp) then
4181 Expand_Fpt_Attribute_R (N);
4182 Analyze_And_Resolve (N, Typ);
4184 -- For modular types, nothing to do (no overflow, since wraps)
4186 elsif Is_Modular_Integer_Type (Ptyp) then
4189 -- For other types, if range checking is enabled, we must generate
4190 -- a check if overflow checking is enabled.
4192 elsif not Overflow_Checks_Suppressed (Ptyp) then
4193 Expand_Pred_Succ (N);
4201 -- Transforms X'Tag into a direct reference to the tag of X
4203 when Attribute_Tag => Tag :
4206 Prefix_Is_Type : Boolean;
4209 if Is_Entity_Name (Pref) and then Is_Type (Entity (Pref)) then
4210 Ttyp := Entity (Pref);
4211 Prefix_Is_Type := True;
4213 Ttyp := Etype (Pref);
4214 Prefix_Is_Type := False;
4217 if Is_Class_Wide_Type (Ttyp) then
4218 Ttyp := Root_Type (Ttyp);
4221 Ttyp := Underlying_Type (Ttyp);
4223 if Prefix_Is_Type then
4225 -- For VMs we leave the type attribute unexpanded because
4226 -- there's not a dispatching table to reference.
4228 if VM_Target = No_VM then
4230 Unchecked_Convert_To (RTE (RE_Tag),
4232 (Node (First_Elmt (Access_Disp_Table (Ttyp))), Loc)));
4233 Analyze_And_Resolve (N, RTE (RE_Tag));
4236 -- (Ada 2005 (AI-251): The use of 'Tag in the sources always
4237 -- references the primary tag of the actual object. If 'Tag is
4238 -- applied to class-wide interface objects we generate code that
4239 -- displaces "this" to reference the base of the object.
4241 elsif Comes_From_Source (N)
4242 and then Is_Class_Wide_Type (Etype (Prefix (N)))
4243 and then Is_Interface (Etype (Prefix (N)))
4246 -- (To_Tag_Ptr (Prefix'Address)).all
4248 -- Note that Prefix'Address is recursively expanded into a call
4249 -- to Base_Address (Obj.Tag)
4251 -- Not needed for VM targets, since all handled by the VM
4253 if VM_Target = No_VM then
4255 Make_Explicit_Dereference (Loc,
4256 Unchecked_Convert_To (RTE (RE_Tag_Ptr),
4257 Make_Attribute_Reference (Loc,
4258 Prefix => Relocate_Node (Pref),
4259 Attribute_Name => Name_Address))));
4260 Analyze_And_Resolve (N, RTE (RE_Tag));
4265 Make_Selected_Component (Loc,
4266 Prefix => Relocate_Node (Pref),
4268 New_Reference_To (First_Tag_Component (Ttyp), Loc)));
4269 Analyze_And_Resolve (N, RTE (RE_Tag));
4277 -- Transforms 'Terminated attribute into a call to Terminated function
4279 when Attribute_Terminated => Terminated :
4281 -- The prefix of Terminated is of a task interface class-wide type.
4284 -- terminated (Task_Id (Pref._disp_get_task_id));
4286 if Ada_Version >= Ada_05
4287 and then Ekind (Etype (Pref)) = E_Class_Wide_Type
4288 and then Is_Interface (Etype (Pref))
4289 and then Is_Task_Interface (Etype (Pref))
4292 Make_Function_Call (Loc,
4294 New_Reference_To (RTE (RE_Terminated), Loc),
4295 Parameter_Associations => New_List (
4296 Make_Unchecked_Type_Conversion (Loc,
4298 New_Reference_To (RTE (RO_ST_Task_Id), Loc),
4300 Make_Selected_Component (Loc,
4302 New_Copy_Tree (Pref),
4304 Make_Identifier (Loc, Name_uDisp_Get_Task_Id))))));
4306 elsif Restricted_Profile then
4308 Build_Call_With_Task (Pref, RTE (RE_Restricted_Terminated)));
4312 Build_Call_With_Task (Pref, RTE (RE_Terminated)));
4315 Analyze_And_Resolve (N, Standard_Boolean);
4322 -- Transforms System'To_Address (X) into unchecked conversion
4323 -- from (integral) type of X to type address.
4325 when Attribute_To_Address =>
4327 Unchecked_Convert_To (RTE (RE_Address),
4328 Relocate_Node (First (Exprs))));
4329 Analyze_And_Resolve (N, RTE (RE_Address));
4335 -- Transforms 'Truncation into a call to the floating-point attribute
4336 -- function Truncation in Fat_xxx (where xxx is the root type).
4337 -- Expansion is avoided for cases the back end can handle directly.
4339 when Attribute_Truncation =>
4340 if not Is_Inline_Floating_Point_Attribute (N) then
4341 Expand_Fpt_Attribute_R (N);
4344 -----------------------
4345 -- Unbiased_Rounding --
4346 -----------------------
4348 -- Transforms 'Unbiased_Rounding into a call to the floating-point
4349 -- attribute function Unbiased_Rounding in Fat_xxx (where xxx is the
4350 -- root type). Expansion is avoided for cases the back end can handle
4353 when Attribute_Unbiased_Rounding =>
4354 if not Is_Inline_Floating_Point_Attribute (N) then
4355 Expand_Fpt_Attribute_R (N);
4362 when Attribute_UET_Address => UET_Address : declare
4363 Ent : constant Entity_Id :=
4364 Make_Defining_Identifier (Loc, New_Internal_Name ('T'));
4368 Make_Object_Declaration (Loc,
4369 Defining_Identifier => Ent,
4370 Aliased_Present => True,
4371 Object_Definition =>
4372 New_Occurrence_Of (RTE (RE_Address), Loc)));
4374 -- Construct name __gnat_xxx__SDP, where xxx is the unit name
4375 -- in normal external form.
4377 Get_External_Unit_Name_String (Get_Unit_Name (Pref));
4378 Name_Buffer (1 + 7 .. Name_Len + 7) := Name_Buffer (1 .. Name_Len);
4379 Name_Len := Name_Len + 7;
4380 Name_Buffer (1 .. 7) := "__gnat_";
4381 Name_Buffer (Name_Len + 1 .. Name_Len + 5) := "__SDP";
4382 Name_Len := Name_Len + 5;
4384 Set_Is_Imported (Ent);
4385 Set_Interface_Name (Ent,
4386 Make_String_Literal (Loc,
4387 Strval => String_From_Name_Buffer));
4389 -- Set entity as internal to ensure proper Sprint output of its
4390 -- implicit importation.
4392 Set_Is_Internal (Ent);
4395 Make_Attribute_Reference (Loc,
4396 Prefix => New_Occurrence_Of (Ent, Loc),
4397 Attribute_Name => Name_Address));
4399 Analyze_And_Resolve (N, Typ);
4406 -- The processing for VADS_Size is shared with Size
4412 -- For enumeration types with a standard representation, and for all
4413 -- other types, Val is handled by Gigi. For enumeration types with
4414 -- a non-standard representation we use the _Pos_To_Rep array that
4415 -- was created when the type was frozen.
4417 when Attribute_Val => Val :
4419 Etyp : constant Entity_Id := Base_Type (Entity (Pref));
4422 if Is_Enumeration_Type (Etyp)
4423 and then Present (Enum_Pos_To_Rep (Etyp))
4425 if Has_Contiguous_Rep (Etyp) then
4427 Rep_Node : constant Node_Id :=
4428 Unchecked_Convert_To (Etyp,
4431 Make_Integer_Literal (Loc,
4432 Enumeration_Rep (First_Literal (Etyp))),
4434 (Convert_To (Standard_Integer,
4435 Relocate_Node (First (Exprs))))));
4439 Unchecked_Convert_To (Etyp,
4442 Make_Integer_Literal (Loc,
4443 Enumeration_Rep (First_Literal (Etyp))),
4445 Make_Function_Call (Loc,
4448 (TSS (Etyp, TSS_Rep_To_Pos), Loc),
4449 Parameter_Associations => New_List (
4451 Rep_To_Pos_Flag (Etyp, Loc))))));
4456 Make_Indexed_Component (Loc,
4457 Prefix => New_Reference_To (Enum_Pos_To_Rep (Etyp), Loc),
4458 Expressions => New_List (
4459 Convert_To (Standard_Integer,
4460 Relocate_Node (First (Exprs))))));
4463 Analyze_And_Resolve (N, Typ);
4471 -- The code for valid is dependent on the particular types involved.
4472 -- See separate sections below for the generated code in each case.
4474 when Attribute_Valid => Valid :
4476 Ptyp : constant Entity_Id := Etype (Pref);
4477 Btyp : Entity_Id := Base_Type (Ptyp);
4480 Save_Validity_Checks_On : constant Boolean := Validity_Checks_On;
4481 -- Save the validity checking mode. We always turn off validity
4482 -- checking during process of 'Valid since this is one place
4483 -- where we do not want the implicit validity checks to intefere
4484 -- with the explicit validity check that the programmer is doing.
4486 function Make_Range_Test return Node_Id;
4487 -- Build the code for a range test of the form
4488 -- Btyp!(Pref) >= Btyp!(Ptyp'First)
4490 -- Btyp!(Pref) <= Btyp!(Ptyp'Last)
4492 ---------------------
4493 -- Make_Range_Test --
4494 ---------------------
4496 function Make_Range_Test return Node_Id is
4503 Unchecked_Convert_To (Btyp, Duplicate_Subexpr (Pref)),
4506 Unchecked_Convert_To (Btyp,
4507 Make_Attribute_Reference (Loc,
4508 Prefix => New_Occurrence_Of (Ptyp, Loc),
4509 Attribute_Name => Name_First))),
4514 Unchecked_Convert_To (Btyp,
4515 Duplicate_Subexpr_No_Checks (Pref)),
4518 Unchecked_Convert_To (Btyp,
4519 Make_Attribute_Reference (Loc,
4520 Prefix => New_Occurrence_Of (Ptyp, Loc),
4521 Attribute_Name => Name_Last))));
4522 end Make_Range_Test;
4524 -- Start of processing for Attribute_Valid
4527 -- Turn off validity checks. We do not want any implicit validity
4528 -- checks to intefere with the explicit check from the attribute
4530 Validity_Checks_On := False;
4532 -- Floating-point case. This case is handled by the Valid attribute
4533 -- code in the floating-point attribute run-time library.
4535 if Is_Floating_Point_Type (Ptyp) then
4541 -- For vax fpt types, call appropriate routine in special vax
4542 -- floating point unit. We do not have to worry about loads in
4543 -- this case, since these types have no signalling NaN's.
4545 if Vax_Float (Btyp) then
4546 Expand_Vax_Valid (N);
4548 -- The AAMP back end handles Valid for floating-point types
4550 elsif Is_AAMP_Float (Btyp) then
4551 Analyze_And_Resolve (Pref, Ptyp);
4552 Set_Etype (N, Standard_Boolean);
4555 -- Non VAX float case
4558 Find_Fat_Info (Etype (Pref), Ftp, Pkg);
4560 -- If the floating-point object might be unaligned, we need
4561 -- to call the special routine Unaligned_Valid, which makes
4562 -- the needed copy, being careful not to load the value into
4563 -- any floating-point register. The argument in this case is
4564 -- obj'Address (see Unaligned_Valid routine in Fat_Gen).
4566 if Is_Possibly_Unaligned_Object (Pref) then
4567 Expand_Fpt_Attribute
4568 (N, Pkg, Name_Unaligned_Valid,
4570 Make_Attribute_Reference (Loc,
4571 Prefix => Relocate_Node (Pref),
4572 Attribute_Name => Name_Address)));
4574 -- In the normal case where we are sure the object is
4575 -- aligned, we generate a call to Valid, and the argument in
4576 -- this case is obj'Unrestricted_Access (after converting
4577 -- obj to the right floating-point type).
4580 Expand_Fpt_Attribute
4581 (N, Pkg, Name_Valid,
4583 Make_Attribute_Reference (Loc,
4584 Prefix => Unchecked_Convert_To (Ftp, Pref),
4585 Attribute_Name => Name_Unrestricted_Access)));
4589 -- One more task, we still need a range check. Required
4590 -- only if we have a constraint, since the Valid routine
4591 -- catches infinities properly (infinities are never valid).
4593 -- The way we do the range check is simply to create the
4594 -- expression: Valid (N) and then Base_Type(Pref) in Typ.
4596 if not Subtypes_Statically_Match (Ptyp, Btyp) then
4599 Left_Opnd => Relocate_Node (N),
4602 Left_Opnd => Convert_To (Btyp, Pref),
4603 Right_Opnd => New_Occurrence_Of (Ptyp, Loc))));
4607 -- Enumeration type with holes
4609 -- For enumeration types with holes, the Pos value constructed by
4610 -- the Enum_Rep_To_Pos function built in Exp_Ch3 called with a
4611 -- second argument of False returns minus one for an invalid value,
4612 -- and the non-negative pos value for a valid value, so the
4613 -- expansion of X'Valid is simply:
4615 -- type(X)'Pos (X) >= 0
4617 -- We can't quite generate it that way because of the requirement
4618 -- for the non-standard second argument of False in the resulting
4619 -- rep_to_pos call, so we have to explicitly create:
4621 -- _rep_to_pos (X, False) >= 0
4623 -- If we have an enumeration subtype, we also check that the
4624 -- value is in range:
4626 -- _rep_to_pos (X, False) >= 0
4628 -- (X >= type(X)'First and then type(X)'Last <= X)
4630 elsif Is_Enumeration_Type (Ptyp)
4631 and then Present (Enum_Pos_To_Rep (Base_Type (Ptyp)))
4636 Make_Function_Call (Loc,
4639 (TSS (Base_Type (Ptyp), TSS_Rep_To_Pos), Loc),
4640 Parameter_Associations => New_List (
4642 New_Occurrence_Of (Standard_False, Loc))),
4643 Right_Opnd => Make_Integer_Literal (Loc, 0));
4647 (Type_Low_Bound (Ptyp) /= Type_Low_Bound (Btyp)
4649 Type_High_Bound (Ptyp) /= Type_High_Bound (Btyp))
4651 -- The call to Make_Range_Test will create declarations
4652 -- that need a proper insertion point, but Pref is now
4653 -- attached to a node with no ancestor. Attach to tree
4654 -- even if it is to be rewritten below.
4656 Set_Parent (Tst, Parent (N));
4660 Left_Opnd => Make_Range_Test,
4666 -- Fortran convention booleans
4668 -- For the very special case of Fortran convention booleans, the
4669 -- value is always valid, since it is an integer with the semantics
4670 -- that non-zero is true, and any value is permissible.
4672 elsif Is_Boolean_Type (Ptyp)
4673 and then Convention (Ptyp) = Convention_Fortran
4675 Rewrite (N, New_Occurrence_Of (Standard_True, Loc));
4677 -- For biased representations, we will be doing an unchecked
4678 -- conversion without unbiasing the result. That means that the range
4679 -- test has to take this into account, and the proper form of the
4682 -- Btyp!(Pref) < Btyp!(Ptyp'Range_Length)
4684 elsif Has_Biased_Representation (Ptyp) then
4685 Btyp := RTE (RE_Unsigned_32);
4689 Unchecked_Convert_To (Btyp, Duplicate_Subexpr (Pref)),
4691 Unchecked_Convert_To (Btyp,
4692 Make_Attribute_Reference (Loc,
4693 Prefix => New_Occurrence_Of (Ptyp, Loc),
4694 Attribute_Name => Name_Range_Length))));
4696 -- For all other scalar types, what we want logically is a
4699 -- X in type(X)'First .. type(X)'Last
4701 -- But that's precisely what won't work because of possible
4702 -- unwanted optimization (and indeed the basic motivation for
4703 -- the Valid attribute is exactly that this test does not work!)
4704 -- What will work is:
4706 -- Btyp!(X) >= Btyp!(type(X)'First)
4708 -- Btyp!(X) <= Btyp!(type(X)'Last)
4710 -- where Btyp is an integer type large enough to cover the full
4711 -- range of possible stored values (i.e. it is chosen on the basis
4712 -- of the size of the type, not the range of the values). We write
4713 -- this as two tests, rather than a range check, so that static
4714 -- evaluation will easily remove either or both of the checks if
4715 -- they can be -statically determined to be true (this happens
4716 -- when the type of X is static and the range extends to the full
4717 -- range of stored values).
4719 -- Unsigned types. Note: it is safe to consider only whether the
4720 -- subtype is unsigned, since we will in that case be doing all
4721 -- unsigned comparisons based on the subtype range. Since we use the
4722 -- actual subtype object size, this is appropriate.
4724 -- For example, if we have
4726 -- subtype x is integer range 1 .. 200;
4727 -- for x'Object_Size use 8;
4729 -- Now the base type is signed, but objects of this type are bits
4730 -- unsigned, and doing an unsigned test of the range 1 to 200 is
4731 -- correct, even though a value greater than 127 looks signed to a
4732 -- signed comparison.
4734 elsif Is_Unsigned_Type (Ptyp) then
4735 if Esize (Ptyp) <= 32 then
4736 Btyp := RTE (RE_Unsigned_32);
4738 Btyp := RTE (RE_Unsigned_64);
4741 Rewrite (N, Make_Range_Test);
4746 if Esize (Ptyp) <= Esize (Standard_Integer) then
4747 Btyp := Standard_Integer;
4749 Btyp := Universal_Integer;
4752 Rewrite (N, Make_Range_Test);
4755 Analyze_And_Resolve (N, Standard_Boolean);
4756 Validity_Checks_On := Save_Validity_Checks_On;
4763 -- Value attribute is handled in separate unti Exp_Imgv
4765 when Attribute_Value =>
4766 Exp_Imgv.Expand_Value_Attribute (N);
4772 -- The processing for Value_Size shares the processing for Size
4778 -- The processing for Version shares the processing for Body_Version
4784 -- Wide_Image attribute is handled in separate unit Exp_Imgv
4786 when Attribute_Wide_Image =>
4787 Exp_Imgv.Expand_Wide_Image_Attribute (N);
4789 ---------------------
4790 -- Wide_Wide_Image --
4791 ---------------------
4793 -- Wide_Wide_Image attribute is handled in separate unit Exp_Imgv
4795 when Attribute_Wide_Wide_Image =>
4796 Exp_Imgv.Expand_Wide_Wide_Image_Attribute (N);
4802 -- We expand typ'Wide_Value (X) into
4805 -- (Wide_String_To_String (X, Wide_Character_Encoding_Method))
4807 -- Wide_String_To_String is a runtime function that converts its wide
4808 -- string argument to String, converting any non-translatable characters
4809 -- into appropriate escape sequences. This preserves the required
4810 -- semantics of Wide_Value in all cases, and results in a very simple
4811 -- implementation approach.
4813 -- Note: for this approach to be fully standard compliant for the cases
4814 -- where typ is Wide_Character and Wide_Wide_Character, the encoding
4815 -- method must cover the entire character range (e.g. UTF-8). But that
4816 -- is a reasonable requirement when dealing with encoded character
4817 -- sequences. Presumably if one of the restrictive encoding mechanisms
4818 -- is in use such as Shift-JIS, then characters that cannot be
4819 -- represented using this encoding will not appear in any case.
4821 when Attribute_Wide_Value => Wide_Value :
4824 Make_Attribute_Reference (Loc,
4826 Attribute_Name => Name_Value,
4828 Expressions => New_List (
4829 Make_Function_Call (Loc,
4831 New_Reference_To (RTE (RE_Wide_String_To_String), Loc),
4833 Parameter_Associations => New_List (
4834 Relocate_Node (First (Exprs)),
4835 Make_Integer_Literal (Loc,
4836 Intval => Int (Wide_Character_Encoding_Method)))))));
4838 Analyze_And_Resolve (N, Typ);
4841 ---------------------
4842 -- Wide_Wide_Value --
4843 ---------------------
4845 -- We expand typ'Wide_Value_Value (X) into
4848 -- (Wide_Wide_String_To_String (X, Wide_Character_Encoding_Method))
4850 -- Wide_Wide_String_To_String is a runtime function that converts its
4851 -- wide string argument to String, converting any non-translatable
4852 -- characters into appropriate escape sequences. This preserves the
4853 -- required semantics of Wide_Wide_Value in all cases, and results in a
4854 -- very simple implementation approach.
4856 -- It's not quite right where typ = Wide_Wide_Character, because the
4857 -- encoding method may not cover the whole character type ???
4859 when Attribute_Wide_Wide_Value => Wide_Wide_Value :
4862 Make_Attribute_Reference (Loc,
4864 Attribute_Name => Name_Value,
4866 Expressions => New_List (
4867 Make_Function_Call (Loc,
4869 New_Reference_To (RTE (RE_Wide_Wide_String_To_String), Loc),
4871 Parameter_Associations => New_List (
4872 Relocate_Node (First (Exprs)),
4873 Make_Integer_Literal (Loc,
4874 Intval => Int (Wide_Character_Encoding_Method)))))));
4876 Analyze_And_Resolve (N, Typ);
4877 end Wide_Wide_Value;
4879 ---------------------
4880 -- Wide_Wide_Width --
4881 ---------------------
4883 -- Wide_Wide_Width attribute is handled in separate unit Exp_Imgv
4885 when Attribute_Wide_Wide_Width =>
4886 Exp_Imgv.Expand_Width_Attribute (N, Wide_Wide);
4892 -- Wide_Width attribute is handled in separate unit Exp_Imgv
4894 when Attribute_Wide_Width =>
4895 Exp_Imgv.Expand_Width_Attribute (N, Wide);
4901 -- Width attribute is handled in separate unit Exp_Imgv
4903 when Attribute_Width =>
4904 Exp_Imgv.Expand_Width_Attribute (N, Normal);
4910 when Attribute_Write => Write : declare
4911 P_Type : constant Entity_Id := Entity (Pref);
4912 U_Type : constant Entity_Id := Underlying_Type (P_Type);
4920 -- If no underlying type, we have an error that will be diagnosed
4921 -- elsewhere, so here we just completely ignore the expansion.
4927 -- The simple case, if there is a TSS for Write, just call it
4929 Pname := Find_Stream_Subprogram (P_Type, TSS_Stream_Write);
4931 if Present (Pname) then
4935 -- If there is a Stream_Convert pragma, use it, we rewrite
4937 -- sourcetyp'Output (stream, Item)
4941 -- strmtyp'Output (Stream, strmwrite (acttyp (Item)));
4943 -- where strmwrite is the given Write function that converts an
4944 -- argument of type sourcetyp or a type acctyp, from which it is
4945 -- derived to type strmtyp. The conversion to acttyp is required
4946 -- for the derived case.
4948 Prag := Get_Stream_Convert_Pragma (P_Type);
4950 if Present (Prag) then
4952 Next (Next (First (Pragma_Argument_Associations (Prag))));
4953 Wfunc := Entity (Expression (Arg3));
4956 Make_Attribute_Reference (Loc,
4957 Prefix => New_Occurrence_Of (Etype (Wfunc), Loc),
4958 Attribute_Name => Name_Output,
4959 Expressions => New_List (
4960 Relocate_Node (First (Exprs)),
4961 Make_Function_Call (Loc,
4962 Name => New_Occurrence_Of (Wfunc, Loc),
4963 Parameter_Associations => New_List (
4964 OK_Convert_To (Etype (First_Formal (Wfunc)),
4965 Relocate_Node (Next (First (Exprs)))))))));
4970 -- For elementary types, we call the W_xxx routine directly
4972 elsif Is_Elementary_Type (U_Type) then
4973 Rewrite (N, Build_Elementary_Write_Call (N));
4979 elsif Is_Array_Type (U_Type) then
4980 Build_Array_Write_Procedure (N, U_Type, Decl, Pname);
4981 Compile_Stream_Body_In_Scope (N, Decl, U_Type, Check => False);
4983 -- Tagged type case, use the primitive Write function. Note that
4984 -- this will dispatch in the class-wide case which is what we want
4986 elsif Is_Tagged_Type (U_Type) then
4987 Pname := Find_Prim_Op (U_Type, TSS_Stream_Write);
4989 -- All other record type cases, including protected records.
4990 -- The latter only arise for expander generated code for
4991 -- handling shared passive partition access.
4995 (Is_Record_Type (U_Type) or else Is_Protected_Type (U_Type));
4997 -- Ada 2005 (AI-216): Program_Error is raised when executing
4998 -- the default implementation of the Write attribute of an
4999 -- Unchecked_Union type. However, if the 'Write reference is
5000 -- within the generated Output stream procedure, Write outputs
5001 -- the components, and the default values of the discriminant
5002 -- are streamed by the Output procedure itself.
5004 if Is_Unchecked_Union (Base_Type (U_Type))
5005 and not Is_TSS (Current_Scope, TSS_Stream_Output)
5008 Make_Raise_Program_Error (Loc,
5009 Reason => PE_Unchecked_Union_Restriction));
5012 if Has_Discriminants (U_Type)
5014 (Discriminant_Default_Value (First_Discriminant (U_Type)))
5016 Build_Mutable_Record_Write_Procedure
5017 (Loc, Base_Type (U_Type), Decl, Pname);
5019 Build_Record_Write_Procedure
5020 (Loc, Base_Type (U_Type), Decl, Pname);
5023 Insert_Action (N, Decl);
5027 -- If we fall through, Pname is the procedure to be called
5029 Rewrite_Stream_Proc_Call (Pname);
5032 -- Component_Size is handled by Gigi, unless the component size is known
5033 -- at compile time, which is always true in the packed array case. It is
5034 -- important that the packed array case is handled in the front end (see
5035 -- Eval_Attribute) since Gigi would otherwise get confused by the
5036 -- equivalent packed array type.
5038 when Attribute_Component_Size =>
5041 -- The following attributes are handled by the back end (except that
5042 -- static cases have already been evaluated during semantic processing,
5043 -- but in any case the back end should not count on this). The one bit
5044 -- of special processing required is that these attributes typically
5045 -- generate conditionals in the code, so we need to check the relevant
5048 when Attribute_Max |
5050 Check_Restriction (No_Implicit_Conditionals, N);
5052 -- The following attributes are handled by the back end (except that
5053 -- static cases have already been evaluated during semantic processing,
5054 -- but in any case the back end should not count on this).
5056 -- Gigi also handles the non-class-wide cases of Size
5058 when Attribute_Bit_Order |
5059 Attribute_Code_Address |
5060 Attribute_Definite |
5061 Attribute_Null_Parameter |
5062 Attribute_Passed_By_Reference |
5063 Attribute_Pool_Address =>
5066 -- The following attributes are also handled by Gigi, but return a
5067 -- universal integer result, so may need a conversion for checking
5068 -- that the result is in range.
5070 when Attribute_Aft |
5072 Attribute_Max_Size_In_Storage_Elements
5074 Apply_Universal_Integer_Attribute_Checks (N);
5076 -- The following attributes should not appear at this stage, since they
5077 -- have already been handled by the analyzer (and properly rewritten
5078 -- with corresponding values or entities to represent the right values)
5080 when Attribute_Abort_Signal |
5081 Attribute_Address_Size |
5084 Attribute_Default_Bit_Order |
5091 Attribute_Fast_Math |
5092 Attribute_Has_Access_Values |
5093 Attribute_Has_Discriminants |
5095 Attribute_Machine_Emax |
5096 Attribute_Machine_Emin |
5097 Attribute_Machine_Mantissa |
5098 Attribute_Machine_Overflows |
5099 Attribute_Machine_Radix |
5100 Attribute_Machine_Rounds |
5101 Attribute_Maximum_Alignment |
5102 Attribute_Model_Emin |
5103 Attribute_Model_Epsilon |
5104 Attribute_Model_Mantissa |
5105 Attribute_Model_Small |
5107 Attribute_Partition_ID |
5109 Attribute_Safe_Emax |
5110 Attribute_Safe_First |
5111 Attribute_Safe_Large |
5112 Attribute_Safe_Last |
5113 Attribute_Safe_Small |
5115 Attribute_Signed_Zeros |
5117 Attribute_Storage_Unit |
5118 Attribute_Stub_Type |
5119 Attribute_Target_Name |
5120 Attribute_Type_Class |
5121 Attribute_Unconstrained_Array |
5122 Attribute_Universal_Literal_String |
5123 Attribute_Wchar_T_Size |
5124 Attribute_Word_Size =>
5126 raise Program_Error;
5128 -- The Asm_Input and Asm_Output attributes are not expanded at this
5129 -- stage, but will be eliminated in the expansion of the Asm call,
5130 -- see Exp_Intr for details. So Gigi will never see these either.
5132 when Attribute_Asm_Input |
5133 Attribute_Asm_Output =>
5140 when RE_Not_Available =>
5142 end Expand_N_Attribute_Reference;
5144 ----------------------
5145 -- Expand_Pred_Succ --
5146 ----------------------
5148 -- For typ'Pred (exp), we generate the check
5150 -- [constraint_error when exp = typ'Base'First]
5152 -- Similarly, for typ'Succ (exp), we generate the check
5154 -- [constraint_error when exp = typ'Base'Last]
5156 -- These checks are not generated for modular types, since the proper
5157 -- semantics for Succ and Pred on modular types is to wrap, not raise CE.
5159 procedure Expand_Pred_Succ (N : Node_Id) is
5160 Loc : constant Source_Ptr := Sloc (N);
5164 if Attribute_Name (N) = Name_Pred then
5171 Make_Raise_Constraint_Error (Loc,
5175 Duplicate_Subexpr_Move_Checks (First (Expressions (N))),
5177 Make_Attribute_Reference (Loc,
5179 New_Reference_To (Base_Type (Etype (Prefix (N))), Loc),
5180 Attribute_Name => Cnam)),
5181 Reason => CE_Overflow_Check_Failed));
5182 end Expand_Pred_Succ;
5188 procedure Find_Fat_Info
5190 Fat_Type : out Entity_Id;
5191 Fat_Pkg : out RE_Id)
5193 Btyp : constant Entity_Id := Base_Type (T);
5194 Rtyp : constant Entity_Id := Root_Type (T);
5195 Digs : constant Nat := UI_To_Int (Digits_Value (Btyp));
5198 -- If the base type is VAX float, then get appropriate VAX float type
5200 if Vax_Float (Btyp) then
5203 Fat_Type := RTE (RE_Fat_VAX_F);
5204 Fat_Pkg := RE_Attr_VAX_F_Float;
5207 Fat_Type := RTE (RE_Fat_VAX_D);
5208 Fat_Pkg := RE_Attr_VAX_D_Float;
5211 Fat_Type := RTE (RE_Fat_VAX_G);
5212 Fat_Pkg := RE_Attr_VAX_G_Float;
5215 raise Program_Error;
5218 -- If root type is VAX float, this is the case where the library has
5219 -- been recompiled in VAX float mode, and we have an IEEE float type.
5220 -- This is when we use the special IEEE Fat packages.
5222 elsif Vax_Float (Rtyp) then
5225 Fat_Type := RTE (RE_Fat_IEEE_Short);
5226 Fat_Pkg := RE_Attr_IEEE_Short;
5229 Fat_Type := RTE (RE_Fat_IEEE_Long);
5230 Fat_Pkg := RE_Attr_IEEE_Long;
5233 raise Program_Error;
5236 -- If neither the base type nor the root type is VAX_Float then VAX
5237 -- float is out of the picture, and we can just use the root type.
5242 if Fat_Type = Standard_Short_Float then
5243 Fat_Pkg := RE_Attr_Short_Float;
5245 elsif Fat_Type = Standard_Float then
5246 Fat_Pkg := RE_Attr_Float;
5248 elsif Fat_Type = Standard_Long_Float then
5249 Fat_Pkg := RE_Attr_Long_Float;
5251 elsif Fat_Type = Standard_Long_Long_Float then
5252 Fat_Pkg := RE_Attr_Long_Long_Float;
5254 -- Universal real (which is its own root type) is treated as being
5255 -- equivalent to Standard.Long_Long_Float, since it is defined to
5256 -- have the same precision as the longest Float type.
5258 elsif Fat_Type = Universal_Real then
5259 Fat_Type := Standard_Long_Long_Float;
5260 Fat_Pkg := RE_Attr_Long_Long_Float;
5263 raise Program_Error;
5268 ----------------------------
5269 -- Find_Stream_Subprogram --
5270 ----------------------------
5272 function Find_Stream_Subprogram
5274 Nam : TSS_Name_Type) return Entity_Id
5276 Ent : constant Entity_Id := TSS (Typ, Nam);
5278 if Present (Ent) then
5282 if Is_Tagged_Type (Typ)
5283 and then Is_Derived_Type (Typ)
5285 return Find_Prim_Op (Typ, Nam);
5287 return Find_Inherited_TSS (Typ, Nam);
5289 end Find_Stream_Subprogram;
5291 -----------------------
5292 -- Get_Index_Subtype --
5293 -----------------------
5295 function Get_Index_Subtype (N : Node_Id) return Node_Id is
5296 P_Type : Entity_Id := Etype (Prefix (N));
5301 if Is_Access_Type (P_Type) then
5302 P_Type := Designated_Type (P_Type);
5305 if No (Expressions (N)) then
5308 J := UI_To_Int (Expr_Value (First (Expressions (N))));
5311 Indx := First_Index (P_Type);
5317 return Etype (Indx);
5318 end Get_Index_Subtype;
5320 -------------------------------
5321 -- Get_Stream_Convert_Pragma --
5322 -------------------------------
5324 function Get_Stream_Convert_Pragma (T : Entity_Id) return Node_Id is
5329 -- Note: we cannot use Get_Rep_Pragma here because of the peculiarity
5330 -- that a stream convert pragma for a tagged type is not inherited from
5331 -- its parent. Probably what is wrong here is that it is basically
5332 -- incorrect to consider a stream convert pragma to be a representation
5333 -- pragma at all ???
5335 N := First_Rep_Item (Implementation_Base_Type (T));
5336 while Present (N) loop
5337 if Nkind (N) = N_Pragma
5338 and then Pragma_Name (N) = Name_Stream_Convert
5340 -- For tagged types this pragma is not inherited, so we
5341 -- must verify that it is defined for the given type and
5345 Entity (Expression (First (Pragma_Argument_Associations (N))));
5347 if not Is_Tagged_Type (T)
5349 or else (Is_Private_Type (Typ) and then T = Full_View (Typ))
5359 end Get_Stream_Convert_Pragma;
5361 ---------------------------------
5362 -- Is_Constrained_Packed_Array --
5363 ---------------------------------
5365 function Is_Constrained_Packed_Array (Typ : Entity_Id) return Boolean is
5366 Arr : Entity_Id := Typ;
5369 if Is_Access_Type (Arr) then
5370 Arr := Designated_Type (Arr);
5373 return Is_Array_Type (Arr)
5374 and then Is_Constrained (Arr)
5375 and then Present (Packed_Array_Type (Arr));
5376 end Is_Constrained_Packed_Array;
5378 ----------------------------------------
5379 -- Is_Inline_Floating_Point_Attribute --
5380 ----------------------------------------
5382 function Is_Inline_Floating_Point_Attribute (N : Node_Id) return Boolean is
5383 Id : constant Attribute_Id := Get_Attribute_Id (Attribute_Name (N));
5386 if Nkind (Parent (N)) /= N_Type_Conversion
5387 or else not Is_Integer_Type (Etype (Parent (N)))
5392 -- Should also support 'Machine_Rounding and 'Unbiased_Rounding, but
5393 -- required back end support has not been implemented yet ???
5395 return Id = Attribute_Truncation;
5396 end Is_Inline_Floating_Point_Attribute;