1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2018, 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 3, 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 COPYING3. If not, go to --
19 -- http://www.gnu.org/licenses for a complete copy of the license. --
21 -- GNAT was originally developed by the GNAT team at New York University. --
22 -- Extensive contributions were provided by Ada Core Technologies Inc. --
24 ------------------------------------------------------------------------------
26 with Aspects
; use Aspects
;
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_Ch3
; use Exp_Ch3
;
34 with Exp_Ch6
; use Exp_Ch6
;
35 with Exp_Ch9
; use Exp_Ch9
;
36 with Exp_Dist
; use Exp_Dist
;
37 with Exp_Imgv
; use Exp_Imgv
;
38 with Exp_Pakd
; use Exp_Pakd
;
39 with Exp_Strm
; use Exp_Strm
;
40 with Exp_Tss
; use Exp_Tss
;
41 with Exp_Util
; use Exp_Util
;
42 with Freeze
; use Freeze
;
43 with Gnatvsn
; use Gnatvsn
;
44 with Itypes
; use Itypes
;
46 with Namet
; use Namet
;
47 with Nmake
; use Nmake
;
48 with Nlists
; use Nlists
;
50 with Restrict
; use Restrict
;
51 with Rident
; use Rident
;
52 with Rtsfind
; use Rtsfind
;
54 with Sem_Aux
; use Sem_Aux
;
55 with Sem_Ch6
; use Sem_Ch6
;
56 with Sem_Ch7
; use Sem_Ch7
;
57 with Sem_Ch8
; use Sem_Ch8
;
58 with Sem_Eval
; use Sem_Eval
;
59 with Sem_Res
; use Sem_Res
;
60 with Sem_Util
; use Sem_Util
;
61 with Sinfo
; use Sinfo
;
62 with Snames
; use Snames
;
63 with Stand
; use Stand
;
64 with Stringt
; use Stringt
;
65 with Tbuild
; use Tbuild
;
66 with Ttypes
; use Ttypes
;
67 with Uintp
; use Uintp
;
68 with Uname
; use Uname
;
69 with Validsw
; use Validsw
;
71 package body Exp_Attr
is
73 -----------------------
74 -- Local Subprograms --
75 -----------------------
77 function Build_Array_VS_Func
79 Formal_Typ
: Entity_Id
;
80 Array_Typ
: Entity_Id
;
81 Comp_Typ
: Entity_Id
) return Entity_Id
;
82 -- Validate the components of an array type by means of a function. Return
83 -- the entity of the validation function. The parameters are as follows:
85 -- * Attr - the 'Valid_Scalars attribute for which the function is
88 -- * Formal_Typ - the type of the generated function's only formal
91 -- * Array_Typ - the array type whose components are to be validated
93 -- * Comp_Typ - the component type of the array
95 function Build_Disp_Get_Task_Id_Call
(Actual
: Node_Id
) return Node_Id
;
96 -- Build a call to Disp_Get_Task_Id, passing Actual as actual parameter
98 function Build_Record_VS_Func
100 Formal_Typ
: Entity_Id
;
101 Rec_Typ
: Entity_Id
) return Entity_Id
;
102 -- Validate the components, discriminants, and variants of a record type by
103 -- means of a function. Return the entity of the validation function. The
104 -- parameters are as follows:
106 -- * Attr - the 'Valid_Scalars attribute for which the function is
109 -- * Formal_Typ - the type of the generated function's only formal
112 -- * Rec_Typ - the record type whose internals are to be validated
114 procedure Compile_Stream_Body_In_Scope
119 -- The body for a stream subprogram may be generated outside of the scope
120 -- of the type. If the type is fully private, it may depend on the full
121 -- view of other types (e.g. indexes) that are currently private as well.
122 -- We install the declarations of the package in which the type is declared
123 -- before compiling the body in what is its proper environment. The Check
124 -- parameter indicates if checks are to be suppressed for the stream body.
125 -- We suppress checks for array/record reads, since the rule is that these
126 -- are like assignments, out of range values due to uninitialized storage,
127 -- or other invalid values do NOT cause a Constraint_Error to be raised.
128 -- If we are within an instance body all visibility has been established
129 -- already and there is no need to install the package.
131 -- This mechanism is now extended to the component types of the array type,
132 -- when the component type is not in scope and is private, to handle
133 -- properly the case when the full view has defaulted discriminants.
135 -- This special processing is ultimately caused by the fact that the
136 -- compiler lacks a well-defined phase when full views are visible
137 -- everywhere. Having such a separate pass would remove much of the
138 -- special-case code that shuffles partial and full views in the middle
139 -- of semantic analysis and expansion.
141 procedure Expand_Access_To_Protected_Op
145 -- An attribute reference to a protected subprogram is transformed into
146 -- a pair of pointers: one to the object, and one to the operations.
147 -- This expansion is performed for 'Access and for 'Unrestricted_Access.
149 procedure Expand_Fpt_Attribute
154 -- This procedure expands a call to a floating-point attribute function.
155 -- N is the attribute reference node, and Args is a list of arguments to
156 -- be passed to the function call. Pkg identifies the package containing
157 -- the appropriate instantiation of System.Fat_Gen. Float arguments in Args
158 -- have already been converted to the floating-point type for which Pkg was
159 -- instantiated. The Nam argument is the relevant attribute processing
160 -- routine to be called. This is the same as the attribute name, except in
161 -- the Unaligned_Valid case.
163 procedure Expand_Fpt_Attribute_R
(N
: Node_Id
);
164 -- This procedure expands a call to a floating-point attribute function
165 -- that takes a single floating-point argument. The function to be called
166 -- is always the same as the attribute name.
168 procedure Expand_Fpt_Attribute_RI
(N
: Node_Id
);
169 -- This procedure expands a call to a floating-point attribute function
170 -- that takes one floating-point argument and one integer argument. The
171 -- function to be called is always the same as the attribute name.
173 procedure Expand_Fpt_Attribute_RR
(N
: Node_Id
);
174 -- This procedure expands a call to a floating-point attribute function
175 -- that takes two floating-point arguments. The function to be called
176 -- is always the same as the attribute name.
178 procedure Expand_Loop_Entry_Attribute
(N
: Node_Id
);
179 -- Handle the expansion of attribute 'Loop_Entry. As a result, the related
180 -- loop may be converted into a conditional block. See body for details.
182 procedure Expand_Min_Max_Attribute
(N
: Node_Id
);
183 -- Handle the expansion of attributes 'Max and 'Min, including expanding
184 -- then out if we are in Modify_Tree_For_C mode.
186 procedure Expand_Pred_Succ_Attribute
(N
: Node_Id
);
187 -- Handles expansion of Pred or Succ attributes for case of non-real
188 -- operand with overflow checking required.
190 procedure Expand_Update_Attribute
(N
: Node_Id
);
191 -- Handle the expansion of attribute Update
193 function Get_Index_Subtype
(N
: Node_Id
) return Entity_Id
;
194 -- Used for Last, Last, and Length, when the prefix is an array type.
195 -- Obtains the corresponding index subtype.
197 procedure Find_Fat_Info
199 Fat_Type
: out Entity_Id
;
200 Fat_Pkg
: out RE_Id
);
201 -- Given a floating-point type T, identifies the package containing the
202 -- attributes for this type (returned in Fat_Pkg), and the corresponding
203 -- type for which this package was instantiated from Fat_Gen. Error if T
204 -- is not a floating-point type.
206 function Find_Stream_Subprogram
208 Nam
: TSS_Name_Type
) return Entity_Id
;
209 -- Returns the stream-oriented subprogram attribute for Typ. For tagged
210 -- types, the corresponding primitive operation is looked up, else the
211 -- appropriate TSS from the type itself, or from its closest ancestor
212 -- defining it, is returned. In both cases, inheritance of representation
213 -- aspects is thus taken into account.
215 function Full_Base
(T
: Entity_Id
) return Entity_Id
;
216 -- The stream functions need to examine the underlying representation of
217 -- composite types. In some cases T may be non-private but its base type
218 -- is, in which case the function returns the corresponding full view.
220 function Get_Stream_Convert_Pragma
(T
: Entity_Id
) return Node_Id
;
221 -- Given a type, find a corresponding stream convert pragma that applies to
222 -- the implementation base type of this type (Typ). If found, return the
223 -- pragma node, otherwise return Empty if no pragma is found.
225 function Is_Constrained_Packed_Array
(Typ
: Entity_Id
) return Boolean;
226 -- Utility for array attributes, returns true on packed constrained
227 -- arrays, and on access to same.
229 function Is_Inline_Floating_Point_Attribute
(N
: Node_Id
) return Boolean;
230 -- Returns true iff the given node refers to an attribute call that
231 -- can be expanded directly by the back end and does not need front end
232 -- expansion. Typically used for rounding and truncation attributes that
233 -- appear directly inside a conversion to integer.
235 -------------------------
236 -- Build_Array_VS_Func --
237 -------------------------
239 function Build_Array_VS_Func
241 Formal_Typ
: Entity_Id
;
242 Array_Typ
: Entity_Id
;
243 Comp_Typ
: Entity_Id
) return Entity_Id
245 Loc
: constant Source_Ptr
:= Sloc
(Attr
);
247 function Validate_Component
249 Indexes
: List_Id
) return Node_Id
;
250 -- Process a single component denoted by indexes Indexes. Obj_Id denotes
251 -- the entity of the validation parameter. Return the check associated
252 -- with the component.
254 function Validate_Dimension
257 Indexes
: List_Id
) return Node_Id
;
258 -- Process dimension Dim of the array type. Obj_Id denotes the entity
259 -- of the validation parameter. Indexes is a list where each dimension
260 -- deposits its loop variable, which will later identify a component.
261 -- Return the loop associated with the current dimension.
263 ------------------------
264 -- Validate_Component --
265 ------------------------
267 function Validate_Component
269 Indexes
: List_Id
) return Node_Id
274 if Is_Scalar_Type
(Comp_Typ
) then
275 Attr_Nam
:= Name_Valid
;
277 Attr_Nam
:= Name_Valid_Scalars
;
281 -- if not Array_Typ (Obj_Id) (Indexes)'Valid[_Scalars] then
286 Make_If_Statement
(Loc
,
290 Make_Attribute_Reference
(Loc
,
292 Make_Indexed_Component
(Loc
,
294 Unchecked_Convert_To
(Array_Typ
,
295 New_Occurrence_Of
(Obj_Id
, Loc
)),
296 Expressions
=> Indexes
),
297 Attribute_Name
=> Attr_Nam
)),
299 Then_Statements
=> New_List
(
300 Make_Simple_Return_Statement
(Loc
,
301 Expression
=> New_Occurrence_Of
(Standard_False
, Loc
))));
302 end Validate_Component
;
304 ------------------------
305 -- Validate_Dimension --
306 ------------------------
308 function Validate_Dimension
311 Indexes
: List_Id
) return Node_Id
316 -- Validate the component once all dimensions have produced their
319 if Dim
> Number_Dimensions
(Array_Typ
) then
320 return Validate_Component
(Obj_Id
, Indexes
);
322 -- Process the current dimension
326 Make_Defining_Identifier
(Loc
, New_External_Name
('J', Dim
));
328 Append_To
(Indexes
, New_Occurrence_Of
(Index
, Loc
));
331 -- for J1 in Array_Typ (Obj_Id)'Range (1) loop
332 -- for JN in Array_Typ (Obj_Id)'Range (N) loop
333 -- if not Array_Typ (Obj_Id) (Indexes)'Valid[_Scalars]
341 Make_Implicit_Loop_Statement
(Attr
,
344 Make_Iteration_Scheme
(Loc
,
345 Loop_Parameter_Specification
=>
346 Make_Loop_Parameter_Specification
(Loc
,
347 Defining_Identifier
=> Index
,
348 Discrete_Subtype_Definition
=>
349 Make_Attribute_Reference
(Loc
,
351 Unchecked_Convert_To
(Array_Typ
,
352 New_Occurrence_Of
(Obj_Id
, Loc
)),
353 Attribute_Name
=> Name_Range
,
354 Expressions
=> New_List
(
355 Make_Integer_Literal
(Loc
, Dim
))))),
356 Statements
=> New_List
(
357 Validate_Dimension
(Obj_Id
, Dim
+ 1, Indexes
)));
359 end Validate_Dimension
;
363 Func_Id
: constant Entity_Id
:= Make_Temporary
(Loc
, 'V');
364 Indexes
: constant List_Id
:= New_List
;
365 Obj_Id
: constant Entity_Id
:= Make_Temporary
(Loc
, 'A');
368 -- Start of processing for Build_Array_VS_Func
371 Stmts
:= New_List
(Validate_Dimension
(Obj_Id
, 1, Indexes
));
377 Make_Simple_Return_Statement
(Loc
,
378 Expression
=> New_Occurrence_Of
(Standard_True
, Loc
)));
381 -- function Func_Id (Obj_Id : Formal_Typ) return Boolean is
386 Set_Ekind
(Func_Id
, E_Function
);
387 Set_Is_Internal
(Func_Id
);
388 Set_Is_Pure
(Func_Id
);
390 if not Debug_Generated_Code
then
391 Set_Debug_Info_Off
(Func_Id
);
395 Make_Subprogram_Body
(Loc
,
397 Make_Function_Specification
(Loc
,
398 Defining_Unit_Name
=> Func_Id
,
399 Parameter_Specifications
=> New_List
(
400 Make_Parameter_Specification
(Loc
,
401 Defining_Identifier
=> Obj_Id
,
403 Out_Present
=> False,
404 Parameter_Type
=> New_Occurrence_Of
(Formal_Typ
, Loc
))),
406 New_Occurrence_Of
(Standard_Boolean
, Loc
)),
407 Declarations
=> New_List
,
408 Handled_Statement_Sequence
=>
409 Make_Handled_Sequence_Of_Statements
(Loc
,
410 Statements
=> Stmts
)));
413 end Build_Array_VS_Func
;
415 ---------------------------------
416 -- Build_Disp_Get_Task_Id_Call --
417 ---------------------------------
419 function Build_Disp_Get_Task_Id_Call
(Actual
: Node_Id
) return Node_Id
is
420 Loc
: constant Source_Ptr
:= Sloc
(Actual
);
421 Typ
: constant Entity_Id
:= Etype
(Actual
);
422 Subp
: constant Entity_Id
:= Find_Prim_Op
(Typ
, Name_uDisp_Get_Task_Id
);
426 -- _Disp_Get_Task_Id (Actual)
429 Make_Function_Call
(Loc
,
430 Name
=> New_Occurrence_Of
(Subp
, Loc
),
431 Parameter_Associations
=> New_List
(Actual
));
432 end Build_Disp_Get_Task_Id_Call
;
434 --------------------------
435 -- Build_Record_VS_Func --
436 --------------------------
438 function Build_Record_VS_Func
440 Formal_Typ
: Entity_Id
;
441 Rec_Typ
: Entity_Id
) return Entity_Id
443 -- NOTE: The logic of Build_Record_VS_Func is intentionally passive.
444 -- It generates code only when there are components, discriminants,
445 -- or variant parts to validate.
447 -- NOTE: The routines within Build_Record_VS_Func are intentionally
448 -- unnested to avoid deep indentation of code.
450 Loc
: constant Source_Ptr
:= Sloc
(Attr
);
452 procedure Validate_Component_List
455 Stmts
: in out List_Id
);
456 -- Process all components and variant parts of component list Comp_List.
457 -- Obj_Id denotes the entity of the validation parameter. All new code
458 -- is added to list Stmts.
460 procedure Validate_Field
463 Cond
: in out Node_Id
);
464 -- Process component declaration or discriminant specification Field.
465 -- Obj_Id denotes the entity of the validation parameter. Cond denotes
466 -- an "or else" conditional expression which contains the new code (if
469 procedure Validate_Fields
472 Stmts
: in out List_Id
);
473 -- Process component declarations or discriminant specifications in list
474 -- Fields. Obj_Id denotes the entity of the validation parameter. All
475 -- new code is added to list Stmts.
477 procedure Validate_Variant
480 Alts
: in out List_Id
);
481 -- Process variant Var. Obj_Id denotes the entity of the validation
482 -- parameter. Alts denotes a list of case statement alternatives which
483 -- contains the new code (if any).
485 procedure Validate_Variant_Part
488 Stmts
: in out List_Id
);
489 -- Process variant part Var_Part. Obj_Id denotes the entity of the
490 -- validation parameter. All new code is added to list Stmts.
492 -----------------------------
493 -- Validate_Component_List --
494 -----------------------------
496 procedure Validate_Component_List
499 Stmts
: in out List_Id
)
501 Var_Part
: constant Node_Id
:= Variant_Part
(Comp_List
);
504 -- Validate all components
508 Fields
=> Component_Items
(Comp_List
),
511 -- Validate the variant part
513 if Present
(Var_Part
) then
514 Validate_Variant_Part
516 Var_Part
=> Var_Part
,
519 end Validate_Component_List
;
525 procedure Validate_Field
528 Cond
: in out Node_Id
)
530 Field_Id
: constant Entity_Id
:= Defining_Entity
(Field
);
531 Field_Nam
: constant Name_Id
:= Chars
(Field_Id
);
532 Field_Typ
: constant Entity_Id
:= Validated_View
(Etype
(Field_Id
));
536 -- Do not process internally-generated fields. Note that checking for
537 -- Comes_From_Source is not correct because this will eliminate the
538 -- components within the corresponding record of a protected type.
540 if Nam_In
(Field_Nam
, Name_uObject
,
546 -- Do not process fields without any scalar components
548 elsif not Scalar_Part_Present
(Field_Typ
) then
551 -- Otherwise the field needs to be validated. Use Make_Identifier
552 -- rather than New_Occurrence_Of to identify the field because the
553 -- wrong entity may be picked up when private types are involved.
556 -- [or else] not Rec_Typ (Obj_Id).Item_Nam'Valid[_Scalars]
559 if Is_Scalar_Type
(Field_Typ
) then
560 Attr_Nam
:= Name_Valid
;
562 Attr_Nam
:= Name_Valid_Scalars
;
565 Evolve_Or_Else
(Cond
,
568 Make_Attribute_Reference
(Loc
,
570 Make_Selected_Component
(Loc
,
572 Unchecked_Convert_To
(Rec_Typ
,
573 New_Occurrence_Of
(Obj_Id
, Loc
)),
574 Selector_Name
=> Make_Identifier
(Loc
, Field_Nam
)),
575 Attribute_Name
=> Attr_Nam
)));
579 ---------------------
580 -- Validate_Fields --
581 ---------------------
583 procedure Validate_Fields
586 Stmts
: in out List_Id
)
592 -- Assume that none of the fields are eligible for verification
596 -- Validate all fields
598 Field
:= First_Non_Pragma
(Fields
);
599 while Present
(Field
) loop
605 Next_Non_Pragma
(Field
);
609 -- if not Rec_Typ (Obj_Id).Item_Nam_1'Valid[_Scalars]
610 -- or else not Rec_Typ (Obj_Id).Item_Nam_N'Valid[_Scalars]
615 if Present
(Cond
) then
616 Append_New_To
(Stmts
,
617 Make_Implicit_If_Statement
(Attr
,
619 Then_Statements
=> New_List
(
620 Make_Simple_Return_Statement
(Loc
,
621 Expression
=> New_Occurrence_Of
(Standard_False
, Loc
)))));
625 ----------------------
626 -- Validate_Variant --
627 ----------------------
629 procedure Validate_Variant
632 Alts
: in out List_Id
)
637 -- Assume that none of the components and variants are eligible for
642 -- Validate componants
644 Validate_Component_List
646 Comp_List
=> Component_List
(Var
),
649 -- Generate a null statement in case none of the components were
650 -- verified because this will otherwise eliminate an alternative
651 -- from the variant case statement and render the generated code
655 Append_New_To
(Stmts
, Make_Null_Statement
(Loc
));
659 -- when Discrete_Choices =>
663 Make_Case_Statement_Alternative
(Loc
,
665 New_Copy_List_Tree
(Discrete_Choices
(Var
)),
666 Statements
=> Stmts
));
667 end Validate_Variant
;
669 ---------------------------
670 -- Validate_Variant_Part --
671 ---------------------------
673 procedure Validate_Variant_Part
676 Stmts
: in out List_Id
)
678 Vars
: constant List_Id
:= Variants
(Var_Part
);
683 -- Assume that none of the variants are eligible for verification
689 Var
:= First_Non_Pragma
(Vars
);
690 while Present
(Var
) loop
696 Next_Non_Pragma
(Var
);
699 -- Even though individual variants may lack eligible components, the
700 -- alternatives must still be generated.
702 pragma Assert
(Present
(Alts
));
705 -- case Rec_Typ (Obj_Id).Discriminant is
706 -- when Discrete_Choices_1 =>
708 -- when Discrete_Choices_N =>
712 Append_New_To
(Stmts
,
713 Make_Case_Statement
(Loc
,
715 Make_Selected_Component
(Loc
,
717 Unchecked_Convert_To
(Rec_Typ
,
718 New_Occurrence_Of
(Obj_Id
, Loc
)),
719 Selector_Name
=> New_Copy_Tree
(Name
(Var_Part
))),
720 Alternatives
=> Alts
));
721 end Validate_Variant_Part
;
725 Func_Id
: constant Entity_Id
:= Make_Temporary
(Loc
, 'V');
726 Obj_Id
: constant Entity_Id
:= Make_Temporary
(Loc
, 'R');
727 Rec_Decl
: constant Node_Id
:= Declaration_Node
(Rec_Typ
);
728 Rec_Def
: constant Node_Id
:= Type_Definition
(Rec_Decl
);
731 -- Start of processing for Build_Record_VS_Func
734 -- The code generated by this routine is as follows:
736 -- function Func_Id (Obj_Id : Formal_Typ) return Boolean is
738 -- if not Rec_Typ (Obj_Id).Discriminant_1'Valid[_Scalars]
739 -- or else not Rec_Typ (Obj_Id).Discriminant_N'Valid[_Scalars]
744 -- if not Rec_Typ (Obj_Id).Component_1'Valid[_Scalars]
745 -- or else not Rec_Typ (Obj_Id).Component_N'Valid[_Scalars]
750 -- case Discriminant_1 is
752 -- if not Rec_Typ (Obj_Id).Component_1'Valid[_Scalars]
753 -- or else not Rec_Typ (Obj_Id).Component_N'Valid[_Scalars]
758 -- case Discriminant_N is
767 -- Assume that the record type lacks eligible components, discriminants,
768 -- and variant parts.
772 -- Validate the discriminants
774 if not Is_Unchecked_Union
(Rec_Typ
) then
777 Fields
=> Discriminant_Specifications
(Rec_Decl
),
781 -- Validate the components and variant parts
783 Validate_Component_List
785 Comp_List
=> Component_List
(Rec_Def
),
791 Append_New_To
(Stmts
,
792 Make_Simple_Return_Statement
(Loc
,
793 Expression
=> New_Occurrence_Of
(Standard_True
, Loc
)));
796 -- function Func_Id (Obj_Id : Formal_Typ) return Boolean is
801 Set_Ekind
(Func_Id
, E_Function
);
802 Set_Is_Internal
(Func_Id
);
803 Set_Is_Pure
(Func_Id
);
805 if not Debug_Generated_Code
then
806 Set_Debug_Info_Off
(Func_Id
);
810 Make_Subprogram_Body
(Loc
,
812 Make_Function_Specification
(Loc
,
813 Defining_Unit_Name
=> Func_Id
,
814 Parameter_Specifications
=> New_List
(
815 Make_Parameter_Specification
(Loc
,
816 Defining_Identifier
=> Obj_Id
,
817 Parameter_Type
=> New_Occurrence_Of
(Formal_Typ
, Loc
))),
819 New_Occurrence_Of
(Standard_Boolean
, Loc
)),
820 Declarations
=> New_List
,
821 Handled_Statement_Sequence
=>
822 Make_Handled_Sequence_Of_Statements
(Loc
,
823 Statements
=> Stmts
)),
824 Suppress
=> Discriminant_Check
);
827 end Build_Record_VS_Func
;
829 ----------------------------------
830 -- Compile_Stream_Body_In_Scope --
831 ----------------------------------
833 procedure Compile_Stream_Body_In_Scope
839 C_Type
: constant Entity_Id
:= Base_Type
(Component_Type
(Arr
));
840 Curr
: constant Entity_Id
:= Current_Scope
;
841 Install
: Boolean := False;
842 Scop
: Entity_Id
:= Scope
(Arr
);
846 and then not In_Open_Scopes
(Scop
)
847 and then Ekind
(Scop
) = E_Package
852 -- The component type may be private, in which case we install its
853 -- full view to compile the subprogram.
855 -- The component type may be private, in which case we install its
856 -- full view to compile the subprogram. We do not do this if the
857 -- type has a Stream_Convert pragma, which indicates that there are
858 -- special stream-processing operations for that type (for example
859 -- Unbounded_String and its wide varieties).
861 Scop
:= Scope
(C_Type
);
863 if Is_Private_Type
(C_Type
)
864 and then Present
(Full_View
(C_Type
))
865 and then not In_Open_Scopes
(Scop
)
866 and then Ekind
(Scop
) = E_Package
867 and then No
(Get_Stream_Convert_Pragma
(C_Type
))
873 -- If we are within an instance body, then all visibility has been
874 -- established already and there is no need to install the package.
876 if Install
and then not In_Instance_Body
then
878 Install_Visible_Declarations
(Scop
);
879 Install_Private_Declarations
(Scop
);
881 -- The entities in the package are now visible, but the generated
882 -- stream entity must appear in the current scope (usually an
883 -- enclosing stream function) so that itypes all have their proper
892 Insert_Action
(N
, Decl
);
894 Insert_Action
(N
, Decl
, Suppress
=> All_Checks
);
899 -- Remove extra copy of current scope, and package itself
902 End_Package_Scope
(Scop
);
904 end Compile_Stream_Body_In_Scope
;
906 -----------------------------------
907 -- Expand_Access_To_Protected_Op --
908 -----------------------------------
910 procedure Expand_Access_To_Protected_Op
915 -- The value of the attribute_reference is a record containing two
916 -- fields: an access to the protected object, and an access to the
917 -- subprogram itself. The prefix is a selected component.
919 Loc
: constant Source_Ptr
:= Sloc
(N
);
921 Btyp
: constant Entity_Id
:= Base_Type
(Typ
);
924 E_T
: constant Entity_Id
:= Equivalent_Type
(Btyp
);
925 Acc
: constant Entity_Id
:=
926 Etype
(Next_Component
(First_Component
(E_T
)));
930 -- Start of processing for Expand_Access_To_Protected_Op
933 -- Within the body of the protected type, the prefix designates a local
934 -- operation, and the object is the first parameter of the corresponding
935 -- protected body of the current enclosing operation.
937 if Is_Entity_Name
(Pref
) then
938 -- All indirect calls are external calls, so must do locking and
939 -- barrier reevaluation, even if the 'Access occurs within the
940 -- protected body. Hence the call to External_Subprogram, as opposed
941 -- to Protected_Body_Subprogram, below. See RM-9.5(5). This means
942 -- that indirect calls from within the same protected body will
943 -- deadlock, as allowed by RM-9.5.1(8,15,17).
945 Sub
:= New_Occurrence_Of
(External_Subprogram
(Entity
(Pref
)), Loc
);
947 -- Don't traverse the scopes when the attribute occurs within an init
948 -- proc, because we directly use the _init formal of the init proc in
951 Curr
:= Current_Scope
;
952 if not Is_Init_Proc
(Curr
) then
953 pragma Assert
(In_Open_Scopes
(Scope
(Entity
(Pref
))));
955 while Scope
(Curr
) /= Scope
(Entity
(Pref
)) loop
956 Curr
:= Scope
(Curr
);
960 -- In case of protected entries the first formal of its Protected_
961 -- Body_Subprogram is the address of the object.
963 if Ekind
(Curr
) = E_Entry
then
967 (Protected_Body_Subprogram
(Curr
)), Loc
);
969 -- If the current scope is an init proc, then use the address of the
970 -- _init formal as the object reference.
972 elsif Is_Init_Proc
(Curr
) then
974 Make_Attribute_Reference
(Loc
,
975 Prefix
=> New_Occurrence_Of
(First_Formal
(Curr
), Loc
),
976 Attribute_Name
=> Name_Address
);
978 -- In case of protected subprograms the first formal of its
979 -- Protected_Body_Subprogram is the object and we get its address.
983 Make_Attribute_Reference
(Loc
,
987 (Protected_Body_Subprogram
(Curr
)), Loc
),
988 Attribute_Name
=> Name_Address
);
991 -- Case where the prefix is not an entity name. Find the
992 -- version of the protected operation to be called from
993 -- outside the protected object.
999 (Entity
(Selector_Name
(Pref
))), Loc
);
1002 Make_Attribute_Reference
(Loc
,
1003 Prefix
=> Relocate_Node
(Prefix
(Pref
)),
1004 Attribute_Name
=> Name_Address
);
1008 Make_Attribute_Reference
(Loc
,
1010 Attribute_Name
=> Name_Access
);
1012 -- We set the type of the access reference to the already generated
1013 -- access_to_subprogram type, and declare the reference analyzed, to
1014 -- prevent further expansion when the enclosing aggregate is analyzed.
1016 Set_Etype
(Sub_Ref
, Acc
);
1017 Set_Analyzed
(Sub_Ref
);
1020 Make_Aggregate
(Loc
,
1021 Expressions
=> New_List
(Obj_Ref
, Sub_Ref
));
1023 -- Sub_Ref has been marked as analyzed, but we still need to make sure
1024 -- Sub is correctly frozen.
1026 Freeze_Before
(N
, Entity
(Sub
));
1029 Analyze_And_Resolve
(N
, E_T
);
1031 -- For subsequent analysis, the node must retain its type. The backend
1032 -- will replace it with the equivalent type where needed.
1035 end Expand_Access_To_Protected_Op
;
1037 --------------------------
1038 -- Expand_Fpt_Attribute --
1039 --------------------------
1041 procedure Expand_Fpt_Attribute
1047 Loc
: constant Source_Ptr
:= Sloc
(N
);
1048 Typ
: constant Entity_Id
:= Etype
(N
);
1052 -- The function name is the selected component Attr_xxx.yyy where
1053 -- Attr_xxx is the package name, and yyy is the argument Nam.
1055 -- Note: it would be more usual to have separate RE entries for each
1056 -- of the entities in the Fat packages, but first they have identical
1057 -- names (so we would have to have lots of renaming declarations to
1058 -- meet the normal RE rule of separate names for all runtime entities),
1059 -- and second there would be an awful lot of them.
1062 Make_Selected_Component
(Loc
,
1063 Prefix
=> New_Occurrence_Of
(RTE
(Pkg
), Loc
),
1064 Selector_Name
=> Make_Identifier
(Loc
, Nam
));
1066 -- The generated call is given the provided set of parameters, and then
1067 -- wrapped in a conversion which converts the result to the target type
1068 -- We use the base type as the target because a range check may be
1072 Unchecked_Convert_To
(Base_Type
(Etype
(N
)),
1073 Make_Function_Call
(Loc
,
1075 Parameter_Associations
=> Args
)));
1077 Analyze_And_Resolve
(N
, Typ
);
1078 end Expand_Fpt_Attribute
;
1080 ----------------------------
1081 -- Expand_Fpt_Attribute_R --
1082 ----------------------------
1084 -- The single argument is converted to its root type to call the
1085 -- appropriate runtime function, with the actual call being built
1086 -- by Expand_Fpt_Attribute
1088 procedure Expand_Fpt_Attribute_R
(N
: Node_Id
) is
1089 E1
: constant Node_Id
:= First
(Expressions
(N
));
1093 Find_Fat_Info
(Etype
(E1
), Ftp
, Pkg
);
1094 Expand_Fpt_Attribute
1095 (N
, Pkg
, Attribute_Name
(N
),
1096 New_List
(Unchecked_Convert_To
(Ftp
, Relocate_Node
(E1
))));
1097 end Expand_Fpt_Attribute_R
;
1099 -----------------------------
1100 -- Expand_Fpt_Attribute_RI --
1101 -----------------------------
1103 -- The first argument is converted to its root type and the second
1104 -- argument is converted to standard long long integer to call the
1105 -- appropriate runtime function, with the actual call being built
1106 -- by Expand_Fpt_Attribute
1108 procedure Expand_Fpt_Attribute_RI
(N
: Node_Id
) is
1109 E1
: constant Node_Id
:= First
(Expressions
(N
));
1112 E2
: constant Node_Id
:= Next
(E1
);
1114 Find_Fat_Info
(Etype
(E1
), Ftp
, Pkg
);
1115 Expand_Fpt_Attribute
1116 (N
, Pkg
, Attribute_Name
(N
),
1118 Unchecked_Convert_To
(Ftp
, Relocate_Node
(E1
)),
1119 Unchecked_Convert_To
(Standard_Integer
, Relocate_Node
(E2
))));
1120 end Expand_Fpt_Attribute_RI
;
1122 -----------------------------
1123 -- Expand_Fpt_Attribute_RR --
1124 -----------------------------
1126 -- The two arguments are converted to their root types to call the
1127 -- appropriate runtime function, with the actual call being built
1128 -- by Expand_Fpt_Attribute
1130 procedure Expand_Fpt_Attribute_RR
(N
: Node_Id
) is
1131 E1
: constant Node_Id
:= First
(Expressions
(N
));
1132 E2
: constant Node_Id
:= Next
(E1
);
1137 Find_Fat_Info
(Etype
(E1
), Ftp
, Pkg
);
1138 Expand_Fpt_Attribute
1139 (N
, Pkg
, Attribute_Name
(N
),
1141 Unchecked_Convert_To
(Ftp
, Relocate_Node
(E1
)),
1142 Unchecked_Convert_To
(Ftp
, Relocate_Node
(E2
))));
1143 end Expand_Fpt_Attribute_RR
;
1145 ---------------------------------
1146 -- Expand_Loop_Entry_Attribute --
1147 ---------------------------------
1149 procedure Expand_Loop_Entry_Attribute
(N
: Node_Id
) is
1150 procedure Build_Conditional_Block
1153 Loop_Stmt
: Node_Id
;
1154 If_Stmt
: out Node_Id
;
1155 Blk_Stmt
: out Node_Id
);
1156 -- Create a block Blk_Stmt with an empty declarative list and a single
1157 -- loop Loop_Stmt. The block is encased in an if statement If_Stmt with
1158 -- condition Cond. If_Stmt is Empty when there is no condition provided.
1160 function Is_Array_Iteration
(N
: Node_Id
) return Boolean;
1161 -- Determine whether loop statement N denotes an Ada 2012 iteration over
1164 -----------------------------
1165 -- Build_Conditional_Block --
1166 -----------------------------
1168 procedure Build_Conditional_Block
1171 Loop_Stmt
: Node_Id
;
1172 If_Stmt
: out Node_Id
;
1173 Blk_Stmt
: out Node_Id
)
1176 -- Do not reanalyze the original loop statement because it is simply
1179 Set_Analyzed
(Loop_Stmt
);
1182 Make_Block_Statement
(Loc
,
1183 Declarations
=> New_List
,
1184 Handled_Statement_Sequence
=>
1185 Make_Handled_Sequence_Of_Statements
(Loc
,
1186 Statements
=> New_List
(Loop_Stmt
)));
1188 if Present
(Cond
) then
1190 Make_If_Statement
(Loc
,
1192 Then_Statements
=> New_List
(Blk_Stmt
));
1196 end Build_Conditional_Block
;
1198 ------------------------
1199 -- Is_Array_Iteration --
1200 ------------------------
1202 function Is_Array_Iteration
(N
: Node_Id
) return Boolean is
1203 Stmt
: constant Node_Id
:= Original_Node
(N
);
1207 if Nkind
(Stmt
) = N_Loop_Statement
1208 and then Present
(Iteration_Scheme
(Stmt
))
1209 and then Present
(Iterator_Specification
(Iteration_Scheme
(Stmt
)))
1211 Iter
:= Iterator_Specification
(Iteration_Scheme
(Stmt
));
1214 Of_Present
(Iter
) and then Is_Array_Type
(Etype
(Name
(Iter
)));
1218 end Is_Array_Iteration
;
1222 Pref
: constant Node_Id
:= Prefix
(N
);
1223 Base_Typ
: constant Entity_Id
:= Base_Type
(Etype
(Pref
));
1224 Exprs
: constant List_Id
:= Expressions
(N
);
1226 Blk
: Node_Id
:= Empty
;
1228 Installed
: Boolean;
1230 Loop_Id
: Entity_Id
;
1231 Loop_Stmt
: Node_Id
;
1232 Result
: Node_Id
:= Empty
;
1234 Temp_Decl
: Node_Id
;
1235 Temp_Id
: Entity_Id
;
1237 -- Start of processing for Expand_Loop_Entry_Attribute
1240 -- Step 1: Find the related loop
1242 -- The loop label variant of attribute 'Loop_Entry already has all the
1243 -- information in its expression.
1245 if Present
(Exprs
) then
1246 Loop_Id
:= Entity
(First
(Exprs
));
1247 Loop_Stmt
:= Label_Construct
(Parent
(Loop_Id
));
1249 -- Climb the parent chain to find the nearest enclosing loop. Skip
1250 -- all internally generated loops for quantified expressions and for
1251 -- element iterators over multidimensional arrays because the pragma
1252 -- applies to source loop.
1256 while Present
(Loop_Stmt
) loop
1257 if Nkind
(Loop_Stmt
) = N_Loop_Statement
1258 and then Nkind
(Original_Node
(Loop_Stmt
)) = N_Loop_Statement
1259 and then Comes_From_Source
(Original_Node
(Loop_Stmt
))
1264 Loop_Stmt
:= Parent
(Loop_Stmt
);
1267 Loop_Id
:= Entity
(Identifier
(Loop_Stmt
));
1270 Loc
:= Sloc
(Loop_Stmt
);
1272 -- Step 2: Transform the loop
1274 -- The loop has already been transformed during the expansion of a prior
1275 -- 'Loop_Entry attribute. Retrieve the declarative list of the block.
1277 if Has_Loop_Entry_Attributes
(Loop_Id
) then
1279 -- When the related loop name appears as the argument of attribute
1280 -- Loop_Entry, the corresponding label construct is the generated
1281 -- block statement. This is because the expander reuses the label.
1283 if Nkind
(Loop_Stmt
) = N_Block_Statement
then
1284 Decls
:= Declarations
(Loop_Stmt
);
1286 -- In all other cases, the loop must appear in the handled sequence
1287 -- of statements of the generated block.
1291 (Nkind
(Parent
(Loop_Stmt
)) = N_Handled_Sequence_Of_Statements
1293 Nkind
(Parent
(Parent
(Loop_Stmt
))) = N_Block_Statement
);
1295 Decls
:= Declarations
(Parent
(Parent
(Loop_Stmt
)));
1298 -- Transform the loop into a conditional block
1301 Set_Has_Loop_Entry_Attributes
(Loop_Id
);
1302 Scheme
:= Iteration_Scheme
(Loop_Stmt
);
1304 -- Infinite loops are transformed into:
1307 -- Temp1 : constant <type of Pref1> := <Pref1>;
1309 -- TempN : constant <type of PrefN> := <PrefN>;
1312 -- <original source statements with attribute rewrites>
1317 Build_Conditional_Block
(Loc
,
1319 Loop_Stmt
=> Relocate_Node
(Loop_Stmt
),
1325 -- While loops are transformed into:
1327 -- function Fnn return Boolean is
1329 -- <condition actions>
1330 -- return <condition>;
1335 -- Temp1 : constant <type of Pref1> := <Pref1>;
1337 -- TempN : constant <type of PrefN> := <PrefN>;
1340 -- <original source statements with attribute rewrites>
1341 -- exit when not Fnn;
1346 -- Note that loops over iterators and containers are already
1347 -- converted into while loops.
1349 elsif Present
(Condition
(Scheme
)) then
1351 Func_Decl
: Node_Id
;
1352 Func_Id
: Entity_Id
;
1356 -- Wrap the condition of the while loop in a Boolean function.
1357 -- This avoids the duplication of the same code which may lead
1358 -- to gigi issues with respect to multiple declaration of the
1359 -- same entity in the presence of side effects or checks. Note
1360 -- that the condition actions must also be relocated to the
1361 -- wrapping function.
1364 -- <condition actions>
1365 -- return <condition>;
1367 if Present
(Condition_Actions
(Scheme
)) then
1368 Stmts
:= Condition_Actions
(Scheme
);
1374 Make_Simple_Return_Statement
(Loc
,
1375 Expression
=> Relocate_Node
(Condition
(Scheme
))));
1378 -- function Fnn return Boolean is
1383 Func_Id
:= Make_Temporary
(Loc
, 'F');
1385 Make_Subprogram_Body
(Loc
,
1387 Make_Function_Specification
(Loc
,
1388 Defining_Unit_Name
=> Func_Id
,
1389 Result_Definition
=>
1390 New_Occurrence_Of
(Standard_Boolean
, Loc
)),
1391 Declarations
=> Empty_List
,
1392 Handled_Statement_Sequence
=>
1393 Make_Handled_Sequence_Of_Statements
(Loc
,
1394 Statements
=> Stmts
));
1396 -- The function is inserted before the related loop. Make sure
1397 -- to analyze it in the context of the loop's enclosing scope.
1399 Push_Scope
(Scope
(Loop_Id
));
1400 Insert_Action
(Loop_Stmt
, Func_Decl
);
1403 -- Transform the original while loop into an infinite loop
1404 -- where the last statement checks the negated condition. This
1405 -- placement ensures that the condition will not be evaluated
1406 -- twice on the first iteration.
1408 Set_Iteration_Scheme
(Loop_Stmt
, Empty
);
1412 -- exit when not Fnn;
1414 Append_To
(Statements
(Loop_Stmt
),
1415 Make_Exit_Statement
(Loc
,
1419 Make_Function_Call
(Loc
,
1420 Name
=> New_Occurrence_Of
(Func_Id
, Loc
)))));
1422 Build_Conditional_Block
(Loc
,
1424 Make_Function_Call
(Loc
,
1425 Name
=> New_Occurrence_Of
(Func_Id
, Loc
)),
1426 Loop_Stmt
=> Relocate_Node
(Loop_Stmt
),
1431 -- Ada 2012 iteration over an array is transformed into:
1433 -- if <Array_Nam>'Length (1) > 0
1434 -- and then <Array_Nam>'Length (N) > 0
1437 -- Temp1 : constant <type of Pref1> := <Pref1>;
1439 -- TempN : constant <type of PrefN> := <PrefN>;
1441 -- for X in ... loop -- multiple loops depending on dims
1442 -- <original source statements with attribute rewrites>
1447 elsif Is_Array_Iteration
(Loop_Stmt
) then
1449 Array_Nam
: constant Entity_Id
:=
1450 Entity
(Name
(Iterator_Specification
1451 (Iteration_Scheme
(Original_Node
(Loop_Stmt
)))));
1452 Num_Dims
: constant Pos
:=
1453 Number_Dimensions
(Etype
(Array_Nam
));
1454 Cond
: Node_Id
:= Empty
;
1458 -- Generate a check which determines whether all dimensions of
1459 -- the array are non-null.
1461 for Dim
in 1 .. Num_Dims
loop
1465 Make_Attribute_Reference
(Loc
,
1466 Prefix
=> New_Occurrence_Of
(Array_Nam
, Loc
),
1467 Attribute_Name
=> Name_Length
,
1468 Expressions
=> New_List
(
1469 Make_Integer_Literal
(Loc
, Dim
))),
1471 Make_Integer_Literal
(Loc
, 0));
1479 Right_Opnd
=> Check
);
1483 Build_Conditional_Block
(Loc
,
1485 Loop_Stmt
=> Relocate_Node
(Loop_Stmt
),
1490 -- For loops are transformed into:
1492 -- if <Low> <= <High> then
1494 -- Temp1 : constant <type of Pref1> := <Pref1>;
1496 -- TempN : constant <type of PrefN> := <PrefN>;
1498 -- for <Def_Id> in <Low> .. <High> loop
1499 -- <original source statements with attribute rewrites>
1504 elsif Present
(Loop_Parameter_Specification
(Scheme
)) then
1506 Loop_Spec
: constant Node_Id
:=
1507 Loop_Parameter_Specification
(Scheme
);
1512 Subt_Def
:= Discrete_Subtype_Definition
(Loop_Spec
);
1514 -- When the loop iterates over a subtype indication with a
1515 -- range, use the low and high bounds of the subtype itself.
1517 if Nkind
(Subt_Def
) = N_Subtype_Indication
then
1518 Subt_Def
:= Scalar_Range
(Etype
(Subt_Def
));
1521 pragma Assert
(Nkind
(Subt_Def
) = N_Range
);
1528 Left_Opnd
=> New_Copy_Tree
(Low_Bound
(Subt_Def
)),
1529 Right_Opnd
=> New_Copy_Tree
(High_Bound
(Subt_Def
)));
1531 Build_Conditional_Block
(Loc
,
1533 Loop_Stmt
=> Relocate_Node
(Loop_Stmt
),
1539 Decls
:= Declarations
(Blk
);
1542 -- Step 3: Create a constant to capture the value of the prefix at the
1543 -- entry point into the loop.
1545 Temp_Id
:= Make_Temporary
(Loc
, 'P');
1547 -- Preserve the tag of the prefix by offering a specific view of the
1548 -- class-wide version of the prefix.
1550 if Is_Tagged_Type
(Base_Typ
) then
1551 Tagged_Case
: declare
1552 CW_Temp
: Entity_Id
;
1557 -- CW_Temp : constant Base_Typ'Class := Base_Typ'Class (Pref);
1559 CW_Temp
:= Make_Temporary
(Loc
, 'T');
1560 CW_Typ
:= Class_Wide_Type
(Base_Typ
);
1563 Make_Object_Declaration
(Loc
,
1564 Defining_Identifier
=> CW_Temp
,
1565 Constant_Present
=> True,
1566 Object_Definition
=> New_Occurrence_Of
(CW_Typ
, Loc
),
1568 Convert_To
(CW_Typ
, Relocate_Node
(Pref
)));
1569 Append_To
(Decls
, Aux_Decl
);
1572 -- Temp : Base_Typ renames Base_Typ (CW_Temp);
1575 Make_Object_Renaming_Declaration
(Loc
,
1576 Defining_Identifier
=> Temp_Id
,
1577 Subtype_Mark
=> New_Occurrence_Of
(Base_Typ
, Loc
),
1579 Convert_To
(Base_Typ
, New_Occurrence_Of
(CW_Temp
, Loc
)));
1580 Append_To
(Decls
, Temp_Decl
);
1586 Untagged_Case
: declare
1587 Temp_Expr
: Node_Id
;
1592 -- Generate a nominal type for the constant when the prefix is of
1593 -- a constrained type. This is achieved by setting the Etype of
1594 -- the relocated prefix to its base type. Since the prefix is now
1595 -- the initialization expression of the constant, its freezing
1596 -- will produce a proper nominal type.
1598 Temp_Expr
:= Relocate_Node
(Pref
);
1599 Set_Etype
(Temp_Expr
, Base_Typ
);
1602 -- Temp : constant Base_Typ := Pref;
1605 Make_Object_Declaration
(Loc
,
1606 Defining_Identifier
=> Temp_Id
,
1607 Constant_Present
=> True,
1608 Object_Definition
=> New_Occurrence_Of
(Base_Typ
, Loc
),
1609 Expression
=> Temp_Expr
);
1610 Append_To
(Decls
, Temp_Decl
);
1614 -- Step 4: Analyze all bits
1616 Installed
:= Current_Scope
= Scope
(Loop_Id
);
1618 -- Depending on the pracement of attribute 'Loop_Entry relative to the
1619 -- associated loop, ensure the proper visibility for analysis.
1621 if not Installed
then
1622 Push_Scope
(Scope
(Loop_Id
));
1625 -- The analysis of the conditional block takes care of the constant
1628 if Present
(Result
) then
1629 Rewrite
(Loop_Stmt
, Result
);
1630 Analyze
(Loop_Stmt
);
1632 -- The conditional block was analyzed when a previous 'Loop_Entry was
1633 -- expanded. There is no point in reanalyzing the block, simply analyze
1634 -- the declaration of the constant.
1637 if Present
(Aux_Decl
) then
1641 Analyze
(Temp_Decl
);
1644 Rewrite
(N
, New_Occurrence_Of
(Temp_Id
, Loc
));
1647 if not Installed
then
1650 end Expand_Loop_Entry_Attribute
;
1652 ------------------------------
1653 -- Expand_Min_Max_Attribute --
1654 ------------------------------
1656 procedure Expand_Min_Max_Attribute
(N
: Node_Id
) is
1658 -- Min and Max are handled by the back end (except that static cases
1659 -- have already been evaluated during semantic processing, although the
1660 -- back end should not count on this). The one bit of special processing
1661 -- required in the normal case is that these two attributes typically
1662 -- generate conditionals in the code, so check the relevant restriction.
1664 Check_Restriction
(No_Implicit_Conditionals
, N
);
1666 -- In Modify_Tree_For_C mode, we rewrite as an if expression
1668 if Modify_Tree_For_C
then
1670 Loc
: constant Source_Ptr
:= Sloc
(N
);
1671 Typ
: constant Entity_Id
:= Etype
(N
);
1672 Expr
: constant Node_Id
:= First
(Expressions
(N
));
1673 Left
: constant Node_Id
:= Relocate_Node
(Expr
);
1674 Right
: constant Node_Id
:= Relocate_Node
(Next
(Expr
));
1676 function Make_Compare
(Left
, Right
: Node_Id
) return Node_Id
;
1677 -- Returns Left >= Right for Max, Left <= Right for Min
1683 function Make_Compare
(Left
, Right
: Node_Id
) return Node_Id
is
1685 if Attribute_Name
(N
) = Name_Max
then
1689 Right_Opnd
=> Right
);
1694 Right_Opnd
=> Right
);
1698 -- Start of processing for Min_Max
1701 -- If both Left and Right are side effect free, then we can just
1702 -- use Duplicate_Expr to duplicate the references and return
1704 -- (if Left >=|<= Right then Left else Right)
1706 if Side_Effect_Free
(Left
) and then Side_Effect_Free
(Right
) then
1708 Make_If_Expression
(Loc
,
1709 Expressions
=> New_List
(
1710 Make_Compare
(Left
, Right
),
1711 Duplicate_Subexpr_No_Checks
(Left
),
1712 Duplicate_Subexpr_No_Checks
(Right
))));
1714 -- Otherwise we generate declarations to capture the values.
1716 -- The translation is
1719 -- T1 : constant typ := Left;
1720 -- T2 : constant typ := Right;
1722 -- (if T1 >=|<= T2 then T1 else T2)
1727 T1
: constant Entity_Id
:= Make_Temporary
(Loc
, 'T', Left
);
1728 T2
: constant Entity_Id
:= Make_Temporary
(Loc
, 'T', Right
);
1732 Make_Expression_With_Actions
(Loc
,
1733 Actions
=> New_List
(
1734 Make_Object_Declaration
(Loc
,
1735 Defining_Identifier
=> T1
,
1736 Constant_Present
=> True,
1737 Object_Definition
=>
1738 New_Occurrence_Of
(Etype
(Left
), Loc
),
1739 Expression
=> Relocate_Node
(Left
)),
1741 Make_Object_Declaration
(Loc
,
1742 Defining_Identifier
=> T2
,
1743 Constant_Present
=> True,
1744 Object_Definition
=>
1745 New_Occurrence_Of
(Etype
(Right
), Loc
),
1746 Expression
=> Relocate_Node
(Right
))),
1749 Make_If_Expression
(Loc
,
1750 Expressions
=> New_List
(
1752 (New_Occurrence_Of
(T1
, Loc
),
1753 New_Occurrence_Of
(T2
, Loc
)),
1754 New_Occurrence_Of
(T1
, Loc
),
1755 New_Occurrence_Of
(T2
, Loc
)))));
1759 Analyze_And_Resolve
(N
, Typ
);
1762 end Expand_Min_Max_Attribute
;
1764 ----------------------------------
1765 -- Expand_N_Attribute_Reference --
1766 ----------------------------------
1768 procedure Expand_N_Attribute_Reference
(N
: Node_Id
) is
1769 Loc
: constant Source_Ptr
:= Sloc
(N
);
1770 Typ
: constant Entity_Id
:= Etype
(N
);
1771 Btyp
: constant Entity_Id
:= Base_Type
(Typ
);
1772 Pref
: constant Node_Id
:= Prefix
(N
);
1773 Ptyp
: constant Entity_Id
:= Etype
(Pref
);
1774 Exprs
: constant List_Id
:= Expressions
(N
);
1775 Id
: constant Attribute_Id
:= Get_Attribute_Id
(Attribute_Name
(N
));
1777 procedure Rewrite_Stream_Proc_Call
(Pname
: Entity_Id
);
1778 -- Rewrites a stream attribute for Read, Write or Output with the
1779 -- procedure call. Pname is the entity for the procedure to call.
1781 ------------------------------
1782 -- Rewrite_Stream_Proc_Call --
1783 ------------------------------
1785 procedure Rewrite_Stream_Proc_Call
(Pname
: Entity_Id
) is
1786 Item
: constant Node_Id
:= Next
(First
(Exprs
));
1787 Item_Typ
: constant Entity_Id
:= Etype
(Item
);
1788 Formal
: constant Entity_Id
:= Next_Formal
(First_Formal
(Pname
));
1789 Formal_Typ
: constant Entity_Id
:= Etype
(Formal
);
1790 Is_Written
: constant Boolean := Ekind
(Formal
) /= E_In_Parameter
;
1793 -- The expansion depends on Item, the second actual, which is
1794 -- the object being streamed in or out.
1796 -- If the item is a component of a packed array type, and
1797 -- a conversion is needed on exit, we introduce a temporary to
1798 -- hold the value, because otherwise the packed reference will
1799 -- not be properly expanded.
1801 if Nkind
(Item
) = N_Indexed_Component
1802 and then Is_Packed
(Base_Type
(Etype
(Prefix
(Item
))))
1803 and then Base_Type
(Item_Typ
) /= Base_Type
(Formal_Typ
)
1807 Temp
: constant Entity_Id
:= Make_Temporary
(Loc
, 'V');
1813 Make_Object_Declaration
(Loc
,
1814 Defining_Identifier
=> Temp
,
1815 Object_Definition
=> New_Occurrence_Of
(Formal_Typ
, Loc
));
1816 Set_Etype
(Temp
, Formal_Typ
);
1819 Make_Assignment_Statement
(Loc
,
1820 Name
=> New_Copy_Tree
(Item
),
1822 Unchecked_Convert_To
1823 (Item_Typ
, New_Occurrence_Of
(Temp
, Loc
)));
1825 Rewrite
(Item
, New_Occurrence_Of
(Temp
, Loc
));
1829 Make_Procedure_Call_Statement
(Loc
,
1830 Name
=> New_Occurrence_Of
(Pname
, Loc
),
1831 Parameter_Associations
=> Exprs
),
1834 Rewrite
(N
, Make_Null_Statement
(Loc
));
1839 -- For the class-wide dispatching cases, and for cases in which
1840 -- the base type of the second argument matches the base type of
1841 -- the corresponding formal parameter (that is to say the stream
1842 -- operation is not inherited), we are all set, and can use the
1843 -- argument unchanged.
1845 if not Is_Class_Wide_Type
(Entity
(Pref
))
1846 and then not Is_Class_Wide_Type
(Etype
(Item
))
1847 and then Base_Type
(Item_Typ
) /= Base_Type
(Formal_Typ
)
1849 -- Perform a view conversion when either the argument or the
1850 -- formal parameter are of a private type.
1852 if Is_Private_Type
(Base_Type
(Formal_Typ
))
1853 or else Is_Private_Type
(Base_Type
(Item_Typ
))
1856 Unchecked_Convert_To
(Formal_Typ
, Relocate_Node
(Item
)));
1858 -- Otherwise perform a regular type conversion to ensure that all
1859 -- relevant checks are installed.
1862 Rewrite
(Item
, Convert_To
(Formal_Typ
, Relocate_Node
(Item
)));
1865 -- For untagged derived types set Assignment_OK, to prevent
1866 -- copies from being created when the unchecked conversion
1867 -- is expanded (which would happen in Remove_Side_Effects
1868 -- if Expand_N_Unchecked_Conversion were allowed to call
1869 -- Force_Evaluation). The copy could violate Ada semantics in
1870 -- cases such as an actual that is an out parameter. Note that
1871 -- this approach is also used in exp_ch7 for calls to controlled
1872 -- type operations to prevent problems with actuals wrapped in
1873 -- unchecked conversions.
1875 if Is_Untagged_Derivation
(Etype
(Expression
(Item
))) then
1876 Set_Assignment_OK
(Item
);
1880 -- The stream operation to call may be a renaming created by an
1881 -- attribute definition clause, and may not be frozen yet. Ensure
1882 -- that it has the necessary extra formals.
1884 if not Is_Frozen
(Pname
) then
1885 Create_Extra_Formals
(Pname
);
1888 -- And now rewrite the call
1891 Make_Procedure_Call_Statement
(Loc
,
1892 Name
=> New_Occurrence_Of
(Pname
, Loc
),
1893 Parameter_Associations
=> Exprs
));
1896 end Rewrite_Stream_Proc_Call
;
1898 -- Start of processing for Expand_N_Attribute_Reference
1901 -- Do required validity checking, if enabled. Do not apply check to
1902 -- output parameters of an Asm instruction, since the value of this
1903 -- is not set till after the attribute has been elaborated, and do
1904 -- not apply the check to the arguments of a 'Read or 'Input attribute
1905 -- reference since the scalar argument is an OUT scalar.
1907 if Validity_Checks_On
and then Validity_Check_Operands
1908 and then Id
/= Attribute_Asm_Output
1909 and then Id
/= Attribute_Read
1910 and then Id
/= Attribute_Input
1915 Expr
:= First
(Expressions
(N
));
1916 while Present
(Expr
) loop
1917 Ensure_Valid
(Expr
);
1923 -- Ada 2005 (AI-318-02): If attribute prefix is a call to a build-in-
1924 -- place function, then a temporary return object needs to be created
1925 -- and access to it must be passed to the function.
1927 if Is_Build_In_Place_Function_Call
(Pref
) then
1929 -- If attribute is 'Old, the context is a postcondition, and
1930 -- the temporary must go in the corresponding subprogram, not
1931 -- the postcondition function or any created blocks, as when
1932 -- the attribute appears in a quantified expression. This is
1933 -- handled below in the expansion of the attribute.
1935 if Attribute_Name
(Parent
(Pref
)) = Name_Old
then
1938 Make_Build_In_Place_Call_In_Anonymous_Context
(Pref
);
1941 -- Ada 2005 (AI-318-02): Specialization of the previous case for prefix
1942 -- containing build-in-place function calls whose returned object covers
1945 elsif Present
(Unqual_BIP_Iface_Function_Call
(Pref
)) then
1946 Make_Build_In_Place_Iface_Call_In_Anonymous_Context
(Pref
);
1949 -- If prefix is a protected type name, this is a reference to the
1950 -- current instance of the type. For a component definition, nothing
1951 -- to do (expansion will occur in the init proc). In other contexts,
1952 -- rewrite into reference to current instance.
1954 if Is_Protected_Self_Reference
(Pref
)
1956 (Nkind_In
(Parent
(N
), N_Index_Or_Discriminant_Constraint
,
1957 N_Discriminant_Association
)
1958 and then Nkind
(Parent
(Parent
(Parent
(Parent
(N
))))) =
1959 N_Component_Definition
)
1961 -- No action needed for these attributes since the current instance
1962 -- will be rewritten to be the name of the _object parameter
1963 -- associated with the enclosing protected subprogram (see below).
1965 and then Id
/= Attribute_Access
1966 and then Id
/= Attribute_Unchecked_Access
1967 and then Id
/= Attribute_Unrestricted_Access
1969 Rewrite
(Pref
, Concurrent_Ref
(Pref
));
1973 -- Remaining processing depends on specific attribute
1975 -- Note: individual sections of the following case statement are
1976 -- allowed to assume there is no code after the case statement, and
1977 -- are legitimately allowed to execute return statements if they have
1978 -- nothing more to do.
1982 -- Attributes related to Ada 2012 iterators
1984 when Attribute_Constant_Indexing
1985 | Attribute_Default_Iterator
1986 | Attribute_Implicit_Dereference
1987 | Attribute_Iterable
1988 | Attribute_Iterator_Element
1989 | Attribute_Variable_Indexing
1993 -- Internal attributes used to deal with Ada 2012 delayed aspects. These
1994 -- were already rejected by the parser. Thus they shouldn't appear here.
1996 when Internal_Attribute_Id
=>
1997 raise Program_Error
;
2003 when Attribute_Access
2004 | Attribute_Unchecked_Access
2005 | Attribute_Unrestricted_Access
2007 Access_Cases
: declare
2008 Ref_Object
: constant Node_Id
:= Get_Referenced_Object
(Pref
);
2009 Btyp_DDT
: Entity_Id
;
2011 function Enclosing_Object
(N
: Node_Id
) return Node_Id
;
2012 -- If N denotes a compound name (selected component, indexed
2013 -- component, or slice), returns the name of the outermost such
2014 -- enclosing object. Otherwise returns N. If the object is a
2015 -- renaming, then the renamed object is returned.
2017 ----------------------
2018 -- Enclosing_Object --
2019 ----------------------
2021 function Enclosing_Object
(N
: Node_Id
) return Node_Id
is
2026 while Nkind_In
(Obj_Name
, N_Selected_Component
,
2027 N_Indexed_Component
,
2030 Obj_Name
:= Prefix
(Obj_Name
);
2033 return Get_Referenced_Object
(Obj_Name
);
2034 end Enclosing_Object
;
2036 -- Local declarations
2038 Enc_Object
: constant Node_Id
:= Enclosing_Object
(Ref_Object
);
2040 -- Start of processing for Access_Cases
2043 Btyp_DDT
:= Designated_Type
(Btyp
);
2045 -- Handle designated types that come from the limited view
2047 if From_Limited_With
(Btyp_DDT
)
2048 and then Has_Non_Limited_View
(Btyp_DDT
)
2050 Btyp_DDT
:= Non_Limited_View
(Btyp_DDT
);
2053 -- In order to improve the text of error messages, the designated
2054 -- type of access-to-subprogram itypes is set by the semantics as
2055 -- the associated subprogram entity (see sem_attr). Now we replace
2056 -- such node with the proper E_Subprogram_Type itype.
2058 if Id
= Attribute_Unrestricted_Access
2059 and then Is_Subprogram
(Directly_Designated_Type
(Typ
))
2061 -- The following conditions ensure that this special management
2062 -- is done only for "Address!(Prim'Unrestricted_Access)" nodes.
2063 -- At this stage other cases in which the designated type is
2064 -- still a subprogram (instead of an E_Subprogram_Type) are
2065 -- wrong because the semantics must have overridden the type of
2066 -- the node with the type imposed by the context.
2068 if Nkind
(Parent
(N
)) = N_Unchecked_Type_Conversion
2069 and then Etype
(Parent
(N
)) = RTE
(RE_Prim_Ptr
)
2071 Set_Etype
(N
, RTE
(RE_Prim_Ptr
));
2075 Subp
: constant Entity_Id
:=
2076 Directly_Designated_Type
(Typ
);
2078 Extra
: Entity_Id
:= Empty
;
2079 New_Formal
: Entity_Id
;
2080 Old_Formal
: Entity_Id
:= First_Formal
(Subp
);
2081 Subp_Typ
: Entity_Id
;
2084 Subp_Typ
:= Create_Itype
(E_Subprogram_Type
, N
);
2085 Set_Etype
(Subp_Typ
, Etype
(Subp
));
2086 Set_Returns_By_Ref
(Subp_Typ
, Returns_By_Ref
(Subp
));
2088 if Present
(Old_Formal
) then
2089 New_Formal
:= New_Copy
(Old_Formal
);
2090 Set_First_Entity
(Subp_Typ
, New_Formal
);
2093 Set_Scope
(New_Formal
, Subp_Typ
);
2094 Etyp
:= Etype
(New_Formal
);
2096 -- Handle itypes. There is no need to duplicate
2097 -- here the itypes associated with record types
2098 -- (i.e the implicit full view of private types).
2101 and then Ekind
(Base_Type
(Etyp
)) /= E_Record_Type
2103 Extra
:= New_Copy
(Etyp
);
2104 Set_Parent
(Extra
, New_Formal
);
2105 Set_Etype
(New_Formal
, Extra
);
2106 Set_Scope
(Extra
, Subp_Typ
);
2109 Extra
:= New_Formal
;
2110 Next_Formal
(Old_Formal
);
2111 exit when No
(Old_Formal
);
2113 Link_Entities
(New_Formal
, New_Copy
(Old_Formal
));
2114 Next_Entity
(New_Formal
);
2117 Unlink_Next_Entity
(New_Formal
);
2118 Set_Last_Entity
(Subp_Typ
, Extra
);
2121 -- Now that the explicit formals have been duplicated,
2122 -- any extra formals needed by the subprogram must be
2125 if Present
(Extra
) then
2126 Set_Extra_Formal
(Extra
, Empty
);
2129 Create_Extra_Formals
(Subp_Typ
);
2130 Set_Directly_Designated_Type
(Typ
, Subp_Typ
);
2135 if Is_Access_Protected_Subprogram_Type
(Btyp
) then
2136 Expand_Access_To_Protected_Op
(N
, Pref
, Typ
);
2138 -- If prefix is a type name, this is a reference to the current
2139 -- instance of the type, within its initialization procedure.
2141 elsif Is_Entity_Name
(Pref
)
2142 and then Is_Type
(Entity
(Pref
))
2149 -- If the current instance name denotes a task type, then
2150 -- the access attribute is rewritten to be the name of the
2151 -- "_task" parameter associated with the task type's task
2152 -- procedure. An unchecked conversion is applied to ensure
2153 -- a type match in cases of expander-generated calls (e.g.
2156 if Is_Task_Type
(Entity
(Pref
)) then
2158 First_Entity
(Get_Task_Body_Procedure
(Entity
(Pref
)));
2159 while Present
(Formal
) loop
2160 exit when Chars
(Formal
) = Name_uTask
;
2161 Next_Entity
(Formal
);
2164 pragma Assert
(Present
(Formal
));
2167 Unchecked_Convert_To
(Typ
,
2168 New_Occurrence_Of
(Formal
, Loc
)));
2171 elsif Is_Protected_Type
(Entity
(Pref
)) then
2173 -- No action needed for current instance located in a
2174 -- component definition (expansion will occur in the
2177 if Is_Protected_Type
(Current_Scope
) then
2180 -- If the current instance reference is located in a
2181 -- protected subprogram or entry then rewrite the access
2182 -- attribute to be the name of the "_object" parameter.
2183 -- An unchecked conversion is applied to ensure a type
2184 -- match in cases of expander-generated calls (e.g. init
2187 -- The code may be nested in a block, so find enclosing
2188 -- scope that is a protected operation.
2195 Subp
:= Current_Scope
;
2196 while Ekind_In
(Subp
, E_Loop
, E_Block
) loop
2197 Subp
:= Scope
(Subp
);
2202 (Protected_Body_Subprogram
(Subp
));
2204 -- For a protected subprogram the _Object parameter
2205 -- is the protected record, so we create an access
2206 -- to it. The _Object parameter of an entry is an
2209 if Ekind
(Subp
) = E_Entry
then
2211 Unchecked_Convert_To
(Typ
,
2212 New_Occurrence_Of
(Formal
, Loc
)));
2217 Unchecked_Convert_To
(Typ
,
2218 Make_Attribute_Reference
(Loc
,
2219 Attribute_Name
=> Name_Unrestricted_Access
,
2221 New_Occurrence_Of
(Formal
, Loc
))));
2222 Analyze_And_Resolve
(N
);
2227 -- The expression must appear in a default expression,
2228 -- (which in the initialization procedure is the right-hand
2229 -- side of an assignment), and not in a discriminant
2234 while Present
(Par
) loop
2235 exit when Nkind
(Par
) = N_Assignment_Statement
;
2237 if Nkind
(Par
) = N_Component_Declaration
then
2241 Par
:= Parent
(Par
);
2244 if Present
(Par
) then
2246 Make_Attribute_Reference
(Loc
,
2247 Prefix
=> Make_Identifier
(Loc
, Name_uInit
),
2248 Attribute_Name
=> Attribute_Name
(N
)));
2250 Analyze_And_Resolve
(N
, Typ
);
2255 -- If the prefix of an Access attribute is a dereference of an
2256 -- access parameter (or a renaming of such a dereference, or a
2257 -- subcomponent of such a dereference) and the context is a
2258 -- general access type (including the type of an object or
2259 -- component with an access_definition, but not the anonymous
2260 -- type of an access parameter or access discriminant), then
2261 -- apply an accessibility check to the access parameter. We used
2262 -- to rewrite the access parameter as a type conversion, but that
2263 -- could only be done if the immediate prefix of the Access
2264 -- attribute was the dereference, and didn't handle cases where
2265 -- the attribute is applied to a subcomponent of the dereference,
2266 -- since there's generally no available, appropriate access type
2267 -- to convert to in that case. The attribute is passed as the
2268 -- point to insert the check, because the access parameter may
2269 -- come from a renaming, possibly in a different scope, and the
2270 -- check must be associated with the attribute itself.
2272 elsif Id
= Attribute_Access
2273 and then Nkind
(Enc_Object
) = N_Explicit_Dereference
2274 and then Is_Entity_Name
(Prefix
(Enc_Object
))
2275 and then (Ekind
(Btyp
) = E_General_Access_Type
2276 or else Is_Local_Anonymous_Access
(Btyp
))
2277 and then Ekind
(Entity
(Prefix
(Enc_Object
))) in Formal_Kind
2278 and then Ekind
(Etype
(Entity
(Prefix
(Enc_Object
))))
2279 = E_Anonymous_Access_Type
2280 and then Present
(Extra_Accessibility
2281 (Entity
(Prefix
(Enc_Object
))))
2283 Apply_Accessibility_Check
(Prefix
(Enc_Object
), Typ
, N
);
2285 -- Ada 2005 (AI-251): If the designated type is an interface we
2286 -- add an implicit conversion to force the displacement of the
2287 -- pointer to reference the secondary dispatch table.
2289 elsif Is_Interface
(Btyp_DDT
)
2290 and then (Comes_From_Source
(N
)
2291 or else Comes_From_Source
(Ref_Object
)
2292 or else (Nkind
(Ref_Object
) in N_Has_Chars
2293 and then Chars
(Ref_Object
) = Name_uInit
))
2295 if Nkind
(Ref_Object
) /= N_Explicit_Dereference
then
2297 -- No implicit conversion required if types match, or if
2298 -- the prefix is the class_wide_type of the interface. In
2299 -- either case passing an object of the interface type has
2300 -- already set the pointer correctly.
2302 if Btyp_DDT
= Etype
(Ref_Object
)
2303 or else (Is_Class_Wide_Type
(Etype
(Ref_Object
))
2305 Class_Wide_Type
(Btyp_DDT
) = Etype
(Ref_Object
))
2310 Rewrite
(Prefix
(N
),
2311 Convert_To
(Btyp_DDT
,
2312 New_Copy_Tree
(Prefix
(N
))));
2314 Analyze_And_Resolve
(Prefix
(N
), Btyp_DDT
);
2317 -- When the object is an explicit dereference, convert the
2318 -- dereference's prefix.
2322 Obj_DDT
: constant Entity_Id
:=
2324 (Directly_Designated_Type
2325 (Etype
(Prefix
(Ref_Object
))));
2327 -- No implicit conversion required if designated types
2330 if Obj_DDT
/= Btyp_DDT
2331 and then not (Is_Class_Wide_Type
(Obj_DDT
)
2332 and then Etype
(Obj_DDT
) = Btyp_DDT
)
2336 New_Copy_Tree
(Prefix
(Ref_Object
))));
2337 Analyze_And_Resolve
(N
, Typ
);
2348 -- Transforms 'Adjacent into a call to the floating-point attribute
2349 -- function Adjacent in Fat_xxx (where xxx is the root type)
2351 when Attribute_Adjacent
=>
2352 Expand_Fpt_Attribute_RR
(N
);
2358 when Attribute_Address
=> Address
: declare
2359 Task_Proc
: Entity_Id
;
2362 -- If the prefix is a task or a task type, the useful address is that
2363 -- of the procedure for the task body, i.e. the actual program unit.
2364 -- We replace the original entity with that of the procedure.
2366 if Is_Entity_Name
(Pref
)
2367 and then Is_Task_Type
(Entity
(Pref
))
2369 Task_Proc
:= Next_Entity
(Root_Type
(Ptyp
));
2371 while Present
(Task_Proc
) loop
2372 exit when Ekind
(Task_Proc
) = E_Procedure
2373 and then Etype
(First_Formal
(Task_Proc
)) =
2374 Corresponding_Record_Type
(Ptyp
);
2375 Next_Entity
(Task_Proc
);
2378 if Present
(Task_Proc
) then
2379 Set_Entity
(Pref
, Task_Proc
);
2380 Set_Etype
(Pref
, Etype
(Task_Proc
));
2383 -- Similarly, the address of a protected operation is the address
2384 -- of the corresponding protected body, regardless of the protected
2385 -- object from which it is selected.
2387 elsif Nkind
(Pref
) = N_Selected_Component
2388 and then Is_Subprogram
(Entity
(Selector_Name
(Pref
)))
2389 and then Is_Protected_Type
(Scope
(Entity
(Selector_Name
(Pref
))))
2393 External_Subprogram
(Entity
(Selector_Name
(Pref
))), Loc
));
2395 elsif Nkind
(Pref
) = N_Explicit_Dereference
2396 and then Ekind
(Ptyp
) = E_Subprogram_Type
2397 and then Convention
(Ptyp
) = Convention_Protected
2399 -- The prefix is be a dereference of an access_to_protected_
2400 -- subprogram. The desired address is the second component of
2401 -- the record that represents the access.
2404 Addr
: constant Entity_Id
:= Etype
(N
);
2405 Ptr
: constant Node_Id
:= Prefix
(Pref
);
2406 T
: constant Entity_Id
:=
2407 Equivalent_Type
(Base_Type
(Etype
(Ptr
)));
2411 Unchecked_Convert_To
(Addr
,
2412 Make_Selected_Component
(Loc
,
2413 Prefix
=> Unchecked_Convert_To
(T
, Ptr
),
2414 Selector_Name
=> New_Occurrence_Of
(
2415 Next_Entity
(First_Entity
(T
)), Loc
))));
2417 Analyze_And_Resolve
(N
, Addr
);
2420 -- Ada 2005 (AI-251): Class-wide interface objects are always
2421 -- "displaced" to reference the tag associated with the interface
2422 -- type. In order to obtain the real address of such objects we
2423 -- generate a call to a run-time subprogram that returns the base
2424 -- address of the object.
2426 -- This processing is not needed in the VM case, where dispatching
2427 -- issues are taken care of by the virtual machine.
2429 elsif Is_Class_Wide_Type
(Ptyp
)
2430 and then Is_Interface
(Underlying_Type
(Ptyp
))
2431 and then Tagged_Type_Expansion
2432 and then not (Nkind
(Pref
) in N_Has_Entity
2433 and then Is_Subprogram
(Entity
(Pref
)))
2436 Make_Function_Call
(Loc
,
2437 Name
=> New_Occurrence_Of
(RTE
(RE_Base_Address
), Loc
),
2438 Parameter_Associations
=> New_List
(
2439 Relocate_Node
(N
))));
2444 -- Deal with packed array reference, other cases are handled by
2447 if Involves_Packed_Array_Reference
(Pref
) then
2448 Expand_Packed_Address_Reference
(N
);
2456 when Attribute_Alignment
=> Alignment
: declare
2460 -- For class-wide types, X'Class'Alignment is transformed into a
2461 -- direct reference to the Alignment of the class type, so that the
2462 -- back end does not have to deal with the X'Class'Alignment
2465 if Is_Entity_Name
(Pref
)
2466 and then Is_Class_Wide_Type
(Entity
(Pref
))
2468 Rewrite
(Prefix
(N
), New_Occurrence_Of
(Entity
(Pref
), Loc
));
2471 -- For x'Alignment applied to an object of a class wide type,
2472 -- transform X'Alignment into a call to the predefined primitive
2473 -- operation _Alignment applied to X.
2475 elsif Is_Class_Wide_Type
(Ptyp
) then
2477 Make_Attribute_Reference
(Loc
,
2479 Attribute_Name
=> Name_Tag
);
2481 New_Node
:= Build_Get_Alignment
(Loc
, New_Node
);
2483 -- Case where the context is a specific integer type with which
2484 -- the original attribute was compatible. The function has a
2485 -- specific type as well, so to preserve the compatibility we
2486 -- must convert explicitly.
2488 if Typ
/= Standard_Integer
then
2489 New_Node
:= Convert_To
(Typ
, New_Node
);
2492 Rewrite
(N
, New_Node
);
2493 Analyze_And_Resolve
(N
, Typ
);
2496 -- For all other cases, we just have to deal with the case of
2497 -- the fact that the result can be universal.
2500 Apply_Universal_Integer_Attribute_Checks
(N
);
2508 -- We compute this if a packed array reference was present, otherwise we
2509 -- leave the computation up to the back end.
2511 when Attribute_Bit
=>
2512 if Involves_Packed_Array_Reference
(Pref
) then
2513 Expand_Packed_Bit_Reference
(N
);
2515 Apply_Universal_Integer_Attribute_Checks
(N
);
2522 -- We compute this if a component clause was present, otherwise we leave
2523 -- the computation up to the back end, since we don't know what layout
2526 -- Note that the attribute can apply to a naked record component
2527 -- in generated code (i.e. the prefix is an identifier that
2528 -- references the component or discriminant entity).
2530 when Attribute_Bit_Position
=> Bit_Position
: declare
2534 if Nkind
(Pref
) = N_Identifier
then
2535 CE
:= Entity
(Pref
);
2537 CE
:= Entity
(Selector_Name
(Pref
));
2540 if Known_Static_Component_Bit_Offset
(CE
) then
2542 Make_Integer_Literal
(Loc
,
2543 Intval
=> Component_Bit_Offset
(CE
)));
2544 Analyze_And_Resolve
(N
, Typ
);
2547 Apply_Universal_Integer_Attribute_Checks
(N
);
2555 -- A reference to P'Body_Version or P'Version is expanded to
2558 -- pragma Import (C, Vnn, "uuuuT");
2560 -- Get_Version_String (Vnn)
2562 -- where uuuu is the unit name (dots replaced by double underscore)
2563 -- and T is B for the cases of Body_Version, or Version applied to a
2564 -- subprogram acting as its own spec, and S for Version applied to a
2565 -- subprogram spec or package. This sequence of code references the
2566 -- unsigned constant created in the main program by the binder.
2568 -- A special exception occurs for Standard, where the string returned
2569 -- is a copy of the library string in gnatvsn.ads.
2571 when Attribute_Body_Version
2575 E
: constant Entity_Id
:= Make_Temporary
(Loc
, 'V');
2580 -- If not library unit, get to containing library unit
2582 Pent
:= Entity
(Pref
);
2583 while Pent
/= Standard_Standard
2584 and then Scope
(Pent
) /= Standard_Standard
2585 and then not Is_Child_Unit
(Pent
)
2587 Pent
:= Scope
(Pent
);
2590 -- Special case Standard and Standard.ASCII
2592 if Pent
= Standard_Standard
or else Pent
= Standard_ASCII
then
2594 Make_String_Literal
(Loc
,
2595 Strval
=> Verbose_Library_Version
));
2600 -- Build required string constant
2602 Get_Name_String
(Get_Unit_Name
(Pent
));
2605 for J
in 1 .. Name_Len
- 2 loop
2606 if Name_Buffer
(J
) = '.' then
2607 Store_String_Chars
("__");
2609 Store_String_Char
(Get_Char_Code
(Name_Buffer
(J
)));
2613 -- Case of subprogram acting as its own spec, always use body
2615 if Nkind
(Declaration_Node
(Pent
)) in N_Subprogram_Specification
2616 and then Nkind
(Parent
(Declaration_Node
(Pent
))) =
2618 and then Acts_As_Spec
(Parent
(Declaration_Node
(Pent
)))
2620 Store_String_Chars
("B");
2622 -- Case of no body present, always use spec
2624 elsif not Unit_Requires_Body
(Pent
) then
2625 Store_String_Chars
("S");
2627 -- Otherwise use B for Body_Version, S for spec
2629 elsif Id
= Attribute_Body_Version
then
2630 Store_String_Chars
("B");
2632 Store_String_Chars
("S");
2636 Lib
.Version_Referenced
(S
);
2638 -- Insert the object declaration
2640 Insert_Actions
(N
, New_List
(
2641 Make_Object_Declaration
(Loc
,
2642 Defining_Identifier
=> E
,
2643 Object_Definition
=>
2644 New_Occurrence_Of
(RTE
(RE_Unsigned
), Loc
))));
2646 -- Set entity as imported with correct external name
2648 Set_Is_Imported
(E
);
2649 Set_Interface_Name
(E
, Make_String_Literal
(Loc
, S
));
2651 -- Set entity as internal to ensure proper Sprint output of its
2652 -- implicit importation.
2654 Set_Is_Internal
(E
);
2656 -- And now rewrite original reference
2659 Make_Function_Call
(Loc
,
2661 New_Occurrence_Of
(RTE
(RE_Get_Version_String
), Loc
),
2662 Parameter_Associations
=> New_List
(
2663 New_Occurrence_Of
(E
, Loc
))));
2666 Analyze_And_Resolve
(N
, RTE
(RE_Version_String
));
2673 -- Transforms 'Ceiling into a call to the floating-point attribute
2674 -- function Ceiling in Fat_xxx (where xxx is the root type)
2676 when Attribute_Ceiling
=>
2677 Expand_Fpt_Attribute_R
(N
);
2683 -- Transforms 'Callable attribute into a call to the Callable function
2685 when Attribute_Callable
=>
2687 -- We have an object of a task interface class-wide type as a prefix
2688 -- to Callable. Generate:
2689 -- callable (Task_Id (Pref._disp_get_task_id));
2691 if Ada_Version
>= Ada_2005
2692 and then Ekind
(Ptyp
) = E_Class_Wide_Type
2693 and then Is_Interface
(Ptyp
)
2694 and then Is_Task_Interface
(Ptyp
)
2697 Make_Function_Call
(Loc
,
2699 New_Occurrence_Of
(RTE
(RE_Callable
), Loc
),
2700 Parameter_Associations
=> New_List
(
2701 Make_Unchecked_Type_Conversion
(Loc
,
2703 New_Occurrence_Of
(RTE
(RO_ST_Task_Id
), Loc
),
2704 Expression
=> Build_Disp_Get_Task_Id_Call
(Pref
)))));
2707 Rewrite
(N
, Build_Call_With_Task
(Pref
, RTE
(RE_Callable
)));
2710 Analyze_And_Resolve
(N
, Standard_Boolean
);
2716 -- Transforms 'Caller attribute into a call to either the
2717 -- Task_Entry_Caller or the Protected_Entry_Caller function.
2719 when Attribute_Caller
=> Caller
: declare
2720 Id_Kind
: constant Entity_Id
:= RTE
(RO_AT_Task_Id
);
2721 Ent
: constant Entity_Id
:= Entity
(Pref
);
2722 Conctype
: constant Entity_Id
:= Scope
(Ent
);
2723 Nest_Depth
: Integer := 0;
2730 if Is_Protected_Type
(Conctype
) then
2731 case Corresponding_Runtime_Package
(Conctype
) is
2732 when System_Tasking_Protected_Objects_Entries
=>
2735 (RTE
(RE_Protected_Entry_Caller
), Loc
);
2737 when System_Tasking_Protected_Objects_Single_Entry
=>
2740 (RTE
(RE_Protected_Single_Entry_Caller
), Loc
);
2743 raise Program_Error
;
2747 Unchecked_Convert_To
(Id_Kind
,
2748 Make_Function_Call
(Loc
,
2750 Parameter_Associations
=> New_List
(
2752 (Find_Protection_Object
(Current_Scope
), Loc
)))));
2757 -- Determine the nesting depth of the E'Caller attribute, that
2758 -- is, how many accept statements are nested within the accept
2759 -- statement for E at the point of E'Caller. The runtime uses
2760 -- this depth to find the specified entry call.
2762 for J
in reverse 0 .. Scope_Stack
.Last
loop
2763 S
:= Scope_Stack
.Table
(J
).Entity
;
2765 -- We should not reach the scope of the entry, as it should
2766 -- already have been checked in Sem_Attr that this attribute
2767 -- reference is within a matching accept statement.
2769 pragma Assert
(S
/= Conctype
);
2774 elsif Is_Entry
(S
) then
2775 Nest_Depth
:= Nest_Depth
+ 1;
2780 Unchecked_Convert_To
(Id_Kind
,
2781 Make_Function_Call
(Loc
,
2783 New_Occurrence_Of
(RTE
(RE_Task_Entry_Caller
), Loc
),
2784 Parameter_Associations
=> New_List
(
2785 Make_Integer_Literal
(Loc
,
2786 Intval
=> Int
(Nest_Depth
))))));
2789 Analyze_And_Resolve
(N
, Id_Kind
);
2796 -- Transforms 'Compose into a call to the floating-point attribute
2797 -- function Compose in Fat_xxx (where xxx is the root type)
2799 -- Note: we strictly should have special code here to deal with the
2800 -- case of absurdly negative arguments (less than Integer'First)
2801 -- which will return a (signed) zero value, but it hardly seems
2802 -- worth the effort. Absurdly large positive arguments will raise
2803 -- constraint error which is fine.
2805 when Attribute_Compose
=>
2806 Expand_Fpt_Attribute_RI
(N
);
2812 when Attribute_Constrained
=> Constrained
: declare
2813 Formal_Ent
: constant Entity_Id
:= Param_Entity
(Pref
);
2815 function Is_Constrained_Aliased_View
(Obj
: Node_Id
) return Boolean;
2816 -- Ada 2005 (AI-363): Returns True if the object name Obj denotes a
2817 -- view of an aliased object whose subtype is constrained.
2819 ---------------------------------
2820 -- Is_Constrained_Aliased_View --
2821 ---------------------------------
2823 function Is_Constrained_Aliased_View
(Obj
: Node_Id
) return Boolean is
2827 if Is_Entity_Name
(Obj
) then
2830 if Present
(Renamed_Object
(E
)) then
2831 return Is_Constrained_Aliased_View
(Renamed_Object
(E
));
2833 return Is_Aliased
(E
) and then Is_Constrained
(Etype
(E
));
2837 return Is_Aliased_View
(Obj
)
2839 (Is_Constrained
(Etype
(Obj
))
2841 (Nkind
(Obj
) = N_Explicit_Dereference
2843 not Object_Type_Has_Constrained_Partial_View
2844 (Typ
=> Base_Type
(Etype
(Obj
)),
2845 Scop
=> Current_Scope
)));
2847 end Is_Constrained_Aliased_View
;
2849 -- Start of processing for Constrained
2852 -- Reference to a parameter where the value is passed as an extra
2853 -- actual, corresponding to the extra formal referenced by the
2854 -- Extra_Constrained field of the corresponding formal. If this
2855 -- is an entry in-parameter, it is replaced by a constant renaming
2856 -- for which Extra_Constrained is never created.
2858 if Present
(Formal_Ent
)
2859 and then Ekind
(Formal_Ent
) /= E_Constant
2860 and then Present
(Extra_Constrained
(Formal_Ent
))
2864 (Extra_Constrained
(Formal_Ent
), Sloc
(N
)));
2866 -- If the prefix is an access to object, the attribute applies to
2867 -- the designated object, so rewrite with an explicit dereference.
2869 elsif Is_Access_Type
(Etype
(Pref
))
2871 (not Is_Entity_Name
(Pref
) or else Is_Object
(Entity
(Pref
)))
2874 Make_Explicit_Dereference
(Loc
, Relocate_Node
(Pref
)));
2875 Analyze_And_Resolve
(N
, Standard_Boolean
);
2878 -- For variables with a Extra_Constrained field, we use the
2879 -- corresponding entity.
2881 elsif Nkind
(Pref
) = N_Identifier
2882 and then Ekind
(Entity
(Pref
)) = E_Variable
2883 and then Present
(Extra_Constrained
(Entity
(Pref
)))
2887 (Extra_Constrained
(Entity
(Pref
)), Sloc
(N
)));
2889 -- For all other entity names, we can tell at compile time
2891 elsif Is_Entity_Name
(Pref
) then
2893 Ent
: constant Entity_Id
:= Entity
(Pref
);
2897 -- (RM J.4) obsolescent cases
2899 if Is_Type
(Ent
) then
2903 if Is_Private_Type
(Ent
) then
2904 Res
:= not Has_Discriminants
(Ent
)
2905 or else Is_Constrained
(Ent
);
2907 -- It not a private type, must be a generic actual type
2908 -- that corresponded to a private type. We know that this
2909 -- correspondence holds, since otherwise the reference
2910 -- within the generic template would have been illegal.
2913 if Is_Composite_Type
(Underlying_Type
(Ent
)) then
2914 Res
:= Is_Constrained
(Ent
);
2921 -- For access type, apply access check as needed
2923 if Is_Access_Type
(Ptyp
) then
2924 Apply_Access_Check
(N
);
2927 -- If the prefix is not a variable or is aliased, then
2928 -- definitely true; if it's a formal parameter without an
2929 -- associated extra formal, then treat it as constrained.
2931 -- Ada 2005 (AI-363): An aliased prefix must be known to be
2932 -- constrained in order to set the attribute to True.
2934 if not Is_Variable
(Pref
)
2935 or else Present
(Formal_Ent
)
2936 or else (Ada_Version
< Ada_2005
2937 and then Is_Aliased_View
(Pref
))
2938 or else (Ada_Version
>= Ada_2005
2939 and then Is_Constrained_Aliased_View
(Pref
))
2943 -- Variable case, look at type to see if it is constrained.
2944 -- Note that the one case where this is not accurate (the
2945 -- procedure formal case), has been handled above.
2947 -- We use the Underlying_Type here (and below) in case the
2948 -- type is private without discriminants, but the full type
2949 -- has discriminants. This case is illegal, but we generate
2950 -- it internally for passing to the Extra_Constrained
2954 -- In Ada 2012, test for case of a limited tagged type,
2955 -- in which case the attribute is always required to
2956 -- return True. The underlying type is tested, to make
2957 -- sure we also return True for cases where there is an
2958 -- unconstrained object with an untagged limited partial
2959 -- view which has defaulted discriminants (such objects
2960 -- always produce a False in earlier versions of
2961 -- Ada). (Ada 2012: AI05-0214)
2964 Is_Constrained
(Underlying_Type
(Etype
(Ent
)))
2966 (Ada_Version
>= Ada_2012
2967 and then Is_Tagged_Type
(Underlying_Type
(Ptyp
))
2968 and then Is_Limited_Type
(Ptyp
));
2972 Rewrite
(N
, New_Occurrence_Of
(Boolean_Literals
(Res
), Loc
));
2975 -- Prefix is not an entity name. These are also cases where we can
2976 -- always tell at compile time by looking at the form and type of the
2977 -- prefix. If an explicit dereference of an object with constrained
2978 -- partial view, this is unconstrained (Ada 2005: AI95-0363). If the
2979 -- underlying type is a limited tagged type, then Constrained is
2980 -- required to always return True (Ada 2012: AI05-0214).
2986 not Is_Variable
(Pref
)
2988 (Nkind
(Pref
) = N_Explicit_Dereference
2990 not Object_Type_Has_Constrained_Partial_View
2991 (Typ
=> Base_Type
(Ptyp
),
2992 Scop
=> Current_Scope
))
2993 or else Is_Constrained
(Underlying_Type
(Ptyp
))
2994 or else (Ada_Version
>= Ada_2012
2995 and then Is_Tagged_Type
(Underlying_Type
(Ptyp
))
2996 and then Is_Limited_Type
(Ptyp
))),
3000 Analyze_And_Resolve
(N
, Standard_Boolean
);
3007 -- Transforms 'Copy_Sign into a call to the floating-point attribute
3008 -- function Copy_Sign in Fat_xxx (where xxx is the root type)
3010 when Attribute_Copy_Sign
=>
3011 Expand_Fpt_Attribute_RR
(N
);
3017 -- Transforms 'Count attribute into a call to the Count function
3019 when Attribute_Count
=> Count
: declare
3021 Conctyp
: Entity_Id
;
3023 Entry_Id
: Entity_Id
;
3028 -- If the prefix is a member of an entry family, retrieve both
3029 -- entry name and index. For a simple entry there is no index.
3031 if Nkind
(Pref
) = N_Indexed_Component
then
3032 Entnam
:= Prefix
(Pref
);
3033 Index
:= First
(Expressions
(Pref
));
3039 Entry_Id
:= Entity
(Entnam
);
3041 -- Find the concurrent type in which this attribute is referenced
3042 -- (there had better be one).
3044 Conctyp
:= Current_Scope
;
3045 while not Is_Concurrent_Type
(Conctyp
) loop
3046 Conctyp
:= Scope
(Conctyp
);
3051 if Is_Protected_Type
(Conctyp
) then
3052 case Corresponding_Runtime_Package
(Conctyp
) is
3053 when System_Tasking_Protected_Objects_Entries
=>
3054 Name
:= New_Occurrence_Of
(RTE
(RE_Protected_Count
), Loc
);
3057 Make_Function_Call
(Loc
,
3059 Parameter_Associations
=> New_List
(
3061 (Find_Protection_Object
(Current_Scope
), Loc
),
3062 Entry_Index_Expression
3063 (Loc
, Entry_Id
, Index
, Scope
(Entry_Id
))));
3065 when System_Tasking_Protected_Objects_Single_Entry
=>
3067 New_Occurrence_Of
(RTE
(RE_Protected_Count_Entry
), Loc
);
3070 Make_Function_Call
(Loc
,
3072 Parameter_Associations
=> New_List
(
3074 (Find_Protection_Object
(Current_Scope
), Loc
)));
3077 raise Program_Error
;
3084 Make_Function_Call
(Loc
,
3085 Name
=> New_Occurrence_Of
(RTE
(RE_Task_Count
), Loc
),
3086 Parameter_Associations
=> New_List
(
3087 Entry_Index_Expression
(Loc
,
3088 Entry_Id
, Index
, Scope
(Entry_Id
))));
3091 -- The call returns type Natural but the context is universal integer
3092 -- so any integer type is allowed. The attribute was already resolved
3093 -- so its Etype is the required result type. If the base type of the
3094 -- context type is other than Standard.Integer we put in a conversion
3095 -- to the required type. This can be a normal typed conversion since
3096 -- both input and output types of the conversion are integer types
3098 if Base_Type
(Typ
) /= Base_Type
(Standard_Integer
) then
3099 Rewrite
(N
, Convert_To
(Typ
, Call
));
3104 Analyze_And_Resolve
(N
, Typ
);
3107 ---------------------
3108 -- Descriptor_Size --
3109 ---------------------
3111 when Attribute_Descriptor_Size
=>
3113 -- Attribute Descriptor_Size is handled by the back end when applied
3114 -- to an unconstrained array type.
3116 if Is_Array_Type
(Ptyp
)
3117 and then not Is_Constrained
(Ptyp
)
3119 Apply_Universal_Integer_Attribute_Checks
(N
);
3121 -- For any other type, the descriptor size is 0 because there is no
3122 -- actual descriptor, but the result is not formally static.
3125 Rewrite
(N
, Make_Integer_Literal
(Loc
, 0));
3127 Set_Is_Static_Expression
(N
, False);
3134 -- This processing is shared by Elab_Spec
3136 -- What we do is to insert the following declarations
3139 -- pragma Import (C, enn, "name___elabb/s");
3141 -- and then the Elab_Body/Spec attribute is replaced by a reference
3142 -- to this defining identifier.
3144 when Attribute_Elab_Body
3145 | Attribute_Elab_Spec
3147 -- Leave attribute unexpanded in CodePeer mode: the gnat2scil
3148 -- back-end knows how to handle these attributes directly.
3150 if CodePeer_Mode
then
3155 Ent
: constant Entity_Id
:= Make_Temporary
(Loc
, 'E');
3159 procedure Make_Elab_String
(Nod
: Node_Id
);
3160 -- Given Nod, an identifier, or a selected component, put the
3161 -- image into the current string literal, with double underline
3162 -- between components.
3164 ----------------------
3165 -- Make_Elab_String --
3166 ----------------------
3168 procedure Make_Elab_String
(Nod
: Node_Id
) is
3170 if Nkind
(Nod
) = N_Selected_Component
then
3171 Make_Elab_String
(Prefix
(Nod
));
3172 Store_String_Char
('_');
3173 Store_String_Char
('_');
3174 Get_Name_String
(Chars
(Selector_Name
(Nod
)));
3177 pragma Assert
(Nkind
(Nod
) = N_Identifier
);
3178 Get_Name_String
(Chars
(Nod
));
3181 Store_String_Chars
(Name_Buffer
(1 .. Name_Len
));
3182 end Make_Elab_String
;
3184 -- Start of processing for Elab_Body/Elab_Spec
3187 -- First we need to prepare the string literal for the name of
3188 -- the elaboration routine to be referenced.
3191 Make_Elab_String
(Pref
);
3192 Store_String_Chars
("___elab");
3193 Lang
:= Make_Identifier
(Loc
, Name_C
);
3195 if Id
= Attribute_Elab_Body
then
3196 Store_String_Char
('b');
3198 Store_String_Char
('s');
3203 Insert_Actions
(N
, New_List
(
3204 Make_Subprogram_Declaration
(Loc
,
3206 Make_Procedure_Specification
(Loc
,
3207 Defining_Unit_Name
=> Ent
)),
3210 Chars
=> Name_Import
,
3211 Pragma_Argument_Associations
=> New_List
(
3212 Make_Pragma_Argument_Association
(Loc
, Expression
=> Lang
),
3214 Make_Pragma_Argument_Association
(Loc
,
3215 Expression
=> Make_Identifier
(Loc
, Chars
(Ent
))),
3217 Make_Pragma_Argument_Association
(Loc
,
3218 Expression
=> Make_String_Literal
(Loc
, Str
))))));
3220 Set_Entity
(N
, Ent
);
3221 Rewrite
(N
, New_Occurrence_Of
(Ent
, Loc
));
3224 --------------------
3225 -- Elab_Subp_Body --
3226 --------------------
3228 -- Always ignored. In CodePeer mode, gnat2scil knows how to handle
3229 -- this attribute directly, and if we are not in CodePeer mode it is
3230 -- entirely ignored ???
3232 when Attribute_Elab_Subp_Body
=>
3239 -- Elaborated is always True for preelaborated units, predefined units,
3240 -- pure units and units which have Elaborate_Body pragmas. These units
3241 -- have no elaboration entity.
3243 -- Note: The Elaborated attribute is never passed to the back end
3245 when Attribute_Elaborated
=> Elaborated
: declare
3246 Elab_Id
: constant Entity_Id
:= Elaboration_Entity
(Entity
(Pref
));
3249 if Present
(Elab_Id
) then
3252 Left_Opnd
=> New_Occurrence_Of
(Elab_Id
, Loc
),
3253 Right_Opnd
=> Make_Integer_Literal
(Loc
, Uint_0
)));
3255 Analyze_And_Resolve
(N
, Typ
);
3257 Rewrite
(N
, New_Occurrence_Of
(Standard_True
, Loc
));
3265 when Attribute_Enum_Rep
=> Enum_Rep
: declare
3269 -- Get the expression, which is X for Enum_Type'Enum_Rep (X) or
3272 if Is_Non_Empty_List
(Exprs
) then
3273 Expr
:= First
(Exprs
);
3278 -- If the expression is an enumeration literal, it is replaced by the
3281 if Nkind
(Expr
) in N_Has_Entity
3282 and then Ekind
(Entity
(Expr
)) = E_Enumeration_Literal
3285 Make_Integer_Literal
(Loc
, Enumeration_Rep
(Entity
(Expr
))));
3287 -- If this is a renaming of a literal, recover the representation
3288 -- of the original. If it renames an expression there is nothing to
3291 elsif Nkind
(Expr
) in N_Has_Entity
3292 and then Ekind
(Entity
(Expr
)) = E_Constant
3293 and then Present
(Renamed_Object
(Entity
(Expr
)))
3294 and then Is_Entity_Name
(Renamed_Object
(Entity
(Expr
)))
3295 and then Ekind
(Entity
(Renamed_Object
(Entity
(Expr
)))) =
3296 E_Enumeration_Literal
3299 Make_Integer_Literal
(Loc
,
3300 Enumeration_Rep
(Entity
(Renamed_Object
(Entity
(Expr
))))));
3302 -- If not constant-folded above, Enum_Type'Enum_Rep (X) or
3303 -- X'Enum_Rep expands to
3307 -- This is simply a direct conversion from the enumeration type to
3308 -- the target integer type, which is treated by the back end as a
3309 -- normal integer conversion, treating the enumeration type as an
3310 -- integer, which is exactly what we want. We set Conversion_OK to
3311 -- make sure that the analyzer does not complain about what otherwise
3312 -- might be an illegal conversion.
3315 Rewrite
(N
, OK_Convert_To
(Typ
, Relocate_Node
(Expr
)));
3319 Analyze_And_Resolve
(N
, Typ
);
3326 when Attribute_Enum_Val
=> Enum_Val
: declare
3328 Btyp
: constant Entity_Id
:= Base_Type
(Ptyp
);
3331 -- X'Enum_Val (Y) expands to
3333 -- [constraint_error when _rep_to_pos (Y, False) = -1, msg]
3336 Expr
:= Unchecked_Convert_To
(Ptyp
, First
(Exprs
));
3339 Make_Raise_Constraint_Error
(Loc
,
3343 Make_Function_Call
(Loc
,
3345 New_Occurrence_Of
(TSS
(Btyp
, TSS_Rep_To_Pos
), Loc
),
3346 Parameter_Associations
=> New_List
(
3347 Relocate_Node
(Duplicate_Subexpr
(Expr
)),
3348 New_Occurrence_Of
(Standard_False
, Loc
))),
3350 Right_Opnd
=> Make_Integer_Literal
(Loc
, -1)),
3351 Reason
=> CE_Range_Check_Failed
));
3354 Analyze_And_Resolve
(N
, Ptyp
);
3361 -- Transforms 'Exponent into a call to the floating-point attribute
3362 -- function Exponent in Fat_xxx (where xxx is the root type)
3364 when Attribute_Exponent
=>
3365 Expand_Fpt_Attribute_R
(N
);
3371 -- transforme X'External_Tag into Ada.Tags.External_Tag (X'tag)
3373 when Attribute_External_Tag
=>
3375 Make_Function_Call
(Loc
,
3377 New_Occurrence_Of
(RTE
(RE_External_Tag
), Loc
),
3378 Parameter_Associations
=> New_List
(
3379 Make_Attribute_Reference
(Loc
,
3380 Attribute_Name
=> Name_Tag
,
3381 Prefix
=> Prefix
(N
)))));
3383 Analyze_And_Resolve
(N
, Standard_String
);
3385 -----------------------
3386 -- Finalization_Size --
3387 -----------------------
3389 when Attribute_Finalization_Size
=> Finalization_Size
: declare
3390 function Calculate_Header_Size
return Node_Id
;
3391 -- Generate a runtime call to calculate the size of the hidden header
3392 -- along with any added padding which would precede a heap-allocated
3393 -- object of the prefix type.
3395 ---------------------------
3396 -- Calculate_Header_Size --
3397 ---------------------------
3399 function Calculate_Header_Size
return Node_Id
is
3402 -- Universal_Integer
3403 -- (Header_Size_With_Padding (Pref'Alignment))
3406 Convert_To
(Universal_Integer
,
3407 Make_Function_Call
(Loc
,
3409 New_Occurrence_Of
(RTE
(RE_Header_Size_With_Padding
), Loc
),
3411 Parameter_Associations
=> New_List
(
3412 Make_Attribute_Reference
(Loc
,
3413 Prefix
=> New_Copy_Tree
(Pref
),
3414 Attribute_Name
=> Name_Alignment
))));
3415 end Calculate_Header_Size
;
3421 -- Start of Finalization_Size
3424 -- An object of a class-wide type first requires a runtime check to
3425 -- determine whether it is actually controlled or not. Depending on
3426 -- the outcome of this check, the Finalization_Size of the object
3427 -- may be zero or some positive value.
3429 -- In this scenario, Pref'Finalization_Size is expanded into
3431 -- Size : Integer := 0;
3433 -- if Needs_Finalization (Pref'Tag) then
3435 -- Universal_Integer
3436 -- (Header_Size_With_Padding (Pref'Alignment));
3439 -- and the attribute reference is replaced with a reference to Size.
3441 if Is_Class_Wide_Type
(Ptyp
) then
3442 Size
:= Make_Temporary
(Loc
, 'S');
3444 Insert_Actions
(N
, New_List
(
3447 -- Size : Integer := 0;
3449 Make_Object_Declaration
(Loc
,
3450 Defining_Identifier
=> Size
,
3451 Object_Definition
=>
3452 New_Occurrence_Of
(Standard_Integer
, Loc
),
3453 Expression
=> Make_Integer_Literal
(Loc
, 0)),
3456 -- if Needs_Finalization (Pref'Tag) then
3458 -- Universal_Integer
3459 -- (Header_Size_With_Padding (Pref'Alignment));
3462 Make_If_Statement
(Loc
,
3464 Make_Function_Call
(Loc
,
3466 New_Occurrence_Of
(RTE
(RE_Needs_Finalization
), Loc
),
3468 Parameter_Associations
=> New_List
(
3469 Make_Attribute_Reference
(Loc
,
3470 Prefix
=> New_Copy_Tree
(Pref
),
3471 Attribute_Name
=> Name_Tag
))),
3473 Then_Statements
=> New_List
(
3474 Make_Assignment_Statement
(Loc
,
3475 Name
=> New_Occurrence_Of
(Size
, Loc
),
3476 Expression
=> Calculate_Header_Size
)))));
3478 Rewrite
(N
, New_Occurrence_Of
(Size
, Loc
));
3480 -- The prefix is known to be controlled at compile time. Calculate
3481 -- Finalization_Size by calling function Header_Size_With_Padding.
3483 elsif Needs_Finalization
(Ptyp
) then
3484 Rewrite
(N
, Calculate_Header_Size
);
3486 -- The prefix is not an object with controlled parts, so its
3487 -- Finalization_Size is zero.
3490 Rewrite
(N
, Make_Integer_Literal
(Loc
, 0));
3493 -- Due to cases where the entity type of the attribute is already
3494 -- resolved the rewritten N must get re-resolved to its appropriate
3497 Analyze_And_Resolve
(N
, Typ
);
3498 end Finalization_Size
;
3504 when Attribute_First
=>
3506 -- If the prefix type is a constrained packed array type which
3507 -- already has a Packed_Array_Impl_Type representation defined, then
3508 -- replace this attribute with a direct reference to 'First of the
3509 -- appropriate index subtype (since otherwise the back end will try
3510 -- to give us the value of 'First for this implementation type).
3512 if Is_Constrained_Packed_Array
(Ptyp
) then
3514 Make_Attribute_Reference
(Loc
,
3515 Attribute_Name
=> Name_First
,
3517 New_Occurrence_Of
(Get_Index_Subtype
(N
), Loc
)));
3518 Analyze_And_Resolve
(N
, Typ
);
3520 -- For access type, apply access check as needed
3522 elsif Is_Access_Type
(Ptyp
) then
3523 Apply_Access_Check
(N
);
3525 -- For scalar type, if low bound is a reference to an entity, just
3526 -- replace with a direct reference. Note that we can only have a
3527 -- reference to a constant entity at this stage, anything else would
3528 -- have already been rewritten.
3530 elsif Is_Scalar_Type
(Ptyp
) then
3532 Lo
: constant Node_Id
:= Type_Low_Bound
(Ptyp
);
3534 if Is_Entity_Name
(Lo
) then
3535 Rewrite
(N
, New_Occurrence_Of
(Entity
(Lo
), Loc
));
3544 -- Compute this if component clause was present, otherwise we leave the
3545 -- computation to be completed in the back-end, since we don't know what
3546 -- layout will be chosen.
3548 when Attribute_First_Bit
=> First_Bit_Attr
: declare
3549 CE
: constant Entity_Id
:= Entity
(Selector_Name
(Pref
));
3552 -- In Ada 2005 (or later) if we have the non-default bit order, then
3553 -- we return the original value as given in the component clause
3554 -- (RM 2005 13.5.2(3/2)).
3556 if Present
(Component_Clause
(CE
))
3557 and then Ada_Version
>= Ada_2005
3558 and then Reverse_Bit_Order
(Scope
(CE
))
3561 Make_Integer_Literal
(Loc
,
3562 Intval
=> Expr_Value
(First_Bit
(Component_Clause
(CE
)))));
3563 Analyze_And_Resolve
(N
, Typ
);
3565 -- Otherwise (Ada 83/95 or Ada 2005 or later with default bit order),
3566 -- rewrite with normalized value if we know it statically.
3568 elsif Known_Static_Component_Bit_Offset
(CE
) then
3570 Make_Integer_Literal
(Loc
,
3571 Component_Bit_Offset
(CE
) mod System_Storage_Unit
));
3572 Analyze_And_Resolve
(N
, Typ
);
3574 -- Otherwise left to back end, just do universal integer checks
3577 Apply_Universal_Integer_Attribute_Checks
(N
);
3581 --------------------------------
3582 -- Fixed_Value, Integer_Value --
3583 --------------------------------
3587 -- fixtype'Fixed_Value (integer-value)
3588 -- inttype'Fixed_Value (fixed-value)
3592 -- fixtype (integer-value)
3593 -- inttype (fixed-value)
3597 -- We do all the required analysis of the conversion here, because we do
3598 -- not want this to go through the fixed-point conversion circuits. Note
3599 -- that the back end always treats fixed-point as equivalent to the
3600 -- corresponding integer type anyway.
3602 when Attribute_Fixed_Value
3603 | Attribute_Integer_Value
3606 Make_Type_Conversion
(Loc
,
3607 Subtype_Mark
=> New_Occurrence_Of
(Entity
(Pref
), Loc
),
3608 Expression
=> Relocate_Node
(First
(Exprs
))));
3609 Set_Etype
(N
, Entity
(Pref
));
3612 -- Note: it might appear that a properly analyzed unchecked
3613 -- conversion would be just fine here, but that's not the case,
3614 -- since the full range checks performed by the following call
3617 Apply_Type_Conversion_Checks
(N
);
3623 -- Transforms 'Floor into a call to the floating-point attribute
3624 -- function Floor in Fat_xxx (where xxx is the root type)
3626 when Attribute_Floor
=>
3627 Expand_Fpt_Attribute_R
(N
);
3633 -- For the fixed-point type Typ:
3639 -- Result_Type (System.Fore (Universal_Real (Type'First)),
3640 -- Universal_Real (Type'Last))
3642 -- Note that we know that the type is a non-static subtype, or Fore
3643 -- would have itself been computed dynamically in Eval_Attribute.
3645 when Attribute_Fore
=>
3648 Make_Function_Call
(Loc
,
3650 New_Occurrence_Of
(RTE
(RE_Fore
), Loc
),
3652 Parameter_Associations
=> New_List
(
3653 Convert_To
(Universal_Real
,
3654 Make_Attribute_Reference
(Loc
,
3655 Prefix
=> New_Occurrence_Of
(Ptyp
, Loc
),
3656 Attribute_Name
=> Name_First
)),
3658 Convert_To
(Universal_Real
,
3659 Make_Attribute_Reference
(Loc
,
3660 Prefix
=> New_Occurrence_Of
(Ptyp
, Loc
),
3661 Attribute_Name
=> Name_Last
))))));
3663 Analyze_And_Resolve
(N
, Typ
);
3669 -- Transforms 'Fraction into a call to the floating-point attribute
3670 -- function Fraction in Fat_xxx (where xxx is the root type)
3672 when Attribute_Fraction
=>
3673 Expand_Fpt_Attribute_R
(N
);
3679 when Attribute_From_Any
=> From_Any
: declare
3680 P_Type
: constant Entity_Id
:= Etype
(Pref
);
3681 Decls
: constant List_Id
:= New_List
;
3685 Build_From_Any_Call
(P_Type
,
3686 Relocate_Node
(First
(Exprs
)),
3688 Insert_Actions
(N
, Decls
);
3689 Analyze_And_Resolve
(N
, P_Type
);
3692 ----------------------
3693 -- Has_Same_Storage --
3694 ----------------------
3696 when Attribute_Has_Same_Storage
=> Has_Same_Storage
: declare
3697 Loc
: constant Source_Ptr
:= Sloc
(N
);
3699 X
: constant Node_Id
:= Prefix
(N
);
3700 Y
: constant Node_Id
:= First
(Expressions
(N
));
3705 -- Rhe expressions for their addresses
3709 -- Rhe expressions for their sizes
3712 -- The attribute is expanded as:
3714 -- (X'address = Y'address)
3715 -- and then (X'Size = Y'Size)
3717 -- If both arguments have the same Etype the second conjunct can be
3721 Make_Attribute_Reference
(Loc
,
3722 Attribute_Name
=> Name_Address
,
3723 Prefix
=> New_Copy_Tree
(X
));
3726 Make_Attribute_Reference
(Loc
,
3727 Attribute_Name
=> Name_Address
,
3728 Prefix
=> New_Copy_Tree
(Y
));
3731 Make_Attribute_Reference
(Loc
,
3732 Attribute_Name
=> Name_Size
,
3733 Prefix
=> New_Copy_Tree
(X
));
3736 Make_Attribute_Reference
(Loc
,
3737 Attribute_Name
=> Name_Size
,
3738 Prefix
=> New_Copy_Tree
(Y
));
3740 if Etype
(X
) = Etype
(Y
) then
3743 Left_Opnd
=> X_Addr
,
3744 Right_Opnd
=> Y_Addr
));
3750 Left_Opnd
=> X_Addr
,
3751 Right_Opnd
=> Y_Addr
),
3754 Left_Opnd
=> X_Size
,
3755 Right_Opnd
=> Y_Size
)));
3758 Analyze_And_Resolve
(N
, Standard_Boolean
);
3759 end Has_Same_Storage
;
3765 -- For an exception returns a reference to the exception data:
3766 -- Exception_Id!(Prefix'Reference)
3768 -- For a task it returns a reference to the _task_id component of
3769 -- corresponding record:
3771 -- taskV!(Prefix)._Task_Id, converted to the type Task_Id defined
3773 -- in Ada.Task_Identification
3775 when Attribute_Identity
=> Identity
: declare
3776 Id_Kind
: Entity_Id
;
3779 if Ptyp
= Standard_Exception_Type
then
3780 Id_Kind
:= RTE
(RE_Exception_Id
);
3782 if Present
(Renamed_Object
(Entity
(Pref
))) then
3783 Set_Entity
(Pref
, Renamed_Object
(Entity
(Pref
)));
3787 Unchecked_Convert_To
(Id_Kind
, Make_Reference
(Loc
, Pref
)));
3789 Id_Kind
:= RTE
(RO_AT_Task_Id
);
3791 -- If the prefix is a task interface, the Task_Id is obtained
3792 -- dynamically through a dispatching call, as for other task
3793 -- attributes applied to interfaces.
3795 if Ada_Version
>= Ada_2005
3796 and then Ekind
(Ptyp
) = E_Class_Wide_Type
3797 and then Is_Interface
(Ptyp
)
3798 and then Is_Task_Interface
(Ptyp
)
3801 Unchecked_Convert_To
3802 (Id_Kind
, Build_Disp_Get_Task_Id_Call
(Pref
)));
3806 Unchecked_Convert_To
(Id_Kind
, Concurrent_Ref
(Pref
)));
3810 Analyze_And_Resolve
(N
, Id_Kind
);
3817 -- Image attribute is handled in separate unit Exp_Imgv
3819 when Attribute_Image
=>
3821 -- Leave attribute unexpanded in CodePeer mode: the gnat2scil
3822 -- back-end knows how to handle this attribute directly.
3824 if CodePeer_Mode
then
3828 Expand_Image_Attribute
(N
);
3834 -- X'Img is expanded to typ'Image (X), where typ is the type of X
3836 when Attribute_Img
=>
3837 Expand_Image_Attribute
(N
);
3843 when Attribute_Input
=> Input
: declare
3844 P_Type
: constant Entity_Id
:= Entity
(Pref
);
3845 B_Type
: constant Entity_Id
:= Base_Type
(P_Type
);
3846 U_Type
: constant Entity_Id
:= Underlying_Type
(P_Type
);
3847 Strm
: constant Node_Id
:= First
(Exprs
);
3855 Cntrl
: Node_Id
:= Empty
;
3856 -- Value for controlling argument in call. Always Empty except in
3857 -- the dispatching (class-wide type) case, where it is a reference
3858 -- to the dummy object initialized to the right internal tag.
3860 procedure Freeze_Stream_Subprogram
(F
: Entity_Id
);
3861 -- The expansion of the attribute reference may generate a call to
3862 -- a user-defined stream subprogram that is frozen by the call. This
3863 -- can lead to access-before-elaboration problem if the reference
3864 -- appears in an object declaration and the subprogram body has not
3865 -- been seen. The freezing of the subprogram requires special code
3866 -- because it appears in an expanded context where expressions do
3867 -- not freeze their constituents.
3869 ------------------------------
3870 -- Freeze_Stream_Subprogram --
3871 ------------------------------
3873 procedure Freeze_Stream_Subprogram
(F
: Entity_Id
) is
3874 Decl
: constant Node_Id
:= Unit_Declaration_Node
(F
);
3878 -- If this is user-defined subprogram, the corresponding
3879 -- stream function appears as a renaming-as-body, and the
3880 -- user subprogram must be retrieved by tree traversal.
3883 and then Nkind
(Decl
) = N_Subprogram_Declaration
3884 and then Present
(Corresponding_Body
(Decl
))
3886 Bod
:= Corresponding_Body
(Decl
);
3888 if Nkind
(Unit_Declaration_Node
(Bod
)) =
3889 N_Subprogram_Renaming_Declaration
3891 Set_Is_Frozen
(Entity
(Name
(Unit_Declaration_Node
(Bod
))));
3894 end Freeze_Stream_Subprogram
;
3896 -- Start of processing for Input
3899 -- If no underlying type, we have an error that will be diagnosed
3900 -- elsewhere, so here we just completely ignore the expansion.
3906 -- Stream operations can appear in user code even if the restriction
3907 -- No_Streams is active (for example, when instantiating a predefined
3908 -- container). In that case rewrite the attribute as a Raise to
3909 -- prevent any run-time use.
3911 if Restriction_Active
(No_Streams
) then
3913 Make_Raise_Program_Error
(Sloc
(N
),
3914 Reason
=> PE_Stream_Operation_Not_Allowed
));
3915 Set_Etype
(N
, B_Type
);
3919 -- If there is a TSS for Input, just call it
3921 Fname
:= Find_Stream_Subprogram
(P_Type
, TSS_Stream_Input
);
3923 if Present
(Fname
) then
3927 -- If there is a Stream_Convert pragma, use it, we rewrite
3929 -- sourcetyp'Input (stream)
3933 -- sourcetyp (streamread (strmtyp'Input (stream)));
3935 -- where streamread is the given Read function that converts an
3936 -- argument of type strmtyp to type sourcetyp or a type from which
3937 -- it is derived (extra conversion required for the derived case).
3939 Prag
:= Get_Stream_Convert_Pragma
(P_Type
);
3941 if Present
(Prag
) then
3942 Arg2
:= Next
(First
(Pragma_Argument_Associations
(Prag
)));
3943 Rfunc
:= Entity
(Expression
(Arg2
));
3947 Make_Function_Call
(Loc
,
3948 Name
=> New_Occurrence_Of
(Rfunc
, Loc
),
3949 Parameter_Associations
=> New_List
(
3950 Make_Attribute_Reference
(Loc
,
3953 (Etype
(First_Formal
(Rfunc
)), Loc
),
3954 Attribute_Name
=> Name_Input
,
3955 Expressions
=> Exprs
)))));
3957 Analyze_And_Resolve
(N
, B_Type
);
3962 elsif Is_Elementary_Type
(U_Type
) then
3964 -- A special case arises if we have a defined _Read routine,
3965 -- since in this case we are required to call this routine.
3968 Typ
: Entity_Id
:= P_Type
;
3970 if Present
(Full_View
(Typ
)) then
3971 Typ
:= Full_View
(Typ
);
3974 if Present
(TSS
(Base_Type
(Typ
), TSS_Stream_Read
)) then
3975 Build_Record_Or_Elementary_Input_Function
3976 (Loc
, Typ
, Decl
, Fname
, Use_Underlying
=> False);
3977 Insert_Action
(N
, Decl
);
3979 -- For normal cases, we call the I_xxx routine directly
3982 Rewrite
(N
, Build_Elementary_Input_Call
(N
));
3983 Analyze_And_Resolve
(N
, P_Type
);
3990 elsif Is_Array_Type
(U_Type
) then
3991 Build_Array_Input_Function
(Loc
, U_Type
, Decl
, Fname
);
3992 Compile_Stream_Body_In_Scope
(N
, Decl
, U_Type
, Check
=> False);
3994 -- Dispatching case with class-wide type
3996 elsif Is_Class_Wide_Type
(P_Type
) then
3998 -- No need to do anything else compiling under restriction
3999 -- No_Dispatching_Calls. During the semantic analysis we
4000 -- already notified such violation.
4002 if Restriction_Active
(No_Dispatching_Calls
) then
4007 Rtyp
: constant Entity_Id
:= Root_Type
(P_Type
);
4011 -- Read the internal tag (RM 13.13.2(34)) and use it to
4012 -- initialize a dummy tag value. We used to generate:
4014 -- Descendant_Tag (String'Input (Strm), P_Type);
4016 -- which turns into a call to String_Input_Blk_IO. However,
4017 -- if the input is malformed, that could try to read an
4018 -- enormous String, causing chaos. So instead we call
4019 -- String_Input_Tag, which does the same thing as
4020 -- String_Input_Blk_IO, except that if the String is
4021 -- absurdly long, it raises an exception.
4023 -- This value is used only to provide a controlling
4024 -- argument for the eventual _Input call. Descendant_Tag is
4025 -- called rather than Internal_Tag to ensure that we have a
4026 -- tag for a type that is descended from the prefix type and
4027 -- declared at the same accessibility level (the exception
4028 -- Tag_Error will be raised otherwise). The level check is
4029 -- required for Ada 2005 because tagged types can be
4030 -- extended in nested scopes (AI-344).
4032 -- Note: we used to generate an explicit declaration of a
4033 -- constant Ada.Tags.Tag object, and use an occurrence of
4034 -- this constant in Cntrl, but this caused a secondary stack
4038 Make_Function_Call
(Loc
,
4040 New_Occurrence_Of
(RTE
(RE_Descendant_Tag
), Loc
),
4041 Parameter_Associations
=> New_List
(
4042 Make_Function_Call
(Loc
,
4045 (RTE
(RE_String_Input_Tag
), Loc
),
4046 Parameter_Associations
=> New_List
(
4047 Relocate_Node
(Duplicate_Subexpr
(Strm
)))),
4049 Make_Attribute_Reference
(Loc
,
4050 Prefix
=> New_Occurrence_Of
(P_Type
, Loc
),
4051 Attribute_Name
=> Name_Tag
)));
4053 Set_Etype
(Expr
, RTE
(RE_Tag
));
4055 -- Now we need to get the entity for the call, and construct
4056 -- a function call node, where we preset a reference to Dnn
4057 -- as the controlling argument (doing an unchecked convert
4058 -- to the class-wide tagged type to make it look like a real
4061 Fname
:= Find_Prim_Op
(Rtyp
, TSS_Stream_Input
);
4062 Cntrl
:= Unchecked_Convert_To
(P_Type
, Expr
);
4063 Set_Etype
(Cntrl
, P_Type
);
4064 Set_Parent
(Cntrl
, N
);
4067 -- For tagged types, use the primitive Input function
4069 elsif Is_Tagged_Type
(U_Type
) then
4070 Fname
:= Find_Prim_Op
(U_Type
, TSS_Stream_Input
);
4072 -- All other record type cases, including protected records. The
4073 -- latter only arise for expander generated code for handling
4074 -- shared passive partition access.
4078 (Is_Record_Type
(U_Type
) or else Is_Protected_Type
(U_Type
));
4080 -- Ada 2005 (AI-216): Program_Error is raised executing default
4081 -- implementation of the Input attribute of an unchecked union
4082 -- type if the type lacks default discriminant values.
4084 if Is_Unchecked_Union
(Base_Type
(U_Type
))
4085 and then No
(Discriminant_Constraint
(U_Type
))
4088 Make_Raise_Program_Error
(Loc
,
4089 Reason
=> PE_Unchecked_Union_Restriction
));
4094 -- Build the type's Input function, passing the subtype rather
4095 -- than its base type, because checks are needed in the case of
4096 -- constrained discriminants (see Ada 2012 AI05-0192).
4098 Build_Record_Or_Elementary_Input_Function
4099 (Loc
, U_Type
, Decl
, Fname
);
4100 Insert_Action
(N
, Decl
);
4102 if Nkind
(Parent
(N
)) = N_Object_Declaration
4103 and then Is_Record_Type
(U_Type
)
4105 -- The stream function may contain calls to user-defined
4106 -- Read procedures for individual components.
4113 Comp
:= First_Component
(U_Type
);
4114 while Present
(Comp
) loop
4116 Find_Stream_Subprogram
4117 (Etype
(Comp
), TSS_Stream_Read
);
4119 if Present
(Func
) then
4120 Freeze_Stream_Subprogram
(Func
);
4123 Next_Component
(Comp
);
4130 -- If we fall through, Fname is the function to be called. The result
4131 -- is obtained by calling the appropriate function, then converting
4132 -- the result. The conversion does a subtype check.
4135 Make_Function_Call
(Loc
,
4136 Name
=> New_Occurrence_Of
(Fname
, Loc
),
4137 Parameter_Associations
=> New_List
(
4138 Relocate_Node
(Strm
)));
4140 Set_Controlling_Argument
(Call
, Cntrl
);
4141 Rewrite
(N
, Unchecked_Convert_To
(P_Type
, Call
));
4142 Analyze_And_Resolve
(N
, P_Type
);
4144 if Nkind
(Parent
(N
)) = N_Object_Declaration
then
4145 Freeze_Stream_Subprogram
(Fname
);
4153 when Attribute_Invalid_Value
=>
4154 Rewrite
(N
, Get_Simple_Init_Val
(Ptyp
, N
));
4160 when Attribute_Last
=>
4162 -- If the prefix type is a constrained packed array type which
4163 -- already has a Packed_Array_Impl_Type representation defined, then
4164 -- replace this attribute with a direct reference to 'Last of the
4165 -- appropriate index subtype (since otherwise the back end will try
4166 -- to give us the value of 'Last for this implementation type).
4168 if Is_Constrained_Packed_Array
(Ptyp
) then
4170 Make_Attribute_Reference
(Loc
,
4171 Attribute_Name
=> Name_Last
,
4172 Prefix
=> New_Occurrence_Of
(Get_Index_Subtype
(N
), Loc
)));
4173 Analyze_And_Resolve
(N
, Typ
);
4175 -- For access type, apply access check as needed
4177 elsif Is_Access_Type
(Ptyp
) then
4178 Apply_Access_Check
(N
);
4180 -- For scalar type, if low bound is a reference to an entity, just
4181 -- replace with a direct reference. Note that we can only have a
4182 -- reference to a constant entity at this stage, anything else would
4183 -- have already been rewritten.
4185 elsif Is_Scalar_Type
(Ptyp
) then
4187 Hi
: constant Node_Id
:= Type_High_Bound
(Ptyp
);
4189 if Is_Entity_Name
(Hi
) then
4190 Rewrite
(N
, New_Occurrence_Of
(Entity
(Hi
), Loc
));
4199 -- We compute this if a component clause was present, otherwise we leave
4200 -- the computation up to the back end, since we don't know what layout
4203 when Attribute_Last_Bit
=> Last_Bit_Attr
: declare
4204 CE
: constant Entity_Id
:= Entity
(Selector_Name
(Pref
));
4207 -- In Ada 2005 (or later) if we have the non-default bit order, then
4208 -- we return the original value as given in the component clause
4209 -- (RM 2005 13.5.2(3/2)).
4211 if Present
(Component_Clause
(CE
))
4212 and then Ada_Version
>= Ada_2005
4213 and then Reverse_Bit_Order
(Scope
(CE
))
4216 Make_Integer_Literal
(Loc
,
4217 Intval
=> Expr_Value
(Last_Bit
(Component_Clause
(CE
)))));
4218 Analyze_And_Resolve
(N
, Typ
);
4220 -- Otherwise (Ada 83/95 or Ada 2005 or later with default bit order),
4221 -- rewrite with normalized value if we know it statically.
4223 elsif Known_Static_Component_Bit_Offset
(CE
)
4224 and then Known_Static_Esize
(CE
)
4227 Make_Integer_Literal
(Loc
,
4228 Intval
=> (Component_Bit_Offset
(CE
) mod System_Storage_Unit
)
4230 Analyze_And_Resolve
(N
, Typ
);
4232 -- Otherwise leave to back end, just apply universal integer checks
4235 Apply_Universal_Integer_Attribute_Checks
(N
);
4243 -- Transforms 'Leading_Part into a call to the floating-point attribute
4244 -- function Leading_Part in Fat_xxx (where xxx is the root type)
4246 -- Note: strictly, we should generate special case code to deal with
4247 -- absurdly large positive arguments (greater than Integer'Last), which
4248 -- result in returning the first argument unchanged, but it hardly seems
4249 -- worth the effort. We raise constraint error for absurdly negative
4250 -- arguments which is fine.
4252 when Attribute_Leading_Part
=>
4253 Expand_Fpt_Attribute_RI
(N
);
4259 when Attribute_Length
=> Length
: declare
4264 -- Processing for packed array types
4266 if Is_Array_Type
(Ptyp
) and then Is_Packed
(Ptyp
) then
4267 Ityp
:= Get_Index_Subtype
(N
);
4269 -- If the index type, Ityp, is an enumeration type with holes,
4270 -- then we calculate X'Length explicitly using
4273 -- (0, Ityp'Pos (X'Last (N)) -
4274 -- Ityp'Pos (X'First (N)) + 1);
4276 -- Since the bounds in the template are the representation values
4277 -- and the back end would get the wrong value.
4279 if Is_Enumeration_Type
(Ityp
)
4280 and then Present
(Enum_Pos_To_Rep
(Base_Type
(Ityp
)))
4285 Xnum
:= Expr_Value
(First
(Expressions
(N
)));
4289 Make_Attribute_Reference
(Loc
,
4290 Prefix
=> New_Occurrence_Of
(Typ
, Loc
),
4291 Attribute_Name
=> Name_Max
,
4292 Expressions
=> New_List
4293 (Make_Integer_Literal
(Loc
, 0),
4297 Make_Op_Subtract
(Loc
,
4299 Make_Attribute_Reference
(Loc
,
4300 Prefix
=> New_Occurrence_Of
(Ityp
, Loc
),
4301 Attribute_Name
=> Name_Pos
,
4303 Expressions
=> New_List
(
4304 Make_Attribute_Reference
(Loc
,
4305 Prefix
=> Duplicate_Subexpr
(Pref
),
4306 Attribute_Name
=> Name_Last
,
4307 Expressions
=> New_List
(
4308 Make_Integer_Literal
(Loc
, Xnum
))))),
4311 Make_Attribute_Reference
(Loc
,
4312 Prefix
=> New_Occurrence_Of
(Ityp
, Loc
),
4313 Attribute_Name
=> Name_Pos
,
4315 Expressions
=> New_List
(
4316 Make_Attribute_Reference
(Loc
,
4318 Duplicate_Subexpr_No_Checks
(Pref
),
4319 Attribute_Name
=> Name_First
,
4320 Expressions
=> New_List
(
4321 Make_Integer_Literal
(Loc
, Xnum
)))))),
4323 Right_Opnd
=> Make_Integer_Literal
(Loc
, 1)))));
4325 Analyze_And_Resolve
(N
, Typ
, Suppress
=> All_Checks
);
4328 -- If the prefix type is a constrained packed array type which
4329 -- already has a Packed_Array_Impl_Type representation defined,
4330 -- then replace this attribute with a reference to 'Range_Length
4331 -- of the appropriate index subtype (since otherwise the
4332 -- back end will try to give us the value of 'Length for
4333 -- this implementation type).s
4335 elsif Is_Constrained
(Ptyp
) then
4337 Make_Attribute_Reference
(Loc
,
4338 Attribute_Name
=> Name_Range_Length
,
4339 Prefix
=> New_Occurrence_Of
(Ityp
, Loc
)));
4340 Analyze_And_Resolve
(N
, Typ
);
4345 elsif Is_Access_Type
(Ptyp
) then
4346 Apply_Access_Check
(N
);
4348 -- If the designated type is a packed array type, then we convert
4349 -- the reference to:
4352 -- xtyp'Pos (Pref'Last (Expr)) -
4353 -- xtyp'Pos (Pref'First (Expr)));
4355 -- This is a bit complex, but it is the easiest thing to do that
4356 -- works in all cases including enum types with holes xtyp here
4357 -- is the appropriate index type.
4360 Dtyp
: constant Entity_Id
:= Designated_Type
(Ptyp
);
4364 if Is_Array_Type
(Dtyp
) and then Is_Packed
(Dtyp
) then
4365 Xtyp
:= Get_Index_Subtype
(N
);
4368 Make_Attribute_Reference
(Loc
,
4369 Prefix
=> New_Occurrence_Of
(Typ
, Loc
),
4370 Attribute_Name
=> Name_Max
,
4371 Expressions
=> New_List
(
4372 Make_Integer_Literal
(Loc
, 0),
4375 Make_Integer_Literal
(Loc
, 1),
4376 Make_Op_Subtract
(Loc
,
4378 Make_Attribute_Reference
(Loc
,
4379 Prefix
=> New_Occurrence_Of
(Xtyp
, Loc
),
4380 Attribute_Name
=> Name_Pos
,
4381 Expressions
=> New_List
(
4382 Make_Attribute_Reference
(Loc
,
4383 Prefix
=> Duplicate_Subexpr
(Pref
),
4384 Attribute_Name
=> Name_Last
,
4386 New_Copy_List
(Exprs
)))),
4389 Make_Attribute_Reference
(Loc
,
4390 Prefix
=> New_Occurrence_Of
(Xtyp
, Loc
),
4391 Attribute_Name
=> Name_Pos
,
4392 Expressions
=> New_List
(
4393 Make_Attribute_Reference
(Loc
,
4395 Duplicate_Subexpr_No_Checks
(Pref
),
4396 Attribute_Name
=> Name_First
,
4398 New_Copy_List
(Exprs
)))))))));
4400 Analyze_And_Resolve
(N
, Typ
);
4404 -- Otherwise leave it to the back end
4407 Apply_Universal_Integer_Attribute_Checks
(N
);
4411 -- Attribute Loop_Entry is replaced with a reference to a constant value
4412 -- which captures the prefix at the entry point of the related loop. The
4413 -- loop itself may be transformed into a conditional block.
4415 when Attribute_Loop_Entry
=>
4416 Expand_Loop_Entry_Attribute
(N
);
4422 -- Transforms 'Machine into a call to the floating-point attribute
4423 -- function Machine in Fat_xxx (where xxx is the root type).
4424 -- Expansion is avoided for cases the back end can handle directly.
4426 when Attribute_Machine
=>
4427 if not Is_Inline_Floating_Point_Attribute
(N
) then
4428 Expand_Fpt_Attribute_R
(N
);
4431 ----------------------
4432 -- Machine_Rounding --
4433 ----------------------
4435 -- Transforms 'Machine_Rounding into a call to the floating-point
4436 -- attribute function Machine_Rounding in Fat_xxx (where xxx is the root
4437 -- type). Expansion is avoided for cases the back end can handle
4440 when Attribute_Machine_Rounding
=>
4441 if not Is_Inline_Floating_Point_Attribute
(N
) then
4442 Expand_Fpt_Attribute_R
(N
);
4449 -- Machine_Size is equivalent to Object_Size, so transform it into
4450 -- Object_Size and that way the back end never sees Machine_Size.
4452 when Attribute_Machine_Size
=>
4454 Make_Attribute_Reference
(Loc
,
4455 Prefix
=> Prefix
(N
),
4456 Attribute_Name
=> Name_Object_Size
));
4458 Analyze_And_Resolve
(N
, Typ
);
4464 -- The only case that can get this far is the dynamic case of the old
4465 -- Ada 83 Mantissa attribute for the fixed-point case. For this case,
4472 -- ityp (System.Mantissa.Mantissa_Value
4473 -- (Integer'Integer_Value (typ'First),
4474 -- Integer'Integer_Value (typ'Last)));
4476 when Attribute_Mantissa
=>
4479 Make_Function_Call
(Loc
,
4481 New_Occurrence_Of
(RTE
(RE_Mantissa_Value
), Loc
),
4483 Parameter_Associations
=> New_List
(
4484 Make_Attribute_Reference
(Loc
,
4485 Prefix
=> New_Occurrence_Of
(Standard_Integer
, Loc
),
4486 Attribute_Name
=> Name_Integer_Value
,
4487 Expressions
=> New_List
(
4488 Make_Attribute_Reference
(Loc
,
4489 Prefix
=> New_Occurrence_Of
(Ptyp
, Loc
),
4490 Attribute_Name
=> Name_First
))),
4492 Make_Attribute_Reference
(Loc
,
4493 Prefix
=> New_Occurrence_Of
(Standard_Integer
, Loc
),
4494 Attribute_Name
=> Name_Integer_Value
,
4495 Expressions
=> New_List
(
4496 Make_Attribute_Reference
(Loc
,
4497 Prefix
=> New_Occurrence_Of
(Ptyp
, Loc
),
4498 Attribute_Name
=> Name_Last
)))))));
4500 Analyze_And_Resolve
(N
, Typ
);
4506 when Attribute_Max
=>
4507 Expand_Min_Max_Attribute
(N
);
4509 ----------------------------------
4510 -- Max_Size_In_Storage_Elements --
4511 ----------------------------------
4513 when Attribute_Max_Size_In_Storage_Elements
=> declare
4514 Typ
: constant Entity_Id
:= Etype
(N
);
4517 Conversion_Added
: Boolean := False;
4518 -- A flag which tracks whether the original attribute has been
4519 -- wrapped inside a type conversion.
4522 -- If the prefix is X'Class, we transform it into a direct reference
4523 -- to the class-wide type, because the back end must not see a 'Class
4524 -- reference. See also 'Size.
4526 if Is_Entity_Name
(Pref
)
4527 and then Is_Class_Wide_Type
(Entity
(Pref
))
4529 Rewrite
(Prefix
(N
), New_Occurrence_Of
(Entity
(Pref
), Loc
));
4533 Apply_Universal_Integer_Attribute_Checks
(N
);
4535 -- The universal integer check may sometimes add a type conversion,
4536 -- retrieve the original attribute reference from the expression.
4540 if Nkind
(Attr
) = N_Type_Conversion
then
4541 Attr
:= Expression
(Attr
);
4542 Conversion_Added
:= True;
4545 pragma Assert
(Nkind
(Attr
) = N_Attribute_Reference
);
4547 -- Heap-allocated controlled objects contain two extra pointers which
4548 -- are not part of the actual type. Transform the attribute reference
4549 -- into a runtime expression to add the size of the hidden header.
4551 if Needs_Finalization
(Ptyp
)
4552 and then not Header_Size_Added
(Attr
)
4554 Set_Header_Size_Added
(Attr
);
4557 -- P'Max_Size_In_Storage_Elements +
4558 -- Universal_Integer
4559 -- (Header_Size_With_Padding (Ptyp'Alignment))
4563 Left_Opnd
=> Relocate_Node
(Attr
),
4565 Convert_To
(Universal_Integer
,
4566 Make_Function_Call
(Loc
,
4569 (RTE
(RE_Header_Size_With_Padding
), Loc
),
4571 Parameter_Associations
=> New_List
(
4572 Make_Attribute_Reference
(Loc
,
4574 New_Occurrence_Of
(Ptyp
, Loc
),
4575 Attribute_Name
=> Name_Alignment
))))));
4577 -- Add a conversion to the target type
4579 if not Conversion_Added
then
4581 Make_Type_Conversion
(Loc
,
4582 Subtype_Mark
=> New_Occurrence_Of
(Typ
, Loc
),
4583 Expression
=> Relocate_Node
(Attr
)));
4591 --------------------
4592 -- Mechanism_Code --
4593 --------------------
4595 when Attribute_Mechanism_Code
=>
4597 -- We must replace the prefix in the renamed case
4599 if Is_Entity_Name
(Pref
)
4600 and then Present
(Alias
(Entity
(Pref
)))
4602 Set_Renamed_Subprogram
(Pref
, Alias
(Entity
(Pref
)));
4609 when Attribute_Min
=>
4610 Expand_Min_Max_Attribute
(N
);
4616 when Attribute_Mod
=> Mod_Case
: declare
4617 Arg
: constant Node_Id
:= Relocate_Node
(First
(Exprs
));
4618 Hi
: constant Node_Id
:= Type_High_Bound
(Etype
(Arg
));
4619 Modv
: constant Uint
:= Modulus
(Btyp
);
4623 -- This is not so simple. The issue is what type to use for the
4624 -- computation of the modular value.
4626 -- The easy case is when the modulus value is within the bounds
4627 -- of the signed integer type of the argument. In this case we can
4628 -- just do the computation in that signed integer type, and then
4629 -- do an ordinary conversion to the target type.
4631 if Modv
<= Expr_Value
(Hi
) then
4636 Right_Opnd
=> Make_Integer_Literal
(Loc
, Modv
))));
4638 -- Here we know that the modulus is larger than type'Last of the
4639 -- integer type. There are two cases to consider:
4641 -- a) The integer value is non-negative. In this case, it is
4642 -- returned as the result (since it is less than the modulus).
4644 -- b) The integer value is negative. In this case, we know that the
4645 -- result is modulus + value, where the value might be as small as
4646 -- -modulus. The trouble is what type do we use to do the subtract.
4647 -- No type will do, since modulus can be as big as 2**64, and no
4648 -- integer type accommodates this value. Let's do bit of algebra
4651 -- = modulus - (-value)
4652 -- = (modulus - 1) - (-value - 1)
4654 -- Now modulus - 1 is certainly in range of the modular type.
4655 -- -value is in the range 1 .. modulus, so -value -1 is in the
4656 -- range 0 .. modulus-1 which is in range of the modular type.
4657 -- Furthermore, (-value - 1) can be expressed as -(value + 1)
4658 -- which we can compute using the integer base type.
4660 -- Once this is done we analyze the if expression without range
4661 -- checks, because we know everything is in range, and we want
4662 -- to prevent spurious warnings on either branch.
4666 Make_If_Expression
(Loc
,
4667 Expressions
=> New_List
(
4669 Left_Opnd
=> Duplicate_Subexpr
(Arg
),
4670 Right_Opnd
=> Make_Integer_Literal
(Loc
, 0)),
4673 Duplicate_Subexpr_No_Checks
(Arg
)),
4675 Make_Op_Subtract
(Loc
,
4677 Make_Integer_Literal
(Loc
,
4678 Intval
=> Modv
- 1),
4684 Left_Opnd
=> Duplicate_Subexpr_No_Checks
(Arg
),
4686 Make_Integer_Literal
(Loc
,
4687 Intval
=> 1))))))));
4691 Analyze_And_Resolve
(N
, Btyp
, Suppress
=> All_Checks
);
4698 -- Transforms 'Model into a call to the floating-point attribute
4699 -- function Model in Fat_xxx (where xxx is the root type).
4700 -- Expansion is avoided for cases the back end can handle directly.
4702 when Attribute_Model
=>
4703 if not Is_Inline_Floating_Point_Attribute
(N
) then
4704 Expand_Fpt_Attribute_R
(N
);
4711 -- The processing for Object_Size shares the processing for Size
4717 when Attribute_Old
=> Old
: declare
4718 Typ
: constant Entity_Id
:= Etype
(N
);
4719 CW_Temp
: Entity_Id
;
4726 -- Generating C code we don't need to expand this attribute when
4727 -- we are analyzing the internally built nested postconditions
4728 -- procedure since it will be expanded inline (and later it will
4729 -- be removed by Expand_N_Subprogram_Body). It this expansion is
4730 -- performed in such case then the compiler generates unreferenced
4731 -- extra temporaries.
4733 if Modify_Tree_For_C
4734 and then Chars
(Current_Scope
) = Name_uPostconditions
4739 -- Climb the parent chain looking for subprogram _Postconditions
4742 while Present
(Subp
) loop
4743 exit when Nkind
(Subp
) = N_Subprogram_Body
4744 and then Chars
(Defining_Entity
(Subp
)) = Name_uPostconditions
;
4746 -- If assertions are disabled, no need to create the declaration
4747 -- that preserves the value. The postcondition pragma in which
4748 -- 'Old appears will be checked or disabled according to the
4749 -- current policy in effect.
4751 if Nkind
(Subp
) = N_Pragma
and then not Is_Checked
(Subp
) then
4755 Subp
:= Parent
(Subp
);
4758 -- 'Old can only appear in a postcondition, the generated body of
4759 -- _Postconditions must be in the tree (or inlined if we are
4760 -- generating C code).
4764 or else (Modify_Tree_For_C
and then In_Inlined_Body
));
4766 Temp
:= Make_Temporary
(Loc
, 'T', Pref
);
4768 -- Set the entity kind now in order to mark the temporary as a
4769 -- handler of attribute 'Old's prefix.
4771 Set_Ekind
(Temp
, E_Constant
);
4772 Set_Stores_Attribute_Old_Prefix
(Temp
);
4774 -- Push the scope of the related subprogram where _Postcondition
4775 -- resides as this ensures that the object will be analyzed in the
4778 if Present
(Subp
) then
4779 Push_Scope
(Scope
(Defining_Entity
(Subp
)));
4781 -- No need to push the scope when generating C code since the
4782 -- _Postcondition procedure has been inlined.
4784 else pragma Assert
(Modify_Tree_For_C
);
4785 pragma Assert
(In_Inlined_Body
);
4789 -- Locate the insertion place of the internal temporary that saves
4792 if Present
(Subp
) then
4795 -- Generating C, the postcondition procedure has been inlined and the
4796 -- temporary is added before the first declaration of the enclosing
4799 else pragma Assert
(Modify_Tree_For_C
);
4801 while Nkind
(Ins_Nod
) /= N_Subprogram_Body
loop
4802 Ins_Nod
:= Parent
(Ins_Nod
);
4805 Ins_Nod
:= First
(Declarations
(Ins_Nod
));
4808 -- Preserve the tag of the prefix by offering a specific view of the
4809 -- class-wide version of the prefix.
4811 if Is_Tagged_Type
(Typ
) then
4814 -- CW_Temp : constant Typ'Class := Typ'Class (Pref);
4816 CW_Temp
:= Make_Temporary
(Loc
, 'T');
4817 CW_Typ
:= Class_Wide_Type
(Typ
);
4819 Insert_Before_And_Analyze
(Ins_Nod
,
4820 Make_Object_Declaration
(Loc
,
4821 Defining_Identifier
=> CW_Temp
,
4822 Constant_Present
=> True,
4823 Object_Definition
=> New_Occurrence_Of
(CW_Typ
, Loc
),
4825 Convert_To
(CW_Typ
, Relocate_Node
(Pref
))));
4828 -- Temp : Typ renames Typ (CW_Temp);
4830 Insert_Before_And_Analyze
(Ins_Nod
,
4831 Make_Object_Renaming_Declaration
(Loc
,
4832 Defining_Identifier
=> Temp
,
4833 Subtype_Mark
=> New_Occurrence_Of
(Typ
, Loc
),
4835 Convert_To
(Typ
, New_Occurrence_Of
(CW_Temp
, Loc
))));
4841 -- Temp : constant Typ := Pref;
4843 Insert_Before_And_Analyze
(Ins_Nod
,
4844 Make_Object_Declaration
(Loc
,
4845 Defining_Identifier
=> Temp
,
4846 Constant_Present
=> True,
4847 Object_Definition
=> New_Occurrence_Of
(Typ
, Loc
),
4848 Expression
=> Relocate_Node
(Pref
)));
4851 if Present
(Subp
) then
4855 -- Ensure that the prefix of attribute 'Old is valid. The check must
4856 -- be inserted after the expansion of the attribute has taken place
4857 -- to reflect the new placement of the prefix.
4859 if Validity_Checks_On
and then Validity_Check_Operands
then
4860 Ensure_Valid
(Pref
);
4863 Rewrite
(N
, New_Occurrence_Of
(Temp
, Loc
));
4866 ----------------------
4867 -- Overlaps_Storage --
4868 ----------------------
4870 when Attribute_Overlaps_Storage
=> Overlaps_Storage
: declare
4871 Loc
: constant Source_Ptr
:= Sloc
(N
);
4873 X
: constant Node_Id
:= Prefix
(N
);
4874 Y
: constant Node_Id
:= First
(Expressions
(N
));
4877 X_Addr
, Y_Addr
: Node_Id
;
4878 -- the expressions for their integer addresses
4880 X_Size
, Y_Size
: Node_Id
;
4881 -- the expressions for their sizes
4886 -- Attribute expands into:
4888 -- if X'Address < Y'address then
4889 -- (X'address + X'Size - 1) >= Y'address
4891 -- (Y'address + Y'size - 1) >= X'Address
4894 -- with the proper address operations. We convert addresses to
4895 -- integer addresses to use predefined arithmetic. The size is
4896 -- expressed in storage units. We add copies of X_Addr and Y_Addr
4897 -- to prevent the appearance of the same node in two places in
4901 Unchecked_Convert_To
(RTE
(RE_Integer_Address
),
4902 Make_Attribute_Reference
(Loc
,
4903 Attribute_Name
=> Name_Address
,
4904 Prefix
=> New_Copy_Tree
(X
)));
4907 Unchecked_Convert_To
(RTE
(RE_Integer_Address
),
4908 Make_Attribute_Reference
(Loc
,
4909 Attribute_Name
=> Name_Address
,
4910 Prefix
=> New_Copy_Tree
(Y
)));
4913 Make_Op_Divide
(Loc
,
4915 Make_Attribute_Reference
(Loc
,
4916 Attribute_Name
=> Name_Size
,
4917 Prefix
=> New_Copy_Tree
(X
)),
4919 Make_Integer_Literal
(Loc
, System_Storage_Unit
));
4922 Make_Op_Divide
(Loc
,
4924 Make_Attribute_Reference
(Loc
,
4925 Attribute_Name
=> Name_Size
,
4926 Prefix
=> New_Copy_Tree
(Y
)),
4928 Make_Integer_Literal
(Loc
, System_Storage_Unit
));
4932 Left_Opnd
=> X_Addr
,
4933 Right_Opnd
=> Y_Addr
);
4936 Make_If_Expression
(Loc
, New_List
(
4942 Left_Opnd
=> New_Copy_Tree
(X_Addr
),
4944 Make_Op_Subtract
(Loc
,
4945 Left_Opnd
=> X_Size
,
4946 Right_Opnd
=> Make_Integer_Literal
(Loc
, 1))),
4947 Right_Opnd
=> Y_Addr
),
4952 Left_Opnd
=> New_Copy_Tree
(Y_Addr
),
4954 Make_Op_Subtract
(Loc
,
4955 Left_Opnd
=> Y_Size
,
4956 Right_Opnd
=> Make_Integer_Literal
(Loc
, 1))),
4957 Right_Opnd
=> X_Addr
))));
4959 Analyze_And_Resolve
(N
, Standard_Boolean
);
4960 end Overlaps_Storage
;
4966 when Attribute_Output
=> Output
: declare
4967 P_Type
: constant Entity_Id
:= Entity
(Pref
);
4968 U_Type
: constant Entity_Id
:= Underlying_Type
(P_Type
);
4976 -- If no underlying type, we have an error that will be diagnosed
4977 -- elsewhere, so here we just completely ignore the expansion.
4983 -- Stream operations can appear in user code even if the restriction
4984 -- No_Streams is active (for example, when instantiating a predefined
4985 -- container). In that case rewrite the attribute as a Raise to
4986 -- prevent any run-time use.
4988 if Restriction_Active
(No_Streams
) then
4990 Make_Raise_Program_Error
(Sloc
(N
),
4991 Reason
=> PE_Stream_Operation_Not_Allowed
));
4992 Set_Etype
(N
, Standard_Void_Type
);
4996 -- If TSS for Output is present, just call it
4998 Pname
:= Find_Stream_Subprogram
(P_Type
, TSS_Stream_Output
);
5000 if Present
(Pname
) then
5004 -- If there is a Stream_Convert pragma, use it, we rewrite
5006 -- sourcetyp'Output (stream, Item)
5010 -- strmtyp'Output (Stream, strmwrite (acttyp (Item)));
5012 -- where strmwrite is the given Write function that converts an
5013 -- argument of type sourcetyp or a type acctyp, from which it is
5014 -- derived to type strmtyp. The conversion to acttyp is required
5015 -- for the derived case.
5017 Prag
:= Get_Stream_Convert_Pragma
(P_Type
);
5019 if Present
(Prag
) then
5021 Next
(Next
(First
(Pragma_Argument_Associations
(Prag
))));
5022 Wfunc
:= Entity
(Expression
(Arg3
));
5025 Make_Attribute_Reference
(Loc
,
5026 Prefix
=> New_Occurrence_Of
(Etype
(Wfunc
), Loc
),
5027 Attribute_Name
=> Name_Output
,
5028 Expressions
=> New_List
(
5029 Relocate_Node
(First
(Exprs
)),
5030 Make_Function_Call
(Loc
,
5031 Name
=> New_Occurrence_Of
(Wfunc
, Loc
),
5032 Parameter_Associations
=> New_List
(
5033 OK_Convert_To
(Etype
(First_Formal
(Wfunc
)),
5034 Relocate_Node
(Next
(First
(Exprs
)))))))));
5039 -- For elementary types, we call the W_xxx routine directly. Note
5040 -- that the effect of Write and Output is identical for the case
5041 -- of an elementary type (there are no discriminants or bounds).
5043 elsif Is_Elementary_Type
(U_Type
) then
5045 -- A special case arises if we have a defined _Write routine,
5046 -- since in this case we are required to call this routine.
5049 Typ
: Entity_Id
:= P_Type
;
5051 if Present
(Full_View
(Typ
)) then
5052 Typ
:= Full_View
(Typ
);
5055 if Present
(TSS
(Base_Type
(Typ
), TSS_Stream_Write
)) then
5056 Build_Record_Or_Elementary_Output_Procedure
5057 (Loc
, Typ
, Decl
, Pname
);
5058 Insert_Action
(N
, Decl
);
5060 -- For normal cases, we call the W_xxx routine directly
5063 Rewrite
(N
, Build_Elementary_Write_Call
(N
));
5071 elsif Is_Array_Type
(U_Type
) then
5072 Build_Array_Output_Procedure
(Loc
, U_Type
, Decl
, Pname
);
5073 Compile_Stream_Body_In_Scope
(N
, Decl
, U_Type
, Check
=> False);
5075 -- Class-wide case, first output external tag, then dispatch
5076 -- to the appropriate primitive Output function (RM 13.13.2(31)).
5078 elsif Is_Class_Wide_Type
(P_Type
) then
5080 -- No need to do anything else compiling under restriction
5081 -- No_Dispatching_Calls. During the semantic analysis we
5082 -- already notified such violation.
5084 if Restriction_Active
(No_Dispatching_Calls
) then
5089 Strm
: constant Node_Id
:= First
(Exprs
);
5090 Item
: constant Node_Id
:= Next
(Strm
);
5093 -- Ada 2005 (AI-344): Check that the accessibility level
5094 -- of the type of the output object is not deeper than
5095 -- that of the attribute's prefix type.
5097 -- if Get_Access_Level (Item'Tag)
5098 -- /= Get_Access_Level (P_Type'Tag)
5103 -- String'Output (Strm, External_Tag (Item'Tag));
5105 -- We cannot figure out a practical way to implement this
5106 -- accessibility check on virtual machines, so we omit it.
5108 if Ada_Version
>= Ada_2005
5109 and then Tagged_Type_Expansion
5112 Make_Implicit_If_Statement
(N
,
5116 Build_Get_Access_Level
(Loc
,
5117 Make_Attribute_Reference
(Loc
,
5120 Duplicate_Subexpr
(Item
,
5122 Attribute_Name
=> Name_Tag
)),
5125 Make_Integer_Literal
(Loc
,
5126 Type_Access_Level
(P_Type
))),
5129 New_List
(Make_Raise_Statement
(Loc
,
5131 RTE
(RE_Tag_Error
), Loc
)))));
5135 Make_Attribute_Reference
(Loc
,
5136 Prefix
=> New_Occurrence_Of
(Standard_String
, Loc
),
5137 Attribute_Name
=> Name_Output
,
5138 Expressions
=> New_List
(
5139 Relocate_Node
(Duplicate_Subexpr
(Strm
)),
5140 Make_Function_Call
(Loc
,
5142 New_Occurrence_Of
(RTE
(RE_External_Tag
), Loc
),
5143 Parameter_Associations
=> New_List
(
5144 Make_Attribute_Reference
(Loc
,
5147 (Duplicate_Subexpr
(Item
, Name_Req
=> True)),
5148 Attribute_Name
=> Name_Tag
))))));
5151 Pname
:= Find_Prim_Op
(U_Type
, TSS_Stream_Output
);
5153 -- Tagged type case, use the primitive Output function
5155 elsif Is_Tagged_Type
(U_Type
) then
5156 Pname
:= Find_Prim_Op
(U_Type
, TSS_Stream_Output
);
5158 -- All other record type cases, including protected records.
5159 -- The latter only arise for expander generated code for
5160 -- handling shared passive partition access.
5164 (Is_Record_Type
(U_Type
) or else Is_Protected_Type
(U_Type
));
5166 -- Ada 2005 (AI-216): Program_Error is raised when executing
5167 -- the default implementation of the Output attribute of an
5168 -- unchecked union type if the type lacks default discriminant
5171 if Is_Unchecked_Union
(Base_Type
(U_Type
))
5172 and then No
(Discriminant_Constraint
(U_Type
))
5175 Make_Raise_Program_Error
(Loc
,
5176 Reason
=> PE_Unchecked_Union_Restriction
));
5181 Build_Record_Or_Elementary_Output_Procedure
5182 (Loc
, Base_Type
(U_Type
), Decl
, Pname
);
5183 Insert_Action
(N
, Decl
);
5187 -- If we fall through, Pname is the name of the procedure to call
5189 Rewrite_Stream_Proc_Call
(Pname
);
5196 -- For enumeration types with a standard representation, Pos is
5197 -- handled by the back end.
5199 -- For enumeration types, with a non-standard representation we generate
5200 -- a call to the _Rep_To_Pos function created when the type was frozen.
5201 -- The call has the form
5203 -- _rep_to_pos (expr, flag)
5205 -- The parameter flag is True if range checks are enabled, causing
5206 -- Program_Error to be raised if the expression has an invalid
5207 -- representation, and False if range checks are suppressed.
5209 -- For integer types, Pos is equivalent to a simple integer
5210 -- conversion and we rewrite it as such
5212 when Attribute_Pos
=> Pos
: declare
5213 Etyp
: Entity_Id
:= Base_Type
(Entity
(Pref
));
5216 -- Deal with zero/non-zero boolean values
5218 if Is_Boolean_Type
(Etyp
) then
5219 Adjust_Condition
(First
(Exprs
));
5220 Etyp
:= Standard_Boolean
;
5221 Set_Prefix
(N
, New_Occurrence_Of
(Standard_Boolean
, Loc
));
5224 -- Case of enumeration type
5226 if Is_Enumeration_Type
(Etyp
) then
5228 -- Non-standard enumeration type (generate call)
5230 if Present
(Enum_Pos_To_Rep
(Etyp
)) then
5231 Append_To
(Exprs
, Rep_To_Pos_Flag
(Etyp
, Loc
));
5234 Make_Function_Call
(Loc
,
5236 New_Occurrence_Of
(TSS
(Etyp
, TSS_Rep_To_Pos
), Loc
),
5237 Parameter_Associations
=> Exprs
)));
5239 Analyze_And_Resolve
(N
, Typ
);
5241 -- Standard enumeration type (do universal integer check)
5244 Apply_Universal_Integer_Attribute_Checks
(N
);
5247 -- Deal with integer types (replace by conversion)
5249 elsif Is_Integer_Type
(Etyp
) then
5250 Rewrite
(N
, Convert_To
(Typ
, First
(Exprs
)));
5251 Analyze_And_Resolve
(N
, Typ
);
5260 -- We compute this if a component clause was present, otherwise we leave
5261 -- the computation up to the back end, since we don't know what layout
5264 when Attribute_Position
=> Position_Attr
: declare
5265 CE
: constant Entity_Id
:= Entity
(Selector_Name
(Pref
));
5268 if Present
(Component_Clause
(CE
)) then
5270 -- In Ada 2005 (or later) if we have the non-default bit order,
5271 -- then we return the original value as given in the component
5272 -- clause (RM 2005 13.5.2(2/2)).
5274 if Ada_Version
>= Ada_2005
5275 and then Reverse_Bit_Order
(Scope
(CE
))
5278 Make_Integer_Literal
(Loc
,
5279 Intval
=> Expr_Value
(Position
(Component_Clause
(CE
)))));
5281 -- Otherwise (Ada 83 or 95, or default bit order specified in
5282 -- later Ada version), return the normalized value.
5286 Make_Integer_Literal
(Loc
,
5287 Intval
=> Component_Bit_Offset
(CE
) / System_Storage_Unit
));
5290 Analyze_And_Resolve
(N
, Typ
);
5292 -- If back end is doing things, just apply universal integer checks
5295 Apply_Universal_Integer_Attribute_Checks
(N
);
5303 -- 1. Deal with enumeration types with holes.
5304 -- 2. For floating-point, generate call to attribute function.
5305 -- 3. For other cases, deal with constraint checking.
5307 when Attribute_Pred
=> Pred
: declare
5308 Etyp
: constant Entity_Id
:= Base_Type
(Ptyp
);
5312 -- For enumeration types with non-standard representations, we
5313 -- expand typ'Pred (x) into
5315 -- Pos_To_Rep (Rep_To_Pos (x) - 1)
5317 -- If the representation is contiguous, we compute instead
5318 -- Lit1 + Rep_to_Pos (x -1), to catch invalid representations.
5319 -- The conversion function Enum_Pos_To_Rep is defined on the
5320 -- base type, not the subtype, so we have to use the base type
5321 -- explicitly for this and other enumeration attributes.
5323 if Is_Enumeration_Type
(Ptyp
)
5324 and then Present
(Enum_Pos_To_Rep
(Etyp
))
5326 if Has_Contiguous_Rep
(Etyp
) then
5328 Unchecked_Convert_To
(Ptyp
,
5331 Make_Integer_Literal
(Loc
,
5332 Enumeration_Rep
(First_Literal
(Ptyp
))),
5334 Make_Function_Call
(Loc
,
5337 (TSS
(Etyp
, TSS_Rep_To_Pos
), Loc
),
5339 Parameter_Associations
=>
5341 Unchecked_Convert_To
(Ptyp
,
5342 Make_Op_Subtract
(Loc
,
5344 Unchecked_Convert_To
(Standard_Integer
,
5345 Relocate_Node
(First
(Exprs
))),
5347 Make_Integer_Literal
(Loc
, 1))),
5348 Rep_To_Pos_Flag
(Ptyp
, Loc
))))));
5351 -- Add Boolean parameter True, to request program errror if
5352 -- we have a bad representation on our hands. If checks are
5353 -- suppressed, then add False instead
5355 Append_To
(Exprs
, Rep_To_Pos_Flag
(Ptyp
, Loc
));
5357 Make_Indexed_Component
(Loc
,
5360 (Enum_Pos_To_Rep
(Etyp
), Loc
),
5361 Expressions
=> New_List
(
5362 Make_Op_Subtract
(Loc
,
5364 Make_Function_Call
(Loc
,
5367 (TSS
(Etyp
, TSS_Rep_To_Pos
), Loc
),
5368 Parameter_Associations
=> Exprs
),
5369 Right_Opnd
=> Make_Integer_Literal
(Loc
, 1)))));
5372 Analyze_And_Resolve
(N
, Typ
);
5374 -- For floating-point, we transform 'Pred into a call to the Pred
5375 -- floating-point attribute function in Fat_xxx (xxx is root type).
5376 -- Note that this function takes care of the overflow case.
5378 elsif Is_Floating_Point_Type
(Ptyp
) then
5379 Expand_Fpt_Attribute_R
(N
);
5380 Analyze_And_Resolve
(N
, Typ
);
5382 -- For modular types, nothing to do (no overflow, since wraps)
5384 elsif Is_Modular_Integer_Type
(Ptyp
) then
5387 -- For other types, if argument is marked as needing a range check or
5388 -- overflow checking is enabled, we must generate a check.
5390 elsif not Overflow_Checks_Suppressed
(Ptyp
)
5391 or else Do_Range_Check
(First
(Exprs
))
5393 Set_Do_Range_Check
(First
(Exprs
), False);
5394 Expand_Pred_Succ_Attribute
(N
);
5402 -- Ada 2005 (AI-327): Dynamic ceiling priorities
5404 -- We rewrite X'Priority as the following run-time call:
5406 -- Get_Ceiling (X._Object)
5408 -- Note that although X'Priority is notionally an object, it is quite
5409 -- deliberately not defined as an aliased object in the RM. This means
5410 -- that it works fine to rewrite it as a call, without having to worry
5411 -- about complications that would other arise from X'Priority'Access,
5412 -- which is illegal, because of the lack of aliasing.
5414 when Attribute_Priority
=> Priority
: declare
5416 Conctyp
: Entity_Id
;
5417 New_Itype
: Entity_Id
;
5418 Object_Parm
: Node_Id
;
5420 RT_Subprg_Name
: Node_Id
;
5423 -- Look for the enclosing concurrent type
5425 Conctyp
:= Current_Scope
;
5426 while not Is_Concurrent_Type
(Conctyp
) loop
5427 Conctyp
:= Scope
(Conctyp
);
5430 pragma Assert
(Is_Protected_Type
(Conctyp
));
5432 -- Generate the actual of the call
5434 Subprg
:= Current_Scope
;
5435 while not Present
(Protected_Body_Subprogram
(Subprg
)) loop
5436 Subprg
:= Scope
(Subprg
);
5439 -- Use of 'Priority inside protected entries and barriers (in both
5440 -- cases the type of the first formal of their expanded subprogram
5443 if Etype
(First_Entity
(Protected_Body_Subprogram
(Subprg
))) =
5446 -- In the expansion of protected entries the type of the first
5447 -- formal of the Protected_Body_Subprogram is an Address. In order
5448 -- to reference the _object component we generate:
5450 -- type T is access p__ptTV;
5453 New_Itype
:= Create_Itype
(E_Access_Type
, N
);
5454 Set_Etype
(New_Itype
, New_Itype
);
5455 Set_Directly_Designated_Type
(New_Itype
,
5456 Corresponding_Record_Type
(Conctyp
));
5457 Freeze_Itype
(New_Itype
, N
);
5460 -- T!(O)._object'unchecked_access
5463 Make_Attribute_Reference
(Loc
,
5465 Make_Selected_Component
(Loc
,
5467 Unchecked_Convert_To
(New_Itype
,
5469 (First_Entity
(Protected_Body_Subprogram
(Subprg
)),
5471 Selector_Name
=> Make_Identifier
(Loc
, Name_uObject
)),
5472 Attribute_Name
=> Name_Unchecked_Access
);
5474 -- Use of 'Priority inside a protected subprogram
5478 Make_Attribute_Reference
(Loc
,
5480 Make_Selected_Component
(Loc
,
5483 (First_Entity
(Protected_Body_Subprogram
(Subprg
)),
5485 Selector_Name
=> Make_Identifier
(Loc
, Name_uObject
)),
5486 Attribute_Name
=> Name_Unchecked_Access
);
5489 -- Select the appropriate run-time subprogram
5491 if Number_Entries
(Conctyp
) = 0 then
5492 RT_Subprg_Name
:= New_Occurrence_Of
(RTE
(RE_Get_Ceiling
), Loc
);
5494 RT_Subprg_Name
:= New_Occurrence_Of
(RTE
(RO_PE_Get_Ceiling
), Loc
);
5498 Make_Function_Call
(Loc
,
5499 Name
=> RT_Subprg_Name
,
5500 Parameter_Associations
=> New_List
(Object_Parm
));
5504 -- Avoid the generation of extra checks on the pointer to the
5505 -- protected object.
5507 Analyze_And_Resolve
(N
, Typ
, Suppress
=> Access_Check
);
5514 when Attribute_Range_Length
=>
5516 -- The only special processing required is for the case where
5517 -- Range_Length is applied to an enumeration type with holes.
5518 -- In this case we transform
5524 -- X'Pos (X'Last) - X'Pos (X'First) + 1
5526 -- So that the result reflects the proper Pos values instead
5527 -- of the underlying representations.
5529 if Is_Enumeration_Type
(Ptyp
)
5530 and then Has_Non_Standard_Rep
(Ptyp
)
5535 Make_Op_Subtract
(Loc
,
5537 Make_Attribute_Reference
(Loc
,
5538 Attribute_Name
=> Name_Pos
,
5539 Prefix
=> New_Occurrence_Of
(Ptyp
, Loc
),
5540 Expressions
=> New_List
(
5541 Make_Attribute_Reference
(Loc
,
5542 Attribute_Name
=> Name_Last
,
5544 New_Occurrence_Of
(Ptyp
, Loc
)))),
5547 Make_Attribute_Reference
(Loc
,
5548 Attribute_Name
=> Name_Pos
,
5549 Prefix
=> New_Occurrence_Of
(Ptyp
, Loc
),
5550 Expressions
=> New_List
(
5551 Make_Attribute_Reference
(Loc
,
5552 Attribute_Name
=> Name_First
,
5554 New_Occurrence_Of
(Ptyp
, Loc
))))),
5556 Right_Opnd
=> Make_Integer_Literal
(Loc
, 1)));
5558 Analyze_And_Resolve
(N
, Typ
);
5560 -- For all other cases, the attribute is handled by the back end, but
5561 -- we need to deal with the case of the range check on a universal
5565 Apply_Universal_Integer_Attribute_Checks
(N
);
5572 when Attribute_Read
=> Read
: declare
5573 P_Type
: constant Entity_Id
:= Entity
(Pref
);
5574 B_Type
: constant Entity_Id
:= Base_Type
(P_Type
);
5575 U_Type
: constant Entity_Id
:= Underlying_Type
(P_Type
);
5585 -- If no underlying type, we have an error that will be diagnosed
5586 -- elsewhere, so here we just completely ignore the expansion.
5592 -- Stream operations can appear in user code even if the restriction
5593 -- No_Streams is active (for example, when instantiating a predefined
5594 -- container). In that case rewrite the attribute as a Raise to
5595 -- prevent any run-time use.
5597 if Restriction_Active
(No_Streams
) then
5599 Make_Raise_Program_Error
(Sloc
(N
),
5600 Reason
=> PE_Stream_Operation_Not_Allowed
));
5601 Set_Etype
(N
, B_Type
);
5605 -- The simple case, if there is a TSS for Read, just call it
5607 Pname
:= Find_Stream_Subprogram
(P_Type
, TSS_Stream_Read
);
5609 if Present
(Pname
) then
5613 -- If there is a Stream_Convert pragma, use it, we rewrite
5615 -- sourcetyp'Read (stream, Item)
5619 -- Item := sourcetyp (strmread (strmtyp'Input (Stream)));
5621 -- where strmread is the given Read function that converts an
5622 -- argument of type strmtyp to type sourcetyp or a type from which
5623 -- it is derived. The conversion to sourcetyp is required in the
5626 -- A special case arises if Item is a type conversion in which
5627 -- case, we have to expand to:
5629 -- Itemx := typex (strmread (strmtyp'Input (Stream)));
5631 -- where Itemx is the expression of the type conversion (i.e.
5632 -- the actual object), and typex is the type of Itemx.
5634 Prag
:= Get_Stream_Convert_Pragma
(P_Type
);
5636 if Present
(Prag
) then
5637 Arg2
:= Next
(First
(Pragma_Argument_Associations
(Prag
)));
5638 Rfunc
:= Entity
(Expression
(Arg2
));
5639 Lhs
:= Relocate_Node
(Next
(First
(Exprs
)));
5641 OK_Convert_To
(B_Type
,
5642 Make_Function_Call
(Loc
,
5643 Name
=> New_Occurrence_Of
(Rfunc
, Loc
),
5644 Parameter_Associations
=> New_List
(
5645 Make_Attribute_Reference
(Loc
,
5648 (Etype
(First_Formal
(Rfunc
)), Loc
),
5649 Attribute_Name
=> Name_Input
,
5650 Expressions
=> New_List
(
5651 Relocate_Node
(First
(Exprs
)))))));
5653 if Nkind
(Lhs
) = N_Type_Conversion
then
5654 Lhs
:= Expression
(Lhs
);
5655 Rhs
:= Convert_To
(Etype
(Lhs
), Rhs
);
5659 Make_Assignment_Statement
(Loc
,
5661 Expression
=> Rhs
));
5662 Set_Assignment_OK
(Lhs
);
5666 -- For elementary types, we call the I_xxx routine using the first
5667 -- parameter and then assign the result into the second parameter.
5668 -- We set Assignment_OK to deal with the conversion case.
5670 elsif Is_Elementary_Type
(U_Type
) then
5676 Lhs
:= Relocate_Node
(Next
(First
(Exprs
)));
5677 Rhs
:= Build_Elementary_Input_Call
(N
);
5679 if Nkind
(Lhs
) = N_Type_Conversion
then
5680 Lhs
:= Expression
(Lhs
);
5681 Rhs
:= Convert_To
(Etype
(Lhs
), Rhs
);
5684 Set_Assignment_OK
(Lhs
);
5687 Make_Assignment_Statement
(Loc
,
5689 Expression
=> Rhs
));
5697 elsif Is_Array_Type
(U_Type
) then
5698 Build_Array_Read_Procedure
(N
, U_Type
, Decl
, Pname
);
5699 Compile_Stream_Body_In_Scope
(N
, Decl
, U_Type
, Check
=> False);
5701 -- Tagged type case, use the primitive Read function. Note that
5702 -- this will dispatch in the class-wide case which is what we want
5704 elsif Is_Tagged_Type
(U_Type
) then
5705 Pname
:= Find_Prim_Op
(U_Type
, TSS_Stream_Read
);
5707 -- All other record type cases, including protected records. The
5708 -- latter only arise for expander generated code for handling
5709 -- shared passive partition access.
5713 (Is_Record_Type
(U_Type
) or else Is_Protected_Type
(U_Type
));
5715 -- Ada 2005 (AI-216): Program_Error is raised when executing
5716 -- the default implementation of the Read attribute of an
5717 -- Unchecked_Union type. We replace the attribute with a
5718 -- raise statement (rather than inserting it before) to handle
5719 -- properly the case of an unchecked union that is a record
5722 if Is_Unchecked_Union
(Base_Type
(U_Type
)) then
5724 Make_Raise_Program_Error
(Loc
,
5725 Reason
=> PE_Unchecked_Union_Restriction
));
5726 Set_Etype
(N
, B_Type
);
5730 if Has_Discriminants
(U_Type
)
5732 (Discriminant_Default_Value
(First_Discriminant
(U_Type
)))
5734 Build_Mutable_Record_Read_Procedure
5735 (Loc
, Full_Base
(U_Type
), Decl
, Pname
);
5737 Build_Record_Read_Procedure
5738 (Loc
, Full_Base
(U_Type
), Decl
, Pname
);
5741 -- Suppress checks, uninitialized or otherwise invalid
5742 -- data does not cause constraint errors to be raised for
5743 -- a complete record read.
5745 Insert_Action
(N
, Decl
, All_Checks
);
5749 Rewrite_Stream_Proc_Call
(Pname
);
5756 -- Ref is identical to To_Address, see To_Address for processing
5762 -- Transforms 'Remainder into a call to the floating-point attribute
5763 -- function Remainder in Fat_xxx (where xxx is the root type)
5765 when Attribute_Remainder
=>
5766 Expand_Fpt_Attribute_RR
(N
);
5772 -- Transform 'Result into reference to _Result formal. At the point
5773 -- where a legal 'Result attribute is expanded, we know that we are in
5774 -- the context of a _Postcondition function with a _Result parameter.
5776 when Attribute_Result
=>
5777 Rewrite
(N
, Make_Identifier
(Loc
, Chars
=> Name_uResult
));
5778 Analyze_And_Resolve
(N
, Typ
);
5784 -- The handling of the Round attribute is quite delicate. The processing
5785 -- in Sem_Attr introduced a conversion to universal real, reflecting the
5786 -- semantics of Round, but we do not want anything to do with universal
5787 -- real at runtime, since this corresponds to using floating-point
5790 -- What we have now is that the Etype of the Round attribute correctly
5791 -- indicates the final result type. The operand of the Round is the
5792 -- conversion to universal real, described above, and the operand of
5793 -- this conversion is the actual operand of Round, which may be the
5794 -- special case of a fixed point multiplication or division (Etype =
5797 -- The exapander will expand first the operand of the conversion, then
5798 -- the conversion, and finally the round attribute itself, since we
5799 -- always work inside out. But we cannot simply process naively in this
5800 -- order. In the semantic world where universal fixed and real really
5801 -- exist and have infinite precision, there is no problem, but in the
5802 -- implementation world, where universal real is a floating-point type,
5803 -- we would get the wrong result.
5805 -- So the approach is as follows. First, when expanding a multiply or
5806 -- divide whose type is universal fixed, we do nothing at all, instead
5807 -- deferring the operation till later.
5809 -- The actual processing is done in Expand_N_Type_Conversion which
5810 -- handles the special case of Round by looking at its parent to see if
5811 -- it is a Round attribute, and if it is, handling the conversion (or
5812 -- its fixed multiply/divide child) in an appropriate manner.
5814 -- This means that by the time we get to expanding the Round attribute
5815 -- itself, the Round is nothing more than a type conversion (and will
5816 -- often be a null type conversion), so we just replace it with the
5817 -- appropriate conversion operation.
5819 when Attribute_Round
=>
5821 Convert_To
(Etype
(N
), Relocate_Node
(First
(Exprs
))));
5822 Analyze_And_Resolve
(N
);
5828 -- Transforms 'Rounding into a call to the floating-point attribute
5829 -- function Rounding in Fat_xxx (where xxx is the root type)
5830 -- Expansion is avoided for cases the back end can handle directly.
5832 when Attribute_Rounding
=>
5833 if not Is_Inline_Floating_Point_Attribute
(N
) then
5834 Expand_Fpt_Attribute_R
(N
);
5841 -- Transforms 'Scaling into a call to the floating-point attribute
5842 -- function Scaling in Fat_xxx (where xxx is the root type)
5844 when Attribute_Scaling
=>
5845 Expand_Fpt_Attribute_RI
(N
);
5847 -------------------------
5848 -- Simple_Storage_Pool --
5849 -------------------------
5851 when Attribute_Simple_Storage_Pool
=>
5853 Make_Type_Conversion
(Loc
,
5854 Subtype_Mark
=> New_Occurrence_Of
(Etype
(N
), Loc
),
5855 Expression
=> New_Occurrence_Of
(Entity
(N
), Loc
)));
5856 Analyze_And_Resolve
(N
, Typ
);
5862 when Attribute_Object_Size
5864 | Attribute_Value_Size
5865 | Attribute_VADS_Size
5872 -- Processing for VADS_Size case. Note that this processing
5873 -- removes all traces of VADS_Size from the tree, and completes
5874 -- all required processing for VADS_Size by translating the
5875 -- attribute reference to an appropriate Size or Object_Size
5878 if Id
= Attribute_VADS_Size
5879 or else (Use_VADS_Size
and then Id
= Attribute_Size
)
5881 -- If the size is specified, then we simply use the specified
5882 -- size. This applies to both types and objects. The size of an
5883 -- object can be specified in the following ways:
5885 -- An explicit size object is given for an object
5886 -- A component size is specified for an indexed component
5887 -- A component clause is specified for a selected component
5888 -- The object is a component of a packed composite object
5890 -- If the size is specified, then VADS_Size of an object
5892 if (Is_Entity_Name
(Pref
)
5893 and then Present
(Size_Clause
(Entity
(Pref
))))
5895 (Nkind
(Pref
) = N_Component_Clause
5896 and then (Present
(Component_Clause
5897 (Entity
(Selector_Name
(Pref
))))
5898 or else Is_Packed
(Etype
(Prefix
(Pref
)))))
5900 (Nkind
(Pref
) = N_Indexed_Component
5901 and then (Component_Size
(Etype
(Prefix
(Pref
))) /= 0
5902 or else Is_Packed
(Etype
(Prefix
(Pref
)))))
5904 Set_Attribute_Name
(N
, Name_Size
);
5906 -- Otherwise if we have an object rather than a type, then
5907 -- the VADS_Size attribute applies to the type of the object,
5908 -- rather than the object itself. This is one of the respects
5909 -- in which VADS_Size differs from Size.
5912 if (not Is_Entity_Name
(Pref
)
5913 or else not Is_Type
(Entity
(Pref
)))
5914 and then (Is_Scalar_Type
(Ptyp
)
5915 or else Is_Constrained
(Ptyp
))
5917 Rewrite
(Pref
, New_Occurrence_Of
(Ptyp
, Loc
));
5920 -- For a scalar type for which no size was explicitly given,
5921 -- VADS_Size means Object_Size. This is the other respect in
5922 -- which VADS_Size differs from Size.
5924 if Is_Scalar_Type
(Ptyp
)
5925 and then No
(Size_Clause
(Ptyp
))
5927 Set_Attribute_Name
(N
, Name_Object_Size
);
5929 -- In all other cases, Size and VADS_Size are the sane
5932 Set_Attribute_Name
(N
, Name_Size
);
5937 -- If the prefix is X'Class, transform it into a direct reference
5938 -- to the class-wide type, because the back end must not see a
5939 -- 'Class reference.
5941 if Is_Entity_Name
(Pref
)
5942 and then Is_Class_Wide_Type
(Entity
(Pref
))
5944 Rewrite
(Prefix
(N
), New_Occurrence_Of
(Entity
(Pref
), Loc
));
5947 -- For X'Size applied to an object of a class-wide type, transform
5948 -- X'Size into a call to the primitive operation _Size applied to
5951 elsif Is_Class_Wide_Type
(Ptyp
) then
5953 -- No need to do anything else compiling under restriction
5954 -- No_Dispatching_Calls. During the semantic analysis we
5955 -- already noted this restriction violation.
5957 if Restriction_Active
(No_Dispatching_Calls
) then
5962 Make_Function_Call
(Loc
,
5964 New_Occurrence_Of
(Find_Prim_Op
(Ptyp
, Name_uSize
), Loc
),
5965 Parameter_Associations
=> New_List
(Pref
));
5967 if Typ
/= Standard_Long_Long_Integer
then
5969 -- The context is a specific integer type with which the
5970 -- original attribute was compatible. The function has a
5971 -- specific type as well, so to preserve the compatibility
5972 -- we must convert explicitly.
5974 New_Node
:= Convert_To
(Typ
, New_Node
);
5977 Rewrite
(N
, New_Node
);
5978 Analyze_And_Resolve
(N
, Typ
);
5981 -- Case of known RM_Size of a type
5983 elsif (Id
= Attribute_Size
or else Id
= Attribute_Value_Size
)
5984 and then Is_Entity_Name
(Pref
)
5985 and then Is_Type
(Entity
(Pref
))
5986 and then Known_Static_RM_Size
(Entity
(Pref
))
5988 Siz
:= RM_Size
(Entity
(Pref
));
5990 -- Case of known Esize of a type
5992 elsif Id
= Attribute_Object_Size
5993 and then Is_Entity_Name
(Pref
)
5994 and then Is_Type
(Entity
(Pref
))
5995 and then Known_Static_Esize
(Entity
(Pref
))
5997 Siz
:= Esize
(Entity
(Pref
));
5999 -- Case of known size of object
6001 elsif Id
= Attribute_Size
6002 and then Is_Entity_Name
(Pref
)
6003 and then Is_Object
(Entity
(Pref
))
6004 and then Known_Esize
(Entity
(Pref
))
6005 and then Known_Static_Esize
(Entity
(Pref
))
6007 Siz
:= Esize
(Entity
(Pref
));
6009 -- For an array component, we can do Size in the front end if the
6010 -- component_size of the array is set.
6012 elsif Nkind
(Pref
) = N_Indexed_Component
then
6013 Siz
:= Component_Size
(Etype
(Prefix
(Pref
)));
6015 -- For a record component, we can do Size in the front end if
6016 -- there is a component clause, or if the record is packed and the
6017 -- component's size is known at compile time.
6019 elsif Nkind
(Pref
) = N_Selected_Component
then
6021 Rec
: constant Entity_Id
:= Etype
(Prefix
(Pref
));
6022 Comp
: constant Entity_Id
:= Entity
(Selector_Name
(Pref
));
6025 if Present
(Component_Clause
(Comp
)) then
6026 Siz
:= Esize
(Comp
);
6028 elsif Is_Packed
(Rec
) then
6029 Siz
:= RM_Size
(Ptyp
);
6032 Apply_Universal_Integer_Attribute_Checks
(N
);
6037 -- All other cases are handled by the back end
6040 Apply_Universal_Integer_Attribute_Checks
(N
);
6042 -- If Size is applied to a formal parameter that is of a packed
6043 -- array subtype, then apply Size to the actual subtype.
6045 if Is_Entity_Name
(Pref
)
6046 and then Is_Formal
(Entity
(Pref
))
6047 and then Is_Array_Type
(Ptyp
)
6048 and then Is_Packed
(Ptyp
)
6051 Make_Attribute_Reference
(Loc
,
6053 New_Occurrence_Of
(Get_Actual_Subtype
(Pref
), Loc
),
6054 Attribute_Name
=> Name_Size
));
6055 Analyze_And_Resolve
(N
, Typ
);
6058 -- If Size applies to a dereference of an access to
6059 -- unconstrained packed array, the back end needs to see its
6060 -- unconstrained nominal type, but also a hint to the actual
6061 -- constrained type.
6063 if Nkind
(Pref
) = N_Explicit_Dereference
6064 and then Is_Array_Type
(Ptyp
)
6065 and then not Is_Constrained
(Ptyp
)
6066 and then Is_Packed
(Ptyp
)
6068 Set_Actual_Designated_Subtype
(Pref
,
6069 Get_Actual_Subtype
(Pref
));
6075 -- Common processing for record and array component case
6077 if Siz
/= No_Uint
and then Siz
/= 0 then
6079 CS
: constant Boolean := Comes_From_Source
(N
);
6082 Rewrite
(N
, Make_Integer_Literal
(Loc
, Siz
));
6084 -- This integer literal is not a static expression. We do
6085 -- not call Analyze_And_Resolve here, because this would
6086 -- activate the circuit for deciding that a static value
6087 -- was out of range, and we don't want that.
6089 -- So just manually set the type, mark the expression as
6090 -- non-static, and then ensure that the result is checked
6091 -- properly if the attribute comes from source (if it was
6092 -- internally generated, we never need a constraint check).
6095 Set_Is_Static_Expression
(N
, False);
6098 Apply_Constraint_Check
(N
, Typ
);
6108 when Attribute_Storage_Pool
=>
6110 Make_Type_Conversion
(Loc
,
6111 Subtype_Mark
=> New_Occurrence_Of
(Etype
(N
), Loc
),
6112 Expression
=> New_Occurrence_Of
(Entity
(N
), Loc
)));
6113 Analyze_And_Resolve
(N
, Typ
);
6119 when Attribute_Storage_Size
=> Storage_Size
: declare
6120 Alloc_Op
: Entity_Id
:= Empty
;
6124 -- Access type case, always go to the root type
6126 -- The case of access types results in a value of zero for the case
6127 -- where no storage size attribute clause has been given. If a
6128 -- storage size has been given, then the attribute is converted
6129 -- to a reference to the variable used to hold this value.
6131 if Is_Access_Type
(Ptyp
) then
6132 if Present
(Storage_Size_Variable
(Root_Type
(Ptyp
))) then
6134 Make_Attribute_Reference
(Loc
,
6135 Prefix
=> New_Occurrence_Of
(Typ
, Loc
),
6136 Attribute_Name
=> Name_Max
,
6137 Expressions
=> New_List
(
6138 Make_Integer_Literal
(Loc
, 0),
6141 (Storage_Size_Variable
(Root_Type
(Ptyp
)), Loc
)))));
6143 elsif Present
(Associated_Storage_Pool
(Root_Type
(Ptyp
))) then
6145 -- If the access type is associated with a simple storage pool
6146 -- object, then attempt to locate the optional Storage_Size
6147 -- function of the simple storage pool type. If not found,
6148 -- then the result will default to zero.
6150 if Present
(Get_Rep_Pragma
(Root_Type
(Ptyp
),
6151 Name_Simple_Storage_Pool_Type
))
6154 Pool_Type
: constant Entity_Id
:=
6155 Base_Type
(Etype
(Entity
(N
)));
6158 Alloc_Op
:= Get_Name_Entity_Id
(Name_Storage_Size
);
6159 while Present
(Alloc_Op
) loop
6160 if Scope
(Alloc_Op
) = Scope
(Pool_Type
)
6161 and then Present
(First_Formal
(Alloc_Op
))
6162 and then Etype
(First_Formal
(Alloc_Op
)) = Pool_Type
6167 Alloc_Op
:= Homonym
(Alloc_Op
);
6171 -- In the normal Storage_Pool case, retrieve the primitive
6172 -- function associated with the pool type.
6177 (Etype
(Associated_Storage_Pool
(Root_Type
(Ptyp
))),
6178 Attribute_Name
(N
));
6181 -- If Storage_Size wasn't found (can only occur in the simple
6182 -- storage pool case), then simply use zero for the result.
6184 if not Present
(Alloc_Op
) then
6185 Rewrite
(N
, Make_Integer_Literal
(Loc
, 0));
6187 -- Otherwise, rewrite the allocator as a call to pool type's
6188 -- Storage_Size function.
6193 Make_Function_Call
(Loc
,
6195 New_Occurrence_Of
(Alloc_Op
, Loc
),
6197 Parameter_Associations
=> New_List
(
6199 (Associated_Storage_Pool
6200 (Root_Type
(Ptyp
)), Loc
)))));
6204 Rewrite
(N
, Make_Integer_Literal
(Loc
, 0));
6207 Analyze_And_Resolve
(N
, Typ
);
6209 -- For tasks, we retrieve the size directly from the TCB. The
6210 -- size may depend on a discriminant of the type, and therefore
6211 -- can be a per-object expression, so type-level information is
6212 -- not sufficient in general. There are four cases to consider:
6214 -- a) If the attribute appears within a task body, the designated
6215 -- TCB is obtained by a call to Self.
6217 -- b) If the prefix of the attribute is the name of a task object,
6218 -- the designated TCB is the one stored in the corresponding record.
6220 -- c) If the prefix is a task type, the size is obtained from the
6221 -- size variable created for each task type
6223 -- d) If no Storage_Size was specified for the type, there is no
6224 -- size variable, and the value is a system-specific default.
6227 if In_Open_Scopes
(Ptyp
) then
6229 -- Storage_Size (Self)
6233 Make_Function_Call
(Loc
,
6235 New_Occurrence_Of
(RTE
(RE_Storage_Size
), Loc
),
6236 Parameter_Associations
=>
6238 Make_Function_Call
(Loc
,
6240 New_Occurrence_Of
(RTE
(RE_Self
), Loc
))))));
6242 elsif not Is_Entity_Name
(Pref
)
6243 or else not Is_Type
(Entity
(Pref
))
6245 -- Storage_Size (Rec (Obj).Size)
6249 Make_Function_Call
(Loc
,
6251 New_Occurrence_Of
(RTE
(RE_Storage_Size
), Loc
),
6252 Parameter_Associations
=>
6254 Make_Selected_Component
(Loc
,
6256 Unchecked_Convert_To
(
6257 Corresponding_Record_Type
(Ptyp
),
6258 New_Copy_Tree
(Pref
)),
6260 Make_Identifier
(Loc
, Name_uTask_Id
))))));
6262 elsif Present
(Storage_Size_Variable
(Ptyp
)) then
6264 -- Static Storage_Size pragma given for type: retrieve value
6265 -- from its allocated storage variable.
6269 Make_Function_Call
(Loc
,
6270 Name
=> New_Occurrence_Of
(
6271 RTE
(RE_Adjust_Storage_Size
), Loc
),
6272 Parameter_Associations
=>
6275 Storage_Size_Variable
(Ptyp
), Loc
)))));
6277 -- Get system default
6281 Make_Function_Call
(Loc
,
6284 RTE
(RE_Default_Stack_Size
), Loc
))));
6287 Analyze_And_Resolve
(N
, Typ
);
6295 when Attribute_Stream_Size
=>
6297 Make_Integer_Literal
(Loc
, Intval
=> Get_Stream_Size
(Ptyp
)));
6298 Analyze_And_Resolve
(N
, Typ
);
6304 -- 1. Deal with enumeration types with holes.
6305 -- 2. For floating-point, generate call to attribute function.
6306 -- 3. For other cases, deal with constraint checking.
6308 when Attribute_Succ
=> Succ
: declare
6309 Etyp
: constant Entity_Id
:= Base_Type
(Ptyp
);
6312 -- For enumeration types with non-standard representations, we
6313 -- expand typ'Succ (x) into
6315 -- Pos_To_Rep (Rep_To_Pos (x) + 1)
6317 -- If the representation is contiguous, we compute instead
6318 -- Lit1 + Rep_to_Pos (x+1), to catch invalid representations.
6320 if Is_Enumeration_Type
(Ptyp
)
6321 and then Present
(Enum_Pos_To_Rep
(Etyp
))
6323 if Has_Contiguous_Rep
(Etyp
) then
6325 Unchecked_Convert_To
(Ptyp
,
6328 Make_Integer_Literal
(Loc
,
6329 Enumeration_Rep
(First_Literal
(Ptyp
))),
6331 Make_Function_Call
(Loc
,
6334 (TSS
(Etyp
, TSS_Rep_To_Pos
), Loc
),
6336 Parameter_Associations
=>
6338 Unchecked_Convert_To
(Ptyp
,
6341 Unchecked_Convert_To
(Standard_Integer
,
6342 Relocate_Node
(First
(Exprs
))),
6344 Make_Integer_Literal
(Loc
, 1))),
6345 Rep_To_Pos_Flag
(Ptyp
, Loc
))))));
6347 -- Add Boolean parameter True, to request program errror if
6348 -- we have a bad representation on our hands. Add False if
6349 -- checks are suppressed.
6351 Append_To
(Exprs
, Rep_To_Pos_Flag
(Ptyp
, Loc
));
6353 Make_Indexed_Component
(Loc
,
6356 (Enum_Pos_To_Rep
(Etyp
), Loc
),
6357 Expressions
=> New_List
(
6360 Make_Function_Call
(Loc
,
6363 (TSS
(Etyp
, TSS_Rep_To_Pos
), Loc
),
6364 Parameter_Associations
=> Exprs
),
6365 Right_Opnd
=> Make_Integer_Literal
(Loc
, 1)))));
6368 Analyze_And_Resolve
(N
, Typ
);
6370 -- For floating-point, we transform 'Succ into a call to the Succ
6371 -- floating-point attribute function in Fat_xxx (xxx is root type)
6373 elsif Is_Floating_Point_Type
(Ptyp
) then
6374 Expand_Fpt_Attribute_R
(N
);
6375 Analyze_And_Resolve
(N
, Typ
);
6377 -- For modular types, nothing to do (no overflow, since wraps)
6379 elsif Is_Modular_Integer_Type
(Ptyp
) then
6382 -- For other types, if argument is marked as needing a range check or
6383 -- overflow checking is enabled, we must generate a check.
6385 elsif not Overflow_Checks_Suppressed
(Ptyp
)
6386 or else Do_Range_Check
(First
(Exprs
))
6388 Set_Do_Range_Check
(First
(Exprs
), False);
6389 Expand_Pred_Succ_Attribute
(N
);
6397 -- Transforms X'Tag into a direct reference to the tag of X
6399 when Attribute_Tag
=> Tag
: declare
6401 Prefix_Is_Type
: Boolean;
6404 if Is_Entity_Name
(Pref
) and then Is_Type
(Entity
(Pref
)) then
6405 Ttyp
:= Entity
(Pref
);
6406 Prefix_Is_Type
:= True;
6409 Prefix_Is_Type
:= False;
6412 if Is_Class_Wide_Type
(Ttyp
) then
6413 Ttyp
:= Root_Type
(Ttyp
);
6416 Ttyp
:= Underlying_Type
(Ttyp
);
6418 -- Ada 2005: The type may be a synchronized tagged type, in which
6419 -- case the tag information is stored in the corresponding record.
6421 if Is_Concurrent_Type
(Ttyp
) then
6422 Ttyp
:= Corresponding_Record_Type
(Ttyp
);
6425 if Prefix_Is_Type
then
6427 -- For VMs we leave the type attribute unexpanded because
6428 -- there's not a dispatching table to reference.
6430 if Tagged_Type_Expansion
then
6432 Unchecked_Convert_To
(RTE
(RE_Tag
),
6434 (Node
(First_Elmt
(Access_Disp_Table
(Ttyp
))), Loc
)));
6435 Analyze_And_Resolve
(N
, RTE
(RE_Tag
));
6438 -- Ada 2005 (AI-251): The use of 'Tag in the sources always
6439 -- references the primary tag of the actual object. If 'Tag is
6440 -- applied to class-wide interface objects we generate code that
6441 -- displaces "this" to reference the base of the object.
6443 elsif Comes_From_Source
(N
)
6444 and then Is_Class_Wide_Type
(Etype
(Prefix
(N
)))
6445 and then Is_Interface
(Underlying_Type
(Etype
(Prefix
(N
))))
6448 -- (To_Tag_Ptr (Prefix'Address)).all
6450 -- Note that Prefix'Address is recursively expanded into a call
6451 -- to Base_Address (Obj.Tag)
6453 -- Not needed for VM targets, since all handled by the VM
6455 if Tagged_Type_Expansion
then
6457 Make_Explicit_Dereference
(Loc
,
6458 Unchecked_Convert_To
(RTE
(RE_Tag_Ptr
),
6459 Make_Attribute_Reference
(Loc
,
6460 Prefix
=> Relocate_Node
(Pref
),
6461 Attribute_Name
=> Name_Address
))));
6462 Analyze_And_Resolve
(N
, RTE
(RE_Tag
));
6467 Make_Selected_Component
(Loc
,
6468 Prefix
=> Relocate_Node
(Pref
),
6470 New_Occurrence_Of
(First_Tag_Component
(Ttyp
), Loc
)));
6471 Analyze_And_Resolve
(N
, RTE
(RE_Tag
));
6479 -- Transforms 'Terminated attribute into a call to Terminated function
6481 when Attribute_Terminated
=> Terminated
: begin
6483 -- The prefix of Terminated is of a task interface class-wide type.
6485 -- terminated (Task_Id (_disp_get_task_id (Pref)));
6487 if Ada_Version
>= Ada_2005
6488 and then Ekind
(Ptyp
) = E_Class_Wide_Type
6489 and then Is_Interface
(Ptyp
)
6490 and then Is_Task_Interface
(Ptyp
)
6493 Make_Function_Call
(Loc
,
6495 New_Occurrence_Of
(RTE
(RE_Terminated
), Loc
),
6496 Parameter_Associations
=> New_List
(
6497 Make_Unchecked_Type_Conversion
(Loc
,
6499 New_Occurrence_Of
(RTE
(RO_ST_Task_Id
), Loc
),
6500 Expression
=> Build_Disp_Get_Task_Id_Call
(Pref
)))));
6502 elsif Restricted_Profile
then
6504 Build_Call_With_Task
(Pref
, RTE
(RE_Restricted_Terminated
)));
6508 Build_Call_With_Task
(Pref
, RTE
(RE_Terminated
)));
6511 Analyze_And_Resolve
(N
, Standard_Boolean
);
6518 -- Transforms System'To_Address (X) and System.Address'Ref (X) into
6519 -- unchecked conversion from (integral) type of X to type address.
6522 | Attribute_To_Address
6525 Unchecked_Convert_To
(RTE
(RE_Address
),
6526 Relocate_Node
(First
(Exprs
))));
6527 Analyze_And_Resolve
(N
, RTE
(RE_Address
));
6533 when Attribute_To_Any
=> To_Any
: declare
6534 P_Type
: constant Entity_Id
:= Etype
(Pref
);
6535 Decls
: constant List_Id
:= New_List
;
6541 Relocate_Node
(First
(Exprs
))), Decls
));
6542 Insert_Actions
(N
, Decls
);
6543 Analyze_And_Resolve
(N
, RTE
(RE_Any
));
6550 -- Transforms 'Truncation into a call to the floating-point attribute
6551 -- function Truncation in Fat_xxx (where xxx is the root type).
6552 -- Expansion is avoided for cases the back end can handle directly.
6554 when Attribute_Truncation
=>
6555 if not Is_Inline_Floating_Point_Attribute
(N
) then
6556 Expand_Fpt_Attribute_R
(N
);
6563 when Attribute_TypeCode
=> TypeCode
: declare
6564 P_Type
: constant Entity_Id
:= Etype
(Pref
);
6565 Decls
: constant List_Id
:= New_List
;
6567 Rewrite
(N
, Build_TypeCode_Call
(Loc
, P_Type
, Decls
));
6568 Insert_Actions
(N
, Decls
);
6569 Analyze_And_Resolve
(N
, RTE
(RE_TypeCode
));
6572 -----------------------
6573 -- Unbiased_Rounding --
6574 -----------------------
6576 -- Transforms 'Unbiased_Rounding into a call to the floating-point
6577 -- attribute function Unbiased_Rounding in Fat_xxx (where xxx is the
6578 -- root type). Expansion is avoided for cases the back end can handle
6581 when Attribute_Unbiased_Rounding
=>
6582 if not Is_Inline_Floating_Point_Attribute
(N
) then
6583 Expand_Fpt_Attribute_R
(N
);
6590 when Attribute_Update
=>
6591 Expand_Update_Attribute
(N
);
6597 -- The processing for VADS_Size is shared with Size
6603 -- For enumeration types with a standard representation, and for all
6604 -- other types, Val is handled by the back end. For enumeration types
6605 -- with a non-standard representation we use the _Pos_To_Rep array that
6606 -- was created when the type was frozen.
6608 when Attribute_Val
=> Val
: declare
6609 Etyp
: constant Entity_Id
:= Base_Type
(Entity
(Pref
));
6612 if Is_Enumeration_Type
(Etyp
)
6613 and then Present
(Enum_Pos_To_Rep
(Etyp
))
6615 if Has_Contiguous_Rep
(Etyp
) then
6617 Rep_Node
: constant Node_Id
:=
6618 Unchecked_Convert_To
(Etyp
,
6621 Make_Integer_Literal
(Loc
,
6622 Enumeration_Rep
(First_Literal
(Etyp
))),
6624 (Convert_To
(Standard_Integer
,
6625 Relocate_Node
(First
(Exprs
))))));
6629 Unchecked_Convert_To
(Etyp
,
6632 Make_Integer_Literal
(Loc
,
6633 Enumeration_Rep
(First_Literal
(Etyp
))),
6635 Make_Function_Call
(Loc
,
6638 (TSS
(Etyp
, TSS_Rep_To_Pos
), Loc
),
6639 Parameter_Associations
=> New_List
(
6641 Rep_To_Pos_Flag
(Etyp
, Loc
))))));
6646 Make_Indexed_Component
(Loc
,
6647 Prefix
=> New_Occurrence_Of
(Enum_Pos_To_Rep
(Etyp
), Loc
),
6648 Expressions
=> New_List
(
6649 Convert_To
(Standard_Integer
,
6650 Relocate_Node
(First
(Exprs
))))));
6653 Analyze_And_Resolve
(N
, Typ
);
6655 -- If the argument is marked as requiring a range check then generate
6658 elsif Do_Range_Check
(First
(Exprs
)) then
6659 Generate_Range_Check
(First
(Exprs
), Etyp
, CE_Range_Check_Failed
);
6667 -- The code for valid is dependent on the particular types involved.
6668 -- See separate sections below for the generated code in each case.
6670 when Attribute_Valid
=> Valid
: declare
6671 Btyp
: Entity_Id
:= Base_Type
(Ptyp
);
6673 Save_Validity_Checks_On
: constant Boolean := Validity_Checks_On
;
6674 -- Save the validity checking mode. We always turn off validity
6675 -- checking during process of 'Valid since this is one place
6676 -- where we do not want the implicit validity checks to interfere
6677 -- with the explicit validity check that the programmer is doing.
6679 function Make_Range_Test
return Node_Id
;
6680 -- Build the code for a range test of the form
6681 -- Btyp!(Pref) in Btyp!(Ptyp'First) .. Btyp!(Ptyp'Last)
6683 ---------------------
6684 -- Make_Range_Test --
6685 ---------------------
6687 function Make_Range_Test
return Node_Id
is
6691 -- The prefix of attribute 'Valid should always denote an object
6692 -- reference. The reference is either coming directly from source
6693 -- or is produced by validity check expansion. The object may be
6694 -- wrapped in a conversion in which case the call to Unqual_Conv
6697 -- If the prefix denotes a variable which captures the value of
6698 -- an object for validation purposes, use the variable in the
6699 -- range test. This ensures that no extra copies or extra reads
6700 -- are produced as part of the test. Generate:
6702 -- Temp : ... := Object;
6703 -- if not Temp in ... then
6705 if Is_Validation_Variable_Reference
(Pref
) then
6706 Temp
:= New_Occurrence_Of
(Entity
(Unqual_Conv
(Pref
)), Loc
);
6708 -- Otherwise the prefix is either a source object or a constant
6709 -- produced by validity check expansion. Generate:
6711 -- Temp : constant ... := Pref;
6712 -- if not Temp in ... then
6715 Temp
:= Duplicate_Subexpr
(Pref
);
6720 Left_Opnd
=> Unchecked_Convert_To
(Btyp
, Temp
),
6724 Unchecked_Convert_To
(Btyp
,
6725 Make_Attribute_Reference
(Loc
,
6726 Prefix
=> New_Occurrence_Of
(Ptyp
, Loc
),
6727 Attribute_Name
=> Name_First
)),
6729 Unchecked_Convert_To
(Btyp
,
6730 Make_Attribute_Reference
(Loc
,
6731 Prefix
=> New_Occurrence_Of
(Ptyp
, Loc
),
6732 Attribute_Name
=> Name_Last
))));
6733 end Make_Range_Test
;
6739 -- Start of processing for Attribute_Valid
6742 -- Do not expand sourced code 'Valid reference in CodePeer mode,
6743 -- will be handled by the back-end directly.
6745 if CodePeer_Mode
and then Comes_From_Source
(N
) then
6749 -- Turn off validity checks. We do not want any implicit validity
6750 -- checks to intefere with the explicit check from the attribute
6752 Validity_Checks_On
:= False;
6754 -- Retrieve the base type. Handle the case where the base type is a
6755 -- private enumeration type.
6757 if Is_Private_Type
(Btyp
) and then Present
(Full_View
(Btyp
)) then
6758 Btyp
:= Full_View
(Btyp
);
6761 -- Floating-point case. This case is handled by the Valid attribute
6762 -- code in the floating-point attribute run-time library.
6764 if Is_Floating_Point_Type
(Ptyp
) then
6765 Float_Valid
: declare
6769 function Get_Fat_Entity
(Nam
: Name_Id
) return Entity_Id
;
6770 -- Return entity for Pkg.Nam
6772 --------------------
6773 -- Get_Fat_Entity --
6774 --------------------
6776 function Get_Fat_Entity
(Nam
: Name_Id
) return Entity_Id
is
6777 Exp_Name
: constant Node_Id
:=
6778 Make_Selected_Component
(Loc
,
6779 Prefix
=> New_Occurrence_Of
(RTE
(Pkg
), Loc
),
6780 Selector_Name
=> Make_Identifier
(Loc
, Nam
));
6782 Find_Selected_Component
(Exp_Name
);
6783 return Entity
(Exp_Name
);
6786 -- Start of processing for Float_Valid
6789 -- The C and AAMP back-ends handle Valid for fpt types
6791 if Modify_Tree_For_C
or else Float_Rep
(Btyp
) = AAMP
then
6792 Analyze_And_Resolve
(Pref
, Ptyp
);
6793 Set_Etype
(N
, Standard_Boolean
);
6797 Find_Fat_Info
(Ptyp
, Ftp
, Pkg
);
6799 -- If the prefix is a reverse SSO component, or is possibly
6800 -- unaligned, first create a temporary copy that is in
6801 -- native SSO, and properly aligned. Make it Volatile to
6802 -- prevent folding in the back-end. Note that we use an
6803 -- intermediate constrained string type to initialize the
6804 -- temporary, as the value at hand might be invalid, and in
6805 -- that case it cannot be copied using a floating point
6808 if In_Reverse_Storage_Order_Object
(Pref
)
6809 or else Is_Possibly_Unaligned_Object
(Pref
)
6812 Temp
: constant Entity_Id
:=
6813 Make_Temporary
(Loc
, 'F');
6815 Fat_S
: constant Entity_Id
:=
6816 Get_Fat_Entity
(Name_S
);
6817 -- Constrained string subtype of appropriate size
6819 Fat_P
: constant Entity_Id
:=
6820 Get_Fat_Entity
(Name_P
);
6823 Decl
: constant Node_Id
:=
6824 Make_Object_Declaration
(Loc
,
6825 Defining_Identifier
=> Temp
,
6826 Aliased_Present
=> True,
6827 Object_Definition
=>
6828 New_Occurrence_Of
(Ptyp
, Loc
));
6831 Set_Aspect_Specifications
(Decl
, New_List
(
6832 Make_Aspect_Specification
(Loc
,
6834 Make_Identifier
(Loc
, Name_Volatile
))));
6840 Make_Assignment_Statement
(Loc
,
6842 Make_Explicit_Dereference
(Loc
,
6844 Unchecked_Convert_To
(Fat_P
,
6845 Make_Attribute_Reference
(Loc
,
6847 New_Occurrence_Of
(Temp
, Loc
),
6849 Name_Unrestricted_Access
))),
6851 Unchecked_Convert_To
(Fat_S
,
6852 Relocate_Node
(Pref
)))),
6854 Suppress
=> All_Checks
);
6856 Rewrite
(Pref
, New_Occurrence_Of
(Temp
, Loc
));
6860 -- We now have an object of the proper endianness and
6861 -- alignment, and can construct a Valid attribute.
6863 -- We make sure the prefix of this valid attribute is
6864 -- marked as not coming from source, to avoid losing
6865 -- warnings from 'Valid looking like a possible update.
6867 Set_Comes_From_Source
(Pref
, False);
6869 Expand_Fpt_Attribute
6870 (N
, Pkg
, Name_Valid
,
6872 Make_Attribute_Reference
(Loc
,
6873 Prefix
=> Unchecked_Convert_To
(Ftp
, Pref
),
6874 Attribute_Name
=> Name_Unrestricted_Access
)));
6877 -- One more task, we still need a range check. Required
6878 -- only if we have a constraint, since the Valid routine
6879 -- catches infinities properly (infinities are never valid).
6881 -- The way we do the range check is simply to create the
6882 -- expression: Valid (N) and then Base_Type(Pref) in Typ.
6884 if not Subtypes_Statically_Match
(Ptyp
, Btyp
) then
6887 Left_Opnd
=> Relocate_Node
(N
),
6890 Left_Opnd
=> Convert_To
(Btyp
, Pref
),
6891 Right_Opnd
=> New_Occurrence_Of
(Ptyp
, Loc
))));
6895 -- Enumeration type with holes
6897 -- For enumeration types with holes, the Pos value constructed by
6898 -- the Enum_Rep_To_Pos function built in Exp_Ch3 called with a
6899 -- second argument of False returns minus one for an invalid value,
6900 -- and the non-negative pos value for a valid value, so the
6901 -- expansion of X'Valid is simply:
6903 -- type(X)'Pos (X) >= 0
6905 -- We can't quite generate it that way because of the requirement
6906 -- for the non-standard second argument of False in the resulting
6907 -- rep_to_pos call, so we have to explicitly create:
6909 -- _rep_to_pos (X, False) >= 0
6911 -- If we have an enumeration subtype, we also check that the
6912 -- value is in range:
6914 -- _rep_to_pos (X, False) >= 0
6916 -- (X >= type(X)'First and then type(X)'Last <= X)
6918 elsif Is_Enumeration_Type
(Ptyp
)
6919 and then Present
(Enum_Pos_To_Rep
(Btyp
))
6924 Make_Function_Call
(Loc
,
6926 New_Occurrence_Of
(TSS
(Btyp
, TSS_Rep_To_Pos
), Loc
),
6927 Parameter_Associations
=> New_List
(
6929 New_Occurrence_Of
(Standard_False
, Loc
))),
6930 Right_Opnd
=> Make_Integer_Literal
(Loc
, 0));
6934 (Type_Low_Bound
(Ptyp
) /= Type_Low_Bound
(Btyp
)
6936 Type_High_Bound
(Ptyp
) /= Type_High_Bound
(Btyp
))
6938 -- The call to Make_Range_Test will create declarations
6939 -- that need a proper insertion point, but Pref is now
6940 -- attached to a node with no ancestor. Attach to tree
6941 -- even if it is to be rewritten below.
6943 Set_Parent
(Tst
, Parent
(N
));
6947 Left_Opnd
=> Make_Range_Test
,
6953 -- Fortran convention booleans
6955 -- For the very special case of Fortran convention booleans, the
6956 -- value is always valid, since it is an integer with the semantics
6957 -- that non-zero is true, and any value is permissible.
6959 elsif Is_Boolean_Type
(Ptyp
)
6960 and then Convention
(Ptyp
) = Convention_Fortran
6962 Rewrite
(N
, New_Occurrence_Of
(Standard_True
, Loc
));
6964 -- For biased representations, we will be doing an unchecked
6965 -- conversion without unbiasing the result. That means that the range
6966 -- test has to take this into account, and the proper form of the
6969 -- Btyp!(Pref) < Btyp!(Ptyp'Range_Length)
6971 elsif Has_Biased_Representation
(Ptyp
) then
6972 Btyp
:= RTE
(RE_Unsigned_32
);
6976 Unchecked_Convert_To
(Btyp
, Duplicate_Subexpr
(Pref
)),
6978 Unchecked_Convert_To
(Btyp
,
6979 Make_Attribute_Reference
(Loc
,
6980 Prefix
=> New_Occurrence_Of
(Ptyp
, Loc
),
6981 Attribute_Name
=> Name_Range_Length
))));
6983 -- For all other scalar types, what we want logically is a
6986 -- X in type(X)'First .. type(X)'Last
6988 -- But that's precisely what won't work because of possible
6989 -- unwanted optimization (and indeed the basic motivation for
6990 -- the Valid attribute is exactly that this test does not work).
6991 -- What will work is:
6993 -- Btyp!(X) >= Btyp!(type(X)'First)
6995 -- Btyp!(X) <= Btyp!(type(X)'Last)
6997 -- where Btyp is an integer type large enough to cover the full
6998 -- range of possible stored values (i.e. it is chosen on the basis
6999 -- of the size of the type, not the range of the values). We write
7000 -- this as two tests, rather than a range check, so that static
7001 -- evaluation will easily remove either or both of the checks if
7002 -- they can be -statically determined to be true (this happens
7003 -- when the type of X is static and the range extends to the full
7004 -- range of stored values).
7006 -- Unsigned types. Note: it is safe to consider only whether the
7007 -- subtype is unsigned, since we will in that case be doing all
7008 -- unsigned comparisons based on the subtype range. Since we use the
7009 -- actual subtype object size, this is appropriate.
7011 -- For example, if we have
7013 -- subtype x is integer range 1 .. 200;
7014 -- for x'Object_Size use 8;
7016 -- Now the base type is signed, but objects of this type are bits
7017 -- unsigned, and doing an unsigned test of the range 1 to 200 is
7018 -- correct, even though a value greater than 127 looks signed to a
7019 -- signed comparison.
7021 elsif Is_Unsigned_Type
(Ptyp
) then
7022 if Esize
(Ptyp
) <= 32 then
7023 Btyp
:= RTE
(RE_Unsigned_32
);
7025 Btyp
:= RTE
(RE_Unsigned_64
);
7028 Rewrite
(N
, Make_Range_Test
);
7033 if Esize
(Ptyp
) <= Esize
(Standard_Integer
) then
7034 Btyp
:= Standard_Integer
;
7036 Btyp
:= Universal_Integer
;
7039 Rewrite
(N
, Make_Range_Test
);
7042 -- If a predicate is present, then we do the predicate test, even if
7043 -- within the predicate function (infinite recursion is warned about
7044 -- in Sem_Attr in that case).
7047 Pred_Func
: constant Entity_Id
:= Predicate_Function
(Ptyp
);
7050 if Present
(Pred_Func
) then
7053 Left_Opnd
=> Relocate_Node
(N
),
7054 Right_Opnd
=> Make_Predicate_Call
(Ptyp
, Pref
)));
7058 Analyze_And_Resolve
(N
, Standard_Boolean
);
7059 Validity_Checks_On
:= Save_Validity_Checks_On
;
7066 when Attribute_Valid_Scalars
=> Valid_Scalars
: declare
7067 Val_Typ
: constant Entity_Id
:= Validated_View
(Ptyp
);
7068 Comp_Typ
: Entity_Id
;
7072 -- Assume that the prefix does not need validation
7076 -- Attribute 'Valid_Scalars is not supported on private tagged types
7078 if Is_Private_Type
(Ptyp
) and then Is_Tagged_Type
(Ptyp
) then
7081 -- Attribute 'Valid_Scalars evaluates to True when the type lacks
7084 elsif not Scalar_Part_Present
(Val_Typ
) then
7087 -- Attribute 'Valid_Scalars is the same as attribute 'Valid when the
7088 -- validated type is a scalar type. Generate:
7090 -- Val_Typ (Pref)'Valid
7092 elsif Is_Scalar_Type
(Val_Typ
) then
7094 Make_Attribute_Reference
(Loc
,
7096 Unchecked_Convert_To
(Val_Typ
, New_Copy_Tree
(Pref
)),
7097 Attribute_Name
=> Name_Valid
);
7099 -- Validate the scalar components of an array by iterating over all
7100 -- dimensions of the array while checking individual components.
7102 elsif Is_Array_Type
(Val_Typ
) then
7103 Comp_Typ
:= Validated_View
(Component_Type
(Val_Typ
));
7105 if Scalar_Part_Present
(Comp_Typ
) then
7107 Make_Function_Call
(Loc
,
7110 (Build_Array_VS_Func
7113 Array_Typ
=> Val_Typ
,
7114 Comp_Typ
=> Comp_Typ
),
7116 Parameter_Associations
=> New_List
(Pref
));
7119 -- Validate the scalar components, discriminants of a record type by
7120 -- examining the structure of a record type.
7122 elsif Is_Record_Type
(Val_Typ
) then
7124 Make_Function_Call
(Loc
,
7127 (Build_Record_VS_Func
7130 Rec_Typ
=> Val_Typ
),
7132 Parameter_Associations
=> New_List
(Pref
));
7135 -- Default the attribute to True when the type of the prefix does not
7139 Expr
:= New_Occurrence_Of
(Standard_True
, Loc
);
7143 Analyze_And_Resolve
(N
, Standard_Boolean
);
7144 Set_Is_Static_Expression
(N
, False);
7151 -- Value attribute is handled in separate unit Exp_Imgv
7153 when Attribute_Value
=>
7154 Exp_Imgv
.Expand_Value_Attribute
(N
);
7160 -- The processing for Value_Size shares the processing for Size
7166 -- The processing for Version shares the processing for Body_Version
7172 -- Wide_Image attribute is handled in separate unit Exp_Imgv
7174 when Attribute_Wide_Image
=>
7175 -- Leave attribute unexpanded in CodePeer mode: the gnat2scil
7176 -- back-end knows how to handle this attribute directly.
7178 if CodePeer_Mode
then
7182 Exp_Imgv
.Expand_Wide_Image_Attribute
(N
);
7184 ---------------------
7185 -- Wide_Wide_Image --
7186 ---------------------
7188 -- Wide_Wide_Image attribute is handled in separate unit Exp_Imgv
7190 when Attribute_Wide_Wide_Image
=>
7191 -- Leave attribute unexpanded in CodePeer mode: the gnat2scil
7192 -- back-end knows how to handle this attribute directly.
7194 if CodePeer_Mode
then
7198 Exp_Imgv
.Expand_Wide_Wide_Image_Attribute
(N
);
7204 -- We expand typ'Wide_Value (X) into
7207 -- (Wide_String_To_String (X, Wide_Character_Encoding_Method))
7209 -- Wide_String_To_String is a runtime function that converts its wide
7210 -- string argument to String, converting any non-translatable characters
7211 -- into appropriate escape sequences. This preserves the required
7212 -- semantics of Wide_Value in all cases, and results in a very simple
7213 -- implementation approach.
7215 -- Note: for this approach to be fully standard compliant for the cases
7216 -- where typ is Wide_Character and Wide_Wide_Character, the encoding
7217 -- method must cover the entire character range (e.g. UTF-8). But that
7218 -- is a reasonable requirement when dealing with encoded character
7219 -- sequences. Presumably if one of the restrictive encoding mechanisms
7220 -- is in use such as Shift-JIS, then characters that cannot be
7221 -- represented using this encoding will not appear in any case.
7223 when Attribute_Wide_Value
=>
7225 Make_Attribute_Reference
(Loc
,
7227 Attribute_Name
=> Name_Value
,
7229 Expressions
=> New_List
(
7230 Make_Function_Call
(Loc
,
7232 New_Occurrence_Of
(RTE
(RE_Wide_String_To_String
), Loc
),
7234 Parameter_Associations
=> New_List
(
7235 Relocate_Node
(First
(Exprs
)),
7236 Make_Integer_Literal
(Loc
,
7237 Intval
=> Int
(Wide_Character_Encoding_Method
)))))));
7239 Analyze_And_Resolve
(N
, Typ
);
7241 ---------------------
7242 -- Wide_Wide_Value --
7243 ---------------------
7245 -- We expand typ'Wide_Value_Value (X) into
7248 -- (Wide_Wide_String_To_String (X, Wide_Character_Encoding_Method))
7250 -- Wide_Wide_String_To_String is a runtime function that converts its
7251 -- wide string argument to String, converting any non-translatable
7252 -- characters into appropriate escape sequences. This preserves the
7253 -- required semantics of Wide_Wide_Value in all cases, and results in a
7254 -- very simple implementation approach.
7256 -- It's not quite right where typ = Wide_Wide_Character, because the
7257 -- encoding method may not cover the whole character type ???
7259 when Attribute_Wide_Wide_Value
=>
7261 Make_Attribute_Reference
(Loc
,
7263 Attribute_Name
=> Name_Value
,
7265 Expressions
=> New_List
(
7266 Make_Function_Call
(Loc
,
7269 (RTE
(RE_Wide_Wide_String_To_String
), Loc
),
7271 Parameter_Associations
=> New_List
(
7272 Relocate_Node
(First
(Exprs
)),
7273 Make_Integer_Literal
(Loc
,
7274 Intval
=> Int
(Wide_Character_Encoding_Method
)))))));
7276 Analyze_And_Resolve
(N
, Typ
);
7278 ---------------------
7279 -- Wide_Wide_Width --
7280 ---------------------
7282 -- Wide_Wide_Width attribute is handled in separate unit Exp_Imgv
7284 when Attribute_Wide_Wide_Width
=>
7285 Exp_Imgv
.Expand_Width_Attribute
(N
, Wide_Wide
);
7291 -- Wide_Width attribute is handled in separate unit Exp_Imgv
7293 when Attribute_Wide_Width
=>
7294 Exp_Imgv
.Expand_Width_Attribute
(N
, Wide
);
7300 -- Width attribute is handled in separate unit Exp_Imgv
7302 when Attribute_Width
=>
7303 Exp_Imgv
.Expand_Width_Attribute
(N
, Normal
);
7309 when Attribute_Write
=> Write
: declare
7310 P_Type
: constant Entity_Id
:= Entity
(Pref
);
7311 U_Type
: constant Entity_Id
:= Underlying_Type
(P_Type
);
7319 -- If no underlying type, we have an error that will be diagnosed
7320 -- elsewhere, so here we just completely ignore the expansion.
7326 -- Stream operations can appear in user code even if the restriction
7327 -- No_Streams is active (for example, when instantiating a predefined
7328 -- container). In that case rewrite the attribute as a Raise to
7329 -- prevent any run-time use.
7331 if Restriction_Active
(No_Streams
) then
7333 Make_Raise_Program_Error
(Sloc
(N
),
7334 Reason
=> PE_Stream_Operation_Not_Allowed
));
7335 Set_Etype
(N
, U_Type
);
7339 -- The simple case, if there is a TSS for Write, just call it
7341 Pname
:= Find_Stream_Subprogram
(P_Type
, TSS_Stream_Write
);
7343 if Present
(Pname
) then
7347 -- If there is a Stream_Convert pragma, use it, we rewrite
7349 -- sourcetyp'Output (stream, Item)
7353 -- strmtyp'Output (Stream, strmwrite (acttyp (Item)));
7355 -- where strmwrite is the given Write function that converts an
7356 -- argument of type sourcetyp or a type acctyp, from which it is
7357 -- derived to type strmtyp. The conversion to acttyp is required
7358 -- for the derived case.
7360 Prag
:= Get_Stream_Convert_Pragma
(P_Type
);
7362 if Present
(Prag
) then
7364 Next
(Next
(First
(Pragma_Argument_Associations
(Prag
))));
7365 Wfunc
:= Entity
(Expression
(Arg3
));
7368 Make_Attribute_Reference
(Loc
,
7369 Prefix
=> New_Occurrence_Of
(Etype
(Wfunc
), Loc
),
7370 Attribute_Name
=> Name_Output
,
7371 Expressions
=> New_List
(
7372 Relocate_Node
(First
(Exprs
)),
7373 Make_Function_Call
(Loc
,
7374 Name
=> New_Occurrence_Of
(Wfunc
, Loc
),
7375 Parameter_Associations
=> New_List
(
7376 OK_Convert_To
(Etype
(First_Formal
(Wfunc
)),
7377 Relocate_Node
(Next
(First
(Exprs
)))))))));
7382 -- For elementary types, we call the W_xxx routine directly
7384 elsif Is_Elementary_Type
(U_Type
) then
7385 Rewrite
(N
, Build_Elementary_Write_Call
(N
));
7391 elsif Is_Array_Type
(U_Type
) then
7392 Build_Array_Write_Procedure
(N
, U_Type
, Decl
, Pname
);
7393 Compile_Stream_Body_In_Scope
(N
, Decl
, U_Type
, Check
=> False);
7395 -- Tagged type case, use the primitive Write function. Note that
7396 -- this will dispatch in the class-wide case which is what we want
7398 elsif Is_Tagged_Type
(U_Type
) then
7399 Pname
:= Find_Prim_Op
(U_Type
, TSS_Stream_Write
);
7401 -- All other record type cases, including protected records.
7402 -- The latter only arise for expander generated code for
7403 -- handling shared passive partition access.
7407 (Is_Record_Type
(U_Type
) or else Is_Protected_Type
(U_Type
));
7409 -- Ada 2005 (AI-216): Program_Error is raised when executing
7410 -- the default implementation of the Write attribute of an
7411 -- Unchecked_Union type. However, if the 'Write reference is
7412 -- within the generated Output stream procedure, Write outputs
7413 -- the components, and the default values of the discriminant
7414 -- are streamed by the Output procedure itself. If there are
7415 -- no default values this is also erroneous.
7417 if Is_Unchecked_Union
(Base_Type
(U_Type
)) then
7418 if (not Is_TSS
(Current_Scope
, TSS_Stream_Output
)
7419 and not Is_TSS
(Current_Scope
, TSS_Stream_Write
))
7420 or else No
(Discriminant_Default_Value
7421 (First_Discriminant
(U_Type
)))
7424 Make_Raise_Program_Error
(Loc
,
7425 Reason
=> PE_Unchecked_Union_Restriction
));
7426 Set_Etype
(N
, U_Type
);
7431 if Has_Discriminants
(U_Type
)
7433 (Discriminant_Default_Value
(First_Discriminant
(U_Type
)))
7435 Build_Mutable_Record_Write_Procedure
7436 (Loc
, Full_Base
(U_Type
), Decl
, Pname
);
7438 Build_Record_Write_Procedure
7439 (Loc
, Full_Base
(U_Type
), Decl
, Pname
);
7442 Insert_Action
(N
, Decl
);
7446 -- If we fall through, Pname is the procedure to be called
7448 Rewrite_Stream_Proc_Call
(Pname
);
7451 -- Component_Size is handled by the back end, unless the component size
7452 -- is known at compile time, which is always true in the packed array
7453 -- case. It is important that the packed array case is handled in the
7454 -- front end (see Eval_Attribute) since the back end would otherwise get
7455 -- confused by the equivalent packed array type.
7457 when Attribute_Component_Size
=>
7460 -- The following attributes are handled by the back end (except that
7461 -- static cases have already been evaluated during semantic processing,
7462 -- but in any case the back end should not count on this).
7464 -- The back end also handles the non-class-wide cases of Size
7466 when Attribute_Bit_Order
7467 | Attribute_Code_Address
7468 | Attribute_Definite
7470 | Attribute_Null_Parameter
7471 | Attribute_Passed_By_Reference
7472 | Attribute_Pool_Address
7473 | Attribute_Scalar_Storage_Order
7477 -- The following attributes are also handled by the back end, but return
7478 -- a universal integer result, so may need a conversion for checking
7479 -- that the result is in range.
7482 | Attribute_Max_Alignment_For_Allocation
7484 Apply_Universal_Integer_Attribute_Checks
(N
);
7486 -- The following attributes should not appear at this stage, since they
7487 -- have already been handled by the analyzer (and properly rewritten
7488 -- with corresponding values or entities to represent the right values)
7490 when Attribute_Abort_Signal
7491 | Attribute_Address_Size
7492 | Attribute_Atomic_Always_Lock_Free
7495 | Attribute_Compiler_Version
7496 | Attribute_Default_Bit_Order
7497 | Attribute_Default_Scalar_Storage_Order
7504 | Attribute_Fast_Math
7505 | Attribute_First_Valid
7506 | Attribute_Has_Access_Values
7507 | Attribute_Has_Discriminants
7508 | Attribute_Has_Tagged_Values
7510 | Attribute_Last_Valid
7511 | Attribute_Library_Level
7512 | Attribute_Lock_Free
7513 | Attribute_Machine_Emax
7514 | Attribute_Machine_Emin
7515 | Attribute_Machine_Mantissa
7516 | Attribute_Machine_Overflows
7517 | Attribute_Machine_Radix
7518 | Attribute_Machine_Rounds
7519 | Attribute_Maximum_Alignment
7520 | Attribute_Model_Emin
7521 | Attribute_Model_Epsilon
7522 | Attribute_Model_Mantissa
7523 | Attribute_Model_Small
7525 | Attribute_Partition_ID
7527 | Attribute_Restriction_Set
7528 | Attribute_Safe_Emax
7529 | Attribute_Safe_First
7530 | Attribute_Safe_Large
7531 | Attribute_Safe_Last
7532 | Attribute_Safe_Small
7534 | Attribute_Signed_Zeros
7536 | Attribute_Storage_Unit
7537 | Attribute_Stub_Type
7538 | Attribute_System_Allocator_Alignment
7539 | Attribute_Target_Name
7540 | Attribute_Type_Class
7541 | Attribute_Type_Key
7542 | Attribute_Unconstrained_Array
7543 | Attribute_Universal_Literal_String
7544 | Attribute_Wchar_T_Size
7545 | Attribute_Word_Size
7547 raise Program_Error
;
7549 -- The Asm_Input and Asm_Output attributes are not expanded at this
7550 -- stage, but will be eliminated in the expansion of the Asm call, see
7551 -- Exp_Intr for details. So the back end will never see these either.
7553 when Attribute_Asm_Input
7554 | Attribute_Asm_Output
7559 -- Note: as mentioned earlier, individual sections of the above case
7560 -- statement assume there is no code after the case statement, and are
7561 -- legitimately allowed to execute return statements if they have nothing
7562 -- more to do, so DO NOT add code at this point.
7565 when RE_Not_Available
=>
7567 end Expand_N_Attribute_Reference
;
7569 --------------------------------
7570 -- Expand_Pred_Succ_Attribute --
7571 --------------------------------
7573 -- For typ'Pred (exp), we generate the check
7575 -- [constraint_error when exp = typ'Base'First]
7577 -- Similarly, for typ'Succ (exp), we generate the check
7579 -- [constraint_error when exp = typ'Base'Last]
7581 -- These checks are not generated for modular types, since the proper
7582 -- semantics for Succ and Pred on modular types is to wrap, not raise CE.
7583 -- We also suppress these checks if we are the right side of an assignment
7584 -- statement or the expression of an object declaration, where the flag
7585 -- Suppress_Assignment_Checks is set for the assignment/declaration.
7587 procedure Expand_Pred_Succ_Attribute
(N
: Node_Id
) is
7588 Loc
: constant Source_Ptr
:= Sloc
(N
);
7589 P
: constant Node_Id
:= Parent
(N
);
7593 if Attribute_Name
(N
) = Name_Pred
then
7599 if not Nkind_In
(P
, N_Assignment_Statement
, N_Object_Declaration
)
7600 or else not Suppress_Assignment_Checks
(P
)
7603 Make_Raise_Constraint_Error
(Loc
,
7607 Duplicate_Subexpr_Move_Checks
(First
(Expressions
(N
))),
7609 Make_Attribute_Reference
(Loc
,
7611 New_Occurrence_Of
(Base_Type
(Etype
(Prefix
(N
))), Loc
),
7612 Attribute_Name
=> Cnam
)),
7613 Reason
=> CE_Overflow_Check_Failed
));
7615 end Expand_Pred_Succ_Attribute
;
7617 -----------------------------
7618 -- Expand_Update_Attribute --
7619 -----------------------------
7621 procedure Expand_Update_Attribute
(N
: Node_Id
) is
7622 procedure Process_Component_Or_Element_Update
7627 -- Generate the statements necessary to update a single component or an
7628 -- element of the prefix. The code is inserted before the attribute N.
7629 -- Temp denotes the entity of the anonymous object created to reflect
7630 -- the changes in values. Comp is the component/index expression to be
7631 -- updated. Expr is an expression yielding the new value of Comp. Typ
7632 -- is the type of the prefix of attribute Update.
7634 procedure Process_Range_Update
7639 -- Generate the statements necessary to update a slice of the prefix.
7640 -- The code is inserted before the attribute N. Temp denotes the entity
7641 -- of the anonymous object created to reflect the changes in values.
7642 -- Comp is range of the slice to be updated. Expr is an expression
7643 -- yielding the new value of Comp. Typ is the type of the prefix of
7644 -- attribute Update.
7646 -----------------------------------------
7647 -- Process_Component_Or_Element_Update --
7648 -----------------------------------------
7650 procedure Process_Component_Or_Element_Update
7656 Loc
: constant Source_Ptr
:= Sloc
(Comp
);
7661 -- An array element may be modified by the following relations
7662 -- depending on the number of dimensions:
7664 -- 1 => Expr -- one dimensional update
7665 -- (1, ..., N) => Expr -- multi dimensional update
7667 -- The above forms are converted in assignment statements where the
7668 -- left hand side is an indexed component:
7670 -- Temp (1) := Expr; -- one dimensional update
7671 -- Temp (1, ..., N) := Expr; -- multi dimensional update
7673 if Is_Array_Type
(Typ
) then
7675 -- The index expressions of a multi dimensional array update
7676 -- appear as an aggregate.
7678 if Nkind
(Comp
) = N_Aggregate
then
7679 Exprs
:= New_Copy_List_Tree
(Expressions
(Comp
));
7681 Exprs
:= New_List
(Relocate_Node
(Comp
));
7685 Make_Indexed_Component
(Loc
,
7686 Prefix
=> New_Occurrence_Of
(Temp
, Loc
),
7687 Expressions
=> Exprs
);
7689 -- A record component update appears in the following form:
7693 -- The above relation is transformed into an assignment statement
7694 -- where the left hand side is a selected component:
7696 -- Temp.Comp := Expr;
7698 else pragma Assert
(Is_Record_Type
(Typ
));
7700 Make_Selected_Component
(Loc
,
7701 Prefix
=> New_Occurrence_Of
(Temp
, Loc
),
7702 Selector_Name
=> Relocate_Node
(Comp
));
7706 Make_Assignment_Statement
(Loc
,
7708 Expression
=> Relocate_Node
(Expr
)));
7709 end Process_Component_Or_Element_Update
;
7711 --------------------------
7712 -- Process_Range_Update --
7713 --------------------------
7715 procedure Process_Range_Update
7721 Index_Typ
: constant Entity_Id
:= Etype
(First_Index
(Typ
));
7722 Loc
: constant Source_Ptr
:= Sloc
(Comp
);
7726 -- A range update appears as
7728 -- (Low .. High => Expr)
7730 -- The above construct is transformed into a loop that iterates over
7731 -- the given range and modifies the corresponding array values to the
7734 -- for Index in Low .. High loop
7735 -- Temp (<Index_Typ> (Index)) := Expr;
7738 Index
:= Make_Temporary
(Loc
, 'I');
7741 Make_Loop_Statement
(Loc
,
7743 Make_Iteration_Scheme
(Loc
,
7744 Loop_Parameter_Specification
=>
7745 Make_Loop_Parameter_Specification
(Loc
,
7746 Defining_Identifier
=> Index
,
7747 Discrete_Subtype_Definition
=> Relocate_Node
(Comp
))),
7749 Statements
=> New_List
(
7750 Make_Assignment_Statement
(Loc
,
7752 Make_Indexed_Component
(Loc
,
7753 Prefix
=> New_Occurrence_Of
(Temp
, Loc
),
7754 Expressions
=> New_List
(
7755 Convert_To
(Index_Typ
,
7756 New_Occurrence_Of
(Index
, Loc
)))),
7757 Expression
=> Relocate_Node
(Expr
))),
7759 End_Label
=> Empty
));
7760 end Process_Range_Update
;
7764 Aggr
: constant Node_Id
:= First
(Expressions
(N
));
7765 Loc
: constant Source_Ptr
:= Sloc
(N
);
7766 Pref
: constant Node_Id
:= Prefix
(N
);
7767 Typ
: constant Entity_Id
:= Etype
(Pref
);
7770 CW_Temp
: Entity_Id
;
7775 -- Start of processing for Expand_Update_Attribute
7778 -- Create the anonymous object to store the value of the prefix and
7779 -- capture subsequent changes in value.
7781 Temp
:= Make_Temporary
(Loc
, 'T', Pref
);
7783 -- Preserve the tag of the prefix by offering a specific view of the
7784 -- class-wide version of the prefix.
7786 if Is_Tagged_Type
(Typ
) then
7789 -- CW_Temp : Typ'Class := Typ'Class (Pref);
7791 CW_Temp
:= Make_Temporary
(Loc
, 'T');
7792 CW_Typ
:= Class_Wide_Type
(Typ
);
7795 Make_Object_Declaration
(Loc
,
7796 Defining_Identifier
=> CW_Temp
,
7797 Object_Definition
=> New_Occurrence_Of
(CW_Typ
, Loc
),
7799 Convert_To
(CW_Typ
, Relocate_Node
(Pref
))));
7802 -- Temp : Typ renames Typ (CW_Temp);
7805 Make_Object_Renaming_Declaration
(Loc
,
7806 Defining_Identifier
=> Temp
,
7807 Subtype_Mark
=> New_Occurrence_Of
(Typ
, Loc
),
7809 Convert_To
(Typ
, New_Occurrence_Of
(CW_Temp
, Loc
))));
7815 -- Temp : Typ := Pref;
7818 Make_Object_Declaration
(Loc
,
7819 Defining_Identifier
=> Temp
,
7820 Object_Definition
=> New_Occurrence_Of
(Typ
, Loc
),
7821 Expression
=> Relocate_Node
(Pref
)));
7824 -- Process the update aggregate
7826 Assoc
:= First
(Component_Associations
(Aggr
));
7827 while Present
(Assoc
) loop
7828 Comp
:= First
(Choices
(Assoc
));
7829 Expr
:= Expression
(Assoc
);
7830 while Present
(Comp
) loop
7831 if Nkind
(Comp
) = N_Range
then
7832 Process_Range_Update
(Temp
, Comp
, Expr
, Typ
);
7834 Process_Component_Or_Element_Update
(Temp
, Comp
, Expr
, Typ
);
7843 -- The attribute is replaced by a reference to the anonymous object
7845 Rewrite
(N
, New_Occurrence_Of
(Temp
, Loc
));
7847 end Expand_Update_Attribute
;
7853 procedure Find_Fat_Info
7855 Fat_Type
: out Entity_Id
;
7856 Fat_Pkg
: out RE_Id
)
7858 Rtyp
: constant Entity_Id
:= Root_Type
(T
);
7861 -- All we do is use the root type (historically this dealt with
7862 -- VAX-float .. to be cleaned up further later ???)
7866 if Fat_Type
= Standard_Short_Float
then
7867 Fat_Pkg
:= RE_Attr_Short_Float
;
7869 elsif Fat_Type
= Standard_Float
then
7870 Fat_Pkg
:= RE_Attr_Float
;
7872 elsif Fat_Type
= Standard_Long_Float
then
7873 Fat_Pkg
:= RE_Attr_Long_Float
;
7875 elsif Fat_Type
= Standard_Long_Long_Float
then
7876 Fat_Pkg
:= RE_Attr_Long_Long_Float
;
7878 -- Universal real (which is its own root type) is treated as being
7879 -- equivalent to Standard.Long_Long_Float, since it is defined to
7880 -- have the same precision as the longest Float type.
7882 elsif Fat_Type
= Universal_Real
then
7883 Fat_Type
:= Standard_Long_Long_Float
;
7884 Fat_Pkg
:= RE_Attr_Long_Long_Float
;
7887 raise Program_Error
;
7891 ----------------------------
7892 -- Find_Stream_Subprogram --
7893 ----------------------------
7895 function Find_Stream_Subprogram
7897 Nam
: TSS_Name_Type
) return Entity_Id
7899 Base_Typ
: constant Entity_Id
:= Base_Type
(Typ
);
7900 Ent
: constant Entity_Id
:= TSS
(Typ
, Nam
);
7902 function Is_Available
(Entity
: RE_Id
) return Boolean;
7903 pragma Inline
(Is_Available
);
7904 -- Function to check whether the specified run-time call is available
7905 -- in the run time used. In the case of a configurable run time, it
7906 -- is normal that some subprograms are not there.
7908 -- I don't understand this routine at all, why is this not just a
7909 -- call to RTE_Available? And if for some reason we need a different
7910 -- routine with different semantics, why is not in Rtsfind ???
7916 function Is_Available
(Entity
: RE_Id
) return Boolean is
7918 -- Assume that the unit will always be available when using a
7919 -- "normal" (not configurable) run time.
7921 return not Configurable_Run_Time_Mode
or else RTE_Available
(Entity
);
7924 -- Start of processing for Find_Stream_Subprogram
7927 if Present
(Ent
) then
7931 -- Stream attributes for strings are expanded into library calls. The
7932 -- following checks are disabled when the run-time is not available or
7933 -- when compiling predefined types due to bootstrap issues. As a result,
7934 -- the compiler will generate in-place stream routines for string types
7935 -- that appear in GNAT's library, but will generate calls via rtsfind
7936 -- to library routines for user code.
7938 -- Note: In the case of using a configurable run time, it is very likely
7939 -- that stream routines for string types are not present (they require
7940 -- file system support). In this case, the specific stream routines for
7941 -- strings are not used, relying on the regular stream mechanism
7942 -- instead. That is why we include the test Is_Available when dealing
7943 -- with these cases.
7945 if not Is_Predefined_Unit
(Current_Sem_Unit
) then
7946 -- Storage_Array as defined in package System.Storage_Elements
7948 if Is_RTE
(Base_Typ
, RE_Storage_Array
) then
7950 -- Case of No_Stream_Optimizations restriction active
7952 if Restriction_Active
(No_Stream_Optimizations
) then
7953 if Nam
= TSS_Stream_Input
7954 and then Is_Available
(RE_Storage_Array_Input
)
7956 return RTE
(RE_Storage_Array_Input
);
7958 elsif Nam
= TSS_Stream_Output
7959 and then Is_Available
(RE_Storage_Array_Output
)
7961 return RTE
(RE_Storage_Array_Output
);
7963 elsif Nam
= TSS_Stream_Read
7964 and then Is_Available
(RE_Storage_Array_Read
)
7966 return RTE
(RE_Storage_Array_Read
);
7968 elsif Nam
= TSS_Stream_Write
7969 and then Is_Available
(RE_Storage_Array_Write
)
7971 return RTE
(RE_Storage_Array_Write
);
7973 elsif Nam
/= TSS_Stream_Input
and then
7974 Nam
/= TSS_Stream_Output
and then
7975 Nam
/= TSS_Stream_Read
and then
7976 Nam
/= TSS_Stream_Write
7978 raise Program_Error
;
7981 -- Restriction No_Stream_Optimizations is not set, so we can go
7982 -- ahead and optimize using the block IO forms of the routines.
7985 if Nam
= TSS_Stream_Input
7986 and then Is_Available
(RE_Storage_Array_Input_Blk_IO
)
7988 return RTE
(RE_Storage_Array_Input_Blk_IO
);
7990 elsif Nam
= TSS_Stream_Output
7991 and then Is_Available
(RE_Storage_Array_Output_Blk_IO
)
7993 return RTE
(RE_Storage_Array_Output_Blk_IO
);
7995 elsif Nam
= TSS_Stream_Read
7996 and then Is_Available
(RE_Storage_Array_Read_Blk_IO
)
7998 return RTE
(RE_Storage_Array_Read_Blk_IO
);
8000 elsif Nam
= TSS_Stream_Write
8001 and then Is_Available
(RE_Storage_Array_Write_Blk_IO
)
8003 return RTE
(RE_Storage_Array_Write_Blk_IO
);
8005 elsif Nam
/= TSS_Stream_Input
and then
8006 Nam
/= TSS_Stream_Output
and then
8007 Nam
/= TSS_Stream_Read
and then
8008 Nam
/= TSS_Stream_Write
8010 raise Program_Error
;
8014 -- Stream_Element_Array as defined in package Ada.Streams
8016 elsif Is_RTE
(Base_Typ
, RE_Stream_Element_Array
) then
8018 -- Case of No_Stream_Optimizations restriction active
8020 if Restriction_Active
(No_Stream_Optimizations
) then
8021 if Nam
= TSS_Stream_Input
8022 and then Is_Available
(RE_Stream_Element_Array_Input
)
8024 return RTE
(RE_Stream_Element_Array_Input
);
8026 elsif Nam
= TSS_Stream_Output
8027 and then Is_Available
(RE_Stream_Element_Array_Output
)
8029 return RTE
(RE_Stream_Element_Array_Output
);
8031 elsif Nam
= TSS_Stream_Read
8032 and then Is_Available
(RE_Stream_Element_Array_Read
)
8034 return RTE
(RE_Stream_Element_Array_Read
);
8036 elsif Nam
= TSS_Stream_Write
8037 and then Is_Available
(RE_Stream_Element_Array_Write
)
8039 return RTE
(RE_Stream_Element_Array_Write
);
8041 elsif Nam
/= TSS_Stream_Input
and then
8042 Nam
/= TSS_Stream_Output
and then
8043 Nam
/= TSS_Stream_Read
and then
8044 Nam
/= TSS_Stream_Write
8046 raise Program_Error
;
8049 -- Restriction No_Stream_Optimizations is not set, so we can go
8050 -- ahead and optimize using the block IO forms of the routines.
8053 if Nam
= TSS_Stream_Input
8054 and then Is_Available
(RE_Stream_Element_Array_Input_Blk_IO
)
8056 return RTE
(RE_Stream_Element_Array_Input_Blk_IO
);
8058 elsif Nam
= TSS_Stream_Output
8059 and then Is_Available
(RE_Stream_Element_Array_Output_Blk_IO
)
8061 return RTE
(RE_Stream_Element_Array_Output_Blk_IO
);
8063 elsif Nam
= TSS_Stream_Read
8064 and then Is_Available
(RE_Stream_Element_Array_Read_Blk_IO
)
8066 return RTE
(RE_Stream_Element_Array_Read_Blk_IO
);
8068 elsif Nam
= TSS_Stream_Write
8069 and then Is_Available
(RE_Stream_Element_Array_Write_Blk_IO
)
8071 return RTE
(RE_Stream_Element_Array_Write_Blk_IO
);
8073 elsif Nam
/= TSS_Stream_Input
and then
8074 Nam
/= TSS_Stream_Output
and then
8075 Nam
/= TSS_Stream_Read
and then
8076 Nam
/= TSS_Stream_Write
8078 raise Program_Error
;
8082 -- String as defined in package Ada
8084 elsif Base_Typ
= Standard_String
then
8086 -- Case of No_Stream_Optimizations restriction active
8088 if Restriction_Active
(No_Stream_Optimizations
) then
8089 if Nam
= TSS_Stream_Input
8090 and then Is_Available
(RE_String_Input
)
8092 return RTE
(RE_String_Input
);
8094 elsif Nam
= TSS_Stream_Output
8095 and then Is_Available
(RE_String_Output
)
8097 return RTE
(RE_String_Output
);
8099 elsif Nam
= TSS_Stream_Read
8100 and then Is_Available
(RE_String_Read
)
8102 return RTE
(RE_String_Read
);
8104 elsif Nam
= TSS_Stream_Write
8105 and then Is_Available
(RE_String_Write
)
8107 return RTE
(RE_String_Write
);
8109 elsif Nam
/= TSS_Stream_Input
and then
8110 Nam
/= TSS_Stream_Output
and then
8111 Nam
/= TSS_Stream_Read
and then
8112 Nam
/= TSS_Stream_Write
8114 raise Program_Error
;
8117 -- Restriction No_Stream_Optimizations is not set, so we can go
8118 -- ahead and optimize using the block IO forms of the routines.
8121 if Nam
= TSS_Stream_Input
8122 and then Is_Available
(RE_String_Input_Blk_IO
)
8124 return RTE
(RE_String_Input_Blk_IO
);
8126 elsif Nam
= TSS_Stream_Output
8127 and then Is_Available
(RE_String_Output_Blk_IO
)
8129 return RTE
(RE_String_Output_Blk_IO
);
8131 elsif Nam
= TSS_Stream_Read
8132 and then Is_Available
(RE_String_Read_Blk_IO
)
8134 return RTE
(RE_String_Read_Blk_IO
);
8136 elsif Nam
= TSS_Stream_Write
8137 and then Is_Available
(RE_String_Write_Blk_IO
)
8139 return RTE
(RE_String_Write_Blk_IO
);
8141 elsif Nam
/= TSS_Stream_Input
and then
8142 Nam
/= TSS_Stream_Output
and then
8143 Nam
/= TSS_Stream_Read
and then
8144 Nam
/= TSS_Stream_Write
8146 raise Program_Error
;
8150 -- Wide_String as defined in package Ada
8152 elsif Base_Typ
= Standard_Wide_String
then
8154 -- Case of No_Stream_Optimizations restriction active
8156 if Restriction_Active
(No_Stream_Optimizations
) then
8157 if Nam
= TSS_Stream_Input
8158 and then Is_Available
(RE_Wide_String_Input
)
8160 return RTE
(RE_Wide_String_Input
);
8162 elsif Nam
= TSS_Stream_Output
8163 and then Is_Available
(RE_Wide_String_Output
)
8165 return RTE
(RE_Wide_String_Output
);
8167 elsif Nam
= TSS_Stream_Read
8168 and then Is_Available
(RE_Wide_String_Read
)
8170 return RTE
(RE_Wide_String_Read
);
8172 elsif Nam
= TSS_Stream_Write
8173 and then Is_Available
(RE_Wide_String_Write
)
8175 return RTE
(RE_Wide_String_Write
);
8177 elsif Nam
/= TSS_Stream_Input
and then
8178 Nam
/= TSS_Stream_Output
and then
8179 Nam
/= TSS_Stream_Read
and then
8180 Nam
/= TSS_Stream_Write
8182 raise Program_Error
;
8185 -- Restriction No_Stream_Optimizations is not set, so we can go
8186 -- ahead and optimize using the block IO forms of the routines.
8189 if Nam
= TSS_Stream_Input
8190 and then Is_Available
(RE_Wide_String_Input_Blk_IO
)
8192 return RTE
(RE_Wide_String_Input_Blk_IO
);
8194 elsif Nam
= TSS_Stream_Output
8195 and then Is_Available
(RE_Wide_String_Output_Blk_IO
)
8197 return RTE
(RE_Wide_String_Output_Blk_IO
);
8199 elsif Nam
= TSS_Stream_Read
8200 and then Is_Available
(RE_Wide_String_Read_Blk_IO
)
8202 return RTE
(RE_Wide_String_Read_Blk_IO
);
8204 elsif Nam
= TSS_Stream_Write
8205 and then Is_Available
(RE_Wide_String_Write_Blk_IO
)
8207 return RTE
(RE_Wide_String_Write_Blk_IO
);
8209 elsif Nam
/= TSS_Stream_Input
and then
8210 Nam
/= TSS_Stream_Output
and then
8211 Nam
/= TSS_Stream_Read
and then
8212 Nam
/= TSS_Stream_Write
8214 raise Program_Error
;
8218 -- Wide_Wide_String as defined in package Ada
8220 elsif Base_Typ
= Standard_Wide_Wide_String
then
8222 -- Case of No_Stream_Optimizations restriction active
8224 if Restriction_Active
(No_Stream_Optimizations
) then
8225 if Nam
= TSS_Stream_Input
8226 and then Is_Available
(RE_Wide_Wide_String_Input
)
8228 return RTE
(RE_Wide_Wide_String_Input
);
8230 elsif Nam
= TSS_Stream_Output
8231 and then Is_Available
(RE_Wide_Wide_String_Output
)
8233 return RTE
(RE_Wide_Wide_String_Output
);
8235 elsif Nam
= TSS_Stream_Read
8236 and then Is_Available
(RE_Wide_Wide_String_Read
)
8238 return RTE
(RE_Wide_Wide_String_Read
);
8240 elsif Nam
= TSS_Stream_Write
8241 and then Is_Available
(RE_Wide_Wide_String_Write
)
8243 return RTE
(RE_Wide_Wide_String_Write
);
8245 elsif Nam
/= TSS_Stream_Input
and then
8246 Nam
/= TSS_Stream_Output
and then
8247 Nam
/= TSS_Stream_Read
and then
8248 Nam
/= TSS_Stream_Write
8250 raise Program_Error
;
8253 -- Restriction No_Stream_Optimizations is not set, so we can go
8254 -- ahead and optimize using the block IO forms of the routines.
8257 if Nam
= TSS_Stream_Input
8258 and then Is_Available
(RE_Wide_Wide_String_Input_Blk_IO
)
8260 return RTE
(RE_Wide_Wide_String_Input_Blk_IO
);
8262 elsif Nam
= TSS_Stream_Output
8263 and then Is_Available
(RE_Wide_Wide_String_Output_Blk_IO
)
8265 return RTE
(RE_Wide_Wide_String_Output_Blk_IO
);
8267 elsif Nam
= TSS_Stream_Read
8268 and then Is_Available
(RE_Wide_Wide_String_Read_Blk_IO
)
8270 return RTE
(RE_Wide_Wide_String_Read_Blk_IO
);
8272 elsif Nam
= TSS_Stream_Write
8273 and then Is_Available
(RE_Wide_Wide_String_Write_Blk_IO
)
8275 return RTE
(RE_Wide_Wide_String_Write_Blk_IO
);
8277 elsif Nam
/= TSS_Stream_Input
and then
8278 Nam
/= TSS_Stream_Output
and then
8279 Nam
/= TSS_Stream_Read
and then
8280 Nam
/= TSS_Stream_Write
8282 raise Program_Error
;
8288 if Is_Tagged_Type
(Typ
) and then Is_Derived_Type
(Typ
) then
8289 return Find_Prim_Op
(Typ
, Nam
);
8291 return Find_Inherited_TSS
(Typ
, Nam
);
8293 end Find_Stream_Subprogram
;
8299 function Full_Base
(T
: Entity_Id
) return Entity_Id
is
8303 BT
:= Base_Type
(T
);
8305 if Is_Private_Type
(BT
)
8306 and then Present
(Full_View
(BT
))
8308 BT
:= Full_View
(BT
);
8314 -----------------------
8315 -- Get_Index_Subtype --
8316 -----------------------
8318 function Get_Index_Subtype
(N
: Node_Id
) return Node_Id
is
8319 P_Type
: Entity_Id
:= Etype
(Prefix
(N
));
8324 if Is_Access_Type
(P_Type
) then
8325 P_Type
:= Designated_Type
(P_Type
);
8328 if No
(Expressions
(N
)) then
8331 J
:= UI_To_Int
(Expr_Value
(First
(Expressions
(N
))));
8334 Indx
:= First_Index
(P_Type
);
8340 return Etype
(Indx
);
8341 end Get_Index_Subtype
;
8343 -------------------------------
8344 -- Get_Stream_Convert_Pragma --
8345 -------------------------------
8347 function Get_Stream_Convert_Pragma
(T
: Entity_Id
) return Node_Id
is
8352 -- Note: we cannot use Get_Rep_Pragma here because of the peculiarity
8353 -- that a stream convert pragma for a tagged type is not inherited from
8354 -- its parent. Probably what is wrong here is that it is basically
8355 -- incorrect to consider a stream convert pragma to be a representation
8356 -- pragma at all ???
8358 N
:= First_Rep_Item
(Implementation_Base_Type
(T
));
8359 while Present
(N
) loop
8360 if Nkind
(N
) = N_Pragma
8361 and then Pragma_Name
(N
) = Name_Stream_Convert
8363 -- For tagged types this pragma is not inherited, so we
8364 -- must verify that it is defined for the given type and
8368 Entity
(Expression
(First
(Pragma_Argument_Associations
(N
))));
8370 if not Is_Tagged_Type
(T
)
8372 or else (Is_Private_Type
(Typ
) and then T
= Full_View
(Typ
))
8382 end Get_Stream_Convert_Pragma
;
8384 ---------------------------------
8385 -- Is_Constrained_Packed_Array --
8386 ---------------------------------
8388 function Is_Constrained_Packed_Array
(Typ
: Entity_Id
) return Boolean is
8389 Arr
: Entity_Id
:= Typ
;
8392 if Is_Access_Type
(Arr
) then
8393 Arr
:= Designated_Type
(Arr
);
8396 return Is_Array_Type
(Arr
)
8397 and then Is_Constrained
(Arr
)
8398 and then Present
(Packed_Array_Impl_Type
(Arr
));
8399 end Is_Constrained_Packed_Array
;
8401 ----------------------------------------
8402 -- Is_Inline_Floating_Point_Attribute --
8403 ----------------------------------------
8405 function Is_Inline_Floating_Point_Attribute
(N
: Node_Id
) return Boolean is
8406 Id
: constant Attribute_Id
:= Get_Attribute_Id
(Attribute_Name
(N
));
8408 function Is_GCC_Target
return Boolean;
8409 -- Return True if we are using a GCC target/back-end
8410 -- ??? Note: the implementation is kludgy/fragile
8416 function Is_GCC_Target
return Boolean is
8418 return not CodePeer_Mode
8419 and then not Modify_Tree_For_C
;
8422 -- Start of processing for Is_Inline_Floating_Point_Attribute
8425 -- Machine and Model can be expanded by the GCC back end only
8427 if Id
= Attribute_Machine
or else Id
= Attribute_Model
then
8428 return Is_GCC_Target
;
8430 -- Remaining cases handled by all back ends are Rounding and Truncation
8431 -- when appearing as the operand of a conversion to some integer type.
8433 elsif Nkind
(Parent
(N
)) /= N_Type_Conversion
8434 or else not Is_Integer_Type
(Etype
(Parent
(N
)))
8439 -- Here we are in the integer conversion context
8441 -- Very probably we should also recognize the cases of Machine_Rounding
8442 -- and unbiased rounding in this conversion context, but the back end is
8443 -- not yet prepared to handle these cases ???
8445 return Id
= Attribute_Rounding
or else Id
= Attribute_Truncation
;
8446 end Is_Inline_Floating_Point_Attribute
;