1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2005, Free Software Foundation, Inc. --
11 -- GNAT is free software; you can redistribute it and/or modify it under --
12 -- terms of the GNU General Public License as published by the Free Soft- --
13 -- ware Foundation; either version 2, or (at your option) any later ver- --
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
16 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
17 -- for more details. You should have received a copy of the GNU General --
18 -- Public License distributed with GNAT; see file COPYING. If not, write --
19 -- to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, --
20 -- MA 02111-1307, USA. --
22 -- GNAT was originally developed by the GNAT team at New York University. --
23 -- Extensive contributions were provided by Ada Core Technologies Inc. --
25 ------------------------------------------------------------------------------
27 with Atree
; use Atree
;
28 with Checks
; use Checks
;
29 with Einfo
; use Einfo
;
30 with Elists
; use Elists
;
31 with Errout
; use Errout
;
32 with Exp_Aggr
; use Exp_Aggr
;
33 with Exp_Ch7
; use Exp_Ch7
;
34 with Exp_Ch11
; use Exp_Ch11
;
35 with Exp_Tss
; use Exp_Tss
;
36 with Hostparm
; use Hostparm
;
37 with Inline
; use Inline
;
38 with Itypes
; use Itypes
;
40 with Namet
; use Namet
;
41 with Nlists
; use Nlists
;
42 with Nmake
; use Nmake
;
44 with Restrict
; use Restrict
;
45 with Rident
; use Rident
;
47 with Sem_Ch8
; use Sem_Ch8
;
48 with Sem_Eval
; use Sem_Eval
;
49 with Sem_Res
; use Sem_Res
;
50 with Sem_Util
; use Sem_Util
;
51 with Sinfo
; use Sinfo
;
52 with Snames
; use Snames
;
53 with Stand
; use Stand
;
54 with Stringt
; use Stringt
;
55 with Targparm
; use Targparm
;
56 with Tbuild
; use Tbuild
;
57 with Ttypes
; use Ttypes
;
58 with Uintp
; use Uintp
;
59 with Urealp
; use Urealp
;
60 with Validsw
; use Validsw
;
62 package body Exp_Util
is
64 -----------------------
65 -- Local Subprograms --
66 -----------------------
68 function Build_Task_Array_Image
72 Dyn
: Boolean := False) return Node_Id
;
73 -- Build function to generate the image string for a task that is an
74 -- array component, concatenating the images of each index. To avoid
75 -- storage leaks, the string is built with successive slice assignments.
76 -- The flag Dyn indicates whether this is called for the initialization
77 -- procedure of an array of tasks, or for the name of a dynamically
78 -- created task that is assigned to an indexed component.
80 function Build_Task_Image_Function
84 Res
: Entity_Id
) return Node_Id
;
85 -- Common processing for Task_Array_Image and Task_Record_Image.
86 -- Build function body that computes image.
88 procedure Build_Task_Image_Prefix
95 Decls
: in out List_Id
;
96 Stats
: in out List_Id
);
97 -- Common processing for Task_Array_Image and Task_Record_Image.
98 -- Create local variables and assign prefix of name to result string.
100 function Build_Task_Record_Image
103 Dyn
: Boolean := False) return Node_Id
;
104 -- Build function to generate the image string for a task that is a
105 -- record component. Concatenate name of variable with that of selector.
106 -- The flag Dyn indicates whether this is called for the initialization
107 -- procedure of record with task components, or for a dynamically
108 -- created task that is assigned to a selected component.
110 function Make_CW_Equivalent_Type
112 E
: Node_Id
) return Entity_Id
;
113 -- T is a class-wide type entity, E is the initial expression node that
114 -- constrains T in case such as: " X: T := E" or "new T'(E)"
115 -- This function returns the entity of the Equivalent type and inserts
116 -- on the fly the necessary declaration such as:
118 -- type anon is record
119 -- _parent : Root_Type (T); constrained with E discriminants (if any)
120 -- Extension : String (1 .. expr to match size of E);
123 -- This record is compatible with any object of the class of T thanks
124 -- to the first field and has the same size as E thanks to the second.
126 function Make_Literal_Range
128 Literal_Typ
: Entity_Id
) return Node_Id
;
129 -- Produce a Range node whose bounds are:
130 -- Low_Bound (Literal_Type) ..
131 -- Low_Bound (Literal_Type) + Length (Literal_Typ) - 1
132 -- this is used for expanding declarations like X : String := "sdfgdfg";
134 function New_Class_Wide_Subtype
136 N
: Node_Id
) return Entity_Id
;
137 -- Create an implicit subtype of CW_Typ attached to node N
139 ----------------------
140 -- Adjust_Condition --
141 ----------------------
143 procedure Adjust_Condition
(N
: Node_Id
) is
150 Loc
: constant Source_Ptr
:= Sloc
(N
);
151 T
: constant Entity_Id
:= Etype
(N
);
155 -- For now, we simply ignore a call where the argument has no
156 -- type (probably case of unanalyzed condition), or has a type
157 -- that is not Boolean. This is because this is a pretty marginal
158 -- piece of functionality, and violations of these rules are
159 -- likely to be truly marginal (how much code uses Fortran Logical
160 -- as the barrier to a protected entry?) and we do not want to
161 -- blow up existing programs. We can change this to an assertion
162 -- after 3.12a is released ???
164 if No
(T
) or else not Is_Boolean_Type
(T
) then
168 -- Apply validity checking if needed
170 if Validity_Checks_On
and Validity_Check_Tests
then
174 -- Immediate return if standard boolean, the most common case,
175 -- where nothing needs to be done.
177 if Base_Type
(T
) = Standard_Boolean
then
181 -- Case of zero/non-zero semantics or non-standard enumeration
182 -- representation. In each case, we rewrite the node as:
184 -- ityp!(N) /= False'Enum_Rep
186 -- where ityp is an integer type with large enough size to hold
187 -- any value of type T.
189 if Nonzero_Is_True
(T
) or else Has_Non_Standard_Rep
(T
) then
190 if Esize
(T
) <= Esize
(Standard_Integer
) then
191 Ti
:= Standard_Integer
;
193 Ti
:= Standard_Long_Long_Integer
;
198 Left_Opnd
=> Unchecked_Convert_To
(Ti
, N
),
200 Make_Attribute_Reference
(Loc
,
201 Attribute_Name
=> Name_Enum_Rep
,
203 New_Occurrence_Of
(First_Literal
(T
), Loc
))));
204 Analyze_And_Resolve
(N
, Standard_Boolean
);
207 Rewrite
(N
, Convert_To
(Standard_Boolean
, N
));
208 Analyze_And_Resolve
(N
, Standard_Boolean
);
211 end Adjust_Condition
;
213 ------------------------
214 -- Adjust_Result_Type --
215 ------------------------
217 procedure Adjust_Result_Type
(N
: Node_Id
; T
: Entity_Id
) is
219 -- Ignore call if current type is not Standard.Boolean
221 if Etype
(N
) /= Standard_Boolean
then
225 -- If result is already of correct type, nothing to do. Note that
226 -- this will get the most common case where everything has a type
227 -- of Standard.Boolean.
229 if Base_Type
(T
) = Standard_Boolean
then
234 KP
: constant Node_Kind
:= Nkind
(Parent
(N
));
237 -- If result is to be used as a Condition in the syntax, no need
238 -- to convert it back, since if it was changed to Standard.Boolean
239 -- using Adjust_Condition, that is just fine for this usage.
241 if KP
in N_Raise_xxx_Error
or else KP
in N_Has_Condition
then
244 -- If result is an operand of another logical operation, no need
245 -- to reset its type, since Standard.Boolean is just fine, and
246 -- such operations always do Adjust_Condition on their operands.
248 elsif KP
in N_Op_Boolean
249 or else KP
= N_And_Then
250 or else KP
= N_Or_Else
251 or else KP
= N_Op_Not
255 -- Otherwise we perform a conversion from the current type,
256 -- which must be Standard.Boolean, to the desired type.
260 Rewrite
(N
, Convert_To
(T
, N
));
261 Analyze_And_Resolve
(N
, T
);
265 end Adjust_Result_Type
;
267 --------------------------
268 -- Append_Freeze_Action --
269 --------------------------
271 procedure Append_Freeze_Action
(T
: Entity_Id
; N
: Node_Id
) is
272 Fnode
: Node_Id
:= Freeze_Node
(T
);
275 Ensure_Freeze_Node
(T
);
276 Fnode
:= Freeze_Node
(T
);
278 if not Present
(Actions
(Fnode
)) then
279 Set_Actions
(Fnode
, New_List
);
282 Append
(N
, Actions
(Fnode
));
283 end Append_Freeze_Action
;
285 ---------------------------
286 -- Append_Freeze_Actions --
287 ---------------------------
289 procedure Append_Freeze_Actions
(T
: Entity_Id
; L
: List_Id
) is
290 Fnode
: constant Node_Id
:= Freeze_Node
(T
);
297 if No
(Actions
(Fnode
)) then
298 Set_Actions
(Fnode
, L
);
301 Append_List
(L
, Actions
(Fnode
));
305 end Append_Freeze_Actions
;
307 ------------------------
308 -- Build_Runtime_Call --
309 ------------------------
311 function Build_Runtime_Call
(Loc
: Source_Ptr
; RE
: RE_Id
) return Node_Id
is
313 -- If entity is not available, we can skip making the call (this avoids
314 -- junk duplicated error messages in a number of cases).
316 if not RTE_Available
(RE
) then
317 return Make_Null_Statement
(Loc
);
320 Make_Procedure_Call_Statement
(Loc
,
321 Name
=> New_Reference_To
(RTE
(RE
), Loc
));
323 end Build_Runtime_Call
;
325 ----------------------------
326 -- Build_Task_Array_Image --
327 ----------------------------
329 -- This function generates the body for a function that constructs the
330 -- image string for a task that is an array component. The function is
331 -- local to the init proc for the array type, and is called for each one
332 -- of the components. The constructed image has the form of an indexed
333 -- component, whose prefix is the outer variable of the array type.
334 -- The n-dimensional array type has known indices Index, Index2...
335 -- Id_Ref is an indexed component form created by the enclosing init proc.
336 -- Its successive indices are Val1, Val2,.. which are the loop variables
337 -- in the loops that call the individual task init proc on each component.
339 -- The generated function has the following structure:
341 -- function F return String is
342 -- Pref : string renames Task_Name;
343 -- T1 : String := Index1'Image (Val1);
345 -- Tn : String := indexn'image (Valn);
346 -- Len : Integer := T1'Length + ... + Tn'Length + n + 1;
347 -- -- Len includes commas and the end parentheses.
348 -- Res : String (1..Len);
349 -- Pos : Integer := Pref'Length;
352 -- Res (1 .. Pos) := Pref;
356 -- Res (Pos .. Pos + T1'Length - 1) := T1;
357 -- Pos := Pos + T1'Length;
361 -- Res (Pos .. Pos + Tn'Length - 1) := Tn;
367 -- Needless to say, multidimensional arrays of tasks are rare enough
368 -- that the bulkiness of this code is not really a concern.
370 function Build_Task_Array_Image
374 Dyn
: Boolean := False) return Node_Id
376 Dims
: constant Nat
:= Number_Dimensions
(A_Type
);
377 -- Number of dimensions for array of tasks
379 Temps
: array (1 .. Dims
) of Entity_Id
;
380 -- Array of temporaries to hold string for each index
386 -- Total length of generated name
389 -- Running index for substring assignments
392 -- Name of enclosing variable, prefix of resulting name
395 -- String to hold result
398 -- Value of successive indices
401 -- Expression to compute total size of string
404 -- Entity for name at one index position
406 Decls
: List_Id
:= New_List
;
407 Stats
: List_Id
:= New_List
;
410 Pref
:= Make_Defining_Identifier
(Loc
, New_Internal_Name
('P'));
412 -- For a dynamic task, the name comes from the target variable.
413 -- For a static one it is a formal of the enclosing init proc.
416 Get_Name_String
(Chars
(Entity
(Prefix
(Id_Ref
))));
418 Make_Object_Declaration
(Loc
,
419 Defining_Identifier
=> Pref
,
420 Object_Definition
=> New_Occurrence_Of
(Standard_String
, Loc
),
422 Make_String_Literal
(Loc
,
423 Strval
=> String_From_Name_Buffer
)));
427 Make_Object_Renaming_Declaration
(Loc
,
428 Defining_Identifier
=> Pref
,
429 Subtype_Mark
=> New_Occurrence_Of
(Standard_String
, Loc
),
430 Name
=> Make_Identifier
(Loc
, Name_uTask_Name
)));
433 Indx
:= First_Index
(A_Type
);
434 Val
:= First
(Expressions
(Id_Ref
));
436 for J
in 1 .. Dims
loop
437 T
:= Make_Defining_Identifier
(Loc
, New_Internal_Name
('T'));
441 Make_Object_Declaration
(Loc
,
442 Defining_Identifier
=> T
,
443 Object_Definition
=> New_Occurrence_Of
(Standard_String
, Loc
),
445 Make_Attribute_Reference
(Loc
,
446 Attribute_Name
=> Name_Image
,
448 New_Occurrence_Of
(Etype
(Indx
), Loc
),
449 Expressions
=> New_List
(
450 New_Copy_Tree
(Val
)))));
456 Sum
:= Make_Integer_Literal
(Loc
, Dims
+ 1);
462 Make_Attribute_Reference
(Loc
,
463 Attribute_Name
=> Name_Length
,
465 New_Occurrence_Of
(Pref
, Loc
),
466 Expressions
=> New_List
(Make_Integer_Literal
(Loc
, 1))));
468 for J
in 1 .. Dims
loop
473 Make_Attribute_Reference
(Loc
,
474 Attribute_Name
=> Name_Length
,
476 New_Occurrence_Of
(Temps
(J
), Loc
),
477 Expressions
=> New_List
(Make_Integer_Literal
(Loc
, 1))));
480 Build_Task_Image_Prefix
(Loc
, Len
, Res
, Pos
, Pref
, Sum
, Decls
, Stats
);
482 Set_Character_Literal_Name
(Char_Code
(Character'Pos ('(')));
485 Make_Assignment_Statement
(Loc
,
486 Name
=> Make_Indexed_Component
(Loc
,
487 Prefix
=> New_Occurrence_Of
(Res
, Loc
),
488 Expressions
=> New_List
(New_Occurrence_Of
(Pos
, Loc
))),
490 Make_Character_Literal
(Loc
,
492 Char_Literal_Value
=>
493 UI_From_Int
(Character'Pos ('(')))));
496 Make_Assignment_Statement
(Loc
,
497 Name
=> New_Occurrence_Of
(Pos
, Loc
),
500 Left_Opnd
=> New_Occurrence_Of
(Pos
, Loc
),
501 Right_Opnd
=> Make_Integer_Literal
(Loc
, 1))));
503 for J
in 1 .. Dims
loop
506 Make_Assignment_Statement
(Loc
,
507 Name
=> Make_Slice
(Loc
,
508 Prefix
=> New_Occurrence_Of
(Res
, Loc
),
511 Low_Bound
=> New_Occurrence_Of
(Pos
, Loc
),
512 High_Bound
=> Make_Op_Subtract
(Loc
,
515 Left_Opnd
=> New_Occurrence_Of
(Pos
, Loc
),
517 Make_Attribute_Reference
(Loc
,
518 Attribute_Name
=> Name_Length
,
520 New_Occurrence_Of
(Temps
(J
), Loc
),
522 New_List
(Make_Integer_Literal
(Loc
, 1)))),
523 Right_Opnd
=> Make_Integer_Literal
(Loc
, 1)))),
525 Expression
=> New_Occurrence_Of
(Temps
(J
), Loc
)));
529 Make_Assignment_Statement
(Loc
,
530 Name
=> New_Occurrence_Of
(Pos
, Loc
),
533 Left_Opnd
=> New_Occurrence_Of
(Pos
, Loc
),
535 Make_Attribute_Reference
(Loc
,
536 Attribute_Name
=> Name_Length
,
537 Prefix
=> New_Occurrence_Of
(Temps
(J
), Loc
),
539 New_List
(Make_Integer_Literal
(Loc
, 1))))));
541 Set_Character_Literal_Name
(Char_Code
(Character'Pos (',')));
544 Make_Assignment_Statement
(Loc
,
545 Name
=> Make_Indexed_Component
(Loc
,
546 Prefix
=> New_Occurrence_Of
(Res
, Loc
),
547 Expressions
=> New_List
(New_Occurrence_Of
(Pos
, Loc
))),
549 Make_Character_Literal
(Loc
,
551 Char_Literal_Value
=>
552 UI_From_Int
(Character'Pos (',')))));
555 Make_Assignment_Statement
(Loc
,
556 Name
=> New_Occurrence_Of
(Pos
, Loc
),
559 Left_Opnd
=> New_Occurrence_Of
(Pos
, Loc
),
560 Right_Opnd
=> Make_Integer_Literal
(Loc
, 1))));
564 Set_Character_Literal_Name
(Char_Code
(Character'Pos (')')));
567 Make_Assignment_Statement
(Loc
,
568 Name
=> Make_Indexed_Component
(Loc
,
569 Prefix
=> New_Occurrence_Of
(Res
, Loc
),
570 Expressions
=> New_List
(New_Occurrence_Of
(Len
, Loc
))),
572 Make_Character_Literal
(Loc
,
574 Char_Literal_Value
=>
575 UI_From_Int
(Character'Pos (')')))));
576 return Build_Task_Image_Function
(Loc
, Decls
, Stats
, Res
);
577 end Build_Task_Array_Image
;
579 ----------------------------
580 -- Build_Task_Image_Decls --
581 ----------------------------
583 function Build_Task_Image_Decls
586 A_Type
: Entity_Id
) return List_Id
588 Decls
: constant List_Id
:= New_List
;
589 T_Id
: Entity_Id
:= Empty
;
591 Expr
: Node_Id
:= Empty
;
592 Fun
: Node_Id
:= Empty
;
593 Is_Dyn
: constant Boolean :=
594 Nkind
(Parent
(Id_Ref
)) = N_Assignment_Statement
596 Nkind
(Expression
(Parent
(Id_Ref
))) = N_Allocator
;
599 -- If Discard_Names or No_Implicit_Heap_Allocations are in effect,
600 -- generate a dummy declaration only.
602 if Restriction_Active
(No_Implicit_Heap_Allocations
)
603 or else Global_Discard_Names
605 T_Id
:= Make_Defining_Identifier
(Loc
, New_Internal_Name
('J'));
610 Make_Object_Declaration
(Loc
,
611 Defining_Identifier
=> T_Id
,
612 Object_Definition
=> New_Occurrence_Of
(Standard_String
, Loc
),
614 Make_String_Literal
(Loc
,
615 Strval
=> String_From_Name_Buffer
)));
618 if Nkind
(Id_Ref
) = N_Identifier
619 or else Nkind
(Id_Ref
) = N_Defining_Identifier
621 -- For a simple variable, the image of the task is built from
622 -- the name of the variable. To avoid possible conflict with
623 -- the anonymous type created for a single protected object,
624 -- add a numeric suffix.
627 Make_Defining_Identifier
(Loc
,
628 New_External_Name
(Chars
(Id_Ref
), 'T', 1));
630 Get_Name_String
(Chars
(Id_Ref
));
633 Make_String_Literal
(Loc
,
634 Strval
=> String_From_Name_Buffer
);
636 elsif Nkind
(Id_Ref
) = N_Selected_Component
then
638 Make_Defining_Identifier
(Loc
,
639 New_External_Name
(Chars
(Selector_Name
(Id_Ref
)), 'T'));
640 Fun
:= Build_Task_Record_Image
(Loc
, Id_Ref
, Is_Dyn
);
642 elsif Nkind
(Id_Ref
) = N_Indexed_Component
then
644 Make_Defining_Identifier
(Loc
,
645 New_External_Name
(Chars
(A_Type
), 'N'));
647 Fun
:= Build_Task_Array_Image
(Loc
, Id_Ref
, A_Type
, Is_Dyn
);
651 if Present
(Fun
) then
653 Expr
:= Make_Function_Call
(Loc
,
654 Name
=> New_Occurrence_Of
(Defining_Entity
(Fun
), Loc
));
657 Decl
:= Make_Object_Declaration
(Loc
,
658 Defining_Identifier
=> T_Id
,
659 Object_Definition
=> New_Occurrence_Of
(Standard_String
, Loc
),
660 Constant_Present
=> True,
663 Append
(Decl
, Decls
);
665 end Build_Task_Image_Decls
;
667 -------------------------------
668 -- Build_Task_Image_Function --
669 -------------------------------
671 function Build_Task_Image_Function
675 Res
: Entity_Id
) return Node_Id
681 Make_Return_Statement
(Loc
,
682 Expression
=> New_Occurrence_Of
(Res
, Loc
)));
684 Spec
:= Make_Function_Specification
(Loc
,
685 Defining_Unit_Name
=>
686 Make_Defining_Identifier
(Loc
, New_Internal_Name
('F')),
687 Subtype_Mark
=> New_Occurrence_Of
(Standard_String
, Loc
));
689 -- Calls to 'Image use the secondary stack, which must be cleaned
690 -- up after the task name is built.
692 Set_Uses_Sec_Stack
(Defining_Unit_Name
(Spec
));
694 return Make_Subprogram_Body
(Loc
,
695 Specification
=> Spec
,
696 Declarations
=> Decls
,
697 Handled_Statement_Sequence
=>
698 Make_Handled_Sequence_Of_Statements
(Loc
, Statements
=> Stats
));
699 end Build_Task_Image_Function
;
701 -----------------------------
702 -- Build_Task_Image_Prefix --
703 -----------------------------
705 procedure Build_Task_Image_Prefix
712 Decls
: in out List_Id
;
713 Stats
: in out List_Id
)
716 Len
:= Make_Defining_Identifier
(Loc
, New_Internal_Name
('L'));
719 Make_Object_Declaration
(Loc
,
720 Defining_Identifier
=> Len
,
721 Object_Definition
=> New_Occurrence_Of
(Standard_Integer
, Loc
),
724 Res
:= Make_Defining_Identifier
(Loc
, New_Internal_Name
('R'));
727 Make_Object_Declaration
(Loc
,
728 Defining_Identifier
=> Res
,
730 Make_Subtype_Indication
(Loc
,
731 Subtype_Mark
=> New_Occurrence_Of
(Standard_String
, Loc
),
733 Make_Index_Or_Discriminant_Constraint
(Loc
,
737 Low_Bound
=> Make_Integer_Literal
(Loc
, 1),
738 High_Bound
=> New_Occurrence_Of
(Len
, Loc
)))))));
740 Pos
:= Make_Defining_Identifier
(Loc
, New_Internal_Name
('P'));
743 Make_Object_Declaration
(Loc
,
744 Defining_Identifier
=> Pos
,
745 Object_Definition
=> New_Occurrence_Of
(Standard_Integer
, Loc
)));
747 -- Pos := Prefix'Length;
750 Make_Assignment_Statement
(Loc
,
751 Name
=> New_Occurrence_Of
(Pos
, Loc
),
753 Make_Attribute_Reference
(Loc
,
754 Attribute_Name
=> Name_Length
,
755 Prefix
=> New_Occurrence_Of
(Prefix
, Loc
),
757 New_List
(Make_Integer_Literal
(Loc
, 1)))));
759 -- Res (1 .. Pos) := Prefix;
762 Make_Assignment_Statement
(Loc
,
763 Name
=> Make_Slice
(Loc
,
764 Prefix
=> New_Occurrence_Of
(Res
, Loc
),
767 Low_Bound
=> Make_Integer_Literal
(Loc
, 1),
768 High_Bound
=> New_Occurrence_Of
(Pos
, Loc
))),
770 Expression
=> New_Occurrence_Of
(Prefix
, Loc
)));
773 Make_Assignment_Statement
(Loc
,
774 Name
=> New_Occurrence_Of
(Pos
, Loc
),
777 Left_Opnd
=> New_Occurrence_Of
(Pos
, Loc
),
778 Right_Opnd
=> Make_Integer_Literal
(Loc
, 1))));
779 end Build_Task_Image_Prefix
;
781 -----------------------------
782 -- Build_Task_Record_Image --
783 -----------------------------
785 function Build_Task_Record_Image
788 Dyn
: Boolean := False) return Node_Id
791 -- Total length of generated name
797 -- String to hold result
800 -- Name of enclosing variable, prefix of resulting name
803 -- Expression to compute total size of string
806 -- Entity for selector name
808 Decls
: List_Id
:= New_List
;
809 Stats
: List_Id
:= New_List
;
812 Pref
:= Make_Defining_Identifier
(Loc
, New_Internal_Name
('P'));
814 -- For a dynamic task, the name comes from the target variable.
815 -- For a static one it is a formal of the enclosing init proc.
818 Get_Name_String
(Chars
(Entity
(Prefix
(Id_Ref
))));
820 Make_Object_Declaration
(Loc
,
821 Defining_Identifier
=> Pref
,
822 Object_Definition
=> New_Occurrence_Of
(Standard_String
, Loc
),
824 Make_String_Literal
(Loc
,
825 Strval
=> String_From_Name_Buffer
)));
829 Make_Object_Renaming_Declaration
(Loc
,
830 Defining_Identifier
=> Pref
,
831 Subtype_Mark
=> New_Occurrence_Of
(Standard_String
, Loc
),
832 Name
=> Make_Identifier
(Loc
, Name_uTask_Name
)));
835 Sel
:= Make_Defining_Identifier
(Loc
, New_Internal_Name
('S'));
837 Get_Name_String
(Chars
(Selector_Name
(Id_Ref
)));
840 Make_Object_Declaration
(Loc
,
841 Defining_Identifier
=> Sel
,
842 Object_Definition
=> New_Occurrence_Of
(Standard_String
, Loc
),
844 Make_String_Literal
(Loc
,
845 Strval
=> String_From_Name_Buffer
)));
847 Sum
:= Make_Integer_Literal
(Loc
, Nat
(Name_Len
+ 1));
853 Make_Attribute_Reference
(Loc
,
854 Attribute_Name
=> Name_Length
,
856 New_Occurrence_Of
(Pref
, Loc
),
857 Expressions
=> New_List
(Make_Integer_Literal
(Loc
, 1))));
859 Build_Task_Image_Prefix
(Loc
, Len
, Res
, Pos
, Pref
, Sum
, Decls
, Stats
);
861 Set_Character_Literal_Name
(Char_Code
(Character'Pos ('.')));
866 Make_Assignment_Statement
(Loc
,
867 Name
=> Make_Indexed_Component
(Loc
,
868 Prefix
=> New_Occurrence_Of
(Res
, Loc
),
869 Expressions
=> New_List
(New_Occurrence_Of
(Pos
, Loc
))),
871 Make_Character_Literal
(Loc
,
873 Char_Literal_Value
=>
874 UI_From_Int
(Character'Pos ('.')))));
877 Make_Assignment_Statement
(Loc
,
878 Name
=> New_Occurrence_Of
(Pos
, Loc
),
881 Left_Opnd
=> New_Occurrence_Of
(Pos
, Loc
),
882 Right_Opnd
=> Make_Integer_Literal
(Loc
, 1))));
884 -- Res (Pos .. Len) := Selector;
887 Make_Assignment_Statement
(Loc
,
888 Name
=> Make_Slice
(Loc
,
889 Prefix
=> New_Occurrence_Of
(Res
, Loc
),
892 Low_Bound
=> New_Occurrence_Of
(Pos
, Loc
),
893 High_Bound
=> New_Occurrence_Of
(Len
, Loc
))),
894 Expression
=> New_Occurrence_Of
(Sel
, Loc
)));
896 return Build_Task_Image_Function
(Loc
, Decls
, Stats
, Res
);
897 end Build_Task_Record_Image
;
899 ----------------------------------
900 -- Component_May_Be_Bit_Aligned --
901 ----------------------------------
903 function Component_May_Be_Bit_Aligned
(Comp
: Entity_Id
) return Boolean is
905 -- If no component clause, then everything is fine, since the
906 -- back end never bit-misaligns by default, even if there is
907 -- a pragma Packed for the record.
909 if No
(Component_Clause
(Comp
)) then
913 -- It is only array and record types that cause trouble
915 if not Is_Record_Type
(Etype
(Comp
))
916 and then not Is_Array_Type
(Etype
(Comp
))
920 -- If we know that we have a small (64 bits or less) record
921 -- or bit-packed array, then everything is fine, since the
922 -- back end can handle these cases correctly.
924 elsif Esize
(Comp
) <= 64
925 and then (Is_Record_Type
(Etype
(Comp
))
926 or else Is_Bit_Packed_Array
(Etype
(Comp
)))
930 -- Otherwise if the component is not byte aligned, we
931 -- know we have the nasty unaligned case.
933 elsif Normalized_First_Bit
(Comp
) /= Uint_0
934 or else Esize
(Comp
) mod System_Storage_Unit
/= Uint_0
938 -- If we are large and byte aligned, then OK at this level
943 end Component_May_Be_Bit_Aligned
;
945 -------------------------------
946 -- Convert_To_Actual_Subtype --
947 -------------------------------
949 procedure Convert_To_Actual_Subtype
(Exp
: Entity_Id
) is
953 Act_ST
:= Get_Actual_Subtype
(Exp
);
955 if Act_ST
= Etype
(Exp
) then
960 Convert_To
(Act_ST
, Relocate_Node
(Exp
)));
961 Analyze_And_Resolve
(Exp
, Act_ST
);
963 end Convert_To_Actual_Subtype
;
965 -----------------------------------
966 -- Current_Sem_Unit_Declarations --
967 -----------------------------------
969 function Current_Sem_Unit_Declarations
return List_Id
is
970 U
: Node_Id
:= Unit
(Cunit
(Current_Sem_Unit
));
974 -- If the current unit is a package body, locate the visible
975 -- declarations of the package spec.
977 if Nkind
(U
) = N_Package_Body
then
978 U
:= Unit
(Library_Unit
(Cunit
(Current_Sem_Unit
)));
981 if Nkind
(U
) = N_Package_Declaration
then
982 U
:= Specification
(U
);
983 Decls
:= Visible_Declarations
(U
);
987 Set_Visible_Declarations
(U
, Decls
);
991 Decls
:= Declarations
(U
);
995 Set_Declarations
(U
, Decls
);
1000 end Current_Sem_Unit_Declarations
;
1002 -----------------------
1003 -- Duplicate_Subexpr --
1004 -----------------------
1006 function Duplicate_Subexpr
1008 Name_Req
: Boolean := False) return Node_Id
1011 Remove_Side_Effects
(Exp
, Name_Req
);
1012 return New_Copy_Tree
(Exp
);
1013 end Duplicate_Subexpr
;
1015 ---------------------------------
1016 -- Duplicate_Subexpr_No_Checks --
1017 ---------------------------------
1019 function Duplicate_Subexpr_No_Checks
1021 Name_Req
: Boolean := False) return Node_Id
1026 Remove_Side_Effects
(Exp
, Name_Req
);
1027 New_Exp
:= New_Copy_Tree
(Exp
);
1028 Remove_Checks
(New_Exp
);
1030 end Duplicate_Subexpr_No_Checks
;
1032 -----------------------------------
1033 -- Duplicate_Subexpr_Move_Checks --
1034 -----------------------------------
1036 function Duplicate_Subexpr_Move_Checks
1038 Name_Req
: Boolean := False) return Node_Id
1043 Remove_Side_Effects
(Exp
, Name_Req
);
1044 New_Exp
:= New_Copy_Tree
(Exp
);
1045 Remove_Checks
(Exp
);
1047 end Duplicate_Subexpr_Move_Checks
;
1049 --------------------
1050 -- Ensure_Defined --
1051 --------------------
1053 procedure Ensure_Defined
(Typ
: Entity_Id
; N
: Node_Id
) is
1058 if Is_Itype
(Typ
) then
1059 IR
:= Make_Itype_Reference
(Sloc
(N
));
1060 Set_Itype
(IR
, Typ
);
1062 if not In_Open_Scopes
(Scope
(Typ
))
1063 and then Is_Subprogram
(Current_Scope
)
1064 and then Scope
(Current_Scope
) /= Standard_Standard
1066 -- Insert node in front of subprogram, to avoid scope anomalies
1071 and then Nkind
(P
) /= N_Subprogram_Body
1077 Insert_Action
(P
, IR
);
1079 Insert_Action
(N
, IR
);
1083 Insert_Action
(N
, IR
);
1088 ---------------------
1089 -- Evolve_And_Then --
1090 ---------------------
1092 procedure Evolve_And_Then
(Cond
: in out Node_Id
; Cond1
: Node_Id
) is
1098 Make_And_Then
(Sloc
(Cond1
),
1100 Right_Opnd
=> Cond1
);
1102 end Evolve_And_Then
;
1104 --------------------
1105 -- Evolve_Or_Else --
1106 --------------------
1108 procedure Evolve_Or_Else
(Cond
: in out Node_Id
; Cond1
: Node_Id
) is
1114 Make_Or_Else
(Sloc
(Cond1
),
1116 Right_Opnd
=> Cond1
);
1120 ------------------------------
1121 -- Expand_Subtype_From_Expr --
1122 ------------------------------
1124 -- This function is applicable for both static and dynamic allocation of
1125 -- objects which are constrained by an initial expression. Basically it
1126 -- transforms an unconstrained subtype indication into a constrained one.
1127 -- The expression may also be transformed in certain cases in order to
1128 -- avoid multiple evaulation. In the static allocation case, the general
1133 -- is transformed into
1135 -- Val : Constrained_Subtype_of_T := Maybe_Modified_Expr;
1137 -- Here are the main cases :
1139 -- <if Expr is a Slice>
1140 -- Val : T ([Index_Subtype (Expr)]) := Expr;
1142 -- <elsif Expr is a String Literal>
1143 -- Val : T (T'First .. T'First + Length (string literal) - 1) := Expr;
1145 -- <elsif Expr is Constrained>
1146 -- subtype T is Type_Of_Expr
1149 -- <elsif Expr is an entity_name>
1150 -- Val : T (constraints taken from Expr) := Expr;
1153 -- type Axxx is access all T;
1154 -- Rval : Axxx := Expr'ref;
1155 -- Val : T (constraints taken from Rval) := Rval.all;
1157 -- ??? note: when the Expression is allocated in the secondary stack
1158 -- we could use it directly instead of copying it by declaring
1159 -- Val : T (...) renames Rval.all
1161 procedure Expand_Subtype_From_Expr
1163 Unc_Type
: Entity_Id
;
1164 Subtype_Indic
: Node_Id
;
1167 Loc
: constant Source_Ptr
:= Sloc
(N
);
1168 Exp_Typ
: constant Entity_Id
:= Etype
(Exp
);
1172 -- In general we cannot build the subtype if expansion is disabled,
1173 -- because internal entities may not have been defined. However, to
1174 -- avoid some cascaded errors, we try to continue when the expression
1175 -- is an array (or string), because it is safe to compute the bounds.
1176 -- It is in fact required to do so even in a generic context, because
1177 -- there may be constants that depend on bounds of string literal.
1179 if not Expander_Active
1180 and then (No
(Etype
(Exp
))
1181 or else Base_Type
(Etype
(Exp
)) /= Standard_String
)
1186 if Nkind
(Exp
) = N_Slice
then
1188 Slice_Type
: constant Entity_Id
:= Etype
(First_Index
(Exp_Typ
));
1191 Rewrite
(Subtype_Indic
,
1192 Make_Subtype_Indication
(Loc
,
1193 Subtype_Mark
=> New_Reference_To
(Unc_Type
, Loc
),
1195 Make_Index_Or_Discriminant_Constraint
(Loc
,
1196 Constraints
=> New_List
1197 (New_Reference_To
(Slice_Type
, Loc
)))));
1199 -- This subtype indication may be used later for contraint checks
1200 -- we better make sure that if a variable was used as a bound of
1201 -- of the original slice, its value is frozen.
1203 Force_Evaluation
(Low_Bound
(Scalar_Range
(Slice_Type
)));
1204 Force_Evaluation
(High_Bound
(Scalar_Range
(Slice_Type
)));
1207 elsif Ekind
(Exp_Typ
) = E_String_Literal_Subtype
then
1208 Rewrite
(Subtype_Indic
,
1209 Make_Subtype_Indication
(Loc
,
1210 Subtype_Mark
=> New_Reference_To
(Unc_Type
, Loc
),
1212 Make_Index_Or_Discriminant_Constraint
(Loc
,
1213 Constraints
=> New_List
(
1214 Make_Literal_Range
(Loc
,
1215 Literal_Typ
=> Exp_Typ
)))));
1217 elsif Is_Constrained
(Exp_Typ
)
1218 and then not Is_Class_Wide_Type
(Unc_Type
)
1220 if Is_Itype
(Exp_Typ
) then
1222 -- No need to generate a new one
1228 Make_Defining_Identifier
(Loc
,
1229 Chars
=> New_Internal_Name
('T'));
1232 Make_Subtype_Declaration
(Loc
,
1233 Defining_Identifier
=> T
,
1234 Subtype_Indication
=> New_Reference_To
(Exp_Typ
, Loc
)));
1236 -- This type is marked as an itype even though it has an
1237 -- explicit declaration because otherwise it can be marked
1238 -- with Is_Generic_Actual_Type and generate spurious errors.
1239 -- (see sem_ch8.Analyze_Package_Renaming and sem_type.covers)
1242 Set_Associated_Node_For_Itype
(T
, Exp
);
1245 Rewrite
(Subtype_Indic
, New_Reference_To
(T
, Loc
));
1247 -- nothing needs to be done for private types with unknown discriminants
1248 -- if the underlying type is not an unconstrained composite type.
1250 elsif Is_Private_Type
(Unc_Type
)
1251 and then Has_Unknown_Discriminants
(Unc_Type
)
1252 and then (not Is_Composite_Type
(Underlying_Type
(Unc_Type
))
1253 or else Is_Constrained
(Underlying_Type
(Unc_Type
)))
1258 Remove_Side_Effects
(Exp
);
1259 Rewrite
(Subtype_Indic
,
1260 Make_Subtype_From_Expr
(Exp
, Unc_Type
));
1262 end Expand_Subtype_From_Expr
;
1268 function Find_Prim_Op
(T
: Entity_Id
; Name
: Name_Id
) return Entity_Id
is
1270 Typ
: Entity_Id
:= T
;
1273 if Is_Class_Wide_Type
(Typ
) then
1274 Typ
:= Root_Type
(Typ
);
1277 Typ
:= Underlying_Type
(Typ
);
1279 Prim
:= First_Elmt
(Primitive_Operations
(Typ
));
1280 while Chars
(Node
(Prim
)) /= Name
loop
1282 pragma Assert
(Present
(Prim
));
1288 function Find_Prim_Op
1290 Name
: TSS_Name_Type
) return Entity_Id
1293 Typ
: Entity_Id
:= T
;
1296 if Is_Class_Wide_Type
(Typ
) then
1297 Typ
:= Root_Type
(Typ
);
1300 Typ
:= Underlying_Type
(Typ
);
1302 Prim
:= First_Elmt
(Primitive_Operations
(Typ
));
1303 while not Is_TSS
(Node
(Prim
), Name
) loop
1305 pragma Assert
(Present
(Prim
));
1311 ----------------------
1312 -- Force_Evaluation --
1313 ----------------------
1315 procedure Force_Evaluation
(Exp
: Node_Id
; Name_Req
: Boolean := False) is
1316 Component_In_Lhs
: Boolean := False;
1320 -- Loop to determine whether there is a component reference in
1321 -- the left hand side if Exp appears on the left side of an
1322 -- assignment statement. Needed to determine if form of result
1323 -- must be a variable.
1328 (Nkind
(Par
) = N_Selected_Component
1330 Nkind
(Par
) = N_Indexed_Component
)
1332 if Nkind
(Parent
(Par
)) = N_Assignment_Statement
1333 and then Par
= Name
(Parent
(Par
))
1335 Component_In_Lhs
:= True;
1338 Par
:= Parent
(Par
);
1342 -- If the expression is a selected component, it is being evaluated
1343 -- as part of a discriminant check. If it is part of a left-hand
1344 -- side, this is the last use of its value and it is safe to create
1345 -- a renaming for it, rather than a temporary. In addition, if it
1346 -- is not an addressable field, creating a temporary may be a problem
1347 -- for gigi, or might drop the value of the assignment. Therefore,
1348 -- if the expression is on the lhs of an assignment, remove side
1349 -- effects without requiring a temporary, and create a renaming.
1350 -- (See remove_side_effects for details).
1353 (Exp
, Name_Req
, Variable_Ref
=> not Component_In_Lhs
);
1354 end Force_Evaluation
;
1356 ------------------------
1357 -- Generate_Poll_Call --
1358 ------------------------
1360 procedure Generate_Poll_Call
(N
: Node_Id
) is
1362 -- No poll call if polling not active
1364 if not Polling_Required
then
1367 -- Otherwise generate require poll call
1370 Insert_Before_And_Analyze
(N
,
1371 Make_Procedure_Call_Statement
(Sloc
(N
),
1372 Name
=> New_Occurrence_Of
(RTE
(RE_Poll
), Sloc
(N
))));
1374 end Generate_Poll_Call
;
1376 ---------------------------------
1377 -- Get_Current_Value_Condition --
1378 ---------------------------------
1380 procedure Get_Current_Value_Condition
1385 Loc
: constant Source_Ptr
:= Sloc
(Var
);
1386 CV
: constant Node_Id
:= Current_Value
(Entity
(Var
));
1395 -- If statement. Condition is known true in THEN section, known False
1396 -- in any ELSIF or ELSE part, and unknown outside the IF statement.
1398 if Nkind
(CV
) = N_If_Statement
then
1400 -- Before start of IF statement
1402 if Loc
< Sloc
(CV
) then
1405 -- After end of IF statement
1407 elsif Loc
>= Sloc
(CV
) + Text_Ptr
(UI_To_Int
(End_Span
(CV
))) then
1411 -- At this stage we know that we are within the IF statement, but
1412 -- unfortunately, the tree does not record the SLOC of the ELSE so
1413 -- we cannot use a simple SLOC comparison to distinguish between
1414 -- the then/else statements, so we have to climb the tree.
1421 while Parent
(N
) /= CV
loop
1424 -- If we fall off the top of the tree, then that's odd, but
1425 -- perhaps it could occur in some error situation, and the
1426 -- safest response is simply to assume that the outcome of
1427 -- the condition is unknown. No point in bombing during an
1428 -- attempt to optimize things.
1435 -- Now we have N pointing to a node whose parent is the IF
1436 -- statement in question, so now we can tell if we are within
1437 -- the THEN statements.
1439 if Is_List_Member
(N
)
1440 and then List_Containing
(N
) = Then_Statements
(CV
)
1444 -- Otherwise we must be in ELSIF or ELSE part
1451 -- ELSIF part. Condition is known true within the referenced
1452 -- ELSIF, known False in any subsequent ELSIF or ELSE part,
1453 -- and unknown before the ELSE part or after the IF statement.
1455 elsif Nkind
(CV
) = N_Elsif_Part
then
1458 -- Before start of ELSIF part
1460 if Loc
< Sloc
(CV
) then
1463 -- After end of IF statement
1465 elsif Loc
>= Sloc
(Stm
) +
1466 Text_Ptr
(UI_To_Int
(End_Span
(Stm
)))
1471 -- Again we lack the SLOC of the ELSE, so we need to climb the
1472 -- tree to see if we are within the ELSIF part in question.
1479 while Parent
(N
) /= Stm
loop
1482 -- If we fall off the top of the tree, then that's odd, but
1483 -- perhaps it could occur in some error situation, and the
1484 -- safest response is simply to assume that the outcome of
1485 -- the condition is unknown. No point in bombing during an
1486 -- attempt to optimize things.
1493 -- Now we have N pointing to a node whose parent is the IF
1494 -- statement in question, so see if is the ELSIF part we want.
1495 -- the THEN statements.
1500 -- Otherwise we must be in susbequent ELSIF or ELSE part
1507 -- All other cases of Current_Value settings
1513 -- If we fall through here, then we have a reportable
1514 -- condition, Sens is True if the condition is true and
1515 -- False if it needs inverting.
1517 -- Deal with NOT operators, inverting sense
1519 Cond
:= Condition
(CV
);
1520 while Nkind
(Cond
) = N_Op_Not
loop
1521 Cond
:= Right_Opnd
(Cond
);
1525 -- Now we must have a relational operator
1527 pragma Assert
(Entity
(Var
) = Entity
(Left_Opnd
(Cond
)));
1528 Val
:= Right_Opnd
(Cond
);
1531 if Sens
= False then
1533 when N_Op_Eq
=> Op
:= N_Op_Ne
;
1534 when N_Op_Ne
=> Op
:= N_Op_Eq
;
1535 when N_Op_Lt
=> Op
:= N_Op_Ge
;
1536 when N_Op_Gt
=> Op
:= N_Op_Le
;
1537 when N_Op_Le
=> Op
:= N_Op_Gt
;
1538 when N_Op_Ge
=> Op
:= N_Op_Lt
;
1540 -- No other entry should be possible
1543 raise Program_Error
;
1546 end Get_Current_Value_Condition
;
1548 --------------------
1549 -- Homonym_Number --
1550 --------------------
1552 function Homonym_Number
(Subp
: Entity_Id
) return Nat
is
1558 Hom
:= Homonym
(Subp
);
1559 while Present
(Hom
) loop
1560 if Scope
(Hom
) = Scope
(Subp
) then
1564 Hom
:= Homonym
(Hom
);
1570 ------------------------------
1571 -- In_Unconditional_Context --
1572 ------------------------------
1574 function In_Unconditional_Context
(Node
: Node_Id
) return Boolean is
1579 while Present
(P
) loop
1581 when N_Subprogram_Body
=>
1584 when N_If_Statement
=>
1587 when N_Loop_Statement
=>
1590 when N_Case_Statement
=>
1599 end In_Unconditional_Context
;
1605 procedure Insert_Action
(Assoc_Node
: Node_Id
; Ins_Action
: Node_Id
) is
1607 if Present
(Ins_Action
) then
1608 Insert_Actions
(Assoc_Node
, New_List
(Ins_Action
));
1612 -- Version with check(s) suppressed
1614 procedure Insert_Action
1615 (Assoc_Node
: Node_Id
; Ins_Action
: Node_Id
; Suppress
: Check_Id
)
1618 Insert_Actions
(Assoc_Node
, New_List
(Ins_Action
), Suppress
);
1621 --------------------
1622 -- Insert_Actions --
1623 --------------------
1625 procedure Insert_Actions
(Assoc_Node
: Node_Id
; Ins_Actions
: List_Id
) is
1629 Wrapped_Node
: Node_Id
:= Empty
;
1632 if No
(Ins_Actions
) or else Is_Empty_List
(Ins_Actions
) then
1636 -- Ignore insert of actions from inside default expression in the
1637 -- special preliminary analyze mode. Any insertions at this point
1638 -- have no relevance, since we are only doing the analyze to freeze
1639 -- the types of any static expressions. See section "Handling of
1640 -- Default Expressions" in the spec of package Sem for further details.
1642 if In_Default_Expression
then
1646 -- If the action derives from stuff inside a record, then the actions
1647 -- are attached to the current scope, to be inserted and analyzed on
1648 -- exit from the scope. The reason for this is that we may also
1649 -- be generating freeze actions at the same time, and they must
1650 -- eventually be elaborated in the correct order.
1652 if Is_Record_Type
(Current_Scope
)
1653 and then not Is_Frozen
(Current_Scope
)
1655 if No
(Scope_Stack
.Table
1656 (Scope_Stack
.Last
).Pending_Freeze_Actions
)
1658 Scope_Stack
.Table
(Scope_Stack
.Last
).Pending_Freeze_Actions
:=
1663 Scope_Stack
.Table
(Scope_Stack
.Last
).Pending_Freeze_Actions
);
1669 -- We now intend to climb up the tree to find the right point to
1670 -- insert the actions. We start at Assoc_Node, unless this node is
1671 -- a subexpression in which case we start with its parent. We do this
1672 -- for two reasons. First it speeds things up. Second, if Assoc_Node
1673 -- is itself one of the special nodes like N_And_Then, then we assume
1674 -- that an initial request to insert actions for such a node does not
1675 -- expect the actions to get deposited in the node for later handling
1676 -- when the node is expanded, since clearly the node is being dealt
1677 -- with by the caller. Note that in the subexpression case, N is
1678 -- always the child we came from.
1680 -- N_Raise_xxx_Error is an annoying special case, it is a statement
1681 -- if it has type Standard_Void_Type, and a subexpression otherwise.
1682 -- otherwise. Procedure attribute references are also statements.
1684 if Nkind
(Assoc_Node
) in N_Subexpr
1685 and then (Nkind
(Assoc_Node
) in N_Raise_xxx_Error
1686 or else Etype
(Assoc_Node
) /= Standard_Void_Type
)
1687 and then (Nkind
(Assoc_Node
) /= N_Attribute_Reference
1689 not Is_Procedure_Attribute_Name
1690 (Attribute_Name
(Assoc_Node
)))
1692 P
:= Assoc_Node
; -- ??? does not agree with above!
1693 N
:= Parent
(Assoc_Node
);
1695 -- Non-subexpression case. Note that N is initially Empty in this
1696 -- case (N is only guaranteed Non-Empty in the subexpr case).
1703 -- Capture root of the transient scope
1705 if Scope_Is_Transient
then
1706 Wrapped_Node
:= Node_To_Be_Wrapped
;
1710 pragma Assert
(Present
(P
));
1714 -- Case of right operand of AND THEN or OR ELSE. Put the actions
1715 -- in the Actions field of the right operand. They will be moved
1716 -- out further when the AND THEN or OR ELSE operator is expanded.
1717 -- Nothing special needs to be done for the left operand since
1718 -- in that case the actions are executed unconditionally.
1720 when N_And_Then | N_Or_Else
=>
1721 if N
= Right_Opnd
(P
) then
1722 if Present
(Actions
(P
)) then
1723 Insert_List_After_And_Analyze
1724 (Last
(Actions
(P
)), Ins_Actions
);
1726 Set_Actions
(P
, Ins_Actions
);
1727 Analyze_List
(Actions
(P
));
1733 -- Then or Else operand of conditional expression. Add actions to
1734 -- Then_Actions or Else_Actions field as appropriate. The actions
1735 -- will be moved further out when the conditional is expanded.
1737 when N_Conditional_Expression
=>
1739 ThenX
: constant Node_Id
:= Next
(First
(Expressions
(P
)));
1740 ElseX
: constant Node_Id
:= Next
(ThenX
);
1743 -- Actions belong to the then expression, temporarily
1744 -- place them as Then_Actions of the conditional expr.
1745 -- They will be moved to the proper place later when
1746 -- the conditional expression is expanded.
1749 if Present
(Then_Actions
(P
)) then
1750 Insert_List_After_And_Analyze
1751 (Last
(Then_Actions
(P
)), Ins_Actions
);
1753 Set_Then_Actions
(P
, Ins_Actions
);
1754 Analyze_List
(Then_Actions
(P
));
1759 -- Actions belong to the else expression, temporarily
1760 -- place them as Else_Actions of the conditional expr.
1761 -- They will be moved to the proper place later when
1762 -- the conditional expression is expanded.
1764 elsif N
= ElseX
then
1765 if Present
(Else_Actions
(P
)) then
1766 Insert_List_After_And_Analyze
1767 (Last
(Else_Actions
(P
)), Ins_Actions
);
1769 Set_Else_Actions
(P
, Ins_Actions
);
1770 Analyze_List
(Else_Actions
(P
));
1775 -- Actions belong to the condition. In this case they are
1776 -- unconditionally executed, and so we can continue the
1777 -- search for the proper insert point.
1784 -- Case of appearing in the condition of a while expression or
1785 -- elsif. We insert the actions into the Condition_Actions field.
1786 -- They will be moved further out when the while loop or elsif
1789 when N_Iteration_Scheme |
1792 if N
= Condition
(P
) then
1793 if Present
(Condition_Actions
(P
)) then
1794 Insert_List_After_And_Analyze
1795 (Last
(Condition_Actions
(P
)), Ins_Actions
);
1797 Set_Condition_Actions
(P
, Ins_Actions
);
1799 -- Set the parent of the insert actions explicitly.
1800 -- This is not a syntactic field, but we need the
1801 -- parent field set, in particular so that freeze
1802 -- can understand that it is dealing with condition
1803 -- actions, and properly insert the freezing actions.
1805 Set_Parent
(Ins_Actions
, P
);
1806 Analyze_List
(Condition_Actions
(P
));
1812 -- Statements, declarations, pragmas, representation clauses
1817 N_Procedure_Call_Statement |
1818 N_Statement_Other_Than_Procedure_Call |
1824 -- Representation_Clause
1827 N_Attribute_Definition_Clause |
1828 N_Enumeration_Representation_Clause |
1829 N_Record_Representation_Clause |
1833 N_Abstract_Subprogram_Declaration |
1835 N_Exception_Declaration |
1836 N_Exception_Renaming_Declaration |
1837 N_Formal_Abstract_Subprogram_Declaration |
1838 N_Formal_Concrete_Subprogram_Declaration |
1839 N_Formal_Object_Declaration |
1840 N_Formal_Type_Declaration |
1841 N_Full_Type_Declaration |
1842 N_Function_Instantiation |
1843 N_Generic_Function_Renaming_Declaration |
1844 N_Generic_Package_Declaration |
1845 N_Generic_Package_Renaming_Declaration |
1846 N_Generic_Procedure_Renaming_Declaration |
1847 N_Generic_Subprogram_Declaration |
1848 N_Implicit_Label_Declaration |
1849 N_Incomplete_Type_Declaration |
1850 N_Number_Declaration |
1851 N_Object_Declaration |
1852 N_Object_Renaming_Declaration |
1854 N_Package_Body_Stub |
1855 N_Package_Declaration |
1856 N_Package_Instantiation |
1857 N_Package_Renaming_Declaration |
1858 N_Private_Extension_Declaration |
1859 N_Private_Type_Declaration |
1860 N_Procedure_Instantiation |
1861 N_Protected_Body_Stub |
1862 N_Protected_Type_Declaration |
1863 N_Single_Task_Declaration |
1865 N_Subprogram_Body_Stub |
1866 N_Subprogram_Declaration |
1867 N_Subprogram_Renaming_Declaration |
1868 N_Subtype_Declaration |
1871 N_Task_Type_Declaration |
1873 -- Freeze entity behaves like a declaration or statement
1877 -- Do not insert here if the item is not a list member (this
1878 -- happens for example with a triggering statement, and the
1879 -- proper approach is to insert before the entire select).
1881 if not Is_List_Member
(P
) then
1884 -- Do not insert if parent of P is an N_Component_Association
1885 -- node (i.e. we are in the context of an N_Aggregate node.
1886 -- In this case we want to insert before the entire aggregate.
1888 elsif Nkind
(Parent
(P
)) = N_Component_Association
then
1891 -- Do not insert if the parent of P is either an N_Variant
1892 -- node or an N_Record_Definition node, meaning in either
1893 -- case that P is a member of a component list, and that
1894 -- therefore the actions should be inserted outside the
1895 -- complete record declaration.
1897 elsif Nkind
(Parent
(P
)) = N_Variant
1898 or else Nkind
(Parent
(P
)) = N_Record_Definition
1902 -- Do not insert freeze nodes within the loop generated for
1903 -- an aggregate, because they may be elaborated too late for
1904 -- subsequent use in the back end: within a package spec the
1905 -- loop is part of the elaboration procedure and is only
1906 -- elaborated during the second pass.
1907 -- If the loop comes from source, or the entity is local to
1908 -- the loop itself it must remain within.
1910 elsif Nkind
(Parent
(P
)) = N_Loop_Statement
1911 and then not Comes_From_Source
(Parent
(P
))
1912 and then Nkind
(First
(Ins_Actions
)) = N_Freeze_Entity
1914 Scope
(Entity
(First
(Ins_Actions
))) /= Current_Scope
1918 -- Otherwise we can go ahead and do the insertion
1920 elsif P
= Wrapped_Node
then
1921 Store_Before_Actions_In_Scope
(Ins_Actions
);
1925 Insert_List_Before_And_Analyze
(P
, Ins_Actions
);
1929 -- A special case, N_Raise_xxx_Error can act either as a
1930 -- statement or a subexpression. We tell the difference
1931 -- by looking at the Etype. It is set to Standard_Void_Type
1932 -- in the statement case.
1935 N_Raise_xxx_Error
=>
1936 if Etype
(P
) = Standard_Void_Type
then
1937 if P
= Wrapped_Node
then
1938 Store_Before_Actions_In_Scope
(Ins_Actions
);
1940 Insert_List_Before_And_Analyze
(P
, Ins_Actions
);
1945 -- In the subexpression case, keep climbing
1951 -- If a component association appears within a loop created for
1952 -- an array aggregate, attach the actions to the association so
1953 -- they can be subsequently inserted within the loop. For other
1954 -- component associations insert outside of the aggregate. For
1955 -- an association that will generate a loop, its Loop_Actions
1956 -- attribute is already initialized (see exp_aggr.adb).
1958 -- The list of loop_actions can in turn generate additional ones,
1959 -- that are inserted before the associated node. If the associated
1960 -- node is outside the aggregate, the new actions are collected
1961 -- at the end of the loop actions, to respect the order in which
1962 -- they are to be elaborated.
1965 N_Component_Association
=>
1966 if Nkind
(Parent
(P
)) = N_Aggregate
1967 and then Present
(Loop_Actions
(P
))
1969 if Is_Empty_List
(Loop_Actions
(P
)) then
1970 Set_Loop_Actions
(P
, Ins_Actions
);
1971 Analyze_List
(Ins_Actions
);
1978 -- Check whether these actions were generated
1979 -- by a declaration that is part of the loop_
1980 -- actions for the component_association.
1983 while Present
(Decl
) loop
1984 exit when Parent
(Decl
) = P
1985 and then Is_List_Member
(Decl
)
1987 List_Containing
(Decl
) = Loop_Actions
(P
);
1988 Decl
:= Parent
(Decl
);
1991 if Present
(Decl
) then
1992 Insert_List_Before_And_Analyze
1993 (Decl
, Ins_Actions
);
1995 Insert_List_After_And_Analyze
1996 (Last
(Loop_Actions
(P
)), Ins_Actions
);
2007 -- Another special case, an attribute denoting a procedure call
2010 N_Attribute_Reference
=>
2011 if Is_Procedure_Attribute_Name
(Attribute_Name
(P
)) then
2012 if P
= Wrapped_Node
then
2013 Store_Before_Actions_In_Scope
(Ins_Actions
);
2015 Insert_List_Before_And_Analyze
(P
, Ins_Actions
);
2020 -- In the subexpression case, keep climbing
2026 -- For all other node types, keep climbing tree
2030 N_Accept_Alternative |
2031 N_Access_Definition |
2032 N_Access_Function_Definition |
2033 N_Access_Procedure_Definition |
2034 N_Access_To_Object_Definition |
2037 N_Case_Statement_Alternative |
2038 N_Character_Literal |
2039 N_Compilation_Unit |
2040 N_Compilation_Unit_Aux |
2041 N_Component_Clause |
2042 N_Component_Declaration |
2043 N_Component_Definition |
2045 N_Constrained_Array_Definition |
2046 N_Decimal_Fixed_Point_Definition |
2047 N_Defining_Character_Literal |
2048 N_Defining_Identifier |
2049 N_Defining_Operator_Symbol |
2050 N_Defining_Program_Unit_Name |
2051 N_Delay_Alternative |
2052 N_Delta_Constraint |
2053 N_Derived_Type_Definition |
2055 N_Digits_Constraint |
2056 N_Discriminant_Association |
2057 N_Discriminant_Specification |
2059 N_Entry_Body_Formal_Part |
2060 N_Entry_Call_Alternative |
2061 N_Entry_Declaration |
2062 N_Entry_Index_Specification |
2063 N_Enumeration_Type_Definition |
2065 N_Exception_Handler |
2067 N_Explicit_Dereference |
2068 N_Extension_Aggregate |
2069 N_Floating_Point_Definition |
2070 N_Formal_Decimal_Fixed_Point_Definition |
2071 N_Formal_Derived_Type_Definition |
2072 N_Formal_Discrete_Type_Definition |
2073 N_Formal_Floating_Point_Definition |
2074 N_Formal_Modular_Type_Definition |
2075 N_Formal_Ordinary_Fixed_Point_Definition |
2076 N_Formal_Package_Declaration |
2077 N_Formal_Private_Type_Definition |
2078 N_Formal_Signed_Integer_Type_Definition |
2080 N_Function_Specification |
2081 N_Generic_Association |
2082 N_Handled_Sequence_Of_Statements |
2085 N_Index_Or_Discriminant_Constraint |
2086 N_Indexed_Component |
2090 N_Loop_Parameter_Specification |
2092 N_Modular_Type_Definition |
2118 N_Op_Shift_Right_Arithmetic |
2122 N_Ordinary_Fixed_Point_Definition |
2124 N_Package_Specification |
2125 N_Parameter_Association |
2126 N_Parameter_Specification |
2127 N_Pragma_Argument_Association |
2128 N_Procedure_Specification |
2130 N_Protected_Definition |
2131 N_Qualified_Expression |
2133 N_Range_Constraint |
2135 N_Real_Range_Specification |
2136 N_Record_Definition |
2138 N_Selected_Component |
2139 N_Signed_Integer_Type_Definition |
2140 N_Single_Protected_Declaration |
2144 N_Subtype_Indication |
2147 N_Terminate_Alternative |
2148 N_Triggering_Alternative |
2150 N_Unchecked_Expression |
2151 N_Unchecked_Type_Conversion |
2152 N_Unconstrained_Array_Definition |
2155 N_Use_Package_Clause |
2159 N_Validate_Unchecked_Conversion |
2167 -- Make sure that inserted actions stay in the transient scope
2169 if P
= Wrapped_Node
then
2170 Store_Before_Actions_In_Scope
(Ins_Actions
);
2174 -- If we fall through above tests, keep climbing tree
2178 if Nkind
(Parent
(N
)) = N_Subunit
then
2180 -- This is the proper body corresponding to a stub. Insertion
2181 -- must be done at the point of the stub, which is in the decla-
2182 -- tive part of the parent unit.
2184 P
:= Corresponding_Stub
(Parent
(N
));
2193 -- Version with check(s) suppressed
2195 procedure Insert_Actions
2196 (Assoc_Node
: Node_Id
; Ins_Actions
: List_Id
; Suppress
: Check_Id
)
2199 if Suppress
= All_Checks
then
2201 Svg
: constant Suppress_Array
:= Scope_Suppress
;
2204 Scope_Suppress
:= (others => True);
2205 Insert_Actions
(Assoc_Node
, Ins_Actions
);
2206 Scope_Suppress
:= Svg
;
2211 Svg
: constant Boolean := Scope_Suppress
(Suppress
);
2214 Scope_Suppress
(Suppress
) := True;
2215 Insert_Actions
(Assoc_Node
, Ins_Actions
);
2216 Scope_Suppress
(Suppress
) := Svg
;
2221 --------------------------
2222 -- Insert_Actions_After --
2223 --------------------------
2225 procedure Insert_Actions_After
2226 (Assoc_Node
: Node_Id
;
2227 Ins_Actions
: List_Id
)
2230 if Scope_Is_Transient
2231 and then Assoc_Node
= Node_To_Be_Wrapped
2233 Store_After_Actions_In_Scope
(Ins_Actions
);
2235 Insert_List_After_And_Analyze
(Assoc_Node
, Ins_Actions
);
2237 end Insert_Actions_After
;
2239 ---------------------------------
2240 -- Insert_Library_Level_Action --
2241 ---------------------------------
2243 procedure Insert_Library_Level_Action
(N
: Node_Id
) is
2244 Aux
: constant Node_Id
:= Aux_Decls_Node
(Cunit
(Main_Unit
));
2247 New_Scope
(Cunit_Entity
(Main_Unit
));
2249 if No
(Actions
(Aux
)) then
2250 Set_Actions
(Aux
, New_List
(N
));
2252 Append
(N
, Actions
(Aux
));
2257 end Insert_Library_Level_Action
;
2259 ----------------------------------
2260 -- Insert_Library_Level_Actions --
2261 ----------------------------------
2263 procedure Insert_Library_Level_Actions
(L
: List_Id
) is
2264 Aux
: constant Node_Id
:= Aux_Decls_Node
(Cunit
(Main_Unit
));
2267 if Is_Non_Empty_List
(L
) then
2268 New_Scope
(Cunit_Entity
(Main_Unit
));
2270 if No
(Actions
(Aux
)) then
2271 Set_Actions
(Aux
, L
);
2274 Insert_List_After_And_Analyze
(Last
(Actions
(Aux
)), L
);
2279 end Insert_Library_Level_Actions
;
2281 ----------------------
2282 -- Inside_Init_Proc --
2283 ----------------------
2285 function Inside_Init_Proc
return Boolean is
2291 and then S
/= Standard_Standard
2293 if Is_Init_Proc
(S
) then
2301 end Inside_Init_Proc
;
2303 ----------------------------
2304 -- Is_All_Null_Statements --
2305 ----------------------------
2307 function Is_All_Null_Statements
(L
: List_Id
) return Boolean is
2312 while Present
(Stm
) loop
2313 if Nkind
(Stm
) /= N_Null_Statement
then
2321 end Is_All_Null_Statements
;
2323 ----------------------------------
2324 -- Is_Possibly_Unaligned_Object --
2325 ----------------------------------
2327 function Is_Possibly_Unaligned_Object
(N
: Node_Id
) return Boolean is
2328 T
: constant Entity_Id
:= Etype
(N
);
2331 -- If renamed object, apply test to underlying object
2333 if Is_Entity_Name
(N
)
2334 and then Is_Object
(Entity
(N
))
2335 and then Present
(Renamed_Object
(Entity
(N
)))
2337 return Is_Possibly_Unaligned_Object
(Renamed_Object
(Entity
(N
)));
2340 -- Tagged and controlled types and aliased types are always aligned,
2341 -- as are concurrent types.
2344 or else Has_Controlled_Component
(T
)
2345 or else Is_Concurrent_Type
(T
)
2346 or else Is_Tagged_Type
(T
)
2347 or else Is_Controlled
(T
)
2352 -- If this is an element of a packed array, may be unaligned
2354 if Is_Ref_To_Bit_Packed_Array
(N
) then
2358 -- Case of component reference
2360 if Nkind
(N
) = N_Selected_Component
then
2362 P
: constant Node_Id
:= Prefix
(N
);
2363 C
: constant Entity_Id
:= Entity
(Selector_Name
(N
));
2368 -- If component reference is for an array with non-static bounds,
2369 -- then it is always aligned, we can only unaligned arrays with
2370 -- static bounds (more accurately bounds known at compile time)
2372 if Is_Array_Type
(T
)
2373 and then not Compile_Time_Known_Bounds
(T
)
2378 -- If component is aliased, it is definitely properly aligned
2380 if Is_Aliased
(C
) then
2384 -- If component is for a type implemented as a scalar, and the
2385 -- record is packed, and the component is other than the first
2386 -- component of the record, then the component may be unaligned.
2388 if Is_Packed
(Etype
(P
))
2389 and then Represented_As_Scalar
(Etype
(C
))
2390 and then First_Entity
(Scope
(C
)) /= C
2395 -- Compute maximum possible alignment for T
2397 -- If alignment is known, then that settles things
2399 if Known_Alignment
(T
) then
2400 M
:= UI_To_Int
(Alignment
(T
));
2402 -- If alignment is not known, tentatively set max alignment
2405 M
:= Ttypes
.Maximum_Alignment
;
2407 -- We can reduce this if the Esize is known since the default
2408 -- alignment will never be more than the smallest power of 2
2409 -- that does not exceed this Esize value.
2411 if Known_Esize
(T
) then
2412 S
:= UI_To_Int
(Esize
(T
));
2414 while (M
/ 2) >= S
loop
2420 -- If the component reference is for a record that has a specified
2421 -- alignment, and we either know it is too small, or cannot tell,
2422 -- then the component may be unaligned
2424 if Known_Alignment
(Etype
(P
))
2425 and then Alignment
(Etype
(P
)) < Ttypes
.Maximum_Alignment
2426 and then M
> Alignment
(Etype
(P
))
2431 -- Case of component clause present which may specify an
2432 -- unaligned position.
2434 if Present
(Component_Clause
(C
)) then
2436 -- Otherwise we can do a test to make sure that the actual
2437 -- start position in the record, and the length, are both
2438 -- consistent with the required alignment. If not, we know
2439 -- that we are unaligned.
2442 Align_In_Bits
: constant Nat
:= M
* System_Storage_Unit
;
2444 if Component_Bit_Offset
(C
) mod Align_In_Bits
/= 0
2445 or else Esize
(C
) mod Align_In_Bits
/= 0
2452 -- Otherwise, for a component reference, test prefix
2454 return Is_Possibly_Unaligned_Object
(P
);
2457 -- If not a component reference, must be aligned
2462 end Is_Possibly_Unaligned_Object
;
2464 ---------------------------------
2465 -- Is_Possibly_Unaligned_Slice --
2466 ---------------------------------
2468 function Is_Possibly_Unaligned_Slice
(N
: Node_Id
) return Boolean is
2470 -- ??? GCC3 will eventually handle strings with arbitrary alignments,
2471 -- but for now the following check must be disabled.
2473 -- if get_gcc_version >= 3 then
2477 -- For renaming case, go to renamed object
2479 if Is_Entity_Name
(N
)
2480 and then Is_Object
(Entity
(N
))
2481 and then Present
(Renamed_Object
(Entity
(N
)))
2483 return Is_Possibly_Unaligned_Slice
(Renamed_Object
(Entity
(N
)));
2486 -- The reference must be a slice
2488 if Nkind
(N
) /= N_Slice
then
2492 -- Always assume the worst for a nested record component with a
2493 -- component clause, which gigi/gcc does not appear to handle well.
2494 -- It is not clear why this special test is needed at all ???
2496 if Nkind
(Prefix
(N
)) = N_Selected_Component
2497 and then Nkind
(Prefix
(Prefix
(N
))) = N_Selected_Component
2499 Present
(Component_Clause
(Entity
(Selector_Name
(Prefix
(N
)))))
2504 -- We only need to worry if the target has strict alignment
2506 if not Target_Strict_Alignment
then
2510 -- If it is a slice, then look at the array type being sliced
2513 Sarr
: constant Node_Id
:= Prefix
(N
);
2514 -- Prefix of the slice, i.e. the array being sliced
2516 Styp
: constant Entity_Id
:= Etype
(Prefix
(N
));
2517 -- Type of the array being sliced
2523 -- The problems arise if the array object that is being sliced
2524 -- is a component of a record or array, and we cannot guarantee
2525 -- the alignment of the array within its containing object.
2527 -- To investigate this, we look at successive prefixes to see
2528 -- if we have a worrisome indexed or selected component.
2532 -- Case of array is part of an indexed component reference
2534 if Nkind
(Pref
) = N_Indexed_Component
then
2535 Ptyp
:= Etype
(Prefix
(Pref
));
2537 -- The only problematic case is when the array is packed,
2538 -- in which case we really know nothing about the alignment
2539 -- of individual components.
2541 if Is_Bit_Packed_Array
(Ptyp
) then
2545 -- Case of array is part of a selected component reference
2547 elsif Nkind
(Pref
) = N_Selected_Component
then
2548 Ptyp
:= Etype
(Prefix
(Pref
));
2550 -- We are definitely in trouble if the record in question
2551 -- has an alignment, and either we know this alignment is
2552 -- inconsistent with the alignment of the slice, or we
2553 -- don't know what the alignment of the slice should be.
2555 if Known_Alignment
(Ptyp
)
2556 and then (Unknown_Alignment
(Styp
)
2557 or else Alignment
(Styp
) > Alignment
(Ptyp
))
2562 -- We are in potential trouble if the record type is packed.
2563 -- We could special case when we know that the array is the
2564 -- first component, but that's not such a simple case ???
2566 if Is_Packed
(Ptyp
) then
2570 -- We are in trouble if there is a component clause, and
2571 -- either we do not know the alignment of the slice, or
2572 -- the alignment of the slice is inconsistent with the
2573 -- bit position specified by the component clause.
2576 Field
: constant Entity_Id
:= Entity
(Selector_Name
(Pref
));
2578 if Present
(Component_Clause
(Field
))
2580 (Unknown_Alignment
(Styp
)
2582 (Component_Bit_Offset
(Field
) mod
2583 (System_Storage_Unit
* Alignment
(Styp
))) /= 0)
2589 -- For cases other than selected or indexed components we
2590 -- know we are OK, since no issues arise over alignment.
2596 -- We processed an indexed component or selected component
2597 -- reference that looked safe, so keep checking prefixes.
2599 Pref
:= Prefix
(Pref
);
2602 end Is_Possibly_Unaligned_Slice
;
2604 --------------------------------
2605 -- Is_Ref_To_Bit_Packed_Array --
2606 --------------------------------
2608 function Is_Ref_To_Bit_Packed_Array
(N
: Node_Id
) return Boolean is
2613 if Is_Entity_Name
(N
)
2614 and then Is_Object
(Entity
(N
))
2615 and then Present
(Renamed_Object
(Entity
(N
)))
2617 return Is_Ref_To_Bit_Packed_Array
(Renamed_Object
(Entity
(N
)));
2620 if Nkind
(N
) = N_Indexed_Component
2622 Nkind
(N
) = N_Selected_Component
2624 if Is_Bit_Packed_Array
(Etype
(Prefix
(N
))) then
2627 Result
:= Is_Ref_To_Bit_Packed_Array
(Prefix
(N
));
2630 if Result
and then Nkind
(N
) = N_Indexed_Component
then
2631 Expr
:= First
(Expressions
(N
));
2632 while Present
(Expr
) loop
2633 Force_Evaluation
(Expr
);
2643 end Is_Ref_To_Bit_Packed_Array
;
2645 --------------------------------
2646 -- Is_Ref_To_Bit_Packed_Slice --
2647 --------------------------------
2649 function Is_Ref_To_Bit_Packed_Slice
(N
: Node_Id
) return Boolean is
2651 if Is_Entity_Name
(N
)
2652 and then Is_Object
(Entity
(N
))
2653 and then Present
(Renamed_Object
(Entity
(N
)))
2655 return Is_Ref_To_Bit_Packed_Slice
(Renamed_Object
(Entity
(N
)));
2658 if Nkind
(N
) = N_Slice
2659 and then Is_Bit_Packed_Array
(Etype
(Prefix
(N
)))
2663 elsif Nkind
(N
) = N_Indexed_Component
2665 Nkind
(N
) = N_Selected_Component
2667 return Is_Ref_To_Bit_Packed_Slice
(Prefix
(N
));
2672 end Is_Ref_To_Bit_Packed_Slice
;
2674 -----------------------
2675 -- Is_Renamed_Object --
2676 -----------------------
2678 function Is_Renamed_Object
(N
: Node_Id
) return Boolean is
2679 Pnod
: constant Node_Id
:= Parent
(N
);
2680 Kind
: constant Node_Kind
:= Nkind
(Pnod
);
2683 if Kind
= N_Object_Renaming_Declaration
then
2686 elsif Kind
= N_Indexed_Component
2687 or else Kind
= N_Selected_Component
2689 return Is_Renamed_Object
(Pnod
);
2694 end Is_Renamed_Object
;
2696 ----------------------------
2697 -- Is_Untagged_Derivation --
2698 ----------------------------
2700 function Is_Untagged_Derivation
(T
: Entity_Id
) return Boolean is
2702 return (not Is_Tagged_Type
(T
) and then Is_Derived_Type
(T
))
2704 (Is_Private_Type
(T
) and then Present
(Full_View
(T
))
2705 and then not Is_Tagged_Type
(Full_View
(T
))
2706 and then Is_Derived_Type
(Full_View
(T
))
2707 and then Etype
(Full_View
(T
)) /= T
);
2709 end Is_Untagged_Derivation
;
2711 --------------------
2712 -- Kill_Dead_Code --
2713 --------------------
2715 procedure Kill_Dead_Code
(N
: Node_Id
) is
2718 Remove_Handler_Entries
(N
);
2719 Remove_Warning_Messages
(N
);
2721 -- Recurse into block statements and bodies to process declarations
2724 if Nkind
(N
) = N_Block_Statement
2725 or else Nkind
(N
) = N_Subprogram_Body
2726 or else Nkind
(N
) = N_Package_Body
2728 Kill_Dead_Code
(Declarations
(N
));
2729 Kill_Dead_Code
(Statements
(Handled_Statement_Sequence
(N
)));
2731 if Nkind
(N
) = N_Subprogram_Body
then
2732 Set_Is_Eliminated
(Defining_Entity
(N
));
2735 elsif Nkind
(N
) = N_Package_Declaration
then
2736 Kill_Dead_Code
(Visible_Declarations
(Specification
(N
)));
2737 Kill_Dead_Code
(Private_Declarations
(Specification
(N
)));
2740 E
: Entity_Id
:= First_Entity
(Defining_Entity
(N
));
2742 while Present
(E
) loop
2743 if Ekind
(E
) = E_Operator
then
2744 Set_Is_Eliminated
(E
);
2751 -- Recurse into composite statement to kill individual statements,
2752 -- in particular instantiations.
2754 elsif Nkind
(N
) = N_If_Statement
then
2755 Kill_Dead_Code
(Then_Statements
(N
));
2756 Kill_Dead_Code
(Elsif_Parts
(N
));
2757 Kill_Dead_Code
(Else_Statements
(N
));
2759 elsif Nkind
(N
) = N_Loop_Statement
then
2760 Kill_Dead_Code
(Statements
(N
));
2762 elsif Nkind
(N
) = N_Case_Statement
then
2766 Alt
:= First
(Alternatives
(N
));
2767 while Present
(Alt
) loop
2768 Kill_Dead_Code
(Statements
(Alt
));
2773 elsif Nkind
(N
) = N_Case_Statement_Alternative
then
2774 Kill_Dead_Code
(Statements
(N
));
2776 -- Deal with dead instances caused by deleting instantiations
2778 elsif Nkind
(N
) in N_Generic_Instantiation
then
2779 Remove_Dead_Instance
(N
);
2786 -- Case where argument is a list of nodes to be killed
2788 procedure Kill_Dead_Code
(L
: List_Id
) is
2792 if Is_Non_Empty_List
(L
) then
2794 N
:= Remove_Head
(L
);
2801 ------------------------
2802 -- Known_Non_Negative --
2803 ------------------------
2805 function Known_Non_Negative
(Opnd
: Node_Id
) return Boolean is
2807 if Is_OK_Static_Expression
(Opnd
)
2808 and then Expr_Value
(Opnd
) >= 0
2814 Lo
: constant Node_Id
:= Type_Low_Bound
(Etype
(Opnd
));
2818 Is_OK_Static_Expression
(Lo
) and then Expr_Value
(Lo
) >= 0;
2821 end Known_Non_Negative
;
2823 --------------------
2824 -- Known_Non_Null --
2825 --------------------
2827 function Known_Non_Null
(N
: Node_Id
) return Boolean is
2829 pragma Assert
(Is_Access_Type
(Underlying_Type
(Etype
(N
))));
2831 -- Case of entity for which Is_Known_Non_Null is True
2833 if Is_Entity_Name
(N
) and then Is_Known_Non_Null
(Entity
(N
)) then
2835 -- If the entity is aliased or volatile, then we decide that
2836 -- we don't know it is really non-null even if the sequential
2837 -- flow indicates that it is, since such variables can be
2838 -- changed without us noticing.
2840 if Is_Aliased
(Entity
(N
))
2841 or else Treat_As_Volatile
(Entity
(N
))
2845 -- For all other cases, the flag is decisive
2851 -- True if access attribute
2853 elsif Nkind
(N
) = N_Attribute_Reference
2854 and then (Attribute_Name
(N
) = Name_Access
2856 Attribute_Name
(N
) = Name_Unchecked_Access
2858 Attribute_Name
(N
) = Name_Unrestricted_Access
)
2862 -- True if allocator
2864 elsif Nkind
(N
) = N_Allocator
then
2867 -- For a conversion, true if expression is known non-null
2869 elsif Nkind
(N
) = N_Type_Conversion
then
2870 return Known_Non_Null
(Expression
(N
));
2872 -- One more case is when Current_Value references a condition
2873 -- that ensures a non-null value.
2875 elsif Is_Entity_Name
(N
) then
2881 Get_Current_Value_Condition
(N
, Op
, Val
);
2882 return Op
= N_Op_Ne
and then Nkind
(Val
) = N_Null
;
2885 -- Above are all cases where the value could be determined to be
2886 -- non-null. In all other cases, we don't know, so return False.
2893 -----------------------------
2894 -- Make_CW_Equivalent_Type --
2895 -----------------------------
2897 -- Create a record type used as an equivalent of any member
2898 -- of the class which takes its size from exp.
2900 -- Generate the following code:
2902 -- type Equiv_T is record
2903 -- _parent : T (List of discriminant constaints taken from Exp);
2904 -- Ext__50 : Storage_Array (1 .. (Exp'size - Typ'object_size)/8);
2907 -- ??? Note that this type does not guarantee same alignment as all
2910 function Make_CW_Equivalent_Type
2912 E
: Node_Id
) return Entity_Id
2914 Loc
: constant Source_Ptr
:= Sloc
(E
);
2915 Root_Typ
: constant Entity_Id
:= Root_Type
(T
);
2916 List_Def
: constant List_Id
:= Empty_List
;
2917 Equiv_Type
: Entity_Id
;
2918 Range_Type
: Entity_Id
;
2919 Str_Type
: Entity_Id
;
2920 Constr_Root
: Entity_Id
;
2924 if not Has_Discriminants
(Root_Typ
) then
2925 Constr_Root
:= Root_Typ
;
2928 Make_Defining_Identifier
(Loc
, New_Internal_Name
('R'));
2930 -- subtype cstr__n is T (List of discr constraints taken from Exp)
2932 Append_To
(List_Def
,
2933 Make_Subtype_Declaration
(Loc
,
2934 Defining_Identifier
=> Constr_Root
,
2935 Subtype_Indication
=>
2936 Make_Subtype_From_Expr
(E
, Root_Typ
)));
2939 -- subtype rg__xx is Storage_Offset range
2940 -- (Expr'size - typ'size) / Storage_Unit
2942 Range_Type
:= Make_Defining_Identifier
(Loc
, New_Internal_Name
('G'));
2945 Make_Op_Subtract
(Loc
,
2947 Make_Attribute_Reference
(Loc
,
2949 OK_Convert_To
(T
, Duplicate_Subexpr_No_Checks
(E
)),
2950 Attribute_Name
=> Name_Size
),
2952 Make_Attribute_Reference
(Loc
,
2953 Prefix
=> New_Reference_To
(Constr_Root
, Loc
),
2954 Attribute_Name
=> Name_Object_Size
));
2956 Set_Paren_Count
(Sizexpr
, 1);
2958 Append_To
(List_Def
,
2959 Make_Subtype_Declaration
(Loc
,
2960 Defining_Identifier
=> Range_Type
,
2961 Subtype_Indication
=>
2962 Make_Subtype_Indication
(Loc
,
2963 Subtype_Mark
=> New_Reference_To
(RTE
(RE_Storage_Offset
), Loc
),
2964 Constraint
=> Make_Range_Constraint
(Loc
,
2967 Low_Bound
=> Make_Integer_Literal
(Loc
, 1),
2969 Make_Op_Divide
(Loc
,
2970 Left_Opnd
=> Sizexpr
,
2971 Right_Opnd
=> Make_Integer_Literal
(Loc
,
2972 Intval
=> System_Storage_Unit
)))))));
2974 -- subtype str__nn is Storage_Array (rg__x);
2976 Str_Type
:= Make_Defining_Identifier
(Loc
, New_Internal_Name
('S'));
2977 Append_To
(List_Def
,
2978 Make_Subtype_Declaration
(Loc
,
2979 Defining_Identifier
=> Str_Type
,
2980 Subtype_Indication
=>
2981 Make_Subtype_Indication
(Loc
,
2982 Subtype_Mark
=> New_Reference_To
(RTE
(RE_Storage_Array
), Loc
),
2984 Make_Index_Or_Discriminant_Constraint
(Loc
,
2986 New_List
(New_Reference_To
(Range_Type
, Loc
))))));
2988 -- type Equiv_T is record
2993 Equiv_Type
:= Make_Defining_Identifier
(Loc
, New_Internal_Name
('T'));
2995 -- When the target requires front-end layout, it's necessary to allow
2996 -- the equivalent type to be frozen so that layout can occur (when the
2997 -- associated class-wide subtype is frozen, the equivalent type will
2998 -- be frozen, see freeze.adb). For other targets, Gigi wants to have
2999 -- the equivalent type marked as frozen and deals with this type itself.
3000 -- In the Gigi case this will also avoid the generation of an init
3001 -- procedure for the type.
3003 if not Frontend_Layout_On_Target
then
3004 Set_Is_Frozen
(Equiv_Type
);
3007 Set_Ekind
(Equiv_Type
, E_Record_Type
);
3008 Set_Parent_Subtype
(Equiv_Type
, Constr_Root
);
3010 Append_To
(List_Def
,
3011 Make_Full_Type_Declaration
(Loc
,
3012 Defining_Identifier
=> Equiv_Type
,
3015 Make_Record_Definition
(Loc
,
3016 Component_List
=> Make_Component_List
(Loc
,
3017 Component_Items
=> New_List
(
3018 Make_Component_Declaration
(Loc
,
3019 Defining_Identifier
=>
3020 Make_Defining_Identifier
(Loc
, Name_uParent
),
3021 Component_Definition
=>
3022 Make_Component_Definition
(Loc
,
3023 Aliased_Present
=> False,
3024 Subtype_Indication
=>
3025 New_Reference_To
(Constr_Root
, Loc
))),
3027 Make_Component_Declaration
(Loc
,
3028 Defining_Identifier
=>
3029 Make_Defining_Identifier
(Loc
,
3030 Chars
=> New_Internal_Name
('C')),
3031 Component_Definition
=>
3032 Make_Component_Definition
(Loc
,
3033 Aliased_Present
=> False,
3034 Subtype_Indication
=>
3035 New_Reference_To
(Str_Type
, Loc
)))),
3037 Variant_Part
=> Empty
))));
3039 Insert_Actions
(E
, List_Def
);
3041 end Make_CW_Equivalent_Type
;
3043 ------------------------
3044 -- Make_Literal_Range --
3045 ------------------------
3047 function Make_Literal_Range
3049 Literal_Typ
: Entity_Id
) return Node_Id
3051 Lo
: constant Node_Id
:=
3052 New_Copy_Tree
(String_Literal_Low_Bound
(Literal_Typ
));
3055 Set_Analyzed
(Lo
, False);
3062 Make_Op_Subtract
(Loc
,
3065 Left_Opnd
=> New_Copy_Tree
(Lo
),
3067 Make_Integer_Literal
(Loc
,
3068 String_Literal_Length
(Literal_Typ
))),
3069 Right_Opnd
=> Make_Integer_Literal
(Loc
, 1)));
3070 end Make_Literal_Range
;
3072 ----------------------------
3073 -- Make_Subtype_From_Expr --
3074 ----------------------------
3076 -- 1. If Expr is an uncontrained array expression, creates
3077 -- Unc_Type(Expr'first(1)..Expr'Last(1),..., Expr'first(n)..Expr'last(n))
3079 -- 2. If Expr is a unconstrained discriminated type expression, creates
3080 -- Unc_Type(Expr.Discr1, ... , Expr.Discr_n)
3082 -- 3. If Expr is class-wide, creates an implicit class wide subtype
3084 function Make_Subtype_From_Expr
3086 Unc_Typ
: Entity_Id
) return Node_Id
3088 Loc
: constant Source_Ptr
:= Sloc
(E
);
3089 List_Constr
: constant List_Id
:= New_List
;
3092 Full_Subtyp
: Entity_Id
;
3093 Priv_Subtyp
: Entity_Id
;
3098 if Is_Private_Type
(Unc_Typ
)
3099 and then Has_Unknown_Discriminants
(Unc_Typ
)
3101 -- Prepare the subtype completion, Go to base type to
3102 -- find underlying type.
3104 Utyp
:= Underlying_Type
(Base_Type
(Unc_Typ
));
3105 Full_Subtyp
:= Make_Defining_Identifier
(Loc
,
3106 New_Internal_Name
('C'));
3108 Unchecked_Convert_To
3109 (Utyp
, Duplicate_Subexpr_No_Checks
(E
));
3110 Set_Parent
(Full_Exp
, Parent
(E
));
3113 Make_Defining_Identifier
(Loc
, New_Internal_Name
('P'));
3116 Make_Subtype_Declaration
(Loc
,
3117 Defining_Identifier
=> Full_Subtyp
,
3118 Subtype_Indication
=> Make_Subtype_From_Expr
(Full_Exp
, Utyp
)));
3120 -- Define the dummy private subtype
3122 Set_Ekind
(Priv_Subtyp
, Subtype_Kind
(Ekind
(Unc_Typ
)));
3123 Set_Etype
(Priv_Subtyp
, Unc_Typ
);
3124 Set_Scope
(Priv_Subtyp
, Full_Subtyp
);
3125 Set_Is_Constrained
(Priv_Subtyp
);
3126 Set_Is_Tagged_Type
(Priv_Subtyp
, Is_Tagged_Type
(Unc_Typ
));
3127 Set_Is_Itype
(Priv_Subtyp
);
3128 Set_Associated_Node_For_Itype
(Priv_Subtyp
, E
);
3130 if Is_Tagged_Type
(Priv_Subtyp
) then
3132 (Base_Type
(Priv_Subtyp
), Class_Wide_Type
(Unc_Typ
));
3133 Set_Primitive_Operations
(Priv_Subtyp
,
3134 Primitive_Operations
(Unc_Typ
));
3137 Set_Full_View
(Priv_Subtyp
, Full_Subtyp
);
3139 return New_Reference_To
(Priv_Subtyp
, Loc
);
3141 elsif Is_Array_Type
(Unc_Typ
) then
3142 for J
in 1 .. Number_Dimensions
(Unc_Typ
) loop
3143 Append_To
(List_Constr
,
3146 Make_Attribute_Reference
(Loc
,
3147 Prefix
=> Duplicate_Subexpr_No_Checks
(E
),
3148 Attribute_Name
=> Name_First
,
3149 Expressions
=> New_List
(
3150 Make_Integer_Literal
(Loc
, J
))),
3153 Make_Attribute_Reference
(Loc
,
3154 Prefix
=> Duplicate_Subexpr_No_Checks
(E
),
3155 Attribute_Name
=> Name_Last
,
3156 Expressions
=> New_List
(
3157 Make_Integer_Literal
(Loc
, J
)))));
3160 elsif Is_Class_Wide_Type
(Unc_Typ
) then
3162 CW_Subtype
: Entity_Id
;
3163 EQ_Typ
: Entity_Id
:= Empty
;
3166 -- A class-wide equivalent type is not needed when Java_VM
3167 -- because the JVM back end handles the class-wide object
3168 -- initialization itself (and doesn't need or want the
3169 -- additional intermediate type to handle the assignment).
3171 if Expander_Active
and then not Java_VM
then
3172 EQ_Typ
:= Make_CW_Equivalent_Type
(Unc_Typ
, E
);
3175 CW_Subtype
:= New_Class_Wide_Subtype
(Unc_Typ
, E
);
3176 Set_Equivalent_Type
(CW_Subtype
, EQ_Typ
);
3178 if Present
(EQ_Typ
) then
3179 Set_Is_Class_Wide_Equivalent_Type
(EQ_Typ
);
3182 Set_Cloned_Subtype
(CW_Subtype
, Base_Type
(Unc_Typ
));
3184 return New_Occurrence_Of
(CW_Subtype
, Loc
);
3187 -- Comment needed (what case is this ???)
3190 D
:= First_Discriminant
(Unc_Typ
);
3191 while Present
(D
) loop
3192 Append_To
(List_Constr
,
3193 Make_Selected_Component
(Loc
,
3194 Prefix
=> Duplicate_Subexpr_No_Checks
(E
),
3195 Selector_Name
=> New_Reference_To
(D
, Loc
)));
3197 Next_Discriminant
(D
);
3202 Make_Subtype_Indication
(Loc
,
3203 Subtype_Mark
=> New_Reference_To
(Unc_Typ
, Loc
),
3205 Make_Index_Or_Discriminant_Constraint
(Loc
,
3206 Constraints
=> List_Constr
));
3207 end Make_Subtype_From_Expr
;
3209 -----------------------------
3210 -- May_Generate_Large_Temp --
3211 -----------------------------
3213 -- At the current time, the only types that we return False for (i.e.
3214 -- where we decide we know they cannot generate large temps) are ones
3215 -- where we know the size is 256 bits or less at compile time, and we
3216 -- are still not doing a thorough job on arrays and records ???
3218 function May_Generate_Large_Temp
(Typ
: Entity_Id
) return Boolean is
3220 if not Size_Known_At_Compile_Time
(Typ
) then
3223 elsif Esize
(Typ
) /= 0 and then Esize
(Typ
) <= 256 then
3226 elsif Is_Array_Type
(Typ
)
3227 and then Present
(Packed_Array_Type
(Typ
))
3229 return May_Generate_Large_Temp
(Packed_Array_Type
(Typ
));
3231 -- We could do more here to find other small types ???
3236 end May_Generate_Large_Temp
;
3238 ----------------------------
3239 -- New_Class_Wide_Subtype --
3240 ----------------------------
3242 function New_Class_Wide_Subtype
3243 (CW_Typ
: Entity_Id
;
3244 N
: Node_Id
) return Entity_Id
3246 Res
: constant Entity_Id
:= Create_Itype
(E_Void
, N
);
3247 Res_Name
: constant Name_Id
:= Chars
(Res
);
3248 Res_Scope
: constant Entity_Id
:= Scope
(Res
);
3251 Copy_Node
(CW_Typ
, Res
);
3252 Set_Sloc
(Res
, Sloc
(N
));
3254 Set_Associated_Node_For_Itype
(Res
, N
);
3255 Set_Is_Public
(Res
, False); -- By default, may be changed below.
3256 Set_Public_Status
(Res
);
3257 Set_Chars
(Res
, Res_Name
);
3258 Set_Scope
(Res
, Res_Scope
);
3259 Set_Ekind
(Res
, E_Class_Wide_Subtype
);
3260 Set_Next_Entity
(Res
, Empty
);
3261 Set_Etype
(Res
, Base_Type
(CW_Typ
));
3263 -- For targets where front-end layout is required, reset the Is_Frozen
3264 -- status of the subtype to False (it can be implicitly set to true
3265 -- from the copy of the class-wide type). For other targets, Gigi
3266 -- doesn't want the class-wide subtype to go through the freezing
3267 -- process (though it's unclear why that causes problems and it would
3268 -- be nice to allow freezing to occur normally for all targets ???).
3270 if Frontend_Layout_On_Target
then
3271 Set_Is_Frozen
(Res
, False);
3274 Set_Freeze_Node
(Res
, Empty
);
3276 end New_Class_Wide_Subtype
;
3278 -------------------------
3279 -- Remove_Side_Effects --
3280 -------------------------
3282 procedure Remove_Side_Effects
3284 Name_Req
: Boolean := False;
3285 Variable_Ref
: Boolean := False)
3287 Loc
: constant Source_Ptr
:= Sloc
(Exp
);
3288 Exp_Type
: constant Entity_Id
:= Etype
(Exp
);
3289 Svg_Suppress
: constant Suppress_Array
:= Scope_Suppress
;
3291 Ref_Type
: Entity_Id
;
3293 Ptr_Typ_Decl
: Node_Id
;
3297 function Side_Effect_Free
(N
: Node_Id
) return Boolean;
3298 -- Determines if the tree N represents an expression that is known
3299 -- not to have side effects, and for which no processing is required.
3301 function Side_Effect_Free
(L
: List_Id
) return Boolean;
3302 -- Determines if all elements of the list L are side effect free
3304 function Safe_Prefixed_Reference
(N
: Node_Id
) return Boolean;
3305 -- The argument N is a construct where the Prefix is dereferenced
3306 -- if it is a an access type and the result is a variable. The call
3307 -- returns True if the construct is side effect free (not considering
3308 -- side effects in other than the prefix which are to be tested by the
3311 function Within_In_Parameter
(N
: Node_Id
) return Boolean;
3312 -- Determines if N is a subcomponent of a composite in-parameter.
3313 -- If so, N is not side-effect free when the actual is global and
3314 -- modifiable indirectly from within a subprogram, because it may
3315 -- be passed by reference. The front-end must be conservative here
3316 -- and assume that this may happen with any array or record type.
3317 -- On the other hand, we cannot create temporaries for all expressions
3318 -- for which this condition is true, for various reasons that might
3319 -- require clearing up ??? For example, descriminant references that
3320 -- appear out of place, or spurious type errors with class-wide
3321 -- expressions. As a result, we limit the transformation to loop
3322 -- bounds, which is so far the only case that requires it.
3324 -----------------------------
3325 -- Safe_Prefixed_Reference --
3326 -----------------------------
3328 function Safe_Prefixed_Reference
(N
: Node_Id
) return Boolean is
3330 -- If prefix is not side effect free, definitely not safe
3332 if not Side_Effect_Free
(Prefix
(N
)) then
3335 -- If the prefix is of an access type that is not access-to-constant,
3336 -- then this construct is a variable reference, which means it is to
3337 -- be considered to have side effects if Variable_Ref is set True
3338 -- Exception is an access to an entity that is a constant or an
3339 -- in-parameter which does not come from source, and is the result
3340 -- of a previous removal of side-effects.
3342 elsif Is_Access_Type
(Etype
(Prefix
(N
)))
3343 and then not Is_Access_Constant
(Etype
(Prefix
(N
)))
3344 and then Variable_Ref
3346 if not Is_Entity_Name
(Prefix
(N
)) then
3349 return Ekind
(Entity
(Prefix
(N
))) = E_Constant
3350 or else Ekind
(Entity
(Prefix
(N
))) = E_In_Parameter
;
3353 -- The following test is the simplest way of solving a complex
3354 -- problem uncovered by BB08-010: Side effect on loop bound that
3355 -- is a subcomponent of a global variable:
3356 -- If a loop bound is a subcomponent of a global variable, a
3357 -- modification of that variable within the loop may incorrectly
3358 -- affect the execution of the loop.
3361 (Nkind
(Parent
(Parent
(N
))) /= N_Loop_Parameter_Specification
3362 or else not Within_In_Parameter
(Prefix
(N
)))
3366 -- All other cases are side effect free
3371 end Safe_Prefixed_Reference
;
3373 ----------------------
3374 -- Side_Effect_Free --
3375 ----------------------
3377 function Side_Effect_Free
(N
: Node_Id
) return Boolean is
3379 -- Note on checks that could raise Constraint_Error. Strictly, if
3380 -- we take advantage of 11.6, these checks do not count as side
3381 -- effects. However, we would just as soon consider that they are
3382 -- side effects, since the backend CSE does not work very well on
3383 -- expressions which can raise Constraint_Error. On the other
3384 -- hand, if we do not consider them to be side effect free, then
3385 -- we get some awkward expansions in -gnato mode, resulting in
3386 -- code insertions at a point where we do not have a clear model
3387 -- for performing the insertions. See 4908-002/comment for details.
3389 -- Special handling for entity names
3391 if Is_Entity_Name
(N
) then
3393 -- If the entity is a constant, it is definitely side effect
3394 -- free. Note that the test of Is_Variable (N) below might
3395 -- be expected to catch this case, but it does not, because
3396 -- this test goes to the original tree, and we may have
3397 -- already rewritten a variable node with a constant as
3398 -- a result of an earlier Force_Evaluation call.
3400 if Ekind
(Entity
(N
)) = E_Constant
3401 or else Ekind
(Entity
(N
)) = E_In_Parameter
3405 -- Functions are not side effect free
3407 elsif Ekind
(Entity
(N
)) = E_Function
then
3410 -- Variables are considered to be a side effect if Variable_Ref
3411 -- is set or if we have a volatile variable and Name_Req is off.
3412 -- If Name_Req is True then we can't help returning a name which
3413 -- effectively allows multiple references in any case.
3415 elsif Is_Variable
(N
) then
3416 return not Variable_Ref
3417 and then (not Treat_As_Volatile
(Entity
(N
))
3420 -- Any other entity (e.g. a subtype name) is definitely side
3427 -- A value known at compile time is always side effect free
3429 elsif Compile_Time_Known_Value
(N
) then
3433 -- For other than entity names and compile time known values,
3434 -- check the node kind for special processing.
3438 -- An attribute reference is side effect free if its expressions
3439 -- are side effect free and its prefix is side effect free or
3440 -- is an entity reference.
3442 -- Is this right? what about x'first where x is a variable???
3444 when N_Attribute_Reference
=>
3445 return Side_Effect_Free
(Expressions
(N
))
3446 and then (Is_Entity_Name
(Prefix
(N
))
3447 or else Side_Effect_Free
(Prefix
(N
)));
3449 -- A binary operator is side effect free if and both operands
3450 -- are side effect free. For this purpose binary operators
3451 -- include membership tests and short circuit forms
3458 return Side_Effect_Free
(Left_Opnd
(N
))
3459 and then Side_Effect_Free
(Right_Opnd
(N
));
3461 -- An explicit dereference is side effect free only if it is
3462 -- a side effect free prefixed reference.
3464 when N_Explicit_Dereference
=>
3465 return Safe_Prefixed_Reference
(N
);
3467 -- A call to _rep_to_pos is side effect free, since we generate
3468 -- this pure function call ourselves. Moreover it is critically
3469 -- important to make this exception, since otherwise we can
3470 -- have discriminants in array components which don't look
3471 -- side effect free in the case of an array whose index type
3472 -- is an enumeration type with an enumeration rep clause.
3474 -- All other function calls are not side effect free
3476 when N_Function_Call
=>
3477 return Nkind
(Name
(N
)) = N_Identifier
3478 and then Is_TSS
(Name
(N
), TSS_Rep_To_Pos
)
3480 Side_Effect_Free
(First
(Parameter_Associations
(N
)));
3482 -- An indexed component is side effect free if it is a side
3483 -- effect free prefixed reference and all the indexing
3484 -- expressions are side effect free.
3486 when N_Indexed_Component
=>
3487 return Side_Effect_Free
(Expressions
(N
))
3488 and then Safe_Prefixed_Reference
(N
);
3490 -- A type qualification is side effect free if the expression
3491 -- is side effect free.
3493 when N_Qualified_Expression
=>
3494 return Side_Effect_Free
(Expression
(N
));
3496 -- A selected component is side effect free only if it is a
3497 -- side effect free prefixed reference.
3499 when N_Selected_Component
=>
3500 return Safe_Prefixed_Reference
(N
);
3502 -- A range is side effect free if the bounds are side effect free
3505 return Side_Effect_Free
(Low_Bound
(N
))
3506 and then Side_Effect_Free
(High_Bound
(N
));
3508 -- A slice is side effect free if it is a side effect free
3509 -- prefixed reference and the bounds are side effect free.
3512 return Side_Effect_Free
(Discrete_Range
(N
))
3513 and then Safe_Prefixed_Reference
(N
);
3515 -- A type conversion is side effect free if the expression
3516 -- to be converted is side effect free.
3518 when N_Type_Conversion
=>
3519 return Side_Effect_Free
(Expression
(N
));
3521 -- A unary operator is side effect free if the operand
3522 -- is side effect free.
3525 return Side_Effect_Free
(Right_Opnd
(N
));
3527 -- An unchecked type conversion is side effect free only if it
3528 -- is safe and its argument is side effect free.
3530 when N_Unchecked_Type_Conversion
=>
3531 return Safe_Unchecked_Type_Conversion
(N
)
3532 and then Side_Effect_Free
(Expression
(N
));
3534 -- An unchecked expression is side effect free if its expression
3535 -- is side effect free.
3537 when N_Unchecked_Expression
=>
3538 return Side_Effect_Free
(Expression
(N
));
3540 -- A literal is side effect free
3542 when N_Character_Literal |
3548 -- We consider that anything else has side effects. This is a bit
3549 -- crude, but we are pretty close for most common cases, and we
3550 -- are certainly correct (i.e. we never return True when the
3551 -- answer should be False).
3556 end Side_Effect_Free
;
3558 -- A list is side effect free if all elements of the list are
3559 -- side effect free.
3561 function Side_Effect_Free
(L
: List_Id
) return Boolean is
3565 if L
= No_List
or else L
= Error_List
then
3570 while Present
(N
) loop
3571 if not Side_Effect_Free
(N
) then
3580 end Side_Effect_Free
;
3582 -------------------------
3583 -- Within_In_Parameter --
3584 -------------------------
3586 function Within_In_Parameter
(N
: Node_Id
) return Boolean is
3588 if not Comes_From_Source
(N
) then
3591 elsif Is_Entity_Name
(N
) then
3593 Ekind
(Entity
(N
)) = E_In_Parameter
;
3595 elsif Nkind
(N
) = N_Indexed_Component
3596 or else Nkind
(N
) = N_Selected_Component
3598 return Within_In_Parameter
(Prefix
(N
));
3603 end Within_In_Parameter
;
3605 -- Start of processing for Remove_Side_Effects
3608 -- If we are side effect free already or expansion is disabled,
3609 -- there is nothing to do.
3611 if Side_Effect_Free
(Exp
) or else not Expander_Active
then
3615 -- All this must not have any checks
3617 Scope_Suppress
:= (others => True);
3619 -- If the expression has the form v.all then we can just capture
3620 -- the pointer, and then do an explicit dereference on the result.
3622 if Nkind
(Exp
) = N_Explicit_Dereference
then
3624 Make_Defining_Identifier
(Loc
, New_Internal_Name
('R'));
3626 Make_Explicit_Dereference
(Loc
, New_Reference_To
(Def_Id
, Loc
));
3629 Make_Object_Declaration
(Loc
,
3630 Defining_Identifier
=> Def_Id
,
3631 Object_Definition
=>
3632 New_Reference_To
(Etype
(Prefix
(Exp
)), Loc
),
3633 Constant_Present
=> True,
3634 Expression
=> Relocate_Node
(Prefix
(Exp
))));
3636 -- Similar processing for an unchecked conversion of an expression
3637 -- of the form v.all, where we want the same kind of treatment.
3639 elsif Nkind
(Exp
) = N_Unchecked_Type_Conversion
3640 and then Nkind
(Expression
(Exp
)) = N_Explicit_Dereference
3642 Remove_Side_Effects
(Expression
(Exp
), Name_Req
, Variable_Ref
);
3643 Scope_Suppress
:= Svg_Suppress
;
3646 -- If this is a type conversion, leave the type conversion and remove
3647 -- the side effects in the expression. This is important in several
3648 -- circumstances: for change of representations, and also when this
3649 -- is a view conversion to a smaller object, where gigi can end up
3650 -- creating its own temporary of the wrong size.
3652 -- ??? this transformation is inhibited for elementary types that are
3653 -- not involved in a change of representation because it causes
3654 -- regressions that are not fully understood yet.
3656 elsif Nkind
(Exp
) = N_Type_Conversion
3657 and then (not Is_Elementary_Type
(Underlying_Type
(Exp_Type
))
3658 or else Nkind
(Parent
(Exp
)) = N_Assignment_Statement
)
3660 Remove_Side_Effects
(Expression
(Exp
), Name_Req
, Variable_Ref
);
3661 Scope_Suppress
:= Svg_Suppress
;
3664 -- For expressions that denote objects, we can use a renaming scheme.
3665 -- We skip using this if we have a volatile variable and we do not
3666 -- have Nam_Req set true (see comments above for Side_Effect_Free).
3667 -- We also skip this scheme for class-wide expressions in order to
3668 -- avoid recursive expansion (see Expand_N_Object_Renaming_Declaration)
3669 -- If the object is a function call, we need to create a temporary and
3672 -- Note that we could use ordinary object declarations in the case of
3673 -- expressions not appearing as lvalues. That is left as a possible
3674 -- optimization in the future but we prefer to generate renamings
3675 -- right now, since we may indeed be transforming an lvalue.
3677 elsif Is_Object_Reference
(Exp
)
3678 and then Nkind
(Exp
) /= N_Function_Call
3679 and then not Variable_Ref
3681 or else not Is_Entity_Name
(Exp
)
3682 or else not Treat_As_Volatile
(Entity
(Exp
)))
3683 and then not Is_Class_Wide_Type
(Exp_Type
)
3685 Def_Id
:= Make_Defining_Identifier
(Loc
, New_Internal_Name
('R'));
3687 if Nkind
(Exp
) = N_Selected_Component
3688 and then Nkind
(Prefix
(Exp
)) = N_Function_Call
3689 and then Is_Array_Type
(Etype
(Exp
))
3691 -- Avoid generating a variable-sized temporary, by generating
3692 -- the renaming declaration just for the function call. The
3693 -- transformation could be refined to apply only when the array
3694 -- component is constrained by a discriminant???
3697 Make_Selected_Component
(Loc
,
3698 Prefix
=> New_Occurrence_Of
(Def_Id
, Loc
),
3699 Selector_Name
=> Selector_Name
(Exp
));
3702 Make_Object_Renaming_Declaration
(Loc
,
3703 Defining_Identifier
=> Def_Id
,
3705 New_Reference_To
(Base_Type
(Etype
(Prefix
(Exp
))), Loc
),
3706 Name
=> Relocate_Node
(Prefix
(Exp
))));
3708 -- The temporary must be elaborated by gigi, and is of course
3709 -- not to be replaced in-line by the expression it renames,
3710 -- which would defeat the purpose of removing the side-effect.
3712 Set_Is_Renaming_Of_Object
(Def_Id
, False);
3715 Res
:= New_Reference_To
(Def_Id
, Loc
);
3718 Make_Object_Renaming_Declaration
(Loc
,
3719 Defining_Identifier
=> Def_Id
,
3720 Subtype_Mark
=> New_Reference_To
(Exp_Type
, Loc
),
3721 Name
=> Relocate_Node
(Exp
)));
3723 Set_Is_Renaming_Of_Object
(Def_Id
, False);
3726 -- If it is a scalar type, just make a copy
3728 elsif Is_Elementary_Type
(Exp_Type
) then
3729 Def_Id
:= Make_Defining_Identifier
(Loc
, New_Internal_Name
('R'));
3730 Set_Etype
(Def_Id
, Exp_Type
);
3731 Res
:= New_Reference_To
(Def_Id
, Loc
);
3734 Make_Object_Declaration
(Loc
,
3735 Defining_Identifier
=> Def_Id
,
3736 Object_Definition
=> New_Reference_To
(Exp_Type
, Loc
),
3737 Constant_Present
=> True,
3738 Expression
=> Relocate_Node
(Exp
));
3740 Set_Assignment_OK
(E
);
3741 Insert_Action
(Exp
, E
);
3743 -- Always use a renaming for an unchecked conversion
3744 -- If this is an unchecked conversion that Gigi can't handle, make
3745 -- a copy or a use a renaming to capture the value.
3747 elsif Nkind
(Exp
) = N_Unchecked_Type_Conversion
3748 and then not Safe_Unchecked_Type_Conversion
(Exp
)
3750 if Controlled_Type
(Etype
(Exp
)) then
3752 -- Use a renaming to capture the expression, rather than create
3753 -- a controlled temporary.
3755 Def_Id
:= Make_Defining_Identifier
(Loc
, New_Internal_Name
('R'));
3756 Res
:= New_Reference_To
(Def_Id
, Loc
);
3759 Make_Object_Renaming_Declaration
(Loc
,
3760 Defining_Identifier
=> Def_Id
,
3761 Subtype_Mark
=> New_Reference_To
(Exp_Type
, Loc
),
3762 Name
=> Relocate_Node
(Exp
)));
3765 Def_Id
:= Make_Defining_Identifier
(Loc
, New_Internal_Name
('R'));
3766 Set_Etype
(Def_Id
, Exp_Type
);
3767 Res
:= New_Reference_To
(Def_Id
, Loc
);
3770 Make_Object_Declaration
(Loc
,
3771 Defining_Identifier
=> Def_Id
,
3772 Object_Definition
=> New_Reference_To
(Exp_Type
, Loc
),
3773 Constant_Present
=> not Is_Variable
(Exp
),
3774 Expression
=> Relocate_Node
(Exp
));
3776 Set_Assignment_OK
(E
);
3777 Insert_Action
(Exp
, E
);
3780 -- Otherwise we generate a reference to the value
3783 Ref_Type
:= Make_Defining_Identifier
(Loc
, New_Internal_Name
('A'));
3786 Make_Full_Type_Declaration
(Loc
,
3787 Defining_Identifier
=> Ref_Type
,
3789 Make_Access_To_Object_Definition
(Loc
,
3790 All_Present
=> True,
3791 Subtype_Indication
=>
3792 New_Reference_To
(Exp_Type
, Loc
)));
3795 Insert_Action
(Exp
, Ptr_Typ_Decl
);
3797 Def_Id
:= Make_Defining_Identifier
(Loc
, New_Internal_Name
('R'));
3798 Set_Etype
(Def_Id
, Exp_Type
);
3801 Make_Explicit_Dereference
(Loc
,
3802 Prefix
=> New_Reference_To
(Def_Id
, Loc
));
3804 if Nkind
(E
) = N_Explicit_Dereference
then
3805 New_Exp
:= Relocate_Node
(Prefix
(E
));
3807 E
:= Relocate_Node
(E
);
3808 New_Exp
:= Make_Reference
(Loc
, E
);
3811 if Is_Delayed_Aggregate
(E
) then
3813 -- The expansion of nested aggregates is delayed until the
3814 -- enclosing aggregate is expanded. As aggregates are often
3815 -- qualified, the predicate applies to qualified expressions
3816 -- as well, indicating that the enclosing aggregate has not
3817 -- been expanded yet. At this point the aggregate is part of
3818 -- a stand-alone declaration, and must be fully expanded.
3820 if Nkind
(E
) = N_Qualified_Expression
then
3821 Set_Expansion_Delayed
(Expression
(E
), False);
3822 Set_Analyzed
(Expression
(E
), False);
3824 Set_Expansion_Delayed
(E
, False);
3827 Set_Analyzed
(E
, False);
3831 Make_Object_Declaration
(Loc
,
3832 Defining_Identifier
=> Def_Id
,
3833 Object_Definition
=> New_Reference_To
(Ref_Type
, Loc
),
3834 Expression
=> New_Exp
));
3837 -- Preserve the Assignment_OK flag in all copies, since at least
3838 -- one copy may be used in a context where this flag must be set
3839 -- (otherwise why would the flag be set in the first place).
3841 Set_Assignment_OK
(Res
, Assignment_OK
(Exp
));
3843 -- Finally rewrite the original expression and we are done
3846 Analyze_And_Resolve
(Exp
, Exp_Type
);
3847 Scope_Suppress
:= Svg_Suppress
;
3848 end Remove_Side_Effects
;
3850 ---------------------------
3851 -- Represented_As_Scalar --
3852 ---------------------------
3854 function Represented_As_Scalar
(T
: Entity_Id
) return Boolean is
3855 UT
: constant Entity_Id
:= Underlying_Type
(T
);
3857 return Is_Scalar_Type
(UT
)
3858 or else (Is_Bit_Packed_Array
(UT
)
3859 and then Is_Scalar_Type
(Packed_Array_Type
(UT
)));
3860 end Represented_As_Scalar
;
3862 ------------------------------------
3863 -- Safe_Unchecked_Type_Conversion --
3864 ------------------------------------
3866 -- Note: this function knows quite a bit about the exact requirements
3867 -- of Gigi with respect to unchecked type conversions, and its code
3868 -- must be coordinated with any changes in Gigi in this area.
3870 -- The above requirements should be documented in Sinfo ???
3872 function Safe_Unchecked_Type_Conversion
(Exp
: Node_Id
) return Boolean is
3877 Pexp
: constant Node_Id
:= Parent
(Exp
);
3880 -- If the expression is the RHS of an assignment or object declaration
3881 -- we are always OK because there will always be a target.
3883 -- Object renaming declarations, (generated for view conversions of
3884 -- actuals in inlined calls), like object declarations, provide an
3885 -- explicit type, and are safe as well.
3887 if (Nkind
(Pexp
) = N_Assignment_Statement
3888 and then Expression
(Pexp
) = Exp
)
3889 or else Nkind
(Pexp
) = N_Object_Declaration
3890 or else Nkind
(Pexp
) = N_Object_Renaming_Declaration
3894 -- If the expression is the prefix of an N_Selected_Component
3895 -- we should also be OK because GCC knows to look inside the
3896 -- conversion except if the type is discriminated. We assume
3897 -- that we are OK anyway if the type is not set yet or if it is
3898 -- controlled since we can't afford to introduce a temporary in
3901 elsif Nkind
(Pexp
) = N_Selected_Component
3902 and then Prefix
(Pexp
) = Exp
3904 if No
(Etype
(Pexp
)) then
3908 not Has_Discriminants
(Etype
(Pexp
))
3909 or else Is_Constrained
(Etype
(Pexp
));
3913 -- Set the output type, this comes from Etype if it is set, otherwise
3914 -- we take it from the subtype mark, which we assume was already
3917 if Present
(Etype
(Exp
)) then
3918 Otyp
:= Etype
(Exp
);
3920 Otyp
:= Entity
(Subtype_Mark
(Exp
));
3923 -- The input type always comes from the expression, and we assume
3924 -- this is indeed always analyzed, so we can simply get the Etype.
3926 Ityp
:= Etype
(Expression
(Exp
));
3928 -- Initialize alignments to unknown so far
3933 -- Replace a concurrent type by its corresponding record type
3934 -- and each type by its underlying type and do the tests on those.
3935 -- The original type may be a private type whose completion is a
3936 -- concurrent type, so find the underlying type first.
3938 if Present
(Underlying_Type
(Otyp
)) then
3939 Otyp
:= Underlying_Type
(Otyp
);
3942 if Present
(Underlying_Type
(Ityp
)) then
3943 Ityp
:= Underlying_Type
(Ityp
);
3946 if Is_Concurrent_Type
(Otyp
) then
3947 Otyp
:= Corresponding_Record_Type
(Otyp
);
3950 if Is_Concurrent_Type
(Ityp
) then
3951 Ityp
:= Corresponding_Record_Type
(Ityp
);
3954 -- If the base types are the same, we know there is no problem since
3955 -- this conversion will be a noop.
3957 if Implementation_Base_Type
(Otyp
) = Implementation_Base_Type
(Ityp
) then
3960 -- Same if this is an upwards conversion of an untagged type, and there
3961 -- are no constraints involved (could be more general???)
3963 elsif Etype
(Ityp
) = Otyp
3964 and then not Is_Tagged_Type
(Ityp
)
3965 and then not Has_Discriminants
(Ityp
)
3966 and then No
(First_Rep_Item
(Base_Type
(Ityp
)))
3970 -- If the size of output type is known at compile time, there is
3971 -- never a problem. Note that unconstrained records are considered
3972 -- to be of known size, but we can't consider them that way here,
3973 -- because we are talking about the actual size of the object.
3975 -- We also make sure that in addition to the size being known, we do
3976 -- not have a case which might generate an embarrassingly large temp
3977 -- in stack checking mode.
3979 elsif Size_Known_At_Compile_Time
(Otyp
)
3981 (not Stack_Checking_Enabled
3982 or else not May_Generate_Large_Temp
(Otyp
))
3983 and then not (Is_Record_Type
(Otyp
) and then not Is_Constrained
(Otyp
))
3987 -- If either type is tagged, then we know the alignment is OK so
3988 -- Gigi will be able to use pointer punning.
3990 elsif Is_Tagged_Type
(Otyp
) or else Is_Tagged_Type
(Ityp
) then
3993 -- If either type is a limited record type, we cannot do a copy, so
3994 -- say safe since there's nothing else we can do.
3996 elsif Is_Limited_Record
(Otyp
) or else Is_Limited_Record
(Ityp
) then
3999 -- Conversions to and from packed array types are always ignored and
4002 elsif Is_Packed_Array_Type
(Otyp
)
4003 or else Is_Packed_Array_Type
(Ityp
)
4008 -- The only other cases known to be safe is if the input type's
4009 -- alignment is known to be at least the maximum alignment for the
4010 -- target or if both alignments are known and the output type's
4011 -- alignment is no stricter than the input's. We can use the alignment
4012 -- of the component type of an array if a type is an unpacked
4015 if Present
(Alignment_Clause
(Otyp
)) then
4016 Oalign
:= Expr_Value
(Expression
(Alignment_Clause
(Otyp
)));
4018 elsif Is_Array_Type
(Otyp
)
4019 and then Present
(Alignment_Clause
(Component_Type
(Otyp
)))
4021 Oalign
:= Expr_Value
(Expression
(Alignment_Clause
4022 (Component_Type
(Otyp
))));
4025 if Present
(Alignment_Clause
(Ityp
)) then
4026 Ialign
:= Expr_Value
(Expression
(Alignment_Clause
(Ityp
)));
4028 elsif Is_Array_Type
(Ityp
)
4029 and then Present
(Alignment_Clause
(Component_Type
(Ityp
)))
4031 Ialign
:= Expr_Value
(Expression
(Alignment_Clause
4032 (Component_Type
(Ityp
))));
4035 if Ialign
/= No_Uint
and then Ialign
> Maximum_Alignment
then
4038 elsif Ialign
/= No_Uint
and then Oalign
/= No_Uint
4039 and then Ialign
<= Oalign
4043 -- Otherwise, Gigi cannot handle this and we must make a temporary
4049 end Safe_Unchecked_Type_Conversion
;
4051 --------------------------
4052 -- Set_Elaboration_Flag --
4053 --------------------------
4055 procedure Set_Elaboration_Flag
(N
: Node_Id
; Spec_Id
: Entity_Id
) is
4056 Loc
: constant Source_Ptr
:= Sloc
(N
);
4057 Ent
: constant Entity_Id
:= Elaboration_Entity
(Spec_Id
);
4061 if Present
(Ent
) then
4063 -- Nothing to do if at the compilation unit level, because in this
4064 -- case the flag is set by the binder generated elaboration routine.
4066 if Nkind
(Parent
(N
)) = N_Compilation_Unit
then
4069 -- Here we do need to generate an assignment statement
4072 Check_Restriction
(No_Elaboration_Code
, N
);
4074 Make_Assignment_Statement
(Loc
,
4075 Name
=> New_Occurrence_Of
(Ent
, Loc
),
4076 Expression
=> New_Occurrence_Of
(Standard_True
, Loc
));
4078 if Nkind
(Parent
(N
)) = N_Subunit
then
4079 Insert_After
(Corresponding_Stub
(Parent
(N
)), Asn
);
4081 Insert_After
(N
, Asn
);
4086 -- Kill current value indication. This is necessary because
4087 -- the tests of this flag are inserted out of sequence and must
4088 -- not pick up bogus indications of the wrong constant value.
4090 Set_Current_Value
(Ent
, Empty
);
4093 end Set_Elaboration_Flag
;
4095 --------------------------
4096 -- Target_Has_Fixed_Ops --
4097 --------------------------
4099 Integer_Sized_Small
: Ureal
;
4100 -- Set to 2.0 ** -(Integer'Size - 1) the first time that this
4101 -- function is called (we don't want to compute it more than once!)
4103 Long_Integer_Sized_Small
: Ureal
;
4104 -- Set to 2.0 ** -(Long_Integer'Size - 1) the first time that this
4105 -- functoin is called (we don't want to compute it more than once)
4107 First_Time_For_THFO
: Boolean := True;
4108 -- Set to False after first call (if Fractional_Fixed_Ops_On_Target)
4110 function Target_Has_Fixed_Ops
4111 (Left_Typ
: Entity_Id
;
4112 Right_Typ
: Entity_Id
;
4113 Result_Typ
: Entity_Id
) return Boolean
4115 function Is_Fractional_Type
(Typ
: Entity_Id
) return Boolean;
4116 -- Return True if the given type is a fixed-point type with a small
4117 -- value equal to 2 ** (-(T'Object_Size - 1)) and whose values have
4118 -- an absolute value less than 1.0. This is currently limited
4119 -- to fixed-point types that map to Integer or Long_Integer.
4121 ------------------------
4122 -- Is_Fractional_Type --
4123 ------------------------
4125 function Is_Fractional_Type
(Typ
: Entity_Id
) return Boolean is
4127 if Esize
(Typ
) = Standard_Integer_Size
then
4128 return Small_Value
(Typ
) = Integer_Sized_Small
;
4130 elsif Esize
(Typ
) = Standard_Long_Integer_Size
then
4131 return Small_Value
(Typ
) = Long_Integer_Sized_Small
;
4136 end Is_Fractional_Type
;
4138 -- Start of processing for Target_Has_Fixed_Ops
4141 -- Return False if Fractional_Fixed_Ops_On_Target is false
4143 if not Fractional_Fixed_Ops_On_Target
then
4147 -- Here the target has Fractional_Fixed_Ops, if first time, compute
4148 -- standard constants used by Is_Fractional_Type.
4150 if First_Time_For_THFO
then
4151 First_Time_For_THFO
:= False;
4153 Integer_Sized_Small
:=
4156 Den
=> UI_From_Int
(Standard_Integer_Size
- 1),
4159 Long_Integer_Sized_Small
:=
4162 Den
=> UI_From_Int
(Standard_Long_Integer_Size
- 1),
4166 -- Return True if target supports fixed-by-fixed multiply/divide
4167 -- for fractional fixed-point types (see Is_Fractional_Type) and
4168 -- the operand and result types are equivalent fractional types.
4170 return Is_Fractional_Type
(Base_Type
(Left_Typ
))
4171 and then Is_Fractional_Type
(Base_Type
(Right_Typ
))
4172 and then Is_Fractional_Type
(Base_Type
(Result_Typ
))
4173 and then Esize
(Left_Typ
) = Esize
(Right_Typ
)
4174 and then Esize
(Left_Typ
) = Esize
(Result_Typ
);
4175 end Target_Has_Fixed_Ops
;
4177 ------------------------------------------
4178 -- Type_May_Have_Bit_Aligned_Components --
4179 ------------------------------------------
4181 function Type_May_Have_Bit_Aligned_Components
4182 (Typ
: Entity_Id
) return Boolean
4185 -- Array type, check component type
4187 if Is_Array_Type
(Typ
) then
4189 Type_May_Have_Bit_Aligned_Components
(Component_Type
(Typ
));
4191 -- Record type, check components
4193 elsif Is_Record_Type
(Typ
) then
4198 E
:= First_Entity
(Typ
);
4199 while Present
(E
) loop
4200 if Ekind
(E
) = E_Component
4201 or else Ekind
(E
) = E_Discriminant
4203 if Component_May_Be_Bit_Aligned
(E
)
4205 Type_May_Have_Bit_Aligned_Components
(Etype
(E
))
4217 -- Type other than array or record is always OK
4222 end Type_May_Have_Bit_Aligned_Components
;
4224 ----------------------------
4225 -- Wrap_Cleanup_Procedure --
4226 ----------------------------
4228 procedure Wrap_Cleanup_Procedure
(N
: Node_Id
) is
4229 Loc
: constant Source_Ptr
:= Sloc
(N
);
4230 Stseq
: constant Node_Id
:= Handled_Statement_Sequence
(N
);
4231 Stmts
: constant List_Id
:= Statements
(Stseq
);
4234 if Abort_Allowed
then
4235 Prepend_To
(Stmts
, Build_Runtime_Call
(Loc
, RE_Abort_Defer
));
4236 Append_To
(Stmts
, Build_Runtime_Call
(Loc
, RE_Abort_Undefer
));
4238 end Wrap_Cleanup_Procedure
;