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_Ch7
; use Exp_Ch7
;
33 with Exp_Ch11
; use Exp_Ch11
;
34 with Exp_Tss
; use Exp_Tss
;
35 with Hostparm
; use Hostparm
;
36 with Inline
; use Inline
;
37 with Itypes
; use Itypes
;
39 with Namet
; use Namet
;
40 with Nlists
; use Nlists
;
41 with Nmake
; use Nmake
;
43 with Restrict
; use Restrict
;
44 with Rident
; use Rident
;
46 with Sem_Ch8
; use Sem_Ch8
;
47 with Sem_Eval
; use Sem_Eval
;
48 with Sem_Res
; use Sem_Res
;
49 with Sem_Util
; use Sem_Util
;
50 with Sinfo
; use Sinfo
;
51 with Snames
; use Snames
;
52 with Stand
; use Stand
;
53 with Stringt
; use Stringt
;
54 with Targparm
; use Targparm
;
55 with Tbuild
; use Tbuild
;
56 with Ttypes
; use Ttypes
;
57 with Uintp
; use Uintp
;
58 with Urealp
; use Urealp
;
59 with Validsw
; use Validsw
;
61 package body Exp_Util
is
63 -----------------------
64 -- Local Subprograms --
65 -----------------------
67 function Build_Task_Array_Image
71 Dyn
: Boolean := False) return Node_Id
;
72 -- Build function to generate the image string for a task that is an
73 -- array component, concatenating the images of each index. To avoid
74 -- storage leaks, the string is built with successive slice assignments.
75 -- The flag Dyn indicates whether this is called for the initialization
76 -- procedure of an array of tasks, or for the name of a dynamically
77 -- created task that is assigned to an indexed component.
79 function Build_Task_Image_Function
83 Res
: Entity_Id
) return Node_Id
;
84 -- Common processing for Task_Array_Image and Task_Record_Image.
85 -- Build function body that computes image.
87 procedure Build_Task_Image_Prefix
94 Decls
: in out List_Id
;
95 Stats
: in out List_Id
);
96 -- Common processing for Task_Array_Image and Task_Record_Image.
97 -- Create local variables and assign prefix of name to result string.
99 function Build_Task_Record_Image
102 Dyn
: Boolean := False) return Node_Id
;
103 -- Build function to generate the image string for a task that is a
104 -- record component. Concatenate name of variable with that of selector.
105 -- The flag Dyn indicates whether this is called for the initialization
106 -- procedure of record with task components, or for a dynamically
107 -- created task that is assigned to a selected component.
109 function Make_CW_Equivalent_Type
111 E
: Node_Id
) return Entity_Id
;
112 -- T is a class-wide type entity, E is the initial expression node that
113 -- constrains T in case such as: " X: T := E" or "new T'(E)"
114 -- This function returns the entity of the Equivalent type and inserts
115 -- on the fly the necessary declaration such as:
117 -- type anon is record
118 -- _parent : Root_Type (T); constrained with E discriminants (if any)
119 -- Extension : String (1 .. expr to match size of E);
122 -- This record is compatible with any object of the class of T thanks
123 -- to the first field and has the same size as E thanks to the second.
125 function Make_Literal_Range
127 Literal_Typ
: Entity_Id
) return Node_Id
;
128 -- Produce a Range node whose bounds are:
129 -- Low_Bound (Literal_Type) ..
130 -- Low_Bound (Literal_Type) + Length (Literal_Typ) - 1
131 -- this is used for expanding declarations like X : String := "sdfgdfg";
133 function New_Class_Wide_Subtype
135 N
: Node_Id
) return Entity_Id
;
136 -- Create an implicit subtype of CW_Typ attached to node N
138 ----------------------
139 -- Adjust_Condition --
140 ----------------------
142 procedure Adjust_Condition
(N
: Node_Id
) is
149 Loc
: constant Source_Ptr
:= Sloc
(N
);
150 T
: constant Entity_Id
:= Etype
(N
);
154 -- For now, we simply ignore a call where the argument has no
155 -- type (probably case of unanalyzed condition), or has a type
156 -- that is not Boolean. This is because this is a pretty marginal
157 -- piece of functionality, and violations of these rules are
158 -- likely to be truly marginal (how much code uses Fortran Logical
159 -- as the barrier to a protected entry?) and we do not want to
160 -- blow up existing programs. We can change this to an assertion
161 -- after 3.12a is released ???
163 if No
(T
) or else not Is_Boolean_Type
(T
) then
167 -- Apply validity checking if needed
169 if Validity_Checks_On
and Validity_Check_Tests
then
173 -- Immediate return if standard boolean, the most common case,
174 -- where nothing needs to be done.
176 if Base_Type
(T
) = Standard_Boolean
then
180 -- Case of zero/non-zero semantics or non-standard enumeration
181 -- representation. In each case, we rewrite the node as:
183 -- ityp!(N) /= False'Enum_Rep
185 -- where ityp is an integer type with large enough size to hold
186 -- any value of type T.
188 if Nonzero_Is_True
(T
) or else Has_Non_Standard_Rep
(T
) then
189 if Esize
(T
) <= Esize
(Standard_Integer
) then
190 Ti
:= Standard_Integer
;
192 Ti
:= Standard_Long_Long_Integer
;
197 Left_Opnd
=> Unchecked_Convert_To
(Ti
, N
),
199 Make_Attribute_Reference
(Loc
,
200 Attribute_Name
=> Name_Enum_Rep
,
202 New_Occurrence_Of
(First_Literal
(T
), Loc
))));
203 Analyze_And_Resolve
(N
, Standard_Boolean
);
206 Rewrite
(N
, Convert_To
(Standard_Boolean
, N
));
207 Analyze_And_Resolve
(N
, Standard_Boolean
);
210 end Adjust_Condition
;
212 ------------------------
213 -- Adjust_Result_Type --
214 ------------------------
216 procedure Adjust_Result_Type
(N
: Node_Id
; T
: Entity_Id
) is
218 -- Ignore call if current type is not Standard.Boolean
220 if Etype
(N
) /= Standard_Boolean
then
224 -- If result is already of correct type, nothing to do. Note that
225 -- this will get the most common case where everything has a type
226 -- of Standard.Boolean.
228 if Base_Type
(T
) = Standard_Boolean
then
233 KP
: constant Node_Kind
:= Nkind
(Parent
(N
));
236 -- If result is to be used as a Condition in the syntax, no need
237 -- to convert it back, since if it was changed to Standard.Boolean
238 -- using Adjust_Condition, that is just fine for this usage.
240 if KP
in N_Raise_xxx_Error
or else KP
in N_Has_Condition
then
243 -- If result is an operand of another logical operation, no need
244 -- to reset its type, since Standard.Boolean is just fine, and
245 -- such operations always do Adjust_Condition on their operands.
247 elsif KP
in N_Op_Boolean
248 or else KP
= N_And_Then
249 or else KP
= N_Or_Else
250 or else KP
= N_Op_Not
254 -- Otherwise we perform a conversion from the current type,
255 -- which must be Standard.Boolean, to the desired type.
259 Rewrite
(N
, Convert_To
(T
, N
));
260 Analyze_And_Resolve
(N
, T
);
264 end Adjust_Result_Type
;
266 --------------------------
267 -- Append_Freeze_Action --
268 --------------------------
270 procedure Append_Freeze_Action
(T
: Entity_Id
; N
: Node_Id
) is
271 Fnode
: Node_Id
:= Freeze_Node
(T
);
274 Ensure_Freeze_Node
(T
);
275 Fnode
:= Freeze_Node
(T
);
277 if not Present
(Actions
(Fnode
)) then
278 Set_Actions
(Fnode
, New_List
);
281 Append
(N
, Actions
(Fnode
));
282 end Append_Freeze_Action
;
284 ---------------------------
285 -- Append_Freeze_Actions --
286 ---------------------------
288 procedure Append_Freeze_Actions
(T
: Entity_Id
; L
: List_Id
) is
289 Fnode
: constant Node_Id
:= Freeze_Node
(T
);
296 if No
(Actions
(Fnode
)) then
297 Set_Actions
(Fnode
, L
);
300 Append_List
(L
, Actions
(Fnode
));
304 end Append_Freeze_Actions
;
306 ------------------------
307 -- Build_Runtime_Call --
308 ------------------------
310 function Build_Runtime_Call
(Loc
: Source_Ptr
; RE
: RE_Id
) return Node_Id
is
312 -- If entity is not available, we can skip making the call (this avoids
313 -- junk duplicated error messages in a number of cases).
315 if not RTE_Available
(RE
) then
316 return Make_Null_Statement
(Loc
);
319 Make_Procedure_Call_Statement
(Loc
,
320 Name
=> New_Reference_To
(RTE
(RE
), Loc
));
322 end Build_Runtime_Call
;
324 ----------------------------
325 -- Build_Task_Array_Image --
326 ----------------------------
328 -- This function generates the body for a function that constructs the
329 -- image string for a task that is an array component. The function is
330 -- local to the init proc for the array type, and is called for each one
331 -- of the components. The constructed image has the form of an indexed
332 -- component, whose prefix is the outer variable of the array type.
333 -- The n-dimensional array type has known indices Index, Index2...
334 -- Id_Ref is an indexed component form created by the enclosing init proc.
335 -- Its successive indices are Val1, Val2,.. which are the loop variables
336 -- in the loops that call the individual task init proc on each component.
338 -- The generated function has the following structure:
340 -- function F return String is
341 -- Pref : string renames Task_Name;
342 -- T1 : String := Index1'Image (Val1);
344 -- Tn : String := indexn'image (Valn);
345 -- Len : Integer := T1'Length + ... + Tn'Length + n + 1;
346 -- -- Len includes commas and the end parentheses.
347 -- Res : String (1..Len);
348 -- Pos : Integer := Pref'Length;
351 -- Res (1 .. Pos) := Pref;
355 -- Res (Pos .. Pos + T1'Length - 1) := T1;
356 -- Pos := Pos + T1'Length;
360 -- Res (Pos .. Pos + Tn'Length - 1) := Tn;
366 -- Needless to say, multidimensional arrays of tasks are rare enough
367 -- that the bulkiness of this code is not really a concern.
369 function Build_Task_Array_Image
373 Dyn
: Boolean := False) return Node_Id
375 Dims
: constant Nat
:= Number_Dimensions
(A_Type
);
376 -- Number of dimensions for array of tasks
378 Temps
: array (1 .. Dims
) of Entity_Id
;
379 -- Array of temporaries to hold string for each index
385 -- Total length of generated name
388 -- Running index for substring assignments
391 -- Name of enclosing variable, prefix of resulting name
394 -- String to hold result
397 -- Value of successive indices
400 -- Expression to compute total size of string
403 -- Entity for name at one index position
405 Decls
: List_Id
:= New_List
;
406 Stats
: List_Id
:= New_List
;
409 Pref
:= Make_Defining_Identifier
(Loc
, New_Internal_Name
('P'));
411 -- For a dynamic task, the name comes from the target variable.
412 -- For a static one it is a formal of the enclosing init proc.
415 Get_Name_String
(Chars
(Entity
(Prefix
(Id_Ref
))));
417 Make_Object_Declaration
(Loc
,
418 Defining_Identifier
=> Pref
,
419 Object_Definition
=> New_Occurrence_Of
(Standard_String
, Loc
),
421 Make_String_Literal
(Loc
,
422 Strval
=> String_From_Name_Buffer
)));
426 Make_Object_Renaming_Declaration
(Loc
,
427 Defining_Identifier
=> Pref
,
428 Subtype_Mark
=> New_Occurrence_Of
(Standard_String
, Loc
),
429 Name
=> Make_Identifier
(Loc
, Name_uTask_Name
)));
432 Indx
:= First_Index
(A_Type
);
433 Val
:= First
(Expressions
(Id_Ref
));
435 for J
in 1 .. Dims
loop
436 T
:= Make_Defining_Identifier
(Loc
, New_Internal_Name
('T'));
440 Make_Object_Declaration
(Loc
,
441 Defining_Identifier
=> T
,
442 Object_Definition
=> New_Occurrence_Of
(Standard_String
, Loc
),
444 Make_Attribute_Reference
(Loc
,
445 Attribute_Name
=> Name_Image
,
447 New_Occurrence_Of
(Etype
(Indx
), Loc
),
448 Expressions
=> New_List
(
449 New_Copy_Tree
(Val
)))));
455 Sum
:= Make_Integer_Literal
(Loc
, Dims
+ 1);
461 Make_Attribute_Reference
(Loc
,
462 Attribute_Name
=> Name_Length
,
464 New_Occurrence_Of
(Pref
, Loc
),
465 Expressions
=> New_List
(Make_Integer_Literal
(Loc
, 1))));
467 for J
in 1 .. Dims
loop
472 Make_Attribute_Reference
(Loc
,
473 Attribute_Name
=> Name_Length
,
475 New_Occurrence_Of
(Temps
(J
), Loc
),
476 Expressions
=> New_List
(Make_Integer_Literal
(Loc
, 1))));
479 Build_Task_Image_Prefix
(Loc
, Len
, Res
, Pos
, Pref
, Sum
, Decls
, Stats
);
481 Set_Character_Literal_Name
(Char_Code
(Character'Pos ('(')));
484 Make_Assignment_Statement
(Loc
,
485 Name
=> Make_Indexed_Component
(Loc
,
486 Prefix
=> New_Occurrence_Of
(Res
, Loc
),
487 Expressions
=> New_List
(New_Occurrence_Of
(Pos
, Loc
))),
489 Make_Character_Literal
(Loc
,
491 Char_Literal_Value
=>
492 UI_From_Int
(Character'Pos ('(')))));
495 Make_Assignment_Statement
(Loc
,
496 Name
=> New_Occurrence_Of
(Pos
, Loc
),
499 Left_Opnd
=> New_Occurrence_Of
(Pos
, Loc
),
500 Right_Opnd
=> Make_Integer_Literal
(Loc
, 1))));
502 for J
in 1 .. Dims
loop
505 Make_Assignment_Statement
(Loc
,
506 Name
=> Make_Slice
(Loc
,
507 Prefix
=> New_Occurrence_Of
(Res
, Loc
),
510 Low_Bound
=> New_Occurrence_Of
(Pos
, Loc
),
511 High_Bound
=> Make_Op_Subtract
(Loc
,
514 Left_Opnd
=> New_Occurrence_Of
(Pos
, Loc
),
516 Make_Attribute_Reference
(Loc
,
517 Attribute_Name
=> Name_Length
,
519 New_Occurrence_Of
(Temps
(J
), Loc
),
521 New_List
(Make_Integer_Literal
(Loc
, 1)))),
522 Right_Opnd
=> Make_Integer_Literal
(Loc
, 1)))),
524 Expression
=> New_Occurrence_Of
(Temps
(J
), Loc
)));
528 Make_Assignment_Statement
(Loc
,
529 Name
=> New_Occurrence_Of
(Pos
, Loc
),
532 Left_Opnd
=> New_Occurrence_Of
(Pos
, Loc
),
534 Make_Attribute_Reference
(Loc
,
535 Attribute_Name
=> Name_Length
,
536 Prefix
=> New_Occurrence_Of
(Temps
(J
), Loc
),
538 New_List
(Make_Integer_Literal
(Loc
, 1))))));
540 Set_Character_Literal_Name
(Char_Code
(Character'Pos (',')));
543 Make_Assignment_Statement
(Loc
,
544 Name
=> Make_Indexed_Component
(Loc
,
545 Prefix
=> New_Occurrence_Of
(Res
, Loc
),
546 Expressions
=> New_List
(New_Occurrence_Of
(Pos
, Loc
))),
548 Make_Character_Literal
(Loc
,
550 Char_Literal_Value
=>
551 UI_From_Int
(Character'Pos (',')))));
554 Make_Assignment_Statement
(Loc
,
555 Name
=> New_Occurrence_Of
(Pos
, Loc
),
558 Left_Opnd
=> New_Occurrence_Of
(Pos
, Loc
),
559 Right_Opnd
=> Make_Integer_Literal
(Loc
, 1))));
563 Set_Character_Literal_Name
(Char_Code
(Character'Pos (')')));
566 Make_Assignment_Statement
(Loc
,
567 Name
=> Make_Indexed_Component
(Loc
,
568 Prefix
=> New_Occurrence_Of
(Res
, Loc
),
569 Expressions
=> New_List
(New_Occurrence_Of
(Len
, Loc
))),
571 Make_Character_Literal
(Loc
,
573 Char_Literal_Value
=>
574 UI_From_Int
(Character'Pos (')')))));
575 return Build_Task_Image_Function
(Loc
, Decls
, Stats
, Res
);
576 end Build_Task_Array_Image
;
578 ----------------------------
579 -- Build_Task_Image_Decls --
580 ----------------------------
582 function Build_Task_Image_Decls
585 A_Type
: Entity_Id
) return List_Id
587 Decls
: constant List_Id
:= New_List
;
588 T_Id
: Entity_Id
:= Empty
;
590 Expr
: Node_Id
:= Empty
;
591 Fun
: Node_Id
:= Empty
;
592 Is_Dyn
: constant Boolean :=
593 Nkind
(Parent
(Id_Ref
)) = N_Assignment_Statement
595 Nkind
(Expression
(Parent
(Id_Ref
))) = N_Allocator
;
598 -- If Discard_Names or No_Implicit_Heap_Allocations are in effect,
599 -- generate a dummy declaration only.
601 if Restriction_Active
(No_Implicit_Heap_Allocations
)
602 or else Global_Discard_Names
604 T_Id
:= Make_Defining_Identifier
(Loc
, New_Internal_Name
('J'));
609 Make_Object_Declaration
(Loc
,
610 Defining_Identifier
=> T_Id
,
611 Object_Definition
=> New_Occurrence_Of
(Standard_String
, Loc
),
613 Make_String_Literal
(Loc
,
614 Strval
=> String_From_Name_Buffer
)));
617 if Nkind
(Id_Ref
) = N_Identifier
618 or else Nkind
(Id_Ref
) = N_Defining_Identifier
620 -- For a simple variable, the image of the task is built from
621 -- the name of the variable. To avoid possible conflict with
622 -- the anonymous type created for a single protected object,
623 -- add a numeric suffix.
626 Make_Defining_Identifier
(Loc
,
627 New_External_Name
(Chars
(Id_Ref
), 'T', 1));
629 Get_Name_String
(Chars
(Id_Ref
));
632 Make_String_Literal
(Loc
,
633 Strval
=> String_From_Name_Buffer
);
635 elsif Nkind
(Id_Ref
) = N_Selected_Component
then
637 Make_Defining_Identifier
(Loc
,
638 New_External_Name
(Chars
(Selector_Name
(Id_Ref
)), 'T'));
639 Fun
:= Build_Task_Record_Image
(Loc
, Id_Ref
, Is_Dyn
);
641 elsif Nkind
(Id_Ref
) = N_Indexed_Component
then
643 Make_Defining_Identifier
(Loc
,
644 New_External_Name
(Chars
(A_Type
), 'N'));
646 Fun
:= Build_Task_Array_Image
(Loc
, Id_Ref
, A_Type
, Is_Dyn
);
650 if Present
(Fun
) then
652 Expr
:= Make_Function_Call
(Loc
,
653 Name
=> New_Occurrence_Of
(Defining_Entity
(Fun
), Loc
));
656 Decl
:= Make_Object_Declaration
(Loc
,
657 Defining_Identifier
=> T_Id
,
658 Object_Definition
=> New_Occurrence_Of
(Standard_String
, Loc
),
659 Constant_Present
=> True,
662 Append
(Decl
, Decls
);
664 end Build_Task_Image_Decls
;
666 -------------------------------
667 -- Build_Task_Image_Function --
668 -------------------------------
670 function Build_Task_Image_Function
674 Res
: Entity_Id
) return Node_Id
680 Make_Return_Statement
(Loc
,
681 Expression
=> New_Occurrence_Of
(Res
, Loc
)));
683 Spec
:= Make_Function_Specification
(Loc
,
684 Defining_Unit_Name
=>
685 Make_Defining_Identifier
(Loc
, New_Internal_Name
('F')),
686 Subtype_Mark
=> New_Occurrence_Of
(Standard_String
, Loc
));
688 -- Calls to 'Image use the secondary stack, which must be cleaned
689 -- up after the task name is built.
691 Set_Uses_Sec_Stack
(Defining_Unit_Name
(Spec
));
693 return Make_Subprogram_Body
(Loc
,
694 Specification
=> Spec
,
695 Declarations
=> Decls
,
696 Handled_Statement_Sequence
=>
697 Make_Handled_Sequence_Of_Statements
(Loc
, Statements
=> Stats
));
698 end Build_Task_Image_Function
;
700 -----------------------------
701 -- Build_Task_Image_Prefix --
702 -----------------------------
704 procedure Build_Task_Image_Prefix
711 Decls
: in out List_Id
;
712 Stats
: in out List_Id
)
715 Len
:= Make_Defining_Identifier
(Loc
, New_Internal_Name
('L'));
718 Make_Object_Declaration
(Loc
,
719 Defining_Identifier
=> Len
,
720 Object_Definition
=> New_Occurrence_Of
(Standard_Integer
, Loc
),
723 Res
:= Make_Defining_Identifier
(Loc
, New_Internal_Name
('R'));
726 Make_Object_Declaration
(Loc
,
727 Defining_Identifier
=> Res
,
729 Make_Subtype_Indication
(Loc
,
730 Subtype_Mark
=> New_Occurrence_Of
(Standard_String
, Loc
),
732 Make_Index_Or_Discriminant_Constraint
(Loc
,
736 Low_Bound
=> Make_Integer_Literal
(Loc
, 1),
737 High_Bound
=> New_Occurrence_Of
(Len
, Loc
)))))));
739 Pos
:= Make_Defining_Identifier
(Loc
, New_Internal_Name
('P'));
742 Make_Object_Declaration
(Loc
,
743 Defining_Identifier
=> Pos
,
744 Object_Definition
=> New_Occurrence_Of
(Standard_Integer
, Loc
)));
746 -- Pos := Prefix'Length;
749 Make_Assignment_Statement
(Loc
,
750 Name
=> New_Occurrence_Of
(Pos
, Loc
),
752 Make_Attribute_Reference
(Loc
,
753 Attribute_Name
=> Name_Length
,
754 Prefix
=> New_Occurrence_Of
(Prefix
, Loc
),
756 New_List
(Make_Integer_Literal
(Loc
, 1)))));
758 -- Res (1 .. Pos) := Prefix;
761 Make_Assignment_Statement
(Loc
,
762 Name
=> Make_Slice
(Loc
,
763 Prefix
=> New_Occurrence_Of
(Res
, Loc
),
766 Low_Bound
=> Make_Integer_Literal
(Loc
, 1),
767 High_Bound
=> New_Occurrence_Of
(Pos
, Loc
))),
769 Expression
=> New_Occurrence_Of
(Prefix
, Loc
)));
772 Make_Assignment_Statement
(Loc
,
773 Name
=> New_Occurrence_Of
(Pos
, Loc
),
776 Left_Opnd
=> New_Occurrence_Of
(Pos
, Loc
),
777 Right_Opnd
=> Make_Integer_Literal
(Loc
, 1))));
778 end Build_Task_Image_Prefix
;
780 -----------------------------
781 -- Build_Task_Record_Image --
782 -----------------------------
784 function Build_Task_Record_Image
787 Dyn
: Boolean := False) return Node_Id
790 -- Total length of generated name
796 -- String to hold result
799 -- Name of enclosing variable, prefix of resulting name
802 -- Expression to compute total size of string
805 -- Entity for selector name
807 Decls
: List_Id
:= New_List
;
808 Stats
: List_Id
:= New_List
;
811 Pref
:= Make_Defining_Identifier
(Loc
, New_Internal_Name
('P'));
813 -- For a dynamic task, the name comes from the target variable.
814 -- For a static one it is a formal of the enclosing init proc.
817 Get_Name_String
(Chars
(Entity
(Prefix
(Id_Ref
))));
819 Make_Object_Declaration
(Loc
,
820 Defining_Identifier
=> Pref
,
821 Object_Definition
=> New_Occurrence_Of
(Standard_String
, Loc
),
823 Make_String_Literal
(Loc
,
824 Strval
=> String_From_Name_Buffer
)));
828 Make_Object_Renaming_Declaration
(Loc
,
829 Defining_Identifier
=> Pref
,
830 Subtype_Mark
=> New_Occurrence_Of
(Standard_String
, Loc
),
831 Name
=> Make_Identifier
(Loc
, Name_uTask_Name
)));
834 Sel
:= Make_Defining_Identifier
(Loc
, New_Internal_Name
('S'));
836 Get_Name_String
(Chars
(Selector_Name
(Id_Ref
)));
839 Make_Object_Declaration
(Loc
,
840 Defining_Identifier
=> Sel
,
841 Object_Definition
=> New_Occurrence_Of
(Standard_String
, Loc
),
843 Make_String_Literal
(Loc
,
844 Strval
=> String_From_Name_Buffer
)));
846 Sum
:= Make_Integer_Literal
(Loc
, Nat
(Name_Len
+ 1));
852 Make_Attribute_Reference
(Loc
,
853 Attribute_Name
=> Name_Length
,
855 New_Occurrence_Of
(Pref
, Loc
),
856 Expressions
=> New_List
(Make_Integer_Literal
(Loc
, 1))));
858 Build_Task_Image_Prefix
(Loc
, Len
, Res
, Pos
, Pref
, Sum
, Decls
, Stats
);
860 Set_Character_Literal_Name
(Char_Code
(Character'Pos ('.')));
865 Make_Assignment_Statement
(Loc
,
866 Name
=> Make_Indexed_Component
(Loc
,
867 Prefix
=> New_Occurrence_Of
(Res
, Loc
),
868 Expressions
=> New_List
(New_Occurrence_Of
(Pos
, Loc
))),
870 Make_Character_Literal
(Loc
,
872 Char_Literal_Value
=>
873 UI_From_Int
(Character'Pos ('.')))));
876 Make_Assignment_Statement
(Loc
,
877 Name
=> New_Occurrence_Of
(Pos
, Loc
),
880 Left_Opnd
=> New_Occurrence_Of
(Pos
, Loc
),
881 Right_Opnd
=> Make_Integer_Literal
(Loc
, 1))));
883 -- Res (Pos .. Len) := Selector;
886 Make_Assignment_Statement
(Loc
,
887 Name
=> Make_Slice
(Loc
,
888 Prefix
=> New_Occurrence_Of
(Res
, Loc
),
891 Low_Bound
=> New_Occurrence_Of
(Pos
, Loc
),
892 High_Bound
=> New_Occurrence_Of
(Len
, Loc
))),
893 Expression
=> New_Occurrence_Of
(Sel
, Loc
)));
895 return Build_Task_Image_Function
(Loc
, Decls
, Stats
, Res
);
896 end Build_Task_Record_Image
;
898 ----------------------------------
899 -- Component_May_Be_Bit_Aligned --
900 ----------------------------------
902 function Component_May_Be_Bit_Aligned
(Comp
: Entity_Id
) return Boolean is
904 -- If no component clause, then everything is fine, since the
905 -- back end never bit-misaligns by default, even if there is
906 -- a pragma Packed for the record.
908 if No
(Component_Clause
(Comp
)) then
912 -- It is only array and record types that cause trouble
914 if not Is_Record_Type
(Etype
(Comp
))
915 and then not Is_Array_Type
(Etype
(Comp
))
919 -- If we know that we have a small (64 bits or less) record
920 -- or bit-packed array, then everything is fine, since the
921 -- back end can handle these cases correctly.
923 elsif Esize
(Comp
) <= 64
924 and then (Is_Record_Type
(Etype
(Comp
))
925 or else Is_Bit_Packed_Array
(Etype
(Comp
)))
929 -- Otherwise if the component is not byte aligned, we
930 -- know we have the nasty unaligned case.
932 elsif Normalized_First_Bit
(Comp
) /= Uint_0
933 or else Esize
(Comp
) mod System_Storage_Unit
/= Uint_0
937 -- If we are large and byte aligned, then OK at this level
942 end Component_May_Be_Bit_Aligned
;
944 -------------------------------
945 -- Convert_To_Actual_Subtype --
946 -------------------------------
948 procedure Convert_To_Actual_Subtype
(Exp
: Entity_Id
) is
952 Act_ST
:= Get_Actual_Subtype
(Exp
);
954 if Act_ST
= Etype
(Exp
) then
959 Convert_To
(Act_ST
, Relocate_Node
(Exp
)));
960 Analyze_And_Resolve
(Exp
, Act_ST
);
962 end Convert_To_Actual_Subtype
;
964 -----------------------------------
965 -- Current_Sem_Unit_Declarations --
966 -----------------------------------
968 function Current_Sem_Unit_Declarations
return List_Id
is
969 U
: Node_Id
:= Unit
(Cunit
(Current_Sem_Unit
));
973 -- If the current unit is a package body, locate the visible
974 -- declarations of the package spec.
976 if Nkind
(U
) = N_Package_Body
then
977 U
:= Unit
(Library_Unit
(Cunit
(Current_Sem_Unit
)));
980 if Nkind
(U
) = N_Package_Declaration
then
981 U
:= Specification
(U
);
982 Decls
:= Visible_Declarations
(U
);
986 Set_Visible_Declarations
(U
, Decls
);
990 Decls
:= Declarations
(U
);
994 Set_Declarations
(U
, Decls
);
999 end Current_Sem_Unit_Declarations
;
1001 -----------------------
1002 -- Duplicate_Subexpr --
1003 -----------------------
1005 function Duplicate_Subexpr
1007 Name_Req
: Boolean := False) return Node_Id
1010 Remove_Side_Effects
(Exp
, Name_Req
);
1011 return New_Copy_Tree
(Exp
);
1012 end Duplicate_Subexpr
;
1014 ---------------------------------
1015 -- Duplicate_Subexpr_No_Checks --
1016 ---------------------------------
1018 function Duplicate_Subexpr_No_Checks
1020 Name_Req
: Boolean := False) return Node_Id
1025 Remove_Side_Effects
(Exp
, Name_Req
);
1026 New_Exp
:= New_Copy_Tree
(Exp
);
1027 Remove_Checks
(New_Exp
);
1029 end Duplicate_Subexpr_No_Checks
;
1031 -----------------------------------
1032 -- Duplicate_Subexpr_Move_Checks --
1033 -----------------------------------
1035 function Duplicate_Subexpr_Move_Checks
1037 Name_Req
: Boolean := False) return Node_Id
1042 Remove_Side_Effects
(Exp
, Name_Req
);
1043 New_Exp
:= New_Copy_Tree
(Exp
);
1044 Remove_Checks
(Exp
);
1046 end Duplicate_Subexpr_Move_Checks
;
1048 --------------------
1049 -- Ensure_Defined --
1050 --------------------
1052 procedure Ensure_Defined
(Typ
: Entity_Id
; N
: Node_Id
) is
1057 if Is_Itype
(Typ
) then
1058 IR
:= Make_Itype_Reference
(Sloc
(N
));
1059 Set_Itype
(IR
, Typ
);
1061 if not In_Open_Scopes
(Scope
(Typ
))
1062 and then Is_Subprogram
(Current_Scope
)
1063 and then Scope
(Current_Scope
) /= Standard_Standard
1065 -- Insert node in front of subprogram, to avoid scope anomalies
1070 and then Nkind
(P
) /= N_Subprogram_Body
1076 Insert_Action
(P
, IR
);
1078 Insert_Action
(N
, IR
);
1082 Insert_Action
(N
, IR
);
1087 ---------------------
1088 -- Evolve_And_Then --
1089 ---------------------
1091 procedure Evolve_And_Then
(Cond
: in out Node_Id
; Cond1
: Node_Id
) is
1097 Make_And_Then
(Sloc
(Cond1
),
1099 Right_Opnd
=> Cond1
);
1101 end Evolve_And_Then
;
1103 --------------------
1104 -- Evolve_Or_Else --
1105 --------------------
1107 procedure Evolve_Or_Else
(Cond
: in out Node_Id
; Cond1
: Node_Id
) is
1113 Make_Or_Else
(Sloc
(Cond1
),
1115 Right_Opnd
=> Cond1
);
1119 ------------------------------
1120 -- Expand_Subtype_From_Expr --
1121 ------------------------------
1123 -- This function is applicable for both static and dynamic allocation of
1124 -- objects which are constrained by an initial expression. Basically it
1125 -- transforms an unconstrained subtype indication into a constrained one.
1126 -- The expression may also be transformed in certain cases in order to
1127 -- avoid multiple evaulation. In the static allocation case, the general
1132 -- is transformed into
1134 -- Val : Constrained_Subtype_of_T := Maybe_Modified_Expr;
1136 -- Here are the main cases :
1138 -- <if Expr is a Slice>
1139 -- Val : T ([Index_Subtype (Expr)]) := Expr;
1141 -- <elsif Expr is a String Literal>
1142 -- Val : T (T'First .. T'First + Length (string literal) - 1) := Expr;
1144 -- <elsif Expr is Constrained>
1145 -- subtype T is Type_Of_Expr
1148 -- <elsif Expr is an entity_name>
1149 -- Val : T (constraints taken from Expr) := Expr;
1152 -- type Axxx is access all T;
1153 -- Rval : Axxx := Expr'ref;
1154 -- Val : T (constraints taken from Rval) := Rval.all;
1156 -- ??? note: when the Expression is allocated in the secondary stack
1157 -- we could use it directly instead of copying it by declaring
1158 -- Val : T (...) renames Rval.all
1160 procedure Expand_Subtype_From_Expr
1162 Unc_Type
: Entity_Id
;
1163 Subtype_Indic
: Node_Id
;
1166 Loc
: constant Source_Ptr
:= Sloc
(N
);
1167 Exp_Typ
: constant Entity_Id
:= Etype
(Exp
);
1171 -- In general we cannot build the subtype if expansion is disabled,
1172 -- because internal entities may not have been defined. However, to
1173 -- avoid some cascaded errors, we try to continue when the expression
1174 -- is an array (or string), because it is safe to compute the bounds.
1175 -- It is in fact required to do so even in a generic context, because
1176 -- there may be constants that depend on bounds of string literal.
1178 if not Expander_Active
1179 and then (No
(Etype
(Exp
))
1180 or else Base_Type
(Etype
(Exp
)) /= Standard_String
)
1185 if Nkind
(Exp
) = N_Slice
then
1187 Slice_Type
: constant Entity_Id
:= Etype
(First_Index
(Exp_Typ
));
1190 Rewrite
(Subtype_Indic
,
1191 Make_Subtype_Indication
(Loc
,
1192 Subtype_Mark
=> New_Reference_To
(Unc_Type
, Loc
),
1194 Make_Index_Or_Discriminant_Constraint
(Loc
,
1195 Constraints
=> New_List
1196 (New_Reference_To
(Slice_Type
, Loc
)))));
1198 -- This subtype indication may be used later for contraint checks
1199 -- we better make sure that if a variable was used as a bound of
1200 -- of the original slice, its value is frozen.
1202 Force_Evaluation
(Low_Bound
(Scalar_Range
(Slice_Type
)));
1203 Force_Evaluation
(High_Bound
(Scalar_Range
(Slice_Type
)));
1206 elsif Ekind
(Exp_Typ
) = E_String_Literal_Subtype
then
1207 Rewrite
(Subtype_Indic
,
1208 Make_Subtype_Indication
(Loc
,
1209 Subtype_Mark
=> New_Reference_To
(Unc_Type
, Loc
),
1211 Make_Index_Or_Discriminant_Constraint
(Loc
,
1212 Constraints
=> New_List
(
1213 Make_Literal_Range
(Loc
,
1214 Literal_Typ
=> Exp_Typ
)))));
1216 elsif Is_Constrained
(Exp_Typ
)
1217 and then not Is_Class_Wide_Type
(Unc_Type
)
1219 if Is_Itype
(Exp_Typ
) then
1221 -- No need to generate a new one
1227 Make_Defining_Identifier
(Loc
,
1228 Chars
=> New_Internal_Name
('T'));
1231 Make_Subtype_Declaration
(Loc
,
1232 Defining_Identifier
=> T
,
1233 Subtype_Indication
=> New_Reference_To
(Exp_Typ
, Loc
)));
1235 -- This type is marked as an itype even though it has an
1236 -- explicit declaration because otherwise it can be marked
1237 -- with Is_Generic_Actual_Type and generate spurious errors.
1238 -- (see sem_ch8.Analyze_Package_Renaming and sem_type.covers)
1241 Set_Associated_Node_For_Itype
(T
, Exp
);
1244 Rewrite
(Subtype_Indic
, New_Reference_To
(T
, Loc
));
1246 -- nothing needs to be done for private types with unknown discriminants
1247 -- if the underlying type is not an unconstrained composite type.
1249 elsif Is_Private_Type
(Unc_Type
)
1250 and then Has_Unknown_Discriminants
(Unc_Type
)
1251 and then (not Is_Composite_Type
(Underlying_Type
(Unc_Type
))
1252 or else Is_Constrained
(Underlying_Type
(Unc_Type
)))
1257 Remove_Side_Effects
(Exp
);
1258 Rewrite
(Subtype_Indic
,
1259 Make_Subtype_From_Expr
(Exp
, Unc_Type
));
1261 end Expand_Subtype_From_Expr
;
1267 function Find_Prim_Op
(T
: Entity_Id
; Name
: Name_Id
) return Entity_Id
is
1269 Typ
: Entity_Id
:= T
;
1272 if Is_Class_Wide_Type
(Typ
) then
1273 Typ
:= Root_Type
(Typ
);
1276 Typ
:= Underlying_Type
(Typ
);
1278 Prim
:= First_Elmt
(Primitive_Operations
(Typ
));
1279 while Chars
(Node
(Prim
)) /= Name
loop
1281 pragma Assert
(Present
(Prim
));
1287 function Find_Prim_Op
1289 Name
: TSS_Name_Type
) return Entity_Id
1292 Typ
: Entity_Id
:= T
;
1295 if Is_Class_Wide_Type
(Typ
) then
1296 Typ
:= Root_Type
(Typ
);
1299 Typ
:= Underlying_Type
(Typ
);
1301 Prim
:= First_Elmt
(Primitive_Operations
(Typ
));
1302 while not Is_TSS
(Node
(Prim
), Name
) loop
1304 pragma Assert
(Present
(Prim
));
1310 ----------------------
1311 -- Force_Evaluation --
1312 ----------------------
1314 procedure Force_Evaluation
(Exp
: Node_Id
; Name_Req
: Boolean := False) is
1315 Component_In_Lhs
: Boolean := False;
1319 -- Loop to determine whether there is a component reference in
1320 -- the left hand side if Exp appears on the left side of an
1321 -- assignment statement. Needed to determine if form of result
1322 -- must be a variable.
1327 (Nkind
(Par
) = N_Selected_Component
1329 Nkind
(Par
) = N_Indexed_Component
)
1331 if Nkind
(Parent
(Par
)) = N_Assignment_Statement
1332 and then Par
= Name
(Parent
(Par
))
1334 Component_In_Lhs
:= True;
1337 Par
:= Parent
(Par
);
1341 -- If the expression is a selected component, it is being evaluated
1342 -- as part of a discriminant check. If it is part of a left-hand
1343 -- side, this is the last use of its value and it is safe to create
1344 -- a renaming for it, rather than a temporary. In addition, if it
1345 -- is not an addressable field, creating a temporary may be a problem
1346 -- for gigi, or might drop the value of the assignment. Therefore,
1347 -- if the expression is on the lhs of an assignment, remove side
1348 -- effects without requiring a temporary, and create a renaming.
1349 -- (See remove_side_effects for details).
1352 (Exp
, Name_Req
, Variable_Ref
=> not Component_In_Lhs
);
1353 end Force_Evaluation
;
1355 ------------------------
1356 -- Generate_Poll_Call --
1357 ------------------------
1359 procedure Generate_Poll_Call
(N
: Node_Id
) is
1361 -- No poll call if polling not active
1363 if not Polling_Required
then
1366 -- Otherwise generate require poll call
1369 Insert_Before_And_Analyze
(N
,
1370 Make_Procedure_Call_Statement
(Sloc
(N
),
1371 Name
=> New_Occurrence_Of
(RTE
(RE_Poll
), Sloc
(N
))));
1373 end Generate_Poll_Call
;
1375 ---------------------------------
1376 -- Get_Current_Value_Condition --
1377 ---------------------------------
1379 procedure Get_Current_Value_Condition
1384 Loc
: constant Source_Ptr
:= Sloc
(Var
);
1385 CV
: constant Node_Id
:= Current_Value
(Entity
(Var
));
1394 -- If statement. Condition is known true in THEN section, known False
1395 -- in any ELSIF or ELSE part, and unknown outside the IF statement.
1397 if Nkind
(CV
) = N_If_Statement
then
1399 -- Before start of IF statement
1401 if Loc
< Sloc
(CV
) then
1404 -- After end of IF statement
1406 elsif Loc
>= Sloc
(CV
) + Text_Ptr
(UI_To_Int
(End_Span
(CV
))) then
1410 -- At this stage we know that we are within the IF statement, but
1411 -- unfortunately, the tree does not record the SLOC of the ELSE so
1412 -- we cannot use a simple SLOC comparison to distinguish between
1413 -- the then/else statements, so we have to climb the tree.
1420 while Parent
(N
) /= CV
loop
1423 -- If we fall off the top of the tree, then that's odd, but
1424 -- perhaps it could occur in some error situation, and the
1425 -- safest response is simply to assume that the outcome of
1426 -- the condition is unknown. No point in bombing during an
1427 -- attempt to optimize things.
1434 -- Now we have N pointing to a node whose parent is the IF
1435 -- statement in question, so now we can tell if we are within
1436 -- the THEN statements.
1438 if Is_List_Member
(N
)
1439 and then List_Containing
(N
) = Then_Statements
(CV
)
1443 -- Otherwise we must be in ELSIF or ELSE part
1450 -- ELSIF part. Condition is known true within the referenced
1451 -- ELSIF, known False in any subsequent ELSIF or ELSE part,
1452 -- and unknown before the ELSE part or after the IF statement.
1454 elsif Nkind
(CV
) = N_Elsif_Part
then
1457 -- Before start of ELSIF part
1459 if Loc
< Sloc
(CV
) then
1462 -- After end of IF statement
1464 elsif Loc
>= Sloc
(Stm
) +
1465 Text_Ptr
(UI_To_Int
(End_Span
(Stm
)))
1470 -- Again we lack the SLOC of the ELSE, so we need to climb the
1471 -- tree to see if we are within the ELSIF part in question.
1478 while Parent
(N
) /= Stm
loop
1481 -- If we fall off the top of the tree, then that's odd, but
1482 -- perhaps it could occur in some error situation, and the
1483 -- safest response is simply to assume that the outcome of
1484 -- the condition is unknown. No point in bombing during an
1485 -- attempt to optimize things.
1492 -- Now we have N pointing to a node whose parent is the IF
1493 -- statement in question, so see if is the ELSIF part we want.
1494 -- the THEN statements.
1499 -- Otherwise we must be in susbequent ELSIF or ELSE part
1506 -- All other cases of Current_Value settings
1512 -- If we fall through here, then we have a reportable
1513 -- condition, Sens is True if the condition is true and
1514 -- False if it needs inverting.
1516 -- Deal with NOT operators, inverting sense
1518 Cond
:= Condition
(CV
);
1519 while Nkind
(Cond
) = N_Op_Not
loop
1520 Cond
:= Right_Opnd
(Cond
);
1524 -- Now we must have a relational operator
1526 pragma Assert
(Entity
(Var
) = Entity
(Left_Opnd
(Cond
)));
1527 Val
:= Right_Opnd
(Cond
);
1530 if Sens
= False then
1532 when N_Op_Eq
=> Op
:= N_Op_Ne
;
1533 when N_Op_Ne
=> Op
:= N_Op_Eq
;
1534 when N_Op_Lt
=> Op
:= N_Op_Ge
;
1535 when N_Op_Gt
=> Op
:= N_Op_Le
;
1536 when N_Op_Le
=> Op
:= N_Op_Gt
;
1537 when N_Op_Ge
=> Op
:= N_Op_Lt
;
1539 -- No other entry should be possible
1542 raise Program_Error
;
1545 end Get_Current_Value_Condition
;
1547 --------------------
1548 -- Homonym_Number --
1549 --------------------
1551 function Homonym_Number
(Subp
: Entity_Id
) return Nat
is
1557 Hom
:= Homonym
(Subp
);
1558 while Present
(Hom
) loop
1559 if Scope
(Hom
) = Scope
(Subp
) then
1563 Hom
:= Homonym
(Hom
);
1569 ------------------------------
1570 -- In_Unconditional_Context --
1571 ------------------------------
1573 function In_Unconditional_Context
(Node
: Node_Id
) return Boolean is
1578 while Present
(P
) loop
1580 when N_Subprogram_Body
=>
1583 when N_If_Statement
=>
1586 when N_Loop_Statement
=>
1589 when N_Case_Statement
=>
1598 end In_Unconditional_Context
;
1604 procedure Insert_Action
(Assoc_Node
: Node_Id
; Ins_Action
: Node_Id
) is
1606 if Present
(Ins_Action
) then
1607 Insert_Actions
(Assoc_Node
, New_List
(Ins_Action
));
1611 -- Version with check(s) suppressed
1613 procedure Insert_Action
1614 (Assoc_Node
: Node_Id
; Ins_Action
: Node_Id
; Suppress
: Check_Id
)
1617 Insert_Actions
(Assoc_Node
, New_List
(Ins_Action
), Suppress
);
1620 --------------------
1621 -- Insert_Actions --
1622 --------------------
1624 procedure Insert_Actions
(Assoc_Node
: Node_Id
; Ins_Actions
: List_Id
) is
1628 Wrapped_Node
: Node_Id
:= Empty
;
1631 if No
(Ins_Actions
) or else Is_Empty_List
(Ins_Actions
) then
1635 -- Ignore insert of actions from inside default expression in the
1636 -- special preliminary analyze mode. Any insertions at this point
1637 -- have no relevance, since we are only doing the analyze to freeze
1638 -- the types of any static expressions. See section "Handling of
1639 -- Default Expressions" in the spec of package Sem for further details.
1641 if In_Default_Expression
then
1645 -- If the action derives from stuff inside a record, then the actions
1646 -- are attached to the current scope, to be inserted and analyzed on
1647 -- exit from the scope. The reason for this is that we may also
1648 -- be generating freeze actions at the same time, and they must
1649 -- eventually be elaborated in the correct order.
1651 if Is_Record_Type
(Current_Scope
)
1652 and then not Is_Frozen
(Current_Scope
)
1654 if No
(Scope_Stack
.Table
1655 (Scope_Stack
.Last
).Pending_Freeze_Actions
)
1657 Scope_Stack
.Table
(Scope_Stack
.Last
).Pending_Freeze_Actions
:=
1662 Scope_Stack
.Table
(Scope_Stack
.Last
).Pending_Freeze_Actions
);
1668 -- We now intend to climb up the tree to find the right point to
1669 -- insert the actions. We start at Assoc_Node, unless this node is
1670 -- a subexpression in which case we start with its parent. We do this
1671 -- for two reasons. First it speeds things up. Second, if Assoc_Node
1672 -- is itself one of the special nodes like N_And_Then, then we assume
1673 -- that an initial request to insert actions for such a node does not
1674 -- expect the actions to get deposited in the node for later handling
1675 -- when the node is expanded, since clearly the node is being dealt
1676 -- with by the caller. Note that in the subexpression case, N is
1677 -- always the child we came from.
1679 -- N_Raise_xxx_Error is an annoying special case, it is a statement
1680 -- if it has type Standard_Void_Type, and a subexpression otherwise.
1681 -- otherwise. Procedure attribute references are also statements.
1683 if Nkind
(Assoc_Node
) in N_Subexpr
1684 and then (Nkind
(Assoc_Node
) in N_Raise_xxx_Error
1685 or else Etype
(Assoc_Node
) /= Standard_Void_Type
)
1686 and then (Nkind
(Assoc_Node
) /= N_Attribute_Reference
1688 not Is_Procedure_Attribute_Name
1689 (Attribute_Name
(Assoc_Node
)))
1691 P
:= Assoc_Node
; -- ??? does not agree with above!
1692 N
:= Parent
(Assoc_Node
);
1694 -- Non-subexpression case. Note that N is initially Empty in this
1695 -- case (N is only guaranteed Non-Empty in the subexpr case).
1702 -- Capture root of the transient scope
1704 if Scope_Is_Transient
then
1705 Wrapped_Node
:= Node_To_Be_Wrapped
;
1709 pragma Assert
(Present
(P
));
1713 -- Case of right operand of AND THEN or OR ELSE. Put the actions
1714 -- in the Actions field of the right operand. They will be moved
1715 -- out further when the AND THEN or OR ELSE operator is expanded.
1716 -- Nothing special needs to be done for the left operand since
1717 -- in that case the actions are executed unconditionally.
1719 when N_And_Then | N_Or_Else
=>
1720 if N
= Right_Opnd
(P
) then
1721 if Present
(Actions
(P
)) then
1722 Insert_List_After_And_Analyze
1723 (Last
(Actions
(P
)), Ins_Actions
);
1725 Set_Actions
(P
, Ins_Actions
);
1726 Analyze_List
(Actions
(P
));
1732 -- Then or Else operand of conditional expression. Add actions to
1733 -- Then_Actions or Else_Actions field as appropriate. The actions
1734 -- will be moved further out when the conditional is expanded.
1736 when N_Conditional_Expression
=>
1738 ThenX
: constant Node_Id
:= Next
(First
(Expressions
(P
)));
1739 ElseX
: constant Node_Id
:= Next
(ThenX
);
1742 -- Actions belong to the then expression, temporarily
1743 -- place them as Then_Actions of the conditional expr.
1744 -- They will be moved to the proper place later when
1745 -- the conditional expression is expanded.
1748 if Present
(Then_Actions
(P
)) then
1749 Insert_List_After_And_Analyze
1750 (Last
(Then_Actions
(P
)), Ins_Actions
);
1752 Set_Then_Actions
(P
, Ins_Actions
);
1753 Analyze_List
(Then_Actions
(P
));
1758 -- Actions belong to the else expression, temporarily
1759 -- place them as Else_Actions of the conditional expr.
1760 -- They will be moved to the proper place later when
1761 -- the conditional expression is expanded.
1763 elsif N
= ElseX
then
1764 if Present
(Else_Actions
(P
)) then
1765 Insert_List_After_And_Analyze
1766 (Last
(Else_Actions
(P
)), Ins_Actions
);
1768 Set_Else_Actions
(P
, Ins_Actions
);
1769 Analyze_List
(Else_Actions
(P
));
1774 -- Actions belong to the condition. In this case they are
1775 -- unconditionally executed, and so we can continue the
1776 -- search for the proper insert point.
1783 -- Case of appearing in the condition of a while expression or
1784 -- elsif. We insert the actions into the Condition_Actions field.
1785 -- They will be moved further out when the while loop or elsif
1788 when N_Iteration_Scheme |
1791 if N
= Condition
(P
) then
1792 if Present
(Condition_Actions
(P
)) then
1793 Insert_List_After_And_Analyze
1794 (Last
(Condition_Actions
(P
)), Ins_Actions
);
1796 Set_Condition_Actions
(P
, Ins_Actions
);
1798 -- Set the parent of the insert actions explicitly.
1799 -- This is not a syntactic field, but we need the
1800 -- parent field set, in particular so that freeze
1801 -- can understand that it is dealing with condition
1802 -- actions, and properly insert the freezing actions.
1804 Set_Parent
(Ins_Actions
, P
);
1805 Analyze_List
(Condition_Actions
(P
));
1811 -- Statements, declarations, pragmas, representation clauses
1816 N_Procedure_Call_Statement |
1817 N_Statement_Other_Than_Procedure_Call |
1823 -- Representation_Clause
1826 N_Attribute_Definition_Clause |
1827 N_Enumeration_Representation_Clause |
1828 N_Record_Representation_Clause |
1832 N_Abstract_Subprogram_Declaration |
1834 N_Exception_Declaration |
1835 N_Exception_Renaming_Declaration |
1836 N_Formal_Abstract_Subprogram_Declaration |
1837 N_Formal_Concrete_Subprogram_Declaration |
1838 N_Formal_Object_Declaration |
1839 N_Formal_Type_Declaration |
1840 N_Full_Type_Declaration |
1841 N_Function_Instantiation |
1842 N_Generic_Function_Renaming_Declaration |
1843 N_Generic_Package_Declaration |
1844 N_Generic_Package_Renaming_Declaration |
1845 N_Generic_Procedure_Renaming_Declaration |
1846 N_Generic_Subprogram_Declaration |
1847 N_Implicit_Label_Declaration |
1848 N_Incomplete_Type_Declaration |
1849 N_Number_Declaration |
1850 N_Object_Declaration |
1851 N_Object_Renaming_Declaration |
1853 N_Package_Body_Stub |
1854 N_Package_Declaration |
1855 N_Package_Instantiation |
1856 N_Package_Renaming_Declaration |
1857 N_Private_Extension_Declaration |
1858 N_Private_Type_Declaration |
1859 N_Procedure_Instantiation |
1860 N_Protected_Body_Stub |
1861 N_Protected_Type_Declaration |
1862 N_Single_Task_Declaration |
1864 N_Subprogram_Body_Stub |
1865 N_Subprogram_Declaration |
1866 N_Subprogram_Renaming_Declaration |
1867 N_Subtype_Declaration |
1870 N_Task_Type_Declaration |
1872 -- Freeze entity behaves like a declaration or statement
1876 -- Do not insert here if the item is not a list member (this
1877 -- happens for example with a triggering statement, and the
1878 -- proper approach is to insert before the entire select).
1880 if not Is_List_Member
(P
) then
1883 -- Do not insert if parent of P is an N_Component_Association
1884 -- node (i.e. we are in the context of an N_Aggregate node.
1885 -- In this case we want to insert before the entire aggregate.
1887 elsif Nkind
(Parent
(P
)) = N_Component_Association
then
1890 -- Do not insert if the parent of P is either an N_Variant
1891 -- node or an N_Record_Definition node, meaning in either
1892 -- case that P is a member of a component list, and that
1893 -- therefore the actions should be inserted outside the
1894 -- complete record declaration.
1896 elsif Nkind
(Parent
(P
)) = N_Variant
1897 or else Nkind
(Parent
(P
)) = N_Record_Definition
1901 -- Do not insert freeze nodes within the loop generated for
1902 -- an aggregate, because they may be elaborated too late for
1903 -- subsequent use in the back end: within a package spec the
1904 -- loop is part of the elaboration procedure and is only
1905 -- elaborated during the second pass.
1906 -- If the loop comes from source, or the entity is local to
1907 -- the loop itself it must remain within.
1909 elsif Nkind
(Parent
(P
)) = N_Loop_Statement
1910 and then not Comes_From_Source
(Parent
(P
))
1911 and then Nkind
(First
(Ins_Actions
)) = N_Freeze_Entity
1913 Scope
(Entity
(First
(Ins_Actions
))) /= Current_Scope
1917 -- Otherwise we can go ahead and do the insertion
1919 elsif P
= Wrapped_Node
then
1920 Store_Before_Actions_In_Scope
(Ins_Actions
);
1924 Insert_List_Before_And_Analyze
(P
, Ins_Actions
);
1928 -- A special case, N_Raise_xxx_Error can act either as a
1929 -- statement or a subexpression. We tell the difference
1930 -- by looking at the Etype. It is set to Standard_Void_Type
1931 -- in the statement case.
1934 N_Raise_xxx_Error
=>
1935 if Etype
(P
) = Standard_Void_Type
then
1936 if P
= Wrapped_Node
then
1937 Store_Before_Actions_In_Scope
(Ins_Actions
);
1939 Insert_List_Before_And_Analyze
(P
, Ins_Actions
);
1944 -- In the subexpression case, keep climbing
1950 -- If a component association appears within a loop created for
1951 -- an array aggregate, attach the actions to the association so
1952 -- they can be subsequently inserted within the loop. For other
1953 -- component associations insert outside of the aggregate. For
1954 -- an association that will generate a loop, its Loop_Actions
1955 -- attribute is already initialized (see exp_aggr.adb).
1957 -- The list of loop_actions can in turn generate additional ones,
1958 -- that are inserted before the associated node. If the associated
1959 -- node is outside the aggregate, the new actions are collected
1960 -- at the end of the loop actions, to respect the order in which
1961 -- they are to be elaborated.
1964 N_Component_Association
=>
1965 if Nkind
(Parent
(P
)) = N_Aggregate
1966 and then Present
(Loop_Actions
(P
))
1968 if Is_Empty_List
(Loop_Actions
(P
)) then
1969 Set_Loop_Actions
(P
, Ins_Actions
);
1970 Analyze_List
(Ins_Actions
);
1977 -- Check whether these actions were generated
1978 -- by a declaration that is part of the loop_
1979 -- actions for the component_association.
1982 while Present
(Decl
) loop
1983 exit when Parent
(Decl
) = P
1984 and then Is_List_Member
(Decl
)
1986 List_Containing
(Decl
) = Loop_Actions
(P
);
1987 Decl
:= Parent
(Decl
);
1990 if Present
(Decl
) then
1991 Insert_List_Before_And_Analyze
1992 (Decl
, Ins_Actions
);
1994 Insert_List_After_And_Analyze
1995 (Last
(Loop_Actions
(P
)), Ins_Actions
);
2006 -- Another special case, an attribute denoting a procedure call
2009 N_Attribute_Reference
=>
2010 if Is_Procedure_Attribute_Name
(Attribute_Name
(P
)) then
2011 if P
= Wrapped_Node
then
2012 Store_Before_Actions_In_Scope
(Ins_Actions
);
2014 Insert_List_Before_And_Analyze
(P
, Ins_Actions
);
2019 -- In the subexpression case, keep climbing
2025 -- For all other node types, keep climbing tree
2029 N_Accept_Alternative |
2030 N_Access_Definition |
2031 N_Access_Function_Definition |
2032 N_Access_Procedure_Definition |
2033 N_Access_To_Object_Definition |
2036 N_Case_Statement_Alternative |
2037 N_Character_Literal |
2038 N_Compilation_Unit |
2039 N_Compilation_Unit_Aux |
2040 N_Component_Clause |
2041 N_Component_Declaration |
2042 N_Component_Definition |
2044 N_Constrained_Array_Definition |
2045 N_Decimal_Fixed_Point_Definition |
2046 N_Defining_Character_Literal |
2047 N_Defining_Identifier |
2048 N_Defining_Operator_Symbol |
2049 N_Defining_Program_Unit_Name |
2050 N_Delay_Alternative |
2051 N_Delta_Constraint |
2052 N_Derived_Type_Definition |
2054 N_Digits_Constraint |
2055 N_Discriminant_Association |
2056 N_Discriminant_Specification |
2058 N_Entry_Body_Formal_Part |
2059 N_Entry_Call_Alternative |
2060 N_Entry_Declaration |
2061 N_Entry_Index_Specification |
2062 N_Enumeration_Type_Definition |
2064 N_Exception_Handler |
2066 N_Explicit_Dereference |
2067 N_Extension_Aggregate |
2068 N_Floating_Point_Definition |
2069 N_Formal_Decimal_Fixed_Point_Definition |
2070 N_Formal_Derived_Type_Definition |
2071 N_Formal_Discrete_Type_Definition |
2072 N_Formal_Floating_Point_Definition |
2073 N_Formal_Modular_Type_Definition |
2074 N_Formal_Ordinary_Fixed_Point_Definition |
2075 N_Formal_Package_Declaration |
2076 N_Formal_Private_Type_Definition |
2077 N_Formal_Signed_Integer_Type_Definition |
2079 N_Function_Specification |
2080 N_Generic_Association |
2081 N_Handled_Sequence_Of_Statements |
2084 N_Index_Or_Discriminant_Constraint |
2085 N_Indexed_Component |
2089 N_Loop_Parameter_Specification |
2091 N_Modular_Type_Definition |
2117 N_Op_Shift_Right_Arithmetic |
2121 N_Ordinary_Fixed_Point_Definition |
2123 N_Package_Specification |
2124 N_Parameter_Association |
2125 N_Parameter_Specification |
2126 N_Pragma_Argument_Association |
2127 N_Procedure_Specification |
2129 N_Protected_Definition |
2130 N_Qualified_Expression |
2132 N_Range_Constraint |
2134 N_Real_Range_Specification |
2135 N_Record_Definition |
2137 N_Selected_Component |
2138 N_Signed_Integer_Type_Definition |
2139 N_Single_Protected_Declaration |
2143 N_Subtype_Indication |
2146 N_Terminate_Alternative |
2147 N_Triggering_Alternative |
2149 N_Unchecked_Expression |
2150 N_Unchecked_Type_Conversion |
2151 N_Unconstrained_Array_Definition |
2154 N_Use_Package_Clause |
2158 N_Validate_Unchecked_Conversion |
2166 -- Make sure that inserted actions stay in the transient scope
2168 if P
= Wrapped_Node
then
2169 Store_Before_Actions_In_Scope
(Ins_Actions
);
2173 -- If we fall through above tests, keep climbing tree
2177 if Nkind
(Parent
(N
)) = N_Subunit
then
2179 -- This is the proper body corresponding to a stub. Insertion
2180 -- must be done at the point of the stub, which is in the decla-
2181 -- tive part of the parent unit.
2183 P
:= Corresponding_Stub
(Parent
(N
));
2192 -- Version with check(s) suppressed
2194 procedure Insert_Actions
2195 (Assoc_Node
: Node_Id
; Ins_Actions
: List_Id
; Suppress
: Check_Id
)
2198 if Suppress
= All_Checks
then
2200 Svg
: constant Suppress_Array
:= Scope_Suppress
;
2203 Scope_Suppress
:= (others => True);
2204 Insert_Actions
(Assoc_Node
, Ins_Actions
);
2205 Scope_Suppress
:= Svg
;
2210 Svg
: constant Boolean := Scope_Suppress
(Suppress
);
2213 Scope_Suppress
(Suppress
) := True;
2214 Insert_Actions
(Assoc_Node
, Ins_Actions
);
2215 Scope_Suppress
(Suppress
) := Svg
;
2220 --------------------------
2221 -- Insert_Actions_After --
2222 --------------------------
2224 procedure Insert_Actions_After
2225 (Assoc_Node
: Node_Id
;
2226 Ins_Actions
: List_Id
)
2229 if Scope_Is_Transient
2230 and then Assoc_Node
= Node_To_Be_Wrapped
2232 Store_After_Actions_In_Scope
(Ins_Actions
);
2234 Insert_List_After_And_Analyze
(Assoc_Node
, Ins_Actions
);
2236 end Insert_Actions_After
;
2238 ---------------------------------
2239 -- Insert_Library_Level_Action --
2240 ---------------------------------
2242 procedure Insert_Library_Level_Action
(N
: Node_Id
) is
2243 Aux
: constant Node_Id
:= Aux_Decls_Node
(Cunit
(Main_Unit
));
2246 New_Scope
(Cunit_Entity
(Main_Unit
));
2248 if No
(Actions
(Aux
)) then
2249 Set_Actions
(Aux
, New_List
(N
));
2251 Append
(N
, Actions
(Aux
));
2256 end Insert_Library_Level_Action
;
2258 ----------------------------------
2259 -- Insert_Library_Level_Actions --
2260 ----------------------------------
2262 procedure Insert_Library_Level_Actions
(L
: List_Id
) is
2263 Aux
: constant Node_Id
:= Aux_Decls_Node
(Cunit
(Main_Unit
));
2266 if Is_Non_Empty_List
(L
) then
2267 New_Scope
(Cunit_Entity
(Main_Unit
));
2269 if No
(Actions
(Aux
)) then
2270 Set_Actions
(Aux
, L
);
2273 Insert_List_After_And_Analyze
(Last
(Actions
(Aux
)), L
);
2278 end Insert_Library_Level_Actions
;
2280 ----------------------
2281 -- Inside_Init_Proc --
2282 ----------------------
2284 function Inside_Init_Proc
return Boolean is
2290 and then S
/= Standard_Standard
2292 if Is_Init_Proc
(S
) then
2300 end Inside_Init_Proc
;
2302 ----------------------------
2303 -- Is_All_Null_Statements --
2304 ----------------------------
2306 function Is_All_Null_Statements
(L
: List_Id
) return Boolean is
2311 while Present
(Stm
) loop
2312 if Nkind
(Stm
) /= N_Null_Statement
then
2320 end Is_All_Null_Statements
;
2322 ----------------------------------
2323 -- Is_Possibly_Unaligned_Object --
2324 ----------------------------------
2326 function Is_Possibly_Unaligned_Object
(P
: Node_Id
) return Boolean is
2328 -- If target does not have strict alignment, result is always
2329 -- False, since correctness of code does no depend on alignment.
2331 if not Target_Strict_Alignment
then
2335 -- If renamed object, apply test to underlying object
2337 if Is_Entity_Name
(P
)
2338 and then Is_Object
(Entity
(P
))
2339 and then Present
(Renamed_Object
(Entity
(P
)))
2341 return Is_Possibly_Unaligned_Object
(Renamed_Object
(Entity
(P
)));
2344 -- If this is an element of a packed array, may be unaligned
2346 if Is_Ref_To_Bit_Packed_Array
(P
) then
2350 -- Case of component reference
2352 if Nkind
(P
) = N_Selected_Component
then
2354 -- If component reference is for a record that is bit packed
2355 -- or has a specified alignment (that might be too small) or
2356 -- the component reference has a component clause, then the
2357 -- object may be unaligned.
2359 if Is_Packed
(Etype
(Prefix
(P
)))
2360 or else Known_Alignment
(Etype
(Prefix
(P
)))
2361 or else Present
(Component_Clause
(Entity
(Selector_Name
(P
))))
2365 -- Otherwise, for a component reference, test prefix
2368 return Is_Possibly_Unaligned_Object
(Prefix
(P
));
2371 -- If not a component reference, must be aligned
2376 end Is_Possibly_Unaligned_Object
;
2378 ---------------------------------
2379 -- Is_Possibly_Unaligned_Slice --
2380 ---------------------------------
2382 function Is_Possibly_Unaligned_Slice
(P
: Node_Id
) return Boolean is
2384 -- ??? GCC3 will eventually handle strings with arbitrary alignments,
2385 -- but for now the following check must be disabled.
2387 -- if get_gcc_version >= 3 then
2391 -- For renaming case, go to renamed object
2393 if Is_Entity_Name
(P
)
2394 and then Is_Object
(Entity
(P
))
2395 and then Present
(Renamed_Object
(Entity
(P
)))
2397 return Is_Possibly_Unaligned_Slice
(Renamed_Object
(Entity
(P
)));
2400 -- The reference must be a slice
2402 if Nkind
(P
) /= N_Slice
then
2406 -- Always assume the worst for a nested record component with a
2407 -- component clause, which gigi/gcc does not appear to handle well.
2408 -- It is not clear why this special test is needed at all ???
2410 if Nkind
(Prefix
(P
)) = N_Selected_Component
2411 and then Nkind
(Prefix
(Prefix
(P
))) = N_Selected_Component
2413 Present
(Component_Clause
(Entity
(Selector_Name
(Prefix
(P
)))))
2418 -- We only need to worry if the target has strict alignment
2420 if not Target_Strict_Alignment
then
2424 -- If it is a slice, then look at the array type being sliced
2427 Sarr
: constant Node_Id
:= Prefix
(P
);
2428 -- Prefix of the slice, i.e. the array being sliced
2430 Styp
: constant Entity_Id
:= Etype
(Prefix
(P
));
2431 -- Type of the array being sliced
2437 -- The problems arise if the array object that is being sliced
2438 -- is a component of a record or array, and we cannot guarantee
2439 -- the alignment of the array within its containing object.
2441 -- To investigate this, we look at successive prefixes to see
2442 -- if we have a worrisome indexed or selected component.
2446 -- Case of array is part of an indexed component reference
2448 if Nkind
(Pref
) = N_Indexed_Component
then
2449 Ptyp
:= Etype
(Prefix
(Pref
));
2451 -- The only problematic case is when the array is packed,
2452 -- in which case we really know nothing about the alignment
2453 -- of individual components.
2455 if Is_Bit_Packed_Array
(Ptyp
) then
2459 -- Case of array is part of a selected component reference
2461 elsif Nkind
(Pref
) = N_Selected_Component
then
2462 Ptyp
:= Etype
(Prefix
(Pref
));
2464 -- We are definitely in trouble if the record in question
2465 -- has an alignment, and either we know this alignment is
2466 -- inconsistent with the alignment of the slice, or we
2467 -- don't know what the alignment of the slice should be.
2469 if Known_Alignment
(Ptyp
)
2470 and then (Unknown_Alignment
(Styp
)
2471 or else Alignment
(Styp
) > Alignment
(Ptyp
))
2476 -- We are in potential trouble if the record type is packed.
2477 -- We could special case when we know that the array is the
2478 -- first component, but that's not such a simple case ???
2480 if Is_Packed
(Ptyp
) then
2484 -- We are in trouble if there is a component clause, and
2485 -- either we do not know the alignment of the slice, or
2486 -- the alignment of the slice is inconsistent with the
2487 -- bit position specified by the component clause.
2490 Field
: constant Entity_Id
:= Entity
(Selector_Name
(Pref
));
2492 if Present
(Component_Clause
(Field
))
2494 (Unknown_Alignment
(Styp
)
2496 (Component_Bit_Offset
(Field
) mod
2497 (System_Storage_Unit
* Alignment
(Styp
))) /= 0)
2503 -- For cases other than selected or indexed components we
2504 -- know we are OK, since no issues arise over alignment.
2510 -- We processed an indexed component or selected component
2511 -- reference that looked safe, so keep checking prefixes.
2513 Pref
:= Prefix
(Pref
);
2516 end Is_Possibly_Unaligned_Slice
;
2518 --------------------------------
2519 -- Is_Ref_To_Bit_Packed_Array --
2520 --------------------------------
2522 function Is_Ref_To_Bit_Packed_Array
(P
: Node_Id
) return Boolean is
2527 if Is_Entity_Name
(P
)
2528 and then Is_Object
(Entity
(P
))
2529 and then Present
(Renamed_Object
(Entity
(P
)))
2531 return Is_Ref_To_Bit_Packed_Array
(Renamed_Object
(Entity
(P
)));
2534 if Nkind
(P
) = N_Indexed_Component
2536 Nkind
(P
) = N_Selected_Component
2538 if Is_Bit_Packed_Array
(Etype
(Prefix
(P
))) then
2541 Result
:= Is_Ref_To_Bit_Packed_Array
(Prefix
(P
));
2544 if Result
and then Nkind
(P
) = N_Indexed_Component
then
2545 Expr
:= First
(Expressions
(P
));
2546 while Present
(Expr
) loop
2547 Force_Evaluation
(Expr
);
2557 end Is_Ref_To_Bit_Packed_Array
;
2559 --------------------------------
2560 -- Is_Ref_To_Bit_Packed_Slice --
2561 --------------------------------
2563 function Is_Ref_To_Bit_Packed_Slice
(P
: Node_Id
) return Boolean is
2565 if Is_Entity_Name
(P
)
2566 and then Is_Object
(Entity
(P
))
2567 and then Present
(Renamed_Object
(Entity
(P
)))
2569 return Is_Ref_To_Bit_Packed_Slice
(Renamed_Object
(Entity
(P
)));
2572 if Nkind
(P
) = N_Slice
2573 and then Is_Bit_Packed_Array
(Etype
(Prefix
(P
)))
2577 elsif Nkind
(P
) = N_Indexed_Component
2579 Nkind
(P
) = N_Selected_Component
2581 return Is_Ref_To_Bit_Packed_Slice
(Prefix
(P
));
2586 end Is_Ref_To_Bit_Packed_Slice
;
2588 -----------------------
2589 -- Is_Renamed_Object --
2590 -----------------------
2592 function Is_Renamed_Object
(N
: Node_Id
) return Boolean is
2593 Pnod
: constant Node_Id
:= Parent
(N
);
2594 Kind
: constant Node_Kind
:= Nkind
(Pnod
);
2597 if Kind
= N_Object_Renaming_Declaration
then
2600 elsif Kind
= N_Indexed_Component
2601 or else Kind
= N_Selected_Component
2603 return Is_Renamed_Object
(Pnod
);
2608 end Is_Renamed_Object
;
2610 ----------------------------
2611 -- Is_Untagged_Derivation --
2612 ----------------------------
2614 function Is_Untagged_Derivation
(T
: Entity_Id
) return Boolean is
2616 return (not Is_Tagged_Type
(T
) and then Is_Derived_Type
(T
))
2618 (Is_Private_Type
(T
) and then Present
(Full_View
(T
))
2619 and then not Is_Tagged_Type
(Full_View
(T
))
2620 and then Is_Derived_Type
(Full_View
(T
))
2621 and then Etype
(Full_View
(T
)) /= T
);
2623 end Is_Untagged_Derivation
;
2625 --------------------
2626 -- Kill_Dead_Code --
2627 --------------------
2629 procedure Kill_Dead_Code
(N
: Node_Id
) is
2632 Remove_Handler_Entries
(N
);
2633 Remove_Warning_Messages
(N
);
2635 -- Recurse into block statements and bodies to process declarations
2638 if Nkind
(N
) = N_Block_Statement
2639 or else Nkind
(N
) = N_Subprogram_Body
2640 or else Nkind
(N
) = N_Package_Body
2642 Kill_Dead_Code
(Declarations
(N
));
2643 Kill_Dead_Code
(Statements
(Handled_Statement_Sequence
(N
)));
2645 if Nkind
(N
) = N_Subprogram_Body
then
2646 Set_Is_Eliminated
(Defining_Entity
(N
));
2649 -- Recurse into composite statement to kill individual statements,
2650 -- in particular instantiations.
2652 elsif Nkind
(N
) = N_If_Statement
then
2653 Kill_Dead_Code
(Then_Statements
(N
));
2654 Kill_Dead_Code
(Elsif_Parts
(N
));
2655 Kill_Dead_Code
(Else_Statements
(N
));
2657 elsif Nkind
(N
) = N_Loop_Statement
then
2658 Kill_Dead_Code
(Statements
(N
));
2660 elsif Nkind
(N
) = N_Case_Statement
then
2664 Alt
:= First
(Alternatives
(N
));
2665 while Present
(Alt
) loop
2666 Kill_Dead_Code
(Statements
(Alt
));
2671 elsif Nkind
(N
) = N_Case_Statement_Alternative
then
2672 Kill_Dead_Code
(Statements
(N
));
2674 -- Deal with dead instances caused by deleting instantiations
2676 elsif Nkind
(N
) in N_Generic_Instantiation
then
2677 Remove_Dead_Instance
(N
);
2684 -- Case where argument is a list of nodes to be killed
2686 procedure Kill_Dead_Code
(L
: List_Id
) is
2690 if Is_Non_Empty_List
(L
) then
2692 N
:= Remove_Head
(L
);
2699 ------------------------
2700 -- Known_Non_Negative --
2701 ------------------------
2703 function Known_Non_Negative
(Opnd
: Node_Id
) return Boolean is
2705 if Is_OK_Static_Expression
(Opnd
)
2706 and then Expr_Value
(Opnd
) >= 0
2712 Lo
: constant Node_Id
:= Type_Low_Bound
(Etype
(Opnd
));
2716 Is_OK_Static_Expression
(Lo
) and then Expr_Value
(Lo
) >= 0;
2719 end Known_Non_Negative
;
2721 --------------------
2722 -- Known_Non_Null --
2723 --------------------
2725 function Known_Non_Null
(N
: Node_Id
) return Boolean is
2727 pragma Assert
(Is_Access_Type
(Underlying_Type
(Etype
(N
))));
2729 -- Case of entity for which Is_Known_Non_Null is True
2731 if Is_Entity_Name
(N
) and then Is_Known_Non_Null
(Entity
(N
)) then
2733 -- If the entity is aliased or volatile, then we decide that
2734 -- we don't know it is really non-null even if the sequential
2735 -- flow indicates that it is, since such variables can be
2736 -- changed without us noticing.
2738 if Is_Aliased
(Entity
(N
))
2739 or else Treat_As_Volatile
(Entity
(N
))
2743 -- For all other cases, the flag is decisive
2749 -- True if access attribute
2751 elsif Nkind
(N
) = N_Attribute_Reference
2752 and then (Attribute_Name
(N
) = Name_Access
2754 Attribute_Name
(N
) = Name_Unchecked_Access
2756 Attribute_Name
(N
) = Name_Unrestricted_Access
)
2760 -- True if allocator
2762 elsif Nkind
(N
) = N_Allocator
then
2765 -- For a conversion, true if expression is known non-null
2767 elsif Nkind
(N
) = N_Type_Conversion
then
2768 return Known_Non_Null
(Expression
(N
));
2770 -- One more case is when Current_Value references a condition
2771 -- that ensures a non-null value.
2773 elsif Is_Entity_Name
(N
) then
2779 Get_Current_Value_Condition
(N
, Op
, Val
);
2780 return Op
= N_Op_Ne
and then Nkind
(Val
) = N_Null
;
2783 -- Above are all cases where the value could be determined to be
2784 -- non-null. In all other cases, we don't know, so return False.
2791 -----------------------------
2792 -- Make_CW_Equivalent_Type --
2793 -----------------------------
2795 -- Create a record type used as an equivalent of any member
2796 -- of the class which takes its size from exp.
2798 -- Generate the following code:
2800 -- type Equiv_T is record
2801 -- _parent : T (List of discriminant constaints taken from Exp);
2802 -- Ext__50 : Storage_Array (1 .. (Exp'size - Typ'object_size)/8);
2805 -- ??? Note that this type does not guarantee same alignment as all
2808 function Make_CW_Equivalent_Type
2810 E
: Node_Id
) return Entity_Id
2812 Loc
: constant Source_Ptr
:= Sloc
(E
);
2813 Root_Typ
: constant Entity_Id
:= Root_Type
(T
);
2814 List_Def
: constant List_Id
:= Empty_List
;
2815 Equiv_Type
: Entity_Id
;
2816 Range_Type
: Entity_Id
;
2817 Str_Type
: Entity_Id
;
2818 Constr_Root
: Entity_Id
;
2822 if not Has_Discriminants
(Root_Typ
) then
2823 Constr_Root
:= Root_Typ
;
2826 Make_Defining_Identifier
(Loc
, New_Internal_Name
('R'));
2828 -- subtype cstr__n is T (List of discr constraints taken from Exp)
2830 Append_To
(List_Def
,
2831 Make_Subtype_Declaration
(Loc
,
2832 Defining_Identifier
=> Constr_Root
,
2833 Subtype_Indication
=>
2834 Make_Subtype_From_Expr
(E
, Root_Typ
)));
2837 -- subtype rg__xx is Storage_Offset range
2838 -- (Expr'size - typ'size) / Storage_Unit
2840 Range_Type
:= Make_Defining_Identifier
(Loc
, New_Internal_Name
('G'));
2843 Make_Op_Subtract
(Loc
,
2845 Make_Attribute_Reference
(Loc
,
2847 OK_Convert_To
(T
, Duplicate_Subexpr_No_Checks
(E
)),
2848 Attribute_Name
=> Name_Size
),
2850 Make_Attribute_Reference
(Loc
,
2851 Prefix
=> New_Reference_To
(Constr_Root
, Loc
),
2852 Attribute_Name
=> Name_Object_Size
));
2854 Set_Paren_Count
(Sizexpr
, 1);
2856 Append_To
(List_Def
,
2857 Make_Subtype_Declaration
(Loc
,
2858 Defining_Identifier
=> Range_Type
,
2859 Subtype_Indication
=>
2860 Make_Subtype_Indication
(Loc
,
2861 Subtype_Mark
=> New_Reference_To
(RTE
(RE_Storage_Offset
), Loc
),
2862 Constraint
=> Make_Range_Constraint
(Loc
,
2865 Low_Bound
=> Make_Integer_Literal
(Loc
, 1),
2867 Make_Op_Divide
(Loc
,
2868 Left_Opnd
=> Sizexpr
,
2869 Right_Opnd
=> Make_Integer_Literal
(Loc
,
2870 Intval
=> System_Storage_Unit
)))))));
2872 -- subtype str__nn is Storage_Array (rg__x);
2874 Str_Type
:= Make_Defining_Identifier
(Loc
, New_Internal_Name
('S'));
2875 Append_To
(List_Def
,
2876 Make_Subtype_Declaration
(Loc
,
2877 Defining_Identifier
=> Str_Type
,
2878 Subtype_Indication
=>
2879 Make_Subtype_Indication
(Loc
,
2880 Subtype_Mark
=> New_Reference_To
(RTE
(RE_Storage_Array
), Loc
),
2882 Make_Index_Or_Discriminant_Constraint
(Loc
,
2884 New_List
(New_Reference_To
(Range_Type
, Loc
))))));
2886 -- type Equiv_T is record
2891 Equiv_Type
:= Make_Defining_Identifier
(Loc
, New_Internal_Name
('T'));
2893 -- When the target requires front-end layout, it's necessary to allow
2894 -- the equivalent type to be frozen so that layout can occur (when the
2895 -- associated class-wide subtype is frozen, the equivalent type will
2896 -- be frozen, see freeze.adb). For other targets, Gigi wants to have
2897 -- the equivalent type marked as frozen and deals with this type itself.
2898 -- In the Gigi case this will also avoid the generation of an init
2899 -- procedure for the type.
2901 if not Frontend_Layout_On_Target
then
2902 Set_Is_Frozen
(Equiv_Type
);
2905 Set_Ekind
(Equiv_Type
, E_Record_Type
);
2906 Set_Parent_Subtype
(Equiv_Type
, Constr_Root
);
2908 Append_To
(List_Def
,
2909 Make_Full_Type_Declaration
(Loc
,
2910 Defining_Identifier
=> Equiv_Type
,
2913 Make_Record_Definition
(Loc
,
2914 Component_List
=> Make_Component_List
(Loc
,
2915 Component_Items
=> New_List
(
2916 Make_Component_Declaration
(Loc
,
2917 Defining_Identifier
=>
2918 Make_Defining_Identifier
(Loc
, Name_uParent
),
2919 Component_Definition
=>
2920 Make_Component_Definition
(Loc
,
2921 Aliased_Present
=> False,
2922 Subtype_Indication
=>
2923 New_Reference_To
(Constr_Root
, Loc
))),
2925 Make_Component_Declaration
(Loc
,
2926 Defining_Identifier
=>
2927 Make_Defining_Identifier
(Loc
,
2928 Chars
=> New_Internal_Name
('C')),
2929 Component_Definition
=>
2930 Make_Component_Definition
(Loc
,
2931 Aliased_Present
=> False,
2932 Subtype_Indication
=>
2933 New_Reference_To
(Str_Type
, Loc
)))),
2935 Variant_Part
=> Empty
))));
2937 Insert_Actions
(E
, List_Def
);
2939 end Make_CW_Equivalent_Type
;
2941 ------------------------
2942 -- Make_Literal_Range --
2943 ------------------------
2945 function Make_Literal_Range
2947 Literal_Typ
: Entity_Id
) return Node_Id
2949 Lo
: constant Node_Id
:=
2950 New_Copy_Tree
(String_Literal_Low_Bound
(Literal_Typ
));
2953 Set_Analyzed
(Lo
, False);
2960 Make_Op_Subtract
(Loc
,
2963 Left_Opnd
=> New_Copy_Tree
(Lo
),
2965 Make_Integer_Literal
(Loc
,
2966 String_Literal_Length
(Literal_Typ
))),
2967 Right_Opnd
=> Make_Integer_Literal
(Loc
, 1)));
2968 end Make_Literal_Range
;
2970 ----------------------------
2971 -- Make_Subtype_From_Expr --
2972 ----------------------------
2974 -- 1. If Expr is an uncontrained array expression, creates
2975 -- Unc_Type(Expr'first(1)..Expr'Last(1),..., Expr'first(n)..Expr'last(n))
2977 -- 2. If Expr is a unconstrained discriminated type expression, creates
2978 -- Unc_Type(Expr.Discr1, ... , Expr.Discr_n)
2980 -- 3. If Expr is class-wide, creates an implicit class wide subtype
2982 function Make_Subtype_From_Expr
2984 Unc_Typ
: Entity_Id
) return Node_Id
2986 Loc
: constant Source_Ptr
:= Sloc
(E
);
2987 List_Constr
: constant List_Id
:= New_List
;
2990 Full_Subtyp
: Entity_Id
;
2991 Priv_Subtyp
: Entity_Id
;
2996 if Is_Private_Type
(Unc_Typ
)
2997 and then Has_Unknown_Discriminants
(Unc_Typ
)
2999 -- Prepare the subtype completion, Go to base type to
3000 -- find underlying type.
3002 Utyp
:= Underlying_Type
(Base_Type
(Unc_Typ
));
3003 Full_Subtyp
:= Make_Defining_Identifier
(Loc
,
3004 New_Internal_Name
('C'));
3006 Unchecked_Convert_To
3007 (Utyp
, Duplicate_Subexpr_No_Checks
(E
));
3008 Set_Parent
(Full_Exp
, Parent
(E
));
3011 Make_Defining_Identifier
(Loc
, New_Internal_Name
('P'));
3014 Make_Subtype_Declaration
(Loc
,
3015 Defining_Identifier
=> Full_Subtyp
,
3016 Subtype_Indication
=> Make_Subtype_From_Expr
(Full_Exp
, Utyp
)));
3018 -- Define the dummy private subtype
3020 Set_Ekind
(Priv_Subtyp
, Subtype_Kind
(Ekind
(Unc_Typ
)));
3021 Set_Etype
(Priv_Subtyp
, Unc_Typ
);
3022 Set_Scope
(Priv_Subtyp
, Full_Subtyp
);
3023 Set_Is_Constrained
(Priv_Subtyp
);
3024 Set_Is_Tagged_Type
(Priv_Subtyp
, Is_Tagged_Type
(Unc_Typ
));
3025 Set_Is_Itype
(Priv_Subtyp
);
3026 Set_Associated_Node_For_Itype
(Priv_Subtyp
, E
);
3028 if Is_Tagged_Type
(Priv_Subtyp
) then
3030 (Base_Type
(Priv_Subtyp
), Class_Wide_Type
(Unc_Typ
));
3031 Set_Primitive_Operations
(Priv_Subtyp
,
3032 Primitive_Operations
(Unc_Typ
));
3035 Set_Full_View
(Priv_Subtyp
, Full_Subtyp
);
3037 return New_Reference_To
(Priv_Subtyp
, Loc
);
3039 elsif Is_Array_Type
(Unc_Typ
) then
3040 for J
in 1 .. Number_Dimensions
(Unc_Typ
) loop
3041 Append_To
(List_Constr
,
3044 Make_Attribute_Reference
(Loc
,
3045 Prefix
=> Duplicate_Subexpr_No_Checks
(E
),
3046 Attribute_Name
=> Name_First
,
3047 Expressions
=> New_List
(
3048 Make_Integer_Literal
(Loc
, J
))),
3051 Make_Attribute_Reference
(Loc
,
3052 Prefix
=> Duplicate_Subexpr_No_Checks
(E
),
3053 Attribute_Name
=> Name_Last
,
3054 Expressions
=> New_List
(
3055 Make_Integer_Literal
(Loc
, J
)))));
3058 elsif Is_Class_Wide_Type
(Unc_Typ
) then
3060 CW_Subtype
: Entity_Id
;
3061 EQ_Typ
: Entity_Id
:= Empty
;
3064 -- A class-wide equivalent type is not needed when Java_VM
3065 -- because the JVM back end handles the class-wide object
3066 -- initialization itself (and doesn't need or want the
3067 -- additional intermediate type to handle the assignment).
3069 if Expander_Active
and then not Java_VM
then
3070 EQ_Typ
:= Make_CW_Equivalent_Type
(Unc_Typ
, E
);
3073 CW_Subtype
:= New_Class_Wide_Subtype
(Unc_Typ
, E
);
3074 Set_Equivalent_Type
(CW_Subtype
, EQ_Typ
);
3076 if Present
(EQ_Typ
) then
3077 Set_Is_Class_Wide_Equivalent_Type
(EQ_Typ
);
3080 Set_Cloned_Subtype
(CW_Subtype
, Base_Type
(Unc_Typ
));
3082 return New_Occurrence_Of
(CW_Subtype
, Loc
);
3085 -- Comment needed (what case is this ???)
3088 D
:= First_Discriminant
(Unc_Typ
);
3089 while Present
(D
) loop
3090 Append_To
(List_Constr
,
3091 Make_Selected_Component
(Loc
,
3092 Prefix
=> Duplicate_Subexpr_No_Checks
(E
),
3093 Selector_Name
=> New_Reference_To
(D
, Loc
)));
3095 Next_Discriminant
(D
);
3100 Make_Subtype_Indication
(Loc
,
3101 Subtype_Mark
=> New_Reference_To
(Unc_Typ
, Loc
),
3103 Make_Index_Or_Discriminant_Constraint
(Loc
,
3104 Constraints
=> List_Constr
));
3105 end Make_Subtype_From_Expr
;
3107 -----------------------------
3108 -- May_Generate_Large_Temp --
3109 -----------------------------
3111 -- At the current time, the only types that we return False for (i.e.
3112 -- where we decide we know they cannot generate large temps) are ones
3113 -- where we know the size is 128 bits or less at compile time, and we
3114 -- are still not doing a thorough job on arrays and records ???
3116 function May_Generate_Large_Temp
(Typ
: Entity_Id
) return Boolean is
3118 if not Size_Known_At_Compile_Time
(Typ
) then
3121 elsif Esize
(Typ
) /= 0 and then Esize
(Typ
) <= 256 then
3124 elsif Is_Array_Type
(Typ
)
3125 and then Present
(Packed_Array_Type
(Typ
))
3127 return May_Generate_Large_Temp
(Packed_Array_Type
(Typ
));
3129 -- We could do more here to find other small types ???
3134 end May_Generate_Large_Temp
;
3136 ----------------------------
3137 -- New_Class_Wide_Subtype --
3138 ----------------------------
3140 function New_Class_Wide_Subtype
3141 (CW_Typ
: Entity_Id
;
3142 N
: Node_Id
) return Entity_Id
3144 Res
: constant Entity_Id
:= Create_Itype
(E_Void
, N
);
3145 Res_Name
: constant Name_Id
:= Chars
(Res
);
3146 Res_Scope
: constant Entity_Id
:= Scope
(Res
);
3149 Copy_Node
(CW_Typ
, Res
);
3150 Set_Sloc
(Res
, Sloc
(N
));
3152 Set_Associated_Node_For_Itype
(Res
, N
);
3153 Set_Is_Public
(Res
, False); -- By default, may be changed below.
3154 Set_Public_Status
(Res
);
3155 Set_Chars
(Res
, Res_Name
);
3156 Set_Scope
(Res
, Res_Scope
);
3157 Set_Ekind
(Res
, E_Class_Wide_Subtype
);
3158 Set_Next_Entity
(Res
, Empty
);
3159 Set_Etype
(Res
, Base_Type
(CW_Typ
));
3161 -- For targets where front-end layout is required, reset the Is_Frozen
3162 -- status of the subtype to False (it can be implicitly set to true
3163 -- from the copy of the class-wide type). For other targets, Gigi
3164 -- doesn't want the class-wide subtype to go through the freezing
3165 -- process (though it's unclear why that causes problems and it would
3166 -- be nice to allow freezing to occur normally for all targets ???).
3168 if Frontend_Layout_On_Target
then
3169 Set_Is_Frozen
(Res
, False);
3172 Set_Freeze_Node
(Res
, Empty
);
3174 end New_Class_Wide_Subtype
;
3176 -------------------------
3177 -- Remove_Side_Effects --
3178 -------------------------
3180 procedure Remove_Side_Effects
3182 Name_Req
: Boolean := False;
3183 Variable_Ref
: Boolean := False)
3185 Loc
: constant Source_Ptr
:= Sloc
(Exp
);
3186 Exp_Type
: constant Entity_Id
:= Etype
(Exp
);
3187 Svg_Suppress
: constant Suppress_Array
:= Scope_Suppress
;
3189 Ref_Type
: Entity_Id
;
3191 Ptr_Typ_Decl
: Node_Id
;
3195 function Side_Effect_Free
(N
: Node_Id
) return Boolean;
3196 -- Determines if the tree N represents an expession that is known
3197 -- not to have side effects, and for which no processing is required.
3199 function Side_Effect_Free
(L
: List_Id
) return Boolean;
3200 -- Determines if all elements of the list L are side effect free
3202 function Safe_Prefixed_Reference
(N
: Node_Id
) return Boolean;
3203 -- The argument N is a construct where the Prefix is dereferenced
3204 -- if it is a an access type and the result is a variable. The call
3205 -- returns True if the construct is side effect free (not considering
3206 -- side effects in other than the prefix which are to be tested by the
3209 function Within_In_Parameter
(N
: Node_Id
) return Boolean;
3210 -- Determines if N is a subcomponent of a composite in-parameter.
3211 -- If so, N is not side-effect free when the actual is global and
3212 -- modifiable indirectly from within a subprogram, because it may
3213 -- be passed by reference. The front-end must be conservative here
3214 -- and assume that this may happen with any array or record type.
3215 -- On the other hand, we cannot create temporaries for all expressions
3216 -- for which this condition is true, for various reasons that might
3217 -- require clearing up ??? For example, descriminant references that
3218 -- appear out of place, or spurious type errors with class-wide
3219 -- expressions. As a result, we limit the transformation to loop
3220 -- bounds, which is so far the only case that requires it.
3222 -----------------------------
3223 -- Safe_Prefixed_Reference --
3224 -----------------------------
3226 function Safe_Prefixed_Reference
(N
: Node_Id
) return Boolean is
3228 -- If prefix is not side effect free, definitely not safe
3230 if not Side_Effect_Free
(Prefix
(N
)) then
3233 -- If the prefix is of an access type that is not access-to-constant,
3234 -- then this construct is a variable reference, which means it is to
3235 -- be considered to have side effects if Variable_Ref is set True
3236 -- Exception is an access to an entity that is a constant or an
3237 -- in-parameter which does not come from source, and is the result
3238 -- of a previous removal of side-effects.
3240 elsif Is_Access_Type
(Etype
(Prefix
(N
)))
3241 and then not Is_Access_Constant
(Etype
(Prefix
(N
)))
3242 and then Variable_Ref
3244 if not Is_Entity_Name
(Prefix
(N
)) then
3247 return Ekind
(Entity
(Prefix
(N
))) = E_Constant
3248 or else Ekind
(Entity
(Prefix
(N
))) = E_In_Parameter
;
3251 -- The following test is the simplest way of solving a complex
3252 -- problem uncovered by BB08-010: Side effect on loop bound that
3253 -- is a subcomponent of a global variable:
3254 -- If a loop bound is a subcomponent of a global variable, a
3255 -- modification of that variable within the loop may incorrectly
3256 -- affect the execution of the loop.
3259 (Nkind
(Parent
(Parent
(N
))) /= N_Loop_Parameter_Specification
3260 or else not Within_In_Parameter
(Prefix
(N
)))
3264 -- All other cases are side effect free
3269 end Safe_Prefixed_Reference
;
3271 ----------------------
3272 -- Side_Effect_Free --
3273 ----------------------
3275 function Side_Effect_Free
(N
: Node_Id
) return Boolean is
3277 -- Note on checks that could raise Constraint_Error. Strictly, if
3278 -- we take advantage of 11.6, these checks do not count as side
3279 -- effects. However, we would just as soon consider that they are
3280 -- side effects, since the backend CSE does not work very well on
3281 -- expressions which can raise Constraint_Error. On the other
3282 -- hand, if we do not consider them to be side effect free, then
3283 -- we get some awkward expansions in -gnato mode, resulting in
3284 -- code insertions at a point where we do not have a clear model
3285 -- for performing the insertions. See 4908-002/comment for details.
3287 -- Special handling for entity names
3289 if Is_Entity_Name
(N
) then
3291 -- If the entity is a constant, it is definitely side effect
3292 -- free. Note that the test of Is_Variable (N) below might
3293 -- be expected to catch this case, but it does not, because
3294 -- this test goes to the original tree, and we may have
3295 -- already rewritten a variable node with a constant as
3296 -- a result of an earlier Force_Evaluation call.
3298 if Ekind
(Entity
(N
)) = E_Constant
3299 or else Ekind
(Entity
(N
)) = E_In_Parameter
3303 -- Functions are not side effect free
3305 elsif Ekind
(Entity
(N
)) = E_Function
then
3308 -- Variables are considered to be a side effect if Variable_Ref
3309 -- is set or if we have a volatile variable and Name_Req is off.
3310 -- If Name_Req is True then we can't help returning a name which
3311 -- effectively allows multiple references in any case.
3313 elsif Is_Variable
(N
) then
3314 return not Variable_Ref
3315 and then (not Treat_As_Volatile
(Entity
(N
))
3318 -- Any other entity (e.g. a subtype name) is definitely side
3325 -- A value known at compile time is always side effect free
3327 elsif Compile_Time_Known_Value
(N
) then
3331 -- For other than entity names and compile time known values,
3332 -- check the node kind for special processing.
3336 -- An attribute reference is side effect free if its expressions
3337 -- are side effect free and its prefix is side effect free or
3338 -- is an entity reference.
3340 -- Is this right? what about x'first where x is a variable???
3342 when N_Attribute_Reference
=>
3343 return Side_Effect_Free
(Expressions
(N
))
3344 and then (Is_Entity_Name
(Prefix
(N
))
3345 or else Side_Effect_Free
(Prefix
(N
)));
3347 -- A binary operator is side effect free if and both operands
3348 -- are side effect free. For this purpose binary operators
3349 -- include membership tests and short circuit forms
3356 return Side_Effect_Free
(Left_Opnd
(N
))
3357 and then Side_Effect_Free
(Right_Opnd
(N
));
3359 -- An explicit dereference is side effect free only if it is
3360 -- a side effect free prefixed reference.
3362 when N_Explicit_Dereference
=>
3363 return Safe_Prefixed_Reference
(N
);
3365 -- A call to _rep_to_pos is side effect free, since we generate
3366 -- this pure function call ourselves. Moreover it is critically
3367 -- important to make this exception, since otherwise we can
3368 -- have discriminants in array components which don't look
3369 -- side effect free in the case of an array whose index type
3370 -- is an enumeration type with an enumeration rep clause.
3372 -- All other function calls are not side effect free
3374 when N_Function_Call
=>
3375 return Nkind
(Name
(N
)) = N_Identifier
3376 and then Is_TSS
(Name
(N
), TSS_Rep_To_Pos
)
3378 Side_Effect_Free
(First
(Parameter_Associations
(N
)));
3380 -- An indexed component is side effect free if it is a side
3381 -- effect free prefixed reference and all the indexing
3382 -- expressions are side effect free.
3384 when N_Indexed_Component
=>
3385 return Side_Effect_Free
(Expressions
(N
))
3386 and then Safe_Prefixed_Reference
(N
);
3388 -- A type qualification is side effect free if the expression
3389 -- is side effect free.
3391 when N_Qualified_Expression
=>
3392 return Side_Effect_Free
(Expression
(N
));
3394 -- A selected component is side effect free only if it is a
3395 -- side effect free prefixed reference.
3397 when N_Selected_Component
=>
3398 return Safe_Prefixed_Reference
(N
);
3400 -- A range is side effect free if the bounds are side effect free
3403 return Side_Effect_Free
(Low_Bound
(N
))
3404 and then Side_Effect_Free
(High_Bound
(N
));
3406 -- A slice is side effect free if it is a side effect free
3407 -- prefixed reference and the bounds are side effect free.
3410 return Side_Effect_Free
(Discrete_Range
(N
))
3411 and then Safe_Prefixed_Reference
(N
);
3413 -- A type conversion is side effect free if the expression
3414 -- to be converted is side effect free.
3416 when N_Type_Conversion
=>
3417 return Side_Effect_Free
(Expression
(N
));
3419 -- A unary operator is side effect free if the operand
3420 -- is side effect free.
3423 return Side_Effect_Free
(Right_Opnd
(N
));
3425 -- An unchecked type conversion is side effect free only if it
3426 -- is safe and its argument is side effect free.
3428 when N_Unchecked_Type_Conversion
=>
3429 return Safe_Unchecked_Type_Conversion
(N
)
3430 and then Side_Effect_Free
(Expression
(N
));
3432 -- An unchecked expression is side effect free if its expression
3433 -- is side effect free.
3435 when N_Unchecked_Expression
=>
3436 return Side_Effect_Free
(Expression
(N
));
3438 -- A literal is side effect free
3440 when N_Character_Literal |
3446 -- We consider that anything else has side effects. This is a bit
3447 -- crude, but we are pretty close for most common cases, and we
3448 -- are certainly correct (i.e. we never return True when the
3449 -- answer should be False).
3454 end Side_Effect_Free
;
3456 -- A list is side effect free if all elements of the list are
3457 -- side effect free.
3459 function Side_Effect_Free
(L
: List_Id
) return Boolean is
3463 if L
= No_List
or else L
= Error_List
then
3468 while Present
(N
) loop
3469 if not Side_Effect_Free
(N
) then
3478 end Side_Effect_Free
;
3480 -------------------------
3481 -- Within_In_Parameter --
3482 -------------------------
3484 function Within_In_Parameter
(N
: Node_Id
) return Boolean is
3486 if not Comes_From_Source
(N
) then
3489 elsif Is_Entity_Name
(N
) then
3491 Ekind
(Entity
(N
)) = E_In_Parameter
;
3493 elsif Nkind
(N
) = N_Indexed_Component
3494 or else Nkind
(N
) = N_Selected_Component
3496 return Within_In_Parameter
(Prefix
(N
));
3501 end Within_In_Parameter
;
3503 -- Start of processing for Remove_Side_Effects
3506 -- If we are side effect free already or expansion is disabled,
3507 -- there is nothing to do.
3509 if Side_Effect_Free
(Exp
) or else not Expander_Active
then
3513 -- All this must not have any checks
3515 Scope_Suppress
:= (others => True);
3517 -- If the expression has the form v.all then we can just capture
3518 -- the pointer, and then do an explicit dereference on the result.
3520 if Nkind
(Exp
) = N_Explicit_Dereference
then
3522 Make_Defining_Identifier
(Loc
, New_Internal_Name
('R'));
3524 Make_Explicit_Dereference
(Loc
, New_Reference_To
(Def_Id
, Loc
));
3527 Make_Object_Declaration
(Loc
,
3528 Defining_Identifier
=> Def_Id
,
3529 Object_Definition
=>
3530 New_Reference_To
(Etype
(Prefix
(Exp
)), Loc
),
3531 Constant_Present
=> True,
3532 Expression
=> Relocate_Node
(Prefix
(Exp
))));
3534 -- Similar processing for an unchecked conversion of an expression
3535 -- of the form v.all, where we want the same kind of treatment.
3537 elsif Nkind
(Exp
) = N_Unchecked_Type_Conversion
3538 and then Nkind
(Expression
(Exp
)) = N_Explicit_Dereference
3540 Remove_Side_Effects
(Expression
(Exp
), Variable_Ref
);
3541 Scope_Suppress
:= Svg_Suppress
;
3544 -- If this is a type conversion, leave the type conversion and remove
3545 -- the side effects in the expression. This is important in several
3546 -- circumstances: for change of representations, and also when this
3547 -- is a view conversion to a smaller object, where gigi can end up
3548 -- its own temporary of the wrong size.
3550 -- ??? this transformation is inhibited for elementary types that are
3551 -- not involved in a change of representation because it causes
3552 -- regressions that are not fully understood yet.
3554 elsif Nkind
(Exp
) = N_Type_Conversion
3555 and then (not Is_Elementary_Type
(Underlying_Type
(Exp_Type
))
3556 or else Nkind
(Parent
(Exp
)) = N_Assignment_Statement
)
3558 Remove_Side_Effects
(Expression
(Exp
), Variable_Ref
);
3559 Scope_Suppress
:= Svg_Suppress
;
3562 -- For expressions that denote objects, we can use a renaming scheme.
3563 -- We skip using this if we have a volatile variable and we do not
3564 -- have Nam_Req set true (see comments above for Side_Effect_Free).
3565 -- We also skip this scheme for class-wide expressions in order to
3566 -- avoid recursive expansion (see Expand_N_Object_Renaming_Declaration)
3567 -- If the object is a function call, we need to create a temporary and
3570 -- Note that we could use ordinary object declarations in the case of
3571 -- expressions not appearing as lvalues. That is left as a possible
3572 -- optimization in the future but we prefer to generate renamings
3573 -- right now, since we may indeed be transforming an lvalue.
3575 elsif Is_Object_Reference
(Exp
)
3576 and then Nkind
(Exp
) /= N_Function_Call
3577 and then not Variable_Ref
3579 or else not Is_Entity_Name
(Exp
)
3580 or else not Treat_As_Volatile
(Entity
(Exp
)))
3581 and then not Is_Class_Wide_Type
(Exp_Type
)
3583 Def_Id
:= Make_Defining_Identifier
(Loc
, New_Internal_Name
('R'));
3585 if Nkind
(Exp
) = N_Selected_Component
3586 and then Nkind
(Prefix
(Exp
)) = N_Function_Call
3587 and then Is_Array_Type
(Etype
(Exp
))
3589 -- Avoid generating a variable-sized temporary, by generating
3590 -- the renaming declaration just for the function call. The
3591 -- transformation could be refined to apply only when the array
3592 -- component is constrained by a discriminant???
3595 Make_Selected_Component
(Loc
,
3596 Prefix
=> New_Occurrence_Of
(Def_Id
, Loc
),
3597 Selector_Name
=> Selector_Name
(Exp
));
3600 Make_Object_Renaming_Declaration
(Loc
,
3601 Defining_Identifier
=> Def_Id
,
3603 New_Reference_To
(Base_Type
(Etype
(Prefix
(Exp
))), Loc
),
3604 Name
=> Relocate_Node
(Prefix
(Exp
))));
3606 -- The temporary must be elaborated by gigi, and is of course
3607 -- not to be replaced in-line by the expression it renames,
3608 -- which would defeat the purpose of removing the side-effect.
3610 Set_Is_Renaming_Of_Object
(Def_Id
, False);
3613 Res
:= New_Reference_To
(Def_Id
, Loc
);
3616 Make_Object_Renaming_Declaration
(Loc
,
3617 Defining_Identifier
=> Def_Id
,
3618 Subtype_Mark
=> New_Reference_To
(Exp_Type
, Loc
),
3619 Name
=> Relocate_Node
(Exp
)));
3621 Set_Is_Renaming_Of_Object
(Def_Id
, False);
3624 -- If it is a scalar type, just make a copy
3626 elsif Is_Elementary_Type
(Exp_Type
) then
3627 Def_Id
:= Make_Defining_Identifier
(Loc
, New_Internal_Name
('R'));
3628 Set_Etype
(Def_Id
, Exp_Type
);
3629 Res
:= New_Reference_To
(Def_Id
, Loc
);
3632 Make_Object_Declaration
(Loc
,
3633 Defining_Identifier
=> Def_Id
,
3634 Object_Definition
=> New_Reference_To
(Exp_Type
, Loc
),
3635 Constant_Present
=> True,
3636 Expression
=> Relocate_Node
(Exp
));
3638 Set_Assignment_OK
(E
);
3639 Insert_Action
(Exp
, E
);
3641 -- Always use a renaming for an unchecked conversion
3642 -- If this is an unchecked conversion that Gigi can't handle, make
3643 -- a copy or a use a renaming to capture the value.
3645 elsif Nkind
(Exp
) = N_Unchecked_Type_Conversion
3646 and then not Safe_Unchecked_Type_Conversion
(Exp
)
3648 if Controlled_Type
(Etype
(Exp
)) then
3650 -- Use a renaming to capture the expression, rather than create
3651 -- a controlled temporary.
3653 Def_Id
:= Make_Defining_Identifier
(Loc
, New_Internal_Name
('R'));
3654 Res
:= New_Reference_To
(Def_Id
, Loc
);
3657 Make_Object_Renaming_Declaration
(Loc
,
3658 Defining_Identifier
=> Def_Id
,
3659 Subtype_Mark
=> New_Reference_To
(Exp_Type
, Loc
),
3660 Name
=> Relocate_Node
(Exp
)));
3663 Def_Id
:= Make_Defining_Identifier
(Loc
, New_Internal_Name
('R'));
3664 Set_Etype
(Def_Id
, Exp_Type
);
3665 Res
:= New_Reference_To
(Def_Id
, Loc
);
3668 Make_Object_Declaration
(Loc
,
3669 Defining_Identifier
=> Def_Id
,
3670 Object_Definition
=> New_Reference_To
(Exp_Type
, Loc
),
3671 Constant_Present
=> not Is_Variable
(Exp
),
3672 Expression
=> Relocate_Node
(Exp
));
3674 Set_Assignment_OK
(E
);
3675 Insert_Action
(Exp
, E
);
3678 -- Otherwise we generate a reference to the value
3681 Ref_Type
:= Make_Defining_Identifier
(Loc
, New_Internal_Name
('A'));
3684 Make_Full_Type_Declaration
(Loc
,
3685 Defining_Identifier
=> Ref_Type
,
3687 Make_Access_To_Object_Definition
(Loc
,
3688 All_Present
=> True,
3689 Subtype_Indication
=>
3690 New_Reference_To
(Exp_Type
, Loc
)));
3693 Insert_Action
(Exp
, Ptr_Typ_Decl
);
3695 Def_Id
:= Make_Defining_Identifier
(Loc
, New_Internal_Name
('R'));
3696 Set_Etype
(Def_Id
, Exp_Type
);
3699 Make_Explicit_Dereference
(Loc
,
3700 Prefix
=> New_Reference_To
(Def_Id
, Loc
));
3702 if Nkind
(E
) = N_Explicit_Dereference
then
3703 New_Exp
:= Relocate_Node
(Prefix
(E
));
3705 E
:= Relocate_Node
(E
);
3706 New_Exp
:= Make_Reference
(Loc
, E
);
3709 if Nkind
(E
) = N_Aggregate
and then Expansion_Delayed
(E
) then
3710 Set_Expansion_Delayed
(E
, False);
3711 Set_Analyzed
(E
, False);
3715 Make_Object_Declaration
(Loc
,
3716 Defining_Identifier
=> Def_Id
,
3717 Object_Definition
=> New_Reference_To
(Ref_Type
, Loc
),
3718 Expression
=> New_Exp
));
3721 -- Preserve the Assignment_OK flag in all copies, since at least
3722 -- one copy may be used in a context where this flag must be set
3723 -- (otherwise why would the flag be set in the first place).
3725 Set_Assignment_OK
(Res
, Assignment_OK
(Exp
));
3727 -- Finally rewrite the original expression and we are done
3730 Analyze_And_Resolve
(Exp
, Exp_Type
);
3731 Scope_Suppress
:= Svg_Suppress
;
3732 end Remove_Side_Effects
;
3734 ------------------------------------
3735 -- Safe_Unchecked_Type_Conversion --
3736 ------------------------------------
3738 -- Note: this function knows quite a bit about the exact requirements
3739 -- of Gigi with respect to unchecked type conversions, and its code
3740 -- must be coordinated with any changes in Gigi in this area.
3742 -- The above requirements should be documented in Sinfo ???
3744 function Safe_Unchecked_Type_Conversion
(Exp
: Node_Id
) return Boolean is
3749 Pexp
: constant Node_Id
:= Parent
(Exp
);
3752 -- If the expression is the RHS of an assignment or object declaration
3753 -- we are always OK because there will always be a target.
3755 -- Object renaming declarations, (generated for view conversions of
3756 -- actuals in inlined calls), like object declarations, provide an
3757 -- explicit type, and are safe as well.
3759 if (Nkind
(Pexp
) = N_Assignment_Statement
3760 and then Expression
(Pexp
) = Exp
)
3761 or else Nkind
(Pexp
) = N_Object_Declaration
3762 or else Nkind
(Pexp
) = N_Object_Renaming_Declaration
3766 -- If the expression is the prefix of an N_Selected_Component
3767 -- we should also be OK because GCC knows to look inside the
3768 -- conversion except if the type is discriminated. We assume
3769 -- that we are OK anyway if the type is not set yet or if it is
3770 -- controlled since we can't afford to introduce a temporary in
3773 elsif Nkind
(Pexp
) = N_Selected_Component
3774 and then Prefix
(Pexp
) = Exp
3776 if No
(Etype
(Pexp
)) then
3780 not Has_Discriminants
(Etype
(Pexp
))
3781 or else Is_Constrained
(Etype
(Pexp
));
3785 -- Set the output type, this comes from Etype if it is set, otherwise
3786 -- we take it from the subtype mark, which we assume was already
3789 if Present
(Etype
(Exp
)) then
3790 Otyp
:= Etype
(Exp
);
3792 Otyp
:= Entity
(Subtype_Mark
(Exp
));
3795 -- The input type always comes from the expression, and we assume
3796 -- this is indeed always analyzed, so we can simply get the Etype.
3798 Ityp
:= Etype
(Expression
(Exp
));
3800 -- Initialize alignments to unknown so far
3805 -- Replace a concurrent type by its corresponding record type
3806 -- and each type by its underlying type and do the tests on those.
3807 -- The original type may be a private type whose completion is a
3808 -- concurrent type, so find the underlying type first.
3810 if Present
(Underlying_Type
(Otyp
)) then
3811 Otyp
:= Underlying_Type
(Otyp
);
3814 if Present
(Underlying_Type
(Ityp
)) then
3815 Ityp
:= Underlying_Type
(Ityp
);
3818 if Is_Concurrent_Type
(Otyp
) then
3819 Otyp
:= Corresponding_Record_Type
(Otyp
);
3822 if Is_Concurrent_Type
(Ityp
) then
3823 Ityp
:= Corresponding_Record_Type
(Ityp
);
3826 -- If the base types are the same, we know there is no problem since
3827 -- this conversion will be a noop.
3829 if Implementation_Base_Type
(Otyp
) = Implementation_Base_Type
(Ityp
) then
3832 -- Same if this is an upwards conversion of an untagged type, and there
3833 -- are no constraints involved (could be more general???)
3835 elsif Etype
(Ityp
) = Otyp
3836 and then not Is_Tagged_Type
(Ityp
)
3837 and then not Has_Discriminants
(Ityp
)
3838 and then No
(First_Rep_Item
(Base_Type
(Ityp
)))
3842 -- If the size of output type is known at compile time, there is
3843 -- never a problem. Note that unconstrained records are considered
3844 -- to be of known size, but we can't consider them that way here,
3845 -- because we are talking about the actual size of the object.
3847 -- We also make sure that in addition to the size being known, we do
3848 -- not have a case which might generate an embarrassingly large temp
3849 -- in stack checking mode.
3851 elsif Size_Known_At_Compile_Time
(Otyp
)
3853 (not Stack_Checking_Enabled
3854 or else not May_Generate_Large_Temp
(Otyp
))
3855 and then not (Is_Record_Type
(Otyp
) and then not Is_Constrained
(Otyp
))
3859 -- If either type is tagged, then we know the alignment is OK so
3860 -- Gigi will be able to use pointer punning.
3862 elsif Is_Tagged_Type
(Otyp
) or else Is_Tagged_Type
(Ityp
) then
3865 -- If either type is a limited record type, we cannot do a copy, so
3866 -- say safe since there's nothing else we can do.
3868 elsif Is_Limited_Record
(Otyp
) or else Is_Limited_Record
(Ityp
) then
3871 -- Conversions to and from packed array types are always ignored and
3874 elsif Is_Packed_Array_Type
(Otyp
)
3875 or else Is_Packed_Array_Type
(Ityp
)
3880 -- The only other cases known to be safe is if the input type's
3881 -- alignment is known to be at least the maximum alignment for the
3882 -- target or if both alignments are known and the output type's
3883 -- alignment is no stricter than the input's. We can use the alignment
3884 -- of the component type of an array if a type is an unpacked
3887 if Present
(Alignment_Clause
(Otyp
)) then
3888 Oalign
:= Expr_Value
(Expression
(Alignment_Clause
(Otyp
)));
3890 elsif Is_Array_Type
(Otyp
)
3891 and then Present
(Alignment_Clause
(Component_Type
(Otyp
)))
3893 Oalign
:= Expr_Value
(Expression
(Alignment_Clause
3894 (Component_Type
(Otyp
))));
3897 if Present
(Alignment_Clause
(Ityp
)) then
3898 Ialign
:= Expr_Value
(Expression
(Alignment_Clause
(Ityp
)));
3900 elsif Is_Array_Type
(Ityp
)
3901 and then Present
(Alignment_Clause
(Component_Type
(Ityp
)))
3903 Ialign
:= Expr_Value
(Expression
(Alignment_Clause
3904 (Component_Type
(Ityp
))));
3907 if Ialign
/= No_Uint
and then Ialign
> Maximum_Alignment
then
3910 elsif Ialign
/= No_Uint
and then Oalign
/= No_Uint
3911 and then Ialign
<= Oalign
3915 -- Otherwise, Gigi cannot handle this and we must make a temporary
3921 end Safe_Unchecked_Type_Conversion
;
3923 --------------------------
3924 -- Set_Elaboration_Flag --
3925 --------------------------
3927 procedure Set_Elaboration_Flag
(N
: Node_Id
; Spec_Id
: Entity_Id
) is
3928 Loc
: constant Source_Ptr
:= Sloc
(N
);
3929 Ent
: constant Entity_Id
:= Elaboration_Entity
(Spec_Id
);
3933 if Present
(Ent
) then
3935 -- Nothing to do if at the compilation unit level, because in this
3936 -- case the flag is set by the binder generated elaboration routine.
3938 if Nkind
(Parent
(N
)) = N_Compilation_Unit
then
3941 -- Here we do need to generate an assignment statement
3944 Check_Restriction
(No_Elaboration_Code
, N
);
3946 Make_Assignment_Statement
(Loc
,
3947 Name
=> New_Occurrence_Of
(Ent
, Loc
),
3948 Expression
=> New_Occurrence_Of
(Standard_True
, Loc
));
3950 if Nkind
(Parent
(N
)) = N_Subunit
then
3951 Insert_After
(Corresponding_Stub
(Parent
(N
)), Asn
);
3953 Insert_After
(N
, Asn
);
3958 -- Kill current value indication. This is necessary because
3959 -- the tests of this flag are inserted out of sequence and must
3960 -- not pick up bogus indications of the wrong constant value.
3962 Set_Current_Value
(Ent
, Empty
);
3965 end Set_Elaboration_Flag
;
3967 --------------------------
3968 -- Target_Has_Fixed_Ops --
3969 --------------------------
3971 Integer_Sized_Small
: Ureal
;
3972 -- Set to 2.0 ** -(Integer'Size - 1) the first time that this
3973 -- function is called (we don't want to compute it more than once!)
3975 Long_Integer_Sized_Small
: Ureal
;
3976 -- Set to 2.0 ** -(Long_Integer'Size - 1) the first time that this
3977 -- functoin is called (we don't want to compute it more than once)
3979 First_Time_For_THFO
: Boolean := True;
3980 -- Set to False after first call (if Fractional_Fixed_Ops_On_Target)
3982 function Target_Has_Fixed_Ops
3983 (Left_Typ
: Entity_Id
;
3984 Right_Typ
: Entity_Id
;
3985 Result_Typ
: Entity_Id
) return Boolean
3987 function Is_Fractional_Type
(Typ
: Entity_Id
) return Boolean;
3988 -- Return True if the given type is a fixed-point type with a small
3989 -- value equal to 2 ** (-(T'Object_Size - 1)) and whose values have
3990 -- an absolute value less than 1.0. This is currently limited
3991 -- to fixed-point types that map to Integer or Long_Integer.
3993 ------------------------
3994 -- Is_Fractional_Type --
3995 ------------------------
3997 function Is_Fractional_Type
(Typ
: Entity_Id
) return Boolean is
3999 if Esize
(Typ
) = Standard_Integer_Size
then
4000 return Small_Value
(Typ
) = Integer_Sized_Small
;
4002 elsif Esize
(Typ
) = Standard_Long_Integer_Size
then
4003 return Small_Value
(Typ
) = Long_Integer_Sized_Small
;
4008 end Is_Fractional_Type
;
4010 -- Start of processing for Target_Has_Fixed_Ops
4013 -- Return False if Fractional_Fixed_Ops_On_Target is false
4015 if not Fractional_Fixed_Ops_On_Target
then
4019 -- Here the target has Fractional_Fixed_Ops, if first time, compute
4020 -- standard constants used by Is_Fractional_Type.
4022 if First_Time_For_THFO
then
4023 First_Time_For_THFO
:= False;
4025 Integer_Sized_Small
:=
4028 Den
=> UI_From_Int
(Standard_Integer_Size
- 1),
4031 Long_Integer_Sized_Small
:=
4034 Den
=> UI_From_Int
(Standard_Long_Integer_Size
- 1),
4038 -- Return True if target supports fixed-by-fixed multiply/divide
4039 -- for fractional fixed-point types (see Is_Fractional_Type) and
4040 -- the operand and result types are equivalent fractional types.
4042 return Is_Fractional_Type
(Base_Type
(Left_Typ
))
4043 and then Is_Fractional_Type
(Base_Type
(Right_Typ
))
4044 and then Is_Fractional_Type
(Base_Type
(Result_Typ
))
4045 and then Esize
(Left_Typ
) = Esize
(Right_Typ
)
4046 and then Esize
(Left_Typ
) = Esize
(Result_Typ
);
4047 end Target_Has_Fixed_Ops
;
4049 ------------------------------------------
4050 -- Type_May_Have_Bit_Aligned_Components --
4051 ------------------------------------------
4053 function Type_May_Have_Bit_Aligned_Components
4054 (Typ
: Entity_Id
) return Boolean
4057 -- Array type, check component type
4059 if Is_Array_Type
(Typ
) then
4061 Type_May_Have_Bit_Aligned_Components
(Component_Type
(Typ
));
4063 -- Record type, check components
4065 elsif Is_Record_Type
(Typ
) then
4070 E
:= First_Entity
(Typ
);
4071 while Present
(E
) loop
4072 if Ekind
(E
) = E_Component
4073 or else Ekind
(E
) = E_Discriminant
4075 if Component_May_Be_Bit_Aligned
(E
)
4077 Type_May_Have_Bit_Aligned_Components
(Etype
(E
))
4089 -- Type other than array or record is always OK
4094 end Type_May_Have_Bit_Aligned_Components
;
4096 ----------------------------
4097 -- Wrap_Cleanup_Procedure --
4098 ----------------------------
4100 procedure Wrap_Cleanup_Procedure
(N
: Node_Id
) is
4101 Loc
: constant Source_Ptr
:= Sloc
(N
);
4102 Stseq
: constant Node_Id
:= Handled_Statement_Sequence
(N
);
4103 Stmts
: constant List_Id
:= Statements
(Stseq
);
4106 if Abort_Allowed
then
4107 Prepend_To
(Stmts
, Build_Runtime_Call
(Loc
, RE_Abort_Defer
));
4108 Append_To
(Stmts
, Build_Runtime_Call
(Loc
, RE_Abort_Undefer
));
4110 end Wrap_Cleanup_Procedure
;